DEADSOFTWARE

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