DEADSOFTWARE

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