DEADSOFTWARE

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