DEADSOFTWARE

net: some Preliminary (but half-working) code for new map/resource download scheme
[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 GoalLimit: Word;
33 WarmupTime: Word;
34 MaxLives: Byte;
35 Options: LongWord;
36 WAD: String;
37 end;
39 TGameEvent = record
40 Name: String;
41 Command: String;
42 end;
44 TDelayedEvent = record
45 Pending: Boolean;
46 Time: LongWord;
47 DEType: Byte;
48 DENum: Integer;
49 DEStr: String;
50 end;
52 TChatSound = record
53 Sound: TPlayableSound;
54 Tags: Array of String;
55 FullWord: Boolean;
56 end;
58 TPlayerSettings = record
59 Name: String;
60 Model: String;
61 Color: TRGB;
62 Team: Byte;
63 end;
65 TMegaWADInfo = record
66 Name: String;
67 Description: String;
68 Author: String;
69 Pic: String;
70 end;
72 THearPoint = record
73 Active: Boolean;
74 Coords: TDFPoint;
75 end;
77 function g_Game_IsNet(): Boolean;
78 function g_Game_IsServer(): Boolean;
79 function g_Game_IsClient(): Boolean;
80 procedure g_Game_Init();
81 procedure g_Game_Free (freeTextures: Boolean=true);
82 procedure g_Game_LoadData();
83 procedure g_Game_FreeData();
84 procedure g_Game_Update();
85 procedure g_Game_Draw();
86 procedure g_Game_Quit();
87 procedure g_Game_SetupScreenSize();
88 procedure g_Game_ChangeResolution(newWidth, newHeight: Word; nowFull, nowMax: Boolean);
89 function g_Game_ModeToText(Mode: Byte): string;
90 function g_Game_TextToMode(Mode: string): Byte;
91 procedure g_Game_ExecuteEvent(Name: String);
92 function g_Game_DelayEvent(DEType: Byte; Time: LongWord; Num: Integer = 0; Str: String = ''): Integer;
93 procedure g_Game_AddPlayer(Team: Byte = TEAM_NONE);
94 procedure g_Game_RemovePlayer();
95 procedure g_Game_Spectate();
96 procedure g_Game_SpectateCenterView();
97 procedure g_Game_StartSingle(Map: String; TwoPlayers: Boolean; nPlayers: Byte);
98 procedure g_Game_StartCustom(Map: String; GameMode: Byte; TimeLimit, GoalLimit: Word; MaxLives: Byte; Options: LongWord; nPlayers: Byte);
99 procedure g_Game_StartServer(Map: String; GameMode: Byte; TimeLimit, GoalLimit: Word; MaxLives: Byte; Options: LongWord; nPlayers: Byte; IPAddr: LongWord; Port: Word);
100 procedure g_Game_StartClient(Addr: String; Port: Word; PW: String);
101 procedure g_Game_Restart();
102 procedure g_Game_RestartLevel();
103 procedure g_Game_RestartRound(NoMapRestart: Boolean = False);
104 procedure g_Game_ClientWAD(NewWAD: String; const WHash: TMD5Digest);
105 procedure g_Game_SaveOptions();
106 function g_Game_StartMap(Map: String; Force: Boolean = False; const oldMapPath: AnsiString=''): Boolean;
107 procedure g_Game_ChangeMap(const MapPath: String);
108 procedure g_Game_ExitLevel(const Map: AnsiString);
109 function g_Game_GetFirstMap(WAD: String): String;
110 function g_Game_GetNextMap(): String;
111 procedure g_Game_NextLevel();
112 procedure g_Game_Pause(Enable: Boolean);
113 procedure g_Game_HolmesPause(Enable: Boolean);
114 procedure g_Game_InGameMenu(Show: Boolean);
115 function g_Game_IsWatchedPlayer(UID: Word): Boolean;
116 function g_Game_IsWatchedTeam(Team: Byte): Boolean;
117 procedure g_Game_Message(Msg: String; Time: Word);
118 procedure g_Game_LoadMapList(FileName: String);
119 procedure g_Game_PauseAllSounds(Enable: Boolean);
120 procedure g_Game_StopAllSounds(all: Boolean);
121 procedure g_Game_UpdateTriggerSounds();
122 function g_Game_GetMegaWADInfo(WAD: String): TMegaWADInfo;
123 procedure g_Game_ChatSound(Text: String; Taunt: Boolean = True);
124 procedure g_Game_Announce_GoodShot(SpawnerUID: Word);
125 procedure g_Game_Announce_KillCombo(Param: Integer);
126 procedure g_Game_Announce_BodyKill(SpawnerUID: Word);
127 procedure g_Game_StartVote(Command, Initiator: string);
128 procedure g_Game_CheckVote;
129 procedure g_TakeScreenShot();
130 procedure g_FatalError(Text: String);
131 procedure g_SimpleError(Text: String);
132 function g_Game_IsTestMap(): Boolean;
133 procedure g_Game_DeleteTestMap();
134 procedure GameCVars(P: SSArray);
135 procedure GameCommands(P: SSArray);
136 procedure GameCheats(P: SSArray);
137 procedure DebugCommands(P: SSArray);
138 procedure g_Game_Process_Params;
139 procedure g_Game_SetLoadingText(Text: String; Max: Integer; reWrite: Boolean);
140 procedure g_Game_StepLoading(Value: Integer = -1);
141 procedure g_Game_ClearLoading();
142 procedure g_Game_SetDebugMode();
143 procedure DrawLoadingStat();
144 procedure DrawMenuBackground(tex: AnsiString);
146 { procedure SetWinPause(Enable: Boolean); }
148 const
149 GAME_TICK = 28;
151 LOADING_SHOW_STEP = 100;
152 LOADING_INTERLINE = 20;
154 GT_NONE = 0;
155 GT_SINGLE = 1;
156 GT_CUSTOM = 2;
157 GT_SERVER = 3;
158 GT_CLIENT = 4;
160 GM_NONE = 0;
161 GM_DM = 1;
162 GM_TDM = 2;
163 GM_CTF = 3;
164 GM_COOP = 4;
165 GM_SINGLE = 5;
167 MESSAGE_DIKEY = WM_USER + 1;
169 EXIT_QUIT = 1;
170 EXIT_SIMPLE = 2;
171 EXIT_RESTART = 3;
172 EXIT_ENDLEVELSINGLE = 4;
173 EXIT_ENDLEVELCUSTOM = 5;
175 GAME_OPTION_RESERVED = 1;
176 GAME_OPTION_TEAMDAMAGE = 2;
177 GAME_OPTION_ALLOWEXIT = 4;
178 GAME_OPTION_WEAPONSTAY = 8;
179 GAME_OPTION_MONSTERS = 16;
180 GAME_OPTION_BOTVSPLAYER = 32;
181 GAME_OPTION_BOTVSMONSTER = 64;
183 STATE_NONE = 0;
184 STATE_MENU = 1;
185 STATE_FOLD = 2;
186 STATE_INTERCUSTOM = 3;
187 STATE_INTERSINGLE = 4;
188 STATE_INTERTEXT = 5;
189 STATE_INTERPIC = 6;
190 STATE_ENDPIC = 7;
191 STATE_SLIST = 8;
193 LMS_RESPAWN_NONE = 0;
194 LMS_RESPAWN_WARMUP = 1;
195 LMS_RESPAWN_FINAL = 2;
197 SPECT_NONE = 0;
198 SPECT_STATS = 1;
199 SPECT_MAPVIEW = 2;
200 SPECT_PLAYERS = 3;
202 DE_GLOBEVENT = 0;
203 DE_BFGHIT = 1;
204 DE_KILLCOMBO = 2;
205 DE_BODYKILL = 3;
207 ANNOUNCE_NONE = 0;
208 ANNOUNCE_ME = 1;
209 ANNOUNCE_MEPLUS = 2;
210 ANNOUNCE_ALL = 3;
212 CONFIG_FILENAME = 'Doom2DF.cfg';
214 TEST_MAP_NAME = '$$$_TEST_$$$';
216 STD_PLAYER_MODEL = 'Doomer';
218 {$IFDEF HEADLESS}
219 DEFAULT_PLAYERS = 0;
220 {$ELSE}
221 DEFAULT_PLAYERS = 1;
222 {$ENDIF}
224 var
225 gStdFont: DWORD;
226 gGameSettings: TGameSettings;
227 gPlayer1Settings: TPlayerSettings;
228 gPlayer2Settings: TPlayerSettings;
229 gGameOn: Boolean;
230 gPlayerScreenSize: TDFPoint;
231 gPlayer1ScreenCoord: TDFPoint;
232 gPlayer2ScreenCoord: TDFPoint;
233 gPlayer1: TPlayer = nil;
234 gPlayer2: TPlayer = nil;
235 gPlayerDrawn: TPlayer = nil;
236 gTime: LongWord;
237 gSwitchGameMode: Byte = GM_DM;
238 gHearPoint1, gHearPoint2: THearPoint;
239 gSoundEffectsDF: Boolean = False;
240 gSoundTriggerTime: Word = 0;
241 gAnnouncer: Byte = ANNOUNCE_NONE;
242 goodsnd: array[0..3] of TPlayableSound;
243 killsnd: array[0..3] of TPlayableSound;
244 hahasnd: array[0..2] of TPlayableSound;
245 sound_get_flag: array[0..1] of TPlayableSound;
246 sound_lost_flag: array[0..1] of TPlayableSound;
247 sound_ret_flag: array[0..1] of TPlayableSound;
248 sound_cap_flag: array[0..1] of TPlayableSound;
249 gBodyKillEvent: Integer = -1;
250 gDefInterTime: ShortInt = -1;
251 gInterEndTime: LongWord = 0;
252 gInterTime: LongWord = 0;
253 gServInterTime: Byte = 0;
254 gGameStartTime: LongWord = 0;
255 gTotalMonsters: Integer = 0;
256 gPauseMain: Boolean = false;
257 gPauseHolmes: Boolean = false;
258 gShowTime: Boolean = False;
259 gShowFPS: Boolean = False;
260 gShowGoals: Boolean = True;
261 gShowStat: Boolean = True;
262 gShowKillMsg: Boolean = True;
263 gShowLives: Boolean = True;
264 gShowPing: Boolean = False;
265 gShowMap: Boolean = False;
266 gExit: Byte = 0;
267 gState: Byte = STATE_NONE;
268 sX, sY: Integer;
269 sWidth, sHeight: Word;
270 gSpectMode: Byte = SPECT_NONE;
271 gSpectHUD: Boolean = True;
272 gSpectKeyPress: Boolean = False;
273 gSpectX: Integer = 0;
274 gSpectY: Integer = 0;
275 gSpectStep: Byte = 8;
276 gSpectViewTwo: Boolean = False;
277 gSpectPID1: Integer = -1;
278 gSpectPID2: Integer = -1;
279 gSpectAuto: Boolean = False;
280 gSpectAutoNext: LongWord;
281 gSpectAutoStepX: Integer;
282 gSpectAutoStepY: Integer;
283 gMusic: TMusic = nil;
284 gLoadGameMode: Boolean;
285 gCheats: Boolean = False;
286 gMapOnce: Boolean = False;
287 gMapToDelete: String;
288 gTempDelete: Boolean = False;
289 gLastMap: Boolean = False;
290 gWinPosX, gWinPosY: Integer;
291 gWinSizeX, gWinSizeY: Integer;
292 gWinFrameX, gWinFrameY, gWinCaption: Integer;
293 gWinActive: Boolean = True; // by default window is active, lol
294 gResolutionChange: Boolean = False;
295 gRC_Width, gRC_Height: Word;
296 gRC_FullScreen, gRC_Maximized: Boolean;
297 gLanguageChange: Boolean = False;
298 gDebugMode: Boolean = False;
299 g_debug_Sounds: Boolean = False;
300 g_debug_Frames: Boolean = False;
301 g_debug_WinMsgs: Boolean = False;
302 g_debug_MonsterOff: Boolean = False;
303 g_debug_BotAIOff: Byte = 0;
304 g_debug_HealthBar: Boolean = False;
305 g_Debug_Player: Boolean = False;
306 gCoopMonstersKilled: Word = 0;
307 gCoopSecretsFound: Word = 0;
308 gCoopTotalMonstersKilled: Word = 0;
309 gCoopTotalSecretsFound: Word = 0;
310 gCoopTotalMonsters: Word = 0;
311 gCoopTotalSecrets: Word = 0;
312 gStatsOff: Boolean = False;
313 gStatsPressed: Boolean = False;
314 gExitByTrigger: Boolean = False;
315 gNextMap: String = '';
316 gLMSRespawn: Byte = LMS_RESPAWN_NONE;
317 gLMSRespawnTime: Cardinal = 0;
318 gLMSSoftSpawn: Boolean = False;
319 gMissionFailed: Boolean = False;
320 gVoteInProgress: Boolean = False;
321 gVotePassed: Boolean = False;
322 gVoteCommand: string = '';
323 gVoteTimer: Cardinal = 0;
324 gVoteCmdTimer: Cardinal = 0;
325 gVoteCount: Integer = 0;
326 gVoteTimeout: Cardinal = 30;
327 gVoted: Boolean = False;
328 gVotesEnabled: Boolean = True;
329 gEvents: Array of TGameEvent;
330 gDelayedEvents: Array of TDelayedEvent;
331 gUseChatSounds: Boolean = True;
332 gChatSounds: Array of TChatSound;
333 gSelectWeapon: Array [0..1, WP_FIRST..WP_LAST] of Boolean; // [player, weapon]
334 gInterReadyCount: Integer = 0;
336 g_dbg_ignore_bounds: Boolean = false;
337 r_smallmap_h: Integer = 0; // 0: left; 1: center; 2: right
338 r_smallmap_v: Integer = 2; // 0: top; 1: center; 2: bottom
340 // move button values:
341 // bits 0-1: l/r state:
342 // 0: neither left, nor right pressed
343 // 1: left pressed
344 // 2: right pressed
345 // bits 4-5: l/r state when strafe was pressed
346 P1MoveButton: Byte = 0;
347 P2MoveButton: Byte = 0;
349 g_profile_frame_update: Boolean = false;
350 g_profile_frame_draw: Boolean = false;
351 g_profile_collision: Boolean = false;
352 g_profile_los: Boolean = false;
353 g_profile_history_size: Integer = 1000;
355 g_rlayer_back: Boolean = true;
356 g_rlayer_step: Boolean = true;
357 g_rlayer_wall: Boolean = true;
358 g_rlayer_door: Boolean = true;
359 g_rlayer_acid1: Boolean = true;
360 g_rlayer_acid2: Boolean = true;
361 g_rlayer_water: Boolean = true;
362 g_rlayer_fore: Boolean = true;
365 procedure g_ResetDynlights ();
366 procedure g_AddDynLight (x, y, radius: Integer; r, g, b, a: Single);
367 procedure g_DynLightExplosion (x, y, radius: Integer; r, g, b: Single);
369 function conIsCheatsEnabled (): Boolean; inline;
370 function gPause (): Boolean; inline;
373 implementation
375 uses
376 {$INCLUDE ../nogl/noGLuses.inc}
377 {$IFDEF ENABLE_HOLMES}
378 g_holmes,
379 {$ENDIF}
380 e_texture, g_textures, g_main, g_window, g_menu,
381 e_input, e_log, g_console, g_items, g_map, g_panel,
382 g_playermodel, g_gfx, g_options, Math,
383 g_triggers, g_monsters, e_sound, CONFIG,
384 g_language, g_net,
385 ENet, e_msg, g_netmsg, g_netmaster,
386 sfs, wadreader;
389 var
390 hasPBarGfx: Boolean = false;
393 // ////////////////////////////////////////////////////////////////////////// //
394 function gPause (): Boolean; inline; begin result := gPauseMain or gPauseHolmes; end;
397 // ////////////////////////////////////////////////////////////////////////// //
398 function conIsCheatsEnabled (): Boolean; inline;
399 begin
400 result := false;
401 if g_Game_IsNet then exit;
402 if not gDebugMode then
403 begin
404 //if not gCheats then exit;
405 if not (gGameSettings.GameType in [GT_SINGLE, GT_CUSTOM]) then exit;
406 if not (gGameSettings.GameMode in [GM_COOP, GM_SINGLE]) then exit;
407 end;
408 result := true;
409 end;
412 // ////////////////////////////////////////////////////////////////////////// //
413 var
414 profileFrameDraw: TProfiler = nil;
417 // ////////////////////////////////////////////////////////////////////////// //
418 type
419 TDynLight = record
420 x, y, radius: Integer;
421 r, g, b, a: Single;
422 exploCount: Integer;
423 exploRadius: Integer;
424 end;
426 var
427 g_dynLights: array of TDynLight = nil;
428 g_dynLightCount: Integer = 0;
429 g_playerLight: Boolean = false;
431 procedure g_ResetDynlights ();
432 var
433 lnum, idx: Integer;
434 begin
435 if not gwin_has_stencil then begin g_dynLightCount := 0; exit; end;
436 lnum := 0;
437 for idx := 0 to g_dynLightCount-1 do
438 begin
439 if g_dynLights[idx].exploCount = -666 then
440 begin
441 // skip it
442 end
443 else
444 begin
445 // explosion
446 Inc(g_dynLights[idx].exploCount);
447 if (g_dynLights[idx].exploCount < 10) then
448 begin
449 g_dynLights[idx].radius := g_dynLights[idx].exploRadius+g_dynLights[idx].exploCount*8;
450 g_dynLights[idx].a := 0.4+g_dynLights[idx].exploCount/10;
451 if (g_dynLights[idx].a > 0.8) then g_dynLights[idx].a := 0.8;
452 if lnum <> idx then g_dynLights[lnum] := g_dynLights[idx];
453 Inc(lnum);
454 end;
455 end;
456 end;
457 g_dynLightCount := lnum;
458 end;
460 procedure g_AddDynLight (x, y, radius: Integer; r, g, b, a: Single);
461 begin
462 if not gwin_has_stencil then exit;
463 if g_dynLightCount = length(g_dynLights) then SetLength(g_dynLights, g_dynLightCount+1024);
464 g_dynLights[g_dynLightCount].x := x;
465 g_dynLights[g_dynLightCount].y := y;
466 g_dynLights[g_dynLightCount].radius := radius;
467 g_dynLights[g_dynLightCount].r := r;
468 g_dynLights[g_dynLightCount].g := g;
469 g_dynLights[g_dynLightCount].b := b;
470 g_dynLights[g_dynLightCount].a := a;
471 g_dynLights[g_dynLightCount].exploCount := -666;
472 Inc(g_dynLightCount);
473 end;
475 procedure g_DynLightExplosion (x, y, radius: Integer; r, g, b: Single);
476 begin
477 if not gwin_has_stencil then exit;
478 if g_dynLightCount = length(g_dynLights) then SetLength(g_dynLights, g_dynLightCount+1024);
479 g_dynLights[g_dynLightCount].x := x;
480 g_dynLights[g_dynLightCount].y := y;
481 g_dynLights[g_dynLightCount].radius := 0;
482 g_dynLights[g_dynLightCount].exploRadius := radius;
483 g_dynLights[g_dynLightCount].r := r;
484 g_dynLights[g_dynLightCount].g := g;
485 g_dynLights[g_dynLightCount].b := b;
486 g_dynLights[g_dynLightCount].a := 0;
487 g_dynLights[g_dynLightCount].exploCount := 0;
488 Inc(g_dynLightCount);
489 end;
492 // ////////////////////////////////////////////////////////////////////////// //
493 function calcProfilesHeight (prof: TProfiler): Integer;
494 begin
495 result := 0;
496 if (prof = nil) then exit;
497 if (length(prof.bars) = 0) then exit;
498 result := length(prof.bars)*(16+2);
499 end;
501 // returns width
502 function drawProfiles (x, y: Integer; prof: TProfiler): Integer;
503 var
504 wdt, hgt: Integer;
505 yy: Integer;
506 ii: Integer;
507 begin
508 result := 0;
509 if (prof = nil) then exit;
510 // gScreenWidth
511 if (length(prof.bars) = 0) then exit;
512 wdt := 192;
513 hgt := calcProfilesHeight(prof);
514 if (x < 0) then x := gScreenWidth-(wdt-1)+x;
515 if (y < 0) then y := gScreenHeight-(hgt-1)+y;
516 // background
517 //e_DrawFillQuad(x, y, x+wdt-1, y+hgt-1, 255, 255, 255, 200, B_BLEND);
518 //e_DrawFillQuad(x, y, x+wdt-1, y+hgt-1, 20, 20, 20, 0, B_NONE);
519 e_DarkenQuadWH(x, y, wdt, hgt, 150);
520 // title
521 yy := y+2;
522 for ii := 0 to High(prof.bars) do
523 begin
524 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);
525 Inc(yy, 16+2);
526 end;
527 result := wdt;
528 end;
531 // ////////////////////////////////////////////////////////////////////////// //
532 type
533 TEndCustomGameStat = record
534 PlayerStat: TPlayerStatArray;
535 TeamStat: TTeamStat;
536 GameTime: LongWord;
537 GameMode: Byte;
538 Map, MapName: String;
539 end;
541 TEndSingleGameStat = record
542 PlayerStat: Array [0..1] of record
543 Kills: Integer;
544 Secrets: Integer;
545 end;
546 GameTime: LongWord;
547 TwoPlayers: Boolean;
548 TotalSecrets: Integer;
549 end;
551 TLoadingStat = record
552 CurValue: Integer;
553 MaxValue: Integer;
554 ShowCount: Integer;
555 Msgs: Array of String;
556 NextMsg: Word;
557 PBarWasHere: Boolean; // did we draw a progress bar for this message?
558 end;
560 TParamStrValue = record
561 Name: String;
562 Value: String;
563 end;
565 TParamStrValues = Array of TParamStrValue;
567 const
568 INTER_ACTION_TEXT = 1;
569 INTER_ACTION_PIC = 2;
570 INTER_ACTION_MUSIC = 3;
572 var
573 FPS, UPS: Word;
574 FPSCounter, UPSCounter: Word;
575 FPSTime, UPSTime: LongWord;
576 DataLoaded: Boolean = False;
577 IsDrawStat: Boolean = False;
578 CustomStat: TEndCustomGameStat;
579 SingleStat: TEndSingleGameStat;
580 LoadingStat: TLoadingStat;
581 EndingGameCounter: Byte = 0;
582 MessageText: String;
583 MessageTime: Word;
584 MessageLineLength: Integer = 80;
585 MapList: SSArray = nil;
586 MapIndex: Integer = -1;
587 InterReadyTime: Integer = -1;
588 MegaWAD: record
589 info: TMegaWADInfo;
590 endpic: String;
591 endmus: String;
592 res: record
593 text: Array of ShortString;
594 anim: Array of ShortString;
595 pic: Array of ShortString;
596 mus: Array of ShortString;
597 end;
598 triggers: Array of record
599 event: ShortString;
600 actions: Array of record
601 action, p1, p2: Integer;
602 end;
603 end;
604 cur_trigger: Integer;
605 cur_action: Integer;
606 end;
607 //InterPic: String;
608 InterText: record
609 lines: SSArray;
610 img: String;
611 cur_line: Integer;
612 cur_char: Integer;
613 counter: Integer;
614 endtext: Boolean;
615 end;
617 function Compare(a, b: TPlayerStat): Integer;
618 begin
619 if a.Spectator then Result := 1
620 else if b.Spectator then Result := -1
621 else if a.Frags < b.Frags then Result := 1
622 else if a.Frags > b.Frags then Result := -1
623 else if a.Deaths < b.Deaths then Result := -1
624 else if a.Deaths > b.Deaths then Result := 1
625 else if a.Kills < b.Kills then Result := -1
626 else Result := 1;
627 end;
629 procedure SortGameStat(var stat: TPlayerStatArray);
630 var
631 I, J: Integer;
632 T: TPlayerStat;
633 begin
634 if stat = nil then Exit;
636 for I := High(stat) downto Low(stat) do
637 for J := Low(stat) to High(stat) - 1 do
638 if Compare(stat[J], stat[J + 1]) = 1 then
639 begin
640 T := stat[J];
641 stat[J] := stat[J + 1];
642 stat[J + 1] := T;
643 end;
644 end;
646 function g_Game_ModeToText(Mode: Byte): string;
647 begin
648 Result := '';
649 case Mode of
650 GM_DM: Result := _lc[I_MENU_GAME_TYPE_DM];
651 GM_TDM: Result := _lc[I_MENU_GAME_TYPE_TDM];
652 GM_CTF: Result := _lc[I_MENU_GAME_TYPE_CTF];
653 GM_COOP: Result := _lc[I_MENU_GAME_TYPE_COOP];
654 GM_SINGLE: Result := _lc[I_MENU_GAME_TYPE_SINGLE];
655 end;
656 end;
658 function g_Game_TextToMode(Mode: string): Byte;
659 begin
660 Result := GM_NONE;
661 Mode := UpperCase(Mode);
662 if Mode = _lc[I_MENU_GAME_TYPE_DM] then
663 begin
664 Result := GM_DM;
665 Exit;
666 end;
667 if Mode = _lc[I_MENU_GAME_TYPE_TDM] then
668 begin
669 Result := GM_TDM;
670 Exit;
671 end;
672 if Mode = _lc[I_MENU_GAME_TYPE_CTF] then
673 begin
674 Result := GM_CTF;
675 Exit;
676 end;
677 if Mode = _lc[I_MENU_GAME_TYPE_COOP] then
678 begin
679 Result := GM_COOP;
680 Exit;
681 end;
682 if Mode = _lc[I_MENU_GAME_TYPE_SINGLE] then
683 begin
684 Result := GM_SINGLE;
685 Exit;
686 end;
687 end;
689 function g_Game_IsNet(): Boolean;
690 begin
691 Result := (gGameSettings.GameType in [GT_SERVER, GT_CLIENT]);
692 end;
694 function g_Game_IsServer(): Boolean;
695 begin
696 Result := (gGameSettings.GameType in [GT_SINGLE, GT_CUSTOM, GT_SERVER]);
697 end;
699 function g_Game_IsClient(): Boolean;
700 begin
701 Result := (gGameSettings.GameType = GT_CLIENT);
702 end;
704 function g_Game_GetMegaWADInfo(WAD: String): TMegaWADInfo;
705 var
706 w: TWADFile;
707 cfg: TConfig;
708 p: Pointer;
709 len: Integer;
710 begin
711 Result.name := ExtractFileName(WAD);
712 Result.description := '';
713 Result.author := '';
715 w := TWADFile.Create();
716 w.ReadFile(WAD);
718 if not w.GetResource('INTERSCRIPT', p, len) then
719 begin
720 w.Free();
721 Exit;
722 end;
724 cfg := TConfig.CreateMem(p, len);
725 Result.name := cfg.ReadStr('megawad', 'name', ExtractFileName(WAD));
726 Result.description := cfg.ReadStr('megawad', 'description', '');
727 Result.author := cfg.ReadStr('megawad', 'author', '');
728 Result.pic := cfg.ReadStr('megawad', 'pic', '');
729 cfg.Free();
731 FreeMem(p);
732 end;
734 procedure g_Game_FreeWAD();
735 var
736 a: Integer;
737 begin
738 for a := 0 to High(MegaWAD.res.pic) do
739 if MegaWAD.res.pic[a] <> '' then
740 g_Texture_Delete(MegaWAD.res.pic[a]);
742 for a := 0 to High(MegaWAD.res.mus) do
743 if MegaWAD.res.mus[a] <> '' then
744 g_Sound_Delete(MegaWAD.res.mus[a]);
746 MegaWAD.res.pic := nil;
747 MegaWAD.res.text := nil;
748 MegaWAD.res.anim := nil;
749 MegaWAD.res.mus := nil;
750 MegaWAD.triggers := nil;
752 g_Texture_Delete('TEXTURE_endpic');
753 g_Sound_Delete('MUSIC_endmus');
755 ZeroMemory(@MegaWAD, SizeOf(MegaWAD));
756 gGameSettings.WAD := '';
757 end;
759 procedure g_Game_LoadWAD(WAD: string);
760 var
761 w: TWADFile;
762 cfg: TConfig;
763 p: Pointer;
764 {b, }len: Integer;
765 s: string;
766 begin
767 g_Game_FreeWAD();
768 gGameSettings.WAD := WAD;
769 if not (gGameSettings.GameMode in [GM_COOP, GM_SINGLE]) then
770 Exit;
772 MegaWAD.info := g_Game_GetMegaWADInfo(MapsDir + WAD);
774 w := TWADFile.Create();
775 w.ReadFile(MapsDir + WAD);
777 if not w.GetResource('INTERSCRIPT', p, len) then
778 begin
779 w.Free();
780 Exit;
781 end;
783 cfg := TConfig.CreateMem(p, len);
785 {b := 1;
786 while True do
787 begin
788 s := cfg.ReadStr('pic', 'pic'+IntToStr(b), '');
789 if s = '' then Break;
790 b := b+1;
792 SetLength(MegaWAD.res.pic, Length(MegaWAD.res.pic)+1);
793 MegaWAD.res.pic[High(MegaWAD.res.pic)] := s;
795 g_Texture_CreateWADEx(s, s);
796 end;
798 b := 1;
799 while True do
800 begin
801 s := cfg.ReadStr('mus', 'mus'+IntToStr(b), '');
802 if s = '' then Break;
803 b := b+1;
805 SetLength(MegaWAD.res.mus, Length(MegaWAD.res.mus)+1);
806 MegaWAD.res.mus[High(MegaWAD.res.mus)] := s;
808 g_Music_CreateWADEx(s, s);
809 end;}
811 MegaWAD.endpic := cfg.ReadStr('megawad', 'endpic', '');
812 if MegaWAD.endpic <> '' then
813 begin
814 s := g_ExtractWadName(MegaWAD.endpic);
815 if s = '' then s := MapsDir+WAD else s := GameDir+'/wads/';
816 TEXTUREFILTER := GL_LINEAR;
817 g_Texture_CreateWADEx('TEXTURE_endpic', s+MegaWAD.endpic);
818 TEXTUREFILTER := GL_NEAREST;
819 end;
820 MegaWAD.endmus := cfg.ReadStr('megawad', 'endmus', 'Standart.wad:D2DMUS\ÊÎÍÅÖ');
821 if MegaWAD.endmus <> '' then
822 begin
823 s := g_ExtractWadName(MegaWAD.endmus);
824 if s = '' then s := MapsDir+WAD else s := GameDir+'/wads/';
825 g_Sound_CreateWADEx('MUSIC_endmus', s+MegaWAD.endmus, True);
826 end;
828 cfg.Free();
829 FreeMem(p);
830 w.Free();
831 end;
833 {procedure start_trigger(t: string);
834 begin
835 end;
837 function next_trigger(): Boolean;
838 begin
839 end;}
841 procedure DisableCheats();
842 begin
843 MAX_RUNVEL := 8;
844 VEL_JUMP := 10;
845 gFly := False;
847 if gPlayer1 <> nil then gPlayer1.GodMode := False;
848 if gPlayer2 <> nil then gPlayer2.GodMode := False;
849 if gPlayer1 <> nil then gPlayer1.NoTarget := False;
850 if gPlayer2 <> nil then gPlayer2.NoTarget := False;
852 {$IF DEFINED(D2F_DEBUG)}
853 if gPlayer1 <> nil then gPlayer1.NoTarget := True;
854 gAimLine := g_dbg_aimline_on;
855 {$ENDIF}
856 end;
858 procedure g_Game_ExecuteEvent(Name: String);
859 var
860 a: Integer;
861 begin
862 if Name = '' then
863 Exit;
864 if gEvents = nil then
865 Exit;
866 for a := 0 to High(gEvents) do
867 if gEvents[a].Name = Name then
868 begin
869 if gEvents[a].Command <> '' then
870 g_Console_Process(gEvents[a].Command, True);
871 break;
872 end;
873 end;
875 function g_Game_DelayEvent(DEType: Byte; Time: LongWord; Num: Integer = 0; Str: String = ''): Integer;
876 var
877 a, n: Integer;
878 begin
879 n := -1;
880 if gDelayedEvents <> nil then
881 for a := 0 to High(gDelayedEvents) do
882 if not gDelayedEvents[a].Pending then
883 begin
884 n := a;
885 break;
886 end;
887 if n = -1 then
888 begin
889 SetLength(gDelayedEvents, Length(gDelayedEvents) + 1);
890 n := High(gDelayedEvents);
891 end;
892 gDelayedEvents[n].Pending := True;
893 gDelayedEvents[n].DEType := DEType;
894 gDelayedEvents[n].DENum := Num;
895 gDelayedEvents[n].DEStr := Str;
896 if DEType = DE_GLOBEVENT then
897 gDelayedEvents[n].Time := (GetTimer() {div 1000}) + Time
898 else
899 gDelayedEvents[n].Time := gTime + Time;
900 Result := n;
901 end;
903 procedure EndGame();
904 var
905 a: Integer;
906 FileName: string;
907 begin
908 if g_Game_IsNet and g_Game_IsServer then
909 MH_SEND_GameEvent(NET_EV_MAPEND, Byte(gMissionFailed));
911 // Ñòîï èãðà:
912 gPauseMain := false;
913 gPauseHolmes := false;
914 gGameOn := false;
916 g_Game_StopAllSounds(False);
918 MessageTime := 0;
919 MessageText := '';
921 EndingGameCounter := 0;
922 g_ActiveWindow := nil;
924 gLMSRespawn := LMS_RESPAWN_NONE;
925 gLMSRespawnTime := 0;
927 case gExit of
928 EXIT_SIMPLE: // Âûõîä ÷åðåç ìåíþ èëè êîíåö òåñòà
929 begin
930 g_Game_Free();
932 if gMapOnce then
933 begin // Ýòî áûë òåñò
934 g_Game_Quit();
935 end
936 else
937 begin // Âûõîä â ãëàâíîå ìåíþ
938 gMusic.SetByName('MUSIC_MENU');
939 gMusic.Play();
940 if gState <> STATE_SLIST then
941 begin
942 g_GUI_ShowWindow('MainMenu');
943 gState := STATE_MENU;
944 end else
945 begin
946 // Îáíîâëÿåì ñïèñîê ñåðâåðîâ
947 slReturnPressed := True;
948 if g_Net_Slist_Fetch(slCurrent) then
949 begin
950 if slCurrent = nil then
951 slWaitStr := _lc[I_NET_SLIST_NOSERVERS];
952 end
953 else
954 slWaitStr := _lc[I_NET_SLIST_ERROR];
955 g_Serverlist_GenerateTable(slCurrent, slTable);
956 end;
958 g_Game_ExecuteEvent('ongameend');
959 end;
960 end;
962 EXIT_RESTART: // Íà÷àòü óðîâåíü ñíà÷àëà
963 begin
964 if not g_Game_IsClient then g_Game_Restart();
965 end;
967 EXIT_ENDLEVELCUSTOM: // Çàêîí÷èëñÿ óðîâåíü â Ñâîåé èãðå
968 begin
969 // Ñòàòèñòèêà Ñâîåé èãðû:
970 FileName := g_ExtractWadName(gMapInfo.Map);
972 CustomStat.GameTime := gTime;
973 CustomStat.Map := ExtractFileName(FileName)+':'+g_ExtractFileName(gMapInfo.Map); //ResName;
974 CustomStat.MapName := gMapInfo.Name;
975 CustomStat.GameMode := gGameSettings.GameMode;
976 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
977 CustomStat.TeamStat := gTeamStat;
979 CustomStat.PlayerStat := nil;
981 // Ñòàòèñòèêà èãðîêîâ:
982 if gPlayers <> nil then
983 begin
984 for a := 0 to High(gPlayers) do
985 if gPlayers[a] <> nil then
986 begin
987 SetLength(CustomStat.PlayerStat, Length(CustomStat.PlayerStat)+1);
988 with CustomStat.PlayerStat[High(CustomStat.PlayerStat)] do
989 begin
990 Num := a;
991 Name := gPlayers[a].Name;
992 Frags := gPlayers[a].Frags;
993 Deaths := gPlayers[a].Death;
994 Kills := gPlayers[a].Kills;
995 Team := gPlayers[a].Team;
996 Color := gPlayers[a].Model.Color;
997 Spectator := gPlayers[a].FSpectator;
998 end;
999 end;
1001 SortGameStat(CustomStat.PlayerStat);
1002 end;
1004 g_Game_ExecuteEvent('onmapend');
1005 if not g_Game_IsClient then g_Player_ResetReady;
1006 gInterReadyCount := 0;
1008 // Çàòóõàþùèé ýêðàí:
1009 EndingGameCounter := 255;
1010 gState := STATE_FOLD;
1011 gInterTime := 0;
1012 if gDefInterTime < 0 then
1013 gInterEndTime := IfThen((gGameSettings.GameType = GT_SERVER) and (gPlayer1 = nil), 15000, 25000)
1014 else
1015 gInterEndTime := gDefInterTime * 1000;
1016 end;
1018 EXIT_ENDLEVELSINGLE: // Çàêîí÷èëñÿ óðîâåíü â Îäèíî÷íîé èãðå
1019 begin
1020 // Ñòàòèñòèêà Îäèíî÷íîé èãðû:
1021 SingleStat.GameTime := gTime;
1022 SingleStat.TwoPlayers := gPlayer2 <> nil;
1023 SingleStat.TotalSecrets := gSecretsCount;
1024 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
1025 SingleStat.PlayerStat[0].Kills := gPlayer1.MonsterKills;
1026 SingleStat.PlayerStat[0].Secrets := gPlayer1.Secrets;
1027 // Ñòàòèñòèêà âòîðîãî èãðîêà (åñëè åñòü):
1028 if SingleStat.TwoPlayers then
1029 begin
1030 SingleStat.PlayerStat[1].Kills := gPlayer2.MonsterKills;
1031 SingleStat.PlayerStat[1].Secrets := gPlayer2.Secrets;
1032 end;
1034 g_Game_ExecuteEvent('onmapend');
1036 // Åñòü åùå êàðòû:
1037 if gNextMap <> '' then
1038 begin
1039 gMusic.SetByName('MUSIC_INTERMUS');
1040 gMusic.Play();
1041 gState := STATE_INTERSINGLE;
1042 e_UnpressAllKeys();
1044 g_Game_ExecuteEvent('oninter');
1045 end
1046 else // Áîëüøå íåò êàðò
1047 begin
1048 // Çàòóõàþùèé ýêðàí:
1049 EndingGameCounter := 255;
1050 gState := STATE_FOLD;
1051 end;
1052 end;
1053 end;
1055 // Îêîí÷àíèå îáðàáîòàíî:
1056 if gExit <> EXIT_QUIT then
1057 gExit := 0;
1058 end;
1060 procedure drawTime(X, Y: Integer); inline;
1061 begin
1062 e_TextureFontPrint(x, y,
1063 Format('%d:%.2d:%.2d', [
1064 gTime div 1000 div 3600,
1065 (gTime div 1000 div 60) mod 60,
1066 gTime div 1000 mod 60
1067 ]),
1068 gStdFont);
1069 end;
1071 procedure DrawStat();
1072 var
1073 pc, x, y, w, h: Integer;
1074 w1, w2, w3, w4: Integer;
1075 a, aa: Integer;
1076 cw, ch, r, g, b, rr, gg, bb: Byte;
1077 s1, s2, s3: String;
1078 _y: Integer;
1079 stat: TPlayerStatArray;
1080 wad, map: string;
1081 mapstr: string;
1082 begin
1083 s1 := '';
1084 s2 := '';
1085 s3 := '';
1086 pc := g_Player_GetCount;
1087 e_TextureFontGetSize(gStdFont, cw, ch);
1089 w := gScreenWidth-(gScreenWidth div 5);
1090 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
1091 h := 32+ch*(11+pc)
1092 else
1093 h := 40+ch*5+(ch+8)*pc;
1094 x := (gScreenWidth div 2)-(w div 2);
1095 y := (gScreenHeight div 2)-(h div 2);
1097 e_DrawFillQuad(x, y, x+w-1, y+h-1, 64, 64, 64, 32);
1098 e_DrawQuad(x, y, x+w-1, y+h-1, 255, 127, 0);
1100 drawTime(x+w-78, y+8);
1102 wad := g_ExtractWadNameNoPath(gMapInfo.Map);
1103 map := g_ExtractFileName(gMapInfo.Map);
1104 mapstr := wad + ':\' + map + ' - ' + gMapInfo.Name;
1106 case gGameSettings.GameMode of
1107 GM_DM:
1108 begin
1109 if gGameSettings.MaxLives = 0 then
1110 s1 := _lc[I_GAME_DM]
1111 else
1112 s1 := _lc[I_GAME_LMS];
1113 s2 := Format(_lc[I_GAME_FRAG_LIMIT], [gGameSettings.GoalLimit]);
1114 s3 := Format(_lc[I_GAME_TIME_LIMIT], [gGameSettings.TimeLimit div 3600, (gGameSettings.TimeLimit div 60) mod 60, gGameSettings.TimeLimit mod 60]);
1115 end;
1117 GM_TDM:
1118 begin
1119 if gGameSettings.MaxLives = 0 then
1120 s1 := _lc[I_GAME_TDM]
1121 else
1122 s1 := _lc[I_GAME_TLMS];
1123 s2 := Format(_lc[I_GAME_FRAG_LIMIT], [gGameSettings.GoalLimit]);
1124 s3 := Format(_lc[I_GAME_TIME_LIMIT], [gGameSettings.TimeLimit div 3600, (gGameSettings.TimeLimit div 60) mod 60, gGameSettings.TimeLimit mod 60]);
1125 end;
1127 GM_CTF:
1128 begin
1129 s1 := _lc[I_GAME_CTF];
1130 s2 := Format(_lc[I_GAME_SCORE_LIMIT], [gGameSettings.GoalLimit]);
1131 s3 := Format(_lc[I_GAME_TIME_LIMIT], [gGameSettings.TimeLimit div 3600, (gGameSettings.TimeLimit div 60) mod 60, gGameSettings.TimeLimit mod 60]);
1132 end;
1134 GM_COOP:
1135 begin
1136 if gGameSettings.MaxLives = 0 then
1137 s1 := _lc[I_GAME_COOP]
1138 else
1139 s1 := _lc[I_GAME_SURV];
1140 s2 := _lc[I_GAME_MONSTERS] + ' ' + IntToStr(gCoopMonstersKilled) + '/' + IntToStr(gTotalMonsters);
1141 s3 := _lc[I_GAME_SECRETS] + ' ' + IntToStr(gCoopSecretsFound) + '/' + IntToStr(gSecretsCount);
1142 end;
1144 else
1145 begin
1146 s1 := '';
1147 s2 := '';
1148 end;
1149 end;
1151 _y := y+8;
1152 e_TextureFontPrintEx(x+(w div 2)-(Length(s1)*cw div 2), _y, s1, gStdFont, 255, 255, 255, 1);
1153 _y := _y+ch+8;
1154 e_TextureFontPrintEx(x+(w div 2)-(Length(mapstr)*cw div 2), _y, mapstr, gStdFont, 200, 200, 200, 1);
1155 _y := _y+ch+8;
1156 e_TextureFontPrintEx(x+16, _y, s2, gStdFont, 200, 200, 200, 1);
1158 e_TextureFontPrintEx(x+w-16-(Length(s3))*cw, _y, s3,
1159 gStdFont, 200, 200, 200, 1);
1161 if NetMode = NET_SERVER then
1162 e_TextureFontPrintEx(x+8, y + 8, _lc[I_NET_SERVER], gStdFont, 255, 255, 255, 1)
1163 else
1164 if NetMode = NET_CLIENT then
1165 e_TextureFontPrintEx(x+8, y + 8,
1166 NetClientIP + ':' + IntToStr(NetClientPort), gStdFont, 255, 255, 255, 1);
1168 if pc = 0 then
1169 Exit;
1170 stat := g_Player_GetStats();
1171 SortGameStat(stat);
1173 w2 := (w-16) div 6 + 48; // øèðèíà 2 ñòîëáöà
1174 w3 := (w-16) div 6; // øèðèíà 3 è 4 ñòîëáöîâ
1175 w4 := w3;
1176 w1 := w-16-w2-w3-w4; // îñòàâøååñÿ ïðîñòðàíñòâî - äëÿ öâåòà è èìåíè èãðîêà
1178 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
1179 begin
1180 _y := _y+ch+ch;
1182 for a := TEAM_RED to TEAM_BLUE do
1183 begin
1184 if a = TEAM_RED then
1185 begin
1186 s1 := _lc[I_GAME_TEAM_RED];
1187 r := 255;
1188 g := 0;
1189 b := 0;
1190 end
1191 else
1192 begin
1193 s1 := _lc[I_GAME_TEAM_BLUE];
1194 r := 0;
1195 g := 0;
1196 b := 255;
1197 end;
1199 e_TextureFontPrintEx(x+16, _y, s1, gStdFont, r, g, b, 1);
1200 e_TextureFontPrintEx(x+w1+16, _y, IntToStr(gTeamStat[a].Goals),
1201 gStdFont, r, g, b, 1);
1203 _y := _y+ch+(ch div 4);
1204 e_DrawLine(1, x+16, _y, x+w-16, _y, r, g, b);
1205 _y := _y+(ch div 4);
1207 for aa := 0 to High(stat) do
1208 if stat[aa].Team = a then
1209 with stat[aa] do
1210 begin
1211 if Spectator then
1212 begin
1213 rr := r div 2;
1214 gg := g div 2;
1215 bb := b div 2;
1216 end
1217 else
1218 begin
1219 rr := r;
1220 gg := g;
1221 bb := b;
1222 end;
1223 // Èìÿ
1224 e_TextureFontPrintEx(x+16, _y, Name, gStdFont, rr, gg, bb, 1);
1225 // Ïèíã/ïîòåðè
1226 e_TextureFontPrintEx(x+w1+16, _y, Format(_lc[I_GAME_PING_MS], [Ping, Loss]), gStdFont, rr, gg, bb, 1);
1227 // Ôðàãè
1228 e_TextureFontPrintEx(x+w1+w2+16, _y, IntToStr(Frags), gStdFont, rr, gg, bb, 1);
1229 // Ñìåðòè
1230 e_TextureFontPrintEx(x+w1+w2+w3+16, _y, IntToStr(Deaths), gStdFont, rr, gg, bb, 1);
1231 _y := _y+ch;
1232 end;
1234 _y := _y+ch;
1235 end;
1236 end
1237 else if gGameSettings.GameMode in [GM_DM, GM_COOP] then
1238 begin
1239 _y := _y+ch+ch;
1240 e_TextureFontPrintEx(x+16, _y, _lc[I_GAME_PLAYER_NAME], gStdFont, 255, 127, 0, 1);
1241 e_TextureFontPrintEx(x+16+w1, _y, _lc[I_GAME_PING], gStdFont, 255, 127, 0, 1);
1242 e_TextureFontPrintEx(x+16+w1+w2, _y, _lc[I_GAME_FRAGS], gStdFont, 255, 127, 0, 1);
1243 e_TextureFontPrintEx(x+16+w1+w2+w3, _y, _lc[I_GAME_DEATHS], gStdFont, 255, 127, 0, 1);
1245 _y := _y+ch+8;
1246 for aa := 0 to High(stat) do
1247 with stat[aa] do
1248 begin
1249 if Spectator then
1250 begin
1251 r := 127;
1252 g := 64;
1253 end
1254 else
1255 begin
1256 r := 255;
1257 g := 127;
1258 end;
1259 // Öâåò èãðîêà
1260 e_DrawFillQuad(x+16, _y+4, x+32-1, _y+16+4-1, Color.R, Color.G, Color.B, 0);
1261 e_DrawQuad(x+16, _y+4, x+32-1, _y+16+4-1, 192, 192, 192);
1262 // Èìÿ
1263 e_TextureFontPrintEx(x+16+16+8, _y+4, Name, gStdFont, r, g, 0, 1);
1264 // Ïèíã/ïîòåðè
1265 e_TextureFontPrintEx(x+w1+16, _y+4, Format(_lc[I_GAME_PING_MS], [Ping, Loss]), gStdFont, r, g, 0, 1);
1266 // Ôðàãè
1267 e_TextureFontPrintEx(x+w1+w2+16, _y+4, IntToStr(Frags), gStdFont, r, g, 0, 1);
1268 // Ñìåðòè
1269 e_TextureFontPrintEx(x+w1+w2+w3+16, _y+4, IntToStr(Deaths), gStdFont, r, g, 0, 1);
1270 _y := _y+ch+8;
1271 end;
1272 end
1273 end;
1275 procedure g_Game_Init();
1276 var
1277 SR: TSearchRec;
1278 begin
1279 gExit := 0;
1280 gMapToDelete := '';
1281 gTempDelete := False;
1283 sfsGCDisable(); // temporary disable removing of temporary volumes
1285 try
1286 TEXTUREFILTER := GL_LINEAR;
1287 g_Texture_CreateWADEx('MENU_BACKGROUND', GameWAD+':TEXTURES\TITLE');
1288 g_Texture_CreateWADEx('INTER', GameWAD+':TEXTURES\INTER');
1289 g_Texture_CreateWADEx('ENDGAME_EN', GameWAD+':TEXTURES\ENDGAME_EN');
1290 g_Texture_CreateWADEx('ENDGAME_RU', GameWAD+':TEXTURES\ENDGAME_RU');
1291 TEXTUREFILTER := GL_NEAREST;
1293 LoadStdFont('STDTXT', 'STDFONT', gStdFont);
1294 LoadFont('MENUTXT', 'MENUFONT', gMenuFont);
1295 LoadFont('SMALLTXT', 'SMALLFONT', gMenuSmallFont);
1297 g_Game_ClearLoading();
1298 g_Game_SetLoadingText(Format('Doom 2D: Forever %s', [GAME_VERSION]), 0, False);
1299 g_Game_SetLoadingText('', 0, False);
1301 g_Game_SetLoadingText(_lc[I_LOAD_CONSOLE], 0, False);
1302 g_Console_Init();
1304 g_Game_SetLoadingText(_lc[I_LOAD_MODELS], 0, False);
1305 g_PlayerModel_LoadData();
1307 if FindFirst(ModelsDir+'*.wad', faAnyFile, SR) = 0 then
1308 repeat
1309 if not g_PlayerModel_Load(ModelsDir+SR.Name) then
1310 e_WriteLog(Format('Error loading model %s', [SR.Name]), TMsgType.Warning);
1311 until FindNext(SR) <> 0;
1312 FindClose(SR);
1314 if FindFirst(ModelsDir+'*.pk3', faAnyFile, SR) = 0 then
1315 repeat
1316 if not g_PlayerModel_Load(ModelsDir+SR.Name) then
1317 e_WriteLog(Format('Error loading model %s', [SR.Name]), TMsgType.Warning);
1318 until FindNext(SR) <> 0;
1319 FindClose(SR);
1321 if FindFirst(ModelsDir+'*.zip', faAnyFile, SR) = 0 then
1322 repeat
1323 if not g_PlayerModel_Load(ModelsDir+SR.Name) then
1324 e_WriteLog(Format('Error loading model %s', [SR.Name]), TMsgType.Warning);
1325 until FindNext(SR) <> 0;
1326 FindClose(SR);
1328 gGameOn := false;
1329 gPauseMain := false;
1330 gPauseHolmes := false;
1331 gTime := 0;
1333 {e_MouseInfo.Accel := 1.0;}
1335 g_Game_SetLoadingText(_lc[I_LOAD_GAME_DATA], 0, False);
1336 g_Game_LoadData();
1338 g_Game_SetLoadingText(_lc[I_LOAD_MUSIC], 0, False);
1339 g_Sound_CreateWADEx('MUSIC_INTERMUS', GameWAD+':MUSIC\INTERMUS', True);
1340 g_Sound_CreateWADEx('MUSIC_MENU', GameWAD+':MUSIC\MENU', True);
1341 g_Sound_CreateWADEx('MUSIC_ROUNDMUS', GameWAD+':MUSIC\ROUNDMUS', True, True);
1342 g_Sound_CreateWADEx('MUSIC_STDENDMUS', GameWAD+':MUSIC\ENDMUS', True);
1344 {$IFNDEF HEADLESS}
1345 g_Game_SetLoadingText(_lc[I_LOAD_MENUS], 0, False);
1346 g_Menu_Init();
1347 {$ENDIF}
1349 gMusic := TMusic.Create();
1350 gMusic.SetByName('MUSIC_MENU');
1351 gMusic.Play();
1353 gGameSettings.WarmupTime := 30;
1355 gState := STATE_MENU;
1357 SetLength(gEvents, 6);
1358 gEvents[0].Name := 'ongamestart';
1359 gEvents[1].Name := 'ongameend';
1360 gEvents[2].Name := 'onmapstart';
1361 gEvents[3].Name := 'onmapend';
1362 gEvents[4].Name := 'oninter';
1363 gEvents[5].Name := 'onwadend';
1364 finally
1365 sfsGCEnable(); // enable releasing unused volumes
1366 end;
1367 end;
1369 procedure g_Game_Free(freeTextures: Boolean=true);
1370 begin
1371 if NetMode = NET_CLIENT then g_Net_Disconnect();
1372 if NetMode = NET_SERVER then g_Net_Host_Die();
1374 g_Map_Free(freeTextures);
1375 g_Player_Free();
1376 g_Player_RemoveAllCorpses();
1378 gGameSettings.GameType := GT_NONE;
1379 if gGameSettings.GameMode = GM_SINGLE then
1380 gGameSettings.GameMode := GM_DM;
1381 gSwitchGameMode := gGameSettings.GameMode;
1383 gChatShow := False;
1384 gExitByTrigger := False;
1385 end;
1387 function IsActivePlayer(p: TPlayer): Boolean;
1388 begin
1389 Result := False;
1390 if p = nil then
1391 Exit;
1392 Result := (not p.FDummy) and (not p.FSpectator);
1393 end;
1395 function GetActivePlayer_ByID(ID: Integer): TPlayer;
1396 var
1397 a: Integer;
1398 begin
1399 Result := nil;
1400 if ID < 0 then
1401 Exit;
1402 if gPlayers = nil then
1403 Exit;
1404 for a := Low(gPlayers) to High(gPlayers) do
1405 if IsActivePlayer(gPlayers[a]) then
1406 begin
1407 if gPlayers[a].UID <> ID then
1408 continue;
1409 Result := gPlayers[a];
1410 break;
1411 end;
1412 end;
1414 function GetActivePlayerID_Next(Skip: Integer = -1): Integer;
1415 var
1416 a, idx: Integer;
1417 ids: Array of Word;
1418 begin
1419 Result := -1;
1420 if gPlayers = nil then
1421 Exit;
1422 SetLength(ids, 0);
1423 idx := -1;
1424 for a := Low(gPlayers) to High(gPlayers) do
1425 if IsActivePlayer(gPlayers[a]) then
1426 begin
1427 SetLength(ids, Length(ids) + 1);
1428 ids[High(ids)] := gPlayers[a].UID;
1429 if gPlayers[a].UID = Skip then
1430 idx := High(ids);
1431 end;
1432 if Length(ids) = 0 then
1433 Exit;
1434 if idx = -1 then
1435 Result := ids[0]
1436 else
1437 Result := ids[(idx + 1) mod Length(ids)];
1438 end;
1440 function GetActivePlayerID_Prev(Skip: Integer = -1): Integer;
1441 var
1442 a, idx: Integer;
1443 ids: Array of Word;
1444 begin
1445 Result := -1;
1446 if gPlayers = nil then
1447 Exit;
1448 SetLength(ids, 0);
1449 idx := -1;
1450 for a := Low(gPlayers) to High(gPlayers) do
1451 if IsActivePlayer(gPlayers[a]) then
1452 begin
1453 SetLength(ids, Length(ids) + 1);
1454 ids[High(ids)] := gPlayers[a].UID;
1455 if gPlayers[a].UID = Skip then
1456 idx := High(ids);
1457 end;
1458 if Length(ids) = 0 then
1459 Exit;
1460 if idx = -1 then
1461 Result := ids[Length(ids) - 1]
1462 else
1463 Result := ids[(Length(ids) - 1 + idx) mod Length(ids)];
1464 end;
1466 function GetActivePlayerID_Random(Skip: Integer = -1): Integer;
1467 var
1468 a, idx: Integer;
1469 ids: Array of Word;
1470 begin
1471 Result := -1;
1472 if gPlayers = nil then
1473 Exit;
1474 SetLength(ids, 0);
1475 idx := -1;
1476 for a := Low(gPlayers) to High(gPlayers) do
1477 if IsActivePlayer(gPlayers[a]) then
1478 begin
1479 SetLength(ids, Length(ids) + 1);
1480 ids[High(ids)] := gPlayers[a].UID;
1481 if gPlayers[a].UID = Skip then
1482 idx := High(ids);
1483 end;
1484 if Length(ids) = 0 then
1485 Exit;
1486 if Length(ids) = 1 then
1487 begin
1488 Result := ids[0];
1489 Exit;
1490 end;
1491 Result := ids[Random(Length(ids))];
1492 a := 10;
1493 while (idx <> -1) and (Result = Skip) and (a > 0) do
1494 begin
1495 Result := ids[Random(Length(ids))];
1496 Dec(a);
1497 end;
1498 end;
1500 function GetRandomSpectMode(Current: Byte): Byte;
1501 label
1502 retry;
1503 begin
1504 Result := Current;
1505 retry:
1506 case Random(7) of
1507 0: Result := SPECT_STATS;
1508 1: Result := SPECT_MAPVIEW;
1509 2: Result := SPECT_MAPVIEW;
1510 3: Result := SPECT_PLAYERS;
1511 4: Result := SPECT_PLAYERS;
1512 5: Result := SPECT_PLAYERS;
1513 6: Result := SPECT_PLAYERS;
1514 end;
1515 if (Current in [SPECT_STATS, SPECT_MAPVIEW]) and (Current = Result) then
1516 goto retry;
1517 end;
1519 procedure ProcessPlayerControls (plr: TPlayer; p: Integer; var MoveButton: Byte);
1520 var
1521 time: Word;
1522 strafeDir: Byte;
1523 i: Integer;
1524 begin
1525 if (plr = nil) then exit;
1526 if (p = 2) then time := 1000 else time := 1;
1527 strafeDir := MoveButton shr 4;
1528 MoveButton := MoveButton and $0F;
1530 if gPlayerAction[p, ACTION_MOVELEFT] and (not gPlayerAction[p, ACTION_MOVERIGHT]) then
1531 MoveButton := 1 // Íàæàòà òîëüêî "Âëåâî"
1532 else if (not gPlayerAction[p, ACTION_MOVELEFT]) and gPlayerAction[p, ACTION_MOVERIGHT] then
1533 MoveButton := 2 // Íàæàòà òîëüêî "Âïðàâî"
1534 else if (not gPlayerAction[p, ACTION_MOVELEFT]) and (not gPlayerAction[p, ACTION_MOVERIGHT]) then
1535 MoveButton := 0; // Íå íàæàòû íè "Âëåâî", íè "Âïðàâî"
1537 // Ñåé÷àñ èëè ðàíüøå áûëè íàæàòû "Âëåâî"/"Âïðàâî" => ïåðåäàåì èãðîêó:
1538 if MoveButton = 1 then
1539 plr.PressKey(KEY_LEFT, time)
1540 else if MoveButton = 2 then
1541 plr.PressKey(KEY_RIGHT, time);
1543 // if we have "strafe" key, turn off old strafe mechanics
1544 if gPlayerAction[p, ACTION_STRAFE] then
1545 begin
1546 // new strafe mechanics
1547 if (strafeDir = 0) then
1548 strafeDir := MoveButton; // start strafing
1549 // now set direction according to strafe (reversed)
1550 if (strafeDir = 2) then
1551 plr.SetDirection(TDirection.D_LEFT)
1552 else if (strafeDir = 1) then
1553 plr.SetDirection(TDirection.D_RIGHT)
1554 end
1555 else
1556 begin
1557 strafeDir := 0; // not strafing anymore
1558 // Ðàíüøå áûëà íàæàòà "Âïðàâî", à ñåé÷àñ "Âëåâî" => áåæèì âïðàâî, ñìîòðèì âëåâî:
1559 if (MoveButton = 2) and gPlayerAction[p, ACTION_MOVELEFT] then
1560 plr.SetDirection(TDirection.D_LEFT)
1561 // Ðàíüøå áûëà íàæàòà "Âëåâî", à ñåé÷àñ "Âïðàâî" => áåæèì âëåâî, ñìîòðèì âïðàâî:
1562 else if (MoveButton = 1) and gPlayerAction[p, ACTION_MOVERIGHT] then
1563 plr.SetDirection(TDirection.D_RIGHT)
1564 // ×òî-òî áûëî íàæàòî è íå èçìåíèëîñü => êóäà áåæèì, òóäà è ñìîòðèì:
1565 else if MoveButton <> 0 then
1566 plr.SetDirection(TDirection(MoveButton-1))
1567 end;
1569 // fix movebutton state
1570 MoveButton := MoveButton or (strafeDir shl 4);
1572 // Îñòàëüíûå êëàâèøè:
1573 if gPlayerAction[p, ACTION_JUMP] then plr.PressKey(KEY_JUMP, time);
1574 if gPlayerAction[p, ACTION_LOOKUP] then plr.PressKey(KEY_UP, time);
1575 if gPlayerAction[p, ACTION_LOOKDOWN] then plr.PressKey(KEY_DOWN, time);
1576 if gPlayerAction[p, ACTION_ATTACK] then plr.PressKey(KEY_FIRE);
1577 if gPlayerAction[p, ACTION_WEAPNEXT] then plr.PressKey(KEY_NEXTWEAPON);
1578 if gPlayerAction[p, ACTION_WEAPPREV] then plr.PressKey(KEY_PREVWEAPON);
1579 if gPlayerAction[p, ACTION_ACTIVATE] then plr.PressKey(KEY_OPEN);
1581 gPlayerAction[p, ACTION_WEAPNEXT] := False; // HACK, remove after readyweaon&pendinweapon implementation
1582 gPlayerAction[p, ACTION_WEAPPREV] := False; // HACK, remove after readyweaon&pendinweapon implementation
1584 for i := WP_FIRST to WP_LAST do
1585 begin
1586 if gSelectWeapon[p, i] then
1587 begin
1588 plr.QueueWeaponSwitch(i); // all choices are passed there, and god will take the best
1589 gSelectWeapon[p, i] := False
1590 end
1591 end;
1593 // HACK: add dynlight here
1594 if gwin_k8_enable_light_experiments then
1595 begin
1596 if e_KeyPressed(IK_F8) and gGameOn and (not gConsoleShow) and (g_ActiveWindow = nil) then
1597 begin
1598 g_playerLight := true;
1599 end;
1600 if e_KeyPressed(IK_F9) and gGameOn and (not gConsoleShow) and (g_ActiveWindow = nil) then
1601 begin
1602 g_playerLight := false;
1603 end;
1604 end;
1606 if gwin_has_stencil and g_playerLight then g_AddDynLight(plr.GameX+32, plr.GameY+40, 128, 1, 1, 0, 0.6);
1607 end;
1609 // HACK: don't have a "key was pressed" function
1610 procedure InterReady();
1611 begin
1612 if InterReadyTime > gTime then Exit;
1613 InterReadyTime := gTime + 3000;
1614 MC_SEND_CheatRequest(NET_CHEAT_READY);
1615 end;
1617 procedure g_Game_Update();
1618 var
1619 Msg: g_gui.TMessage;
1620 Time: Int64;
1621 a: Byte;
1622 w: Word;
1623 i, b: Integer;
1625 function sendMonsPos (mon: TMonster): Boolean;
1626 begin
1627 result := false; // don't stop
1628 // this will also reset "need-send" flag
1629 if mon.gncNeedSend then
1630 begin
1631 MH_SEND_MonsterPos(mon.UID);
1632 end
1633 else if (mon.MonsterType = MONSTER_BARREL) then
1634 begin
1635 if (mon.GameVelX <> 0) or (mon.GameVelY <> 0) then MH_SEND_MonsterPos(mon.UID);
1636 end
1637 else if (mon.MonsterState <> MONSTATE_SLEEP) then
1638 begin
1639 if (mon.MonsterState <> MONSTATE_DEAD) or (mon.GameVelX <> 0) or (mon.GameVelY <> 0) then MH_SEND_MonsterPos(mon.UID);
1640 end;
1641 end;
1643 function sendMonsPosUnexpected (mon: TMonster): Boolean;
1644 begin
1645 result := false; // don't stop
1646 // this will also reset "need-send" flag
1647 if mon.gncNeedSend then MH_SEND_MonsterPos(mon.UID);
1648 end;
1650 var
1651 reliableUpdate: Boolean;
1652 begin
1653 g_ResetDynlights();
1654 framePool.reset();
1656 // Ïîðà âûêëþ÷àòü èãðó:
1657 if gExit = EXIT_QUIT then
1658 Exit;
1659 // Èãðà çàêîí÷èëàñü - îáðàáàòûâàåì:
1660 if gExit <> 0 then
1661 begin
1662 EndGame();
1663 if gExit = EXIT_QUIT then
1664 Exit;
1665 end;
1667 // ×èòàåì êëàâèàòóðó è äæîéñòèê, åñëè îêíî àêòèâíî
1668 // no need to, as we'll do it in event handler
1670 // Îáíîâëÿåì êîíñîëü (äâèæåíèå è ñîîáùåíèÿ):
1671 g_Console_Update();
1673 if (NetMode = NET_NONE) and (g_Game_IsNet) and (gGameOn or (gState in [STATE_FOLD, STATE_INTERCUSTOM])) then
1674 begin
1675 gExit := EXIT_SIMPLE;
1676 EndGame();
1677 Exit;
1678 end;
1680 case gState of
1681 STATE_INTERSINGLE, // Ñòàòèñòêà ïîñëå ïðîõîæäåíèÿ óðîâíÿ â Îäèíî÷íîé èãðå
1682 STATE_INTERCUSTOM, // Ñòàòèñòêà ïîñëå ïðîõîæäåíèÿ óðîâíÿ â Ñâîåé èãðå
1683 STATE_INTERTEXT, // Òåêñò ìåæäó óðîâíÿìè
1684 STATE_INTERPIC: // Êàðòèíêà ìåæäó óðîâíÿìè
1685 begin
1686 if g_Game_IsNet and g_Game_IsServer then
1687 begin
1688 gInterTime := gInterTime + GAME_TICK;
1689 a := Min((gInterEndTime - gInterTime) div 1000 + 1, 255);
1690 if a <> gServInterTime then
1691 begin
1692 gServInterTime := a;
1693 MH_SEND_TimeSync(gServInterTime);
1694 end;
1695 end;
1697 if (not g_Game_IsClient) and
1701 e_KeyPressed(IK_RETURN) or e_KeyPressed(IK_KPRETURN) or e_KeyPressed(IK_SPACE) or
1702 e_KeyPressed(VK_FIRE) or e_KeyPressed(VK_OPEN) or
1703 e_KeyPressed(JOY0_ATTACK) or e_KeyPressed(JOY1_ATTACK) or
1704 e_KeyPressed(JOY2_ATTACK) or e_KeyPressed(JOY3_ATTACK)
1706 and (not gJustChatted) and (not gConsoleShow) and (not gChatShow)
1707 and (g_ActiveWindow = nil)
1709 or (g_Game_IsNet and ((gInterTime > gInterEndTime) or (gInterReadyCount >= NetClientCount)))
1711 then
1712 begin // Íàæàëè <Enter>/<Ïðîáåë> èëè ïðîøëî äîñòàòî÷íî âðåìåíè:
1713 g_Game_StopAllSounds(True);
1715 if gMapOnce then // Ýòî áûë òåñò
1716 gExit := EXIT_SIMPLE
1717 else
1718 if gNextMap <> '' then // Ïåðåõîäèì íà ñëåäóþùóþ êàðòó
1719 g_Game_ChangeMap(gNextMap)
1720 else // Ñëåäóþùåé êàðòû íåò
1721 begin
1722 if gGameSettings.GameType in [GT_CUSTOM, GT_SERVER] then
1723 begin
1724 // Âûõîä â ãëàâíîå ìåíþ:
1725 g_Game_Free;
1726 g_GUI_ShowWindow('MainMenu');
1727 gMusic.SetByName('MUSIC_MENU');
1728 gMusic.Play();
1729 gState := STATE_MENU;
1730 end else
1731 begin
1732 // Ôèíàëüíàÿ êàðòèíêà:
1733 g_Game_ExecuteEvent('onwadend');
1734 g_Game_Free();
1735 if not gMusic.SetByName('MUSIC_endmus') then
1736 gMusic.SetByName('MUSIC_STDENDMUS');
1737 gMusic.Play();
1738 gState := STATE_ENDPIC;
1739 end;
1740 g_Game_ExecuteEvent('ongameend');
1741 end;
1743 Exit;
1744 end
1745 else if g_Game_IsClient and
1748 e_KeyPressed(IK_RETURN) or e_KeyPressed(IK_KPRETURN) or e_KeyPressed(IK_SPACE) or
1749 e_KeyPressed(VK_FIRE) or e_KeyPressed(VK_OPEN) or
1750 e_KeyPressed(JOY0_ATTACK) or e_KeyPressed(JOY1_ATTACK) or
1751 e_KeyPressed(JOY2_ATTACK) or e_KeyPressed(JOY3_ATTACK)
1753 and (not gJustChatted) and (not gConsoleShow) and (not gChatShow)
1754 and (g_ActiveWindow = nil)
1756 then
1757 begin
1758 // ready / unready
1759 InterReady();
1760 end;
1762 if gState = STATE_INTERTEXT then
1763 if InterText.counter > 0 then
1764 InterText.counter := InterText.counter - 1;
1765 end;
1767 STATE_FOLD: // Çàòóõàíèå ýêðàíà
1768 begin
1769 if EndingGameCounter = 0 then
1770 begin
1771 // Çàêîí÷èëñÿ óðîâåíü â Ñâîåé èãðå:
1772 if gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT] then
1773 begin
1774 InterReadyTime := -1;
1775 if gLastMap and (gGameSettings.GameMode = GM_COOP) then
1776 begin
1777 g_Game_ExecuteEvent('onwadend');
1778 if not gMusic.SetByName('MUSIC_endmus') then
1779 gMusic.SetByName('MUSIC_STDENDMUS');
1780 end
1781 else
1782 gMusic.SetByName('MUSIC_ROUNDMUS');
1784 gMusic.Play();
1785 gState := STATE_INTERCUSTOM;
1786 e_UnpressAllKeys();
1787 end
1788 else // Çàêîí÷èëàñü ïîñëåäíÿÿ êàðòà â Îäèíî÷íîé èãðå
1789 begin
1790 gMusic.SetByName('MUSIC_INTERMUS');
1791 gMusic.Play();
1792 gState := STATE_INTERSINGLE;
1793 e_UnpressAllKeys();
1794 end;
1795 g_Game_ExecuteEvent('oninter');
1796 end
1797 else
1798 DecMin(EndingGameCounter, 6, 0);
1799 end;
1801 STATE_ENDPIC: // Êàðòèíêà îêîí÷àíèÿ ìåãàÂàäà
1802 begin
1803 if gMapOnce then // Ýòî áûë òåñò
1804 begin
1805 gExit := EXIT_SIMPLE;
1806 Exit;
1807 end;
1808 end;
1810 STATE_SLIST:
1811 g_Serverlist_Control(slCurrent, slTable);
1812 end;
1814 // Ñòàòèñòèêà ïî Tab:
1815 if gGameOn then
1816 IsDrawStat := (not gConsoleShow) and (not gChatShow) and (gGameSettings.GameType <> GT_SINGLE) and g_Console_Action(ACTION_SCORES);
1818 // Èãðà èäåò:
1819 if gGameOn and not gPause and (gState <> STATE_FOLD) then
1820 begin
1821 // Âðåìÿ += 28 ìèëëèñåêóíä:
1822 gTime := gTime + GAME_TICK;
1824 // Ñîîáùåíèå ïîñåðåäèíå ýêðàíà:
1825 if MessageTime = 0 then
1826 MessageText := '';
1827 if MessageTime > 0 then
1828 MessageTime := MessageTime - 1;
1830 if (g_Game_IsServer) then
1831 begin
1832 // Áûë çàäàí ëèìèò âðåìåíè:
1833 if (gGameSettings.TimeLimit > 0) then
1834 if (gTime - gGameStartTime) div 1000 >= gGameSettings.TimeLimit then
1835 begin // Îí ïðîøåë => êîíåö óðîâíÿ
1836 g_Game_NextLevel();
1837 Exit;
1838 end;
1840 // Íàäî ðåñïàâíèòü èãðîêîâ â LMS:
1841 if (gLMSRespawn > LMS_RESPAWN_NONE) and (gLMSRespawnTime < gTime) then
1842 g_Game_RestartRound(gLMSSoftSpawn);
1844 // Ïðîâåðèì ðåçóëüòàò ãîëîñîâàíèÿ, åñëè âðåìÿ ïðîøëî
1845 if gVoteInProgress and (gVoteTimer < gTime) then
1846 g_Game_CheckVote
1847 else if gVotePassed and (gVoteCmdTimer < gTime) then
1848 begin
1849 g_Console_Process(gVoteCommand);
1850 gVoteCommand := '';
1851 gVotePassed := False;
1852 end;
1854 // Çàìåðÿåì âðåìÿ çàõâàòà ôëàãîâ
1855 if gFlags[FLAG_RED].State = FLAG_STATE_CAPTURED then
1856 gFlags[FLAG_RED].CaptureTime := gFlags[FLAG_RED].CaptureTime + GAME_TICK;
1857 if gFlags[FLAG_BLUE].State = FLAG_STATE_CAPTURED then
1858 gFlags[FLAG_BLUE].CaptureTime := gFlags[FLAG_BLUE].CaptureTime + GAME_TICK;
1860 // Áûë çàäàí ëèìèò ïîáåä:
1861 if (gGameSettings.GoalLimit > 0) then
1862 begin
1863 b := 0;
1865 if gGameSettings.GameMode = GM_DM then
1866 begin // Â DM èùåì èãðîêà ñ max ôðàãàìè
1867 for i := 0 to High(gPlayers) do
1868 if gPlayers[i] <> nil then
1869 if gPlayers[i].Frags > b then
1870 b := gPlayers[i].Frags;
1871 end
1872 else
1873 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
1874 begin //  CTF/TDM âûáèðàåì êîìàíäó ñ íàèáîëüøèì ñ÷åòîì
1875 b := Max(gTeamStat[TEAM_RED].Goals, gTeamStat[TEAM_BLUE].Goals);
1876 end;
1878 // Ëèìèò ïîáåä íàáðàí => êîíåö óðîâíÿ:
1879 if b >= gGameSettings.GoalLimit then
1880 begin
1881 g_Game_NextLevel();
1882 Exit;
1883 end;
1884 end;
1886 // Îáðàáàòûâàåì êëàâèøè èãðîêîâ:
1887 if gPlayer1 <> nil then gPlayer1.ReleaseKeys();
1888 if gPlayer2 <> nil then gPlayer2.ReleaseKeys();
1889 if (not gConsoleShow) and (not gChatShow) and (g_ActiveWindow = nil) then
1890 begin
1891 ProcessPlayerControls(gPlayer1, 0, P1MoveButton);
1892 ProcessPlayerControls(gPlayer2, 1, P2MoveButton);
1893 end // if not console
1894 else
1895 begin
1896 if g_Game_IsNet and (gPlayer1 <> nil) then gPlayer1.PressKey(KEY_CHAT, 10000);
1897 end;
1898 // process weapon switch queue
1899 end; // if server
1901 // Íàáëþäàòåëü
1902 if (gPlayer1 = nil) and (gPlayer2 = nil) and
1903 (not gConsoleShow) and (not gChatShow) and (g_ActiveWindow = nil) then
1904 begin
1905 if not gSpectKeyPress then
1906 begin
1907 if gPlayerAction[0, ACTION_JUMP] and (not gSpectAuto) then
1908 begin
1909 // switch spect mode
1910 case gSpectMode of
1911 SPECT_NONE: ; // not spectator
1912 SPECT_STATS,
1913 SPECT_MAPVIEW: Inc(gSpectMode);
1914 SPECT_PLAYERS: gSpectMode := SPECT_STATS; // reset to 1
1915 end;
1916 gSpectKeyPress := True;
1917 end;
1918 if (gSpectMode = SPECT_MAPVIEW)
1919 and (not gSpectAuto) then
1920 begin
1921 if gPlayerAction[0, ACTION_MOVELEFT] then
1922 gSpectX := Max(gSpectX - gSpectStep, 0);
1923 if gPlayerAction[0, ACTION_MOVERIGHT] then
1924 gSpectX := Min(gSpectX + gSpectStep, gMapInfo.Width - gScreenWidth);
1925 if gPlayerAction[0, ACTION_LOOKUP] then
1926 gSpectY := Max(gSpectY - gSpectStep, 0);
1927 if gPlayerAction[0, ACTION_LOOKDOWN] then
1928 gSpectY := Min(gSpectY + gSpectStep, gMapInfo.Height - gScreenHeight);
1929 if gPlayerAction[0, ACTION_WEAPPREV] then
1930 begin
1931 // decrease step
1932 if gSpectStep > 4 then gSpectStep := gSpectStep shr 1;
1933 gSpectKeyPress := True;
1934 end;
1935 if gPlayerAction[0, ACTION_WEAPNEXT] then
1936 begin
1937 // increase step
1938 if gSpectStep < 64 then gSpectStep := gSpectStep shl 1;
1939 gSpectKeyPress := True;
1940 end;
1941 end;
1942 if (gSpectMode = SPECT_PLAYERS)
1943 and (not gSpectAuto) then
1944 begin
1945 if gPlayerAction[0, ACTION_LOOKUP] then
1946 begin
1947 // add second view
1948 gSpectViewTwo := True;
1949 gSpectKeyPress := True;
1950 end;
1951 if gPlayerAction[0, ACTION_LOOKDOWN] then
1952 begin
1953 // remove second view
1954 gSpectViewTwo := False;
1955 gSpectKeyPress := True;
1956 end;
1957 if gPlayerAction[0, ACTION_MOVELEFT] then
1958 begin
1959 // prev player (view 1)
1960 gSpectPID1 := GetActivePlayerID_Prev(gSpectPID1);
1961 gSpectKeyPress := True;
1962 end;
1963 if gPlayerAction[0, ACTION_MOVERIGHT] then
1964 begin
1965 // next player (view 1)
1966 gSpectPID1 := GetActivePlayerID_Next(gSpectPID1);
1967 gSpectKeyPress := True;
1968 end;
1969 if gPlayerAction[0, ACTION_WEAPPREV] then
1970 begin
1971 // prev player (view 2)
1972 gSpectPID2 := GetActivePlayerID_Prev(gSpectPID2);
1973 gSpectKeyPress := True;
1974 end;
1975 if gPlayerAction[0, ACTION_WEAPNEXT] then
1976 begin
1977 // next player (view 2)
1978 gSpectPID2 := GetActivePlayerID_Next(gSpectPID2);
1979 gSpectKeyPress := True;
1980 end;
1981 end;
1982 if gPlayerAction[0, ACTION_ATTACK] then
1983 begin
1984 if (gSpectMode = SPECT_STATS) and (not gSpectAuto) then
1985 begin
1986 gSpectAuto := True;
1987 gSpectAutoNext := 0;
1988 gSpectViewTwo := False;
1989 gSpectKeyPress := True;
1990 end
1991 else
1992 if gSpectAuto then
1993 begin
1994 gSpectMode := SPECT_STATS;
1995 gSpectAuto := False;
1996 gSpectKeyPress := True;
1997 end;
1998 end;
1999 end
2000 else
2001 if (not gPlayerAction[0, ACTION_JUMP]) and
2002 (not gPlayerAction[0, ACTION_ATTACK]) and
2003 (not gPlayerAction[0, ACTION_MOVELEFT]) and
2004 (not gPlayerAction[0, ACTION_MOVERIGHT]) and
2005 (not gPlayerAction[0, ACTION_LOOKUP]) and
2006 (not gPlayerAction[0, ACTION_LOOKDOWN]) and
2007 (not gPlayerAction[0, ACTION_WEAPPREV]) and
2008 (not gPlayerAction[0, ACTION_WEAPNEXT]) then
2009 gSpectKeyPress := False;
2011 if gSpectAuto then
2012 begin
2013 if gSpectMode = SPECT_MAPVIEW then
2014 begin
2015 i := Min(Max(gSpectX + gSpectAutoStepX, 0), gMapInfo.Width - gScreenWidth);
2016 if i = gSpectX then
2017 gSpectAutoNext := gTime
2018 else
2019 gSpectX := i;
2020 i := Min(Max(gSpectY + gSpectAutoStepY, 0), gMapInfo.Height - gScreenHeight);
2021 if i = gSpectY then
2022 gSpectAutoNext := gTime
2023 else
2024 gSpectY := i;
2025 end;
2026 if gSpectAutoNext <= gTime then
2027 begin
2028 if gSpectAutoNext > 0 then
2029 begin
2030 gSpectMode := GetRandomSpectMode(gSpectMode);
2031 case gSpectMode of
2032 SPECT_MAPVIEW:
2033 begin
2034 gSpectX := Random(gMapInfo.Width - gScreenWidth);
2035 gSpectY := Random(gMapInfo.Height - gScreenHeight);
2036 gSpectAutoStepX := Random(9) - 4;
2037 gSpectAutoStepY := Random(9) - 4;
2038 if ((gSpectX < 800) and (gSpectAutoStepX < 0)) or
2039 ((gSpectX > gMapInfo.Width - gScreenWidth - 800) and (gSpectAutoStepX > 0)) then
2040 gSpectAutoStepX := gSpectAutoStepX * -1;
2041 if ((gSpectY < 800) and (gSpectAutoStepY < 0)) or
2042 ((gSpectY > gMapInfo.Height - gScreenHeight - 800) and (gSpectAutoStepY > 0)) then
2043 gSpectAutoStepY := gSpectAutoStepY * -1;
2044 end;
2045 SPECT_PLAYERS:
2046 begin
2047 gSpectPID1 := GetActivePlayerID_Random(gSpectPID1);
2048 end;
2049 end;
2050 end;
2051 case gSpectMode of
2052 SPECT_STATS: gSpectAutoNext := gTime + (Random(3) + 5) * 1000;
2053 SPECT_MAPVIEW: gSpectAutoNext := gTime + (Random(4) + 7) * 1000;
2054 SPECT_PLAYERS: gSpectAutoNext := gTime + (Random(7) + 8) * 1000;
2055 end;
2056 end;
2057 end;
2058 end;
2060 // Îáíîâëÿåì âñå îñòàëüíîå:
2061 g_Map_Update();
2062 g_Items_Update();
2063 g_Triggers_Update();
2064 g_Weapon_Update();
2065 g_Monsters_Update();
2066 g_GFX_Update();
2067 g_Player_UpdateAll();
2068 g_Player_UpdatePhysicalObjects();
2070 // server: send newly spawned monsters unconditionally
2071 if (gGameSettings.GameType = GT_SERVER) then
2072 begin
2073 if (Length(gMonstersSpawned) > 0) then
2074 begin
2075 for I := 0 to High(gMonstersSpawned) do MH_SEND_MonsterSpawn(gMonstersSpawned[I]);
2076 SetLength(gMonstersSpawned, 0);
2077 end;
2078 end;
2080 if (gSoundTriggerTime > 8) then
2081 begin
2082 g_Game_UpdateTriggerSounds();
2083 gSoundTriggerTime := 0;
2084 end
2085 else
2086 begin
2087 Inc(gSoundTriggerTime);
2088 end;
2090 if (NetMode = NET_SERVER) then
2091 begin
2092 Inc(NetTimeToUpdate);
2093 Inc(NetTimeToReliable);
2095 // send monster updates
2096 if (NetTimeToReliable >= NetRelupdRate) or (NetTimeToUpdate >= NetUpdateRate) then
2097 begin
2098 // send all monsters (periodic sync)
2099 reliableUpdate := (NetTimeToReliable >= NetRelupdRate);
2101 for I := 0 to High(gPlayers) do
2102 begin
2103 if (gPlayers[I] <> nil) then MH_SEND_PlayerPos(reliableUpdate, gPlayers[I].UID);
2104 end;
2106 g_Mons_ForEach(sendMonsPos);
2108 if reliableUpdate then
2109 begin
2110 NetTimeToReliable := 0;
2111 NetTimeToUpdate := NetUpdateRate;
2112 end
2113 else
2114 begin
2115 NetTimeToUpdate := 0;
2116 end;
2117 end
2118 else
2119 begin
2120 // send only mosters with some unexpected changes
2121 g_Mons_ForEach(sendMonsPosUnexpected);
2122 end;
2124 // send unexpected platform changes
2125 g_Map_NetSendInterestingPanels();
2127 if NetUseMaster then
2128 begin
2129 if gTime >= NetTimeToMaster then
2130 begin
2131 if (NetMHost = nil) or (NetMPeer = nil) then
2132 begin
2133 g_Net_Slist_Connect(false); // non-blocking connection to the master
2134 end;
2136 g_Net_Slist_Update;
2137 NetTimeToMaster := gTime + NetMasterRate;
2138 end;
2139 end;
2140 end
2141 else if (NetMode = NET_CLIENT) then
2142 begin
2143 MC_SEND_PlayerPos();
2144 end;
2145 end; // if gameOn ...
2147 // Àêòèâíî îêíî èíòåðôåéñà - ïåðåäàåì êëàâèøè åìó:
2148 if g_ActiveWindow <> nil then
2149 begin
2150 w := e_GetFirstKeyPressed();
2152 if (w <> IK_INVALID) then
2153 begin
2154 Msg.Msg := MESSAGE_DIKEY;
2155 Msg.wParam := w;
2156 g_ActiveWindow.OnMessage(Msg);
2157 end;
2159 // Åñëè îíî îò ýòîãî íå çàêðûëîñü, òî îáíîâëÿåì:
2160 if g_ActiveWindow <> nil then
2161 g_ActiveWindow.Update();
2163 // Íóæíî ñìåíèòü ðàçðåøåíèå:
2164 if gResolutionChange then
2165 begin
2166 e_WriteLog('Changing resolution', TMsgType.Notify);
2167 g_Game_ChangeResolution(gRC_Width, gRC_Height, gRC_FullScreen, gRC_Maximized);
2168 gResolutionChange := False;
2169 g_ActiveWindow := nil;
2170 end;
2172 // Íóæíî ñìåíèòü ÿçûê:
2173 if gLanguageChange then
2174 begin
2175 //e_WriteLog('Read language file', MSG_NOTIFY);
2176 //g_Language_Load(DataDir + gLanguage + '.txt');
2177 g_Language_Set(gLanguage);
2178 {$IFNDEF HEADLESS}
2179 g_Menu_Reset();
2180 {$ENDIF}
2181 gLanguageChange := False;
2182 end;
2183 end;
2185 // Ãîðÿ÷àÿ êëàâèøà äëÿ âûçîâà ìåíþ âûõîäà èç èãðû (F10):
2186 if e_KeyPressed(IK_F10) and
2187 gGameOn and
2188 (not gConsoleShow) and
2189 (g_ActiveWindow = nil) then
2190 begin
2191 KeyPress(IK_F10);
2192 end;
2194 Time := GetTimer() {div 1000};
2196 // Îáðàáîòêà îòëîæåííûõ ñîáûòèé:
2197 if gDelayedEvents <> nil then
2198 for a := 0 to High(gDelayedEvents) do
2199 if gDelayedEvents[a].Pending and
2201 ((gDelayedEvents[a].DEType = DE_GLOBEVENT) and (gDelayedEvents[a].Time <= Time)) or
2202 ((gDelayedEvents[a].DEType > DE_GLOBEVENT) and (gDelayedEvents[a].Time <= gTime))
2203 ) then
2204 begin
2205 case gDelayedEvents[a].DEType of
2206 DE_GLOBEVENT:
2207 g_Game_ExecuteEvent(gDelayedEvents[a].DEStr);
2208 DE_BFGHIT:
2209 if gGameOn then
2210 g_Game_Announce_GoodShot(gDelayedEvents[a].DENum);
2211 DE_KILLCOMBO:
2212 if gGameOn then
2213 begin
2214 g_Game_Announce_KillCombo(gDelayedEvents[a].DENum);
2215 if g_Game_IsNet and g_Game_IsServer then
2216 MH_SEND_GameEvent(NET_EV_KILLCOMBO, gDelayedEvents[a].DENum);
2217 end;
2218 DE_BODYKILL:
2219 if gGameOn then
2220 g_Game_Announce_BodyKill(gDelayedEvents[a].DENum);
2221 end;
2222 gDelayedEvents[a].Pending := False;
2223 end;
2225 // Êàæäóþ ñåêóíäó îáíîâëÿåì ñ÷åò÷èê îáíîâëåíèé:
2226 UPSCounter := UPSCounter + 1;
2227 if Time - UPSTime >= 1000 then
2228 begin
2229 UPS := UPSCounter;
2230 UPSCounter := 0;
2231 UPSTime := Time;
2232 end;
2234 if gGameOn then
2235 begin
2236 g_Weapon_AddDynLights();
2237 g_Items_AddDynLights();
2238 end;
2239 end;
2241 procedure g_Game_LoadChatSounds(Resource: string);
2242 var
2243 WAD: TWADFile;
2244 FileName, Snd: string;
2245 p: Pointer;
2246 len, cnt, tags, i, j: Integer;
2247 cfg: TConfig;
2248 begin
2249 FileName := g_ExtractWadName(Resource);
2251 WAD := TWADFile.Create();
2252 WAD.ReadFile(FileName);
2254 if not WAD.GetResource(g_ExtractFilePathName(Resource), p, len) then
2255 begin
2256 gChatSounds := nil;
2257 WAD.Free();
2258 Exit;
2259 end;
2261 cfg := TConfig.CreateMem(p, len);
2262 cnt := cfg.ReadInt('ChatSounds', 'Count', 0);
2264 SetLength(gChatSounds, cnt);
2265 for i := 0 to Length(gChatSounds) - 1 do
2266 begin
2267 gChatSounds[i].Sound := nil;
2268 Snd := Trim(cfg.ReadStr(IntToStr(i), 'Sound', ''));
2269 tags := cfg.ReadInt(IntToStr(i), 'Tags', 0);
2270 if (Snd = '') or (Tags <= 0) then
2271 continue;
2272 g_Sound_CreateWADEx('SOUND_CHAT_MACRO' + IntToStr(i), GameWAD+':'+Snd);
2273 gChatSounds[i].Sound := TPlayableSound.Create();
2274 gChatSounds[i].Sound.SetByName('SOUND_CHAT_MACRO' + IntToStr(i));
2275 SetLength(gChatSounds[i].Tags, tags);
2276 for j := 0 to tags - 1 do
2277 gChatSounds[i].Tags[j] := toLowerCase1251(cfg.ReadStr(IntToStr(i), 'Tag' + IntToStr(j), ''));
2278 gChatSounds[i].FullWord := cfg.ReadBool(IntToStr(i), 'FullWord', False);
2279 end;
2281 cfg.Free();
2282 WAD.Free();
2283 end;
2285 procedure g_Game_FreeChatSounds();
2286 var
2287 i: Integer;
2288 begin
2289 for i := 0 to Length(gChatSounds) - 1 do
2290 begin
2291 gChatSounds[i].Sound.Free();
2292 g_Sound_Delete('SOUND_CHAT_MACRO' + IntToStr(i));
2293 end;
2294 SetLength(gChatSounds, 0);
2295 gChatSounds := nil;
2296 end;
2298 procedure g_Game_LoadData();
2299 var
2300 wl, hl: Integer;
2301 wr, hr: Integer;
2302 wb, hb: Integer;
2303 wm, hm: Integer;
2304 begin
2305 if DataLoaded then Exit;
2307 e_WriteLog('Loading game data...', TMsgType.Notify);
2309 g_Texture_CreateWADEx('NOTEXTURE', GameWAD+':TEXTURES\NOTEXTURE');
2310 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUD', GameWAD+':TEXTURES\HUD');
2311 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDAIR', GameWAD+':TEXTURES\AIRBAR');
2312 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDJET', GameWAD+':TEXTURES\JETBAR');
2313 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDBG', GameWAD+':TEXTURES\HUDBG');
2314 g_Texture_CreateWADEx('TEXTURE_PLAYER_ARMORHUD', GameWAD+':TEXTURES\ARMORHUD');
2315 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG', GameWAD+':TEXTURES\FLAGHUD_R_BASE');
2316 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_S', GameWAD+':TEXTURES\FLAGHUD_R_STOLEN');
2317 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_D', GameWAD+':TEXTURES\FLAGHUD_R_DROP');
2318 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG', GameWAD+':TEXTURES\FLAGHUD_B_BASE');
2319 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_S', GameWAD+':TEXTURES\FLAGHUD_B_STOLEN');
2320 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_D', GameWAD+':TEXTURES\FLAGHUD_B_DROP');
2321 g_Texture_CreateWADEx('TEXTURE_PLAYER_TALKBUBBLE', GameWAD+':TEXTURES\TALKBUBBLE');
2322 g_Texture_CreateWADEx('TEXTURE_PLAYER_INVULPENTA', GameWAD+':TEXTURES\PENTA');
2323 g_Texture_CreateWADEx('TEXTURE_PLAYER_INDICATOR', GameWAD+':TEXTURES\PLRIND');
2325 hasPBarGfx := true;
2326 if not g_Texture_CreateWADEx('UI_GFX_PBAR_LEFT', GameWAD+':TEXTURES\LLEFT') then hasPBarGfx := false;
2327 if not g_Texture_CreateWADEx('UI_GFX_PBAR_MARKER', GameWAD+':TEXTURES\LMARKER') then hasPBarGfx := false;
2328 if not g_Texture_CreateWADEx('UI_GFX_PBAR_MIDDLE', GameWAD+':TEXTURES\LMIDDLE') then hasPBarGfx := false;
2329 if not g_Texture_CreateWADEx('UI_GFX_PBAR_RIGHT', GameWAD+':TEXTURES\LRIGHT') then hasPBarGfx := false;
2331 if hasPBarGfx then
2332 begin
2333 g_Texture_GetSize('UI_GFX_PBAR_LEFT', wl, hl);
2334 g_Texture_GetSize('UI_GFX_PBAR_RIGHT', wr, hr);
2335 g_Texture_GetSize('UI_GFX_PBAR_MIDDLE', wb, hb);
2336 g_Texture_GetSize('UI_GFX_PBAR_MARKER', wm, hm);
2337 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
2338 begin
2339 // yay!
2340 end
2341 else
2342 begin
2343 hasPBarGfx := false;
2344 end;
2345 end;
2347 g_Frames_CreateWAD(nil, 'FRAMES_TELEPORT', GameWAD+':TEXTURES\TELEPORT', 64, 64, 10, False);
2348 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH', GameWAD+':WEAPONS\PUNCH', 64, 64, 4, False);
2349 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_UP', GameWAD+':WEAPONS\PUNCH_UP', 64, 64, 4, False);
2350 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_DN', GameWAD+':WEAPONS\PUNCH_DN', 64, 64, 4, False);
2351 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK', GameWAD+':WEAPONS\PUNCHB', 64, 64, 4, False);
2352 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK_UP', GameWAD+':WEAPONS\PUNCHB_UP', 64, 64, 4, False);
2353 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK_DN', GameWAD+':WEAPONS\PUNCHB_DN', 64, 64, 4, False);
2354 g_Sound_CreateWADEx('SOUND_GAME_TELEPORT', GameWAD+':SOUNDS\TELEPORT');
2355 g_Sound_CreateWADEx('SOUND_GAME_NOTELEPORT', GameWAD+':SOUNDS\NOTELEPORT');
2356 g_Sound_CreateWADEx('SOUND_GAME_SECRET', GameWAD+':SOUNDS\SECRET');
2357 g_Sound_CreateWADEx('SOUND_GAME_DOOROPEN', GameWAD+':SOUNDS\DOOROPEN');
2358 g_Sound_CreateWADEx('SOUND_GAME_DOORCLOSE', GameWAD+':SOUNDS\DOORCLOSE');
2359 g_Sound_CreateWADEx('SOUND_GAME_BULK1', GameWAD+':SOUNDS\BULK1');
2360 g_Sound_CreateWADEx('SOUND_GAME_BULK2', GameWAD+':SOUNDS\BULK2');
2361 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE1', GameWAD+':SOUNDS\BUBBLE1');
2362 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE2', GameWAD+':SOUNDS\BUBBLE2');
2363 g_Sound_CreateWADEx('SOUND_GAME_BURNING', GameWAD+':SOUNDS\BURNING');
2364 g_Sound_CreateWADEx('SOUND_GAME_SWITCH1', GameWAD+':SOUNDS\SWITCH1');
2365 g_Sound_CreateWADEx('SOUND_GAME_SWITCH0', GameWAD+':SOUNDS\SWITCH0');
2366 g_Sound_CreateWADEx('SOUND_GAME_RADIO', GameWAD+':SOUNDS\RADIO');
2367 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD1', GameWAD+':SOUNDS\GOOD1');
2368 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD2', GameWAD+':SOUNDS\GOOD2');
2369 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD3', GameWAD+':SOUNDS\GOOD3');
2370 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD4', GameWAD+':SOUNDS\GOOD4');
2371 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL2X', GameWAD+':SOUNDS\KILL2X');
2372 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL3X', GameWAD+':SOUNDS\KILL3X');
2373 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL4X', GameWAD+':SOUNDS\KILL4X');
2374 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILLMX', GameWAD+':SOUNDS\KILLMX');
2375 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA1', GameWAD+':SOUNDS\MUHAHA1');
2376 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA2', GameWAD+':SOUNDS\MUHAHA2');
2377 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA3', GameWAD+':SOUNDS\MUHAHA3');
2378 g_Sound_CreateWADEx('SOUND_CTF_GET1', GameWAD+':SOUNDS\GETFLAG1');
2379 g_Sound_CreateWADEx('SOUND_CTF_GET2', GameWAD+':SOUNDS\GETFLAG2');
2380 g_Sound_CreateWADEx('SOUND_CTF_LOST1', GameWAD+':SOUNDS\LOSTFLG1');
2381 g_Sound_CreateWADEx('SOUND_CTF_LOST2', GameWAD+':SOUNDS\LOSTFLG2');
2382 g_Sound_CreateWADEx('SOUND_CTF_RETURN1', GameWAD+':SOUNDS\RETFLAG1');
2383 g_Sound_CreateWADEx('SOUND_CTF_RETURN2', GameWAD+':SOUNDS\RETFLAG2');
2384 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE1', GameWAD+':SOUNDS\CAPFLAG1');
2385 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE2', GameWAD+':SOUNDS\CAPFLAG2');
2387 goodsnd[0] := TPlayableSound.Create();
2388 goodsnd[1] := TPlayableSound.Create();
2389 goodsnd[2] := TPlayableSound.Create();
2390 goodsnd[3] := TPlayableSound.Create();
2392 goodsnd[0].SetByName('SOUND_ANNOUNCER_GOOD1');
2393 goodsnd[1].SetByName('SOUND_ANNOUNCER_GOOD2');
2394 goodsnd[2].SetByName('SOUND_ANNOUNCER_GOOD3');
2395 goodsnd[3].SetByName('SOUND_ANNOUNCER_GOOD4');
2397 killsnd[0] := TPlayableSound.Create();
2398 killsnd[1] := TPlayableSound.Create();
2399 killsnd[2] := TPlayableSound.Create();
2400 killsnd[3] := TPlayableSound.Create();
2402 killsnd[0].SetByName('SOUND_ANNOUNCER_KILL2X');
2403 killsnd[1].SetByName('SOUND_ANNOUNCER_KILL3X');
2404 killsnd[2].SetByName('SOUND_ANNOUNCER_KILL4X');
2405 killsnd[3].SetByName('SOUND_ANNOUNCER_KILLMX');
2407 hahasnd[0] := TPlayableSound.Create();
2408 hahasnd[1] := TPlayableSound.Create();
2409 hahasnd[2] := TPlayableSound.Create();
2411 hahasnd[0].SetByName('SOUND_ANNOUNCER_MUHAHA1');
2412 hahasnd[1].SetByName('SOUND_ANNOUNCER_MUHAHA2');
2413 hahasnd[2].SetByName('SOUND_ANNOUNCER_MUHAHA3');
2415 sound_get_flag[0] := TPlayableSound.Create();
2416 sound_get_flag[1] := TPlayableSound.Create();
2417 sound_lost_flag[0] := TPlayableSound.Create();
2418 sound_lost_flag[1] := TPlayableSound.Create();
2419 sound_ret_flag[0] := TPlayableSound.Create();
2420 sound_ret_flag[1] := TPlayableSound.Create();
2421 sound_cap_flag[0] := TPlayableSound.Create();
2422 sound_cap_flag[1] := TPlayableSound.Create();
2424 sound_get_flag[0].SetByName('SOUND_CTF_GET1');
2425 sound_get_flag[1].SetByName('SOUND_CTF_GET2');
2426 sound_lost_flag[0].SetByName('SOUND_CTF_LOST1');
2427 sound_lost_flag[1].SetByName('SOUND_CTF_LOST2');
2428 sound_ret_flag[0].SetByName('SOUND_CTF_RETURN1');
2429 sound_ret_flag[1].SetByName('SOUND_CTF_RETURN2');
2430 sound_cap_flag[0].SetByName('SOUND_CTF_CAPTURE1');
2431 sound_cap_flag[1].SetByName('SOUND_CTF_CAPTURE2');
2433 g_Game_LoadChatSounds(GameWAD+':CHATSND\SNDCFG');
2435 g_Game_SetLoadingText(_lc[I_LOAD_ITEMS_DATA], 0, False);
2436 g_Items_LoadData();
2438 g_Game_SetLoadingText(_lc[I_LOAD_WEAPONS_DATA], 0, False);
2439 g_Weapon_LoadData();
2441 g_Monsters_LoadData();
2443 DataLoaded := True;
2444 end;
2446 procedure g_Game_FreeData();
2447 begin
2448 if not DataLoaded then Exit;
2450 g_Items_FreeData();
2451 g_Weapon_FreeData();
2452 g_Monsters_FreeData();
2454 e_WriteLog('Releasing game data...', TMsgType.Notify);
2456 g_Texture_Delete('NOTEXTURE');
2457 g_Texture_Delete('TEXTURE_PLAYER_HUD');
2458 g_Texture_Delete('TEXTURE_PLAYER_HUDBG');
2459 g_Texture_Delete('TEXTURE_PLAYER_ARMORHUD');
2460 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG');
2461 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_S');
2462 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_D');
2463 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG');
2464 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_S');
2465 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_D');
2466 g_Texture_Delete('TEXTURE_PLAYER_TALKBUBBLE');
2467 g_Texture_Delete('TEXTURE_PLAYER_INVULPENTA');
2468 g_Frames_DeleteByName('FRAMES_TELEPORT');
2469 g_Frames_DeleteByName('FRAMES_PUNCH');
2470 g_Frames_DeleteByName('FRAMES_PUNCH_UP');
2471 g_Frames_DeleteByName('FRAMES_PUNCH_DN');
2472 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK');
2473 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK_UP');
2474 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK_DN');
2475 g_Sound_Delete('SOUND_GAME_TELEPORT');
2476 g_Sound_Delete('SOUND_GAME_NOTELEPORT');
2477 g_Sound_Delete('SOUND_GAME_SECRET');
2478 g_Sound_Delete('SOUND_GAME_DOOROPEN');
2479 g_Sound_Delete('SOUND_GAME_DOORCLOSE');
2480 g_Sound_Delete('SOUND_GAME_BULK1');
2481 g_Sound_Delete('SOUND_GAME_BULK2');
2482 g_Sound_Delete('SOUND_GAME_BUBBLE1');
2483 g_Sound_Delete('SOUND_GAME_BUBBLE2');
2484 g_Sound_Delete('SOUND_GAME_BURNING');
2485 g_Sound_Delete('SOUND_GAME_SWITCH1');
2486 g_Sound_Delete('SOUND_GAME_SWITCH0');
2488 goodsnd[0].Free();
2489 goodsnd[1].Free();
2490 goodsnd[2].Free();
2491 goodsnd[3].Free();
2493 g_Sound_Delete('SOUND_ANNOUNCER_GOOD1');
2494 g_Sound_Delete('SOUND_ANNOUNCER_GOOD2');
2495 g_Sound_Delete('SOUND_ANNOUNCER_GOOD3');
2496 g_Sound_Delete('SOUND_ANNOUNCER_GOOD4');
2498 killsnd[0].Free();
2499 killsnd[1].Free();
2500 killsnd[2].Free();
2501 killsnd[3].Free();
2503 g_Sound_Delete('SOUND_ANNOUNCER_KILL2X');
2504 g_Sound_Delete('SOUND_ANNOUNCER_KILL3X');
2505 g_Sound_Delete('SOUND_ANNOUNCER_KILL4X');
2506 g_Sound_Delete('SOUND_ANNOUNCER_KILLMX');
2508 hahasnd[0].Free();
2509 hahasnd[1].Free();
2510 hahasnd[2].Free();
2512 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA1');
2513 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA2');
2514 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA3');
2516 sound_get_flag[0].Free();
2517 sound_get_flag[1].Free();
2518 sound_lost_flag[0].Free();
2519 sound_lost_flag[1].Free();
2520 sound_ret_flag[0].Free();
2521 sound_ret_flag[1].Free();
2522 sound_cap_flag[0].Free();
2523 sound_cap_flag[1].Free();
2525 g_Sound_Delete('SOUND_CTF_GET1');
2526 g_Sound_Delete('SOUND_CTF_GET2');
2527 g_Sound_Delete('SOUND_CTF_LOST1');
2528 g_Sound_Delete('SOUND_CTF_LOST2');
2529 g_Sound_Delete('SOUND_CTF_RETURN1');
2530 g_Sound_Delete('SOUND_CTF_RETURN2');
2531 g_Sound_Delete('SOUND_CTF_CAPTURE1');
2532 g_Sound_Delete('SOUND_CTF_CAPTURE2');
2534 g_Game_FreeChatSounds();
2536 DataLoaded := False;
2537 end;
2539 procedure DrawCustomStat();
2540 var
2541 pc, x, y, w, _y,
2542 w1, w2, w3,
2543 t, p, m: Integer;
2544 ww1, hh1: Word;
2545 ww2, hh2, r, g, b, rr, gg, bb: Byte;
2546 s1, s2, topstr: String;
2547 begin
2548 e_TextureFontGetSize(gStdFont, ww2, hh2);
2550 g_ProcessMessages();
2552 if g_Console_Action(ACTION_SCORES) then
2553 begin
2554 if not gStatsPressed then
2555 begin
2556 gStatsOff := not gStatsOff;
2557 gStatsPressed := True;
2558 end;
2559 end
2560 else
2561 gStatsPressed := False;
2563 if gStatsOff then
2564 begin
2565 s1 := _lc[I_MENU_INTER_NOTICE_TAB];
2566 w := (Length(s1) * ww2) div 2;
2567 x := gScreenWidth div 2 - w;
2568 y := 8;
2569 e_TextureFontPrint(x, y, s1, gStdFont);
2570 Exit;
2571 end;
2573 if (gGameSettings.GameMode = GM_COOP) then
2574 begin
2575 if gMissionFailed then
2576 topstr := _lc[I_MENU_INTER_MISSION_FAIL]
2577 else
2578 topstr := _lc[I_MENU_INTER_LEVEL_COMPLETE];
2579 end
2580 else
2581 topstr := _lc[I_MENU_INTER_ROUND_OVER];
2583 e_CharFont_GetSize(gMenuFont, topstr, ww1, hh1);
2584 e_CharFont_Print(gMenuFont, (gScreenWidth div 2)-(ww1 div 2), 16, topstr);
2586 if g_Game_IsNet then
2587 begin
2588 topstr := Format(_lc[I_MENU_INTER_NOTICE_TIME], [gServInterTime]);
2589 if not gChatShow then
2590 e_TextureFontPrintEx((gScreenWidth div 2)-(Length(topstr)*ww2 div 2),
2591 gScreenHeight-(hh2+4)*2, topstr, gStdFont, 255, 255, 255, 1);
2592 end;
2594 if g_Game_IsClient then
2595 topstr := _lc[I_MENU_INTER_NOTICE_MAP]
2596 else
2597 topstr := _lc[I_MENU_INTER_NOTICE_SPACE];
2598 if not gChatShow then
2599 e_TextureFontPrintEx((gScreenWidth div 2)-(Length(topstr)*ww2 div 2),
2600 gScreenHeight-(hh2+4), topstr, gStdFont, 255, 255, 255, 1);
2602 x := 32;
2603 y := 16+hh1+16;
2605 w := gScreenWidth-x*2;
2607 w2 := (w-16) div 6;
2608 w3 := w2;
2609 w1 := w-16-w2-w3;
2611 e_DrawFillQuad(x, y, gScreenWidth-x-1, gScreenHeight-y-1, 64, 64, 64, 32);
2612 e_DrawQuad(x, y, gScreenWidth-x-1, gScreenHeight-y-1, 255, 127, 0);
2614 m := Max(Length(_lc[I_MENU_MAP])+1, Length(_lc[I_GAME_GAME_TIME])+1)*ww2;
2616 case CustomStat.GameMode of
2617 GM_DM:
2618 begin
2619 if gGameSettings.MaxLives = 0 then
2620 s1 := _lc[I_GAME_DM]
2621 else
2622 s1 := _lc[I_GAME_LMS];
2623 end;
2624 GM_TDM:
2625 begin
2626 if gGameSettings.MaxLives = 0 then
2627 s1 := _lc[I_GAME_TDM]
2628 else
2629 s1 := _lc[I_GAME_TLMS];
2630 end;
2631 GM_CTF: s1 := _lc[I_GAME_CTF];
2632 GM_COOP:
2633 begin
2634 if gGameSettings.MaxLives = 0 then
2635 s1 := _lc[I_GAME_COOP]
2636 else
2637 s1 := _lc[I_GAME_SURV];
2638 end;
2639 else s1 := '';
2640 end;
2642 _y := y+16;
2643 e_TextureFontPrintEx(x+(w div 2)-(Length(s1)*ww2 div 2), _y, s1, gStdFont, 255, 255, 255, 1);
2644 _y := _y+8;
2646 _y := _y+16;
2647 e_TextureFontPrintEx(x+8, _y, _lc[I_MENU_MAP], gStdFont, 255, 127, 0, 1);
2648 e_TextureFontPrint(x+8+m, _y, Format('%s - %s', [CustomStat.Map, CustomStat.MapName]), gStdFont);
2650 _y := _y+16;
2651 e_TextureFontPrintEx(x+8, _y, _lc[I_GAME_GAME_TIME], gStdFont, 255, 127, 0, 1);
2652 e_TextureFontPrint(x+8+m, _y, Format('%d:%.2d:%.2d', [CustomStat.GameTime div 1000 div 3600,
2653 (CustomStat.GameTime div 1000 div 60) mod 60,
2654 CustomStat.GameTime div 1000 mod 60]), gStdFont);
2656 pc := Length(CustomStat.PlayerStat);
2657 if pc = 0 then Exit;
2659 if CustomStat.GameMode = GM_COOP then
2660 begin
2661 m := Max(Length(_lc[I_GAME_MONSTERS])+1, Length(_lc[I_GAME_SECRETS])+1)*ww2;
2662 _y := _y+32;
2663 s2 := _lc[I_GAME_MONSTERS];
2664 e_TextureFontPrintEx(x+8, _y, s2, gStdFont, 255, 127, 0, 1);
2665 e_TextureFontPrintEx(x+8+m, _y, IntToStr(gCoopMonstersKilled) + '/' + IntToStr(gTotalMonsters), gStdFont, 255, 255, 255, 1);
2666 _y := _y+16;
2667 s2 := _lc[I_GAME_SECRETS];
2668 e_TextureFontPrintEx(x+8, _y, s2, gStdFont, 255, 127, 0, 1);
2669 e_TextureFontPrintEx(x+8+m, _y, IntToStr(gCoopSecretsFound) + '/' + IntToStr(gSecretsCount), gStdFont, 255, 255, 255, 1);
2670 if gLastMap then
2671 begin
2672 m := Max(Length(_lc[I_GAME_MONSTERS_TOTAL])+1, Length(_lc[I_GAME_SECRETS_TOTAL])+1)*ww2;
2673 _y := _y-16;
2674 s2 := _lc[I_GAME_MONSTERS_TOTAL];
2675 e_TextureFontPrintEx(x+250, _y, s2, gStdFont, 255, 127, 0, 1);
2676 e_TextureFontPrintEx(x+250+m, _y, IntToStr(gCoopTotalMonstersKilled) + '/' + IntToStr(gCoopTotalMonsters), gStdFont, 255, 255, 255, 1);
2677 _y := _y+16;
2678 s2 := _lc[I_GAME_SECRETS_TOTAL];
2679 e_TextureFontPrintEx(x+250, _y, s2, gStdFont, 255, 127, 0, 1);
2680 e_TextureFontPrintEx(x+250+m, _y, IntToStr(gCoopTotalSecretsFound) + '/' + IntToStr(gCoopTotalSecrets), gStdFont, 255, 255, 255, 1);
2681 end;
2682 end;
2684 if CustomStat.GameMode in [GM_TDM, GM_CTF] then
2685 begin
2686 _y := _y+16+16;
2688 with CustomStat do
2689 if TeamStat[TEAM_RED].Goals > TeamStat[TEAM_BLUE].Goals then s1 := _lc[I_GAME_WIN_RED]
2690 else if TeamStat[TEAM_BLUE].Goals > TeamStat[TEAM_RED].Goals then s1 := _lc[I_GAME_WIN_BLUE]
2691 else s1 := _lc[I_GAME_WIN_DRAW];
2693 e_TextureFontPrintEx(x+8+(w div 2)-(Length(s1)*ww2 div 2), _y, s1, gStdFont, 255, 255, 255, 1);
2694 _y := _y+40;
2696 for t := TEAM_RED to TEAM_BLUE do
2697 begin
2698 if t = TEAM_RED then
2699 begin
2700 e_TextureFontPrintEx(x+8, _y, _lc[I_GAME_TEAM_RED],
2701 gStdFont, 255, 0, 0, 1);
2702 e_TextureFontPrintEx(x+w1+8, _y, IntToStr(CustomStat.TeamStat[TEAM_RED].Goals),
2703 gStdFont, 255, 0, 0, 1);
2704 r := 255;
2705 g := 0;
2706 b := 0;
2707 end
2708 else
2709 begin
2710 e_TextureFontPrintEx(x+8, _y, _lc[I_GAME_TEAM_BLUE],
2711 gStdFont, 0, 0, 255, 1);
2712 e_TextureFontPrintEx(x+w1+8, _y, IntToStr(CustomStat.TeamStat[TEAM_BLUE].Goals),
2713 gStdFont, 0, 0, 255, 1);
2714 r := 0;
2715 g := 0;
2716 b := 255;
2717 end;
2719 e_DrawLine(1, x+8, _y+20, x-8+w, _y+20, r, g, b);
2720 _y := _y+24;
2722 for p := 0 to High(CustomStat.PlayerStat) do
2723 if CustomStat.PlayerStat[p].Team = t then
2724 with CustomStat.PlayerStat[p] do
2725 begin
2726 if Spectator then
2727 begin
2728 rr := r div 2;
2729 gg := g div 2;
2730 bb := b div 2;
2731 end
2732 else
2733 begin
2734 rr := r;
2735 gg := g;
2736 bb := b;
2737 end;
2738 if (gPlayers[Num] <> nil) and (gPlayers[Num].FReady) then
2739 e_TextureFontPrintEx(x+16, _y, Name + ' *', gStdFont, rr, gg, bb, 1)
2740 else
2741 e_TextureFontPrintEx(x+16, _y, Name, gStdFont, rr, gg, bb, 1);
2742 e_TextureFontPrintEx(x+w1+16, _y, IntToStr(Frags), gStdFont, rr, gg, bb, 1);
2743 e_TextureFontPrintEx(x+w1+w2+16, _y, IntToStr(Deaths), gStdFont, rr, gg, bb, 1);
2744 _y := _y+24;
2745 end;
2747 _y := _y+16+16;
2748 end;
2749 end
2750 else if CustomStat.GameMode in [GM_DM, GM_COOP] then
2751 begin
2752 _y := _y+40;
2753 e_TextureFontPrintEx(x+8, _y, _lc[I_GAME_PLAYER_NAME], gStdFont, 255, 127, 0, 1);
2754 e_TextureFontPrintEx(x+8+w1, _y, _lc[I_GAME_FRAGS], gStdFont, 255, 127, 0, 1);
2755 e_TextureFontPrintEx(x+8+w1+w2, _y, _lc[I_GAME_DEATHS], gStdFont, 255, 127, 0, 1);
2757 _y := _y+24;
2758 for p := 0 to High(CustomStat.PlayerStat) do
2759 with CustomStat.PlayerStat[p] do
2760 begin
2761 e_DrawFillQuad(x+8, _y+4, x+24-1, _y+16+4-1, Color.R, Color.G, Color.B, 0);
2763 if Spectator then
2764 r := 127
2765 else
2766 r := 255;
2768 if (gPlayers[Num] <> nil) and (gPlayers[Num].FReady) then
2769 e_TextureFontPrintEx(x+8+16+8, _y+4, Name + ' *', gStdFont, r, r, r, 1, True)
2770 else
2771 e_TextureFontPrintEx(x+8+16+8, _y+4, Name, gStdFont, r, r, r, 1, True);
2772 e_TextureFontPrintEx(x+w1+8+16+8, _y+4, IntToStr(Frags), gStdFont, r, r, r, 1, True);
2773 e_TextureFontPrintEx(x+w1+w2+8+16+8, _y+4, IntToStr(Deaths), gStdFont, r, r, r, 1, True);
2774 _y := _y+24;
2775 end;
2776 end;
2777 end;
2779 procedure DrawSingleStat();
2780 var
2781 tm, key_x, val_x, y: Integer;
2782 w1, w2, h: Word;
2783 s1, s2: String;
2785 procedure player_stat(n: Integer);
2786 var
2787 kpm: Real;
2789 begin
2790 // "Kills: # / #":
2791 s1 := Format(' %d ', [SingleStat.PlayerStat[n].Kills]);
2792 s2 := Format(' %d', [gTotalMonsters]);
2794 e_CharFont_Print(gMenuFont, key_x, y, _lc[I_MENU_INTER_KILLS]);
2795 e_CharFont_PrintEx(gMenuFont, val_x, y, s1, _RGB(255, 0, 0));
2796 e_CharFont_GetSize(gMenuFont, s1, w1, h);
2797 e_CharFont_Print(gMenuFont, val_x+w1, y, '/');
2798 s1 := s1 + '/';
2799 e_CharFont_GetSize(gMenuFont, s1, w1, h);
2800 e_CharFont_PrintEx(gMenuFont, val_x+w1, y, s2, _RGB(255, 0, 0));
2802 // "Kills-per-minute: ##.#":
2803 s1 := _lc[I_MENU_INTER_KPM];
2804 if tm > 0 then
2805 kpm := (SingleStat.PlayerStat[n].Kills / tm) * 60
2806 else
2807 kpm := SingleStat.PlayerStat[n].Kills;
2808 s2 := Format(' %.1f', [kpm]);
2810 e_CharFont_Print(gMenuFont, key_x, y+32, s1);
2811 e_CharFont_PrintEx(gMenuFont, val_x, y+32, s2, _RGB(255, 0, 0));
2813 // "Secrets found: # / #":
2814 s1 := Format(' %d ', [SingleStat.PlayerStat[n].Secrets]);
2815 s2 := Format(' %d', [SingleStat.TotalSecrets]);
2817 e_CharFont_Print(gMenuFont, key_x, y+64, _lc[I_MENU_INTER_SECRETS]);
2818 e_CharFont_PrintEx(gMenuFont, val_x, y+64, s1, _RGB(255, 0, 0));
2819 e_CharFont_GetSize(gMenuFont, s1, w1, h);
2820 e_CharFont_Print(gMenuFont, val_x+w1, y+64, '/');
2821 s1 := s1 + '/';
2822 e_CharFont_GetSize(gMenuFont, s1, w1, h);
2823 e_CharFont_PrintEx(gMenuFont, val_x+w1, y+64, s2, _RGB(255, 0, 0));
2824 end;
2826 begin
2827 // "Level Complete":
2828 e_CharFont_GetSize(gMenuFont, _lc[I_MENU_INTER_LEVEL_COMPLETE], w1, h);
2829 e_CharFont_Print(gMenuFont, (gScreenWidth-w1) div 2, 32, _lc[I_MENU_INTER_LEVEL_COMPLETE]);
2831 // Îïðåäåëÿåì êîîðäèíàòû âûðàâíèâàíèÿ ïî ñàìîé äëèííîé ñòðîêå:
2832 s1 := _lc[I_MENU_INTER_KPM];
2833 e_CharFont_GetSize(gMenuFont, s1, w1, h);
2834 Inc(w1, 16);
2835 s1 := ' 9999.9';
2836 e_CharFont_GetSize(gMenuFont, s1, w2, h);
2838 key_x := (gScreenWidth-w1-w2) div 2;
2839 val_x := key_x + w1;
2841 // "Time: #:##:##":
2842 tm := SingleStat.GameTime div 1000;
2843 s1 := _lc[I_MENU_INTER_TIME];
2844 s2 := Format(' %d:%.2d:%.2d', [tm div (60*60), (tm mod (60*60)) div 60, tm mod 60]);
2846 e_CharFont_Print(gMenuFont, key_x, 80, s1);
2847 e_CharFont_PrintEx(gMenuFont, val_x, 80, s2, _RGB(255, 0, 0));
2849 if SingleStat.TwoPlayers then
2850 begin
2851 // "Player 1":
2852 s1 := _lc[I_MENU_PLAYER_1];
2853 e_CharFont_GetSize(gMenuFont, s1, w1, h);
2854 e_CharFont_Print(gMenuFont, (gScreenWidth-w1) div 2, 128, s1);
2856 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
2857 y := 176;
2858 player_stat(0);
2860 // "Player 2":
2861 s1 := _lc[I_MENU_PLAYER_2];
2862 e_CharFont_GetSize(gMenuFont, s1, w1, h);
2863 e_CharFont_Print(gMenuFont, (gScreenWidth-w1) div 2, 288, s1);
2865 // Ñòàòèñòèêà âòîðîãî èãðîêà:
2866 y := 336;
2867 player_stat(1);
2868 end
2869 else
2870 begin
2871 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
2872 y := 128;
2873 player_stat(0);
2874 end;
2875 end;
2877 procedure DrawLoadingStat();
2878 procedure drawRect (x, y, w, h: Integer);
2879 begin
2880 if (w < 1) or (h < 1) then exit;
2881 glBegin(GL_QUADS);
2882 glVertex2f(x+0.375, y+0.375);
2883 glVertex2f(x+w+0.375, y+0.375);
2884 glVertex2f(x+w+0.375, y+h+0.375);
2885 glVertex2f(x+0.375, y+h+0.375);
2886 glEnd();
2887 end;
2889 function drawPBar (cur, total: Integer; washere: Boolean): Boolean;
2890 var
2891 rectW, rectH: Integer;
2892 x0, y0: Integer;
2893 wdt: Integer;
2894 wl, hl: Integer;
2895 wr, hr: Integer;
2896 wb, hb: Integer;
2897 wm, hm: Integer;
2898 idl, idr, idb, idm: LongWord;
2899 f, my: Integer;
2900 begin
2901 result := false;
2902 if (total < 1) then exit;
2903 if (cur < 1) then exit; // don't blink
2904 if (not washere) and (cur >= total) then exit; // don't blink
2905 //if (cur < 0) then cur := 0;
2906 //if (cur > total) then cur := total;
2907 result := true;
2909 if (hasPBarGfx) then
2910 begin
2911 g_Texture_Get('UI_GFX_PBAR_LEFT', idl);
2912 g_Texture_GetSize('UI_GFX_PBAR_LEFT', wl, hl);
2913 g_Texture_Get('UI_GFX_PBAR_RIGHT', idr);
2914 g_Texture_GetSize('UI_GFX_PBAR_RIGHT', wr, hr);
2915 g_Texture_Get('UI_GFX_PBAR_MIDDLE', idb);
2916 g_Texture_GetSize('UI_GFX_PBAR_MIDDLE', wb, hb);
2917 g_Texture_Get('UI_GFX_PBAR_MARKER', idm);
2918 g_Texture_GetSize('UI_GFX_PBAR_MARKER', wm, hm);
2920 //rectW := gScreenWidth-360;
2921 rectW := trunc(624.0*gScreenWidth/1024.0);
2922 rectH := hl;
2924 x0 := (gScreenWidth-rectW) div 2;
2925 y0 := gScreenHeight-rectH-64;
2926 if (y0 < 2) then y0 := 2;
2928 glEnable(GL_SCISSOR_TEST);
2930 // left and right
2931 glScissor(x0, gScreenHeight-y0-rectH, rectW, rectH);
2932 e_DrawSize(idl, x0, y0, 0, true, false, wl, hl);
2933 e_DrawSize(idr, x0+rectW-wr, y0, 0, true, false, wr, hr);
2935 // body
2936 glScissor(x0+wl, gScreenHeight-y0-rectH, rectW-wl-wr, rectH);
2937 f := x0+wl;
2938 while (f < x0+rectW) do
2939 begin
2940 e_DrawSize(idb, f, y0, 0, true, false, wb, hb);
2941 f += wb;
2942 end;
2944 // filled part
2945 wdt := (rectW-wl-wr)*cur div total;
2946 if (wdt > rectW-wl-wr) then wdt := rectW-wr-wr;
2947 if (wdt > 0) then
2948 begin
2949 my := y0; // don't be so smart, ketmar: +(rectH-wm) div 2;
2950 glScissor(x0+wl, gScreenHeight-my-rectH, wdt, hm);
2951 f := x0+wl;
2952 while (wdt > 0) do
2953 begin
2954 e_DrawSize(idm, f, y0, 0, true, false, wm, hm);
2955 f += wm;
2956 wdt -= wm;
2957 end;
2958 end;
2960 glScissor(0, 0, gScreenWidth, gScreenHeight);
2961 end
2962 else
2963 begin
2964 rectW := gScreenWidth-64;
2965 rectH := 16;
2967 x0 := (gScreenWidth-rectW) div 2;
2968 y0 := gScreenHeight-rectH-64;
2969 if (y0 < 2) then y0 := 2;
2971 glDisable(GL_BLEND);
2972 glDisable(GL_TEXTURE_2D);
2974 //glClearColor(0, 0, 0, 0);
2975 //glClear(GL_COLOR_BUFFER_BIT);
2977 glColor4ub(127, 127, 127, 255);
2978 drawRect(x0-2, y0-2, rectW+4, rectH+4);
2980 glColor4ub(0, 0, 0, 255);
2981 drawRect(x0-1, y0-1, rectW+2, rectH+2);
2983 glColor4ub(127, 127, 127, 255);
2984 wdt := rectW*cur div total;
2985 if (wdt > rectW) then wdt := rectW;
2986 drawRect(x0, y0, wdt, rectH);
2987 end;
2988 end;
2990 var
2991 ww, hh: Word;
2992 xx, yy, i: Integer;
2993 s: String;
2994 begin
2995 if (Length(LoadingStat.Msgs) = 0) then exit;
2997 e_CharFont_GetSize(gMenuFont, _lc[I_MENU_LOADING], ww, hh);
2998 yy := (gScreenHeight div 3);
2999 e_CharFont_Print(gMenuFont, (gScreenWidth div 2)-(ww div 2), yy-2*hh, _lc[I_MENU_LOADING]);
3000 xx := (gScreenWidth div 3);
3002 with LoadingStat do
3003 begin
3004 for i := 0 to NextMsg-1 do
3005 begin
3006 if (i = (NextMsg-1)) and (MaxValue > 0) then
3007 s := Format('%s: %d/%d', [Msgs[i], CurValue, MaxValue])
3008 else
3009 s := Msgs[i];
3011 e_CharFont_PrintEx(gMenuSmallFont, xx, yy, s, _RGB(255, 0, 0));
3012 yy := yy + LOADING_INTERLINE;
3013 PBarWasHere := drawPBar(CurValue, MaxValue, PBarWasHere);
3014 end;
3015 end;
3016 end;
3018 procedure DrawMenuBackground(tex: AnsiString);
3019 var
3020 w, h: Word;
3021 ID: DWord;
3023 begin
3024 if g_Texture_Get(tex, ID) then
3025 begin
3026 e_Clear(GL_COLOR_BUFFER_BIT, 0, 0, 0);
3027 e_GetTextureSize(ID, @w, @h);
3028 if w = h then
3029 w := round(w * 1.333 * (gScreenHeight / h))
3030 else
3031 w := trunc(w * (gScreenHeight / h));
3032 e_DrawSize(ID, (gScreenWidth - w) div 2, 0, 0, False, False, w, gScreenHeight);
3033 end
3034 else e_Clear(GL_COLOR_BUFFER_BIT, 0, 0, 0);
3035 end;
3037 procedure DrawMinimap(p: TPlayer; RenderRect: e_graphics.TRect);
3038 var
3039 a, aX, aY, aX2, aY2, Scale, ScaleSz: Integer;
3041 function monDraw (mon: TMonster): Boolean;
3042 begin
3043 result := false; // don't stop
3044 with mon do
3045 begin
3046 if alive then
3047 begin
3048 // Ëåâûé âåðõíèé óãîë
3049 aX := Obj.X div ScaleSz + 1;
3050 aY := Obj.Y div ScaleSz + 1;
3051 // Ðàçìåðû
3052 aX2 := max(Obj.Rect.Width div ScaleSz, 1);
3053 aY2 := max(Obj.Rect.Height div ScaleSz, 1);
3054 // Ïðàâûé íèæíèé óãîë
3055 aX2 := aX + aX2 - 1;
3056 aY2 := aY + aY2 - 1;
3057 e_DrawFillQuad(aX, aY, aX2, aY2, 255, 255, 0, 0);
3058 end;
3059 end;
3060 end;
3062 begin
3063 if (gMapInfo.Width > RenderRect.Right - RenderRect.Left) or
3064 (gMapInfo.Height > RenderRect.Bottom - RenderRect.Top) then
3065 begin
3066 Scale := 1;
3067 // Ñêîëüêî ïèêñåëîâ êàðòû â 1 ïèêñåëå ìèíè-êàðòû:
3068 ScaleSz := 16 div Scale;
3069 // Ðàçìåðû ìèíè-êàðòû:
3070 aX := max(gMapInfo.Width div ScaleSz, 1);
3071 aY := max(gMapInfo.Height div ScaleSz, 1);
3072 // Ðàìêà êàðòû:
3073 e_DrawFillQuad(0, 0, aX-1, aY-1, 0, 0, 0, 0);
3075 if gWalls <> nil then
3076 begin
3077 // Ðèñóåì ñòåíû:
3078 for a := 0 to High(gWalls) do
3079 with gWalls[a] do
3080 if PanelType <> 0 then
3081 begin
3082 // Ëåâûé âåðõíèé óãîë:
3083 aX := X div ScaleSz;
3084 aY := Y div ScaleSz;
3085 // Ðàçìåðû:
3086 aX2 := max(Width div ScaleSz, 1);
3087 aY2 := max(Height div ScaleSz, 1);
3088 // Ïðàâûé íèæíèé óãîë:
3089 aX2 := aX + aX2 - 1;
3090 aY2 := aY + aY2 - 1;
3092 case PanelType of
3093 PANEL_WALL: e_DrawFillQuad(aX, aY, aX2, aY2, 208, 208, 208, 0);
3094 PANEL_OPENDOOR, PANEL_CLOSEDOOR:
3095 if Enabled then e_DrawFillQuad(aX, aY, aX2, aY2, 160, 160, 160, 0);
3096 end;
3097 end;
3098 end;
3099 if gSteps <> nil then
3100 begin
3101 // Ðèñóåì ñòóïåíè:
3102 for a := 0 to High(gSteps) do
3103 with gSteps[a] do
3104 if PanelType <> 0 then
3105 begin
3106 // Ëåâûé âåðõíèé óãîë:
3107 aX := X div ScaleSz;
3108 aY := Y div ScaleSz;
3109 // Ðàçìåðû:
3110 aX2 := max(Width div ScaleSz, 1);
3111 aY2 := max(Height div ScaleSz, 1);
3112 // Ïðàâûé íèæíèé óãîë:
3113 aX2 := aX + aX2 - 1;
3114 aY2 := aY + aY2 - 1;
3116 e_DrawFillQuad(aX, aY, aX2, aY2, 128, 128, 128, 0);
3117 end;
3118 end;
3119 if gLifts <> nil then
3120 begin
3121 // Ðèñóåì ëèôòû:
3122 for a := 0 to High(gLifts) do
3123 with gLifts[a] do
3124 if PanelType <> 0 then
3125 begin
3126 // Ëåâûé âåðõíèé óãîë:
3127 aX := X div ScaleSz;
3128 aY := Y div ScaleSz;
3129 // Ðàçìåðû:
3130 aX2 := max(Width div ScaleSz, 1);
3131 aY2 := max(Height div ScaleSz, 1);
3132 // Ïðàâûé íèæíèé óãîë:
3133 aX2 := aX + aX2 - 1;
3134 aY2 := aY + aY2 - 1;
3136 case LiftType of
3137 LIFTTYPE_UP: e_DrawFillQuad(aX, aY, aX2, aY2, 116, 72, 36, 0);
3138 LIFTTYPE_DOWN: e_DrawFillQuad(aX, aY, aX2, aY2, 116, 124, 96, 0);
3139 LIFTTYPE_LEFT: e_DrawFillQuad(aX, aY, aX2, aY2, 200, 80, 4, 0);
3140 LIFTTYPE_RIGHT: e_DrawFillQuad(aX, aY, aX2, aY2, 252, 140, 56, 0);
3141 end;
3142 end;
3143 end;
3144 if gWater <> nil then
3145 begin
3146 // Ðèñóåì âîäó:
3147 for a := 0 to High(gWater) do
3148 with gWater[a] do
3149 if PanelType <> 0 then
3150 begin
3151 // Ëåâûé âåðõíèé óãîë:
3152 aX := X div ScaleSz;
3153 aY := Y div ScaleSz;
3154 // Ðàçìåðû:
3155 aX2 := max(Width div ScaleSz, 1);
3156 aY2 := max(Height div ScaleSz, 1);
3157 // Ïðàâûé íèæíèé óãîë:
3158 aX2 := aX + aX2 - 1;
3159 aY2 := aY + aY2 - 1;
3161 e_DrawFillQuad(aX, aY, aX2, aY2, 0, 0, 192, 0);
3162 end;
3163 end;
3164 if gAcid1 <> nil then
3165 begin
3166 // Ðèñóåì êèñëîòó 1:
3167 for a := 0 to High(gAcid1) do
3168 with gAcid1[a] do
3169 if PanelType <> 0 then
3170 begin
3171 // Ëåâûé âåðõíèé óãîë:
3172 aX := X div ScaleSz;
3173 aY := Y div ScaleSz;
3174 // Ðàçìåðû:
3175 aX2 := max(Width div ScaleSz, 1);
3176 aY2 := max(Height div ScaleSz, 1);
3177 // Ïðàâûé íèæíèé óãîë:
3178 aX2 := aX + aX2 - 1;
3179 aY2 := aY + aY2 - 1;
3181 e_DrawFillQuad(aX, aY, aX2, aY2, 0, 176, 0, 0);
3182 end;
3183 end;
3184 if gAcid2 <> nil then
3185 begin
3186 // Ðèñóåì êèñëîòó 2:
3187 for a := 0 to High(gAcid2) do
3188 with gAcid2[a] do
3189 if PanelType <> 0 then
3190 begin
3191 // Ëåâûé âåðõíèé óãîë:
3192 aX := X div ScaleSz;
3193 aY := Y div ScaleSz;
3194 // Ðàçìåðû:
3195 aX2 := max(Width div ScaleSz, 1);
3196 aY2 := max(Height div ScaleSz, 1);
3197 // Ïðàâûé íèæíèé óãîë:
3198 aX2 := aX + aX2 - 1;
3199 aY2 := aY + aY2 - 1;
3201 e_DrawFillQuad(aX, aY, aX2, aY2, 176, 0, 0, 0);
3202 end;
3203 end;
3204 if gPlayers <> nil then
3205 begin
3206 // Ðèñóåì èãðîêîâ:
3207 for a := 0 to High(gPlayers) do
3208 if gPlayers[a] <> nil then with gPlayers[a] do
3209 if alive then begin
3210 // Ëåâûé âåðõíèé óãîë:
3211 aX := Obj.X div ScaleSz + 1;
3212 aY := Obj.Y div ScaleSz + 1;
3213 // Ðàçìåðû:
3214 aX2 := max(Obj.Rect.Width div ScaleSz, 1);
3215 aY2 := max(Obj.Rect.Height div ScaleSz, 1);
3216 // Ïðàâûé íèæíèé óãîë:
3217 aX2 := aX + aX2 - 1;
3218 aY2 := aY + aY2 - 1;
3220 if gPlayers[a] = p then
3221 e_DrawFillQuad(aX, aY, aX2, aY2, 0, 255, 0, 0)
3222 else
3223 case Team of
3224 TEAM_RED: e_DrawFillQuad(aX, aY, aX2, aY2, 255, 0, 0, 0);
3225 TEAM_BLUE: e_DrawFillQuad(aX, aY, aX2, aY2, 0, 0, 255, 0);
3226 else e_DrawFillQuad(aX, aY, aX2, aY2, 255, 128, 0, 0);
3227 end;
3228 end;
3229 end;
3230 // Ðèñóåì ìîíñòðîâ
3231 g_Mons_ForEach(monDraw);
3232 end;
3233 end;
3236 procedure renderAmbientQuad (hasAmbient: Boolean; constref ambColor: TDFColor);
3237 begin
3238 if not hasAmbient then exit;
3239 e_AmbientQuad(sX, sY, sWidth, sHeight, ambColor.r, ambColor.g, ambColor.b, ambColor.a);
3240 end;
3243 // setup sX, sY, sWidth, sHeight, and transformation matrix before calling this!
3244 //FIXME: broken for splitscreen mode
3245 procedure renderDynLightsInternal ();
3246 var
3247 //hasAmbient: Boolean;
3248 //ambColor: TDFColor;
3249 lln: Integer;
3250 lx, ly, lrad: Integer;
3251 scxywh: array[0..3] of GLint;
3252 wassc: Boolean;
3253 begin
3254 if e_NoGraphics then exit;
3256 //TODO: lights should be in separate grid, i think
3257 // but on the other side: grid may be slower for dynlights, as their lifetime is short
3258 if (not gwin_k8_enable_light_experiments) or (not gwin_has_stencil) or (g_dynLightCount < 1) then exit;
3260 // rendering mode
3261 //ambColor := gCurrentMap['light_ambient'].rgba;
3262 //hasAmbient := (not ambColor.isOpaque) or (not ambColor.isBlack);
3264 { // this will multiply incoming color to alpha from framebuffer
3265 glEnable(GL_BLEND);
3266 glBlendFunc(GL_DST_ALPHA, GL_ONE);
3269 (*
3270 * light rendering: (INVALID!)
3271 * glStencilFunc(GL_EQUAL, 0, $ff);
3272 * for each light:
3273 * glClear(GL_STENCIL_BUFFER_BIT);
3274 * glStencilOp(GL_KEEP, GL_KEEP, GL_INCR);
3275 * draw shadow volume into stencil buffer
3276 * glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); // modify color buffer
3277 * glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); // don't modify stencil buffer
3278 * turn off blending
3279 * draw color-less quad with light alpha (WARNING! don't touch color!)
3280 * glEnable(GL_BLEND);
3281 * glBlendFunc(GL_DST_ALPHA, GL_ONE);
3282 * draw all geometry up to and including walls (with alpha-testing, probably) -- this does lighting
3283 *)
3284 wassc := (glIsEnabled(GL_SCISSOR_TEST) <> 0);
3285 if wassc then glGetIntegerv(GL_SCISSOR_BOX, @scxywh[0]) else glGetIntegerv(GL_VIEWPORT, @scxywh[0]);
3287 // setup OpenGL parameters
3288 glStencilMask($FFFFFFFF);
3289 glStencilFunc(GL_ALWAYS, 0, $FFFFFFFF);
3290 glEnable(GL_STENCIL_TEST);
3291 glEnable(GL_SCISSOR_TEST);
3292 glClear(GL_STENCIL_BUFFER_BIT);
3293 glStencilFunc(GL_EQUAL, 0, $ff);
3295 for lln := 0 to g_dynLightCount-1 do
3296 begin
3297 lx := g_dynLights[lln].x;
3298 ly := g_dynLights[lln].y;
3299 lrad := g_dynLights[lln].radius;
3300 if (lrad < 3) then continue;
3302 if (lx-sX+lrad < 0) then continue;
3303 if (ly-sY+lrad < 0) then continue;
3304 if (lx-sX-lrad >= gPlayerScreenSize.X) then continue;
3305 if (ly-sY-lrad >= gPlayerScreenSize.Y) then continue;
3307 // set scissor to optimize drawing
3308 if (g_dbg_scale = 1.0) then
3309 begin
3310 glScissor((lx-sX)-lrad+2, gPlayerScreenSize.Y-(ly-sY)-lrad-1+2, lrad*2-4, lrad*2-4);
3311 end
3312 else
3313 begin
3314 glScissor(0, 0, gWinSizeX, gWinSizeY);
3315 end;
3316 // no need to clear stencil buffer, light blitting will do it for us... but only for normal scale
3317 if (g_dbg_scale <> 1.0) then glClear(GL_STENCIL_BUFFER_BIT);
3318 glStencilOp(GL_KEEP, GL_KEEP, GL_INCR);
3319 // draw extruded panels
3320 glDisable(GL_TEXTURE_2D);
3321 glDisable(GL_BLEND);
3322 glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); // no need to modify color buffer
3323 if (lrad > 4) then g_Map_DrawPanelShadowVolumes(lx, ly, lrad);
3324 // render light texture
3325 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); // modify color buffer
3326 glStencilOp(GL_ZERO, GL_ZERO, GL_ZERO); // draw light, and clear stencil buffer
3327 // blend it
3328 glEnable(GL_BLEND);
3329 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
3330 glEnable(GL_TEXTURE_2D);
3331 // color and opacity
3332 glColor4f(g_dynLights[lln].r, g_dynLights[lln].g, g_dynLights[lln].b, g_dynLights[lln].a);
3333 glBindTexture(GL_TEXTURE_2D, g_Texture_Light());
3334 glBegin(GL_QUADS);
3335 glTexCoord2f(0.0, 0.0); glVertex2i(lx-lrad, ly-lrad); // top-left
3336 glTexCoord2f(1.0, 0.0); glVertex2i(lx+lrad, ly-lrad); // top-right
3337 glTexCoord2f(1.0, 1.0); glVertex2i(lx+lrad, ly+lrad); // bottom-right
3338 glTexCoord2f(0.0, 1.0); glVertex2i(lx-lrad, ly+lrad); // bottom-left
3339 glEnd();
3340 end;
3342 // done
3343 glDisable(GL_STENCIL_TEST);
3344 glDisable(GL_BLEND);
3345 glDisable(GL_SCISSOR_TEST);
3346 //glScissor(0, 0, sWidth, sHeight);
3348 glScissor(scxywh[0], scxywh[1], scxywh[2], scxywh[3]);
3349 if wassc then glEnable(GL_SCISSOR_TEST) else glDisable(GL_SCISSOR_TEST);
3350 end;
3353 function fixViewportForScale (): Boolean;
3354 var
3355 nx0, ny0, nw, nh: Integer;
3356 begin
3357 result := false;
3358 if (g_dbg_scale <> 1.0) then
3359 begin
3360 result := true;
3361 nx0 := round(sX-(gPlayerScreenSize.X-(sWidth*g_dbg_scale))/2/g_dbg_scale);
3362 ny0 := round(sY-(gPlayerScreenSize.Y-(sHeight*g_dbg_scale))/2/g_dbg_scale);
3363 nw := round(sWidth/g_dbg_scale);
3364 nh := round(sHeight/g_dbg_scale);
3365 sX := nx0;
3366 sY := ny0;
3367 sWidth := nw;
3368 sHeight := nh;
3369 end;
3370 end;
3373 // setup sX, sY, sWidth, sHeight, and transformation matrix before calling this!
3374 // WARNING! this WILL CALL `glTranslatef()`, but won't restore matrices!
3375 procedure renderMapInternal (backXOfs, backYOfs: Integer; setTransMatrix: Boolean);
3376 type
3377 TDrawCB = procedure ();
3379 var
3380 hasAmbient: Boolean;
3381 ambColor: TDFColor;
3382 doAmbient: Boolean = false;
3384 procedure drawPanelType (profname: AnsiString; panType: DWord; doDraw: Boolean);
3385 var
3386 tagmask: Integer;
3387 pan: TPanel;
3388 begin
3389 if (profileFrameDraw <> nil) then profileFrameDraw.sectionBegin(profname);
3390 if gdbg_map_use_accel_render then
3391 begin
3392 tagmask := panelTypeToTag(panType);
3393 while (gDrawPanelList.count > 0) do
3394 begin
3395 pan := TPanel(gDrawPanelList.front());
3396 if ((pan.tag and tagmask) = 0) then break;
3397 if doDraw then pan.Draw(doAmbient, ambColor);
3398 gDrawPanelList.popFront();
3399 end;
3400 end
3401 else
3402 begin
3403 if doDraw then g_Map_DrawPanels(panType, hasAmbient, ambColor);
3404 end;
3405 if (profileFrameDraw <> nil) then profileFrameDraw.sectionEnd();
3406 end;
3408 procedure drawOther (profname: AnsiString; cb: TDrawCB);
3409 begin
3410 if (profileFrameDraw <> nil) then profileFrameDraw.sectionBegin(profname);
3411 if assigned(cb) then cb();
3412 if (profileFrameDraw <> nil) then profileFrameDraw.sectionEnd();
3413 end;
3415 begin
3416 if (profileFrameDraw <> nil) then profileFrameDraw.sectionBegin('total');
3418 // our accelerated renderer will collect all panels to gDrawPanelList
3419 // we can use panel tag to render level parts (see GridTagXXX in g_map.pas)
3420 if (profileFrameDraw <> nil) then profileFrameDraw.sectionBegin('collect');
3421 if gdbg_map_use_accel_render then
3422 begin
3423 g_Map_CollectDrawPanels(sX, sY, sWidth, sHeight);
3424 end;
3425 if (profileFrameDraw <> nil) then profileFrameDraw.sectionEnd();
3427 if (profileFrameDraw <> nil) then profileFrameDraw.sectionBegin('skyback');
3428 g_Map_DrawBack(backXOfs, backYOfs);
3429 if (profileFrameDraw <> nil) then profileFrameDraw.sectionEnd();
3431 if setTransMatrix then
3432 begin
3433 //if (g_dbg_scale <> 1.0) then glTranslatef(0.0, -0.375/2, 0);
3434 glScalef(g_dbg_scale, g_dbg_scale, 1.0);
3435 glTranslatef(-sX, -sY, 0);
3436 end;
3438 // rendering mode
3439 ambColor := gCurrentMap['light_ambient'].rgba;
3440 hasAmbient := (not ambColor.isOpaque) or (not ambColor.isBlack);
3443 if hasAmbient then
3444 begin
3445 //writeln('color: (', ambColor.r, ',', ambColor.g, ',', ambColor.b, ',', ambColor.a, ')');
3446 glColor4ub(ambColor.r, ambColor.g, ambColor.b, ambColor.a);
3447 glClear(GL_COLOR_BUFFER_BIT);
3448 end;
3450 //writeln('color: (', ambColor.r, ',', ambColor.g, ',', ambColor.b, ',', ambColor.a, ')');
3453 drawPanelType('*back', PANEL_BACK, g_rlayer_back);
3454 drawPanelType('*step', PANEL_STEP, g_rlayer_step);
3455 drawOther('items', @g_Items_Draw);
3456 drawOther('weapons', @g_Weapon_Draw);
3457 drawOther('shells', @g_Player_DrawShells);
3458 drawOther('drawall', @g_Player_DrawAll);
3459 drawOther('corpses', @g_Player_DrawCorpses);
3460 drawPanelType('*wall', PANEL_WALL, g_rlayer_wall);
3461 drawOther('monsters', @g_Monsters_Draw);
3462 drawOther('itemdrop', @g_Items_DrawDrop);
3463 drawPanelType('*door', PANEL_CLOSEDOOR, g_rlayer_door);
3464 drawOther('gfx', @g_GFX_Draw);
3465 drawOther('flags', @g_Map_DrawFlags);
3466 drawPanelType('*acid1', PANEL_ACID1, g_rlayer_acid1);
3467 drawPanelType('*acid2', PANEL_ACID2, g_rlayer_acid2);
3468 drawPanelType('*water', PANEL_WATER, g_rlayer_water);
3469 drawOther('dynlights', @renderDynLightsInternal);
3471 if hasAmbient {and ((not g_playerLight) or (not gwin_has_stencil) or (g_dynLightCount < 1))} then
3472 begin
3473 renderAmbientQuad(hasAmbient, ambColor);
3474 end;
3476 doAmbient := true;
3477 drawPanelType('*fore', PANEL_FORE, g_rlayer_fore);
3480 if g_debug_HealthBar then
3481 begin
3482 g_Monsters_DrawHealth();
3483 g_Player_DrawHealth();
3484 end;
3486 if (profileFrameDraw <> nil) then profileFrameDraw.mainEnd(); // map rendering
3487 end;
3490 procedure DrawMapView(x, y, w, h: Integer);
3492 var
3493 bx, by: Integer;
3494 begin
3495 glPushMatrix();
3497 bx := Round(x/(gMapInfo.Width - w)*(gBackSize.X - w));
3498 by := Round(y/(gMapInfo.Height - h)*(gBackSize.Y - h));
3500 sX := x;
3501 sY := y;
3502 sWidth := w;
3503 sHeight := h;
3505 fixViewportForScale();
3506 renderMapInternal(-bx, -by, true);
3508 glPopMatrix();
3509 end;
3512 procedure DrawPlayer(p: TPlayer);
3513 var
3514 px, py, a, b, c, d, i: Integer;
3515 //R: TRect;
3516 begin
3517 if (p = nil) or (p.FDummy) then
3518 begin
3519 glPushMatrix();
3520 g_Map_DrawBack(0, 0);
3521 glPopMatrix();
3522 Exit;
3523 end;
3525 if (profileFrameDraw = nil) then profileFrameDraw := TProfiler.Create('RENDER', g_profile_history_size);
3526 if (profileFrameDraw <> nil) then profileFrameDraw.mainBegin(g_profile_frame_draw);
3528 gPlayerDrawn := p;
3530 glPushMatrix();
3532 px := p.GameX + PLAYER_RECT_CX;
3533 py := p.GameY + PLAYER_RECT_CY+p.Obj.slopeUpLeft;
3535 if (g_dbg_scale = 1.0) and (not g_dbg_ignore_bounds) then
3536 begin
3537 if (px > (gPlayerScreenSize.X div 2)) then a := -px+(gPlayerScreenSize.X div 2) else a := 0;
3538 if (py > (gPlayerScreenSize.Y div 2)) then b := -py+(gPlayerScreenSize.Y div 2) else b := 0;
3540 if (px > gMapInfo.Width-(gPlayerScreenSize.X div 2)) then a := -gMapInfo.Width+gPlayerScreenSize.X;
3541 if (py > gMapInfo.Height-(gPlayerScreenSize.Y div 2)) then b := -gMapInfo.Height+gPlayerScreenSize.Y;
3543 if (gMapInfo.Width = gPlayerScreenSize.X) then a := 0
3544 else if (gMapInfo.Width < gPlayerScreenSize.X) then
3545 begin
3546 // hcenter
3547 a := (gPlayerScreenSize.X-gMapInfo.Width) div 2;
3548 end;
3550 if (gMapInfo.Height = gPlayerScreenSize.Y) then b := 0
3551 else if (gMapInfo.Height < gPlayerScreenSize.Y) then
3552 begin
3553 // vcenter
3554 b := (gPlayerScreenSize.Y-gMapInfo.Height) div 2;
3555 end;
3556 end
3557 else
3558 begin
3559 // scaled, ignore level bounds
3560 a := -px+(gPlayerScreenSize.X div 2);
3561 b := -py+(gPlayerScreenSize.Y div 2);
3562 end;
3564 if p.IncCam <> 0 then
3565 begin
3566 if py > gMapInfo.Height-(gPlayerScreenSize.Y div 2) then
3567 begin
3568 if p.IncCam > 120-(py-(gMapInfo.Height-(gPlayerScreenSize.Y div 2))) then
3569 begin
3570 p.IncCam := 120-(py-(gMapInfo.Height-(gPlayerScreenSize.Y div 2)));
3571 end;
3572 end;
3574 if py < gPlayerScreenSize.Y div 2 then
3575 begin
3576 if p.IncCam < -120+((gPlayerScreenSize.Y div 2)-py) then
3577 begin
3578 p.IncCam := -120+((gPlayerScreenSize.Y div 2)-py);
3579 end;
3580 end;
3582 if p.IncCam < 0 then
3583 begin
3584 while (py+(gPlayerScreenSize.Y div 2)-p.IncCam > gMapInfo.Height) and (p.IncCam < 0) do p.IncCam := p.IncCam+1; //Inc(p.IncCam);
3585 end;
3587 if p.IncCam > 0 then
3588 begin
3589 while (py-(gPlayerScreenSize.Y div 2)-p.IncCam < 0) and (p.IncCam > 0) do p.IncCam := p.IncCam-1; //Dec(p.IncCam);
3590 end;
3591 end;
3593 if (px < gPlayerScreenSize.X div 2) or (gMapInfo.Width-gPlayerScreenSize.X <= 256) then c := 0
3594 else if (px > gMapInfo.Width-(gPlayerScreenSize.X div 2)) then c := gBackSize.X-gPlayerScreenSize.X
3595 else c := round((px-(gPlayerScreenSize.X div 2))/(gMapInfo.Width-gPlayerScreenSize.X)*(gBackSize.X-gPlayerScreenSize.X));
3597 if (py-p.IncCam <= gPlayerScreenSize.Y div 2) or (gMapInfo.Height-gPlayerScreenSize.Y <= 256) then d := 0
3598 else if (py-p.IncCam >= gMapInfo.Height-(gPlayerScreenSize.Y div 2)) then d := gBackSize.Y-gPlayerScreenSize.Y
3599 else d := round((py-p.IncCam-(gPlayerScreenSize.Y div 2))/(gMapInfo.Height-gPlayerScreenSize.Y)*(gBackSize.Y-gPlayerScreenSize.Y));
3601 sX := -a;
3602 sY := -(b+p.IncCam);
3603 sWidth := gPlayerScreenSize.X;
3604 sHeight := gPlayerScreenSize.Y;
3606 //glTranslatef(a, b+p.IncCam, 0);
3608 //if (p = gPlayer1) and (g_dbg_scale >= 1.0) then g_Holmes_plrViewSize(sWidth, sHeight);
3610 //conwritefln('OLD: (%s,%s)-(%s,%s)', [sX, sY, sWidth, sHeight]);
3611 fixViewportForScale();
3612 //conwritefln(' (%s,%s)-(%s,%s)', [sX, sY, sWidth, sHeight]);
3614 if (g_dbg_scale <> 1.0) and (not g_dbg_ignore_bounds) then
3615 begin
3616 if (sX+sWidth > gMapInfo.Width) then sX := gMapInfo.Width-sWidth;
3617 if (sY+sHeight > gMapInfo.Height) then sY := gMapInfo.Height-sHeight;
3618 if (sX < 0) then sX := 0;
3619 if (sY < 0) then sY := 0;
3621 if (gBackSize.X <= gPlayerScreenSize.X) or (gMapInfo.Width <= sWidth) then c := 0 else c := trunc((gBackSize.X-gPlayerScreenSize.X)*sX/(gMapInfo.Width-sWidth));
3622 if (gBackSize.Y <= gPlayerScreenSize.Y) or (gMapInfo.Height <= sHeight) then d := 0 else d := trunc((gBackSize.Y-gPlayerScreenSize.Y)*sY/(gMapInfo.Height-sHeight));
3623 end;
3625 //r_smallmap_h: 0: left; 1: center; 2: right
3626 //r_smallmap_v: 0: top; 1: center; 2: bottom
3627 // horiz small map?
3628 if (gMapInfo.Width = sWidth) then
3629 begin
3630 sX := 0;
3631 end
3632 else if (gMapInfo.Width < sWidth) then
3633 begin
3634 case r_smallmap_h of
3635 1: sX := -((sWidth-gMapInfo.Width) div 2); // center
3636 2: sX := -(sWidth-gMapInfo.Width); // right
3637 else sX := 0; // left
3638 end;
3639 end;
3640 // vert small map?
3641 if (gMapInfo.Height = sHeight) then
3642 begin
3643 sY := 0;
3644 end
3645 else if (gMapInfo.Height < sHeight) then
3646 begin
3647 case r_smallmap_v of
3648 1: sY := -((sHeight-gMapInfo.Height) div 2); // center
3649 2: sY := -(sHeight-gMapInfo.Height); // bottom
3650 else sY := 0; // top
3651 end;
3652 end;
3654 p.viewPortX := sX;
3655 p.viewPortY := sY;
3656 p.viewPortW := sWidth;
3657 p.viewPortH := sHeight;
3659 {$IFDEF ENABLE_HOLMES}
3660 if (p = gPlayer1) then
3661 begin
3662 g_Holmes_plrViewPos(sX, sY);
3663 g_Holmes_plrViewSize(sWidth, sHeight);
3664 end;
3665 {$ENDIF}
3667 renderMapInternal(-c, -d, true);
3669 if (gGameSettings.GameMode <> GM_SINGLE) and (gPlayerIndicator > 0) then
3670 case gPlayerIndicator of
3671 1:
3672 p.DrawIndicator(_RGB(255, 255, 255));
3674 2:
3675 for i := 0 to High(gPlayers) do
3676 if gPlayers[i] <> nil then
3677 if gPlayers[i] = p then p.DrawIndicator(_RGB(255, 255, 255))
3678 else if (gPlayers[i].Team = p.Team) and (gPlayers[i].Team <> TEAM_NONE) then
3679 if gPlayerIndicatorStyle = 1 then
3680 gPlayers[i].DrawIndicator(_RGB(192, 192, 192))
3681 else gPlayers[i].DrawIndicator(gPlayers[i].GetColor);
3682 end;
3684 if p.FSpectator then
3685 e_TextureFontPrintEx(p.GameX + PLAYER_RECT_CX - 4,
3686 p.GameY + PLAYER_RECT_CY - 4,
3687 'X', gStdFont, 255, 255, 255, 1, True);
3689 for a := 0 to High(gCollideMap) do
3690 for b := 0 to High(gCollideMap[a]) do
3691 begin
3692 d := 0;
3693 if ByteBool(gCollideMap[a, b] and MARK_WALL) then
3694 d := d + 1;
3695 if ByteBool(gCollideMap[a, b] and MARK_DOOR) then
3696 d := d + 2;
3698 case d of
3699 1: e_DrawPoint(1, b, a, 200, 200, 200);
3700 2: e_DrawPoint(1, b, a, 64, 64, 255);
3701 3: e_DrawPoint(1, b, a, 255, 0, 255);
3702 end;
3703 end;
3706 glPopMatrix();
3708 p.DrawPain();
3709 p.DrawPickup();
3710 p.DrawRulez();
3711 if gShowMap then DrawMinimap(p, _TRect(0, 0, 128, 128));
3712 if g_Debug_Player then
3713 g_Player_DrawDebug(p);
3714 p.DrawGUI();
3715 end;
3717 procedure drawProfilers ();
3718 var
3719 px: Integer = -1;
3720 py: Integer = -1;
3721 begin
3722 if g_profile_frame_draw and (profileFrameDraw <> nil) then px := px-drawProfiles(px, py, profileFrameDraw);
3723 if g_profile_collision and (profMapCollision <> nil) then begin px := px-drawProfiles(px, py, profMapCollision); py -= calcProfilesHeight(profMonsLOS); end;
3724 if g_profile_los and (profMonsLOS <> nil) then begin px := px-drawProfiles(px, py, profMonsLOS); py -= calcProfilesHeight(profMonsLOS); end;
3725 end;
3727 procedure g_Game_Draw();
3728 var
3729 ID: DWORD;
3730 w, h: Word;
3731 ww, hh: Byte;
3732 Time: Int64;
3733 back: string;
3734 plView1, plView2: TPlayer;
3735 Split: Boolean;
3736 begin
3737 if gExit = EXIT_QUIT then Exit;
3739 Time := GetTimer() {div 1000};
3740 FPSCounter := FPSCounter+1;
3741 if Time - FPSTime >= 1000 then
3742 begin
3743 FPS := FPSCounter;
3744 FPSCounter := 0;
3745 FPSTime := Time;
3746 end;
3748 if gGameOn or (gState = STATE_FOLD) then
3749 begin
3750 if (gPlayer1 <> nil) and (gPlayer2 <> nil) then
3751 begin
3752 gSpectMode := SPECT_NONE;
3753 if not gRevertPlayers then
3754 begin
3755 plView1 := gPlayer1;
3756 plView2 := gPlayer2;
3757 end
3758 else
3759 begin
3760 plView1 := gPlayer2;
3761 plView2 := gPlayer1;
3762 end;
3763 end
3764 else
3765 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
3766 begin
3767 gSpectMode := SPECT_NONE;
3768 if gPlayer2 = nil then
3769 plView1 := gPlayer1
3770 else
3771 plView1 := gPlayer2;
3772 plView2 := nil;
3773 end
3774 else
3775 begin
3776 plView1 := nil;
3777 plView2 := nil;
3778 end;
3780 if (plView1 = nil) and (plView2 = nil) and (gSpectMode = SPECT_NONE) then
3781 gSpectMode := SPECT_STATS;
3783 if gSpectMode = SPECT_PLAYERS then
3784 if gPlayers <> nil then
3785 begin
3786 plView1 := GetActivePlayer_ByID(gSpectPID1);
3787 if plView1 = nil then
3788 begin
3789 gSpectPID1 := GetActivePlayerID_Next();
3790 plView1 := GetActivePlayer_ByID(gSpectPID1);
3791 end;
3792 if gSpectViewTwo then
3793 begin
3794 plView2 := GetActivePlayer_ByID(gSpectPID2);
3795 if plView2 = nil then
3796 begin
3797 gSpectPID2 := GetActivePlayerID_Next();
3798 plView2 := GetActivePlayer_ByID(gSpectPID2);
3799 end;
3800 end;
3801 end;
3803 if gSpectMode = SPECT_MAPVIEW then
3804 begin
3805 // Ðåæèì ïðîñìîòðà êàðòû
3806 Split := False;
3807 e_SetViewPort(0, 0, gScreenWidth, gScreenHeight);
3808 DrawMapView(gSpectX, gSpectY, gScreenWidth, gScreenHeight);
3809 gHearPoint1.Active := True;
3810 gHearPoint1.Coords.X := gScreenWidth div 2 + gSpectX;
3811 gHearPoint1.Coords.Y := gScreenHeight div 2 + gSpectY;
3812 gHearPoint2.Active := False;
3813 end
3814 else
3815 begin
3816 Split := (plView1 <> nil) and (plView2 <> nil);
3818 // Òî÷êè ñëóõà èãðîêîâ
3819 if plView1 <> nil then
3820 begin
3821 gHearPoint1.Active := True;
3822 gHearPoint1.Coords.X := plView1.GameX + PLAYER_RECT.Width;
3823 gHearPoint1.Coords.Y := plView1.GameY + PLAYER_RECT.Height DIV 2;
3824 end else
3825 gHearPoint1.Active := False;
3826 if plView2 <> nil then
3827 begin
3828 gHearPoint2.Active := True;
3829 gHearPoint2.Coords.X := plView2.GameX + PLAYER_RECT.Width;
3830 gHearPoint2.Coords.Y := plView2.GameY + PLAYER_RECT.Height DIV 2;
3831 end else
3832 gHearPoint2.Active := False;
3834 // Ðàçìåð ýêðàíîâ èãðîêîâ:
3835 gPlayerScreenSize.X := gScreenWidth-196;
3836 if Split then
3837 begin
3838 gPlayerScreenSize.Y := gScreenHeight div 2;
3839 if gScreenHeight mod 2 = 0 then
3840 Dec(gPlayerScreenSize.Y);
3841 end
3842 else
3843 gPlayerScreenSize.Y := gScreenHeight;
3845 if Split then
3846 if gScreenHeight mod 2 = 0 then
3847 e_SetViewPort(0, gPlayerScreenSize.Y+2, gPlayerScreenSize.X+196, gPlayerScreenSize.Y)
3848 else
3849 e_SetViewPort(0, gPlayerScreenSize.Y+1, gPlayerScreenSize.X+196, gPlayerScreenSize.Y);
3851 DrawPlayer(plView1);
3852 gPlayer1ScreenCoord.X := sX;
3853 gPlayer1ScreenCoord.Y := sY;
3855 if Split then
3856 begin
3857 e_SetViewPort(0, 0, gPlayerScreenSize.X+196, gPlayerScreenSize.Y);
3859 DrawPlayer(plView2);
3860 gPlayer2ScreenCoord.X := sX;
3861 gPlayer2ScreenCoord.Y := sY;
3862 end;
3864 e_SetViewPort(0, 0, gScreenWidth, gScreenHeight);
3866 if Split then
3867 e_DrawLine(2, 0, gScreenHeight div 2, gScreenWidth, gScreenHeight div 2, 0, 0, 0);
3868 end;
3870 {$IFDEF ENABLE_HOLMES}
3871 // draw inspector
3872 if (g_holmes_enabled) then g_Holmes_Draw();
3873 {$ENDIF}
3875 if MessageText <> '' then
3876 begin
3877 w := 0;
3878 h := 0;
3879 e_CharFont_GetSizeFmt(gMenuFont, MessageText, w, h);
3880 if Split then
3881 e_CharFont_PrintFmt(gMenuFont, (gScreenWidth div 2)-(w div 2),
3882 (gScreenHeight div 2)-(h div 2), MessageText)
3883 else
3884 e_CharFont_PrintFmt(gMenuFont, (gScreenWidth div 2)-(w div 2),
3885 Round(gScreenHeight / 2.75)-(h div 2), MessageText);
3886 end;
3888 if IsDrawStat or (gSpectMode = 1) then DrawStat();
3890 if gSpectHUD and (not gChatShow) and (gSpectMode <> SPECT_NONE) and (not gSpectAuto) then
3891 begin
3892 // Draw spectator GUI
3893 ww := 0;
3894 hh := 0;
3895 e_TextureFontGetSize(gStdFont, ww, hh);
3896 case gSpectMode of
3897 SPECT_STATS:
3898 e_TextureFontPrintEx(0, gScreenHeight - (hh+2)*2, 'MODE: Stats', gStdFont, 255, 255, 255, 1);
3899 SPECT_MAPVIEW:
3900 e_TextureFontPrintEx(0, gScreenHeight - (hh+2)*2, 'MODE: Observe Map', gStdFont, 255, 255, 255, 1);
3901 SPECT_PLAYERS:
3902 e_TextureFontPrintEx(0, gScreenHeight - (hh+2)*2, 'MODE: Watch Players', gStdFont, 255, 255, 255, 1);
3903 end;
3904 e_TextureFontPrintEx(2*ww, gScreenHeight - (hh+2), '< jump >', gStdFont, 255, 255, 255, 1);
3905 if gSpectMode = SPECT_STATS then
3906 begin
3907 e_TextureFontPrintEx(16*ww, gScreenHeight - (hh+2)*2, 'Autoview', gStdFont, 255, 255, 255, 1);
3908 e_TextureFontPrintEx(16*ww, gScreenHeight - (hh+2), '< fire >', gStdFont, 255, 255, 255, 1);
3909 end;
3910 if gSpectMode = SPECT_MAPVIEW then
3911 begin
3912 e_TextureFontPrintEx(22*ww, gScreenHeight - (hh+2)*2, '[-]', gStdFont, 255, 255, 255, 1);
3913 e_TextureFontPrintEx(26*ww, gScreenHeight - (hh+2)*2, 'Step ' + IntToStr(gSpectStep), gStdFont, 255, 255, 255, 1);
3914 e_TextureFontPrintEx(34*ww, gScreenHeight - (hh+2)*2, '[+]', gStdFont, 255, 255, 255, 1);
3915 e_TextureFontPrintEx(18*ww, gScreenHeight - (hh+2), '<prev weap>', gStdFont, 255, 255, 255, 1);
3916 e_TextureFontPrintEx(30*ww, gScreenHeight - (hh+2), '<next weap>', gStdFont, 255, 255, 255, 1);
3917 end;
3918 if gSpectMode = SPECT_PLAYERS then
3919 begin
3920 e_TextureFontPrintEx(22*ww, gScreenHeight - (hh+2)*2, 'Player 1', gStdFont, 255, 255, 255, 1);
3921 e_TextureFontPrintEx(20*ww, gScreenHeight - (hh+2), '<left/right>', gStdFont, 255, 255, 255, 1);
3922 if gSpectViewTwo then
3923 begin
3924 e_TextureFontPrintEx(37*ww, gScreenHeight - (hh+2)*2, 'Player 2', gStdFont, 255, 255, 255, 1);
3925 e_TextureFontPrintEx(34*ww, gScreenHeight - (hh+2), '<prev w/next w>', gStdFont, 255, 255, 255, 1);
3926 e_TextureFontPrintEx(52*ww, gScreenHeight - (hh+2)*2, '2x View', gStdFont, 255, 255, 255, 1);
3927 e_TextureFontPrintEx(51*ww, gScreenHeight - (hh+2), '<up/down>', gStdFont, 255, 255, 255, 1);
3928 end
3929 else
3930 begin
3931 e_TextureFontPrintEx(35*ww, gScreenHeight - (hh+2)*2, '2x View', gStdFont, 255, 255, 255, 1);
3932 e_TextureFontPrintEx(34*ww, gScreenHeight - (hh+2), '<up/down>', gStdFont, 255, 255, 255, 1);
3933 end;
3934 end;
3935 end;
3936 end;
3938 if gPauseMain and gGameOn and (g_ActiveWindow = nil) then
3939 begin
3940 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
3941 e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
3943 e_CharFont_GetSize(gMenuFont, _lc[I_MENU_PAUSE], w, h);
3944 e_CharFont_Print(gMenuFont, (gScreenWidth div 2)-(w div 2),
3945 (gScreenHeight div 2)-(h div 2), _lc[I_MENU_PAUSE]);
3946 end;
3948 if not gGameOn then
3949 begin
3950 if (gState = STATE_MENU) then
3951 begin
3952 if (g_ActiveWindow = nil) or (g_ActiveWindow.BackTexture = '') then DrawMenuBackground('MENU_BACKGROUND');
3953 // F3 at menu will show game loading dialog
3954 if e_KeyPressed(IK_F3) then g_Menu_Show_LoadMenu(true);
3955 if (g_ActiveWindow <> nil) then
3956 begin
3957 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
3958 e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
3959 end
3960 else
3961 begin
3962 // F3 at titlepic will show game loading dialog
3963 if e_KeyPressed(IK_F3) then
3964 begin
3965 g_Menu_Show_LoadMenu(true);
3966 if (g_ActiveWindow <> nil) then e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
3967 end;
3968 end;
3969 end;
3971 if gState = STATE_FOLD then
3972 begin
3973 e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 0, 0, 0, EndingGameCounter);
3974 end;
3976 if gState = STATE_INTERCUSTOM then
3977 begin
3978 if gLastMap and (gGameSettings.GameMode = GM_COOP) then
3979 begin
3980 back := 'TEXTURE_endpic';
3981 if not g_Texture_Get(back, ID) then
3982 back := _lc[I_TEXTURE_ENDPIC];
3983 end
3984 else
3985 back := 'INTER';
3987 DrawMenuBackground(back);
3989 DrawCustomStat();
3991 if g_ActiveWindow <> nil then
3992 begin
3993 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
3994 e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
3995 end;
3996 end;
3998 if gState = STATE_INTERSINGLE then
3999 begin
4000 if EndingGameCounter > 0 then
4001 begin
4002 e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 0, 0, 0, EndingGameCounter);
4003 end
4004 else
4005 begin
4006 back := 'INTER';
4008 DrawMenuBackground(back);
4010 DrawSingleStat();
4012 if g_ActiveWindow <> nil then
4013 begin
4014 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4015 e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
4016 end;
4017 end;
4018 end;
4020 if gState = STATE_ENDPIC then
4021 begin
4022 ID := DWORD(-1);
4023 if g_Texture_Get('TEXTURE_endpic', ID) then DrawMenuBackground('TEXTURE_endpic')
4024 else DrawMenuBackground(_lc[I_TEXTURE_ENDPIC]);
4026 if g_ActiveWindow <> nil then
4027 begin
4028 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4029 e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
4030 end;
4031 end;
4033 if gState = STATE_SLIST then
4034 begin
4035 // if g_Texture_Get('MENU_BACKGROUND', ID) then
4036 // begin
4037 // e_DrawSize(ID, 0, 0, 0, False, False, gScreenWidth, gScreenHeight);
4038 // //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4039 // end;
4040 DrawMenuBackground('MENU_BACKGROUND');
4041 e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
4042 g_Serverlist_Draw(slCurrent, slTable);
4043 end;
4044 end;
4046 if g_ActiveWindow <> nil then
4047 begin
4048 if gGameOn then
4049 begin
4050 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4051 e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
4052 end;
4053 g_ActiveWindow.Draw();
4054 end;
4056 {$IFNDEF HEADLESS}
4057 g_Console_Draw();
4058 {$ENDIF}
4060 if g_debug_Sounds and gGameOn then
4061 begin
4062 for w := 0 to High(e_SoundsArray) do
4063 for h := 0 to e_SoundsArray[w].nRefs do
4064 e_DrawPoint(1, w+100, h+100, 255, 0, 0);
4065 end;
4067 if gShowFPS then
4068 begin
4069 e_TextureFontPrint(0, 0, Format('FPS: %d', [FPS]), gStdFont);
4070 e_TextureFontPrint(0, 16, Format('UPS: %d', [UPS]), gStdFont);
4071 end;
4073 if gGameOn and gShowTime then
4074 drawTime(gScreenWidth-72, gScreenHeight-16);
4076 if gGameOn then drawProfilers();
4078 {$IFDEF ENABLE_HOLMES}
4079 g_Holmes_DrawUI();
4080 {$ENDIF}
4082 g_Touch_Draw;
4083 end;
4085 procedure g_Game_Quit();
4086 begin
4087 g_Game_StopAllSounds(True);
4088 gMusic.Free();
4089 g_Game_SaveOptions();
4090 g_Game_FreeData();
4091 g_PlayerModel_FreeData();
4092 g_Texture_DeleteAll();
4093 g_Frames_DeleteAll();
4094 {$IFNDEF HEADLESS}
4095 //g_Menu_Free(); //k8: this segfaults after resolution change; who cares?
4096 {$ENDIF}
4098 if NetInitDone then g_Net_Free;
4100 // Íàäî óäàëèòü êàðòó ïîñëå òåñòà:
4101 if gMapToDelete <> '' then
4102 g_Game_DeleteTestMap();
4104 gExit := EXIT_QUIT;
4105 PushExitEvent();
4106 end;
4108 procedure g_FatalError(Text: String);
4109 begin
4110 g_Console_Add(Format(_lc[I_FATAL_ERROR], [Text]), True);
4111 e_WriteLog(Format(_lc[I_FATAL_ERROR], [Text]), TMsgType.Warning);
4113 gExit := EXIT_SIMPLE;
4114 end;
4116 procedure g_SimpleError(Text: String);
4117 begin
4118 g_Console_Add(Format(_lc[I_SIMPLE_ERROR], [Text]), True);
4119 e_WriteLog(Format(_lc[I_SIMPLE_ERROR], [Text]), TMsgType.Warning);
4120 end;
4122 procedure g_Game_SetupScreenSize();
4123 const
4124 RES_FACTOR = 4.0 / 3.0;
4125 var
4126 s: Single;
4127 rf: Single;
4128 bw, bh: Word;
4129 begin
4130 // Ðàçìåð ýêðàíîâ èãðîêîâ:
4131 gPlayerScreenSize.X := gScreenWidth-196;
4132 if (gPlayer1 <> nil) and (gPlayer2 <> nil) then
4133 gPlayerScreenSize.Y := gScreenHeight div 2
4134 else
4135 gPlayerScreenSize.Y := gScreenHeight;
4137 // Ðàçìåð çàäíåãî ïëàíà:
4138 if BackID <> DWORD(-1) then
4139 begin
4140 s := SKY_STRETCH;
4141 if (gScreenWidth*s > gMapInfo.Width) or
4142 (gScreenHeight*s > gMapInfo.Height) then
4143 begin
4144 gBackSize.X := gScreenWidth;
4145 gBackSize.Y := gScreenHeight;
4146 end
4147 else
4148 begin
4149 e_GetTextureSize(BackID, @bw, @bh);
4150 rf := Single(bw) / Single(bh);
4151 if (rf > RES_FACTOR) then bw := Round(Single(bh) * RES_FACTOR)
4152 else if (rf < RES_FACTOR) then bh := Round(Single(bw) / RES_FACTOR);
4153 s := Max(gScreenWidth / bw, gScreenHeight / bh);
4154 if (s < 1.0) then s := 1.0;
4155 gBackSize.X := Round(bw*s);
4156 gBackSize.Y := Round(bh*s);
4157 end;
4158 end;
4159 end;
4161 procedure g_Game_ChangeResolution(newWidth, newHeight: Word; nowFull, nowMax: Boolean);
4162 begin
4163 g_Window_SetSize(newWidth, newHeight, nowFull);
4164 end;
4166 procedure g_Game_AddPlayer(Team: Byte = TEAM_NONE);
4167 begin
4168 if ((not gGameOn) and (gState <> STATE_INTERCUSTOM))
4169 or (not (gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT])) then
4170 Exit;
4171 if gPlayer1 = nil then
4172 begin
4173 if g_Game_IsClient then
4174 begin
4175 if NetPlrUID1 > -1 then
4176 begin
4177 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE);
4178 gPlayer1 := g_Player_Get(NetPlrUID1);
4179 end;
4180 Exit;
4181 end;
4183 if not (Team in [TEAM_RED, TEAM_BLUE]) then
4184 Team := gPlayer1Settings.Team;
4186 // Ñîçäàíèå ïåðâîãî èãðîêà:
4187 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
4188 gPlayer1Settings.Color,
4189 Team, False));
4190 if gPlayer1 = nil then
4191 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]))
4192 else
4193 begin
4194 gPlayer1.Name := gPlayer1Settings.Name;
4195 g_Console_Add(Format(_lc[I_PLAYER_JOIN], [gPlayer1.Name]), True);
4196 if g_Game_IsServer and g_Game_IsNet then
4197 MH_SEND_PlayerCreate(gPlayer1.UID);
4198 gPlayer1.Respawn(False, True);
4200 if g_Game_IsNet and NetUseMaster then
4201 g_Net_Slist_Update;
4202 end;
4204 Exit;
4205 end;
4206 if gPlayer2 = nil then
4207 begin
4208 if g_Game_IsClient then
4209 begin
4210 if NetPlrUID2 > -1 then
4211 gPlayer2 := g_Player_Get(NetPlrUID2);
4212 Exit;
4213 end;
4215 if not (Team in [TEAM_RED, TEAM_BLUE]) then
4216 Team := gPlayer2Settings.Team;
4218 // Ñîçäàíèå âòîðîãî èãðîêà:
4219 gPlayer2 := g_Player_Get(g_Player_Create(gPlayer2Settings.Model,
4220 gPlayer2Settings.Color,
4221 Team, False));
4222 if gPlayer2 = nil then
4223 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [2]))
4224 else
4225 begin
4226 gPlayer2.Name := gPlayer2Settings.Name;
4227 g_Console_Add(Format(_lc[I_PLAYER_JOIN], [gPlayer2.Name]), True);
4228 if g_Game_IsServer and g_Game_IsNet then
4229 MH_SEND_PlayerCreate(gPlayer2.UID);
4230 gPlayer2.Respawn(False, True);
4232 if g_Game_IsNet and NetUseMaster then
4233 g_Net_Slist_Update;
4234 end;
4236 Exit;
4237 end;
4238 end;
4240 procedure g_Game_RemovePlayer();
4241 var
4242 Pl: TPlayer;
4243 begin
4244 if ((not gGameOn) and (gState <> STATE_INTERCUSTOM))
4245 or (not (gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT])) then
4246 Exit;
4247 Pl := gPlayer2;
4248 if Pl <> nil then
4249 begin
4250 if g_Game_IsServer then
4251 begin
4252 Pl.Lives := 0;
4253 Pl.Kill(K_SIMPLEKILL, 0, HIT_DISCON);
4254 g_Console_Add(Format(_lc[I_PLAYER_LEAVE], [Pl.Name]), True);
4255 g_Player_Remove(Pl.UID);
4257 if g_Game_IsNet and NetUseMaster then
4258 g_Net_Slist_Update;
4259 end else
4260 gPlayer2 := nil;
4261 Exit;
4262 end;
4263 Pl := gPlayer1;
4264 if Pl <> nil then
4265 begin
4266 if g_Game_IsServer then
4267 begin
4268 Pl.Lives := 0;
4269 Pl.Kill(K_SIMPLEKILL, 0, HIT_DISCON);
4270 g_Console_Add(Format(_lc[I_PLAYER_LEAVE], [Pl.Name]), True);
4271 g_Player_Remove(Pl.UID);
4273 if g_Game_IsNet and NetUseMaster then
4274 g_Net_Slist_Update;
4275 end else
4276 begin
4277 gPlayer1 := nil;
4278 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE);
4279 end;
4280 Exit;
4281 end;
4282 end;
4284 procedure g_Game_Spectate();
4285 begin
4286 g_Game_RemovePlayer();
4287 if gPlayer1 <> nil then
4288 g_Game_RemovePlayer();
4289 end;
4291 procedure g_Game_SpectateCenterView();
4292 begin
4293 gSpectX := Max(gMapInfo.Width div 2 - gScreenWidth div 2, 0);
4294 gSpectY := Max(gMapInfo.Height div 2 - gScreenHeight div 2, 0);
4295 end;
4297 procedure g_Game_StartSingle(Map: String; TwoPlayers: Boolean; nPlayers: Byte);
4298 var
4299 i, nPl: Integer;
4300 tmps: AnsiString;
4301 begin
4302 g_Game_Free();
4304 e_WriteLog('Starting singleplayer game...', TMsgType.Notify);
4306 g_Game_ClearLoading();
4308 // Íàñòðîéêè èãðû:
4309 FillByte(gGameSettings, SizeOf(TGameSettings), 0);
4310 gAimLine := False;
4311 gShowMap := False;
4312 gGameSettings.GameType := GT_SINGLE;
4313 gGameSettings.MaxLives := 0;
4314 gGameSettings.Options := gGameSettings.Options + GAME_OPTION_ALLOWEXIT;
4315 gGameSettings.Options := gGameSettings.Options + GAME_OPTION_MONSTERS;
4316 gGameSettings.Options := gGameSettings.Options + GAME_OPTION_BOTVSMONSTER;
4317 gSwitchGameMode := GM_SINGLE;
4319 g_Game_ExecuteEvent('ongamestart');
4321 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
4322 g_Game_SetupScreenSize();
4324 // Ñîçäàíèå ïåðâîãî èãðîêà:
4325 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
4326 gPlayer1Settings.Color,
4327 gPlayer1Settings.Team, False));
4328 if gPlayer1 = nil then
4329 begin
4330 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]));
4331 Exit;
4332 end;
4334 gPlayer1.Name := gPlayer1Settings.Name;
4335 nPl := 1;
4337 // Ñîçäàíèå âòîðîãî èãðîêà, åñëè åñòü:
4338 if TwoPlayers then
4339 begin
4340 gPlayer2 := g_Player_Get(g_Player_Create(gPlayer2Settings.Model,
4341 gPlayer2Settings.Color,
4342 gPlayer2Settings.Team, False));
4343 if gPlayer2 = nil then
4344 begin
4345 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [2]));
4346 Exit;
4347 end;
4349 gPlayer2.Name := gPlayer2Settings.Name;
4350 Inc(nPl);
4351 end;
4353 // Çàãðóçêà è çàïóñê êàðòû:
4354 if not g_Game_StartMap(MAP, True) then
4355 begin
4356 if (Pos(':\', Map) > 0) or (Pos(':/', Map) > 0) then tmps := Map else tmps := gGameSettings.WAD + ':\' + MAP;
4357 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [tmps]));
4358 Exit;
4359 end;
4361 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4362 g_Player_Init();
4364 // Ñîçäàåì áîòîâ:
4365 for i := nPl+1 to nPlayers do
4366 g_Player_Create(STD_PLAYER_MODEL, _RGB(0, 0, 0), 0, True);
4367 end;
4369 procedure g_Game_StartCustom(Map: String; GameMode: Byte;
4370 TimeLimit, GoalLimit: Word;
4371 MaxLives: Byte;
4372 Options: LongWord; nPlayers: Byte);
4373 var
4374 i, nPl: Integer;
4375 begin
4376 g_Game_Free();
4378 e_WriteLog('Starting custom game...', TMsgType.Notify);
4380 g_Game_ClearLoading();
4382 // Íàñòðîéêè èãðû:
4383 gGameSettings.GameType := GT_CUSTOM;
4384 gGameSettings.GameMode := GameMode;
4385 gSwitchGameMode := GameMode;
4386 gGameSettings.TimeLimit := TimeLimit;
4387 gGameSettings.GoalLimit := GoalLimit;
4388 gGameSettings.MaxLives := IfThen(GameMode = GM_CTF, 0, MaxLives);
4389 gGameSettings.Options := Options;
4391 gCoopTotalMonstersKilled := 0;
4392 gCoopTotalSecretsFound := 0;
4393 gCoopTotalMonsters := 0;
4394 gCoopTotalSecrets := 0;
4395 gAimLine := False;
4396 gShowMap := False;
4398 g_Game_ExecuteEvent('ongamestart');
4400 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
4401 g_Game_SetupScreenSize();
4403 // Ðåæèì íàáëþäàòåëÿ:
4404 if nPlayers = 0 then
4405 begin
4406 gPlayer1 := nil;
4407 gPlayer2 := nil;
4408 end;
4410 nPl := 0;
4411 if nPlayers >= 1 then
4412 begin
4413 // Ñîçäàíèå ïåðâîãî èãðîêà:
4414 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
4415 gPlayer1Settings.Color,
4416 gPlayer1Settings.Team, False));
4417 if gPlayer1 = nil then
4418 begin
4419 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]));
4420 Exit;
4421 end;
4423 gPlayer1.Name := gPlayer1Settings.Name;
4424 Inc(nPl);
4425 end;
4427 if nPlayers >= 2 then
4428 begin
4429 // Ñîçäàíèå âòîðîãî èãðîêà:
4430 gPlayer2 := g_Player_Get(g_Player_Create(gPlayer2Settings.Model,
4431 gPlayer2Settings.Color,
4432 gPlayer2Settings.Team, False));
4433 if gPlayer2 = nil then
4434 begin
4435 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [2]));
4436 Exit;
4437 end;
4439 gPlayer2.Name := gPlayer2Settings.Name;
4440 Inc(nPl);
4441 end;
4443 // Çàãðóçêà è çàïóñê êàðòû:
4444 if not g_Game_StartMap(Map, True) then
4445 begin
4446 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [Map]));
4447 Exit;
4448 end;
4450 // Íåò òî÷åê ïîÿâëåíèÿ:
4451 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1) +
4452 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2) +
4453 g_Map_GetPointCount(RESPAWNPOINT_DM) +
4454 g_Map_GetPointCount(RESPAWNPOINT_RED)+
4455 g_Map_GetPointCount(RESPAWNPOINT_BLUE)) < 1 then
4456 begin
4457 g_FatalError(_lc[I_GAME_ERROR_GET_SPAWN]);
4458 Exit;
4459 end;
4461 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4462 g_Player_Init();
4464 // Ñîçäàåì áîòîâ:
4465 for i := nPl+1 to nPlayers do
4466 g_Player_Create(STD_PLAYER_MODEL, _RGB(0, 0, 0), 0, True);
4467 end;
4469 procedure g_Game_StartServer(Map: String; GameMode: Byte;
4470 TimeLimit, GoalLimit: Word; MaxLives: Byte;
4471 Options: LongWord; nPlayers: Byte;
4472 IPAddr: LongWord; Port: Word);
4473 begin
4474 g_Game_Free();
4476 e_WriteLog('Starting net game (server)...', TMsgType.Notify);
4478 g_Game_ClearLoading();
4480 // Íàñòðîéêè èãðû:
4481 gGameSettings.GameType := GT_SERVER;
4482 gGameSettings.GameMode := GameMode;
4483 gSwitchGameMode := GameMode;
4484 gGameSettings.TimeLimit := TimeLimit;
4485 gGameSettings.GoalLimit := GoalLimit;
4486 gGameSettings.MaxLives := IfThen(GameMode = GM_CTF, 0, MaxLives);
4487 gGameSettings.Options := Options;
4489 gCoopTotalMonstersKilled := 0;
4490 gCoopTotalSecretsFound := 0;
4491 gCoopTotalMonsters := 0;
4492 gCoopTotalSecrets := 0;
4493 gAimLine := False;
4494 gShowMap := False;
4496 g_Game_ExecuteEvent('ongamestart');
4498 // Óñòàíîâêà ðàçìåðîâ îêíà èãðîêà
4499 g_Game_SetupScreenSize();
4501 // Ðåæèì íàáëþäàòåëÿ:
4502 if nPlayers = 0 then
4503 begin
4504 gPlayer1 := nil;
4505 gPlayer2 := nil;
4506 end;
4508 if nPlayers >= 1 then
4509 begin
4510 // Ñîçäàíèå ïåðâîãî èãðîêà:
4511 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
4512 gPlayer1Settings.Color,
4513 gPlayer1Settings.Team, False));
4514 if gPlayer1 = nil then
4515 begin
4516 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]));
4517 Exit;
4518 end;
4520 gPlayer1.Name := gPlayer1Settings.Name;
4521 end;
4523 if nPlayers >= 2 then
4524 begin
4525 // Ñîçäàíèå âòîðîãî èãðîêà:
4526 gPlayer2 := g_Player_Get(g_Player_Create(gPlayer2Settings.Model,
4527 gPlayer2Settings.Color,
4528 gPlayer2Settings.Team, False));
4529 if gPlayer2 = nil then
4530 begin
4531 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [2]));
4532 Exit;
4533 end;
4535 gPlayer2.Name := gPlayer2Settings.Name;
4536 end;
4538 g_Game_SetLoadingText(_lc[I_LOAD_HOST], 0, False);
4539 if NetForwardPorts then
4540 g_Game_SetLoadingText(_lc[I_LOAD_PORTS], 0, False);
4542 // Ñòàðòóåì ñåðâåð
4543 if not g_Net_Host(IPAddr, Port, NetMaxClients) then
4544 begin
4545 g_FatalError(_lc[I_NET_MSG] + _lc[I_NET_ERR_HOST]);
4546 Exit;
4547 end;
4549 g_Net_Slist_Set(NetSlistIP, NetSlistPort);
4551 // Çàãðóçêà è çàïóñê êàðòû:
4552 if not g_Game_StartMap(Map, True) then
4553 begin
4554 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [Map]));
4555 Exit;
4556 end;
4558 // Íåò òî÷åê ïîÿâëåíèÿ:
4559 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1) +
4560 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2) +
4561 g_Map_GetPointCount(RESPAWNPOINT_DM) +
4562 g_Map_GetPointCount(RESPAWNPOINT_RED)+
4563 g_Map_GetPointCount(RESPAWNPOINT_BLUE)) < 1 then
4564 begin
4565 g_FatalError(_lc[I_GAME_ERROR_GET_SPAWN]);
4566 Exit;
4567 end;
4569 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4570 g_Player_Init();
4572 NetState := NET_STATE_GAME;
4573 end;
4575 procedure g_Game_StartClient(Addr: String; Port: Word; PW: String);
4576 var
4577 Map: String;
4578 WadName: string;
4579 Ptr: Pointer;
4580 T: Cardinal;
4581 MID: Byte;
4582 State: Byte;
4583 OuterLoop: Boolean;
4584 newResPath: string;
4585 InMsg: TMsg;
4586 begin
4587 g_Game_Free();
4589 State := 0;
4590 e_WriteLog('Starting net game (client)...', TMsgType.Notify);
4591 e_WriteLog('NET: Trying to connect to ' + Addr + ':' + IntToStr(Port) + '...', TMsgType.Notify);
4593 g_Game_ClearLoading();
4595 // Íàñòðîéêè èãðû:
4596 gGameSettings.GameType := GT_CLIENT;
4598 gCoopTotalMonstersKilled := 0;
4599 gCoopTotalSecretsFound := 0;
4600 gCoopTotalMonsters := 0;
4601 gCoopTotalSecrets := 0;
4602 gAimLine := False;
4603 gShowMap := False;
4605 g_Game_ExecuteEvent('ongamestart');
4607 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
4608 g_Game_SetupScreenSize();
4610 NetState := NET_STATE_AUTH;
4612 g_Game_SetLoadingText(_lc[I_LOAD_CONNECT], 0, False);
4613 // Ñòàðòóåì êëèåíò
4614 if not g_Net_Connect(Addr, Port) then
4615 begin
4616 g_FatalError(_lc[I_NET_MSG] + _lc[I_NET_ERR_CONN]);
4617 NetState := NET_STATE_NONE;
4618 Exit;
4619 end;
4621 g_Game_SetLoadingText(_lc[I_LOAD_SEND_INFO], 0, False);
4622 MC_SEND_Info(PW);
4623 g_Game_SetLoadingText(_lc[I_LOAD_WAIT_INFO], 0, False);
4625 OuterLoop := True;
4626 while OuterLoop do
4627 begin
4628 while (enet_host_service(NetHost, @NetEvent, 50) > 0) do
4629 begin
4630 if (NetEvent.kind = ENET_EVENT_TYPE_RECEIVE) then
4631 begin
4632 Ptr := NetEvent.packet^.data;
4633 if not InMsg.Init(Ptr, NetEvent.packet^.dataLength, True) then
4634 continue;
4636 InMsg.ReadLongWord(); // skip size
4637 MID := InMsg.ReadByte();
4639 if (MID = NET_MSG_INFO) and (State = 0) then
4640 begin
4641 NetMyID := InMsg.ReadByte();
4642 NetPlrUID1 := InMsg.ReadWord();
4644 WadName := InMsg.ReadString();
4645 Map := InMsg.ReadString();
4647 gWADHash := InMsg.ReadMD5();
4649 gGameSettings.GameMode := InMsg.ReadByte();
4650 gSwitchGameMode := gGameSettings.GameMode;
4651 gGameSettings.GoalLimit := InMsg.ReadWord();
4652 gGameSettings.TimeLimit := InMsg.ReadWord();
4653 gGameSettings.MaxLives := InMsg.ReadByte();
4654 gGameSettings.Options := InMsg.ReadLongWord();
4655 T := InMsg.ReadLongWord();
4657 newResPath := g_Res_SearchSameWAD(MapsDir, WadName, gWADHash);
4658 if newResPath = '' then
4659 begin
4660 g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
4661 newResPath := g_Res_DownloadMapWAD(WadName, gWADHash);
4662 if newResPath = '' then
4663 begin
4664 g_FatalError(_lc[I_NET_ERR_HASH]);
4665 enet_packet_destroy(NetEvent.packet);
4666 NetState := NET_STATE_NONE;
4667 Exit;
4668 end;
4669 end;
4670 newResPath := ExtractRelativePath(MapsDir, newResPath);
4672 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
4673 gPlayer1Settings.Color,
4674 gPlayer1Settings.Team, False));
4676 if gPlayer1 = nil then
4677 begin
4678 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]));
4680 enet_packet_destroy(NetEvent.packet);
4681 NetState := NET_STATE_NONE;
4682 Exit;
4683 end;
4685 gPlayer1.Name := gPlayer1Settings.Name;
4686 gPlayer1.UID := NetPlrUID1;
4687 gPlayer1.Reset(True);
4689 if not g_Game_StartMap(newResPath + ':\' + Map, True) then
4690 begin
4691 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [WadName + ':\' + Map]));
4693 enet_packet_destroy(NetEvent.packet);
4694 NetState := NET_STATE_NONE;
4695 Exit;
4696 end;
4698 gTime := T;
4700 State := 1;
4701 OuterLoop := False;
4702 enet_packet_destroy(NetEvent.packet);
4703 break;
4704 end
4705 else
4706 enet_packet_destroy(NetEvent.packet);
4707 end
4708 else
4709 begin
4710 if (NetEvent.kind = ENET_EVENT_TYPE_DISCONNECT) then
4711 begin
4712 State := 0;
4713 if (NetEvent.data <= NET_DISC_MAX) then
4714 g_Console_Add(_lc[I_NET_MSG_ERROR] + _lc[I_NET_ERR_CONN] + ' ' +
4715 _lc[TStrings_Locale(Cardinal(I_NET_DISC_NONE) + NetEvent.data)], True);
4716 OuterLoop := False;
4717 Break;
4718 end;
4719 end;
4720 end;
4722 ProcessLoading(true);
4724 if g_Net_UserRequestExit() then
4725 begin
4726 State := 0;
4727 break;
4728 end;
4729 end;
4731 if State <> 1 then
4732 begin
4733 g_FatalError(_lc[I_NET_MSG] + _lc[I_NET_ERR_CONN]);
4734 NetState := NET_STATE_NONE;
4735 Exit;
4736 end;
4738 gLMSRespawn := LMS_RESPAWN_NONE;
4739 gLMSRespawnTime := 0;
4741 g_Player_Init();
4742 NetState := NET_STATE_GAME;
4743 MC_SEND_FullStateRequest;
4744 e_WriteLog('NET: Connection successful.', TMsgType.Notify);
4745 end;
4747 procedure g_Game_SaveOptions();
4748 begin
4749 g_Options_Write_Video(GameDir+'/'+CONFIG_FILENAME);
4750 end;
4752 procedure g_Game_ChangeMap(const MapPath: String);
4753 var
4754 Force: Boolean;
4755 begin
4756 g_Game_ClearLoading();
4758 Force := gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF];
4759 // Åñëè óðîâåíü çàâåðøèëñÿ ïî òðèããåðó Âûõîä, íå î÷èùàòü èíâåíòàðü
4760 if gExitByTrigger then
4761 begin
4762 Force := False;
4763 gExitByTrigger := False;
4764 end;
4765 if not g_Game_StartMap(MapPath, Force) then
4766 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [MapPath]));
4767 end;
4769 procedure g_Game_Restart();
4770 var
4771 Map: string;
4772 begin
4773 if g_Game_IsClient then
4774 Exit;
4775 map := g_ExtractFileName(gMapInfo.Map);
4777 MessageTime := 0;
4778 gGameOn := False;
4779 g_Game_ClearLoading();
4780 g_Game_StartMap(Map, True, gCurrentMapFileName);
4781 end;
4783 function g_Game_StartMap(Map: String; Force: Boolean = False; const oldMapPath: AnsiString=''): Boolean;
4784 var
4785 NewWAD, ResName: String;
4786 I: Integer;
4787 nws: AnsiString;
4788 begin
4789 g_Map_Free((Map <> gCurrentMapFileName) and (oldMapPath <> gCurrentMapFileName));
4790 g_Player_RemoveAllCorpses();
4792 if (not g_Game_IsClient) and
4793 (gSwitchGameMode <> gGameSettings.GameMode) and
4794 (gGameSettings.GameMode <> GM_SINGLE) then
4795 begin
4796 if gSwitchGameMode = GM_CTF then
4797 gGameSettings.MaxLives := 0;
4798 gGameSettings.GameMode := gSwitchGameMode;
4799 Force := True;
4800 end else
4801 gSwitchGameMode := gGameSettings.GameMode;
4803 g_Player_ResetTeams();
4805 if isWadPath(Map) then
4806 begin
4807 NewWAD := g_ExtractWadName(Map);
4808 ResName := g_ExtractFileName(Map);
4809 if g_Game_IsServer then
4810 begin
4811 nws := findDiskWad(MapsDir+NewWAD);
4812 if (length(nws) = 0) then
4813 begin
4814 ResName := '';
4815 end
4816 else
4817 begin
4818 gWADHash := MD5File(nws);
4819 //writeln('********: nws=', nws, ' : Map=', Map, ' : nw=', NewWAD, ' : resname=', ResName);
4820 g_Game_LoadWAD(NewWAD);
4821 end;
4822 end else
4823 // hash received in MC_RECV_GameEvent -> NET_EV_MAPSTART
4824 g_Game_ClientWAD(NewWAD, gWADHash);
4825 end else
4826 ResName := Map;
4828 //writeln('********: gsw=', gGameSettings.WAD, '; rn=', ResName);
4829 Result := (ResName <> '') and g_Map_Load(MapsDir + gGameSettings.WAD + ':\' + ResName);
4830 if Result then
4831 begin
4832 g_Player_ResetAll(Force or gLastMap, gGameSettings.GameType = GT_SINGLE);
4834 gState := STATE_NONE;
4835 g_ActiveWindow := nil;
4836 gGameOn := True;
4838 DisableCheats();
4839 ResetTimer();
4841 if gGameSettings.GameMode = GM_CTF then
4842 begin
4843 g_Map_ResetFlag(FLAG_RED);
4844 g_Map_ResetFlag(FLAG_BLUE);
4845 // CTF, à ôëàãîâ íåò:
4846 if not g_Map_HaveFlagPoints() then
4847 g_SimpleError(_lc[I_GAME_ERROR_CTF]);
4848 end;
4849 end
4850 else
4851 begin
4852 gState := STATE_MENU;
4853 gGameOn := False;
4854 end;
4856 gExit := 0;
4857 gPauseMain := false;
4858 gPauseHolmes := false;
4859 gTime := 0;
4860 NetTimeToUpdate := 1;
4861 NetTimeToReliable := 0;
4862 NetTimeToMaster := NetMasterRate;
4863 gLMSRespawn := LMS_RESPAWN_NONE;
4864 gLMSRespawnTime := 0;
4865 gMissionFailed := False;
4866 gNextMap := '';
4868 gCoopMonstersKilled := 0;
4869 gCoopSecretsFound := 0;
4871 gVoteInProgress := False;
4872 gVotePassed := False;
4873 gVoteCount := 0;
4874 gVoted := False;
4876 gStatsOff := False;
4878 if not gGameOn then Exit;
4880 g_Game_SpectateCenterView();
4882 if (gGameSettings.MaxLives > 0) and (gGameSettings.WarmupTime > 0) then
4883 begin
4884 gLMSRespawn := LMS_RESPAWN_WARMUP;
4885 gLMSRespawnTime := gTime + gGameSettings.WarmupTime*1000;
4886 gLMSSoftSpawn := True;
4887 if NetMode = NET_SERVER then
4888 MH_SEND_GameEvent(NET_EV_LMS_WARMUP, (gLMSRespawnTime - gTime) div 1000)
4889 else
4890 g_Console_Add(Format(_lc[I_MSG_WARMUP_START], [(gLMSRespawnTime - gTime) div 1000]), True);
4891 end;
4893 if NetMode = NET_SERVER then
4894 begin
4895 MH_SEND_GameEvent(NET_EV_MAPSTART, gGameSettings.GameMode, Map);
4897 // Ìàñòåðñåðâåð
4898 if NetUseMaster then
4899 begin
4900 if (NetMHost = nil) or (NetMPeer = nil) then
4901 begin
4902 // let the connection be blocking here, why not?
4903 g_Net_Slist_Connect();
4904 end;
4905 g_Net_Slist_Update;
4906 end;
4908 if NetClients <> nil then
4909 for I := 0 to High(NetClients) do
4910 if NetClients[I].Used then
4911 begin
4912 NetClients[I].Voted := False;
4913 if NetClients[I].RequestedFullUpdate then
4914 begin
4915 MH_SEND_Everything((NetClients[I].State = NET_STATE_AUTH), I);
4916 NetClients[I].RequestedFullUpdate := False;
4917 end;
4918 end;
4920 g_Net_UnbanNonPermHosts();
4921 end;
4923 if gLastMap then
4924 begin
4925 gCoopTotalMonstersKilled := 0;
4926 gCoopTotalSecretsFound := 0;
4927 gCoopTotalMonsters := 0;
4928 gCoopTotalSecrets := 0;
4929 gLastMap := False;
4930 end;
4932 g_Game_ExecuteEvent('onmapstart');
4933 end;
4935 procedure SetFirstLevel();
4936 begin
4937 gNextMap := '';
4939 MapList := g_Map_GetMapsList(MapsDir + gGameSettings.WAD);
4940 if MapList = nil then
4941 Exit;
4943 SortSArray(MapList);
4944 gNextMap := MapList[Low(MapList)];
4946 MapList := nil;
4947 end;
4949 procedure g_Game_ExitLevel(const Map: AnsiString);
4950 begin
4951 gNextMap := Map;
4953 gCoopTotalMonstersKilled := gCoopTotalMonstersKilled + gCoopMonstersKilled;
4954 gCoopTotalSecretsFound := gCoopTotalSecretsFound + gCoopSecretsFound;
4955 gCoopTotalMonsters := gCoopTotalMonsters + gTotalMonsters;
4956 gCoopTotalSecrets := gCoopTotalSecrets + gSecretsCount;
4958 // Âûøëè â âûõîä â Îäèíî÷íîé èãðå:
4959 if gGameSettings.GameType = GT_SINGLE then
4960 gExit := EXIT_ENDLEVELSINGLE
4961 else // Âûøëè â âûõîä â Ñâîåé èãðå
4962 begin
4963 gExit := EXIT_ENDLEVELCUSTOM;
4964 if gGameSettings.GameMode = GM_COOP then
4965 g_Player_RememberAll;
4967 if not g_Map_Exist(MapsDir + gGameSettings.WAD + ':\' + gNextMap) then
4968 begin
4969 gLastMap := True;
4970 if gGameSettings.GameMode = GM_COOP then
4971 gStatsOff := True;
4973 gStatsPressed := True;
4974 gNextMap := 'MAP01';
4976 if not g_Map_Exist(MapsDir + gGameSettings.WAD + ':\' + gNextMap) then
4977 g_Game_NextLevel;
4979 if g_Game_IsNet then
4980 begin
4981 MH_SEND_GameStats();
4982 MH_SEND_CoopStats();
4983 end;
4984 end;
4985 end;
4986 end;
4988 procedure g_Game_RestartLevel();
4989 var
4990 Map: string;
4991 begin
4992 if gGameSettings.GameMode = GM_SINGLE then
4993 begin
4994 g_Game_Restart();
4995 Exit;
4996 end;
4997 gExit := EXIT_ENDLEVELCUSTOM;
4998 Map := g_ExtractFileName(gMapInfo.Map);
4999 gNextMap := Map;
5000 end;
5002 procedure g_Game_ClientWAD(NewWAD: String; const WHash: TMD5Digest);
5003 var
5004 gWAD: String;
5005 begin
5006 if LowerCase(NewWAD) = LowerCase(gGameSettings.WAD) then
5007 Exit;
5008 if not g_Game_IsClient then
5009 Exit;
5010 gWAD := g_Res_SearchSameWAD(MapsDir, ExtractFileName(NewWAD), WHash);
5011 if gWAD = '' then
5012 begin
5013 g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
5014 gWAD := g_Res_DownloadMapWAD(ExtractFileName(NewWAD), WHash);
5015 if gWAD = '' then
5016 begin
5017 g_Game_Free();
5018 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_WAD], [ExtractFileName(NewWAD)]));
5019 Exit;
5020 end;
5021 end;
5022 NewWAD := ExtractRelativePath(MapsDir, gWAD);
5023 g_Game_LoadWAD(NewWAD);
5024 end;
5026 procedure g_Game_RestartRound(NoMapRestart: Boolean = False);
5027 var
5028 i, n, nb, nr: Integer;
5030 function monRespawn (mon: TMonster): Boolean;
5031 begin
5032 result := false; // don't stop
5033 if not mon.FNoRespawn then mon.Respawn();
5034 end;
5036 begin
5037 if not g_Game_IsServer then Exit;
5038 if gLMSRespawn = LMS_RESPAWN_NONE then Exit;
5039 gLMSRespawn := LMS_RESPAWN_NONE;
5040 gLMSRespawnTime := 0;
5041 MessageTime := 0;
5043 if (gGameSettings.GameMode = GM_COOP) and not NoMapRestart then
5044 begin
5045 gMissionFailed := True;
5046 g_Game_RestartLevel;
5047 Exit;
5048 end;
5050 n := 0; nb := 0; nr := 0;
5051 for i := Low(gPlayers) to High(gPlayers) do
5052 if (gPlayers[i] <> nil) and
5053 ((not gPlayers[i].FSpectator) or gPlayers[i].FWantsInGame or
5054 (gPlayers[i] is TBot)) then
5055 begin
5056 Inc(n);
5057 if gPlayers[i].Team = TEAM_RED then Inc(nr)
5058 else if gPlayers[i].Team = TEAM_BLUE then Inc(nb)
5059 end;
5061 if (n < 2) or ((gGameSettings.GameMode = GM_TDM) and ((nr = 0) or (nb = 0))) then
5062 begin
5063 // wait a second until the fuckers finally decide to join
5064 gLMSRespawn := LMS_RESPAWN_WARMUP;
5065 gLMSRespawnTime := gTime + 1000;
5066 gLMSSoftSpawn := NoMapRestart;
5067 Exit;
5068 end;
5070 g_Player_RemoveAllCorpses;
5071 g_Game_Message(_lc[I_MESSAGE_LMS_START], 144);
5072 if g_Game_IsNet then
5073 MH_SEND_GameEvent(NET_EV_LMS_START);
5075 for i := Low(gPlayers) to High(gPlayers) do
5076 begin
5077 if gPlayers[i] = nil then continue;
5078 if gPlayers[i] is TBot then gPlayers[i].FWantsInGame := True;
5079 // don't touch normal spectators
5080 if gPlayers[i].FSpectator and not gPlayers[i].FWantsInGame then
5081 begin
5082 gPlayers[i].FNoRespawn := True;
5083 gPlayers[i].Lives := 0;
5084 if g_Game_IsNet then
5085 MH_SEND_PlayerStats(gPlayers[I].UID);
5086 continue;
5087 end;
5088 gPlayers[i].FNoRespawn := False;
5089 gPlayers[i].Lives := gGameSettings.MaxLives;
5090 gPlayers[i].Respawn(False, True);
5091 if gGameSettings.GameMode = GM_COOP then
5092 begin
5093 gPlayers[i].Frags := 0;
5094 gPlayers[i].RecallState;
5095 end;
5096 if (gPlayer1 = nil) and (gLMSPID1 > 0) then
5097 gPlayer1 := g_Player_Get(gLMSPID1);
5098 if (gPlayer2 = nil) and (gLMSPID2 > 0) then
5099 gPlayer2 := g_Player_Get(gLMSPID2);
5100 end;
5102 g_Items_RestartRound();
5105 g_Mons_ForEach(monRespawn);
5107 gLMSSoftSpawn := False;
5108 end;
5110 function g_Game_GetFirstMap(WAD: String): String;
5111 begin
5112 Result := '';
5114 MapList := g_Map_GetMapsList(WAD);
5115 if MapList = nil then
5116 Exit;
5118 SortSArray(MapList);
5119 Result := MapList[Low(MapList)];
5121 if not g_Map_Exist(WAD + ':\' + Result) then
5122 Result := '';
5124 MapList := nil;
5125 end;
5127 function g_Game_GetNextMap(): String;
5128 var
5129 I: Integer;
5130 Map: string;
5131 begin
5132 Result := '';
5134 MapList := g_Map_GetMapsList(MapsDir + gGameSettings.WAD);
5135 if MapList = nil then
5136 Exit;
5138 Map := g_ExtractFileName(gMapInfo.Map);
5140 SortSArray(MapList);
5141 MapIndex := -255;
5142 for I := Low(MapList) to High(MapList) do
5143 if Map = MapList[I] then
5144 begin
5145 MapIndex := I;
5146 Break;
5147 end;
5149 if MapIndex <> -255 then
5150 begin
5151 if MapIndex = High(MapList) then
5152 Result := MapList[Low(MapList)]
5153 else
5154 Result := MapList[MapIndex + 1];
5156 if not g_Map_Exist(MapsDir + gGameSettings.WAD + ':\' + Result) then Result := Map;
5157 end;
5159 MapList := nil;
5160 end;
5162 procedure g_Game_NextLevel();
5163 begin
5164 if gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF, GM_COOP] then
5165 gExit := EXIT_ENDLEVELCUSTOM
5166 else
5167 begin
5168 gExit := EXIT_ENDLEVELSINGLE;
5169 Exit;
5170 end;
5172 if gNextMap <> '' then Exit;
5173 gNextMap := g_Game_GetNextMap();
5174 end;
5176 function g_Game_IsTestMap(): Boolean;
5177 begin
5178 result := StrEquCI1251(TEST_MAP_NAME, g_ExtractFileName(gMapInfo.Map));
5179 end;
5181 procedure g_Game_DeleteTestMap();
5182 var
5183 a: Integer;
5184 //MapName: AnsiString;
5185 WadName: string;
5187 WAD: TWADFile;
5188 MapList: SSArray;
5189 time: Integer;
5191 begin
5192 a := Pos('.wad:\', toLowerCase1251(gMapToDelete));
5193 if (a = 0) then a := Pos('.wad:/', toLowerCase1251(gMapToDelete));
5194 if (a = 0) then exit;
5196 // Âûäåëÿåì èìÿ wad-ôàéëà è èìÿ êàðòû
5197 WadName := Copy(gMapToDelete, 1, a+3);
5198 Delete(gMapToDelete, 1, a+5);
5199 gMapToDelete := UpperCase(gMapToDelete);
5200 //MapName := '';
5201 //CopyMemory(@MapName[0], @gMapToDelete[1], Min(16, Length(gMapToDelete)));
5204 // Èìÿ êàðòû íå ñòàíäàðòíîå òåñòîâîå:
5205 if MapName <> TEST_MAP_NAME then
5206 Exit;
5208 if not gTempDelete then
5209 begin
5210 time := g_GetFileTime(WadName);
5211 WAD := TWADFile.Create();
5213 // ×èòàåì Wad-ôàéë:
5214 if not WAD.ReadFile(WadName) then
5215 begin // Íåò òàêîãî WAD-ôàéëà
5216 WAD.Free();
5217 Exit;
5218 end;
5220 // Ñîñòàâëÿåì ñïèñîê êàðò è èùåì íóæíóþ:
5221 WAD.CreateImage();
5222 MapList := WAD.GetResourcesList('');
5224 if MapList <> nil then
5225 for a := 0 to High(MapList) do
5226 if MapList[a] = MapName then
5227 begin
5228 // Óäàëÿåì è ñîõðàíÿåì:
5229 WAD.RemoveResource('', MapName);
5230 WAD.SaveTo(WadName);
5231 Break;
5232 end;
5234 WAD.Free();
5235 g_SetFileTime(WadName, time);
5236 end else
5238 if gTempDelete then DeleteFile(WadName);
5239 end;
5241 procedure GameCVars(P: SSArray);
5242 var
5243 a, b: Integer;
5244 stat: TPlayerStatArray;
5245 cmd, s: string;
5246 config: TConfig;
5247 begin
5248 stat := nil;
5249 cmd := LowerCase(P[0]);
5250 if (cmd = 'g_friendlyfire') and not g_Game_IsClient then
5251 begin
5252 with gGameSettings do
5253 begin
5254 if (Length(P) > 1) and
5255 ((P[1] = '1') or (P[1] = '0')) then
5256 begin
5257 if (P[1][1] = '1') then
5258 Options := Options or GAME_OPTION_TEAMDAMAGE
5259 else
5260 Options := Options and (not GAME_OPTION_TEAMDAMAGE);
5261 end;
5263 if (LongBool(Options and GAME_OPTION_TEAMDAMAGE)) then
5264 g_Console_Add(_lc[I_MSG_FRIENDLY_FIRE_ON])
5265 else
5266 g_Console_Add(_lc[I_MSG_FRIENDLY_FIRE_OFF]);
5268 if g_Game_IsNet then MH_SEND_GameSettings;
5269 end;
5270 end
5271 else if (cmd = 'g_weaponstay') and not g_Game_IsClient then
5272 begin
5273 with gGameSettings do
5274 begin
5275 if (Length(P) > 1) and
5276 ((P[1] = '1') or (P[1] = '0')) then
5277 begin
5278 if (P[1][1] = '1') then
5279 Options := Options or GAME_OPTION_WEAPONSTAY
5280 else
5281 Options := Options and (not GAME_OPTION_WEAPONSTAY);
5282 end;
5284 if (LongBool(Options and GAME_OPTION_WEAPONSTAY)) then
5285 g_Console_Add(_lc[I_MSG_WEAPONSTAY_ON])
5286 else
5287 g_Console_Add(_lc[I_MSG_WEAPONSTAY_OFF]);
5289 if g_Game_IsNet then MH_SEND_GameSettings;
5290 end;
5291 end
5292 else if cmd = 'g_gamemode' then
5293 begin
5294 a := g_Game_TextToMode(P[1]);
5295 if a = GM_SINGLE then a := GM_COOP;
5296 if (Length(P) > 1) and (a <> GM_NONE) and (not g_Game_IsClient) then
5297 begin
5298 gSwitchGameMode := a;
5299 if (gGameOn and (gGameSettings.GameMode = GM_SINGLE)) or
5300 (gState = STATE_INTERSINGLE) then
5301 gSwitchGameMode := GM_SINGLE;
5302 if not gGameOn then
5303 gGameSettings.GameMode := gSwitchGameMode;
5304 end;
5305 if gSwitchGameMode = gGameSettings.GameMode then
5306 g_Console_Add(Format(_lc[I_MSG_GAMEMODE_CURRENT],
5307 [g_Game_ModeToText(gGameSettings.GameMode)]))
5308 else
5309 g_Console_Add(Format(_lc[I_MSG_GAMEMODE_CHANGE],
5310 [g_Game_ModeToText(gGameSettings.GameMode),
5311 g_Game_ModeToText(gSwitchGameMode)]));
5312 end
5313 else if (cmd = 'g_allow_exit') and not g_Game_IsClient then
5314 begin
5315 with gGameSettings do
5316 begin
5317 if (Length(P) > 1) and
5318 ((P[1] = '1') or (P[1] = '0')) then
5319 begin
5320 if (P[1][1] = '1') then
5321 Options := Options or GAME_OPTION_ALLOWEXIT
5322 else
5323 Options := Options and (not GAME_OPTION_ALLOWEXIT);
5324 end;
5326 if (LongBool(Options and GAME_OPTION_ALLOWEXIT)) then
5327 g_Console_Add(_lc[I_MSG_ALLOWEXIT_ON])
5328 else
5329 g_Console_Add(_lc[I_MSG_ALLOWEXIT_OFF]);
5330 g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
5332 if g_Game_IsNet then MH_SEND_GameSettings;
5333 end;
5334 end
5335 else if (cmd = 'g_allow_monsters') and not g_Game_IsClient then
5336 begin
5337 with gGameSettings do
5338 begin
5339 if (Length(P) > 1) and
5340 ((P[1] = '1') or (P[1] = '0')) then
5341 begin
5342 if (P[1][1] = '1') then
5343 Options := Options or GAME_OPTION_MONSTERS
5344 else
5345 Options := Options and (not GAME_OPTION_MONSTERS);
5346 end;
5348 if (LongBool(Options and GAME_OPTION_MONSTERS)) then
5349 g_Console_Add(_lc[I_MSG_ALLOWMON_ON])
5350 else
5351 g_Console_Add(_lc[I_MSG_ALLOWMON_OFF]);
5352 g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
5354 if g_Game_IsNet then MH_SEND_GameSettings;
5355 end;
5356 end
5357 else if (cmd = 'g_bot_vsplayers') and not g_Game_IsClient then
5358 begin
5359 with gGameSettings do
5360 begin
5361 if (Length(P) > 1) and
5362 ((P[1] = '1') or (P[1] = '0')) then
5363 begin
5364 if (P[1][1] = '1') then
5365 Options := Options or GAME_OPTION_BOTVSPLAYER
5366 else
5367 Options := Options and (not GAME_OPTION_BOTVSPLAYER);
5368 end;
5370 if (LongBool(Options and GAME_OPTION_BOTVSPLAYER)) then
5371 g_Console_Add(_lc[I_MSG_BOTSVSPLAYERS_ON])
5372 else
5373 g_Console_Add(_lc[I_MSG_BOTSVSPLAYERS_OFF]);
5375 if g_Game_IsNet then MH_SEND_GameSettings;
5376 end;
5377 end
5378 else if (cmd = 'g_bot_vsmonsters') and not g_Game_IsClient then
5379 begin
5380 with gGameSettings do
5381 begin
5382 if (Length(P) > 1) and
5383 ((P[1] = '1') or (P[1] = '0')) then
5384 begin
5385 if (P[1][1] = '1') then
5386 Options := Options or GAME_OPTION_BOTVSMONSTER
5387 else
5388 Options := Options and (not GAME_OPTION_BOTVSMONSTER);
5389 end;
5391 if (LongBool(Options and GAME_OPTION_BOTVSMONSTER)) then
5392 g_Console_Add(_lc[I_MSG_BOTSVSMONSTERS_ON])
5393 else
5394 g_Console_Add(_lc[I_MSG_BOTSVSMONSTERS_OFF]);
5396 if g_Game_IsNet then MH_SEND_GameSettings;
5397 end;
5398 end
5399 else if (cmd = 'g_warmuptime') and not g_Game_IsClient then
5400 begin
5401 if Length(P) > 1 then
5402 begin
5403 if StrToIntDef(P[1], gGameSettings.WarmupTime) = 0 then
5404 gGameSettings.WarmupTime := 30
5405 else
5406 gGameSettings.WarmupTime := StrToIntDef(P[1], gGameSettings.WarmupTime);
5407 end;
5409 g_Console_Add(Format(_lc[I_MSG_WARMUP],
5410 [gGameSettings.WarmupTime]));
5411 g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
5412 end
5413 else if cmd = 'net_interp' then
5414 begin
5415 if (Length(P) > 1) then
5416 NetInterpLevel := StrToIntDef(P[1], NetInterpLevel);
5418 g_Console_Add('net_interp = ' + IntToStr(NetInterpLevel));
5419 config := TConfig.CreateFile(GameDir+'/'+CONFIG_FILENAME);
5420 config.WriteInt('Client', 'InterpolationSteps', NetInterpLevel);
5421 config.SaveFile(GameDir+'/'+CONFIG_FILENAME);
5422 config.Free();
5423 end
5424 else if cmd = 'net_forceplayerupdate' then
5425 begin
5426 if (Length(P) > 1) and
5427 ((P[1] = '1') or (P[1] = '0')) then
5428 NetForcePlayerUpdate := (P[1][1] = '1');
5430 if NetForcePlayerUpdate then
5431 g_Console_Add('net_forceplayerupdate = 1')
5432 else
5433 g_Console_Add('net_forceplayerupdate = 0');
5434 config := TConfig.CreateFile(GameDir+'/'+CONFIG_FILENAME);
5435 config.WriteBool('Client', 'ForcePlayerUpdate', NetForcePlayerUpdate);
5436 config.SaveFile(GameDir+'/'+CONFIG_FILENAME);
5437 config.Free();
5438 end
5439 else if cmd = 'net_predictself' then
5440 begin
5441 if (Length(P) > 1) and
5442 ((P[1] = '1') or (P[1] = '0')) then
5443 NetPredictSelf := (P[1][1] = '1');
5445 if NetPredictSelf then
5446 g_Console_Add('net_predictself = 1')
5447 else
5448 g_Console_Add('net_predictself = 0');
5449 config := TConfig.CreateFile(GameDir+'/'+CONFIG_FILENAME);
5450 config.WriteBool('Client', 'PredictSelf', NetPredictSelf);
5451 config.SaveFile(GameDir+'/'+CONFIG_FILENAME);
5452 config.Free();
5453 end
5454 else if cmd = 'sv_name' then
5455 begin
5456 if (Length(P) > 1) and (Length(P[1]) > 0) then
5457 begin
5458 NetServerName := P[1];
5459 if Length(NetServerName) > 64 then
5460 SetLength(NetServerName, 64);
5461 if g_Game_IsServer and g_Game_IsNet and NetUseMaster then
5462 g_Net_Slist_Update;
5463 end;
5465 g_Console_Add(cmd + ' = "' + NetServerName + '"');
5466 end
5467 else if cmd = 'sv_passwd' then
5468 begin
5469 if (Length(P) > 1) and (Length(P[1]) > 0) then
5470 begin
5471 NetPassword := P[1];
5472 if Length(NetPassword) > 24 then
5473 SetLength(NetPassword, 24);
5474 if g_Game_IsServer and g_Game_IsNet and NetUseMaster then
5475 g_Net_Slist_Update;
5476 end;
5478 g_Console_Add(cmd + ' = "' + AnsiLowerCase(NetPassword) + '"');
5479 end
5480 else if cmd = 'sv_maxplrs' then
5481 begin
5482 if (Length(P) > 1) then
5483 begin
5484 NetMaxClients := Min(Max(StrToIntDef(P[1], NetMaxClients), 1), NET_MAXCLIENTS);
5485 if g_Game_IsServer and g_Game_IsNet then
5486 begin
5487 b := 0;
5488 for a := 0 to High(NetClients) do
5489 if NetClients[a].Used then
5490 begin
5491 Inc(b);
5492 if b > NetMaxClients then
5493 begin
5494 s := g_Player_Get(NetClients[a].Player).Name;
5495 enet_peer_disconnect(NetClients[a].Peer, NET_DISC_FULL);
5496 g_Console_Add(Format(_lc[I_PLAYER_KICK], [s]));
5497 MH_SEND_GameEvent(NET_EV_PLAYER_KICK, 0, s);
5498 end;
5499 end;
5500 if NetUseMaster then
5501 g_Net_Slist_Update;
5502 end;
5503 end;
5505 g_Console_Add(cmd + ' = ' + IntToStr(NetMaxClients));
5506 end
5507 else if cmd = 'sv_public' then
5508 begin
5509 if (Length(P) > 1) then
5510 begin
5511 NetUseMaster := StrToIntDef(P[1], Byte(NetUseMaster)) > 0;
5512 if g_Game_IsServer and g_Game_IsNet then
5513 if NetUseMaster then
5514 begin
5515 if NetMPeer = nil then g_Net_Slist_Connect();
5516 g_Net_Slist_Update();
5517 end
5518 else
5519 if NetMPeer <> nil then
5520 g_Net_Slist_Disconnect();
5521 end;
5523 g_Console_Add(cmd + ' = ' + IntToStr(Byte(NetUseMaster)));
5524 end
5525 else if cmd = 'sv_intertime' then
5526 begin
5527 if (Length(P) > 1) then
5528 gDefInterTime := Min(Max(StrToIntDef(P[1], gDefInterTime), -1), 120);
5530 g_Console_Add(cmd + ' = ' + IntToStr(gDefInterTime));
5531 end
5532 else if cmd = 'p1_name' then
5533 begin
5534 if (Length(P) > 1) and gGameOn then
5535 begin
5536 if g_Game_IsClient then
5537 begin
5538 gPlayer1Settings.Name := b_Text_Unformat(P[1]);
5539 MC_SEND_PlayerSettings;
5540 end
5541 else
5542 if gPlayer1 <> nil then
5543 begin
5544 gPlayer1.Name := b_Text_Unformat(P[1]);
5545 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer1.UID);
5546 end
5547 else
5548 gPlayer1Settings.Name := b_Text_Unformat(P[1]);
5549 end;
5550 end
5551 else if cmd = 'p2_name' then
5552 begin
5553 if (Length(P) > 1) and gGameOn then
5554 begin
5555 if g_Game_IsClient then
5556 begin
5557 gPlayer2Settings.Name := b_Text_Unformat(P[1]);
5558 MC_SEND_PlayerSettings;
5559 end
5560 else
5561 if gPlayer2 <> nil then
5562 begin
5563 gPlayer2.Name := b_Text_Unformat(P[1]);
5564 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer2.UID);
5565 end
5566 else
5567 gPlayer2Settings.Name := b_Text_Unformat(P[1]);
5568 end;
5569 end
5570 else if cmd = 'p1_color' then
5571 begin
5572 if Length(P) > 3 then
5573 if g_Game_IsClient then
5574 begin
5575 gPlayer1Settings.Color := _RGB(EnsureRange(StrToIntDef(P[1], 0), 0, 255),
5576 EnsureRange(StrToIntDef(P[2], 0), 0, 255),
5577 EnsureRange(StrToIntDef(P[3], 0), 0, 255));
5578 MC_SEND_PlayerSettings;
5579 end
5580 else
5581 if gPlayer1 <> nil then
5582 begin
5583 gPlayer1.Model.SetColor(EnsureRange(StrToIntDef(P[1], 0), 0, 255),
5584 EnsureRange(StrToIntDef(P[2], 0), 0, 255),
5585 EnsureRange(StrToIntDef(P[3], 0), 0, 255));
5586 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer1.UID);
5587 end
5588 else
5589 gPlayer1Settings.Color := _RGB(EnsureRange(StrToIntDef(P[1], 0), 0, 255),
5590 EnsureRange(StrToIntDef(P[2], 0), 0, 255),
5591 EnsureRange(StrToIntDef(P[3], 0), 0, 255));
5592 end
5593 else if (cmd = 'p2_color') and not g_Game_IsNet then
5594 begin
5595 if Length(P) > 3 then
5596 if g_Game_IsClient then
5597 begin
5598 gPlayer2Settings.Color := _RGB(EnsureRange(StrToIntDef(P[1], 0), 0, 255),
5599 EnsureRange(StrToIntDef(P[2], 0), 0, 255),
5600 EnsureRange(StrToIntDef(P[3], 0), 0, 255));
5601 MC_SEND_PlayerSettings;
5602 end
5603 else
5604 if gPlayer2 <> nil then
5605 begin
5606 gPlayer2.Model.SetColor(EnsureRange(StrToIntDef(P[1], 0), 0, 255),
5607 EnsureRange(StrToIntDef(P[2], 0), 0, 255),
5608 EnsureRange(StrToIntDef(P[3], 0), 0, 255));
5609 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer2.UID);
5610 end
5611 else
5612 gPlayer2Settings.Color := _RGB(EnsureRange(StrToIntDef(P[1], 0), 0, 255),
5613 EnsureRange(StrToIntDef(P[2], 0), 0, 255),
5614 EnsureRange(StrToIntDef(P[3], 0), 0, 255));
5615 end
5616 else if gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT] then
5617 begin
5618 if cmd = 'r_showscore' then
5619 begin
5620 if (Length(P) > 1) and
5621 ((P[1] = '1') or (P[1] = '0')) then
5622 gShowGoals := (P[1][1] = '1');
5624 if gShowGoals then
5625 g_Console_Add(_lc[I_MSG_SCORE_ON])
5626 else
5627 g_Console_Add(_lc[I_MSG_SCORE_OFF]);
5628 end
5629 else if cmd = 'r_showstat' then
5630 begin
5631 if (Length(P) > 1) and
5632 ((P[1] = '1') or (P[1] = '0')) then
5633 gShowStat := (P[1][1] = '1');
5635 if gShowStat then
5636 g_Console_Add(_lc[I_MSG_STATS_ON])
5637 else
5638 g_Console_Add(_lc[I_MSG_STATS_OFF]);
5639 end
5640 else if cmd = 'r_showkillmsg' then
5641 begin
5642 if (Length(P) > 1) and
5643 ((P[1] = '1') or (P[1] = '0')) then
5644 gShowKillMsg := (P[1][1] = '1');
5646 if gShowKillMsg then
5647 g_Console_Add(_lc[I_MSG_KILL_MSGS_ON])
5648 else
5649 g_Console_Add(_lc[I_MSG_KILL_MSGS_OFF]);
5650 end
5651 else if cmd = 'r_showlives' then
5652 begin
5653 if (Length(P) > 1) and
5654 ((P[1] = '1') or (P[1] = '0')) then
5655 gShowLives := (P[1][1] = '1');
5657 if gShowLives then
5658 g_Console_Add(_lc[I_MSG_LIVES_ON])
5659 else
5660 g_Console_Add(_lc[I_MSG_LIVES_OFF]);
5661 end
5662 else if cmd = 'r_showspect' then
5663 begin
5664 if (Length(P) > 1) and
5665 ((P[1] = '1') or (P[1] = '0')) then
5666 gSpectHUD := (P[1][1] = '1');
5668 if gSpectHUD then
5669 g_Console_Add(_lc[I_MSG_SPECT_HUD_ON])
5670 else
5671 g_Console_Add(_lc[I_MSG_SPECT_HUD_OFF]);
5672 end
5673 else if cmd = 'r_showping' then
5674 begin
5675 if (Length(P) > 1) and
5676 ((P[1] = '1') or (P[1] = '0')) then
5677 gShowPing := (P[1][1] = '1');
5679 if gShowPing then
5680 g_Console_Add(_lc[I_MSG_PING_ON])
5681 else
5682 g_Console_Add(_lc[I_MSG_PING_OFF]);
5683 end
5684 else if (cmd = 'g_scorelimit') and not g_Game_IsClient then
5685 begin
5686 if Length(P) > 1 then
5687 begin
5688 if StrToIntDef(P[1], gGameSettings.GoalLimit) = 0 then
5689 gGameSettings.GoalLimit := 0
5690 else
5691 begin
5692 b := 0;
5694 if gGameSettings.GameMode = GM_DM then
5695 begin // DM
5696 stat := g_Player_GetStats();
5697 if stat <> nil then
5698 for a := 0 to High(stat) do
5699 if stat[a].Frags > b then
5700 b := stat[a].Frags;
5701 end
5702 else // TDM/CTF
5703 b := Max(gTeamStat[TEAM_RED].Goals, gTeamStat[TEAM_BLUE].Goals);
5705 gGameSettings.GoalLimit := Max(StrToIntDef(P[1], gGameSettings.GoalLimit), b);
5706 end;
5708 if g_Game_IsNet then MH_SEND_GameSettings;
5709 end;
5711 g_Console_Add(Format(_lc[I_MSG_SCORE_LIMIT], [gGameSettings.GoalLimit]));
5712 end
5713 else if (cmd = 'g_timelimit') and not g_Game_IsClient then
5714 begin
5715 if (Length(P) > 1) and (StrToIntDef(P[1], -1) >= 0) then
5716 gGameSettings.TimeLimit := StrToIntDef(P[1], -1);
5718 g_Console_Add(Format(_lc[I_MSG_TIME_LIMIT],
5719 [gGameSettings.TimeLimit div 3600,
5720 (gGameSettings.TimeLimit div 60) mod 60,
5721 gGameSettings.TimeLimit mod 60]));
5722 if g_Game_IsNet then MH_SEND_GameSettings;
5723 end
5724 else if (cmd = 'g_maxlives') and not g_Game_IsClient then
5725 begin
5726 if Length(P) > 1 then
5727 begin
5728 if StrToIntDef(P[1], gGameSettings.MaxLives) = 0 then
5729 gGameSettings.MaxLives := 0
5730 else
5731 begin
5732 b := 0;
5733 stat := g_Player_GetStats();
5734 if stat <> nil then
5735 for a := 0 to High(stat) do
5736 if stat[a].Lives > b then
5737 b := stat[a].Lives;
5738 gGameSettings.MaxLives :=
5739 Max(StrToIntDef(P[1], gGameSettings.MaxLives), b);
5740 end;
5741 end;
5743 g_Console_Add(Format(_lc[I_MSG_LIVES],
5744 [gGameSettings.MaxLives]));
5745 if g_Game_IsNet then MH_SEND_GameSettings;
5746 end;
5747 end;
5748 end;
5750 procedure PrintHeapStats();
5751 var
5752 hs: TFPCHeapStatus;
5753 begin
5754 hs := GetFPCHeapStatus();
5755 e_LogWriteLn ('v===== heap status =====v');
5756 e_LogWriteFln('max heap size = %d k', [hs.MaxHeapSize div 1024]);
5757 e_LogWriteFln('max heap used = %d k', [hs.MaxHeapUsed div 1024]);
5758 e_LogWriteFln('cur heap size = %d k', [hs.CurrHeapSize div 1024]);
5759 e_LogWriteFln('cur heap used = %d k', [hs.CurrHeapUsed div 1024]);
5760 e_LogWriteFln('cur heap free = %d k', [hs.CurrHeapFree div 1024]);
5761 e_LogWriteLn ('^=======================^');
5762 end;
5764 procedure DebugCommands(P: SSArray);
5765 var
5766 a, b: Integer;
5767 cmd: string;
5768 //pt: TDFPoint;
5769 mon: TMonster;
5770 begin
5771 // Êîìàíäû îòëàäî÷íîãî ðåæèìà:
5772 if {gDebugMode}conIsCheatsEnabled then
5773 begin
5774 cmd := LowerCase(P[0]);
5775 if cmd = 'd_window' then
5776 begin
5777 g_Console_Add(Format('gWinPosX = %d, gWinPosY %d', [gWinPosX, gWinPosY]));
5778 g_Console_Add(Format('gWinRealPosX = %d, gWinRealPosY %d', [gWinRealPosX, gWinRealPosY]));
5779 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth, gScreenHeight]));
5780 g_Console_Add(Format('gWinSizeX = %d, gWinSizeY = %d', [gWinSizeX, gWinSizeY]));
5781 g_Console_Add(Format('Frame X = %d, Y = %d, Caption Y = %d', [gWinFrameX, gWinFrameY, gWinCaption]));
5782 end
5783 else if cmd = 'd_sounds' then
5784 begin
5785 if (Length(P) > 1) and
5786 ((P[1] = '1') or (P[1] = '0')) then
5787 g_Debug_Sounds := (P[1][1] = '1');
5789 g_Console_Add(Format('d_sounds is %d', [Byte(g_Debug_Sounds)]));
5790 end
5791 else if cmd = 'd_frames' then
5792 begin
5793 if (Length(P) > 1) and
5794 ((P[1] = '1') or (P[1] = '0')) then
5795 g_Debug_Frames := (P[1][1] = '1');
5797 g_Console_Add(Format('d_frames is %d', [Byte(g_Debug_Frames)]));
5798 end
5799 else if cmd = 'd_winmsg' then
5800 begin
5801 if (Length(P) > 1) and
5802 ((P[1] = '1') or (P[1] = '0')) then
5803 g_Debug_WinMsgs := (P[1][1] = '1');
5805 g_Console_Add(Format('d_winmsg is %d', [Byte(g_Debug_WinMsgs)]));
5806 end
5807 else if (cmd = 'd_monoff') and not g_Game_IsNet then
5808 begin
5809 if (Length(P) > 1) and
5810 ((P[1] = '1') or (P[1] = '0')) then
5811 g_Debug_MonsterOff := (P[1][1] = '1');
5813 g_Console_Add(Format('d_monoff is %d', [Byte(g_debug_MonsterOff)]));
5814 end
5815 else if (cmd = 'd_botoff') and not g_Game_IsNet then
5816 begin
5817 if Length(P) > 1 then
5818 case P[1][1] of
5819 '0': g_debug_BotAIOff := 0;
5820 '1': g_debug_BotAIOff := 1;
5821 '2': g_debug_BotAIOff := 2;
5822 '3': g_debug_BotAIOff := 3;
5823 end;
5825 g_Console_Add(Format('d_botoff is %d', [g_debug_BotAIOff]));
5826 end
5827 else if cmd = 'd_monster' then
5828 begin
5829 if gGameOn and (gPlayer1 <> nil) and (gPlayer1.alive) and (not g_Game_IsNet) then
5830 if Length(P) < 2 then
5831 begin
5832 g_Console_Add(cmd + ' [ID | Name] [behaviour]');
5833 g_Console_Add('ID | Name');
5834 for b := MONSTER_DEMON to MONSTER_MAN do
5835 g_Console_Add(Format('%2d | %s', [b, g_Mons_NameByTypeId(b)]));
5836 conwriteln('behav. num'#10'normal 0'#10'killer 1'#10'maniac 2'#10'insane 3'#10'cannibal 4'#10'good 5');
5837 end else
5838 begin
5839 a := StrToIntDef(P[1], 0);
5840 if (a < MONSTER_DEMON) or (a > MONSTER_MAN) then
5841 a := g_Mons_TypeIdByName(P[1]);
5843 if (a < MONSTER_DEMON) or (a > MONSTER_MAN) then
5844 g_Console_Add(Format(_lc[I_MSG_NO_MONSTER], [P[1]]))
5845 else
5846 begin
5847 with gPlayer1.Obj do
5848 begin
5849 mon := g_Monsters_Create(a,
5850 X + Rect.X + (Rect.Width div 2),
5851 Y + Rect.Y + Rect.Height,
5852 gPlayer1.Direction, True);
5853 end;
5854 if (Length(P) > 2) and (mon <> nil) then
5855 begin
5856 if (CompareText(P[2], 'normal') = 0) then mon.MonsterBehaviour := BH_NORMAL
5857 else if (CompareText(P[2], 'killer') = 0) then mon.MonsterBehaviour := BH_KILLER
5858 else if (CompareText(P[2], 'maniac') = 0) then mon.MonsterBehaviour := BH_MANIAC
5859 else if (CompareText(P[2], 'insane') = 0) then mon.MonsterBehaviour := BH_INSANE
5860 else if (CompareText(P[2], 'cannibal') = 0) then mon.MonsterBehaviour := BH_CANNIBAL
5861 else if (CompareText(P[2], 'good') = 0) then mon.MonsterBehaviour := BH_GOOD
5862 else if (CompareText(P[2], 'friend') = 0) then mon.MonsterBehaviour := BH_GOOD
5863 else if (CompareText(P[2], 'friendly') = 0) then mon.MonsterBehaviour := BH_GOOD
5864 else mon.MonsterBehaviour := Min(Max(StrToIntDef(P[2], BH_NORMAL), BH_NORMAL), BH_GOOD);
5865 end;
5866 end;
5867 end;
5868 end
5869 else if (cmd = 'd_health') then
5870 begin
5871 if (Length(P) > 1) and
5872 ((P[1] = '1') or (P[1] = '0')) then
5873 g_debug_HealthBar := (P[1][1] = '1');
5875 g_Console_Add(Format('d_health is %d', [Byte(g_debug_HealthBar)]));
5876 end
5877 else if (cmd = 'd_player') then
5878 begin
5879 if (Length(P) > 1) and
5880 ((P[1] = '1') or (P[1] = '0')) then
5881 g_debug_Player := (P[1][1] = '1');
5883 g_Console_Add(Format(cmd + ' is %d', [Byte(g_Debug_Player)]));
5884 end
5885 else if (cmd = 'd_mem') then
5886 begin
5887 PrintHeapStats();
5888 end;
5889 end
5890 else
5891 g_Console_Add(_lc[I_MSG_NOT_DEBUG]);
5892 end;
5895 procedure GameCheats(P: SSArray);
5896 var
5897 cmd: string;
5898 f, a: Integer;
5899 plr: TPlayer;
5900 begin
5901 if (not gGameOn) or (not conIsCheatsEnabled) then
5902 begin
5903 g_Console_Add('not available');
5904 exit;
5905 end;
5906 plr := gPlayer1;
5907 if plr = nil then
5908 begin
5909 g_Console_Add('where is the player?!');
5910 exit;
5911 end;
5912 cmd := LowerCase(P[0]);
5913 // god
5914 if cmd = 'god' then
5915 begin
5916 plr.GodMode := not plr.GodMode;
5917 if plr.GodMode then g_Console_Add('player is godlike now') else g_Console_Add('player is mortal now');
5918 exit;
5919 end;
5920 // give <health|exit|weapons|air|suit|jetpack|berserk|all>
5921 if cmd = 'give' then
5922 begin
5923 if length(P) < 2 then begin g_Console_Add('give what?!'); exit; end;
5924 for f := 1 to High(P) do
5925 begin
5926 cmd := LowerCase(P[f]);
5927 if cmd = 'health' then begin plr.RestoreHealthArmor(); g_Console_Add('player feels himself better'); continue; end;
5928 if (cmd = 'all') {or (cmd = 'weapons')} then begin plr.AllRulez(False); g_Console_Add('player got the gifts'); continue; end;
5929 if cmd = 'exit' then
5930 begin
5931 if gTriggers <> nil then
5932 begin
5933 for a := 0 to High(gTriggers) do
5934 begin
5935 if gTriggers[a].TriggerType = TRIGGER_EXIT then
5936 begin
5937 g_Console_Add('player left the map');
5938 gExitByTrigger := True;
5939 //g_Game_ExitLevel(gTriggers[a].Data.MapName);
5940 g_Game_ExitLevel(gTriggers[a].tgcMap);
5941 break;
5942 end;
5943 end;
5944 end;
5945 continue;
5946 end;
5948 if cmd = 'air' then begin plr.GiveItem(ITEM_OXYGEN); g_Console_Add('player got some air'); continue; end;
5949 if cmd = 'jetpack' then begin plr.GiveItem(ITEM_JETPACK); g_Console_Add('player got a jetpack'); continue; end;
5950 if cmd = 'suit' then begin plr.GiveItem(ITEM_SUIT); g_Console_Add('player got an envirosuit'); continue; end;
5951 if cmd = 'berserk' then begin plr.GiveItem(ITEM_MEDKIT_BLACK); g_Console_Add('player got a berserk pack'); continue; end;
5952 if cmd = 'backpack' then begin plr.GiveItem(ITEM_AMMO_BACKPACK); g_Console_Add('player got a backpack'); continue; end;
5954 if cmd = 'helmet' then begin plr.GiveItem(ITEM_HELMET); g_Console_Add('player got a helmet'); continue; end;
5955 if cmd = 'bottle' then begin plr.GiveItem(ITEM_BOTTLE); g_Console_Add('player got a bottle of health'); continue; end;
5957 if cmd = 'stimpack' then begin plr.GiveItem(ITEM_MEDKIT_SMALL); g_Console_Add('player got a stimpack'); continue; end;
5958 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;
5960 if cmd = 'greenarmor' then begin plr.GiveItem(ITEM_ARMOR_GREEN); g_Console_Add('player got a security armor'); continue; end;
5961 if cmd = 'bluearmor' then begin plr.GiveItem(ITEM_ARMOR_BLUE); g_Console_Add('player got a combat armor'); continue; end;
5963 if (cmd = 'megasphere') or (cmd = 'mega') then begin plr.GiveItem(ITEM_SPHERE_BLUE); g_Console_Add('player got a megasphere'); continue; end;
5964 if (cmd = 'soulsphere') or (cmd = 'soul')then begin plr.GiveItem(ITEM_SPHERE_WHITE); g_Console_Add('player got a soul sphere'); continue; end;
5966 if (cmd = 'invul') or (cmd = 'invulnerability') then begin plr.GiveItem(ITEM_INVUL); g_Console_Add('player got invulnerability'); continue; end;
5967 if (cmd = 'invis') or (cmd = 'invisibility') then begin plr.GiveItem(ITEM_INVIS); g_Console_Add('player got invisibility'); continue; end;
5969 if cmd = 'redkey' then begin plr.GiveItem(ITEM_KEY_RED); g_Console_Add('player got the red key'); continue; end;
5970 if cmd = 'greenkey' then begin plr.GiveItem(ITEM_KEY_GREEN); g_Console_Add('player got the green key'); continue; end;
5971 if cmd = 'bluekey' then begin plr.GiveItem(ITEM_KEY_BLUE); g_Console_Add('player got the blue key'); continue; end;
5973 if (cmd = 'shotgun') or (cmd = 'sg') then begin plr.GiveItem(ITEM_WEAPON_SHOTGUN1); g_Console_Add('player got a shotgun'); continue; end;
5974 if (cmd = 'supershotgun') or (cmd = 'ssg') then begin plr.GiveItem(ITEM_WEAPON_SHOTGUN2); g_Console_Add('player got a supershotgun'); continue; end;
5975 if cmd = 'chaingun' then begin plr.GiveItem(ITEM_WEAPON_CHAINGUN); g_Console_Add('player got a chaingun'); continue; end;
5976 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;
5977 if cmd = 'plasmagun' then begin plr.GiveItem(ITEM_WEAPON_PLASMA); g_Console_Add('player got a plasma gun'); continue; end;
5978 if cmd = 'bfg' then begin plr.GiveItem(ITEM_WEAPON_BFG); g_Console_Add('player got a BFG-9000'); continue; end;
5980 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;
5981 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;
5982 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;
5983 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;
5984 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;
5985 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;
5987 if cmd = 'superchaingun' then begin plr.GiveItem(ITEM_WEAPON_SUPERPULEMET); g_Console_Add('player got a superchaingun'); continue; end;
5988 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;
5990 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;
5991 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;
5993 if cmd = 'chainsaw' then begin plr.GiveItem(ITEM_WEAPON_SAW); g_Console_Add('player got a chainsaw'); continue; end;
5995 if cmd = 'ammo' then
5996 begin
5997 plr.GiveItem(ITEM_AMMO_SHELLS_BOX);
5998 plr.GiveItem(ITEM_AMMO_BULLETS_BOX);
5999 plr.GiveItem(ITEM_AMMO_CELL_BIG);
6000 plr.GiveItem(ITEM_AMMO_ROCKET_BOX);
6001 plr.GiveItem(ITEM_AMMO_FUELCAN);
6002 g_Console_Add('player got some ammo');
6003 continue;
6004 end;
6006 if cmd = 'clip' then begin plr.GiveItem(ITEM_AMMO_BULLETS); g_Console_Add('player got some bullets'); continue; end;
6007 if cmd = 'bullets' then begin plr.GiveItem(ITEM_AMMO_BULLETS_BOX); g_Console_Add('player got a box of bullets'); continue; end;
6009 if cmd = 'shells' then begin plr.GiveItem(ITEM_AMMO_SHELLS); g_Console_Add('player got some shells'); continue; end;
6010 if cmd = 'shellbox' then begin plr.GiveItem(ITEM_AMMO_SHELLS_BOX); g_Console_Add('player got a box of shells'); continue; end;
6012 if cmd = 'cells' then begin plr.GiveItem(ITEM_AMMO_CELL); g_Console_Add('player got some cells'); continue; end;
6013 if cmd = 'battery' then begin plr.GiveItem(ITEM_AMMO_CELL_BIG); g_Console_Add('player got cell battery'); continue; end;
6015 if cmd = 'rocket' then begin plr.GiveItem(ITEM_AMMO_ROCKET); g_Console_Add('player got a rocket'); continue; end;
6016 if cmd = 'rocketbox' then begin plr.GiveItem(ITEM_AMMO_ROCKET_BOX); g_Console_Add('player got some rockets'); continue; end;
6018 if (cmd = 'fuel') or (cmd = 'fuelcan') then begin plr.GiveItem(ITEM_AMMO_FUELCAN); g_Console_Add('player got fuel canister'); continue; end;
6020 if cmd = 'weapons' then
6021 begin
6022 plr.GiveItem(ITEM_WEAPON_SHOTGUN1);
6023 plr.GiveItem(ITEM_WEAPON_SHOTGUN2);
6024 plr.GiveItem(ITEM_WEAPON_CHAINGUN);
6025 plr.GiveItem(ITEM_WEAPON_ROCKETLAUNCHER);
6026 plr.GiveItem(ITEM_WEAPON_PLASMA);
6027 plr.GiveItem(ITEM_WEAPON_BFG);
6028 g_Console_Add('player got weapons');
6029 continue;
6030 end;
6032 if cmd = 'keys' then
6033 begin
6034 plr.GiveItem(ITEM_KEY_RED);
6035 plr.GiveItem(ITEM_KEY_GREEN);
6036 plr.GiveItem(ITEM_KEY_BLUE);
6037 g_Console_Add('player got all keys');
6038 continue;
6039 end;
6041 g_Console_Add('i don''t know how to give '''+cmd+'''!');
6042 end;
6043 exit;
6044 end;
6045 // open
6046 if cmd = 'open' then
6047 begin
6048 g_Console_Add('player activated sesame');
6049 g_Triggers_OpenAll();
6050 exit;
6051 end;
6052 // fly
6053 if cmd = 'fly' then
6054 begin
6055 gFly := not gFly;
6056 if gFly then g_Console_Add('player feels himself lighter') else g_Console_Add('player lost his wings');
6057 exit;
6058 end;
6059 // noclip
6060 if cmd = 'noclip' then
6061 begin
6062 plr.SwitchNoClip;
6063 g_Console_Add('wall hardeness adjusted');
6064 exit;
6065 end;
6066 // notarget
6067 if cmd = 'notarget' then
6068 begin
6069 plr.NoTarget := not plr.NoTarget;
6070 if plr.NoTarget then g_Console_Add('player hides in shadows') else g_Console_Add('player is brave again');
6071 exit;
6072 end;
6073 // noreload
6074 if cmd = 'noreload' then
6075 begin
6076 plr.NoReload := not plr.NoReload;
6077 if plr.NoReload then g_Console_Add('player is action hero now') else g_Console_Add('player is ordinary man now');
6078 exit;
6079 end;
6080 // speedy
6081 if cmd = 'speedy' then
6082 begin
6083 MAX_RUNVEL := 32-MAX_RUNVEL;
6084 g_Console_Add('speed adjusted');
6085 exit;
6086 end;
6087 // jumpy
6088 if cmd = 'jumpy' then
6089 begin
6090 VEL_JUMP := 30-VEL_JUMP;
6091 g_Console_Add('jump height adjusted');
6092 exit;
6093 end;
6094 // automap
6095 if cmd = 'automap' then
6096 begin
6097 gShowMap := not gShowMap;
6098 if gShowMap then g_Console_Add('player gains second sight') else g_Console_Add('player lost second sight');
6099 exit;
6100 end;
6101 // aimline
6102 if cmd = 'aimline' then
6103 begin
6104 gAimLine := not gAimLine;
6105 if gAimLine then g_Console_Add('player gains laser sight') else g_Console_Add('player lost laser sight');
6106 exit;
6107 end;
6108 end;
6110 procedure GameCommands(P: SSArray);
6111 var
6112 a, b: Integer;
6113 s, pw: String;
6114 chstr: string;
6115 cmd: string;
6116 pl: pTNetClient = nil;
6117 plr: TPlayer;
6118 prt: Word;
6119 nm: Boolean;
6120 listen: LongWord;
6121 begin
6122 // Îáùèå êîìàíäû:
6123 cmd := LowerCase(P[0]);
6124 chstr := '';
6125 if (cmd = 'quit') or
6126 (cmd = 'exit') then
6127 begin
6128 g_Game_Free();
6129 g_Game_Quit();
6130 Exit;
6131 end
6132 else if cmd = 'pause' then
6133 begin
6134 if (g_ActiveWindow = nil) then
6135 g_Game_Pause(not gPauseMain);
6136 end
6137 else if cmd = 'endgame' then
6138 gExit := EXIT_SIMPLE
6139 else if cmd = 'restart' then
6140 begin
6141 if gGameOn or (gState in [STATE_INTERSINGLE, STATE_INTERCUSTOM]) then
6142 begin
6143 if g_Game_IsClient then
6144 begin
6145 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6146 Exit;
6147 end;
6148 g_Game_Restart();
6149 end else
6150 g_Console_Add(_lc[I_MSG_NOT_GAME]);
6151 end
6152 else if cmd = 'kick' then
6153 begin
6154 if g_Game_IsServer then
6155 begin
6156 if Length(P) < 2 then
6157 begin
6158 g_Console_Add('kick <name>');
6159 Exit;
6160 end;
6161 if P[1] = '' then
6162 begin
6163 g_Console_Add('kick <name>');
6164 Exit;
6165 end;
6167 if g_Game_IsNet then
6168 pl := g_Net_Client_ByName(P[1]);
6169 if (pl <> nil) then
6170 begin
6171 s := g_Net_ClientName_ByID(pl^.ID);
6172 enet_peer_disconnect(pl^.Peer, NET_DISC_KICK);
6173 g_Console_Add(Format(_lc[I_PLAYER_KICK], [s]));
6174 MH_SEND_GameEvent(NET_EV_PLAYER_KICK, 0, s);
6175 if NetUseMaster then
6176 g_Net_Slist_Update;
6177 end else if gPlayers <> nil then
6178 for a := Low(gPlayers) to High(gPlayers) do
6179 if gPlayers[a] <> nil then
6180 if Copy(LowerCase(gPlayers[a].Name), 1, Length(P[1])) = LowerCase(P[1]) then
6181 begin
6182 // Íå îòêëþ÷àòü îñíîâíûõ èãðîêîâ â ñèíãëå
6183 if not(gPlayers[a] is TBot) and (gGameSettings.GameType = GT_SINGLE) then
6184 continue;
6185 gPlayers[a].Lives := 0;
6186 gPlayers[a].Kill(K_SIMPLEKILL, 0, HIT_DISCON);
6187 g_Console_Add(Format(_lc[I_PLAYER_LEAVE], [gPlayers[a].Name]), True);
6188 g_Player_Remove(gPlayers[a].UID);
6189 if NetUseMaster then
6190 g_Net_Slist_Update;
6191 // Åñëè íå ïåðåìåøàòü, ïðè äîáàâëåíèè íîâûõ áîòîâ ïîÿâÿòñÿ ñòàðûå
6192 g_Bot_MixNames();
6193 end;
6194 end else
6195 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
6196 end
6197 else if cmd = 'kick_id' then
6198 begin
6199 if g_Game_IsServer and g_Game_IsNet then
6200 begin
6201 if Length(P) < 2 then
6202 begin
6203 g_Console_Add('kick_id <client ID>');
6204 Exit;
6205 end;
6206 if P[1] = '' then
6207 begin
6208 g_Console_Add('kick_id <client ID>');
6209 Exit;
6210 end;
6212 a := StrToIntDef(P[1], 0);
6213 if (NetClients <> nil) and (a <= High(NetClients)) then
6214 begin
6215 if NetClients[a].Used and (NetClients[a].Peer <> nil) then
6216 begin
6217 s := g_Net_ClientName_ByID(NetClients[a].ID);
6218 enet_peer_disconnect(NetClients[a].Peer, NET_DISC_KICK);
6219 g_Console_Add(Format(_lc[I_PLAYER_KICK], [s]));
6220 MH_SEND_GameEvent(NET_EV_PLAYER_KICK, 0, s);
6221 if NetUseMaster then
6222 g_Net_Slist_Update;
6223 end;
6224 end;
6225 end else
6226 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6227 end
6228 else if cmd = 'ban' then
6229 begin
6230 if g_Game_IsServer and g_Game_IsNet then
6231 begin
6232 if Length(P) < 2 then
6233 begin
6234 g_Console_Add('ban <name>');
6235 Exit;
6236 end;
6237 if P[1] = '' then
6238 begin
6239 g_Console_Add('ban <name>');
6240 Exit;
6241 end;
6243 pl := g_Net_Client_ByName(P[1]);
6244 if (pl <> nil) then
6245 begin
6246 s := g_Net_ClientName_ByID(pl^.ID);
6247 g_Net_BanHost(pl^.Peer^.address.host, False);
6248 enet_peer_disconnect(pl^.Peer, NET_DISC_TEMPBAN);
6249 g_Console_Add(Format(_lc[I_PLAYER_BAN], [s]));
6250 MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s);
6251 if NetUseMaster then
6252 g_Net_Slist_Update;
6253 end else
6254 g_Console_Add(Format(_lc[I_NET_ERR_NAME404], [P[1]]));
6255 end else
6256 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6257 end
6258 else if cmd = 'ban_id' then
6259 begin
6260 if g_Game_IsServer and g_Game_IsNet then
6261 begin
6262 if Length(P) < 2 then
6263 begin
6264 g_Console_Add('ban_id <client ID>');
6265 Exit;
6266 end;
6267 if P[1] = '' then
6268 begin
6269 g_Console_Add('ban_id <client ID>');
6270 Exit;
6271 end;
6273 a := StrToIntDef(P[1], 0);
6274 if (NetClients <> nil) and (a <= High(NetClients)) then
6275 if NetClients[a].Used and (NetClients[a].Peer <> nil) then
6276 begin
6277 s := g_Net_ClientName_ByID(NetClients[a].ID);
6278 g_Net_BanHost(NetClients[a].Peer^.address.host, False);
6279 enet_peer_disconnect(NetClients[a].Peer, NET_DISC_TEMPBAN);
6280 g_Console_Add(Format(_lc[I_PLAYER_BAN], [s]));
6281 MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s);
6282 if NetUseMaster then
6283 g_Net_Slist_Update;
6284 end;
6285 end else
6286 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6287 end
6288 else if cmd = 'permban' then
6289 begin
6290 if g_Game_IsServer and g_Game_IsNet then
6291 begin
6292 if Length(P) < 2 then
6293 begin
6294 g_Console_Add('permban <name>');
6295 Exit;
6296 end;
6297 if P[1] = '' then
6298 begin
6299 g_Console_Add('permban <name>');
6300 Exit;
6301 end;
6303 pl := g_Net_Client_ByName(P[1]);
6304 if (pl <> nil) then
6305 begin
6306 s := g_Net_ClientName_ByID(pl^.ID);
6307 g_Net_BanHost(pl^.Peer^.address.host);
6308 enet_peer_disconnect(pl^.Peer, NET_DISC_BAN);
6309 g_Net_SaveBanList();
6310 g_Console_Add(Format(_lc[I_PLAYER_BAN], [s]));
6311 MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s);
6312 if NetUseMaster then
6313 g_Net_Slist_Update;
6314 end else
6315 g_Console_Add(Format(_lc[I_NET_ERR_NAME404], [P[1]]));
6316 end else
6317 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6318 end
6319 else if cmd = 'permban_id' then
6320 begin
6321 if g_Game_IsServer and g_Game_IsNet then
6322 begin
6323 if Length(P) < 2 then
6324 begin
6325 g_Console_Add('permban_id <client ID>');
6326 Exit;
6327 end;
6328 if P[1] = '' then
6329 begin
6330 g_Console_Add('permban_id <client ID>');
6331 Exit;
6332 end;
6334 a := StrToIntDef(P[1], 0);
6335 if (NetClients <> nil) and (a <= High(NetClients)) then
6336 if NetClients[a].Used and (NetClients[a].Peer <> nil) then
6337 begin
6338 s := g_Net_ClientName_ByID(NetClients[a].ID);
6339 g_Net_BanHost(NetClients[a].Peer^.address.host);
6340 enet_peer_disconnect(NetClients[a].Peer, NET_DISC_BAN);
6341 g_Net_SaveBanList();
6342 g_Console_Add(Format(_lc[I_PLAYER_BAN], [s]));
6343 MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s);
6344 if NetUseMaster then
6345 g_Net_Slist_Update;
6346 end;
6347 end else
6348 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6349 end
6350 else if cmd = 'unban' then
6351 begin
6352 if g_Game_IsServer and g_Game_IsNet then
6353 begin
6354 if Length(P) < 2 then
6355 begin
6356 g_Console_Add('unban <IP Address>');
6357 Exit;
6358 end;
6359 if P[1] = '' then
6360 begin
6361 g_Console_Add('unban <IP Address>');
6362 Exit;
6363 end;
6365 if g_Net_UnbanHost(P[1]) then
6366 begin
6367 g_Console_Add(Format(_lc[I_MSG_UNBAN_OK], [P[1]]));
6368 g_Net_SaveBanList();
6369 end else
6370 g_Console_Add(Format(_lc[I_MSG_UNBAN_FAIL], [P[1]]));
6371 end else
6372 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6373 end
6374 else if cmd = 'clientlist' then
6375 begin
6376 if g_Game_IsServer and g_Game_IsNet then
6377 begin
6378 b := 0;
6379 if NetClients <> nil then
6380 for a := Low(NetClients) to High(NetClients) do
6381 if NetClients[a].Used and (NetClients[a].Peer <> nil) then
6382 begin
6383 plr := g_Player_Get(NetClients[a].Player);
6384 if plr = nil then continue;
6385 Inc(b);
6386 g_Console_Add(Format('#%2d: %-15s | %s', [a,
6387 IpToStr(NetClients[a].Peer^.address.host), plr.Name]));
6388 end;
6389 if b = 0 then
6390 g_Console_Add(_lc[I_MSG_NOCLIENTS]);
6391 end else
6392 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6393 end
6394 else if cmd = 'connect' then
6395 begin
6396 if (NetMode = NET_NONE) then
6397 begin
6398 if Length(P) < 2 then
6399 begin
6400 g_Console_Add('connect <IP> [port] [password]');
6401 Exit;
6402 end;
6403 if P[1] = '' then
6404 begin
6405 g_Console_Add('connect <IP> [port] [password]');
6406 Exit;
6407 end;
6409 if Length(P) > 2 then
6410 prt := StrToIntDef(P[2], 25666)
6411 else
6412 prt := 25666;
6414 if Length(P) > 3 then
6415 pw := P[3]
6416 else
6417 pw := '';
6419 g_Game_StartClient(P[1], prt, pw);
6420 end;
6421 end
6422 else if cmd = 'disconnect' then
6423 begin
6424 if (NetMode = NET_CLIENT) then
6425 g_Net_Disconnect();
6426 end
6427 else if cmd = 'reconnect' then
6428 begin
6429 if (NetMode = NET_SERVER) then
6430 Exit;
6432 if (NetMode = NET_CLIENT) then
6433 begin
6434 g_Net_Disconnect();
6435 gExit := EXIT_SIMPLE;
6436 EndGame;
6437 end;
6439 //TODO: Use last successful password to reconnect, instead of ''
6440 g_Game_StartClient(NetClientIP, NetClientPort, '');
6441 end
6442 else if (cmd = 'addbot') or
6443 (cmd = 'bot_add') then
6444 begin
6445 if Length(P) > 2 then
6446 g_Bot_Add(TEAM_NONE, StrToIntDef(P[1], 2), StrToIntDef(P[2], 100))
6447 else if Length(P) > 1 then
6448 g_Bot_Add(TEAM_NONE, StrToIntDef(P[1], 2))
6449 else
6450 g_Bot_Add(TEAM_NONE, 2);
6451 end
6452 else if cmd = 'bot_addlist' then
6453 begin
6454 if Length(P) > 1 then
6455 begin
6456 if Length(P) = 2 then
6457 g_Bot_AddList(TEAM_NONE, P[1], StrToIntDef(P[1], -1))
6458 else if Length(P) = 3 then
6459 g_Bot_AddList(TEAM_NONE, P[1], StrToIntDef(P[1], -1), StrToIntDef(P[2], 100))
6460 else
6461 g_Bot_AddList(IfThen(P[2] = 'red', TEAM_RED, TEAM_BLUE), P[1], StrToIntDef(P[1], -1));
6462 end;
6463 end
6464 else if cmd = 'bot_removeall' then
6465 g_Bot_RemoveAll()
6466 else if cmd = 'chat' then
6467 begin
6468 if g_Game_IsNet then
6469 begin
6470 if Length(P) > 1 then
6471 begin
6472 for a := 1 to High(P) do
6473 chstr := chstr + P[a] + ' ';
6475 if Length(chstr) > 200 then SetLength(chstr, 200);
6477 if Length(chstr) < 1 then
6478 begin
6479 g_Console_Add('chat <text>');
6480 Exit;
6481 end;
6483 chstr := b_Text_Format(chstr);
6484 if g_Game_IsClient then
6485 MC_SEND_Chat(chstr, NET_CHAT_PLAYER)
6486 else
6487 MH_SEND_Chat(gPlayer1Settings.Name + ': ' + chstr, NET_CHAT_PLAYER);
6488 end
6489 else
6490 g_Console_Add('chat <text>');
6491 end else
6492 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
6493 end
6494 else if cmd = 'teamchat' then
6495 begin
6496 if g_Game_IsNet and (gGameSettings.GameMode in [GM_TDM, GM_CTF]) then
6497 begin
6498 if Length(P) > 1 then
6499 begin
6500 for a := 1 to High(P) do
6501 chstr := chstr + P[a] + ' ';
6503 if Length(chstr) > 200 then SetLength(chstr, 200);
6505 if Length(chstr) < 1 then
6506 begin
6507 g_Console_Add('teamchat <text>');
6508 Exit;
6509 end;
6511 chstr := b_Text_Format(chstr);
6512 if g_Game_IsClient then
6513 MC_SEND_Chat(chstr, NET_CHAT_TEAM)
6514 else
6515 MH_SEND_Chat(gPlayer1Settings.Name + ': ' + chstr, NET_CHAT_TEAM,
6516 gPlayer1Settings.Team);
6517 end
6518 else
6519 g_Console_Add('teamchat <text>');
6520 end else
6521 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
6522 end
6523 else if cmd = 'game' then
6524 begin
6525 if gGameSettings.GameType <> GT_NONE then
6526 begin
6527 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
6528 Exit;
6529 end;
6530 if Length(P) = 1 then
6531 begin
6532 g_Console_Add(cmd + ' <WAD> [MAP] [# players]');
6533 Exit;
6534 end;
6535 // Èãðà åù¸ íå çàïóùåíà, ñíà÷àëà íàì íàäî çàãðóçèòü êàêîé-òî WAD
6536 P[1] := addWadExtension(P[1]);
6537 if FileExists(MapsDir + P[1]) then
6538 begin
6539 // Åñëè êàðòà íå óêàçàíà, áåð¸ì ïåðâóþ êàðòó â ôàéëå
6540 if Length(P) < 3 then
6541 begin
6542 SetLength(P, 3);
6543 P[2] := g_Game_GetFirstMap(MapsDir + P[1]);
6544 end;
6546 s := P[1] + ':\' + UpperCase(P[2]);
6548 if g_Map_Exist(MapsDir + s) then
6549 begin
6550 // Çàïóñêàåì ñâîþ èãðó
6551 g_Game_Free();
6552 with gGameSettings do
6553 begin
6554 GameMode := g_Game_TextToMode(gcGameMode);
6555 if gSwitchGameMode <> GM_NONE then
6556 GameMode := gSwitchGameMode;
6557 if GameMode = GM_NONE then GameMode := GM_DM;
6558 if GameMode = GM_SINGLE then GameMode := GM_COOP;
6559 b := 1;
6560 if Length(P) >= 4 then
6561 b := StrToIntDef(P[3], 1);
6562 g_Game_StartCustom(s, GameMode, TimeLimit,
6563 GoalLimit, MaxLives, Options, b);
6564 end;
6565 end
6566 else
6567 if P[2] = '' then
6568 g_Console_Add(Format(_lc[I_MSG_NO_MAPS], [P[1]]))
6569 else
6570 g_Console_Add(Format(_lc[I_MSG_NO_MAP_FALLBACK], [UpperCase(P[2]), P[1]]));
6571 end else
6572 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]));
6573 end
6574 else if cmd = 'host' then
6575 begin
6576 if gGameSettings.GameType <> GT_NONE then
6577 begin
6578 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
6579 Exit;
6580 end;
6581 if Length(P) < 4 then
6582 begin
6583 g_Console_Add(cmd + ' <listen IP> <port> <WAD> [MAP] [# players]');
6584 Exit;
6585 end;
6586 if not StrToIp(P[1], listen) then
6587 Exit;
6588 prt := StrToIntDef(P[2], 25666);
6590 P[3] := addWadExtension(P[3]);
6591 if FileExists(MapsDir + P[3]) then
6592 begin
6593 // Åñëè êàðòà íå óêàçàíà, áåð¸ì ïåðâóþ êàðòó â ôàéëå
6594 if Length(P) < 5 then
6595 begin
6596 SetLength(P, 5);
6597 P[4] := g_Game_GetFirstMap(MapsDir + P[1]);
6598 end;
6600 s := P[3] + ':\' + UpperCase(P[4]);
6602 if g_Map_Exist(MapsDir + s) then
6603 begin
6604 // Çàïóñêàåì ñâîþ èãðó
6605 g_Game_Free();
6606 with gGameSettings do
6607 begin
6608 GameMode := g_Game_TextToMode(gcGameMode);
6609 if gSwitchGameMode <> GM_NONE then
6610 GameMode := gSwitchGameMode;
6611 if GameMode = GM_NONE then GameMode := GM_DM;
6612 if GameMode = GM_SINGLE then GameMode := GM_COOP;
6613 b := 0;
6614 if Length(P) >= 6 then
6615 b := StrToIntDef(P[5], 0);
6616 g_Game_StartServer(s, GameMode, TimeLimit,
6617 GoalLimit, MaxLives, Options, b, listen, prt);
6618 end;
6619 end
6620 else
6621 if P[4] = '' then
6622 g_Console_Add(Format(_lc[I_MSG_NO_MAPS], [P[3]]))
6623 else
6624 g_Console_Add(Format(_lc[I_MSG_NO_MAP_FALLBACK], [UpperCase(P[4]), P[3]]));
6625 end else
6626 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[3]]));
6627 end
6628 else if cmd = 'map' then
6629 begin
6630 if Length(P) = 1 then
6631 begin
6632 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
6633 begin
6634 g_Console_Add(cmd + ' <MAP>');
6635 g_Console_Add(cmd + ' <WAD> [MAP]');
6636 end else
6637 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
6638 end else
6639 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
6640 begin
6641 // Èä¸ò ñâîÿ èãðà èëè ñåðâåð
6642 if Length(P) < 3 then
6643 begin
6644 // Ïåðâûé ïàðàìåòð - ëèáî êàðòà, ëèáî èìÿ WAD ôàéëà
6645 s := UpperCase(P[1]);
6646 if g_Map_Exist(MapsDir + gGameSettings.WAD + ':\' + s) then
6647 begin // Êàðòà íàøëàñü
6648 gExitByTrigger := False;
6649 if gGameOn then
6650 begin // Èä¸ò èãðà - çàâåðøàåì óðîâåíü
6651 gNextMap := s;
6652 gExit := EXIT_ENDLEVELCUSTOM;
6653 end
6654 else // Èíòåðìèññèÿ - ñðàçó çàãðóæàåì êàðòó
6655 g_Game_ChangeMap(s);
6656 end else
6657 begin
6658 // Òàêîé êàðòû íåò, èùåì WAD ôàéë
6659 pw := findDiskWad(MapsDir + P[1]);
6660 g_Console_Add(Format(_lc[I_MSG_NO_MAP_FALLBACK], [s, 'WAD ' + P[1]]));
6661 if FileExists(pw) then
6662 begin
6663 // Ïàðàìåòðà êàðòû íåò, ïîýòîìó ñòàâèì ïåðâóþ èç ôàéëà
6664 SetLength(P, 3);
6665 P[1] := ExtractRelativePath(MapsDir, pw);
6666 P[2] := g_Game_GetFirstMap(MapsDir + P[1]);
6668 s := P[1] + ':\' + P[2];
6670 if g_Map_Exist(MapsDir + s) then
6671 begin
6672 gExitByTrigger := False;
6673 if gGameOn then
6674 begin // Èä¸ò èãðà - çàâåðøàåì óðîâåíü
6675 gNextMap := s;
6676 gExit := EXIT_ENDLEVELCUSTOM;
6677 end
6678 else // Èíòåðìèññèÿ - ñðàçó çàãðóæàåì êàðòó
6679 g_Game_ChangeMap(s);
6680 end else
6681 if P[2] = '' then
6682 g_Console_Add(Format(_lc[I_MSG_NO_MAPS], [P[1]]))
6683 else
6684 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [P[2]]));
6685 end else
6686 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]));
6687 end;
6688 end else
6689 begin
6690 // Óêàçàíî äâà ïàðàìåòðà, çíà÷èò ïåðâûé - WAD ôàéë, à âòîðîé - êàðòà
6691 P[1] := addWadExtension(P[1]);
6692 if FileExists(MapsDir + P[1]) then
6693 begin
6694 // Íàøëè WAD ôàéë
6695 P[2] := UpperCase(P[2]);
6696 s := P[1] + ':\' + P[2];
6698 if g_Map_Exist(MapsDir + s) then
6699 begin // Íàøëè êàðòó
6700 gExitByTrigger := False;
6701 if gGameOn then
6702 begin // Èä¸ò èãðà - çàâåðøàåì óðîâåíü
6703 gNextMap := s;
6704 gExit := EXIT_ENDLEVELCUSTOM;
6705 end
6706 else // Èíòåðìèññèÿ - ñðàçó çàãðóæàåì êàðòó
6707 g_Game_ChangeMap(s);
6708 end else
6709 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [P[2]]));
6710 end else
6711 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]));
6712 end;
6713 end else
6714 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
6715 end
6716 else if cmd = 'nextmap' then
6717 begin
6718 if not(gGameOn or (gState = STATE_INTERCUSTOM)) then
6719 g_Console_Add(_lc[I_MSG_NOT_GAME])
6720 else begin
6721 nm := True;
6722 if Length(P) = 1 then
6723 begin
6724 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
6725 begin
6726 g_Console_Add(cmd + ' <MAP>');
6727 g_Console_Add(cmd + ' <WAD> [MAP]');
6728 end else begin
6729 nm := False;
6730 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
6731 end;
6732 end else
6733 begin
6734 nm := False;
6735 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
6736 begin
6737 if Length(P) < 3 then
6738 begin
6739 // Ïåðâûé ïàðàìåòð - ëèáî êàðòà, ëèáî èìÿ WAD ôàéëà
6740 s := UpperCase(P[1]);
6741 if g_Map_Exist(MapsDir + gGameSettings.WAD + ':\' + s) then
6742 begin // Êàðòà íàøëàñü
6743 gExitByTrigger := False;
6744 gNextMap := s;
6745 nm := True;
6746 end else
6747 begin
6748 // Òàêîé êàðòû íåò, èùåì WAD ôàéë
6749 P[1] := addWadExtension(P[1]);
6750 g_Console_Add(Format(_lc[I_MSG_NO_MAP_FALLBACK], [s, P[1]]));
6751 if FileExists(MapsDir + P[1]) then
6752 begin
6753 // Ïàðàìåòðà êàðòû íåò, ïîýòîìó ñòàâèì ïåðâóþ èç ôàéëà
6754 SetLength(P, 3);
6755 P[2] := g_Game_GetFirstMap(MapsDir + P[1]);
6757 s := P[1] + ':\' + P[2];
6759 if g_Map_Exist(MapsDir + s) then
6760 begin // Óñòàíàâëèâàåì êàðòó
6761 gExitByTrigger := False;
6762 gNextMap := s;
6763 nm := True;
6764 end else
6765 if P[2] = '' then
6766 g_Console_Add(Format(_lc[I_MSG_NO_MAPS], [P[1]]))
6767 else
6768 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [P[2]]));
6769 end else
6770 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]));
6771 end;
6772 end else
6773 begin
6774 // Óêàçàíî äâà ïàðàìåòðà, çíà÷èò ïåðâûé - WAD ôàéë, à âòîðîé - êàðòà
6775 P[1] := addWadExtension(P[1]);
6776 if FileExists(MapsDir + P[1]) then
6777 begin
6778 // Íàøëè WAD ôàéë
6779 P[2] := UpperCase(P[2]);
6780 s := P[1] + ':\' + P[2];
6782 if g_Map_Exist(MapsDir + s) then
6783 begin // Íàøëè êàðòó
6784 gExitByTrigger := False;
6785 gNextMap := s;
6786 nm := True;
6787 end else
6788 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [P[2]]));
6789 end else
6790 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]));
6791 end;
6792 end else
6793 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
6794 end;
6795 if nm then
6796 if gNextMap = '' then
6797 g_Console_Add(_lc[I_MSG_NEXTMAP_UNSET])
6798 else
6799 g_Console_Add(Format(_lc[I_MSG_NEXTMAP_SET], [gNextMap]));
6800 end;
6801 end
6802 else if (cmd = 'endmap') or (cmd = 'goodbye') then
6803 begin
6804 if not gGameOn then
6805 g_Console_Add(_lc[I_MSG_NOT_GAME])
6806 else
6807 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
6808 begin
6809 gExitByTrigger := False;
6810 // Ñëåäóþùàÿ êàðòà íå çàäàíà, ïðîáóåì íàéòè òðèããåð Âûõîä
6811 if (gNextMap = '') and (gTriggers <> nil) then
6812 for a := 0 to High(gTriggers) do
6813 if gTriggers[a].TriggerType = TRIGGER_EXIT then
6814 begin
6815 gExitByTrigger := True;
6816 //gNextMap := gTriggers[a].Data.MapName;
6817 gNextMap := gTriggers[a].tgcMap;
6818 Break;
6819 end;
6820 // Èùåì ñëåäóþùóþ êàðòó â WAD ôàéëå
6821 if gNextMap = '' then
6822 gNextMap := g_Game_GetNextMap();
6823 // Ïðîâåðÿåì, íå çàäàí ëè WAD ôàéë ðåñóðñíîé ñòðîêîé
6824 if not isWadPath(gNextMap) then
6825 s := gGameSettings.WAD + ':\' + gNextMap
6826 else
6827 s := gNextMap;
6828 // Åñëè êàðòà íàéäåíà, âûõîäèì ñ óðîâíÿ
6829 if g_Map_Exist(MapsDir + s) then
6830 gExit := EXIT_ENDLEVELCUSTOM
6831 else
6832 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [gNextMap]));
6833 end else
6834 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
6835 end
6836 else if (cmd = 'event') then
6837 begin
6838 if (Length(P) <= 1) then
6839 begin
6840 for a := 0 to High(gEvents) do
6841 if gEvents[a].Command = '' then
6842 g_Console_Add(gEvents[a].Name + ' <none>')
6843 else
6844 g_Console_Add(gEvents[a].Name + ' "' + gEvents[a].Command + '"');
6845 Exit;
6846 end;
6847 if (Length(P) = 2) then
6848 begin
6849 for a := 0 to High(gEvents) do
6850 if gEvents[a].Name = P[1] then
6851 if gEvents[a].Command = '' then
6852 g_Console_Add(gEvents[a].Name + ' <none>')
6853 else
6854 g_Console_Add(gEvents[a].Name + ' "' + gEvents[a].Command + '"');
6855 Exit;
6856 end;
6857 for a := 0 to High(gEvents) do
6858 if gEvents[a].Name = P[1] then
6859 begin
6860 gEvents[a].Command := '';
6861 for b := 2 to High(P) do
6862 if Pos(' ', P[b]) = 0 then
6863 gEvents[a].Command := gEvents[a].Command + ' ' + P[b]
6864 else
6865 gEvents[a].Command := gEvents[a].Command + ' "' + P[b] + '"';
6866 gEvents[a].Command := Trim(gEvents[a].Command);
6867 Exit;
6868 end;
6869 end
6870 else if cmd = 'suicide' then
6871 begin
6872 if gGameOn then
6873 begin
6874 if g_Game_IsClient then
6875 MC_SEND_CheatRequest(NET_CHEAT_SUICIDE)
6876 else
6877 begin
6878 if gPlayer1 <> nil then
6879 gPlayer1.Damage(SUICIDE_DAMAGE, gPlayer1.UID, 0, 0, HIT_SELF);
6880 if gPlayer2 <> nil then
6881 gPlayer2.Damage(SUICIDE_DAMAGE, gPlayer2.UID, 0, 0, HIT_SELF);
6882 end;
6883 end;
6884 end
6885 else if cmd = 'screenshot' then
6886 begin
6887 g_TakeScreenShot()
6888 end
6889 else if cmd = 'weapon' then
6890 begin
6891 if Length(p) = 2 then
6892 begin
6893 a := WP_FIRST + StrToInt(p[1]) - 1;
6894 if (a >= WP_FIRST) and (a <= WP_LAST) then
6895 gSelectWeapon[0, a] := True
6896 end
6897 end
6898 else if (cmd = 'p1_weapon') or (cmd = 'p2_weapon') then
6899 begin
6900 if Length(p) = 2 then
6901 begin
6902 a := WP_FIRST + StrToInt(p[1]) - 1;
6903 b := ord(cmd[2]) - ord('1');
6904 if (a >= WP_FIRST) and (a <= WP_LAST) then
6905 gSelectWeapon[b, a] := True
6906 end
6907 end
6908 // Êîìàíäû Ñâîåé èãðû:
6909 else if gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT] then
6910 begin
6911 if cmd = 'bot_addred' then
6912 begin
6913 if Length(P) > 1 then
6914 g_Bot_Add(TEAM_RED, StrToIntDef(P[1], 2))
6915 else
6916 g_Bot_Add(TEAM_RED, 2);
6917 end
6918 else if cmd = 'bot_addblue' then
6919 begin
6920 if Length(P) > 1 then
6921 g_Bot_Add(TEAM_BLUE, StrToIntDef(P[1], 2))
6922 else
6923 g_Bot_Add(TEAM_BLUE, 2);
6924 end
6925 else if cmd = 'spectate' then
6926 begin
6927 if not gGameOn then
6928 Exit;
6929 g_Game_Spectate();
6930 end
6931 else if cmd = 'say' then
6932 begin
6933 if g_Game_IsServer and g_Game_IsNet then
6934 begin
6935 if Length(P) > 1 then
6936 begin
6937 chstr := '';
6938 for a := 1 to High(P) do
6939 chstr := chstr + P[a] + ' ';
6941 if Length(chstr) > 200 then SetLength(chstr, 200);
6943 if Length(chstr) < 1 then
6944 begin
6945 g_Console_Add('say <text>');
6946 Exit;
6947 end;
6949 chstr := b_Text_Format(chstr);
6950 MH_SEND_Chat(chstr, NET_CHAT_PLAYER);
6951 end
6952 else g_Console_Add('say <text>');
6953 end else
6954 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6955 end
6956 else if cmd = 'tell' then
6957 begin
6958 if g_Game_IsServer and g_Game_IsNet then
6959 begin
6960 if (Length(P) > 2) and (P[1] <> '') then
6961 begin
6962 chstr := '';
6963 for a := 2 to High(P) do
6964 chstr := chstr + P[a] + ' ';
6966 if Length(chstr) > 200 then SetLength(chstr, 200);
6968 if Length(chstr) < 1 then
6969 begin
6970 g_Console_Add('tell <playername> <text>');
6971 Exit;
6972 end;
6974 pl := g_Net_Client_ByName(P[1]);
6975 if pl <> nil then
6976 MH_SEND_Chat(b_Text_Format(chstr), NET_CHAT_PLAYER, pl^.ID)
6977 else
6978 g_Console_Add(Format(_lc[I_NET_ERR_NAME404], [P[1]]));
6979 end
6980 else g_Console_Add('tell <playername> <text>');
6981 end else
6982 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6983 end
6984 else if (cmd = 'overtime') and not g_Game_IsClient then
6985 begin
6986 if (Length(P) = 1) or (StrToIntDef(P[1], -1) <= 0) then
6987 Exit;
6988 // Äîïîëíèòåëüíîå âðåìÿ:
6989 gGameSettings.TimeLimit := (gTime - gGameStartTime) div 1000 + Word(StrToIntDef(P[1], 0));
6991 g_Console_Add(Format(_lc[I_MSG_TIME_LIMIT],
6992 [gGameSettings.TimeLimit div 3600,
6993 (gGameSettings.TimeLimit div 60) mod 60,
6994 gGameSettings.TimeLimit mod 60]));
6995 if g_Game_IsNet then MH_SEND_GameSettings;
6996 end
6997 else if (cmd = 'rcon_password') and g_Game_IsClient then
6998 begin
6999 if (Length(P) <= 1) then
7000 g_Console_Add('rcon_password <password>')
7001 else
7002 MC_SEND_RCONPassword(P[1]);
7003 end
7004 else if cmd = 'rcon' then
7005 begin
7006 if g_Game_IsClient then
7007 begin
7008 if Length(P) > 1 then
7009 begin
7010 chstr := '';
7011 for a := 1 to High(P) do
7012 chstr := chstr + P[a] + ' ';
7014 if Length(chstr) > 200 then SetLength(chstr, 200);
7016 if Length(chstr) < 1 then
7017 begin
7018 g_Console_Add('rcon <command>');
7019 Exit;
7020 end;
7022 MC_SEND_RCONCommand(chstr);
7023 end
7024 else g_Console_Add('rcon <command>');
7025 end;
7026 end
7027 else if cmd = 'ready' then
7028 begin
7029 if g_Game_IsServer and (gLMSRespawn = LMS_RESPAWN_WARMUP) then
7030 gLMSRespawnTime := gTime + 100;
7031 end
7032 else if (cmd = 'callvote') and g_Game_IsNet then
7033 begin
7034 if Length(P) > 1 then
7035 begin
7036 chstr := '';
7037 for a := 1 to High(P) do begin
7038 if a > 1 then chstr := chstr + ' ';
7039 chstr := chstr + P[a];
7040 end;
7042 if Length(chstr) > 200 then SetLength(chstr, 200);
7044 if Length(chstr) < 1 then
7045 begin
7046 g_Console_Add('callvote <command>');
7047 Exit;
7048 end;
7050 if g_Game_IsClient then
7051 MC_SEND_Vote(True, chstr)
7052 else
7053 g_Game_StartVote(chstr, gPlayer1Settings.Name);
7054 g_Console_Process('vote', True);
7055 end
7056 else
7057 g_Console_Add('callvote <command>');
7058 end
7059 else if (cmd = 'vote') and g_Game_IsNet then
7060 begin
7061 if g_Game_IsClient then
7062 MC_SEND_Vote(False)
7063 else if gVoteInProgress then
7064 begin
7065 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
7066 a := Floor((NetClientCount+1)/2.0) + 1
7067 else
7068 a := Floor(NetClientCount/2.0) + 1;
7069 if gVoted then
7070 begin
7071 Dec(gVoteCount);
7072 gVoted := False;
7073 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_REVOKED], [gPlayer1Settings.Name, gVoteCount, a]), True);
7074 MH_SEND_VoteEvent(NET_VE_REVOKE, gPlayer1Settings.Name, 'a', gVoteCount, a);
7075 end
7076 else
7077 begin
7078 Inc(gVoteCount);
7079 gVoted := True;
7080 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_VOTE], [gPlayer1Settings.Name, gVoteCount, a]), True);
7081 MH_SEND_VoteEvent(NET_VE_VOTE, gPlayer1Settings.Name, 'a', gVoteCount, a);
7082 g_Game_CheckVote;
7083 end;
7084 end;
7085 end
7086 end;
7087 end;
7089 procedure g_TakeScreenShot();
7090 var
7091 a: Word;
7092 FileName: string;
7093 ssdir, t: string;
7094 st: TStream;
7095 ok: Boolean;
7096 begin
7097 if e_NoGraphics then Exit;
7098 ssdir := GameDir+'/screenshots';
7099 if not findFileCI(ssdir, true) then
7100 begin
7101 // try to create dir
7102 try
7103 CreateDir(ssdir);
7104 except
7105 end;
7106 if not findFileCI(ssdir, true) then exit; // alas
7107 end;
7108 try
7109 for a := 1 to High(Word) do
7110 begin
7111 FileName := Format(ssdir+'screenshot%.3d.png', [a]);
7112 t := FileName;
7113 if findFileCI(t, true) then continue;
7114 if not findFileCI(FileName) then
7115 begin
7116 ok := false;
7117 st := createDiskFile(FileName);
7118 try
7119 e_MakeScreenshot(st, gScreenWidth, gScreenHeight);
7120 ok := true;
7121 finally
7122 st.Free();
7123 end;
7124 if not ok then try DeleteFile(FileName); except end else g_Console_Add(Format(_lc[I_CONSOLE_SCREENSHOT], [ExtractFileName(FileName)]));
7125 break;
7126 end;
7127 end;
7128 except
7129 end;
7130 end;
7132 procedure g_Game_InGameMenu(Show: Boolean);
7133 begin
7134 if (g_ActiveWindow = nil) and Show then
7135 begin
7136 if gGameSettings.GameType = GT_SINGLE then
7137 g_GUI_ShowWindow('GameSingleMenu')
7138 else
7139 begin
7140 if g_Game_IsClient then
7141 g_GUI_ShowWindow('GameClientMenu')
7142 else
7143 if g_Game_IsNet then
7144 g_GUI_ShowWindow('GameServerMenu')
7145 else
7146 g_GUI_ShowWindow('GameCustomMenu');
7147 end;
7148 g_Sound_PlayEx('MENU_OPEN');
7150 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
7151 if (not g_Game_IsNet) then
7152 g_Game_Pause(True);
7153 end
7154 else
7155 if (g_ActiveWindow <> nil) and (not Show) then
7156 begin
7157 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
7158 if (not g_Game_IsNet) then
7159 g_Game_Pause(False);
7160 end;
7161 end;
7163 procedure g_Game_Pause (Enable: Boolean);
7164 var
7165 oldPause: Boolean;
7166 begin
7167 if not gGameOn then exit;
7169 if not (gGameSettings.GameType in [GT_SINGLE, GT_CUSTOM]) then exit;
7171 oldPause := gPause;
7172 gPauseMain := Enable;
7174 if (gPause <> oldPause) then g_Game_PauseAllSounds(gPause);
7175 end;
7177 procedure g_Game_HolmesPause (Enable: Boolean);
7178 var
7179 oldPause: Boolean;
7180 begin
7181 if not gGameOn then exit;
7182 if not (gGameSettings.GameType in [GT_SINGLE, GT_CUSTOM]) then exit;
7184 oldPause := gPause;
7185 gPauseHolmes := Enable;
7187 if (gPause <> oldPause) then g_Game_PauseAllSounds(gPause);
7188 end;
7190 procedure g_Game_PauseAllSounds(Enable: Boolean);
7191 var
7192 i: Integer;
7193 begin
7194 // Òðèããåðû:
7195 if gTriggers <> nil then
7196 for i := 0 to High(gTriggers) do
7197 with gTriggers[i] do
7198 if (TriggerType = TRIGGER_SOUND) and
7199 (Sound <> nil) and
7200 Sound.IsPlaying() then
7201 begin
7202 Sound.Pause(Enable);
7203 end;
7205 // Çâóêè èãðîêîâ:
7206 if gPlayers <> nil then
7207 for i := 0 to High(gPlayers) do
7208 if gPlayers[i] <> nil then
7209 gPlayers[i].PauseSounds(Enable);
7211 // Ìóçûêà:
7212 if gMusic <> nil then
7213 gMusic.Pause(Enable);
7214 end;
7216 procedure g_Game_StopAllSounds(all: Boolean);
7217 var
7218 i: Integer;
7219 begin
7220 if gTriggers <> nil then
7221 for i := 0 to High(gTriggers) do
7222 with gTriggers[i] do
7223 if (TriggerType = TRIGGER_SOUND) and
7224 (Sound <> nil) then
7225 Sound.Stop();
7227 if gMusic <> nil then
7228 gMusic.Stop();
7230 if all then
7231 e_StopChannels();
7232 end;
7234 procedure g_Game_UpdateTriggerSounds;
7235 var i: Integer;
7236 begin
7237 if gTriggers <> nil then
7238 for i := 0 to High(gTriggers) do
7239 with gTriggers[i] do
7240 if (TriggerType = TRIGGER_SOUND) and (Sound <> nil) and tgcLocal and Sound.IsPlaying() then
7241 Sound.SetCoordsRect(X, Y, Width, Height, tgcVolume / 255.0)
7242 end;
7244 function g_Game_IsWatchedPlayer(UID: Word): Boolean;
7245 begin
7246 Result := False;
7247 if (gPlayer1 <> nil) and (gPlayer1.UID = UID) then
7248 begin
7249 Result := True;
7250 Exit;
7251 end;
7252 if (gPlayer2 <> nil) and (gPlayer2.UID = UID) then
7253 begin
7254 Result := True;
7255 Exit;
7256 end;
7257 if gSpectMode <> SPECT_PLAYERS then
7258 Exit;
7259 if gSpectPID1 = UID then
7260 begin
7261 Result := True;
7262 Exit;
7263 end;
7264 if gSpectViewTwo and (gSpectPID2 = UID) then
7265 begin
7266 Result := True;
7267 Exit;
7268 end;
7269 end;
7271 function g_Game_IsWatchedTeam(Team: Byte): Boolean;
7272 var
7273 Pl: TPlayer;
7274 begin
7275 Result := False;
7276 if (gPlayer1 <> nil) and (gPlayer1.Team = Team) then
7277 begin
7278 Result := True;
7279 Exit;
7280 end;
7281 if (gPlayer2 <> nil) and (gPlayer2.Team = Team) then
7282 begin
7283 Result := True;
7284 Exit;
7285 end;
7286 if gSpectMode <> SPECT_PLAYERS then
7287 Exit;
7288 Pl := g_Player_Get(gSpectPID1);
7289 if (Pl <> nil) and (Pl.Team = Team) then
7290 begin
7291 Result := True;
7292 Exit;
7293 end;
7294 if gSpectViewTwo then
7295 begin
7296 Pl := g_Player_Get(gSpectPID2);
7297 if (Pl <> nil) and (Pl.Team = Team) then
7298 begin
7299 Result := True;
7300 Exit;
7301 end;
7302 end;
7303 end;
7305 procedure g_Game_Message(Msg: string; Time: Word);
7306 begin
7307 MessageLineLength := (gScreenWidth - 204) div e_CharFont_GetMaxWidth(gMenuFont);
7308 MessageText := b_Text_Wrap(b_Text_Format(Msg), MessageLineLength);
7309 MessageTime := Time;
7310 end;
7312 procedure g_Game_ChatSound(Text: String; Taunt: Boolean = True);
7313 const
7314 punct: Array[0..13] of String =
7315 ('.', ',', ':', ';', '!', '?', '(', ')', '''', '"', '/', '\', '*', '^');
7316 var
7317 i, j: Integer;
7318 ok: Boolean;
7319 fpText: String;
7321 function IsPunctuation(S: String): Boolean;
7322 var
7323 i: Integer;
7324 begin
7325 Result := False;
7326 if Length(S) <> 1 then
7327 Exit;
7328 for i := Low(punct) to High(punct) do
7329 if S = punct[i] then
7330 begin
7331 Result := True;
7332 break;
7333 end;
7334 end;
7335 function FilterPunctuation(S: String): String;
7336 var
7337 i: Integer;
7338 begin
7339 for i := Low(punct) to High(punct) do
7340 S := StringReplace(S, punct[i], ' ', [rfReplaceAll]);
7341 Result := S;
7342 end;
7343 begin
7344 ok := False;
7346 if gUseChatSounds and Taunt and (gChatSounds <> nil) and (Pos(': ', Text) > 0) then
7347 begin
7348 // remove player name
7349 Delete(Text, 1, Pos(': ', Text) + 2 - 1);
7350 // for FullWord check
7351 Text := toLowerCase1251(' ' + Text + ' ');
7352 fpText := FilterPunctuation(Text);
7354 for i := 0 to Length(gChatSounds) - 1 do
7355 begin
7356 ok := True;
7357 for j := 0 to Length(gChatSounds[i].Tags) - 1 do
7358 begin
7359 if gChatSounds[i].FullWord and (not IsPunctuation(gChatSounds[i].Tags[j])) then
7360 ok := Pos(' ' + gChatSounds[i].Tags[j] + ' ', fpText) > 0
7361 else
7362 ok := Pos(gChatSounds[i].Tags[j], Text) > 0;
7363 if not ok then
7364 break;
7365 end;
7366 if ok then
7367 begin
7368 gChatSounds[i].Sound.Play();
7369 break;
7370 end;
7371 end;
7372 end;
7373 if not ok then
7374 g_Sound_PlayEx('SOUND_GAME_RADIO');
7375 end;
7377 procedure g_Game_Announce_GoodShot(SpawnerUID: Word);
7378 var
7379 a: Integer;
7380 begin
7381 case gAnnouncer of
7382 ANNOUNCE_NONE:
7383 Exit;
7384 ANNOUNCE_ME,
7385 ANNOUNCE_MEPLUS:
7386 if not g_Game_IsWatchedPlayer(SpawnerUID) then
7387 Exit;
7388 end;
7389 for a := 0 to 3 do
7390 if goodsnd[a].IsPlaying() then
7391 Exit;
7393 goodsnd[Random(4)].Play();
7394 end;
7396 procedure g_Game_Announce_KillCombo(Param: Integer);
7397 var
7398 UID: Word;
7399 c, n: Byte;
7400 Pl: TPlayer;
7401 Name: String;
7402 begin
7403 UID := Param and $FFFF;
7404 c := Param shr 16;
7405 if c < 2 then
7406 Exit;
7408 Pl := g_Player_Get(UID);
7409 if Pl = nil then
7410 Name := '?'
7411 else
7412 Name := Pl.Name;
7414 case c of
7415 2: begin
7416 n := 0;
7417 g_Console_Add(Format(_lc[I_PLAYER_KILL_2X], [Name]), True);
7418 end;
7419 3: begin
7420 n := 1;
7421 g_Console_Add(Format(_lc[I_PLAYER_KILL_3X], [Name]), True);
7422 end;
7423 4: begin
7424 n := 2;
7425 g_Console_Add(Format(_lc[I_PLAYER_KILL_4X], [Name]), True);
7426 end;
7427 else begin
7428 n := 3;
7429 g_Console_Add(Format(_lc[I_PLAYER_KILL_MX], [Name]), True);
7430 end;
7431 end;
7433 case gAnnouncer of
7434 ANNOUNCE_NONE:
7435 Exit;
7436 ANNOUNCE_ME:
7437 if not g_Game_IsWatchedPlayer(UID) then
7438 Exit;
7439 ANNOUNCE_MEPLUS:
7440 if (not g_Game_IsWatchedPlayer(UID)) and (c < 4) then
7441 Exit;
7442 end;
7444 if killsnd[n].IsPlaying() then
7445 killsnd[n].Stop();
7446 killsnd[n].Play();
7447 end;
7449 procedure g_Game_Announce_BodyKill(SpawnerUID: Word);
7450 var
7451 a: Integer;
7452 begin
7453 case gAnnouncer of
7454 ANNOUNCE_NONE:
7455 Exit;
7456 ANNOUNCE_ME,
7457 ANNOUNCE_MEPLUS:
7458 if not g_Game_IsWatchedPlayer(SpawnerUID) then
7459 Exit;
7460 end;
7461 for a := 0 to 2 do
7462 if hahasnd[a].IsPlaying() then
7463 Exit;
7465 hahasnd[Random(3)].Play();
7466 end;
7468 procedure g_Game_StartVote(Command, Initiator: string);
7469 var
7470 Need: Integer;
7471 begin
7472 if not gVotesEnabled then Exit;
7473 if gGameSettings.GameType <> GT_SERVER then Exit;
7474 if gVoteInProgress or gVotePassed then
7475 begin
7476 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_INPROGRESS], [gVoteCommand]), True);
7477 MH_SEND_VoteEvent(NET_VE_INPROGRESS, gVoteCommand);
7478 Exit;
7479 end;
7480 gVoteInProgress := True;
7481 gVotePassed := False;
7482 gVoteTimer := gTime + gVoteTimeout * 1000;
7483 gVoteCount := 0;
7484 gVoted := False;
7485 gVoteCommand := Command;
7487 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
7488 Need := Floor((NetClientCount+1)/2.0)+1
7489 else
7490 Need := Floor(NetClientCount/2.0)+1;
7491 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_STARTED], [Initiator, Command, Need]), True);
7492 MH_SEND_VoteEvent(NET_VE_STARTED, Initiator, Command, Need);
7493 end;
7495 procedure g_Game_CheckVote;
7496 var
7497 I, Need: Integer;
7498 begin
7499 if gGameSettings.GameType <> GT_SERVER then Exit;
7500 if not gVoteInProgress then Exit;
7502 if (gTime >= gVoteTimer) then
7503 begin
7504 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
7505 Need := Floor((NetClientCount+1)/2.0) + 1
7506 else
7507 Need := Floor(NetClientCount/2.0) + 1;
7508 if gVoteCount >= Need then
7509 begin
7510 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_PASSED], [gVoteCommand]), True);
7511 MH_SEND_VoteEvent(NET_VE_PASSED, gVoteCommand);
7512 gVotePassed := True;
7513 gVoteCmdTimer := gTime + 5000;
7514 end
7515 else
7516 begin
7517 g_Console_Add(_lc[I_MESSAGE_VOTE_FAILED], True);
7518 MH_SEND_VoteEvent(NET_VE_FAILED);
7519 end;
7520 if NetClients <> nil then
7521 for I := Low(NetClients) to High(NetClients) do
7522 if NetClients[i].Used then
7523 NetClients[i].Voted := False;
7524 gVoteInProgress := False;
7525 gVoted := False;
7526 gVoteCount := 0;
7527 end
7528 else
7529 begin
7530 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
7531 Need := Floor((NetClientCount+1)/2.0) + 1
7532 else
7533 Need := Floor(NetClientCount/2.0) + 1;
7534 if gVoteCount >= Need then
7535 begin
7536 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_PASSED], [gVoteCommand]), True);
7537 MH_SEND_VoteEvent(NET_VE_PASSED, gVoteCommand);
7538 gVoteInProgress := False;
7539 gVotePassed := True;
7540 gVoteCmdTimer := gTime + 5000;
7541 gVoted := False;
7542 gVoteCount := 0;
7543 if NetClients <> nil then
7544 for I := Low(NetClients) to High(NetClients) do
7545 if NetClients[i].Used then
7546 NetClients[i].Voted := False;
7547 end;
7548 end;
7549 end;
7551 procedure g_Game_LoadMapList(FileName: string);
7552 var
7553 ListFile: TextFile;
7554 s: string;
7555 begin
7556 MapList := nil;
7557 MapIndex := -1;
7559 if not FileExists(FileName) then Exit;
7561 AssignFile(ListFile, FileName);
7562 Reset(ListFile);
7563 while not EOF(ListFile) do
7564 begin
7565 ReadLn(ListFile, s);
7567 s := Trim(s);
7568 if s = '' then Continue;
7570 SetLength(MapList, Length(MapList)+1);
7571 MapList[High(MapList)] := s;
7572 end;
7573 CloseFile(ListFile);
7574 end;
7576 procedure g_Game_SetDebugMode();
7577 begin
7578 gDebugMode := True;
7579 // ×èòû (äàæå â ñâîåé èãðå):
7580 gCheats := True;
7581 end;
7583 procedure g_Game_SetLoadingText(Text: String; Max: Integer; reWrite: Boolean);
7584 var
7585 i: Word;
7586 begin
7587 if Length(LoadingStat.Msgs) = 0 then
7588 Exit;
7590 with LoadingStat do
7591 begin
7592 if not reWrite then
7593 begin // Ïåðåõîäèì íà ñëåäóþùóþ ñòðîêó èëè ñêðîëëèðóåì:
7594 if NextMsg = Length(Msgs) then
7595 begin // scroll
7596 for i := 0 to High(Msgs)-1 do
7597 Msgs[i] := Msgs[i+1];
7598 end
7599 else
7600 Inc(NextMsg);
7601 end else
7602 if NextMsg = 0 then
7603 Inc(NextMsg);
7605 Msgs[NextMsg-1] := Text;
7606 CurValue := 0;
7607 MaxValue := Max;
7608 ShowCount := 0;
7609 PBarWasHere := false;
7610 end;
7612 g_ActiveWindow := nil;
7614 ProcessLoading(true);
7615 end;
7617 procedure g_Game_StepLoading(Value: Integer = -1);
7618 begin
7619 with LoadingStat do
7620 begin
7621 if Value = -1 then
7622 begin
7623 Inc(CurValue);
7624 Inc(ShowCount);
7625 end
7626 else
7627 CurValue := Value;
7628 if (ShowCount > LOADING_SHOW_STEP) or (Value > -1) then
7629 begin
7630 ShowCount := 0;
7631 ProcessLoading();
7632 end;
7633 end;
7634 end;
7636 procedure g_Game_ClearLoading();
7637 var
7638 len: Word;
7639 begin
7640 with LoadingStat do
7641 begin
7642 CurValue := 0;
7643 MaxValue := 0;
7644 ShowCount := 0;
7645 len := ((gScreenHeight div 3)*2 - 50) div LOADING_INTERLINE;
7646 if len < 1 then len := 1;
7647 SetLength(Msgs, len);
7648 for len := Low(Msgs) to High(Msgs) do
7649 Msgs[len] := '';
7650 NextMsg := 0;
7651 PBarWasHere := false;
7652 end;
7653 end;
7655 procedure Parse_Params(var pars: TParamStrValues);
7656 var
7657 i: Integer;
7658 s: String;
7659 begin
7660 SetLength(pars, 0);
7661 i := 1;
7662 while i <= ParamCount do
7663 begin
7664 s := ParamStr(i);
7665 if (s[1] = '-') and (Length(s) > 1) then
7666 begin
7667 if (s[2] = '-') and (Length(s) > 2) then
7668 begin // Îäèíî÷íûé ïàðàìåòð
7669 SetLength(pars, Length(pars) + 1);
7670 with pars[High(pars)] do
7671 begin
7672 Name := LowerCase(s);
7673 Value := '+';
7674 end;
7675 end
7676 else
7677 if (i < ParamCount) then
7678 begin // Ïàðàìåòð ñî çíà÷åíèåì
7679 Inc(i);
7680 SetLength(pars, Length(pars) + 1);
7681 with pars[High(pars)] do
7682 begin
7683 Name := LowerCase(s);
7684 Value := LowerCase(ParamStr(i));
7685 end;
7686 end;
7687 end;
7689 Inc(i);
7690 end;
7691 end;
7693 function Find_Param_Value(var pars: TParamStrValues; aName: String): String;
7694 var
7695 i: Integer;
7696 begin
7697 Result := '';
7698 for i := 0 to High(pars) do
7699 if pars[i].Name = aName then
7700 begin
7701 Result := pars[i].Value;
7702 Break;
7703 end;
7704 end;
7706 procedure g_Game_Process_Params();
7707 var
7708 pars: TParamStrValues;
7709 map: String;
7710 GMode, n: Byte;
7711 LimT, LimS: Integer;
7712 Opt: LongWord;
7713 Lives: Integer;
7714 s: String;
7715 Port: Integer;
7716 ip: String;
7717 F: TextFile;
7718 begin
7719 Parse_Params(pars);
7721 // Debug mode:
7722 s := Find_Param_Value(pars, '--debug');
7723 if (s <> '') then
7724 begin
7725 g_Game_SetDebugMode();
7726 s := Find_Param_Value(pars, '--netdump');
7727 if (s <> '') then
7728 NetDump := True;
7729 end;
7731 // Connect when game loads
7732 ip := Find_Param_Value(pars, '-connect');
7734 if ip <> '' then
7735 begin
7736 s := Find_Param_Value(pars, '-port');
7737 if (s = '') or not TryStrToInt(s, Port) then
7738 Port := 25666;
7740 s := Find_Param_Value(pars, '-pw');
7742 g_Game_StartClient(ip, Port, s);
7743 Exit;
7744 end;
7746 s := LowerCase(Find_Param_Value(pars, '-dbg-mainwad'));
7747 if (s <> '') then
7748 begin
7749 gDefaultMegawadStart := s;
7750 end;
7752 if (Find_Param_Value(pars, '--dbg-mainwad-restore') <> '') or
7753 (Find_Param_Value(pars, '--dbg-mainwad-default') <> '') then
7754 begin
7755 gDefaultMegawadStart := DF_Default_Megawad_Start;
7756 end;
7758 // Start map when game loads:
7759 map := LowerCase(Find_Param_Value(pars, '-map'));
7760 if isWadPath(map) then
7761 begin
7762 // Game mode:
7763 s := Find_Param_Value(pars, '-gm');
7764 GMode := g_Game_TextToMode(s);
7765 if GMode = GM_NONE then GMode := GM_DM;
7766 if GMode = GM_SINGLE then GMode := GM_COOP;
7768 // Time limit:
7769 s := Find_Param_Value(pars, '-limt');
7770 if (s = '') or (not TryStrToInt(s, LimT)) then
7771 LimT := 0;
7772 if LimT < 0 then
7773 LimT := 0;
7775 // Goal limit:
7776 s := Find_Param_Value(pars, '-lims');
7777 if (s = '') or (not TryStrToInt(s, LimS)) then
7778 LimS := 0;
7779 if LimS < 0 then
7780 LimS := 0;
7782 // Lives limit:
7783 s := Find_Param_Value(pars, '-lives');
7784 if (s = '') or (not TryStrToInt(s, Lives)) then
7785 Lives := 0;
7786 if Lives < 0 then
7787 Lives := 0;
7789 // Options:
7790 s := Find_Param_Value(pars, '-opt');
7791 if (s = '') then
7792 Opt := GAME_OPTION_ALLOWEXIT or GAME_OPTION_BOTVSPLAYER or GAME_OPTION_BOTVSMONSTER
7793 else
7794 Opt := StrToIntDef(s, 0);
7795 if Opt = 0 then
7796 Opt := GAME_OPTION_ALLOWEXIT or GAME_OPTION_BOTVSPLAYER or GAME_OPTION_BOTVSMONSTER;
7798 // Close after map:
7799 s := Find_Param_Value(pars, '--close');
7800 if (s <> '') then
7801 gMapOnce := True;
7803 // Override map to test:
7804 s := LowerCase(Find_Param_Value(pars, '-testmap'));
7805 if s <> '' then
7806 gTestMap := MapsDir + s;
7808 // Delete test map after play:
7809 s := Find_Param_Value(pars, '--testdelete');
7810 if (s <> '') then
7811 begin
7812 gMapToDelete := MapsDir + map;
7813 e_WriteLog('"--testdelete" is deprecated, use --tempdelete.', TMsgType.Fatal);
7814 Halt(1);
7815 end;
7817 // Delete temporary WAD after play:
7818 s := Find_Param_Value(pars, '--tempdelete');
7819 if (s <> '') and (gTestMap <> '') then
7820 begin
7821 gMapToDelete := gTestMap;
7822 gTempDelete := True;
7823 end;
7825 // Number of players:
7826 s := Find_Param_Value(pars, '-pl');
7827 if (s = '') then
7828 n := DEFAULT_PLAYERS
7829 else
7830 n := StrToIntDef(s, DEFAULT_PLAYERS);
7832 // Start:
7833 s := Find_Param_Value(pars, '-port');
7834 if (s = '') or not TryStrToInt(s, Port) then
7835 g_Game_StartCustom(map, GMode, LimT, LimS, Lives, Opt, n)
7836 else
7837 g_Game_StartServer(map, GMode, LimT, LimS, Lives, Opt, n, 0, Port);
7838 end;
7840 // Execute script when game loads:
7841 s := Find_Param_Value(pars, '-exec');
7842 if s <> '' then
7843 begin
7844 if not isWadPath(s) then
7845 s := GameDir + '/' + s;
7847 {$I-}
7848 AssignFile(F, s);
7849 Reset(F);
7850 if IOResult <> 0 then
7851 begin
7852 e_WriteLog(Format(_lc[I_SIMPLE_ERROR], ['Failed to read file: ' + s]), TMsgType.Warning);
7853 g_Console_Add(Format(_lc[I_CONSOLE_ERROR_READ], [s]));
7854 CloseFile(F);
7855 Exit;
7856 end;
7857 e_WriteLog('Executing script: ' + s, TMsgType.Notify);
7858 g_Console_Add(Format(_lc[I_CONSOLE_EXEC], [s]));
7860 while not EOF(F) do
7861 begin
7862 ReadLn(F, s);
7863 if IOResult <> 0 then
7864 begin
7865 e_WriteLog(Format(_lc[I_SIMPLE_ERROR], ['Failed to read file: ' + s]), TMsgType.Warning);
7866 g_Console_Add(Format(_lc[I_CONSOLE_ERROR_READ], [s]));
7867 CloseFile(F);
7868 Exit;
7869 end;
7870 if Pos('#', s) <> 1 then // script comment
7871 g_Console_Process(s, True);
7872 end;
7874 CloseFile(F);
7875 {$I+}
7876 end;
7878 SetLength(pars, 0);
7879 end;
7881 begin
7882 conRegVar('pf_draw_frame', @g_profile_frame_draw, 'draw frame rendering profiles', 'render profiles');
7883 //conRegVar('pf_update_frame', @g_profile_frame_update, 'draw frame updating profiles', 'update profiles');
7884 conRegVar('pf_coldet', @g_profile_collision, 'draw collision detection profiles', 'coldet profiles');
7885 conRegVar('pf_los', @g_profile_los, 'draw monster LOS profiles', 'monster LOS profiles');
7887 conRegVar('r_sq_draw', @gdbg_map_use_accel_render, 'accelerated spatial queries in rendering', 'accelerated rendering');
7888 conRegVar('cd_sq_enabled', @gdbg_map_use_accel_coldet, 'accelerated spatial queries in map coldet', 'accelerated map coldet');
7889 conRegVar('mon_sq_enabled', @gmon_debug_use_sqaccel, 'accelerated spatial queries for monsters', 'accelerated monster coldet');
7890 conRegVar('wtrace_sq_enabled', @gwep_debug_fast_trace, 'accelerated spatial queries for weapon hitscan trace', 'accelerated weapon hitscan');
7892 conRegVar('pr_enabled', @gpart_dbg_enabled, 'enable/disable particles', 'particles');
7893 conRegVar('pr_phys_enabled', @gpart_dbg_phys_enabled, 'enable/disable particle physics', 'particle physics');
7895 conRegVar('los_enabled', @gmon_dbg_los_enabled, 'enable/disable monster LOS calculations', 'monster LOS', true);
7896 conRegVar('mon_think', @gmon_debug_think, 'enable/disable monster thinking', 'monster thinking', true);
7898 {$IFDEF ENABLE_HOLMES}
7899 conRegVar('dbg_holmes', @g_holmes_enabled, 'enable/disable Holmes', 'Holmes', true);
7900 {$ENDIF}
7902 conRegVar('dbg_ignore_level_bounds', @g_dbg_ignore_bounds, 'ignore level bounds', '', false);
7904 conRegVar('r_scale', @g_dbg_scale, 0.01, 100.0, 'render scale', '', false);
7906 conRegVar('light_enabled', @gwin_k8_enable_light_experiments, 'enable/disable dynamic lighting', 'lighting');
7907 conRegVar('light_player_halo', @g_playerLight, 'enable/disable player halo', 'player light halo');
7909 conRegVar('r_smallmap_align_h', @r_smallmap_h, 'halign: 0: left; 1: center; 2: right', 'horizontal aligning of small maps');
7910 conRegVar('r_smallmap_align_v', @r_smallmap_v, 'valign: 0: top; 1: center; 2: bottom', 'vertial aligning of small maps');
7912 conRegVar('r_showfps', @gShowFPS, 'draw fps counter', 'draw fps counter');
7913 conRegVar('r_showtime', @gShowTime, 'show game time', 'show game time');
7914 end.