DEADSOFTWARE

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