DEADSOFTWARE

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