DEADSOFTWARE

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