DEADSOFTWARE

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