DEADSOFTWARE

a35e2cba976e5c6c121c4d043cad3a8a169ca802
[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 RulezRespawnTime: Word;
38 RulezRespawnRandom: 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 SkipFist: 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;
189 GAME_OPTION_TEAMDAMAGE = 2;
190 GAME_OPTION_ALLOWEXIT = 4;
191 GAME_OPTION_WEAPONSTAY = 8;
192 GAME_OPTION_MONSTERS = 16;
193 GAME_OPTION_BOTVSPLAYER = 32;
194 GAME_OPTION_BOTVSMONSTER = 64;
195 GAME_OPTION_DMKEYS = 128;
196 GAME_OPTION_TEAMHITTRACE = 256;
197 GAME_OPTION_TEAMHITPROJECTILE = 512;
198 GAME_OPTION_TEAMABSORBDAMAGE = 1024;
199 GAME_OPTION_ALLOWDROPFLAG = 2048;
200 GAME_OPTION_THROWFLAG = 4096;
201 GAME_OPTION_RULEZRANDOM = 8192;
202 GAME_OPTION_ITEMALLRANDOM = 16384;
203 GAME_OPTION_ITEMHELPRANDOM = 32768;
204 GAME_OPTION_ITEMAMMORANDOM = 65536;
205 GAME_OPTION_ITEMWEAPONRANDOM = 131072;
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.DrawRulez();
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 px := px-drawProfiles(px, py, profileFrameDraw);
3889 if g_profile_collision and (profMapCollision <> nil) then begin px := px-drawProfiles(px, py, profMapCollision); py -= calcProfilesHeight(profMonsLOS); end;
3890 if g_profile_los and (profMonsLOS <> nil) then begin px := px-drawProfiles(px, py, profMonsLOS); py -= calcProfilesHeight(profMonsLOS); end;
3891 end;
3893 procedure g_Game_Draw();
3894 var
3895 ID: DWORD;
3896 w, h: Word;
3897 ww, hh: Byte;
3898 Time: Int64;
3899 back: string;
3900 plView1, plView2: TPlayer;
3901 Split: Boolean;
3902 begin
3903 if gExit = EXIT_QUIT then Exit;
3905 Time := sys_GetTicks() {div 1000};
3906 FPSCounter := FPSCounter+1;
3907 if Time - FPSTime >= 1000 then
3908 begin
3909 FPS := FPSCounter;
3910 FPSCounter := 0;
3911 FPSTime := Time;
3912 end;
3914 e_SetRendertarget(True);
3915 e_SetViewPort(0, 0, gScreenWidth, gScreenHeight);
3917 if gGameOn or (gState = STATE_FOLD) then
3918 begin
3919 if (gPlayer1 <> nil) and (gPlayer2 <> nil) then
3920 begin
3921 gSpectMode := SPECT_NONE;
3922 if not gRevertPlayers then
3923 begin
3924 plView1 := gPlayer1;
3925 plView2 := gPlayer2;
3926 end
3927 else
3928 begin
3929 plView1 := gPlayer2;
3930 plView2 := gPlayer1;
3931 end;
3932 end
3933 else
3934 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
3935 begin
3936 gSpectMode := SPECT_NONE;
3937 if gPlayer2 = nil then
3938 plView1 := gPlayer1
3939 else
3940 plView1 := gPlayer2;
3941 plView2 := nil;
3942 end
3943 else
3944 begin
3945 plView1 := nil;
3946 plView2 := nil;
3947 end;
3949 if (plView1 = nil) and (plView2 = nil) and (gSpectMode = SPECT_NONE) then
3950 gSpectMode := SPECT_STATS;
3952 if gSpectMode = SPECT_PLAYERS then
3953 if gPlayers <> nil then
3954 begin
3955 plView1 := GetActivePlayer_ByID(gSpectPID1);
3956 if plView1 = nil then
3957 begin
3958 gSpectPID1 := GetActivePlayerID_Next();
3959 plView1 := GetActivePlayer_ByID(gSpectPID1);
3960 end;
3961 if gSpectViewTwo then
3962 begin
3963 plView2 := GetActivePlayer_ByID(gSpectPID2);
3964 if plView2 = nil then
3965 begin
3966 gSpectPID2 := GetActivePlayerID_Next();
3967 plView2 := GetActivePlayer_ByID(gSpectPID2);
3968 end;
3969 end;
3970 end;
3972 if gSpectMode = SPECT_MAPVIEW then
3973 begin
3974 // Ðåæèì ïðîñìîòðà êàðòû
3975 Split := False;
3976 e_SetViewPort(0, 0, gScreenWidth, gScreenHeight);
3977 DrawMapView(gSpectX, gSpectY, gScreenWidth, gScreenHeight);
3978 gHearPoint1.Active := True;
3979 gHearPoint1.Coords.X := gScreenWidth div 2 + gSpectX;
3980 gHearPoint1.Coords.Y := gScreenHeight div 2 + gSpectY;
3981 gHearPoint2.Active := False;
3982 end
3983 else
3984 begin
3985 Split := (plView1 <> nil) and (plView2 <> nil);
3987 // Òî÷êè ñëóõà èãðîêîâ
3988 if plView1 <> nil then
3989 begin
3990 gHearPoint1.Active := True;
3991 gHearPoint1.Coords.X := plView1.GameX + PLAYER_RECT.Width;
3992 gHearPoint1.Coords.Y := plView1.GameY + PLAYER_RECT.Height DIV 2;
3993 end else
3994 gHearPoint1.Active := False;
3995 if plView2 <> nil then
3996 begin
3997 gHearPoint2.Active := True;
3998 gHearPoint2.Coords.X := plView2.GameX + PLAYER_RECT.Width;
3999 gHearPoint2.Coords.Y := plView2.GameY + PLAYER_RECT.Height DIV 2;
4000 end else
4001 gHearPoint2.Active := False;
4003 // Ðàçìåð ýêðàíîâ èãðîêîâ:
4004 gPlayerScreenSize.X := gScreenWidth-196;
4005 if Split then
4006 begin
4007 gPlayerScreenSize.Y := gScreenHeight div 2;
4008 if gScreenHeight mod 2 = 0 then
4009 Dec(gPlayerScreenSize.Y);
4010 end
4011 else
4012 gPlayerScreenSize.Y := gScreenHeight;
4014 if Split then
4015 if gScreenHeight mod 2 = 0 then
4016 e_SetViewPort(0, gPlayerScreenSize.Y+2, gPlayerScreenSize.X+196, gPlayerScreenSize.Y)
4017 else
4018 e_SetViewPort(0, gPlayerScreenSize.Y+1, gPlayerScreenSize.X+196, gPlayerScreenSize.Y);
4020 DrawPlayer(plView1);
4021 gPlayer1ScreenCoord.X := sX;
4022 gPlayer1ScreenCoord.Y := sY;
4024 if Split then
4025 begin
4026 e_SetViewPort(0, 0, gPlayerScreenSize.X+196, gPlayerScreenSize.Y);
4028 DrawPlayer(plView2);
4029 gPlayer2ScreenCoord.X := sX;
4030 gPlayer2ScreenCoord.Y := sY;
4031 end;
4033 e_SetViewPort(0, 0, gScreenWidth, gScreenHeight);
4035 if Split then
4036 e_DrawLine(2, 0, gScreenHeight div 2, gScreenWidth, gScreenHeight div 2, 0, 0, 0);
4037 end;
4039 {$IFDEF ENABLE_HOLMES}
4040 // draw inspector
4041 if (g_holmes_enabled) then g_Holmes_Draw();
4042 {$ENDIF}
4044 if MessageText <> '' then
4045 begin
4046 w := 0;
4047 h := 0;
4048 e_CharFont_GetSizeFmt(gMenuFont, MessageText, w, h);
4049 if Split then
4050 e_CharFont_PrintFmt(gMenuFont, (gScreenWidth div 2)-(w div 2),
4051 (gScreenHeight div 2)-(h div 2), MessageText)
4052 else
4053 e_CharFont_PrintFmt(gMenuFont, (gScreenWidth div 2)-(w div 2),
4054 Round(gScreenHeight / 2.75)-(h div 2), MessageText);
4055 end;
4057 if IsDrawStat or (gSpectMode = SPECT_STATS) then
4058 DrawStat();
4060 if gSpectHUD and (not gChatShow) and (gSpectMode <> SPECT_NONE) and (not gSpectAuto) then
4061 begin
4062 // Draw spectator GUI
4063 ww := 0;
4064 hh := 0;
4065 e_TextureFontGetSize(gStdFont, ww, hh);
4066 case gSpectMode of
4067 SPECT_STATS:
4068 e_TextureFontPrintEx(0, gScreenHeight - (hh+2)*2, 'MODE: Stats', gStdFont, 255, 255, 255, 1);
4069 SPECT_MAPVIEW:
4070 e_TextureFontPrintEx(0, gScreenHeight - (hh+2)*2, 'MODE: Observe Map', gStdFont, 255, 255, 255, 1);
4071 SPECT_PLAYERS:
4072 e_TextureFontPrintEx(0, gScreenHeight - (hh+2)*2, 'MODE: Watch Players', gStdFont, 255, 255, 255, 1);
4073 end;
4074 e_TextureFontPrintEx(2*ww, gScreenHeight - (hh+2), '< jump >', gStdFont, 255, 255, 255, 1);
4075 if gSpectMode = SPECT_STATS then
4076 begin
4077 e_TextureFontPrintEx(16*ww, gScreenHeight - (hh+2)*2, 'Autoview', gStdFont, 255, 255, 255, 1);
4078 e_TextureFontPrintEx(16*ww, gScreenHeight - (hh+2), '< fire >', gStdFont, 255, 255, 255, 1);
4079 end;
4080 if gSpectMode = SPECT_MAPVIEW then
4081 begin
4082 e_TextureFontPrintEx(22*ww, gScreenHeight - (hh+2)*2, '[-]', gStdFont, 255, 255, 255, 1);
4083 e_TextureFontPrintEx(26*ww, gScreenHeight - (hh+2)*2, 'Step ' + IntToStr(gSpectStep), gStdFont, 255, 255, 255, 1);
4084 e_TextureFontPrintEx(34*ww, gScreenHeight - (hh+2)*2, '[+]', gStdFont, 255, 255, 255, 1);
4085 e_TextureFontPrintEx(18*ww, gScreenHeight - (hh+2), '<prev weap>', gStdFont, 255, 255, 255, 1);
4086 e_TextureFontPrintEx(30*ww, gScreenHeight - (hh+2), '<next weap>', gStdFont, 255, 255, 255, 1);
4087 end;
4088 if gSpectMode = SPECT_PLAYERS then
4089 begin
4090 e_TextureFontPrintEx(22*ww, gScreenHeight - (hh+2)*2, 'Player 1', gStdFont, 255, 255, 255, 1);
4091 e_TextureFontPrintEx(20*ww, gScreenHeight - (hh+2), '<left/right>', gStdFont, 255, 255, 255, 1);
4092 if gSpectViewTwo then
4093 begin
4094 e_TextureFontPrintEx(37*ww, gScreenHeight - (hh+2)*2, 'Player 2', gStdFont, 255, 255, 255, 1);
4095 e_TextureFontPrintEx(34*ww, gScreenHeight - (hh+2), '<prev w/next w>', gStdFont, 255, 255, 255, 1);
4096 e_TextureFontPrintEx(52*ww, gScreenHeight - (hh+2)*2, '2x View', gStdFont, 255, 255, 255, 1);
4097 e_TextureFontPrintEx(51*ww, gScreenHeight - (hh+2), '<up/down>', gStdFont, 255, 255, 255, 1);
4098 end
4099 else
4100 begin
4101 e_TextureFontPrintEx(35*ww, gScreenHeight - (hh+2)*2, '2x View', gStdFont, 255, 255, 255, 1);
4102 e_TextureFontPrintEx(34*ww, gScreenHeight - (hh+2), '<up/down>', gStdFont, 255, 255, 255, 1);
4103 end;
4104 end;
4105 end;
4106 end;
4108 if gPauseMain and gGameOn and (g_ActiveWindow = nil) then
4109 begin
4110 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4111 e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
4113 e_CharFont_GetSize(gMenuFont, _lc[I_MENU_PAUSE], w, h);
4114 e_CharFont_Print(gMenuFont, (gScreenWidth div 2)-(w div 2),
4115 (gScreenHeight div 2)-(h div 2), _lc[I_MENU_PAUSE]);
4116 end;
4118 if not gGameOn then
4119 begin
4120 if (gState = STATE_MENU) then
4121 begin
4122 if (g_ActiveWindow = nil) or (g_ActiveWindow.BackTexture = '') then DrawMenuBackground('MENU_BACKGROUND');
4123 // F3 at menu will show game loading dialog
4124 if e_KeyPressed(IK_F3) then g_Menu_Show_LoadMenu(true);
4125 if (g_ActiveWindow <> nil) then
4126 begin
4127 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4128 e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
4129 end
4130 else
4131 begin
4132 // F3 at titlepic will show game loading dialog
4133 if e_KeyPressed(IK_F3) then
4134 begin
4135 g_Menu_Show_LoadMenu(true);
4136 if (g_ActiveWindow <> nil) then e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
4137 end;
4138 end;
4139 end;
4141 if gState = STATE_FOLD then
4142 begin
4143 e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 0, 0, 0, EndingGameCounter);
4144 end;
4146 if gState = STATE_INTERCUSTOM then
4147 begin
4148 if gLastMap and (gGameSettings.GameMode = GM_COOP) then
4149 begin
4150 back := 'TEXTURE_endpic';
4151 if not g_Texture_Get(back, ID) then
4152 back := _lc[I_TEXTURE_ENDPIC];
4153 end
4154 else
4155 back := 'INTER';
4157 DrawMenuBackground(back);
4159 DrawCustomStat();
4161 if g_ActiveWindow <> nil then
4162 begin
4163 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4164 e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
4165 end;
4166 end;
4168 if gState = STATE_INTERSINGLE then
4169 begin
4170 if EndingGameCounter > 0 then
4171 begin
4172 e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 0, 0, 0, EndingGameCounter);
4173 end
4174 else
4175 begin
4176 back := 'INTER';
4178 DrawMenuBackground(back);
4180 DrawSingleStat();
4182 if g_ActiveWindow <> nil then
4183 begin
4184 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4185 e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
4186 end;
4187 end;
4188 end;
4190 if gState = STATE_ENDPIC then
4191 begin
4192 ID := DWORD(-1);
4193 if g_Texture_Get('TEXTURE_endpic', ID) then DrawMenuBackground('TEXTURE_endpic')
4194 else DrawMenuBackground(_lc[I_TEXTURE_ENDPIC]);
4196 if g_ActiveWindow <> nil then
4197 begin
4198 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4199 e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
4200 end;
4201 end;
4203 if gState = STATE_SLIST then
4204 begin
4205 // if g_Texture_Get('MENU_BACKGROUND', ID) then
4206 // begin
4207 // e_DrawSize(ID, 0, 0, 0, False, False, gScreenWidth, gScreenHeight);
4208 // //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4209 // end;
4210 DrawMenuBackground('MENU_BACKGROUND');
4211 e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
4212 g_Serverlist_Draw(slCurrent, slTable);
4213 end;
4214 end;
4216 if g_ActiveWindow <> nil then
4217 begin
4218 if gGameOn then
4219 begin
4220 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4221 e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
4222 end;
4223 g_ActiveWindow.Draw();
4224 end;
4226 {$IFNDEF HEADLESS}
4227 g_Console_Draw();
4228 {$ENDIF}
4230 if g_debug_Sounds and gGameOn then
4231 begin
4232 for w := 0 to High(e_SoundsArray) do
4233 for h := 0 to e_SoundsArray[w].nRefs do
4234 e_DrawPoint(1, w+100, h+100, 255, 0, 0);
4235 end;
4237 if gShowFPS then
4238 begin
4239 e_TextureFontPrint(0, 0, Format('FPS: %d', [FPS]), gStdFont);
4240 e_TextureFontPrint(0, 16, Format('UPS: %d', [UPS]), gStdFont);
4241 end;
4243 if gGameOn and gShowTime then
4244 drawTime(gScreenWidth-72, gScreenHeight-16);
4246 if gGameOn then drawProfilers();
4248 // TODO: draw this after the FBO and remap mouse click coordinates
4250 {$IFDEF ENABLE_HOLMES}
4251 g_Holmes_DrawUI();
4252 {$ENDIF}
4254 // blit framebuffer to screen
4256 e_SetRendertarget(False);
4257 e_SetViewPort(0, 0, gWinSizeX, gWinSizeY);
4258 e_BlitFramebuffer(gWinSizeX, gWinSizeY);
4260 // draw the overlay stuff on top of it
4262 g_Touch_Draw;
4263 end;
4265 procedure g_Game_Quit();
4266 begin
4267 g_Game_StopAllSounds(True);
4268 gMusic.Free();
4269 g_Game_FreeData();
4270 g_PlayerModel_FreeData();
4271 g_Texture_DeleteAll();
4272 g_Frames_DeleteAll();
4273 {$IFNDEF HEADLESS}
4274 //g_Menu_Free(); //k8: this segfaults after resolution change; who cares?
4275 {$ENDIF}
4277 if NetInitDone then g_Net_Free;
4279 // Íàäî óäàëèòü êàðòó ïîñëå òåñòà:
4280 if gMapToDelete <> '' then
4281 g_Game_DeleteTestMap();
4283 gExit := EXIT_QUIT;
4284 sys_RequestQuit;
4285 end;
4287 procedure g_FatalError(Text: String);
4288 begin
4289 g_Console_Add(Format(_lc[I_FATAL_ERROR], [Text]), True);
4290 e_WriteLog(Format(_lc[I_FATAL_ERROR], [Text]), TMsgType.Warning);
4292 gExit := EXIT_SIMPLE;
4293 if gGameOn then EndGame;
4294 end;
4296 procedure g_SimpleError(Text: String);
4297 begin
4298 g_Console_Add(Format(_lc[I_SIMPLE_ERROR], [Text]), True);
4299 e_WriteLog(Format(_lc[I_SIMPLE_ERROR], [Text]), TMsgType.Warning);
4300 end;
4302 procedure g_Game_SetupScreenSize();
4303 const
4304 RES_FACTOR = 4.0 / 3.0;
4305 var
4306 s: Single;
4307 rf: Single;
4308 bw, bh: Word;
4309 begin
4310 // Ðàçìåð ýêðàíîâ èãðîêîâ:
4311 gPlayerScreenSize.X := gScreenWidth-196;
4312 if (gPlayer1 <> nil) and (gPlayer2 <> nil) then
4313 gPlayerScreenSize.Y := gScreenHeight div 2
4314 else
4315 gPlayerScreenSize.Y := gScreenHeight;
4317 // Ðàçìåð çàäíåãî ïëàíà:
4318 if BackID <> DWORD(-1) then
4319 begin
4320 s := SKY_STRETCH;
4321 if (gScreenWidth*s > gMapInfo.Width) or
4322 (gScreenHeight*s > gMapInfo.Height) then
4323 begin
4324 gBackSize.X := gScreenWidth;
4325 gBackSize.Y := gScreenHeight;
4326 end
4327 else
4328 begin
4329 e_GetTextureSize(BackID, @bw, @bh);
4330 rf := Single(bw) / Single(bh);
4331 if (rf > RES_FACTOR) then bw := Round(Single(bh) * RES_FACTOR)
4332 else if (rf < RES_FACTOR) then bh := Round(Single(bw) / RES_FACTOR);
4333 s := Max(gScreenWidth / bw, gScreenHeight / bh);
4334 if (s < 1.0) then s := 1.0;
4335 gBackSize.X := Round(bw*s);
4336 gBackSize.Y := Round(bh*s);
4337 end;
4338 end;
4339 end;
4341 procedure g_Game_ChangeResolution(newWidth, newHeight: Word; nowFull, nowMax: Boolean);
4342 begin
4343 sys_SetDisplayMode(newWidth, newHeight, gBPP, nowFull, nowMax);
4344 end;
4346 procedure g_Game_AddPlayer(Team: Byte = TEAM_NONE);
4347 begin
4348 if ((not gGameOn) and (gState <> STATE_INTERCUSTOM))
4349 or (not (gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT])) then
4350 Exit;
4352 if (gGameSettings.MaxLives > 0) and (gLMSRespawn = LMS_RESPAWN_NONE) then
4353 Exit;
4355 if gPlayer1 = nil then
4356 begin
4357 if g_Game_IsClient then
4358 begin
4359 if NetPlrUID1 > -1 then
4360 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE);
4361 Exit;
4362 end;
4364 if not (Team in [TEAM_RED, TEAM_BLUE]) then
4365 Team := gPlayer1Settings.Team;
4367 // Ñîçäàíèå ïåðâîãî èãðîêà:
4368 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
4369 gPlayer1Settings.Color,
4370 Team, False));
4371 if gPlayer1 = nil then
4372 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]))
4373 else
4374 begin
4375 gPlayer1.Name := gPlayer1Settings.Name;
4376 gPlayer1.WeapSwitchMode := gPlayer1Settings.WeaponSwitch;
4377 gPlayer1.setWeaponPrefs(gPlayer1Settings.WeaponPreferences);
4378 gPlayer1.SwitchToEmpty := gPlayer1Settings.SwitchToEmpty;
4379 gPlayer1.SkipFist := gPlayer1Settings.SkipFist;
4380 g_Console_Add(Format(_lc[I_PLAYER_JOIN], [gPlayer1.Name]), True);
4381 if g_Game_IsServer and g_Game_IsNet then
4382 MH_SEND_PlayerCreate(gPlayer1.UID);
4383 gPlayer1.Respawn(False, True);
4384 g_Net_Slist_ServerPlayerComes();
4385 end;
4387 Exit;
4388 end;
4389 if gPlayer2 = nil then
4390 begin
4391 if g_Game_IsClient then
4392 begin
4393 if NetPlrUID2 > -1 then
4394 gPlayer2 := g_Player_Get(NetPlrUID2);
4395 Exit;
4396 end;
4398 if not (Team in [TEAM_RED, TEAM_BLUE]) then
4399 Team := gPlayer2Settings.Team;
4401 // Ñîçäàíèå âòîðîãî èãðîêà:
4402 gPlayer2 := g_Player_Get(g_Player_Create(gPlayer2Settings.Model,
4403 gPlayer2Settings.Color,
4404 Team, False));
4405 if gPlayer2 = nil then
4406 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [2]))
4407 else
4408 begin
4409 gPlayer2.Name := gPlayer2Settings.Name;
4410 gPlayer2.WeapSwitchMode := gPlayer2Settings.WeaponSwitch;
4411 gPlayer2.setWeaponPrefs(gPlayer2Settings.WeaponPreferences);
4412 gPlayer2.SwitchToEmpty := gPlayer2Settings.SwitchToEmpty;
4413 gPlayer2.SkipFist := gPlayer2Settings.SkipFist;
4414 g_Console_Add(Format(_lc[I_PLAYER_JOIN], [gPlayer2.Name]), True);
4415 if g_Game_IsServer and g_Game_IsNet then
4416 MH_SEND_PlayerCreate(gPlayer2.UID);
4417 gPlayer2.Respawn(False, True);
4418 g_Net_Slist_ServerPlayerComes();
4419 end;
4421 Exit;
4422 end;
4423 end;
4425 procedure g_Game_RemovePlayer();
4426 var
4427 Pl: TPlayer;
4428 begin
4429 if ((not gGameOn) and (gState <> STATE_INTERCUSTOM))
4430 or (not (gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT])) then
4431 Exit;
4432 Pl := gPlayer2;
4433 if Pl <> nil then
4434 begin
4435 if g_Game_IsServer then
4436 begin
4437 Pl.Lives := 0;
4438 Pl.Kill(K_SIMPLEKILL, 0, HIT_DISCON);
4439 g_Console_Add(Format(_lc[I_PLAYER_LEAVE], [Pl.Name]), True);
4440 g_Player_Remove(Pl.UID);
4441 g_Net_Slist_ServerPlayerLeaves();
4442 end
4443 else
4444 begin
4445 gSpectLatchPID2 := Pl.UID;
4446 gPlayer2 := nil;
4447 end;
4448 Exit;
4449 end;
4450 Pl := gPlayer1;
4451 if Pl <> nil then
4452 begin
4453 if g_Game_IsServer then
4454 begin
4455 Pl.Lives := 0;
4456 Pl.Kill(K_SIMPLEKILL, 0, HIT_DISCON);
4457 g_Console_Add(Format(_lc[I_PLAYER_LEAVE], [Pl.Name]), True);
4458 g_Player_Remove(Pl.UID);
4459 g_Net_Slist_ServerPlayerLeaves();
4460 end else
4461 begin
4462 gSpectLatchPID1 := Pl.UID;
4463 gPlayer1 := nil;
4464 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE);
4465 end;
4466 Exit;
4467 end;
4468 g_Net_Slist_ServerPlayerLeaves();
4469 end;
4471 procedure g_Game_Spectate();
4472 begin
4473 g_Game_RemovePlayer();
4474 if gPlayer1 <> nil then
4475 g_Game_RemovePlayer();
4476 end;
4478 procedure g_Game_SpectateCenterView();
4479 begin
4480 gSpectX := Max(gMapInfo.Width div 2 - gScreenWidth div 2, 0);
4481 gSpectY := Max(gMapInfo.Height div 2 - gScreenHeight div 2, 0);
4482 end;
4484 procedure g_Game_StartSingle(Map: String; TwoPlayers: Boolean; nPlayers: Byte);
4485 var
4486 i, nPl: Integer;
4487 tmps: AnsiString;
4488 begin
4489 g_Game_Free();
4491 e_WriteLog('Starting singleplayer game...', TMsgType.Notify);
4493 g_Game_ClearLoading();
4495 // Íàñòðîéêè èãðû:
4496 FillByte(gGameSettings, SizeOf(TGameSettings), 0);
4497 gAimLine := False;
4498 gShowMap := False;
4499 gGameSettings.GameType := GT_SINGLE;
4500 gGameSettings.MaxLives := 0;
4501 gGameSettings.Options := gGameSettings.Options + GAME_OPTION_ALLOWEXIT;
4502 gGameSettings.Options := gGameSettings.Options + GAME_OPTION_MONSTERS;
4503 gGameSettings.Options := gGameSettings.Options + GAME_OPTION_BOTVSMONSTER;
4504 gGameSettings.Options := gGameSettings.Options + GAME_OPTION_TEAMHITPROJECTILE;
4505 gGameSettings.Options := gGameSettings.Options + GAME_OPTION_TEAMHITTRACE;
4506 gGameSettings.Options := gGameSettings.Options + GAME_OPTION_RULEZRANDOM;
4507 gGameSettings.Options := gGameSettings.Options + GAME_OPTION_ITEMALLRANDOM;
4508 gGameSettings.Options := gGameSettings.Options + GAME_OPTION_ITEMHELPRANDOM;
4509 gGameSettings.Options := gGameSettings.Options + GAME_OPTION_ITEMAMMORANDOM;
4510 gGameSettings.Options := gGameSettings.Options + GAME_OPTION_ITEMWEAPONRANDOM;
4511 gSwitchGameMode := GM_SINGLE;
4513 gLMSRespawn := LMS_RESPAWN_NONE;
4514 gLMSRespawnTime := 0;
4515 gSpectLatchPID1 := 0;
4516 gSpectLatchPID2 := 0;
4518 g_Game_ExecuteEvent('ongamestart');
4520 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
4521 g_Game_SetupScreenSize();
4523 // Ñîçäàíèå ïåðâîãî èãðîêà:
4524 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
4525 gPlayer1Settings.Color,
4526 gPlayer1Settings.Team, False));
4527 if gPlayer1 = nil then
4528 begin
4529 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]));
4530 Exit;
4531 end;
4533 gPlayer1.Name := gPlayer1Settings.Name;
4534 gPlayer1.WeapSwitchMode := gPlayer1Settings.WeaponSwitch;
4535 gPlayer1.setWeaponPrefs(gPlayer1Settings.WeaponPreferences);
4536 gPlayer1.SwitchToEmpty := gPlayer1Settings.SwitchToEmpty;
4537 gPlayer1.SkipFist := gPlayer1Settings.SkipFist;
4538 nPl := 1;
4540 // Ñîçäàíèå âòîðîãî èãðîêà, åñëè åñòü:
4541 if TwoPlayers then
4542 begin
4543 gPlayer2 := g_Player_Get(g_Player_Create(gPlayer2Settings.Model,
4544 gPlayer2Settings.Color,
4545 gPlayer2Settings.Team, False));
4546 if gPlayer2 = nil then
4547 begin
4548 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [2]));
4549 Exit;
4550 end;
4552 gPlayer2.Name := gPlayer2Settings.Name;
4553 gPlayer2.WeapSwitchMode := gPlayer2Settings.WeaponSwitch;
4554 gPlayer2.setWeaponPrefs(gPlayer2Settings.WeaponPreferences);
4555 gPlayer2.SwitchToEmpty := gPlayer2Settings.SwitchToEmpty;
4556 gPlayer2.SkipFist := gPlayer2Settings.SkipFist;
4557 Inc(nPl);
4558 end;
4560 // Çàãðóçêà è çàïóñê êàðòû:
4561 if not g_Game_StartMap(false{asMegawad}, MAP, True) then
4562 begin
4563 if (Pos(':\', Map) > 0) or (Pos(':/', Map) > 0) then tmps := Map else tmps := gGameSettings.WAD + ':\' + MAP;
4564 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [tmps]));
4565 Exit;
4566 end;
4568 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4569 g_Player_Init();
4571 // Ñîçäàåì áîòîâ:
4572 for i := nPl+1 to nPlayers do
4573 g_Player_Create(STD_PLAYER_MODEL, _RGB(0, 0, 0), 0, True);
4574 end;
4576 procedure g_Game_StartCustom(Map: String; GameMode: Byte;
4577 TimeLimit, ScoreLimit: Word;
4578 MaxLives: Byte;
4579 Options: LongWord; nPlayers: Byte);
4580 var
4581 i, nPl: Integer;
4582 begin
4583 g_Game_Free();
4585 e_WriteLog('Starting custom game...', TMsgType.Notify);
4587 g_Game_ClearLoading();
4589 // Íàñòðîéêè èãðû:
4590 gGameSettings.GameType := GT_CUSTOM;
4591 gGameSettings.GameMode := GameMode;
4592 gSwitchGameMode := GameMode;
4593 gGameSettings.TimeLimit := TimeLimit;
4594 gGameSettings.ScoreLimit := ScoreLimit;
4595 gGameSettings.MaxLives := IfThen(GameMode = GM_CTF, 0, MaxLives);
4596 gGameSettings.Options := Options;
4598 gCoopTotalMonstersKilled := 0;
4599 gCoopTotalSecretsFound := 0;
4600 gCoopTotalMonsters := 0;
4601 gCoopTotalSecrets := 0;
4602 gAimLine := False;
4603 gShowMap := False;
4605 gLMSRespawn := LMS_RESPAWN_NONE;
4606 gLMSRespawnTime := 0;
4607 gSpectLatchPID1 := 0;
4608 gSpectLatchPID2 := 0;
4610 g_Game_ExecuteEvent('ongamestart');
4612 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
4613 g_Game_SetupScreenSize();
4615 // Ðåæèì íàáëþäàòåëÿ:
4616 if nPlayers = 0 then
4617 begin
4618 gPlayer1 := nil;
4619 gPlayer2 := nil;
4620 end;
4622 nPl := 0;
4623 if nPlayers >= 1 then
4624 begin
4625 // Ñîçäàíèå ïåðâîãî èãðîêà:
4626 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
4627 gPlayer1Settings.Color,
4628 gPlayer1Settings.Team, False));
4629 if gPlayer1 = nil then
4630 begin
4631 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]));
4632 Exit;
4633 end;
4635 gPlayer1.Name := gPlayer1Settings.Name;
4636 gPlayer1.WeapSwitchMode := gPlayer1Settings.WeaponSwitch;
4637 gPlayer1.setWeaponPrefs(gPlayer1Settings.WeaponPreferences);
4638 gPlayer1.SwitchToEmpty := gPlayer1Settings.SwitchToEmpty;
4639 gPlayer1.SkipFist := gPlayer1Settings.SkipFist;
4640 Inc(nPl);
4641 end;
4643 if nPlayers >= 2 then
4644 begin
4645 // Ñîçäàíèå âòîðîãî èãðîêà:
4646 gPlayer2 := g_Player_Get(g_Player_Create(gPlayer2Settings.Model,
4647 gPlayer2Settings.Color,
4648 gPlayer2Settings.Team, False));
4649 if gPlayer2 = nil then
4650 begin
4651 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [2]));
4652 Exit;
4653 end;
4655 gPlayer2.Name := gPlayer2Settings.Name;
4656 gPlayer2.WeapSwitchMode := gPlayer2Settings.WeaponSwitch;
4657 gPlayer2.setWeaponPrefs(gPlayer2Settings.WeaponPreferences);
4658 gPlayer2.SwitchToEmpty := gPlayer2Settings.SwitchToEmpty;
4659 gPlayer2.SkipFist := gPlayer2Settings.SkipFist;
4660 Inc(nPl);
4661 end;
4663 // Çàãðóçêà è çàïóñê êàðòû:
4664 if not g_Game_StartMap(true{asMegawad}, Map, True) then
4665 begin
4666 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [Map]));
4667 Exit;
4668 end;
4670 // Íåò òî÷åê ïîÿâëåíèÿ:
4671 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1) +
4672 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2) +
4673 g_Map_GetPointCount(RESPAWNPOINT_DM) +
4674 g_Map_GetPointCount(RESPAWNPOINT_RED)+
4675 g_Map_GetPointCount(RESPAWNPOINT_BLUE)) < 1 then
4676 begin
4677 g_FatalError(_lc[I_GAME_ERROR_GET_SPAWN]);
4678 Exit;
4679 end;
4681 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4682 g_Player_Init();
4684 // Ñîçäàåì áîòîâ:
4685 for i := nPl+1 to nPlayers do
4686 g_Player_Create(STD_PLAYER_MODEL, _RGB(0, 0, 0), 0, True);
4687 end;
4689 procedure g_Game_StartServer(Map: String; GameMode: Byte;
4690 TimeLimit, ScoreLimit: Word; MaxLives: Byte;
4691 Options: LongWord; nPlayers: Byte;
4692 IPAddr: LongWord; Port: Word);
4693 begin
4694 g_Game_Free();
4695 g_Net_Slist_ServerClosed();
4697 e_WriteLog('Starting net game (server)...', TMsgType.Notify);
4699 g_Game_ClearLoading();
4701 ClearDebugCvars();
4703 // Íàñòðîéêè èãðû:
4704 gGameSettings.GameType := GT_SERVER;
4705 gGameSettings.GameMode := GameMode;
4706 gSwitchGameMode := GameMode;
4707 gGameSettings.TimeLimit := TimeLimit;
4708 gGameSettings.ScoreLimit := ScoreLimit;
4709 gGameSettings.MaxLives := IfThen(GameMode = GM_CTF, 0, MaxLives);
4710 gGameSettings.Options := Options;
4712 gCoopTotalMonstersKilled := 0;
4713 gCoopTotalSecretsFound := 0;
4714 gCoopTotalMonsters := 0;
4715 gCoopTotalSecrets := 0;
4716 gAimLine := False;
4717 gShowMap := False;
4719 gLMSRespawn := LMS_RESPAWN_NONE;
4720 gLMSRespawnTime := 0;
4721 gSpectLatchPID1 := 0;
4722 gSpectLatchPID2 := 0;
4724 g_Game_ExecuteEvent('ongamestart');
4726 // Óñòàíîâêà ðàçìåðîâ îêíà èãðîêà
4727 g_Game_SetupScreenSize();
4729 // Ðåæèì íàáëþäàòåëÿ:
4730 if nPlayers = 0 then
4731 begin
4732 gPlayer1 := nil;
4733 gPlayer2 := nil;
4734 end;
4736 if nPlayers >= 1 then
4737 begin
4738 // Ñîçäàíèå ïåðâîãî èãðîêà:
4739 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
4740 gPlayer1Settings.Color,
4741 gPlayer1Settings.Team, False));
4742 if gPlayer1 = nil then
4743 begin
4744 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]));
4745 Exit;
4746 end;
4748 gPlayer1.Name := gPlayer1Settings.Name;
4749 gPlayer1.WeapSwitchMode := gPlayer1Settings.WeaponSwitch;
4750 gPlayer1.setWeaponPrefs(gPlayer1Settings.WeaponPreferences);
4751 gPlayer1.SwitchToEmpty := gPlayer1Settings.SwitchToEmpty;
4752 gPlayer1.SkipFist := gPlayer1Settings.SkipFist;
4753 end;
4755 if nPlayers >= 2 then
4756 begin
4757 // Ñîçäàíèå âòîðîãî èãðîêà:
4758 gPlayer2 := g_Player_Get(g_Player_Create(gPlayer2Settings.Model,
4759 gPlayer2Settings.Color,
4760 gPlayer2Settings.Team, False));
4761 if gPlayer2 = nil then
4762 begin
4763 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [2]));
4764 Exit;
4765 end;
4767 gPlayer2.Name := gPlayer2Settings.Name;
4768 gPlayer2.WeapSwitchMode := gPlayer2Settings.WeaponSwitch;
4769 gPlayer2.setWeaponPrefs(gPlayer2Settings.WeaponPreferences);
4770 gPlayer2.SwitchToEmpty := gPlayer2Settings.SwitchToEmpty;
4771 gPlayer2.SkipFist := gPlayer2Settings.SkipFist;
4772 end;
4774 g_Game_SetLoadingText(_lc[I_LOAD_HOST], 0, False);
4775 if NetForwardPorts then
4776 g_Game_SetLoadingText(_lc[I_LOAD_PORTS], 0, False);
4778 // Ñòàðòóåì ñåðâåð
4779 if not g_Net_Host(IPAddr, Port, NetMaxClients) then
4780 begin
4781 g_FatalError(_lc[I_NET_MSG] + Format(_lc[I_NET_ERR_HOST], [Port]));
4782 Exit;
4783 end;
4785 g_Net_Slist_Set(NetMasterList);
4787 g_Net_Slist_ServerStarted();
4789 // Çàãðóçêà è çàïóñê êàðòû:
4790 if not g_Game_StartMap(false{asMegawad}, Map, True) then
4791 begin
4792 g_Net_Slist_ServerClosed();
4793 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [Map]));
4794 Exit;
4795 end;
4797 // Íåò òî÷åê ïîÿâëåíèÿ:
4798 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1) +
4799 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2) +
4800 g_Map_GetPointCount(RESPAWNPOINT_DM) +
4801 g_Map_GetPointCount(RESPAWNPOINT_RED)+
4802 g_Map_GetPointCount(RESPAWNPOINT_BLUE)) < 1 then
4803 begin
4804 g_Net_Slist_ServerClosed();
4805 g_FatalError(_lc[I_GAME_ERROR_GET_SPAWN]);
4806 Exit;
4807 end;
4809 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4810 g_Player_Init();
4812 g_Net_Slist_ServerMapStarted();
4813 NetState := NET_STATE_GAME;
4814 end;
4816 procedure g_Game_StartClient(Addr: String; Port: Word; PW: String);
4817 var
4818 Map: String;
4819 WadName: string;
4820 Ptr: Pointer;
4821 T: Cardinal;
4822 MID: Byte;
4823 State: Byte;
4824 OuterLoop: Boolean;
4825 newResPath: string;
4826 InMsg: TMsg;
4827 begin
4828 g_Game_Free();
4830 State := 0;
4831 e_WriteLog('Starting net game (client)...', TMsgType.Notify);
4832 e_WriteLog('NET: Trying to connect to ' + Addr + ':' + IntToStr(Port) + '...', TMsgType.Notify);
4834 g_Game_ClearLoading();
4836 ClearDebugCvars();
4838 // Íàñòðîéêè èãðû:
4839 gGameSettings.GameType := GT_CLIENT;
4841 gCoopTotalMonstersKilled := 0;
4842 gCoopTotalSecretsFound := 0;
4843 gCoopTotalMonsters := 0;
4844 gCoopTotalSecrets := 0;
4845 gAimLine := False;
4846 gShowMap := False;
4848 g_Game_ExecuteEvent('ongamestart');
4850 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
4851 g_Game_SetupScreenSize();
4853 NetState := NET_STATE_AUTH;
4855 g_Game_SetLoadingText(_lc[I_LOAD_CONNECT], 0, False);
4857 // create (or update) map/resource databases
4858 g_Res_CreateDatabases(true);
4860 gLMSRespawn := LMS_RESPAWN_NONE;
4861 gLMSRespawnTime := 0;
4862 gSpectLatchPID1 := 0;
4863 gSpectLatchPID2 := 0;
4865 // Ñòàðòóåì êëèåíò
4866 if not g_Net_Connect(Addr, Port) then
4867 begin
4868 g_FatalError(_lc[I_NET_MSG] + _lc[I_NET_ERR_CONN]);
4869 NetState := NET_STATE_NONE;
4870 Exit;
4871 end;
4873 g_Game_SetLoadingText(_lc[I_LOAD_SEND_INFO], 0, False);
4874 MC_SEND_Info(PW);
4875 g_Game_SetLoadingText(_lc[I_LOAD_WAIT_INFO], 0, False);
4877 OuterLoop := True;
4878 while OuterLoop do
4879 begin
4880 // fuck! https://www.mail-archive.com/enet-discuss@cubik.org/msg00852.html
4881 // tl;dr: on shitdows, we can get -1 sometimes, and it is *NOT* a failure.
4882 // thank you, enet. let's ignore failures altogether then.
4883 while (enet_host_service(NetHost, @NetEvent, 50) > 0) do
4884 begin
4885 if (NetEvent.kind = ENET_EVENT_TYPE_RECEIVE) then
4886 begin
4887 Ptr := NetEvent.packet^.data;
4888 if not InMsg.Init(Ptr, NetEvent.packet^.dataLength, True) then
4889 begin
4890 enet_packet_destroy(NetEvent.packet);
4891 continue;
4892 end;
4894 InMsg.ReadLongWord(); // skip size
4895 MID := InMsg.ReadByte();
4897 if (MID = NET_MSG_INFO) and (State = 0) then
4898 begin
4899 NetMyID := InMsg.ReadByte();
4900 NetPlrUID1 := InMsg.ReadWord();
4902 WadName := InMsg.ReadString();
4903 Map := InMsg.ReadString();
4905 gWADHash := InMsg.ReadMD5();
4907 gGameSettings.GameMode := InMsg.ReadByte();
4908 gSwitchGameMode := gGameSettings.GameMode;
4909 gGameSettings.ScoreLimit := InMsg.ReadWord();
4910 gGameSettings.TimeLimit := InMsg.ReadWord();
4911 gGameSettings.MaxLives := InMsg.ReadByte();
4912 gGameSettings.Options := InMsg.ReadLongWord();
4913 T := InMsg.ReadLongWord();
4915 //newResPath := g_Res_SearchSameWAD(MapsDir, WadName, gWADHash);
4916 //if newResPath = '' then
4917 begin
4918 //g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
4919 newResPath := g_Res_DownloadMapWAD(ExtractFileName(WadName), gWADHash);
4920 if newResPath = '' then
4921 begin
4922 g_FatalError(_lc[I_NET_ERR_HASH]);
4923 enet_packet_destroy(NetEvent.packet);
4924 NetState := NET_STATE_NONE;
4925 Exit;
4926 end;
4927 e_LogWritefln('using downloaded map wad [%s] for [%s]`', [newResPath, WadName], TMsgType.Notify);
4928 end;
4929 //newResPath := ExtractRelativePath(MapsDir, newResPath);
4932 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
4933 gPlayer1Settings.Color,
4934 gPlayer1Settings.Team, False));
4936 if gPlayer1 = nil then
4937 begin
4938 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]));
4940 enet_packet_destroy(NetEvent.packet);
4941 NetState := NET_STATE_NONE;
4942 Exit;
4943 end;
4945 gPlayer1.Name := gPlayer1Settings.Name;
4946 gPlayer1.WeapSwitchMode := gPlayer1Settings.WeaponSwitch;
4947 gPlayer1.setWeaponPrefs(gPlayer1Settings.WeaponPreferences);
4948 gPlayer1.SwitchToEmpty := gPlayer1Settings.SwitchToEmpty;
4949 gPlayer1.SkipFist := gPlayer1Settings.SkipFist;
4950 gPlayer1.UID := NetPlrUID1;
4951 gPlayer1.Reset(True);
4953 if not g_Game_StartMap(false{asMegawad}, newResPath + ':\' + Map, True) then
4954 begin
4955 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [WadName + ':\' + Map]));
4957 enet_packet_destroy(NetEvent.packet);
4958 NetState := NET_STATE_NONE;
4959 Exit;
4960 end;
4962 gTime := T;
4964 State := 1;
4965 OuterLoop := False;
4966 enet_packet_destroy(NetEvent.packet);
4967 break;
4968 end
4969 else
4970 enet_packet_destroy(NetEvent.packet);
4971 end
4972 else
4973 begin
4974 if (NetEvent.kind = ENET_EVENT_TYPE_DISCONNECT) then
4975 begin
4976 State := 0;
4977 if (NetEvent.data <= NET_DISC_MAX) then
4978 g_Console_Add(_lc[I_NET_MSG_ERROR] + _lc[I_NET_ERR_CONN] + ' ' +
4979 _lc[TStrings_Locale(Cardinal(I_NET_DISC_NONE) + NetEvent.data)], True);
4980 OuterLoop := False;
4981 Break;
4982 end;
4983 end;
4984 end;
4986 ProcessLoading(True);
4987 if g_Net_UserRequestExit() then
4988 begin
4989 State := 0;
4990 break;
4991 end;
4992 end;
4994 if State <> 1 then
4995 begin
4996 g_FatalError(_lc[I_NET_MSG] + _lc[I_NET_ERR_CONN]);
4997 NetState := NET_STATE_NONE;
4998 Exit;
4999 end;
5001 g_Player_Init();
5002 NetState := NET_STATE_GAME;
5003 MC_SEND_FullStateRequest;
5004 e_WriteLog('NET: Connection successful.', TMsgType.Notify);
5005 end;
5007 var
5008 lastAsMegaWad: Boolean = false;
5010 procedure g_Game_ChangeMap(const MapPath: String);
5011 var
5012 Force: Boolean;
5013 begin
5014 g_Game_ClearLoading();
5016 Force := gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF];
5017 // Åñëè óðîâåíü çàâåðøèëñÿ ïî òðèããåðó Âûõîä, íå î÷èùàòü èíâåíòàðü
5018 if gExitByTrigger then
5019 begin
5020 Force := False;
5021 gExitByTrigger := False;
5022 end;
5023 if not g_Game_StartMap(lastAsMegaWad, MapPath, Force) then
5024 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [MapPath]));
5025 end;
5027 procedure g_Game_Restart();
5028 var
5029 Map: string;
5030 begin
5031 if g_Game_IsClient then
5032 Exit;
5033 map := g_ExtractFileName(gMapInfo.Map);
5034 e_LogWritefln('g_Game_Restart: map = "%s" gCurrentMapFileName = "%s"', [map, gCurrentMapFileName]);
5036 MessageTime := 0;
5037 gGameOn := False;
5038 g_Game_ClearLoading();
5039 g_Game_StartMap(lastAsMegaWad, Map, True, gCurrentMapFileName);
5040 end;
5042 function g_Game_StartMap (asMegawad: Boolean; Map: String; Force: Boolean = False; const oldMapPath: AnsiString=''): Boolean;
5043 var
5044 NewWAD, ResName: String;
5045 I: Integer;
5046 nws: AnsiString;
5047 begin
5048 g_Map_Free((Map <> gCurrentMapFileName) and (oldMapPath <> gCurrentMapFileName));
5049 g_Player_RemoveAllCorpses();
5051 if (not g_Game_IsClient) and
5052 (gSwitchGameMode <> gGameSettings.GameMode) and
5053 (gGameSettings.GameMode <> GM_SINGLE) then
5054 begin
5055 if gSwitchGameMode = GM_CTF then
5056 gGameSettings.MaxLives := 0;
5057 gGameSettings.GameMode := gSwitchGameMode;
5058 Force := True;
5059 end else
5060 gSwitchGameMode := gGameSettings.GameMode;
5062 g_Player_ResetTeams();
5064 lastAsMegaWad := asMegawad;
5065 if isWadPath(Map) then
5066 begin
5067 NewWAD := g_ExtractWadName(Map);
5068 ResName := g_ExtractFileName(Map);
5069 if g_Game_IsServer then
5070 begin
5071 nws := findDiskWad(NewWAD);
5072 //writeln('000: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
5073 if (asMegawad) then
5074 begin
5075 if (length(nws) = 0) then nws := e_FindWad(MegawadDirs, NewWAD);
5076 if (length(nws) = 0) then nws := e_FindWad(MapDirs, NewWAD);
5077 end
5078 else
5079 begin
5080 if (length(nws) = 0) then nws := e_FindWad(MapDirs, NewWAD);
5081 if (length(nws) = 0) then nws := e_FindWad(MegawadDirs, NewWAD);
5082 end;
5083 //if (length(nws) = 0) then nws := e_FindWad(MapDownloadDirs, NewWAD);
5084 //writeln('001: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
5085 //nws := NewWAD;
5086 if (length(nws) = 0) then
5087 begin
5088 ResName := ''; // failed
5089 end
5090 else
5091 begin
5092 NewWAD := nws;
5093 if (g_Game_IsNet) then gWADHash := MD5File(nws);
5094 //writeln('********: nws=', nws, ' : Map=', Map, ' : nw=', NewWAD, ' : resname=', ResName);
5095 g_Game_LoadWAD(NewWAD);
5096 end;
5097 end
5098 else
5099 begin
5100 // hash received in MC_RECV_GameEvent -> NET_EV_MAPSTART
5101 NewWAD := g_Game_ClientWAD(NewWAD, gWADHash);
5102 end;
5103 end
5104 else
5105 begin
5106 NewWAD := gGameSettings.WAD;
5107 ResName := Map;
5108 end;
5110 gTime := 0;
5112 //writeln('********: gsw=', gGameSettings.WAD, '; rn=', ResName);
5113 result := false;
5114 if (ResName <> '') and (NewWAD <> '') then
5115 begin
5116 //result := g_Map_Load(gGameSettings.WAD + ':\' + ResName);
5117 result := g_Map_Load(NewWAD+':\'+ResName);
5118 end;
5119 if Result then
5120 begin
5121 g_Player_ResetAll(Force or gLastMap, gGameSettings.GameType = GT_SINGLE);
5123 gState := STATE_NONE;
5124 g_ActiveWindow := nil;
5125 gGameOn := True;
5127 DisableCheats();
5128 ResetTimer();
5130 if gGameSettings.GameMode = GM_CTF then
5131 begin
5132 g_Map_ResetFlag(FLAG_RED);
5133 g_Map_ResetFlag(FLAG_BLUE);
5134 // CTF, à ôëàãîâ íåò:
5135 if not g_Map_HaveFlagPoints() then
5136 g_SimpleError(_lc[I_GAME_ERROR_CTF]);
5137 end;
5138 end
5139 else
5140 begin
5141 gState := STATE_MENU;
5142 gGameOn := False;
5143 end;
5145 gExit := 0;
5146 gPauseMain := false;
5147 gPauseHolmes := false;
5148 NetTimeToUpdate := 1;
5149 NetTimeToReliable := 0;
5150 NetTimeToMaster := NetMasterRate;
5151 gSpectLatchPID1 := 0;
5152 gSpectLatchPID2 := 0;
5153 gMissionFailed := False;
5154 gNextMap := '';
5156 gCoopMonstersKilled := 0;
5157 gCoopSecretsFound := 0;
5159 gVoteInProgress := False;
5160 gVotePassed := False;
5161 gVoteCount := 0;
5162 gVoted := False;
5164 gStatsOff := False;
5166 if not gGameOn then Exit;
5168 g_Game_SpectateCenterView();
5170 if g_Game_IsServer then
5171 begin
5172 if (gGameSettings.MaxLives > 0) and (gGameSettings.WarmupTime > 0) then
5173 begin
5174 gLMSRespawn := LMS_RESPAWN_WARMUP;
5175 gLMSRespawnTime := gTime + gGameSettings.WarmupTime*1000;
5176 gLMSSoftSpawn := True;
5177 if g_Game_IsNet then
5178 MH_SEND_GameEvent(NET_EV_LMS_WARMUP, gLMSRespawnTime - gTime);
5179 end
5180 else
5181 begin
5182 gLMSRespawn := LMS_RESPAWN_NONE;
5183 gLMSRespawnTime := 0;
5184 end;
5185 end;
5187 if NetMode = NET_SERVER then
5188 begin
5189 // reset full state flags
5190 if NetClients <> nil then
5191 for I := 0 to High(NetClients) do
5192 NetClients[I].FullUpdateSent := False;
5194 MH_SEND_GameEvent(NET_EV_MAPSTART, gGameSettings.GameMode, Map);
5196 // Ìàñòåðñåðâåð
5197 g_Net_Slist_ServerMapStarted();
5199 if NetClients <> nil then
5200 for I := 0 to High(NetClients) do
5201 if NetClients[I].Used then
5202 begin
5203 NetClients[I].Voted := False;
5204 if NetClients[I].RequestedFullUpdate then
5205 begin
5206 MH_SEND_Everything((NetClients[I].State = NET_STATE_AUTH), I);
5207 NetClients[I].RequestedFullUpdate := False;
5208 end;
5209 end;
5211 g_Net_UnbanNonPerm();
5212 end;
5214 if gLastMap then
5215 begin
5216 gCoopTotalMonstersKilled := 0;
5217 gCoopTotalSecretsFound := 0;
5218 gCoopTotalMonsters := 0;
5219 gCoopTotalSecrets := 0;
5220 gLastMap := False;
5221 end;
5223 g_Game_ExecuteEvent('onmapstart');
5224 end;
5226 procedure SetFirstLevel;
5227 begin
5228 gNextMap := '';
5230 MapList := g_Map_GetMapsList(gGameSettings.WAD);
5231 if MapList = nil then
5232 Exit;
5234 SortSArray(MapList);
5235 gNextMap := MapList[Low(MapList)];
5237 MapList := nil;
5238 end;
5240 procedure g_Game_ExitLevel(const Map: AnsiString);
5241 begin
5242 gNextMap := Map;
5244 gCoopTotalMonstersKilled := gCoopTotalMonstersKilled + gCoopMonstersKilled;
5245 gCoopTotalSecretsFound := gCoopTotalSecretsFound + gCoopSecretsFound;
5246 gCoopTotalMonsters := gCoopTotalMonsters + gTotalMonsters;
5247 gCoopTotalSecrets := gCoopTotalSecrets + gSecretsCount;
5249 // Âûøëè â âûõîä â Îäèíî÷íîé èãðå:
5250 if gGameSettings.GameType = GT_SINGLE then
5251 gExit := EXIT_ENDLEVELSINGLE
5252 else // Âûøëè â âûõîä â Ñâîåé èãðå
5253 begin
5254 gExit := EXIT_ENDLEVELCUSTOM;
5255 if gGameSettings.GameMode = GM_COOP then
5256 g_Player_RememberAll;
5258 if not g_Map_Exist(gGameSettings.WAD + ':\' + gNextMap) then
5259 begin
5260 gLastMap := True;
5261 if gGameSettings.GameMode = GM_COOP then
5262 gStatsOff := True;
5264 gStatsPressed := True;
5265 gNextMap := 'MAP01';
5267 if not g_Map_Exist(gGameSettings.WAD + ':\' + gNextMap) then
5268 g_Game_NextLevel;
5270 if g_Game_IsNet then
5271 begin
5272 MH_SEND_GameStats();
5273 MH_SEND_CoopStats();
5274 end;
5275 end;
5276 end;
5277 end;
5279 procedure g_Game_RestartLevel();
5280 var
5281 Map: string;
5282 begin
5283 if gGameSettings.GameMode = GM_SINGLE then
5284 begin
5285 g_Game_Restart();
5286 Exit;
5287 end;
5288 gExit := EXIT_ENDLEVELCUSTOM;
5289 Map := g_ExtractFileName(gMapInfo.Map);
5290 gNextMap := Map;
5291 end;
5293 function g_Game_ClientWAD (NewWAD: String; const WHash: TMD5Digest): AnsiString;
5294 var
5295 gWAD{, xwad}: String;
5296 begin
5297 result := NewWAD;
5298 if not g_Game_IsClient then Exit;
5299 //e_LogWritefln('*** g_Game_ClientWAD: `%s`', [NewWAD]);
5301 gWAD := g_Res_DownloadMapWAD(ExtractFileName(NewWAD), WHash);
5302 if gWAD = '' then
5303 begin
5304 result := '';
5305 g_Game_Free();
5306 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_WAD], [ExtractFileName(NewWAD)]));
5307 Exit;
5308 end;
5310 e_LogWritefln('using downloaded client map wad [%s] for [%s]', [gWAD, NewWAD], TMsgType.Notify);
5311 NewWAD := gWAD;
5313 g_Game_LoadWAD(NewWAD);
5314 result := NewWAD;
5317 if LowerCase(NewWAD) = LowerCase(gGameSettings.WAD) then Exit;
5318 gWAD := g_Res_SearchSameWAD(MapsDir, ExtractFileName(NewWAD), WHash);
5319 if gWAD = '' then
5320 begin
5321 g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
5322 gWAD := g_Res_DownloadMapWAD(ExtractFileName(NewWAD), WHash);
5323 if gWAD = '' then
5324 begin
5325 g_Game_Free();
5326 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_WAD], [ExtractFileName(NewWAD)]));
5327 Exit;
5328 end;
5329 end;
5330 NewWAD := ExtractRelativePath(MapsDir, gWAD);
5331 g_Game_LoadWAD(NewWAD);
5333 end;
5335 procedure g_Game_RestartRound(NoMapRestart: Boolean = False);
5336 var
5337 i, n, nb, nr: Integer;
5338 begin
5339 if not g_Game_IsServer then Exit;
5340 if gLMSRespawn = LMS_RESPAWN_NONE then Exit;
5341 gLMSRespawn := LMS_RESPAWN_NONE;
5342 gLMSRespawnTime := 0;
5343 MessageTime := 0;
5345 if (gGameSettings.GameMode = GM_COOP) and not NoMapRestart then
5346 begin
5347 gMissionFailed := True;
5348 g_Game_RestartLevel;
5349 Exit;
5350 end;
5352 n := 0; nb := 0; nr := 0;
5353 for i := Low(gPlayers) to High(gPlayers) do
5354 if (gPlayers[i] <> nil) and
5355 ((not gPlayers[i].FSpectator) or gPlayers[i].FWantsInGame or
5356 (gPlayers[i] is TBot)) then
5357 begin
5358 Inc(n);
5359 if gPlayers[i].Team = TEAM_RED then Inc(nr)
5360 else if gPlayers[i].Team = TEAM_BLUE then Inc(nb)
5361 end;
5363 if (n < 1) or ((gGameSettings.GameMode = GM_TDM) and ((nr = 0) or (nb = 0))) then
5364 begin
5365 // wait a second until the fuckers finally decide to join
5366 gLMSRespawn := LMS_RESPAWN_WARMUP;
5367 gLMSRespawnTime := gTime + gGameSettings.WarmupTime*1000;
5368 gLMSSoftSpawn := NoMapRestart;
5369 if g_Game_IsNet then
5370 MH_SEND_GameEvent(NET_EV_LMS_WARMUP, gLMSRespawnTime - gTime);
5371 Exit;
5372 end;
5374 g_Player_RemoveAllCorpses;
5375 g_Game_Message(_lc[I_MESSAGE_LMS_START], 144);
5376 if g_Game_IsNet then
5377 MH_SEND_GameEvent(NET_EV_LMS_START);
5379 for i := Low(gPlayers) to High(gPlayers) do
5380 begin
5381 if gPlayers[i] = nil then continue;
5382 if gPlayers[i] is TBot then gPlayers[i].FWantsInGame := True;
5383 // don't touch normal spectators
5384 if gPlayers[i].FSpectator and not gPlayers[i].FWantsInGame then
5385 begin
5386 gPlayers[i].FNoRespawn := True;
5387 gPlayers[i].Lives := 0;
5388 if g_Game_IsNet then
5389 MH_SEND_PlayerStats(gPlayers[I].UID);
5390 continue;
5391 end;
5392 gPlayers[i].FNoRespawn := False;
5393 gPlayers[i].Lives := gGameSettings.MaxLives;
5394 gPlayers[i].Respawn(False, True);
5395 if gGameSettings.GameMode = GM_COOP then
5396 begin
5397 gPlayers[i].Frags := 0;
5398 gPlayers[i].RecallState;
5399 end;
5400 if (gPlayer1 = nil) and (gSpectLatchPID1 > 0) then
5401 gPlayer1 := g_Player_Get(gSpectLatchPID1);
5402 if (gPlayer2 = nil) and (gSpectLatchPID2 > 0) then
5403 gPlayer2 := g_Player_Get(gSpectLatchPID2);
5404 end;
5406 g_Items_RestartRound();
5408 gLMSSoftSpawn := False;
5409 end;
5411 function g_Game_GetFirstMap(WAD: String): String;
5412 begin
5413 Result := '';
5415 MapList := g_Map_GetMapsList(WAD);
5416 if MapList = nil then
5417 Exit;
5419 SortSArray(MapList);
5420 Result := MapList[Low(MapList)];
5422 if not g_Map_Exist(WAD + ':\' + Result) then
5423 Result := '';
5425 MapList := nil;
5426 end;
5428 function g_Game_GetNextMap(): String;
5429 var
5430 I: Integer;
5431 Map: string;
5432 begin
5433 Result := '';
5435 MapList := g_Map_GetMapsList(gGameSettings.WAD);
5436 if MapList = nil then
5437 Exit;
5439 Map := g_ExtractFileName(gMapInfo.Map);
5441 SortSArray(MapList);
5442 MapIndex := -255;
5443 for I := Low(MapList) to High(MapList) do
5444 if Map = MapList[I] then
5445 begin
5446 MapIndex := I;
5447 Break;
5448 end;
5450 if MapIndex <> -255 then
5451 begin
5452 if MapIndex = High(MapList) then
5453 Result := MapList[Low(MapList)]
5454 else
5455 Result := MapList[MapIndex + 1];
5457 if not g_Map_Exist(gGameSettings.WAD + ':\' + Result) then Result := Map;
5458 end;
5460 MapList := nil;
5461 end;
5463 procedure g_Game_NextLevel();
5464 begin
5465 if gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF, GM_COOP] then
5466 gExit := EXIT_ENDLEVELCUSTOM
5467 else
5468 begin
5469 gExit := EXIT_ENDLEVELSINGLE;
5470 Exit;
5471 end;
5473 if gNextMap <> '' then Exit;
5474 gNextMap := g_Game_GetNextMap();
5475 end;
5477 function g_Game_IsTestMap(): Boolean;
5478 begin
5479 result := StrEquCI1251(TEST_MAP_NAME, g_ExtractFileName(gMapInfo.Map));
5480 end;
5482 procedure g_Game_DeleteTestMap();
5483 var
5484 a: Integer;
5485 //MapName: AnsiString;
5486 WadName: string;
5488 WAD: TWADFile;
5489 MapList: SSArray;
5490 time: Integer;
5492 begin
5493 a := Pos('.wad:\', toLowerCase1251(gMapToDelete));
5494 if (a = 0) then a := Pos('.wad:/', toLowerCase1251(gMapToDelete));
5495 if (a = 0) then exit;
5497 // Âûäåëÿåì èìÿ wad-ôàéëà è èìÿ êàðòû
5498 WadName := Copy(gMapToDelete, 1, a+3);
5499 Delete(gMapToDelete, 1, a+5);
5500 gMapToDelete := UpperCase(gMapToDelete);
5501 //MapName := '';
5502 //CopyMemory(@MapName[0], @gMapToDelete[1], Min(16, Length(gMapToDelete)));
5505 // Èìÿ êàðòû íå ñòàíäàðòíîå òåñòîâîå:
5506 if MapName <> TEST_MAP_NAME then
5507 Exit;
5509 if not gTempDelete then
5510 begin
5511 time := g_GetFileTime(WadName);
5512 WAD := TWADFile.Create();
5514 // ×èòàåì Wad-ôàéë:
5515 if not WAD.ReadFile(WadName) then
5516 begin // Íåò òàêîãî WAD-ôàéëà
5517 WAD.Free();
5518 Exit;
5519 end;
5521 // Ñîñòàâëÿåì ñïèñîê êàðò è èùåì íóæíóþ:
5522 WAD.CreateImage();
5523 MapList := WAD.GetResourcesList('');
5525 if MapList <> nil then
5526 for a := 0 to High(MapList) do
5527 if MapList[a] = MapName then
5528 begin
5529 // Óäàëÿåì è ñîõðàíÿåì:
5530 WAD.RemoveResource('', MapName);
5531 WAD.SaveTo(WadName);
5532 Break;
5533 end;
5535 WAD.Free();
5536 g_SetFileTime(WadName, time);
5537 end else
5539 if gTempDelete then DeleteFile(WadName);
5540 end;
5542 procedure GameCVars(P: SSArray);
5543 var
5544 a, b: Integer;
5545 stat: TPlayerStatArray;
5546 cmd: string;
5547 it: PItem;
5549 procedure ParseGameFlag(Flag: LongWord; OffMsg, OnMsg: TStrings_Locale; OnMapChange: Boolean = False);
5550 var
5551 x: Boolean;
5552 begin
5553 if Length(P) > 1 then
5554 begin
5555 x := P[1] = '1';
5557 if x then
5558 gsGameFlags := gsGameFlags or Flag
5559 else
5560 gsGameFlags := gsGameFlags and (not Flag);
5562 if g_Game_IsServer then
5563 begin
5564 if x then
5565 gGameSettings.Options := gGameSettings.Options or Flag
5566 else
5567 gGameSettings.Options := gGameSettings.Options and (not Flag);
5568 if g_Game_IsNet then MH_SEND_GameSettings;
5569 end;
5570 end;
5572 if LongBool(gsGameFlags and Flag) then
5573 g_Console_Add(_lc[OnMsg])
5574 else
5575 g_Console_Add(_lc[OffMsg]);
5577 if OnMapChange and g_Game_IsServer then
5578 g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
5579 end;
5581 begin
5582 stat := nil;
5583 cmd := LowerCase(P[0]);
5585 if cmd = 'g_gamemode' then
5586 begin
5587 if (Length(P) > 1) then
5588 begin
5589 a := g_Game_TextToMode(P[1]);
5590 if a = GM_SINGLE then a := GM_COOP;
5591 gsGameMode := g_Game_ModeToText(a);
5592 if g_Game_IsServer then
5593 begin
5594 gSwitchGameMode := a;
5595 if (gGameOn and (gGameSettings.GameMode = GM_SINGLE)) or
5596 (gState = STATE_INTERSINGLE) then
5597 gSwitchGameMode := GM_SINGLE;
5598 if not gGameOn then
5599 gGameSettings.GameMode := gSwitchGameMode;
5600 end;
5601 end;
5603 if gSwitchGameMode = gGameSettings.GameMode then
5604 g_Console_Add(Format(_lc[I_MSG_GAMEMODE_CURRENT],
5605 [g_Game_ModeToText(gGameSettings.GameMode)]))
5606 else
5607 g_Console_Add(Format(_lc[I_MSG_GAMEMODE_CHANGE],
5608 [g_Game_ModeToText(gGameSettings.GameMode),
5609 g_Game_ModeToText(gSwitchGameMode)]));
5610 end
5611 else if cmd = 'g_friendlyfire' then
5612 begin
5613 ParseGameFlag(GAME_OPTION_TEAMDAMAGE, I_MSG_FRIENDLY_FIRE_OFF, I_MSG_FRIENDLY_FIRE_ON);
5614 end
5615 else if cmd = 'g_friendly_absorb_damage' then
5616 begin
5617 ParseGameFlag(GAME_OPTION_TEAMABSORBDAMAGE, I_MSG_FRIENDLY_ABSORB_DAMAGE_OFF, I_MSG_FRIENDLY_ABSORB_DAMAGE_ON);
5618 end
5619 else if cmd = 'g_friendly_hit_trace' then
5620 begin
5621 ParseGameFlag(GAME_OPTION_TEAMHITTRACE, I_MSG_FRIENDLY_HIT_TRACE_OFF, I_MSG_FRIENDLY_HIT_TRACE_ON);
5622 end
5623 else if cmd = 'g_friendly_hit_projectile' then
5624 begin
5625 ParseGameFlag(GAME_OPTION_TEAMHITPROJECTILE, I_MSG_FRIENDLY_PROJECT_TRACE_OFF, I_MSG_FRIENDLY_PROJECT_TRACE_ON);
5626 end
5627 else if cmd = 'g_items_all_respawn_random' then
5628 begin
5629 ParseGameFlag(GAME_OPTION_ITEMALLRANDOM, I_MSG_ITEM_ALL_RANDOM_OFF, I_MSG_ITEM_ALL_RANDOM_ON, False);
5630 end
5631 else if cmd = 'g_items_help_respawn_random' then
5632 begin
5633 ParseGameFlag(GAME_OPTION_ITEMHELPRANDOM, I_MSG_ITEM_HELP_RANDOM_OFF, I_MSG_ITEM_HELP_RANDOM_ON, False);
5634 end
5635 else if cmd = 'g_items_ammo_respawn_random' then
5636 begin
5637 ParseGameFlag(GAME_OPTION_ITEMAMMORANDOM, I_MSG_ITEM_AMMO_RANDOM_OFF, I_MSG_ITEM_AMMO_RANDOM_ON, False);
5638 end
5639 else if cmd = 'g_items_weapon_respawn_random' then
5640 begin
5641 ParseGameFlag(GAME_OPTION_ITEMWEAPONRANDOM, I_MSG_ITEM_WEAPON_RANDOM_OFF, I_MSG_ITEM_WEAPON_RANDOM_ON);
5642 end
5643 else if cmd = 'g_powerup_randomize_respawn' then
5644 begin
5645 ParseGameFlag(GAME_OPTION_RULEZRANDOM, I_MSG_RULEZ_RANDOM_OFF, I_MSG_RULEZ_RANDOM_ON, False);
5646 end
5647 else if cmd = 'g_weaponstay' then
5648 begin
5649 ParseGameFlag(GAME_OPTION_WEAPONSTAY, I_MSG_WEAPONSTAY_OFF, I_MSG_WEAPONSTAY_ON);
5650 end
5651 else if cmd = 'g_allow_exit' then
5652 begin
5653 ParseGameFlag(GAME_OPTION_ALLOWEXIT, I_MSG_ALLOWEXIT_OFF, I_MSG_ALLOWEXIT_ON, True);
5654 end
5655 else if cmd = 'g_allow_monsters' then
5656 begin
5657 ParseGameFlag(GAME_OPTION_MONSTERS, I_MSG_ALLOWMON_OFF, I_MSG_ALLOWMON_ON, True);
5658 end
5659 else if cmd = 'g_allow_dropflag' then
5660 begin
5661 ParseGameFlag(GAME_OPTION_ALLOWDROPFLAG, I_MSG_ALLOWDROPFLAG_OFF, I_MSG_ALLOWDROPFLAG_ON);
5662 end
5663 else if cmd = 'g_throw_flag' then
5664 begin
5665 ParseGameFlag(GAME_OPTION_THROWFLAG, I_MSG_THROWFLAG_OFF, I_MSG_THROWFLAG_ON);
5666 end
5667 else if cmd = 'g_bot_vsplayers' then
5668 begin
5669 ParseGameFlag(GAME_OPTION_BOTVSPLAYER, I_MSG_BOTSVSPLAYERS_OFF, I_MSG_BOTSVSPLAYERS_ON);
5670 end
5671 else if cmd = 'g_bot_vsmonsters' then
5672 begin
5673 ParseGameFlag(GAME_OPTION_BOTVSMONSTER, I_MSG_BOTSVSMONSTERS_OFF, I_MSG_BOTSVSMONSTERS_ON);
5674 end
5675 else if cmd = 'g_dm_keys' then
5676 begin
5677 ParseGameFlag(GAME_OPTION_DMKEYS, I_MSG_DMKEYS_OFF, I_MSG_DMKEYS_ON, True);
5678 end
5679 else if cmd = 'g_gameflags' then
5680 begin
5681 if Length(P) > 1 then
5682 begin
5683 gsGameFlags := StrToDWordDef(P[1], gsGameFlags);
5684 if g_Game_IsServer then
5685 begin
5686 gGameSettings.Options := gsGameFlags;
5687 if g_Game_IsNet then MH_SEND_GameSettings;
5688 end;
5689 end;
5691 g_Console_Add(Format('%s %u', [cmd, gsGameFlags]));
5692 end
5693 else if cmd = 'g_warmup_time' then
5694 begin
5695 if Length(P) > 1 then
5696 begin
5697 gsWarmupTime := nclamp(StrToIntDef(P[1], gsWarmupTime), 0, $FFFF);
5698 if g_Game_IsServer then
5699 begin
5700 gGameSettings.WarmupTime := gsWarmupTime;
5701 // extend warmup if it's already going
5702 if gLMSRespawn = LMS_RESPAWN_WARMUP then
5703 begin
5704 gLMSRespawnTime := gTime + gsWarmupTime * 1000;
5705 if g_Game_IsNet then MH_SEND_GameEvent(NET_EV_LMS_WARMUP, gLMSRespawnTime - gTime);
5706 end;
5707 if g_Game_IsNet then MH_SEND_GameSettings;
5708 end;
5709 end;
5711 g_Console_Add(Format(_lc[I_MSG_WARMUP], [Integer(gsWarmupTime)]));
5712 if g_Game_IsServer then g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
5713 end
5714 else if cmd = 'g_spawn_invul' then
5715 begin
5716 if Length(P) > 1 then
5717 begin
5718 gsSpawnInvul := nclamp(StrToIntDef(P[1], gsSpawnInvul), 0, $FFFF);
5719 if g_Game_IsServer then
5720 begin
5721 gGameSettings.SpawnInvul := gsSpawnInvul;
5722 if g_Game_IsNet then MH_SEND_GameSettings;
5723 end;
5724 end;
5726 g_Console_Add(Format('%s %d', [cmd, Integer(gsSpawnInvul)]));
5727 end
5728 else if cmd = 'g_item_respawn_time' then
5729 begin
5730 if Length(P) > 1 then
5731 begin
5732 gsItemRespawnTime := nclamp(StrToIntDef(P[1], gsItemRespawnTime), 0, $FFFF);
5733 if g_Game_IsServer then
5734 begin
5735 gGameSettings.ItemRespawnTime := gsItemRespawnTime;
5736 if g_Game_IsNet then MH_SEND_GameSettings;
5737 end;
5738 end;
5740 g_Console_Add(Format('%s %d', [cmd, Integer(gsItemRespawnTime)]));
5741 if g_Game_IsServer then g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
5742 end
5743 else if cmd = 'g_item_time_random' then
5744 begin
5745 if Length(P) > 1 then
5746 begin
5747 gsItemRespawnRandom := nclamp(StrToIntDef(P[1], gsItemRespawnRandom), 0, $FFFF);
5748 if g_Game_IsServer then
5749 begin
5750 gGameSettings.ItemRespawnRandom := gsItemRespawnRandom;
5751 if g_Game_IsNet then MH_SEND_GameSettings;
5752 end;
5753 end;
5755 g_Console_Add(Format('%s %d', [cmd, Integer(gsItemRespawnRandom)]));
5756 if g_Game_IsServer then g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
5757 end
5758 else if cmd = 'g_powerup_respawn_time' then
5759 begin
5760 if Length(P) > 1 then
5761 begin
5762 gsRulezRespawnTime := nclamp(StrToIntDef(P[1], gsRulezRespawnTime), 0, $FFFF);
5763 if g_Game_IsServer then
5764 begin
5765 gGameSettings.RulezRespawnTime := gsRulezRespawnTime;
5766 if g_Game_IsNet then MH_SEND_GameSettings;
5767 end;
5768 end;
5770 g_Console_Add(Format('%s %d', [cmd, Integer(gsRulezRespawnTime)]));
5771 if g_Game_IsServer then g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
5772 end
5773 else if cmd = 'g_powerup_time_random' then
5774 begin
5775 if Length(P) > 1 then
5776 begin
5777 gsRulezRespawnRandom := nclamp(StrToIntDef(P[1], gsRulezRespawnRandom), 0, $FFFF);
5778 if g_Game_IsServer then
5779 begin
5780 gGameSettings.RulezRespawnRandom := gsRulezRespawnRandom;
5781 if g_Game_IsNet then MH_SEND_GameSettings;
5782 end;
5783 end;
5785 g_Console_Add(Format('%s %d', [cmd, Integer(gsRulezRespawnRandom)]));
5786 if g_Game_IsServer then g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
5787 end
5788 else if cmd = 'sv_intertime' then
5789 begin
5790 if (Length(P) > 1) then
5791 gDefInterTime := Min(Max(StrToIntDef(P[1], gDefInterTime), -1), 120);
5793 g_Console_Add(cmd + ' = ' + IntToStr(gDefInterTime));
5794 end
5795 else if cmd = 'g_max_particles' then
5796 begin
5797 if Length(p) = 2 then
5798 begin
5799 a := Max(0, StrToIntDef(p[1], 0));
5800 g_GFX_SetMax(a)
5801 end
5802 else if Length(p) = 1 then
5803 begin
5804 e_LogWritefln('%s', [g_GFX_GetMax()])
5805 end
5806 else
5807 begin
5808 e_LogWritefln('usage: %s <n>', [cmd])
5809 end
5810 end
5811 else if cmd = 'g_max_shells' then
5812 begin
5813 if Length(p) = 2 then
5814 begin
5815 a := Max(0, StrToIntDef(p[1], 0));
5816 g_Shells_SetMax(a)
5817 end
5818 else if Length(p) = 1 then
5819 begin
5820 e_LogWritefln('%s', [g_Shells_GetMax()])
5821 end
5822 else
5823 begin
5824 e_LogWritefln('usage: %s <n>', [cmd])
5825 end
5826 end
5827 else if cmd = 'g_max_gibs' then
5828 begin
5829 if Length(p) = 2 then
5830 begin
5831 a := Max(0, StrToIntDef(p[1], 0));
5832 g_Gibs_SetMax(a)
5833 end
5834 else if Length(p) = 1 then
5835 begin
5836 e_LogWritefln('%s', [g_Gibs_GetMax()])
5837 end
5838 else
5839 begin
5840 e_LogWritefln('usage: %s <n>', [cmd])
5841 end
5842 end
5843 else if cmd = 'g_max_corpses' then
5844 begin
5845 if Length(p) = 2 then
5846 begin
5847 a := Max(0, StrToIntDef(p[1], 0));
5848 g_Corpses_SetMax(a)
5849 end
5850 else if Length(p) = 1 then
5851 begin
5852 e_LogWritefln('%s', [g_Corpses_GetMax()])
5853 end
5854 else
5855 begin
5856 e_LogWritefln('usage: %s <n>', [cmd])
5857 end
5858 end
5859 else if cmd = 'g_force_model' then
5860 begin
5861 if Length(p) = 2 then
5862 begin
5863 a := StrToIntDef(p[1], 0);
5864 g_Force_Model_Set(a);
5865 if (g_Force_Model_Get() <> 0) and (gPlayers <> nil) then
5866 begin
5867 for a := Low(gPlayers) to High(gPlayers) do
5868 begin
5869 if (gPlayers[a] <> nil) then
5870 begin
5871 if (gPlayers[a].UID = gPlayer1.UID) then
5872 continue
5873 else if (gPlayer2 <> nil) and (gPlayers[a].UID = gPlayer2.UID) then
5874 continue;
5875 gPlayers[a].setModel(g_Forced_Model_GetName());
5876 end;
5877 end
5878 end
5879 else 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(gPlayers[a].FActualModelName);
5890 end;
5891 end
5892 end
5893 end
5894 end
5895 else if cmd = 'g_force_model_name' then
5896 begin
5897 if (Length(P) > 1) then
5898 begin
5899 cmd := b_Text_Unformat(P[1]);
5900 g_Forced_Model_SetName(cmd);
5901 if (g_Force_Model_Get() <> 0) and (gPlayers <> nil) then
5902 begin
5903 for a := Low(gPlayers) to High(gPlayers) do
5904 begin
5905 if (gPlayers[a] <> nil) then
5906 begin
5907 if (gPlayers[a].UID = gPlayer1.UID) then
5908 continue
5909 else if (gPlayer2 <> nil) and (gPlayers[a].UID = gPlayer2.UID) then
5910 continue;
5911 gPlayers[a].setModel(g_Forced_Model_GetName());
5912 end;
5913 end
5914 end
5915 end
5916 end
5917 else if cmd = 'g_scorelimit' then
5918 begin
5919 if Length(P) > 1 then
5920 begin
5921 gsScoreLimit := nclamp(StrToIntDef(P[1], gsScoreLimit), 0, $FFFF);
5923 if g_Game_IsServer then
5924 begin
5925 b := 0;
5926 if gGameSettings.GameMode = GM_DM then
5927 begin // DM
5928 stat := g_Player_GetStats();
5929 if stat <> nil then
5930 for a := 0 to High(stat) do
5931 if stat[a].Frags > b then
5932 b := stat[a].Frags;
5933 end
5934 else // TDM/CTF
5935 b := Max(gTeamStat[TEAM_RED].Score, gTeamStat[TEAM_BLUE].Score);
5937 // if someone has a higher score, set it to that instead
5938 gsScoreLimit := max(gsScoreLimit, b);
5939 gGameSettings.ScoreLimit := gsScoreLimit;
5941 if g_Game_IsNet then MH_SEND_GameSettings;
5942 end;
5943 end;
5945 g_Console_Add(Format(_lc[I_MSG_SCORE_LIMIT], [Integer(gsScoreLimit)]));
5946 end
5947 else if cmd = 'g_timelimit' then
5948 begin
5949 if Length(P) > 1 then
5950 begin
5951 gsTimeLimit := nclamp(StrToIntDef(P[1], gsTimeLimit), 0, $FFFF);
5952 if g_Game_IsServer then
5953 begin
5954 gGameSettings.TimeLimit := gsTimeLimit;
5955 if g_Game_IsNet then MH_SEND_GameSettings;
5956 end;
5957 end;
5958 g_Console_Add(Format(_lc[I_MSG_TIME_LIMIT],
5959 [gsTimeLimit div 3600,
5960 (gsTimeLimit div 60) mod 60,
5961 gsTimeLimit mod 60]));
5962 end
5963 else if cmd = 'g_max_bots' then
5964 begin
5965 if Length(P) > 1 then
5966 gMaxBots := nclamp(StrToIntDef(P[1], gMaxBots), 0, 127);
5967 g_Console_Add('g_max_bots = ' + IntToStr(gMaxBots));
5968 end
5969 else if cmd = 'g_maxlives' then
5970 begin
5971 if Length(P) > 1 then
5972 begin
5973 gsMaxLives := nclamp(StrToIntDef(P[1], gsMaxLives), 0, $FFFF);
5974 if g_Game_IsServer then
5975 begin
5976 gGameSettings.MaxLives := gsMaxLives;
5977 if g_Game_IsNet then MH_SEND_GameSettings;
5978 end;
5979 end;
5981 g_Console_Add(Format(_lc[I_MSG_LIVES], [Integer(gsMaxLives)]));
5982 end;
5983 end;
5985 procedure PlayerSettingsCVars(P: SSArray);
5986 var
5987 cmd: string;
5988 team: Byte;
5990 function ParseTeam(s: string): Byte;
5991 begin
5992 result := 0;
5993 case s of
5994 'red', '1': result := TEAM_RED;
5995 'blue', '2': result := TEAM_BLUE;
5996 else result := TEAM_NONE;
5997 end;
5998 end;
5999 begin
6000 cmd := LowerCase(P[0]);
6001 case cmd of
6002 'p1_name':
6003 begin
6004 if (Length(P) > 1) then
6005 begin
6006 gPlayer1Settings.Name := b_Text_Unformat(P[1]);
6007 if g_Game_IsClient then
6008 MC_SEND_PlayerSettings
6009 else if gGameOn and (gPlayer1 <> nil) then
6010 begin
6011 gPlayer1.Name := b_Text_Unformat(P[1]);
6012 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer1.UID);
6013 end;
6014 end;
6015 end;
6016 'p2_name':
6017 begin
6018 if (Length(P) > 1) then
6019 begin
6020 gPlayer2Settings.Name := b_Text_Unformat(P[1]);
6021 if g_Game_IsClient then
6022 MC_SEND_PlayerSettings
6023 else if gGameOn and (gPlayer2 <> nil) then
6024 begin
6025 gPlayer2.Name := b_Text_Unformat(P[1]);
6026 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer2.UID);
6027 end;
6028 end;
6029 end;
6030 'p1_color':
6031 begin
6032 if Length(P) > 3 then
6033 begin
6034 gPlayer1Settings.Color := _RGB(EnsureRange(StrToIntDef(P[1], 0), 0, 255),
6035 EnsureRange(StrToIntDef(P[2], 0), 0, 255),
6036 EnsureRange(StrToIntDef(P[3], 0), 0, 255));
6037 if g_Game_IsClient then
6038 MC_SEND_PlayerSettings
6039 else if gGameOn and (gPlayer1 <> nil) then
6040 begin
6041 gPlayer1.SetColor(gPlayer1Settings.Color);
6042 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer1.UID);
6043 end;
6044 end;
6045 end;
6046 'p2_color':
6047 begin
6048 if Length(P) > 3 then
6049 begin
6050 gPlayer2Settings.Color := _RGB(EnsureRange(StrToIntDef(P[1], 0), 0, 255),
6051 EnsureRange(StrToIntDef(P[2], 0), 0, 255),
6052 EnsureRange(StrToIntDef(P[3], 0), 0, 255));
6053 if g_Game_IsClient then
6054 MC_SEND_PlayerSettings
6055 else if gGameOn and (gPlayer2 <> nil) then
6056 begin
6057 gPlayer2.SetColor(gPlayer2Settings.Color);
6058 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer2.UID);
6059 end;
6060 end;
6061 end;
6062 'p1_model':
6063 begin
6064 if (Length(P) > 1) then
6065 begin
6066 gPlayer1Settings.Model := P[1];
6067 if g_Game_IsClient then
6068 MC_SEND_PlayerSettings
6069 else if gGameOn and (gPlayer1 <> nil) then
6070 begin
6071 gPlayer1.FActualModelName := gPlayer1Settings.Model;
6072 gPlayer1.SetModel(gPlayer1Settings.Model);
6073 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer1.UID);
6074 end;
6075 end;
6076 end;
6077 'p2_model':
6078 begin
6079 if (Length(P) > 1) then
6080 begin
6081 gPlayer2Settings.Model := P[1];
6082 if g_Game_IsClient then
6083 MC_SEND_PlayerSettings
6084 else if gGameOn and (gPlayer2 <> nil) then
6085 begin
6086 gPlayer2.FActualModelName := gPlayer2Settings.Model;
6087 gPlayer2.SetModel(gPlayer2Settings.Model);
6088 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer2.UID);
6089 end;
6090 end;
6091 end;
6092 'p1_team':
6093 begin
6094 // TODO: switch teams if in game or store this separately
6095 if (Length(P) > 1) then
6096 begin
6097 team := ParseTeam(P[1]);
6098 if team = TEAM_NONE then
6099 g_Console_Add('expected ''red'', ''blue'', 1 or 2')
6100 else if not gGameOn and not g_Game_IsNet then
6101 gPlayer1Settings.Team := team
6102 else
6103 g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
6104 end;
6105 end;
6106 'p2_team':
6107 begin
6108 // TODO: switch teams if in game or store this separately
6109 if (Length(P) > 1) then
6110 begin
6111 team := ParseTeam(P[1]);
6112 if team = TEAM_NONE then
6113 g_Console_Add('expected ''red'', ''blue'', 1 or 2')
6114 else if not gGameOn and not g_Game_IsNet then
6115 gPlayer2Settings.Team := team
6116 else
6117 g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
6118 end;
6119 end;
6120 'p1_autoswitch':
6121 begin
6122 if (Length(P) = 2) then
6123 gPlayer1Settings.WeaponSwitch := EnsureRange(StrTointDef(P[1], 0), 0, 2);
6124 end;
6125 'p2_autoswitch':
6126 begin
6127 if (Length(P) = 2) then
6128 gPlayer2Settings.WeaponSwitch := EnsureRange(StrTointDef(P[1], 0), 0, 2);
6129 end;
6130 'p1_switch_empty':
6131 begin
6132 if (Length(P) = 2) then
6133 gPlayer1Settings.SwitchToEmpty := EnsureRange(StrTointDef(P[1], 0), 0, 1);
6134 end;
6135 'p2_switch_empty':
6136 begin
6137 if (Length(P) = 2) then
6138 gPlayer2Settings.SwitchToEmpty := EnsureRange(StrTointDef(P[1], 0), 0, 1);
6139 end;
6140 'p1_skip_fist':
6141 begin
6142 if (Length(P) = 2) then
6143 gPlayer1Settings.SkipFist := EnsureRange(StrTointDef(P[1], 0), 0, 1);
6144 end;
6145 'p2_skip_fist':
6146 begin
6147 if (Length(P) = 2) then
6148 gPlayer2Settings.SkipFist := EnsureRange(StrTointDef(P[1], 0), 0, 1);
6149 end;
6150 'p1_priority_kastet':
6151 begin
6152 if (Length(P) = 2) then
6153 gPlayer1Settings.WeaponPreferences[WEAPON_KASTET] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6154 end;
6155 'p2_priority_kastet':
6156 begin
6157 if (Length(P) = 2) then
6158 gPlayer2Settings.WeaponPreferences[WEAPON_KASTET] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6159 end;
6160 'p1_priority_saw':
6161 begin
6162 if (Length(P) = 2) then
6163 gPlayer1Settings.WeaponPreferences[WEAPON_SAW] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6164 end;
6165 'p2_priority_saw':
6166 begin
6167 if (Length(P) = 2) then
6168 gPlayer2Settings.WeaponPreferences[WEAPON_SAW] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6169 end;
6170 'p1_priority_pistol':
6171 begin
6172 if (Length(P) = 2) then
6173 gPlayer1Settings.WeaponPreferences[WEAPON_KASTET] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6174 end;
6175 'p2_priority_pistol':
6176 begin
6177 if (Length(P) = 2) then
6178 gPlayer2Settings.WeaponPreferences[WEAPON_KASTET] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6179 end;
6180 'p1_priority_shotgun1':
6181 begin
6182 if (Length(P) = 2) then
6183 gPlayer1Settings.WeaponPreferences[WEAPON_SHOTGUN1] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6184 end;
6185 'p2_priority_shotgun1':
6186 begin
6187 if (Length(P) = 2) then
6188 gPlayer2Settings.WeaponPreferences[WEAPON_SHOTGUN1] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6189 end;
6190 'p1_priority_shotgun2':
6191 begin
6192 if (Length(P) = 2) then
6193 gPlayer1Settings.WeaponPreferences[WEAPON_SHOTGUN2] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6194 end;
6195 'p2_priority_shotgun2':
6196 begin
6197 if (Length(P) = 2) then
6198 gPlayer2Settings.WeaponPreferences[WEAPON_SHOTGUN2] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6199 end;
6200 'p1_priority_chaingun':
6201 begin
6202 if (Length(P) = 2) then
6203 gPlayer1Settings.WeaponPreferences[WEAPON_CHAINGUN] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6204 end;
6205 'p2_priority_chaingun':
6206 begin
6207 if (Length(P) = 2) then
6208 gPlayer2Settings.WeaponPreferences[WEAPON_CHAINGUN] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6209 end;
6210 'p1_priority_rocketlauncher':
6211 begin
6212 if (Length(P) = 2) then
6213 gPlayer1Settings.WeaponPreferences[WEAPON_ROCKETLAUNCHER] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6214 end;
6215 'p2_priority_rocketlauncher':
6216 begin
6217 if (Length(P) = 2) then
6218 gPlayer2Settings.WeaponPreferences[WEAPON_ROCKETLAUNCHER] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6219 end;
6220 'p1_priority_plasma':
6221 begin
6222 if (Length(P) = 2) then
6223 gPlayer1Settings.WeaponPreferences[WEAPON_PLASMA] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6224 end;
6225 'p2_priority_plasma':
6226 begin
6227 if (Length(P) = 2) then
6228 gPlayer2Settings.WeaponPreferences[WEAPON_PLASMA] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6229 end;
6230 'p1_priority_bfg':
6231 begin
6232 if (Length(P) = 2) then
6233 gPlayer1Settings.WeaponPreferences[WEAPON_BFG] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6234 end;
6235 'p2_priority_bfg':
6236 begin
6237 if (Length(P) = 2) then
6238 gPlayer2Settings.WeaponPreferences[WEAPON_BFG] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6239 end;
6240 'p1_priority_super':
6241 begin
6242 if (Length(P) = 2) then
6243 gPlayer1Settings.WeaponPreferences[WEAPON_SUPERPULEMET] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6244 end;
6245 'p2_priority_super':
6246 begin
6247 if (Length(P) = 2) then
6248 gPlayer2Settings.WeaponPreferences[WEAPON_SUPERPULEMET] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6249 end;
6250 'p1_priority_flamethrower':
6251 begin
6252 if (Length(P) = 2) then
6253 gPlayer1Settings.WeaponPreferences[WEAPON_FLAMETHROWER] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6254 end;
6255 'p2_priority_flamethrower':
6256 begin
6257 if (Length(P) = 2) then
6258 gPlayer2Settings.WeaponPreferences[WEAPON_FLAMETHROWER] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6259 end;
6260 'p1_priority_berserk':
6261 begin
6262 if (Length(P) = 2) then
6263 gPlayer1Settings.WeaponPreferences[WP_LAST+1] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6264 end;
6265 'p2_priority_berserk':
6266 begin
6267 if (Length(P) = 2) then
6268 gPlayer2Settings.WeaponPreferences[WP_LAST+1] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6269 end;
6270 end;
6271 end;
6273 procedure PrintHeapStats();
6274 var
6275 hs: TFPCHeapStatus;
6276 begin
6277 hs := GetFPCHeapStatus();
6278 e_LogWriteLn ('v===== heap status =====v');
6279 e_LogWriteFln('max heap size = %d k', [hs.MaxHeapSize div 1024]);
6280 e_LogWriteFln('max heap used = %d k', [hs.MaxHeapUsed div 1024]);
6281 e_LogWriteFln('cur heap size = %d k', [hs.CurrHeapSize div 1024]);
6282 e_LogWriteFln('cur heap used = %d k', [hs.CurrHeapUsed div 1024]);
6283 e_LogWriteFln('cur heap free = %d k', [hs.CurrHeapFree div 1024]);
6284 e_LogWriteLn ('^=======================^');
6285 end;
6287 procedure DebugCommands(P: SSArray);
6288 var
6289 a, b: Integer;
6290 cmd: string;
6291 //pt: TDFPoint;
6292 mon: TMonster;
6293 begin
6294 // Êîìàíäû îòëàäî÷íîãî ðåæèìà:
6295 if {gDebugMode}conIsCheatsEnabled then
6296 begin
6297 cmd := LowerCase(P[0]);
6298 if cmd = 'd_window' then
6299 begin
6300 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth, gScreenHeight]));
6301 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth, gScreenHeight]));
6302 end
6303 else if cmd = 'd_sounds' then
6304 begin
6305 if (Length(P) > 1) and
6306 ((P[1] = '1') or (P[1] = '0')) then
6307 g_Debug_Sounds := (P[1][1] = '1');
6309 g_Console_Add(Format('d_sounds is %d', [Byte(g_Debug_Sounds)]));
6310 end
6311 else if cmd = 'd_frames' then
6312 begin
6313 if (Length(P) > 1) and
6314 ((P[1] = '1') or (P[1] = '0')) then
6315 g_Debug_Frames := (P[1][1] = '1');
6317 g_Console_Add(Format('d_frames is %d', [Byte(g_Debug_Frames)]));
6318 end
6319 else if cmd = 'd_winmsg' then
6320 begin
6321 if (Length(P) > 1) and
6322 ((P[1] = '1') or (P[1] = '0')) then
6323 g_Debug_WinMsgs := (P[1][1] = '1');
6325 g_Console_Add(Format('d_winmsg is %d', [Byte(g_Debug_WinMsgs)]));
6326 end
6327 else if (cmd = 'd_monoff') and not g_Game_IsNet then
6328 begin
6329 if (Length(P) > 1) and
6330 ((P[1] = '1') or (P[1] = '0')) then
6331 g_Debug_MonsterOff := (P[1][1] = '1');
6333 g_Console_Add(Format('d_monoff is %d', [Byte(g_debug_MonsterOff)]));
6334 end
6335 else if (cmd = 'd_botoff') and not g_Game_IsNet then
6336 begin
6337 if Length(P) > 1 then
6338 case P[1][1] of
6339 '0': g_debug_BotAIOff := 0;
6340 '1': g_debug_BotAIOff := 1;
6341 '2': g_debug_BotAIOff := 2;
6342 '3': g_debug_BotAIOff := 3;
6343 end;
6345 g_Console_Add(Format('d_botoff is %d', [g_debug_BotAIOff]));
6346 end
6347 else if cmd = 'd_monster' then
6348 begin
6349 if gGameOn and (gPlayer1 <> nil) and (gPlayer1.alive) and (not g_Game_IsNet) then
6350 if Length(P) < 2 then
6351 begin
6352 g_Console_Add(cmd + ' [ID | Name] [behaviour]');
6353 g_Console_Add('ID | Name');
6354 for b := MONSTER_DEMON to MONSTER_MAN do
6355 g_Console_Add(Format('%2d | %s', [b, g_Mons_NameByTypeId(b)]));
6356 conwriteln('behav. num'#10'normal 0'#10'killer 1'#10'maniac 2'#10'insane 3'#10'cannibal 4'#10'good 5');
6357 end else
6358 begin
6359 a := StrToIntDef(P[1], 0);
6360 if (a < MONSTER_DEMON) or (a > MONSTER_MAN) then
6361 a := g_Mons_TypeIdByName(P[1]);
6363 if (a < MONSTER_DEMON) or (a > MONSTER_MAN) then
6364 g_Console_Add(Format(_lc[I_MSG_NO_MONSTER], [P[1]]))
6365 else
6366 begin
6367 with gPlayer1.Obj do
6368 begin
6369 mon := g_Monsters_Create(a,
6370 X + Rect.X + (Rect.Width div 2),
6371 Y + Rect.Y + Rect.Height,
6372 gPlayer1.Direction, True);
6373 end;
6374 if (Length(P) > 2) and (mon <> nil) then
6375 begin
6376 if (CompareText(P[2], 'normal') = 0) then mon.MonsterBehaviour := BH_NORMAL
6377 else if (CompareText(P[2], 'killer') = 0) then mon.MonsterBehaviour := BH_KILLER
6378 else if (CompareText(P[2], 'maniac') = 0) then mon.MonsterBehaviour := BH_MANIAC
6379 else if (CompareText(P[2], 'insane') = 0) then mon.MonsterBehaviour := BH_INSANE
6380 else if (CompareText(P[2], 'cannibal') = 0) then mon.MonsterBehaviour := BH_CANNIBAL
6381 else if (CompareText(P[2], 'good') = 0) then mon.MonsterBehaviour := BH_GOOD
6382 else if (CompareText(P[2], 'friend') = 0) then mon.MonsterBehaviour := BH_GOOD
6383 else if (CompareText(P[2], 'friendly') = 0) then mon.MonsterBehaviour := BH_GOOD
6384 else mon.MonsterBehaviour := Min(Max(StrToIntDef(P[2], BH_NORMAL), BH_NORMAL), BH_GOOD);
6385 end;
6386 end;
6387 end;
6388 end
6389 else if (cmd = 'd_health') then
6390 begin
6391 if (Length(P) > 1) and
6392 ((P[1] = '1') or (P[1] = '0')) then
6393 g_debug_HealthBar := (P[1][1] = '1');
6395 g_Console_Add(Format('d_health is %d', [Byte(g_debug_HealthBar)]));
6396 end
6397 else if (cmd = 'd_player') then
6398 begin
6399 if (Length(P) > 1) and
6400 ((P[1] = '1') or (P[1] = '0')) then
6401 g_debug_Player := (P[1][1] = '1');
6403 g_Console_Add(Format(cmd + ' is %d', [Byte(g_Debug_Player)]));
6404 end
6405 else if (cmd = 'd_mem') then
6406 begin
6407 PrintHeapStats();
6408 end;
6409 end
6410 else
6411 g_Console_Add(_lc[I_MSG_NOT_DEBUG]);
6412 end;
6415 procedure GameCheats(P: SSArray);
6416 var
6417 cmd: string;
6418 f, a: Integer;
6419 plr: TPlayer;
6420 begin
6421 if (not gGameOn) or (not conIsCheatsEnabled) then
6422 begin
6423 g_Console_Add('not available');
6424 exit;
6425 end;
6426 plr := gPlayer1;
6427 if plr = nil then
6428 begin
6429 g_Console_Add('where is the player?!');
6430 exit;
6431 end;
6432 cmd := LowerCase(P[0]);
6433 // god
6434 if cmd = 'god' then
6435 begin
6436 plr.GodMode := not plr.GodMode;
6437 if plr.GodMode then g_Console_Add('player is godlike now') else g_Console_Add('player is mortal now');
6438 exit;
6439 end;
6440 // give <health|exit|weapons|air|suit|jetpack|berserk|all>
6441 if cmd = 'give' then
6442 begin
6443 if length(P) < 2 then begin g_Console_Add('give what?!'); exit; end;
6444 for f := 1 to High(P) do
6445 begin
6446 cmd := LowerCase(P[f]);
6447 if cmd = 'health' then begin plr.RestoreHealthArmor(); g_Console_Add('player feels himself better'); continue; end;
6448 if (cmd = 'all') {or (cmd = 'weapons')} then begin plr.AllRulez(False); g_Console_Add('player got the gifts'); continue; end;
6449 if cmd = 'exit' then
6450 begin
6451 if gTriggers <> nil then
6452 begin
6453 for a := 0 to High(gTriggers) do
6454 begin
6455 if gTriggers[a].TriggerType = TRIGGER_EXIT then
6456 begin
6457 g_Console_Add('player left the map');
6458 gExitByTrigger := True;
6459 //g_Game_ExitLevel(gTriggers[a].Data.MapName);
6460 g_Game_ExitLevel(gTriggers[a].tgcMap);
6461 break;
6462 end;
6463 end;
6464 end;
6465 continue;
6466 end;
6468 if cmd = 'air' then begin plr.GiveItem(ITEM_OXYGEN); g_Console_Add('player got some air'); continue; end;
6469 if cmd = 'jetpack' then begin plr.GiveItem(ITEM_JETPACK); g_Console_Add('player got a jetpack'); continue; end;
6470 if cmd = 'suit' then begin plr.GiveItem(ITEM_SUIT); g_Console_Add('player got an envirosuit'); continue; end;
6471 if cmd = 'berserk' then begin plr.GiveItem(ITEM_MEDKIT_BLACK); g_Console_Add('player got a berserk pack'); continue; end;
6472 if cmd = 'backpack' then begin plr.GiveItem(ITEM_AMMO_BACKPACK); g_Console_Add('player got a backpack'); continue; end;
6474 if cmd = 'helmet' then begin plr.GiveItem(ITEM_HELMET); g_Console_Add('player got a helmet'); continue; end;
6475 if cmd = 'bottle' then begin plr.GiveItem(ITEM_BOTTLE); g_Console_Add('player got a bottle of health'); continue; end;
6477 if cmd = 'stimpack' then begin plr.GiveItem(ITEM_MEDKIT_SMALL); g_Console_Add('player got a stimpack'); continue; end;
6478 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;
6480 if cmd = 'greenarmor' then begin plr.GiveItem(ITEM_ARMOR_GREEN); g_Console_Add('player got a security armor'); continue; end;
6481 if cmd = 'bluearmor' then begin plr.GiveItem(ITEM_ARMOR_BLUE); g_Console_Add('player got a combat armor'); continue; end;
6483 if (cmd = 'soulsphere') or (cmd = 'soul') then begin plr.GiveItem(ITEM_SPHERE_BLUE); g_Console_Add('player got a soul sphere'); continue; end;
6484 if (cmd = 'megasphere') or (cmd = 'mega') then begin plr.GiveItem(ITEM_SPHERE_WHITE); g_Console_Add('player got a megasphere'); continue; end;
6486 if (cmd = 'invul') or (cmd = 'invulnerability') then begin plr.GiveItem(ITEM_INVUL); g_Console_Add('player got invulnerability'); continue; end;
6487 if (cmd = 'invis') or (cmd = 'invisibility') then begin plr.GiveItem(ITEM_INVIS); g_Console_Add('player got invisibility'); continue; end;
6489 if cmd = 'redkey' then begin plr.GiveItem(ITEM_KEY_RED); g_Console_Add('player got the red key'); continue; end;
6490 if cmd = 'greenkey' then begin plr.GiveItem(ITEM_KEY_GREEN); g_Console_Add('player got the green key'); continue; end;
6491 if cmd = 'bluekey' then begin plr.GiveItem(ITEM_KEY_BLUE); g_Console_Add('player got the blue key'); continue; end;
6493 if (cmd = 'shotgun') or (cmd = 'sg') then begin plr.GiveItem(ITEM_WEAPON_SHOTGUN1); g_Console_Add('player got a shotgun'); continue; end;
6494 if (cmd = 'supershotgun') or (cmd = 'ssg') then begin plr.GiveItem(ITEM_WEAPON_SHOTGUN2); g_Console_Add('player got a supershotgun'); continue; end;
6495 if cmd = 'chaingun' then begin plr.GiveItem(ITEM_WEAPON_CHAINGUN); g_Console_Add('player got a chaingun'); continue; end;
6496 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;
6497 if cmd = 'plasmagun' then begin plr.GiveItem(ITEM_WEAPON_PLASMA); g_Console_Add('player got a plasma gun'); continue; end;
6498 if cmd = 'bfg' then begin plr.GiveItem(ITEM_WEAPON_BFG); g_Console_Add('player got a BFG-9000'); continue; end;
6500 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;
6501 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;
6502 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;
6503 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;
6504 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;
6505 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;
6507 if cmd = 'superchaingun' then begin plr.GiveItem(ITEM_WEAPON_SUPERPULEMET); g_Console_Add('player got a superchaingun'); continue; end;
6508 if cmd = 'superchaingunzz' then begin plr.GiveItem(ITEM_WEAPON_SUPERPULEMET); plr.GiveItem(ITEM_AMMO_BULLETS_BOX); g_Console_Add('player got a superchaingun'); continue; end;
6510 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;
6511 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;
6513 if cmd = 'chainsaw' then begin plr.GiveItem(ITEM_WEAPON_SAW); g_Console_Add('player got a chainsaw'); continue; end;
6515 if cmd = 'ammo' then
6516 begin
6517 plr.GiveItem(ITEM_AMMO_SHELLS_BOX);
6518 plr.GiveItem(ITEM_AMMO_BULLETS_BOX);
6519 plr.GiveItem(ITEM_AMMO_CELL_BIG);
6520 plr.GiveItem(ITEM_AMMO_ROCKET_BOX);
6521 plr.GiveItem(ITEM_AMMO_FUELCAN);
6522 g_Console_Add('player got some ammo');
6523 continue;
6524 end;
6526 if cmd = 'clip' then begin plr.GiveItem(ITEM_AMMO_BULLETS); g_Console_Add('player got some bullets'); continue; end;
6527 if cmd = 'bullets' then begin plr.GiveItem(ITEM_AMMO_BULLETS_BOX); g_Console_Add('player got a box of bullets'); continue; end;
6529 if cmd = 'shells' then begin plr.GiveItem(ITEM_AMMO_SHELLS); g_Console_Add('player got some shells'); continue; end;
6530 if cmd = 'shellbox' then begin plr.GiveItem(ITEM_AMMO_SHELLS_BOX); g_Console_Add('player got a box of shells'); continue; end;
6532 if cmd = 'cells' then begin plr.GiveItem(ITEM_AMMO_CELL); g_Console_Add('player got some cells'); continue; end;
6533 if cmd = 'battery' then begin plr.GiveItem(ITEM_AMMO_CELL_BIG); g_Console_Add('player got cell battery'); continue; end;
6535 if cmd = 'rocket' then begin plr.GiveItem(ITEM_AMMO_ROCKET); g_Console_Add('player got a rocket'); continue; end;
6536 if cmd = 'rocketbox' then begin plr.GiveItem(ITEM_AMMO_ROCKET_BOX); g_Console_Add('player got some rockets'); continue; end;
6538 if (cmd = 'fuel') or (cmd = 'fuelcan') then begin plr.GiveItem(ITEM_AMMO_FUELCAN); g_Console_Add('player got fuel canister'); continue; end;
6540 if cmd = 'weapons' then
6541 begin
6542 plr.GiveItem(ITEM_WEAPON_SHOTGUN1);
6543 plr.GiveItem(ITEM_WEAPON_SHOTGUN2);
6544 plr.GiveItem(ITEM_WEAPON_CHAINGUN);
6545 plr.GiveItem(ITEM_WEAPON_ROCKETLAUNCHER);
6546 plr.GiveItem(ITEM_WEAPON_PLASMA);
6547 plr.GiveItem(ITEM_WEAPON_BFG);
6548 g_Console_Add('player got weapons');
6549 continue;
6550 end;
6552 if cmd = 'keys' then
6553 begin
6554 plr.GiveItem(ITEM_KEY_RED);
6555 plr.GiveItem(ITEM_KEY_GREEN);
6556 plr.GiveItem(ITEM_KEY_BLUE);
6557 g_Console_Add('player got all keys');
6558 continue;
6559 end;
6561 g_Console_Add('i don''t know how to give '''+cmd+'''!');
6562 end;
6563 exit;
6564 end;
6565 // open
6566 if cmd = 'open' then
6567 begin
6568 g_Console_Add('player activated sesame');
6569 g_Triggers_OpenAll();
6570 exit;
6571 end;
6572 // fly
6573 if cmd = 'fly' then
6574 begin
6575 gFly := not gFly;
6576 if gFly then g_Console_Add('player feels himself lighter') else g_Console_Add('player lost his wings');
6577 exit;
6578 end;
6579 // noclip
6580 if cmd = 'noclip' then
6581 begin
6582 plr.SwitchNoClip;
6583 g_Console_Add('wall hardeness adjusted');
6584 exit;
6585 end;
6586 // notarget
6587 if cmd = 'notarget' then
6588 begin
6589 plr.NoTarget := not plr.NoTarget;
6590 if plr.NoTarget then g_Console_Add('player hides in shadows') else g_Console_Add('player is brave again');
6591 exit;
6592 end;
6593 // noreload
6594 if cmd = 'noreload' then
6595 begin
6596 plr.NoReload := not plr.NoReload;
6597 if plr.NoReload then g_Console_Add('player is action hero now') else g_Console_Add('player is ordinary man now');
6598 exit;
6599 end;
6600 // speedy
6601 if cmd = 'speedy' then
6602 begin
6603 MAX_RUNVEL := 32-MAX_RUNVEL;
6604 g_Console_Add('speed adjusted');
6605 exit;
6606 end;
6607 // jumpy
6608 if cmd = 'jumpy' then
6609 begin
6610 VEL_JUMP := 30-VEL_JUMP;
6611 g_Console_Add('jump height adjusted');
6612 exit;
6613 end;
6614 // automap
6615 if cmd = 'automap' then
6616 begin
6617 gShowMap := not gShowMap;
6618 if gShowMap then g_Console_Add('player gains second sight') else g_Console_Add('player lost second sight');
6619 exit;
6620 end;
6621 // aimline
6622 if cmd = 'aimline' then
6623 begin
6624 gAimLine := not gAimLine;
6625 if gAimLine then g_Console_Add('player gains laser sight') else g_Console_Add('player lost laser sight');
6626 exit;
6627 end;
6628 end;
6630 procedure GameCommands(P: SSArray);
6631 var
6632 a, b: Integer;
6633 s, pw: String;
6634 chstr: string;
6635 cmd: string;
6636 pl: pTNetClient = nil;
6637 plr: TPlayer;
6638 prt: Word;
6639 nm: Boolean;
6640 listen: LongWord;
6641 found: Boolean;
6642 t: Byte;
6643 begin
6644 // Îáùèå êîìàíäû:
6645 cmd := LowerCase(P[0]);
6646 chstr := '';
6647 if cmd = 'pause' then
6648 begin
6649 if (g_ActiveWindow = nil) then
6650 g_Game_Pause(not gPauseMain);
6651 end
6652 else if cmd = 'endgame' then
6653 gExit := EXIT_SIMPLE
6654 else if cmd = 'restart' then
6655 begin
6656 if gGameOn or (gState in [STATE_INTERSINGLE, STATE_INTERCUSTOM]) then
6657 begin
6658 if g_Game_IsClient then
6659 begin
6660 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6661 Exit;
6662 end;
6663 g_Game_Restart();
6664 end else
6665 g_Console_Add(_lc[I_MSG_NOT_GAME]);
6666 end
6667 else if cmd = 'kick' then
6668 begin
6669 if g_Game_IsServer then
6670 begin
6671 if Length(P) < 2 then
6672 begin
6673 g_Console_Add('kick <name>');
6674 Exit;
6675 end;
6676 if P[1] = '' then
6677 begin
6678 g_Console_Add('kick <name>');
6679 Exit;
6680 end;
6682 if g_Game_IsNet then
6683 pl := g_Net_Client_ByName(P[1]);
6684 if (pl <> nil) then
6685 begin
6686 s := g_Net_ClientName_ByID(pl^.ID);
6687 g_Net_Host_Kick(pl^.ID, NET_DISC_KICK);
6688 g_Console_Add(Format(_lc[I_PLAYER_KICK], [s]));
6689 MH_SEND_GameEvent(NET_EV_PLAYER_KICK, 0, s);
6690 g_Net_Slist_ServerPlayerLeaves();
6691 end else if gPlayers <> nil then
6692 for a := Low(gPlayers) to High(gPlayers) do
6693 if gPlayers[a] <> nil then
6694 if Copy(LowerCase(gPlayers[a].Name), 1, Length(P[1])) = LowerCase(P[1]) then
6695 begin
6696 // Íå îòêëþ÷àòü îñíîâíûõ èãðîêîâ â ñèíãëå
6697 if not(gPlayers[a] is TBot) and (gGameSettings.GameType = GT_SINGLE) then
6698 continue;
6699 gPlayers[a].Lives := 0;
6700 gPlayers[a].Kill(K_SIMPLEKILL, 0, HIT_DISCON);
6701 g_Console_Add(Format(_lc[I_PLAYER_LEAVE], [gPlayers[a].Name]), True);
6702 g_Player_Remove(gPlayers[a].UID);
6703 g_Net_Slist_ServerPlayerLeaves();
6704 // Åñëè íå ïåðåìåøàòü, ïðè äîáàâëåíèè íîâûõ áîòîâ ïîÿâÿòñÿ ñòàðûå
6705 g_Bot_MixNames();
6706 end;
6707 end else
6708 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
6709 end
6710 else if cmd = 'kick_id' then
6711 begin
6712 if g_Game_IsServer and g_Game_IsNet then
6713 begin
6714 if Length(P) < 2 then
6715 begin
6716 g_Console_Add('kick_id <client ID>');
6717 Exit;
6718 end;
6719 if P[1] = '' then
6720 begin
6721 g_Console_Add('kick_id <client ID>');
6722 Exit;
6723 end;
6725 a := StrToIntDef(P[1], 0);
6726 if (NetClients <> nil) and (a <= High(NetClients)) then
6727 begin
6728 if NetClients[a].Used and (NetClients[a].Peer <> nil) then
6729 begin
6730 s := g_Net_ClientName_ByID(NetClients[a].ID);
6731 g_Net_Host_Kick(NetClients[a].ID, NET_DISC_KICK);
6732 g_Console_Add(Format(_lc[I_PLAYER_KICK], [s]));
6733 MH_SEND_GameEvent(NET_EV_PLAYER_KICK, 0, s);
6734 g_Net_Slist_ServerPlayerLeaves();
6735 end;
6736 end;
6737 end else
6738 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6739 end
6740 else if cmd = 'kick_pid' then
6741 begin
6742 if g_Game_IsServer and g_Game_IsNet then
6743 begin
6744 if Length(P) < 2 then
6745 begin
6746 g_Console_Add('kick_pid <player ID>');
6747 Exit;
6748 end;
6749 if P[1] = '' then
6750 begin
6751 g_Console_Add('kick_pid <player ID>');
6752 Exit;
6753 end;
6755 a := StrToIntDef(P[1], 0);
6756 pl := g_Net_Client_ByPlayer(a);
6757 if (pl <> nil) and pl^.Used and (pl^.Peer <> nil) then
6758 begin
6759 s := g_Net_ClientName_ByID(pl^.ID);
6760 g_Net_Host_Kick(pl^.ID, NET_DISC_KICK);
6761 g_Console_Add(Format(_lc[I_PLAYER_KICK], [s]));
6762 MH_SEND_GameEvent(NET_EV_PLAYER_KICK, 0, s);
6763 g_Net_Slist_ServerPlayerLeaves();
6764 end;
6765 end else
6766 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6767 end
6768 else if cmd = 'ban' then
6769 begin
6770 if g_Game_IsServer and g_Game_IsNet then
6771 begin
6772 if Length(P) < 2 then
6773 begin
6774 g_Console_Add('ban <name>');
6775 Exit;
6776 end;
6777 if P[1] = '' then
6778 begin
6779 g_Console_Add('ban <name>');
6780 Exit;
6781 end;
6783 pl := g_Net_Client_ByName(P[1]);
6784 if (pl <> nil) then
6785 g_Net_Host_Ban(pl, False)
6786 else
6787 g_Console_Add(Format(_lc[I_NET_ERR_NAME404], [P[1]]));
6788 end else
6789 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6790 end
6791 else if cmd = 'ban_id' then
6792 begin
6793 if g_Game_IsServer and g_Game_IsNet then
6794 begin
6795 if Length(P) < 2 then
6796 begin
6797 g_Console_Add('ban_id <client ID>');
6798 Exit;
6799 end;
6800 if P[1] = '' then
6801 begin
6802 g_Console_Add('ban_id <client ID>');
6803 Exit;
6804 end;
6806 a := StrToIntDef(P[1], 0);
6807 if (NetClients <> nil) and (a <= High(NetClients)) then
6808 if NetClients[a].Used and (NetClients[a].Peer <> nil) then
6809 g_Net_Host_Ban(pl, False);
6810 end else
6811 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6812 end
6813 else if cmd = 'ban_pid' then
6814 begin
6815 if g_Game_IsServer and g_Game_IsNet then
6816 begin
6817 if Length(P) < 2 then
6818 begin
6819 g_Console_Add('ban_pid <player ID>');
6820 Exit;
6821 end;
6822 if P[1] = '' then
6823 begin
6824 g_Console_Add('ban_pid <player ID>');
6825 Exit;
6826 end;
6828 a := StrToIntDef(P[1], 0);
6829 pl := g_Net_Client_ByPlayer(a);
6830 if (pl <> nil) and pl^.Used and (pl^.Peer <> nil) then
6831 g_Net_Host_Ban(pl, False);
6832 end else
6833 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6834 end
6835 else if cmd = 'permban' then
6836 begin
6837 if g_Game_IsServer and g_Game_IsNet then
6838 begin
6839 if Length(P) < 2 then
6840 begin
6841 g_Console_Add('permban <name>');
6842 Exit;
6843 end;
6844 if P[1] = '' then
6845 begin
6846 g_Console_Add('permban <name>');
6847 Exit;
6848 end;
6850 pl := g_Net_Client_ByName(P[1]);
6851 if (pl <> nil) then
6852 g_Net_Host_Ban(pl, True)
6853 else
6854 g_Console_Add(Format(_lc[I_NET_ERR_NAME404], [P[1]]));
6855 end else
6856 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6857 end
6858 else if cmd = 'permban_id' then
6859 begin
6860 if g_Game_IsServer and g_Game_IsNet then
6861 begin
6862 if Length(P) < 2 then
6863 begin
6864 g_Console_Add('permban_id <client ID>');
6865 Exit;
6866 end;
6867 if P[1] = '' then
6868 begin
6869 g_Console_Add('permban_id <client ID>');
6870 Exit;
6871 end;
6873 a := StrToIntDef(P[1], 0);
6874 if (NetClients <> nil) and (a <= High(NetClients)) then
6875 if NetClients[a].Used and (NetClients[a].Peer <> nil) then
6876 g_Net_Host_Ban(@NetClients[a], True);
6877 end else
6878 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6879 end
6880 else if cmd = 'permban_pid' then
6881 begin
6882 if g_Game_IsServer and g_Game_IsNet then
6883 begin
6884 if Length(P) < 2 then
6885 begin
6886 g_Console_Add('permban_pid <player ID>');
6887 Exit;
6888 end;
6889 if P[1] = '' then
6890 begin
6891 g_Console_Add('permban_pid <player ID>');
6892 Exit;
6893 end;
6895 a := StrToIntDef(P[1], 0);
6896 pl := g_Net_Client_ByPlayer(a);
6897 if (pl <> nil) and pl^.Used and (pl^.Peer <> nil) then
6898 g_Net_Host_Ban(pl, True);
6899 end else
6900 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6901 end
6902 else if cmd = 'permban_ip' 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('permban_ip <IP address>');
6909 Exit;
6910 end;
6911 if P[1] = '' then
6912 begin
6913 g_Console_Add('permban_ip <IP address>');
6914 Exit;
6915 end;
6917 g_Net_BanAddress(P[1]);
6918 g_Net_SaveBanList();
6919 g_Console_Add(Format(_lc[I_PLAYER_BAN], [P[1]]));
6920 end else
6921 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6922 end
6923 else if cmd = 'unban' then
6924 begin
6925 if g_Game_IsServer and g_Game_IsNet then
6926 begin
6927 if Length(P) < 2 then
6928 begin
6929 g_Console_Add('unban <IP Address>');
6930 Exit;
6931 end;
6932 if P[1] = '' then
6933 begin
6934 g_Console_Add('unban <IP Address>');
6935 Exit;
6936 end;
6938 if g_Net_UnbanAddress(P[1]) then
6939 begin
6940 g_Console_Add(Format(_lc[I_MSG_UNBAN_OK], [P[1]]));
6941 g_Net_SaveBanList();
6942 end else
6943 g_Console_Add(Format(_lc[I_MSG_UNBAN_FAIL], [P[1]]));
6944 end else
6945 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6946 end
6947 else if cmd = 'clientlist' then
6948 begin
6949 if g_Game_IsServer and g_Game_IsNet then
6950 begin
6951 b := 0;
6952 if NetClients <> nil then
6953 for a := Low(NetClients) to High(NetClients) do
6954 if NetClients[a].Used and (NetClients[a].Peer <> nil) then
6955 begin
6956 plr := g_Player_Get(NetClients[a].Player);
6957 if plr = nil then continue;
6958 Inc(b);
6959 g_Console_Add(Format('#%2d: %-15s | %s', [a,
6960 IpToStr(NetClients[a].Peer^.address.host), plr.Name]));
6961 end;
6962 if b = 0 then
6963 g_Console_Add(_lc[I_MSG_NOCLIENTS]);
6964 end else
6965 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6966 end
6967 else if cmd = 'connect' then
6968 begin
6969 if (NetMode = NET_NONE) then
6970 begin
6971 if Length(P) < 2 then
6972 begin
6973 g_Console_Add('connect <IP> [port] [password]');
6974 Exit;
6975 end;
6976 if P[1] = '' then
6977 begin
6978 g_Console_Add('connect <IP> [port] [password]');
6979 Exit;
6980 end;
6982 if Length(P) > 2 then
6983 prt := StrToIntDef(P[2], 25666)
6984 else
6985 prt := 25666;
6987 if Length(P) > 3 then
6988 pw := P[3]
6989 else
6990 pw := '';
6992 g_Game_StartClient(P[1], prt, pw);
6993 end;
6994 end
6995 else if cmd = 'disconnect' then
6996 begin
6997 if (NetMode = NET_CLIENT) then
6998 g_Net_Disconnect();
6999 end
7000 else if cmd = 'reconnect' then
7001 begin
7002 if (NetMode = NET_SERVER) then
7003 Exit;
7005 if (NetMode = NET_CLIENT) then
7006 begin
7007 g_Net_Disconnect();
7008 gExit := EXIT_SIMPLE;
7009 EndGame;
7010 end;
7012 //TODO: Use last successful password to reconnect, instead of ''
7013 g_Game_StartClient(NetClientIP, NetClientPort, '');
7014 end
7015 else if (cmd = 'addbot') or
7016 (cmd = 'bot_add') then
7017 begin
7018 case Length(P) of
7019 1: g_Bot_Add(TEAM_NONE, 2);
7020 2: g_Bot_Add(TEAM_NONE, StrToIntDef(P[1], 2));
7021 else
7022 g_Bot_Add(TEAM_NONE, StrToIntDef(P[1], 2), StrToIntDef(P[2], 100));
7023 end;
7024 end
7025 else if cmd = 'bot_addlist' then
7026 begin
7027 case Length(P) of
7028 1: g_Bot_AddList(TEAM_NONE, '');
7029 2: g_Bot_AddList(TEAM_NONE, P[1], StrToIntDef(P[1], -1));
7030 else
7031 if P[2] = 'red' then
7032 t := TEAM_RED
7033 else if P[2] = 'blue' then
7034 t := TEAM_BLUE
7035 else
7036 t := TEAM_NONE;
7038 if Length(P) = 3
7039 then g_Bot_AddList(t, P[1], StrToIntDef(P[1], -1))
7040 else g_Bot_AddList(t, P[1], StrToIntDef(P[1], -1), StrToIntDef(P[3], 100));
7041 end;
7042 end
7043 else if cmd = 'bot_removeall' then
7044 g_Bot_RemoveAll()
7045 else if cmd = 'chat' then
7046 begin
7047 if g_Game_IsNet then
7048 begin
7049 if Length(P) > 1 then
7050 begin
7051 for a := 1 to High(P) do
7052 chstr := chstr + P[a] + ' ';
7054 if Length(chstr) > 200 then SetLength(chstr, 200);
7056 if Length(chstr) < 1 then
7057 begin
7058 g_Console_Add('chat <text>');
7059 Exit;
7060 end;
7062 chstr := b_Text_Format(chstr);
7063 if g_Game_IsClient then
7064 MC_SEND_Chat(chstr, NET_CHAT_PLAYER)
7065 else
7066 MH_SEND_Chat(gPlayer1Settings.Name + ': ' + chstr, NET_CHAT_PLAYER);
7067 end
7068 else
7069 g_Console_Add('chat <text>');
7070 end else
7071 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
7072 end
7073 else if cmd = 'teamchat' then
7074 begin
7075 if g_Game_IsNet and (gGameSettings.GameMode in [GM_TDM, GM_CTF]) then
7076 begin
7077 if Length(P) > 1 then
7078 begin
7079 for a := 1 to High(P) do
7080 chstr := chstr + P[a] + ' ';
7082 if Length(chstr) > 200 then SetLength(chstr, 200);
7084 if Length(chstr) < 1 then
7085 begin
7086 g_Console_Add('teamchat <text>');
7087 Exit;
7088 end;
7090 chstr := b_Text_Format(chstr);
7091 if g_Game_IsClient then
7092 MC_SEND_Chat(chstr, NET_CHAT_TEAM)
7093 else
7094 MH_SEND_Chat(gPlayer1Settings.Name + ': ' + chstr, NET_CHAT_TEAM,
7095 gPlayer1Settings.Team);
7096 end
7097 else
7098 g_Console_Add('teamchat <text>');
7099 end else
7100 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
7101 end
7102 else if (cmd = 'an') or (cmd = 'announce') then
7103 begin
7104 if g_Game_IsNet then
7105 begin
7106 if Length(P) > 1 then
7107 begin
7108 for a := 1 to High(P) do
7109 chstr := chstr + P[a] + ' ';
7111 if Length(chstr) > 200 then SetLength(chstr, 200);
7113 if Length(chstr) < 1 then
7114 begin
7115 g_Console_Add('announce <text>');
7116 Exit;
7117 end;
7119 chstr := 'centerprint 100 ' + b_Text_Format(chstr);
7120 if g_Game_IsClient then
7121 MC_SEND_RCONCommand(chstr)
7122 else
7123 g_Console_Process(chstr, True);
7124 end
7125 else
7126 g_Console_Add('announce <text>');
7127 end else
7128 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
7129 end
7130 else if cmd = 'game' then
7131 begin
7132 if gGameSettings.GameType <> GT_NONE then
7133 begin
7134 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
7135 Exit;
7136 end;
7137 if Length(P) = 1 then
7138 begin
7139 g_Console_Add(cmd + ' <WAD> [MAP] [# players]');
7140 Exit;
7141 end;
7142 // game not started yet, load fist map from some wad
7143 found := false;
7144 s := addWadExtension(P[1]);
7145 found := e_FindResource(AllMapDirs, s);
7146 P[1] := s;
7147 if found then
7148 begin
7149 P[1] := ExpandFileName(P[1]);
7150 // if map not choosed then set first map
7151 if Length(P) < 3 then
7152 begin
7153 SetLength(P, 3);
7154 P[2] := g_Game_GetFirstMap(P[1]);
7155 end;
7157 s := P[1] + ':\' + UpperCase(P[2]);
7159 if g_Map_Exist(s) then
7160 begin
7161 // start game
7162 g_Game_Free();
7163 with gGameSettings do
7164 begin
7165 Options := gsGameFlags;
7166 GameMode := g_Game_TextToMode(gsGameMode);
7167 if gSwitchGameMode <> GM_NONE then
7168 GameMode := gSwitchGameMode;
7169 if GameMode = GM_NONE then GameMode := GM_DM;
7170 if GameMode = GM_SINGLE then GameMode := GM_COOP;
7171 b := 1;
7172 if Length(P) >= 4 then
7173 b := StrToIntDef(P[3], 1);
7174 g_Game_StartCustom(s, GameMode, TimeLimit,
7175 ScoreLimit, MaxLives, Options, b);
7176 end;
7177 end
7178 else
7179 if P[2] = '' then
7180 g_Console_Add(Format(_lc[I_MSG_NO_MAPS], [P[1]]))
7181 else
7182 g_Console_Add(Format(_lc[I_MSG_NO_MAP_FALLBACK], [UpperCase(P[2]), P[1]]));
7183 end else
7184 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]));
7185 end
7186 else if cmd = 'host' then
7187 begin
7188 if gGameSettings.GameType <> GT_NONE then
7189 begin
7190 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
7191 Exit;
7192 end;
7193 if Length(P) < 4 then
7194 begin
7195 g_Console_Add(cmd + ' <listen IP> <port> <WAD> [MAP] [# players]');
7196 Exit;
7197 end;
7198 if not StrToIp(P[1], listen) then
7199 Exit;
7200 prt := StrToIntDef(P[2], 25666);
7202 s := addWadExtension(P[3]);
7203 found := e_FindResource(AllMapDirs, s);
7204 P[3] := s;
7205 if found then
7206 begin
7207 // get first map in wad, if not specified
7208 if Length(P) < 5 then
7209 begin
7210 SetLength(P, 5);
7211 P[4] := g_Game_GetFirstMap(P[1]);
7212 end;
7213 s := P[3] + ':\' + UpperCase(P[4]);
7214 if g_Map_Exist(s) then
7215 begin
7216 // start game
7217 g_Game_Free();
7218 with gGameSettings do
7219 begin
7220 Options := gsGameFlags;
7221 GameMode := g_Game_TextToMode(gsGameMode);
7222 if gSwitchGameMode <> GM_NONE then GameMode := gSwitchGameMode;
7223 if GameMode = GM_NONE then GameMode := GM_DM;
7224 if GameMode = GM_SINGLE then GameMode := GM_COOP;
7225 b := 0;
7226 if Length(P) >= 6 then
7227 b := StrToIntDef(P[5], 0);
7228 g_Game_StartServer(s, GameMode, TimeLimit, ScoreLimit, MaxLives, Options, b, listen, prt)
7229 end
7230 end
7231 else
7232 begin
7233 if P[4] = '' then
7234 g_Console_Add(Format(_lc[I_MSG_NO_MAPS], [P[3]]))
7235 else
7236 g_Console_Add(Format(_lc[I_MSG_NO_MAP_FALLBACK], [UpperCase(P[4]), P[3]]))
7237 end
7238 end
7239 else
7240 begin
7241 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[3]]))
7242 end
7243 end
7244 else if cmd = 'map' then
7245 begin
7246 if Length(P) = 1 then
7247 begin
7248 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
7249 begin
7250 g_Console_Add(cmd + ' <MAP>');
7251 g_Console_Add(cmd + ' <WAD> [MAP]')
7252 end
7253 else
7254 begin
7255 g_Console_Add(_lc[I_MSG_GM_UNAVAIL])
7256 end
7257 end
7258 else if not e_IsValidResourceName(P[1]) then
7259 begin
7260 g_Console_Add('wad name must not be absolute or relative');
7261 end
7262 else
7263 begin
7264 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
7265 begin
7266 if Length(P) < 3 then
7267 begin
7268 // first param is map or wad
7269 s := UpperCase(P[1]);
7270 if g_Map_Exist(gGameSettings.WAD + ':\' + s) then
7271 begin
7272 gExitByTrigger := False;
7273 if gGameOn then
7274 begin
7275 // already in game, finish current map
7276 gNextMap := s;
7277 gExit := EXIT_ENDLEVELCUSTOM;
7278 end
7279 else
7280 begin
7281 // intermission, so change map immediately
7282 g_Game_ChangeMap(s)
7283 end
7284 end
7285 else
7286 begin
7287 s := P[1];
7288 found := e_FindResource(AllMapDirs, s);
7289 P[1] := s;
7290 g_Console_Add(Format(_lc[I_MSG_NO_MAP_FALLBACK], [s, 'WAD ' + P[1]]));
7291 if found then
7292 begin
7293 // no such map, found wad
7294 pw := P[1];
7295 SetLength(P, 3);
7296 P[1] := ExpandFileName(pw);
7297 P[2] := g_Game_GetFirstMap(P[1]);
7298 s := P[1] + ':\' + P[2];
7299 if g_Map_Exist(s) then
7300 begin
7301 gExitByTrigger := False;
7302 if gGameOn then
7303 begin
7304 // already in game, finish current map
7305 gNextMap := s;
7306 gExit := EXIT_ENDLEVELCUSTOM
7307 end
7308 else
7309 begin
7310 // intermission, so change map immediately
7311 g_Game_ChangeMap(s)
7312 end
7313 end
7314 else
7315 begin
7316 if P[2] = '' then
7317 g_Console_Add(Format(_lc[I_MSG_NO_MAPS], [P[1]]))
7318 else
7319 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [P[2]]))
7320 end
7321 end
7322 else
7323 begin
7324 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]))
7325 end
7326 end;
7327 end
7328 else
7329 begin
7330 s := addWadExtension(P[1]);
7331 found := e_FindResource(AllMapDirs, s);
7332 P[1] := s;
7333 if found then
7334 begin
7335 P[2] := UpperCase(P[2]);
7336 s := P[1] + ':\' + P[2];
7337 if g_Map_Exist(s) then
7338 begin
7339 gExitByTrigger := False;
7340 if gGameOn then
7341 begin
7342 gNextMap := s;
7343 gExit := EXIT_ENDLEVELCUSTOM
7344 end
7345 else
7346 begin
7347 g_Game_ChangeMap(s)
7348 end
7349 end
7350 else
7351 begin
7352 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [P[2]]))
7353 end
7354 end
7355 else
7356 begin
7357 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]))
7358 end
7359 end
7360 end
7361 else
7362 begin
7363 g_Console_Add(_lc[I_MSG_GM_UNAVAIL])
7364 end
7365 end
7366 end
7367 else if cmd = 'nextmap' then
7368 begin
7369 if not(gGameOn or (gState = STATE_INTERCUSTOM)) then
7370 begin
7371 g_Console_Add(_lc[I_MSG_NOT_GAME])
7372 end
7373 else
7374 begin
7375 nm := True;
7376 if Length(P) = 1 then
7377 begin
7378 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
7379 begin
7380 g_Console_Add(cmd + ' <MAP>');
7381 g_Console_Add(cmd + ' <WAD> [MAP]');
7382 end
7383 else
7384 begin
7385 nm := False;
7386 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
7387 end;
7388 end
7389 else if not e_IsValidResourceName(P[1]) then
7390 begin
7391 g_Console_Add('wad name must not be absolute or relative');
7392 end
7393 else
7394 begin
7395 nm := False;
7396 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
7397 begin
7398 if Length(P) < 3 then
7399 begin
7400 // first param is map or wad
7401 s := UpperCase(P[1]);
7402 if g_Map_Exist(gGameSettings.WAD + ':\' + s) then
7403 begin
7404 // map founded
7405 gExitByTrigger := False;
7406 gNextMap := s;
7407 nm := True;
7408 end
7409 else
7410 begin
7411 // no such map, found wad
7412 pw := addWadExtension(P[1]);
7413 found := e_FindResource(MapDirs, pw);
7414 if not found then
7415 found := e_FindResource(WadDirs, pw);
7416 P[1] := pw;
7417 g_Console_Add(Format(_lc[I_MSG_NO_MAP_FALLBACK], [s, P[1]]));
7418 if found then
7419 begin
7420 // map not specified, select first map
7421 SetLength(P, 3);
7422 P[2] := g_Game_GetFirstMap(P[1]);
7423 s := P[1] + ':\' + P[2];
7424 if g_Map_Exist(s) then
7425 begin
7426 gExitByTrigger := False;
7427 gNextMap := s;
7428 nm := True
7429 end
7430 else
7431 begin
7432 if P[2] = '' then
7433 g_Console_Add(Format(_lc[I_MSG_NO_MAPS], [P[1]]))
7434 else
7435 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [P[2]]))
7436 end
7437 end
7438 else
7439 begin
7440 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]))
7441 end
7442 end
7443 end
7444 else
7445 begin
7446 // specified two params wad + map
7447 pw := addWadExtension(P[1]);
7448 found := e_FindResource(MapDirs, pw);
7449 if not found then
7450 found := e_FindResource(MapDirs, pw);
7451 P[1] := pw;
7452 if found then
7453 begin
7454 P[2] := UpperCase(P[2]);
7455 s := P[1] + ':\' + P[2];
7456 if g_Map_Exist(s) then
7457 begin
7458 gExitByTrigger := False;
7459 gNextMap := s;
7460 nm := True
7461 end
7462 else
7463 begin
7464 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [P[2]]))
7465 end
7466 end
7467 else
7468 begin
7469 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]))
7470 end
7471 end
7472 end
7473 else
7474 begin
7475 g_Console_Add(_lc[I_MSG_GM_UNAVAIL])
7476 end
7477 end;
7478 if nm then
7479 begin
7480 if gNextMap = '' then
7481 g_Console_Add(_lc[I_MSG_NEXTMAP_UNSET])
7482 else
7483 g_Console_Add(Format(_lc[I_MSG_NEXTMAP_SET], [gNextMap]))
7484 end
7485 end
7486 end
7487 else if (cmd = 'endmap') or (cmd = 'goodbye') then
7488 begin
7489 if not gGameOn then
7490 begin
7491 g_Console_Add(_lc[I_MSG_NOT_GAME])
7492 end
7493 else
7494 begin
7495 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
7496 begin
7497 gExitByTrigger := False;
7498 // next map not specified, try to find trigger EXIT
7499 if (gNextMap = '') and (gTriggers <> nil) then
7500 begin
7501 for a := 0 to High(gTriggers) do
7502 begin
7503 if gTriggers[a].TriggerType = TRIGGER_EXIT then
7504 begin
7505 gExitByTrigger := True;
7506 //gNextMap := gTriggers[a].Data.MapName;
7507 gNextMap := gTriggers[a].tgcMap;
7508 Break
7509 end
7510 end
7511 end;
7512 if gNextMap = '' then
7513 gNextMap := g_Game_GetNextMap();
7514 if not isWadPath(gNextMap) then
7515 s := gGameSettings.WAD + ':\' + gNextMap
7516 else
7517 s := gNextMap;
7518 if g_Map_Exist(s) then
7519 gExit := EXIT_ENDLEVELCUSTOM
7520 else
7521 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [gNextMap]))
7522 end
7523 else
7524 begin
7525 g_Console_Add(_lc[I_MSG_GM_UNAVAIL])
7526 end
7527 end
7528 end
7529 else if (cmd = 'event') then
7530 begin
7531 if (Length(P) <= 1) then
7532 begin
7533 for a := 0 to High(gEvents) do
7534 if gEvents[a].Command = '' then
7535 g_Console_Add(gEvents[a].Name + ' <none>')
7536 else
7537 g_Console_Add(gEvents[a].Name + ' "' + gEvents[a].Command + '"');
7538 Exit;
7539 end;
7540 if (Length(P) = 2) then
7541 begin
7542 for a := 0 to High(gEvents) do
7543 if gEvents[a].Name = P[1] then
7544 if gEvents[a].Command = '' then
7545 g_Console_Add(gEvents[a].Name + ' <none>')
7546 else
7547 g_Console_Add(gEvents[a].Name + ' "' + gEvents[a].Command + '"');
7548 Exit;
7549 end;
7550 for a := 0 to High(gEvents) do
7551 if gEvents[a].Name = P[1] then
7552 begin
7553 gEvents[a].Command := '';
7554 for b := 2 to High(P) do
7555 if Pos(' ', P[b]) = 0 then
7556 gEvents[a].Command := gEvents[a].Command + ' ' + P[b]
7557 else
7558 gEvents[a].Command := gEvents[a].Command + ' "' + P[b] + '"';
7559 gEvents[a].Command := Trim(gEvents[a].Command);
7560 Exit;
7561 end;
7562 end
7563 else if cmd = 'suicide' then
7564 begin
7565 if gGameOn then
7566 begin
7567 if g_Game_IsClient then
7568 MC_SEND_CheatRequest(NET_CHEAT_SUICIDE)
7569 else
7570 begin
7571 if gPlayer1 <> nil then
7572 gPlayer1.Damage(SUICIDE_DAMAGE, gPlayer1.UID, 0, 0, HIT_SELF);
7573 if gPlayer2 <> nil then
7574 gPlayer2.Damage(SUICIDE_DAMAGE, gPlayer2.UID, 0, 0, HIT_SELF);
7575 end;
7576 end;
7577 end
7578 else if cmd = 'screenshot' then
7579 begin
7580 g_TakeScreenShot()
7581 end
7582 else if (cmd = 'weapnext') or (cmd = 'weapprev') then
7583 begin
7584 a := 1 - (ord(cmd[5]) - ord('n'));
7585 if a = -1 then
7586 gWeaponAction[0, WP_PREV] := True;
7587 if a = 1 then
7588 gWeaponAction[0, WP_NEXT] := True;
7589 end
7590 else if cmd = 'weapon' then
7591 begin
7592 if Length(p) = 2 then
7593 begin
7594 a := WP_FIRST + StrToIntDef(p[1], 0) - 1;
7595 if (a >= WP_FIRST) and (a <= WP_LAST) then
7596 gSelectWeapon[0, a] := True
7597 end
7598 end
7599 else if (cmd = 'p1_weapnext') or (cmd = 'p1_weapprev')
7600 or (cmd = 'p2_weapnext') or (cmd = 'p2_weapprev') then
7601 begin
7602 a := 1 - (ord(cmd[8]) - ord('n'));
7603 b := ord(cmd[2]) - ord('1');
7604 if a = -1 then
7605 gWeaponAction[b, WP_PREV] := True;
7606 if a = 1 then
7607 gWeaponAction[b, WP_NEXT] := True;
7608 end
7609 else if (cmd = 'p1_weapon') or (cmd = 'p2_weapon') then
7610 begin
7611 if Length(p) = 2 then
7612 begin
7613 a := WP_FIRST + StrToIntDef(p[1], 0) - 1;
7614 b := ord(cmd[2]) - ord('1');
7615 if (a >= WP_FIRST) and (a <= WP_LAST) then
7616 gSelectWeapon[b, a] := True
7617 end
7618 end
7619 else if (cmd = 'p1_weapbest') or (cmd = 'p2_weapbest') then
7620 begin
7621 b := ord(cmd[2]) - ord('1');
7622 if b = 0 then
7623 gSelectWeapon[b, gPlayer1.GetMorePrefered()] := True
7624 else
7625 gSelectWeapon[b, gPlayer2.GetMorePrefered()] := True;
7626 end
7627 else if (cmd = 'dropflag') then
7628 begin
7629 if g_Game_IsServer then
7630 begin
7631 if gPlayer2 <> nil then gPlayer2.TryDropFlag();
7632 if gPlayer1 <> nil then gPlayer1.TryDropFlag();
7633 end
7634 else
7635 MC_SEND_CheatRequest(NET_CHEAT_DROPFLAG);
7636 end
7637 else if (cmd = 'p1_dropflag') or (cmd = 'p2_dropflag') then
7638 begin
7639 b := ord(cmd[2]) - ord('1');
7640 if g_Game_IsServer then
7641 begin
7642 if (b = 1) and (gPlayer2 <> nil) then gPlayer2.TryDropFlag()
7643 else if (b = 0) and (gPlayer1 <> nil) then gPlayer1.TryDropFlag();
7644 end
7645 else
7646 MC_SEND_CheatRequest(NET_CHEAT_DROPFLAG);
7647 end
7648 // Êîìàíäû Ñâîåé èãðû:
7649 else if gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT] then
7650 begin
7651 if cmd = 'bot_addred' then
7652 begin
7653 if Length(P) > 1 then
7654 g_Bot_Add(TEAM_RED, StrToIntDef(P[1], 2))
7655 else
7656 g_Bot_Add(TEAM_RED, 2);
7657 end
7658 else if cmd = 'bot_addblue' then
7659 begin
7660 if Length(P) > 1 then
7661 g_Bot_Add(TEAM_BLUE, StrToIntDef(P[1], 2))
7662 else
7663 g_Bot_Add(TEAM_BLUE, 2);
7664 end
7665 else if cmd = 'spectate' then
7666 begin
7667 if not gGameOn then
7668 Exit;
7669 g_Game_Spectate();
7670 end
7671 else if cmd = 'say' then
7672 begin
7673 if g_Game_IsServer and g_Game_IsNet then
7674 begin
7675 if Length(P) > 1 then
7676 begin
7677 chstr := '';
7678 for a := 1 to High(P) do
7679 chstr := chstr + P[a] + ' ';
7681 if Length(chstr) > 200 then SetLength(chstr, 200);
7683 if Length(chstr) < 1 then
7684 begin
7685 g_Console_Add('say <text>');
7686 Exit;
7687 end;
7689 chstr := b_Text_Format(chstr);
7690 MH_SEND_Chat(chstr, NET_CHAT_PLAYER);
7691 end
7692 else g_Console_Add('say <text>');
7693 end else
7694 g_Console_Add(_lc[I_MSG_SERVERONLY]);
7695 end
7696 else if cmd = 'tell' then
7697 begin
7698 if g_Game_IsServer and g_Game_IsNet then
7699 begin
7700 if (Length(P) > 2) and (P[1] <> '') then
7701 begin
7702 chstr := '';
7703 for a := 2 to High(P) do
7704 chstr := chstr + P[a] + ' ';
7706 if Length(chstr) > 200 then SetLength(chstr, 200);
7708 if Length(chstr) < 1 then
7709 begin
7710 g_Console_Add('tell <playername> <text>');
7711 Exit;
7712 end;
7714 pl := g_Net_Client_ByName(P[1]);
7715 if pl <> nil then
7716 MH_SEND_Chat(b_Text_Format(chstr), NET_CHAT_PLAYER, pl^.ID)
7717 else
7718 g_Console_Add(Format(_lc[I_NET_ERR_NAME404], [P[1]]));
7719 end
7720 else g_Console_Add('tell <playername> <text>');
7721 end else
7722 g_Console_Add(_lc[I_MSG_SERVERONLY]);
7723 end
7724 else if cmd = 'centerprint' then
7725 begin
7726 if (Length(P) > 2) and (P[1] <> '') then
7727 begin
7728 chstr := '';
7729 for a := 2 to High(P) do
7730 chstr := chstr + P[a] + ' ';
7732 if Length(chstr) > 200 then SetLength(chstr, 200);
7734 if Length(chstr) < 1 then
7735 begin
7736 g_Console_Add('centerprint <timeout> <text>');
7737 Exit;
7738 end;
7740 a := StrToIntDef(P[1], 100);
7741 chstr := b_Text_Format(chstr);
7742 g_Game_Message(chstr, a);
7743 if g_Game_IsNet and g_Game_IsServer then
7744 MH_SEND_GameEvent(NET_EV_BIGTEXT, a, chstr);
7745 end
7746 else g_Console_Add('centerprint <timeout> <text>');
7747 end
7748 else if (cmd = 'overtime') and not g_Game_IsClient then
7749 begin
7750 if (Length(P) = 1) or (StrToIntDef(P[1], -1) <= 0) then
7751 Exit;
7752 // Äîïîëíèòåëüíîå âðåìÿ:
7753 gGameSettings.TimeLimit := (gTime - gGameStartTime) div 1000 + Word(StrToIntDef(P[1], 0));
7755 g_Console_Add(Format(_lc[I_MSG_TIME_LIMIT],
7756 [gGameSettings.TimeLimit div 3600,
7757 (gGameSettings.TimeLimit div 60) mod 60,
7758 gGameSettings.TimeLimit mod 60]));
7759 if g_Game_IsNet then MH_SEND_GameSettings;
7760 end
7761 else if (cmd = 'rcon_password') and g_Game_IsClient then
7762 begin
7763 if (Length(P) <= 1) then
7764 g_Console_Add('rcon_password <password>')
7765 else
7766 MC_SEND_RCONPassword(P[1]);
7767 end
7768 else if cmd = 'rcon' then
7769 begin
7770 if g_Game_IsClient then
7771 begin
7772 if Length(P) > 1 then
7773 begin
7774 chstr := '';
7775 for a := 1 to High(P) do
7776 chstr := chstr + P[a] + ' ';
7778 if Length(chstr) > 200 then SetLength(chstr, 200);
7780 if Length(chstr) < 1 then
7781 begin
7782 g_Console_Add('rcon <command>');
7783 Exit;
7784 end;
7786 MC_SEND_RCONCommand(chstr);
7787 end
7788 else g_Console_Add('rcon <command>');
7789 end;
7790 end
7791 else if cmd = 'ready' then
7792 begin
7793 if g_Game_IsServer and (gLMSRespawn = LMS_RESPAWN_WARMUP) then
7794 gLMSRespawnTime := gTime + 100;
7795 end
7796 else if (cmd = 'callvote') and g_Game_IsNet then
7797 begin
7798 if Length(P) > 1 then
7799 begin
7800 chstr := '';
7801 for a := 1 to High(P) do begin
7802 if a > 1 then chstr := chstr + ' ';
7803 chstr := chstr + P[a];
7804 end;
7806 if Length(chstr) > 200 then SetLength(chstr, 200);
7808 if Length(chstr) < 1 then
7809 begin
7810 g_Console_Add('callvote <command>');
7811 Exit;
7812 end;
7814 if g_Game_IsClient then
7815 MC_SEND_Vote(True, chstr)
7816 else
7817 g_Game_StartVote(chstr, gPlayer1Settings.Name);
7818 g_Console_Process('vote', True);
7819 end
7820 else
7821 g_Console_Add('callvote <command>');
7822 end
7823 else if (cmd = 'vote') and g_Game_IsNet then
7824 begin
7825 if g_Game_IsClient then
7826 MC_SEND_Vote(False)
7827 else if gVoteInProgress then
7828 begin
7829 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
7830 a := Floor((NetClientCount+1)/2.0) + 1
7831 else
7832 a := Floor(NetClientCount/2.0) + 1;
7833 if gVoted then
7834 begin
7835 Dec(gVoteCount);
7836 gVoted := False;
7837 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_REVOKED], [gPlayer1Settings.Name, gVoteCount, a]), True);
7838 MH_SEND_VoteEvent(NET_VE_REVOKE, gPlayer1Settings.Name, 'a', gVoteCount, a);
7839 end
7840 else
7841 begin
7842 Inc(gVoteCount);
7843 gVoted := True;
7844 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_VOTE], [gPlayer1Settings.Name, gVoteCount, a]), True);
7845 MH_SEND_VoteEvent(NET_VE_VOTE, gPlayer1Settings.Name, 'a', gVoteCount, a);
7846 g_Game_CheckVote;
7847 end;
7848 end;
7849 end
7850 end;
7851 end;
7853 procedure SystemCommands(P: SSArray);
7854 var
7855 cmd: string;
7856 begin
7857 cmd := LowerCase(P[0]);
7858 case cmd of
7859 'exit', 'quit':
7860 begin
7861 g_Game_Free();
7862 g_Game_Quit();
7863 end;
7864 'r_reset':
7865 begin
7866 gRC_Width := Max(1, gRC_Width);
7867 gRC_Height := Max(1, gRC_Height);
7868 gBPP := Max(1, gBPP);
7869 if sys_SetDisplayMode(gRC_Width, gRC_Height, gBPP, gRC_FullScreen, gRC_Maximized) = True then
7870 e_LogWriteln('resolution changed')
7871 else
7872 e_LogWriteln('resolution not changed');
7873 sys_EnableVSync(gVSync);
7874 end;
7875 'r_maxfps':
7876 begin
7877 if Length(p) = 2 then
7878 begin
7879 gMaxFPS := StrToIntDef(p[1], gMaxFPS);
7880 if gMaxFPS > 0 then
7881 gFrameTime := 1000 div gMaxFPS
7882 else
7883 gFrameTime := 0;
7884 end;
7885 e_LogWritefln('r_maxfps %d', [gMaxFPS]);
7886 end;
7887 'g_language':
7888 begin
7889 if Length(p) = 2 then
7890 begin
7891 gAskLanguage := true;
7892 gLanguage := LANGUAGE_ENGLISH;
7893 case LowerCase(p[1]) of
7894 'english':
7895 begin
7896 gAskLanguage := false;
7897 gLanguage := LANGUAGE_ENGLISH;
7898 end;
7899 'russian':
7900 begin
7901 gAskLanguage := false;
7902 gLanguage := LANGUAGE_RUSSIAN;
7903 end;
7904 'ask':
7905 begin
7906 gAskLanguage := true;
7907 gLanguage := LANGUAGE_ENGLISH;
7908 end;
7909 end;
7910 g_Language_Set(gLanguage);
7911 end
7912 else
7913 begin
7914 e_LogWritefln('usage: %s <English|Russian|Ask>', [cmd]);
7915 end
7916 end;
7917 end;
7918 end;
7920 procedure g_TakeScreenShot(Filename: string = '');
7921 var s: TStream; t: TDateTime; dir, date, name: String;
7922 begin
7923 if e_NoGraphics then Exit;
7924 try
7925 dir := e_GetWriteableDir(ScreenshotDirs);
7927 if Filename = '' then
7928 begin
7929 t := Now;
7930 DateTimeToString(date, 'yyyy-mm-dd-hh-nn-ss', t);
7931 Filename := 'screenshot-' + date;
7932 end;
7934 name := e_CatPath(dir, Filename + '.png');
7935 s := createDiskFile(name);
7936 try
7937 e_MakeScreenshot(s, gWinSizeX, gWinSizeY);
7938 s.Free;
7939 g_Console_Add(Format(_lc[I_CONSOLE_SCREENSHOT], [name]))
7940 except
7941 g_Console_Add(Format(_lc[I_CONSOLE_ERROR_WRITE], [name]));
7942 s.Free;
7943 DeleteFile(name)
7944 end
7945 except
7946 g_Console_Add('oh shit, i can''t create screenshot!')
7947 end
7948 end;
7950 procedure g_Game_InGameMenu(Show: Boolean);
7951 begin
7952 if (g_ActiveWindow = nil) and Show then
7953 begin
7954 if gGameSettings.GameType = GT_SINGLE then
7955 g_GUI_ShowWindow('GameSingleMenu')
7956 else
7957 begin
7958 if g_Game_IsClient then
7959 g_GUI_ShowWindow('GameClientMenu')
7960 else
7961 if g_Game_IsNet then
7962 g_GUI_ShowWindow('GameServerMenu')
7963 else
7964 g_GUI_ShowWindow('GameCustomMenu');
7965 end;
7966 g_Sound_PlayEx('MENU_OPEN');
7968 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
7969 if (not g_Game_IsNet) then
7970 g_Game_Pause(True);
7971 end
7972 else
7973 if (g_ActiveWindow <> nil) and (not Show) then
7974 begin
7975 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
7976 if (not g_Game_IsNet) then
7977 g_Game_Pause(False);
7978 end;
7979 end;
7981 procedure g_Game_Pause (Enable: Boolean);
7982 var
7983 oldPause: Boolean;
7984 begin
7985 if not gGameOn then exit;
7987 if not (gGameSettings.GameType in [GT_SINGLE, GT_CUSTOM]) then exit;
7989 oldPause := gPause;
7990 gPauseMain := Enable;
7992 if (gPause <> oldPause) then g_Game_PauseAllSounds(gPause);
7993 end;
7995 procedure g_Game_HolmesPause (Enable: Boolean);
7996 var
7997 oldPause: Boolean;
7998 begin
7999 if not gGameOn then exit;
8000 if not (gGameSettings.GameType in [GT_SINGLE, GT_CUSTOM]) then exit;
8002 oldPause := gPause;
8003 gPauseHolmes := Enable;
8005 if (gPause <> oldPause) then g_Game_PauseAllSounds(gPause);
8006 end;
8008 procedure g_Game_PauseAllSounds(Enable: Boolean);
8009 var
8010 i: Integer;
8011 begin
8012 // Òðèããåðû:
8013 if gTriggers <> nil then
8014 for i := 0 to High(gTriggers) do
8015 with gTriggers[i] do
8016 if (TriggerType = TRIGGER_SOUND) and
8017 (Sound <> nil) and
8018 Sound.IsPlaying() then
8019 begin
8020 Sound.Pause(Enable);
8021 end;
8023 // Çâóêè èãðîêîâ:
8024 if gPlayers <> nil then
8025 for i := 0 to High(gPlayers) do
8026 if gPlayers[i] <> nil then
8027 gPlayers[i].PauseSounds(Enable);
8029 // Ìóçûêà:
8030 if gMusic <> nil then
8031 gMusic.Pause(Enable);
8032 end;
8034 procedure g_Game_StopAllSounds(all: Boolean);
8035 var
8036 i: Integer;
8037 begin
8038 if gTriggers <> nil then
8039 for i := 0 to High(gTriggers) do
8040 with gTriggers[i] do
8041 if (TriggerType = TRIGGER_SOUND) and
8042 (Sound <> nil) then
8043 Sound.Stop();
8045 if gMusic <> nil then
8046 gMusic.Stop();
8048 if all then
8049 e_StopChannels();
8050 end;
8052 procedure g_Game_UpdateTriggerSounds;
8053 var i: Integer;
8054 begin
8055 if gTriggers <> nil then
8056 for i := 0 to High(gTriggers) do
8057 with gTriggers[i] do
8058 if (TriggerType = TRIGGER_SOUND) and (Sound <> nil) and tgcLocal and Sound.IsPlaying() then
8059 Sound.SetCoordsRect(X, Y, Width, Height, tgcVolume / 255.0)
8060 end;
8062 function g_Game_IsWatchedPlayer(UID: Word): Boolean;
8063 begin
8064 Result := False;
8065 if (gPlayer1 <> nil) and (gPlayer1.UID = UID) then
8066 begin
8067 Result := True;
8068 Exit;
8069 end;
8070 if (gPlayer2 <> nil) and (gPlayer2.UID = UID) then
8071 begin
8072 Result := True;
8073 Exit;
8074 end;
8075 if gSpectMode <> SPECT_PLAYERS then
8076 Exit;
8077 if gSpectPID1 = UID then
8078 begin
8079 Result := True;
8080 Exit;
8081 end;
8082 if gSpectViewTwo and (gSpectPID2 = UID) then
8083 begin
8084 Result := True;
8085 Exit;
8086 end;
8087 end;
8089 function g_Game_IsWatchedTeam(Team: Byte): Boolean;
8090 var
8091 Pl: TPlayer;
8092 begin
8093 Result := False;
8094 if (gPlayer1 <> nil) and (gPlayer1.Team = Team) then
8095 begin
8096 Result := True;
8097 Exit;
8098 end;
8099 if (gPlayer2 <> nil) and (gPlayer2.Team = Team) then
8100 begin
8101 Result := True;
8102 Exit;
8103 end;
8104 if gSpectMode <> SPECT_PLAYERS then
8105 Exit;
8106 Pl := g_Player_Get(gSpectPID1);
8107 if (Pl <> nil) and (Pl.Team = Team) then
8108 begin
8109 Result := True;
8110 Exit;
8111 end;
8112 if gSpectViewTwo then
8113 begin
8114 Pl := g_Player_Get(gSpectPID2);
8115 if (Pl <> nil) and (Pl.Team = Team) then
8116 begin
8117 Result := True;
8118 Exit;
8119 end;
8120 end;
8121 end;
8123 procedure g_Game_Message(Msg: string; Time: Word);
8124 begin
8125 MessageLineLength := (gScreenWidth - 204) div e_CharFont_GetMaxWidth(gMenuFont);
8126 MessageText := b_Text_Wrap(b_Text_Format(Msg), MessageLineLength);
8127 MessageTime := Time;
8128 end;
8130 procedure g_Game_ChatSound(Text: String; Taunt: Boolean = True);
8131 const
8132 punct: Array[0..13] of String =
8133 ('.', ',', ':', ';', '!', '?', '(', ')', '''', '"', '/', '\', '*', '^');
8134 var
8135 i, j: Integer;
8136 ok: Boolean;
8137 fpText: String;
8139 function IsPunctuation(S: String): Boolean;
8140 var
8141 i: Integer;
8142 begin
8143 Result := False;
8144 if Length(S) <> 1 then
8145 Exit;
8146 for i := Low(punct) to High(punct) do
8147 if S = punct[i] then
8148 begin
8149 Result := True;
8150 break;
8151 end;
8152 end;
8153 function FilterPunctuation(S: String): String;
8154 var
8155 i: Integer;
8156 begin
8157 for i := Low(punct) to High(punct) do
8158 S := StringReplace(S, punct[i], ' ', [rfReplaceAll]);
8159 Result := S;
8160 end;
8161 begin
8162 ok := False;
8164 if gUseChatSounds and Taunt and (gChatSounds <> nil) and (Pos(': ', Text) > 0) then
8165 begin
8166 // remove player name
8167 Delete(Text, 1, Pos(': ', Text) + 2 - 1);
8168 // for FullWord check
8169 Text := toLowerCase1251(' ' + Text + ' ');
8170 fpText := FilterPunctuation(Text);
8172 for i := 0 to Length(gChatSounds) - 1 do
8173 begin
8174 ok := True;
8175 for j := 0 to Length(gChatSounds[i].Tags) - 1 do
8176 begin
8177 if gChatSounds[i].FullWord and (not IsPunctuation(gChatSounds[i].Tags[j])) then
8178 ok := Pos(' ' + gChatSounds[i].Tags[j] + ' ', fpText) > 0
8179 else
8180 ok := Pos(gChatSounds[i].Tags[j], Text) > 0;
8181 if not ok then
8182 break;
8183 end;
8184 if ok then
8185 begin
8186 gChatSounds[i].Sound.Play();
8187 break;
8188 end;
8189 end;
8190 end;
8191 if not ok then
8192 g_Sound_PlayEx('SOUND_GAME_RADIO');
8193 end;
8195 procedure g_Game_Announce_GoodShot(SpawnerUID: Word);
8196 var
8197 a: Integer;
8198 begin
8199 case gAnnouncer of
8200 ANNOUNCE_NONE:
8201 Exit;
8202 ANNOUNCE_ME,
8203 ANNOUNCE_MEPLUS:
8204 if not g_Game_IsWatchedPlayer(SpawnerUID) then
8205 Exit;
8206 end;
8207 for a := 0 to 3 do
8208 if goodsnd[a].IsPlaying() then
8209 Exit;
8211 goodsnd[Random(4)].Play();
8212 end;
8214 procedure g_Game_Announce_KillCombo(Param: Integer);
8215 var
8216 UID: Word;
8217 c, n: Byte;
8218 Pl: TPlayer;
8219 Name: String;
8220 begin
8221 UID := Param and $FFFF;
8222 c := Param shr 16;
8223 if c < 2 then
8224 Exit;
8226 Pl := g_Player_Get(UID);
8227 if Pl = nil then
8228 Name := '?'
8229 else
8230 Name := Pl.Name;
8232 case c of
8233 2: begin
8234 n := 0;
8235 g_Console_Add(Format(_lc[I_PLAYER_KILL_2X], [Name]), True);
8236 end;
8237 3: begin
8238 n := 1;
8239 g_Console_Add(Format(_lc[I_PLAYER_KILL_3X], [Name]), True);
8240 end;
8241 4: begin
8242 n := 2;
8243 g_Console_Add(Format(_lc[I_PLAYER_KILL_4X], [Name]), True);
8244 end;
8245 else begin
8246 n := 3;
8247 g_Console_Add(Format(_lc[I_PLAYER_KILL_MX], [Name]), True);
8248 end;
8249 end;
8251 case gAnnouncer of
8252 ANNOUNCE_NONE:
8253 Exit;
8254 ANNOUNCE_ME:
8255 if not g_Game_IsWatchedPlayer(UID) then
8256 Exit;
8257 ANNOUNCE_MEPLUS:
8258 if (not g_Game_IsWatchedPlayer(UID)) and (c < 4) then
8259 Exit;
8260 end;
8262 if killsnd[n].IsPlaying() then
8263 killsnd[n].Stop();
8264 killsnd[n].Play();
8265 end;
8267 procedure g_Game_Announce_BodyKill(SpawnerUID: Word);
8268 var
8269 a: Integer;
8270 begin
8271 case gAnnouncer of
8272 ANNOUNCE_NONE:
8273 Exit;
8274 ANNOUNCE_ME:
8275 if not g_Game_IsWatchedPlayer(SpawnerUID) then
8276 Exit;
8277 end;
8278 for a := 0 to 2 do
8279 if hahasnd[a].IsPlaying() then
8280 Exit;
8282 hahasnd[Random(3)].Play();
8283 end;
8285 procedure g_Game_Effect_Bubbles (fX, fY: Integer; count: Word; devX, devY: Byte; Silent: Boolean);
8286 begin
8287 g_GFX_Bubbles(fX, fY, count, devX, devY);
8288 if not Silent then if Random(2) = 0
8289 then g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', fX, fY)
8290 else g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', fX, fY);
8291 end;
8293 procedure g_Game_StartVote(Command, Initiator: string);
8294 var
8295 Need: Integer;
8296 begin
8297 if not gVotesEnabled then Exit;
8298 if gGameSettings.GameType <> GT_SERVER then Exit;
8299 if gVoteInProgress or gVotePassed then
8300 begin
8301 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_INPROGRESS], [gVoteCommand]), True);
8302 MH_SEND_VoteEvent(NET_VE_INPROGRESS, gVoteCommand);
8303 Exit;
8304 end;
8305 gVoteInProgress := True;
8306 gVotePassed := False;
8307 gVoteTimer := gTime + gVoteTimeout * 1000;
8308 gVoteCount := 0;
8309 gVoted := False;
8310 gVoteCommand := Command;
8312 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
8313 Need := Floor((NetClientCount+1)/2.0)+1
8314 else
8315 Need := Floor(NetClientCount/2.0)+1;
8316 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_STARTED], [Initiator, Command, Need]), True);
8317 MH_SEND_VoteEvent(NET_VE_STARTED, Initiator, Command, Need);
8318 end;
8320 procedure g_Game_CheckVote;
8321 var
8322 I, Need: Integer;
8323 begin
8324 if gGameSettings.GameType <> GT_SERVER then Exit;
8325 if not gVoteInProgress then Exit;
8327 if (gTime >= gVoteTimer) then
8328 begin
8329 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
8330 Need := Floor((NetClientCount+1)/2.0) + 1
8331 else
8332 Need := Floor(NetClientCount/2.0) + 1;
8333 if gVoteCount >= Need then
8334 begin
8335 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_PASSED], [gVoteCommand]), True);
8336 MH_SEND_VoteEvent(NET_VE_PASSED, gVoteCommand);
8337 gVotePassed := True;
8338 gVoteCmdTimer := gTime + 5000;
8339 end
8340 else
8341 begin
8342 g_Console_Add(_lc[I_MESSAGE_VOTE_FAILED], True);
8343 MH_SEND_VoteEvent(NET_VE_FAILED);
8344 end;
8345 if NetClients <> nil then
8346 for I := Low(NetClients) to High(NetClients) do
8347 if NetClients[i].Used then
8348 NetClients[i].Voted := False;
8349 gVoteInProgress := False;
8350 gVoted := False;
8351 gVoteCount := 0;
8352 end
8353 else
8354 begin
8355 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
8356 Need := Floor((NetClientCount+1)/2.0) + 1
8357 else
8358 Need := Floor(NetClientCount/2.0) + 1;
8359 if gVoteCount >= Need then
8360 begin
8361 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_PASSED], [gVoteCommand]), True);
8362 MH_SEND_VoteEvent(NET_VE_PASSED, gVoteCommand);
8363 gVoteInProgress := False;
8364 gVotePassed := True;
8365 gVoteCmdTimer := gTime + 5000;
8366 gVoted := False;
8367 gVoteCount := 0;
8368 if NetClients <> nil then
8369 for I := Low(NetClients) to High(NetClients) do
8370 if NetClients[i].Used then
8371 NetClients[i].Voted := False;
8372 end;
8373 end;
8374 end;
8376 procedure g_Game_LoadMapList(FileName: string);
8377 var
8378 ListFile: TextFile;
8379 s: string;
8380 begin
8381 MapList := nil;
8382 MapIndex := -1;
8384 if not FileExists(FileName) then Exit;
8386 AssignFile(ListFile, FileName);
8387 Reset(ListFile);
8388 while not EOF(ListFile) do
8389 begin
8390 ReadLn(ListFile, s);
8392 s := Trim(s);
8393 if s = '' then Continue;
8395 SetLength(MapList, Length(MapList)+1);
8396 MapList[High(MapList)] := s;
8397 end;
8398 CloseFile(ListFile);
8399 end;
8401 procedure g_Game_SetDebugMode();
8402 begin
8403 gDebugMode := True;
8404 // ×èòû (äàæå â ñâîåé èãðå):
8405 gCheats := True;
8406 end;
8408 procedure g_Game_SetLoadingText(Text: String; Max: Integer; reWrite: Boolean);
8409 var
8410 i: Word;
8411 begin
8412 if Length(LoadingStat.Msgs) = 0 then
8413 Exit;
8415 with LoadingStat do
8416 begin
8417 if not reWrite then
8418 begin // Ïåðåõîäèì íà ñëåäóþùóþ ñòðîêó èëè ñêðîëëèðóåì:
8419 if NextMsg = Length(Msgs) then
8420 begin // scroll
8421 for i := 0 to High(Msgs)-1 do
8422 Msgs[i] := Msgs[i+1];
8423 end
8424 else
8425 Inc(NextMsg);
8426 end else
8427 if NextMsg = 0 then
8428 Inc(NextMsg);
8430 Msgs[NextMsg-1] := Text;
8431 CurValue := 0;
8432 MaxValue := Max;
8433 ShowCount := 0;
8434 PBarWasHere := false;
8435 end;
8437 g_ActiveWindow := nil;
8438 ProcessLoading(True);
8439 end;
8441 procedure g_Game_StepLoading(Value: Integer = -1);
8442 begin
8443 with LoadingStat do
8444 begin
8445 if Value = -1 then
8446 begin
8447 Inc(CurValue);
8448 Inc(ShowCount);
8449 end
8450 else
8451 CurValue := Value;
8453 if (ShowCount > LOADING_SHOW_STEP) or (Value > -1) then
8454 begin
8455 ShowCount := 0;
8456 ProcessLoading(False);
8457 end;
8458 end;
8459 end;
8461 procedure g_Game_ClearLoading();
8462 var
8463 len: Word;
8464 begin
8465 with LoadingStat do
8466 begin
8467 CurValue := 0;
8468 MaxValue := 0;
8469 ShowCount := 0;
8470 len := ((gScreenHeight div 3)*2 - 50) div LOADING_INTERLINE;
8471 if len < 1 then len := 1;
8472 SetLength(Msgs, len);
8473 for len := Low(Msgs) to High(Msgs) do
8474 Msgs[len] := '';
8475 NextMsg := 0;
8476 PBarWasHere := false;
8477 end;
8478 end;
8480 procedure Parse_Params(var pars: TParamStrValues);
8481 var
8482 i: Integer;
8483 s: String;
8484 begin
8485 SetLength(pars, 0);
8486 i := 1;
8487 while i <= ParamCount do
8488 begin
8489 s := ParamStr(i);
8490 if (Length(s) > 1) and (s[1] = '-') then
8491 begin
8492 if (Length(s) > 2) and (s[2] = '-') then
8493 begin // Îäèíî÷íûé ïàðàìåòð
8494 SetLength(pars, Length(pars) + 1);
8495 with pars[High(pars)] do
8496 begin
8497 Name := LowerCase(s);
8498 Value := '+';
8499 end;
8500 end
8501 else
8502 if (i < ParamCount) then
8503 begin // Ïàðàìåòð ñî çíà÷åíèåì
8504 Inc(i);
8505 SetLength(pars, Length(pars) + 1);
8506 with pars[High(pars)] do
8507 begin
8508 Name := LowerCase(s);
8509 Value := LowerCase(ParamStr(i));
8510 end;
8511 end;
8512 end;
8514 Inc(i);
8515 end;
8516 end;
8518 function Find_Param_Value(var pars: TParamStrValues; aName: String): String;
8519 var
8520 i: Integer;
8521 begin
8522 Result := '';
8523 for i := 0 to High(pars) do
8524 if pars[i].Name = aName then
8525 begin
8526 Result := pars[i].Value;
8527 Break;
8528 end;
8529 end;
8531 procedure g_Game_Process_Params();
8532 var
8533 pars: TParamStrValues;
8534 map: String;
8535 GMode, n: Byte;
8536 LimT, LimS: Integer;
8537 Opt: LongWord;
8538 Lives: Integer;
8539 s: String;
8540 Port: Integer;
8541 ip: String;
8542 F: TextFile;
8543 begin
8544 Parse_Params(pars);
8546 // Debug mode:
8547 s := Find_Param_Value(pars, '--debug');
8548 if (s <> '') then
8549 begin
8550 g_Game_SetDebugMode();
8551 s := Find_Param_Value(pars, '--netdump');
8552 if (s <> '') then
8553 NetDump := True;
8554 end;
8556 // Connect when game loads
8557 ip := Find_Param_Value(pars, '-connect');
8559 if ip <> '' then
8560 begin
8561 s := Find_Param_Value(pars, '-port');
8562 if (s = '') or not TryStrToInt(s, Port) then
8563 Port := 25666;
8565 s := Find_Param_Value(pars, '-pw');
8567 g_Game_StartClient(ip, Port, s);
8568 Exit;
8569 end;
8571 s := LowerCase(Find_Param_Value(pars, '-dbg-mainwad'));
8572 if (s <> '') then
8573 begin
8574 gDefaultMegawadStart := s;
8575 end;
8577 if (Find_Param_Value(pars, '--dbg-mainwad-restore') <> '') or
8578 (Find_Param_Value(pars, '--dbg-mainwad-default') <> '') then
8579 begin
8580 gDefaultMegawadStart := DF_Default_Megawad_Start;
8581 end;
8583 // Start map when game loads:
8584 map := LowerCase(Find_Param_Value(pars, '-map'));
8585 if isWadPath(map) then
8586 begin
8587 // Game mode:
8588 s := Find_Param_Value(pars, '-gm');
8589 GMode := g_Game_TextToMode(s);
8590 if GMode = GM_NONE then GMode := GM_DM;
8591 if GMode = GM_SINGLE then GMode := GM_COOP;
8593 // Time limit:
8594 s := Find_Param_Value(pars, '-limt');
8595 if (s = '') or (not TryStrToInt(s, LimT)) then
8596 LimT := 0;
8597 if LimT < 0 then
8598 LimT := 0;
8600 // Score limit:
8601 s := Find_Param_Value(pars, '-lims');
8602 if (s = '') or (not TryStrToInt(s, LimS)) then
8603 LimS := 0;
8604 if LimS < 0 then
8605 LimS := 0;
8607 // Lives limit:
8608 s := Find_Param_Value(pars, '-lives');
8609 if (s = '') or (not TryStrToInt(s, Lives)) then
8610 Lives := 0;
8611 if Lives < 0 then
8612 Lives := 0;
8614 // Options:
8615 s := Find_Param_Value(pars, '-opt');
8616 if (s = '') then
8617 Opt := gsGameFlags
8618 else
8619 Opt := StrToIntDef(s, 0);
8621 // Close after map:
8622 s := Find_Param_Value(pars, '--close');
8623 if (s <> '') then
8624 gMapOnce := True;
8626 // Override map to test:
8627 s := LowerCase(Find_Param_Value(pars, '-testmap'));
8628 if s <> '' then
8629 begin
8630 if e_IsValidResourceName(s) then
8631 e_FindResource(AllMapDirs, s);
8632 gTestMap := ExpandFileName(s);
8633 end;
8635 // Delete test map after play:
8636 s := Find_Param_Value(pars, '--testdelete');
8637 if (s <> '') then
8638 begin
8639 //gMapToDelete := MapsDir + map;
8640 e_WriteLog('"--testdelete" is deprecated, use --tempdelete.', TMsgType.Fatal);
8641 Halt(1);
8642 end;
8644 // Delete temporary WAD after play:
8645 s := Find_Param_Value(pars, '--tempdelete');
8646 if (s <> '') and (gTestMap <> '') then
8647 begin
8648 gMapToDelete := gTestMap;
8649 gTempDelete := True;
8650 end;
8652 // Number of players:
8653 s := Find_Param_Value(pars, '-pl');
8654 if (s = '') then
8655 n := DEFAULT_PLAYERS
8656 else
8657 n := StrToIntDef(s, DEFAULT_PLAYERS);
8659 // Start:
8660 s := Find_Param_Value(pars, '-port');
8661 if (s = '') or not TryStrToInt(s, Port) then
8662 g_Game_StartCustom(map, GMode, LimT, LimS, Lives, Opt, n)
8663 else
8664 g_Game_StartServer(map, GMode, LimT, LimS, Lives, Opt, n, 0, Port);
8665 end;
8667 // Execute script when game loads:
8668 s := Find_Param_Value(pars, '-exec');
8669 if s <> '' then
8670 begin
8671 // if not isWadPath(s) then
8672 // s := GameDir + '/' + s;
8674 {$I-}
8675 AssignFile(F, s);
8676 Reset(F);
8677 if IOResult <> 0 then
8678 begin
8679 e_WriteLog(Format(_lc[I_SIMPLE_ERROR], ['Failed to read file: ' + s]), TMsgType.Warning);
8680 g_Console_Add(Format(_lc[I_CONSOLE_ERROR_READ], [s]));
8681 CloseFile(F);
8682 Exit;
8683 end;
8684 e_WriteLog('Executing script: ' + s, TMsgType.Notify);
8685 g_Console_Add(Format(_lc[I_CONSOLE_EXEC], [s]));
8687 while not EOF(F) do
8688 begin
8689 ReadLn(F, s);
8690 if IOResult <> 0 then
8691 begin
8692 e_WriteLog(Format(_lc[I_SIMPLE_ERROR], ['Failed to read file: ' + s]), TMsgType.Warning);
8693 g_Console_Add(Format(_lc[I_CONSOLE_ERROR_READ], [s]));
8694 CloseFile(F);
8695 Exit;
8696 end;
8697 if Pos('#', s) <> 1 then // script comment
8698 g_Console_Process(s, True);
8699 end;
8701 CloseFile(F);
8702 {$I+}
8703 end;
8705 SetLength(pars, 0);
8706 end;
8708 begin
8709 conRegVar('pf_draw_frame', @g_profile_frame_draw, 'draw frame rendering profiles', 'render profiles');
8710 //conRegVar('pf_update_frame', @g_profile_frame_update, 'draw frame updating profiles', 'update profiles');
8711 conRegVar('pf_coldet', @g_profile_collision, 'draw collision detection profiles', 'coldet profiles');
8712 conRegVar('pf_los', @g_profile_los, 'draw monster LOS profiles', 'monster LOS profiles');
8714 conRegVar('r_sq_draw', @gdbg_map_use_accel_render, 'accelerated spatial queries in rendering', 'accelerated rendering');
8715 conRegVar('cd_sq_enabled', @gdbg_map_use_accel_coldet, 'accelerated spatial queries in map coldet', 'accelerated map coldet');
8716 conRegVar('mon_sq_enabled', @gmon_debug_use_sqaccel, 'accelerated spatial queries for monsters', 'accelerated monster coldet');
8717 conRegVar('wtrace_sq_enabled', @gwep_debug_fast_trace, 'accelerated spatial queries for weapon hitscan trace', 'accelerated weapon hitscan');
8719 conRegVar('pr_enabled', @gpart_dbg_enabled, 'enable/disable particles', 'particles');
8720 conRegVar('pr_phys_enabled', @gpart_dbg_phys_enabled, 'enable/disable particle physics', 'particle physics');
8722 conRegVar('los_enabled', @gmon_dbg_los_enabled, 'enable/disable monster LOS calculations', 'monster LOS', true);
8723 conRegVar('mon_think', @gmon_debug_think, 'enable/disable monster thinking', 'monster thinking', true);
8725 {$IFDEF ENABLE_HOLMES}
8726 conRegVar('dbg_holmes', @g_holmes_enabled, 'enable/disable Holmes', 'Holmes', true);
8727 {$ENDIF}
8729 conRegVar('dbg_ignore_level_bounds', @g_dbg_ignore_bounds, 'ignore level bounds', '', false);
8731 conRegVar('r_scale', @g_dbg_scale, 0.01, 100.0, 'render scale', '', false);
8732 conRegVar('r_resolution_scale', @r_pixel_scale, 0.01, 100.0, 'upscale factor', '', false);
8734 conRegVar('light_enabled', @gwin_k8_enable_light_experiments, 'enable/disable dynamic lighting', 'lighting');
8735 conRegVar('light_player_halo', @g_playerLight, 'enable/disable player halo', 'player light halo');
8737 conRegVar('r_smallmap_align_h', @r_smallmap_h, 'halign: 0: left; 1: center; 2: right', 'horizontal aligning of small maps');
8738 conRegVar('r_smallmap_align_v', @r_smallmap_v, 'valign: 0: top; 1: center; 2: bottom', 'vertial aligning of small maps');
8740 conRegVar('r_showfps', @gShowFPS, 'draw fps counter', 'draw fps counter');
8741 conRegVar('r_showtime', @gShowTime, 'show game time', 'show game time');
8742 conRegVar('r_showping', @gShowPing, 'show ping', 'show ping');
8743 conRegVar('r_showscore', @gShowScore, 'show score', 'show score');
8744 conRegVar('r_showkillmsg', @gShowKillMsg, 'show kill log', 'show kill log');
8745 conRegVar('r_showlives', @gShowLives, 'show lives', 'show lives');
8746 conRegVar('r_showspect', @gSpectHUD, 'show spectator hud', 'show spectator hud');
8747 conRegVar('r_showstat', @gShowStat, 'show stats', 'show stats');
8748 conRegVar('r_showpids', @gShowPIDs, 'show PIDs', 'show PIDs');
8749 end.