DEADSOFTWARE

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