DEADSOFTWARE

game: fix spectator mode switch
[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) then
2263 begin
2264 (* no local players -> automatically enable to spectator mode *)
2265 if gSpectMode = SPECT_NONE then gSpectMode := SPECT_STATS;
2266 end
2267 else
2268 begin
2269 (* at least one local player -> automatically disable spectator mode *)
2270 gSpectMode := SPECT_NONE;
2271 end;
2273 if IsActivePlayer(g_Player_Get(gSpectPID1)) = false then
2274 gSpectPID1 := GetActivePlayerID_Next();
2276 if IsActivePlayer(g_Player_Get(gSpectPID2)) = false then
2277 gSpectPID2 := GetActivePlayerID_Next();
2279 g_Game_SetupHearPoints;
2281 // Обновляем все остальное:
2282 g_Map_Update();
2283 g_Items_Update();
2284 g_Triggers_Update();
2285 g_Weapon_Update();
2286 g_Monsters_Update();
2287 {$IFDEF ENABLE_GFX}
2288 g_GFX_Update;
2289 {$ENDIF}
2290 g_Player_UpdateAll();
2291 {$IFDEF ENABLE_GIBS}
2292 g_Gibs_Update;
2293 {$ENDIF}
2294 {$IFDEF ENABLE_CORPSES}
2295 g_Corpses_Update;
2296 {$ENDIF}
2297 {$IFDEF ENABLE_SHELLS}
2298 g_Shells_Update;
2299 {$ENDIF}
2301 // server: send newly spawned monsters unconditionally
2302 if (gGameSettings.GameType = GT_SERVER) then
2303 begin
2304 if (Length(gMonstersSpawned) > 0) then
2305 begin
2306 for I := 0 to High(gMonstersSpawned) do MH_SEND_MonsterSpawn(gMonstersSpawned[I]);
2307 SetLength(gMonstersSpawned, 0);
2308 end;
2309 end;
2311 if (gSoundTriggerTime > 8) then
2312 begin
2313 g_Game_UpdateTriggerSounds();
2314 gSoundTriggerTime := 0;
2315 end
2316 else
2317 begin
2318 Inc(gSoundTriggerTime);
2319 end;
2321 if (NetMode = NET_SERVER) then
2322 begin
2323 Inc(NetTimeToUpdate);
2324 Inc(NetTimeToReliable);
2326 // send monster updates
2327 if (NetTimeToReliable >= NetRelupdRate) or (NetTimeToUpdate >= NetUpdateRate) then
2328 begin
2329 // send all monsters (periodic sync)
2330 reliableUpdate := (NetTimeToReliable >= NetRelupdRate);
2332 for I := 0 to High(gPlayers) do
2333 begin
2334 if (gPlayers[I] <> nil) then MH_SEND_PlayerPos(reliableUpdate, gPlayers[I].UID);
2335 end;
2337 g_Mons_ForEach(sendMonsPos);
2339 // update flags that aren't stationary
2340 if gGameSettings.GameMode = GM_CTF then
2341 for I := FLAG_RED to FLAG_BLUE do
2342 if gFlags[I].NeedSend then
2343 begin
2344 gFlags[I].NeedSend := False;
2345 MH_SEND_FlagPos(I);
2346 end;
2348 // update items that aren't stationary
2349 g_Items_ForEachAlive(sendItemPos);
2351 if reliableUpdate then
2352 begin
2353 NetTimeToReliable := 0;
2354 NetTimeToUpdate := NetUpdateRate;
2355 end
2356 else
2357 begin
2358 NetTimeToUpdate := 0;
2359 end;
2360 end
2361 else
2362 begin
2363 // send only mosters with some unexpected changes
2364 g_Mons_ForEach(sendMonsPosUnexpected);
2365 end;
2367 // send unexpected platform changes
2368 g_Map_NetSendInterestingPanels();
2370 g_Net_Slist_ServerUpdate();
2372 if NetUseMaster then
2373 begin
2374 if (gTime >= NetTimeToMaster) or g_Net_Slist_IsConnectionInProgress then
2375 begin
2376 if (not g_Net_Slist_IsConnectionActive) then g_Net_Slist_Connect(false); // non-blocking connection to the master
2377 g_Net_Slist_Update;
2378 NetTimeToMaster := gTime + NetMasterRate;
2379 end;
2380 end;
2382 end
2383 else if (NetMode = NET_CLIENT) then
2384 begin
2385 MC_SEND_PlayerPos();
2386 end;
2387 end; // if gameOn ...
2389 // Активно окно интерфейса - передаем клавиши ему:
2390 {$IFDEF ENABLE_MENU}
2391 if g_ActiveWindow <> nil then
2392 begin
2393 w := e_GetFirstKeyPressed();
2395 if (w <> IK_INVALID) then
2396 begin
2397 Msg.Msg := MESSAGE_DIKEY;
2398 Msg.wParam := w;
2399 g_ActiveWindow.OnMessage(Msg);
2400 end;
2402 // Если оно от этого не закрылось, то обновляем:
2403 if g_ActiveWindow <> nil then
2404 g_ActiveWindow.Update();
2406 // Нужно сменить разрешение:
2407 if gResolutionChange then
2408 begin
2409 {$IFDEF ENABLE_RENDER}
2410 e_WriteLog('Changing resolution', TMsgType.Notify);
2411 r_Render_Apply;
2412 {$ENDIF}
2413 gResolutionChange := False;
2414 g_ActiveWindow := nil;
2415 end;
2417 // Нужно сменить язык:
2418 if gLanguageChange then
2419 begin
2420 //e_WriteLog('Read language file', MSG_NOTIFY);
2421 //g_Language_Load(DataDir + gLanguage + '.txt');
2422 g_Language_Set(gLanguage);
2423 g_Menu_Reset();
2424 gLanguageChange := False;
2425 end;
2426 end;
2428 // Горячая клавиша для вызова меню выхода из игры (F10):
2429 if e_KeyPressed(IK_F10) and
2430 gGameOn and
2431 (not gConsoleShow) and
2432 (g_ActiveWindow = nil) then
2433 begin
2434 KeyPress(IK_F10);
2435 end;
2436 {$ENDIF}
2438 Time := GetTickCount64() {div 1000};
2440 // Обработка отложенных событий:
2441 if gDelayedEvents <> nil then
2442 for a := 0 to High(gDelayedEvents) do
2443 if gDelayedEvents[a].Pending and
2445 ((gDelayedEvents[a].DEType = DE_GLOBEVENT) and (gDelayedEvents[a].Time <= Time)) or
2446 ((gDelayedEvents[a].DEType > DE_GLOBEVENT) and (gDelayedEvents[a].Time <= gTime))
2447 ) then
2448 begin
2449 case gDelayedEvents[a].DEType of
2450 DE_GLOBEVENT:
2451 g_Game_ExecuteEvent(gDelayedEvents[a].DEStr);
2452 DE_BFGHIT:
2453 if gGameOn then
2454 g_Game_Announce_GoodShot(gDelayedEvents[a].DENum);
2455 DE_KILLCOMBO:
2456 if gGameOn then
2457 begin
2458 g_Game_Announce_KillCombo(gDelayedEvents[a].DENum);
2459 if g_Game_IsNet and g_Game_IsServer then
2460 MH_SEND_GameEvent(NET_EV_KILLCOMBO, gDelayedEvents[a].DENum);
2461 end;
2462 DE_BODYKILL:
2463 if gGameOn then
2464 g_Game_Announce_BodyKill(gDelayedEvents[a].DENum);
2465 end;
2466 gDelayedEvents[a].Pending := False;
2467 end;
2469 // Каждую секунду обновляем счетчик обновлений:
2470 UPSCounter := UPSCounter + 1;
2471 if Time - UPSTime >= 1000 then
2472 begin
2473 UPS := UPSCounter;
2474 UPSCounter := 0;
2475 UPSTime := Time;
2476 end;
2478 if gGameOn then
2479 begin
2480 g_Weapon_AddDynLights();
2481 g_Items_AddDynLights();
2482 end;
2483 end;
2485 procedure g_Game_LoadChatSounds(Resource: string);
2486 var
2487 WAD: TWADFile;
2488 FileName, Snd: string;
2489 p: Pointer;
2490 len, cnt, tags, i, j: Integer;
2491 cfg: TConfig;
2492 begin
2493 FileName := g_ExtractWadName(Resource);
2495 WAD := TWADFile.Create();
2496 WAD.ReadFile(FileName);
2498 if not WAD.GetResource(g_ExtractFilePathName(Resource), p, len) then
2499 begin
2500 gChatSounds := nil;
2501 WAD.Free();
2502 Exit;
2503 end;
2505 cfg := TConfig.CreateMem(p, len);
2506 cnt := cfg.ReadInt('ChatSounds', 'Count', 0);
2508 SetLength(gChatSounds, cnt);
2509 for i := 0 to Length(gChatSounds) - 1 do
2510 begin
2511 gChatSounds[i].Sound := nil;
2512 Snd := Trim(cfg.ReadStr(IntToStr(i), 'Sound', ''));
2513 tags := cfg.ReadInt(IntToStr(i), 'Tags', 0);
2514 if (Snd = '') or (Tags <= 0) then
2515 continue;
2516 g_Sound_CreateWADEx('SOUND_CHAT_MACRO' + IntToStr(i), GameWAD+':'+Snd);
2517 gChatSounds[i].Sound := TPlayableSound.Create();
2518 gChatSounds[i].Sound.SetByName('SOUND_CHAT_MACRO' + IntToStr(i));
2519 SetLength(gChatSounds[i].Tags, tags);
2520 for j := 0 to tags - 1 do
2521 gChatSounds[i].Tags[j] := toLowerCase1251(cfg.ReadStr(IntToStr(i), 'Tag' + IntToStr(j), ''));
2522 gChatSounds[i].FullWord := cfg.ReadBool(IntToStr(i), 'FullWord', False);
2523 end;
2525 cfg.Free();
2526 WAD.Free();
2527 end;
2529 procedure g_Game_FreeChatSounds();
2530 var
2531 i: Integer;
2532 begin
2533 for i := 0 to Length(gChatSounds) - 1 do
2534 begin
2535 gChatSounds[i].Sound.Free();
2536 g_Sound_Delete('SOUND_CHAT_MACRO' + IntToStr(i));
2537 end;
2538 SetLength(gChatSounds, 0);
2539 gChatSounds := nil;
2540 end;
2542 procedure g_Game_LoadData();
2543 begin
2544 if DataLoaded then Exit;
2546 e_WriteLog('Loading game data...', TMsgType.Notify);
2547 g_Game_SetLoadingText(_lc[I_LOAD_GAME_DATA], 0, False);
2549 g_Sound_CreateWADEx('SOUND_GAME_TELEPORT', GameWAD+':SOUNDS\TELEPORT');
2550 g_Sound_CreateWADEx('SOUND_GAME_NOTELEPORT', GameWAD+':SOUNDS\NOTELEPORT');
2551 g_Sound_CreateWADEx('SOUND_GAME_SECRET', GameWAD+':SOUNDS\SECRET');
2552 g_Sound_CreateWADEx('SOUND_GAME_DOOROPEN', GameWAD+':SOUNDS\DOOROPEN');
2553 g_Sound_CreateWADEx('SOUND_GAME_DOORCLOSE', GameWAD+':SOUNDS\DOORCLOSE');
2554 g_Sound_CreateWADEx('SOUND_GAME_BULK1', GameWAD+':SOUNDS\BULK1');
2555 g_Sound_CreateWADEx('SOUND_GAME_BULK2', GameWAD+':SOUNDS\BULK2');
2556 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE1', GameWAD+':SOUNDS\BUBBLE1');
2557 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE2', GameWAD+':SOUNDS\BUBBLE2');
2558 g_Sound_CreateWADEx('SOUND_GAME_BURNING', GameWAD+':SOUNDS\BURNING');
2559 g_Sound_CreateWADEx('SOUND_GAME_SWITCH1', GameWAD+':SOUNDS\SWITCH1');
2560 g_Sound_CreateWADEx('SOUND_GAME_SWITCH0', GameWAD+':SOUNDS\SWITCH0');
2561 g_Sound_CreateWADEx('SOUND_GAME_RADIO', GameWAD+':SOUNDS\RADIO');
2562 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD1', GameWAD+':SOUNDS\GOOD1');
2563 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD2', GameWAD+':SOUNDS\GOOD2');
2564 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD3', GameWAD+':SOUNDS\GOOD3');
2565 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD4', GameWAD+':SOUNDS\GOOD4');
2566 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL2X', GameWAD+':SOUNDS\KILL2X');
2567 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL3X', GameWAD+':SOUNDS\KILL3X');
2568 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL4X', GameWAD+':SOUNDS\KILL4X');
2569 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILLMX', GameWAD+':SOUNDS\KILLMX');
2570 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA1', GameWAD+':SOUNDS\MUHAHA1');
2571 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA2', GameWAD+':SOUNDS\MUHAHA2');
2572 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA3', GameWAD+':SOUNDS\MUHAHA3');
2573 g_Sound_CreateWADEx('SOUND_CTF_GET1', GameWAD+':SOUNDS\GETFLAG1');
2574 g_Sound_CreateWADEx('SOUND_CTF_GET2', GameWAD+':SOUNDS\GETFLAG2');
2575 g_Sound_CreateWADEx('SOUND_CTF_LOST1', GameWAD+':SOUNDS\LOSTFLG1');
2576 g_Sound_CreateWADEx('SOUND_CTF_LOST2', GameWAD+':SOUNDS\LOSTFLG2');
2577 g_Sound_CreateWADEx('SOUND_CTF_RETURN1', GameWAD+':SOUNDS\RETFLAG1');
2578 g_Sound_CreateWADEx('SOUND_CTF_RETURN2', GameWAD+':SOUNDS\RETFLAG2');
2579 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE1', GameWAD+':SOUNDS\CAPFLAG1');
2580 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE2', GameWAD+':SOUNDS\CAPFLAG2');
2582 goodsnd[0] := TPlayableSound.Create();
2583 goodsnd[1] := TPlayableSound.Create();
2584 goodsnd[2] := TPlayableSound.Create();
2585 goodsnd[3] := TPlayableSound.Create();
2587 goodsnd[0].SetByName('SOUND_ANNOUNCER_GOOD1');
2588 goodsnd[1].SetByName('SOUND_ANNOUNCER_GOOD2');
2589 goodsnd[2].SetByName('SOUND_ANNOUNCER_GOOD3');
2590 goodsnd[3].SetByName('SOUND_ANNOUNCER_GOOD4');
2592 killsnd[0] := TPlayableSound.Create();
2593 killsnd[1] := TPlayableSound.Create();
2594 killsnd[2] := TPlayableSound.Create();
2595 killsnd[3] := TPlayableSound.Create();
2597 killsnd[0].SetByName('SOUND_ANNOUNCER_KILL2X');
2598 killsnd[1].SetByName('SOUND_ANNOUNCER_KILL3X');
2599 killsnd[2].SetByName('SOUND_ANNOUNCER_KILL4X');
2600 killsnd[3].SetByName('SOUND_ANNOUNCER_KILLMX');
2602 hahasnd[0] := TPlayableSound.Create();
2603 hahasnd[1] := TPlayableSound.Create();
2604 hahasnd[2] := TPlayableSound.Create();
2606 hahasnd[0].SetByName('SOUND_ANNOUNCER_MUHAHA1');
2607 hahasnd[1].SetByName('SOUND_ANNOUNCER_MUHAHA2');
2608 hahasnd[2].SetByName('SOUND_ANNOUNCER_MUHAHA3');
2610 sound_get_flag[0] := TPlayableSound.Create();
2611 sound_get_flag[1] := TPlayableSound.Create();
2612 sound_lost_flag[0] := TPlayableSound.Create();
2613 sound_lost_flag[1] := TPlayableSound.Create();
2614 sound_ret_flag[0] := TPlayableSound.Create();
2615 sound_ret_flag[1] := TPlayableSound.Create();
2616 sound_cap_flag[0] := TPlayableSound.Create();
2617 sound_cap_flag[1] := TPlayableSound.Create();
2619 sound_get_flag[0].SetByName('SOUND_CTF_GET1');
2620 sound_get_flag[1].SetByName('SOUND_CTF_GET2');
2621 sound_lost_flag[0].SetByName('SOUND_CTF_LOST1');
2622 sound_lost_flag[1].SetByName('SOUND_CTF_LOST2');
2623 sound_ret_flag[0].SetByName('SOUND_CTF_RETURN1');
2624 sound_ret_flag[1].SetByName('SOUND_CTF_RETURN2');
2625 sound_cap_flag[0].SetByName('SOUND_CTF_CAPTURE1');
2626 sound_cap_flag[1].SetByName('SOUND_CTF_CAPTURE2');
2628 g_Game_LoadChatSounds(GameWAD+':CHATSND\SNDCFG');
2630 g_Items_LoadData();
2632 g_Weapon_LoadData();
2634 g_Monsters_LoadData();
2636 DataLoaded := True;
2637 end;
2639 procedure g_Game_Quit();
2640 begin
2641 g_Game_StopAllSounds(True);
2642 gMusic.Free();
2643 g_Game_FreeData();
2644 g_PlayerModel_FreeData();
2645 {$IFDEF ENABLE_MENU}
2646 // g_Menu_Free(); //k8: this segfaults after resolution change; who cares?
2647 {$ENDIF}
2649 if NetInitDone then g_Net_Free;
2651 // remove map after test
2652 if gMapToDelete <> '' then
2653 g_Game_DeleteTestMap();
2655 gExit := EXIT_QUIT;
2657 {$IFDEF ENABLE_SYSTEM}
2658 sys_RequestQuit;
2659 {$ENDIF}
2660 end;
2662 procedure g_Game_FreeData();
2663 begin
2664 if not DataLoaded then Exit;
2666 g_Items_FreeData();
2667 g_Weapon_FreeData();
2668 g_Monsters_FreeData();
2670 e_WriteLog('Releasing game data...', TMsgType.Notify);
2672 g_Sound_Delete('SOUND_GAME_TELEPORT');
2673 g_Sound_Delete('SOUND_GAME_NOTELEPORT');
2674 g_Sound_Delete('SOUND_GAME_SECRET');
2675 g_Sound_Delete('SOUND_GAME_DOOROPEN');
2676 g_Sound_Delete('SOUND_GAME_DOORCLOSE');
2677 g_Sound_Delete('SOUND_GAME_BULK1');
2678 g_Sound_Delete('SOUND_GAME_BULK2');
2679 g_Sound_Delete('SOUND_GAME_BUBBLE1');
2680 g_Sound_Delete('SOUND_GAME_BUBBLE2');
2681 g_Sound_Delete('SOUND_GAME_BURNING');
2682 g_Sound_Delete('SOUND_GAME_SWITCH1');
2683 g_Sound_Delete('SOUND_GAME_SWITCH0');
2685 goodsnd[0].Free();
2686 goodsnd[1].Free();
2687 goodsnd[2].Free();
2688 goodsnd[3].Free();
2690 g_Sound_Delete('SOUND_ANNOUNCER_GOOD1');
2691 g_Sound_Delete('SOUND_ANNOUNCER_GOOD2');
2692 g_Sound_Delete('SOUND_ANNOUNCER_GOOD3');
2693 g_Sound_Delete('SOUND_ANNOUNCER_GOOD4');
2695 killsnd[0].Free();
2696 killsnd[1].Free();
2697 killsnd[2].Free();
2698 killsnd[3].Free();
2700 g_Sound_Delete('SOUND_ANNOUNCER_KILL2X');
2701 g_Sound_Delete('SOUND_ANNOUNCER_KILL3X');
2702 g_Sound_Delete('SOUND_ANNOUNCER_KILL4X');
2703 g_Sound_Delete('SOUND_ANNOUNCER_KILLMX');
2705 hahasnd[0].Free();
2706 hahasnd[1].Free();
2707 hahasnd[2].Free();
2709 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA1');
2710 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA2');
2711 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA3');
2713 sound_get_flag[0].Free();
2714 sound_get_flag[1].Free();
2715 sound_lost_flag[0].Free();
2716 sound_lost_flag[1].Free();
2717 sound_ret_flag[0].Free();
2718 sound_ret_flag[1].Free();
2719 sound_cap_flag[0].Free();
2720 sound_cap_flag[1].Free();
2722 g_Sound_Delete('SOUND_CTF_GET1');
2723 g_Sound_Delete('SOUND_CTF_GET2');
2724 g_Sound_Delete('SOUND_CTF_LOST1');
2725 g_Sound_Delete('SOUND_CTF_LOST2');
2726 g_Sound_Delete('SOUND_CTF_RETURN1');
2727 g_Sound_Delete('SOUND_CTF_RETURN2');
2728 g_Sound_Delete('SOUND_CTF_CAPTURE1');
2729 g_Sound_Delete('SOUND_CTF_CAPTURE2');
2731 g_Game_FreeChatSounds();
2733 DataLoaded := False;
2734 end;
2736 procedure g_FatalError(Text: String);
2737 begin
2738 g_Console_Add(Format(_lc[I_FATAL_ERROR], [Text]), True);
2739 e_WriteLog(Format(_lc[I_FATAL_ERROR], [Text]), TMsgType.Warning);
2741 gExit := EXIT_SIMPLE;
2742 if gGameOn then EndGame;
2743 end;
2745 procedure g_SimpleError(Text: String);
2746 begin
2747 g_Console_Add(Format(_lc[I_SIMPLE_ERROR], [Text]), True);
2748 e_WriteLog(Format(_lc[I_SIMPLE_ERROR], [Text]), TMsgType.Warning);
2749 end;
2751 procedure g_Game_AddPlayer(Team: Byte = TEAM_NONE);
2752 begin
2753 if ((not gGameOn) and (gState <> STATE_INTERCUSTOM))
2754 or (not (gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT])) then
2755 Exit;
2757 if (gGameSettings.MaxLives > 0) and (gLMSRespawn = LMS_RESPAWN_NONE) then
2758 Exit;
2760 if gPlayer1 = nil then
2761 begin
2762 if g_Game_IsClient then
2763 begin
2764 if NetPlrUID1 > -1 then
2765 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE);
2766 Exit;
2767 end;
2769 if not (Team in [TEAM_RED, TEAM_BLUE]) then
2770 Team := gPlayer1Settings.Team;
2772 // Создание первого игрока:
2773 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
2774 gPlayer1Settings.Color,
2775 Team, False));
2776 if gPlayer1 = nil then
2777 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]))
2778 else
2779 begin
2780 gPlayer1.Name := gPlayer1Settings.Name;
2781 gPlayer1.WeapSwitchMode := gPlayer1Settings.WeaponSwitch;
2782 gPlayer1.setWeaponPrefs(gPlayer1Settings.WeaponPreferences);
2783 gPlayer1.SwitchToEmpty := gPlayer1Settings.SwitchToEmpty;
2784 gPlayer1.SkipFist := gPlayer1Settings.SkipFist;
2785 g_Console_Add(Format(_lc[I_PLAYER_JOIN], [gPlayer1.Name]), True);
2786 if g_Game_IsServer and g_Game_IsNet then
2787 MH_SEND_PlayerCreate(gPlayer1.UID);
2788 gPlayer1.Respawn(False, True);
2789 g_Net_Slist_ServerPlayerComes();
2790 end;
2792 Exit;
2793 end;
2794 if gPlayer2 = nil then
2795 begin
2796 if g_Game_IsClient then
2797 begin
2798 if NetPlrUID2 > -1 then
2799 gPlayer2 := g_Player_Get(NetPlrUID2);
2800 Exit;
2801 end;
2803 if not (Team in [TEAM_RED, TEAM_BLUE]) then
2804 Team := gPlayer2Settings.Team;
2806 // Создание второго игрока:
2807 gPlayer2 := g_Player_Get(g_Player_Create(gPlayer2Settings.Model,
2808 gPlayer2Settings.Color,
2809 Team, False));
2810 if gPlayer2 = nil then
2811 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [2]))
2812 else
2813 begin
2814 gPlayer2.Name := gPlayer2Settings.Name;
2815 gPlayer2.WeapSwitchMode := gPlayer2Settings.WeaponSwitch;
2816 gPlayer2.setWeaponPrefs(gPlayer2Settings.WeaponPreferences);
2817 gPlayer2.SwitchToEmpty := gPlayer2Settings.SwitchToEmpty;
2818 gPlayer2.SkipFist := gPlayer2Settings.SkipFist;
2819 g_Console_Add(Format(_lc[I_PLAYER_JOIN], [gPlayer2.Name]), True);
2820 if g_Game_IsServer and g_Game_IsNet then
2821 MH_SEND_PlayerCreate(gPlayer2.UID);
2822 gPlayer2.Respawn(False, True);
2823 g_Net_Slist_ServerPlayerComes();
2824 end;
2826 Exit;
2827 end;
2828 end;
2830 procedure g_Game_RemovePlayer();
2831 var
2832 Pl: TPlayer;
2833 begin
2834 if ((not gGameOn) and (gState <> STATE_INTERCUSTOM))
2835 or (not (gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT])) then
2836 Exit;
2837 Pl := gPlayer2;
2838 if Pl <> nil then
2839 begin
2840 if g_Game_IsServer then
2841 begin
2842 Pl.Lives := 0;
2843 Pl.Kill(K_SIMPLEKILL, 0, HIT_DISCON);
2844 g_Console_Add(Format(_lc[I_PLAYER_LEAVE], [Pl.Name]), True);
2845 g_Player_Remove(Pl.UID);
2846 g_Net_Slist_ServerPlayerLeaves();
2847 end
2848 else
2849 begin
2850 gSpectLatchPID2 := Pl.UID;
2851 gPlayer2 := nil;
2852 end;
2853 Exit;
2854 end;
2855 Pl := gPlayer1;
2856 if Pl <> nil then
2857 begin
2858 if g_Game_IsServer then
2859 begin
2860 Pl.Lives := 0;
2861 Pl.Kill(K_SIMPLEKILL, 0, HIT_DISCON);
2862 g_Console_Add(Format(_lc[I_PLAYER_LEAVE], [Pl.Name]), True);
2863 g_Player_Remove(Pl.UID);
2864 g_Net_Slist_ServerPlayerLeaves();
2865 end else
2866 begin
2867 gSpectLatchPID1 := Pl.UID;
2868 gPlayer1 := nil;
2869 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE);
2870 end;
2871 Exit;
2872 end;
2873 g_Net_Slist_ServerPlayerLeaves();
2874 end;
2876 procedure g_Game_Spectate();
2877 begin
2878 g_Game_RemovePlayer();
2879 if gPlayer1 <> nil then
2880 g_Game_RemovePlayer();
2881 end;
2883 procedure g_Game_SpectateCenterView();
2884 begin
2885 gSpectX := Max(gMapInfo.Width div 2 - gScreenWidth div 2, 0);
2886 gSpectY := Max(gMapInfo.Height div 2 - gScreenHeight div 2, 0);
2887 end;
2889 procedure g_Game_StartSingle(Map: String; TwoPlayers: Boolean; nPlayers: Byte);
2890 var
2891 i, nPl: Integer;
2892 tmps: AnsiString;
2893 begin
2894 g_Game_Free();
2896 e_WriteLog('Starting singleplayer game...', TMsgType.Notify);
2898 g_Game_ClearLoading();
2900 // Настройки игры:
2901 FillByte(gGameSettings, SizeOf(TGameSettings), 0);
2902 gAimLine := False;
2903 gShowMap := False;
2904 gGameSettings.GameType := GT_SINGLE;
2905 gGameSettings.MaxLives := 0;
2906 gGameSettings.Options := gGameSettings.Options + GAME_OPTION_ALLOWEXIT;
2907 gGameSettings.Options := gGameSettings.Options + GAME_OPTION_MONSTERS;
2908 gGameSettings.Options := gGameSettings.Options + GAME_OPTION_BOTVSMONSTER;
2909 gGameSettings.Options := gGameSettings.Options + GAME_OPTION_TEAMHITPROJECTILE;
2910 gGameSettings.Options := gGameSettings.Options + GAME_OPTION_TEAMHITTRACE;
2911 gSwitchGameMode := GM_SINGLE;
2913 gLMSRespawn := LMS_RESPAWN_NONE;
2914 gLMSRespawnTime := 0;
2915 gSpectLatchPID1 := 0;
2916 gSpectLatchPID2 := 0;
2918 g_Game_ExecuteEvent('ongamestart');
2920 // Создание первого игрока:
2921 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
2922 gPlayer1Settings.Color,
2923 gPlayer1Settings.Team, False));
2924 if gPlayer1 = nil then
2925 begin
2926 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]));
2927 Exit;
2928 end;
2930 gPlayer1.Name := gPlayer1Settings.Name;
2931 gPlayer1.WeapSwitchMode := gPlayer1Settings.WeaponSwitch;
2932 gPlayer1.setWeaponPrefs(gPlayer1Settings.WeaponPreferences);
2933 gPlayer1.SwitchToEmpty := gPlayer1Settings.SwitchToEmpty;
2934 gPlayer1.SkipFist := gPlayer1Settings.SkipFist;
2935 nPl := 1;
2937 // Создание второго игрока, если есть:
2938 if TwoPlayers then
2939 begin
2940 gPlayer2 := g_Player_Get(g_Player_Create(gPlayer2Settings.Model,
2941 gPlayer2Settings.Color,
2942 gPlayer2Settings.Team, False));
2943 if gPlayer2 = nil then
2944 begin
2945 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [2]));
2946 Exit;
2947 end;
2949 gPlayer2.Name := gPlayer2Settings.Name;
2950 gPlayer2.WeapSwitchMode := gPlayer2Settings.WeaponSwitch;
2951 gPlayer2.setWeaponPrefs(gPlayer2Settings.WeaponPreferences);
2952 gPlayer2.SwitchToEmpty := gPlayer2Settings.SwitchToEmpty;
2953 gPlayer2.SkipFist := gPlayer2Settings.SkipFist;
2954 Inc(nPl);
2955 end;
2957 // Загрузка и запуск карты:
2958 if not g_Game_StartMap(false{asMegawad}, MAP, True) then
2959 begin
2960 if (Pos(':\', Map) > 0) or (Pos(':/', Map) > 0) then tmps := Map else tmps := gGameSettings.WAD + ':\' + MAP;
2961 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [tmps]));
2962 Exit;
2963 end;
2965 // Настройки игроков и ботов:
2966 g_Player_Init();
2968 // Создаем ботов:
2969 for i := nPl+1 to nPlayers do
2970 g_Player_Create(STD_PLAYER_MODEL, _RGB(0, 0, 0), 0, True);
2971 end;
2973 procedure g_Game_StartCustom(Map: String; GameMode: Byte;
2974 TimeLimit, ScoreLimit: Word;
2975 MaxLives: Byte;
2976 Options: LongWord; nPlayers: Byte);
2977 var
2978 i, nPl: Integer;
2979 begin
2980 g_Game_Free();
2982 e_WriteLog('Starting custom game...', TMsgType.Notify);
2984 g_Game_ClearLoading();
2986 // Настройки игры:
2987 gGameSettings.GameType := GT_CUSTOM;
2988 gGameSettings.GameMode := GameMode;
2989 gSwitchGameMode := GameMode;
2990 gGameSettings.TimeLimit := TimeLimit;
2991 gGameSettings.ScoreLimit := ScoreLimit;
2992 gGameSettings.MaxLives := IfThen(GameMode = GM_CTF, 0, MaxLives);
2993 gGameSettings.Options := Options;
2995 gCoopTotalMonstersKilled := 0;
2996 gCoopTotalSecretsFound := 0;
2997 gCoopTotalMonsters := 0;
2998 gCoopTotalSecrets := 0;
2999 gAimLine := False;
3000 gShowMap := False;
3002 gLMSRespawn := LMS_RESPAWN_NONE;
3003 gLMSRespawnTime := 0;
3004 gSpectLatchPID1 := 0;
3005 gSpectLatchPID2 := 0;
3007 g_Game_ExecuteEvent('ongamestart');
3009 // Режим наблюдателя:
3010 if nPlayers = 0 then
3011 begin
3012 gPlayer1 := nil;
3013 gPlayer2 := nil;
3014 end;
3016 nPl := 0;
3017 if nPlayers >= 1 then
3018 begin
3019 // Создание первого игрока:
3020 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
3021 gPlayer1Settings.Color,
3022 gPlayer1Settings.Team, False));
3023 if gPlayer1 = nil then
3024 begin
3025 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]));
3026 Exit;
3027 end;
3029 gPlayer1.Name := gPlayer1Settings.Name;
3030 gPlayer1.WeapSwitchMode := gPlayer1Settings.WeaponSwitch;
3031 gPlayer1.setWeaponPrefs(gPlayer1Settings.WeaponPreferences);
3032 gPlayer1.SwitchToEmpty := gPlayer1Settings.SwitchToEmpty;
3033 gPlayer1.SkipFist := gPlayer1Settings.SkipFist;
3034 Inc(nPl);
3035 end;
3037 if nPlayers >= 2 then
3038 begin
3039 // Создание второго игрока:
3040 gPlayer2 := g_Player_Get(g_Player_Create(gPlayer2Settings.Model,
3041 gPlayer2Settings.Color,
3042 gPlayer2Settings.Team, False));
3043 if gPlayer2 = nil then
3044 begin
3045 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [2]));
3046 Exit;
3047 end;
3049 gPlayer2.Name := gPlayer2Settings.Name;
3050 gPlayer2.WeapSwitchMode := gPlayer2Settings.WeaponSwitch;
3051 gPlayer2.setWeaponPrefs(gPlayer2Settings.WeaponPreferences);
3052 gPlayer2.SwitchToEmpty := gPlayer2Settings.SwitchToEmpty;
3053 gPlayer2.SkipFist := gPlayer2Settings.SkipFist;
3054 Inc(nPl);
3055 end;
3057 // Загрузка и запуск карты:
3058 if not g_Game_StartMap(true{asMegawad}, Map, True) then
3059 begin
3060 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [Map]));
3061 Exit;
3062 end;
3064 // Нет точек появления:
3065 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1) +
3066 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2) +
3067 g_Map_GetPointCount(RESPAWNPOINT_DM) +
3068 g_Map_GetPointCount(RESPAWNPOINT_RED)+
3069 g_Map_GetPointCount(RESPAWNPOINT_BLUE)) < 1 then
3070 begin
3071 g_FatalError(_lc[I_GAME_ERROR_GET_SPAWN]);
3072 Exit;
3073 end;
3075 // Настройки игроков и ботов:
3076 g_Player_Init();
3078 // Создаем ботов:
3079 for i := nPl+1 to nPlayers do
3080 g_Player_Create(STD_PLAYER_MODEL, _RGB(0, 0, 0), 0, True);
3081 end;
3083 procedure g_Game_StartServer(Map: String; GameMode: Byte;
3084 TimeLimit, ScoreLimit: Word; MaxLives: Byte;
3085 Options: LongWord; nPlayers: Byte;
3086 IPAddr: LongWord; Port: Word);
3087 begin
3088 g_Game_Free();
3089 g_Net_Slist_ServerClosed();
3091 e_WriteLog('Starting net game (server)...', TMsgType.Notify);
3093 g_Game_ClearLoading();
3095 ClearDebugCvars();
3097 // Настройки игры:
3098 gGameSettings.GameType := GT_SERVER;
3099 gGameSettings.GameMode := GameMode;
3100 gSwitchGameMode := GameMode;
3101 gGameSettings.TimeLimit := TimeLimit;
3102 gGameSettings.ScoreLimit := ScoreLimit;
3103 gGameSettings.MaxLives := IfThen(GameMode = GM_CTF, 0, MaxLives);
3104 gGameSettings.Options := Options;
3106 gCoopTotalMonstersKilled := 0;
3107 gCoopTotalSecretsFound := 0;
3108 gCoopTotalMonsters := 0;
3109 gCoopTotalSecrets := 0;
3110 gAimLine := False;
3111 gShowMap := False;
3113 gLMSRespawn := LMS_RESPAWN_NONE;
3114 gLMSRespawnTime := 0;
3115 gSpectLatchPID1 := 0;
3116 gSpectLatchPID2 := 0;
3118 g_Game_ExecuteEvent('ongamestart');
3120 // Режим наблюдателя:
3121 if nPlayers = 0 then
3122 begin
3123 gPlayer1 := nil;
3124 gPlayer2 := nil;
3125 end;
3127 if nPlayers >= 1 then
3128 begin
3129 // Создание первого игрока:
3130 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
3131 gPlayer1Settings.Color,
3132 gPlayer1Settings.Team, False));
3133 if gPlayer1 = nil then
3134 begin
3135 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]));
3136 Exit;
3137 end;
3139 gPlayer1.Name := gPlayer1Settings.Name;
3140 gPlayer1.WeapSwitchMode := gPlayer1Settings.WeaponSwitch;
3141 gPlayer1.setWeaponPrefs(gPlayer1Settings.WeaponPreferences);
3142 gPlayer1.SwitchToEmpty := gPlayer1Settings.SwitchToEmpty;
3143 gPlayer1.SkipFist := gPlayer1Settings.SkipFist;
3144 end;
3146 if nPlayers >= 2 then
3147 begin
3148 // Создание второго игрока:
3149 gPlayer2 := g_Player_Get(g_Player_Create(gPlayer2Settings.Model,
3150 gPlayer2Settings.Color,
3151 gPlayer2Settings.Team, False));
3152 if gPlayer2 = nil then
3153 begin
3154 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [2]));
3155 Exit;
3156 end;
3158 gPlayer2.Name := gPlayer2Settings.Name;
3159 gPlayer2.WeapSwitchMode := gPlayer2Settings.WeaponSwitch;
3160 gPlayer2.setWeaponPrefs(gPlayer2Settings.WeaponPreferences);
3161 gPlayer2.SwitchToEmpty := gPlayer2Settings.SwitchToEmpty;
3162 gPlayer2.SkipFist := gPlayer2Settings.SkipFist;
3163 end;
3165 g_Game_SetLoadingText(_lc[I_LOAD_HOST], 0, False);
3166 if NetForwardPorts then
3167 g_Game_SetLoadingText(_lc[I_LOAD_PORTS], 0, False);
3169 // Стартуем сервер
3170 if not g_Net_Host(IPAddr, Port, NetMaxClients) then
3171 begin
3172 g_FatalError(_lc[I_NET_MSG] + Format(_lc[I_NET_ERR_HOST], [Port]));
3173 Exit;
3174 end;
3176 g_Net_Slist_Set(NetMasterList);
3178 g_Net_Slist_ServerStarted();
3180 // Загрузка и запуск карты:
3181 if not g_Game_StartMap(false{asMegawad}, Map, True) then
3182 begin
3183 g_Net_Slist_ServerClosed();
3184 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [Map]));
3185 Exit;
3186 end;
3188 // Нет точек появления:
3189 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1) +
3190 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2) +
3191 g_Map_GetPointCount(RESPAWNPOINT_DM) +
3192 g_Map_GetPointCount(RESPAWNPOINT_RED)+
3193 g_Map_GetPointCount(RESPAWNPOINT_BLUE)) < 1 then
3194 begin
3195 g_Net_Slist_ServerClosed();
3196 g_FatalError(_lc[I_GAME_ERROR_GET_SPAWN]);
3197 Exit;
3198 end;
3200 // Настройки игроков и ботов:
3201 g_Player_Init();
3203 g_Net_Slist_ServerMapStarted();
3204 NetState := NET_STATE_GAME;
3205 end;
3207 procedure g_Game_StartClient(Addr: String; Port: Word; PW: String);
3208 var
3209 Map: String;
3210 WadName: string;
3211 Ptr: Pointer;
3212 T: Cardinal;
3213 MID: Byte;
3214 State: Byte;
3215 OuterLoop: Boolean;
3216 newResPath: string;
3217 InMsg: TMsg;
3218 begin
3219 g_Game_Free();
3221 State := 0;
3222 e_WriteLog('Starting net game (client)...', TMsgType.Notify);
3223 e_WriteLog('NET: Trying to connect to ' + Addr + ':' + IntToStr(Port) + '...', TMsgType.Notify);
3225 g_Game_ClearLoading();
3227 ClearDebugCvars();
3229 // Настройки игры:
3230 gGameSettings.GameType := GT_CLIENT;
3232 gCoopTotalMonstersKilled := 0;
3233 gCoopTotalSecretsFound := 0;
3234 gCoopTotalMonsters := 0;
3235 gCoopTotalSecrets := 0;
3236 gAimLine := False;
3237 gShowMap := False;
3239 g_Game_ExecuteEvent('ongamestart');
3241 NetState := NET_STATE_AUTH;
3243 g_Game_SetLoadingText(_lc[I_LOAD_CONNECT], 0, False);
3245 // create (or update) map/resource databases
3246 g_Res_CreateDatabases(true);
3248 gLMSRespawn := LMS_RESPAWN_NONE;
3249 gLMSRespawnTime := 0;
3250 gSpectLatchPID1 := 0;
3251 gSpectLatchPID2 := 0;
3253 // Стартуем клиент
3254 if not g_Net_Connect(Addr, Port) then
3255 begin
3256 g_FatalError(_lc[I_NET_MSG] + _lc[I_NET_ERR_CONN]);
3257 NetState := NET_STATE_NONE;
3258 Exit;
3259 end;
3261 g_Game_SetLoadingText(_lc[I_LOAD_SEND_INFO], 0, False);
3262 MC_SEND_Info(PW);
3263 g_Game_SetLoadingText(_lc[I_LOAD_WAIT_INFO], 0, False);
3265 OuterLoop := True;
3266 while OuterLoop do
3267 begin
3268 // fuck! https://www.mail-archive.com/enet-discuss@cubik.org/msg00852.html
3269 // tl;dr: on shitdows, we can get -1 sometimes, and it is *NOT* a failure.
3270 // thank you, enet. let's ignore failures altogether then.
3271 while (enet_host_service(NetHost, @NetEvent, 50) > 0) do
3272 begin
3273 if (NetEvent.kind = ENET_EVENT_TYPE_RECEIVE) then
3274 begin
3275 Ptr := NetEvent.packet^.data;
3276 if not InMsg.Init(Ptr, NetEvent.packet^.dataLength, True) then
3277 begin
3278 enet_packet_destroy(NetEvent.packet);
3279 continue;
3280 end;
3282 InMsg.ReadLongWord(); // skip size
3283 MID := InMsg.ReadByte();
3285 if (MID = NET_MSG_INFO) and (State = 0) then
3286 begin
3287 NetMyID := InMsg.ReadByte();
3288 NetPlrUID1 := InMsg.ReadWord();
3290 WadName := InMsg.ReadString();
3291 Map := InMsg.ReadString();
3293 gWADHash := InMsg.ReadMD5();
3295 gGameSettings.GameMode := InMsg.ReadByte();
3296 gSwitchGameMode := gGameSettings.GameMode;
3297 gGameSettings.ScoreLimit := InMsg.ReadWord();
3298 gGameSettings.TimeLimit := InMsg.ReadWord();
3299 gGameSettings.MaxLives := InMsg.ReadByte();
3300 gGameSettings.Options := InMsg.ReadLongWord();
3301 T := InMsg.ReadLongWord();
3303 //newResPath := g_Res_SearchSameWAD(MapsDir, WadName, gWADHash);
3304 //if newResPath = '' then
3305 begin
3306 //g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
3307 newResPath := g_Res_DownloadMapWAD(ExtractFileName(WadName), gWADHash);
3308 if newResPath = '' then
3309 begin
3310 g_FatalError(_lc[I_NET_ERR_HASH]);
3311 enet_packet_destroy(NetEvent.packet);
3312 NetState := NET_STATE_NONE;
3313 Exit;
3314 end;
3315 e_LogWritefln('using downloaded map wad [%s] for [%s]`', [newResPath, WadName], TMsgType.Notify);
3316 end;
3317 //newResPath := ExtractRelativePath(MapsDir, newResPath);
3320 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
3321 gPlayer1Settings.Color,
3322 gPlayer1Settings.Team, False));
3324 if gPlayer1 = nil then
3325 begin
3326 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]));
3328 enet_packet_destroy(NetEvent.packet);
3329 NetState := NET_STATE_NONE;
3330 Exit;
3331 end;
3333 gPlayer1.Name := gPlayer1Settings.Name;
3334 gPlayer1.WeapSwitchMode := gPlayer1Settings.WeaponSwitch;
3335 gPlayer1.setWeaponPrefs(gPlayer1Settings.WeaponPreferences);
3336 gPlayer1.SwitchToEmpty := gPlayer1Settings.SwitchToEmpty;
3337 gPlayer1.SkipFist := gPlayer1Settings.SkipFist;
3338 gPlayer1.UID := NetPlrUID1;
3339 gPlayer1.Reset(True);
3341 if not g_Game_StartMap(false{asMegawad}, newResPath + ':\' + Map, True) then
3342 begin
3343 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [WadName + ':\' + Map]));
3345 enet_packet_destroy(NetEvent.packet);
3346 NetState := NET_STATE_NONE;
3347 Exit;
3348 end;
3350 gTime := T;
3352 State := 1;
3353 OuterLoop := False;
3354 enet_packet_destroy(NetEvent.packet);
3355 break;
3356 end
3357 else
3358 enet_packet_destroy(NetEvent.packet);
3359 end
3360 else
3361 begin
3362 if (NetEvent.kind = ENET_EVENT_TYPE_DISCONNECT) then
3363 begin
3364 State := 0;
3365 if (NetEvent.data <= NET_DISC_MAX) then
3366 g_Console_Add(_lc[I_NET_MSG_ERROR] + _lc[I_NET_ERR_CONN] + ' ' +
3367 _lc[TStrings_Locale(Cardinal(I_NET_DISC_NONE) + NetEvent.data)], True);
3368 OuterLoop := False;
3369 Break;
3370 end;
3371 end;
3372 end;
3374 ProcessLoading(True);
3375 if g_Net_UserRequestExit() then
3376 begin
3377 State := 0;
3378 break;
3379 end;
3380 end;
3382 if State <> 1 then
3383 begin
3384 g_FatalError(_lc[I_NET_MSG] + _lc[I_NET_ERR_CONN]);
3385 NetState := NET_STATE_NONE;
3386 Exit;
3387 end;
3389 g_Player_Init();
3390 NetState := NET_STATE_GAME;
3391 MC_SEND_FullStateRequest;
3392 e_WriteLog('NET: Connection successful.', TMsgType.Notify);
3393 end;
3395 var
3396 lastAsMegaWad: Boolean = false;
3398 procedure g_Game_ChangeMap(const MapPath: String);
3399 var
3400 Force: Boolean;
3401 begin
3402 g_Game_ClearLoading();
3404 Force := gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF];
3405 // Если уровень завершился по триггеру Выход, не очищать инвентарь
3406 if gExitByTrigger then
3407 begin
3408 Force := False;
3409 gExitByTrigger := False;
3410 end;
3411 if not g_Game_StartMap(lastAsMegaWad, MapPath, Force) then
3412 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [MapPath]));
3413 end;
3415 procedure g_Game_Restart();
3416 var
3417 Map: string;
3418 begin
3419 if g_Game_IsClient then
3420 Exit;
3421 map := g_ExtractFileName(gMapInfo.Map);
3422 e_LogWritefln('g_Game_Restart: map = "%s" gCurrentMapFileName = "%s"', [map, gCurrentMapFileName]);
3424 MessageTime := 0;
3425 gGameOn := False;
3426 g_Game_ClearLoading();
3427 g_Game_StartMap(lastAsMegaWad, Map, True, gCurrentMapFileName);
3428 end;
3430 function g_Game_StartMap (asMegawad: Boolean; Map: String; Force: Boolean = False; const oldMapPath: AnsiString=''): Boolean;
3431 var
3432 NewWAD, ResName: String;
3433 I: Integer;
3434 nws: AnsiString;
3435 begin
3436 g_Map_Free((Map <> gCurrentMapFileName) and (oldMapPath <> gCurrentMapFileName));
3438 {$IFDEF ENABLE_GIBS}
3439 g_Gibs_RemoveAll;
3440 {$ENDIF}
3441 {$IFDEF ENABLE_SHELLS}
3442 g_Shells_RemoveAll;
3443 {$ENDIF}
3444 {$IFDEF ENABLE_CORPSES}
3445 g_Corpses_RemoveAll;
3446 {$ENDIF}
3448 if (not g_Game_IsClient) and
3449 (gSwitchGameMode <> gGameSettings.GameMode) and
3450 (gGameSettings.GameMode <> GM_SINGLE) then
3451 begin
3452 if gSwitchGameMode = GM_CTF then
3453 gGameSettings.MaxLives := 0;
3454 gGameSettings.GameMode := gSwitchGameMode;
3455 Force := True;
3456 end else
3457 gSwitchGameMode := gGameSettings.GameMode;
3459 g_Player_ResetTeams();
3461 lastAsMegaWad := asMegawad;
3462 if isWadPath(Map) then
3463 begin
3464 NewWAD := g_ExtractWadName(Map);
3465 ResName := g_ExtractFileName(Map);
3466 if g_Game_IsServer then
3467 begin
3468 nws := findDiskWad(NewWAD);
3469 //writeln('000: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
3470 if (asMegawad) then
3471 begin
3472 if (length(nws) = 0) then nws := e_FindWad(MegawadDirs, NewWAD);
3473 if (length(nws) = 0) then nws := e_FindWad(MapDirs, NewWAD);
3474 end
3475 else
3476 begin
3477 if (length(nws) = 0) then nws := e_FindWad(MapDirs, NewWAD);
3478 if (length(nws) = 0) then nws := e_FindWad(MegawadDirs, NewWAD);
3479 end;
3480 //if (length(nws) = 0) then nws := e_FindWad(MapDownloadDirs, NewWAD);
3481 //writeln('001: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
3482 //nws := NewWAD;
3483 if (length(nws) = 0) then
3484 begin
3485 ResName := ''; // failed
3486 end
3487 else
3488 begin
3489 NewWAD := nws;
3490 if (g_Game_IsNet) then gWADHash := MD5File(nws);
3491 //writeln('********: nws=', nws, ' : Map=', Map, ' : nw=', NewWAD, ' : resname=', ResName);
3492 g_Game_LoadWAD(NewWAD);
3493 end;
3494 end
3495 else
3496 begin
3497 // hash received in MC_RECV_GameEvent -> NET_EV_MAPSTART
3498 NewWAD := g_Game_ClientWAD(NewWAD, gWADHash);
3499 end;
3500 end
3501 else
3502 begin
3503 NewWAD := gGameSettings.WAD;
3504 ResName := Map;
3505 end;
3507 gTime := 0;
3509 //writeln('********: gsw=', gGameSettings.WAD, '; rn=', ResName);
3510 result := false;
3511 if (ResName <> '') and (NewWAD <> '') then
3512 begin
3513 //result := g_Map_Load(gGameSettings.WAD + ':\' + ResName);
3514 result := g_Map_Load(NewWAD+':\'+ResName);
3515 end;
3516 if Result then
3517 begin
3518 {$IFDEF ENABLE_RENDER}
3519 r_Render_LoadTextures;
3520 r_Render_Reset;
3521 {$ENDIF}
3522 g_Player_ResetAll(Force or gLastMap, gGameSettings.GameType = GT_SINGLE);
3524 gState := STATE_NONE;
3525 {$IFDEF ENABLE_MENU}
3526 g_ActiveWindow := nil;
3527 {$ENDIF}
3528 gGameOn := True;
3530 DisableCheats();
3531 wNeedTimeReset := True;
3533 if gGameSettings.GameMode = GM_CTF then
3534 begin
3535 g_Map_ResetFlag(FLAG_RED);
3536 g_Map_ResetFlag(FLAG_BLUE);
3537 // CTF, а флагов нет:
3538 if not g_Map_HaveFlagPoints() then
3539 g_SimpleError(_lc[I_GAME_ERROR_CTF]);
3540 end;
3541 end
3542 else
3543 begin
3544 gState := STATE_MENU;
3545 gGameOn := False;
3546 end;
3548 gExit := 0;
3549 gPauseMain := false;
3550 gPauseHolmes := false;
3551 NetTimeToUpdate := 1;
3552 NetTimeToReliable := 0;
3553 NetTimeToMaster := NetMasterRate;
3554 gSpectLatchPID1 := 0;
3555 gSpectLatchPID2 := 0;
3556 gMissionFailed := False;
3557 gNextMap := '';
3559 gCoopMonstersKilled := 0;
3560 gCoopSecretsFound := 0;
3562 gVoteInProgress := False;
3563 gVotePassed := False;
3564 gVoteCount := 0;
3565 gVoted := False;
3567 gStatsOff := False;
3569 if not gGameOn then Exit;
3571 g_Game_SpectateCenterView();
3573 if g_Game_IsServer then
3574 begin
3575 if (gGameSettings.MaxLives > 0) and (gGameSettings.WarmupTime > 0) then
3576 begin
3577 gLMSRespawn := LMS_RESPAWN_WARMUP;
3578 gLMSRespawnTime := gTime + gGameSettings.WarmupTime*1000;
3579 gLMSSoftSpawn := True;
3580 if g_Game_IsNet then
3581 MH_SEND_GameEvent(NET_EV_LMS_WARMUP, gLMSRespawnTime - gTime);
3582 end
3583 else
3584 begin
3585 gLMSRespawn := LMS_RESPAWN_NONE;
3586 gLMSRespawnTime := 0;
3587 end;
3588 end;
3590 if NetMode = NET_SERVER then
3591 begin
3592 // reset full state flags
3593 if NetClients <> nil then
3594 for I := 0 to High(NetClients) do
3595 NetClients[I].FullUpdateSent := False;
3597 MH_SEND_GameEvent(NET_EV_MAPSTART, gGameSettings.GameMode, Map);
3599 // Мастерсервер
3600 g_Net_Slist_ServerMapStarted();
3602 if NetClients <> nil then
3603 for I := 0 to High(NetClients) do
3604 if NetClients[I].Used then
3605 begin
3606 NetClients[I].Voted := False;
3607 if NetClients[I].RequestedFullUpdate then
3608 begin
3609 MH_SEND_Everything((NetClients[I].State = NET_STATE_AUTH), I);
3610 NetClients[I].RequestedFullUpdate := False;
3611 end;
3612 end;
3614 g_Net_UnbanNonPermHosts();
3615 end;
3617 if gLastMap then
3618 begin
3619 gCoopTotalMonstersKilled := 0;
3620 gCoopTotalSecretsFound := 0;
3621 gCoopTotalMonsters := 0;
3622 gCoopTotalSecrets := 0;
3623 gLastMap := False;
3624 end;
3626 g_Game_ExecuteEvent('onmapstart');
3627 end;
3629 procedure SetFirstLevel;
3630 begin
3631 gNextMap := '';
3633 MapList := g_Map_GetMapsList(gGameSettings.WAD);
3634 if MapList = nil then
3635 Exit;
3637 SortSArray(MapList);
3638 gNextMap := MapList[Low(MapList)];
3640 MapList := nil;
3641 end;
3643 procedure g_Game_ExitLevel(const Map: AnsiString);
3644 begin
3645 gNextMap := Map;
3647 gCoopTotalMonstersKilled := gCoopTotalMonstersKilled + gCoopMonstersKilled;
3648 gCoopTotalSecretsFound := gCoopTotalSecretsFound + gCoopSecretsFound;
3649 gCoopTotalMonsters := gCoopTotalMonsters + gTotalMonsters;
3650 gCoopTotalSecrets := gCoopTotalSecrets + gSecretsCount;
3652 // Вышли в выход в Одиночной игре:
3653 if gGameSettings.GameType = GT_SINGLE then
3654 gExit := EXIT_ENDLEVELSINGLE
3655 else // Вышли в выход в Своей игре
3656 begin
3657 gExit := EXIT_ENDLEVELCUSTOM;
3658 if gGameSettings.GameMode = GM_COOP then
3659 g_Player_RememberAll;
3661 if not g_Map_Exist(gGameSettings.WAD + ':\' + gNextMap) then
3662 begin
3663 gLastMap := True;
3664 if gGameSettings.GameMode = GM_COOP then
3665 gStatsOff := True;
3667 gStatsPressed := True;
3668 gNextMap := 'MAP01';
3670 if not g_Map_Exist(gGameSettings.WAD + ':\' + gNextMap) then
3671 g_Game_NextLevel;
3673 if g_Game_IsNet then
3674 begin
3675 MH_SEND_GameStats();
3676 MH_SEND_CoopStats();
3677 end;
3678 end;
3679 end;
3680 end;
3682 procedure g_Game_RestartLevel();
3683 var
3684 Map: string;
3685 begin
3686 if gGameSettings.GameMode = GM_SINGLE then
3687 begin
3688 g_Game_Restart();
3689 Exit;
3690 end;
3691 gExit := EXIT_ENDLEVELCUSTOM;
3692 Map := g_ExtractFileName(gMapInfo.Map);
3693 gNextMap := Map;
3694 end;
3696 function g_Game_ClientWAD (NewWAD: String; const WHash: TMD5Digest): AnsiString;
3697 var
3698 gWAD{, xwad}: String;
3699 begin
3700 result := NewWAD;
3701 if not g_Game_IsClient then Exit;
3702 //e_LogWritefln('*** g_Game_ClientWAD: `%s`', [NewWAD]);
3704 gWAD := g_Res_DownloadMapWAD(ExtractFileName(NewWAD), WHash);
3705 if gWAD = '' then
3706 begin
3707 result := '';
3708 g_Game_Free();
3709 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_WAD], [ExtractFileName(NewWAD)]));
3710 Exit;
3711 end;
3713 e_LogWritefln('using downloaded client map wad [%s] for [%s]', [gWAD, NewWAD], TMsgType.Notify);
3714 NewWAD := gWAD;
3716 g_Game_LoadWAD(NewWAD);
3717 result := NewWAD;
3720 if LowerCase(NewWAD) = LowerCase(gGameSettings.WAD) then Exit;
3721 gWAD := g_Res_SearchSameWAD(MapsDir, ExtractFileName(NewWAD), WHash);
3722 if gWAD = '' then
3723 begin
3724 g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
3725 gWAD := g_Res_DownloadMapWAD(ExtractFileName(NewWAD), WHash);
3726 if gWAD = '' then
3727 begin
3728 g_Game_Free();
3729 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_WAD], [ExtractFileName(NewWAD)]));
3730 Exit;
3731 end;
3732 end;
3733 NewWAD := ExtractRelativePath(MapsDir, gWAD);
3734 g_Game_LoadWAD(NewWAD);
3736 end;
3738 procedure g_Game_RestartRound(NoMapRestart: Boolean = False);
3739 var
3740 i, n, nb, nr: Integer;
3741 begin
3742 if not g_Game_IsServer then Exit;
3743 if gLMSRespawn = LMS_RESPAWN_NONE then Exit;
3744 gLMSRespawn := LMS_RESPAWN_NONE;
3745 gLMSRespawnTime := 0;
3746 MessageTime := 0;
3748 if (gGameSettings.GameMode = GM_COOP) and not NoMapRestart then
3749 begin
3750 gMissionFailed := True;
3751 g_Game_RestartLevel;
3752 Exit;
3753 end;
3755 n := 0; nb := 0; nr := 0;
3756 for i := Low(gPlayers) to High(gPlayers) do
3757 if (gPlayers[i] <> nil) and
3758 ((not gPlayers[i].FSpectator) or gPlayers[i].FWantsInGame or
3759 (gPlayers[i] is TBot)) then
3760 begin
3761 Inc(n);
3762 if gPlayers[i].Team = TEAM_RED then Inc(nr)
3763 else if gPlayers[i].Team = TEAM_BLUE then Inc(nb)
3764 end;
3766 if (n < 1) or ((gGameSettings.GameMode = GM_TDM) and ((nr = 0) or (nb = 0))) then
3767 begin
3768 // wait a second until the fuckers finally decide to join
3769 gLMSRespawn := LMS_RESPAWN_WARMUP;
3770 gLMSRespawnTime := gTime + gGameSettings.WarmupTime*1000;
3771 gLMSSoftSpawn := NoMapRestart;
3772 if g_Game_IsNet then
3773 MH_SEND_GameEvent(NET_EV_LMS_WARMUP, gLMSRespawnTime - gTime);
3774 Exit;
3775 end;
3777 {$IFDEF ENABLE_GIBS}
3778 g_Gibs_RemoveAll;
3779 {$ENDIF}
3780 {$IFDEF ENABLE_SHELLS}
3781 g_Shells_RemoveAll;
3782 {$ENDIF}
3783 {$IFDEF ENABLE_CORPSES}
3784 g_Corpses_RemoveAll;
3785 {$ENDIF}
3787 g_Game_Message(_lc[I_MESSAGE_LMS_START], 144);
3788 if g_Game_IsNet then
3789 MH_SEND_GameEvent(NET_EV_LMS_START);
3791 for i := Low(gPlayers) to High(gPlayers) do
3792 begin
3793 if gPlayers[i] = nil then continue;
3794 if gPlayers[i] is TBot then gPlayers[i].FWantsInGame := True;
3795 // don't touch normal spectators
3796 if gPlayers[i].FSpectator and not gPlayers[i].FWantsInGame then
3797 begin
3798 gPlayers[i].FNoRespawn := True;
3799 gPlayers[i].Lives := 0;
3800 if g_Game_IsNet then
3801 MH_SEND_PlayerStats(gPlayers[I].UID);
3802 continue;
3803 end;
3804 gPlayers[i].FNoRespawn := False;
3805 gPlayers[i].Lives := gGameSettings.MaxLives;
3806 gPlayers[i].Respawn(False, True);
3807 if gGameSettings.GameMode = GM_COOP then
3808 begin
3809 gPlayers[i].Frags := 0;
3810 gPlayers[i].RecallState;
3811 end;
3812 if (gPlayer1 = nil) and (gSpectLatchPID1 > 0) then
3813 gPlayer1 := g_Player_Get(gSpectLatchPID1);
3814 if (gPlayer2 = nil) and (gSpectLatchPID2 > 0) then
3815 gPlayer2 := g_Player_Get(gSpectLatchPID2);
3816 end;
3818 g_Items_RestartRound();
3820 gLMSSoftSpawn := False;
3821 end;
3823 function g_Game_GetFirstMap(WAD: String): String;
3824 begin
3825 Result := '';
3827 MapList := g_Map_GetMapsList(WAD);
3828 if MapList = nil then
3829 Exit;
3831 SortSArray(MapList);
3832 Result := MapList[Low(MapList)];
3834 if not g_Map_Exist(WAD + ':\' + Result) then
3835 Result := '';
3837 MapList := nil;
3838 end;
3840 function g_Game_GetNextMap(): String;
3841 var
3842 I: Integer;
3843 Map: string;
3844 begin
3845 Result := '';
3847 MapList := g_Map_GetMapsList(gGameSettings.WAD);
3848 if MapList = nil then
3849 Exit;
3851 Map := g_ExtractFileName(gMapInfo.Map);
3853 SortSArray(MapList);
3854 MapIndex := -255;
3855 for I := Low(MapList) to High(MapList) do
3856 if Map = MapList[I] then
3857 begin
3858 MapIndex := I;
3859 Break;
3860 end;
3862 if MapIndex <> -255 then
3863 begin
3864 if MapIndex = High(MapList) then
3865 Result := MapList[Low(MapList)]
3866 else
3867 Result := MapList[MapIndex + 1];
3869 if not g_Map_Exist(gGameSettings.WAD + ':\' + Result) then Result := Map;
3870 end;
3872 MapList := nil;
3873 end;
3875 procedure g_Game_NextLevel();
3876 begin
3877 if gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF, GM_COOP] then
3878 gExit := EXIT_ENDLEVELCUSTOM
3879 else
3880 begin
3881 gExit := EXIT_ENDLEVELSINGLE;
3882 Exit;
3883 end;
3885 if gNextMap <> '' then Exit;
3886 gNextMap := g_Game_GetNextMap();
3887 end;
3889 function g_Game_IsTestMap(): Boolean;
3890 begin
3891 result := StrEquCI1251(TEST_MAP_NAME, g_ExtractFileName(gMapInfo.Map));
3892 end;
3894 procedure g_Game_DeleteTestMap();
3895 var
3896 a: Integer;
3897 //MapName: AnsiString;
3898 WadName: string;
3900 WAD: TWADFile;
3901 MapList: SSArray;
3902 time: Integer;
3904 begin
3905 a := Pos('.wad:\', toLowerCase1251(gMapToDelete));
3906 if (a = 0) then a := Pos('.wad:/', toLowerCase1251(gMapToDelete));
3907 if (a = 0) then exit;
3909 // Выделяем имя wad-файла и имя карты
3910 WadName := Copy(gMapToDelete, 1, a+3);
3911 Delete(gMapToDelete, 1, a+5);
3912 gMapToDelete := UpperCase(gMapToDelete);
3913 //MapName := '';
3914 //CopyMemory(@MapName[0], @gMapToDelete[1], Min(16, Length(gMapToDelete)));
3917 // Имя карты не стандартное тестовое:
3918 if MapName <> TEST_MAP_NAME then
3919 Exit;
3921 if not gTempDelete then
3922 begin
3923 time := g_GetFileTime(WadName);
3924 WAD := TWADFile.Create();
3926 // Читаем Wad-файл:
3927 if not WAD.ReadFile(WadName) then
3928 begin // Нет такого WAD-файла
3929 WAD.Free();
3930 Exit;
3931 end;
3933 // Составляем список карт и ищем нужную:
3934 WAD.CreateImage();
3935 MapList := WAD.GetResourcesList('');
3937 if MapList <> nil then
3938 for a := 0 to High(MapList) do
3939 if MapList[a] = MapName then
3940 begin
3941 // Удаляем и сохраняем:
3942 WAD.RemoveResource('', MapName);
3943 WAD.SaveTo(WadName);
3944 Break;
3945 end;
3947 WAD.Free();
3948 g_SetFileTime(WadName, time);
3949 end else
3951 if gTempDelete then DeleteFile(WadName);
3952 end;
3954 procedure GameCVars(P: SSArray);
3955 var
3956 a, b: Integer;
3957 stat: TPlayerStatArray;
3958 cmd: string;
3960 procedure ParseGameFlag(Flag: LongWord; OffMsg, OnMsg: TStrings_Locale; OnMapChange: Boolean = False);
3961 var
3962 x: Boolean;
3963 begin
3964 if Length(P) > 1 then
3965 begin
3966 x := P[1] = '1';
3968 if x then
3969 gsGameFlags := gsGameFlags or Flag
3970 else
3971 gsGameFlags := gsGameFlags and (not Flag);
3973 if g_Game_IsServer then
3974 begin
3975 if x then
3976 gGameSettings.Options := gGameSettings.Options or Flag
3977 else
3978 gGameSettings.Options := gGameSettings.Options and (not Flag);
3979 if g_Game_IsNet then MH_SEND_GameSettings;
3980 end;
3981 end;
3983 if LongBool(gsGameFlags and Flag) then
3984 g_Console_Add(_lc[OnMsg])
3985 else
3986 g_Console_Add(_lc[OffMsg]);
3988 if OnMapChange and g_Game_IsServer then
3989 g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
3990 end;
3992 begin
3993 stat := nil;
3994 cmd := LowerCase(P[0]);
3996 if cmd = 'g_gamemode' then
3997 begin
3998 if (Length(P) > 1) then
3999 begin
4000 a := g_Game_TextToMode(P[1]);
4001 if a = GM_SINGLE then a := GM_COOP;
4002 gsGameMode := g_Game_ModeToText(a);
4003 if g_Game_IsServer then
4004 begin
4005 gSwitchGameMode := a;
4006 if (gGameOn and (gGameSettings.GameMode = GM_SINGLE)) or
4007 (gState = STATE_INTERSINGLE) then
4008 gSwitchGameMode := GM_SINGLE;
4009 if not gGameOn then
4010 gGameSettings.GameMode := gSwitchGameMode;
4011 end;
4012 end;
4014 if gSwitchGameMode = gGameSettings.GameMode then
4015 g_Console_Add(Format(_lc[I_MSG_GAMEMODE_CURRENT],
4016 [g_Game_ModeToText(gGameSettings.GameMode)]))
4017 else
4018 g_Console_Add(Format(_lc[I_MSG_GAMEMODE_CHANGE],
4019 [g_Game_ModeToText(gGameSettings.GameMode),
4020 g_Game_ModeToText(gSwitchGameMode)]));
4021 end
4022 else if cmd = 'g_friendlyfire' then
4023 begin
4024 ParseGameFlag(GAME_OPTION_TEAMDAMAGE, I_MSG_FRIENDLY_FIRE_OFF, I_MSG_FRIENDLY_FIRE_ON);
4025 end
4026 else if cmd = 'g_friendly_absorb_damage' then
4027 begin
4028 ParseGameFlag(GAME_OPTION_TEAMABSORBDAMAGE, I_MSG_FRIENDLY_ABSORB_DAMAGE_OFF, I_MSG_FRIENDLY_ABSORB_DAMAGE_ON);
4029 end
4030 else if cmd = 'g_friendly_hit_trace' then
4031 begin
4032 ParseGameFlag(GAME_OPTION_TEAMHITTRACE, I_MSG_FRIENDLY_HIT_TRACE_OFF, I_MSG_FRIENDLY_HIT_TRACE_ON);
4033 end
4034 else if cmd = 'g_friendly_hit_projectile' then
4035 begin
4036 ParseGameFlag(GAME_OPTION_TEAMHITPROJECTILE, I_MSG_FRIENDLY_PROJECT_TRACE_OFF, I_MSG_FRIENDLY_PROJECT_TRACE_ON);
4037 end
4038 else if cmd = 'g_weaponstay' then
4039 begin
4040 ParseGameFlag(GAME_OPTION_WEAPONSTAY, I_MSG_WEAPONSTAY_OFF, I_MSG_WEAPONSTAY_ON);
4041 end
4042 else if cmd = 'g_allow_exit' then
4043 begin
4044 ParseGameFlag(GAME_OPTION_ALLOWEXIT, I_MSG_ALLOWEXIT_OFF, I_MSG_ALLOWEXIT_ON, True);
4045 end
4046 else if cmd = 'g_allow_monsters' then
4047 begin
4048 ParseGameFlag(GAME_OPTION_MONSTERS, I_MSG_ALLOWMON_OFF, I_MSG_ALLOWMON_ON, True);
4049 end
4050 else if cmd = 'g_allow_dropflag' then
4051 begin
4052 ParseGameFlag(GAME_OPTION_ALLOWDROPFLAG, I_MSG_ALLOWDROPFLAG_OFF, I_MSG_ALLOWDROPFLAG_ON);
4053 end
4054 else if cmd = 'g_throw_flag' then
4055 begin
4056 ParseGameFlag(GAME_OPTION_THROWFLAG, I_MSG_THROWFLAG_OFF, I_MSG_THROWFLAG_ON);
4057 end
4058 else if cmd = 'g_bot_vsplayers' then
4059 begin
4060 ParseGameFlag(GAME_OPTION_BOTVSPLAYER, I_MSG_BOTSVSPLAYERS_OFF, I_MSG_BOTSVSPLAYERS_ON);
4061 end
4062 else if cmd = 'g_bot_vsmonsters' then
4063 begin
4064 ParseGameFlag(GAME_OPTION_BOTVSMONSTER, I_MSG_BOTSVSMONSTERS_OFF, I_MSG_BOTSVSMONSTERS_ON);
4065 end
4066 else if cmd = 'g_dm_keys' then
4067 begin
4068 ParseGameFlag(GAME_OPTION_DMKEYS, I_MSG_DMKEYS_OFF, I_MSG_DMKEYS_ON, True);
4069 end
4070 else if cmd = 'g_gameflags' then
4071 begin
4072 if Length(P) > 1 then
4073 begin
4074 gsGameFlags := StrToDWordDef(P[1], gsGameFlags);
4075 if g_Game_IsServer then
4076 begin
4077 gGameSettings.Options := gsGameFlags;
4078 if g_Game_IsNet then MH_SEND_GameSettings;
4079 end;
4080 end;
4082 g_Console_Add(Format('%s %u', [cmd, gsGameFlags]));
4083 end
4084 else if cmd = 'g_warmup_time' then
4085 begin
4086 if Length(P) > 1 then
4087 begin
4088 gsWarmupTime := nclamp(StrToIntDef(P[1], gsWarmupTime), 0, $FFFF);
4089 if g_Game_IsServer then
4090 begin
4091 gGameSettings.WarmupTime := gsWarmupTime;
4092 // extend warmup if it's already going
4093 if gLMSRespawn = LMS_RESPAWN_WARMUP then
4094 begin
4095 gLMSRespawnTime := gTime + gsWarmupTime * 1000;
4096 if g_Game_IsNet then MH_SEND_GameEvent(NET_EV_LMS_WARMUP, gLMSRespawnTime - gTime);
4097 end;
4098 if g_Game_IsNet then MH_SEND_GameSettings;
4099 end;
4100 end;
4102 g_Console_Add(Format(_lc[I_MSG_WARMUP], [Integer(gsWarmupTime)]));
4103 if g_Game_IsServer then g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
4104 end
4105 else if cmd = 'g_spawn_invul' then
4106 begin
4107 if Length(P) > 1 then
4108 begin
4109 gsSpawnInvul := nclamp(StrToIntDef(P[1], gsSpawnInvul), 0, $FFFF);
4110 if g_Game_IsServer then
4111 begin
4112 gGameSettings.SpawnInvul := gsSpawnInvul;
4113 if g_Game_IsNet then MH_SEND_GameSettings;
4114 end;
4115 end;
4117 g_Console_Add(Format('%s %d', [cmd, Integer(gsSpawnInvul)]));
4118 end
4119 else if cmd = 'g_item_respawn_time' then
4120 begin
4121 if Length(P) > 1 then
4122 begin
4123 gsItemRespawnTime := nclamp(StrToIntDef(P[1], gsItemRespawnTime), 0, $FFFF);
4124 if g_Game_IsServer then
4125 begin
4126 gGameSettings.ItemRespawnTime := gsItemRespawnTime;
4127 if g_Game_IsNet then MH_SEND_GameSettings;
4128 end;
4129 end;
4131 g_Console_Add(Format('%s %d', [cmd, Integer(gsItemRespawnTime)]));
4132 if g_Game_IsServer then g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
4133 end
4134 else if cmd = 'sv_intertime' then
4135 begin
4136 if (Length(P) > 1) then
4137 gDefInterTime := Min(Max(StrToIntDef(P[1], gDefInterTime), -1), 120);
4139 g_Console_Add(cmd + ' = ' + IntToStr(gDefInterTime));
4140 end
4141 else if cmd = 'g_max_particles' then
4142 begin
4143 if Length(p) = 2 then
4144 begin
4145 {$IFDEF ENABLE_GFX}
4146 a := Max(0, StrToIntDef(p[1], 0));
4147 g_GFX_SetMax(a)
4148 {$ENDIF}
4149 end
4150 else if Length(p) = 1 then
4151 begin
4152 {$IFDEF ENABLE_GFX}
4153 e_LogWritefln('%s', [g_GFX_GetMax()])
4154 {$ELSE}
4155 e_LogWritefln('%s', [0])
4156 {$ENDIF}
4157 end
4158 else
4159 begin
4160 e_LogWritefln('usage: %s <n>', [cmd])
4161 end
4162 end
4163 else if cmd = 'g_max_shells' then
4164 begin
4165 if Length(p) = 2 then
4166 begin
4167 {$IFDEF ENABLE_SHELLS}
4168 a := Max(0, StrToIntDef(p[1], 0));
4169 g_Shells_SetMax(a)
4170 {$ENDIF}
4171 end
4172 else if Length(p) = 1 then
4173 begin
4174 {$IFDEF ENABLE_SHELLS}
4175 e_LogWritefln('%s', [g_Shells_GetMax()])
4176 {$ELSE}
4177 e_LogWritefln('%s', [0])
4178 {$ENDIF}
4179 end
4180 else
4181 begin
4182 e_LogWritefln('usage: %s <n>', [cmd])
4183 end
4184 end
4185 else if cmd = 'g_max_gibs' then
4186 begin
4187 if Length(p) = 2 then
4188 begin
4189 {$IFDEF ENABLE_GIBS}
4190 a := Max(0, StrToIntDef(p[1], 0));
4191 g_Gibs_SetMax(a)
4192 {$ENDIF}
4193 end
4194 else if Length(p) = 1 then
4195 begin
4196 {$IFDEF ENABLE_GIBS}
4197 e_LogWritefln('%s', [g_Gibs_GetMax()])
4198 {$ELSE}
4199 e_LogWritefln('%s', [0])
4200 {$ENDIF}
4201 end
4202 else
4203 begin
4204 e_LogWritefln('usage: %s <n>', [cmd])
4205 end
4206 end
4207 else if cmd = 'g_max_corpses' then
4208 begin
4209 if Length(p) = 2 then
4210 begin
4211 {$IFDEF ENABLE_CORPSES}
4212 a := Max(0, StrToIntDef(p[1], 0));
4213 g_Corpses_SetMax(a)
4214 {$ENDIF}
4215 end
4216 else if Length(p) = 1 then
4217 begin
4218 {$IFDEF ENABLE_CORPSES}
4219 e_LogWritefln('%s', [g_Corpses_GetMax()])
4220 {$ELSE}
4221 e_LogWritefln('%s', [0])
4222 {$ENDIF}
4223 end
4224 else
4225 begin
4226 e_LogWritefln('usage: %s <n>', [cmd])
4227 end
4228 end
4229 else if cmd = 'g_force_model' then
4230 begin
4231 if Length(p) = 2 then
4232 begin
4233 a := StrToIntDef(p[1], 0);
4234 g_Force_Model_Set(a);
4235 if (g_Force_Model_Get() <> 0) and (gPlayers <> nil) then
4236 begin
4237 for a := Low(gPlayers) to High(gPlayers) do
4238 begin
4239 if (gPlayers[a] <> nil) then
4240 begin
4241 if (gPlayers[a].UID = gPlayer1.UID) then
4242 continue
4243 else if (gPlayer2 <> nil) and (gPlayers[a].UID = gPlayer2.UID) then
4244 continue;
4245 gPlayers[a].setModel(g_Forced_Model_GetName());
4246 end;
4247 end
4248 end
4249 else if (g_Force_Model_Get() = 0) and (gPlayers <> nil) then
4250 begin
4251 for a := Low(gPlayers) to High(gPlayers) do
4252 begin
4253 if (gPlayers[a] <> nil) then
4254 begin
4255 if (gPlayers[a].UID = gPlayer1.UID) then
4256 continue
4257 else if (gPlayer2 <> nil) and (gPlayers[a].UID = gPlayer2.UID) then
4258 continue;
4259 gPlayers[a].setModel(gPlayers[a].FActualModelName);
4260 end;
4261 end
4262 end
4263 end
4264 end
4265 else if cmd = 'g_force_model_name' then
4266 begin
4267 if (Length(P) > 1) then
4268 begin
4269 cmd := b_Text_Unformat(P[1]);
4270 g_Forced_Model_SetName(cmd);
4271 if (g_Force_Model_Get() <> 0) and (gPlayers <> nil) then
4272 begin
4273 for a := Low(gPlayers) to High(gPlayers) do
4274 begin
4275 if (gPlayers[a] <> nil) then
4276 begin
4277 if (gPlayers[a].UID = gPlayer1.UID) then
4278 continue
4279 else if (gPlayer2 <> nil) and (gPlayers[a].UID = gPlayer2.UID) then
4280 continue;
4281 gPlayers[a].setModel(g_Forced_Model_GetName());
4282 end;
4283 end
4284 end
4285 end
4286 end
4287 else if cmd = 'g_scorelimit' then
4288 begin
4289 if Length(P) > 1 then
4290 begin
4291 gsScoreLimit := nclamp(StrToIntDef(P[1], gsScoreLimit), 0, $FFFF);
4293 if g_Game_IsServer then
4294 begin
4295 b := 0;
4296 if gGameSettings.GameMode = GM_DM then
4297 begin // DM
4298 stat := g_Player_GetStats();
4299 if stat <> nil then
4300 for a := 0 to High(stat) do
4301 if stat[a].Frags > b then
4302 b := stat[a].Frags;
4303 end
4304 else // TDM/CTF
4305 b := Max(gTeamStat[TEAM_RED].Score, gTeamStat[TEAM_BLUE].Score);
4307 // if someone has a higher score, set it to that instead
4308 gsScoreLimit := max(gsScoreLimit, b);
4309 gGameSettings.ScoreLimit := gsScoreLimit;
4311 if g_Game_IsNet then MH_SEND_GameSettings;
4312 end;
4313 end;
4315 g_Console_Add(Format(_lc[I_MSG_SCORE_LIMIT], [Integer(gsScoreLimit)]));
4316 end
4317 else if cmd = 'g_timelimit' then
4318 begin
4319 if Length(P) > 1 then
4320 begin
4321 gsTimeLimit := nclamp(StrToIntDef(P[1], gsTimeLimit), 0, $FFFF);
4322 if g_Game_IsServer then
4323 begin
4324 gGameSettings.TimeLimit := gsTimeLimit;
4325 if g_Game_IsNet then MH_SEND_GameSettings;
4326 end;
4327 end;
4328 g_Console_Add(Format(_lc[I_MSG_TIME_LIMIT],
4329 [gsTimeLimit div 3600,
4330 (gsTimeLimit div 60) mod 60,
4331 gsTimeLimit mod 60]));
4332 end
4333 else if cmd = 'g_max_bots' then
4334 begin
4335 if Length(P) > 1 then
4336 gMaxBots := nclamp(StrToIntDef(P[1], gMaxBots), 0, 127);
4337 g_Console_Add('g_max_bots = ' + IntToStr(gMaxBots));
4338 end
4339 else if cmd = 'g_maxlives' then
4340 begin
4341 if Length(P) > 1 then
4342 begin
4343 gsMaxLives := nclamp(StrToIntDef(P[1], gsMaxLives), 0, $FFFF);
4344 if g_Game_IsServer then
4345 begin
4346 gGameSettings.MaxLives := gsMaxLives;
4347 if g_Game_IsNet then MH_SEND_GameSettings;
4348 end;
4349 end;
4351 g_Console_Add(Format(_lc[I_MSG_LIVES], [Integer(gsMaxLives)]));
4352 end;
4353 end;
4355 procedure PlayerSettingsCVars(P: SSArray);
4356 var
4357 cmd: string;
4358 team: Byte;
4360 function ParseTeam(s: string): Byte;
4361 begin
4362 result := 0;
4363 case s of
4364 'red', '1': result := TEAM_RED;
4365 'blue', '2': result := TEAM_BLUE;
4366 else result := TEAM_NONE;
4367 end;
4368 end;
4369 begin
4370 cmd := LowerCase(P[0]);
4371 case cmd of
4372 'p1_name':
4373 begin
4374 if (Length(P) > 1) then
4375 begin
4376 gPlayer1Settings.Name := b_Text_Unformat(P[1]);
4377 if g_Game_IsClient then
4378 MC_SEND_PlayerSettings
4379 else if gGameOn and (gPlayer1 <> nil) then
4380 begin
4381 gPlayer1.Name := b_Text_Unformat(P[1]);
4382 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer1.UID);
4383 end;
4384 end;
4385 end;
4386 'p2_name':
4387 begin
4388 if (Length(P) > 1) then
4389 begin
4390 gPlayer2Settings.Name := b_Text_Unformat(P[1]);
4391 if g_Game_IsClient then
4392 MC_SEND_PlayerSettings
4393 else if gGameOn and (gPlayer2 <> nil) then
4394 begin
4395 gPlayer2.Name := b_Text_Unformat(P[1]);
4396 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer2.UID);
4397 end;
4398 end;
4399 end;
4400 'p1_color':
4401 begin
4402 if Length(P) > 3 then
4403 begin
4404 gPlayer1Settings.Color := _RGB(EnsureRange(StrToIntDef(P[1], 0), 0, 255),
4405 EnsureRange(StrToIntDef(P[2], 0), 0, 255),
4406 EnsureRange(StrToIntDef(P[3], 0), 0, 255));
4407 if g_Game_IsClient then
4408 MC_SEND_PlayerSettings
4409 else if gGameOn and (gPlayer1 <> nil) then
4410 begin
4411 gPlayer1.SetColor(gPlayer1Settings.Color);
4412 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer1.UID);
4413 end;
4414 end;
4415 end;
4416 'p2_color':
4417 begin
4418 if Length(P) > 3 then
4419 begin
4420 gPlayer2Settings.Color := _RGB(EnsureRange(StrToIntDef(P[1], 0), 0, 255),
4421 EnsureRange(StrToIntDef(P[2], 0), 0, 255),
4422 EnsureRange(StrToIntDef(P[3], 0), 0, 255));
4423 if g_Game_IsClient then
4424 MC_SEND_PlayerSettings
4425 else if gGameOn and (gPlayer2 <> nil) then
4426 begin
4427 gPlayer2.SetColor(gPlayer2Settings.Color);
4428 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer2.UID);
4429 end;
4430 end;
4431 end;
4432 'p1_model':
4433 begin
4434 if (Length(P) > 1) then
4435 begin
4436 gPlayer1Settings.Model := P[1];
4437 if g_Game_IsClient then
4438 MC_SEND_PlayerSettings
4439 else if gGameOn and (gPlayer1 <> nil) then
4440 begin
4441 gPlayer1.FActualModelName := gPlayer1Settings.Model;
4442 gPlayer1.SetModel(gPlayer1Settings.Model);
4443 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer1.UID);
4444 end;
4445 end;
4446 end;
4447 'p2_model':
4448 begin
4449 if (Length(P) > 1) then
4450 begin
4451 gPlayer2Settings.Model := P[1];
4452 if g_Game_IsClient then
4453 MC_SEND_PlayerSettings
4454 else if gGameOn and (gPlayer2 <> nil) then
4455 begin
4456 gPlayer2.FActualModelName := gPlayer2Settings.Model;
4457 gPlayer2.SetModel(gPlayer2Settings.Model);
4458 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer2.UID);
4459 end;
4460 end;
4461 end;
4462 'p1_team':
4463 begin
4464 // TODO: switch teams if in game or store this separately
4465 if (Length(P) > 1) then
4466 begin
4467 team := ParseTeam(P[1]);
4468 if team = TEAM_NONE then
4469 g_Console_Add('expected ''red'', ''blue'', 1 or 2')
4470 else if not gGameOn and not g_Game_IsNet then
4471 gPlayer1Settings.Team := team
4472 else
4473 g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
4474 end;
4475 end;
4476 'p2_team':
4477 begin
4478 // TODO: switch teams if in game or store this separately
4479 if (Length(P) > 1) then
4480 begin
4481 team := ParseTeam(P[1]);
4482 if team = TEAM_NONE then
4483 g_Console_Add('expected ''red'', ''blue'', 1 or 2')
4484 else if not gGameOn and not g_Game_IsNet then
4485 gPlayer2Settings.Team := team
4486 else
4487 g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
4488 end;
4489 end;
4490 'p1_autoswitch':
4491 begin
4492 if (Length(P) = 2) then
4493 gPlayer1Settings.WeaponSwitch := EnsureRange(StrTointDef(P[1], 0), 0, 2);
4494 end;
4495 'p2_autoswitch':
4496 begin
4497 if (Length(P) = 2) then
4498 gPlayer2Settings.WeaponSwitch := EnsureRange(StrTointDef(P[1], 0), 0, 2);
4499 end;
4500 'p1_switch_empty':
4501 begin
4502 if (Length(P) = 2) then
4503 gPlayer1Settings.SwitchToEmpty := EnsureRange(StrTointDef(P[1], 0), 0, 1);
4504 end;
4505 'p2_switch_empty':
4506 begin
4507 if (Length(P) = 2) then
4508 gPlayer2Settings.SwitchToEmpty := EnsureRange(StrTointDef(P[1], 0), 0, 1);
4509 end;
4510 'p1_skip_fist':
4511 begin
4512 if (Length(P) = 2) then
4513 gPlayer1Settings.SkipFist := EnsureRange(StrTointDef(P[1], 0), 0, 1);
4514 end;
4515 'p2_skip_fist':
4516 begin
4517 if (Length(P) = 2) then
4518 gPlayer2Settings.SkipFist := EnsureRange(StrTointDef(P[1], 0), 0, 1);
4519 end;
4520 'p1_priority_kastet':
4521 begin
4522 if (Length(P) = 2) then
4523 gPlayer1Settings.WeaponPreferences[WEAPON_KASTET] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
4524 end;
4525 'p2_priority_kastet':
4526 begin
4527 if (Length(P) = 2) then
4528 gPlayer2Settings.WeaponPreferences[WEAPON_KASTET] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
4529 end;
4530 'p1_priority_saw':
4531 begin
4532 if (Length(P) = 2) then
4533 gPlayer1Settings.WeaponPreferences[WEAPON_SAW] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
4534 end;
4535 'p2_priority_saw':
4536 begin
4537 if (Length(P) = 2) then
4538 gPlayer2Settings.WeaponPreferences[WEAPON_SAW] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
4539 end;
4540 'p1_priority_pistol':
4541 begin
4542 if (Length(P) = 2) then
4543 gPlayer1Settings.WeaponPreferences[WEAPON_KASTET] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
4544 end;
4545 'p2_priority_pistol':
4546 begin
4547 if (Length(P) = 2) then
4548 gPlayer2Settings.WeaponPreferences[WEAPON_KASTET] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
4549 end;
4550 'p1_priority_shotgun1':
4551 begin
4552 if (Length(P) = 2) then
4553 gPlayer1Settings.WeaponPreferences[WEAPON_SHOTGUN1] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
4554 end;
4555 'p2_priority_shotgun1':
4556 begin
4557 if (Length(P) = 2) then
4558 gPlayer2Settings.WeaponPreferences[WEAPON_SHOTGUN1] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
4559 end;
4560 'p1_priority_shotgun2':
4561 begin
4562 if (Length(P) = 2) then
4563 gPlayer1Settings.WeaponPreferences[WEAPON_SHOTGUN2] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
4564 end;
4565 'p2_priority_shotgun2':
4566 begin
4567 if (Length(P) = 2) then
4568 gPlayer2Settings.WeaponPreferences[WEAPON_SHOTGUN2] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
4569 end;
4570 'p1_priority_chaingun':
4571 begin
4572 if (Length(P) = 2) then
4573 gPlayer1Settings.WeaponPreferences[WEAPON_CHAINGUN] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
4574 end;
4575 'p2_priority_chaingun':
4576 begin
4577 if (Length(P) = 2) then
4578 gPlayer2Settings.WeaponPreferences[WEAPON_CHAINGUN] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
4579 end;
4580 'p1_priority_rocketlauncher':
4581 begin
4582 if (Length(P) = 2) then
4583 gPlayer1Settings.WeaponPreferences[WEAPON_ROCKETLAUNCHER] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
4584 end;
4585 'p2_priority_rocketlauncher':
4586 begin
4587 if (Length(P) = 2) then
4588 gPlayer2Settings.WeaponPreferences[WEAPON_ROCKETLAUNCHER] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
4589 end;
4590 'p1_priority_plasma':
4591 begin
4592 if (Length(P) = 2) then
4593 gPlayer1Settings.WeaponPreferences[WEAPON_PLASMA] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
4594 end;
4595 'p2_priority_plasma':
4596 begin
4597 if (Length(P) = 2) then
4598 gPlayer2Settings.WeaponPreferences[WEAPON_PLASMA] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
4599 end;
4600 'p1_priority_bfg':
4601 begin
4602 if (Length(P) = 2) then
4603 gPlayer1Settings.WeaponPreferences[WEAPON_BFG] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
4604 end;
4605 'p2_priority_bfg':
4606 begin
4607 if (Length(P) = 2) then
4608 gPlayer2Settings.WeaponPreferences[WEAPON_BFG] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
4609 end;
4610 'p1_priority_super':
4611 begin
4612 if (Length(P) = 2) then
4613 gPlayer1Settings.WeaponPreferences[WEAPON_SUPERPULEMET] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
4614 end;
4615 'p2_priority_super':
4616 begin
4617 if (Length(P) = 2) then
4618 gPlayer2Settings.WeaponPreferences[WEAPON_SUPERPULEMET] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
4619 end;
4620 'p1_priority_flamethrower':
4621 begin
4622 if (Length(P) = 2) then
4623 gPlayer1Settings.WeaponPreferences[WEAPON_FLAMETHROWER] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
4624 end;
4625 'p2_priority_flamethrower':
4626 begin
4627 if (Length(P) = 2) then
4628 gPlayer2Settings.WeaponPreferences[WEAPON_FLAMETHROWER] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
4629 end;
4630 'p1_priority_berserk':
4631 begin
4632 if (Length(P) = 2) then
4633 gPlayer1Settings.WeaponPreferences[WP_LAST+1] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
4634 end;
4635 'p2_priority_berserk':
4636 begin
4637 if (Length(P) = 2) then
4638 gPlayer2Settings.WeaponPreferences[WP_LAST+1] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
4639 end;
4640 end;
4641 end;
4643 procedure PrintHeapStats();
4644 var
4645 hs: TFPCHeapStatus;
4646 begin
4647 hs := GetFPCHeapStatus();
4648 e_LogWriteLn ('v===== heap status =====v');
4649 e_LogWriteFln('max heap size = %d k', [hs.MaxHeapSize div 1024]);
4650 e_LogWriteFln('max heap used = %d k', [hs.MaxHeapUsed div 1024]);
4651 e_LogWriteFln('cur heap size = %d k', [hs.CurrHeapSize div 1024]);
4652 e_LogWriteFln('cur heap used = %d k', [hs.CurrHeapUsed div 1024]);
4653 e_LogWriteFln('cur heap free = %d k', [hs.CurrHeapFree div 1024]);
4654 e_LogWriteLn ('^=======================^');
4655 end;
4657 procedure DebugCommands(P: SSArray);
4658 var
4659 a, b: Integer;
4660 cmd: string;
4661 //pt: TDFPoint;
4662 mon: TMonster;
4663 begin
4664 // Команды отладочного режима:
4665 if {gDebugMode}conIsCheatsEnabled then
4666 begin
4667 cmd := LowerCase(P[0]);
4668 if cmd = 'd_window' then
4669 begin
4670 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth, gScreenHeight]));
4671 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth, gScreenHeight]));
4672 end
4673 else if cmd = 'd_winmsg' then
4674 begin
4675 if (Length(P) > 1) and
4676 ((P[1] = '1') or (P[1] = '0')) then
4677 g_Debug_WinMsgs := (P[1][1] = '1');
4679 g_Console_Add(Format('d_winmsg is %d', [Byte(g_Debug_WinMsgs)]));
4680 end
4681 else if (cmd = 'd_monoff') and not g_Game_IsNet then
4682 begin
4683 if (Length(P) > 1) and
4684 ((P[1] = '1') or (P[1] = '0')) then
4685 g_Debug_MonsterOff := (P[1][1] = '1');
4687 g_Console_Add(Format('d_monoff is %d', [Byte(g_debug_MonsterOff)]));
4688 end
4689 else if (cmd = 'd_botoff') and not g_Game_IsNet then
4690 begin
4691 if Length(P) > 1 then
4692 case P[1][1] of
4693 '0': g_debug_BotAIOff := 0;
4694 '1': g_debug_BotAIOff := 1;
4695 '2': g_debug_BotAIOff := 2;
4696 '3': g_debug_BotAIOff := 3;
4697 end;
4699 g_Console_Add(Format('d_botoff is %d', [g_debug_BotAIOff]));
4700 end
4701 else if cmd = 'd_monster' then
4702 begin
4703 if gGameOn and (gPlayer1 <> nil) and (gPlayer1.alive) and (not g_Game_IsNet) then
4704 if Length(P) < 2 then
4705 begin
4706 g_Console_Add(cmd + ' [ID | Name] [behaviour]');
4707 g_Console_Add('ID | Name');
4708 for b := MONSTER_DEMON to MONSTER_MAN do
4709 g_Console_Add(Format('%2d | %s', [b, g_Mons_NameByTypeId(b)]));
4710 conwriteln('behav. num'#10'normal 0'#10'killer 1'#10'maniac 2'#10'insane 3'#10'cannibal 4'#10'good 5');
4711 end else
4712 begin
4713 a := StrToIntDef(P[1], 0);
4714 if (a < MONSTER_DEMON) or (a > MONSTER_MAN) then
4715 a := g_Mons_TypeIdByName(P[1]);
4717 if (a < MONSTER_DEMON) or (a > MONSTER_MAN) then
4718 g_Console_Add(Format(_lc[I_MSG_NO_MONSTER], [P[1]]))
4719 else
4720 begin
4721 with gPlayer1.Obj do
4722 begin
4723 mon := g_Monsters_Create(a,
4724 X + Rect.X + (Rect.Width div 2),
4725 Y + Rect.Y + Rect.Height,
4726 gPlayer1.Direction, True);
4727 end;
4728 if (Length(P) > 2) and (mon <> nil) then
4729 begin
4730 if (CompareText(P[2], 'normal') = 0) then mon.MonsterBehaviour := BH_NORMAL
4731 else if (CompareText(P[2], 'killer') = 0) then mon.MonsterBehaviour := BH_KILLER
4732 else if (CompareText(P[2], 'maniac') = 0) then mon.MonsterBehaviour := BH_MANIAC
4733 else if (CompareText(P[2], 'insane') = 0) then mon.MonsterBehaviour := BH_INSANE
4734 else if (CompareText(P[2], 'cannibal') = 0) then mon.MonsterBehaviour := BH_CANNIBAL
4735 else if (CompareText(P[2], 'good') = 0) then mon.MonsterBehaviour := BH_GOOD
4736 else if (CompareText(P[2], 'friend') = 0) then mon.MonsterBehaviour := BH_GOOD
4737 else if (CompareText(P[2], 'friendly') = 0) then mon.MonsterBehaviour := BH_GOOD
4738 else mon.MonsterBehaviour := Min(Max(StrToIntDef(P[2], BH_NORMAL), BH_NORMAL), BH_GOOD);
4739 end;
4740 end;
4741 end;
4742 end
4743 else if (cmd = 'd_player') then
4744 begin
4745 if (Length(P) > 1) and
4746 ((P[1] = '1') or (P[1] = '0')) then
4747 g_debug_Player := (P[1][1] = '1');
4749 g_Console_Add(Format(cmd + ' is %d', [Byte(g_Debug_Player)]));
4750 end
4751 else if (cmd = 'd_mem') then
4752 begin
4753 PrintHeapStats();
4754 end;
4755 end
4756 else
4757 g_Console_Add(_lc[I_MSG_NOT_DEBUG]);
4758 end;
4761 procedure GameCheats(P: SSArray);
4762 var
4763 cmd: string;
4764 f, a: Integer;
4765 plr: TPlayer;
4766 begin
4767 if (not gGameOn) or (not conIsCheatsEnabled) then
4768 begin
4769 g_Console_Add('not available');
4770 exit;
4771 end;
4772 plr := gPlayer1;
4773 if plr = nil then
4774 begin
4775 g_Console_Add('where is the player?!');
4776 exit;
4777 end;
4778 cmd := LowerCase(P[0]);
4779 // god
4780 if cmd = 'god' then
4781 begin
4782 plr.GodMode := not plr.GodMode;
4783 if plr.GodMode then g_Console_Add('player is godlike now') else g_Console_Add('player is mortal now');
4784 exit;
4785 end;
4786 // give <health|exit|weapons|air|suit|jetpack|berserk|all>
4787 if cmd = 'give' then
4788 begin
4789 if length(P) < 2 then begin g_Console_Add('give what?!'); exit; end;
4790 for f := 1 to High(P) do
4791 begin
4792 cmd := LowerCase(P[f]);
4793 if cmd = 'health' then begin plr.RestoreHealthArmor(); g_Console_Add('player feels himself better'); continue; end;
4794 if (cmd = 'all') {or (cmd = 'weapons')} then begin plr.AllRulez(False); g_Console_Add('player got the gifts'); continue; end;
4795 if cmd = 'exit' then
4796 begin
4797 if gTriggers <> nil then
4798 begin
4799 for a := 0 to High(gTriggers) do
4800 begin
4801 if gTriggers[a].TriggerType = TRIGGER_EXIT then
4802 begin
4803 g_Console_Add('player left the map');
4804 gExitByTrigger := True;
4805 //g_Game_ExitLevel(gTriggers[a].Data.MapName);
4806 g_Game_ExitLevel(gTriggers[a].tgcMap);
4807 break;
4808 end;
4809 end;
4810 end;
4811 continue;
4812 end;
4814 if cmd = 'air' then begin plr.GiveItem(ITEM_OXYGEN); g_Console_Add('player got some air'); continue; end;
4815 if cmd = 'jetpack' then begin plr.GiveItem(ITEM_JETPACK); g_Console_Add('player got a jetpack'); continue; end;
4816 if cmd = 'suit' then begin plr.GiveItem(ITEM_SUIT); g_Console_Add('player got an envirosuit'); continue; end;
4817 if cmd = 'berserk' then begin plr.GiveItem(ITEM_MEDKIT_BLACK); g_Console_Add('player got a berserk pack'); continue; end;
4818 if cmd = 'backpack' then begin plr.GiveItem(ITEM_AMMO_BACKPACK); g_Console_Add('player got a backpack'); continue; end;
4820 if cmd = 'helmet' then begin plr.GiveItem(ITEM_HELMET); g_Console_Add('player got a helmet'); continue; end;
4821 if cmd = 'bottle' then begin plr.GiveItem(ITEM_BOTTLE); g_Console_Add('player got a bottle of health'); continue; end;
4823 if cmd = 'stimpack' then begin plr.GiveItem(ITEM_MEDKIT_SMALL); g_Console_Add('player got a stimpack'); continue; end;
4824 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;
4826 if cmd = 'greenarmor' then begin plr.GiveItem(ITEM_ARMOR_GREEN); g_Console_Add('player got a security armor'); continue; end;
4827 if cmd = 'bluearmor' then begin plr.GiveItem(ITEM_ARMOR_BLUE); g_Console_Add('player got a combat armor'); continue; end;
4829 if (cmd = 'megasphere') or (cmd = 'mega') then begin plr.GiveItem(ITEM_SPHERE_BLUE); g_Console_Add('player got a megasphere'); continue; end;
4830 if (cmd = 'soulsphere') or (cmd = 'soul')then begin plr.GiveItem(ITEM_SPHERE_WHITE); g_Console_Add('player got a soul sphere'); continue; end;
4832 if (cmd = 'invul') or (cmd = 'invulnerability') then begin plr.GiveItem(ITEM_INVUL); g_Console_Add('player got invulnerability'); continue; end;
4833 if (cmd = 'invis') or (cmd = 'invisibility') then begin plr.GiveItem(ITEM_INVIS); g_Console_Add('player got invisibility'); continue; end;
4835 if cmd = 'redkey' then begin plr.GiveItem(ITEM_KEY_RED); g_Console_Add('player got the red key'); continue; end;
4836 if cmd = 'greenkey' then begin plr.GiveItem(ITEM_KEY_GREEN); g_Console_Add('player got the green key'); continue; end;
4837 if cmd = 'bluekey' then begin plr.GiveItem(ITEM_KEY_BLUE); g_Console_Add('player got the blue key'); continue; end;
4839 if (cmd = 'shotgun') or (cmd = 'sg') then begin plr.GiveItem(ITEM_WEAPON_SHOTGUN1); g_Console_Add('player got a shotgun'); continue; end;
4840 if (cmd = 'supershotgun') or (cmd = 'ssg') then begin plr.GiveItem(ITEM_WEAPON_SHOTGUN2); g_Console_Add('player got a supershotgun'); continue; end;
4841 if cmd = 'chaingun' then begin plr.GiveItem(ITEM_WEAPON_CHAINGUN); g_Console_Add('player got a chaingun'); continue; end;
4842 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;
4843 if cmd = 'plasmagun' then begin plr.GiveItem(ITEM_WEAPON_PLASMA); g_Console_Add('player got a plasma gun'); continue; end;
4844 if cmd = 'bfg' then begin plr.GiveItem(ITEM_WEAPON_BFG); g_Console_Add('player got a BFG-9000'); continue; end;
4846 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;
4847 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;
4848 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;
4849 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;
4850 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;
4851 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;
4853 if cmd = 'superchaingun' then begin plr.GiveItem(ITEM_WEAPON_SUPERPULEMET); g_Console_Add('player got a superchaingun'); continue; end;
4854 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;
4856 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;
4857 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;
4859 if cmd = 'chainsaw' then begin plr.GiveItem(ITEM_WEAPON_SAW); g_Console_Add('player got a chainsaw'); continue; end;
4861 if cmd = 'ammo' then
4862 begin
4863 plr.GiveItem(ITEM_AMMO_SHELLS_BOX);
4864 plr.GiveItem(ITEM_AMMO_BULLETS_BOX);
4865 plr.GiveItem(ITEM_AMMO_CELL_BIG);
4866 plr.GiveItem(ITEM_AMMO_ROCKET_BOX);
4867 plr.GiveItem(ITEM_AMMO_FUELCAN);
4868 g_Console_Add('player got some ammo');
4869 continue;
4870 end;
4872 if cmd = 'clip' then begin plr.GiveItem(ITEM_AMMO_BULLETS); g_Console_Add('player got some bullets'); continue; end;
4873 if cmd = 'bullets' then begin plr.GiveItem(ITEM_AMMO_BULLETS_BOX); g_Console_Add('player got a box of bullets'); continue; end;
4875 if cmd = 'shells' then begin plr.GiveItem(ITEM_AMMO_SHELLS); g_Console_Add('player got some shells'); continue; end;
4876 if cmd = 'shellbox' then begin plr.GiveItem(ITEM_AMMO_SHELLS_BOX); g_Console_Add('player got a box of shells'); continue; end;
4878 if cmd = 'cells' then begin plr.GiveItem(ITEM_AMMO_CELL); g_Console_Add('player got some cells'); continue; end;
4879 if cmd = 'battery' then begin plr.GiveItem(ITEM_AMMO_CELL_BIG); g_Console_Add('player got cell battery'); continue; end;
4881 if cmd = 'rocket' then begin plr.GiveItem(ITEM_AMMO_ROCKET); g_Console_Add('player got a rocket'); continue; end;
4882 if cmd = 'rocketbox' then begin plr.GiveItem(ITEM_AMMO_ROCKET_BOX); g_Console_Add('player got some rockets'); continue; end;
4884 if (cmd = 'fuel') or (cmd = 'fuelcan') then begin plr.GiveItem(ITEM_AMMO_FUELCAN); g_Console_Add('player got fuel canister'); continue; end;
4886 if cmd = 'weapons' then
4887 begin
4888 plr.GiveItem(ITEM_WEAPON_SHOTGUN1);
4889 plr.GiveItem(ITEM_WEAPON_SHOTGUN2);
4890 plr.GiveItem(ITEM_WEAPON_CHAINGUN);
4891 plr.GiveItem(ITEM_WEAPON_ROCKETLAUNCHER);
4892 plr.GiveItem(ITEM_WEAPON_PLASMA);
4893 plr.GiveItem(ITEM_WEAPON_BFG);
4894 g_Console_Add('player got weapons');
4895 continue;
4896 end;
4898 if cmd = 'keys' then
4899 begin
4900 plr.GiveItem(ITEM_KEY_RED);
4901 plr.GiveItem(ITEM_KEY_GREEN);
4902 plr.GiveItem(ITEM_KEY_BLUE);
4903 g_Console_Add('player got all keys');
4904 continue;
4905 end;
4907 g_Console_Add('i don''t know how to give '''+cmd+'''!');
4908 end;
4909 exit;
4910 end;
4911 // open
4912 if cmd = 'open' then
4913 begin
4914 g_Console_Add('player activated sesame');
4915 g_Triggers_OpenAll();
4916 exit;
4917 end;
4918 // fly
4919 if cmd = 'fly' then
4920 begin
4921 gFly := not gFly;
4922 if gFly then g_Console_Add('player feels himself lighter') else g_Console_Add('player lost his wings');
4923 exit;
4924 end;
4925 // noclip
4926 if cmd = 'noclip' then
4927 begin
4928 plr.SwitchNoClip;
4929 g_Console_Add('wall hardeness adjusted');
4930 exit;
4931 end;
4932 // notarget
4933 if cmd = 'notarget' then
4934 begin
4935 plr.NoTarget := not plr.NoTarget;
4936 if plr.NoTarget then g_Console_Add('player hides in shadows') else g_Console_Add('player is brave again');
4937 exit;
4938 end;
4939 // noreload
4940 if cmd = 'noreload' then
4941 begin
4942 plr.NoReload := not plr.NoReload;
4943 if plr.NoReload then g_Console_Add('player is action hero now') else g_Console_Add('player is ordinary man now');
4944 exit;
4945 end;
4946 // speedy
4947 if cmd = 'speedy' then
4948 begin
4949 MAX_RUNVEL := 32-MAX_RUNVEL;
4950 g_Console_Add('speed adjusted');
4951 exit;
4952 end;
4953 // jumpy
4954 if cmd = 'jumpy' then
4955 begin
4956 VEL_JUMP := 30-VEL_JUMP;
4957 g_Console_Add('jump height adjusted');
4958 exit;
4959 end;
4960 // automap
4961 if cmd = 'automap' then
4962 begin
4963 gShowMap := not gShowMap;
4964 if gShowMap then g_Console_Add('player gains second sight') else g_Console_Add('player lost second sight');
4965 exit;
4966 end;
4967 // aimline
4968 if cmd = 'aimline' then
4969 begin
4970 gAimLine := not gAimLine;
4971 if gAimLine then g_Console_Add('player gains laser sight') else g_Console_Add('player lost laser sight');
4972 exit;
4973 end;
4974 end;
4976 procedure GameCommands(P: SSArray);
4977 var
4978 a, b: Integer;
4979 s, pw: String;
4980 chstr: string;
4981 cmd: string;
4982 pl: pTNetClient = nil;
4983 plr: TPlayer;
4984 prt: Word;
4985 nm: Boolean;
4986 listen: LongWord;
4987 found: Boolean;
4988 begin
4989 // Общие команды:
4990 cmd := LowerCase(P[0]);
4991 chstr := '';
4992 if cmd = 'pause' then
4993 begin
4994 {$IFDEF ENABLE_MENU}
4995 if (g_ActiveWindow = nil) then
4996 g_Game_Pause(not gPauseMain);
4997 {$ELSE}
4998 g_Game_Pause(not gPauseMain);
4999 {$ENDIF}
5000 end
5001 else if cmd = 'endgame' then
5002 gExit := EXIT_SIMPLE
5003 else if cmd = 'restart' then
5004 begin
5005 if gGameOn or (gState in [STATE_INTERSINGLE, STATE_INTERCUSTOM]) then
5006 begin
5007 if g_Game_IsClient then
5008 begin
5009 g_Console_Add(_lc[I_MSG_SERVERONLY]);
5010 Exit;
5011 end;
5012 g_Game_Restart();
5013 end else
5014 g_Console_Add(_lc[I_MSG_NOT_GAME]);
5015 end
5016 else if cmd = 'kick' then
5017 begin
5018 if g_Game_IsServer then
5019 begin
5020 if Length(P) < 2 then
5021 begin
5022 g_Console_Add('kick <name>');
5023 Exit;
5024 end;
5025 if P[1] = '' then
5026 begin
5027 g_Console_Add('kick <name>');
5028 Exit;
5029 end;
5031 if g_Game_IsNet then
5032 pl := g_Net_Client_ByName(P[1]);
5033 if (pl <> nil) then
5034 begin
5035 s := g_Net_ClientName_ByID(pl^.ID);
5036 g_Net_Host_Kick(pl^.ID, NET_DISC_KICK);
5037 g_Console_Add(Format(_lc[I_PLAYER_KICK], [s]));
5038 MH_SEND_GameEvent(NET_EV_PLAYER_KICK, 0, s);
5039 g_Net_Slist_ServerPlayerLeaves();
5040 end else if gPlayers <> nil then
5041 for a := Low(gPlayers) to High(gPlayers) do
5042 if gPlayers[a] <> nil then
5043 if Copy(LowerCase(gPlayers[a].Name), 1, Length(P[1])) = LowerCase(P[1]) then
5044 begin
5045 // Не отключать основных игроков в сингле
5046 if not(gPlayers[a] is TBot) and (gGameSettings.GameType = GT_SINGLE) then
5047 continue;
5048 gPlayers[a].Lives := 0;
5049 gPlayers[a].Kill(K_SIMPLEKILL, 0, HIT_DISCON);
5050 g_Console_Add(Format(_lc[I_PLAYER_LEAVE], [gPlayers[a].Name]), True);
5051 g_Player_Remove(gPlayers[a].UID);
5052 g_Net_Slist_ServerPlayerLeaves();
5053 // Если не перемешать, при добавлении новых ботов появятся старые
5054 g_Bot_MixNames();
5055 end;
5056 end else
5057 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
5058 end
5059 else if cmd = 'kick_id' then
5060 begin
5061 if g_Game_IsServer and g_Game_IsNet then
5062 begin
5063 if Length(P) < 2 then
5064 begin
5065 g_Console_Add('kick_id <client ID>');
5066 Exit;
5067 end;
5068 if P[1] = '' then
5069 begin
5070 g_Console_Add('kick_id <client ID>');
5071 Exit;
5072 end;
5074 a := StrToIntDef(P[1], 0);
5075 if (NetClients <> nil) and (a <= High(NetClients)) then
5076 begin
5077 if NetClients[a].Used and (NetClients[a].Peer <> nil) then
5078 begin
5079 s := g_Net_ClientName_ByID(NetClients[a].ID);
5080 g_Net_Host_Kick(NetClients[a].ID, NET_DISC_KICK);
5081 g_Console_Add(Format(_lc[I_PLAYER_KICK], [s]));
5082 MH_SEND_GameEvent(NET_EV_PLAYER_KICK, 0, s);
5083 g_Net_Slist_ServerPlayerLeaves();
5084 end;
5085 end;
5086 end else
5087 g_Console_Add(_lc[I_MSG_SERVERONLY]);
5088 end
5089 else if cmd = 'kick_pid' then
5090 begin
5091 if g_Game_IsServer and g_Game_IsNet then
5092 begin
5093 if Length(P) < 2 then
5094 begin
5095 g_Console_Add('kick_pid <player ID>');
5096 Exit;
5097 end;
5098 if P[1] = '' then
5099 begin
5100 g_Console_Add('kick_pid <player ID>');
5101 Exit;
5102 end;
5104 a := StrToIntDef(P[1], 0);
5105 pl := g_Net_Client_ByPlayer(a);
5106 if (pl <> nil) and pl^.Used and (pl^.Peer <> nil) then
5107 begin
5108 s := g_Net_ClientName_ByID(pl^.ID);
5109 g_Net_Host_Kick(pl^.ID, NET_DISC_KICK);
5110 g_Console_Add(Format(_lc[I_PLAYER_KICK], [s]));
5111 MH_SEND_GameEvent(NET_EV_PLAYER_KICK, 0, s);
5112 g_Net_Slist_ServerPlayerLeaves();
5113 end;
5114 end else
5115 g_Console_Add(_lc[I_MSG_SERVERONLY]);
5116 end
5117 else if cmd = 'ban' then
5118 begin
5119 if g_Game_IsServer and g_Game_IsNet then
5120 begin
5121 if Length(P) < 2 then
5122 begin
5123 g_Console_Add('ban <name>');
5124 Exit;
5125 end;
5126 if P[1] = '' then
5127 begin
5128 g_Console_Add('ban <name>');
5129 Exit;
5130 end;
5132 pl := g_Net_Client_ByName(P[1]);
5133 if (pl <> nil) then
5134 begin
5135 s := g_Net_ClientName_ByID(pl^.ID);
5136 g_Net_BanHost(pl^.Peer^.address.host, False);
5137 g_Net_Host_Kick(pl^.ID, NET_DISC_TEMPBAN);
5138 g_Console_Add(Format(_lc[I_PLAYER_BAN], [s]));
5139 MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s);
5140 g_Net_Slist_ServerPlayerLeaves();
5141 end else
5142 g_Console_Add(Format(_lc[I_NET_ERR_NAME404], [P[1]]));
5143 end else
5144 g_Console_Add(_lc[I_MSG_SERVERONLY]);
5145 end
5146 else if cmd = 'ban_id' then
5147 begin
5148 if g_Game_IsServer and g_Game_IsNet then
5149 begin
5150 if Length(P) < 2 then
5151 begin
5152 g_Console_Add('ban_id <client ID>');
5153 Exit;
5154 end;
5155 if P[1] = '' then
5156 begin
5157 g_Console_Add('ban_id <client ID>');
5158 Exit;
5159 end;
5161 a := StrToIntDef(P[1], 0);
5162 if (NetClients <> nil) and (a <= High(NetClients)) then
5163 if NetClients[a].Used and (NetClients[a].Peer <> nil) then
5164 begin
5165 s := g_Net_ClientName_ByID(NetClients[a].ID);
5166 g_Net_BanHost(NetClients[a].Peer^.address.host, False);
5167 g_Net_Host_Kick(NetClients[a].ID, NET_DISC_TEMPBAN);
5168 g_Console_Add(Format(_lc[I_PLAYER_BAN], [s]));
5169 MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s);
5170 g_Net_Slist_ServerPlayerLeaves();
5171 end;
5172 end else
5173 g_Console_Add(_lc[I_MSG_SERVERONLY]);
5174 end
5175 else if cmd = 'ban_pid' then
5176 begin
5177 if g_Game_IsServer and g_Game_IsNet then
5178 begin
5179 if Length(P) < 2 then
5180 begin
5181 g_Console_Add('ban_pid <player ID>');
5182 Exit;
5183 end;
5184 if P[1] = '' then
5185 begin
5186 g_Console_Add('ban_pid <player ID>');
5187 Exit;
5188 end;
5190 a := StrToIntDef(P[1], 0);
5191 pl := g_Net_Client_ByPlayer(a);
5192 if (pl <> nil) and pl^.Used and (pl^.Peer <> nil) then
5193 begin
5194 s := g_Net_ClientName_ByID(pl^.ID);
5195 g_Net_BanHost(pl^.Peer^.address.host, False);
5196 g_Net_Host_Kick(pl^.ID, NET_DISC_TEMPBAN);
5197 g_Console_Add(Format(_lc[I_PLAYER_BAN], [s]));
5198 MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s);
5199 g_Net_Slist_ServerPlayerLeaves();
5200 end;
5201 end else
5202 g_Console_Add(_lc[I_MSG_SERVERONLY]);
5203 end
5204 else if cmd = 'permban' then
5205 begin
5206 if g_Game_IsServer and g_Game_IsNet then
5207 begin
5208 if Length(P) < 2 then
5209 begin
5210 g_Console_Add('permban <name>');
5211 Exit;
5212 end;
5213 if P[1] = '' then
5214 begin
5215 g_Console_Add('permban <name>');
5216 Exit;
5217 end;
5219 pl := g_Net_Client_ByName(P[1]);
5220 if (pl <> nil) then
5221 begin
5222 s := g_Net_ClientName_ByID(pl^.ID);
5223 g_Net_BanHost(pl^.Peer^.address.host);
5224 g_Net_Host_Kick(pl^.ID, NET_DISC_BAN);
5225 g_Net_SaveBanList();
5226 g_Console_Add(Format(_lc[I_PLAYER_BAN], [s]));
5227 MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s);
5228 g_Net_Slist_ServerPlayerLeaves();
5229 end else
5230 g_Console_Add(Format(_lc[I_NET_ERR_NAME404], [P[1]]));
5231 end else
5232 g_Console_Add(_lc[I_MSG_SERVERONLY]);
5233 end
5234 else if cmd = 'permban_id' then
5235 begin
5236 if g_Game_IsServer and g_Game_IsNet then
5237 begin
5238 if Length(P) < 2 then
5239 begin
5240 g_Console_Add('permban_id <client ID>');
5241 Exit;
5242 end;
5243 if P[1] = '' then
5244 begin
5245 g_Console_Add('permban_id <client ID>');
5246 Exit;
5247 end;
5249 a := StrToIntDef(P[1], 0);
5250 if (NetClients <> nil) and (a <= High(NetClients)) then
5251 if NetClients[a].Used and (NetClients[a].Peer <> nil) then
5252 begin
5253 s := g_Net_ClientName_ByID(NetClients[a].ID);
5254 g_Net_BanHost(NetClients[a].Peer^.address.host);
5255 g_Net_Host_Kick(NetClients[a].ID, NET_DISC_BAN);
5256 g_Net_SaveBanList();
5257 g_Console_Add(Format(_lc[I_PLAYER_BAN], [s]));
5258 MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s);
5259 g_Net_Slist_ServerPlayerLeaves();
5260 end;
5261 end else
5262 g_Console_Add(_lc[I_MSG_SERVERONLY]);
5263 end
5264 else if cmd = 'permban_pid' then
5265 begin
5266 if g_Game_IsServer and g_Game_IsNet then
5267 begin
5268 if Length(P) < 2 then
5269 begin
5270 g_Console_Add('permban_pid <player ID>');
5271 Exit;
5272 end;
5273 if P[1] = '' then
5274 begin
5275 g_Console_Add('permban_pid <player ID>');
5276 Exit;
5277 end;
5279 a := StrToIntDef(P[1], 0);
5280 pl := g_Net_Client_ByPlayer(a);
5281 if (pl <> nil) and pl^.Used and (pl^.Peer <> nil) then
5282 begin
5283 s := g_Net_ClientName_ByID(pl^.ID);
5284 g_Net_BanHost(pl^.Peer^.address.host);
5285 g_Net_Host_Kick(pl^.ID, NET_DISC_TEMPBAN);
5286 g_Net_SaveBanList();
5287 g_Console_Add(Format(_lc[I_PLAYER_BAN], [s]));
5288 MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s);
5289 g_Net_Slist_ServerPlayerLeaves();
5290 end;
5291 end else
5292 g_Console_Add(_lc[I_MSG_SERVERONLY]);
5293 end
5294 else if cmd = 'permban_ip' then
5295 begin
5296 if g_Game_IsServer and g_Game_IsNet then
5297 begin
5298 if Length(P) < 2 then
5299 begin
5300 g_Console_Add('permban_ip <IP address>');
5301 Exit;
5302 end;
5303 if P[1] = '' then
5304 begin
5305 g_Console_Add('permban_ip <IP address>');
5306 Exit;
5307 end;
5309 g_Net_BanHost(P[1]);
5310 g_Net_SaveBanList();
5311 g_Console_Add(Format(_lc[I_PLAYER_BAN], [P[1]]));
5312 end else
5313 g_Console_Add(_lc[I_MSG_SERVERONLY]);
5314 end
5315 else if cmd = 'unban' then
5316 begin
5317 if g_Game_IsServer and g_Game_IsNet then
5318 begin
5319 if Length(P) < 2 then
5320 begin
5321 g_Console_Add('unban <IP Address>');
5322 Exit;
5323 end;
5324 if P[1] = '' then
5325 begin
5326 g_Console_Add('unban <IP Address>');
5327 Exit;
5328 end;
5330 if g_Net_UnbanHost(P[1]) then
5331 begin
5332 g_Console_Add(Format(_lc[I_MSG_UNBAN_OK], [P[1]]));
5333 g_Net_SaveBanList();
5334 end else
5335 g_Console_Add(Format(_lc[I_MSG_UNBAN_FAIL], [P[1]]));
5336 end else
5337 g_Console_Add(_lc[I_MSG_SERVERONLY]);
5338 end
5339 else if cmd = 'clientlist' then
5340 begin
5341 if g_Game_IsServer and g_Game_IsNet then
5342 begin
5343 b := 0;
5344 if NetClients <> nil then
5345 for a := Low(NetClients) to High(NetClients) do
5346 if NetClients[a].Used and (NetClients[a].Peer <> nil) then
5347 begin
5348 plr := g_Player_Get(NetClients[a].Player);
5349 if plr = nil then continue;
5350 Inc(b);
5351 g_Console_Add(Format('#%2d: %-15s | %s', [a,
5352 IpToStr(NetClients[a].Peer^.address.host), plr.Name]));
5353 end;
5354 if b = 0 then
5355 g_Console_Add(_lc[I_MSG_NOCLIENTS]);
5356 end else
5357 g_Console_Add(_lc[I_MSG_SERVERONLY]);
5358 end
5359 else if cmd = 'connect' then
5360 begin
5361 if (NetMode = NET_NONE) then
5362 begin
5363 if Length(P) < 2 then
5364 begin
5365 g_Console_Add('connect <IP> [port] [password]');
5366 Exit;
5367 end;
5368 if P[1] = '' then
5369 begin
5370 g_Console_Add('connect <IP> [port] [password]');
5371 Exit;
5372 end;
5374 if Length(P) > 2 then
5375 prt := StrToIntDef(P[2], 25666)
5376 else
5377 prt := 25666;
5379 if Length(P) > 3 then
5380 pw := P[3]
5381 else
5382 pw := '';
5384 g_Game_StartClient(P[1], prt, pw);
5385 end;
5386 end
5387 else if cmd = 'disconnect' then
5388 begin
5389 if (NetMode = NET_CLIENT) then
5390 g_Net_Disconnect();
5391 end
5392 else if cmd = 'reconnect' then
5393 begin
5394 if (NetMode = NET_SERVER) then
5395 Exit;
5397 if (NetMode = NET_CLIENT) then
5398 begin
5399 g_Net_Disconnect();
5400 gExit := EXIT_SIMPLE;
5401 EndGame;
5402 end;
5404 //TODO: Use last successful password to reconnect, instead of ''
5405 g_Game_StartClient(NetClientIP, NetClientPort, '');
5406 end
5407 else if (cmd = 'addbot') or
5408 (cmd = 'bot_add') then
5409 begin
5410 if Length(P) > 2 then
5411 g_Bot_Add(TEAM_NONE, StrToIntDef(P[1], 2), StrToIntDef(P[2], 100))
5412 else if Length(P) > 1 then
5413 g_Bot_Add(TEAM_NONE, StrToIntDef(P[1], 2))
5414 else
5415 g_Bot_Add(TEAM_NONE, 2);
5416 end
5417 else if cmd = 'bot_addlist' then
5418 begin
5419 if Length(P) > 1 then
5420 begin
5421 if Length(P) = 2 then
5422 g_Bot_AddList(TEAM_NONE, P[1], StrToIntDef(P[1], -1))
5423 else if Length(P) = 3 then
5424 g_Bot_AddList(TEAM_NONE, P[1], StrToIntDef(P[1], -1), StrToIntDef(P[2], 100))
5425 else
5426 g_Bot_AddList(IfThen(P[2] = 'red', TEAM_RED, TEAM_BLUE), P[1], StrToIntDef(P[1], -1));
5427 end;
5428 end
5429 else if cmd = 'bot_removeall' then
5430 g_Bot_RemoveAll()
5431 else if cmd = 'chat' then
5432 begin
5433 if g_Game_IsNet then
5434 begin
5435 if Length(P) > 1 then
5436 begin
5437 for a := 1 to High(P) do
5438 chstr := chstr + P[a] + ' ';
5440 if Length(chstr) > 200 then SetLength(chstr, 200);
5442 if Length(chstr) < 1 then
5443 begin
5444 g_Console_Add('chat <text>');
5445 Exit;
5446 end;
5448 chstr := b_Text_Format(chstr);
5449 if g_Game_IsClient then
5450 MC_SEND_Chat(chstr, NET_CHAT_PLAYER)
5451 else
5452 MH_SEND_Chat(gPlayer1Settings.Name + ': ' + chstr, NET_CHAT_PLAYER);
5453 end
5454 else
5455 g_Console_Add('chat <text>');
5456 end else
5457 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
5458 end
5459 else if cmd = 'teamchat' then
5460 begin
5461 if g_Game_IsNet and (gGameSettings.GameMode in [GM_TDM, GM_CTF]) then
5462 begin
5463 if Length(P) > 1 then
5464 begin
5465 for a := 1 to High(P) do
5466 chstr := chstr + P[a] + ' ';
5468 if Length(chstr) > 200 then SetLength(chstr, 200);
5470 if Length(chstr) < 1 then
5471 begin
5472 g_Console_Add('teamchat <text>');
5473 Exit;
5474 end;
5476 chstr := b_Text_Format(chstr);
5477 if g_Game_IsClient then
5478 MC_SEND_Chat(chstr, NET_CHAT_TEAM)
5479 else
5480 MH_SEND_Chat(gPlayer1Settings.Name + ': ' + chstr, NET_CHAT_TEAM,
5481 gPlayer1Settings.Team);
5482 end
5483 else
5484 g_Console_Add('teamchat <text>');
5485 end else
5486 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
5487 end
5488 else if (cmd = 'an') or (cmd = 'announce') then
5489 begin
5490 if g_Game_IsNet then
5491 begin
5492 if Length(P) > 1 then
5493 begin
5494 for a := 1 to High(P) do
5495 chstr := chstr + P[a] + ' ';
5497 if Length(chstr) > 200 then SetLength(chstr, 200);
5499 if Length(chstr) < 1 then
5500 begin
5501 g_Console_Add('announce <text>');
5502 Exit;
5503 end;
5505 chstr := 'centerprint 100 ' + b_Text_Format(chstr);
5506 if g_Game_IsClient then
5507 MC_SEND_RCONCommand(chstr)
5508 else
5509 g_Console_Process(chstr, True);
5510 end
5511 else
5512 g_Console_Add('announce <text>');
5513 end else
5514 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
5515 end
5516 else if cmd = 'game' then
5517 begin
5518 if gGameSettings.GameType <> GT_NONE then
5519 begin
5520 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
5521 Exit;
5522 end;
5523 if Length(P) = 1 then
5524 begin
5525 g_Console_Add(cmd + ' <WAD> [MAP] [# players]');
5526 Exit;
5527 end;
5528 // game not started yet, load fist map from some wad
5529 found := false;
5530 s := addWadExtension(P[1]);
5531 found := e_FindResource(AllMapDirs, s);
5532 P[1] := s;
5533 if found then
5534 begin
5535 P[1] := ExpandFileName(P[1]);
5536 // if map not choosed then set first map
5537 if Length(P) < 3 then
5538 begin
5539 SetLength(P, 3);
5540 P[2] := g_Game_GetFirstMap(P[1]);
5541 end;
5543 s := P[1] + ':\' + UpperCase(P[2]);
5545 if g_Map_Exist(s) then
5546 begin
5547 // start game
5548 g_Game_Free();
5549 with gGameSettings do
5550 begin
5551 Options := gsGameFlags;
5552 GameMode := g_Game_TextToMode(gsGameMode);
5553 if gSwitchGameMode <> GM_NONE then
5554 GameMode := gSwitchGameMode;
5555 if GameMode = GM_NONE then GameMode := GM_DM;
5556 if GameMode = GM_SINGLE then GameMode := GM_COOP;
5557 b := 1;
5558 if Length(P) >= 4 then
5559 b := StrToIntDef(P[3], 1);
5560 g_Game_StartCustom(s, GameMode, TimeLimit,
5561 ScoreLimit, MaxLives, Options, b);
5562 end;
5563 end
5564 else
5565 if P[2] = '' then
5566 g_Console_Add(Format(_lc[I_MSG_NO_MAPS], [P[1]]))
5567 else
5568 g_Console_Add(Format(_lc[I_MSG_NO_MAP_FALLBACK], [UpperCase(P[2]), P[1]]));
5569 end else
5570 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]));
5571 end
5572 else if cmd = 'host' then
5573 begin
5574 if gGameSettings.GameType <> GT_NONE then
5575 begin
5576 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
5577 Exit;
5578 end;
5579 if Length(P) < 4 then
5580 begin
5581 g_Console_Add(cmd + ' <listen IP> <port> <WAD> [MAP] [# players]');
5582 Exit;
5583 end;
5584 if not StrToIp(P[1], listen) then
5585 Exit;
5586 prt := StrToIntDef(P[2], 25666);
5588 s := addWadExtension(P[3]);
5589 found := e_FindResource(AllMapDirs, s);
5590 P[3] := s;
5591 if found then
5592 begin
5593 // get first map in wad, if not specified
5594 if Length(P) < 5 then
5595 begin
5596 SetLength(P, 5);
5597 P[4] := g_Game_GetFirstMap(P[1]);
5598 end;
5599 s := P[3] + ':\' + UpperCase(P[4]);
5600 if g_Map_Exist(s) then
5601 begin
5602 // start game
5603 g_Game_Free();
5604 with gGameSettings do
5605 begin
5606 Options := gsGameFlags;
5607 GameMode := g_Game_TextToMode(gsGameMode);
5608 if gSwitchGameMode <> GM_NONE then GameMode := gSwitchGameMode;
5609 if GameMode = GM_NONE then GameMode := GM_DM;
5610 if GameMode = GM_SINGLE then GameMode := GM_COOP;
5611 b := 0;
5612 if Length(P) >= 6 then
5613 b := StrToIntDef(P[5], 0);
5614 g_Game_StartServer(s, GameMode, TimeLimit, ScoreLimit, MaxLives, Options, b, listen, prt)
5615 end
5616 end
5617 else
5618 begin
5619 if P[4] = '' then
5620 g_Console_Add(Format(_lc[I_MSG_NO_MAPS], [P[3]]))
5621 else
5622 g_Console_Add(Format(_lc[I_MSG_NO_MAP_FALLBACK], [UpperCase(P[4]), P[3]]))
5623 end
5624 end
5625 else
5626 begin
5627 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[3]]))
5628 end
5629 end
5630 else if cmd = 'map' then
5631 begin
5632 if Length(P) = 1 then
5633 begin
5634 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
5635 begin
5636 g_Console_Add(cmd + ' <MAP>');
5637 g_Console_Add(cmd + ' <WAD> [MAP]')
5638 end
5639 else
5640 begin
5641 g_Console_Add(_lc[I_MSG_GM_UNAVAIL])
5642 end
5643 end
5644 else
5645 begin
5646 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
5647 begin
5648 if Length(P) < 3 then
5649 begin
5650 // first param is map or wad
5651 s := UpperCase(P[1]);
5652 if g_Map_Exist(gGameSettings.WAD + ':\' + s) then
5653 begin
5654 gExitByTrigger := False;
5655 if gGameOn then
5656 begin
5657 // already in game, finish current map
5658 gNextMap := s;
5659 gExit := EXIT_ENDLEVELCUSTOM;
5660 end
5661 else
5662 begin
5663 // intermission, so change map immediately
5664 g_Game_ChangeMap(s)
5665 end
5666 end
5667 else
5668 begin
5669 s := P[1];
5670 found := e_FindResource(AllMapDirs, s);
5671 P[1] := s;
5672 g_Console_Add(Format(_lc[I_MSG_NO_MAP_FALLBACK], [s, 'WAD ' + P[1]]));
5673 if found then
5674 begin
5675 // no such map, found wad
5676 pw := P[1];
5677 SetLength(P, 3);
5678 P[1] := ExpandFileName(pw);
5679 P[2] := g_Game_GetFirstMap(P[1]);
5680 s := P[1] + ':\' + P[2];
5681 if g_Map_Exist(s) then
5682 begin
5683 gExitByTrigger := False;
5684 if gGameOn then
5685 begin
5686 // already in game, finish current map
5687 gNextMap := s;
5688 gExit := EXIT_ENDLEVELCUSTOM
5689 end
5690 else
5691 begin
5692 // intermission, so change map immediately
5693 g_Game_ChangeMap(s)
5694 end
5695 end
5696 else
5697 begin
5698 if P[2] = '' then
5699 g_Console_Add(Format(_lc[I_MSG_NO_MAPS], [P[1]]))
5700 else
5701 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [P[2]]))
5702 end
5703 end
5704 else
5705 begin
5706 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]))
5707 end
5708 end;
5709 end
5710 else
5711 begin
5712 s := addWadExtension(P[1]);
5713 found := e_FindResource(AllMapDirs, s);
5714 P[1] := s;
5715 if found then
5716 begin
5717 P[2] := UpperCase(P[2]);
5718 s := P[1] + ':\' + P[2];
5719 if g_Map_Exist(s) then
5720 begin
5721 gExitByTrigger := False;
5722 if gGameOn then
5723 begin
5724 gNextMap := s;
5725 gExit := EXIT_ENDLEVELCUSTOM
5726 end
5727 else
5728 begin
5729 g_Game_ChangeMap(s)
5730 end
5731 end
5732 else
5733 begin
5734 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [P[2]]))
5735 end
5736 end
5737 else
5738 begin
5739 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]))
5740 end
5741 end
5742 end
5743 else
5744 begin
5745 g_Console_Add(_lc[I_MSG_GM_UNAVAIL])
5746 end
5747 end
5748 end
5749 else if cmd = 'nextmap' then
5750 begin
5751 if not(gGameOn or (gState = STATE_INTERCUSTOM)) then
5752 begin
5753 g_Console_Add(_lc[I_MSG_NOT_GAME])
5754 end
5755 else
5756 begin
5757 nm := True;
5758 if Length(P) = 1 then
5759 begin
5760 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
5761 begin
5762 g_Console_Add(cmd + ' <MAP>');
5763 g_Console_Add(cmd + ' <WAD> [MAP]');
5764 end
5765 else
5766 begin
5767 nm := False;
5768 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
5769 end;
5770 end
5771 else
5772 begin
5773 nm := False;
5774 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
5775 begin
5776 if Length(P) < 3 then
5777 begin
5778 // first param is map or wad
5779 s := UpperCase(P[1]);
5780 if g_Map_Exist(gGameSettings.WAD + ':\' + s) then
5781 begin
5782 // map founded
5783 gExitByTrigger := False;
5784 gNextMap := s;
5785 nm := True;
5786 end
5787 else
5788 begin
5789 // no such map, found wad
5790 pw := addWadExtension(P[1]);
5791 found := e_FindResource(MapDirs, pw);
5792 if not found then
5793 found := e_FindResource(WadDirs, pw);
5794 P[1] := pw;
5795 g_Console_Add(Format(_lc[I_MSG_NO_MAP_FALLBACK], [s, P[1]]));
5796 if found then
5797 begin
5798 // map not specified, select first map
5799 SetLength(P, 3);
5800 P[2] := g_Game_GetFirstMap(P[1]);
5801 s := P[1] + ':\' + P[2];
5802 if g_Map_Exist(s) then
5803 begin
5804 gExitByTrigger := False;
5805 gNextMap := s;
5806 nm := True
5807 end
5808 else
5809 begin
5810 if P[2] = '' then
5811 g_Console_Add(Format(_lc[I_MSG_NO_MAPS], [P[1]]))
5812 else
5813 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [P[2]]))
5814 end
5815 end
5816 else
5817 begin
5818 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]))
5819 end
5820 end
5821 end
5822 else
5823 begin
5824 // specified two params wad + map
5825 pw := addWadExtension(P[1]);
5826 found := e_FindResource(MapDirs, pw);
5827 if not found then
5828 found := e_FindResource(MapDirs, pw);
5829 P[1] := pw;
5830 if found then
5831 begin
5832 P[2] := UpperCase(P[2]);
5833 s := P[1] + ':\' + P[2];
5834 if g_Map_Exist(s) then
5835 begin
5836 gExitByTrigger := False;
5837 gNextMap := s;
5838 nm := True
5839 end
5840 else
5841 begin
5842 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [P[2]]))
5843 end
5844 end
5845 else
5846 begin
5847 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]))
5848 end
5849 end
5850 end
5851 else
5852 begin
5853 g_Console_Add(_lc[I_MSG_GM_UNAVAIL])
5854 end
5855 end;
5856 if nm then
5857 begin
5858 if gNextMap = '' then
5859 g_Console_Add(_lc[I_MSG_NEXTMAP_UNSET])
5860 else
5861 g_Console_Add(Format(_lc[I_MSG_NEXTMAP_SET], [gNextMap]))
5862 end
5863 end
5864 end
5865 else if (cmd = 'endmap') or (cmd = 'goodbye') then
5866 begin
5867 if not gGameOn then
5868 begin
5869 g_Console_Add(_lc[I_MSG_NOT_GAME])
5870 end
5871 else
5872 begin
5873 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
5874 begin
5875 gExitByTrigger := False;
5876 // next map not specified, try to find trigger EXIT
5877 if (gNextMap = '') and (gTriggers <> nil) then
5878 begin
5879 for a := 0 to High(gTriggers) do
5880 begin
5881 if gTriggers[a].TriggerType = TRIGGER_EXIT then
5882 begin
5883 gExitByTrigger := True;
5884 //gNextMap := gTriggers[a].Data.MapName;
5885 gNextMap := gTriggers[a].tgcMap;
5886 Break
5887 end
5888 end
5889 end;
5890 if gNextMap = '' then
5891 gNextMap := g_Game_GetNextMap();
5892 if not isWadPath(gNextMap) then
5893 s := gGameSettings.WAD + ':\' + gNextMap
5894 else
5895 s := gNextMap;
5896 if g_Map_Exist(s) then
5897 gExit := EXIT_ENDLEVELCUSTOM
5898 else
5899 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [gNextMap]))
5900 end
5901 else
5902 begin
5903 g_Console_Add(_lc[I_MSG_GM_UNAVAIL])
5904 end
5905 end
5906 end
5907 else if (cmd = 'event') then
5908 begin
5909 if (Length(P) <= 1) then
5910 begin
5911 for a := 0 to High(gEvents) do
5912 if gEvents[a].Command = '' then
5913 g_Console_Add(gEvents[a].Name + ' <none>')
5914 else
5915 g_Console_Add(gEvents[a].Name + ' "' + gEvents[a].Command + '"');
5916 Exit;
5917 end;
5918 if (Length(P) = 2) then
5919 begin
5920 for a := 0 to High(gEvents) do
5921 if gEvents[a].Name = P[1] then
5922 if gEvents[a].Command = '' then
5923 g_Console_Add(gEvents[a].Name + ' <none>')
5924 else
5925 g_Console_Add(gEvents[a].Name + ' "' + gEvents[a].Command + '"');
5926 Exit;
5927 end;
5928 for a := 0 to High(gEvents) do
5929 if gEvents[a].Name = P[1] then
5930 begin
5931 gEvents[a].Command := '';
5932 for b := 2 to High(P) do
5933 if Pos(' ', P[b]) = 0 then
5934 gEvents[a].Command := gEvents[a].Command + ' ' + P[b]
5935 else
5936 gEvents[a].Command := gEvents[a].Command + ' "' + P[b] + '"';
5937 gEvents[a].Command := Trim(gEvents[a].Command);
5938 Exit;
5939 end;
5940 end
5941 else if cmd = 'suicide' then
5942 begin
5943 if gGameOn then
5944 begin
5945 if g_Game_IsClient then
5946 MC_SEND_CheatRequest(NET_CHEAT_SUICIDE)
5947 else
5948 begin
5949 if gPlayer1 <> nil then
5950 gPlayer1.Damage(SUICIDE_DAMAGE, gPlayer1.UID, 0, 0, HIT_SELF);
5951 if gPlayer2 <> nil then
5952 gPlayer2.Damage(SUICIDE_DAMAGE, gPlayer2.UID, 0, 0, HIT_SELF);
5953 end;
5954 end;
5955 end
5956 else if cmd = 'screenshot' then
5957 begin
5958 {$IFDEF ENABLE_RENDER}
5959 r_Render_RequestScreenShot;
5960 {$ENDIF}
5961 end
5962 else if (cmd = 'weapnext') or (cmd = 'weapprev') then
5963 begin
5964 a := 1 - (ord(cmd[5]) - ord('n'));
5965 if a = -1 then
5966 gWeaponAction[0, WP_PREV] := True;
5967 if a = 1 then
5968 gWeaponAction[0, WP_NEXT] := True;
5969 end
5970 else if cmd = 'weapon' then
5971 begin
5972 if Length(p) = 2 then
5973 begin
5974 a := WP_FIRST + StrToIntDef(p[1], 0) - 1;
5975 if (a >= WP_FIRST) and (a <= WP_LAST) then
5976 gSelectWeapon[0, a] := True
5977 end
5978 end
5979 else if (cmd = 'p1_weapnext') or (cmd = 'p1_weapprev')
5980 or (cmd = 'p2_weapnext') or (cmd = 'p2_weapprev') then
5981 begin
5982 a := 1 - (ord(cmd[8]) - ord('n'));
5983 b := ord(cmd[2]) - ord('1');
5984 if a = -1 then
5985 gWeaponAction[b, WP_PREV] := True;
5986 if a = 1 then
5987 gWeaponAction[b, WP_NEXT] := True;
5988 end
5989 else if (cmd = 'p1_weapon') or (cmd = 'p2_weapon') then
5990 begin
5991 if Length(p) = 2 then
5992 begin
5993 a := WP_FIRST + StrToIntDef(p[1], 0) - 1;
5994 b := ord(cmd[2]) - ord('1');
5995 if (a >= WP_FIRST) and (a <= WP_LAST) then
5996 gSelectWeapon[b, a] := True
5997 end
5998 end
5999 else if (cmd = 'p1_weapbest') or (cmd = 'p2_weapbest') then
6000 begin
6001 b := ord(cmd[2]) - ord('1');
6002 if b = 0 then
6003 gSelectWeapon[b, gPlayer1.GetMorePrefered()] := True
6004 else
6005 gSelectWeapon[b, gPlayer2.GetMorePrefered()] := True;
6006 end
6007 else if (cmd = 'dropflag') then
6008 begin
6009 if g_Game_IsServer then
6010 begin
6011 if gPlayer2 <> nil then gPlayer2.TryDropFlag();
6012 if gPlayer1 <> nil then gPlayer1.TryDropFlag();
6013 end
6014 else
6015 MC_SEND_CheatRequest(NET_CHEAT_DROPFLAG);
6016 end
6017 else if (cmd = 'p1_dropflag') or (cmd = 'p2_dropflag') then
6018 begin
6019 b := ord(cmd[2]) - ord('1');
6020 if g_Game_IsServer then
6021 begin
6022 if (b = 1) and (gPlayer2 <> nil) then gPlayer2.TryDropFlag()
6023 else if (b = 0) and (gPlayer1 <> nil) then gPlayer1.TryDropFlag();
6024 end
6025 else
6026 MC_SEND_CheatRequest(NET_CHEAT_DROPFLAG);
6027 end
6028 // Команды Своей игры:
6029 else if gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT] then
6030 begin
6031 if cmd = 'bot_addred' then
6032 begin
6033 if Length(P) > 1 then
6034 g_Bot_Add(TEAM_RED, StrToIntDef(P[1], 2))
6035 else
6036 g_Bot_Add(TEAM_RED, 2);
6037 end
6038 else if cmd = 'bot_addblue' then
6039 begin
6040 if Length(P) > 1 then
6041 g_Bot_Add(TEAM_BLUE, StrToIntDef(P[1], 2))
6042 else
6043 g_Bot_Add(TEAM_BLUE, 2);
6044 end
6045 else if cmd = 'spectate' then
6046 begin
6047 if not gGameOn then
6048 Exit;
6049 g_Game_Spectate();
6050 end
6051 else if cmd = 'say' then
6052 begin
6053 if g_Game_IsServer and g_Game_IsNet then
6054 begin
6055 if Length(P) > 1 then
6056 begin
6057 chstr := '';
6058 for a := 1 to High(P) do
6059 chstr := chstr + P[a] + ' ';
6061 if Length(chstr) > 200 then SetLength(chstr, 200);
6063 if Length(chstr) < 1 then
6064 begin
6065 g_Console_Add('say <text>');
6066 Exit;
6067 end;
6069 chstr := b_Text_Format(chstr);
6070 MH_SEND_Chat(chstr, NET_CHAT_PLAYER);
6071 end
6072 else g_Console_Add('say <text>');
6073 end else
6074 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6075 end
6076 else if cmd = 'tell' then
6077 begin
6078 if g_Game_IsServer and g_Game_IsNet then
6079 begin
6080 if (Length(P) > 2) and (P[1] <> '') then
6081 begin
6082 chstr := '';
6083 for a := 2 to High(P) do
6084 chstr := chstr + P[a] + ' ';
6086 if Length(chstr) > 200 then SetLength(chstr, 200);
6088 if Length(chstr) < 1 then
6089 begin
6090 g_Console_Add('tell <playername> <text>');
6091 Exit;
6092 end;
6094 pl := g_Net_Client_ByName(P[1]);
6095 if pl <> nil then
6096 MH_SEND_Chat(b_Text_Format(chstr), NET_CHAT_PLAYER, pl^.ID)
6097 else
6098 g_Console_Add(Format(_lc[I_NET_ERR_NAME404], [P[1]]));
6099 end
6100 else g_Console_Add('tell <playername> <text>');
6101 end else
6102 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6103 end
6104 else if cmd = 'centerprint' then
6105 begin
6106 if (Length(P) > 2) and (P[1] <> '') then
6107 begin
6108 chstr := '';
6109 for a := 2 to High(P) do
6110 chstr := chstr + P[a] + ' ';
6112 if Length(chstr) > 200 then SetLength(chstr, 200);
6114 if Length(chstr) < 1 then
6115 begin
6116 g_Console_Add('centerprint <timeout> <text>');
6117 Exit;
6118 end;
6120 a := StrToIntDef(P[1], 100);
6121 chstr := b_Text_Format(chstr);
6122 g_Game_Message(chstr, a);
6123 if g_Game_IsNet and g_Game_IsServer then
6124 MH_SEND_GameEvent(NET_EV_BIGTEXT, a, chstr);
6125 end
6126 else g_Console_Add('centerprint <timeout> <text>');
6127 end
6128 else if (cmd = 'overtime') and not g_Game_IsClient then
6129 begin
6130 if (Length(P) = 1) or (StrToIntDef(P[1], -1) <= 0) then
6131 Exit;
6132 // Дополнительное время:
6133 gGameSettings.TimeLimit := (gTime - gGameStartTime) div 1000 + Word(StrToIntDef(P[1], 0));
6135 g_Console_Add(Format(_lc[I_MSG_TIME_LIMIT],
6136 [gGameSettings.TimeLimit div 3600,
6137 (gGameSettings.TimeLimit div 60) mod 60,
6138 gGameSettings.TimeLimit mod 60]));
6139 if g_Game_IsNet then MH_SEND_GameSettings;
6140 end
6141 else if (cmd = 'rcon_password') and g_Game_IsClient then
6142 begin
6143 if (Length(P) <= 1) then
6144 g_Console_Add('rcon_password <password>')
6145 else
6146 MC_SEND_RCONPassword(P[1]);
6147 end
6148 else if cmd = 'rcon' then
6149 begin
6150 if g_Game_IsClient then
6151 begin
6152 if Length(P) > 1 then
6153 begin
6154 chstr := '';
6155 for a := 1 to High(P) do
6156 chstr := chstr + P[a] + ' ';
6158 if Length(chstr) > 200 then SetLength(chstr, 200);
6160 if Length(chstr) < 1 then
6161 begin
6162 g_Console_Add('rcon <command>');
6163 Exit;
6164 end;
6166 MC_SEND_RCONCommand(chstr);
6167 end
6168 else g_Console_Add('rcon <command>');
6169 end;
6170 end
6171 else if cmd = 'ready' then
6172 begin
6173 if g_Game_IsServer and (gLMSRespawn = LMS_RESPAWN_WARMUP) then
6174 gLMSRespawnTime := gTime + 100;
6175 end
6176 else if (cmd = 'callvote') and g_Game_IsNet then
6177 begin
6178 if Length(P) > 1 then
6179 begin
6180 chstr := '';
6181 for a := 1 to High(P) do begin
6182 if a > 1 then chstr := chstr + ' ';
6183 chstr := chstr + P[a];
6184 end;
6186 if Length(chstr) > 200 then SetLength(chstr, 200);
6188 if Length(chstr) < 1 then
6189 begin
6190 g_Console_Add('callvote <command>');
6191 Exit;
6192 end;
6194 if g_Game_IsClient then
6195 MC_SEND_Vote(True, chstr)
6196 else
6197 g_Game_StartVote(chstr, gPlayer1Settings.Name);
6198 g_Console_Process('vote', True);
6199 end
6200 else
6201 g_Console_Add('callvote <command>');
6202 end
6203 else if (cmd = 'vote') and g_Game_IsNet then
6204 begin
6205 if g_Game_IsClient then
6206 MC_SEND_Vote(False)
6207 else if gVoteInProgress then
6208 begin
6209 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
6210 a := Floor((NetClientCount+1)/2.0) + 1
6211 else
6212 a := Floor(NetClientCount/2.0) + 1;
6213 if gVoted then
6214 begin
6215 Dec(gVoteCount);
6216 gVoted := False;
6217 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_REVOKED], [gPlayer1Settings.Name, gVoteCount, a]), True);
6218 MH_SEND_VoteEvent(NET_VE_REVOKE, gPlayer1Settings.Name, 'a', gVoteCount, a);
6219 end
6220 else
6221 begin
6222 Inc(gVoteCount);
6223 gVoted := True;
6224 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_VOTE], [gPlayer1Settings.Name, gVoteCount, a]), True);
6225 MH_SEND_VoteEvent(NET_VE_VOTE, gPlayer1Settings.Name, 'a', gVoteCount, a);
6226 g_Game_CheckVote;
6227 end;
6228 end;
6229 end
6230 end;
6231 end;
6233 procedure SystemCommands(P: SSArray);
6234 var
6235 cmd: string;
6236 begin
6237 cmd := LowerCase(P[0]);
6238 case cmd of
6239 'exit', 'quit':
6240 begin
6241 g_Game_Free();
6242 g_Game_Quit();
6243 end;
6244 {$IFDEF ENABLE_RENDER}
6245 'r_reset':
6246 r_Render_Apply;
6247 {$ENDIF}
6248 'r_maxfps':
6249 begin
6250 if Length(p) = 2 then
6251 begin
6252 gMaxFPS := StrToIntDef(p[1], gMaxFPS);
6253 if gMaxFPS > 0 then
6254 gFrameTime := 1000 div gMaxFPS
6255 else
6256 gFrameTime := 0;
6257 end;
6258 e_LogWritefln('r_maxfps %d', [gMaxFPS]);
6259 end;
6260 'g_language':
6261 begin
6262 if Length(p) = 2 then
6263 begin
6264 gAskLanguage := true;
6265 gLanguage := LANGUAGE_ENGLISH;
6266 case LowerCase(p[1]) of
6267 'english':
6268 begin
6269 gAskLanguage := false;
6270 gLanguage := LANGUAGE_ENGLISH;
6271 end;
6272 'russian':
6273 begin
6274 gAskLanguage := false;
6275 gLanguage := LANGUAGE_RUSSIAN;
6276 end;
6277 'ask':
6278 begin
6279 gAskLanguage := true;
6280 gLanguage := LANGUAGE_ENGLISH;
6281 end;
6282 end;
6283 g_Language_Set(gLanguage);
6284 end
6285 else
6286 begin
6287 e_LogWritefln('usage: %s <English|Russian|Ask>', [cmd]);
6288 end
6289 end;
6290 end;
6291 end;
6293 {$IFDEF ENABLE_MENU}
6294 procedure g_Game_InGameMenu(Show: Boolean);
6295 begin
6296 if (g_ActiveWindow = nil) and Show then
6297 begin
6298 if gGameSettings.GameType = GT_SINGLE then
6299 g_GUI_ShowWindow('GameSingleMenu')
6300 else
6301 begin
6302 if g_Game_IsClient then
6303 g_GUI_ShowWindow('GameClientMenu')
6304 else
6305 if g_Game_IsNet then
6306 g_GUI_ShowWindow('GameServerMenu')
6307 else
6308 g_GUI_ShowWindow('GameCustomMenu');
6309 end;
6310 g_Sound_PlayEx('MENU_OPEN');
6312 // Пауза при меню только в одиночной игре:
6313 if (not g_Game_IsNet) then
6314 g_Game_Pause(True);
6315 end
6316 else
6317 if (g_ActiveWindow <> nil) and (not Show) then
6318 begin
6319 // Пауза при меню только в одиночной игре:
6320 if (not g_Game_IsNet) then
6321 g_Game_Pause(False);
6322 end;
6323 end;
6324 {$ENDIF}
6326 procedure g_Game_Pause (Enable: Boolean);
6327 var
6328 oldPause: Boolean;
6329 begin
6330 if not gGameOn then exit;
6332 if not (gGameSettings.GameType in [GT_SINGLE, GT_CUSTOM]) then exit;
6334 oldPause := gPause;
6335 gPauseMain := Enable;
6337 if (gPause <> oldPause) then g_Game_PauseAllSounds(gPause);
6338 end;
6340 procedure g_Game_HolmesPause (Enable: Boolean);
6341 var
6342 oldPause: Boolean;
6343 begin
6344 if not gGameOn then exit;
6345 if not (gGameSettings.GameType in [GT_SINGLE, GT_CUSTOM]) then exit;
6347 oldPause := gPause;
6348 gPauseHolmes := Enable;
6350 if (gPause <> oldPause) then g_Game_PauseAllSounds(gPause);
6351 end;
6353 procedure g_Game_PauseAllSounds(Enable: Boolean);
6354 var
6355 i: Integer;
6356 begin
6357 // Триггеры:
6358 if gTriggers <> nil then
6359 for i := 0 to High(gTriggers) do
6360 with gTriggers[i] do
6361 if (TriggerType = TRIGGER_SOUND) and
6362 (Sound <> nil) and
6363 Sound.IsPlaying() then
6364 begin
6365 Sound.Pause(Enable);
6366 end;
6368 // Звуки игроков:
6369 if gPlayers <> nil then
6370 for i := 0 to High(gPlayers) do
6371 if gPlayers[i] <> nil then
6372 gPlayers[i].PauseSounds(Enable);
6374 // Музыка:
6375 if gMusic <> nil then
6376 gMusic.Pause(Enable);
6377 end;
6379 procedure g_Game_StopAllSounds(all: Boolean);
6380 var
6381 i: Integer;
6382 begin
6383 if gTriggers <> nil then
6384 for i := 0 to High(gTriggers) do
6385 with gTriggers[i] do
6386 if (TriggerType = TRIGGER_SOUND) and
6387 (Sound <> nil) then
6388 Sound.Stop();
6390 if gMusic <> nil then
6391 gMusic.Stop();
6393 if all then
6394 e_StopChannels();
6395 end;
6397 procedure g_Game_UpdateTriggerSounds;
6398 var i: Integer;
6399 begin
6400 if gTriggers <> nil then
6401 for i := 0 to High(gTriggers) do
6402 with gTriggers[i] do
6403 if (TriggerType = TRIGGER_SOUND) and (Sound <> nil) and tgcLocal and Sound.IsPlaying() then
6404 Sound.SetCoordsRect(X, Y, Width, Height, tgcVolume / 255.0)
6405 end;
6407 function g_Game_IsWatchedPlayer(UID: Word): Boolean;
6408 begin
6409 Result := False;
6410 if (gPlayer1 <> nil) and (gPlayer1.UID = UID) then
6411 begin
6412 Result := True;
6413 Exit;
6414 end;
6415 if (gPlayer2 <> nil) and (gPlayer2.UID = UID) then
6416 begin
6417 Result := True;
6418 Exit;
6419 end;
6420 if gSpectMode <> SPECT_PLAYERS then
6421 Exit;
6422 if gSpectPID1 = UID then
6423 begin
6424 Result := True;
6425 Exit;
6426 end;
6427 if gSpectViewTwo and (gSpectPID2 = UID) then
6428 begin
6429 Result := True;
6430 Exit;
6431 end;
6432 end;
6434 function g_Game_IsWatchedTeam(Team: Byte): Boolean;
6435 var
6436 Pl: TPlayer;
6437 begin
6438 Result := False;
6439 if (gPlayer1 <> nil) and (gPlayer1.Team = Team) then
6440 begin
6441 Result := True;
6442 Exit;
6443 end;
6444 if (gPlayer2 <> nil) and (gPlayer2.Team = Team) then
6445 begin
6446 Result := True;
6447 Exit;
6448 end;
6449 if gSpectMode <> SPECT_PLAYERS then
6450 Exit;
6451 Pl := g_Player_Get(gSpectPID1);
6452 if (Pl <> nil) and (Pl.Team = Team) then
6453 begin
6454 Result := True;
6455 Exit;
6456 end;
6457 if gSpectViewTwo then
6458 begin
6459 Pl := g_Player_Get(gSpectPID2);
6460 if (Pl <> nil) and (Pl.Team = Team) then
6461 begin
6462 Result := True;
6463 Exit;
6464 end;
6465 end;
6466 end;
6468 procedure g_Game_Message (Msg: string; Time: Word);
6469 begin
6470 MessageText := Msg;
6471 MessageTime := Time;
6472 end;
6474 procedure g_Game_ChatSound(Text: String; Taunt: Boolean = True);
6475 const
6476 punct: Array[0..13] of String =
6477 ('.', ',', ':', ';', '!', '?', '(', ')', '''', '"', '/', '\', '*', '^');
6478 var
6479 i, j: Integer;
6480 ok: Boolean;
6481 fpText: String;
6483 function IsPunctuation(S: String): Boolean;
6484 var
6485 i: Integer;
6486 begin
6487 Result := False;
6488 if Length(S) <> 1 then
6489 Exit;
6490 for i := Low(punct) to High(punct) do
6491 if S = punct[i] then
6492 begin
6493 Result := True;
6494 break;
6495 end;
6496 end;
6497 function FilterPunctuation(S: String): String;
6498 var
6499 i: Integer;
6500 begin
6501 for i := Low(punct) to High(punct) do
6502 S := StringReplace(S, punct[i], ' ', [rfReplaceAll]);
6503 Result := S;
6504 end;
6505 begin
6506 ok := False;
6508 if gUseChatSounds and Taunt and (gChatSounds <> nil) and (Pos(': ', Text) > 0) then
6509 begin
6510 // remove player name
6511 Delete(Text, 1, Pos(': ', Text) + 2 - 1);
6512 // for FullWord check
6513 Text := toLowerCase1251(' ' + Text + ' ');
6514 fpText := FilterPunctuation(Text);
6516 for i := 0 to Length(gChatSounds) - 1 do
6517 begin
6518 ok := True;
6519 for j := 0 to Length(gChatSounds[i].Tags) - 1 do
6520 begin
6521 if gChatSounds[i].FullWord and (not IsPunctuation(gChatSounds[i].Tags[j])) then
6522 ok := Pos(' ' + gChatSounds[i].Tags[j] + ' ', fpText) > 0
6523 else
6524 ok := Pos(gChatSounds[i].Tags[j], Text) > 0;
6525 if not ok then
6526 break;
6527 end;
6528 if ok then
6529 begin
6530 gChatSounds[i].Sound.Play();
6531 break;
6532 end;
6533 end;
6534 end;
6535 if not ok then
6536 g_Sound_PlayEx('SOUND_GAME_RADIO');
6537 end;
6539 procedure g_Game_Announce_GoodShot(SpawnerUID: Word);
6540 var
6541 a: Integer;
6542 begin
6543 case gAnnouncer of
6544 ANNOUNCE_NONE:
6545 Exit;
6546 ANNOUNCE_ME,
6547 ANNOUNCE_MEPLUS:
6548 if not g_Game_IsWatchedPlayer(SpawnerUID) then
6549 Exit;
6550 end;
6551 for a := 0 to 3 do
6552 if goodsnd[a].IsPlaying() then
6553 Exit;
6555 goodsnd[Random(4)].Play();
6556 end;
6558 procedure g_Game_Announce_KillCombo(Param: Integer);
6559 var
6560 UID: Word;
6561 c, n: Byte;
6562 Pl: TPlayer;
6563 Name: String;
6564 begin
6565 UID := Param and $FFFF;
6566 c := Param shr 16;
6567 if c < 2 then
6568 Exit;
6570 Pl := g_Player_Get(UID);
6571 if Pl = nil then
6572 Name := '?'
6573 else
6574 Name := Pl.Name;
6576 case c of
6577 2: begin
6578 n := 0;
6579 g_Console_Add(Format(_lc[I_PLAYER_KILL_2X], [Name]), True);
6580 end;
6581 3: begin
6582 n := 1;
6583 g_Console_Add(Format(_lc[I_PLAYER_KILL_3X], [Name]), True);
6584 end;
6585 4: begin
6586 n := 2;
6587 g_Console_Add(Format(_lc[I_PLAYER_KILL_4X], [Name]), True);
6588 end;
6589 else begin
6590 n := 3;
6591 g_Console_Add(Format(_lc[I_PLAYER_KILL_MX], [Name]), True);
6592 end;
6593 end;
6595 case gAnnouncer of
6596 ANNOUNCE_NONE:
6597 Exit;
6598 ANNOUNCE_ME:
6599 if not g_Game_IsWatchedPlayer(UID) then
6600 Exit;
6601 ANNOUNCE_MEPLUS:
6602 if (not g_Game_IsWatchedPlayer(UID)) and (c < 4) then
6603 Exit;
6604 end;
6606 if killsnd[n].IsPlaying() then
6607 killsnd[n].Stop();
6608 killsnd[n].Play();
6609 end;
6611 procedure g_Game_Announce_BodyKill(SpawnerUID: Word);
6612 var
6613 a: Integer;
6614 begin
6615 case gAnnouncer of
6616 ANNOUNCE_NONE:
6617 Exit;
6618 ANNOUNCE_ME:
6619 if not g_Game_IsWatchedPlayer(SpawnerUID) then
6620 Exit;
6621 end;
6622 for a := 0 to 2 do
6623 if hahasnd[a].IsPlaying() then
6624 Exit;
6626 hahasnd[Random(3)].Play();
6627 end;
6629 procedure g_Game_StartVote(Command, Initiator: string);
6630 var
6631 Need: Integer;
6632 begin
6633 if not gVotesEnabled then Exit;
6634 if gGameSettings.GameType <> GT_SERVER then Exit;
6635 if gVoteInProgress or gVotePassed then
6636 begin
6637 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_INPROGRESS], [gVoteCommand]), True);
6638 MH_SEND_VoteEvent(NET_VE_INPROGRESS, gVoteCommand);
6639 Exit;
6640 end;
6641 gVoteInProgress := True;
6642 gVotePassed := False;
6643 gVoteTimer := gTime + gVoteTimeout * 1000;
6644 gVoteCount := 0;
6645 gVoted := False;
6646 gVoteCommand := Command;
6648 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
6649 Need := Floor((NetClientCount+1)/2.0)+1
6650 else
6651 Need := Floor(NetClientCount/2.0)+1;
6652 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_STARTED], [Initiator, Command, Need]), True);
6653 MH_SEND_VoteEvent(NET_VE_STARTED, Initiator, Command, Need);
6654 end;
6656 procedure g_Game_CheckVote;
6657 var
6658 I, Need: Integer;
6659 begin
6660 if gGameSettings.GameType <> GT_SERVER then Exit;
6661 if not gVoteInProgress then Exit;
6663 if (gTime >= gVoteTimer) then
6664 begin
6665 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
6666 Need := Floor((NetClientCount+1)/2.0) + 1
6667 else
6668 Need := Floor(NetClientCount/2.0) + 1;
6669 if gVoteCount >= Need then
6670 begin
6671 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_PASSED], [gVoteCommand]), True);
6672 MH_SEND_VoteEvent(NET_VE_PASSED, gVoteCommand);
6673 gVotePassed := True;
6674 gVoteCmdTimer := gTime + 5000;
6675 end
6676 else
6677 begin
6678 g_Console_Add(_lc[I_MESSAGE_VOTE_FAILED], True);
6679 MH_SEND_VoteEvent(NET_VE_FAILED);
6680 end;
6681 if NetClients <> nil then
6682 for I := Low(NetClients) to High(NetClients) do
6683 if NetClients[i].Used then
6684 NetClients[i].Voted := False;
6685 gVoteInProgress := False;
6686 gVoted := False;
6687 gVoteCount := 0;
6688 end
6689 else
6690 begin
6691 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
6692 Need := Floor((NetClientCount+1)/2.0) + 1
6693 else
6694 Need := Floor(NetClientCount/2.0) + 1;
6695 if gVoteCount >= Need then
6696 begin
6697 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_PASSED], [gVoteCommand]), True);
6698 MH_SEND_VoteEvent(NET_VE_PASSED, gVoteCommand);
6699 gVoteInProgress := False;
6700 gVotePassed := True;
6701 gVoteCmdTimer := gTime + 5000;
6702 gVoted := False;
6703 gVoteCount := 0;
6704 if NetClients <> nil then
6705 for I := Low(NetClients) to High(NetClients) do
6706 if NetClients[i].Used then
6707 NetClients[i].Voted := False;
6708 end;
6709 end;
6710 end;
6712 procedure g_Game_LoadMapList(FileName: string);
6713 var
6714 ListFile: TextFile;
6715 s: string;
6716 begin
6717 MapList := nil;
6718 MapIndex := -1;
6720 if not FileExists(FileName) then Exit;
6722 AssignFile(ListFile, FileName);
6723 Reset(ListFile);
6724 while not EOF(ListFile) do
6725 begin
6726 ReadLn(ListFile, s);
6728 s := Trim(s);
6729 if s = '' then Continue;
6731 SetLength(MapList, Length(MapList)+1);
6732 MapList[High(MapList)] := s;
6733 end;
6734 CloseFile(ListFile);
6735 end;
6737 procedure g_Game_SetDebugMode();
6738 begin
6739 gDebugMode := True;
6740 // Читы (даже в своей игре):
6741 gCheats := True;
6742 end;
6744 procedure Parse_Params(var pars: TParamStrValues);
6745 var
6746 i: Integer;
6747 s: String;
6748 begin
6749 SetLength(pars, 0);
6750 i := 1;
6751 while i <= ParamCount do
6752 begin
6753 s := ParamStr(i);
6754 if (Length(s) > 1) and (s[1] = '-') then
6755 begin
6756 if (Length(s) > 2) and (s[2] = '-') then
6757 begin // Одиночный параметр
6758 SetLength(pars, Length(pars) + 1);
6759 with pars[High(pars)] do
6760 begin
6761 Name := LowerCase(s);
6762 Value := '+';
6763 end;
6764 end
6765 else
6766 if (i < ParamCount) then
6767 begin // Параметр со значением
6768 Inc(i);
6769 SetLength(pars, Length(pars) + 1);
6770 with pars[High(pars)] do
6771 begin
6772 Name := LowerCase(s);
6773 Value := LowerCase(ParamStr(i));
6774 end;
6775 end;
6776 end;
6778 Inc(i);
6779 end;
6780 end;
6782 function Find_Param_Value(var pars: TParamStrValues; aName: String): String;
6783 var
6784 i: Integer;
6785 begin
6786 Result := '';
6787 for i := 0 to High(pars) do
6788 if pars[i].Name = aName then
6789 begin
6790 Result := pars[i].Value;
6791 Break;
6792 end;
6793 end;
6795 procedure g_Game_Process_Params();
6796 var
6797 pars: TParamStrValues;
6798 map: String;
6799 GMode, n: Byte;
6800 LimT, LimS: Integer;
6801 Opt: LongWord;
6802 Lives: Integer;
6803 s: String;
6804 Port: Integer;
6805 ip: String;
6806 F: TextFile;
6807 begin
6808 Parse_Params(pars);
6810 // Debug mode:
6811 s := Find_Param_Value(pars, '--debug');
6812 if (s <> '') then
6813 begin
6814 g_Game_SetDebugMode();
6815 s := Find_Param_Value(pars, '--netdump');
6816 if (s <> '') then
6817 NetDump := True;
6818 end;
6820 // Connect when game loads
6821 ip := Find_Param_Value(pars, '-connect');
6823 if ip <> '' then
6824 begin
6825 s := Find_Param_Value(pars, '-port');
6826 if (s = '') or not TryStrToInt(s, Port) then
6827 Port := 25666;
6829 s := Find_Param_Value(pars, '-pw');
6831 g_Game_StartClient(ip, Port, s);
6832 Exit;
6833 end;
6835 s := LowerCase(Find_Param_Value(pars, '-dbg-mainwad'));
6836 if (s <> '') then
6837 begin
6838 gDefaultMegawadStart := s;
6839 end;
6841 if (Find_Param_Value(pars, '--dbg-mainwad-restore') <> '') or
6842 (Find_Param_Value(pars, '--dbg-mainwad-default') <> '') then
6843 begin
6844 gDefaultMegawadStart := DF_Default_Megawad_Start;
6845 end;
6847 // Start map when game loads:
6848 map := LowerCase(Find_Param_Value(pars, '-map'));
6849 if isWadPath(map) then
6850 begin
6851 // Game mode:
6852 s := Find_Param_Value(pars, '-gm');
6853 GMode := g_Game_TextToMode(s);
6854 if GMode = GM_NONE then GMode := GM_DM;
6855 if GMode = GM_SINGLE then GMode := GM_COOP;
6857 // Time limit:
6858 s := Find_Param_Value(pars, '-limt');
6859 if (s = '') or (not TryStrToInt(s, LimT)) then
6860 LimT := 0;
6861 if LimT < 0 then
6862 LimT := 0;
6864 // Score limit:
6865 s := Find_Param_Value(pars, '-lims');
6866 if (s = '') or (not TryStrToInt(s, LimS)) then
6867 LimS := 0;
6868 if LimS < 0 then
6869 LimS := 0;
6871 // Lives limit:
6872 s := Find_Param_Value(pars, '-lives');
6873 if (s = '') or (not TryStrToInt(s, Lives)) then
6874 Lives := 0;
6875 if Lives < 0 then
6876 Lives := 0;
6878 // Options:
6879 s := Find_Param_Value(pars, '-opt');
6880 if (s = '') then
6881 Opt := gsGameFlags
6882 else
6883 Opt := StrToIntDef(s, 0);
6885 // Close after map:
6886 s := Find_Param_Value(pars, '--close');
6887 if (s <> '') then
6888 gMapOnce := True;
6890 // Override map to test:
6891 s := LowerCase(Find_Param_Value(pars, '-testmap'));
6892 if s <> '' then
6893 begin
6894 if e_IsValidResourceName(s) then
6895 e_FindResource(AllMapDirs, s);
6896 gTestMap := ExpandFileName(s);
6897 end;
6899 // Delete test map after play:
6900 s := Find_Param_Value(pars, '--testdelete');
6901 if (s <> '') then
6902 begin
6903 //gMapToDelete := MapsDir + map;
6904 e_WriteLog('"--testdelete" is deprecated, use --tempdelete.', TMsgType.Fatal);
6905 Halt(1);
6906 end;
6908 // Delete temporary WAD after play:
6909 s := Find_Param_Value(pars, '--tempdelete');
6910 if (s <> '') and (gTestMap <> '') then
6911 begin
6912 gMapToDelete := gTestMap;
6913 gTempDelete := True;
6914 end;
6916 // Number of players:
6917 s := Find_Param_Value(pars, '-pl');
6918 if (s = '') then
6919 n := DEFAULT_PLAYERS
6920 else
6921 n := StrToIntDef(s, DEFAULT_PLAYERS);
6923 // Start:
6924 s := Find_Param_Value(pars, '-port');
6925 if (s = '') or not TryStrToInt(s, Port) then
6926 g_Game_StartCustom(map, GMode, LimT, LimS, Lives, Opt, n)
6927 else
6928 g_Game_StartServer(map, GMode, LimT, LimS, Lives, Opt, n, 0, Port);
6929 end;
6931 // Execute script when game loads:
6932 s := Find_Param_Value(pars, '-exec');
6933 if s <> '' then
6934 begin
6935 // if not isWadPath(s) then
6936 // s := GameDir + '/' + s;
6938 {$I-}
6939 AssignFile(F, s);
6940 Reset(F);
6941 if IOResult <> 0 then
6942 begin
6943 e_WriteLog(Format(_lc[I_SIMPLE_ERROR], ['Failed to read file: ' + s]), TMsgType.Warning);
6944 g_Console_Add(Format(_lc[I_CONSOLE_ERROR_READ], [s]));
6945 CloseFile(F);
6946 Exit;
6947 end;
6948 e_WriteLog('Executing script: ' + s, TMsgType.Notify);
6949 g_Console_Add(Format(_lc[I_CONSOLE_EXEC], [s]));
6951 while not EOF(F) do
6952 begin
6953 ReadLn(F, s);
6954 if IOResult <> 0 then
6955 begin
6956 e_WriteLog(Format(_lc[I_SIMPLE_ERROR], ['Failed to read file: ' + s]), TMsgType.Warning);
6957 g_Console_Add(Format(_lc[I_CONSOLE_ERROR_READ], [s]));
6958 CloseFile(F);
6959 Exit;
6960 end;
6961 if Pos('#', s) <> 1 then // script comment
6962 g_Console_Process(s, True);
6963 end;
6965 CloseFile(F);
6966 {$I+}
6967 end;
6969 SetLength(pars, 0);
6970 end;
6972 begin
6973 conRegVar('pf_draw_frame', @g_profile_frame_draw, 'draw frame rendering profiles', 'render profiles');
6974 //conRegVar('pf_update_frame', @g_profile_frame_update, 'draw frame updating profiles', 'update profiles');
6975 conRegVar('pf_coldet', @g_profile_collision, 'draw collision detection profiles', 'coldet profiles');
6976 conRegVar('pf_los', @g_profile_los, 'draw monster LOS profiles', 'monster LOS profiles');
6978 conRegVar('cd_sq_enabled', @gdbg_map_use_accel_coldet, 'accelerated spatial queries in map coldet', 'accelerated map coldet');
6979 conRegVar('mon_sq_enabled', @gmon_debug_use_sqaccel, 'accelerated spatial queries for monsters', 'accelerated monster coldet');
6980 conRegVar('wtrace_sq_enabled', @gwep_debug_fast_trace, 'accelerated spatial queries for weapon hitscan trace', 'accelerated weapon hitscan');
6982 {$IFDEF ENABLE_GFX}
6983 conRegVar('pr_enabled', @gpart_dbg_enabled, 'enable/disable particles', 'particles');
6984 conRegVar('pr_phys_enabled', @gpart_dbg_phys_enabled, 'enable/disable particle physics', 'particle physics');
6985 {$ENDIF}
6987 conRegVar('los_enabled', @gmon_dbg_los_enabled, 'enable/disable monster LOS calculations', 'monster LOS', true);
6988 conRegVar('mon_think', @gmon_debug_think, 'enable/disable monster thinking', 'monster thinking', true);
6990 {$IFDEF ENABLE_HOLMES}
6991 conRegVar('dbg_holmes', @g_holmes_enabled, 'enable/disable Holmes', 'Holmes', true);
6992 {$ENDIF}
6994 conRegVar('dbg_ignore_level_bounds', @g_dbg_ignore_bounds, 'ignore level bounds', '', false);
6996 conRegVar('light_enabled', @gwin_k8_enable_light_experiments, 'enable/disable dynamic lighting', 'lighting');
6997 conRegVar('light_player_halo', @g_playerLight, 'enable/disable player halo', 'player light halo');
6999 conRegVar('r_smallmap_align_h', @r_smallmap_h, 'halign: 0: left; 1: center; 2: right', 'horizontal aligning of small maps');
7000 conRegVar('r_smallmap_align_v', @r_smallmap_v, 'valign: 0: top; 1: center; 2: bottom', 'vertial aligning of small maps');
7002 conRegVar('r_showfps', @gShowFPS, 'draw fps counter', 'draw fps counter');
7003 conRegVar('r_showtime', @gShowTime, 'show game time', 'show game time');
7004 conRegVar('r_showping', @gShowPing, 'show ping', 'show ping');
7005 conRegVar('r_showscore', @gShowScore, 'show score', 'show score');
7006 conRegVar('r_showkillmsg', @gShowKillMsg, 'show kill log', 'show kill log');
7007 conRegVar('r_showlives', @gShowLives, 'show lives', 'show lives');
7008 conRegVar('r_showspect', @gSpectHUD, 'show spectator hud', 'show spectator hud');
7009 conRegVar('r_showstat', @gShowStat, 'show stats', 'show stats');
7010 conRegVar('r_showpids', @gShowPIDs, 'show PIDs', 'show PIDs');
7011 end.