DEADSOFTWARE

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