DEADSOFTWARE

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