DEADSOFTWARE

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