DEADSOFTWARE

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