DEADSOFTWARE

render: move textures loaders to render
[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,
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 g_Player_UpdateAll();
2238 g_Player_UpdatePhysicalObjects();
2240 // server: send newly spawned monsters unconditionally
2241 if (gGameSettings.GameType = GT_SERVER) then
2242 begin
2243 if (Length(gMonstersSpawned) > 0) then
2244 begin
2245 for I := 0 to High(gMonstersSpawned) do MH_SEND_MonsterSpawn(gMonstersSpawned[I]);
2246 SetLength(gMonstersSpawned, 0);
2247 end;
2248 end;
2250 if (gSoundTriggerTime > 8) then
2251 begin
2252 g_Game_UpdateTriggerSounds();
2253 gSoundTriggerTime := 0;
2254 end
2255 else
2256 begin
2257 Inc(gSoundTriggerTime);
2258 end;
2260 if (NetMode = NET_SERVER) then
2261 begin
2262 Inc(NetTimeToUpdate);
2263 Inc(NetTimeToReliable);
2265 // send monster updates
2266 if (NetTimeToReliable >= NetRelupdRate) or (NetTimeToUpdate >= NetUpdateRate) then
2267 begin
2268 // send all monsters (periodic sync)
2269 reliableUpdate := (NetTimeToReliable >= NetRelupdRate);
2271 for I := 0 to High(gPlayers) do
2272 begin
2273 if (gPlayers[I] <> nil) then MH_SEND_PlayerPos(reliableUpdate, gPlayers[I].UID);
2274 end;
2276 g_Mons_ForEach(sendMonsPos);
2278 if reliableUpdate then
2279 begin
2280 NetTimeToReliable := 0;
2281 NetTimeToUpdate := NetUpdateRate;
2282 end
2283 else
2284 begin
2285 NetTimeToUpdate := 0;
2286 end;
2287 end
2288 else
2289 begin
2290 // send only mosters with some unexpected changes
2291 g_Mons_ForEach(sendMonsPosUnexpected);
2292 end;
2294 // send unexpected platform changes
2295 g_Map_NetSendInterestingPanels();
2297 g_Net_Slist_ServerUpdate();
2299 if NetUseMaster then
2300 begin
2301 if (gTime >= NetTimeToMaster) or g_Net_Slist_IsConnectionInProgress then
2302 begin
2303 if (not g_Net_Slist_IsConnectionActive) then g_Net_Slist_Connect(false); // non-blocking connection to the master
2304 g_Net_Slist_Update;
2305 NetTimeToMaster := gTime + NetMasterRate;
2306 end;
2307 end;
2309 end
2310 else if (NetMode = NET_CLIENT) then
2311 begin
2312 MC_SEND_PlayerPos();
2313 end;
2314 end; // if gameOn ...
2316 // Активно окно интерфейса - передаем клавиши ему:
2317 if g_ActiveWindow <> nil then
2318 begin
2319 w := e_GetFirstKeyPressed();
2321 if (w <> IK_INVALID) then
2322 begin
2323 Msg.Msg := MESSAGE_DIKEY;
2324 Msg.wParam := w;
2325 g_ActiveWindow.OnMessage(Msg);
2326 end;
2328 // Если оно от этого не закрылось, то обновляем:
2329 if g_ActiveWindow <> nil then
2330 g_ActiveWindow.Update();
2332 // Нужно сменить разрешение:
2333 if gResolutionChange then
2334 begin
2335 e_WriteLog('Changing resolution', TMsgType.Notify);
2336 r_Render_Apply;
2337 gResolutionChange := False;
2338 g_ActiveWindow := nil;
2339 end;
2341 // Нужно сменить язык:
2342 if gLanguageChange then
2343 begin
2344 //e_WriteLog('Read language file', MSG_NOTIFY);
2345 //g_Language_Load(DataDir + gLanguage + '.txt');
2346 g_Language_Set(gLanguage);
2347 {$IFNDEF HEADLESS}
2348 g_Menu_Reset();
2349 {$ENDIF}
2350 gLanguageChange := False;
2351 end;
2352 end;
2354 // Горячая клавиша для вызова меню выхода из игры (F10):
2355 if e_KeyPressed(IK_F10) and
2356 gGameOn and
2357 (not gConsoleShow) and
2358 (g_ActiveWindow = nil) then
2359 begin
2360 KeyPress(IK_F10);
2361 end;
2363 Time := GetTickCount64() {div 1000};
2365 // Обработка отложенных событий:
2366 if gDelayedEvents <> nil then
2367 for a := 0 to High(gDelayedEvents) do
2368 if gDelayedEvents[a].Pending and
2370 ((gDelayedEvents[a].DEType = DE_GLOBEVENT) and (gDelayedEvents[a].Time <= Time)) or
2371 ((gDelayedEvents[a].DEType > DE_GLOBEVENT) and (gDelayedEvents[a].Time <= gTime))
2372 ) then
2373 begin
2374 case gDelayedEvents[a].DEType of
2375 DE_GLOBEVENT:
2376 g_Game_ExecuteEvent(gDelayedEvents[a].DEStr);
2377 DE_BFGHIT:
2378 if gGameOn then
2379 g_Game_Announce_GoodShot(gDelayedEvents[a].DENum);
2380 DE_KILLCOMBO:
2381 if gGameOn then
2382 begin
2383 g_Game_Announce_KillCombo(gDelayedEvents[a].DENum);
2384 if g_Game_IsNet and g_Game_IsServer then
2385 MH_SEND_GameEvent(NET_EV_KILLCOMBO, gDelayedEvents[a].DENum);
2386 end;
2387 DE_BODYKILL:
2388 if gGameOn then
2389 g_Game_Announce_BodyKill(gDelayedEvents[a].DENum);
2390 end;
2391 gDelayedEvents[a].Pending := False;
2392 end;
2394 // Каждую секунду обновляем счетчик обновлений:
2395 UPSCounter := UPSCounter + 1;
2396 if Time - UPSTime >= 1000 then
2397 begin
2398 UPS := UPSCounter;
2399 UPSCounter := 0;
2400 UPSTime := Time;
2401 end;
2403 if gGameOn then
2404 begin
2405 g_Weapon_AddDynLights();
2406 g_Items_AddDynLights();
2407 end;
2408 end;
2410 procedure g_Game_LoadChatSounds(Resource: string);
2411 var
2412 WAD: TWADFile;
2413 FileName, Snd: string;
2414 p: Pointer;
2415 len, cnt, tags, i, j: Integer;
2416 cfg: TConfig;
2417 begin
2418 FileName := g_ExtractWadName(Resource);
2420 WAD := TWADFile.Create();
2421 WAD.ReadFile(FileName);
2423 if not WAD.GetResource(g_ExtractFilePathName(Resource), p, len) then
2424 begin
2425 gChatSounds := nil;
2426 WAD.Free();
2427 Exit;
2428 end;
2430 cfg := TConfig.CreateMem(p, len);
2431 cnt := cfg.ReadInt('ChatSounds', 'Count', 0);
2433 SetLength(gChatSounds, cnt);
2434 for i := 0 to Length(gChatSounds) - 1 do
2435 begin
2436 gChatSounds[i].Sound := nil;
2437 Snd := Trim(cfg.ReadStr(IntToStr(i), 'Sound', ''));
2438 tags := cfg.ReadInt(IntToStr(i), 'Tags', 0);
2439 if (Snd = '') or (Tags <= 0) then
2440 continue;
2441 g_Sound_CreateWADEx('SOUND_CHAT_MACRO' + IntToStr(i), GameWAD+':'+Snd);
2442 gChatSounds[i].Sound := TPlayableSound.Create();
2443 gChatSounds[i].Sound.SetByName('SOUND_CHAT_MACRO' + IntToStr(i));
2444 SetLength(gChatSounds[i].Tags, tags);
2445 for j := 0 to tags - 1 do
2446 gChatSounds[i].Tags[j] := toLowerCase1251(cfg.ReadStr(IntToStr(i), 'Tag' + IntToStr(j), ''));
2447 gChatSounds[i].FullWord := cfg.ReadBool(IntToStr(i), 'FullWord', False);
2448 end;
2450 cfg.Free();
2451 WAD.Free();
2452 end;
2454 procedure g_Game_FreeChatSounds();
2455 var
2456 i: Integer;
2457 begin
2458 for i := 0 to Length(gChatSounds) - 1 do
2459 begin
2460 gChatSounds[i].Sound.Free();
2461 g_Sound_Delete('SOUND_CHAT_MACRO' + IntToStr(i));
2462 end;
2463 SetLength(gChatSounds, 0);
2464 gChatSounds := nil;
2465 end;
2467 procedure g_Game_LoadData();
2468 var
2469 wl, hl: Integer;
2470 wr, hr: Integer;
2471 wb, hb: Integer;
2472 wm, hm: Integer;
2473 begin
2474 if DataLoaded then Exit;
2476 e_WriteLog('Loading game data...', TMsgType.Notify);
2478 g_Texture_CreateWADEx('NOTEXTURE', GameWAD+':TEXTURES\NOTEXTURE');
2479 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUD', GameWAD+':TEXTURES\HUD');
2480 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDAIR', GameWAD+':TEXTURES\AIRBAR');
2481 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDJET', GameWAD+':TEXTURES\JETBAR');
2482 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDBG', GameWAD+':TEXTURES\HUDBG');
2483 g_Texture_CreateWADEx('TEXTURE_PLAYER_ARMORHUD', GameWAD+':TEXTURES\ARMORHUD');
2484 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG', GameWAD+':TEXTURES\FLAGHUD_R_BASE');
2485 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_S', GameWAD+':TEXTURES\FLAGHUD_R_STOLEN');
2486 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_D', GameWAD+':TEXTURES\FLAGHUD_R_DROP');
2487 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG', GameWAD+':TEXTURES\FLAGHUD_B_BASE');
2488 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_S', GameWAD+':TEXTURES\FLAGHUD_B_STOLEN');
2489 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_D', GameWAD+':TEXTURES\FLAGHUD_B_DROP');
2490 g_Texture_CreateWADEx('TEXTURE_PLAYER_TALKBUBBLE', GameWAD+':TEXTURES\TALKBUBBLE');
2491 g_Texture_CreateWADEx('TEXTURE_PLAYER_INVULPENTA', GameWAD+':TEXTURES\PENTA');
2492 g_Texture_CreateWADEx('TEXTURE_PLAYER_INDICATOR', GameWAD+':TEXTURES\PLRIND');
2494 hasPBarGfx := true;
2495 if not g_Texture_CreateWADEx('UI_GFX_PBAR_LEFT', GameWAD+':TEXTURES\LLEFT') then hasPBarGfx := false;
2496 if not g_Texture_CreateWADEx('UI_GFX_PBAR_MARKER', GameWAD+':TEXTURES\LMARKER') then hasPBarGfx := false;
2497 if not g_Texture_CreateWADEx('UI_GFX_PBAR_MIDDLE', GameWAD+':TEXTURES\LMIDDLE') then hasPBarGfx := false;
2498 if not g_Texture_CreateWADEx('UI_GFX_PBAR_RIGHT', GameWAD+':TEXTURES\LRIGHT') then hasPBarGfx := false;
2500 if hasPBarGfx then
2501 begin
2502 g_Texture_GetSize('UI_GFX_PBAR_LEFT', wl, hl);
2503 g_Texture_GetSize('UI_GFX_PBAR_RIGHT', wr, hr);
2504 g_Texture_GetSize('UI_GFX_PBAR_MIDDLE', wb, hb);
2505 g_Texture_GetSize('UI_GFX_PBAR_MARKER', wm, hm);
2506 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
2507 begin
2508 // yay!
2509 end
2510 else
2511 begin
2512 hasPBarGfx := false;
2513 end;
2514 end;
2516 g_Frames_CreateWAD(nil, 'FRAMES_TELEPORT', GameWAD+':TEXTURES\TELEPORT', 64, 64, 10, False);
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_TELEPORT');
2660 g_Frames_DeleteByName('FRAMES_PUNCH');
2661 g_Frames_DeleteByName('FRAMES_PUNCH_UP');
2662 g_Frames_DeleteByName('FRAMES_PUNCH_DN');
2663 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK');
2664 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK_UP');
2665 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK_DN');
2666 g_Sound_Delete('SOUND_GAME_TELEPORT');
2667 g_Sound_Delete('SOUND_GAME_NOTELEPORT');
2668 g_Sound_Delete('SOUND_GAME_SECRET');
2669 g_Sound_Delete('SOUND_GAME_DOOROPEN');
2670 g_Sound_Delete('SOUND_GAME_DOORCLOSE');
2671 g_Sound_Delete('SOUND_GAME_BULK1');
2672 g_Sound_Delete('SOUND_GAME_BULK2');
2673 g_Sound_Delete('SOUND_GAME_BUBBLE1');
2674 g_Sound_Delete('SOUND_GAME_BUBBLE2');
2675 g_Sound_Delete('SOUND_GAME_BURNING');
2676 g_Sound_Delete('SOUND_GAME_SWITCH1');
2677 g_Sound_Delete('SOUND_GAME_SWITCH0');
2679 goodsnd[0].Free();
2680 goodsnd[1].Free();
2681 goodsnd[2].Free();
2682 goodsnd[3].Free();
2684 g_Sound_Delete('SOUND_ANNOUNCER_GOOD1');
2685 g_Sound_Delete('SOUND_ANNOUNCER_GOOD2');
2686 g_Sound_Delete('SOUND_ANNOUNCER_GOOD3');
2687 g_Sound_Delete('SOUND_ANNOUNCER_GOOD4');
2689 killsnd[0].Free();
2690 killsnd[1].Free();
2691 killsnd[2].Free();
2692 killsnd[3].Free();
2694 g_Sound_Delete('SOUND_ANNOUNCER_KILL2X');
2695 g_Sound_Delete('SOUND_ANNOUNCER_KILL3X');
2696 g_Sound_Delete('SOUND_ANNOUNCER_KILL4X');
2697 g_Sound_Delete('SOUND_ANNOUNCER_KILLMX');
2699 hahasnd[0].Free();
2700 hahasnd[1].Free();
2701 hahasnd[2].Free();
2703 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA1');
2704 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA2');
2705 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA3');
2707 sound_get_flag[0].Free();
2708 sound_get_flag[1].Free();
2709 sound_lost_flag[0].Free();
2710 sound_lost_flag[1].Free();
2711 sound_ret_flag[0].Free();
2712 sound_ret_flag[1].Free();
2713 sound_cap_flag[0].Free();
2714 sound_cap_flag[1].Free();
2716 g_Sound_Delete('SOUND_CTF_GET1');
2717 g_Sound_Delete('SOUND_CTF_GET2');
2718 g_Sound_Delete('SOUND_CTF_LOST1');
2719 g_Sound_Delete('SOUND_CTF_LOST2');
2720 g_Sound_Delete('SOUND_CTF_RETURN1');
2721 g_Sound_Delete('SOUND_CTF_RETURN2');
2722 g_Sound_Delete('SOUND_CTF_CAPTURE1');
2723 g_Sound_Delete('SOUND_CTF_CAPTURE2');
2725 g_Game_FreeChatSounds();
2727 DataLoaded := False;
2728 end;
2730 procedure g_FatalError(Text: String);
2731 begin
2732 g_Console_Add(Format(_lc[I_FATAL_ERROR], [Text]), True);
2733 e_WriteLog(Format(_lc[I_FATAL_ERROR], [Text]), TMsgType.Warning);
2735 gExit := EXIT_SIMPLE;
2736 if gGameOn then EndGame;
2737 end;
2739 procedure g_SimpleError(Text: String);
2740 begin
2741 g_Console_Add(Format(_lc[I_SIMPLE_ERROR], [Text]), True);
2742 e_WriteLog(Format(_lc[I_SIMPLE_ERROR], [Text]), TMsgType.Warning);
2743 end;
2745 procedure g_Game_SetupScreenSize();
2746 const
2747 RES_FACTOR = 4.0 / 3.0;
2748 var
2749 s: Single;
2750 rf: Single;
2751 bw, bh: Word;
2752 begin
2753 // Размер экранов игроков:
2754 gPlayerScreenSize.X := gScreenWidth-196;
2755 if (gPlayer1 <> nil) and (gPlayer2 <> nil) then
2756 gPlayerScreenSize.Y := gScreenHeight div 2
2757 else
2758 gPlayerScreenSize.Y := gScreenHeight;
2760 // Размер заднего плана:
2761 if BackID <> DWORD(-1) then
2762 begin
2763 s := SKY_STRETCH;
2764 if (gScreenWidth*s > gMapInfo.Width) or
2765 (gScreenHeight*s > gMapInfo.Height) then
2766 begin
2767 gBackSize.X := gScreenWidth;
2768 gBackSize.Y := gScreenHeight;
2769 end
2770 else
2771 begin
2772 e_GetTextureSize(BackID, @bw, @bh);
2773 rf := Single(bw) / Single(bh);
2774 if (rf > RES_FACTOR) then bw := Round(Single(bh) * RES_FACTOR)
2775 else if (rf < RES_FACTOR) then bh := Round(Single(bw) / RES_FACTOR);
2776 s := Max(gScreenWidth / bw, gScreenHeight / bh);
2777 if (s < 1.0) then s := 1.0;
2778 gBackSize.X := Round(bw*s);
2779 gBackSize.Y := Round(bh*s);
2780 end;
2781 end;
2782 end;
2784 procedure g_Game_AddPlayer(Team: Byte = TEAM_NONE);
2785 begin
2786 if ((not gGameOn) and (gState <> STATE_INTERCUSTOM))
2787 or (not (gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT])) then
2788 Exit;
2790 if (gGameSettings.MaxLives > 0) and (gLMSRespawn = LMS_RESPAWN_NONE) then
2791 Exit;
2793 if gPlayer1 = nil then
2794 begin
2795 if g_Game_IsClient then
2796 begin
2797 if NetPlrUID1 > -1 then
2798 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE);
2799 Exit;
2800 end;
2802 if not (Team in [TEAM_RED, TEAM_BLUE]) then
2803 Team := gPlayer1Settings.Team;
2805 // Создание первого игрока:
2806 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
2807 gPlayer1Settings.Color,
2808 Team, False));
2809 if gPlayer1 = nil then
2810 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]))
2811 else
2812 begin
2813 gPlayer1.Name := gPlayer1Settings.Name;
2814 g_Console_Add(Format(_lc[I_PLAYER_JOIN], [gPlayer1.Name]), True);
2815 if g_Game_IsServer and g_Game_IsNet then
2816 MH_SEND_PlayerCreate(gPlayer1.UID);
2817 gPlayer1.Respawn(False, True);
2818 g_Net_Slist_ServerPlayerComes();
2819 end;
2821 Exit;
2822 end;
2823 if gPlayer2 = nil then
2824 begin
2825 if g_Game_IsClient then
2826 begin
2827 if NetPlrUID2 > -1 then
2828 gPlayer2 := g_Player_Get(NetPlrUID2);
2829 Exit;
2830 end;
2832 if not (Team in [TEAM_RED, TEAM_BLUE]) then
2833 Team := gPlayer2Settings.Team;
2835 // Создание второго игрока:
2836 gPlayer2 := g_Player_Get(g_Player_Create(gPlayer2Settings.Model,
2837 gPlayer2Settings.Color,
2838 Team, False));
2839 if gPlayer2 = nil then
2840 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [2]))
2841 else
2842 begin
2843 gPlayer2.Name := gPlayer2Settings.Name;
2844 g_Console_Add(Format(_lc[I_PLAYER_JOIN], [gPlayer2.Name]), True);
2845 if g_Game_IsServer and g_Game_IsNet then
2846 MH_SEND_PlayerCreate(gPlayer2.UID);
2847 gPlayer2.Respawn(False, True);
2848 g_Net_Slist_ServerPlayerComes();
2849 end;
2851 Exit;
2852 end;
2853 end;
2855 procedure g_Game_RemovePlayer();
2856 var
2857 Pl: TPlayer;
2858 begin
2859 if ((not gGameOn) and (gState <> STATE_INTERCUSTOM))
2860 or (not (gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT])) then
2861 Exit;
2862 Pl := gPlayer2;
2863 if Pl <> nil then
2864 begin
2865 if g_Game_IsServer then
2866 begin
2867 Pl.Lives := 0;
2868 Pl.Kill(K_SIMPLEKILL, 0, HIT_DISCON);
2869 g_Console_Add(Format(_lc[I_PLAYER_LEAVE], [Pl.Name]), True);
2870 g_Player_Remove(Pl.UID);
2871 g_Net_Slist_ServerPlayerLeaves();
2872 end
2873 else
2874 begin
2875 gSpectLatchPID2 := Pl.UID;
2876 gPlayer2 := nil;
2877 end;
2878 Exit;
2879 end;
2880 Pl := gPlayer1;
2881 if Pl <> nil then
2882 begin
2883 if g_Game_IsServer then
2884 begin
2885 Pl.Lives := 0;
2886 Pl.Kill(K_SIMPLEKILL, 0, HIT_DISCON);
2887 g_Console_Add(Format(_lc[I_PLAYER_LEAVE], [Pl.Name]), True);
2888 g_Player_Remove(Pl.UID);
2889 g_Net_Slist_ServerPlayerLeaves();
2890 end else
2891 begin
2892 gSpectLatchPID1 := Pl.UID;
2893 gPlayer1 := nil;
2894 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE);
2895 end;
2896 Exit;
2897 end;
2898 g_Net_Slist_ServerPlayerLeaves();
2899 end;
2901 procedure g_Game_Spectate();
2902 begin
2903 g_Game_RemovePlayer();
2904 if gPlayer1 <> nil then
2905 g_Game_RemovePlayer();
2906 end;
2908 procedure g_Game_SpectateCenterView();
2909 begin
2910 gSpectX := Max(gMapInfo.Width div 2 - gScreenWidth div 2, 0);
2911 gSpectY := Max(gMapInfo.Height div 2 - gScreenHeight div 2, 0);
2912 end;
2914 procedure g_Game_StartSingle(Map: String; TwoPlayers: Boolean; nPlayers: Byte);
2915 var
2916 i, nPl: Integer;
2917 tmps: AnsiString;
2918 begin
2919 g_Game_Free();
2921 e_WriteLog('Starting singleplayer game...', TMsgType.Notify);
2923 g_Game_ClearLoading();
2925 // Настройки игры:
2926 FillByte(gGameSettings, SizeOf(TGameSettings), 0);
2927 gAimLine := False;
2928 gShowMap := False;
2929 gGameSettings.GameType := GT_SINGLE;
2930 gGameSettings.MaxLives := 0;
2931 gGameSettings.Options := gGameSettings.Options + GAME_OPTION_ALLOWEXIT;
2932 gGameSettings.Options := gGameSettings.Options + GAME_OPTION_MONSTERS;
2933 gGameSettings.Options := gGameSettings.Options + GAME_OPTION_BOTVSMONSTER;
2934 gGameSettings.Options := gGameSettings.Options + GAME_OPTION_TEAMHITPROJECTILE;
2935 gGameSettings.Options := gGameSettings.Options + GAME_OPTION_TEAMHITTRACE;
2936 gSwitchGameMode := GM_SINGLE;
2938 gLMSRespawn := LMS_RESPAWN_NONE;
2939 gLMSRespawnTime := 0;
2940 gSpectLatchPID1 := 0;
2941 gSpectLatchPID2 := 0;
2943 g_Game_ExecuteEvent('ongamestart');
2945 // Установка размеров окон игроков:
2946 g_Game_SetupScreenSize();
2948 // Создание первого игрока:
2949 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
2950 gPlayer1Settings.Color,
2951 gPlayer1Settings.Team, False));
2952 if gPlayer1 = nil then
2953 begin
2954 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]));
2955 Exit;
2956 end;
2958 gPlayer1.Name := gPlayer1Settings.Name;
2959 nPl := 1;
2961 // Создание второго игрока, если есть:
2962 if TwoPlayers then
2963 begin
2964 gPlayer2 := g_Player_Get(g_Player_Create(gPlayer2Settings.Model,
2965 gPlayer2Settings.Color,
2966 gPlayer2Settings.Team, False));
2967 if gPlayer2 = nil then
2968 begin
2969 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [2]));
2970 Exit;
2971 end;
2973 gPlayer2.Name := gPlayer2Settings.Name;
2974 Inc(nPl);
2975 end;
2977 // Загрузка и запуск карты:
2978 if not g_Game_StartMap(false{asMegawad}, MAP, True) then
2979 begin
2980 if (Pos(':\', Map) > 0) or (Pos(':/', Map) > 0) then tmps := Map else tmps := gGameSettings.WAD + ':\' + MAP;
2981 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [tmps]));
2982 Exit;
2983 end;
2985 // Настройки игроков и ботов:
2986 g_Player_Init();
2988 // Создаем ботов:
2989 for i := nPl+1 to nPlayers do
2990 g_Player_Create(STD_PLAYER_MODEL, _RGB(0, 0, 0), 0, True);
2991 end;
2993 procedure g_Game_StartCustom(Map: String; GameMode: Byte;
2994 TimeLimit, GoalLimit: Word;
2995 MaxLives: Byte;
2996 Options: LongWord; nPlayers: Byte);
2997 var
2998 i, nPl: Integer;
2999 begin
3000 g_Game_Free();
3002 e_WriteLog('Starting custom game...', TMsgType.Notify);
3004 g_Game_ClearLoading();
3006 // Настройки игры:
3007 gGameSettings.GameType := GT_CUSTOM;
3008 gGameSettings.GameMode := GameMode;
3009 gSwitchGameMode := GameMode;
3010 gGameSettings.TimeLimit := TimeLimit;
3011 gGameSettings.GoalLimit := GoalLimit;
3012 gGameSettings.MaxLives := IfThen(GameMode = GM_CTF, 0, MaxLives);
3013 gGameSettings.Options := Options;
3015 gCoopTotalMonstersKilled := 0;
3016 gCoopTotalSecretsFound := 0;
3017 gCoopTotalMonsters := 0;
3018 gCoopTotalSecrets := 0;
3019 gAimLine := False;
3020 gShowMap := False;
3022 gLMSRespawn := LMS_RESPAWN_NONE;
3023 gLMSRespawnTime := 0;
3024 gSpectLatchPID1 := 0;
3025 gSpectLatchPID2 := 0;
3027 g_Game_ExecuteEvent('ongamestart');
3029 // Установка размеров окон игроков:
3030 g_Game_SetupScreenSize();
3032 // Режим наблюдателя:
3033 if nPlayers = 0 then
3034 begin
3035 gPlayer1 := nil;
3036 gPlayer2 := nil;
3037 end;
3039 nPl := 0;
3040 if nPlayers >= 1 then
3041 begin
3042 // Создание первого игрока:
3043 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
3044 gPlayer1Settings.Color,
3045 gPlayer1Settings.Team, False));
3046 if gPlayer1 = nil then
3047 begin
3048 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]));
3049 Exit;
3050 end;
3052 gPlayer1.Name := gPlayer1Settings.Name;
3053 Inc(nPl);
3054 end;
3056 if nPlayers >= 2 then
3057 begin
3058 // Создание второго игрока:
3059 gPlayer2 := g_Player_Get(g_Player_Create(gPlayer2Settings.Model,
3060 gPlayer2Settings.Color,
3061 gPlayer2Settings.Team, False));
3062 if gPlayer2 = nil then
3063 begin
3064 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [2]));
3065 Exit;
3066 end;
3068 gPlayer2.Name := gPlayer2Settings.Name;
3069 Inc(nPl);
3070 end;
3072 // Загрузка и запуск карты:
3073 if not g_Game_StartMap(true{asMegawad}, Map, True) then
3074 begin
3075 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [Map]));
3076 Exit;
3077 end;
3079 // Нет точек появления:
3080 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1) +
3081 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2) +
3082 g_Map_GetPointCount(RESPAWNPOINT_DM) +
3083 g_Map_GetPointCount(RESPAWNPOINT_RED)+
3084 g_Map_GetPointCount(RESPAWNPOINT_BLUE)) < 1 then
3085 begin
3086 g_FatalError(_lc[I_GAME_ERROR_GET_SPAWN]);
3087 Exit;
3088 end;
3090 // Настройки игроков и ботов:
3091 g_Player_Init();
3093 // Создаем ботов:
3094 for i := nPl+1 to nPlayers do
3095 g_Player_Create(STD_PLAYER_MODEL, _RGB(0, 0, 0), 0, True);
3096 end;
3098 procedure g_Game_StartServer(Map: String; GameMode: Byte;
3099 TimeLimit, GoalLimit: Word; MaxLives: Byte;
3100 Options: LongWord; nPlayers: Byte;
3101 IPAddr: LongWord; Port: Word);
3102 begin
3103 g_Game_Free();
3104 g_Net_Slist_ServerClosed();
3106 e_WriteLog('Starting net game (server)...', TMsgType.Notify);
3108 g_Game_ClearLoading();
3110 // Настройки игры:
3111 gGameSettings.GameType := GT_SERVER;
3112 gGameSettings.GameMode := GameMode;
3113 gSwitchGameMode := GameMode;
3114 gGameSettings.TimeLimit := TimeLimit;
3115 gGameSettings.GoalLimit := GoalLimit;
3116 gGameSettings.MaxLives := IfThen(GameMode = GM_CTF, 0, MaxLives);
3117 gGameSettings.Options := Options;
3119 gCoopTotalMonstersKilled := 0;
3120 gCoopTotalSecretsFound := 0;
3121 gCoopTotalMonsters := 0;
3122 gCoopTotalSecrets := 0;
3123 gAimLine := False;
3124 gShowMap := False;
3126 gLMSRespawn := LMS_RESPAWN_NONE;
3127 gLMSRespawnTime := 0;
3128 gSpectLatchPID1 := 0;
3129 gSpectLatchPID2 := 0;
3131 g_Game_ExecuteEvent('ongamestart');
3133 // Установка размеров окна игрока
3134 g_Game_SetupScreenSize();
3136 // Режим наблюдателя:
3137 if nPlayers = 0 then
3138 begin
3139 gPlayer1 := nil;
3140 gPlayer2 := nil;
3141 end;
3143 if nPlayers >= 1 then
3144 begin
3145 // Создание первого игрока:
3146 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
3147 gPlayer1Settings.Color,
3148 gPlayer1Settings.Team, False));
3149 if gPlayer1 = nil then
3150 begin
3151 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]));
3152 Exit;
3153 end;
3155 gPlayer1.Name := gPlayer1Settings.Name;
3156 end;
3158 if nPlayers >= 2 then
3159 begin
3160 // Создание второго игрока:
3161 gPlayer2 := g_Player_Get(g_Player_Create(gPlayer2Settings.Model,
3162 gPlayer2Settings.Color,
3163 gPlayer2Settings.Team, False));
3164 if gPlayer2 = nil then
3165 begin
3166 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [2]));
3167 Exit;
3168 end;
3170 gPlayer2.Name := gPlayer2Settings.Name;
3171 end;
3173 g_Game_SetLoadingText(_lc[I_LOAD_HOST], 0, False);
3174 if NetForwardPorts then
3175 g_Game_SetLoadingText(_lc[I_LOAD_PORTS], 0, False);
3177 // Стартуем сервер
3178 if not g_Net_Host(IPAddr, Port, NetMaxClients) then
3179 begin
3180 g_FatalError(_lc[I_NET_MSG] + Format(_lc[I_NET_ERR_HOST], [Port]));
3181 Exit;
3182 end;
3184 g_Net_Slist_Set(NetMasterList);
3186 g_Net_Slist_ServerStarted();
3188 // Загрузка и запуск карты:
3189 if not g_Game_StartMap(false{asMegawad}, Map, True) then
3190 begin
3191 g_Net_Slist_ServerClosed();
3192 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [Map]));
3193 Exit;
3194 end;
3196 // Нет точек появления:
3197 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1) +
3198 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2) +
3199 g_Map_GetPointCount(RESPAWNPOINT_DM) +
3200 g_Map_GetPointCount(RESPAWNPOINT_RED)+
3201 g_Map_GetPointCount(RESPAWNPOINT_BLUE)) < 1 then
3202 begin
3203 g_Net_Slist_ServerClosed();
3204 g_FatalError(_lc[I_GAME_ERROR_GET_SPAWN]);
3205 Exit;
3206 end;
3208 // Настройки игроков и ботов:
3209 g_Player_Init();
3211 g_Net_Slist_ServerMapStarted();
3212 NetState := NET_STATE_GAME;
3213 end;
3215 procedure g_Game_StartClient(Addr: String; Port: Word; PW: String);
3216 var
3217 Map: String;
3218 WadName: string;
3219 Ptr: Pointer;
3220 T: Cardinal;
3221 MID: Byte;
3222 State: Byte;
3223 OuterLoop: Boolean;
3224 newResPath: string;
3225 InMsg: TMsg;
3226 begin
3227 g_Game_Free();
3229 State := 0;
3230 e_WriteLog('Starting net game (client)...', TMsgType.Notify);
3231 e_WriteLog('NET: Trying to connect to ' + Addr + ':' + IntToStr(Port) + '...', TMsgType.Notify);
3233 g_Game_ClearLoading();
3235 // Настройки игры:
3236 gGameSettings.GameType := GT_CLIENT;
3238 gCoopTotalMonstersKilled := 0;
3239 gCoopTotalSecretsFound := 0;
3240 gCoopTotalMonsters := 0;
3241 gCoopTotalSecrets := 0;
3242 gAimLine := False;
3243 gShowMap := False;
3245 g_Game_ExecuteEvent('ongamestart');
3247 // Установка размеров окон игроков:
3248 g_Game_SetupScreenSize();
3250 NetState := NET_STATE_AUTH;
3252 g_Game_SetLoadingText(_lc[I_LOAD_CONNECT], 0, False);
3254 // create (or update) map/resource databases
3255 g_Res_CreateDatabases(true);
3257 gLMSRespawn := LMS_RESPAWN_NONE;
3258 gLMSRespawnTime := 0;
3259 gSpectLatchPID1 := 0;
3260 gSpectLatchPID2 := 0;
3262 // Стартуем клиент
3263 if not g_Net_Connect(Addr, Port) then
3264 begin
3265 g_FatalError(_lc[I_NET_MSG] + _lc[I_NET_ERR_CONN]);
3266 NetState := NET_STATE_NONE;
3267 Exit;
3268 end;
3270 g_Game_SetLoadingText(_lc[I_LOAD_SEND_INFO], 0, False);
3271 MC_SEND_Info(PW);
3272 g_Game_SetLoadingText(_lc[I_LOAD_WAIT_INFO], 0, False);
3274 OuterLoop := True;
3275 while OuterLoop do
3276 begin
3277 // fuck! https://www.mail-archive.com/enet-discuss@cubik.org/msg00852.html
3278 // tl;dr: on shitdows, we can get -1 sometimes, and it is *NOT* a failure.
3279 // thank you, enet. let's ignore failures altogether then.
3280 while (enet_host_service(NetHost, @NetEvent, 50) > 0) do
3281 begin
3282 if (NetEvent.kind = ENET_EVENT_TYPE_RECEIVE) then
3283 begin
3284 if (NetEvent.channelID = NET_CHAN_DOWNLOAD_EX) then
3285 begin
3286 // ignore all download packets, they're processed by separate code
3287 enet_packet_destroy(NetEvent.packet);
3288 continue;
3289 end;
3290 Ptr := NetEvent.packet^.data;
3291 if not InMsg.Init(Ptr, NetEvent.packet^.dataLength, True) then
3292 begin
3293 enet_packet_destroy(NetEvent.packet);
3294 continue;
3295 end;
3297 InMsg.ReadLongWord(); // skip size
3298 MID := InMsg.ReadByte();
3300 if (MID = NET_MSG_INFO) and (State = 0) then
3301 begin
3302 NetMyID := InMsg.ReadByte();
3303 NetPlrUID1 := InMsg.ReadWord();
3305 WadName := InMsg.ReadString();
3306 Map := InMsg.ReadString();
3308 gWADHash := InMsg.ReadMD5();
3310 gGameSettings.GameMode := InMsg.ReadByte();
3311 gSwitchGameMode := gGameSettings.GameMode;
3312 gGameSettings.GoalLimit := InMsg.ReadWord();
3313 gGameSettings.TimeLimit := InMsg.ReadWord();
3314 gGameSettings.MaxLives := InMsg.ReadByte();
3315 gGameSettings.Options := InMsg.ReadLongWord();
3316 T := InMsg.ReadLongWord();
3318 //newResPath := g_Res_SearchSameWAD(MapsDir, WadName, gWADHash);
3319 //if newResPath = '' then
3320 begin
3321 //g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
3322 newResPath := g_Res_DownloadMapWAD(ExtractFileName(WadName), gWADHash);
3323 if newResPath = '' then
3324 begin
3325 g_FatalError(_lc[I_NET_ERR_HASH]);
3326 enet_packet_destroy(NetEvent.packet);
3327 NetState := NET_STATE_NONE;
3328 Exit;
3329 end;
3330 e_LogWritefln('using downloaded map wad [%s] for [%s]`', [newResPath, WadName], TMsgType.Notify);
3331 end;
3332 //newResPath := ExtractRelativePath(MapsDir, newResPath);
3335 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
3336 gPlayer1Settings.Color,
3337 gPlayer1Settings.Team, False));
3339 if gPlayer1 = nil then
3340 begin
3341 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]));
3343 enet_packet_destroy(NetEvent.packet);
3344 NetState := NET_STATE_NONE;
3345 Exit;
3346 end;
3348 gPlayer1.Name := gPlayer1Settings.Name;
3349 gPlayer1.UID := NetPlrUID1;
3350 gPlayer1.Reset(True);
3352 if not g_Game_StartMap(false{asMegawad}, newResPath + ':\' + Map, True) then
3353 begin
3354 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [WadName + ':\' + Map]));
3356 enet_packet_destroy(NetEvent.packet);
3357 NetState := NET_STATE_NONE;
3358 Exit;
3359 end;
3361 gTime := T;
3363 State := 1;
3364 OuterLoop := False;
3365 enet_packet_destroy(NetEvent.packet);
3366 break;
3367 end
3368 else
3369 enet_packet_destroy(NetEvent.packet);
3370 end
3371 else
3372 begin
3373 if (NetEvent.kind = ENET_EVENT_TYPE_DISCONNECT) then
3374 begin
3375 State := 0;
3376 if (NetEvent.data <= NET_DISC_MAX) then
3377 g_Console_Add(_lc[I_NET_MSG_ERROR] + _lc[I_NET_ERR_CONN] + ' ' +
3378 _lc[TStrings_Locale(Cardinal(I_NET_DISC_NONE) + NetEvent.data)], True);
3379 OuterLoop := False;
3380 Break;
3381 end;
3382 end;
3383 end;
3385 ProcessLoading(true);
3387 if g_Net_UserRequestExit() then
3388 begin
3389 State := 0;
3390 break;
3391 end;
3392 end;
3394 if State <> 1 then
3395 begin
3396 g_FatalError(_lc[I_NET_MSG] + _lc[I_NET_ERR_CONN]);
3397 NetState := NET_STATE_NONE;
3398 Exit;
3399 end;
3401 g_Player_Init();
3402 NetState := NET_STATE_GAME;
3403 MC_SEND_FullStateRequest;
3404 e_WriteLog('NET: Connection successful.', TMsgType.Notify);
3405 end;
3407 var
3408 lastAsMegaWad: Boolean = false;
3410 procedure g_Game_ChangeMap(const MapPath: String);
3411 var
3412 Force: Boolean;
3413 begin
3414 g_Game_ClearLoading();
3416 Force := gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF];
3417 // Если уровень завершился по триггеру Выход, не очищать инвентарь
3418 if gExitByTrigger then
3419 begin
3420 Force := False;
3421 gExitByTrigger := False;
3422 end;
3423 if not g_Game_StartMap(lastAsMegaWad, MapPath, Force) then
3424 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [MapPath]));
3425 end;
3427 procedure g_Game_Restart();
3428 var
3429 Map: string;
3430 begin
3431 if g_Game_IsClient then
3432 Exit;
3433 map := g_ExtractFileName(gMapInfo.Map);
3434 e_LogWritefln('g_Game_Restart: map = "%s" gCurrentMapFileName = "%s"', [map, gCurrentMapFileName]);
3436 MessageTime := 0;
3437 gGameOn := False;
3438 g_Game_ClearLoading();
3439 g_Game_StartMap(lastAsMegaWad, Map, True, gCurrentMapFileName);
3440 end;
3442 function g_Game_StartMap (asMegawad: Boolean; Map: String; Force: Boolean = False; const oldMapPath: AnsiString=''): Boolean;
3443 var
3444 NewWAD, ResName: String;
3445 I: Integer;
3446 nws: AnsiString;
3447 begin
3448 g_Map_Free((Map <> gCurrentMapFileName) and (oldMapPath <> gCurrentMapFileName));
3449 g_Player_RemoveAllCorpses();
3451 if (not g_Game_IsClient) and
3452 (gSwitchGameMode <> gGameSettings.GameMode) and
3453 (gGameSettings.GameMode <> GM_SINGLE) then
3454 begin
3455 if gSwitchGameMode = GM_CTF then
3456 gGameSettings.MaxLives := 0;
3457 gGameSettings.GameMode := gSwitchGameMode;
3458 Force := True;
3459 end else
3460 gSwitchGameMode := gGameSettings.GameMode;
3462 g_Player_ResetTeams();
3464 lastAsMegaWad := asMegawad;
3465 if isWadPath(Map) then
3466 begin
3467 NewWAD := g_ExtractWadName(Map);
3468 ResName := g_ExtractFileName(Map);
3469 if g_Game_IsServer then
3470 begin
3471 nws := findDiskWad(NewWAD);
3472 //writeln('000: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
3473 if (asMegawad) then
3474 begin
3475 if (length(nws) = 0) then nws := e_FindWad(MegawadDirs, NewWAD);
3476 if (length(nws) = 0) then nws := e_FindWad(MapDirs, NewWAD);
3477 end
3478 else
3479 begin
3480 if (length(nws) = 0) then nws := e_FindWad(MapDirs, NewWAD);
3481 if (length(nws) = 0) then nws := e_FindWad(MegawadDirs, NewWAD);
3482 end;
3483 //if (length(nws) = 0) then nws := e_FindWad(MapDownloadDirs, NewWAD);
3484 //writeln('001: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
3485 //nws := NewWAD;
3486 if (length(nws) = 0) then
3487 begin
3488 ResName := ''; // failed
3489 end
3490 else
3491 begin
3492 NewWAD := nws;
3493 if (g_Game_IsNet) then gWADHash := MD5File(nws);
3494 //writeln('********: nws=', nws, ' : Map=', Map, ' : nw=', NewWAD, ' : resname=', ResName);
3495 g_Game_LoadWAD(NewWAD);
3496 end;
3497 end
3498 else
3499 begin
3500 // hash received in MC_RECV_GameEvent -> NET_EV_MAPSTART
3501 NewWAD := g_Game_ClientWAD(NewWAD, gWADHash);
3502 end;
3503 end
3504 else
3505 begin
3506 NewWAD := gGameSettings.WAD;
3507 ResName := Map;
3508 end;
3510 gTime := 0;
3512 //writeln('********: gsw=', gGameSettings.WAD, '; rn=', ResName);
3513 result := false;
3514 if (ResName <> '') and (NewWAD <> '') then
3515 begin
3516 //result := g_Map_Load(gGameSettings.WAD + ':\' + ResName);
3517 result := g_Map_Load(NewWAD+':\'+ResName);
3518 end;
3519 if Result then
3520 begin
3521 g_Player_ResetAll(Force or gLastMap, gGameSettings.GameType = GT_SINGLE);
3523 gState := STATE_NONE;
3524 g_ActiveWindow := nil;
3525 gGameOn := True;
3527 DisableCheats();
3528 wNeedTimeReset := True;
3530 if gGameSettings.GameMode = GM_CTF then
3531 begin
3532 g_Map_ResetFlag(FLAG_RED);
3533 g_Map_ResetFlag(FLAG_BLUE);
3534 // CTF, а флагов нет:
3535 if not g_Map_HaveFlagPoints() then
3536 g_SimpleError(_lc[I_GAME_ERROR_CTF]);
3537 end;
3538 end
3539 else
3540 begin
3541 gState := STATE_MENU;
3542 gGameOn := False;
3543 end;
3545 gExit := 0;
3546 gPauseMain := false;
3547 gPauseHolmes := false;
3548 NetTimeToUpdate := 1;
3549 NetTimeToReliable := 0;
3550 NetTimeToMaster := NetMasterRate;
3551 gSpectLatchPID1 := 0;
3552 gSpectLatchPID2 := 0;
3553 gMissionFailed := False;
3554 gNextMap := '';
3556 gCoopMonstersKilled := 0;
3557 gCoopSecretsFound := 0;
3559 gVoteInProgress := False;
3560 gVotePassed := False;
3561 gVoteCount := 0;
3562 gVoted := False;
3564 gStatsOff := False;
3566 if not gGameOn then Exit;
3568 g_Game_SpectateCenterView();
3570 if g_Game_IsServer then
3571 begin
3572 if (gGameSettings.MaxLives > 0) and (gGameSettings.WarmupTime > 0) then
3573 begin
3574 gLMSRespawn := LMS_RESPAWN_WARMUP;
3575 gLMSRespawnTime := gTime + gGameSettings.WarmupTime*1000;
3576 gLMSSoftSpawn := True;
3577 if g_Game_IsNet then
3578 MH_SEND_GameEvent(NET_EV_LMS_WARMUP, gLMSRespawnTime - gTime);
3579 end
3580 else
3581 begin
3582 gLMSRespawn := LMS_RESPAWN_NONE;
3583 gLMSRespawnTime := 0;
3584 end;
3585 end;
3587 if NetMode = NET_SERVER then
3588 begin
3589 MH_SEND_GameEvent(NET_EV_MAPSTART, gGameSettings.GameMode, Map);
3591 // Мастерсервер
3592 g_Net_Slist_ServerMapStarted();
3594 if NetClients <> nil then
3595 for I := 0 to High(NetClients) do
3596 if NetClients[I].Used then
3597 begin
3598 NetClients[I].Voted := False;
3599 if NetClients[I].RequestedFullUpdate then
3600 begin
3601 MH_SEND_Everything((NetClients[I].State = NET_STATE_AUTH), I);
3602 NetClients[I].RequestedFullUpdate := False;
3603 end;
3604 end;
3606 g_Net_UnbanNonPermHosts();
3607 end;
3609 if gLastMap then
3610 begin
3611 gCoopTotalMonstersKilled := 0;
3612 gCoopTotalSecretsFound := 0;
3613 gCoopTotalMonsters := 0;
3614 gCoopTotalSecrets := 0;
3615 gLastMap := False;
3616 end;
3618 g_Game_ExecuteEvent('onmapstart');
3619 end;
3621 procedure SetFirstLevel;
3622 begin
3623 gNextMap := '';
3625 MapList := g_Map_GetMapsList(gGameSettings.WAD);
3626 if MapList = nil then
3627 Exit;
3629 SortSArray(MapList);
3630 gNextMap := MapList[Low(MapList)];
3632 MapList := nil;
3633 end;
3635 procedure g_Game_ExitLevel(const Map: AnsiString);
3636 begin
3637 gNextMap := Map;
3639 gCoopTotalMonstersKilled := gCoopTotalMonstersKilled + gCoopMonstersKilled;
3640 gCoopTotalSecretsFound := gCoopTotalSecretsFound + gCoopSecretsFound;
3641 gCoopTotalMonsters := gCoopTotalMonsters + gTotalMonsters;
3642 gCoopTotalSecrets := gCoopTotalSecrets + gSecretsCount;
3644 // Вышли в выход в Одиночной игре:
3645 if gGameSettings.GameType = GT_SINGLE then
3646 gExit := EXIT_ENDLEVELSINGLE
3647 else // Вышли в выход в Своей игре
3648 begin
3649 gExit := EXIT_ENDLEVELCUSTOM;
3650 if gGameSettings.GameMode = GM_COOP then
3651 g_Player_RememberAll;
3653 if not g_Map_Exist(gGameSettings.WAD + ':\' + gNextMap) then
3654 begin
3655 gLastMap := True;
3656 if gGameSettings.GameMode = GM_COOP then
3657 gStatsOff := True;
3659 gStatsPressed := True;
3660 gNextMap := 'MAP01';
3662 if not g_Map_Exist(gGameSettings.WAD + ':\' + gNextMap) then
3663 g_Game_NextLevel;
3665 if g_Game_IsNet then
3666 begin
3667 MH_SEND_GameStats();
3668 MH_SEND_CoopStats();
3669 end;
3670 end;
3671 end;
3672 end;
3674 procedure g_Game_RestartLevel();
3675 var
3676 Map: string;
3677 begin
3678 if gGameSettings.GameMode = GM_SINGLE then
3679 begin
3680 g_Game_Restart();
3681 Exit;
3682 end;
3683 gExit := EXIT_ENDLEVELCUSTOM;
3684 Map := g_ExtractFileName(gMapInfo.Map);
3685 gNextMap := Map;
3686 end;
3688 function g_Game_ClientWAD (NewWAD: String; const WHash: TMD5Digest): AnsiString;
3689 var
3690 gWAD{, xwad}: String;
3691 begin
3692 result := NewWAD;
3693 if not g_Game_IsClient then Exit;
3694 //e_LogWritefln('*** g_Game_ClientWAD: `%s`', [NewWAD]);
3696 gWAD := g_Res_DownloadMapWAD(ExtractFileName(NewWAD), WHash);
3697 if gWAD = '' then
3698 begin
3699 result := '';
3700 g_Game_Free();
3701 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_WAD], [ExtractFileName(NewWAD)]));
3702 Exit;
3703 end;
3705 e_LogWritefln('using downloaded client map wad [%s] for [%s]', [gWAD, NewWAD], TMsgType.Notify);
3706 NewWAD := gWAD;
3708 g_Game_LoadWAD(NewWAD);
3709 result := NewWAD;
3712 if LowerCase(NewWAD) = LowerCase(gGameSettings.WAD) then Exit;
3713 gWAD := g_Res_SearchSameWAD(MapsDir, ExtractFileName(NewWAD), WHash);
3714 if gWAD = '' then
3715 begin
3716 g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
3717 gWAD := g_Res_DownloadMapWAD(ExtractFileName(NewWAD), WHash);
3718 if gWAD = '' then
3719 begin
3720 g_Game_Free();
3721 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_WAD], [ExtractFileName(NewWAD)]));
3722 Exit;
3723 end;
3724 end;
3725 NewWAD := ExtractRelativePath(MapsDir, gWAD);
3726 g_Game_LoadWAD(NewWAD);
3728 end;
3730 procedure g_Game_RestartRound(NoMapRestart: Boolean = False);
3731 var
3732 i, n, nb, nr: Integer;
3733 begin
3734 if not g_Game_IsServer then Exit;
3735 if gLMSRespawn = LMS_RESPAWN_NONE then Exit;
3736 gLMSRespawn := LMS_RESPAWN_NONE;
3737 gLMSRespawnTime := 0;
3738 MessageTime := 0;
3740 if (gGameSettings.GameMode = GM_COOP) and not NoMapRestart then
3741 begin
3742 gMissionFailed := True;
3743 g_Game_RestartLevel;
3744 Exit;
3745 end;
3747 n := 0; nb := 0; nr := 0;
3748 for i := Low(gPlayers) to High(gPlayers) do
3749 if (gPlayers[i] <> nil) and
3750 ((not gPlayers[i].FSpectator) or gPlayers[i].FWantsInGame or
3751 (gPlayers[i] is TBot)) then
3752 begin
3753 Inc(n);
3754 if gPlayers[i].Team = TEAM_RED then Inc(nr)
3755 else if gPlayers[i].Team = TEAM_BLUE then Inc(nb)
3756 end;
3758 if (n < 1) or ((gGameSettings.GameMode = GM_TDM) and ((nr = 0) or (nb = 0))) then
3759 begin
3760 // wait a second until the fuckers finally decide to join
3761 gLMSRespawn := LMS_RESPAWN_WARMUP;
3762 gLMSRespawnTime := gTime + gGameSettings.WarmupTime*1000;
3763 gLMSSoftSpawn := NoMapRestart;
3764 if g_Game_IsNet then
3765 MH_SEND_GameEvent(NET_EV_LMS_WARMUP, gLMSRespawnTime - gTime);
3766 Exit;
3767 end;
3769 g_Player_RemoveAllCorpses;
3770 g_Game_Message(_lc[I_MESSAGE_LMS_START], 144);
3771 if g_Game_IsNet then
3772 MH_SEND_GameEvent(NET_EV_LMS_START);
3774 for i := Low(gPlayers) to High(gPlayers) do
3775 begin
3776 if gPlayers[i] = nil then continue;
3777 if gPlayers[i] is TBot then gPlayers[i].FWantsInGame := True;
3778 // don't touch normal spectators
3779 if gPlayers[i].FSpectator and not gPlayers[i].FWantsInGame then
3780 begin
3781 gPlayers[i].FNoRespawn := True;
3782 gPlayers[i].Lives := 0;
3783 if g_Game_IsNet then
3784 MH_SEND_PlayerStats(gPlayers[I].UID);
3785 continue;
3786 end;
3787 gPlayers[i].FNoRespawn := False;
3788 gPlayers[i].Lives := gGameSettings.MaxLives;
3789 gPlayers[i].Respawn(False, True);
3790 if gGameSettings.GameMode = GM_COOP then
3791 begin
3792 gPlayers[i].Frags := 0;
3793 gPlayers[i].RecallState;
3794 end;
3795 if (gPlayer1 = nil) and (gSpectLatchPID1 > 0) then
3796 gPlayer1 := g_Player_Get(gSpectLatchPID1);
3797 if (gPlayer2 = nil) and (gSpectLatchPID2 > 0) then
3798 gPlayer2 := g_Player_Get(gSpectLatchPID2);
3799 end;
3801 g_Items_RestartRound();
3803 gLMSSoftSpawn := False;
3804 end;
3806 function g_Game_GetFirstMap(WAD: String): String;
3807 begin
3808 Result := '';
3810 MapList := g_Map_GetMapsList(WAD);
3811 if MapList = nil then
3812 Exit;
3814 SortSArray(MapList);
3815 Result := MapList[Low(MapList)];
3817 if not g_Map_Exist(WAD + ':\' + Result) then
3818 Result := '';
3820 MapList := nil;
3821 end;
3823 function g_Game_GetNextMap(): String;
3824 var
3825 I: Integer;
3826 Map: string;
3827 begin
3828 Result := '';
3830 MapList := g_Map_GetMapsList(gGameSettings.WAD);
3831 if MapList = nil then
3832 Exit;
3834 Map := g_ExtractFileName(gMapInfo.Map);
3836 SortSArray(MapList);
3837 MapIndex := -255;
3838 for I := Low(MapList) to High(MapList) do
3839 if Map = MapList[I] then
3840 begin
3841 MapIndex := I;
3842 Break;
3843 end;
3845 if MapIndex <> -255 then
3846 begin
3847 if MapIndex = High(MapList) then
3848 Result := MapList[Low(MapList)]
3849 else
3850 Result := MapList[MapIndex + 1];
3852 if not g_Map_Exist(gGameSettings.WAD + ':\' + Result) then Result := Map;
3853 end;
3855 MapList := nil;
3856 end;
3858 procedure g_Game_NextLevel();
3859 begin
3860 if gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF, GM_COOP] then
3861 gExit := EXIT_ENDLEVELCUSTOM
3862 else
3863 begin
3864 gExit := EXIT_ENDLEVELSINGLE;
3865 Exit;
3866 end;
3868 if gNextMap <> '' then Exit;
3869 gNextMap := g_Game_GetNextMap();
3870 end;
3872 function g_Game_IsTestMap(): Boolean;
3873 begin
3874 result := StrEquCI1251(TEST_MAP_NAME, g_ExtractFileName(gMapInfo.Map));
3875 end;
3877 procedure g_Game_DeleteTestMap();
3878 var
3879 a: Integer;
3880 //MapName: AnsiString;
3881 WadName: string;
3883 WAD: TWADFile;
3884 MapList: SSArray;
3885 time: Integer;
3887 begin
3888 a := Pos('.wad:\', toLowerCase1251(gMapToDelete));
3889 if (a = 0) then a := Pos('.wad:/', toLowerCase1251(gMapToDelete));
3890 if (a = 0) then exit;
3892 // Выделяем имя wad-файла и имя карты
3893 WadName := Copy(gMapToDelete, 1, a+3);
3894 Delete(gMapToDelete, 1, a+5);
3895 gMapToDelete := UpperCase(gMapToDelete);
3896 //MapName := '';
3897 //CopyMemory(@MapName[0], @gMapToDelete[1], Min(16, Length(gMapToDelete)));
3900 // Имя карты не стандартное тестовое:
3901 if MapName <> TEST_MAP_NAME then
3902 Exit;
3904 if not gTempDelete then
3905 begin
3906 time := g_GetFileTime(WadName);
3907 WAD := TWADFile.Create();
3909 // Читаем Wad-файл:
3910 if not WAD.ReadFile(WadName) then
3911 begin // Нет такого WAD-файла
3912 WAD.Free();
3913 Exit;
3914 end;
3916 // Составляем список карт и ищем нужную:
3917 WAD.CreateImage();
3918 MapList := WAD.GetResourcesList('');
3920 if MapList <> nil then
3921 for a := 0 to High(MapList) do
3922 if MapList[a] = MapName then
3923 begin
3924 // Удаляем и сохраняем:
3925 WAD.RemoveResource('', MapName);
3926 WAD.SaveTo(WadName);
3927 Break;
3928 end;
3930 WAD.Free();
3931 g_SetFileTime(WadName, time);
3932 end else
3934 if gTempDelete then DeleteFile(WadName);
3935 end;
3937 procedure GameCVars(P: SSArray);
3938 var
3939 a, b: Integer;
3940 stat: TPlayerStatArray;
3941 cmd: string;
3943 procedure ParseGameFlag(Flag: LongWord; OffMsg, OnMsg: TStrings_Locale; OnMapChange: Boolean = False);
3944 var
3945 x: Boolean;
3946 begin
3947 if Length(P) > 1 then
3948 begin
3949 x := P[1] = '1';
3951 if x then
3952 gsGameFlags := gsGameFlags or Flag
3953 else
3954 gsGameFlags := gsGameFlags and (not Flag);
3956 if g_Game_IsServer then
3957 begin
3958 if x then
3959 gGameSettings.Options := gGameSettings.Options or Flag
3960 else
3961 gGameSettings.Options := gGameSettings.Options and (not Flag);
3962 if g_Game_IsNet then MH_SEND_GameSettings;
3963 end;
3964 end;
3966 if LongBool(gsGameFlags and Flag) then
3967 g_Console_Add(_lc[OnMsg])
3968 else
3969 g_Console_Add(_lc[OffMsg]);
3971 if OnMapChange and g_Game_IsServer then
3972 g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
3973 end;
3975 begin
3976 stat := nil;
3977 cmd := LowerCase(P[0]);
3979 if cmd = 'g_gamemode' then
3980 begin
3981 if (Length(P) > 1) then
3982 begin
3983 a := g_Game_TextToMode(P[1]);
3984 if a = GM_SINGLE then a := GM_COOP;
3985 gsGameMode := g_Game_ModeToText(a);
3986 if g_Game_IsServer then
3987 begin
3988 gSwitchGameMode := a;
3989 if (gGameOn and (gGameSettings.GameMode = GM_SINGLE)) or
3990 (gState = STATE_INTERSINGLE) then
3991 gSwitchGameMode := GM_SINGLE;
3992 if not gGameOn then
3993 gGameSettings.GameMode := gSwitchGameMode;
3994 end;
3995 end;
3997 if gSwitchGameMode = gGameSettings.GameMode then
3998 g_Console_Add(Format(_lc[I_MSG_GAMEMODE_CURRENT],
3999 [g_Game_ModeToText(gGameSettings.GameMode)]))
4000 else
4001 g_Console_Add(Format(_lc[I_MSG_GAMEMODE_CHANGE],
4002 [g_Game_ModeToText(gGameSettings.GameMode),
4003 g_Game_ModeToText(gSwitchGameMode)]));
4004 end
4005 else if cmd = 'g_friendlyfire' then
4006 begin
4007 ParseGameFlag(GAME_OPTION_TEAMDAMAGE, I_MSG_FRIENDLY_FIRE_OFF, I_MSG_FRIENDLY_FIRE_ON);
4008 end
4009 else if cmd = 'g_friendly_absorb_damage' then
4010 begin
4011 ParseGameFlag(GAME_OPTION_TEAMABSORBDAMAGE, I_MSG_FRIENDLY_FIRE_OFF, I_MSG_FRIENDLY_FIRE_ON);
4012 end
4013 else if cmd = 'g_friendly_hit_trace' then
4014 begin
4015 ParseGameFlag(GAME_OPTION_TEAMHITTRACE, I_MSG_FRIENDLY_FIRE_OFF, I_MSG_FRIENDLY_FIRE_ON);
4016 end
4017 else if cmd = 'g_friendly_hit_projectile' then
4018 begin
4019 ParseGameFlag(GAME_OPTION_TEAMHITPROJECTILE, I_MSG_FRIENDLY_FIRE_OFF, I_MSG_FRIENDLY_FIRE_ON);
4020 end
4021 else if cmd = 'g_weaponstay' then
4022 begin
4023 ParseGameFlag(GAME_OPTION_WEAPONSTAY, I_MSG_WEAPONSTAY_OFF, I_MSG_WEAPONSTAY_ON);
4024 end
4025 else if cmd = 'g_allow_exit' then
4026 begin
4027 ParseGameFlag(GAME_OPTION_ALLOWEXIT, I_MSG_ALLOWEXIT_OFF, I_MSG_ALLOWEXIT_ON, True);
4028 end
4029 else if cmd = 'g_allow_monsters' then
4030 begin
4031 ParseGameFlag(GAME_OPTION_MONSTERS, I_MSG_ALLOWMON_OFF, I_MSG_ALLOWMON_ON, True);
4032 end
4033 else if cmd = 'g_bot_vsplayers' then
4034 begin
4035 ParseGameFlag(GAME_OPTION_BOTVSPLAYER, I_MSG_BOTSVSPLAYERS_OFF, I_MSG_BOTSVSPLAYERS_ON);
4036 end
4037 else if cmd = 'g_bot_vsmonsters' then
4038 begin
4039 ParseGameFlag(GAME_OPTION_BOTVSMONSTER, I_MSG_BOTSVSMONSTERS_OFF, I_MSG_BOTSVSMONSTERS_ON);
4040 end
4041 else if cmd = 'g_dm_keys' then
4042 begin
4043 ParseGameFlag(GAME_OPTION_DMKEYS, I_MSG_DMKEYS_OFF, I_MSG_DMKEYS_ON, True);
4044 end
4045 else if cmd = 'g_gameflags' then
4046 begin
4047 if Length(P) > 1 then
4048 begin
4049 gsGameFlags := StrToDWordDef(P[1], gsGameFlags);
4050 if g_Game_IsServer then
4051 begin
4052 gGameSettings.Options := gsGameFlags;
4053 if g_Game_IsNet then MH_SEND_GameSettings;
4054 end;
4055 end;
4057 g_Console_Add(Format('%s %u', [cmd, gsGameFlags]));
4058 end
4059 else if cmd = 'g_warmup_time' then
4060 begin
4061 if Length(P) > 1 then
4062 begin
4063 gsWarmupTime := nclamp(StrToIntDef(P[1], gsWarmupTime), 0, $FFFF);
4064 if g_Game_IsServer then
4065 begin
4066 gGameSettings.WarmupTime := gsWarmupTime;
4067 // extend warmup if it's already going
4068 if gLMSRespawn = LMS_RESPAWN_WARMUP then
4069 begin
4070 gLMSRespawnTime := gTime + gsWarmupTime * 1000;
4071 if g_Game_IsNet then MH_SEND_GameEvent(NET_EV_LMS_WARMUP, gLMSRespawnTime - gTime);
4072 end;
4073 if g_Game_IsNet then MH_SEND_GameSettings;
4074 end;
4075 end;
4077 g_Console_Add(Format(_lc[I_MSG_WARMUP], [Integer(gsWarmupTime)]));
4078 if g_Game_IsServer then g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
4079 end
4080 else if cmd = 'g_spawn_invul' then
4081 begin
4082 if Length(P) > 1 then
4083 begin
4084 gsSpawnInvul := nclamp(StrToIntDef(P[1], gsSpawnInvul), 0, $FFFF);
4085 if g_Game_IsServer then
4086 begin
4087 gGameSettings.SpawnInvul := gsSpawnInvul;
4088 if g_Game_IsNet then MH_SEND_GameSettings;
4089 end;
4090 end;
4092 g_Console_Add(Format('%s %d', [cmd, Integer(gsSpawnInvul)]));
4093 end
4094 else if cmd = 'g_item_respawn_time' then
4095 begin
4096 if Length(P) > 1 then
4097 begin
4098 gsItemRespawnTime := nclamp(StrToIntDef(P[1], gsItemRespawnTime), 0, $FFFF);
4099 if g_Game_IsServer then
4100 begin
4101 gGameSettings.ItemRespawnTime := gsItemRespawnTime;
4102 if g_Game_IsNet then MH_SEND_GameSettings;
4103 end;
4104 end;
4106 g_Console_Add(Format('%s %d', [cmd, Integer(gsItemRespawnTime)]));
4107 if g_Game_IsServer then g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
4108 end
4109 else if cmd = 'sv_intertime' then
4110 begin
4111 if (Length(P) > 1) then
4112 gDefInterTime := Min(Max(StrToIntDef(P[1], gDefInterTime), -1), 120);
4114 g_Console_Add(cmd + ' = ' + IntToStr(gDefInterTime));
4115 end
4116 else if cmd = 'g_max_particles' then
4117 begin
4118 if Length(p) = 2 then
4119 begin
4120 a := Max(0, StrToInt(p[1]));
4121 g_GFX_SetMax(a)
4122 end
4123 else if Length(p) = 1 then
4124 begin
4125 e_LogWritefln('%s', [g_GFX_GetMax()])
4126 end
4127 else
4128 begin
4129 e_LogWritefln('usage: %s <n>', [cmd])
4130 end
4131 end
4132 else if cmd = 'g_max_shells' then
4133 begin
4134 if Length(p) = 2 then
4135 begin
4136 a := Max(0, StrToInt(p[1]));
4137 g_Shells_SetMax(a)
4138 end
4139 else if Length(p) = 1 then
4140 begin
4141 e_LogWritefln('%s', [g_Shells_GetMax()])
4142 end
4143 else
4144 begin
4145 e_LogWritefln('usage: %s <n>', [cmd])
4146 end
4147 end
4148 else if cmd = 'g_max_gibs' then
4149 begin
4150 if Length(p) = 2 then
4151 begin
4152 a := Max(0, StrToInt(p[1]));
4153 g_Gibs_SetMax(a)
4154 end
4155 else if Length(p) = 1 then
4156 begin
4157 e_LogWritefln('%s', [g_Gibs_GetMax()])
4158 end
4159 else
4160 begin
4161 e_LogWritefln('usage: %s <n>', [cmd])
4162 end
4163 end
4164 else if cmd = 'g_max_corpses' then
4165 begin
4166 if Length(p) = 2 then
4167 begin
4168 a := Max(0, StrToInt(p[1]));
4169 g_Corpses_SetMax(a)
4170 end
4171 else if Length(p) = 1 then
4172 begin
4173 e_LogWritefln('%s', [g_Corpses_GetMax()])
4174 end
4175 else
4176 begin
4177 e_LogWritefln('usage: %s <n>', [cmd])
4178 end
4179 end
4180 else if cmd = 'g_scorelimit' then
4181 begin
4182 if Length(P) > 1 then
4183 begin
4184 gsGoalLimit := nclamp(StrToIntDef(P[1], gsGoalLimit), 0, $FFFF);
4186 if g_Game_IsServer then
4187 begin
4188 b := 0;
4189 if gGameSettings.GameMode = GM_DM then
4190 begin // DM
4191 stat := g_Player_GetStats();
4192 if stat <> nil then
4193 for a := 0 to High(stat) do
4194 if stat[a].Frags > b then
4195 b := stat[a].Frags;
4196 end
4197 else // TDM/CTF
4198 b := Max(gTeamStat[TEAM_RED].Goals, gTeamStat[TEAM_BLUE].Goals);
4200 // if someone has a higher score, set it to that instead
4201 gsGoalLimit := max(gsGoalLimit, b);
4202 gGameSettings.GoalLimit := gsGoalLimit;
4204 if g_Game_IsNet then MH_SEND_GameSettings;
4205 end;
4206 end;
4208 g_Console_Add(Format(_lc[I_MSG_SCORE_LIMIT], [Integer(gsGoalLimit)]));
4209 end
4210 else if cmd = 'g_timelimit' then
4211 begin
4212 if Length(P) > 1 then
4213 begin
4214 gsTimeLimit := nclamp(StrToIntDef(P[1], gsTimeLimit), 0, $FFFF);
4215 if g_Game_IsServer then
4216 begin
4217 gGameSettings.TimeLimit := gsTimeLimit;
4218 if g_Game_IsNet then MH_SEND_GameSettings;
4219 end;
4220 end;
4221 g_Console_Add(Format(_lc[I_MSG_TIME_LIMIT],
4222 [gsTimeLimit div 3600,
4223 (gsTimeLimit div 60) mod 60,
4224 gsTimeLimit mod 60]));
4225 end
4226 else if cmd = 'g_maxlives' then
4227 begin
4228 if Length(P) > 1 then
4229 begin
4230 gsMaxLives := nclamp(StrToIntDef(P[1], gsMaxLives), 0, $FFFF);
4231 if g_Game_IsServer then
4232 begin
4233 gGameSettings.MaxLives := gsMaxLives;
4234 if g_Game_IsNet then MH_SEND_GameSettings;
4235 end;
4236 end;
4238 g_Console_Add(Format(_lc[I_MSG_LIVES], [Integer(gsMaxLives)]));
4239 end;
4240 end;
4242 procedure PlayerSettingsCVars(P: SSArray);
4243 var
4244 cmd: string;
4245 team: Byte;
4247 function ParseTeam(s: string): Byte;
4248 begin
4249 result := 0;
4250 case s of
4251 'red', '1': result := TEAM_RED;
4252 'blue', '2': result := TEAM_BLUE;
4253 else result := TEAM_NONE;
4254 end;
4255 end;
4256 begin
4257 cmd := LowerCase(P[0]);
4258 case cmd of
4259 'p1_name':
4260 begin
4261 if (Length(P) > 1) then
4262 begin
4263 gPlayer1Settings.Name := b_Text_Unformat(P[1]);
4264 if g_Game_IsClient then
4265 MC_SEND_PlayerSettings
4266 else if gGameOn and (gPlayer1 <> nil) then
4267 begin
4268 gPlayer1.Name := b_Text_Unformat(P[1]);
4269 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer1.UID);
4270 end;
4271 end;
4272 end;
4273 'p2_name':
4274 begin
4275 if (Length(P) > 1) then
4276 begin
4277 gPlayer2Settings.Name := b_Text_Unformat(P[1]);
4278 if g_Game_IsClient then
4279 MC_SEND_PlayerSettings
4280 else if gGameOn and (gPlayer2 <> nil) then
4281 begin
4282 gPlayer2.Name := b_Text_Unformat(P[1]);
4283 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer2.UID);
4284 end;
4285 end;
4286 end;
4287 'p1_color':
4288 begin
4289 if Length(P) > 3 then
4290 begin
4291 gPlayer1Settings.Color := _RGB(EnsureRange(StrToIntDef(P[1], 0), 0, 255),
4292 EnsureRange(StrToIntDef(P[2], 0), 0, 255),
4293 EnsureRange(StrToIntDef(P[3], 0), 0, 255));
4294 if g_Game_IsClient then
4295 MC_SEND_PlayerSettings
4296 else if gGameOn and (gPlayer1 <> nil) then
4297 begin
4298 gPlayer1.SetColor(gPlayer1Settings.Color);
4299 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer1.UID);
4300 end;
4301 end;
4302 end;
4303 'p2_color':
4304 begin
4305 if Length(P) > 3 then
4306 begin
4307 gPlayer2Settings.Color := _RGB(EnsureRange(StrToIntDef(P[1], 0), 0, 255),
4308 EnsureRange(StrToIntDef(P[2], 0), 0, 255),
4309 EnsureRange(StrToIntDef(P[3], 0), 0, 255));
4310 if g_Game_IsClient then
4311 MC_SEND_PlayerSettings
4312 else if gGameOn and (gPlayer2 <> nil) then
4313 begin
4314 gPlayer2.SetColor(gPlayer2Settings.Color);
4315 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer2.UID);
4316 end;
4317 end;
4318 end;
4319 'p1_model':
4320 begin
4321 if (Length(P) > 1) then
4322 begin
4323 gPlayer1Settings.Model := P[1];
4324 if g_Game_IsClient then
4325 MC_SEND_PlayerSettings
4326 else if gGameOn and (gPlayer1 <> nil) then
4327 begin
4328 gPlayer1.FActualModelName := gPlayer1Settings.Model;
4329 gPlayer1.SetModel(gPlayer1Settings.Model);
4330 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer1.UID);
4331 end;
4332 end;
4333 end;
4334 'p2_model':
4335 begin
4336 if (Length(P) > 1) then
4337 begin
4338 gPlayer2Settings.Model := P[1];
4339 if g_Game_IsClient then
4340 MC_SEND_PlayerSettings
4341 else if gGameOn and (gPlayer2 <> nil) then
4342 begin
4343 gPlayer2.FActualModelName := gPlayer2Settings.Model;
4344 gPlayer2.SetModel(gPlayer2Settings.Model);
4345 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer2.UID);
4346 end;
4347 end;
4348 end;
4349 'p1_team':
4350 begin
4351 // TODO: switch teams if in game or store this separately
4352 if (Length(P) > 1) then
4353 begin
4354 team := ParseTeam(P[1]);
4355 if team = TEAM_NONE then
4356 g_Console_Add('expected ''red'', ''blue'', 1 or 2')
4357 else if not gGameOn and not g_Game_IsNet then
4358 gPlayer1Settings.Team := team
4359 else
4360 g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
4361 end;
4362 end;
4363 'p2_team':
4364 begin
4365 // TODO: switch teams if in game or store this separately
4366 if (Length(P) > 1) then
4367 begin
4368 team := ParseTeam(P[1]);
4369 if team = TEAM_NONE then
4370 g_Console_Add('expected ''red'', ''blue'', 1 or 2')
4371 else if not gGameOn and not g_Game_IsNet then
4372 gPlayer2Settings.Team := team
4373 else
4374 g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
4375 end;
4376 end;
4377 end;
4378 end;
4380 procedure PrintHeapStats();
4381 var
4382 hs: TFPCHeapStatus;
4383 begin
4384 hs := GetFPCHeapStatus();
4385 e_LogWriteLn ('v===== heap status =====v');
4386 e_LogWriteFln('max heap size = %d k', [hs.MaxHeapSize div 1024]);
4387 e_LogWriteFln('max heap used = %d k', [hs.MaxHeapUsed div 1024]);
4388 e_LogWriteFln('cur heap size = %d k', [hs.CurrHeapSize div 1024]);
4389 e_LogWriteFln('cur heap used = %d k', [hs.CurrHeapUsed div 1024]);
4390 e_LogWriteFln('cur heap free = %d k', [hs.CurrHeapFree div 1024]);
4391 e_LogWriteLn ('^=======================^');
4392 end;
4394 procedure DebugCommands(P: SSArray);
4395 var
4396 a, b: Integer;
4397 cmd: string;
4398 //pt: TDFPoint;
4399 mon: TMonster;
4400 begin
4401 // Команды отладочного режима:
4402 if {gDebugMode}conIsCheatsEnabled then
4403 begin
4404 cmd := LowerCase(P[0]);
4405 if cmd = 'd_window' then
4406 begin
4407 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth, gScreenHeight]));
4408 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth, gScreenHeight]));
4409 end
4410 else if cmd = 'd_sounds' then
4411 begin
4412 if (Length(P) > 1) and
4413 ((P[1] = '1') or (P[1] = '0')) then
4414 g_Debug_Sounds := (P[1][1] = '1');
4416 g_Console_Add(Format('d_sounds is %d', [Byte(g_Debug_Sounds)]));
4417 end
4418 else if cmd = 'd_frames' then
4419 begin
4420 if (Length(P) > 1) and
4421 ((P[1] = '1') or (P[1] = '0')) then
4422 g_Debug_Frames := (P[1][1] = '1');
4424 g_Console_Add(Format('d_frames is %d', [Byte(g_Debug_Frames)]));
4425 end
4426 else if cmd = 'd_winmsg' then
4427 begin
4428 if (Length(P) > 1) and
4429 ((P[1] = '1') or (P[1] = '0')) then
4430 g_Debug_WinMsgs := (P[1][1] = '1');
4432 g_Console_Add(Format('d_winmsg is %d', [Byte(g_Debug_WinMsgs)]));
4433 end
4434 else if (cmd = 'd_monoff') and not g_Game_IsNet then
4435 begin
4436 if (Length(P) > 1) and
4437 ((P[1] = '1') or (P[1] = '0')) then
4438 g_Debug_MonsterOff := (P[1][1] = '1');
4440 g_Console_Add(Format('d_monoff is %d', [Byte(g_debug_MonsterOff)]));
4441 end
4442 else if (cmd = 'd_botoff') and not g_Game_IsNet then
4443 begin
4444 if Length(P) > 1 then
4445 case P[1][1] of
4446 '0': g_debug_BotAIOff := 0;
4447 '1': g_debug_BotAIOff := 1;
4448 '2': g_debug_BotAIOff := 2;
4449 '3': g_debug_BotAIOff := 3;
4450 end;
4452 g_Console_Add(Format('d_botoff is %d', [g_debug_BotAIOff]));
4453 end
4454 else if cmd = 'd_monster' then
4455 begin
4456 if gGameOn and (gPlayer1 <> nil) and (gPlayer1.alive) and (not g_Game_IsNet) then
4457 if Length(P) < 2 then
4458 begin
4459 g_Console_Add(cmd + ' [ID | Name] [behaviour]');
4460 g_Console_Add('ID | Name');
4461 for b := MONSTER_DEMON to MONSTER_MAN do
4462 g_Console_Add(Format('%2d | %s', [b, g_Mons_NameByTypeId(b)]));
4463 conwriteln('behav. num'#10'normal 0'#10'killer 1'#10'maniac 2'#10'insane 3'#10'cannibal 4'#10'good 5');
4464 end else
4465 begin
4466 a := StrToIntDef(P[1], 0);
4467 if (a < MONSTER_DEMON) or (a > MONSTER_MAN) then
4468 a := g_Mons_TypeIdByName(P[1]);
4470 if (a < MONSTER_DEMON) or (a > MONSTER_MAN) then
4471 g_Console_Add(Format(_lc[I_MSG_NO_MONSTER], [P[1]]))
4472 else
4473 begin
4474 with gPlayer1.Obj do
4475 begin
4476 mon := g_Monsters_Create(a,
4477 X + Rect.X + (Rect.Width div 2),
4478 Y + Rect.Y + Rect.Height,
4479 gPlayer1.Direction, True);
4480 end;
4481 if (Length(P) > 2) and (mon <> nil) then
4482 begin
4483 if (CompareText(P[2], 'normal') = 0) then mon.MonsterBehaviour := BH_NORMAL
4484 else if (CompareText(P[2], 'killer') = 0) then mon.MonsterBehaviour := BH_KILLER
4485 else if (CompareText(P[2], 'maniac') = 0) then mon.MonsterBehaviour := BH_MANIAC
4486 else if (CompareText(P[2], 'insane') = 0) then mon.MonsterBehaviour := BH_INSANE
4487 else if (CompareText(P[2], 'cannibal') = 0) then mon.MonsterBehaviour := BH_CANNIBAL
4488 else if (CompareText(P[2], 'good') = 0) then mon.MonsterBehaviour := BH_GOOD
4489 else if (CompareText(P[2], 'friend') = 0) then mon.MonsterBehaviour := BH_GOOD
4490 else if (CompareText(P[2], 'friendly') = 0) then mon.MonsterBehaviour := BH_GOOD
4491 else mon.MonsterBehaviour := Min(Max(StrToIntDef(P[2], BH_NORMAL), BH_NORMAL), BH_GOOD);
4492 end;
4493 end;
4494 end;
4495 end
4496 else if (cmd = 'd_health') then
4497 begin
4498 if (Length(P) > 1) and
4499 ((P[1] = '1') or (P[1] = '0')) then
4500 g_debug_HealthBar := (P[1][1] = '1');
4502 g_Console_Add(Format('d_health is %d', [Byte(g_debug_HealthBar)]));
4503 end
4504 else if (cmd = 'd_player') then
4505 begin
4506 if (Length(P) > 1) and
4507 ((P[1] = '1') or (P[1] = '0')) then
4508 g_debug_Player := (P[1][1] = '1');
4510 g_Console_Add(Format(cmd + ' is %d', [Byte(g_Debug_Player)]));
4511 end
4512 else if (cmd = 'd_mem') then
4513 begin
4514 PrintHeapStats();
4515 end;
4516 end
4517 else
4518 g_Console_Add(_lc[I_MSG_NOT_DEBUG]);
4519 end;
4522 procedure GameCheats(P: SSArray);
4523 var
4524 cmd: string;
4525 f, a: Integer;
4526 plr: TPlayer;
4527 begin
4528 if (not gGameOn) or (not conIsCheatsEnabled) then
4529 begin
4530 g_Console_Add('not available');
4531 exit;
4532 end;
4533 plr := gPlayer1;
4534 if plr = nil then
4535 begin
4536 g_Console_Add('where is the player?!');
4537 exit;
4538 end;
4539 cmd := LowerCase(P[0]);
4540 // god
4541 if cmd = 'god' then
4542 begin
4543 plr.GodMode := not plr.GodMode;
4544 if plr.GodMode then g_Console_Add('player is godlike now') else g_Console_Add('player is mortal now');
4545 exit;
4546 end;
4547 // give <health|exit|weapons|air|suit|jetpack|berserk|all>
4548 if cmd = 'give' then
4549 begin
4550 if length(P) < 2 then begin g_Console_Add('give what?!'); exit; end;
4551 for f := 1 to High(P) do
4552 begin
4553 cmd := LowerCase(P[f]);
4554 if cmd = 'health' then begin plr.RestoreHealthArmor(); g_Console_Add('player feels himself better'); continue; end;
4555 if (cmd = 'all') {or (cmd = 'weapons')} then begin plr.AllRulez(False); g_Console_Add('player got the gifts'); continue; end;
4556 if cmd = 'exit' then
4557 begin
4558 if gTriggers <> nil then
4559 begin
4560 for a := 0 to High(gTriggers) do
4561 begin
4562 if gTriggers[a].TriggerType = TRIGGER_EXIT then
4563 begin
4564 g_Console_Add('player left the map');
4565 gExitByTrigger := True;
4566 //g_Game_ExitLevel(gTriggers[a].Data.MapName);
4567 g_Game_ExitLevel(gTriggers[a].tgcMap);
4568 break;
4569 end;
4570 end;
4571 end;
4572 continue;
4573 end;
4575 if cmd = 'air' then begin plr.GiveItem(ITEM_OXYGEN); g_Console_Add('player got some air'); continue; end;
4576 if cmd = 'jetpack' then begin plr.GiveItem(ITEM_JETPACK); g_Console_Add('player got a jetpack'); continue; end;
4577 if cmd = 'suit' then begin plr.GiveItem(ITEM_SUIT); g_Console_Add('player got an envirosuit'); continue; end;
4578 if cmd = 'berserk' then begin plr.GiveItem(ITEM_MEDKIT_BLACK); g_Console_Add('player got a berserk pack'); continue; end;
4579 if cmd = 'backpack' then begin plr.GiveItem(ITEM_AMMO_BACKPACK); g_Console_Add('player got a backpack'); continue; end;
4581 if cmd = 'helmet' then begin plr.GiveItem(ITEM_HELMET); g_Console_Add('player got a helmet'); continue; end;
4582 if cmd = 'bottle' then begin plr.GiveItem(ITEM_BOTTLE); g_Console_Add('player got a bottle of health'); continue; end;
4584 if cmd = 'stimpack' then begin plr.GiveItem(ITEM_MEDKIT_SMALL); g_Console_Add('player got a stimpack'); continue; end;
4585 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;
4587 if cmd = 'greenarmor' then begin plr.GiveItem(ITEM_ARMOR_GREEN); g_Console_Add('player got a security armor'); continue; end;
4588 if cmd = 'bluearmor' then begin plr.GiveItem(ITEM_ARMOR_BLUE); g_Console_Add('player got a combat armor'); continue; end;
4590 if (cmd = 'megasphere') or (cmd = 'mega') then begin plr.GiveItem(ITEM_SPHERE_BLUE); g_Console_Add('player got a megasphere'); continue; end;
4591 if (cmd = 'soulsphere') or (cmd = 'soul')then begin plr.GiveItem(ITEM_SPHERE_WHITE); g_Console_Add('player got a soul sphere'); continue; end;
4593 if (cmd = 'invul') or (cmd = 'invulnerability') then begin plr.GiveItem(ITEM_INVUL); g_Console_Add('player got invulnerability'); continue; end;
4594 if (cmd = 'invis') or (cmd = 'invisibility') then begin plr.GiveItem(ITEM_INVIS); g_Console_Add('player got invisibility'); continue; end;
4596 if cmd = 'redkey' then begin plr.GiveItem(ITEM_KEY_RED); g_Console_Add('player got the red key'); continue; end;
4597 if cmd = 'greenkey' then begin plr.GiveItem(ITEM_KEY_GREEN); g_Console_Add('player got the green key'); continue; end;
4598 if cmd = 'bluekey' then begin plr.GiveItem(ITEM_KEY_BLUE); g_Console_Add('player got the blue key'); continue; end;
4600 if (cmd = 'shotgun') or (cmd = 'sg') then begin plr.GiveItem(ITEM_WEAPON_SHOTGUN1); g_Console_Add('player got a shotgun'); continue; end;
4601 if (cmd = 'supershotgun') or (cmd = 'ssg') then begin plr.GiveItem(ITEM_WEAPON_SHOTGUN2); g_Console_Add('player got a supershotgun'); continue; end;
4602 if cmd = 'chaingun' then begin plr.GiveItem(ITEM_WEAPON_CHAINGUN); g_Console_Add('player got a chaingun'); continue; end;
4603 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;
4604 if cmd = 'plasmagun' then begin plr.GiveItem(ITEM_WEAPON_PLASMA); g_Console_Add('player got a plasma gun'); continue; end;
4605 if cmd = 'bfg' then begin plr.GiveItem(ITEM_WEAPON_BFG); g_Console_Add('player got a BFG-9000'); continue; end;
4607 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;
4608 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;
4609 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;
4610 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;
4611 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;
4612 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;
4614 if cmd = 'superchaingun' then begin plr.GiveItem(ITEM_WEAPON_SUPERPULEMET); g_Console_Add('player got a superchaingun'); continue; end;
4615 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;
4617 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;
4618 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;
4620 if cmd = 'chainsaw' then begin plr.GiveItem(ITEM_WEAPON_SAW); g_Console_Add('player got a chainsaw'); continue; end;
4622 if cmd = 'ammo' then
4623 begin
4624 plr.GiveItem(ITEM_AMMO_SHELLS_BOX);
4625 plr.GiveItem(ITEM_AMMO_BULLETS_BOX);
4626 plr.GiveItem(ITEM_AMMO_CELL_BIG);
4627 plr.GiveItem(ITEM_AMMO_ROCKET_BOX);
4628 plr.GiveItem(ITEM_AMMO_FUELCAN);
4629 g_Console_Add('player got some ammo');
4630 continue;
4631 end;
4633 if cmd = 'clip' then begin plr.GiveItem(ITEM_AMMO_BULLETS); g_Console_Add('player got some bullets'); continue; end;
4634 if cmd = 'bullets' then begin plr.GiveItem(ITEM_AMMO_BULLETS_BOX); g_Console_Add('player got a box of bullets'); continue; end;
4636 if cmd = 'shells' then begin plr.GiveItem(ITEM_AMMO_SHELLS); g_Console_Add('player got some shells'); continue; end;
4637 if cmd = 'shellbox' then begin plr.GiveItem(ITEM_AMMO_SHELLS_BOX); g_Console_Add('player got a box of shells'); continue; end;
4639 if cmd = 'cells' then begin plr.GiveItem(ITEM_AMMO_CELL); g_Console_Add('player got some cells'); continue; end;
4640 if cmd = 'battery' then begin plr.GiveItem(ITEM_AMMO_CELL_BIG); g_Console_Add('player got cell battery'); continue; end;
4642 if cmd = 'rocket' then begin plr.GiveItem(ITEM_AMMO_ROCKET); g_Console_Add('player got a rocket'); continue; end;
4643 if cmd = 'rocketbox' then begin plr.GiveItem(ITEM_AMMO_ROCKET_BOX); g_Console_Add('player got some rockets'); continue; end;
4645 if (cmd = 'fuel') or (cmd = 'fuelcan') then begin plr.GiveItem(ITEM_AMMO_FUELCAN); g_Console_Add('player got fuel canister'); continue; end;
4647 if cmd = 'weapons' then
4648 begin
4649 plr.GiveItem(ITEM_WEAPON_SHOTGUN1);
4650 plr.GiveItem(ITEM_WEAPON_SHOTGUN2);
4651 plr.GiveItem(ITEM_WEAPON_CHAINGUN);
4652 plr.GiveItem(ITEM_WEAPON_ROCKETLAUNCHER);
4653 plr.GiveItem(ITEM_WEAPON_PLASMA);
4654 plr.GiveItem(ITEM_WEAPON_BFG);
4655 g_Console_Add('player got weapons');
4656 continue;
4657 end;
4659 if cmd = 'keys' then
4660 begin
4661 plr.GiveItem(ITEM_KEY_RED);
4662 plr.GiveItem(ITEM_KEY_GREEN);
4663 plr.GiveItem(ITEM_KEY_BLUE);
4664 g_Console_Add('player got all keys');
4665 continue;
4666 end;
4668 g_Console_Add('i don''t know how to give '''+cmd+'''!');
4669 end;
4670 exit;
4671 end;
4672 // open
4673 if cmd = 'open' then
4674 begin
4675 g_Console_Add('player activated sesame');
4676 g_Triggers_OpenAll();
4677 exit;
4678 end;
4679 // fly
4680 if cmd = 'fly' then
4681 begin
4682 gFly := not gFly;
4683 if gFly then g_Console_Add('player feels himself lighter') else g_Console_Add('player lost his wings');
4684 exit;
4685 end;
4686 // noclip
4687 if cmd = 'noclip' then
4688 begin
4689 plr.SwitchNoClip;
4690 g_Console_Add('wall hardeness adjusted');
4691 exit;
4692 end;
4693 // notarget
4694 if cmd = 'notarget' then
4695 begin
4696 plr.NoTarget := not plr.NoTarget;
4697 if plr.NoTarget then g_Console_Add('player hides in shadows') else g_Console_Add('player is brave again');
4698 exit;
4699 end;
4700 // noreload
4701 if cmd = 'noreload' then
4702 begin
4703 plr.NoReload := not plr.NoReload;
4704 if plr.NoReload then g_Console_Add('player is action hero now') else g_Console_Add('player is ordinary man now');
4705 exit;
4706 end;
4707 // speedy
4708 if cmd = 'speedy' then
4709 begin
4710 MAX_RUNVEL := 32-MAX_RUNVEL;
4711 g_Console_Add('speed adjusted');
4712 exit;
4713 end;
4714 // jumpy
4715 if cmd = 'jumpy' then
4716 begin
4717 VEL_JUMP := 30-VEL_JUMP;
4718 g_Console_Add('jump height adjusted');
4719 exit;
4720 end;
4721 // automap
4722 if cmd = 'automap' then
4723 begin
4724 gShowMap := not gShowMap;
4725 if gShowMap then g_Console_Add('player gains second sight') else g_Console_Add('player lost second sight');
4726 exit;
4727 end;
4728 // aimline
4729 if cmd = 'aimline' then
4730 begin
4731 gAimLine := not gAimLine;
4732 if gAimLine then g_Console_Add('player gains laser sight') else g_Console_Add('player lost laser sight');
4733 exit;
4734 end;
4735 end;
4737 procedure GameCommands(P: SSArray);
4738 var
4739 a, b: Integer;
4740 s, pw: String;
4741 chstr: string;
4742 cmd: string;
4743 pl: pTNetClient = nil;
4744 plr: TPlayer;
4745 prt: Word;
4746 nm: Boolean;
4747 listen: LongWord;
4748 found: Boolean;
4749 begin
4750 // Общие команды:
4751 cmd := LowerCase(P[0]);
4752 chstr := '';
4753 if cmd = 'pause' then
4754 begin
4755 if (g_ActiveWindow = nil) then
4756 g_Game_Pause(not gPauseMain);
4757 end
4758 else if cmd = 'endgame' then
4759 gExit := EXIT_SIMPLE
4760 else if cmd = 'restart' then
4761 begin
4762 if gGameOn or (gState in [STATE_INTERSINGLE, STATE_INTERCUSTOM]) then
4763 begin
4764 if g_Game_IsClient then
4765 begin
4766 g_Console_Add(_lc[I_MSG_SERVERONLY]);
4767 Exit;
4768 end;
4769 g_Game_Restart();
4770 end else
4771 g_Console_Add(_lc[I_MSG_NOT_GAME]);
4772 end
4773 else if cmd = 'kick' then
4774 begin
4775 if g_Game_IsServer then
4776 begin
4777 if Length(P) < 2 then
4778 begin
4779 g_Console_Add('kick <name>');
4780 Exit;
4781 end;
4782 if P[1] = '' then
4783 begin
4784 g_Console_Add('kick <name>');
4785 Exit;
4786 end;
4788 if g_Game_IsNet then
4789 pl := g_Net_Client_ByName(P[1]);
4790 if (pl <> nil) then
4791 begin
4792 s := g_Net_ClientName_ByID(pl^.ID);
4793 enet_peer_disconnect(pl^.Peer, NET_DISC_KICK);
4794 g_Console_Add(Format(_lc[I_PLAYER_KICK], [s]));
4795 MH_SEND_GameEvent(NET_EV_PLAYER_KICK, 0, s);
4796 g_Net_Slist_ServerPlayerLeaves();
4797 end else if gPlayers <> nil then
4798 for a := Low(gPlayers) to High(gPlayers) do
4799 if gPlayers[a] <> nil then
4800 if Copy(LowerCase(gPlayers[a].Name), 1, Length(P[1])) = LowerCase(P[1]) then
4801 begin
4802 // Не отключать основных игроков в сингле
4803 if not(gPlayers[a] is TBot) and (gGameSettings.GameType = GT_SINGLE) then
4804 continue;
4805 gPlayers[a].Lives := 0;
4806 gPlayers[a].Kill(K_SIMPLEKILL, 0, HIT_DISCON);
4807 g_Console_Add(Format(_lc[I_PLAYER_LEAVE], [gPlayers[a].Name]), True);
4808 g_Player_Remove(gPlayers[a].UID);
4809 g_Net_Slist_ServerPlayerLeaves();
4810 // Если не перемешать, при добавлении новых ботов появятся старые
4811 g_Bot_MixNames();
4812 end;
4813 end else
4814 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
4815 end
4816 else if cmd = 'kick_id' then
4817 begin
4818 if g_Game_IsServer and g_Game_IsNet then
4819 begin
4820 if Length(P) < 2 then
4821 begin
4822 g_Console_Add('kick_id <client ID>');
4823 Exit;
4824 end;
4825 if P[1] = '' then
4826 begin
4827 g_Console_Add('kick_id <client ID>');
4828 Exit;
4829 end;
4831 a := StrToIntDef(P[1], 0);
4832 if (NetClients <> nil) and (a <= High(NetClients)) then
4833 begin
4834 if NetClients[a].Used and (NetClients[a].Peer <> nil) then
4835 begin
4836 s := g_Net_ClientName_ByID(NetClients[a].ID);
4837 enet_peer_disconnect(NetClients[a].Peer, NET_DISC_KICK);
4838 g_Console_Add(Format(_lc[I_PLAYER_KICK], [s]));
4839 MH_SEND_GameEvent(NET_EV_PLAYER_KICK, 0, s);
4840 g_Net_Slist_ServerPlayerLeaves();
4841 end;
4842 end;
4843 end else
4844 g_Console_Add(_lc[I_MSG_SERVERONLY]);
4845 end
4846 else if cmd = 'kick_pid' then
4847 begin
4848 if g_Game_IsServer and g_Game_IsNet then
4849 begin
4850 if Length(P) < 2 then
4851 begin
4852 g_Console_Add('kick_pid <player ID>');
4853 Exit;
4854 end;
4855 if P[1] = '' then
4856 begin
4857 g_Console_Add('kick_pid <player ID>');
4858 Exit;
4859 end;
4861 a := StrToIntDef(P[1], 0);
4862 pl := g_Net_Client_ByPlayer(a);
4863 if (pl <> nil) and pl^.Used and (pl^.Peer <> nil) then
4864 begin
4865 s := g_Net_ClientName_ByID(pl^.ID);
4866 enet_peer_disconnect(pl^.Peer, NET_DISC_KICK);
4867 g_Console_Add(Format(_lc[I_PLAYER_KICK], [s]));
4868 MH_SEND_GameEvent(NET_EV_PLAYER_KICK, 0, s);
4869 g_Net_Slist_ServerPlayerLeaves();
4870 end;
4871 end else
4872 g_Console_Add(_lc[I_MSG_SERVERONLY]);
4873 end
4874 else if cmd = 'ban' then
4875 begin
4876 if g_Game_IsServer and g_Game_IsNet then
4877 begin
4878 if Length(P) < 2 then
4879 begin
4880 g_Console_Add('ban <name>');
4881 Exit;
4882 end;
4883 if P[1] = '' then
4884 begin
4885 g_Console_Add('ban <name>');
4886 Exit;
4887 end;
4889 pl := g_Net_Client_ByName(P[1]);
4890 if (pl <> nil) then
4891 begin
4892 s := g_Net_ClientName_ByID(pl^.ID);
4893 g_Net_BanHost(pl^.Peer^.address.host, False);
4894 enet_peer_disconnect(pl^.Peer, NET_DISC_TEMPBAN);
4895 g_Console_Add(Format(_lc[I_PLAYER_BAN], [s]));
4896 MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s);
4897 g_Net_Slist_ServerPlayerLeaves();
4898 end else
4899 g_Console_Add(Format(_lc[I_NET_ERR_NAME404], [P[1]]));
4900 end else
4901 g_Console_Add(_lc[I_MSG_SERVERONLY]);
4902 end
4903 else if cmd = 'ban_id' then
4904 begin
4905 if g_Game_IsServer and g_Game_IsNet then
4906 begin
4907 if Length(P) < 2 then
4908 begin
4909 g_Console_Add('ban_id <client ID>');
4910 Exit;
4911 end;
4912 if P[1] = '' then
4913 begin
4914 g_Console_Add('ban_id <client ID>');
4915 Exit;
4916 end;
4918 a := StrToIntDef(P[1], 0);
4919 if (NetClients <> nil) and (a <= High(NetClients)) then
4920 if NetClients[a].Used and (NetClients[a].Peer <> nil) then
4921 begin
4922 s := g_Net_ClientName_ByID(NetClients[a].ID);
4923 g_Net_BanHost(NetClients[a].Peer^.address.host, False);
4924 enet_peer_disconnect(NetClients[a].Peer, NET_DISC_TEMPBAN);
4925 g_Console_Add(Format(_lc[I_PLAYER_BAN], [s]));
4926 MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s);
4927 g_Net_Slist_ServerPlayerLeaves();
4928 end;
4929 end else
4930 g_Console_Add(_lc[I_MSG_SERVERONLY]);
4931 end
4932 else if cmd = 'ban_pid' then
4933 begin
4934 if g_Game_IsServer and g_Game_IsNet then
4935 begin
4936 if Length(P) < 2 then
4937 begin
4938 g_Console_Add('ban_pid <player ID>');
4939 Exit;
4940 end;
4941 if P[1] = '' then
4942 begin
4943 g_Console_Add('ban_pid <player ID>');
4944 Exit;
4945 end;
4947 a := StrToIntDef(P[1], 0);
4948 pl := g_Net_Client_ByPlayer(a);
4949 if (pl <> nil) and pl^.Used and (pl^.Peer <> nil) then
4950 begin
4951 s := g_Net_ClientName_ByID(pl^.ID);
4952 g_Net_BanHost(pl^.Peer^.address.host, False);
4953 enet_peer_disconnect(pl^.Peer, NET_DISC_TEMPBAN);
4954 g_Console_Add(Format(_lc[I_PLAYER_BAN], [s]));
4955 MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s);
4956 g_Net_Slist_ServerPlayerLeaves();
4957 end;
4958 end else
4959 g_Console_Add(_lc[I_MSG_SERVERONLY]);
4960 end
4961 else if cmd = 'permban' then
4962 begin
4963 if g_Game_IsServer and g_Game_IsNet then
4964 begin
4965 if Length(P) < 2 then
4966 begin
4967 g_Console_Add('permban <name>');
4968 Exit;
4969 end;
4970 if P[1] = '' then
4971 begin
4972 g_Console_Add('permban <name>');
4973 Exit;
4974 end;
4976 pl := g_Net_Client_ByName(P[1]);
4977 if (pl <> nil) then
4978 begin
4979 s := g_Net_ClientName_ByID(pl^.ID);
4980 g_Net_BanHost(pl^.Peer^.address.host);
4981 enet_peer_disconnect(pl^.Peer, NET_DISC_BAN);
4982 g_Net_SaveBanList();
4983 g_Console_Add(Format(_lc[I_PLAYER_BAN], [s]));
4984 MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s);
4985 g_Net_Slist_ServerPlayerLeaves();
4986 end else
4987 g_Console_Add(Format(_lc[I_NET_ERR_NAME404], [P[1]]));
4988 end else
4989 g_Console_Add(_lc[I_MSG_SERVERONLY]);
4990 end
4991 else if cmd = 'permban_id' then
4992 begin
4993 if g_Game_IsServer and g_Game_IsNet then
4994 begin
4995 if Length(P) < 2 then
4996 begin
4997 g_Console_Add('permban_id <client ID>');
4998 Exit;
4999 end;
5000 if P[1] = '' then
5001 begin
5002 g_Console_Add('permban_id <client ID>');
5003 Exit;
5004 end;
5006 a := StrToIntDef(P[1], 0);
5007 if (NetClients <> nil) and (a <= High(NetClients)) then
5008 if NetClients[a].Used and (NetClients[a].Peer <> nil) then
5009 begin
5010 s := g_Net_ClientName_ByID(NetClients[a].ID);
5011 g_Net_BanHost(NetClients[a].Peer^.address.host);
5012 enet_peer_disconnect(NetClients[a].Peer, NET_DISC_BAN);
5013 g_Net_SaveBanList();
5014 g_Console_Add(Format(_lc[I_PLAYER_BAN], [s]));
5015 MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s);
5016 g_Net_Slist_ServerPlayerLeaves();
5017 end;
5018 end else
5019 g_Console_Add(_lc[I_MSG_SERVERONLY]);
5020 end
5021 else if cmd = 'permban_pid' then
5022 begin
5023 if g_Game_IsServer and g_Game_IsNet then
5024 begin
5025 if Length(P) < 2 then
5026 begin
5027 g_Console_Add('permban_pid <player ID>');
5028 Exit;
5029 end;
5030 if P[1] = '' then
5031 begin
5032 g_Console_Add('permban_pid <player ID>');
5033 Exit;
5034 end;
5036 a := StrToIntDef(P[1], 0);
5037 pl := g_Net_Client_ByPlayer(a);
5038 if (pl <> nil) and pl^.Used and (pl^.Peer <> nil) then
5039 begin
5040 s := g_Net_ClientName_ByID(pl^.ID);
5041 g_Net_BanHost(pl^.Peer^.address.host);
5042 enet_peer_disconnect(pl^.Peer, NET_DISC_BAN);
5043 g_Net_SaveBanList();
5044 g_Console_Add(Format(_lc[I_PLAYER_BAN], [s]));
5045 MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s);
5046 g_Net_Slist_ServerPlayerLeaves();
5047 end;
5048 end else
5049 g_Console_Add(_lc[I_MSG_SERVERONLY]);
5050 end
5051 else if cmd = 'permban_ip' then
5052 begin
5053 if g_Game_IsServer and g_Game_IsNet then
5054 begin
5055 if Length(P) < 2 then
5056 begin
5057 g_Console_Add('permban_ip <IP address>');
5058 Exit;
5059 end;
5060 if P[1] = '' then
5061 begin
5062 g_Console_Add('permban_ip <IP address>');
5063 Exit;
5064 end;
5066 g_Net_BanHost(P[1]);
5067 g_Net_SaveBanList();
5068 g_Console_Add(Format(_lc[I_PLAYER_BAN], [P[1]]));
5069 end else
5070 g_Console_Add(_lc[I_MSG_SERVERONLY]);
5071 end
5072 else if cmd = 'unban' then
5073 begin
5074 if g_Game_IsServer and g_Game_IsNet then
5075 begin
5076 if Length(P) < 2 then
5077 begin
5078 g_Console_Add('unban <IP Address>');
5079 Exit;
5080 end;
5081 if P[1] = '' then
5082 begin
5083 g_Console_Add('unban <IP Address>');
5084 Exit;
5085 end;
5087 if g_Net_UnbanHost(P[1]) then
5088 begin
5089 g_Console_Add(Format(_lc[I_MSG_UNBAN_OK], [P[1]]));
5090 g_Net_SaveBanList();
5091 end else
5092 g_Console_Add(Format(_lc[I_MSG_UNBAN_FAIL], [P[1]]));
5093 end else
5094 g_Console_Add(_lc[I_MSG_SERVERONLY]);
5095 end
5096 else if cmd = 'clientlist' then
5097 begin
5098 if g_Game_IsServer and g_Game_IsNet then
5099 begin
5100 b := 0;
5101 if NetClients <> nil then
5102 for a := Low(NetClients) to High(NetClients) do
5103 if NetClients[a].Used and (NetClients[a].Peer <> nil) then
5104 begin
5105 plr := g_Player_Get(NetClients[a].Player);
5106 if plr = nil then continue;
5107 Inc(b);
5108 g_Console_Add(Format('#%2d: %-15s | %s', [a,
5109 IpToStr(NetClients[a].Peer^.address.host), plr.Name]));
5110 end;
5111 if b = 0 then
5112 g_Console_Add(_lc[I_MSG_NOCLIENTS]);
5113 end else
5114 g_Console_Add(_lc[I_MSG_SERVERONLY]);
5115 end
5116 else if cmd = 'connect' then
5117 begin
5118 if (NetMode = NET_NONE) then
5119 begin
5120 if Length(P) < 2 then
5121 begin
5122 g_Console_Add('connect <IP> [port] [password]');
5123 Exit;
5124 end;
5125 if P[1] = '' then
5126 begin
5127 g_Console_Add('connect <IP> [port] [password]');
5128 Exit;
5129 end;
5131 if Length(P) > 2 then
5132 prt := StrToIntDef(P[2], 25666)
5133 else
5134 prt := 25666;
5136 if Length(P) > 3 then
5137 pw := P[3]
5138 else
5139 pw := '';
5141 g_Game_StartClient(P[1], prt, pw);
5142 end;
5143 end
5144 else if cmd = 'disconnect' then
5145 begin
5146 if (NetMode = NET_CLIENT) then
5147 g_Net_Disconnect();
5148 end
5149 else if cmd = 'reconnect' then
5150 begin
5151 if (NetMode = NET_SERVER) then
5152 Exit;
5154 if (NetMode = NET_CLIENT) then
5155 begin
5156 g_Net_Disconnect();
5157 gExit := EXIT_SIMPLE;
5158 EndGame;
5159 end;
5161 //TODO: Use last successful password to reconnect, instead of ''
5162 g_Game_StartClient(NetClientIP, NetClientPort, '');
5163 end
5164 else if (cmd = 'addbot') or
5165 (cmd = 'bot_add') then
5166 begin
5167 if Length(P) > 2 then
5168 g_Bot_Add(TEAM_NONE, StrToIntDef(P[1], 2), StrToIntDef(P[2], 100))
5169 else if Length(P) > 1 then
5170 g_Bot_Add(TEAM_NONE, StrToIntDef(P[1], 2))
5171 else
5172 g_Bot_Add(TEAM_NONE, 2);
5173 end
5174 else if cmd = 'bot_addlist' then
5175 begin
5176 if Length(P) > 1 then
5177 begin
5178 if Length(P) = 2 then
5179 g_Bot_AddList(TEAM_NONE, P[1], StrToIntDef(P[1], -1))
5180 else if Length(P) = 3 then
5181 g_Bot_AddList(TEAM_NONE, P[1], StrToIntDef(P[1], -1), StrToIntDef(P[2], 100))
5182 else
5183 g_Bot_AddList(IfThen(P[2] = 'red', TEAM_RED, TEAM_BLUE), P[1], StrToIntDef(P[1], -1));
5184 end;
5185 end
5186 else if cmd = 'bot_removeall' then
5187 g_Bot_RemoveAll()
5188 else if cmd = 'chat' then
5189 begin
5190 if g_Game_IsNet then
5191 begin
5192 if Length(P) > 1 then
5193 begin
5194 for a := 1 to High(P) do
5195 chstr := chstr + P[a] + ' ';
5197 if Length(chstr) > 200 then SetLength(chstr, 200);
5199 if Length(chstr) < 1 then
5200 begin
5201 g_Console_Add('chat <text>');
5202 Exit;
5203 end;
5205 chstr := b_Text_Format(chstr);
5206 if g_Game_IsClient then
5207 MC_SEND_Chat(chstr, NET_CHAT_PLAYER)
5208 else
5209 MH_SEND_Chat(gPlayer1Settings.Name + ': ' + chstr, NET_CHAT_PLAYER);
5210 end
5211 else
5212 g_Console_Add('chat <text>');
5213 end else
5214 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
5215 end
5216 else if cmd = 'teamchat' then
5217 begin
5218 if g_Game_IsNet and (gGameSettings.GameMode in [GM_TDM, GM_CTF]) then
5219 begin
5220 if Length(P) > 1 then
5221 begin
5222 for a := 1 to High(P) do
5223 chstr := chstr + P[a] + ' ';
5225 if Length(chstr) > 200 then SetLength(chstr, 200);
5227 if Length(chstr) < 1 then
5228 begin
5229 g_Console_Add('teamchat <text>');
5230 Exit;
5231 end;
5233 chstr := b_Text_Format(chstr);
5234 if g_Game_IsClient then
5235 MC_SEND_Chat(chstr, NET_CHAT_TEAM)
5236 else
5237 MH_SEND_Chat(gPlayer1Settings.Name + ': ' + chstr, NET_CHAT_TEAM,
5238 gPlayer1Settings.Team);
5239 end
5240 else
5241 g_Console_Add('teamchat <text>');
5242 end else
5243 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
5244 end
5245 else if cmd = 'game' then
5246 begin
5247 if gGameSettings.GameType <> GT_NONE then
5248 begin
5249 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
5250 Exit;
5251 end;
5252 if Length(P) = 1 then
5253 begin
5254 g_Console_Add(cmd + ' <WAD> [MAP] [# players]');
5255 Exit;
5256 end;
5257 // game not started yet, load fist map from some wad
5258 found := false;
5259 s := addWadExtension(P[1]);
5260 found := e_FindResource(AllMapDirs, s);
5261 P[1] := s;
5262 if found then
5263 begin
5264 P[1] := ExpandFileName(P[1]);
5265 // if map not choosed then set first map
5266 if Length(P) < 3 then
5267 begin
5268 SetLength(P, 3);
5269 P[2] := g_Game_GetFirstMap(P[1]);
5270 end;
5272 s := P[1] + ':\' + UpperCase(P[2]);
5274 if g_Map_Exist(s) then
5275 begin
5276 // start game
5277 g_Game_Free();
5278 with gGameSettings do
5279 begin
5280 Options := gsGameFlags;
5281 GameMode := g_Game_TextToMode(gsGameMode);
5282 if gSwitchGameMode <> GM_NONE then
5283 GameMode := gSwitchGameMode;
5284 if GameMode = GM_NONE then GameMode := GM_DM;
5285 if GameMode = GM_SINGLE then GameMode := GM_COOP;
5286 b := 1;
5287 if Length(P) >= 4 then
5288 b := StrToIntDef(P[3], 1);
5289 g_Game_StartCustom(s, GameMode, TimeLimit,
5290 GoalLimit, MaxLives, Options, b);
5291 end;
5292 end
5293 else
5294 if P[2] = '' then
5295 g_Console_Add(Format(_lc[I_MSG_NO_MAPS], [P[1]]))
5296 else
5297 g_Console_Add(Format(_lc[I_MSG_NO_MAP_FALLBACK], [UpperCase(P[2]), P[1]]));
5298 end else
5299 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]));
5300 end
5301 else if cmd = 'host' then
5302 begin
5303 if gGameSettings.GameType <> GT_NONE then
5304 begin
5305 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
5306 Exit;
5307 end;
5308 if Length(P) < 4 then
5309 begin
5310 g_Console_Add(cmd + ' <listen IP> <port> <WAD> [MAP] [# players]');
5311 Exit;
5312 end;
5313 if not StrToIp(P[1], listen) then
5314 Exit;
5315 prt := StrToIntDef(P[2], 25666);
5317 s := addWadExtension(P[3]);
5318 found := e_FindResource(AllMapDirs, s);
5319 P[3] := s;
5320 if found then
5321 begin
5322 // get first map in wad, if not specified
5323 if Length(P) < 5 then
5324 begin
5325 SetLength(P, 5);
5326 P[4] := g_Game_GetFirstMap(P[1]);
5327 end;
5328 s := P[3] + ':\' + UpperCase(P[4]);
5329 if g_Map_Exist(s) then
5330 begin
5331 // start game
5332 g_Game_Free();
5333 with gGameSettings do
5334 begin
5335 Options := gsGameFlags;
5336 GameMode := g_Game_TextToMode(gsGameMode);
5337 if gSwitchGameMode <> GM_NONE then GameMode := gSwitchGameMode;
5338 if GameMode = GM_NONE then GameMode := GM_DM;
5339 if GameMode = GM_SINGLE then GameMode := GM_COOP;
5340 b := 0;
5341 if Length(P) >= 6 then
5342 b := StrToIntDef(P[5], 0);
5343 g_Game_StartServer(s, GameMode, TimeLimit, GoalLimit, MaxLives, Options, b, listen, prt)
5344 end
5345 end
5346 else
5347 begin
5348 if P[4] = '' then
5349 g_Console_Add(Format(_lc[I_MSG_NO_MAPS], [P[3]]))
5350 else
5351 g_Console_Add(Format(_lc[I_MSG_NO_MAP_FALLBACK], [UpperCase(P[4]), P[3]]))
5352 end
5353 end
5354 else
5355 begin
5356 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[3]]))
5357 end
5358 end
5359 else if cmd = 'map' then
5360 begin
5361 if Length(P) = 1 then
5362 begin
5363 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
5364 begin
5365 g_Console_Add(cmd + ' <MAP>');
5366 g_Console_Add(cmd + ' <WAD> [MAP]')
5367 end
5368 else
5369 begin
5370 g_Console_Add(_lc[I_MSG_GM_UNAVAIL])
5371 end
5372 end
5373 else
5374 begin
5375 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
5376 begin
5377 if Length(P) < 3 then
5378 begin
5379 // first param is map or wad
5380 s := UpperCase(P[1]);
5381 if g_Map_Exist(gGameSettings.WAD + ':\' + s) then
5382 begin
5383 gExitByTrigger := False;
5384 if gGameOn then
5385 begin
5386 // already in game, finish current map
5387 gNextMap := s;
5388 gExit := EXIT_ENDLEVELCUSTOM;
5389 end
5390 else
5391 begin
5392 // intermission, so change map immediately
5393 g_Game_ChangeMap(s)
5394 end
5395 end
5396 else
5397 begin
5398 s := P[1];
5399 found := e_FindResource(AllMapDirs, s);
5400 P[1] := s;
5401 g_Console_Add(Format(_lc[I_MSG_NO_MAP_FALLBACK], [s, 'WAD ' + P[1]]));
5402 if found then
5403 begin
5404 // no such map, found wad
5405 pw := P[1];
5406 SetLength(P, 3);
5407 P[1] := ExpandFileName(pw);
5408 P[2] := g_Game_GetFirstMap(P[1]);
5409 s := P[1] + ':\' + P[2];
5410 if g_Map_Exist(s) then
5411 begin
5412 gExitByTrigger := False;
5413 if gGameOn then
5414 begin
5415 // already in game, finish current map
5416 gNextMap := s;
5417 gExit := EXIT_ENDLEVELCUSTOM
5418 end
5419 else
5420 begin
5421 // intermission, so change map immediately
5422 g_Game_ChangeMap(s)
5423 end
5424 end
5425 else
5426 begin
5427 if P[2] = '' then
5428 g_Console_Add(Format(_lc[I_MSG_NO_MAPS], [P[1]]))
5429 else
5430 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [P[2]]))
5431 end
5432 end
5433 else
5434 begin
5435 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]))
5436 end
5437 end;
5438 end
5439 else
5440 begin
5441 s := addWadExtension(P[1]);
5442 found := e_FindResource(AllMapDirs, s);
5443 P[1] := s;
5444 if found then
5445 begin
5446 P[2] := UpperCase(P[2]);
5447 s := P[1] + ':\' + P[2];
5448 if g_Map_Exist(s) then
5449 begin
5450 gExitByTrigger := False;
5451 if gGameOn then
5452 begin
5453 gNextMap := s;
5454 gExit := EXIT_ENDLEVELCUSTOM
5455 end
5456 else
5457 begin
5458 g_Game_ChangeMap(s)
5459 end
5460 end
5461 else
5462 begin
5463 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [P[2]]))
5464 end
5465 end
5466 else
5467 begin
5468 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]))
5469 end
5470 end
5471 end
5472 else
5473 begin
5474 g_Console_Add(_lc[I_MSG_GM_UNAVAIL])
5475 end
5476 end
5477 end
5478 else if cmd = 'nextmap' then
5479 begin
5480 if not(gGameOn or (gState = STATE_INTERCUSTOM)) then
5481 begin
5482 g_Console_Add(_lc[I_MSG_NOT_GAME])
5483 end
5484 else
5485 begin
5486 nm := True;
5487 if Length(P) = 1 then
5488 begin
5489 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
5490 begin
5491 g_Console_Add(cmd + ' <MAP>');
5492 g_Console_Add(cmd + ' <WAD> [MAP]');
5493 end
5494 else
5495 begin
5496 nm := False;
5497 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
5498 end;
5499 end
5500 else
5501 begin
5502 nm := False;
5503 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
5504 begin
5505 if Length(P) < 3 then
5506 begin
5507 // first param is map or wad
5508 s := UpperCase(P[1]);
5509 if g_Map_Exist(gGameSettings.WAD + ':\' + s) then
5510 begin
5511 // map founded
5512 gExitByTrigger := False;
5513 gNextMap := s;
5514 nm := True;
5515 end
5516 else
5517 begin
5518 // no such map, found wad
5519 pw := addWadExtension(P[1]);
5520 found := e_FindResource(MapDirs, pw);
5521 if not found then
5522 found := e_FindResource(WadDirs, pw);
5523 P[1] := pw;
5524 g_Console_Add(Format(_lc[I_MSG_NO_MAP_FALLBACK], [s, P[1]]));
5525 if found then
5526 begin
5527 // map not specified, select first map
5528 SetLength(P, 3);
5529 P[2] := g_Game_GetFirstMap(P[1]);
5530 s := P[1] + ':\' + P[2];
5531 if g_Map_Exist(s) then
5532 begin
5533 gExitByTrigger := False;
5534 gNextMap := s;
5535 nm := True
5536 end
5537 else
5538 begin
5539 if P[2] = '' then
5540 g_Console_Add(Format(_lc[I_MSG_NO_MAPS], [P[1]]))
5541 else
5542 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [P[2]]))
5543 end
5544 end
5545 else
5546 begin
5547 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]))
5548 end
5549 end
5550 end
5551 else
5552 begin
5553 // specified two params wad + map
5554 pw := addWadExtension(P[1]);
5555 found := e_FindResource(MapDirs, pw);
5556 if not found then
5557 found := e_FindResource(MapDirs, pw);
5558 P[1] := pw;
5559 if found then
5560 begin
5561 P[2] := UpperCase(P[2]);
5562 s := P[1] + ':\' + P[2];
5563 if g_Map_Exist(s) then
5564 begin
5565 gExitByTrigger := False;
5566 gNextMap := s;
5567 nm := True
5568 end
5569 else
5570 begin
5571 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [P[2]]))
5572 end
5573 end
5574 else
5575 begin
5576 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]))
5577 end
5578 end
5579 end
5580 else
5581 begin
5582 g_Console_Add(_lc[I_MSG_GM_UNAVAIL])
5583 end
5584 end;
5585 if nm then
5586 begin
5587 if gNextMap = '' then
5588 g_Console_Add(_lc[I_MSG_NEXTMAP_UNSET])
5589 else
5590 g_Console_Add(Format(_lc[I_MSG_NEXTMAP_SET], [gNextMap]))
5591 end
5592 end
5593 end
5594 else if (cmd = 'endmap') or (cmd = 'goodbye') then
5595 begin
5596 if not gGameOn then
5597 begin
5598 g_Console_Add(_lc[I_MSG_NOT_GAME])
5599 end
5600 else
5601 begin
5602 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
5603 begin
5604 gExitByTrigger := False;
5605 // next map not specified, try to find trigger EXIT
5606 if (gNextMap = '') and (gTriggers <> nil) then
5607 begin
5608 for a := 0 to High(gTriggers) do
5609 begin
5610 if gTriggers[a].TriggerType = TRIGGER_EXIT then
5611 begin
5612 gExitByTrigger := True;
5613 //gNextMap := gTriggers[a].Data.MapName;
5614 gNextMap := gTriggers[a].tgcMap;
5615 Break
5616 end
5617 end
5618 end;
5619 if gNextMap = '' then
5620 gNextMap := g_Game_GetNextMap();
5621 if not isWadPath(gNextMap) then
5622 s := gGameSettings.WAD + ':\' + gNextMap
5623 else
5624 s := gNextMap;
5625 if g_Map_Exist(s) then
5626 gExit := EXIT_ENDLEVELCUSTOM
5627 else
5628 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [gNextMap]))
5629 end
5630 else
5631 begin
5632 g_Console_Add(_lc[I_MSG_GM_UNAVAIL])
5633 end
5634 end
5635 end
5636 else if (cmd = 'event') then
5637 begin
5638 if (Length(P) <= 1) then
5639 begin
5640 for a := 0 to High(gEvents) do
5641 if gEvents[a].Command = '' then
5642 g_Console_Add(gEvents[a].Name + ' <none>')
5643 else
5644 g_Console_Add(gEvents[a].Name + ' "' + gEvents[a].Command + '"');
5645 Exit;
5646 end;
5647 if (Length(P) = 2) then
5648 begin
5649 for a := 0 to High(gEvents) do
5650 if gEvents[a].Name = P[1] then
5651 if gEvents[a].Command = '' then
5652 g_Console_Add(gEvents[a].Name + ' <none>')
5653 else
5654 g_Console_Add(gEvents[a].Name + ' "' + gEvents[a].Command + '"');
5655 Exit;
5656 end;
5657 for a := 0 to High(gEvents) do
5658 if gEvents[a].Name = P[1] then
5659 begin
5660 gEvents[a].Command := '';
5661 for b := 2 to High(P) do
5662 if Pos(' ', P[b]) = 0 then
5663 gEvents[a].Command := gEvents[a].Command + ' ' + P[b]
5664 else
5665 gEvents[a].Command := gEvents[a].Command + ' "' + P[b] + '"';
5666 gEvents[a].Command := Trim(gEvents[a].Command);
5667 Exit;
5668 end;
5669 end
5670 else if cmd = 'suicide' then
5671 begin
5672 if gGameOn then
5673 begin
5674 if g_Game_IsClient then
5675 MC_SEND_CheatRequest(NET_CHEAT_SUICIDE)
5676 else
5677 begin
5678 if gPlayer1 <> nil then
5679 gPlayer1.Damage(SUICIDE_DAMAGE, gPlayer1.UID, 0, 0, HIT_SELF);
5680 if gPlayer2 <> nil then
5681 gPlayer2.Damage(SUICIDE_DAMAGE, gPlayer2.UID, 0, 0, HIT_SELF);
5682 end;
5683 end;
5684 end
5685 else if cmd = 'screenshot' then
5686 begin
5687 g_TakeScreenShot()
5688 end
5689 else if cmd = 'weapon' then
5690 begin
5691 if Length(p) = 2 then
5692 begin
5693 a := WP_FIRST + StrToInt(p[1]) - 1;
5694 if (a >= WP_FIRST) and (a <= WP_LAST) then
5695 gSelectWeapon[0, a] := True
5696 end
5697 end
5698 else if (cmd = 'p1_weapon') or (cmd = 'p2_weapon') then
5699 begin
5700 if Length(p) = 2 then
5701 begin
5702 a := WP_FIRST + StrToInt(p[1]) - 1;
5703 b := ord(cmd[2]) - ord('1');
5704 if (a >= WP_FIRST) and (a <= WP_LAST) then
5705 gSelectWeapon[b, a] := True
5706 end
5707 end
5708 // Команды Своей игры:
5709 else if gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT] then
5710 begin
5711 if cmd = 'bot_addred' then
5712 begin
5713 if Length(P) > 1 then
5714 g_Bot_Add(TEAM_RED, StrToIntDef(P[1], 2))
5715 else
5716 g_Bot_Add(TEAM_RED, 2);
5717 end
5718 else if cmd = 'bot_addblue' then
5719 begin
5720 if Length(P) > 1 then
5721 g_Bot_Add(TEAM_BLUE, StrToIntDef(P[1], 2))
5722 else
5723 g_Bot_Add(TEAM_BLUE, 2);
5724 end
5725 else if cmd = 'spectate' then
5726 begin
5727 if not gGameOn then
5728 Exit;
5729 g_Game_Spectate();
5730 end
5731 else if cmd = 'say' then
5732 begin
5733 if g_Game_IsServer and g_Game_IsNet then
5734 begin
5735 if Length(P) > 1 then
5736 begin
5737 chstr := '';
5738 for a := 1 to High(P) do
5739 chstr := chstr + P[a] + ' ';
5741 if Length(chstr) > 200 then SetLength(chstr, 200);
5743 if Length(chstr) < 1 then
5744 begin
5745 g_Console_Add('say <text>');
5746 Exit;
5747 end;
5749 chstr := b_Text_Format(chstr);
5750 MH_SEND_Chat(chstr, NET_CHAT_PLAYER);
5751 end
5752 else g_Console_Add('say <text>');
5753 end else
5754 g_Console_Add(_lc[I_MSG_SERVERONLY]);
5755 end
5756 else if cmd = 'tell' then
5757 begin
5758 if g_Game_IsServer and g_Game_IsNet then
5759 begin
5760 if (Length(P) > 2) and (P[1] <> '') then
5761 begin
5762 chstr := '';
5763 for a := 2 to High(P) do
5764 chstr := chstr + P[a] + ' ';
5766 if Length(chstr) > 200 then SetLength(chstr, 200);
5768 if Length(chstr) < 1 then
5769 begin
5770 g_Console_Add('tell <playername> <text>');
5771 Exit;
5772 end;
5774 pl := g_Net_Client_ByName(P[1]);
5775 if pl <> nil then
5776 MH_SEND_Chat(b_Text_Format(chstr), NET_CHAT_PLAYER, pl^.ID)
5777 else
5778 g_Console_Add(Format(_lc[I_NET_ERR_NAME404], [P[1]]));
5779 end
5780 else g_Console_Add('tell <playername> <text>');
5781 end else
5782 g_Console_Add(_lc[I_MSG_SERVERONLY]);
5783 end
5784 else if cmd = 'centerprint' then
5785 begin
5786 if (Length(P) > 2) and (P[1] <> '') then
5787 begin
5788 chstr := '';
5789 for a := 2 to High(P) do
5790 chstr := chstr + P[a] + ' ';
5792 if Length(chstr) > 200 then SetLength(chstr, 200);
5794 if Length(chstr) < 1 then
5795 begin
5796 g_Console_Add('centerprint <timeout> <text>');
5797 Exit;
5798 end;
5800 a := StrToIntDef(P[1], 100);
5801 chstr := b_Text_Format(chstr);
5802 g_Game_Message(chstr, a);
5803 if g_Game_IsNet and g_Game_IsServer then
5804 MH_SEND_GameEvent(NET_EV_BIGTEXT, a, chstr);
5805 end
5806 else g_Console_Add('centerprint <timeout> <text>');
5807 end
5808 else if (cmd = 'overtime') and not g_Game_IsClient then
5809 begin
5810 if (Length(P) = 1) or (StrToIntDef(P[1], -1) <= 0) then
5811 Exit;
5812 // Дополнительное время:
5813 gGameSettings.TimeLimit := (gTime - gGameStartTime) div 1000 + Word(StrToIntDef(P[1], 0));
5815 g_Console_Add(Format(_lc[I_MSG_TIME_LIMIT],
5816 [gGameSettings.TimeLimit div 3600,
5817 (gGameSettings.TimeLimit div 60) mod 60,
5818 gGameSettings.TimeLimit mod 60]));
5819 if g_Game_IsNet then MH_SEND_GameSettings;
5820 end
5821 else if (cmd = 'rcon_password') and g_Game_IsClient then
5822 begin
5823 if (Length(P) <= 1) then
5824 g_Console_Add('rcon_password <password>')
5825 else
5826 MC_SEND_RCONPassword(P[1]);
5827 end
5828 else if cmd = 'rcon' then
5829 begin
5830 if g_Game_IsClient then
5831 begin
5832 if Length(P) > 1 then
5833 begin
5834 chstr := '';
5835 for a := 1 to High(P) do
5836 chstr := chstr + P[a] + ' ';
5838 if Length(chstr) > 200 then SetLength(chstr, 200);
5840 if Length(chstr) < 1 then
5841 begin
5842 g_Console_Add('rcon <command>');
5843 Exit;
5844 end;
5846 MC_SEND_RCONCommand(chstr);
5847 end
5848 else g_Console_Add('rcon <command>');
5849 end;
5850 end
5851 else if cmd = 'ready' then
5852 begin
5853 if g_Game_IsServer and (gLMSRespawn = LMS_RESPAWN_WARMUP) then
5854 gLMSRespawnTime := gTime + 100;
5855 end
5856 else if (cmd = 'callvote') and g_Game_IsNet then
5857 begin
5858 if Length(P) > 1 then
5859 begin
5860 chstr := '';
5861 for a := 1 to High(P) do begin
5862 if a > 1 then chstr := chstr + ' ';
5863 chstr := chstr + P[a];
5864 end;
5866 if Length(chstr) > 200 then SetLength(chstr, 200);
5868 if Length(chstr) < 1 then
5869 begin
5870 g_Console_Add('callvote <command>');
5871 Exit;
5872 end;
5874 if g_Game_IsClient then
5875 MC_SEND_Vote(True, chstr)
5876 else
5877 g_Game_StartVote(chstr, gPlayer1Settings.Name);
5878 g_Console_Process('vote', True);
5879 end
5880 else
5881 g_Console_Add('callvote <command>');
5882 end
5883 else if (cmd = 'vote') and g_Game_IsNet then
5884 begin
5885 if g_Game_IsClient then
5886 MC_SEND_Vote(False)
5887 else if gVoteInProgress then
5888 begin
5889 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
5890 a := Floor((NetClientCount+1)/2.0) + 1
5891 else
5892 a := Floor(NetClientCount/2.0) + 1;
5893 if gVoted then
5894 begin
5895 Dec(gVoteCount);
5896 gVoted := False;
5897 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_REVOKED], [gPlayer1Settings.Name, gVoteCount, a]), True);
5898 MH_SEND_VoteEvent(NET_VE_REVOKE, gPlayer1Settings.Name, 'a', gVoteCount, a);
5899 end
5900 else
5901 begin
5902 Inc(gVoteCount);
5903 gVoted := True;
5904 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_VOTE], [gPlayer1Settings.Name, gVoteCount, a]), True);
5905 MH_SEND_VoteEvent(NET_VE_VOTE, gPlayer1Settings.Name, 'a', gVoteCount, a);
5906 g_Game_CheckVote;
5907 end;
5908 end;
5909 end
5910 end;
5911 end;
5913 procedure SystemCommands(P: SSArray);
5914 var
5915 cmd: string;
5916 begin
5917 cmd := LowerCase(P[0]);
5918 case cmd of
5919 'exit', 'quit':
5920 begin
5921 g_Game_Free();
5922 g_Game_Quit();
5923 end;
5924 'r_reset':
5925 r_Render_Apply;
5926 'r_maxfps':
5927 begin
5928 if Length(p) = 2 then
5929 begin
5930 gMaxFPS := StrToIntDef(p[1], gMaxFPS);
5931 if gMaxFPS > 0 then
5932 gFrameTime := 1000 div gMaxFPS
5933 else
5934 gFrameTime := 0;
5935 end;
5936 e_LogWritefln('r_maxfps %d', [gMaxFPS]);
5937 end;
5938 'g_language':
5939 begin
5940 if Length(p) = 2 then
5941 begin
5942 gAskLanguage := true;
5943 gLanguage := LANGUAGE_ENGLISH;
5944 case LowerCase(p[1]) of
5945 'english':
5946 begin
5947 gAskLanguage := false;
5948 gLanguage := LANGUAGE_ENGLISH;
5949 end;
5950 'russian':
5951 begin
5952 gAskLanguage := false;
5953 gLanguage := LANGUAGE_RUSSIAN;
5954 end;
5955 'ask':
5956 begin
5957 gAskLanguage := true;
5958 gLanguage := LANGUAGE_ENGLISH;
5959 end;
5960 end;
5961 g_Language_Set(gLanguage);
5962 end
5963 else
5964 begin
5965 e_LogWritefln('usage: %s <English|Russian|Ask>', [cmd]);
5966 end
5967 end;
5968 end;
5969 end;
5971 procedure g_TakeScreenShot(Filename: string = '');
5972 var s: TStream; t: TDateTime; dir, date, name: String;
5973 begin
5974 if e_NoGraphics then Exit;
5975 try
5976 dir := e_GetWriteableDir(ScreenshotDirs);
5978 if Filename = '' then
5979 begin
5980 t := Now;
5981 DateTimeToString(date, 'yyyy-mm-dd-hh-nn-ss', t);
5982 Filename := 'screenshot-' + date;
5983 end;
5985 name := e_CatPath(dir, Filename + '.png');
5986 s := createDiskFile(name);
5987 try
5988 e_MakeScreenshot(s, gScreenWidth, gScreenHeight);
5989 s.Free;
5990 g_Console_Add(Format(_lc[I_CONSOLE_SCREENSHOT], [name]))
5991 except
5992 g_Console_Add(Format(_lc[I_CONSOLE_ERROR_WRITE], [name]));
5993 s.Free;
5994 DeleteFile(name)
5995 end
5996 except
5997 g_Console_Add('oh shit, i can''t create screenshot!')
5998 end
5999 end;
6001 procedure g_Game_InGameMenu(Show: Boolean);
6002 begin
6003 if (g_ActiveWindow = nil) and Show then
6004 begin
6005 if gGameSettings.GameType = GT_SINGLE then
6006 g_GUI_ShowWindow('GameSingleMenu')
6007 else
6008 begin
6009 if g_Game_IsClient then
6010 g_GUI_ShowWindow('GameClientMenu')
6011 else
6012 if g_Game_IsNet then
6013 g_GUI_ShowWindow('GameServerMenu')
6014 else
6015 g_GUI_ShowWindow('GameCustomMenu');
6016 end;
6017 g_Sound_PlayEx('MENU_OPEN');
6019 // Пауза при меню только в одиночной игре:
6020 if (not g_Game_IsNet) then
6021 g_Game_Pause(True);
6022 end
6023 else
6024 if (g_ActiveWindow <> nil) and (not Show) then
6025 begin
6026 // Пауза при меню только в одиночной игре:
6027 if (not g_Game_IsNet) then
6028 g_Game_Pause(False);
6029 end;
6030 end;
6032 procedure g_Game_Pause (Enable: Boolean);
6033 var
6034 oldPause: Boolean;
6035 begin
6036 if not gGameOn then exit;
6038 if not (gGameSettings.GameType in [GT_SINGLE, GT_CUSTOM]) then exit;
6040 oldPause := gPause;
6041 gPauseMain := Enable;
6043 if (gPause <> oldPause) then g_Game_PauseAllSounds(gPause);
6044 end;
6046 procedure g_Game_HolmesPause (Enable: Boolean);
6047 var
6048 oldPause: Boolean;
6049 begin
6050 if not gGameOn then exit;
6051 if not (gGameSettings.GameType in [GT_SINGLE, GT_CUSTOM]) then exit;
6053 oldPause := gPause;
6054 gPauseHolmes := Enable;
6056 if (gPause <> oldPause) then g_Game_PauseAllSounds(gPause);
6057 end;
6059 procedure g_Game_PauseAllSounds(Enable: Boolean);
6060 var
6061 i: Integer;
6062 begin
6063 // Триггеры:
6064 if gTriggers <> nil then
6065 for i := 0 to High(gTriggers) do
6066 with gTriggers[i] do
6067 if (TriggerType = TRIGGER_SOUND) and
6068 (Sound <> nil) and
6069 Sound.IsPlaying() then
6070 begin
6071 Sound.Pause(Enable);
6072 end;
6074 // Звуки игроков:
6075 if gPlayers <> nil then
6076 for i := 0 to High(gPlayers) do
6077 if gPlayers[i] <> nil then
6078 gPlayers[i].PauseSounds(Enable);
6080 // Музыка:
6081 if gMusic <> nil then
6082 gMusic.Pause(Enable);
6083 end;
6085 procedure g_Game_StopAllSounds(all: Boolean);
6086 var
6087 i: Integer;
6088 begin
6089 if gTriggers <> nil then
6090 for i := 0 to High(gTriggers) do
6091 with gTriggers[i] do
6092 if (TriggerType = TRIGGER_SOUND) and
6093 (Sound <> nil) then
6094 Sound.Stop();
6096 if gMusic <> nil then
6097 gMusic.Stop();
6099 if all then
6100 e_StopChannels();
6101 end;
6103 procedure g_Game_UpdateTriggerSounds;
6104 var i: Integer;
6105 begin
6106 if gTriggers <> nil then
6107 for i := 0 to High(gTriggers) do
6108 with gTriggers[i] do
6109 if (TriggerType = TRIGGER_SOUND) and (Sound <> nil) and tgcLocal and Sound.IsPlaying() then
6110 Sound.SetCoordsRect(X, Y, Width, Height, tgcVolume / 255.0)
6111 end;
6113 function g_Game_IsWatchedPlayer(UID: Word): Boolean;
6114 begin
6115 Result := False;
6116 if (gPlayer1 <> nil) and (gPlayer1.UID = UID) then
6117 begin
6118 Result := True;
6119 Exit;
6120 end;
6121 if (gPlayer2 <> nil) and (gPlayer2.UID = UID) then
6122 begin
6123 Result := True;
6124 Exit;
6125 end;
6126 if gSpectMode <> SPECT_PLAYERS then
6127 Exit;
6128 if gSpectPID1 = UID then
6129 begin
6130 Result := True;
6131 Exit;
6132 end;
6133 if gSpectViewTwo and (gSpectPID2 = UID) then
6134 begin
6135 Result := True;
6136 Exit;
6137 end;
6138 end;
6140 function g_Game_IsWatchedTeam(Team: Byte): Boolean;
6141 var
6142 Pl: TPlayer;
6143 begin
6144 Result := False;
6145 if (gPlayer1 <> nil) and (gPlayer1.Team = Team) then
6146 begin
6147 Result := True;
6148 Exit;
6149 end;
6150 if (gPlayer2 <> nil) and (gPlayer2.Team = Team) then
6151 begin
6152 Result := True;
6153 Exit;
6154 end;
6155 if gSpectMode <> SPECT_PLAYERS then
6156 Exit;
6157 Pl := g_Player_Get(gSpectPID1);
6158 if (Pl <> nil) and (Pl.Team = Team) then
6159 begin
6160 Result := True;
6161 Exit;
6162 end;
6163 if gSpectViewTwo then
6164 begin
6165 Pl := g_Player_Get(gSpectPID2);
6166 if (Pl <> nil) and (Pl.Team = Team) then
6167 begin
6168 Result := True;
6169 Exit;
6170 end;
6171 end;
6172 end;
6174 procedure g_Game_Message(Msg: string; Time: Word);
6175 begin
6176 MessageLineLength := (gScreenWidth - 204) div e_CharFont_GetMaxWidth(gMenuFont);
6177 MessageText := b_Text_Wrap(b_Text_Format(Msg), MessageLineLength);
6178 MessageTime := Time;
6179 end;
6181 procedure g_Game_ChatSound(Text: String; Taunt: Boolean = True);
6182 const
6183 punct: Array[0..13] of String =
6184 ('.', ',', ':', ';', '!', '?', '(', ')', '''', '"', '/', '\', '*', '^');
6185 var
6186 i, j: Integer;
6187 ok: Boolean;
6188 fpText: String;
6190 function IsPunctuation(S: String): Boolean;
6191 var
6192 i: Integer;
6193 begin
6194 Result := False;
6195 if Length(S) <> 1 then
6196 Exit;
6197 for i := Low(punct) to High(punct) do
6198 if S = punct[i] then
6199 begin
6200 Result := True;
6201 break;
6202 end;
6203 end;
6204 function FilterPunctuation(S: String): String;
6205 var
6206 i: Integer;
6207 begin
6208 for i := Low(punct) to High(punct) do
6209 S := StringReplace(S, punct[i], ' ', [rfReplaceAll]);
6210 Result := S;
6211 end;
6212 begin
6213 ok := False;
6215 if gUseChatSounds and Taunt and (gChatSounds <> nil) and (Pos(': ', Text) > 0) then
6216 begin
6217 // remove player name
6218 Delete(Text, 1, Pos(': ', Text) + 2 - 1);
6219 // for FullWord check
6220 Text := toLowerCase1251(' ' + Text + ' ');
6221 fpText := FilterPunctuation(Text);
6223 for i := 0 to Length(gChatSounds) - 1 do
6224 begin
6225 ok := True;
6226 for j := 0 to Length(gChatSounds[i].Tags) - 1 do
6227 begin
6228 if gChatSounds[i].FullWord and (not IsPunctuation(gChatSounds[i].Tags[j])) then
6229 ok := Pos(' ' + gChatSounds[i].Tags[j] + ' ', fpText) > 0
6230 else
6231 ok := Pos(gChatSounds[i].Tags[j], Text) > 0;
6232 if not ok then
6233 break;
6234 end;
6235 if ok then
6236 begin
6237 gChatSounds[i].Sound.Play();
6238 break;
6239 end;
6240 end;
6241 end;
6242 if not ok then
6243 g_Sound_PlayEx('SOUND_GAME_RADIO');
6244 end;
6246 procedure g_Game_Announce_GoodShot(SpawnerUID: Word);
6247 var
6248 a: Integer;
6249 begin
6250 case gAnnouncer of
6251 ANNOUNCE_NONE:
6252 Exit;
6253 ANNOUNCE_ME,
6254 ANNOUNCE_MEPLUS:
6255 if not g_Game_IsWatchedPlayer(SpawnerUID) then
6256 Exit;
6257 end;
6258 for a := 0 to 3 do
6259 if goodsnd[a].IsPlaying() then
6260 Exit;
6262 goodsnd[Random(4)].Play();
6263 end;
6265 procedure g_Game_Announce_KillCombo(Param: Integer);
6266 var
6267 UID: Word;
6268 c, n: Byte;
6269 Pl: TPlayer;
6270 Name: String;
6271 begin
6272 UID := Param and $FFFF;
6273 c := Param shr 16;
6274 if c < 2 then
6275 Exit;
6277 Pl := g_Player_Get(UID);
6278 if Pl = nil then
6279 Name := '?'
6280 else
6281 Name := Pl.Name;
6283 case c of
6284 2: begin
6285 n := 0;
6286 g_Console_Add(Format(_lc[I_PLAYER_KILL_2X], [Name]), True);
6287 end;
6288 3: begin
6289 n := 1;
6290 g_Console_Add(Format(_lc[I_PLAYER_KILL_3X], [Name]), True);
6291 end;
6292 4: begin
6293 n := 2;
6294 g_Console_Add(Format(_lc[I_PLAYER_KILL_4X], [Name]), True);
6295 end;
6296 else begin
6297 n := 3;
6298 g_Console_Add(Format(_lc[I_PLAYER_KILL_MX], [Name]), True);
6299 end;
6300 end;
6302 case gAnnouncer of
6303 ANNOUNCE_NONE:
6304 Exit;
6305 ANNOUNCE_ME:
6306 if not g_Game_IsWatchedPlayer(UID) then
6307 Exit;
6308 ANNOUNCE_MEPLUS:
6309 if (not g_Game_IsWatchedPlayer(UID)) and (c < 4) then
6310 Exit;
6311 end;
6313 if killsnd[n].IsPlaying() then
6314 killsnd[n].Stop();
6315 killsnd[n].Play();
6316 end;
6318 procedure g_Game_Announce_BodyKill(SpawnerUID: Word);
6319 var
6320 a: Integer;
6321 begin
6322 case gAnnouncer of
6323 ANNOUNCE_NONE:
6324 Exit;
6325 ANNOUNCE_ME:
6326 if not g_Game_IsWatchedPlayer(SpawnerUID) then
6327 Exit;
6328 end;
6329 for a := 0 to 2 do
6330 if hahasnd[a].IsPlaying() then
6331 Exit;
6333 hahasnd[Random(3)].Play();
6334 end;
6336 procedure g_Game_StartVote(Command, Initiator: string);
6337 var
6338 Need: Integer;
6339 begin
6340 if not gVotesEnabled then Exit;
6341 if gGameSettings.GameType <> GT_SERVER then Exit;
6342 if gVoteInProgress or gVotePassed then
6343 begin
6344 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_INPROGRESS], [gVoteCommand]), True);
6345 MH_SEND_VoteEvent(NET_VE_INPROGRESS, gVoteCommand);
6346 Exit;
6347 end;
6348 gVoteInProgress := True;
6349 gVotePassed := False;
6350 gVoteTimer := gTime + gVoteTimeout * 1000;
6351 gVoteCount := 0;
6352 gVoted := False;
6353 gVoteCommand := Command;
6355 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
6356 Need := Floor((NetClientCount+1)/2.0)+1
6357 else
6358 Need := Floor(NetClientCount/2.0)+1;
6359 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_STARTED], [Initiator, Command, Need]), True);
6360 MH_SEND_VoteEvent(NET_VE_STARTED, Initiator, Command, Need);
6361 end;
6363 procedure g_Game_CheckVote;
6364 var
6365 I, Need: Integer;
6366 begin
6367 if gGameSettings.GameType <> GT_SERVER then Exit;
6368 if not gVoteInProgress then Exit;
6370 if (gTime >= gVoteTimer) then
6371 begin
6372 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
6373 Need := Floor((NetClientCount+1)/2.0) + 1
6374 else
6375 Need := Floor(NetClientCount/2.0) + 1;
6376 if gVoteCount >= Need then
6377 begin
6378 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_PASSED], [gVoteCommand]), True);
6379 MH_SEND_VoteEvent(NET_VE_PASSED, gVoteCommand);
6380 gVotePassed := True;
6381 gVoteCmdTimer := gTime + 5000;
6382 end
6383 else
6384 begin
6385 g_Console_Add(_lc[I_MESSAGE_VOTE_FAILED], True);
6386 MH_SEND_VoteEvent(NET_VE_FAILED);
6387 end;
6388 if NetClients <> nil then
6389 for I := Low(NetClients) to High(NetClients) do
6390 if NetClients[i].Used then
6391 NetClients[i].Voted := False;
6392 gVoteInProgress := False;
6393 gVoted := False;
6394 gVoteCount := 0;
6395 end
6396 else
6397 begin
6398 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
6399 Need := Floor((NetClientCount+1)/2.0) + 1
6400 else
6401 Need := Floor(NetClientCount/2.0) + 1;
6402 if gVoteCount >= Need then
6403 begin
6404 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_PASSED], [gVoteCommand]), True);
6405 MH_SEND_VoteEvent(NET_VE_PASSED, gVoteCommand);
6406 gVoteInProgress := False;
6407 gVotePassed := True;
6408 gVoteCmdTimer := gTime + 5000;
6409 gVoted := False;
6410 gVoteCount := 0;
6411 if NetClients <> nil then
6412 for I := Low(NetClients) to High(NetClients) do
6413 if NetClients[i].Used then
6414 NetClients[i].Voted := False;
6415 end;
6416 end;
6417 end;
6419 procedure g_Game_LoadMapList(FileName: string);
6420 var
6421 ListFile: TextFile;
6422 s: string;
6423 begin
6424 MapList := nil;
6425 MapIndex := -1;
6427 if not FileExists(FileName) then Exit;
6429 AssignFile(ListFile, FileName);
6430 Reset(ListFile);
6431 while not EOF(ListFile) do
6432 begin
6433 ReadLn(ListFile, s);
6435 s := Trim(s);
6436 if s = '' then Continue;
6438 SetLength(MapList, Length(MapList)+1);
6439 MapList[High(MapList)] := s;
6440 end;
6441 CloseFile(ListFile);
6442 end;
6444 procedure g_Game_SetDebugMode();
6445 begin
6446 gDebugMode := True;
6447 // Читы (даже в своей игре):
6448 gCheats := True;
6449 end;
6451 procedure g_Game_SetLoadingText(Text: String; Max: Integer; reWrite: Boolean);
6452 var
6453 i: Word;
6454 begin
6455 if Length(LoadingStat.Msgs) = 0 then
6456 Exit;
6458 with LoadingStat do
6459 begin
6460 if not reWrite then
6461 begin // Переходим на следующую строку или скроллируем:
6462 if NextMsg = Length(Msgs) then
6463 begin // scroll
6464 for i := 0 to High(Msgs)-1 do
6465 Msgs[i] := Msgs[i+1];
6466 end
6467 else
6468 Inc(NextMsg);
6469 end else
6470 if NextMsg = 0 then
6471 Inc(NextMsg);
6473 Msgs[NextMsg-1] := Text;
6474 CurValue := 0;
6475 MaxValue := Max;
6476 ShowCount := 0;
6477 PBarWasHere := false;
6478 end;
6480 g_ActiveWindow := nil;
6482 ProcessLoading(true);
6483 end;
6485 procedure g_Game_StepLoading(Value: Integer = -1);
6486 begin
6487 with LoadingStat do
6488 begin
6489 if Value = -1 then
6490 begin
6491 Inc(CurValue);
6492 Inc(ShowCount);
6493 end
6494 else
6495 CurValue := Value;
6496 if (ShowCount > LOADING_SHOW_STEP) or (Value > -1) then
6497 begin
6498 ShowCount := 0;
6499 ProcessLoading();
6500 end;
6501 end;
6502 end;
6504 procedure g_Game_ClearLoading();
6505 var
6506 len: Word;
6507 begin
6508 with LoadingStat do
6509 begin
6510 CurValue := 0;
6511 MaxValue := 0;
6512 ShowCount := 0;
6513 len := ((gScreenHeight div 3)*2 - 50) div LOADING_INTERLINE;
6514 if len < 1 then len := 1;
6515 SetLength(Msgs, len);
6516 for len := Low(Msgs) to High(Msgs) do
6517 Msgs[len] := '';
6518 NextMsg := 0;
6519 PBarWasHere := false;
6520 end;
6521 end;
6523 procedure Parse_Params(var pars: TParamStrValues);
6524 var
6525 i: Integer;
6526 s: String;
6527 begin
6528 SetLength(pars, 0);
6529 i := 1;
6530 while i <= ParamCount do
6531 begin
6532 s := ParamStr(i);
6533 if (s[1] = '-') and (Length(s) > 1) then
6534 begin
6535 if (s[2] = '-') and (Length(s) > 2) then
6536 begin // Одиночный параметр
6537 SetLength(pars, Length(pars) + 1);
6538 with pars[High(pars)] do
6539 begin
6540 Name := LowerCase(s);
6541 Value := '+';
6542 end;
6543 end
6544 else
6545 if (i < ParamCount) then
6546 begin // Параметр со значением
6547 Inc(i);
6548 SetLength(pars, Length(pars) + 1);
6549 with pars[High(pars)] do
6550 begin
6551 Name := LowerCase(s);
6552 Value := LowerCase(ParamStr(i));
6553 end;
6554 end;
6555 end;
6557 Inc(i);
6558 end;
6559 end;
6561 function Find_Param_Value(var pars: TParamStrValues; aName: String): String;
6562 var
6563 i: Integer;
6564 begin
6565 Result := '';
6566 for i := 0 to High(pars) do
6567 if pars[i].Name = aName then
6568 begin
6569 Result := pars[i].Value;
6570 Break;
6571 end;
6572 end;
6574 procedure g_Game_Process_Params();
6575 var
6576 pars: TParamStrValues;
6577 map: String;
6578 GMode, n: Byte;
6579 LimT, LimS: Integer;
6580 Opt: LongWord;
6581 Lives: Integer;
6582 s: String;
6583 Port: Integer;
6584 ip: String;
6585 F: TextFile;
6586 begin
6587 Parse_Params(pars);
6589 // Debug mode:
6590 s := Find_Param_Value(pars, '--debug');
6591 if (s <> '') then
6592 begin
6593 g_Game_SetDebugMode();
6594 s := Find_Param_Value(pars, '--netdump');
6595 if (s <> '') then
6596 NetDump := True;
6597 end;
6599 // Connect when game loads
6600 ip := Find_Param_Value(pars, '-connect');
6602 if ip <> '' then
6603 begin
6604 s := Find_Param_Value(pars, '-port');
6605 if (s = '') or not TryStrToInt(s, Port) then
6606 Port := 25666;
6608 s := Find_Param_Value(pars, '-pw');
6610 g_Game_StartClient(ip, Port, s);
6611 Exit;
6612 end;
6614 s := LowerCase(Find_Param_Value(pars, '-dbg-mainwad'));
6615 if (s <> '') then
6616 begin
6617 gDefaultMegawadStart := s;
6618 end;
6620 if (Find_Param_Value(pars, '--dbg-mainwad-restore') <> '') or
6621 (Find_Param_Value(pars, '--dbg-mainwad-default') <> '') then
6622 begin
6623 gDefaultMegawadStart := DF_Default_Megawad_Start;
6624 end;
6626 // Start map when game loads:
6627 map := LowerCase(Find_Param_Value(pars, '-map'));
6628 if isWadPath(map) then
6629 begin
6630 // Game mode:
6631 s := Find_Param_Value(pars, '-gm');
6632 GMode := g_Game_TextToMode(s);
6633 if GMode = GM_NONE then GMode := GM_DM;
6634 if GMode = GM_SINGLE then GMode := GM_COOP;
6636 // Time limit:
6637 s := Find_Param_Value(pars, '-limt');
6638 if (s = '') or (not TryStrToInt(s, LimT)) then
6639 LimT := 0;
6640 if LimT < 0 then
6641 LimT := 0;
6643 // Goal limit:
6644 s := Find_Param_Value(pars, '-lims');
6645 if (s = '') or (not TryStrToInt(s, LimS)) then
6646 LimS := 0;
6647 if LimS < 0 then
6648 LimS := 0;
6650 // Lives limit:
6651 s := Find_Param_Value(pars, '-lives');
6652 if (s = '') or (not TryStrToInt(s, Lives)) then
6653 Lives := 0;
6654 if Lives < 0 then
6655 Lives := 0;
6657 // Options:
6658 s := Find_Param_Value(pars, '-opt');
6659 if (s = '') then
6660 Opt := gsGameFlags
6661 else
6662 Opt := StrToIntDef(s, 0);
6664 // Close after map:
6665 s := Find_Param_Value(pars, '--close');
6666 if (s <> '') then
6667 gMapOnce := True;
6669 // Override map to test:
6670 s := LowerCase(Find_Param_Value(pars, '-testmap'));
6671 if s <> '' then
6672 begin
6673 if e_IsValidResourceName(s) then
6674 e_FindResource(AllMapDirs, s);
6675 gTestMap := ExpandFileName(s);
6676 end;
6678 // Delete test map after play:
6679 s := Find_Param_Value(pars, '--testdelete');
6680 if (s <> '') then
6681 begin
6682 //gMapToDelete := MapsDir + map;
6683 e_WriteLog('"--testdelete" is deprecated, use --tempdelete.', TMsgType.Fatal);
6684 Halt(1);
6685 end;
6687 // Delete temporary WAD after play:
6688 s := Find_Param_Value(pars, '--tempdelete');
6689 if (s <> '') and (gTestMap <> '') then
6690 begin
6691 gMapToDelete := gTestMap;
6692 gTempDelete := True;
6693 end;
6695 // Number of players:
6696 s := Find_Param_Value(pars, '-pl');
6697 if (s = '') then
6698 n := DEFAULT_PLAYERS
6699 else
6700 n := StrToIntDef(s, DEFAULT_PLAYERS);
6702 // Start:
6703 s := Find_Param_Value(pars, '-port');
6704 if (s = '') or not TryStrToInt(s, Port) then
6705 g_Game_StartCustom(map, GMode, LimT, LimS, Lives, Opt, n)
6706 else
6707 g_Game_StartServer(map, GMode, LimT, LimS, Lives, Opt, n, 0, Port);
6708 end;
6710 // Execute script when game loads:
6711 s := Find_Param_Value(pars, '-exec');
6712 if s <> '' then
6713 begin
6714 // if not isWadPath(s) then
6715 // s := GameDir + '/' + s;
6717 {$I-}
6718 AssignFile(F, s);
6719 Reset(F);
6720 if IOResult <> 0 then
6721 begin
6722 e_WriteLog(Format(_lc[I_SIMPLE_ERROR], ['Failed to read file: ' + s]), TMsgType.Warning);
6723 g_Console_Add(Format(_lc[I_CONSOLE_ERROR_READ], [s]));
6724 CloseFile(F);
6725 Exit;
6726 end;
6727 e_WriteLog('Executing script: ' + s, TMsgType.Notify);
6728 g_Console_Add(Format(_lc[I_CONSOLE_EXEC], [s]));
6730 while not EOF(F) do
6731 begin
6732 ReadLn(F, s);
6733 if IOResult <> 0 then
6734 begin
6735 e_WriteLog(Format(_lc[I_SIMPLE_ERROR], ['Failed to read file: ' + s]), TMsgType.Warning);
6736 g_Console_Add(Format(_lc[I_CONSOLE_ERROR_READ], [s]));
6737 CloseFile(F);
6738 Exit;
6739 end;
6740 if Pos('#', s) <> 1 then // script comment
6741 g_Console_Process(s, True);
6742 end;
6744 CloseFile(F);
6745 {$I+}
6746 end;
6748 SetLength(pars, 0);
6749 end;
6751 begin
6752 conRegVar('pf_draw_frame', @g_profile_frame_draw, 'draw frame rendering profiles', 'render profiles');
6753 //conRegVar('pf_update_frame', @g_profile_frame_update, 'draw frame updating profiles', 'update profiles');
6754 conRegVar('pf_coldet', @g_profile_collision, 'draw collision detection profiles', 'coldet profiles');
6755 conRegVar('pf_los', @g_profile_los, 'draw monster LOS profiles', 'monster LOS profiles');
6757 conRegVar('r_sq_draw', @gdbg_map_use_accel_render, 'accelerated spatial queries in rendering', 'accelerated rendering');
6758 conRegVar('cd_sq_enabled', @gdbg_map_use_accel_coldet, 'accelerated spatial queries in map coldet', 'accelerated map coldet');
6759 conRegVar('mon_sq_enabled', @gmon_debug_use_sqaccel, 'accelerated spatial queries for monsters', 'accelerated monster coldet');
6760 conRegVar('wtrace_sq_enabled', @gwep_debug_fast_trace, 'accelerated spatial queries for weapon hitscan trace', 'accelerated weapon hitscan');
6762 conRegVar('pr_enabled', @gpart_dbg_enabled, 'enable/disable particles', 'particles');
6763 conRegVar('pr_phys_enabled', @gpart_dbg_phys_enabled, 'enable/disable particle physics', 'particle physics');
6765 conRegVar('los_enabled', @gmon_dbg_los_enabled, 'enable/disable monster LOS calculations', 'monster LOS', true);
6766 conRegVar('mon_think', @gmon_debug_think, 'enable/disable monster thinking', 'monster thinking', true);
6768 {$IFDEF ENABLE_HOLMES}
6769 conRegVar('dbg_holmes', @g_holmes_enabled, 'enable/disable Holmes', 'Holmes', true);
6770 {$ENDIF}
6772 conRegVar('dbg_ignore_level_bounds', @g_dbg_ignore_bounds, 'ignore level bounds', '', false);
6774 conRegVar('light_enabled', @gwin_k8_enable_light_experiments, 'enable/disable dynamic lighting', 'lighting');
6775 conRegVar('light_player_halo', @g_playerLight, 'enable/disable player halo', 'player light halo');
6777 conRegVar('r_smallmap_align_h', @r_smallmap_h, 'halign: 0: left; 1: center; 2: right', 'horizontal aligning of small maps');
6778 conRegVar('r_smallmap_align_v', @r_smallmap_v, 'valign: 0: top; 1: center; 2: bottom', 'vertial aligning of small maps');
6780 conRegVar('r_showfps', @gShowFPS, 'draw fps counter', 'draw fps counter');
6781 conRegVar('r_showtime', @gShowTime, 'show game time', 'show game time');
6782 conRegVar('r_showping', @gShowPing, 'show ping', 'show ping');
6783 conRegVar('r_showscore', @gShowGoals, 'show score', 'show score');
6784 conRegVar('r_showkillmsg', @gShowKillMsg, 'show kill log', 'show kill log');
6785 conRegVar('r_showlives', @gShowLives, 'show lives', 'show lives');
6786 conRegVar('r_showspect', @gSpectHUD, 'show spectator hud', 'show spectator hud');
6787 conRegVar('r_showstat', @gShowStat, 'show stats', 'show stats');
6788 conRegVar('r_showpids', @gShowPIDs, 'show PIDs', 'show PIDs');
6789 end.