DEADSOFTWARE

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