DEADSOFTWARE

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