DEADSOFTWARE

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