DEADSOFTWARE

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