DEADSOFTWARE

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