DEADSOFTWARE

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