DEADSOFTWARE

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