DEADSOFTWARE

render: draw touch controls via render
[d2df-sdl.git] / src / game / g_game.pas
1 (* Copyright (C) Doom 2D: Forever Developers
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, version 3 of the License ONLY.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14 *)
15 {$INCLUDE ../shared/a_modes.inc}
16 unit g_game;
18 interface
20 uses
21 {$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 GoalLimit: 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 end;
70 TMegaWADInfo = record
71 Name: String;
72 Description: String;
73 Author: String;
74 Pic: String;
75 end;
77 THearPoint = record
78 Active: Boolean;
79 Coords: TDFPoint;
80 end;
82 function g_Game_IsNet(): Boolean;
83 function g_Game_IsServer(): Boolean;
84 function g_Game_IsClient(): Boolean;
85 procedure g_Game_Init();
86 procedure g_Game_Free (freeTextures: Boolean=true);
87 procedure g_Game_LoadData();
88 procedure g_Game_FreeData();
89 procedure g_Game_Update();
90 procedure g_Game_PreUpdate();
91 procedure g_Game_Quit();
92 function g_Game_ModeToText(Mode: Byte): string;
93 function g_Game_TextToMode(Mode: string): Byte;
94 procedure g_Game_ExecuteEvent(Name: String);
95 function g_Game_DelayEvent(DEType: Byte; Time: LongWord; Num: Integer = 0; Str: String = ''): Integer;
96 procedure g_Game_AddPlayer(Team: Byte = TEAM_NONE);
97 procedure g_Game_RemovePlayer();
98 procedure g_Game_Spectate();
99 procedure g_Game_SpectateCenterView();
100 procedure g_Game_StartSingle(Map: String; TwoPlayers: Boolean; nPlayers: Byte);
101 procedure g_Game_StartCustom(Map: String; GameMode: Byte; TimeLimit, GoalLimit: Word; MaxLives: Byte; Options: LongWord; nPlayers: Byte);
102 procedure g_Game_StartServer(Map: String; GameMode: Byte; TimeLimit, GoalLimit: Word; MaxLives: Byte; Options: LongWord; nPlayers: Byte; IPAddr: LongWord; Port: Word);
103 procedure g_Game_StartClient(Addr: String; Port: Word; PW: String);
104 procedure g_Game_Restart();
105 procedure g_Game_RestartLevel();
106 procedure g_Game_RestartRound(NoMapRestart: Boolean = False);
107 function g_Game_ClientWAD (NewWAD: String; const WHash: TMD5Digest): AnsiString;
108 function g_Game_StartMap(asMegawad: Boolean; Map: String; Force: Boolean = False; const oldMapPath: AnsiString=''): Boolean;
109 procedure g_Game_ChangeMap(const MapPath: String);
110 procedure g_Game_ExitLevel(const Map: AnsiString);
111 function g_Game_GetFirstMap(WAD: String): String;
112 function g_Game_GetNextMap(): String;
113 procedure g_Game_NextLevel();
114 procedure g_Game_Pause(Enable: Boolean);
115 procedure g_Game_HolmesPause(Enable: Boolean);
116 function g_Game_IsWatchedPlayer(UID: Word): Boolean;
117 function g_Game_IsWatchedTeam(Team: Byte): Boolean;
118 procedure g_Game_Message(Msg: String; Time: Word);
119 procedure g_Game_LoadMapList(FileName: String);
120 procedure g_Game_PauseAllSounds(Enable: Boolean);
121 procedure g_Game_StopAllSounds(all: Boolean);
122 procedure g_Game_UpdateTriggerSounds();
123 function g_Game_GetMegaWADInfo(WAD: String): TMegaWADInfo;
124 procedure g_Game_ChatSound(Text: String; Taunt: Boolean = True);
125 procedure g_Game_Announce_GoodShot(SpawnerUID: Word);
126 procedure g_Game_Announce_KillCombo(Param: Integer);
127 procedure g_Game_Announce_BodyKill(SpawnerUID: Word);
128 procedure g_Game_StartVote(Command, Initiator: string);
129 procedure g_Game_CheckVote;
130 {$IFNDEF HEADLESS}
131 procedure g_TakeScreenShot(Filename: string = '');
132 {$ENDIF}
133 procedure g_FatalError(Text: String);
134 procedure g_SimpleError(Text: String);
135 function g_Game_IsTestMap(): Boolean;
136 procedure g_Game_DeleteTestMap();
137 procedure GameCVars(P: SSArray);
138 procedure PlayerSettingsCVars(P: SSArray);
139 procedure SystemCommands(P: SSArray);
140 procedure GameCommands(P: SSArray);
141 procedure GameCheats(P: SSArray);
142 procedure DebugCommands(P: SSArray);
143 procedure g_Game_Process_Params;
144 procedure g_Game_SetLoadingText(Text: String; Max: Integer; reWrite: Boolean);
145 procedure g_Game_StepLoading(Value: Integer = -1);
146 procedure g_Game_ClearLoading();
147 procedure g_Game_SetDebugMode();
149 function IsActivePlayer(p: TPlayer): Boolean;
150 function GetActivePlayerID_Next(Skip: Integer = -1): Integer;
151 procedure SortGameStat(var stat: TPlayerStatArray);
154 {$IFDEF ENABLE_MENU}
155 procedure g_Game_InGameMenu(Show: Boolean);
156 {$ENDIF}
157 {$IFNDEF HEADLESS}
158 procedure CharPress (C: AnsiChar);
159 {$ENDIF}
160 procedure KeyPress (K: Word);
162 { procedure SetWinPause(Enable: Boolean); }
164 const
165 GAME_TICK = 28;
167 LOADING_SHOW_STEP = 100;
168 LOADING_INTERLINE = 20;
170 GT_NONE = 0;
171 GT_SINGLE = 1;
172 GT_CUSTOM = 2;
173 GT_SERVER = 3;
174 GT_CLIENT = 4;
176 GM_NONE = 0;
177 GM_DM = 1;
178 GM_TDM = 2;
179 GM_CTF = 3;
180 GM_COOP = 4;
181 GM_SINGLE = 5;
183 EXIT_QUIT = 1;
184 EXIT_SIMPLE = 2;
185 EXIT_RESTART = 3;
186 EXIT_ENDLEVELSINGLE = 4;
187 EXIT_ENDLEVELCUSTOM = 5;
189 GAME_OPTION_RESERVED = 1;
190 GAME_OPTION_TEAMDAMAGE = 2;
191 GAME_OPTION_ALLOWEXIT = 4;
192 GAME_OPTION_WEAPONSTAY = 8;
193 GAME_OPTION_MONSTERS = 16;
194 GAME_OPTION_BOTVSPLAYER = 32;
195 GAME_OPTION_BOTVSMONSTER = 64;
196 GAME_OPTION_DMKEYS = 128;
197 GAME_OPTION_TEAMHITTRACE = 256;
198 GAME_OPTION_TEAMHITPROJECTILE = 512;
199 GAME_OPTION_TEAMABSORBDAMAGE = 1024;
201 STATE_NONE = 0;
202 STATE_MENU = 1;
203 STATE_FOLD = 2;
204 STATE_INTERCUSTOM = 3;
205 STATE_INTERSINGLE = 4;
206 STATE_INTERTEXT = 5;
207 STATE_INTERPIC = 6;
208 STATE_ENDPIC = 7;
209 STATE_SLIST = 8;
211 LMS_RESPAWN_NONE = 0;
212 LMS_RESPAWN_WARMUP = 1;
213 LMS_RESPAWN_FINAL = 2;
215 SPECT_NONE = 0;
216 SPECT_STATS = 1;
217 SPECT_MAPVIEW = 2;
218 SPECT_PLAYERS = 3;
220 DE_GLOBEVENT = 0;
221 DE_BFGHIT = 1;
222 DE_KILLCOMBO = 2;
223 DE_BODYKILL = 3;
225 ANNOUNCE_NONE = 0;
226 ANNOUNCE_ME = 1;
227 ANNOUNCE_MEPLUS = 2;
228 ANNOUNCE_ALL = 3;
230 CONFIG_FILENAME = 'Doom2DF.cfg';
232 TEST_MAP_NAME = '$$$_TEST_$$$';
234 STD_PLAYER_MODEL = 'Doomer';
236 {$IFDEF HEADLESS}
237 DEFAULT_PLAYERS = 0;
238 {$ELSE}
239 DEFAULT_PLAYERS = 1;
240 {$ENDIF}
242 STATFILE_VERSION = $03;
244 var
245 gGameSettings: TGameSettings;
246 gPlayer1Settings: TPlayerSettings;
247 gPlayer2Settings: TPlayerSettings;
248 gGameOn: Boolean;
249 gPlayerScreenSize: TDFPoint;
250 gPlayer1ScreenCoord: TDFPoint;
251 gPlayer2ScreenCoord: TDFPoint;
252 gPlayer1: TPlayer = nil;
253 gPlayer2: TPlayer = nil;
254 gPlayerDrawn: TPlayer = nil;
255 gTime: LongWord;
256 gLerpFactor: Single = 1.0;
257 gSwitchGameMode: Byte = GM_DM;
258 gHearPoint1, gHearPoint2: THearPoint;
259 gSoundEffectsDF: Boolean = False;
260 gSoundTriggerTime: Word = 0;
261 gAnnouncer: Integer = ANNOUNCE_NONE;
262 goodsnd: array[0..3] of TPlayableSound;
263 killsnd: array[0..3] of TPlayableSound;
264 hahasnd: array[0..2] of TPlayableSound;
265 sound_get_flag: array[0..1] of TPlayableSound;
266 sound_lost_flag: array[0..1] of TPlayableSound;
267 sound_ret_flag: array[0..1] of TPlayableSound;
268 sound_cap_flag: array[0..1] of TPlayableSound;
269 gBodyKillEvent: Integer = -1;
270 gDefInterTime: ShortInt = -1;
271 gInterEndTime: LongWord = 0;
272 gInterTime: LongWord = 0;
273 gServInterTime: Byte = 0;
274 gGameStartTime: LongWord = 0;
275 gTotalMonsters: Integer = 0;
276 gPauseMain: Boolean = false;
277 gPauseHolmes: Boolean = false;
278 gShowTime: Boolean = False;
279 gShowFPS: Boolean = False;
280 gShowGoals: Boolean = True;
281 gShowStat: Boolean = True;
282 gShowPIDs: Boolean = False;
283 gShowKillMsg: Boolean = True;
284 gShowLives: Boolean = True;
285 gShowPing: Boolean = False;
286 gShowMap: Boolean = False;
287 gExit: Byte = 0;
288 gState: Byte = STATE_NONE;
289 sX, sY: Integer;
290 sWidth, sHeight: Word;
291 gSpectMode: Byte = SPECT_NONE;
292 gSpectHUD: Boolean = True;
293 gSpectKeyPress: Boolean = False;
294 gSpectX: Integer = 0;
295 gSpectY: Integer = 0;
296 gSpectStep: Byte = 8;
297 gSpectViewTwo: Boolean = False;
298 gSpectPID1: Integer = -1;
299 gSpectPID2: Integer = -1;
300 gSpectAuto: Boolean = False;
301 gSpectAutoNext: LongWord;
302 gSpectAutoStepX: Integer;
303 gSpectAutoStepY: Integer;
304 gMusic: TMusic = nil;
305 gLoadGameMode: Boolean;
306 gCheats: Boolean = False;
307 gMapOnce: Boolean = False;
308 gMapToDelete: String;
309 gTempDelete: Boolean = False;
310 gLastMap: Boolean = False;
311 gScreenWidth: Word;
312 gScreenHeight: Word;
313 gResolutionChange: Boolean = False;
314 gRC_Width, gRC_Height: Integer;
315 gRC_FullScreen, gRC_Maximized: Boolean;
316 gLanguageChange: Boolean = False;
317 gDebugMode: Boolean = False;
318 g_debug_Sounds: Boolean = False;
319 g_debug_Frames: Boolean = False;
320 g_debug_WinMsgs: Boolean = False;
321 g_debug_MonsterOff: Boolean = False;
322 g_debug_BotAIOff: Byte = 0;
323 g_debug_HealthBar: Boolean = False;
324 g_Debug_Player: Boolean = False;
325 gCoopMonstersKilled: Word = 0;
326 gCoopSecretsFound: Word = 0;
327 gCoopTotalMonstersKilled: Word = 0;
328 gCoopTotalSecretsFound: Word = 0;
329 gCoopTotalMonsters: Word = 0;
330 gCoopTotalSecrets: Word = 0;
331 gStatsOff: Boolean = False;
332 gStatsPressed: Boolean = False;
333 gExitByTrigger: Boolean = False;
334 gNextMap: String = '';
335 gLMSRespawn: Byte = LMS_RESPAWN_NONE;
336 gLMSRespawnTime: Cardinal = 0;
337 gLMSSoftSpawn: Boolean = False;
338 gMissionFailed: Boolean = False;
339 gVoteInProgress: Boolean = False;
340 gVotePassed: Boolean = False;
341 gVoteCommand: string = '';
342 gVoteTimer: Cardinal = 0;
343 gVoteCmdTimer: Cardinal = 0;
344 gVoteCount: Integer = 0;
345 gVoteTimeout: Cardinal = 30;
346 gVoted: Boolean = False;
347 gVotesEnabled: Boolean = True;
348 gEvents: Array of TGameEvent;
349 gDelayedEvents: Array of TDelayedEvent;
350 gUseChatSounds: Boolean = True;
351 gChatSounds: Array of TChatSound;
352 gSelectWeapon: Array [0..1, WP_FIRST..WP_LAST] of Boolean; // [player, weapon]
353 gInterReadyCount: Integer = 0;
355 g_dbg_ignore_bounds: Boolean = false;
356 r_smallmap_h: Integer = 0; // 0: left; 1: center; 2: right
357 r_smallmap_v: Integer = 2; // 0: top; 1: center; 2: bottom
359 // move button values:
360 // bits 0-1: l/r state:
361 // 0: neither left, nor right pressed
362 // 1: left pressed
363 // 2: right pressed
364 // bits 4-5: l/r state when strafe was pressed
365 P1MoveButton: Byte = 0;
366 P2MoveButton: Byte = 0;
368 g_profile_frame_update: Boolean = false;
369 g_profile_frame_draw: Boolean = false;
370 g_profile_collision: Boolean = false;
371 g_profile_los: Boolean = false;
372 g_profile_history_size: Integer = 1000;
374 g_rlayer_back: Boolean = true;
375 g_rlayer_step: Boolean = true;
376 g_rlayer_wall: Boolean = true;
377 g_rlayer_door: Boolean = true;
378 g_rlayer_acid1: Boolean = true;
379 g_rlayer_acid2: Boolean = true;
380 g_rlayer_water: Boolean = true;
381 g_rlayer_fore: Boolean = true;
383 wNeedTimeReset: Boolean = false;
385 procedure g_ResetDynlights ();
386 procedure g_AddDynLight (x, y, radius: Integer; r, g, b, a: Single);
387 procedure g_DynLightExplosion (x, y, radius: Integer; r, g, b: Single);
389 function conIsCheatsEnabled (): Boolean; inline;
390 function gPause (): Boolean; inline;
392 type (* private state *)
393 TEndCustomGameStat = record
394 PlayerStat: TPlayerStatArray;
395 TeamStat: TTeamStat;
396 GameTime: LongWord;
397 GameMode: Byte;
398 Map, MapName: String;
399 end;
401 TEndSingleGameStat = record
402 PlayerStat: Array [0..1] of record
403 Kills: Integer;
404 Secrets: Integer;
405 end;
406 GameTime: LongWord;
407 TwoPlayers: Boolean;
408 TotalSecrets: Integer;
409 end;
411 TLoadingStat = record
412 CurValue: Integer;
413 MaxValue: Integer;
414 ShowCount: Integer;
415 Msgs: Array of String;
416 NextMsg: Word;
417 PBarWasHere: Boolean; // did we draw a progress bar for this message?
418 end;
420 TDynLight = record
421 x, y, radius: Integer;
422 r, g, b, a: Single;
423 exploCount: Integer;
424 exploRadius: Integer;
425 end;
427 var (* private state *)
428 CustomStat: TEndCustomGameStat;
429 StatShotDone: Boolean;
430 StatFilename: string = ''; // used by stat screenshot to save with the same name as the csv
431 SingleStat: TEndSingleGameStat;
432 LoadingStat: TLoadingStat;
433 MessageText: String;
434 IsDrawStat: Boolean;
435 EndingGameCounter: Byte;
436 UPS: Word;
437 g_playerLight: Boolean;
438 g_dynLights: array of TDynLight = nil;
439 g_dynLightCount: Integer = 0;
440 EndPicPath: AnsiString; // full path, used by render
442 implementation
444 uses
445 {$IFDEF ENABLE_HOLMES}
446 g_holmes,
447 {$ENDIF}
448 {$IFDEF ENABLE_MENU}
449 g_menu,
450 {$ENDIF}
451 {$IFNDEF HEADLESS}
452 r_render, 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_gfx, g_options, Math,
457 g_triggers, g_monsters, e_sound, CONFIG,
458 g_language, g_net, g_phys,
459 ENet, e_msg, g_netmsg, g_netmaster,
460 sfs, wadreader;
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 {$IFNDEF HEADLESS}
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 Rewrite(s);
981 // line 1: stats ver, datetime, server name, map name, game mode, time limit, score limit, dmflags, game time, num players
982 if g_Game_IsNet then fname := NetServerName else fname := '';
983 map := g_ExtractWadNameNoPath(gMapInfo.Map) + ':/' + g_ExtractFileName(gMapInfo.Map);
984 mode := g_Game_ModeToText(Stat.GameMode);
985 etime := Format('%d:%.2d:%.2d', [
986 Stat.GameTime div 1000 div 3600,
987 (Stat.GameTime div 1000 div 60) mod 60,
988 Stat.GameTime div 1000 mod 60
989 ]);
990 WriteLn(s, 'stats_ver,datetime,server,map,mode,timelimit,scorelimit,dmflags,time,num_players');
991 WriteLn(s, Format('%d,%s,%s,%s,%s,%u,%u,%u,%s,%d', [
992 STATFILE_VERSION,
993 StatDate,
994 dquoteStr(fname),
995 dquoteStr(map),
996 mode,
997 gGameSettings.TimeLimit,
998 gGameSettings.GoalLimit,
999 gGameSettings.Options,
1000 etime,
1001 Length(Stat.PlayerStat)
1002 ]));
1003 // line 2: game specific shit
1004 // if it's a team game: red score, blue score
1005 // if it's a coop game: monsters killed, monsters total, secrets found, secrets total
1006 // otherwise nothing
1007 if Stat.GameMode in [GM_TDM, GM_CTF] then
1008 WriteLn(s,
1009 Format('red_score,blue_score' + LineEnding + '%d,%d', [Stat.TeamStat[TEAM_RED].Goals, Stat.TeamStat[TEAM_BLUE].Goals]))
1010 else if Stat.GameMode in [GM_COOP, GM_SINGLE] then
1011 WriteLn(s,
1012 Format('mon_killed,mon_total,secrets_found,secrets_total' + LineEnding + '%d,%d,%d,%d',[gCoopMonstersKilled, gTotalMonsters, gCoopSecretsFound, gSecretsCount]));
1013 // lines 3-...: team, player name, frags, deaths
1014 WriteLn(s, 'team,name,frags,deaths');
1015 for I := Low(Stat.PlayerStat) to High(Stat.PlayerStat) do
1016 with Stat.PlayerStat[I] do
1017 WriteLn(s, Format('%d,%s,%d,%d', [Team, dquoteStr(Name), Frags, Deaths]));
1018 except
1019 g_Console_Add(Format(_lc[I_CONSOLE_ERROR_WRITE], [fname]));
1020 end;
1021 except
1022 g_Console_Add('could not create gamestats file "' + fname + '"');
1023 end;
1024 CloseFile(s);
1025 end;
1027 function g_Game_ModeToText(Mode: Byte): string;
1028 begin
1029 Result := '';
1030 case Mode of
1031 GM_DM: Result := _lc[I_MENU_GAME_TYPE_DM];
1032 GM_TDM: Result := _lc[I_MENU_GAME_TYPE_TDM];
1033 GM_CTF: Result := _lc[I_MENU_GAME_TYPE_CTF];
1034 GM_COOP: Result := _lc[I_MENU_GAME_TYPE_COOP];
1035 GM_SINGLE: Result := _lc[I_MENU_GAME_TYPE_SINGLE];
1036 end;
1037 end;
1039 function g_Game_TextToMode(Mode: string): Byte;
1040 begin
1041 Result := GM_NONE;
1042 Mode := UpperCase(Mode);
1043 if Mode = _lc[I_MENU_GAME_TYPE_DM] then
1044 begin
1045 Result := GM_DM;
1046 Exit;
1047 end;
1048 if Mode = _lc[I_MENU_GAME_TYPE_TDM] then
1049 begin
1050 Result := GM_TDM;
1051 Exit;
1052 end;
1053 if Mode = _lc[I_MENU_GAME_TYPE_CTF] then
1054 begin
1055 Result := GM_CTF;
1056 Exit;
1057 end;
1058 if Mode = _lc[I_MENU_GAME_TYPE_COOP] then
1059 begin
1060 Result := GM_COOP;
1061 Exit;
1062 end;
1063 if Mode = _lc[I_MENU_GAME_TYPE_SINGLE] then
1064 begin
1065 Result := GM_SINGLE;
1066 Exit;
1067 end;
1068 end;
1070 function g_Game_IsNet(): Boolean;
1071 begin
1072 Result := (gGameSettings.GameType in [GT_SERVER, GT_CLIENT]);
1073 end;
1075 function g_Game_IsServer(): Boolean;
1076 begin
1077 Result := (gGameSettings.GameType in [GT_SINGLE, GT_CUSTOM, GT_SERVER]);
1078 end;
1080 function g_Game_IsClient(): Boolean;
1081 begin
1082 Result := (gGameSettings.GameType = GT_CLIENT);
1083 end;
1085 function g_Game_GetMegaWADInfo(WAD: String): TMegaWADInfo;
1086 var
1087 w: TWADFile;
1088 cfg: TConfig;
1089 p: Pointer;
1090 len: Integer;
1091 begin
1092 Result.name := ExtractFileName(WAD);
1093 Result.description := '';
1094 Result.author := '';
1096 w := TWADFile.Create();
1097 w.ReadFile(WAD);
1099 if not w.GetResource('INTERSCRIPT', p, len) then
1100 begin
1101 w.Free();
1102 Exit;
1103 end;
1105 cfg := TConfig.CreateMem(p, len);
1106 Result.name := cfg.ReadStr('megawad', 'name', ExtractFileName(WAD));
1107 Result.description := cfg.ReadStr('megawad', 'description', '');
1108 Result.author := cfg.ReadStr('megawad', 'author', '');
1109 Result.pic := cfg.ReadStr('megawad', 'pic', '');
1110 cfg.Free();
1112 FreeMem(p);
1113 end;
1115 procedure g_Game_FreeWAD;
1116 begin
1117 EndPicPath := '';
1118 g_Sound_Delete('MUSIC_endmus');
1119 ZeroMemory(@MegaWAD, SizeOf(MegaWAD));
1120 gGameSettings.WAD := '';
1121 end;
1123 procedure g_Game_LoadWAD(WAD: string);
1124 var
1125 w: TWADFile;
1126 cfg: TConfig;
1127 p: Pointer;
1128 len: Integer;
1129 s: AnsiString;
1130 begin
1131 g_Game_FreeWAD();
1132 gGameSettings.WAD := WAD;
1133 if not (gGameSettings.GameMode in [GM_COOP, GM_SINGLE]) then
1134 Exit;
1136 MegaWAD.info := g_Game_GetMegaWADInfo(WAD);
1138 w := TWADFile.Create();
1139 w.ReadFile(WAD);
1141 if not w.GetResource('INTERSCRIPT', p, len) then
1142 begin
1143 w.Free();
1144 Exit;
1145 end;
1147 cfg := TConfig.CreateMem(p, len);
1149 EndPicPath := '';
1150 MegaWAD.endpic := cfg.ReadStr('megawad', 'endpic', '');
1151 if MegaWAD.endpic <> '' then
1152 EndPicPath := e_GetResourcePath(WadDirs, MegaWAD.endpic, WAD);
1154 MegaWAD.endmus := cfg.ReadStr('megawad', 'endmus', 'Standart.wad:D2DMUS\КОНЕЦ');
1155 if MegaWAD.endmus <> '' then
1156 begin
1157 s := e_GetResourcePath(WadDirs, MegaWAD.endmus, WAD);
1158 g_Sound_CreateWADEx('MUSIC_endmus', s, True);
1159 end;
1161 cfg.Free();
1162 FreeMem(p);
1163 w.Free();
1164 end;
1166 {procedure start_trigger(t: string);
1167 begin
1168 end;
1170 function next_trigger(): Boolean;
1171 begin
1172 end;}
1174 procedure DisableCheats();
1175 begin
1176 MAX_RUNVEL := 8;
1177 VEL_JUMP := 10;
1178 gFly := False;
1180 if gPlayer1 <> nil then gPlayer1.GodMode := False;
1181 if gPlayer2 <> nil then gPlayer2.GodMode := False;
1182 if gPlayer1 <> nil then gPlayer1.NoTarget := False;
1183 if gPlayer2 <> nil then gPlayer2.NoTarget := False;
1185 {$IF DEFINED(D2F_DEBUG)}
1186 if gPlayer1 <> nil then gPlayer1.NoTarget := True;
1187 gAimLine := g_dbg_aimline_on;
1188 {$ENDIF}
1189 end;
1191 procedure g_Game_ExecuteEvent(Name: String);
1192 var
1193 a: Integer;
1194 begin
1195 if Name = '' then
1196 Exit;
1197 if gEvents = nil then
1198 Exit;
1199 for a := 0 to High(gEvents) do
1200 if gEvents[a].Name = Name then
1201 begin
1202 if gEvents[a].Command <> '' then
1203 g_Console_Process(gEvents[a].Command, True);
1204 break;
1205 end;
1206 end;
1208 function g_Game_DelayEvent(DEType: Byte; Time: LongWord; Num: Integer = 0; Str: String = ''): Integer;
1209 var
1210 a, n: Integer;
1211 begin
1212 n := -1;
1213 if gDelayedEvents <> nil then
1214 for a := 0 to High(gDelayedEvents) do
1215 if not gDelayedEvents[a].Pending then
1216 begin
1217 n := a;
1218 break;
1219 end;
1220 if n = -1 then
1221 begin
1222 SetLength(gDelayedEvents, Length(gDelayedEvents) + 1);
1223 n := High(gDelayedEvents);
1224 end;
1225 gDelayedEvents[n].Pending := True;
1226 gDelayedEvents[n].DEType := DEType;
1227 gDelayedEvents[n].DENum := Num;
1228 gDelayedEvents[n].DEStr := Str;
1229 if DEType = DE_GLOBEVENT then
1230 gDelayedEvents[n].Time := (GetTickCount64() {div 1000}) + Time
1231 else
1232 gDelayedEvents[n].Time := gTime + Time;
1233 Result := n;
1234 end;
1236 procedure EndGame();
1237 var
1238 a: Integer;
1239 FileName: string;
1240 t: TDateTime;
1241 begin
1242 if g_Game_IsNet and g_Game_IsServer then
1243 MH_SEND_GameEvent(NET_EV_MAPEND, Byte(gMissionFailed));
1245 // Стоп игра:
1246 gPauseMain := false;
1247 gPauseHolmes := false;
1248 gGameOn := false;
1250 g_Game_StopAllSounds(False);
1252 MessageTime := 0;
1253 MessageText := '';
1255 EndingGameCounter := 0;
1257 {$IFDEF ENABLE_MENU}
1258 g_ActiveWindow := nil;
1259 {$ENDIF}
1261 gLMSRespawn := LMS_RESPAWN_NONE;
1262 gLMSRespawnTime := 0;
1264 case gExit of
1265 EXIT_SIMPLE: // Выход через меню или конец теста
1266 begin
1267 g_Game_Free();
1268 if gMapOnce then
1269 begin // Это был тест
1270 g_Game_Quit();
1271 end
1272 else
1273 begin // Выход в главное меню
1274 {$IFDEF DISABLE_MENU}
1275 gState := STATE_MENU; // ???
1276 {$ELSE}
1277 gMusic.SetByName('MUSIC_MENU');
1278 gMusic.Play();
1279 if gState <> STATE_SLIST then
1280 begin
1281 g_GUI_ShowWindow('MainMenu');
1282 gState := STATE_MENU;
1283 end
1284 else
1285 begin
1286 // Обновляем список серверов
1287 slReturnPressed := True;
1288 if g_Net_Slist_Fetch(slCurrent) then
1289 begin
1290 if slCurrent = nil then
1291 slWaitStr := _lc[I_NET_SLIST_NOSERVERS];
1292 end
1293 else
1294 slWaitStr := _lc[I_NET_SLIST_ERROR];
1295 g_Serverlist_GenerateTable(slCurrent, slTable);
1296 end;
1297 {$ENDIF}
1298 g_Game_ExecuteEvent('ongameend');
1299 end;
1300 end;
1302 EXIT_RESTART: // Начать уровень сначала
1303 begin
1304 if not g_Game_IsClient then g_Game_Restart();
1305 end;
1307 EXIT_ENDLEVELCUSTOM: // Закончился уровень в Своей игре
1308 begin
1309 // Статистика Своей игры:
1310 FileName := g_ExtractWadName(gMapInfo.Map);
1312 CustomStat.GameTime := gTime;
1313 CustomStat.Map := ExtractFileName(FileName)+':'+g_ExtractFileName(gMapInfo.Map); //ResName;
1314 CustomStat.MapName := gMapInfo.Name;
1315 CustomStat.GameMode := gGameSettings.GameMode;
1316 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
1317 CustomStat.TeamStat := gTeamStat;
1319 CustomStat.PlayerStat := nil;
1321 // Статистика игроков:
1322 if gPlayers <> nil then
1323 begin
1324 for a := 0 to High(gPlayers) do
1325 if gPlayers[a] <> nil then
1326 begin
1327 SetLength(CustomStat.PlayerStat, Length(CustomStat.PlayerStat)+1);
1328 with CustomStat.PlayerStat[High(CustomStat.PlayerStat)] do
1329 begin
1330 Num := a;
1331 Name := gPlayers[a].Name;
1332 Frags := gPlayers[a].Frags;
1333 Deaths := gPlayers[a].Death;
1334 Kills := gPlayers[a].Kills;
1335 Team := gPlayers[a].Team;
1336 Color := gPlayers[a].Model.Color;
1337 Spectator := gPlayers[a].FSpectator;
1338 end;
1339 end;
1341 SortGameStat(CustomStat.PlayerStat);
1343 if (gSaveStats or gScreenshotStats) and (Length(CustomStat.PlayerStat) > 1) then
1344 begin
1345 t := Now;
1346 if g_Game_IsNet then StatFilename := NetServerName else StatFilename := 'local';
1347 StatDate := FormatDateTime('yymmdd_hhnnss', t);
1348 StatFilename := StatFilename + '_' + CustomStat.Map + '_' + g_Game_ModeToText(CustomStat.GameMode);
1349 StatFilename := sanitizeFilename(StatFilename) + '_' + StatDate;
1350 if gSaveStats then
1351 SaveGameStat(CustomStat, FormatDateTime('yyyy"/"mm"/"dd', t));
1352 end;
1354 StatShotDone := False;
1355 end;
1357 g_Game_ExecuteEvent('onmapend');
1358 if not g_Game_IsClient then g_Player_ResetReady;
1359 gInterReadyCount := 0;
1361 // Затухающий экран:
1362 EndingGameCounter := 255;
1363 gState := STATE_FOLD;
1364 gInterTime := 0;
1365 if gDefInterTime < 0 then
1366 gInterEndTime := IfThen((gGameSettings.GameType = GT_SERVER) and (gPlayer1 = nil), 15000, 25000)
1367 else
1368 gInterEndTime := gDefInterTime * 1000;
1369 end;
1371 EXIT_ENDLEVELSINGLE: // Закончился уровень в Одиночной игре
1372 begin
1373 // Статистика Одиночной игры:
1374 SingleStat.GameTime := gTime;
1375 SingleStat.TwoPlayers := gPlayer2 <> nil;
1376 SingleStat.TotalSecrets := gSecretsCount;
1377 // Статистика первого игрока:
1378 SingleStat.PlayerStat[0].Kills := gPlayer1.MonsterKills;
1379 SingleStat.PlayerStat[0].Secrets := gPlayer1.Secrets;
1380 // Статистика второго игрока (если есть):
1381 if SingleStat.TwoPlayers then
1382 begin
1383 SingleStat.PlayerStat[1].Kills := gPlayer2.MonsterKills;
1384 SingleStat.PlayerStat[1].Secrets := gPlayer2.Secrets;
1385 end;
1387 g_Game_ExecuteEvent('onmapend');
1389 // Есть еще карты:
1390 if gNextMap <> '' then
1391 begin
1392 gMusic.SetByName('MUSIC_INTERMUS');
1393 gMusic.Play();
1394 gState := STATE_INTERSINGLE;
1395 e_UnpressAllKeys();
1397 g_Game_ExecuteEvent('oninter');
1398 end
1399 else // Больше нет карт
1400 begin
1401 // Затухающий экран:
1402 EndingGameCounter := 255;
1403 gState := STATE_FOLD;
1404 end;
1405 end;
1406 end;
1408 // Окончание обработано:
1409 if gExit <> EXIT_QUIT then
1410 gExit := 0;
1411 end;
1413 procedure g_Game_Init();
1414 begin
1415 gExit := 0;
1416 gMapToDelete := '';
1417 gTempDelete := False;
1419 sfsGCDisable(); // temporary disable removing of temporary volumes
1421 try
1422 g_Game_ClearLoading();
1423 g_Game_SetLoadingText(Format('Doom 2D: Forever %s', [GAME_VERSION]), 0, False);
1424 g_Game_SetLoadingText('', 0, False);
1426 // g_Game_SetLoadingText(_lc[I_LOAD_MODELS], 0, False);
1428 gGameOn := false;
1429 gPauseMain := false;
1430 gPauseHolmes := false;
1431 gTime := 0;
1433 {e_MouseInfo.Accel := 1.0;}
1435 g_Game_SetLoadingText(_lc[I_LOAD_GAME_DATA], 0, False);
1436 g_Game_LoadData();
1438 g_Game_SetLoadingText(_lc[I_LOAD_MUSIC], 0, False);
1439 g_Sound_CreateWADEx('MUSIC_INTERMUS', GameWAD+':MUSIC\INTERMUS', True);
1440 g_Sound_CreateWADEx('MUSIC_MENU', GameWAD+':MUSIC\MENU', True);
1441 g_Sound_CreateWADEx('MUSIC_ROUNDMUS', GameWAD+':MUSIC\ROUNDMUS', True, True);
1442 g_Sound_CreateWADEx('MUSIC_STDENDMUS', GameWAD+':MUSIC\ENDMUS', True);
1444 gMusic := TMusic.Create();
1445 gMusic.SetByName('MUSIC_MENU');
1446 gMusic.Play();
1448 gGameSettings.WarmupTime := 30;
1450 gState := STATE_MENU;
1452 SetLength(gEvents, 6);
1453 gEvents[0].Name := 'ongamestart';
1454 gEvents[1].Name := 'ongameend';
1455 gEvents[2].Name := 'onmapstart';
1456 gEvents[3].Name := 'onmapend';
1457 gEvents[4].Name := 'oninter';
1458 gEvents[5].Name := 'onwadend';
1459 finally
1460 sfsGCEnable(); // enable releasing unused volumes
1461 end;
1462 end;
1464 procedure g_Game_Free(freeTextures: Boolean=true);
1465 begin
1466 if NetMode = NET_CLIENT then g_Net_Disconnect();
1467 if NetMode = NET_SERVER then g_Net_Host_Die();
1469 g_Map_Free(freeTextures);
1470 g_Player_Free();
1471 g_Player_RemoveAllCorpses();
1473 gGameSettings.GameType := GT_NONE;
1474 if gGameSettings.GameMode = GM_SINGLE then
1475 gGameSettings.GameMode := GM_DM;
1476 gSwitchGameMode := gGameSettings.GameMode;
1478 gChatShow := False;
1479 gExitByTrigger := False;
1480 end;
1482 function IsActivePlayer(p: TPlayer): Boolean;
1483 begin
1484 Result := False;
1485 if p = nil then
1486 Exit;
1487 Result := (not p.FDummy) and (not p.FSpectator);
1488 end;
1490 function GetActivePlayerID_Next(Skip: Integer = -1): Integer;
1491 var
1492 a, idx: Integer;
1493 ids: Array of Word;
1494 begin
1495 Result := -1;
1496 if gPlayers = nil then
1497 Exit;
1498 SetLength(ids, 0);
1499 idx := -1;
1500 for a := Low(gPlayers) to High(gPlayers) do
1501 if IsActivePlayer(gPlayers[a]) then
1502 begin
1503 SetLength(ids, Length(ids) + 1);
1504 ids[High(ids)] := gPlayers[a].UID;
1505 if gPlayers[a].UID = Skip then
1506 idx := High(ids);
1507 end;
1508 if Length(ids) = 0 then
1509 Exit;
1510 if idx = -1 then
1511 Result := ids[0]
1512 else
1513 Result := ids[(idx + 1) mod Length(ids)];
1514 end;
1516 function GetActivePlayerID_Prev(Skip: Integer = -1): Integer;
1517 var
1518 a, idx: Integer;
1519 ids: Array of Word;
1520 begin
1521 Result := -1;
1522 if gPlayers = nil then
1523 Exit;
1524 SetLength(ids, 0);
1525 idx := -1;
1526 for a := Low(gPlayers) to High(gPlayers) do
1527 if IsActivePlayer(gPlayers[a]) then
1528 begin
1529 SetLength(ids, Length(ids) + 1);
1530 ids[High(ids)] := gPlayers[a].UID;
1531 if gPlayers[a].UID = Skip then
1532 idx := High(ids);
1533 end;
1534 if Length(ids) = 0 then
1535 Exit;
1536 if idx = -1 then
1537 Result := ids[Length(ids) - 1]
1538 else
1539 Result := ids[(Length(ids) - 1 + idx) mod Length(ids)];
1540 end;
1542 function GetActivePlayerID_Random(Skip: Integer = -1): Integer;
1543 var
1544 a, idx: Integer;
1545 ids: Array of Word;
1546 begin
1547 Result := -1;
1548 if gPlayers = nil then
1549 Exit;
1550 SetLength(ids, 0);
1551 idx := -1;
1552 for a := Low(gPlayers) to High(gPlayers) do
1553 if IsActivePlayer(gPlayers[a]) then
1554 begin
1555 SetLength(ids, Length(ids) + 1);
1556 ids[High(ids)] := gPlayers[a].UID;
1557 if gPlayers[a].UID = Skip then
1558 idx := High(ids);
1559 end;
1560 if Length(ids) = 0 then
1561 Exit;
1562 if Length(ids) = 1 then
1563 begin
1564 Result := ids[0];
1565 Exit;
1566 end;
1567 Result := ids[Random(Length(ids))];
1568 a := 10;
1569 while (idx <> -1) and (Result = Skip) and (a > 0) do
1570 begin
1571 Result := ids[Random(Length(ids))];
1572 Dec(a);
1573 end;
1574 end;
1576 function GetRandomSpectMode(Current: Byte): Byte;
1577 label
1578 retry;
1579 begin
1580 Result := Current;
1581 retry:
1582 case Random(7) of
1583 0: Result := SPECT_STATS;
1584 1: Result := SPECT_MAPVIEW;
1585 2: Result := SPECT_MAPVIEW;
1586 3: Result := SPECT_PLAYERS;
1587 4: Result := SPECT_PLAYERS;
1588 5: Result := SPECT_PLAYERS;
1589 6: Result := SPECT_PLAYERS;
1590 end;
1591 if (Current in [SPECT_STATS, SPECT_MAPVIEW]) and (Current = Result) then
1592 goto retry;
1593 end;
1595 procedure ProcessPlayerControls (plr: TPlayer; p: Integer; var MoveButton: Byte);
1596 var
1597 time: Word;
1598 strafeDir: Byte;
1599 i: Integer;
1600 begin
1601 if (plr = nil) then exit;
1602 if (p = 2) then time := 1000 else time := 1;
1603 strafeDir := MoveButton shr 4;
1604 MoveButton := MoveButton and $0F;
1606 if gPlayerAction[p, ACTION_MOVELEFT] and (not gPlayerAction[p, ACTION_MOVERIGHT]) then
1607 MoveButton := 1 // Нажата только "Влево"
1608 else if (not gPlayerAction[p, ACTION_MOVELEFT]) and gPlayerAction[p, ACTION_MOVERIGHT] then
1609 MoveButton := 2 // Нажата только "Вправо"
1610 else if (not gPlayerAction[p, ACTION_MOVELEFT]) and (not gPlayerAction[p, ACTION_MOVERIGHT]) then
1611 MoveButton := 0; // Не нажаты ни "Влево", ни "Вправо"
1613 // Сейчас или раньше были нажаты "Влево"/"Вправо" => передаем игроку:
1614 if MoveButton = 1 then
1615 plr.PressKey(KEY_LEFT, time)
1616 else if MoveButton = 2 then
1617 plr.PressKey(KEY_RIGHT, time);
1619 // if we have "strafe" key, turn off old strafe mechanics
1620 if gPlayerAction[p, ACTION_STRAFE] then
1621 begin
1622 // new strafe mechanics
1623 if (strafeDir = 0) then
1624 strafeDir := MoveButton; // start strafing
1625 // now set direction according to strafe (reversed)
1626 if (strafeDir = 2) then
1627 plr.SetDirection(TDirection.D_LEFT)
1628 else if (strafeDir = 1) then
1629 plr.SetDirection(TDirection.D_RIGHT)
1630 end
1631 else
1632 begin
1633 strafeDir := 0; // not strafing anymore
1634 // Раньше была нажата "Вправо", а сейчас "Влево" => бежим вправо, смотрим влево:
1635 if (MoveButton = 2) and gPlayerAction[p, ACTION_MOVELEFT] then
1636 plr.SetDirection(TDirection.D_LEFT)
1637 // Раньше была нажата "Влево", а сейчас "Вправо" => бежим влево, смотрим вправо:
1638 else if (MoveButton = 1) and gPlayerAction[p, ACTION_MOVERIGHT] then
1639 plr.SetDirection(TDirection.D_RIGHT)
1640 // Что-то было нажато и не изменилось => куда бежим, туда и смотрим:
1641 else if MoveButton <> 0 then
1642 plr.SetDirection(TDirection(MoveButton-1))
1643 end;
1645 // fix movebutton state
1646 MoveButton := MoveButton or (strafeDir shl 4);
1648 // Остальные клавиши:
1649 if gPlayerAction[p, ACTION_JUMP] then plr.PressKey(KEY_JUMP, time);
1650 if gPlayerAction[p, ACTION_LOOKUP] then plr.PressKey(KEY_UP, time);
1651 if gPlayerAction[p, ACTION_LOOKDOWN] then plr.PressKey(KEY_DOWN, time);
1652 if gPlayerAction[p, ACTION_ATTACK] then plr.PressKey(KEY_FIRE);
1653 if gPlayerAction[p, ACTION_WEAPNEXT] then plr.PressKey(KEY_NEXTWEAPON);
1654 if gPlayerAction[p, ACTION_WEAPPREV] then plr.PressKey(KEY_PREVWEAPON);
1655 if gPlayerAction[p, ACTION_ACTIVATE] then plr.PressKey(KEY_OPEN);
1657 gPlayerAction[p, ACTION_WEAPNEXT] := False; // HACK, remove after readyweaon&pendinweapon implementation
1658 gPlayerAction[p, ACTION_WEAPPREV] := False; // HACK, remove after readyweaon&pendinweapon implementation
1660 for i := WP_FIRST to WP_LAST do
1661 begin
1662 if gSelectWeapon[p, i] then
1663 begin
1664 plr.QueueWeaponSwitch(i); // all choices are passed there, and god will take the best
1665 gSelectWeapon[p, i] := False
1666 end
1667 end;
1669 {$IFDEF ENABLE_MENU}
1670 // HACK: add dynlight here
1671 if gwin_k8_enable_light_experiments then
1672 begin
1673 if e_KeyPressed(IK_F8) and gGameOn and (not gConsoleShow) and (g_ActiveWindow = nil) then
1674 begin
1675 g_playerLight := true;
1676 end;
1677 if e_KeyPressed(IK_F9) and gGameOn and (not gConsoleShow) and (g_ActiveWindow = nil) then
1678 begin
1679 g_playerLight := false;
1680 end;
1681 end;
1683 if gwin_has_stencil and g_playerLight then g_AddDynLight(plr.GameX+32, plr.GameY+40, 128, 1, 1, 0, 0.6);
1684 {$ENDIF}
1685 end;
1687 // HACK: don't have a "key was pressed" function
1688 procedure InterReady();
1689 begin
1690 if InterReadyTime > gTime then Exit;
1691 InterReadyTime := gTime + 3000;
1692 MC_SEND_CheatRequest(NET_CHEAT_READY);
1693 end;
1695 procedure g_Game_PreUpdate();
1696 begin
1697 // these are in separate PreUpdate functions because they can interact during Update()
1698 // and are synced over the net
1699 // we don't care that much about corpses and gibs
1700 g_Player_PreUpdate();
1701 g_Monsters_PreUpdate();
1702 g_Items_PreUpdate();
1703 g_Weapon_PreUpdate();
1704 end;
1706 procedure g_Game_Update();
1707 var
1708 {$IFDEF ENABLE_MENU}
1709 Msg: g_gui.TMessage;
1710 w: Word;
1711 {$ENDIF}
1712 Time: Int64;
1713 a: Byte;
1714 i, b: Integer;
1716 function sendMonsPos (mon: TMonster): Boolean;
1717 begin
1718 result := false; // don't stop
1719 // this will also reset "need-send" flag
1720 if mon.gncNeedSend then
1721 begin
1722 MH_SEND_MonsterPos(mon.UID);
1723 end
1724 else if (mon.MonsterType = MONSTER_BARREL) then
1725 begin
1726 if (mon.GameVelX <> 0) or (mon.GameVelY <> 0) then MH_SEND_MonsterPos(mon.UID);
1727 end
1728 else if (mon.MonsterState <> MONSTATE_SLEEP) then
1729 begin
1730 if (mon.MonsterState <> MONSTATE_DEAD) or (mon.GameVelX <> 0) or (mon.GameVelY <> 0) then MH_SEND_MonsterPos(mon.UID);
1731 end;
1732 end;
1734 function sendMonsPosUnexpected (mon: TMonster): Boolean;
1735 begin
1736 result := false; // don't stop
1737 // this will also reset "need-send" flag
1738 if mon.gncNeedSend then MH_SEND_MonsterPos(mon.UID);
1739 end;
1741 var
1742 reliableUpdate: Boolean;
1743 begin
1744 g_ResetDynlights();
1745 framePool.reset();
1747 // Пора выключать игру:
1748 if gExit = EXIT_QUIT then
1749 Exit;
1750 // Игра закончилась - обрабатываем:
1751 if gExit <> 0 then
1752 begin
1753 EndGame();
1754 if gExit = EXIT_QUIT then
1755 Exit;
1756 end;
1758 // Читаем клавиатуру и джойстик, если окно активно
1759 // no need to, as we'll do it in event handler
1761 // Обновляем консоль (движение и сообщения):
1762 g_Console_Update();
1764 if (NetMode = NET_NONE) and (g_Game_IsNet) and (gGameOn or (gState in [STATE_FOLD, STATE_INTERCUSTOM])) then
1765 begin
1766 gExit := EXIT_SIMPLE;
1767 EndGame();
1768 Exit;
1769 end;
1771 // process master server communications
1772 g_Net_Slist_Pulse();
1774 case gState of
1775 STATE_INTERSINGLE, // Статистка после прохождения уровня в Одиночной игре
1776 STATE_INTERCUSTOM, // Статистка после прохождения уровня в Своей игре
1777 STATE_INTERTEXT, // Текст между уровнями
1778 STATE_INTERPIC: // Картинка между уровнями
1779 begin
1780 if g_Game_IsNet and g_Game_IsServer then
1781 begin
1782 gInterTime := gInterTime + GAME_TICK;
1783 a := Min((gInterEndTime - gInterTime) div 1000 + 1, 255);
1784 if a <> gServInterTime then
1785 begin
1786 gServInterTime := a;
1787 MH_SEND_TimeSync(gServInterTime);
1788 end;
1789 end;
1791 if (not g_Game_IsClient) and
1795 e_KeyPressed(IK_RETURN) or e_KeyPressed(IK_KPRETURN) or e_KeyPressed(IK_SPACE) or
1796 e_KeyPressed(VK_FIRE) or e_KeyPressed(VK_OPEN) or
1797 e_KeyPressed(JOY0_ATTACK) or e_KeyPressed(JOY1_ATTACK) or
1798 e_KeyPressed(JOY2_ATTACK) or e_KeyPressed(JOY3_ATTACK)
1800 and (not gJustChatted) and (not gConsoleShow) and (not gChatShow)
1801 {$IFDEF ENABLE_MENU}
1802 and (g_ActiveWindow = nil)
1803 {$ENDIF}
1805 or (g_Game_IsNet and ((gInterTime > gInterEndTime) or ((gInterReadyCount >= NetClientCount) and (NetClientCount > 0))))
1807 then
1808 begin // Нажали <Enter>/<Пробел> или прошло достаточно времени:
1809 g_Game_StopAllSounds(True);
1811 if gMapOnce then // Это был тест
1812 gExit := EXIT_SIMPLE
1813 else
1814 if gNextMap <> '' then // Переходим на следующую карту
1815 g_Game_ChangeMap(gNextMap)
1816 else // Следующей карты нет
1817 begin
1818 if gGameSettings.GameType in [GT_CUSTOM, GT_SERVER] then
1819 begin
1820 // Выход в главное меню:
1821 g_Game_Free;
1822 {$IFDEF ENABLE_MENU}
1823 g_GUI_ShowWindow('MainMenu');
1824 gMusic.SetByName('MUSIC_MENU');
1825 gMusic.Play();
1826 {$ENDIF}
1827 gState := STATE_MENU;
1828 end else
1829 begin
1830 // Финальная картинка:
1831 g_Game_ExecuteEvent('onwadend');
1832 g_Game_Free();
1833 if not gMusic.SetByName('MUSIC_endmus') then
1834 gMusic.SetByName('MUSIC_STDENDMUS');
1835 gMusic.Play();
1836 gState := STATE_ENDPIC;
1837 end;
1838 g_Game_ExecuteEvent('ongameend');
1839 end;
1841 Exit;
1842 end
1843 else if g_Game_IsClient and
1846 e_KeyPressed(IK_RETURN) or e_KeyPressed(IK_KPRETURN) or e_KeyPressed(IK_SPACE) or
1847 e_KeyPressed(VK_FIRE) or e_KeyPressed(VK_OPEN) or
1848 e_KeyPressed(JOY0_ATTACK) or e_KeyPressed(JOY1_ATTACK) or
1849 e_KeyPressed(JOY2_ATTACK) or e_KeyPressed(JOY3_ATTACK)
1851 and (not gJustChatted) and (not gConsoleShow) and (not gChatShow)
1852 {$IFDEF ENABLE_MENU}
1853 and (g_ActiveWindow = nil)
1854 {$ENDIF}
1856 then
1857 begin
1858 // ready / unready
1859 InterReady();
1860 end;
1862 if gState = STATE_INTERTEXT then
1863 if InterText.counter > 0 then
1864 InterText.counter := InterText.counter - 1;
1865 end;
1867 STATE_FOLD: // Затухание экрана
1868 begin
1869 if EndingGameCounter = 0 then
1870 begin
1871 // Закончился уровень в Своей игре:
1872 if gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT] then
1873 begin
1874 InterReadyTime := -1;
1875 if gLastMap and (gGameSettings.GameMode = GM_COOP) then
1876 begin
1877 g_Game_ExecuteEvent('onwadend');
1878 if not gMusic.SetByName('MUSIC_endmus') then
1879 gMusic.SetByName('MUSIC_STDENDMUS');
1880 end
1881 else
1882 gMusic.SetByName('MUSIC_ROUNDMUS');
1884 gMusic.Play();
1885 gState := STATE_INTERCUSTOM;
1886 e_UnpressAllKeys();
1887 end
1888 else // Закончилась последняя карта в Одиночной игре
1889 begin
1890 gMusic.SetByName('MUSIC_INTERMUS');
1891 gMusic.Play();
1892 gState := STATE_INTERSINGLE;
1893 e_UnpressAllKeys();
1894 end;
1895 g_Game_ExecuteEvent('oninter');
1896 end
1897 else
1898 DecMin(EndingGameCounter, 6, 0);
1899 end;
1901 STATE_ENDPIC: // Картинка окончания мегаВада
1902 begin
1903 if gMapOnce then // Это был тест
1904 begin
1905 gExit := EXIT_SIMPLE;
1906 Exit;
1907 end;
1908 end;
1910 STATE_SLIST:
1911 g_Serverlist_Control(slCurrent, slTable);
1912 end;
1914 // Статистика по Tab:
1915 if gGameOn then
1916 IsDrawStat := (not gConsoleShow) and (not gChatShow) and (gGameSettings.GameType <> GT_SINGLE) and g_Console_Action(ACTION_SCORES);
1918 // Игра идет:
1919 if gGameOn and not gPause and (gState <> STATE_FOLD) then
1920 begin
1921 // Время += 28 миллисекунд:
1922 gTime := gTime + GAME_TICK;
1924 // Сообщение посередине экрана:
1925 if MessageTime = 0 then
1926 MessageText := '';
1927 if MessageTime > 0 then
1928 MessageTime := MessageTime - 1;
1930 if (g_Game_IsServer) then
1931 begin
1932 // Был задан лимит времени:
1933 if (gGameSettings.TimeLimit > 0) then
1934 if (gTime - gGameStartTime) div 1000 >= gGameSettings.TimeLimit then
1935 begin // Он прошел => конец уровня
1936 g_Game_NextLevel();
1937 Exit;
1938 end;
1940 // Надо респавнить игроков в LMS:
1941 if (gLMSRespawn > LMS_RESPAWN_NONE) and (gLMSRespawnTime < gTime) then
1942 g_Game_RestartRound(gLMSSoftSpawn);
1944 // Проверим результат голосования, если время прошло
1945 if gVoteInProgress and (gVoteTimer < gTime) then
1946 g_Game_CheckVote
1947 else if gVotePassed and (gVoteCmdTimer < gTime) then
1948 begin
1949 g_Console_Process(gVoteCommand);
1950 gVoteCommand := '';
1951 gVotePassed := False;
1952 end;
1954 // Замеряем время захвата флагов
1955 if gFlags[FLAG_RED].State = FLAG_STATE_CAPTURED then
1956 gFlags[FLAG_RED].CaptureTime := gFlags[FLAG_RED].CaptureTime + GAME_TICK;
1957 if gFlags[FLAG_BLUE].State = FLAG_STATE_CAPTURED then
1958 gFlags[FLAG_BLUE].CaptureTime := gFlags[FLAG_BLUE].CaptureTime + GAME_TICK;
1960 // Был задан лимит побед:
1961 if (gGameSettings.GoalLimit > 0) then
1962 begin
1963 b := 0;
1965 if gGameSettings.GameMode = GM_DM then
1966 begin // В DM ищем игрока с max фрагами
1967 for i := 0 to High(gPlayers) do
1968 if gPlayers[i] <> nil then
1969 if gPlayers[i].Frags > b then
1970 b := gPlayers[i].Frags;
1971 end
1972 else
1973 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
1974 begin // В CTF/TDM выбираем команду с наибольшим счетом
1975 b := Max(gTeamStat[TEAM_RED].Goals, gTeamStat[TEAM_BLUE].Goals);
1976 end;
1978 // Лимит побед набран => конец уровня:
1979 if b >= gGameSettings.GoalLimit then
1980 begin
1981 g_Game_NextLevel();
1982 Exit;
1983 end;
1984 end;
1986 // Обрабатываем клавиши игроков:
1987 if gPlayer1 <> nil then gPlayer1.ReleaseKeys();
1988 if gPlayer2 <> nil then gPlayer2.ReleaseKeys();
1989 {$IFDEF DISABLE_MENU}
1990 if (not gConsoleShow) and (not gChatShow) then
1991 {$ELSE}
1992 if (not gConsoleShow) and (not gChatShow) and (g_ActiveWindow = nil) then
1993 {$ENDIF}
1994 begin
1995 ProcessPlayerControls(gPlayer1, 0, P1MoveButton);
1996 ProcessPlayerControls(gPlayer2, 1, P2MoveButton);
1997 end // if not console
1998 else
1999 begin
2000 if g_Game_IsNet and (gPlayer1 <> nil) then gPlayer1.PressKey(KEY_CHAT, 10000);
2001 end;
2002 // process weapon switch queue
2003 end; // if server
2005 // Наблюдатель
2006 if (gPlayer1 = nil) and (gPlayer2 = nil)
2007 and (not gConsoleShow) and (not gChatShow)
2008 {$IFDEF ENABLE_MENU}
2009 and (g_ActiveWindow = nil)
2010 {$ENDIF}
2011 then
2012 begin
2013 if not gSpectKeyPress then
2014 begin
2015 if gPlayerAction[0, ACTION_JUMP] and (not gSpectAuto) then
2016 begin
2017 // switch spect mode
2018 case gSpectMode of
2019 SPECT_NONE: ; // not spectator
2020 SPECT_STATS,
2021 SPECT_MAPVIEW: Inc(gSpectMode);
2022 SPECT_PLAYERS: gSpectMode := SPECT_STATS; // reset to 1
2023 end;
2024 gSpectKeyPress := True;
2025 end;
2026 if (gSpectMode = SPECT_MAPVIEW)
2027 and (not gSpectAuto) then
2028 begin
2029 if gPlayerAction[0, ACTION_MOVELEFT] then
2030 gSpectX := Max(gSpectX - gSpectStep, 0);
2031 if gPlayerAction[0, ACTION_MOVERIGHT] then
2032 gSpectX := Min(gSpectX + gSpectStep, gMapInfo.Width - gScreenWidth);
2033 if gPlayerAction[0, ACTION_LOOKUP] then
2034 gSpectY := Max(gSpectY - gSpectStep, 0);
2035 if gPlayerAction[0, ACTION_LOOKDOWN] then
2036 gSpectY := Min(gSpectY + gSpectStep, gMapInfo.Height - gScreenHeight);
2037 if gPlayerAction[0, ACTION_WEAPPREV] then
2038 begin
2039 // decrease step
2040 if gSpectStep > 4 then gSpectStep := gSpectStep shr 1;
2041 gSpectKeyPress := True;
2042 end;
2043 if gPlayerAction[0, ACTION_WEAPNEXT] then
2044 begin
2045 // increase step
2046 if gSpectStep < 64 then gSpectStep := gSpectStep shl 1;
2047 gSpectKeyPress := True;
2048 end;
2049 end;
2050 if (gSpectMode = SPECT_PLAYERS)
2051 and (not gSpectAuto) then
2052 begin
2053 if gPlayerAction[0, ACTION_LOOKUP] then
2054 begin
2055 // add second view
2056 gSpectViewTwo := True;
2057 gSpectKeyPress := True;
2058 end;
2059 if gPlayerAction[0, ACTION_LOOKDOWN] then
2060 begin
2061 // remove second view
2062 gSpectViewTwo := False;
2063 gSpectKeyPress := True;
2064 end;
2065 if gPlayerAction[0, ACTION_MOVELEFT] then
2066 begin
2067 // prev player (view 1)
2068 gSpectPID1 := GetActivePlayerID_Prev(gSpectPID1);
2069 gSpectKeyPress := True;
2070 end;
2071 if gPlayerAction[0, ACTION_MOVERIGHT] then
2072 begin
2073 // next player (view 1)
2074 gSpectPID1 := GetActivePlayerID_Next(gSpectPID1);
2075 gSpectKeyPress := True;
2076 end;
2077 if gPlayerAction[0, ACTION_WEAPPREV] then
2078 begin
2079 // prev player (view 2)
2080 gSpectPID2 := GetActivePlayerID_Prev(gSpectPID2);
2081 gSpectKeyPress := True;
2082 end;
2083 if gPlayerAction[0, ACTION_WEAPNEXT] then
2084 begin
2085 // next player (view 2)
2086 gSpectPID2 := GetActivePlayerID_Next(gSpectPID2);
2087 gSpectKeyPress := True;
2088 end;
2089 end;
2090 if gPlayerAction[0, ACTION_ATTACK] then
2091 begin
2092 if (gSpectMode = SPECT_STATS) and (not gSpectAuto) then
2093 begin
2094 gSpectAuto := True;
2095 gSpectAutoNext := 0;
2096 gSpectViewTwo := False;
2097 gSpectKeyPress := True;
2098 end
2099 else
2100 if gSpectAuto then
2101 begin
2102 gSpectMode := SPECT_STATS;
2103 gSpectAuto := False;
2104 gSpectKeyPress := True;
2105 end;
2106 end;
2107 end
2108 else
2109 if (not gPlayerAction[0, ACTION_JUMP]) and
2110 (not gPlayerAction[0, ACTION_ATTACK]) and
2111 (not gPlayerAction[0, ACTION_MOVELEFT]) and
2112 (not gPlayerAction[0, ACTION_MOVERIGHT]) and
2113 (not gPlayerAction[0, ACTION_LOOKUP]) and
2114 (not gPlayerAction[0, ACTION_LOOKDOWN]) and
2115 (not gPlayerAction[0, ACTION_WEAPPREV]) and
2116 (not gPlayerAction[0, ACTION_WEAPNEXT]) then
2117 gSpectKeyPress := False;
2119 if gSpectAuto then
2120 begin
2121 if gSpectMode = SPECT_MAPVIEW then
2122 begin
2123 i := Min(Max(gSpectX + gSpectAutoStepX, 0), gMapInfo.Width - gScreenWidth);
2124 if i = gSpectX then
2125 gSpectAutoNext := gTime
2126 else
2127 gSpectX := i;
2128 i := Min(Max(gSpectY + gSpectAutoStepY, 0), gMapInfo.Height - gScreenHeight);
2129 if i = gSpectY then
2130 gSpectAutoNext := gTime
2131 else
2132 gSpectY := i;
2133 end;
2134 if gSpectAutoNext <= gTime then
2135 begin
2136 if gSpectAutoNext > 0 then
2137 begin
2138 gSpectMode := GetRandomSpectMode(gSpectMode);
2139 case gSpectMode of
2140 SPECT_MAPVIEW:
2141 begin
2142 gSpectX := Random(gMapInfo.Width - gScreenWidth);
2143 gSpectY := Random(gMapInfo.Height - gScreenHeight);
2144 gSpectAutoStepX := Random(9) - 4;
2145 gSpectAutoStepY := Random(9) - 4;
2146 if ((gSpectX < 800) and (gSpectAutoStepX < 0)) or
2147 ((gSpectX > gMapInfo.Width - gScreenWidth - 800) and (gSpectAutoStepX > 0)) then
2148 gSpectAutoStepX := gSpectAutoStepX * -1;
2149 if ((gSpectY < 800) and (gSpectAutoStepY < 0)) or
2150 ((gSpectY > gMapInfo.Height - gScreenHeight - 800) and (gSpectAutoStepY > 0)) then
2151 gSpectAutoStepY := gSpectAutoStepY * -1;
2152 end;
2153 SPECT_PLAYERS:
2154 begin
2155 gSpectPID1 := GetActivePlayerID_Random(gSpectPID1);
2156 end;
2157 end;
2158 end;
2159 case gSpectMode of
2160 SPECT_STATS: gSpectAutoNext := gTime + (Random(3) + 5) * 1000;
2161 SPECT_MAPVIEW: gSpectAutoNext := gTime + (Random(4) + 7) * 1000;
2162 SPECT_PLAYERS: gSpectAutoNext := gTime + (Random(7) + 8) * 1000;
2163 end;
2164 end;
2165 end;
2166 end;
2168 // Обновляем все остальное:
2169 g_Map_Update();
2170 g_Items_Update();
2171 g_Triggers_Update();
2172 g_Weapon_Update();
2173 g_Monsters_Update();
2174 g_GFX_Update();
2175 g_Player_UpdateAll();
2176 g_Player_UpdatePhysicalObjects();
2178 // server: send newly spawned monsters unconditionally
2179 if (gGameSettings.GameType = GT_SERVER) then
2180 begin
2181 if (Length(gMonstersSpawned) > 0) then
2182 begin
2183 for I := 0 to High(gMonstersSpawned) do MH_SEND_MonsterSpawn(gMonstersSpawned[I]);
2184 SetLength(gMonstersSpawned, 0);
2185 end;
2186 end;
2188 if (gSoundTriggerTime > 8) then
2189 begin
2190 g_Game_UpdateTriggerSounds();
2191 gSoundTriggerTime := 0;
2192 end
2193 else
2194 begin
2195 Inc(gSoundTriggerTime);
2196 end;
2198 if (NetMode = NET_SERVER) then
2199 begin
2200 Inc(NetTimeToUpdate);
2201 Inc(NetTimeToReliable);
2203 // send monster updates
2204 if (NetTimeToReliable >= NetRelupdRate) or (NetTimeToUpdate >= NetUpdateRate) then
2205 begin
2206 // send all monsters (periodic sync)
2207 reliableUpdate := (NetTimeToReliable >= NetRelupdRate);
2209 for I := 0 to High(gPlayers) do
2210 begin
2211 if (gPlayers[I] <> nil) then MH_SEND_PlayerPos(reliableUpdate, gPlayers[I].UID);
2212 end;
2214 g_Mons_ForEach(sendMonsPos);
2216 if reliableUpdate then
2217 begin
2218 NetTimeToReliable := 0;
2219 NetTimeToUpdate := NetUpdateRate;
2220 end
2221 else
2222 begin
2223 NetTimeToUpdate := 0;
2224 end;
2225 end
2226 else
2227 begin
2228 // send only mosters with some unexpected changes
2229 g_Mons_ForEach(sendMonsPosUnexpected);
2230 end;
2232 // send unexpected platform changes
2233 g_Map_NetSendInterestingPanels();
2235 g_Net_Slist_ServerUpdate();
2237 if NetUseMaster then
2238 begin
2239 if (gTime >= NetTimeToMaster) or g_Net_Slist_IsConnectionInProgress then
2240 begin
2241 if (not g_Net_Slist_IsConnectionActive) then g_Net_Slist_Connect(false); // non-blocking connection to the master
2242 g_Net_Slist_Update;
2243 NetTimeToMaster := gTime + NetMasterRate;
2244 end;
2245 end;
2247 end
2248 else if (NetMode = NET_CLIENT) then
2249 begin
2250 MC_SEND_PlayerPos();
2251 end;
2252 end; // if gameOn ...
2254 // Активно окно интерфейса - передаем клавиши ему:
2255 {$IFDEF ENABLE_MENU}
2256 if g_ActiveWindow <> nil then
2257 begin
2258 w := e_GetFirstKeyPressed();
2260 if (w <> IK_INVALID) then
2261 begin
2262 Msg.Msg := MESSAGE_DIKEY;
2263 Msg.wParam := w;
2264 g_ActiveWindow.OnMessage(Msg);
2265 end;
2267 // Если оно от этого не закрылось, то обновляем:
2268 if g_ActiveWindow <> nil then
2269 g_ActiveWindow.Update();
2271 // Нужно сменить разрешение:
2272 if gResolutionChange then
2273 begin
2274 {$IFNDEF HEADLESS}
2275 e_WriteLog('Changing resolution', TMsgType.Notify);
2276 r_Render_Apply;
2277 {$ENDIF}
2278 gResolutionChange := False;
2279 g_ActiveWindow := nil;
2280 end;
2282 // Нужно сменить язык:
2283 if gLanguageChange then
2284 begin
2285 //e_WriteLog('Read language file', MSG_NOTIFY);
2286 //g_Language_Load(DataDir + gLanguage + '.txt');
2287 g_Language_Set(gLanguage);
2288 g_Menu_Reset();
2289 gLanguageChange := False;
2290 end;
2291 end;
2293 // Горячая клавиша для вызова меню выхода из игры (F10):
2294 if e_KeyPressed(IK_F10) and
2295 gGameOn and
2296 (not gConsoleShow) and
2297 (g_ActiveWindow = nil) then
2298 begin
2299 KeyPress(IK_F10);
2300 end;
2301 {$ENDIF}
2303 Time := GetTickCount64() {div 1000};
2305 // Обработка отложенных событий:
2306 if gDelayedEvents <> nil then
2307 for a := 0 to High(gDelayedEvents) do
2308 if gDelayedEvents[a].Pending and
2310 ((gDelayedEvents[a].DEType = DE_GLOBEVENT) and (gDelayedEvents[a].Time <= Time)) or
2311 ((gDelayedEvents[a].DEType > DE_GLOBEVENT) and (gDelayedEvents[a].Time <= gTime))
2312 ) then
2313 begin
2314 case gDelayedEvents[a].DEType of
2315 DE_GLOBEVENT:
2316 g_Game_ExecuteEvent(gDelayedEvents[a].DEStr);
2317 DE_BFGHIT:
2318 if gGameOn then
2319 g_Game_Announce_GoodShot(gDelayedEvents[a].DENum);
2320 DE_KILLCOMBO:
2321 if gGameOn then
2322 begin
2323 g_Game_Announce_KillCombo(gDelayedEvents[a].DENum);
2324 if g_Game_IsNet and g_Game_IsServer then
2325 MH_SEND_GameEvent(NET_EV_KILLCOMBO, gDelayedEvents[a].DENum);
2326 end;
2327 DE_BODYKILL:
2328 if gGameOn then
2329 g_Game_Announce_BodyKill(gDelayedEvents[a].DENum);
2330 end;
2331 gDelayedEvents[a].Pending := False;
2332 end;
2334 // Каждую секунду обновляем счетчик обновлений:
2335 UPSCounter := UPSCounter + 1;
2336 if Time - UPSTime >= 1000 then
2337 begin
2338 UPS := UPSCounter;
2339 UPSCounter := 0;
2340 UPSTime := Time;
2341 end;
2343 if gGameOn then
2344 begin
2345 g_Weapon_AddDynLights();
2346 g_Items_AddDynLights();
2347 end;
2348 end;
2350 procedure g_Game_LoadChatSounds(Resource: string);
2351 var
2352 WAD: TWADFile;
2353 FileName, Snd: string;
2354 p: Pointer;
2355 len, cnt, tags, i, j: Integer;
2356 cfg: TConfig;
2357 begin
2358 FileName := g_ExtractWadName(Resource);
2360 WAD := TWADFile.Create();
2361 WAD.ReadFile(FileName);
2363 if not WAD.GetResource(g_ExtractFilePathName(Resource), p, len) then
2364 begin
2365 gChatSounds := nil;
2366 WAD.Free();
2367 Exit;
2368 end;
2370 cfg := TConfig.CreateMem(p, len);
2371 cnt := cfg.ReadInt('ChatSounds', 'Count', 0);
2373 SetLength(gChatSounds, cnt);
2374 for i := 0 to Length(gChatSounds) - 1 do
2375 begin
2376 gChatSounds[i].Sound := nil;
2377 Snd := Trim(cfg.ReadStr(IntToStr(i), 'Sound', ''));
2378 tags := cfg.ReadInt(IntToStr(i), 'Tags', 0);
2379 if (Snd = '') or (Tags <= 0) then
2380 continue;
2381 g_Sound_CreateWADEx('SOUND_CHAT_MACRO' + IntToStr(i), GameWAD+':'+Snd);
2382 gChatSounds[i].Sound := TPlayableSound.Create();
2383 gChatSounds[i].Sound.SetByName('SOUND_CHAT_MACRO' + IntToStr(i));
2384 SetLength(gChatSounds[i].Tags, tags);
2385 for j := 0 to tags - 1 do
2386 gChatSounds[i].Tags[j] := toLowerCase1251(cfg.ReadStr(IntToStr(i), 'Tag' + IntToStr(j), ''));
2387 gChatSounds[i].FullWord := cfg.ReadBool(IntToStr(i), 'FullWord', False);
2388 end;
2390 cfg.Free();
2391 WAD.Free();
2392 end;
2394 procedure g_Game_FreeChatSounds();
2395 var
2396 i: Integer;
2397 begin
2398 for i := 0 to Length(gChatSounds) - 1 do
2399 begin
2400 gChatSounds[i].Sound.Free();
2401 g_Sound_Delete('SOUND_CHAT_MACRO' + IntToStr(i));
2402 end;
2403 SetLength(gChatSounds, 0);
2404 gChatSounds := nil;
2405 end;
2407 procedure g_Game_LoadData();
2408 begin
2409 if DataLoaded then Exit;
2411 e_WriteLog('Loading game data...', TMsgType.Notify);
2413 g_Sound_CreateWADEx('SOUND_GAME_TELEPORT', GameWAD+':SOUNDS\TELEPORT');
2414 g_Sound_CreateWADEx('SOUND_GAME_NOTELEPORT', GameWAD+':SOUNDS\NOTELEPORT');
2415 g_Sound_CreateWADEx('SOUND_GAME_SECRET', GameWAD+':SOUNDS\SECRET');
2416 g_Sound_CreateWADEx('SOUND_GAME_DOOROPEN', GameWAD+':SOUNDS\DOOROPEN');
2417 g_Sound_CreateWADEx('SOUND_GAME_DOORCLOSE', GameWAD+':SOUNDS\DOORCLOSE');
2418 g_Sound_CreateWADEx('SOUND_GAME_BULK1', GameWAD+':SOUNDS\BULK1');
2419 g_Sound_CreateWADEx('SOUND_GAME_BULK2', GameWAD+':SOUNDS\BULK2');
2420 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE1', GameWAD+':SOUNDS\BUBBLE1');
2421 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE2', GameWAD+':SOUNDS\BUBBLE2');
2422 g_Sound_CreateWADEx('SOUND_GAME_BURNING', GameWAD+':SOUNDS\BURNING');
2423 g_Sound_CreateWADEx('SOUND_GAME_SWITCH1', GameWAD+':SOUNDS\SWITCH1');
2424 g_Sound_CreateWADEx('SOUND_GAME_SWITCH0', GameWAD+':SOUNDS\SWITCH0');
2425 g_Sound_CreateWADEx('SOUND_GAME_RADIO', GameWAD+':SOUNDS\RADIO');
2426 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD1', GameWAD+':SOUNDS\GOOD1');
2427 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD2', GameWAD+':SOUNDS\GOOD2');
2428 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD3', GameWAD+':SOUNDS\GOOD3');
2429 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD4', GameWAD+':SOUNDS\GOOD4');
2430 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL2X', GameWAD+':SOUNDS\KILL2X');
2431 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL3X', GameWAD+':SOUNDS\KILL3X');
2432 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL4X', GameWAD+':SOUNDS\KILL4X');
2433 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILLMX', GameWAD+':SOUNDS\KILLMX');
2434 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA1', GameWAD+':SOUNDS\MUHAHA1');
2435 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA2', GameWAD+':SOUNDS\MUHAHA2');
2436 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA3', GameWAD+':SOUNDS\MUHAHA3');
2437 g_Sound_CreateWADEx('SOUND_CTF_GET1', GameWAD+':SOUNDS\GETFLAG1');
2438 g_Sound_CreateWADEx('SOUND_CTF_GET2', GameWAD+':SOUNDS\GETFLAG2');
2439 g_Sound_CreateWADEx('SOUND_CTF_LOST1', GameWAD+':SOUNDS\LOSTFLG1');
2440 g_Sound_CreateWADEx('SOUND_CTF_LOST2', GameWAD+':SOUNDS\LOSTFLG2');
2441 g_Sound_CreateWADEx('SOUND_CTF_RETURN1', GameWAD+':SOUNDS\RETFLAG1');
2442 g_Sound_CreateWADEx('SOUND_CTF_RETURN2', GameWAD+':SOUNDS\RETFLAG2');
2443 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE1', GameWAD+':SOUNDS\CAPFLAG1');
2444 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE2', GameWAD+':SOUNDS\CAPFLAG2');
2446 goodsnd[0] := TPlayableSound.Create();
2447 goodsnd[1] := TPlayableSound.Create();
2448 goodsnd[2] := TPlayableSound.Create();
2449 goodsnd[3] := TPlayableSound.Create();
2451 goodsnd[0].SetByName('SOUND_ANNOUNCER_GOOD1');
2452 goodsnd[1].SetByName('SOUND_ANNOUNCER_GOOD2');
2453 goodsnd[2].SetByName('SOUND_ANNOUNCER_GOOD3');
2454 goodsnd[3].SetByName('SOUND_ANNOUNCER_GOOD4');
2456 killsnd[0] := TPlayableSound.Create();
2457 killsnd[1] := TPlayableSound.Create();
2458 killsnd[2] := TPlayableSound.Create();
2459 killsnd[3] := TPlayableSound.Create();
2461 killsnd[0].SetByName('SOUND_ANNOUNCER_KILL2X');
2462 killsnd[1].SetByName('SOUND_ANNOUNCER_KILL3X');
2463 killsnd[2].SetByName('SOUND_ANNOUNCER_KILL4X');
2464 killsnd[3].SetByName('SOUND_ANNOUNCER_KILLMX');
2466 hahasnd[0] := TPlayableSound.Create();
2467 hahasnd[1] := TPlayableSound.Create();
2468 hahasnd[2] := TPlayableSound.Create();
2470 hahasnd[0].SetByName('SOUND_ANNOUNCER_MUHAHA1');
2471 hahasnd[1].SetByName('SOUND_ANNOUNCER_MUHAHA2');
2472 hahasnd[2].SetByName('SOUND_ANNOUNCER_MUHAHA3');
2474 sound_get_flag[0] := TPlayableSound.Create();
2475 sound_get_flag[1] := TPlayableSound.Create();
2476 sound_lost_flag[0] := TPlayableSound.Create();
2477 sound_lost_flag[1] := TPlayableSound.Create();
2478 sound_ret_flag[0] := TPlayableSound.Create();
2479 sound_ret_flag[1] := TPlayableSound.Create();
2480 sound_cap_flag[0] := TPlayableSound.Create();
2481 sound_cap_flag[1] := TPlayableSound.Create();
2483 sound_get_flag[0].SetByName('SOUND_CTF_GET1');
2484 sound_get_flag[1].SetByName('SOUND_CTF_GET2');
2485 sound_lost_flag[0].SetByName('SOUND_CTF_LOST1');
2486 sound_lost_flag[1].SetByName('SOUND_CTF_LOST2');
2487 sound_ret_flag[0].SetByName('SOUND_CTF_RETURN1');
2488 sound_ret_flag[1].SetByName('SOUND_CTF_RETURN2');
2489 sound_cap_flag[0].SetByName('SOUND_CTF_CAPTURE1');
2490 sound_cap_flag[1].SetByName('SOUND_CTF_CAPTURE2');
2492 g_Game_LoadChatSounds(GameWAD+':CHATSND\SNDCFG');
2494 g_Game_SetLoadingText(_lc[I_LOAD_ITEMS_DATA], 0, False);
2495 g_Items_LoadData();
2497 g_Game_SetLoadingText(_lc[I_LOAD_WEAPONS_DATA], 0, False);
2498 g_Weapon_LoadData();
2500 g_Monsters_LoadData();
2502 DataLoaded := True;
2503 end;
2505 procedure g_Game_Quit();
2506 begin
2507 g_Game_StopAllSounds(True);
2508 gMusic.Free();
2509 g_Game_FreeData();
2510 g_PlayerModel_FreeData();
2511 {$IFNDEF HEADLESS}
2512 //g_Menu_Free(); //k8: this segfaults after resolution change; who cares?
2513 {$ENDIF}
2515 if NetInitDone then g_Net_Free;
2517 // remove map after test
2518 if gMapToDelete <> '' then
2519 g_Game_DeleteTestMap();
2521 gExit := EXIT_QUIT;
2523 {$IFNDEF HEADLESS}
2524 sys_RequestQuit;
2525 {$ENDIF}
2526 end;
2528 procedure g_Game_FreeData();
2529 begin
2530 if not DataLoaded then Exit;
2532 g_Items_FreeData();
2533 g_Weapon_FreeData();
2534 g_Monsters_FreeData();
2536 e_WriteLog('Releasing game data...', TMsgType.Notify);
2538 g_Sound_Delete('SOUND_GAME_TELEPORT');
2539 g_Sound_Delete('SOUND_GAME_NOTELEPORT');
2540 g_Sound_Delete('SOUND_GAME_SECRET');
2541 g_Sound_Delete('SOUND_GAME_DOOROPEN');
2542 g_Sound_Delete('SOUND_GAME_DOORCLOSE');
2543 g_Sound_Delete('SOUND_GAME_BULK1');
2544 g_Sound_Delete('SOUND_GAME_BULK2');
2545 g_Sound_Delete('SOUND_GAME_BUBBLE1');
2546 g_Sound_Delete('SOUND_GAME_BUBBLE2');
2547 g_Sound_Delete('SOUND_GAME_BURNING');
2548 g_Sound_Delete('SOUND_GAME_SWITCH1');
2549 g_Sound_Delete('SOUND_GAME_SWITCH0');
2551 goodsnd[0].Free();
2552 goodsnd[1].Free();
2553 goodsnd[2].Free();
2554 goodsnd[3].Free();
2556 g_Sound_Delete('SOUND_ANNOUNCER_GOOD1');
2557 g_Sound_Delete('SOUND_ANNOUNCER_GOOD2');
2558 g_Sound_Delete('SOUND_ANNOUNCER_GOOD3');
2559 g_Sound_Delete('SOUND_ANNOUNCER_GOOD4');
2561 killsnd[0].Free();
2562 killsnd[1].Free();
2563 killsnd[2].Free();
2564 killsnd[3].Free();
2566 g_Sound_Delete('SOUND_ANNOUNCER_KILL2X');
2567 g_Sound_Delete('SOUND_ANNOUNCER_KILL3X');
2568 g_Sound_Delete('SOUND_ANNOUNCER_KILL4X');
2569 g_Sound_Delete('SOUND_ANNOUNCER_KILLMX');
2571 hahasnd[0].Free();
2572 hahasnd[1].Free();
2573 hahasnd[2].Free();
2575 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA1');
2576 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA2');
2577 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA3');
2579 sound_get_flag[0].Free();
2580 sound_get_flag[1].Free();
2581 sound_lost_flag[0].Free();
2582 sound_lost_flag[1].Free();
2583 sound_ret_flag[0].Free();
2584 sound_ret_flag[1].Free();
2585 sound_cap_flag[0].Free();
2586 sound_cap_flag[1].Free();
2588 g_Sound_Delete('SOUND_CTF_GET1');
2589 g_Sound_Delete('SOUND_CTF_GET2');
2590 g_Sound_Delete('SOUND_CTF_LOST1');
2591 g_Sound_Delete('SOUND_CTF_LOST2');
2592 g_Sound_Delete('SOUND_CTF_RETURN1');
2593 g_Sound_Delete('SOUND_CTF_RETURN2');
2594 g_Sound_Delete('SOUND_CTF_CAPTURE1');
2595 g_Sound_Delete('SOUND_CTF_CAPTURE2');
2597 g_Game_FreeChatSounds();
2599 DataLoaded := False;
2600 end;
2602 procedure g_FatalError(Text: String);
2603 begin
2604 g_Console_Add(Format(_lc[I_FATAL_ERROR], [Text]), True);
2605 e_WriteLog(Format(_lc[I_FATAL_ERROR], [Text]), TMsgType.Warning);
2607 gExit := EXIT_SIMPLE;
2608 if gGameOn then EndGame;
2609 end;
2611 procedure g_SimpleError(Text: String);
2612 begin
2613 g_Console_Add(Format(_lc[I_SIMPLE_ERROR], [Text]), True);
2614 e_WriteLog(Format(_lc[I_SIMPLE_ERROR], [Text]), TMsgType.Warning);
2615 end;
2617 procedure g_Game_AddPlayer(Team: Byte = TEAM_NONE);
2618 begin
2619 if ((not gGameOn) and (gState <> STATE_INTERCUSTOM))
2620 or (not (gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT])) then
2621 Exit;
2623 if (gGameSettings.MaxLives > 0) and (gLMSRespawn = LMS_RESPAWN_NONE) then
2624 Exit;
2626 if gPlayer1 = nil then
2627 begin
2628 if g_Game_IsClient then
2629 begin
2630 if NetPlrUID1 > -1 then
2631 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE);
2632 Exit;
2633 end;
2635 if not (Team in [TEAM_RED, TEAM_BLUE]) then
2636 Team := gPlayer1Settings.Team;
2638 // Создание первого игрока:
2639 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
2640 gPlayer1Settings.Color,
2641 Team, False));
2642 if gPlayer1 = nil then
2643 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]))
2644 else
2645 begin
2646 gPlayer1.Name := gPlayer1Settings.Name;
2647 g_Console_Add(Format(_lc[I_PLAYER_JOIN], [gPlayer1.Name]), True);
2648 if g_Game_IsServer and g_Game_IsNet then
2649 MH_SEND_PlayerCreate(gPlayer1.UID);
2650 gPlayer1.Respawn(False, True);
2651 g_Net_Slist_ServerPlayerComes();
2652 end;
2654 Exit;
2655 end;
2656 if gPlayer2 = nil then
2657 begin
2658 if g_Game_IsClient then
2659 begin
2660 if NetPlrUID2 > -1 then
2661 gPlayer2 := g_Player_Get(NetPlrUID2);
2662 Exit;
2663 end;
2665 if not (Team in [TEAM_RED, TEAM_BLUE]) then
2666 Team := gPlayer2Settings.Team;
2668 // Создание второго игрока:
2669 gPlayer2 := g_Player_Get(g_Player_Create(gPlayer2Settings.Model,
2670 gPlayer2Settings.Color,
2671 Team, False));
2672 if gPlayer2 = nil then
2673 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [2]))
2674 else
2675 begin
2676 gPlayer2.Name := gPlayer2Settings.Name;
2677 g_Console_Add(Format(_lc[I_PLAYER_JOIN], [gPlayer2.Name]), True);
2678 if g_Game_IsServer and g_Game_IsNet then
2679 MH_SEND_PlayerCreate(gPlayer2.UID);
2680 gPlayer2.Respawn(False, True);
2681 g_Net_Slist_ServerPlayerComes();
2682 end;
2684 Exit;
2685 end;
2686 end;
2688 procedure g_Game_RemovePlayer();
2689 var
2690 Pl: TPlayer;
2691 begin
2692 if ((not gGameOn) and (gState <> STATE_INTERCUSTOM))
2693 or (not (gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT])) then
2694 Exit;
2695 Pl := gPlayer2;
2696 if Pl <> nil then
2697 begin
2698 if g_Game_IsServer then
2699 begin
2700 Pl.Lives := 0;
2701 Pl.Kill(K_SIMPLEKILL, 0, HIT_DISCON);
2702 g_Console_Add(Format(_lc[I_PLAYER_LEAVE], [Pl.Name]), True);
2703 g_Player_Remove(Pl.UID);
2704 g_Net_Slist_ServerPlayerLeaves();
2705 end
2706 else
2707 begin
2708 gSpectLatchPID2 := Pl.UID;
2709 gPlayer2 := nil;
2710 end;
2711 Exit;
2712 end;
2713 Pl := gPlayer1;
2714 if Pl <> nil then
2715 begin
2716 if g_Game_IsServer then
2717 begin
2718 Pl.Lives := 0;
2719 Pl.Kill(K_SIMPLEKILL, 0, HIT_DISCON);
2720 g_Console_Add(Format(_lc[I_PLAYER_LEAVE], [Pl.Name]), True);
2721 g_Player_Remove(Pl.UID);
2722 g_Net_Slist_ServerPlayerLeaves();
2723 end else
2724 begin
2725 gSpectLatchPID1 := Pl.UID;
2726 gPlayer1 := nil;
2727 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE);
2728 end;
2729 Exit;
2730 end;
2731 g_Net_Slist_ServerPlayerLeaves();
2732 end;
2734 procedure g_Game_Spectate();
2735 begin
2736 g_Game_RemovePlayer();
2737 if gPlayer1 <> nil then
2738 g_Game_RemovePlayer();
2739 end;
2741 procedure g_Game_SpectateCenterView();
2742 begin
2743 gSpectX := Max(gMapInfo.Width div 2 - gScreenWidth div 2, 0);
2744 gSpectY := Max(gMapInfo.Height div 2 - gScreenHeight div 2, 0);
2745 end;
2747 procedure g_Game_StartSingle(Map: String; TwoPlayers: Boolean; nPlayers: Byte);
2748 var
2749 i, nPl: Integer;
2750 tmps: AnsiString;
2751 begin
2752 g_Game_Free();
2754 e_WriteLog('Starting singleplayer game...', TMsgType.Notify);
2756 g_Game_ClearLoading();
2758 // Настройки игры:
2759 FillByte(gGameSettings, SizeOf(TGameSettings), 0);
2760 gAimLine := False;
2761 gShowMap := False;
2762 gGameSettings.GameType := GT_SINGLE;
2763 gGameSettings.MaxLives := 0;
2764 gGameSettings.Options := gGameSettings.Options + GAME_OPTION_ALLOWEXIT;
2765 gGameSettings.Options := gGameSettings.Options + GAME_OPTION_MONSTERS;
2766 gGameSettings.Options := gGameSettings.Options + GAME_OPTION_BOTVSMONSTER;
2767 gGameSettings.Options := gGameSettings.Options + GAME_OPTION_TEAMHITPROJECTILE;
2768 gGameSettings.Options := gGameSettings.Options + GAME_OPTION_TEAMHITTRACE;
2769 gSwitchGameMode := GM_SINGLE;
2771 gLMSRespawn := LMS_RESPAWN_NONE;
2772 gLMSRespawnTime := 0;
2773 gSpectLatchPID1 := 0;
2774 gSpectLatchPID2 := 0;
2776 g_Game_ExecuteEvent('ongamestart');
2778 // Создание первого игрока:
2779 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
2780 gPlayer1Settings.Color,
2781 gPlayer1Settings.Team, False));
2782 if gPlayer1 = nil then
2783 begin
2784 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]));
2785 Exit;
2786 end;
2788 gPlayer1.Name := gPlayer1Settings.Name;
2789 nPl := 1;
2791 // Создание второго игрока, если есть:
2792 if TwoPlayers then
2793 begin
2794 gPlayer2 := g_Player_Get(g_Player_Create(gPlayer2Settings.Model,
2795 gPlayer2Settings.Color,
2796 gPlayer2Settings.Team, False));
2797 if gPlayer2 = nil then
2798 begin
2799 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [2]));
2800 Exit;
2801 end;
2803 gPlayer2.Name := gPlayer2Settings.Name;
2804 Inc(nPl);
2805 end;
2807 // Загрузка и запуск карты:
2808 if not g_Game_StartMap(false{asMegawad}, MAP, True) then
2809 begin
2810 if (Pos(':\', Map) > 0) or (Pos(':/', Map) > 0) then tmps := Map else tmps := gGameSettings.WAD + ':\' + MAP;
2811 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [tmps]));
2812 Exit;
2813 end;
2815 // Настройки игроков и ботов:
2816 g_Player_Init();
2818 // Создаем ботов:
2819 for i := nPl+1 to nPlayers do
2820 g_Player_Create(STD_PLAYER_MODEL, _RGB(0, 0, 0), 0, True);
2821 end;
2823 procedure g_Game_StartCustom(Map: String; GameMode: Byte;
2824 TimeLimit, GoalLimit: Word;
2825 MaxLives: Byte;
2826 Options: LongWord; nPlayers: Byte);
2827 var
2828 i, nPl: Integer;
2829 begin
2830 g_Game_Free();
2832 e_WriteLog('Starting custom game...', TMsgType.Notify);
2834 g_Game_ClearLoading();
2836 // Настройки игры:
2837 gGameSettings.GameType := GT_CUSTOM;
2838 gGameSettings.GameMode := GameMode;
2839 gSwitchGameMode := GameMode;
2840 gGameSettings.TimeLimit := TimeLimit;
2841 gGameSettings.GoalLimit := GoalLimit;
2842 gGameSettings.MaxLives := IfThen(GameMode = GM_CTF, 0, MaxLives);
2843 gGameSettings.Options := Options;
2845 gCoopTotalMonstersKilled := 0;
2846 gCoopTotalSecretsFound := 0;
2847 gCoopTotalMonsters := 0;
2848 gCoopTotalSecrets := 0;
2849 gAimLine := False;
2850 gShowMap := False;
2852 gLMSRespawn := LMS_RESPAWN_NONE;
2853 gLMSRespawnTime := 0;
2854 gSpectLatchPID1 := 0;
2855 gSpectLatchPID2 := 0;
2857 g_Game_ExecuteEvent('ongamestart');
2859 // Режим наблюдателя:
2860 if nPlayers = 0 then
2861 begin
2862 gPlayer1 := nil;
2863 gPlayer2 := nil;
2864 end;
2866 nPl := 0;
2867 if nPlayers >= 1 then
2868 begin
2869 // Создание первого игрока:
2870 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
2871 gPlayer1Settings.Color,
2872 gPlayer1Settings.Team, False));
2873 if gPlayer1 = nil then
2874 begin
2875 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]));
2876 Exit;
2877 end;
2879 gPlayer1.Name := gPlayer1Settings.Name;
2880 Inc(nPl);
2881 end;
2883 if nPlayers >= 2 then
2884 begin
2885 // Создание второго игрока:
2886 gPlayer2 := g_Player_Get(g_Player_Create(gPlayer2Settings.Model,
2887 gPlayer2Settings.Color,
2888 gPlayer2Settings.Team, False));
2889 if gPlayer2 = nil then
2890 begin
2891 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [2]));
2892 Exit;
2893 end;
2895 gPlayer2.Name := gPlayer2Settings.Name;
2896 Inc(nPl);
2897 end;
2899 // Загрузка и запуск карты:
2900 if not g_Game_StartMap(true{asMegawad}, Map, True) then
2901 begin
2902 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [Map]));
2903 Exit;
2904 end;
2906 // Нет точек появления:
2907 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1) +
2908 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2) +
2909 g_Map_GetPointCount(RESPAWNPOINT_DM) +
2910 g_Map_GetPointCount(RESPAWNPOINT_RED)+
2911 g_Map_GetPointCount(RESPAWNPOINT_BLUE)) < 1 then
2912 begin
2913 g_FatalError(_lc[I_GAME_ERROR_GET_SPAWN]);
2914 Exit;
2915 end;
2917 // Настройки игроков и ботов:
2918 g_Player_Init();
2920 // Создаем ботов:
2921 for i := nPl+1 to nPlayers do
2922 g_Player_Create(STD_PLAYER_MODEL, _RGB(0, 0, 0), 0, True);
2923 end;
2925 procedure g_Game_StartServer(Map: String; GameMode: Byte;
2926 TimeLimit, GoalLimit: Word; MaxLives: Byte;
2927 Options: LongWord; nPlayers: Byte;
2928 IPAddr: LongWord; Port: Word);
2929 begin
2930 g_Game_Free();
2931 g_Net_Slist_ServerClosed();
2933 e_WriteLog('Starting net game (server)...', TMsgType.Notify);
2935 g_Game_ClearLoading();
2937 // Настройки игры:
2938 gGameSettings.GameType := GT_SERVER;
2939 gGameSettings.GameMode := GameMode;
2940 gSwitchGameMode := GameMode;
2941 gGameSettings.TimeLimit := TimeLimit;
2942 gGameSettings.GoalLimit := GoalLimit;
2943 gGameSettings.MaxLives := IfThen(GameMode = GM_CTF, 0, MaxLives);
2944 gGameSettings.Options := Options;
2946 gCoopTotalMonstersKilled := 0;
2947 gCoopTotalSecretsFound := 0;
2948 gCoopTotalMonsters := 0;
2949 gCoopTotalSecrets := 0;
2950 gAimLine := False;
2951 gShowMap := False;
2953 gLMSRespawn := LMS_RESPAWN_NONE;
2954 gLMSRespawnTime := 0;
2955 gSpectLatchPID1 := 0;
2956 gSpectLatchPID2 := 0;
2958 g_Game_ExecuteEvent('ongamestart');
2960 // Режим наблюдателя:
2961 if nPlayers = 0 then
2962 begin
2963 gPlayer1 := nil;
2964 gPlayer2 := nil;
2965 end;
2967 if nPlayers >= 1 then
2968 begin
2969 // Создание первого игрока:
2970 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
2971 gPlayer1Settings.Color,
2972 gPlayer1Settings.Team, False));
2973 if gPlayer1 = nil then
2974 begin
2975 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]));
2976 Exit;
2977 end;
2979 gPlayer1.Name := gPlayer1Settings.Name;
2980 end;
2982 if nPlayers >= 2 then
2983 begin
2984 // Создание второго игрока:
2985 gPlayer2 := g_Player_Get(g_Player_Create(gPlayer2Settings.Model,
2986 gPlayer2Settings.Color,
2987 gPlayer2Settings.Team, False));
2988 if gPlayer2 = nil then
2989 begin
2990 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [2]));
2991 Exit;
2992 end;
2994 gPlayer2.Name := gPlayer2Settings.Name;
2995 end;
2997 g_Game_SetLoadingText(_lc[I_LOAD_HOST], 0, False);
2998 if NetForwardPorts then
2999 g_Game_SetLoadingText(_lc[I_LOAD_PORTS], 0, False);
3001 // Стартуем сервер
3002 if not g_Net_Host(IPAddr, Port, NetMaxClients) then
3003 begin
3004 g_FatalError(_lc[I_NET_MSG] + Format(_lc[I_NET_ERR_HOST], [Port]));
3005 Exit;
3006 end;
3008 g_Net_Slist_Set(NetMasterList);
3010 g_Net_Slist_ServerStarted();
3012 // Загрузка и запуск карты:
3013 if not g_Game_StartMap(false{asMegawad}, Map, True) then
3014 begin
3015 g_Net_Slist_ServerClosed();
3016 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [Map]));
3017 Exit;
3018 end;
3020 // Нет точек появления:
3021 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1) +
3022 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2) +
3023 g_Map_GetPointCount(RESPAWNPOINT_DM) +
3024 g_Map_GetPointCount(RESPAWNPOINT_RED)+
3025 g_Map_GetPointCount(RESPAWNPOINT_BLUE)) < 1 then
3026 begin
3027 g_Net_Slist_ServerClosed();
3028 g_FatalError(_lc[I_GAME_ERROR_GET_SPAWN]);
3029 Exit;
3030 end;
3032 // Настройки игроков и ботов:
3033 g_Player_Init();
3035 g_Net_Slist_ServerMapStarted();
3036 NetState := NET_STATE_GAME;
3037 end;
3039 procedure g_Game_StartClient(Addr: String; Port: Word; PW: String);
3040 var
3041 Map: String;
3042 WadName: string;
3043 Ptr: Pointer;
3044 T: Cardinal;
3045 MID: Byte;
3046 State: Byte;
3047 OuterLoop: Boolean;
3048 newResPath: string;
3049 InMsg: TMsg;
3050 begin
3051 g_Game_Free();
3053 State := 0;
3054 e_WriteLog('Starting net game (client)...', TMsgType.Notify);
3055 e_WriteLog('NET: Trying to connect to ' + Addr + ':' + IntToStr(Port) + '...', TMsgType.Notify);
3057 g_Game_ClearLoading();
3059 // Настройки игры:
3060 gGameSettings.GameType := GT_CLIENT;
3062 gCoopTotalMonstersKilled := 0;
3063 gCoopTotalSecretsFound := 0;
3064 gCoopTotalMonsters := 0;
3065 gCoopTotalSecrets := 0;
3066 gAimLine := False;
3067 gShowMap := False;
3069 g_Game_ExecuteEvent('ongamestart');
3071 NetState := NET_STATE_AUTH;
3073 g_Game_SetLoadingText(_lc[I_LOAD_CONNECT], 0, False);
3075 // create (or update) map/resource databases
3076 g_Res_CreateDatabases(true);
3078 gLMSRespawn := LMS_RESPAWN_NONE;
3079 gLMSRespawnTime := 0;
3080 gSpectLatchPID1 := 0;
3081 gSpectLatchPID2 := 0;
3083 // Стартуем клиент
3084 if not g_Net_Connect(Addr, Port) then
3085 begin
3086 g_FatalError(_lc[I_NET_MSG] + _lc[I_NET_ERR_CONN]);
3087 NetState := NET_STATE_NONE;
3088 Exit;
3089 end;
3091 g_Game_SetLoadingText(_lc[I_LOAD_SEND_INFO], 0, False);
3092 MC_SEND_Info(PW);
3093 g_Game_SetLoadingText(_lc[I_LOAD_WAIT_INFO], 0, False);
3095 OuterLoop := True;
3096 while OuterLoop do
3097 begin
3098 // fuck! https://www.mail-archive.com/enet-discuss@cubik.org/msg00852.html
3099 // tl;dr: on shitdows, we can get -1 sometimes, and it is *NOT* a failure.
3100 // thank you, enet. let's ignore failures altogether then.
3101 while (enet_host_service(NetHost, @NetEvent, 50) > 0) do
3102 begin
3103 if (NetEvent.kind = ENET_EVENT_TYPE_RECEIVE) then
3104 begin
3105 if (NetEvent.channelID = NET_CHAN_DOWNLOAD_EX) then
3106 begin
3107 // ignore all download packets, they're processed by separate code
3108 enet_packet_destroy(NetEvent.packet);
3109 continue;
3110 end;
3111 Ptr := NetEvent.packet^.data;
3112 if not InMsg.Init(Ptr, NetEvent.packet^.dataLength, True) then
3113 begin
3114 enet_packet_destroy(NetEvent.packet);
3115 continue;
3116 end;
3118 InMsg.ReadLongWord(); // skip size
3119 MID := InMsg.ReadByte();
3121 if (MID = NET_MSG_INFO) and (State = 0) then
3122 begin
3123 NetMyID := InMsg.ReadByte();
3124 NetPlrUID1 := InMsg.ReadWord();
3126 WadName := InMsg.ReadString();
3127 Map := InMsg.ReadString();
3129 gWADHash := InMsg.ReadMD5();
3131 gGameSettings.GameMode := InMsg.ReadByte();
3132 gSwitchGameMode := gGameSettings.GameMode;
3133 gGameSettings.GoalLimit := InMsg.ReadWord();
3134 gGameSettings.TimeLimit := InMsg.ReadWord();
3135 gGameSettings.MaxLives := InMsg.ReadByte();
3136 gGameSettings.Options := InMsg.ReadLongWord();
3137 T := InMsg.ReadLongWord();
3139 //newResPath := g_Res_SearchSameWAD(MapsDir, WadName, gWADHash);
3140 //if newResPath = '' then
3141 begin
3142 //g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
3143 newResPath := g_Res_DownloadMapWAD(ExtractFileName(WadName), gWADHash);
3144 if newResPath = '' then
3145 begin
3146 g_FatalError(_lc[I_NET_ERR_HASH]);
3147 enet_packet_destroy(NetEvent.packet);
3148 NetState := NET_STATE_NONE;
3149 Exit;
3150 end;
3151 e_LogWritefln('using downloaded map wad [%s] for [%s]`', [newResPath, WadName], TMsgType.Notify);
3152 end;
3153 //newResPath := ExtractRelativePath(MapsDir, newResPath);
3156 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
3157 gPlayer1Settings.Color,
3158 gPlayer1Settings.Team, False));
3160 if gPlayer1 = nil then
3161 begin
3162 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]));
3164 enet_packet_destroy(NetEvent.packet);
3165 NetState := NET_STATE_NONE;
3166 Exit;
3167 end;
3169 gPlayer1.Name := gPlayer1Settings.Name;
3170 gPlayer1.UID := NetPlrUID1;
3171 gPlayer1.Reset(True);
3173 if not g_Game_StartMap(false{asMegawad}, newResPath + ':\' + Map, True) then
3174 begin
3175 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [WadName + ':\' + Map]));
3177 enet_packet_destroy(NetEvent.packet);
3178 NetState := NET_STATE_NONE;
3179 Exit;
3180 end;
3182 gTime := T;
3184 State := 1;
3185 OuterLoop := False;
3186 enet_packet_destroy(NetEvent.packet);
3187 break;
3188 end
3189 else
3190 enet_packet_destroy(NetEvent.packet);
3191 end
3192 else
3193 begin
3194 if (NetEvent.kind = ENET_EVENT_TYPE_DISCONNECT) then
3195 begin
3196 State := 0;
3197 if (NetEvent.data <= NET_DISC_MAX) then
3198 g_Console_Add(_lc[I_NET_MSG_ERROR] + _lc[I_NET_ERR_CONN] + ' ' +
3199 _lc[TStrings_Locale(Cardinal(I_NET_DISC_NONE) + NetEvent.data)], True);
3200 OuterLoop := False;
3201 Break;
3202 end;
3203 end;
3204 end;
3206 ProcessLoading(true);
3208 if g_Net_UserRequestExit() then
3209 begin
3210 State := 0;
3211 break;
3212 end;
3213 end;
3215 if State <> 1 then
3216 begin
3217 g_FatalError(_lc[I_NET_MSG] + _lc[I_NET_ERR_CONN]);
3218 NetState := NET_STATE_NONE;
3219 Exit;
3220 end;
3222 g_Player_Init();
3223 NetState := NET_STATE_GAME;
3224 MC_SEND_FullStateRequest;
3225 e_WriteLog('NET: Connection successful.', TMsgType.Notify);
3226 end;
3228 var
3229 lastAsMegaWad: Boolean = false;
3231 procedure g_Game_ChangeMap(const MapPath: String);
3232 var
3233 Force: Boolean;
3234 begin
3235 g_Game_ClearLoading();
3237 Force := gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF];
3238 // Если уровень завершился по триггеру Выход, не очищать инвентарь
3239 if gExitByTrigger then
3240 begin
3241 Force := False;
3242 gExitByTrigger := False;
3243 end;
3244 if not g_Game_StartMap(lastAsMegaWad, MapPath, Force) then
3245 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [MapPath]));
3246 end;
3248 procedure g_Game_Restart();
3249 var
3250 Map: string;
3251 begin
3252 if g_Game_IsClient then
3253 Exit;
3254 map := g_ExtractFileName(gMapInfo.Map);
3255 e_LogWritefln('g_Game_Restart: map = "%s" gCurrentMapFileName = "%s"', [map, gCurrentMapFileName]);
3257 MessageTime := 0;
3258 gGameOn := False;
3259 g_Game_ClearLoading();
3260 g_Game_StartMap(lastAsMegaWad, Map, True, gCurrentMapFileName);
3261 end;
3263 function g_Game_StartMap (asMegawad: Boolean; Map: String; Force: Boolean = False; const oldMapPath: AnsiString=''): Boolean;
3264 var
3265 NewWAD, ResName: String;
3266 I: Integer;
3267 nws: AnsiString;
3268 begin
3269 g_Map_Free((Map <> gCurrentMapFileName) and (oldMapPath <> gCurrentMapFileName));
3270 g_Player_RemoveAllCorpses();
3272 if (not g_Game_IsClient) and
3273 (gSwitchGameMode <> gGameSettings.GameMode) and
3274 (gGameSettings.GameMode <> GM_SINGLE) then
3275 begin
3276 if gSwitchGameMode = GM_CTF then
3277 gGameSettings.MaxLives := 0;
3278 gGameSettings.GameMode := gSwitchGameMode;
3279 Force := True;
3280 end else
3281 gSwitchGameMode := gGameSettings.GameMode;
3283 g_Player_ResetTeams();
3285 lastAsMegaWad := asMegawad;
3286 if isWadPath(Map) then
3287 begin
3288 NewWAD := g_ExtractWadName(Map);
3289 ResName := g_ExtractFileName(Map);
3290 if g_Game_IsServer then
3291 begin
3292 nws := findDiskWad(NewWAD);
3293 //writeln('000: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
3294 if (asMegawad) then
3295 begin
3296 if (length(nws) = 0) then nws := e_FindWad(MegawadDirs, NewWAD);
3297 if (length(nws) = 0) then nws := e_FindWad(MapDirs, NewWAD);
3298 end
3299 else
3300 begin
3301 if (length(nws) = 0) then nws := e_FindWad(MapDirs, NewWAD);
3302 if (length(nws) = 0) then nws := e_FindWad(MegawadDirs, NewWAD);
3303 end;
3304 //if (length(nws) = 0) then nws := e_FindWad(MapDownloadDirs, NewWAD);
3305 //writeln('001: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
3306 //nws := NewWAD;
3307 if (length(nws) = 0) then
3308 begin
3309 ResName := ''; // failed
3310 end
3311 else
3312 begin
3313 NewWAD := nws;
3314 if (g_Game_IsNet) then gWADHash := MD5File(nws);
3315 //writeln('********: nws=', nws, ' : Map=', Map, ' : nw=', NewWAD, ' : resname=', ResName);
3316 g_Game_LoadWAD(NewWAD);
3317 end;
3318 end
3319 else
3320 begin
3321 // hash received in MC_RECV_GameEvent -> NET_EV_MAPSTART
3322 NewWAD := g_Game_ClientWAD(NewWAD, gWADHash);
3323 end;
3324 end
3325 else
3326 begin
3327 NewWAD := gGameSettings.WAD;
3328 ResName := Map;
3329 end;
3331 gTime := 0;
3333 //writeln('********: gsw=', gGameSettings.WAD, '; rn=', ResName);
3334 result := false;
3335 if (ResName <> '') and (NewWAD <> '') then
3336 begin
3337 //result := g_Map_Load(gGameSettings.WAD + ':\' + ResName);
3338 result := g_Map_Load(NewWAD+':\'+ResName);
3339 {$IFNDEF HEADLESS}
3340 r_Render_LoadTextures;
3341 {$ENDIF}
3342 end;
3343 if Result then
3344 begin
3345 g_Player_ResetAll(Force or gLastMap, gGameSettings.GameType = GT_SINGLE);
3347 gState := STATE_NONE;
3348 {$IFDEF ENABLE_MENU}
3349 g_ActiveWindow := nil;
3350 {$ENDIF}
3351 gGameOn := True;
3353 DisableCheats();
3354 wNeedTimeReset := True;
3356 if gGameSettings.GameMode = GM_CTF then
3357 begin
3358 g_Map_ResetFlag(FLAG_RED);
3359 g_Map_ResetFlag(FLAG_BLUE);
3360 // CTF, а флагов нет:
3361 if not g_Map_HaveFlagPoints() then
3362 g_SimpleError(_lc[I_GAME_ERROR_CTF]);
3363 end;
3364 end
3365 else
3366 begin
3367 gState := STATE_MENU;
3368 gGameOn := False;
3369 end;
3371 gExit := 0;
3372 gPauseMain := false;
3373 gPauseHolmes := false;
3374 NetTimeToUpdate := 1;
3375 NetTimeToReliable := 0;
3376 NetTimeToMaster := NetMasterRate;
3377 gSpectLatchPID1 := 0;
3378 gSpectLatchPID2 := 0;
3379 gMissionFailed := False;
3380 gNextMap := '';
3382 gCoopMonstersKilled := 0;
3383 gCoopSecretsFound := 0;
3385 gVoteInProgress := False;
3386 gVotePassed := False;
3387 gVoteCount := 0;
3388 gVoted := False;
3390 gStatsOff := False;
3392 if not gGameOn then Exit;
3394 g_Game_SpectateCenterView();
3396 if g_Game_IsServer then
3397 begin
3398 if (gGameSettings.MaxLives > 0) and (gGameSettings.WarmupTime > 0) then
3399 begin
3400 gLMSRespawn := LMS_RESPAWN_WARMUP;
3401 gLMSRespawnTime := gTime + gGameSettings.WarmupTime*1000;
3402 gLMSSoftSpawn := True;
3403 if g_Game_IsNet then
3404 MH_SEND_GameEvent(NET_EV_LMS_WARMUP, gLMSRespawnTime - gTime);
3405 end
3406 else
3407 begin
3408 gLMSRespawn := LMS_RESPAWN_NONE;
3409 gLMSRespawnTime := 0;
3410 end;
3411 end;
3413 if NetMode = NET_SERVER then
3414 begin
3415 MH_SEND_GameEvent(NET_EV_MAPSTART, gGameSettings.GameMode, Map);
3417 // Мастерсервер
3418 g_Net_Slist_ServerMapStarted();
3420 if NetClients <> nil then
3421 for I := 0 to High(NetClients) do
3422 if NetClients[I].Used then
3423 begin
3424 NetClients[I].Voted := False;
3425 if NetClients[I].RequestedFullUpdate then
3426 begin
3427 MH_SEND_Everything((NetClients[I].State = NET_STATE_AUTH), I);
3428 NetClients[I].RequestedFullUpdate := False;
3429 end;
3430 end;
3432 g_Net_UnbanNonPermHosts();
3433 end;
3435 if gLastMap then
3436 begin
3437 gCoopTotalMonstersKilled := 0;
3438 gCoopTotalSecretsFound := 0;
3439 gCoopTotalMonsters := 0;
3440 gCoopTotalSecrets := 0;
3441 gLastMap := False;
3442 end;
3444 g_Game_ExecuteEvent('onmapstart');
3445 end;
3447 procedure SetFirstLevel;
3448 begin
3449 gNextMap := '';
3451 MapList := g_Map_GetMapsList(gGameSettings.WAD);
3452 if MapList = nil then
3453 Exit;
3455 SortSArray(MapList);
3456 gNextMap := MapList[Low(MapList)];
3458 MapList := nil;
3459 end;
3461 procedure g_Game_ExitLevel(const Map: AnsiString);
3462 begin
3463 gNextMap := Map;
3465 gCoopTotalMonstersKilled := gCoopTotalMonstersKilled + gCoopMonstersKilled;
3466 gCoopTotalSecretsFound := gCoopTotalSecretsFound + gCoopSecretsFound;
3467 gCoopTotalMonsters := gCoopTotalMonsters + gTotalMonsters;
3468 gCoopTotalSecrets := gCoopTotalSecrets + gSecretsCount;
3470 // Вышли в выход в Одиночной игре:
3471 if gGameSettings.GameType = GT_SINGLE then
3472 gExit := EXIT_ENDLEVELSINGLE
3473 else // Вышли в выход в Своей игре
3474 begin
3475 gExit := EXIT_ENDLEVELCUSTOM;
3476 if gGameSettings.GameMode = GM_COOP then
3477 g_Player_RememberAll;
3479 if not g_Map_Exist(gGameSettings.WAD + ':\' + gNextMap) then
3480 begin
3481 gLastMap := True;
3482 if gGameSettings.GameMode = GM_COOP then
3483 gStatsOff := True;
3485 gStatsPressed := True;
3486 gNextMap := 'MAP01';
3488 if not g_Map_Exist(gGameSettings.WAD + ':\' + gNextMap) then
3489 g_Game_NextLevel;
3491 if g_Game_IsNet then
3492 begin
3493 MH_SEND_GameStats();
3494 MH_SEND_CoopStats();
3495 end;
3496 end;
3497 end;
3498 end;
3500 procedure g_Game_RestartLevel();
3501 var
3502 Map: string;
3503 begin
3504 if gGameSettings.GameMode = GM_SINGLE then
3505 begin
3506 g_Game_Restart();
3507 Exit;
3508 end;
3509 gExit := EXIT_ENDLEVELCUSTOM;
3510 Map := g_ExtractFileName(gMapInfo.Map);
3511 gNextMap := Map;
3512 end;
3514 function g_Game_ClientWAD (NewWAD: String; const WHash: TMD5Digest): AnsiString;
3515 var
3516 gWAD{, xwad}: String;
3517 begin
3518 result := NewWAD;
3519 if not g_Game_IsClient then Exit;
3520 //e_LogWritefln('*** g_Game_ClientWAD: `%s`', [NewWAD]);
3522 gWAD := g_Res_DownloadMapWAD(ExtractFileName(NewWAD), WHash);
3523 if gWAD = '' then
3524 begin
3525 result := '';
3526 g_Game_Free();
3527 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_WAD], [ExtractFileName(NewWAD)]));
3528 Exit;
3529 end;
3531 e_LogWritefln('using downloaded client map wad [%s] for [%s]', [gWAD, NewWAD], TMsgType.Notify);
3532 NewWAD := gWAD;
3534 g_Game_LoadWAD(NewWAD);
3535 result := NewWAD;
3538 if LowerCase(NewWAD) = LowerCase(gGameSettings.WAD) then Exit;
3539 gWAD := g_Res_SearchSameWAD(MapsDir, ExtractFileName(NewWAD), WHash);
3540 if gWAD = '' then
3541 begin
3542 g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
3543 gWAD := g_Res_DownloadMapWAD(ExtractFileName(NewWAD), WHash);
3544 if gWAD = '' then
3545 begin
3546 g_Game_Free();
3547 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_WAD], [ExtractFileName(NewWAD)]));
3548 Exit;
3549 end;
3550 end;
3551 NewWAD := ExtractRelativePath(MapsDir, gWAD);
3552 g_Game_LoadWAD(NewWAD);
3554 end;
3556 procedure g_Game_RestartRound(NoMapRestart: Boolean = False);
3557 var
3558 i, n, nb, nr: Integer;
3559 begin
3560 if not g_Game_IsServer then Exit;
3561 if gLMSRespawn = LMS_RESPAWN_NONE then Exit;
3562 gLMSRespawn := LMS_RESPAWN_NONE;
3563 gLMSRespawnTime := 0;
3564 MessageTime := 0;
3566 if (gGameSettings.GameMode = GM_COOP) and not NoMapRestart then
3567 begin
3568 gMissionFailed := True;
3569 g_Game_RestartLevel;
3570 Exit;
3571 end;
3573 n := 0; nb := 0; nr := 0;
3574 for i := Low(gPlayers) to High(gPlayers) do
3575 if (gPlayers[i] <> nil) and
3576 ((not gPlayers[i].FSpectator) or gPlayers[i].FWantsInGame or
3577 (gPlayers[i] is TBot)) then
3578 begin
3579 Inc(n);
3580 if gPlayers[i].Team = TEAM_RED then Inc(nr)
3581 else if gPlayers[i].Team = TEAM_BLUE then Inc(nb)
3582 end;
3584 if (n < 1) or ((gGameSettings.GameMode = GM_TDM) and ((nr = 0) or (nb = 0))) then
3585 begin
3586 // wait a second until the fuckers finally decide to join
3587 gLMSRespawn := LMS_RESPAWN_WARMUP;
3588 gLMSRespawnTime := gTime + gGameSettings.WarmupTime*1000;
3589 gLMSSoftSpawn := NoMapRestart;
3590 if g_Game_IsNet then
3591 MH_SEND_GameEvent(NET_EV_LMS_WARMUP, gLMSRespawnTime - gTime);
3592 Exit;
3593 end;
3595 g_Player_RemoveAllCorpses;
3596 g_Game_Message(_lc[I_MESSAGE_LMS_START], 144);
3597 if g_Game_IsNet then
3598 MH_SEND_GameEvent(NET_EV_LMS_START);
3600 for i := Low(gPlayers) to High(gPlayers) do
3601 begin
3602 if gPlayers[i] = nil then continue;
3603 if gPlayers[i] is TBot then gPlayers[i].FWantsInGame := True;
3604 // don't touch normal spectators
3605 if gPlayers[i].FSpectator and not gPlayers[i].FWantsInGame then
3606 begin
3607 gPlayers[i].FNoRespawn := True;
3608 gPlayers[i].Lives := 0;
3609 if g_Game_IsNet then
3610 MH_SEND_PlayerStats(gPlayers[I].UID);
3611 continue;
3612 end;
3613 gPlayers[i].FNoRespawn := False;
3614 gPlayers[i].Lives := gGameSettings.MaxLives;
3615 gPlayers[i].Respawn(False, True);
3616 if gGameSettings.GameMode = GM_COOP then
3617 begin
3618 gPlayers[i].Frags := 0;
3619 gPlayers[i].RecallState;
3620 end;
3621 if (gPlayer1 = nil) and (gSpectLatchPID1 > 0) then
3622 gPlayer1 := g_Player_Get(gSpectLatchPID1);
3623 if (gPlayer2 = nil) and (gSpectLatchPID2 > 0) then
3624 gPlayer2 := g_Player_Get(gSpectLatchPID2);
3625 end;
3627 g_Items_RestartRound();
3629 gLMSSoftSpawn := False;
3630 end;
3632 function g_Game_GetFirstMap(WAD: String): String;
3633 begin
3634 Result := '';
3636 MapList := g_Map_GetMapsList(WAD);
3637 if MapList = nil then
3638 Exit;
3640 SortSArray(MapList);
3641 Result := MapList[Low(MapList)];
3643 if not g_Map_Exist(WAD + ':\' + Result) then
3644 Result := '';
3646 MapList := nil;
3647 end;
3649 function g_Game_GetNextMap(): String;
3650 var
3651 I: Integer;
3652 Map: string;
3653 begin
3654 Result := '';
3656 MapList := g_Map_GetMapsList(gGameSettings.WAD);
3657 if MapList = nil then
3658 Exit;
3660 Map := g_ExtractFileName(gMapInfo.Map);
3662 SortSArray(MapList);
3663 MapIndex := -255;
3664 for I := Low(MapList) to High(MapList) do
3665 if Map = MapList[I] then
3666 begin
3667 MapIndex := I;
3668 Break;
3669 end;
3671 if MapIndex <> -255 then
3672 begin
3673 if MapIndex = High(MapList) then
3674 Result := MapList[Low(MapList)]
3675 else
3676 Result := MapList[MapIndex + 1];
3678 if not g_Map_Exist(gGameSettings.WAD + ':\' + Result) then Result := Map;
3679 end;
3681 MapList := nil;
3682 end;
3684 procedure g_Game_NextLevel();
3685 begin
3686 if gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF, GM_COOP] then
3687 gExit := EXIT_ENDLEVELCUSTOM
3688 else
3689 begin
3690 gExit := EXIT_ENDLEVELSINGLE;
3691 Exit;
3692 end;
3694 if gNextMap <> '' then Exit;
3695 gNextMap := g_Game_GetNextMap();
3696 end;
3698 function g_Game_IsTestMap(): Boolean;
3699 begin
3700 result := StrEquCI1251(TEST_MAP_NAME, g_ExtractFileName(gMapInfo.Map));
3701 end;
3703 procedure g_Game_DeleteTestMap();
3704 var
3705 a: Integer;
3706 //MapName: AnsiString;
3707 WadName: string;
3709 WAD: TWADFile;
3710 MapList: SSArray;
3711 time: Integer;
3713 begin
3714 a := Pos('.wad:\', toLowerCase1251(gMapToDelete));
3715 if (a = 0) then a := Pos('.wad:/', toLowerCase1251(gMapToDelete));
3716 if (a = 0) then exit;
3718 // Выделяем имя wad-файла и имя карты
3719 WadName := Copy(gMapToDelete, 1, a+3);
3720 Delete(gMapToDelete, 1, a+5);
3721 gMapToDelete := UpperCase(gMapToDelete);
3722 //MapName := '';
3723 //CopyMemory(@MapName[0], @gMapToDelete[1], Min(16, Length(gMapToDelete)));
3726 // Имя карты не стандартное тестовое:
3727 if MapName <> TEST_MAP_NAME then
3728 Exit;
3730 if not gTempDelete then
3731 begin
3732 time := g_GetFileTime(WadName);
3733 WAD := TWADFile.Create();
3735 // Читаем Wad-файл:
3736 if not WAD.ReadFile(WadName) then
3737 begin // Нет такого WAD-файла
3738 WAD.Free();
3739 Exit;
3740 end;
3742 // Составляем список карт и ищем нужную:
3743 WAD.CreateImage();
3744 MapList := WAD.GetResourcesList('');
3746 if MapList <> nil then
3747 for a := 0 to High(MapList) do
3748 if MapList[a] = MapName then
3749 begin
3750 // Удаляем и сохраняем:
3751 WAD.RemoveResource('', MapName);
3752 WAD.SaveTo(WadName);
3753 Break;
3754 end;
3756 WAD.Free();
3757 g_SetFileTime(WadName, time);
3758 end else
3760 if gTempDelete then DeleteFile(WadName);
3761 end;
3763 procedure GameCVars(P: SSArray);
3764 var
3765 a, b: Integer;
3766 stat: TPlayerStatArray;
3767 cmd: string;
3769 procedure ParseGameFlag(Flag: LongWord; OffMsg, OnMsg: TStrings_Locale; OnMapChange: Boolean = False);
3770 var
3771 x: Boolean;
3772 begin
3773 if Length(P) > 1 then
3774 begin
3775 x := P[1] = '1';
3777 if x then
3778 gsGameFlags := gsGameFlags or Flag
3779 else
3780 gsGameFlags := gsGameFlags and (not Flag);
3782 if g_Game_IsServer then
3783 begin
3784 if x then
3785 gGameSettings.Options := gGameSettings.Options or Flag
3786 else
3787 gGameSettings.Options := gGameSettings.Options and (not Flag);
3788 if g_Game_IsNet then MH_SEND_GameSettings;
3789 end;
3790 end;
3792 if LongBool(gsGameFlags and Flag) then
3793 g_Console_Add(_lc[OnMsg])
3794 else
3795 g_Console_Add(_lc[OffMsg]);
3797 if OnMapChange and g_Game_IsServer then
3798 g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
3799 end;
3801 begin
3802 stat := nil;
3803 cmd := LowerCase(P[0]);
3805 if cmd = 'g_gamemode' then
3806 begin
3807 if (Length(P) > 1) then
3808 begin
3809 a := g_Game_TextToMode(P[1]);
3810 if a = GM_SINGLE then a := GM_COOP;
3811 gsGameMode := g_Game_ModeToText(a);
3812 if g_Game_IsServer then
3813 begin
3814 gSwitchGameMode := a;
3815 if (gGameOn and (gGameSettings.GameMode = GM_SINGLE)) or
3816 (gState = STATE_INTERSINGLE) then
3817 gSwitchGameMode := GM_SINGLE;
3818 if not gGameOn then
3819 gGameSettings.GameMode := gSwitchGameMode;
3820 end;
3821 end;
3823 if gSwitchGameMode = gGameSettings.GameMode then
3824 g_Console_Add(Format(_lc[I_MSG_GAMEMODE_CURRENT],
3825 [g_Game_ModeToText(gGameSettings.GameMode)]))
3826 else
3827 g_Console_Add(Format(_lc[I_MSG_GAMEMODE_CHANGE],
3828 [g_Game_ModeToText(gGameSettings.GameMode),
3829 g_Game_ModeToText(gSwitchGameMode)]));
3830 end
3831 else if cmd = 'g_friendlyfire' then
3832 begin
3833 ParseGameFlag(GAME_OPTION_TEAMDAMAGE, I_MSG_FRIENDLY_FIRE_OFF, I_MSG_FRIENDLY_FIRE_ON);
3834 end
3835 else if cmd = 'g_friendly_absorb_damage' then
3836 begin
3837 ParseGameFlag(GAME_OPTION_TEAMABSORBDAMAGE, I_MSG_FRIENDLY_FIRE_OFF, I_MSG_FRIENDLY_FIRE_ON);
3838 end
3839 else if cmd = 'g_friendly_hit_trace' then
3840 begin
3841 ParseGameFlag(GAME_OPTION_TEAMHITTRACE, I_MSG_FRIENDLY_FIRE_OFF, I_MSG_FRIENDLY_FIRE_ON);
3842 end
3843 else if cmd = 'g_friendly_hit_projectile' then
3844 begin
3845 ParseGameFlag(GAME_OPTION_TEAMHITPROJECTILE, I_MSG_FRIENDLY_FIRE_OFF, I_MSG_FRIENDLY_FIRE_ON);
3846 end
3847 else if cmd = 'g_weaponstay' then
3848 begin
3849 ParseGameFlag(GAME_OPTION_WEAPONSTAY, I_MSG_WEAPONSTAY_OFF, I_MSG_WEAPONSTAY_ON);
3850 end
3851 else if cmd = 'g_allow_exit' then
3852 begin
3853 ParseGameFlag(GAME_OPTION_ALLOWEXIT, I_MSG_ALLOWEXIT_OFF, I_MSG_ALLOWEXIT_ON, True);
3854 end
3855 else if cmd = 'g_allow_monsters' then
3856 begin
3857 ParseGameFlag(GAME_OPTION_MONSTERS, I_MSG_ALLOWMON_OFF, I_MSG_ALLOWMON_ON, True);
3858 end
3859 else if cmd = 'g_bot_vsplayers' then
3860 begin
3861 ParseGameFlag(GAME_OPTION_BOTVSPLAYER, I_MSG_BOTSVSPLAYERS_OFF, I_MSG_BOTSVSPLAYERS_ON);
3862 end
3863 else if cmd = 'g_bot_vsmonsters' then
3864 begin
3865 ParseGameFlag(GAME_OPTION_BOTVSMONSTER, I_MSG_BOTSVSMONSTERS_OFF, I_MSG_BOTSVSMONSTERS_ON);
3866 end
3867 else if cmd = 'g_dm_keys' then
3868 begin
3869 ParseGameFlag(GAME_OPTION_DMKEYS, I_MSG_DMKEYS_OFF, I_MSG_DMKEYS_ON, True);
3870 end
3871 else if cmd = 'g_gameflags' then
3872 begin
3873 if Length(P) > 1 then
3874 begin
3875 gsGameFlags := StrToDWordDef(P[1], gsGameFlags);
3876 if g_Game_IsServer then
3877 begin
3878 gGameSettings.Options := gsGameFlags;
3879 if g_Game_IsNet then MH_SEND_GameSettings;
3880 end;
3881 end;
3883 g_Console_Add(Format('%s %u', [cmd, gsGameFlags]));
3884 end
3885 else if cmd = 'g_warmup_time' then
3886 begin
3887 if Length(P) > 1 then
3888 begin
3889 gsWarmupTime := nclamp(StrToIntDef(P[1], gsWarmupTime), 0, $FFFF);
3890 if g_Game_IsServer then
3891 begin
3892 gGameSettings.WarmupTime := gsWarmupTime;
3893 // extend warmup if it's already going
3894 if gLMSRespawn = LMS_RESPAWN_WARMUP then
3895 begin
3896 gLMSRespawnTime := gTime + gsWarmupTime * 1000;
3897 if g_Game_IsNet then MH_SEND_GameEvent(NET_EV_LMS_WARMUP, gLMSRespawnTime - gTime);
3898 end;
3899 if g_Game_IsNet then MH_SEND_GameSettings;
3900 end;
3901 end;
3903 g_Console_Add(Format(_lc[I_MSG_WARMUP], [Integer(gsWarmupTime)]));
3904 if g_Game_IsServer then g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
3905 end
3906 else if cmd = 'g_spawn_invul' then
3907 begin
3908 if Length(P) > 1 then
3909 begin
3910 gsSpawnInvul := nclamp(StrToIntDef(P[1], gsSpawnInvul), 0, $FFFF);
3911 if g_Game_IsServer then
3912 begin
3913 gGameSettings.SpawnInvul := gsSpawnInvul;
3914 if g_Game_IsNet then MH_SEND_GameSettings;
3915 end;
3916 end;
3918 g_Console_Add(Format('%s %d', [cmd, Integer(gsSpawnInvul)]));
3919 end
3920 else if cmd = 'g_item_respawn_time' then
3921 begin
3922 if Length(P) > 1 then
3923 begin
3924 gsItemRespawnTime := nclamp(StrToIntDef(P[1], gsItemRespawnTime), 0, $FFFF);
3925 if g_Game_IsServer then
3926 begin
3927 gGameSettings.ItemRespawnTime := gsItemRespawnTime;
3928 if g_Game_IsNet then MH_SEND_GameSettings;
3929 end;
3930 end;
3932 g_Console_Add(Format('%s %d', [cmd, Integer(gsItemRespawnTime)]));
3933 if g_Game_IsServer then g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
3934 end
3935 else if cmd = 'sv_intertime' then
3936 begin
3937 if (Length(P) > 1) then
3938 gDefInterTime := Min(Max(StrToIntDef(P[1], gDefInterTime), -1), 120);
3940 g_Console_Add(cmd + ' = ' + IntToStr(gDefInterTime));
3941 end
3942 else if cmd = 'g_max_particles' then
3943 begin
3944 if Length(p) = 2 then
3945 begin
3946 a := Max(0, StrToInt(p[1]));
3947 g_GFX_SetMax(a)
3948 end
3949 else if Length(p) = 1 then
3950 begin
3951 e_LogWritefln('%s', [g_GFX_GetMax()])
3952 end
3953 else
3954 begin
3955 e_LogWritefln('usage: %s <n>', [cmd])
3956 end
3957 end
3958 else if cmd = 'g_max_shells' then
3959 begin
3960 if Length(p) = 2 then
3961 begin
3962 a := Max(0, StrToInt(p[1]));
3963 g_Shells_SetMax(a)
3964 end
3965 else if Length(p) = 1 then
3966 begin
3967 e_LogWritefln('%s', [g_Shells_GetMax()])
3968 end
3969 else
3970 begin
3971 e_LogWritefln('usage: %s <n>', [cmd])
3972 end
3973 end
3974 else if cmd = 'g_max_gibs' then
3975 begin
3976 if Length(p) = 2 then
3977 begin
3978 a := Max(0, StrToInt(p[1]));
3979 g_Gibs_SetMax(a)
3980 end
3981 else if Length(p) = 1 then
3982 begin
3983 e_LogWritefln('%s', [g_Gibs_GetMax()])
3984 end
3985 else
3986 begin
3987 e_LogWritefln('usage: %s <n>', [cmd])
3988 end
3989 end
3990 else if cmd = 'g_max_corpses' then
3991 begin
3992 if Length(p) = 2 then
3993 begin
3994 a := Max(0, StrToInt(p[1]));
3995 g_Corpses_SetMax(a)
3996 end
3997 else if Length(p) = 1 then
3998 begin
3999 e_LogWritefln('%s', [g_Corpses_GetMax()])
4000 end
4001 else
4002 begin
4003 e_LogWritefln('usage: %s <n>', [cmd])
4004 end
4005 end
4006 else if cmd = 'g_scorelimit' then
4007 begin
4008 if Length(P) > 1 then
4009 begin
4010 gsGoalLimit := nclamp(StrToIntDef(P[1], gsGoalLimit), 0, $FFFF);
4012 if g_Game_IsServer then
4013 begin
4014 b := 0;
4015 if gGameSettings.GameMode = GM_DM then
4016 begin // DM
4017 stat := g_Player_GetStats();
4018 if stat <> nil then
4019 for a := 0 to High(stat) do
4020 if stat[a].Frags > b then
4021 b := stat[a].Frags;
4022 end
4023 else // TDM/CTF
4024 b := Max(gTeamStat[TEAM_RED].Goals, gTeamStat[TEAM_BLUE].Goals);
4026 // if someone has a higher score, set it to that instead
4027 gsGoalLimit := max(gsGoalLimit, b);
4028 gGameSettings.GoalLimit := gsGoalLimit;
4030 if g_Game_IsNet then MH_SEND_GameSettings;
4031 end;
4032 end;
4034 g_Console_Add(Format(_lc[I_MSG_SCORE_LIMIT], [Integer(gsGoalLimit)]));
4035 end
4036 else if cmd = 'g_timelimit' then
4037 begin
4038 if Length(P) > 1 then
4039 begin
4040 gsTimeLimit := nclamp(StrToIntDef(P[1], gsTimeLimit), 0, $FFFF);
4041 if g_Game_IsServer then
4042 begin
4043 gGameSettings.TimeLimit := gsTimeLimit;
4044 if g_Game_IsNet then MH_SEND_GameSettings;
4045 end;
4046 end;
4047 g_Console_Add(Format(_lc[I_MSG_TIME_LIMIT],
4048 [gsTimeLimit div 3600,
4049 (gsTimeLimit div 60) mod 60,
4050 gsTimeLimit mod 60]));
4051 end
4052 else if cmd = 'g_maxlives' then
4053 begin
4054 if Length(P) > 1 then
4055 begin
4056 gsMaxLives := nclamp(StrToIntDef(P[1], gsMaxLives), 0, $FFFF);
4057 if g_Game_IsServer then
4058 begin
4059 gGameSettings.MaxLives := gsMaxLives;
4060 if g_Game_IsNet then MH_SEND_GameSettings;
4061 end;
4062 end;
4064 g_Console_Add(Format(_lc[I_MSG_LIVES], [Integer(gsMaxLives)]));
4065 end;
4066 end;
4068 procedure PlayerSettingsCVars(P: SSArray);
4069 var
4070 cmd: string;
4071 team: Byte;
4073 function ParseTeam(s: string): Byte;
4074 begin
4075 result := 0;
4076 case s of
4077 'red', '1': result := TEAM_RED;
4078 'blue', '2': result := TEAM_BLUE;
4079 else result := TEAM_NONE;
4080 end;
4081 end;
4082 begin
4083 cmd := LowerCase(P[0]);
4084 case cmd of
4085 'p1_name':
4086 begin
4087 if (Length(P) > 1) then
4088 begin
4089 gPlayer1Settings.Name := b_Text_Unformat(P[1]);
4090 if g_Game_IsClient then
4091 MC_SEND_PlayerSettings
4092 else if gGameOn and (gPlayer1 <> nil) then
4093 begin
4094 gPlayer1.Name := b_Text_Unformat(P[1]);
4095 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer1.UID);
4096 end;
4097 end;
4098 end;
4099 'p2_name':
4100 begin
4101 if (Length(P) > 1) then
4102 begin
4103 gPlayer2Settings.Name := b_Text_Unformat(P[1]);
4104 if g_Game_IsClient then
4105 MC_SEND_PlayerSettings
4106 else if gGameOn and (gPlayer2 <> nil) then
4107 begin
4108 gPlayer2.Name := b_Text_Unformat(P[1]);
4109 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer2.UID);
4110 end;
4111 end;
4112 end;
4113 'p1_color':
4114 begin
4115 if Length(P) > 3 then
4116 begin
4117 gPlayer1Settings.Color := _RGB(EnsureRange(StrToIntDef(P[1], 0), 0, 255),
4118 EnsureRange(StrToIntDef(P[2], 0), 0, 255),
4119 EnsureRange(StrToIntDef(P[3], 0), 0, 255));
4120 if g_Game_IsClient then
4121 MC_SEND_PlayerSettings
4122 else if gGameOn and (gPlayer1 <> nil) then
4123 begin
4124 gPlayer1.SetColor(gPlayer1Settings.Color);
4125 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer1.UID);
4126 end;
4127 end;
4128 end;
4129 'p2_color':
4130 begin
4131 if Length(P) > 3 then
4132 begin
4133 gPlayer2Settings.Color := _RGB(EnsureRange(StrToIntDef(P[1], 0), 0, 255),
4134 EnsureRange(StrToIntDef(P[2], 0), 0, 255),
4135 EnsureRange(StrToIntDef(P[3], 0), 0, 255));
4136 if g_Game_IsClient then
4137 MC_SEND_PlayerSettings
4138 else if gGameOn and (gPlayer2 <> nil) then
4139 begin
4140 gPlayer2.SetColor(gPlayer2Settings.Color);
4141 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer2.UID);
4142 end;
4143 end;
4144 end;
4145 'p1_model':
4146 begin
4147 if (Length(P) > 1) then
4148 begin
4149 gPlayer1Settings.Model := P[1];
4150 if g_Game_IsClient then
4151 MC_SEND_PlayerSettings
4152 else if gGameOn and (gPlayer1 <> nil) then
4153 begin
4154 gPlayer1.FActualModelName := gPlayer1Settings.Model;
4155 gPlayer1.SetModel(gPlayer1Settings.Model);
4156 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer1.UID);
4157 end;
4158 end;
4159 end;
4160 'p2_model':
4161 begin
4162 if (Length(P) > 1) then
4163 begin
4164 gPlayer2Settings.Model := P[1];
4165 if g_Game_IsClient then
4166 MC_SEND_PlayerSettings
4167 else if gGameOn and (gPlayer2 <> nil) then
4168 begin
4169 gPlayer2.FActualModelName := gPlayer2Settings.Model;
4170 gPlayer2.SetModel(gPlayer2Settings.Model);
4171 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer2.UID);
4172 end;
4173 end;
4174 end;
4175 'p1_team':
4176 begin
4177 // TODO: switch teams if in game or store this separately
4178 if (Length(P) > 1) then
4179 begin
4180 team := ParseTeam(P[1]);
4181 if team = TEAM_NONE then
4182 g_Console_Add('expected ''red'', ''blue'', 1 or 2')
4183 else if not gGameOn and not g_Game_IsNet then
4184 gPlayer1Settings.Team := team
4185 else
4186 g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
4187 end;
4188 end;
4189 'p2_team':
4190 begin
4191 // TODO: switch teams if in game or store this separately
4192 if (Length(P) > 1) then
4193 begin
4194 team := ParseTeam(P[1]);
4195 if team = TEAM_NONE then
4196 g_Console_Add('expected ''red'', ''blue'', 1 or 2')
4197 else if not gGameOn and not g_Game_IsNet then
4198 gPlayer2Settings.Team := team
4199 else
4200 g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
4201 end;
4202 end;
4203 end;
4204 end;
4206 procedure PrintHeapStats();
4207 var
4208 hs: TFPCHeapStatus;
4209 begin
4210 hs := GetFPCHeapStatus();
4211 e_LogWriteLn ('v===== heap status =====v');
4212 e_LogWriteFln('max heap size = %d k', [hs.MaxHeapSize div 1024]);
4213 e_LogWriteFln('max heap used = %d k', [hs.MaxHeapUsed div 1024]);
4214 e_LogWriteFln('cur heap size = %d k', [hs.CurrHeapSize div 1024]);
4215 e_LogWriteFln('cur heap used = %d k', [hs.CurrHeapUsed div 1024]);
4216 e_LogWriteFln('cur heap free = %d k', [hs.CurrHeapFree div 1024]);
4217 e_LogWriteLn ('^=======================^');
4218 end;
4220 procedure DebugCommands(P: SSArray);
4221 var
4222 a, b: Integer;
4223 cmd: string;
4224 //pt: TDFPoint;
4225 mon: TMonster;
4226 begin
4227 // Команды отладочного режима:
4228 if {gDebugMode}conIsCheatsEnabled then
4229 begin
4230 cmd := LowerCase(P[0]);
4231 if cmd = 'd_window' then
4232 begin
4233 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth, gScreenHeight]));
4234 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth, gScreenHeight]));
4235 end
4236 else if cmd = 'd_sounds' then
4237 begin
4238 if (Length(P) > 1) and
4239 ((P[1] = '1') or (P[1] = '0')) then
4240 g_Debug_Sounds := (P[1][1] = '1');
4242 g_Console_Add(Format('d_sounds is %d', [Byte(g_Debug_Sounds)]));
4243 end
4244 else if cmd = 'd_frames' then
4245 begin
4246 if (Length(P) > 1) and
4247 ((P[1] = '1') or (P[1] = '0')) then
4248 g_Debug_Frames := (P[1][1] = '1');
4250 g_Console_Add(Format('d_frames is %d', [Byte(g_Debug_Frames)]));
4251 end
4252 else if cmd = 'd_winmsg' then
4253 begin
4254 if (Length(P) > 1) and
4255 ((P[1] = '1') or (P[1] = '0')) then
4256 g_Debug_WinMsgs := (P[1][1] = '1');
4258 g_Console_Add(Format('d_winmsg is %d', [Byte(g_Debug_WinMsgs)]));
4259 end
4260 else if (cmd = 'd_monoff') and not g_Game_IsNet then
4261 begin
4262 if (Length(P) > 1) and
4263 ((P[1] = '1') or (P[1] = '0')) then
4264 g_Debug_MonsterOff := (P[1][1] = '1');
4266 g_Console_Add(Format('d_monoff is %d', [Byte(g_debug_MonsterOff)]));
4267 end
4268 else if (cmd = 'd_botoff') and not g_Game_IsNet then
4269 begin
4270 if Length(P) > 1 then
4271 case P[1][1] of
4272 '0': g_debug_BotAIOff := 0;
4273 '1': g_debug_BotAIOff := 1;
4274 '2': g_debug_BotAIOff := 2;
4275 '3': g_debug_BotAIOff := 3;
4276 end;
4278 g_Console_Add(Format('d_botoff is %d', [g_debug_BotAIOff]));
4279 end
4280 else if cmd = 'd_monster' then
4281 begin
4282 if gGameOn and (gPlayer1 <> nil) and (gPlayer1.alive) and (not g_Game_IsNet) then
4283 if Length(P) < 2 then
4284 begin
4285 g_Console_Add(cmd + ' [ID | Name] [behaviour]');
4286 g_Console_Add('ID | Name');
4287 for b := MONSTER_DEMON to MONSTER_MAN do
4288 g_Console_Add(Format('%2d | %s', [b, g_Mons_NameByTypeId(b)]));
4289 conwriteln('behav. num'#10'normal 0'#10'killer 1'#10'maniac 2'#10'insane 3'#10'cannibal 4'#10'good 5');
4290 end else
4291 begin
4292 a := StrToIntDef(P[1], 0);
4293 if (a < MONSTER_DEMON) or (a > MONSTER_MAN) then
4294 a := g_Mons_TypeIdByName(P[1]);
4296 if (a < MONSTER_DEMON) or (a > MONSTER_MAN) then
4297 g_Console_Add(Format(_lc[I_MSG_NO_MONSTER], [P[1]]))
4298 else
4299 begin
4300 with gPlayer1.Obj do
4301 begin
4302 mon := g_Monsters_Create(a,
4303 X + Rect.X + (Rect.Width div 2),
4304 Y + Rect.Y + Rect.Height,
4305 gPlayer1.Direction, True);
4306 end;
4307 if (Length(P) > 2) and (mon <> nil) then
4308 begin
4309 if (CompareText(P[2], 'normal') = 0) then mon.MonsterBehaviour := BH_NORMAL
4310 else if (CompareText(P[2], 'killer') = 0) then mon.MonsterBehaviour := BH_KILLER
4311 else if (CompareText(P[2], 'maniac') = 0) then mon.MonsterBehaviour := BH_MANIAC
4312 else if (CompareText(P[2], 'insane') = 0) then mon.MonsterBehaviour := BH_INSANE
4313 else if (CompareText(P[2], 'cannibal') = 0) then mon.MonsterBehaviour := BH_CANNIBAL
4314 else if (CompareText(P[2], 'good') = 0) then mon.MonsterBehaviour := BH_GOOD
4315 else if (CompareText(P[2], 'friend') = 0) then mon.MonsterBehaviour := BH_GOOD
4316 else if (CompareText(P[2], 'friendly') = 0) then mon.MonsterBehaviour := BH_GOOD
4317 else mon.MonsterBehaviour := Min(Max(StrToIntDef(P[2], BH_NORMAL), BH_NORMAL), BH_GOOD);
4318 end;
4319 end;
4320 end;
4321 end
4322 else if (cmd = 'd_health') then
4323 begin
4324 if (Length(P) > 1) and
4325 ((P[1] = '1') or (P[1] = '0')) then
4326 g_debug_HealthBar := (P[1][1] = '1');
4328 g_Console_Add(Format('d_health is %d', [Byte(g_debug_HealthBar)]));
4329 end
4330 else if (cmd = 'd_player') then
4331 begin
4332 if (Length(P) > 1) and
4333 ((P[1] = '1') or (P[1] = '0')) then
4334 g_debug_Player := (P[1][1] = '1');
4336 g_Console_Add(Format(cmd + ' is %d', [Byte(g_Debug_Player)]));
4337 end
4338 else if (cmd = 'd_mem') then
4339 begin
4340 PrintHeapStats();
4341 end;
4342 end
4343 else
4344 g_Console_Add(_lc[I_MSG_NOT_DEBUG]);
4345 end;
4348 procedure GameCheats(P: SSArray);
4349 var
4350 cmd: string;
4351 f, a: Integer;
4352 plr: TPlayer;
4353 begin
4354 if (not gGameOn) or (not conIsCheatsEnabled) then
4355 begin
4356 g_Console_Add('not available');
4357 exit;
4358 end;
4359 plr := gPlayer1;
4360 if plr = nil then
4361 begin
4362 g_Console_Add('where is the player?!');
4363 exit;
4364 end;
4365 cmd := LowerCase(P[0]);
4366 // god
4367 if cmd = 'god' then
4368 begin
4369 plr.GodMode := not plr.GodMode;
4370 if plr.GodMode then g_Console_Add('player is godlike now') else g_Console_Add('player is mortal now');
4371 exit;
4372 end;
4373 // give <health|exit|weapons|air|suit|jetpack|berserk|all>
4374 if cmd = 'give' then
4375 begin
4376 if length(P) < 2 then begin g_Console_Add('give what?!'); exit; end;
4377 for f := 1 to High(P) do
4378 begin
4379 cmd := LowerCase(P[f]);
4380 if cmd = 'health' then begin plr.RestoreHealthArmor(); g_Console_Add('player feels himself better'); continue; end;
4381 if (cmd = 'all') {or (cmd = 'weapons')} then begin plr.AllRulez(False); g_Console_Add('player got the gifts'); continue; end;
4382 if cmd = 'exit' then
4383 begin
4384 if gTriggers <> nil then
4385 begin
4386 for a := 0 to High(gTriggers) do
4387 begin
4388 if gTriggers[a].TriggerType = TRIGGER_EXIT then
4389 begin
4390 g_Console_Add('player left the map');
4391 gExitByTrigger := True;
4392 //g_Game_ExitLevel(gTriggers[a].Data.MapName);
4393 g_Game_ExitLevel(gTriggers[a].tgcMap);
4394 break;
4395 end;
4396 end;
4397 end;
4398 continue;
4399 end;
4401 if cmd = 'air' then begin plr.GiveItem(ITEM_OXYGEN); g_Console_Add('player got some air'); continue; end;
4402 if cmd = 'jetpack' then begin plr.GiveItem(ITEM_JETPACK); g_Console_Add('player got a jetpack'); continue; end;
4403 if cmd = 'suit' then begin plr.GiveItem(ITEM_SUIT); g_Console_Add('player got an envirosuit'); continue; end;
4404 if cmd = 'berserk' then begin plr.GiveItem(ITEM_MEDKIT_BLACK); g_Console_Add('player got a berserk pack'); continue; end;
4405 if cmd = 'backpack' then begin plr.GiveItem(ITEM_AMMO_BACKPACK); g_Console_Add('player got a backpack'); continue; end;
4407 if cmd = 'helmet' then begin plr.GiveItem(ITEM_HELMET); g_Console_Add('player got a helmet'); continue; end;
4408 if cmd = 'bottle' then begin plr.GiveItem(ITEM_BOTTLE); g_Console_Add('player got a bottle of health'); continue; end;
4410 if cmd = 'stimpack' then begin plr.GiveItem(ITEM_MEDKIT_SMALL); g_Console_Add('player got a stimpack'); continue; end;
4411 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;
4413 if cmd = 'greenarmor' then begin plr.GiveItem(ITEM_ARMOR_GREEN); g_Console_Add('player got a security armor'); continue; end;
4414 if cmd = 'bluearmor' then begin plr.GiveItem(ITEM_ARMOR_BLUE); g_Console_Add('player got a combat armor'); continue; end;
4416 if (cmd = 'megasphere') or (cmd = 'mega') then begin plr.GiveItem(ITEM_SPHERE_BLUE); g_Console_Add('player got a megasphere'); continue; end;
4417 if (cmd = 'soulsphere') or (cmd = 'soul')then begin plr.GiveItem(ITEM_SPHERE_WHITE); g_Console_Add('player got a soul sphere'); continue; end;
4419 if (cmd = 'invul') or (cmd = 'invulnerability') then begin plr.GiveItem(ITEM_INVUL); g_Console_Add('player got invulnerability'); continue; end;
4420 if (cmd = 'invis') or (cmd = 'invisibility') then begin plr.GiveItem(ITEM_INVIS); g_Console_Add('player got invisibility'); continue; end;
4422 if cmd = 'redkey' then begin plr.GiveItem(ITEM_KEY_RED); g_Console_Add('player got the red key'); continue; end;
4423 if cmd = 'greenkey' then begin plr.GiveItem(ITEM_KEY_GREEN); g_Console_Add('player got the green key'); continue; end;
4424 if cmd = 'bluekey' then begin plr.GiveItem(ITEM_KEY_BLUE); g_Console_Add('player got the blue key'); continue; end;
4426 if (cmd = 'shotgun') or (cmd = 'sg') then begin plr.GiveItem(ITEM_WEAPON_SHOTGUN1); g_Console_Add('player got a shotgun'); continue; end;
4427 if (cmd = 'supershotgun') or (cmd = 'ssg') then begin plr.GiveItem(ITEM_WEAPON_SHOTGUN2); g_Console_Add('player got a supershotgun'); continue; end;
4428 if cmd = 'chaingun' then begin plr.GiveItem(ITEM_WEAPON_CHAINGUN); g_Console_Add('player got a chaingun'); continue; end;
4429 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;
4430 if cmd = 'plasmagun' then begin plr.GiveItem(ITEM_WEAPON_PLASMA); g_Console_Add('player got a plasma gun'); continue; end;
4431 if cmd = 'bfg' then begin plr.GiveItem(ITEM_WEAPON_BFG); g_Console_Add('player got a BFG-9000'); continue; end;
4433 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;
4434 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;
4435 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;
4436 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;
4437 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;
4438 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;
4440 if cmd = 'superchaingun' then begin plr.GiveItem(ITEM_WEAPON_SUPERPULEMET); g_Console_Add('player got a superchaingun'); continue; end;
4441 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;
4443 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;
4444 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;
4446 if cmd = 'chainsaw' then begin plr.GiveItem(ITEM_WEAPON_SAW); g_Console_Add('player got a chainsaw'); continue; end;
4448 if cmd = 'ammo' then
4449 begin
4450 plr.GiveItem(ITEM_AMMO_SHELLS_BOX);
4451 plr.GiveItem(ITEM_AMMO_BULLETS_BOX);
4452 plr.GiveItem(ITEM_AMMO_CELL_BIG);
4453 plr.GiveItem(ITEM_AMMO_ROCKET_BOX);
4454 plr.GiveItem(ITEM_AMMO_FUELCAN);
4455 g_Console_Add('player got some ammo');
4456 continue;
4457 end;
4459 if cmd = 'clip' then begin plr.GiveItem(ITEM_AMMO_BULLETS); g_Console_Add('player got some bullets'); continue; end;
4460 if cmd = 'bullets' then begin plr.GiveItem(ITEM_AMMO_BULLETS_BOX); g_Console_Add('player got a box of bullets'); continue; end;
4462 if cmd = 'shells' then begin plr.GiveItem(ITEM_AMMO_SHELLS); g_Console_Add('player got some shells'); continue; end;
4463 if cmd = 'shellbox' then begin plr.GiveItem(ITEM_AMMO_SHELLS_BOX); g_Console_Add('player got a box of shells'); continue; end;
4465 if cmd = 'cells' then begin plr.GiveItem(ITEM_AMMO_CELL); g_Console_Add('player got some cells'); continue; end;
4466 if cmd = 'battery' then begin plr.GiveItem(ITEM_AMMO_CELL_BIG); g_Console_Add('player got cell battery'); continue; end;
4468 if cmd = 'rocket' then begin plr.GiveItem(ITEM_AMMO_ROCKET); g_Console_Add('player got a rocket'); continue; end;
4469 if cmd = 'rocketbox' then begin plr.GiveItem(ITEM_AMMO_ROCKET_BOX); g_Console_Add('player got some rockets'); continue; end;
4471 if (cmd = 'fuel') or (cmd = 'fuelcan') then begin plr.GiveItem(ITEM_AMMO_FUELCAN); g_Console_Add('player got fuel canister'); continue; end;
4473 if cmd = 'weapons' then
4474 begin
4475 plr.GiveItem(ITEM_WEAPON_SHOTGUN1);
4476 plr.GiveItem(ITEM_WEAPON_SHOTGUN2);
4477 plr.GiveItem(ITEM_WEAPON_CHAINGUN);
4478 plr.GiveItem(ITEM_WEAPON_ROCKETLAUNCHER);
4479 plr.GiveItem(ITEM_WEAPON_PLASMA);
4480 plr.GiveItem(ITEM_WEAPON_BFG);
4481 g_Console_Add('player got weapons');
4482 continue;
4483 end;
4485 if cmd = 'keys' then
4486 begin
4487 plr.GiveItem(ITEM_KEY_RED);
4488 plr.GiveItem(ITEM_KEY_GREEN);
4489 plr.GiveItem(ITEM_KEY_BLUE);
4490 g_Console_Add('player got all keys');
4491 continue;
4492 end;
4494 g_Console_Add('i don''t know how to give '''+cmd+'''!');
4495 end;
4496 exit;
4497 end;
4498 // open
4499 if cmd = 'open' then
4500 begin
4501 g_Console_Add('player activated sesame');
4502 g_Triggers_OpenAll();
4503 exit;
4504 end;
4505 // fly
4506 if cmd = 'fly' then
4507 begin
4508 gFly := not gFly;
4509 if gFly then g_Console_Add('player feels himself lighter') else g_Console_Add('player lost his wings');
4510 exit;
4511 end;
4512 // noclip
4513 if cmd = 'noclip' then
4514 begin
4515 plr.SwitchNoClip;
4516 g_Console_Add('wall hardeness adjusted');
4517 exit;
4518 end;
4519 // notarget
4520 if cmd = 'notarget' then
4521 begin
4522 plr.NoTarget := not plr.NoTarget;
4523 if plr.NoTarget then g_Console_Add('player hides in shadows') else g_Console_Add('player is brave again');
4524 exit;
4525 end;
4526 // noreload
4527 if cmd = 'noreload' then
4528 begin
4529 plr.NoReload := not plr.NoReload;
4530 if plr.NoReload then g_Console_Add('player is action hero now') else g_Console_Add('player is ordinary man now');
4531 exit;
4532 end;
4533 // speedy
4534 if cmd = 'speedy' then
4535 begin
4536 MAX_RUNVEL := 32-MAX_RUNVEL;
4537 g_Console_Add('speed adjusted');
4538 exit;
4539 end;
4540 // jumpy
4541 if cmd = 'jumpy' then
4542 begin
4543 VEL_JUMP := 30-VEL_JUMP;
4544 g_Console_Add('jump height adjusted');
4545 exit;
4546 end;
4547 // automap
4548 if cmd = 'automap' then
4549 begin
4550 gShowMap := not gShowMap;
4551 if gShowMap then g_Console_Add('player gains second sight') else g_Console_Add('player lost second sight');
4552 exit;
4553 end;
4554 // aimline
4555 if cmd = 'aimline' then
4556 begin
4557 gAimLine := not gAimLine;
4558 if gAimLine then g_Console_Add('player gains laser sight') else g_Console_Add('player lost laser sight');
4559 exit;
4560 end;
4561 end;
4563 procedure GameCommands(P: SSArray);
4564 var
4565 a, b: Integer;
4566 s, pw: String;
4567 chstr: string;
4568 cmd: string;
4569 pl: pTNetClient = nil;
4570 plr: TPlayer;
4571 prt: Word;
4572 nm: Boolean;
4573 listen: LongWord;
4574 found: Boolean;
4575 begin
4576 // Общие команды:
4577 cmd := LowerCase(P[0]);
4578 chstr := '';
4579 if cmd = 'pause' then
4580 begin
4581 {$IFDEF ENABLE_MENU}
4582 if (g_ActiveWindow = nil) then
4583 g_Game_Pause(not gPauseMain);
4584 {$ELSE}
4585 g_Game_Pause(not gPauseMain);
4586 {$ENDIF}
4587 end
4588 else if cmd = 'endgame' then
4589 gExit := EXIT_SIMPLE
4590 else if cmd = 'restart' then
4591 begin
4592 if gGameOn or (gState in [STATE_INTERSINGLE, STATE_INTERCUSTOM]) then
4593 begin
4594 if g_Game_IsClient then
4595 begin
4596 g_Console_Add(_lc[I_MSG_SERVERONLY]);
4597 Exit;
4598 end;
4599 g_Game_Restart();
4600 end else
4601 g_Console_Add(_lc[I_MSG_NOT_GAME]);
4602 end
4603 else if cmd = 'kick' then
4604 begin
4605 if g_Game_IsServer then
4606 begin
4607 if Length(P) < 2 then
4608 begin
4609 g_Console_Add('kick <name>');
4610 Exit;
4611 end;
4612 if P[1] = '' then
4613 begin
4614 g_Console_Add('kick <name>');
4615 Exit;
4616 end;
4618 if g_Game_IsNet then
4619 pl := g_Net_Client_ByName(P[1]);
4620 if (pl <> nil) then
4621 begin
4622 s := g_Net_ClientName_ByID(pl^.ID);
4623 enet_peer_disconnect(pl^.Peer, NET_DISC_KICK);
4624 g_Console_Add(Format(_lc[I_PLAYER_KICK], [s]));
4625 MH_SEND_GameEvent(NET_EV_PLAYER_KICK, 0, s);
4626 g_Net_Slist_ServerPlayerLeaves();
4627 end else if gPlayers <> nil then
4628 for a := Low(gPlayers) to High(gPlayers) do
4629 if gPlayers[a] <> nil then
4630 if Copy(LowerCase(gPlayers[a].Name), 1, Length(P[1])) = LowerCase(P[1]) then
4631 begin
4632 // Не отключать основных игроков в сингле
4633 if not(gPlayers[a] is TBot) and (gGameSettings.GameType = GT_SINGLE) then
4634 continue;
4635 gPlayers[a].Lives := 0;
4636 gPlayers[a].Kill(K_SIMPLEKILL, 0, HIT_DISCON);
4637 g_Console_Add(Format(_lc[I_PLAYER_LEAVE], [gPlayers[a].Name]), True);
4638 g_Player_Remove(gPlayers[a].UID);
4639 g_Net_Slist_ServerPlayerLeaves();
4640 // Если не перемешать, при добавлении новых ботов появятся старые
4641 g_Bot_MixNames();
4642 end;
4643 end else
4644 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
4645 end
4646 else if cmd = 'kick_id' then
4647 begin
4648 if g_Game_IsServer and g_Game_IsNet then
4649 begin
4650 if Length(P) < 2 then
4651 begin
4652 g_Console_Add('kick_id <client ID>');
4653 Exit;
4654 end;
4655 if P[1] = '' then
4656 begin
4657 g_Console_Add('kick_id <client ID>');
4658 Exit;
4659 end;
4661 a := StrToIntDef(P[1], 0);
4662 if (NetClients <> nil) and (a <= High(NetClients)) then
4663 begin
4664 if NetClients[a].Used and (NetClients[a].Peer <> nil) then
4665 begin
4666 s := g_Net_ClientName_ByID(NetClients[a].ID);
4667 enet_peer_disconnect(NetClients[a].Peer, NET_DISC_KICK);
4668 g_Console_Add(Format(_lc[I_PLAYER_KICK], [s]));
4669 MH_SEND_GameEvent(NET_EV_PLAYER_KICK, 0, s);
4670 g_Net_Slist_ServerPlayerLeaves();
4671 end;
4672 end;
4673 end else
4674 g_Console_Add(_lc[I_MSG_SERVERONLY]);
4675 end
4676 else if cmd = 'kick_pid' then
4677 begin
4678 if g_Game_IsServer and g_Game_IsNet then
4679 begin
4680 if Length(P) < 2 then
4681 begin
4682 g_Console_Add('kick_pid <player ID>');
4683 Exit;
4684 end;
4685 if P[1] = '' then
4686 begin
4687 g_Console_Add('kick_pid <player ID>');
4688 Exit;
4689 end;
4691 a := StrToIntDef(P[1], 0);
4692 pl := g_Net_Client_ByPlayer(a);
4693 if (pl <> nil) and pl^.Used and (pl^.Peer <> nil) then
4694 begin
4695 s := g_Net_ClientName_ByID(pl^.ID);
4696 enet_peer_disconnect(pl^.Peer, NET_DISC_KICK);
4697 g_Console_Add(Format(_lc[I_PLAYER_KICK], [s]));
4698 MH_SEND_GameEvent(NET_EV_PLAYER_KICK, 0, s);
4699 g_Net_Slist_ServerPlayerLeaves();
4700 end;
4701 end else
4702 g_Console_Add(_lc[I_MSG_SERVERONLY]);
4703 end
4704 else if cmd = 'ban' then
4705 begin
4706 if g_Game_IsServer and g_Game_IsNet then
4707 begin
4708 if Length(P) < 2 then
4709 begin
4710 g_Console_Add('ban <name>');
4711 Exit;
4712 end;
4713 if P[1] = '' then
4714 begin
4715 g_Console_Add('ban <name>');
4716 Exit;
4717 end;
4719 pl := g_Net_Client_ByName(P[1]);
4720 if (pl <> nil) then
4721 begin
4722 s := g_Net_ClientName_ByID(pl^.ID);
4723 g_Net_BanHost(pl^.Peer^.address.host, False);
4724 enet_peer_disconnect(pl^.Peer, NET_DISC_TEMPBAN);
4725 g_Console_Add(Format(_lc[I_PLAYER_BAN], [s]));
4726 MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s);
4727 g_Net_Slist_ServerPlayerLeaves();
4728 end else
4729 g_Console_Add(Format(_lc[I_NET_ERR_NAME404], [P[1]]));
4730 end else
4731 g_Console_Add(_lc[I_MSG_SERVERONLY]);
4732 end
4733 else if cmd = 'ban_id' then
4734 begin
4735 if g_Game_IsServer and g_Game_IsNet then
4736 begin
4737 if Length(P) < 2 then
4738 begin
4739 g_Console_Add('ban_id <client ID>');
4740 Exit;
4741 end;
4742 if P[1] = '' then
4743 begin
4744 g_Console_Add('ban_id <client ID>');
4745 Exit;
4746 end;
4748 a := StrToIntDef(P[1], 0);
4749 if (NetClients <> nil) and (a <= High(NetClients)) then
4750 if NetClients[a].Used and (NetClients[a].Peer <> nil) then
4751 begin
4752 s := g_Net_ClientName_ByID(NetClients[a].ID);
4753 g_Net_BanHost(NetClients[a].Peer^.address.host, False);
4754 enet_peer_disconnect(NetClients[a].Peer, NET_DISC_TEMPBAN);
4755 g_Console_Add(Format(_lc[I_PLAYER_BAN], [s]));
4756 MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s);
4757 g_Net_Slist_ServerPlayerLeaves();
4758 end;
4759 end else
4760 g_Console_Add(_lc[I_MSG_SERVERONLY]);
4761 end
4762 else if cmd = 'ban_pid' then
4763 begin
4764 if g_Game_IsServer and g_Game_IsNet then
4765 begin
4766 if Length(P) < 2 then
4767 begin
4768 g_Console_Add('ban_pid <player ID>');
4769 Exit;
4770 end;
4771 if P[1] = '' then
4772 begin
4773 g_Console_Add('ban_pid <player ID>');
4774 Exit;
4775 end;
4777 a := StrToIntDef(P[1], 0);
4778 pl := g_Net_Client_ByPlayer(a);
4779 if (pl <> nil) and pl^.Used and (pl^.Peer <> nil) then
4780 begin
4781 s := g_Net_ClientName_ByID(pl^.ID);
4782 g_Net_BanHost(pl^.Peer^.address.host, False);
4783 enet_peer_disconnect(pl^.Peer, NET_DISC_TEMPBAN);
4784 g_Console_Add(Format(_lc[I_PLAYER_BAN], [s]));
4785 MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s);
4786 g_Net_Slist_ServerPlayerLeaves();
4787 end;
4788 end else
4789 g_Console_Add(_lc[I_MSG_SERVERONLY]);
4790 end
4791 else if cmd = 'permban' then
4792 begin
4793 if g_Game_IsServer and g_Game_IsNet then
4794 begin
4795 if Length(P) < 2 then
4796 begin
4797 g_Console_Add('permban <name>');
4798 Exit;
4799 end;
4800 if P[1] = '' then
4801 begin
4802 g_Console_Add('permban <name>');
4803 Exit;
4804 end;
4806 pl := g_Net_Client_ByName(P[1]);
4807 if (pl <> nil) then
4808 begin
4809 s := g_Net_ClientName_ByID(pl^.ID);
4810 g_Net_BanHost(pl^.Peer^.address.host);
4811 enet_peer_disconnect(pl^.Peer, NET_DISC_BAN);
4812 g_Net_SaveBanList();
4813 g_Console_Add(Format(_lc[I_PLAYER_BAN], [s]));
4814 MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s);
4815 g_Net_Slist_ServerPlayerLeaves();
4816 end else
4817 g_Console_Add(Format(_lc[I_NET_ERR_NAME404], [P[1]]));
4818 end else
4819 g_Console_Add(_lc[I_MSG_SERVERONLY]);
4820 end
4821 else if cmd = 'permban_id' then
4822 begin
4823 if g_Game_IsServer and g_Game_IsNet then
4824 begin
4825 if Length(P) < 2 then
4826 begin
4827 g_Console_Add('permban_id <client ID>');
4828 Exit;
4829 end;
4830 if P[1] = '' then
4831 begin
4832 g_Console_Add('permban_id <client ID>');
4833 Exit;
4834 end;
4836 a := StrToIntDef(P[1], 0);
4837 if (NetClients <> nil) and (a <= High(NetClients)) then
4838 if NetClients[a].Used and (NetClients[a].Peer <> nil) then
4839 begin
4840 s := g_Net_ClientName_ByID(NetClients[a].ID);
4841 g_Net_BanHost(NetClients[a].Peer^.address.host);
4842 enet_peer_disconnect(NetClients[a].Peer, NET_DISC_BAN);
4843 g_Net_SaveBanList();
4844 g_Console_Add(Format(_lc[I_PLAYER_BAN], [s]));
4845 MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s);
4846 g_Net_Slist_ServerPlayerLeaves();
4847 end;
4848 end else
4849 g_Console_Add(_lc[I_MSG_SERVERONLY]);
4850 end
4851 else if cmd = 'permban_pid' then
4852 begin
4853 if g_Game_IsServer and g_Game_IsNet then
4854 begin
4855 if Length(P) < 2 then
4856 begin
4857 g_Console_Add('permban_pid <player ID>');
4858 Exit;
4859 end;
4860 if P[1] = '' then
4861 begin
4862 g_Console_Add('permban_pid <player ID>');
4863 Exit;
4864 end;
4866 a := StrToIntDef(P[1], 0);
4867 pl := g_Net_Client_ByPlayer(a);
4868 if (pl <> nil) and pl^.Used and (pl^.Peer <> nil) then
4869 begin
4870 s := g_Net_ClientName_ByID(pl^.ID);
4871 g_Net_BanHost(pl^.Peer^.address.host);
4872 enet_peer_disconnect(pl^.Peer, NET_DISC_BAN);
4873 g_Net_SaveBanList();
4874 g_Console_Add(Format(_lc[I_PLAYER_BAN], [s]));
4875 MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s);
4876 g_Net_Slist_ServerPlayerLeaves();
4877 end;
4878 end else
4879 g_Console_Add(_lc[I_MSG_SERVERONLY]);
4880 end
4881 else if cmd = 'permban_ip' then
4882 begin
4883 if g_Game_IsServer and g_Game_IsNet then
4884 begin
4885 if Length(P) < 2 then
4886 begin
4887 g_Console_Add('permban_ip <IP address>');
4888 Exit;
4889 end;
4890 if P[1] = '' then
4891 begin
4892 g_Console_Add('permban_ip <IP address>');
4893 Exit;
4894 end;
4896 g_Net_BanHost(P[1]);
4897 g_Net_SaveBanList();
4898 g_Console_Add(Format(_lc[I_PLAYER_BAN], [P[1]]));
4899 end else
4900 g_Console_Add(_lc[I_MSG_SERVERONLY]);
4901 end
4902 else if cmd = 'unban' then
4903 begin
4904 if g_Game_IsServer and g_Game_IsNet then
4905 begin
4906 if Length(P) < 2 then
4907 begin
4908 g_Console_Add('unban <IP Address>');
4909 Exit;
4910 end;
4911 if P[1] = '' then
4912 begin
4913 g_Console_Add('unban <IP Address>');
4914 Exit;
4915 end;
4917 if g_Net_UnbanHost(P[1]) then
4918 begin
4919 g_Console_Add(Format(_lc[I_MSG_UNBAN_OK], [P[1]]));
4920 g_Net_SaveBanList();
4921 end else
4922 g_Console_Add(Format(_lc[I_MSG_UNBAN_FAIL], [P[1]]));
4923 end else
4924 g_Console_Add(_lc[I_MSG_SERVERONLY]);
4925 end
4926 else if cmd = 'clientlist' then
4927 begin
4928 if g_Game_IsServer and g_Game_IsNet then
4929 begin
4930 b := 0;
4931 if NetClients <> nil then
4932 for a := Low(NetClients) to High(NetClients) do
4933 if NetClients[a].Used and (NetClients[a].Peer <> nil) then
4934 begin
4935 plr := g_Player_Get(NetClients[a].Player);
4936 if plr = nil then continue;
4937 Inc(b);
4938 g_Console_Add(Format('#%2d: %-15s | %s', [a,
4939 IpToStr(NetClients[a].Peer^.address.host), plr.Name]));
4940 end;
4941 if b = 0 then
4942 g_Console_Add(_lc[I_MSG_NOCLIENTS]);
4943 end else
4944 g_Console_Add(_lc[I_MSG_SERVERONLY]);
4945 end
4946 else if cmd = 'connect' then
4947 begin
4948 if (NetMode = NET_NONE) then
4949 begin
4950 if Length(P) < 2 then
4951 begin
4952 g_Console_Add('connect <IP> [port] [password]');
4953 Exit;
4954 end;
4955 if P[1] = '' then
4956 begin
4957 g_Console_Add('connect <IP> [port] [password]');
4958 Exit;
4959 end;
4961 if Length(P) > 2 then
4962 prt := StrToIntDef(P[2], 25666)
4963 else
4964 prt := 25666;
4966 if Length(P) > 3 then
4967 pw := P[3]
4968 else
4969 pw := '';
4971 g_Game_StartClient(P[1], prt, pw);
4972 end;
4973 end
4974 else if cmd = 'disconnect' then
4975 begin
4976 if (NetMode = NET_CLIENT) then
4977 g_Net_Disconnect();
4978 end
4979 else if cmd = 'reconnect' then
4980 begin
4981 if (NetMode = NET_SERVER) then
4982 Exit;
4984 if (NetMode = NET_CLIENT) then
4985 begin
4986 g_Net_Disconnect();
4987 gExit := EXIT_SIMPLE;
4988 EndGame;
4989 end;
4991 //TODO: Use last successful password to reconnect, instead of ''
4992 g_Game_StartClient(NetClientIP, NetClientPort, '');
4993 end
4994 else if (cmd = 'addbot') or
4995 (cmd = 'bot_add') then
4996 begin
4997 if Length(P) > 2 then
4998 g_Bot_Add(TEAM_NONE, StrToIntDef(P[1], 2), StrToIntDef(P[2], 100))
4999 else if Length(P) > 1 then
5000 g_Bot_Add(TEAM_NONE, StrToIntDef(P[1], 2))
5001 else
5002 g_Bot_Add(TEAM_NONE, 2);
5003 end
5004 else if cmd = 'bot_addlist' then
5005 begin
5006 if Length(P) > 1 then
5007 begin
5008 if Length(P) = 2 then
5009 g_Bot_AddList(TEAM_NONE, P[1], StrToIntDef(P[1], -1))
5010 else if Length(P) = 3 then
5011 g_Bot_AddList(TEAM_NONE, P[1], StrToIntDef(P[1], -1), StrToIntDef(P[2], 100))
5012 else
5013 g_Bot_AddList(IfThen(P[2] = 'red', TEAM_RED, TEAM_BLUE), P[1], StrToIntDef(P[1], -1));
5014 end;
5015 end
5016 else if cmd = 'bot_removeall' then
5017 g_Bot_RemoveAll()
5018 else if cmd = 'chat' then
5019 begin
5020 if g_Game_IsNet then
5021 begin
5022 if Length(P) > 1 then
5023 begin
5024 for a := 1 to High(P) do
5025 chstr := chstr + P[a] + ' ';
5027 if Length(chstr) > 200 then SetLength(chstr, 200);
5029 if Length(chstr) < 1 then
5030 begin
5031 g_Console_Add('chat <text>');
5032 Exit;
5033 end;
5035 chstr := b_Text_Format(chstr);
5036 if g_Game_IsClient then
5037 MC_SEND_Chat(chstr, NET_CHAT_PLAYER)
5038 else
5039 MH_SEND_Chat(gPlayer1Settings.Name + ': ' + chstr, NET_CHAT_PLAYER);
5040 end
5041 else
5042 g_Console_Add('chat <text>');
5043 end else
5044 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
5045 end
5046 else if cmd = 'teamchat' then
5047 begin
5048 if g_Game_IsNet and (gGameSettings.GameMode in [GM_TDM, GM_CTF]) then
5049 begin
5050 if Length(P) > 1 then
5051 begin
5052 for a := 1 to High(P) do
5053 chstr := chstr + P[a] + ' ';
5055 if Length(chstr) > 200 then SetLength(chstr, 200);
5057 if Length(chstr) < 1 then
5058 begin
5059 g_Console_Add('teamchat <text>');
5060 Exit;
5061 end;
5063 chstr := b_Text_Format(chstr);
5064 if g_Game_IsClient then
5065 MC_SEND_Chat(chstr, NET_CHAT_TEAM)
5066 else
5067 MH_SEND_Chat(gPlayer1Settings.Name + ': ' + chstr, NET_CHAT_TEAM,
5068 gPlayer1Settings.Team);
5069 end
5070 else
5071 g_Console_Add('teamchat <text>');
5072 end else
5073 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
5074 end
5075 else if cmd = 'game' then
5076 begin
5077 if gGameSettings.GameType <> GT_NONE then
5078 begin
5079 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
5080 Exit;
5081 end;
5082 if Length(P) = 1 then
5083 begin
5084 g_Console_Add(cmd + ' <WAD> [MAP] [# players]');
5085 Exit;
5086 end;
5087 // game not started yet, load fist map from some wad
5088 found := false;
5089 s := addWadExtension(P[1]);
5090 found := e_FindResource(AllMapDirs, s);
5091 P[1] := s;
5092 if found then
5093 begin
5094 P[1] := ExpandFileName(P[1]);
5095 // if map not choosed then set first map
5096 if Length(P) < 3 then
5097 begin
5098 SetLength(P, 3);
5099 P[2] := g_Game_GetFirstMap(P[1]);
5100 end;
5102 s := P[1] + ':\' + UpperCase(P[2]);
5104 if g_Map_Exist(s) then
5105 begin
5106 // start game
5107 g_Game_Free();
5108 with gGameSettings do
5109 begin
5110 Options := gsGameFlags;
5111 GameMode := g_Game_TextToMode(gsGameMode);
5112 if gSwitchGameMode <> GM_NONE then
5113 GameMode := gSwitchGameMode;
5114 if GameMode = GM_NONE then GameMode := GM_DM;
5115 if GameMode = GM_SINGLE then GameMode := GM_COOP;
5116 b := 1;
5117 if Length(P) >= 4 then
5118 b := StrToIntDef(P[3], 1);
5119 g_Game_StartCustom(s, GameMode, TimeLimit,
5120 GoalLimit, MaxLives, Options, b);
5121 end;
5122 end
5123 else
5124 if P[2] = '' then
5125 g_Console_Add(Format(_lc[I_MSG_NO_MAPS], [P[1]]))
5126 else
5127 g_Console_Add(Format(_lc[I_MSG_NO_MAP_FALLBACK], [UpperCase(P[2]), P[1]]));
5128 end else
5129 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]));
5130 end
5131 else if cmd = 'host' then
5132 begin
5133 if gGameSettings.GameType <> GT_NONE then
5134 begin
5135 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
5136 Exit;
5137 end;
5138 if Length(P) < 4 then
5139 begin
5140 g_Console_Add(cmd + ' <listen IP> <port> <WAD> [MAP] [# players]');
5141 Exit;
5142 end;
5143 if not StrToIp(P[1], listen) then
5144 Exit;
5145 prt := StrToIntDef(P[2], 25666);
5147 s := addWadExtension(P[3]);
5148 found := e_FindResource(AllMapDirs, s);
5149 P[3] := s;
5150 if found then
5151 begin
5152 // get first map in wad, if not specified
5153 if Length(P) < 5 then
5154 begin
5155 SetLength(P, 5);
5156 P[4] := g_Game_GetFirstMap(P[1]);
5157 end;
5158 s := P[3] + ':\' + UpperCase(P[4]);
5159 if g_Map_Exist(s) then
5160 begin
5161 // start game
5162 g_Game_Free();
5163 with gGameSettings do
5164 begin
5165 Options := gsGameFlags;
5166 GameMode := g_Game_TextToMode(gsGameMode);
5167 if gSwitchGameMode <> GM_NONE then GameMode := gSwitchGameMode;
5168 if GameMode = GM_NONE then GameMode := GM_DM;
5169 if GameMode = GM_SINGLE then GameMode := GM_COOP;
5170 b := 0;
5171 if Length(P) >= 6 then
5172 b := StrToIntDef(P[5], 0);
5173 g_Game_StartServer(s, GameMode, TimeLimit, GoalLimit, MaxLives, Options, b, listen, prt)
5174 end
5175 end
5176 else
5177 begin
5178 if P[4] = '' then
5179 g_Console_Add(Format(_lc[I_MSG_NO_MAPS], [P[3]]))
5180 else
5181 g_Console_Add(Format(_lc[I_MSG_NO_MAP_FALLBACK], [UpperCase(P[4]), P[3]]))
5182 end
5183 end
5184 else
5185 begin
5186 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[3]]))
5187 end
5188 end
5189 else if cmd = 'map' then
5190 begin
5191 if Length(P) = 1 then
5192 begin
5193 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
5194 begin
5195 g_Console_Add(cmd + ' <MAP>');
5196 g_Console_Add(cmd + ' <WAD> [MAP]')
5197 end
5198 else
5199 begin
5200 g_Console_Add(_lc[I_MSG_GM_UNAVAIL])
5201 end
5202 end
5203 else
5204 begin
5205 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
5206 begin
5207 if Length(P) < 3 then
5208 begin
5209 // first param is map or wad
5210 s := UpperCase(P[1]);
5211 if g_Map_Exist(gGameSettings.WAD + ':\' + s) then
5212 begin
5213 gExitByTrigger := False;
5214 if gGameOn then
5215 begin
5216 // already in game, finish current map
5217 gNextMap := s;
5218 gExit := EXIT_ENDLEVELCUSTOM;
5219 end
5220 else
5221 begin
5222 // intermission, so change map immediately
5223 g_Game_ChangeMap(s)
5224 end
5225 end
5226 else
5227 begin
5228 s := P[1];
5229 found := e_FindResource(AllMapDirs, s);
5230 P[1] := s;
5231 g_Console_Add(Format(_lc[I_MSG_NO_MAP_FALLBACK], [s, 'WAD ' + P[1]]));
5232 if found then
5233 begin
5234 // no such map, found wad
5235 pw := P[1];
5236 SetLength(P, 3);
5237 P[1] := ExpandFileName(pw);
5238 P[2] := g_Game_GetFirstMap(P[1]);
5239 s := P[1] + ':\' + P[2];
5240 if g_Map_Exist(s) then
5241 begin
5242 gExitByTrigger := False;
5243 if gGameOn then
5244 begin
5245 // already in game, finish current map
5246 gNextMap := s;
5247 gExit := EXIT_ENDLEVELCUSTOM
5248 end
5249 else
5250 begin
5251 // intermission, so change map immediately
5252 g_Game_ChangeMap(s)
5253 end
5254 end
5255 else
5256 begin
5257 if P[2] = '' then
5258 g_Console_Add(Format(_lc[I_MSG_NO_MAPS], [P[1]]))
5259 else
5260 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [P[2]]))
5261 end
5262 end
5263 else
5264 begin
5265 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]))
5266 end
5267 end;
5268 end
5269 else
5270 begin
5271 s := addWadExtension(P[1]);
5272 found := e_FindResource(AllMapDirs, s);
5273 P[1] := s;
5274 if found then
5275 begin
5276 P[2] := UpperCase(P[2]);
5277 s := P[1] + ':\' + P[2];
5278 if g_Map_Exist(s) then
5279 begin
5280 gExitByTrigger := False;
5281 if gGameOn then
5282 begin
5283 gNextMap := s;
5284 gExit := EXIT_ENDLEVELCUSTOM
5285 end
5286 else
5287 begin
5288 g_Game_ChangeMap(s)
5289 end
5290 end
5291 else
5292 begin
5293 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [P[2]]))
5294 end
5295 end
5296 else
5297 begin
5298 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]))
5299 end
5300 end
5301 end
5302 else
5303 begin
5304 g_Console_Add(_lc[I_MSG_GM_UNAVAIL])
5305 end
5306 end
5307 end
5308 else if cmd = 'nextmap' then
5309 begin
5310 if not(gGameOn or (gState = STATE_INTERCUSTOM)) then
5311 begin
5312 g_Console_Add(_lc[I_MSG_NOT_GAME])
5313 end
5314 else
5315 begin
5316 nm := True;
5317 if Length(P) = 1 then
5318 begin
5319 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
5320 begin
5321 g_Console_Add(cmd + ' <MAP>');
5322 g_Console_Add(cmd + ' <WAD> [MAP]');
5323 end
5324 else
5325 begin
5326 nm := False;
5327 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
5328 end;
5329 end
5330 else
5331 begin
5332 nm := False;
5333 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
5334 begin
5335 if Length(P) < 3 then
5336 begin
5337 // first param is map or wad
5338 s := UpperCase(P[1]);
5339 if g_Map_Exist(gGameSettings.WAD + ':\' + s) then
5340 begin
5341 // map founded
5342 gExitByTrigger := False;
5343 gNextMap := s;
5344 nm := True;
5345 end
5346 else
5347 begin
5348 // no such map, found wad
5349 pw := addWadExtension(P[1]);
5350 found := e_FindResource(MapDirs, pw);
5351 if not found then
5352 found := e_FindResource(WadDirs, pw);
5353 P[1] := pw;
5354 g_Console_Add(Format(_lc[I_MSG_NO_MAP_FALLBACK], [s, P[1]]));
5355 if found then
5356 begin
5357 // map not specified, select first map
5358 SetLength(P, 3);
5359 P[2] := g_Game_GetFirstMap(P[1]);
5360 s := P[1] + ':\' + P[2];
5361 if g_Map_Exist(s) then
5362 begin
5363 gExitByTrigger := False;
5364 gNextMap := s;
5365 nm := True
5366 end
5367 else
5368 begin
5369 if P[2] = '' then
5370 g_Console_Add(Format(_lc[I_MSG_NO_MAPS], [P[1]]))
5371 else
5372 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [P[2]]))
5373 end
5374 end
5375 else
5376 begin
5377 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]))
5378 end
5379 end
5380 end
5381 else
5382 begin
5383 // specified two params wad + map
5384 pw := addWadExtension(P[1]);
5385 found := e_FindResource(MapDirs, pw);
5386 if not found then
5387 found := e_FindResource(MapDirs, pw);
5388 P[1] := pw;
5389 if found then
5390 begin
5391 P[2] := UpperCase(P[2]);
5392 s := P[1] + ':\' + P[2];
5393 if g_Map_Exist(s) then
5394 begin
5395 gExitByTrigger := False;
5396 gNextMap := s;
5397 nm := True
5398 end
5399 else
5400 begin
5401 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [P[2]]))
5402 end
5403 end
5404 else
5405 begin
5406 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]))
5407 end
5408 end
5409 end
5410 else
5411 begin
5412 g_Console_Add(_lc[I_MSG_GM_UNAVAIL])
5413 end
5414 end;
5415 if nm then
5416 begin
5417 if gNextMap = '' then
5418 g_Console_Add(_lc[I_MSG_NEXTMAP_UNSET])
5419 else
5420 g_Console_Add(Format(_lc[I_MSG_NEXTMAP_SET], [gNextMap]))
5421 end
5422 end
5423 end
5424 else if (cmd = 'endmap') or (cmd = 'goodbye') then
5425 begin
5426 if not gGameOn then
5427 begin
5428 g_Console_Add(_lc[I_MSG_NOT_GAME])
5429 end
5430 else
5431 begin
5432 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
5433 begin
5434 gExitByTrigger := False;
5435 // next map not specified, try to find trigger EXIT
5436 if (gNextMap = '') and (gTriggers <> nil) then
5437 begin
5438 for a := 0 to High(gTriggers) do
5439 begin
5440 if gTriggers[a].TriggerType = TRIGGER_EXIT then
5441 begin
5442 gExitByTrigger := True;
5443 //gNextMap := gTriggers[a].Data.MapName;
5444 gNextMap := gTriggers[a].tgcMap;
5445 Break
5446 end
5447 end
5448 end;
5449 if gNextMap = '' then
5450 gNextMap := g_Game_GetNextMap();
5451 if not isWadPath(gNextMap) then
5452 s := gGameSettings.WAD + ':\' + gNextMap
5453 else
5454 s := gNextMap;
5455 if g_Map_Exist(s) then
5456 gExit := EXIT_ENDLEVELCUSTOM
5457 else
5458 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [gNextMap]))
5459 end
5460 else
5461 begin
5462 g_Console_Add(_lc[I_MSG_GM_UNAVAIL])
5463 end
5464 end
5465 end
5466 else if (cmd = 'event') then
5467 begin
5468 if (Length(P) <= 1) then
5469 begin
5470 for a := 0 to High(gEvents) do
5471 if gEvents[a].Command = '' then
5472 g_Console_Add(gEvents[a].Name + ' <none>')
5473 else
5474 g_Console_Add(gEvents[a].Name + ' "' + gEvents[a].Command + '"');
5475 Exit;
5476 end;
5477 if (Length(P) = 2) then
5478 begin
5479 for a := 0 to High(gEvents) do
5480 if gEvents[a].Name = P[1] then
5481 if gEvents[a].Command = '' then
5482 g_Console_Add(gEvents[a].Name + ' <none>')
5483 else
5484 g_Console_Add(gEvents[a].Name + ' "' + gEvents[a].Command + '"');
5485 Exit;
5486 end;
5487 for a := 0 to High(gEvents) do
5488 if gEvents[a].Name = P[1] then
5489 begin
5490 gEvents[a].Command := '';
5491 for b := 2 to High(P) do
5492 if Pos(' ', P[b]) = 0 then
5493 gEvents[a].Command := gEvents[a].Command + ' ' + P[b]
5494 else
5495 gEvents[a].Command := gEvents[a].Command + ' "' + P[b] + '"';
5496 gEvents[a].Command := Trim(gEvents[a].Command);
5497 Exit;
5498 end;
5499 end
5500 else if cmd = 'suicide' then
5501 begin
5502 if gGameOn then
5503 begin
5504 if g_Game_IsClient then
5505 MC_SEND_CheatRequest(NET_CHEAT_SUICIDE)
5506 else
5507 begin
5508 if gPlayer1 <> nil then
5509 gPlayer1.Damage(SUICIDE_DAMAGE, gPlayer1.UID, 0, 0, HIT_SELF);
5510 if gPlayer2 <> nil then
5511 gPlayer2.Damage(SUICIDE_DAMAGE, gPlayer2.UID, 0, 0, HIT_SELF);
5512 end;
5513 end;
5514 end
5515 else if cmd = 'screenshot' then
5516 begin
5517 {$IFNDEF HEADLESS}
5518 g_TakeScreenShot()
5519 {$ENDIF}
5520 end
5521 else if cmd = 'weapon' then
5522 begin
5523 if Length(p) = 2 then
5524 begin
5525 a := WP_FIRST + StrToInt(p[1]) - 1;
5526 if (a >= WP_FIRST) and (a <= WP_LAST) then
5527 gSelectWeapon[0, a] := True
5528 end
5529 end
5530 else if (cmd = 'p1_weapon') or (cmd = 'p2_weapon') then
5531 begin
5532 if Length(p) = 2 then
5533 begin
5534 a := WP_FIRST + StrToInt(p[1]) - 1;
5535 b := ord(cmd[2]) - ord('1');
5536 if (a >= WP_FIRST) and (a <= WP_LAST) then
5537 gSelectWeapon[b, a] := True
5538 end
5539 end
5540 // Команды Своей игры:
5541 else if gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT] then
5542 begin
5543 if cmd = 'bot_addred' then
5544 begin
5545 if Length(P) > 1 then
5546 g_Bot_Add(TEAM_RED, StrToIntDef(P[1], 2))
5547 else
5548 g_Bot_Add(TEAM_RED, 2);
5549 end
5550 else if cmd = 'bot_addblue' then
5551 begin
5552 if Length(P) > 1 then
5553 g_Bot_Add(TEAM_BLUE, StrToIntDef(P[1], 2))
5554 else
5555 g_Bot_Add(TEAM_BLUE, 2);
5556 end
5557 else if cmd = 'spectate' then
5558 begin
5559 if not gGameOn then
5560 Exit;
5561 g_Game_Spectate();
5562 end
5563 else if cmd = 'say' then
5564 begin
5565 if g_Game_IsServer and g_Game_IsNet then
5566 begin
5567 if Length(P) > 1 then
5568 begin
5569 chstr := '';
5570 for a := 1 to High(P) do
5571 chstr := chstr + P[a] + ' ';
5573 if Length(chstr) > 200 then SetLength(chstr, 200);
5575 if Length(chstr) < 1 then
5576 begin
5577 g_Console_Add('say <text>');
5578 Exit;
5579 end;
5581 chstr := b_Text_Format(chstr);
5582 MH_SEND_Chat(chstr, NET_CHAT_PLAYER);
5583 end
5584 else g_Console_Add('say <text>');
5585 end else
5586 g_Console_Add(_lc[I_MSG_SERVERONLY]);
5587 end
5588 else if cmd = 'tell' then
5589 begin
5590 if g_Game_IsServer and g_Game_IsNet then
5591 begin
5592 if (Length(P) > 2) and (P[1] <> '') then
5593 begin
5594 chstr := '';
5595 for a := 2 to High(P) do
5596 chstr := chstr + P[a] + ' ';
5598 if Length(chstr) > 200 then SetLength(chstr, 200);
5600 if Length(chstr) < 1 then
5601 begin
5602 g_Console_Add('tell <playername> <text>');
5603 Exit;
5604 end;
5606 pl := g_Net_Client_ByName(P[1]);
5607 if pl <> nil then
5608 MH_SEND_Chat(b_Text_Format(chstr), NET_CHAT_PLAYER, pl^.ID)
5609 else
5610 g_Console_Add(Format(_lc[I_NET_ERR_NAME404], [P[1]]));
5611 end
5612 else g_Console_Add('tell <playername> <text>');
5613 end else
5614 g_Console_Add(_lc[I_MSG_SERVERONLY]);
5615 end
5616 else if cmd = 'centerprint' then
5617 begin
5618 if (Length(P) > 2) and (P[1] <> '') then
5619 begin
5620 chstr := '';
5621 for a := 2 to High(P) do
5622 chstr := chstr + P[a] + ' ';
5624 if Length(chstr) > 200 then SetLength(chstr, 200);
5626 if Length(chstr) < 1 then
5627 begin
5628 g_Console_Add('centerprint <timeout> <text>');
5629 Exit;
5630 end;
5632 a := StrToIntDef(P[1], 100);
5633 chstr := b_Text_Format(chstr);
5634 g_Game_Message(chstr, a);
5635 if g_Game_IsNet and g_Game_IsServer then
5636 MH_SEND_GameEvent(NET_EV_BIGTEXT, a, chstr);
5637 end
5638 else g_Console_Add('centerprint <timeout> <text>');
5639 end
5640 else if (cmd = 'overtime') and not g_Game_IsClient then
5641 begin
5642 if (Length(P) = 1) or (StrToIntDef(P[1], -1) <= 0) then
5643 Exit;
5644 // Дополнительное время:
5645 gGameSettings.TimeLimit := (gTime - gGameStartTime) div 1000 + Word(StrToIntDef(P[1], 0));
5647 g_Console_Add(Format(_lc[I_MSG_TIME_LIMIT],
5648 [gGameSettings.TimeLimit div 3600,
5649 (gGameSettings.TimeLimit div 60) mod 60,
5650 gGameSettings.TimeLimit mod 60]));
5651 if g_Game_IsNet then MH_SEND_GameSettings;
5652 end
5653 else if (cmd = 'rcon_password') and g_Game_IsClient then
5654 begin
5655 if (Length(P) <= 1) then
5656 g_Console_Add('rcon_password <password>')
5657 else
5658 MC_SEND_RCONPassword(P[1]);
5659 end
5660 else if cmd = 'rcon' then
5661 begin
5662 if g_Game_IsClient then
5663 begin
5664 if Length(P) > 1 then
5665 begin
5666 chstr := '';
5667 for a := 1 to High(P) do
5668 chstr := chstr + P[a] + ' ';
5670 if Length(chstr) > 200 then SetLength(chstr, 200);
5672 if Length(chstr) < 1 then
5673 begin
5674 g_Console_Add('rcon <command>');
5675 Exit;
5676 end;
5678 MC_SEND_RCONCommand(chstr);
5679 end
5680 else g_Console_Add('rcon <command>');
5681 end;
5682 end
5683 else if cmd = 'ready' then
5684 begin
5685 if g_Game_IsServer and (gLMSRespawn = LMS_RESPAWN_WARMUP) then
5686 gLMSRespawnTime := gTime + 100;
5687 end
5688 else if (cmd = 'callvote') and g_Game_IsNet then
5689 begin
5690 if Length(P) > 1 then
5691 begin
5692 chstr := '';
5693 for a := 1 to High(P) do begin
5694 if a > 1 then chstr := chstr + ' ';
5695 chstr := chstr + P[a];
5696 end;
5698 if Length(chstr) > 200 then SetLength(chstr, 200);
5700 if Length(chstr) < 1 then
5701 begin
5702 g_Console_Add('callvote <command>');
5703 Exit;
5704 end;
5706 if g_Game_IsClient then
5707 MC_SEND_Vote(True, chstr)
5708 else
5709 g_Game_StartVote(chstr, gPlayer1Settings.Name);
5710 g_Console_Process('vote', True);
5711 end
5712 else
5713 g_Console_Add('callvote <command>');
5714 end
5715 else if (cmd = 'vote') and g_Game_IsNet then
5716 begin
5717 if g_Game_IsClient then
5718 MC_SEND_Vote(False)
5719 else if gVoteInProgress then
5720 begin
5721 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
5722 a := Floor((NetClientCount+1)/2.0) + 1
5723 else
5724 a := Floor(NetClientCount/2.0) + 1;
5725 if gVoted then
5726 begin
5727 Dec(gVoteCount);
5728 gVoted := False;
5729 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_REVOKED], [gPlayer1Settings.Name, gVoteCount, a]), True);
5730 MH_SEND_VoteEvent(NET_VE_REVOKE, gPlayer1Settings.Name, 'a', gVoteCount, a);
5731 end
5732 else
5733 begin
5734 Inc(gVoteCount);
5735 gVoted := True;
5736 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_VOTE], [gPlayer1Settings.Name, gVoteCount, a]), True);
5737 MH_SEND_VoteEvent(NET_VE_VOTE, gPlayer1Settings.Name, 'a', gVoteCount, a);
5738 g_Game_CheckVote;
5739 end;
5740 end;
5741 end
5742 end;
5743 end;
5745 procedure SystemCommands(P: SSArray);
5746 var
5747 cmd: string;
5748 begin
5749 cmd := LowerCase(P[0]);
5750 case cmd of
5751 'exit', 'quit':
5752 begin
5753 g_Game_Free();
5754 g_Game_Quit();
5755 end;
5756 {$IFNDEF HEADLESS}
5757 'r_reset':
5758 r_Render_Apply;
5759 {$ENDIF}
5760 'r_maxfps':
5761 begin
5762 if Length(p) = 2 then
5763 begin
5764 gMaxFPS := StrToIntDef(p[1], gMaxFPS);
5765 if gMaxFPS > 0 then
5766 gFrameTime := 1000 div gMaxFPS
5767 else
5768 gFrameTime := 0;
5769 end;
5770 e_LogWritefln('r_maxfps %d', [gMaxFPS]);
5771 end;
5772 'g_language':
5773 begin
5774 if Length(p) = 2 then
5775 begin
5776 gAskLanguage := true;
5777 gLanguage := LANGUAGE_ENGLISH;
5778 case LowerCase(p[1]) of
5779 'english':
5780 begin
5781 gAskLanguage := false;
5782 gLanguage := LANGUAGE_ENGLISH;
5783 end;
5784 'russian':
5785 begin
5786 gAskLanguage := false;
5787 gLanguage := LANGUAGE_RUSSIAN;
5788 end;
5789 'ask':
5790 begin
5791 gAskLanguage := true;
5792 gLanguage := LANGUAGE_ENGLISH;
5793 end;
5794 end;
5795 g_Language_Set(gLanguage);
5796 end
5797 else
5798 begin
5799 e_LogWritefln('usage: %s <English|Russian|Ask>', [cmd]);
5800 end
5801 end;
5802 end;
5803 end;
5805 {$IFNDEF HEADLESS}
5806 procedure g_TakeScreenShot(Filename: string = '');
5807 var t: TDateTime; dir, date, name: String;
5808 begin
5809 if e_NoGraphics then
5810 Exit;
5812 dir := e_GetWriteableDir(ScreenshotDirs);
5813 if Filename = '' then
5814 begin
5815 t := Now;
5816 DateTimeToString(date, 'yyyy-mm-dd-hh-nn-ss', t);
5817 Filename := 'screenshot-' + date;
5818 end;
5820 name := e_CatPath(dir, Filename + '.png');
5821 if r_Render_WriteScreenShot(name) then
5822 g_Console_Add(Format(_lc[I_CONSOLE_SCREENSHOT], [name]))
5823 else
5824 g_Console_Add(Format(_lc[I_CONSOLE_ERROR_WRITE], [name]));
5825 end;
5826 {$ENDIF}
5828 {$IFDEF ENABLE_MENU}
5829 procedure g_Game_InGameMenu(Show: Boolean);
5830 begin
5831 if (g_ActiveWindow = nil) and Show then
5832 begin
5833 if gGameSettings.GameType = GT_SINGLE then
5834 g_GUI_ShowWindow('GameSingleMenu')
5835 else
5836 begin
5837 if g_Game_IsClient then
5838 g_GUI_ShowWindow('GameClientMenu')
5839 else
5840 if g_Game_IsNet then
5841 g_GUI_ShowWindow('GameServerMenu')
5842 else
5843 g_GUI_ShowWindow('GameCustomMenu');
5844 end;
5845 g_Sound_PlayEx('MENU_OPEN');
5847 // Пауза при меню только в одиночной игре:
5848 if (not g_Game_IsNet) then
5849 g_Game_Pause(True);
5850 end
5851 else
5852 if (g_ActiveWindow <> nil) and (not Show) then
5853 begin
5854 // Пауза при меню только в одиночной игре:
5855 if (not g_Game_IsNet) then
5856 g_Game_Pause(False);
5857 end;
5858 end;
5859 {$ENDIF}
5861 procedure g_Game_Pause (Enable: Boolean);
5862 var
5863 oldPause: Boolean;
5864 begin
5865 if not gGameOn then exit;
5867 if not (gGameSettings.GameType in [GT_SINGLE, GT_CUSTOM]) then exit;
5869 oldPause := gPause;
5870 gPauseMain := Enable;
5872 if (gPause <> oldPause) then g_Game_PauseAllSounds(gPause);
5873 end;
5875 procedure g_Game_HolmesPause (Enable: Boolean);
5876 var
5877 oldPause: Boolean;
5878 begin
5879 if not gGameOn then exit;
5880 if not (gGameSettings.GameType in [GT_SINGLE, GT_CUSTOM]) then exit;
5882 oldPause := gPause;
5883 gPauseHolmes := Enable;
5885 if (gPause <> oldPause) then g_Game_PauseAllSounds(gPause);
5886 end;
5888 procedure g_Game_PauseAllSounds(Enable: Boolean);
5889 var
5890 i: Integer;
5891 begin
5892 // Триггеры:
5893 if gTriggers <> nil then
5894 for i := 0 to High(gTriggers) do
5895 with gTriggers[i] do
5896 if (TriggerType = TRIGGER_SOUND) and
5897 (Sound <> nil) and
5898 Sound.IsPlaying() then
5899 begin
5900 Sound.Pause(Enable);
5901 end;
5903 // Звуки игроков:
5904 if gPlayers <> nil then
5905 for i := 0 to High(gPlayers) do
5906 if gPlayers[i] <> nil then
5907 gPlayers[i].PauseSounds(Enable);
5909 // Музыка:
5910 if gMusic <> nil then
5911 gMusic.Pause(Enable);
5912 end;
5914 procedure g_Game_StopAllSounds(all: Boolean);
5915 var
5916 i: Integer;
5917 begin
5918 if gTriggers <> nil then
5919 for i := 0 to High(gTriggers) do
5920 with gTriggers[i] do
5921 if (TriggerType = TRIGGER_SOUND) and
5922 (Sound <> nil) then
5923 Sound.Stop();
5925 if gMusic <> nil then
5926 gMusic.Stop();
5928 if all then
5929 e_StopChannels();
5930 end;
5932 procedure g_Game_UpdateTriggerSounds;
5933 var i: Integer;
5934 begin
5935 if gTriggers <> nil then
5936 for i := 0 to High(gTriggers) do
5937 with gTriggers[i] do
5938 if (TriggerType = TRIGGER_SOUND) and (Sound <> nil) and tgcLocal and Sound.IsPlaying() then
5939 Sound.SetCoordsRect(X, Y, Width, Height, tgcVolume / 255.0)
5940 end;
5942 function g_Game_IsWatchedPlayer(UID: Word): Boolean;
5943 begin
5944 Result := False;
5945 if (gPlayer1 <> nil) and (gPlayer1.UID = UID) then
5946 begin
5947 Result := True;
5948 Exit;
5949 end;
5950 if (gPlayer2 <> nil) and (gPlayer2.UID = UID) then
5951 begin
5952 Result := True;
5953 Exit;
5954 end;
5955 if gSpectMode <> SPECT_PLAYERS then
5956 Exit;
5957 if gSpectPID1 = UID then
5958 begin
5959 Result := True;
5960 Exit;
5961 end;
5962 if gSpectViewTwo and (gSpectPID2 = UID) then
5963 begin
5964 Result := True;
5965 Exit;
5966 end;
5967 end;
5969 function g_Game_IsWatchedTeam(Team: Byte): Boolean;
5970 var
5971 Pl: TPlayer;
5972 begin
5973 Result := False;
5974 if (gPlayer1 <> nil) and (gPlayer1.Team = Team) then
5975 begin
5976 Result := True;
5977 Exit;
5978 end;
5979 if (gPlayer2 <> nil) and (gPlayer2.Team = Team) then
5980 begin
5981 Result := True;
5982 Exit;
5983 end;
5984 if gSpectMode <> SPECT_PLAYERS then
5985 Exit;
5986 Pl := g_Player_Get(gSpectPID1);
5987 if (Pl <> nil) and (Pl.Team = Team) then
5988 begin
5989 Result := True;
5990 Exit;
5991 end;
5992 if gSpectViewTwo then
5993 begin
5994 Pl := g_Player_Get(gSpectPID2);
5995 if (Pl <> nil) and (Pl.Team = Team) then
5996 begin
5997 Result := True;
5998 Exit;
5999 end;
6000 end;
6001 end;
6003 procedure g_Game_Message (Msg: string; Time: Word);
6004 begin
6005 MessageText := Msg;
6006 MessageTime := Time;
6007 end;
6009 procedure g_Game_ChatSound(Text: String; Taunt: Boolean = True);
6010 const
6011 punct: Array[0..13] of String =
6012 ('.', ',', ':', ';', '!', '?', '(', ')', '''', '"', '/', '\', '*', '^');
6013 var
6014 i, j: Integer;
6015 ok: Boolean;
6016 fpText: String;
6018 function IsPunctuation(S: String): Boolean;
6019 var
6020 i: Integer;
6021 begin
6022 Result := False;
6023 if Length(S) <> 1 then
6024 Exit;
6025 for i := Low(punct) to High(punct) do
6026 if S = punct[i] then
6027 begin
6028 Result := True;
6029 break;
6030 end;
6031 end;
6032 function FilterPunctuation(S: String): String;
6033 var
6034 i: Integer;
6035 begin
6036 for i := Low(punct) to High(punct) do
6037 S := StringReplace(S, punct[i], ' ', [rfReplaceAll]);
6038 Result := S;
6039 end;
6040 begin
6041 ok := False;
6043 if gUseChatSounds and Taunt and (gChatSounds <> nil) and (Pos(': ', Text) > 0) then
6044 begin
6045 // remove player name
6046 Delete(Text, 1, Pos(': ', Text) + 2 - 1);
6047 // for FullWord check
6048 Text := toLowerCase1251(' ' + Text + ' ');
6049 fpText := FilterPunctuation(Text);
6051 for i := 0 to Length(gChatSounds) - 1 do
6052 begin
6053 ok := True;
6054 for j := 0 to Length(gChatSounds[i].Tags) - 1 do
6055 begin
6056 if gChatSounds[i].FullWord and (not IsPunctuation(gChatSounds[i].Tags[j])) then
6057 ok := Pos(' ' + gChatSounds[i].Tags[j] + ' ', fpText) > 0
6058 else
6059 ok := Pos(gChatSounds[i].Tags[j], Text) > 0;
6060 if not ok then
6061 break;
6062 end;
6063 if ok then
6064 begin
6065 gChatSounds[i].Sound.Play();
6066 break;
6067 end;
6068 end;
6069 end;
6070 if not ok then
6071 g_Sound_PlayEx('SOUND_GAME_RADIO');
6072 end;
6074 procedure g_Game_Announce_GoodShot(SpawnerUID: Word);
6075 var
6076 a: Integer;
6077 begin
6078 case gAnnouncer of
6079 ANNOUNCE_NONE:
6080 Exit;
6081 ANNOUNCE_ME,
6082 ANNOUNCE_MEPLUS:
6083 if not g_Game_IsWatchedPlayer(SpawnerUID) then
6084 Exit;
6085 end;
6086 for a := 0 to 3 do
6087 if goodsnd[a].IsPlaying() then
6088 Exit;
6090 goodsnd[Random(4)].Play();
6091 end;
6093 procedure g_Game_Announce_KillCombo(Param: Integer);
6094 var
6095 UID: Word;
6096 c, n: Byte;
6097 Pl: TPlayer;
6098 Name: String;
6099 begin
6100 UID := Param and $FFFF;
6101 c := Param shr 16;
6102 if c < 2 then
6103 Exit;
6105 Pl := g_Player_Get(UID);
6106 if Pl = nil then
6107 Name := '?'
6108 else
6109 Name := Pl.Name;
6111 case c of
6112 2: begin
6113 n := 0;
6114 g_Console_Add(Format(_lc[I_PLAYER_KILL_2X], [Name]), True);
6115 end;
6116 3: begin
6117 n := 1;
6118 g_Console_Add(Format(_lc[I_PLAYER_KILL_3X], [Name]), True);
6119 end;
6120 4: begin
6121 n := 2;
6122 g_Console_Add(Format(_lc[I_PLAYER_KILL_4X], [Name]), True);
6123 end;
6124 else begin
6125 n := 3;
6126 g_Console_Add(Format(_lc[I_PLAYER_KILL_MX], [Name]), True);
6127 end;
6128 end;
6130 case gAnnouncer of
6131 ANNOUNCE_NONE:
6132 Exit;
6133 ANNOUNCE_ME:
6134 if not g_Game_IsWatchedPlayer(UID) then
6135 Exit;
6136 ANNOUNCE_MEPLUS:
6137 if (not g_Game_IsWatchedPlayer(UID)) and (c < 4) then
6138 Exit;
6139 end;
6141 if killsnd[n].IsPlaying() then
6142 killsnd[n].Stop();
6143 killsnd[n].Play();
6144 end;
6146 procedure g_Game_Announce_BodyKill(SpawnerUID: Word);
6147 var
6148 a: Integer;
6149 begin
6150 case gAnnouncer of
6151 ANNOUNCE_NONE:
6152 Exit;
6153 ANNOUNCE_ME:
6154 if not g_Game_IsWatchedPlayer(SpawnerUID) then
6155 Exit;
6156 end;
6157 for a := 0 to 2 do
6158 if hahasnd[a].IsPlaying() then
6159 Exit;
6161 hahasnd[Random(3)].Play();
6162 end;
6164 procedure g_Game_StartVote(Command, Initiator: string);
6165 var
6166 Need: Integer;
6167 begin
6168 if not gVotesEnabled then Exit;
6169 if gGameSettings.GameType <> GT_SERVER then Exit;
6170 if gVoteInProgress or gVotePassed then
6171 begin
6172 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_INPROGRESS], [gVoteCommand]), True);
6173 MH_SEND_VoteEvent(NET_VE_INPROGRESS, gVoteCommand);
6174 Exit;
6175 end;
6176 gVoteInProgress := True;
6177 gVotePassed := False;
6178 gVoteTimer := gTime + gVoteTimeout * 1000;
6179 gVoteCount := 0;
6180 gVoted := False;
6181 gVoteCommand := Command;
6183 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
6184 Need := Floor((NetClientCount+1)/2.0)+1
6185 else
6186 Need := Floor(NetClientCount/2.0)+1;
6187 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_STARTED], [Initiator, Command, Need]), True);
6188 MH_SEND_VoteEvent(NET_VE_STARTED, Initiator, Command, Need);
6189 end;
6191 procedure g_Game_CheckVote;
6192 var
6193 I, Need: Integer;
6194 begin
6195 if gGameSettings.GameType <> GT_SERVER then Exit;
6196 if not gVoteInProgress then Exit;
6198 if (gTime >= gVoteTimer) then
6199 begin
6200 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
6201 Need := Floor((NetClientCount+1)/2.0) + 1
6202 else
6203 Need := Floor(NetClientCount/2.0) + 1;
6204 if gVoteCount >= Need then
6205 begin
6206 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_PASSED], [gVoteCommand]), True);
6207 MH_SEND_VoteEvent(NET_VE_PASSED, gVoteCommand);
6208 gVotePassed := True;
6209 gVoteCmdTimer := gTime + 5000;
6210 end
6211 else
6212 begin
6213 g_Console_Add(_lc[I_MESSAGE_VOTE_FAILED], True);
6214 MH_SEND_VoteEvent(NET_VE_FAILED);
6215 end;
6216 if NetClients <> nil then
6217 for I := Low(NetClients) to High(NetClients) do
6218 if NetClients[i].Used then
6219 NetClients[i].Voted := False;
6220 gVoteInProgress := False;
6221 gVoted := False;
6222 gVoteCount := 0;
6223 end
6224 else
6225 begin
6226 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
6227 Need := Floor((NetClientCount+1)/2.0) + 1
6228 else
6229 Need := Floor(NetClientCount/2.0) + 1;
6230 if gVoteCount >= Need then
6231 begin
6232 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_PASSED], [gVoteCommand]), True);
6233 MH_SEND_VoteEvent(NET_VE_PASSED, gVoteCommand);
6234 gVoteInProgress := False;
6235 gVotePassed := True;
6236 gVoteCmdTimer := gTime + 5000;
6237 gVoted := False;
6238 gVoteCount := 0;
6239 if NetClients <> nil then
6240 for I := Low(NetClients) to High(NetClients) do
6241 if NetClients[i].Used then
6242 NetClients[i].Voted := False;
6243 end;
6244 end;
6245 end;
6247 procedure g_Game_LoadMapList(FileName: string);
6248 var
6249 ListFile: TextFile;
6250 s: string;
6251 begin
6252 MapList := nil;
6253 MapIndex := -1;
6255 if not FileExists(FileName) then Exit;
6257 AssignFile(ListFile, FileName);
6258 Reset(ListFile);
6259 while not EOF(ListFile) do
6260 begin
6261 ReadLn(ListFile, s);
6263 s := Trim(s);
6264 if s = '' then Continue;
6266 SetLength(MapList, Length(MapList)+1);
6267 MapList[High(MapList)] := s;
6268 end;
6269 CloseFile(ListFile);
6270 end;
6272 procedure g_Game_SetDebugMode();
6273 begin
6274 gDebugMode := True;
6275 // Читы (даже в своей игре):
6276 gCheats := True;
6277 end;
6279 procedure g_Game_SetLoadingText(Text: String; Max: Integer; reWrite: Boolean);
6280 var
6281 i: Word;
6282 begin
6283 if Length(LoadingStat.Msgs) = 0 then
6284 Exit;
6286 with LoadingStat do
6287 begin
6288 if not reWrite then
6289 begin // Переходим на следующую строку или скроллируем:
6290 if NextMsg = Length(Msgs) then
6291 begin // scroll
6292 for i := 0 to High(Msgs)-1 do
6293 Msgs[i] := Msgs[i+1];
6294 end
6295 else
6296 Inc(NextMsg);
6297 end else
6298 if NextMsg = 0 then
6299 Inc(NextMsg);
6301 Msgs[NextMsg-1] := Text;
6302 CurValue := 0;
6303 MaxValue := Max;
6304 ShowCount := 0;
6305 PBarWasHere := false;
6306 end;
6308 {$IFDEF ENABLE_MENU}
6309 g_ActiveWindow := nil;
6310 {$ENDIF}
6312 ProcessLoading(true);
6313 end;
6315 procedure g_Game_StepLoading(Value: Integer = -1);
6316 begin
6317 with LoadingStat do
6318 begin
6319 if Value = -1 then
6320 begin
6321 Inc(CurValue);
6322 Inc(ShowCount);
6323 end
6324 else
6325 CurValue := Value;
6326 if (ShowCount > LOADING_SHOW_STEP) or (Value > -1) then
6327 begin
6328 ShowCount := 0;
6329 ProcessLoading();
6330 end;
6331 end;
6332 end;
6334 procedure g_Game_ClearLoading();
6335 var
6336 len: Word;
6337 begin
6338 with LoadingStat do
6339 begin
6340 CurValue := 0;
6341 MaxValue := 0;
6342 ShowCount := 0;
6343 len := ((gScreenHeight div 3)*2 - 50) div LOADING_INTERLINE;
6344 if len < 1 then len := 1;
6345 SetLength(Msgs, len);
6346 for len := Low(Msgs) to High(Msgs) do
6347 Msgs[len] := '';
6348 NextMsg := 0;
6349 PBarWasHere := false;
6350 end;
6351 end;
6353 procedure Parse_Params(var pars: TParamStrValues);
6354 var
6355 i: Integer;
6356 s: String;
6357 begin
6358 SetLength(pars, 0);
6359 i := 1;
6360 while i <= ParamCount do
6361 begin
6362 s := ParamStr(i);
6363 if (s[1] = '-') and (Length(s) > 1) then
6364 begin
6365 if (s[2] = '-') and (Length(s) > 2) then
6366 begin // Одиночный параметр
6367 SetLength(pars, Length(pars) + 1);
6368 with pars[High(pars)] do
6369 begin
6370 Name := LowerCase(s);
6371 Value := '+';
6372 end;
6373 end
6374 else
6375 if (i < ParamCount) then
6376 begin // Параметр со значением
6377 Inc(i);
6378 SetLength(pars, Length(pars) + 1);
6379 with pars[High(pars)] do
6380 begin
6381 Name := LowerCase(s);
6382 Value := LowerCase(ParamStr(i));
6383 end;
6384 end;
6385 end;
6387 Inc(i);
6388 end;
6389 end;
6391 function Find_Param_Value(var pars: TParamStrValues; aName: String): String;
6392 var
6393 i: Integer;
6394 begin
6395 Result := '';
6396 for i := 0 to High(pars) do
6397 if pars[i].Name = aName then
6398 begin
6399 Result := pars[i].Value;
6400 Break;
6401 end;
6402 end;
6404 procedure g_Game_Process_Params();
6405 var
6406 pars: TParamStrValues;
6407 map: String;
6408 GMode, n: Byte;
6409 LimT, LimS: Integer;
6410 Opt: LongWord;
6411 Lives: Integer;
6412 s: String;
6413 Port: Integer;
6414 ip: String;
6415 F: TextFile;
6416 begin
6417 Parse_Params(pars);
6419 // Debug mode:
6420 s := Find_Param_Value(pars, '--debug');
6421 if (s <> '') then
6422 begin
6423 g_Game_SetDebugMode();
6424 s := Find_Param_Value(pars, '--netdump');
6425 if (s <> '') then
6426 NetDump := True;
6427 end;
6429 // Connect when game loads
6430 ip := Find_Param_Value(pars, '-connect');
6432 if ip <> '' then
6433 begin
6434 s := Find_Param_Value(pars, '-port');
6435 if (s = '') or not TryStrToInt(s, Port) then
6436 Port := 25666;
6438 s := Find_Param_Value(pars, '-pw');
6440 g_Game_StartClient(ip, Port, s);
6441 Exit;
6442 end;
6444 s := LowerCase(Find_Param_Value(pars, '-dbg-mainwad'));
6445 if (s <> '') then
6446 begin
6447 gDefaultMegawadStart := s;
6448 end;
6450 if (Find_Param_Value(pars, '--dbg-mainwad-restore') <> '') or
6451 (Find_Param_Value(pars, '--dbg-mainwad-default') <> '') then
6452 begin
6453 gDefaultMegawadStart := DF_Default_Megawad_Start;
6454 end;
6456 // Start map when game loads:
6457 map := LowerCase(Find_Param_Value(pars, '-map'));
6458 if isWadPath(map) then
6459 begin
6460 // Game mode:
6461 s := Find_Param_Value(pars, '-gm');
6462 GMode := g_Game_TextToMode(s);
6463 if GMode = GM_NONE then GMode := GM_DM;
6464 if GMode = GM_SINGLE then GMode := GM_COOP;
6466 // Time limit:
6467 s := Find_Param_Value(pars, '-limt');
6468 if (s = '') or (not TryStrToInt(s, LimT)) then
6469 LimT := 0;
6470 if LimT < 0 then
6471 LimT := 0;
6473 // Goal limit:
6474 s := Find_Param_Value(pars, '-lims');
6475 if (s = '') or (not TryStrToInt(s, LimS)) then
6476 LimS := 0;
6477 if LimS < 0 then
6478 LimS := 0;
6480 // Lives limit:
6481 s := Find_Param_Value(pars, '-lives');
6482 if (s = '') or (not TryStrToInt(s, Lives)) then
6483 Lives := 0;
6484 if Lives < 0 then
6485 Lives := 0;
6487 // Options:
6488 s := Find_Param_Value(pars, '-opt');
6489 if (s = '') then
6490 Opt := gsGameFlags
6491 else
6492 Opt := StrToIntDef(s, 0);
6494 // Close after map:
6495 s := Find_Param_Value(pars, '--close');
6496 if (s <> '') then
6497 gMapOnce := True;
6499 // Override map to test:
6500 s := LowerCase(Find_Param_Value(pars, '-testmap'));
6501 if s <> '' then
6502 begin
6503 if e_IsValidResourceName(s) then
6504 e_FindResource(AllMapDirs, s);
6505 gTestMap := ExpandFileName(s);
6506 end;
6508 // Delete test map after play:
6509 s := Find_Param_Value(pars, '--testdelete');
6510 if (s <> '') then
6511 begin
6512 //gMapToDelete := MapsDir + map;
6513 e_WriteLog('"--testdelete" is deprecated, use --tempdelete.', TMsgType.Fatal);
6514 Halt(1);
6515 end;
6517 // Delete temporary WAD after play:
6518 s := Find_Param_Value(pars, '--tempdelete');
6519 if (s <> '') and (gTestMap <> '') then
6520 begin
6521 gMapToDelete := gTestMap;
6522 gTempDelete := True;
6523 end;
6525 // Number of players:
6526 s := Find_Param_Value(pars, '-pl');
6527 if (s = '') then
6528 n := DEFAULT_PLAYERS
6529 else
6530 n := StrToIntDef(s, DEFAULT_PLAYERS);
6532 // Start:
6533 s := Find_Param_Value(pars, '-port');
6534 if (s = '') or not TryStrToInt(s, Port) then
6535 g_Game_StartCustom(map, GMode, LimT, LimS, Lives, Opt, n)
6536 else
6537 g_Game_StartServer(map, GMode, LimT, LimS, Lives, Opt, n, 0, Port);
6538 end;
6540 // Execute script when game loads:
6541 s := Find_Param_Value(pars, '-exec');
6542 if s <> '' then
6543 begin
6544 // if not isWadPath(s) then
6545 // s := GameDir + '/' + s;
6547 {$I-}
6548 AssignFile(F, s);
6549 Reset(F);
6550 if IOResult <> 0 then
6551 begin
6552 e_WriteLog(Format(_lc[I_SIMPLE_ERROR], ['Failed to read file: ' + s]), TMsgType.Warning);
6553 g_Console_Add(Format(_lc[I_CONSOLE_ERROR_READ], [s]));
6554 CloseFile(F);
6555 Exit;
6556 end;
6557 e_WriteLog('Executing script: ' + s, TMsgType.Notify);
6558 g_Console_Add(Format(_lc[I_CONSOLE_EXEC], [s]));
6560 while not EOF(F) do
6561 begin
6562 ReadLn(F, s);
6563 if IOResult <> 0 then
6564 begin
6565 e_WriteLog(Format(_lc[I_SIMPLE_ERROR], ['Failed to read file: ' + s]), TMsgType.Warning);
6566 g_Console_Add(Format(_lc[I_CONSOLE_ERROR_READ], [s]));
6567 CloseFile(F);
6568 Exit;
6569 end;
6570 if Pos('#', s) <> 1 then // script comment
6571 g_Console_Process(s, True);
6572 end;
6574 CloseFile(F);
6575 {$I+}
6576 end;
6578 SetLength(pars, 0);
6579 end;
6581 begin
6582 conRegVar('pf_draw_frame', @g_profile_frame_draw, 'draw frame rendering profiles', 'render profiles');
6583 //conRegVar('pf_update_frame', @g_profile_frame_update, 'draw frame updating profiles', 'update profiles');
6584 conRegVar('pf_coldet', @g_profile_collision, 'draw collision detection profiles', 'coldet profiles');
6585 conRegVar('pf_los', @g_profile_los, 'draw monster LOS profiles', 'monster LOS profiles');
6587 conRegVar('r_sq_draw', @gdbg_map_use_accel_render, 'accelerated spatial queries in rendering', 'accelerated rendering');
6588 conRegVar('cd_sq_enabled', @gdbg_map_use_accel_coldet, 'accelerated spatial queries in map coldet', 'accelerated map coldet');
6589 conRegVar('mon_sq_enabled', @gmon_debug_use_sqaccel, 'accelerated spatial queries for monsters', 'accelerated monster coldet');
6590 conRegVar('wtrace_sq_enabled', @gwep_debug_fast_trace, 'accelerated spatial queries for weapon hitscan trace', 'accelerated weapon hitscan');
6592 conRegVar('pr_enabled', @gpart_dbg_enabled, 'enable/disable particles', 'particles');
6593 conRegVar('pr_phys_enabled', @gpart_dbg_phys_enabled, 'enable/disable particle physics', 'particle physics');
6595 conRegVar('los_enabled', @gmon_dbg_los_enabled, 'enable/disable monster LOS calculations', 'monster LOS', true);
6596 conRegVar('mon_think', @gmon_debug_think, 'enable/disable monster thinking', 'monster thinking', true);
6598 {$IFDEF ENABLE_HOLMES}
6599 conRegVar('dbg_holmes', @g_holmes_enabled, 'enable/disable Holmes', 'Holmes', true);
6600 {$ENDIF}
6602 conRegVar('dbg_ignore_level_bounds', @g_dbg_ignore_bounds, 'ignore level bounds', '', false);
6604 conRegVar('light_enabled', @gwin_k8_enable_light_experiments, 'enable/disable dynamic lighting', 'lighting');
6605 conRegVar('light_player_halo', @g_playerLight, 'enable/disable player halo', 'player light halo');
6607 conRegVar('r_smallmap_align_h', @r_smallmap_h, 'halign: 0: left; 1: center; 2: right', 'horizontal aligning of small maps');
6608 conRegVar('r_smallmap_align_v', @r_smallmap_v, 'valign: 0: top; 1: center; 2: bottom', 'vertial aligning of small maps');
6610 conRegVar('r_showfps', @gShowFPS, 'draw fps counter', 'draw fps counter');
6611 conRegVar('r_showtime', @gShowTime, 'show game time', 'show game time');
6612 conRegVar('r_showping', @gShowPing, 'show ping', 'show ping');
6613 conRegVar('r_showscore', @gShowGoals, 'show score', 'show score');
6614 conRegVar('r_showkillmsg', @gShowKillMsg, 'show kill log', 'show kill log');
6615 conRegVar('r_showlives', @gShowLives, 'show lives', 'show lives');
6616 conRegVar('r_showspect', @gSpectHUD, 'show spectator hud', 'show spectator hud');
6617 conRegVar('r_showstat', @gShowStat, 'show stats', 'show stats');
6618 conRegVar('r_showpids', @gShowPIDs, 'show PIDs', 'show PIDs');
6619 end.