DEADSOFTWARE

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