DEADSOFTWARE

85f85894e86ff92a0226c26257836bd0f878f519
[d2df-sdl.git] / src / game / g_game.pas
1 (* Copyright (C) Doom 2D: Forever Developers
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, version 3 of the License ONLY.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14 *)
15 {$INCLUDE ../shared/a_modes.inc}
16 unit g_game;
18 interface
20 uses
21 SysUtils, Classes,
22 MAPDEF,
23 g_base, g_basic, g_player, r_graphics, g_res_downloader,
24 g_sound, g_gui, utils, md5, mempool, xprofiler,
25 g_touch, g_weapons;
27 type
28 TGameSettings = record
29 GameType: Byte;
30 GameMode: Byte;
31 TimeLimit: Word;
32 ScoreLimit: Word;
33 WarmupTime: Word;
34 SpawnInvul: Word;
35 ItemRespawnTime: Word;
36 MaxLives: Byte;
37 Options: LongWord;
38 WAD: String;
39 end;
41 TGameEvent = record
42 Name: String;
43 Command: String;
44 end;
46 TDelayedEvent = record
47 Pending: Boolean;
48 Time: LongWord;
49 DEType: Byte;
50 DENum: Integer;
51 DEStr: String;
52 end;
54 TChatSound = record
55 Sound: TPlayableSound;
56 Tags: Array of String;
57 FullWord: Boolean;
58 end;
60 TPlayerSettings = record
61 Name: String;
62 Model: String;
63 Color: TRGB;
64 Team: Byte;
65 // ones below are sent only to the server
66 WeaponSwitch: Byte;
67 WeaponPreferences: Array[WP_FIRST..WP_LAST+1] of Byte;
68 SwitchToEmpty: Byte;
69 SkipFist: Byte;
70 end;
72 TMegaWADInfo = record
73 Name: String;
74 Description: String;
75 Author: String;
76 Pic: String;
77 end;
79 THearPoint = record
80 Active: Boolean;
81 Coords: TDFPoint;
82 end;
84 function g_Game_IsNet(): Boolean;
85 function g_Game_IsServer(): Boolean;
86 function g_Game_IsClient(): Boolean;
87 procedure g_Game_Init();
88 procedure g_Game_Free (freeTextures: Boolean=true);
89 procedure g_Game_LoadData();
90 procedure g_Game_FreeData();
91 procedure g_Game_Update();
92 procedure g_Game_PreUpdate();
93 procedure g_Game_Quit();
94 procedure g_Game_SetupScreenSize();
95 procedure g_Game_ChangeResolution(newWidth, newHeight: Word; nowFull, nowMax: Boolean);
96 function g_Game_ModeToText(Mode: Byte): string;
97 function g_Game_TextToMode(Mode: string): Byte;
98 procedure g_Game_ExecuteEvent(Name: String);
99 function g_Game_DelayEvent(DEType: Byte; Time: LongWord; Num: Integer = 0; Str: String = ''): Integer;
100 procedure g_Game_AddPlayer(Team: Byte = TEAM_NONE);
101 procedure g_Game_RemovePlayer();
102 procedure g_Game_Spectate();
103 procedure g_Game_SpectateCenterView();
104 procedure g_Game_StartSingle(Map: String; TwoPlayers: Boolean; nPlayers: Byte);
105 procedure g_Game_StartCustom(Map: String; GameMode: Byte; TimeLimit, ScoreLimit: Word; MaxLives: Byte; Options: LongWord; nPlayers: Byte);
106 procedure g_Game_StartServer(Map: String; GameMode: Byte; TimeLimit, ScoreLimit: Word; MaxLives: Byte; Options: LongWord; nPlayers: Byte; IPAddr: LongWord; Port: Word);
107 procedure g_Game_StartClient(Addr: String; Port: Word; PW: String);
108 procedure g_Game_Restart();
109 procedure g_Game_RestartLevel();
110 procedure g_Game_RestartRound(NoMapRestart: Boolean = False);
111 function g_Game_ClientWAD (NewWAD: String; const WHash: TMD5Digest): AnsiString;
112 function g_Game_StartMap(asMegawad: Boolean; Map: String; Force: Boolean = False; const oldMapPath: AnsiString=''): Boolean;
113 procedure g_Game_ChangeMap(const MapPath: String);
114 procedure g_Game_ExitLevel(const Map: AnsiString);
115 function g_Game_GetFirstMap(WAD: String): String;
116 function g_Game_GetNextMap(): String;
117 procedure g_Game_NextLevel();
118 procedure g_Game_Pause(Enable: Boolean);
119 procedure g_Game_HolmesPause(Enable: Boolean);
120 procedure g_Game_InGameMenu(Show: Boolean);
121 function g_Game_IsWatchedPlayer(UID: Word): Boolean;
122 function g_Game_IsWatchedTeam(Team: Byte): Boolean;
123 procedure g_Game_Message(Msg: String; Time: Word);
124 procedure g_Game_LoadMapList(FileName: String);
125 procedure g_Game_PauseAllSounds(Enable: Boolean);
126 procedure g_Game_StopAllSounds(all: Boolean);
127 procedure g_Game_UpdateTriggerSounds();
128 function g_Game_GetMegaWADInfo(WAD: String): TMegaWADInfo;
129 procedure g_Game_ChatSound(Text: String; Taunt: Boolean = True);
130 procedure g_Game_Announce_GoodShot(SpawnerUID: Word);
131 procedure g_Game_Announce_KillCombo(Param: Integer);
132 procedure g_Game_Announce_BodyKill(SpawnerUID: Word);
133 procedure g_Game_StartVote(Command, Initiator: string);
134 procedure g_Game_CheckVote;
135 procedure g_TakeScreenShot(Filename: string = '');
136 procedure g_FatalError(Text: String);
137 procedure g_SimpleError(Text: String);
138 function g_Game_IsTestMap(): Boolean;
139 procedure g_Game_DeleteTestMap();
140 procedure GameCVars(P: SSArray);
141 procedure PlayerSettingsCVars(P: SSArray);
142 procedure SystemCommands(P: SSArray);
143 procedure GameCommands(P: SSArray);
144 procedure GameCheats(P: SSArray);
145 procedure DebugCommands(P: SSArray);
146 procedure g_Game_Process_Params;
147 procedure g_Game_SetLoadingText(Text: String; Max: Integer; reWrite: Boolean);
148 procedure g_Game_StepLoading(Value: Integer = -1);
149 procedure g_Game_ClearLoading();
150 procedure g_Game_SetDebugMode();
152 function IsActivePlayer(p: TPlayer): Boolean;
153 function GetActivePlayerID_Next(Skip: Integer = -1): Integer;
154 procedure SortGameStat(var stat: TPlayerStatArray);
156 { procedure 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, r_playermodel;
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 r_PlayerModel_Initialize;
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 r_PlayerModel_Finalize;
2333 g_PlayerModel_FreeData();
2334 g_Texture_DeleteAll();
2335 g_Frames_DeleteAll();
2336 {$IFNDEF HEADLESS}
2337 //g_Menu_Free(); //k8: this segfaults after resolution change; who cares?
2338 {$ENDIF}
2340 if NetInitDone then g_Net_Free;
2342 // remove map after test
2343 if gMapToDelete <> '' then
2344 g_Game_DeleteTestMap();
2346 gExit := EXIT_QUIT;
2347 sys_RequestQuit;
2348 end;
2350 procedure g_Game_FreeData();
2351 begin
2352 if not DataLoaded then Exit;
2354 g_Items_FreeData();
2355 g_Weapon_FreeData();
2356 g_Monsters_FreeData();
2358 e_WriteLog('Releasing game data...', TMsgType.Notify);
2360 g_Texture_Delete('NOTEXTURE');
2361 g_Texture_Delete('TEXTURE_PLAYER_HUD');
2362 g_Texture_Delete('TEXTURE_PLAYER_HUDBG');
2363 g_Texture_Delete('TEXTURE_PLAYER_ARMORHUD');
2364 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG');
2365 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_S');
2366 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_D');
2367 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG');
2368 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_S');
2369 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_D');
2370 g_Texture_Delete('TEXTURE_PLAYER_TALKBUBBLE');
2371 g_Texture_Delete('TEXTURE_PLAYER_INVULPENTA');
2372 g_Frames_DeleteByName('FRAMES_TELEPORT');
2373 g_Frames_DeleteByName('FRAMES_PUNCH');
2374 g_Frames_DeleteByName('FRAMES_PUNCH_UP');
2375 g_Frames_DeleteByName('FRAMES_PUNCH_DN');
2376 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK');
2377 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK_UP');
2378 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK_DN');
2379 g_Sound_Delete('SOUND_GAME_TELEPORT');
2380 g_Sound_Delete('SOUND_GAME_NOTELEPORT');
2381 g_Sound_Delete('SOUND_GAME_SECRET');
2382 g_Sound_Delete('SOUND_GAME_DOOROPEN');
2383 g_Sound_Delete('SOUND_GAME_DOORCLOSE');
2384 g_Sound_Delete('SOUND_GAME_BULK1');
2385 g_Sound_Delete('SOUND_GAME_BULK2');
2386 g_Sound_Delete('SOUND_GAME_BUBBLE1');
2387 g_Sound_Delete('SOUND_GAME_BUBBLE2');
2388 g_Sound_Delete('SOUND_GAME_BURNING');
2389 g_Sound_Delete('SOUND_GAME_SWITCH1');
2390 g_Sound_Delete('SOUND_GAME_SWITCH0');
2392 goodsnd[0].Free();
2393 goodsnd[1].Free();
2394 goodsnd[2].Free();
2395 goodsnd[3].Free();
2397 g_Sound_Delete('SOUND_ANNOUNCER_GOOD1');
2398 g_Sound_Delete('SOUND_ANNOUNCER_GOOD2');
2399 g_Sound_Delete('SOUND_ANNOUNCER_GOOD3');
2400 g_Sound_Delete('SOUND_ANNOUNCER_GOOD4');
2402 killsnd[0].Free();
2403 killsnd[1].Free();
2404 killsnd[2].Free();
2405 killsnd[3].Free();
2407 g_Sound_Delete('SOUND_ANNOUNCER_KILL2X');
2408 g_Sound_Delete('SOUND_ANNOUNCER_KILL3X');
2409 g_Sound_Delete('SOUND_ANNOUNCER_KILL4X');
2410 g_Sound_Delete('SOUND_ANNOUNCER_KILLMX');
2412 hahasnd[0].Free();
2413 hahasnd[1].Free();
2414 hahasnd[2].Free();
2416 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA1');
2417 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA2');
2418 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA3');
2420 sound_get_flag[0].Free();
2421 sound_get_flag[1].Free();
2422 sound_lost_flag[0].Free();
2423 sound_lost_flag[1].Free();
2424 sound_ret_flag[0].Free();
2425 sound_ret_flag[1].Free();
2426 sound_cap_flag[0].Free();
2427 sound_cap_flag[1].Free();
2429 g_Sound_Delete('SOUND_CTF_GET1');
2430 g_Sound_Delete('SOUND_CTF_GET2');
2431 g_Sound_Delete('SOUND_CTF_LOST1');
2432 g_Sound_Delete('SOUND_CTF_LOST2');
2433 g_Sound_Delete('SOUND_CTF_RETURN1');
2434 g_Sound_Delete('SOUND_CTF_RETURN2');
2435 g_Sound_Delete('SOUND_CTF_CAPTURE1');
2436 g_Sound_Delete('SOUND_CTF_CAPTURE2');
2438 g_Game_FreeChatSounds();
2440 DataLoaded := False;
2441 end;
2443 procedure g_FatalError(Text: String);
2444 begin
2445 g_Console_Add(Format(_lc[I_FATAL_ERROR], [Text]), True);
2446 e_WriteLog(Format(_lc[I_FATAL_ERROR], [Text]), TMsgType.Warning);
2448 gExit := EXIT_SIMPLE;
2449 if gGameOn then EndGame;
2450 end;
2452 procedure g_SimpleError(Text: String);
2453 begin
2454 g_Console_Add(Format(_lc[I_SIMPLE_ERROR], [Text]), True);
2455 e_WriteLog(Format(_lc[I_SIMPLE_ERROR], [Text]), TMsgType.Warning);
2456 end;
2458 procedure g_Game_SetupScreenSize();
2459 const
2460 RES_FACTOR = 4.0 / 3.0;
2461 var
2462 s: Single;
2463 rf: Single;
2464 bw, bh: Word;
2465 begin
2466 // Размер экранов игроков:
2467 gPlayerScreenSize.X := gScreenWidth-196;
2468 if (gPlayer1 <> nil) and (gPlayer2 <> nil) then
2469 gPlayerScreenSize.Y := gScreenHeight div 2
2470 else
2471 gPlayerScreenSize.Y := gScreenHeight;
2473 // Размер заднего плана:
2474 if BackID <> DWORD(-1) then
2475 begin
2476 s := SKY_STRETCH;
2477 if (gScreenWidth*s > gMapInfo.Width) or
2478 (gScreenHeight*s > gMapInfo.Height) then
2479 begin
2480 gBackSize.X := gScreenWidth;
2481 gBackSize.Y := gScreenHeight;
2482 end
2483 else
2484 begin
2485 e_GetTextureSize(BackID, @bw, @bh);
2486 rf := Single(bw) / Single(bh);
2487 if (rf > RES_FACTOR) then bw := Round(Single(bh) * RES_FACTOR)
2488 else if (rf < RES_FACTOR) then bh := Round(Single(bw) / RES_FACTOR);
2489 s := Max(gScreenWidth / bw, gScreenHeight / bh);
2490 if (s < 1.0) then s := 1.0;
2491 gBackSize.X := Round(bw*s);
2492 gBackSize.Y := Round(bh*s);
2493 end;
2494 end;
2495 end;
2497 procedure g_Game_ChangeResolution(newWidth, newHeight: Word; nowFull, nowMax: Boolean);
2498 begin
2499 sys_SetDisplayMode(newWidth, newHeight, gBPP, nowFull, nowMax);
2500 end;
2502 procedure g_Game_AddPlayer(Team: Byte = TEAM_NONE);
2503 begin
2504 if ((not gGameOn) and (gState <> STATE_INTERCUSTOM))
2505 or (not (gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT])) then
2506 Exit;
2508 if (gGameSettings.MaxLives > 0) and (gLMSRespawn = LMS_RESPAWN_NONE) then
2509 Exit;
2511 if gPlayer1 = nil then
2512 begin
2513 if g_Game_IsClient then
2514 begin
2515 if NetPlrUID1 > -1 then
2516 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE);
2517 Exit;
2518 end;
2520 if not (Team in [TEAM_RED, TEAM_BLUE]) then
2521 Team := gPlayer1Settings.Team;
2523 // Создание первого игрока:
2524 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
2525 gPlayer1Settings.Color,
2526 Team, False));
2527 if gPlayer1 = nil then
2528 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]))
2529 else
2530 begin
2531 gPlayer1.Name := gPlayer1Settings.Name;
2532 gPlayer1.WeapSwitchMode := gPlayer1Settings.WeaponSwitch;
2533 gPlayer1.setWeaponPrefs(gPlayer1Settings.WeaponPreferences);
2534 gPlayer1.SwitchToEmpty := gPlayer1Settings.SwitchToEmpty;
2535 gPlayer1.SkipFist := gPlayer1Settings.SkipFist;
2536 g_Console_Add(Format(_lc[I_PLAYER_JOIN], [gPlayer1.Name]), True);
2537 if g_Game_IsServer and g_Game_IsNet then
2538 MH_SEND_PlayerCreate(gPlayer1.UID);
2539 gPlayer1.Respawn(False, True);
2540 g_Net_Slist_ServerPlayerComes();
2541 end;
2543 Exit;
2544 end;
2545 if gPlayer2 = nil then
2546 begin
2547 if g_Game_IsClient then
2548 begin
2549 if NetPlrUID2 > -1 then
2550 gPlayer2 := g_Player_Get(NetPlrUID2);
2551 Exit;
2552 end;
2554 if not (Team in [TEAM_RED, TEAM_BLUE]) then
2555 Team := gPlayer2Settings.Team;
2557 // Создание второго игрока:
2558 gPlayer2 := g_Player_Get(g_Player_Create(gPlayer2Settings.Model,
2559 gPlayer2Settings.Color,
2560 Team, False));
2561 if gPlayer2 = nil then
2562 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [2]))
2563 else
2564 begin
2565 gPlayer2.Name := gPlayer2Settings.Name;
2566 gPlayer2.WeapSwitchMode := gPlayer2Settings.WeaponSwitch;
2567 gPlayer2.setWeaponPrefs(gPlayer2Settings.WeaponPreferences);
2568 gPlayer2.SwitchToEmpty := gPlayer2Settings.SwitchToEmpty;
2569 gPlayer2.SkipFist := gPlayer2Settings.SkipFist;
2570 g_Console_Add(Format(_lc[I_PLAYER_JOIN], [gPlayer2.Name]), True);
2571 if g_Game_IsServer and g_Game_IsNet then
2572 MH_SEND_PlayerCreate(gPlayer2.UID);
2573 gPlayer2.Respawn(False, True);
2574 g_Net_Slist_ServerPlayerComes();
2575 end;
2577 Exit;
2578 end;
2579 end;
2581 procedure g_Game_RemovePlayer();
2582 var
2583 Pl: TPlayer;
2584 begin
2585 if ((not gGameOn) and (gState <> STATE_INTERCUSTOM))
2586 or (not (gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT])) then
2587 Exit;
2588 Pl := gPlayer2;
2589 if Pl <> nil then
2590 begin
2591 if g_Game_IsServer then
2592 begin
2593 Pl.Lives := 0;
2594 Pl.Kill(K_SIMPLEKILL, 0, HIT_DISCON);
2595 g_Console_Add(Format(_lc[I_PLAYER_LEAVE], [Pl.Name]), True);
2596 g_Player_Remove(Pl.UID);
2597 g_Net_Slist_ServerPlayerLeaves();
2598 end
2599 else
2600 begin
2601 gSpectLatchPID2 := Pl.UID;
2602 gPlayer2 := nil;
2603 end;
2604 Exit;
2605 end;
2606 Pl := gPlayer1;
2607 if Pl <> nil then
2608 begin
2609 if g_Game_IsServer then
2610 begin
2611 Pl.Lives := 0;
2612 Pl.Kill(K_SIMPLEKILL, 0, HIT_DISCON);
2613 g_Console_Add(Format(_lc[I_PLAYER_LEAVE], [Pl.Name]), True);
2614 g_Player_Remove(Pl.UID);
2615 g_Net_Slist_ServerPlayerLeaves();
2616 end else
2617 begin
2618 gSpectLatchPID1 := Pl.UID;
2619 gPlayer1 := nil;
2620 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE);
2621 end;
2622 Exit;
2623 end;
2624 g_Net_Slist_ServerPlayerLeaves();
2625 end;
2627 procedure g_Game_Spectate();
2628 begin
2629 g_Game_RemovePlayer();
2630 if gPlayer1 <> nil then
2631 g_Game_RemovePlayer();
2632 end;
2634 procedure g_Game_SpectateCenterView();
2635 begin
2636 gSpectX := Max(gMapInfo.Width div 2 - gScreenWidth div 2, 0);
2637 gSpectY := Max(gMapInfo.Height div 2 - gScreenHeight div 2, 0);
2638 end;
2640 procedure g_Game_StartSingle(Map: String; TwoPlayers: Boolean; nPlayers: Byte);
2641 var
2642 i, nPl: Integer;
2643 tmps: AnsiString;
2644 begin
2645 g_Game_Free();
2647 e_WriteLog('Starting singleplayer game...', TMsgType.Notify);
2649 g_Game_ClearLoading();
2651 // Настройки игры:
2652 FillByte(gGameSettings, SizeOf(TGameSettings), 0);
2653 gAimLine := False;
2654 gShowMap := False;
2655 gGameSettings.GameType := GT_SINGLE;
2656 gGameSettings.MaxLives := 0;
2657 gGameSettings.Options := gGameSettings.Options + GAME_OPTION_ALLOWEXIT;
2658 gGameSettings.Options := gGameSettings.Options + GAME_OPTION_MONSTERS;
2659 gGameSettings.Options := gGameSettings.Options + GAME_OPTION_BOTVSMONSTER;
2660 gGameSettings.Options := gGameSettings.Options + GAME_OPTION_TEAMHITPROJECTILE;
2661 gGameSettings.Options := gGameSettings.Options + GAME_OPTION_TEAMHITTRACE;
2662 gSwitchGameMode := GM_SINGLE;
2664 gLMSRespawn := LMS_RESPAWN_NONE;
2665 gLMSRespawnTime := 0;
2666 gSpectLatchPID1 := 0;
2667 gSpectLatchPID2 := 0;
2669 g_Game_ExecuteEvent('ongamestart');
2671 // Установка размеров окон игроков:
2672 g_Game_SetupScreenSize();
2674 // Создание первого игрока:
2675 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
2676 gPlayer1Settings.Color,
2677 gPlayer1Settings.Team, False));
2678 if gPlayer1 = nil then
2679 begin
2680 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]));
2681 Exit;
2682 end;
2684 gPlayer1.Name := gPlayer1Settings.Name;
2685 gPlayer1.WeapSwitchMode := gPlayer1Settings.WeaponSwitch;
2686 gPlayer1.setWeaponPrefs(gPlayer1Settings.WeaponPreferences);
2687 gPlayer1.SwitchToEmpty := gPlayer1Settings.SwitchToEmpty;
2688 gPlayer1.SkipFist := gPlayer1Settings.SkipFist;
2689 nPl := 1;
2691 // Создание второго игрока, если есть:
2692 if TwoPlayers then
2693 begin
2694 gPlayer2 := g_Player_Get(g_Player_Create(gPlayer2Settings.Model,
2695 gPlayer2Settings.Color,
2696 gPlayer2Settings.Team, False));
2697 if gPlayer2 = nil then
2698 begin
2699 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [2]));
2700 Exit;
2701 end;
2703 gPlayer2.Name := gPlayer2Settings.Name;
2704 gPlayer2.WeapSwitchMode := gPlayer2Settings.WeaponSwitch;
2705 gPlayer2.setWeaponPrefs(gPlayer2Settings.WeaponPreferences);
2706 gPlayer2.SwitchToEmpty := gPlayer2Settings.SwitchToEmpty;
2707 gPlayer2.SkipFist := gPlayer2Settings.SkipFist;
2708 Inc(nPl);
2709 end;
2711 // Загрузка и запуск карты:
2712 if not g_Game_StartMap(false{asMegawad}, MAP, True) then
2713 begin
2714 if (Pos(':\', Map) > 0) or (Pos(':/', Map) > 0) then tmps := Map else tmps := gGameSettings.WAD + ':\' + MAP;
2715 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [tmps]));
2716 Exit;
2717 end;
2719 // Настройки игроков и ботов:
2720 g_Player_Init();
2722 // Создаем ботов:
2723 for i := nPl+1 to nPlayers do
2724 g_Player_Create(STD_PLAYER_MODEL, _RGB(0, 0, 0), 0, True);
2725 end;
2727 procedure g_Game_StartCustom(Map: String; GameMode: Byte;
2728 TimeLimit, ScoreLimit: Word;
2729 MaxLives: Byte;
2730 Options: LongWord; nPlayers: Byte);
2731 var
2732 i, nPl: Integer;
2733 begin
2734 g_Game_Free();
2736 e_WriteLog('Starting custom game...', TMsgType.Notify);
2738 g_Game_ClearLoading();
2740 // Настройки игры:
2741 gGameSettings.GameType := GT_CUSTOM;
2742 gGameSettings.GameMode := GameMode;
2743 gSwitchGameMode := GameMode;
2744 gGameSettings.TimeLimit := TimeLimit;
2745 gGameSettings.ScoreLimit := ScoreLimit;
2746 gGameSettings.MaxLives := IfThen(GameMode = GM_CTF, 0, MaxLives);
2747 gGameSettings.Options := Options;
2749 gCoopTotalMonstersKilled := 0;
2750 gCoopTotalSecretsFound := 0;
2751 gCoopTotalMonsters := 0;
2752 gCoopTotalSecrets := 0;
2753 gAimLine := False;
2754 gShowMap := False;
2756 gLMSRespawn := LMS_RESPAWN_NONE;
2757 gLMSRespawnTime := 0;
2758 gSpectLatchPID1 := 0;
2759 gSpectLatchPID2 := 0;
2761 g_Game_ExecuteEvent('ongamestart');
2763 // Установка размеров окон игроков:
2764 g_Game_SetupScreenSize();
2766 // Режим наблюдателя:
2767 if nPlayers = 0 then
2768 begin
2769 gPlayer1 := nil;
2770 gPlayer2 := nil;
2771 end;
2773 nPl := 0;
2774 if nPlayers >= 1 then
2775 begin
2776 // Создание первого игрока:
2777 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
2778 gPlayer1Settings.Color,
2779 gPlayer1Settings.Team, False));
2780 if gPlayer1 = nil then
2781 begin
2782 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]));
2783 Exit;
2784 end;
2786 gPlayer1.Name := gPlayer1Settings.Name;
2787 gPlayer1.WeapSwitchMode := gPlayer1Settings.WeaponSwitch;
2788 gPlayer1.setWeaponPrefs(gPlayer1Settings.WeaponPreferences);
2789 gPlayer1.SwitchToEmpty := gPlayer1Settings.SwitchToEmpty;
2790 gPlayer1.SkipFist := gPlayer1Settings.SkipFist;
2791 Inc(nPl);
2792 end;
2794 if nPlayers >= 2 then
2795 begin
2796 // Создание второго игрока:
2797 gPlayer2 := g_Player_Get(g_Player_Create(gPlayer2Settings.Model,
2798 gPlayer2Settings.Color,
2799 gPlayer2Settings.Team, False));
2800 if gPlayer2 = nil then
2801 begin
2802 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [2]));
2803 Exit;
2804 end;
2806 gPlayer2.Name := gPlayer2Settings.Name;
2807 gPlayer2.WeapSwitchMode := gPlayer2Settings.WeaponSwitch;
2808 gPlayer2.setWeaponPrefs(gPlayer2Settings.WeaponPreferences);
2809 gPlayer2.SwitchToEmpty := gPlayer2Settings.SwitchToEmpty;
2810 gPlayer2.SkipFist := gPlayer2Settings.SkipFist;
2811 Inc(nPl);
2812 end;
2814 // Загрузка и запуск карты:
2815 if not g_Game_StartMap(true{asMegawad}, Map, True) then
2816 begin
2817 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [Map]));
2818 Exit;
2819 end;
2821 // Нет точек появления:
2822 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1) +
2823 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2) +
2824 g_Map_GetPointCount(RESPAWNPOINT_DM) +
2825 g_Map_GetPointCount(RESPAWNPOINT_RED)+
2826 g_Map_GetPointCount(RESPAWNPOINT_BLUE)) < 1 then
2827 begin
2828 g_FatalError(_lc[I_GAME_ERROR_GET_SPAWN]);
2829 Exit;
2830 end;
2832 // Настройки игроков и ботов:
2833 g_Player_Init();
2835 // Создаем ботов:
2836 for i := nPl+1 to nPlayers do
2837 g_Player_Create(STD_PLAYER_MODEL, _RGB(0, 0, 0), 0, True);
2838 end;
2840 procedure g_Game_StartServer(Map: String; GameMode: Byte;
2841 TimeLimit, ScoreLimit: Word; MaxLives: Byte;
2842 Options: LongWord; nPlayers: Byte;
2843 IPAddr: LongWord; Port: Word);
2844 begin
2845 g_Game_Free();
2846 g_Net_Slist_ServerClosed();
2848 e_WriteLog('Starting net game (server)...', TMsgType.Notify);
2850 g_Game_ClearLoading();
2852 ClearDebugCvars();
2854 // Настройки игры:
2855 gGameSettings.GameType := GT_SERVER;
2856 gGameSettings.GameMode := GameMode;
2857 gSwitchGameMode := GameMode;
2858 gGameSettings.TimeLimit := TimeLimit;
2859 gGameSettings.ScoreLimit := ScoreLimit;
2860 gGameSettings.MaxLives := IfThen(GameMode = GM_CTF, 0, MaxLives);
2861 gGameSettings.Options := Options;
2863 gCoopTotalMonstersKilled := 0;
2864 gCoopTotalSecretsFound := 0;
2865 gCoopTotalMonsters := 0;
2866 gCoopTotalSecrets := 0;
2867 gAimLine := False;
2868 gShowMap := False;
2870 gLMSRespawn := LMS_RESPAWN_NONE;
2871 gLMSRespawnTime := 0;
2872 gSpectLatchPID1 := 0;
2873 gSpectLatchPID2 := 0;
2875 g_Game_ExecuteEvent('ongamestart');
2877 // Установка размеров окна игрока
2878 g_Game_SetupScreenSize();
2880 // Режим наблюдателя:
2881 if nPlayers = 0 then
2882 begin
2883 gPlayer1 := nil;
2884 gPlayer2 := nil;
2885 end;
2887 if nPlayers >= 1 then
2888 begin
2889 // Создание первого игрока:
2890 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
2891 gPlayer1Settings.Color,
2892 gPlayer1Settings.Team, False));
2893 if gPlayer1 = nil then
2894 begin
2895 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]));
2896 Exit;
2897 end;
2899 gPlayer1.Name := gPlayer1Settings.Name;
2900 gPlayer1.WeapSwitchMode := gPlayer1Settings.WeaponSwitch;
2901 gPlayer1.setWeaponPrefs(gPlayer1Settings.WeaponPreferences);
2902 gPlayer1.SwitchToEmpty := gPlayer1Settings.SwitchToEmpty;
2903 gPlayer1.SkipFist := gPlayer1Settings.SkipFist;
2904 end;
2906 if nPlayers >= 2 then
2907 begin
2908 // Создание второго игрока:
2909 gPlayer2 := g_Player_Get(g_Player_Create(gPlayer2Settings.Model,
2910 gPlayer2Settings.Color,
2911 gPlayer2Settings.Team, False));
2912 if gPlayer2 = nil then
2913 begin
2914 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [2]));
2915 Exit;
2916 end;
2918 gPlayer2.Name := gPlayer2Settings.Name;
2919 gPlayer2.WeapSwitchMode := gPlayer2Settings.WeaponSwitch;
2920 gPlayer2.setWeaponPrefs(gPlayer2Settings.WeaponPreferences);
2921 gPlayer2.SwitchToEmpty := gPlayer2Settings.SwitchToEmpty;
2922 gPlayer2.SkipFist := gPlayer2Settings.SkipFist;
2923 end;
2925 g_Game_SetLoadingText(_lc[I_LOAD_HOST], 0, False);
2926 if NetForwardPorts then
2927 g_Game_SetLoadingText(_lc[I_LOAD_PORTS], 0, False);
2929 // Стартуем сервер
2930 if not g_Net_Host(IPAddr, Port, NetMaxClients) then
2931 begin
2932 g_FatalError(_lc[I_NET_MSG] + Format(_lc[I_NET_ERR_HOST], [Port]));
2933 Exit;
2934 end;
2936 g_Net_Slist_Set(NetMasterList);
2938 g_Net_Slist_ServerStarted();
2940 // Загрузка и запуск карты:
2941 if not g_Game_StartMap(false{asMegawad}, Map, True) then
2942 begin
2943 g_Net_Slist_ServerClosed();
2944 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [Map]));
2945 Exit;
2946 end;
2948 // Нет точек появления:
2949 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1) +
2950 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2) +
2951 g_Map_GetPointCount(RESPAWNPOINT_DM) +
2952 g_Map_GetPointCount(RESPAWNPOINT_RED)+
2953 g_Map_GetPointCount(RESPAWNPOINT_BLUE)) < 1 then
2954 begin
2955 g_Net_Slist_ServerClosed();
2956 g_FatalError(_lc[I_GAME_ERROR_GET_SPAWN]);
2957 Exit;
2958 end;
2960 // Настройки игроков и ботов:
2961 g_Player_Init();
2963 g_Net_Slist_ServerMapStarted();
2964 NetState := NET_STATE_GAME;
2965 end;
2967 procedure g_Game_StartClient(Addr: String; Port: Word; PW: String);
2968 var
2969 Map: String;
2970 WadName: string;
2971 Ptr: Pointer;
2972 T: Cardinal;
2973 MID: Byte;
2974 State: Byte;
2975 OuterLoop: Boolean;
2976 newResPath: string;
2977 InMsg: TMsg;
2978 begin
2979 g_Game_Free();
2981 State := 0;
2982 e_WriteLog('Starting net game (client)...', TMsgType.Notify);
2983 e_WriteLog('NET: Trying to connect to ' + Addr + ':' + IntToStr(Port) + '...', TMsgType.Notify);
2985 g_Game_ClearLoading();
2987 ClearDebugCvars();
2989 // Настройки игры:
2990 gGameSettings.GameType := GT_CLIENT;
2992 gCoopTotalMonstersKilled := 0;
2993 gCoopTotalSecretsFound := 0;
2994 gCoopTotalMonsters := 0;
2995 gCoopTotalSecrets := 0;
2996 gAimLine := False;
2997 gShowMap := False;
2999 g_Game_ExecuteEvent('ongamestart');
3001 // Установка размеров окон игроков:
3002 g_Game_SetupScreenSize();
3004 NetState := NET_STATE_AUTH;
3006 g_Game_SetLoadingText(_lc[I_LOAD_CONNECT], 0, False);
3008 // create (or update) map/resource databases
3009 g_Res_CreateDatabases(true);
3011 gLMSRespawn := LMS_RESPAWN_NONE;
3012 gLMSRespawnTime := 0;
3013 gSpectLatchPID1 := 0;
3014 gSpectLatchPID2 := 0;
3016 // Стартуем клиент
3017 if not g_Net_Connect(Addr, Port) then
3018 begin
3019 g_FatalError(_lc[I_NET_MSG] + _lc[I_NET_ERR_CONN]);
3020 NetState := NET_STATE_NONE;
3021 Exit;
3022 end;
3024 g_Game_SetLoadingText(_lc[I_LOAD_SEND_INFO], 0, False);
3025 MC_SEND_Info(PW);
3026 g_Game_SetLoadingText(_lc[I_LOAD_WAIT_INFO], 0, False);
3028 OuterLoop := True;
3029 while OuterLoop do
3030 begin
3031 // fuck! https://www.mail-archive.com/enet-discuss@cubik.org/msg00852.html
3032 // tl;dr: on shitdows, we can get -1 sometimes, and it is *NOT* a failure.
3033 // thank you, enet. let's ignore failures altogether then.
3034 while (enet_host_service(NetHost, @NetEvent, 50) > 0) do
3035 begin
3036 if (NetEvent.kind = ENET_EVENT_TYPE_RECEIVE) then
3037 begin
3038 Ptr := NetEvent.packet^.data;
3039 if not InMsg.Init(Ptr, NetEvent.packet^.dataLength, True) then
3040 begin
3041 enet_packet_destroy(NetEvent.packet);
3042 continue;
3043 end;
3045 InMsg.ReadLongWord(); // skip size
3046 MID := InMsg.ReadByte();
3048 if (MID = NET_MSG_INFO) and (State = 0) then
3049 begin
3050 NetMyID := InMsg.ReadByte();
3051 NetPlrUID1 := InMsg.ReadWord();
3053 WadName := InMsg.ReadString();
3054 Map := InMsg.ReadString();
3056 gWADHash := InMsg.ReadMD5();
3058 gGameSettings.GameMode := InMsg.ReadByte();
3059 gSwitchGameMode := gGameSettings.GameMode;
3060 gGameSettings.ScoreLimit := InMsg.ReadWord();
3061 gGameSettings.TimeLimit := InMsg.ReadWord();
3062 gGameSettings.MaxLives := InMsg.ReadByte();
3063 gGameSettings.Options := InMsg.ReadLongWord();
3064 T := InMsg.ReadLongWord();
3066 //newResPath := g_Res_SearchSameWAD(MapsDir, WadName, gWADHash);
3067 //if newResPath = '' then
3068 begin
3069 //g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
3070 newResPath := g_Res_DownloadMapWAD(ExtractFileName(WadName), gWADHash);
3071 if newResPath = '' then
3072 begin
3073 g_FatalError(_lc[I_NET_ERR_HASH]);
3074 enet_packet_destroy(NetEvent.packet);
3075 NetState := NET_STATE_NONE;
3076 Exit;
3077 end;
3078 e_LogWritefln('using downloaded map wad [%s] for [%s]`', [newResPath, WadName], TMsgType.Notify);
3079 end;
3080 //newResPath := ExtractRelativePath(MapsDir, newResPath);
3083 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
3084 gPlayer1Settings.Color,
3085 gPlayer1Settings.Team, False));
3087 if gPlayer1 = nil then
3088 begin
3089 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]));
3091 enet_packet_destroy(NetEvent.packet);
3092 NetState := NET_STATE_NONE;
3093 Exit;
3094 end;
3096 gPlayer1.Name := gPlayer1Settings.Name;
3097 gPlayer1.WeapSwitchMode := gPlayer1Settings.WeaponSwitch;
3098 gPlayer1.setWeaponPrefs(gPlayer1Settings.WeaponPreferences);
3099 gPlayer1.SwitchToEmpty := gPlayer1Settings.SwitchToEmpty;
3100 gPlayer1.SkipFist := gPlayer1Settings.SkipFist;
3101 gPlayer1.UID := NetPlrUID1;
3102 gPlayer1.Reset(True);
3104 if not g_Game_StartMap(false{asMegawad}, newResPath + ':\' + Map, True) then
3105 begin
3106 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [WadName + ':\' + Map]));
3108 enet_packet_destroy(NetEvent.packet);
3109 NetState := NET_STATE_NONE;
3110 Exit;
3111 end;
3113 gTime := T;
3115 State := 1;
3116 OuterLoop := False;
3117 enet_packet_destroy(NetEvent.packet);
3118 break;
3119 end
3120 else
3121 enet_packet_destroy(NetEvent.packet);
3122 end
3123 else
3124 begin
3125 if (NetEvent.kind = ENET_EVENT_TYPE_DISCONNECT) then
3126 begin
3127 State := 0;
3128 if (NetEvent.data <= NET_DISC_MAX) then
3129 g_Console_Add(_lc[I_NET_MSG_ERROR] + _lc[I_NET_ERR_CONN] + ' ' +
3130 _lc[TStrings_Locale(Cardinal(I_NET_DISC_NONE) + NetEvent.data)], True);
3131 OuterLoop := False;
3132 Break;
3133 end;
3134 end;
3135 end;
3137 ProcessLoading(True);
3138 if g_Net_UserRequestExit() then
3139 begin
3140 State := 0;
3141 break;
3142 end;
3143 end;
3145 if State <> 1 then
3146 begin
3147 g_FatalError(_lc[I_NET_MSG] + _lc[I_NET_ERR_CONN]);
3148 NetState := NET_STATE_NONE;
3149 Exit;
3150 end;
3152 g_Player_Init();
3153 NetState := NET_STATE_GAME;
3154 MC_SEND_FullStateRequest;
3155 e_WriteLog('NET: Connection successful.', TMsgType.Notify);
3156 end;
3158 var
3159 lastAsMegaWad: Boolean = false;
3161 procedure g_Game_ChangeMap(const MapPath: String);
3162 var
3163 Force: Boolean;
3164 begin
3165 g_Game_ClearLoading();
3167 Force := gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF];
3168 // Если уровень завершился по триггеру Выход, не очищать инвентарь
3169 if gExitByTrigger then
3170 begin
3171 Force := False;
3172 gExitByTrigger := False;
3173 end;
3174 if not g_Game_StartMap(lastAsMegaWad, MapPath, Force) then
3175 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [MapPath]));
3176 end;
3178 procedure g_Game_Restart();
3179 var
3180 Map: string;
3181 begin
3182 if g_Game_IsClient then
3183 Exit;
3184 map := g_ExtractFileName(gMapInfo.Map);
3185 e_LogWritefln('g_Game_Restart: map = "%s" gCurrentMapFileName = "%s"', [map, gCurrentMapFileName]);
3187 MessageTime := 0;
3188 gGameOn := False;
3189 g_Game_ClearLoading();
3190 g_Game_StartMap(lastAsMegaWad, Map, True, gCurrentMapFileName);
3191 end;
3193 function g_Game_StartMap (asMegawad: Boolean; Map: String; Force: Boolean = False; const oldMapPath: AnsiString=''): Boolean;
3194 var
3195 NewWAD, ResName: String;
3196 I: Integer;
3197 nws: AnsiString;
3198 begin
3199 g_Map_Free((Map <> gCurrentMapFileName) and (oldMapPath <> gCurrentMapFileName));
3200 g_Player_RemoveAllCorpses();
3202 if (not g_Game_IsClient) and
3203 (gSwitchGameMode <> gGameSettings.GameMode) and
3204 (gGameSettings.GameMode <> GM_SINGLE) then
3205 begin
3206 if gSwitchGameMode = GM_CTF then
3207 gGameSettings.MaxLives := 0;
3208 gGameSettings.GameMode := gSwitchGameMode;
3209 Force := True;
3210 end else
3211 gSwitchGameMode := gGameSettings.GameMode;
3213 g_Player_ResetTeams();
3215 lastAsMegaWad := asMegawad;
3216 if isWadPath(Map) then
3217 begin
3218 NewWAD := g_ExtractWadName(Map);
3219 ResName := g_ExtractFileName(Map);
3220 if g_Game_IsServer then
3221 begin
3222 nws := findDiskWad(NewWAD);
3223 //writeln('000: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
3224 if (asMegawad) then
3225 begin
3226 if (length(nws) = 0) then nws := e_FindWad(MegawadDirs, NewWAD);
3227 if (length(nws) = 0) then nws := e_FindWad(MapDirs, NewWAD);
3228 end
3229 else
3230 begin
3231 if (length(nws) = 0) then nws := e_FindWad(MapDirs, NewWAD);
3232 if (length(nws) = 0) then nws := e_FindWad(MegawadDirs, NewWAD);
3233 end;
3234 //if (length(nws) = 0) then nws := e_FindWad(MapDownloadDirs, NewWAD);
3235 //writeln('001: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
3236 //nws := NewWAD;
3237 if (length(nws) = 0) then
3238 begin
3239 ResName := ''; // failed
3240 end
3241 else
3242 begin
3243 NewWAD := nws;
3244 if (g_Game_IsNet) then gWADHash := MD5File(nws);
3245 //writeln('********: nws=', nws, ' : Map=', Map, ' : nw=', NewWAD, ' : resname=', ResName);
3246 g_Game_LoadWAD(NewWAD);
3247 end;
3248 end
3249 else
3250 begin
3251 // hash received in MC_RECV_GameEvent -> NET_EV_MAPSTART
3252 NewWAD := g_Game_ClientWAD(NewWAD, gWADHash);
3253 end;
3254 end
3255 else
3256 begin
3257 NewWAD := gGameSettings.WAD;
3258 ResName := Map;
3259 end;
3261 gTime := 0;
3263 //writeln('********: gsw=', gGameSettings.WAD, '; rn=', ResName);
3264 result := false;
3265 if (ResName <> '') and (NewWAD <> '') then
3266 begin
3267 //result := g_Map_Load(gGameSettings.WAD + ':\' + ResName);
3268 result := g_Map_Load(NewWAD+':\'+ResName);
3269 end;
3270 if Result then
3271 begin
3272 g_Player_ResetAll(Force or gLastMap, gGameSettings.GameType = GT_SINGLE);
3274 gState := STATE_NONE;
3275 g_ActiveWindow := nil;
3276 gGameOn := True;
3278 DisableCheats();
3279 ResetTimer();
3281 if gGameSettings.GameMode = GM_CTF then
3282 begin
3283 g_Map_ResetFlag(FLAG_RED);
3284 g_Map_ResetFlag(FLAG_BLUE);
3285 // CTF, а флагов нет:
3286 if not g_Map_HaveFlagPoints() then
3287 g_SimpleError(_lc[I_GAME_ERROR_CTF]);
3288 end;
3289 end
3290 else
3291 begin
3292 gState := STATE_MENU;
3293 gGameOn := False;
3294 end;
3296 gExit := 0;
3297 gPauseMain := false;
3298 gPauseHolmes := false;
3299 NetTimeToUpdate := 1;
3300 NetTimeToReliable := 0;
3301 NetTimeToMaster := NetMasterRate;
3302 gSpectLatchPID1 := 0;
3303 gSpectLatchPID2 := 0;
3304 gMissionFailed := False;
3305 gNextMap := '';
3307 gCoopMonstersKilled := 0;
3308 gCoopSecretsFound := 0;
3310 gVoteInProgress := False;
3311 gVotePassed := False;
3312 gVoteCount := 0;
3313 gVoted := False;
3315 gStatsOff := False;
3317 if not gGameOn then Exit;
3319 g_Game_SpectateCenterView();
3321 if g_Game_IsServer then
3322 begin
3323 if (gGameSettings.MaxLives > 0) and (gGameSettings.WarmupTime > 0) then
3324 begin
3325 gLMSRespawn := LMS_RESPAWN_WARMUP;
3326 gLMSRespawnTime := gTime + gGameSettings.WarmupTime*1000;
3327 gLMSSoftSpawn := True;
3328 if g_Game_IsNet then
3329 MH_SEND_GameEvent(NET_EV_LMS_WARMUP, gLMSRespawnTime - gTime);
3330 end
3331 else
3332 begin
3333 gLMSRespawn := LMS_RESPAWN_NONE;
3334 gLMSRespawnTime := 0;
3335 end;
3336 end;
3338 if NetMode = NET_SERVER then
3339 begin
3340 // reset full state flags
3341 if NetClients <> nil then
3342 for I := 0 to High(NetClients) do
3343 NetClients[I].FullUpdateSent := False;
3345 MH_SEND_GameEvent(NET_EV_MAPSTART, gGameSettings.GameMode, Map);
3347 // Мастерсервер
3348 g_Net_Slist_ServerMapStarted();
3350 if NetClients <> nil then
3351 for I := 0 to High(NetClients) do
3352 if NetClients[I].Used then
3353 begin
3354 NetClients[I].Voted := False;
3355 if NetClients[I].RequestedFullUpdate then
3356 begin
3357 MH_SEND_Everything((NetClients[I].State = NET_STATE_AUTH), I);
3358 NetClients[I].RequestedFullUpdate := False;
3359 end;
3360 end;
3362 g_Net_UnbanNonPermHosts();
3363 end;
3365 if gLastMap then
3366 begin
3367 gCoopTotalMonstersKilled := 0;
3368 gCoopTotalSecretsFound := 0;
3369 gCoopTotalMonsters := 0;
3370 gCoopTotalSecrets := 0;
3371 gLastMap := False;
3372 end;
3374 g_Game_ExecuteEvent('onmapstart');
3375 end;
3377 procedure SetFirstLevel;
3378 begin
3379 gNextMap := '';
3381 MapList := g_Map_GetMapsList(gGameSettings.WAD);
3382 if MapList = nil then
3383 Exit;
3385 SortSArray(MapList);
3386 gNextMap := MapList[Low(MapList)];
3388 MapList := nil;
3389 end;
3391 procedure g_Game_ExitLevel(const Map: AnsiString);
3392 begin
3393 gNextMap := Map;
3395 gCoopTotalMonstersKilled := gCoopTotalMonstersKilled + gCoopMonstersKilled;
3396 gCoopTotalSecretsFound := gCoopTotalSecretsFound + gCoopSecretsFound;
3397 gCoopTotalMonsters := gCoopTotalMonsters + gTotalMonsters;
3398 gCoopTotalSecrets := gCoopTotalSecrets + gSecretsCount;
3400 // Вышли в выход в Одиночной игре:
3401 if gGameSettings.GameType = GT_SINGLE then
3402 gExit := EXIT_ENDLEVELSINGLE
3403 else // Вышли в выход в Своей игре
3404 begin
3405 gExit := EXIT_ENDLEVELCUSTOM;
3406 if gGameSettings.GameMode = GM_COOP then
3407 g_Player_RememberAll;
3409 if not g_Map_Exist(gGameSettings.WAD + ':\' + gNextMap) then
3410 begin
3411 gLastMap := True;
3412 if gGameSettings.GameMode = GM_COOP then
3413 gStatsOff := True;
3415 gStatsPressed := True;
3416 gNextMap := 'MAP01';
3418 if not g_Map_Exist(gGameSettings.WAD + ':\' + gNextMap) then
3419 g_Game_NextLevel;
3421 if g_Game_IsNet then
3422 begin
3423 MH_SEND_GameStats();
3424 MH_SEND_CoopStats();
3425 end;
3426 end;
3427 end;
3428 end;
3430 procedure g_Game_RestartLevel();
3431 var
3432 Map: string;
3433 begin
3434 if gGameSettings.GameMode = GM_SINGLE then
3435 begin
3436 g_Game_Restart();
3437 Exit;
3438 end;
3439 gExit := EXIT_ENDLEVELCUSTOM;
3440 Map := g_ExtractFileName(gMapInfo.Map);
3441 gNextMap := Map;
3442 end;
3444 function g_Game_ClientWAD (NewWAD: String; const WHash: TMD5Digest): AnsiString;
3445 var
3446 gWAD{, xwad}: String;
3447 begin
3448 result := NewWAD;
3449 if not g_Game_IsClient then Exit;
3450 //e_LogWritefln('*** g_Game_ClientWAD: `%s`', [NewWAD]);
3452 gWAD := g_Res_DownloadMapWAD(ExtractFileName(NewWAD), WHash);
3453 if gWAD = '' then
3454 begin
3455 result := '';
3456 g_Game_Free();
3457 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_WAD], [ExtractFileName(NewWAD)]));
3458 Exit;
3459 end;
3461 e_LogWritefln('using downloaded client map wad [%s] for [%s]', [gWAD, NewWAD], TMsgType.Notify);
3462 NewWAD := gWAD;
3464 g_Game_LoadWAD(NewWAD);
3465 result := NewWAD;
3468 if LowerCase(NewWAD) = LowerCase(gGameSettings.WAD) then Exit;
3469 gWAD := g_Res_SearchSameWAD(MapsDir, ExtractFileName(NewWAD), WHash);
3470 if gWAD = '' then
3471 begin
3472 g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
3473 gWAD := g_Res_DownloadMapWAD(ExtractFileName(NewWAD), WHash);
3474 if gWAD = '' then
3475 begin
3476 g_Game_Free();
3477 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_WAD], [ExtractFileName(NewWAD)]));
3478 Exit;
3479 end;
3480 end;
3481 NewWAD := ExtractRelativePath(MapsDir, gWAD);
3482 g_Game_LoadWAD(NewWAD);
3484 end;
3486 procedure g_Game_RestartRound(NoMapRestart: Boolean = False);
3487 var
3488 i, n, nb, nr: Integer;
3489 begin
3490 if not g_Game_IsServer then Exit;
3491 if gLMSRespawn = LMS_RESPAWN_NONE then Exit;
3492 gLMSRespawn := LMS_RESPAWN_NONE;
3493 gLMSRespawnTime := 0;
3494 MessageTime := 0;
3496 if (gGameSettings.GameMode = GM_COOP) and not NoMapRestart then
3497 begin
3498 gMissionFailed := True;
3499 g_Game_RestartLevel;
3500 Exit;
3501 end;
3503 n := 0; nb := 0; nr := 0;
3504 for i := Low(gPlayers) to High(gPlayers) do
3505 if (gPlayers[i] <> nil) and
3506 ((not gPlayers[i].FSpectator) or gPlayers[i].FWantsInGame or
3507 (gPlayers[i] is TBot)) then
3508 begin
3509 Inc(n);
3510 if gPlayers[i].Team = TEAM_RED then Inc(nr)
3511 else if gPlayers[i].Team = TEAM_BLUE then Inc(nb)
3512 end;
3514 if (n < 1) or ((gGameSettings.GameMode = GM_TDM) and ((nr = 0) or (nb = 0))) then
3515 begin
3516 // wait a second until the fuckers finally decide to join
3517 gLMSRespawn := LMS_RESPAWN_WARMUP;
3518 gLMSRespawnTime := gTime + gGameSettings.WarmupTime*1000;
3519 gLMSSoftSpawn := NoMapRestart;
3520 if g_Game_IsNet then
3521 MH_SEND_GameEvent(NET_EV_LMS_WARMUP, gLMSRespawnTime - gTime);
3522 Exit;
3523 end;
3525 g_Player_RemoveAllCorpses;
3526 g_Game_Message(_lc[I_MESSAGE_LMS_START], 144);
3527 if g_Game_IsNet then
3528 MH_SEND_GameEvent(NET_EV_LMS_START);
3530 for i := Low(gPlayers) to High(gPlayers) do
3531 begin
3532 if gPlayers[i] = nil then continue;
3533 if gPlayers[i] is TBot then gPlayers[i].FWantsInGame := True;
3534 // don't touch normal spectators
3535 if gPlayers[i].FSpectator and not gPlayers[i].FWantsInGame then
3536 begin
3537 gPlayers[i].FNoRespawn := True;
3538 gPlayers[i].Lives := 0;
3539 if g_Game_IsNet then
3540 MH_SEND_PlayerStats(gPlayers[I].UID);
3541 continue;
3542 end;
3543 gPlayers[i].FNoRespawn := False;
3544 gPlayers[i].Lives := gGameSettings.MaxLives;
3545 gPlayers[i].Respawn(False, True);
3546 if gGameSettings.GameMode = GM_COOP then
3547 begin
3548 gPlayers[i].Frags := 0;
3549 gPlayers[i].RecallState;
3550 end;
3551 if (gPlayer1 = nil) and (gSpectLatchPID1 > 0) then
3552 gPlayer1 := g_Player_Get(gSpectLatchPID1);
3553 if (gPlayer2 = nil) and (gSpectLatchPID2 > 0) then
3554 gPlayer2 := g_Player_Get(gSpectLatchPID2);
3555 end;
3557 g_Items_RestartRound();
3559 gLMSSoftSpawn := False;
3560 end;
3562 function g_Game_GetFirstMap(WAD: String): String;
3563 begin
3564 Result := '';
3566 MapList := g_Map_GetMapsList(WAD);
3567 if MapList = nil then
3568 Exit;
3570 SortSArray(MapList);
3571 Result := MapList[Low(MapList)];
3573 if not g_Map_Exist(WAD + ':\' + Result) then
3574 Result := '';
3576 MapList := nil;
3577 end;
3579 function g_Game_GetNextMap(): String;
3580 var
3581 I: Integer;
3582 Map: string;
3583 begin
3584 Result := '';
3586 MapList := g_Map_GetMapsList(gGameSettings.WAD);
3587 if MapList = nil then
3588 Exit;
3590 Map := g_ExtractFileName(gMapInfo.Map);
3592 SortSArray(MapList);
3593 MapIndex := -255;
3594 for I := Low(MapList) to High(MapList) do
3595 if Map = MapList[I] then
3596 begin
3597 MapIndex := I;
3598 Break;
3599 end;
3601 if MapIndex <> -255 then
3602 begin
3603 if MapIndex = High(MapList) then
3604 Result := MapList[Low(MapList)]
3605 else
3606 Result := MapList[MapIndex + 1];
3608 if not g_Map_Exist(gGameSettings.WAD + ':\' + Result) then Result := Map;
3609 end;
3611 MapList := nil;
3612 end;
3614 procedure g_Game_NextLevel();
3615 begin
3616 if gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF, GM_COOP] then
3617 gExit := EXIT_ENDLEVELCUSTOM
3618 else
3619 begin
3620 gExit := EXIT_ENDLEVELSINGLE;
3621 Exit;
3622 end;
3624 if gNextMap <> '' then Exit;
3625 gNextMap := g_Game_GetNextMap();
3626 end;
3628 function g_Game_IsTestMap(): Boolean;
3629 begin
3630 result := StrEquCI1251(TEST_MAP_NAME, g_ExtractFileName(gMapInfo.Map));
3631 end;
3633 procedure g_Game_DeleteTestMap();
3634 var
3635 a: Integer;
3636 //MapName: AnsiString;
3637 WadName: string;
3639 WAD: TWADFile;
3640 MapList: SSArray;
3641 time: Integer;
3643 begin
3644 a := Pos('.wad:\', toLowerCase1251(gMapToDelete));
3645 if (a = 0) then a := Pos('.wad:/', toLowerCase1251(gMapToDelete));
3646 if (a = 0) then exit;
3648 // Выделяем имя wad-файла и имя карты
3649 WadName := Copy(gMapToDelete, 1, a+3);
3650 Delete(gMapToDelete, 1, a+5);
3651 gMapToDelete := UpperCase(gMapToDelete);
3652 //MapName := '';
3653 //CopyMemory(@MapName[0], @gMapToDelete[1], Min(16, Length(gMapToDelete)));
3656 // Имя карты не стандартное тестовое:
3657 if MapName <> TEST_MAP_NAME then
3658 Exit;
3660 if not gTempDelete then
3661 begin
3662 time := g_GetFileTime(WadName);
3663 WAD := TWADFile.Create();
3665 // Читаем Wad-файл:
3666 if not WAD.ReadFile(WadName) then
3667 begin // Нет такого WAD-файла
3668 WAD.Free();
3669 Exit;
3670 end;
3672 // Составляем список карт и ищем нужную:
3673 WAD.CreateImage();
3674 MapList := WAD.GetResourcesList('');
3676 if MapList <> nil then
3677 for a := 0 to High(MapList) do
3678 if MapList[a] = MapName then
3679 begin
3680 // Удаляем и сохраняем:
3681 WAD.RemoveResource('', MapName);
3682 WAD.SaveTo(WadName);
3683 Break;
3684 end;
3686 WAD.Free();
3687 g_SetFileTime(WadName, time);
3688 end else
3690 if gTempDelete then DeleteFile(WadName);
3691 end;
3693 procedure GameCVars(P: SSArray);
3694 var
3695 a, b: Integer;
3696 stat: TPlayerStatArray;
3697 cmd: string;
3699 procedure ParseGameFlag(Flag: LongWord; OffMsg, OnMsg: TStrings_Locale; OnMapChange: Boolean = False);
3700 var
3701 x: Boolean;
3702 begin
3703 if Length(P) > 1 then
3704 begin
3705 x := P[1] = '1';
3707 if x then
3708 gsGameFlags := gsGameFlags or Flag
3709 else
3710 gsGameFlags := gsGameFlags and (not Flag);
3712 if g_Game_IsServer then
3713 begin
3714 if x then
3715 gGameSettings.Options := gGameSettings.Options or Flag
3716 else
3717 gGameSettings.Options := gGameSettings.Options and (not Flag);
3718 if g_Game_IsNet then MH_SEND_GameSettings;
3719 end;
3720 end;
3722 if LongBool(gsGameFlags and Flag) then
3723 g_Console_Add(_lc[OnMsg])
3724 else
3725 g_Console_Add(_lc[OffMsg]);
3727 if OnMapChange and g_Game_IsServer then
3728 g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
3729 end;
3731 begin
3732 stat := nil;
3733 cmd := LowerCase(P[0]);
3735 if cmd = 'g_gamemode' then
3736 begin
3737 if (Length(P) > 1) then
3738 begin
3739 a := g_Game_TextToMode(P[1]);
3740 if a = GM_SINGLE then a := GM_COOP;
3741 gsGameMode := g_Game_ModeToText(a);
3742 if g_Game_IsServer then
3743 begin
3744 gSwitchGameMode := a;
3745 if (gGameOn and (gGameSettings.GameMode = GM_SINGLE)) or
3746 (gState = STATE_INTERSINGLE) then
3747 gSwitchGameMode := GM_SINGLE;
3748 if not gGameOn then
3749 gGameSettings.GameMode := gSwitchGameMode;
3750 end;
3751 end;
3753 if gSwitchGameMode = gGameSettings.GameMode then
3754 g_Console_Add(Format(_lc[I_MSG_GAMEMODE_CURRENT],
3755 [g_Game_ModeToText(gGameSettings.GameMode)]))
3756 else
3757 g_Console_Add(Format(_lc[I_MSG_GAMEMODE_CHANGE],
3758 [g_Game_ModeToText(gGameSettings.GameMode),
3759 g_Game_ModeToText(gSwitchGameMode)]));
3760 end
3761 else if cmd = 'g_friendlyfire' then
3762 begin
3763 ParseGameFlag(GAME_OPTION_TEAMDAMAGE, I_MSG_FRIENDLY_FIRE_OFF, I_MSG_FRIENDLY_FIRE_ON);
3764 end
3765 else if cmd = 'g_friendly_absorb_damage' then
3766 begin
3767 ParseGameFlag(GAME_OPTION_TEAMABSORBDAMAGE, I_MSG_FRIENDLY_ABSORB_DAMAGE_OFF, I_MSG_FRIENDLY_ABSORB_DAMAGE_ON);
3768 end
3769 else if cmd = 'g_friendly_hit_trace' then
3770 begin
3771 ParseGameFlag(GAME_OPTION_TEAMHITTRACE, I_MSG_FRIENDLY_HIT_TRACE_OFF, I_MSG_FRIENDLY_HIT_TRACE_ON);
3772 end
3773 else if cmd = 'g_friendly_hit_projectile' then
3774 begin
3775 ParseGameFlag(GAME_OPTION_TEAMHITPROJECTILE, I_MSG_FRIENDLY_PROJECT_TRACE_OFF, I_MSG_FRIENDLY_PROJECT_TRACE_ON);
3776 end
3777 else if cmd = 'g_weaponstay' then
3778 begin
3779 ParseGameFlag(GAME_OPTION_WEAPONSTAY, I_MSG_WEAPONSTAY_OFF, I_MSG_WEAPONSTAY_ON);
3780 end
3781 else if cmd = 'g_allow_exit' then
3782 begin
3783 ParseGameFlag(GAME_OPTION_ALLOWEXIT, I_MSG_ALLOWEXIT_OFF, I_MSG_ALLOWEXIT_ON, True);
3784 end
3785 else if cmd = 'g_allow_monsters' then
3786 begin
3787 ParseGameFlag(GAME_OPTION_MONSTERS, I_MSG_ALLOWMON_OFF, I_MSG_ALLOWMON_ON, True);
3788 end
3789 else if cmd = 'g_allow_dropflag' then
3790 begin
3791 ParseGameFlag(GAME_OPTION_ALLOWDROPFLAG, I_MSG_ALLOWDROPFLAG_OFF, I_MSG_ALLOWDROPFLAG_ON);
3792 end
3793 else if cmd = 'g_throw_flag' then
3794 begin
3795 ParseGameFlag(GAME_OPTION_THROWFLAG, I_MSG_THROWFLAG_OFF, I_MSG_THROWFLAG_ON);
3796 end
3797 else if cmd = 'g_bot_vsplayers' then
3798 begin
3799 ParseGameFlag(GAME_OPTION_BOTVSPLAYER, I_MSG_BOTSVSPLAYERS_OFF, I_MSG_BOTSVSPLAYERS_ON);
3800 end
3801 else if cmd = 'g_bot_vsmonsters' then
3802 begin
3803 ParseGameFlag(GAME_OPTION_BOTVSMONSTER, I_MSG_BOTSVSMONSTERS_OFF, I_MSG_BOTSVSMONSTERS_ON);
3804 end
3805 else if cmd = 'g_dm_keys' then
3806 begin
3807 ParseGameFlag(GAME_OPTION_DMKEYS, I_MSG_DMKEYS_OFF, I_MSG_DMKEYS_ON, True);
3808 end
3809 else if cmd = 'g_gameflags' then
3810 begin
3811 if Length(P) > 1 then
3812 begin
3813 gsGameFlags := StrToDWordDef(P[1], gsGameFlags);
3814 if g_Game_IsServer then
3815 begin
3816 gGameSettings.Options := gsGameFlags;
3817 if g_Game_IsNet then MH_SEND_GameSettings;
3818 end;
3819 end;
3821 g_Console_Add(Format('%s %u', [cmd, gsGameFlags]));
3822 end
3823 else if cmd = 'g_warmup_time' then
3824 begin
3825 if Length(P) > 1 then
3826 begin
3827 gsWarmupTime := nclamp(StrToIntDef(P[1], gsWarmupTime), 0, $FFFF);
3828 if g_Game_IsServer then
3829 begin
3830 gGameSettings.WarmupTime := gsWarmupTime;
3831 // extend warmup if it's already going
3832 if gLMSRespawn = LMS_RESPAWN_WARMUP then
3833 begin
3834 gLMSRespawnTime := gTime + gsWarmupTime * 1000;
3835 if g_Game_IsNet then MH_SEND_GameEvent(NET_EV_LMS_WARMUP, gLMSRespawnTime - gTime);
3836 end;
3837 if g_Game_IsNet then MH_SEND_GameSettings;
3838 end;
3839 end;
3841 g_Console_Add(Format(_lc[I_MSG_WARMUP], [Integer(gsWarmupTime)]));
3842 if g_Game_IsServer then g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
3843 end
3844 else if cmd = 'g_spawn_invul' then
3845 begin
3846 if Length(P) > 1 then
3847 begin
3848 gsSpawnInvul := nclamp(StrToIntDef(P[1], gsSpawnInvul), 0, $FFFF);
3849 if g_Game_IsServer then
3850 begin
3851 gGameSettings.SpawnInvul := gsSpawnInvul;
3852 if g_Game_IsNet then MH_SEND_GameSettings;
3853 end;
3854 end;
3856 g_Console_Add(Format('%s %d', [cmd, Integer(gsSpawnInvul)]));
3857 end
3858 else if cmd = 'g_item_respawn_time' then
3859 begin
3860 if Length(P) > 1 then
3861 begin
3862 gsItemRespawnTime := nclamp(StrToIntDef(P[1], gsItemRespawnTime), 0, $FFFF);
3863 if g_Game_IsServer then
3864 begin
3865 gGameSettings.ItemRespawnTime := gsItemRespawnTime;
3866 if g_Game_IsNet then MH_SEND_GameSettings;
3867 end;
3868 end;
3870 g_Console_Add(Format('%s %d', [cmd, Integer(gsItemRespawnTime)]));
3871 if g_Game_IsServer then g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
3872 end
3873 else if cmd = 'sv_intertime' then
3874 begin
3875 if (Length(P) > 1) then
3876 gDefInterTime := Min(Max(StrToIntDef(P[1], gDefInterTime), -1), 120);
3878 g_Console_Add(cmd + ' = ' + IntToStr(gDefInterTime));
3879 end
3880 else if cmd = 'g_max_particles' then
3881 begin
3882 if Length(p) = 2 then
3883 begin
3884 a := Max(0, StrToIntDef(p[1], 0));
3885 g_GFX_SetMax(a)
3886 end
3887 else if Length(p) = 1 then
3888 begin
3889 e_LogWritefln('%s', [g_GFX_GetMax()])
3890 end
3891 else
3892 begin
3893 e_LogWritefln('usage: %s <n>', [cmd])
3894 end
3895 end
3896 else if cmd = 'g_max_shells' then
3897 begin
3898 if Length(p) = 2 then
3899 begin
3900 a := Max(0, StrToIntDef(p[1], 0));
3901 g_Shells_SetMax(a)
3902 end
3903 else if Length(p) = 1 then
3904 begin
3905 e_LogWritefln('%s', [g_Shells_GetMax()])
3906 end
3907 else
3908 begin
3909 e_LogWritefln('usage: %s <n>', [cmd])
3910 end
3911 end
3912 else if cmd = 'g_max_gibs' then
3913 begin
3914 if Length(p) = 2 then
3915 begin
3916 a := Max(0, StrToIntDef(p[1], 0));
3917 g_Gibs_SetMax(a)
3918 end
3919 else if Length(p) = 1 then
3920 begin
3921 e_LogWritefln('%s', [g_Gibs_GetMax()])
3922 end
3923 else
3924 begin
3925 e_LogWritefln('usage: %s <n>', [cmd])
3926 end
3927 end
3928 else if cmd = 'g_max_corpses' then
3929 begin
3930 if Length(p) = 2 then
3931 begin
3932 a := Max(0, StrToIntDef(p[1], 0));
3933 g_Corpses_SetMax(a)
3934 end
3935 else if Length(p) = 1 then
3936 begin
3937 e_LogWritefln('%s', [g_Corpses_GetMax()])
3938 end
3939 else
3940 begin
3941 e_LogWritefln('usage: %s <n>', [cmd])
3942 end
3943 end
3944 else if cmd = 'g_force_model' then
3945 begin
3946 if Length(p) = 2 then
3947 begin
3948 a := StrToIntDef(p[1], 0);
3949 g_Force_Model_Set(a);
3950 if (g_Force_Model_Get() <> 0) and (gPlayers <> nil) then
3951 begin
3952 for a := Low(gPlayers) to High(gPlayers) do
3953 begin
3954 if (gPlayers[a] <> nil) then
3955 begin
3956 if (gPlayers[a].UID = gPlayer1.UID) then
3957 continue
3958 else if (gPlayer2 <> nil) and (gPlayers[a].UID = gPlayer2.UID) then
3959 continue;
3960 gPlayers[a].setModel(g_Forced_Model_GetName());
3961 end;
3962 end
3963 end
3964 else if (g_Force_Model_Get() = 0) and (gPlayers <> nil) then
3965 begin
3966 for a := Low(gPlayers) to High(gPlayers) do
3967 begin
3968 if (gPlayers[a] <> nil) then
3969 begin
3970 if (gPlayers[a].UID = gPlayer1.UID) then
3971 continue
3972 else if (gPlayer2 <> nil) and (gPlayers[a].UID = gPlayer2.UID) then
3973 continue;
3974 gPlayers[a].setModel(gPlayers[a].FActualModelName);
3975 end;
3976 end
3977 end
3978 end
3979 end
3980 else if cmd = 'g_force_model_name' then
3981 begin
3982 if (Length(P) > 1) then
3983 begin
3984 cmd := b_Text_Unformat(P[1]);
3985 g_Forced_Model_SetName(cmd);
3986 if (g_Force_Model_Get() <> 0) and (gPlayers <> nil) then
3987 begin
3988 for a := Low(gPlayers) to High(gPlayers) do
3989 begin
3990 if (gPlayers[a] <> nil) then
3991 begin
3992 if (gPlayers[a].UID = gPlayer1.UID) then
3993 continue
3994 else if (gPlayer2 <> nil) and (gPlayers[a].UID = gPlayer2.UID) then
3995 continue;
3996 gPlayers[a].setModel(g_Forced_Model_GetName());
3997 end;
3998 end
3999 end
4000 end
4001 end
4002 else if cmd = 'g_scorelimit' then
4003 begin
4004 if Length(P) > 1 then
4005 begin
4006 gsScoreLimit := nclamp(StrToIntDef(P[1], gsScoreLimit), 0, $FFFF);
4008 if g_Game_IsServer then
4009 begin
4010 b := 0;
4011 if gGameSettings.GameMode = GM_DM then
4012 begin // DM
4013 stat := g_Player_GetStats();
4014 if stat <> nil then
4015 for a := 0 to High(stat) do
4016 if stat[a].Frags > b then
4017 b := stat[a].Frags;
4018 end
4019 else // TDM/CTF
4020 b := Max(gTeamStat[TEAM_RED].Score, gTeamStat[TEAM_BLUE].Score);
4022 // if someone has a higher score, set it to that instead
4023 gsScoreLimit := max(gsScoreLimit, b);
4024 gGameSettings.ScoreLimit := gsScoreLimit;
4026 if g_Game_IsNet then MH_SEND_GameSettings;
4027 end;
4028 end;
4030 g_Console_Add(Format(_lc[I_MSG_SCORE_LIMIT], [Integer(gsScoreLimit)]));
4031 end
4032 else if cmd = 'g_timelimit' then
4033 begin
4034 if Length(P) > 1 then
4035 begin
4036 gsTimeLimit := nclamp(StrToIntDef(P[1], gsTimeLimit), 0, $FFFF);
4037 if g_Game_IsServer then
4038 begin
4039 gGameSettings.TimeLimit := gsTimeLimit;
4040 if g_Game_IsNet then MH_SEND_GameSettings;
4041 end;
4042 end;
4043 g_Console_Add(Format(_lc[I_MSG_TIME_LIMIT],
4044 [gsTimeLimit div 3600,
4045 (gsTimeLimit div 60) mod 60,
4046 gsTimeLimit mod 60]));
4047 end
4048 else if cmd = 'g_max_bots' then
4049 begin
4050 if Length(P) > 1 then
4051 gMaxBots := nclamp(StrToIntDef(P[1], gMaxBots), 0, 127);
4052 g_Console_Add('g_max_bots = ' + IntToStr(gMaxBots));
4053 end
4054 else if cmd = 'g_maxlives' then
4055 begin
4056 if Length(P) > 1 then
4057 begin
4058 gsMaxLives := nclamp(StrToIntDef(P[1], gsMaxLives), 0, $FFFF);
4059 if g_Game_IsServer then
4060 begin
4061 gGameSettings.MaxLives := gsMaxLives;
4062 if g_Game_IsNet then MH_SEND_GameSettings;
4063 end;
4064 end;
4066 g_Console_Add(Format(_lc[I_MSG_LIVES], [Integer(gsMaxLives)]));
4067 end;
4068 end;
4070 procedure PlayerSettingsCVars(P: SSArray);
4071 var
4072 cmd: string;
4073 team: Byte;
4075 function ParseTeam(s: string): Byte;
4076 begin
4077 result := 0;
4078 case s of
4079 'red', '1': result := TEAM_RED;
4080 'blue', '2': result := TEAM_BLUE;
4081 else result := TEAM_NONE;
4082 end;
4083 end;
4084 begin
4085 cmd := LowerCase(P[0]);
4086 case cmd of
4087 'p1_name':
4088 begin
4089 if (Length(P) > 1) then
4090 begin
4091 gPlayer1Settings.Name := b_Text_Unformat(P[1]);
4092 if g_Game_IsClient then
4093 MC_SEND_PlayerSettings
4094 else if gGameOn and (gPlayer1 <> nil) then
4095 begin
4096 gPlayer1.Name := b_Text_Unformat(P[1]);
4097 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer1.UID);
4098 end;
4099 end;
4100 end;
4101 'p2_name':
4102 begin
4103 if (Length(P) > 1) then
4104 begin
4105 gPlayer2Settings.Name := b_Text_Unformat(P[1]);
4106 if g_Game_IsClient then
4107 MC_SEND_PlayerSettings
4108 else if gGameOn and (gPlayer2 <> nil) then
4109 begin
4110 gPlayer2.Name := b_Text_Unformat(P[1]);
4111 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer2.UID);
4112 end;
4113 end;
4114 end;
4115 'p1_color':
4116 begin
4117 if Length(P) > 3 then
4118 begin
4119 gPlayer1Settings.Color := _RGB(EnsureRange(StrToIntDef(P[1], 0), 0, 255),
4120 EnsureRange(StrToIntDef(P[2], 0), 0, 255),
4121 EnsureRange(StrToIntDef(P[3], 0), 0, 255));
4122 if g_Game_IsClient then
4123 MC_SEND_PlayerSettings
4124 else if gGameOn and (gPlayer1 <> nil) then
4125 begin
4126 gPlayer1.SetColor(gPlayer1Settings.Color);
4127 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer1.UID);
4128 end;
4129 end;
4130 end;
4131 'p2_color':
4132 begin
4133 if Length(P) > 3 then
4134 begin
4135 gPlayer2Settings.Color := _RGB(EnsureRange(StrToIntDef(P[1], 0), 0, 255),
4136 EnsureRange(StrToIntDef(P[2], 0), 0, 255),
4137 EnsureRange(StrToIntDef(P[3], 0), 0, 255));
4138 if g_Game_IsClient then
4139 MC_SEND_PlayerSettings
4140 else if gGameOn and (gPlayer2 <> nil) then
4141 begin
4142 gPlayer2.SetColor(gPlayer2Settings.Color);
4143 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer2.UID);
4144 end;
4145 end;
4146 end;
4147 'p1_model':
4148 begin
4149 if (Length(P) > 1) then
4150 begin
4151 gPlayer1Settings.Model := P[1];
4152 if g_Game_IsClient then
4153 MC_SEND_PlayerSettings
4154 else if gGameOn and (gPlayer1 <> nil) then
4155 begin
4156 gPlayer1.FActualModelName := gPlayer1Settings.Model;
4157 gPlayer1.SetModel(gPlayer1Settings.Model);
4158 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer1.UID);
4159 end;
4160 end;
4161 end;
4162 'p2_model':
4163 begin
4164 if (Length(P) > 1) then
4165 begin
4166 gPlayer2Settings.Model := P[1];
4167 if g_Game_IsClient then
4168 MC_SEND_PlayerSettings
4169 else if gGameOn and (gPlayer2 <> nil) then
4170 begin
4171 gPlayer2.FActualModelName := gPlayer2Settings.Model;
4172 gPlayer2.SetModel(gPlayer2Settings.Model);
4173 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer2.UID);
4174 end;
4175 end;
4176 end;
4177 'p1_team':
4178 begin
4179 // TODO: switch teams if in game or store this separately
4180 if (Length(P) > 1) then
4181 begin
4182 team := ParseTeam(P[1]);
4183 if team = TEAM_NONE then
4184 g_Console_Add('expected ''red'', ''blue'', 1 or 2')
4185 else if not gGameOn and not g_Game_IsNet then
4186 gPlayer1Settings.Team := team
4187 else
4188 g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
4189 end;
4190 end;
4191 'p2_team':
4192 begin
4193 // TODO: switch teams if in game or store this separately
4194 if (Length(P) > 1) then
4195 begin
4196 team := ParseTeam(P[1]);
4197 if team = TEAM_NONE then
4198 g_Console_Add('expected ''red'', ''blue'', 1 or 2')
4199 else if not gGameOn and not g_Game_IsNet then
4200 gPlayer2Settings.Team := team
4201 else
4202 g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
4203 end;
4204 end;
4205 'p1_autoswitch':
4206 begin
4207 if (Length(P) = 2) then
4208 gPlayer1Settings.WeaponSwitch := EnsureRange(StrTointDef(P[1], 0), 0, 2);
4209 end;
4210 'p2_autoswitch':
4211 begin
4212 if (Length(P) = 2) then
4213 gPlayer2Settings.WeaponSwitch := EnsureRange(StrTointDef(P[1], 0), 0, 2);
4214 end;
4215 'p1_switch_empty':
4216 begin
4217 if (Length(P) = 2) then
4218 gPlayer1Settings.SwitchToEmpty := EnsureRange(StrTointDef(P[1], 0), 0, 1);
4219 end;
4220 'p2_switch_empty':
4221 begin
4222 if (Length(P) = 2) then
4223 gPlayer2Settings.SwitchToEmpty := EnsureRange(StrTointDef(P[1], 0), 0, 1);
4224 end;
4225 'p1_skip_fist':
4226 begin
4227 if (Length(P) = 2) then
4228 gPlayer1Settings.SkipFist := EnsureRange(StrTointDef(P[1], 0), 0, 1);
4229 end;
4230 'p2_skip_fist':
4231 begin
4232 if (Length(P) = 2) then
4233 gPlayer2Settings.SkipFist := EnsureRange(StrTointDef(P[1], 0), 0, 1);
4234 end;
4235 'p1_priority_kastet':
4236 begin
4237 if (Length(P) = 2) then
4238 gPlayer1Settings.WeaponPreferences[WEAPON_KASTET] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
4239 end;
4240 'p2_priority_kastet':
4241 begin
4242 if (Length(P) = 2) then
4243 gPlayer2Settings.WeaponPreferences[WEAPON_KASTET] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
4244 end;
4245 'p1_priority_saw':
4246 begin
4247 if (Length(P) = 2) then
4248 gPlayer1Settings.WeaponPreferences[WEAPON_SAW] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
4249 end;
4250 'p2_priority_saw':
4251 begin
4252 if (Length(P) = 2) then
4253 gPlayer2Settings.WeaponPreferences[WEAPON_SAW] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
4254 end;
4255 'p1_priority_pistol':
4256 begin
4257 if (Length(P) = 2) then
4258 gPlayer1Settings.WeaponPreferences[WEAPON_KASTET] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
4259 end;
4260 'p2_priority_pistol':
4261 begin
4262 if (Length(P) = 2) then
4263 gPlayer2Settings.WeaponPreferences[WEAPON_KASTET] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
4264 end;
4265 'p1_priority_shotgun1':
4266 begin
4267 if (Length(P) = 2) then
4268 gPlayer1Settings.WeaponPreferences[WEAPON_SHOTGUN1] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
4269 end;
4270 'p2_priority_shotgun1':
4271 begin
4272 if (Length(P) = 2) then
4273 gPlayer2Settings.WeaponPreferences[WEAPON_SHOTGUN1] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
4274 end;
4275 'p1_priority_shotgun2':
4276 begin
4277 if (Length(P) = 2) then
4278 gPlayer1Settings.WeaponPreferences[WEAPON_SHOTGUN2] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
4279 end;
4280 'p2_priority_shotgun2':
4281 begin
4282 if (Length(P) = 2) then
4283 gPlayer2Settings.WeaponPreferences[WEAPON_SHOTGUN2] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
4284 end;
4285 'p1_priority_chaingun':
4286 begin
4287 if (Length(P) = 2) then
4288 gPlayer1Settings.WeaponPreferences[WEAPON_CHAINGUN] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
4289 end;
4290 'p2_priority_chaingun':
4291 begin
4292 if (Length(P) = 2) then
4293 gPlayer2Settings.WeaponPreferences[WEAPON_CHAINGUN] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
4294 end;
4295 'p1_priority_rocketlauncher':
4296 begin
4297 if (Length(P) = 2) then
4298 gPlayer1Settings.WeaponPreferences[WEAPON_ROCKETLAUNCHER] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
4299 end;
4300 'p2_priority_rocketlauncher':
4301 begin
4302 if (Length(P) = 2) then
4303 gPlayer2Settings.WeaponPreferences[WEAPON_ROCKETLAUNCHER] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
4304 end;
4305 'p1_priority_plasma':
4306 begin
4307 if (Length(P) = 2) then
4308 gPlayer1Settings.WeaponPreferences[WEAPON_PLASMA] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
4309 end;
4310 'p2_priority_plasma':
4311 begin
4312 if (Length(P) = 2) then
4313 gPlayer2Settings.WeaponPreferences[WEAPON_PLASMA] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
4314 end;
4315 'p1_priority_bfg':
4316 begin
4317 if (Length(P) = 2) then
4318 gPlayer1Settings.WeaponPreferences[WEAPON_BFG] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
4319 end;
4320 'p2_priority_bfg':
4321 begin
4322 if (Length(P) = 2) then
4323 gPlayer2Settings.WeaponPreferences[WEAPON_BFG] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
4324 end;
4325 'p1_priority_super':
4326 begin
4327 if (Length(P) = 2) then
4328 gPlayer1Settings.WeaponPreferences[WEAPON_SUPERPULEMET] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
4329 end;
4330 'p2_priority_super':
4331 begin
4332 if (Length(P) = 2) then
4333 gPlayer2Settings.WeaponPreferences[WEAPON_SUPERPULEMET] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
4334 end;
4335 'p1_priority_flamethrower':
4336 begin
4337 if (Length(P) = 2) then
4338 gPlayer1Settings.WeaponPreferences[WEAPON_FLAMETHROWER] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
4339 end;
4340 'p2_priority_flamethrower':
4341 begin
4342 if (Length(P) = 2) then
4343 gPlayer2Settings.WeaponPreferences[WEAPON_FLAMETHROWER] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
4344 end;
4345 'p1_priority_berserk':
4346 begin
4347 if (Length(P) = 2) then
4348 gPlayer1Settings.WeaponPreferences[WP_LAST+1] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
4349 end;
4350 'p2_priority_berserk':
4351 begin
4352 if (Length(P) = 2) then
4353 gPlayer2Settings.WeaponPreferences[WP_LAST+1] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
4354 end;
4355 end;
4356 end;
4358 procedure PrintHeapStats();
4359 var
4360 hs: TFPCHeapStatus;
4361 begin
4362 hs := GetFPCHeapStatus();
4363 e_LogWriteLn ('v===== heap status =====v');
4364 e_LogWriteFln('max heap size = %d k', [hs.MaxHeapSize div 1024]);
4365 e_LogWriteFln('max heap used = %d k', [hs.MaxHeapUsed div 1024]);
4366 e_LogWriteFln('cur heap size = %d k', [hs.CurrHeapSize div 1024]);
4367 e_LogWriteFln('cur heap used = %d k', [hs.CurrHeapUsed div 1024]);
4368 e_LogWriteFln('cur heap free = %d k', [hs.CurrHeapFree div 1024]);
4369 e_LogWriteLn ('^=======================^');
4370 end;
4372 procedure DebugCommands(P: SSArray);
4373 var
4374 a, b: Integer;
4375 cmd: string;
4376 //pt: TDFPoint;
4377 mon: TMonster;
4378 begin
4379 // Команды отладочного режима:
4380 if {gDebugMode}conIsCheatsEnabled then
4381 begin
4382 cmd := LowerCase(P[0]);
4383 if cmd = 'd_window' then
4384 begin
4385 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth, gScreenHeight]));
4386 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth, gScreenHeight]));
4387 end
4388 else if cmd = 'd_sounds' then
4389 begin
4390 if (Length(P) > 1) and
4391 ((P[1] = '1') or (P[1] = '0')) then
4392 g_Debug_Sounds := (P[1][1] = '1');
4394 g_Console_Add(Format('d_sounds is %d', [Byte(g_Debug_Sounds)]));
4395 end
4396 else if cmd = 'd_frames' then
4397 begin
4398 if (Length(P) > 1) and
4399 ((P[1] = '1') or (P[1] = '0')) then
4400 g_Debug_Frames := (P[1][1] = '1');
4402 g_Console_Add(Format('d_frames is %d', [Byte(g_Debug_Frames)]));
4403 end
4404 else if cmd = 'd_winmsg' then
4405 begin
4406 if (Length(P) > 1) and
4407 ((P[1] = '1') or (P[1] = '0')) then
4408 g_Debug_WinMsgs := (P[1][1] = '1');
4410 g_Console_Add(Format('d_winmsg is %d', [Byte(g_Debug_WinMsgs)]));
4411 end
4412 else if (cmd = 'd_monoff') and not g_Game_IsNet then
4413 begin
4414 if (Length(P) > 1) and
4415 ((P[1] = '1') or (P[1] = '0')) then
4416 g_Debug_MonsterOff := (P[1][1] = '1');
4418 g_Console_Add(Format('d_monoff is %d', [Byte(g_debug_MonsterOff)]));
4419 end
4420 else if (cmd = 'd_botoff') and not g_Game_IsNet then
4421 begin
4422 if Length(P) > 1 then
4423 case P[1][1] of
4424 '0': g_debug_BotAIOff := 0;
4425 '1': g_debug_BotAIOff := 1;
4426 '2': g_debug_BotAIOff := 2;
4427 '3': g_debug_BotAIOff := 3;
4428 end;
4430 g_Console_Add(Format('d_botoff is %d', [g_debug_BotAIOff]));
4431 end
4432 else if cmd = 'd_monster' then
4433 begin
4434 if gGameOn and (gPlayer1 <> nil) and (gPlayer1.alive) and (not g_Game_IsNet) then
4435 if Length(P) < 2 then
4436 begin
4437 g_Console_Add(cmd + ' [ID | Name] [behaviour]');
4438 g_Console_Add('ID | Name');
4439 for b := MONSTER_DEMON to MONSTER_MAN do
4440 g_Console_Add(Format('%2d | %s', [b, g_Mons_NameByTypeId(b)]));
4441 conwriteln('behav. num'#10'normal 0'#10'killer 1'#10'maniac 2'#10'insane 3'#10'cannibal 4'#10'good 5');
4442 end else
4443 begin
4444 a := StrToIntDef(P[1], 0);
4445 if (a < MONSTER_DEMON) or (a > MONSTER_MAN) then
4446 a := g_Mons_TypeIdByName(P[1]);
4448 if (a < MONSTER_DEMON) or (a > MONSTER_MAN) then
4449 g_Console_Add(Format(_lc[I_MSG_NO_MONSTER], [P[1]]))
4450 else
4451 begin
4452 with gPlayer1.Obj do
4453 begin
4454 mon := g_Monsters_Create(a,
4455 X + Rect.X + (Rect.Width div 2),
4456 Y + Rect.Y + Rect.Height,
4457 gPlayer1.Direction, True);
4458 end;
4459 if (Length(P) > 2) and (mon <> nil) then
4460 begin
4461 if (CompareText(P[2], 'normal') = 0) then mon.MonsterBehaviour := BH_NORMAL
4462 else if (CompareText(P[2], 'killer') = 0) then mon.MonsterBehaviour := BH_KILLER
4463 else if (CompareText(P[2], 'maniac') = 0) then mon.MonsterBehaviour := BH_MANIAC
4464 else if (CompareText(P[2], 'insane') = 0) then mon.MonsterBehaviour := BH_INSANE
4465 else if (CompareText(P[2], 'cannibal') = 0) then mon.MonsterBehaviour := BH_CANNIBAL
4466 else if (CompareText(P[2], 'good') = 0) then mon.MonsterBehaviour := BH_GOOD
4467 else if (CompareText(P[2], 'friend') = 0) then mon.MonsterBehaviour := BH_GOOD
4468 else if (CompareText(P[2], 'friendly') = 0) then mon.MonsterBehaviour := BH_GOOD
4469 else mon.MonsterBehaviour := Min(Max(StrToIntDef(P[2], BH_NORMAL), BH_NORMAL), BH_GOOD);
4470 end;
4471 end;
4472 end;
4473 end
4474 else if (cmd = 'd_health') then
4475 begin
4476 if (Length(P) > 1) and
4477 ((P[1] = '1') or (P[1] = '0')) then
4478 g_debug_HealthBar := (P[1][1] = '1');
4480 g_Console_Add(Format('d_health is %d', [Byte(g_debug_HealthBar)]));
4481 end
4482 else if (cmd = 'd_player') then
4483 begin
4484 if (Length(P) > 1) and
4485 ((P[1] = '1') or (P[1] = '0')) then
4486 g_debug_Player := (P[1][1] = '1');
4488 g_Console_Add(Format(cmd + ' is %d', [Byte(g_Debug_Player)]));
4489 end
4490 else if (cmd = 'd_mem') then
4491 begin
4492 PrintHeapStats();
4493 end;
4494 end
4495 else
4496 g_Console_Add(_lc[I_MSG_NOT_DEBUG]);
4497 end;
4500 procedure GameCheats(P: SSArray);
4501 var
4502 cmd: string;
4503 f, a: Integer;
4504 plr: TPlayer;
4505 begin
4506 if (not gGameOn) or (not conIsCheatsEnabled) then
4507 begin
4508 g_Console_Add('not available');
4509 exit;
4510 end;
4511 plr := gPlayer1;
4512 if plr = nil then
4513 begin
4514 g_Console_Add('where is the player?!');
4515 exit;
4516 end;
4517 cmd := LowerCase(P[0]);
4518 // god
4519 if cmd = 'god' then
4520 begin
4521 plr.GodMode := not plr.GodMode;
4522 if plr.GodMode then g_Console_Add('player is godlike now') else g_Console_Add('player is mortal now');
4523 exit;
4524 end;
4525 // give <health|exit|weapons|air|suit|jetpack|berserk|all>
4526 if cmd = 'give' then
4527 begin
4528 if length(P) < 2 then begin g_Console_Add('give what?!'); exit; end;
4529 for f := 1 to High(P) do
4530 begin
4531 cmd := LowerCase(P[f]);
4532 if cmd = 'health' then begin plr.RestoreHealthArmor(); g_Console_Add('player feels himself better'); continue; end;
4533 if (cmd = 'all') {or (cmd = 'weapons')} then begin plr.AllRulez(False); g_Console_Add('player got the gifts'); continue; end;
4534 if cmd = 'exit' then
4535 begin
4536 if gTriggers <> nil then
4537 begin
4538 for a := 0 to High(gTriggers) do
4539 begin
4540 if gTriggers[a].TriggerType = TRIGGER_EXIT then
4541 begin
4542 g_Console_Add('player left the map');
4543 gExitByTrigger := True;
4544 //g_Game_ExitLevel(gTriggers[a].Data.MapName);
4545 g_Game_ExitLevel(gTriggers[a].tgcMap);
4546 break;
4547 end;
4548 end;
4549 end;
4550 continue;
4551 end;
4553 if cmd = 'air' then begin plr.GiveItem(ITEM_OXYGEN); g_Console_Add('player got some air'); continue; end;
4554 if cmd = 'jetpack' then begin plr.GiveItem(ITEM_JETPACK); g_Console_Add('player got a jetpack'); continue; end;
4555 if cmd = 'suit' then begin plr.GiveItem(ITEM_SUIT); g_Console_Add('player got an envirosuit'); continue; end;
4556 if cmd = 'berserk' then begin plr.GiveItem(ITEM_MEDKIT_BLACK); g_Console_Add('player got a berserk pack'); continue; end;
4557 if cmd = 'backpack' then begin plr.GiveItem(ITEM_AMMO_BACKPACK); g_Console_Add('player got a backpack'); continue; end;
4559 if cmd = 'helmet' then begin plr.GiveItem(ITEM_HELMET); g_Console_Add('player got a helmet'); continue; end;
4560 if cmd = 'bottle' then begin plr.GiveItem(ITEM_BOTTLE); g_Console_Add('player got a bottle of health'); continue; end;
4562 if cmd = 'stimpack' then begin plr.GiveItem(ITEM_MEDKIT_SMALL); g_Console_Add('player got a stimpack'); continue; end;
4563 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;
4565 if cmd = 'greenarmor' then begin plr.GiveItem(ITEM_ARMOR_GREEN); g_Console_Add('player got a security armor'); continue; end;
4566 if cmd = 'bluearmor' then begin plr.GiveItem(ITEM_ARMOR_BLUE); g_Console_Add('player got a combat armor'); continue; end;
4568 if (cmd = 'megasphere') or (cmd = 'mega') then begin plr.GiveItem(ITEM_SPHERE_BLUE); g_Console_Add('player got a megasphere'); continue; end;
4569 if (cmd = 'soulsphere') or (cmd = 'soul')then begin plr.GiveItem(ITEM_SPHERE_WHITE); g_Console_Add('player got a soul sphere'); continue; end;
4571 if (cmd = 'invul') or (cmd = 'invulnerability') then begin plr.GiveItem(ITEM_INVUL); g_Console_Add('player got invulnerability'); continue; end;
4572 if (cmd = 'invis') or (cmd = 'invisibility') then begin plr.GiveItem(ITEM_INVIS); g_Console_Add('player got invisibility'); continue; end;
4574 if cmd = 'redkey' then begin plr.GiveItem(ITEM_KEY_RED); g_Console_Add('player got the red key'); continue; end;
4575 if cmd = 'greenkey' then begin plr.GiveItem(ITEM_KEY_GREEN); g_Console_Add('player got the green key'); continue; end;
4576 if cmd = 'bluekey' then begin plr.GiveItem(ITEM_KEY_BLUE); g_Console_Add('player got the blue key'); continue; end;
4578 if (cmd = 'shotgun') or (cmd = 'sg') then begin plr.GiveItem(ITEM_WEAPON_SHOTGUN1); g_Console_Add('player got a shotgun'); continue; end;
4579 if (cmd = 'supershotgun') or (cmd = 'ssg') then begin plr.GiveItem(ITEM_WEAPON_SHOTGUN2); g_Console_Add('player got a supershotgun'); continue; end;
4580 if cmd = 'chaingun' then begin plr.GiveItem(ITEM_WEAPON_CHAINGUN); g_Console_Add('player got a chaingun'); continue; end;
4581 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;
4582 if cmd = 'plasmagun' then begin plr.GiveItem(ITEM_WEAPON_PLASMA); g_Console_Add('player got a plasma gun'); continue; end;
4583 if cmd = 'bfg' then begin plr.GiveItem(ITEM_WEAPON_BFG); g_Console_Add('player got a BFG-9000'); continue; end;
4585 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;
4586 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;
4587 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;
4588 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;
4589 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;
4590 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;
4592 if cmd = 'superchaingun' then begin plr.GiveItem(ITEM_WEAPON_SUPERPULEMET); g_Console_Add('player got a superchaingun'); continue; end;
4593 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;
4595 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;
4596 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;
4598 if cmd = 'chainsaw' then begin plr.GiveItem(ITEM_WEAPON_SAW); g_Console_Add('player got a chainsaw'); continue; end;
4600 if cmd = 'ammo' then
4601 begin
4602 plr.GiveItem(ITEM_AMMO_SHELLS_BOX);
4603 plr.GiveItem(ITEM_AMMO_BULLETS_BOX);
4604 plr.GiveItem(ITEM_AMMO_CELL_BIG);
4605 plr.GiveItem(ITEM_AMMO_ROCKET_BOX);
4606 plr.GiveItem(ITEM_AMMO_FUELCAN);
4607 g_Console_Add('player got some ammo');
4608 continue;
4609 end;
4611 if cmd = 'clip' then begin plr.GiveItem(ITEM_AMMO_BULLETS); g_Console_Add('player got some bullets'); continue; end;
4612 if cmd = 'bullets' then begin plr.GiveItem(ITEM_AMMO_BULLETS_BOX); g_Console_Add('player got a box of bullets'); continue; end;
4614 if cmd = 'shells' then begin plr.GiveItem(ITEM_AMMO_SHELLS); g_Console_Add('player got some shells'); continue; end;
4615 if cmd = 'shellbox' then begin plr.GiveItem(ITEM_AMMO_SHELLS_BOX); g_Console_Add('player got a box of shells'); continue; end;
4617 if cmd = 'cells' then begin plr.GiveItem(ITEM_AMMO_CELL); g_Console_Add('player got some cells'); continue; end;
4618 if cmd = 'battery' then begin plr.GiveItem(ITEM_AMMO_CELL_BIG); g_Console_Add('player got cell battery'); continue; end;
4620 if cmd = 'rocket' then begin plr.GiveItem(ITEM_AMMO_ROCKET); g_Console_Add('player got a rocket'); continue; end;
4621 if cmd = 'rocketbox' then begin plr.GiveItem(ITEM_AMMO_ROCKET_BOX); g_Console_Add('player got some rockets'); continue; end;
4623 if (cmd = 'fuel') or (cmd = 'fuelcan') then begin plr.GiveItem(ITEM_AMMO_FUELCAN); g_Console_Add('player got fuel canister'); continue; end;
4625 if cmd = 'weapons' then
4626 begin
4627 plr.GiveItem(ITEM_WEAPON_SHOTGUN1);
4628 plr.GiveItem(ITEM_WEAPON_SHOTGUN2);
4629 plr.GiveItem(ITEM_WEAPON_CHAINGUN);
4630 plr.GiveItem(ITEM_WEAPON_ROCKETLAUNCHER);
4631 plr.GiveItem(ITEM_WEAPON_PLASMA);
4632 plr.GiveItem(ITEM_WEAPON_BFG);
4633 g_Console_Add('player got weapons');
4634 continue;
4635 end;
4637 if cmd = 'keys' then
4638 begin
4639 plr.GiveItem(ITEM_KEY_RED);
4640 plr.GiveItem(ITEM_KEY_GREEN);
4641 plr.GiveItem(ITEM_KEY_BLUE);
4642 g_Console_Add('player got all keys');
4643 continue;
4644 end;
4646 g_Console_Add('i don''t know how to give '''+cmd+'''!');
4647 end;
4648 exit;
4649 end;
4650 // open
4651 if cmd = 'open' then
4652 begin
4653 g_Console_Add('player activated sesame');
4654 g_Triggers_OpenAll();
4655 exit;
4656 end;
4657 // fly
4658 if cmd = 'fly' then
4659 begin
4660 gFly := not gFly;
4661 if gFly then g_Console_Add('player feels himself lighter') else g_Console_Add('player lost his wings');
4662 exit;
4663 end;
4664 // noclip
4665 if cmd = 'noclip' then
4666 begin
4667 plr.SwitchNoClip;
4668 g_Console_Add('wall hardeness adjusted');
4669 exit;
4670 end;
4671 // notarget
4672 if cmd = 'notarget' then
4673 begin
4674 plr.NoTarget := not plr.NoTarget;
4675 if plr.NoTarget then g_Console_Add('player hides in shadows') else g_Console_Add('player is brave again');
4676 exit;
4677 end;
4678 // noreload
4679 if cmd = 'noreload' then
4680 begin
4681 plr.NoReload := not plr.NoReload;
4682 if plr.NoReload then g_Console_Add('player is action hero now') else g_Console_Add('player is ordinary man now');
4683 exit;
4684 end;
4685 // speedy
4686 if cmd = 'speedy' then
4687 begin
4688 MAX_RUNVEL := 32-MAX_RUNVEL;
4689 g_Console_Add('speed adjusted');
4690 exit;
4691 end;
4692 // jumpy
4693 if cmd = 'jumpy' then
4694 begin
4695 VEL_JUMP := 30-VEL_JUMP;
4696 g_Console_Add('jump height adjusted');
4697 exit;
4698 end;
4699 // automap
4700 if cmd = 'automap' then
4701 begin
4702 gShowMap := not gShowMap;
4703 if gShowMap then g_Console_Add('player gains second sight') else g_Console_Add('player lost second sight');
4704 exit;
4705 end;
4706 // aimline
4707 if cmd = 'aimline' then
4708 begin
4709 gAimLine := not gAimLine;
4710 if gAimLine then g_Console_Add('player gains laser sight') else g_Console_Add('player lost laser sight');
4711 exit;
4712 end;
4713 end;
4715 procedure GameCommands(P: SSArray);
4716 var
4717 a, b: Integer;
4718 s, pw: String;
4719 chstr: string;
4720 cmd: string;
4721 pl: pTNetClient = nil;
4722 plr: TPlayer;
4723 prt: Word;
4724 nm: Boolean;
4725 listen: LongWord;
4726 found: Boolean;
4727 begin
4728 // Общие команды:
4729 cmd := LowerCase(P[0]);
4730 chstr := '';
4731 if cmd = 'pause' then
4732 begin
4733 if (g_ActiveWindow = nil) then
4734 g_Game_Pause(not gPauseMain);
4735 end
4736 else if cmd = 'endgame' then
4737 gExit := EXIT_SIMPLE
4738 else if cmd = 'restart' then
4739 begin
4740 if gGameOn or (gState in [STATE_INTERSINGLE, STATE_INTERCUSTOM]) then
4741 begin
4742 if g_Game_IsClient then
4743 begin
4744 g_Console_Add(_lc[I_MSG_SERVERONLY]);
4745 Exit;
4746 end;
4747 g_Game_Restart();
4748 end else
4749 g_Console_Add(_lc[I_MSG_NOT_GAME]);
4750 end
4751 else if cmd = 'kick' then
4752 begin
4753 if g_Game_IsServer then
4754 begin
4755 if Length(P) < 2 then
4756 begin
4757 g_Console_Add('kick <name>');
4758 Exit;
4759 end;
4760 if P[1] = '' then
4761 begin
4762 g_Console_Add('kick <name>');
4763 Exit;
4764 end;
4766 if g_Game_IsNet then
4767 pl := g_Net_Client_ByName(P[1]);
4768 if (pl <> nil) then
4769 begin
4770 s := g_Net_ClientName_ByID(pl^.ID);
4771 g_Net_Host_Kick(pl^.ID, NET_DISC_KICK);
4772 g_Console_Add(Format(_lc[I_PLAYER_KICK], [s]));
4773 MH_SEND_GameEvent(NET_EV_PLAYER_KICK, 0, s);
4774 g_Net_Slist_ServerPlayerLeaves();
4775 end else if gPlayers <> nil then
4776 for a := Low(gPlayers) to High(gPlayers) do
4777 if gPlayers[a] <> nil then
4778 if Copy(LowerCase(gPlayers[a].Name), 1, Length(P[1])) = LowerCase(P[1]) then
4779 begin
4780 // Не отключать основных игроков в сингле
4781 if not(gPlayers[a] is TBot) and (gGameSettings.GameType = GT_SINGLE) then
4782 continue;
4783 gPlayers[a].Lives := 0;
4784 gPlayers[a].Kill(K_SIMPLEKILL, 0, HIT_DISCON);
4785 g_Console_Add(Format(_lc[I_PLAYER_LEAVE], [gPlayers[a].Name]), True);
4786 g_Player_Remove(gPlayers[a].UID);
4787 g_Net_Slist_ServerPlayerLeaves();
4788 // Если не перемешать, при добавлении новых ботов появятся старые
4789 g_Bot_MixNames();
4790 end;
4791 end else
4792 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
4793 end
4794 else if cmd = 'kick_id' then
4795 begin
4796 if g_Game_IsServer and g_Game_IsNet then
4797 begin
4798 if Length(P) < 2 then
4799 begin
4800 g_Console_Add('kick_id <client ID>');
4801 Exit;
4802 end;
4803 if P[1] = '' then
4804 begin
4805 g_Console_Add('kick_id <client ID>');
4806 Exit;
4807 end;
4809 a := StrToIntDef(P[1], 0);
4810 if (NetClients <> nil) and (a <= High(NetClients)) then
4811 begin
4812 if NetClients[a].Used and (NetClients[a].Peer <> nil) then
4813 begin
4814 s := g_Net_ClientName_ByID(NetClients[a].ID);
4815 g_Net_Host_Kick(NetClients[a].ID, NET_DISC_KICK);
4816 g_Console_Add(Format(_lc[I_PLAYER_KICK], [s]));
4817 MH_SEND_GameEvent(NET_EV_PLAYER_KICK, 0, s);
4818 g_Net_Slist_ServerPlayerLeaves();
4819 end;
4820 end;
4821 end else
4822 g_Console_Add(_lc[I_MSG_SERVERONLY]);
4823 end
4824 else if cmd = 'kick_pid' then
4825 begin
4826 if g_Game_IsServer and g_Game_IsNet then
4827 begin
4828 if Length(P) < 2 then
4829 begin
4830 g_Console_Add('kick_pid <player ID>');
4831 Exit;
4832 end;
4833 if P[1] = '' then
4834 begin
4835 g_Console_Add('kick_pid <player ID>');
4836 Exit;
4837 end;
4839 a := StrToIntDef(P[1], 0);
4840 pl := g_Net_Client_ByPlayer(a);
4841 if (pl <> nil) and pl^.Used and (pl^.Peer <> nil) then
4842 begin
4843 s := g_Net_ClientName_ByID(pl^.ID);
4844 g_Net_Host_Kick(pl^.ID, NET_DISC_KICK);
4845 g_Console_Add(Format(_lc[I_PLAYER_KICK], [s]));
4846 MH_SEND_GameEvent(NET_EV_PLAYER_KICK, 0, s);
4847 g_Net_Slist_ServerPlayerLeaves();
4848 end;
4849 end else
4850 g_Console_Add(_lc[I_MSG_SERVERONLY]);
4851 end
4852 else if cmd = 'ban' then
4853 begin
4854 if g_Game_IsServer and g_Game_IsNet then
4855 begin
4856 if Length(P) < 2 then
4857 begin
4858 g_Console_Add('ban <name>');
4859 Exit;
4860 end;
4861 if P[1] = '' then
4862 begin
4863 g_Console_Add('ban <name>');
4864 Exit;
4865 end;
4867 pl := g_Net_Client_ByName(P[1]);
4868 if (pl <> nil) then
4869 begin
4870 s := g_Net_ClientName_ByID(pl^.ID);
4871 g_Net_BanHost(pl^.Peer^.address.host, False);
4872 g_Net_Host_Kick(pl^.ID, NET_DISC_TEMPBAN);
4873 g_Console_Add(Format(_lc[I_PLAYER_BAN], [s]));
4874 MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s);
4875 g_Net_Slist_ServerPlayerLeaves();
4876 end else
4877 g_Console_Add(Format(_lc[I_NET_ERR_NAME404], [P[1]]));
4878 end else
4879 g_Console_Add(_lc[I_MSG_SERVERONLY]);
4880 end
4881 else if cmd = 'ban_id' then
4882 begin
4883 if g_Game_IsServer and g_Game_IsNet then
4884 begin
4885 if Length(P) < 2 then
4886 begin
4887 g_Console_Add('ban_id <client ID>');
4888 Exit;
4889 end;
4890 if P[1] = '' then
4891 begin
4892 g_Console_Add('ban_id <client ID>');
4893 Exit;
4894 end;
4896 a := StrToIntDef(P[1], 0);
4897 if (NetClients <> nil) and (a <= High(NetClients)) then
4898 if NetClients[a].Used and (NetClients[a].Peer <> nil) then
4899 begin
4900 s := g_Net_ClientName_ByID(NetClients[a].ID);
4901 g_Net_BanHost(NetClients[a].Peer^.address.host, False);
4902 g_Net_Host_Kick(NetClients[a].ID, NET_DISC_TEMPBAN);
4903 g_Console_Add(Format(_lc[I_PLAYER_BAN], [s]));
4904 MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s);
4905 g_Net_Slist_ServerPlayerLeaves();
4906 end;
4907 end else
4908 g_Console_Add(_lc[I_MSG_SERVERONLY]);
4909 end
4910 else if cmd = 'ban_pid' then
4911 begin
4912 if g_Game_IsServer and g_Game_IsNet then
4913 begin
4914 if Length(P) < 2 then
4915 begin
4916 g_Console_Add('ban_pid <player ID>');
4917 Exit;
4918 end;
4919 if P[1] = '' then
4920 begin
4921 g_Console_Add('ban_pid <player ID>');
4922 Exit;
4923 end;
4925 a := StrToIntDef(P[1], 0);
4926 pl := g_Net_Client_ByPlayer(a);
4927 if (pl <> nil) and pl^.Used and (pl^.Peer <> nil) then
4928 begin
4929 s := g_Net_ClientName_ByID(pl^.ID);
4930 g_Net_BanHost(pl^.Peer^.address.host, False);
4931 g_Net_Host_Kick(pl^.ID, NET_DISC_TEMPBAN);
4932 g_Console_Add(Format(_lc[I_PLAYER_BAN], [s]));
4933 MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s);
4934 g_Net_Slist_ServerPlayerLeaves();
4935 end;
4936 end else
4937 g_Console_Add(_lc[I_MSG_SERVERONLY]);
4938 end
4939 else if cmd = 'permban' then
4940 begin
4941 if g_Game_IsServer and g_Game_IsNet then
4942 begin
4943 if Length(P) < 2 then
4944 begin
4945 g_Console_Add('permban <name>');
4946 Exit;
4947 end;
4948 if P[1] = '' then
4949 begin
4950 g_Console_Add('permban <name>');
4951 Exit;
4952 end;
4954 pl := g_Net_Client_ByName(P[1]);
4955 if (pl <> nil) then
4956 begin
4957 s := g_Net_ClientName_ByID(pl^.ID);
4958 g_Net_BanHost(pl^.Peer^.address.host);
4959 g_Net_Host_Kick(pl^.ID, NET_DISC_BAN);
4960 g_Net_SaveBanList();
4961 g_Console_Add(Format(_lc[I_PLAYER_BAN], [s]));
4962 MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s);
4963 g_Net_Slist_ServerPlayerLeaves();
4964 end else
4965 g_Console_Add(Format(_lc[I_NET_ERR_NAME404], [P[1]]));
4966 end else
4967 g_Console_Add(_lc[I_MSG_SERVERONLY]);
4968 end
4969 else if cmd = 'permban_id' then
4970 begin
4971 if g_Game_IsServer and g_Game_IsNet then
4972 begin
4973 if Length(P) < 2 then
4974 begin
4975 g_Console_Add('permban_id <client ID>');
4976 Exit;
4977 end;
4978 if P[1] = '' then
4979 begin
4980 g_Console_Add('permban_id <client ID>');
4981 Exit;
4982 end;
4984 a := StrToIntDef(P[1], 0);
4985 if (NetClients <> nil) and (a <= High(NetClients)) then
4986 if NetClients[a].Used and (NetClients[a].Peer <> nil) then
4987 begin
4988 s := g_Net_ClientName_ByID(NetClients[a].ID);
4989 g_Net_BanHost(NetClients[a].Peer^.address.host);
4990 g_Net_Host_Kick(NetClients[a].ID, NET_DISC_BAN);
4991 g_Net_SaveBanList();
4992 g_Console_Add(Format(_lc[I_PLAYER_BAN], [s]));
4993 MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s);
4994 g_Net_Slist_ServerPlayerLeaves();
4995 end;
4996 end else
4997 g_Console_Add(_lc[I_MSG_SERVERONLY]);
4998 end
4999 else if cmd = 'permban_pid' then
5000 begin
5001 if g_Game_IsServer and g_Game_IsNet then
5002 begin
5003 if Length(P) < 2 then
5004 begin
5005 g_Console_Add('permban_pid <player ID>');
5006 Exit;
5007 end;
5008 if P[1] = '' then
5009 begin
5010 g_Console_Add('permban_pid <player ID>');
5011 Exit;
5012 end;
5014 a := StrToIntDef(P[1], 0);
5015 pl := g_Net_Client_ByPlayer(a);
5016 if (pl <> nil) and pl^.Used and (pl^.Peer <> nil) then
5017 begin
5018 s := g_Net_ClientName_ByID(pl^.ID);
5019 g_Net_BanHost(pl^.Peer^.address.host);
5020 g_Net_Host_Kick(pl^.ID, NET_DISC_TEMPBAN);
5021 g_Net_SaveBanList();
5022 g_Console_Add(Format(_lc[I_PLAYER_BAN], [s]));
5023 MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s);
5024 g_Net_Slist_ServerPlayerLeaves();
5025 end;
5026 end else
5027 g_Console_Add(_lc[I_MSG_SERVERONLY]);
5028 end
5029 else if cmd = 'permban_ip' then
5030 begin
5031 if g_Game_IsServer and g_Game_IsNet then
5032 begin
5033 if Length(P) < 2 then
5034 begin
5035 g_Console_Add('permban_ip <IP address>');
5036 Exit;
5037 end;
5038 if P[1] = '' then
5039 begin
5040 g_Console_Add('permban_ip <IP address>');
5041 Exit;
5042 end;
5044 g_Net_BanHost(P[1]);
5045 g_Net_SaveBanList();
5046 g_Console_Add(Format(_lc[I_PLAYER_BAN], [P[1]]));
5047 end else
5048 g_Console_Add(_lc[I_MSG_SERVERONLY]);
5049 end
5050 else if cmd = 'unban' then
5051 begin
5052 if g_Game_IsServer and g_Game_IsNet then
5053 begin
5054 if Length(P) < 2 then
5055 begin
5056 g_Console_Add('unban <IP Address>');
5057 Exit;
5058 end;
5059 if P[1] = '' then
5060 begin
5061 g_Console_Add('unban <IP Address>');
5062 Exit;
5063 end;
5065 if g_Net_UnbanHost(P[1]) then
5066 begin
5067 g_Console_Add(Format(_lc[I_MSG_UNBAN_OK], [P[1]]));
5068 g_Net_SaveBanList();
5069 end else
5070 g_Console_Add(Format(_lc[I_MSG_UNBAN_FAIL], [P[1]]));
5071 end else
5072 g_Console_Add(_lc[I_MSG_SERVERONLY]);
5073 end
5074 else if cmd = 'clientlist' then
5075 begin
5076 if g_Game_IsServer and g_Game_IsNet then
5077 begin
5078 b := 0;
5079 if NetClients <> nil then
5080 for a := Low(NetClients) to High(NetClients) do
5081 if NetClients[a].Used and (NetClients[a].Peer <> nil) then
5082 begin
5083 plr := g_Player_Get(NetClients[a].Player);
5084 if plr = nil then continue;
5085 Inc(b);
5086 g_Console_Add(Format('#%2d: %-15s | %s', [a,
5087 IpToStr(NetClients[a].Peer^.address.host), plr.Name]));
5088 end;
5089 if b = 0 then
5090 g_Console_Add(_lc[I_MSG_NOCLIENTS]);
5091 end else
5092 g_Console_Add(_lc[I_MSG_SERVERONLY]);
5093 end
5094 else if cmd = 'connect' then
5095 begin
5096 if (NetMode = NET_NONE) then
5097 begin
5098 if Length(P) < 2 then
5099 begin
5100 g_Console_Add('connect <IP> [port] [password]');
5101 Exit;
5102 end;
5103 if P[1] = '' then
5104 begin
5105 g_Console_Add('connect <IP> [port] [password]');
5106 Exit;
5107 end;
5109 if Length(P) > 2 then
5110 prt := StrToIntDef(P[2], 25666)
5111 else
5112 prt := 25666;
5114 if Length(P) > 3 then
5115 pw := P[3]
5116 else
5117 pw := '';
5119 g_Game_StartClient(P[1], prt, pw);
5120 end;
5121 end
5122 else if cmd = 'disconnect' then
5123 begin
5124 if (NetMode = NET_CLIENT) then
5125 g_Net_Disconnect();
5126 end
5127 else if cmd = 'reconnect' then
5128 begin
5129 if (NetMode = NET_SERVER) then
5130 Exit;
5132 if (NetMode = NET_CLIENT) then
5133 begin
5134 g_Net_Disconnect();
5135 gExit := EXIT_SIMPLE;
5136 EndGame;
5137 end;
5139 //TODO: Use last successful password to reconnect, instead of ''
5140 g_Game_StartClient(NetClientIP, NetClientPort, '');
5141 end
5142 else if (cmd = 'addbot') or
5143 (cmd = 'bot_add') then
5144 begin
5145 if Length(P) > 2 then
5146 g_Bot_Add(TEAM_NONE, StrToIntDef(P[1], 2), StrToIntDef(P[2], 100))
5147 else if Length(P) > 1 then
5148 g_Bot_Add(TEAM_NONE, StrToIntDef(P[1], 2))
5149 else
5150 g_Bot_Add(TEAM_NONE, 2);
5151 end
5152 else if cmd = 'bot_addlist' then
5153 begin
5154 if Length(P) > 1 then
5155 begin
5156 if Length(P) = 2 then
5157 g_Bot_AddList(TEAM_NONE, P[1], StrToIntDef(P[1], -1))
5158 else if Length(P) = 3 then
5159 g_Bot_AddList(TEAM_NONE, P[1], StrToIntDef(P[1], -1), StrToIntDef(P[2], 100))
5160 else
5161 g_Bot_AddList(IfThen(P[2] = 'red', TEAM_RED, TEAM_BLUE), P[1], StrToIntDef(P[1], -1));
5162 end;
5163 end
5164 else if cmd = 'bot_removeall' then
5165 g_Bot_RemoveAll()
5166 else if cmd = 'chat' then
5167 begin
5168 if g_Game_IsNet then
5169 begin
5170 if Length(P) > 1 then
5171 begin
5172 for a := 1 to High(P) do
5173 chstr := chstr + P[a] + ' ';
5175 if Length(chstr) > 200 then SetLength(chstr, 200);
5177 if Length(chstr) < 1 then
5178 begin
5179 g_Console_Add('chat <text>');
5180 Exit;
5181 end;
5183 chstr := b_Text_Format(chstr);
5184 if g_Game_IsClient then
5185 MC_SEND_Chat(chstr, NET_CHAT_PLAYER)
5186 else
5187 MH_SEND_Chat(gPlayer1Settings.Name + ': ' + chstr, NET_CHAT_PLAYER);
5188 end
5189 else
5190 g_Console_Add('chat <text>');
5191 end else
5192 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
5193 end
5194 else if cmd = 'teamchat' then
5195 begin
5196 if g_Game_IsNet and (gGameSettings.GameMode in [GM_TDM, GM_CTF]) then
5197 begin
5198 if Length(P) > 1 then
5199 begin
5200 for a := 1 to High(P) do
5201 chstr := chstr + P[a] + ' ';
5203 if Length(chstr) > 200 then SetLength(chstr, 200);
5205 if Length(chstr) < 1 then
5206 begin
5207 g_Console_Add('teamchat <text>');
5208 Exit;
5209 end;
5211 chstr := b_Text_Format(chstr);
5212 if g_Game_IsClient then
5213 MC_SEND_Chat(chstr, NET_CHAT_TEAM)
5214 else
5215 MH_SEND_Chat(gPlayer1Settings.Name + ': ' + chstr, NET_CHAT_TEAM,
5216 gPlayer1Settings.Team);
5217 end
5218 else
5219 g_Console_Add('teamchat <text>');
5220 end else
5221 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
5222 end
5223 else if (cmd = 'an') or (cmd = 'announce') then
5224 begin
5225 if g_Game_IsNet then
5226 begin
5227 if Length(P) > 1 then
5228 begin
5229 for a := 1 to High(P) do
5230 chstr := chstr + P[a] + ' ';
5232 if Length(chstr) > 200 then SetLength(chstr, 200);
5234 if Length(chstr) < 1 then
5235 begin
5236 g_Console_Add('announce <text>');
5237 Exit;
5238 end;
5240 chstr := 'centerprint 100 ' + b_Text_Format(chstr);
5241 if g_Game_IsClient then
5242 MC_SEND_RCONCommand(chstr)
5243 else
5244 g_Console_Process(chstr, True);
5245 end
5246 else
5247 g_Console_Add('announce <text>');
5248 end else
5249 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
5250 end
5251 else if cmd = 'game' then
5252 begin
5253 if gGameSettings.GameType <> GT_NONE then
5254 begin
5255 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
5256 Exit;
5257 end;
5258 if Length(P) = 1 then
5259 begin
5260 g_Console_Add(cmd + ' <WAD> [MAP] [# players]');
5261 Exit;
5262 end;
5263 // game not started yet, load fist map from some wad
5264 found := false;
5265 s := addWadExtension(P[1]);
5266 found := e_FindResource(AllMapDirs, s);
5267 P[1] := s;
5268 if found then
5269 begin
5270 P[1] := ExpandFileName(P[1]);
5271 // if map not choosed then set first map
5272 if Length(P) < 3 then
5273 begin
5274 SetLength(P, 3);
5275 P[2] := g_Game_GetFirstMap(P[1]);
5276 end;
5278 s := P[1] + ':\' + UpperCase(P[2]);
5280 if g_Map_Exist(s) then
5281 begin
5282 // start game
5283 g_Game_Free();
5284 with gGameSettings do
5285 begin
5286 Options := gsGameFlags;
5287 GameMode := g_Game_TextToMode(gsGameMode);
5288 if gSwitchGameMode <> GM_NONE then
5289 GameMode := gSwitchGameMode;
5290 if GameMode = GM_NONE then GameMode := GM_DM;
5291 if GameMode = GM_SINGLE then GameMode := GM_COOP;
5292 b := 1;
5293 if Length(P) >= 4 then
5294 b := StrToIntDef(P[3], 1);
5295 g_Game_StartCustom(s, GameMode, TimeLimit,
5296 ScoreLimit, MaxLives, Options, b);
5297 end;
5298 end
5299 else
5300 if P[2] = '' then
5301 g_Console_Add(Format(_lc[I_MSG_NO_MAPS], [P[1]]))
5302 else
5303 g_Console_Add(Format(_lc[I_MSG_NO_MAP_FALLBACK], [UpperCase(P[2]), P[1]]));
5304 end else
5305 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]));
5306 end
5307 else if cmd = 'host' then
5308 begin
5309 if gGameSettings.GameType <> GT_NONE then
5310 begin
5311 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
5312 Exit;
5313 end;
5314 if Length(P) < 4 then
5315 begin
5316 g_Console_Add(cmd + ' <listen IP> <port> <WAD> [MAP] [# players]');
5317 Exit;
5318 end;
5319 if not StrToIp(P[1], listen) then
5320 Exit;
5321 prt := StrToIntDef(P[2], 25666);
5323 s := addWadExtension(P[3]);
5324 found := e_FindResource(AllMapDirs, s);
5325 P[3] := s;
5326 if found then
5327 begin
5328 // get first map in wad, if not specified
5329 if Length(P) < 5 then
5330 begin
5331 SetLength(P, 5);
5332 P[4] := g_Game_GetFirstMap(P[1]);
5333 end;
5334 s := P[3] + ':\' + UpperCase(P[4]);
5335 if g_Map_Exist(s) then
5336 begin
5337 // start game
5338 g_Game_Free();
5339 with gGameSettings do
5340 begin
5341 Options := gsGameFlags;
5342 GameMode := g_Game_TextToMode(gsGameMode);
5343 if gSwitchGameMode <> GM_NONE then GameMode := gSwitchGameMode;
5344 if GameMode = GM_NONE then GameMode := GM_DM;
5345 if GameMode = GM_SINGLE then GameMode := GM_COOP;
5346 b := 0;
5347 if Length(P) >= 6 then
5348 b := StrToIntDef(P[5], 0);
5349 g_Game_StartServer(s, GameMode, TimeLimit, ScoreLimit, MaxLives, Options, b, listen, prt)
5350 end
5351 end
5352 else
5353 begin
5354 if P[4] = '' then
5355 g_Console_Add(Format(_lc[I_MSG_NO_MAPS], [P[3]]))
5356 else
5357 g_Console_Add(Format(_lc[I_MSG_NO_MAP_FALLBACK], [UpperCase(P[4]), P[3]]))
5358 end
5359 end
5360 else
5361 begin
5362 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[3]]))
5363 end
5364 end
5365 else if cmd = 'map' then
5366 begin
5367 if Length(P) = 1 then
5368 begin
5369 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
5370 begin
5371 g_Console_Add(cmd + ' <MAP>');
5372 g_Console_Add(cmd + ' <WAD> [MAP]')
5373 end
5374 else
5375 begin
5376 g_Console_Add(_lc[I_MSG_GM_UNAVAIL])
5377 end
5378 end
5379 else
5380 begin
5381 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
5382 begin
5383 if Length(P) < 3 then
5384 begin
5385 // first param is map or wad
5386 s := UpperCase(P[1]);
5387 if g_Map_Exist(gGameSettings.WAD + ':\' + s) then
5388 begin
5389 gExitByTrigger := False;
5390 if gGameOn then
5391 begin
5392 // already in game, finish current map
5393 gNextMap := s;
5394 gExit := EXIT_ENDLEVELCUSTOM;
5395 end
5396 else
5397 begin
5398 // intermission, so change map immediately
5399 g_Game_ChangeMap(s)
5400 end
5401 end
5402 else
5403 begin
5404 s := P[1];
5405 found := e_FindResource(AllMapDirs, s);
5406 P[1] := s;
5407 g_Console_Add(Format(_lc[I_MSG_NO_MAP_FALLBACK], [s, 'WAD ' + P[1]]));
5408 if found then
5409 begin
5410 // no such map, found wad
5411 pw := P[1];
5412 SetLength(P, 3);
5413 P[1] := ExpandFileName(pw);
5414 P[2] := g_Game_GetFirstMap(P[1]);
5415 s := P[1] + ':\' + P[2];
5416 if g_Map_Exist(s) then
5417 begin
5418 gExitByTrigger := False;
5419 if gGameOn then
5420 begin
5421 // already in game, finish current map
5422 gNextMap := s;
5423 gExit := EXIT_ENDLEVELCUSTOM
5424 end
5425 else
5426 begin
5427 // intermission, so change map immediately
5428 g_Game_ChangeMap(s)
5429 end
5430 end
5431 else
5432 begin
5433 if P[2] = '' then
5434 g_Console_Add(Format(_lc[I_MSG_NO_MAPS], [P[1]]))
5435 else
5436 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [P[2]]))
5437 end
5438 end
5439 else
5440 begin
5441 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]))
5442 end
5443 end;
5444 end
5445 else
5446 begin
5447 s := addWadExtension(P[1]);
5448 found := e_FindResource(AllMapDirs, s);
5449 P[1] := s;
5450 if found then
5451 begin
5452 P[2] := UpperCase(P[2]);
5453 s := P[1] + ':\' + P[2];
5454 if g_Map_Exist(s) then
5455 begin
5456 gExitByTrigger := False;
5457 if gGameOn then
5458 begin
5459 gNextMap := s;
5460 gExit := EXIT_ENDLEVELCUSTOM
5461 end
5462 else
5463 begin
5464 g_Game_ChangeMap(s)
5465 end
5466 end
5467 else
5468 begin
5469 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [P[2]]))
5470 end
5471 end
5472 else
5473 begin
5474 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]))
5475 end
5476 end
5477 end
5478 else
5479 begin
5480 g_Console_Add(_lc[I_MSG_GM_UNAVAIL])
5481 end
5482 end
5483 end
5484 else if cmd = 'nextmap' then
5485 begin
5486 if not(gGameOn or (gState = STATE_INTERCUSTOM)) then
5487 begin
5488 g_Console_Add(_lc[I_MSG_NOT_GAME])
5489 end
5490 else
5491 begin
5492 nm := True;
5493 if Length(P) = 1 then
5494 begin
5495 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
5496 begin
5497 g_Console_Add(cmd + ' <MAP>');
5498 g_Console_Add(cmd + ' <WAD> [MAP]');
5499 end
5500 else
5501 begin
5502 nm := False;
5503 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
5504 end;
5505 end
5506 else
5507 begin
5508 nm := False;
5509 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
5510 begin
5511 if Length(P) < 3 then
5512 begin
5513 // first param is map or wad
5514 s := UpperCase(P[1]);
5515 if g_Map_Exist(gGameSettings.WAD + ':\' + s) then
5516 begin
5517 // map founded
5518 gExitByTrigger := False;
5519 gNextMap := s;
5520 nm := True;
5521 end
5522 else
5523 begin
5524 // no such map, found wad
5525 pw := addWadExtension(P[1]);
5526 found := e_FindResource(MapDirs, pw);
5527 if not found then
5528 found := e_FindResource(WadDirs, pw);
5529 P[1] := pw;
5530 g_Console_Add(Format(_lc[I_MSG_NO_MAP_FALLBACK], [s, P[1]]));
5531 if found then
5532 begin
5533 // map not specified, select first map
5534 SetLength(P, 3);
5535 P[2] := g_Game_GetFirstMap(P[1]);
5536 s := P[1] + ':\' + P[2];
5537 if g_Map_Exist(s) then
5538 begin
5539 gExitByTrigger := False;
5540 gNextMap := s;
5541 nm := True
5542 end
5543 else
5544 begin
5545 if P[2] = '' then
5546 g_Console_Add(Format(_lc[I_MSG_NO_MAPS], [P[1]]))
5547 else
5548 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [P[2]]))
5549 end
5550 end
5551 else
5552 begin
5553 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]))
5554 end
5555 end
5556 end
5557 else
5558 begin
5559 // specified two params wad + map
5560 pw := addWadExtension(P[1]);
5561 found := e_FindResource(MapDirs, pw);
5562 if not found then
5563 found := e_FindResource(MapDirs, pw);
5564 P[1] := pw;
5565 if found then
5566 begin
5567 P[2] := UpperCase(P[2]);
5568 s := P[1] + ':\' + P[2];
5569 if g_Map_Exist(s) then
5570 begin
5571 gExitByTrigger := False;
5572 gNextMap := s;
5573 nm := True
5574 end
5575 else
5576 begin
5577 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [P[2]]))
5578 end
5579 end
5580 else
5581 begin
5582 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]))
5583 end
5584 end
5585 end
5586 else
5587 begin
5588 g_Console_Add(_lc[I_MSG_GM_UNAVAIL])
5589 end
5590 end;
5591 if nm then
5592 begin
5593 if gNextMap = '' then
5594 g_Console_Add(_lc[I_MSG_NEXTMAP_UNSET])
5595 else
5596 g_Console_Add(Format(_lc[I_MSG_NEXTMAP_SET], [gNextMap]))
5597 end
5598 end
5599 end
5600 else if (cmd = 'endmap') or (cmd = 'goodbye') then
5601 begin
5602 if not gGameOn then
5603 begin
5604 g_Console_Add(_lc[I_MSG_NOT_GAME])
5605 end
5606 else
5607 begin
5608 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
5609 begin
5610 gExitByTrigger := False;
5611 // next map not specified, try to find trigger EXIT
5612 if (gNextMap = '') and (gTriggers <> nil) then
5613 begin
5614 for a := 0 to High(gTriggers) do
5615 begin
5616 if gTriggers[a].TriggerType = TRIGGER_EXIT then
5617 begin
5618 gExitByTrigger := True;
5619 //gNextMap := gTriggers[a].Data.MapName;
5620 gNextMap := gTriggers[a].tgcMap;
5621 Break
5622 end
5623 end
5624 end;
5625 if gNextMap = '' then
5626 gNextMap := g_Game_GetNextMap();
5627 if not isWadPath(gNextMap) then
5628 s := gGameSettings.WAD + ':\' + gNextMap
5629 else
5630 s := gNextMap;
5631 if g_Map_Exist(s) then
5632 gExit := EXIT_ENDLEVELCUSTOM
5633 else
5634 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [gNextMap]))
5635 end
5636 else
5637 begin
5638 g_Console_Add(_lc[I_MSG_GM_UNAVAIL])
5639 end
5640 end
5641 end
5642 else if (cmd = 'event') then
5643 begin
5644 if (Length(P) <= 1) then
5645 begin
5646 for a := 0 to High(gEvents) do
5647 if gEvents[a].Command = '' then
5648 g_Console_Add(gEvents[a].Name + ' <none>')
5649 else
5650 g_Console_Add(gEvents[a].Name + ' "' + gEvents[a].Command + '"');
5651 Exit;
5652 end;
5653 if (Length(P) = 2) then
5654 begin
5655 for a := 0 to High(gEvents) do
5656 if gEvents[a].Name = P[1] then
5657 if gEvents[a].Command = '' then
5658 g_Console_Add(gEvents[a].Name + ' <none>')
5659 else
5660 g_Console_Add(gEvents[a].Name + ' "' + gEvents[a].Command + '"');
5661 Exit;
5662 end;
5663 for a := 0 to High(gEvents) do
5664 if gEvents[a].Name = P[1] then
5665 begin
5666 gEvents[a].Command := '';
5667 for b := 2 to High(P) do
5668 if Pos(' ', P[b]) = 0 then
5669 gEvents[a].Command := gEvents[a].Command + ' ' + P[b]
5670 else
5671 gEvents[a].Command := gEvents[a].Command + ' "' + P[b] + '"';
5672 gEvents[a].Command := Trim(gEvents[a].Command);
5673 Exit;
5674 end;
5675 end
5676 else if cmd = 'suicide' then
5677 begin
5678 if gGameOn then
5679 begin
5680 if g_Game_IsClient then
5681 MC_SEND_CheatRequest(NET_CHEAT_SUICIDE)
5682 else
5683 begin
5684 if gPlayer1 <> nil then
5685 gPlayer1.Damage(SUICIDE_DAMAGE, gPlayer1.UID, 0, 0, HIT_SELF);
5686 if gPlayer2 <> nil then
5687 gPlayer2.Damage(SUICIDE_DAMAGE, gPlayer2.UID, 0, 0, HIT_SELF);
5688 end;
5689 end;
5690 end
5691 else if cmd = 'screenshot' then
5692 begin
5693 g_TakeScreenShot()
5694 end
5695 else if (cmd = 'weapnext') or (cmd = 'weapprev') then
5696 begin
5697 a := 1 - (ord(cmd[5]) - ord('n'));
5698 if a = -1 then
5699 gWeaponAction[0, WP_PREV] := True;
5700 if a = 1 then
5701 gWeaponAction[0, WP_NEXT] := True;
5702 end
5703 else if cmd = 'weapon' then
5704 begin
5705 if Length(p) = 2 then
5706 begin
5707 a := WP_FIRST + StrToIntDef(p[1], 0) - 1;
5708 if (a >= WP_FIRST) and (a <= WP_LAST) then
5709 gSelectWeapon[0, a] := True
5710 end
5711 end
5712 else if (cmd = 'p1_weapnext') or (cmd = 'p1_weapprev')
5713 or (cmd = 'p2_weapnext') or (cmd = 'p2_weapprev') then
5714 begin
5715 a := 1 - (ord(cmd[8]) - ord('n'));
5716 b := ord(cmd[2]) - ord('1');
5717 if a = -1 then
5718 gWeaponAction[b, WP_PREV] := True;
5719 if a = 1 then
5720 gWeaponAction[b, WP_NEXT] := True;
5721 end
5722 else if (cmd = 'p1_weapon') or (cmd = 'p2_weapon') then
5723 begin
5724 if Length(p) = 2 then
5725 begin
5726 a := WP_FIRST + StrToIntDef(p[1], 0) - 1;
5727 b := ord(cmd[2]) - ord('1');
5728 if (a >= WP_FIRST) and (a <= WP_LAST) then
5729 gSelectWeapon[b, a] := True
5730 end
5731 end
5732 else if (cmd = 'p1_weapbest') or (cmd = 'p2_weapbest') then
5733 begin
5734 b := ord(cmd[2]) - ord('1');
5735 if b = 0 then
5736 gSelectWeapon[b, gPlayer1.GetMorePrefered()] := True
5737 else
5738 gSelectWeapon[b, gPlayer2.GetMorePrefered()] := True;
5739 end
5740 else if (cmd = 'dropflag') then
5741 begin
5742 if g_Game_IsServer then
5743 begin
5744 if gPlayer2 <> nil then gPlayer2.TryDropFlag();
5745 if gPlayer1 <> nil then gPlayer1.TryDropFlag();
5746 end
5747 else
5748 MC_SEND_CheatRequest(NET_CHEAT_DROPFLAG);
5749 end
5750 else if (cmd = 'p1_dropflag') or (cmd = 'p2_dropflag') then
5751 begin
5752 b := ord(cmd[2]) - ord('1');
5753 if g_Game_IsServer then
5754 begin
5755 if (b = 1) and (gPlayer2 <> nil) then gPlayer2.TryDropFlag()
5756 else if (b = 0) and (gPlayer1 <> nil) then gPlayer1.TryDropFlag();
5757 end
5758 else
5759 MC_SEND_CheatRequest(NET_CHEAT_DROPFLAG);
5760 end
5761 // Команды Своей игры:
5762 else if gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT] then
5763 begin
5764 if cmd = 'bot_addred' then
5765 begin
5766 if Length(P) > 1 then
5767 g_Bot_Add(TEAM_RED, StrToIntDef(P[1], 2))
5768 else
5769 g_Bot_Add(TEAM_RED, 2);
5770 end
5771 else if cmd = 'bot_addblue' then
5772 begin
5773 if Length(P) > 1 then
5774 g_Bot_Add(TEAM_BLUE, StrToIntDef(P[1], 2))
5775 else
5776 g_Bot_Add(TEAM_BLUE, 2);
5777 end
5778 else if cmd = 'spectate' then
5779 begin
5780 if not gGameOn then
5781 Exit;
5782 g_Game_Spectate();
5783 end
5784 else if cmd = 'say' then
5785 begin
5786 if g_Game_IsServer and g_Game_IsNet then
5787 begin
5788 if Length(P) > 1 then
5789 begin
5790 chstr := '';
5791 for a := 1 to High(P) do
5792 chstr := chstr + P[a] + ' ';
5794 if Length(chstr) > 200 then SetLength(chstr, 200);
5796 if Length(chstr) < 1 then
5797 begin
5798 g_Console_Add('say <text>');
5799 Exit;
5800 end;
5802 chstr := b_Text_Format(chstr);
5803 MH_SEND_Chat(chstr, NET_CHAT_PLAYER);
5804 end
5805 else g_Console_Add('say <text>');
5806 end else
5807 g_Console_Add(_lc[I_MSG_SERVERONLY]);
5808 end
5809 else if cmd = 'tell' then
5810 begin
5811 if g_Game_IsServer and g_Game_IsNet then
5812 begin
5813 if (Length(P) > 2) and (P[1] <> '') then
5814 begin
5815 chstr := '';
5816 for a := 2 to High(P) do
5817 chstr := chstr + P[a] + ' ';
5819 if Length(chstr) > 200 then SetLength(chstr, 200);
5821 if Length(chstr) < 1 then
5822 begin
5823 g_Console_Add('tell <playername> <text>');
5824 Exit;
5825 end;
5827 pl := g_Net_Client_ByName(P[1]);
5828 if pl <> nil then
5829 MH_SEND_Chat(b_Text_Format(chstr), NET_CHAT_PLAYER, pl^.ID)
5830 else
5831 g_Console_Add(Format(_lc[I_NET_ERR_NAME404], [P[1]]));
5832 end
5833 else g_Console_Add('tell <playername> <text>');
5834 end else
5835 g_Console_Add(_lc[I_MSG_SERVERONLY]);
5836 end
5837 else if cmd = 'centerprint' then
5838 begin
5839 if (Length(P) > 2) and (P[1] <> '') then
5840 begin
5841 chstr := '';
5842 for a := 2 to High(P) do
5843 chstr := chstr + P[a] + ' ';
5845 if Length(chstr) > 200 then SetLength(chstr, 200);
5847 if Length(chstr) < 1 then
5848 begin
5849 g_Console_Add('centerprint <timeout> <text>');
5850 Exit;
5851 end;
5853 a := StrToIntDef(P[1], 100);
5854 chstr := b_Text_Format(chstr);
5855 g_Game_Message(chstr, a);
5856 if g_Game_IsNet and g_Game_IsServer then
5857 MH_SEND_GameEvent(NET_EV_BIGTEXT, a, chstr);
5858 end
5859 else g_Console_Add('centerprint <timeout> <text>');
5860 end
5861 else if (cmd = 'overtime') and not g_Game_IsClient then
5862 begin
5863 if (Length(P) = 1) or (StrToIntDef(P[1], -1) <= 0) then
5864 Exit;
5865 // Дополнительное время:
5866 gGameSettings.TimeLimit := (gTime - gGameStartTime) div 1000 + Word(StrToIntDef(P[1], 0));
5868 g_Console_Add(Format(_lc[I_MSG_TIME_LIMIT],
5869 [gGameSettings.TimeLimit div 3600,
5870 (gGameSettings.TimeLimit div 60) mod 60,
5871 gGameSettings.TimeLimit mod 60]));
5872 if g_Game_IsNet then MH_SEND_GameSettings;
5873 end
5874 else if (cmd = 'rcon_password') and g_Game_IsClient then
5875 begin
5876 if (Length(P) <= 1) then
5877 g_Console_Add('rcon_password <password>')
5878 else
5879 MC_SEND_RCONPassword(P[1]);
5880 end
5881 else if cmd = 'rcon' then
5882 begin
5883 if g_Game_IsClient then
5884 begin
5885 if Length(P) > 1 then
5886 begin
5887 chstr := '';
5888 for a := 1 to High(P) do
5889 chstr := chstr + P[a] + ' ';
5891 if Length(chstr) > 200 then SetLength(chstr, 200);
5893 if Length(chstr) < 1 then
5894 begin
5895 g_Console_Add('rcon <command>');
5896 Exit;
5897 end;
5899 MC_SEND_RCONCommand(chstr);
5900 end
5901 else g_Console_Add('rcon <command>');
5902 end;
5903 end
5904 else if cmd = 'ready' then
5905 begin
5906 if g_Game_IsServer and (gLMSRespawn = LMS_RESPAWN_WARMUP) then
5907 gLMSRespawnTime := gTime + 100;
5908 end
5909 else if (cmd = 'callvote') and g_Game_IsNet then
5910 begin
5911 if Length(P) > 1 then
5912 begin
5913 chstr := '';
5914 for a := 1 to High(P) do begin
5915 if a > 1 then chstr := chstr + ' ';
5916 chstr := chstr + P[a];
5917 end;
5919 if Length(chstr) > 200 then SetLength(chstr, 200);
5921 if Length(chstr) < 1 then
5922 begin
5923 g_Console_Add('callvote <command>');
5924 Exit;
5925 end;
5927 if g_Game_IsClient then
5928 MC_SEND_Vote(True, chstr)
5929 else
5930 g_Game_StartVote(chstr, gPlayer1Settings.Name);
5931 g_Console_Process('vote', True);
5932 end
5933 else
5934 g_Console_Add('callvote <command>');
5935 end
5936 else if (cmd = 'vote') and g_Game_IsNet then
5937 begin
5938 if g_Game_IsClient then
5939 MC_SEND_Vote(False)
5940 else if gVoteInProgress then
5941 begin
5942 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
5943 a := Floor((NetClientCount+1)/2.0) + 1
5944 else
5945 a := Floor(NetClientCount/2.0) + 1;
5946 if gVoted then
5947 begin
5948 Dec(gVoteCount);
5949 gVoted := False;
5950 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_REVOKED], [gPlayer1Settings.Name, gVoteCount, a]), True);
5951 MH_SEND_VoteEvent(NET_VE_REVOKE, gPlayer1Settings.Name, 'a', gVoteCount, a);
5952 end
5953 else
5954 begin
5955 Inc(gVoteCount);
5956 gVoted := True;
5957 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_VOTE], [gPlayer1Settings.Name, gVoteCount, a]), True);
5958 MH_SEND_VoteEvent(NET_VE_VOTE, gPlayer1Settings.Name, 'a', gVoteCount, a);
5959 g_Game_CheckVote;
5960 end;
5961 end;
5962 end
5963 end;
5964 end;
5966 procedure SystemCommands(P: SSArray);
5967 var
5968 cmd: string;
5969 begin
5970 cmd := LowerCase(P[0]);
5971 case cmd of
5972 'exit', 'quit':
5973 begin
5974 g_Game_Free();
5975 g_Game_Quit();
5976 end;
5977 'r_reset':
5978 begin
5979 gRC_Width := Max(1, gRC_Width);
5980 gRC_Height := Max(1, gRC_Height);
5981 gBPP := Max(1, gBPP);
5982 if sys_SetDisplayMode(gRC_Width, gRC_Height, gBPP, gRC_FullScreen, gRC_Maximized) = True then
5983 e_LogWriteln('resolution changed')
5984 else
5985 e_LogWriteln('resolution not changed');
5986 sys_EnableVSync(gVSync);
5987 end;
5988 'r_maxfps':
5989 begin
5990 if Length(p) = 2 then
5991 begin
5992 gMaxFPS := StrToIntDef(p[1], gMaxFPS);
5993 if gMaxFPS > 0 then
5994 gFrameTime := 1000 div gMaxFPS
5995 else
5996 gFrameTime := 0;
5997 end;
5998 e_LogWritefln('r_maxfps %d', [gMaxFPS]);
5999 end;
6000 'g_language':
6001 begin
6002 if Length(p) = 2 then
6003 begin
6004 gAskLanguage := true;
6005 gLanguage := LANGUAGE_ENGLISH;
6006 case LowerCase(p[1]) of
6007 'english':
6008 begin
6009 gAskLanguage := false;
6010 gLanguage := LANGUAGE_ENGLISH;
6011 end;
6012 'russian':
6013 begin
6014 gAskLanguage := false;
6015 gLanguage := LANGUAGE_RUSSIAN;
6016 end;
6017 'ask':
6018 begin
6019 gAskLanguage := true;
6020 gLanguage := LANGUAGE_ENGLISH;
6021 end;
6022 end;
6023 g_Language_Set(gLanguage);
6024 end
6025 else
6026 begin
6027 e_LogWritefln('usage: %s <English|Russian|Ask>', [cmd]);
6028 end
6029 end;
6030 end;
6031 end;
6033 procedure g_TakeScreenShot(Filename: string = '');
6034 var s: TStream; t: TDateTime; dir, date, name: String;
6035 begin
6036 if e_NoGraphics then Exit;
6037 try
6038 dir := e_GetWriteableDir(ScreenshotDirs);
6040 if Filename = '' then
6041 begin
6042 t := Now;
6043 DateTimeToString(date, 'yyyy-mm-dd-hh-nn-ss', t);
6044 Filename := 'screenshot-' + date;
6045 end;
6047 name := e_CatPath(dir, Filename + '.png');
6048 s := createDiskFile(name);
6049 try
6050 e_MakeScreenshot(s, gWinSizeX, gWinSizeY);
6051 s.Free;
6052 g_Console_Add(Format(_lc[I_CONSOLE_SCREENSHOT], [name]))
6053 except
6054 g_Console_Add(Format(_lc[I_CONSOLE_ERROR_WRITE], [name]));
6055 s.Free;
6056 DeleteFile(name)
6057 end
6058 except
6059 g_Console_Add('oh shit, i can''t create screenshot!')
6060 end
6061 end;
6063 procedure g_Game_InGameMenu(Show: Boolean);
6064 begin
6065 if (g_ActiveWindow = nil) and Show then
6066 begin
6067 if gGameSettings.GameType = GT_SINGLE then
6068 g_GUI_ShowWindow('GameSingleMenu')
6069 else
6070 begin
6071 if g_Game_IsClient then
6072 g_GUI_ShowWindow('GameClientMenu')
6073 else
6074 if g_Game_IsNet then
6075 g_GUI_ShowWindow('GameServerMenu')
6076 else
6077 g_GUI_ShowWindow('GameCustomMenu');
6078 end;
6079 g_Sound_PlayEx('MENU_OPEN');
6081 // Пауза при меню только в одиночной игре:
6082 if (not g_Game_IsNet) then
6083 g_Game_Pause(True);
6084 end
6085 else
6086 if (g_ActiveWindow <> nil) and (not Show) then
6087 begin
6088 // Пауза при меню только в одиночной игре:
6089 if (not g_Game_IsNet) then
6090 g_Game_Pause(False);
6091 end;
6092 end;
6094 procedure g_Game_Pause (Enable: Boolean);
6095 var
6096 oldPause: Boolean;
6097 begin
6098 if not gGameOn then exit;
6100 if not (gGameSettings.GameType in [GT_SINGLE, GT_CUSTOM]) then exit;
6102 oldPause := gPause;
6103 gPauseMain := Enable;
6105 if (gPause <> oldPause) then g_Game_PauseAllSounds(gPause);
6106 end;
6108 procedure g_Game_HolmesPause (Enable: Boolean);
6109 var
6110 oldPause: Boolean;
6111 begin
6112 if not gGameOn then exit;
6113 if not (gGameSettings.GameType in [GT_SINGLE, GT_CUSTOM]) then exit;
6115 oldPause := gPause;
6116 gPauseHolmes := Enable;
6118 if (gPause <> oldPause) then g_Game_PauseAllSounds(gPause);
6119 end;
6121 procedure g_Game_PauseAllSounds(Enable: Boolean);
6122 var
6123 i: Integer;
6124 begin
6125 // Триггеры:
6126 if gTriggers <> nil then
6127 for i := 0 to High(gTriggers) do
6128 with gTriggers[i] do
6129 if (TriggerType = TRIGGER_SOUND) and
6130 (Sound <> nil) and
6131 Sound.IsPlaying() then
6132 begin
6133 Sound.Pause(Enable);
6134 end;
6136 // Звуки игроков:
6137 if gPlayers <> nil then
6138 for i := 0 to High(gPlayers) do
6139 if gPlayers[i] <> nil then
6140 gPlayers[i].PauseSounds(Enable);
6142 // Музыка:
6143 if gMusic <> nil then
6144 gMusic.Pause(Enable);
6145 end;
6147 procedure g_Game_StopAllSounds(all: Boolean);
6148 var
6149 i: Integer;
6150 begin
6151 if gTriggers <> nil then
6152 for i := 0 to High(gTriggers) do
6153 with gTriggers[i] do
6154 if (TriggerType = TRIGGER_SOUND) and
6155 (Sound <> nil) then
6156 Sound.Stop();
6158 if gMusic <> nil then
6159 gMusic.Stop();
6161 if all then
6162 e_StopChannels();
6163 end;
6165 procedure g_Game_UpdateTriggerSounds;
6166 var i: Integer;
6167 begin
6168 if gTriggers <> nil then
6169 for i := 0 to High(gTriggers) do
6170 with gTriggers[i] do
6171 if (TriggerType = TRIGGER_SOUND) and (Sound <> nil) and tgcLocal and Sound.IsPlaying() then
6172 Sound.SetCoordsRect(X, Y, Width, Height, tgcVolume / 255.0)
6173 end;
6175 function g_Game_IsWatchedPlayer(UID: Word): Boolean;
6176 begin
6177 Result := False;
6178 if (gPlayer1 <> nil) and (gPlayer1.UID = UID) then
6179 begin
6180 Result := True;
6181 Exit;
6182 end;
6183 if (gPlayer2 <> nil) and (gPlayer2.UID = UID) then
6184 begin
6185 Result := True;
6186 Exit;
6187 end;
6188 if gSpectMode <> SPECT_PLAYERS then
6189 Exit;
6190 if gSpectPID1 = UID then
6191 begin
6192 Result := True;
6193 Exit;
6194 end;
6195 if gSpectViewTwo and (gSpectPID2 = UID) then
6196 begin
6197 Result := True;
6198 Exit;
6199 end;
6200 end;
6202 function g_Game_IsWatchedTeam(Team: Byte): Boolean;
6203 var
6204 Pl: TPlayer;
6205 begin
6206 Result := False;
6207 if (gPlayer1 <> nil) and (gPlayer1.Team = Team) then
6208 begin
6209 Result := True;
6210 Exit;
6211 end;
6212 if (gPlayer2 <> nil) and (gPlayer2.Team = Team) then
6213 begin
6214 Result := True;
6215 Exit;
6216 end;
6217 if gSpectMode <> SPECT_PLAYERS then
6218 Exit;
6219 Pl := g_Player_Get(gSpectPID1);
6220 if (Pl <> nil) and (Pl.Team = Team) then
6221 begin
6222 Result := True;
6223 Exit;
6224 end;
6225 if gSpectViewTwo then
6226 begin
6227 Pl := g_Player_Get(gSpectPID2);
6228 if (Pl <> nil) and (Pl.Team = Team) then
6229 begin
6230 Result := True;
6231 Exit;
6232 end;
6233 end;
6234 end;
6236 procedure g_Game_Message(Msg: string; Time: Word);
6237 begin
6238 MessageLineLength := (gScreenWidth - 204) div e_CharFont_GetMaxWidth(gMenuFont);
6239 MessageText := b_Text_Wrap(b_Text_Format(Msg), MessageLineLength);
6240 MessageTime := Time;
6241 end;
6243 procedure g_Game_ChatSound(Text: String; Taunt: Boolean = True);
6244 const
6245 punct: Array[0..13] of String =
6246 ('.', ',', ':', ';', '!', '?', '(', ')', '''', '"', '/', '\', '*', '^');
6247 var
6248 i, j: Integer;
6249 ok: Boolean;
6250 fpText: String;
6252 function IsPunctuation(S: String): Boolean;
6253 var
6254 i: Integer;
6255 begin
6256 Result := False;
6257 if Length(S) <> 1 then
6258 Exit;
6259 for i := Low(punct) to High(punct) do
6260 if S = punct[i] then
6261 begin
6262 Result := True;
6263 break;
6264 end;
6265 end;
6266 function FilterPunctuation(S: String): String;
6267 var
6268 i: Integer;
6269 begin
6270 for i := Low(punct) to High(punct) do
6271 S := StringReplace(S, punct[i], ' ', [rfReplaceAll]);
6272 Result := S;
6273 end;
6274 begin
6275 ok := False;
6277 if gUseChatSounds and Taunt and (gChatSounds <> nil) and (Pos(': ', Text) > 0) then
6278 begin
6279 // remove player name
6280 Delete(Text, 1, Pos(': ', Text) + 2 - 1);
6281 // for FullWord check
6282 Text := toLowerCase1251(' ' + Text + ' ');
6283 fpText := FilterPunctuation(Text);
6285 for i := 0 to Length(gChatSounds) - 1 do
6286 begin
6287 ok := True;
6288 for j := 0 to Length(gChatSounds[i].Tags) - 1 do
6289 begin
6290 if gChatSounds[i].FullWord and (not IsPunctuation(gChatSounds[i].Tags[j])) then
6291 ok := Pos(' ' + gChatSounds[i].Tags[j] + ' ', fpText) > 0
6292 else
6293 ok := Pos(gChatSounds[i].Tags[j], Text) > 0;
6294 if not ok then
6295 break;
6296 end;
6297 if ok then
6298 begin
6299 gChatSounds[i].Sound.Play();
6300 break;
6301 end;
6302 end;
6303 end;
6304 if not ok then
6305 g_Sound_PlayEx('SOUND_GAME_RADIO');
6306 end;
6308 procedure g_Game_Announce_GoodShot(SpawnerUID: Word);
6309 var
6310 a: Integer;
6311 begin
6312 case gAnnouncer of
6313 ANNOUNCE_NONE:
6314 Exit;
6315 ANNOUNCE_ME,
6316 ANNOUNCE_MEPLUS:
6317 if not g_Game_IsWatchedPlayer(SpawnerUID) then
6318 Exit;
6319 end;
6320 for a := 0 to 3 do
6321 if goodsnd[a].IsPlaying() then
6322 Exit;
6324 goodsnd[Random(4)].Play();
6325 end;
6327 procedure g_Game_Announce_KillCombo(Param: Integer);
6328 var
6329 UID: Word;
6330 c, n: Byte;
6331 Pl: TPlayer;
6332 Name: String;
6333 begin
6334 UID := Param and $FFFF;
6335 c := Param shr 16;
6336 if c < 2 then
6337 Exit;
6339 Pl := g_Player_Get(UID);
6340 if Pl = nil then
6341 Name := '?'
6342 else
6343 Name := Pl.Name;
6345 case c of
6346 2: begin
6347 n := 0;
6348 g_Console_Add(Format(_lc[I_PLAYER_KILL_2X], [Name]), True);
6349 end;
6350 3: begin
6351 n := 1;
6352 g_Console_Add(Format(_lc[I_PLAYER_KILL_3X], [Name]), True);
6353 end;
6354 4: begin
6355 n := 2;
6356 g_Console_Add(Format(_lc[I_PLAYER_KILL_4X], [Name]), True);
6357 end;
6358 else begin
6359 n := 3;
6360 g_Console_Add(Format(_lc[I_PLAYER_KILL_MX], [Name]), True);
6361 end;
6362 end;
6364 case gAnnouncer of
6365 ANNOUNCE_NONE:
6366 Exit;
6367 ANNOUNCE_ME:
6368 if not g_Game_IsWatchedPlayer(UID) then
6369 Exit;
6370 ANNOUNCE_MEPLUS:
6371 if (not g_Game_IsWatchedPlayer(UID)) and (c < 4) then
6372 Exit;
6373 end;
6375 if killsnd[n].IsPlaying() then
6376 killsnd[n].Stop();
6377 killsnd[n].Play();
6378 end;
6380 procedure g_Game_Announce_BodyKill(SpawnerUID: Word);
6381 var
6382 a: Integer;
6383 begin
6384 case gAnnouncer of
6385 ANNOUNCE_NONE:
6386 Exit;
6387 ANNOUNCE_ME:
6388 if not g_Game_IsWatchedPlayer(SpawnerUID) then
6389 Exit;
6390 end;
6391 for a := 0 to 2 do
6392 if hahasnd[a].IsPlaying() then
6393 Exit;
6395 hahasnd[Random(3)].Play();
6396 end;
6398 procedure g_Game_StartVote(Command, Initiator: string);
6399 var
6400 Need: Integer;
6401 begin
6402 if not gVotesEnabled then Exit;
6403 if gGameSettings.GameType <> GT_SERVER then Exit;
6404 if gVoteInProgress or gVotePassed then
6405 begin
6406 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_INPROGRESS], [gVoteCommand]), True);
6407 MH_SEND_VoteEvent(NET_VE_INPROGRESS, gVoteCommand);
6408 Exit;
6409 end;
6410 gVoteInProgress := True;
6411 gVotePassed := False;
6412 gVoteTimer := gTime + gVoteTimeout * 1000;
6413 gVoteCount := 0;
6414 gVoted := False;
6415 gVoteCommand := Command;
6417 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
6418 Need := Floor((NetClientCount+1)/2.0)+1
6419 else
6420 Need := Floor(NetClientCount/2.0)+1;
6421 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_STARTED], [Initiator, Command, Need]), True);
6422 MH_SEND_VoteEvent(NET_VE_STARTED, Initiator, Command, Need);
6423 end;
6425 procedure g_Game_CheckVote;
6426 var
6427 I, Need: Integer;
6428 begin
6429 if gGameSettings.GameType <> GT_SERVER then Exit;
6430 if not gVoteInProgress then Exit;
6432 if (gTime >= gVoteTimer) then
6433 begin
6434 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
6435 Need := Floor((NetClientCount+1)/2.0) + 1
6436 else
6437 Need := Floor(NetClientCount/2.0) + 1;
6438 if gVoteCount >= Need then
6439 begin
6440 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_PASSED], [gVoteCommand]), True);
6441 MH_SEND_VoteEvent(NET_VE_PASSED, gVoteCommand);
6442 gVotePassed := True;
6443 gVoteCmdTimer := gTime + 5000;
6444 end
6445 else
6446 begin
6447 g_Console_Add(_lc[I_MESSAGE_VOTE_FAILED], True);
6448 MH_SEND_VoteEvent(NET_VE_FAILED);
6449 end;
6450 if NetClients <> nil then
6451 for I := Low(NetClients) to High(NetClients) do
6452 if NetClients[i].Used then
6453 NetClients[i].Voted := False;
6454 gVoteInProgress := False;
6455 gVoted := False;
6456 gVoteCount := 0;
6457 end
6458 else
6459 begin
6460 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
6461 Need := Floor((NetClientCount+1)/2.0) + 1
6462 else
6463 Need := Floor(NetClientCount/2.0) + 1;
6464 if gVoteCount >= Need then
6465 begin
6466 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_PASSED], [gVoteCommand]), True);
6467 MH_SEND_VoteEvent(NET_VE_PASSED, gVoteCommand);
6468 gVoteInProgress := False;
6469 gVotePassed := True;
6470 gVoteCmdTimer := gTime + 5000;
6471 gVoted := False;
6472 gVoteCount := 0;
6473 if NetClients <> nil then
6474 for I := Low(NetClients) to High(NetClients) do
6475 if NetClients[i].Used then
6476 NetClients[i].Voted := False;
6477 end;
6478 end;
6479 end;
6481 procedure g_Game_LoadMapList(FileName: string);
6482 var
6483 ListFile: TextFile;
6484 s: string;
6485 begin
6486 MapList := nil;
6487 MapIndex := -1;
6489 if not FileExists(FileName) then Exit;
6491 AssignFile(ListFile, FileName);
6492 Reset(ListFile);
6493 while not EOF(ListFile) do
6494 begin
6495 ReadLn(ListFile, s);
6497 s := Trim(s);
6498 if s = '' then Continue;
6500 SetLength(MapList, Length(MapList)+1);
6501 MapList[High(MapList)] := s;
6502 end;
6503 CloseFile(ListFile);
6504 end;
6506 procedure g_Game_SetDebugMode();
6507 begin
6508 gDebugMode := True;
6509 // Читы (даже в своей игре):
6510 gCheats := True;
6511 end;
6513 procedure g_Game_SetLoadingText(Text: String; Max: Integer; reWrite: Boolean);
6514 var
6515 i: Word;
6516 begin
6517 if Length(LoadingStat.Msgs) = 0 then
6518 Exit;
6520 with LoadingStat do
6521 begin
6522 if not reWrite then
6523 begin // Переходим на следующую строку или скроллируем:
6524 if NextMsg = Length(Msgs) then
6525 begin // scroll
6526 for i := 0 to High(Msgs)-1 do
6527 Msgs[i] := Msgs[i+1];
6528 end
6529 else
6530 Inc(NextMsg);
6531 end else
6532 if NextMsg = 0 then
6533 Inc(NextMsg);
6535 Msgs[NextMsg-1] := Text;
6536 CurValue := 0;
6537 MaxValue := Max;
6538 ShowCount := 0;
6539 PBarWasHere := false;
6540 end;
6542 g_ActiveWindow := nil;
6543 ProcessLoading(True);
6544 end;
6546 procedure g_Game_StepLoading(Value: Integer = -1);
6547 begin
6548 with LoadingStat do
6549 begin
6550 if Value = -1 then
6551 begin
6552 Inc(CurValue);
6553 Inc(ShowCount);
6554 end
6555 else
6556 CurValue := Value;
6558 if (ShowCount > LOADING_SHOW_STEP) or (Value > -1) then
6559 begin
6560 ShowCount := 0;
6561 ProcessLoading(False);
6562 end;
6563 end;
6564 end;
6566 procedure g_Game_ClearLoading();
6567 var
6568 len: Word;
6569 begin
6570 with LoadingStat do
6571 begin
6572 CurValue := 0;
6573 MaxValue := 0;
6574 ShowCount := 0;
6575 len := ((gScreenHeight div 3)*2 - 50) div LOADING_INTERLINE;
6576 if len < 1 then len := 1;
6577 SetLength(Msgs, len);
6578 for len := Low(Msgs) to High(Msgs) do
6579 Msgs[len] := '';
6580 NextMsg := 0;
6581 PBarWasHere := false;
6582 end;
6583 end;
6585 procedure Parse_Params(var pars: TParamStrValues);
6586 var
6587 i: Integer;
6588 s: String;
6589 begin
6590 SetLength(pars, 0);
6591 i := 1;
6592 while i <= ParamCount do
6593 begin
6594 s := ParamStr(i);
6595 if (Length(s) > 1) and (s[1] = '-') then
6596 begin
6597 if (Length(s) > 2) and (s[2] = '-') then
6598 begin // Одиночный параметр
6599 SetLength(pars, Length(pars) + 1);
6600 with pars[High(pars)] do
6601 begin
6602 Name := LowerCase(s);
6603 Value := '+';
6604 end;
6605 end
6606 else
6607 if (i < ParamCount) then
6608 begin // Параметр со значением
6609 Inc(i);
6610 SetLength(pars, Length(pars) + 1);
6611 with pars[High(pars)] do
6612 begin
6613 Name := LowerCase(s);
6614 Value := LowerCase(ParamStr(i));
6615 end;
6616 end;
6617 end;
6619 Inc(i);
6620 end;
6621 end;
6623 function Find_Param_Value(var pars: TParamStrValues; aName: String): String;
6624 var
6625 i: Integer;
6626 begin
6627 Result := '';
6628 for i := 0 to High(pars) do
6629 if pars[i].Name = aName then
6630 begin
6631 Result := pars[i].Value;
6632 Break;
6633 end;
6634 end;
6636 procedure g_Game_Process_Params();
6637 var
6638 pars: TParamStrValues;
6639 map: String;
6640 GMode, n: Byte;
6641 LimT, LimS: Integer;
6642 Opt: LongWord;
6643 Lives: Integer;
6644 s: String;
6645 Port: Integer;
6646 ip: String;
6647 F: TextFile;
6648 begin
6649 Parse_Params(pars);
6651 // Debug mode:
6652 s := Find_Param_Value(pars, '--debug');
6653 if (s <> '') then
6654 begin
6655 g_Game_SetDebugMode();
6656 s := Find_Param_Value(pars, '--netdump');
6657 if (s <> '') then
6658 NetDump := True;
6659 end;
6661 // Connect when game loads
6662 ip := Find_Param_Value(pars, '-connect');
6664 if ip <> '' then
6665 begin
6666 s := Find_Param_Value(pars, '-port');
6667 if (s = '') or not TryStrToInt(s, Port) then
6668 Port := 25666;
6670 s := Find_Param_Value(pars, '-pw');
6672 g_Game_StartClient(ip, Port, s);
6673 Exit;
6674 end;
6676 s := LowerCase(Find_Param_Value(pars, '-dbg-mainwad'));
6677 if (s <> '') then
6678 begin
6679 gDefaultMegawadStart := s;
6680 end;
6682 if (Find_Param_Value(pars, '--dbg-mainwad-restore') <> '') or
6683 (Find_Param_Value(pars, '--dbg-mainwad-default') <> '') then
6684 begin
6685 gDefaultMegawadStart := DF_Default_Megawad_Start;
6686 end;
6688 // Start map when game loads:
6689 map := LowerCase(Find_Param_Value(pars, '-map'));
6690 if isWadPath(map) then
6691 begin
6692 // Game mode:
6693 s := Find_Param_Value(pars, '-gm');
6694 GMode := g_Game_TextToMode(s);
6695 if GMode = GM_NONE then GMode := GM_DM;
6696 if GMode = GM_SINGLE then GMode := GM_COOP;
6698 // Time limit:
6699 s := Find_Param_Value(pars, '-limt');
6700 if (s = '') or (not TryStrToInt(s, LimT)) then
6701 LimT := 0;
6702 if LimT < 0 then
6703 LimT := 0;
6705 // Score limit:
6706 s := Find_Param_Value(pars, '-lims');
6707 if (s = '') or (not TryStrToInt(s, LimS)) then
6708 LimS := 0;
6709 if LimS < 0 then
6710 LimS := 0;
6712 // Lives limit:
6713 s := Find_Param_Value(pars, '-lives');
6714 if (s = '') or (not TryStrToInt(s, Lives)) then
6715 Lives := 0;
6716 if Lives < 0 then
6717 Lives := 0;
6719 // Options:
6720 s := Find_Param_Value(pars, '-opt');
6721 if (s = '') then
6722 Opt := gsGameFlags
6723 else
6724 Opt := StrToIntDef(s, 0);
6726 // Close after map:
6727 s := Find_Param_Value(pars, '--close');
6728 if (s <> '') then
6729 gMapOnce := True;
6731 // Override map to test:
6732 s := LowerCase(Find_Param_Value(pars, '-testmap'));
6733 if s <> '' then
6734 begin
6735 if e_IsValidResourceName(s) then
6736 e_FindResource(AllMapDirs, s);
6737 gTestMap := ExpandFileName(s);
6738 end;
6740 // Delete test map after play:
6741 s := Find_Param_Value(pars, '--testdelete');
6742 if (s <> '') then
6743 begin
6744 //gMapToDelete := MapsDir + map;
6745 e_WriteLog('"--testdelete" is deprecated, use --tempdelete.', TMsgType.Fatal);
6746 Halt(1);
6747 end;
6749 // Delete temporary WAD after play:
6750 s := Find_Param_Value(pars, '--tempdelete');
6751 if (s <> '') and (gTestMap <> '') then
6752 begin
6753 gMapToDelete := gTestMap;
6754 gTempDelete := True;
6755 end;
6757 // Number of players:
6758 s := Find_Param_Value(pars, '-pl');
6759 if (s = '') then
6760 n := DEFAULT_PLAYERS
6761 else
6762 n := StrToIntDef(s, DEFAULT_PLAYERS);
6764 // Start:
6765 s := Find_Param_Value(pars, '-port');
6766 if (s = '') or not TryStrToInt(s, Port) then
6767 g_Game_StartCustom(map, GMode, LimT, LimS, Lives, Opt, n)
6768 else
6769 g_Game_StartServer(map, GMode, LimT, LimS, Lives, Opt, n, 0, Port);
6770 end;
6772 // Execute script when game loads:
6773 s := Find_Param_Value(pars, '-exec');
6774 if s <> '' then
6775 begin
6776 // if not isWadPath(s) then
6777 // s := GameDir + '/' + s;
6779 {$I-}
6780 AssignFile(F, s);
6781 Reset(F);
6782 if IOResult <> 0 then
6783 begin
6784 e_WriteLog(Format(_lc[I_SIMPLE_ERROR], ['Failed to read file: ' + s]), TMsgType.Warning);
6785 g_Console_Add(Format(_lc[I_CONSOLE_ERROR_READ], [s]));
6786 CloseFile(F);
6787 Exit;
6788 end;
6789 e_WriteLog('Executing script: ' + s, TMsgType.Notify);
6790 g_Console_Add(Format(_lc[I_CONSOLE_EXEC], [s]));
6792 while not EOF(F) do
6793 begin
6794 ReadLn(F, s);
6795 if IOResult <> 0 then
6796 begin
6797 e_WriteLog(Format(_lc[I_SIMPLE_ERROR], ['Failed to read file: ' + s]), TMsgType.Warning);
6798 g_Console_Add(Format(_lc[I_CONSOLE_ERROR_READ], [s]));
6799 CloseFile(F);
6800 Exit;
6801 end;
6802 if Pos('#', s) <> 1 then // script comment
6803 g_Console_Process(s, True);
6804 end;
6806 CloseFile(F);
6807 {$I+}
6808 end;
6810 SetLength(pars, 0);
6811 end;
6813 begin
6814 conRegVar('pf_draw_frame', @g_profile_frame_draw, 'draw frame rendering profiles', 'render profiles');
6815 //conRegVar('pf_update_frame', @g_profile_frame_update, 'draw frame updating profiles', 'update profiles');
6816 conRegVar('pf_coldet', @g_profile_collision, 'draw collision detection profiles', 'coldet profiles');
6817 conRegVar('pf_los', @g_profile_los, 'draw monster LOS profiles', 'monster LOS profiles');
6819 conRegVar('r_sq_draw', @gdbg_map_use_accel_render, 'accelerated spatial queries in rendering', 'accelerated rendering');
6820 conRegVar('cd_sq_enabled', @gdbg_map_use_accel_coldet, 'accelerated spatial queries in map coldet', 'accelerated map coldet');
6821 conRegVar('mon_sq_enabled', @gmon_debug_use_sqaccel, 'accelerated spatial queries for monsters', 'accelerated monster coldet');
6822 conRegVar('wtrace_sq_enabled', @gwep_debug_fast_trace, 'accelerated spatial queries for weapon hitscan trace', 'accelerated weapon hitscan');
6824 conRegVar('pr_enabled', @gpart_dbg_enabled, 'enable/disable particles', 'particles');
6825 conRegVar('pr_phys_enabled', @gpart_dbg_phys_enabled, 'enable/disable particle physics', 'particle physics');
6827 conRegVar('los_enabled', @gmon_dbg_los_enabled, 'enable/disable monster LOS calculations', 'monster LOS', true);
6828 conRegVar('mon_think', @gmon_debug_think, 'enable/disable monster thinking', 'monster thinking', true);
6830 {$IFDEF ENABLE_HOLMES}
6831 conRegVar('dbg_holmes', @g_holmes_enabled, 'enable/disable Holmes', 'Holmes', true);
6832 {$ENDIF}
6834 conRegVar('dbg_ignore_level_bounds', @g_dbg_ignore_bounds, 'ignore level bounds', '', false);
6836 conRegVar('r_scale', @g_dbg_scale, 0.01, 100.0, 'render scale', '', false);
6837 conRegVar('r_resolution_scale', @r_pixel_scale, 0.01, 100.0, 'upscale factor', '', false);
6839 conRegVar('light_enabled', @gwin_k8_enable_light_experiments, 'enable/disable dynamic lighting', 'lighting');
6840 conRegVar('light_player_halo', @g_playerLight, 'enable/disable player halo', 'player light halo');
6842 conRegVar('r_smallmap_align_h', @r_smallmap_h, 'halign: 0: left; 1: center; 2: right', 'horizontal aligning of small maps');
6843 conRegVar('r_smallmap_align_v', @r_smallmap_v, 'valign: 0: top; 1: center; 2: bottom', 'vertial aligning of small maps');
6845 conRegVar('r_showfps', @gShowFPS, 'draw fps counter', 'draw fps counter');
6846 conRegVar('r_showtime', @gShowTime, 'show game time', 'show game time');
6847 conRegVar('r_showping', @gShowPing, 'show ping', 'show ping');
6848 conRegVar('r_showscore', @gShowScore, 'show score', 'show score');
6849 conRegVar('r_showkillmsg', @gShowKillMsg, 'show kill log', 'show kill log');
6850 conRegVar('r_showlives', @gShowLives, 'show lives', 'show lives');
6851 conRegVar('r_showspect', @gSpectHUD, 'show spectator hud', 'show spectator hud');
6852 conRegVar('r_showstat', @gShowStat, 'show stats', 'show stats');
6853 conRegVar('r_showpids', @gShowPIDs, 'show PIDs', 'show PIDs');
6854 end.