DEADSOFTWARE

af3d8ad0c99ffcdd01002045a44084cde72561c2
[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, version 3 of the License ONLY.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14 *)
15 {$INCLUDE ../shared/a_modes.inc}
16 unit g_game;
18 interface
20 uses
21 SysUtils, Classes,
22 MAPDEF,
23 g_base, g_basic, g_player, r_graphics, g_res_downloader,
24 g_sound, g_gui, utils, md5, mempool, xprofiler,
25 g_touch, g_weapons;
27 type
28 TGameSettings = record
29 GameType: Byte;
30 GameMode: Byte;
31 TimeLimit: Word;
32 GoalLimit: Word;
33 WarmupTime: Word;
34 SpawnInvul: Word;
35 ItemRespawnTime: Word;
36 MaxLives: Byte;
37 Options: LongWord;
38 WAD: String;
39 end;
41 TGameEvent = record
42 Name: String;
43 Command: String;
44 end;
46 TDelayedEvent = record
47 Pending: Boolean;
48 Time: LongWord;
49 DEType: Byte;
50 DENum: Integer;
51 DEStr: String;
52 end;
54 TChatSound = record
55 Sound: TPlayableSound;
56 Tags: Array of String;
57 FullWord: Boolean;
58 end;
60 TPlayerSettings = record
61 Name: String;
62 Model: String;
63 Color: TRGB;
64 Team: Byte;
65 end;
67 TMegaWADInfo = record
68 Name: String;
69 Description: String;
70 Author: String;
71 Pic: String;
72 end;
74 THearPoint = record
75 Active: Boolean;
76 Coords: TDFPoint;
77 end;
79 function g_Game_IsNet(): Boolean;
80 function g_Game_IsServer(): Boolean;
81 function g_Game_IsClient(): Boolean;
82 procedure g_Game_Init();
83 procedure g_Game_Free (freeTextures: Boolean=true);
84 procedure g_Game_LoadData();
85 procedure g_Game_FreeData();
86 procedure g_Game_Update();
87 procedure g_Game_PreUpdate();
88 procedure g_Game_Quit();
89 procedure g_Game_SetupScreenSize();
90 procedure g_Game_ChangeResolution(newWidth, newHeight: Word; nowFull, nowMax: Boolean);
91 function g_Game_ModeToText(Mode: Byte): string;
92 function g_Game_TextToMode(Mode: string): Byte;
93 procedure g_Game_ExecuteEvent(Name: String);
94 function g_Game_DelayEvent(DEType: Byte; Time: LongWord; Num: Integer = 0; Str: String = ''): Integer;
95 procedure g_Game_AddPlayer(Team: Byte = TEAM_NONE);
96 procedure g_Game_RemovePlayer();
97 procedure g_Game_Spectate();
98 procedure g_Game_SpectateCenterView();
99 procedure g_Game_StartSingle(Map: String; TwoPlayers: Boolean; nPlayers: Byte);
100 procedure g_Game_StartCustom(Map: String; GameMode: Byte; TimeLimit, GoalLimit: Word; MaxLives: Byte; Options: LongWord; nPlayers: Byte);
101 procedure g_Game_StartServer(Map: String; GameMode: Byte; TimeLimit, GoalLimit: Word; MaxLives: Byte; Options: LongWord; nPlayers: Byte; IPAddr: LongWord; Port: Word);
102 procedure g_Game_StartClient(Addr: String; Port: Word; PW: String);
103 procedure g_Game_Restart();
104 procedure g_Game_RestartLevel();
105 procedure g_Game_RestartRound(NoMapRestart: Boolean = False);
106 function g_Game_ClientWAD (NewWAD: String; const WHash: TMD5Digest): AnsiString;
107 function g_Game_StartMap(asMegawad: Boolean; 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(Filename: string = '');
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 PlayerSettingsCVars(P: SSArray);
137 procedure SystemCommands(P: SSArray);
138 procedure GameCommands(P: SSArray);
139 procedure GameCheats(P: SSArray);
140 procedure DebugCommands(P: SSArray);
141 procedure g_Game_Process_Params;
142 procedure g_Game_SetLoadingText(Text: String; Max: Integer; reWrite: Boolean);
143 procedure g_Game_StepLoading(Value: Integer = -1);
144 procedure g_Game_ClearLoading();
145 procedure g_Game_SetDebugMode();
147 function IsActivePlayer(p: TPlayer): Boolean;
148 function GetActivePlayerID_Next(Skip: Integer = -1): Integer;
149 procedure SortGameStat(var stat: TPlayerStatArray);
151 procedure KeyPress (K: Word);
152 procedure CharPress (C: AnsiChar);
154 { procedure SetWinPause(Enable: Boolean); }
156 const
157 GAME_TICK = 28;
159 LOADING_SHOW_STEP = 100;
160 LOADING_INTERLINE = 20;
162 GT_NONE = 0;
163 GT_SINGLE = 1;
164 GT_CUSTOM = 2;
165 GT_SERVER = 3;
166 GT_CLIENT = 4;
168 GM_NONE = 0;
169 GM_DM = 1;
170 GM_TDM = 2;
171 GM_CTF = 3;
172 GM_COOP = 4;
173 GM_SINGLE = 5;
175 MESSAGE_DIKEY = WM_USER + 1;
177 EXIT_QUIT = 1;
178 EXIT_SIMPLE = 2;
179 EXIT_RESTART = 3;
180 EXIT_ENDLEVELSINGLE = 4;
181 EXIT_ENDLEVELCUSTOM = 5;
183 GAME_OPTION_RESERVED = 1;
184 GAME_OPTION_TEAMDAMAGE = 2;
185 GAME_OPTION_ALLOWEXIT = 4;
186 GAME_OPTION_WEAPONSTAY = 8;
187 GAME_OPTION_MONSTERS = 16;
188 GAME_OPTION_BOTVSPLAYER = 32;
189 GAME_OPTION_BOTVSMONSTER = 64;
190 GAME_OPTION_DMKEYS = 128;
191 GAME_OPTION_TEAMHITTRACE = 256;
192 GAME_OPTION_TEAMHITPROJECTILE = 512;
193 GAME_OPTION_TEAMABSORBDAMAGE = 1024;
195 STATE_NONE = 0;
196 STATE_MENU = 1;
197 STATE_FOLD = 2;
198 STATE_INTERCUSTOM = 3;
199 STATE_INTERSINGLE = 4;
200 STATE_INTERTEXT = 5;
201 STATE_INTERPIC = 6;
202 STATE_ENDPIC = 7;
203 STATE_SLIST = 8;
205 LMS_RESPAWN_NONE = 0;
206 LMS_RESPAWN_WARMUP = 1;
207 LMS_RESPAWN_FINAL = 2;
209 SPECT_NONE = 0;
210 SPECT_STATS = 1;
211 SPECT_MAPVIEW = 2;
212 SPECT_PLAYERS = 3;
214 DE_GLOBEVENT = 0;
215 DE_BFGHIT = 1;
216 DE_KILLCOMBO = 2;
217 DE_BODYKILL = 3;
219 ANNOUNCE_NONE = 0;
220 ANNOUNCE_ME = 1;
221 ANNOUNCE_MEPLUS = 2;
222 ANNOUNCE_ALL = 3;
224 CONFIG_FILENAME = 'Doom2DF.cfg';
226 TEST_MAP_NAME = '$$$_TEST_$$$';
228 STD_PLAYER_MODEL = 'Doomer';
230 {$IFDEF HEADLESS}
231 DEFAULT_PLAYERS = 0;
232 {$ELSE}
233 DEFAULT_PLAYERS = 1;
234 {$ENDIF}
236 STATFILE_VERSION = $03;
238 var
239 gStdFont: DWORD;
240 gGameSettings: TGameSettings;
241 gPlayer1Settings: TPlayerSettings;
242 gPlayer2Settings: TPlayerSettings;
243 gGameOn: Boolean;
244 gPlayerScreenSize: TDFPoint;
245 gPlayer1ScreenCoord: TDFPoint;
246 gPlayer2ScreenCoord: TDFPoint;
247 gPlayer1: TPlayer = nil;
248 gPlayer2: TPlayer = nil;
249 gPlayerDrawn: TPlayer = nil;
250 gTime: LongWord;
251 gLerpFactor: Single = 1.0;
252 gSwitchGameMode: Byte = GM_DM;
253 gHearPoint1, gHearPoint2: THearPoint;
254 gSoundEffectsDF: Boolean = False;
255 gSoundTriggerTime: Word = 0;
256 gAnnouncer: Integer = ANNOUNCE_NONE;
257 goodsnd: array[0..3] of TPlayableSound;
258 killsnd: array[0..3] of TPlayableSound;
259 hahasnd: array[0..2] of TPlayableSound;
260 sound_get_flag: array[0..1] of TPlayableSound;
261 sound_lost_flag: array[0..1] of TPlayableSound;
262 sound_ret_flag: array[0..1] of TPlayableSound;
263 sound_cap_flag: array[0..1] of TPlayableSound;
264 gBodyKillEvent: Integer = -1;
265 gDefInterTime: ShortInt = -1;
266 gInterEndTime: LongWord = 0;
267 gInterTime: LongWord = 0;
268 gServInterTime: Byte = 0;
269 gGameStartTime: LongWord = 0;
270 gTotalMonsters: Integer = 0;
271 gPauseMain: Boolean = false;
272 gPauseHolmes: Boolean = false;
273 gShowTime: Boolean = False;
274 gShowFPS: Boolean = False;
275 gShowGoals: Boolean = True;
276 gShowStat: Boolean = True;
277 gShowPIDs: Boolean = False;
278 gShowKillMsg: Boolean = True;
279 gShowLives: Boolean = True;
280 gShowPing: Boolean = False;
281 gShowMap: Boolean = False;
282 gExit: Byte = 0;
283 gState: Byte = STATE_NONE;
284 sX, sY: Integer;
285 sWidth, sHeight: Word;
286 gSpectMode: Byte = SPECT_NONE;
287 gSpectHUD: Boolean = True;
288 gSpectKeyPress: Boolean = False;
289 gSpectX: Integer = 0;
290 gSpectY: Integer = 0;
291 gSpectStep: Byte = 8;
292 gSpectViewTwo: Boolean = False;
293 gSpectPID1: Integer = -1;
294 gSpectPID2: Integer = -1;
295 gSpectAuto: Boolean = False;
296 gSpectAutoNext: LongWord;
297 gSpectAutoStepX: Integer;
298 gSpectAutoStepY: Integer;
299 gMusic: TMusic = nil;
300 gLoadGameMode: Boolean;
301 gCheats: Boolean = False;
302 gMapOnce: Boolean = False;
303 gMapToDelete: String;
304 gTempDelete: Boolean = False;
305 gLastMap: Boolean = False;
306 gScreenWidth: Word;
307 gScreenHeight: Word;
308 gResolutionChange: Boolean = False;
309 gRC_Width, gRC_Height: Integer;
310 gRC_FullScreen, gRC_Maximized: Boolean;
311 gLanguageChange: Boolean = False;
312 gDebugMode: Boolean = False;
313 g_debug_Sounds: Boolean = False;
314 g_debug_Frames: Boolean = False;
315 g_debug_WinMsgs: Boolean = False;
316 g_debug_MonsterOff: Boolean = False;
317 g_debug_BotAIOff: Byte = 0;
318 g_debug_HealthBar: Boolean = False;
319 g_Debug_Player: Boolean = False;
320 gCoopMonstersKilled: Word = 0;
321 gCoopSecretsFound: Word = 0;
322 gCoopTotalMonstersKilled: Word = 0;
323 gCoopTotalSecretsFound: Word = 0;
324 gCoopTotalMonsters: Word = 0;
325 gCoopTotalSecrets: Word = 0;
326 gStatsOff: Boolean = False;
327 gStatsPressed: Boolean = False;
328 gExitByTrigger: Boolean = False;
329 gNextMap: String = '';
330 gLMSRespawn: Byte = LMS_RESPAWN_NONE;
331 gLMSRespawnTime: Cardinal = 0;
332 gLMSSoftSpawn: Boolean = False;
333 gMissionFailed: Boolean = False;
334 gVoteInProgress: Boolean = False;
335 gVotePassed: Boolean = False;
336 gVoteCommand: string = '';
337 gVoteTimer: Cardinal = 0;
338 gVoteCmdTimer: Cardinal = 0;
339 gVoteCount: Integer = 0;
340 gVoteTimeout: Cardinal = 30;
341 gVoted: Boolean = False;
342 gVotesEnabled: Boolean = True;
343 gEvents: Array of TGameEvent;
344 gDelayedEvents: Array of TDelayedEvent;
345 gUseChatSounds: Boolean = True;
346 gChatSounds: Array of TChatSound;
347 gSelectWeapon: Array [0..1, WP_FIRST..WP_LAST] of Boolean; // [player, weapon]
348 gInterReadyCount: Integer = 0;
350 g_dbg_ignore_bounds: Boolean = false;
351 r_smallmap_h: Integer = 0; // 0: left; 1: center; 2: right
352 r_smallmap_v: Integer = 2; // 0: top; 1: center; 2: bottom
354 // move button values:
355 // bits 0-1: l/r state:
356 // 0: neither left, nor right pressed
357 // 1: left pressed
358 // 2: right pressed
359 // bits 4-5: l/r state when strafe was pressed
360 P1MoveButton: Byte = 0;
361 P2MoveButton: Byte = 0;
363 g_profile_frame_update: Boolean = false;
364 g_profile_frame_draw: Boolean = false;
365 g_profile_collision: Boolean = false;
366 g_profile_los: Boolean = false;
367 g_profile_history_size: Integer = 1000;
369 g_rlayer_back: Boolean = true;
370 g_rlayer_step: Boolean = true;
371 g_rlayer_wall: Boolean = true;
372 g_rlayer_door: Boolean = true;
373 g_rlayer_acid1: Boolean = true;
374 g_rlayer_acid2: Boolean = true;
375 g_rlayer_water: Boolean = true;
376 g_rlayer_fore: Boolean = true;
378 wNeedTimeReset: Boolean = false;
380 procedure g_ResetDynlights ();
381 procedure g_AddDynLight (x, y, radius: Integer; r, g, b, a: Single);
382 procedure g_DynLightExplosion (x, y, radius: Integer; r, g, b: Single);
384 function conIsCheatsEnabled (): Boolean; inline;
385 function gPause (): Boolean; inline;
387 type (* private state *)
388 TEndCustomGameStat = record
389 PlayerStat: TPlayerStatArray;
390 TeamStat: TTeamStat;
391 GameTime: LongWord;
392 GameMode: Byte;
393 Map, MapName: String;
394 end;
396 TEndSingleGameStat = record
397 PlayerStat: Array [0..1] of record
398 Kills: Integer;
399 Secrets: Integer;
400 end;
401 GameTime: LongWord;
402 TwoPlayers: Boolean;
403 TotalSecrets: Integer;
404 end;
406 TLoadingStat = record
407 CurValue: Integer;
408 MaxValue: Integer;
409 ShowCount: Integer;
410 Msgs: Array of String;
411 NextMsg: Word;
412 PBarWasHere: Boolean; // did we draw a progress bar for this message?
413 end;
415 TDynLight = record
416 x, y, radius: Integer;
417 r, g, b, a: Single;
418 exploCount: Integer;
419 exploRadius: Integer;
420 end;
422 var (* private state *)
423 CustomStat: TEndCustomGameStat;
424 StatShotDone: Boolean;
425 StatFilename: string = ''; // used by stat screenshot to save with the same name as the csv
426 SingleStat: TEndSingleGameStat;
427 hasPBarGfx: Boolean;
428 LoadingStat: TLoadingStat;
429 MessageText: String;
430 IsDrawStat: Boolean;
431 EndingGameCounter: Byte;
432 UPS: Word;
433 g_playerLight: Boolean;
434 g_dynLights: array of TDynLight = nil;
435 g_dynLightCount: Integer = 0;
437 implementation
439 uses
440 {$IFDEF ENABLE_HOLMES}
441 g_holmes,
442 {$ENDIF}
443 e_res, g_textures, g_window, g_menu,
444 e_input, e_log, g_console, r_console, g_items, g_map, g_panel,
445 g_playermodel, g_gfx, g_options, Math,
446 g_triggers, g_monsters, e_sound, CONFIG,
447 g_language, g_net, g_phys,
448 ENet, e_msg, g_netmsg, g_netmaster,
449 sfs, wadreader, g_system, r_playermodel;
451 var
452 charbuff: packed array [0..15] of AnsiChar = (
453 ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' '
454 );
456 function Translit (const S: AnsiString): AnsiString;
457 var
458 i: Integer;
459 begin
460 Result := S;
461 for i := 1 to Length(Result) do
462 begin
463 case Result[i] of
464 #$C9: Result[i] := 'Q';
465 #$D6: Result[i] := 'W';
466 #$D3: Result[i] := 'E';
467 #$CA: Result[i] := 'R';
468 #$C5: Result[i] := 'T';
469 #$CD: Result[i] := 'Y';
470 #$C3: Result[i] := 'U';
471 #$D8: Result[i] := 'I';
472 #$D9: Result[i] := 'O';
473 #$C7: Result[i] := 'P';
474 #$D5: Result[i] := '['; //Chr(219);
475 #$DA: Result[i] := ']'; //Chr(221);
476 #$D4: Result[i] := 'A';
477 #$DB: Result[i] := 'S';
478 #$C2: Result[i] := 'D';
479 #$C0: Result[i] := 'F';
480 #$CF: Result[i] := 'G';
481 #$D0: Result[i] := 'H';
482 #$CE: Result[i] := 'J';
483 #$CB: Result[i] := 'K';
484 #$C4: Result[i] := 'L';
485 #$C6: Result[i] := ';'; //Chr(186);
486 #$DD: Result[i] := #39; //Chr(222);
487 #$DF: Result[i] := 'Z';
488 #$D7: Result[i] := 'X';
489 #$D1: Result[i] := 'C';
490 #$CC: Result[i] := 'V';
491 #$C8: Result[i] := 'B';
492 #$D2: Result[i] := 'N';
493 #$DC: Result[i] := 'M';
494 #$C1: Result[i] := ','; //Chr(188);
495 #$DE: Result[i] := '.'; //Chr(190);
496 end;
497 end;
498 end;
501 function CheckCheat (ct: TStrings_Locale; eofs: Integer=0): Boolean;
502 var
503 ls1, ls2: string;
504 begin
505 ls1 := CheatEng[ct];
506 ls2 := Translit(CheatRus[ct]);
507 if length(ls1) = 0 then ls1 := '~';
508 if length(ls2) = 0 then ls2 := '~';
509 result :=
510 (Copy(charbuff, 17-Length(ls1)-eofs, Length(ls1)) = ls1) or
511 (Translit(Copy(charbuff, 17-Length(ls1)-eofs, Length(ls1))) = ls1) or
512 (Copy(charbuff, 17-Length(ls2)-eofs, Length(ls2)) = ls2) or
513 (Translit(Copy(charbuff, 17-Length(ls2)-eofs, Length(ls2))) = ls2);
515 if ct = I_GAME_CHEAT_JETPACK then
516 begin
517 e_WriteLog('ls1: ['+ls1+']', MSG_NOTIFY);
518 e_WriteLog('ls2: ['+ls2+']', MSG_NOTIFY);
519 e_WriteLog('bf0: ['+Copy(charbuff, 17-Length(ls1)-eofs, Length(ls1))+']', MSG_NOTIFY);
520 e_WriteLog('bf1: ['+Translit(Copy(charbuff, 17-Length(ls1)-eofs, Length(ls1)))+']', MSG_NOTIFY);
521 e_WriteLog('bf2: ['+Copy(charbuff, 17-Length(ls2)-eofs, Length(ls2))+']', MSG_NOTIFY);
522 e_WriteLog('bf3: ['+Translit(Copy(charbuff, 17-Length(ls2)-eofs, Length(ls2)))+']', MSG_NOTIFY);
523 end;
525 end;
527 procedure Cheat ();
528 const
529 CHEAT_DAMAGE = 500;
530 label
531 Cheated;
532 var
533 s, s2: string;
534 c: ShortString;
535 a: Integer;
536 begin
538 if (not gGameOn) or (not gCheats) or ((gGameSettings.GameType <> GT_SINGLE) and
539 (gGameSettings.GameMode <> GM_COOP) and (not gDebugMode))
540 or g_Game_IsNet then Exit;
542 if not gGameOn then exit;
543 if not conIsCheatsEnabled then exit;
545 s := 'SOUND_GAME_RADIO';
547 //
548 if CheckCheat(I_GAME_CHEAT_GODMODE) then
549 begin
550 if gPlayer1 <> nil then gPlayer1.GodMode := not gPlayer1.GodMode;
551 if gPlayer2 <> nil then gPlayer2.GodMode := not gPlayer2.GodMode;
552 goto Cheated;
553 end;
554 // RAMBO
555 if CheckCheat(I_GAME_CHEAT_WEAPONS) then
556 begin
557 if gPlayer1 <> nil then gPlayer1.AllRulez(False);
558 if gPlayer2 <> nil then gPlayer2.AllRulez(False);
559 goto Cheated;
560 end;
561 // TANK
562 if CheckCheat(I_GAME_CHEAT_HEALTH) then
563 begin
564 if gPlayer1 <> nil then gPlayer1.AllRulez(True);
565 if gPlayer2 <> nil then gPlayer2.AllRulez(True);
566 goto Cheated;
567 end;
568 // IDDQD
569 if CheckCheat(I_GAME_CHEAT_DEATH) then
570 begin
571 if gPlayer1 <> nil then gPlayer1.Damage(CHEAT_DAMAGE, 0, 0, 0, HIT_TRAP);
572 if gPlayer2 <> nil then gPlayer2.Damage(CHEAT_DAMAGE, 0, 0, 0, HIT_TRAP);
573 s := 'SOUND_MONSTER_HAHA';
574 goto Cheated;
575 end;
576 //
577 if CheckCheat(I_GAME_CHEAT_DOORS) then
578 begin
579 g_Triggers_OpenAll();
580 goto Cheated;
581 end;
582 // GOODBYE
583 if CheckCheat(I_GAME_CHEAT_NEXTMAP) then
584 begin
585 if gTriggers <> nil then
586 for a := 0 to High(gTriggers) do
587 if gTriggers[a].TriggerType = TRIGGER_EXIT then
588 begin
589 gExitByTrigger := True;
590 //g_Game_ExitLevel(gTriggers[a].Data.MapName);
591 g_Game_ExitLevel(gTriggers[a].tgcMap);
592 Break;
593 end;
594 goto Cheated;
595 end;
596 //
597 s2 := Copy(charbuff, 15, 2);
598 if CheckCheat(I_GAME_CHEAT_CHANGEMAP, 2) and (s2[1] >= '0') and (s2[1] <= '9') and (s2[2] >= '0') and (s2[2] <= '9') then
599 begin
600 if g_Map_Exist(gGameSettings.WAD + ':\MAP' + s2) then
601 begin
602 c := 'MAP' + s2;
603 g_Game_ExitLevel(c);
604 end;
605 goto Cheated;
606 end;
607 //
608 if CheckCheat(I_GAME_CHEAT_FLY) then
609 begin
610 gFly := not gFly;
611 goto Cheated;
612 end;
613 // BULLFROG
614 if CheckCheat(I_GAME_CHEAT_JUMPS) then
615 begin
616 VEL_JUMP := 30-VEL_JUMP;
617 goto Cheated;
618 end;
619 // FORMULA1
620 if CheckCheat(I_GAME_CHEAT_SPEED) then
621 begin
622 MAX_RUNVEL := 32-MAX_RUNVEL;
623 goto Cheated;
624 end;
625 // CONDOM
626 if CheckCheat(I_GAME_CHEAT_SUIT) then
627 begin
628 if gPlayer1 <> nil then gPlayer1.GiveItem(ITEM_SUIT);
629 if gPlayer2 <> nil then gPlayer2.GiveItem(ITEM_SUIT);
630 goto Cheated;
631 end;
632 //
633 if CheckCheat(I_GAME_CHEAT_AIR) then
634 begin
635 if gPlayer1 <> nil then gPlayer1.GiveItem(ITEM_OXYGEN);
636 if gPlayer2 <> nil then gPlayer2.GiveItem(ITEM_OXYGEN);
637 goto Cheated;
638 end;
639 // PURELOVE
640 if CheckCheat(I_GAME_CHEAT_BERSERK) then
641 begin
642 if gPlayer1 <> nil then gPlayer1.GiveItem(ITEM_MEDKIT_BLACK);
643 if gPlayer2 <> nil then gPlayer2.GiveItem(ITEM_MEDKIT_BLACK);
644 goto Cheated;
645 end;
646 //
647 if CheckCheat(I_GAME_CHEAT_JETPACK) then
648 begin
649 if gPlayer1 <> nil then gPlayer1.GiveItem(ITEM_JETPACK);
650 if gPlayer2 <> nil then gPlayer2.GiveItem(ITEM_JETPACK);
651 goto Cheated;
652 end;
653 // CASPER
654 if CheckCheat(I_GAME_CHEAT_NOCLIP) then
655 begin
656 if gPlayer1 <> nil then gPlayer1.SwitchNoClip;
657 if gPlayer2 <> nil then gPlayer2.SwitchNoClip;
658 goto Cheated;
659 end;
660 //
661 if CheckCheat(I_GAME_CHEAT_NOTARGET) then
662 begin
663 if gPlayer1 <> nil then gPlayer1.NoTarget := not gPlayer1.NoTarget;
664 if gPlayer2 <> nil then gPlayer2.NoTarget := not gPlayer2.NoTarget;
665 goto Cheated;
666 end;
667 // INFERNO
668 if CheckCheat(I_GAME_CHEAT_NORELOAD) then
669 begin
670 if gPlayer1 <> nil then gPlayer1.NoReload := not gPlayer1.NoReload;
671 if gPlayer2 <> nil then gPlayer2.NoReload := not gPlayer2.NoReload;
672 goto Cheated;
673 end;
674 if CheckCheat(I_GAME_CHEAT_AIMLINE) then
675 begin
676 gAimLine := not gAimLine;
677 goto Cheated;
678 end;
679 if CheckCheat(I_GAME_CHEAT_AUTOMAP) then
680 begin
681 gShowMap := not gShowMap;
682 goto Cheated;
683 end;
684 Exit;
686 Cheated:
687 g_Sound_PlayEx(s);
688 end;
691 procedure KeyPress (K: Word);
692 {$IFNDEF HEADLESS}
693 var
694 Msg: g_gui.TMessage;
695 {$ENDIF}
696 begin
697 {$IFNDEF HEADLESS}
698 case K of
699 VK_ESCAPE: // <Esc>:
700 begin
701 if (g_ActiveWindow <> nil) then
702 begin
703 Msg.Msg := WM_KEYDOWN;
704 Msg.WParam := VK_ESCAPE;
705 g_ActiveWindow.OnMessage(Msg);
706 if (not g_Game_IsNet) and (g_ActiveWindow = nil) then g_Game_Pause(false); //Fn loves to do this
707 end
708 else if (gState <> STATE_FOLD) then
709 begin
710 if gGameOn or (gState = STATE_INTERSINGLE) or (gState = STATE_INTERCUSTOM) then
711 begin
712 g_Game_InGameMenu(True);
713 end
714 else if (gExit = 0) and (gState <> STATE_SLIST) then
715 begin
716 if (gState <> STATE_MENU) then
717 begin
718 if (NetMode <> NET_NONE) then
719 begin
720 g_Game_StopAllSounds(True);
721 g_Game_Free;
722 gState := STATE_MENU;
723 Exit;
724 end;
725 end;
726 g_GUI_ShowWindow('MainMenu');
727 g_Sound_PlayEx('MENU_OPEN');
728 end;
729 end;
730 end;
732 IK_F2, IK_F3, IK_F4, IK_F5, IK_F6, IK_F7, IK_F10:
733 begin // <F2> .. <F6> � <F12>
734 if gGameOn and (not gConsoleShow) and (not gChatShow) then
735 begin
736 while (g_ActiveWindow <> nil) do g_GUI_HideWindow(False);
737 if (not g_Game_IsNet) then g_Game_Pause(True);
738 case K of
739 IK_F2: g_Menu_Show_SaveMenu();
740 IK_F3: g_Menu_Show_LoadMenu();
741 IK_F4: g_Menu_Show_GameSetGame();
742 IK_F5: g_Menu_Show_OptionsVideo();
743 IK_F6: g_Menu_Show_OptionsSound();
744 IK_F7: g_Menu_Show_EndGameMenu();
745 IK_F10: g_Menu_Show_QuitGameMenu();
746 end;
747 end;
748 end;
750 else
751 begin
752 gJustChatted := False;
753 if gConsoleShow or gChatShow then
754 begin
755 g_Console_Control(K);
756 end
757 else if (g_ActiveWindow <> nil) then
758 begin
759 Msg.Msg := WM_KEYDOWN;
760 Msg.WParam := K;
761 g_ActiveWindow.OnMessage(Msg);
762 end
763 else if (gState = STATE_MENU) then
764 begin
765 g_GUI_ShowWindow('MainMenu');
766 g_Sound_PlayEx('MENU_OPEN');
767 end;
768 end;
769 end;
770 {$ENDIF}
771 end;
773 procedure CharPress (C: AnsiChar);
774 var
775 Msg: g_gui.TMessage;
776 a: Integer;
777 begin
778 if gConsoleShow or gChatShow then
779 begin
780 g_Console_Char(C)
781 end
782 else if (g_ActiveWindow <> nil) then
783 begin
784 Msg.Msg := WM_CHAR;
785 Msg.WParam := Ord(C);
786 g_ActiveWindow.OnMessage(Msg);
787 end
788 else
789 begin
790 for a := 0 to 14 do charbuff[a] := charbuff[a+1];
791 charbuff[15] := upcase1251(C);
792 Cheat();
793 end;
794 end;
797 // ////////////////////////////////////////////////////////////////////////// //
798 function gPause (): Boolean; inline; begin result := gPauseMain or gPauseHolmes; end;
800 procedure g_ResetDynlights ();
801 var
802 lnum, idx: Integer;
803 begin
804 if not gwin_has_stencil then begin g_dynLightCount := 0; exit; end;
805 lnum := 0;
806 for idx := 0 to g_dynLightCount-1 do
807 begin
808 if g_dynLights[idx].exploCount = -666 then
809 begin
810 // skip it
811 end
812 else
813 begin
814 // explosion
815 Inc(g_dynLights[idx].exploCount);
816 if (g_dynLights[idx].exploCount < 10) then
817 begin
818 g_dynLights[idx].radius := g_dynLights[idx].exploRadius+g_dynLights[idx].exploCount*8;
819 g_dynLights[idx].a := 0.4+g_dynLights[idx].exploCount/10;
820 if (g_dynLights[idx].a > 0.8) then g_dynLights[idx].a := 0.8;
821 if lnum <> idx then g_dynLights[lnum] := g_dynLights[idx];
822 Inc(lnum);
823 end;
824 end;
825 end;
826 g_dynLightCount := lnum;
827 end;
829 procedure g_AddDynLight (x, y, radius: Integer; r, g, b, a: Single);
830 begin
831 if not gwin_has_stencil then exit;
832 if g_dynLightCount = length(g_dynLights) then SetLength(g_dynLights, g_dynLightCount+1024);
833 g_dynLights[g_dynLightCount].x := x;
834 g_dynLights[g_dynLightCount].y := y;
835 g_dynLights[g_dynLightCount].radius := radius;
836 g_dynLights[g_dynLightCount].r := r;
837 g_dynLights[g_dynLightCount].g := g;
838 g_dynLights[g_dynLightCount].b := b;
839 g_dynLights[g_dynLightCount].a := a;
840 g_dynLights[g_dynLightCount].exploCount := -666;
841 Inc(g_dynLightCount);
842 end;
844 procedure g_DynLightExplosion (x, y, radius: Integer; r, g, b: Single);
845 begin
846 if not gwin_has_stencil then exit;
847 if g_dynLightCount = length(g_dynLights) then SetLength(g_dynLights, g_dynLightCount+1024);
848 g_dynLights[g_dynLightCount].x := x;
849 g_dynLights[g_dynLightCount].y := y;
850 g_dynLights[g_dynLightCount].radius := 0;
851 g_dynLights[g_dynLightCount].exploRadius := radius;
852 g_dynLights[g_dynLightCount].r := r;
853 g_dynLights[g_dynLightCount].g := g;
854 g_dynLights[g_dynLightCount].b := b;
855 g_dynLights[g_dynLightCount].a := 0;
856 g_dynLights[g_dynLightCount].exploCount := 0;
857 Inc(g_dynLightCount);
858 end;
860 // ////////////////////////////////////////////////////////////////////////// //
861 function conIsCheatsEnabled (): Boolean; inline;
862 begin
863 result := false;
864 if g_Game_IsNet then exit;
865 if not gDebugMode then
866 begin
867 //if not gCheats then exit;
868 if not (gGameSettings.GameType in [GT_SINGLE, GT_CUSTOM]) then exit;
869 if not (gGameSettings.GameMode in [GM_COOP, GM_SINGLE]) then exit;
870 end;
871 result := true;
872 end;
874 // ////////////////////////////////////////////////////////////////////////// //
875 type
876 TParamStrValue = record
877 Name: String;
878 Value: String;
879 end;
881 TParamStrValues = Array of TParamStrValue;
883 const
884 INTER_ACTION_TEXT = 1;
885 INTER_ACTION_PIC = 2;
886 INTER_ACTION_MUSIC = 3;
888 var
889 UPSCounter: Word;
890 UPSTime: LongWord;
891 DataLoaded: Boolean = False;
892 MessageTime: Word;
893 MessageLineLength: Integer = 80;
894 MapList: SSArray = nil;
895 MapIndex: Integer = -1;
896 InterReadyTime: Integer = -1;
897 StatDate: string = '';
898 MegaWAD: record
899 info: TMegaWADInfo;
900 endpic: String;
901 endmus: String;
902 res: record
903 text: Array of ShortString;
904 anim: Array of ShortString;
905 pic: Array of ShortString;
906 mus: Array of ShortString;
907 end;
908 triggers: Array of record
909 event: ShortString;
910 actions: Array of record
911 action, p1, p2: Integer;
912 end;
913 end;
914 cur_trigger: Integer;
915 cur_action: Integer;
916 end;
917 //InterPic: String;
918 InterText: record
919 lines: SSArray;
920 img: String;
921 cur_line: Integer;
922 cur_char: Integer;
923 counter: Integer;
924 endtext: Boolean;
925 end;
927 function Compare(a, b: TPlayerStat): Integer;
928 begin
929 if a.Spectator then Result := 1
930 else if b.Spectator then Result := -1
931 else if a.Frags < b.Frags then Result := 1
932 else if a.Frags > b.Frags then Result := -1
933 else if a.Deaths < b.Deaths then Result := -1
934 else if a.Deaths > b.Deaths then Result := 1
935 else if a.Kills < b.Kills then Result := -1
936 else Result := 1;
937 end;
939 procedure SortGameStat(var stat: TPlayerStatArray);
940 var
941 I, J: Integer;
942 T: TPlayerStat;
943 begin
944 if stat = nil then Exit;
946 for I := High(stat) downto Low(stat) do
947 for J := Low(stat) to High(stat) - 1 do
948 if Compare(stat[J], stat[J + 1]) = 1 then
949 begin
950 T := stat[J];
951 stat[J] := stat[J + 1];
952 stat[J + 1] := T;
953 end;
954 end;
956 // saves a shitty CSV containing the game stats passed to it
957 procedure SaveGameStat(Stat: TEndCustomGameStat; Path: string);
958 var
959 s: TextFile;
960 dir, fname, map, mode, etime: String;
961 I: Integer;
962 begin
963 try
964 dir := e_GetWriteableDir(StatsDirs);
965 // stats are placed in stats/yy/mm/dd/*.csv
966 fname := e_CatPath(dir, Path);
967 ForceDirectories(fname); // ensure yy/mm/dd exists within the stats dir
968 fname := e_CatPath(fname, StatFilename + '.csv');
969 AssignFile(s, fname);
970 try
971 Rewrite(s);
972 // line 1: stats ver, datetime, server name, map name, game mode, time limit, score limit, dmflags, game time, num players
973 if g_Game_IsNet then fname := NetServerName else fname := '';
974 map := g_ExtractWadNameNoPath(gMapInfo.Map) + ':/' + g_ExtractFileName(gMapInfo.Map);
975 mode := g_Game_ModeToText(Stat.GameMode);
976 etime := Format('%d:%.2d:%.2d', [
977 Stat.GameTime div 1000 div 3600,
978 (Stat.GameTime div 1000 div 60) mod 60,
979 Stat.GameTime div 1000 mod 60
980 ]);
981 WriteLn(s, 'stats_ver,datetime,server,map,mode,timelimit,scorelimit,dmflags,time,num_players');
982 WriteLn(s, Format('%d,%s,%s,%s,%s,%u,%u,%u,%s,%d', [
983 STATFILE_VERSION,
984 StatDate,
985 dquoteStr(fname),
986 dquoteStr(map),
987 mode,
988 gGameSettings.TimeLimit,
989 gGameSettings.GoalLimit,
990 gGameSettings.Options,
991 etime,
992 Length(Stat.PlayerStat)
993 ]));
994 // line 2: game specific shit
995 // if it's a team game: red score, blue score
996 // if it's a coop game: monsters killed, monsters total, secrets found, secrets total
997 // otherwise nothing
998 if Stat.GameMode in [GM_TDM, GM_CTF] then
999 WriteLn(s,
1000 Format('red_score,blue_score' + LineEnding + '%d,%d', [Stat.TeamStat[TEAM_RED].Goals, Stat.TeamStat[TEAM_BLUE].Goals]))
1001 else if Stat.GameMode in [GM_COOP, GM_SINGLE] then
1002 WriteLn(s,
1003 Format('mon_killed,mon_total,secrets_found,secrets_total' + LineEnding + '%d,%d,%d,%d',[gCoopMonstersKilled, gTotalMonsters, gCoopSecretsFound, gSecretsCount]));
1004 // lines 3-...: team, player name, frags, deaths
1005 WriteLn(s, 'team,name,frags,deaths');
1006 for I := Low(Stat.PlayerStat) to High(Stat.PlayerStat) do
1007 with Stat.PlayerStat[I] do
1008 WriteLn(s, Format('%d,%s,%d,%d', [Team, dquoteStr(Name), Frags, Deaths]));
1009 except
1010 g_Console_Add(Format(_lc[I_CONSOLE_ERROR_WRITE], [fname]));
1011 end;
1012 except
1013 g_Console_Add('could not create gamestats file "' + fname + '"');
1014 end;
1015 CloseFile(s);
1016 end;
1018 function g_Game_ModeToText(Mode: Byte): string;
1019 begin
1020 Result := '';
1021 case Mode of
1022 GM_DM: Result := _lc[I_MENU_GAME_TYPE_DM];
1023 GM_TDM: Result := _lc[I_MENU_GAME_TYPE_TDM];
1024 GM_CTF: Result := _lc[I_MENU_GAME_TYPE_CTF];
1025 GM_COOP: Result := _lc[I_MENU_GAME_TYPE_COOP];
1026 GM_SINGLE: Result := _lc[I_MENU_GAME_TYPE_SINGLE];
1027 end;
1028 end;
1030 function g_Game_TextToMode(Mode: string): Byte;
1031 begin
1032 Result := GM_NONE;
1033 Mode := UpperCase(Mode);
1034 if Mode = _lc[I_MENU_GAME_TYPE_DM] then
1035 begin
1036 Result := GM_DM;
1037 Exit;
1038 end;
1039 if Mode = _lc[I_MENU_GAME_TYPE_TDM] then
1040 begin
1041 Result := GM_TDM;
1042 Exit;
1043 end;
1044 if Mode = _lc[I_MENU_GAME_TYPE_CTF] then
1045 begin
1046 Result := GM_CTF;
1047 Exit;
1048 end;
1049 if Mode = _lc[I_MENU_GAME_TYPE_COOP] then
1050 begin
1051 Result := GM_COOP;
1052 Exit;
1053 end;
1054 if Mode = _lc[I_MENU_GAME_TYPE_SINGLE] then
1055 begin
1056 Result := GM_SINGLE;
1057 Exit;
1058 end;
1059 end;
1061 function g_Game_IsNet(): Boolean;
1062 begin
1063 Result := (gGameSettings.GameType in [GT_SERVER, GT_CLIENT]);
1064 end;
1066 function g_Game_IsServer(): Boolean;
1067 begin
1068 Result := (gGameSettings.GameType in [GT_SINGLE, GT_CUSTOM, GT_SERVER]);
1069 end;
1071 function g_Game_IsClient(): Boolean;
1072 begin
1073 Result := (gGameSettings.GameType = GT_CLIENT);
1074 end;
1076 function g_Game_GetMegaWADInfo(WAD: String): TMegaWADInfo;
1077 var
1078 w: TWADFile;
1079 cfg: TConfig;
1080 p: Pointer;
1081 len: Integer;
1082 begin
1083 Result.name := ExtractFileName(WAD);
1084 Result.description := '';
1085 Result.author := '';
1087 w := TWADFile.Create();
1088 w.ReadFile(WAD);
1090 if not w.GetResource('INTERSCRIPT', p, len) then
1091 begin
1092 w.Free();
1093 Exit;
1094 end;
1096 cfg := TConfig.CreateMem(p, len);
1097 Result.name := cfg.ReadStr('megawad', 'name', ExtractFileName(WAD));
1098 Result.description := cfg.ReadStr('megawad', 'description', '');
1099 Result.author := cfg.ReadStr('megawad', 'author', '');
1100 Result.pic := cfg.ReadStr('megawad', 'pic', '');
1101 cfg.Free();
1103 FreeMem(p);
1104 end;
1106 procedure g_Game_FreeWAD();
1107 var
1108 a: Integer;
1109 begin
1110 for a := 0 to High(MegaWAD.res.pic) do
1111 if MegaWAD.res.pic[a] <> '' then
1112 g_Texture_Delete(MegaWAD.res.pic[a]);
1114 for a := 0 to High(MegaWAD.res.mus) do
1115 if MegaWAD.res.mus[a] <> '' then
1116 g_Sound_Delete(MegaWAD.res.mus[a]);
1118 MegaWAD.res.pic := nil;
1119 MegaWAD.res.text := nil;
1120 MegaWAD.res.anim := nil;
1121 MegaWAD.res.mus := nil;
1122 MegaWAD.triggers := nil;
1124 g_Texture_Delete('TEXTURE_endpic');
1125 g_Sound_Delete('MUSIC_endmus');
1127 ZeroMemory(@MegaWAD, SizeOf(MegaWAD));
1128 gGameSettings.WAD := '';
1129 end;
1131 procedure g_Game_LoadWAD(WAD: string);
1132 var
1133 w: TWADFile;
1134 cfg: TConfig;
1135 p: Pointer;
1136 {b, }len: Integer;
1137 s: AnsiString;
1138 begin
1139 g_Game_FreeWAD();
1140 gGameSettings.WAD := WAD;
1141 if not (gGameSettings.GameMode in [GM_COOP, GM_SINGLE]) then
1142 Exit;
1144 MegaWAD.info := g_Game_GetMegaWADInfo(WAD);
1146 w := TWADFile.Create();
1147 w.ReadFile(WAD);
1149 if not w.GetResource('INTERSCRIPT', p, len) then
1150 begin
1151 w.Free();
1152 Exit;
1153 end;
1155 cfg := TConfig.CreateMem(p, len);
1157 {b := 1;
1158 while True do
1159 begin
1160 s := cfg.ReadStr('pic', 'pic'+IntToStr(b), '');
1161 if s = '' then Break;
1162 b := b+1;
1164 SetLength(MegaWAD.res.pic, Length(MegaWAD.res.pic)+1);
1165 MegaWAD.res.pic[High(MegaWAD.res.pic)] := s;
1167 g_Texture_CreateWADEx(s, s);
1168 end;
1170 b := 1;
1171 while True do
1172 begin
1173 s := cfg.ReadStr('mus', 'mus'+IntToStr(b), '');
1174 if s = '' then Break;
1175 b := b+1;
1177 SetLength(MegaWAD.res.mus, Length(MegaWAD.res.mus)+1);
1178 MegaWAD.res.mus[High(MegaWAD.res.mus)] := s;
1180 g_Music_CreateWADEx(s, s);
1181 end;}
1183 MegaWAD.endpic := cfg.ReadStr('megawad', 'endpic', '');
1184 if MegaWAD.endpic <> '' then
1185 begin
1186 s := e_GetResourcePath(WadDirs, MegaWAD.endpic, WAD);
1187 g_Texture_CreateWADEx('TEXTURE_endpic', s, gTextureFilter);
1188 end;
1189 MegaWAD.endmus := cfg.ReadStr('megawad', 'endmus', 'Standart.wad:D2DMUS\КОНЕЦ');
1190 if MegaWAD.endmus <> '' then
1191 begin
1192 s := e_GetResourcePath(WadDirs, MegaWAD.endmus, WAD);
1193 g_Sound_CreateWADEx('MUSIC_endmus', s, True);
1194 end;
1196 cfg.Free();
1197 FreeMem(p);
1198 w.Free();
1199 end;
1201 {procedure start_trigger(t: string);
1202 begin
1203 end;
1205 function next_trigger(): Boolean;
1206 begin
1207 end;}
1209 procedure DisableCheats();
1210 begin
1211 MAX_RUNVEL := 8;
1212 VEL_JUMP := 10;
1213 gFly := False;
1215 if gPlayer1 <> nil then gPlayer1.GodMode := False;
1216 if gPlayer2 <> nil then gPlayer2.GodMode := False;
1217 if gPlayer1 <> nil then gPlayer1.NoTarget := False;
1218 if gPlayer2 <> nil then gPlayer2.NoTarget := False;
1220 {$IF DEFINED(D2F_DEBUG)}
1221 if gPlayer1 <> nil then gPlayer1.NoTarget := True;
1222 gAimLine := g_dbg_aimline_on;
1223 {$ENDIF}
1224 end;
1226 procedure g_Game_ExecuteEvent(Name: String);
1227 var
1228 a: Integer;
1229 begin
1230 if Name = '' then
1231 Exit;
1232 if gEvents = nil then
1233 Exit;
1234 for a := 0 to High(gEvents) do
1235 if gEvents[a].Name = Name then
1236 begin
1237 if gEvents[a].Command <> '' then
1238 g_Console_Process(gEvents[a].Command, True);
1239 break;
1240 end;
1241 end;
1243 function g_Game_DelayEvent(DEType: Byte; Time: LongWord; Num: Integer = 0; Str: String = ''): Integer;
1244 var
1245 a, n: Integer;
1246 begin
1247 n := -1;
1248 if gDelayedEvents <> nil then
1249 for a := 0 to High(gDelayedEvents) do
1250 if not gDelayedEvents[a].Pending then
1251 begin
1252 n := a;
1253 break;
1254 end;
1255 if n = -1 then
1256 begin
1257 SetLength(gDelayedEvents, Length(gDelayedEvents) + 1);
1258 n := High(gDelayedEvents);
1259 end;
1260 gDelayedEvents[n].Pending := True;
1261 gDelayedEvents[n].DEType := DEType;
1262 gDelayedEvents[n].DENum := Num;
1263 gDelayedEvents[n].DEStr := Str;
1264 if DEType = DE_GLOBEVENT then
1265 gDelayedEvents[n].Time := (sys_GetTicks() {div 1000}) + Time
1266 else
1267 gDelayedEvents[n].Time := gTime + Time;
1268 Result := n;
1269 end;
1271 procedure EndGame();
1272 var
1273 a: Integer;
1274 FileName: string;
1275 t: TDateTime;
1276 begin
1277 if g_Game_IsNet and g_Game_IsServer then
1278 MH_SEND_GameEvent(NET_EV_MAPEND, Byte(gMissionFailed));
1280 // Стоп игра:
1281 gPauseMain := false;
1282 gPauseHolmes := false;
1283 gGameOn := false;
1285 g_Game_StopAllSounds(False);
1287 MessageTime := 0;
1288 MessageText := '';
1290 EndingGameCounter := 0;
1291 g_ActiveWindow := nil;
1293 gLMSRespawn := LMS_RESPAWN_NONE;
1294 gLMSRespawnTime := 0;
1296 case gExit of
1297 EXIT_SIMPLE: // Выход через меню или конец теста
1298 begin
1299 g_Game_Free();
1301 if gMapOnce then
1302 begin // Это был тест
1303 g_Game_Quit();
1304 end
1305 else
1306 begin // Выход в главное меню
1307 gMusic.SetByName('MUSIC_MENU');
1308 gMusic.Play();
1309 if gState <> STATE_SLIST then
1310 begin
1311 g_GUI_ShowWindow('MainMenu');
1312 gState := STATE_MENU;
1313 end else
1314 begin
1315 // Обновляем список серверов
1316 slReturnPressed := True;
1317 if g_Net_Slist_Fetch(slCurrent) then
1318 begin
1319 if slCurrent = nil then
1320 slWaitStr := _lc[I_NET_SLIST_NOSERVERS];
1321 end
1322 else
1323 slWaitStr := _lc[I_NET_SLIST_ERROR];
1324 g_Serverlist_GenerateTable(slCurrent, slTable);
1325 end;
1327 g_Game_ExecuteEvent('ongameend');
1328 end;
1329 end;
1331 EXIT_RESTART: // Начать уровень сначала
1332 begin
1333 if not g_Game_IsClient then g_Game_Restart();
1334 end;
1336 EXIT_ENDLEVELCUSTOM: // Закончился уровень в Своей игре
1337 begin
1338 // Статистика Своей игры:
1339 FileName := g_ExtractWadName(gMapInfo.Map);
1341 CustomStat.GameTime := gTime;
1342 CustomStat.Map := ExtractFileName(FileName)+':'+g_ExtractFileName(gMapInfo.Map); //ResName;
1343 CustomStat.MapName := gMapInfo.Name;
1344 CustomStat.GameMode := gGameSettings.GameMode;
1345 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
1346 CustomStat.TeamStat := gTeamStat;
1348 CustomStat.PlayerStat := nil;
1350 // Статистика игроков:
1351 if gPlayers <> nil then
1352 begin
1353 for a := 0 to High(gPlayers) do
1354 if gPlayers[a] <> nil then
1355 begin
1356 SetLength(CustomStat.PlayerStat, Length(CustomStat.PlayerStat)+1);
1357 with CustomStat.PlayerStat[High(CustomStat.PlayerStat)] do
1358 begin
1359 Num := a;
1360 Name := gPlayers[a].Name;
1361 Frags := gPlayers[a].Frags;
1362 Deaths := gPlayers[a].Death;
1363 Kills := gPlayers[a].Kills;
1364 Team := gPlayers[a].Team;
1365 Color := gPlayers[a].Model.Color;
1366 Spectator := gPlayers[a].FSpectator;
1367 end;
1368 end;
1370 SortGameStat(CustomStat.PlayerStat);
1372 if (gSaveStats or gScreenshotStats) and (Length(CustomStat.PlayerStat) > 1) then
1373 begin
1374 t := Now;
1375 if g_Game_IsNet then StatFilename := NetServerName else StatFilename := 'local';
1376 StatDate := FormatDateTime('yymmdd_hhnnss', t);
1377 StatFilename := StatFilename + '_' + CustomStat.Map + '_' + g_Game_ModeToText(CustomStat.GameMode);
1378 StatFilename := sanitizeFilename(StatFilename) + '_' + StatDate;
1379 if gSaveStats then
1380 SaveGameStat(CustomStat, FormatDateTime('yyyy"/"mm"/"dd', t));
1381 end;
1383 StatShotDone := False;
1384 end;
1386 g_Game_ExecuteEvent('onmapend');
1387 if not g_Game_IsClient then g_Player_ResetReady;
1388 gInterReadyCount := 0;
1390 // Затухающий экран:
1391 EndingGameCounter := 255;
1392 gState := STATE_FOLD;
1393 gInterTime := 0;
1394 if gDefInterTime < 0 then
1395 gInterEndTime := IfThen((gGameSettings.GameType = GT_SERVER) and (gPlayer1 = nil), 15000, 25000)
1396 else
1397 gInterEndTime := gDefInterTime * 1000;
1398 end;
1400 EXIT_ENDLEVELSINGLE: // Закончился уровень в Одиночной игре
1401 begin
1402 // Статистика Одиночной игры:
1403 SingleStat.GameTime := gTime;
1404 SingleStat.TwoPlayers := gPlayer2 <> nil;
1405 SingleStat.TotalSecrets := gSecretsCount;
1406 // Статистика первого игрока:
1407 SingleStat.PlayerStat[0].Kills := gPlayer1.MonsterKills;
1408 SingleStat.PlayerStat[0].Secrets := gPlayer1.Secrets;
1409 // Статистика второго игрока (если есть):
1410 if SingleStat.TwoPlayers then
1411 begin
1412 SingleStat.PlayerStat[1].Kills := gPlayer2.MonsterKills;
1413 SingleStat.PlayerStat[1].Secrets := gPlayer2.Secrets;
1414 end;
1416 g_Game_ExecuteEvent('onmapend');
1418 // Есть еще карты:
1419 if gNextMap <> '' then
1420 begin
1421 gMusic.SetByName('MUSIC_INTERMUS');
1422 gMusic.Play();
1423 gState := STATE_INTERSINGLE;
1424 e_UnpressAllKeys();
1426 g_Game_ExecuteEvent('oninter');
1427 end
1428 else // Больше нет карт
1429 begin
1430 // Затухающий экран:
1431 EndingGameCounter := 255;
1432 gState := STATE_FOLD;
1433 end;
1434 end;
1435 end;
1437 // Окончание обработано:
1438 if gExit <> EXIT_QUIT then
1439 gExit := 0;
1440 end;
1442 procedure g_Game_Init();
1443 var
1444 SR: TSearchRec;
1445 knownFiles: array of AnsiString = nil;
1446 found: Boolean;
1447 wext, s: AnsiString;
1448 f: Integer;
1449 begin
1450 gExit := 0;
1451 gMapToDelete := '';
1452 gTempDelete := False;
1454 sfsGCDisable(); // temporary disable removing of temporary volumes
1456 try
1457 g_Texture_CreateWADEx('MENU_BACKGROUND', GameWAD+':TEXTURES\TITLE', gTextureFilter);
1458 g_Texture_CreateWADEx('INTER', GameWAD+':TEXTURES\INTER', gTextureFilter);
1459 g_Texture_CreateWADEx('ENDGAME_EN', GameWAD+':TEXTURES\ENDGAME_EN', gTextureFilter);
1460 g_Texture_CreateWADEx('ENDGAME_RU', GameWAD+':TEXTURES\ENDGAME_RU', gTextureFilter);
1462 LoadStdFont('STDTXT', 'STDFONT', gStdFont);
1463 LoadFont('MENUTXT', 'MENUFONT', gMenuFont);
1464 LoadFont('SMALLTXT', 'SMALLFONT', gMenuSmallFont);
1466 g_Game_ClearLoading();
1467 g_Game_SetLoadingText(Format('Doom 2D: Forever %s', [GAME_VERSION]), 0, False);
1468 g_Game_SetLoadingText('', 0, False);
1470 g_Game_SetLoadingText(_lc[I_LOAD_MODELS], 0, False);
1471 // load models from all possible wad types, in all known directories
1472 // this does a loosy job (linear search, ooph!), but meh
1473 for wext in wadExtensions do
1474 begin
1475 for f := High(ModelDirs) downto Low(ModelDirs) do
1476 begin
1477 if (FindFirst(ModelDirs[f]+DirectorySeparator+'*'+wext, faAnyFile, SR) = 0) then
1478 begin
1479 repeat
1480 found := false;
1481 for s in knownFiles do
1482 begin
1483 if (strEquCI1251(forceFilenameExt(SR.Name, ''), forceFilenameExt(ExtractFileName(s), ''))) then
1484 begin
1485 found := true;
1486 break;
1487 end;
1488 end;
1489 if not found then
1490 begin
1491 SetLength(knownFiles, length(knownFiles)+1);
1492 knownFiles[High(knownFiles)] := ModelDirs[f]+DirectorySeparator+SR.Name;
1493 end;
1494 until (FindNext(SR) <> 0);
1495 end;
1496 FindClose(SR);
1497 end;
1498 end;
1500 if (length(knownFiles) = 0) then raise Exception.Create('no player models found!');
1502 if (length(knownFiles) = 1) then e_LogWriteln('1 player model found.', TMsgType.Notify) else e_LogWritefln('%d player models found.', [Integer(length(knownFiles))], TMsgType.Notify);
1503 for s in knownFiles do
1504 begin
1505 if not g_PlayerModel_Load(s) then e_LogWritefln('Error loading model "%s"', [s], TMsgType.Warning);
1506 end;
1508 gGameOn := false;
1509 gPauseMain := false;
1510 gPauseHolmes := false;
1511 gTime := 0;
1513 {e_MouseInfo.Accel := 1.0;}
1515 g_Game_SetLoadingText(_lc[I_LOAD_GAME_DATA], 0, False);
1516 g_Game_LoadData();
1518 g_Game_SetLoadingText(_lc[I_LOAD_MUSIC], 0, False);
1519 g_Sound_CreateWADEx('MUSIC_INTERMUS', GameWAD+':MUSIC\INTERMUS', True);
1520 g_Sound_CreateWADEx('MUSIC_MENU', GameWAD+':MUSIC\MENU', True);
1521 g_Sound_CreateWADEx('MUSIC_ROUNDMUS', GameWAD+':MUSIC\ROUNDMUS', True, True);
1522 g_Sound_CreateWADEx('MUSIC_STDENDMUS', GameWAD+':MUSIC\ENDMUS', True);
1524 gMusic := TMusic.Create();
1525 gMusic.SetByName('MUSIC_MENU');
1526 gMusic.Play();
1528 gGameSettings.WarmupTime := 30;
1530 gState := STATE_MENU;
1532 SetLength(gEvents, 6);
1533 gEvents[0].Name := 'ongamestart';
1534 gEvents[1].Name := 'ongameend';
1535 gEvents[2].Name := 'onmapstart';
1536 gEvents[3].Name := 'onmapend';
1537 gEvents[4].Name := 'oninter';
1538 gEvents[5].Name := 'onwadend';
1539 finally
1540 sfsGCEnable(); // enable releasing unused volumes
1541 end;
1542 end;
1544 procedure g_Game_Free(freeTextures: Boolean=true);
1545 begin
1546 if NetMode = NET_CLIENT then g_Net_Disconnect();
1547 if NetMode = NET_SERVER then g_Net_Host_Die();
1549 g_Map_Free(freeTextures);
1550 g_Player_Free();
1551 g_Player_RemoveAllCorpses();
1553 gGameSettings.GameType := GT_NONE;
1554 if gGameSettings.GameMode = GM_SINGLE then
1555 gGameSettings.GameMode := GM_DM;
1556 gSwitchGameMode := gGameSettings.GameMode;
1558 gChatShow := False;
1559 gExitByTrigger := False;
1560 end;
1562 function IsActivePlayer(p: TPlayer): Boolean;
1563 begin
1564 Result := False;
1565 if p = nil then
1566 Exit;
1567 Result := (not p.FDummy) and (not p.FSpectator);
1568 end;
1570 function GetActivePlayerID_Next(Skip: Integer = -1): Integer;
1571 var
1572 a, idx: Integer;
1573 ids: Array of Word;
1574 begin
1575 Result := -1;
1576 if gPlayers = nil then
1577 Exit;
1578 SetLength(ids, 0);
1579 idx := -1;
1580 for a := Low(gPlayers) to High(gPlayers) do
1581 if IsActivePlayer(gPlayers[a]) then
1582 begin
1583 SetLength(ids, Length(ids) + 1);
1584 ids[High(ids)] := gPlayers[a].UID;
1585 if gPlayers[a].UID = Skip then
1586 idx := High(ids);
1587 end;
1588 if Length(ids) = 0 then
1589 Exit;
1590 if idx = -1 then
1591 Result := ids[0]
1592 else
1593 Result := ids[(idx + 1) mod Length(ids)];
1594 end;
1596 function GetActivePlayerID_Prev(Skip: Integer = -1): Integer;
1597 var
1598 a, idx: Integer;
1599 ids: Array of Word;
1600 begin
1601 Result := -1;
1602 if gPlayers = nil then
1603 Exit;
1604 SetLength(ids, 0);
1605 idx := -1;
1606 for a := Low(gPlayers) to High(gPlayers) do
1607 if IsActivePlayer(gPlayers[a]) then
1608 begin
1609 SetLength(ids, Length(ids) + 1);
1610 ids[High(ids)] := gPlayers[a].UID;
1611 if gPlayers[a].UID = Skip then
1612 idx := High(ids);
1613 end;
1614 if Length(ids) = 0 then
1615 Exit;
1616 if idx = -1 then
1617 Result := ids[Length(ids) - 1]
1618 else
1619 Result := ids[(Length(ids) - 1 + idx) mod Length(ids)];
1620 end;
1622 function GetActivePlayerID_Random(Skip: Integer = -1): Integer;
1623 var
1624 a, idx: Integer;
1625 ids: Array of Word;
1626 begin
1627 Result := -1;
1628 if gPlayers = nil then
1629 Exit;
1630 SetLength(ids, 0);
1631 idx := -1;
1632 for a := Low(gPlayers) to High(gPlayers) do
1633 if IsActivePlayer(gPlayers[a]) then
1634 begin
1635 SetLength(ids, Length(ids) + 1);
1636 ids[High(ids)] := gPlayers[a].UID;
1637 if gPlayers[a].UID = Skip then
1638 idx := High(ids);
1639 end;
1640 if Length(ids) = 0 then
1641 Exit;
1642 if Length(ids) = 1 then
1643 begin
1644 Result := ids[0];
1645 Exit;
1646 end;
1647 Result := ids[Random(Length(ids))];
1648 a := 10;
1649 while (idx <> -1) and (Result = Skip) and (a > 0) do
1650 begin
1651 Result := ids[Random(Length(ids))];
1652 Dec(a);
1653 end;
1654 end;
1656 function GetRandomSpectMode(Current: Byte): Byte;
1657 label
1658 retry;
1659 begin
1660 Result := Current;
1661 retry:
1662 case Random(7) of
1663 0: Result := SPECT_STATS;
1664 1: Result := SPECT_MAPVIEW;
1665 2: Result := SPECT_MAPVIEW;
1666 3: Result := SPECT_PLAYERS;
1667 4: Result := SPECT_PLAYERS;
1668 5: Result := SPECT_PLAYERS;
1669 6: Result := SPECT_PLAYERS;
1670 end;
1671 if (Current in [SPECT_STATS, SPECT_MAPVIEW]) and (Current = Result) then
1672 goto retry;
1673 end;
1675 procedure ProcessPlayerControls (plr: TPlayer; p: Integer; var MoveButton: Byte);
1676 var
1677 time: Word;
1678 strafeDir: Byte;
1679 i: Integer;
1680 begin
1681 if (plr = nil) then exit;
1682 if (p = 2) then time := 1000 else time := 1;
1683 strafeDir := MoveButton shr 4;
1684 MoveButton := MoveButton and $0F;
1686 if gPlayerAction[p, ACTION_MOVELEFT] and (not gPlayerAction[p, ACTION_MOVERIGHT]) then
1687 MoveButton := 1 // Нажата только "Влево"
1688 else if (not gPlayerAction[p, ACTION_MOVELEFT]) and gPlayerAction[p, ACTION_MOVERIGHT] then
1689 MoveButton := 2 // Нажата только "Вправо"
1690 else if (not gPlayerAction[p, ACTION_MOVELEFT]) and (not gPlayerAction[p, ACTION_MOVERIGHT]) then
1691 MoveButton := 0; // Не нажаты ни "Влево", ни "Вправо"
1693 // Сейчас или раньше были нажаты "Влево"/"Вправо" => передаем игроку:
1694 if MoveButton = 1 then
1695 plr.PressKey(KEY_LEFT, time)
1696 else if MoveButton = 2 then
1697 plr.PressKey(KEY_RIGHT, time);
1699 // if we have "strafe" key, turn off old strafe mechanics
1700 if gPlayerAction[p, ACTION_STRAFE] then
1701 begin
1702 // new strafe mechanics
1703 if (strafeDir = 0) then
1704 strafeDir := MoveButton; // start strafing
1705 // now set direction according to strafe (reversed)
1706 if (strafeDir = 2) then
1707 plr.SetDirection(TDirection.D_LEFT)
1708 else if (strafeDir = 1) then
1709 plr.SetDirection(TDirection.D_RIGHT)
1710 end
1711 else
1712 begin
1713 strafeDir := 0; // not strafing anymore
1714 // Раньше была нажата "Вправо", а сейчас "Влево" => бежим вправо, смотрим влево:
1715 if (MoveButton = 2) and gPlayerAction[p, ACTION_MOVELEFT] then
1716 plr.SetDirection(TDirection.D_LEFT)
1717 // Раньше была нажата "Влево", а сейчас "Вправо" => бежим влево, смотрим вправо:
1718 else if (MoveButton = 1) and gPlayerAction[p, ACTION_MOVERIGHT] then
1719 plr.SetDirection(TDirection.D_RIGHT)
1720 // Что-то было нажато и не изменилось => куда бежим, туда и смотрим:
1721 else if MoveButton <> 0 then
1722 plr.SetDirection(TDirection(MoveButton-1))
1723 end;
1725 // fix movebutton state
1726 MoveButton := MoveButton or (strafeDir shl 4);
1728 // Остальные клавиши:
1729 if gPlayerAction[p, ACTION_JUMP] then plr.PressKey(KEY_JUMP, time);
1730 if gPlayerAction[p, ACTION_LOOKUP] then plr.PressKey(KEY_UP, time);
1731 if gPlayerAction[p, ACTION_LOOKDOWN] then plr.PressKey(KEY_DOWN, time);
1732 if gPlayerAction[p, ACTION_ATTACK] then plr.PressKey(KEY_FIRE);
1733 if gPlayerAction[p, ACTION_WEAPNEXT] then plr.PressKey(KEY_NEXTWEAPON);
1734 if gPlayerAction[p, ACTION_WEAPPREV] then plr.PressKey(KEY_PREVWEAPON);
1735 if gPlayerAction[p, ACTION_ACTIVATE] then plr.PressKey(KEY_OPEN);
1737 gPlayerAction[p, ACTION_WEAPNEXT] := False; // HACK, remove after readyweaon&pendinweapon implementation
1738 gPlayerAction[p, ACTION_WEAPPREV] := False; // HACK, remove after readyweaon&pendinweapon implementation
1740 for i := WP_FIRST to WP_LAST do
1741 begin
1742 if gSelectWeapon[p, i] then
1743 begin
1744 plr.QueueWeaponSwitch(i); // all choices are passed there, and god will take the best
1745 gSelectWeapon[p, i] := False
1746 end
1747 end;
1749 // HACK: add dynlight here
1750 if gwin_k8_enable_light_experiments then
1751 begin
1752 if e_KeyPressed(IK_F8) and gGameOn and (not gConsoleShow) and (g_ActiveWindow = nil) then
1753 begin
1754 g_playerLight := true;
1755 end;
1756 if e_KeyPressed(IK_F9) and gGameOn and (not gConsoleShow) and (g_ActiveWindow = nil) then
1757 begin
1758 g_playerLight := false;
1759 end;
1760 end;
1762 if gwin_has_stencil and g_playerLight then g_AddDynLight(plr.GameX+32, plr.GameY+40, 128, 1, 1, 0, 0.6);
1763 end;
1765 // HACK: don't have a "key was pressed" function
1766 procedure InterReady();
1767 begin
1768 if InterReadyTime > gTime then Exit;
1769 InterReadyTime := gTime + 3000;
1770 MC_SEND_CheatRequest(NET_CHEAT_READY);
1771 end;
1773 procedure g_Game_PreUpdate();
1774 begin
1775 // these are in separate PreUpdate functions because they can interact during Update()
1776 // and are synced over the net
1777 // we don't care that much about corpses and gibs
1778 g_Player_PreUpdate();
1779 g_Monsters_PreUpdate();
1780 g_Items_PreUpdate();
1781 g_Weapon_PreUpdate();
1782 end;
1784 procedure g_Game_Update();
1785 var
1786 Msg: g_gui.TMessage;
1787 Time: Int64;
1788 a: Byte;
1789 w: Word;
1790 i, b: Integer;
1792 function sendMonsPos (mon: TMonster): Boolean;
1793 begin
1794 result := false; // don't stop
1795 // this will also reset "need-send" flag
1796 if mon.gncNeedSend then
1797 begin
1798 MH_SEND_MonsterPos(mon.UID);
1799 end
1800 else if (mon.MonsterType = MONSTER_BARREL) then
1801 begin
1802 if (mon.GameVelX <> 0) or (mon.GameVelY <> 0) then MH_SEND_MonsterPos(mon.UID);
1803 end
1804 else if (mon.MonsterState <> MONSTATE_SLEEP) then
1805 begin
1806 if (mon.MonsterState <> MONSTATE_DEAD) or (mon.GameVelX <> 0) or (mon.GameVelY <> 0) then MH_SEND_MonsterPos(mon.UID);
1807 end;
1808 end;
1810 function sendMonsPosUnexpected (mon: TMonster): Boolean;
1811 begin
1812 result := false; // don't stop
1813 // this will also reset "need-send" flag
1814 if mon.gncNeedSend then MH_SEND_MonsterPos(mon.UID);
1815 end;
1817 var
1818 reliableUpdate: Boolean;
1819 begin
1820 g_ResetDynlights();
1821 framePool.reset();
1823 // Пора выключать игру:
1824 if gExit = EXIT_QUIT then
1825 Exit;
1826 // Игра закончилась - обрабатываем:
1827 if gExit <> 0 then
1828 begin
1829 EndGame();
1830 if gExit = EXIT_QUIT then
1831 Exit;
1832 end;
1834 // Читаем клавиатуру и джойстик, если окно активно
1835 // no need to, as we'll do it in event handler
1837 // Обновляем консоль (движение и сообщения):
1838 r_Console_Update;
1839 g_Console_Update();
1841 if (NetMode = NET_NONE) and (g_Game_IsNet) and (gGameOn or (gState in [STATE_FOLD, STATE_INTERCUSTOM])) then
1842 begin
1843 gExit := EXIT_SIMPLE;
1844 EndGame();
1845 Exit;
1846 end;
1848 // process master server communications
1849 g_Net_Slist_Pulse();
1851 case gState of
1852 STATE_INTERSINGLE, // Статистка после прохождения уровня в Одиночной игре
1853 STATE_INTERCUSTOM, // Статистка после прохождения уровня в Своей игре
1854 STATE_INTERTEXT, // Текст между уровнями
1855 STATE_INTERPIC: // Картинка между уровнями
1856 begin
1857 if g_Game_IsNet and g_Game_IsServer then
1858 begin
1859 gInterTime := gInterTime + GAME_TICK;
1860 a := Min((gInterEndTime - gInterTime) div 1000 + 1, 255);
1861 if a <> gServInterTime then
1862 begin
1863 gServInterTime := a;
1864 MH_SEND_TimeSync(gServInterTime);
1865 end;
1866 end;
1868 if (not g_Game_IsClient) and
1872 e_KeyPressed(IK_RETURN) or e_KeyPressed(IK_KPRETURN) or e_KeyPressed(IK_SPACE) or
1873 e_KeyPressed(VK_FIRE) or e_KeyPressed(VK_OPEN) or
1874 e_KeyPressed(JOY0_ATTACK) or e_KeyPressed(JOY1_ATTACK) or
1875 e_KeyPressed(JOY2_ATTACK) or e_KeyPressed(JOY3_ATTACK)
1877 and (not gJustChatted) and (not gConsoleShow) and (not gChatShow)
1878 and (g_ActiveWindow = nil)
1880 or (g_Game_IsNet and ((gInterTime > gInterEndTime) or ((gInterReadyCount >= NetClientCount) and (NetClientCount > 0))))
1882 then
1883 begin // Нажали <Enter>/<Пробел> или прошло достаточно времени:
1884 g_Game_StopAllSounds(True);
1886 if gMapOnce then // Это был тест
1887 gExit := EXIT_SIMPLE
1888 else
1889 if gNextMap <> '' then // Переходим на следующую карту
1890 g_Game_ChangeMap(gNextMap)
1891 else // Следующей карты нет
1892 begin
1893 if gGameSettings.GameType in [GT_CUSTOM, GT_SERVER] then
1894 begin
1895 // Выход в главное меню:
1896 g_Game_Free;
1897 g_GUI_ShowWindow('MainMenu');
1898 gMusic.SetByName('MUSIC_MENU');
1899 gMusic.Play();
1900 gState := STATE_MENU;
1901 end else
1902 begin
1903 // Финальная картинка:
1904 g_Game_ExecuteEvent('onwadend');
1905 g_Game_Free();
1906 if not gMusic.SetByName('MUSIC_endmus') then
1907 gMusic.SetByName('MUSIC_STDENDMUS');
1908 gMusic.Play();
1909 gState := STATE_ENDPIC;
1910 end;
1911 g_Game_ExecuteEvent('ongameend');
1912 end;
1914 Exit;
1915 end
1916 else if g_Game_IsClient and
1919 e_KeyPressed(IK_RETURN) or e_KeyPressed(IK_KPRETURN) or e_KeyPressed(IK_SPACE) or
1920 e_KeyPressed(VK_FIRE) or e_KeyPressed(VK_OPEN) or
1921 e_KeyPressed(JOY0_ATTACK) or e_KeyPressed(JOY1_ATTACK) or
1922 e_KeyPressed(JOY2_ATTACK) or e_KeyPressed(JOY3_ATTACK)
1924 and (not gJustChatted) and (not gConsoleShow) and (not gChatShow)
1925 and (g_ActiveWindow = nil)
1927 then
1928 begin
1929 // ready / unready
1930 InterReady();
1931 end;
1933 if gState = STATE_INTERTEXT then
1934 if InterText.counter > 0 then
1935 InterText.counter := InterText.counter - 1;
1936 end;
1938 STATE_FOLD: // Затухание экрана
1939 begin
1940 if EndingGameCounter = 0 then
1941 begin
1942 // Закончился уровень в Своей игре:
1943 if gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT] then
1944 begin
1945 InterReadyTime := -1;
1946 if gLastMap and (gGameSettings.GameMode = GM_COOP) then
1947 begin
1948 g_Game_ExecuteEvent('onwadend');
1949 if not gMusic.SetByName('MUSIC_endmus') then
1950 gMusic.SetByName('MUSIC_STDENDMUS');
1951 end
1952 else
1953 gMusic.SetByName('MUSIC_ROUNDMUS');
1955 gMusic.Play();
1956 gState := STATE_INTERCUSTOM;
1957 e_UnpressAllKeys();
1958 end
1959 else // Закончилась последняя карта в Одиночной игре
1960 begin
1961 gMusic.SetByName('MUSIC_INTERMUS');
1962 gMusic.Play();
1963 gState := STATE_INTERSINGLE;
1964 e_UnpressAllKeys();
1965 end;
1966 g_Game_ExecuteEvent('oninter');
1967 end
1968 else
1969 DecMin(EndingGameCounter, 6, 0);
1970 end;
1972 STATE_ENDPIC: // Картинка окончания мегаВада
1973 begin
1974 if gMapOnce then // Это был тест
1975 begin
1976 gExit := EXIT_SIMPLE;
1977 Exit;
1978 end;
1979 end;
1981 STATE_SLIST:
1982 g_Serverlist_Control(slCurrent, slTable);
1983 end;
1985 // Статистика по Tab:
1986 if gGameOn then
1987 IsDrawStat := (not gConsoleShow) and (not gChatShow) and (gGameSettings.GameType <> GT_SINGLE) and g_Console_Action(ACTION_SCORES);
1989 // Игра идет:
1990 if gGameOn and not gPause and (gState <> STATE_FOLD) then
1991 begin
1992 // Время += 28 миллисекунд:
1993 gTime := gTime + GAME_TICK;
1995 // Сообщение посередине экрана:
1996 if MessageTime = 0 then
1997 MessageText := '';
1998 if MessageTime > 0 then
1999 MessageTime := MessageTime - 1;
2001 if (g_Game_IsServer) then
2002 begin
2003 // Был задан лимит времени:
2004 if (gGameSettings.TimeLimit > 0) then
2005 if (gTime - gGameStartTime) div 1000 >= gGameSettings.TimeLimit then
2006 begin // Он прошел => конец уровня
2007 g_Game_NextLevel();
2008 Exit;
2009 end;
2011 // Надо респавнить игроков в LMS:
2012 if (gLMSRespawn > LMS_RESPAWN_NONE) and (gLMSRespawnTime < gTime) then
2013 g_Game_RestartRound(gLMSSoftSpawn);
2015 // Проверим результат голосования, если время прошло
2016 if gVoteInProgress and (gVoteTimer < gTime) then
2017 g_Game_CheckVote
2018 else if gVotePassed and (gVoteCmdTimer < gTime) then
2019 begin
2020 g_Console_Process(gVoteCommand);
2021 gVoteCommand := '';
2022 gVotePassed := False;
2023 end;
2025 // Замеряем время захвата флагов
2026 if gFlags[FLAG_RED].State = FLAG_STATE_CAPTURED then
2027 gFlags[FLAG_RED].CaptureTime := gFlags[FLAG_RED].CaptureTime + GAME_TICK;
2028 if gFlags[FLAG_BLUE].State = FLAG_STATE_CAPTURED then
2029 gFlags[FLAG_BLUE].CaptureTime := gFlags[FLAG_BLUE].CaptureTime + GAME_TICK;
2031 // Был задан лимит побед:
2032 if (gGameSettings.GoalLimit > 0) then
2033 begin
2034 b := 0;
2036 if gGameSettings.GameMode = GM_DM then
2037 begin // В DM ищем игрока с max фрагами
2038 for i := 0 to High(gPlayers) do
2039 if gPlayers[i] <> nil then
2040 if gPlayers[i].Frags > b then
2041 b := gPlayers[i].Frags;
2042 end
2043 else
2044 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
2045 begin // В CTF/TDM выбираем команду с наибольшим счетом
2046 b := Max(gTeamStat[TEAM_RED].Goals, gTeamStat[TEAM_BLUE].Goals);
2047 end;
2049 // Лимит побед набран => конец уровня:
2050 if b >= gGameSettings.GoalLimit then
2051 begin
2052 g_Game_NextLevel();
2053 Exit;
2054 end;
2055 end;
2057 // Обрабатываем клавиши игроков:
2058 if gPlayer1 <> nil then gPlayer1.ReleaseKeys();
2059 if gPlayer2 <> nil then gPlayer2.ReleaseKeys();
2060 if (not gConsoleShow) and (not gChatShow) and (g_ActiveWindow = nil) then
2061 begin
2062 ProcessPlayerControls(gPlayer1, 0, P1MoveButton);
2063 ProcessPlayerControls(gPlayer2, 1, P2MoveButton);
2064 end // if not console
2065 else
2066 begin
2067 if g_Game_IsNet and (gPlayer1 <> nil) then gPlayer1.PressKey(KEY_CHAT, 10000);
2068 end;
2069 // process weapon switch queue
2070 end; // if server
2072 // Наблюдатель
2073 if (gPlayer1 = nil) and (gPlayer2 = nil) and
2074 (not gConsoleShow) and (not gChatShow) and (g_ActiveWindow = nil) then
2075 begin
2076 if not gSpectKeyPress then
2077 begin
2078 if gPlayerAction[0, ACTION_JUMP] and (not gSpectAuto) then
2079 begin
2080 // switch spect mode
2081 case gSpectMode of
2082 SPECT_NONE: ; // not spectator
2083 SPECT_STATS,
2084 SPECT_MAPVIEW: Inc(gSpectMode);
2085 SPECT_PLAYERS: gSpectMode := SPECT_STATS; // reset to 1
2086 end;
2087 gSpectKeyPress := True;
2088 end;
2089 if (gSpectMode = SPECT_MAPVIEW)
2090 and (not gSpectAuto) then
2091 begin
2092 if gPlayerAction[0, ACTION_MOVELEFT] then
2093 gSpectX := Max(gSpectX - gSpectStep, 0);
2094 if gPlayerAction[0, ACTION_MOVERIGHT] then
2095 gSpectX := Min(gSpectX + gSpectStep, gMapInfo.Width - gScreenWidth);
2096 if gPlayerAction[0, ACTION_LOOKUP] then
2097 gSpectY := Max(gSpectY - gSpectStep, 0);
2098 if gPlayerAction[0, ACTION_LOOKDOWN] then
2099 gSpectY := Min(gSpectY + gSpectStep, gMapInfo.Height - gScreenHeight);
2100 if gPlayerAction[0, ACTION_WEAPPREV] then
2101 begin
2102 // decrease step
2103 if gSpectStep > 4 then gSpectStep := gSpectStep shr 1;
2104 gSpectKeyPress := True;
2105 end;
2106 if gPlayerAction[0, ACTION_WEAPNEXT] then
2107 begin
2108 // increase step
2109 if gSpectStep < 64 then gSpectStep := gSpectStep shl 1;
2110 gSpectKeyPress := True;
2111 end;
2112 end;
2113 if (gSpectMode = SPECT_PLAYERS)
2114 and (not gSpectAuto) then
2115 begin
2116 if gPlayerAction[0, ACTION_LOOKUP] then
2117 begin
2118 // add second view
2119 gSpectViewTwo := True;
2120 gSpectKeyPress := True;
2121 end;
2122 if gPlayerAction[0, ACTION_LOOKDOWN] then
2123 begin
2124 // remove second view
2125 gSpectViewTwo := False;
2126 gSpectKeyPress := True;
2127 end;
2128 if gPlayerAction[0, ACTION_MOVELEFT] then
2129 begin
2130 // prev player (view 1)
2131 gSpectPID1 := GetActivePlayerID_Prev(gSpectPID1);
2132 gSpectKeyPress := True;
2133 end;
2134 if gPlayerAction[0, ACTION_MOVERIGHT] then
2135 begin
2136 // next player (view 1)
2137 gSpectPID1 := GetActivePlayerID_Next(gSpectPID1);
2138 gSpectKeyPress := True;
2139 end;
2140 if gPlayerAction[0, ACTION_WEAPPREV] then
2141 begin
2142 // prev player (view 2)
2143 gSpectPID2 := GetActivePlayerID_Prev(gSpectPID2);
2144 gSpectKeyPress := True;
2145 end;
2146 if gPlayerAction[0, ACTION_WEAPNEXT] then
2147 begin
2148 // next player (view 2)
2149 gSpectPID2 := GetActivePlayerID_Next(gSpectPID2);
2150 gSpectKeyPress := True;
2151 end;
2152 end;
2153 if gPlayerAction[0, ACTION_ATTACK] then
2154 begin
2155 if (gSpectMode = SPECT_STATS) and (not gSpectAuto) then
2156 begin
2157 gSpectAuto := True;
2158 gSpectAutoNext := 0;
2159 gSpectViewTwo := False;
2160 gSpectKeyPress := True;
2161 end
2162 else
2163 if gSpectAuto then
2164 begin
2165 gSpectMode := SPECT_STATS;
2166 gSpectAuto := False;
2167 gSpectKeyPress := True;
2168 end;
2169 end;
2170 end
2171 else
2172 if (not gPlayerAction[0, ACTION_JUMP]) and
2173 (not gPlayerAction[0, ACTION_ATTACK]) and
2174 (not gPlayerAction[0, ACTION_MOVELEFT]) and
2175 (not gPlayerAction[0, ACTION_MOVERIGHT]) and
2176 (not gPlayerAction[0, ACTION_LOOKUP]) and
2177 (not gPlayerAction[0, ACTION_LOOKDOWN]) and
2178 (not gPlayerAction[0, ACTION_WEAPPREV]) and
2179 (not gPlayerAction[0, ACTION_WEAPNEXT]) then
2180 gSpectKeyPress := False;
2182 if gSpectAuto then
2183 begin
2184 if gSpectMode = SPECT_MAPVIEW then
2185 begin
2186 i := Min(Max(gSpectX + gSpectAutoStepX, 0), gMapInfo.Width - gScreenWidth);
2187 if i = gSpectX then
2188 gSpectAutoNext := gTime
2189 else
2190 gSpectX := i;
2191 i := Min(Max(gSpectY + gSpectAutoStepY, 0), gMapInfo.Height - gScreenHeight);
2192 if i = gSpectY then
2193 gSpectAutoNext := gTime
2194 else
2195 gSpectY := i;
2196 end;
2197 if gSpectAutoNext <= gTime then
2198 begin
2199 if gSpectAutoNext > 0 then
2200 begin
2201 gSpectMode := GetRandomSpectMode(gSpectMode);
2202 case gSpectMode of
2203 SPECT_MAPVIEW:
2204 begin
2205 gSpectX := Random(gMapInfo.Width - gScreenWidth);
2206 gSpectY := Random(gMapInfo.Height - gScreenHeight);
2207 gSpectAutoStepX := Random(9) - 4;
2208 gSpectAutoStepY := Random(9) - 4;
2209 if ((gSpectX < 800) and (gSpectAutoStepX < 0)) or
2210 ((gSpectX > gMapInfo.Width - gScreenWidth - 800) and (gSpectAutoStepX > 0)) then
2211 gSpectAutoStepX := gSpectAutoStepX * -1;
2212 if ((gSpectY < 800) and (gSpectAutoStepY < 0)) or
2213 ((gSpectY > gMapInfo.Height - gScreenHeight - 800) and (gSpectAutoStepY > 0)) then
2214 gSpectAutoStepY := gSpectAutoStepY * -1;
2215 end;
2216 SPECT_PLAYERS:
2217 begin
2218 gSpectPID1 := GetActivePlayerID_Random(gSpectPID1);
2219 end;
2220 end;
2221 end;
2222 case gSpectMode of
2223 SPECT_STATS: gSpectAutoNext := gTime + (Random(3) + 5) * 1000;
2224 SPECT_MAPVIEW: gSpectAutoNext := gTime + (Random(4) + 7) * 1000;
2225 SPECT_PLAYERS: gSpectAutoNext := gTime + (Random(7) + 8) * 1000;
2226 end;
2227 end;
2228 end;
2229 end;
2231 // Обновляем все остальное:
2232 g_Map_Update();
2233 g_Items_Update();
2234 g_Triggers_Update();
2235 g_Weapon_Update();
2236 g_Monsters_Update();
2237 g_GFX_Update();
2238 g_Player_UpdateAll();
2239 g_Player_UpdatePhysicalObjects();
2241 // server: send newly spawned monsters unconditionally
2242 if (gGameSettings.GameType = GT_SERVER) then
2243 begin
2244 if (Length(gMonstersSpawned) > 0) then
2245 begin
2246 for I := 0 to High(gMonstersSpawned) do MH_SEND_MonsterSpawn(gMonstersSpawned[I]);
2247 SetLength(gMonstersSpawned, 0);
2248 end;
2249 end;
2251 if (gSoundTriggerTime > 8) then
2252 begin
2253 g_Game_UpdateTriggerSounds();
2254 gSoundTriggerTime := 0;
2255 end
2256 else
2257 begin
2258 Inc(gSoundTriggerTime);
2259 end;
2261 if (NetMode = NET_SERVER) then
2262 begin
2263 Inc(NetTimeToUpdate);
2264 Inc(NetTimeToReliable);
2266 // send monster updates
2267 if (NetTimeToReliable >= NetRelupdRate) or (NetTimeToUpdate >= NetUpdateRate) then
2268 begin
2269 // send all monsters (periodic sync)
2270 reliableUpdate := (NetTimeToReliable >= NetRelupdRate);
2272 for I := 0 to High(gPlayers) do
2273 begin
2274 if (gPlayers[I] <> nil) then MH_SEND_PlayerPos(reliableUpdate, gPlayers[I].UID);
2275 end;
2277 g_Mons_ForEach(sendMonsPos);
2279 if reliableUpdate then
2280 begin
2281 NetTimeToReliable := 0;
2282 NetTimeToUpdate := NetUpdateRate;
2283 end
2284 else
2285 begin
2286 NetTimeToUpdate := 0;
2287 end;
2288 end
2289 else
2290 begin
2291 // send only mosters with some unexpected changes
2292 g_Mons_ForEach(sendMonsPosUnexpected);
2293 end;
2295 // send unexpected platform changes
2296 g_Map_NetSendInterestingPanels();
2298 g_Net_Slist_ServerUpdate();
2300 if NetUseMaster then
2301 begin
2302 if (gTime >= NetTimeToMaster) or g_Net_Slist_IsConnectionInProgress then
2303 begin
2304 if (not g_Net_Slist_IsConnectionActive) then g_Net_Slist_Connect(false); // non-blocking connection to the master
2305 g_Net_Slist_Update;
2306 NetTimeToMaster := gTime + NetMasterRate;
2307 end;
2308 end;
2310 end
2311 else if (NetMode = NET_CLIENT) then
2312 begin
2313 MC_SEND_PlayerPos();
2314 end;
2315 end; // if gameOn ...
2317 // Активно окно интерфейса - передаем клавиши ему:
2318 if g_ActiveWindow <> nil then
2319 begin
2320 w := e_GetFirstKeyPressed();
2322 if (w <> IK_INVALID) then
2323 begin
2324 Msg.Msg := MESSAGE_DIKEY;
2325 Msg.wParam := w;
2326 g_ActiveWindow.OnMessage(Msg);
2327 end;
2329 // Если оно от этого не закрылось, то обновляем:
2330 if g_ActiveWindow <> nil then
2331 g_ActiveWindow.Update();
2333 // Нужно сменить разрешение:
2334 if gResolutionChange then
2335 begin
2336 e_WriteLog('Changing resolution', TMsgType.Notify);
2337 g_Game_ChangeResolution(gRC_Width, gRC_Height, gRC_FullScreen, gRC_Maximized);
2338 gResolutionChange := False;
2339 g_ActiveWindow := nil;
2340 end;
2342 // Нужно сменить язык:
2343 if gLanguageChange then
2344 begin
2345 //e_WriteLog('Read language file', MSG_NOTIFY);
2346 //g_Language_Load(DataDir + gLanguage + '.txt');
2347 g_Language_Set(gLanguage);
2348 {$IFNDEF HEADLESS}
2349 g_Menu_Reset();
2350 {$ENDIF}
2351 gLanguageChange := False;
2352 end;
2353 end;
2355 // Горячая клавиша для вызова меню выхода из игры (F10):
2356 if e_KeyPressed(IK_F10) and
2357 gGameOn and
2358 (not gConsoleShow) and
2359 (g_ActiveWindow = nil) then
2360 begin
2361 KeyPress(IK_F10);
2362 end;
2364 Time := sys_GetTicks() {div 1000};
2366 // Обработка отложенных событий:
2367 if gDelayedEvents <> nil then
2368 for a := 0 to High(gDelayedEvents) do
2369 if gDelayedEvents[a].Pending and
2371 ((gDelayedEvents[a].DEType = DE_GLOBEVENT) and (gDelayedEvents[a].Time <= Time)) or
2372 ((gDelayedEvents[a].DEType > DE_GLOBEVENT) and (gDelayedEvents[a].Time <= gTime))
2373 ) then
2374 begin
2375 case gDelayedEvents[a].DEType of
2376 DE_GLOBEVENT:
2377 g_Game_ExecuteEvent(gDelayedEvents[a].DEStr);
2378 DE_BFGHIT:
2379 if gGameOn then
2380 g_Game_Announce_GoodShot(gDelayedEvents[a].DENum);
2381 DE_KILLCOMBO:
2382 if gGameOn then
2383 begin
2384 g_Game_Announce_KillCombo(gDelayedEvents[a].DENum);
2385 if g_Game_IsNet and g_Game_IsServer then
2386 MH_SEND_GameEvent(NET_EV_KILLCOMBO, gDelayedEvents[a].DENum);
2387 end;
2388 DE_BODYKILL:
2389 if gGameOn then
2390 g_Game_Announce_BodyKill(gDelayedEvents[a].DENum);
2391 end;
2392 gDelayedEvents[a].Pending := False;
2393 end;
2395 // Каждую секунду обновляем счетчик обновлений:
2396 UPSCounter := UPSCounter + 1;
2397 if Time - UPSTime >= 1000 then
2398 begin
2399 UPS := UPSCounter;
2400 UPSCounter := 0;
2401 UPSTime := Time;
2402 end;
2404 if gGameOn then
2405 begin
2406 g_Weapon_AddDynLights();
2407 g_Items_AddDynLights();
2408 end;
2409 end;
2411 procedure g_Game_LoadChatSounds(Resource: string);
2412 var
2413 WAD: TWADFile;
2414 FileName, Snd: string;
2415 p: Pointer;
2416 len, cnt, tags, i, j: Integer;
2417 cfg: TConfig;
2418 begin
2419 FileName := g_ExtractWadName(Resource);
2421 WAD := TWADFile.Create();
2422 WAD.ReadFile(FileName);
2424 if not WAD.GetResource(g_ExtractFilePathName(Resource), p, len) then
2425 begin
2426 gChatSounds := nil;
2427 WAD.Free();
2428 Exit;
2429 end;
2431 cfg := TConfig.CreateMem(p, len);
2432 cnt := cfg.ReadInt('ChatSounds', 'Count', 0);
2434 SetLength(gChatSounds, cnt);
2435 for i := 0 to Length(gChatSounds) - 1 do
2436 begin
2437 gChatSounds[i].Sound := nil;
2438 Snd := Trim(cfg.ReadStr(IntToStr(i), 'Sound', ''));
2439 tags := cfg.ReadInt(IntToStr(i), 'Tags', 0);
2440 if (Snd = '') or (Tags <= 0) then
2441 continue;
2442 g_Sound_CreateWADEx('SOUND_CHAT_MACRO' + IntToStr(i), GameWAD+':'+Snd);
2443 gChatSounds[i].Sound := TPlayableSound.Create();
2444 gChatSounds[i].Sound.SetByName('SOUND_CHAT_MACRO' + IntToStr(i));
2445 SetLength(gChatSounds[i].Tags, tags);
2446 for j := 0 to tags - 1 do
2447 gChatSounds[i].Tags[j] := toLowerCase1251(cfg.ReadStr(IntToStr(i), 'Tag' + IntToStr(j), ''));
2448 gChatSounds[i].FullWord := cfg.ReadBool(IntToStr(i), 'FullWord', False);
2449 end;
2451 cfg.Free();
2452 WAD.Free();
2453 end;
2455 procedure g_Game_FreeChatSounds();
2456 var
2457 i: Integer;
2458 begin
2459 for i := 0 to Length(gChatSounds) - 1 do
2460 begin
2461 gChatSounds[i].Sound.Free();
2462 g_Sound_Delete('SOUND_CHAT_MACRO' + IntToStr(i));
2463 end;
2464 SetLength(gChatSounds, 0);
2465 gChatSounds := nil;
2466 end;
2468 procedure g_Game_LoadData();
2469 var
2470 wl, hl: Integer;
2471 wr, hr: Integer;
2472 wb, hb: Integer;
2473 wm, hm: Integer;
2474 begin
2475 if DataLoaded then Exit;
2477 e_WriteLog('Loading game data...', TMsgType.Notify);
2479 g_Texture_CreateWADEx('NOTEXTURE', GameWAD+':TEXTURES\NOTEXTURE');
2480 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUD', GameWAD+':TEXTURES\HUD');
2481 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDAIR', GameWAD+':TEXTURES\AIRBAR');
2482 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDJET', GameWAD+':TEXTURES\JETBAR');
2483 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDBG', GameWAD+':TEXTURES\HUDBG');
2484 g_Texture_CreateWADEx('TEXTURE_PLAYER_ARMORHUD', GameWAD+':TEXTURES\ARMORHUD');
2485 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG', GameWAD+':TEXTURES\FLAGHUD_R_BASE');
2486 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_S', GameWAD+':TEXTURES\FLAGHUD_R_STOLEN');
2487 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_D', GameWAD+':TEXTURES\FLAGHUD_R_DROP');
2488 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG', GameWAD+':TEXTURES\FLAGHUD_B_BASE');
2489 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_S', GameWAD+':TEXTURES\FLAGHUD_B_STOLEN');
2490 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_D', GameWAD+':TEXTURES\FLAGHUD_B_DROP');
2491 g_Texture_CreateWADEx('TEXTURE_PLAYER_TALKBUBBLE', GameWAD+':TEXTURES\TALKBUBBLE');
2492 g_Texture_CreateWADEx('TEXTURE_PLAYER_INVULPENTA', GameWAD+':TEXTURES\PENTA');
2493 g_Texture_CreateWADEx('TEXTURE_PLAYER_INDICATOR', GameWAD+':TEXTURES\PLRIND');
2495 hasPBarGfx := true;
2496 if not g_Texture_CreateWADEx('UI_GFX_PBAR_LEFT', GameWAD+':TEXTURES\LLEFT') then hasPBarGfx := false;
2497 if not g_Texture_CreateWADEx('UI_GFX_PBAR_MARKER', GameWAD+':TEXTURES\LMARKER') then hasPBarGfx := false;
2498 if not g_Texture_CreateWADEx('UI_GFX_PBAR_MIDDLE', GameWAD+':TEXTURES\LMIDDLE') then hasPBarGfx := false;
2499 if not g_Texture_CreateWADEx('UI_GFX_PBAR_RIGHT', GameWAD+':TEXTURES\LRIGHT') then hasPBarGfx := false;
2501 if hasPBarGfx then
2502 begin
2503 g_Texture_GetSize('UI_GFX_PBAR_LEFT', wl, hl);
2504 g_Texture_GetSize('UI_GFX_PBAR_RIGHT', wr, hr);
2505 g_Texture_GetSize('UI_GFX_PBAR_MIDDLE', wb, hb);
2506 g_Texture_GetSize('UI_GFX_PBAR_MARKER', wm, hm);
2507 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
2508 begin
2509 // yay!
2510 end
2511 else
2512 begin
2513 hasPBarGfx := false;
2514 end;
2515 end;
2517 g_Frames_CreateWAD(nil, 'FRAMES_TELEPORT', GameWAD+':TEXTURES\TELEPORT', 64, 64, 10, False);
2518 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH', GameWAD+':WEAPONS\PUNCH', 64, 64, 4, False);
2519 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_UP', GameWAD+':WEAPONS\PUNCH_UP', 64, 64, 4, False);
2520 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_DN', GameWAD+':WEAPONS\PUNCH_DN', 64, 64, 4, False);
2521 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK', GameWAD+':WEAPONS\PUNCHB', 64, 64, 4, False);
2522 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK_UP', GameWAD+':WEAPONS\PUNCHB_UP', 64, 64, 4, False);
2523 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK_DN', GameWAD+':WEAPONS\PUNCHB_DN', 64, 64, 4, False);
2524 g_Sound_CreateWADEx('SOUND_GAME_TELEPORT', GameWAD+':SOUNDS\TELEPORT');
2525 g_Sound_CreateWADEx('SOUND_GAME_NOTELEPORT', GameWAD+':SOUNDS\NOTELEPORT');
2526 g_Sound_CreateWADEx('SOUND_GAME_SECRET', GameWAD+':SOUNDS\SECRET');
2527 g_Sound_CreateWADEx('SOUND_GAME_DOOROPEN', GameWAD+':SOUNDS\DOOROPEN');
2528 g_Sound_CreateWADEx('SOUND_GAME_DOORCLOSE', GameWAD+':SOUNDS\DOORCLOSE');
2529 g_Sound_CreateWADEx('SOUND_GAME_BULK1', GameWAD+':SOUNDS\BULK1');
2530 g_Sound_CreateWADEx('SOUND_GAME_BULK2', GameWAD+':SOUNDS\BULK2');
2531 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE1', GameWAD+':SOUNDS\BUBBLE1');
2532 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE2', GameWAD+':SOUNDS\BUBBLE2');
2533 g_Sound_CreateWADEx('SOUND_GAME_BURNING', GameWAD+':SOUNDS\BURNING');
2534 g_Sound_CreateWADEx('SOUND_GAME_SWITCH1', GameWAD+':SOUNDS\SWITCH1');
2535 g_Sound_CreateWADEx('SOUND_GAME_SWITCH0', GameWAD+':SOUNDS\SWITCH0');
2536 g_Sound_CreateWADEx('SOUND_GAME_RADIO', GameWAD+':SOUNDS\RADIO');
2537 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD1', GameWAD+':SOUNDS\GOOD1');
2538 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD2', GameWAD+':SOUNDS\GOOD2');
2539 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD3', GameWAD+':SOUNDS\GOOD3');
2540 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD4', GameWAD+':SOUNDS\GOOD4');
2541 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL2X', GameWAD+':SOUNDS\KILL2X');
2542 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL3X', GameWAD+':SOUNDS\KILL3X');
2543 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL4X', GameWAD+':SOUNDS\KILL4X');
2544 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILLMX', GameWAD+':SOUNDS\KILLMX');
2545 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA1', GameWAD+':SOUNDS\MUHAHA1');
2546 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA2', GameWAD+':SOUNDS\MUHAHA2');
2547 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA3', GameWAD+':SOUNDS\MUHAHA3');
2548 g_Sound_CreateWADEx('SOUND_CTF_GET1', GameWAD+':SOUNDS\GETFLAG1');
2549 g_Sound_CreateWADEx('SOUND_CTF_GET2', GameWAD+':SOUNDS\GETFLAG2');
2550 g_Sound_CreateWADEx('SOUND_CTF_LOST1', GameWAD+':SOUNDS\LOSTFLG1');
2551 g_Sound_CreateWADEx('SOUND_CTF_LOST2', GameWAD+':SOUNDS\LOSTFLG2');
2552 g_Sound_CreateWADEx('SOUND_CTF_RETURN1', GameWAD+':SOUNDS\RETFLAG1');
2553 g_Sound_CreateWADEx('SOUND_CTF_RETURN2', GameWAD+':SOUNDS\RETFLAG2');
2554 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE1', GameWAD+':SOUNDS\CAPFLAG1');
2555 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE2', GameWAD+':SOUNDS\CAPFLAG2');
2557 goodsnd[0] := TPlayableSound.Create();
2558 goodsnd[1] := TPlayableSound.Create();
2559 goodsnd[2] := TPlayableSound.Create();
2560 goodsnd[3] := TPlayableSound.Create();
2562 goodsnd[0].SetByName('SOUND_ANNOUNCER_GOOD1');
2563 goodsnd[1].SetByName('SOUND_ANNOUNCER_GOOD2');
2564 goodsnd[2].SetByName('SOUND_ANNOUNCER_GOOD3');
2565 goodsnd[3].SetByName('SOUND_ANNOUNCER_GOOD4');
2567 killsnd[0] := TPlayableSound.Create();
2568 killsnd[1] := TPlayableSound.Create();
2569 killsnd[2] := TPlayableSound.Create();
2570 killsnd[3] := TPlayableSound.Create();
2572 killsnd[0].SetByName('SOUND_ANNOUNCER_KILL2X');
2573 killsnd[1].SetByName('SOUND_ANNOUNCER_KILL3X');
2574 killsnd[2].SetByName('SOUND_ANNOUNCER_KILL4X');
2575 killsnd[3].SetByName('SOUND_ANNOUNCER_KILLMX');
2577 hahasnd[0] := TPlayableSound.Create();
2578 hahasnd[1] := TPlayableSound.Create();
2579 hahasnd[2] := TPlayableSound.Create();
2581 hahasnd[0].SetByName('SOUND_ANNOUNCER_MUHAHA1');
2582 hahasnd[1].SetByName('SOUND_ANNOUNCER_MUHAHA2');
2583 hahasnd[2].SetByName('SOUND_ANNOUNCER_MUHAHA3');
2585 sound_get_flag[0] := TPlayableSound.Create();
2586 sound_get_flag[1] := TPlayableSound.Create();
2587 sound_lost_flag[0] := TPlayableSound.Create();
2588 sound_lost_flag[1] := TPlayableSound.Create();
2589 sound_ret_flag[0] := TPlayableSound.Create();
2590 sound_ret_flag[1] := TPlayableSound.Create();
2591 sound_cap_flag[0] := TPlayableSound.Create();
2592 sound_cap_flag[1] := TPlayableSound.Create();
2594 sound_get_flag[0].SetByName('SOUND_CTF_GET1');
2595 sound_get_flag[1].SetByName('SOUND_CTF_GET2');
2596 sound_lost_flag[0].SetByName('SOUND_CTF_LOST1');
2597 sound_lost_flag[1].SetByName('SOUND_CTF_LOST2');
2598 sound_ret_flag[0].SetByName('SOUND_CTF_RETURN1');
2599 sound_ret_flag[1].SetByName('SOUND_CTF_RETURN2');
2600 sound_cap_flag[0].SetByName('SOUND_CTF_CAPTURE1');
2601 sound_cap_flag[1].SetByName('SOUND_CTF_CAPTURE2');
2603 g_Game_LoadChatSounds(GameWAD+':CHATSND\SNDCFG');
2605 g_Game_SetLoadingText(_lc[I_LOAD_ITEMS_DATA], 0, False);
2606 g_Items_LoadData();
2608 g_Game_SetLoadingText(_lc[I_LOAD_WEAPONS_DATA], 0, False);
2609 g_Weapon_LoadData();
2611 g_Monsters_LoadData();
2613 DataLoaded := True;
2614 end;
2616 procedure g_Game_Quit();
2617 begin
2618 g_Game_StopAllSounds(True);
2619 gMusic.Free();
2620 g_Game_FreeData();
2621 g_PlayerModel_FreeData();
2622 g_Texture_DeleteAll();
2623 g_Frames_DeleteAll();
2624 {$IFNDEF HEADLESS}
2625 //g_Menu_Free(); //k8: this segfaults after resolution change; who cares?
2626 {$ENDIF}
2628 if NetInitDone then g_Net_Free;
2630 // remove map after test
2631 if gMapToDelete <> '' then
2632 g_Game_DeleteTestMap();
2634 gExit := EXIT_QUIT;
2635 sys_RequestQuit;
2636 end;
2638 procedure g_Game_FreeData();
2639 begin
2640 if not DataLoaded then Exit;
2642 g_Items_FreeData();
2643 g_Weapon_FreeData();
2644 g_Monsters_FreeData();
2646 e_WriteLog('Releasing game data...', TMsgType.Notify);
2648 g_Texture_Delete('NOTEXTURE');
2649 g_Texture_Delete('TEXTURE_PLAYER_HUD');
2650 g_Texture_Delete('TEXTURE_PLAYER_HUDBG');
2651 g_Texture_Delete('TEXTURE_PLAYER_ARMORHUD');
2652 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG');
2653 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_S');
2654 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_D');
2655 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG');
2656 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_S');
2657 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_D');
2658 g_Texture_Delete('TEXTURE_PLAYER_TALKBUBBLE');
2659 g_Texture_Delete('TEXTURE_PLAYER_INVULPENTA');
2660 g_Frames_DeleteByName('FRAMES_TELEPORT');
2661 g_Frames_DeleteByName('FRAMES_PUNCH');
2662 g_Frames_DeleteByName('FRAMES_PUNCH_UP');
2663 g_Frames_DeleteByName('FRAMES_PUNCH_DN');
2664 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK');
2665 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK_UP');
2666 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK_DN');
2667 g_Sound_Delete('SOUND_GAME_TELEPORT');
2668 g_Sound_Delete('SOUND_GAME_NOTELEPORT');
2669 g_Sound_Delete('SOUND_GAME_SECRET');
2670 g_Sound_Delete('SOUND_GAME_DOOROPEN');
2671 g_Sound_Delete('SOUND_GAME_DOORCLOSE');
2672 g_Sound_Delete('SOUND_GAME_BULK1');
2673 g_Sound_Delete('SOUND_GAME_BULK2');
2674 g_Sound_Delete('SOUND_GAME_BUBBLE1');
2675 g_Sound_Delete('SOUND_GAME_BUBBLE2');
2676 g_Sound_Delete('SOUND_GAME_BURNING');
2677 g_Sound_Delete('SOUND_GAME_SWITCH1');
2678 g_Sound_Delete('SOUND_GAME_SWITCH0');
2680 goodsnd[0].Free();
2681 goodsnd[1].Free();
2682 goodsnd[2].Free();
2683 goodsnd[3].Free();
2685 g_Sound_Delete('SOUND_ANNOUNCER_GOOD1');
2686 g_Sound_Delete('SOUND_ANNOUNCER_GOOD2');
2687 g_Sound_Delete('SOUND_ANNOUNCER_GOOD3');
2688 g_Sound_Delete('SOUND_ANNOUNCER_GOOD4');
2690 killsnd[0].Free();
2691 killsnd[1].Free();
2692 killsnd[2].Free();
2693 killsnd[3].Free();
2695 g_Sound_Delete('SOUND_ANNOUNCER_KILL2X');
2696 g_Sound_Delete('SOUND_ANNOUNCER_KILL3X');
2697 g_Sound_Delete('SOUND_ANNOUNCER_KILL4X');
2698 g_Sound_Delete('SOUND_ANNOUNCER_KILLMX');
2700 hahasnd[0].Free();
2701 hahasnd[1].Free();
2702 hahasnd[2].Free();
2704 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA1');
2705 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA2');
2706 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA3');
2708 sound_get_flag[0].Free();
2709 sound_get_flag[1].Free();
2710 sound_lost_flag[0].Free();
2711 sound_lost_flag[1].Free();
2712 sound_ret_flag[0].Free();
2713 sound_ret_flag[1].Free();
2714 sound_cap_flag[0].Free();
2715 sound_cap_flag[1].Free();
2717 g_Sound_Delete('SOUND_CTF_GET1');
2718 g_Sound_Delete('SOUND_CTF_GET2');
2719 g_Sound_Delete('SOUND_CTF_LOST1');
2720 g_Sound_Delete('SOUND_CTF_LOST2');
2721 g_Sound_Delete('SOUND_CTF_RETURN1');
2722 g_Sound_Delete('SOUND_CTF_RETURN2');
2723 g_Sound_Delete('SOUND_CTF_CAPTURE1');
2724 g_Sound_Delete('SOUND_CTF_CAPTURE2');
2726 g_Game_FreeChatSounds();
2728 DataLoaded := False;
2729 end;
2731 procedure g_FatalError(Text: String);
2732 begin
2733 g_Console_Add(Format(_lc[I_FATAL_ERROR], [Text]), True);
2734 e_WriteLog(Format(_lc[I_FATAL_ERROR], [Text]), TMsgType.Warning);
2736 gExit := EXIT_SIMPLE;
2737 if gGameOn then EndGame;
2738 end;
2740 procedure g_SimpleError(Text: String);
2741 begin
2742 g_Console_Add(Format(_lc[I_SIMPLE_ERROR], [Text]), True);
2743 e_WriteLog(Format(_lc[I_SIMPLE_ERROR], [Text]), TMsgType.Warning);
2744 end;
2746 procedure g_Game_SetupScreenSize();
2747 const
2748 RES_FACTOR = 4.0 / 3.0;
2749 var
2750 s: Single;
2751 rf: Single;
2752 bw, bh: Word;
2753 begin
2754 // Размер экранов игроков:
2755 gPlayerScreenSize.X := gScreenWidth-196;
2756 if (gPlayer1 <> nil) and (gPlayer2 <> nil) then
2757 gPlayerScreenSize.Y := gScreenHeight div 2
2758 else
2759 gPlayerScreenSize.Y := gScreenHeight;
2761 // Размер заднего плана:
2762 if BackID <> DWORD(-1) then
2763 begin
2764 s := SKY_STRETCH;
2765 if (gScreenWidth*s > gMapInfo.Width) or
2766 (gScreenHeight*s > gMapInfo.Height) then
2767 begin
2768 gBackSize.X := gScreenWidth;
2769 gBackSize.Y := gScreenHeight;
2770 end
2771 else
2772 begin
2773 e_GetTextureSize(BackID, @bw, @bh);
2774 rf := Single(bw) / Single(bh);
2775 if (rf > RES_FACTOR) then bw := Round(Single(bh) * RES_FACTOR)
2776 else if (rf < RES_FACTOR) then bh := Round(Single(bw) / RES_FACTOR);
2777 s := Max(gScreenWidth / bw, gScreenHeight / bh);
2778 if (s < 1.0) then s := 1.0;
2779 gBackSize.X := Round(bw*s);
2780 gBackSize.Y := Round(bh*s);
2781 end;
2782 end;
2783 end;
2785 procedure g_Game_ChangeResolution(newWidth, newHeight: Word; nowFull, nowMax: Boolean);
2786 begin
2787 sys_SetDisplayMode(newWidth, newHeight, gBPP, nowFull, nowMax);
2788 end;
2790 procedure g_Game_AddPlayer(Team: Byte = TEAM_NONE);
2791 begin
2792 if ((not gGameOn) and (gState <> STATE_INTERCUSTOM))
2793 or (not (gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT])) then
2794 Exit;
2796 if (gGameSettings.MaxLives > 0) and (gLMSRespawn = LMS_RESPAWN_NONE) then
2797 Exit;
2799 if gPlayer1 = nil then
2800 begin
2801 if g_Game_IsClient then
2802 begin
2803 if NetPlrUID1 > -1 then
2804 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE);
2805 Exit;
2806 end;
2808 if not (Team in [TEAM_RED, TEAM_BLUE]) then
2809 Team := gPlayer1Settings.Team;
2811 // Создание первого игрока:
2812 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
2813 gPlayer1Settings.Color,
2814 Team, False));
2815 if gPlayer1 = nil then
2816 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]))
2817 else
2818 begin
2819 gPlayer1.Name := gPlayer1Settings.Name;
2820 g_Console_Add(Format(_lc[I_PLAYER_JOIN], [gPlayer1.Name]), True);
2821 if g_Game_IsServer and g_Game_IsNet then
2822 MH_SEND_PlayerCreate(gPlayer1.UID);
2823 gPlayer1.Respawn(False, True);
2824 g_Net_Slist_ServerPlayerComes();
2825 end;
2827 Exit;
2828 end;
2829 if gPlayer2 = nil then
2830 begin
2831 if g_Game_IsClient then
2832 begin
2833 if NetPlrUID2 > -1 then
2834 gPlayer2 := g_Player_Get(NetPlrUID2);
2835 Exit;
2836 end;
2838 if not (Team in [TEAM_RED, TEAM_BLUE]) then
2839 Team := gPlayer2Settings.Team;
2841 // Создание второго игрока:
2842 gPlayer2 := g_Player_Get(g_Player_Create(gPlayer2Settings.Model,
2843 gPlayer2Settings.Color,
2844 Team, False));
2845 if gPlayer2 = nil then
2846 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [2]))
2847 else
2848 begin
2849 gPlayer2.Name := gPlayer2Settings.Name;
2850 g_Console_Add(Format(_lc[I_PLAYER_JOIN], [gPlayer2.Name]), True);
2851 if g_Game_IsServer and g_Game_IsNet then
2852 MH_SEND_PlayerCreate(gPlayer2.UID);
2853 gPlayer2.Respawn(False, True);
2854 g_Net_Slist_ServerPlayerComes();
2855 end;
2857 Exit;
2858 end;
2859 end;
2861 procedure g_Game_RemovePlayer();
2862 var
2863 Pl: TPlayer;
2864 begin
2865 if ((not gGameOn) and (gState <> STATE_INTERCUSTOM))
2866 or (not (gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT])) then
2867 Exit;
2868 Pl := gPlayer2;
2869 if Pl <> nil then
2870 begin
2871 if g_Game_IsServer then
2872 begin
2873 Pl.Lives := 0;
2874 Pl.Kill(K_SIMPLEKILL, 0, HIT_DISCON);
2875 g_Console_Add(Format(_lc[I_PLAYER_LEAVE], [Pl.Name]), True);
2876 g_Player_Remove(Pl.UID);
2877 g_Net_Slist_ServerPlayerLeaves();
2878 end
2879 else
2880 begin
2881 gSpectLatchPID2 := Pl.UID;
2882 gPlayer2 := nil;
2883 end;
2884 Exit;
2885 end;
2886 Pl := gPlayer1;
2887 if Pl <> nil then
2888 begin
2889 if g_Game_IsServer then
2890 begin
2891 Pl.Lives := 0;
2892 Pl.Kill(K_SIMPLEKILL, 0, HIT_DISCON);
2893 g_Console_Add(Format(_lc[I_PLAYER_LEAVE], [Pl.Name]), True);
2894 g_Player_Remove(Pl.UID);
2895 g_Net_Slist_ServerPlayerLeaves();
2896 end else
2897 begin
2898 gSpectLatchPID1 := Pl.UID;
2899 gPlayer1 := nil;
2900 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE);
2901 end;
2902 Exit;
2903 end;
2904 g_Net_Slist_ServerPlayerLeaves();
2905 end;
2907 procedure g_Game_Spectate();
2908 begin
2909 g_Game_RemovePlayer();
2910 if gPlayer1 <> nil then
2911 g_Game_RemovePlayer();
2912 end;
2914 procedure g_Game_SpectateCenterView();
2915 begin
2916 gSpectX := Max(gMapInfo.Width div 2 - gScreenWidth div 2, 0);
2917 gSpectY := Max(gMapInfo.Height div 2 - gScreenHeight div 2, 0);
2918 end;
2920 procedure g_Game_StartSingle(Map: String; TwoPlayers: Boolean; nPlayers: Byte);
2921 var
2922 i, nPl: Integer;
2923 tmps: AnsiString;
2924 begin
2925 g_Game_Free();
2927 e_WriteLog('Starting singleplayer game...', TMsgType.Notify);
2929 g_Game_ClearLoading();
2931 // Настройки игры:
2932 FillByte(gGameSettings, SizeOf(TGameSettings), 0);
2933 gAimLine := False;
2934 gShowMap := False;
2935 gGameSettings.GameType := GT_SINGLE;
2936 gGameSettings.MaxLives := 0;
2937 gGameSettings.Options := gGameSettings.Options + GAME_OPTION_ALLOWEXIT;
2938 gGameSettings.Options := gGameSettings.Options + GAME_OPTION_MONSTERS;
2939 gGameSettings.Options := gGameSettings.Options + GAME_OPTION_BOTVSMONSTER;
2940 gGameSettings.Options := gGameSettings.Options + GAME_OPTION_TEAMHITPROJECTILE;
2941 gGameSettings.Options := gGameSettings.Options + GAME_OPTION_TEAMHITTRACE;
2942 gSwitchGameMode := GM_SINGLE;
2944 gLMSRespawn := LMS_RESPAWN_NONE;
2945 gLMSRespawnTime := 0;
2946 gSpectLatchPID1 := 0;
2947 gSpectLatchPID2 := 0;
2949 g_Game_ExecuteEvent('ongamestart');
2951 // Установка размеров окон игроков:
2952 g_Game_SetupScreenSize();
2954 // Создание первого игрока:
2955 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
2956 gPlayer1Settings.Color,
2957 gPlayer1Settings.Team, False));
2958 if gPlayer1 = nil then
2959 begin
2960 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]));
2961 Exit;
2962 end;
2964 gPlayer1.Name := gPlayer1Settings.Name;
2965 nPl := 1;
2967 // Создание второго игрока, если есть:
2968 if TwoPlayers then
2969 begin
2970 gPlayer2 := g_Player_Get(g_Player_Create(gPlayer2Settings.Model,
2971 gPlayer2Settings.Color,
2972 gPlayer2Settings.Team, False));
2973 if gPlayer2 = nil then
2974 begin
2975 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [2]));
2976 Exit;
2977 end;
2979 gPlayer2.Name := gPlayer2Settings.Name;
2980 Inc(nPl);
2981 end;
2983 // Загрузка и запуск карты:
2984 if not g_Game_StartMap(false{asMegawad}, MAP, True) then
2985 begin
2986 if (Pos(':\', Map) > 0) or (Pos(':/', Map) > 0) then tmps := Map else tmps := gGameSettings.WAD + ':\' + MAP;
2987 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [tmps]));
2988 Exit;
2989 end;
2991 // Настройки игроков и ботов:
2992 g_Player_Init();
2994 // Создаем ботов:
2995 for i := nPl+1 to nPlayers do
2996 g_Player_Create(STD_PLAYER_MODEL, _RGB(0, 0, 0), 0, True);
2997 end;
2999 procedure g_Game_StartCustom(Map: String; GameMode: Byte;
3000 TimeLimit, GoalLimit: Word;
3001 MaxLives: Byte;
3002 Options: LongWord; nPlayers: Byte);
3003 var
3004 i, nPl: Integer;
3005 begin
3006 g_Game_Free();
3008 e_WriteLog('Starting custom game...', TMsgType.Notify);
3010 g_Game_ClearLoading();
3012 // Настройки игры:
3013 gGameSettings.GameType := GT_CUSTOM;
3014 gGameSettings.GameMode := GameMode;
3015 gSwitchGameMode := GameMode;
3016 gGameSettings.TimeLimit := TimeLimit;
3017 gGameSettings.GoalLimit := GoalLimit;
3018 gGameSettings.MaxLives := IfThen(GameMode = GM_CTF, 0, MaxLives);
3019 gGameSettings.Options := Options;
3021 gCoopTotalMonstersKilled := 0;
3022 gCoopTotalSecretsFound := 0;
3023 gCoopTotalMonsters := 0;
3024 gCoopTotalSecrets := 0;
3025 gAimLine := False;
3026 gShowMap := False;
3028 gLMSRespawn := LMS_RESPAWN_NONE;
3029 gLMSRespawnTime := 0;
3030 gSpectLatchPID1 := 0;
3031 gSpectLatchPID2 := 0;
3033 g_Game_ExecuteEvent('ongamestart');
3035 // Установка размеров окон игроков:
3036 g_Game_SetupScreenSize();
3038 // Режим наблюдателя:
3039 if nPlayers = 0 then
3040 begin
3041 gPlayer1 := nil;
3042 gPlayer2 := nil;
3043 end;
3045 nPl := 0;
3046 if nPlayers >= 1 then
3047 begin
3048 // Создание первого игрока:
3049 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
3050 gPlayer1Settings.Color,
3051 gPlayer1Settings.Team, False));
3052 if gPlayer1 = nil then
3053 begin
3054 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]));
3055 Exit;
3056 end;
3058 gPlayer1.Name := gPlayer1Settings.Name;
3059 Inc(nPl);
3060 end;
3062 if nPlayers >= 2 then
3063 begin
3064 // Создание второго игрока:
3065 gPlayer2 := g_Player_Get(g_Player_Create(gPlayer2Settings.Model,
3066 gPlayer2Settings.Color,
3067 gPlayer2Settings.Team, False));
3068 if gPlayer2 = nil then
3069 begin
3070 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [2]));
3071 Exit;
3072 end;
3074 gPlayer2.Name := gPlayer2Settings.Name;
3075 Inc(nPl);
3076 end;
3078 // Загрузка и запуск карты:
3079 if not g_Game_StartMap(true{asMegawad}, Map, True) then
3080 begin
3081 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [Map]));
3082 Exit;
3083 end;
3085 // Нет точек появления:
3086 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1) +
3087 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2) +
3088 g_Map_GetPointCount(RESPAWNPOINT_DM) +
3089 g_Map_GetPointCount(RESPAWNPOINT_RED)+
3090 g_Map_GetPointCount(RESPAWNPOINT_BLUE)) < 1 then
3091 begin
3092 g_FatalError(_lc[I_GAME_ERROR_GET_SPAWN]);
3093 Exit;
3094 end;
3096 // Настройки игроков и ботов:
3097 g_Player_Init();
3099 // Создаем ботов:
3100 for i := nPl+1 to nPlayers do
3101 g_Player_Create(STD_PLAYER_MODEL, _RGB(0, 0, 0), 0, True);
3102 end;
3104 procedure g_Game_StartServer(Map: String; GameMode: Byte;
3105 TimeLimit, GoalLimit: Word; MaxLives: Byte;
3106 Options: LongWord; nPlayers: Byte;
3107 IPAddr: LongWord; Port: Word);
3108 begin
3109 g_Game_Free();
3110 g_Net_Slist_ServerClosed();
3112 e_WriteLog('Starting net game (server)...', TMsgType.Notify);
3114 g_Game_ClearLoading();
3116 // Настройки игры:
3117 gGameSettings.GameType := GT_SERVER;
3118 gGameSettings.GameMode := GameMode;
3119 gSwitchGameMode := GameMode;
3120 gGameSettings.TimeLimit := TimeLimit;
3121 gGameSettings.GoalLimit := GoalLimit;
3122 gGameSettings.MaxLives := IfThen(GameMode = GM_CTF, 0, MaxLives);
3123 gGameSettings.Options := Options;
3125 gCoopTotalMonstersKilled := 0;
3126 gCoopTotalSecretsFound := 0;
3127 gCoopTotalMonsters := 0;
3128 gCoopTotalSecrets := 0;
3129 gAimLine := False;
3130 gShowMap := False;
3132 gLMSRespawn := LMS_RESPAWN_NONE;
3133 gLMSRespawnTime := 0;
3134 gSpectLatchPID1 := 0;
3135 gSpectLatchPID2 := 0;
3137 g_Game_ExecuteEvent('ongamestart');
3139 // Установка размеров окна игрока
3140 g_Game_SetupScreenSize();
3142 // Режим наблюдателя:
3143 if nPlayers = 0 then
3144 begin
3145 gPlayer1 := nil;
3146 gPlayer2 := nil;
3147 end;
3149 if nPlayers >= 1 then
3150 begin
3151 // Создание первого игрока:
3152 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
3153 gPlayer1Settings.Color,
3154 gPlayer1Settings.Team, False));
3155 if gPlayer1 = nil then
3156 begin
3157 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]));
3158 Exit;
3159 end;
3161 gPlayer1.Name := gPlayer1Settings.Name;
3162 end;
3164 if nPlayers >= 2 then
3165 begin
3166 // Создание второго игрока:
3167 gPlayer2 := g_Player_Get(g_Player_Create(gPlayer2Settings.Model,
3168 gPlayer2Settings.Color,
3169 gPlayer2Settings.Team, False));
3170 if gPlayer2 = nil then
3171 begin
3172 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [2]));
3173 Exit;
3174 end;
3176 gPlayer2.Name := gPlayer2Settings.Name;
3177 end;
3179 g_Game_SetLoadingText(_lc[I_LOAD_HOST], 0, False);
3180 if NetForwardPorts then
3181 g_Game_SetLoadingText(_lc[I_LOAD_PORTS], 0, False);
3183 // Стартуем сервер
3184 if not g_Net_Host(IPAddr, Port, NetMaxClients) then
3185 begin
3186 g_FatalError(_lc[I_NET_MSG] + Format(_lc[I_NET_ERR_HOST], [Port]));
3187 Exit;
3188 end;
3190 g_Net_Slist_Set(NetMasterList);
3192 g_Net_Slist_ServerStarted();
3194 // Загрузка и запуск карты:
3195 if not g_Game_StartMap(false{asMegawad}, Map, True) then
3196 begin
3197 g_Net_Slist_ServerClosed();
3198 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [Map]));
3199 Exit;
3200 end;
3202 // Нет точек появления:
3203 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1) +
3204 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2) +
3205 g_Map_GetPointCount(RESPAWNPOINT_DM) +
3206 g_Map_GetPointCount(RESPAWNPOINT_RED)+
3207 g_Map_GetPointCount(RESPAWNPOINT_BLUE)) < 1 then
3208 begin
3209 g_Net_Slist_ServerClosed();
3210 g_FatalError(_lc[I_GAME_ERROR_GET_SPAWN]);
3211 Exit;
3212 end;
3214 // Настройки игроков и ботов:
3215 g_Player_Init();
3217 g_Net_Slist_ServerMapStarted();
3218 NetState := NET_STATE_GAME;
3219 end;
3221 procedure g_Game_StartClient(Addr: String; Port: Word; PW: String);
3222 var
3223 Map: String;
3224 WadName: string;
3225 Ptr: Pointer;
3226 T: Cardinal;
3227 MID: Byte;
3228 State: Byte;
3229 OuterLoop: Boolean;
3230 newResPath: string;
3231 InMsg: TMsg;
3232 begin
3233 g_Game_Free();
3235 State := 0;
3236 e_WriteLog('Starting net game (client)...', TMsgType.Notify);
3237 e_WriteLog('NET: Trying to connect to ' + Addr + ':' + IntToStr(Port) + '...', TMsgType.Notify);
3239 g_Game_ClearLoading();
3241 // Настройки игры:
3242 gGameSettings.GameType := GT_CLIENT;
3244 gCoopTotalMonstersKilled := 0;
3245 gCoopTotalSecretsFound := 0;
3246 gCoopTotalMonsters := 0;
3247 gCoopTotalSecrets := 0;
3248 gAimLine := False;
3249 gShowMap := False;
3251 g_Game_ExecuteEvent('ongamestart');
3253 // Установка размеров окон игроков:
3254 g_Game_SetupScreenSize();
3256 NetState := NET_STATE_AUTH;
3258 g_Game_SetLoadingText(_lc[I_LOAD_CONNECT], 0, False);
3260 // create (or update) map/resource databases
3261 g_Res_CreateDatabases(true);
3263 gLMSRespawn := LMS_RESPAWN_NONE;
3264 gLMSRespawnTime := 0;
3265 gSpectLatchPID1 := 0;
3266 gSpectLatchPID2 := 0;
3268 // Стартуем клиент
3269 if not g_Net_Connect(Addr, Port) then
3270 begin
3271 g_FatalError(_lc[I_NET_MSG] + _lc[I_NET_ERR_CONN]);
3272 NetState := NET_STATE_NONE;
3273 Exit;
3274 end;
3276 g_Game_SetLoadingText(_lc[I_LOAD_SEND_INFO], 0, False);
3277 MC_SEND_Info(PW);
3278 g_Game_SetLoadingText(_lc[I_LOAD_WAIT_INFO], 0, False);
3280 OuterLoop := True;
3281 while OuterLoop do
3282 begin
3283 // fuck! https://www.mail-archive.com/enet-discuss@cubik.org/msg00852.html
3284 // tl;dr: on shitdows, we can get -1 sometimes, and it is *NOT* a failure.
3285 // thank you, enet. let's ignore failures altogether then.
3286 while (enet_host_service(NetHost, @NetEvent, 50) > 0) do
3287 begin
3288 if (NetEvent.kind = ENET_EVENT_TYPE_RECEIVE) then
3289 begin
3290 if (NetEvent.channelID = NET_CHAN_DOWNLOAD_EX) then
3291 begin
3292 // ignore all download packets, they're processed by separate code
3293 enet_packet_destroy(NetEvent.packet);
3294 continue;
3295 end;
3296 Ptr := NetEvent.packet^.data;
3297 if not InMsg.Init(Ptr, NetEvent.packet^.dataLength, True) then
3298 begin
3299 enet_packet_destroy(NetEvent.packet);
3300 continue;
3301 end;
3303 InMsg.ReadLongWord(); // skip size
3304 MID := InMsg.ReadByte();
3306 if (MID = NET_MSG_INFO) and (State = 0) then
3307 begin
3308 NetMyID := InMsg.ReadByte();
3309 NetPlrUID1 := InMsg.ReadWord();
3311 WadName := InMsg.ReadString();
3312 Map := InMsg.ReadString();
3314 gWADHash := InMsg.ReadMD5();
3316 gGameSettings.GameMode := InMsg.ReadByte();
3317 gSwitchGameMode := gGameSettings.GameMode;
3318 gGameSettings.GoalLimit := InMsg.ReadWord();
3319 gGameSettings.TimeLimit := InMsg.ReadWord();
3320 gGameSettings.MaxLives := InMsg.ReadByte();
3321 gGameSettings.Options := InMsg.ReadLongWord();
3322 T := InMsg.ReadLongWord();
3324 //newResPath := g_Res_SearchSameWAD(MapsDir, WadName, gWADHash);
3325 //if newResPath = '' then
3326 begin
3327 //g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
3328 newResPath := g_Res_DownloadMapWAD(ExtractFileName(WadName), gWADHash);
3329 if newResPath = '' then
3330 begin
3331 g_FatalError(_lc[I_NET_ERR_HASH]);
3332 enet_packet_destroy(NetEvent.packet);
3333 NetState := NET_STATE_NONE;
3334 Exit;
3335 end;
3336 e_LogWritefln('using downloaded map wad [%s] for [%s]`', [newResPath, WadName], TMsgType.Notify);
3337 end;
3338 //newResPath := ExtractRelativePath(MapsDir, newResPath);
3341 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
3342 gPlayer1Settings.Color,
3343 gPlayer1Settings.Team, False));
3345 if gPlayer1 = nil then
3346 begin
3347 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]));
3349 enet_packet_destroy(NetEvent.packet);
3350 NetState := NET_STATE_NONE;
3351 Exit;
3352 end;
3354 gPlayer1.Name := gPlayer1Settings.Name;
3355 gPlayer1.UID := NetPlrUID1;
3356 gPlayer1.Reset(True);
3358 if not g_Game_StartMap(false{asMegawad}, newResPath + ':\' + Map, True) then
3359 begin
3360 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [WadName + ':\' + Map]));
3362 enet_packet_destroy(NetEvent.packet);
3363 NetState := NET_STATE_NONE;
3364 Exit;
3365 end;
3367 gTime := T;
3369 State := 1;
3370 OuterLoop := False;
3371 enet_packet_destroy(NetEvent.packet);
3372 break;
3373 end
3374 else
3375 enet_packet_destroy(NetEvent.packet);
3376 end
3377 else
3378 begin
3379 if (NetEvent.kind = ENET_EVENT_TYPE_DISCONNECT) then
3380 begin
3381 State := 0;
3382 if (NetEvent.data <= NET_DISC_MAX) then
3383 g_Console_Add(_lc[I_NET_MSG_ERROR] + _lc[I_NET_ERR_CONN] + ' ' +
3384 _lc[TStrings_Locale(Cardinal(I_NET_DISC_NONE) + NetEvent.data)], True);
3385 OuterLoop := False;
3386 Break;
3387 end;
3388 end;
3389 end;
3391 ProcessLoading(true);
3393 if g_Net_UserRequestExit() then
3394 begin
3395 State := 0;
3396 break;
3397 end;
3398 end;
3400 if State <> 1 then
3401 begin
3402 g_FatalError(_lc[I_NET_MSG] + _lc[I_NET_ERR_CONN]);
3403 NetState := NET_STATE_NONE;
3404 Exit;
3405 end;
3407 g_Player_Init();
3408 NetState := NET_STATE_GAME;
3409 MC_SEND_FullStateRequest;
3410 e_WriteLog('NET: Connection successful.', TMsgType.Notify);
3411 end;
3413 var
3414 lastAsMegaWad: Boolean = false;
3416 procedure g_Game_ChangeMap(const MapPath: String);
3417 var
3418 Force: Boolean;
3419 begin
3420 g_Game_ClearLoading();
3422 Force := gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF];
3423 // Если уровень завершился по триггеру Выход, не очищать инвентарь
3424 if gExitByTrigger then
3425 begin
3426 Force := False;
3427 gExitByTrigger := False;
3428 end;
3429 if not g_Game_StartMap(lastAsMegaWad, MapPath, Force) then
3430 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [MapPath]));
3431 end;
3433 procedure g_Game_Restart();
3434 var
3435 Map: string;
3436 begin
3437 if g_Game_IsClient then
3438 Exit;
3439 map := g_ExtractFileName(gMapInfo.Map);
3440 e_LogWritefln('g_Game_Restart: map = "%s" gCurrentMapFileName = "%s"', [map, gCurrentMapFileName]);
3442 MessageTime := 0;
3443 gGameOn := False;
3444 g_Game_ClearLoading();
3445 g_Game_StartMap(lastAsMegaWad, Map, True, gCurrentMapFileName);
3446 end;
3448 function g_Game_StartMap (asMegawad: Boolean; Map: String; Force: Boolean = False; const oldMapPath: AnsiString=''): Boolean;
3449 var
3450 NewWAD, ResName: String;
3451 I: Integer;
3452 nws: AnsiString;
3453 begin
3454 g_Map_Free((Map <> gCurrentMapFileName) and (oldMapPath <> gCurrentMapFileName));
3455 g_Player_RemoveAllCorpses();
3457 if (not g_Game_IsClient) and
3458 (gSwitchGameMode <> gGameSettings.GameMode) and
3459 (gGameSettings.GameMode <> GM_SINGLE) then
3460 begin
3461 if gSwitchGameMode = GM_CTF then
3462 gGameSettings.MaxLives := 0;
3463 gGameSettings.GameMode := gSwitchGameMode;
3464 Force := True;
3465 end else
3466 gSwitchGameMode := gGameSettings.GameMode;
3468 g_Player_ResetTeams();
3470 lastAsMegaWad := asMegawad;
3471 if isWadPath(Map) then
3472 begin
3473 NewWAD := g_ExtractWadName(Map);
3474 ResName := g_ExtractFileName(Map);
3475 if g_Game_IsServer then
3476 begin
3477 nws := findDiskWad(NewWAD);
3478 //writeln('000: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
3479 if (asMegawad) then
3480 begin
3481 if (length(nws) = 0) then nws := e_FindWad(MegawadDirs, NewWAD);
3482 if (length(nws) = 0) then nws := e_FindWad(MapDirs, NewWAD);
3483 end
3484 else
3485 begin
3486 if (length(nws) = 0) then nws := e_FindWad(MapDirs, NewWAD);
3487 if (length(nws) = 0) then nws := e_FindWad(MegawadDirs, NewWAD);
3488 end;
3489 //if (length(nws) = 0) then nws := e_FindWad(MapDownloadDirs, NewWAD);
3490 //writeln('001: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
3491 //nws := NewWAD;
3492 if (length(nws) = 0) then
3493 begin
3494 ResName := ''; // failed
3495 end
3496 else
3497 begin
3498 NewWAD := nws;
3499 if (g_Game_IsNet) then gWADHash := MD5File(nws);
3500 //writeln('********: nws=', nws, ' : Map=', Map, ' : nw=', NewWAD, ' : resname=', ResName);
3501 g_Game_LoadWAD(NewWAD);
3502 end;
3503 end
3504 else
3505 begin
3506 // hash received in MC_RECV_GameEvent -> NET_EV_MAPSTART
3507 NewWAD := g_Game_ClientWAD(NewWAD, gWADHash);
3508 end;
3509 end
3510 else
3511 begin
3512 NewWAD := gGameSettings.WAD;
3513 ResName := Map;
3514 end;
3516 gTime := 0;
3518 //writeln('********: gsw=', gGameSettings.WAD, '; rn=', ResName);
3519 result := false;
3520 if (ResName <> '') and (NewWAD <> '') then
3521 begin
3522 //result := g_Map_Load(gGameSettings.WAD + ':\' + ResName);
3523 result := g_Map_Load(NewWAD+':\'+ResName);
3524 end;
3525 if Result then
3526 begin
3527 g_Player_ResetAll(Force or gLastMap, gGameSettings.GameType = GT_SINGLE);
3529 gState := STATE_NONE;
3530 g_ActiveWindow := nil;
3531 gGameOn := True;
3533 DisableCheats();
3534 wNeedTimeReset := True;
3536 if gGameSettings.GameMode = GM_CTF then
3537 begin
3538 g_Map_ResetFlag(FLAG_RED);
3539 g_Map_ResetFlag(FLAG_BLUE);
3540 // CTF, а флагов нет:
3541 if not g_Map_HaveFlagPoints() then
3542 g_SimpleError(_lc[I_GAME_ERROR_CTF]);
3543 end;
3544 end
3545 else
3546 begin
3547 gState := STATE_MENU;
3548 gGameOn := False;
3549 end;
3551 gExit := 0;
3552 gPauseMain := false;
3553 gPauseHolmes := false;
3554 NetTimeToUpdate := 1;
3555 NetTimeToReliable := 0;
3556 NetTimeToMaster := NetMasterRate;
3557 gSpectLatchPID1 := 0;
3558 gSpectLatchPID2 := 0;
3559 gMissionFailed := False;
3560 gNextMap := '';
3562 gCoopMonstersKilled := 0;
3563 gCoopSecretsFound := 0;
3565 gVoteInProgress := False;
3566 gVotePassed := False;
3567 gVoteCount := 0;
3568 gVoted := False;
3570 gStatsOff := False;
3572 if not gGameOn then Exit;
3574 g_Game_SpectateCenterView();
3576 if g_Game_IsServer then
3577 begin
3578 if (gGameSettings.MaxLives > 0) and (gGameSettings.WarmupTime > 0) then
3579 begin
3580 gLMSRespawn := LMS_RESPAWN_WARMUP;
3581 gLMSRespawnTime := gTime + gGameSettings.WarmupTime*1000;
3582 gLMSSoftSpawn := True;
3583 if g_Game_IsNet then
3584 MH_SEND_GameEvent(NET_EV_LMS_WARMUP, gLMSRespawnTime - gTime);
3585 end
3586 else
3587 begin
3588 gLMSRespawn := LMS_RESPAWN_NONE;
3589 gLMSRespawnTime := 0;
3590 end;
3591 end;
3593 if NetMode = NET_SERVER then
3594 begin
3595 MH_SEND_GameEvent(NET_EV_MAPSTART, gGameSettings.GameMode, Map);
3597 // Мастерсервер
3598 g_Net_Slist_ServerMapStarted();
3600 if NetClients <> nil then
3601 for I := 0 to High(NetClients) do
3602 if NetClients[I].Used then
3603 begin
3604 NetClients[I].Voted := False;
3605 if NetClients[I].RequestedFullUpdate then
3606 begin
3607 MH_SEND_Everything((NetClients[I].State = NET_STATE_AUTH), I);
3608 NetClients[I].RequestedFullUpdate := False;
3609 end;
3610 end;
3612 g_Net_UnbanNonPermHosts();
3613 end;
3615 if gLastMap then
3616 begin
3617 gCoopTotalMonstersKilled := 0;
3618 gCoopTotalSecretsFound := 0;
3619 gCoopTotalMonsters := 0;
3620 gCoopTotalSecrets := 0;
3621 gLastMap := False;
3622 end;
3624 g_Game_ExecuteEvent('onmapstart');
3625 end;
3627 procedure SetFirstLevel;
3628 begin
3629 gNextMap := '';
3631 MapList := g_Map_GetMapsList(gGameSettings.WAD);
3632 if MapList = nil then
3633 Exit;
3635 SortSArray(MapList);
3636 gNextMap := MapList[Low(MapList)];
3638 MapList := nil;
3639 end;
3641 procedure g_Game_ExitLevel(const Map: AnsiString);
3642 begin
3643 gNextMap := Map;
3645 gCoopTotalMonstersKilled := gCoopTotalMonstersKilled + gCoopMonstersKilled;
3646 gCoopTotalSecretsFound := gCoopTotalSecretsFound + gCoopSecretsFound;
3647 gCoopTotalMonsters := gCoopTotalMonsters + gTotalMonsters;
3648 gCoopTotalSecrets := gCoopTotalSecrets + gSecretsCount;
3650 // Вышли в выход в Одиночной игре:
3651 if gGameSettings.GameType = GT_SINGLE then
3652 gExit := EXIT_ENDLEVELSINGLE
3653 else // Вышли в выход в Своей игре
3654 begin
3655 gExit := EXIT_ENDLEVELCUSTOM;
3656 if gGameSettings.GameMode = GM_COOP then
3657 g_Player_RememberAll;
3659 if not g_Map_Exist(gGameSettings.WAD + ':\' + gNextMap) then
3660 begin
3661 gLastMap := True;
3662 if gGameSettings.GameMode = GM_COOP then
3663 gStatsOff := True;
3665 gStatsPressed := True;
3666 gNextMap := 'MAP01';
3668 if not g_Map_Exist(gGameSettings.WAD + ':\' + gNextMap) then
3669 g_Game_NextLevel;
3671 if g_Game_IsNet then
3672 begin
3673 MH_SEND_GameStats();
3674 MH_SEND_CoopStats();
3675 end;
3676 end;
3677 end;
3678 end;
3680 procedure g_Game_RestartLevel();
3681 var
3682 Map: string;
3683 begin
3684 if gGameSettings.GameMode = GM_SINGLE then
3685 begin
3686 g_Game_Restart();
3687 Exit;
3688 end;
3689 gExit := EXIT_ENDLEVELCUSTOM;
3690 Map := g_ExtractFileName(gMapInfo.Map);
3691 gNextMap := Map;
3692 end;
3694 function g_Game_ClientWAD (NewWAD: String; const WHash: TMD5Digest): AnsiString;
3695 var
3696 gWAD{, xwad}: String;
3697 begin
3698 result := NewWAD;
3699 if not g_Game_IsClient then Exit;
3700 //e_LogWritefln('*** g_Game_ClientWAD: `%s`', [NewWAD]);
3702 gWAD := g_Res_DownloadMapWAD(ExtractFileName(NewWAD), WHash);
3703 if gWAD = '' then
3704 begin
3705 result := '';
3706 g_Game_Free();
3707 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_WAD], [ExtractFileName(NewWAD)]));
3708 Exit;
3709 end;
3711 e_LogWritefln('using downloaded client map wad [%s] for [%s]', [gWAD, NewWAD], TMsgType.Notify);
3712 NewWAD := gWAD;
3714 g_Game_LoadWAD(NewWAD);
3715 result := NewWAD;
3718 if LowerCase(NewWAD) = LowerCase(gGameSettings.WAD) then Exit;
3719 gWAD := g_Res_SearchSameWAD(MapsDir, ExtractFileName(NewWAD), WHash);
3720 if gWAD = '' then
3721 begin
3722 g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
3723 gWAD := g_Res_DownloadMapWAD(ExtractFileName(NewWAD), WHash);
3724 if gWAD = '' then
3725 begin
3726 g_Game_Free();
3727 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_WAD], [ExtractFileName(NewWAD)]));
3728 Exit;
3729 end;
3730 end;
3731 NewWAD := ExtractRelativePath(MapsDir, gWAD);
3732 g_Game_LoadWAD(NewWAD);
3734 end;
3736 procedure g_Game_RestartRound(NoMapRestart: Boolean = False);
3737 var
3738 i, n, nb, nr: Integer;
3739 begin
3740 if not g_Game_IsServer then Exit;
3741 if gLMSRespawn = LMS_RESPAWN_NONE then Exit;
3742 gLMSRespawn := LMS_RESPAWN_NONE;
3743 gLMSRespawnTime := 0;
3744 MessageTime := 0;
3746 if (gGameSettings.GameMode = GM_COOP) and not NoMapRestart then
3747 begin
3748 gMissionFailed := True;
3749 g_Game_RestartLevel;
3750 Exit;
3751 end;
3753 n := 0; nb := 0; nr := 0;
3754 for i := Low(gPlayers) to High(gPlayers) do
3755 if (gPlayers[i] <> nil) and
3756 ((not gPlayers[i].FSpectator) or gPlayers[i].FWantsInGame or
3757 (gPlayers[i] is TBot)) then
3758 begin
3759 Inc(n);
3760 if gPlayers[i].Team = TEAM_RED then Inc(nr)
3761 else if gPlayers[i].Team = TEAM_BLUE then Inc(nb)
3762 end;
3764 if (n < 1) or ((gGameSettings.GameMode = GM_TDM) and ((nr = 0) or (nb = 0))) then
3765 begin
3766 // wait a second until the fuckers finally decide to join
3767 gLMSRespawn := LMS_RESPAWN_WARMUP;
3768 gLMSRespawnTime := gTime + gGameSettings.WarmupTime*1000;
3769 gLMSSoftSpawn := NoMapRestart;
3770 if g_Game_IsNet then
3771 MH_SEND_GameEvent(NET_EV_LMS_WARMUP, gLMSRespawnTime - gTime);
3772 Exit;
3773 end;
3775 g_Player_RemoveAllCorpses;
3776 g_Game_Message(_lc[I_MESSAGE_LMS_START], 144);
3777 if g_Game_IsNet then
3778 MH_SEND_GameEvent(NET_EV_LMS_START);
3780 for i := Low(gPlayers) to High(gPlayers) do
3781 begin
3782 if gPlayers[i] = nil then continue;
3783 if gPlayers[i] is TBot then gPlayers[i].FWantsInGame := True;
3784 // don't touch normal spectators
3785 if gPlayers[i].FSpectator and not gPlayers[i].FWantsInGame then
3786 begin
3787 gPlayers[i].FNoRespawn := True;
3788 gPlayers[i].Lives := 0;
3789 if g_Game_IsNet then
3790 MH_SEND_PlayerStats(gPlayers[I].UID);
3791 continue;
3792 end;
3793 gPlayers[i].FNoRespawn := False;
3794 gPlayers[i].Lives := gGameSettings.MaxLives;
3795 gPlayers[i].Respawn(False, True);
3796 if gGameSettings.GameMode = GM_COOP then
3797 begin
3798 gPlayers[i].Frags := 0;
3799 gPlayers[i].RecallState;
3800 end;
3801 if (gPlayer1 = nil) and (gSpectLatchPID1 > 0) then
3802 gPlayer1 := g_Player_Get(gSpectLatchPID1);
3803 if (gPlayer2 = nil) and (gSpectLatchPID2 > 0) then
3804 gPlayer2 := g_Player_Get(gSpectLatchPID2);
3805 end;
3807 g_Items_RestartRound();
3809 gLMSSoftSpawn := False;
3810 end;
3812 function g_Game_GetFirstMap(WAD: String): String;
3813 begin
3814 Result := '';
3816 MapList := g_Map_GetMapsList(WAD);
3817 if MapList = nil then
3818 Exit;
3820 SortSArray(MapList);
3821 Result := MapList[Low(MapList)];
3823 if not g_Map_Exist(WAD + ':\' + Result) then
3824 Result := '';
3826 MapList := nil;
3827 end;
3829 function g_Game_GetNextMap(): String;
3830 var
3831 I: Integer;
3832 Map: string;
3833 begin
3834 Result := '';
3836 MapList := g_Map_GetMapsList(gGameSettings.WAD);
3837 if MapList = nil then
3838 Exit;
3840 Map := g_ExtractFileName(gMapInfo.Map);
3842 SortSArray(MapList);
3843 MapIndex := -255;
3844 for I := Low(MapList) to High(MapList) do
3845 if Map = MapList[I] then
3846 begin
3847 MapIndex := I;
3848 Break;
3849 end;
3851 if MapIndex <> -255 then
3852 begin
3853 if MapIndex = High(MapList) then
3854 Result := MapList[Low(MapList)]
3855 else
3856 Result := MapList[MapIndex + 1];
3858 if not g_Map_Exist(gGameSettings.WAD + ':\' + Result) then Result := Map;
3859 end;
3861 MapList := nil;
3862 end;
3864 procedure g_Game_NextLevel();
3865 begin
3866 if gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF, GM_COOP] then
3867 gExit := EXIT_ENDLEVELCUSTOM
3868 else
3869 begin
3870 gExit := EXIT_ENDLEVELSINGLE;
3871 Exit;
3872 end;
3874 if gNextMap <> '' then Exit;
3875 gNextMap := g_Game_GetNextMap();
3876 end;
3878 function g_Game_IsTestMap(): Boolean;
3879 begin
3880 result := StrEquCI1251(TEST_MAP_NAME, g_ExtractFileName(gMapInfo.Map));
3881 end;
3883 procedure g_Game_DeleteTestMap();
3884 var
3885 a: Integer;
3886 //MapName: AnsiString;
3887 WadName: string;
3889 WAD: TWADFile;
3890 MapList: SSArray;
3891 time: Integer;
3893 begin
3894 a := Pos('.wad:\', toLowerCase1251(gMapToDelete));
3895 if (a = 0) then a := Pos('.wad:/', toLowerCase1251(gMapToDelete));
3896 if (a = 0) then exit;
3898 // Выделяем имя wad-файла и имя карты
3899 WadName := Copy(gMapToDelete, 1, a+3);
3900 Delete(gMapToDelete, 1, a+5);
3901 gMapToDelete := UpperCase(gMapToDelete);
3902 //MapName := '';
3903 //CopyMemory(@MapName[0], @gMapToDelete[1], Min(16, Length(gMapToDelete)));
3906 // Имя карты не стандартное тестовое:
3907 if MapName <> TEST_MAP_NAME then
3908 Exit;
3910 if not gTempDelete then
3911 begin
3912 time := g_GetFileTime(WadName);
3913 WAD := TWADFile.Create();
3915 // Читаем Wad-файл:
3916 if not WAD.ReadFile(WadName) then
3917 begin // Нет такого WAD-файла
3918 WAD.Free();
3919 Exit;
3920 end;
3922 // Составляем список карт и ищем нужную:
3923 WAD.CreateImage();
3924 MapList := WAD.GetResourcesList('');
3926 if MapList <> nil then
3927 for a := 0 to High(MapList) do
3928 if MapList[a] = MapName then
3929 begin
3930 // Удаляем и сохраняем:
3931 WAD.RemoveResource('', MapName);
3932 WAD.SaveTo(WadName);
3933 Break;
3934 end;
3936 WAD.Free();
3937 g_SetFileTime(WadName, time);
3938 end else
3940 if gTempDelete then DeleteFile(WadName);
3941 end;
3943 procedure GameCVars(P: SSArray);
3944 var
3945 a, b: Integer;
3946 stat: TPlayerStatArray;
3947 cmd: string;
3949 procedure ParseGameFlag(Flag: LongWord; OffMsg, OnMsg: TStrings_Locale; OnMapChange: Boolean = False);
3950 var
3951 x: Boolean;
3952 begin
3953 if Length(P) > 1 then
3954 begin
3955 x := P[1] = '1';
3957 if x then
3958 gsGameFlags := gsGameFlags or Flag
3959 else
3960 gsGameFlags := gsGameFlags and (not Flag);
3962 if g_Game_IsServer then
3963 begin
3964 if x then
3965 gGameSettings.Options := gGameSettings.Options or Flag
3966 else
3967 gGameSettings.Options := gGameSettings.Options and (not Flag);
3968 if g_Game_IsNet then MH_SEND_GameSettings;
3969 end;
3970 end;
3972 if LongBool(gsGameFlags and Flag) then
3973 g_Console_Add(_lc[OnMsg])
3974 else
3975 g_Console_Add(_lc[OffMsg]);
3977 if OnMapChange and g_Game_IsServer then
3978 g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
3979 end;
3981 begin
3982 stat := nil;
3983 cmd := LowerCase(P[0]);
3985 if cmd = 'g_gamemode' then
3986 begin
3987 if (Length(P) > 1) then
3988 begin
3989 a := g_Game_TextToMode(P[1]);
3990 if a = GM_SINGLE then a := GM_COOP;
3991 gsGameMode := g_Game_ModeToText(a);
3992 if g_Game_IsServer then
3993 begin
3994 gSwitchGameMode := a;
3995 if (gGameOn and (gGameSettings.GameMode = GM_SINGLE)) or
3996 (gState = STATE_INTERSINGLE) then
3997 gSwitchGameMode := GM_SINGLE;
3998 if not gGameOn then
3999 gGameSettings.GameMode := gSwitchGameMode;
4000 end;
4001 end;
4003 if gSwitchGameMode = gGameSettings.GameMode then
4004 g_Console_Add(Format(_lc[I_MSG_GAMEMODE_CURRENT],
4005 [g_Game_ModeToText(gGameSettings.GameMode)]))
4006 else
4007 g_Console_Add(Format(_lc[I_MSG_GAMEMODE_CHANGE],
4008 [g_Game_ModeToText(gGameSettings.GameMode),
4009 g_Game_ModeToText(gSwitchGameMode)]));
4010 end
4011 else if cmd = 'g_friendlyfire' then
4012 begin
4013 ParseGameFlag(GAME_OPTION_TEAMDAMAGE, I_MSG_FRIENDLY_FIRE_OFF, I_MSG_FRIENDLY_FIRE_ON);
4014 end
4015 else if cmd = 'g_friendly_absorb_damage' then
4016 begin
4017 ParseGameFlag(GAME_OPTION_TEAMABSORBDAMAGE, I_MSG_FRIENDLY_FIRE_OFF, I_MSG_FRIENDLY_FIRE_ON);
4018 end
4019 else if cmd = 'g_friendly_hit_trace' then
4020 begin
4021 ParseGameFlag(GAME_OPTION_TEAMHITTRACE, I_MSG_FRIENDLY_FIRE_OFF, I_MSG_FRIENDLY_FIRE_ON);
4022 end
4023 else if cmd = 'g_friendly_hit_projectile' then
4024 begin
4025 ParseGameFlag(GAME_OPTION_TEAMHITPROJECTILE, I_MSG_FRIENDLY_FIRE_OFF, I_MSG_FRIENDLY_FIRE_ON);
4026 end
4027 else if cmd = 'g_weaponstay' then
4028 begin
4029 ParseGameFlag(GAME_OPTION_WEAPONSTAY, I_MSG_WEAPONSTAY_OFF, I_MSG_WEAPONSTAY_ON);
4030 end
4031 else if cmd = 'g_allow_exit' then
4032 begin
4033 ParseGameFlag(GAME_OPTION_ALLOWEXIT, I_MSG_ALLOWEXIT_OFF, I_MSG_ALLOWEXIT_ON, True);
4034 end
4035 else if cmd = 'g_allow_monsters' then
4036 begin
4037 ParseGameFlag(GAME_OPTION_MONSTERS, I_MSG_ALLOWMON_OFF, I_MSG_ALLOWMON_ON, True);
4038 end
4039 else if cmd = 'g_bot_vsplayers' then
4040 begin
4041 ParseGameFlag(GAME_OPTION_BOTVSPLAYER, I_MSG_BOTSVSPLAYERS_OFF, I_MSG_BOTSVSPLAYERS_ON);
4042 end
4043 else if cmd = 'g_bot_vsmonsters' then
4044 begin
4045 ParseGameFlag(GAME_OPTION_BOTVSMONSTER, I_MSG_BOTSVSMONSTERS_OFF, I_MSG_BOTSVSMONSTERS_ON);
4046 end
4047 else if cmd = 'g_dm_keys' then
4048 begin
4049 ParseGameFlag(GAME_OPTION_DMKEYS, I_MSG_DMKEYS_OFF, I_MSG_DMKEYS_ON, True);
4050 end
4051 else if cmd = 'g_gameflags' then
4052 begin
4053 if Length(P) > 1 then
4054 begin
4055 gsGameFlags := StrToDWordDef(P[1], gsGameFlags);
4056 if g_Game_IsServer then
4057 begin
4058 gGameSettings.Options := gsGameFlags;
4059 if g_Game_IsNet then MH_SEND_GameSettings;
4060 end;
4061 end;
4063 g_Console_Add(Format('%s %u', [cmd, gsGameFlags]));
4064 end
4065 else if cmd = 'g_warmup_time' then
4066 begin
4067 if Length(P) > 1 then
4068 begin
4069 gsWarmupTime := nclamp(StrToIntDef(P[1], gsWarmupTime), 0, $FFFF);
4070 if g_Game_IsServer then
4071 begin
4072 gGameSettings.WarmupTime := gsWarmupTime;
4073 // extend warmup if it's already going
4074 if gLMSRespawn = LMS_RESPAWN_WARMUP then
4075 begin
4076 gLMSRespawnTime := gTime + gsWarmupTime * 1000;
4077 if g_Game_IsNet then MH_SEND_GameEvent(NET_EV_LMS_WARMUP, gLMSRespawnTime - gTime);
4078 end;
4079 if g_Game_IsNet then MH_SEND_GameSettings;
4080 end;
4081 end;
4083 g_Console_Add(Format(_lc[I_MSG_WARMUP], [Integer(gsWarmupTime)]));
4084 if g_Game_IsServer then g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
4085 end
4086 else if cmd = 'g_spawn_invul' then
4087 begin
4088 if Length(P) > 1 then
4089 begin
4090 gsSpawnInvul := nclamp(StrToIntDef(P[1], gsSpawnInvul), 0, $FFFF);
4091 if g_Game_IsServer then
4092 begin
4093 gGameSettings.SpawnInvul := gsSpawnInvul;
4094 if g_Game_IsNet then MH_SEND_GameSettings;
4095 end;
4096 end;
4098 g_Console_Add(Format('%s %d', [cmd, Integer(gsSpawnInvul)]));
4099 end
4100 else if cmd = 'g_item_respawn_time' then
4101 begin
4102 if Length(P) > 1 then
4103 begin
4104 gsItemRespawnTime := nclamp(StrToIntDef(P[1], gsItemRespawnTime), 0, $FFFF);
4105 if g_Game_IsServer then
4106 begin
4107 gGameSettings.ItemRespawnTime := gsItemRespawnTime;
4108 if g_Game_IsNet then MH_SEND_GameSettings;
4109 end;
4110 end;
4112 g_Console_Add(Format('%s %d', [cmd, Integer(gsItemRespawnTime)]));
4113 if g_Game_IsServer then g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
4114 end
4115 else if cmd = 'sv_intertime' then
4116 begin
4117 if (Length(P) > 1) then
4118 gDefInterTime := Min(Max(StrToIntDef(P[1], gDefInterTime), -1), 120);
4120 g_Console_Add(cmd + ' = ' + IntToStr(gDefInterTime));
4121 end
4122 else if cmd = 'g_max_particles' then
4123 begin
4124 if Length(p) = 2 then
4125 begin
4126 a := Max(0, StrToInt(p[1]));
4127 g_GFX_SetMax(a)
4128 end
4129 else if Length(p) = 1 then
4130 begin
4131 e_LogWritefln('%s', [g_GFX_GetMax()])
4132 end
4133 else
4134 begin
4135 e_LogWritefln('usage: %s <n>', [cmd])
4136 end
4137 end
4138 else if cmd = 'g_max_shells' then
4139 begin
4140 if Length(p) = 2 then
4141 begin
4142 a := Max(0, StrToInt(p[1]));
4143 g_Shells_SetMax(a)
4144 end
4145 else if Length(p) = 1 then
4146 begin
4147 e_LogWritefln('%s', [g_Shells_GetMax()])
4148 end
4149 else
4150 begin
4151 e_LogWritefln('usage: %s <n>', [cmd])
4152 end
4153 end
4154 else if cmd = 'g_max_gibs' then
4155 begin
4156 if Length(p) = 2 then
4157 begin
4158 a := Max(0, StrToInt(p[1]));
4159 g_Gibs_SetMax(a)
4160 end
4161 else if Length(p) = 1 then
4162 begin
4163 e_LogWritefln('%s', [g_Gibs_GetMax()])
4164 end
4165 else
4166 begin
4167 e_LogWritefln('usage: %s <n>', [cmd])
4168 end
4169 end
4170 else if cmd = 'g_max_corpses' then
4171 begin
4172 if Length(p) = 2 then
4173 begin
4174 a := Max(0, StrToInt(p[1]));
4175 g_Corpses_SetMax(a)
4176 end
4177 else if Length(p) = 1 then
4178 begin
4179 e_LogWritefln('%s', [g_Corpses_GetMax()])
4180 end
4181 else
4182 begin
4183 e_LogWritefln('usage: %s <n>', [cmd])
4184 end
4185 end
4186 else if cmd = 'g_scorelimit' then
4187 begin
4188 if Length(P) > 1 then
4189 begin
4190 gsGoalLimit := nclamp(StrToIntDef(P[1], gsGoalLimit), 0, $FFFF);
4192 if g_Game_IsServer then
4193 begin
4194 b := 0;
4195 if gGameSettings.GameMode = GM_DM then
4196 begin // DM
4197 stat := g_Player_GetStats();
4198 if stat <> nil then
4199 for a := 0 to High(stat) do
4200 if stat[a].Frags > b then
4201 b := stat[a].Frags;
4202 end
4203 else // TDM/CTF
4204 b := Max(gTeamStat[TEAM_RED].Goals, gTeamStat[TEAM_BLUE].Goals);
4206 // if someone has a higher score, set it to that instead
4207 gsGoalLimit := max(gsGoalLimit, b);
4208 gGameSettings.GoalLimit := gsGoalLimit;
4210 if g_Game_IsNet then MH_SEND_GameSettings;
4211 end;
4212 end;
4214 g_Console_Add(Format(_lc[I_MSG_SCORE_LIMIT], [Integer(gsGoalLimit)]));
4215 end
4216 else if cmd = 'g_timelimit' then
4217 begin
4218 if Length(P) > 1 then
4219 begin
4220 gsTimeLimit := nclamp(StrToIntDef(P[1], gsTimeLimit), 0, $FFFF);
4221 if g_Game_IsServer then
4222 begin
4223 gGameSettings.TimeLimit := gsTimeLimit;
4224 if g_Game_IsNet then MH_SEND_GameSettings;
4225 end;
4226 end;
4227 g_Console_Add(Format(_lc[I_MSG_TIME_LIMIT],
4228 [gsTimeLimit div 3600,
4229 (gsTimeLimit div 60) mod 60,
4230 gsTimeLimit mod 60]));
4231 end
4232 else if cmd = 'g_maxlives' then
4233 begin
4234 if Length(P) > 1 then
4235 begin
4236 gsMaxLives := nclamp(StrToIntDef(P[1], gsMaxLives), 0, $FFFF);
4237 if g_Game_IsServer then
4238 begin
4239 gGameSettings.MaxLives := gsMaxLives;
4240 if g_Game_IsNet then MH_SEND_GameSettings;
4241 end;
4242 end;
4244 g_Console_Add(Format(_lc[I_MSG_LIVES], [Integer(gsMaxLives)]));
4245 end;
4246 end;
4248 procedure PlayerSettingsCVars(P: SSArray);
4249 var
4250 cmd: string;
4251 team: Byte;
4253 function ParseTeam(s: string): Byte;
4254 begin
4255 result := 0;
4256 case s of
4257 'red', '1': result := TEAM_RED;
4258 'blue', '2': result := TEAM_BLUE;
4259 else result := TEAM_NONE;
4260 end;
4261 end;
4262 begin
4263 cmd := LowerCase(P[0]);
4264 case cmd of
4265 'p1_name':
4266 begin
4267 if (Length(P) > 1) then
4268 begin
4269 gPlayer1Settings.Name := b_Text_Unformat(P[1]);
4270 if g_Game_IsClient then
4271 MC_SEND_PlayerSettings
4272 else if gGameOn and (gPlayer1 <> nil) then
4273 begin
4274 gPlayer1.Name := b_Text_Unformat(P[1]);
4275 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer1.UID);
4276 end;
4277 end;
4278 end;
4279 'p2_name':
4280 begin
4281 if (Length(P) > 1) then
4282 begin
4283 gPlayer2Settings.Name := b_Text_Unformat(P[1]);
4284 if g_Game_IsClient then
4285 MC_SEND_PlayerSettings
4286 else if gGameOn and (gPlayer2 <> nil) then
4287 begin
4288 gPlayer2.Name := b_Text_Unformat(P[1]);
4289 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer2.UID);
4290 end;
4291 end;
4292 end;
4293 'p1_color':
4294 begin
4295 if Length(P) > 3 then
4296 begin
4297 gPlayer1Settings.Color := _RGB(EnsureRange(StrToIntDef(P[1], 0), 0, 255),
4298 EnsureRange(StrToIntDef(P[2], 0), 0, 255),
4299 EnsureRange(StrToIntDef(P[3], 0), 0, 255));
4300 if g_Game_IsClient then
4301 MC_SEND_PlayerSettings
4302 else if gGameOn and (gPlayer1 <> nil) then
4303 begin
4304 gPlayer1.SetColor(gPlayer1Settings.Color);
4305 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer1.UID);
4306 end;
4307 end;
4308 end;
4309 'p2_color':
4310 begin
4311 if Length(P) > 3 then
4312 begin
4313 gPlayer2Settings.Color := _RGB(EnsureRange(StrToIntDef(P[1], 0), 0, 255),
4314 EnsureRange(StrToIntDef(P[2], 0), 0, 255),
4315 EnsureRange(StrToIntDef(P[3], 0), 0, 255));
4316 if g_Game_IsClient then
4317 MC_SEND_PlayerSettings
4318 else if gGameOn and (gPlayer2 <> nil) then
4319 begin
4320 gPlayer2.SetColor(gPlayer2Settings.Color);
4321 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer2.UID);
4322 end;
4323 end;
4324 end;
4325 'p1_model':
4326 begin
4327 if (Length(P) > 1) then
4328 begin
4329 gPlayer1Settings.Model := P[1];
4330 if g_Game_IsClient then
4331 MC_SEND_PlayerSettings
4332 else if gGameOn and (gPlayer1 <> nil) then
4333 begin
4334 gPlayer1.FActualModelName := gPlayer1Settings.Model;
4335 gPlayer1.SetModel(gPlayer1Settings.Model);
4336 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer1.UID);
4337 end;
4338 end;
4339 end;
4340 'p2_model':
4341 begin
4342 if (Length(P) > 1) then
4343 begin
4344 gPlayer2Settings.Model := P[1];
4345 if g_Game_IsClient then
4346 MC_SEND_PlayerSettings
4347 else if gGameOn and (gPlayer2 <> nil) then
4348 begin
4349 gPlayer2.FActualModelName := gPlayer2Settings.Model;
4350 gPlayer2.SetModel(gPlayer2Settings.Model);
4351 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer2.UID);
4352 end;
4353 end;
4354 end;
4355 'p1_team':
4356 begin
4357 // TODO: switch teams if in game or store this separately
4358 if (Length(P) > 1) then
4359 begin
4360 team := ParseTeam(P[1]);
4361 if team = TEAM_NONE then
4362 g_Console_Add('expected ''red'', ''blue'', 1 or 2')
4363 else if not gGameOn and not g_Game_IsNet then
4364 gPlayer1Settings.Team := team
4365 else
4366 g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
4367 end;
4368 end;
4369 'p2_team':
4370 begin
4371 // TODO: switch teams if in game or store this separately
4372 if (Length(P) > 1) then
4373 begin
4374 team := ParseTeam(P[1]);
4375 if team = TEAM_NONE then
4376 g_Console_Add('expected ''red'', ''blue'', 1 or 2')
4377 else if not gGameOn and not g_Game_IsNet then
4378 gPlayer2Settings.Team := team
4379 else
4380 g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
4381 end;
4382 end;
4383 end;
4384 end;
4386 procedure PrintHeapStats();
4387 var
4388 hs: TFPCHeapStatus;
4389 begin
4390 hs := GetFPCHeapStatus();
4391 e_LogWriteLn ('v===== heap status =====v');
4392 e_LogWriteFln('max heap size = %d k', [hs.MaxHeapSize div 1024]);
4393 e_LogWriteFln('max heap used = %d k', [hs.MaxHeapUsed div 1024]);
4394 e_LogWriteFln('cur heap size = %d k', [hs.CurrHeapSize div 1024]);
4395 e_LogWriteFln('cur heap used = %d k', [hs.CurrHeapUsed div 1024]);
4396 e_LogWriteFln('cur heap free = %d k', [hs.CurrHeapFree div 1024]);
4397 e_LogWriteLn ('^=======================^');
4398 end;
4400 procedure DebugCommands(P: SSArray);
4401 var
4402 a, b: Integer;
4403 cmd: string;
4404 //pt: TDFPoint;
4405 mon: TMonster;
4406 begin
4407 // Команды отладочного режима:
4408 if {gDebugMode}conIsCheatsEnabled then
4409 begin
4410 cmd := LowerCase(P[0]);
4411 if cmd = 'd_window' then
4412 begin
4413 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth, gScreenHeight]));
4414 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth, gScreenHeight]));
4415 end
4416 else if cmd = 'd_sounds' then
4417 begin
4418 if (Length(P) > 1) and
4419 ((P[1] = '1') or (P[1] = '0')) then
4420 g_Debug_Sounds := (P[1][1] = '1');
4422 g_Console_Add(Format('d_sounds is %d', [Byte(g_Debug_Sounds)]));
4423 end
4424 else if cmd = 'd_frames' then
4425 begin
4426 if (Length(P) > 1) and
4427 ((P[1] = '1') or (P[1] = '0')) then
4428 g_Debug_Frames := (P[1][1] = '1');
4430 g_Console_Add(Format('d_frames is %d', [Byte(g_Debug_Frames)]));
4431 end
4432 else if cmd = 'd_winmsg' then
4433 begin
4434 if (Length(P) > 1) and
4435 ((P[1] = '1') or (P[1] = '0')) then
4436 g_Debug_WinMsgs := (P[1][1] = '1');
4438 g_Console_Add(Format('d_winmsg is %d', [Byte(g_Debug_WinMsgs)]));
4439 end
4440 else if (cmd = 'd_monoff') and not g_Game_IsNet then
4441 begin
4442 if (Length(P) > 1) and
4443 ((P[1] = '1') or (P[1] = '0')) then
4444 g_Debug_MonsterOff := (P[1][1] = '1');
4446 g_Console_Add(Format('d_monoff is %d', [Byte(g_debug_MonsterOff)]));
4447 end
4448 else if (cmd = 'd_botoff') and not g_Game_IsNet then
4449 begin
4450 if Length(P) > 1 then
4451 case P[1][1] of
4452 '0': g_debug_BotAIOff := 0;
4453 '1': g_debug_BotAIOff := 1;
4454 '2': g_debug_BotAIOff := 2;
4455 '3': g_debug_BotAIOff := 3;
4456 end;
4458 g_Console_Add(Format('d_botoff is %d', [g_debug_BotAIOff]));
4459 end
4460 else if cmd = 'd_monster' then
4461 begin
4462 if gGameOn and (gPlayer1 <> nil) and (gPlayer1.alive) and (not g_Game_IsNet) then
4463 if Length(P) < 2 then
4464 begin
4465 g_Console_Add(cmd + ' [ID | Name] [behaviour]');
4466 g_Console_Add('ID | Name');
4467 for b := MONSTER_DEMON to MONSTER_MAN do
4468 g_Console_Add(Format('%2d | %s', [b, g_Mons_NameByTypeId(b)]));
4469 conwriteln('behav. num'#10'normal 0'#10'killer 1'#10'maniac 2'#10'insane 3'#10'cannibal 4'#10'good 5');
4470 end else
4471 begin
4472 a := StrToIntDef(P[1], 0);
4473 if (a < MONSTER_DEMON) or (a > MONSTER_MAN) then
4474 a := g_Mons_TypeIdByName(P[1]);
4476 if (a < MONSTER_DEMON) or (a > MONSTER_MAN) then
4477 g_Console_Add(Format(_lc[I_MSG_NO_MONSTER], [P[1]]))
4478 else
4479 begin
4480 with gPlayer1.Obj do
4481 begin
4482 mon := g_Monsters_Create(a,
4483 X + Rect.X + (Rect.Width div 2),
4484 Y + Rect.Y + Rect.Height,
4485 gPlayer1.Direction, True);
4486 end;
4487 if (Length(P) > 2) and (mon <> nil) then
4488 begin
4489 if (CompareText(P[2], 'normal') = 0) then mon.MonsterBehaviour := BH_NORMAL
4490 else if (CompareText(P[2], 'killer') = 0) then mon.MonsterBehaviour := BH_KILLER
4491 else if (CompareText(P[2], 'maniac') = 0) then mon.MonsterBehaviour := BH_MANIAC
4492 else if (CompareText(P[2], 'insane') = 0) then mon.MonsterBehaviour := BH_INSANE
4493 else if (CompareText(P[2], 'cannibal') = 0) then mon.MonsterBehaviour := BH_CANNIBAL
4494 else if (CompareText(P[2], 'good') = 0) then mon.MonsterBehaviour := BH_GOOD
4495 else if (CompareText(P[2], 'friend') = 0) then mon.MonsterBehaviour := BH_GOOD
4496 else if (CompareText(P[2], 'friendly') = 0) then mon.MonsterBehaviour := BH_GOOD
4497 else mon.MonsterBehaviour := Min(Max(StrToIntDef(P[2], BH_NORMAL), BH_NORMAL), BH_GOOD);
4498 end;
4499 end;
4500 end;
4501 end
4502 else if (cmd = 'd_health') then
4503 begin
4504 if (Length(P) > 1) and
4505 ((P[1] = '1') or (P[1] = '0')) then
4506 g_debug_HealthBar := (P[1][1] = '1');
4508 g_Console_Add(Format('d_health is %d', [Byte(g_debug_HealthBar)]));
4509 end
4510 else if (cmd = 'd_player') then
4511 begin
4512 if (Length(P) > 1) and
4513 ((P[1] = '1') or (P[1] = '0')) then
4514 g_debug_Player := (P[1][1] = '1');
4516 g_Console_Add(Format(cmd + ' is %d', [Byte(g_Debug_Player)]));
4517 end
4518 else if (cmd = 'd_mem') then
4519 begin
4520 PrintHeapStats();
4521 end;
4522 end
4523 else
4524 g_Console_Add(_lc[I_MSG_NOT_DEBUG]);
4525 end;
4528 procedure GameCheats(P: SSArray);
4529 var
4530 cmd: string;
4531 f, a: Integer;
4532 plr: TPlayer;
4533 begin
4534 if (not gGameOn) or (not conIsCheatsEnabled) then
4535 begin
4536 g_Console_Add('not available');
4537 exit;
4538 end;
4539 plr := gPlayer1;
4540 if plr = nil then
4541 begin
4542 g_Console_Add('where is the player?!');
4543 exit;
4544 end;
4545 cmd := LowerCase(P[0]);
4546 // god
4547 if cmd = 'god' then
4548 begin
4549 plr.GodMode := not plr.GodMode;
4550 if plr.GodMode then g_Console_Add('player is godlike now') else g_Console_Add('player is mortal now');
4551 exit;
4552 end;
4553 // give <health|exit|weapons|air|suit|jetpack|berserk|all>
4554 if cmd = 'give' then
4555 begin
4556 if length(P) < 2 then begin g_Console_Add('give what?!'); exit; end;
4557 for f := 1 to High(P) do
4558 begin
4559 cmd := LowerCase(P[f]);
4560 if cmd = 'health' then begin plr.RestoreHealthArmor(); g_Console_Add('player feels himself better'); continue; end;
4561 if (cmd = 'all') {or (cmd = 'weapons')} then begin plr.AllRulez(False); g_Console_Add('player got the gifts'); continue; end;
4562 if cmd = 'exit' then
4563 begin
4564 if gTriggers <> nil then
4565 begin
4566 for a := 0 to High(gTriggers) do
4567 begin
4568 if gTriggers[a].TriggerType = TRIGGER_EXIT then
4569 begin
4570 g_Console_Add('player left the map');
4571 gExitByTrigger := True;
4572 //g_Game_ExitLevel(gTriggers[a].Data.MapName);
4573 g_Game_ExitLevel(gTriggers[a].tgcMap);
4574 break;
4575 end;
4576 end;
4577 end;
4578 continue;
4579 end;
4581 if cmd = 'air' then begin plr.GiveItem(ITEM_OXYGEN); g_Console_Add('player got some air'); continue; end;
4582 if cmd = 'jetpack' then begin plr.GiveItem(ITEM_JETPACK); g_Console_Add('player got a jetpack'); continue; end;
4583 if cmd = 'suit' then begin plr.GiveItem(ITEM_SUIT); g_Console_Add('player got an envirosuit'); continue; end;
4584 if cmd = 'berserk' then begin plr.GiveItem(ITEM_MEDKIT_BLACK); g_Console_Add('player got a berserk pack'); continue; end;
4585 if cmd = 'backpack' then begin plr.GiveItem(ITEM_AMMO_BACKPACK); g_Console_Add('player got a backpack'); continue; end;
4587 if cmd = 'helmet' then begin plr.GiveItem(ITEM_HELMET); g_Console_Add('player got a helmet'); continue; end;
4588 if cmd = 'bottle' then begin plr.GiveItem(ITEM_BOTTLE); g_Console_Add('player got a bottle of health'); continue; end;
4590 if cmd = 'stimpack' then begin plr.GiveItem(ITEM_MEDKIT_SMALL); g_Console_Add('player got a stimpack'); continue; end;
4591 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;
4593 if cmd = 'greenarmor' then begin plr.GiveItem(ITEM_ARMOR_GREEN); g_Console_Add('player got a security armor'); continue; end;
4594 if cmd = 'bluearmor' then begin plr.GiveItem(ITEM_ARMOR_BLUE); g_Console_Add('player got a combat armor'); continue; end;
4596 if (cmd = 'megasphere') or (cmd = 'mega') then begin plr.GiveItem(ITEM_SPHERE_BLUE); g_Console_Add('player got a megasphere'); continue; end;
4597 if (cmd = 'soulsphere') or (cmd = 'soul')then begin plr.GiveItem(ITEM_SPHERE_WHITE); g_Console_Add('player got a soul sphere'); continue; end;
4599 if (cmd = 'invul') or (cmd = 'invulnerability') then begin plr.GiveItem(ITEM_INVUL); g_Console_Add('player got invulnerability'); continue; end;
4600 if (cmd = 'invis') or (cmd = 'invisibility') then begin plr.GiveItem(ITEM_INVIS); g_Console_Add('player got invisibility'); continue; end;
4602 if cmd = 'redkey' then begin plr.GiveItem(ITEM_KEY_RED); g_Console_Add('player got the red key'); continue; end;
4603 if cmd = 'greenkey' then begin plr.GiveItem(ITEM_KEY_GREEN); g_Console_Add('player got the green key'); continue; end;
4604 if cmd = 'bluekey' then begin plr.GiveItem(ITEM_KEY_BLUE); g_Console_Add('player got the blue key'); continue; end;
4606 if (cmd = 'shotgun') or (cmd = 'sg') then begin plr.GiveItem(ITEM_WEAPON_SHOTGUN1); g_Console_Add('player got a shotgun'); continue; end;
4607 if (cmd = 'supershotgun') or (cmd = 'ssg') then begin plr.GiveItem(ITEM_WEAPON_SHOTGUN2); g_Console_Add('player got a supershotgun'); continue; end;
4608 if cmd = 'chaingun' then begin plr.GiveItem(ITEM_WEAPON_CHAINGUN); g_Console_Add('player got a chaingun'); continue; end;
4609 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;
4610 if cmd = 'plasmagun' then begin plr.GiveItem(ITEM_WEAPON_PLASMA); g_Console_Add('player got a plasma gun'); continue; end;
4611 if cmd = 'bfg' then begin plr.GiveItem(ITEM_WEAPON_BFG); g_Console_Add('player got a BFG-9000'); continue; end;
4613 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;
4614 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;
4615 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;
4616 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;
4617 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;
4618 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;
4620 if cmd = 'superchaingun' then begin plr.GiveItem(ITEM_WEAPON_SUPERPULEMET); g_Console_Add('player got a superchaingun'); continue; end;
4621 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;
4623 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;
4624 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;
4626 if cmd = 'chainsaw' then begin plr.GiveItem(ITEM_WEAPON_SAW); g_Console_Add('player got a chainsaw'); continue; end;
4628 if cmd = 'ammo' then
4629 begin
4630 plr.GiveItem(ITEM_AMMO_SHELLS_BOX);
4631 plr.GiveItem(ITEM_AMMO_BULLETS_BOX);
4632 plr.GiveItem(ITEM_AMMO_CELL_BIG);
4633 plr.GiveItem(ITEM_AMMO_ROCKET_BOX);
4634 plr.GiveItem(ITEM_AMMO_FUELCAN);
4635 g_Console_Add('player got some ammo');
4636 continue;
4637 end;
4639 if cmd = 'clip' then begin plr.GiveItem(ITEM_AMMO_BULLETS); g_Console_Add('player got some bullets'); continue; end;
4640 if cmd = 'bullets' then begin plr.GiveItem(ITEM_AMMO_BULLETS_BOX); g_Console_Add('player got a box of bullets'); continue; end;
4642 if cmd = 'shells' then begin plr.GiveItem(ITEM_AMMO_SHELLS); g_Console_Add('player got some shells'); continue; end;
4643 if cmd = 'shellbox' then begin plr.GiveItem(ITEM_AMMO_SHELLS_BOX); g_Console_Add('player got a box of shells'); continue; end;
4645 if cmd = 'cells' then begin plr.GiveItem(ITEM_AMMO_CELL); g_Console_Add('player got some cells'); continue; end;
4646 if cmd = 'battery' then begin plr.GiveItem(ITEM_AMMO_CELL_BIG); g_Console_Add('player got cell battery'); continue; end;
4648 if cmd = 'rocket' then begin plr.GiveItem(ITEM_AMMO_ROCKET); g_Console_Add('player got a rocket'); continue; end;
4649 if cmd = 'rocketbox' then begin plr.GiveItem(ITEM_AMMO_ROCKET_BOX); g_Console_Add('player got some rockets'); continue; end;
4651 if (cmd = 'fuel') or (cmd = 'fuelcan') then begin plr.GiveItem(ITEM_AMMO_FUELCAN); g_Console_Add('player got fuel canister'); continue; end;
4653 if cmd = 'weapons' then
4654 begin
4655 plr.GiveItem(ITEM_WEAPON_SHOTGUN1);
4656 plr.GiveItem(ITEM_WEAPON_SHOTGUN2);
4657 plr.GiveItem(ITEM_WEAPON_CHAINGUN);
4658 plr.GiveItem(ITEM_WEAPON_ROCKETLAUNCHER);
4659 plr.GiveItem(ITEM_WEAPON_PLASMA);
4660 plr.GiveItem(ITEM_WEAPON_BFG);
4661 g_Console_Add('player got weapons');
4662 continue;
4663 end;
4665 if cmd = 'keys' then
4666 begin
4667 plr.GiveItem(ITEM_KEY_RED);
4668 plr.GiveItem(ITEM_KEY_GREEN);
4669 plr.GiveItem(ITEM_KEY_BLUE);
4670 g_Console_Add('player got all keys');
4671 continue;
4672 end;
4674 g_Console_Add('i don''t know how to give '''+cmd+'''!');
4675 end;
4676 exit;
4677 end;
4678 // open
4679 if cmd = 'open' then
4680 begin
4681 g_Console_Add('player activated sesame');
4682 g_Triggers_OpenAll();
4683 exit;
4684 end;
4685 // fly
4686 if cmd = 'fly' then
4687 begin
4688 gFly := not gFly;
4689 if gFly then g_Console_Add('player feels himself lighter') else g_Console_Add('player lost his wings');
4690 exit;
4691 end;
4692 // noclip
4693 if cmd = 'noclip' then
4694 begin
4695 plr.SwitchNoClip;
4696 g_Console_Add('wall hardeness adjusted');
4697 exit;
4698 end;
4699 // notarget
4700 if cmd = 'notarget' then
4701 begin
4702 plr.NoTarget := not plr.NoTarget;
4703 if plr.NoTarget then g_Console_Add('player hides in shadows') else g_Console_Add('player is brave again');
4704 exit;
4705 end;
4706 // noreload
4707 if cmd = 'noreload' then
4708 begin
4709 plr.NoReload := not plr.NoReload;
4710 if plr.NoReload then g_Console_Add('player is action hero now') else g_Console_Add('player is ordinary man now');
4711 exit;
4712 end;
4713 // speedy
4714 if cmd = 'speedy' then
4715 begin
4716 MAX_RUNVEL := 32-MAX_RUNVEL;
4717 g_Console_Add('speed adjusted');
4718 exit;
4719 end;
4720 // jumpy
4721 if cmd = 'jumpy' then
4722 begin
4723 VEL_JUMP := 30-VEL_JUMP;
4724 g_Console_Add('jump height adjusted');
4725 exit;
4726 end;
4727 // automap
4728 if cmd = 'automap' then
4729 begin
4730 gShowMap := not gShowMap;
4731 if gShowMap then g_Console_Add('player gains second sight') else g_Console_Add('player lost second sight');
4732 exit;
4733 end;
4734 // aimline
4735 if cmd = 'aimline' then
4736 begin
4737 gAimLine := not gAimLine;
4738 if gAimLine then g_Console_Add('player gains laser sight') else g_Console_Add('player lost laser sight');
4739 exit;
4740 end;
4741 end;
4743 procedure GameCommands(P: SSArray);
4744 var
4745 a, b: Integer;
4746 s, pw: String;
4747 chstr: string;
4748 cmd: string;
4749 pl: pTNetClient = nil;
4750 plr: TPlayer;
4751 prt: Word;
4752 nm: Boolean;
4753 listen: LongWord;
4754 found: Boolean;
4755 begin
4756 // Общие команды:
4757 cmd := LowerCase(P[0]);
4758 chstr := '';
4759 if cmd = 'pause' then
4760 begin
4761 if (g_ActiveWindow = nil) then
4762 g_Game_Pause(not gPauseMain);
4763 end
4764 else if cmd = 'endgame' then
4765 gExit := EXIT_SIMPLE
4766 else if cmd = 'restart' then
4767 begin
4768 if gGameOn or (gState in [STATE_INTERSINGLE, STATE_INTERCUSTOM]) then
4769 begin
4770 if g_Game_IsClient then
4771 begin
4772 g_Console_Add(_lc[I_MSG_SERVERONLY]);
4773 Exit;
4774 end;
4775 g_Game_Restart();
4776 end else
4777 g_Console_Add(_lc[I_MSG_NOT_GAME]);
4778 end
4779 else if cmd = 'kick' then
4780 begin
4781 if g_Game_IsServer then
4782 begin
4783 if Length(P) < 2 then
4784 begin
4785 g_Console_Add('kick <name>');
4786 Exit;
4787 end;
4788 if P[1] = '' then
4789 begin
4790 g_Console_Add('kick <name>');
4791 Exit;
4792 end;
4794 if g_Game_IsNet then
4795 pl := g_Net_Client_ByName(P[1]);
4796 if (pl <> nil) then
4797 begin
4798 s := g_Net_ClientName_ByID(pl^.ID);
4799 enet_peer_disconnect(pl^.Peer, NET_DISC_KICK);
4800 g_Console_Add(Format(_lc[I_PLAYER_KICK], [s]));
4801 MH_SEND_GameEvent(NET_EV_PLAYER_KICK, 0, s);
4802 g_Net_Slist_ServerPlayerLeaves();
4803 end else if gPlayers <> nil then
4804 for a := Low(gPlayers) to High(gPlayers) do
4805 if gPlayers[a] <> nil then
4806 if Copy(LowerCase(gPlayers[a].Name), 1, Length(P[1])) = LowerCase(P[1]) then
4807 begin
4808 // Не отключать основных игроков в сингле
4809 if not(gPlayers[a] is TBot) and (gGameSettings.GameType = GT_SINGLE) then
4810 continue;
4811 gPlayers[a].Lives := 0;
4812 gPlayers[a].Kill(K_SIMPLEKILL, 0, HIT_DISCON);
4813 g_Console_Add(Format(_lc[I_PLAYER_LEAVE], [gPlayers[a].Name]), True);
4814 g_Player_Remove(gPlayers[a].UID);
4815 g_Net_Slist_ServerPlayerLeaves();
4816 // Если не перемешать, при добавлении новых ботов появятся старые
4817 g_Bot_MixNames();
4818 end;
4819 end else
4820 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
4821 end
4822 else if cmd = 'kick_id' then
4823 begin
4824 if g_Game_IsServer and g_Game_IsNet then
4825 begin
4826 if Length(P) < 2 then
4827 begin
4828 g_Console_Add('kick_id <client ID>');
4829 Exit;
4830 end;
4831 if P[1] = '' then
4832 begin
4833 g_Console_Add('kick_id <client ID>');
4834 Exit;
4835 end;
4837 a := StrToIntDef(P[1], 0);
4838 if (NetClients <> nil) and (a <= High(NetClients)) then
4839 begin
4840 if NetClients[a].Used and (NetClients[a].Peer <> nil) then
4841 begin
4842 s := g_Net_ClientName_ByID(NetClients[a].ID);
4843 enet_peer_disconnect(NetClients[a].Peer, NET_DISC_KICK);
4844 g_Console_Add(Format(_lc[I_PLAYER_KICK], [s]));
4845 MH_SEND_GameEvent(NET_EV_PLAYER_KICK, 0, s);
4846 g_Net_Slist_ServerPlayerLeaves();
4847 end;
4848 end;
4849 end else
4850 g_Console_Add(_lc[I_MSG_SERVERONLY]);
4851 end
4852 else if cmd = 'kick_pid' then
4853 begin
4854 if g_Game_IsServer and g_Game_IsNet then
4855 begin
4856 if Length(P) < 2 then
4857 begin
4858 g_Console_Add('kick_pid <player ID>');
4859 Exit;
4860 end;
4861 if P[1] = '' then
4862 begin
4863 g_Console_Add('kick_pid <player ID>');
4864 Exit;
4865 end;
4867 a := StrToIntDef(P[1], 0);
4868 pl := g_Net_Client_ByPlayer(a);
4869 if (pl <> nil) and pl^.Used and (pl^.Peer <> nil) then
4870 begin
4871 s := g_Net_ClientName_ByID(pl^.ID);
4872 enet_peer_disconnect(pl^.Peer, NET_DISC_KICK);
4873 g_Console_Add(Format(_lc[I_PLAYER_KICK], [s]));
4874 MH_SEND_GameEvent(NET_EV_PLAYER_KICK, 0, s);
4875 g_Net_Slist_ServerPlayerLeaves();
4876 end;
4877 end else
4878 g_Console_Add(_lc[I_MSG_SERVERONLY]);
4879 end
4880 else if cmd = 'ban' then
4881 begin
4882 if g_Game_IsServer and g_Game_IsNet then
4883 begin
4884 if Length(P) < 2 then
4885 begin
4886 g_Console_Add('ban <name>');
4887 Exit;
4888 end;
4889 if P[1] = '' then
4890 begin
4891 g_Console_Add('ban <name>');
4892 Exit;
4893 end;
4895 pl := g_Net_Client_ByName(P[1]);
4896 if (pl <> nil) then
4897 begin
4898 s := g_Net_ClientName_ByID(pl^.ID);
4899 g_Net_BanHost(pl^.Peer^.address.host, False);
4900 enet_peer_disconnect(pl^.Peer, NET_DISC_TEMPBAN);
4901 g_Console_Add(Format(_lc[I_PLAYER_BAN], [s]));
4902 MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s);
4903 g_Net_Slist_ServerPlayerLeaves();
4904 end else
4905 g_Console_Add(Format(_lc[I_NET_ERR_NAME404], [P[1]]));
4906 end else
4907 g_Console_Add(_lc[I_MSG_SERVERONLY]);
4908 end
4909 else if cmd = 'ban_id' then
4910 begin
4911 if g_Game_IsServer and g_Game_IsNet then
4912 begin
4913 if Length(P) < 2 then
4914 begin
4915 g_Console_Add('ban_id <client ID>');
4916 Exit;
4917 end;
4918 if P[1] = '' then
4919 begin
4920 g_Console_Add('ban_id <client ID>');
4921 Exit;
4922 end;
4924 a := StrToIntDef(P[1], 0);
4925 if (NetClients <> nil) and (a <= High(NetClients)) then
4926 if NetClients[a].Used and (NetClients[a].Peer <> nil) then
4927 begin
4928 s := g_Net_ClientName_ByID(NetClients[a].ID);
4929 g_Net_BanHost(NetClients[a].Peer^.address.host, False);
4930 enet_peer_disconnect(NetClients[a].Peer, NET_DISC_TEMPBAN);
4931 g_Console_Add(Format(_lc[I_PLAYER_BAN], [s]));
4932 MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s);
4933 g_Net_Slist_ServerPlayerLeaves();
4934 end;
4935 end else
4936 g_Console_Add(_lc[I_MSG_SERVERONLY]);
4937 end
4938 else if cmd = 'ban_pid' then
4939 begin
4940 if g_Game_IsServer and g_Game_IsNet then
4941 begin
4942 if Length(P) < 2 then
4943 begin
4944 g_Console_Add('ban_pid <player ID>');
4945 Exit;
4946 end;
4947 if P[1] = '' then
4948 begin
4949 g_Console_Add('ban_pid <player ID>');
4950 Exit;
4951 end;
4953 a := StrToIntDef(P[1], 0);
4954 pl := g_Net_Client_ByPlayer(a);
4955 if (pl <> nil) and pl^.Used and (pl^.Peer <> nil) then
4956 begin
4957 s := g_Net_ClientName_ByID(pl^.ID);
4958 g_Net_BanHost(pl^.Peer^.address.host, False);
4959 enet_peer_disconnect(pl^.Peer, NET_DISC_TEMPBAN);
4960 g_Console_Add(Format(_lc[I_PLAYER_BAN], [s]));
4961 MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s);
4962 g_Net_Slist_ServerPlayerLeaves();
4963 end;
4964 end else
4965 g_Console_Add(_lc[I_MSG_SERVERONLY]);
4966 end
4967 else if cmd = 'permban' then
4968 begin
4969 if g_Game_IsServer and g_Game_IsNet then
4970 begin
4971 if Length(P) < 2 then
4972 begin
4973 g_Console_Add('permban <name>');
4974 Exit;
4975 end;
4976 if P[1] = '' then
4977 begin
4978 g_Console_Add('permban <name>');
4979 Exit;
4980 end;
4982 pl := g_Net_Client_ByName(P[1]);
4983 if (pl <> nil) then
4984 begin
4985 s := g_Net_ClientName_ByID(pl^.ID);
4986 g_Net_BanHost(pl^.Peer^.address.host);
4987 enet_peer_disconnect(pl^.Peer, NET_DISC_BAN);
4988 g_Net_SaveBanList();
4989 g_Console_Add(Format(_lc[I_PLAYER_BAN], [s]));
4990 MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s);
4991 g_Net_Slist_ServerPlayerLeaves();
4992 end else
4993 g_Console_Add(Format(_lc[I_NET_ERR_NAME404], [P[1]]));
4994 end else
4995 g_Console_Add(_lc[I_MSG_SERVERONLY]);
4996 end
4997 else if cmd = 'permban_id' then
4998 begin
4999 if g_Game_IsServer and g_Game_IsNet then
5000 begin
5001 if Length(P) < 2 then
5002 begin
5003 g_Console_Add('permban_id <client ID>');
5004 Exit;
5005 end;
5006 if P[1] = '' then
5007 begin
5008 g_Console_Add('permban_id <client ID>');
5009 Exit;
5010 end;
5012 a := StrToIntDef(P[1], 0);
5013 if (NetClients <> nil) and (a <= High(NetClients)) then
5014 if NetClients[a].Used and (NetClients[a].Peer <> nil) then
5015 begin
5016 s := g_Net_ClientName_ByID(NetClients[a].ID);
5017 g_Net_BanHost(NetClients[a].Peer^.address.host);
5018 enet_peer_disconnect(NetClients[a].Peer, NET_DISC_BAN);
5019 g_Net_SaveBanList();
5020 g_Console_Add(Format(_lc[I_PLAYER_BAN], [s]));
5021 MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s);
5022 g_Net_Slist_ServerPlayerLeaves();
5023 end;
5024 end else
5025 g_Console_Add(_lc[I_MSG_SERVERONLY]);
5026 end
5027 else if cmd = 'permban_pid' then
5028 begin
5029 if g_Game_IsServer and g_Game_IsNet then
5030 begin
5031 if Length(P) < 2 then
5032 begin
5033 g_Console_Add('permban_pid <player ID>');
5034 Exit;
5035 end;
5036 if P[1] = '' then
5037 begin
5038 g_Console_Add('permban_pid <player ID>');
5039 Exit;
5040 end;
5042 a := StrToIntDef(P[1], 0);
5043 pl := g_Net_Client_ByPlayer(a);
5044 if (pl <> nil) and pl^.Used and (pl^.Peer <> nil) then
5045 begin
5046 s := g_Net_ClientName_ByID(pl^.ID);
5047 g_Net_BanHost(pl^.Peer^.address.host);
5048 enet_peer_disconnect(pl^.Peer, NET_DISC_BAN);
5049 g_Net_SaveBanList();
5050 g_Console_Add(Format(_lc[I_PLAYER_BAN], [s]));
5051 MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s);
5052 g_Net_Slist_ServerPlayerLeaves();
5053 end;
5054 end else
5055 g_Console_Add(_lc[I_MSG_SERVERONLY]);
5056 end
5057 else if cmd = 'permban_ip' then
5058 begin
5059 if g_Game_IsServer and g_Game_IsNet then
5060 begin
5061 if Length(P) < 2 then
5062 begin
5063 g_Console_Add('permban_ip <IP address>');
5064 Exit;
5065 end;
5066 if P[1] = '' then
5067 begin
5068 g_Console_Add('permban_ip <IP address>');
5069 Exit;
5070 end;
5072 g_Net_BanHost(P[1]);
5073 g_Net_SaveBanList();
5074 g_Console_Add(Format(_lc[I_PLAYER_BAN], [P[1]]));
5075 end else
5076 g_Console_Add(_lc[I_MSG_SERVERONLY]);
5077 end
5078 else if cmd = 'unban' then
5079 begin
5080 if g_Game_IsServer and g_Game_IsNet then
5081 begin
5082 if Length(P) < 2 then
5083 begin
5084 g_Console_Add('unban <IP Address>');
5085 Exit;
5086 end;
5087 if P[1] = '' then
5088 begin
5089 g_Console_Add('unban <IP Address>');
5090 Exit;
5091 end;
5093 if g_Net_UnbanHost(P[1]) then
5094 begin
5095 g_Console_Add(Format(_lc[I_MSG_UNBAN_OK], [P[1]]));
5096 g_Net_SaveBanList();
5097 end else
5098 g_Console_Add(Format(_lc[I_MSG_UNBAN_FAIL], [P[1]]));
5099 end else
5100 g_Console_Add(_lc[I_MSG_SERVERONLY]);
5101 end
5102 else if cmd = 'clientlist' then
5103 begin
5104 if g_Game_IsServer and g_Game_IsNet then
5105 begin
5106 b := 0;
5107 if NetClients <> nil then
5108 for a := Low(NetClients) to High(NetClients) do
5109 if NetClients[a].Used and (NetClients[a].Peer <> nil) then
5110 begin
5111 plr := g_Player_Get(NetClients[a].Player);
5112 if plr = nil then continue;
5113 Inc(b);
5114 g_Console_Add(Format('#%2d: %-15s | %s', [a,
5115 IpToStr(NetClients[a].Peer^.address.host), plr.Name]));
5116 end;
5117 if b = 0 then
5118 g_Console_Add(_lc[I_MSG_NOCLIENTS]);
5119 end else
5120 g_Console_Add(_lc[I_MSG_SERVERONLY]);
5121 end
5122 else if cmd = 'connect' then
5123 begin
5124 if (NetMode = NET_NONE) then
5125 begin
5126 if Length(P) < 2 then
5127 begin
5128 g_Console_Add('connect <IP> [port] [password]');
5129 Exit;
5130 end;
5131 if P[1] = '' then
5132 begin
5133 g_Console_Add('connect <IP> [port] [password]');
5134 Exit;
5135 end;
5137 if Length(P) > 2 then
5138 prt := StrToIntDef(P[2], 25666)
5139 else
5140 prt := 25666;
5142 if Length(P) > 3 then
5143 pw := P[3]
5144 else
5145 pw := '';
5147 g_Game_StartClient(P[1], prt, pw);
5148 end;
5149 end
5150 else if cmd = 'disconnect' then
5151 begin
5152 if (NetMode = NET_CLIENT) then
5153 g_Net_Disconnect();
5154 end
5155 else if cmd = 'reconnect' then
5156 begin
5157 if (NetMode = NET_SERVER) then
5158 Exit;
5160 if (NetMode = NET_CLIENT) then
5161 begin
5162 g_Net_Disconnect();
5163 gExit := EXIT_SIMPLE;
5164 EndGame;
5165 end;
5167 //TODO: Use last successful password to reconnect, instead of ''
5168 g_Game_StartClient(NetClientIP, NetClientPort, '');
5169 end
5170 else if (cmd = 'addbot') or
5171 (cmd = 'bot_add') then
5172 begin
5173 if Length(P) > 2 then
5174 g_Bot_Add(TEAM_NONE, StrToIntDef(P[1], 2), StrToIntDef(P[2], 100))
5175 else if Length(P) > 1 then
5176 g_Bot_Add(TEAM_NONE, StrToIntDef(P[1], 2))
5177 else
5178 g_Bot_Add(TEAM_NONE, 2);
5179 end
5180 else if cmd = 'bot_addlist' then
5181 begin
5182 if Length(P) > 1 then
5183 begin
5184 if Length(P) = 2 then
5185 g_Bot_AddList(TEAM_NONE, P[1], StrToIntDef(P[1], -1))
5186 else if Length(P) = 3 then
5187 g_Bot_AddList(TEAM_NONE, P[1], StrToIntDef(P[1], -1), StrToIntDef(P[2], 100))
5188 else
5189 g_Bot_AddList(IfThen(P[2] = 'red', TEAM_RED, TEAM_BLUE), P[1], StrToIntDef(P[1], -1));
5190 end;
5191 end
5192 else if cmd = 'bot_removeall' then
5193 g_Bot_RemoveAll()
5194 else if cmd = 'chat' then
5195 begin
5196 if g_Game_IsNet then
5197 begin
5198 if Length(P) > 1 then
5199 begin
5200 for a := 1 to High(P) do
5201 chstr := chstr + P[a] + ' ';
5203 if Length(chstr) > 200 then SetLength(chstr, 200);
5205 if Length(chstr) < 1 then
5206 begin
5207 g_Console_Add('chat <text>');
5208 Exit;
5209 end;
5211 chstr := b_Text_Format(chstr);
5212 if g_Game_IsClient then
5213 MC_SEND_Chat(chstr, NET_CHAT_PLAYER)
5214 else
5215 MH_SEND_Chat(gPlayer1Settings.Name + ': ' + chstr, NET_CHAT_PLAYER);
5216 end
5217 else
5218 g_Console_Add('chat <text>');
5219 end else
5220 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
5221 end
5222 else if cmd = 'teamchat' then
5223 begin
5224 if g_Game_IsNet and (gGameSettings.GameMode in [GM_TDM, GM_CTF]) then
5225 begin
5226 if Length(P) > 1 then
5227 begin
5228 for a := 1 to High(P) do
5229 chstr := chstr + P[a] + ' ';
5231 if Length(chstr) > 200 then SetLength(chstr, 200);
5233 if Length(chstr) < 1 then
5234 begin
5235 g_Console_Add('teamchat <text>');
5236 Exit;
5237 end;
5239 chstr := b_Text_Format(chstr);
5240 if g_Game_IsClient then
5241 MC_SEND_Chat(chstr, NET_CHAT_TEAM)
5242 else
5243 MH_SEND_Chat(gPlayer1Settings.Name + ': ' + chstr, NET_CHAT_TEAM,
5244 gPlayer1Settings.Team);
5245 end
5246 else
5247 g_Console_Add('teamchat <text>');
5248 end else
5249 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
5250 end
5251 else if cmd = 'game' then
5252 begin
5253 if gGameSettings.GameType <> GT_NONE then
5254 begin
5255 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
5256 Exit;
5257 end;
5258 if Length(P) = 1 then
5259 begin
5260 g_Console_Add(cmd + ' <WAD> [MAP] [# players]');
5261 Exit;
5262 end;
5263 // game not started yet, load fist map from some wad
5264 found := false;
5265 s := addWadExtension(P[1]);
5266 found := e_FindResource(AllMapDirs, s);
5267 P[1] := s;
5268 if found then
5269 begin
5270 P[1] := ExpandFileName(P[1]);
5271 // if map not choosed then set first map
5272 if Length(P) < 3 then
5273 begin
5274 SetLength(P, 3);
5275 P[2] := g_Game_GetFirstMap(P[1]);
5276 end;
5278 s := P[1] + ':\' + UpperCase(P[2]);
5280 if g_Map_Exist(s) then
5281 begin
5282 // start game
5283 g_Game_Free();
5284 with gGameSettings do
5285 begin
5286 Options := gsGameFlags;
5287 GameMode := g_Game_TextToMode(gsGameMode);
5288 if gSwitchGameMode <> GM_NONE then
5289 GameMode := gSwitchGameMode;
5290 if GameMode = GM_NONE then GameMode := GM_DM;
5291 if GameMode = GM_SINGLE then GameMode := GM_COOP;
5292 b := 1;
5293 if Length(P) >= 4 then
5294 b := StrToIntDef(P[3], 1);
5295 g_Game_StartCustom(s, GameMode, TimeLimit,
5296 GoalLimit, MaxLives, Options, b);
5297 end;
5298 end
5299 else
5300 if P[2] = '' then
5301 g_Console_Add(Format(_lc[I_MSG_NO_MAPS], [P[1]]))
5302 else
5303 g_Console_Add(Format(_lc[I_MSG_NO_MAP_FALLBACK], [UpperCase(P[2]), P[1]]));
5304 end else
5305 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]));
5306 end
5307 else if cmd = 'host' then
5308 begin
5309 if gGameSettings.GameType <> GT_NONE then
5310 begin
5311 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
5312 Exit;
5313 end;
5314 if Length(P) < 4 then
5315 begin
5316 g_Console_Add(cmd + ' <listen IP> <port> <WAD> [MAP] [# players]');
5317 Exit;
5318 end;
5319 if not StrToIp(P[1], listen) then
5320 Exit;
5321 prt := StrToIntDef(P[2], 25666);
5323 s := addWadExtension(P[3]);
5324 found := e_FindResource(AllMapDirs, s);
5325 P[3] := s;
5326 if found then
5327 begin
5328 // get first map in wad, if not specified
5329 if Length(P) < 5 then
5330 begin
5331 SetLength(P, 5);
5332 P[4] := g_Game_GetFirstMap(P[1]);
5333 end;
5334 s := P[3] + ':\' + UpperCase(P[4]);
5335 if g_Map_Exist(s) then
5336 begin
5337 // start game
5338 g_Game_Free();
5339 with gGameSettings do
5340 begin
5341 Options := gsGameFlags;
5342 GameMode := g_Game_TextToMode(gsGameMode);
5343 if gSwitchGameMode <> GM_NONE then GameMode := gSwitchGameMode;
5344 if GameMode = GM_NONE then GameMode := GM_DM;
5345 if GameMode = GM_SINGLE then GameMode := GM_COOP;
5346 b := 0;
5347 if Length(P) >= 6 then
5348 b := StrToIntDef(P[5], 0);
5349 g_Game_StartServer(s, GameMode, TimeLimit, GoalLimit, MaxLives, Options, b, listen, prt)
5350 end
5351 end
5352 else
5353 begin
5354 if P[4] = '' then
5355 g_Console_Add(Format(_lc[I_MSG_NO_MAPS], [P[3]]))
5356 else
5357 g_Console_Add(Format(_lc[I_MSG_NO_MAP_FALLBACK], [UpperCase(P[4]), P[3]]))
5358 end
5359 end
5360 else
5361 begin
5362 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[3]]))
5363 end
5364 end
5365 else if cmd = 'map' then
5366 begin
5367 if Length(P) = 1 then
5368 begin
5369 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
5370 begin
5371 g_Console_Add(cmd + ' <MAP>');
5372 g_Console_Add(cmd + ' <WAD> [MAP]')
5373 end
5374 else
5375 begin
5376 g_Console_Add(_lc[I_MSG_GM_UNAVAIL])
5377 end
5378 end
5379 else
5380 begin
5381 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
5382 begin
5383 if Length(P) < 3 then
5384 begin
5385 // first param is map or wad
5386 s := UpperCase(P[1]);
5387 if g_Map_Exist(gGameSettings.WAD + ':\' + s) then
5388 begin
5389 gExitByTrigger := False;
5390 if gGameOn then
5391 begin
5392 // already in game, finish current map
5393 gNextMap := s;
5394 gExit := EXIT_ENDLEVELCUSTOM;
5395 end
5396 else
5397 begin
5398 // intermission, so change map immediately
5399 g_Game_ChangeMap(s)
5400 end
5401 end
5402 else
5403 begin
5404 s := P[1];
5405 found := e_FindResource(AllMapDirs, s);
5406 P[1] := s;
5407 g_Console_Add(Format(_lc[I_MSG_NO_MAP_FALLBACK], [s, 'WAD ' + P[1]]));
5408 if found then
5409 begin
5410 // no such map, found wad
5411 pw := P[1];
5412 SetLength(P, 3);
5413 P[1] := ExpandFileName(pw);
5414 P[2] := g_Game_GetFirstMap(P[1]);
5415 s := P[1] + ':\' + P[2];
5416 if g_Map_Exist(s) then
5417 begin
5418 gExitByTrigger := False;
5419 if gGameOn then
5420 begin
5421 // already in game, finish current map
5422 gNextMap := s;
5423 gExit := EXIT_ENDLEVELCUSTOM
5424 end
5425 else
5426 begin
5427 // intermission, so change map immediately
5428 g_Game_ChangeMap(s)
5429 end
5430 end
5431 else
5432 begin
5433 if P[2] = '' then
5434 g_Console_Add(Format(_lc[I_MSG_NO_MAPS], [P[1]]))
5435 else
5436 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [P[2]]))
5437 end
5438 end
5439 else
5440 begin
5441 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]))
5442 end
5443 end;
5444 end
5445 else
5446 begin
5447 s := addWadExtension(P[1]);
5448 found := e_FindResource(AllMapDirs, s);
5449 P[1] := s;
5450 if found then
5451 begin
5452 P[2] := UpperCase(P[2]);
5453 s := P[1] + ':\' + P[2];
5454 if g_Map_Exist(s) then
5455 begin
5456 gExitByTrigger := False;
5457 if gGameOn then
5458 begin
5459 gNextMap := s;
5460 gExit := EXIT_ENDLEVELCUSTOM
5461 end
5462 else
5463 begin
5464 g_Game_ChangeMap(s)
5465 end
5466 end
5467 else
5468 begin
5469 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [P[2]]))
5470 end
5471 end
5472 else
5473 begin
5474 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]))
5475 end
5476 end
5477 end
5478 else
5479 begin
5480 g_Console_Add(_lc[I_MSG_GM_UNAVAIL])
5481 end
5482 end
5483 end
5484 else if cmd = 'nextmap' then
5485 begin
5486 if not(gGameOn or (gState = STATE_INTERCUSTOM)) then
5487 begin
5488 g_Console_Add(_lc[I_MSG_NOT_GAME])
5489 end
5490 else
5491 begin
5492 nm := True;
5493 if Length(P) = 1 then
5494 begin
5495 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
5496 begin
5497 g_Console_Add(cmd + ' <MAP>');
5498 g_Console_Add(cmd + ' <WAD> [MAP]');
5499 end
5500 else
5501 begin
5502 nm := False;
5503 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
5504 end;
5505 end
5506 else
5507 begin
5508 nm := False;
5509 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
5510 begin
5511 if Length(P) < 3 then
5512 begin
5513 // first param is map or wad
5514 s := UpperCase(P[1]);
5515 if g_Map_Exist(gGameSettings.WAD + ':\' + s) then
5516 begin
5517 // map founded
5518 gExitByTrigger := False;
5519 gNextMap := s;
5520 nm := True;
5521 end
5522 else
5523 begin
5524 // no such map, found wad
5525 pw := addWadExtension(P[1]);
5526 found := e_FindResource(MapDirs, pw);
5527 if not found then
5528 found := e_FindResource(WadDirs, pw);
5529 P[1] := pw;
5530 g_Console_Add(Format(_lc[I_MSG_NO_MAP_FALLBACK], [s, P[1]]));
5531 if found then
5532 begin
5533 // map not specified, select first map
5534 SetLength(P, 3);
5535 P[2] := g_Game_GetFirstMap(P[1]);
5536 s := P[1] + ':\' + P[2];
5537 if g_Map_Exist(s) then
5538 begin
5539 gExitByTrigger := False;
5540 gNextMap := s;
5541 nm := True
5542 end
5543 else
5544 begin
5545 if P[2] = '' then
5546 g_Console_Add(Format(_lc[I_MSG_NO_MAPS], [P[1]]))
5547 else
5548 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [P[2]]))
5549 end
5550 end
5551 else
5552 begin
5553 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]))
5554 end
5555 end
5556 end
5557 else
5558 begin
5559 // specified two params wad + map
5560 pw := addWadExtension(P[1]);
5561 found := e_FindResource(MapDirs, pw);
5562 if not found then
5563 found := e_FindResource(MapDirs, pw);
5564 P[1] := pw;
5565 if found then
5566 begin
5567 P[2] := UpperCase(P[2]);
5568 s := P[1] + ':\' + P[2];
5569 if g_Map_Exist(s) then
5570 begin
5571 gExitByTrigger := False;
5572 gNextMap := s;
5573 nm := True
5574 end
5575 else
5576 begin
5577 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [P[2]]))
5578 end
5579 end
5580 else
5581 begin
5582 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]))
5583 end
5584 end
5585 end
5586 else
5587 begin
5588 g_Console_Add(_lc[I_MSG_GM_UNAVAIL])
5589 end
5590 end;
5591 if nm then
5592 begin
5593 if gNextMap = '' then
5594 g_Console_Add(_lc[I_MSG_NEXTMAP_UNSET])
5595 else
5596 g_Console_Add(Format(_lc[I_MSG_NEXTMAP_SET], [gNextMap]))
5597 end
5598 end
5599 end
5600 else if (cmd = 'endmap') or (cmd = 'goodbye') then
5601 begin
5602 if not gGameOn then
5603 begin
5604 g_Console_Add(_lc[I_MSG_NOT_GAME])
5605 end
5606 else
5607 begin
5608 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
5609 begin
5610 gExitByTrigger := False;
5611 // next map not specified, try to find trigger EXIT
5612 if (gNextMap = '') and (gTriggers <> nil) then
5613 begin
5614 for a := 0 to High(gTriggers) do
5615 begin
5616 if gTriggers[a].TriggerType = TRIGGER_EXIT then
5617 begin
5618 gExitByTrigger := True;
5619 //gNextMap := gTriggers[a].Data.MapName;
5620 gNextMap := gTriggers[a].tgcMap;
5621 Break
5622 end
5623 end
5624 end;
5625 if gNextMap = '' then
5626 gNextMap := g_Game_GetNextMap();
5627 if not isWadPath(gNextMap) then
5628 s := gGameSettings.WAD + ':\' + gNextMap
5629 else
5630 s := gNextMap;
5631 if g_Map_Exist(s) then
5632 gExit := EXIT_ENDLEVELCUSTOM
5633 else
5634 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [gNextMap]))
5635 end
5636 else
5637 begin
5638 g_Console_Add(_lc[I_MSG_GM_UNAVAIL])
5639 end
5640 end
5641 end
5642 else if (cmd = 'event') then
5643 begin
5644 if (Length(P) <= 1) then
5645 begin
5646 for a := 0 to High(gEvents) do
5647 if gEvents[a].Command = '' then
5648 g_Console_Add(gEvents[a].Name + ' <none>')
5649 else
5650 g_Console_Add(gEvents[a].Name + ' "' + gEvents[a].Command + '"');
5651 Exit;
5652 end;
5653 if (Length(P) = 2) then
5654 begin
5655 for a := 0 to High(gEvents) do
5656 if gEvents[a].Name = P[1] then
5657 if gEvents[a].Command = '' then
5658 g_Console_Add(gEvents[a].Name + ' <none>')
5659 else
5660 g_Console_Add(gEvents[a].Name + ' "' + gEvents[a].Command + '"');
5661 Exit;
5662 end;
5663 for a := 0 to High(gEvents) do
5664 if gEvents[a].Name = P[1] then
5665 begin
5666 gEvents[a].Command := '';
5667 for b := 2 to High(P) do
5668 if Pos(' ', P[b]) = 0 then
5669 gEvents[a].Command := gEvents[a].Command + ' ' + P[b]
5670 else
5671 gEvents[a].Command := gEvents[a].Command + ' "' + P[b] + '"';
5672 gEvents[a].Command := Trim(gEvents[a].Command);
5673 Exit;
5674 end;
5675 end
5676 else if cmd = 'suicide' then
5677 begin
5678 if gGameOn then
5679 begin
5680 if g_Game_IsClient then
5681 MC_SEND_CheatRequest(NET_CHEAT_SUICIDE)
5682 else
5683 begin
5684 if gPlayer1 <> nil then
5685 gPlayer1.Damage(SUICIDE_DAMAGE, gPlayer1.UID, 0, 0, HIT_SELF);
5686 if gPlayer2 <> nil then
5687 gPlayer2.Damage(SUICIDE_DAMAGE, gPlayer2.UID, 0, 0, HIT_SELF);
5688 end;
5689 end;
5690 end
5691 else if cmd = 'screenshot' then
5692 begin
5693 g_TakeScreenShot()
5694 end
5695 else if cmd = 'weapon' then
5696 begin
5697 if Length(p) = 2 then
5698 begin
5699 a := WP_FIRST + StrToInt(p[1]) - 1;
5700 if (a >= WP_FIRST) and (a <= WP_LAST) then
5701 gSelectWeapon[0, a] := True
5702 end
5703 end
5704 else if (cmd = 'p1_weapon') or (cmd = 'p2_weapon') then
5705 begin
5706 if Length(p) = 2 then
5707 begin
5708 a := WP_FIRST + StrToInt(p[1]) - 1;
5709 b := ord(cmd[2]) - ord('1');
5710 if (a >= WP_FIRST) and (a <= WP_LAST) then
5711 gSelectWeapon[b, a] := True
5712 end
5713 end
5714 // Команды Своей игры:
5715 else if gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT] then
5716 begin
5717 if cmd = 'bot_addred' then
5718 begin
5719 if Length(P) > 1 then
5720 g_Bot_Add(TEAM_RED, StrToIntDef(P[1], 2))
5721 else
5722 g_Bot_Add(TEAM_RED, 2);
5723 end
5724 else if cmd = 'bot_addblue' then
5725 begin
5726 if Length(P) > 1 then
5727 g_Bot_Add(TEAM_BLUE, StrToIntDef(P[1], 2))
5728 else
5729 g_Bot_Add(TEAM_BLUE, 2);
5730 end
5731 else if cmd = 'spectate' then
5732 begin
5733 if not gGameOn then
5734 Exit;
5735 g_Game_Spectate();
5736 end
5737 else if cmd = 'say' then
5738 begin
5739 if g_Game_IsServer and g_Game_IsNet then
5740 begin
5741 if Length(P) > 1 then
5742 begin
5743 chstr := '';
5744 for a := 1 to High(P) do
5745 chstr := chstr + P[a] + ' ';
5747 if Length(chstr) > 200 then SetLength(chstr, 200);
5749 if Length(chstr) < 1 then
5750 begin
5751 g_Console_Add('say <text>');
5752 Exit;
5753 end;
5755 chstr := b_Text_Format(chstr);
5756 MH_SEND_Chat(chstr, NET_CHAT_PLAYER);
5757 end
5758 else g_Console_Add('say <text>');
5759 end else
5760 g_Console_Add(_lc[I_MSG_SERVERONLY]);
5761 end
5762 else if cmd = 'tell' then
5763 begin
5764 if g_Game_IsServer and g_Game_IsNet then
5765 begin
5766 if (Length(P) > 2) and (P[1] <> '') then
5767 begin
5768 chstr := '';
5769 for a := 2 to High(P) do
5770 chstr := chstr + P[a] + ' ';
5772 if Length(chstr) > 200 then SetLength(chstr, 200);
5774 if Length(chstr) < 1 then
5775 begin
5776 g_Console_Add('tell <playername> <text>');
5777 Exit;
5778 end;
5780 pl := g_Net_Client_ByName(P[1]);
5781 if pl <> nil then
5782 MH_SEND_Chat(b_Text_Format(chstr), NET_CHAT_PLAYER, pl^.ID)
5783 else
5784 g_Console_Add(Format(_lc[I_NET_ERR_NAME404], [P[1]]));
5785 end
5786 else g_Console_Add('tell <playername> <text>');
5787 end else
5788 g_Console_Add(_lc[I_MSG_SERVERONLY]);
5789 end
5790 else if cmd = 'centerprint' then
5791 begin
5792 if (Length(P) > 2) and (P[1] <> '') then
5793 begin
5794 chstr := '';
5795 for a := 2 to High(P) do
5796 chstr := chstr + P[a] + ' ';
5798 if Length(chstr) > 200 then SetLength(chstr, 200);
5800 if Length(chstr) < 1 then
5801 begin
5802 g_Console_Add('centerprint <timeout> <text>');
5803 Exit;
5804 end;
5806 a := StrToIntDef(P[1], 100);
5807 chstr := b_Text_Format(chstr);
5808 g_Game_Message(chstr, a);
5809 if g_Game_IsNet and g_Game_IsServer then
5810 MH_SEND_GameEvent(NET_EV_BIGTEXT, a, chstr);
5811 end
5812 else g_Console_Add('centerprint <timeout> <text>');
5813 end
5814 else if (cmd = 'overtime') and not g_Game_IsClient then
5815 begin
5816 if (Length(P) = 1) or (StrToIntDef(P[1], -1) <= 0) then
5817 Exit;
5818 // Дополнительное время:
5819 gGameSettings.TimeLimit := (gTime - gGameStartTime) div 1000 + Word(StrToIntDef(P[1], 0));
5821 g_Console_Add(Format(_lc[I_MSG_TIME_LIMIT],
5822 [gGameSettings.TimeLimit div 3600,
5823 (gGameSettings.TimeLimit div 60) mod 60,
5824 gGameSettings.TimeLimit mod 60]));
5825 if g_Game_IsNet then MH_SEND_GameSettings;
5826 end
5827 else if (cmd = 'rcon_password') and g_Game_IsClient then
5828 begin
5829 if (Length(P) <= 1) then
5830 g_Console_Add('rcon_password <password>')
5831 else
5832 MC_SEND_RCONPassword(P[1]);
5833 end
5834 else if cmd = 'rcon' then
5835 begin
5836 if g_Game_IsClient then
5837 begin
5838 if Length(P) > 1 then
5839 begin
5840 chstr := '';
5841 for a := 1 to High(P) do
5842 chstr := chstr + P[a] + ' ';
5844 if Length(chstr) > 200 then SetLength(chstr, 200);
5846 if Length(chstr) < 1 then
5847 begin
5848 g_Console_Add('rcon <command>');
5849 Exit;
5850 end;
5852 MC_SEND_RCONCommand(chstr);
5853 end
5854 else g_Console_Add('rcon <command>');
5855 end;
5856 end
5857 else if cmd = 'ready' then
5858 begin
5859 if g_Game_IsServer and (gLMSRespawn = LMS_RESPAWN_WARMUP) then
5860 gLMSRespawnTime := gTime + 100;
5861 end
5862 else if (cmd = 'callvote') and g_Game_IsNet then
5863 begin
5864 if Length(P) > 1 then
5865 begin
5866 chstr := '';
5867 for a := 1 to High(P) do begin
5868 if a > 1 then chstr := chstr + ' ';
5869 chstr := chstr + P[a];
5870 end;
5872 if Length(chstr) > 200 then SetLength(chstr, 200);
5874 if Length(chstr) < 1 then
5875 begin
5876 g_Console_Add('callvote <command>');
5877 Exit;
5878 end;
5880 if g_Game_IsClient then
5881 MC_SEND_Vote(True, chstr)
5882 else
5883 g_Game_StartVote(chstr, gPlayer1Settings.Name);
5884 g_Console_Process('vote', True);
5885 end
5886 else
5887 g_Console_Add('callvote <command>');
5888 end
5889 else if (cmd = 'vote') and g_Game_IsNet then
5890 begin
5891 if g_Game_IsClient then
5892 MC_SEND_Vote(False)
5893 else if gVoteInProgress then
5894 begin
5895 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
5896 a := Floor((NetClientCount+1)/2.0) + 1
5897 else
5898 a := Floor(NetClientCount/2.0) + 1;
5899 if gVoted then
5900 begin
5901 Dec(gVoteCount);
5902 gVoted := False;
5903 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_REVOKED], [gPlayer1Settings.Name, gVoteCount, a]), True);
5904 MH_SEND_VoteEvent(NET_VE_REVOKE, gPlayer1Settings.Name, 'a', gVoteCount, a);
5905 end
5906 else
5907 begin
5908 Inc(gVoteCount);
5909 gVoted := True;
5910 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_VOTE], [gPlayer1Settings.Name, gVoteCount, a]), True);
5911 MH_SEND_VoteEvent(NET_VE_VOTE, gPlayer1Settings.Name, 'a', gVoteCount, a);
5912 g_Game_CheckVote;
5913 end;
5914 end;
5915 end
5916 end;
5917 end;
5919 procedure SystemCommands(P: SSArray);
5920 var
5921 cmd: string;
5922 begin
5923 cmd := LowerCase(P[0]);
5924 case cmd of
5925 'exit', 'quit':
5926 begin
5927 g_Game_Free();
5928 g_Game_Quit();
5929 end;
5930 'r_reset':
5931 begin
5932 gRC_Width := Max(1, gRC_Width);
5933 gRC_Height := Max(1, gRC_Height);
5934 gBPP := Max(1, gBPP);
5935 if sys_SetDisplayMode(gRC_Width, gRC_Height, gBPP, gRC_FullScreen, gRC_Maximized) = True then
5936 e_LogWriteln('resolution changed')
5937 else
5938 e_LogWriteln('resolution not changed');
5939 sys_EnableVSync(gVSync);
5940 end;
5941 'r_maxfps':
5942 begin
5943 if Length(p) = 2 then
5944 begin
5945 gMaxFPS := StrToIntDef(p[1], gMaxFPS);
5946 if gMaxFPS > 0 then
5947 gFrameTime := 1000 div gMaxFPS
5948 else
5949 gFrameTime := 0;
5950 end;
5951 e_LogWritefln('r_maxfps %d', [gMaxFPS]);
5952 end;
5953 'g_language':
5954 begin
5955 if Length(p) = 2 then
5956 begin
5957 gAskLanguage := true;
5958 gLanguage := LANGUAGE_ENGLISH;
5959 case LowerCase(p[1]) of
5960 'english':
5961 begin
5962 gAskLanguage := false;
5963 gLanguage := LANGUAGE_ENGLISH;
5964 end;
5965 'russian':
5966 begin
5967 gAskLanguage := false;
5968 gLanguage := LANGUAGE_RUSSIAN;
5969 end;
5970 'ask':
5971 begin
5972 gAskLanguage := true;
5973 gLanguage := LANGUAGE_ENGLISH;
5974 end;
5975 end;
5976 g_Language_Set(gLanguage);
5977 end
5978 else
5979 begin
5980 e_LogWritefln('usage: %s <English|Russian|Ask>', [cmd]);
5981 end
5982 end;
5983 end;
5984 end;
5986 procedure g_TakeScreenShot(Filename: string = '');
5987 var s: TStream; t: TDateTime; dir, date, name: String;
5988 begin
5989 if e_NoGraphics then Exit;
5990 try
5991 dir := e_GetWriteableDir(ScreenshotDirs);
5993 if Filename = '' then
5994 begin
5995 t := Now;
5996 DateTimeToString(date, 'yyyy-mm-dd-hh-nn-ss', t);
5997 Filename := 'screenshot-' + date;
5998 end;
6000 name := e_CatPath(dir, Filename + '.png');
6001 s := createDiskFile(name);
6002 try
6003 e_MakeScreenshot(s, gScreenWidth, gScreenHeight);
6004 s.Free;
6005 g_Console_Add(Format(_lc[I_CONSOLE_SCREENSHOT], [name]))
6006 except
6007 g_Console_Add(Format(_lc[I_CONSOLE_ERROR_WRITE], [name]));
6008 s.Free;
6009 DeleteFile(name)
6010 end
6011 except
6012 g_Console_Add('oh shit, i can''t create screenshot!')
6013 end
6014 end;
6016 procedure g_Game_InGameMenu(Show: Boolean);
6017 begin
6018 if (g_ActiveWindow = nil) and Show then
6019 begin
6020 if gGameSettings.GameType = GT_SINGLE then
6021 g_GUI_ShowWindow('GameSingleMenu')
6022 else
6023 begin
6024 if g_Game_IsClient then
6025 g_GUI_ShowWindow('GameClientMenu')
6026 else
6027 if g_Game_IsNet then
6028 g_GUI_ShowWindow('GameServerMenu')
6029 else
6030 g_GUI_ShowWindow('GameCustomMenu');
6031 end;
6032 g_Sound_PlayEx('MENU_OPEN');
6034 // Пауза при меню только в одиночной игре:
6035 if (not g_Game_IsNet) then
6036 g_Game_Pause(True);
6037 end
6038 else
6039 if (g_ActiveWindow <> nil) and (not Show) then
6040 begin
6041 // Пауза при меню только в одиночной игре:
6042 if (not g_Game_IsNet) then
6043 g_Game_Pause(False);
6044 end;
6045 end;
6047 procedure g_Game_Pause (Enable: Boolean);
6048 var
6049 oldPause: Boolean;
6050 begin
6051 if not gGameOn then exit;
6053 if not (gGameSettings.GameType in [GT_SINGLE, GT_CUSTOM]) then exit;
6055 oldPause := gPause;
6056 gPauseMain := Enable;
6058 if (gPause <> oldPause) then g_Game_PauseAllSounds(gPause);
6059 end;
6061 procedure g_Game_HolmesPause (Enable: Boolean);
6062 var
6063 oldPause: Boolean;
6064 begin
6065 if not gGameOn then exit;
6066 if not (gGameSettings.GameType in [GT_SINGLE, GT_CUSTOM]) then exit;
6068 oldPause := gPause;
6069 gPauseHolmes := Enable;
6071 if (gPause <> oldPause) then g_Game_PauseAllSounds(gPause);
6072 end;
6074 procedure g_Game_PauseAllSounds(Enable: Boolean);
6075 var
6076 i: Integer;
6077 begin
6078 // Триггеры:
6079 if gTriggers <> nil then
6080 for i := 0 to High(gTriggers) do
6081 with gTriggers[i] do
6082 if (TriggerType = TRIGGER_SOUND) and
6083 (Sound <> nil) and
6084 Sound.IsPlaying() then
6085 begin
6086 Sound.Pause(Enable);
6087 end;
6089 // Звуки игроков:
6090 if gPlayers <> nil then
6091 for i := 0 to High(gPlayers) do
6092 if gPlayers[i] <> nil then
6093 gPlayers[i].PauseSounds(Enable);
6095 // Музыка:
6096 if gMusic <> nil then
6097 gMusic.Pause(Enable);
6098 end;
6100 procedure g_Game_StopAllSounds(all: Boolean);
6101 var
6102 i: Integer;
6103 begin
6104 if gTriggers <> nil then
6105 for i := 0 to High(gTriggers) do
6106 with gTriggers[i] do
6107 if (TriggerType = TRIGGER_SOUND) and
6108 (Sound <> nil) then
6109 Sound.Stop();
6111 if gMusic <> nil then
6112 gMusic.Stop();
6114 if all then
6115 e_StopChannels();
6116 end;
6118 procedure g_Game_UpdateTriggerSounds;
6119 var i: Integer;
6120 begin
6121 if gTriggers <> nil then
6122 for i := 0 to High(gTriggers) do
6123 with gTriggers[i] do
6124 if (TriggerType = TRIGGER_SOUND) and (Sound <> nil) and tgcLocal and Sound.IsPlaying() then
6125 Sound.SetCoordsRect(X, Y, Width, Height, tgcVolume / 255.0)
6126 end;
6128 function g_Game_IsWatchedPlayer(UID: Word): Boolean;
6129 begin
6130 Result := False;
6131 if (gPlayer1 <> nil) and (gPlayer1.UID = UID) then
6132 begin
6133 Result := True;
6134 Exit;
6135 end;
6136 if (gPlayer2 <> nil) and (gPlayer2.UID = UID) then
6137 begin
6138 Result := True;
6139 Exit;
6140 end;
6141 if gSpectMode <> SPECT_PLAYERS then
6142 Exit;
6143 if gSpectPID1 = UID then
6144 begin
6145 Result := True;
6146 Exit;
6147 end;
6148 if gSpectViewTwo and (gSpectPID2 = UID) then
6149 begin
6150 Result := True;
6151 Exit;
6152 end;
6153 end;
6155 function g_Game_IsWatchedTeam(Team: Byte): Boolean;
6156 var
6157 Pl: TPlayer;
6158 begin
6159 Result := False;
6160 if (gPlayer1 <> nil) and (gPlayer1.Team = Team) then
6161 begin
6162 Result := True;
6163 Exit;
6164 end;
6165 if (gPlayer2 <> nil) and (gPlayer2.Team = Team) then
6166 begin
6167 Result := True;
6168 Exit;
6169 end;
6170 if gSpectMode <> SPECT_PLAYERS then
6171 Exit;
6172 Pl := g_Player_Get(gSpectPID1);
6173 if (Pl <> nil) and (Pl.Team = Team) then
6174 begin
6175 Result := True;
6176 Exit;
6177 end;
6178 if gSpectViewTwo then
6179 begin
6180 Pl := g_Player_Get(gSpectPID2);
6181 if (Pl <> nil) and (Pl.Team = Team) then
6182 begin
6183 Result := True;
6184 Exit;
6185 end;
6186 end;
6187 end;
6189 procedure g_Game_Message(Msg: string; Time: Word);
6190 begin
6191 MessageLineLength := (gScreenWidth - 204) div e_CharFont_GetMaxWidth(gMenuFont);
6192 MessageText := b_Text_Wrap(b_Text_Format(Msg), MessageLineLength);
6193 MessageTime := Time;
6194 end;
6196 procedure g_Game_ChatSound(Text: String; Taunt: Boolean = True);
6197 const
6198 punct: Array[0..13] of String =
6199 ('.', ',', ':', ';', '!', '?', '(', ')', '''', '"', '/', '\', '*', '^');
6200 var
6201 i, j: Integer;
6202 ok: Boolean;
6203 fpText: String;
6205 function IsPunctuation(S: String): Boolean;
6206 var
6207 i: Integer;
6208 begin
6209 Result := False;
6210 if Length(S) <> 1 then
6211 Exit;
6212 for i := Low(punct) to High(punct) do
6213 if S = punct[i] then
6214 begin
6215 Result := True;
6216 break;
6217 end;
6218 end;
6219 function FilterPunctuation(S: String): String;
6220 var
6221 i: Integer;
6222 begin
6223 for i := Low(punct) to High(punct) do
6224 S := StringReplace(S, punct[i], ' ', [rfReplaceAll]);
6225 Result := S;
6226 end;
6227 begin
6228 ok := False;
6230 if gUseChatSounds and Taunt and (gChatSounds <> nil) and (Pos(': ', Text) > 0) then
6231 begin
6232 // remove player name
6233 Delete(Text, 1, Pos(': ', Text) + 2 - 1);
6234 // for FullWord check
6235 Text := toLowerCase1251(' ' + Text + ' ');
6236 fpText := FilterPunctuation(Text);
6238 for i := 0 to Length(gChatSounds) - 1 do
6239 begin
6240 ok := True;
6241 for j := 0 to Length(gChatSounds[i].Tags) - 1 do
6242 begin
6243 if gChatSounds[i].FullWord and (not IsPunctuation(gChatSounds[i].Tags[j])) then
6244 ok := Pos(' ' + gChatSounds[i].Tags[j] + ' ', fpText) > 0
6245 else
6246 ok := Pos(gChatSounds[i].Tags[j], Text) > 0;
6247 if not ok then
6248 break;
6249 end;
6250 if ok then
6251 begin
6252 gChatSounds[i].Sound.Play();
6253 break;
6254 end;
6255 end;
6256 end;
6257 if not ok then
6258 g_Sound_PlayEx('SOUND_GAME_RADIO');
6259 end;
6261 procedure g_Game_Announce_GoodShot(SpawnerUID: Word);
6262 var
6263 a: Integer;
6264 begin
6265 case gAnnouncer of
6266 ANNOUNCE_NONE:
6267 Exit;
6268 ANNOUNCE_ME,
6269 ANNOUNCE_MEPLUS:
6270 if not g_Game_IsWatchedPlayer(SpawnerUID) then
6271 Exit;
6272 end;
6273 for a := 0 to 3 do
6274 if goodsnd[a].IsPlaying() then
6275 Exit;
6277 goodsnd[Random(4)].Play();
6278 end;
6280 procedure g_Game_Announce_KillCombo(Param: Integer);
6281 var
6282 UID: Word;
6283 c, n: Byte;
6284 Pl: TPlayer;
6285 Name: String;
6286 begin
6287 UID := Param and $FFFF;
6288 c := Param shr 16;
6289 if c < 2 then
6290 Exit;
6292 Pl := g_Player_Get(UID);
6293 if Pl = nil then
6294 Name := '?'
6295 else
6296 Name := Pl.Name;
6298 case c of
6299 2: begin
6300 n := 0;
6301 g_Console_Add(Format(_lc[I_PLAYER_KILL_2X], [Name]), True);
6302 end;
6303 3: begin
6304 n := 1;
6305 g_Console_Add(Format(_lc[I_PLAYER_KILL_3X], [Name]), True);
6306 end;
6307 4: begin
6308 n := 2;
6309 g_Console_Add(Format(_lc[I_PLAYER_KILL_4X], [Name]), True);
6310 end;
6311 else begin
6312 n := 3;
6313 g_Console_Add(Format(_lc[I_PLAYER_KILL_MX], [Name]), True);
6314 end;
6315 end;
6317 case gAnnouncer of
6318 ANNOUNCE_NONE:
6319 Exit;
6320 ANNOUNCE_ME:
6321 if not g_Game_IsWatchedPlayer(UID) then
6322 Exit;
6323 ANNOUNCE_MEPLUS:
6324 if (not g_Game_IsWatchedPlayer(UID)) and (c < 4) then
6325 Exit;
6326 end;
6328 if killsnd[n].IsPlaying() then
6329 killsnd[n].Stop();
6330 killsnd[n].Play();
6331 end;
6333 procedure g_Game_Announce_BodyKill(SpawnerUID: Word);
6334 var
6335 a: Integer;
6336 begin
6337 case gAnnouncer of
6338 ANNOUNCE_NONE:
6339 Exit;
6340 ANNOUNCE_ME:
6341 if not g_Game_IsWatchedPlayer(SpawnerUID) then
6342 Exit;
6343 end;
6344 for a := 0 to 2 do
6345 if hahasnd[a].IsPlaying() then
6346 Exit;
6348 hahasnd[Random(3)].Play();
6349 end;
6351 procedure g_Game_StartVote(Command, Initiator: string);
6352 var
6353 Need: Integer;
6354 begin
6355 if not gVotesEnabled then Exit;
6356 if gGameSettings.GameType <> GT_SERVER then Exit;
6357 if gVoteInProgress or gVotePassed then
6358 begin
6359 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_INPROGRESS], [gVoteCommand]), True);
6360 MH_SEND_VoteEvent(NET_VE_INPROGRESS, gVoteCommand);
6361 Exit;
6362 end;
6363 gVoteInProgress := True;
6364 gVotePassed := False;
6365 gVoteTimer := gTime + gVoteTimeout * 1000;
6366 gVoteCount := 0;
6367 gVoted := False;
6368 gVoteCommand := Command;
6370 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
6371 Need := Floor((NetClientCount+1)/2.0)+1
6372 else
6373 Need := Floor(NetClientCount/2.0)+1;
6374 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_STARTED], [Initiator, Command, Need]), True);
6375 MH_SEND_VoteEvent(NET_VE_STARTED, Initiator, Command, Need);
6376 end;
6378 procedure g_Game_CheckVote;
6379 var
6380 I, Need: Integer;
6381 begin
6382 if gGameSettings.GameType <> GT_SERVER then Exit;
6383 if not gVoteInProgress then Exit;
6385 if (gTime >= gVoteTimer) then
6386 begin
6387 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
6388 Need := Floor((NetClientCount+1)/2.0) + 1
6389 else
6390 Need := Floor(NetClientCount/2.0) + 1;
6391 if gVoteCount >= Need then
6392 begin
6393 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_PASSED], [gVoteCommand]), True);
6394 MH_SEND_VoteEvent(NET_VE_PASSED, gVoteCommand);
6395 gVotePassed := True;
6396 gVoteCmdTimer := gTime + 5000;
6397 end
6398 else
6399 begin
6400 g_Console_Add(_lc[I_MESSAGE_VOTE_FAILED], True);
6401 MH_SEND_VoteEvent(NET_VE_FAILED);
6402 end;
6403 if NetClients <> nil then
6404 for I := Low(NetClients) to High(NetClients) do
6405 if NetClients[i].Used then
6406 NetClients[i].Voted := False;
6407 gVoteInProgress := False;
6408 gVoted := False;
6409 gVoteCount := 0;
6410 end
6411 else
6412 begin
6413 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
6414 Need := Floor((NetClientCount+1)/2.0) + 1
6415 else
6416 Need := Floor(NetClientCount/2.0) + 1;
6417 if gVoteCount >= Need then
6418 begin
6419 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_PASSED], [gVoteCommand]), True);
6420 MH_SEND_VoteEvent(NET_VE_PASSED, gVoteCommand);
6421 gVoteInProgress := False;
6422 gVotePassed := True;
6423 gVoteCmdTimer := gTime + 5000;
6424 gVoted := False;
6425 gVoteCount := 0;
6426 if NetClients <> nil then
6427 for I := Low(NetClients) to High(NetClients) do
6428 if NetClients[i].Used then
6429 NetClients[i].Voted := False;
6430 end;
6431 end;
6432 end;
6434 procedure g_Game_LoadMapList(FileName: string);
6435 var
6436 ListFile: TextFile;
6437 s: string;
6438 begin
6439 MapList := nil;
6440 MapIndex := -1;
6442 if not FileExists(FileName) then Exit;
6444 AssignFile(ListFile, FileName);
6445 Reset(ListFile);
6446 while not EOF(ListFile) do
6447 begin
6448 ReadLn(ListFile, s);
6450 s := Trim(s);
6451 if s = '' then Continue;
6453 SetLength(MapList, Length(MapList)+1);
6454 MapList[High(MapList)] := s;
6455 end;
6456 CloseFile(ListFile);
6457 end;
6459 procedure g_Game_SetDebugMode();
6460 begin
6461 gDebugMode := True;
6462 // Читы (даже в своей игре):
6463 gCheats := True;
6464 end;
6466 procedure g_Game_SetLoadingText(Text: String; Max: Integer; reWrite: Boolean);
6467 var
6468 i: Word;
6469 begin
6470 if Length(LoadingStat.Msgs) = 0 then
6471 Exit;
6473 with LoadingStat do
6474 begin
6475 if not reWrite then
6476 begin // Переходим на следующую строку или скроллируем:
6477 if NextMsg = Length(Msgs) then
6478 begin // scroll
6479 for i := 0 to High(Msgs)-1 do
6480 Msgs[i] := Msgs[i+1];
6481 end
6482 else
6483 Inc(NextMsg);
6484 end else
6485 if NextMsg = 0 then
6486 Inc(NextMsg);
6488 Msgs[NextMsg-1] := Text;
6489 CurValue := 0;
6490 MaxValue := Max;
6491 ShowCount := 0;
6492 PBarWasHere := false;
6493 end;
6495 g_ActiveWindow := nil;
6497 ProcessLoading(true);
6498 end;
6500 procedure g_Game_StepLoading(Value: Integer = -1);
6501 begin
6502 with LoadingStat do
6503 begin
6504 if Value = -1 then
6505 begin
6506 Inc(CurValue);
6507 Inc(ShowCount);
6508 end
6509 else
6510 CurValue := Value;
6511 if (ShowCount > LOADING_SHOW_STEP) or (Value > -1) then
6512 begin
6513 ShowCount := 0;
6514 ProcessLoading();
6515 end;
6516 end;
6517 end;
6519 procedure g_Game_ClearLoading();
6520 var
6521 len: Word;
6522 begin
6523 with LoadingStat do
6524 begin
6525 CurValue := 0;
6526 MaxValue := 0;
6527 ShowCount := 0;
6528 len := ((gScreenHeight div 3)*2 - 50) div LOADING_INTERLINE;
6529 if len < 1 then len := 1;
6530 SetLength(Msgs, len);
6531 for len := Low(Msgs) to High(Msgs) do
6532 Msgs[len] := '';
6533 NextMsg := 0;
6534 PBarWasHere := false;
6535 end;
6536 end;
6538 procedure Parse_Params(var pars: TParamStrValues);
6539 var
6540 i: Integer;
6541 s: String;
6542 begin
6543 SetLength(pars, 0);
6544 i := 1;
6545 while i <= ParamCount do
6546 begin
6547 s := ParamStr(i);
6548 if (s[1] = '-') and (Length(s) > 1) then
6549 begin
6550 if (s[2] = '-') and (Length(s) > 2) then
6551 begin // Одиночный параметр
6552 SetLength(pars, Length(pars) + 1);
6553 with pars[High(pars)] do
6554 begin
6555 Name := LowerCase(s);
6556 Value := '+';
6557 end;
6558 end
6559 else
6560 if (i < ParamCount) then
6561 begin // Параметр со значением
6562 Inc(i);
6563 SetLength(pars, Length(pars) + 1);
6564 with pars[High(pars)] do
6565 begin
6566 Name := LowerCase(s);
6567 Value := LowerCase(ParamStr(i));
6568 end;
6569 end;
6570 end;
6572 Inc(i);
6573 end;
6574 end;
6576 function Find_Param_Value(var pars: TParamStrValues; aName: String): String;
6577 var
6578 i: Integer;
6579 begin
6580 Result := '';
6581 for i := 0 to High(pars) do
6582 if pars[i].Name = aName then
6583 begin
6584 Result := pars[i].Value;
6585 Break;
6586 end;
6587 end;
6589 procedure g_Game_Process_Params();
6590 var
6591 pars: TParamStrValues;
6592 map: String;
6593 GMode, n: Byte;
6594 LimT, LimS: Integer;
6595 Opt: LongWord;
6596 Lives: Integer;
6597 s: String;
6598 Port: Integer;
6599 ip: String;
6600 F: TextFile;
6601 begin
6602 Parse_Params(pars);
6604 // Debug mode:
6605 s := Find_Param_Value(pars, '--debug');
6606 if (s <> '') then
6607 begin
6608 g_Game_SetDebugMode();
6609 s := Find_Param_Value(pars, '--netdump');
6610 if (s <> '') then
6611 NetDump := True;
6612 end;
6614 // Connect when game loads
6615 ip := Find_Param_Value(pars, '-connect');
6617 if ip <> '' then
6618 begin
6619 s := Find_Param_Value(pars, '-port');
6620 if (s = '') or not TryStrToInt(s, Port) then
6621 Port := 25666;
6623 s := Find_Param_Value(pars, '-pw');
6625 g_Game_StartClient(ip, Port, s);
6626 Exit;
6627 end;
6629 s := LowerCase(Find_Param_Value(pars, '-dbg-mainwad'));
6630 if (s <> '') then
6631 begin
6632 gDefaultMegawadStart := s;
6633 end;
6635 if (Find_Param_Value(pars, '--dbg-mainwad-restore') <> '') or
6636 (Find_Param_Value(pars, '--dbg-mainwad-default') <> '') then
6637 begin
6638 gDefaultMegawadStart := DF_Default_Megawad_Start;
6639 end;
6641 // Start map when game loads:
6642 map := LowerCase(Find_Param_Value(pars, '-map'));
6643 if isWadPath(map) then
6644 begin
6645 // Game mode:
6646 s := Find_Param_Value(pars, '-gm');
6647 GMode := g_Game_TextToMode(s);
6648 if GMode = GM_NONE then GMode := GM_DM;
6649 if GMode = GM_SINGLE then GMode := GM_COOP;
6651 // Time limit:
6652 s := Find_Param_Value(pars, '-limt');
6653 if (s = '') or (not TryStrToInt(s, LimT)) then
6654 LimT := 0;
6655 if LimT < 0 then
6656 LimT := 0;
6658 // Goal limit:
6659 s := Find_Param_Value(pars, '-lims');
6660 if (s = '') or (not TryStrToInt(s, LimS)) then
6661 LimS := 0;
6662 if LimS < 0 then
6663 LimS := 0;
6665 // Lives limit:
6666 s := Find_Param_Value(pars, '-lives');
6667 if (s = '') or (not TryStrToInt(s, Lives)) then
6668 Lives := 0;
6669 if Lives < 0 then
6670 Lives := 0;
6672 // Options:
6673 s := Find_Param_Value(pars, '-opt');
6674 if (s = '') then
6675 Opt := gsGameFlags
6676 else
6677 Opt := StrToIntDef(s, 0);
6679 // Close after map:
6680 s := Find_Param_Value(pars, '--close');
6681 if (s <> '') then
6682 gMapOnce := True;
6684 // Override map to test:
6685 s := LowerCase(Find_Param_Value(pars, '-testmap'));
6686 if s <> '' then
6687 begin
6688 if e_IsValidResourceName(s) then
6689 e_FindResource(AllMapDirs, s);
6690 gTestMap := ExpandFileName(s);
6691 end;
6693 // Delete test map after play:
6694 s := Find_Param_Value(pars, '--testdelete');
6695 if (s <> '') then
6696 begin
6697 //gMapToDelete := MapsDir + map;
6698 e_WriteLog('"--testdelete" is deprecated, use --tempdelete.', TMsgType.Fatal);
6699 Halt(1);
6700 end;
6702 // Delete temporary WAD after play:
6703 s := Find_Param_Value(pars, '--tempdelete');
6704 if (s <> '') and (gTestMap <> '') then
6705 begin
6706 gMapToDelete := gTestMap;
6707 gTempDelete := True;
6708 end;
6710 // Number of players:
6711 s := Find_Param_Value(pars, '-pl');
6712 if (s = '') then
6713 n := DEFAULT_PLAYERS
6714 else
6715 n := StrToIntDef(s, DEFAULT_PLAYERS);
6717 // Start:
6718 s := Find_Param_Value(pars, '-port');
6719 if (s = '') or not TryStrToInt(s, Port) then
6720 g_Game_StartCustom(map, GMode, LimT, LimS, Lives, Opt, n)
6721 else
6722 g_Game_StartServer(map, GMode, LimT, LimS, Lives, Opt, n, 0, Port);
6723 end;
6725 // Execute script when game loads:
6726 s := Find_Param_Value(pars, '-exec');
6727 if s <> '' then
6728 begin
6729 // if not isWadPath(s) then
6730 // s := GameDir + '/' + s;
6732 {$I-}
6733 AssignFile(F, s);
6734 Reset(F);
6735 if IOResult <> 0 then
6736 begin
6737 e_WriteLog(Format(_lc[I_SIMPLE_ERROR], ['Failed to read file: ' + s]), TMsgType.Warning);
6738 g_Console_Add(Format(_lc[I_CONSOLE_ERROR_READ], [s]));
6739 CloseFile(F);
6740 Exit;
6741 end;
6742 e_WriteLog('Executing script: ' + s, TMsgType.Notify);
6743 g_Console_Add(Format(_lc[I_CONSOLE_EXEC], [s]));
6745 while not EOF(F) do
6746 begin
6747 ReadLn(F, s);
6748 if IOResult <> 0 then
6749 begin
6750 e_WriteLog(Format(_lc[I_SIMPLE_ERROR], ['Failed to read file: ' + s]), TMsgType.Warning);
6751 g_Console_Add(Format(_lc[I_CONSOLE_ERROR_READ], [s]));
6752 CloseFile(F);
6753 Exit;
6754 end;
6755 if Pos('#', s) <> 1 then // script comment
6756 g_Console_Process(s, True);
6757 end;
6759 CloseFile(F);
6760 {$I+}
6761 end;
6763 SetLength(pars, 0);
6764 end;
6766 begin
6767 conRegVar('pf_draw_frame', @g_profile_frame_draw, 'draw frame rendering profiles', 'render profiles');
6768 //conRegVar('pf_update_frame', @g_profile_frame_update, 'draw frame updating profiles', 'update profiles');
6769 conRegVar('pf_coldet', @g_profile_collision, 'draw collision detection profiles', 'coldet profiles');
6770 conRegVar('pf_los', @g_profile_los, 'draw monster LOS profiles', 'monster LOS profiles');
6772 conRegVar('r_sq_draw', @gdbg_map_use_accel_render, 'accelerated spatial queries in rendering', 'accelerated rendering');
6773 conRegVar('cd_sq_enabled', @gdbg_map_use_accel_coldet, 'accelerated spatial queries in map coldet', 'accelerated map coldet');
6774 conRegVar('mon_sq_enabled', @gmon_debug_use_sqaccel, 'accelerated spatial queries for monsters', 'accelerated monster coldet');
6775 conRegVar('wtrace_sq_enabled', @gwep_debug_fast_trace, 'accelerated spatial queries for weapon hitscan trace', 'accelerated weapon hitscan');
6777 conRegVar('pr_enabled', @gpart_dbg_enabled, 'enable/disable particles', 'particles');
6778 conRegVar('pr_phys_enabled', @gpart_dbg_phys_enabled, 'enable/disable particle physics', 'particle physics');
6780 conRegVar('los_enabled', @gmon_dbg_los_enabled, 'enable/disable monster LOS calculations', 'monster LOS', true);
6781 conRegVar('mon_think', @gmon_debug_think, 'enable/disable monster thinking', 'monster thinking', true);
6783 {$IFDEF ENABLE_HOLMES}
6784 conRegVar('dbg_holmes', @g_holmes_enabled, 'enable/disable Holmes', 'Holmes', true);
6785 {$ENDIF}
6787 conRegVar('dbg_ignore_level_bounds', @g_dbg_ignore_bounds, 'ignore level bounds', '', false);
6789 conRegVar('light_enabled', @gwin_k8_enable_light_experiments, 'enable/disable dynamic lighting', 'lighting');
6790 conRegVar('light_player_halo', @g_playerLight, 'enable/disable player halo', 'player light halo');
6792 conRegVar('r_smallmap_align_h', @r_smallmap_h, 'halign: 0: left; 1: center; 2: right', 'horizontal aligning of small maps');
6793 conRegVar('r_smallmap_align_v', @r_smallmap_v, 'valign: 0: top; 1: center; 2: bottom', 'vertial aligning of small maps');
6795 conRegVar('r_showfps', @gShowFPS, 'draw fps counter', 'draw fps counter');
6796 conRegVar('r_showtime', @gShowTime, 'show game time', 'show game time');
6797 conRegVar('r_showping', @gShowPing, 'show ping', 'show ping');
6798 conRegVar('r_showscore', @gShowGoals, 'show score', 'show score');
6799 conRegVar('r_showkillmsg', @gShowKillMsg, 'show kill log', 'show kill log');
6800 conRegVar('r_showlives', @gShowLives, 'show lives', 'show lives');
6801 conRegVar('r_showspect', @gSpectHUD, 'show spectator hud', 'show spectator hud');
6802 conRegVar('r_showstat', @gShowStat, 'show stats', 'show stats');
6803 conRegVar('r_showpids', @gShowPIDs, 'show PIDs', 'show PIDs');
6804 end.