DEADSOFTWARE

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