DEADSOFTWARE

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