DEADSOFTWARE

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