DEADSOFTWARE

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