DEADSOFTWARE

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