DEADSOFTWARE

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