DEADSOFTWARE

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