DEADSOFTWARE

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