DEADSOFTWARE

Net: Buffer outgoing messages
[d2df-sdl.git] / src / game / g_game.pas
1 (* Copyright (C) Doom 2D: Forever Developers
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *)
16 {$INCLUDE ../shared/a_modes.inc}
17 unit g_game;
19 interface
21 uses
22 SysUtils, Classes,
23 MAPDEF,
24 g_basic, g_player, e_graphics, g_res_downloader,
25 g_sound, g_gui, utils, md5, mempool, xprofiler,
26 g_touch, g_weapons;
28 type
29 TGameSettings = record
30 GameType: Byte;
31 GameMode: Byte;
32 TimeLimit: Word;
33 GoalLimit: Word;
34 WarmupTime: Word;
35 MaxLives: Byte;
36 Options: LongWord;
37 WAD: String;
38 end;
40 TGameEvent = record
41 Name: String;
42 Command: String;
43 end;
45 TDelayedEvent = record
46 Pending: Boolean;
47 Time: LongWord;
48 DEType: Byte;
49 DENum: Integer;
50 DEStr: String;
51 end;
53 TChatSound = record
54 Sound: TPlayableSound;
55 Tags: Array of String;
56 FullWord: Boolean;
57 end;
59 TPlayerSettings = record
60 Name: String;
61 Model: String;
62 Color: TRGB;
63 Team: Byte;
64 end;
66 TMegaWADInfo = record
67 Name: String;
68 Description: String;
69 Author: String;
70 Pic: String;
71 end;
73 THearPoint = record
74 Active: Boolean;
75 Coords: TDFPoint;
76 end;
78 function g_Game_IsNet(): Boolean;
79 function g_Game_IsServer(): Boolean;
80 function g_Game_IsClient(): Boolean;
81 procedure g_Game_Init();
82 procedure g_Game_Free (freeTextures: Boolean=true);
83 procedure g_Game_LoadData();
84 procedure g_Game_FreeData();
85 procedure g_Game_Update();
86 procedure g_Game_Draw();
87 procedure g_Game_Quit();
88 procedure g_Game_SetupScreenSize();
89 procedure g_Game_ChangeResolution(newWidth, newHeight: Word; nowFull, nowMax: Boolean);
90 function g_Game_ModeToText(Mode: Byte): string;
91 function g_Game_TextToMode(Mode: string): Byte;
92 procedure g_Game_ExecuteEvent(Name: String);
93 function g_Game_DelayEvent(DEType: Byte; Time: LongWord; Num: Integer = 0; Str: String = ''): Integer;
94 procedure g_Game_AddPlayer(Team: Byte = TEAM_NONE);
95 procedure g_Game_RemovePlayer();
96 procedure g_Game_Spectate();
97 procedure g_Game_SpectateCenterView();
98 procedure g_Game_StartSingle(Map: String; TwoPlayers: Boolean; nPlayers: Byte);
99 procedure g_Game_StartCustom(Map: String; GameMode: Byte; TimeLimit, GoalLimit: Word; MaxLives: Byte; Options: LongWord; nPlayers: Byte);
100 procedure g_Game_StartServer(Map: String; GameMode: Byte; TimeLimit, GoalLimit: Word; MaxLives: Byte; Options: LongWord; nPlayers: Byte; IPAddr: LongWord; Port: Word);
101 procedure g_Game_StartClient(Addr: String; Port: Word; PW: String);
102 procedure g_Game_Restart();
103 procedure g_Game_RestartLevel();
104 procedure g_Game_RestartRound(NoMapRestart: Boolean = False);
105 procedure g_Game_ClientWAD(NewWAD: String; WHash: TMD5Digest);
106 procedure g_Game_SaveOptions();
107 function g_Game_StartMap(Map: String; Force: Boolean = False; const oldMapPath: AnsiString=''): Boolean;
108 procedure g_Game_ChangeMap(const MapPath: String);
109 procedure g_Game_ExitLevel(const Map: AnsiString);
110 function g_Game_GetFirstMap(WAD: String): String;
111 function g_Game_GetNextMap(): String;
112 procedure g_Game_NextLevel();
113 procedure g_Game_Pause(Enable: Boolean);
114 procedure g_Game_HolmesPause(Enable: Boolean);
115 procedure g_Game_InGameMenu(Show: Boolean);
116 function g_Game_IsWatchedPlayer(UID: Word): Boolean;
117 function g_Game_IsWatchedTeam(Team: Byte): Boolean;
118 procedure g_Game_Message(Msg: String; Time: Word);
119 procedure g_Game_LoadMapList(FileName: String);
120 procedure g_Game_PauseAllSounds(Enable: Boolean);
121 procedure g_Game_StopAllSounds(all: Boolean);
122 procedure g_Game_UpdateTriggerSounds();
123 function g_Game_GetMegaWADInfo(WAD: String): TMegaWADInfo;
124 procedure g_Game_ChatSound(Text: String; Taunt: Boolean = True);
125 procedure g_Game_Announce_GoodShot(SpawnerUID: Word);
126 procedure g_Game_Announce_KillCombo(Param: Integer);
127 procedure g_Game_Announce_BodyKill(SpawnerUID: Word);
128 procedure g_Game_StartVote(Command, Initiator: string);
129 procedure g_Game_CheckVote;
130 procedure g_TakeScreenShot();
131 procedure g_FatalError(Text: String);
132 procedure g_SimpleError(Text: String);
133 function g_Game_IsTestMap(): Boolean;
134 procedure g_Game_DeleteTestMap();
135 procedure GameCVars(P: SSArray);
136 procedure GameCommands(P: SSArray);
137 procedure GameCheats(P: SSArray);
138 procedure DebugCommands(P: SSArray);
139 procedure g_Game_Process_Params;
140 procedure g_Game_SetLoadingText(Text: String; Max: Integer; reWrite: Boolean);
141 procedure g_Game_StepLoading(Value: Integer = -1);
142 procedure g_Game_ClearLoading();
143 procedure g_Game_SetDebugMode();
144 procedure DrawLoadingStat();
145 procedure DrawMenuBackground(tex: AnsiString);
147 { procedure SetWinPause(Enable: Boolean); }
149 const
150 GAME_TICK = 28;
152 LOADING_SHOW_STEP = 100;
153 LOADING_INTERLINE = 20;
155 GT_NONE = 0;
156 GT_SINGLE = 1;
157 GT_CUSTOM = 2;
158 GT_SERVER = 3;
159 GT_CLIENT = 4;
161 GM_NONE = 0;
162 GM_DM = 1;
163 GM_TDM = 2;
164 GM_CTF = 3;
165 GM_COOP = 4;
166 GM_SINGLE = 5;
168 MESSAGE_DIKEY = WM_USER + 1;
170 EXIT_QUIT = 1;
171 EXIT_SIMPLE = 2;
172 EXIT_RESTART = 3;
173 EXIT_ENDLEVELSINGLE = 4;
174 EXIT_ENDLEVELCUSTOM = 5;
176 GAME_OPTION_RESERVED = 1;
177 GAME_OPTION_TEAMDAMAGE = 2;
178 GAME_OPTION_ALLOWEXIT = 4;
179 GAME_OPTION_WEAPONSTAY = 8;
180 GAME_OPTION_MONSTERS = 16;
181 GAME_OPTION_BOTVSPLAYER = 32;
182 GAME_OPTION_BOTVSMONSTER = 64;
184 STATE_NONE = 0;
185 STATE_MENU = 1;
186 STATE_FOLD = 2;
187 STATE_INTERCUSTOM = 3;
188 STATE_INTERSINGLE = 4;
189 STATE_INTERTEXT = 5;
190 STATE_INTERPIC = 6;
191 STATE_ENDPIC = 7;
192 STATE_SLIST = 8;
194 LMS_RESPAWN_NONE = 0;
195 LMS_RESPAWN_WARMUP = 1;
196 LMS_RESPAWN_FINAL = 2;
198 SPECT_NONE = 0;
199 SPECT_STATS = 1;
200 SPECT_MAPVIEW = 2;
201 SPECT_PLAYERS = 3;
203 DE_GLOBEVENT = 0;
204 DE_BFGHIT = 1;
205 DE_KILLCOMBO = 2;
206 DE_BODYKILL = 3;
208 ANNOUNCE_NONE = 0;
209 ANNOUNCE_ME = 1;
210 ANNOUNCE_MEPLUS = 2;
211 ANNOUNCE_ALL = 3;
213 CONFIG_FILENAME = 'Doom2DF.cfg';
214 LOG_FILENAME = 'Doom2DF.log';
216 TEST_MAP_NAME = '$$$_TEST_$$$';
218 STD_PLAYER_MODEL = 'Doomer';
220 {$IFDEF HEADLESS}
221 DEFAULT_PLAYERS = 0;
222 {$ELSE}
223 DEFAULT_PLAYERS = 1;
224 {$ENDIF}
226 var
227 gStdFont: DWORD;
228 gGameSettings: TGameSettings;
229 gPlayer1Settings: TPlayerSettings;
230 gPlayer2Settings: TPlayerSettings;
231 gGameOn: Boolean;
232 gPlayerScreenSize: TDFPoint;
233 gPlayer1ScreenCoord: TDFPoint;
234 gPlayer2ScreenCoord: TDFPoint;
235 gPlayer1: TPlayer = nil;
236 gPlayer2: TPlayer = nil;
237 gPlayerDrawn: TPlayer = nil;
238 gTime: LongWord;
239 gSwitchGameMode: Byte = GM_DM;
240 gHearPoint1, gHearPoint2: THearPoint;
241 gSoundEffectsDF: Boolean = False;
242 gSoundTriggerTime: Word = 0;
243 gAnnouncer: Byte = ANNOUNCE_NONE;
244 goodsnd: array[0..3] of TPlayableSound;
245 killsnd: array[0..3] of TPlayableSound;
246 hahasnd: array[0..2] of TPlayableSound;
247 sound_get_flag: array[0..1] of TPlayableSound;
248 sound_lost_flag: array[0..1] of TPlayableSound;
249 sound_ret_flag: array[0..1] of TPlayableSound;
250 sound_cap_flag: array[0..1] of TPlayableSound;
251 gBodyKillEvent: Integer = -1;
252 gDefInterTime: ShortInt = -1;
253 gInterEndTime: LongWord = 0;
254 gInterTime: LongWord = 0;
255 gServInterTime: Byte = 0;
256 gGameStartTime: LongWord = 0;
257 gTotalMonsters: Integer = 0;
258 gPauseMain: Boolean = false;
259 gPauseHolmes: Boolean = false;
260 gShowTime: Boolean = False;
261 gShowFPS: Boolean = False;
262 gShowGoals: Boolean = True;
263 gShowStat: Boolean = True;
264 gShowKillMsg: Boolean = True;
265 gShowLives: Boolean = True;
266 gShowPing: Boolean = False;
267 gShowMap: Boolean = False;
268 gExit: Byte = 0;
269 gState: Byte = STATE_NONE;
270 sX, sY: Integer;
271 sWidth, sHeight: Word;
272 gSpectMode: Byte = SPECT_NONE;
273 gSpectHUD: Boolean = True;
274 gSpectKeyPress: Boolean = False;
275 gSpectX: Integer = 0;
276 gSpectY: Integer = 0;
277 gSpectStep: Byte = 8;
278 gSpectViewTwo: Boolean = False;
279 gSpectPID1: Integer = -1;
280 gSpectPID2: Integer = -1;
281 gSpectAuto: Boolean = False;
282 gSpectAutoNext: LongWord;
283 gSpectAutoStepX: Integer;
284 gSpectAutoStepY: Integer;
285 gMusic: TMusic = nil;
286 gLoadGameMode: Boolean;
287 gCheats: Boolean = False;
288 gMapOnce: Boolean = False;
289 gMapToDelete: String;
290 gTempDelete: Boolean = False;
291 gLastMap: Boolean = False;
292 gWinPosX, gWinPosY: Integer;
293 gWinSizeX, gWinSizeY: Integer;
294 gWinFrameX, gWinFrameY, gWinCaption: Integer;
295 gWinActive: Boolean = True; // by default window is active, lol
296 gResolutionChange: Boolean = False;
297 gRC_Width, gRC_Height: Word;
298 gRC_FullScreen, gRC_Maximized: Boolean;
299 gLanguageChange: Boolean = False;
300 gDebugMode: Boolean = False;
301 g_debug_Sounds: Boolean = False;
302 g_debug_Frames: Boolean = False;
303 g_debug_WinMsgs: Boolean = False;
304 g_debug_MonsterOff: Boolean = False;
305 g_debug_BotAIOff: Byte = 0;
306 g_debug_HealthBar: Boolean = False;
307 g_Debug_Player: Boolean = False;
308 gCoopMonstersKilled: Word = 0;
309 gCoopSecretsFound: Word = 0;
310 gCoopTotalMonstersKilled: Word = 0;
311 gCoopTotalSecretsFound: Word = 0;
312 gCoopTotalMonsters: Word = 0;
313 gCoopTotalSecrets: Word = 0;
314 gStatsOff: Boolean = False;
315 gStatsPressed: Boolean = False;
316 gExitByTrigger: Boolean = False;
317 gNextMap: String = '';
318 gLMSRespawn: Byte = LMS_RESPAWN_NONE;
319 gLMSRespawnTime: Cardinal = 0;
320 gLMSSoftSpawn: Boolean = False;
321 gMissionFailed: Boolean = False;
322 gVoteInProgress: Boolean = False;
323 gVotePassed: Boolean = False;
324 gVoteCommand: string = '';
325 gVoteTimer: Cardinal = 0;
326 gVoteCmdTimer: Cardinal = 0;
327 gVoteCount: Integer = 0;
328 gVoteTimeout: Cardinal = 30;
329 gVoted: Boolean = False;
330 gVotesEnabled: Boolean = True;
331 gEvents: Array of TGameEvent;
332 gDelayedEvents: Array of TDelayedEvent;
333 gUseChatSounds: Boolean = True;
334 gChatSounds: Array of TChatSound;
335 gSelectWeapon: Array [0..1, WP_FIRST..WP_LAST] of Boolean; // [player, weapon]
336 gInterReadyCount: Integer = 0;
338 g_dbg_ignore_bounds: Boolean = false;
339 r_smallmap_h: Integer = 0; // 0: left; 1: center; 2: right
340 r_smallmap_v: Integer = 2; // 0: top; 1: center; 2: bottom
342 // move button values:
343 // bits 0-1: l/r state:
344 // 0: neither left, nor right pressed
345 // 1: left pressed
346 // 2: right pressed
347 // bits 4-5: l/r state when strafe was pressed
348 P1MoveButton: Byte = 0;
349 P2MoveButton: Byte = 0;
351 g_profile_frame_update: Boolean = false;
352 g_profile_frame_draw: Boolean = false;
353 g_profile_collision: Boolean = false;
354 g_profile_los: Boolean = false;
355 g_profile_history_size: Integer = 1000;
357 g_rlayer_back: Boolean = true;
358 g_rlayer_step: Boolean = true;
359 g_rlayer_wall: Boolean = true;
360 g_rlayer_door: Boolean = true;
361 g_rlayer_acid1: Boolean = true;
362 g_rlayer_acid2: Boolean = true;
363 g_rlayer_water: Boolean = true;
364 g_rlayer_fore: Boolean = true;
367 procedure g_ResetDynlights ();
368 procedure g_AddDynLight (x, y, radius: Integer; r, g, b, a: Single);
369 procedure g_DynLightExplosion (x, y, radius: Integer; r, g, b: Single);
371 function conIsCheatsEnabled (): Boolean; inline;
372 function gPause (): Boolean; inline;
375 implementation
377 uses
378 {$INCLUDE ../nogl/noGLuses.inc}
379 {$IFDEF ENABLE_HOLMES}
380 g_holmes,
381 {$ENDIF}
382 e_texture, g_textures, g_main, g_window, g_menu,
383 e_input, e_log, g_console, g_items, g_map, g_panel,
384 g_playermodel, g_gfx, g_options, Math,
385 g_triggers, g_monsters, e_sound, CONFIG,
386 g_language, g_net,
387 ENet, e_msg, g_netmsg, g_netmaster,
388 sfs, wadreader;
391 var
392 hasPBarGfx: Boolean = false;
395 // ////////////////////////////////////////////////////////////////////////// //
396 function gPause (): Boolean; inline; begin result := gPauseMain or gPauseHolmes; end;
399 // ////////////////////////////////////////////////////////////////////////// //
400 function conIsCheatsEnabled (): Boolean; inline;
401 begin
402 result := false;
403 if g_Game_IsNet then exit;
404 if not gDebugMode then
405 begin
406 //if not gCheats then exit;
407 if not (gGameSettings.GameType in [GT_SINGLE, GT_CUSTOM]) then exit;
408 if not (gGameSettings.GameMode in [GM_COOP, GM_SINGLE]) then exit;
409 end;
410 result := true;
411 end;
414 // ////////////////////////////////////////////////////////////////////////// //
415 var
416 profileFrameDraw: TProfiler = nil;
419 // ////////////////////////////////////////////////////////////////////////// //
420 type
421 TDynLight = record
422 x, y, radius: Integer;
423 r, g, b, a: Single;
424 exploCount: Integer;
425 exploRadius: Integer;
426 end;
428 var
429 g_dynLights: array of TDynLight = nil;
430 g_dynLightCount: Integer = 0;
431 g_playerLight: Boolean = false;
433 procedure g_ResetDynlights ();
434 var
435 lnum, idx: Integer;
436 begin
437 if not gwin_has_stencil then begin g_dynLightCount := 0; exit; end;
438 lnum := 0;
439 for idx := 0 to g_dynLightCount-1 do
440 begin
441 if g_dynLights[idx].exploCount = -666 then
442 begin
443 // skip it
444 end
445 else
446 begin
447 // explosion
448 Inc(g_dynLights[idx].exploCount);
449 if (g_dynLights[idx].exploCount < 10) then
450 begin
451 g_dynLights[idx].radius := g_dynLights[idx].exploRadius+g_dynLights[idx].exploCount*8;
452 g_dynLights[idx].a := 0.4+g_dynLights[idx].exploCount/10;
453 if (g_dynLights[idx].a > 0.8) then g_dynLights[idx].a := 0.8;
454 if lnum <> idx then g_dynLights[lnum] := g_dynLights[idx];
455 Inc(lnum);
456 end;
457 end;
458 end;
459 g_dynLightCount := lnum;
460 end;
462 procedure g_AddDynLight (x, y, radius: Integer; r, g, b, a: Single);
463 begin
464 if not gwin_has_stencil then exit;
465 if g_dynLightCount = length(g_dynLights) then SetLength(g_dynLights, g_dynLightCount+1024);
466 g_dynLights[g_dynLightCount].x := x;
467 g_dynLights[g_dynLightCount].y := y;
468 g_dynLights[g_dynLightCount].radius := radius;
469 g_dynLights[g_dynLightCount].r := r;
470 g_dynLights[g_dynLightCount].g := g;
471 g_dynLights[g_dynLightCount].b := b;
472 g_dynLights[g_dynLightCount].a := a;
473 g_dynLights[g_dynLightCount].exploCount := -666;
474 Inc(g_dynLightCount);
475 end;
477 procedure g_DynLightExplosion (x, y, radius: Integer; r, g, b: Single);
478 begin
479 if not gwin_has_stencil then exit;
480 if g_dynLightCount = length(g_dynLights) then SetLength(g_dynLights, g_dynLightCount+1024);
481 g_dynLights[g_dynLightCount].x := x;
482 g_dynLights[g_dynLightCount].y := y;
483 g_dynLights[g_dynLightCount].radius := 0;
484 g_dynLights[g_dynLightCount].exploRadius := radius;
485 g_dynLights[g_dynLightCount].r := r;
486 g_dynLights[g_dynLightCount].g := g;
487 g_dynLights[g_dynLightCount].b := b;
488 g_dynLights[g_dynLightCount].a := 0;
489 g_dynLights[g_dynLightCount].exploCount := 0;
490 Inc(g_dynLightCount);
491 end;
494 // ////////////////////////////////////////////////////////////////////////// //
495 function calcProfilesHeight (prof: TProfiler): Integer;
496 begin
497 result := 0;
498 if (prof = nil) then exit;
499 if (length(prof.bars) = 0) then exit;
500 result := length(prof.bars)*(16+2);
501 end;
503 // returns width
504 function drawProfiles (x, y: Integer; prof: TProfiler): Integer;
505 var
506 wdt, hgt: Integer;
507 yy: Integer;
508 ii: Integer;
509 begin
510 result := 0;
511 if (prof = nil) then exit;
512 // gScreenWidth
513 if (length(prof.bars) = 0) then exit;
514 wdt := 192;
515 hgt := calcProfilesHeight(prof);
516 if (x < 0) then x := gScreenWidth-(wdt-1)+x;
517 if (y < 0) then y := gScreenHeight-(hgt-1)+y;
518 // background
519 //e_DrawFillQuad(x, y, x+wdt-1, y+hgt-1, 255, 255, 255, 200, B_BLEND);
520 //e_DrawFillQuad(x, y, x+wdt-1, y+hgt-1, 20, 20, 20, 0, B_NONE);
521 e_DarkenQuadWH(x, y, wdt, hgt, 150);
522 // title
523 yy := y+2;
524 for ii := 0 to High(prof.bars) do
525 begin
526 e_TextureFontPrintEx(x+2+4*prof.bars[ii].level, yy, Format('%s: %d', [prof.bars[ii].name, prof.bars[ii].value]), gStdFont, 255, 255, 0, 1, false);
527 Inc(yy, 16+2);
528 end;
529 result := wdt;
530 end;
533 // ////////////////////////////////////////////////////////////////////////// //
534 type
535 TEndCustomGameStat = record
536 PlayerStat: TPlayerStatArray;
537 TeamStat: TTeamStat;
538 GameTime: LongWord;
539 GameMode: Byte;
540 Map, MapName: String;
541 end;
543 TEndSingleGameStat = record
544 PlayerStat: Array [0..1] of record
545 Kills: Integer;
546 Secrets: Integer;
547 end;
548 GameTime: LongWord;
549 TwoPlayers: Boolean;
550 TotalSecrets: Integer;
551 end;
553 TLoadingStat = record
554 CurValue: Integer;
555 MaxValue: Integer;
556 ShowCount: Integer;
557 Msgs: Array of String;
558 NextMsg: Word;
559 PBarWasHere: Boolean; // did we draw a progress bar for this message?
560 end;
562 TParamStrValue = record
563 Name: String;
564 Value: String;
565 end;
567 TParamStrValues = Array of TParamStrValue;
569 const
570 INTER_ACTION_TEXT = 1;
571 INTER_ACTION_PIC = 2;
572 INTER_ACTION_MUSIC = 3;
574 var
575 FPS, UPS: Word;
576 FPSCounter, UPSCounter: Word;
577 FPSTime, UPSTime: LongWord;
578 DataLoaded: Boolean = False;
579 IsDrawStat: Boolean = False;
580 CustomStat: TEndCustomGameStat;
581 SingleStat: TEndSingleGameStat;
582 LoadingStat: TLoadingStat;
583 EndingGameCounter: Byte = 0;
584 MessageText: String;
585 MessageTime: Word;
586 MessageLineLength: Integer = 80;
587 MapList: SSArray = nil;
588 MapIndex: Integer = -1;
589 InterReadyTime: Integer = -1;
590 MegaWAD: record
591 info: TMegaWADInfo;
592 endpic: String;
593 endmus: String;
594 res: record
595 text: Array of ShortString;
596 anim: Array of ShortString;
597 pic: Array of ShortString;
598 mus: Array of ShortString;
599 end;
600 triggers: Array of record
601 event: ShortString;
602 actions: Array of record
603 action, p1, p2: Integer;
604 end;
605 end;
606 cur_trigger: Integer;
607 cur_action: Integer;
608 end;
609 //InterPic: String;
610 InterText: record
611 lines: SSArray;
612 img: String;
613 cur_line: Integer;
614 cur_char: Integer;
615 counter: Integer;
616 endtext: Boolean;
617 end;
619 function Compare(a, b: TPlayerStat): Integer;
620 begin
621 if a.Spectator then Result := 1
622 else if b.Spectator then Result := -1
623 else if a.Frags < b.Frags then Result := 1
624 else if a.Frags > b.Frags then Result := -1
625 else if a.Deaths < b.Deaths then Result := -1
626 else if a.Deaths > b.Deaths then Result := 1
627 else if a.Kills < b.Kills then Result := -1
628 else Result := 1;
629 end;
631 procedure SortGameStat(var stat: TPlayerStatArray);
632 var
633 I, J: Integer;
634 T: TPlayerStat;
635 begin
636 if stat = nil then Exit;
638 for I := High(stat) downto Low(stat) do
639 for J := Low(stat) to High(stat) - 1 do
640 if Compare(stat[J], stat[J + 1]) = 1 then
641 begin
642 T := stat[J];
643 stat[J] := stat[J + 1];
644 stat[J + 1] := T;
645 end;
646 end;
648 function g_Game_ModeToText(Mode: Byte): string;
649 begin
650 Result := '';
651 case Mode of
652 GM_DM: Result := _lc[I_MENU_GAME_TYPE_DM];
653 GM_TDM: Result := _lc[I_MENU_GAME_TYPE_TDM];
654 GM_CTF: Result := _lc[I_MENU_GAME_TYPE_CTF];
655 GM_COOP: Result := _lc[I_MENU_GAME_TYPE_COOP];
656 GM_SINGLE: Result := _lc[I_MENU_GAME_TYPE_SINGLE];
657 end;
658 end;
660 function g_Game_TextToMode(Mode: string): Byte;
661 begin
662 Result := GM_NONE;
663 Mode := UpperCase(Mode);
664 if Mode = _lc[I_MENU_GAME_TYPE_DM] then
665 begin
666 Result := GM_DM;
667 Exit;
668 end;
669 if Mode = _lc[I_MENU_GAME_TYPE_TDM] then
670 begin
671 Result := GM_TDM;
672 Exit;
673 end;
674 if Mode = _lc[I_MENU_GAME_TYPE_CTF] then
675 begin
676 Result := GM_CTF;
677 Exit;
678 end;
679 if Mode = _lc[I_MENU_GAME_TYPE_COOP] then
680 begin
681 Result := GM_COOP;
682 Exit;
683 end;
684 if Mode = _lc[I_MENU_GAME_TYPE_SINGLE] then
685 begin
686 Result := GM_SINGLE;
687 Exit;
688 end;
689 end;
691 function g_Game_IsNet(): Boolean;
692 begin
693 Result := (gGameSettings.GameType in [GT_SERVER, GT_CLIENT]);
694 end;
696 function g_Game_IsServer(): Boolean;
697 begin
698 Result := (gGameSettings.GameType in [GT_SINGLE, GT_CUSTOM, GT_SERVER]);
699 end;
701 function g_Game_IsClient(): Boolean;
702 begin
703 Result := (gGameSettings.GameType = GT_CLIENT);
704 end;
706 function g_Game_GetMegaWADInfo(WAD: String): TMegaWADInfo;
707 var
708 w: TWADFile;
709 cfg: TConfig;
710 p: Pointer;
711 len: Integer;
712 begin
713 Result.name := ExtractFileName(WAD);
714 Result.description := '';
715 Result.author := '';
717 w := TWADFile.Create();
718 w.ReadFile(WAD);
720 if not w.GetResource('INTERSCRIPT', p, len) then
721 begin
722 w.Free();
723 Exit;
724 end;
726 cfg := TConfig.CreateMem(p, len);
727 Result.name := cfg.ReadStr('megawad', 'name', ExtractFileName(WAD));
728 Result.description := cfg.ReadStr('megawad', 'description', '');
729 Result.author := cfg.ReadStr('megawad', 'author', '');
730 Result.pic := cfg.ReadStr('megawad', 'pic', '');
731 cfg.Free();
733 FreeMem(p);
734 end;
736 procedure g_Game_FreeWAD();
737 var
738 a: Integer;
739 begin
740 for a := 0 to High(MegaWAD.res.pic) do
741 if MegaWAD.res.pic[a] <> '' then
742 g_Texture_Delete(MegaWAD.res.pic[a]);
744 for a := 0 to High(MegaWAD.res.mus) do
745 if MegaWAD.res.mus[a] <> '' then
746 g_Sound_Delete(MegaWAD.res.mus[a]);
748 MegaWAD.res.pic := nil;
749 MegaWAD.res.text := nil;
750 MegaWAD.res.anim := nil;
751 MegaWAD.res.mus := nil;
752 MegaWAD.triggers := nil;
754 g_Texture_Delete('TEXTURE_endpic');
755 g_Sound_Delete('MUSIC_endmus');
757 ZeroMemory(@MegaWAD, SizeOf(MegaWAD));
758 gGameSettings.WAD := '';
759 end;
761 procedure g_Game_LoadWAD(WAD: string);
762 var
763 w: TWADFile;
764 cfg: TConfig;
765 p: Pointer;
766 {b, }len: Integer;
767 s: string;
768 begin
769 g_Game_FreeWAD();
770 gGameSettings.WAD := WAD;
771 if not (gGameSettings.GameMode in [GM_COOP, GM_SINGLE]) then
772 Exit;
774 MegaWAD.info := g_Game_GetMegaWADInfo(MapsDir + WAD);
776 w := TWADFile.Create();
777 w.ReadFile(MapsDir + WAD);
779 if not w.GetResource('INTERSCRIPT', p, len) then
780 begin
781 w.Free();
782 Exit;
783 end;
785 cfg := TConfig.CreateMem(p, len);
787 {b := 1;
788 while True do
789 begin
790 s := cfg.ReadStr('pic', 'pic'+IntToStr(b), '');
791 if s = '' then Break;
792 b := b+1;
794 SetLength(MegaWAD.res.pic, Length(MegaWAD.res.pic)+1);
795 MegaWAD.res.pic[High(MegaWAD.res.pic)] := s;
797 g_Texture_CreateWADEx(s, s);
798 end;
800 b := 1;
801 while True do
802 begin
803 s := cfg.ReadStr('mus', 'mus'+IntToStr(b), '');
804 if s = '' then Break;
805 b := b+1;
807 SetLength(MegaWAD.res.mus, Length(MegaWAD.res.mus)+1);
808 MegaWAD.res.mus[High(MegaWAD.res.mus)] := s;
810 g_Music_CreateWADEx(s, s);
811 end;}
813 MegaWAD.endpic := cfg.ReadStr('megawad', 'endpic', '');
814 if MegaWAD.endpic <> '' then
815 begin
816 s := g_ExtractWadName(MegaWAD.endpic);
817 if s = '' then s := MapsDir+WAD else s := GameDir+'/wads/';
818 TEXTUREFILTER := GL_LINEAR;
819 g_Texture_CreateWADEx('TEXTURE_endpic', s+MegaWAD.endpic);
820 TEXTUREFILTER := GL_NEAREST;
821 end;
822 MegaWAD.endmus := cfg.ReadStr('megawad', 'endmus', 'Standart.wad:D2DMUS\ÊÎÍÅÖ');
823 if MegaWAD.endmus <> '' then
824 begin
825 s := g_ExtractWadName(MegaWAD.endmus);
826 if s = '' then s := MapsDir+WAD else s := GameDir+'/wads/';
827 g_Sound_CreateWADEx('MUSIC_endmus', s+MegaWAD.endmus, True);
828 end;
830 cfg.Free();
831 FreeMem(p);
832 w.Free();
833 end;
835 {procedure start_trigger(t: string);
836 begin
837 end;
839 function next_trigger(): Boolean;
840 begin
841 end;}
843 procedure DisableCheats();
844 begin
845 MAX_RUNVEL := 8;
846 VEL_JUMP := 10;
847 gFly := False;
849 if gPlayer1 <> nil then gPlayer1.GodMode := False;
850 if gPlayer2 <> nil then gPlayer2.GodMode := False;
851 if gPlayer1 <> nil then gPlayer1.NoTarget := False;
852 if gPlayer2 <> nil then gPlayer2.NoTarget := False;
854 {$IF DEFINED(D2F_DEBUG)}
855 if gPlayer1 <> nil then gPlayer1.NoTarget := True;
856 gAimLine := g_dbg_aimline_on;
857 {$ENDIF}
858 end;
860 procedure g_Game_ExecuteEvent(Name: String);
861 var
862 a: Integer;
863 begin
864 if Name = '' then
865 Exit;
866 if gEvents = nil then
867 Exit;
868 for a := 0 to High(gEvents) do
869 if gEvents[a].Name = Name then
870 begin
871 if gEvents[a].Command <> '' then
872 g_Console_Process(gEvents[a].Command, True);
873 break;
874 end;
875 end;
877 function g_Game_DelayEvent(DEType: Byte; Time: LongWord; Num: Integer = 0; Str: String = ''): Integer;
878 var
879 a, n: Integer;
880 begin
881 n := -1;
882 if gDelayedEvents <> nil then
883 for a := 0 to High(gDelayedEvents) do
884 if not gDelayedEvents[a].Pending then
885 begin
886 n := a;
887 break;
888 end;
889 if n = -1 then
890 begin
891 SetLength(gDelayedEvents, Length(gDelayedEvents) + 1);
892 n := High(gDelayedEvents);
893 end;
894 gDelayedEvents[n].Pending := True;
895 gDelayedEvents[n].DEType := DEType;
896 gDelayedEvents[n].DENum := Num;
897 gDelayedEvents[n].DEStr := Str;
898 if DEType = DE_GLOBEVENT then
899 gDelayedEvents[n].Time := (GetTimer() {div 1000}) + Time
900 else
901 gDelayedEvents[n].Time := gTime + Time;
902 Result := n;
903 end;
905 procedure EndGame();
906 var
907 a: Integer;
908 FileName: string;
909 begin
910 if g_Game_IsNet and g_Game_IsServer then
911 MH_SEND_GameEvent(NET_EV_MAPEND, Byte(gMissionFailed));
913 // Ñòîï èãðà:
914 gPauseMain := false;
915 gPauseHolmes := false;
916 gGameOn := false;
918 g_Game_StopAllSounds(False);
920 MessageTime := 0;
921 MessageText := '';
923 EndingGameCounter := 0;
924 g_ActiveWindow := nil;
926 gLMSRespawn := LMS_RESPAWN_NONE;
927 gLMSRespawnTime := 0;
929 case gExit of
930 EXIT_SIMPLE: // Âûõîä ÷åðåç ìåíþ èëè êîíåö òåñòà
931 begin
932 g_Game_Free();
934 if gMapOnce then
935 begin // Ýòî áûë òåñò
936 g_Game_Quit();
937 end
938 else
939 begin // Âûõîä â ãëàâíîå ìåíþ
940 gMusic.SetByName('MUSIC_MENU');
941 gMusic.Play();
942 if gState <> STATE_SLIST then
943 begin
944 g_GUI_ShowWindow('MainMenu');
945 gState := STATE_MENU;
946 end else
947 begin
948 // Îáíîâëÿåì ñïèñîê ñåðâåðîâ
949 slReturnPressed := True;
950 if g_Net_Slist_Fetch(slCurrent) then
951 begin
952 if slCurrent = nil then
953 slWaitStr := _lc[I_NET_SLIST_NOSERVERS];
954 end
955 else
956 slWaitStr := _lc[I_NET_SLIST_ERROR];
957 g_Serverlist_GenerateTable(slCurrent, slTable);
958 end;
960 g_Game_ExecuteEvent('ongameend');
961 end;
962 end;
964 EXIT_RESTART: // Íà÷àòü óðîâåíü ñíà÷àëà
965 begin
966 if not g_Game_IsClient then g_Game_Restart();
967 end;
969 EXIT_ENDLEVELCUSTOM: // Çàêîí÷èëñÿ óðîâåíü â Ñâîåé èãðå
970 begin
971 // Ñòàòèñòèêà Ñâîåé èãðû:
972 FileName := g_ExtractWadName(gMapInfo.Map);
974 CustomStat.GameTime := gTime;
975 CustomStat.Map := ExtractFileName(FileName)+':'+g_ExtractFileName(gMapInfo.Map); //ResName;
976 CustomStat.MapName := gMapInfo.Name;
977 CustomStat.GameMode := gGameSettings.GameMode;
978 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
979 CustomStat.TeamStat := gTeamStat;
981 CustomStat.PlayerStat := nil;
983 // Ñòàòèñòèêà èãðîêîâ:
984 if gPlayers <> nil then
985 begin
986 for a := 0 to High(gPlayers) do
987 if gPlayers[a] <> nil then
988 begin
989 SetLength(CustomStat.PlayerStat, Length(CustomStat.PlayerStat)+1);
990 with CustomStat.PlayerStat[High(CustomStat.PlayerStat)] do
991 begin
992 Num := a;
993 Name := gPlayers[a].Name;
994 Frags := gPlayers[a].Frags;
995 Deaths := gPlayers[a].Death;
996 Kills := gPlayers[a].Kills;
997 Team := gPlayers[a].Team;
998 Color := gPlayers[a].Model.Color;
999 Spectator := gPlayers[a].FSpectator;
1000 end;
1001 end;
1003 SortGameStat(CustomStat.PlayerStat);
1004 end;
1006 g_Game_ExecuteEvent('onmapend');
1007 if not g_Game_IsClient then g_Player_ResetReady;
1008 gInterReadyCount := 0;
1010 // Çàòóõàþùèé ýêðàí:
1011 EndingGameCounter := 255;
1012 gState := STATE_FOLD;
1013 gInterTime := 0;
1014 if gDefInterTime < 0 then
1015 gInterEndTime := IfThen((gGameSettings.GameType = GT_SERVER) and (gPlayer1 = nil), 15000, 25000)
1016 else
1017 gInterEndTime := gDefInterTime * 1000;
1018 end;
1020 EXIT_ENDLEVELSINGLE: // Çàêîí÷èëñÿ óðîâåíü â Îäèíî÷íîé èãðå
1021 begin
1022 // Ñòàòèñòèêà Îäèíî÷íîé èãðû:
1023 SingleStat.GameTime := gTime;
1024 SingleStat.TwoPlayers := gPlayer2 <> nil;
1025 SingleStat.TotalSecrets := gSecretsCount;
1026 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
1027 SingleStat.PlayerStat[0].Kills := gPlayer1.MonsterKills;
1028 SingleStat.PlayerStat[0].Secrets := gPlayer1.Secrets;
1029 // Ñòàòèñòèêà âòîðîãî èãðîêà (åñëè åñòü):
1030 if SingleStat.TwoPlayers then
1031 begin
1032 SingleStat.PlayerStat[1].Kills := gPlayer2.MonsterKills;
1033 SingleStat.PlayerStat[1].Secrets := gPlayer2.Secrets;
1034 end;
1036 g_Game_ExecuteEvent('onmapend');
1038 // Åñòü åùå êàðòû:
1039 if gNextMap <> '' then
1040 begin
1041 gMusic.SetByName('MUSIC_INTERMUS');
1042 gMusic.Play();
1043 gState := STATE_INTERSINGLE;
1044 e_UnpressAllKeys();
1046 g_Game_ExecuteEvent('oninter');
1047 end
1048 else // Áîëüøå íåò êàðò
1049 begin
1050 // Çàòóõàþùèé ýêðàí:
1051 EndingGameCounter := 255;
1052 gState := STATE_FOLD;
1053 end;
1054 end;
1055 end;
1057 // Îêîí÷àíèå îáðàáîòàíî:
1058 if gExit <> EXIT_QUIT then
1059 gExit := 0;
1060 end;
1062 procedure drawTime(X, Y: Integer); inline;
1063 begin
1064 e_TextureFontPrint(x, y,
1065 Format('%d:%.2d:%.2d', [
1066 gTime div 1000 div 3600,
1067 (gTime div 1000 div 60) mod 60,
1068 gTime div 1000 mod 60
1069 ]),
1070 gStdFont);
1071 end;
1073 procedure DrawStat();
1074 var
1075 pc, x, y, w, h: Integer;
1076 w1, w2, w3, w4: Integer;
1077 a, aa: Integer;
1078 cw, ch, r, g, b, rr, gg, bb: Byte;
1079 s1, s2, s3: String;
1080 _y: Integer;
1081 stat: TPlayerStatArray;
1082 wad, map: string;
1083 mapstr: string;
1084 begin
1085 s1 := '';
1086 s2 := '';
1087 s3 := '';
1088 pc := g_Player_GetCount;
1089 e_TextureFontGetSize(gStdFont, cw, ch);
1091 w := gScreenWidth-(gScreenWidth div 5);
1092 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
1093 h := 32+ch*(11+pc)
1094 else
1095 h := 40+ch*5+(ch+8)*pc;
1096 x := (gScreenWidth div 2)-(w div 2);
1097 y := (gScreenHeight div 2)-(h div 2);
1099 e_DrawFillQuad(x, y, x+w-1, y+h-1, 64, 64, 64, 32);
1100 e_DrawQuad(x, y, x+w-1, y+h-1, 255, 127, 0);
1102 drawTime(x+w-78, y+8);
1104 wad := g_ExtractWadNameNoPath(gMapInfo.Map);
1105 map := g_ExtractFileName(gMapInfo.Map);
1106 mapstr := wad + ':\' + map + ' - ' + gMapInfo.Name;
1108 case gGameSettings.GameMode of
1109 GM_DM:
1110 begin
1111 if gGameSettings.MaxLives = 0 then
1112 s1 := _lc[I_GAME_DM]
1113 else
1114 s1 := _lc[I_GAME_LMS];
1115 s2 := Format(_lc[I_GAME_FRAG_LIMIT], [gGameSettings.GoalLimit]);
1116 s3 := Format(_lc[I_GAME_TIME_LIMIT], [gGameSettings.TimeLimit div 3600, (gGameSettings.TimeLimit div 60) mod 60, gGameSettings.TimeLimit mod 60]);
1117 end;
1119 GM_TDM:
1120 begin
1121 if gGameSettings.MaxLives = 0 then
1122 s1 := _lc[I_GAME_TDM]
1123 else
1124 s1 := _lc[I_GAME_TLMS];
1125 s2 := Format(_lc[I_GAME_FRAG_LIMIT], [gGameSettings.GoalLimit]);
1126 s3 := Format(_lc[I_GAME_TIME_LIMIT], [gGameSettings.TimeLimit div 3600, (gGameSettings.TimeLimit div 60) mod 60, gGameSettings.TimeLimit mod 60]);
1127 end;
1129 GM_CTF:
1130 begin
1131 s1 := _lc[I_GAME_CTF];
1132 s2 := Format(_lc[I_GAME_SCORE_LIMIT], [gGameSettings.GoalLimit]);
1133 s3 := Format(_lc[I_GAME_TIME_LIMIT], [gGameSettings.TimeLimit div 3600, (gGameSettings.TimeLimit div 60) mod 60, gGameSettings.TimeLimit mod 60]);
1134 end;
1136 GM_COOP:
1137 begin
1138 if gGameSettings.MaxLives = 0 then
1139 s1 := _lc[I_GAME_COOP]
1140 else
1141 s1 := _lc[I_GAME_SURV];
1142 s2 := _lc[I_GAME_MONSTERS] + ' ' + IntToStr(gCoopMonstersKilled) + '/' + IntToStr(gTotalMonsters);
1143 s3 := _lc[I_GAME_SECRETS] + ' ' + IntToStr(gCoopSecretsFound) + '/' + IntToStr(gSecretsCount);
1144 end;
1146 else
1147 begin
1148 s1 := '';
1149 s2 := '';
1150 end;
1151 end;
1153 _y := y+8;
1154 e_TextureFontPrintEx(x+(w div 2)-(Length(s1)*cw div 2), _y, s1, gStdFont, 255, 255, 255, 1);
1155 _y := _y+ch+8;
1156 e_TextureFontPrintEx(x+(w div 2)-(Length(mapstr)*cw div 2), _y, mapstr, gStdFont, 200, 200, 200, 1);
1157 _y := _y+ch+8;
1158 e_TextureFontPrintEx(x+16, _y, s2, gStdFont, 200, 200, 200, 1);
1160 e_TextureFontPrintEx(x+w-16-(Length(s3))*cw, _y, s3,
1161 gStdFont, 200, 200, 200, 1);
1163 if NetMode = NET_SERVER then
1164 e_TextureFontPrintEx(x+8, y + 8, _lc[I_NET_SERVER], gStdFont, 255, 255, 255, 1)
1165 else
1166 if NetMode = NET_CLIENT then
1167 e_TextureFontPrintEx(x+8, y + 8,
1168 NetClientIP + ':' + IntToStr(NetClientPort), gStdFont, 255, 255, 255, 1);
1170 if pc = 0 then
1171 Exit;
1172 stat := g_Player_GetStats();
1173 SortGameStat(stat);
1175 w2 := (w-16) div 6 + 48; // øèðèíà 2 ñòîëáöà
1176 w3 := (w-16) div 6; // øèðèíà 3 è 4 ñòîëáöîâ
1177 w4 := w3;
1178 w1 := w-16-w2-w3-w4; // îñòàâøååñÿ ïðîñòðàíñòâî - äëÿ öâåòà è èìåíè èãðîêà
1180 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
1181 begin
1182 _y := _y+ch+ch;
1184 for a := TEAM_RED to TEAM_BLUE do
1185 begin
1186 if a = TEAM_RED then
1187 begin
1188 s1 := _lc[I_GAME_TEAM_RED];
1189 r := 255;
1190 g := 0;
1191 b := 0;
1192 end
1193 else
1194 begin
1195 s1 := _lc[I_GAME_TEAM_BLUE];
1196 r := 0;
1197 g := 0;
1198 b := 255;
1199 end;
1201 e_TextureFontPrintEx(x+16, _y, s1, gStdFont, r, g, b, 1);
1202 e_TextureFontPrintEx(x+w1+16, _y, IntToStr(gTeamStat[a].Goals),
1203 gStdFont, r, g, b, 1);
1205 _y := _y+ch+(ch div 4);
1206 e_DrawLine(1, x+16, _y, x+w-16, _y, r, g, b);
1207 _y := _y+(ch div 4);
1209 for aa := 0 to High(stat) do
1210 if stat[aa].Team = a then
1211 with stat[aa] do
1212 begin
1213 if Spectator then
1214 begin
1215 rr := r div 2;
1216 gg := g div 2;
1217 bb := b div 2;
1218 end
1219 else
1220 begin
1221 rr := r;
1222 gg := g;
1223 bb := b;
1224 end;
1225 // Èìÿ
1226 e_TextureFontPrintEx(x+16, _y, Name, gStdFont, rr, gg, bb, 1);
1227 // Ïèíã/ïîòåðè
1228 e_TextureFontPrintEx(x+w1+16, _y, Format(_lc[I_GAME_PING_MS], [Ping, Loss]), gStdFont, rr, gg, bb, 1);
1229 // Ôðàãè
1230 e_TextureFontPrintEx(x+w1+w2+16, _y, IntToStr(Frags), gStdFont, rr, gg, bb, 1);
1231 // Ñìåðòè
1232 e_TextureFontPrintEx(x+w1+w2+w3+16, _y, IntToStr(Deaths), gStdFont, rr, gg, bb, 1);
1233 _y := _y+ch;
1234 end;
1236 _y := _y+ch;
1237 end;
1238 end
1239 else if gGameSettings.GameMode in [GM_DM, GM_COOP] then
1240 begin
1241 _y := _y+ch+ch;
1242 e_TextureFontPrintEx(x+16, _y, _lc[I_GAME_PLAYER_NAME], gStdFont, 255, 127, 0, 1);
1243 e_TextureFontPrintEx(x+16+w1, _y, _lc[I_GAME_PING], gStdFont, 255, 127, 0, 1);
1244 e_TextureFontPrintEx(x+16+w1+w2, _y, _lc[I_GAME_FRAGS], gStdFont, 255, 127, 0, 1);
1245 e_TextureFontPrintEx(x+16+w1+w2+w3, _y, _lc[I_GAME_DEATHS], gStdFont, 255, 127, 0, 1);
1247 _y := _y+ch+8;
1248 for aa := 0 to High(stat) do
1249 with stat[aa] do
1250 begin
1251 if Spectator then
1252 begin
1253 r := 127;
1254 g := 64;
1255 end
1256 else
1257 begin
1258 r := 255;
1259 g := 127;
1260 end;
1261 // Öâåò èãðîêà
1262 e_DrawFillQuad(x+16, _y+4, x+32-1, _y+16+4-1, Color.R, Color.G, Color.B, 0);
1263 e_DrawQuad(x+16, _y+4, x+32-1, _y+16+4-1, 192, 192, 192);
1264 // Èìÿ
1265 e_TextureFontPrintEx(x+16+16+8, _y+4, Name, gStdFont, r, g, 0, 1);
1266 // Ïèíã/ïîòåðè
1267 e_TextureFontPrintEx(x+w1+16, _y+4, Format(_lc[I_GAME_PING_MS], [Ping, Loss]), gStdFont, r, g, 0, 1);
1268 // Ôðàãè
1269 e_TextureFontPrintEx(x+w1+w2+16, _y+4, IntToStr(Frags), gStdFont, r, g, 0, 1);
1270 // Ñìåðòè
1271 e_TextureFontPrintEx(x+w1+w2+w3+16, _y+4, IntToStr(Deaths), gStdFont, r, g, 0, 1);
1272 _y := _y+ch+8;
1273 end;
1274 end
1275 end;
1277 procedure g_Game_Init();
1278 var
1279 SR: TSearchRec;
1280 begin
1281 gExit := 0;
1282 gMapToDelete := '';
1283 gTempDelete := False;
1285 sfsGCDisable(); // temporary disable removing of temporary volumes
1287 try
1288 TEXTUREFILTER := GL_LINEAR;
1289 g_Texture_CreateWADEx('MENU_BACKGROUND', GameWAD+':TEXTURES\TITLE');
1290 g_Texture_CreateWADEx('INTER', GameWAD+':TEXTURES\INTER');
1291 g_Texture_CreateWADEx('ENDGAME_EN', GameWAD+':TEXTURES\ENDGAME_EN');
1292 g_Texture_CreateWADEx('ENDGAME_RU', GameWAD+':TEXTURES\ENDGAME_RU');
1293 TEXTUREFILTER := GL_NEAREST;
1295 LoadStdFont('STDTXT', 'STDFONT', gStdFont);
1296 LoadFont('MENUTXT', 'MENUFONT', gMenuFont);
1297 LoadFont('SMALLTXT', 'SMALLFONT', gMenuSmallFont);
1299 g_Game_ClearLoading();
1300 g_Game_SetLoadingText(Format('Doom 2D: Forever %s', [GAME_VERSION]), 0, False);
1301 g_Game_SetLoadingText('', 0, False);
1303 g_Game_SetLoadingText(_lc[I_LOAD_CONSOLE], 0, False);
1304 g_Console_Init();
1306 g_Game_SetLoadingText(_lc[I_LOAD_MODELS], 0, False);
1307 g_PlayerModel_LoadData();
1309 if FindFirst(ModelsDir+'*.wad', faAnyFile, SR) = 0 then
1310 repeat
1311 if not g_PlayerModel_Load(ModelsDir+SR.Name) then
1312 e_WriteLog(Format('Error loading model %s', [SR.Name]), TMsgType.Warning);
1313 until FindNext(SR) <> 0;
1314 FindClose(SR);
1316 if FindFirst(ModelsDir+'*.pk3', faAnyFile, SR) = 0 then
1317 repeat
1318 if not g_PlayerModel_Load(ModelsDir+SR.Name) then
1319 e_WriteLog(Format('Error loading model %s', [SR.Name]), TMsgType.Warning);
1320 until FindNext(SR) <> 0;
1321 FindClose(SR);
1323 if FindFirst(ModelsDir+'*.zip', faAnyFile, SR) = 0 then
1324 repeat
1325 if not g_PlayerModel_Load(ModelsDir+SR.Name) then
1326 e_WriteLog(Format('Error loading model %s', [SR.Name]), TMsgType.Warning);
1327 until FindNext(SR) <> 0;
1328 FindClose(SR);
1330 gGameOn := false;
1331 gPauseMain := false;
1332 gPauseHolmes := false;
1333 gTime := 0;
1335 {e_MouseInfo.Accel := 1.0;}
1337 g_Game_SetLoadingText(_lc[I_LOAD_GAME_DATA], 0, False);
1338 g_Game_LoadData();
1340 g_Game_SetLoadingText(_lc[I_LOAD_MUSIC], 0, False);
1341 g_Sound_CreateWADEx('MUSIC_INTERMUS', GameWAD+':MUSIC\INTERMUS', True);
1342 g_Sound_CreateWADEx('MUSIC_MENU', GameWAD+':MUSIC\MENU', True);
1343 g_Sound_CreateWADEx('MUSIC_ROUNDMUS', GameWAD+':MUSIC\ROUNDMUS', True, True);
1344 g_Sound_CreateWADEx('MUSIC_STDENDMUS', GameWAD+':MUSIC\ENDMUS', True);
1346 g_Game_SetLoadingText(_lc[I_LOAD_MENUS], 0, False);
1347 g_Menu_Init();
1349 gMusic := TMusic.Create();
1350 gMusic.SetByName('MUSIC_MENU');
1351 gMusic.Play();
1353 gGameSettings.WarmupTime := 30;
1355 gState := STATE_MENU;
1357 SetLength(gEvents, 6);
1358 gEvents[0].Name := 'ongamestart';
1359 gEvents[1].Name := 'ongameend';
1360 gEvents[2].Name := 'onmapstart';
1361 gEvents[3].Name := 'onmapend';
1362 gEvents[4].Name := 'oninter';
1363 gEvents[5].Name := 'onwadend';
1364 finally
1365 sfsGCEnable(); // enable releasing unused volumes
1366 end;
1367 end;
1369 procedure g_Game_Free(freeTextures: Boolean=true);
1370 begin
1371 if NetMode = NET_CLIENT then g_Net_Disconnect();
1372 if NetMode = NET_SERVER then g_Net_Host_Die();
1374 g_Map_Free(freeTextures);
1375 g_Player_Free();
1376 g_Player_RemoveAllCorpses();
1378 gGameSettings.GameType := GT_NONE;
1379 if gGameSettings.GameMode = GM_SINGLE then
1380 gGameSettings.GameMode := GM_DM;
1381 gSwitchGameMode := gGameSettings.GameMode;
1383 gChatShow := False;
1384 gExitByTrigger := False;
1385 end;
1387 function IsActivePlayer(p: TPlayer): Boolean;
1388 begin
1389 Result := False;
1390 if p = nil then
1391 Exit;
1392 Result := (not p.FDummy) and (not p.FSpectator);
1393 end;
1395 function GetActivePlayer_ByID(ID: Integer): TPlayer;
1396 var
1397 a: Integer;
1398 begin
1399 Result := nil;
1400 if ID < 0 then
1401 Exit;
1402 if gPlayers = nil then
1403 Exit;
1404 for a := Low(gPlayers) to High(gPlayers) do
1405 if IsActivePlayer(gPlayers[a]) then
1406 begin
1407 if gPlayers[a].UID <> ID then
1408 continue;
1409 Result := gPlayers[a];
1410 break;
1411 end;
1412 end;
1414 function GetActivePlayerID_Next(Skip: Integer = -1): Integer;
1415 var
1416 a, idx: Integer;
1417 ids: Array of Word;
1418 begin
1419 Result := -1;
1420 if gPlayers = nil then
1421 Exit;
1422 SetLength(ids, 0);
1423 idx := -1;
1424 for a := Low(gPlayers) to High(gPlayers) do
1425 if IsActivePlayer(gPlayers[a]) then
1426 begin
1427 SetLength(ids, Length(ids) + 1);
1428 ids[High(ids)] := gPlayers[a].UID;
1429 if gPlayers[a].UID = Skip then
1430 idx := High(ids);
1431 end;
1432 if Length(ids) = 0 then
1433 Exit;
1434 if idx = -1 then
1435 Result := ids[0]
1436 else
1437 Result := ids[(idx + 1) mod Length(ids)];
1438 end;
1440 function GetActivePlayerID_Prev(Skip: Integer = -1): Integer;
1441 var
1442 a, idx: Integer;
1443 ids: Array of Word;
1444 begin
1445 Result := -1;
1446 if gPlayers = nil then
1447 Exit;
1448 SetLength(ids, 0);
1449 idx := -1;
1450 for a := Low(gPlayers) to High(gPlayers) do
1451 if IsActivePlayer(gPlayers[a]) then
1452 begin
1453 SetLength(ids, Length(ids) + 1);
1454 ids[High(ids)] := gPlayers[a].UID;
1455 if gPlayers[a].UID = Skip then
1456 idx := High(ids);
1457 end;
1458 if Length(ids) = 0 then
1459 Exit;
1460 if idx = -1 then
1461 Result := ids[Length(ids) - 1]
1462 else
1463 Result := ids[(Length(ids) - 1 + idx) mod Length(ids)];
1464 end;
1466 function GetActivePlayerID_Random(Skip: Integer = -1): Integer;
1467 var
1468 a, idx: Integer;
1469 ids: Array of Word;
1470 begin
1471 Result := -1;
1472 if gPlayers = nil then
1473 Exit;
1474 SetLength(ids, 0);
1475 idx := -1;
1476 for a := Low(gPlayers) to High(gPlayers) do
1477 if IsActivePlayer(gPlayers[a]) then
1478 begin
1479 SetLength(ids, Length(ids) + 1);
1480 ids[High(ids)] := gPlayers[a].UID;
1481 if gPlayers[a].UID = Skip then
1482 idx := High(ids);
1483 end;
1484 if Length(ids) = 0 then
1485 Exit;
1486 if Length(ids) = 1 then
1487 begin
1488 Result := ids[0];
1489 Exit;
1490 end;
1491 Result := ids[Random(Length(ids))];
1492 a := 10;
1493 while (idx <> -1) and (Result = Skip) and (a > 0) do
1494 begin
1495 Result := ids[Random(Length(ids))];
1496 Dec(a);
1497 end;
1498 end;
1500 function GetRandomSpectMode(Current: Byte): Byte;
1501 label
1502 retry;
1503 begin
1504 Result := Current;
1505 retry:
1506 case Random(7) of
1507 0: Result := SPECT_STATS;
1508 1: Result := SPECT_MAPVIEW;
1509 2: Result := SPECT_MAPVIEW;
1510 3: Result := SPECT_PLAYERS;
1511 4: Result := SPECT_PLAYERS;
1512 5: Result := SPECT_PLAYERS;
1513 6: Result := SPECT_PLAYERS;
1514 end;
1515 if (Current in [SPECT_STATS, SPECT_MAPVIEW]) and (Current = Result) then
1516 goto retry;
1517 end;
1519 procedure ProcessPlayerControls (plr: TPlayer; p: Integer; var MoveButton: Byte);
1520 var
1521 time: Word;
1522 strafeDir: Byte;
1523 i: Integer;
1524 begin
1525 if (plr = nil) then exit;
1526 if (p = 2) then time := 1000 else time := 1;
1527 strafeDir := MoveButton shr 4;
1528 MoveButton := MoveButton and $0F;
1530 if gPlayerAction[p, ACTION_MOVELEFT] and (not gPlayerAction[p, ACTION_MOVERIGHT]) then
1531 MoveButton := 1 // Íàæàòà òîëüêî "Âëåâî"
1532 else if (not gPlayerAction[p, ACTION_MOVELEFT]) and gPlayerAction[p, ACTION_MOVERIGHT] then
1533 MoveButton := 2 // Íàæàòà òîëüêî "Âïðàâî"
1534 else if (not gPlayerAction[p, ACTION_MOVELEFT]) and (not gPlayerAction[p, ACTION_MOVERIGHT]) then
1535 MoveButton := 0; // Íå íàæàòû íè "Âëåâî", íè "Âïðàâî"
1537 // Ñåé÷àñ èëè ðàíüøå áûëè íàæàòû "Âëåâî"/"Âïðàâî" => ïåðåäàåì èãðîêó:
1538 if MoveButton = 1 then
1539 plr.PressKey(KEY_LEFT, time)
1540 else if MoveButton = 2 then
1541 plr.PressKey(KEY_RIGHT, time);
1543 // if we have "strafe" key, turn off old strafe mechanics
1544 if gPlayerAction[p, ACTION_STRAFE] then
1545 begin
1546 // new strafe mechanics
1547 if (strafeDir = 0) then
1548 strafeDir := MoveButton; // start strafing
1549 // now set direction according to strafe (reversed)
1550 if (strafeDir = 2) then
1551 plr.SetDirection(TDirection.D_LEFT)
1552 else if (strafeDir = 1) then
1553 plr.SetDirection(TDirection.D_RIGHT)
1554 end
1555 else
1556 begin
1557 strafeDir := 0; // not strafing anymore
1558 // Ðàíüøå áûëà íàæàòà "Âïðàâî", à ñåé÷àñ "Âëåâî" => áåæèì âïðàâî, ñìîòðèì âëåâî:
1559 if (MoveButton = 2) and gPlayerAction[p, ACTION_MOVELEFT] then
1560 plr.SetDirection(TDirection.D_LEFT)
1561 // Ðàíüøå áûëà íàæàòà "Âëåâî", à ñåé÷àñ "Âïðàâî" => áåæèì âëåâî, ñìîòðèì âïðàâî:
1562 else if (MoveButton = 1) and gPlayerAction[p, ACTION_MOVERIGHT] then
1563 plr.SetDirection(TDirection.D_RIGHT)
1564 // ×òî-òî áûëî íàæàòî è íå èçìåíèëîñü => êóäà áåæèì, òóäà è ñìîòðèì:
1565 else if MoveButton <> 0 then
1566 plr.SetDirection(TDirection(MoveButton-1))
1567 end;
1569 // fix movebutton state
1570 MoveButton := MoveButton or (strafeDir shl 4);
1572 // Îñòàëüíûå êëàâèøè:
1573 if gPlayerAction[p, ACTION_JUMP] then plr.PressKey(KEY_JUMP, time);
1574 if gPlayerAction[p, ACTION_LOOKUP] then plr.PressKey(KEY_UP, time);
1575 if gPlayerAction[p, ACTION_LOOKDOWN] then plr.PressKey(KEY_DOWN, time);
1576 if gPlayerAction[p, ACTION_ATTACK] then plr.PressKey(KEY_FIRE);
1577 if gPlayerAction[p, ACTION_WEAPNEXT] then plr.PressKey(KEY_NEXTWEAPON);
1578 if gPlayerAction[p, ACTION_WEAPPREV] then plr.PressKey(KEY_PREVWEAPON);
1579 if gPlayerAction[p, ACTION_ACTIVATE] then plr.PressKey(KEY_OPEN);
1581 gPlayerAction[p, ACTION_WEAPNEXT] := False; // HACK, remove after readyweaon&pendinweapon implementation
1582 gPlayerAction[p, ACTION_WEAPPREV] := False; // HACK, remove after readyweaon&pendinweapon implementation
1584 for i := WP_FIRST to WP_LAST do
1585 begin
1586 if gSelectWeapon[p, i] then
1587 begin
1588 plr.QueueWeaponSwitch(i); // all choices are passed there, and god will take the best
1589 gSelectWeapon[p, i] := False
1590 end
1591 end;
1593 // HACK: add dynlight here
1594 if gwin_k8_enable_light_experiments then
1595 begin
1596 if e_KeyPressed(IK_F8) and gGameOn and (not gConsoleShow) and (g_ActiveWindow = nil) then
1597 begin
1598 g_playerLight := true;
1599 end;
1600 if e_KeyPressed(IK_F9) and gGameOn and (not gConsoleShow) and (g_ActiveWindow = nil) then
1601 begin
1602 g_playerLight := false;
1603 end;
1604 end;
1606 if gwin_has_stencil and g_playerLight then g_AddDynLight(plr.GameX+32, plr.GameY+40, 128, 1, 1, 0, 0.6);
1607 end;
1609 // HACK: don't have a "key was pressed" function
1610 procedure InterReady();
1611 begin
1612 if InterReadyTime > gTime then Exit;
1613 InterReadyTime := gTime + 3000;
1614 MC_SEND_CheatRequest(NET_CHEAT_READY);
1615 end;
1617 procedure g_Game_Update();
1618 var
1619 Msg: g_gui.TMessage;
1620 Time: Int64;
1621 a: Byte;
1622 w: Word;
1623 i, b: Integer;
1625 function sendMonsPos (mon: TMonster): Boolean;
1626 begin
1627 result := false; // don't stop
1628 // this will also reset "need-send" flag
1629 if mon.gncNeedSend then
1630 begin
1631 MH_SEND_MonsterPos(mon.UID);
1632 end
1633 else if (mon.MonsterType = MONSTER_BARREL) then
1634 begin
1635 if (mon.GameVelX <> 0) or (mon.GameVelY <> 0) then MH_SEND_MonsterPos(mon.UID);
1636 end
1637 else if (mon.MonsterState <> MONSTATE_SLEEP) then
1638 begin
1639 if (mon.MonsterState <> MONSTATE_DEAD) or (mon.GameVelX <> 0) or (mon.GameVelY <> 0) then MH_SEND_MonsterPos(mon.UID);
1640 end;
1641 end;
1643 function sendMonsPosUnexpected (mon: TMonster): Boolean;
1644 begin
1645 result := false; // don't stop
1646 // this will also reset "need-send" flag
1647 if mon.gncNeedSend then MH_SEND_MonsterPos(mon.UID);
1648 end;
1650 var
1651 reliableUpdate: Boolean;
1652 begin
1653 g_ResetDynlights();
1654 framePool.reset();
1656 // Ïîðà âûêëþ÷àòü èãðó:
1657 if gExit = EXIT_QUIT then
1658 Exit;
1659 // Èãðà çàêîí÷èëàñü - îáðàáàòûâàåì:
1660 if gExit <> 0 then
1661 begin
1662 EndGame();
1663 if gExit = EXIT_QUIT then
1664 Exit;
1665 end;
1667 // ×èòàåì êëàâèàòóðó è äæîéñòèê, åñëè îêíî àêòèâíî
1668 // no need to, as we'll do it in event handler
1670 // Îáíîâëÿåì êîíñîëü (äâèæåíèå è ñîîáùåíèÿ):
1671 g_Console_Update();
1673 if (NetMode = NET_NONE) and (g_Game_IsNet) and (gGameOn or (gState in [STATE_FOLD, STATE_INTERCUSTOM])) then
1674 begin
1675 gExit := EXIT_SIMPLE;
1676 EndGame();
1677 Exit;
1678 end;
1680 case gState of
1681 STATE_INTERSINGLE, // Ñòàòèñòêà ïîñëå ïðîõîæäåíèÿ óðîâíÿ â Îäèíî÷íîé èãðå
1682 STATE_INTERCUSTOM, // Ñòàòèñòêà ïîñëå ïðîõîæäåíèÿ óðîâíÿ â Ñâîåé èãðå
1683 STATE_INTERTEXT, // Òåêñò ìåæäó óðîâíÿìè
1684 STATE_INTERPIC: // Êàðòèíêà ìåæäó óðîâíÿìè
1685 begin
1686 if g_Game_IsNet and g_Game_IsServer then
1687 begin
1688 gInterTime := gInterTime + GAME_TICK;
1689 a := Min((gInterEndTime - gInterTime) div 1000 + 1, 255);
1690 if a <> gServInterTime then
1691 begin
1692 gServInterTime := a;
1693 MH_SEND_TimeSync(gServInterTime);
1694 end;
1695 end;
1697 if (not g_Game_IsClient) and
1701 e_KeyPressed(IK_RETURN) or e_KeyPressed(IK_KPRETURN) or e_KeyPressed(IK_SPACE) or
1702 e_KeyPressed(VK_FIRE) or e_KeyPressed(VK_OPEN) or
1703 e_KeyPressed(JOY0_ATTACK) or e_KeyPressed(JOY1_ATTACK) or
1704 e_KeyPressed(JOY2_ATTACK) or e_KeyPressed(JOY3_ATTACK)
1706 and (not gJustChatted) and (not gConsoleShow) and (not gChatShow)
1707 and (g_ActiveWindow = nil)
1709 or (g_Game_IsNet and ((gInterTime > gInterEndTime) or (gInterReadyCount >= NetClientCount)))
1711 then
1712 begin // Íàæàëè <Enter>/<Ïðîáåë> èëè ïðîøëî äîñòàòî÷íî âðåìåíè:
1713 g_Game_StopAllSounds(True);
1715 if gMapOnce then // Ýòî áûë òåñò
1716 gExit := EXIT_SIMPLE
1717 else
1718 if gNextMap <> '' then // Ïåðåõîäèì íà ñëåäóþùóþ êàðòó
1719 g_Game_ChangeMap(gNextMap)
1720 else // Ñëåäóþùåé êàðòû íåò
1721 begin
1722 if gGameSettings.GameType in [GT_CUSTOM, GT_SERVER] then
1723 begin
1724 // Âûõîä â ãëàâíîå ìåíþ:
1725 g_Game_Free;
1726 g_GUI_ShowWindow('MainMenu');
1727 gMusic.SetByName('MUSIC_MENU');
1728 gMusic.Play();
1729 gState := STATE_MENU;
1730 end else
1731 begin
1732 // Ôèíàëüíàÿ êàðòèíêà:
1733 g_Game_ExecuteEvent('onwadend');
1734 g_Game_Free();
1735 if not gMusic.SetByName('MUSIC_endmus') then
1736 gMusic.SetByName('MUSIC_STDENDMUS');
1737 gMusic.Play();
1738 gState := STATE_ENDPIC;
1739 end;
1740 g_Game_ExecuteEvent('ongameend');
1741 end;
1743 Exit;
1744 end
1745 else if g_Game_IsClient and
1748 e_KeyPressed(IK_RETURN) or e_KeyPressed(IK_KPRETURN) or e_KeyPressed(IK_SPACE) or
1749 e_KeyPressed(VK_FIRE) or e_KeyPressed(VK_OPEN) or
1750 e_KeyPressed(JOY0_ATTACK) or e_KeyPressed(JOY1_ATTACK) or
1751 e_KeyPressed(JOY2_ATTACK) or e_KeyPressed(JOY3_ATTACK)
1753 and (not gJustChatted) and (not gConsoleShow) and (not gChatShow)
1754 and (g_ActiveWindow = nil)
1756 then
1757 begin
1758 // ready / unready
1759 InterReady();
1760 end;
1762 if gState = STATE_INTERTEXT then
1763 if InterText.counter > 0 then
1764 InterText.counter := InterText.counter - 1;
1765 end;
1767 STATE_FOLD: // Çàòóõàíèå ýêðàíà
1768 begin
1769 if EndingGameCounter = 0 then
1770 begin
1771 // Çàêîí÷èëñÿ óðîâåíü â Ñâîåé èãðå:
1772 if gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT] then
1773 begin
1774 InterReadyTime := -1;
1775 if gLastMap and (gGameSettings.GameMode = GM_COOP) then
1776 begin
1777 g_Game_ExecuteEvent('onwadend');
1778 if not gMusic.SetByName('MUSIC_endmus') then
1779 gMusic.SetByName('MUSIC_STDENDMUS');
1780 end
1781 else
1782 gMusic.SetByName('MUSIC_ROUNDMUS');
1784 gMusic.Play();
1785 gState := STATE_INTERCUSTOM;
1786 e_UnpressAllKeys();
1787 end
1788 else // Çàêîí÷èëàñü ïîñëåäíÿÿ êàðòà â Îäèíî÷íîé èãðå
1789 begin
1790 gMusic.SetByName('MUSIC_INTERMUS');
1791 gMusic.Play();
1792 gState := STATE_INTERSINGLE;
1793 e_UnpressAllKeys();
1794 end;
1795 g_Game_ExecuteEvent('oninter');
1796 end
1797 else
1798 DecMin(EndingGameCounter, 6, 0);
1799 end;
1801 STATE_ENDPIC: // Êàðòèíêà îêîí÷àíèÿ ìåãàÂàäà
1802 begin
1803 if gMapOnce then // Ýòî áûë òåñò
1804 begin
1805 gExit := EXIT_SIMPLE;
1806 Exit;
1807 end;
1808 end;
1810 STATE_SLIST:
1811 g_Serverlist_Control(slCurrent, slTable);
1812 end;
1814 // Ñòàòèñòèêà ïî Tab:
1815 if gGameOn then
1816 IsDrawStat := (not gConsoleShow) and (not gChatShow) and (gGameSettings.GameType <> GT_SINGLE) and g_Console_Action(ACTION_SCORES);
1818 // Èãðà èäåò:
1819 if gGameOn and not gPause and (gState <> STATE_FOLD) then
1820 begin
1821 // Âðåìÿ += 28 ìèëëèñåêóíä:
1822 gTime := gTime + GAME_TICK;
1824 // Ñîîáùåíèå ïîñåðåäèíå ýêðàíà:
1825 if MessageTime = 0 then
1826 MessageText := '';
1827 if MessageTime > 0 then
1828 MessageTime := MessageTime - 1;
1830 if (g_Game_IsServer) then
1831 begin
1832 // Áûë çàäàí ëèìèò âðåìåíè:
1833 if (gGameSettings.TimeLimit > 0) then
1834 if (gTime - gGameStartTime) div 1000 >= gGameSettings.TimeLimit then
1835 begin // Îí ïðîøåë => êîíåö óðîâíÿ
1836 g_Game_NextLevel();
1837 Exit;
1838 end;
1840 // Íàäî ðåñïàâíèòü èãðîêîâ â LMS:
1841 if (gLMSRespawn > LMS_RESPAWN_NONE) and (gLMSRespawnTime < gTime) then
1842 g_Game_RestartRound(gLMSSoftSpawn);
1844 // Ïðîâåðèì ðåçóëüòàò ãîëîñîâàíèÿ, åñëè âðåìÿ ïðîøëî
1845 if gVoteInProgress and (gVoteTimer < gTime) then
1846 g_Game_CheckVote
1847 else if gVotePassed and (gVoteCmdTimer < gTime) then
1848 begin
1849 g_Console_Process(gVoteCommand);
1850 gVoteCommand := '';
1851 gVotePassed := False;
1852 end;
1854 // Çàìåðÿåì âðåìÿ çàõâàòà ôëàãîâ
1855 if gFlags[FLAG_RED].State = FLAG_STATE_CAPTURED then
1856 gFlags[FLAG_RED].CaptureTime := gFlags[FLAG_RED].CaptureTime + GAME_TICK;
1857 if gFlags[FLAG_BLUE].State = FLAG_STATE_CAPTURED then
1858 gFlags[FLAG_BLUE].CaptureTime := gFlags[FLAG_BLUE].CaptureTime + GAME_TICK;
1860 // Áûë çàäàí ëèìèò ïîáåä:
1861 if (gGameSettings.GoalLimit > 0) then
1862 begin
1863 b := 0;
1865 if gGameSettings.GameMode = GM_DM then
1866 begin // Â DM èùåì èãðîêà ñ max ôðàãàìè
1867 for i := 0 to High(gPlayers) do
1868 if gPlayers[i] <> nil then
1869 if gPlayers[i].Frags > b then
1870 b := gPlayers[i].Frags;
1871 end
1872 else
1873 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
1874 begin //  CTF/TDM âûáèðàåì êîìàíäó ñ íàèáîëüøèì ñ÷åòîì
1875 b := Max(gTeamStat[TEAM_RED].Goals, gTeamStat[TEAM_BLUE].Goals);
1876 end;
1878 // Ëèìèò ïîáåä íàáðàí => êîíåö óðîâíÿ:
1879 if b >= gGameSettings.GoalLimit then
1880 begin
1881 g_Game_NextLevel();
1882 Exit;
1883 end;
1884 end;
1886 // Îáðàáàòûâàåì êëàâèøè èãðîêîâ:
1887 if gPlayer1 <> nil then gPlayer1.ReleaseKeys();
1888 if gPlayer2 <> nil then gPlayer2.ReleaseKeys();
1889 if (not gConsoleShow) and (not gChatShow) and (g_ActiveWindow = nil) then
1890 begin
1891 ProcessPlayerControls(gPlayer1, 0, P1MoveButton);
1892 ProcessPlayerControls(gPlayer2, 1, P2MoveButton);
1893 end // if not console
1894 else
1895 begin
1896 if g_Game_IsNet and (gPlayer1 <> nil) then gPlayer1.PressKey(KEY_CHAT, 10000);
1897 end;
1898 // process weapon switch queue
1899 end; // if server
1901 // Íàáëþäàòåëü
1902 if (gPlayer1 = nil) and (gPlayer2 = nil) and
1903 (not gConsoleShow) and (not gChatShow) and (g_ActiveWindow = nil) then
1904 begin
1905 if not gSpectKeyPress then
1906 begin
1907 if gPlayerAction[0, ACTION_JUMP] and (not gSpectAuto) then
1908 begin
1909 // switch spect mode
1910 case gSpectMode of
1911 SPECT_NONE: ; // not spectator
1912 SPECT_STATS,
1913 SPECT_MAPVIEW: Inc(gSpectMode);
1914 SPECT_PLAYERS: gSpectMode := SPECT_STATS; // reset to 1
1915 end;
1916 gSpectKeyPress := True;
1917 end;
1918 if (gSpectMode = SPECT_MAPVIEW)
1919 and (not gSpectAuto) then
1920 begin
1921 if gPlayerAction[0, ACTION_MOVELEFT] then
1922 gSpectX := Max(gSpectX - gSpectStep, 0);
1923 if gPlayerAction[0, ACTION_MOVERIGHT] then
1924 gSpectX := Min(gSpectX + gSpectStep, gMapInfo.Width - gScreenWidth);
1925 if gPlayerAction[0, ACTION_LOOKUP] then
1926 gSpectY := Max(gSpectY - gSpectStep, 0);
1927 if gPlayerAction[0, ACTION_LOOKDOWN] then
1928 gSpectY := Min(gSpectY + gSpectStep, gMapInfo.Height - gScreenHeight);
1929 if gPlayerAction[0, ACTION_WEAPPREV] then
1930 begin
1931 // decrease step
1932 if gSpectStep > 4 then gSpectStep := gSpectStep shr 1;
1933 gSpectKeyPress := True;
1934 end;
1935 if gPlayerAction[0, ACTION_WEAPNEXT] then
1936 begin
1937 // increase step
1938 if gSpectStep < 64 then gSpectStep := gSpectStep shl 1;
1939 gSpectKeyPress := True;
1940 end;
1941 end;
1942 if (gSpectMode = SPECT_PLAYERS)
1943 and (not gSpectAuto) then
1944 begin
1945 if gPlayerAction[0, ACTION_LOOKUP] then
1946 begin
1947 // add second view
1948 gSpectViewTwo := True;
1949 gSpectKeyPress := True;
1950 end;
1951 if gPlayerAction[0, ACTION_LOOKDOWN] then
1952 begin
1953 // remove second view
1954 gSpectViewTwo := False;
1955 gSpectKeyPress := True;
1956 end;
1957 if gPlayerAction[0, ACTION_MOVELEFT] then
1958 begin
1959 // prev player (view 1)
1960 gSpectPID1 := GetActivePlayerID_Prev(gSpectPID1);
1961 gSpectKeyPress := True;
1962 end;
1963 if gPlayerAction[0, ACTION_MOVERIGHT] then
1964 begin
1965 // next player (view 1)
1966 gSpectPID1 := GetActivePlayerID_Next(gSpectPID1);
1967 gSpectKeyPress := True;
1968 end;
1969 if gPlayerAction[0, ACTION_WEAPPREV] then
1970 begin
1971 // prev player (view 2)
1972 gSpectPID2 := GetActivePlayerID_Prev(gSpectPID2);
1973 gSpectKeyPress := True;
1974 end;
1975 if gPlayerAction[0, ACTION_WEAPNEXT] then
1976 begin
1977 // next player (view 2)
1978 gSpectPID2 := GetActivePlayerID_Next(gSpectPID2);
1979 gSpectKeyPress := True;
1980 end;
1981 end;
1982 if gPlayerAction[0, ACTION_ATTACK] then
1983 begin
1984 if (gSpectMode = SPECT_STATS) and (not gSpectAuto) then
1985 begin
1986 gSpectAuto := True;
1987 gSpectAutoNext := 0;
1988 gSpectViewTwo := False;
1989 gSpectKeyPress := True;
1990 end
1991 else
1992 if gSpectAuto then
1993 begin
1994 gSpectMode := SPECT_STATS;
1995 gSpectAuto := False;
1996 gSpectKeyPress := True;
1997 end;
1998 end;
1999 end
2000 else
2001 if (not gPlayerAction[0, ACTION_JUMP]) and
2002 (not gPlayerAction[0, ACTION_ATTACK]) and
2003 (not gPlayerAction[0, ACTION_MOVELEFT]) and
2004 (not gPlayerAction[0, ACTION_MOVERIGHT]) and
2005 (not gPlayerAction[0, ACTION_LOOKUP]) and
2006 (not gPlayerAction[0, ACTION_LOOKDOWN]) and
2007 (not gPlayerAction[0, ACTION_WEAPPREV]) and
2008 (not gPlayerAction[0, ACTION_WEAPNEXT]) then
2009 gSpectKeyPress := False;
2011 if gSpectAuto then
2012 begin
2013 if gSpectMode = SPECT_MAPVIEW then
2014 begin
2015 i := Min(Max(gSpectX + gSpectAutoStepX, 0), gMapInfo.Width - gScreenWidth);
2016 if i = gSpectX then
2017 gSpectAutoNext := gTime
2018 else
2019 gSpectX := i;
2020 i := Min(Max(gSpectY + gSpectAutoStepY, 0), gMapInfo.Height - gScreenHeight);
2021 if i = gSpectY then
2022 gSpectAutoNext := gTime
2023 else
2024 gSpectY := i;
2025 end;
2026 if gSpectAutoNext <= gTime then
2027 begin
2028 if gSpectAutoNext > 0 then
2029 begin
2030 gSpectMode := GetRandomSpectMode(gSpectMode);
2031 case gSpectMode of
2032 SPECT_MAPVIEW:
2033 begin
2034 gSpectX := Random(gMapInfo.Width - gScreenWidth);
2035 gSpectY := Random(gMapInfo.Height - gScreenHeight);
2036 gSpectAutoStepX := Random(9) - 4;
2037 gSpectAutoStepY := Random(9) - 4;
2038 if ((gSpectX < 800) and (gSpectAutoStepX < 0)) or
2039 ((gSpectX > gMapInfo.Width - gScreenWidth - 800) and (gSpectAutoStepX > 0)) then
2040 gSpectAutoStepX := gSpectAutoStepX * -1;
2041 if ((gSpectY < 800) and (gSpectAutoStepY < 0)) or
2042 ((gSpectY > gMapInfo.Height - gScreenHeight - 800) and (gSpectAutoStepY > 0)) then
2043 gSpectAutoStepY := gSpectAutoStepY * -1;
2044 end;
2045 SPECT_PLAYERS:
2046 begin
2047 gSpectPID1 := GetActivePlayerID_Random(gSpectPID1);
2048 end;
2049 end;
2050 end;
2051 case gSpectMode of
2052 SPECT_STATS: gSpectAutoNext := gTime + (Random(3) + 5) * 1000;
2053 SPECT_MAPVIEW: gSpectAutoNext := gTime + (Random(4) + 7) * 1000;
2054 SPECT_PLAYERS: gSpectAutoNext := gTime + (Random(7) + 8) * 1000;
2055 end;
2056 end;
2057 end;
2058 end;
2060 // Îáíîâëÿåì âñå îñòàëüíîå:
2061 g_Map_Update();
2062 g_Items_Update();
2063 g_Triggers_Update();
2064 g_Weapon_Update();
2065 g_Monsters_Update();
2066 g_GFX_Update();
2067 g_Player_UpdateAll();
2068 g_Player_UpdatePhysicalObjects();
2070 // server: send newly spawned monsters unconditionally
2071 if (gGameSettings.GameType = GT_SERVER) then
2072 begin
2073 if (Length(gMonstersSpawned) > 0) then
2074 begin
2075 for I := 0 to High(gMonstersSpawned) do MH_SEND_MonsterSpawn(gMonstersSpawned[I]);
2076 SetLength(gMonstersSpawned, 0);
2077 end;
2078 end;
2080 if (gSoundTriggerTime > 8) then
2081 begin
2082 g_Game_UpdateTriggerSounds();
2083 gSoundTriggerTime := 0;
2084 end
2085 else
2086 begin
2087 Inc(gSoundTriggerTime);
2088 end;
2090 if (NetMode = NET_SERVER) then
2091 begin
2092 Inc(NetTimeToUpdate);
2093 Inc(NetTimeToReliable);
2095 // send monster updates
2096 if (NetTimeToReliable >= NetRelupdRate) or (NetTimeToUpdate >= NetUpdateRate) then
2097 begin
2098 // send all monsters (periodic sync)
2099 reliableUpdate := (NetTimeToReliable >= NetRelupdRate);
2101 for I := 0 to High(gPlayers) do
2102 begin
2103 if (gPlayers[I] <> nil) then MH_SEND_PlayerPos(reliableUpdate, gPlayers[I].UID);
2104 end;
2106 g_Mons_ForEach(sendMonsPos);
2108 if reliableUpdate then
2109 begin
2110 NetTimeToReliable := 0;
2111 NetTimeToUpdate := NetUpdateRate;
2112 end
2113 else
2114 begin
2115 NetTimeToUpdate := 0;
2116 end;
2117 end
2118 else
2119 begin
2120 // send only mosters with some unexpected changes
2121 g_Mons_ForEach(sendMonsPosUnexpected);
2122 end;
2124 // send unexpected platform changes
2125 g_Map_NetSendInterestingPanels();
2127 if NetUseMaster then
2128 begin
2129 if gTime >= NetTimeToMaster then
2130 begin
2131 if (NetMHost = nil) or (NetMPeer = nil) then
2132 begin
2133 if not g_Net_Slist_Connect then g_Console_Add(_lc[I_NET_MSG_ERROR] + _lc[I_NET_SLIST_ERROR]);
2134 end;
2136 g_Net_Slist_Update;
2137 NetTimeToMaster := gTime + NetMasterRate;
2138 end;
2139 end;
2140 end
2141 else if (NetMode = NET_CLIENT) then
2142 begin
2143 MC_SEND_PlayerPos();
2144 end;
2145 end; // if gameOn ...
2147 // Àêòèâíî îêíî èíòåðôåéñà - ïåðåäàåì êëàâèøè åìó:
2148 if g_ActiveWindow <> nil then
2149 begin
2150 w := e_GetFirstKeyPressed();
2152 if (w <> IK_INVALID) then
2153 begin
2154 Msg.Msg := MESSAGE_DIKEY;
2155 Msg.wParam := w;
2156 g_ActiveWindow.OnMessage(Msg);
2157 end;
2159 // Åñëè îíî îò ýòîãî íå çàêðûëîñü, òî îáíîâëÿåì:
2160 if g_ActiveWindow <> nil then
2161 g_ActiveWindow.Update();
2163 // Íóæíî ñìåíèòü ðàçðåøåíèå:
2164 if gResolutionChange then
2165 begin
2166 e_WriteLog('Changing resolution', TMsgType.Notify);
2167 g_Game_ChangeResolution(gRC_Width, gRC_Height, gRC_FullScreen, gRC_Maximized);
2168 gResolutionChange := False;
2169 g_ActiveWindow := nil;
2170 end;
2172 // Íóæíî ñìåíèòü ÿçûê:
2173 if gLanguageChange then
2174 begin
2175 //e_WriteLog('Read language file', MSG_NOTIFY);
2176 //g_Language_Load(DataDir + gLanguage + '.txt');
2177 g_Language_Set(gLanguage);
2178 g_Menu_Reset();
2179 gLanguageChange := False;
2180 end;
2181 end;
2183 // Ãîðÿ÷àÿ êëàâèøà äëÿ âûçîâà ìåíþ âûõîäà èç èãðû (F10):
2184 if e_KeyPressed(IK_F10) and
2185 gGameOn and
2186 (not gConsoleShow) and
2187 (g_ActiveWindow = nil) then
2188 begin
2189 KeyPress(IK_F10);
2190 end;
2192 Time := GetTimer() {div 1000};
2194 // Îáðàáîòêà îòëîæåííûõ ñîáûòèé:
2195 if gDelayedEvents <> nil then
2196 for a := 0 to High(gDelayedEvents) do
2197 if gDelayedEvents[a].Pending and
2199 ((gDelayedEvents[a].DEType = DE_GLOBEVENT) and (gDelayedEvents[a].Time <= Time)) or
2200 ((gDelayedEvents[a].DEType > DE_GLOBEVENT) and (gDelayedEvents[a].Time <= gTime))
2201 ) then
2202 begin
2203 case gDelayedEvents[a].DEType of
2204 DE_GLOBEVENT:
2205 g_Game_ExecuteEvent(gDelayedEvents[a].DEStr);
2206 DE_BFGHIT:
2207 if gGameOn then
2208 g_Game_Announce_GoodShot(gDelayedEvents[a].DENum);
2209 DE_KILLCOMBO:
2210 if gGameOn then
2211 begin
2212 g_Game_Announce_KillCombo(gDelayedEvents[a].DENum);
2213 if g_Game_IsNet and g_Game_IsServer then
2214 MH_SEND_GameEvent(NET_EV_KILLCOMBO, gDelayedEvents[a].DENum);
2215 end;
2216 DE_BODYKILL:
2217 if gGameOn then
2218 g_Game_Announce_BodyKill(gDelayedEvents[a].DENum);
2219 end;
2220 gDelayedEvents[a].Pending := False;
2221 end;
2223 // Êàæäóþ ñåêóíäó îáíîâëÿåì ñ÷åò÷èê îáíîâëåíèé:
2224 UPSCounter := UPSCounter + 1;
2225 if Time - UPSTime >= 1000 then
2226 begin
2227 UPS := UPSCounter;
2228 UPSCounter := 0;
2229 UPSTime := Time;
2230 end;
2232 if gGameOn then
2233 begin
2234 g_Weapon_AddDynLights();
2235 g_Items_AddDynLights();
2236 end;
2237 end;
2239 procedure g_Game_LoadChatSounds(Resource: string);
2240 var
2241 WAD: TWADFile;
2242 FileName, Snd: string;
2243 p: Pointer;
2244 len, cnt, tags, i, j: Integer;
2245 cfg: TConfig;
2246 begin
2247 FileName := g_ExtractWadName(Resource);
2249 WAD := TWADFile.Create();
2250 WAD.ReadFile(FileName);
2252 if not WAD.GetResource(g_ExtractFilePathName(Resource), p, len) then
2253 begin
2254 gChatSounds := nil;
2255 WAD.Free();
2256 Exit;
2257 end;
2259 cfg := TConfig.CreateMem(p, len);
2260 cnt := cfg.ReadInt('ChatSounds', 'Count', 0);
2262 SetLength(gChatSounds, cnt);
2263 for i := 0 to Length(gChatSounds) - 1 do
2264 begin
2265 gChatSounds[i].Sound := nil;
2266 Snd := Trim(cfg.ReadStr(IntToStr(i), 'Sound', ''));
2267 tags := cfg.ReadInt(IntToStr(i), 'Tags', 0);
2268 if (Snd = '') or (Tags <= 0) then
2269 continue;
2270 g_Sound_CreateWADEx('SOUND_CHAT_MACRO' + IntToStr(i), GameWAD+':'+Snd);
2271 gChatSounds[i].Sound := TPlayableSound.Create();
2272 gChatSounds[i].Sound.SetByName('SOUND_CHAT_MACRO' + IntToStr(i));
2273 SetLength(gChatSounds[i].Tags, tags);
2274 for j := 0 to tags - 1 do
2275 gChatSounds[i].Tags[j] := toLowerCase1251(cfg.ReadStr(IntToStr(i), 'Tag' + IntToStr(j), ''));
2276 gChatSounds[i].FullWord := cfg.ReadBool(IntToStr(i), 'FullWord', False);
2277 end;
2279 cfg.Free();
2280 WAD.Free();
2281 end;
2283 procedure g_Game_FreeChatSounds();
2284 var
2285 i: Integer;
2286 begin
2287 for i := 0 to Length(gChatSounds) - 1 do
2288 begin
2289 gChatSounds[i].Sound.Free();
2290 g_Sound_Delete('SOUND_CHAT_MACRO' + IntToStr(i));
2291 end;
2292 SetLength(gChatSounds, 0);
2293 gChatSounds := nil;
2294 end;
2296 procedure g_Game_LoadData();
2297 var
2298 wl, hl: Integer;
2299 wr, hr: Integer;
2300 wb, hb: Integer;
2301 wm, hm: Integer;
2302 begin
2303 if DataLoaded then Exit;
2305 e_WriteLog('Loading game data...', TMsgType.Notify);
2307 g_Texture_CreateWADEx('NOTEXTURE', GameWAD+':TEXTURES\NOTEXTURE');
2308 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUD', GameWAD+':TEXTURES\HUD');
2309 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDAIR', GameWAD+':TEXTURES\AIRBAR');
2310 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDJET', GameWAD+':TEXTURES\JETBAR');
2311 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDBG', GameWAD+':TEXTURES\HUDBG');
2312 g_Texture_CreateWADEx('TEXTURE_PLAYER_ARMORHUD', GameWAD+':TEXTURES\ARMORHUD');
2313 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG', GameWAD+':TEXTURES\FLAGHUD_R_BASE');
2314 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_S', GameWAD+':TEXTURES\FLAGHUD_R_STOLEN');
2315 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_D', GameWAD+':TEXTURES\FLAGHUD_R_DROP');
2316 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG', GameWAD+':TEXTURES\FLAGHUD_B_BASE');
2317 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_S', GameWAD+':TEXTURES\FLAGHUD_B_STOLEN');
2318 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_D', GameWAD+':TEXTURES\FLAGHUD_B_DROP');
2319 g_Texture_CreateWADEx('TEXTURE_PLAYER_TALKBUBBLE', GameWAD+':TEXTURES\TALKBUBBLE');
2320 g_Texture_CreateWADEx('TEXTURE_PLAYER_INVULPENTA', GameWAD+':TEXTURES\PENTA');
2321 g_Texture_CreateWADEx('TEXTURE_PLAYER_INDICATOR', GameWAD+':TEXTURES\PLRIND');
2323 hasPBarGfx := true;
2324 if not g_Texture_CreateWADEx('UI_GFX_PBAR_LEFT', GameWAD+':TEXTURES\LLEFT') then hasPBarGfx := false;
2325 if not g_Texture_CreateWADEx('UI_GFX_PBAR_MARKER', GameWAD+':TEXTURES\LMARKER') then hasPBarGfx := false;
2326 if not g_Texture_CreateWADEx('UI_GFX_PBAR_MIDDLE', GameWAD+':TEXTURES\LMIDDLE') then hasPBarGfx := false;
2327 if not g_Texture_CreateWADEx('UI_GFX_PBAR_RIGHT', GameWAD+':TEXTURES\LRIGHT') then hasPBarGfx := false;
2329 if hasPBarGfx then
2330 begin
2331 g_Texture_GetSize('UI_GFX_PBAR_LEFT', wl, hl);
2332 g_Texture_GetSize('UI_GFX_PBAR_RIGHT', wr, hr);
2333 g_Texture_GetSize('UI_GFX_PBAR_MIDDLE', wb, hb);
2334 g_Texture_GetSize('UI_GFX_PBAR_MARKER', wm, hm);
2335 if (wl > 0) and (hl > 0) and (wr > 0) and (hr = hl) and (wb > 0) and (hb = hl) and (wm > 0) and (hm > 0) and (hm <= hl) then
2336 begin
2337 // yay!
2338 end
2339 else
2340 begin
2341 hasPBarGfx := false;
2342 end;
2343 end;
2345 g_Frames_CreateWAD(nil, 'FRAMES_TELEPORT', GameWAD+':TEXTURES\TELEPORT', 64, 64, 10, False);
2346 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH', GameWAD+':WEAPONS\PUNCH', 64, 64, 4, False);
2347 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_UP', GameWAD+':WEAPONS\PUNCH_UP', 64, 64, 4, False);
2348 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_DN', GameWAD+':WEAPONS\PUNCH_DN', 64, 64, 4, False);
2349 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK', GameWAD+':WEAPONS\PUNCHB', 64, 64, 4, False);
2350 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK_UP', GameWAD+':WEAPONS\PUNCHB_UP', 64, 64, 4, False);
2351 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK_DN', GameWAD+':WEAPONS\PUNCHB_DN', 64, 64, 4, False);
2352 g_Sound_CreateWADEx('SOUND_GAME_TELEPORT', GameWAD+':SOUNDS\TELEPORT');
2353 g_Sound_CreateWADEx('SOUND_GAME_NOTELEPORT', GameWAD+':SOUNDS\NOTELEPORT');
2354 g_Sound_CreateWADEx('SOUND_GAME_SECRET', GameWAD+':SOUNDS\SECRET');
2355 g_Sound_CreateWADEx('SOUND_GAME_DOOROPEN', GameWAD+':SOUNDS\DOOROPEN');
2356 g_Sound_CreateWADEx('SOUND_GAME_DOORCLOSE', GameWAD+':SOUNDS\DOORCLOSE');
2357 g_Sound_CreateWADEx('SOUND_GAME_BULK1', GameWAD+':SOUNDS\BULK1');
2358 g_Sound_CreateWADEx('SOUND_GAME_BULK2', GameWAD+':SOUNDS\BULK2');
2359 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE1', GameWAD+':SOUNDS\BUBBLE1');
2360 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE2', GameWAD+':SOUNDS\BUBBLE2');
2361 g_Sound_CreateWADEx('SOUND_GAME_BURNING', GameWAD+':SOUNDS\BURNING');
2362 g_Sound_CreateWADEx('SOUND_GAME_SWITCH1', GameWAD+':SOUNDS\SWITCH1');
2363 g_Sound_CreateWADEx('SOUND_GAME_SWITCH0', GameWAD+':SOUNDS\SWITCH0');
2364 g_Sound_CreateWADEx('SOUND_GAME_RADIO', GameWAD+':SOUNDS\RADIO');
2365 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD1', GameWAD+':SOUNDS\GOOD1');
2366 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD2', GameWAD+':SOUNDS\GOOD2');
2367 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD3', GameWAD+':SOUNDS\GOOD3');
2368 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD4', GameWAD+':SOUNDS\GOOD4');
2369 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL2X', GameWAD+':SOUNDS\KILL2X');
2370 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL3X', GameWAD+':SOUNDS\KILL3X');
2371 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL4X', GameWAD+':SOUNDS\KILL4X');
2372 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILLMX', GameWAD+':SOUNDS\KILLMX');
2373 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA1', GameWAD+':SOUNDS\MUHAHA1');
2374 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA2', GameWAD+':SOUNDS\MUHAHA2');
2375 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA3', GameWAD+':SOUNDS\MUHAHA3');
2376 g_Sound_CreateWADEx('SOUND_CTF_GET1', GameWAD+':SOUNDS\GETFLAG1');
2377 g_Sound_CreateWADEx('SOUND_CTF_GET2', GameWAD+':SOUNDS\GETFLAG2');
2378 g_Sound_CreateWADEx('SOUND_CTF_LOST1', GameWAD+':SOUNDS\LOSTFLG1');
2379 g_Sound_CreateWADEx('SOUND_CTF_LOST2', GameWAD+':SOUNDS\LOSTFLG2');
2380 g_Sound_CreateWADEx('SOUND_CTF_RETURN1', GameWAD+':SOUNDS\RETFLAG1');
2381 g_Sound_CreateWADEx('SOUND_CTF_RETURN2', GameWAD+':SOUNDS\RETFLAG2');
2382 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE1', GameWAD+':SOUNDS\CAPFLAG1');
2383 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE2', GameWAD+':SOUNDS\CAPFLAG2');
2385 goodsnd[0] := TPlayableSound.Create();
2386 goodsnd[1] := TPlayableSound.Create();
2387 goodsnd[2] := TPlayableSound.Create();
2388 goodsnd[3] := TPlayableSound.Create();
2390 goodsnd[0].SetByName('SOUND_ANNOUNCER_GOOD1');
2391 goodsnd[1].SetByName('SOUND_ANNOUNCER_GOOD2');
2392 goodsnd[2].SetByName('SOUND_ANNOUNCER_GOOD3');
2393 goodsnd[3].SetByName('SOUND_ANNOUNCER_GOOD4');
2395 killsnd[0] := TPlayableSound.Create();
2396 killsnd[1] := TPlayableSound.Create();
2397 killsnd[2] := TPlayableSound.Create();
2398 killsnd[3] := TPlayableSound.Create();
2400 killsnd[0].SetByName('SOUND_ANNOUNCER_KILL2X');
2401 killsnd[1].SetByName('SOUND_ANNOUNCER_KILL3X');
2402 killsnd[2].SetByName('SOUND_ANNOUNCER_KILL4X');
2403 killsnd[3].SetByName('SOUND_ANNOUNCER_KILLMX');
2405 hahasnd[0] := TPlayableSound.Create();
2406 hahasnd[1] := TPlayableSound.Create();
2407 hahasnd[2] := TPlayableSound.Create();
2409 hahasnd[0].SetByName('SOUND_ANNOUNCER_MUHAHA1');
2410 hahasnd[1].SetByName('SOUND_ANNOUNCER_MUHAHA2');
2411 hahasnd[2].SetByName('SOUND_ANNOUNCER_MUHAHA3');
2413 sound_get_flag[0] := TPlayableSound.Create();
2414 sound_get_flag[1] := TPlayableSound.Create();
2415 sound_lost_flag[0] := TPlayableSound.Create();
2416 sound_lost_flag[1] := TPlayableSound.Create();
2417 sound_ret_flag[0] := TPlayableSound.Create();
2418 sound_ret_flag[1] := TPlayableSound.Create();
2419 sound_cap_flag[0] := TPlayableSound.Create();
2420 sound_cap_flag[1] := TPlayableSound.Create();
2422 sound_get_flag[0].SetByName('SOUND_CTF_GET1');
2423 sound_get_flag[1].SetByName('SOUND_CTF_GET2');
2424 sound_lost_flag[0].SetByName('SOUND_CTF_LOST1');
2425 sound_lost_flag[1].SetByName('SOUND_CTF_LOST2');
2426 sound_ret_flag[0].SetByName('SOUND_CTF_RETURN1');
2427 sound_ret_flag[1].SetByName('SOUND_CTF_RETURN2');
2428 sound_cap_flag[0].SetByName('SOUND_CTF_CAPTURE1');
2429 sound_cap_flag[1].SetByName('SOUND_CTF_CAPTURE2');
2431 g_Game_LoadChatSounds(GameWAD+':CHATSND\SNDCFG');
2433 g_Game_SetLoadingText(_lc[I_LOAD_ITEMS_DATA], 0, False);
2434 g_Items_LoadData();
2436 g_Game_SetLoadingText(_lc[I_LOAD_WEAPONS_DATA], 0, False);
2437 g_Weapon_LoadData();
2439 g_Monsters_LoadData();
2441 DataLoaded := True;
2442 end;
2444 procedure g_Game_FreeData();
2445 begin
2446 if not DataLoaded then Exit;
2448 g_Items_FreeData();
2449 g_Weapon_FreeData();
2450 g_Monsters_FreeData();
2452 e_WriteLog('Releasing game data...', TMsgType.Notify);
2454 g_Texture_Delete('NOTEXTURE');
2455 g_Texture_Delete('TEXTURE_PLAYER_HUD');
2456 g_Texture_Delete('TEXTURE_PLAYER_HUDBG');
2457 g_Texture_Delete('TEXTURE_PLAYER_ARMORHUD');
2458 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG');
2459 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_S');
2460 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_D');
2461 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG');
2462 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_S');
2463 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_D');
2464 g_Texture_Delete('TEXTURE_PLAYER_TALKBUBBLE');
2465 g_Texture_Delete('TEXTURE_PLAYER_INVULPENTA');
2466 g_Frames_DeleteByName('FRAMES_TELEPORT');
2467 g_Frames_DeleteByName('FRAMES_PUNCH');
2468 g_Frames_DeleteByName('FRAMES_PUNCH_UP');
2469 g_Frames_DeleteByName('FRAMES_PUNCH_DN');
2470 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK');
2471 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK_UP');
2472 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK_DN');
2473 g_Sound_Delete('SOUND_GAME_TELEPORT');
2474 g_Sound_Delete('SOUND_GAME_NOTELEPORT');
2475 g_Sound_Delete('SOUND_GAME_SECRET');
2476 g_Sound_Delete('SOUND_GAME_DOOROPEN');
2477 g_Sound_Delete('SOUND_GAME_DOORCLOSE');
2478 g_Sound_Delete('SOUND_GAME_BULK1');
2479 g_Sound_Delete('SOUND_GAME_BULK2');
2480 g_Sound_Delete('SOUND_GAME_BUBBLE1');
2481 g_Sound_Delete('SOUND_GAME_BUBBLE2');
2482 g_Sound_Delete('SOUND_GAME_BURNING');
2483 g_Sound_Delete('SOUND_GAME_SWITCH1');
2484 g_Sound_Delete('SOUND_GAME_SWITCH0');
2486 goodsnd[0].Free();
2487 goodsnd[1].Free();
2488 goodsnd[2].Free();
2489 goodsnd[3].Free();
2491 g_Sound_Delete('SOUND_ANNOUNCER_GOOD1');
2492 g_Sound_Delete('SOUND_ANNOUNCER_GOOD2');
2493 g_Sound_Delete('SOUND_ANNOUNCER_GOOD3');
2494 g_Sound_Delete('SOUND_ANNOUNCER_GOOD4');
2496 killsnd[0].Free();
2497 killsnd[1].Free();
2498 killsnd[2].Free();
2499 killsnd[3].Free();
2501 g_Sound_Delete('SOUND_ANNOUNCER_KILL2X');
2502 g_Sound_Delete('SOUND_ANNOUNCER_KILL3X');
2503 g_Sound_Delete('SOUND_ANNOUNCER_KILL4X');
2504 g_Sound_Delete('SOUND_ANNOUNCER_KILLMX');
2506 hahasnd[0].Free();
2507 hahasnd[1].Free();
2508 hahasnd[2].Free();
2510 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA1');
2511 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA2');
2512 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA3');
2514 sound_get_flag[0].Free();
2515 sound_get_flag[1].Free();
2516 sound_lost_flag[0].Free();
2517 sound_lost_flag[1].Free();
2518 sound_ret_flag[0].Free();
2519 sound_ret_flag[1].Free();
2520 sound_cap_flag[0].Free();
2521 sound_cap_flag[1].Free();
2523 g_Sound_Delete('SOUND_CTF_GET1');
2524 g_Sound_Delete('SOUND_CTF_GET2');
2525 g_Sound_Delete('SOUND_CTF_LOST1');
2526 g_Sound_Delete('SOUND_CTF_LOST2');
2527 g_Sound_Delete('SOUND_CTF_RETURN1');
2528 g_Sound_Delete('SOUND_CTF_RETURN2');
2529 g_Sound_Delete('SOUND_CTF_CAPTURE1');
2530 g_Sound_Delete('SOUND_CTF_CAPTURE2');
2532 g_Game_FreeChatSounds();
2534 DataLoaded := False;
2535 end;
2537 procedure DrawCustomStat();
2538 var
2539 pc, x, y, w, _y,
2540 w1, w2, w3,
2541 t, p, m: Integer;
2542 ww1, hh1: Word;
2543 ww2, hh2, r, g, b, rr, gg, bb: Byte;
2544 s1, s2, topstr: String;
2545 begin
2546 e_TextureFontGetSize(gStdFont, ww2, hh2);
2548 g_ProcessMessages();
2550 if g_Console_Action(ACTION_SCORES) then
2551 begin
2552 if not gStatsPressed then
2553 begin
2554 gStatsOff := not gStatsOff;
2555 gStatsPressed := True;
2556 end;
2557 end
2558 else
2559 gStatsPressed := False;
2561 if gStatsOff then
2562 begin
2563 s1 := _lc[I_MENU_INTER_NOTICE_TAB];
2564 w := (Length(s1) * ww2) div 2;
2565 x := gScreenWidth div 2 - w;
2566 y := 8;
2567 e_TextureFontPrint(x, y, s1, gStdFont);
2568 Exit;
2569 end;
2571 if (gGameSettings.GameMode = GM_COOP) then
2572 begin
2573 if gMissionFailed then
2574 topstr := _lc[I_MENU_INTER_MISSION_FAIL]
2575 else
2576 topstr := _lc[I_MENU_INTER_LEVEL_COMPLETE];
2577 end
2578 else
2579 topstr := _lc[I_MENU_INTER_ROUND_OVER];
2581 e_CharFont_GetSize(gMenuFont, topstr, ww1, hh1);
2582 e_CharFont_Print(gMenuFont, (gScreenWidth div 2)-(ww1 div 2), 16, topstr);
2584 if g_Game_IsNet then
2585 begin
2586 topstr := Format(_lc[I_MENU_INTER_NOTICE_TIME], [gServInterTime]);
2587 if not gChatShow then
2588 e_TextureFontPrintEx((gScreenWidth div 2)-(Length(topstr)*ww2 div 2),
2589 gScreenHeight-(hh2+4)*2, topstr, gStdFont, 255, 255, 255, 1);
2590 end;
2592 if g_Game_IsClient then
2593 topstr := _lc[I_MENU_INTER_NOTICE_MAP]
2594 else
2595 topstr := _lc[I_MENU_INTER_NOTICE_SPACE];
2596 if not gChatShow then
2597 e_TextureFontPrintEx((gScreenWidth div 2)-(Length(topstr)*ww2 div 2),
2598 gScreenHeight-(hh2+4), topstr, gStdFont, 255, 255, 255, 1);
2600 x := 32;
2601 y := 16+hh1+16;
2603 w := gScreenWidth-x*2;
2605 w2 := (w-16) div 6;
2606 w3 := w2;
2607 w1 := w-16-w2-w3;
2609 e_DrawFillQuad(x, y, gScreenWidth-x-1, gScreenHeight-y-1, 64, 64, 64, 32);
2610 e_DrawQuad(x, y, gScreenWidth-x-1, gScreenHeight-y-1, 255, 127, 0);
2612 m := Max(Length(_lc[I_MENU_MAP])+1, Length(_lc[I_GAME_GAME_TIME])+1)*ww2;
2614 case CustomStat.GameMode of
2615 GM_DM:
2616 begin
2617 if gGameSettings.MaxLives = 0 then
2618 s1 := _lc[I_GAME_DM]
2619 else
2620 s1 := _lc[I_GAME_LMS];
2621 end;
2622 GM_TDM:
2623 begin
2624 if gGameSettings.MaxLives = 0 then
2625 s1 := _lc[I_GAME_TDM]
2626 else
2627 s1 := _lc[I_GAME_TLMS];
2628 end;
2629 GM_CTF: s1 := _lc[I_GAME_CTF];
2630 GM_COOP:
2631 begin
2632 if gGameSettings.MaxLives = 0 then
2633 s1 := _lc[I_GAME_COOP]
2634 else
2635 s1 := _lc[I_GAME_SURV];
2636 end;
2637 else s1 := '';
2638 end;
2640 _y := y+16;
2641 e_TextureFontPrintEx(x+(w div 2)-(Length(s1)*ww2 div 2), _y, s1, gStdFont, 255, 255, 255, 1);
2642 _y := _y+8;
2644 _y := _y+16;
2645 e_TextureFontPrintEx(x+8, _y, _lc[I_MENU_MAP], gStdFont, 255, 127, 0, 1);
2646 e_TextureFontPrint(x+8+m, _y, Format('%s - %s', [CustomStat.Map, CustomStat.MapName]), gStdFont);
2648 _y := _y+16;
2649 e_TextureFontPrintEx(x+8, _y, _lc[I_GAME_GAME_TIME], gStdFont, 255, 127, 0, 1);
2650 e_TextureFontPrint(x+8+m, _y, Format('%d:%.2d:%.2d', [CustomStat.GameTime div 1000 div 3600,
2651 (CustomStat.GameTime div 1000 div 60) mod 60,
2652 CustomStat.GameTime div 1000 mod 60]), gStdFont);
2654 pc := Length(CustomStat.PlayerStat);
2655 if pc = 0 then Exit;
2657 if CustomStat.GameMode = GM_COOP then
2658 begin
2659 m := Max(Length(_lc[I_GAME_MONSTERS])+1, Length(_lc[I_GAME_SECRETS])+1)*ww2;
2660 _y := _y+32;
2661 s2 := _lc[I_GAME_MONSTERS];
2662 e_TextureFontPrintEx(x+8, _y, s2, gStdFont, 255, 127, 0, 1);
2663 e_TextureFontPrintEx(x+8+m, _y, IntToStr(gCoopMonstersKilled) + '/' + IntToStr(gTotalMonsters), gStdFont, 255, 255, 255, 1);
2664 _y := _y+16;
2665 s2 := _lc[I_GAME_SECRETS];
2666 e_TextureFontPrintEx(x+8, _y, s2, gStdFont, 255, 127, 0, 1);
2667 e_TextureFontPrintEx(x+8+m, _y, IntToStr(gCoopSecretsFound) + '/' + IntToStr(gSecretsCount), gStdFont, 255, 255, 255, 1);
2668 if gLastMap then
2669 begin
2670 m := Max(Length(_lc[I_GAME_MONSTERS_TOTAL])+1, Length(_lc[I_GAME_SECRETS_TOTAL])+1)*ww2;
2671 _y := _y-16;
2672 s2 := _lc[I_GAME_MONSTERS_TOTAL];
2673 e_TextureFontPrintEx(x+250, _y, s2, gStdFont, 255, 127, 0, 1);
2674 e_TextureFontPrintEx(x+250+m, _y, IntToStr(gCoopTotalMonstersKilled) + '/' + IntToStr(gCoopTotalMonsters), gStdFont, 255, 255, 255, 1);
2675 _y := _y+16;
2676 s2 := _lc[I_GAME_SECRETS_TOTAL];
2677 e_TextureFontPrintEx(x+250, _y, s2, gStdFont, 255, 127, 0, 1);
2678 e_TextureFontPrintEx(x+250+m, _y, IntToStr(gCoopTotalSecretsFound) + '/' + IntToStr(gCoopTotalSecrets), gStdFont, 255, 255, 255, 1);
2679 end;
2680 end;
2682 if CustomStat.GameMode in [GM_TDM, GM_CTF] then
2683 begin
2684 _y := _y+16+16;
2686 with CustomStat do
2687 if TeamStat[TEAM_RED].Goals > TeamStat[TEAM_BLUE].Goals then s1 := _lc[I_GAME_WIN_RED]
2688 else if TeamStat[TEAM_BLUE].Goals > TeamStat[TEAM_RED].Goals then s1 := _lc[I_GAME_WIN_BLUE]
2689 else s1 := _lc[I_GAME_WIN_DRAW];
2691 e_TextureFontPrintEx(x+8+(w div 2)-(Length(s1)*ww2 div 2), _y, s1, gStdFont, 255, 255, 255, 1);
2692 _y := _y+40;
2694 for t := TEAM_RED to TEAM_BLUE do
2695 begin
2696 if t = TEAM_RED then
2697 begin
2698 e_TextureFontPrintEx(x+8, _y, _lc[I_GAME_TEAM_RED],
2699 gStdFont, 255, 0, 0, 1);
2700 e_TextureFontPrintEx(x+w1+8, _y, IntToStr(CustomStat.TeamStat[TEAM_RED].Goals),
2701 gStdFont, 255, 0, 0, 1);
2702 r := 255;
2703 g := 0;
2704 b := 0;
2705 end
2706 else
2707 begin
2708 e_TextureFontPrintEx(x+8, _y, _lc[I_GAME_TEAM_BLUE],
2709 gStdFont, 0, 0, 255, 1);
2710 e_TextureFontPrintEx(x+w1+8, _y, IntToStr(CustomStat.TeamStat[TEAM_BLUE].Goals),
2711 gStdFont, 0, 0, 255, 1);
2712 r := 0;
2713 g := 0;
2714 b := 255;
2715 end;
2717 e_DrawLine(1, x+8, _y+20, x-8+w, _y+20, r, g, b);
2718 _y := _y+24;
2720 for p := 0 to High(CustomStat.PlayerStat) do
2721 if CustomStat.PlayerStat[p].Team = t then
2722 with CustomStat.PlayerStat[p] do
2723 begin
2724 if Spectator then
2725 begin
2726 rr := r div 2;
2727 gg := g div 2;
2728 bb := b div 2;
2729 end
2730 else
2731 begin
2732 rr := r;
2733 gg := g;
2734 bb := b;
2735 end;
2736 if (gPlayers[Num] <> nil) and (gPlayers[Num].FReady) then
2737 e_TextureFontPrintEx(x+16, _y, Name + ' *', gStdFont, rr, gg, bb, 1)
2738 else
2739 e_TextureFontPrintEx(x+16, _y, Name, gStdFont, rr, gg, bb, 1);
2740 e_TextureFontPrintEx(x+w1+16, _y, IntToStr(Frags), gStdFont, rr, gg, bb, 1);
2741 e_TextureFontPrintEx(x+w1+w2+16, _y, IntToStr(Deaths), gStdFont, rr, gg, bb, 1);
2742 _y := _y+24;
2743 end;
2745 _y := _y+16+16;
2746 end;
2747 end
2748 else if CustomStat.GameMode in [GM_DM, GM_COOP] then
2749 begin
2750 _y := _y+40;
2751 e_TextureFontPrintEx(x+8, _y, _lc[I_GAME_PLAYER_NAME], gStdFont, 255, 127, 0, 1);
2752 e_TextureFontPrintEx(x+8+w1, _y, _lc[I_GAME_FRAGS], gStdFont, 255, 127, 0, 1);
2753 e_TextureFontPrintEx(x+8+w1+w2, _y, _lc[I_GAME_DEATHS], gStdFont, 255, 127, 0, 1);
2755 _y := _y+24;
2756 for p := 0 to High(CustomStat.PlayerStat) do
2757 with CustomStat.PlayerStat[p] do
2758 begin
2759 e_DrawFillQuad(x+8, _y+4, x+24-1, _y+16+4-1, Color.R, Color.G, Color.B, 0);
2761 if Spectator then
2762 r := 127
2763 else
2764 r := 255;
2766 if (gPlayers[Num] <> nil) and (gPlayers[Num].FReady) then
2767 e_TextureFontPrintEx(x+8+16+8, _y+4, Name + ' *', gStdFont, r, r, r, 1, True)
2768 else
2769 e_TextureFontPrintEx(x+8+16+8, _y+4, Name, gStdFont, r, r, r, 1, True);
2770 e_TextureFontPrintEx(x+w1+8+16+8, _y+4, IntToStr(Frags), gStdFont, r, r, r, 1, True);
2771 e_TextureFontPrintEx(x+w1+w2+8+16+8, _y+4, IntToStr(Deaths), gStdFont, r, r, r, 1, True);
2772 _y := _y+24;
2773 end;
2774 end;
2775 end;
2777 procedure DrawSingleStat();
2778 var
2779 tm, key_x, val_x, y: Integer;
2780 w1, w2, h: Word;
2781 s1, s2: String;
2783 procedure player_stat(n: Integer);
2784 var
2785 kpm: Real;
2787 begin
2788 // "Kills: # / #":
2789 s1 := Format(' %d ', [SingleStat.PlayerStat[n].Kills]);
2790 s2 := Format(' %d', [gTotalMonsters]);
2792 e_CharFont_Print(gMenuFont, key_x, y, _lc[I_MENU_INTER_KILLS]);
2793 e_CharFont_PrintEx(gMenuFont, val_x, y, s1, _RGB(255, 0, 0));
2794 e_CharFont_GetSize(gMenuFont, s1, w1, h);
2795 e_CharFont_Print(gMenuFont, val_x+w1, y, '/');
2796 s1 := s1 + '/';
2797 e_CharFont_GetSize(gMenuFont, s1, w1, h);
2798 e_CharFont_PrintEx(gMenuFont, val_x+w1, y, s2, _RGB(255, 0, 0));
2800 // "Kills-per-minute: ##.#":
2801 s1 := _lc[I_MENU_INTER_KPM];
2802 if tm > 0 then
2803 kpm := (SingleStat.PlayerStat[n].Kills / tm) * 60
2804 else
2805 kpm := SingleStat.PlayerStat[n].Kills;
2806 s2 := Format(' %.1f', [kpm]);
2808 e_CharFont_Print(gMenuFont, key_x, y+32, s1);
2809 e_CharFont_PrintEx(gMenuFont, val_x, y+32, s2, _RGB(255, 0, 0));
2811 // "Secrets found: # / #":
2812 s1 := Format(' %d ', [SingleStat.PlayerStat[n].Secrets]);
2813 s2 := Format(' %d', [SingleStat.TotalSecrets]);
2815 e_CharFont_Print(gMenuFont, key_x, y+64, _lc[I_MENU_INTER_SECRETS]);
2816 e_CharFont_PrintEx(gMenuFont, val_x, y+64, s1, _RGB(255, 0, 0));
2817 e_CharFont_GetSize(gMenuFont, s1, w1, h);
2818 e_CharFont_Print(gMenuFont, val_x+w1, y+64, '/');
2819 s1 := s1 + '/';
2820 e_CharFont_GetSize(gMenuFont, s1, w1, h);
2821 e_CharFont_PrintEx(gMenuFont, val_x+w1, y+64, s2, _RGB(255, 0, 0));
2822 end;
2824 begin
2825 // "Level Complete":
2826 e_CharFont_GetSize(gMenuFont, _lc[I_MENU_INTER_LEVEL_COMPLETE], w1, h);
2827 e_CharFont_Print(gMenuFont, (gScreenWidth-w1) div 2, 32, _lc[I_MENU_INTER_LEVEL_COMPLETE]);
2829 // Îïðåäåëÿåì êîîðäèíàòû âûðàâíèâàíèÿ ïî ñàìîé äëèííîé ñòðîêå:
2830 s1 := _lc[I_MENU_INTER_KPM];
2831 e_CharFont_GetSize(gMenuFont, s1, w1, h);
2832 Inc(w1, 16);
2833 s1 := ' 9999.9';
2834 e_CharFont_GetSize(gMenuFont, s1, w2, h);
2836 key_x := (gScreenWidth-w1-w2) div 2;
2837 val_x := key_x + w1;
2839 // "Time: #:##:##":
2840 tm := SingleStat.GameTime div 1000;
2841 s1 := _lc[I_MENU_INTER_TIME];
2842 s2 := Format(' %d:%.2d:%.2d', [tm div (60*60), (tm mod (60*60)) div 60, tm mod 60]);
2844 e_CharFont_Print(gMenuFont, key_x, 80, s1);
2845 e_CharFont_PrintEx(gMenuFont, val_x, 80, s2, _RGB(255, 0, 0));
2847 if SingleStat.TwoPlayers then
2848 begin
2849 // "Player 1":
2850 s1 := _lc[I_MENU_PLAYER_1];
2851 e_CharFont_GetSize(gMenuFont, s1, w1, h);
2852 e_CharFont_Print(gMenuFont, (gScreenWidth-w1) div 2, 128, s1);
2854 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
2855 y := 176;
2856 player_stat(0);
2858 // "Player 2":
2859 s1 := _lc[I_MENU_PLAYER_2];
2860 e_CharFont_GetSize(gMenuFont, s1, w1, h);
2861 e_CharFont_Print(gMenuFont, (gScreenWidth-w1) div 2, 288, s1);
2863 // Ñòàòèñòèêà âòîðîãî èãðîêà:
2864 y := 336;
2865 player_stat(1);
2866 end
2867 else
2868 begin
2869 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
2870 y := 128;
2871 player_stat(0);
2872 end;
2873 end;
2875 procedure DrawLoadingStat();
2876 procedure drawRect (x, y, w, h: Integer);
2877 begin
2878 if (w < 1) or (h < 1) then exit;
2879 glBegin(GL_QUADS);
2880 glVertex2f(x+0.375, y+0.375);
2881 glVertex2f(x+w+0.375, y+0.375);
2882 glVertex2f(x+w+0.375, y+h+0.375);
2883 glVertex2f(x+0.375, y+h+0.375);
2884 glEnd();
2885 end;
2887 function drawPBar (cur, total: Integer; washere: Boolean): Boolean;
2888 var
2889 rectW, rectH: Integer;
2890 x0, y0: Integer;
2891 wdt: Integer;
2892 wl, hl: Integer;
2893 wr, hr: Integer;
2894 wb, hb: Integer;
2895 wm, hm: Integer;
2896 idl, idr, idb, idm: LongWord;
2897 f, my: Integer;
2898 begin
2899 result := false;
2900 if (total < 1) then exit;
2901 if (cur < 1) then exit; // don't blink
2902 if (not washere) and (cur >= total) then exit; // don't blink
2903 //if (cur < 0) then cur := 0;
2904 //if (cur > total) then cur := total;
2905 result := true;
2907 if (hasPBarGfx) then
2908 begin
2909 g_Texture_Get('UI_GFX_PBAR_LEFT', idl);
2910 g_Texture_GetSize('UI_GFX_PBAR_LEFT', wl, hl);
2911 g_Texture_Get('UI_GFX_PBAR_RIGHT', idr);
2912 g_Texture_GetSize('UI_GFX_PBAR_RIGHT', wr, hr);
2913 g_Texture_Get('UI_GFX_PBAR_MIDDLE', idb);
2914 g_Texture_GetSize('UI_GFX_PBAR_MIDDLE', wb, hb);
2915 g_Texture_Get('UI_GFX_PBAR_MARKER', idm);
2916 g_Texture_GetSize('UI_GFX_PBAR_MARKER', wm, hm);
2918 //rectW := gScreenWidth-360;
2919 rectW := trunc(624.0*gScreenWidth/1024.0);
2920 rectH := hl;
2922 x0 := (gScreenWidth-rectW) div 2;
2923 y0 := gScreenHeight-rectH-64;
2924 if (y0 < 2) then y0 := 2;
2926 glEnable(GL_SCISSOR_TEST);
2928 // left and right
2929 glScissor(x0, gScreenHeight-y0-rectH, rectW, rectH);
2930 e_DrawSize(idl, x0, y0, 0, true, false, wl, hl);
2931 e_DrawSize(idr, x0+rectW-wr, y0, 0, true, false, wr, hr);
2933 // body
2934 glScissor(x0+wl, gScreenHeight-y0-rectH, rectW-wl-wr, rectH);
2935 f := x0+wl;
2936 while (f < x0+rectW) do
2937 begin
2938 e_DrawSize(idb, f, y0, 0, true, false, wb, hb);
2939 f += wb;
2940 end;
2942 // filled part
2943 wdt := (rectW-wl-wr)*cur div total;
2944 if (wdt > rectW-wl-wr) then wdt := rectW-wr-wr;
2945 if (wdt > 0) then
2946 begin
2947 my := y0; // don't be so smart, ketmar: +(rectH-wm) div 2;
2948 glScissor(x0+wl, gScreenHeight-my-rectH, wdt, hm);
2949 f := x0+wl;
2950 while (wdt > 0) do
2951 begin
2952 e_DrawSize(idm, f, y0, 0, true, false, wm, hm);
2953 f += wm;
2954 wdt -= wm;
2955 end;
2956 end;
2958 glScissor(0, 0, gScreenWidth, gScreenHeight);
2959 end
2960 else
2961 begin
2962 rectW := gScreenWidth-64;
2963 rectH := 16;
2965 x0 := (gScreenWidth-rectW) div 2;
2966 y0 := gScreenHeight-rectH-64;
2967 if (y0 < 2) then y0 := 2;
2969 glDisable(GL_BLEND);
2970 glDisable(GL_TEXTURE_2D);
2972 //glClearColor(0, 0, 0, 0);
2973 //glClear(GL_COLOR_BUFFER_BIT);
2975 glColor4ub(127, 127, 127, 255);
2976 drawRect(x0-2, y0-2, rectW+4, rectH+4);
2978 glColor4ub(0, 0, 0, 255);
2979 drawRect(x0-1, y0-1, rectW+2, rectH+2);
2981 glColor4ub(127, 127, 127, 255);
2982 wdt := rectW*cur div total;
2983 if (wdt > rectW) then wdt := rectW;
2984 drawRect(x0, y0, wdt, rectH);
2985 end;
2986 end;
2988 var
2989 ww, hh: Word;
2990 xx, yy, i: Integer;
2991 s: String;
2992 begin
2993 if (Length(LoadingStat.Msgs) = 0) then exit;
2995 e_CharFont_GetSize(gMenuFont, _lc[I_MENU_LOADING], ww, hh);
2996 yy := (gScreenHeight div 3);
2997 e_CharFont_Print(gMenuFont, (gScreenWidth div 2)-(ww div 2), yy-2*hh, _lc[I_MENU_LOADING]);
2998 xx := (gScreenWidth div 3);
3000 with LoadingStat do
3001 begin
3002 for i := 0 to NextMsg-1 do
3003 begin
3004 if (i = (NextMsg-1)) and (MaxValue > 0) then
3005 s := Format('%s: %d/%d', [Msgs[i], CurValue, MaxValue])
3006 else
3007 s := Msgs[i];
3009 e_CharFont_PrintEx(gMenuSmallFont, xx, yy, s, _RGB(255, 0, 0));
3010 yy := yy + LOADING_INTERLINE;
3011 PBarWasHere := drawPBar(CurValue, MaxValue, PBarWasHere);
3012 end;
3013 end;
3014 end;
3016 procedure DrawMenuBackground(tex: AnsiString);
3017 var
3018 w, h: Word;
3019 ID: DWord;
3021 begin
3022 if g_Texture_Get(tex, ID) then
3023 begin
3024 e_Clear(GL_COLOR_BUFFER_BIT, 0, 0, 0);
3025 e_GetTextureSize(ID, @w, @h);
3026 if w = h then
3027 w := round(w * 1.333 * (gScreenHeight / h))
3028 else
3029 w := trunc(w * (gScreenHeight / h));
3030 e_DrawSize(ID, (gScreenWidth - w) div 2, 0, 0, False, False, w, gScreenHeight);
3031 end
3032 else e_Clear(GL_COLOR_BUFFER_BIT, 0, 0, 0);
3033 end;
3035 procedure DrawMinimap(p: TPlayer; RenderRect: e_graphics.TRect);
3036 var
3037 a, aX, aY, aX2, aY2, Scale, ScaleSz: Integer;
3039 function monDraw (mon: TMonster): Boolean;
3040 begin
3041 result := false; // don't stop
3042 with mon do
3043 begin
3044 if alive then
3045 begin
3046 // Ëåâûé âåðõíèé óãîë
3047 aX := Obj.X div ScaleSz + 1;
3048 aY := Obj.Y div ScaleSz + 1;
3049 // Ðàçìåðû
3050 aX2 := max(Obj.Rect.Width div ScaleSz, 1);
3051 aY2 := max(Obj.Rect.Height div ScaleSz, 1);
3052 // Ïðàâûé íèæíèé óãîë
3053 aX2 := aX + aX2 - 1;
3054 aY2 := aY + aY2 - 1;
3055 e_DrawFillQuad(aX, aY, aX2, aY2, 255, 255, 0, 0);
3056 end;
3057 end;
3058 end;
3060 begin
3061 if (gMapInfo.Width > RenderRect.Right - RenderRect.Left) or
3062 (gMapInfo.Height > RenderRect.Bottom - RenderRect.Top) then
3063 begin
3064 Scale := 1;
3065 // Ñêîëüêî ïèêñåëîâ êàðòû â 1 ïèêñåëå ìèíè-êàðòû:
3066 ScaleSz := 16 div Scale;
3067 // Ðàçìåðû ìèíè-êàðòû:
3068 aX := max(gMapInfo.Width div ScaleSz, 1);
3069 aY := max(gMapInfo.Height div ScaleSz, 1);
3070 // Ðàìêà êàðòû:
3071 e_DrawFillQuad(0, 0, aX-1, aY-1, 0, 0, 0, 0);
3073 if gWalls <> nil then
3074 begin
3075 // Ðèñóåì ñòåíû:
3076 for a := 0 to High(gWalls) do
3077 with gWalls[a] do
3078 if PanelType <> 0 then
3079 begin
3080 // Ëåâûé âåðõíèé óãîë:
3081 aX := X div ScaleSz;
3082 aY := Y div ScaleSz;
3083 // Ðàçìåðû:
3084 aX2 := max(Width div ScaleSz, 1);
3085 aY2 := max(Height div ScaleSz, 1);
3086 // Ïðàâûé íèæíèé óãîë:
3087 aX2 := aX + aX2 - 1;
3088 aY2 := aY + aY2 - 1;
3090 case PanelType of
3091 PANEL_WALL: e_DrawFillQuad(aX, aY, aX2, aY2, 208, 208, 208, 0);
3092 PANEL_OPENDOOR, PANEL_CLOSEDOOR:
3093 if Enabled then e_DrawFillQuad(aX, aY, aX2, aY2, 160, 160, 160, 0);
3094 end;
3095 end;
3096 end;
3097 if gSteps <> nil then
3098 begin
3099 // Ðèñóåì ñòóïåíè:
3100 for a := 0 to High(gSteps) do
3101 with gSteps[a] do
3102 if PanelType <> 0 then
3103 begin
3104 // Ëåâûé âåðõíèé óãîë:
3105 aX := X div ScaleSz;
3106 aY := Y div ScaleSz;
3107 // Ðàçìåðû:
3108 aX2 := max(Width div ScaleSz, 1);
3109 aY2 := max(Height div ScaleSz, 1);
3110 // Ïðàâûé íèæíèé óãîë:
3111 aX2 := aX + aX2 - 1;
3112 aY2 := aY + aY2 - 1;
3114 e_DrawFillQuad(aX, aY, aX2, aY2, 128, 128, 128, 0);
3115 end;
3116 end;
3117 if gLifts <> nil then
3118 begin
3119 // Ðèñóåì ëèôòû:
3120 for a := 0 to High(gLifts) do
3121 with gLifts[a] do
3122 if PanelType <> 0 then
3123 begin
3124 // Ëåâûé âåðõíèé óãîë:
3125 aX := X div ScaleSz;
3126 aY := Y div ScaleSz;
3127 // Ðàçìåðû:
3128 aX2 := max(Width div ScaleSz, 1);
3129 aY2 := max(Height div ScaleSz, 1);
3130 // Ïðàâûé íèæíèé óãîë:
3131 aX2 := aX + aX2 - 1;
3132 aY2 := aY + aY2 - 1;
3134 case LiftType of
3135 LIFTTYPE_UP: e_DrawFillQuad(aX, aY, aX2, aY2, 116, 72, 36, 0);
3136 LIFTTYPE_DOWN: e_DrawFillQuad(aX, aY, aX2, aY2, 116, 124, 96, 0);
3137 LIFTTYPE_LEFT: e_DrawFillQuad(aX, aY, aX2, aY2, 200, 80, 4, 0);
3138 LIFTTYPE_RIGHT: e_DrawFillQuad(aX, aY, aX2, aY2, 252, 140, 56, 0);
3139 end;
3140 end;
3141 end;
3142 if gWater <> nil then
3143 begin
3144 // Ðèñóåì âîäó:
3145 for a := 0 to High(gWater) do
3146 with gWater[a] do
3147 if PanelType <> 0 then
3148 begin
3149 // Ëåâûé âåðõíèé óãîë:
3150 aX := X div ScaleSz;
3151 aY := Y div ScaleSz;
3152 // Ðàçìåðû:
3153 aX2 := max(Width div ScaleSz, 1);
3154 aY2 := max(Height div ScaleSz, 1);
3155 // Ïðàâûé íèæíèé óãîë:
3156 aX2 := aX + aX2 - 1;
3157 aY2 := aY + aY2 - 1;
3159 e_DrawFillQuad(aX, aY, aX2, aY2, 0, 0, 192, 0);
3160 end;
3161 end;
3162 if gAcid1 <> nil then
3163 begin
3164 // Ðèñóåì êèñëîòó 1:
3165 for a := 0 to High(gAcid1) do
3166 with gAcid1[a] do
3167 if PanelType <> 0 then
3168 begin
3169 // Ëåâûé âåðõíèé óãîë:
3170 aX := X div ScaleSz;
3171 aY := Y div ScaleSz;
3172 // Ðàçìåðû:
3173 aX2 := max(Width div ScaleSz, 1);
3174 aY2 := max(Height div ScaleSz, 1);
3175 // Ïðàâûé íèæíèé óãîë:
3176 aX2 := aX + aX2 - 1;
3177 aY2 := aY + aY2 - 1;
3179 e_DrawFillQuad(aX, aY, aX2, aY2, 0, 176, 0, 0);
3180 end;
3181 end;
3182 if gAcid2 <> nil then
3183 begin
3184 // Ðèñóåì êèñëîòó 2:
3185 for a := 0 to High(gAcid2) do
3186 with gAcid2[a] do
3187 if PanelType <> 0 then
3188 begin
3189 // Ëåâûé âåðõíèé óãîë:
3190 aX := X div ScaleSz;
3191 aY := Y div ScaleSz;
3192 // Ðàçìåðû:
3193 aX2 := max(Width div ScaleSz, 1);
3194 aY2 := max(Height div ScaleSz, 1);
3195 // Ïðàâûé íèæíèé óãîë:
3196 aX2 := aX + aX2 - 1;
3197 aY2 := aY + aY2 - 1;
3199 e_DrawFillQuad(aX, aY, aX2, aY2, 176, 0, 0, 0);
3200 end;
3201 end;
3202 if gPlayers <> nil then
3203 begin
3204 // Ðèñóåì èãðîêîâ:
3205 for a := 0 to High(gPlayers) do
3206 if gPlayers[a] <> nil then with gPlayers[a] do
3207 if alive then begin
3208 // Ëåâûé âåðõíèé óãîë:
3209 aX := Obj.X div ScaleSz + 1;
3210 aY := Obj.Y div ScaleSz + 1;
3211 // Ðàçìåðû:
3212 aX2 := max(Obj.Rect.Width div ScaleSz, 1);
3213 aY2 := max(Obj.Rect.Height div ScaleSz, 1);
3214 // Ïðàâûé íèæíèé óãîë:
3215 aX2 := aX + aX2 - 1;
3216 aY2 := aY + aY2 - 1;
3218 if gPlayers[a] = p then
3219 e_DrawFillQuad(aX, aY, aX2, aY2, 0, 255, 0, 0)
3220 else
3221 case Team of
3222 TEAM_RED: e_DrawFillQuad(aX, aY, aX2, aY2, 255, 0, 0, 0);
3223 TEAM_BLUE: e_DrawFillQuad(aX, aY, aX2, aY2, 0, 0, 255, 0);
3224 else e_DrawFillQuad(aX, aY, aX2, aY2, 255, 128, 0, 0);
3225 end;
3226 end;
3227 end;
3228 // Ðèñóåì ìîíñòðîâ
3229 g_Mons_ForEach(monDraw);
3230 end;
3231 end;
3234 procedure renderAmbientQuad (hasAmbient: Boolean; constref ambColor: TDFColor);
3235 begin
3236 if not hasAmbient then exit;
3237 e_AmbientQuad(sX, sY, sWidth, sHeight, ambColor.r, ambColor.g, ambColor.b, ambColor.a);
3238 end;
3241 // setup sX, sY, sWidth, sHeight, and transformation matrix before calling this!
3242 //FIXME: broken for splitscreen mode
3243 procedure renderDynLightsInternal ();
3244 var
3245 //hasAmbient: Boolean;
3246 //ambColor: TDFColor;
3247 lln: Integer;
3248 lx, ly, lrad: Integer;
3249 scxywh: array[0..3] of GLint;
3250 wassc: Boolean;
3251 begin
3252 if e_NoGraphics then exit;
3254 //TODO: lights should be in separate grid, i think
3255 // but on the other side: grid may be slower for dynlights, as their lifetime is short
3256 if (not gwin_k8_enable_light_experiments) or (not gwin_has_stencil) or (g_dynLightCount < 1) then exit;
3258 // rendering mode
3259 //ambColor := gCurrentMap['light_ambient'].rgba;
3260 //hasAmbient := (not ambColor.isOpaque) or (not ambColor.isBlack);
3262 { // this will multiply incoming color to alpha from framebuffer
3263 glEnable(GL_BLEND);
3264 glBlendFunc(GL_DST_ALPHA, GL_ONE);
3267 (*
3268 * light rendering: (INVALID!)
3269 * glStencilFunc(GL_EQUAL, 0, $ff);
3270 * for each light:
3271 * glClear(GL_STENCIL_BUFFER_BIT);
3272 * glStencilOp(GL_KEEP, GL_KEEP, GL_INCR);
3273 * draw shadow volume into stencil buffer
3274 * glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); // modify color buffer
3275 * glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); // don't modify stencil buffer
3276 * turn off blending
3277 * draw color-less quad with light alpha (WARNING! don't touch color!)
3278 * glEnable(GL_BLEND);
3279 * glBlendFunc(GL_DST_ALPHA, GL_ONE);
3280 * draw all geometry up to and including walls (with alpha-testing, probably) -- this does lighting
3281 *)
3282 wassc := (glIsEnabled(GL_SCISSOR_TEST) <> 0);
3283 if wassc then glGetIntegerv(GL_SCISSOR_BOX, @scxywh[0]) else glGetIntegerv(GL_VIEWPORT, @scxywh[0]);
3285 // setup OpenGL parameters
3286 glStencilMask($FFFFFFFF);
3287 glStencilFunc(GL_ALWAYS, 0, $FFFFFFFF);
3288 glEnable(GL_STENCIL_TEST);
3289 glEnable(GL_SCISSOR_TEST);
3290 glClear(GL_STENCIL_BUFFER_BIT);
3291 glStencilFunc(GL_EQUAL, 0, $ff);
3293 for lln := 0 to g_dynLightCount-1 do
3294 begin
3295 lx := g_dynLights[lln].x;
3296 ly := g_dynLights[lln].y;
3297 lrad := g_dynLights[lln].radius;
3298 if (lrad < 3) then continue;
3300 if (lx-sX+lrad < 0) then continue;
3301 if (ly-sY+lrad < 0) then continue;
3302 if (lx-sX-lrad >= gPlayerScreenSize.X) then continue;
3303 if (ly-sY-lrad >= gPlayerScreenSize.Y) then continue;
3305 // set scissor to optimize drawing
3306 if (g_dbg_scale = 1.0) then
3307 begin
3308 glScissor((lx-sX)-lrad+2, gPlayerScreenSize.Y-(ly-sY)-lrad-1+2, lrad*2-4, lrad*2-4);
3309 end
3310 else
3311 begin
3312 glScissor(0, 0, gWinSizeX, gWinSizeY);
3313 end;
3314 // no need to clear stencil buffer, light blitting will do it for us... but only for normal scale
3315 if (g_dbg_scale <> 1.0) then glClear(GL_STENCIL_BUFFER_BIT);
3316 glStencilOp(GL_KEEP, GL_KEEP, GL_INCR);
3317 // draw extruded panels
3318 glDisable(GL_TEXTURE_2D);
3319 glDisable(GL_BLEND);
3320 glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); // no need to modify color buffer
3321 if (lrad > 4) then g_Map_DrawPanelShadowVolumes(lx, ly, lrad);
3322 // render light texture
3323 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); // modify color buffer
3324 glStencilOp(GL_ZERO, GL_ZERO, GL_ZERO); // draw light, and clear stencil buffer
3325 // blend it
3326 glEnable(GL_BLEND);
3327 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
3328 glEnable(GL_TEXTURE_2D);
3329 // color and opacity
3330 glColor4f(g_dynLights[lln].r, g_dynLights[lln].g, g_dynLights[lln].b, g_dynLights[lln].a);
3331 glBindTexture(GL_TEXTURE_2D, g_Texture_Light());
3332 glBegin(GL_QUADS);
3333 glTexCoord2f(0.0, 0.0); glVertex2i(lx-lrad, ly-lrad); // top-left
3334 glTexCoord2f(1.0, 0.0); glVertex2i(lx+lrad, ly-lrad); // top-right
3335 glTexCoord2f(1.0, 1.0); glVertex2i(lx+lrad, ly+lrad); // bottom-right
3336 glTexCoord2f(0.0, 1.0); glVertex2i(lx-lrad, ly+lrad); // bottom-left
3337 glEnd();
3338 end;
3340 // done
3341 glDisable(GL_STENCIL_TEST);
3342 glDisable(GL_BLEND);
3343 glDisable(GL_SCISSOR_TEST);
3344 //glScissor(0, 0, sWidth, sHeight);
3346 glScissor(scxywh[0], scxywh[1], scxywh[2], scxywh[3]);
3347 if wassc then glEnable(GL_SCISSOR_TEST) else glDisable(GL_SCISSOR_TEST);
3348 end;
3351 function fixViewportForScale (): Boolean;
3352 var
3353 nx0, ny0, nw, nh: Integer;
3354 begin
3355 result := false;
3356 if (g_dbg_scale <> 1.0) then
3357 begin
3358 result := true;
3359 nx0 := round(sX-(gPlayerScreenSize.X-(sWidth*g_dbg_scale))/2/g_dbg_scale);
3360 ny0 := round(sY-(gPlayerScreenSize.Y-(sHeight*g_dbg_scale))/2/g_dbg_scale);
3361 nw := round(sWidth/g_dbg_scale);
3362 nh := round(sHeight/g_dbg_scale);
3363 sX := nx0;
3364 sY := ny0;
3365 sWidth := nw;
3366 sHeight := nh;
3367 end;
3368 end;
3371 // setup sX, sY, sWidth, sHeight, and transformation matrix before calling this!
3372 // WARNING! this WILL CALL `glTranslatef()`, but won't restore matrices!
3373 procedure renderMapInternal (backXOfs, backYOfs: Integer; setTransMatrix: Boolean);
3374 type
3375 TDrawCB = procedure ();
3377 var
3378 hasAmbient: Boolean;
3379 ambColor: TDFColor;
3380 doAmbient: Boolean = false;
3382 procedure drawPanelType (profname: AnsiString; panType: DWord; doDraw: Boolean);
3383 var
3384 tagmask: Integer;
3385 pan: TPanel;
3386 begin
3387 if (profileFrameDraw <> nil) then profileFrameDraw.sectionBegin(profname);
3388 if gdbg_map_use_accel_render then
3389 begin
3390 tagmask := panelTypeToTag(panType);
3391 while (gDrawPanelList.count > 0) do
3392 begin
3393 pan := TPanel(gDrawPanelList.front());
3394 if ((pan.tag and tagmask) = 0) then break;
3395 if doDraw then pan.Draw(doAmbient, ambColor);
3396 gDrawPanelList.popFront();
3397 end;
3398 end
3399 else
3400 begin
3401 if doDraw then g_Map_DrawPanels(panType, hasAmbient, ambColor);
3402 end;
3403 if (profileFrameDraw <> nil) then profileFrameDraw.sectionEnd();
3404 end;
3406 procedure drawOther (profname: AnsiString; cb: TDrawCB);
3407 begin
3408 if (profileFrameDraw <> nil) then profileFrameDraw.sectionBegin(profname);
3409 if assigned(cb) then cb();
3410 if (profileFrameDraw <> nil) then profileFrameDraw.sectionEnd();
3411 end;
3413 begin
3414 if (profileFrameDraw <> nil) then profileFrameDraw.sectionBegin('total');
3416 // our accelerated renderer will collect all panels to gDrawPanelList
3417 // we can use panel tag to render level parts (see GridTagXXX in g_map.pas)
3418 if (profileFrameDraw <> nil) then profileFrameDraw.sectionBegin('collect');
3419 if gdbg_map_use_accel_render then
3420 begin
3421 g_Map_CollectDrawPanels(sX, sY, sWidth, sHeight);
3422 end;
3423 if (profileFrameDraw <> nil) then profileFrameDraw.sectionEnd();
3425 if (profileFrameDraw <> nil) then profileFrameDraw.sectionBegin('skyback');
3426 g_Map_DrawBack(backXOfs, backYOfs);
3427 if (profileFrameDraw <> nil) then profileFrameDraw.sectionEnd();
3429 if setTransMatrix then
3430 begin
3431 //if (g_dbg_scale <> 1.0) then glTranslatef(0.0, -0.375/2, 0);
3432 glScalef(g_dbg_scale, g_dbg_scale, 1.0);
3433 glTranslatef(-sX, -sY, 0);
3434 end;
3436 // rendering mode
3437 ambColor := gCurrentMap['light_ambient'].rgba;
3438 hasAmbient := (not ambColor.isOpaque) or (not ambColor.isBlack);
3441 if hasAmbient then
3442 begin
3443 //writeln('color: (', ambColor.r, ',', ambColor.g, ',', ambColor.b, ',', ambColor.a, ')');
3444 glColor4ub(ambColor.r, ambColor.g, ambColor.b, ambColor.a);
3445 glClear(GL_COLOR_BUFFER_BIT);
3446 end;
3448 //writeln('color: (', ambColor.r, ',', ambColor.g, ',', ambColor.b, ',', ambColor.a, ')');
3451 drawPanelType('*back', PANEL_BACK, g_rlayer_back);
3452 drawPanelType('*step', PANEL_STEP, g_rlayer_step);
3453 drawOther('items', @g_Items_Draw);
3454 drawOther('weapons', @g_Weapon_Draw);
3455 drawOther('shells', @g_Player_DrawShells);
3456 drawOther('drawall', @g_Player_DrawAll);
3457 drawOther('corpses', @g_Player_DrawCorpses);
3458 drawPanelType('*wall', PANEL_WALL, g_rlayer_wall);
3459 drawOther('monsters', @g_Monsters_Draw);
3460 drawOther('itemdrop', @g_Items_DrawDrop);
3461 drawPanelType('*door', PANEL_CLOSEDOOR, g_rlayer_door);
3462 drawOther('gfx', @g_GFX_Draw);
3463 drawOther('flags', @g_Map_DrawFlags);
3464 drawPanelType('*acid1', PANEL_ACID1, g_rlayer_acid1);
3465 drawPanelType('*acid2', PANEL_ACID2, g_rlayer_acid2);
3466 drawPanelType('*water', PANEL_WATER, g_rlayer_water);
3467 drawOther('dynlights', @renderDynLightsInternal);
3469 if hasAmbient {and ((not g_playerLight) or (not gwin_has_stencil) or (g_dynLightCount < 1))} then
3470 begin
3471 renderAmbientQuad(hasAmbient, ambColor);
3472 end;
3474 doAmbient := true;
3475 drawPanelType('*fore', PANEL_FORE, g_rlayer_fore);
3478 if g_debug_HealthBar then
3479 begin
3480 g_Monsters_DrawHealth();
3481 g_Player_DrawHealth();
3482 end;
3484 if (profileFrameDraw <> nil) then profileFrameDraw.mainEnd(); // map rendering
3485 end;
3488 procedure DrawMapView(x, y, w, h: Integer);
3490 var
3491 bx, by: Integer;
3492 begin
3493 glPushMatrix();
3495 bx := Round(x/(gMapInfo.Width - w)*(gBackSize.X - w));
3496 by := Round(y/(gMapInfo.Height - h)*(gBackSize.Y - h));
3498 sX := x;
3499 sY := y;
3500 sWidth := w;
3501 sHeight := h;
3503 fixViewportForScale();
3504 renderMapInternal(-bx, -by, true);
3506 glPopMatrix();
3507 end;
3510 procedure DrawPlayer(p: TPlayer);
3511 var
3512 px, py, a, b, c, d: Integer;
3513 //R: TRect;
3514 begin
3515 if (p = nil) or (p.FDummy) then
3516 begin
3517 glPushMatrix();
3518 g_Map_DrawBack(0, 0);
3519 glPopMatrix();
3520 Exit;
3521 end;
3523 if (profileFrameDraw = nil) then profileFrameDraw := TProfiler.Create('RENDER', g_profile_history_size);
3524 if (profileFrameDraw <> nil) then profileFrameDraw.mainBegin(g_profile_frame_draw);
3526 gPlayerDrawn := p;
3528 glPushMatrix();
3530 px := p.GameX + PLAYER_RECT_CX;
3531 py := p.GameY + PLAYER_RECT_CY+p.Obj.slopeUpLeft;
3533 if (g_dbg_scale = 1.0) and (not g_dbg_ignore_bounds) then
3534 begin
3535 if (px > (gPlayerScreenSize.X div 2)) then a := -px+(gPlayerScreenSize.X div 2) else a := 0;
3536 if (py > (gPlayerScreenSize.Y div 2)) then b := -py+(gPlayerScreenSize.Y div 2) else b := 0;
3538 if (px > gMapInfo.Width-(gPlayerScreenSize.X div 2)) then a := -gMapInfo.Width+gPlayerScreenSize.X;
3539 if (py > gMapInfo.Height-(gPlayerScreenSize.Y div 2)) then b := -gMapInfo.Height+gPlayerScreenSize.Y;
3541 if (gMapInfo.Width = gPlayerScreenSize.X) then a := 0
3542 else if (gMapInfo.Width < gPlayerScreenSize.X) then
3543 begin
3544 // hcenter
3545 a := (gPlayerScreenSize.X-gMapInfo.Width) div 2;
3546 end;
3548 if (gMapInfo.Height = gPlayerScreenSize.Y) then b := 0
3549 else if (gMapInfo.Height < gPlayerScreenSize.Y) then
3550 begin
3551 // vcenter
3552 b := (gPlayerScreenSize.Y-gMapInfo.Height) div 2;
3553 end;
3554 end
3555 else
3556 begin
3557 // scaled, ignore level bounds
3558 a := -px+(gPlayerScreenSize.X div 2);
3559 b := -py+(gPlayerScreenSize.Y div 2);
3560 end;
3562 if p.IncCam <> 0 then
3563 begin
3564 if py > gMapInfo.Height-(gPlayerScreenSize.Y div 2) then
3565 begin
3566 if p.IncCam > 120-(py-(gMapInfo.Height-(gPlayerScreenSize.Y div 2))) then
3567 begin
3568 p.IncCam := 120-(py-(gMapInfo.Height-(gPlayerScreenSize.Y div 2)));
3569 end;
3570 end;
3572 if py < gPlayerScreenSize.Y div 2 then
3573 begin
3574 if p.IncCam < -120+((gPlayerScreenSize.Y div 2)-py) then
3575 begin
3576 p.IncCam := -120+((gPlayerScreenSize.Y div 2)-py);
3577 end;
3578 end;
3580 if p.IncCam < 0 then
3581 begin
3582 while (py+(gPlayerScreenSize.Y div 2)-p.IncCam > gMapInfo.Height) and (p.IncCam < 0) do p.IncCam := p.IncCam+1; //Inc(p.IncCam);
3583 end;
3585 if p.IncCam > 0 then
3586 begin
3587 while (py-(gPlayerScreenSize.Y div 2)-p.IncCam < 0) and (p.IncCam > 0) do p.IncCam := p.IncCam-1; //Dec(p.IncCam);
3588 end;
3589 end;
3591 if (px < gPlayerScreenSize.X div 2) or (gMapInfo.Width-gPlayerScreenSize.X <= 256) then c := 0
3592 else if (px > gMapInfo.Width-(gPlayerScreenSize.X div 2)) then c := gBackSize.X-gPlayerScreenSize.X
3593 else c := round((px-(gPlayerScreenSize.X div 2))/(gMapInfo.Width-gPlayerScreenSize.X)*(gBackSize.X-gPlayerScreenSize.X));
3595 if (py-p.IncCam <= gPlayerScreenSize.Y div 2) or (gMapInfo.Height-gPlayerScreenSize.Y <= 256) then d := 0
3596 else if (py-p.IncCam >= gMapInfo.Height-(gPlayerScreenSize.Y div 2)) then d := gBackSize.Y-gPlayerScreenSize.Y
3597 else d := round((py-p.IncCam-(gPlayerScreenSize.Y div 2))/(gMapInfo.Height-gPlayerScreenSize.Y)*(gBackSize.Y-gPlayerScreenSize.Y));
3599 sX := -a;
3600 sY := -(b+p.IncCam);
3601 sWidth := gPlayerScreenSize.X;
3602 sHeight := gPlayerScreenSize.Y;
3604 //glTranslatef(a, b+p.IncCam, 0);
3606 //if (p = gPlayer1) and (g_dbg_scale >= 1.0) then g_Holmes_plrViewSize(sWidth, sHeight);
3608 //conwritefln('OLD: (%s,%s)-(%s,%s)', [sX, sY, sWidth, sHeight]);
3609 fixViewportForScale();
3610 //conwritefln(' (%s,%s)-(%s,%s)', [sX, sY, sWidth, sHeight]);
3612 if (g_dbg_scale <> 1.0) and (not g_dbg_ignore_bounds) then
3613 begin
3614 if (sX+sWidth > gMapInfo.Width) then sX := gMapInfo.Width-sWidth;
3615 if (sY+sHeight > gMapInfo.Height) then sY := gMapInfo.Height-sHeight;
3616 if (sX < 0) then sX := 0;
3617 if (sY < 0) then sY := 0;
3619 if (gBackSize.X <= gPlayerScreenSize.X) or (gMapInfo.Width <= sWidth) then c := 0 else c := trunc((gBackSize.X-gPlayerScreenSize.X)*sX/(gMapInfo.Width-sWidth));
3620 if (gBackSize.Y <= gPlayerScreenSize.Y) or (gMapInfo.Height <= sHeight) then d := 0 else d := trunc((gBackSize.Y-gPlayerScreenSize.Y)*sY/(gMapInfo.Height-sHeight));
3621 end;
3623 //r_smallmap_h: 0: left; 1: center; 2: right
3624 //r_smallmap_v: 0: top; 1: center; 2: bottom
3625 // horiz small map?
3626 if (gMapInfo.Width = sWidth) then
3627 begin
3628 sX := 0;
3629 end
3630 else if (gMapInfo.Width < sWidth) then
3631 begin
3632 case r_smallmap_h of
3633 1: sX := -((sWidth-gMapInfo.Width) div 2); // center
3634 2: sX := -(sWidth-gMapInfo.Width); // right
3635 else sX := 0; // left
3636 end;
3637 end;
3638 // vert small map?
3639 if (gMapInfo.Height = sHeight) then
3640 begin
3641 sY := 0;
3642 end
3643 else if (gMapInfo.Height < sHeight) then
3644 begin
3645 case r_smallmap_v of
3646 1: sY := -((sHeight-gMapInfo.Height) div 2); // center
3647 2: sY := -(sHeight-gMapInfo.Height); // bottom
3648 else sY := 0; // top
3649 end;
3650 end;
3652 p.viewPortX := sX;
3653 p.viewPortY := sY;
3654 p.viewPortW := sWidth;
3655 p.viewPortH := sHeight;
3657 {$IFDEF ENABLE_HOLMES}
3658 if (p = gPlayer1) then
3659 begin
3660 g_Holmes_plrViewPos(sX, sY);
3661 g_Holmes_plrViewSize(sWidth, sHeight);
3662 end;
3663 {$ENDIF}
3665 renderMapInternal(-c, -d, true);
3667 if (gGameSettings.GameMode <> GM_SINGLE) and gPlayerIndicator then
3668 p.DrawIndicator();
3669 if p.FSpectator then
3670 e_TextureFontPrintEx(p.GameX + PLAYER_RECT_CX - 4,
3671 p.GameY + PLAYER_RECT_CY - 4,
3672 'X', gStdFont, 255, 255, 255, 1, True);
3674 for a := 0 to High(gCollideMap) do
3675 for b := 0 to High(gCollideMap[a]) do
3676 begin
3677 d := 0;
3678 if ByteBool(gCollideMap[a, b] and MARK_WALL) then
3679 d := d + 1;
3680 if ByteBool(gCollideMap[a, b] and MARK_DOOR) then
3681 d := d + 2;
3683 case d of
3684 1: e_DrawPoint(1, b, a, 200, 200, 200);
3685 2: e_DrawPoint(1, b, a, 64, 64, 255);
3686 3: e_DrawPoint(1, b, a, 255, 0, 255);
3687 end;
3688 end;
3691 glPopMatrix();
3693 p.DrawPain();
3694 p.DrawPickup();
3695 p.DrawRulez();
3696 if gShowMap then DrawMinimap(p, _TRect(0, 0, 128, 128));
3697 if g_Debug_Player then
3698 g_Player_DrawDebug(p);
3699 p.DrawGUI();
3700 end;
3702 procedure drawProfilers ();
3703 var
3704 px: Integer = -1;
3705 py: Integer = -1;
3706 begin
3707 if g_profile_frame_draw and (profileFrameDraw <> nil) then px := px-drawProfiles(px, py, profileFrameDraw);
3708 if g_profile_collision and (profMapCollision <> nil) then begin px := px-drawProfiles(px, py, profMapCollision); py -= calcProfilesHeight(profMonsLOS); end;
3709 if g_profile_los and (profMonsLOS <> nil) then begin px := px-drawProfiles(px, py, profMonsLOS); py -= calcProfilesHeight(profMonsLOS); end;
3710 end;
3712 procedure g_Game_Draw();
3713 var
3714 ID: DWORD;
3715 w, h: Word;
3716 ww, hh: Byte;
3717 Time: Int64;
3718 back: string;
3719 plView1, plView2: TPlayer;
3720 Split: Boolean;
3721 begin
3722 if gExit = EXIT_QUIT then Exit;
3724 Time := GetTimer() {div 1000};
3725 FPSCounter := FPSCounter+1;
3726 if Time - FPSTime >= 1000 then
3727 begin
3728 FPS := FPSCounter;
3729 FPSCounter := 0;
3730 FPSTime := Time;
3731 end;
3733 if gGameOn or (gState = STATE_FOLD) then
3734 begin
3735 if (gPlayer1 <> nil) and (gPlayer2 <> nil) then
3736 begin
3737 gSpectMode := SPECT_NONE;
3738 if not gRevertPlayers then
3739 begin
3740 plView1 := gPlayer1;
3741 plView2 := gPlayer2;
3742 end
3743 else
3744 begin
3745 plView1 := gPlayer2;
3746 plView2 := gPlayer1;
3747 end;
3748 end
3749 else
3750 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
3751 begin
3752 gSpectMode := SPECT_NONE;
3753 if gPlayer2 = nil then
3754 plView1 := gPlayer1
3755 else
3756 plView1 := gPlayer2;
3757 plView2 := nil;
3758 end
3759 else
3760 begin
3761 plView1 := nil;
3762 plView2 := nil;
3763 end;
3765 if (plView1 = nil) and (plView2 = nil) and (gSpectMode = SPECT_NONE) then
3766 gSpectMode := SPECT_STATS;
3768 if gSpectMode = SPECT_PLAYERS then
3769 if gPlayers <> nil then
3770 begin
3771 plView1 := GetActivePlayer_ByID(gSpectPID1);
3772 if plView1 = nil then
3773 begin
3774 gSpectPID1 := GetActivePlayerID_Next();
3775 plView1 := GetActivePlayer_ByID(gSpectPID1);
3776 end;
3777 if gSpectViewTwo then
3778 begin
3779 plView2 := GetActivePlayer_ByID(gSpectPID2);
3780 if plView2 = nil then
3781 begin
3782 gSpectPID2 := GetActivePlayerID_Next();
3783 plView2 := GetActivePlayer_ByID(gSpectPID2);
3784 end;
3785 end;
3786 end;
3788 if gSpectMode = SPECT_MAPVIEW then
3789 begin
3790 // Ðåæèì ïðîñìîòðà êàðòû
3791 Split := False;
3792 e_SetViewPort(0, 0, gScreenWidth, gScreenHeight);
3793 DrawMapView(gSpectX, gSpectY, gScreenWidth, gScreenHeight);
3794 gHearPoint1.Active := True;
3795 gHearPoint1.Coords.X := gScreenWidth div 2 + gSpectX;
3796 gHearPoint1.Coords.Y := gScreenHeight div 2 + gSpectY;
3797 gHearPoint2.Active := False;
3798 end
3799 else
3800 begin
3801 Split := (plView1 <> nil) and (plView2 <> nil);
3803 // Òî÷êè ñëóõà èãðîêîâ
3804 if plView1 <> nil then
3805 begin
3806 gHearPoint1.Active := True;
3807 gHearPoint1.Coords.X := plView1.GameX + PLAYER_RECT.Width;
3808 gHearPoint1.Coords.Y := plView1.GameY + PLAYER_RECT.Height DIV 2;
3809 end else
3810 gHearPoint1.Active := False;
3811 if plView2 <> nil then
3812 begin
3813 gHearPoint2.Active := True;
3814 gHearPoint2.Coords.X := plView2.GameX + PLAYER_RECT.Width;
3815 gHearPoint2.Coords.Y := plView2.GameY + PLAYER_RECT.Height DIV 2;
3816 end else
3817 gHearPoint2.Active := False;
3819 // Ðàçìåð ýêðàíîâ èãðîêîâ:
3820 gPlayerScreenSize.X := gScreenWidth-196;
3821 if Split then
3822 begin
3823 gPlayerScreenSize.Y := gScreenHeight div 2;
3824 if gScreenHeight mod 2 = 0 then
3825 Dec(gPlayerScreenSize.Y);
3826 end
3827 else
3828 gPlayerScreenSize.Y := gScreenHeight;
3830 if Split then
3831 if gScreenHeight mod 2 = 0 then
3832 e_SetViewPort(0, gPlayerScreenSize.Y+2, gPlayerScreenSize.X+196, gPlayerScreenSize.Y)
3833 else
3834 e_SetViewPort(0, gPlayerScreenSize.Y+1, gPlayerScreenSize.X+196, gPlayerScreenSize.Y);
3836 DrawPlayer(plView1);
3837 gPlayer1ScreenCoord.X := sX;
3838 gPlayer1ScreenCoord.Y := sY;
3840 if Split then
3841 begin
3842 e_SetViewPort(0, 0, gPlayerScreenSize.X+196, gPlayerScreenSize.Y);
3844 DrawPlayer(plView2);
3845 gPlayer2ScreenCoord.X := sX;
3846 gPlayer2ScreenCoord.Y := sY;
3847 end;
3849 e_SetViewPort(0, 0, gScreenWidth, gScreenHeight);
3851 if Split then
3852 e_DrawLine(2, 0, gScreenHeight div 2, gScreenWidth, gScreenHeight div 2, 0, 0, 0);
3853 end;
3855 {$IFDEF ENABLE_HOLMES}
3856 // draw inspector
3857 if (g_holmes_enabled) then g_Holmes_Draw();
3858 {$ENDIF}
3860 if MessageText <> '' then
3861 begin
3862 w := 0;
3863 h := 0;
3864 e_CharFont_GetSizeFmt(gMenuFont, MessageText, w, h);
3865 if Split then
3866 e_CharFont_PrintFmt(gMenuFont, (gScreenWidth div 2)-(w div 2),
3867 (gScreenHeight div 2)-(h div 2), MessageText)
3868 else
3869 e_CharFont_PrintFmt(gMenuFont, (gScreenWidth div 2)-(w div 2),
3870 Round(gScreenHeight / 2.75)-(h div 2), MessageText);
3871 end;
3873 if IsDrawStat or (gSpectMode = 1) then DrawStat();
3875 if gSpectHUD and (not gChatShow) and (gSpectMode <> SPECT_NONE) and (not gSpectAuto) then
3876 begin
3877 // Draw spectator GUI
3878 ww := 0;
3879 hh := 0;
3880 e_TextureFontGetSize(gStdFont, ww, hh);
3881 case gSpectMode of
3882 SPECT_STATS:
3883 e_TextureFontPrintEx(0, gScreenHeight - (hh+2)*2, 'MODE: Stats', gStdFont, 255, 255, 255, 1);
3884 SPECT_MAPVIEW:
3885 e_TextureFontPrintEx(0, gScreenHeight - (hh+2)*2, 'MODE: Observe Map', gStdFont, 255, 255, 255, 1);
3886 SPECT_PLAYERS:
3887 e_TextureFontPrintEx(0, gScreenHeight - (hh+2)*2, 'MODE: Watch Players', gStdFont, 255, 255, 255, 1);
3888 end;
3889 e_TextureFontPrintEx(2*ww, gScreenHeight - (hh+2), '< jump >', gStdFont, 255, 255, 255, 1);
3890 if gSpectMode = SPECT_STATS then
3891 begin
3892 e_TextureFontPrintEx(16*ww, gScreenHeight - (hh+2)*2, 'Autoview', gStdFont, 255, 255, 255, 1);
3893 e_TextureFontPrintEx(16*ww, gScreenHeight - (hh+2), '< fire >', gStdFont, 255, 255, 255, 1);
3894 end;
3895 if gSpectMode = SPECT_MAPVIEW then
3896 begin
3897 e_TextureFontPrintEx(22*ww, gScreenHeight - (hh+2)*2, '[-]', gStdFont, 255, 255, 255, 1);
3898 e_TextureFontPrintEx(26*ww, gScreenHeight - (hh+2)*2, 'Step ' + IntToStr(gSpectStep), gStdFont, 255, 255, 255, 1);
3899 e_TextureFontPrintEx(34*ww, gScreenHeight - (hh+2)*2, '[+]', gStdFont, 255, 255, 255, 1);
3900 e_TextureFontPrintEx(18*ww, gScreenHeight - (hh+2), '<prev weap>', gStdFont, 255, 255, 255, 1);
3901 e_TextureFontPrintEx(30*ww, gScreenHeight - (hh+2), '<next weap>', gStdFont, 255, 255, 255, 1);
3902 end;
3903 if gSpectMode = SPECT_PLAYERS then
3904 begin
3905 e_TextureFontPrintEx(22*ww, gScreenHeight - (hh+2)*2, 'Player 1', gStdFont, 255, 255, 255, 1);
3906 e_TextureFontPrintEx(20*ww, gScreenHeight - (hh+2), '<left/right>', gStdFont, 255, 255, 255, 1);
3907 if gSpectViewTwo then
3908 begin
3909 e_TextureFontPrintEx(37*ww, gScreenHeight - (hh+2)*2, 'Player 2', gStdFont, 255, 255, 255, 1);
3910 e_TextureFontPrintEx(34*ww, gScreenHeight - (hh+2), '<prev w/next w>', gStdFont, 255, 255, 255, 1);
3911 e_TextureFontPrintEx(52*ww, gScreenHeight - (hh+2)*2, '2x View', gStdFont, 255, 255, 255, 1);
3912 e_TextureFontPrintEx(51*ww, gScreenHeight - (hh+2), '<up/down>', gStdFont, 255, 255, 255, 1);
3913 end
3914 else
3915 begin
3916 e_TextureFontPrintEx(35*ww, gScreenHeight - (hh+2)*2, '2x View', gStdFont, 255, 255, 255, 1);
3917 e_TextureFontPrintEx(34*ww, gScreenHeight - (hh+2), '<up/down>', gStdFont, 255, 255, 255, 1);
3918 end;
3919 end;
3920 end;
3921 end;
3923 if gPauseMain and gGameOn and (g_ActiveWindow = nil) then
3924 begin
3925 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
3926 e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
3928 e_CharFont_GetSize(gMenuFont, _lc[I_MENU_PAUSE], w, h);
3929 e_CharFont_Print(gMenuFont, (gScreenWidth div 2)-(w div 2),
3930 (gScreenHeight div 2)-(h div 2), _lc[I_MENU_PAUSE]);
3931 end;
3933 if not gGameOn then
3934 begin
3935 if (gState = STATE_MENU) then
3936 begin
3937 if (g_ActiveWindow = nil) or (g_ActiveWindow.BackTexture = '') then DrawMenuBackground('MENU_BACKGROUND');
3938 // F3 at menu will show game loading dialog
3939 if e_KeyPressed(IK_F3) then g_Menu_Show_LoadMenu(true);
3940 if (g_ActiveWindow <> nil) then
3941 begin
3942 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
3943 e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
3944 end
3945 else
3946 begin
3947 // F3 at titlepic will show game loading dialog
3948 if e_KeyPressed(IK_F3) then
3949 begin
3950 g_Menu_Show_LoadMenu(true);
3951 if (g_ActiveWindow <> nil) then e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
3952 end;
3953 end;
3954 end;
3956 if gState = STATE_FOLD then
3957 begin
3958 e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 0, 0, 0, EndingGameCounter);
3959 end;
3961 if gState = STATE_INTERCUSTOM then
3962 begin
3963 if gLastMap and (gGameSettings.GameMode = GM_COOP) then
3964 begin
3965 back := 'TEXTURE_endpic';
3966 if not g_Texture_Get(back, ID) then
3967 back := _lc[I_TEXTURE_ENDPIC];
3968 end
3969 else
3970 back := 'INTER';
3972 DrawMenuBackground(back);
3974 DrawCustomStat();
3976 if g_ActiveWindow <> nil then
3977 begin
3978 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
3979 e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
3980 end;
3981 end;
3983 if gState = STATE_INTERSINGLE then
3984 begin
3985 if EndingGameCounter > 0 then
3986 begin
3987 e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 0, 0, 0, EndingGameCounter);
3988 end
3989 else
3990 begin
3991 back := 'INTER';
3993 DrawMenuBackground(back);
3995 DrawSingleStat();
3997 if g_ActiveWindow <> nil then
3998 begin
3999 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4000 e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
4001 end;
4002 end;
4003 end;
4005 if gState = STATE_ENDPIC then
4006 begin
4007 ID := DWORD(-1);
4008 if g_Texture_Get('TEXTURE_endpic', ID) then DrawMenuBackground('TEXTURE_endpic')
4009 else DrawMenuBackground(_lc[I_TEXTURE_ENDPIC]);
4011 if g_ActiveWindow <> nil then
4012 begin
4013 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4014 e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
4015 end;
4016 end;
4018 if gState = STATE_SLIST then
4019 begin
4020 // if g_Texture_Get('MENU_BACKGROUND', ID) then
4021 // begin
4022 // e_DrawSize(ID, 0, 0, 0, False, False, gScreenWidth, gScreenHeight);
4023 // //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4024 // end;
4025 DrawMenuBackground('MENU_BACKGROUND');
4026 e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
4027 g_Serverlist_Draw(slCurrent, slTable);
4028 end;
4029 end;
4031 if g_ActiveWindow <> nil then
4032 begin
4033 if gGameOn then
4034 begin
4035 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4036 e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
4037 end;
4038 g_ActiveWindow.Draw();
4039 end;
4041 g_Console_Draw();
4043 if g_debug_Sounds and gGameOn then
4044 begin
4045 for w := 0 to High(e_SoundsArray) do
4046 for h := 0 to e_SoundsArray[w].nRefs do
4047 e_DrawPoint(1, w+100, h+100, 255, 0, 0);
4048 end;
4050 if gShowFPS then
4051 begin
4052 e_TextureFontPrint(0, 0, Format('FPS: %d', [FPS]), gStdFont);
4053 e_TextureFontPrint(0, 16, Format('UPS: %d', [UPS]), gStdFont);
4054 end;
4056 if gGameOn and gShowTime then
4057 drawTime(gScreenWidth-72, gScreenHeight-16);
4059 if gGameOn then drawProfilers();
4061 {$IFDEF ENABLE_HOLMES}
4062 g_Holmes_DrawUI();
4063 {$ENDIF}
4065 g_Touch_Draw;
4066 end;
4068 procedure g_Game_Quit();
4069 begin
4070 g_Game_StopAllSounds(True);
4071 gMusic.Free();
4072 g_Game_SaveOptions();
4073 g_Game_FreeData();
4074 g_PlayerModel_FreeData();
4075 g_Texture_DeleteAll();
4076 g_Frames_DeleteAll();
4077 //g_Menu_Free(); //k8: this segfaults after resolution change; who cares?
4079 if NetInitDone then g_Net_Free;
4081 // Íàäî óäàëèòü êàðòó ïîñëå òåñòà:
4082 if gMapToDelete <> '' then
4083 g_Game_DeleteTestMap();
4085 gExit := EXIT_QUIT;
4086 PushExitEvent();
4087 end;
4089 procedure g_FatalError(Text: String);
4090 begin
4091 g_Console_Add(Format(_lc[I_FATAL_ERROR], [Text]), True);
4092 e_WriteLog(Format(_lc[I_FATAL_ERROR], [Text]), TMsgType.Warning);
4094 gExit := EXIT_SIMPLE;
4095 end;
4097 procedure g_SimpleError(Text: String);
4098 begin
4099 g_Console_Add(Format(_lc[I_SIMPLE_ERROR], [Text]), True);
4100 e_WriteLog(Format(_lc[I_SIMPLE_ERROR], [Text]), TMsgType.Warning);
4101 end;
4103 procedure g_Game_SetupScreenSize();
4104 const
4105 RES_FACTOR = 4.0 / 3.0;
4106 var
4107 s: Single;
4108 rf: Single;
4109 bw, bh: Word;
4110 begin
4111 // Ðàçìåð ýêðàíîâ èãðîêîâ:
4112 gPlayerScreenSize.X := gScreenWidth-196;
4113 if (gPlayer1 <> nil) and (gPlayer2 <> nil) then
4114 gPlayerScreenSize.Y := gScreenHeight div 2
4115 else
4116 gPlayerScreenSize.Y := gScreenHeight;
4118 // Ðàçìåð çàäíåãî ïëàíà:
4119 if BackID <> DWORD(-1) then
4120 begin
4121 s := SKY_STRETCH;
4122 if (gScreenWidth*s > gMapInfo.Width) or
4123 (gScreenHeight*s > gMapInfo.Height) then
4124 begin
4125 gBackSize.X := gScreenWidth;
4126 gBackSize.Y := gScreenHeight;
4127 end
4128 else
4129 begin
4130 e_GetTextureSize(BackID, @bw, @bh);
4131 rf := Single(bw) / Single(bh);
4132 if (rf > RES_FACTOR) then bw := Round(Single(bh) * RES_FACTOR)
4133 else if (rf < RES_FACTOR) then bh := Round(Single(bw) / RES_FACTOR);
4134 s := Max(gScreenWidth / bw, gScreenHeight / bh);
4135 if (s < 1.0) then s := 1.0;
4136 gBackSize.X := Round(bw*s);
4137 gBackSize.Y := Round(bh*s);
4138 end;
4139 end;
4140 end;
4142 procedure g_Game_ChangeResolution(newWidth, newHeight: Word; nowFull, nowMax: Boolean);
4143 begin
4144 g_Window_SetSize(newWidth, newHeight, nowFull);
4145 end;
4147 procedure g_Game_AddPlayer(Team: Byte = TEAM_NONE);
4148 begin
4149 if ((not gGameOn) and (gState <> STATE_INTERCUSTOM))
4150 or (not (gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT])) then
4151 Exit;
4152 if gPlayer1 = nil then
4153 begin
4154 if g_Game_IsClient then
4155 begin
4156 if NetPlrUID1 > -1 then
4157 begin
4158 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE);
4159 gPlayer1 := g_Player_Get(NetPlrUID1);
4160 end;
4161 Exit;
4162 end;
4164 if not (Team in [TEAM_RED, TEAM_BLUE]) then
4165 Team := gPlayer1Settings.Team;
4167 // Ñîçäàíèå ïåðâîãî èãðîêà:
4168 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
4169 gPlayer1Settings.Color,
4170 Team, False));
4171 if gPlayer1 = nil then
4172 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]))
4173 else
4174 begin
4175 gPlayer1.Name := gPlayer1Settings.Name;
4176 g_Console_Add(Format(_lc[I_PLAYER_JOIN], [gPlayer1.Name]), True);
4177 if g_Game_IsServer and g_Game_IsNet then
4178 MH_SEND_PlayerCreate(gPlayer1.UID);
4179 gPlayer1.Respawn(False, True);
4181 if g_Game_IsNet and NetUseMaster then
4182 g_Net_Slist_Update;
4183 end;
4185 Exit;
4186 end;
4187 if gPlayer2 = nil then
4188 begin
4189 if g_Game_IsClient then
4190 begin
4191 if NetPlrUID2 > -1 then
4192 gPlayer2 := g_Player_Get(NetPlrUID2);
4193 Exit;
4194 end;
4196 if not (Team in [TEAM_RED, TEAM_BLUE]) then
4197 Team := gPlayer2Settings.Team;
4199 // Ñîçäàíèå âòîðîãî èãðîêà:
4200 gPlayer2 := g_Player_Get(g_Player_Create(gPlayer2Settings.Model,
4201 gPlayer2Settings.Color,
4202 Team, False));
4203 if gPlayer2 = nil then
4204 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [2]))
4205 else
4206 begin
4207 gPlayer2.Name := gPlayer2Settings.Name;
4208 g_Console_Add(Format(_lc[I_PLAYER_JOIN], [gPlayer2.Name]), True);
4209 if g_Game_IsServer and g_Game_IsNet then
4210 MH_SEND_PlayerCreate(gPlayer2.UID);
4211 gPlayer2.Respawn(False, True);
4213 if g_Game_IsNet and NetUseMaster then
4214 g_Net_Slist_Update;
4215 end;
4217 Exit;
4218 end;
4219 end;
4221 procedure g_Game_RemovePlayer();
4222 var
4223 Pl: TPlayer;
4224 begin
4225 if ((not gGameOn) and (gState <> STATE_INTERCUSTOM))
4226 or (not (gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT])) then
4227 Exit;
4228 Pl := gPlayer2;
4229 if Pl <> nil then
4230 begin
4231 if g_Game_IsServer then
4232 begin
4233 Pl.Lives := 0;
4234 Pl.Kill(K_SIMPLEKILL, 0, HIT_DISCON);
4235 g_Console_Add(Format(_lc[I_PLAYER_LEAVE], [Pl.Name]), True);
4236 g_Player_Remove(Pl.UID);
4238 if g_Game_IsNet and NetUseMaster then
4239 g_Net_Slist_Update;
4240 end else
4241 gPlayer2 := nil;
4242 Exit;
4243 end;
4244 Pl := gPlayer1;
4245 if Pl <> nil then
4246 begin
4247 if g_Game_IsServer then
4248 begin
4249 Pl.Lives := 0;
4250 Pl.Kill(K_SIMPLEKILL, 0, HIT_DISCON);
4251 g_Console_Add(Format(_lc[I_PLAYER_LEAVE], [Pl.Name]), True);
4252 g_Player_Remove(Pl.UID);
4254 if g_Game_IsNet and NetUseMaster then
4255 g_Net_Slist_Update;
4256 end else
4257 begin
4258 gPlayer1 := nil;
4259 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE);
4260 end;
4261 Exit;
4262 end;
4263 end;
4265 procedure g_Game_Spectate();
4266 begin
4267 g_Game_RemovePlayer();
4268 if gPlayer1 <> nil then
4269 g_Game_RemovePlayer();
4270 end;
4272 procedure g_Game_SpectateCenterView();
4273 begin
4274 gSpectX := Max(gMapInfo.Width div 2 - gScreenWidth div 2, 0);
4275 gSpectY := Max(gMapInfo.Height div 2 - gScreenHeight div 2, 0);
4276 end;
4278 procedure g_Game_StartSingle(Map: String; TwoPlayers: Boolean; nPlayers: Byte);
4279 var
4280 i, nPl: Integer;
4281 tmps: AnsiString;
4282 begin
4283 g_Game_Free();
4285 e_WriteLog('Starting singleplayer game...', TMsgType.Notify);
4287 g_Game_ClearLoading();
4289 // Íàñòðîéêè èãðû:
4290 FillByte(gGameSettings, SizeOf(TGameSettings), 0);
4291 gAimLine := False;
4292 gShowMap := False;
4293 gGameSettings.GameType := GT_SINGLE;
4294 gGameSettings.MaxLives := 0;
4295 gGameSettings.Options := gGameSettings.Options + GAME_OPTION_ALLOWEXIT;
4296 gGameSettings.Options := gGameSettings.Options + GAME_OPTION_MONSTERS;
4297 gGameSettings.Options := gGameSettings.Options + GAME_OPTION_BOTVSMONSTER;
4298 gSwitchGameMode := GM_SINGLE;
4300 g_Game_ExecuteEvent('ongamestart');
4302 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
4303 g_Game_SetupScreenSize();
4305 // Ñîçäàíèå ïåðâîãî èãðîêà:
4306 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
4307 gPlayer1Settings.Color,
4308 gPlayer1Settings.Team, False));
4309 if gPlayer1 = nil then
4310 begin
4311 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]));
4312 Exit;
4313 end;
4315 gPlayer1.Name := gPlayer1Settings.Name;
4316 nPl := 1;
4318 // Ñîçäàíèå âòîðîãî èãðîêà, åñëè åñòü:
4319 if TwoPlayers then
4320 begin
4321 gPlayer2 := g_Player_Get(g_Player_Create(gPlayer2Settings.Model,
4322 gPlayer2Settings.Color,
4323 gPlayer2Settings.Team, False));
4324 if gPlayer2 = nil then
4325 begin
4326 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [2]));
4327 Exit;
4328 end;
4330 gPlayer2.Name := gPlayer2Settings.Name;
4331 Inc(nPl);
4332 end;
4334 // Çàãðóçêà è çàïóñê êàðòû:
4335 if not g_Game_StartMap(MAP, True) then
4336 begin
4337 if (Pos(':\', Map) > 0) or (Pos(':/', Map) > 0) then tmps := Map else tmps := gGameSettings.WAD + ':\' + MAP;
4338 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [tmps]));
4339 Exit;
4340 end;
4342 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4343 g_Player_Init();
4345 // Ñîçäàåì áîòîâ:
4346 for i := nPl+1 to nPlayers do
4347 g_Player_Create(STD_PLAYER_MODEL, _RGB(0, 0, 0), 0, True);
4348 end;
4350 procedure g_Game_StartCustom(Map: String; GameMode: Byte;
4351 TimeLimit, GoalLimit: Word;
4352 MaxLives: Byte;
4353 Options: LongWord; nPlayers: Byte);
4354 var
4355 i, nPl: Integer;
4356 begin
4357 g_Game_Free();
4359 e_WriteLog('Starting custom game...', TMsgType.Notify);
4361 g_Game_ClearLoading();
4363 // Íàñòðîéêè èãðû:
4364 gGameSettings.GameType := GT_CUSTOM;
4365 gGameSettings.GameMode := GameMode;
4366 gSwitchGameMode := GameMode;
4367 gGameSettings.TimeLimit := TimeLimit;
4368 gGameSettings.GoalLimit := GoalLimit;
4369 gGameSettings.MaxLives := IfThen(GameMode = GM_CTF, 0, MaxLives);
4370 gGameSettings.Options := Options;
4372 gCoopTotalMonstersKilled := 0;
4373 gCoopTotalSecretsFound := 0;
4374 gCoopTotalMonsters := 0;
4375 gCoopTotalSecrets := 0;
4376 gAimLine := False;
4377 gShowMap := False;
4379 g_Game_ExecuteEvent('ongamestart');
4381 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
4382 g_Game_SetupScreenSize();
4384 // Ðåæèì íàáëþäàòåëÿ:
4385 if nPlayers = 0 then
4386 begin
4387 gPlayer1 := nil;
4388 gPlayer2 := nil;
4389 end;
4391 nPl := 0;
4392 if nPlayers >= 1 then
4393 begin
4394 // Ñîçäàíèå ïåðâîãî èãðîêà:
4395 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
4396 gPlayer1Settings.Color,
4397 gPlayer1Settings.Team, False));
4398 if gPlayer1 = nil then
4399 begin
4400 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]));
4401 Exit;
4402 end;
4404 gPlayer1.Name := gPlayer1Settings.Name;
4405 Inc(nPl);
4406 end;
4408 if nPlayers >= 2 then
4409 begin
4410 // Ñîçäàíèå âòîðîãî èãðîêà:
4411 gPlayer2 := g_Player_Get(g_Player_Create(gPlayer2Settings.Model,
4412 gPlayer2Settings.Color,
4413 gPlayer2Settings.Team, False));
4414 if gPlayer2 = nil then
4415 begin
4416 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [2]));
4417 Exit;
4418 end;
4420 gPlayer2.Name := gPlayer2Settings.Name;
4421 Inc(nPl);
4422 end;
4424 // Çàãðóçêà è çàïóñê êàðòû:
4425 if not g_Game_StartMap(Map, True) then
4426 begin
4427 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [Map]));
4428 Exit;
4429 end;
4431 // Íåò òî÷åê ïîÿâëåíèÿ:
4432 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1) +
4433 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2) +
4434 g_Map_GetPointCount(RESPAWNPOINT_DM) +
4435 g_Map_GetPointCount(RESPAWNPOINT_RED)+
4436 g_Map_GetPointCount(RESPAWNPOINT_BLUE)) < 1 then
4437 begin
4438 g_FatalError(_lc[I_GAME_ERROR_GET_SPAWN]);
4439 Exit;
4440 end;
4442 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4443 g_Player_Init();
4445 // Ñîçäàåì áîòîâ:
4446 for i := nPl+1 to nPlayers do
4447 g_Player_Create(STD_PLAYER_MODEL, _RGB(0, 0, 0), 0, True);
4448 end;
4450 procedure g_Game_StartServer(Map: String; GameMode: Byte;
4451 TimeLimit, GoalLimit: Word; MaxLives: Byte;
4452 Options: LongWord; nPlayers: Byte;
4453 IPAddr: LongWord; Port: Word);
4454 begin
4455 g_Game_Free();
4457 e_WriteLog('Starting net game (server)...', TMsgType.Notify);
4459 g_Game_ClearLoading();
4461 // Íàñòðîéêè èãðû:
4462 gGameSettings.GameType := GT_SERVER;
4463 gGameSettings.GameMode := GameMode;
4464 gSwitchGameMode := GameMode;
4465 gGameSettings.TimeLimit := TimeLimit;
4466 gGameSettings.GoalLimit := GoalLimit;
4467 gGameSettings.MaxLives := IfThen(GameMode = GM_CTF, 0, MaxLives);
4468 gGameSettings.Options := Options;
4470 gCoopTotalMonstersKilled := 0;
4471 gCoopTotalSecretsFound := 0;
4472 gCoopTotalMonsters := 0;
4473 gCoopTotalSecrets := 0;
4474 gAimLine := False;
4475 gShowMap := False;
4477 g_Game_ExecuteEvent('ongamestart');
4479 // Óñòàíîâêà ðàçìåðîâ îêíà èãðîêà
4480 g_Game_SetupScreenSize();
4482 // Ðåæèì íàáëþäàòåëÿ:
4483 if nPlayers = 0 then
4484 begin
4485 gPlayer1 := nil;
4486 gPlayer2 := nil;
4487 end;
4489 if nPlayers >= 1 then
4490 begin
4491 // Ñîçäàíèå ïåðâîãî èãðîêà:
4492 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
4493 gPlayer1Settings.Color,
4494 gPlayer1Settings.Team, False));
4495 if gPlayer1 = nil then
4496 begin
4497 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]));
4498 Exit;
4499 end;
4501 gPlayer1.Name := gPlayer1Settings.Name;
4502 end;
4504 if nPlayers >= 2 then
4505 begin
4506 // Ñîçäàíèå âòîðîãî èãðîêà:
4507 gPlayer2 := g_Player_Get(g_Player_Create(gPlayer2Settings.Model,
4508 gPlayer2Settings.Color,
4509 gPlayer2Settings.Team, False));
4510 if gPlayer2 = nil then
4511 begin
4512 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [2]));
4513 Exit;
4514 end;
4516 gPlayer2.Name := gPlayer2Settings.Name;
4517 end;
4519 g_Game_SetLoadingText(_lc[I_LOAD_HOST], 0, False);
4520 if NetForwardPorts then
4521 g_Game_SetLoadingText(_lc[I_LOAD_PORTS], 0, False);
4523 // Ñòàðòóåì ñåðâåð
4524 if not g_Net_Host(IPAddr, Port, NetMaxClients) then
4525 begin
4526 g_FatalError(_lc[I_NET_MSG] + _lc[I_NET_ERR_HOST]);
4527 Exit;
4528 end;
4530 g_Net_Slist_Set(NetSlistIP, NetSlistPort);
4532 // Çàãðóçêà è çàïóñê êàðòû:
4533 if not g_Game_StartMap(Map, True) then
4534 begin
4535 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [Map]));
4536 Exit;
4537 end;
4539 // Íåò òî÷åê ïîÿâëåíèÿ:
4540 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1) +
4541 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2) +
4542 g_Map_GetPointCount(RESPAWNPOINT_DM) +
4543 g_Map_GetPointCount(RESPAWNPOINT_RED)+
4544 g_Map_GetPointCount(RESPAWNPOINT_BLUE)) < 1 then
4545 begin
4546 g_FatalError(_lc[I_GAME_ERROR_GET_SPAWN]);
4547 Exit;
4548 end;
4550 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4551 g_Player_Init();
4553 NetState := NET_STATE_GAME;
4554 end;
4556 procedure g_Game_StartClient(Addr: String; Port: Word; PW: String);
4557 var
4558 Map: String;
4559 WadName: string;
4560 Ptr: Pointer;
4561 T: Cardinal;
4562 MID: Byte;
4563 State: Byte;
4564 OuterLoop: Boolean;
4565 newResPath: string;
4566 InMsg: TMsg;
4567 begin
4568 g_Game_Free();
4570 State := 0;
4571 e_WriteLog('Starting net game (client)...', TMsgType.Notify);
4572 e_WriteLog('NET: Trying to connect to ' + Addr + ':' + IntToStr(Port) + '...', TMsgType.Notify);
4574 g_Game_ClearLoading();
4576 // Íàñòðîéêè èãðû:
4577 gGameSettings.GameType := GT_CLIENT;
4579 gCoopTotalMonstersKilled := 0;
4580 gCoopTotalSecretsFound := 0;
4581 gCoopTotalMonsters := 0;
4582 gCoopTotalSecrets := 0;
4583 gAimLine := False;
4584 gShowMap := False;
4586 g_Game_ExecuteEvent('ongamestart');
4588 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
4589 g_Game_SetupScreenSize();
4591 NetState := NET_STATE_AUTH;
4593 g_Game_SetLoadingText(_lc[I_LOAD_CONNECT], 0, False);
4594 // Ñòàðòóåì êëèåíò
4595 if not g_Net_Connect(Addr, Port) then
4596 begin
4597 g_FatalError(_lc[I_NET_MSG] + _lc[I_NET_ERR_CONN]);
4598 NetState := NET_STATE_NONE;
4599 Exit;
4600 end;
4602 g_Game_SetLoadingText(_lc[I_LOAD_SEND_INFO], 0, False);
4603 MC_SEND_Info(PW);
4604 g_Game_SetLoadingText(_lc[I_LOAD_WAIT_INFO], 0, False);
4606 OuterLoop := True;
4607 while OuterLoop do
4608 begin
4609 while (enet_host_service(NetHost, @NetEvent, 0) > 0) do
4610 begin
4611 if (NetEvent.kind = ENET_EVENT_TYPE_RECEIVE) then
4612 begin
4613 Ptr := NetEvent.packet^.data;
4614 if not InMsg.Init(Ptr, NetEvent.packet^.dataLength, True) then
4615 continue;
4617 InMsg.ReadLongWord(); // skip size
4618 MID := InMsg.ReadByte();
4620 if (MID = NET_MSG_INFO) and (State = 0) then
4621 begin
4622 NetMyID := InMsg.ReadByte();
4623 NetPlrUID1 := InMsg.ReadWord();
4625 WadName := InMsg.ReadString();
4626 Map := InMsg.ReadString();
4628 gWADHash := InMsg.ReadMD5();
4630 gGameSettings.GameMode := InMsg.ReadByte();
4631 gSwitchGameMode := gGameSettings.GameMode;
4632 gGameSettings.GoalLimit := InMsg.ReadWord();
4633 gGameSettings.TimeLimit := InMsg.ReadWord();
4634 gGameSettings.MaxLives := InMsg.ReadByte();
4635 gGameSettings.Options := InMsg.ReadLongWord();
4636 T := InMsg.ReadLongWord();
4638 newResPath := g_Res_SearchSameWAD(MapsDir, WadName, gWADHash);
4639 if newResPath = '' then
4640 begin
4641 g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
4642 newResPath := g_Res_DownloadWAD(WadName);
4643 if newResPath = '' then
4644 begin
4645 g_FatalError(_lc[I_NET_ERR_HASH]);
4646 enet_packet_destroy(NetEvent.packet);
4647 NetState := NET_STATE_NONE;
4648 Exit;
4649 end;
4650 end;
4651 newResPath := ExtractRelativePath(MapsDir, newResPath);
4653 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
4654 gPlayer1Settings.Color,
4655 gPlayer1Settings.Team, False));
4657 if gPlayer1 = nil then
4658 begin
4659 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]));
4661 enet_packet_destroy(NetEvent.packet);
4662 NetState := NET_STATE_NONE;
4663 Exit;
4664 end;
4666 gPlayer1.Name := gPlayer1Settings.Name;
4667 gPlayer1.UID := NetPlrUID1;
4668 gPlayer1.Reset(True);
4670 if not g_Game_StartMap(newResPath + ':\' + Map, True) then
4671 begin
4672 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [WadName + ':\' + Map]));
4674 enet_packet_destroy(NetEvent.packet);
4675 NetState := NET_STATE_NONE;
4676 Exit;
4677 end;
4679 gTime := T;
4681 State := 1;
4682 OuterLoop := False;
4683 enet_packet_destroy(NetEvent.packet);
4684 break;
4685 end
4686 else
4687 enet_packet_destroy(NetEvent.packet);
4688 end
4689 else
4690 begin
4691 if (NetEvent.kind = ENET_EVENT_TYPE_DISCONNECT) then
4692 begin
4693 State := 0;
4694 if (NetEvent.data <= NET_DISC_MAX) then
4695 g_Console_Add(_lc[I_NET_MSG_ERROR] + _lc[I_NET_ERR_CONN] + ' ' +
4696 _lc[TStrings_Locale(Cardinal(I_NET_DISC_NONE) + NetEvent.data)], True);
4697 OuterLoop := False;
4698 Break;
4699 end;
4700 end;
4701 end;
4703 ProcessLoading(true);
4705 if e_KeyPressed(IK_SPACE) or e_KeyPressed(IK_ESCAPE) or e_KeyPressed(VK_ESCAPE) or
4706 e_KeyPressed(JOY0_JUMP) or e_KeyPressed(JOY1_JUMP) or e_KeyPressed(JOY2_JUMP) or e_KeyPressed(JOY3_JUMP) then
4707 begin
4708 State := 0;
4709 break;
4710 end;
4711 end;
4713 if State <> 1 then
4714 begin
4715 g_FatalError(_lc[I_NET_MSG] + _lc[I_NET_ERR_CONN]);
4716 NetState := NET_STATE_NONE;
4717 Exit;
4718 end;
4720 gLMSRespawn := LMS_RESPAWN_NONE;
4721 gLMSRespawnTime := 0;
4723 g_Player_Init();
4724 NetState := NET_STATE_GAME;
4725 MC_SEND_FullStateRequest;
4726 e_WriteLog('NET: Connection successful.', TMsgType.Notify);
4727 end;
4729 procedure g_Game_SaveOptions();
4730 begin
4731 g_Options_Write_Video(GameDir+'/'+CONFIG_FILENAME);
4732 end;
4734 procedure g_Game_ChangeMap(const MapPath: String);
4735 var
4736 Force: Boolean;
4737 begin
4738 g_Game_ClearLoading();
4740 Force := gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF];
4741 // Åñëè óðîâåíü çàâåðøèëñÿ ïî òðèããåðó Âûõîä, íå î÷èùàòü èíâåíòàðü
4742 if gExitByTrigger then
4743 begin
4744 Force := False;
4745 gExitByTrigger := False;
4746 end;
4747 if not g_Game_StartMap(MapPath, Force) then
4748 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [MapPath]));
4749 end;
4751 procedure g_Game_Restart();
4752 var
4753 Map: string;
4754 begin
4755 if g_Game_IsClient then
4756 Exit;
4757 map := g_ExtractFileName(gMapInfo.Map);
4759 MessageTime := 0;
4760 gGameOn := False;
4761 g_Game_ClearLoading();
4762 g_Game_StartMap(Map, True, gCurrentMapFileName);
4763 end;
4765 function g_Game_StartMap(Map: String; Force: Boolean = False; const oldMapPath: AnsiString=''): Boolean;
4766 var
4767 NewWAD, ResName: String;
4768 I: Integer;
4769 begin
4770 g_Map_Free((Map <> gCurrentMapFileName) and (oldMapPath <> gCurrentMapFileName));
4771 g_Player_RemoveAllCorpses();
4773 if (not g_Game_IsClient) and
4774 (gSwitchGameMode <> gGameSettings.GameMode) and
4775 (gGameSettings.GameMode <> GM_SINGLE) then
4776 begin
4777 if gSwitchGameMode = GM_CTF then
4778 gGameSettings.MaxLives := 0;
4779 gGameSettings.GameMode := gSwitchGameMode;
4780 Force := True;
4781 end else
4782 gSwitchGameMode := gGameSettings.GameMode;
4784 g_Player_ResetTeams();
4786 if isWadPath(Map) then
4787 begin
4788 NewWAD := g_ExtractWadName(Map);
4789 ResName := g_ExtractFileName(Map);
4790 if g_Game_IsServer then
4791 begin
4792 gWADHash := MD5File(MapsDir + NewWAD);
4793 g_Game_LoadWAD(NewWAD);
4794 end else
4795 // hash received in MC_RECV_GameEvent -> NET_EV_MAPSTART
4796 g_Game_ClientWAD(NewWAD, gWADHash);
4797 end else
4798 ResName := Map;
4800 Result := g_Map_Load(MapsDir + gGameSettings.WAD + ':\' + ResName);
4801 if Result then
4802 begin
4803 g_Player_ResetAll(Force or gLastMap, gGameSettings.GameType = GT_SINGLE);
4805 gState := STATE_NONE;
4806 g_ActiveWindow := nil;
4807 gGameOn := True;
4809 DisableCheats();
4810 ResetTimer();
4812 if gGameSettings.GameMode = GM_CTF then
4813 begin
4814 g_Map_ResetFlag(FLAG_RED);
4815 g_Map_ResetFlag(FLAG_BLUE);
4816 // CTF, à ôëàãîâ íåò:
4817 if not g_Map_HaveFlagPoints() then
4818 g_SimpleError(_lc[I_GAME_ERROR_CTF]);
4819 end;
4820 end
4821 else
4822 begin
4823 gState := STATE_MENU;
4824 gGameOn := False;
4825 end;
4827 gExit := 0;
4828 gPauseMain := false;
4829 gPauseHolmes := false;
4830 gTime := 0;
4831 NetTimeToUpdate := 1;
4832 NetTimeToReliable := 0;
4833 NetTimeToMaster := NetMasterRate;
4834 gLMSRespawn := LMS_RESPAWN_NONE;
4835 gLMSRespawnTime := 0;
4836 gMissionFailed := False;
4837 gNextMap := '';
4839 gCoopMonstersKilled := 0;
4840 gCoopSecretsFound := 0;
4842 gVoteInProgress := False;
4843 gVotePassed := False;
4844 gVoteCount := 0;
4845 gVoted := False;
4847 gStatsOff := False;
4849 if not gGameOn then Exit;
4851 g_Game_SpectateCenterView();
4853 if (gGameSettings.MaxLives > 0) and (gGameSettings.WarmupTime > 0) then
4854 begin
4855 gLMSRespawn := LMS_RESPAWN_WARMUP;
4856 gLMSRespawnTime := gTime + gGameSettings.WarmupTime*1000;
4857 gLMSSoftSpawn := True;
4858 if NetMode = NET_SERVER then
4859 MH_SEND_GameEvent(NET_EV_LMS_WARMUP, (gLMSRespawnTime - gTime) div 1000)
4860 else
4861 g_Console_Add(Format(_lc[I_MSG_WARMUP_START], [(gLMSRespawnTime - gTime) div 1000]), True);
4862 end;
4864 if NetMode = NET_SERVER then
4865 begin
4866 MH_SEND_GameEvent(NET_EV_MAPSTART, gGameSettings.GameMode, Map);
4868 // Ìàñòåðñåðâåð
4869 if NetUseMaster then
4870 begin
4871 if (NetMHost = nil) or (NetMPeer = nil) then
4872 if not g_Net_Slist_Connect then
4873 g_Console_Add(_lc[I_NET_MSG_ERROR] + _lc[I_NET_SLIST_ERROR]);
4875 g_Net_Slist_Update;
4876 end;
4878 if NetClients <> nil then
4879 for I := 0 to High(NetClients) do
4880 if NetClients[I].Used then
4881 begin
4882 NetClients[I].Voted := False;
4883 if NetClients[I].RequestedFullUpdate then
4884 begin
4885 MH_SEND_Everything((NetClients[I].State = NET_STATE_AUTH), I);
4886 NetClients[I].RequestedFullUpdate := False;
4887 end;
4888 end;
4890 g_Net_UnbanNonPermHosts();
4891 end;
4893 if gLastMap then
4894 begin
4895 gCoopTotalMonstersKilled := 0;
4896 gCoopTotalSecretsFound := 0;
4897 gCoopTotalMonsters := 0;
4898 gCoopTotalSecrets := 0;
4899 gLastMap := False;
4900 end;
4902 g_Game_ExecuteEvent('onmapstart');
4903 end;
4905 procedure SetFirstLevel();
4906 begin
4907 gNextMap := '';
4909 MapList := g_Map_GetMapsList(MapsDir + gGameSettings.WAD);
4910 if MapList = nil then
4911 Exit;
4913 SortSArray(MapList);
4914 gNextMap := MapList[Low(MapList)];
4916 MapList := nil;
4917 end;
4919 procedure g_Game_ExitLevel(const Map: AnsiString);
4920 begin
4921 gNextMap := Map;
4923 gCoopTotalMonstersKilled := gCoopTotalMonstersKilled + gCoopMonstersKilled;
4924 gCoopTotalSecretsFound := gCoopTotalSecretsFound + gCoopSecretsFound;
4925 gCoopTotalMonsters := gCoopTotalMonsters + gTotalMonsters;
4926 gCoopTotalSecrets := gCoopTotalSecrets + gSecretsCount;
4928 // Âûøëè â âûõîä â Îäèíî÷íîé èãðå:
4929 if gGameSettings.GameType = GT_SINGLE then
4930 gExit := EXIT_ENDLEVELSINGLE
4931 else // Âûøëè â âûõîä â Ñâîåé èãðå
4932 begin
4933 gExit := EXIT_ENDLEVELCUSTOM;
4934 if gGameSettings.GameMode = GM_COOP then
4935 g_Player_RememberAll;
4937 if not g_Map_Exist(MapsDir + gGameSettings.WAD + ':\' + gNextMap) then
4938 begin
4939 gLastMap := True;
4940 if gGameSettings.GameMode = GM_COOP then
4941 gStatsOff := True;
4943 gStatsPressed := True;
4944 gNextMap := 'MAP01';
4946 if not g_Map_Exist(MapsDir + gGameSettings.WAD + ':\' + gNextMap) then
4947 g_Game_NextLevel;
4949 if g_Game_IsNet then
4950 begin
4951 MH_SEND_GameStats();
4952 MH_SEND_CoopStats();
4953 end;
4954 end;
4955 end;
4956 end;
4958 procedure g_Game_RestartLevel();
4959 var
4960 Map: string;
4961 begin
4962 if gGameSettings.GameMode = GM_SINGLE then
4963 begin
4964 g_Game_Restart();
4965 Exit;
4966 end;
4967 gExit := EXIT_ENDLEVELCUSTOM;
4968 Map := g_ExtractFileName(gMapInfo.Map);
4969 gNextMap := Map;
4970 end;
4972 procedure g_Game_ClientWAD(NewWAD: String; WHash: TMD5Digest);
4973 var
4974 gWAD: String;
4975 begin
4976 if LowerCase(NewWAD) = LowerCase(gGameSettings.WAD) then
4977 Exit;
4978 if not g_Game_IsClient then
4979 Exit;
4980 gWAD := g_Res_SearchSameWAD(MapsDir, ExtractFileName(NewWAD), WHash);
4981 if gWAD = '' then
4982 begin
4983 g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
4984 gWAD := g_Res_DownloadWAD(ExtractFileName(NewWAD));
4985 if gWAD = '' then
4986 begin
4987 g_Game_Free();
4988 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_WAD], [ExtractFileName(NewWAD)]));
4989 Exit;
4990 end;
4991 end;
4992 NewWAD := ExtractRelativePath(MapsDir, gWAD);
4993 g_Game_LoadWAD(NewWAD);
4994 end;
4996 procedure g_Game_RestartRound(NoMapRestart: Boolean = False);
4997 var
4998 i, n, nb, nr: Integer;
5000 function monRespawn (mon: TMonster): Boolean;
5001 begin
5002 result := false; // don't stop
5003 if not mon.FNoRespawn then mon.Respawn();
5004 end;
5006 begin
5007 if not g_Game_IsServer then Exit;
5008 if gLMSRespawn = LMS_RESPAWN_NONE then Exit;
5009 gLMSRespawn := LMS_RESPAWN_NONE;
5010 gLMSRespawnTime := 0;
5011 MessageTime := 0;
5013 if (gGameSettings.GameMode = GM_COOP) and not NoMapRestart then
5014 begin
5015 gMissionFailed := True;
5016 g_Game_RestartLevel;
5017 Exit;
5018 end;
5020 n := 0; nb := 0; nr := 0;
5021 for i := Low(gPlayers) to High(gPlayers) do
5022 if (gPlayers[i] <> nil) and
5023 ((not gPlayers[i].FSpectator) or gPlayers[i].FWantsInGame or
5024 (gPlayers[i] is TBot)) then
5025 begin
5026 Inc(n);
5027 if gPlayers[i].Team = TEAM_RED then Inc(nr)
5028 else if gPlayers[i].Team = TEAM_BLUE then Inc(nb)
5029 end;
5031 if (n < 2) or ((gGameSettings.GameMode = GM_TDM) and ((nr = 0) or (nb = 0))) then
5032 begin
5033 // wait a second until the fuckers finally decide to join
5034 gLMSRespawn := LMS_RESPAWN_WARMUP;
5035 gLMSRespawnTime := gTime + 1000;
5036 gLMSSoftSpawn := NoMapRestart;
5037 Exit;
5038 end;
5040 g_Player_RemoveAllCorpses;
5041 g_Game_Message(_lc[I_MESSAGE_LMS_START], 144);
5042 if g_Game_IsNet then
5043 MH_SEND_GameEvent(NET_EV_LMS_START);
5045 for i := Low(gPlayers) to High(gPlayers) do
5046 begin
5047 if gPlayers[i] = nil then continue;
5048 if gPlayers[i] is TBot then gPlayers[i].FWantsInGame := True;
5049 // don't touch normal spectators
5050 if gPlayers[i].FSpectator and not gPlayers[i].FWantsInGame then
5051 begin
5052 gPlayers[i].FNoRespawn := True;
5053 gPlayers[i].Lives := 0;
5054 if g_Game_IsNet then
5055 MH_SEND_PlayerStats(gPlayers[I].UID);
5056 continue;
5057 end;
5058 gPlayers[i].FNoRespawn := False;
5059 gPlayers[i].Lives := gGameSettings.MaxLives;
5060 gPlayers[i].Respawn(False, True);
5061 if gGameSettings.GameMode = GM_COOP then
5062 begin
5063 gPlayers[i].Frags := 0;
5064 gPlayers[i].RecallState;
5065 end;
5066 if (gPlayer1 = nil) and (gLMSPID1 > 0) then
5067 gPlayer1 := g_Player_Get(gLMSPID1);
5068 if (gPlayer2 = nil) and (gLMSPID2 > 0) then
5069 gPlayer2 := g_Player_Get(gLMSPID2);
5070 end;
5072 g_Items_RestartRound();
5075 g_Mons_ForEach(monRespawn);
5077 gLMSSoftSpawn := False;
5078 end;
5080 function g_Game_GetFirstMap(WAD: String): String;
5081 begin
5082 Result := '';
5084 MapList := g_Map_GetMapsList(WAD);
5085 if MapList = nil then
5086 Exit;
5088 SortSArray(MapList);
5089 Result := MapList[Low(MapList)];
5091 if not g_Map_Exist(WAD + ':\' + Result) then
5092 Result := '';
5094 MapList := nil;
5095 end;
5097 function g_Game_GetNextMap(): String;
5098 var
5099 I: Integer;
5100 Map: string;
5101 begin
5102 Result := '';
5104 MapList := g_Map_GetMapsList(MapsDir + gGameSettings.WAD);
5105 if MapList = nil then
5106 Exit;
5108 Map := g_ExtractFileName(gMapInfo.Map);
5110 SortSArray(MapList);
5111 MapIndex := -255;
5112 for I := Low(MapList) to High(MapList) do
5113 if Map = MapList[I] then
5114 begin
5115 MapIndex := I;
5116 Break;
5117 end;
5119 if MapIndex <> -255 then
5120 begin
5121 if MapIndex = High(MapList) then
5122 Result := MapList[Low(MapList)]
5123 else
5124 Result := MapList[MapIndex + 1];
5126 if not g_Map_Exist(MapsDir + gGameSettings.WAD + ':\' + Result) then Result := Map;
5127 end;
5129 MapList := nil;
5130 end;
5132 procedure g_Game_NextLevel();
5133 begin
5134 if gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF, GM_COOP] then
5135 gExit := EXIT_ENDLEVELCUSTOM
5136 else
5137 begin
5138 gExit := EXIT_ENDLEVELSINGLE;
5139 Exit;
5140 end;
5142 if gNextMap <> '' then Exit;
5143 gNextMap := g_Game_GetNextMap();
5144 end;
5146 function g_Game_IsTestMap(): Boolean;
5147 begin
5148 result := StrEquCI1251(TEST_MAP_NAME, g_ExtractFileName(gMapInfo.Map));
5149 end;
5151 procedure g_Game_DeleteTestMap();
5152 var
5153 a: Integer;
5154 //MapName: AnsiString;
5155 WadName: string;
5157 WAD: TWADFile;
5158 MapList: SSArray;
5159 time: Integer;
5161 begin
5162 a := Pos('.wad:\', toLowerCase1251(gMapToDelete));
5163 if (a = 0) then a := Pos('.wad:/', toLowerCase1251(gMapToDelete));
5164 if (a = 0) then exit;
5166 // Âûäåëÿåì èìÿ wad-ôàéëà è èìÿ êàðòû
5167 WadName := Copy(gMapToDelete, 1, a+3);
5168 Delete(gMapToDelete, 1, a+5);
5169 gMapToDelete := UpperCase(gMapToDelete);
5170 //MapName := '';
5171 //CopyMemory(@MapName[0], @gMapToDelete[1], Min(16, Length(gMapToDelete)));
5174 // Èìÿ êàðòû íå ñòàíäàðòíîå òåñòîâîå:
5175 if MapName <> TEST_MAP_NAME then
5176 Exit;
5178 if not gTempDelete then
5179 begin
5180 time := g_GetFileTime(WadName);
5181 WAD := TWADFile.Create();
5183 // ×èòàåì Wad-ôàéë:
5184 if not WAD.ReadFile(WadName) then
5185 begin // Íåò òàêîãî WAD-ôàéëà
5186 WAD.Free();
5187 Exit;
5188 end;
5190 // Ñîñòàâëÿåì ñïèñîê êàðò è èùåì íóæíóþ:
5191 WAD.CreateImage();
5192 MapList := WAD.GetResourcesList('');
5194 if MapList <> nil then
5195 for a := 0 to High(MapList) do
5196 if MapList[a] = MapName then
5197 begin
5198 // Óäàëÿåì è ñîõðàíÿåì:
5199 WAD.RemoveResource('', MapName);
5200 WAD.SaveTo(WadName);
5201 Break;
5202 end;
5204 WAD.Free();
5205 g_SetFileTime(WadName, time);
5206 end else
5208 if gTempDelete then DeleteFile(WadName);
5209 end;
5211 procedure GameCVars(P: SSArray);
5212 var
5213 a, b: Integer;
5214 stat: TPlayerStatArray;
5215 cmd, s: string;
5216 config: TConfig;
5217 begin
5218 stat := nil;
5219 cmd := LowerCase(P[0]);
5220 if (cmd = 'g_friendlyfire') and not g_Game_IsClient then
5221 begin
5222 with gGameSettings do
5223 begin
5224 if (Length(P) > 1) and
5225 ((P[1] = '1') or (P[1] = '0')) then
5226 begin
5227 if (P[1][1] = '1') then
5228 Options := Options or GAME_OPTION_TEAMDAMAGE
5229 else
5230 Options := Options and (not GAME_OPTION_TEAMDAMAGE);
5231 end;
5233 if (LongBool(Options and GAME_OPTION_TEAMDAMAGE)) then
5234 g_Console_Add(_lc[I_MSG_FRIENDLY_FIRE_ON])
5235 else
5236 g_Console_Add(_lc[I_MSG_FRIENDLY_FIRE_OFF]);
5238 if g_Game_IsNet then MH_SEND_GameSettings;
5239 end;
5240 end
5241 else if (cmd = 'g_weaponstay') and not g_Game_IsClient then
5242 begin
5243 with gGameSettings do
5244 begin
5245 if (Length(P) > 1) and
5246 ((P[1] = '1') or (P[1] = '0')) then
5247 begin
5248 if (P[1][1] = '1') then
5249 Options := Options or GAME_OPTION_WEAPONSTAY
5250 else
5251 Options := Options and (not GAME_OPTION_WEAPONSTAY);
5252 end;
5254 if (LongBool(Options and GAME_OPTION_WEAPONSTAY)) then
5255 g_Console_Add(_lc[I_MSG_WEAPONSTAY_ON])
5256 else
5257 g_Console_Add(_lc[I_MSG_WEAPONSTAY_OFF]);
5259 if g_Game_IsNet then MH_SEND_GameSettings;
5260 end;
5261 end
5262 else if cmd = 'g_gamemode' then
5263 begin
5264 a := g_Game_TextToMode(P[1]);
5265 if a = GM_SINGLE then a := GM_COOP;
5266 if (Length(P) > 1) and (a <> GM_NONE) and (not g_Game_IsClient) then
5267 begin
5268 gSwitchGameMode := a;
5269 if (gGameOn and (gGameSettings.GameMode = GM_SINGLE)) or
5270 (gState = STATE_INTERSINGLE) then
5271 gSwitchGameMode := GM_SINGLE;
5272 if not gGameOn then
5273 gGameSettings.GameMode := gSwitchGameMode;
5274 end;
5275 if gSwitchGameMode = gGameSettings.GameMode then
5276 g_Console_Add(Format(_lc[I_MSG_GAMEMODE_CURRENT],
5277 [g_Game_ModeToText(gGameSettings.GameMode)]))
5278 else
5279 g_Console_Add(Format(_lc[I_MSG_GAMEMODE_CHANGE],
5280 [g_Game_ModeToText(gGameSettings.GameMode),
5281 g_Game_ModeToText(gSwitchGameMode)]));
5282 end
5283 else if (cmd = 'g_allow_exit') and not g_Game_IsClient then
5284 begin
5285 with gGameSettings do
5286 begin
5287 if (Length(P) > 1) and
5288 ((P[1] = '1') or (P[1] = '0')) then
5289 begin
5290 if (P[1][1] = '1') then
5291 Options := Options or GAME_OPTION_ALLOWEXIT
5292 else
5293 Options := Options and (not GAME_OPTION_ALLOWEXIT);
5294 end;
5296 if (LongBool(Options and GAME_OPTION_ALLOWEXIT)) then
5297 g_Console_Add(_lc[I_MSG_ALLOWEXIT_ON])
5298 else
5299 g_Console_Add(_lc[I_MSG_ALLOWEXIT_OFF]);
5300 g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
5302 if g_Game_IsNet then MH_SEND_GameSettings;
5303 end;
5304 end
5305 else if (cmd = 'g_allow_monsters') and not g_Game_IsClient then
5306 begin
5307 with gGameSettings do
5308 begin
5309 if (Length(P) > 1) and
5310 ((P[1] = '1') or (P[1] = '0')) then
5311 begin
5312 if (P[1][1] = '1') then
5313 Options := Options or GAME_OPTION_MONSTERS
5314 else
5315 Options := Options and (not GAME_OPTION_MONSTERS);
5316 end;
5318 if (LongBool(Options and GAME_OPTION_MONSTERS)) then
5319 g_Console_Add(_lc[I_MSG_ALLOWMON_ON])
5320 else
5321 g_Console_Add(_lc[I_MSG_ALLOWMON_OFF]);
5322 g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
5324 if g_Game_IsNet then MH_SEND_GameSettings;
5325 end;
5326 end
5327 else if (cmd = 'g_bot_vsplayers') and not g_Game_IsClient then
5328 begin
5329 with gGameSettings do
5330 begin
5331 if (Length(P) > 1) and
5332 ((P[1] = '1') or (P[1] = '0')) then
5333 begin
5334 if (P[1][1] = '1') then
5335 Options := Options or GAME_OPTION_BOTVSPLAYER
5336 else
5337 Options := Options and (not GAME_OPTION_BOTVSPLAYER);
5338 end;
5340 if (LongBool(Options and GAME_OPTION_BOTVSPLAYER)) then
5341 g_Console_Add(_lc[I_MSG_BOTSVSPLAYERS_ON])
5342 else
5343 g_Console_Add(_lc[I_MSG_BOTSVSPLAYERS_OFF]);
5345 if g_Game_IsNet then MH_SEND_GameSettings;
5346 end;
5347 end
5348 else if (cmd = 'g_bot_vsmonsters') and not g_Game_IsClient then
5349 begin
5350 with gGameSettings do
5351 begin
5352 if (Length(P) > 1) and
5353 ((P[1] = '1') or (P[1] = '0')) then
5354 begin
5355 if (P[1][1] = '1') then
5356 Options := Options or GAME_OPTION_BOTVSMONSTER
5357 else
5358 Options := Options and (not GAME_OPTION_BOTVSMONSTER);
5359 end;
5361 if (LongBool(Options and GAME_OPTION_BOTVSMONSTER)) then
5362 g_Console_Add(_lc[I_MSG_BOTSVSMONSTERS_ON])
5363 else
5364 g_Console_Add(_lc[I_MSG_BOTSVSMONSTERS_OFF]);
5366 if g_Game_IsNet then MH_SEND_GameSettings;
5367 end;
5368 end
5369 else if (cmd = 'g_warmuptime') and not g_Game_IsClient then
5370 begin
5371 if Length(P) > 1 then
5372 begin
5373 if StrToIntDef(P[1], gGameSettings.WarmupTime) = 0 then
5374 gGameSettings.WarmupTime := 30
5375 else
5376 gGameSettings.WarmupTime := StrToIntDef(P[1], gGameSettings.WarmupTime);
5377 end;
5379 g_Console_Add(Format(_lc[I_MSG_WARMUP],
5380 [gGameSettings.WarmupTime]));
5381 g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
5382 end
5383 else if cmd = 'net_interp' then
5384 begin
5385 if (Length(P) > 1) then
5386 NetInterpLevel := StrToIntDef(P[1], NetInterpLevel);
5388 g_Console_Add('net_interp = ' + IntToStr(NetInterpLevel));
5389 config := TConfig.CreateFile(GameDir+'/'+CONFIG_FILENAME);
5390 config.WriteInt('Client', 'InterpolationSteps', NetInterpLevel);
5391 config.SaveFile(GameDir+'/'+CONFIG_FILENAME);
5392 config.Free();
5393 end
5394 else if cmd = 'net_forceplayerupdate' then
5395 begin
5396 if (Length(P) > 1) and
5397 ((P[1] = '1') or (P[1] = '0')) then
5398 NetForcePlayerUpdate := (P[1][1] = '1');
5400 if NetForcePlayerUpdate then
5401 g_Console_Add('net_forceplayerupdate = 1')
5402 else
5403 g_Console_Add('net_forceplayerupdate = 0');
5404 config := TConfig.CreateFile(GameDir+'/'+CONFIG_FILENAME);
5405 config.WriteBool('Client', 'ForcePlayerUpdate', NetForcePlayerUpdate);
5406 config.SaveFile(GameDir+'/'+CONFIG_FILENAME);
5407 config.Free();
5408 end
5409 else if cmd = 'net_predictself' then
5410 begin
5411 if (Length(P) > 1) and
5412 ((P[1] = '1') or (P[1] = '0')) then
5413 NetPredictSelf := (P[1][1] = '1');
5415 if NetPredictSelf then
5416 g_Console_Add('net_predictself = 1')
5417 else
5418 g_Console_Add('net_predictself = 0');
5419 config := TConfig.CreateFile(GameDir+'/'+CONFIG_FILENAME);
5420 config.WriteBool('Client', 'PredictSelf', NetPredictSelf);
5421 config.SaveFile(GameDir+'/'+CONFIG_FILENAME);
5422 config.Free();
5423 end
5424 else if cmd = 'sv_name' then
5425 begin
5426 if (Length(P) > 1) and (Length(P[1]) > 0) then
5427 begin
5428 NetServerName := P[1];
5429 if Length(NetServerName) > 64 then
5430 SetLength(NetServerName, 64);
5431 if g_Game_IsServer and g_Game_IsNet and NetUseMaster then
5432 g_Net_Slist_Update;
5433 end;
5435 g_Console_Add(cmd + ' = "' + NetServerName + '"');
5436 end
5437 else if cmd = 'sv_passwd' then
5438 begin
5439 if (Length(P) > 1) and (Length(P[1]) > 0) then
5440 begin
5441 NetPassword := P[1];
5442 if Length(NetPassword) > 24 then
5443 SetLength(NetPassword, 24);
5444 if g_Game_IsServer and g_Game_IsNet and NetUseMaster then
5445 g_Net_Slist_Update;
5446 end;
5448 g_Console_Add(cmd + ' = "' + AnsiLowerCase(NetPassword) + '"');
5449 end
5450 else if cmd = 'sv_maxplrs' then
5451 begin
5452 if (Length(P) > 1) then
5453 begin
5454 NetMaxClients := Min(Max(StrToIntDef(P[1], NetMaxClients), 1), NET_MAXCLIENTS);
5455 if g_Game_IsServer and g_Game_IsNet then
5456 begin
5457 b := 0;
5458 for a := 0 to High(NetClients) do
5459 if NetClients[a].Used then
5460 begin
5461 Inc(b);
5462 if b > NetMaxClients then
5463 begin
5464 s := g_Player_Get(NetClients[a].Player).Name;
5465 enet_peer_disconnect(NetClients[a].Peer, NET_DISC_FULL);
5466 g_Console_Add(Format(_lc[I_PLAYER_KICK], [s]));
5467 MH_SEND_GameEvent(NET_EV_PLAYER_KICK, 0, s);
5468 end;
5469 end;
5470 if NetUseMaster then
5471 g_Net_Slist_Update;
5472 end;
5473 end;
5475 g_Console_Add(cmd + ' = ' + IntToStr(NetMaxClients));
5476 end
5477 else if cmd = 'sv_public' then
5478 begin
5479 if (Length(P) > 1) then
5480 begin
5481 NetUseMaster := StrToIntDef(P[1], Byte(NetUseMaster)) > 0;
5482 if g_Game_IsServer and g_Game_IsNet then
5483 if NetUseMaster then
5484 begin
5485 if NetMPeer = nil then
5486 if not g_Net_Slist_Connect() then
5487 g_Console_Add(_lc[I_NET_MSG_ERROR] + _lc[I_NET_SLIST_ERROR]);
5488 g_Net_Slist_Update();
5489 end
5490 else
5491 if NetMPeer <> nil then
5492 g_Net_Slist_Disconnect();
5493 end;
5495 g_Console_Add(cmd + ' = ' + IntToStr(Byte(NetUseMaster)));
5496 end
5497 else if cmd = 'sv_intertime' then
5498 begin
5499 if (Length(P) > 1) then
5500 gDefInterTime := Min(Max(StrToIntDef(P[1], gDefInterTime), -1), 120);
5502 g_Console_Add(cmd + ' = ' + IntToStr(gDefInterTime));
5503 end
5504 else if cmd = 'p1_name' then
5505 begin
5506 if (Length(P) > 1) and gGameOn then
5507 begin
5508 if g_Game_IsClient then
5509 begin
5510 gPlayer1Settings.Name := b_Text_Unformat(P[1]);
5511 MC_SEND_PlayerSettings;
5512 end
5513 else
5514 if gPlayer1 <> nil then
5515 begin
5516 gPlayer1.Name := b_Text_Unformat(P[1]);
5517 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer1.UID);
5518 end
5519 else
5520 gPlayer1Settings.Name := b_Text_Unformat(P[1]);
5521 end;
5522 end
5523 else if cmd = 'p2_name' then
5524 begin
5525 if (Length(P) > 1) and gGameOn then
5526 begin
5527 if g_Game_IsClient then
5528 begin
5529 gPlayer2Settings.Name := b_Text_Unformat(P[1]);
5530 MC_SEND_PlayerSettings;
5531 end
5532 else
5533 if gPlayer2 <> nil then
5534 begin
5535 gPlayer2.Name := b_Text_Unformat(P[1]);
5536 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer2.UID);
5537 end
5538 else
5539 gPlayer2Settings.Name := b_Text_Unformat(P[1]);
5540 end;
5541 end
5542 else if cmd = 'p1_color' then
5543 begin
5544 if Length(P) > 3 then
5545 if g_Game_IsClient then
5546 begin
5547 gPlayer1Settings.Color := _RGB(EnsureRange(StrToIntDef(P[1], 0), 0, 255),
5548 EnsureRange(StrToIntDef(P[2], 0), 0, 255),
5549 EnsureRange(StrToIntDef(P[3], 0), 0, 255));
5550 MC_SEND_PlayerSettings;
5551 end
5552 else
5553 if gPlayer1 <> nil then
5554 begin
5555 gPlayer1.Model.SetColor(EnsureRange(StrToIntDef(P[1], 0), 0, 255),
5556 EnsureRange(StrToIntDef(P[2], 0), 0, 255),
5557 EnsureRange(StrToIntDef(P[3], 0), 0, 255));
5558 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer1.UID);
5559 end
5560 else
5561 gPlayer1Settings.Color := _RGB(EnsureRange(StrToIntDef(P[1], 0), 0, 255),
5562 EnsureRange(StrToIntDef(P[2], 0), 0, 255),
5563 EnsureRange(StrToIntDef(P[3], 0), 0, 255));
5564 end
5565 else if (cmd = 'p2_color') and not g_Game_IsNet then
5566 begin
5567 if Length(P) > 3 then
5568 if g_Game_IsClient then
5569 begin
5570 gPlayer2Settings.Color := _RGB(EnsureRange(StrToIntDef(P[1], 0), 0, 255),
5571 EnsureRange(StrToIntDef(P[2], 0), 0, 255),
5572 EnsureRange(StrToIntDef(P[3], 0), 0, 255));
5573 MC_SEND_PlayerSettings;
5574 end
5575 else
5576 if gPlayer2 <> nil then
5577 begin
5578 gPlayer2.Model.SetColor(EnsureRange(StrToIntDef(P[1], 0), 0, 255),
5579 EnsureRange(StrToIntDef(P[2], 0), 0, 255),
5580 EnsureRange(StrToIntDef(P[3], 0), 0, 255));
5581 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer2.UID);
5582 end
5583 else
5584 gPlayer2Settings.Color := _RGB(EnsureRange(StrToIntDef(P[1], 0), 0, 255),
5585 EnsureRange(StrToIntDef(P[2], 0), 0, 255),
5586 EnsureRange(StrToIntDef(P[3], 0), 0, 255));
5587 end
5588 else if gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT] then
5589 begin
5590 if cmd = 'r_showscore' then
5591 begin
5592 if (Length(P) > 1) and
5593 ((P[1] = '1') or (P[1] = '0')) then
5594 gShowGoals := (P[1][1] = '1');
5596 if gShowGoals then
5597 g_Console_Add(_lc[I_MSG_SCORE_ON])
5598 else
5599 g_Console_Add(_lc[I_MSG_SCORE_OFF]);
5600 end
5601 else if cmd = 'r_showstat' then
5602 begin
5603 if (Length(P) > 1) and
5604 ((P[1] = '1') or (P[1] = '0')) then
5605 gShowStat := (P[1][1] = '1');
5607 if gShowStat then
5608 g_Console_Add(_lc[I_MSG_STATS_ON])
5609 else
5610 g_Console_Add(_lc[I_MSG_STATS_OFF]);
5611 end
5612 else if cmd = 'r_showkillmsg' then
5613 begin
5614 if (Length(P) > 1) and
5615 ((P[1] = '1') or (P[1] = '0')) then
5616 gShowKillMsg := (P[1][1] = '1');
5618 if gShowKillMsg then
5619 g_Console_Add(_lc[I_MSG_KILL_MSGS_ON])
5620 else
5621 g_Console_Add(_lc[I_MSG_KILL_MSGS_OFF]);
5622 end
5623 else if cmd = 'r_showlives' then
5624 begin
5625 if (Length(P) > 1) and
5626 ((P[1] = '1') or (P[1] = '0')) then
5627 gShowLives := (P[1][1] = '1');
5629 if gShowLives then
5630 g_Console_Add(_lc[I_MSG_LIVES_ON])
5631 else
5632 g_Console_Add(_lc[I_MSG_LIVES_OFF]);
5633 end
5634 else if cmd = 'r_showspect' then
5635 begin
5636 if (Length(P) > 1) and
5637 ((P[1] = '1') or (P[1] = '0')) then
5638 gSpectHUD := (P[1][1] = '1');
5640 if gSpectHUD then
5641 g_Console_Add(_lc[I_MSG_SPECT_HUD_ON])
5642 else
5643 g_Console_Add(_lc[I_MSG_SPECT_HUD_OFF]);
5644 end
5645 else if cmd = 'r_showping' then
5646 begin
5647 if (Length(P) > 1) and
5648 ((P[1] = '1') or (P[1] = '0')) then
5649 gShowPing := (P[1][1] = '1');
5651 if gShowPing then
5652 g_Console_Add(_lc[I_MSG_PING_ON])
5653 else
5654 g_Console_Add(_lc[I_MSG_PING_OFF]);
5655 end
5656 else if (cmd = 'g_scorelimit') and not g_Game_IsClient then
5657 begin
5658 if Length(P) > 1 then
5659 begin
5660 if StrToIntDef(P[1], gGameSettings.GoalLimit) = 0 then
5661 gGameSettings.GoalLimit := 0
5662 else
5663 begin
5664 b := 0;
5666 if gGameSettings.GameMode = GM_DM then
5667 begin // DM
5668 stat := g_Player_GetStats();
5669 if stat <> nil then
5670 for a := 0 to High(stat) do
5671 if stat[a].Frags > b then
5672 b := stat[a].Frags;
5673 end
5674 else // TDM/CTF
5675 b := Max(gTeamStat[TEAM_RED].Goals, gTeamStat[TEAM_BLUE].Goals);
5677 gGameSettings.GoalLimit := Max(StrToIntDef(P[1], gGameSettings.GoalLimit), b);
5678 end;
5680 if g_Game_IsNet then MH_SEND_GameSettings;
5681 end;
5683 g_Console_Add(Format(_lc[I_MSG_SCORE_LIMIT], [gGameSettings.GoalLimit]));
5684 end
5685 else if (cmd = 'g_timelimit') and not g_Game_IsClient then
5686 begin
5687 if (Length(P) > 1) and (StrToIntDef(P[1], -1) >= 0) then
5688 gGameSettings.TimeLimit := StrToIntDef(P[1], -1);
5690 g_Console_Add(Format(_lc[I_MSG_TIME_LIMIT],
5691 [gGameSettings.TimeLimit div 3600,
5692 (gGameSettings.TimeLimit div 60) mod 60,
5693 gGameSettings.TimeLimit mod 60]));
5694 if g_Game_IsNet then MH_SEND_GameSettings;
5695 end
5696 else if (cmd = 'g_maxlives') and not g_Game_IsClient then
5697 begin
5698 if Length(P) > 1 then
5699 begin
5700 if StrToIntDef(P[1], gGameSettings.MaxLives) = 0 then
5701 gGameSettings.MaxLives := 0
5702 else
5703 begin
5704 b := 0;
5705 stat := g_Player_GetStats();
5706 if stat <> nil then
5707 for a := 0 to High(stat) do
5708 if stat[a].Lives > b then
5709 b := stat[a].Lives;
5710 gGameSettings.MaxLives :=
5711 Max(StrToIntDef(P[1], gGameSettings.MaxLives), b);
5712 end;
5713 end;
5715 g_Console_Add(Format(_lc[I_MSG_LIVES],
5716 [gGameSettings.MaxLives]));
5717 if g_Game_IsNet then MH_SEND_GameSettings;
5718 end;
5719 end;
5720 end;
5722 procedure PrintHeapStats();
5723 var
5724 hs: TFPCHeapStatus;
5725 begin
5726 hs := GetFPCHeapStatus();
5727 e_LogWriteLn ('v===== heap status =====v');
5728 e_LogWriteFln('max heap size = %d k', [hs.MaxHeapSize div 1024]);
5729 e_LogWriteFln('max heap used = %d k', [hs.MaxHeapUsed div 1024]);
5730 e_LogWriteFln('cur heap size = %d k', [hs.CurrHeapSize div 1024]);
5731 e_LogWriteFln('cur heap used = %d k', [hs.CurrHeapUsed div 1024]);
5732 e_LogWriteFln('cur heap free = %d k', [hs.CurrHeapFree div 1024]);
5733 e_LogWriteLn ('^=======================^');
5734 end;
5736 procedure DebugCommands(P: SSArray);
5737 var
5738 a, b: Integer;
5739 cmd: string;
5740 //pt: TDFPoint;
5741 mon: TMonster;
5742 begin
5743 // Êîìàíäû îòëàäî÷íîãî ðåæèìà:
5744 if {gDebugMode}conIsCheatsEnabled then
5745 begin
5746 cmd := LowerCase(P[0]);
5747 if cmd = 'd_window' then
5748 begin
5749 g_Console_Add(Format('gWinPosX = %d, gWinPosY %d', [gWinPosX, gWinPosY]));
5750 g_Console_Add(Format('gWinRealPosX = %d, gWinRealPosY %d', [gWinRealPosX, gWinRealPosY]));
5751 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth, gScreenHeight]));
5752 g_Console_Add(Format('gWinSizeX = %d, gWinSizeY = %d', [gWinSizeX, gWinSizeY]));
5753 g_Console_Add(Format('Frame X = %d, Y = %d, Caption Y = %d', [gWinFrameX, gWinFrameY, gWinCaption]));
5754 end
5755 else if cmd = 'd_sounds' then
5756 begin
5757 if (Length(P) > 1) and
5758 ((P[1] = '1') or (P[1] = '0')) then
5759 g_Debug_Sounds := (P[1][1] = '1');
5761 g_Console_Add(Format('d_sounds is %d', [Byte(g_Debug_Sounds)]));
5762 end
5763 else if cmd = 'd_frames' then
5764 begin
5765 if (Length(P) > 1) and
5766 ((P[1] = '1') or (P[1] = '0')) then
5767 g_Debug_Frames := (P[1][1] = '1');
5769 g_Console_Add(Format('d_frames is %d', [Byte(g_Debug_Frames)]));
5770 end
5771 else if cmd = 'd_winmsg' then
5772 begin
5773 if (Length(P) > 1) and
5774 ((P[1] = '1') or (P[1] = '0')) then
5775 g_Debug_WinMsgs := (P[1][1] = '1');
5777 g_Console_Add(Format('d_winmsg is %d', [Byte(g_Debug_WinMsgs)]));
5778 end
5779 else if (cmd = 'd_monoff') and not g_Game_IsNet then
5780 begin
5781 if (Length(P) > 1) and
5782 ((P[1] = '1') or (P[1] = '0')) then
5783 g_Debug_MonsterOff := (P[1][1] = '1');
5785 g_Console_Add(Format('d_monoff is %d', [Byte(g_debug_MonsterOff)]));
5786 end
5787 else if (cmd = 'd_botoff') and not g_Game_IsNet then
5788 begin
5789 if Length(P) > 1 then
5790 case P[1][1] of
5791 '0': g_debug_BotAIOff := 0;
5792 '1': g_debug_BotAIOff := 1;
5793 '2': g_debug_BotAIOff := 2;
5794 '3': g_debug_BotAIOff := 3;
5795 end;
5797 g_Console_Add(Format('d_botoff is %d', [g_debug_BotAIOff]));
5798 end
5799 else if cmd = 'd_monster' then
5800 begin
5801 if gGameOn and (gPlayer1 <> nil) and (gPlayer1.alive) and (not g_Game_IsNet) then
5802 if Length(P) < 2 then
5803 begin
5804 g_Console_Add(cmd + ' [ID | Name] [behaviour]');
5805 g_Console_Add('ID | Name');
5806 for b := MONSTER_DEMON to MONSTER_MAN do
5807 g_Console_Add(Format('%2d | %s', [b, g_Mons_NameByTypeId(b)]));
5808 conwriteln('behav. num'#10'normal 0'#10'killer 1'#10'maniac 2'#10'insane 3'#10'cannibal 4'#10'good 5');
5809 end else
5810 begin
5811 a := StrToIntDef(P[1], 0);
5812 if (a < MONSTER_DEMON) or (a > MONSTER_MAN) then
5813 a := g_Mons_TypeIdByName(P[1]);
5815 if (a < MONSTER_DEMON) or (a > MONSTER_MAN) then
5816 g_Console_Add(Format(_lc[I_MSG_NO_MONSTER], [P[1]]))
5817 else
5818 begin
5819 with gPlayer1.Obj do
5820 begin
5821 mon := g_Monsters_Create(a,
5822 X + Rect.X + (Rect.Width div 2),
5823 Y + Rect.Y + Rect.Height,
5824 gPlayer1.Direction, True);
5825 end;
5826 if (Length(P) > 2) and (mon <> nil) then
5827 begin
5828 if (CompareText(P[2], 'normal') = 0) then mon.MonsterBehaviour := BH_NORMAL
5829 else if (CompareText(P[2], 'killer') = 0) then mon.MonsterBehaviour := BH_KILLER
5830 else if (CompareText(P[2], 'maniac') = 0) then mon.MonsterBehaviour := BH_MANIAC
5831 else if (CompareText(P[2], 'insane') = 0) then mon.MonsterBehaviour := BH_INSANE
5832 else if (CompareText(P[2], 'cannibal') = 0) then mon.MonsterBehaviour := BH_CANNIBAL
5833 else if (CompareText(P[2], 'good') = 0) then mon.MonsterBehaviour := BH_GOOD
5834 else if (CompareText(P[2], 'friend') = 0) then mon.MonsterBehaviour := BH_GOOD
5835 else if (CompareText(P[2], 'friendly') = 0) then mon.MonsterBehaviour := BH_GOOD
5836 else mon.MonsterBehaviour := Min(Max(StrToIntDef(P[2], BH_NORMAL), BH_NORMAL), BH_GOOD);
5837 end;
5838 end;
5839 end;
5840 end
5841 else if (cmd = 'd_health') then
5842 begin
5843 if (Length(P) > 1) and
5844 ((P[1] = '1') or (P[1] = '0')) then
5845 g_debug_HealthBar := (P[1][1] = '1');
5847 g_Console_Add(Format('d_health is %d', [Byte(g_debug_HealthBar)]));
5848 end
5849 else if (cmd = 'd_player') then
5850 begin
5851 if (Length(P) > 1) and
5852 ((P[1] = '1') or (P[1] = '0')) then
5853 g_debug_Player := (P[1][1] = '1');
5855 g_Console_Add(Format(cmd + ' is %d', [Byte(g_Debug_Player)]));
5856 end
5857 else if (cmd = 'd_mem') then
5858 begin
5859 PrintHeapStats();
5860 end;
5861 end
5862 else
5863 g_Console_Add(_lc[I_MSG_NOT_DEBUG]);
5864 end;
5867 procedure GameCheats(P: SSArray);
5868 var
5869 cmd: string;
5870 f, a: Integer;
5871 plr: TPlayer;
5872 begin
5873 if (not gGameOn) or (not conIsCheatsEnabled) then
5874 begin
5875 g_Console_Add('not available');
5876 exit;
5877 end;
5878 plr := gPlayer1;
5879 if plr = nil then
5880 begin
5881 g_Console_Add('where is the player?!');
5882 exit;
5883 end;
5884 cmd := LowerCase(P[0]);
5885 // god
5886 if cmd = 'god' then
5887 begin
5888 plr.GodMode := not plr.GodMode;
5889 if plr.GodMode then g_Console_Add('player is godlike now') else g_Console_Add('player is mortal now');
5890 exit;
5891 end;
5892 // give <health|exit|weapons|air|suit|jetpack|berserk|all>
5893 if cmd = 'give' then
5894 begin
5895 if length(P) < 2 then begin g_Console_Add('give what?!'); exit; end;
5896 for f := 1 to High(P) do
5897 begin
5898 cmd := LowerCase(P[f]);
5899 if cmd = 'health' then begin plr.RestoreHealthArmor(); g_Console_Add('player feels himself better'); continue; end;
5900 if (cmd = 'all') {or (cmd = 'weapons')} then begin plr.AllRulez(False); g_Console_Add('player got the gifts'); continue; end;
5901 if cmd = 'exit' then
5902 begin
5903 if gTriggers <> nil then
5904 begin
5905 for a := 0 to High(gTriggers) do
5906 begin
5907 if gTriggers[a].TriggerType = TRIGGER_EXIT then
5908 begin
5909 g_Console_Add('player left the map');
5910 gExitByTrigger := True;
5911 //g_Game_ExitLevel(gTriggers[a].Data.MapName);
5912 g_Game_ExitLevel(gTriggers[a].tgcMap);
5913 break;
5914 end;
5915 end;
5916 end;
5917 continue;
5918 end;
5920 if cmd = 'air' then begin plr.GiveItem(ITEM_OXYGEN); g_Console_Add('player got some air'); continue; end;
5921 if cmd = 'jetpack' then begin plr.GiveItem(ITEM_JETPACK); g_Console_Add('player got a jetpack'); continue; end;
5922 if cmd = 'suit' then begin plr.GiveItem(ITEM_SUIT); g_Console_Add('player got an envirosuit'); continue; end;
5923 if cmd = 'berserk' then begin plr.GiveItem(ITEM_MEDKIT_BLACK); g_Console_Add('player got a berserk pack'); continue; end;
5924 if cmd = 'backpack' then begin plr.GiveItem(ITEM_AMMO_BACKPACK); g_Console_Add('player got a backpack'); continue; end;
5926 if cmd = 'helmet' then begin plr.GiveItem(ITEM_HELMET); g_Console_Add('player got a helmet'); continue; end;
5927 if cmd = 'bottle' then begin plr.GiveItem(ITEM_BOTTLE); g_Console_Add('player got a bottle of health'); continue; end;
5929 if cmd = 'stimpack' then begin plr.GiveItem(ITEM_MEDKIT_SMALL); g_Console_Add('player got a stimpack'); continue; end;
5930 if (cmd = 'medkit') or (cmd = 'medikit') or (cmd = 'medpack') or (cmd = 'medipack') then begin plr.GiveItem(ITEM_MEDKIT_LARGE); g_Console_Add('player got a '+cmd); continue; end;
5932 if cmd = 'greenarmor' then begin plr.GiveItem(ITEM_ARMOR_GREEN); g_Console_Add('player got a security armor'); continue; end;
5933 if cmd = 'bluearmor' then begin plr.GiveItem(ITEM_ARMOR_BLUE); g_Console_Add('player got a combat armor'); continue; end;
5935 if (cmd = 'megasphere') or (cmd = 'mega') then begin plr.GiveItem(ITEM_SPHERE_BLUE); g_Console_Add('player got a megasphere'); continue; end;
5936 if (cmd = 'soulsphere') or (cmd = 'soul')then begin plr.GiveItem(ITEM_SPHERE_WHITE); g_Console_Add('player got a soul sphere'); continue; end;
5938 if (cmd = 'invul') or (cmd = 'invulnerability') then begin plr.GiveItem(ITEM_INVUL); g_Console_Add('player got invulnerability'); continue; end;
5939 if (cmd = 'invis') or (cmd = 'invisibility') then begin plr.GiveItem(ITEM_INVIS); g_Console_Add('player got invisibility'); continue; end;
5941 if cmd = 'redkey' then begin plr.GiveItem(ITEM_KEY_RED); g_Console_Add('player got the red key'); continue; end;
5942 if cmd = 'greenkey' then begin plr.GiveItem(ITEM_KEY_GREEN); g_Console_Add('player got the green key'); continue; end;
5943 if cmd = 'bluekey' then begin plr.GiveItem(ITEM_KEY_BLUE); g_Console_Add('player got the blue key'); continue; end;
5945 if (cmd = 'shotgun') or (cmd = 'sg') then begin plr.GiveItem(ITEM_WEAPON_SHOTGUN1); g_Console_Add('player got a shotgun'); continue; end;
5946 if (cmd = 'supershotgun') or (cmd = 'ssg') then begin plr.GiveItem(ITEM_WEAPON_SHOTGUN2); g_Console_Add('player got a supershotgun'); continue; end;
5947 if cmd = 'chaingun' then begin plr.GiveItem(ITEM_WEAPON_CHAINGUN); g_Console_Add('player got a chaingun'); continue; end;
5948 if (cmd = 'launcher') or (cmd = 'rocketlauncher') or (cmd = 'rl') then begin plr.GiveItem(ITEM_WEAPON_ROCKETLAUNCHER); g_Console_Add('player got a rocket launcher'); continue; end;
5949 if cmd = 'plasmagun' then begin plr.GiveItem(ITEM_WEAPON_PLASMA); g_Console_Add('player got a plasma gun'); continue; end;
5950 if cmd = 'bfg' then begin plr.GiveItem(ITEM_WEAPON_BFG); g_Console_Add('player got a BFG-9000'); continue; end;
5952 if (cmd = 'shotgunzz') or (cmd = 'sgzz') then begin plr.GiveItem(ITEM_WEAPON_SHOTGUN1); plr.GiveItem(ITEM_AMMO_SHELLS_BOX); g_Console_Add('player got a shotgun'); continue; end;
5953 if (cmd = 'supershotgunzz') or (cmd = 'ssgzz') then begin plr.GiveItem(ITEM_WEAPON_SHOTGUN2); plr.GiveItem(ITEM_AMMO_SHELLS_BOX); g_Console_Add('player got a supershotgun'); continue; end;
5954 if cmd = 'chaingunzz' then begin plr.GiveItem(ITEM_WEAPON_CHAINGUN); plr.GiveItem(ITEM_AMMO_BULLETS_BOX); g_Console_Add('player got a chaingun'); continue; end;
5955 if (cmd = 'launcherzz') or (cmd = 'rocketlauncherzz') or (cmd = 'rlzz') then begin plr.GiveItem(ITEM_WEAPON_ROCKETLAUNCHER); plr.GiveItem(ITEM_AMMO_ROCKET_BOX); g_Console_Add('player got a rocket launcher'); continue; end;
5956 if cmd = 'plasmagunzz' then begin plr.GiveItem(ITEM_WEAPON_PLASMA); plr.GiveItem(ITEM_AMMO_CELL_BIG); g_Console_Add('player got a plasma gun'); continue; end;
5957 if cmd = 'bfgzz' then begin plr.GiveItem(ITEM_WEAPON_BFG); plr.GiveItem(ITEM_AMMO_CELL_BIG); g_Console_Add('player got a BFG-9000'); continue; end;
5959 if cmd = 'superchaingun' then begin plr.GiveItem(ITEM_WEAPON_SUPERPULEMET); g_Console_Add('player got a superchaingun'); continue; end;
5960 if cmd = 'superchaingunzz' then begin plr.GiveItem(ITEM_WEAPON_SUPERPULEMET); plr.GiveItem(ITEM_AMMO_BULLETS_BOX); g_Console_Add('player got a superchaingun'); continue; end;
5962 if (cmd = 'flamer') or (cmd = 'flamethrower') or (cmd = 'ft') then begin plr.GiveItem(ITEM_WEAPON_FLAMETHROWER); g_Console_Add('player got a flame thrower'); continue; end;
5963 if (cmd = 'flamerzz') or (cmd = 'flamethrowerzz') or (cmd = 'ftzz') then begin plr.GiveItem(ITEM_WEAPON_FLAMETHROWER); plr.GiveItem(ITEM_AMMO_FUELCAN); g_Console_Add('player got a flame thrower'); continue; end;
5965 if cmd = 'chainsaw' then begin plr.GiveItem(ITEM_WEAPON_SAW); g_Console_Add('player got a chainsaw'); continue; end;
5967 if cmd = 'ammo' then
5968 begin
5969 plr.GiveItem(ITEM_AMMO_SHELLS_BOX);
5970 plr.GiveItem(ITEM_AMMO_BULLETS_BOX);
5971 plr.GiveItem(ITEM_AMMO_CELL_BIG);
5972 plr.GiveItem(ITEM_AMMO_ROCKET_BOX);
5973 plr.GiveItem(ITEM_AMMO_FUELCAN);
5974 g_Console_Add('player got some ammo');
5975 continue;
5976 end;
5978 if cmd = 'clip' then begin plr.GiveItem(ITEM_AMMO_BULLETS); g_Console_Add('player got some bullets'); continue; end;
5979 if cmd = 'bullets' then begin plr.GiveItem(ITEM_AMMO_BULLETS_BOX); g_Console_Add('player got a box of bullets'); continue; end;
5981 if cmd = 'shells' then begin plr.GiveItem(ITEM_AMMO_SHELLS); g_Console_Add('player got some shells'); continue; end;
5982 if cmd = 'shellbox' then begin plr.GiveItem(ITEM_AMMO_SHELLS_BOX); g_Console_Add('player got a box of shells'); continue; end;
5984 if cmd = 'cells' then begin plr.GiveItem(ITEM_AMMO_CELL); g_Console_Add('player got some cells'); continue; end;
5985 if cmd = 'battery' then begin plr.GiveItem(ITEM_AMMO_CELL_BIG); g_Console_Add('player got cell battery'); continue; end;
5987 if cmd = 'rocket' then begin plr.GiveItem(ITEM_AMMO_ROCKET); g_Console_Add('player got a rocket'); continue; end;
5988 if cmd = 'rocketbox' then begin plr.GiveItem(ITEM_AMMO_ROCKET_BOX); g_Console_Add('player got some rockets'); continue; end;
5990 if (cmd = 'fuel') or (cmd = 'fuelcan') then begin plr.GiveItem(ITEM_AMMO_FUELCAN); g_Console_Add('player got fuel canister'); continue; end;
5992 if cmd = 'weapons' then
5993 begin
5994 plr.GiveItem(ITEM_WEAPON_SHOTGUN1);
5995 plr.GiveItem(ITEM_WEAPON_SHOTGUN2);
5996 plr.GiveItem(ITEM_WEAPON_CHAINGUN);
5997 plr.GiveItem(ITEM_WEAPON_ROCKETLAUNCHER);
5998 plr.GiveItem(ITEM_WEAPON_PLASMA);
5999 plr.GiveItem(ITEM_WEAPON_BFG);
6000 g_Console_Add('player got weapons');
6001 continue;
6002 end;
6004 if cmd = 'keys' then
6005 begin
6006 plr.GiveItem(ITEM_KEY_RED);
6007 plr.GiveItem(ITEM_KEY_GREEN);
6008 plr.GiveItem(ITEM_KEY_BLUE);
6009 g_Console_Add('player got all keys');
6010 continue;
6011 end;
6013 g_Console_Add('i don''t know how to give '''+cmd+'''!');
6014 end;
6015 exit;
6016 end;
6017 // open
6018 if cmd = 'open' then
6019 begin
6020 g_Console_Add('player activated sesame');
6021 g_Triggers_OpenAll();
6022 exit;
6023 end;
6024 // fly
6025 if cmd = 'fly' then
6026 begin
6027 gFly := not gFly;
6028 if gFly then g_Console_Add('player feels himself lighter') else g_Console_Add('player lost his wings');
6029 exit;
6030 end;
6031 // noclip
6032 if cmd = 'noclip' then
6033 begin
6034 plr.SwitchNoClip;
6035 g_Console_Add('wall hardeness adjusted');
6036 exit;
6037 end;
6038 // notarget
6039 if cmd = 'notarget' then
6040 begin
6041 plr.NoTarget := not plr.NoTarget;
6042 if plr.NoTarget then g_Console_Add('player hides in shadows') else g_Console_Add('player is brave again');
6043 exit;
6044 end;
6045 // noreload
6046 if cmd = 'noreload' then
6047 begin
6048 plr.NoReload := not plr.NoReload;
6049 if plr.NoReload then g_Console_Add('player is action hero now') else g_Console_Add('player is ordinary man now');
6050 exit;
6051 end;
6052 // speedy
6053 if cmd = 'speedy' then
6054 begin
6055 MAX_RUNVEL := 32-MAX_RUNVEL;
6056 g_Console_Add('speed adjusted');
6057 exit;
6058 end;
6059 // jumpy
6060 if cmd = 'jumpy' then
6061 begin
6062 VEL_JUMP := 30-VEL_JUMP;
6063 g_Console_Add('jump height adjusted');
6064 exit;
6065 end;
6066 // automap
6067 if cmd = 'automap' then
6068 begin
6069 gShowMap := not gShowMap;
6070 if gShowMap then g_Console_Add('player gains second sight') else g_Console_Add('player lost second sight');
6071 exit;
6072 end;
6073 // aimline
6074 if cmd = 'aimline' then
6075 begin
6076 gAimLine := not gAimLine;
6077 if gAimLine then g_Console_Add('player gains laser sight') else g_Console_Add('player lost laser sight');
6078 exit;
6079 end;
6080 end;
6082 procedure GameCommands(P: SSArray);
6083 var
6084 a, b: Integer;
6085 s, pw: String;
6086 chstr: string;
6087 cmd: string;
6088 pl: pTNetClient = nil;
6089 plr: TPlayer;
6090 prt: Word;
6091 nm: Boolean;
6092 listen: LongWord;
6093 begin
6094 // Îáùèå êîìàíäû:
6095 cmd := LowerCase(P[0]);
6096 chstr := '';
6097 if (cmd = 'quit') or
6098 (cmd = 'exit') then
6099 begin
6100 g_Game_Free();
6101 g_Game_Quit();
6102 Exit;
6103 end
6104 else if cmd = 'pause' then
6105 begin
6106 if (g_ActiveWindow = nil) then
6107 g_Game_Pause(not gPauseMain);
6108 end
6109 else if cmd = 'endgame' then
6110 gExit := EXIT_SIMPLE
6111 else if cmd = 'restart' then
6112 begin
6113 if gGameOn or (gState in [STATE_INTERSINGLE, STATE_INTERCUSTOM]) then
6114 begin
6115 if g_Game_IsClient then
6116 begin
6117 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6118 Exit;
6119 end;
6120 g_Game_Restart();
6121 end else
6122 g_Console_Add(_lc[I_MSG_NOT_GAME]);
6123 end
6124 else if cmd = 'kick' then
6125 begin
6126 if g_Game_IsServer then
6127 begin
6128 if Length(P) < 2 then
6129 begin
6130 g_Console_Add('kick <name>');
6131 Exit;
6132 end;
6133 if P[1] = '' then
6134 begin
6135 g_Console_Add('kick <name>');
6136 Exit;
6137 end;
6139 if g_Game_IsNet then
6140 pl := g_Net_Client_ByName(P[1]);
6141 if (pl <> nil) then
6142 begin
6143 s := g_Net_ClientName_ByID(pl^.ID);
6144 enet_peer_disconnect(pl^.Peer, NET_DISC_KICK);
6145 g_Console_Add(Format(_lc[I_PLAYER_KICK], [s]));
6146 MH_SEND_GameEvent(NET_EV_PLAYER_KICK, 0, s);
6147 if NetUseMaster then
6148 g_Net_Slist_Update;
6149 end else if gPlayers <> nil then
6150 for a := Low(gPlayers) to High(gPlayers) do
6151 if gPlayers[a] <> nil then
6152 if Copy(LowerCase(gPlayers[a].Name), 1, Length(P[1])) = LowerCase(P[1]) then
6153 begin
6154 // Íå îòêëþ÷àòü îñíîâíûõ èãðîêîâ â ñèíãëå
6155 if not(gPlayers[a] is TBot) and (gGameSettings.GameType = GT_SINGLE) then
6156 continue;
6157 gPlayers[a].Lives := 0;
6158 gPlayers[a].Kill(K_SIMPLEKILL, 0, HIT_DISCON);
6159 g_Console_Add(Format(_lc[I_PLAYER_LEAVE], [gPlayers[a].Name]), True);
6160 g_Player_Remove(gPlayers[a].UID);
6161 if NetUseMaster then
6162 g_Net_Slist_Update;
6163 // Åñëè íå ïåðåìåøàòü, ïðè äîáàâëåíèè íîâûõ áîòîâ ïîÿâÿòñÿ ñòàðûå
6164 g_Bot_MixNames();
6165 end;
6166 end else
6167 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
6168 end
6169 else if cmd = 'kick_id' then
6170 begin
6171 if g_Game_IsServer and g_Game_IsNet then
6172 begin
6173 if Length(P) < 2 then
6174 begin
6175 g_Console_Add('kick_id <client ID>');
6176 Exit;
6177 end;
6178 if P[1] = '' then
6179 begin
6180 g_Console_Add('kick_id <client ID>');
6181 Exit;
6182 end;
6184 a := StrToIntDef(P[1], 0);
6185 if (NetClients <> nil) and (a <= High(NetClients)) then
6186 begin
6187 if NetClients[a].Used and (NetClients[a].Peer <> nil) then
6188 begin
6189 s := g_Net_ClientName_ByID(NetClients[a].ID);
6190 enet_peer_disconnect(NetClients[a].Peer, NET_DISC_KICK);
6191 g_Console_Add(Format(_lc[I_PLAYER_KICK], [s]));
6192 MH_SEND_GameEvent(NET_EV_PLAYER_KICK, 0, s);
6193 if NetUseMaster then
6194 g_Net_Slist_Update;
6195 end;
6196 end;
6197 end else
6198 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6199 end
6200 else if cmd = 'ban' then
6201 begin
6202 if g_Game_IsServer and g_Game_IsNet then
6203 begin
6204 if Length(P) < 2 then
6205 begin
6206 g_Console_Add('ban <name>');
6207 Exit;
6208 end;
6209 if P[1] = '' then
6210 begin
6211 g_Console_Add('ban <name>');
6212 Exit;
6213 end;
6215 pl := g_Net_Client_ByName(P[1]);
6216 if (pl <> nil) then
6217 begin
6218 s := g_Net_ClientName_ByID(pl^.ID);
6219 g_Net_BanHost(pl^.Peer^.address.host, False);
6220 enet_peer_disconnect(pl^.Peer, NET_DISC_TEMPBAN);
6221 g_Console_Add(Format(_lc[I_PLAYER_BAN], [s]));
6222 MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s);
6223 if NetUseMaster then
6224 g_Net_Slist_Update;
6225 end else
6226 g_Console_Add(Format(_lc[I_NET_ERR_NAME404], [P[1]]));
6227 end else
6228 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6229 end
6230 else if cmd = 'ban_id' then
6231 begin
6232 if g_Game_IsServer and g_Game_IsNet then
6233 begin
6234 if Length(P) < 2 then
6235 begin
6236 g_Console_Add('ban_id <client ID>');
6237 Exit;
6238 end;
6239 if P[1] = '' then
6240 begin
6241 g_Console_Add('ban_id <client ID>');
6242 Exit;
6243 end;
6245 a := StrToIntDef(P[1], 0);
6246 if (NetClients <> nil) and (a <= High(NetClients)) then
6247 if NetClients[a].Used and (NetClients[a].Peer <> nil) then
6248 begin
6249 s := g_Net_ClientName_ByID(NetClients[a].ID);
6250 g_Net_BanHost(NetClients[a].Peer^.address.host, False);
6251 enet_peer_disconnect(NetClients[a].Peer, NET_DISC_TEMPBAN);
6252 g_Console_Add(Format(_lc[I_PLAYER_BAN], [s]));
6253 MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s);
6254 if NetUseMaster then
6255 g_Net_Slist_Update;
6256 end;
6257 end else
6258 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6259 end
6260 else if cmd = 'permban' then
6261 begin
6262 if g_Game_IsServer and g_Game_IsNet then
6263 begin
6264 if Length(P) < 2 then
6265 begin
6266 g_Console_Add('permban <name>');
6267 Exit;
6268 end;
6269 if P[1] = '' then
6270 begin
6271 g_Console_Add('permban <name>');
6272 Exit;
6273 end;
6275 pl := g_Net_Client_ByName(P[1]);
6276 if (pl <> nil) then
6277 begin
6278 s := g_Net_ClientName_ByID(pl^.ID);
6279 g_Net_BanHost(pl^.Peer^.address.host);
6280 enet_peer_disconnect(pl^.Peer, NET_DISC_BAN);
6281 g_Net_SaveBanList();
6282 g_Console_Add(Format(_lc[I_PLAYER_BAN], [s]));
6283 MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s);
6284 if NetUseMaster then
6285 g_Net_Slist_Update;
6286 end else
6287 g_Console_Add(Format(_lc[I_NET_ERR_NAME404], [P[1]]));
6288 end else
6289 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6290 end
6291 else if cmd = 'permban_id' then
6292 begin
6293 if g_Game_IsServer and g_Game_IsNet then
6294 begin
6295 if Length(P) < 2 then
6296 begin
6297 g_Console_Add('permban_id <client ID>');
6298 Exit;
6299 end;
6300 if P[1] = '' then
6301 begin
6302 g_Console_Add('permban_id <client ID>');
6303 Exit;
6304 end;
6306 a := StrToIntDef(P[1], 0);
6307 if (NetClients <> nil) and (a <= High(NetClients)) then
6308 if NetClients[a].Used and (NetClients[a].Peer <> nil) then
6309 begin
6310 s := g_Net_ClientName_ByID(NetClients[a].ID);
6311 g_Net_BanHost(NetClients[a].Peer^.address.host);
6312 enet_peer_disconnect(NetClients[a].Peer, NET_DISC_BAN);
6313 g_Net_SaveBanList();
6314 g_Console_Add(Format(_lc[I_PLAYER_BAN], [s]));
6315 MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s);
6316 if NetUseMaster then
6317 g_Net_Slist_Update;
6318 end;
6319 end else
6320 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6321 end
6322 else if cmd = 'unban' then
6323 begin
6324 if g_Game_IsServer and g_Game_IsNet then
6325 begin
6326 if Length(P) < 2 then
6327 begin
6328 g_Console_Add('unban <IP Address>');
6329 Exit;
6330 end;
6331 if P[1] = '' then
6332 begin
6333 g_Console_Add('unban <IP Address>');
6334 Exit;
6335 end;
6337 if g_Net_UnbanHost(P[1]) then
6338 begin
6339 g_Console_Add(Format(_lc[I_MSG_UNBAN_OK], [P[1]]));
6340 g_Net_SaveBanList();
6341 end else
6342 g_Console_Add(Format(_lc[I_MSG_UNBAN_FAIL], [P[1]]));
6343 end else
6344 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6345 end
6346 else if cmd = 'clientlist' then
6347 begin
6348 if g_Game_IsServer and g_Game_IsNet then
6349 begin
6350 b := 0;
6351 if NetClients <> nil then
6352 for a := Low(NetClients) to High(NetClients) do
6353 if NetClients[a].Used and (NetClients[a].Peer <> nil) then
6354 begin
6355 plr := g_Player_Get(NetClients[a].Player);
6356 if plr = nil then continue;
6357 Inc(b);
6358 g_Console_Add(Format('#%2d: %-15s | %s', [a,
6359 IpToStr(NetClients[a].Peer^.address.host), plr.Name]));
6360 end;
6361 if b = 0 then
6362 g_Console_Add(_lc[I_MSG_NOCLIENTS]);
6363 end else
6364 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6365 end
6366 else if cmd = 'connect' then
6367 begin
6368 if (NetMode = NET_NONE) then
6369 begin
6370 if Length(P) < 2 then
6371 begin
6372 g_Console_Add('connect <IP> [port] [password]');
6373 Exit;
6374 end;
6375 if P[1] = '' then
6376 begin
6377 g_Console_Add('connect <IP> [port] [password]');
6378 Exit;
6379 end;
6381 if Length(P) > 2 then
6382 prt := StrToIntDef(P[2], 25666)
6383 else
6384 prt := 25666;
6386 if Length(P) > 3 then
6387 pw := P[3]
6388 else
6389 pw := '';
6391 g_Game_StartClient(P[1], prt, pw);
6392 end;
6393 end
6394 else if cmd = 'disconnect' then
6395 begin
6396 if (NetMode = NET_CLIENT) then
6397 g_Net_Disconnect();
6398 end
6399 else if cmd = 'reconnect' then
6400 begin
6401 if (NetMode = NET_SERVER) then
6402 Exit;
6404 if (NetMode = NET_CLIENT) then
6405 begin
6406 g_Net_Disconnect();
6407 gExit := EXIT_SIMPLE;
6408 EndGame;
6409 end;
6411 //TODO: Use last successful password to reconnect, instead of ''
6412 g_Game_StartClient(NetClientIP, NetClientPort, '');
6413 end
6414 else if (cmd = 'addbot') or
6415 (cmd = 'bot_add') then
6416 begin
6417 if Length(P) > 2 then
6418 g_Bot_Add(TEAM_NONE, StrToIntDef(P[1], 2), StrToIntDef(P[2], 100))
6419 else if Length(P) > 1 then
6420 g_Bot_Add(TEAM_NONE, StrToIntDef(P[1], 2))
6421 else
6422 g_Bot_Add(TEAM_NONE, 2);
6423 end
6424 else if cmd = 'bot_addlist' then
6425 begin
6426 if Length(P) > 1 then
6427 begin
6428 if Length(P) = 2 then
6429 g_Bot_AddList(TEAM_NONE, P[1], StrToIntDef(P[1], -1))
6430 else if Length(P) = 3 then
6431 g_Bot_AddList(TEAM_NONE, P[1], StrToIntDef(P[1], -1), StrToIntDef(P[2], 100))
6432 else
6433 g_Bot_AddList(IfThen(P[2] = 'red', TEAM_RED, TEAM_BLUE), P[1], StrToIntDef(P[1], -1));
6434 end;
6435 end
6436 else if cmd = 'bot_removeall' then
6437 g_Bot_RemoveAll()
6438 else if cmd = 'chat' then
6439 begin
6440 if g_Game_IsNet then
6441 begin
6442 if Length(P) > 1 then
6443 begin
6444 for a := 1 to High(P) do
6445 chstr := chstr + P[a] + ' ';
6447 if Length(chstr) > 200 then SetLength(chstr, 200);
6449 if Length(chstr) < 1 then
6450 begin
6451 g_Console_Add('chat <text>');
6452 Exit;
6453 end;
6455 chstr := b_Text_Format(chstr);
6456 if g_Game_IsClient then
6457 MC_SEND_Chat(chstr, NET_CHAT_PLAYER)
6458 else
6459 MH_SEND_Chat(gPlayer1Settings.Name + ': ' + chstr, NET_CHAT_PLAYER);
6460 end
6461 else
6462 g_Console_Add('chat <text>');
6463 end else
6464 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
6465 end
6466 else if cmd = 'teamchat' then
6467 begin
6468 if g_Game_IsNet and (gGameSettings.GameMode in [GM_TDM, GM_CTF]) then
6469 begin
6470 if Length(P) > 1 then
6471 begin
6472 for a := 1 to High(P) do
6473 chstr := chstr + P[a] + ' ';
6475 if Length(chstr) > 200 then SetLength(chstr, 200);
6477 if Length(chstr) < 1 then
6478 begin
6479 g_Console_Add('teamchat <text>');
6480 Exit;
6481 end;
6483 chstr := b_Text_Format(chstr);
6484 if g_Game_IsClient then
6485 MC_SEND_Chat(chstr, NET_CHAT_TEAM)
6486 else
6487 MH_SEND_Chat(gPlayer1Settings.Name + ': ' + chstr, NET_CHAT_TEAM,
6488 gPlayer1Settings.Team);
6489 end
6490 else
6491 g_Console_Add('teamchat <text>');
6492 end else
6493 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
6494 end
6495 else if cmd = 'game' then
6496 begin
6497 if gGameSettings.GameType <> GT_NONE then
6498 begin
6499 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
6500 Exit;
6501 end;
6502 if Length(P) = 1 then
6503 begin
6504 g_Console_Add(cmd + ' <WAD> [MAP] [# players]');
6505 Exit;
6506 end;
6507 // Èãðà åù¸ íå çàïóùåíà, ñíà÷àëà íàì íàäî çàãðóçèòü êàêîé-òî WAD
6508 P[1] := addWadExtension(P[1]);
6509 if FileExists(MapsDir + P[1]) then
6510 begin
6511 // Åñëè êàðòà íå óêàçàíà, áåð¸ì ïåðâóþ êàðòó â ôàéëå
6512 if Length(P) < 3 then
6513 begin
6514 SetLength(P, 3);
6515 P[2] := g_Game_GetFirstMap(MapsDir + P[1]);
6516 end;
6518 s := P[1] + ':\' + UpperCase(P[2]);
6520 if g_Map_Exist(MapsDir + s) then
6521 begin
6522 // Çàïóñêàåì ñâîþ èãðó
6523 g_Game_Free();
6524 with gGameSettings do
6525 begin
6526 GameMode := g_Game_TextToMode(gcGameMode);
6527 if gSwitchGameMode <> GM_NONE then
6528 GameMode := gSwitchGameMode;
6529 if GameMode = GM_NONE then GameMode := GM_DM;
6530 if GameMode = GM_SINGLE then GameMode := GM_COOP;
6531 b := 1;
6532 if Length(P) >= 4 then
6533 b := StrToIntDef(P[3], 1);
6534 g_Game_StartCustom(s, GameMode, TimeLimit,
6535 GoalLimit, MaxLives, Options, b);
6536 end;
6537 end
6538 else
6539 if P[2] = '' then
6540 g_Console_Add(Format(_lc[I_MSG_NO_MAPS], [P[1]]))
6541 else
6542 g_Console_Add(Format(_lc[I_MSG_NO_MAP_FALLBACK], [UpperCase(P[2]), P[1]]));
6543 end else
6544 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]));
6545 end
6546 else if cmd = 'host' then
6547 begin
6548 if gGameSettings.GameType <> GT_NONE then
6549 begin
6550 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
6551 Exit;
6552 end;
6553 if Length(P) < 4 then
6554 begin
6555 g_Console_Add(cmd + ' <listen IP> <port> <WAD> [MAP] [# players]');
6556 Exit;
6557 end;
6558 if not StrToIp(P[1], listen) then
6559 Exit;
6560 prt := StrToIntDef(P[2], 25666);
6562 P[3] := addWadExtension(P[3]);
6563 if FileExists(MapsDir + P[3]) then
6564 begin
6565 // Åñëè êàðòà íå óêàçàíà, áåð¸ì ïåðâóþ êàðòó â ôàéëå
6566 if Length(P) < 5 then
6567 begin
6568 SetLength(P, 5);
6569 P[4] := g_Game_GetFirstMap(MapsDir + P[1]);
6570 end;
6572 s := P[3] + ':\' + UpperCase(P[4]);
6574 if g_Map_Exist(MapsDir + s) then
6575 begin
6576 // Çàïóñêàåì ñâîþ èãðó
6577 g_Game_Free();
6578 with gGameSettings do
6579 begin
6580 GameMode := g_Game_TextToMode(gcGameMode);
6581 if gSwitchGameMode <> GM_NONE then
6582 GameMode := gSwitchGameMode;
6583 if GameMode = GM_NONE then GameMode := GM_DM;
6584 if GameMode = GM_SINGLE then GameMode := GM_COOP;
6585 b := 0;
6586 if Length(P) >= 6 then
6587 b := StrToIntDef(P[5], 0);
6588 g_Game_StartServer(s, GameMode, TimeLimit,
6589 GoalLimit, MaxLives, Options, b, listen, prt);
6590 end;
6591 end
6592 else
6593 if P[4] = '' then
6594 g_Console_Add(Format(_lc[I_MSG_NO_MAPS], [P[3]]))
6595 else
6596 g_Console_Add(Format(_lc[I_MSG_NO_MAP_FALLBACK], [UpperCase(P[4]), P[3]]));
6597 end else
6598 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[3]]));
6599 end
6600 else if cmd = 'map' then
6601 begin
6602 if Length(P) = 1 then
6603 begin
6604 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
6605 begin
6606 g_Console_Add(cmd + ' <MAP>');
6607 g_Console_Add(cmd + ' <WAD> [MAP]');
6608 end else
6609 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
6610 end else
6611 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
6612 begin
6613 // Èä¸ò ñâîÿ èãðà èëè ñåðâåð
6614 if Length(P) < 3 then
6615 begin
6616 // Ïåðâûé ïàðàìåòð - ëèáî êàðòà, ëèáî èìÿ WAD ôàéëà
6617 s := UpperCase(P[1]);
6618 if g_Map_Exist(MapsDir + gGameSettings.WAD + ':\' + s) then
6619 begin // Êàðòà íàøëàñü
6620 gExitByTrigger := False;
6621 if gGameOn then
6622 begin // Èä¸ò èãðà - çàâåðøàåì óðîâåíü
6623 gNextMap := s;
6624 gExit := EXIT_ENDLEVELCUSTOM;
6625 end
6626 else // Èíòåðìèññèÿ - ñðàçó çàãðóæàåì êàðòó
6627 g_Game_ChangeMap(s);
6628 end else
6629 begin
6630 // Òàêîé êàðòû íåò, èùåì WAD ôàéë
6631 pw := findDiskWad(MapsDir + P[1]);
6632 g_Console_Add(Format(_lc[I_MSG_NO_MAP_FALLBACK], [s, 'WAD ' + P[1]]));
6633 if FileExists(pw) then
6634 begin
6635 // Ïàðàìåòðà êàðòû íåò, ïîýòîìó ñòàâèì ïåðâóþ èç ôàéëà
6636 SetLength(P, 3);
6637 P[1] := ExtractRelativePath(MapsDir, pw);
6638 P[2] := g_Game_GetFirstMap(MapsDir + P[1]);
6640 s := P[1] + ':\' + P[2];
6642 if g_Map_Exist(MapsDir + s) then
6643 begin
6644 gExitByTrigger := False;
6645 if gGameOn then
6646 begin // Èä¸ò èãðà - çàâåðøàåì óðîâåíü
6647 gNextMap := s;
6648 gExit := EXIT_ENDLEVELCUSTOM;
6649 end
6650 else // Èíòåðìèññèÿ - ñðàçó çàãðóæàåì êàðòó
6651 g_Game_ChangeMap(s);
6652 end else
6653 if P[2] = '' then
6654 g_Console_Add(Format(_lc[I_MSG_NO_MAPS], [P[1]]))
6655 else
6656 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [P[2]]));
6657 end else
6658 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]));
6659 end;
6660 end else
6661 begin
6662 // Óêàçàíî äâà ïàðàìåòðà, çíà÷èò ïåðâûé - WAD ôàéë, à âòîðîé - êàðòà
6663 P[1] := addWadExtension(P[1]);
6664 if FileExists(MapsDir + P[1]) then
6665 begin
6666 // Íàøëè WAD ôàéë
6667 P[2] := UpperCase(P[2]);
6668 s := P[1] + ':\' + P[2];
6670 if g_Map_Exist(MapsDir + s) then
6671 begin // Íàøëè êàðòó
6672 gExitByTrigger := False;
6673 if gGameOn then
6674 begin // Èä¸ò èãðà - çàâåðøàåì óðîâåíü
6675 gNextMap := s;
6676 gExit := EXIT_ENDLEVELCUSTOM;
6677 end
6678 else // Èíòåðìèññèÿ - ñðàçó çàãðóæàåì êàðòó
6679 g_Game_ChangeMap(s);
6680 end else
6681 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [P[2]]));
6682 end else
6683 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]));
6684 end;
6685 end else
6686 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
6687 end
6688 else if cmd = 'nextmap' then
6689 begin
6690 if not(gGameOn or (gState = STATE_INTERCUSTOM)) then
6691 g_Console_Add(_lc[I_MSG_NOT_GAME])
6692 else begin
6693 nm := True;
6694 if Length(P) = 1 then
6695 begin
6696 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
6697 begin
6698 g_Console_Add(cmd + ' <MAP>');
6699 g_Console_Add(cmd + ' <WAD> [MAP]');
6700 end else begin
6701 nm := False;
6702 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
6703 end;
6704 end else
6705 begin
6706 nm := False;
6707 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
6708 begin
6709 if Length(P) < 3 then
6710 begin
6711 // Ïåðâûé ïàðàìåòð - ëèáî êàðòà, ëèáî èìÿ WAD ôàéëà
6712 s := UpperCase(P[1]);
6713 if g_Map_Exist(MapsDir + gGameSettings.WAD + ':\' + s) then
6714 begin // Êàðòà íàøëàñü
6715 gExitByTrigger := False;
6716 gNextMap := s;
6717 nm := True;
6718 end else
6719 begin
6720 // Òàêîé êàðòû íåò, èùåì WAD ôàéë
6721 P[1] := addWadExtension(P[1]);
6722 g_Console_Add(Format(_lc[I_MSG_NO_MAP_FALLBACK], [s, P[1]]));
6723 if FileExists(MapsDir + P[1]) then
6724 begin
6725 // Ïàðàìåòðà êàðòû íåò, ïîýòîìó ñòàâèì ïåðâóþ èç ôàéëà
6726 SetLength(P, 3);
6727 P[2] := g_Game_GetFirstMap(MapsDir + P[1]);
6729 s := P[1] + ':\' + P[2];
6731 if g_Map_Exist(MapsDir + s) then
6732 begin // Óñòàíàâëèâàåì êàðòó
6733 gExitByTrigger := False;
6734 gNextMap := s;
6735 nm := True;
6736 end else
6737 if P[2] = '' then
6738 g_Console_Add(Format(_lc[I_MSG_NO_MAPS], [P[1]]))
6739 else
6740 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [P[2]]));
6741 end else
6742 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]));
6743 end;
6744 end else
6745 begin
6746 // Óêàçàíî äâà ïàðàìåòðà, çíà÷èò ïåðâûé - WAD ôàéë, à âòîðîé - êàðòà
6747 P[1] := addWadExtension(P[1]);
6748 if FileExists(MapsDir + P[1]) then
6749 begin
6750 // Íàøëè WAD ôàéë
6751 P[2] := UpperCase(P[2]);
6752 s := P[1] + ':\' + P[2];
6754 if g_Map_Exist(MapsDir + s) then
6755 begin // Íàøëè êàðòó
6756 gExitByTrigger := False;
6757 gNextMap := s;
6758 nm := True;
6759 end else
6760 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [P[2]]));
6761 end else
6762 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]));
6763 end;
6764 end else
6765 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
6766 end;
6767 if nm then
6768 if gNextMap = '' then
6769 g_Console_Add(_lc[I_MSG_NEXTMAP_UNSET])
6770 else
6771 g_Console_Add(Format(_lc[I_MSG_NEXTMAP_SET], [gNextMap]));
6772 end;
6773 end
6774 else if (cmd = 'endmap') or (cmd = 'goodbye') then
6775 begin
6776 if not gGameOn then
6777 g_Console_Add(_lc[I_MSG_NOT_GAME])
6778 else
6779 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
6780 begin
6781 gExitByTrigger := False;
6782 // Ñëåäóþùàÿ êàðòà íå çàäàíà, ïðîáóåì íàéòè òðèããåð Âûõîä
6783 if (gNextMap = '') and (gTriggers <> nil) then
6784 for a := 0 to High(gTriggers) do
6785 if gTriggers[a].TriggerType = TRIGGER_EXIT then
6786 begin
6787 gExitByTrigger := True;
6788 //gNextMap := gTriggers[a].Data.MapName;
6789 gNextMap := gTriggers[a].tgcMap;
6790 Break;
6791 end;
6792 // Èùåì ñëåäóþùóþ êàðòó â WAD ôàéëå
6793 if gNextMap = '' then
6794 gNextMap := g_Game_GetNextMap();
6795 // Ïðîâåðÿåì, íå çàäàí ëè WAD ôàéë ðåñóðñíîé ñòðîêîé
6796 if not isWadPath(gNextMap) then
6797 s := gGameSettings.WAD + ':\' + gNextMap
6798 else
6799 s := gNextMap;
6800 // Åñëè êàðòà íàéäåíà, âûõîäèì ñ óðîâíÿ
6801 if g_Map_Exist(MapsDir + s) then
6802 gExit := EXIT_ENDLEVELCUSTOM
6803 else
6804 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [gNextMap]));
6805 end else
6806 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
6807 end
6808 else if (cmd = 'event') then
6809 begin
6810 if (Length(P) <= 1) then
6811 begin
6812 for a := 0 to High(gEvents) do
6813 if gEvents[a].Command = '' then
6814 g_Console_Add(gEvents[a].Name + ' <none>')
6815 else
6816 g_Console_Add(gEvents[a].Name + ' "' + gEvents[a].Command + '"');
6817 Exit;
6818 end;
6819 if (Length(P) = 2) then
6820 begin
6821 for a := 0 to High(gEvents) do
6822 if gEvents[a].Name = P[1] then
6823 if gEvents[a].Command = '' then
6824 g_Console_Add(gEvents[a].Name + ' <none>')
6825 else
6826 g_Console_Add(gEvents[a].Name + ' "' + gEvents[a].Command + '"');
6827 Exit;
6828 end;
6829 for a := 0 to High(gEvents) do
6830 if gEvents[a].Name = P[1] then
6831 begin
6832 gEvents[a].Command := '';
6833 for b := 2 to High(P) do
6834 if Pos(' ', P[b]) = 0 then
6835 gEvents[a].Command := gEvents[a].Command + ' ' + P[b]
6836 else
6837 gEvents[a].Command := gEvents[a].Command + ' "' + P[b] + '"';
6838 gEvents[a].Command := Trim(gEvents[a].Command);
6839 Exit;
6840 end;
6841 end
6842 else if cmd = 'suicide' then
6843 begin
6844 if gGameOn then
6845 begin
6846 if g_Game_IsClient then
6847 MC_SEND_CheatRequest(NET_CHEAT_SUICIDE)
6848 else
6849 begin
6850 if gPlayer1 <> nil then
6851 gPlayer1.Damage(SUICIDE_DAMAGE, gPlayer1.UID, 0, 0, HIT_SELF);
6852 if gPlayer2 <> nil then
6853 gPlayer2.Damage(SUICIDE_DAMAGE, gPlayer2.UID, 0, 0, HIT_SELF);
6854 end;
6855 end;
6856 end
6857 else if cmd = 'screenshot' then
6858 begin
6859 g_TakeScreenShot()
6860 end
6861 else if cmd = 'weapon' then
6862 begin
6863 if Length(p) = 2 then
6864 begin
6865 a := WP_FIRST + StrToInt(p[1]) - 1;
6866 if (a >= WP_FIRST) and (a <= WP_LAST) then
6867 gSelectWeapon[0, a] := True
6868 end
6869 end
6870 else if (cmd = 'p1_weapon') or (cmd = 'p2_weapon') then
6871 begin
6872 if Length(p) = 2 then
6873 begin
6874 a := WP_FIRST + StrToInt(p[1]) - 1;
6875 b := ord(cmd[2]) - ord('1');
6876 if (a >= WP_FIRST) and (a <= WP_LAST) then
6877 gSelectWeapon[b, a] := True
6878 end
6879 end
6880 // Êîìàíäû Ñâîåé èãðû:
6881 else if gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT] then
6882 begin
6883 if cmd = 'bot_addred' then
6884 begin
6885 if Length(P) > 1 then
6886 g_Bot_Add(TEAM_RED, StrToIntDef(P[1], 2))
6887 else
6888 g_Bot_Add(TEAM_RED, 2);
6889 end
6890 else if cmd = 'bot_addblue' then
6891 begin
6892 if Length(P) > 1 then
6893 g_Bot_Add(TEAM_BLUE, StrToIntDef(P[1], 2))
6894 else
6895 g_Bot_Add(TEAM_BLUE, 2);
6896 end
6897 else if cmd = 'spectate' then
6898 begin
6899 if not gGameOn then
6900 Exit;
6901 g_Game_Spectate();
6902 end
6903 else if cmd = 'say' then
6904 begin
6905 if g_Game_IsServer and g_Game_IsNet then
6906 begin
6907 if Length(P) > 1 then
6908 begin
6909 chstr := '';
6910 for a := 1 to High(P) do
6911 chstr := chstr + P[a] + ' ';
6913 if Length(chstr) > 200 then SetLength(chstr, 200);
6915 if Length(chstr) < 1 then
6916 begin
6917 g_Console_Add('say <text>');
6918 Exit;
6919 end;
6921 chstr := b_Text_Format(chstr);
6922 MH_SEND_Chat(chstr, NET_CHAT_PLAYER);
6923 end
6924 else g_Console_Add('say <text>');
6925 end else
6926 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6927 end
6928 else if cmd = 'tell' then
6929 begin
6930 if g_Game_IsServer and g_Game_IsNet then
6931 begin
6932 if (Length(P) > 2) and (P[1] <> '') then
6933 begin
6934 chstr := '';
6935 for a := 2 to High(P) do
6936 chstr := chstr + P[a] + ' ';
6938 if Length(chstr) > 200 then SetLength(chstr, 200);
6940 if Length(chstr) < 1 then
6941 begin
6942 g_Console_Add('tell <playername> <text>');
6943 Exit;
6944 end;
6946 pl := g_Net_Client_ByName(P[1]);
6947 if pl <> nil then
6948 MH_SEND_Chat(b_Text_Format(chstr), NET_CHAT_PLAYER, pl^.ID)
6949 else
6950 g_Console_Add(Format(_lc[I_NET_ERR_NAME404], [P[1]]));
6951 end
6952 else g_Console_Add('tell <playername> <text>');
6953 end else
6954 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6955 end
6956 else if (cmd = 'overtime') and not g_Game_IsClient then
6957 begin
6958 if (Length(P) = 1) or (StrToIntDef(P[1], -1) <= 0) then
6959 Exit;
6960 // Äîïîëíèòåëüíîå âðåìÿ:
6961 gGameSettings.TimeLimit := (gTime - gGameStartTime) div 1000 + Word(StrToIntDef(P[1], 0));
6963 g_Console_Add(Format(_lc[I_MSG_TIME_LIMIT],
6964 [gGameSettings.TimeLimit div 3600,
6965 (gGameSettings.TimeLimit div 60) mod 60,
6966 gGameSettings.TimeLimit mod 60]));
6967 if g_Game_IsNet then MH_SEND_GameSettings;
6968 end
6969 else if (cmd = 'rcon_password') and g_Game_IsClient then
6970 begin
6971 if (Length(P) <= 1) then
6972 g_Console_Add('rcon_password <password>')
6973 else
6974 MC_SEND_RCONPassword(P[1]);
6975 end
6976 else if cmd = 'rcon' then
6977 begin
6978 if g_Game_IsClient then
6979 begin
6980 if Length(P) > 1 then
6981 begin
6982 chstr := '';
6983 for a := 1 to High(P) do
6984 chstr := chstr + P[a] + ' ';
6986 if Length(chstr) > 200 then SetLength(chstr, 200);
6988 if Length(chstr) < 1 then
6989 begin
6990 g_Console_Add('rcon <command>');
6991 Exit;
6992 end;
6994 MC_SEND_RCONCommand(chstr);
6995 end
6996 else g_Console_Add('rcon <command>');
6997 end;
6998 end
6999 else if cmd = 'ready' then
7000 begin
7001 if g_Game_IsServer and (gLMSRespawn = LMS_RESPAWN_WARMUP) then
7002 gLMSRespawnTime := gTime + 100;
7003 end
7004 else if (cmd = 'callvote') and g_Game_IsNet then
7005 begin
7006 if Length(P) > 1 then
7007 begin
7008 chstr := '';
7009 for a := 1 to High(P) do begin
7010 if a > 1 then chstr := chstr + ' ';
7011 chstr := chstr + P[a];
7012 end;
7014 if Length(chstr) > 200 then SetLength(chstr, 200);
7016 if Length(chstr) < 1 then
7017 begin
7018 g_Console_Add('callvote <command>');
7019 Exit;
7020 end;
7022 if g_Game_IsClient then
7023 MC_SEND_Vote(True, chstr)
7024 else
7025 g_Game_StartVote(chstr, gPlayer1Settings.Name);
7026 g_Console_Process('vote', True);
7027 end
7028 else
7029 g_Console_Add('callvote <command>');
7030 end
7031 else if (cmd = 'vote') and g_Game_IsNet then
7032 begin
7033 if g_Game_IsClient then
7034 MC_SEND_Vote(False)
7035 else if gVoteInProgress then
7036 begin
7037 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
7038 a := Floor((NetClientCount+1)/2.0) + 1
7039 else
7040 a := Floor(NetClientCount/2.0) + 1;
7041 if gVoted then
7042 begin
7043 Dec(gVoteCount);
7044 gVoted := False;
7045 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_REVOKED], [gPlayer1Settings.Name, gVoteCount, a]), True);
7046 MH_SEND_VoteEvent(NET_VE_REVOKE, gPlayer1Settings.Name, 'a', gVoteCount, a);
7047 end
7048 else
7049 begin
7050 Inc(gVoteCount);
7051 gVoted := True;
7052 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_VOTE], [gPlayer1Settings.Name, gVoteCount, a]), True);
7053 MH_SEND_VoteEvent(NET_VE_VOTE, gPlayer1Settings.Name, 'a', gVoteCount, a);
7054 g_Game_CheckVote;
7055 end;
7056 end;
7057 end
7058 end;
7059 end;
7061 procedure g_TakeScreenShot();
7062 var
7063 a: Word;
7064 FileName: string;
7065 ssdir, t: string;
7066 st: TStream;
7067 ok: Boolean;
7068 begin
7069 if e_NoGraphics then Exit;
7070 ssdir := GameDir+'/screenshots';
7071 if not findFileCI(ssdir, true) then
7072 begin
7073 // try to create dir
7074 try
7075 CreateDir(ssdir);
7076 except
7077 end;
7078 if not findFileCI(ssdir, true) then exit; // alas
7079 end;
7080 try
7081 for a := 1 to High(Word) do
7082 begin
7083 FileName := Format(ssdir+'screenshot%.3d.png', [a]);
7084 t := FileName;
7085 if findFileCI(t, true) then continue;
7086 if not findFileCI(FileName) then
7087 begin
7088 ok := false;
7089 st := createDiskFile(FileName);
7090 try
7091 e_MakeScreenshot(st, gScreenWidth, gScreenHeight);
7092 ok := true;
7093 finally
7094 st.Free();
7095 end;
7096 if not ok then try DeleteFile(FileName); except end else g_Console_Add(Format(_lc[I_CONSOLE_SCREENSHOT], [ExtractFileName(FileName)]));
7097 break;
7098 end;
7099 end;
7100 except
7101 end;
7102 end;
7104 procedure g_Game_InGameMenu(Show: Boolean);
7105 begin
7106 if (g_ActiveWindow = nil) and Show then
7107 begin
7108 if gGameSettings.GameType = GT_SINGLE then
7109 g_GUI_ShowWindow('GameSingleMenu')
7110 else
7111 begin
7112 if g_Game_IsClient then
7113 g_GUI_ShowWindow('GameClientMenu')
7114 else
7115 if g_Game_IsNet then
7116 g_GUI_ShowWindow('GameServerMenu')
7117 else
7118 g_GUI_ShowWindow('GameCustomMenu');
7119 end;
7120 g_Sound_PlayEx('MENU_OPEN');
7122 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
7123 if (not g_Game_IsNet) then
7124 g_Game_Pause(True);
7125 end
7126 else
7127 if (g_ActiveWindow <> nil) and (not Show) then
7128 begin
7129 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
7130 if (not g_Game_IsNet) then
7131 g_Game_Pause(False);
7132 end;
7133 end;
7135 procedure g_Game_Pause (Enable: Boolean);
7136 var
7137 oldPause: Boolean;
7138 begin
7139 if not gGameOn then exit;
7141 if not (gGameSettings.GameType in [GT_SINGLE, GT_CUSTOM]) then exit;
7143 oldPause := gPause;
7144 gPauseMain := Enable;
7146 if (gPause <> oldPause) then g_Game_PauseAllSounds(gPause);
7147 end;
7149 procedure g_Game_HolmesPause (Enable: Boolean);
7150 var
7151 oldPause: Boolean;
7152 begin
7153 if not gGameOn then exit;
7154 if not (gGameSettings.GameType in [GT_SINGLE, GT_CUSTOM]) then exit;
7156 oldPause := gPause;
7157 gPauseHolmes := Enable;
7159 if (gPause <> oldPause) then g_Game_PauseAllSounds(gPause);
7160 end;
7162 procedure g_Game_PauseAllSounds(Enable: Boolean);
7163 var
7164 i: Integer;
7165 begin
7166 // Òðèããåðû:
7167 if gTriggers <> nil then
7168 for i := 0 to High(gTriggers) do
7169 with gTriggers[i] do
7170 if (TriggerType = TRIGGER_SOUND) and
7171 (Sound <> nil) and
7172 Sound.IsPlaying() then
7173 begin
7174 Sound.Pause(Enable);
7175 end;
7177 // Çâóêè èãðîêîâ:
7178 if gPlayers <> nil then
7179 for i := 0 to High(gPlayers) do
7180 if gPlayers[i] <> nil then
7181 gPlayers[i].PauseSounds(Enable);
7183 // Ìóçûêà:
7184 if gMusic <> nil then
7185 gMusic.Pause(Enable);
7186 end;
7188 procedure g_Game_StopAllSounds(all: Boolean);
7189 var
7190 i: Integer;
7191 begin
7192 if gTriggers <> nil then
7193 for i := 0 to High(gTriggers) do
7194 with gTriggers[i] do
7195 if (TriggerType = TRIGGER_SOUND) and
7196 (Sound <> nil) then
7197 Sound.Stop();
7199 if gMusic <> nil then
7200 gMusic.Stop();
7202 if all then
7203 e_StopChannels();
7204 end;
7206 procedure g_Game_UpdateTriggerSounds;
7207 var i: Integer;
7208 begin
7209 if gTriggers <> nil then
7210 for i := 0 to High(gTriggers) do
7211 with gTriggers[i] do
7212 if (TriggerType = TRIGGER_SOUND) and (Sound <> nil) and tgcLocal and Sound.IsPlaying() then
7213 Sound.SetCoordsRect(X, Y, Width, Height, tgcVolume / 255.0)
7214 end;
7216 function g_Game_IsWatchedPlayer(UID: Word): Boolean;
7217 begin
7218 Result := False;
7219 if (gPlayer1 <> nil) and (gPlayer1.UID = UID) then
7220 begin
7221 Result := True;
7222 Exit;
7223 end;
7224 if (gPlayer2 <> nil) and (gPlayer2.UID = UID) then
7225 begin
7226 Result := True;
7227 Exit;
7228 end;
7229 if gSpectMode <> SPECT_PLAYERS then
7230 Exit;
7231 if gSpectPID1 = UID then
7232 begin
7233 Result := True;
7234 Exit;
7235 end;
7236 if gSpectViewTwo and (gSpectPID2 = UID) then
7237 begin
7238 Result := True;
7239 Exit;
7240 end;
7241 end;
7243 function g_Game_IsWatchedTeam(Team: Byte): Boolean;
7244 var
7245 Pl: TPlayer;
7246 begin
7247 Result := False;
7248 if (gPlayer1 <> nil) and (gPlayer1.Team = Team) then
7249 begin
7250 Result := True;
7251 Exit;
7252 end;
7253 if (gPlayer2 <> nil) and (gPlayer2.Team = Team) then
7254 begin
7255 Result := True;
7256 Exit;
7257 end;
7258 if gSpectMode <> SPECT_PLAYERS then
7259 Exit;
7260 Pl := g_Player_Get(gSpectPID1);
7261 if (Pl <> nil) and (Pl.Team = Team) then
7262 begin
7263 Result := True;
7264 Exit;
7265 end;
7266 if gSpectViewTwo then
7267 begin
7268 Pl := g_Player_Get(gSpectPID2);
7269 if (Pl <> nil) and (Pl.Team = Team) then
7270 begin
7271 Result := True;
7272 Exit;
7273 end;
7274 end;
7275 end;
7277 procedure g_Game_Message(Msg: string; Time: Word);
7278 begin
7279 MessageLineLength := (gScreenWidth - 204) div e_CharFont_GetMaxWidth(gMenuFont);
7280 MessageText := b_Text_Wrap(b_Text_Format(Msg), MessageLineLength);
7281 MessageTime := Time;
7282 end;
7284 procedure g_Game_ChatSound(Text: String; Taunt: Boolean = True);
7285 const
7286 punct: Array[0..13] of String =
7287 ('.', ',', ':', ';', '!', '?', '(', ')', '''', '"', '/', '\', '*', '^');
7288 var
7289 i, j: Integer;
7290 ok: Boolean;
7291 fpText: String;
7293 function IsPunctuation(S: String): Boolean;
7294 var
7295 i: Integer;
7296 begin
7297 Result := False;
7298 if Length(S) <> 1 then
7299 Exit;
7300 for i := Low(punct) to High(punct) do
7301 if S = punct[i] then
7302 begin
7303 Result := True;
7304 break;
7305 end;
7306 end;
7307 function FilterPunctuation(S: String): String;
7308 var
7309 i: Integer;
7310 begin
7311 for i := Low(punct) to High(punct) do
7312 S := StringReplace(S, punct[i], ' ', [rfReplaceAll]);
7313 Result := S;
7314 end;
7315 begin
7316 ok := False;
7318 if gUseChatSounds and Taunt and (gChatSounds <> nil) and (Pos(': ', Text) > 0) then
7319 begin
7320 // remove player name
7321 Delete(Text, 1, Pos(': ', Text) + 2 - 1);
7322 // for FullWord check
7323 Text := toLowerCase1251(' ' + Text + ' ');
7324 fpText := FilterPunctuation(Text);
7326 for i := 0 to Length(gChatSounds) - 1 do
7327 begin
7328 ok := True;
7329 for j := 0 to Length(gChatSounds[i].Tags) - 1 do
7330 begin
7331 if gChatSounds[i].FullWord and (not IsPunctuation(gChatSounds[i].Tags[j])) then
7332 ok := Pos(' ' + gChatSounds[i].Tags[j] + ' ', fpText) > 0
7333 else
7334 ok := Pos(gChatSounds[i].Tags[j], Text) > 0;
7335 if not ok then
7336 break;
7337 end;
7338 if ok then
7339 begin
7340 gChatSounds[i].Sound.Play();
7341 break;
7342 end;
7343 end;
7344 end;
7345 if not ok then
7346 g_Sound_PlayEx('SOUND_GAME_RADIO');
7347 end;
7349 procedure g_Game_Announce_GoodShot(SpawnerUID: Word);
7350 var
7351 a: Integer;
7352 begin
7353 case gAnnouncer of
7354 ANNOUNCE_NONE:
7355 Exit;
7356 ANNOUNCE_ME,
7357 ANNOUNCE_MEPLUS:
7358 if not g_Game_IsWatchedPlayer(SpawnerUID) then
7359 Exit;
7360 end;
7361 for a := 0 to 3 do
7362 if goodsnd[a].IsPlaying() then
7363 Exit;
7365 goodsnd[Random(4)].Play();
7366 end;
7368 procedure g_Game_Announce_KillCombo(Param: Integer);
7369 var
7370 UID: Word;
7371 c, n: Byte;
7372 Pl: TPlayer;
7373 Name: String;
7374 begin
7375 UID := Param and $FFFF;
7376 c := Param shr 16;
7377 if c < 2 then
7378 Exit;
7380 Pl := g_Player_Get(UID);
7381 if Pl = nil then
7382 Name := '?'
7383 else
7384 Name := Pl.Name;
7386 case c of
7387 2: begin
7388 n := 0;
7389 g_Console_Add(Format(_lc[I_PLAYER_KILL_2X], [Name]), True);
7390 end;
7391 3: begin
7392 n := 1;
7393 g_Console_Add(Format(_lc[I_PLAYER_KILL_3X], [Name]), True);
7394 end;
7395 4: begin
7396 n := 2;
7397 g_Console_Add(Format(_lc[I_PLAYER_KILL_4X], [Name]), True);
7398 end;
7399 else begin
7400 n := 3;
7401 g_Console_Add(Format(_lc[I_PLAYER_KILL_MX], [Name]), True);
7402 end;
7403 end;
7405 case gAnnouncer of
7406 ANNOUNCE_NONE:
7407 Exit;
7408 ANNOUNCE_ME:
7409 if not g_Game_IsWatchedPlayer(UID) then
7410 Exit;
7411 ANNOUNCE_MEPLUS:
7412 if (not g_Game_IsWatchedPlayer(UID)) and (c < 4) then
7413 Exit;
7414 end;
7416 if killsnd[n].IsPlaying() then
7417 killsnd[n].Stop();
7418 killsnd[n].Play();
7419 end;
7421 procedure g_Game_Announce_BodyKill(SpawnerUID: Word);
7422 var
7423 a: Integer;
7424 begin
7425 case gAnnouncer of
7426 ANNOUNCE_NONE:
7427 Exit;
7428 ANNOUNCE_ME,
7429 ANNOUNCE_MEPLUS:
7430 if not g_Game_IsWatchedPlayer(SpawnerUID) then
7431 Exit;
7432 end;
7433 for a := 0 to 2 do
7434 if hahasnd[a].IsPlaying() then
7435 Exit;
7437 hahasnd[Random(3)].Play();
7438 end;
7440 procedure g_Game_StartVote(Command, Initiator: string);
7441 var
7442 Need: Integer;
7443 begin
7444 if not gVotesEnabled then Exit;
7445 if gGameSettings.GameType <> GT_SERVER then Exit;
7446 if gVoteInProgress or gVotePassed then
7447 begin
7448 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_INPROGRESS], [gVoteCommand]), True);
7449 MH_SEND_VoteEvent(NET_VE_INPROGRESS, gVoteCommand);
7450 Exit;
7451 end;
7452 gVoteInProgress := True;
7453 gVotePassed := False;
7454 gVoteTimer := gTime + gVoteTimeout * 1000;
7455 gVoteCount := 0;
7456 gVoted := False;
7457 gVoteCommand := Command;
7459 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
7460 Need := Floor((NetClientCount+1)/2.0)+1
7461 else
7462 Need := Floor(NetClientCount/2.0)+1;
7463 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_STARTED], [Initiator, Command, Need]), True);
7464 MH_SEND_VoteEvent(NET_VE_STARTED, Initiator, Command, Need);
7465 end;
7467 procedure g_Game_CheckVote;
7468 var
7469 I, Need: Integer;
7470 begin
7471 if gGameSettings.GameType <> GT_SERVER then Exit;
7472 if not gVoteInProgress then Exit;
7474 if (gTime >= gVoteTimer) then
7475 begin
7476 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
7477 Need := Floor((NetClientCount+1)/2.0) + 1
7478 else
7479 Need := Floor(NetClientCount/2.0) + 1;
7480 if gVoteCount >= Need then
7481 begin
7482 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_PASSED], [gVoteCommand]), True);
7483 MH_SEND_VoteEvent(NET_VE_PASSED, gVoteCommand);
7484 gVotePassed := True;
7485 gVoteCmdTimer := gTime + 5000;
7486 end
7487 else
7488 begin
7489 g_Console_Add(_lc[I_MESSAGE_VOTE_FAILED], True);
7490 MH_SEND_VoteEvent(NET_VE_FAILED);
7491 end;
7492 if NetClients <> nil then
7493 for I := Low(NetClients) to High(NetClients) do
7494 if NetClients[i].Used then
7495 NetClients[i].Voted := False;
7496 gVoteInProgress := False;
7497 gVoted := False;
7498 gVoteCount := 0;
7499 end
7500 else
7501 begin
7502 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
7503 Need := Floor((NetClientCount+1)/2.0) + 1
7504 else
7505 Need := Floor(NetClientCount/2.0) + 1;
7506 if gVoteCount >= Need then
7507 begin
7508 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_PASSED], [gVoteCommand]), True);
7509 MH_SEND_VoteEvent(NET_VE_PASSED, gVoteCommand);
7510 gVoteInProgress := False;
7511 gVotePassed := True;
7512 gVoteCmdTimer := gTime + 5000;
7513 gVoted := False;
7514 gVoteCount := 0;
7515 if NetClients <> nil then
7516 for I := Low(NetClients) to High(NetClients) do
7517 if NetClients[i].Used then
7518 NetClients[i].Voted := False;
7519 end;
7520 end;
7521 end;
7523 procedure g_Game_LoadMapList(FileName: string);
7524 var
7525 ListFile: TextFile;
7526 s: string;
7527 begin
7528 MapList := nil;
7529 MapIndex := -1;
7531 if not FileExists(FileName) then Exit;
7533 AssignFile(ListFile, FileName);
7534 Reset(ListFile);
7535 while not EOF(ListFile) do
7536 begin
7537 ReadLn(ListFile, s);
7539 s := Trim(s);
7540 if s = '' then Continue;
7542 SetLength(MapList, Length(MapList)+1);
7543 MapList[High(MapList)] := s;
7544 end;
7545 CloseFile(ListFile);
7546 end;
7548 procedure g_Game_SetDebugMode();
7549 begin
7550 gDebugMode := True;
7551 // ×èòû (äàæå â ñâîåé èãðå):
7552 gCheats := True;
7553 end;
7555 procedure g_Game_SetLoadingText(Text: String; Max: Integer; reWrite: Boolean);
7556 var
7557 i: Word;
7558 begin
7559 if Length(LoadingStat.Msgs) = 0 then
7560 Exit;
7562 with LoadingStat do
7563 begin
7564 if not reWrite then
7565 begin // Ïåðåõîäèì íà ñëåäóþùóþ ñòðîêó èëè ñêðîëëèðóåì:
7566 if NextMsg = Length(Msgs) then
7567 begin // scroll
7568 for i := 0 to High(Msgs)-1 do
7569 Msgs[i] := Msgs[i+1];
7570 end
7571 else
7572 Inc(NextMsg);
7573 end else
7574 if NextMsg = 0 then
7575 Inc(NextMsg);
7577 Msgs[NextMsg-1] := Text;
7578 CurValue := 0;
7579 MaxValue := Max;
7580 ShowCount := 0;
7581 PBarWasHere := false;
7582 end;
7584 g_ActiveWindow := nil;
7586 ProcessLoading(true);
7587 end;
7589 procedure g_Game_StepLoading(Value: Integer = -1);
7590 begin
7591 with LoadingStat do
7592 begin
7593 if Value = -1 then
7594 begin
7595 Inc(CurValue);
7596 Inc(ShowCount);
7597 end
7598 else
7599 CurValue := Value;
7600 if (ShowCount > LOADING_SHOW_STEP) or (Value > -1) then
7601 begin
7602 ShowCount := 0;
7603 ProcessLoading();
7604 end;
7605 end;
7606 end;
7608 procedure g_Game_ClearLoading();
7609 var
7610 len: Word;
7611 begin
7612 with LoadingStat do
7613 begin
7614 CurValue := 0;
7615 MaxValue := 0;
7616 ShowCount := 0;
7617 len := ((gScreenHeight div 3)*2 - 50) div LOADING_INTERLINE;
7618 if len < 1 then len := 1;
7619 SetLength(Msgs, len);
7620 for len := Low(Msgs) to High(Msgs) do
7621 Msgs[len] := '';
7622 NextMsg := 0;
7623 PBarWasHere := false;
7624 end;
7625 end;
7627 procedure Parse_Params(var pars: TParamStrValues);
7628 var
7629 i: Integer;
7630 s: String;
7631 begin
7632 SetLength(pars, 0);
7633 i := 1;
7634 while i <= ParamCount do
7635 begin
7636 s := ParamStr(i);
7637 if (s[1] = '-') and (Length(s) > 1) then
7638 begin
7639 if (s[2] = '-') and (Length(s) > 2) then
7640 begin // Îäèíî÷íûé ïàðàìåòð
7641 SetLength(pars, Length(pars) + 1);
7642 with pars[High(pars)] do
7643 begin
7644 Name := LowerCase(s);
7645 Value := '+';
7646 end;
7647 end
7648 else
7649 if (i < ParamCount) then
7650 begin // Ïàðàìåòð ñî çíà÷åíèåì
7651 Inc(i);
7652 SetLength(pars, Length(pars) + 1);
7653 with pars[High(pars)] do
7654 begin
7655 Name := LowerCase(s);
7656 Value := LowerCase(ParamStr(i));
7657 end;
7658 end;
7659 end;
7661 Inc(i);
7662 end;
7663 end;
7665 function Find_Param_Value(var pars: TParamStrValues; aName: String): String;
7666 var
7667 i: Integer;
7668 begin
7669 Result := '';
7670 for i := 0 to High(pars) do
7671 if pars[i].Name = aName then
7672 begin
7673 Result := pars[i].Value;
7674 Break;
7675 end;
7676 end;
7678 procedure g_Game_Process_Params();
7679 var
7680 pars: TParamStrValues;
7681 map: String;
7682 GMode, n: Byte;
7683 LimT, LimS: Integer;
7684 Opt: LongWord;
7685 Lives: Integer;
7686 s: String;
7687 Port: Integer;
7688 ip: String;
7689 F: TextFile;
7690 begin
7691 Parse_Params(pars);
7693 // Debug mode:
7694 s := Find_Param_Value(pars, '--debug');
7695 if (s <> '') then
7696 begin
7697 g_Game_SetDebugMode();
7698 s := Find_Param_Value(pars, '--netdump');
7699 if (s <> '') then
7700 NetDump := True;
7701 end;
7703 // Connect when game loads
7704 ip := Find_Param_Value(pars, '-connect');
7706 if ip <> '' then
7707 begin
7708 s := Find_Param_Value(pars, '-port');
7709 if (s = '') or not TryStrToInt(s, Port) then
7710 Port := 25666;
7712 s := Find_Param_Value(pars, '-pw');
7714 g_Game_StartClient(ip, Port, s);
7715 Exit;
7716 end;
7718 s := LowerCase(Find_Param_Value(pars, '-dbg-mainwad'));
7719 if (s <> '') then
7720 begin
7721 gDefaultMegawadStart := s;
7722 end;
7724 if (Find_Param_Value(pars, '--dbg-mainwad-restore') <> '') or
7725 (Find_Param_Value(pars, '--dbg-mainwad-default') <> '') then
7726 begin
7727 gDefaultMegawadStart := DF_Default_Megawad_Start;
7728 end;
7730 // Start map when game loads:
7731 map := LowerCase(Find_Param_Value(pars, '-map'));
7732 if isWadPath(map) then
7733 begin
7734 // Game mode:
7735 s := Find_Param_Value(pars, '-gm');
7736 GMode := g_Game_TextToMode(s);
7737 if GMode = GM_NONE then GMode := GM_DM;
7738 if GMode = GM_SINGLE then GMode := GM_COOP;
7740 // Time limit:
7741 s := Find_Param_Value(pars, '-limt');
7742 if (s = '') or (not TryStrToInt(s, LimT)) then
7743 LimT := 0;
7744 if LimT < 0 then
7745 LimT := 0;
7747 // Goal limit:
7748 s := Find_Param_Value(pars, '-lims');
7749 if (s = '') or (not TryStrToInt(s, LimS)) then
7750 LimS := 0;
7751 if LimS < 0 then
7752 LimS := 0;
7754 // Lives limit:
7755 s := Find_Param_Value(pars, '-lives');
7756 if (s = '') or (not TryStrToInt(s, Lives)) then
7757 Lives := 0;
7758 if Lives < 0 then
7759 Lives := 0;
7761 // Options:
7762 s := Find_Param_Value(pars, '-opt');
7763 if (s = '') then
7764 Opt := GAME_OPTION_ALLOWEXIT or GAME_OPTION_BOTVSPLAYER or GAME_OPTION_BOTVSMONSTER
7765 else
7766 Opt := StrToIntDef(s, 0);
7767 if Opt = 0 then
7768 Opt := GAME_OPTION_ALLOWEXIT or GAME_OPTION_BOTVSPLAYER or GAME_OPTION_BOTVSMONSTER;
7770 // Close after map:
7771 s := Find_Param_Value(pars, '--close');
7772 if (s <> '') then
7773 gMapOnce := True;
7775 // Override map to test:
7776 s := LowerCase(Find_Param_Value(pars, '-testmap'));
7777 if s <> '' then
7778 gTestMap := MapsDir + s;
7780 // Delete test map after play:
7781 s := Find_Param_Value(pars, '--testdelete');
7782 if (s <> '') then
7783 begin
7784 gMapToDelete := MapsDir + map;
7785 e_WriteLog('"--testdelete" is deprecated, use --tempdelete.', TMsgType.Fatal);
7786 Halt(1);
7787 end;
7789 // Delete temporary WAD after play:
7790 s := Find_Param_Value(pars, '--tempdelete');
7791 if (s <> '') and (gTestMap <> '') then
7792 begin
7793 gMapToDelete := gTestMap;
7794 gTempDelete := True;
7795 end;
7797 // Number of players:
7798 s := Find_Param_Value(pars, '-pl');
7799 if (s = '') then
7800 n := DEFAULT_PLAYERS
7801 else
7802 n := StrToIntDef(s, DEFAULT_PLAYERS);
7804 // Start:
7805 s := Find_Param_Value(pars, '-port');
7806 if (s = '') or not TryStrToInt(s, Port) then
7807 g_Game_StartCustom(map, GMode, LimT, LimS, Lives, Opt, n)
7808 else
7809 g_Game_StartServer(map, GMode, LimT, LimS, Lives, Opt, n, 0, Port);
7810 end;
7812 // Execute script when game loads:
7813 s := Find_Param_Value(pars, '-exec');
7814 if s <> '' then
7815 begin
7816 if not isWadPath(s) then
7817 s := GameDir + '/' + s;
7819 {$I-}
7820 AssignFile(F, s);
7821 Reset(F);
7822 if IOResult <> 0 then
7823 begin
7824 e_WriteLog(Format(_lc[I_SIMPLE_ERROR], ['Failed to read file: ' + s]), TMsgType.Warning);
7825 g_Console_Add(Format(_lc[I_CONSOLE_ERROR_READ], [s]));
7826 CloseFile(F);
7827 Exit;
7828 end;
7829 e_WriteLog('Executing script: ' + s, TMsgType.Notify);
7830 g_Console_Add(Format(_lc[I_CONSOLE_EXEC], [s]));
7832 while not EOF(F) do
7833 begin
7834 ReadLn(F, s);
7835 if IOResult <> 0 then
7836 begin
7837 e_WriteLog(Format(_lc[I_SIMPLE_ERROR], ['Failed to read file: ' + s]), TMsgType.Warning);
7838 g_Console_Add(Format(_lc[I_CONSOLE_ERROR_READ], [s]));
7839 CloseFile(F);
7840 Exit;
7841 end;
7842 if Pos('#', s) <> 1 then // script comment
7843 g_Console_Process(s, True);
7844 end;
7846 CloseFile(F);
7847 {$I+}
7848 end;
7850 SetLength(pars, 0);
7851 end;
7853 begin
7854 conRegVar('pf_draw_frame', @g_profile_frame_draw, 'draw frame rendering profiles', 'render profiles');
7855 //conRegVar('pf_update_frame', @g_profile_frame_update, 'draw frame updating profiles', 'update profiles');
7856 conRegVar('pf_coldet', @g_profile_collision, 'draw collision detection profiles', 'coldet profiles');
7857 conRegVar('pf_los', @g_profile_los, 'draw monster LOS profiles', 'monster LOS profiles');
7859 conRegVar('r_sq_draw', @gdbg_map_use_accel_render, 'accelerated spatial queries in rendering', 'accelerated rendering');
7860 conRegVar('cd_sq_enabled', @gdbg_map_use_accel_coldet, 'accelerated spatial queries in map coldet', 'accelerated map coldet');
7861 conRegVar('mon_sq_enabled', @gmon_debug_use_sqaccel, 'accelerated spatial queries for monsters', 'accelerated monster coldet');
7862 conRegVar('wtrace_sq_enabled', @gwep_debug_fast_trace, 'accelerated spatial queries for weapon hitscan trace', 'accelerated weapon hitscan');
7864 conRegVar('pr_enabled', @gpart_dbg_enabled, 'enable/disable particles', 'particles');
7865 conRegVar('pr_phys_enabled', @gpart_dbg_phys_enabled, 'enable/disable particle physics', 'particle physics');
7867 conRegVar('los_enabled', @gmon_dbg_los_enabled, 'enable/disable monster LOS calculations', 'monster LOS', true);
7868 conRegVar('mon_think', @gmon_debug_think, 'enable/disable monster thinking', 'monster thinking', true);
7870 {$IFDEF ENABLE_HOLMES}
7871 conRegVar('dbg_holmes', @g_holmes_enabled, 'enable/disable Holmes', 'Holmes', true);
7872 {$ENDIF}
7874 conRegVar('dbg_ignore_level_bounds', @g_dbg_ignore_bounds, 'ignore level bounds', '', false);
7876 conRegVar('r_scale', @g_dbg_scale, 0.01, 100.0, 'render scale', '', false);
7878 conRegVar('light_enabled', @gwin_k8_enable_light_experiments, 'enable/disable dynamic lighting', 'lighting');
7879 conRegVar('light_player_halo', @g_playerLight, 'enable/disable player halo', 'player light halo');
7881 conRegVar('r_smallmap_align_h', @r_smallmap_h, 'halign: 0: left; 1: center; 2: right', 'horizontal aligning of small maps');
7882 conRegVar('r_smallmap_align_v', @r_smallmap_v, 'valign: 0: top; 1: center; 2: bottom', 'vertial aligning of small maps');
7884 conRegVar('r_showfps', @gShowFPS, 'draw fps counter', 'draw fps counter');
7885 conRegVar('r_showtime', @gShowTime, 'show game time', 'show game time');
7886 end.