DEADSOFTWARE

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