DEADSOFTWARE

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