DEADSOFTWARE

110fbe47c7e7435e82d8b5bede3ca16572e5f73f
[d2df-sdl.git] / src / game / g_game.pas
1 (* Copyright (C) Doom 2D: Forever Developers
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, version 3 of the License ONLY.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14 *)
15 {$INCLUDE ../shared/a_modes.inc}
16 unit g_game;
18 interface
20 uses
21 SysUtils, Classes,
22 MAPDEF,
23 g_basic, g_player, e_graphics, g_res_downloader,
24 g_sound, g_gui, utils, md5, mempool, xprofiler,
25 g_touch, g_weapons;
27 type
28 TGameSettings = record
29 GameType: Byte;
30 GameMode: Byte;
31 TimeLimit: Word;
32 ScoreLimit: Word;
33 WarmupTime: Word;
34 SpawnInvul: Word;
35 ItemRespawnTime: Word;
36 ItemRespawnRandom: Word;
37 PowerupRespawnTime: Word;
38 PowerupRespawnRandom: Word;
39 MaxLives: Byte;
40 Options: LongWord;
41 WAD: String;
42 end;
44 TGameEvent = record
45 Name: String;
46 Command: String;
47 end;
49 TDelayedEvent = record
50 Pending: Boolean;
51 Time: LongWord;
52 DEType: Byte;
53 DENum: Integer;
54 DEStr: String;
55 end;
57 TChatSound = record
58 Sound: TPlayableSound;
59 Tags: Array of String;
60 FullWord: Boolean;
61 end;
63 TPlayerSettings = record
64 Name: String;
65 Model: String;
66 Color: TRGB;
67 Team: Byte;
68 // ones below are sent only to the server
69 WeaponSwitch: Byte;
70 WeaponPreferences: Array[WP_FIRST..WP_LAST+1] of Byte;
71 SwitchToEmpty: Byte;
72 SkipIronFist: Byte;
73 end;
75 TMegaWADInfo = record
76 Name: String;
77 Description: String;
78 Author: String;
79 Pic: String;
80 end;
82 THearPoint = record
83 Active: Boolean;
84 Coords: TDFPoint;
85 end;
87 function g_Game_IsNet(): Boolean;
88 function g_Game_IsServer(): Boolean;
89 function g_Game_IsClient(): Boolean;
90 procedure g_Game_Init();
91 procedure g_Game_Free (freeTextures: Boolean=true);
92 procedure g_Game_LoadData();
93 procedure g_Game_FreeData();
94 procedure g_Game_Update();
95 procedure g_Game_PreUpdate();
96 procedure g_Game_Draw();
97 procedure g_Game_Quit();
98 procedure g_Game_SetupScreenSize();
99 procedure g_Game_ChangeResolution(newWidth, newHeight: Word; nowFull, nowMax: Boolean);
100 function g_Game_ModeToText(Mode: Byte): string;
101 function g_Game_TextToMode(Mode: string): Byte;
102 procedure g_Game_ExecuteEvent(Name: String);
103 function g_Game_DelayEvent(DEType: Byte; Time: LongWord; Num: Integer = 0; Str: String = ''): Integer;
104 procedure g_Game_AddPlayer(Team: Byte = TEAM_NONE);
105 procedure g_Game_RemovePlayer();
106 procedure g_Game_Spectate();
107 procedure g_Game_SpectateCenterView();
108 procedure g_Game_StartSingle(Map: String; TwoPlayers: Boolean; nPlayers: Byte);
109 procedure g_Game_StartCustom(Map: String; GameMode: Byte; TimeLimit, ScoreLimit: Word; MaxLives: Byte; Options: LongWord; nPlayers: Byte);
110 procedure g_Game_StartServer(Map: String; GameMode: Byte; TimeLimit, ScoreLimit: Word; MaxLives: Byte; Options: LongWord; nPlayers: Byte; IPAddr: LongWord; Port: Word);
111 procedure g_Game_StartClient(Addr: String; Port: Word; PW: String);
112 procedure g_Game_Restart();
113 procedure g_Game_RestartLevel();
114 procedure g_Game_RestartRound(NoMapRestart: Boolean = False);
115 function g_Game_ClientWAD (NewWAD: String; const WHash: TMD5Digest): AnsiString;
116 function g_Game_StartMap(asMegawad: Boolean; Map: String; Force: Boolean = False; const oldMapPath: AnsiString=''): Boolean;
117 procedure g_Game_ChangeMap(const MapPath: String);
118 procedure g_Game_ExitLevel(const Map: AnsiString);
119 function g_Game_GetFirstMap(WAD: String): String;
120 function g_Game_GetNextMap(): String;
121 procedure g_Game_NextLevel();
122 procedure g_Game_Pause(Enable: Boolean);
123 procedure g_Game_HolmesPause(Enable: Boolean);
124 procedure g_Game_InGameMenu(Show: Boolean);
125 function g_Game_IsWatchedPlayer(UID: Word): Boolean;
126 function g_Game_IsWatchedTeam(Team: Byte): Boolean;
127 procedure g_Game_Message(Msg: String; Time: Word);
128 procedure g_Game_LoadMapList(FileName: String);
129 procedure g_Game_PauseAllSounds(Enable: Boolean);
130 procedure g_Game_StopAllSounds(all: Boolean);
131 procedure g_Game_UpdateTriggerSounds();
132 function g_Game_GetMegaWADInfo(WAD: String): TMegaWADInfo;
133 procedure g_Game_ChatSound(Text: String; Taunt: Boolean = True);
134 procedure g_Game_Announce_GoodShot(SpawnerUID: Word);
135 procedure g_Game_Announce_KillCombo(Param: Integer);
136 procedure g_Game_Announce_BodyKill(SpawnerUID: Word);
137 procedure g_Game_Effect_Bubbles(fX, fY: Integer; count: Word; devX, devY: Byte; Silent: Boolean = False);
138 procedure g_Game_StartVote(Command, Initiator: string);
139 procedure g_Game_CheckVote;
140 procedure g_TakeScreenShot(Filename: string = '');
141 procedure g_FatalError(Text: String);
142 procedure g_SimpleError(Text: String);
143 function g_Game_IsTestMap(): Boolean;
144 procedure g_Game_DeleteTestMap();
145 procedure GameCVars(P: SSArray);
146 procedure PlayerSettingsCVars(P: SSArray);
147 procedure SystemCommands(P: SSArray);
148 procedure GameCommands(P: SSArray);
149 procedure GameCheats(P: SSArray);
150 procedure DebugCommands(P: SSArray);
151 procedure g_Game_Process_Params;
152 procedure g_Game_SetLoadingText(Text: String; Max: Integer; reWrite: Boolean);
153 procedure g_Game_StepLoading(Value: Integer = -1);
154 procedure g_Game_ClearLoading();
155 procedure g_Game_SetDebugMode();
156 procedure DrawLoadingStat();
157 procedure DrawMenuBackground(tex: AnsiString);
159 { procedure SetWinPause(Enable: Boolean); }
161 const
162 GAME_TICK = 28;
164 LOADING_SHOW_STEP = 100;
165 LOADING_INTERLINE = 20;
167 GT_NONE = 0;
168 GT_SINGLE = 1;
169 GT_CUSTOM = 2;
170 GT_SERVER = 3;
171 GT_CLIENT = 4;
173 GM_NONE = 0;
174 GM_DM = 1;
175 GM_TDM = 2;
176 GM_CTF = 3;
177 GM_COOP = 4;
178 GM_SINGLE = 5;
180 MESSAGE_DIKEY = WM_USER + 1;
182 EXIT_QUIT = 1;
183 EXIT_SIMPLE = 2;
184 EXIT_RESTART = 3;
185 EXIT_ENDLEVELSINGLE = 4;
186 EXIT_ENDLEVELCUSTOM = 5;
188 GAME_OPTION_RESERVED = 1 shl 0;
189 GAME_OPTION_TEAMDAMAGE = 1 shl 1;
190 GAME_OPTION_ALLOWEXIT = 1 shl 2;
191 GAME_OPTION_WEAPONSTAY = 1 shl 3;
192 GAME_OPTION_MONSTERS = 1 shl 4;
193 GAME_OPTION_BOTVSPLAYER = 1 shl 5;
194 GAME_OPTION_BOTVSMONSTER = 1 shl 6;
195 GAME_OPTION_DMKEYS = 1 shl 7;
196 GAME_OPTION_TEAMHITTRACE = 1 shl 8;
197 GAME_OPTION_TEAMHITPROJECTILE = 1 shl 9;
198 GAME_OPTION_TEAMABSORBDAMAGE = 1 shl 10;
199 GAME_OPTION_ALLOWDROPFLAG = 1 shl 11;
200 GAME_OPTION_THROWFLAG = 1 shl 12;
201 GAME_OPTION_POWERUPRANDOM = 1 shl 13;
202 GAME_OPTION_ITEMALLRANDOM = 1 shl 14;
203 GAME_OPTION_ITEMHELPRANDOM = 1 shl 15;
204 GAME_OPTION_ITEMAMMORANDOM = 1 shl 16;
205 GAME_OPTION_ITEMWEAPONRANDOM = 1 shl 17;
207 STATE_NONE = 0;
208 STATE_MENU = 1;
209 STATE_FOLD = 2;
210 STATE_INTERCUSTOM = 3;
211 STATE_INTERSINGLE = 4;
212 STATE_INTERTEXT = 5;
213 STATE_INTERPIC = 6;
214 STATE_ENDPIC = 7;
215 STATE_SLIST = 8;
217 LMS_RESPAWN_NONE = 0;
218 LMS_RESPAWN_WARMUP = 1;
219 LMS_RESPAWN_FINAL = 2;
221 SPECT_NONE = 0;
222 SPECT_STATS = 1;
223 SPECT_MAPVIEW = 2;
224 SPECT_PLAYERS = 3;
226 DE_GLOBEVENT = 0;
227 DE_BFGHIT = 1;
228 DE_KILLCOMBO = 2;
229 DE_BODYKILL = 3;
231 ANNOUNCE_NONE = 0;
232 ANNOUNCE_ME = 1;
233 ANNOUNCE_MEPLUS = 2;
234 ANNOUNCE_ALL = 3;
236 CONFIG_FILENAME = 'Doom2DF.cfg';
238 TEST_MAP_NAME = '$$$_TEST_$$$';
240 STD_PLAYER_MODEL = 'Doomer';
242 {$IFDEF HEADLESS}
243 DEFAULT_PLAYERS = 0;
244 {$ELSE}
245 DEFAULT_PLAYERS = 1;
246 {$ENDIF}
248 STATFILE_VERSION = $03;
250 var
251 gStdFont: DWORD;
252 gGameSettings: TGameSettings;
253 gPlayer1Settings: TPlayerSettings;
254 gPlayer2Settings: TPlayerSettings;
255 gGameOn: Boolean;
256 gPlayerScreenSize: TDFPoint;
257 gPlayer1ScreenCoord: TDFPoint;
258 gPlayer2ScreenCoord: TDFPoint;
259 gPlayer1: TPlayer = nil;
260 gPlayer2: TPlayer = nil;
261 gPlayerDrawn: TPlayer = nil;
262 gTime: LongWord;
263 gLerpFactor: Single = 1.0;
264 gSwitchGameMode: Byte = GM_DM;
265 gHearPoint1, gHearPoint2: THearPoint;
266 gSoundEffectsDF: Boolean = False;
267 gSoundTriggerTime: Word = 0;
268 gAnnouncer: Integer = ANNOUNCE_NONE;
269 goodsnd: array[0..3] of TPlayableSound;
270 killsnd: array[0..3] of TPlayableSound;
271 hahasnd: array[0..2] of TPlayableSound;
272 sound_get_flag: array[0..1] of TPlayableSound;
273 sound_lost_flag: array[0..1] of TPlayableSound;
274 sound_ret_flag: array[0..1] of TPlayableSound;
275 sound_cap_flag: array[0..1] of TPlayableSound;
276 gBodyKillEvent: Integer = -1;
277 gDefInterTime: ShortInt = -1;
278 gInterEndTime: LongWord = 0;
279 gInterTime: LongWord = 0;
280 gServInterTime: Byte = 0;
281 gGameStartTime: LongWord = 0;
282 gTotalMonsters: Integer = 0;
283 gPauseMain: Boolean = false;
284 gPauseHolmes: Boolean = false;
285 gShowTime: Boolean = False;
286 gShowFPS: Boolean = False;
287 gShowScore: Boolean = True;
288 gShowStat: Boolean = True;
289 gShowPIDs: Boolean = False;
290 gShowKillMsg: Boolean = True;
291 gShowLives: Boolean = True;
292 gShowPing: Boolean = False;
293 gShowMap: Boolean = False;
294 gExit: Byte = 0;
295 gState: Byte = STATE_NONE;
296 sX, sY: Integer;
297 sWidth, sHeight: Word;
298 gSpectMode: Byte = SPECT_NONE;
299 gSpectHUD: Boolean = True;
300 gSpectKeyPress: Boolean = False;
301 gSpectX: Integer = 0;
302 gSpectY: Integer = 0;
303 gSpectStep: Byte = 8;
304 gSpectViewTwo: Boolean = False;
305 gSpectPID1: Integer = -1;
306 gSpectPID2: Integer = -1;
307 gSpectAuto: Boolean = False;
308 gSpectAutoNext: LongWord;
309 gSpectAutoStepX: Integer;
310 gSpectAutoStepY: Integer;
311 gMusic: TMusic = nil;
312 gLoadGameMode: Boolean;
313 gCheats: Boolean = False;
314 gMapOnce: Boolean = False;
315 gMapToDelete: String;
316 gTempDelete: Boolean = False;
317 gLastMap: Boolean = False;
318 gScreenWidth: Word;
319 gScreenHeight: Word;
320 gResolutionChange: Boolean = False;
321 gRC_Width, gRC_Height: Integer;
322 gRC_FullScreen, gRC_Maximized: Boolean;
323 gLanguageChange: Boolean = False;
324 gDebugMode: Boolean = False;
325 g_debug_Sounds: Boolean = False;
326 g_debug_Frames: Boolean = False;
327 g_debug_WinMsgs: Boolean = False;
328 g_debug_MonsterOff: Boolean = False;
329 g_debug_BotAIOff: Byte = 0;
330 g_debug_HealthBar: Boolean = False;
331 g_Debug_Player: Boolean = False;
332 gCoopMonstersKilled: Word = 0;
333 gCoopSecretsFound: Word = 0;
334 gCoopTotalMonstersKilled: Word = 0;
335 gCoopTotalSecretsFound: Word = 0;
336 gCoopTotalMonsters: Word = 0;
337 gCoopTotalSecrets: Word = 0;
338 gStatsOff: Boolean = False;
339 gStatsPressed: Boolean = False;
340 gExitByTrigger: Boolean = False;
341 gNextMap: String = '';
342 gLMSRespawn: Byte = LMS_RESPAWN_NONE;
343 gLMSRespawnTime: Cardinal = 0;
344 gLMSSoftSpawn: Boolean = False;
345 gMissionFailed: Boolean = False;
346 gVoteInProgress: Boolean = False;
347 gVotePassed: Boolean = False;
348 gVoteCommand: string = '';
349 gVoteTimer: Cardinal = 0;
350 gVoteCmdTimer: Cardinal = 0;
351 gVoteCount: Integer = 0;
352 gVoteTimeout: Cardinal = 30;
353 gVoted: Boolean = False;
354 gVotesEnabled: Boolean = True;
355 gEvents: Array of TGameEvent;
356 gDelayedEvents: Array of TDelayedEvent;
357 gUseChatSounds: Boolean = True;
358 gChatSounds: Array of TChatSound;
359 gWeaponAction: Array [0..1, WP_FACT..WP_LACT] of Boolean; // [player, weapon_action]
360 gSelectWeapon: Array [0..1, WP_FIRST..WP_LAST] of Boolean; // [player, weapon]
361 gInterReadyCount: Integer = 0;
362 gMaxBots: Integer = 127;
364 g_dbg_ignore_bounds: Boolean = false;
365 r_smallmap_h: Integer = 0; // 0: left; 1: center; 2: right
366 r_smallmap_v: Integer = 2; // 0: top; 1: center; 2: bottom
368 // move button values:
369 // bits 0-1: l/r state:
370 // 0: neither left, nor right pressed
371 // 1: left pressed
372 // 2: right pressed
373 // bits 4-5: l/r state when strafe was pressed
374 P1MoveButton: Byte = 0;
375 P2MoveButton: Byte = 0;
377 g_profile_frame_update: Boolean = false;
378 g_profile_frame_draw: Boolean = false;
379 g_profile_collision: Boolean = false;
380 g_profile_los: Boolean = false;
381 g_profile_history_size: Integer = 1000;
383 g_rlayer_back: Boolean = true;
384 g_rlayer_step: Boolean = true;
385 g_rlayer_wall: Boolean = true;
386 g_rlayer_door: Boolean = true;
387 g_rlayer_acid1: Boolean = true;
388 g_rlayer_acid2: Boolean = true;
389 g_rlayer_water: Boolean = true;
390 g_rlayer_fore: Boolean = true;
393 procedure g_ResetDynlights ();
394 procedure g_AddDynLight (x, y, radius: Integer; r, g, b, a: Single);
395 procedure g_DynLightExplosion (x, y, radius: Integer; r, g, b: Single);
397 function conIsCheatsEnabled (): Boolean; inline;
398 function gPause (): Boolean; inline;
401 implementation
403 uses
404 {$INCLUDE ../nogl/noGLuses.inc}
405 {$IFDEF ENABLE_HOLMES}
406 g_holmes,
407 {$ENDIF}
408 e_texture, e_res, g_textures, g_window, g_menu,
409 e_input, e_log, g_console, g_items, g_map, g_panel,
410 g_playermodel, g_gfx, g_options, Math,
411 g_triggers, g_monsters, e_sound, CONFIG,
412 g_language, g_net, g_main, g_phys,
413 ENet, e_msg, g_netmsg, g_netmaster,
414 sfs, wadreader, g_system;
417 var
418 hasPBarGfx: Boolean = false;
421 // ////////////////////////////////////////////////////////////////////////// //
422 function gPause (): Boolean; inline; begin result := gPauseMain or gPauseHolmes; end;
425 // ////////////////////////////////////////////////////////////////////////// //
426 function conIsCheatsEnabled (): Boolean; inline;
427 begin
428 result := false;
429 if g_Game_IsNet then exit;
430 if not gDebugMode then
431 begin
432 //if not gCheats then exit;
433 if not (gGameSettings.GameType in [GT_SINGLE, GT_CUSTOM]) then exit;
434 if not (gGameSettings.GameMode in [GM_COOP, GM_SINGLE]) then exit;
435 end;
436 result := true;
437 end;
440 // ////////////////////////////////////////////////////////////////////////// //
441 var
442 profileFrameDraw: TProfiler = nil;
445 // ////////////////////////////////////////////////////////////////////////// //
446 type
447 TDynLight = record
448 x, y, radius: Integer;
449 r, g, b, a: Single;
450 exploCount: Integer;
451 exploRadius: Integer;
452 end;
454 var
455 g_dynLights: array of TDynLight = nil;
456 g_dynLightCount: Integer = 0;
457 g_playerLight: Boolean = false;
459 procedure g_ResetDynlights ();
460 var
461 lnum, idx: Integer;
462 begin
463 if not gwin_has_stencil then begin g_dynLightCount := 0; exit; end;
464 lnum := 0;
465 for idx := 0 to g_dynLightCount-1 do
466 begin
467 if g_dynLights[idx].exploCount = -666 then
468 begin
469 // skip it
470 end
471 else
472 begin
473 // explosion
474 Inc(g_dynLights[idx].exploCount);
475 if (g_dynLights[idx].exploCount < 10) then
476 begin
477 g_dynLights[idx].radius := g_dynLights[idx].exploRadius+g_dynLights[idx].exploCount*8;
478 g_dynLights[idx].a := 0.4+g_dynLights[idx].exploCount/10;
479 if (g_dynLights[idx].a > 0.8) then g_dynLights[idx].a := 0.8;
480 if lnum <> idx then g_dynLights[lnum] := g_dynLights[idx];
481 Inc(lnum);
482 end;
483 end;
484 end;
485 g_dynLightCount := lnum;
486 end;
488 procedure g_AddDynLight (x, y, radius: Integer; r, g, b, a: Single);
489 begin
490 if not gwin_has_stencil then exit;
491 if g_dynLightCount = length(g_dynLights) then SetLength(g_dynLights, g_dynLightCount+1024);
492 g_dynLights[g_dynLightCount].x := x;
493 g_dynLights[g_dynLightCount].y := y;
494 g_dynLights[g_dynLightCount].radius := radius;
495 g_dynLights[g_dynLightCount].r := r;
496 g_dynLights[g_dynLightCount].g := g;
497 g_dynLights[g_dynLightCount].b := b;
498 g_dynLights[g_dynLightCount].a := a;
499 g_dynLights[g_dynLightCount].exploCount := -666;
500 Inc(g_dynLightCount);
501 end;
503 procedure g_DynLightExplosion (x, y, radius: Integer; r, g, b: Single);
504 begin
505 if not gwin_has_stencil then exit;
506 if g_dynLightCount = length(g_dynLights) then SetLength(g_dynLights, g_dynLightCount+1024);
507 g_dynLights[g_dynLightCount].x := x;
508 g_dynLights[g_dynLightCount].y := y;
509 g_dynLights[g_dynLightCount].radius := 0;
510 g_dynLights[g_dynLightCount].exploRadius := radius;
511 g_dynLights[g_dynLightCount].r := r;
512 g_dynLights[g_dynLightCount].g := g;
513 g_dynLights[g_dynLightCount].b := b;
514 g_dynLights[g_dynLightCount].a := 0;
515 g_dynLights[g_dynLightCount].exploCount := 0;
516 Inc(g_dynLightCount);
517 end;
520 // ////////////////////////////////////////////////////////////////////////// //
521 function calcProfilesHeight (prof: TProfiler): Integer;
522 begin
523 result := 0;
524 if (prof = nil) then exit;
525 if (length(prof.bars) = 0) then exit;
526 result := length(prof.bars)*(16+2);
527 end;
529 // returns width
530 function drawProfiles (x, y: Integer; prof: TProfiler): Integer;
531 var
532 wdt, hgt: Integer;
533 yy: Integer;
534 ii: Integer;
535 begin
536 result := 0;
537 if (prof = nil) then exit;
538 // gScreenWidth
539 if (length(prof.bars) = 0) then exit;
540 wdt := 192;
541 hgt := calcProfilesHeight(prof);
542 if (x < 0) then x := gScreenWidth-(wdt-1)+x;
543 if (y < 0) then y := gScreenHeight-(hgt-1)+y;
544 // background
545 //e_DrawFillQuad(x, y, x+wdt-1, y+hgt-1, 255, 255, 255, 200, B_BLEND);
546 //e_DrawFillQuad(x, y, x+wdt-1, y+hgt-1, 20, 20, 20, 0, B_NONE);
547 e_DarkenQuadWH(x, y, wdt, hgt, 150);
548 // title
549 yy := y+2;
550 for ii := 0 to High(prof.bars) do
551 begin
552 e_TextureFontPrintEx(x+2+4*prof.bars[ii].level, yy, Format('%s: %d', [prof.bars[ii].name, prof.bars[ii].value]), gStdFont, 255, 255, 0, 1, false);
553 Inc(yy, 16+2);
554 end;
555 result := wdt;
556 end;
559 // ////////////////////////////////////////////////////////////////////////// //
560 type
561 TEndCustomGameStat = record
562 PlayerStat: TPlayerStatArray;
563 TeamStat: TTeamStat;
564 GameTime: LongWord;
565 GameMode: Byte;
566 Map, MapName: String;
567 end;
569 TEndSingleGameStat = record
570 PlayerStat: Array [0..1] of record
571 Kills: Integer;
572 Secrets: Integer;
573 end;
574 GameTime: LongWord;
575 TwoPlayers: Boolean;
576 TotalSecrets: Integer;
577 end;
579 TLoadingStat = record
580 CurValue: Integer;
581 MaxValue: Integer;
582 ShowCount: Integer;
583 Msgs: Array of String;
584 NextMsg: Word;
585 PBarWasHere: Boolean; // did we draw a progress bar for this message?
586 end;
588 TParamStrValue = record
589 Name: String;
590 Value: String;
591 end;
593 TParamStrValues = Array of TParamStrValue;
595 const
596 INTER_ACTION_TEXT = 1;
597 INTER_ACTION_PIC = 2;
598 INTER_ACTION_MUSIC = 3;
600 var
601 FPS, UPS: Word;
602 FPSCounter, UPSCounter: Word;
603 FPSTime, UPSTime: LongWord;
604 DataLoaded: Boolean = False;
605 IsDrawStat: Boolean = False;
606 CustomStat: TEndCustomGameStat;
607 SingleStat: TEndSingleGameStat;
608 LoadingStat: TLoadingStat;
609 EndingGameCounter: Byte = 0;
610 MessageText: String;
611 MessageTime: Word;
612 MessageLineLength: Integer = 80;
613 MapList: SSArray = nil;
614 MapIndex: Integer = -1;
615 InterReadyTime: Integer = -1;
616 StatShotDone: Boolean = False;
617 StatFilename: string = ''; // used by stat screenshot to save with the same name as the csv
618 StatDate: string = '';
619 MegaWAD: record
620 info: TMegaWADInfo;
621 endpic: String;
622 endmus: String;
623 res: record
624 text: Array of ShortString;
625 anim: Array of ShortString;
626 pic: Array of ShortString;
627 mus: Array of ShortString;
628 end;
629 triggers: Array of record
630 event: ShortString;
631 actions: Array of record
632 action, p1, p2: Integer;
633 end;
634 end;
635 cur_trigger: Integer;
636 cur_action: Integer;
637 end;
638 //InterPic: String;
639 InterText: record
640 lines: SSArray;
641 img: String;
642 cur_line: Integer;
643 cur_char: Integer;
644 counter: Integer;
645 endtext: Boolean;
646 end;
648 function Compare(a, b: TPlayerStat): Integer;
649 begin
650 if a.Spectator then Result := 1
651 else if b.Spectator then Result := -1
652 else if a.Frags < b.Frags then Result := 1
653 else if a.Frags > b.Frags then Result := -1
654 else if a.Deaths < b.Deaths then Result := -1
655 else if a.Deaths > b.Deaths then Result := 1
656 else if a.Kills < b.Kills then Result := -1
657 else Result := 1;
658 end;
660 procedure SortGameStat(var stat: TPlayerStatArray);
661 var
662 I, J: Integer;
663 T: TPlayerStat;
664 begin
665 if stat = nil then Exit;
667 for I := High(stat) downto Low(stat) do
668 for J := Low(stat) to High(stat) - 1 do
669 if Compare(stat[J], stat[J + 1]) = 1 then
670 begin
671 T := stat[J];
672 stat[J] := stat[J + 1];
673 stat[J + 1] := T;
674 end;
675 end;
677 // saves a shitty CSV containing the game stats passed to it
678 procedure SaveGameStat(Stat: TEndCustomGameStat; Path: string);
679 var
680 s: TextFile;
681 dir, fname, map, mode, etime: String;
682 I: Integer;
683 begin
684 try
685 dir := e_GetWriteableDir(StatsDirs);
686 // stats are placed in stats/yy/mm/dd/*.csv
687 fname := e_CatPath(dir, Path);
688 ForceDirectories(fname); // ensure yy/mm/dd exists within the stats dir
689 fname := e_CatPath(fname, StatFilename + '.csv');
690 AssignFile(s, fname);
691 try
692 SetTextCodePage(s, CP_UTF8);
693 Rewrite(s);
694 // line 1: stats ver, datetime, server name, map name, game mode, time limit, score limit, dmflags, game time, num players
695 if g_Game_IsNet then fname := NetServerName else fname := '';
696 map := g_ExtractWadNameNoPath(gMapInfo.Map) + ':/' + g_ExtractFileName(gMapInfo.Map);
697 mode := g_Game_ModeToText(Stat.GameMode);
698 etime := Format('%d:%.2d:%.2d', [
699 Stat.GameTime div 1000 div 3600,
700 (Stat.GameTime div 1000 div 60) mod 60,
701 Stat.GameTime div 1000 mod 60
702 ]);
703 WriteLn(s, 'stats_ver,datetime,server,map,mode,timelimit,scorelimit,dmflags,time,num_players');
704 WriteLn(s, Format('%d,%s,%s,%s,%s,%u,%u,%u,%s,%d', [
705 STATFILE_VERSION,
706 StatDate,
707 dquoteStr(fname),
708 dquoteStr(map),
709 mode,
710 gGameSettings.TimeLimit,
711 gGameSettings.ScoreLimit,
712 gGameSettings.Options,
713 etime,
714 Length(Stat.PlayerStat)
715 ]));
716 // line 2: game specific shit
717 // if it's a team game: red score, blue score
718 // if it's a coop game: monsters killed, monsters total, secrets found, secrets total
719 // otherwise nothing
720 if Stat.GameMode in [GM_TDM, GM_CTF] then
721 WriteLn(s,
722 Format('red_score,blue_score' + LineEnding + '%d,%d', [Stat.TeamStat[TEAM_RED].Score, Stat.TeamStat[TEAM_BLUE].Score]))
723 else if Stat.GameMode in [GM_COOP, GM_SINGLE] then
724 WriteLn(s,
725 Format('mon_killed,mon_total,secrets_found,secrets_total' + LineEnding + '%d,%d,%d,%d',[gCoopMonstersKilled, gTotalMonsters, gCoopSecretsFound, gSecretsCount]));
726 // lines 3-...: team, player name, frags, deaths
727 WriteLn(s, 'team,name,frags,deaths');
728 for I := Low(Stat.PlayerStat) to High(Stat.PlayerStat) do
729 with Stat.PlayerStat[I] do
730 WriteLn(s, Format('%d,%s,%d,%d', [Team, dquoteStr(Name), Frags, Deaths]));
731 except
732 g_Console_Add(Format(_lc[I_CONSOLE_ERROR_WRITE], [fname]));
733 end;
734 except
735 g_Console_Add('could not create gamestats file "' + fname + '"');
736 end;
737 CloseFile(s);
738 end;
740 procedure ClearDebugCvars();
741 begin
742 g_debug_Sounds := False;
743 g_debug_Frames := False;
744 g_debug_WinMsgs := False;
745 g_debug_MonsterOff := False;
746 g_debug_BotAIOff := 0;
747 g_debug_HealthBar := False;
748 g_Debug_Player := False;
749 end;
751 function g_Game_ModeToText(Mode: Byte): string;
752 begin
753 Result := '';
754 case Mode of
755 GM_DM: Result := _lc[I_MENU_GAME_TYPE_DM];
756 GM_TDM: Result := _lc[I_MENU_GAME_TYPE_TDM];
757 GM_CTF: Result := _lc[I_MENU_GAME_TYPE_CTF];
758 GM_COOP: Result := _lc[I_MENU_GAME_TYPE_COOP];
759 GM_SINGLE: Result := _lc[I_MENU_GAME_TYPE_SINGLE];
760 end;
761 end;
763 function g_Game_TextToMode(Mode: string): Byte;
764 begin
765 Result := GM_NONE;
766 Mode := UpperCase(Mode);
767 if Mode = _lc[I_MENU_GAME_TYPE_DM] then
768 begin
769 Result := GM_DM;
770 Exit;
771 end;
772 if Mode = _lc[I_MENU_GAME_TYPE_TDM] then
773 begin
774 Result := GM_TDM;
775 Exit;
776 end;
777 if Mode = _lc[I_MENU_GAME_TYPE_CTF] then
778 begin
779 Result := GM_CTF;
780 Exit;
781 end;
782 if Mode = _lc[I_MENU_GAME_TYPE_COOP] then
783 begin
784 Result := GM_COOP;
785 Exit;
786 end;
787 if Mode = _lc[I_MENU_GAME_TYPE_SINGLE] then
788 begin
789 Result := GM_SINGLE;
790 Exit;
791 end;
792 end;
794 function g_Game_IsNet(): Boolean;
795 begin
796 Result := (gGameSettings.GameType in [GT_SERVER, GT_CLIENT]);
797 end;
799 function g_Game_IsServer(): Boolean;
800 begin
801 Result := (gGameSettings.GameType in [GT_SINGLE, GT_CUSTOM, GT_SERVER]);
802 end;
804 function g_Game_IsClient(): Boolean;
805 begin
806 Result := (gGameSettings.GameType = GT_CLIENT);
807 end;
809 function g_Game_GetMegaWADInfo(WAD: String): TMegaWADInfo;
810 var
811 w: TWADFile;
812 cfg: TConfig;
813 p: Pointer;
814 len: Integer;
815 begin
816 Result.name := ExtractFileName(WAD);
817 Result.description := '';
818 Result.author := '';
820 w := TWADFile.Create();
821 w.ReadFile(WAD);
823 if not w.GetResource('INTERSCRIPT', p, len) then
824 begin
825 w.Free();
826 Exit;
827 end;
829 cfg := TConfig.CreateMem(p, len);
830 Result.name := cfg.ReadStr('megawad', 'name', ExtractFileName(WAD));
831 Result.description := cfg.ReadStr('megawad', 'description', '');
832 Result.author := cfg.ReadStr('megawad', 'author', '');
833 Result.pic := cfg.ReadStr('megawad', 'pic', '');
834 cfg.Free();
836 FreeMem(p);
837 end;
839 procedure g_Game_FreeWAD();
840 var
841 a: Integer;
842 begin
843 for a := 0 to High(MegaWAD.res.pic) do
844 if MegaWAD.res.pic[a] <> '' then
845 g_Texture_Delete(MegaWAD.res.pic[a]);
847 for a := 0 to High(MegaWAD.res.mus) do
848 if MegaWAD.res.mus[a] <> '' then
849 g_Sound_Delete(MegaWAD.res.mus[a]);
851 MegaWAD.res.pic := nil;
852 MegaWAD.res.text := nil;
853 MegaWAD.res.anim := nil;
854 MegaWAD.res.mus := nil;
855 MegaWAD.triggers := nil;
857 g_Texture_Delete('TEXTURE_endpic');
858 g_Sound_Delete('MUSIC_endmus');
860 ZeroMemory(@MegaWAD, SizeOf(MegaWAD));
861 gGameSettings.WAD := '';
862 end;
864 procedure g_Game_LoadWAD(WAD: string);
865 var
866 w: TWADFile;
867 cfg: TConfig;
868 p: Pointer;
869 {b, }len: Integer;
870 s: AnsiString;
871 begin
872 g_Game_FreeWAD();
873 gGameSettings.WAD := WAD;
874 if not (gGameSettings.GameMode in [GM_COOP, GM_SINGLE]) then
875 Exit;
877 MegaWAD.info := g_Game_GetMegaWADInfo(WAD);
879 w := TWADFile.Create();
880 w.ReadFile(WAD);
882 if not w.GetResource('INTERSCRIPT', p, len) then
883 begin
884 w.Free();
885 Exit;
886 end;
888 cfg := TConfig.CreateMem(p, len);
890 {b := 1;
891 while True do
892 begin
893 s := cfg.ReadStr('pic', 'pic'+IntToStr(b), '');
894 if s = '' then Break;
895 b := b+1;
897 SetLength(MegaWAD.res.pic, Length(MegaWAD.res.pic)+1);
898 MegaWAD.res.pic[High(MegaWAD.res.pic)] := s;
900 g_Texture_CreateWADEx(s, s);
901 end;
903 b := 1;
904 while True do
905 begin
906 s := cfg.ReadStr('mus', 'mus'+IntToStr(b), '');
907 if s = '' then Break;
908 b := b+1;
910 SetLength(MegaWAD.res.mus, Length(MegaWAD.res.mus)+1);
911 MegaWAD.res.mus[High(MegaWAD.res.mus)] := s;
913 g_Music_CreateWADEx(s, s);
914 end;}
916 MegaWAD.endpic := cfg.ReadStr('megawad', 'endpic', '');
917 if MegaWAD.endpic <> '' then
918 begin
919 TEXTUREFILTER := GL_LINEAR;
920 s := e_GetResourcePath(WadDirs, MegaWAD.endpic, WAD);
921 g_Texture_CreateWADEx('TEXTURE_endpic', s);
922 TEXTUREFILTER := GL_NEAREST;
923 end;
924 MegaWAD.endmus := cfg.ReadStr('megawad', 'endmus', 'Standart.wad:D2DMUS\ÊÎÍÅÖ');
925 if MegaWAD.endmus <> '' then
926 begin
927 s := e_GetResourcePath(WadDirs, MegaWAD.endmus, WAD);
928 g_Sound_CreateWADEx('MUSIC_endmus', s, True);
929 end;
931 cfg.Free();
932 FreeMem(p);
933 w.Free();
934 end;
936 {procedure start_trigger(t: string);
937 begin
938 end;
940 function next_trigger(): Boolean;
941 begin
942 end;}
944 procedure DisableCheats();
945 begin
946 MAX_RUNVEL := 8;
947 VEL_JUMP := 10;
948 gFly := False;
950 if gPlayer1 <> nil then gPlayer1.GodMode := False;
951 if gPlayer2 <> nil then gPlayer2.GodMode := False;
952 if gPlayer1 <> nil then gPlayer1.NoTarget := False;
953 if gPlayer2 <> nil then gPlayer2.NoTarget := False;
955 {$IF DEFINED(D2F_DEBUG)}
956 if gPlayer1 <> nil then gPlayer1.NoTarget := True;
957 gAimLine := g_dbg_aimline_on;
958 {$ENDIF}
959 end;
961 procedure g_Game_ExecuteEvent(Name: String);
962 var
963 a: Integer;
964 begin
965 if Name = '' then
966 Exit;
967 if gEvents = nil then
968 Exit;
969 for a := 0 to High(gEvents) do
970 if gEvents[a].Name = Name then
971 begin
972 if gEvents[a].Command <> '' then
973 g_Console_Process(gEvents[a].Command, True);
974 break;
975 end;
976 end;
978 function g_Game_DelayEvent(DEType: Byte; Time: LongWord; Num: Integer = 0; Str: String = ''): Integer;
979 var
980 a, n: Integer;
981 begin
982 n := -1;
983 if gDelayedEvents <> nil then
984 for a := 0 to High(gDelayedEvents) do
985 if not gDelayedEvents[a].Pending then
986 begin
987 n := a;
988 break;
989 end;
990 if n = -1 then
991 begin
992 SetLength(gDelayedEvents, Length(gDelayedEvents) + 1);
993 n := High(gDelayedEvents);
994 end;
995 gDelayedEvents[n].Pending := True;
996 gDelayedEvents[n].DEType := DEType;
997 gDelayedEvents[n].DENum := Num;
998 gDelayedEvents[n].DEStr := Str;
999 if DEType = DE_GLOBEVENT then
1000 gDelayedEvents[n].Time := (sys_GetTicks() {div 1000}) + Time
1001 else
1002 gDelayedEvents[n].Time := gTime + Time;
1003 Result := n;
1004 end;
1006 procedure EndGame();
1007 var
1008 a: Integer;
1009 FileName: string;
1010 t: TDateTime;
1011 begin
1012 if g_Game_IsNet and g_Game_IsServer then
1013 MH_SEND_GameEvent(NET_EV_MAPEND, Byte(gMissionFailed));
1015 // Ñòîï èãðà:
1016 gPauseMain := false;
1017 gPauseHolmes := false;
1018 gGameOn := false;
1020 g_Game_StopAllSounds(False);
1022 MessageTime := 0;
1023 MessageText := '';
1025 EndingGameCounter := 0;
1026 g_ActiveWindow := nil;
1028 gLMSRespawn := LMS_RESPAWN_NONE;
1029 gLMSRespawnTime := 0;
1031 case gExit of
1032 EXIT_SIMPLE: // Âûõîä ÷åðåç ìåíþ èëè êîíåö òåñòà
1033 begin
1034 g_Game_Free();
1036 if gMapOnce then
1037 begin // Ýòî áûë òåñò
1038 g_Game_Quit();
1039 end
1040 else
1041 begin // Âûõîä â ãëàâíîå ìåíþ
1042 gMusic.SetByName('MUSIC_MENU');
1043 gMusic.Play();
1044 if gState <> STATE_SLIST then
1045 begin
1046 g_GUI_ShowWindow('MainMenu');
1047 gState := STATE_MENU;
1048 end else
1049 begin
1050 // Îáíîâëÿåì ñïèñîê ñåðâåðîâ
1051 slReturnPressed := True;
1052 if g_Net_Slist_Fetch(slCurrent) then
1053 begin
1054 if slCurrent = nil then
1055 slWaitStr := _lc[I_NET_SLIST_NOSERVERS];
1056 end
1057 else
1058 slWaitStr := _lc[I_NET_SLIST_ERROR];
1059 g_Serverlist_GenerateTable(slCurrent, slTable);
1060 end;
1062 g_Game_ExecuteEvent('ongameend');
1063 end;
1064 end;
1066 EXIT_RESTART: // Íà÷àòü óðîâåíü ñíà÷àëà
1067 begin
1068 if not g_Game_IsClient then g_Game_Restart();
1069 end;
1071 EXIT_ENDLEVELCUSTOM: // Çàêîí÷èëñÿ óðîâåíü â Ñâîåé èãðå
1072 begin
1073 // Ñòàòèñòèêà Ñâîåé èãðû:
1074 FileName := g_ExtractWadName(gMapInfo.Map);
1076 CustomStat.GameTime := gTime;
1077 CustomStat.Map := ExtractFileName(FileName)+':'+g_ExtractFileName(gMapInfo.Map); //ResName;
1078 CustomStat.MapName := gMapInfo.Name;
1079 CustomStat.GameMode := gGameSettings.GameMode;
1080 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
1081 CustomStat.TeamStat := gTeamStat;
1083 CustomStat.PlayerStat := nil;
1085 // Ñòàòèñòèêà èãðîêîâ:
1086 if gPlayers <> nil then
1087 begin
1088 for a := 0 to High(gPlayers) do
1089 if gPlayers[a] <> nil then
1090 begin
1091 SetLength(CustomStat.PlayerStat, Length(CustomStat.PlayerStat)+1);
1092 with CustomStat.PlayerStat[High(CustomStat.PlayerStat)] do
1093 begin
1094 Num := a;
1095 Name := gPlayers[a].Name;
1096 Frags := gPlayers[a].Frags;
1097 Deaths := gPlayers[a].Death;
1098 Kills := gPlayers[a].Kills;
1099 Team := gPlayers[a].Team;
1100 Color := gPlayers[a].Model.Color;
1101 Spectator := gPlayers[a].FSpectator;
1102 end;
1103 end;
1105 SortGameStat(CustomStat.PlayerStat);
1107 if (gSaveStats or gScreenshotStats) and (Length(CustomStat.PlayerStat) > 1) then
1108 begin
1109 t := Now;
1110 if g_Game_IsNet then StatFilename := NetServerName else StatFilename := 'local';
1111 StatDate := FormatDateTime('yymmdd_hhnnss', t);
1112 StatFilename := StatFilename + '_' + CustomStat.Map + '_' + g_Game_ModeToText(CustomStat.GameMode);
1113 StatFilename := sanitizeFilename(StatFilename) + '_' + StatDate;
1114 if gSaveStats then
1115 SaveGameStat(CustomStat, FormatDateTime('yyyy"/"mm"/"dd', t));
1116 end;
1118 StatShotDone := False;
1119 end;
1121 g_Game_ExecuteEvent('onmapend');
1122 if not g_Game_IsClient then g_Player_ResetReady;
1123 gInterReadyCount := 0;
1125 // Çàòóõàþùèé ýêðàí:
1126 EndingGameCounter := 255;
1127 gState := STATE_FOLD;
1128 gInterTime := 0;
1129 if gDefInterTime < 0 then
1130 gInterEndTime := IfThen((gGameSettings.GameType = GT_SERVER) and (gPlayer1 = nil), 15000, 25000)
1131 else
1132 gInterEndTime := gDefInterTime * 1000;
1133 end;
1135 EXIT_ENDLEVELSINGLE: // Çàêîí÷èëñÿ óðîâåíü â Îäèíî÷íîé èãðå
1136 begin
1137 // Ñòàòèñòèêà Îäèíî÷íîé èãðû:
1138 SingleStat.GameTime := gTime;
1139 SingleStat.TwoPlayers := gPlayer2 <> nil;
1140 SingleStat.TotalSecrets := gSecretsCount;
1141 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
1142 SingleStat.PlayerStat[0].Kills := gPlayer1.MonsterKills;
1143 SingleStat.PlayerStat[0].Secrets := gPlayer1.Secrets;
1144 // Ñòàòèñòèêà âòîðîãî èãðîêà (åñëè åñòü):
1145 if SingleStat.TwoPlayers then
1146 begin
1147 SingleStat.PlayerStat[1].Kills := gPlayer2.MonsterKills;
1148 SingleStat.PlayerStat[1].Secrets := gPlayer2.Secrets;
1149 end;
1151 g_Game_ExecuteEvent('onmapend');
1153 // Åñòü åùå êàðòû:
1154 if gNextMap <> '' then
1155 begin
1156 gMusic.SetByName('MUSIC_INTERMUS');
1157 gMusic.Play();
1158 gState := STATE_INTERSINGLE;
1159 e_UnpressAllKeys();
1161 g_Game_ExecuteEvent('oninter');
1162 end
1163 else // Áîëüøå íåò êàðò
1164 begin
1165 // Çàòóõàþùèé ýêðàí:
1166 EndingGameCounter := 255;
1167 gState := STATE_FOLD;
1168 end;
1169 end;
1170 end;
1172 // Îêîí÷àíèå îáðàáîòàíî:
1173 if gExit <> EXIT_QUIT then
1174 gExit := 0;
1175 end;
1177 procedure drawTime(X, Y: Integer); inline;
1178 begin
1179 e_TextureFontPrint(x, y,
1180 Format('%d:%.2d:%.2d', [
1181 gTime div 1000 div 3600,
1182 (gTime div 1000 div 60) mod 60,
1183 gTime div 1000 mod 60
1184 ]),
1185 gStdFont);
1186 end;
1188 procedure DrawStat();
1189 var
1190 pc, x, y, w, h: Integer;
1191 w1, w2, w3, w4: Integer;
1192 a, aa: Integer;
1193 cw, ch, r, g, b, rr, gg, bb: Byte;
1194 s1, s2, s3: String;
1195 _y: Integer;
1196 stat: TPlayerStatArray;
1197 wad, map: string;
1198 mapstr: string;
1199 namestr: string;
1200 begin
1201 s1 := '';
1202 s2 := '';
1203 s3 := '';
1204 pc := g_Player_GetCount;
1205 e_TextureFontGetSize(gStdFont, cw, ch);
1207 w := gScreenWidth-(gScreenWidth div 5);
1208 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
1209 h := 32+ch*(11+pc)
1210 else
1211 h := 40+ch*5+(ch+8)*pc;
1212 x := (gScreenWidth div 2)-(w div 2);
1213 y := (gScreenHeight div 2)-(h div 2);
1215 e_DrawFillQuad(x, y, x+w-1, y+h-1, 64, 64, 64, 32);
1216 e_DrawQuad(x, y, x+w-1, y+h-1, 255, 127, 0);
1218 drawTime(x+w-78, y+8);
1220 wad := g_ExtractWadNameNoPath(gMapInfo.Map);
1221 map := g_ExtractFileName(gMapInfo.Map);
1222 mapstr := wad + ':\' + map + ' - ' + gMapInfo.Name;
1224 case gGameSettings.GameMode of
1225 GM_DM:
1226 begin
1227 if gGameSettings.MaxLives = 0 then
1228 s1 := _lc[I_GAME_DM]
1229 else
1230 s1 := _lc[I_GAME_LMS];
1231 s2 := Format(_lc[I_GAME_FRAG_LIMIT], [gGameSettings.ScoreLimit]);
1232 s3 := Format(_lc[I_GAME_TIME_LIMIT], [gGameSettings.TimeLimit div 3600, (gGameSettings.TimeLimit div 60) mod 60, gGameSettings.TimeLimit mod 60]);
1233 end;
1235 GM_TDM:
1236 begin
1237 if gGameSettings.MaxLives = 0 then
1238 s1 := _lc[I_GAME_TDM]
1239 else
1240 s1 := _lc[I_GAME_TLMS];
1241 s2 := Format(_lc[I_GAME_FRAG_LIMIT], [gGameSettings.ScoreLimit]);
1242 s3 := Format(_lc[I_GAME_TIME_LIMIT], [gGameSettings.TimeLimit div 3600, (gGameSettings.TimeLimit div 60) mod 60, gGameSettings.TimeLimit mod 60]);
1243 end;
1245 GM_CTF:
1246 begin
1247 s1 := _lc[I_GAME_CTF];
1248 s2 := Format(_lc[I_GAME_SCORE_LIMIT], [gGameSettings.ScoreLimit]);
1249 s3 := Format(_lc[I_GAME_TIME_LIMIT], [gGameSettings.TimeLimit div 3600, (gGameSettings.TimeLimit div 60) mod 60, gGameSettings.TimeLimit mod 60]);
1250 end;
1252 GM_COOP:
1253 begin
1254 if gGameSettings.MaxLives = 0 then
1255 s1 := _lc[I_GAME_COOP]
1256 else
1257 s1 := _lc[I_GAME_SURV];
1258 s2 := _lc[I_GAME_MONSTERS] + ' ' + IntToStr(gCoopMonstersKilled) + '/' + IntToStr(gTotalMonsters);
1259 s3 := _lc[I_GAME_SECRETS] + ' ' + IntToStr(gCoopSecretsFound) + '/' + IntToStr(gSecretsCount);
1260 end;
1262 else
1263 begin
1264 s1 := '';
1265 s2 := '';
1266 end;
1267 end;
1269 _y := y+8;
1270 e_TextureFontPrintEx(x+(w div 2)-(Length(s1)*cw div 2), _y, s1, gStdFont, 255, 255, 255, 1);
1271 _y := _y+ch+8;
1272 e_TextureFontPrintEx(x+(w div 2)-(Length(mapstr)*cw div 2), _y, mapstr, gStdFont, 200, 200, 200, 1);
1273 _y := _y+ch+8;
1274 e_TextureFontPrintEx(x+16, _y, s2, gStdFont, 200, 200, 200, 1);
1276 e_TextureFontPrintEx(x+w-16-(Length(s3))*cw, _y, s3,
1277 gStdFont, 200, 200, 200, 1);
1279 if NetMode = NET_SERVER then
1280 e_TextureFontPrintEx(x+8, y + 8, _lc[I_NET_SERVER], gStdFont, 255, 255, 255, 1)
1281 else
1282 if NetMode = NET_CLIENT then
1283 e_TextureFontPrintEx(x+8, y + 8,
1284 NetClientIP + ':' + IntToStr(NetClientPort), gStdFont, 255, 255, 255, 1);
1286 if pc = 0 then
1287 Exit;
1288 stat := g_Player_GetStats();
1289 SortGameStat(stat);
1291 w2 := (w-16) div 6 + 48; // øèðèíà 2 ñòîëáöà
1292 w3 := (w-16) div 6; // øèðèíà 3 è 4 ñòîëáöîâ
1293 w4 := w3;
1294 w1 := w-16-w2-w3-w4; // îñòàâøååñÿ ïðîñòðàíñòâî - äëÿ öâåòà è èìåíè èãðîêà
1296 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
1297 begin
1298 _y := _y+ch+ch;
1300 for a := TEAM_RED to TEAM_BLUE do
1301 begin
1302 if a = TEAM_RED then
1303 begin
1304 s1 := _lc[I_GAME_TEAM_RED];
1305 r := 255;
1306 g := 0;
1307 b := 0;
1308 end
1309 else
1310 begin
1311 s1 := _lc[I_GAME_TEAM_BLUE];
1312 r := 0;
1313 g := 0;
1314 b := 255;
1315 end;
1317 e_TextureFontPrintEx(x+16, _y, s1, gStdFont, r, g, b, 1);
1318 e_TextureFontPrintEx(x+w1+16, _y, IntToStr(gTeamStat[a].Score),
1319 gStdFont, r, g, b, 1);
1321 _y := _y+ch+(ch div 4);
1322 e_DrawLine(1, x+16, _y, x+w-16, _y, r, g, b);
1323 _y := _y+(ch div 4);
1325 for aa := 0 to High(stat) do
1326 if stat[aa].Team = a then
1327 with stat[aa] do
1328 begin
1329 if Spectator then
1330 begin
1331 rr := r div 2;
1332 gg := g div 2;
1333 bb := b div 2;
1334 end
1335 else
1336 begin
1337 rr := r;
1338 gg := g;
1339 bb := b;
1340 end;
1341 if gShowPIDs then
1342 namestr := Format('[%5d] %s', [UID, Name])
1343 else
1344 namestr := Name;
1345 // Èìÿ
1346 e_TextureFontPrintEx(x+16, _y, namestr, gStdFont, rr, gg, bb, 1);
1347 // Ïèíã/ïîòåðè
1348 e_TextureFontPrintEx(x+w1+16, _y, Format(_lc[I_GAME_PING_MS], [Ping, Loss]), gStdFont, rr, gg, bb, 1);
1349 // Ôðàãè
1350 e_TextureFontPrintEx(x+w1+w2+16, _y, IntToStr(Frags), gStdFont, rr, gg, bb, 1);
1351 // Ñìåðòè
1352 e_TextureFontPrintEx(x+w1+w2+w3+16, _y, IntToStr(Deaths), gStdFont, rr, gg, bb, 1);
1353 _y := _y+ch;
1354 end;
1356 _y := _y+ch;
1357 end;
1358 end
1359 else if gGameSettings.GameMode in [GM_DM, GM_COOP] then
1360 begin
1361 _y := _y+ch+ch;
1362 e_TextureFontPrintEx(x+16, _y, _lc[I_GAME_PLAYER_NAME], gStdFont, 255, 127, 0, 1);
1363 e_TextureFontPrintEx(x+16+w1, _y, _lc[I_GAME_PING], gStdFont, 255, 127, 0, 1);
1364 e_TextureFontPrintEx(x+16+w1+w2, _y, _lc[I_GAME_FRAGS], gStdFont, 255, 127, 0, 1);
1365 e_TextureFontPrintEx(x+16+w1+w2+w3, _y, _lc[I_GAME_DEATHS], gStdFont, 255, 127, 0, 1);
1367 _y := _y+ch+8;
1368 for aa := 0 to High(stat) do
1369 with stat[aa] do
1370 begin
1371 if Spectator then
1372 begin
1373 r := 127;
1374 g := 64;
1375 end
1376 else
1377 begin
1378 r := 255;
1379 g := 127;
1380 end;
1381 if gShowPIDs then
1382 namestr := Format('[%5d] %s', [UID, Name])
1383 else
1384 namestr := Name;
1385 // Öâåò èãðîêà
1386 e_DrawFillQuad(x+16, _y+4, x+32-1, _y+16+4-1, Color.R, Color.G, Color.B, 0);
1387 e_DrawQuad(x+16, _y+4, x+32-1, _y+16+4-1, 192, 192, 192);
1388 // Èìÿ
1389 e_TextureFontPrintEx(x+16+16+8, _y+4, namestr, gStdFont, r, g, 0, 1);
1390 // Ïèíã/ïîòåðè
1391 e_TextureFontPrintEx(x+w1+16, _y+4, Format(_lc[I_GAME_PING_MS], [Ping, Loss]), gStdFont, r, g, 0, 1);
1392 // Ôðàãè
1393 e_TextureFontPrintEx(x+w1+w2+16, _y+4, IntToStr(Frags), gStdFont, r, g, 0, 1);
1394 // Ñìåðòè
1395 e_TextureFontPrintEx(x+w1+w2+w3+16, _y+4, IntToStr(Deaths), gStdFont, r, g, 0, 1);
1396 _y := _y+ch+8;
1397 end;
1398 end
1399 end;
1401 procedure g_Game_Init();
1402 var
1403 SR: TSearchRec;
1404 knownFiles: array of AnsiString = nil;
1405 found: Boolean;
1406 wext, s: AnsiString;
1407 f: Integer;
1408 begin
1409 gExit := 0;
1410 gMapToDelete := '';
1411 gTempDelete := False;
1413 sfsGCDisable(); // temporary disable removing of temporary volumes
1415 try
1416 TEXTUREFILTER := GL_LINEAR;
1417 g_Texture_CreateWADEx('MENU_BACKGROUND', GameWAD+':TEXTURES\TITLE');
1418 g_Texture_CreateWADEx('INTER', GameWAD+':TEXTURES\INTER');
1419 g_Texture_CreateWADEx('ENDGAME_EN', GameWAD+':TEXTURES\ENDGAME_EN');
1420 g_Texture_CreateWADEx('ENDGAME_RU', GameWAD+':TEXTURES\ENDGAME_RU');
1421 TEXTUREFILTER := GL_NEAREST;
1423 LoadStdFont('STDTXT', 'STDFONT', gStdFont);
1424 LoadFont('MENUTXT', 'MENUFONT', gMenuFont);
1425 LoadFont('SMALLTXT', 'SMALLFONT', gMenuSmallFont);
1427 g_Game_ClearLoading();
1428 g_Game_SetLoadingText(Format('Doom 2D: Forever %s', [GAME_VERSION]), 0, False);
1429 g_Game_SetLoadingText('', 0, False);
1431 g_Game_SetLoadingText(_lc[I_LOAD_CONSOLE], 0, False);
1432 g_Console_Init();
1434 g_Game_SetLoadingText(_lc[I_LOAD_MODELS], 0, False);
1435 g_PlayerModel_LoadData();
1437 // load models from all possible wad types, in all known directories
1438 // this does a loosy job (linear search, ooph!), but meh
1439 for wext in wadExtensions do
1440 begin
1441 for f := High(ModelDirs) downto Low(ModelDirs) do
1442 begin
1443 if (FindFirst(ModelDirs[f]+DirectorySeparator+'*'+wext, faAnyFile, SR) = 0) then
1444 begin
1445 repeat
1446 found := false;
1447 for s in knownFiles do
1448 begin
1449 if (strEquCI1251(forceFilenameExt(SR.Name, ''), forceFilenameExt(ExtractFileName(s), ''))) then
1450 begin
1451 found := true;
1452 break;
1453 end;
1454 end;
1455 if not found then
1456 begin
1457 SetLength(knownFiles, length(knownFiles)+1);
1458 knownFiles[High(knownFiles)] := ModelDirs[f]+DirectorySeparator+SR.Name;
1459 end;
1460 until (FindNext(SR) <> 0);
1461 end;
1462 FindClose(SR);
1463 end;
1464 end;
1466 if (length(knownFiles) = 0) then raise Exception.Create('no player models found!');
1468 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);
1469 for s in knownFiles do
1470 begin
1471 if not g_PlayerModel_Load(s) then e_LogWritefln('Error loading model "%s"', [s], TMsgType.Warning);
1472 end;
1474 gGameOn := false;
1475 gPauseMain := false;
1476 gPauseHolmes := false;
1477 gTime := 0;
1479 {e_MouseInfo.Accel := 1.0;}
1481 g_Game_SetLoadingText(_lc[I_LOAD_GAME_DATA], 0, False);
1482 g_Game_LoadData();
1484 g_Game_SetLoadingText(_lc[I_LOAD_MUSIC], 0, False);
1485 g_Sound_CreateWADEx('MUSIC_INTERMUS', GameWAD+':MUSIC\INTERMUS', True);
1486 g_Sound_CreateWADEx('MUSIC_MENU', GameWAD+':MUSIC\MENU', True);
1487 g_Sound_CreateWADEx('MUSIC_ROUNDMUS', GameWAD+':MUSIC\ROUNDMUS', True, True);
1488 g_Sound_CreateWADEx('MUSIC_STDENDMUS', GameWAD+':MUSIC\ENDMUS', True);
1490 {$IFNDEF HEADLESS}
1491 g_Game_SetLoadingText(_lc[I_LOAD_MENUS], 0, False);
1492 g_Menu_Init();
1493 {$ENDIF}
1495 gMusic := TMusic.Create();
1496 gMusic.SetByName('MUSIC_MENU');
1497 gMusic.Play();
1499 gGameSettings.WarmupTime := 30;
1501 gState := STATE_MENU;
1503 SetLength(gEvents, 6);
1504 gEvents[0].Name := 'ongamestart';
1505 gEvents[1].Name := 'ongameend';
1506 gEvents[2].Name := 'onmapstart';
1507 gEvents[3].Name := 'onmapend';
1508 gEvents[4].Name := 'oninter';
1509 gEvents[5].Name := 'onwadend';
1510 finally
1511 sfsGCEnable(); // enable releasing unused volumes
1512 end;
1513 end;
1515 procedure g_Game_Free(freeTextures: Boolean=true);
1516 begin
1517 if NetMode = NET_CLIENT then g_Net_Disconnect();
1518 if NetMode = NET_SERVER then g_Net_Host_Die();
1520 g_Map_Free(freeTextures);
1521 g_Player_Free();
1522 g_Player_RemoveAllCorpses();
1524 gGameSettings.GameType := GT_NONE;
1525 if gGameSettings.GameMode = GM_SINGLE then
1526 gGameSettings.GameMode := GM_DM;
1527 gSwitchGameMode := gGameSettings.GameMode;
1529 gChatShow := False;
1530 gExitByTrigger := False;
1531 end;
1533 function IsActivePlayer(p: TPlayer): Boolean;
1534 begin
1535 Result := False;
1536 if p = nil then
1537 Exit;
1538 Result := (not p.FDummy) and (not p.FSpectator);
1539 end;
1541 function GetActivePlayer_ByID(ID: Integer): TPlayer;
1542 var
1543 a: Integer;
1544 begin
1545 Result := nil;
1546 if ID < 0 then
1547 Exit;
1548 if gPlayers = nil then
1549 Exit;
1550 for a := Low(gPlayers) to High(gPlayers) do
1551 if IsActivePlayer(gPlayers[a]) then
1552 begin
1553 if gPlayers[a].UID <> ID then
1554 continue;
1555 Result := gPlayers[a];
1556 break;
1557 end;
1558 end;
1560 function GetActivePlayerID_Next(Skip: Integer = -1): Integer;
1561 var
1562 a, idx: Integer;
1563 ids: Array of Word;
1564 begin
1565 Result := -1;
1566 if gPlayers = nil then
1567 Exit;
1568 SetLength(ids, 0);
1569 idx := -1;
1570 for a := Low(gPlayers) to High(gPlayers) do
1571 if IsActivePlayer(gPlayers[a]) then
1572 begin
1573 SetLength(ids, Length(ids) + 1);
1574 ids[High(ids)] := gPlayers[a].UID;
1575 if gPlayers[a].UID = Skip then
1576 idx := High(ids);
1577 end;
1578 if Length(ids) = 0 then
1579 Exit;
1580 if idx = -1 then
1581 Result := ids[0]
1582 else
1583 Result := ids[(idx + 1) mod Length(ids)];
1584 end;
1586 function GetActivePlayerID_Prev(Skip: Integer = -1): Integer;
1587 var
1588 a, idx: Integer;
1589 ids: Array of Word;
1590 begin
1591 Result := -1;
1592 if gPlayers = nil then
1593 Exit;
1594 SetLength(ids, 0);
1595 idx := -1;
1596 for a := Low(gPlayers) to High(gPlayers) do
1597 if IsActivePlayer(gPlayers[a]) then
1598 begin
1599 SetLength(ids, Length(ids) + 1);
1600 ids[High(ids)] := gPlayers[a].UID;
1601 if gPlayers[a].UID = Skip then
1602 idx := High(ids);
1603 end;
1604 if Length(ids) = 0 then
1605 Exit;
1606 if idx = -1 then
1607 Result := ids[Length(ids) - 1]
1608 else
1609 Result := ids[(Length(ids) - 1 + idx) mod Length(ids)];
1610 end;
1612 function GetActivePlayerID_Random(Skip: Integer = -1): Integer;
1613 var
1614 a, idx: Integer;
1615 ids: Array of Word;
1616 begin
1617 Result := -1;
1618 if gPlayers = nil then
1619 Exit;
1620 SetLength(ids, 0);
1621 idx := -1;
1622 for a := Low(gPlayers) to High(gPlayers) do
1623 if IsActivePlayer(gPlayers[a]) then
1624 begin
1625 SetLength(ids, Length(ids) + 1);
1626 ids[High(ids)] := gPlayers[a].UID;
1627 if gPlayers[a].UID = Skip then
1628 idx := High(ids);
1629 end;
1630 if Length(ids) = 0 then
1631 Exit;
1632 if Length(ids) = 1 then
1633 begin
1634 Result := ids[0];
1635 Exit;
1636 end;
1637 Result := ids[Random(Length(ids))];
1638 a := 10;
1639 while (idx <> -1) and (Result = Skip) and (a > 0) do
1640 begin
1641 Result := ids[Random(Length(ids))];
1642 Dec(a);
1643 end;
1644 end;
1646 function GetRandomSpectMode(Current: Byte): Byte;
1647 label
1648 retry;
1649 begin
1650 Result := Current;
1651 retry:
1652 case Random(7) of
1653 0: Result := SPECT_STATS;
1654 1: Result := SPECT_MAPVIEW;
1655 2: Result := SPECT_MAPVIEW;
1656 3: Result := SPECT_PLAYERS;
1657 4: Result := SPECT_PLAYERS;
1658 5: Result := SPECT_PLAYERS;
1659 6: Result := SPECT_PLAYERS;
1660 end;
1661 if (Current in [SPECT_STATS, SPECT_MAPVIEW]) and (Current = Result) then
1662 goto retry;
1663 end;
1665 procedure ProcessPlayerControls (plr: TPlayer; p: Integer; var MoveButton: Byte);
1666 var
1667 time: Word;
1668 strafeDir: Byte;
1669 i: Integer;
1670 begin
1671 if (plr = nil) then exit;
1672 if (p = 2) then time := 1000 else time := 1;
1673 strafeDir := MoveButton shr 4;
1674 MoveButton := MoveButton and $0F;
1676 if gPlayerAction[p, ACTION_MOVELEFT] and (not gPlayerAction[p, ACTION_MOVERIGHT]) then
1677 MoveButton := 1 // Íàæàòà òîëüêî "Âëåâî"
1678 else if (not gPlayerAction[p, ACTION_MOVELEFT]) and gPlayerAction[p, ACTION_MOVERIGHT] then
1679 MoveButton := 2 // Íàæàòà òîëüêî "Âïðàâî"
1680 else if (not gPlayerAction[p, ACTION_MOVELEFT]) and (not gPlayerAction[p, ACTION_MOVERIGHT]) then
1681 MoveButton := 0; // Íå íàæàòû íè "Âëåâî", íè "Âïðàâî"
1683 // Ñåé÷àñ èëè ðàíüøå áûëè íàæàòû "Âëåâî"/"Âïðàâî" => ïåðåäàåì èãðîêó:
1684 if MoveButton = 1 then
1685 plr.PressKey(KEY_LEFT, time)
1686 else if MoveButton = 2 then
1687 plr.PressKey(KEY_RIGHT, time);
1689 // if we have "strafe" key, turn off old strafe mechanics
1690 if gPlayerAction[p, ACTION_STRAFE] then
1691 begin
1692 // new strafe mechanics
1693 if (strafeDir = 0) then
1694 strafeDir := MoveButton; // start strafing
1695 // now set direction according to strafe (reversed)
1696 if (strafeDir = 2) then
1697 plr.SetDirection(TDirection.D_LEFT)
1698 else if (strafeDir = 1) then
1699 plr.SetDirection(TDirection.D_RIGHT)
1700 end
1701 else
1702 begin
1703 strafeDir := 0; // not strafing anymore
1704 // Ðàíüøå áûëà íàæàòà "Âïðàâî", à ñåé÷àñ "Âëåâî" => áåæèì âïðàâî, ñìîòðèì âëåâî:
1705 if (MoveButton = 2) and gPlayerAction[p, ACTION_MOVELEFT] then
1706 plr.SetDirection(TDirection.D_LEFT)
1707 // Ðàíüøå áûëà íàæàòà "Âëåâî", à ñåé÷àñ "Âïðàâî" => áåæèì âëåâî, ñìîòðèì âïðàâî:
1708 else if (MoveButton = 1) and gPlayerAction[p, ACTION_MOVERIGHT] then
1709 plr.SetDirection(TDirection.D_RIGHT)
1710 // ×òî-òî áûëî íàæàòî è íå èçìåíèëîñü => êóäà áåæèì, òóäà è ñìîòðèì:
1711 else if MoveButton <> 0 then
1712 plr.SetDirection(TDirection(MoveButton-1))
1713 end;
1715 // fix movebutton state
1716 MoveButton := MoveButton or (strafeDir shl 4);
1718 // Îñòàëüíûå êëàâèøè:
1719 if gPlayerAction[p, ACTION_JUMP] then plr.PressKey(KEY_JUMP, time);
1720 if gPlayerAction[p, ACTION_LOOKUP] then plr.PressKey(KEY_UP, time);
1721 if gPlayerAction[p, ACTION_LOOKDOWN] then plr.PressKey(KEY_DOWN, time);
1722 if gPlayerAction[p, ACTION_ATTACK] then plr.PressKey(KEY_FIRE);
1723 if gPlayerAction[p, ACTION_ACTIVATE] then plr.PressKey(KEY_OPEN);
1725 for i := WP_FACT to WP_LACT do
1726 begin
1727 if gWeaponAction[p, i] then
1728 begin
1729 plr.ProcessWeaponAction(i);
1730 gWeaponAction[p, i] := False
1731 end
1732 end;
1734 for i := WP_FIRST to WP_LAST do
1735 begin
1736 if gSelectWeapon[p, i] then
1737 begin
1738 plr.QueueWeaponSwitch(i); // all choices are passed there, and god will take the best
1739 gSelectWeapon[p, i] := False
1740 end
1741 end;
1743 // HACK: add dynlight here
1744 if gwin_k8_enable_light_experiments then
1745 begin
1746 if e_KeyPressed(IK_F8) and gGameOn and (not gConsoleShow) and (g_ActiveWindow = nil) then
1747 begin
1748 g_playerLight := true;
1749 end;
1750 if e_KeyPressed(IK_F9) and gGameOn and (not gConsoleShow) and (g_ActiveWindow = nil) then
1751 begin
1752 g_playerLight := false;
1753 end;
1754 end;
1756 if gwin_has_stencil and g_playerLight then g_AddDynLight(plr.GameX+32, plr.GameY+40, 128, 1, 1, 0, 0.6);
1757 end;
1759 // HACK: don't have a "key was pressed" function
1760 procedure InterReady();
1761 begin
1762 if InterReadyTime > gTime then Exit;
1763 InterReadyTime := gTime + 3000;
1764 MC_SEND_CheatRequest(NET_CHEAT_READY);
1765 end;
1767 procedure g_Game_PreUpdate();
1768 begin
1769 // these are in separate PreUpdate functions because they can interact during Update()
1770 // and are synced over the net
1771 // we don't care that much about corpses and gibs
1772 g_Player_PreUpdate();
1773 g_Monsters_PreUpdate();
1774 g_Items_PreUpdate();
1775 g_Weapon_PreUpdate();
1776 end;
1778 procedure g_Game_Update();
1779 var
1780 Msg: g_gui.TMessage;
1781 Time: Int64;
1782 a: Byte;
1783 w: Word;
1784 i, b: Integer;
1786 function sendMonsPos (mon: TMonster): Boolean;
1787 begin
1788 result := false; // don't stop
1789 // this will also reset "need-send" flag
1790 if mon.gncNeedSend then
1791 begin
1792 MH_SEND_MonsterPos(mon.UID);
1793 end
1794 else if (mon.MonsterType = MONSTER_BARREL) then
1795 begin
1796 if (mon.GameVelX <> 0) or (mon.GameVelY <> 0) then MH_SEND_MonsterPos(mon.UID);
1797 end
1798 else if (mon.MonsterState <> MONSTATE_SLEEP) then
1799 begin
1800 if (mon.MonsterState <> MONSTATE_DEAD) or (mon.GameVelX <> 0) or (mon.GameVelY <> 0) then MH_SEND_MonsterPos(mon.UID);
1801 end;
1802 end;
1804 function sendMonsPosUnexpected (mon: TMonster): Boolean;
1805 begin
1806 result := false; // don't stop
1807 // this will also reset "need-send" flag
1808 if mon.gncNeedSend then MH_SEND_MonsterPos(mon.UID);
1809 end;
1811 function sendItemPos (it: PItem): Boolean;
1812 begin
1813 result := false; // don't stop
1814 if it.needSend then
1815 begin
1816 MH_SEND_ItemPos(it.myId);
1817 it.needSend := False;
1818 end;
1819 end;
1821 var
1822 reliableUpdate: Boolean;
1823 begin
1824 g_ResetDynlights();
1825 framePool.reset();
1827 // Ïîðà âûêëþ÷àòü èãðó:
1828 if gExit = EXIT_QUIT then
1829 Exit;
1830 // Èãðà çàêîí÷èëàñü - îáðàáàòûâàåì:
1831 if gExit <> 0 then
1832 begin
1833 EndGame();
1834 if gExit = EXIT_QUIT then
1835 Exit;
1836 end;
1838 // ×èòàåì êëàâèàòóðó è äæîéñòèê, åñëè îêíî àêòèâíî
1839 // no need to, as we'll do it in event handler
1841 // Îáíîâëÿåì êîíñîëü (äâèæåíèå è ñîîáùåíèÿ):
1842 g_Console_Update();
1844 if (NetMode = NET_NONE) and (g_Game_IsNet) and (gGameOn or (gState in [STATE_FOLD, STATE_INTERCUSTOM])) then
1845 begin
1846 gExit := EXIT_SIMPLE;
1847 EndGame();
1848 Exit;
1849 end;
1851 // process master server communications
1852 g_Net_Slist_Pulse();
1854 case gState of
1855 STATE_INTERSINGLE, // Ñòàòèñòêà ïîñëå ïðîõîæäåíèÿ óðîâíÿ â Îäèíî÷íîé èãðå
1856 STATE_INTERCUSTOM, // Ñòàòèñòêà ïîñëå ïðîõîæäåíèÿ óðîâíÿ â Ñâîåé èãðå
1857 STATE_INTERTEXT, // Òåêñò ìåæäó óðîâíÿìè
1858 STATE_INTERPIC: // Êàðòèíêà ìåæäó óðîâíÿìè
1859 begin
1860 if g_Game_IsNet and g_Game_IsServer then
1861 begin
1862 gInterTime := gInterTime + GAME_TICK;
1863 a := Min((gInterEndTime - gInterTime) div 1000 + 1, 255);
1864 if a <> gServInterTime then
1865 begin
1866 gServInterTime := a;
1867 MH_SEND_TimeSync(gServInterTime);
1868 end;
1869 end;
1871 if (not g_Game_IsClient) and
1875 e_KeyPressed(IK_RETURN) or e_KeyPressed(IK_KPRETURN) or e_KeyPressed(IK_SPACE) or
1876 e_KeyPressed(VK_FIRE) or e_KeyPressed(VK_OPEN) or
1877 e_KeyPressed(JOY0_ATTACK) or e_KeyPressed(JOY1_ATTACK) or
1878 e_KeyPressed(JOY2_ATTACK) or e_KeyPressed(JOY3_ATTACK)
1880 and (not gJustChatted) and (not gConsoleShow) and (not gChatShow)
1881 and (g_ActiveWindow = nil)
1883 or (g_Game_IsNet and ((gInterTime > gInterEndTime) or ((gInterReadyCount >= NetClientCount) and (NetClientCount > 0))))
1885 then
1886 begin // Íàæàëè <Enter>/<Ïðîáåë> èëè ïðîøëî äîñòàòî÷íî âðåìåíè:
1887 g_Game_StopAllSounds(True);
1889 if gMapOnce then // Ýòî áûë òåñò
1890 gExit := EXIT_SIMPLE
1891 else
1892 if gNextMap <> '' then // Ïåðåõîäèì íà ñëåäóþùóþ êàðòó
1893 g_Game_ChangeMap(gNextMap)
1894 else // Ñëåäóþùåé êàðòû íåò
1895 begin
1896 if gGameSettings.GameType in [GT_CUSTOM, GT_SERVER] then
1897 begin
1898 // Âûõîä â ãëàâíîå ìåíþ:
1899 g_Game_Free;
1900 g_GUI_ShowWindow('MainMenu');
1901 gMusic.SetByName('MUSIC_MENU');
1902 gMusic.Play();
1903 gState := STATE_MENU;
1904 end else
1905 begin
1906 // Ôèíàëüíàÿ êàðòèíêà:
1907 g_Game_ExecuteEvent('onwadend');
1908 g_Game_Free();
1909 if not gMusic.SetByName('MUSIC_endmus') then
1910 gMusic.SetByName('MUSIC_STDENDMUS');
1911 gMusic.Play();
1912 gState := STATE_ENDPIC;
1913 end;
1914 g_Game_ExecuteEvent('ongameend');
1915 end;
1917 Exit;
1918 end
1919 else if g_Game_IsClient and
1922 e_KeyPressed(IK_RETURN) or e_KeyPressed(IK_KPRETURN) or e_KeyPressed(IK_SPACE) or
1923 e_KeyPressed(VK_FIRE) or e_KeyPressed(VK_OPEN) or
1924 e_KeyPressed(JOY0_ATTACK) or e_KeyPressed(JOY1_ATTACK) or
1925 e_KeyPressed(JOY2_ATTACK) or e_KeyPressed(JOY3_ATTACK)
1927 and (not gJustChatted) and (not gConsoleShow) and (not gChatShow)
1928 and (g_ActiveWindow = nil)
1930 then
1931 begin
1932 // ready / unready
1933 InterReady();
1934 end;
1936 if gState = STATE_INTERTEXT then
1937 if InterText.counter > 0 then
1938 InterText.counter := InterText.counter - 1;
1939 end;
1941 STATE_FOLD: // Çàòóõàíèå ýêðàíà
1942 begin
1943 if EndingGameCounter = 0 then
1944 begin
1945 // Çàêîí÷èëñÿ óðîâåíü â Ñâîåé èãðå:
1946 if gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT] then
1947 begin
1948 gState := STATE_INTERCUSTOM;
1949 InterReadyTime := -1;
1950 if gLastMap and (gGameSettings.GameMode = GM_COOP) then
1951 begin
1952 g_Game_ExecuteEvent('onwadend');
1953 if not gMusic.SetByName('MUSIC_endmus') then
1954 gMusic.SetByName('MUSIC_STDENDMUS');
1955 end
1956 else
1957 gMusic.SetByName('MUSIC_ROUNDMUS');
1958 gMusic.Play();
1959 e_UnpressAllKeys();
1960 end
1961 else // Çàêîí÷èëàñü ïîñëåäíÿÿ êàðòà â Îäèíî÷íîé èãðå
1962 begin
1963 gMusic.SetByName('MUSIC_INTERMUS');
1964 gMusic.Play();
1965 gState := STATE_INTERSINGLE;
1966 e_UnpressAllKeys();
1967 end;
1968 g_Game_ExecuteEvent('oninter');
1969 end
1970 else
1971 DecMin(EndingGameCounter, 6, 0);
1972 end;
1974 STATE_ENDPIC: // Êàðòèíêà îêîí÷àíèÿ ìåãàÂàäà
1975 begin
1976 if gMapOnce then // Ýòî áûë òåñò
1977 begin
1978 gExit := EXIT_SIMPLE;
1979 Exit;
1980 end;
1981 end;
1983 STATE_SLIST:
1984 g_Serverlist_Control(slCurrent, slTable);
1985 end;
1987 // Ñòàòèñòèêà ïî Tab:
1988 if gGameOn then
1989 IsDrawStat := (not gConsoleShow) and (not gChatShow) and (gGameSettings.GameType <> GT_SINGLE) and g_Console_Action(ACTION_SCORES);
1991 // Èãðà èäåò:
1992 if gGameOn and not gPause and (gState <> STATE_FOLD) then
1993 begin
1994 // Âðåìÿ += 28 ìèëëèñåêóíä:
1995 gTime := gTime + GAME_TICK;
1997 // Ñîîáùåíèå ïîñåðåäèíå ýêðàíà:
1998 if MessageTime = 0 then
1999 MessageText := '';
2000 if MessageTime > 0 then
2001 MessageTime := MessageTime - 1;
2003 if (g_Game_IsServer) then
2004 begin
2005 // Áûë çàäàí ëèìèò âðåìåíè:
2006 if (gGameSettings.TimeLimit > 0) then
2007 if (gTime - gGameStartTime) div 1000 >= gGameSettings.TimeLimit then
2008 begin // Îí ïðîøåë => êîíåö óðîâíÿ
2009 g_Game_NextLevel();
2010 Exit;
2011 end;
2013 // Íàäî ðåñïàâíèòü èãðîêîâ â LMS:
2014 if (gLMSRespawn > LMS_RESPAWN_NONE) and (gLMSRespawnTime < gTime) then
2015 g_Game_RestartRound(gLMSSoftSpawn);
2017 // Ïðîâåðèì ðåçóëüòàò ãîëîñîâàíèÿ, åñëè âðåìÿ ïðîøëî
2018 if gVoteInProgress and (gVoteTimer < gTime) then
2019 g_Game_CheckVote
2020 else if gVotePassed and (gVoteCmdTimer < gTime) then
2021 begin
2022 g_Console_Process(gVoteCommand);
2023 gVoteCommand := '';
2024 gVotePassed := False;
2025 end;
2027 // Çàìåðÿåì âðåìÿ çàõâàòà ôëàãîâ
2028 if gFlags[FLAG_RED].State = FLAG_STATE_CAPTURED then
2029 gFlags[FLAG_RED].CaptureTime := gFlags[FLAG_RED].CaptureTime + GAME_TICK;
2030 if gFlags[FLAG_BLUE].State = FLAG_STATE_CAPTURED then
2031 gFlags[FLAG_BLUE].CaptureTime := gFlags[FLAG_BLUE].CaptureTime + GAME_TICK;
2033 // Áûë çàäàí ëèìèò ïîáåä:
2034 if (gGameSettings.ScoreLimit > 0) then
2035 begin
2036 b := 0;
2038 if gGameSettings.GameMode = GM_DM then
2039 begin // Â DM èùåì èãðîêà ñ max ôðàãàìè
2040 for i := 0 to High(gPlayers) do
2041 if gPlayers[i] <> nil then
2042 if gPlayers[i].Frags > b then
2043 b := gPlayers[i].Frags;
2044 end
2045 else
2046 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
2047 begin //  CTF/TDM âûáèðàåì êîìàíäó ñ íàèáîëüøèì ñ÷åòîì
2048 b := Max(gTeamStat[TEAM_RED].Score, gTeamStat[TEAM_BLUE].Score);
2049 end;
2051 // Ëèìèò ïîáåä íàáðàí => êîíåö óðîâíÿ:
2052 if b >= gGameSettings.ScoreLimit then
2053 begin
2054 g_Game_NextLevel();
2055 Exit;
2056 end;
2057 end;
2059 // Îáðàáàòûâàåì êëàâèøè èãðîêîâ:
2060 if gPlayer1 <> nil then gPlayer1.ReleaseKeys();
2061 if gPlayer2 <> nil then gPlayer2.ReleaseKeys();
2062 if (not gConsoleShow) and (not gChatShow) and (g_ActiveWindow = nil) then
2063 begin
2064 ProcessPlayerControls(gPlayer1, 0, P1MoveButton);
2065 ProcessPlayerControls(gPlayer2, 1, P2MoveButton);
2066 end // if not console
2067 else
2068 begin
2069 if g_Game_IsNet and (gPlayer1 <> nil) then gPlayer1.PressKey(KEY_CHAT, 10000);
2070 end;
2071 // process weapon switch queue
2072 end; // if server
2074 // Íàáëþäàòåëü
2075 if (gPlayer1 = nil) and (gPlayer2 = nil) and
2076 (not gConsoleShow) and (not gChatShow) and (g_ActiveWindow = nil) then
2077 begin
2078 if not gSpectKeyPress then
2079 begin
2080 if gPlayerAction[0, ACTION_JUMP] and (not gSpectAuto) then
2081 begin
2082 // switch spect mode
2083 case gSpectMode of
2084 SPECT_NONE: ; // not spectator
2085 SPECT_STATS,
2086 SPECT_MAPVIEW: Inc(gSpectMode);
2087 SPECT_PLAYERS: gSpectMode := SPECT_STATS; // reset to 1
2088 end;
2089 gSpectKeyPress := True;
2090 end;
2091 if (gSpectMode = SPECT_MAPVIEW)
2092 and (not gSpectAuto) then
2093 begin
2094 if gPlayerAction[0, ACTION_MOVELEFT] then
2095 gSpectX := Max(gSpectX - gSpectStep, 0);
2096 if gPlayerAction[0, ACTION_MOVERIGHT] then
2097 gSpectX := Min(gSpectX + gSpectStep, gMapInfo.Width - gScreenWidth);
2098 if gPlayerAction[0, ACTION_LOOKUP] then
2099 gSpectY := Max(gSpectY - gSpectStep, 0);
2100 if gPlayerAction[0, ACTION_LOOKDOWN] then
2101 gSpectY := Min(gSpectY + gSpectStep, gMapInfo.Height - gScreenHeight);
2102 if gWeaponAction[0, WP_PREV] then
2103 begin
2104 // decrease step
2105 if gSpectStep > 4 then gSpectStep := gSpectStep shr 1;
2106 gWeaponAction[0, WP_PREV] := False;
2107 end;
2108 if gWeaponAction[0, WP_NEXT] then
2109 begin
2110 // increase step
2111 if gSpectStep < 64 then gSpectStep := gSpectStep shl 1;
2112 gWeaponAction[0, WP_NEXT] := False;
2113 end;
2114 end;
2115 if (gSpectMode = SPECT_PLAYERS)
2116 and (not gSpectAuto) then
2117 begin
2118 if gPlayerAction[0, ACTION_LOOKUP] then
2119 begin
2120 // add second view
2121 gSpectViewTwo := True;
2122 gSpectKeyPress := True;
2123 end;
2124 if gPlayerAction[0, ACTION_LOOKDOWN] then
2125 begin
2126 // remove second view
2127 gSpectViewTwo := False;
2128 gSpectKeyPress := True;
2129 end;
2130 if gPlayerAction[0, ACTION_MOVELEFT] then
2131 begin
2132 // prev player (view 1)
2133 gSpectPID1 := GetActivePlayerID_Prev(gSpectPID1);
2134 gSpectKeyPress := True;
2135 end;
2136 if gPlayerAction[0, ACTION_MOVERIGHT] then
2137 begin
2138 // next player (view 1)
2139 gSpectPID1 := GetActivePlayerID_Next(gSpectPID1);
2140 gSpectKeyPress := True;
2141 end;
2142 if gWeaponAction[0, WP_PREV] then
2143 begin
2144 // prev player (view 2)
2145 gSpectPID2 := GetActivePlayerID_Prev(gSpectPID2);
2146 gWeaponAction[0, WP_PREV] := False;
2147 end;
2148 if gWeaponAction[0, WP_NEXT] then
2149 begin
2150 // next player (view 2)
2151 gSpectPID2 := GetActivePlayerID_Next(gSpectPID2);
2152 gWeaponAction[0, WP_NEXT] := False;
2153 end;
2154 end;
2155 if gPlayerAction[0, ACTION_ATTACK] then
2156 begin
2157 if (gSpectMode = SPECT_STATS) and (not gSpectAuto) then
2158 begin
2159 gSpectAuto := True;
2160 gSpectAutoNext := 0;
2161 gSpectViewTwo := False;
2162 gSpectKeyPress := True;
2163 end
2164 else
2165 if gSpectAuto then
2166 begin
2167 gSpectMode := SPECT_STATS;
2168 gSpectAuto := False;
2169 gSpectKeyPress := True;
2170 end;
2171 end;
2172 end
2173 else
2174 if (not gPlayerAction[0, ACTION_JUMP]) and
2175 (not gPlayerAction[0, ACTION_ATTACK]) and
2176 (not gPlayerAction[0, ACTION_MOVELEFT]) and
2177 (not gPlayerAction[0, ACTION_MOVERIGHT]) and
2178 (not gPlayerAction[0, ACTION_LOOKUP]) and
2179 (not gPlayerAction[0, ACTION_LOOKDOWN]) then
2180 gSpectKeyPress := False;
2182 if gSpectAuto then
2183 begin
2184 if gSpectMode = SPECT_MAPVIEW then
2185 begin
2186 i := Min(Max(gSpectX + gSpectAutoStepX, 0), gMapInfo.Width - gScreenWidth);
2187 if i = gSpectX then
2188 gSpectAutoNext := gTime
2189 else
2190 gSpectX := i;
2191 i := Min(Max(gSpectY + gSpectAutoStepY, 0), gMapInfo.Height - gScreenHeight);
2192 if i = gSpectY then
2193 gSpectAutoNext := gTime
2194 else
2195 gSpectY := i;
2196 end;
2197 if gSpectAutoNext <= gTime then
2198 begin
2199 if gSpectAutoNext > 0 then
2200 begin
2201 gSpectMode := GetRandomSpectMode(gSpectMode);
2202 case gSpectMode of
2203 SPECT_MAPVIEW:
2204 begin
2205 gSpectX := Random(gMapInfo.Width - gScreenWidth);
2206 gSpectY := Random(gMapInfo.Height - gScreenHeight);
2207 gSpectAutoStepX := Random(9) - 4;
2208 gSpectAutoStepY := Random(9) - 4;
2209 if ((gSpectX < 800) and (gSpectAutoStepX < 0)) or
2210 ((gSpectX > gMapInfo.Width - gScreenWidth - 800) and (gSpectAutoStepX > 0)) then
2211 gSpectAutoStepX := gSpectAutoStepX * -1;
2212 if ((gSpectY < 800) and (gSpectAutoStepY < 0)) or
2213 ((gSpectY > gMapInfo.Height - gScreenHeight - 800) and (gSpectAutoStepY > 0)) then
2214 gSpectAutoStepY := gSpectAutoStepY * -1;
2215 end;
2216 SPECT_PLAYERS:
2217 begin
2218 gSpectPID1 := GetActivePlayerID_Random(gSpectPID1);
2219 end;
2220 end;
2221 end;
2222 case gSpectMode of
2223 SPECT_STATS: gSpectAutoNext := gTime + (Random(3) + 5) * 1000;
2224 SPECT_MAPVIEW: gSpectAutoNext := gTime + (Random(4) + 7) * 1000;
2225 SPECT_PLAYERS: gSpectAutoNext := gTime + (Random(7) + 8) * 1000;
2226 end;
2227 end;
2228 end;
2229 end;
2231 // Îáíîâëÿåì âñå îñòàëüíîå:
2232 g_Map_Update();
2233 g_Items_Update();
2234 g_Triggers_Update();
2235 g_Weapon_Update();
2236 g_Monsters_Update();
2237 g_GFX_Update();
2238 g_Player_UpdateAll();
2239 g_Player_UpdatePhysicalObjects();
2241 // server: send newly spawned monsters unconditionally
2242 if (gGameSettings.GameType = GT_SERVER) then
2243 begin
2244 if (Length(gMonstersSpawned) > 0) then
2245 begin
2246 for I := 0 to High(gMonstersSpawned) do MH_SEND_MonsterSpawn(gMonstersSpawned[I]);
2247 SetLength(gMonstersSpawned, 0);
2248 end;
2249 end;
2251 if (gSoundTriggerTime > 8) then
2252 begin
2253 g_Game_UpdateTriggerSounds();
2254 gSoundTriggerTime := 0;
2255 end
2256 else
2257 begin
2258 Inc(gSoundTriggerTime);
2259 end;
2261 if (NetMode = NET_SERVER) then
2262 begin
2263 Inc(NetTimeToUpdate);
2264 Inc(NetTimeToReliable);
2266 // send monster updates
2267 if (NetTimeToReliable >= NetRelupdRate) or (NetTimeToUpdate >= NetUpdateRate) then
2268 begin
2269 // send all monsters (periodic sync)
2270 reliableUpdate := (NetTimeToReliable >= NetRelupdRate);
2272 for I := 0 to High(gPlayers) do
2273 begin
2274 if (gPlayers[I] <> nil) then MH_SEND_PlayerPos(reliableUpdate, gPlayers[I].UID);
2275 end;
2277 g_Mons_ForEach(sendMonsPos);
2279 // update flags that aren't stationary
2280 if gGameSettings.GameMode = GM_CTF then
2281 for I := FLAG_RED to FLAG_BLUE do
2282 if gFlags[I].NeedSend then
2283 begin
2284 gFlags[I].NeedSend := False;
2285 MH_SEND_FlagPos(I);
2286 end;
2288 // update items that aren't stationary
2289 g_Items_ForEachAlive(sendItemPos);
2291 if reliableUpdate then
2292 begin
2293 NetTimeToReliable := 0;
2294 NetTimeToUpdate := NetUpdateRate;
2295 end
2296 else
2297 begin
2298 NetTimeToUpdate := 0;
2299 end;
2300 end
2301 else
2302 begin
2303 // send only mosters with some unexpected changes
2304 g_Mons_ForEach(sendMonsPosUnexpected);
2305 end;
2307 // send unexpected platform changes
2308 g_Map_NetSendInterestingPanels();
2310 g_Net_Slist_ServerUpdate();
2312 if NetUseMaster then
2313 begin
2314 if (gTime >= NetTimeToMaster) or g_Net_Slist_IsConnectionInProgress then
2315 begin
2316 if (not g_Net_Slist_IsConnectionActive) then g_Net_Slist_Connect(false); // non-blocking connection to the master
2317 g_Net_Slist_Update;
2318 NetTimeToMaster := gTime + NetMasterRate;
2319 end;
2320 end;
2322 end
2323 else if (NetMode = NET_CLIENT) then
2324 begin
2325 MC_SEND_PlayerPos();
2326 end;
2327 end; // if gameOn ...
2329 // Àêòèâíî îêíî èíòåðôåéñà - ïåðåäàåì êëàâèøè åìó:
2330 if g_ActiveWindow <> nil then
2331 begin
2332 w := e_GetFirstKeyPressed();
2334 if (w <> IK_INVALID) then
2335 begin
2336 Msg.Msg := MESSAGE_DIKEY;
2337 Msg.wParam := w;
2338 g_ActiveWindow.OnMessage(Msg);
2339 end;
2341 // Åñëè îíî îò ýòîãî íå çàêðûëîñü, òî îáíîâëÿåì:
2342 if g_ActiveWindow <> nil then
2343 g_ActiveWindow.Update();
2345 // Íóæíî ñìåíèòü ðàçðåøåíèå:
2346 if gResolutionChange then
2347 begin
2348 e_WriteLog('Changing resolution', TMsgType.Notify);
2349 g_Game_ChangeResolution(gRC_Width, gRC_Height, gRC_FullScreen, gRC_Maximized);
2350 gResolutionChange := False;
2351 g_ActiveWindow := nil;
2352 end;
2354 // Íóæíî ñìåíèòü ÿçûê:
2355 if gLanguageChange then
2356 begin
2357 //e_WriteLog('Read language file', MSG_NOTIFY);
2358 //g_Language_Load(DataDir + gLanguage + '.txt');
2359 g_Language_Set(gLanguage);
2360 {$IFNDEF HEADLESS}
2361 g_Menu_Reset();
2362 {$ENDIF}
2363 gLanguageChange := False;
2364 end;
2365 end;
2367 // Ãîðÿ÷àÿ êëàâèøà äëÿ âûçîâà ìåíþ âûõîäà èç èãðû (F10):
2368 if e_KeyPressed(IK_F10) and
2369 gGameOn and
2370 (not gConsoleShow) and
2371 (g_ActiveWindow = nil) then
2372 begin
2373 KeyPress(IK_F10);
2374 end;
2376 Time := sys_GetTicks() {div 1000};
2378 // Îáðàáîòêà îòëîæåííûõ ñîáûòèé:
2379 if gDelayedEvents <> nil then
2380 for a := 0 to High(gDelayedEvents) do
2381 if gDelayedEvents[a].Pending and
2383 ((gDelayedEvents[a].DEType = DE_GLOBEVENT) and (gDelayedEvents[a].Time <= Time)) or
2384 ((gDelayedEvents[a].DEType > DE_GLOBEVENT) and (gDelayedEvents[a].Time <= gTime))
2385 ) then
2386 begin
2387 case gDelayedEvents[a].DEType of
2388 DE_GLOBEVENT:
2389 g_Game_ExecuteEvent(gDelayedEvents[a].DEStr);
2390 DE_BFGHIT:
2391 if gGameOn then
2392 g_Game_Announce_GoodShot(gDelayedEvents[a].DENum);
2393 DE_KILLCOMBO:
2394 if gGameOn then
2395 begin
2396 g_Game_Announce_KillCombo(gDelayedEvents[a].DENum);
2397 if g_Game_IsNet and g_Game_IsServer then
2398 MH_SEND_GameEvent(NET_EV_KILLCOMBO, gDelayedEvents[a].DENum);
2399 end;
2400 DE_BODYKILL:
2401 if gGameOn then
2402 g_Game_Announce_BodyKill(gDelayedEvents[a].DENum);
2403 end;
2404 gDelayedEvents[a].Pending := False;
2405 end;
2407 // Êàæäóþ ñåêóíäó îáíîâëÿåì ñ÷åò÷èê îáíîâëåíèé:
2408 UPSCounter := UPSCounter + 1;
2409 if Time - UPSTime >= 1000 then
2410 begin
2411 UPS := UPSCounter;
2412 UPSCounter := 0;
2413 UPSTime := Time;
2414 end;
2416 if gGameOn then
2417 begin
2418 g_Weapon_AddDynLights();
2419 g_Items_AddDynLights();
2420 end;
2421 end;
2423 procedure g_Game_LoadChatSounds(Resource: string);
2424 var
2425 WAD: TWADFile;
2426 FileName, Snd: string;
2427 p: Pointer;
2428 len, cnt, tags, i, j: Integer;
2429 cfg: TConfig;
2430 begin
2431 FileName := g_ExtractWadName(Resource);
2433 WAD := TWADFile.Create();
2434 WAD.ReadFile(FileName);
2436 if not WAD.GetResource(g_ExtractFilePathName(Resource), p, len) then
2437 begin
2438 gChatSounds := nil;
2439 WAD.Free();
2440 Exit;
2441 end;
2443 cfg := TConfig.CreateMem(p, len);
2444 cnt := cfg.ReadInt('ChatSounds', 'Count', 0);
2446 SetLength(gChatSounds, cnt);
2447 for i := 0 to Length(gChatSounds) - 1 do
2448 begin
2449 gChatSounds[i].Sound := nil;
2450 Snd := Trim(cfg.ReadStr(IntToStr(i), 'Sound', ''));
2451 tags := cfg.ReadInt(IntToStr(i), 'Tags', 0);
2452 if (Snd = '') or (Tags <= 0) then
2453 continue;
2454 g_Sound_CreateWADEx('SOUND_CHAT_MACRO' + IntToStr(i), GameWAD+':'+Snd);
2455 gChatSounds[i].Sound := TPlayableSound.Create();
2456 gChatSounds[i].Sound.SetByName('SOUND_CHAT_MACRO' + IntToStr(i));
2457 SetLength(gChatSounds[i].Tags, tags);
2458 for j := 0 to tags - 1 do
2459 gChatSounds[i].Tags[j] := toLowerCase1251(cfg.ReadStr(IntToStr(i), 'Tag' + IntToStr(j), ''));
2460 gChatSounds[i].FullWord := cfg.ReadBool(IntToStr(i), 'FullWord', False);
2461 end;
2463 cfg.Free();
2464 WAD.Free();
2465 end;
2467 procedure g_Game_FreeChatSounds();
2468 var
2469 i: Integer;
2470 begin
2471 for i := 0 to Length(gChatSounds) - 1 do
2472 begin
2473 gChatSounds[i].Sound.Free();
2474 g_Sound_Delete('SOUND_CHAT_MACRO' + IntToStr(i));
2475 end;
2476 SetLength(gChatSounds, 0);
2477 gChatSounds := nil;
2478 end;
2480 procedure g_Game_LoadData();
2481 var
2482 wl, hl: Integer;
2483 wr, hr: Integer;
2484 wb, hb: Integer;
2485 wm, hm: Integer;
2486 begin
2487 if DataLoaded then Exit;
2489 e_WriteLog('Loading game data...', TMsgType.Notify);
2491 g_Texture_CreateWADEx('NOTEXTURE', GameWAD+':TEXTURES\NOTEXTURE');
2492 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUD', GameWAD+':TEXTURES\HUD');
2493 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDAIR', GameWAD+':TEXTURES\AIRBAR');
2494 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDJET', GameWAD+':TEXTURES\JETBAR');
2495 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDBG', GameWAD+':TEXTURES\HUDBG');
2496 g_Texture_CreateWADEx('TEXTURE_PLAYER_ARMORHUD', GameWAD+':TEXTURES\ARMORHUD');
2497 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG', GameWAD+':TEXTURES\FLAGHUD_R_BASE');
2498 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_S', GameWAD+':TEXTURES\FLAGHUD_R_STOLEN');
2499 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_D', GameWAD+':TEXTURES\FLAGHUD_R_DROP');
2500 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG', GameWAD+':TEXTURES\FLAGHUD_B_BASE');
2501 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_S', GameWAD+':TEXTURES\FLAGHUD_B_STOLEN');
2502 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_D', GameWAD+':TEXTURES\FLAGHUD_B_DROP');
2503 g_Texture_CreateWADEx('TEXTURE_PLAYER_TALKBUBBLE', GameWAD+':TEXTURES\TALKBUBBLE');
2504 g_Texture_CreateWADEx('TEXTURE_PLAYER_INVULPENTA', GameWAD+':TEXTURES\PENTA');
2505 g_Texture_CreateWADEx('TEXTURE_PLAYER_INDICATOR', GameWAD+':TEXTURES\PLRIND');
2507 hasPBarGfx := true;
2508 if not g_Texture_CreateWADEx('UI_GFX_PBAR_LEFT', GameWAD+':TEXTURES\LLEFT') then hasPBarGfx := false;
2509 if not g_Texture_CreateWADEx('UI_GFX_PBAR_MARKER', GameWAD+':TEXTURES\LMARKER') then hasPBarGfx := false;
2510 if not g_Texture_CreateWADEx('UI_GFX_PBAR_MIDDLE', GameWAD+':TEXTURES\LMIDDLE') then hasPBarGfx := false;
2511 if not g_Texture_CreateWADEx('UI_GFX_PBAR_RIGHT', GameWAD+':TEXTURES\LRIGHT') then hasPBarGfx := false;
2513 if hasPBarGfx then
2514 begin
2515 g_Texture_GetSize('UI_GFX_PBAR_LEFT', wl, hl);
2516 g_Texture_GetSize('UI_GFX_PBAR_RIGHT', wr, hr);
2517 g_Texture_GetSize('UI_GFX_PBAR_MIDDLE', wb, hb);
2518 g_Texture_GetSize('UI_GFX_PBAR_MARKER', wm, hm);
2519 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
2520 begin
2521 // yay!
2522 end
2523 else
2524 begin
2525 hasPBarGfx := false;
2526 end;
2527 end;
2529 g_Frames_CreateWAD(nil, 'FRAMES_TELEPORT', GameWAD+':TEXTURES\TELEPORT', 64, 64, 10, False);
2530 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH', GameWAD+':WEAPONS\PUNCH', 64, 64, 4, False);
2531 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_UP', GameWAD+':WEAPONS\PUNCH_UP', 64, 64, 4, False);
2532 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_DN', GameWAD+':WEAPONS\PUNCH_DN', 64, 64, 4, False);
2533 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK', GameWAD+':WEAPONS\PUNCHB', 64, 64, 4, False);
2534 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK_UP', GameWAD+':WEAPONS\PUNCHB_UP', 64, 64, 4, False);
2535 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK_DN', GameWAD+':WEAPONS\PUNCHB_DN', 64, 64, 4, False);
2536 g_Sound_CreateWADEx('SOUND_GAME_TELEPORT', GameWAD+':SOUNDS\TELEPORT');
2537 g_Sound_CreateWADEx('SOUND_GAME_NOTELEPORT', GameWAD+':SOUNDS\NOTELEPORT');
2538 g_Sound_CreateWADEx('SOUND_GAME_SECRET', GameWAD+':SOUNDS\SECRET');
2539 g_Sound_CreateWADEx('SOUND_GAME_DOOROPEN', GameWAD+':SOUNDS\DOOROPEN');
2540 g_Sound_CreateWADEx('SOUND_GAME_DOORCLOSE', GameWAD+':SOUNDS\DOORCLOSE');
2541 g_Sound_CreateWADEx('SOUND_GAME_BULK1', GameWAD+':SOUNDS\BULK1');
2542 g_Sound_CreateWADEx('SOUND_GAME_BULK2', GameWAD+':SOUNDS\BULK2');
2543 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE1', GameWAD+':SOUNDS\BUBBLE1');
2544 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE2', GameWAD+':SOUNDS\BUBBLE2');
2545 g_Sound_CreateWADEx('SOUND_GAME_BURNING', GameWAD+':SOUNDS\BURNING');
2546 g_Sound_CreateWADEx('SOUND_GAME_SWITCH1', GameWAD+':SOUNDS\SWITCH1');
2547 g_Sound_CreateWADEx('SOUND_GAME_SWITCH0', GameWAD+':SOUNDS\SWITCH0');
2548 g_Sound_CreateWADEx('SOUND_GAME_RADIO', GameWAD+':SOUNDS\RADIO');
2549 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD1', GameWAD+':SOUNDS\GOOD1');
2550 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD2', GameWAD+':SOUNDS\GOOD2');
2551 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD3', GameWAD+':SOUNDS\GOOD3');
2552 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD4', GameWAD+':SOUNDS\GOOD4');
2553 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL2X', GameWAD+':SOUNDS\KILL2X');
2554 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL3X', GameWAD+':SOUNDS\KILL3X');
2555 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL4X', GameWAD+':SOUNDS\KILL4X');
2556 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILLMX', GameWAD+':SOUNDS\KILLMX');
2557 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA1', GameWAD+':SOUNDS\MUHAHA1');
2558 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA2', GameWAD+':SOUNDS\MUHAHA2');
2559 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA3', GameWAD+':SOUNDS\MUHAHA3');
2560 g_Sound_CreateWADEx('SOUND_CTF_GET1', GameWAD+':SOUNDS\GETFLAG1');
2561 g_Sound_CreateWADEx('SOUND_CTF_GET2', GameWAD+':SOUNDS\GETFLAG2');
2562 g_Sound_CreateWADEx('SOUND_CTF_LOST1', GameWAD+':SOUNDS\LOSTFLG1');
2563 g_Sound_CreateWADEx('SOUND_CTF_LOST2', GameWAD+':SOUNDS\LOSTFLG2');
2564 g_Sound_CreateWADEx('SOUND_CTF_RETURN1', GameWAD+':SOUNDS\RETFLAG1');
2565 g_Sound_CreateWADEx('SOUND_CTF_RETURN2', GameWAD+':SOUNDS\RETFLAG2');
2566 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE1', GameWAD+':SOUNDS\CAPFLAG1');
2567 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE2', GameWAD+':SOUNDS\CAPFLAG2');
2569 goodsnd[0] := TPlayableSound.Create();
2570 goodsnd[1] := TPlayableSound.Create();
2571 goodsnd[2] := TPlayableSound.Create();
2572 goodsnd[3] := TPlayableSound.Create();
2574 goodsnd[0].SetByName('SOUND_ANNOUNCER_GOOD1');
2575 goodsnd[1].SetByName('SOUND_ANNOUNCER_GOOD2');
2576 goodsnd[2].SetByName('SOUND_ANNOUNCER_GOOD3');
2577 goodsnd[3].SetByName('SOUND_ANNOUNCER_GOOD4');
2579 killsnd[0] := TPlayableSound.Create();
2580 killsnd[1] := TPlayableSound.Create();
2581 killsnd[2] := TPlayableSound.Create();
2582 killsnd[3] := TPlayableSound.Create();
2584 killsnd[0].SetByName('SOUND_ANNOUNCER_KILL2X');
2585 killsnd[1].SetByName('SOUND_ANNOUNCER_KILL3X');
2586 killsnd[2].SetByName('SOUND_ANNOUNCER_KILL4X');
2587 killsnd[3].SetByName('SOUND_ANNOUNCER_KILLMX');
2589 hahasnd[0] := TPlayableSound.Create();
2590 hahasnd[1] := TPlayableSound.Create();
2591 hahasnd[2] := TPlayableSound.Create();
2593 hahasnd[0].SetByName('SOUND_ANNOUNCER_MUHAHA1');
2594 hahasnd[1].SetByName('SOUND_ANNOUNCER_MUHAHA2');
2595 hahasnd[2].SetByName('SOUND_ANNOUNCER_MUHAHA3');
2597 sound_get_flag[0] := TPlayableSound.Create();
2598 sound_get_flag[1] := TPlayableSound.Create();
2599 sound_lost_flag[0] := TPlayableSound.Create();
2600 sound_lost_flag[1] := TPlayableSound.Create();
2601 sound_ret_flag[0] := TPlayableSound.Create();
2602 sound_ret_flag[1] := TPlayableSound.Create();
2603 sound_cap_flag[0] := TPlayableSound.Create();
2604 sound_cap_flag[1] := TPlayableSound.Create();
2606 sound_get_flag[0].SetByName('SOUND_CTF_GET1');
2607 sound_get_flag[1].SetByName('SOUND_CTF_GET2');
2608 sound_lost_flag[0].SetByName('SOUND_CTF_LOST1');
2609 sound_lost_flag[1].SetByName('SOUND_CTF_LOST2');
2610 sound_ret_flag[0].SetByName('SOUND_CTF_RETURN1');
2611 sound_ret_flag[1].SetByName('SOUND_CTF_RETURN2');
2612 sound_cap_flag[0].SetByName('SOUND_CTF_CAPTURE1');
2613 sound_cap_flag[1].SetByName('SOUND_CTF_CAPTURE2');
2615 g_Game_LoadChatSounds(GameWAD+':CHATSND\SNDCFG');
2617 g_Game_SetLoadingText(_lc[I_LOAD_ITEMS_DATA], 0, False);
2618 g_Items_LoadData();
2620 g_Game_SetLoadingText(_lc[I_LOAD_WEAPONS_DATA], 0, False);
2621 g_Weapon_LoadData();
2623 g_Monsters_LoadData();
2625 DataLoaded := True;
2626 end;
2628 procedure g_Game_FreeData();
2629 begin
2630 if not DataLoaded then Exit;
2632 g_Items_FreeData();
2633 g_Weapon_FreeData();
2634 g_Monsters_FreeData();
2636 e_WriteLog('Releasing game data...', TMsgType.Notify);
2638 g_Texture_Delete('NOTEXTURE');
2639 g_Texture_Delete('TEXTURE_PLAYER_HUD');
2640 g_Texture_Delete('TEXTURE_PLAYER_HUDBG');
2641 g_Texture_Delete('TEXTURE_PLAYER_ARMORHUD');
2642 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG');
2643 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_S');
2644 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_D');
2645 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG');
2646 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_S');
2647 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_D');
2648 g_Texture_Delete('TEXTURE_PLAYER_TALKBUBBLE');
2649 g_Texture_Delete('TEXTURE_PLAYER_INVULPENTA');
2650 g_Frames_DeleteByName('FRAMES_TELEPORT');
2651 g_Frames_DeleteByName('FRAMES_PUNCH');
2652 g_Frames_DeleteByName('FRAMES_PUNCH_UP');
2653 g_Frames_DeleteByName('FRAMES_PUNCH_DN');
2654 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK');
2655 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK_UP');
2656 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK_DN');
2657 g_Sound_Delete('SOUND_GAME_TELEPORT');
2658 g_Sound_Delete('SOUND_GAME_NOTELEPORT');
2659 g_Sound_Delete('SOUND_GAME_SECRET');
2660 g_Sound_Delete('SOUND_GAME_DOOROPEN');
2661 g_Sound_Delete('SOUND_GAME_DOORCLOSE');
2662 g_Sound_Delete('SOUND_GAME_BULK1');
2663 g_Sound_Delete('SOUND_GAME_BULK2');
2664 g_Sound_Delete('SOUND_GAME_BUBBLE1');
2665 g_Sound_Delete('SOUND_GAME_BUBBLE2');
2666 g_Sound_Delete('SOUND_GAME_BURNING');
2667 g_Sound_Delete('SOUND_GAME_SWITCH1');
2668 g_Sound_Delete('SOUND_GAME_SWITCH0');
2670 goodsnd[0].Free();
2671 goodsnd[1].Free();
2672 goodsnd[2].Free();
2673 goodsnd[3].Free();
2675 g_Sound_Delete('SOUND_ANNOUNCER_GOOD1');
2676 g_Sound_Delete('SOUND_ANNOUNCER_GOOD2');
2677 g_Sound_Delete('SOUND_ANNOUNCER_GOOD3');
2678 g_Sound_Delete('SOUND_ANNOUNCER_GOOD4');
2680 killsnd[0].Free();
2681 killsnd[1].Free();
2682 killsnd[2].Free();
2683 killsnd[3].Free();
2685 g_Sound_Delete('SOUND_ANNOUNCER_KILL2X');
2686 g_Sound_Delete('SOUND_ANNOUNCER_KILL3X');
2687 g_Sound_Delete('SOUND_ANNOUNCER_KILL4X');
2688 g_Sound_Delete('SOUND_ANNOUNCER_KILLMX');
2690 hahasnd[0].Free();
2691 hahasnd[1].Free();
2692 hahasnd[2].Free();
2694 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA1');
2695 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA2');
2696 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA3');
2698 sound_get_flag[0].Free();
2699 sound_get_flag[1].Free();
2700 sound_lost_flag[0].Free();
2701 sound_lost_flag[1].Free();
2702 sound_ret_flag[0].Free();
2703 sound_ret_flag[1].Free();
2704 sound_cap_flag[0].Free();
2705 sound_cap_flag[1].Free();
2707 g_Sound_Delete('SOUND_CTF_GET1');
2708 g_Sound_Delete('SOUND_CTF_GET2');
2709 g_Sound_Delete('SOUND_CTF_LOST1');
2710 g_Sound_Delete('SOUND_CTF_LOST2');
2711 g_Sound_Delete('SOUND_CTF_RETURN1');
2712 g_Sound_Delete('SOUND_CTF_RETURN2');
2713 g_Sound_Delete('SOUND_CTF_CAPTURE1');
2714 g_Sound_Delete('SOUND_CTF_CAPTURE2');
2716 g_Game_FreeChatSounds();
2718 DataLoaded := False;
2719 end;
2721 procedure DrawCustomStat();
2722 var
2723 pc, x, y, w, _y,
2724 w1, w2, w3,
2725 t, p, m: Integer;
2726 ww1, hh1: Word;
2727 ww2, hh2, r, g, b, rr, gg, bb: Byte;
2728 s1, s2, topstr: String;
2729 begin
2730 e_TextureFontGetSize(gStdFont, ww2, hh2);
2732 sys_HandleInput;
2734 if g_Console_Action(ACTION_SCORES) then
2735 begin
2736 if not gStatsPressed then
2737 begin
2738 gStatsOff := not gStatsOff;
2739 gStatsPressed := True;
2740 end;
2741 end
2742 else
2743 gStatsPressed := False;
2745 if gStatsOff then
2746 begin
2747 s1 := _lc[I_MENU_INTER_NOTICE_TAB];
2748 w := (Length(s1) * ww2) div 2;
2749 x := gScreenWidth div 2 - w;
2750 y := 8;
2751 e_TextureFontPrint(x, y, s1, gStdFont);
2752 Exit;
2753 end;
2755 if (gGameSettings.GameMode = GM_COOP) then
2756 begin
2757 if gMissionFailed then
2758 topstr := _lc[I_MENU_INTER_MISSION_FAIL]
2759 else
2760 topstr := _lc[I_MENU_INTER_LEVEL_COMPLETE];
2761 end
2762 else
2763 topstr := _lc[I_MENU_INTER_ROUND_OVER];
2765 e_CharFont_GetSize(gMenuFont, topstr, ww1, hh1);
2766 e_CharFont_Print(gMenuFont, (gScreenWidth div 2)-(ww1 div 2), 16, topstr);
2768 if g_Game_IsNet then
2769 begin
2770 topstr := Format(_lc[I_MENU_INTER_NOTICE_TIME], [gServInterTime]);
2771 if not gChatShow then
2772 e_TextureFontPrintEx((gScreenWidth div 2)-(Length(topstr)*ww2 div 2),
2773 gScreenHeight-(hh2+4)*2, topstr, gStdFont, 255, 255, 255, 1);
2774 end;
2776 if g_Game_IsClient then
2777 topstr := _lc[I_MENU_INTER_NOTICE_MAP]
2778 else
2779 topstr := _lc[I_MENU_INTER_NOTICE_SPACE];
2780 if not gChatShow then
2781 e_TextureFontPrintEx((gScreenWidth div 2)-(Length(topstr)*ww2 div 2),
2782 gScreenHeight-(hh2+4), topstr, gStdFont, 255, 255, 255, 1);
2784 x := 32;
2785 y := 16+hh1+16;
2787 w := gScreenWidth-x*2;
2789 w2 := (w-16) div 6;
2790 w3 := w2;
2791 w1 := w-16-w2-w3;
2793 e_DrawFillQuad(x, y, gScreenWidth-x-1, gScreenHeight-y-1, 64, 64, 64, 32);
2794 e_DrawQuad(x, y, gScreenWidth-x-1, gScreenHeight-y-1, 255, 127, 0);
2796 m := Max(Length(_lc[I_MENU_MAP])+1, Length(_lc[I_GAME_GAME_TIME])+1)*ww2;
2798 case CustomStat.GameMode of
2799 GM_DM:
2800 begin
2801 if gGameSettings.MaxLives = 0 then
2802 s1 := _lc[I_GAME_DM]
2803 else
2804 s1 := _lc[I_GAME_LMS];
2805 end;
2806 GM_TDM:
2807 begin
2808 if gGameSettings.MaxLives = 0 then
2809 s1 := _lc[I_GAME_TDM]
2810 else
2811 s1 := _lc[I_GAME_TLMS];
2812 end;
2813 GM_CTF: s1 := _lc[I_GAME_CTF];
2814 GM_COOP:
2815 begin
2816 if gGameSettings.MaxLives = 0 then
2817 s1 := _lc[I_GAME_COOP]
2818 else
2819 s1 := _lc[I_GAME_SURV];
2820 end;
2821 else s1 := '';
2822 end;
2824 _y := y+16;
2825 e_TextureFontPrintEx(x+(w div 2)-(Length(s1)*ww2 div 2), _y, s1, gStdFont, 255, 255, 255, 1);
2826 _y := _y+8;
2828 _y := _y+16;
2829 e_TextureFontPrintEx(x+8, _y, _lc[I_MENU_MAP], gStdFont, 255, 127, 0, 1);
2830 e_TextureFontPrint(x+8+m, _y, Format('%s - %s', [CustomStat.Map, CustomStat.MapName]), gStdFont);
2832 _y := _y+16;
2833 e_TextureFontPrintEx(x+8, _y, _lc[I_GAME_GAME_TIME], gStdFont, 255, 127, 0, 1);
2834 e_TextureFontPrint(x+8+m, _y, Format('%d:%.2d:%.2d', [CustomStat.GameTime div 1000 div 3600,
2835 (CustomStat.GameTime div 1000 div 60) mod 60,
2836 CustomStat.GameTime div 1000 mod 60]), gStdFont);
2838 pc := Length(CustomStat.PlayerStat);
2839 if pc = 0 then Exit;
2841 if CustomStat.GameMode = GM_COOP then
2842 begin
2843 m := Max(Length(_lc[I_GAME_MONSTERS])+1, Length(_lc[I_GAME_SECRETS])+1)*ww2;
2844 _y := _y+32;
2845 s2 := _lc[I_GAME_MONSTERS];
2846 e_TextureFontPrintEx(x+8, _y, s2, gStdFont, 255, 127, 0, 1);
2847 e_TextureFontPrintEx(x+8+m, _y, IntToStr(gCoopMonstersKilled) + '/' + IntToStr(gTotalMonsters), gStdFont, 255, 255, 255, 1);
2848 _y := _y+16;
2849 s2 := _lc[I_GAME_SECRETS];
2850 e_TextureFontPrintEx(x+8, _y, s2, gStdFont, 255, 127, 0, 1);
2851 e_TextureFontPrintEx(x+8+m, _y, IntToStr(gCoopSecretsFound) + '/' + IntToStr(gSecretsCount), gStdFont, 255, 255, 255, 1);
2852 if gLastMap then
2853 begin
2854 m := Max(Length(_lc[I_GAME_MONSTERS_TOTAL])+1, Length(_lc[I_GAME_SECRETS_TOTAL])+1)*ww2;
2855 _y := _y-16;
2856 s2 := _lc[I_GAME_MONSTERS_TOTAL];
2857 e_TextureFontPrintEx(x+250, _y, s2, gStdFont, 255, 127, 0, 1);
2858 e_TextureFontPrintEx(x+250+m, _y, IntToStr(gCoopTotalMonstersKilled) + '/' + IntToStr(gCoopTotalMonsters), gStdFont, 255, 255, 255, 1);
2859 _y := _y+16;
2860 s2 := _lc[I_GAME_SECRETS_TOTAL];
2861 e_TextureFontPrintEx(x+250, _y, s2, gStdFont, 255, 127, 0, 1);
2862 e_TextureFontPrintEx(x+250+m, _y, IntToStr(gCoopTotalSecretsFound) + '/' + IntToStr(gCoopTotalSecrets), gStdFont, 255, 255, 255, 1);
2863 end;
2864 end;
2866 if CustomStat.GameMode in [GM_TDM, GM_CTF] then
2867 begin
2868 _y := _y+16+16;
2870 with CustomStat do
2871 if TeamStat[TEAM_RED].Score > TeamStat[TEAM_BLUE].Score then s1 := _lc[I_GAME_WIN_RED]
2872 else if TeamStat[TEAM_BLUE].Score > TeamStat[TEAM_RED].Score then s1 := _lc[I_GAME_WIN_BLUE]
2873 else s1 := _lc[I_GAME_WIN_DRAW];
2875 e_TextureFontPrintEx(x+8+(w div 2)-(Length(s1)*ww2 div 2), _y, s1, gStdFont, 255, 255, 255, 1);
2876 _y := _y+40;
2878 for t := TEAM_RED to TEAM_BLUE do
2879 begin
2880 if t = TEAM_RED then
2881 begin
2882 e_TextureFontPrintEx(x+8, _y, _lc[I_GAME_TEAM_RED],
2883 gStdFont, 255, 0, 0, 1);
2884 e_TextureFontPrintEx(x+w1+8, _y, IntToStr(CustomStat.TeamStat[TEAM_RED].Score),
2885 gStdFont, 255, 0, 0, 1);
2886 r := 255;
2887 g := 0;
2888 b := 0;
2889 end
2890 else
2891 begin
2892 e_TextureFontPrintEx(x+8, _y, _lc[I_GAME_TEAM_BLUE],
2893 gStdFont, 0, 0, 255, 1);
2894 e_TextureFontPrintEx(x+w1+8, _y, IntToStr(CustomStat.TeamStat[TEAM_BLUE].Score),
2895 gStdFont, 0, 0, 255, 1);
2896 r := 0;
2897 g := 0;
2898 b := 255;
2899 end;
2901 e_DrawLine(1, x+8, _y+20, x-8+w, _y+20, r, g, b);
2902 _y := _y+24;
2904 for p := 0 to High(CustomStat.PlayerStat) do
2905 if CustomStat.PlayerStat[p].Team = t then
2906 with CustomStat.PlayerStat[p] do
2907 begin
2908 if Spectator then
2909 begin
2910 rr := r div 2;
2911 gg := g div 2;
2912 bb := b div 2;
2913 end
2914 else
2915 begin
2916 rr := r;
2917 gg := g;
2918 bb := b;
2919 end;
2920 if (gPlayers[Num] <> nil) and (gPlayers[Num].FReady) then
2921 e_TextureFontPrintEx(x+16, _y, Name + ' *', gStdFont, rr, gg, bb, 1)
2922 else
2923 e_TextureFontPrintEx(x+16, _y, Name, gStdFont, rr, gg, bb, 1);
2924 e_TextureFontPrintEx(x+w1+16, _y, IntToStr(Frags), gStdFont, rr, gg, bb, 1);
2925 e_TextureFontPrintEx(x+w1+w2+16, _y, IntToStr(Deaths), gStdFont, rr, gg, bb, 1);
2926 _y := _y+24;
2927 end;
2929 _y := _y+16+16;
2930 end;
2931 end
2932 else if CustomStat.GameMode in [GM_DM, GM_COOP] then
2933 begin
2934 _y := _y+40;
2935 e_TextureFontPrintEx(x+8, _y, _lc[I_GAME_PLAYER_NAME], gStdFont, 255, 127, 0, 1);
2936 e_TextureFontPrintEx(x+8+w1, _y, _lc[I_GAME_FRAGS], gStdFont, 255, 127, 0, 1);
2937 e_TextureFontPrintEx(x+8+w1+w2, _y, _lc[I_GAME_DEATHS], gStdFont, 255, 127, 0, 1);
2939 _y := _y+24;
2940 for p := 0 to High(CustomStat.PlayerStat) do
2941 with CustomStat.PlayerStat[p] do
2942 begin
2943 e_DrawFillQuad(x+8, _y+4, x+24-1, _y+16+4-1, Color.R, Color.G, Color.B, 0);
2945 if Spectator then
2946 r := 127
2947 else
2948 r := 255;
2950 if (gPlayers[Num] <> nil) and (gPlayers[Num].FReady) then
2951 e_TextureFontPrintEx(x+8+16+8, _y+4, Name + ' *', gStdFont, r, r, r, 1, True)
2952 else
2953 e_TextureFontPrintEx(x+8+16+8, _y+4, Name, gStdFont, r, r, r, 1, True);
2954 e_TextureFontPrintEx(x+w1+8+16+8, _y+4, IntToStr(Frags), gStdFont, r, r, r, 1, True);
2955 e_TextureFontPrintEx(x+w1+w2+8+16+8, _y+4, IntToStr(Deaths), gStdFont, r, r, r, 1, True);
2956 _y := _y+24;
2957 end;
2958 end;
2960 // HACK: take stats screenshot immediately after the first frame of the stats showing
2961 if gScreenshotStats and (not StatShotDone) and (Length(CustomStat.PlayerStat) > 1) then
2962 begin
2963 g_TakeScreenShot('stats/' + StatFilename);
2964 StatShotDone := True;
2965 end;
2966 end;
2968 procedure DrawSingleStat();
2969 var
2970 tm, key_x, val_x, y: Integer;
2971 w1, w2, h: Word;
2972 s1, s2: String;
2974 procedure player_stat(n: Integer);
2975 var
2976 kpm: Real;
2978 begin
2979 // "Kills: # / #":
2980 s1 := Format(' %d ', [SingleStat.PlayerStat[n].Kills]);
2981 s2 := Format(' %d', [gTotalMonsters]);
2983 e_CharFont_Print(gMenuFont, key_x, y, _lc[I_MENU_INTER_KILLS]);
2984 e_CharFont_PrintEx(gMenuFont, val_x, y, s1, _RGB(255, 0, 0));
2985 e_CharFont_GetSize(gMenuFont, s1, w1, h);
2986 e_CharFont_Print(gMenuFont, val_x+w1, y, '/');
2987 s1 := s1 + '/';
2988 e_CharFont_GetSize(gMenuFont, s1, w1, h);
2989 e_CharFont_PrintEx(gMenuFont, val_x+w1, y, s2, _RGB(255, 0, 0));
2991 // "Kills-per-minute: ##.#":
2992 s1 := _lc[I_MENU_INTER_KPM];
2993 if tm > 0 then
2994 kpm := (SingleStat.PlayerStat[n].Kills / tm) * 60
2995 else
2996 kpm := SingleStat.PlayerStat[n].Kills;
2997 s2 := Format(' %.1f', [kpm]);
2999 e_CharFont_Print(gMenuFont, key_x, y+32, s1);
3000 e_CharFont_PrintEx(gMenuFont, val_x, y+32, s2, _RGB(255, 0, 0));
3002 // "Secrets found: # / #":
3003 s1 := Format(' %d ', [SingleStat.PlayerStat[n].Secrets]);
3004 s2 := Format(' %d', [SingleStat.TotalSecrets]);
3006 e_CharFont_Print(gMenuFont, key_x, y+64, _lc[I_MENU_INTER_SECRETS]);
3007 e_CharFont_PrintEx(gMenuFont, val_x, y+64, s1, _RGB(255, 0, 0));
3008 e_CharFont_GetSize(gMenuFont, s1, w1, h);
3009 e_CharFont_Print(gMenuFont, val_x+w1, y+64, '/');
3010 s1 := s1 + '/';
3011 e_CharFont_GetSize(gMenuFont, s1, w1, h);
3012 e_CharFont_PrintEx(gMenuFont, val_x+w1, y+64, s2, _RGB(255, 0, 0));
3013 end;
3015 begin
3016 // "Level Complete":
3017 e_CharFont_GetSize(gMenuFont, _lc[I_MENU_INTER_LEVEL_COMPLETE], w1, h);
3018 e_CharFont_Print(gMenuFont, (gScreenWidth-w1) div 2, 32, _lc[I_MENU_INTER_LEVEL_COMPLETE]);
3020 // Îïðåäåëÿåì êîîðäèíàòû âûðàâíèâàíèÿ ïî ñàìîé äëèííîé ñòðîêå:
3021 s1 := _lc[I_MENU_INTER_KPM];
3022 e_CharFont_GetSize(gMenuFont, s1, w1, h);
3023 Inc(w1, 16);
3024 s1 := ' 9999.9';
3025 e_CharFont_GetSize(gMenuFont, s1, w2, h);
3027 key_x := (gScreenWidth-w1-w2) div 2;
3028 val_x := key_x + w1;
3030 // "Time: #:##:##":
3031 tm := SingleStat.GameTime div 1000;
3032 s1 := _lc[I_MENU_INTER_TIME];
3033 s2 := Format(' %d:%.2d:%.2d', [tm div (60*60), (tm mod (60*60)) div 60, tm mod 60]);
3035 e_CharFont_Print(gMenuFont, key_x, 80, s1);
3036 e_CharFont_PrintEx(gMenuFont, val_x, 80, s2, _RGB(255, 0, 0));
3038 if SingleStat.TwoPlayers then
3039 begin
3040 // "Player 1":
3041 s1 := _lc[I_MENU_PLAYER_1];
3042 e_CharFont_GetSize(gMenuFont, s1, w1, h);
3043 e_CharFont_Print(gMenuFont, (gScreenWidth-w1) div 2, 128, s1);
3045 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
3046 y := 176;
3047 player_stat(0);
3049 // "Player 2":
3050 s1 := _lc[I_MENU_PLAYER_2];
3051 e_CharFont_GetSize(gMenuFont, s1, w1, h);
3052 e_CharFont_Print(gMenuFont, (gScreenWidth-w1) div 2, 288, s1);
3054 // Ñòàòèñòèêà âòîðîãî èãðîêà:
3055 y := 336;
3056 player_stat(1);
3057 end
3058 else
3059 begin
3060 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
3061 y := 128;
3062 player_stat(0);
3063 end;
3064 end;
3066 procedure DrawLoadingStat();
3067 procedure drawRect (x, y, w, h: Integer);
3068 begin
3069 if (w < 1) or (h < 1) then exit;
3070 glBegin(GL_QUADS);
3071 glVertex2f(x+0.375, y+0.375);
3072 glVertex2f(x+w+0.375, y+0.375);
3073 glVertex2f(x+w+0.375, y+h+0.375);
3074 glVertex2f(x+0.375, y+h+0.375);
3075 glEnd();
3076 end;
3078 function drawPBar (cur, total: Integer; washere: Boolean): Boolean;
3079 var
3080 rectW, rectH: Integer;
3081 x0, y0: Integer;
3082 wdt: Integer;
3083 wl, hl: Integer;
3084 wr, hr: Integer;
3085 wb, hb: Integer;
3086 wm, hm: Integer;
3087 idl, idr, idb, idm: LongWord;
3088 f, my: Integer;
3089 begin
3090 result := false;
3091 if (total < 1) then exit;
3092 if (cur < 1) then exit; // don't blink
3093 if (not washere) and (cur >= total) then exit; // don't blink
3094 //if (cur < 0) then cur := 0;
3095 //if (cur > total) then cur := total;
3096 result := true;
3098 if (hasPBarGfx) then
3099 begin
3100 g_Texture_Get('UI_GFX_PBAR_LEFT', idl);
3101 g_Texture_GetSize('UI_GFX_PBAR_LEFT', wl, hl);
3102 g_Texture_Get('UI_GFX_PBAR_RIGHT', idr);
3103 g_Texture_GetSize('UI_GFX_PBAR_RIGHT', wr, hr);
3104 g_Texture_Get('UI_GFX_PBAR_MIDDLE', idb);
3105 g_Texture_GetSize('UI_GFX_PBAR_MIDDLE', wb, hb);
3106 g_Texture_Get('UI_GFX_PBAR_MARKER', idm);
3107 g_Texture_GetSize('UI_GFX_PBAR_MARKER', wm, hm);
3109 //rectW := gScreenWidth-360;
3110 rectW := trunc(624.0*gScreenWidth/1024.0);
3111 rectH := hl;
3113 x0 := (gScreenWidth-rectW) div 2;
3114 y0 := gScreenHeight-rectH-64;
3115 if (y0 < 2) then y0 := 2;
3117 glEnable(GL_SCISSOR_TEST);
3119 // left and right
3120 glScissor(x0, gScreenHeight-y0-rectH, rectW, rectH);
3121 e_DrawSize(idl, x0, y0, 0, true, false, wl, hl);
3122 e_DrawSize(idr, x0+rectW-wr, y0, 0, true, false, wr, hr);
3124 // body
3125 glScissor(x0+wl, gScreenHeight-y0-rectH, rectW-wl-wr, rectH);
3126 f := x0+wl;
3127 while (f < x0+rectW) do
3128 begin
3129 e_DrawSize(idb, f, y0, 0, true, false, wb, hb);
3130 f += wb;
3131 end;
3133 // filled part
3134 wdt := (rectW-wl-wr)*cur div total;
3135 if (wdt > rectW-wl-wr) then wdt := rectW-wr-wr;
3136 if (wdt > 0) then
3137 begin
3138 my := y0; // don't be so smart, ketmar: +(rectH-wm) div 2;
3139 glScissor(x0+wl, gScreenHeight-my-rectH, wdt, hm);
3140 f := x0+wl;
3141 while (wdt > 0) do
3142 begin
3143 e_DrawSize(idm, f, y0, 0, true, false, wm, hm);
3144 f += wm;
3145 wdt -= wm;
3146 end;
3147 end;
3149 glScissor(0, 0, gScreenWidth, gScreenHeight);
3150 end
3151 else
3152 begin
3153 rectW := gScreenWidth-64;
3154 rectH := 16;
3156 x0 := (gScreenWidth-rectW) div 2;
3157 y0 := gScreenHeight-rectH-64;
3158 if (y0 < 2) then y0 := 2;
3160 glDisable(GL_BLEND);
3161 glDisable(GL_TEXTURE_2D);
3163 //glClearColor(0, 0, 0, 0);
3164 //glClear(GL_COLOR_BUFFER_BIT);
3166 glColor4ub(127, 127, 127, 255);
3167 drawRect(x0-2, y0-2, rectW+4, rectH+4);
3169 glColor4ub(0, 0, 0, 255);
3170 drawRect(x0-1, y0-1, rectW+2, rectH+2);
3172 glColor4ub(127, 127, 127, 255);
3173 wdt := rectW*cur div total;
3174 if (wdt > rectW) then wdt := rectW;
3175 drawRect(x0, y0, wdt, rectH);
3176 end;
3177 end;
3179 var
3180 ww, hh: Word;
3181 xx, yy, i: Integer;
3182 s: String;
3183 begin
3184 if (Length(LoadingStat.Msgs) = 0) then exit;
3186 e_CharFont_GetSize(gMenuFont, _lc[I_MENU_LOADING], ww, hh);
3187 yy := (gScreenHeight div 3);
3188 e_CharFont_Print(gMenuFont, (gScreenWidth div 2)-(ww div 2), yy-2*hh, _lc[I_MENU_LOADING]);
3189 xx := (gScreenWidth div 3);
3191 with LoadingStat do
3192 begin
3193 for i := 0 to NextMsg-1 do
3194 begin
3195 if (i = (NextMsg-1)) and (MaxValue > 0) then
3196 s := Format('%s: %d/%d', [Msgs[i], CurValue, MaxValue])
3197 else
3198 s := Msgs[i];
3200 e_CharFont_PrintEx(gMenuSmallFont, xx, yy, s, _RGB(255, 0, 0));
3201 yy := yy + LOADING_INTERLINE;
3202 PBarWasHere := drawPBar(CurValue, MaxValue, PBarWasHere);
3203 end;
3204 end;
3205 end;
3207 procedure DrawMenuBackground(tex: AnsiString);
3208 var
3209 w, h: Word;
3210 ID: DWord;
3212 begin
3213 if g_Texture_Get(tex, ID) then
3214 begin
3215 e_Clear(GL_COLOR_BUFFER_BIT, 0, 0, 0);
3216 e_GetTextureSize(ID, @w, @h);
3217 if w = h then
3218 w := round(w * 1.333 * (gScreenHeight / h))
3219 else
3220 w := trunc(w * (gScreenHeight / h));
3221 e_DrawSize(ID, (gScreenWidth - w) div 2, 0, 0, False, False, w, gScreenHeight);
3222 end
3223 else e_Clear(GL_COLOR_BUFFER_BIT, 0, 0, 0);
3224 end;
3226 procedure DrawMinimap(p: TPlayer; RenderRect: e_graphics.TRect);
3227 var
3228 a, aX, aY, aX2, aY2, Scale, ScaleSz: Integer;
3230 function monDraw (mon: TMonster): Boolean;
3231 begin
3232 result := false; // don't stop
3233 with mon do
3234 begin
3235 if alive then
3236 begin
3237 // Ëåâûé âåðõíèé óãîë
3238 aX := Obj.X div ScaleSz + 1;
3239 aY := Obj.Y div ScaleSz + 1;
3240 // Ðàçìåðû
3241 aX2 := max(Obj.Rect.Width div ScaleSz, 1);
3242 aY2 := max(Obj.Rect.Height div ScaleSz, 1);
3243 // Ïðàâûé íèæíèé óãîë
3244 aX2 := aX + aX2 - 1;
3245 aY2 := aY + aY2 - 1;
3246 e_DrawFillQuad(aX, aY, aX2, aY2, 255, 255, 0, 0);
3247 end;
3248 end;
3249 end;
3251 begin
3252 if (gMapInfo.Width > RenderRect.Right - RenderRect.Left) or
3253 (gMapInfo.Height > RenderRect.Bottom - RenderRect.Top) then
3254 begin
3255 Scale := 1;
3256 // Ñêîëüêî ïèêñåëîâ êàðòû â 1 ïèêñåëå ìèíè-êàðòû:
3257 ScaleSz := 16 div Scale;
3258 // Ðàçìåðû ìèíè-êàðòû:
3259 aX := max(gMapInfo.Width div ScaleSz, 1);
3260 aY := max(gMapInfo.Height div ScaleSz, 1);
3261 // Ðàìêà êàðòû:
3262 e_DrawFillQuad(0, 0, aX-1, aY-1, 0, 0, 0, 0);
3264 if gWalls <> nil then
3265 begin
3266 // Ðèñóåì ñòåíû:
3267 for a := 0 to High(gWalls) do
3268 with gWalls[a] do
3269 if PanelType <> 0 then
3270 begin
3271 // Ëåâûé âåðõíèé óãîë:
3272 aX := X div ScaleSz;
3273 aY := Y div ScaleSz;
3274 // Ðàçìåðû:
3275 aX2 := max(Width div ScaleSz, 1);
3276 aY2 := max(Height div ScaleSz, 1);
3277 // Ïðàâûé íèæíèé óãîë:
3278 aX2 := aX + aX2 - 1;
3279 aY2 := aY + aY2 - 1;
3281 case PanelType of
3282 PANEL_WALL: e_DrawFillQuad(aX, aY, aX2, aY2, 208, 208, 208, 0);
3283 PANEL_OPENDOOR, PANEL_CLOSEDOOR:
3284 if Enabled then e_DrawFillQuad(aX, aY, aX2, aY2, 160, 160, 160, 0);
3285 end;
3286 end;
3287 end;
3288 if gSteps <> nil then
3289 begin
3290 // Ðèñóåì ñòóïåíè:
3291 for a := 0 to High(gSteps) do
3292 with gSteps[a] do
3293 if PanelType <> 0 then
3294 begin
3295 // Ëåâûé âåðõíèé óãîë:
3296 aX := X div ScaleSz;
3297 aY := Y div ScaleSz;
3298 // Ðàçìåðû:
3299 aX2 := max(Width div ScaleSz, 1);
3300 aY2 := max(Height div ScaleSz, 1);
3301 // Ïðàâûé íèæíèé óãîë:
3302 aX2 := aX + aX2 - 1;
3303 aY2 := aY + aY2 - 1;
3305 e_DrawFillQuad(aX, aY, aX2, aY2, 128, 128, 128, 0);
3306 end;
3307 end;
3308 if gLifts <> nil then
3309 begin
3310 // Ðèñóåì ëèôòû:
3311 for a := 0 to High(gLifts) do
3312 with gLifts[a] do
3313 if PanelType <> 0 then
3314 begin
3315 // Ëåâûé âåðõíèé óãîë:
3316 aX := X div ScaleSz;
3317 aY := Y div ScaleSz;
3318 // Ðàçìåðû:
3319 aX2 := max(Width div ScaleSz, 1);
3320 aY2 := max(Height div ScaleSz, 1);
3321 // Ïðàâûé íèæíèé óãîë:
3322 aX2 := aX + aX2 - 1;
3323 aY2 := aY + aY2 - 1;
3325 case LiftType of
3326 LIFTTYPE_UP: e_DrawFillQuad(aX, aY, aX2, aY2, 116, 72, 36, 0);
3327 LIFTTYPE_DOWN: e_DrawFillQuad(aX, aY, aX2, aY2, 116, 124, 96, 0);
3328 LIFTTYPE_LEFT: e_DrawFillQuad(aX, aY, aX2, aY2, 200, 80, 4, 0);
3329 LIFTTYPE_RIGHT: e_DrawFillQuad(aX, aY, aX2, aY2, 252, 140, 56, 0);
3330 end;
3331 end;
3332 end;
3333 if gWater <> nil then
3334 begin
3335 // Ðèñóåì âîäó:
3336 for a := 0 to High(gWater) do
3337 with gWater[a] do
3338 if PanelType <> 0 then
3339 begin
3340 // Ëåâûé âåðõíèé óãîë:
3341 aX := X div ScaleSz;
3342 aY := Y div ScaleSz;
3343 // Ðàçìåðû:
3344 aX2 := max(Width div ScaleSz, 1);
3345 aY2 := max(Height div ScaleSz, 1);
3346 // Ïðàâûé íèæíèé óãîë:
3347 aX2 := aX + aX2 - 1;
3348 aY2 := aY + aY2 - 1;
3350 e_DrawFillQuad(aX, aY, aX2, aY2, 0, 0, 192, 0);
3351 end;
3352 end;
3353 if gAcid1 <> nil then
3354 begin
3355 // Ðèñóåì êèñëîòó 1:
3356 for a := 0 to High(gAcid1) do
3357 with gAcid1[a] do
3358 if PanelType <> 0 then
3359 begin
3360 // Ëåâûé âåðõíèé óãîë:
3361 aX := X div ScaleSz;
3362 aY := Y div ScaleSz;
3363 // Ðàçìåðû:
3364 aX2 := max(Width div ScaleSz, 1);
3365 aY2 := max(Height div ScaleSz, 1);
3366 // Ïðàâûé íèæíèé óãîë:
3367 aX2 := aX + aX2 - 1;
3368 aY2 := aY + aY2 - 1;
3370 e_DrawFillQuad(aX, aY, aX2, aY2, 0, 176, 0, 0);
3371 end;
3372 end;
3373 if gAcid2 <> nil then
3374 begin
3375 // Ðèñóåì êèñëîòó 2:
3376 for a := 0 to High(gAcid2) do
3377 with gAcid2[a] do
3378 if PanelType <> 0 then
3379 begin
3380 // Ëåâûé âåðõíèé óãîë:
3381 aX := X div ScaleSz;
3382 aY := Y div ScaleSz;
3383 // Ðàçìåðû:
3384 aX2 := max(Width div ScaleSz, 1);
3385 aY2 := max(Height div ScaleSz, 1);
3386 // Ïðàâûé íèæíèé óãîë:
3387 aX2 := aX + aX2 - 1;
3388 aY2 := aY + aY2 - 1;
3390 e_DrawFillQuad(aX, aY, aX2, aY2, 176, 0, 0, 0);
3391 end;
3392 end;
3393 if gPlayers <> nil then
3394 begin
3395 // Ðèñóåì èãðîêîâ:
3396 for a := 0 to High(gPlayers) do
3397 if gPlayers[a] <> nil then with gPlayers[a] do
3398 if alive then begin
3399 // Ëåâûé âåðõíèé óãîë:
3400 aX := Obj.X div ScaleSz + 1;
3401 aY := Obj.Y div ScaleSz + 1;
3402 // Ðàçìåðû:
3403 aX2 := max(Obj.Rect.Width div ScaleSz, 1);
3404 aY2 := max(Obj.Rect.Height div ScaleSz, 1);
3405 // Ïðàâûé íèæíèé óãîë:
3406 aX2 := aX + aX2 - 1;
3407 aY2 := aY + aY2 - 1;
3409 if gPlayers[a] = p then
3410 e_DrawFillQuad(aX, aY, aX2, aY2, 0, 255, 0, 0)
3411 else
3412 case Team of
3413 TEAM_RED: e_DrawFillQuad(aX, aY, aX2, aY2, 255, 0, 0, 0);
3414 TEAM_BLUE: e_DrawFillQuad(aX, aY, aX2, aY2, 0, 0, 255, 0);
3415 else e_DrawFillQuad(aX, aY, aX2, aY2, 255, 128, 0, 0);
3416 end;
3417 end;
3418 end;
3419 // Ðèñóåì ìîíñòðîâ
3420 g_Mons_ForEach(monDraw);
3421 end;
3422 end;
3425 procedure renderAmbientQuad (hasAmbient: Boolean; constref ambColor: TDFColor);
3426 begin
3427 if not hasAmbient then exit;
3428 e_AmbientQuad(sX, sY, sWidth, sHeight, ambColor.r, ambColor.g, ambColor.b, ambColor.a);
3429 end;
3432 // setup sX, sY, sWidth, sHeight, and transformation matrix before calling this!
3433 //FIXME: broken for splitscreen mode
3434 procedure renderDynLightsInternal ();
3435 var
3436 //hasAmbient: Boolean;
3437 //ambColor: TDFColor;
3438 lln: Integer;
3439 lx, ly, lrad: Integer;
3440 scxywh: array[0..3] of GLint;
3441 wassc: Boolean;
3442 begin
3443 if e_NoGraphics then exit;
3445 //TODO: lights should be in separate grid, i think
3446 // but on the other side: grid may be slower for dynlights, as their lifetime is short
3447 if (not gwin_k8_enable_light_experiments) or (not gwin_has_stencil) or (g_dynLightCount < 1) then exit;
3449 // rendering mode
3450 //ambColor := gCurrentMap['light_ambient'].rgba;
3451 //hasAmbient := (not ambColor.isOpaque) or (not ambColor.isBlack);
3453 { // this will multiply incoming color to alpha from framebuffer
3454 glEnable(GL_BLEND);
3455 glBlendFunc(GL_DST_ALPHA, GL_ONE);
3458 (*
3459 * light rendering: (INVALID!)
3460 * glStencilFunc(GL_EQUAL, 0, $ff);
3461 * for each light:
3462 * glClear(GL_STENCIL_BUFFER_BIT);
3463 * glStencilOp(GL_KEEP, GL_KEEP, GL_INCR);
3464 * draw shadow volume into stencil buffer
3465 * glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); // modify color buffer
3466 * glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); // don't modify stencil buffer
3467 * turn off blending
3468 * draw color-less quad with light alpha (WARNING! don't touch color!)
3469 * glEnable(GL_BLEND);
3470 * glBlendFunc(GL_DST_ALPHA, GL_ONE);
3471 * draw all geometry up to and including walls (with alpha-testing, probably) -- this does lighting
3472 *)
3473 wassc := (glIsEnabled(GL_SCISSOR_TEST) <> 0);
3474 if wassc then glGetIntegerv(GL_SCISSOR_BOX, @scxywh[0]) else glGetIntegerv(GL_VIEWPORT, @scxywh[0]);
3476 // setup OpenGL parameters
3477 glStencilMask($FFFFFFFF);
3478 glStencilFunc(GL_ALWAYS, 0, $FFFFFFFF);
3479 glEnable(GL_STENCIL_TEST);
3480 glEnable(GL_SCISSOR_TEST);
3481 glClear(GL_STENCIL_BUFFER_BIT);
3482 glStencilFunc(GL_EQUAL, 0, $ff);
3484 for lln := 0 to g_dynLightCount-1 do
3485 begin
3486 lx := g_dynLights[lln].x;
3487 ly := g_dynLights[lln].y;
3488 lrad := g_dynLights[lln].radius;
3489 if (lrad < 3) then continue;
3491 if (lx-sX+lrad < 0) then continue;
3492 if (ly-sY+lrad < 0) then continue;
3493 if (lx-sX-lrad >= gPlayerScreenSize.X) then continue;
3494 if (ly-sY-lrad >= gPlayerScreenSize.Y) then continue;
3496 // set scissor to optimize drawing
3497 if (g_dbg_scale = 1.0) then
3498 begin
3499 glScissor((lx-sX)-lrad+2, gPlayerScreenSize.Y-(ly-sY)-lrad-1+2, lrad*2-4, lrad*2-4);
3500 end
3501 else
3502 begin
3503 glScissor(0, 0, gScreenWidth, gScreenHeight);
3504 end;
3505 // no need to clear stencil buffer, light blitting will do it for us... but only for normal scale
3506 if (g_dbg_scale <> 1.0) then glClear(GL_STENCIL_BUFFER_BIT);
3507 glStencilOp(GL_KEEP, GL_KEEP, GL_INCR);
3508 // draw extruded panels
3509 glDisable(GL_TEXTURE_2D);
3510 glDisable(GL_BLEND);
3511 glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); // no need to modify color buffer
3512 if (lrad > 4) then g_Map_DrawPanelShadowVolumes(lx, ly, lrad);
3513 // render light texture
3514 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); // modify color buffer
3515 glStencilOp(GL_ZERO, GL_ZERO, GL_ZERO); // draw light, and clear stencil buffer
3516 // blend it
3517 glEnable(GL_BLEND);
3518 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
3519 glEnable(GL_TEXTURE_2D);
3520 // color and opacity
3521 glColor4f(g_dynLights[lln].r, g_dynLights[lln].g, g_dynLights[lln].b, g_dynLights[lln].a);
3522 glBindTexture(GL_TEXTURE_2D, g_Texture_Light());
3523 glBegin(GL_QUADS);
3524 glTexCoord2f(0.0, 0.0); glVertex2i(lx-lrad, ly-lrad); // top-left
3525 glTexCoord2f(1.0, 0.0); glVertex2i(lx+lrad, ly-lrad); // top-right
3526 glTexCoord2f(1.0, 1.0); glVertex2i(lx+lrad, ly+lrad); // bottom-right
3527 glTexCoord2f(0.0, 1.0); glVertex2i(lx-lrad, ly+lrad); // bottom-left
3528 glEnd();
3529 end;
3531 // done
3532 glDisable(GL_STENCIL_TEST);
3533 glDisable(GL_BLEND);
3534 glDisable(GL_SCISSOR_TEST);
3535 //glScissor(0, 0, sWidth, sHeight);
3537 glScissor(scxywh[0], scxywh[1], scxywh[2], scxywh[3]);
3538 if wassc then glEnable(GL_SCISSOR_TEST) else glDisable(GL_SCISSOR_TEST);
3539 end;
3542 function fixViewportForScale (): Boolean;
3543 var
3544 nx0, ny0, nw, nh: Integer;
3545 begin
3546 result := false;
3547 if (g_dbg_scale <> 1.0) then
3548 begin
3549 result := true;
3550 nx0 := round(sX-(gPlayerScreenSize.X-(sWidth*g_dbg_scale))/2/g_dbg_scale);
3551 ny0 := round(sY-(gPlayerScreenSize.Y-(sHeight*g_dbg_scale))/2/g_dbg_scale);
3552 nw := round(sWidth/g_dbg_scale);
3553 nh := round(sHeight/g_dbg_scale);
3554 sX := nx0;
3555 sY := ny0;
3556 sWidth := nw;
3557 sHeight := nh;
3558 end;
3559 end;
3562 // setup sX, sY, sWidth, sHeight, and transformation matrix before calling this!
3563 // WARNING! this WILL CALL `glTranslatef()`, but won't restore matrices!
3564 procedure renderMapInternal (backXOfs, backYOfs: Integer; setTransMatrix: Boolean);
3565 type
3566 TDrawCB = procedure ();
3568 var
3569 hasAmbient: Boolean;
3570 ambColor: TDFColor;
3571 doAmbient: Boolean = false;
3573 procedure drawPanelType (profname: AnsiString; panType: DWord; doDraw: Boolean);
3574 var
3575 tagmask: Integer;
3576 pan: TPanel;
3577 begin
3578 if (profileFrameDraw <> nil) then profileFrameDraw.sectionBegin(profname);
3579 if gdbg_map_use_accel_render then
3580 begin
3581 tagmask := panelTypeToTag(panType);
3582 while (gDrawPanelList.count > 0) do
3583 begin
3584 pan := TPanel(gDrawPanelList.front());
3585 if ((pan.tag and tagmask) = 0) then break;
3586 if doDraw then pan.Draw(doAmbient, ambColor);
3587 gDrawPanelList.popFront();
3588 end;
3589 end
3590 else
3591 begin
3592 if doDraw then g_Map_DrawPanels(panType, hasAmbient, ambColor);
3593 end;
3594 if (profileFrameDraw <> nil) then profileFrameDraw.sectionEnd();
3595 end;
3597 procedure drawOther (profname: AnsiString; cb: TDrawCB);
3598 begin
3599 if (profileFrameDraw <> nil) then profileFrameDraw.sectionBegin(profname);
3600 if assigned(cb) then cb();
3601 if (profileFrameDraw <> nil) then profileFrameDraw.sectionEnd();
3602 end;
3604 begin
3605 if (profileFrameDraw <> nil) then profileFrameDraw.sectionBegin('total');
3607 // our accelerated renderer will collect all panels to gDrawPanelList
3608 // we can use panel tag to render level parts (see GridTagXXX in g_map.pas)
3609 if (profileFrameDraw <> nil) then profileFrameDraw.sectionBegin('collect');
3610 if gdbg_map_use_accel_render then
3611 begin
3612 g_Map_CollectDrawPanels(sX, sY, sWidth, sHeight);
3613 end;
3614 if (profileFrameDraw <> nil) then profileFrameDraw.sectionEnd();
3616 if (profileFrameDraw <> nil) then profileFrameDraw.sectionBegin('skyback');
3617 g_Map_DrawBack(backXOfs, backYOfs);
3618 if (profileFrameDraw <> nil) then profileFrameDraw.sectionEnd();
3620 if setTransMatrix then
3621 begin
3622 //if (g_dbg_scale <> 1.0) then glTranslatef(0.0, -0.375/2, 0);
3623 glScalef(g_dbg_scale, g_dbg_scale, 1.0);
3624 glTranslatef(-sX, -sY, 0);
3625 end;
3627 // rendering mode
3628 ambColor := gCurrentMap['light_ambient'].rgba;
3629 hasAmbient := (not ambColor.isOpaque) or (not ambColor.isBlack);
3632 if hasAmbient then
3633 begin
3634 //writeln('color: (', ambColor.r, ',', ambColor.g, ',', ambColor.b, ',', ambColor.a, ')');
3635 glColor4ub(ambColor.r, ambColor.g, ambColor.b, ambColor.a);
3636 glClear(GL_COLOR_BUFFER_BIT);
3637 end;
3639 //writeln('color: (', ambColor.r, ',', ambColor.g, ',', ambColor.b, ',', ambColor.a, ')');
3642 drawPanelType('*back', PANEL_BACK, g_rlayer_back);
3643 drawPanelType('*step', PANEL_STEP, g_rlayer_step);
3644 drawOther('items', @g_Items_Draw);
3645 drawOther('weapons', @g_Weapon_Draw);
3646 drawOther('shells', @g_Player_DrawShells);
3647 drawOther('drawall', @g_Player_DrawAll);
3648 drawOther('corpses', @g_Player_DrawCorpses);
3649 drawPanelType('*wall', PANEL_WALL, g_rlayer_wall);
3650 drawOther('monsters', @g_Monsters_Draw);
3651 drawOther('itemdrop', @g_Items_DrawDrop);
3652 drawPanelType('*door', PANEL_CLOSEDOOR, g_rlayer_door);
3653 drawOther('gfx', @g_GFX_Draw);
3654 drawOther('flags', @g_Map_DrawFlags);
3655 drawPanelType('*acid1', PANEL_ACID1, g_rlayer_acid1);
3656 drawPanelType('*acid2', PANEL_ACID2, g_rlayer_acid2);
3657 drawPanelType('*water', PANEL_WATER, g_rlayer_water);
3658 drawOther('dynlights', @renderDynLightsInternal);
3660 if hasAmbient {and ((not g_playerLight) or (not gwin_has_stencil) or (g_dynLightCount < 1))} then
3661 begin
3662 renderAmbientQuad(hasAmbient, ambColor);
3663 end;
3665 doAmbient := true;
3666 drawPanelType('*fore', PANEL_FORE, g_rlayer_fore);
3669 if g_debug_HealthBar then
3670 begin
3671 g_Monsters_DrawHealth();
3672 g_Player_DrawHealth();
3673 end;
3675 if (profileFrameDraw <> nil) then profileFrameDraw.mainEnd(); // map rendering
3676 end;
3679 procedure DrawMapView(x, y, w, h: Integer);
3681 var
3682 bx, by: Integer;
3683 begin
3684 glPushMatrix();
3686 bx := Round(x/(gMapInfo.Width - w)*(gBackSize.X - w));
3687 by := Round(y/(gMapInfo.Height - h)*(gBackSize.Y - h));
3689 sX := x;
3690 sY := y;
3691 sWidth := w;
3692 sHeight := h;
3694 fixViewportForScale();
3695 renderMapInternal(-bx, -by, true);
3697 glPopMatrix();
3698 end;
3701 procedure DrawPlayer(p: TPlayer);
3702 var
3703 px, py, a, b, c, d, i, fX, fY: Integer;
3704 camObj: TObj;
3705 //R: TRect;
3706 begin
3707 if (p = nil) or (p.FDummy) then
3708 begin
3709 glPushMatrix();
3710 g_Map_DrawBack(0, 0);
3711 glPopMatrix();
3712 Exit;
3713 end;
3715 if (profileFrameDraw = nil) then profileFrameDraw := TProfiler.Create('RENDER', g_profile_history_size);
3716 if (profileFrameDraw <> nil) then profileFrameDraw.mainBegin(g_profile_frame_draw);
3718 gPlayerDrawn := p;
3720 glPushMatrix();
3722 camObj := p.getCameraObj();
3723 camObj.lerp(gLerpFactor, fX, fY);
3724 px := fX + PLAYER_RECT_CX;
3725 py := fY + PLAYER_RECT_CY+nlerp(p.SlopeOld, camObj.slopeUpLeft, gLerpFactor);
3727 if (g_dbg_scale = 1.0) and (not g_dbg_ignore_bounds) then
3728 begin
3729 if (px > (gPlayerScreenSize.X div 2)) then a := -px+(gPlayerScreenSize.X div 2) else a := 0;
3730 if (py > (gPlayerScreenSize.Y div 2)) then b := -py+(gPlayerScreenSize.Y div 2) else b := 0;
3732 if (px > gMapInfo.Width-(gPlayerScreenSize.X div 2)) then a := -gMapInfo.Width+gPlayerScreenSize.X;
3733 if (py > gMapInfo.Height-(gPlayerScreenSize.Y div 2)) then b := -gMapInfo.Height+gPlayerScreenSize.Y;
3735 if (gMapInfo.Width = gPlayerScreenSize.X) then a := 0
3736 else if (gMapInfo.Width < gPlayerScreenSize.X) then
3737 begin
3738 // hcenter
3739 a := (gPlayerScreenSize.X-gMapInfo.Width) div 2;
3740 end;
3742 if (gMapInfo.Height = gPlayerScreenSize.Y) then b := 0
3743 else if (gMapInfo.Height < gPlayerScreenSize.Y) then
3744 begin
3745 // vcenter
3746 b := (gPlayerScreenSize.Y-gMapInfo.Height) div 2;
3747 end;
3748 end
3749 else
3750 begin
3751 // scaled, ignore level bounds
3752 a := -px+(gPlayerScreenSize.X div 2);
3753 b := -py+(gPlayerScreenSize.Y div 2);
3754 end;
3756 sX := -a;
3757 sY := -b;
3758 sWidth := gPlayerScreenSize.X;
3759 sHeight := gPlayerScreenSize.Y;
3760 fixViewportForScale();
3762 i := py - (sY + sHeight div 2);
3763 if (p.IncCam > 0) then
3764 begin
3765 // clamp to level bounds
3766 if (sY - p.IncCam < 0) then
3767 p.IncCam := nclamp(sY, 0, 120);
3768 // clamp around player position
3769 if (i > 0) then
3770 p.IncCam := nclamp(p.IncCam, 0, max(0, 120 - i));
3771 end
3772 else if (p.IncCam < 0) then
3773 begin
3774 // clamp to level bounds
3775 if (sY + sHeight - p.IncCam > gMapInfo.Height) then
3776 p.IncCam := nclamp(sY + sHeight - gMapInfo.Height, -120, 0);
3777 // clamp around player position
3778 if (i < 0) then
3779 p.IncCam := nclamp(p.IncCam, min(0, -120 - i), 0);
3780 end;
3782 sY := sY - nlerp(p.IncCamOld, p.IncCam, gLerpFactor);
3784 if (not g_dbg_ignore_bounds) then
3785 begin
3786 if (sX+sWidth > gMapInfo.Width) then sX := gMapInfo.Width-sWidth;
3787 if (sY+sHeight > gMapInfo.Height) then sY := gMapInfo.Height-sHeight;
3788 if (sX < 0) then sX := 0;
3789 if (sY < 0) then sY := 0;
3790 end;
3792 if (gBackSize.X <= gPlayerScreenSize.X) or (gMapInfo.Width <= sWidth) then c := 0 else c := trunc((gBackSize.X-gPlayerScreenSize.X)*sX/(gMapInfo.Width-sWidth));
3793 if (gBackSize.Y <= gPlayerScreenSize.Y) or (gMapInfo.Height <= sHeight) then d := 0 else d := trunc((gBackSize.Y-gPlayerScreenSize.Y)*sY/(gMapInfo.Height-sHeight));
3795 //r_smallmap_h: 0: left; 1: center; 2: right
3796 //r_smallmap_v: 0: top; 1: center; 2: bottom
3797 // horiz small map?
3798 if (gMapInfo.Width = sWidth) then
3799 begin
3800 sX := 0;
3801 end
3802 else if (gMapInfo.Width < sWidth) then
3803 begin
3804 case r_smallmap_h of
3805 1: sX := -((sWidth-gMapInfo.Width) div 2); // center
3806 2: sX := -(sWidth-gMapInfo.Width); // right
3807 else sX := 0; // left
3808 end;
3809 end;
3810 // vert small map?
3811 if (gMapInfo.Height = sHeight) then
3812 begin
3813 sY := 0;
3814 end
3815 else if (gMapInfo.Height < sHeight) then
3816 begin
3817 case r_smallmap_v of
3818 1: sY := -((sHeight-gMapInfo.Height) div 2); // center
3819 2: sY := -(sHeight-gMapInfo.Height); // bottom
3820 else sY := 0; // top
3821 end;
3822 end;
3824 p.viewPortX := sX;
3825 p.viewPortY := sY;
3826 p.viewPortW := sWidth;
3827 p.viewPortH := sHeight;
3829 {$IFDEF ENABLE_HOLMES}
3830 if (p = gPlayer1) then
3831 begin
3832 g_Holmes_plrViewPos(sX, sY);
3833 g_Holmes_plrViewSize(sWidth, sHeight);
3834 end;
3835 {$ENDIF}
3837 renderMapInternal(-c, -d, true);
3839 if (gGameSettings.GameMode <> GM_SINGLE) and (gPlayerIndicator > 0) then
3840 case gPlayerIndicator of
3841 1:
3842 p.DrawIndicator(_RGB(255, 255, 255));
3844 2:
3845 for i := 0 to High(gPlayers) do
3846 if gPlayers[i] <> nil then
3847 if gPlayers[i] = p then p.DrawIndicator(_RGB(255, 255, 255))
3848 else if (gPlayers[i].Team = p.Team) and (gPlayers[i].Team <> TEAM_NONE) then
3849 if gPlayerIndicatorStyle = 1 then
3850 gPlayers[i].DrawIndicator(_RGB(192, 192, 192))
3851 else gPlayers[i].DrawIndicator(gPlayers[i].GetColor);
3852 end;
3855 for a := 0 to High(gCollideMap) do
3856 for b := 0 to High(gCollideMap[a]) do
3857 begin
3858 d := 0;
3859 if ByteBool(gCollideMap[a, b] and MARK_WALL) then
3860 d := d + 1;
3861 if ByteBool(gCollideMap[a, b] and MARK_DOOR) then
3862 d := d + 2;
3864 case d of
3865 1: e_DrawPoint(1, b, a, 200, 200, 200);
3866 2: e_DrawPoint(1, b, a, 64, 64, 255);
3867 3: e_DrawPoint(1, b, a, 255, 0, 255);
3868 end;
3869 end;
3872 glPopMatrix();
3874 p.DrawPain();
3875 p.DrawPickup();
3876 p.DrawOverlay();
3877 if gShowMap then DrawMinimap(p, _TRect(0, 0, 128, 128));
3878 if g_Debug_Player then
3879 g_Player_DrawDebug(p);
3880 p.DrawGUI();
3881 end;
3883 procedure drawProfilers ();
3884 var
3885 px: Integer = -1;
3886 py: Integer = -1;
3887 begin
3888 if g_profile_frame_draw and (profileFrameDraw <> nil) then
3889 px -= drawProfiles(px, py, profileFrameDraw);
3891 if g_profile_collision and (profMapCollision <> nil) then
3892 begin
3893 px -= drawProfiles(px, py, profMapCollision);
3894 py -= calcProfilesHeight(profMonsLOS);
3895 end;
3897 if g_profile_los and (profMonsLOS <> nil) then
3898 begin
3899 px -= drawProfiles(px, py, profMonsLOS);
3900 py -= calcProfilesHeight(profMonsLOS);
3901 end;
3902 end;
3904 procedure g_Game_Draw();
3905 var
3906 ID: DWORD;
3907 w, h: Word;
3908 ww, hh: Byte;
3909 Time: Int64;
3910 back: string;
3911 plView1, plView2: TPlayer;
3912 Split: Boolean;
3913 begin
3914 if gExit = EXIT_QUIT then Exit;
3916 Time := sys_GetTicks() {div 1000};
3917 FPSCounter := FPSCounter+1;
3918 if Time - FPSTime >= 1000 then
3919 begin
3920 FPS := FPSCounter;
3921 FPSCounter := 0;
3922 FPSTime := Time;
3923 end;
3925 e_SetRendertarget(True);
3926 e_SetViewPort(0, 0, gScreenWidth, gScreenHeight);
3928 if gGameOn or (gState = STATE_FOLD) then
3929 begin
3930 if (gPlayer1 <> nil) and (gPlayer2 <> nil) then
3931 begin
3932 gSpectMode := SPECT_NONE;
3933 if not gRevertPlayers then
3934 begin
3935 plView1 := gPlayer1;
3936 plView2 := gPlayer2;
3937 end
3938 else
3939 begin
3940 plView1 := gPlayer2;
3941 plView2 := gPlayer1;
3942 end;
3943 end
3944 else
3945 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
3946 begin
3947 gSpectMode := SPECT_NONE;
3948 if gPlayer2 = nil then
3949 plView1 := gPlayer1
3950 else
3951 plView1 := gPlayer2;
3952 plView2 := nil;
3953 end
3954 else
3955 begin
3956 plView1 := nil;
3957 plView2 := nil;
3958 end;
3960 if (plView1 = nil) and (plView2 = nil) and (gSpectMode = SPECT_NONE) then
3961 gSpectMode := SPECT_STATS;
3963 if gSpectMode = SPECT_PLAYERS then
3964 if gPlayers <> nil then
3965 begin
3966 plView1 := GetActivePlayer_ByID(gSpectPID1);
3967 if plView1 = nil then
3968 begin
3969 gSpectPID1 := GetActivePlayerID_Next();
3970 plView1 := GetActivePlayer_ByID(gSpectPID1);
3971 end;
3972 if gSpectViewTwo then
3973 begin
3974 plView2 := GetActivePlayer_ByID(gSpectPID2);
3975 if plView2 = nil then
3976 begin
3977 gSpectPID2 := GetActivePlayerID_Next();
3978 plView2 := GetActivePlayer_ByID(gSpectPID2);
3979 end;
3980 end;
3981 end;
3983 if gSpectMode = SPECT_MAPVIEW then
3984 begin
3985 // Ðåæèì ïðîñìîòðà êàðòû
3986 Split := False;
3987 e_SetViewPort(0, 0, gScreenWidth, gScreenHeight);
3988 DrawMapView(gSpectX, gSpectY, gScreenWidth, gScreenHeight);
3989 gHearPoint1.Active := True;
3990 gHearPoint1.Coords.X := gScreenWidth div 2 + gSpectX;
3991 gHearPoint1.Coords.Y := gScreenHeight div 2 + gSpectY;
3992 gHearPoint2.Active := False;
3993 end
3994 else
3995 begin
3996 Split := (plView1 <> nil) and (plView2 <> nil);
3998 // Òî÷êè ñëóõà èãðîêîâ
3999 if plView1 <> nil then
4000 begin
4001 gHearPoint1.Active := True;
4002 gHearPoint1.Coords.X := plView1.GameX + PLAYER_RECT.Width;
4003 gHearPoint1.Coords.Y := plView1.GameY + PLAYER_RECT.Height DIV 2;
4004 end else
4005 gHearPoint1.Active := False;
4006 if plView2 <> nil then
4007 begin
4008 gHearPoint2.Active := True;
4009 gHearPoint2.Coords.X := plView2.GameX + PLAYER_RECT.Width;
4010 gHearPoint2.Coords.Y := plView2.GameY + PLAYER_RECT.Height DIV 2;
4011 end else
4012 gHearPoint2.Active := False;
4014 // Ðàçìåð ýêðàíîâ èãðîêîâ:
4015 gPlayerScreenSize.X := gScreenWidth-196;
4016 if Split then
4017 begin
4018 gPlayerScreenSize.Y := gScreenHeight div 2;
4019 if gScreenHeight mod 2 = 0 then
4020 Dec(gPlayerScreenSize.Y);
4021 end
4022 else
4023 gPlayerScreenSize.Y := gScreenHeight;
4025 if Split then
4026 if gScreenHeight mod 2 = 0 then
4027 e_SetViewPort(0, gPlayerScreenSize.Y+2, gPlayerScreenSize.X+196, gPlayerScreenSize.Y)
4028 else
4029 e_SetViewPort(0, gPlayerScreenSize.Y+1, gPlayerScreenSize.X+196, gPlayerScreenSize.Y);
4031 DrawPlayer(plView1);
4032 gPlayer1ScreenCoord.X := sX;
4033 gPlayer1ScreenCoord.Y := sY;
4035 if Split then
4036 begin
4037 e_SetViewPort(0, 0, gPlayerScreenSize.X+196, gPlayerScreenSize.Y);
4039 DrawPlayer(plView2);
4040 gPlayer2ScreenCoord.X := sX;
4041 gPlayer2ScreenCoord.Y := sY;
4042 end;
4044 e_SetViewPort(0, 0, gScreenWidth, gScreenHeight);
4046 if Split then
4047 e_DrawLine(2, 0, gScreenHeight div 2, gScreenWidth, gScreenHeight div 2, 0, 0, 0);
4048 end;
4050 {$IFDEF ENABLE_HOLMES}
4051 // draw inspector
4052 if (g_holmes_enabled) then g_Holmes_Draw();
4053 {$ENDIF}
4055 if MessageText <> '' then
4056 begin
4057 w := 0;
4058 h := 0;
4059 e_CharFont_GetSizeFmt(gMenuFont, MessageText, w, h);
4060 if Split then
4061 e_CharFont_PrintFmt(gMenuFont, (gScreenWidth div 2)-(w div 2),
4062 (gScreenHeight div 2)-(h div 2), MessageText)
4063 else
4064 e_CharFont_PrintFmt(gMenuFont, (gScreenWidth div 2)-(w div 2),
4065 Round(gScreenHeight / 2.75)-(h div 2), MessageText);
4066 end;
4068 if IsDrawStat or (gSpectMode = SPECT_STATS) then
4069 DrawStat();
4071 if gSpectHUD and (not gChatShow) and (gSpectMode <> SPECT_NONE) and (not gSpectAuto) then
4072 begin
4073 // Draw spectator GUI
4074 ww := 0;
4075 hh := 0;
4076 e_TextureFontGetSize(gStdFont, ww, hh);
4077 case gSpectMode of
4078 SPECT_STATS:
4079 e_TextureFontPrintEx(0, gScreenHeight - (hh+2)*2, 'MODE: Stats', gStdFont, 255, 255, 255, 1);
4080 SPECT_MAPVIEW:
4081 e_TextureFontPrintEx(0, gScreenHeight - (hh+2)*2, 'MODE: Observe Map', gStdFont, 255, 255, 255, 1);
4082 SPECT_PLAYERS:
4083 e_TextureFontPrintEx(0, gScreenHeight - (hh+2)*2, 'MODE: Watch Players', gStdFont, 255, 255, 255, 1);
4084 end;
4085 e_TextureFontPrintEx(2*ww, gScreenHeight - (hh+2), '< jump >', gStdFont, 255, 255, 255, 1);
4086 if gSpectMode = SPECT_STATS then
4087 begin
4088 e_TextureFontPrintEx(16*ww, gScreenHeight - (hh+2)*2, 'Autoview', gStdFont, 255, 255, 255, 1);
4089 e_TextureFontPrintEx(16*ww, gScreenHeight - (hh+2), '< fire >', gStdFont, 255, 255, 255, 1);
4090 end;
4091 if gSpectMode = SPECT_MAPVIEW then
4092 begin
4093 e_TextureFontPrintEx(22*ww, gScreenHeight - (hh+2)*2, '[-]', gStdFont, 255, 255, 255, 1);
4094 e_TextureFontPrintEx(26*ww, gScreenHeight - (hh+2)*2, 'Step ' + IntToStr(gSpectStep), gStdFont, 255, 255, 255, 1);
4095 e_TextureFontPrintEx(34*ww, gScreenHeight - (hh+2)*2, '[+]', gStdFont, 255, 255, 255, 1);
4096 e_TextureFontPrintEx(18*ww, gScreenHeight - (hh+2), '<prev weap>', gStdFont, 255, 255, 255, 1);
4097 e_TextureFontPrintEx(30*ww, gScreenHeight - (hh+2), '<next weap>', gStdFont, 255, 255, 255, 1);
4098 end;
4099 if gSpectMode = SPECT_PLAYERS then
4100 begin
4101 e_TextureFontPrintEx(22*ww, gScreenHeight - (hh+2)*2, 'Player 1', gStdFont, 255, 255, 255, 1);
4102 e_TextureFontPrintEx(20*ww, gScreenHeight - (hh+2), '<left/right>', gStdFont, 255, 255, 255, 1);
4103 if gSpectViewTwo then
4104 begin
4105 e_TextureFontPrintEx(37*ww, gScreenHeight - (hh+2)*2, 'Player 2', gStdFont, 255, 255, 255, 1);
4106 e_TextureFontPrintEx(34*ww, gScreenHeight - (hh+2), '<prev w/next w>', gStdFont, 255, 255, 255, 1);
4107 e_TextureFontPrintEx(52*ww, gScreenHeight - (hh+2)*2, '2x View', gStdFont, 255, 255, 255, 1);
4108 e_TextureFontPrintEx(51*ww, gScreenHeight - (hh+2), '<up/down>', gStdFont, 255, 255, 255, 1);
4109 end
4110 else
4111 begin
4112 e_TextureFontPrintEx(35*ww, gScreenHeight - (hh+2)*2, '2x View', gStdFont, 255, 255, 255, 1);
4113 e_TextureFontPrintEx(34*ww, gScreenHeight - (hh+2), '<up/down>', gStdFont, 255, 255, 255, 1);
4114 end;
4115 end;
4116 end;
4117 end;
4119 if gPauseMain and gGameOn and (g_ActiveWindow = nil) then
4120 begin
4121 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4122 e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
4124 e_CharFont_GetSize(gMenuFont, _lc[I_MENU_PAUSE], w, h);
4125 e_CharFont_Print(gMenuFont, (gScreenWidth div 2)-(w div 2),
4126 (gScreenHeight div 2)-(h div 2), _lc[I_MENU_PAUSE]);
4127 end;
4129 if not gGameOn then
4130 begin
4131 if (gState = STATE_MENU) then
4132 begin
4133 if (g_ActiveWindow = nil) or (g_ActiveWindow.BackTexture = '') then DrawMenuBackground('MENU_BACKGROUND');
4134 // F3 at menu will show game loading dialog
4135 if e_KeyPressed(IK_F3) then g_Menu_Show_LoadMenu(true);
4136 if (g_ActiveWindow <> nil) then
4137 begin
4138 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4139 e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
4140 end
4141 else
4142 begin
4143 // F3 at titlepic will show game loading dialog
4144 if e_KeyPressed(IK_F3) then
4145 begin
4146 g_Menu_Show_LoadMenu(true);
4147 if (g_ActiveWindow <> nil) then e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
4148 end;
4149 end;
4150 end;
4152 if gState = STATE_FOLD then
4153 begin
4154 e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 0, 0, 0, EndingGameCounter);
4155 end;
4157 if gState = STATE_INTERCUSTOM then
4158 begin
4159 if gLastMap and (gGameSettings.GameMode = GM_COOP) then
4160 begin
4161 back := 'TEXTURE_endpic';
4162 if not g_Texture_Get(back, ID) then
4163 back := _lc[I_TEXTURE_ENDPIC];
4164 end
4165 else
4166 back := 'INTER';
4168 DrawMenuBackground(back);
4170 DrawCustomStat();
4172 if g_ActiveWindow <> nil then
4173 begin
4174 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4175 e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
4176 end;
4177 end;
4179 if gState = STATE_INTERSINGLE then
4180 begin
4181 if EndingGameCounter > 0 then
4182 begin
4183 e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 0, 0, 0, EndingGameCounter);
4184 end
4185 else
4186 begin
4187 back := 'INTER';
4189 DrawMenuBackground(back);
4191 DrawSingleStat();
4193 if g_ActiveWindow <> nil then
4194 begin
4195 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4196 e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
4197 end;
4198 end;
4199 end;
4201 if gState = STATE_ENDPIC then
4202 begin
4203 ID := DWORD(-1);
4204 if g_Texture_Get('TEXTURE_endpic', ID) then DrawMenuBackground('TEXTURE_endpic')
4205 else DrawMenuBackground(_lc[I_TEXTURE_ENDPIC]);
4207 if g_ActiveWindow <> nil then
4208 begin
4209 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4210 e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
4211 end;
4212 end;
4214 if gState = STATE_SLIST then
4215 begin
4216 // if g_Texture_Get('MENU_BACKGROUND', ID) then
4217 // begin
4218 // e_DrawSize(ID, 0, 0, 0, False, False, gScreenWidth, gScreenHeight);
4219 // //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4220 // end;
4221 DrawMenuBackground('MENU_BACKGROUND');
4222 e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
4223 g_Serverlist_Draw(slCurrent, slTable);
4224 end;
4225 end;
4227 if g_ActiveWindow <> nil then
4228 begin
4229 if gGameOn then
4230 begin
4231 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4232 e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
4233 end;
4234 g_ActiveWindow.Draw();
4235 end;
4237 {$IFNDEF HEADLESS}
4238 g_Console_Draw();
4239 {$ENDIF}
4241 if g_debug_Sounds and gGameOn then
4242 begin
4243 for w := 0 to High(e_SoundsArray) do
4244 for h := 0 to e_SoundsArray[w].nRefs do
4245 e_DrawPoint(1, w+100, h+100, 255, 0, 0);
4246 end;
4248 if gShowFPS then
4249 begin
4250 e_TextureFontPrint(0, 0, Format('FPS: %d', [FPS]), gStdFont);
4251 e_TextureFontPrint(0, 16, Format('UPS: %d', [UPS]), gStdFont);
4252 end;
4254 if gGameOn and gShowTime then
4255 drawTime(gScreenWidth-72, gScreenHeight-16);
4257 if gGameOn then drawProfilers();
4259 // TODO: draw this after the FBO and remap mouse click coordinates
4261 {$IFDEF ENABLE_HOLMES}
4262 g_Holmes_DrawUI();
4263 {$ENDIF}
4265 // blit framebuffer to screen
4267 e_SetRendertarget(False);
4268 e_SetViewPort(0, 0, gWinSizeX, gWinSizeY);
4269 e_BlitFramebuffer(gWinSizeX, gWinSizeY);
4271 // draw the overlay stuff on top of it
4273 g_Touch_Draw;
4274 end;
4276 procedure g_Game_Quit();
4277 begin
4278 g_Game_StopAllSounds(True);
4279 gMusic.Free();
4280 g_Game_FreeData();
4281 g_PlayerModel_FreeData();
4282 g_Texture_DeleteAll();
4283 g_Frames_DeleteAll();
4284 {$IFNDEF HEADLESS}
4285 //g_Menu_Free(); //k8: this segfaults after resolution change; who cares?
4286 {$ENDIF}
4288 if NetInitDone then g_Net_Free;
4290 // Íàäî óäàëèòü êàðòó ïîñëå òåñòà:
4291 if gMapToDelete <> '' then
4292 g_Game_DeleteTestMap();
4294 gExit := EXIT_QUIT;
4295 sys_RequestQuit;
4296 end;
4298 procedure g_FatalError(Text: String);
4299 begin
4300 g_Console_Add(Format(_lc[I_FATAL_ERROR], [Text]), True);
4301 e_WriteLog(Format(_lc[I_FATAL_ERROR], [Text]), TMsgType.Warning);
4303 gExit := EXIT_SIMPLE;
4304 if gGameOn then EndGame;
4305 end;
4307 procedure g_SimpleError(Text: String);
4308 begin
4309 g_Console_Add(Format(_lc[I_SIMPLE_ERROR], [Text]), True);
4310 e_WriteLog(Format(_lc[I_SIMPLE_ERROR], [Text]), TMsgType.Warning);
4311 end;
4313 procedure g_Game_SetupScreenSize();
4314 const
4315 RES_FACTOR = 4.0 / 3.0;
4316 var
4317 s: Single;
4318 rf: Single;
4319 bw, bh: Word;
4320 begin
4321 // Ðàçìåð ýêðàíîâ èãðîêîâ:
4322 gPlayerScreenSize.X := gScreenWidth-196;
4323 if (gPlayer1 <> nil) and (gPlayer2 <> nil) then
4324 gPlayerScreenSize.Y := gScreenHeight div 2
4325 else
4326 gPlayerScreenSize.Y := gScreenHeight;
4328 // Ðàçìåð çàäíåãî ïëàíà:
4329 if BackID <> DWORD(-1) then
4330 begin
4331 s := SKY_STRETCH;
4332 if (gScreenWidth*s > gMapInfo.Width) or
4333 (gScreenHeight*s > gMapInfo.Height) then
4334 begin
4335 gBackSize.X := gScreenWidth;
4336 gBackSize.Y := gScreenHeight;
4337 end
4338 else
4339 begin
4340 e_GetTextureSize(BackID, @bw, @bh);
4341 rf := Single(bw) / Single(bh);
4342 if (rf > RES_FACTOR) then bw := Round(Single(bh) * RES_FACTOR)
4343 else if (rf < RES_FACTOR) then bh := Round(Single(bw) / RES_FACTOR);
4344 s := Max(gScreenWidth / bw, gScreenHeight / bh);
4345 if (s < 1.0) then s := 1.0;
4346 gBackSize.X := Round(bw*s);
4347 gBackSize.Y := Round(bh*s);
4348 end;
4349 end;
4350 end;
4352 procedure g_Game_ChangeResolution(newWidth, newHeight: Word; nowFull, nowMax: Boolean);
4353 begin
4354 sys_SetDisplayMode(newWidth, newHeight, gBPP, nowFull, nowMax);
4355 end;
4357 procedure g_Game_AddPlayer(Team: Byte = TEAM_NONE);
4358 begin
4359 if ((not gGameOn) and (gState <> STATE_INTERCUSTOM))
4360 or (not (gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT])) then
4361 Exit;
4363 if (gGameSettings.MaxLives > 0) and (gLMSRespawn = LMS_RESPAWN_NONE) then
4364 Exit;
4366 if gPlayer1 = nil then
4367 begin
4368 if g_Game_IsClient then
4369 begin
4370 if NetPlrUID1 > -1 then
4371 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE);
4372 Exit;
4373 end;
4375 if not (Team in [TEAM_RED, TEAM_BLUE]) then
4376 Team := gPlayer1Settings.Team;
4378 // Ñîçäàíèå ïåðâîãî èãðîêà:
4379 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
4380 gPlayer1Settings.Color,
4381 Team, False));
4382 if gPlayer1 = nil then
4383 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]))
4384 else
4385 begin
4386 gPlayer1.Name := gPlayer1Settings.Name;
4387 gPlayer1.WeapSwitchMode := gPlayer1Settings.WeaponSwitch;
4388 gPlayer1.setWeaponPrefs(gPlayer1Settings.WeaponPreferences);
4389 gPlayer1.SwitchToEmpty := gPlayer1Settings.SwitchToEmpty;
4390 gPlayer1.SkipIronFist := gPlayer1Settings.SkipIronFist;
4391 g_Console_Add(Format(_lc[I_PLAYER_JOIN], [gPlayer1.Name]), True);
4392 if g_Game_IsServer and g_Game_IsNet then
4393 MH_SEND_PlayerCreate(gPlayer1.UID);
4394 gPlayer1.Respawn(False, True);
4395 g_Net_Slist_ServerPlayerComes();
4396 end;
4398 Exit;
4399 end;
4400 if gPlayer2 = nil then
4401 begin
4402 if g_Game_IsClient then
4403 begin
4404 if NetPlrUID2 > -1 then
4405 gPlayer2 := g_Player_Get(NetPlrUID2);
4406 Exit;
4407 end;
4409 if not (Team in [TEAM_RED, TEAM_BLUE]) then
4410 Team := gPlayer2Settings.Team;
4412 // Ñîçäàíèå âòîðîãî èãðîêà:
4413 gPlayer2 := g_Player_Get(g_Player_Create(gPlayer2Settings.Model,
4414 gPlayer2Settings.Color,
4415 Team, False));
4416 if gPlayer2 = nil then
4417 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [2]))
4418 else
4419 begin
4420 gPlayer2.Name := gPlayer2Settings.Name;
4421 gPlayer2.WeapSwitchMode := gPlayer2Settings.WeaponSwitch;
4422 gPlayer2.setWeaponPrefs(gPlayer2Settings.WeaponPreferences);
4423 gPlayer2.SwitchToEmpty := gPlayer2Settings.SwitchToEmpty;
4424 gPlayer2.SkipIronFist := gPlayer2Settings.SkipIronFist;
4425 g_Console_Add(Format(_lc[I_PLAYER_JOIN], [gPlayer2.Name]), True);
4426 if g_Game_IsServer and g_Game_IsNet then
4427 MH_SEND_PlayerCreate(gPlayer2.UID);
4428 gPlayer2.Respawn(False, True);
4429 g_Net_Slist_ServerPlayerComes();
4430 end;
4432 Exit;
4433 end;
4434 end;
4436 procedure g_Game_RemovePlayer();
4437 var
4438 Pl: TPlayer;
4439 begin
4440 if ((not gGameOn) and (gState <> STATE_INTERCUSTOM))
4441 or (not (gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT])) then
4442 Exit;
4443 Pl := gPlayer2;
4444 if Pl <> nil then
4445 begin
4446 if g_Game_IsServer then
4447 begin
4448 Pl.Lives := 0;
4449 Pl.Kill(K_SIMPLEKILL, 0, HIT_DISCON);
4450 g_Console_Add(Format(_lc[I_PLAYER_LEAVE], [Pl.Name]), True);
4451 g_Player_Remove(Pl.UID);
4452 g_Net_Slist_ServerPlayerLeaves();
4453 end
4454 else
4455 begin
4456 gSpectLatchPID2 := Pl.UID;
4457 gPlayer2 := nil;
4458 end;
4459 Exit;
4460 end;
4461 Pl := gPlayer1;
4462 if Pl <> nil then
4463 begin
4464 if g_Game_IsServer then
4465 begin
4466 Pl.Lives := 0;
4467 Pl.Kill(K_SIMPLEKILL, 0, HIT_DISCON);
4468 g_Console_Add(Format(_lc[I_PLAYER_LEAVE], [Pl.Name]), True);
4469 g_Player_Remove(Pl.UID);
4470 g_Net_Slist_ServerPlayerLeaves();
4471 end else
4472 begin
4473 gSpectLatchPID1 := Pl.UID;
4474 gPlayer1 := nil;
4475 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE);
4476 end;
4477 Exit;
4478 end;
4479 g_Net_Slist_ServerPlayerLeaves();
4480 end;
4482 procedure g_Game_Spectate();
4483 begin
4484 g_Game_RemovePlayer();
4485 if gPlayer1 <> nil then
4486 g_Game_RemovePlayer();
4487 end;
4489 procedure g_Game_SpectateCenterView();
4490 begin
4491 gSpectX := Max(gMapInfo.Width div 2 - gScreenWidth div 2, 0);
4492 gSpectY := Max(gMapInfo.Height div 2 - gScreenHeight div 2, 0);
4493 end;
4495 procedure g_Game_StartSingle(Map: String; TwoPlayers: Boolean; nPlayers: Byte);
4496 var
4497 i, nPl: Integer;
4498 tmps: AnsiString;
4499 begin
4500 g_Game_Free();
4502 e_WriteLog('Starting singleplayer game...', TMsgType.Notify);
4504 g_Game_ClearLoading();
4506 // Íàñòðîéêè èãðû:
4507 gGameSettings := Default(TGameSettings);
4508 gAimLine := False;
4509 gShowMap := False;
4510 gGameSettings.GameType := GT_SINGLE;
4511 gGameSettings.MaxLives := 0;
4512 gGameSettings.Options := GAME_OPTION_ALLOWEXIT
4513 or GAME_OPTION_MONSTERS
4514 or GAME_OPTION_BOTVSMONSTER
4515 or GAME_OPTION_TEAMHITPROJECTILE
4516 or GAME_OPTION_TEAMHITTRACE
4517 or GAME_OPTION_POWERUPRANDOM
4518 or GAME_OPTION_ITEMALLRANDOM
4519 or GAME_OPTION_ITEMHELPRANDOM
4520 or GAME_OPTION_ITEMAMMORANDOM
4521 or GAME_OPTION_ITEMWEAPONRANDOM;
4522 gSwitchGameMode := GM_SINGLE;
4524 gLMSRespawn := LMS_RESPAWN_NONE;
4525 gLMSRespawnTime := 0;
4526 gSpectLatchPID1 := 0;
4527 gSpectLatchPID2 := 0;
4529 g_Game_ExecuteEvent('ongamestart');
4531 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
4532 g_Game_SetupScreenSize();
4534 // Ñîçäàíèå ïåðâîãî èãðîêà:
4535 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
4536 gPlayer1Settings.Color,
4537 gPlayer1Settings.Team, False));
4538 if gPlayer1 = nil then
4539 begin
4540 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]));
4541 Exit;
4542 end;
4544 gPlayer1.Name := gPlayer1Settings.Name;
4545 gPlayer1.WeapSwitchMode := gPlayer1Settings.WeaponSwitch;
4546 gPlayer1.setWeaponPrefs(gPlayer1Settings.WeaponPreferences);
4547 gPlayer1.SwitchToEmpty := gPlayer1Settings.SwitchToEmpty;
4548 gPlayer1.SkipIronFist := gPlayer1Settings.SkipIronFist;
4549 nPl := 1;
4551 // Ñîçäàíèå âòîðîãî èãðîêà, åñëè åñòü:
4552 if TwoPlayers then
4553 begin
4554 gPlayer2 := g_Player_Get(g_Player_Create(gPlayer2Settings.Model,
4555 gPlayer2Settings.Color,
4556 gPlayer2Settings.Team, False));
4557 if gPlayer2 = nil then
4558 begin
4559 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [2]));
4560 Exit;
4561 end;
4563 gPlayer2.Name := gPlayer2Settings.Name;
4564 gPlayer2.WeapSwitchMode := gPlayer2Settings.WeaponSwitch;
4565 gPlayer2.setWeaponPrefs(gPlayer2Settings.WeaponPreferences);
4566 gPlayer2.SwitchToEmpty := gPlayer2Settings.SwitchToEmpty;
4567 gPlayer2.SkipIronFist := gPlayer2Settings.SkipIronFist;
4568 Inc(nPl);
4569 end;
4571 // Çàãðóçêà è çàïóñê êàðòû:
4572 if not g_Game_StartMap(false{asMegawad}, MAP, True) then
4573 begin
4574 if (Pos(':\', Map) > 0) or (Pos(':/', Map) > 0) then tmps := Map else tmps := gGameSettings.WAD + ':\' + MAP;
4575 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [tmps]));
4576 Exit;
4577 end;
4579 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4580 g_Player_Init();
4582 // Ñîçäàåì áîòîâ:
4583 for i := nPl+1 to nPlayers do
4584 g_Player_Create(STD_PLAYER_MODEL, _RGB(0, 0, 0), 0, True);
4585 end;
4587 procedure g_Game_StartCustom(Map: String; GameMode: Byte;
4588 TimeLimit, ScoreLimit: Word;
4589 MaxLives: Byte;
4590 Options: LongWord; nPlayers: Byte);
4591 var
4592 i, nPl: Integer;
4593 begin
4594 g_Game_Free();
4596 e_WriteLog('Starting custom game...', TMsgType.Notify);
4598 g_Game_ClearLoading();
4600 // Íàñòðîéêè èãðû:
4601 gGameSettings.GameType := GT_CUSTOM;
4602 gGameSettings.GameMode := GameMode;
4603 gSwitchGameMode := GameMode;
4604 gGameSettings.TimeLimit := TimeLimit;
4605 gGameSettings.ScoreLimit := ScoreLimit;
4606 gGameSettings.MaxLives := IfThen(GameMode = GM_CTF, 0, MaxLives);
4607 gGameSettings.Options := Options;
4609 gCoopTotalMonstersKilled := 0;
4610 gCoopTotalSecretsFound := 0;
4611 gCoopTotalMonsters := 0;
4612 gCoopTotalSecrets := 0;
4613 gAimLine := False;
4614 gShowMap := False;
4616 gLMSRespawn := LMS_RESPAWN_NONE;
4617 gLMSRespawnTime := 0;
4618 gSpectLatchPID1 := 0;
4619 gSpectLatchPID2 := 0;
4621 g_Game_ExecuteEvent('ongamestart');
4623 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
4624 g_Game_SetupScreenSize();
4626 // Ðåæèì íàáëþäàòåëÿ:
4627 if nPlayers = 0 then
4628 begin
4629 gPlayer1 := nil;
4630 gPlayer2 := nil;
4631 end;
4633 nPl := 0;
4634 if nPlayers >= 1 then
4635 begin
4636 // Ñîçäàíèå ïåðâîãî èãðîêà:
4637 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
4638 gPlayer1Settings.Color,
4639 gPlayer1Settings.Team, False));
4640 if gPlayer1 = nil then
4641 begin
4642 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]));
4643 Exit;
4644 end;
4646 gPlayer1.Name := gPlayer1Settings.Name;
4647 gPlayer1.WeapSwitchMode := gPlayer1Settings.WeaponSwitch;
4648 gPlayer1.setWeaponPrefs(gPlayer1Settings.WeaponPreferences);
4649 gPlayer1.SwitchToEmpty := gPlayer1Settings.SwitchToEmpty;
4650 gPlayer1.SkipIronFist := gPlayer1Settings.SkipIronFist;
4651 Inc(nPl);
4652 end;
4654 if nPlayers >= 2 then
4655 begin
4656 // Ñîçäàíèå âòîðîãî èãðîêà:
4657 gPlayer2 := g_Player_Get(g_Player_Create(gPlayer2Settings.Model,
4658 gPlayer2Settings.Color,
4659 gPlayer2Settings.Team, False));
4660 if gPlayer2 = nil then
4661 begin
4662 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [2]));
4663 Exit;
4664 end;
4666 gPlayer2.Name := gPlayer2Settings.Name;
4667 gPlayer2.WeapSwitchMode := gPlayer2Settings.WeaponSwitch;
4668 gPlayer2.setWeaponPrefs(gPlayer2Settings.WeaponPreferences);
4669 gPlayer2.SwitchToEmpty := gPlayer2Settings.SwitchToEmpty;
4670 gPlayer2.SkipIronFist := gPlayer2Settings.SkipIronFist;
4671 Inc(nPl);
4672 end;
4674 // Çàãðóçêà è çàïóñê êàðòû:
4675 if not g_Game_StartMap(true{asMegawad}, Map, True) then
4676 begin
4677 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [Map]));
4678 Exit;
4679 end;
4681 // Íåò òî÷åê ïîÿâëåíèÿ:
4682 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1) +
4683 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2) +
4684 g_Map_GetPointCount(RESPAWNPOINT_DM) +
4685 g_Map_GetPointCount(RESPAWNPOINT_RED)+
4686 g_Map_GetPointCount(RESPAWNPOINT_BLUE)) < 1 then
4687 begin
4688 g_FatalError(_lc[I_GAME_ERROR_GET_SPAWN]);
4689 Exit;
4690 end;
4692 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4693 g_Player_Init();
4695 // Ñîçäàåì áîòîâ:
4696 for i := nPl+1 to nPlayers do
4697 g_Player_Create(STD_PLAYER_MODEL, _RGB(0, 0, 0), 0, True);
4698 end;
4700 procedure g_Game_StartServer(Map: String; GameMode: Byte;
4701 TimeLimit, ScoreLimit: Word; MaxLives: Byte;
4702 Options: LongWord; nPlayers: Byte;
4703 IPAddr: LongWord; Port: Word);
4704 begin
4705 g_Game_Free();
4706 g_Net_Slist_ServerClosed();
4708 e_WriteLog('Starting net game (server)...', TMsgType.Notify);
4710 g_Game_ClearLoading();
4712 ClearDebugCvars();
4714 // Íàñòðîéêè èãðû:
4715 gGameSettings.GameType := GT_SERVER;
4716 gGameSettings.GameMode := GameMode;
4717 gSwitchGameMode := GameMode;
4718 gGameSettings.TimeLimit := TimeLimit;
4719 gGameSettings.ScoreLimit := ScoreLimit;
4720 gGameSettings.MaxLives := IfThen(GameMode = GM_CTF, 0, MaxLives);
4721 gGameSettings.Options := Options;
4723 gCoopTotalMonstersKilled := 0;
4724 gCoopTotalSecretsFound := 0;
4725 gCoopTotalMonsters := 0;
4726 gCoopTotalSecrets := 0;
4727 gAimLine := False;
4728 gShowMap := False;
4730 gLMSRespawn := LMS_RESPAWN_NONE;
4731 gLMSRespawnTime := 0;
4732 gSpectLatchPID1 := 0;
4733 gSpectLatchPID2 := 0;
4735 g_Game_ExecuteEvent('ongamestart');
4737 // Óñòàíîâêà ðàçìåðîâ îêíà èãðîêà
4738 g_Game_SetupScreenSize();
4740 // Ðåæèì íàáëþäàòåëÿ:
4741 if nPlayers = 0 then
4742 begin
4743 gPlayer1 := nil;
4744 gPlayer2 := nil;
4745 end;
4747 if nPlayers >= 1 then
4748 begin
4749 // Ñîçäàíèå ïåðâîãî èãðîêà:
4750 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
4751 gPlayer1Settings.Color,
4752 gPlayer1Settings.Team, False));
4753 if gPlayer1 = nil then
4754 begin
4755 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]));
4756 Exit;
4757 end;
4759 gPlayer1.Name := gPlayer1Settings.Name;
4760 gPlayer1.WeapSwitchMode := gPlayer1Settings.WeaponSwitch;
4761 gPlayer1.setWeaponPrefs(gPlayer1Settings.WeaponPreferences);
4762 gPlayer1.SwitchToEmpty := gPlayer1Settings.SwitchToEmpty;
4763 gPlayer1.SkipIronFist := gPlayer1Settings.SkipIronFist;
4764 end;
4766 if nPlayers >= 2 then
4767 begin
4768 // Ñîçäàíèå âòîðîãî èãðîêà:
4769 gPlayer2 := g_Player_Get(g_Player_Create(gPlayer2Settings.Model,
4770 gPlayer2Settings.Color,
4771 gPlayer2Settings.Team, False));
4772 if gPlayer2 = nil then
4773 begin
4774 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [2]));
4775 Exit;
4776 end;
4778 gPlayer2.Name := gPlayer2Settings.Name;
4779 gPlayer2.WeapSwitchMode := gPlayer2Settings.WeaponSwitch;
4780 gPlayer2.setWeaponPrefs(gPlayer2Settings.WeaponPreferences);
4781 gPlayer2.SwitchToEmpty := gPlayer2Settings.SwitchToEmpty;
4782 gPlayer2.SkipIronFist := gPlayer2Settings.SkipIronFist;
4783 end;
4785 g_Game_SetLoadingText(_lc[I_LOAD_HOST], 0, False);
4786 if NetForwardPorts then
4787 g_Game_SetLoadingText(_lc[I_LOAD_PORTS], 0, False);
4789 // Ñòàðòóåì ñåðâåð
4790 if not g_Net_Host(IPAddr, Port, NetMaxClients) then
4791 begin
4792 g_FatalError(_lc[I_NET_MSG] + Format(_lc[I_NET_ERR_HOST], [Port]));
4793 Exit;
4794 end;
4796 g_Net_Slist_Set(NetMasterList);
4798 g_Net_Slist_ServerStarted();
4800 // Çàãðóçêà è çàïóñê êàðòû:
4801 if not g_Game_StartMap(false{asMegawad}, Map, True) then
4802 begin
4803 g_Net_Slist_ServerClosed();
4804 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [Map]));
4805 Exit;
4806 end;
4808 // Íåò òî÷åê ïîÿâëåíèÿ:
4809 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1) +
4810 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2) +
4811 g_Map_GetPointCount(RESPAWNPOINT_DM) +
4812 g_Map_GetPointCount(RESPAWNPOINT_RED)+
4813 g_Map_GetPointCount(RESPAWNPOINT_BLUE)) < 1 then
4814 begin
4815 g_Net_Slist_ServerClosed();
4816 g_FatalError(_lc[I_GAME_ERROR_GET_SPAWN]);
4817 Exit;
4818 end;
4820 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4821 g_Player_Init();
4823 g_Net_Slist_ServerMapStarted();
4824 NetState := NET_STATE_GAME;
4825 end;
4827 procedure g_Game_StartClient(Addr: String; Port: Word; PW: String);
4828 var
4829 Map: String;
4830 WadName: string;
4831 Ptr: Pointer;
4832 T: Cardinal;
4833 MID: Byte;
4834 State: Byte;
4835 OuterLoop: Boolean;
4836 newResPath: string;
4837 InMsg: TMsg;
4838 begin
4839 g_Game_Free();
4841 State := 0;
4842 e_WriteLog('Starting net game (client)...', TMsgType.Notify);
4843 e_WriteLog('NET: Trying to connect to ' + Addr + ':' + IntToStr(Port) + '...', TMsgType.Notify);
4845 g_Game_ClearLoading();
4847 ClearDebugCvars();
4849 // Íàñòðîéêè èãðû:
4850 gGameSettings.GameType := GT_CLIENT;
4852 gCoopTotalMonstersKilled := 0;
4853 gCoopTotalSecretsFound := 0;
4854 gCoopTotalMonsters := 0;
4855 gCoopTotalSecrets := 0;
4856 gAimLine := False;
4857 gShowMap := False;
4859 g_Game_ExecuteEvent('ongamestart');
4861 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
4862 g_Game_SetupScreenSize();
4864 NetState := NET_STATE_AUTH;
4866 g_Game_SetLoadingText(_lc[I_LOAD_CONNECT], 0, False);
4868 // create (or update) map/resource databases
4869 g_Res_CreateDatabases(true);
4871 gLMSRespawn := LMS_RESPAWN_NONE;
4872 gLMSRespawnTime := 0;
4873 gSpectLatchPID1 := 0;
4874 gSpectLatchPID2 := 0;
4876 // Ñòàðòóåì êëèåíò
4877 if not g_Net_Connect(Addr, Port) then
4878 begin
4879 g_FatalError(_lc[I_NET_MSG] + _lc[I_NET_ERR_CONN]);
4880 NetState := NET_STATE_NONE;
4881 Exit;
4882 end;
4884 g_Game_SetLoadingText(_lc[I_LOAD_SEND_INFO], 0, False);
4885 MC_SEND_Info(PW);
4886 g_Game_SetLoadingText(_lc[I_LOAD_WAIT_INFO], 0, False);
4888 OuterLoop := True;
4889 while OuterLoop do
4890 begin
4891 // fuck! https://www.mail-archive.com/enet-discuss@cubik.org/msg00852.html
4892 // tl;dr: on shitdows, we can get -1 sometimes, and it is *NOT* a failure.
4893 // thank you, enet. let's ignore failures altogether then.
4894 while (enet_host_service(NetHost, @NetEvent, 50) > 0) do
4895 begin
4896 if (NetEvent.kind = ENET_EVENT_TYPE_RECEIVE) then
4897 begin
4898 Ptr := NetEvent.packet^.data;
4899 if not InMsg.Init(Ptr, NetEvent.packet^.dataLength, True) then
4900 begin
4901 enet_packet_destroy(NetEvent.packet);
4902 continue;
4903 end;
4905 InMsg.ReadLongWord(); // skip size
4906 MID := InMsg.ReadByte();
4908 if (MID = NET_MSG_INFO) and (State = 0) then
4909 begin
4910 NetMyID := InMsg.ReadByte();
4911 NetPlrUID1 := InMsg.ReadWord();
4913 WadName := InMsg.ReadString();
4914 Map := InMsg.ReadString();
4916 gWADHash := InMsg.ReadMD5();
4918 gGameSettings.GameMode := InMsg.ReadByte();
4919 gSwitchGameMode := gGameSettings.GameMode;
4920 gGameSettings.ScoreLimit := InMsg.ReadWord();
4921 gGameSettings.TimeLimit := InMsg.ReadWord();
4922 gGameSettings.MaxLives := InMsg.ReadByte();
4923 gGameSettings.Options := InMsg.ReadLongWord();
4924 T := InMsg.ReadLongWord();
4926 //newResPath := g_Res_SearchSameWAD(MapsDir, WadName, gWADHash);
4927 //if newResPath = '' then
4928 begin
4929 //g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
4930 newResPath := g_Res_DownloadMapWAD(ExtractFileName(WadName), gWADHash);
4931 if newResPath = '' then
4932 begin
4933 g_FatalError(_lc[I_NET_ERR_HASH]);
4934 enet_packet_destroy(NetEvent.packet);
4935 NetState := NET_STATE_NONE;
4936 Exit;
4937 end;
4938 e_LogWritefln('using downloaded map wad [%s] for [%s]`', [newResPath, WadName], TMsgType.Notify);
4939 end;
4940 //newResPath := ExtractRelativePath(MapsDir, newResPath);
4943 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
4944 gPlayer1Settings.Color,
4945 gPlayer1Settings.Team, False));
4947 if gPlayer1 = nil then
4948 begin
4949 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]));
4951 enet_packet_destroy(NetEvent.packet);
4952 NetState := NET_STATE_NONE;
4953 Exit;
4954 end;
4956 gPlayer1.Name := gPlayer1Settings.Name;
4957 gPlayer1.WeapSwitchMode := gPlayer1Settings.WeaponSwitch;
4958 gPlayer1.setWeaponPrefs(gPlayer1Settings.WeaponPreferences);
4959 gPlayer1.SwitchToEmpty := gPlayer1Settings.SwitchToEmpty;
4960 gPlayer1.SkipIronFist := gPlayer1Settings.SkipIronFist;
4961 gPlayer1.UID := NetPlrUID1;
4962 gPlayer1.Reset(True);
4964 if not g_Game_StartMap(false{asMegawad}, newResPath + ':\' + Map, True) then
4965 begin
4966 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [WadName + ':\' + Map]));
4968 enet_packet_destroy(NetEvent.packet);
4969 NetState := NET_STATE_NONE;
4970 Exit;
4971 end;
4973 gTime := T;
4975 State := 1;
4976 OuterLoop := False;
4977 enet_packet_destroy(NetEvent.packet);
4978 break;
4979 end
4980 else
4981 enet_packet_destroy(NetEvent.packet);
4982 end
4983 else
4984 begin
4985 if (NetEvent.kind = ENET_EVENT_TYPE_DISCONNECT) then
4986 begin
4987 State := 0;
4988 if (NetEvent.data <= NET_DISC_MAX) then
4989 g_Console_Add(_lc[I_NET_MSG_ERROR] + _lc[I_NET_ERR_CONN] + ' ' +
4990 _lc[TStrings_Locale(Cardinal(I_NET_DISC_NONE) + NetEvent.data)], True);
4991 OuterLoop := False;
4992 Break;
4993 end;
4994 end;
4995 end;
4997 ProcessLoading(True);
4998 if g_Net_UserRequestExit() then
4999 begin
5000 State := 0;
5001 break;
5002 end;
5003 end;
5005 if State <> 1 then
5006 begin
5007 g_FatalError(_lc[I_NET_MSG] + _lc[I_NET_ERR_CONN]);
5008 NetState := NET_STATE_NONE;
5009 Exit;
5010 end;
5012 g_Player_Init();
5013 NetState := NET_STATE_GAME;
5014 MC_SEND_FullStateRequest;
5015 e_WriteLog('NET: Connection successful.', TMsgType.Notify);
5016 end;
5018 var
5019 lastAsMegaWad: Boolean = false;
5021 procedure g_Game_ChangeMap(const MapPath: String);
5022 var
5023 Force: Boolean;
5024 begin
5025 g_Game_ClearLoading();
5027 Force := gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF];
5028 // Åñëè óðîâåíü çàâåðøèëñÿ ïî òðèããåðó Âûõîä, íå î÷èùàòü èíâåíòàðü
5029 if gExitByTrigger then
5030 begin
5031 Force := False;
5032 gExitByTrigger := False;
5033 end;
5034 if not g_Game_StartMap(lastAsMegaWad, MapPath, Force) then
5035 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [MapPath]));
5036 end;
5038 procedure g_Game_Restart();
5039 var
5040 Map: string;
5041 begin
5042 if g_Game_IsClient then
5043 Exit;
5044 map := g_ExtractFileName(gMapInfo.Map);
5045 e_LogWritefln('g_Game_Restart: map = "%s" gCurrentMapFileName = "%s"', [map, gCurrentMapFileName]);
5047 MessageTime := 0;
5048 gGameOn := False;
5049 g_Game_ClearLoading();
5050 g_Game_StartMap(lastAsMegaWad, Map, True, gCurrentMapFileName);
5051 end;
5053 function g_Game_StartMap (asMegawad: Boolean; Map: String; Force: Boolean = False; const oldMapPath: AnsiString=''): Boolean;
5054 var
5055 NewWAD, ResName: String;
5056 I: Integer;
5057 nws: AnsiString;
5058 begin
5059 g_Map_Free((Map <> gCurrentMapFileName) and (oldMapPath <> gCurrentMapFileName));
5060 g_Player_RemoveAllCorpses();
5062 if (not g_Game_IsClient) and
5063 (gSwitchGameMode <> gGameSettings.GameMode) and
5064 (gGameSettings.GameMode <> GM_SINGLE) then
5065 begin
5066 if gSwitchGameMode = GM_CTF then
5067 gGameSettings.MaxLives := 0;
5068 gGameSettings.GameMode := gSwitchGameMode;
5069 Force := True;
5070 end else
5071 gSwitchGameMode := gGameSettings.GameMode;
5073 g_Player_ResetTeams();
5075 lastAsMegaWad := asMegawad;
5076 if isWadPath(Map) then
5077 begin
5078 NewWAD := g_ExtractWadName(Map);
5079 ResName := g_ExtractFileName(Map);
5080 if g_Game_IsServer then
5081 begin
5082 nws := findDiskWad(NewWAD);
5083 //writeln('000: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
5084 if (asMegawad) then
5085 begin
5086 if (length(nws) = 0) then nws := e_FindWad(MegawadDirs, NewWAD);
5087 if (length(nws) = 0) then nws := e_FindWad(MapDirs, NewWAD);
5088 end
5089 else
5090 begin
5091 if (length(nws) = 0) then nws := e_FindWad(MapDirs, NewWAD);
5092 if (length(nws) = 0) then nws := e_FindWad(MegawadDirs, NewWAD);
5093 end;
5094 //if (length(nws) = 0) then nws := e_FindWad(MapDownloadDirs, NewWAD);
5095 //writeln('001: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
5096 //nws := NewWAD;
5097 if (length(nws) = 0) then
5098 begin
5099 ResName := ''; // failed
5100 end
5101 else
5102 begin
5103 NewWAD := nws;
5104 if (g_Game_IsNet) then gWADHash := MD5File(nws);
5105 //writeln('********: nws=', nws, ' : Map=', Map, ' : nw=', NewWAD, ' : resname=', ResName);
5106 g_Game_LoadWAD(NewWAD);
5107 end;
5108 end
5109 else
5110 begin
5111 // hash received in MC_RECV_GameEvent -> NET_EV_MAPSTART
5112 NewWAD := g_Game_ClientWAD(NewWAD, gWADHash);
5113 end;
5114 end
5115 else
5116 begin
5117 NewWAD := gGameSettings.WAD;
5118 ResName := Map;
5119 end;
5121 gTime := 0;
5123 //writeln('********: gsw=', gGameSettings.WAD, '; rn=', ResName);
5124 result := false;
5125 if (ResName <> '') and (NewWAD <> '') then
5126 begin
5127 //result := g_Map_Load(gGameSettings.WAD + ':\' + ResName);
5128 result := g_Map_Load(NewWAD+':\'+ResName);
5129 end;
5130 if Result then
5131 begin
5132 g_Player_ResetAll(Force or gLastMap, gGameSettings.GameType = GT_SINGLE);
5134 gState := STATE_NONE;
5135 g_ActiveWindow := nil;
5136 gGameOn := True;
5138 DisableCheats();
5139 ResetTimer();
5141 if gGameSettings.GameMode = GM_CTF then
5142 begin
5143 g_Map_ResetFlag(FLAG_RED);
5144 g_Map_ResetFlag(FLAG_BLUE);
5145 // CTF, à ôëàãîâ íåò:
5146 if not g_Map_HaveFlagPoints() then
5147 g_SimpleError(_lc[I_GAME_ERROR_CTF]);
5148 end;
5149 end
5150 else
5151 begin
5152 gState := STATE_MENU;
5153 gGameOn := False;
5154 end;
5156 gExit := 0;
5157 gPauseMain := false;
5158 gPauseHolmes := false;
5159 NetTimeToUpdate := 1;
5160 NetTimeToReliable := 0;
5161 NetTimeToMaster := NetMasterRate;
5162 gSpectLatchPID1 := 0;
5163 gSpectLatchPID2 := 0;
5164 gMissionFailed := False;
5165 gNextMap := '';
5167 gCoopMonstersKilled := 0;
5168 gCoopSecretsFound := 0;
5170 gVoteInProgress := False;
5171 gVotePassed := False;
5172 gVoteCount := 0;
5173 gVoted := False;
5175 gStatsOff := False;
5177 if not gGameOn then Exit;
5179 g_Game_SpectateCenterView();
5181 if g_Game_IsServer then
5182 begin
5183 if (gGameSettings.MaxLives > 0) and (gGameSettings.WarmupTime > 0) then
5184 begin
5185 gLMSRespawn := LMS_RESPAWN_WARMUP;
5186 gLMSRespawnTime := gTime + gGameSettings.WarmupTime*1000;
5187 gLMSSoftSpawn := True;
5188 if g_Game_IsNet then
5189 MH_SEND_GameEvent(NET_EV_LMS_WARMUP, gLMSRespawnTime - gTime);
5190 end
5191 else
5192 begin
5193 gLMSRespawn := LMS_RESPAWN_NONE;
5194 gLMSRespawnTime := 0;
5195 end;
5196 end;
5198 if NetMode = NET_SERVER then
5199 begin
5200 // reset full state flags
5201 if NetClients <> nil then
5202 for I := 0 to High(NetClients) do
5203 NetClients[I].FullUpdateSent := False;
5205 MH_SEND_GameEvent(NET_EV_MAPSTART, gGameSettings.GameMode, Map);
5207 // Ìàñòåðñåðâåð
5208 g_Net_Slist_ServerMapStarted();
5210 if NetClients <> nil then
5211 for I := 0 to High(NetClients) do
5212 if NetClients[I].Used then
5213 begin
5214 NetClients[I].Voted := False;
5215 if NetClients[I].RequestedFullUpdate then
5216 begin
5217 MH_SEND_Everything((NetClients[I].State = NET_STATE_AUTH), I);
5218 NetClients[I].RequestedFullUpdate := False;
5219 end;
5220 end;
5222 g_Net_UnbanNonPerm();
5223 end;
5225 if gLastMap then
5226 begin
5227 gCoopTotalMonstersKilled := 0;
5228 gCoopTotalSecretsFound := 0;
5229 gCoopTotalMonsters := 0;
5230 gCoopTotalSecrets := 0;
5231 gLastMap := False;
5232 end;
5234 g_Game_ExecuteEvent('onmapstart');
5235 end;
5237 procedure SetFirstLevel;
5238 begin
5239 gNextMap := '';
5241 MapList := g_Map_GetMapsList(gGameSettings.WAD);
5242 if MapList = nil then
5243 Exit;
5245 SortSArray(MapList);
5246 gNextMap := MapList[Low(MapList)];
5248 MapList := nil;
5249 end;
5251 procedure g_Game_ExitLevel(const Map: AnsiString);
5252 begin
5253 gNextMap := Map;
5255 gCoopTotalMonstersKilled := gCoopTotalMonstersKilled + gCoopMonstersKilled;
5256 gCoopTotalSecretsFound := gCoopTotalSecretsFound + gCoopSecretsFound;
5257 gCoopTotalMonsters := gCoopTotalMonsters + gTotalMonsters;
5258 gCoopTotalSecrets := gCoopTotalSecrets + gSecretsCount;
5260 // Âûøëè â âûõîä â Îäèíî÷íîé èãðå:
5261 if gGameSettings.GameType = GT_SINGLE then
5262 gExit := EXIT_ENDLEVELSINGLE
5263 else // Âûøëè â âûõîä â Ñâîåé èãðå
5264 begin
5265 gExit := EXIT_ENDLEVELCUSTOM;
5266 if gGameSettings.GameMode = GM_COOP then
5267 g_Player_RememberAll;
5269 if not g_Map_Exist(gGameSettings.WAD + ':\' + gNextMap) then
5270 begin
5271 gLastMap := True;
5272 if gGameSettings.GameMode = GM_COOP then
5273 gStatsOff := True;
5275 gStatsPressed := True;
5276 gNextMap := 'MAP01';
5278 if not g_Map_Exist(gGameSettings.WAD + ':\' + gNextMap) then
5279 g_Game_NextLevel;
5281 if g_Game_IsNet then
5282 begin
5283 MH_SEND_GameStats();
5284 MH_SEND_CoopStats();
5285 end;
5286 end;
5287 end;
5288 end;
5290 procedure g_Game_RestartLevel();
5291 var
5292 Map: string;
5293 begin
5294 if gGameSettings.GameMode = GM_SINGLE then
5295 begin
5296 g_Game_Restart();
5297 Exit;
5298 end;
5299 gExit := EXIT_ENDLEVELCUSTOM;
5300 Map := g_ExtractFileName(gMapInfo.Map);
5301 gNextMap := Map;
5302 end;
5304 function g_Game_ClientWAD (NewWAD: String; const WHash: TMD5Digest): AnsiString;
5305 var
5306 gWAD{, xwad}: String;
5307 begin
5308 result := NewWAD;
5309 if not g_Game_IsClient then Exit;
5310 //e_LogWritefln('*** g_Game_ClientWAD: `%s`', [NewWAD]);
5312 gWAD := g_Res_DownloadMapWAD(ExtractFileName(NewWAD), WHash);
5313 if gWAD = '' then
5314 begin
5315 result := '';
5316 g_Game_Free();
5317 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_WAD], [ExtractFileName(NewWAD)]));
5318 Exit;
5319 end;
5321 e_LogWritefln('using downloaded client map wad [%s] for [%s]', [gWAD, NewWAD], TMsgType.Notify);
5322 NewWAD := gWAD;
5324 g_Game_LoadWAD(NewWAD);
5325 result := NewWAD;
5328 if LowerCase(NewWAD) = LowerCase(gGameSettings.WAD) then Exit;
5329 gWAD := g_Res_SearchSameWAD(MapsDir, ExtractFileName(NewWAD), WHash);
5330 if gWAD = '' then
5331 begin
5332 g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
5333 gWAD := g_Res_DownloadMapWAD(ExtractFileName(NewWAD), WHash);
5334 if gWAD = '' then
5335 begin
5336 g_Game_Free();
5337 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_WAD], [ExtractFileName(NewWAD)]));
5338 Exit;
5339 end;
5340 end;
5341 NewWAD := ExtractRelativePath(MapsDir, gWAD);
5342 g_Game_LoadWAD(NewWAD);
5344 end;
5346 procedure g_Game_RestartRound(NoMapRestart: Boolean = False);
5347 var
5348 i, n, nb, nr: Integer;
5349 begin
5350 if not g_Game_IsServer then Exit;
5351 if gLMSRespawn = LMS_RESPAWN_NONE then Exit;
5352 gLMSRespawn := LMS_RESPAWN_NONE;
5353 gLMSRespawnTime := 0;
5354 MessageTime := 0;
5356 if (gGameSettings.GameMode = GM_COOP) and not NoMapRestart then
5357 begin
5358 gMissionFailed := True;
5359 g_Game_RestartLevel;
5360 Exit;
5361 end;
5363 n := 0; nb := 0; nr := 0;
5364 for i := Low(gPlayers) to High(gPlayers) do
5365 if (gPlayers[i] <> nil) and
5366 ((not gPlayers[i].FSpectator) or gPlayers[i].FWantsInGame or
5367 (gPlayers[i] is TBot)) then
5368 begin
5369 Inc(n);
5370 if gPlayers[i].Team = TEAM_RED then Inc(nr)
5371 else if gPlayers[i].Team = TEAM_BLUE then Inc(nb)
5372 end;
5374 if (n < 1) or ((gGameSettings.GameMode = GM_TDM) and ((nr = 0) or (nb = 0))) then
5375 begin
5376 // wait a second until the fuckers finally decide to join
5377 gLMSRespawn := LMS_RESPAWN_WARMUP;
5378 gLMSRespawnTime := gTime + gGameSettings.WarmupTime*1000;
5379 gLMSSoftSpawn := NoMapRestart;
5380 if g_Game_IsNet then
5381 MH_SEND_GameEvent(NET_EV_LMS_WARMUP, gLMSRespawnTime - gTime);
5382 Exit;
5383 end;
5385 g_Player_RemoveAllCorpses;
5386 g_Game_Message(_lc[I_MESSAGE_LMS_START], 144);
5387 if g_Game_IsNet then
5388 MH_SEND_GameEvent(NET_EV_LMS_START);
5390 for i := Low(gPlayers) to High(gPlayers) do
5391 begin
5392 if gPlayers[i] = nil then continue;
5393 if gPlayers[i] is TBot then gPlayers[i].FWantsInGame := True;
5394 // don't touch normal spectators
5395 if gPlayers[i].FSpectator and not gPlayers[i].FWantsInGame then
5396 begin
5397 gPlayers[i].FNoRespawn := True;
5398 gPlayers[i].Lives := 0;
5399 if g_Game_IsNet then
5400 MH_SEND_PlayerStats(gPlayers[I].UID);
5401 continue;
5402 end;
5403 gPlayers[i].FNoRespawn := False;
5404 gPlayers[i].Lives := gGameSettings.MaxLives;
5405 gPlayers[i].Respawn(False, True);
5406 if gGameSettings.GameMode = GM_COOP then
5407 begin
5408 gPlayers[i].Frags := 0;
5409 gPlayers[i].RestoreState;
5410 end;
5411 if (gPlayer1 = nil) and (gSpectLatchPID1 > 0) then
5412 gPlayer1 := g_Player_Get(gSpectLatchPID1);
5413 if (gPlayer2 = nil) and (gSpectLatchPID2 > 0) then
5414 gPlayer2 := g_Player_Get(gSpectLatchPID2);
5415 end;
5417 g_Items_RestartRound();
5419 gLMSSoftSpawn := False;
5420 end;
5422 function g_Game_GetFirstMap(WAD: String): String;
5423 begin
5424 Result := '';
5426 MapList := g_Map_GetMapsList(WAD);
5427 if MapList = nil then
5428 Exit;
5430 SortSArray(MapList);
5431 Result := MapList[Low(MapList)];
5433 if not g_Map_Exist(WAD + ':\' + Result) then
5434 Result := '';
5436 MapList := nil;
5437 end;
5439 function g_Game_GetNextMap(): String;
5440 var
5441 I: Integer;
5442 Map: string;
5443 begin
5444 Result := '';
5446 MapList := g_Map_GetMapsList(gGameSettings.WAD);
5447 if MapList = nil then
5448 Exit;
5450 Map := g_ExtractFileName(gMapInfo.Map);
5452 SortSArray(MapList);
5453 MapIndex := -255;
5454 for I := Low(MapList) to High(MapList) do
5455 if Map = MapList[I] then
5456 begin
5457 MapIndex := I;
5458 Break;
5459 end;
5461 if MapIndex <> -255 then
5462 begin
5463 if MapIndex = High(MapList) then
5464 Result := MapList[Low(MapList)]
5465 else
5466 Result := MapList[MapIndex + 1];
5468 if not g_Map_Exist(gGameSettings.WAD + ':\' + Result) then Result := Map;
5469 end;
5471 MapList := nil;
5472 end;
5474 procedure g_Game_NextLevel();
5475 begin
5476 if gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF, GM_COOP] then
5477 gExit := EXIT_ENDLEVELCUSTOM
5478 else
5479 begin
5480 gExit := EXIT_ENDLEVELSINGLE;
5481 Exit;
5482 end;
5484 if gNextMap <> '' then Exit;
5485 gNextMap := g_Game_GetNextMap();
5486 end;
5488 function g_Game_IsTestMap(): Boolean;
5489 begin
5490 result := StrEquCI1251(TEST_MAP_NAME, g_ExtractFileName(gMapInfo.Map));
5491 end;
5493 procedure g_Game_DeleteTestMap();
5494 var
5495 a: Integer;
5496 //MapName: AnsiString;
5497 WadName: string;
5499 WAD: TWADFile;
5500 MapList: SSArray;
5501 time: Integer;
5503 begin
5504 a := Pos('.wad:\', toLowerCase1251(gMapToDelete));
5505 if (a = 0) then a := Pos('.wad:/', toLowerCase1251(gMapToDelete));
5506 if (a = 0) then exit;
5508 // Âûäåëÿåì èìÿ wad-ôàéëà è èìÿ êàðòû
5509 WadName := Copy(gMapToDelete, 1, a+3);
5510 Delete(gMapToDelete, 1, a+5);
5511 gMapToDelete := UpperCase(gMapToDelete);
5512 //MapName := '';
5513 //CopyMemory(@MapName[0], @gMapToDelete[1], Min(16, Length(gMapToDelete)));
5516 // Èìÿ êàðòû íå ñòàíäàðòíîå òåñòîâîå:
5517 if MapName <> TEST_MAP_NAME then
5518 Exit;
5520 if not gTempDelete then
5521 begin
5522 time := g_GetFileTime(WadName);
5523 WAD := TWADFile.Create();
5525 // ×èòàåì Wad-ôàéë:
5526 if not WAD.ReadFile(WadName) then
5527 begin // Íåò òàêîãî WAD-ôàéëà
5528 WAD.Free();
5529 Exit;
5530 end;
5532 // Ñîñòàâëÿåì ñïèñîê êàðò è èùåì íóæíóþ:
5533 WAD.CreateImage();
5534 MapList := WAD.GetResourcesList('');
5536 if MapList <> nil then
5537 for a := 0 to High(MapList) do
5538 if MapList[a] = MapName then
5539 begin
5540 // Óäàëÿåì è ñîõðàíÿåì:
5541 WAD.RemoveResource('', MapName);
5542 WAD.SaveTo(WadName);
5543 Break;
5544 end;
5546 WAD.Free();
5547 g_SetFileTime(WadName, time);
5548 end else
5550 if gTempDelete then DeleteFile(WadName);
5551 end;
5553 procedure GameCVars(P: SSArray);
5554 var
5555 a, b: Integer;
5556 stat: TPlayerStatArray;
5557 cmd: string;
5558 it: PItem;
5560 procedure ParseGameFlag(Flag: LongWord; OffMsg, OnMsg: TStrings_Locale; OnMapChange: Boolean = False);
5561 var
5562 x: Boolean;
5563 begin
5564 if Length(P) > 1 then
5565 begin
5566 x := P[1] = '1';
5568 if x then
5569 gsGameFlags := gsGameFlags or Flag
5570 else
5571 gsGameFlags := gsGameFlags and (not Flag);
5573 if g_Game_IsServer then
5574 begin
5575 if x then
5576 gGameSettings.Options := gGameSettings.Options or Flag
5577 else
5578 gGameSettings.Options := gGameSettings.Options and (not Flag);
5579 if g_Game_IsNet then MH_SEND_GameSettings;
5580 end;
5581 end;
5583 if LongBool(gsGameFlags and Flag) then
5584 g_Console_Add(_lc[OnMsg])
5585 else
5586 g_Console_Add(_lc[OffMsg]);
5588 if OnMapChange and g_Game_IsServer then
5589 g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
5590 end;
5592 begin
5593 stat := nil;
5594 cmd := LowerCase(P[0]);
5596 case cmd of
5597 'g_gamemode': begin
5598 if (Length(P) > 1) then
5599 begin
5600 a := g_Game_TextToMode(P[1]);
5601 if a = GM_SINGLE then a := GM_COOP;
5602 gsGameMode := g_Game_ModeToText(a);
5603 if g_Game_IsServer then
5604 begin
5605 gSwitchGameMode := a;
5606 if (gGameOn and (gGameSettings.GameMode = GM_SINGLE)) or
5607 (gState = STATE_INTERSINGLE) then
5608 gSwitchGameMode := GM_SINGLE;
5609 if not gGameOn then
5610 gGameSettings.GameMode := gSwitchGameMode;
5611 end;
5612 end;
5614 if gSwitchGameMode = gGameSettings.GameMode then
5615 g_Console_Add(Format(_lc[I_MSG_GAMEMODE_CURRENT],
5616 [g_Game_ModeToText(gGameSettings.GameMode)]))
5617 else
5618 g_Console_Add(Format(_lc[I_MSG_GAMEMODE_CHANGE],
5619 [g_Game_ModeToText(gGameSettings.GameMode),
5620 g_Game_ModeToText(gSwitchGameMode)]));
5621 end;
5623 'g_friendlyfire':
5624 ParseGameFlag(GAME_OPTION_TEAMDAMAGE, I_MSG_FRIENDLY_FIRE_OFF, I_MSG_FRIENDLY_FIRE_ON);
5625 'g_friendly_absorb_damage':
5626 ParseGameFlag(GAME_OPTION_TEAMABSORBDAMAGE, I_MSG_FRIENDLY_ABSORB_DAMAGE_OFF, I_MSG_FRIENDLY_ABSORB_DAMAGE_ON);
5627 'g_friendly_hit_trace':
5628 ParseGameFlag(GAME_OPTION_TEAMHITTRACE, I_MSG_FRIENDLY_HIT_TRACE_OFF, I_MSG_FRIENDLY_HIT_TRACE_ON);
5629 'g_friendly_hit_projectile':
5630 ParseGameFlag(GAME_OPTION_TEAMHITPROJECTILE, I_MSG_FRIENDLY_PROJECT_TRACE_OFF, I_MSG_FRIENDLY_PROJECT_TRACE_ON);
5631 'g_items_all_respawn_random':
5632 ParseGameFlag(GAME_OPTION_ITEMALLRANDOM, I_MSG_ITEM_ALL_RANDOM_OFF, I_MSG_ITEM_ALL_RANDOM_ON, False);
5633 'g_items_help_respawn_random':
5634 ParseGameFlag(GAME_OPTION_ITEMHELPRANDOM, I_MSG_ITEM_HELP_RANDOM_OFF, I_MSG_ITEM_HELP_RANDOM_ON, False);
5635 'g_items_ammo_respawn_random':
5636 ParseGameFlag(GAME_OPTION_ITEMAMMORANDOM, I_MSG_ITEM_AMMO_RANDOM_OFF, I_MSG_ITEM_AMMO_RANDOM_ON, False);
5637 'g_items_weapon_respawn_random':
5638 ParseGameFlag(GAME_OPTION_ITEMWEAPONRANDOM, I_MSG_ITEM_WEAPON_RANDOM_OFF, I_MSG_ITEM_WEAPON_RANDOM_ON);
5639 'g_powerup_randomize_respawn':
5640 ParseGameFlag(GAME_OPTION_POWERUPRANDOM, I_MSG_POWERUP_RANDOM_OFF, I_MSG_POWERUP_RANDOM_ON, False);
5641 'g_weaponstay':
5642 ParseGameFlag(GAME_OPTION_WEAPONSTAY, I_MSG_WEAPONSTAY_OFF, I_MSG_WEAPONSTAY_ON);
5643 'g_allow_exit':
5644 ParseGameFlag(GAME_OPTION_ALLOWEXIT, I_MSG_ALLOWEXIT_OFF, I_MSG_ALLOWEXIT_ON, True);
5645 'g_allow_monsters':
5646 ParseGameFlag(GAME_OPTION_MONSTERS, I_MSG_ALLOWMON_OFF, I_MSG_ALLOWMON_ON, True);
5647 'g_allow_dropflag':
5648 ParseGameFlag(GAME_OPTION_ALLOWDROPFLAG, I_MSG_ALLOWDROPFLAG_OFF, I_MSG_ALLOWDROPFLAG_ON);
5649 'g_throw_flag':
5650 ParseGameFlag(GAME_OPTION_THROWFLAG, I_MSG_THROWFLAG_OFF, I_MSG_THROWFLAG_ON);
5651 'g_bot_vsplayers':
5652 ParseGameFlag(GAME_OPTION_BOTVSPLAYER, I_MSG_BOTSVSPLAYERS_OFF, I_MSG_BOTSVSPLAYERS_ON);
5653 'g_bot_vsmonsters':
5654 ParseGameFlag(GAME_OPTION_BOTVSMONSTER, I_MSG_BOTSVSMONSTERS_OFF, I_MSG_BOTSVSMONSTERS_ON);
5655 'g_dm_keys':
5656 ParseGameFlag(GAME_OPTION_DMKEYS, I_MSG_DMKEYS_OFF, I_MSG_DMKEYS_ON, True);
5658 'g_gameflags': begin
5659 if Length(P) > 1 then
5660 begin
5661 gsGameFlags := StrToDWordDef(P[1], gsGameFlags);
5662 if g_Game_IsServer then
5663 begin
5664 gGameSettings.Options := gsGameFlags;
5665 if g_Game_IsNet then MH_SEND_GameSettings;
5666 end;
5667 end;
5669 g_Console_Add(Format('%s %u', [cmd, gsGameFlags]));
5670 end;
5672 'g_warmup_time': begin
5673 if Length(P) > 1 then
5674 begin
5675 gsWarmupTime := nclamp(StrToIntDef(P[1], gsWarmupTime), 0, $FFFF);
5676 if g_Game_IsServer then
5677 begin
5678 gGameSettings.WarmupTime := gsWarmupTime;
5679 // extend warmup if it's already going
5680 if gLMSRespawn = LMS_RESPAWN_WARMUP then
5681 begin
5682 gLMSRespawnTime := gTime + gsWarmupTime * 1000;
5683 if g_Game_IsNet then MH_SEND_GameEvent(NET_EV_LMS_WARMUP, gLMSRespawnTime - gTime);
5684 end;
5685 if g_Game_IsNet then MH_SEND_GameSettings;
5686 end;
5687 end;
5689 g_Console_Add(Format(_lc[I_MSG_WARMUP], [Integer(gsWarmupTime)]));
5690 if g_Game_IsServer then g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
5691 end;
5693 'g_spawn_invul': begin
5694 if Length(P) > 1 then
5695 begin
5696 gsSpawnInvul := nclamp(StrToIntDef(P[1], gsSpawnInvul), 0, $FFFF);
5697 if g_Game_IsServer then
5698 begin
5699 gGameSettings.SpawnInvul := gsSpawnInvul;
5700 if g_Game_IsNet then MH_SEND_GameSettings;
5701 end;
5702 end;
5704 g_Console_Add(Format('%s %d', [cmd, Integer(gsSpawnInvul)]));
5705 end;
5707 'g_item_respawn_time': begin
5708 if Length(P) > 1 then
5709 begin
5710 gsItemRespawnTime := nclamp(StrToIntDef(P[1], gsItemRespawnTime), 0, $FFFF);
5711 if g_Game_IsServer then
5712 begin
5713 gGameSettings.ItemRespawnTime := gsItemRespawnTime;
5714 if g_Game_IsNet then MH_SEND_GameSettings;
5715 end;
5716 end;
5718 g_Console_Add(Format('%s %d', [cmd, Integer(gsItemRespawnTime)]));
5719 if g_Game_IsServer then g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
5720 end;
5722 'g_item_time_random': begin
5723 if Length(P) > 1 then
5724 begin
5725 gsItemRespawnRandom := nclamp(StrToIntDef(P[1], gsItemRespawnRandom), 0, $FFFF);
5726 if g_Game_IsServer then
5727 begin
5728 gGameSettings.ItemRespawnRandom := gsItemRespawnRandom;
5729 if g_Game_IsNet then MH_SEND_GameSettings;
5730 end;
5731 end;
5733 g_Console_Add(Format('%s %d', [cmd, Integer(gsItemRespawnRandom)]));
5734 if g_Game_IsServer then g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
5735 end;
5737 'g_powerup_respawn_time': begin
5738 if Length(P) > 1 then
5739 begin
5740 gsPowerupRespawnTime := nclamp(StrToIntDef(P[1], gsPowerupRespawnTime), 0, $FFFF);
5741 if g_Game_IsServer then
5742 begin
5743 gGameSettings.PowerupRespawnTime := gsPowerupRespawnTime;
5744 if g_Game_IsNet then MH_SEND_GameSettings;
5745 end;
5746 end;
5748 g_Console_Add(Format('%s %d', [cmd, Integer(gsPowerupRespawnTime)]));
5749 if g_Game_IsServer then g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
5750 end;
5752 'g_powerup_time_random': begin
5753 if Length(P) > 1 then
5754 begin
5755 gsPowerupRespawnRandom := nclamp(StrToIntDef(P[1], gsPowerupRespawnRandom), 0, $FFFF);
5756 if g_Game_IsServer then
5757 begin
5758 gGameSettings.PowerupRespawnRandom := gsPowerupRespawnRandom;
5759 if g_Game_IsNet then MH_SEND_GameSettings;
5760 end;
5761 end;
5763 g_Console_Add(Format('%s %d', [cmd, Integer(gsPowerupRespawnRandom)]));
5764 if g_Game_IsServer then g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
5765 end;
5767 'sv_intertime': begin
5768 if (Length(P) > 1) then
5769 gDefInterTime := Min(Max(StrToIntDef(P[1], gDefInterTime), -1), 120);
5771 g_Console_Add(cmd + ' = ' + IntToStr(gDefInterTime));
5772 end;
5774 'g_max_particles': begin
5775 if Length(p) = 2 then
5776 begin
5777 a := Max(0, StrToIntDef(p[1], 0));
5778 g_GFX_SetMax(a)
5779 end
5780 else if Length(p) = 1 then
5781 begin
5782 e_LogWritefln('%s', [g_GFX_GetMax()])
5783 end
5784 else
5785 begin
5786 e_LogWritefln('usage: %s <n>', [cmd])
5787 end
5788 end;
5790 'g_max_shells': begin
5791 if Length(p) = 2 then
5792 begin
5793 a := Max(0, StrToIntDef(p[1], 0));
5794 g_Shells_SetMax(a)
5795 end
5796 else if Length(p) = 1 then
5797 begin
5798 e_LogWritefln('%s', [g_Shells_GetMax()])
5799 end
5800 else
5801 begin
5802 e_LogWritefln('usage: %s <n>', [cmd])
5803 end
5804 end;
5806 'g_max_gibs': begin
5807 if Length(p) = 2 then
5808 begin
5809 a := Max(0, StrToIntDef(p[1], 0));
5810 g_Gibs_SetMax(a)
5811 end
5812 else if Length(p) = 1 then
5813 begin
5814 e_LogWritefln('%s', [g_Gibs_GetMax()])
5815 end
5816 else
5817 begin
5818 e_LogWritefln('usage: %s <n>', [cmd])
5819 end
5820 end;
5822 'g_max_corpses': begin
5823 if Length(p) = 2 then
5824 begin
5825 a := Max(0, StrToIntDef(p[1], 0));
5826 g_Corpses_SetMax(a)
5827 end
5828 else if Length(p) = 1 then
5829 begin
5830 e_LogWritefln('%s', [g_Corpses_GetMax()])
5831 end
5832 else
5833 begin
5834 e_LogWritefln('usage: %s <n>', [cmd])
5835 end
5836 end;
5838 'g_force_model': begin
5839 if Length(p) = 2 then
5840 begin
5841 a := StrToIntDef(p[1], 0);
5842 g_Force_Model_Set(a);
5843 if (g_Force_Model_Get() <> 0) and (gPlayers <> nil) then
5844 begin
5845 for a := Low(gPlayers) to High(gPlayers) do
5846 begin
5847 if (gPlayers[a] <> nil) then
5848 begin
5849 if (gPlayers[a].UID = gPlayer1.UID) then
5850 continue
5851 else if (gPlayer2 <> nil) and (gPlayers[a].UID = gPlayer2.UID) then
5852 continue;
5853 gPlayers[a].setModel(g_Forced_Model_GetName());
5854 end;
5855 end
5856 end
5857 else if (g_Force_Model_Get() = 0) and (gPlayers <> nil) then
5858 begin
5859 for a := Low(gPlayers) to High(gPlayers) do
5860 begin
5861 if (gPlayers[a] <> nil) then
5862 begin
5863 if (gPlayers[a].UID = gPlayer1.UID) then
5864 continue
5865 else if (gPlayer2 <> nil) and (gPlayers[a].UID = gPlayer2.UID) then
5866 continue;
5867 gPlayers[a].setModel(gPlayers[a].FActualModelName);
5868 end;
5869 end
5870 end
5871 end
5872 end;
5874 'g_force_model_name': begin
5875 if (Length(P) > 1) then
5876 begin
5877 cmd := b_Text_Unformat(P[1]);
5878 g_Forced_Model_SetName(cmd);
5879 if (g_Force_Model_Get() <> 0) and (gPlayers <> nil) then
5880 begin
5881 for a := Low(gPlayers) to High(gPlayers) do
5882 begin
5883 if (gPlayers[a] <> nil) then
5884 begin
5885 if (gPlayers[a].UID = gPlayer1.UID) then
5886 continue
5887 else if (gPlayer2 <> nil) and (gPlayers[a].UID = gPlayer2.UID) then
5888 continue;
5889 gPlayers[a].setModel(g_Forced_Model_GetName());
5890 end;
5891 end
5892 end
5893 end
5894 end;
5896 'g_scorelimit': begin
5897 if Length(P) > 1 then
5898 begin
5899 gsScoreLimit := nclamp(StrToIntDef(P[1], gsScoreLimit), 0, $FFFF);
5901 if g_Game_IsServer then
5902 begin
5903 b := 0;
5904 if gGameSettings.GameMode = GM_DM then
5905 begin // DM
5906 stat := g_Player_GetStats();
5907 if stat <> nil then
5908 for a := 0 to High(stat) do
5909 if stat[a].Frags > b then
5910 b := stat[a].Frags;
5911 end
5912 else // TDM/CTF
5913 b := Max(gTeamStat[TEAM_RED].Score, gTeamStat[TEAM_BLUE].Score);
5915 // if someone has a higher score, set it to that instead
5916 gsScoreLimit := max(gsScoreLimit, b);
5917 gGameSettings.ScoreLimit := gsScoreLimit;
5919 if g_Game_IsNet then MH_SEND_GameSettings;
5920 end;
5921 end;
5923 g_Console_Add(Format(_lc[I_MSG_SCORE_LIMIT], [Integer(gsScoreLimit)]));
5924 end;
5926 'g_timelimit': begin
5927 if Length(P) > 1 then
5928 begin
5929 gsTimeLimit := nclamp(StrToIntDef(P[1], gsTimeLimit), 0, $FFFF);
5930 if g_Game_IsServer then
5931 begin
5932 gGameSettings.TimeLimit := gsTimeLimit;
5933 if g_Game_IsNet then MH_SEND_GameSettings;
5934 end;
5935 end;
5936 g_Console_Add(Format(_lc[I_MSG_TIME_LIMIT],
5937 [gsTimeLimit div 3600,
5938 (gsTimeLimit div 60) mod 60,
5939 gsTimeLimit mod 60]));
5940 end;
5942 'g_max_bots': begin
5943 if Length(P) > 1 then
5944 gMaxBots := nclamp(StrToIntDef(P[1], gMaxBots), 0, 127);
5945 g_Console_Add('g_max_bots = ' + IntToStr(gMaxBots));
5946 end;
5948 'g_maxlives': begin
5949 if Length(P) > 1 then
5950 begin
5951 gsMaxLives := nclamp(StrToIntDef(P[1], gsMaxLives), 0, $FFFF);
5952 if g_Game_IsServer then
5953 begin
5954 gGameSettings.MaxLives := gsMaxLives;
5955 if g_Game_IsNet then MH_SEND_GameSettings;
5956 end;
5957 end;
5959 g_Console_Add(Format(_lc[I_MSG_LIVES], [Integer(gsMaxLives)]));
5960 end;
5961 end;
5962 end;
5964 procedure PlayerSettingsCVars(P: SSArray);
5965 var
5966 cmd: string;
5967 team: Byte;
5969 function ParseTeam(s: string): Byte;
5970 begin
5971 result := 0;
5972 case s of
5973 'red', '1': result := TEAM_RED;
5974 'blue', '2': result := TEAM_BLUE;
5975 else result := TEAM_NONE;
5976 end;
5977 end;
5978 begin
5979 cmd := LowerCase(P[0]);
5980 case cmd of
5981 'p1_name':
5982 begin
5983 if (Length(P) > 1) then
5984 begin
5985 gPlayer1Settings.Name := b_Text_Unformat(P[1]);
5986 if g_Game_IsClient then
5987 MC_SEND_PlayerSettings
5988 else if gGameOn and (gPlayer1 <> nil) then
5989 begin
5990 gPlayer1.Name := b_Text_Unformat(P[1]);
5991 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer1.UID);
5992 end;
5993 end;
5994 end;
5995 'p2_name':
5996 begin
5997 if (Length(P) > 1) then
5998 begin
5999 gPlayer2Settings.Name := b_Text_Unformat(P[1]);
6000 if g_Game_IsClient then
6001 MC_SEND_PlayerSettings
6002 else if gGameOn and (gPlayer2 <> nil) then
6003 begin
6004 gPlayer2.Name := b_Text_Unformat(P[1]);
6005 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer2.UID);
6006 end;
6007 end;
6008 end;
6009 'p1_color':
6010 begin
6011 if Length(P) > 3 then
6012 begin
6013 gPlayer1Settings.Color := _RGB(EnsureRange(StrToIntDef(P[1], 0), 0, 255),
6014 EnsureRange(StrToIntDef(P[2], 0), 0, 255),
6015 EnsureRange(StrToIntDef(P[3], 0), 0, 255));
6016 if g_Game_IsClient then
6017 MC_SEND_PlayerSettings
6018 else if gGameOn and (gPlayer1 <> nil) then
6019 begin
6020 gPlayer1.SetColor(gPlayer1Settings.Color);
6021 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer1.UID);
6022 end;
6023 end;
6024 end;
6025 'p2_color':
6026 begin
6027 if Length(P) > 3 then
6028 begin
6029 gPlayer2Settings.Color := _RGB(EnsureRange(StrToIntDef(P[1], 0), 0, 255),
6030 EnsureRange(StrToIntDef(P[2], 0), 0, 255),
6031 EnsureRange(StrToIntDef(P[3], 0), 0, 255));
6032 if g_Game_IsClient then
6033 MC_SEND_PlayerSettings
6034 else if gGameOn and (gPlayer2 <> nil) then
6035 begin
6036 gPlayer2.SetColor(gPlayer2Settings.Color);
6037 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer2.UID);
6038 end;
6039 end;
6040 end;
6041 'p1_model':
6042 begin
6043 if (Length(P) > 1) then
6044 begin
6045 gPlayer1Settings.Model := P[1];
6046 if g_Game_IsClient then
6047 MC_SEND_PlayerSettings
6048 else if gGameOn and (gPlayer1 <> nil) then
6049 begin
6050 gPlayer1.FActualModelName := gPlayer1Settings.Model;
6051 gPlayer1.SetModel(gPlayer1Settings.Model);
6052 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer1.UID);
6053 end;
6054 end;
6055 end;
6056 'p2_model':
6057 begin
6058 if (Length(P) > 1) then
6059 begin
6060 gPlayer2Settings.Model := P[1];
6061 if g_Game_IsClient then
6062 MC_SEND_PlayerSettings
6063 else if gGameOn and (gPlayer2 <> nil) then
6064 begin
6065 gPlayer2.FActualModelName := gPlayer2Settings.Model;
6066 gPlayer2.SetModel(gPlayer2Settings.Model);
6067 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer2.UID);
6068 end;
6069 end;
6070 end;
6071 'p1_team':
6072 begin
6073 // TODO: switch teams if in game or store this separately
6074 if (Length(P) > 1) then
6075 begin
6076 team := ParseTeam(P[1]);
6077 if team = TEAM_NONE then
6078 g_Console_Add('expected ''red'', ''blue'', 1 or 2')
6079 else if not gGameOn and not g_Game_IsNet then
6080 gPlayer1Settings.Team := team
6081 else
6082 g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
6083 end;
6084 end;
6085 'p2_team':
6086 begin
6087 // TODO: switch teams if in game or store this separately
6088 if (Length(P) > 1) then
6089 begin
6090 team := ParseTeam(P[1]);
6091 if team = TEAM_NONE then
6092 g_Console_Add('expected ''red'', ''blue'', 1 or 2')
6093 else if not gGameOn and not g_Game_IsNet then
6094 gPlayer2Settings.Team := team
6095 else
6096 g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
6097 end;
6098 end;
6099 'p1_autoswitch':
6100 begin
6101 if (Length(P) = 2) then
6102 gPlayer1Settings.WeaponSwitch := EnsureRange(StrTointDef(P[1], 0), 0, 2);
6103 end;
6104 'p2_autoswitch':
6105 begin
6106 if (Length(P) = 2) then
6107 gPlayer2Settings.WeaponSwitch := EnsureRange(StrTointDef(P[1], 0), 0, 2);
6108 end;
6109 'p1_switch_empty':
6110 begin
6111 if (Length(P) = 2) then
6112 gPlayer1Settings.SwitchToEmpty := EnsureRange(StrTointDef(P[1], 0), 0, 1);
6113 end;
6114 'p2_switch_empty':
6115 begin
6116 if (Length(P) = 2) then
6117 gPlayer2Settings.SwitchToEmpty := EnsureRange(StrTointDef(P[1], 0), 0, 1);
6118 end;
6119 'p1_skip_ironfist':
6120 begin
6121 if (Length(P) = 2) then
6122 gPlayer1Settings.SkipIronFist := EnsureRange(StrTointDef(P[1], 0), 0, 1);
6123 end;
6124 'p2_skip_ironfist':
6125 begin
6126 if (Length(P) = 2) then
6127 gPlayer2Settings.SkipIronFist := EnsureRange(StrTointDef(P[1], 0), 0, 1);
6128 end;
6129 'p1_priority_ironfist':
6130 begin
6131 if (Length(P) = 2) then
6132 gPlayer1Settings.WeaponPreferences[WEAPON_IRONFIST] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6133 end;
6134 'p2_priority_ironfist':
6135 begin
6136 if (Length(P) = 2) then
6137 gPlayer2Settings.WeaponPreferences[WEAPON_IRONFIST] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6138 end;
6139 'p1_priority_saw':
6140 begin
6141 if (Length(P) = 2) then
6142 gPlayer1Settings.WeaponPreferences[WEAPON_SAW] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6143 end;
6144 'p2_priority_saw':
6145 begin
6146 if (Length(P) = 2) then
6147 gPlayer2Settings.WeaponPreferences[WEAPON_SAW] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6148 end;
6149 'p1_priority_pistol':
6150 begin
6151 if (Length(P) = 2) then
6152 gPlayer1Settings.WeaponPreferences[WEAPON_PISTOL] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6153 end;
6154 'p2_priority_pistol':
6155 begin
6156 if (Length(P) = 2) then
6157 gPlayer2Settings.WeaponPreferences[WEAPON_PISTOL] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6158 end;
6159 'p1_priority_shotgun1':
6160 begin
6161 if (Length(P) = 2) then
6162 gPlayer1Settings.WeaponPreferences[WEAPON_SHOTGUN1] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6163 end;
6164 'p2_priority_shotgun1':
6165 begin
6166 if (Length(P) = 2) then
6167 gPlayer2Settings.WeaponPreferences[WEAPON_SHOTGUN1] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6168 end;
6169 'p1_priority_shotgun2':
6170 begin
6171 if (Length(P) = 2) then
6172 gPlayer1Settings.WeaponPreferences[WEAPON_SHOTGUN2] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6173 end;
6174 'p2_priority_shotgun2':
6175 begin
6176 if (Length(P) = 2) then
6177 gPlayer2Settings.WeaponPreferences[WEAPON_SHOTGUN2] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6178 end;
6179 'p1_priority_chaingun':
6180 begin
6181 if (Length(P) = 2) then
6182 gPlayer1Settings.WeaponPreferences[WEAPON_CHAINGUN] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6183 end;
6184 'p2_priority_chaingun':
6185 begin
6186 if (Length(P) = 2) then
6187 gPlayer2Settings.WeaponPreferences[WEAPON_CHAINGUN] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6188 end;
6189 'p1_priority_rocketlauncher':
6190 begin
6191 if (Length(P) = 2) then
6192 gPlayer1Settings.WeaponPreferences[WEAPON_ROCKETLAUNCHER] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6193 end;
6194 'p2_priority_rocketlauncher':
6195 begin
6196 if (Length(P) = 2) then
6197 gPlayer2Settings.WeaponPreferences[WEAPON_ROCKETLAUNCHER] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6198 end;
6199 'p1_priority_plasma':
6200 begin
6201 if (Length(P) = 2) then
6202 gPlayer1Settings.WeaponPreferences[WEAPON_PLASMA] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6203 end;
6204 'p2_priority_plasma':
6205 begin
6206 if (Length(P) = 2) then
6207 gPlayer2Settings.WeaponPreferences[WEAPON_PLASMA] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6208 end;
6209 'p1_priority_bfg':
6210 begin
6211 if (Length(P) = 2) then
6212 gPlayer1Settings.WeaponPreferences[WEAPON_BFG] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6213 end;
6214 'p2_priority_bfg':
6215 begin
6216 if (Length(P) = 2) then
6217 gPlayer2Settings.WeaponPreferences[WEAPON_BFG] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6218 end;
6219 'p1_priority_superchaingun':
6220 begin
6221 if (Length(P) = 2) then
6222 gPlayer1Settings.WeaponPreferences[WEAPON_SUPERCHAINGUN] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6223 end;
6224 'p2_priority_superchaingun':
6225 begin
6226 if (Length(P) = 2) then
6227 gPlayer2Settings.WeaponPreferences[WEAPON_SUPERCHAINGUN] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6228 end;
6229 'p1_priority_flamethrower':
6230 begin
6231 if (Length(P) = 2) then
6232 gPlayer1Settings.WeaponPreferences[WEAPON_FLAMETHROWER] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6233 end;
6234 'p2_priority_flamethrower':
6235 begin
6236 if (Length(P) = 2) then
6237 gPlayer2Settings.WeaponPreferences[WEAPON_FLAMETHROWER] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6238 end;
6239 'p1_priority_berserk':
6240 begin
6241 if (Length(P) = 2) then
6242 gPlayer1Settings.WeaponPreferences[WP_LAST+1] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6243 end;
6244 'p2_priority_berserk':
6245 begin
6246 if (Length(P) = 2) then
6247 gPlayer2Settings.WeaponPreferences[WP_LAST+1] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6248 end;
6249 end;
6250 end;
6252 procedure PrintHeapStats();
6253 var
6254 hs: TFPCHeapStatus;
6255 begin
6256 hs := GetFPCHeapStatus();
6257 e_LogWriteLn ('v===== heap status =====v');
6258 e_LogWriteFln('max heap size = %d k', [hs.MaxHeapSize div 1024]);
6259 e_LogWriteFln('max heap used = %d k', [hs.MaxHeapUsed div 1024]);
6260 e_LogWriteFln('cur heap size = %d k', [hs.CurrHeapSize div 1024]);
6261 e_LogWriteFln('cur heap used = %d k', [hs.CurrHeapUsed div 1024]);
6262 e_LogWriteFln('cur heap free = %d k', [hs.CurrHeapFree div 1024]);
6263 e_LogWriteLn ('^=======================^');
6264 end;
6266 procedure DebugCommands(P: SSArray);
6267 var
6268 a, b: Integer;
6269 cmd: string;
6270 //pt: TDFPoint;
6271 mon: TMonster;
6272 begin
6273 // Êîìàíäû îòëàäî÷íîãî ðåæèìà:
6274 if {gDebugMode}conIsCheatsEnabled then
6275 begin
6276 cmd := LowerCase(P[0]);
6277 if cmd = 'd_window' then
6278 begin
6279 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth, gScreenHeight]));
6280 g_Console_Add(Format('gWinSizeX = %d, gWinSizeY = %d', [gWinSizeX, gWinSizeY]));
6281 end
6282 else if cmd = 'd_sounds' then
6283 begin
6284 if (Length(P) > 1) and
6285 ((P[1] = '1') or (P[1] = '0')) then
6286 g_Debug_Sounds := (P[1][1] = '1');
6288 g_Console_Add(Format('d_sounds is %d', [Byte(g_Debug_Sounds)]));
6289 end
6290 else if cmd = 'd_frames' then
6291 begin
6292 if (Length(P) > 1) and
6293 ((P[1] = '1') or (P[1] = '0')) then
6294 g_Debug_Frames := (P[1][1] = '1');
6296 g_Console_Add(Format('d_frames is %d', [Byte(g_Debug_Frames)]));
6297 end
6298 else if cmd = 'd_winmsg' then
6299 begin
6300 if (Length(P) > 1) and
6301 ((P[1] = '1') or (P[1] = '0')) then
6302 g_Debug_WinMsgs := (P[1][1] = '1');
6304 g_Console_Add(Format('d_winmsg is %d', [Byte(g_Debug_WinMsgs)]));
6305 end
6306 else if (cmd = 'd_monoff') and not g_Game_IsNet then
6307 begin
6308 if (Length(P) > 1) and
6309 ((P[1] = '1') or (P[1] = '0')) then
6310 g_Debug_MonsterOff := (P[1][1] = '1');
6312 g_Console_Add(Format('d_monoff is %d', [Byte(g_debug_MonsterOff)]));
6313 end
6314 else if (cmd = 'd_botoff') and not g_Game_IsNet then
6315 begin
6316 if Length(P) > 1 then
6317 case P[1][1] of
6318 '0': g_debug_BotAIOff := 0;
6319 '1': g_debug_BotAIOff := 1;
6320 '2': g_debug_BotAIOff := 2;
6321 '3': g_debug_BotAIOff := 3;
6322 end;
6324 g_Console_Add(Format('d_botoff is %d', [g_debug_BotAIOff]));
6325 end
6326 else if cmd = 'd_monster' then
6327 begin
6328 if gGameOn and (gPlayer1 <> nil) and (gPlayer1.alive) and (not g_Game_IsNet) then
6329 if Length(P) < 2 then
6330 begin
6331 g_Console_Add(cmd + ' [ID | Name] [behaviour]');
6332 g_Console_Add('ID | Name');
6333 for b := MONSTER_DEMON to MONSTER_MAN do
6334 g_Console_Add(Format('%2d | %s', [b, g_Mons_NameByTypeId(b)]));
6335 conwriteln('behav. num'#10'normal 0'#10'killer 1'#10'maniac 2'#10'insane 3'#10'cannibal 4'#10'good 5');
6336 end else
6337 begin
6338 a := StrToIntDef(P[1], 0);
6339 if (a < MONSTER_DEMON) or (a > MONSTER_MAN) then
6340 a := g_Mons_TypeIdByName(P[1]);
6342 if (a < MONSTER_DEMON) or (a > MONSTER_MAN) then
6343 g_Console_Add(Format(_lc[I_MSG_NO_MONSTER], [P[1]]))
6344 else
6345 begin
6346 with gPlayer1.Obj do
6347 begin
6348 mon := g_Monsters_Create(a,
6349 X + Rect.X + (Rect.Width div 2),
6350 Y + Rect.Y + Rect.Height,
6351 gPlayer1.Direction, True);
6352 end;
6353 if (Length(P) > 2) and (mon <> nil) then
6354 begin
6355 if (CompareText(P[2], 'normal') = 0) then mon.MonsterBehaviour := BH_NORMAL
6356 else if (CompareText(P[2], 'killer') = 0) then mon.MonsterBehaviour := BH_KILLER
6357 else if (CompareText(P[2], 'maniac') = 0) then mon.MonsterBehaviour := BH_MANIAC
6358 else if (CompareText(P[2], 'insane') = 0) then mon.MonsterBehaviour := BH_INSANE
6359 else if (CompareText(P[2], 'cannibal') = 0) then mon.MonsterBehaviour := BH_CANNIBAL
6360 else if (CompareText(P[2], 'good') = 0) then mon.MonsterBehaviour := BH_GOOD
6361 else if (CompareText(P[2], 'friend') = 0) then mon.MonsterBehaviour := BH_GOOD
6362 else if (CompareText(P[2], 'friendly') = 0) then mon.MonsterBehaviour := BH_GOOD
6363 else mon.MonsterBehaviour := Min(Max(StrToIntDef(P[2], BH_NORMAL), BH_NORMAL), BH_GOOD);
6364 end;
6365 end;
6366 end;
6367 end
6368 else if (cmd = 'd_health') then
6369 begin
6370 if (Length(P) > 1) and
6371 ((P[1] = '1') or (P[1] = '0')) then
6372 g_debug_HealthBar := (P[1][1] = '1');
6374 g_Console_Add(Format('d_health is %d', [Byte(g_debug_HealthBar)]));
6375 end
6376 else if (cmd = 'd_player') then
6377 begin
6378 if (Length(P) > 1) and
6379 ((P[1] = '1') or (P[1] = '0')) then
6380 g_debug_Player := (P[1][1] = '1');
6382 g_Console_Add(Format(cmd + ' is %d', [Byte(g_Debug_Player)]));
6383 end
6384 else if (cmd = 'd_mem') then
6385 begin
6386 PrintHeapStats();
6387 end;
6388 end
6389 else
6390 g_Console_Add(_lc[I_MSG_NOT_DEBUG]);
6391 end;
6394 procedure GameCheats(P: SSArray);
6395 var
6396 cmd: string;
6397 f, a: Integer;
6398 plr: TPlayer;
6399 begin
6400 if (not gGameOn) or (not conIsCheatsEnabled) then
6401 begin
6402 g_Console_Add('not available');
6403 exit;
6404 end;
6405 plr := gPlayer1;
6406 if plr = nil then
6407 begin
6408 g_Console_Add('where is the player?!');
6409 exit;
6410 end;
6411 cmd := LowerCase(P[0]);
6412 // god
6413 if cmd = 'god' then
6414 begin
6415 plr.GodMode := not plr.GodMode;
6416 if plr.GodMode then g_Console_Add('player is godlike now') else g_Console_Add('player is mortal now');
6417 exit;
6418 end;
6419 // give <health|exit|weapons|air|suit|jetpack|berserk|all>
6420 if cmd = 'give' then
6421 begin
6422 if length(P) < 2 then begin g_Console_Add('give what?!'); exit; end;
6423 for f := 1 to High(P) do
6424 begin
6425 cmd := LowerCase(P[f]);
6426 if cmd = 'health' then begin plr.RestoreHealthArmor(); g_Console_Add('player feels himself better'); continue; end;
6427 if (cmd = 'all') {or (cmd = 'weapons')} then begin plr.TankRamboCheats(False); g_Console_Add('player got the gifts'); continue; end;
6428 if cmd = 'exit' then
6429 begin
6430 if gTriggers <> nil then
6431 begin
6432 for a := 0 to High(gTriggers) do
6433 begin
6434 if gTriggers[a].TriggerType = TRIGGER_EXIT then
6435 begin
6436 g_Console_Add('player left the map');
6437 gExitByTrigger := True;
6438 //g_Game_ExitLevel(gTriggers[a].Data.MapName);
6439 g_Game_ExitLevel(gTriggers[a].tgcMap);
6440 break;
6441 end;
6442 end;
6443 end;
6444 continue;
6445 end;
6447 if cmd = 'air' then begin plr.GiveItem(ITEM_OXYGEN); g_Console_Add('player got some air'); continue; end;
6448 if cmd = 'jetpack' then begin plr.GiveItem(ITEM_JETPACK); g_Console_Add('player got a jetpack'); continue; end;
6449 if cmd = 'suit' then begin plr.GiveItem(ITEM_SUIT); g_Console_Add('player got an envirosuit'); continue; end;
6450 if cmd = 'berserk' then begin plr.GiveItem(ITEM_MEDKIT_BLACK); g_Console_Add('player got a berserk pack'); continue; end;
6451 if cmd = 'backpack' then begin plr.GiveItem(ITEM_AMMO_BACKPACK); g_Console_Add('player got a backpack'); continue; end;
6453 if cmd = 'helmet' then begin plr.GiveItem(ITEM_HELMET); g_Console_Add('player got a helmet'); continue; end;
6454 if cmd = 'bottle' then begin plr.GiveItem(ITEM_BOTTLE); g_Console_Add('player got a bottle of health'); continue; end;
6456 if cmd = 'stimpack' then begin plr.GiveItem(ITEM_MEDKIT_SMALL); g_Console_Add('player got a stimpack'); continue; end;
6457 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;
6459 if cmd = 'greenarmor' then begin plr.GiveItem(ITEM_ARMOR_GREEN); g_Console_Add('player got a security armor'); continue; end;
6460 if cmd = 'bluearmor' then begin plr.GiveItem(ITEM_ARMOR_BLUE); g_Console_Add('player got a combat armor'); continue; end;
6462 if (cmd = 'soulsphere') or (cmd = 'soul') then begin plr.GiveItem(ITEM_SPHERE_BLUE); g_Console_Add('player got a soul sphere'); continue; end;
6463 if (cmd = 'megasphere') or (cmd = 'mega') then begin plr.GiveItem(ITEM_SPHERE_WHITE); g_Console_Add('player got a megasphere'); continue; end;
6465 if (cmd = 'invul') or (cmd = 'invulnerability') then begin plr.GiveItem(ITEM_INVUL); g_Console_Add('player got invulnerability'); continue; end;
6466 if (cmd = 'invis') or (cmd = 'invisibility') then begin plr.GiveItem(ITEM_INVIS); g_Console_Add('player got invisibility'); continue; end;
6468 if cmd = 'redkey' then begin plr.GiveItem(ITEM_KEY_RED); g_Console_Add('player got the red key'); continue; end;
6469 if cmd = 'greenkey' then begin plr.GiveItem(ITEM_KEY_GREEN); g_Console_Add('player got the green key'); continue; end;
6470 if cmd = 'bluekey' then begin plr.GiveItem(ITEM_KEY_BLUE); g_Console_Add('player got the blue key'); continue; end;
6472 if (cmd = 'shotgun') or (cmd = 'sg') then begin plr.GiveItem(ITEM_WEAPON_SHOTGUN1); g_Console_Add('player got a shotgun'); continue; end;
6473 if (cmd = 'supershotgun') or (cmd = 'ssg') then begin plr.GiveItem(ITEM_WEAPON_SHOTGUN2); g_Console_Add('player got a supershotgun'); continue; end;
6474 if cmd = 'chaingun' then begin plr.GiveItem(ITEM_WEAPON_CHAINGUN); g_Console_Add('player got a chaingun'); continue; end;
6475 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;
6476 if cmd = 'plasmagun' then begin plr.GiveItem(ITEM_WEAPON_PLASMA); g_Console_Add('player got a plasma gun'); continue; end;
6477 if cmd = 'bfg' then begin plr.GiveItem(ITEM_WEAPON_BFG); g_Console_Add('player got a BFG-9000'); continue; end;
6479 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;
6480 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;
6481 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;
6482 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;
6483 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;
6484 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;
6486 if cmd = 'superchaingun' then begin plr.GiveItem(ITEM_WEAPON_SUPERCHAINGUN); g_Console_Add('player got a superchaingun'); continue; end;
6487 if cmd = 'superchaingunzz' then begin plr.GiveItem(ITEM_WEAPON_SUPERCHAINGUN); plr.GiveItem(ITEM_AMMO_BULLETS_BOX); g_Console_Add('player got a superchaingun'); continue; end;
6489 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;
6490 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;
6492 if cmd = 'chainsaw' then begin plr.GiveItem(ITEM_WEAPON_SAW); g_Console_Add('player got a chainsaw'); continue; end;
6494 if cmd = 'ammo' then
6495 begin
6496 plr.GiveItem(ITEM_AMMO_SHELLS_BOX);
6497 plr.GiveItem(ITEM_AMMO_BULLETS_BOX);
6498 plr.GiveItem(ITEM_AMMO_CELL_BIG);
6499 plr.GiveItem(ITEM_AMMO_ROCKET_BOX);
6500 plr.GiveItem(ITEM_AMMO_FUELCAN);
6501 g_Console_Add('player got some ammo');
6502 continue;
6503 end;
6505 if cmd = 'clip' then begin plr.GiveItem(ITEM_AMMO_BULLETS); g_Console_Add('player got some bullets'); continue; end;
6506 if cmd = 'bullets' then begin plr.GiveItem(ITEM_AMMO_BULLETS_BOX); g_Console_Add('player got a box of bullets'); continue; end;
6508 if cmd = 'shells' then begin plr.GiveItem(ITEM_AMMO_SHELLS); g_Console_Add('player got some shells'); continue; end;
6509 if cmd = 'shellbox' then begin plr.GiveItem(ITEM_AMMO_SHELLS_BOX); g_Console_Add('player got a box of shells'); continue; end;
6511 if cmd = 'cells' then begin plr.GiveItem(ITEM_AMMO_CELL); g_Console_Add('player got some cells'); continue; end;
6512 if cmd = 'battery' then begin plr.GiveItem(ITEM_AMMO_CELL_BIG); g_Console_Add('player got cell battery'); continue; end;
6514 if cmd = 'rocket' then begin plr.GiveItem(ITEM_AMMO_ROCKET); g_Console_Add('player got a rocket'); continue; end;
6515 if cmd = 'rocketbox' then begin plr.GiveItem(ITEM_AMMO_ROCKET_BOX); g_Console_Add('player got some rockets'); continue; end;
6517 if (cmd = 'fuel') or (cmd = 'fuelcan') then begin plr.GiveItem(ITEM_AMMO_FUELCAN); g_Console_Add('player got fuel canister'); continue; end;
6519 if cmd = 'weapons' then
6520 begin
6521 plr.GiveItem(ITEM_WEAPON_SHOTGUN1);
6522 plr.GiveItem(ITEM_WEAPON_SHOTGUN2);
6523 plr.GiveItem(ITEM_WEAPON_CHAINGUN);
6524 plr.GiveItem(ITEM_WEAPON_ROCKETLAUNCHER);
6525 plr.GiveItem(ITEM_WEAPON_PLASMA);
6526 plr.GiveItem(ITEM_WEAPON_BFG);
6527 g_Console_Add('player got weapons');
6528 continue;
6529 end;
6531 if cmd = 'keys' then
6532 begin
6533 plr.GiveItem(ITEM_KEY_RED);
6534 plr.GiveItem(ITEM_KEY_GREEN);
6535 plr.GiveItem(ITEM_KEY_BLUE);
6536 g_Console_Add('player got all keys');
6537 continue;
6538 end;
6540 g_Console_Add('i don''t know how to give '''+cmd+'''!');
6541 end;
6542 exit;
6543 end;
6544 // open
6545 if cmd = 'open' then
6546 begin
6547 g_Console_Add('player activated sesame');
6548 g_Triggers_OpenAll();
6549 exit;
6550 end;
6551 // fly
6552 if cmd = 'fly' then
6553 begin
6554 gFly := not gFly;
6555 if gFly then g_Console_Add('player feels himself lighter') else g_Console_Add('player lost his wings');
6556 exit;
6557 end;
6558 // noclip
6559 if cmd = 'noclip' then
6560 begin
6561 plr.SwitchNoClip;
6562 g_Console_Add('wall hardeness adjusted');
6563 exit;
6564 end;
6565 // notarget
6566 if cmd = 'notarget' then
6567 begin
6568 plr.NoTarget := not plr.NoTarget;
6569 if plr.NoTarget then g_Console_Add('player hides in shadows') else g_Console_Add('player is brave again');
6570 exit;
6571 end;
6572 // noreload
6573 if cmd = 'noreload' then
6574 begin
6575 plr.NoReload := not plr.NoReload;
6576 if plr.NoReload then g_Console_Add('player is action hero now') else g_Console_Add('player is ordinary man now');
6577 exit;
6578 end;
6579 // speedy
6580 if cmd = 'speedy' then
6581 begin
6582 MAX_RUNVEL := 32-MAX_RUNVEL;
6583 g_Console_Add('speed adjusted');
6584 exit;
6585 end;
6586 // jumpy
6587 if cmd = 'jumpy' then
6588 begin
6589 VEL_JUMP := 30-VEL_JUMP;
6590 g_Console_Add('jump height adjusted');
6591 exit;
6592 end;
6593 // automap
6594 if cmd = 'automap' then
6595 begin
6596 gShowMap := not gShowMap;
6597 if gShowMap then g_Console_Add('player gains second sight') else g_Console_Add('player lost second sight');
6598 exit;
6599 end;
6600 // aimline
6601 if cmd = 'aimline' then
6602 begin
6603 gAimLine := not gAimLine;
6604 if gAimLine then g_Console_Add('player gains laser sight') else g_Console_Add('player lost laser sight');
6605 exit;
6606 end;
6607 end;
6609 procedure GameCommands(P: SSArray);
6610 var
6611 a, b: Integer;
6612 s, pw: String;
6613 chstr: string;
6614 cmd: string;
6615 pl: pTNetClient = nil;
6616 plr: TPlayer;
6617 prt: Word;
6618 nm: Boolean;
6619 listen: LongWord;
6620 found: Boolean;
6621 t: Byte;
6622 begin
6623 // Îáùèå êîìàíäû:
6624 cmd := LowerCase(P[0]);
6625 chstr := '';
6626 if cmd = 'pause' then
6627 begin
6628 if (g_ActiveWindow = nil) then
6629 g_Game_Pause(not gPauseMain);
6630 end
6631 else if cmd = 'endgame' then
6632 gExit := EXIT_SIMPLE
6633 else if cmd = 'restart' then
6634 begin
6635 if gGameOn or (gState in [STATE_INTERSINGLE, STATE_INTERCUSTOM]) then
6636 begin
6637 if g_Game_IsClient then
6638 begin
6639 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6640 Exit;
6641 end;
6642 g_Game_Restart();
6643 end else
6644 g_Console_Add(_lc[I_MSG_NOT_GAME]);
6645 end
6646 else if cmd = 'kick' then
6647 begin
6648 if g_Game_IsServer then
6649 begin
6650 if Length(P) < 2 then
6651 begin
6652 g_Console_Add('kick <name>');
6653 Exit;
6654 end;
6655 if P[1] = '' then
6656 begin
6657 g_Console_Add('kick <name>');
6658 Exit;
6659 end;
6661 if g_Game_IsNet then
6662 pl := g_Net_Client_ByName(P[1]);
6663 if (pl <> nil) then
6664 begin
6665 s := g_Net_ClientName_ByID(pl^.ID);
6666 g_Net_Host_Kick(pl^.ID, NET_DISC_KICK);
6667 g_Console_Add(Format(_lc[I_PLAYER_KICK], [s]));
6668 MH_SEND_GameEvent(NET_EV_PLAYER_KICK, 0, s);
6669 g_Net_Slist_ServerPlayerLeaves();
6670 end else if gPlayers <> nil then
6671 for a := Low(gPlayers) to High(gPlayers) do
6672 if gPlayers[a] <> nil then
6673 if Copy(LowerCase(gPlayers[a].Name), 1, Length(P[1])) = LowerCase(P[1]) then
6674 begin
6675 // Íå îòêëþ÷àòü îñíîâíûõ èãðîêîâ â ñèíãëå
6676 if not(gPlayers[a] is TBot) and (gGameSettings.GameType = GT_SINGLE) then
6677 continue;
6678 gPlayers[a].Lives := 0;
6679 gPlayers[a].Kill(K_SIMPLEKILL, 0, HIT_DISCON);
6680 g_Console_Add(Format(_lc[I_PLAYER_LEAVE], [gPlayers[a].Name]), True);
6681 g_Player_Remove(gPlayers[a].UID);
6682 g_Net_Slist_ServerPlayerLeaves();
6683 // Åñëè íå ïåðåìåøàòü, ïðè äîáàâëåíèè íîâûõ áîòîâ ïîÿâÿòñÿ ñòàðûå
6684 g_Bot_MixNames();
6685 end;
6686 end else
6687 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
6688 end
6689 else if cmd = 'kick_id' then
6690 begin
6691 if g_Game_IsServer and g_Game_IsNet then
6692 begin
6693 if Length(P) < 2 then
6694 begin
6695 g_Console_Add('kick_id <client ID>');
6696 Exit;
6697 end;
6698 if P[1] = '' then
6699 begin
6700 g_Console_Add('kick_id <client ID>');
6701 Exit;
6702 end;
6704 a := StrToIntDef(P[1], 0);
6705 if (NetClients <> nil) and (a <= High(NetClients)) then
6706 begin
6707 if NetClients[a].Used and (NetClients[a].Peer <> nil) then
6708 begin
6709 s := g_Net_ClientName_ByID(NetClients[a].ID);
6710 g_Net_Host_Kick(NetClients[a].ID, NET_DISC_KICK);
6711 g_Console_Add(Format(_lc[I_PLAYER_KICK], [s]));
6712 MH_SEND_GameEvent(NET_EV_PLAYER_KICK, 0, s);
6713 g_Net_Slist_ServerPlayerLeaves();
6714 end;
6715 end;
6716 end else
6717 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6718 end
6719 else if cmd = 'kick_pid' then
6720 begin
6721 if g_Game_IsServer and g_Game_IsNet then
6722 begin
6723 if Length(P) < 2 then
6724 begin
6725 g_Console_Add('kick_pid <player ID>');
6726 Exit;
6727 end;
6728 if P[1] = '' then
6729 begin
6730 g_Console_Add('kick_pid <player ID>');
6731 Exit;
6732 end;
6734 a := StrToIntDef(P[1], 0);
6735 pl := g_Net_Client_ByPlayer(a);
6736 if (pl <> nil) and pl^.Used and (pl^.Peer <> nil) then
6737 begin
6738 s := g_Net_ClientName_ByID(pl^.ID);
6739 g_Net_Host_Kick(pl^.ID, NET_DISC_KICK);
6740 g_Console_Add(Format(_lc[I_PLAYER_KICK], [s]));
6741 MH_SEND_GameEvent(NET_EV_PLAYER_KICK, 0, s);
6742 g_Net_Slist_ServerPlayerLeaves();
6743 end;
6744 end else
6745 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6746 end
6747 else if cmd = 'ban' then
6748 begin
6749 if g_Game_IsServer and g_Game_IsNet then
6750 begin
6751 if Length(P) < 2 then
6752 begin
6753 g_Console_Add('ban <name>');
6754 Exit;
6755 end;
6756 if P[1] = '' then
6757 begin
6758 g_Console_Add('ban <name>');
6759 Exit;
6760 end;
6762 pl := g_Net_Client_ByName(P[1]);
6763 if (pl <> nil) then
6764 g_Net_Host_Ban(pl, False)
6765 else
6766 g_Console_Add(Format(_lc[I_NET_ERR_NAME404], [P[1]]));
6767 end else
6768 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6769 end
6770 else if cmd = 'ban_id' then
6771 begin
6772 if g_Game_IsServer and g_Game_IsNet then
6773 begin
6774 if Length(P) < 2 then
6775 begin
6776 g_Console_Add('ban_id <client ID>');
6777 Exit;
6778 end;
6779 if P[1] = '' then
6780 begin
6781 g_Console_Add('ban_id <client ID>');
6782 Exit;
6783 end;
6785 a := StrToIntDef(P[1], 0);
6786 if (NetClients <> nil) and (a <= High(NetClients)) then
6787 if NetClients[a].Used and (NetClients[a].Peer <> nil) then
6788 g_Net_Host_Ban(pl, False);
6789 end else
6790 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6791 end
6792 else if cmd = 'ban_pid' then
6793 begin
6794 if g_Game_IsServer and g_Game_IsNet then
6795 begin
6796 if Length(P) < 2 then
6797 begin
6798 g_Console_Add('ban_pid <player ID>');
6799 Exit;
6800 end;
6801 if P[1] = '' then
6802 begin
6803 g_Console_Add('ban_pid <player ID>');
6804 Exit;
6805 end;
6807 a := StrToIntDef(P[1], 0);
6808 pl := g_Net_Client_ByPlayer(a);
6809 if (pl <> nil) and pl^.Used and (pl^.Peer <> nil) then
6810 g_Net_Host_Ban(pl, False);
6811 end else
6812 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6813 end
6814 else if cmd = 'permban' then
6815 begin
6816 if g_Game_IsServer and g_Game_IsNet then
6817 begin
6818 if Length(P) < 2 then
6819 begin
6820 g_Console_Add('permban <name>');
6821 Exit;
6822 end;
6823 if P[1] = '' then
6824 begin
6825 g_Console_Add('permban <name>');
6826 Exit;
6827 end;
6829 pl := g_Net_Client_ByName(P[1]);
6830 if (pl <> nil) then
6831 g_Net_Host_Ban(pl, True)
6832 else
6833 g_Console_Add(Format(_lc[I_NET_ERR_NAME404], [P[1]]));
6834 end else
6835 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6836 end
6837 else if cmd = 'permban_id' then
6838 begin
6839 if g_Game_IsServer and g_Game_IsNet then
6840 begin
6841 if Length(P) < 2 then
6842 begin
6843 g_Console_Add('permban_id <client ID>');
6844 Exit;
6845 end;
6846 if P[1] = '' then
6847 begin
6848 g_Console_Add('permban_id <client ID>');
6849 Exit;
6850 end;
6852 a := StrToIntDef(P[1], 0);
6853 if (NetClients <> nil) and (a <= High(NetClients)) then
6854 if NetClients[a].Used and (NetClients[a].Peer <> nil) then
6855 g_Net_Host_Ban(@NetClients[a], True);
6856 end else
6857 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6858 end
6859 else if cmd = 'permban_pid' then
6860 begin
6861 if g_Game_IsServer and g_Game_IsNet then
6862 begin
6863 if Length(P) < 2 then
6864 begin
6865 g_Console_Add('permban_pid <player ID>');
6866 Exit;
6867 end;
6868 if P[1] = '' then
6869 begin
6870 g_Console_Add('permban_pid <player ID>');
6871 Exit;
6872 end;
6874 a := StrToIntDef(P[1], 0);
6875 pl := g_Net_Client_ByPlayer(a);
6876 if (pl <> nil) and pl^.Used and (pl^.Peer <> nil) then
6877 g_Net_Host_Ban(pl, True);
6878 end else
6879 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6880 end
6881 else if cmd = 'permban_ip' then
6882 begin
6883 if g_Game_IsServer and g_Game_IsNet then
6884 begin
6885 if Length(P) < 2 then
6886 begin
6887 g_Console_Add('permban_ip <IP address>');
6888 Exit;
6889 end;
6890 if P[1] = '' then
6891 begin
6892 g_Console_Add('permban_ip <IP address>');
6893 Exit;
6894 end;
6896 g_Net_BanAddress(P[1]);
6897 g_Net_SaveBanList();
6898 g_Console_Add(Format(_lc[I_PLAYER_BAN], [P[1]]));
6899 end else
6900 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6901 end
6902 else if cmd = 'unban' then
6903 begin
6904 if g_Game_IsServer and g_Game_IsNet then
6905 begin
6906 if Length(P) < 2 then
6907 begin
6908 g_Console_Add('unban <IP Address>');
6909 Exit;
6910 end;
6911 if P[1] = '' then
6912 begin
6913 g_Console_Add('unban <IP Address>');
6914 Exit;
6915 end;
6917 if g_Net_UnbanAddress(P[1]) then
6918 begin
6919 g_Console_Add(Format(_lc[I_MSG_UNBAN_OK], [P[1]]));
6920 g_Net_SaveBanList();
6921 end else
6922 g_Console_Add(Format(_lc[I_MSG_UNBAN_FAIL], [P[1]]));
6923 end else
6924 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6925 end
6926 else if cmd = 'clientlist' then
6927 begin
6928 if g_Game_IsServer and g_Game_IsNet then
6929 begin
6930 b := 0;
6931 if NetClients <> nil then
6932 for a := Low(NetClients) to High(NetClients) do
6933 if NetClients[a].Used and (NetClients[a].Peer <> nil) then
6934 begin
6935 plr := g_Player_Get(NetClients[a].Player);
6936 if plr = nil then continue;
6937 Inc(b);
6938 g_Console_Add(Format('#%2d: %-15s | %s', [a,
6939 IpToStr(NetClients[a].Peer^.address.host), plr.Name]));
6940 end;
6941 if b = 0 then
6942 g_Console_Add(_lc[I_MSG_NOCLIENTS]);
6943 end else
6944 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6945 end
6946 else if cmd = 'connect' then
6947 begin
6948 if (NetMode = NET_NONE) then
6949 begin
6950 if Length(P) < 2 then
6951 begin
6952 g_Console_Add('connect <IP> [port] [password]');
6953 Exit;
6954 end;
6955 if P[1] = '' then
6956 begin
6957 g_Console_Add('connect <IP> [port] [password]');
6958 Exit;
6959 end;
6961 if Length(P) > 2 then
6962 prt := StrToIntDef(P[2], 25666)
6963 else
6964 prt := 25666;
6966 if Length(P) > 3 then
6967 pw := P[3]
6968 else
6969 pw := '';
6971 g_Game_StartClient(P[1], prt, pw);
6972 end;
6973 end
6974 else if cmd = 'disconnect' then
6975 begin
6976 if (NetMode = NET_CLIENT) then
6977 g_Net_Disconnect();
6978 end
6979 else if cmd = 'reconnect' then
6980 begin
6981 if (NetMode = NET_SERVER) then
6982 Exit;
6984 if (NetMode = NET_CLIENT) then
6985 begin
6986 g_Net_Disconnect();
6987 gExit := EXIT_SIMPLE;
6988 EndGame;
6989 end;
6991 //TODO: Use last successful password to reconnect, instead of ''
6992 g_Game_StartClient(NetClientIP, NetClientPort, '');
6993 end
6994 else if (cmd = 'addbot') or
6995 (cmd = 'bot_add') then
6996 begin
6997 case Length(P) of
6998 1: g_Bot_Add(TEAM_NONE, 2);
6999 2: g_Bot_Add(TEAM_NONE, StrToIntDef(P[1], 2));
7000 else
7001 g_Bot_Add(TEAM_NONE, StrToIntDef(P[1], 2), StrToIntDef(P[2], 100));
7002 end;
7003 end
7004 else if cmd = 'bot_addlist' then
7005 begin
7006 case Length(P) of
7007 1: g_Bot_AddList(TEAM_NONE, '');
7008 2: g_Bot_AddList(TEAM_NONE, P[1], StrToIntDef(P[1], -1));
7009 else
7010 if P[2] = 'red' then
7011 t := TEAM_RED
7012 else if P[2] = 'blue' then
7013 t := TEAM_BLUE
7014 else
7015 t := TEAM_NONE;
7017 if Length(P) = 3
7018 then g_Bot_AddList(t, P[1], StrToIntDef(P[1], -1))
7019 else g_Bot_AddList(t, P[1], StrToIntDef(P[1], -1), StrToIntDef(P[3], 100));
7020 end;
7021 end
7022 else if cmd = 'bot_removeall' then
7023 g_Bot_RemoveAll()
7024 else if cmd = 'chat' then
7025 begin
7026 if g_Game_IsNet then
7027 begin
7028 if Length(P) > 1 then
7029 begin
7030 for a := 1 to High(P) do
7031 chstr := chstr + P[a] + ' ';
7033 if Length(chstr) > 200 then SetLength(chstr, 200);
7035 if Length(chstr) < 1 then
7036 begin
7037 g_Console_Add('chat <text>');
7038 Exit;
7039 end;
7041 chstr := b_Text_Format(chstr);
7042 if g_Game_IsClient then
7043 MC_SEND_Chat(chstr, NET_CHAT_PLAYER)
7044 else
7045 MH_SEND_Chat(gPlayer1Settings.Name + ': ' + chstr, NET_CHAT_PLAYER);
7046 end
7047 else
7048 g_Console_Add('chat <text>');
7049 end else
7050 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
7051 end
7052 else if cmd = 'teamchat' then
7053 begin
7054 if g_Game_IsNet and (gGameSettings.GameMode in [GM_TDM, GM_CTF]) then
7055 begin
7056 if Length(P) > 1 then
7057 begin
7058 for a := 1 to High(P) do
7059 chstr := chstr + P[a] + ' ';
7061 if Length(chstr) > 200 then SetLength(chstr, 200);
7063 if Length(chstr) < 1 then
7064 begin
7065 g_Console_Add('teamchat <text>');
7066 Exit;
7067 end;
7069 chstr := b_Text_Format(chstr);
7070 if g_Game_IsClient then
7071 MC_SEND_Chat(chstr, NET_CHAT_TEAM)
7072 else
7073 MH_SEND_Chat(gPlayer1Settings.Name + ': ' + chstr, NET_CHAT_TEAM,
7074 gPlayer1Settings.Team);
7075 end
7076 else
7077 g_Console_Add('teamchat <text>');
7078 end else
7079 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
7080 end
7081 else if (cmd = 'an') or (cmd = 'announce') then
7082 begin
7083 if g_Game_IsNet then
7084 begin
7085 if Length(P) > 1 then
7086 begin
7087 for a := 1 to High(P) do
7088 chstr := chstr + P[a] + ' ';
7090 if Length(chstr) > 200 then SetLength(chstr, 200);
7092 if Length(chstr) < 1 then
7093 begin
7094 g_Console_Add('announce <text>');
7095 Exit;
7096 end;
7098 chstr := 'centerprint 100 ' + b_Text_Format(chstr);
7099 if g_Game_IsClient then
7100 MC_SEND_RCONCommand(chstr)
7101 else
7102 g_Console_Process(chstr, True);
7103 end
7104 else
7105 g_Console_Add('announce <text>');
7106 end else
7107 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
7108 end
7109 else if cmd = 'game' then
7110 begin
7111 if gGameSettings.GameType <> GT_NONE then
7112 begin
7113 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
7114 Exit;
7115 end;
7116 if Length(P) = 1 then
7117 begin
7118 g_Console_Add(cmd + ' <WAD> [MAP] [# players]');
7119 Exit;
7120 end;
7121 // game not started yet, load first map from some wad
7122 found := false;
7123 s := addWadExtension(P[1]);
7124 found := e_FindResource(AllMapDirs, s);
7125 P[1] := s;
7126 if found then
7127 begin
7128 P[1] := ExpandFileName(P[1]);
7129 // if map not choosed then set first map
7130 if Length(P) < 3 then
7131 begin
7132 SetLength(P, 3);
7133 P[2] := g_Game_GetFirstMap(P[1]);
7134 end;
7136 s := P[1] + ':\' + UpperCase(P[2]);
7138 if g_Map_Exist(s) then
7139 begin
7140 // start game
7141 g_Game_Free();
7142 with gGameSettings do
7143 begin
7144 Options := gsGameFlags;
7145 GameMode := g_Game_TextToMode(gsGameMode);
7146 if gSwitchGameMode <> GM_NONE then
7147 GameMode := gSwitchGameMode;
7148 if GameMode = GM_NONE then GameMode := GM_DM;
7149 if GameMode = GM_SINGLE then GameMode := GM_COOP;
7150 b := 1;
7151 if Length(P) >= 4 then
7152 b := StrToIntDef(P[3], 1);
7153 g_Game_StartCustom(s, GameMode, TimeLimit,
7154 ScoreLimit, MaxLives, Options, b);
7155 end;
7156 end
7157 else
7158 if P[2] = '' then
7159 g_Console_Add(Format(_lc[I_MSG_NO_MAPS], [P[1]]))
7160 else
7161 g_Console_Add(Format(_lc[I_MSG_NO_MAP_FALLBACK], [UpperCase(P[2]), P[1]]));
7162 end else
7163 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]));
7164 end
7165 else if cmd = 'host' then
7166 begin
7167 if gGameSettings.GameType <> GT_NONE then
7168 begin
7169 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
7170 Exit;
7171 end;
7172 if Length(P) < 4 then
7173 begin
7174 g_Console_Add(cmd + ' <listen IP> <port> <WAD> [MAP] [# players]');
7175 Exit;
7176 end;
7177 if not StrToIp(P[1], listen) then
7178 Exit;
7179 prt := StrToIntDef(P[2], 25666);
7181 s := addWadExtension(P[3]);
7182 found := e_FindResource(AllMapDirs, s);
7183 P[3] := s;
7184 if found then
7185 begin
7186 // get first map in wad, if not specified
7187 if Length(P) < 5 then
7188 begin
7189 SetLength(P, 5);
7190 P[4] := g_Game_GetFirstMap(P[1]);
7191 end;
7192 s := P[3] + ':\' + UpperCase(P[4]);
7193 if g_Map_Exist(s) then
7194 begin
7195 // start game
7196 g_Game_Free();
7197 with gGameSettings do
7198 begin
7199 Options := gsGameFlags;
7200 GameMode := g_Game_TextToMode(gsGameMode);
7201 if gSwitchGameMode <> GM_NONE then GameMode := gSwitchGameMode;
7202 if GameMode = GM_NONE then GameMode := GM_DM;
7203 if GameMode = GM_SINGLE then GameMode := GM_COOP;
7204 b := 0;
7205 if Length(P) >= 6 then
7206 b := StrToIntDef(P[5], 0);
7207 g_Game_StartServer(s, GameMode, TimeLimit, ScoreLimit, MaxLives, Options, b, listen, prt)
7208 end
7209 end
7210 else
7211 begin
7212 if P[4] = '' then
7213 g_Console_Add(Format(_lc[I_MSG_NO_MAPS], [P[3]]))
7214 else
7215 g_Console_Add(Format(_lc[I_MSG_NO_MAP_FALLBACK], [UpperCase(P[4]), P[3]]))
7216 end
7217 end
7218 else
7219 begin
7220 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[3]]))
7221 end
7222 end
7223 else if cmd = 'map' then
7224 begin
7225 if Length(P) = 1 then
7226 begin
7227 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
7228 begin
7229 g_Console_Add(cmd + ' <MAP>');
7230 g_Console_Add(cmd + ' <WAD> [MAP]')
7231 end
7232 else
7233 begin
7234 g_Console_Add(_lc[I_MSG_GM_UNAVAIL])
7235 end
7236 end
7237 else if not e_IsValidResourceName(P[1]) then
7238 begin
7239 g_Console_Add('wad name must not be absolute or relative');
7240 end
7241 else
7242 begin
7243 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
7244 begin
7245 if Length(P) < 3 then
7246 begin
7247 // first param is map or wad
7248 s := UpperCase(P[1]);
7249 if g_Map_Exist(gGameSettings.WAD + ':\' + s) then
7250 begin
7251 gExitByTrigger := False;
7252 if gGameOn then
7253 begin
7254 // already in game, finish current map
7255 gNextMap := s;
7256 gExit := EXIT_ENDLEVELCUSTOM;
7257 end
7258 else
7259 begin
7260 // intermission, so change map immediately
7261 g_Game_ChangeMap(s)
7262 end
7263 end
7264 else
7265 begin
7266 s := P[1];
7267 found := e_FindResource(AllMapDirs, s);
7268 P[1] := s;
7269 g_Console_Add(Format(_lc[I_MSG_NO_MAP_FALLBACK], [s, 'WAD ' + P[1]]));
7270 if found then
7271 begin
7272 // no such map, found wad
7273 pw := P[1];
7274 SetLength(P, 3);
7275 P[1] := ExpandFileName(pw);
7276 P[2] := g_Game_GetFirstMap(P[1]);
7277 s := P[1] + ':\' + P[2];
7278 if g_Map_Exist(s) then
7279 begin
7280 gExitByTrigger := False;
7281 if gGameOn then
7282 begin
7283 // already in game, finish current map
7284 gNextMap := s;
7285 gExit := EXIT_ENDLEVELCUSTOM
7286 end
7287 else
7288 begin
7289 // intermission, so change map immediately
7290 g_Game_ChangeMap(s)
7291 end
7292 end
7293 else
7294 begin
7295 if P[2] = '' then
7296 g_Console_Add(Format(_lc[I_MSG_NO_MAPS], [P[1]]))
7297 else
7298 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [P[2]]))
7299 end
7300 end
7301 else
7302 begin
7303 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]))
7304 end
7305 end;
7306 end
7307 else
7308 begin
7309 s := addWadExtension(P[1]);
7310 found := e_FindResource(AllMapDirs, s);
7311 P[1] := s;
7312 if found then
7313 begin
7314 P[2] := UpperCase(P[2]);
7315 s := P[1] + ':\' + P[2];
7316 if g_Map_Exist(s) then
7317 begin
7318 gExitByTrigger := False;
7319 if gGameOn then
7320 begin
7321 gNextMap := s;
7322 gExit := EXIT_ENDLEVELCUSTOM
7323 end
7324 else
7325 begin
7326 g_Game_ChangeMap(s)
7327 end
7328 end
7329 else
7330 begin
7331 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [P[2]]))
7332 end
7333 end
7334 else
7335 begin
7336 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]))
7337 end
7338 end
7339 end
7340 else
7341 begin
7342 g_Console_Add(_lc[I_MSG_GM_UNAVAIL])
7343 end
7344 end
7345 end
7346 else if cmd = 'nextmap' then
7347 begin
7348 if not(gGameOn or (gState = STATE_INTERCUSTOM)) then
7349 begin
7350 g_Console_Add(_lc[I_MSG_NOT_GAME])
7351 end
7352 else
7353 begin
7354 nm := True;
7355 if Length(P) = 1 then
7356 begin
7357 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
7358 begin
7359 g_Console_Add(cmd + ' <MAP>');
7360 g_Console_Add(cmd + ' <WAD> [MAP]');
7361 end
7362 else
7363 begin
7364 nm := False;
7365 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
7366 end;
7367 end
7368 else if not e_IsValidResourceName(P[1]) then
7369 begin
7370 g_Console_Add('wad name must not be absolute or relative');
7371 end
7372 else
7373 begin
7374 nm := False;
7375 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
7376 begin
7377 if Length(P) < 3 then
7378 begin
7379 // first param is map or wad
7380 s := UpperCase(P[1]);
7381 if g_Map_Exist(gGameSettings.WAD + ':\' + s) then
7382 begin
7383 // map founded
7384 gExitByTrigger := False;
7385 gNextMap := s;
7386 nm := True;
7387 end
7388 else
7389 begin
7390 // no such map, found wad
7391 pw := addWadExtension(P[1]);
7392 found := e_FindResource(MapDirs, pw);
7393 if not found then
7394 found := e_FindResource(WadDirs, pw);
7395 P[1] := pw;
7396 g_Console_Add(Format(_lc[I_MSG_NO_MAP_FALLBACK], [s, P[1]]));
7397 if found then
7398 begin
7399 // map not specified, select first map
7400 SetLength(P, 3);
7401 P[2] := g_Game_GetFirstMap(P[1]);
7402 s := P[1] + ':\' + P[2];
7403 if g_Map_Exist(s) then
7404 begin
7405 gExitByTrigger := False;
7406 gNextMap := s;
7407 nm := True
7408 end
7409 else
7410 begin
7411 if P[2] = '' then
7412 g_Console_Add(Format(_lc[I_MSG_NO_MAPS], [P[1]]))
7413 else
7414 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [P[2]]))
7415 end
7416 end
7417 else
7418 begin
7419 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]))
7420 end
7421 end
7422 end
7423 else
7424 begin
7425 // specified two params wad + map
7426 pw := addWadExtension(P[1]);
7427 found := e_FindResource(MapDirs, pw);
7428 if not found then
7429 found := e_FindResource(MapDirs, pw);
7430 P[1] := pw;
7431 if found then
7432 begin
7433 P[2] := UpperCase(P[2]);
7434 s := P[1] + ':\' + P[2];
7435 if g_Map_Exist(s) then
7436 begin
7437 gExitByTrigger := False;
7438 gNextMap := s;
7439 nm := True
7440 end
7441 else
7442 begin
7443 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [P[2]]))
7444 end
7445 end
7446 else
7447 begin
7448 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]))
7449 end
7450 end
7451 end
7452 else
7453 begin
7454 g_Console_Add(_lc[I_MSG_GM_UNAVAIL])
7455 end
7456 end;
7457 if nm then
7458 begin
7459 if gNextMap = '' then
7460 g_Console_Add(_lc[I_MSG_NEXTMAP_UNSET])
7461 else
7462 g_Console_Add(Format(_lc[I_MSG_NEXTMAP_SET], [gNextMap]))
7463 end
7464 end
7465 end
7466 else if (cmd = 'endmap') or (cmd = 'goodbye') then
7467 begin
7468 if not gGameOn then
7469 begin
7470 g_Console_Add(_lc[I_MSG_NOT_GAME])
7471 end
7472 else
7473 begin
7474 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
7475 begin
7476 gExitByTrigger := False;
7477 // next map not specified, try to find trigger EXIT
7478 if (gNextMap = '') and (gTriggers <> nil) then
7479 begin
7480 for a := 0 to High(gTriggers) do
7481 begin
7482 if gTriggers[a].TriggerType = TRIGGER_EXIT then
7483 begin
7484 gExitByTrigger := True;
7485 //gNextMap := gTriggers[a].Data.MapName;
7486 gNextMap := gTriggers[a].tgcMap;
7487 Break
7488 end
7489 end
7490 end;
7491 if gNextMap = '' then
7492 gNextMap := g_Game_GetNextMap();
7493 if not isWadPath(gNextMap) then
7494 s := gGameSettings.WAD + ':\' + gNextMap
7495 else
7496 s := gNextMap;
7497 if g_Map_Exist(s) then
7498 gExit := EXIT_ENDLEVELCUSTOM
7499 else
7500 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [gNextMap]))
7501 end
7502 else
7503 begin
7504 g_Console_Add(_lc[I_MSG_GM_UNAVAIL])
7505 end
7506 end
7507 end
7508 else if (cmd = 'event') then
7509 begin
7510 if (Length(P) <= 1) then
7511 begin
7512 for a := 0 to High(gEvents) do
7513 if gEvents[a].Command = '' then
7514 g_Console_Add(gEvents[a].Name + ' <none>')
7515 else
7516 g_Console_Add(gEvents[a].Name + ' "' + gEvents[a].Command + '"');
7517 Exit;
7518 end;
7519 if (Length(P) = 2) then
7520 begin
7521 for a := 0 to High(gEvents) do
7522 if gEvents[a].Name = P[1] then
7523 if gEvents[a].Command = '' then
7524 g_Console_Add(gEvents[a].Name + ' <none>')
7525 else
7526 g_Console_Add(gEvents[a].Name + ' "' + gEvents[a].Command + '"');
7527 Exit;
7528 end;
7529 for a := 0 to High(gEvents) do
7530 if gEvents[a].Name = P[1] then
7531 begin
7532 gEvents[a].Command := '';
7533 for b := 2 to High(P) do
7534 if Pos(' ', P[b]) = 0 then
7535 gEvents[a].Command := gEvents[a].Command + ' ' + P[b]
7536 else
7537 gEvents[a].Command := gEvents[a].Command + ' "' + P[b] + '"';
7538 gEvents[a].Command := Trim(gEvents[a].Command);
7539 Exit;
7540 end;
7541 end
7542 else if cmd = 'suicide' then
7543 begin
7544 if gGameOn then
7545 begin
7546 if g_Game_IsClient then
7547 MC_SEND_CheatRequest(NET_CHEAT_SUICIDE)
7548 else
7549 begin
7550 if gPlayer1 <> nil then
7551 gPlayer1.Damage(SUICIDE_DAMAGE, gPlayer1.UID, 0, 0, HIT_SELF);
7552 if gPlayer2 <> nil then
7553 gPlayer2.Damage(SUICIDE_DAMAGE, gPlayer2.UID, 0, 0, HIT_SELF);
7554 end;
7555 end;
7556 end
7557 else if cmd = 'screenshot' then
7558 begin
7559 g_TakeScreenShot()
7560 end
7561 else if (cmd = 'weapnext') or (cmd = 'weapprev') then
7562 begin
7563 a := 1 - (ord(cmd[5]) - ord('n'));
7564 if a = -1 then
7565 gWeaponAction[0, WP_PREV] := True;
7566 if a = 1 then
7567 gWeaponAction[0, WP_NEXT] := True;
7568 end
7569 else if cmd = 'weapon' then
7570 begin
7571 if Length(p) = 2 then
7572 begin
7573 a := WP_FIRST + StrToIntDef(p[1], 0) - 1;
7574 if (a >= WP_FIRST) and (a <= WP_LAST) then
7575 gSelectWeapon[0, a] := True
7576 end
7577 end
7578 else if (cmd = 'p1_weapnext') or (cmd = 'p1_weapprev')
7579 or (cmd = 'p2_weapnext') or (cmd = 'p2_weapprev') then
7580 begin
7581 a := 1 - (ord(cmd[8]) - ord('n'));
7582 b := ord(cmd[2]) - ord('1');
7583 if a = -1 then
7584 gWeaponAction[b, WP_PREV] := True;
7585 if a = 1 then
7586 gWeaponAction[b, WP_NEXT] := True;
7587 end
7588 else if (cmd = 'p1_weapon') or (cmd = 'p2_weapon') then
7589 begin
7590 if Length(p) = 2 then
7591 begin
7592 a := WP_FIRST + StrToIntDef(p[1], 0) - 1;
7593 b := ord(cmd[2]) - ord('1');
7594 if (a >= WP_FIRST) and (a <= WP_LAST) then
7595 gSelectWeapon[b, a] := True
7596 end
7597 end
7598 else if (cmd = 'p1_weapbest') or (cmd = 'p2_weapbest') then
7599 begin
7600 b := ord(cmd[2]) - ord('1');
7601 if b = 0 then
7602 gSelectWeapon[b, gPlayer1.GetMorePrefered()] := True
7603 else
7604 gSelectWeapon[b, gPlayer2.GetMorePrefered()] := True;
7605 end
7606 else if (cmd = 'dropflag') then
7607 begin
7608 if g_Game_IsServer then
7609 begin
7610 if gPlayer2 <> nil then gPlayer2.TryDropFlag();
7611 if gPlayer1 <> nil then gPlayer1.TryDropFlag();
7612 end
7613 else
7614 MC_SEND_CheatRequest(NET_CHEAT_DROPFLAG);
7615 end
7616 else if (cmd = 'p1_dropflag') or (cmd = 'p2_dropflag') then
7617 begin
7618 b := ord(cmd[2]) - ord('1');
7619 if g_Game_IsServer then
7620 begin
7621 if (b = 1) and (gPlayer2 <> nil) then gPlayer2.TryDropFlag()
7622 else if (b = 0) and (gPlayer1 <> nil) then gPlayer1.TryDropFlag();
7623 end
7624 else
7625 MC_SEND_CheatRequest(NET_CHEAT_DROPFLAG);
7626 end
7627 // Êîìàíäû Ñâîåé èãðû:
7628 else if gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT] then
7629 begin
7630 if cmd = 'bot_addred' then
7631 begin
7632 if Length(P) > 1 then
7633 g_Bot_Add(TEAM_RED, StrToIntDef(P[1], 2))
7634 else
7635 g_Bot_Add(TEAM_RED, 2);
7636 end
7637 else if cmd = 'bot_addblue' then
7638 begin
7639 if Length(P) > 1 then
7640 g_Bot_Add(TEAM_BLUE, StrToIntDef(P[1], 2))
7641 else
7642 g_Bot_Add(TEAM_BLUE, 2);
7643 end
7644 else if cmd = 'spectate' then
7645 begin
7646 if not gGameOn then
7647 Exit;
7648 g_Game_Spectate();
7649 end
7650 else if cmd = 'say' then
7651 begin
7652 if g_Game_IsServer and g_Game_IsNet then
7653 begin
7654 if Length(P) > 1 then
7655 begin
7656 chstr := '';
7657 for a := 1 to High(P) do
7658 chstr := chstr + P[a] + ' ';
7660 if Length(chstr) > 200 then SetLength(chstr, 200);
7662 if Length(chstr) < 1 then
7663 begin
7664 g_Console_Add('say <text>');
7665 Exit;
7666 end;
7668 chstr := b_Text_Format(chstr);
7669 MH_SEND_Chat(chstr, NET_CHAT_PLAYER);
7670 end
7671 else g_Console_Add('say <text>');
7672 end else
7673 g_Console_Add(_lc[I_MSG_SERVERONLY]);
7674 end
7675 else if cmd = 'tell' then
7676 begin
7677 if g_Game_IsServer and g_Game_IsNet then
7678 begin
7679 if (Length(P) > 2) and (P[1] <> '') then
7680 begin
7681 chstr := '';
7682 for a := 2 to High(P) do
7683 chstr := chstr + P[a] + ' ';
7685 if Length(chstr) > 200 then SetLength(chstr, 200);
7687 if Length(chstr) < 1 then
7688 begin
7689 g_Console_Add('tell <playername> <text>');
7690 Exit;
7691 end;
7693 pl := g_Net_Client_ByName(P[1]);
7694 if pl <> nil then
7695 MH_SEND_Chat(b_Text_Format(chstr), NET_CHAT_PLAYER, pl^.ID)
7696 else
7697 g_Console_Add(Format(_lc[I_NET_ERR_NAME404], [P[1]]));
7698 end
7699 else g_Console_Add('tell <playername> <text>');
7700 end else
7701 g_Console_Add(_lc[I_MSG_SERVERONLY]);
7702 end
7703 else if cmd = 'centerprint' then
7704 begin
7705 if (Length(P) > 2) and (P[1] <> '') then
7706 begin
7707 chstr := '';
7708 for a := 2 to High(P) do
7709 chstr := chstr + P[a] + ' ';
7711 if Length(chstr) > 200 then SetLength(chstr, 200);
7713 if Length(chstr) < 1 then
7714 begin
7715 g_Console_Add('centerprint <timeout> <text>');
7716 Exit;
7717 end;
7719 a := StrToIntDef(P[1], 100);
7720 chstr := b_Text_Format(chstr);
7721 g_Game_Message(chstr, a);
7722 if g_Game_IsNet and g_Game_IsServer then
7723 MH_SEND_GameEvent(NET_EV_BIGTEXT, a, chstr);
7724 end
7725 else g_Console_Add('centerprint <timeout> <text>');
7726 end
7727 else if (cmd = 'overtime') and not g_Game_IsClient then
7728 begin
7729 if (Length(P) = 1) or (StrToIntDef(P[1], -1) <= 0) then
7730 Exit;
7731 // Äîïîëíèòåëüíîå âðåìÿ:
7732 gGameSettings.TimeLimit := (gTime - gGameStartTime) div 1000 + Word(StrToIntDef(P[1], 0));
7734 g_Console_Add(Format(_lc[I_MSG_TIME_LIMIT],
7735 [gGameSettings.TimeLimit div 3600,
7736 (gGameSettings.TimeLimit div 60) mod 60,
7737 gGameSettings.TimeLimit mod 60]));
7738 if g_Game_IsNet then MH_SEND_GameSettings;
7739 end
7740 else if (cmd = 'rcon_password') and g_Game_IsClient then
7741 begin
7742 if (Length(P) <= 1) then
7743 g_Console_Add('rcon_password <password>')
7744 else
7745 MC_SEND_RCONPassword(P[1]);
7746 end
7747 else if cmd = 'rcon' then
7748 begin
7749 if g_Game_IsClient then
7750 begin
7751 if Length(P) > 1 then
7752 begin
7753 chstr := '';
7754 for a := 1 to High(P) do
7755 chstr := chstr + P[a] + ' ';
7757 if Length(chstr) > 200 then SetLength(chstr, 200);
7759 if Length(chstr) < 1 then
7760 begin
7761 g_Console_Add('rcon <command>');
7762 Exit;
7763 end;
7765 MC_SEND_RCONCommand(chstr);
7766 end
7767 else g_Console_Add('rcon <command>');
7768 end;
7769 end
7770 else if cmd = 'ready' then
7771 begin
7772 if g_Game_IsServer and (gLMSRespawn = LMS_RESPAWN_WARMUP) then
7773 gLMSRespawnTime := gTime + 100;
7774 end
7775 else if (cmd = 'callvote') and g_Game_IsNet then
7776 begin
7777 if Length(P) > 1 then
7778 begin
7779 chstr := '';
7780 for a := 1 to High(P) do begin
7781 if a > 1 then chstr := chstr + ' ';
7782 chstr := chstr + P[a];
7783 end;
7785 if Length(chstr) > 200 then SetLength(chstr, 200);
7787 if Length(chstr) < 1 then
7788 begin
7789 g_Console_Add('callvote <command>');
7790 Exit;
7791 end;
7793 if g_Game_IsClient then
7794 MC_SEND_Vote(True, chstr)
7795 else
7796 g_Game_StartVote(chstr, gPlayer1Settings.Name);
7797 g_Console_Process('vote', True);
7798 end
7799 else
7800 g_Console_Add('callvote <command>');
7801 end
7802 else if (cmd = 'vote') and g_Game_IsNet then
7803 begin
7804 if g_Game_IsClient then
7805 MC_SEND_Vote(False)
7806 else if gVoteInProgress then
7807 begin
7808 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
7809 a := Floor((NetClientCount+1)/2.0) + 1
7810 else
7811 a := Floor(NetClientCount/2.0) + 1;
7812 if gVoted then
7813 begin
7814 Dec(gVoteCount);
7815 gVoted := False;
7816 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_REVOKED], [gPlayer1Settings.Name, gVoteCount, a]), True);
7817 MH_SEND_VoteEvent(NET_VE_REVOKE, gPlayer1Settings.Name, 'a', gVoteCount, a);
7818 end
7819 else
7820 begin
7821 Inc(gVoteCount);
7822 gVoted := True;
7823 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_VOTE], [gPlayer1Settings.Name, gVoteCount, a]), True);
7824 MH_SEND_VoteEvent(NET_VE_VOTE, gPlayer1Settings.Name, 'a', gVoteCount, a);
7825 g_Game_CheckVote;
7826 end;
7827 end;
7828 end
7829 end;
7830 end;
7832 procedure SystemCommands(P: SSArray);
7833 var
7834 cmd: string;
7835 begin
7836 cmd := LowerCase(P[0]);
7837 case cmd of
7838 'exit', 'quit':
7839 begin
7840 g_Game_Free();
7841 g_Game_Quit();
7842 end;
7843 'r_reset':
7844 begin
7845 gRC_Width := Max(1, gRC_Width);
7846 gRC_Height := Max(1, gRC_Height);
7847 gBPP := Max(1, gBPP);
7848 if sys_SetDisplayMode(gRC_Width, gRC_Height, gBPP, gRC_FullScreen, gRC_Maximized) = True then
7849 e_LogWriteln('resolution changed')
7850 else
7851 e_LogWriteln('resolution not changed');
7852 sys_EnableVSync(gVSync);
7853 end;
7854 'r_maxfps':
7855 begin
7856 if Length(p) = 2 then
7857 begin
7858 gMaxFPS := StrToIntDef(p[1], gMaxFPS);
7859 if gMaxFPS > 0 then
7860 gFrameTime := 1000 div gMaxFPS
7861 else
7862 gFrameTime := 0;
7863 end;
7864 e_LogWritefln('r_maxfps %d', [gMaxFPS]);
7865 end;
7866 'g_language':
7867 begin
7868 if Length(p) = 2 then
7869 begin
7870 gAskLanguage := true;
7871 gLanguage := LANGUAGE_ENGLISH;
7872 case LowerCase(p[1]) of
7873 'english':
7874 begin
7875 gAskLanguage := false;
7876 gLanguage := LANGUAGE_ENGLISH;
7877 end;
7878 'russian':
7879 begin
7880 gAskLanguage := false;
7881 gLanguage := LANGUAGE_RUSSIAN;
7882 end;
7883 'ask':
7884 begin
7885 gAskLanguage := true;
7886 gLanguage := LANGUAGE_ENGLISH;
7887 end;
7888 end;
7889 g_Language_Set(gLanguage);
7890 end
7891 else
7892 begin
7893 e_LogWritefln('usage: %s <English|Russian|Ask>', [cmd]);
7894 end
7895 end;
7896 end;
7897 end;
7899 procedure g_TakeScreenShot(Filename: string = '');
7900 var s: TStream; t: TDateTime; dir, date, name: String;
7901 begin
7902 if e_NoGraphics then Exit;
7903 try
7904 dir := e_GetWriteableDir(ScreenshotDirs);
7906 if Filename = '' then
7907 begin
7908 t := Now;
7909 DateTimeToString(date, 'yyyy-mm-dd-hh-nn-ss', t);
7910 Filename := 'screenshot-' + date;
7911 end;
7913 name := e_CatPath(dir, Filename + '.png');
7914 s := createDiskFile(name);
7915 try
7916 e_MakeScreenshot(s, gWinSizeX, gWinSizeY);
7917 s.Free;
7918 g_Console_Add(Format(_lc[I_CONSOLE_SCREENSHOT], [name]))
7919 except
7920 g_Console_Add(Format(_lc[I_CONSOLE_ERROR_WRITE], [name]));
7921 s.Free;
7922 DeleteFile(name)
7923 end
7924 except
7925 g_Console_Add('oh shit, i can''t create screenshot!')
7926 end
7927 end;
7929 procedure g_Game_InGameMenu(Show: Boolean);
7930 begin
7931 if (g_ActiveWindow = nil) and Show then
7932 begin
7933 if gGameSettings.GameType = GT_SINGLE then
7934 g_GUI_ShowWindow('GameSingleMenu')
7935 else
7936 begin
7937 if g_Game_IsClient then
7938 g_GUI_ShowWindow('GameClientMenu')
7939 else
7940 if g_Game_IsNet then
7941 g_GUI_ShowWindow('GameServerMenu')
7942 else
7943 g_GUI_ShowWindow('GameCustomMenu');
7944 end;
7945 g_Sound_PlayEx('MENU_OPEN');
7947 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
7948 if (not g_Game_IsNet) then
7949 g_Game_Pause(True);
7950 end
7951 else
7952 if (g_ActiveWindow <> nil) and (not Show) then
7953 begin
7954 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
7955 if (not g_Game_IsNet) then
7956 g_Game_Pause(False);
7957 end;
7958 end;
7960 procedure g_Game_Pause (Enable: Boolean);
7961 var
7962 oldPause: Boolean;
7963 begin
7964 if not gGameOn then exit;
7966 if not (gGameSettings.GameType in [GT_SINGLE, GT_CUSTOM]) then exit;
7968 oldPause := gPause;
7969 gPauseMain := Enable;
7971 if (gPause <> oldPause) then g_Game_PauseAllSounds(gPause);
7972 end;
7974 procedure g_Game_HolmesPause (Enable: Boolean);
7975 var
7976 oldPause: Boolean;
7977 begin
7978 if not gGameOn then exit;
7979 if not (gGameSettings.GameType in [GT_SINGLE, GT_CUSTOM]) then exit;
7981 oldPause := gPause;
7982 gPauseHolmes := Enable;
7984 if (gPause <> oldPause) then g_Game_PauseAllSounds(gPause);
7985 end;
7987 procedure g_Game_PauseAllSounds(Enable: Boolean);
7988 var
7989 i: Integer;
7990 begin
7991 // Òðèããåðû:
7992 if gTriggers <> nil then
7993 for i := 0 to High(gTriggers) do
7994 with gTriggers[i] do
7995 if (TriggerType = TRIGGER_SOUND) and
7996 (Sound <> nil) and
7997 Sound.IsPlaying() then
7998 begin
7999 Sound.Pause(Enable);
8000 end;
8002 // Çâóêè èãðîêîâ:
8003 if gPlayers <> nil then
8004 for i := 0 to High(gPlayers) do
8005 if gPlayers[i] <> nil then
8006 gPlayers[i].PauseSounds(Enable);
8008 // Ìóçûêà:
8009 if gMusic <> nil then
8010 gMusic.Pause(Enable);
8011 end;
8013 procedure g_Game_StopAllSounds(all: Boolean);
8014 var
8015 i: Integer;
8016 begin
8017 if gTriggers <> nil then
8018 for i := 0 to High(gTriggers) do
8019 with gTriggers[i] do
8020 if (TriggerType = TRIGGER_SOUND) and
8021 (Sound <> nil) then
8022 Sound.Stop();
8024 if gMusic <> nil then
8025 gMusic.Stop();
8027 if all then
8028 e_StopChannels();
8029 end;
8031 procedure g_Game_UpdateTriggerSounds;
8032 var i: Integer;
8033 begin
8034 if gTriggers <> nil then
8035 for i := 0 to High(gTriggers) do
8036 with gTriggers[i] do
8037 if (TriggerType = TRIGGER_SOUND) and (Sound <> nil) and tgcLocal and Sound.IsPlaying() then
8038 Sound.SetCoordsRect(X, Y, Width, Height, tgcVolume / 255.0)
8039 end;
8041 function g_Game_IsWatchedPlayer(UID: Word): Boolean;
8042 begin
8043 Result := False;
8044 if (gPlayer1 <> nil) and (gPlayer1.UID = UID) then
8045 begin
8046 Result := True;
8047 Exit;
8048 end;
8049 if (gPlayer2 <> nil) and (gPlayer2.UID = UID) then
8050 begin
8051 Result := True;
8052 Exit;
8053 end;
8054 if gSpectMode <> SPECT_PLAYERS then
8055 Exit;
8056 if gSpectPID1 = UID then
8057 begin
8058 Result := True;
8059 Exit;
8060 end;
8061 if gSpectViewTwo and (gSpectPID2 = UID) then
8062 begin
8063 Result := True;
8064 Exit;
8065 end;
8066 end;
8068 function g_Game_IsWatchedTeam(Team: Byte): Boolean;
8069 var
8070 Pl: TPlayer;
8071 begin
8072 Result := False;
8073 if (gPlayer1 <> nil) and (gPlayer1.Team = Team) then
8074 begin
8075 Result := True;
8076 Exit;
8077 end;
8078 if (gPlayer2 <> nil) and (gPlayer2.Team = Team) then
8079 begin
8080 Result := True;
8081 Exit;
8082 end;
8083 if gSpectMode <> SPECT_PLAYERS then
8084 Exit;
8085 Pl := g_Player_Get(gSpectPID1);
8086 if (Pl <> nil) and (Pl.Team = Team) then
8087 begin
8088 Result := True;
8089 Exit;
8090 end;
8091 if gSpectViewTwo then
8092 begin
8093 Pl := g_Player_Get(gSpectPID2);
8094 if (Pl <> nil) and (Pl.Team = Team) then
8095 begin
8096 Result := True;
8097 Exit;
8098 end;
8099 end;
8100 end;
8102 procedure g_Game_Message(Msg: string; Time: Word);
8103 begin
8104 MessageLineLength := (gScreenWidth - 204) div e_CharFont_GetMaxWidth(gMenuFont);
8105 MessageText := b_Text_Wrap(b_Text_Format(Msg), MessageLineLength);
8106 MessageTime := Time;
8107 end;
8109 procedure g_Game_ChatSound(Text: String; Taunt: Boolean = True);
8110 const
8111 punct: Array[0..13] of String =
8112 ('.', ',', ':', ';', '!', '?', '(', ')', '''', '"', '/', '\', '*', '^');
8113 var
8114 i, j: Integer;
8115 ok: Boolean;
8116 fpText: String;
8118 function IsPunctuation(S: String): Boolean;
8119 var
8120 i: Integer;
8121 begin
8122 Result := False;
8123 if Length(S) <> 1 then
8124 Exit;
8125 for i := Low(punct) to High(punct) do
8126 if S = punct[i] then
8127 begin
8128 Result := True;
8129 break;
8130 end;
8131 end;
8132 function FilterPunctuation(S: String): String;
8133 var
8134 i: Integer;
8135 begin
8136 for i := Low(punct) to High(punct) do
8137 S := StringReplace(S, punct[i], ' ', [rfReplaceAll]);
8138 Result := S;
8139 end;
8140 begin
8141 ok := False;
8143 if gUseChatSounds and Taunt and (gChatSounds <> nil) and (Pos(': ', Text) > 0) then
8144 begin
8145 // remove player name
8146 Delete(Text, 1, Pos(': ', Text) + 2 - 1);
8147 // for FullWord check
8148 Text := toLowerCase1251(' ' + Text + ' ');
8149 fpText := FilterPunctuation(Text);
8151 for i := 0 to Length(gChatSounds) - 1 do
8152 begin
8153 ok := True;
8154 for j := 0 to Length(gChatSounds[i].Tags) - 1 do
8155 begin
8156 if gChatSounds[i].FullWord and (not IsPunctuation(gChatSounds[i].Tags[j])) then
8157 ok := Pos(' ' + gChatSounds[i].Tags[j] + ' ', fpText) > 0
8158 else
8159 ok := Pos(gChatSounds[i].Tags[j], Text) > 0;
8160 if not ok then
8161 break;
8162 end;
8163 if ok then
8164 begin
8165 gChatSounds[i].Sound.Play();
8166 break;
8167 end;
8168 end;
8169 end;
8170 if not ok then
8171 g_Sound_PlayEx('SOUND_GAME_RADIO');
8172 end;
8174 procedure g_Game_Announce_GoodShot(SpawnerUID: Word);
8175 var
8176 a: Integer;
8177 begin
8178 case gAnnouncer of
8179 ANNOUNCE_NONE:
8180 Exit;
8181 ANNOUNCE_ME,
8182 ANNOUNCE_MEPLUS:
8183 if not g_Game_IsWatchedPlayer(SpawnerUID) then
8184 Exit;
8185 end;
8186 for a := 0 to 3 do
8187 if goodsnd[a].IsPlaying() then
8188 Exit;
8190 goodsnd[Random(4)].Play();
8191 end;
8193 procedure g_Game_Announce_KillCombo(Param: Integer);
8194 var
8195 UID: Word;
8196 c, n: Byte;
8197 Pl: TPlayer;
8198 Name: String;
8199 begin
8200 UID := Param and $FFFF;
8201 c := Param shr 16;
8202 if c < 2 then
8203 Exit;
8205 Pl := g_Player_Get(UID);
8206 if Pl = nil then
8207 Name := '?'
8208 else
8209 Name := Pl.Name;
8211 case c of
8212 2: begin
8213 n := 0;
8214 g_Console_Add(Format(_lc[I_PLAYER_KILL_2X], [Name]), True);
8215 end;
8216 3: begin
8217 n := 1;
8218 g_Console_Add(Format(_lc[I_PLAYER_KILL_3X], [Name]), True);
8219 end;
8220 4: begin
8221 n := 2;
8222 g_Console_Add(Format(_lc[I_PLAYER_KILL_4X], [Name]), True);
8223 end;
8224 else begin
8225 n := 3;
8226 g_Console_Add(Format(_lc[I_PLAYER_KILL_MX], [Name]), True);
8227 end;
8228 end;
8230 case gAnnouncer of
8231 ANNOUNCE_NONE:
8232 Exit;
8233 ANNOUNCE_ME:
8234 if not g_Game_IsWatchedPlayer(UID) then
8235 Exit;
8236 ANNOUNCE_MEPLUS:
8237 if (not g_Game_IsWatchedPlayer(UID)) and (c < 4) then
8238 Exit;
8239 end;
8241 if killsnd[n].IsPlaying() then
8242 killsnd[n].Stop();
8243 killsnd[n].Play();
8244 end;
8246 procedure g_Game_Announce_BodyKill(SpawnerUID: Word);
8247 var
8248 a: Integer;
8249 begin
8250 case gAnnouncer of
8251 ANNOUNCE_NONE:
8252 Exit;
8253 ANNOUNCE_ME:
8254 if not g_Game_IsWatchedPlayer(SpawnerUID) then
8255 Exit;
8256 end;
8257 for a := 0 to 2 do
8258 if hahasnd[a].IsPlaying() then
8259 Exit;
8261 hahasnd[Random(3)].Play();
8262 end;
8264 procedure g_Game_Effect_Bubbles (fX, fY: Integer; count: Word; devX, devY: Byte; Silent: Boolean);
8265 begin
8266 g_GFX_Bubbles(fX, fY, count, devX, devY);
8267 if not Silent then if Random(2) = 0
8268 then g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', fX, fY)
8269 else g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', fX, fY);
8270 end;
8272 procedure g_Game_StartVote(Command, Initiator: string);
8273 var
8274 Need: Integer;
8275 begin
8276 if not gVotesEnabled then Exit;
8277 if gGameSettings.GameType <> GT_SERVER then Exit;
8278 if gVoteInProgress or gVotePassed then
8279 begin
8280 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_INPROGRESS], [gVoteCommand]), True);
8281 MH_SEND_VoteEvent(NET_VE_INPROGRESS, gVoteCommand);
8282 Exit;
8283 end;
8284 gVoteInProgress := True;
8285 gVotePassed := False;
8286 gVoteTimer := gTime + gVoteTimeout * 1000;
8287 gVoteCount := 0;
8288 gVoted := False;
8289 gVoteCommand := Command;
8291 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
8292 Need := Floor((NetClientCount+1)/2.0)+1
8293 else
8294 Need := Floor(NetClientCount/2.0)+1;
8295 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_STARTED], [Initiator, Command, Need]), True);
8296 MH_SEND_VoteEvent(NET_VE_STARTED, Initiator, Command, Need);
8297 end;
8299 procedure g_Game_CheckVote;
8300 var
8301 I, Need: Integer;
8302 begin
8303 if gGameSettings.GameType <> GT_SERVER then Exit;
8304 if not gVoteInProgress then Exit;
8306 if (gTime >= gVoteTimer) then
8307 begin
8308 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
8309 Need := Floor((NetClientCount+1)/2.0) + 1
8310 else
8311 Need := Floor(NetClientCount/2.0) + 1;
8312 if gVoteCount >= Need then
8313 begin
8314 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_PASSED], [gVoteCommand]), True);
8315 MH_SEND_VoteEvent(NET_VE_PASSED, gVoteCommand);
8316 gVotePassed := True;
8317 gVoteCmdTimer := gTime + 5000;
8318 end
8319 else
8320 begin
8321 g_Console_Add(_lc[I_MESSAGE_VOTE_FAILED], True);
8322 MH_SEND_VoteEvent(NET_VE_FAILED);
8323 end;
8324 if NetClients <> nil then
8325 for I := Low(NetClients) to High(NetClients) do
8326 if NetClients[i].Used then
8327 NetClients[i].Voted := False;
8328 gVoteInProgress := False;
8329 gVoted := False;
8330 gVoteCount := 0;
8331 end
8332 else
8333 begin
8334 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
8335 Need := Floor((NetClientCount+1)/2.0) + 1
8336 else
8337 Need := Floor(NetClientCount/2.0) + 1;
8338 if gVoteCount >= Need then
8339 begin
8340 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_PASSED], [gVoteCommand]), True);
8341 MH_SEND_VoteEvent(NET_VE_PASSED, gVoteCommand);
8342 gVoteInProgress := False;
8343 gVotePassed := True;
8344 gVoteCmdTimer := gTime + 5000;
8345 gVoted := False;
8346 gVoteCount := 0;
8347 if NetClients <> nil then
8348 for I := Low(NetClients) to High(NetClients) do
8349 if NetClients[i].Used then
8350 NetClients[i].Voted := False;
8351 end;
8352 end;
8353 end;
8355 procedure g_Game_LoadMapList(FileName: string);
8356 var
8357 ListFile: TextFile;
8358 s: string;
8359 begin
8360 MapList := nil;
8361 MapIndex := -1;
8363 if not FileExists(FileName) then Exit;
8365 AssignFile(ListFile, FileName);
8366 Reset(ListFile);
8367 while not EOF(ListFile) do
8368 begin
8369 ReadLn(ListFile, s);
8371 s := Trim(s);
8372 if s = '' then Continue;
8374 SetLength(MapList, Length(MapList)+1);
8375 MapList[High(MapList)] := s;
8376 end;
8377 CloseFile(ListFile);
8378 end;
8380 procedure g_Game_SetDebugMode();
8381 begin
8382 gDebugMode := True;
8383 // ×èòû (äàæå â ñâîåé èãðå):
8384 gCheats := True;
8385 end;
8387 procedure g_Game_SetLoadingText(Text: String; Max: Integer; reWrite: Boolean);
8388 var
8389 i: Word;
8390 begin
8391 if Length(LoadingStat.Msgs) = 0 then
8392 Exit;
8394 with LoadingStat do
8395 begin
8396 if not reWrite then
8397 begin // Ïåðåõîäèì íà ñëåäóþùóþ ñòðîêó èëè ñêðîëëèðóåì:
8398 if NextMsg = Length(Msgs) then
8399 begin // scroll
8400 for i := 0 to High(Msgs)-1 do
8401 Msgs[i] := Msgs[i+1];
8402 end
8403 else
8404 Inc(NextMsg);
8405 end else
8406 if NextMsg = 0 then
8407 Inc(NextMsg);
8409 Msgs[NextMsg-1] := Text;
8410 CurValue := 0;
8411 MaxValue := Max;
8412 ShowCount := 0;
8413 PBarWasHere := false;
8414 end;
8416 g_ActiveWindow := nil;
8417 ProcessLoading(True);
8418 end;
8420 procedure g_Game_StepLoading(Value: Integer = -1);
8421 begin
8422 with LoadingStat do
8423 begin
8424 if Value = -1 then
8425 begin
8426 Inc(CurValue);
8427 Inc(ShowCount);
8428 end
8429 else
8430 CurValue := Value;
8432 if (ShowCount > LOADING_SHOW_STEP) or (Value > -1) then
8433 begin
8434 ShowCount := 0;
8435 ProcessLoading(False);
8436 end;
8437 end;
8438 end;
8440 procedure g_Game_ClearLoading();
8441 var
8442 len: Word;
8443 begin
8444 with LoadingStat do
8445 begin
8446 CurValue := 0;
8447 MaxValue := 0;
8448 ShowCount := 0;
8449 len := ((gScreenHeight div 3)*2 - 50) div LOADING_INTERLINE;
8450 if len < 1 then len := 1;
8451 SetLength(Msgs, len);
8452 for len := Low(Msgs) to High(Msgs) do
8453 Msgs[len] := '';
8454 NextMsg := 0;
8455 PBarWasHere := false;
8456 end;
8457 end;
8459 procedure Parse_Params(var pars: TParamStrValues);
8460 var
8461 i: Integer;
8462 s: String;
8463 begin
8464 SetLength(pars, 0);
8465 i := 1;
8466 while i <= ParamCount do
8467 begin
8468 s := ParamStr(i);
8469 if (Length(s) > 1) and (s[1] = '-') then
8470 begin
8471 if (Length(s) > 2) and (s[2] = '-') then
8472 begin // Îäèíî÷íûé ïàðàìåòð
8473 SetLength(pars, Length(pars) + 1);
8474 with pars[High(pars)] do
8475 begin
8476 Name := LowerCase(s);
8477 Value := '+';
8478 end;
8479 end
8480 else
8481 if (i < ParamCount) then
8482 begin // Ïàðàìåòð ñî çíà÷åíèåì
8483 Inc(i);
8484 SetLength(pars, Length(pars) + 1);
8485 with pars[High(pars)] do
8486 begin
8487 Name := LowerCase(s);
8488 Value := LowerCase(ParamStr(i));
8489 end;
8490 end;
8491 end;
8493 Inc(i);
8494 end;
8495 end;
8497 function Find_Param_Value(var pars: TParamStrValues; aName: String): String;
8498 var
8499 i: Integer;
8500 begin
8501 Result := '';
8502 for i := 0 to High(pars) do
8503 if pars[i].Name = aName then
8504 begin
8505 Result := pars[i].Value;
8506 Break;
8507 end;
8508 end;
8510 procedure g_Game_Process_Params();
8511 var
8512 pars: TParamStrValues;
8513 map: String;
8514 GMode, n: Byte;
8515 LimT, LimS: Integer;
8516 Opt: LongWord;
8517 Lives: Integer;
8518 s: String;
8519 Port: Integer;
8520 ip: String;
8521 F: TextFile;
8522 begin
8523 Parse_Params(pars);
8525 // Debug mode:
8526 s := Find_Param_Value(pars, '--debug');
8527 if (s <> '') then
8528 begin
8529 g_Game_SetDebugMode();
8530 s := Find_Param_Value(pars, '--netdump');
8531 if (s <> '') then
8532 NetDump := True;
8533 end;
8535 // Connect when game loads
8536 ip := Find_Param_Value(pars, '-connect');
8538 if ip <> '' then
8539 begin
8540 s := Find_Param_Value(pars, '-port');
8541 if (s = '') or not TryStrToInt(s, Port) then
8542 Port := 25666;
8544 s := Find_Param_Value(pars, '-pw');
8546 g_Game_StartClient(ip, Port, s);
8547 Exit;
8548 end;
8550 s := LowerCase(Find_Param_Value(pars, '-dbg-mainwad'));
8551 if (s <> '') then
8552 begin
8553 gDefaultMegawadStart := s;
8554 end;
8556 if (Find_Param_Value(pars, '--dbg-mainwad-restore') <> '') or
8557 (Find_Param_Value(pars, '--dbg-mainwad-default') <> '') then
8558 begin
8559 gDefaultMegawadStart := DF_Default_Megawad_Start;
8560 end;
8562 // Start map when game loads:
8563 map := LowerCase(Find_Param_Value(pars, '-map'));
8564 if isWadPath(map) then
8565 begin
8566 // Game mode:
8567 s := Find_Param_Value(pars, '-gm');
8568 GMode := g_Game_TextToMode(s);
8569 if GMode = GM_NONE then GMode := GM_DM;
8570 if GMode = GM_SINGLE then GMode := GM_COOP;
8572 // Time limit:
8573 s := Find_Param_Value(pars, '-limt');
8574 if (s = '') or (not TryStrToInt(s, LimT)) then
8575 LimT := 0;
8576 if LimT < 0 then
8577 LimT := 0;
8579 // Score limit:
8580 s := Find_Param_Value(pars, '-lims');
8581 if (s = '') or (not TryStrToInt(s, LimS)) then
8582 LimS := 0;
8583 if LimS < 0 then
8584 LimS := 0;
8586 // Lives limit:
8587 s := Find_Param_Value(pars, '-lives');
8588 if (s = '') or (not TryStrToInt(s, Lives)) then
8589 Lives := 0;
8590 if Lives < 0 then
8591 Lives := 0;
8593 // Options:
8594 s := Find_Param_Value(pars, '-opt');
8595 if (s = '') then
8596 Opt := gsGameFlags
8597 else
8598 Opt := StrToIntDef(s, 0);
8600 // Close after map:
8601 s := Find_Param_Value(pars, '--close');
8602 if (s <> '') then
8603 gMapOnce := True;
8605 // Override map to test:
8606 s := LowerCase(Find_Param_Value(pars, '-testmap'));
8607 if s <> '' then
8608 begin
8609 if e_IsValidResourceName(s) then
8610 e_FindResource(AllMapDirs, s);
8611 gTestMap := ExpandFileName(s);
8612 end;
8614 // Delete test map after play:
8615 s := Find_Param_Value(pars, '--testdelete');
8616 if (s <> '') then
8617 begin
8618 //gMapToDelete := MapsDir + map;
8619 e_WriteLog('"--testdelete" is deprecated, use --tempdelete.', TMsgType.Fatal);
8620 Halt(1);
8621 end;
8623 // Delete temporary WAD after play:
8624 s := Find_Param_Value(pars, '--tempdelete');
8625 if (s <> '') and (gTestMap <> '') then
8626 begin
8627 gMapToDelete := gTestMap;
8628 gTempDelete := True;
8629 end;
8631 // Number of players:
8632 s := Find_Param_Value(pars, '-pl');
8633 if (s = '') then
8634 n := DEFAULT_PLAYERS
8635 else
8636 n := StrToIntDef(s, DEFAULT_PLAYERS);
8638 // Start:
8639 s := Find_Param_Value(pars, '-port');
8640 if (s = '') or not TryStrToInt(s, Port) then
8641 g_Game_StartCustom(map, GMode, LimT, LimS, Lives, Opt, n)
8642 else
8643 g_Game_StartServer(map, GMode, LimT, LimS, Lives, Opt, n, 0, Port);
8644 end;
8646 // Execute script when game loads:
8647 s := Find_Param_Value(pars, '-exec');
8648 if s <> '' then
8649 begin
8650 // if not isWadPath(s) then
8651 // s := GameDir + '/' + s;
8653 {$I-}
8654 AssignFile(F, s);
8655 Reset(F);
8656 if IOResult <> 0 then
8657 begin
8658 e_WriteLog(Format(_lc[I_SIMPLE_ERROR], ['Failed to read file: ' + s]), TMsgType.Warning);
8659 g_Console_Add(Format(_lc[I_CONSOLE_ERROR_READ], [s]));
8660 CloseFile(F);
8661 Exit;
8662 end;
8663 e_WriteLog('Executing script: ' + s, TMsgType.Notify);
8664 g_Console_Add(Format(_lc[I_CONSOLE_EXEC], [s]));
8666 while not EOF(F) do
8667 begin
8668 ReadLn(F, s);
8669 if IOResult <> 0 then
8670 begin
8671 e_WriteLog(Format(_lc[I_SIMPLE_ERROR], ['Failed to read file: ' + s]), TMsgType.Warning);
8672 g_Console_Add(Format(_lc[I_CONSOLE_ERROR_READ], [s]));
8673 CloseFile(F);
8674 Exit;
8675 end;
8676 if Pos('#', s) <> 1 then // script comment
8677 g_Console_Process(s, True);
8678 end;
8680 CloseFile(F);
8681 {$I+}
8682 end;
8684 SetLength(pars, 0);
8685 end;
8687 begin
8688 conRegVar('pf_draw_frame', @g_profile_frame_draw, 'draw frame rendering profiles', 'render profiles');
8689 //conRegVar('pf_update_frame', @g_profile_frame_update, 'draw frame updating profiles', 'update profiles');
8690 conRegVar('pf_coldet', @g_profile_collision, 'draw collision detection profiles', 'coldet profiles');
8691 conRegVar('pf_los', @g_profile_los, 'draw monster LOS profiles', 'monster LOS profiles');
8693 conRegVar('r_sq_draw', @gdbg_map_use_accel_render, 'accelerated spatial queries in rendering', 'accelerated rendering');
8694 conRegVar('cd_sq_enabled', @gdbg_map_use_accel_coldet, 'accelerated spatial queries in map coldet', 'accelerated map coldet');
8695 conRegVar('mon_sq_enabled', @gmon_debug_use_sqaccel, 'accelerated spatial queries for monsters', 'accelerated monster coldet');
8696 conRegVar('wtrace_sq_enabled', @gwep_debug_fast_trace, 'accelerated spatial queries for weapon hitscan trace', 'accelerated weapon hitscan');
8698 conRegVar('pr_enabled', @gpart_dbg_enabled, 'enable/disable particles', 'particles');
8699 conRegVar('pr_phys_enabled', @gpart_dbg_phys_enabled, 'enable/disable particle physics', 'particle physics');
8701 conRegVar('los_enabled', @gmon_dbg_los_enabled, 'enable/disable monster LOS calculations', 'monster LOS', true);
8702 conRegVar('mon_think', @gmon_debug_think, 'enable/disable monster thinking', 'monster thinking', true);
8704 {$IFDEF ENABLE_HOLMES}
8705 conRegVar('dbg_holmes', @g_holmes_enabled, 'enable/disable Holmes', 'Holmes', true);
8706 {$ENDIF}
8708 conRegVar('dbg_ignore_level_bounds', @g_dbg_ignore_bounds, 'ignore level bounds', '', false);
8710 conRegVar('r_scale', @g_dbg_scale, 0.01, 100.0, 'render scale', '', false);
8711 conRegVar('r_resolution_scale', @r_pixel_scale, 0.01, 100.0, 'upscale factor', '', false);
8713 conRegVar('light_enabled', @gwin_k8_enable_light_experiments, 'enable/disable dynamic lighting', 'lighting');
8714 conRegVar('light_player_halo', @g_playerLight, 'enable/disable player halo', 'player light halo');
8716 conRegVar('r_smallmap_align_h', @r_smallmap_h, 'halign: 0: left; 1: center; 2: right', 'horizontal aligning of small maps');
8717 conRegVar('r_smallmap_align_v', @r_smallmap_v, 'valign: 0: top; 1: center; 2: bottom', 'vertial aligning of small maps');
8719 conRegVar('r_showfps', @gShowFPS, 'draw fps counter', 'draw fps counter');
8720 conRegVar('r_showtime', @gShowTime, 'show game time', 'show game time');
8721 conRegVar('r_showping', @gShowPing, 'show ping', 'show ping');
8722 conRegVar('r_showscore', @gShowScore, 'show score', 'show score');
8723 conRegVar('r_showkillmsg', @gShowKillMsg, 'show kill log', 'show kill log');
8724 conRegVar('r_showlives', @gShowLives, 'show lives', 'show lives');
8725 conRegVar('r_showspect', @gSpectHUD, 'show spectator hud', 'show spectator hud');
8726 conRegVar('r_showstat', @gShowStat, 'show stats', 'show stats');
8727 conRegVar('r_showpids', @gShowPIDs, 'show PIDs', 'show PIDs');
8728 end.