DEADSOFTWARE

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