DEADSOFTWARE

fixed weapon autochange
[d2df-sdl.git] / src / game / g_game.pas
1 (* Copyright (C) Doom 2D: Forever Developers
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, either version 3 of the License, or
6 * (at your option) any later version.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
15 *)
16 {$INCLUDE ../shared/a_modes.inc}
17 unit g_game;
19 interface
21 uses
22 SysUtils, Classes,
23 MAPDEF,
24 g_basic, g_player, e_graphics, g_res_downloader,
25 g_sound, g_gui, utils, md5, mempool, xprofiler,
26 g_touch, g_weapons;
28 type
29 TGameSettings = record
30 GameType: Byte;
31 GameMode: Byte;
32 TimeLimit: Word;
33 GoalLimit: Word;
34 WarmupTime: Word;
35 MaxLives: Byte;
36 Options: LongWord;
37 WAD: String;
38 end;
40 TGameEvent = record
41 Name: String;
42 Command: String;
43 end;
45 TDelayedEvent = record
46 Pending: Boolean;
47 Time: LongWord;
48 DEType: Byte;
49 DENum: Integer;
50 DEStr: String;
51 end;
53 TChatSound = record
54 Sound: TPlayableSound;
55 Tags: Array of String;
56 FullWord: Boolean;
57 end;
59 TPlayerSettings = record
60 Name: String;
61 Model: String;
62 Color: TRGB;
63 Team: Byte;
64 end;
66 TMegaWADInfo = record
67 Name: String;
68 Description: String;
69 Author: String;
70 Pic: String;
71 end;
73 THearPoint = record
74 Active: Boolean;
75 Coords: TDFPoint;
76 end;
78 function g_Game_IsNet(): Boolean;
79 function g_Game_IsServer(): Boolean;
80 function g_Game_IsClient(): Boolean;
81 procedure g_Game_Init();
82 procedure g_Game_Free (freeTextures: Boolean=true);
83 procedure g_Game_LoadData();
84 procedure g_Game_FreeData();
85 procedure g_Game_Update();
86 procedure g_Game_Draw();
87 procedure g_Game_Quit();
88 procedure g_Game_SetupScreenSize();
89 procedure g_Game_ChangeResolution(newWidth, newHeight: Word; nowFull, nowMax: Boolean);
90 function g_Game_ModeToText(Mode: Byte): string;
91 function g_Game_TextToMode(Mode: string): Byte;
92 procedure g_Game_ExecuteEvent(Name: String);
93 function g_Game_DelayEvent(DEType: Byte; Time: LongWord; Num: Integer = 0; Str: String = ''): Integer;
94 procedure g_Game_AddPlayer(Team: Byte = TEAM_NONE);
95 procedure g_Game_RemovePlayer();
96 procedure g_Game_Spectate();
97 procedure g_Game_SpectateCenterView();
98 procedure g_Game_StartSingle(Map: String; TwoPlayers: Boolean; nPlayers: Byte);
99 procedure g_Game_StartCustom(Map: String; GameMode: Byte; TimeLimit, GoalLimit: Word; MaxLives: Byte; Options: LongWord; nPlayers: Byte);
100 procedure g_Game_StartServer(Map: String; GameMode: Byte; TimeLimit, GoalLimit: Word; MaxLives: Byte; Options: LongWord; nPlayers: Byte; IPAddr: LongWord; Port: Word);
101 procedure g_Game_StartClient(Addr: String; Port: Word; PW: String);
102 procedure g_Game_Restart();
103 procedure g_Game_RestartLevel();
104 procedure g_Game_RestartRound(NoMapRestart: Boolean = False);
105 procedure g_Game_ClientWAD(NewWAD: String; WHash: TMD5Digest);
106 procedure g_Game_SaveOptions();
107 function g_Game_StartMap(Map: String; Force: Boolean = False; const oldMapPath: AnsiString=''): Boolean;
108 procedure g_Game_ChangeMap(const MapPath: String);
109 procedure g_Game_ExitLevel(const Map: AnsiString);
110 function g_Game_GetFirstMap(WAD: String): String;
111 function g_Game_GetNextMap(): String;
112 procedure g_Game_NextLevel();
113 procedure g_Game_Pause(Enable: Boolean);
114 procedure g_Game_HolmesPause(Enable: Boolean);
115 procedure g_Game_InGameMenu(Show: Boolean);
116 function g_Game_IsWatchedPlayer(UID: Word): Boolean;
117 function g_Game_IsWatchedTeam(Team: Byte): Boolean;
118 procedure g_Game_Message(Msg: String; Time: Word);
119 procedure g_Game_LoadMapList(FileName: String);
120 procedure g_Game_PauseAllSounds(Enable: Boolean);
121 procedure g_Game_StopAllSounds(all: Boolean);
122 procedure g_Game_UpdateTriggerSounds();
123 function g_Game_GetMegaWADInfo(WAD: String): TMegaWADInfo;
124 procedure g_Game_ChatSound(Text: String; Taunt: Boolean = True);
125 procedure g_Game_Announce_GoodShot(SpawnerUID: Word);
126 procedure g_Game_Announce_KillCombo(Param: Integer);
127 procedure g_Game_Announce_BodyKill(SpawnerUID: Word);
128 procedure g_Game_StartVote(Command, Initiator: string);
129 procedure g_Game_CheckVote;
130 procedure g_TakeScreenShot();
131 procedure g_FatalError(Text: String);
132 procedure g_SimpleError(Text: String);
133 function g_Game_IsTestMap(): Boolean;
134 procedure g_Game_DeleteTestMap();
135 procedure GameCVars(P: SSArray);
136 procedure GameCommands(P: SSArray);
137 procedure GameCheats(P: SSArray);
138 procedure DebugCommands(P: SSArray);
139 procedure g_Game_Process_Params;
140 procedure g_Game_SetLoadingText(Text: String; Max: Integer; reWrite: Boolean);
141 procedure g_Game_StepLoading(Value: Integer = -1);
142 procedure g_Game_ClearLoading();
143 procedure g_Game_SetDebugMode();
144 procedure DrawLoadingStat();
146 { procedure SetWinPause(Enable: Boolean); }
148 const
149 GAME_TICK = 28;
151 LOADING_SHOW_STEP = 100;
152 LOADING_INTERLINE = 20;
154 GT_NONE = 0;
155 GT_SINGLE = 1;
156 GT_CUSTOM = 2;
157 GT_SERVER = 3;
158 GT_CLIENT = 4;
160 GM_NONE = 0;
161 GM_DM = 1;
162 GM_TDM = 2;
163 GM_CTF = 3;
164 GM_COOP = 4;
165 GM_SINGLE = 5;
167 MESSAGE_DIKEY = WM_USER + 1;
169 EXIT_QUIT = 1;
170 EXIT_SIMPLE = 2;
171 EXIT_RESTART = 3;
172 EXIT_ENDLEVELSINGLE = 4;
173 EXIT_ENDLEVELCUSTOM = 5;
175 GAME_OPTION_RESERVED = 1;
176 GAME_OPTION_TEAMDAMAGE = 2;
177 GAME_OPTION_ALLOWEXIT = 4;
178 GAME_OPTION_WEAPONSTAY = 8;
179 GAME_OPTION_MONSTERS = 16;
180 GAME_OPTION_BOTVSPLAYER = 32;
181 GAME_OPTION_BOTVSMONSTER = 64;
183 STATE_NONE = 0;
184 STATE_MENU = 1;
185 STATE_FOLD = 2;
186 STATE_INTERCUSTOM = 3;
187 STATE_INTERSINGLE = 4;
188 STATE_INTERTEXT = 5;
189 STATE_INTERPIC = 6;
190 STATE_ENDPIC = 7;
191 STATE_SLIST = 8;
193 LMS_RESPAWN_NONE = 0;
194 LMS_RESPAWN_WARMUP = 1;
195 LMS_RESPAWN_FINAL = 2;
197 SPECT_NONE = 0;
198 SPECT_STATS = 1;
199 SPECT_MAPVIEW = 2;
200 SPECT_PLAYERS = 3;
202 DE_GLOBEVENT = 0;
203 DE_BFGHIT = 1;
204 DE_KILLCOMBO = 2;
205 DE_BODYKILL = 3;
207 ANNOUNCE_NONE = 0;
208 ANNOUNCE_ME = 1;
209 ANNOUNCE_MEPLUS = 2;
210 ANNOUNCE_ALL = 3;
212 CONFIG_FILENAME = 'Doom2DF.cfg';
213 LOG_FILENAME = 'Doom2DF.log';
215 TEST_MAP_NAME = '$$$_TEST_$$$';
217 STD_PLAYER_MODEL = 'Doomer';
219 var
220 gStdFont: DWORD;
221 gGameSettings: TGameSettings;
222 gPlayer1Settings: TPlayerSettings;
223 gPlayer2Settings: TPlayerSettings;
224 gGameOn: Boolean;
225 gPlayerScreenSize: TDFPoint;
226 gPlayer1ScreenCoord: TDFPoint;
227 gPlayer2ScreenCoord: TDFPoint;
228 gPlayer1: TPlayer = nil;
229 gPlayer2: TPlayer = nil;
230 gPlayerDrawn: TPlayer = nil;
231 gTime: LongWord;
232 gSwitchGameMode: Byte = GM_DM;
233 gHearPoint1, gHearPoint2: THearPoint;
234 gSoundEffectsDF: Boolean = False;
235 gSoundTriggerTime: Word = 0;
236 gAnnouncer: Byte = ANNOUNCE_NONE;
237 goodsnd: array[0..3] of TPlayableSound;
238 killsnd: array[0..3] of TPlayableSound;
239 hahasnd: array[0..2] of TPlayableSound;
240 sound_get_flag: array[0..1] of TPlayableSound;
241 sound_lost_flag: array[0..1] of TPlayableSound;
242 sound_ret_flag: array[0..1] of TPlayableSound;
243 sound_cap_flag: array[0..1] of TPlayableSound;
244 gBodyKillEvent: Integer = -1;
245 gDefInterTime: ShortInt = -1;
246 gInterEndTime: LongWord = 0;
247 gInterTime: LongWord = 0;
248 gServInterTime: Byte = 0;
249 gGameStartTime: LongWord = 0;
250 gTotalMonsters: Integer = 0;
251 gPauseMain: Boolean = false;
252 gPauseHolmes: Boolean = false;
253 gShowTime: Boolean = 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, WP_FIRST..WP_LAST] of Boolean; // [player, weapon]
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, 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 i: Integer;
1508 begin
1509 if (plr = nil) then exit;
1510 if (p = 2) then time := 1000 else time := 1;
1511 strafeDir := MoveButton shr 4;
1512 MoveButton := MoveButton and $0F;
1514 if gPlayerAction[p, ACTION_MOVELEFT] and (not gPlayerAction[p, ACTION_MOVERIGHT]) then
1515 MoveButton := 1 // Íàæàòà òîëüêî "Âëåâî"
1516 else if (not gPlayerAction[p, ACTION_MOVELEFT]) and gPlayerAction[p, ACTION_MOVERIGHT] then
1517 MoveButton := 2 // Íàæàòà òîëüêî "Âïðàâî"
1518 else if (not gPlayerAction[p, ACTION_MOVELEFT]) and (not gPlayerAction[p, ACTION_MOVERIGHT]) then
1519 MoveButton := 0; // Íå íàæàòû íè "Âëåâî", íè "Âïðàâî"
1521 // Ñåé÷àñ èëè ðàíüøå áûëè íàæàòû "Âëåâî"/"Âïðàâî" => ïåðåäàåì èãðîêó:
1522 if MoveButton = 1 then
1523 plr.PressKey(KEY_LEFT, time)
1524 else if MoveButton = 2 then
1525 plr.PressKey(KEY_RIGHT, time);
1527 // if we have "strafe" key, turn off old strafe mechanics
1528 if gPlayerAction[p, ACTION_STRAFE] then
1529 begin
1530 // new strafe mechanics
1531 if (strafeDir = 0) then
1532 strafeDir := MoveButton; // start strafing
1533 // now set direction according to strafe (reversed)
1534 if (strafeDir = 2) then
1535 plr.SetDirection(TDirection.D_LEFT)
1536 else if (strafeDir = 1) then
1537 plr.SetDirection(TDirection.D_RIGHT)
1538 end
1539 else
1540 begin
1541 strafeDir := 0; // not strafing anymore
1542 // Ðàíüøå áûëà íàæàòà "Âïðàâî", à ñåé÷àñ "Âëåâî" => áåæèì âïðàâî, ñìîòðèì âëåâî:
1543 if (MoveButton = 2) and gPlayerAction[p, ACTION_MOVELEFT] then
1544 plr.SetDirection(TDirection.D_LEFT)
1545 // Ðàíüøå áûëà íàæàòà "Âëåâî", à ñåé÷àñ "Âïðàâî" => áåæèì âëåâî, ñìîòðèì âïðàâî:
1546 else if (MoveButton = 1) and gPlayerAction[p, ACTION_MOVERIGHT] then
1547 plr.SetDirection(TDirection.D_RIGHT)
1548 // ×òî-òî áûëî íàæàòî è íå èçìåíèëîñü => êóäà áåæèì, òóäà è ñìîòðèì:
1549 else if MoveButton <> 0 then
1550 plr.SetDirection(TDirection(MoveButton-1))
1551 end;
1553 // fix movebutton state
1554 MoveButton := MoveButton or (strafeDir shl 4);
1556 // Îñòàëüíûå êëàâèøè:
1557 if gPlayerAction[p, ACTION_JUMP] then plr.PressKey(KEY_JUMP, time);
1558 if gPlayerAction[p, ACTION_LOOKUP] then plr.PressKey(KEY_UP, time);
1559 if gPlayerAction[p, ACTION_LOOKDOWN] then plr.PressKey(KEY_DOWN, time);
1560 if gPlayerAction[p, ACTION_ATTACK] then plr.PressKey(KEY_FIRE);
1561 if gPlayerAction[p, ACTION_WEAPNEXT] then plr.PressKey(KEY_NEXTWEAPON);
1562 if gPlayerAction[p, ACTION_WEAPPREV] then plr.PressKey(KEY_PREVWEAPON);
1563 if gPlayerAction[p, ACTION_ACTIVATE] then plr.PressKey(KEY_OPEN);
1565 for i := WP_FIRST to WP_LAST do
1566 begin
1567 if gSelectWeapon[p, i] then
1568 begin
1569 plr.QueueWeaponSwitch(i); // all choices are passed there, and god will take the best
1570 gSelectWeapon[p, i] := False
1571 end
1572 end;
1574 // HACK: add dynlight here
1575 if gwin_k8_enable_light_experiments then
1576 begin
1577 if e_KeyPressed(IK_F8) and gGameOn and (not gConsoleShow) and (g_ActiveWindow = nil) then
1578 begin
1579 g_playerLight := true;
1580 end;
1581 if e_KeyPressed(IK_F9) and gGameOn and (not gConsoleShow) and (g_ActiveWindow = nil) then
1582 begin
1583 g_playerLight := false;
1584 end;
1585 end;
1587 if gwin_has_stencil and g_playerLight then g_AddDynLight(plr.GameX+32, plr.GameY+40, 128, 1, 1, 0, 0.6);
1588 end;
1590 procedure g_Game_Update();
1591 var
1592 Msg: g_gui.TMessage;
1593 Time: Int64;
1594 a: Byte;
1595 w: Word;
1596 i, b: Integer;
1598 function sendMonsPos (mon: TMonster): Boolean;
1599 begin
1600 result := false; // don't stop
1601 // this will also reset "need-send" flag
1602 if mon.gncNeedSend then
1603 begin
1604 MH_SEND_MonsterPos(mon.UID);
1605 end
1606 else if (mon.MonsterType = MONSTER_BARREL) then
1607 begin
1608 if (mon.GameVelX <> 0) or (mon.GameVelY <> 0) then MH_SEND_MonsterPos(mon.UID);
1609 end
1610 else if (mon.MonsterState <> MONSTATE_SLEEP) then
1611 begin
1612 if (mon.MonsterState <> MONSTATE_DEAD) or (mon.GameVelX <> 0) or (mon.GameVelY <> 0) then MH_SEND_MonsterPos(mon.UID);
1613 end;
1614 end;
1616 function sendMonsPosUnexpected (mon: TMonster): Boolean;
1617 begin
1618 result := false; // don't stop
1619 // this will also reset "need-send" flag
1620 if mon.gncNeedSend then MH_SEND_MonsterPos(mon.UID);
1621 end;
1623 var
1624 reliableUpdate: Boolean;
1625 begin
1626 g_ResetDynlights();
1627 framePool.reset();
1629 // Ïîðà âûêëþ÷àòü èãðó:
1630 if gExit = EXIT_QUIT then
1631 Exit;
1632 // Èãðà çàêîí÷èëàñü - îáðàáàòûâàåì:
1633 if gExit <> 0 then
1634 begin
1635 EndGame();
1636 if gExit = EXIT_QUIT then
1637 Exit;
1638 end;
1640 // ×èòàåì êëàâèàòóðó è äæîéñòèê, åñëè îêíî àêòèâíî
1641 // no need to, as we'll do it in event handler
1643 // Îáíîâëÿåì êîíñîëü (äâèæåíèå è ñîîáùåíèÿ):
1644 g_Console_Update();
1646 if (NetMode = NET_NONE) and (g_Game_IsNet) and (gGameOn or (gState in [STATE_FOLD, STATE_INTERCUSTOM])) then
1647 begin
1648 gExit := EXIT_SIMPLE;
1649 EndGame();
1650 Exit;
1651 end;
1653 case gState of
1654 STATE_INTERSINGLE, // Ñòàòèñòêà ïîñëå ïðîõîæäåíèÿ óðîâíÿ â Îäèíî÷íîé èãðå
1655 STATE_INTERCUSTOM, // Ñòàòèñòêà ïîñëå ïðîõîæäåíèÿ óðîâíÿ â Ñâîåé èãðå
1656 STATE_INTERTEXT, // Òåêñò ìåæäó óðîâíÿìè
1657 STATE_INTERPIC: // Êàðòèíêà ìåæäó óðîâíÿìè
1658 begin
1659 if g_Game_IsNet and g_Game_IsServer then
1660 begin
1661 gInterTime := gInterTime + GAME_TICK;
1662 a := Min((gInterEndTime - gInterTime) div 1000 + 1, 255);
1663 if a <> gServInterTime then
1664 begin
1665 gServInterTime := a;
1666 MH_SEND_TimeSync(gServInterTime);
1667 end;
1668 end;
1670 if (not g_Game_IsClient) and
1674 e_KeyPressed(IK_RETURN) or e_KeyPressed(IK_KPRETURN) or e_KeyPressed(IK_SPACE) or
1675 e_KeyPressed(VK_FIRE) or e_KeyPressed(VK_OPEN) or
1676 e_KeyPressed(JOY0_ATTACK) or e_KeyPressed(JOY1_ATTACK) or
1677 e_KeyPressed(JOY2_ATTACK) or e_KeyPressed(JOY3_ATTACK)
1679 and (not gJustChatted) and (not gConsoleShow) and (not gChatShow)
1680 and (g_ActiveWindow = nil)
1682 or (g_Game_IsNet and (gInterTime > gInterEndTime))
1684 then
1685 begin // Íàæàëè <Enter>/<Ïðîáåë> èëè ïðîøëî äîñòàòî÷íî âðåìåíè:
1686 g_Game_StopAllSounds(True);
1688 if gMapOnce then // Ýòî áûë òåñò
1689 gExit := EXIT_SIMPLE
1690 else
1691 if gNextMap <> '' then // Ïåðåõîäèì íà ñëåäóþùóþ êàðòó
1692 g_Game_ChangeMap(gNextMap)
1693 else // Ñëåäóþùåé êàðòû íåò
1694 begin
1695 if gGameSettings.GameType in [GT_CUSTOM, GT_SERVER] then
1696 begin
1697 // Âûõîä â ãëàâíîå ìåíþ:
1698 g_Game_Free;
1699 g_GUI_ShowWindow('MainMenu');
1700 gMusic.SetByName('MUSIC_MENU');
1701 gMusic.Play();
1702 gState := STATE_MENU;
1703 end else
1704 begin
1705 // Ôèíàëüíàÿ êàðòèíêà:
1706 g_Game_ExecuteEvent('onwadend');
1707 g_Game_Free();
1708 if not gMusic.SetByName('MUSIC_endmus') then
1709 gMusic.SetByName('MUSIC_STDENDMUS');
1710 gMusic.Play();
1711 gState := STATE_ENDPIC;
1712 end;
1713 g_Game_ExecuteEvent('ongameend');
1714 end;
1716 Exit;
1717 end;
1719 if gState = STATE_INTERTEXT then
1720 if InterText.counter > 0 then
1721 InterText.counter := InterText.counter - 1;
1722 end;
1724 STATE_FOLD: // Çàòóõàíèå ýêðàíà
1725 begin
1726 if EndingGameCounter = 0 then
1727 begin
1728 // Çàêîí÷èëñÿ óðîâåíü â Ñâîåé èãðå:
1729 if gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT] then
1730 begin
1731 if gLastMap and (gGameSettings.GameMode = GM_COOP) then
1732 begin
1733 g_Game_ExecuteEvent('onwadend');
1734 if not gMusic.SetByName('MUSIC_endmus') then
1735 gMusic.SetByName('MUSIC_STDENDMUS');
1736 end
1737 else
1738 gMusic.SetByName('MUSIC_ROUNDMUS');
1740 gMusic.Play();
1741 gState := STATE_INTERCUSTOM;
1742 e_UnpressAllKeys();
1743 end
1744 else // Çàêîí÷èëàñü ïîñëåäíÿÿ êàðòà â Îäèíî÷íîé èãðå
1745 begin
1746 gMusic.SetByName('MUSIC_INTERMUS');
1747 gMusic.Play();
1748 gState := STATE_INTERSINGLE;
1749 e_UnpressAllKeys();
1750 end;
1751 g_Game_ExecuteEvent('oninter');
1752 end
1753 else
1754 DecMin(EndingGameCounter, 6, 0);
1755 end;
1757 STATE_ENDPIC: // Êàðòèíêà îêîí÷àíèÿ ìåãàÂàäà
1758 begin
1759 if gMapOnce then // Ýòî áûë òåñò
1760 begin
1761 gExit := EXIT_SIMPLE;
1762 Exit;
1763 end;
1764 end;
1766 STATE_SLIST:
1767 g_Serverlist_Control(slCurrent, slTable);
1768 end;
1770 // Ñòàòèñòèêà ïî Tab:
1771 if gGameOn then
1772 IsDrawStat := (not gConsoleShow) and (not gChatShow) and (gGameSettings.GameType <> GT_SINGLE) and g_Console_Action(ACTION_SCORES);
1774 // Èãðà èäåò:
1775 if gGameOn and not gPause and (gState <> STATE_FOLD) then
1776 begin
1777 // Âðåìÿ += 28 ìèëëèñåêóíä:
1778 gTime := gTime + GAME_TICK;
1780 // Ñîîáùåíèå ïîñåðåäèíå ýêðàíà:
1781 if MessageTime = 0 then
1782 MessageText := '';
1783 if MessageTime > 0 then
1784 MessageTime := MessageTime - 1;
1786 if (g_Game_IsServer) then
1787 begin
1788 // Áûë çàäàí ëèìèò âðåìåíè:
1789 if (gGameSettings.TimeLimit > 0) then
1790 if (gTime - gGameStartTime) div 1000 >= gGameSettings.TimeLimit then
1791 begin // Îí ïðîøåë => êîíåö óðîâíÿ
1792 g_Game_NextLevel();
1793 Exit;
1794 end;
1796 // Íàäî ðåñïàâíèòü èãðîêîâ â LMS:
1797 if (gLMSRespawn > LMS_RESPAWN_NONE) and (gLMSRespawnTime < gTime) then
1798 g_Game_RestartRound(gLMSSoftSpawn);
1800 // Ïðîâåðèì ðåçóëüòàò ãîëîñîâàíèÿ, åñëè âðåìÿ ïðîøëî
1801 if gVoteInProgress and (gVoteTimer < gTime) then
1802 g_Game_CheckVote
1803 else if gVotePassed and (gVoteCmdTimer < gTime) then
1804 begin
1805 g_Console_Process(gVoteCommand);
1806 gVoteCommand := '';
1807 gVotePassed := False;
1808 end;
1810 // Çàìåðÿåì âðåìÿ çàõâàòà ôëàãîâ
1811 if gFlags[FLAG_RED].State = FLAG_STATE_CAPTURED then
1812 gFlags[FLAG_RED].CaptureTime := gFlags[FLAG_RED].CaptureTime + GAME_TICK;
1813 if gFlags[FLAG_BLUE].State = FLAG_STATE_CAPTURED then
1814 gFlags[FLAG_BLUE].CaptureTime := gFlags[FLAG_BLUE].CaptureTime + GAME_TICK;
1816 // Áûë çàäàí ëèìèò ïîáåä:
1817 if (gGameSettings.GoalLimit > 0) then
1818 begin
1819 b := 0;
1821 if gGameSettings.GameMode = GM_DM then
1822 begin // Â DM èùåì èãðîêà ñ max ôðàãàìè
1823 for i := 0 to High(gPlayers) do
1824 if gPlayers[i] <> nil then
1825 if gPlayers[i].Frags > b then
1826 b := gPlayers[i].Frags;
1827 end
1828 else
1829 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
1830 begin //  CTF/TDM âûáèðàåì êîìàíäó ñ íàèáîëüøèì ñ÷åòîì
1831 b := Max(gTeamStat[TEAM_RED].Goals, gTeamStat[TEAM_BLUE].Goals);
1832 end;
1834 // Ëèìèò ïîáåä íàáðàí => êîíåö óðîâíÿ:
1835 if b >= gGameSettings.GoalLimit then
1836 begin
1837 g_Game_NextLevel();
1838 Exit;
1839 end;
1840 end;
1842 // Îáðàáàòûâàåì êëàâèøè èãðîêîâ:
1843 if gPlayer1 <> nil then gPlayer1.ReleaseKeys();
1844 if gPlayer2 <> nil then gPlayer2.ReleaseKeys();
1845 if (not gConsoleShow) and (not gChatShow) and (g_ActiveWindow = nil) then
1846 begin
1847 ProcessPlayerControls(gPlayer1, 0, P1MoveButton);
1848 ProcessPlayerControls(gPlayer2, 1, P2MoveButton);
1849 end // if not console
1850 else
1851 begin
1852 if g_Game_IsNet and (gPlayer1 <> nil) then gPlayer1.PressKey(KEY_CHAT, 10000);
1853 end;
1854 // process weapon switch queue
1855 end; // if server
1857 // Íàáëþäàòåëü
1858 if (gPlayer1 = nil) and (gPlayer2 = nil) and
1859 (not gConsoleShow) and (not gChatShow) and (g_ActiveWindow = nil) then
1860 begin
1861 if not gSpectKeyPress then
1862 begin
1863 if gPlayerAction[0, ACTION_JUMP] and (not gSpectAuto) then
1864 begin
1865 // switch spect mode
1866 case gSpectMode of
1867 SPECT_NONE: ; // not spectator
1868 SPECT_STATS,
1869 SPECT_MAPVIEW: Inc(gSpectMode);
1870 SPECT_PLAYERS: gSpectMode := SPECT_STATS; // reset to 1
1871 end;
1872 gSpectKeyPress := True;
1873 end;
1874 if (gSpectMode = SPECT_MAPVIEW)
1875 and (not gSpectAuto) then
1876 begin
1877 if gPlayerAction[0, ACTION_MOVELEFT] then
1878 gSpectX := Max(gSpectX - gSpectStep, 0);
1879 if gPlayerAction[0, ACTION_MOVERIGHT] then
1880 gSpectX := Min(gSpectX + gSpectStep, gMapInfo.Width - gScreenWidth);
1881 if gPlayerAction[0, ACTION_LOOKUP] then
1882 gSpectY := Max(gSpectY - gSpectStep, 0);
1883 if gPlayerAction[0, ACTION_LOOKDOWN] then
1884 gSpectY := Min(gSpectY + gSpectStep, gMapInfo.Height - gScreenHeight);
1885 if gPlayerAction[0, ACTION_WEAPPREV] then
1886 begin
1887 // decrease step
1888 if gSpectStep > 4 then gSpectStep := gSpectStep shr 1;
1889 gSpectKeyPress := True;
1890 end;
1891 if gPlayerAction[0, ACTION_WEAPNEXT] then
1892 begin
1893 // increase step
1894 if gSpectStep < 64 then gSpectStep := gSpectStep shl 1;
1895 gSpectKeyPress := True;
1896 end;
1897 end;
1898 if (gSpectMode = SPECT_PLAYERS)
1899 and (not gSpectAuto) then
1900 begin
1901 if gPlayerAction[0, ACTION_LOOKUP] then
1902 begin
1903 // add second view
1904 gSpectViewTwo := True;
1905 gSpectKeyPress := True;
1906 end;
1907 if gPlayerAction[0, ACTION_LOOKDOWN] then
1908 begin
1909 // remove second view
1910 gSpectViewTwo := False;
1911 gSpectKeyPress := True;
1912 end;
1913 if gPlayerAction[0, ACTION_MOVELEFT] then
1914 begin
1915 // prev player (view 1)
1916 gSpectPID1 := GetActivePlayerID_Prev(gSpectPID1);
1917 gSpectKeyPress := True;
1918 end;
1919 if gPlayerAction[0, ACTION_MOVERIGHT] then
1920 begin
1921 // next player (view 1)
1922 gSpectPID1 := GetActivePlayerID_Next(gSpectPID1);
1923 gSpectKeyPress := True;
1924 end;
1925 if gPlayerAction[0, ACTION_WEAPPREV] then
1926 begin
1927 // prev player (view 2)
1928 gSpectPID2 := GetActivePlayerID_Prev(gSpectPID2);
1929 gSpectKeyPress := True;
1930 end;
1931 if gPlayerAction[0, ACTION_WEAPNEXT] then
1932 begin
1933 // next player (view 2)
1934 gSpectPID2 := GetActivePlayerID_Next(gSpectPID2);
1935 gSpectKeyPress := True;
1936 end;
1937 end;
1938 if gPlayerAction[0, ACTION_ATTACK] then
1939 begin
1940 if (gSpectMode = SPECT_STATS) and (not gSpectAuto) then
1941 begin
1942 gSpectAuto := True;
1943 gSpectAutoNext := 0;
1944 gSpectViewTwo := False;
1945 gSpectKeyPress := True;
1946 end
1947 else
1948 if gSpectAuto then
1949 begin
1950 gSpectMode := SPECT_STATS;
1951 gSpectAuto := False;
1952 gSpectKeyPress := True;
1953 end;
1954 end;
1955 end
1956 else
1957 if (not gPlayerAction[0, ACTION_JUMP]) and
1958 (not gPlayerAction[0, ACTION_ATTACK]) and
1959 (not gPlayerAction[0, ACTION_MOVELEFT]) and
1960 (not gPlayerAction[0, ACTION_MOVERIGHT]) and
1961 (not gPlayerAction[0, ACTION_LOOKUP]) and
1962 (not gPlayerAction[0, ACTION_LOOKDOWN]) and
1963 (not gPlayerAction[0, ACTION_WEAPPREV]) and
1964 (not gPlayerAction[0, ACTION_WEAPNEXT]) then
1965 gSpectKeyPress := False;
1967 if gSpectAuto then
1968 begin
1969 if gSpectMode = SPECT_MAPVIEW then
1970 begin
1971 i := Min(Max(gSpectX + gSpectAutoStepX, 0), gMapInfo.Width - gScreenWidth);
1972 if i = gSpectX then
1973 gSpectAutoNext := gTime
1974 else
1975 gSpectX := i;
1976 i := Min(Max(gSpectY + gSpectAutoStepY, 0), gMapInfo.Height - gScreenHeight);
1977 if i = gSpectY then
1978 gSpectAutoNext := gTime
1979 else
1980 gSpectY := i;
1981 end;
1982 if gSpectAutoNext <= gTime then
1983 begin
1984 if gSpectAutoNext > 0 then
1985 begin
1986 gSpectMode := GetRandomSpectMode(gSpectMode);
1987 case gSpectMode of
1988 SPECT_MAPVIEW:
1989 begin
1990 gSpectX := Random(gMapInfo.Width - gScreenWidth);
1991 gSpectY := Random(gMapInfo.Height - gScreenHeight);
1992 gSpectAutoStepX := Random(9) - 4;
1993 gSpectAutoStepY := Random(9) - 4;
1994 if ((gSpectX < 800) and (gSpectAutoStepX < 0)) or
1995 ((gSpectX > gMapInfo.Width - gScreenWidth - 800) and (gSpectAutoStepX > 0)) then
1996 gSpectAutoStepX := gSpectAutoStepX * -1;
1997 if ((gSpectY < 800) and (gSpectAutoStepY < 0)) or
1998 ((gSpectY > gMapInfo.Height - gScreenHeight - 800) and (gSpectAutoStepY > 0)) then
1999 gSpectAutoStepY := gSpectAutoStepY * -1;
2000 end;
2001 SPECT_PLAYERS:
2002 begin
2003 gSpectPID1 := GetActivePlayerID_Random(gSpectPID1);
2004 end;
2005 end;
2006 end;
2007 case gSpectMode of
2008 SPECT_STATS: gSpectAutoNext := gTime + (Random(3) + 5) * 1000;
2009 SPECT_MAPVIEW: gSpectAutoNext := gTime + (Random(4) + 7) * 1000;
2010 SPECT_PLAYERS: gSpectAutoNext := gTime + (Random(7) + 8) * 1000;
2011 end;
2012 end;
2013 end;
2014 end;
2016 // Îáíîâëÿåì âñå îñòàëüíîå:
2017 g_Map_Update();
2018 g_Items_Update();
2019 g_Triggers_Update();
2020 g_Weapon_Update();
2021 g_Monsters_Update();
2022 g_GFX_Update();
2023 g_Player_UpdateAll();
2024 g_Player_UpdatePhysicalObjects();
2026 // server: send newly spawned monsters unconditionally
2027 if (gGameSettings.GameType = GT_SERVER) then
2028 begin
2029 if (Length(gMonstersSpawned) > 0) then
2030 begin
2031 for I := 0 to High(gMonstersSpawned) do MH_SEND_MonsterSpawn(gMonstersSpawned[I]);
2032 SetLength(gMonstersSpawned, 0);
2033 end;
2034 end;
2036 if (gSoundTriggerTime > 8) then
2037 begin
2038 g_Game_UpdateTriggerSounds();
2039 gSoundTriggerTime := 0;
2040 end
2041 else
2042 begin
2043 Inc(gSoundTriggerTime);
2044 end;
2046 if (NetMode = NET_SERVER) then
2047 begin
2048 Inc(NetTimeToUpdate);
2049 Inc(NetTimeToReliable);
2051 // send monster updates
2052 if (NetTimeToReliable >= NetRelupdRate) or (NetTimeToUpdate >= NetUpdateRate) then
2053 begin
2054 // send all monsters (periodic sync)
2055 reliableUpdate := (NetTimeToReliable >= NetRelupdRate);
2057 for I := 0 to High(gPlayers) do
2058 begin
2059 if (gPlayers[I] <> nil) then MH_SEND_PlayerPos(reliableUpdate, gPlayers[I].UID);
2060 end;
2062 g_Mons_ForEach(sendMonsPos);
2064 if reliableUpdate then
2065 begin
2066 NetTimeToReliable := 0;
2067 NetTimeToUpdate := NetUpdateRate;
2068 end
2069 else
2070 begin
2071 NetTimeToUpdate := 0;
2072 end;
2073 end
2074 else
2075 begin
2076 // send only mosters with some unexpected changes
2077 g_Mons_ForEach(sendMonsPosUnexpected);
2078 end;
2080 // send unexpected platform changes
2081 g_Map_NetSendInterestingPanels();
2083 if NetUseMaster then
2084 begin
2085 if gTime >= NetTimeToMaster then
2086 begin
2087 if (NetMHost = nil) or (NetMPeer = nil) then
2088 begin
2089 if not g_Net_Slist_Connect then g_Console_Add(_lc[I_NET_MSG_ERROR] + _lc[I_NET_SLIST_ERROR]);
2090 end;
2092 g_Net_Slist_Update;
2093 NetTimeToMaster := gTime + NetMasterRate;
2094 end;
2095 end;
2096 end
2097 else if (NetMode = NET_CLIENT) then
2098 begin
2099 MC_SEND_PlayerPos();
2100 end;
2101 end; // if gameOn ...
2103 // Àêòèâíî îêíî èíòåðôåéñà - ïåðåäàåì êëàâèøè åìó:
2104 if g_ActiveWindow <> nil then
2105 begin
2106 w := e_GetFirstKeyPressed();
2108 if (w <> IK_INVALID) then
2109 begin
2110 Msg.Msg := MESSAGE_DIKEY;
2111 Msg.wParam := w;
2112 g_ActiveWindow.OnMessage(Msg);
2113 end;
2115 // Åñëè îíî îò ýòîãî íå çàêðûëîñü, òî îáíîâëÿåì:
2116 if g_ActiveWindow <> nil then
2117 g_ActiveWindow.Update();
2119 // Íóæíî ñìåíèòü ðàçðåøåíèå:
2120 if gResolutionChange then
2121 begin
2122 e_WriteLog('Changing resolution', TMsgType.Notify);
2123 g_Game_ChangeResolution(gRC_Width, gRC_Height, gRC_FullScreen, gRC_Maximized);
2124 gResolutionChange := False;
2125 g_ActiveWindow := nil;
2126 end;
2128 // Íóæíî ñìåíèòü ÿçûê:
2129 if gLanguageChange then
2130 begin
2131 //e_WriteLog('Read language file', MSG_NOTIFY);
2132 //g_Language_Load(DataDir + gLanguage + '.txt');
2133 g_Language_Set(gLanguage);
2134 g_Menu_Reset();
2135 gLanguageChange := False;
2136 end;
2137 end;
2139 // Ãîðÿ÷àÿ êëàâèøà äëÿ âûçîâà ìåíþ âûõîäà èç èãðû (F10):
2140 if e_KeyPressed(IK_F10) and
2141 gGameOn and
2142 (not gConsoleShow) and
2143 (g_ActiveWindow = nil) then
2144 begin
2145 KeyPress(IK_F10);
2146 end;
2148 Time := GetTimer() {div 1000};
2150 // Îáðàáîòêà îòëîæåííûõ ñîáûòèé:
2151 if gDelayedEvents <> nil then
2152 for a := 0 to High(gDelayedEvents) do
2153 if gDelayedEvents[a].Pending and
2155 ((gDelayedEvents[a].DEType = DE_GLOBEVENT) and (gDelayedEvents[a].Time <= Time)) or
2156 ((gDelayedEvents[a].DEType > DE_GLOBEVENT) and (gDelayedEvents[a].Time <= gTime))
2157 ) then
2158 begin
2159 case gDelayedEvents[a].DEType of
2160 DE_GLOBEVENT:
2161 g_Game_ExecuteEvent(gDelayedEvents[a].DEStr);
2162 DE_BFGHIT:
2163 if gGameOn then
2164 g_Game_Announce_GoodShot(gDelayedEvents[a].DENum);
2165 DE_KILLCOMBO:
2166 if gGameOn then
2167 begin
2168 g_Game_Announce_KillCombo(gDelayedEvents[a].DENum);
2169 if g_Game_IsNet and g_Game_IsServer then
2170 MH_SEND_GameEvent(NET_EV_KILLCOMBO, gDelayedEvents[a].DENum);
2171 end;
2172 DE_BODYKILL:
2173 if gGameOn then
2174 g_Game_Announce_BodyKill(gDelayedEvents[a].DENum);
2175 end;
2176 gDelayedEvents[a].Pending := False;
2177 end;
2179 // Êàæäóþ ñåêóíäó îáíîâëÿåì ñ÷åò÷èê îáíîâëåíèé:
2180 UPSCounter := UPSCounter + 1;
2181 if Time - UPSTime >= 1000 then
2182 begin
2183 UPS := UPSCounter;
2184 UPSCounter := 0;
2185 UPSTime := Time;
2186 end;
2188 if gGameOn then
2189 begin
2190 g_Weapon_AddDynLights();
2191 g_Items_AddDynLights();
2192 end;
2193 end;
2195 procedure g_Game_LoadChatSounds(Resource: string);
2196 var
2197 WAD: TWADFile;
2198 FileName, Snd: string;
2199 p: Pointer;
2200 len, cnt, tags, i, j: Integer;
2201 cfg: TConfig;
2202 begin
2203 FileName := g_ExtractWadName(Resource);
2205 WAD := TWADFile.Create();
2206 WAD.ReadFile(FileName);
2208 if not WAD.GetResource(g_ExtractFilePathName(Resource), p, len) then
2209 begin
2210 gChatSounds := nil;
2211 WAD.Free();
2212 Exit;
2213 end;
2215 cfg := TConfig.CreateMem(p, len);
2216 cnt := cfg.ReadInt('ChatSounds', 'Count', 0);
2218 SetLength(gChatSounds, cnt);
2219 for i := 0 to Length(gChatSounds) - 1 do
2220 begin
2221 gChatSounds[i].Sound := nil;
2222 Snd := Trim(cfg.ReadStr(IntToStr(i), 'Sound', ''));
2223 tags := cfg.ReadInt(IntToStr(i), 'Tags', 0);
2224 if (Snd = '') or (Tags <= 0) then
2225 continue;
2226 g_Sound_CreateWADEx('SOUND_CHAT_MACRO' + IntToStr(i), GameWAD+':'+Snd);
2227 gChatSounds[i].Sound := TPlayableSound.Create();
2228 gChatSounds[i].Sound.SetByName('SOUND_CHAT_MACRO' + IntToStr(i));
2229 SetLength(gChatSounds[i].Tags, tags);
2230 for j := 0 to tags - 1 do
2231 gChatSounds[i].Tags[j] := toLowerCase1251(cfg.ReadStr(IntToStr(i), 'Tag' + IntToStr(j), ''));
2232 gChatSounds[i].FullWord := cfg.ReadBool(IntToStr(i), 'FullWord', False);
2233 end;
2235 cfg.Free();
2236 WAD.Free();
2237 end;
2239 procedure g_Game_FreeChatSounds();
2240 var
2241 i: Integer;
2242 begin
2243 for i := 0 to Length(gChatSounds) - 1 do
2244 begin
2245 gChatSounds[i].Sound.Free();
2246 g_Sound_Delete('SOUND_CHAT_MACRO' + IntToStr(i));
2247 end;
2248 SetLength(gChatSounds, 0);
2249 gChatSounds := nil;
2250 end;
2252 procedure g_Game_LoadData();
2253 var
2254 wl, hl: Integer;
2255 wr, hr: Integer;
2256 wb, hb: Integer;
2257 wm, hm: Integer;
2258 begin
2259 if DataLoaded then Exit;
2261 e_WriteLog('Loading game data...', TMsgType.Notify);
2263 g_Texture_CreateWADEx('NOTEXTURE', GameWAD+':TEXTURES\NOTEXTURE');
2264 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUD', GameWAD+':TEXTURES\HUD');
2265 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDAIR', GameWAD+':TEXTURES\AIRBAR');
2266 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDJET', GameWAD+':TEXTURES\JETBAR');
2267 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDBG', GameWAD+':TEXTURES\HUDBG');
2268 g_Texture_CreateWADEx('TEXTURE_PLAYER_ARMORHUD', GameWAD+':TEXTURES\ARMORHUD');
2269 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG', GameWAD+':TEXTURES\FLAGHUD_R_BASE');
2270 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_S', GameWAD+':TEXTURES\FLAGHUD_R_STOLEN');
2271 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_D', GameWAD+':TEXTURES\FLAGHUD_R_DROP');
2272 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG', GameWAD+':TEXTURES\FLAGHUD_B_BASE');
2273 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_S', GameWAD+':TEXTURES\FLAGHUD_B_STOLEN');
2274 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_D', GameWAD+':TEXTURES\FLAGHUD_B_DROP');
2275 g_Texture_CreateWADEx('TEXTURE_PLAYER_TALKBUBBLE', GameWAD+':TEXTURES\TALKBUBBLE');
2276 g_Texture_CreateWADEx('TEXTURE_PLAYER_INVULPENTA', GameWAD+':TEXTURES\PENTA');
2277 g_Texture_CreateWADEx('TEXTURE_PLAYER_INDICATOR', GameWAD+':TEXTURES\PLRIND');
2279 hasPBarGfx := true;
2280 if not g_Texture_CreateWADEx('UI_GFX_PBAR_LEFT', GameWAD+':TEXTURES\LLEFT') then hasPBarGfx := false;
2281 if not g_Texture_CreateWADEx('UI_GFX_PBAR_MARKER', GameWAD+':TEXTURES\LMARKER') then hasPBarGfx := false;
2282 if not g_Texture_CreateWADEx('UI_GFX_PBAR_MIDDLE', GameWAD+':TEXTURES\LMIDDLE') then hasPBarGfx := false;
2283 if not g_Texture_CreateWADEx('UI_GFX_PBAR_RIGHT', GameWAD+':TEXTURES\LRIGHT') then hasPBarGfx := false;
2285 if hasPBarGfx then
2286 begin
2287 g_Texture_GetSize('UI_GFX_PBAR_LEFT', wl, hl);
2288 g_Texture_GetSize('UI_GFX_PBAR_RIGHT', wr, hr);
2289 g_Texture_GetSize('UI_GFX_PBAR_MIDDLE', wb, hb);
2290 g_Texture_GetSize('UI_GFX_PBAR_MARKER', wm, hm);
2291 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
2292 begin
2293 // yay!
2294 end
2295 else
2296 begin
2297 hasPBarGfx := false;
2298 end;
2299 end;
2301 g_Frames_CreateWAD(nil, 'FRAMES_TELEPORT', GameWAD+':TEXTURES\TELEPORT', 64, 64, 10, False);
2302 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH', GameWAD+':WEAPONS\PUNCH', 64, 64, 4, False);
2303 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_UP', GameWAD+':WEAPONS\PUNCH_UP', 64, 64, 4, False);
2304 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_DN', GameWAD+':WEAPONS\PUNCH_DN', 64, 64, 4, False);
2305 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK', GameWAD+':WEAPONS\PUNCHB', 64, 64, 4, False);
2306 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK_UP', GameWAD+':WEAPONS\PUNCHB_UP', 64, 64, 4, False);
2307 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK_DN', GameWAD+':WEAPONS\PUNCHB_DN', 64, 64, 4, False);
2308 g_Sound_CreateWADEx('SOUND_GAME_TELEPORT', GameWAD+':SOUNDS\TELEPORT');
2309 g_Sound_CreateWADEx('SOUND_GAME_NOTELEPORT', GameWAD+':SOUNDS\NOTELEPORT');
2310 g_Sound_CreateWADEx('SOUND_GAME_SECRET', GameWAD+':SOUNDS\SECRET');
2311 g_Sound_CreateWADEx('SOUND_GAME_DOOROPEN', GameWAD+':SOUNDS\DOOROPEN');
2312 g_Sound_CreateWADEx('SOUND_GAME_DOORCLOSE', GameWAD+':SOUNDS\DOORCLOSE');
2313 g_Sound_CreateWADEx('SOUND_GAME_BULK1', GameWAD+':SOUNDS\BULK1');
2314 g_Sound_CreateWADEx('SOUND_GAME_BULK2', GameWAD+':SOUNDS\BULK2');
2315 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE1', GameWAD+':SOUNDS\BUBBLE1');
2316 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE2', GameWAD+':SOUNDS\BUBBLE2');
2317 g_Sound_CreateWADEx('SOUND_GAME_BURNING', GameWAD+':SOUNDS\BURNING');
2318 g_Sound_CreateWADEx('SOUND_GAME_SWITCH1', GameWAD+':SOUNDS\SWITCH1');
2319 g_Sound_CreateWADEx('SOUND_GAME_SWITCH0', GameWAD+':SOUNDS\SWITCH0');
2320 g_Sound_CreateWADEx('SOUND_GAME_RADIO', GameWAD+':SOUNDS\RADIO');
2321 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD1', GameWAD+':SOUNDS\GOOD1');
2322 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD2', GameWAD+':SOUNDS\GOOD2');
2323 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD3', GameWAD+':SOUNDS\GOOD3');
2324 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD4', GameWAD+':SOUNDS\GOOD4');
2325 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL2X', GameWAD+':SOUNDS\KILL2X');
2326 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL3X', GameWAD+':SOUNDS\KILL3X');
2327 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL4X', GameWAD+':SOUNDS\KILL4X');
2328 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILLMX', GameWAD+':SOUNDS\KILLMX');
2329 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA1', GameWAD+':SOUNDS\MUHAHA1');
2330 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA2', GameWAD+':SOUNDS\MUHAHA2');
2331 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA3', GameWAD+':SOUNDS\MUHAHA3');
2332 g_Sound_CreateWADEx('SOUND_CTF_GET1', GameWAD+':SOUNDS\GETFLAG1');
2333 g_Sound_CreateWADEx('SOUND_CTF_GET2', GameWAD+':SOUNDS\GETFLAG2');
2334 g_Sound_CreateWADEx('SOUND_CTF_LOST1', GameWAD+':SOUNDS\LOSTFLG1');
2335 g_Sound_CreateWADEx('SOUND_CTF_LOST2', GameWAD+':SOUNDS\LOSTFLG2');
2336 g_Sound_CreateWADEx('SOUND_CTF_RETURN1', GameWAD+':SOUNDS\RETFLAG1');
2337 g_Sound_CreateWADEx('SOUND_CTF_RETURN2', GameWAD+':SOUNDS\RETFLAG2');
2338 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE1', GameWAD+':SOUNDS\CAPFLAG1');
2339 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE2', GameWAD+':SOUNDS\CAPFLAG2');
2341 goodsnd[0] := TPlayableSound.Create();
2342 goodsnd[1] := TPlayableSound.Create();
2343 goodsnd[2] := TPlayableSound.Create();
2344 goodsnd[3] := TPlayableSound.Create();
2346 goodsnd[0].SetByName('SOUND_ANNOUNCER_GOOD1');
2347 goodsnd[1].SetByName('SOUND_ANNOUNCER_GOOD2');
2348 goodsnd[2].SetByName('SOUND_ANNOUNCER_GOOD3');
2349 goodsnd[3].SetByName('SOUND_ANNOUNCER_GOOD4');
2351 killsnd[0] := TPlayableSound.Create();
2352 killsnd[1] := TPlayableSound.Create();
2353 killsnd[2] := TPlayableSound.Create();
2354 killsnd[3] := TPlayableSound.Create();
2356 killsnd[0].SetByName('SOUND_ANNOUNCER_KILL2X');
2357 killsnd[1].SetByName('SOUND_ANNOUNCER_KILL3X');
2358 killsnd[2].SetByName('SOUND_ANNOUNCER_KILL4X');
2359 killsnd[3].SetByName('SOUND_ANNOUNCER_KILLMX');
2361 hahasnd[0] := TPlayableSound.Create();
2362 hahasnd[1] := TPlayableSound.Create();
2363 hahasnd[2] := TPlayableSound.Create();
2365 hahasnd[0].SetByName('SOUND_ANNOUNCER_MUHAHA1');
2366 hahasnd[1].SetByName('SOUND_ANNOUNCER_MUHAHA2');
2367 hahasnd[2].SetByName('SOUND_ANNOUNCER_MUHAHA3');
2369 sound_get_flag[0] := TPlayableSound.Create();
2370 sound_get_flag[1] := TPlayableSound.Create();
2371 sound_lost_flag[0] := TPlayableSound.Create();
2372 sound_lost_flag[1] := TPlayableSound.Create();
2373 sound_ret_flag[0] := TPlayableSound.Create();
2374 sound_ret_flag[1] := TPlayableSound.Create();
2375 sound_cap_flag[0] := TPlayableSound.Create();
2376 sound_cap_flag[1] := TPlayableSound.Create();
2378 sound_get_flag[0].SetByName('SOUND_CTF_GET1');
2379 sound_get_flag[1].SetByName('SOUND_CTF_GET2');
2380 sound_lost_flag[0].SetByName('SOUND_CTF_LOST1');
2381 sound_lost_flag[1].SetByName('SOUND_CTF_LOST2');
2382 sound_ret_flag[0].SetByName('SOUND_CTF_RETURN1');
2383 sound_ret_flag[1].SetByName('SOUND_CTF_RETURN2');
2384 sound_cap_flag[0].SetByName('SOUND_CTF_CAPTURE1');
2385 sound_cap_flag[1].SetByName('SOUND_CTF_CAPTURE2');
2387 g_Game_LoadChatSounds(GameWAD+':CHATSND\SNDCFG');
2389 g_Game_SetLoadingText(_lc[I_LOAD_ITEMS_DATA], 0, False);
2390 g_Items_LoadData();
2392 g_Game_SetLoadingText(_lc[I_LOAD_WEAPONS_DATA], 0, False);
2393 g_Weapon_LoadData();
2395 g_Monsters_LoadData();
2397 DataLoaded := True;
2398 end;
2400 procedure g_Game_FreeData();
2401 begin
2402 if not DataLoaded then Exit;
2404 g_Items_FreeData();
2405 g_Weapon_FreeData();
2406 g_Monsters_FreeData();
2408 e_WriteLog('Releasing game data...', TMsgType.Notify);
2410 g_Texture_Delete('NOTEXTURE');
2411 g_Texture_Delete('TEXTURE_PLAYER_HUD');
2412 g_Texture_Delete('TEXTURE_PLAYER_HUDBG');
2413 g_Texture_Delete('TEXTURE_PLAYER_ARMORHUD');
2414 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG');
2415 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_S');
2416 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_D');
2417 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG');
2418 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_S');
2419 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_D');
2420 g_Texture_Delete('TEXTURE_PLAYER_TALKBUBBLE');
2421 g_Texture_Delete('TEXTURE_PLAYER_INVULPENTA');
2422 g_Frames_DeleteByName('FRAMES_TELEPORT');
2423 g_Frames_DeleteByName('FRAMES_PUNCH');
2424 g_Frames_DeleteByName('FRAMES_PUNCH_UP');
2425 g_Frames_DeleteByName('FRAMES_PUNCH_DN');
2426 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK');
2427 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK_UP');
2428 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK_DN');
2429 g_Sound_Delete('SOUND_GAME_TELEPORT');
2430 g_Sound_Delete('SOUND_GAME_NOTELEPORT');
2431 g_Sound_Delete('SOUND_GAME_SECRET');
2432 g_Sound_Delete('SOUND_GAME_DOOROPEN');
2433 g_Sound_Delete('SOUND_GAME_DOORCLOSE');
2434 g_Sound_Delete('SOUND_GAME_BULK1');
2435 g_Sound_Delete('SOUND_GAME_BULK2');
2436 g_Sound_Delete('SOUND_GAME_BUBBLE1');
2437 g_Sound_Delete('SOUND_GAME_BUBBLE2');
2438 g_Sound_Delete('SOUND_GAME_BURNING');
2439 g_Sound_Delete('SOUND_GAME_SWITCH1');
2440 g_Sound_Delete('SOUND_GAME_SWITCH0');
2442 goodsnd[0].Free();
2443 goodsnd[1].Free();
2444 goodsnd[2].Free();
2445 goodsnd[3].Free();
2447 g_Sound_Delete('SOUND_ANNOUNCER_GOOD1');
2448 g_Sound_Delete('SOUND_ANNOUNCER_GOOD2');
2449 g_Sound_Delete('SOUND_ANNOUNCER_GOOD3');
2450 g_Sound_Delete('SOUND_ANNOUNCER_GOOD4');
2452 killsnd[0].Free();
2453 killsnd[1].Free();
2454 killsnd[2].Free();
2455 killsnd[3].Free();
2457 g_Sound_Delete('SOUND_ANNOUNCER_KILL2X');
2458 g_Sound_Delete('SOUND_ANNOUNCER_KILL3X');
2459 g_Sound_Delete('SOUND_ANNOUNCER_KILL4X');
2460 g_Sound_Delete('SOUND_ANNOUNCER_KILLMX');
2462 hahasnd[0].Free();
2463 hahasnd[1].Free();
2464 hahasnd[2].Free();
2466 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA1');
2467 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA2');
2468 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA3');
2470 sound_get_flag[0].Free();
2471 sound_get_flag[1].Free();
2472 sound_lost_flag[0].Free();
2473 sound_lost_flag[1].Free();
2474 sound_ret_flag[0].Free();
2475 sound_ret_flag[1].Free();
2476 sound_cap_flag[0].Free();
2477 sound_cap_flag[1].Free();
2479 g_Sound_Delete('SOUND_CTF_GET1');
2480 g_Sound_Delete('SOUND_CTF_GET2');
2481 g_Sound_Delete('SOUND_CTF_LOST1');
2482 g_Sound_Delete('SOUND_CTF_LOST2');
2483 g_Sound_Delete('SOUND_CTF_RETURN1');
2484 g_Sound_Delete('SOUND_CTF_RETURN2');
2485 g_Sound_Delete('SOUND_CTF_CAPTURE1');
2486 g_Sound_Delete('SOUND_CTF_CAPTURE2');
2488 g_Game_FreeChatSounds();
2490 DataLoaded := False;
2491 end;
2493 procedure DrawCustomStat();
2494 var
2495 pc, x, y, w, _y,
2496 w1, w2, w3,
2497 t, p, m: Integer;
2498 ww1, hh1: Word;
2499 ww2, hh2, r, g, b, rr, gg, bb: Byte;
2500 s1, s2, topstr: String;
2501 begin
2502 e_TextureFontGetSize(gStdFont, ww2, hh2);
2504 g_ProcessMessages();
2506 if g_Console_Action(ACTION_SCORES) then
2507 begin
2508 if not gStatsPressed then
2509 begin
2510 gStatsOff := not gStatsOff;
2511 gStatsPressed := True;
2512 end;
2513 end
2514 else
2515 gStatsPressed := False;
2517 if gStatsOff then
2518 begin
2519 s1 := _lc[I_MENU_INTER_NOTICE_TAB];
2520 w := (Length(s1) * ww2) div 2;
2521 x := gScreenWidth div 2 - w;
2522 y := 8;
2523 e_TextureFontPrint(x, y, s1, gStdFont);
2524 Exit;
2525 end;
2527 if (gGameSettings.GameMode = GM_COOP) then
2528 begin
2529 if gMissionFailed then
2530 topstr := _lc[I_MENU_INTER_MISSION_FAIL]
2531 else
2532 topstr := _lc[I_MENU_INTER_LEVEL_COMPLETE];
2533 end
2534 else
2535 topstr := _lc[I_MENU_INTER_ROUND_OVER];
2537 e_CharFont_GetSize(gMenuFont, topstr, ww1, hh1);
2538 e_CharFont_Print(gMenuFont, (gScreenWidth div 2)-(ww1 div 2), 16, topstr);
2540 if g_Game_IsNet then
2541 begin
2542 topstr := Format(_lc[I_MENU_INTER_NOTICE_TIME], [gServInterTime]);
2543 if not gChatShow then
2544 e_TextureFontPrintEx((gScreenWidth div 2)-(Length(topstr)*ww2 div 2),
2545 gScreenHeight-(hh2+4)*2, topstr, gStdFont, 255, 255, 255, 1);
2546 end;
2548 if g_Game_IsClient then
2549 topstr := _lc[I_MENU_INTER_NOTICE_MAP]
2550 else
2551 topstr := _lc[I_MENU_INTER_NOTICE_SPACE];
2552 if not gChatShow then
2553 e_TextureFontPrintEx((gScreenWidth div 2)-(Length(topstr)*ww2 div 2),
2554 gScreenHeight-(hh2+4), topstr, gStdFont, 255, 255, 255, 1);
2556 x := 32;
2557 y := 16+hh1+16;
2559 w := gScreenWidth-x*2;
2561 w2 := (w-16) div 6;
2562 w3 := w2;
2563 w1 := w-16-w2-w3;
2565 e_DrawFillQuad(x, y, gScreenWidth-x-1, gScreenHeight-y-1, 64, 64, 64, 32);
2566 e_DrawQuad(x, y, gScreenWidth-x-1, gScreenHeight-y-1, 255, 127, 0);
2568 m := Max(Length(_lc[I_MENU_MAP])+1, Length(_lc[I_GAME_GAME_TIME])+1)*ww2;
2570 case CustomStat.GameMode of
2571 GM_DM:
2572 begin
2573 if gGameSettings.MaxLives = 0 then
2574 s1 := _lc[I_GAME_DM]
2575 else
2576 s1 := _lc[I_GAME_LMS];
2577 end;
2578 GM_TDM:
2579 begin
2580 if gGameSettings.MaxLives = 0 then
2581 s1 := _lc[I_GAME_TDM]
2582 else
2583 s1 := _lc[I_GAME_TLMS];
2584 end;
2585 GM_CTF: s1 := _lc[I_GAME_CTF];
2586 GM_COOP:
2587 begin
2588 if gGameSettings.MaxLives = 0 then
2589 s1 := _lc[I_GAME_COOP]
2590 else
2591 s1 := _lc[I_GAME_SURV];
2592 end;
2593 else s1 := '';
2594 end;
2596 _y := y+16;
2597 e_TextureFontPrintEx(x+(w div 2)-(Length(s1)*ww2 div 2), _y, s1, gStdFont, 255, 255, 255, 1);
2598 _y := _y+8;
2600 _y := _y+16;
2601 e_TextureFontPrintEx(x+8, _y, _lc[I_MENU_MAP], gStdFont, 255, 127, 0, 1);
2602 e_TextureFontPrint(x+8+m, _y, Format('%s - %s', [CustomStat.Map, CustomStat.MapName]), gStdFont);
2604 _y := _y+16;
2605 e_TextureFontPrintEx(x+8, _y, _lc[I_GAME_GAME_TIME], gStdFont, 255, 127, 0, 1);
2606 e_TextureFontPrint(x+8+m, _y, Format('%d:%.2d:%.2d', [CustomStat.GameTime div 1000 div 3600,
2607 (CustomStat.GameTime div 1000 div 60) mod 60,
2608 CustomStat.GameTime div 1000 mod 60]), gStdFont);
2610 pc := Length(CustomStat.PlayerStat);
2611 if pc = 0 then Exit;
2613 if CustomStat.GameMode = GM_COOP then
2614 begin
2615 m := Max(Length(_lc[I_GAME_MONSTERS])+1, Length(_lc[I_GAME_SECRETS])+1)*ww2;
2616 _y := _y+32;
2617 s2 := _lc[I_GAME_MONSTERS];
2618 e_TextureFontPrintEx(x+8, _y, s2, gStdFont, 255, 127, 0, 1);
2619 e_TextureFontPrintEx(x+8+m, _y, IntToStr(gCoopMonstersKilled) + '/' + IntToStr(gTotalMonsters), gStdFont, 255, 255, 255, 1);
2620 _y := _y+16;
2621 s2 := _lc[I_GAME_SECRETS];
2622 e_TextureFontPrintEx(x+8, _y, s2, gStdFont, 255, 127, 0, 1);
2623 e_TextureFontPrintEx(x+8+m, _y, IntToStr(gCoopSecretsFound) + '/' + IntToStr(gSecretsCount), gStdFont, 255, 255, 255, 1);
2624 if gLastMap then
2625 begin
2626 m := Max(Length(_lc[I_GAME_MONSTERS_TOTAL])+1, Length(_lc[I_GAME_SECRETS_TOTAL])+1)*ww2;
2627 _y := _y-16;
2628 s2 := _lc[I_GAME_MONSTERS_TOTAL];
2629 e_TextureFontPrintEx(x+250, _y, s2, gStdFont, 255, 127, 0, 1);
2630 e_TextureFontPrintEx(x+250+m, _y, IntToStr(gCoopTotalMonstersKilled) + '/' + IntToStr(gCoopTotalMonsters), gStdFont, 255, 255, 255, 1);
2631 _y := _y+16;
2632 s2 := _lc[I_GAME_SECRETS_TOTAL];
2633 e_TextureFontPrintEx(x+250, _y, s2, gStdFont, 255, 127, 0, 1);
2634 e_TextureFontPrintEx(x+250+m, _y, IntToStr(gCoopTotalSecretsFound) + '/' + IntToStr(gCoopTotalSecrets), gStdFont, 255, 255, 255, 1);
2635 end;
2636 end;
2638 if CustomStat.GameMode in [GM_TDM, GM_CTF] then
2639 begin
2640 _y := _y+16+16;
2642 with CustomStat do
2643 if TeamStat[TEAM_RED].Goals > TeamStat[TEAM_BLUE].Goals then s1 := _lc[I_GAME_WIN_RED]
2644 else if TeamStat[TEAM_BLUE].Goals > TeamStat[TEAM_RED].Goals then s1 := _lc[I_GAME_WIN_BLUE]
2645 else s1 := _lc[I_GAME_WIN_DRAW];
2647 e_TextureFontPrintEx(x+8+(w div 2)-(Length(s1)*ww2 div 2), _y, s1, gStdFont, 255, 255, 255, 1);
2648 _y := _y+40;
2650 for t := TEAM_RED to TEAM_BLUE do
2651 begin
2652 if t = TEAM_RED then
2653 begin
2654 e_TextureFontPrintEx(x+8, _y, _lc[I_GAME_TEAM_RED],
2655 gStdFont, 255, 0, 0, 1);
2656 e_TextureFontPrintEx(x+w1+8, _y, IntToStr(CustomStat.TeamStat[TEAM_RED].Goals),
2657 gStdFont, 255, 0, 0, 1);
2658 r := 255;
2659 g := 0;
2660 b := 0;
2661 end
2662 else
2663 begin
2664 e_TextureFontPrintEx(x+8, _y, _lc[I_GAME_TEAM_BLUE],
2665 gStdFont, 0, 0, 255, 1);
2666 e_TextureFontPrintEx(x+w1+8, _y, IntToStr(CustomStat.TeamStat[TEAM_BLUE].Goals),
2667 gStdFont, 0, 0, 255, 1);
2668 r := 0;
2669 g := 0;
2670 b := 255;
2671 end;
2673 e_DrawLine(1, x+8, _y+20, x-8+w, _y+20, r, g, b);
2674 _y := _y+24;
2676 for p := 0 to High(CustomStat.PlayerStat) do
2677 if CustomStat.PlayerStat[p].Team = t then
2678 with CustomStat.PlayerStat[p] do
2679 begin
2680 if Spectator then
2681 begin
2682 rr := r div 2;
2683 gg := g div 2;
2684 bb := b div 2;
2685 end
2686 else
2687 begin
2688 rr := r;
2689 gg := g;
2690 bb := b;
2691 end;
2692 e_TextureFontPrintEx(x+8, _y, Name, gStdFont, rr, gg, bb, 1);
2693 e_TextureFontPrintEx(x+w1+8, _y, IntToStr(Frags), gStdFont, rr, gg, bb, 1);
2694 e_TextureFontPrintEx(x+w1+w2+8, _y, IntToStr(Deaths), gStdFont, rr, gg, bb, 1);
2695 _y := _y+24;
2696 end;
2698 _y := _y+16+16;
2699 end;
2700 end
2701 else if CustomStat.GameMode in [GM_DM, GM_COOP] then
2702 begin
2703 _y := _y+40;
2704 e_TextureFontPrintEx(x+8, _y, _lc[I_GAME_PLAYER_NAME], gStdFont, 255, 127, 0, 1);
2705 e_TextureFontPrintEx(x+8+w1, _y, _lc[I_GAME_FRAGS], gStdFont, 255, 127, 0, 1);
2706 e_TextureFontPrintEx(x+8+w1+w2, _y, _lc[I_GAME_DEATHS], gStdFont, 255, 127, 0, 1);
2708 _y := _y+24;
2709 for p := 0 to High(CustomStat.PlayerStat) do
2710 with CustomStat.PlayerStat[p] do
2711 begin
2712 e_DrawFillQuad(x+8, _y+4, x+24-1, _y+16+4-1, Color.R, Color.G, Color.B, 0);
2714 if Spectator then
2715 r := 127
2716 else
2717 r := 255;
2719 e_TextureFontPrintEx(x+8+16+8, _y+4, Name, gStdFont, r, r, r, 1, True);
2720 e_TextureFontPrintEx(x+w1+8+16+8, _y+4, IntToStr(Frags), gStdFont, r, r, r, 1, True);
2721 e_TextureFontPrintEx(x+w1+w2+8+16+8, _y+4, IntToStr(Deaths), gStdFont, r, r, r, 1, True);
2722 _y := _y+24;
2723 end;
2724 end;
2725 end;
2727 procedure DrawSingleStat();
2728 var
2729 tm, key_x, val_x, y: Integer;
2730 w1, w2, h: Word;
2731 s1, s2: String;
2733 procedure player_stat(n: Integer);
2734 var
2735 kpm: Real;
2737 begin
2738 // "Kills: # / #":
2739 s1 := Format(' %d ', [SingleStat.PlayerStat[n].Kills]);
2740 s2 := Format(' %d', [gTotalMonsters]);
2742 e_CharFont_Print(gMenuFont, key_x, y, _lc[I_MENU_INTER_KILLS]);
2743 e_CharFont_PrintEx(gMenuFont, val_x, y, s1, _RGB(255, 0, 0));
2744 e_CharFont_GetSize(gMenuFont, s1, w1, h);
2745 e_CharFont_Print(gMenuFont, val_x+w1, y, '/');
2746 s1 := s1 + '/';
2747 e_CharFont_GetSize(gMenuFont, s1, w1, h);
2748 e_CharFont_PrintEx(gMenuFont, val_x+w1, y, s2, _RGB(255, 0, 0));
2750 // "Kills-per-minute: ##.#":
2751 s1 := _lc[I_MENU_INTER_KPM];
2752 if tm > 0 then
2753 kpm := (SingleStat.PlayerStat[n].Kills / tm) * 60
2754 else
2755 kpm := SingleStat.PlayerStat[n].Kills;
2756 s2 := Format(' %.1f', [kpm]);
2758 e_CharFont_Print(gMenuFont, key_x, y+32, s1);
2759 e_CharFont_PrintEx(gMenuFont, val_x, y+32, s2, _RGB(255, 0, 0));
2761 // "Secrets found: # / #":
2762 s1 := Format(' %d ', [SingleStat.PlayerStat[n].Secrets]);
2763 s2 := Format(' %d', [SingleStat.TotalSecrets]);
2765 e_CharFont_Print(gMenuFont, key_x, y+64, _lc[I_MENU_INTER_SECRETS]);
2766 e_CharFont_PrintEx(gMenuFont, val_x, y+64, s1, _RGB(255, 0, 0));
2767 e_CharFont_GetSize(gMenuFont, s1, w1, h);
2768 e_CharFont_Print(gMenuFont, val_x+w1, y+64, '/');
2769 s1 := s1 + '/';
2770 e_CharFont_GetSize(gMenuFont, s1, w1, h);
2771 e_CharFont_PrintEx(gMenuFont, val_x+w1, y+64, s2, _RGB(255, 0, 0));
2772 end;
2774 begin
2775 // "Level Complete":
2776 e_CharFont_GetSize(gMenuFont, _lc[I_MENU_INTER_LEVEL_COMPLETE], w1, h);
2777 e_CharFont_Print(gMenuFont, (gScreenWidth-w1) div 2, 32, _lc[I_MENU_INTER_LEVEL_COMPLETE]);
2779 // Îïðåäåëÿåì êîîðäèíàòû âûðàâíèâàíèÿ ïî ñàìîé äëèííîé ñòðîêå:
2780 s1 := _lc[I_MENU_INTER_KPM];
2781 e_CharFont_GetSize(gMenuFont, s1, w1, h);
2782 Inc(w1, 16);
2783 s1 := ' 9999.9';
2784 e_CharFont_GetSize(gMenuFont, s1, w2, h);
2786 key_x := (gScreenWidth-w1-w2) div 2;
2787 val_x := key_x + w1;
2789 // "Time: #:##:##":
2790 tm := SingleStat.GameTime div 1000;
2791 s1 := _lc[I_MENU_INTER_TIME];
2792 s2 := Format(' %d:%.2d:%.2d', [tm div (60*60), (tm mod (60*60)) div 60, tm mod 60]);
2794 e_CharFont_Print(gMenuFont, key_x, 80, s1);
2795 e_CharFont_PrintEx(gMenuFont, val_x, 80, s2, _RGB(255, 0, 0));
2797 if SingleStat.TwoPlayers then
2798 begin
2799 // "Player 1":
2800 s1 := _lc[I_MENU_PLAYER_1];
2801 e_CharFont_GetSize(gMenuFont, s1, w1, h);
2802 e_CharFont_Print(gMenuFont, (gScreenWidth-w1) div 2, 128, s1);
2804 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
2805 y := 176;
2806 player_stat(0);
2808 // "Player 2":
2809 s1 := _lc[I_MENU_PLAYER_2];
2810 e_CharFont_GetSize(gMenuFont, s1, w1, h);
2811 e_CharFont_Print(gMenuFont, (gScreenWidth-w1) div 2, 288, s1);
2813 // Ñòàòèñòèêà âòîðîãî èãðîêà:
2814 y := 336;
2815 player_stat(1);
2816 end
2817 else
2818 begin
2819 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
2820 y := 128;
2821 player_stat(0);
2822 end;
2823 end;
2825 procedure DrawLoadingStat();
2826 procedure drawRect (x, y, w, h: Integer);
2827 begin
2828 if (w < 1) or (h < 1) then exit;
2829 glBegin(GL_QUADS);
2830 glVertex2f(x+0.375, y+0.375);
2831 glVertex2f(x+w+0.375, y+0.375);
2832 glVertex2f(x+w+0.375, y+h+0.375);
2833 glVertex2f(x+0.375, y+h+0.375);
2834 glEnd();
2835 end;
2837 function drawPBar (cur, total: Integer; washere: Boolean): Boolean;
2838 var
2839 rectW, rectH: Integer;
2840 x0, y0: Integer;
2841 wdt: Integer;
2842 wl, hl: Integer;
2843 wr, hr: Integer;
2844 wb, hb: Integer;
2845 wm, hm: Integer;
2846 idl, idr, idb, idm: LongWord;
2847 f, my: Integer;
2848 begin
2849 result := false;
2850 if (total < 1) then exit;
2851 if (cur < 1) then exit; // don't blink
2852 if (not washere) and (cur >= total) then exit; // don't blink
2853 //if (cur < 0) then cur := 0;
2854 //if (cur > total) then cur := total;
2855 result := true;
2857 if (hasPBarGfx) then
2858 begin
2859 g_Texture_Get('UI_GFX_PBAR_LEFT', idl);
2860 g_Texture_GetSize('UI_GFX_PBAR_LEFT', wl, hl);
2861 g_Texture_Get('UI_GFX_PBAR_RIGHT', idr);
2862 g_Texture_GetSize('UI_GFX_PBAR_RIGHT', wr, hr);
2863 g_Texture_Get('UI_GFX_PBAR_MIDDLE', idb);
2864 g_Texture_GetSize('UI_GFX_PBAR_MIDDLE', wb, hb);
2865 g_Texture_Get('UI_GFX_PBAR_MARKER', idm);
2866 g_Texture_GetSize('UI_GFX_PBAR_MARKER', wm, hm);
2868 //rectW := gScreenWidth-360;
2869 rectW := trunc(624.0*gScreenWidth/1024.0);
2870 rectH := hl;
2872 x0 := (gScreenWidth-rectW) div 2;
2873 y0 := gScreenHeight-rectH-64;
2874 if (y0 < 2) then y0 := 2;
2876 glEnable(GL_SCISSOR_TEST);
2878 // left and right
2879 glScissor(x0, gScreenHeight-y0-rectH, rectW, rectH);
2880 e_DrawSize(idl, x0, y0, 0, true, false, wl, hl);
2881 e_DrawSize(idr, x0+rectW-wr, y0, 0, true, false, wr, hr);
2883 // body
2884 glScissor(x0+wl, gScreenHeight-y0-rectH, rectW-wl-wr, rectH);
2885 f := x0+wl;
2886 while (f < x0+rectW) do
2887 begin
2888 e_DrawSize(idb, f, y0, 0, true, false, wb, hb);
2889 f += wb;
2890 end;
2892 // filled part
2893 wdt := (rectW-wl-wr)*cur div total;
2894 if (wdt > rectW-wl-wr) then wdt := rectW-wr-wr;
2895 if (wdt > 0) then
2896 begin
2897 my := y0; // don't be so smart, ketmar: +(rectH-wm) div 2;
2898 glScissor(x0+wl, gScreenHeight-my-rectH, wdt, hm);
2899 f := x0+wl;
2900 while (wdt > 0) do
2901 begin
2902 e_DrawSize(idm, f, y0, 0, true, false, wm, hm);
2903 f += wm;
2904 wdt -= wm;
2905 end;
2906 end;
2908 glScissor(0, 0, gScreenWidth, gScreenHeight);
2909 end
2910 else
2911 begin
2912 rectW := gScreenWidth-64;
2913 rectH := 16;
2915 x0 := (gScreenWidth-rectW) div 2;
2916 y0 := gScreenHeight-rectH-64;
2917 if (y0 < 2) then y0 := 2;
2919 glDisable(GL_BLEND);
2920 glDisable(GL_TEXTURE_2D);
2922 //glClearColor(0, 0, 0, 0);
2923 //glClear(GL_COLOR_BUFFER_BIT);
2925 glColor4ub(127, 127, 127, 255);
2926 drawRect(x0-2, y0-2, rectW+4, rectH+4);
2928 glColor4ub(0, 0, 0, 255);
2929 drawRect(x0-1, y0-1, rectW+2, rectH+2);
2931 glColor4ub(127, 127, 127, 255);
2932 wdt := rectW*cur div total;
2933 if (wdt > rectW) then wdt := rectW;
2934 drawRect(x0, y0, wdt, rectH);
2935 end;
2936 end;
2938 var
2939 ww, hh: Word;
2940 xx, yy, i: Integer;
2941 s: String;
2942 begin
2943 if (Length(LoadingStat.Msgs) = 0) then exit;
2945 e_CharFont_GetSize(gMenuFont, _lc[I_MENU_LOADING], ww, hh);
2946 yy := (gScreenHeight div 3);
2947 e_CharFont_Print(gMenuFont, (gScreenWidth div 2)-(ww div 2), yy-2*hh, _lc[I_MENU_LOADING]);
2948 xx := (gScreenWidth div 3);
2950 with LoadingStat do
2951 begin
2952 for i := 0 to NextMsg-1 do
2953 begin
2954 if (i = (NextMsg-1)) and (MaxValue > 0) then
2955 s := Format('%s: %d/%d', [Msgs[i], CurValue, MaxValue])
2956 else
2957 s := Msgs[i];
2959 e_CharFont_PrintEx(gMenuSmallFont, xx, yy, s, _RGB(255, 0, 0));
2960 yy := yy + LOADING_INTERLINE;
2961 PBarWasHere := drawPBar(CurValue, MaxValue, PBarWasHere);
2962 end;
2963 end;
2964 end;
2966 procedure DrawMinimap(p: TPlayer; RenderRect: e_graphics.TRect);
2967 var
2968 a, aX, aY, aX2, aY2, Scale, ScaleSz: Integer;
2970 function monDraw (mon: TMonster): Boolean;
2971 begin
2972 result := false; // don't stop
2973 with mon do
2974 begin
2975 if alive then
2976 begin
2977 // Ëåâûé âåðõíèé óãîë
2978 aX := Obj.X div ScaleSz + 1;
2979 aY := Obj.Y div ScaleSz + 1;
2980 // Ðàçìåðû
2981 aX2 := max(Obj.Rect.Width div ScaleSz, 1);
2982 aY2 := max(Obj.Rect.Height div ScaleSz, 1);
2983 // Ïðàâûé íèæíèé óãîë
2984 aX2 := aX + aX2 - 1;
2985 aY2 := aY + aY2 - 1;
2986 e_DrawFillQuad(aX, aY, aX2, aY2, 255, 255, 0, 0);
2987 end;
2988 end;
2989 end;
2991 begin
2992 if (gMapInfo.Width > RenderRect.Right - RenderRect.Left) or
2993 (gMapInfo.Height > RenderRect.Bottom - RenderRect.Top) then
2994 begin
2995 Scale := 1;
2996 // Ñêîëüêî ïèêñåëîâ êàðòû â 1 ïèêñåëå ìèíè-êàðòû:
2997 ScaleSz := 16 div Scale;
2998 // Ðàçìåðû ìèíè-êàðòû:
2999 aX := max(gMapInfo.Width div ScaleSz, 1);
3000 aY := max(gMapInfo.Height div ScaleSz, 1);
3001 // Ðàìêà êàðòû:
3002 e_DrawFillQuad(0, 0, aX-1, aY-1, 0, 0, 0, 0);
3004 if gWalls <> nil then
3005 begin
3006 // Ðèñóåì ñòåíû:
3007 for a := 0 to High(gWalls) do
3008 with gWalls[a] do
3009 if PanelType <> 0 then
3010 begin
3011 // Ëåâûé âåðõíèé óãîë:
3012 aX := X div ScaleSz;
3013 aY := Y div ScaleSz;
3014 // Ðàçìåðû:
3015 aX2 := max(Width div ScaleSz, 1);
3016 aY2 := max(Height div ScaleSz, 1);
3017 // Ïðàâûé íèæíèé óãîë:
3018 aX2 := aX + aX2 - 1;
3019 aY2 := aY + aY2 - 1;
3021 case PanelType of
3022 PANEL_WALL: e_DrawFillQuad(aX, aY, aX2, aY2, 208, 208, 208, 0);
3023 PANEL_OPENDOOR, PANEL_CLOSEDOOR:
3024 if Enabled then e_DrawFillQuad(aX, aY, aX2, aY2, 160, 160, 160, 0);
3025 end;
3026 end;
3027 end;
3028 if gSteps <> nil then
3029 begin
3030 // Ðèñóåì ñòóïåíè:
3031 for a := 0 to High(gSteps) do
3032 with gSteps[a] do
3033 if PanelType <> 0 then
3034 begin
3035 // Ëåâûé âåðõíèé óãîë:
3036 aX := X div ScaleSz;
3037 aY := Y div ScaleSz;
3038 // Ðàçìåðû:
3039 aX2 := max(Width div ScaleSz, 1);
3040 aY2 := max(Height div ScaleSz, 1);
3041 // Ïðàâûé íèæíèé óãîë:
3042 aX2 := aX + aX2 - 1;
3043 aY2 := aY + aY2 - 1;
3045 e_DrawFillQuad(aX, aY, aX2, aY2, 128, 128, 128, 0);
3046 end;
3047 end;
3048 if gLifts <> nil then
3049 begin
3050 // Ðèñóåì ëèôòû:
3051 for a := 0 to High(gLifts) do
3052 with gLifts[a] do
3053 if PanelType <> 0 then
3054 begin
3055 // Ëåâûé âåðõíèé óãîë:
3056 aX := X div ScaleSz;
3057 aY := Y div ScaleSz;
3058 // Ðàçìåðû:
3059 aX2 := max(Width div ScaleSz, 1);
3060 aY2 := max(Height div ScaleSz, 1);
3061 // Ïðàâûé íèæíèé óãîë:
3062 aX2 := aX + aX2 - 1;
3063 aY2 := aY + aY2 - 1;
3065 case LiftType of
3066 LIFTTYPE_UP: e_DrawFillQuad(aX, aY, aX2, aY2, 116, 72, 36, 0);
3067 LIFTTYPE_DOWN: e_DrawFillQuad(aX, aY, aX2, aY2, 116, 124, 96, 0);
3068 LIFTTYPE_LEFT: e_DrawFillQuad(aX, aY, aX2, aY2, 200, 80, 4, 0);
3069 LIFTTYPE_RIGHT: e_DrawFillQuad(aX, aY, aX2, aY2, 252, 140, 56, 0);
3070 end;
3071 end;
3072 end;
3073 if gWater <> nil then
3074 begin
3075 // Ðèñóåì âîäó:
3076 for a := 0 to High(gWater) do
3077 with gWater[a] do
3078 if PanelType <> 0 then
3079 begin
3080 // Ëåâûé âåðõíèé óãîë:
3081 aX := X div ScaleSz;
3082 aY := Y div ScaleSz;
3083 // Ðàçìåðû:
3084 aX2 := max(Width div ScaleSz, 1);
3085 aY2 := max(Height div ScaleSz, 1);
3086 // Ïðàâûé íèæíèé óãîë:
3087 aX2 := aX + aX2 - 1;
3088 aY2 := aY + aY2 - 1;
3090 e_DrawFillQuad(aX, aY, aX2, aY2, 0, 0, 192, 0);
3091 end;
3092 end;
3093 if gAcid1 <> nil then
3094 begin
3095 // Ðèñóåì êèñëîòó 1:
3096 for a := 0 to High(gAcid1) do
3097 with gAcid1[a] do
3098 if PanelType <> 0 then
3099 begin
3100 // Ëåâûé âåðõíèé óãîë:
3101 aX := X div ScaleSz;
3102 aY := Y div ScaleSz;
3103 // Ðàçìåðû:
3104 aX2 := max(Width div ScaleSz, 1);
3105 aY2 := max(Height div ScaleSz, 1);
3106 // Ïðàâûé íèæíèé óãîë:
3107 aX2 := aX + aX2 - 1;
3108 aY2 := aY + aY2 - 1;
3110 e_DrawFillQuad(aX, aY, aX2, aY2, 0, 176, 0, 0);
3111 end;
3112 end;
3113 if gAcid2 <> nil then
3114 begin
3115 // Ðèñóåì êèñëîòó 2:
3116 for a := 0 to High(gAcid2) do
3117 with gAcid2[a] do
3118 if PanelType <> 0 then
3119 begin
3120 // Ëåâûé âåðõíèé óãîë:
3121 aX := X div ScaleSz;
3122 aY := Y div ScaleSz;
3123 // Ðàçìåðû:
3124 aX2 := max(Width div ScaleSz, 1);
3125 aY2 := max(Height div ScaleSz, 1);
3126 // Ïðàâûé íèæíèé óãîë:
3127 aX2 := aX + aX2 - 1;
3128 aY2 := aY + aY2 - 1;
3130 e_DrawFillQuad(aX, aY, aX2, aY2, 176, 0, 0, 0);
3131 end;
3132 end;
3133 if gPlayers <> nil then
3134 begin
3135 // Ðèñóåì èãðîêîâ:
3136 for a := 0 to High(gPlayers) do
3137 if gPlayers[a] <> nil then with gPlayers[a] do
3138 if alive then begin
3139 // Ëåâûé âåðõíèé óãîë:
3140 aX := Obj.X div ScaleSz + 1;
3141 aY := Obj.Y div ScaleSz + 1;
3142 // Ðàçìåðû:
3143 aX2 := max(Obj.Rect.Width div ScaleSz, 1);
3144 aY2 := max(Obj.Rect.Height div ScaleSz, 1);
3145 // Ïðàâûé íèæíèé óãîë:
3146 aX2 := aX + aX2 - 1;
3147 aY2 := aY + aY2 - 1;
3149 if gPlayers[a] = p then
3150 e_DrawFillQuad(aX, aY, aX2, aY2, 0, 255, 0, 0)
3151 else
3152 case Team of
3153 TEAM_RED: e_DrawFillQuad(aX, aY, aX2, aY2, 255, 0, 0, 0);
3154 TEAM_BLUE: e_DrawFillQuad(aX, aY, aX2, aY2, 0, 0, 255, 0);
3155 else e_DrawFillQuad(aX, aY, aX2, aY2, 255, 128, 0, 0);
3156 end;
3157 end;
3158 end;
3159 // Ðèñóåì ìîíñòðîâ
3160 g_Mons_ForEach(monDraw);
3161 end;
3162 end;
3165 procedure renderAmbientQuad (hasAmbient: Boolean; constref ambColor: TDFColor);
3166 begin
3167 if not hasAmbient then exit;
3168 e_AmbientQuad(sX, sY, sWidth, sHeight, ambColor.r, ambColor.g, ambColor.b, ambColor.a);
3169 end;
3172 // setup sX, sY, sWidth, sHeight, and transformation matrix before calling this!
3173 //FIXME: broken for splitscreen mode
3174 procedure renderDynLightsInternal ();
3175 var
3176 //hasAmbient: Boolean;
3177 //ambColor: TDFColor;
3178 lln: Integer;
3179 lx, ly, lrad: Integer;
3180 scxywh: array[0..3] of GLint;
3181 wassc: Boolean;
3182 begin
3183 if e_NoGraphics then exit;
3185 //TODO: lights should be in separate grid, i think
3186 // but on the other side: grid may be slower for dynlights, as their lifetime is short
3187 if (not gwin_k8_enable_light_experiments) or (not gwin_has_stencil) or (g_dynLightCount < 1) then exit;
3189 // rendering mode
3190 //ambColor := gCurrentMap['light_ambient'].rgba;
3191 //hasAmbient := (not ambColor.isOpaque) or (not ambColor.isBlack);
3193 { // this will multiply incoming color to alpha from framebuffer
3194 glEnable(GL_BLEND);
3195 glBlendFunc(GL_DST_ALPHA, GL_ONE);
3198 (*
3199 * light rendering: (INVALID!)
3200 * glStencilFunc(GL_EQUAL, 0, $ff);
3201 * for each light:
3202 * glClear(GL_STENCIL_BUFFER_BIT);
3203 * glStencilOp(GL_KEEP, GL_KEEP, GL_INCR);
3204 * draw shadow volume into stencil buffer
3205 * glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); // modify color buffer
3206 * glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); // don't modify stencil buffer
3207 * turn off blending
3208 * draw color-less quad with light alpha (WARNING! don't touch color!)
3209 * glEnable(GL_BLEND);
3210 * glBlendFunc(GL_DST_ALPHA, GL_ONE);
3211 * draw all geometry up to and including walls (with alpha-testing, probably) -- this does lighting
3212 *)
3213 wassc := (glIsEnabled(GL_SCISSOR_TEST) <> 0);
3214 if wassc then glGetIntegerv(GL_SCISSOR_BOX, @scxywh[0]) else glGetIntegerv(GL_VIEWPORT, @scxywh[0]);
3216 // setup OpenGL parameters
3217 glStencilMask($FFFFFFFF);
3218 glStencilFunc(GL_ALWAYS, 0, $FFFFFFFF);
3219 glEnable(GL_STENCIL_TEST);
3220 glEnable(GL_SCISSOR_TEST);
3221 glClear(GL_STENCIL_BUFFER_BIT);
3222 glStencilFunc(GL_EQUAL, 0, $ff);
3224 for lln := 0 to g_dynLightCount-1 do
3225 begin
3226 lx := g_dynLights[lln].x;
3227 ly := g_dynLights[lln].y;
3228 lrad := g_dynLights[lln].radius;
3229 if (lrad < 3) then continue;
3231 if (lx-sX+lrad < 0) then continue;
3232 if (ly-sY+lrad < 0) then continue;
3233 if (lx-sX-lrad >= gPlayerScreenSize.X) then continue;
3234 if (ly-sY-lrad >= gPlayerScreenSize.Y) then continue;
3236 // set scissor to optimize drawing
3237 if (g_dbg_scale = 1.0) then
3238 begin
3239 glScissor((lx-sX)-lrad+2, gPlayerScreenSize.Y-(ly-sY)-lrad-1+2, lrad*2-4, lrad*2-4);
3240 end
3241 else
3242 begin
3243 glScissor(0, 0, gWinSizeX, gWinSizeY);
3244 end;
3245 // no need to clear stencil buffer, light blitting will do it for us... but only for normal scale
3246 if (g_dbg_scale <> 1.0) then glClear(GL_STENCIL_BUFFER_BIT);
3247 glStencilOp(GL_KEEP, GL_KEEP, GL_INCR);
3248 // draw extruded panels
3249 glDisable(GL_TEXTURE_2D);
3250 glDisable(GL_BLEND);
3251 glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); // no need to modify color buffer
3252 if (lrad > 4) then g_Map_DrawPanelShadowVolumes(lx, ly, lrad);
3253 // render light texture
3254 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); // modify color buffer
3255 glStencilOp(GL_ZERO, GL_ZERO, GL_ZERO); // draw light, and clear stencil buffer
3256 // blend it
3257 glEnable(GL_BLEND);
3258 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
3259 glEnable(GL_TEXTURE_2D);
3260 // color and opacity
3261 glColor4f(g_dynLights[lln].r, g_dynLights[lln].g, g_dynLights[lln].b, g_dynLights[lln].a);
3262 glBindTexture(GL_TEXTURE_2D, g_Texture_Light());
3263 glBegin(GL_QUADS);
3264 glTexCoord2f(0.0, 0.0); glVertex2i(lx-lrad, ly-lrad); // top-left
3265 glTexCoord2f(1.0, 0.0); glVertex2i(lx+lrad, ly-lrad); // top-right
3266 glTexCoord2f(1.0, 1.0); glVertex2i(lx+lrad, ly+lrad); // bottom-right
3267 glTexCoord2f(0.0, 1.0); glVertex2i(lx-lrad, ly+lrad); // bottom-left
3268 glEnd();
3269 end;
3271 // done
3272 glDisable(GL_STENCIL_TEST);
3273 glDisable(GL_BLEND);
3274 glDisable(GL_SCISSOR_TEST);
3275 //glScissor(0, 0, sWidth, sHeight);
3277 glScissor(scxywh[0], scxywh[1], scxywh[2], scxywh[3]);
3278 if wassc then glEnable(GL_SCISSOR_TEST) else glDisable(GL_SCISSOR_TEST);
3279 end;
3282 function fixViewportForScale (): Boolean;
3283 var
3284 nx0, ny0, nw, nh: Integer;
3285 begin
3286 result := false;
3287 if (g_dbg_scale <> 1.0) then
3288 begin
3289 result := true;
3290 nx0 := round(sX-(gPlayerScreenSize.X-(sWidth*g_dbg_scale))/2/g_dbg_scale);
3291 ny0 := round(sY-(gPlayerScreenSize.Y-(sHeight*g_dbg_scale))/2/g_dbg_scale);
3292 nw := round(sWidth/g_dbg_scale);
3293 nh := round(sHeight/g_dbg_scale);
3294 sX := nx0;
3295 sY := ny0;
3296 sWidth := nw;
3297 sHeight := nh;
3298 end;
3299 end;
3302 // setup sX, sY, sWidth, sHeight, and transformation matrix before calling this!
3303 // WARNING! this WILL CALL `glTranslatef()`, but won't restore matrices!
3304 procedure renderMapInternal (backXOfs, backYOfs: Integer; setTransMatrix: Boolean);
3305 type
3306 TDrawCB = procedure ();
3308 var
3309 hasAmbient: Boolean;
3310 ambColor: TDFColor;
3311 doAmbient: Boolean = false;
3313 procedure drawPanelType (profname: AnsiString; panType: DWord; doDraw: Boolean);
3314 var
3315 tagmask: Integer;
3316 pan: TPanel;
3317 begin
3318 if (profileFrameDraw <> nil) then profileFrameDraw.sectionBegin(profname);
3319 if gdbg_map_use_accel_render then
3320 begin
3321 tagmask := panelTypeToTag(panType);
3322 while (gDrawPanelList.count > 0) do
3323 begin
3324 pan := TPanel(gDrawPanelList.front());
3325 if ((pan.tag and tagmask) = 0) then break;
3326 if doDraw then pan.Draw(doAmbient, ambColor);
3327 gDrawPanelList.popFront();
3328 end;
3329 end
3330 else
3331 begin
3332 if doDraw then g_Map_DrawPanels(panType, hasAmbient, ambColor);
3333 end;
3334 if (profileFrameDraw <> nil) then profileFrameDraw.sectionEnd();
3335 end;
3337 procedure drawOther (profname: AnsiString; cb: TDrawCB);
3338 begin
3339 if (profileFrameDraw <> nil) then profileFrameDraw.sectionBegin(profname);
3340 if assigned(cb) then cb();
3341 if (profileFrameDraw <> nil) then profileFrameDraw.sectionEnd();
3342 end;
3344 begin
3345 if (profileFrameDraw <> nil) then profileFrameDraw.sectionBegin('total');
3347 // our accelerated renderer will collect all panels to gDrawPanelList
3348 // we can use panel tag to render level parts (see GridTagXXX in g_map.pas)
3349 if (profileFrameDraw <> nil) then profileFrameDraw.sectionBegin('collect');
3350 if gdbg_map_use_accel_render then
3351 begin
3352 g_Map_CollectDrawPanels(sX, sY, sWidth, sHeight);
3353 end;
3354 if (profileFrameDraw <> nil) then profileFrameDraw.sectionEnd();
3356 if (profileFrameDraw <> nil) then profileFrameDraw.sectionBegin('skyback');
3357 g_Map_DrawBack(backXOfs, backYOfs);
3358 if (profileFrameDraw <> nil) then profileFrameDraw.sectionEnd();
3360 if setTransMatrix then
3361 begin
3362 //if (g_dbg_scale <> 1.0) then glTranslatef(0.0, -0.375/2, 0);
3363 glScalef(g_dbg_scale, g_dbg_scale, 1.0);
3364 glTranslatef(-sX, -sY, 0);
3365 end;
3367 // rendering mode
3368 ambColor := gCurrentMap['light_ambient'].rgba;
3369 hasAmbient := (not ambColor.isOpaque) or (not ambColor.isBlack);
3372 if hasAmbient then
3373 begin
3374 //writeln('color: (', ambColor.r, ',', ambColor.g, ',', ambColor.b, ',', ambColor.a, ')');
3375 glColor4ub(ambColor.r, ambColor.g, ambColor.b, ambColor.a);
3376 glClear(GL_COLOR_BUFFER_BIT);
3377 end;
3379 //writeln('color: (', ambColor.r, ',', ambColor.g, ',', ambColor.b, ',', ambColor.a, ')');
3382 drawPanelType('*back', PANEL_BACK, g_rlayer_back);
3383 drawPanelType('*step', PANEL_STEP, g_rlayer_step);
3384 drawOther('items', @g_Items_Draw);
3385 drawOther('weapons', @g_Weapon_Draw);
3386 drawOther('shells', @g_Player_DrawShells);
3387 drawOther('drawall', @g_Player_DrawAll);
3388 drawOther('corpses', @g_Player_DrawCorpses);
3389 drawPanelType('*wall', PANEL_WALL, g_rlayer_wall);
3390 drawOther('monsters', @g_Monsters_Draw);
3391 drawOther('itemdrop', @g_Items_DrawDrop);
3392 drawPanelType('*door', PANEL_CLOSEDOOR, g_rlayer_door);
3393 drawOther('gfx', @g_GFX_Draw);
3394 drawOther('flags', @g_Map_DrawFlags);
3395 drawPanelType('*acid1', PANEL_ACID1, g_rlayer_acid1);
3396 drawPanelType('*acid2', PANEL_ACID2, g_rlayer_acid2);
3397 drawPanelType('*water', PANEL_WATER, g_rlayer_water);
3398 drawOther('dynlights', @renderDynLightsInternal);
3400 if hasAmbient {and ((not g_playerLight) or (not gwin_has_stencil) or (g_dynLightCount < 1))} then
3401 begin
3402 renderAmbientQuad(hasAmbient, ambColor);
3403 end;
3405 doAmbient := true;
3406 drawPanelType('*fore', PANEL_FORE, g_rlayer_fore);
3409 if g_debug_HealthBar then
3410 begin
3411 g_Monsters_DrawHealth();
3412 g_Player_DrawHealth();
3413 end;
3415 if (profileFrameDraw <> nil) then profileFrameDraw.mainEnd(); // map rendering
3416 end;
3419 procedure DrawMapView(x, y, w, h: Integer);
3421 var
3422 bx, by: Integer;
3423 begin
3424 glPushMatrix();
3426 bx := Round(x/(gMapInfo.Width - w)*(gBackSize.X - w));
3427 by := Round(y/(gMapInfo.Height - h)*(gBackSize.Y - h));
3429 sX := x;
3430 sY := y;
3431 sWidth := w;
3432 sHeight := h;
3434 fixViewportForScale();
3435 renderMapInternal(-bx, -by, true);
3437 glPopMatrix();
3438 end;
3441 procedure DrawPlayer(p: TPlayer);
3442 var
3443 px, py, a, b, c, d: Integer;
3444 //R: TRect;
3445 begin
3446 if (p = nil) or (p.FDummy) then
3447 begin
3448 glPushMatrix();
3449 g_Map_DrawBack(0, 0);
3450 glPopMatrix();
3451 Exit;
3452 end;
3454 if (profileFrameDraw = nil) then profileFrameDraw := TProfiler.Create('RENDER', g_profile_history_size);
3455 if (profileFrameDraw <> nil) then profileFrameDraw.mainBegin(g_profile_frame_draw);
3457 gPlayerDrawn := p;
3459 glPushMatrix();
3461 px := p.GameX + PLAYER_RECT_CX;
3462 py := p.GameY + PLAYER_RECT_CY+p.Obj.slopeUpLeft;
3464 if (g_dbg_scale = 1.0) and (not g_dbg_ignore_bounds) then
3465 begin
3466 if (px > (gPlayerScreenSize.X div 2)) then a := -px+(gPlayerScreenSize.X div 2) else a := 0;
3467 if (py > (gPlayerScreenSize.Y div 2)) then b := -py+(gPlayerScreenSize.Y div 2) else b := 0;
3469 if (px > gMapInfo.Width-(gPlayerScreenSize.X div 2)) then a := -gMapInfo.Width+gPlayerScreenSize.X;
3470 if (py > gMapInfo.Height-(gPlayerScreenSize.Y div 2)) then b := -gMapInfo.Height+gPlayerScreenSize.Y;
3472 if (gMapInfo.Width = gPlayerScreenSize.X) then a := 0
3473 else if (gMapInfo.Width < gPlayerScreenSize.X) then
3474 begin
3475 // hcenter
3476 a := (gPlayerScreenSize.X-gMapInfo.Width) div 2;
3477 end;
3479 if (gMapInfo.Height = gPlayerScreenSize.Y) then b := 0
3480 else if (gMapInfo.Height < gPlayerScreenSize.Y) then
3481 begin
3482 // vcenter
3483 b := (gPlayerScreenSize.Y-gMapInfo.Height) div 2;
3484 end;
3485 end
3486 else
3487 begin
3488 // scaled, ignore level bounds
3489 a := -px+(gPlayerScreenSize.X div 2);
3490 b := -py+(gPlayerScreenSize.Y div 2);
3491 end;
3493 if p.IncCam <> 0 then
3494 begin
3495 if py > gMapInfo.Height-(gPlayerScreenSize.Y div 2) then
3496 begin
3497 if p.IncCam > 120-(py-(gMapInfo.Height-(gPlayerScreenSize.Y div 2))) then
3498 begin
3499 p.IncCam := 120-(py-(gMapInfo.Height-(gPlayerScreenSize.Y div 2)));
3500 end;
3501 end;
3503 if py < gPlayerScreenSize.Y div 2 then
3504 begin
3505 if p.IncCam < -120+((gPlayerScreenSize.Y div 2)-py) then
3506 begin
3507 p.IncCam := -120+((gPlayerScreenSize.Y div 2)-py);
3508 end;
3509 end;
3511 if p.IncCam < 0 then
3512 begin
3513 while (py+(gPlayerScreenSize.Y div 2)-p.IncCam > gMapInfo.Height) and (p.IncCam < 0) do p.IncCam := p.IncCam+1; //Inc(p.IncCam);
3514 end;
3516 if p.IncCam > 0 then
3517 begin
3518 while (py-(gPlayerScreenSize.Y div 2)-p.IncCam < 0) and (p.IncCam > 0) do p.IncCam := p.IncCam-1; //Dec(p.IncCam);
3519 end;
3520 end;
3522 if (px < gPlayerScreenSize.X div 2) or (gMapInfo.Width-gPlayerScreenSize.X <= 256) then c := 0
3523 else if (px > gMapInfo.Width-(gPlayerScreenSize.X div 2)) then c := gBackSize.X-gPlayerScreenSize.X
3524 else c := round((px-(gPlayerScreenSize.X div 2))/(gMapInfo.Width-gPlayerScreenSize.X)*(gBackSize.X-gPlayerScreenSize.X));
3526 if (py-p.IncCam <= gPlayerScreenSize.Y div 2) or (gMapInfo.Height-gPlayerScreenSize.Y <= 256) then d := 0
3527 else if (py-p.IncCam >= gMapInfo.Height-(gPlayerScreenSize.Y div 2)) then d := gBackSize.Y-gPlayerScreenSize.Y
3528 else d := round((py-p.IncCam-(gPlayerScreenSize.Y div 2))/(gMapInfo.Height-gPlayerScreenSize.Y)*(gBackSize.Y-gPlayerScreenSize.Y));
3530 sX := -a;
3531 sY := -(b+p.IncCam);
3532 sWidth := gPlayerScreenSize.X;
3533 sHeight := gPlayerScreenSize.Y;
3535 //glTranslatef(a, b+p.IncCam, 0);
3537 //if (p = gPlayer1) and (g_dbg_scale >= 1.0) then g_Holmes_plrViewSize(sWidth, sHeight);
3539 //conwritefln('OLD: (%s,%s)-(%s,%s)', [sX, sY, sWidth, sHeight]);
3540 fixViewportForScale();
3541 //conwritefln(' (%s,%s)-(%s,%s)', [sX, sY, sWidth, sHeight]);
3543 if (g_dbg_scale <> 1.0) and (not g_dbg_ignore_bounds) then
3544 begin
3545 if (sX+sWidth > gMapInfo.Width) then sX := gMapInfo.Width-sWidth;
3546 if (sY+sHeight > gMapInfo.Height) then sY := gMapInfo.Height-sHeight;
3547 if (sX < 0) then sX := 0;
3548 if (sY < 0) then sY := 0;
3550 if (gBackSize.X <= gPlayerScreenSize.X) or (gMapInfo.Width <= sWidth) then c := 0 else c := trunc((gBackSize.X-gPlayerScreenSize.X)*sX/(gMapInfo.Width-sWidth));
3551 if (gBackSize.Y <= gPlayerScreenSize.Y) or (gMapInfo.Height <= sHeight) then d := 0 else d := trunc((gBackSize.Y-gPlayerScreenSize.Y)*sY/(gMapInfo.Height-sHeight));
3552 end;
3554 //r_smallmap_h: 0: left; 1: center; 2: right
3555 //r_smallmap_v: 0: top; 1: center; 2: bottom
3556 // horiz small map?
3557 if (gMapInfo.Width = sWidth) then
3558 begin
3559 sX := 0;
3560 end
3561 else if (gMapInfo.Width < sWidth) then
3562 begin
3563 case r_smallmap_h of
3564 1: sX := -((sWidth-gMapInfo.Width) div 2); // center
3565 2: sX := -(sWidth-gMapInfo.Width); // right
3566 else sX := 0; // left
3567 end;
3568 end;
3569 // vert small map?
3570 if (gMapInfo.Height = sHeight) then
3571 begin
3572 sY := 0;
3573 end
3574 else if (gMapInfo.Height < sHeight) then
3575 begin
3576 case r_smallmap_v of
3577 1: sY := -((sHeight-gMapInfo.Height) div 2); // center
3578 2: sY := -(sHeight-gMapInfo.Height); // bottom
3579 else sY := 0; // top
3580 end;
3581 end;
3583 p.viewPortX := sX;
3584 p.viewPortY := sY;
3585 p.viewPortW := sWidth;
3586 p.viewPortH := sHeight;
3588 {$IFDEF ENABLE_HOLMES}
3589 if (p = gPlayer1) then
3590 begin
3591 g_Holmes_plrViewPos(sX, sY);
3592 g_Holmes_plrViewSize(sWidth, sHeight);
3593 end;
3594 {$ENDIF}
3596 renderMapInternal(-c, -d, true);
3598 if (gGameSettings.GameMode <> GM_SINGLE) and gPlayerIndicator then
3599 p.DrawIndicator();
3600 if p.FSpectator then
3601 e_TextureFontPrintEx(p.GameX + PLAYER_RECT_CX - 4,
3602 p.GameY + PLAYER_RECT_CY - 4,
3603 'X', gStdFont, 255, 255, 255, 1, True);
3605 for a := 0 to High(gCollideMap) do
3606 for b := 0 to High(gCollideMap[a]) do
3607 begin
3608 d := 0;
3609 if ByteBool(gCollideMap[a, b] and MARK_WALL) then
3610 d := d + 1;
3611 if ByteBool(gCollideMap[a, b] and MARK_DOOR) then
3612 d := d + 2;
3614 case d of
3615 1: e_DrawPoint(1, b, a, 200, 200, 200);
3616 2: e_DrawPoint(1, b, a, 64, 64, 255);
3617 3: e_DrawPoint(1, b, a, 255, 0, 255);
3618 end;
3619 end;
3622 glPopMatrix();
3624 p.DrawPain();
3625 p.DrawPickup();
3626 p.DrawRulez();
3627 if gShowMap then DrawMinimap(p, _TRect(0, 0, 128, 128));
3628 if g_Debug_Player then
3629 g_Player_DrawDebug(p);
3630 p.DrawGUI();
3631 end;
3633 procedure drawProfilers ();
3634 var
3635 px: Integer = -1;
3636 py: Integer = -1;
3637 begin
3638 if g_profile_frame_draw and (profileFrameDraw <> nil) then px := px-drawProfiles(px, py, profileFrameDraw);
3639 if g_profile_collision and (profMapCollision <> nil) then begin px := px-drawProfiles(px, py, profMapCollision); py -= calcProfilesHeight(profMonsLOS); end;
3640 if g_profile_los and (profMonsLOS <> nil) then begin px := px-drawProfiles(px, py, profMonsLOS); py -= calcProfilesHeight(profMonsLOS); end;
3641 end;
3643 procedure g_Game_Draw();
3644 var
3645 ID: DWORD;
3646 w, h: Word;
3647 ww, hh: Byte;
3648 Time: Int64;
3649 back: string;
3650 plView1, plView2: TPlayer;
3651 Split: Boolean;
3652 begin
3653 if gExit = EXIT_QUIT then Exit;
3655 Time := GetTimer() {div 1000};
3656 FPSCounter := FPSCounter+1;
3657 if Time - FPSTime >= 1000 then
3658 begin
3659 FPS := FPSCounter;
3660 FPSCounter := 0;
3661 FPSTime := Time;
3662 end;
3664 if gGameOn or (gState = STATE_FOLD) then
3665 begin
3666 if (gPlayer1 <> nil) and (gPlayer2 <> nil) then
3667 begin
3668 gSpectMode := SPECT_NONE;
3669 if not gRevertPlayers then
3670 begin
3671 plView1 := gPlayer1;
3672 plView2 := gPlayer2;
3673 end
3674 else
3675 begin
3676 plView1 := gPlayer2;
3677 plView2 := gPlayer1;
3678 end;
3679 end
3680 else
3681 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
3682 begin
3683 gSpectMode := SPECT_NONE;
3684 if gPlayer2 = nil then
3685 plView1 := gPlayer1
3686 else
3687 plView1 := gPlayer2;
3688 plView2 := nil;
3689 end
3690 else
3691 begin
3692 plView1 := nil;
3693 plView2 := nil;
3694 end;
3696 if (plView1 = nil) and (plView2 = nil) and (gSpectMode = SPECT_NONE) then
3697 gSpectMode := SPECT_STATS;
3699 if gSpectMode = SPECT_PLAYERS then
3700 if gPlayers <> nil then
3701 begin
3702 plView1 := GetActivePlayer_ByID(gSpectPID1);
3703 if plView1 = nil then
3704 begin
3705 gSpectPID1 := GetActivePlayerID_Next();
3706 plView1 := GetActivePlayer_ByID(gSpectPID1);
3707 end;
3708 if gSpectViewTwo then
3709 begin
3710 plView2 := GetActivePlayer_ByID(gSpectPID2);
3711 if plView2 = nil then
3712 begin
3713 gSpectPID2 := GetActivePlayerID_Next();
3714 plView2 := GetActivePlayer_ByID(gSpectPID2);
3715 end;
3716 end;
3717 end;
3719 if gSpectMode = SPECT_MAPVIEW then
3720 begin
3721 // Ðåæèì ïðîñìîòðà êàðòû
3722 Split := False;
3723 e_SetViewPort(0, 0, gScreenWidth, gScreenHeight);
3724 DrawMapView(gSpectX, gSpectY, gScreenWidth, gScreenHeight);
3725 gHearPoint1.Active := True;
3726 gHearPoint1.Coords.X := gScreenWidth div 2 + gSpectX;
3727 gHearPoint1.Coords.Y := gScreenHeight div 2 + gSpectY;
3728 gHearPoint2.Active := False;
3729 end
3730 else
3731 begin
3732 Split := (plView1 <> nil) and (plView2 <> nil);
3734 // Òî÷êè ñëóõà èãðîêîâ
3735 if plView1 <> nil then
3736 begin
3737 gHearPoint1.Active := True;
3738 gHearPoint1.Coords.X := plView1.GameX;
3739 gHearPoint1.Coords.Y := plView1.GameY;
3740 end else
3741 gHearPoint1.Active := False;
3742 if plView2 <> nil then
3743 begin
3744 gHearPoint2.Active := True;
3745 gHearPoint2.Coords.X := plView2.GameX;
3746 gHearPoint2.Coords.Y := plView2.GameY;
3747 end else
3748 gHearPoint2.Active := False;
3750 // Ðàçìåð ýêðàíîâ èãðîêîâ:
3751 gPlayerScreenSize.X := gScreenWidth-196;
3752 if Split then
3753 begin
3754 gPlayerScreenSize.Y := gScreenHeight div 2;
3755 if gScreenHeight mod 2 = 0 then
3756 Dec(gPlayerScreenSize.Y);
3757 end
3758 else
3759 gPlayerScreenSize.Y := gScreenHeight;
3761 if Split then
3762 if gScreenHeight mod 2 = 0 then
3763 e_SetViewPort(0, gPlayerScreenSize.Y+2, gPlayerScreenSize.X+196, gPlayerScreenSize.Y)
3764 else
3765 e_SetViewPort(0, gPlayerScreenSize.Y+1, gPlayerScreenSize.X+196, gPlayerScreenSize.Y);
3767 DrawPlayer(plView1);
3768 gPlayer1ScreenCoord.X := sX;
3769 gPlayer1ScreenCoord.Y := sY;
3771 if Split then
3772 begin
3773 e_SetViewPort(0, 0, gPlayerScreenSize.X+196, gPlayerScreenSize.Y);
3775 DrawPlayer(plView2);
3776 gPlayer2ScreenCoord.X := sX;
3777 gPlayer2ScreenCoord.Y := sY;
3778 end;
3780 e_SetViewPort(0, 0, gScreenWidth, gScreenHeight);
3782 if Split then
3783 e_DrawLine(2, 0, gScreenHeight div 2, gScreenWidth, gScreenHeight div 2, 0, 0, 0);
3784 end;
3786 {$IFDEF ENABLE_HOLMES}
3787 // draw inspector
3788 if (g_holmes_enabled) then g_Holmes_Draw();
3789 {$ENDIF}
3791 if MessageText <> '' then
3792 begin
3793 w := 0;
3794 h := 0;
3795 e_CharFont_GetSizeFmt(gMenuFont, MessageText, w, h);
3796 if Split then
3797 e_CharFont_PrintFmt(gMenuFont, (gScreenWidth div 2)-(w div 2),
3798 (gScreenHeight div 2)-(h div 2), MessageText)
3799 else
3800 e_CharFont_PrintFmt(gMenuFont, (gScreenWidth div 2)-(w div 2),
3801 Round(gScreenHeight / 2.75)-(h div 2), MessageText);
3802 end;
3804 if IsDrawStat or (gSpectMode = 1) then DrawStat();
3806 if gSpectHUD and (not gChatShow) and (gSpectMode <> SPECT_NONE) and (not gSpectAuto) then
3807 begin
3808 // Draw spectator GUI
3809 ww := 0;
3810 hh := 0;
3811 e_TextureFontGetSize(gStdFont, ww, hh);
3812 case gSpectMode of
3813 SPECT_STATS:
3814 e_TextureFontPrintEx(0, gScreenHeight - (hh+2)*2, 'MODE: Stats', gStdFont, 255, 255, 255, 1);
3815 SPECT_MAPVIEW:
3816 e_TextureFontPrintEx(0, gScreenHeight - (hh+2)*2, 'MODE: Observe Map', gStdFont, 255, 255, 255, 1);
3817 SPECT_PLAYERS:
3818 e_TextureFontPrintEx(0, gScreenHeight - (hh+2)*2, 'MODE: Watch Players', gStdFont, 255, 255, 255, 1);
3819 end;
3820 e_TextureFontPrintEx(2*ww, gScreenHeight - (hh+2), '< jump >', gStdFont, 255, 255, 255, 1);
3821 if gSpectMode = SPECT_STATS then
3822 begin
3823 e_TextureFontPrintEx(16*ww, gScreenHeight - (hh+2)*2, 'Autoview', gStdFont, 255, 255, 255, 1);
3824 e_TextureFontPrintEx(16*ww, gScreenHeight - (hh+2), '< fire >', gStdFont, 255, 255, 255, 1);
3825 end;
3826 if gSpectMode = SPECT_MAPVIEW then
3827 begin
3828 e_TextureFontPrintEx(22*ww, gScreenHeight - (hh+2)*2, '[-]', gStdFont, 255, 255, 255, 1);
3829 e_TextureFontPrintEx(26*ww, gScreenHeight - (hh+2)*2, 'Step ' + IntToStr(gSpectStep), gStdFont, 255, 255, 255, 1);
3830 e_TextureFontPrintEx(34*ww, gScreenHeight - (hh+2)*2, '[+]', gStdFont, 255, 255, 255, 1);
3831 e_TextureFontPrintEx(18*ww, gScreenHeight - (hh+2), '<prev weap>', gStdFont, 255, 255, 255, 1);
3832 e_TextureFontPrintEx(30*ww, gScreenHeight - (hh+2), '<next weap>', gStdFont, 255, 255, 255, 1);
3833 end;
3834 if gSpectMode = SPECT_PLAYERS then
3835 begin
3836 e_TextureFontPrintEx(22*ww, gScreenHeight - (hh+2)*2, 'Player 1', gStdFont, 255, 255, 255, 1);
3837 e_TextureFontPrintEx(20*ww, gScreenHeight - (hh+2), '<left/right>', gStdFont, 255, 255, 255, 1);
3838 if gSpectViewTwo then
3839 begin
3840 e_TextureFontPrintEx(37*ww, gScreenHeight - (hh+2)*2, 'Player 2', gStdFont, 255, 255, 255, 1);
3841 e_TextureFontPrintEx(34*ww, gScreenHeight - (hh+2), '<prev w/next w>', gStdFont, 255, 255, 255, 1);
3842 e_TextureFontPrintEx(52*ww, gScreenHeight - (hh+2)*2, '2x View', gStdFont, 255, 255, 255, 1);
3843 e_TextureFontPrintEx(51*ww, gScreenHeight - (hh+2), '<up/down>', gStdFont, 255, 255, 255, 1);
3844 end
3845 else
3846 begin
3847 e_TextureFontPrintEx(35*ww, gScreenHeight - (hh+2)*2, '2x View', gStdFont, 255, 255, 255, 1);
3848 e_TextureFontPrintEx(34*ww, gScreenHeight - (hh+2), '<up/down>', gStdFont, 255, 255, 255, 1);
3849 end;
3850 end;
3851 end;
3852 end;
3854 if gPauseMain and gGameOn and (g_ActiveWindow = nil) then
3855 begin
3856 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
3857 e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
3859 e_CharFont_GetSize(gMenuFont, _lc[I_MENU_PAUSE], w, h);
3860 e_CharFont_Print(gMenuFont, (gScreenWidth div 2)-(w div 2),
3861 (gScreenHeight div 2)-(h div 2), _lc[I_MENU_PAUSE]);
3862 end;
3864 if not gGameOn then
3865 begin
3866 if (gState = STATE_MENU) then
3867 begin
3868 if (g_ActiveWindow = nil) or (g_ActiveWindow.BackTexture = '') then
3869 begin
3870 if g_Texture_Get('MENU_BACKGROUND', ID) then e_DrawSize(ID, 0, 0, 0, False, False, gScreenWidth, gScreenHeight)
3871 else e_Clear(GL_COLOR_BUFFER_BIT, 0, 0, 0);
3872 end;
3873 // F3 at menu will show game loading dialog
3874 if e_KeyPressed(IK_F3) then g_Menu_Show_LoadMenu(true);
3875 if (g_ActiveWindow <> nil) then
3876 begin
3877 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
3878 e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
3879 end
3880 else
3881 begin
3882 // F3 at titlepic will show game loading dialog
3883 if e_KeyPressed(IK_F3) then
3884 begin
3885 g_Menu_Show_LoadMenu(true);
3886 if (g_ActiveWindow <> nil) then e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
3887 end;
3888 end;
3889 end;
3891 if gState = STATE_FOLD then
3892 begin
3893 e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 0, 0, 0, EndingGameCounter);
3894 end;
3896 if gState = STATE_INTERCUSTOM then
3897 begin
3898 if gLastMap and (gGameSettings.GameMode = GM_COOP) then
3899 begin
3900 back := 'TEXTURE_endpic';
3901 if not g_Texture_Get(back, ID) then
3902 back := _lc[I_TEXTURE_ENDPIC];
3903 end
3904 else
3905 back := 'INTER';
3907 if g_Texture_Get(back, ID) then
3908 e_DrawSize(ID, 0, 0, 0, False, False, gScreenWidth, gScreenHeight)
3909 else
3910 e_Clear(GL_COLOR_BUFFER_BIT, 0, 0, 0);
3912 DrawCustomStat();
3914 if g_ActiveWindow <> nil then
3915 begin
3916 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
3917 e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
3918 end;
3919 end;
3921 if gState = STATE_INTERSINGLE then
3922 begin
3923 if EndingGameCounter > 0 then
3924 begin
3925 e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 0, 0, 0, EndingGameCounter);
3926 end
3927 else
3928 begin
3929 back := 'INTER';
3931 if g_Texture_Get(back, ID) then
3932 e_DrawSize(ID, 0, 0, 0, False, False, gScreenWidth, gScreenHeight)
3933 else
3934 e_Clear(GL_COLOR_BUFFER_BIT, 0, 0, 0);
3936 DrawSingleStat();
3938 if g_ActiveWindow <> nil then
3939 begin
3940 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
3941 e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
3942 end;
3943 end;
3944 end;
3946 if gState = STATE_ENDPIC then
3947 begin
3948 ID := DWORD(-1);
3949 if not g_Texture_Get('TEXTURE_endpic', ID) then
3950 g_Texture_Get(_lc[I_TEXTURE_ENDPIC], ID);
3952 if ID <> DWORD(-1) then
3953 e_DrawSize(ID, 0, 0, 0, False, False, gScreenWidth, gScreenHeight)
3954 else
3955 e_Clear(GL_COLOR_BUFFER_BIT, 0, 0, 0);
3957 if g_ActiveWindow <> nil then
3958 begin
3959 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
3960 e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
3961 end;
3962 end;
3964 if gState = STATE_SLIST then
3965 begin
3966 if g_Texture_Get('MENU_BACKGROUND', ID) then
3967 begin
3968 e_DrawSize(ID, 0, 0, 0, False, False, gScreenWidth, gScreenHeight);
3969 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
3970 e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
3971 end;
3972 g_Serverlist_Draw(slCurrent, slTable);
3973 end;
3974 end;
3976 if g_ActiveWindow <> nil then
3977 begin
3978 if gGameOn then
3979 begin
3980 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
3981 e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
3982 end;
3983 g_ActiveWindow.Draw();
3984 end;
3986 g_Console_Draw();
3988 if g_debug_Sounds and gGameOn then
3989 begin
3990 for w := 0 to High(e_SoundsArray) do
3991 for h := 0 to e_SoundsArray[w].nRefs do
3992 e_DrawPoint(1, w+100, h+100, 255, 0, 0);
3993 end;
3995 if gShowFPS then
3996 begin
3997 e_TextureFontPrint(0, 0, Format('FPS: %d', [FPS]), gStdFont);
3998 e_TextureFontPrint(0, 16, Format('UPS: %d', [UPS]), gStdFont);
3999 end;
4001 if gGameOn and gShowTime and (gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT]) then
4002 drawTime(gScreenWidth-72, gScreenHeight-16);
4004 if gGameOn then drawProfilers();
4006 {$IFDEF ENABLE_HOLMES}
4007 g_Holmes_DrawUI();
4008 {$ENDIF}
4010 g_Touch_Draw;
4011 end;
4013 procedure g_Game_Quit();
4014 begin
4015 g_Game_StopAllSounds(True);
4016 gMusic.Free();
4017 g_Game_SaveOptions();
4018 g_Game_FreeData();
4019 g_PlayerModel_FreeData();
4020 g_Texture_DeleteAll();
4021 g_Frames_DeleteAll();
4022 //g_Menu_Free(); //k8: this segfaults after resolution change; who cares?
4024 if NetInitDone then g_Net_Free;
4026 // Íàäî óäàëèòü êàðòó ïîñëå òåñòà:
4027 if gMapToDelete <> '' then
4028 g_Game_DeleteTestMap();
4030 gExit := EXIT_QUIT;
4031 PushExitEvent();
4032 end;
4034 procedure g_FatalError(Text: String);
4035 begin
4036 g_Console_Add(Format(_lc[I_FATAL_ERROR], [Text]), True);
4037 e_WriteLog(Format(_lc[I_FATAL_ERROR], [Text]), TMsgType.Warning);
4039 gExit := EXIT_SIMPLE;
4040 end;
4042 procedure g_SimpleError(Text: String);
4043 begin
4044 g_Console_Add(Format(_lc[I_SIMPLE_ERROR], [Text]), True);
4045 e_WriteLog(Format(_lc[I_SIMPLE_ERROR], [Text]), TMsgType.Warning);
4046 end;
4048 procedure g_Game_SetupScreenSize();
4049 const
4050 RES_FACTOR = 4.0 / 3.0;
4051 var
4052 s: Single;
4053 rf: Single;
4054 bw, bh: Word;
4055 begin
4056 // Ðàçìåð ýêðàíîâ èãðîêîâ:
4057 gPlayerScreenSize.X := gScreenWidth-196;
4058 if (gPlayer1 <> nil) and (gPlayer2 <> nil) then
4059 gPlayerScreenSize.Y := gScreenHeight div 2
4060 else
4061 gPlayerScreenSize.Y := gScreenHeight;
4063 // Ðàçìåð çàäíåãî ïëàíà:
4064 if BackID <> DWORD(-1) then
4065 begin
4066 s := SKY_STRETCH;
4067 if (gScreenWidth*s > gMapInfo.Width) or
4068 (gScreenHeight*s > gMapInfo.Height) then
4069 begin
4070 gBackSize.X := gScreenWidth;
4071 gBackSize.Y := gScreenHeight;
4072 end
4073 else
4074 begin
4075 e_GetTextureSize(BackID, @bw, @bh);
4076 rf := Single(bw) / Single(bh);
4077 if (rf > RES_FACTOR) then bw := Round(Single(bh) * RES_FACTOR)
4078 else if (rf < RES_FACTOR) then bh := Round(Single(bw) / RES_FACTOR);
4079 s := Max(gScreenWidth / bw, gScreenHeight / bh);
4080 if (s < 1.0) then s := 1.0;
4081 gBackSize.X := Round(bw*s);
4082 gBackSize.Y := Round(bh*s);
4083 end;
4084 end;
4085 end;
4087 procedure g_Game_ChangeResolution(newWidth, newHeight: Word; nowFull, nowMax: Boolean);
4088 begin
4089 g_Window_SetSize(newWidth, newHeight, nowFull);
4090 end;
4092 procedure g_Game_AddPlayer(Team: Byte = TEAM_NONE);
4093 begin
4094 if ((not gGameOn) and (gState <> STATE_INTERCUSTOM))
4095 or (not (gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT])) then
4096 Exit;
4097 if gPlayer1 = nil then
4098 begin
4099 if g_Game_IsClient then
4100 begin
4101 if NetPlrUID1 > -1 then
4102 begin
4103 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE);
4104 gPlayer1 := g_Player_Get(NetPlrUID1);
4105 end;
4106 Exit;
4107 end;
4109 if not (Team in [TEAM_RED, TEAM_BLUE]) then
4110 Team := gPlayer1Settings.Team;
4112 // Ñîçäàíèå ïåðâîãî èãðîêà:
4113 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
4114 gPlayer1Settings.Color,
4115 Team, False));
4116 if gPlayer1 = nil then
4117 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]))
4118 else
4119 begin
4120 gPlayer1.Name := gPlayer1Settings.Name;
4121 g_Console_Add(Format(_lc[I_PLAYER_JOIN], [gPlayer1.Name]), True);
4122 if g_Game_IsServer and g_Game_IsNet then
4123 MH_SEND_PlayerCreate(gPlayer1.UID);
4124 gPlayer1.Respawn(False, True);
4126 if g_Game_IsNet and NetUseMaster then
4127 g_Net_Slist_Update;
4128 end;
4130 Exit;
4131 end;
4132 if gPlayer2 = nil then
4133 begin
4134 if g_Game_IsClient then
4135 begin
4136 if NetPlrUID2 > -1 then
4137 gPlayer2 := g_Player_Get(NetPlrUID2);
4138 Exit;
4139 end;
4141 if not (Team in [TEAM_RED, TEAM_BLUE]) then
4142 Team := gPlayer2Settings.Team;
4144 // Ñîçäàíèå âòîðîãî èãðîêà:
4145 gPlayer2 := g_Player_Get(g_Player_Create(gPlayer2Settings.Model,
4146 gPlayer2Settings.Color,
4147 Team, False));
4148 if gPlayer2 = nil then
4149 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [2]))
4150 else
4151 begin
4152 gPlayer2.Name := gPlayer2Settings.Name;
4153 g_Console_Add(Format(_lc[I_PLAYER_JOIN], [gPlayer2.Name]), True);
4154 if g_Game_IsServer and g_Game_IsNet then
4155 MH_SEND_PlayerCreate(gPlayer2.UID);
4156 gPlayer2.Respawn(False, True);
4158 if g_Game_IsNet and NetUseMaster then
4159 g_Net_Slist_Update;
4160 end;
4162 Exit;
4163 end;
4164 end;
4166 procedure g_Game_RemovePlayer();
4167 var
4168 Pl: TPlayer;
4169 begin
4170 if ((not gGameOn) and (gState <> STATE_INTERCUSTOM))
4171 or (not (gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT])) then
4172 Exit;
4173 Pl := gPlayer2;
4174 if Pl <> nil then
4175 begin
4176 if g_Game_IsServer then
4177 begin
4178 Pl.Lives := 0;
4179 Pl.Kill(K_SIMPLEKILL, 0, HIT_DISCON);
4180 g_Console_Add(Format(_lc[I_PLAYER_LEAVE], [Pl.Name]), True);
4181 g_Player_Remove(Pl.UID);
4183 if g_Game_IsNet and NetUseMaster then
4184 g_Net_Slist_Update;
4185 end else
4186 gPlayer2 := nil;
4187 Exit;
4188 end;
4189 Pl := gPlayer1;
4190 if Pl <> nil then
4191 begin
4192 if g_Game_IsServer then
4193 begin
4194 Pl.Lives := 0;
4195 Pl.Kill(K_SIMPLEKILL, 0, HIT_DISCON);
4196 g_Console_Add(Format(_lc[I_PLAYER_LEAVE], [Pl.Name]), True);
4197 g_Player_Remove(Pl.UID);
4199 if g_Game_IsNet and NetUseMaster then
4200 g_Net_Slist_Update;
4201 end else
4202 begin
4203 gPlayer1 := nil;
4204 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE);
4205 end;
4206 Exit;
4207 end;
4208 end;
4210 procedure g_Game_Spectate();
4211 begin
4212 g_Game_RemovePlayer();
4213 if gPlayer1 <> nil then
4214 g_Game_RemovePlayer();
4215 end;
4217 procedure g_Game_SpectateCenterView();
4218 begin
4219 gSpectX := Max(gMapInfo.Width div 2 - gScreenWidth div 2, 0);
4220 gSpectY := Max(gMapInfo.Height div 2 - gScreenHeight div 2, 0);
4221 end;
4223 procedure g_Game_StartSingle(Map: String; TwoPlayers: Boolean; nPlayers: Byte);
4224 var
4225 i, nPl: Integer;
4226 tmps: AnsiString;
4227 begin
4228 g_Game_Free();
4230 e_WriteLog('Starting singleplayer game...', TMsgType.Notify);
4232 g_Game_ClearLoading();
4234 // Íàñòðîéêè èãðû:
4235 FillByte(gGameSettings, SizeOf(TGameSettings), 0);
4236 gAimLine := False;
4237 gShowMap := False;
4238 gGameSettings.GameType := GT_SINGLE;
4239 gGameSettings.MaxLives := 0;
4240 gGameSettings.Options := gGameSettings.Options + GAME_OPTION_ALLOWEXIT;
4241 gGameSettings.Options := gGameSettings.Options + GAME_OPTION_MONSTERS;
4242 gGameSettings.Options := gGameSettings.Options + GAME_OPTION_BOTVSMONSTER;
4243 gSwitchGameMode := GM_SINGLE;
4245 g_Game_ExecuteEvent('ongamestart');
4247 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
4248 g_Game_SetupScreenSize();
4250 // Ñîçäàíèå ïåðâîãî èãðîêà:
4251 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
4252 gPlayer1Settings.Color,
4253 gPlayer1Settings.Team, False));
4254 if gPlayer1 = nil then
4255 begin
4256 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]));
4257 Exit;
4258 end;
4260 gPlayer1.Name := gPlayer1Settings.Name;
4261 nPl := 1;
4263 // Ñîçäàíèå âòîðîãî èãðîêà, åñëè åñòü:
4264 if TwoPlayers then
4265 begin
4266 gPlayer2 := g_Player_Get(g_Player_Create(gPlayer2Settings.Model,
4267 gPlayer2Settings.Color,
4268 gPlayer2Settings.Team, False));
4269 if gPlayer2 = nil then
4270 begin
4271 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [2]));
4272 Exit;
4273 end;
4275 gPlayer2.Name := gPlayer2Settings.Name;
4276 Inc(nPl);
4277 end;
4279 // Çàãðóçêà è çàïóñê êàðòû:
4280 if not g_Game_StartMap(MAP, True) then
4281 begin
4282 if (Pos(':\', Map) > 0) or (Pos(':/', Map) > 0) then tmps := Map else tmps := gGameSettings.WAD + ':\' + MAP;
4283 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [tmps]));
4284 Exit;
4285 end;
4287 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4288 g_Player_Init();
4290 // Ñîçäàåì áîòîâ:
4291 for i := nPl+1 to nPlayers do
4292 g_Player_Create(STD_PLAYER_MODEL, _RGB(0, 0, 0), 0, True);
4293 end;
4295 procedure g_Game_StartCustom(Map: String; GameMode: Byte;
4296 TimeLimit, GoalLimit: Word;
4297 MaxLives: Byte;
4298 Options: LongWord; nPlayers: Byte);
4299 var
4300 i, nPl: Integer;
4301 begin
4302 g_Game_Free();
4304 e_WriteLog('Starting custom game...', TMsgType.Notify);
4306 g_Game_ClearLoading();
4308 // Íàñòðîéêè èãðû:
4309 gGameSettings.GameType := GT_CUSTOM;
4310 gGameSettings.GameMode := GameMode;
4311 gSwitchGameMode := GameMode;
4312 gGameSettings.TimeLimit := TimeLimit;
4313 gGameSettings.GoalLimit := GoalLimit;
4314 gGameSettings.MaxLives := IfThen(GameMode = GM_CTF, 0, MaxLives);
4315 gGameSettings.Options := Options;
4317 gCoopTotalMonstersKilled := 0;
4318 gCoopTotalSecretsFound := 0;
4319 gCoopTotalMonsters := 0;
4320 gCoopTotalSecrets := 0;
4321 gAimLine := False;
4322 gShowMap := False;
4324 g_Game_ExecuteEvent('ongamestart');
4326 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
4327 g_Game_SetupScreenSize();
4329 // Ðåæèì íàáëþäàòåëÿ:
4330 if nPlayers = 0 then
4331 begin
4332 gPlayer1 := nil;
4333 gPlayer2 := nil;
4334 end;
4336 nPl := 0;
4337 if nPlayers >= 1 then
4338 begin
4339 // Ñîçäàíèå ïåðâîãî èãðîêà:
4340 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
4341 gPlayer1Settings.Color,
4342 gPlayer1Settings.Team, False));
4343 if gPlayer1 = nil then
4344 begin
4345 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]));
4346 Exit;
4347 end;
4349 gPlayer1.Name := gPlayer1Settings.Name;
4350 Inc(nPl);
4351 end;
4353 if nPlayers >= 2 then
4354 begin
4355 // Ñîçäàíèå âòîðîãî èãðîêà:
4356 gPlayer2 := g_Player_Get(g_Player_Create(gPlayer2Settings.Model,
4357 gPlayer2Settings.Color,
4358 gPlayer2Settings.Team, False));
4359 if gPlayer2 = nil then
4360 begin
4361 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [2]));
4362 Exit;
4363 end;
4365 gPlayer2.Name := gPlayer2Settings.Name;
4366 Inc(nPl);
4367 end;
4369 // Çàãðóçêà è çàïóñê êàðòû:
4370 if not g_Game_StartMap(Map, True) then
4371 begin
4372 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [Map]));
4373 Exit;
4374 end;
4376 // Íåò òî÷åê ïîÿâëåíèÿ:
4377 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1) +
4378 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2) +
4379 g_Map_GetPointCount(RESPAWNPOINT_DM) +
4380 g_Map_GetPointCount(RESPAWNPOINT_RED)+
4381 g_Map_GetPointCount(RESPAWNPOINT_BLUE)) < 1 then
4382 begin
4383 g_FatalError(_lc[I_GAME_ERROR_GET_SPAWN]);
4384 Exit;
4385 end;
4387 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4388 g_Player_Init();
4390 // Ñîçäàåì áîòîâ:
4391 for i := nPl+1 to nPlayers do
4392 g_Player_Create(STD_PLAYER_MODEL, _RGB(0, 0, 0), 0, True);
4393 end;
4395 procedure g_Game_StartServer(Map: String; GameMode: Byte;
4396 TimeLimit, GoalLimit: Word; MaxLives: Byte;
4397 Options: LongWord; nPlayers: Byte;
4398 IPAddr: LongWord; Port: Word);
4399 begin
4400 g_Game_Free();
4402 e_WriteLog('Starting net game (server)...', TMsgType.Notify);
4404 g_Game_ClearLoading();
4406 // Íàñòðîéêè èãðû:
4407 gGameSettings.GameType := GT_SERVER;
4408 gGameSettings.GameMode := GameMode;
4409 gSwitchGameMode := GameMode;
4410 gGameSettings.TimeLimit := TimeLimit;
4411 gGameSettings.GoalLimit := GoalLimit;
4412 gGameSettings.MaxLives := IfThen(GameMode = GM_CTF, 0, MaxLives);
4413 gGameSettings.Options := Options;
4415 gCoopTotalMonstersKilled := 0;
4416 gCoopTotalSecretsFound := 0;
4417 gCoopTotalMonsters := 0;
4418 gCoopTotalSecrets := 0;
4419 gAimLine := False;
4420 gShowMap := False;
4422 g_Game_ExecuteEvent('ongamestart');
4424 // Óñòàíîâêà ðàçìåðîâ îêíà èãðîêà
4425 g_Game_SetupScreenSize();
4427 // Ðåæèì íàáëþäàòåëÿ:
4428 if nPlayers = 0 then
4429 begin
4430 gPlayer1 := nil;
4431 gPlayer2 := nil;
4432 end;
4434 if nPlayers >= 1 then
4435 begin
4436 // Ñîçäàíèå ïåðâîãî èãðîêà:
4437 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
4438 gPlayer1Settings.Color,
4439 gPlayer1Settings.Team, False));
4440 if gPlayer1 = nil then
4441 begin
4442 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]));
4443 Exit;
4444 end;
4446 gPlayer1.Name := gPlayer1Settings.Name;
4447 end;
4449 if nPlayers >= 2 then
4450 begin
4451 // Ñîçäàíèå âòîðîãî èãðîêà:
4452 gPlayer2 := g_Player_Get(g_Player_Create(gPlayer2Settings.Model,
4453 gPlayer2Settings.Color,
4454 gPlayer2Settings.Team, False));
4455 if gPlayer2 = nil then
4456 begin
4457 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [2]));
4458 Exit;
4459 end;
4461 gPlayer2.Name := gPlayer2Settings.Name;
4462 end;
4464 g_Game_SetLoadingText(_lc[I_LOAD_HOST], 0, False);
4465 if NetForwardPorts then
4466 g_Game_SetLoadingText(_lc[I_LOAD_PORTS], 0, False);
4468 // Ñòàðòóåì ñåðâåð
4469 if not g_Net_Host(IPAddr, Port, NetMaxClients) then
4470 begin
4471 g_FatalError(_lc[I_NET_MSG] + _lc[I_NET_ERR_HOST]);
4472 Exit;
4473 end;
4475 g_Net_Slist_Set(NetSlistIP, NetSlistPort);
4477 // Çàãðóçêà è çàïóñê êàðòû:
4478 if not g_Game_StartMap(Map, True) then
4479 begin
4480 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [Map]));
4481 Exit;
4482 end;
4484 // Íåò òî÷åê ïîÿâëåíèÿ:
4485 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1) +
4486 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2) +
4487 g_Map_GetPointCount(RESPAWNPOINT_DM) +
4488 g_Map_GetPointCount(RESPAWNPOINT_RED)+
4489 g_Map_GetPointCount(RESPAWNPOINT_BLUE)) < 1 then
4490 begin
4491 g_FatalError(_lc[I_GAME_ERROR_GET_SPAWN]);
4492 Exit;
4493 end;
4495 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4496 g_Player_Init();
4498 NetState := NET_STATE_GAME;
4499 end;
4501 procedure g_Game_StartClient(Addr: String; Port: Word; PW: String);
4502 var
4503 Map: String;
4504 WadName: string;
4505 Ptr: Pointer;
4506 T: Cardinal;
4507 MID: Byte;
4508 State: Byte;
4509 OuterLoop: Boolean;
4510 newResPath: string;
4511 InMsg: TMsg;
4512 begin
4513 g_Game_Free();
4515 State := 0;
4516 e_WriteLog('Starting net game (client)...', TMsgType.Notify);
4517 e_WriteLog('NET: Trying to connect to ' + Addr + ':' + IntToStr(Port) + '...', TMsgType.Notify);
4519 g_Game_ClearLoading();
4521 // Íàñòðîéêè èãðû:
4522 gGameSettings.GameType := GT_CLIENT;
4524 gCoopTotalMonstersKilled := 0;
4525 gCoopTotalSecretsFound := 0;
4526 gCoopTotalMonsters := 0;
4527 gCoopTotalSecrets := 0;
4528 gAimLine := False;
4529 gShowMap := False;
4531 g_Game_ExecuteEvent('ongamestart');
4533 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
4534 g_Game_SetupScreenSize();
4536 NetState := NET_STATE_AUTH;
4538 g_Game_SetLoadingText(_lc[I_LOAD_CONNECT], 0, False);
4539 // Ñòàðòóåì êëèåíò
4540 if not g_Net_Connect(Addr, Port) then
4541 begin
4542 g_FatalError(_lc[I_NET_MSG] + _lc[I_NET_ERR_CONN]);
4543 NetState := NET_STATE_NONE;
4544 Exit;
4545 end;
4547 g_Game_SetLoadingText(_lc[I_LOAD_SEND_INFO], 0, False);
4548 MC_SEND_Info(PW);
4549 g_Game_SetLoadingText(_lc[I_LOAD_WAIT_INFO], 0, False);
4551 OuterLoop := True;
4552 while OuterLoop do
4553 begin
4554 while (enet_host_service(NetHost, @NetEvent, 0) > 0) do
4555 begin
4556 if (NetEvent.kind = ENET_EVENT_TYPE_RECEIVE) then
4557 begin
4558 Ptr := NetEvent.packet^.data;
4559 if not InMsg.Init(Ptr, NetEvent.packet^.dataLength, True) then
4560 continue;
4562 MID := InMsg.ReadByte();
4564 if (MID = NET_MSG_INFO) and (State = 0) then
4565 begin
4566 NetMyID := InMsg.ReadByte();
4567 NetPlrUID1 := InMsg.ReadWord();
4569 WadName := InMsg.ReadString();
4570 Map := InMsg.ReadString();
4572 gWADHash := InMsg.ReadMD5();
4574 gGameSettings.GameMode := InMsg.ReadByte();
4575 gSwitchGameMode := gGameSettings.GameMode;
4576 gGameSettings.GoalLimit := InMsg.ReadWord();
4577 gGameSettings.TimeLimit := InMsg.ReadWord();
4578 gGameSettings.MaxLives := InMsg.ReadByte();
4579 gGameSettings.Options := InMsg.ReadLongWord();
4580 T := InMsg.ReadLongWord();
4582 newResPath := g_Res_SearchSameWAD(MapsDir, WadName, gWADHash);
4583 if newResPath = '' then
4584 begin
4585 g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
4586 newResPath := g_Res_DownloadWAD(WadName);
4587 if newResPath = '' then
4588 begin
4589 g_FatalError(_lc[I_NET_ERR_HASH]);
4590 enet_packet_destroy(NetEvent.packet);
4591 NetState := NET_STATE_NONE;
4592 Exit;
4593 end;
4594 end;
4595 newResPath := ExtractRelativePath(MapsDir, newResPath);
4597 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
4598 gPlayer1Settings.Color,
4599 gPlayer1Settings.Team, False));
4601 if gPlayer1 = nil then
4602 begin
4603 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]));
4605 enet_packet_destroy(NetEvent.packet);
4606 NetState := NET_STATE_NONE;
4607 Exit;
4608 end;
4610 gPlayer1.Name := gPlayer1Settings.Name;
4611 gPlayer1.UID := NetPlrUID1;
4612 gPlayer1.Reset(True);
4614 if not g_Game_StartMap(newResPath + ':\' + Map, True) then
4615 begin
4616 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [WadName + ':\' + Map]));
4618 enet_packet_destroy(NetEvent.packet);
4619 NetState := NET_STATE_NONE;
4620 Exit;
4621 end;
4623 gTime := T;
4625 State := 1;
4626 OuterLoop := False;
4627 enet_packet_destroy(NetEvent.packet);
4628 break;
4629 end
4630 else
4631 enet_packet_destroy(NetEvent.packet);
4632 end
4633 else
4634 begin
4635 if (NetEvent.kind = ENET_EVENT_TYPE_DISCONNECT) then
4636 begin
4637 State := 0;
4638 if (NetEvent.data <= NET_DISC_MAX) then
4639 g_Console_Add(_lc[I_NET_MSG_ERROR] + _lc[I_NET_ERR_CONN] + ' ' +
4640 _lc[TStrings_Locale(Cardinal(I_NET_DISC_NONE) + NetEvent.data)], True);
4641 OuterLoop := False;
4642 Break;
4643 end;
4644 end;
4645 end;
4647 ProcessLoading(true);
4649 if e_KeyPressed(IK_SPACE) or e_KeyPressed(VK_ESCAPE) then
4650 begin
4651 State := 0;
4652 break;
4653 end;
4654 end;
4656 if State <> 1 then
4657 begin
4658 g_FatalError(_lc[I_NET_MSG] + _lc[I_NET_ERR_CONN]);
4659 NetState := NET_STATE_NONE;
4660 Exit;
4661 end;
4663 gLMSRespawn := LMS_RESPAWN_NONE;
4664 gLMSRespawnTime := 0;
4666 g_Player_Init();
4667 NetState := NET_STATE_GAME;
4668 MC_SEND_FullStateRequest;
4669 e_WriteLog('NET: Connection successful.', TMsgType.Notify);
4670 end;
4672 procedure g_Game_SaveOptions();
4673 begin
4674 g_Options_Write_Video(GameDir+'/'+CONFIG_FILENAME);
4675 end;
4677 procedure g_Game_ChangeMap(const MapPath: String);
4678 var
4679 Force: Boolean;
4680 begin
4681 g_Game_ClearLoading();
4683 Force := gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF];
4684 // Åñëè óðîâåíü çàâåðøèëñÿ ïî òðèããåðó Âûõîä, íå î÷èùàòü èíâåíòàðü
4685 if gExitByTrigger then
4686 begin
4687 Force := False;
4688 gExitByTrigger := False;
4689 end;
4690 if not g_Game_StartMap(MapPath, Force) then
4691 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [MapPath]));
4692 end;
4694 procedure g_Game_Restart();
4695 var
4696 Map: string;
4697 begin
4698 if g_Game_IsClient then
4699 Exit;
4700 map := g_ExtractFileName(gMapInfo.Map);
4702 MessageTime := 0;
4703 gGameOn := False;
4704 g_Game_ClearLoading();
4705 g_Game_StartMap(Map, True, gCurrentMapFileName);
4706 end;
4708 function g_Game_StartMap(Map: String; Force: Boolean = False; const oldMapPath: AnsiString=''): Boolean;
4709 var
4710 NewWAD, ResName: String;
4711 I: Integer;
4712 begin
4713 g_Map_Free((Map <> gCurrentMapFileName) and (oldMapPath <> gCurrentMapFileName));
4714 g_Player_RemoveAllCorpses();
4716 if (not g_Game_IsClient) and
4717 (gSwitchGameMode <> gGameSettings.GameMode) and
4718 (gGameSettings.GameMode <> GM_SINGLE) then
4719 begin
4720 if gSwitchGameMode = GM_CTF then
4721 gGameSettings.MaxLives := 0;
4722 gGameSettings.GameMode := gSwitchGameMode;
4723 Force := True;
4724 end else
4725 gSwitchGameMode := gGameSettings.GameMode;
4727 g_Player_ResetTeams();
4729 if isWadPath(Map) then
4730 begin
4731 NewWAD := g_ExtractWadName(Map);
4732 ResName := g_ExtractFileName(Map);
4733 if g_Game_IsServer then
4734 begin
4735 gWADHash := MD5File(MapsDir + NewWAD);
4736 g_Game_LoadWAD(NewWAD);
4737 end else
4738 // hash received in MC_RECV_GameEvent -> NET_EV_MAPSTART
4739 g_Game_ClientWAD(NewWAD, gWADHash);
4740 end else
4741 ResName := Map;
4743 Result := g_Map_Load(MapsDir + gGameSettings.WAD + ':\' + ResName);
4744 if Result then
4745 begin
4746 g_Player_ResetAll(Force or gLastMap, gGameSettings.GameType = GT_SINGLE);
4748 gState := STATE_NONE;
4749 g_ActiveWindow := nil;
4750 gGameOn := True;
4752 DisableCheats();
4753 ResetTimer();
4755 if gGameSettings.GameMode = GM_CTF then
4756 begin
4757 g_Map_ResetFlag(FLAG_RED);
4758 g_Map_ResetFlag(FLAG_BLUE);
4759 // CTF, à ôëàãîâ íåò:
4760 if not g_Map_HaveFlagPoints() then
4761 g_SimpleError(_lc[I_GAME_ERROR_CTF]);
4762 end;
4763 end
4764 else
4765 begin
4766 gState := STATE_MENU;
4767 gGameOn := False;
4768 end;
4770 gExit := 0;
4771 gPauseMain := false;
4772 gPauseHolmes := false;
4773 gTime := 0;
4774 NetTimeToUpdate := 1;
4775 NetTimeToReliable := 0;
4776 NetTimeToMaster := NetMasterRate;
4777 gLMSRespawn := LMS_RESPAWN_NONE;
4778 gLMSRespawnTime := 0;
4779 gMissionFailed := False;
4780 gNextMap := '';
4782 gCoopMonstersKilled := 0;
4783 gCoopSecretsFound := 0;
4785 gVoteInProgress := False;
4786 gVotePassed := False;
4787 gVoteCount := 0;
4788 gVoted := False;
4790 gStatsOff := False;
4792 if not gGameOn then Exit;
4794 g_Game_SpectateCenterView();
4796 if (gGameSettings.MaxLives > 0) and (gGameSettings.WarmupTime > 0) then
4797 begin
4798 gLMSRespawn := LMS_RESPAWN_WARMUP;
4799 gLMSRespawnTime := gTime + gGameSettings.WarmupTime*1000;
4800 gLMSSoftSpawn := True;
4801 if NetMode = NET_SERVER then
4802 MH_SEND_GameEvent(NET_EV_LMS_WARMUP, (gLMSRespawnTime - gTime) div 1000)
4803 else
4804 g_Console_Add(Format(_lc[I_MSG_WARMUP_START], [(gLMSRespawnTime - gTime) div 1000]), True);
4805 end;
4807 if NetMode = NET_SERVER then
4808 begin
4809 MH_SEND_GameEvent(NET_EV_MAPSTART, gGameSettings.GameMode, Map);
4811 // Ìàñòåðñåðâåð
4812 if NetUseMaster then
4813 begin
4814 if (NetMHost = nil) or (NetMPeer = nil) then
4815 if not g_Net_Slist_Connect then
4816 g_Console_Add(_lc[I_NET_MSG_ERROR] + _lc[I_NET_SLIST_ERROR]);
4818 g_Net_Slist_Update;
4819 end;
4821 if NetClients <> nil then
4822 for I := 0 to High(NetClients) do
4823 if NetClients[I].Used then
4824 begin
4825 NetClients[I].Voted := False;
4826 if NetClients[I].RequestedFullUpdate then
4827 begin
4828 MH_SEND_Everything((NetClients[I].State = NET_STATE_AUTH), I);
4829 NetClients[I].RequestedFullUpdate := False;
4830 end;
4831 end;
4833 g_Net_UnbanNonPermHosts();
4834 end;
4836 if gLastMap then
4837 begin
4838 gCoopTotalMonstersKilled := 0;
4839 gCoopTotalSecretsFound := 0;
4840 gCoopTotalMonsters := 0;
4841 gCoopTotalSecrets := 0;
4842 gLastMap := False;
4843 end;
4845 g_Game_ExecuteEvent('onmapstart');
4846 end;
4848 procedure SetFirstLevel();
4849 begin
4850 gNextMap := '';
4852 MapList := g_Map_GetMapsList(MapsDir + gGameSettings.WAD);
4853 if MapList = nil then
4854 Exit;
4856 SortSArray(MapList);
4857 gNextMap := MapList[Low(MapList)];
4859 MapList := nil;
4860 end;
4862 procedure g_Game_ExitLevel(const Map: AnsiString);
4863 begin
4864 gNextMap := Map;
4866 gCoopTotalMonstersKilled := gCoopTotalMonstersKilled + gCoopMonstersKilled;
4867 gCoopTotalSecretsFound := gCoopTotalSecretsFound + gCoopSecretsFound;
4868 gCoopTotalMonsters := gCoopTotalMonsters + gTotalMonsters;
4869 gCoopTotalSecrets := gCoopTotalSecrets + gSecretsCount;
4871 // Âûøëè â âûõîä â Îäèíî÷íîé èãðå:
4872 if gGameSettings.GameType = GT_SINGLE then
4873 gExit := EXIT_ENDLEVELSINGLE
4874 else // Âûøëè â âûõîä â Ñâîåé èãðå
4875 begin
4876 gExit := EXIT_ENDLEVELCUSTOM;
4877 if gGameSettings.GameMode = GM_COOP then
4878 g_Player_RememberAll;
4880 if not g_Map_Exist(MapsDir + gGameSettings.WAD + ':\' + gNextMap) then
4881 begin
4882 gLastMap := True;
4883 if gGameSettings.GameMode = GM_COOP then
4884 gStatsOff := True;
4886 gStatsPressed := True;
4887 gNextMap := 'MAP01';
4889 if not g_Map_Exist(MapsDir + gGameSettings.WAD + ':\' + gNextMap) then
4890 g_Game_NextLevel;
4892 if g_Game_IsNet then
4893 begin
4894 MH_SEND_GameStats();
4895 MH_SEND_CoopStats();
4896 end;
4897 end;
4898 end;
4899 end;
4901 procedure g_Game_RestartLevel();
4902 var
4903 Map: string;
4904 begin
4905 if gGameSettings.GameMode = GM_SINGLE then
4906 begin
4907 g_Game_Restart();
4908 Exit;
4909 end;
4910 gExit := EXIT_ENDLEVELCUSTOM;
4911 Map := g_ExtractFileName(gMapInfo.Map);
4912 gNextMap := Map;
4913 end;
4915 procedure g_Game_ClientWAD(NewWAD: String; WHash: TMD5Digest);
4916 var
4917 gWAD: String;
4918 begin
4919 if LowerCase(NewWAD) = LowerCase(gGameSettings.WAD) then
4920 Exit;
4921 if not g_Game_IsClient then
4922 Exit;
4923 gWAD := g_Res_SearchSameWAD(MapsDir, ExtractFileName(NewWAD), WHash);
4924 if gWAD = '' then
4925 begin
4926 g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
4927 gWAD := g_Res_DownloadWAD(ExtractFileName(NewWAD));
4928 if gWAD = '' then
4929 begin
4930 g_Game_Free();
4931 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_WAD], [ExtractFileName(NewWAD)]));
4932 Exit;
4933 end;
4934 end;
4935 NewWAD := ExtractRelativePath(MapsDir, gWAD);
4936 g_Game_LoadWAD(NewWAD);
4937 end;
4939 procedure g_Game_RestartRound(NoMapRestart: Boolean = False);
4940 var
4941 i, n, nb, nr: Integer;
4943 function monRespawn (mon: TMonster): Boolean;
4944 begin
4945 result := false; // don't stop
4946 if not mon.FNoRespawn then mon.Respawn();
4947 end;
4949 begin
4950 if not g_Game_IsServer then Exit;
4951 if gLMSRespawn = LMS_RESPAWN_NONE then Exit;
4952 gLMSRespawn := LMS_RESPAWN_NONE;
4953 gLMSRespawnTime := 0;
4954 MessageTime := 0;
4956 if (gGameSettings.GameMode = GM_COOP) and not NoMapRestart then
4957 begin
4958 gMissionFailed := True;
4959 g_Game_RestartLevel;
4960 Exit;
4961 end;
4963 n := 0; nb := 0; nr := 0;
4964 for i := Low(gPlayers) to High(gPlayers) do
4965 if (gPlayers[i] <> nil) and
4966 ((not gPlayers[i].FSpectator) or gPlayers[i].FWantsInGame or
4967 (gPlayers[i] is TBot)) then
4968 begin
4969 Inc(n);
4970 if gPlayers[i].Team = TEAM_RED then Inc(nr)
4971 else if gPlayers[i].Team = TEAM_BLUE then Inc(nb)
4972 end;
4974 if (n < 2) or ((gGameSettings.GameMode = GM_TDM) and ((nr = 0) or (nb = 0))) then
4975 begin
4976 // wait a second until the fuckers finally decide to join
4977 gLMSRespawn := LMS_RESPAWN_WARMUP;
4978 gLMSRespawnTime := gTime + 1000;
4979 gLMSSoftSpawn := NoMapRestart;
4980 Exit;
4981 end;
4983 g_Player_RemoveAllCorpses;
4984 g_Game_Message(_lc[I_MESSAGE_LMS_START], 144);
4985 if g_Game_IsNet then
4986 MH_SEND_GameEvent(NET_EV_LMS_START);
4988 for i := Low(gPlayers) to High(gPlayers) do
4989 begin
4990 if gPlayers[i] = nil then continue;
4991 if gPlayers[i] is TBot then gPlayers[i].FWantsInGame := True;
4992 // don't touch normal spectators
4993 if gPlayers[i].FSpectator and not gPlayers[i].FWantsInGame then
4994 begin
4995 gPlayers[i].FNoRespawn := True;
4996 gPlayers[i].Lives := 0;
4997 if g_Game_IsNet then
4998 MH_SEND_PlayerStats(gPlayers[I].UID);
4999 continue;
5000 end;
5001 gPlayers[i].FNoRespawn := False;
5002 gPlayers[i].Lives := gGameSettings.MaxLives;
5003 gPlayers[i].Respawn(False, True);
5004 if gGameSettings.GameMode = GM_COOP then
5005 begin
5006 gPlayers[i].Frags := 0;
5007 gPlayers[i].RecallState;
5008 end;
5009 if (gPlayer1 = nil) and (gLMSPID1 > 0) then
5010 gPlayer1 := g_Player_Get(gLMSPID1);
5011 if (gPlayer2 = nil) and (gLMSPID2 > 0) then
5012 gPlayer2 := g_Player_Get(gLMSPID2);
5013 end;
5015 g_Items_RestartRound();
5018 g_Mons_ForEach(monRespawn);
5020 gLMSSoftSpawn := False;
5021 end;
5023 function g_Game_GetFirstMap(WAD: String): String;
5024 begin
5025 Result := '';
5027 MapList := g_Map_GetMapsList(WAD);
5028 if MapList = nil then
5029 Exit;
5031 SortSArray(MapList);
5032 Result := MapList[Low(MapList)];
5034 if not g_Map_Exist(WAD + ':\' + Result) then
5035 Result := '';
5037 MapList := nil;
5038 end;
5040 function g_Game_GetNextMap(): String;
5041 var
5042 I: Integer;
5043 Map: string;
5044 begin
5045 Result := '';
5047 MapList := g_Map_GetMapsList(MapsDir + gGameSettings.WAD);
5048 if MapList = nil then
5049 Exit;
5051 Map := g_ExtractFileName(gMapInfo.Map);
5053 SortSArray(MapList);
5054 MapIndex := -255;
5055 for I := Low(MapList) to High(MapList) do
5056 if Map = MapList[I] then
5057 begin
5058 MapIndex := I;
5059 Break;
5060 end;
5062 if MapIndex <> -255 then
5063 begin
5064 if MapIndex = High(MapList) then
5065 Result := MapList[Low(MapList)]
5066 else
5067 Result := MapList[MapIndex + 1];
5069 if not g_Map_Exist(MapsDir + gGameSettings.WAD + ':\' + Result) then Result := Map;
5070 end;
5072 MapList := nil;
5073 end;
5075 procedure g_Game_NextLevel();
5076 begin
5077 if gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF, GM_COOP] then
5078 gExit := EXIT_ENDLEVELCUSTOM
5079 else
5080 begin
5081 gExit := EXIT_ENDLEVELSINGLE;
5082 Exit;
5083 end;
5085 if gNextMap <> '' then Exit;
5086 gNextMap := g_Game_GetNextMap();
5087 end;
5089 function g_Game_IsTestMap(): Boolean;
5090 begin
5091 result := StrEquCI1251(TEST_MAP_NAME, g_ExtractFileName(gMapInfo.Map));
5092 end;
5094 procedure g_Game_DeleteTestMap();
5095 var
5096 a: Integer;
5097 //MapName: AnsiString;
5098 WadName: string;
5100 WAD: TWADFile;
5101 MapList: SSArray;
5102 time: Integer;
5104 begin
5105 a := Pos('.wad:\', toLowerCase1251(gMapToDelete));
5106 if (a = 0) then a := Pos('.wad:/', toLowerCase1251(gMapToDelete));
5107 if (a = 0) then exit;
5109 // Âûäåëÿåì èìÿ wad-ôàéëà è èìÿ êàðòû
5110 WadName := Copy(gMapToDelete, 1, a+3);
5111 Delete(gMapToDelete, 1, a+5);
5112 gMapToDelete := UpperCase(gMapToDelete);
5113 //MapName := '';
5114 //CopyMemory(@MapName[0], @gMapToDelete[1], Min(16, Length(gMapToDelete)));
5117 // Èìÿ êàðòû íå ñòàíäàðòíîå òåñòîâîå:
5118 if MapName <> TEST_MAP_NAME then
5119 Exit;
5121 if not gTempDelete then
5122 begin
5123 time := g_GetFileTime(WadName);
5124 WAD := TWADFile.Create();
5126 // ×èòàåì Wad-ôàéë:
5127 if not WAD.ReadFile(WadName) then
5128 begin // Íåò òàêîãî WAD-ôàéëà
5129 WAD.Free();
5130 Exit;
5131 end;
5133 // Ñîñòàâëÿåì ñïèñîê êàðò è èùåì íóæíóþ:
5134 WAD.CreateImage();
5135 MapList := WAD.GetResourcesList('');
5137 if MapList <> nil then
5138 for a := 0 to High(MapList) do
5139 if MapList[a] = MapName then
5140 begin
5141 // Óäàëÿåì è ñîõðàíÿåì:
5142 WAD.RemoveResource('', MapName);
5143 WAD.SaveTo(WadName);
5144 Break;
5145 end;
5147 WAD.Free();
5148 g_SetFileTime(WadName, time);
5149 end else
5151 if gTempDelete then DeleteFile(WadName);
5152 end;
5154 procedure GameCVars(P: SSArray);
5155 var
5156 a, b: Integer;
5157 stat: TPlayerStatArray;
5158 cmd, s: string;
5159 config: TConfig;
5160 begin
5161 stat := nil;
5162 cmd := LowerCase(P[0]);
5163 if (cmd = 'g_friendlyfire') and not g_Game_IsClient then
5164 begin
5165 with gGameSettings do
5166 begin
5167 if (Length(P) > 1) and
5168 ((P[1] = '1') or (P[1] = '0')) then
5169 begin
5170 if (P[1][1] = '1') then
5171 Options := Options or GAME_OPTION_TEAMDAMAGE
5172 else
5173 Options := Options and (not GAME_OPTION_TEAMDAMAGE);
5174 end;
5176 if (LongBool(Options and GAME_OPTION_TEAMDAMAGE)) then
5177 g_Console_Add(_lc[I_MSG_FRIENDLY_FIRE_ON])
5178 else
5179 g_Console_Add(_lc[I_MSG_FRIENDLY_FIRE_OFF]);
5181 if g_Game_IsNet then MH_SEND_GameSettings;
5182 end;
5183 end
5184 else if (cmd = 'g_weaponstay') and not g_Game_IsClient then
5185 begin
5186 with gGameSettings do
5187 begin
5188 if (Length(P) > 1) and
5189 ((P[1] = '1') or (P[1] = '0')) then
5190 begin
5191 if (P[1][1] = '1') then
5192 Options := Options or GAME_OPTION_WEAPONSTAY
5193 else
5194 Options := Options and (not GAME_OPTION_WEAPONSTAY);
5195 end;
5197 if (LongBool(Options and GAME_OPTION_WEAPONSTAY)) then
5198 g_Console_Add(_lc[I_MSG_WEAPONSTAY_ON])
5199 else
5200 g_Console_Add(_lc[I_MSG_WEAPONSTAY_OFF]);
5202 if g_Game_IsNet then MH_SEND_GameSettings;
5203 end;
5204 end
5205 else if cmd = 'g_gamemode' then
5206 begin
5207 a := g_Game_TextToMode(P[1]);
5208 if a = GM_SINGLE then a := GM_COOP;
5209 if (Length(P) > 1) and (a <> GM_NONE) and (not g_Game_IsClient) then
5210 begin
5211 gSwitchGameMode := a;
5212 if (gGameOn and (gGameSettings.GameMode = GM_SINGLE)) or
5213 (gState = STATE_INTERSINGLE) then
5214 gSwitchGameMode := GM_SINGLE;
5215 if not gGameOn then
5216 gGameSettings.GameMode := gSwitchGameMode;
5217 end;
5218 if gSwitchGameMode = gGameSettings.GameMode then
5219 g_Console_Add(Format(_lc[I_MSG_GAMEMODE_CURRENT],
5220 [g_Game_ModeToText(gGameSettings.GameMode)]))
5221 else
5222 g_Console_Add(Format(_lc[I_MSG_GAMEMODE_CHANGE],
5223 [g_Game_ModeToText(gGameSettings.GameMode),
5224 g_Game_ModeToText(gSwitchGameMode)]));
5225 end
5226 else if (cmd = 'g_allow_exit') and not g_Game_IsClient then
5227 begin
5228 with gGameSettings do
5229 begin
5230 if (Length(P) > 1) and
5231 ((P[1] = '1') or (P[1] = '0')) then
5232 begin
5233 if (P[1][1] = '1') then
5234 Options := Options or GAME_OPTION_ALLOWEXIT
5235 else
5236 Options := Options and (not GAME_OPTION_ALLOWEXIT);
5237 end;
5239 if (LongBool(Options and GAME_OPTION_ALLOWEXIT)) then
5240 g_Console_Add(_lc[I_MSG_ALLOWEXIT_ON])
5241 else
5242 g_Console_Add(_lc[I_MSG_ALLOWEXIT_OFF]);
5243 g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
5245 if g_Game_IsNet then MH_SEND_GameSettings;
5246 end;
5247 end
5248 else if (cmd = 'g_allow_monsters') and not g_Game_IsClient then
5249 begin
5250 with gGameSettings do
5251 begin
5252 if (Length(P) > 1) and
5253 ((P[1] = '1') or (P[1] = '0')) then
5254 begin
5255 if (P[1][1] = '1') then
5256 Options := Options or GAME_OPTION_MONSTERS
5257 else
5258 Options := Options and (not GAME_OPTION_MONSTERS);
5259 end;
5261 if (LongBool(Options and GAME_OPTION_MONSTERS)) then
5262 g_Console_Add(_lc[I_MSG_ALLOWMON_ON])
5263 else
5264 g_Console_Add(_lc[I_MSG_ALLOWMON_OFF]);
5265 g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
5267 if g_Game_IsNet then MH_SEND_GameSettings;
5268 end;
5269 end
5270 else if (cmd = 'g_bot_vsplayers') and not g_Game_IsClient then
5271 begin
5272 with gGameSettings do
5273 begin
5274 if (Length(P) > 1) and
5275 ((P[1] = '1') or (P[1] = '0')) then
5276 begin
5277 if (P[1][1] = '1') then
5278 Options := Options or GAME_OPTION_BOTVSPLAYER
5279 else
5280 Options := Options and (not GAME_OPTION_BOTVSPLAYER);
5281 end;
5283 if (LongBool(Options and GAME_OPTION_BOTVSPLAYER)) then
5284 g_Console_Add(_lc[I_MSG_BOTSVSPLAYERS_ON])
5285 else
5286 g_Console_Add(_lc[I_MSG_BOTSVSPLAYERS_OFF]);
5288 if g_Game_IsNet then MH_SEND_GameSettings;
5289 end;
5290 end
5291 else if (cmd = 'g_bot_vsmonsters') and not g_Game_IsClient then
5292 begin
5293 with gGameSettings do
5294 begin
5295 if (Length(P) > 1) and
5296 ((P[1] = '1') or (P[1] = '0')) then
5297 begin
5298 if (P[1][1] = '1') then
5299 Options := Options or GAME_OPTION_BOTVSMONSTER
5300 else
5301 Options := Options and (not GAME_OPTION_BOTVSMONSTER);
5302 end;
5304 if (LongBool(Options and GAME_OPTION_BOTVSMONSTER)) then
5305 g_Console_Add(_lc[I_MSG_BOTSVSMONSTERS_ON])
5306 else
5307 g_Console_Add(_lc[I_MSG_BOTSVSMONSTERS_OFF]);
5309 if g_Game_IsNet then MH_SEND_GameSettings;
5310 end;
5311 end
5312 else if (cmd = 'g_warmuptime') and not g_Game_IsClient then
5313 begin
5314 if Length(P) > 1 then
5315 begin
5316 if StrToIntDef(P[1], gGameSettings.WarmupTime) = 0 then
5317 gGameSettings.WarmupTime := 30
5318 else
5319 gGameSettings.WarmupTime := StrToIntDef(P[1], gGameSettings.WarmupTime);
5320 end;
5322 g_Console_Add(Format(_lc[I_MSG_WARMUP],
5323 [gGameSettings.WarmupTime]));
5324 g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
5325 end
5326 else if cmd = 'net_interp' then
5327 begin
5328 if (Length(P) > 1) then
5329 NetInterpLevel := StrToIntDef(P[1], NetInterpLevel);
5331 g_Console_Add('net_interp = ' + IntToStr(NetInterpLevel));
5332 config := TConfig.CreateFile(GameDir+'/'+CONFIG_FILENAME);
5333 config.WriteInt('Client', 'InterpolationSteps', NetInterpLevel);
5334 config.SaveFile(GameDir+'/'+CONFIG_FILENAME);
5335 config.Free();
5336 end
5337 else if cmd = 'net_forceplayerupdate' then
5338 begin
5339 if (Length(P) > 1) and
5340 ((P[1] = '1') or (P[1] = '0')) then
5341 NetForcePlayerUpdate := (P[1][1] = '1');
5343 if NetForcePlayerUpdate then
5344 g_Console_Add('net_forceplayerupdate = 1')
5345 else
5346 g_Console_Add('net_forceplayerupdate = 0');
5347 config := TConfig.CreateFile(GameDir+'/'+CONFIG_FILENAME);
5348 config.WriteBool('Client', 'ForcePlayerUpdate', NetForcePlayerUpdate);
5349 config.SaveFile(GameDir+'/'+CONFIG_FILENAME);
5350 config.Free();
5351 end
5352 else if cmd = 'net_predictself' then
5353 begin
5354 if (Length(P) > 1) and
5355 ((P[1] = '1') or (P[1] = '0')) then
5356 NetPredictSelf := (P[1][1] = '1');
5358 if NetPredictSelf then
5359 g_Console_Add('net_predictself = 1')
5360 else
5361 g_Console_Add('net_predictself = 0');
5362 config := TConfig.CreateFile(GameDir+'/'+CONFIG_FILENAME);
5363 config.WriteBool('Client', 'PredictSelf', NetPredictSelf);
5364 config.SaveFile(GameDir+'/'+CONFIG_FILENAME);
5365 config.Free();
5366 end
5367 else if cmd = 'sv_name' then
5368 begin
5369 if (Length(P) > 1) and (Length(P[1]) > 0) then
5370 begin
5371 NetServerName := P[1];
5372 if Length(NetServerName) > 64 then
5373 SetLength(NetServerName, 64);
5374 if g_Game_IsServer and g_Game_IsNet and NetUseMaster then
5375 g_Net_Slist_Update;
5376 end;
5378 g_Console_Add(cmd + ' = "' + NetServerName + '"');
5379 end
5380 else if cmd = 'sv_passwd' then
5381 begin
5382 if (Length(P) > 1) and (Length(P[1]) > 0) then
5383 begin
5384 NetPassword := P[1];
5385 if Length(NetPassword) > 24 then
5386 SetLength(NetPassword, 24);
5387 if g_Game_IsServer and g_Game_IsNet and NetUseMaster then
5388 g_Net_Slist_Update;
5389 end;
5391 g_Console_Add(cmd + ' = "' + AnsiLowerCase(NetPassword) + '"');
5392 end
5393 else if cmd = 'sv_maxplrs' then
5394 begin
5395 if (Length(P) > 1) then
5396 begin
5397 NetMaxClients := Min(Max(StrToIntDef(P[1], NetMaxClients), 1), NET_MAXCLIENTS);
5398 if g_Game_IsServer and g_Game_IsNet then
5399 begin
5400 b := 0;
5401 for a := 0 to High(NetClients) do
5402 if NetClients[a].Used then
5403 begin
5404 Inc(b);
5405 if b > NetMaxClients then
5406 begin
5407 s := g_Player_Get(NetClients[a].Player).Name;
5408 enet_peer_disconnect(NetClients[a].Peer, NET_DISC_FULL);
5409 g_Console_Add(Format(_lc[I_PLAYER_KICK], [s]));
5410 MH_SEND_GameEvent(NET_EV_PLAYER_KICK, 0, s);
5411 end;
5412 end;
5413 if NetUseMaster then
5414 g_Net_Slist_Update;
5415 end;
5416 end;
5418 g_Console_Add(cmd + ' = ' + IntToStr(NetMaxClients));
5419 end
5420 else if cmd = 'sv_public' then
5421 begin
5422 if (Length(P) > 1) then
5423 begin
5424 NetUseMaster := StrToIntDef(P[1], Byte(NetUseMaster)) > 0;
5425 if g_Game_IsServer and g_Game_IsNet then
5426 if NetUseMaster then
5427 begin
5428 if NetMPeer = nil then
5429 if not g_Net_Slist_Connect() then
5430 g_Console_Add(_lc[I_NET_MSG_ERROR] + _lc[I_NET_SLIST_ERROR]);
5431 g_Net_Slist_Update();
5432 end
5433 else
5434 if NetMPeer <> nil then
5435 g_Net_Slist_Disconnect();
5436 end;
5438 g_Console_Add(cmd + ' = ' + IntToStr(Byte(NetUseMaster)));
5439 end
5440 else if cmd = 'sv_intertime' then
5441 begin
5442 if (Length(P) > 1) then
5443 gDefInterTime := Min(Max(StrToIntDef(P[1], gDefInterTime), -1), 120);
5445 g_Console_Add(cmd + ' = ' + IntToStr(gDefInterTime));
5446 end
5447 else if cmd = 'p1_name' then
5448 begin
5449 if (Length(P) > 1) and gGameOn then
5450 begin
5451 if g_Game_IsClient then
5452 begin
5453 gPlayer1Settings.Name := b_Text_Unformat(P[1]);
5454 MC_SEND_PlayerSettings;
5455 end
5456 else
5457 if gPlayer1 <> nil then
5458 begin
5459 gPlayer1.Name := b_Text_Unformat(P[1]);
5460 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer1.UID);
5461 end
5462 else
5463 gPlayer1Settings.Name := b_Text_Unformat(P[1]);
5464 end;
5465 end
5466 else if cmd = 'p2_name' then
5467 begin
5468 if (Length(P) > 1) and gGameOn then
5469 begin
5470 if g_Game_IsClient then
5471 begin
5472 gPlayer2Settings.Name := b_Text_Unformat(P[1]);
5473 MC_SEND_PlayerSettings;
5474 end
5475 else
5476 if gPlayer2 <> nil then
5477 begin
5478 gPlayer2.Name := b_Text_Unformat(P[1]);
5479 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer2.UID);
5480 end
5481 else
5482 gPlayer2Settings.Name := b_Text_Unformat(P[1]);
5483 end;
5484 end
5485 else if cmd = 'p1_color' then
5486 begin
5487 if Length(P) > 3 then
5488 if g_Game_IsClient then
5489 begin
5490 gPlayer1Settings.Color := _RGB(EnsureRange(StrToIntDef(P[1], 0), 0, 255),
5491 EnsureRange(StrToIntDef(P[2], 0), 0, 255),
5492 EnsureRange(StrToIntDef(P[3], 0), 0, 255));
5493 MC_SEND_PlayerSettings;
5494 end
5495 else
5496 if gPlayer1 <> nil then
5497 begin
5498 gPlayer1.Model.SetColor(EnsureRange(StrToIntDef(P[1], 0), 0, 255),
5499 EnsureRange(StrToIntDef(P[2], 0), 0, 255),
5500 EnsureRange(StrToIntDef(P[3], 0), 0, 255));
5501 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer1.UID);
5502 end
5503 else
5504 gPlayer1Settings.Color := _RGB(EnsureRange(StrToIntDef(P[1], 0), 0, 255),
5505 EnsureRange(StrToIntDef(P[2], 0), 0, 255),
5506 EnsureRange(StrToIntDef(P[3], 0), 0, 255));
5507 end
5508 else if (cmd = 'p2_color') and not g_Game_IsNet then
5509 begin
5510 if Length(P) > 3 then
5511 if g_Game_IsClient then
5512 begin
5513 gPlayer2Settings.Color := _RGB(EnsureRange(StrToIntDef(P[1], 0), 0, 255),
5514 EnsureRange(StrToIntDef(P[2], 0), 0, 255),
5515 EnsureRange(StrToIntDef(P[3], 0), 0, 255));
5516 MC_SEND_PlayerSettings;
5517 end
5518 else
5519 if gPlayer2 <> nil then
5520 begin
5521 gPlayer2.Model.SetColor(EnsureRange(StrToIntDef(P[1], 0), 0, 255),
5522 EnsureRange(StrToIntDef(P[2], 0), 0, 255),
5523 EnsureRange(StrToIntDef(P[3], 0), 0, 255));
5524 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer2.UID);
5525 end
5526 else
5527 gPlayer2Settings.Color := _RGB(EnsureRange(StrToIntDef(P[1], 0), 0, 255),
5528 EnsureRange(StrToIntDef(P[2], 0), 0, 255),
5529 EnsureRange(StrToIntDef(P[3], 0), 0, 255));
5530 end
5531 else if gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT] then
5532 begin
5533 if cmd = 'r_showtime' then
5534 begin
5535 if (Length(P) > 1) and
5536 ((P[1] = '1') or (P[1] = '0')) then
5537 gShowTime := (P[1][1] = '1');
5539 if gShowTime then
5540 g_Console_Add(_lc[I_MSG_TIME_ON])
5541 else
5542 g_Console_Add(_lc[I_MSG_TIME_OFF]);
5543 end
5544 else if cmd = 'r_showscore' then
5545 begin
5546 if (Length(P) > 1) and
5547 ((P[1] = '1') or (P[1] = '0')) then
5548 gShowGoals := (P[1][1] = '1');
5550 if gShowGoals then
5551 g_Console_Add(_lc[I_MSG_SCORE_ON])
5552 else
5553 g_Console_Add(_lc[I_MSG_SCORE_OFF]);
5554 end
5555 else if cmd = 'r_showstat' then
5556 begin
5557 if (Length(P) > 1) and
5558 ((P[1] = '1') or (P[1] = '0')) then
5559 gShowStat := (P[1][1] = '1');
5561 if gShowStat then
5562 g_Console_Add(_lc[I_MSG_STATS_ON])
5563 else
5564 g_Console_Add(_lc[I_MSG_STATS_OFF]);
5565 end
5566 else if cmd = 'r_showkillmsg' then
5567 begin
5568 if (Length(P) > 1) and
5569 ((P[1] = '1') or (P[1] = '0')) then
5570 gShowKillMsg := (P[1][1] = '1');
5572 if gShowKillMsg then
5573 g_Console_Add(_lc[I_MSG_KILL_MSGS_ON])
5574 else
5575 g_Console_Add(_lc[I_MSG_KILL_MSGS_OFF]);
5576 end
5577 else if cmd = 'r_showlives' then
5578 begin
5579 if (Length(P) > 1) and
5580 ((P[1] = '1') or (P[1] = '0')) then
5581 gShowLives := (P[1][1] = '1');
5583 if gShowLives then
5584 g_Console_Add(_lc[I_MSG_LIVES_ON])
5585 else
5586 g_Console_Add(_lc[I_MSG_LIVES_OFF]);
5587 end
5588 else if cmd = 'r_showspect' then
5589 begin
5590 if (Length(P) > 1) and
5591 ((P[1] = '1') or (P[1] = '0')) then
5592 gSpectHUD := (P[1][1] = '1');
5594 if gSpectHUD then
5595 g_Console_Add(_lc[I_MSG_SPECT_HUD_ON])
5596 else
5597 g_Console_Add(_lc[I_MSG_SPECT_HUD_OFF]);
5598 end
5599 else if cmd = 'r_showping' then
5600 begin
5601 if (Length(P) > 1) and
5602 ((P[1] = '1') or (P[1] = '0')) then
5603 gShowPing := (P[1][1] = '1');
5605 if gShowPing then
5606 g_Console_Add(_lc[I_MSG_PING_ON])
5607 else
5608 g_Console_Add(_lc[I_MSG_PING_OFF]);
5609 end
5610 else if (cmd = 'g_scorelimit') and not g_Game_IsClient then
5611 begin
5612 if Length(P) > 1 then
5613 begin
5614 if StrToIntDef(P[1], gGameSettings.GoalLimit) = 0 then
5615 gGameSettings.GoalLimit := 0
5616 else
5617 begin
5618 b := 0;
5620 if gGameSettings.GameMode = GM_DM then
5621 begin // DM
5622 stat := g_Player_GetStats();
5623 if stat <> nil then
5624 for a := 0 to High(stat) do
5625 if stat[a].Frags > b then
5626 b := stat[a].Frags;
5627 end
5628 else // TDM/CTF
5629 b := Max(gTeamStat[TEAM_RED].Goals, gTeamStat[TEAM_BLUE].Goals);
5631 gGameSettings.GoalLimit := Max(StrToIntDef(P[1], gGameSettings.GoalLimit), b);
5632 end;
5634 if g_Game_IsNet then MH_SEND_GameSettings;
5635 end;
5637 g_Console_Add(Format(_lc[I_MSG_SCORE_LIMIT], [gGameSettings.GoalLimit]));
5638 end
5639 else if (cmd = 'g_timelimit') and not g_Game_IsClient then
5640 begin
5641 if (Length(P) > 1) and (StrToIntDef(P[1], -1) >= 0) then
5642 gGameSettings.TimeLimit := StrToIntDef(P[1], -1);
5644 g_Console_Add(Format(_lc[I_MSG_TIME_LIMIT],
5645 [gGameSettings.TimeLimit div 3600,
5646 (gGameSettings.TimeLimit div 60) mod 60,
5647 gGameSettings.TimeLimit mod 60]));
5648 if g_Game_IsNet then MH_SEND_GameSettings;
5649 end
5650 else if (cmd = 'g_maxlives') and not g_Game_IsClient then
5651 begin
5652 if Length(P) > 1 then
5653 begin
5654 if StrToIntDef(P[1], gGameSettings.MaxLives) = 0 then
5655 gGameSettings.MaxLives := 0
5656 else
5657 begin
5658 b := 0;
5659 stat := g_Player_GetStats();
5660 if stat <> nil then
5661 for a := 0 to High(stat) do
5662 if stat[a].Lives > b then
5663 b := stat[a].Lives;
5664 gGameSettings.MaxLives :=
5665 Max(StrToIntDef(P[1], gGameSettings.MaxLives), b);
5666 end;
5667 end;
5669 g_Console_Add(Format(_lc[I_MSG_LIVES],
5670 [gGameSettings.MaxLives]));
5671 if g_Game_IsNet then MH_SEND_GameSettings;
5672 end;
5673 end;
5674 end;
5676 procedure PrintHeapStats();
5677 var
5678 hs: TFPCHeapStatus;
5679 begin
5680 hs := GetFPCHeapStatus();
5681 e_LogWriteLn ('v===== heap status =====v');
5682 e_LogWriteFln('max heap size = %d k', [hs.MaxHeapSize div 1024]);
5683 e_LogWriteFln('max heap used = %d k', [hs.MaxHeapUsed div 1024]);
5684 e_LogWriteFln('cur heap size = %d k', [hs.CurrHeapSize div 1024]);
5685 e_LogWriteFln('cur heap used = %d k', [hs.CurrHeapUsed div 1024]);
5686 e_LogWriteFln('cur heap free = %d k', [hs.CurrHeapFree div 1024]);
5687 e_LogWriteLn ('^=======================^');
5688 end;
5690 procedure DebugCommands(P: SSArray);
5691 var
5692 a, b: Integer;
5693 cmd: string;
5694 //pt: TDFPoint;
5695 mon: TMonster;
5696 begin
5697 // Êîìàíäû îòëàäî÷íîãî ðåæèìà:
5698 if {gDebugMode}conIsCheatsEnabled then
5699 begin
5700 cmd := LowerCase(P[0]);
5701 if cmd = 'd_window' then
5702 begin
5703 g_Console_Add(Format('gWinPosX = %d, gWinPosY %d', [gWinPosX, gWinPosY]));
5704 g_Console_Add(Format('gWinRealPosX = %d, gWinRealPosY %d', [gWinRealPosX, gWinRealPosY]));
5705 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth, gScreenHeight]));
5706 g_Console_Add(Format('gWinSizeX = %d, gWinSizeY = %d', [gWinSizeX, gWinSizeY]));
5707 g_Console_Add(Format('Frame X = %d, Y = %d, Caption Y = %d', [gWinFrameX, gWinFrameY, gWinCaption]));
5708 end
5709 else if cmd = 'd_sounds' then
5710 begin
5711 if (Length(P) > 1) and
5712 ((P[1] = '1') or (P[1] = '0')) then
5713 g_Debug_Sounds := (P[1][1] = '1');
5715 g_Console_Add(Format('d_sounds is %d', [Byte(g_Debug_Sounds)]));
5716 end
5717 else if cmd = 'd_frames' then
5718 begin
5719 if (Length(P) > 1) and
5720 ((P[1] = '1') or (P[1] = '0')) then
5721 g_Debug_Frames := (P[1][1] = '1');
5723 g_Console_Add(Format('d_frames is %d', [Byte(g_Debug_Frames)]));
5724 end
5725 else if cmd = 'd_winmsg' then
5726 begin
5727 if (Length(P) > 1) and
5728 ((P[1] = '1') or (P[1] = '0')) then
5729 g_Debug_WinMsgs := (P[1][1] = '1');
5731 g_Console_Add(Format('d_winmsg is %d', [Byte(g_Debug_WinMsgs)]));
5732 end
5733 else if (cmd = 'd_monoff') and not g_Game_IsNet then
5734 begin
5735 if (Length(P) > 1) and
5736 ((P[1] = '1') or (P[1] = '0')) then
5737 g_Debug_MonsterOff := (P[1][1] = '1');
5739 g_Console_Add(Format('d_monoff is %d', [Byte(g_debug_MonsterOff)]));
5740 end
5741 else if (cmd = 'd_botoff') and not g_Game_IsNet then
5742 begin
5743 if Length(P) > 1 then
5744 case P[1][1] of
5745 '0': g_debug_BotAIOff := 0;
5746 '1': g_debug_BotAIOff := 1;
5747 '2': g_debug_BotAIOff := 2;
5748 '3': g_debug_BotAIOff := 3;
5749 end;
5751 g_Console_Add(Format('d_botoff is %d', [g_debug_BotAIOff]));
5752 end
5753 else if cmd = 'd_monster' then
5754 begin
5755 if gGameOn and (gPlayer1 <> nil) and (gPlayer1.alive) and (not g_Game_IsNet) then
5756 if Length(P) < 2 then
5757 begin
5758 g_Console_Add(cmd + ' [ID | Name] [behaviour]');
5759 g_Console_Add('ID | Name');
5760 for b := MONSTER_DEMON to MONSTER_MAN do
5761 g_Console_Add(Format('%2d | %s', [b, g_Mons_NameByTypeId(b)]));
5762 conwriteln('behav. num'#10'normal 0'#10'killer 1'#10'maniac 2'#10'insane 3'#10'cannibal 4'#10'good 5');
5763 end else
5764 begin
5765 a := StrToIntDef(P[1], 0);
5766 if (a < MONSTER_DEMON) or (a > MONSTER_MAN) then
5767 a := g_Mons_TypeIdByName(P[1]);
5769 if (a < MONSTER_DEMON) or (a > MONSTER_MAN) then
5770 g_Console_Add(Format(_lc[I_MSG_NO_MONSTER], [P[1]]))
5771 else
5772 begin
5773 with gPlayer1.Obj do
5774 begin
5775 mon := g_Monsters_Create(a,
5776 X + Rect.X + (Rect.Width div 2),
5777 Y + Rect.Y + Rect.Height,
5778 gPlayer1.Direction, True);
5779 end;
5780 if (Length(P) > 2) and (mon <> nil) then
5781 begin
5782 if (CompareText(P[2], 'normal') = 0) then mon.MonsterBehaviour := BH_NORMAL
5783 else if (CompareText(P[2], 'killer') = 0) then mon.MonsterBehaviour := BH_KILLER
5784 else if (CompareText(P[2], 'maniac') = 0) then mon.MonsterBehaviour := BH_MANIAC
5785 else if (CompareText(P[2], 'insane') = 0) then mon.MonsterBehaviour := BH_INSANE
5786 else if (CompareText(P[2], 'cannibal') = 0) then mon.MonsterBehaviour := BH_CANNIBAL
5787 else if (CompareText(P[2], 'good') = 0) then mon.MonsterBehaviour := BH_GOOD
5788 else if (CompareText(P[2], 'friend') = 0) then mon.MonsterBehaviour := BH_GOOD
5789 else if (CompareText(P[2], 'friendly') = 0) then mon.MonsterBehaviour := BH_GOOD
5790 else mon.MonsterBehaviour := Min(Max(StrToIntDef(P[2], BH_NORMAL), BH_NORMAL), BH_GOOD);
5791 end;
5792 end;
5793 end;
5794 end
5795 else if (cmd = 'd_health') then
5796 begin
5797 if (Length(P) > 1) and
5798 ((P[1] = '1') or (P[1] = '0')) then
5799 g_debug_HealthBar := (P[1][1] = '1');
5801 g_Console_Add(Format('d_health is %d', [Byte(g_debug_HealthBar)]));
5802 end
5803 else if (cmd = 'd_player') then
5804 begin
5805 if (Length(P) > 1) and
5806 ((P[1] = '1') or (P[1] = '0')) then
5807 g_debug_Player := (P[1][1] = '1');
5809 g_Console_Add(Format(cmd + ' is %d', [Byte(g_Debug_Player)]));
5810 end
5811 else if (cmd = 'd_mem') then
5812 begin
5813 PrintHeapStats();
5814 end;
5815 end
5816 else
5817 g_Console_Add(_lc[I_MSG_NOT_DEBUG]);
5818 end;
5821 procedure GameCheats(P: SSArray);
5822 var
5823 cmd: string;
5824 f, a: Integer;
5825 plr: TPlayer;
5826 begin
5827 if (not gGameOn) or (not conIsCheatsEnabled) then
5828 begin
5829 g_Console_Add('not available');
5830 exit;
5831 end;
5832 plr := gPlayer1;
5833 if plr = nil then
5834 begin
5835 g_Console_Add('where is the player?!');
5836 exit;
5837 end;
5838 cmd := LowerCase(P[0]);
5839 // god
5840 if cmd = 'god' then
5841 begin
5842 plr.GodMode := not plr.GodMode;
5843 if plr.GodMode then g_Console_Add('player is godlike now') else g_Console_Add('player is mortal now');
5844 exit;
5845 end;
5846 // give <health|exit|weapons|air|suit|jetpack|berserk|all>
5847 if cmd = 'give' then
5848 begin
5849 if length(P) < 2 then begin g_Console_Add('give what?!'); exit; end;
5850 for f := 1 to High(P) do
5851 begin
5852 cmd := LowerCase(P[f]);
5853 if cmd = 'health' then begin plr.RestoreHealthArmor(); g_Console_Add('player feels himself better'); continue; end;
5854 if (cmd = 'all') {or (cmd = 'weapons')} then begin plr.AllRulez(False); g_Console_Add('player got the gifts'); continue; end;
5855 if cmd = 'exit' then
5856 begin
5857 if gTriggers <> nil then
5858 begin
5859 for a := 0 to High(gTriggers) do
5860 begin
5861 if gTriggers[a].TriggerType = TRIGGER_EXIT then
5862 begin
5863 g_Console_Add('player left the map');
5864 gExitByTrigger := True;
5865 //g_Game_ExitLevel(gTriggers[a].Data.MapName);
5866 g_Game_ExitLevel(gTriggers[a].tgcMap);
5867 break;
5868 end;
5869 end;
5870 end;
5871 continue;
5872 end;
5874 if cmd = 'air' then begin plr.GiveItem(ITEM_OXYGEN); g_Console_Add('player got some air'); continue; end;
5875 if cmd = 'jetpack' then begin plr.GiveItem(ITEM_JETPACK); g_Console_Add('player got a jetpack'); continue; end;
5876 if cmd = 'suit' then begin plr.GiveItem(ITEM_SUIT); g_Console_Add('player got an envirosuit'); continue; end;
5877 if cmd = 'berserk' then begin plr.GiveItem(ITEM_MEDKIT_BLACK); g_Console_Add('player got a berserk pack'); continue; end;
5878 if cmd = 'backpack' then begin plr.GiveItem(ITEM_AMMO_BACKPACK); g_Console_Add('player got a backpack'); continue; end;
5880 if cmd = 'helmet' then begin plr.GiveItem(ITEM_HELMET); g_Console_Add('player got a helmet'); continue; end;
5881 if cmd = 'bottle' then begin plr.GiveItem(ITEM_BOTTLE); g_Console_Add('player got a bottle of health'); continue; end;
5883 if cmd = 'stimpack' then begin plr.GiveItem(ITEM_MEDKIT_SMALL); g_Console_Add('player got a stimpack'); continue; end;
5884 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;
5886 if cmd = 'greenarmor' then begin plr.GiveItem(ITEM_ARMOR_GREEN); g_Console_Add('player got a security armor'); continue; end;
5887 if cmd = 'bluearmor' then begin plr.GiveItem(ITEM_ARMOR_BLUE); g_Console_Add('player got a combat armor'); continue; end;
5889 if (cmd = 'megasphere') or (cmd = 'mega') then begin plr.GiveItem(ITEM_SPHERE_BLUE); g_Console_Add('player got a megasphere'); continue; end;
5890 if (cmd = 'soulsphere') or (cmd = 'soul')then begin plr.GiveItem(ITEM_SPHERE_WHITE); g_Console_Add('player got a soul sphere'); continue; end;
5892 if (cmd = 'invul') or (cmd = 'invulnerability') then begin plr.GiveItem(ITEM_INVUL); g_Console_Add('player got invulnerability'); continue; end;
5893 if (cmd = 'invis') or (cmd = 'invisibility') then begin plr.GiveItem(ITEM_INVIS); g_Console_Add('player got invisibility'); continue; end;
5895 if cmd = 'redkey' then begin plr.GiveItem(ITEM_KEY_RED); g_Console_Add('player got the red key'); continue; end;
5896 if cmd = 'greenkey' then begin plr.GiveItem(ITEM_KEY_GREEN); g_Console_Add('player got the green key'); continue; end;
5897 if cmd = 'bluekey' then begin plr.GiveItem(ITEM_KEY_BLUE); g_Console_Add('player got the blue key'); continue; end;
5899 if (cmd = 'shotgun') or (cmd = 'sg') then begin plr.GiveItem(ITEM_WEAPON_SHOTGUN1); g_Console_Add('player got a shotgun'); continue; end;
5900 if (cmd = 'supershotgun') or (cmd = 'ssg') then begin plr.GiveItem(ITEM_WEAPON_SHOTGUN2); g_Console_Add('player got a supershotgun'); continue; end;
5901 if cmd = 'chaingun' then begin plr.GiveItem(ITEM_WEAPON_CHAINGUN); g_Console_Add('player got a chaingun'); continue; end;
5902 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;
5903 if cmd = 'plasmagun' then begin plr.GiveItem(ITEM_WEAPON_PLASMA); g_Console_Add('player got a plasma gun'); continue; end;
5904 if cmd = 'bfg' then begin plr.GiveItem(ITEM_WEAPON_BFG); g_Console_Add('player got a BFG-9000'); continue; end;
5906 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;
5907 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;
5908 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;
5909 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;
5910 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;
5911 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;
5913 if cmd = 'superchaingun' then begin plr.GiveItem(ITEM_WEAPON_SUPERPULEMET); g_Console_Add('player got a superchaingun'); continue; end;
5914 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;
5916 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;
5917 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;
5919 if cmd = 'chainsaw' then begin plr.GiveItem(ITEM_WEAPON_SAW); g_Console_Add('player got a chainsaw'); continue; end;
5921 if cmd = 'ammo' then
5922 begin
5923 plr.GiveItem(ITEM_AMMO_SHELLS_BOX);
5924 plr.GiveItem(ITEM_AMMO_BULLETS_BOX);
5925 plr.GiveItem(ITEM_AMMO_CELL_BIG);
5926 plr.GiveItem(ITEM_AMMO_ROCKET_BOX);
5927 plr.GiveItem(ITEM_AMMO_FUELCAN);
5928 g_Console_Add('player got some ammo');
5929 continue;
5930 end;
5932 if cmd = 'clip' then begin plr.GiveItem(ITEM_AMMO_BULLETS); g_Console_Add('player got some bullets'); continue; end;
5933 if cmd = 'bullets' then begin plr.GiveItem(ITEM_AMMO_BULLETS_BOX); g_Console_Add('player got a box of bullets'); continue; end;
5935 if cmd = 'shells' then begin plr.GiveItem(ITEM_AMMO_SHELLS); g_Console_Add('player got some shells'); continue; end;
5936 if cmd = 'shellbox' then begin plr.GiveItem(ITEM_AMMO_SHELLS_BOX); g_Console_Add('player got a box of shells'); continue; end;
5938 if cmd = 'cells' then begin plr.GiveItem(ITEM_AMMO_CELL); g_Console_Add('player got some cells'); continue; end;
5939 if cmd = 'battery' then begin plr.GiveItem(ITEM_AMMO_CELL_BIG); g_Console_Add('player got cell battery'); continue; end;
5941 if cmd = 'rocket' then begin plr.GiveItem(ITEM_AMMO_ROCKET); g_Console_Add('player got a rocket'); continue; end;
5942 if cmd = 'rocketbox' then begin plr.GiveItem(ITEM_AMMO_ROCKET_BOX); g_Console_Add('player got some rockets'); continue; end;
5944 if (cmd = 'fuel') or (cmd = 'fuelcan') then begin plr.GiveItem(ITEM_AMMO_FUELCAN); g_Console_Add('player got fuel canister'); continue; end;
5946 if cmd = 'weapons' then
5947 begin
5948 plr.GiveItem(ITEM_WEAPON_SHOTGUN1);
5949 plr.GiveItem(ITEM_WEAPON_SHOTGUN2);
5950 plr.GiveItem(ITEM_WEAPON_CHAINGUN);
5951 plr.GiveItem(ITEM_WEAPON_ROCKETLAUNCHER);
5952 plr.GiveItem(ITEM_WEAPON_PLASMA);
5953 plr.GiveItem(ITEM_WEAPON_BFG);
5954 g_Console_Add('player got weapons');
5955 continue;
5956 end;
5958 if cmd = 'keys' then
5959 begin
5960 plr.GiveItem(ITEM_KEY_RED);
5961 plr.GiveItem(ITEM_KEY_GREEN);
5962 plr.GiveItem(ITEM_KEY_BLUE);
5963 g_Console_Add('player got all keys');
5964 continue;
5965 end;
5967 g_Console_Add('i don''t know how to give '''+cmd+'''!');
5968 end;
5969 exit;
5970 end;
5971 // open
5972 if cmd = 'open' then
5973 begin
5974 g_Console_Add('player activated sesame');
5975 g_Triggers_OpenAll();
5976 exit;
5977 end;
5978 // fly
5979 if cmd = 'fly' then
5980 begin
5981 gFly := not gFly;
5982 if gFly then g_Console_Add('player feels himself lighter') else g_Console_Add('player lost his wings');
5983 exit;
5984 end;
5985 // noclip
5986 if cmd = 'noclip' then
5987 begin
5988 plr.SwitchNoClip;
5989 g_Console_Add('wall hardeness adjusted');
5990 exit;
5991 end;
5992 // notarget
5993 if cmd = 'notarget' then
5994 begin
5995 plr.NoTarget := not plr.NoTarget;
5996 if plr.NoTarget then g_Console_Add('player hides in shadows') else g_Console_Add('player is brave again');
5997 exit;
5998 end;
5999 // noreload
6000 if cmd = 'noreload' then
6001 begin
6002 plr.NoReload := not plr.NoReload;
6003 if plr.NoReload then g_Console_Add('player is action hero now') else g_Console_Add('player is ordinary man now');
6004 exit;
6005 end;
6006 // speedy
6007 if cmd = 'speedy' then
6008 begin
6009 MAX_RUNVEL := 32-MAX_RUNVEL;
6010 g_Console_Add('speed adjusted');
6011 exit;
6012 end;
6013 // jumpy
6014 if cmd = 'jumpy' then
6015 begin
6016 VEL_JUMP := 30-VEL_JUMP;
6017 g_Console_Add('jump height adjusted');
6018 exit;
6019 end;
6020 // automap
6021 if cmd = 'automap' then
6022 begin
6023 gShowMap := not gShowMap;
6024 if gShowMap then g_Console_Add('player gains second sight') else g_Console_Add('player lost second sight');
6025 exit;
6026 end;
6027 // aimline
6028 if cmd = 'aimline' then
6029 begin
6030 gAimLine := not gAimLine;
6031 if gAimLine then g_Console_Add('player gains laser sight') else g_Console_Add('player lost laser sight');
6032 exit;
6033 end;
6034 end;
6036 procedure GameCommands(P: SSArray);
6037 var
6038 a, b: Integer;
6039 s, pw: String;
6040 chstr: string;
6041 cmd: string;
6042 pl: pTNetClient = nil;
6043 plr: TPlayer;
6044 prt: Word;
6045 nm: Boolean;
6046 listen: LongWord;
6047 begin
6048 // Îáùèå êîìàíäû:
6049 cmd := LowerCase(P[0]);
6050 chstr := '';
6051 if (cmd = 'quit') or
6052 (cmd = 'exit') then
6053 begin
6054 g_Game_Free();
6055 g_Game_Quit();
6056 Exit;
6057 end
6058 else if cmd = 'pause' then
6059 begin
6060 if (g_ActiveWindow = nil) then
6061 g_Game_Pause(not gPauseMain);
6062 end
6063 else if cmd = 'endgame' then
6064 gExit := EXIT_SIMPLE
6065 else if cmd = 'restart' then
6066 begin
6067 if gGameOn or (gState in [STATE_INTERSINGLE, STATE_INTERCUSTOM]) then
6068 begin
6069 if g_Game_IsClient then
6070 begin
6071 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6072 Exit;
6073 end;
6074 g_Game_Restart();
6075 end else
6076 g_Console_Add(_lc[I_MSG_NOT_GAME]);
6077 end
6078 else if cmd = 'kick' then
6079 begin
6080 if g_Game_IsServer then
6081 begin
6082 if Length(P) < 2 then
6083 begin
6084 g_Console_Add('kick <name>');
6085 Exit;
6086 end;
6087 if P[1] = '' then
6088 begin
6089 g_Console_Add('kick <name>');
6090 Exit;
6091 end;
6093 if g_Game_IsNet then
6094 pl := g_Net_Client_ByName(P[1]);
6095 if (pl <> nil) then
6096 begin
6097 s := g_Net_ClientName_ByID(pl^.ID);
6098 enet_peer_disconnect(pl^.Peer, NET_DISC_KICK);
6099 g_Console_Add(Format(_lc[I_PLAYER_KICK], [s]));
6100 MH_SEND_GameEvent(NET_EV_PLAYER_KICK, 0, s);
6101 if NetUseMaster then
6102 g_Net_Slist_Update;
6103 end else if gPlayers <> nil then
6104 for a := Low(gPlayers) to High(gPlayers) do
6105 if gPlayers[a] <> nil then
6106 if Copy(LowerCase(gPlayers[a].Name), 1, Length(P[1])) = LowerCase(P[1]) then
6107 begin
6108 // Íå îòêëþ÷àòü îñíîâíûõ èãðîêîâ â ñèíãëå
6109 if not(gPlayers[a] is TBot) and (gGameSettings.GameType = GT_SINGLE) then
6110 continue;
6111 gPlayers[a].Lives := 0;
6112 gPlayers[a].Kill(K_SIMPLEKILL, 0, HIT_DISCON);
6113 g_Console_Add(Format(_lc[I_PLAYER_LEAVE], [gPlayers[a].Name]), True);
6114 g_Player_Remove(gPlayers[a].UID);
6115 if NetUseMaster then
6116 g_Net_Slist_Update;
6117 // Åñëè íå ïåðåìåøàòü, ïðè äîáàâëåíèè íîâûõ áîòîâ ïîÿâÿòñÿ ñòàðûå
6118 g_Bot_MixNames();
6119 end;
6120 end else
6121 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
6122 end
6123 else if cmd = 'kick_id' then
6124 begin
6125 if g_Game_IsServer and g_Game_IsNet then
6126 begin
6127 if Length(P) < 2 then
6128 begin
6129 g_Console_Add('kick_id <client ID>');
6130 Exit;
6131 end;
6132 if P[1] = '' then
6133 begin
6134 g_Console_Add('kick_id <client ID>');
6135 Exit;
6136 end;
6138 a := StrToIntDef(P[1], 0);
6139 if (NetClients <> nil) and (a <= High(NetClients)) then
6140 begin
6141 if NetClients[a].Used and (NetClients[a].Peer <> nil) then
6142 begin
6143 s := g_Net_ClientName_ByID(NetClients[a].ID);
6144 enet_peer_disconnect(NetClients[a].Peer, NET_DISC_KICK);
6145 g_Console_Add(Format(_lc[I_PLAYER_KICK], [s]));
6146 MH_SEND_GameEvent(NET_EV_PLAYER_KICK, 0, s);
6147 if NetUseMaster then
6148 g_Net_Slist_Update;
6149 end;
6150 end;
6151 end else
6152 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6153 end
6154 else if cmd = 'ban' then
6155 begin
6156 if g_Game_IsServer and g_Game_IsNet then
6157 begin
6158 if Length(P) < 2 then
6159 begin
6160 g_Console_Add('ban <name>');
6161 Exit;
6162 end;
6163 if P[1] = '' then
6164 begin
6165 g_Console_Add('ban <name>');
6166 Exit;
6167 end;
6169 pl := g_Net_Client_ByName(P[1]);
6170 if (pl <> nil) then
6171 begin
6172 s := g_Net_ClientName_ByID(pl^.ID);
6173 g_Net_BanHost(pl^.Peer^.address.host, False);
6174 enet_peer_disconnect(pl^.Peer, NET_DISC_TEMPBAN);
6175 g_Console_Add(Format(_lc[I_PLAYER_BAN], [s]));
6176 MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s);
6177 if NetUseMaster then
6178 g_Net_Slist_Update;
6179 end else
6180 g_Console_Add(Format(_lc[I_NET_ERR_NAME404], [P[1]]));
6181 end else
6182 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6183 end
6184 else if cmd = 'ban_id' then
6185 begin
6186 if g_Game_IsServer and g_Game_IsNet then
6187 begin
6188 if Length(P) < 2 then
6189 begin
6190 g_Console_Add('ban_id <client ID>');
6191 Exit;
6192 end;
6193 if P[1] = '' then
6194 begin
6195 g_Console_Add('ban_id <client ID>');
6196 Exit;
6197 end;
6199 a := StrToIntDef(P[1], 0);
6200 if (NetClients <> nil) and (a <= High(NetClients)) then
6201 if NetClients[a].Used and (NetClients[a].Peer <> nil) then
6202 begin
6203 s := g_Net_ClientName_ByID(NetClients[a].ID);
6204 g_Net_BanHost(NetClients[a].Peer^.address.host, False);
6205 enet_peer_disconnect(NetClients[a].Peer, NET_DISC_TEMPBAN);
6206 g_Console_Add(Format(_lc[I_PLAYER_BAN], [s]));
6207 MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s);
6208 if NetUseMaster then
6209 g_Net_Slist_Update;
6210 end;
6211 end else
6212 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6213 end
6214 else if cmd = 'permban' then
6215 begin
6216 if g_Game_IsServer and g_Game_IsNet then
6217 begin
6218 if Length(P) < 2 then
6219 begin
6220 g_Console_Add('permban <name>');
6221 Exit;
6222 end;
6223 if P[1] = '' then
6224 begin
6225 g_Console_Add('permban <name>');
6226 Exit;
6227 end;
6229 pl := g_Net_Client_ByName(P[1]);
6230 if (pl <> nil) then
6231 begin
6232 s := g_Net_ClientName_ByID(pl^.ID);
6233 g_Net_BanHost(pl^.Peer^.address.host);
6234 enet_peer_disconnect(pl^.Peer, NET_DISC_BAN);
6235 g_Net_SaveBanList();
6236 g_Console_Add(Format(_lc[I_PLAYER_BAN], [s]));
6237 MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s);
6238 if NetUseMaster then
6239 g_Net_Slist_Update;
6240 end else
6241 g_Console_Add(Format(_lc[I_NET_ERR_NAME404], [P[1]]));
6242 end else
6243 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6244 end
6245 else if cmd = 'permban_id' then
6246 begin
6247 if g_Game_IsServer and g_Game_IsNet then
6248 begin
6249 if Length(P) < 2 then
6250 begin
6251 g_Console_Add('permban_id <client ID>');
6252 Exit;
6253 end;
6254 if P[1] = '' then
6255 begin
6256 g_Console_Add('permban_id <client ID>');
6257 Exit;
6258 end;
6260 a := StrToIntDef(P[1], 0);
6261 if (NetClients <> nil) and (a <= High(NetClients)) then
6262 if NetClients[a].Used and (NetClients[a].Peer <> nil) then
6263 begin
6264 s := g_Net_ClientName_ByID(NetClients[a].ID);
6265 g_Net_BanHost(NetClients[a].Peer^.address.host);
6266 enet_peer_disconnect(NetClients[a].Peer, NET_DISC_BAN);
6267 g_Net_SaveBanList();
6268 g_Console_Add(Format(_lc[I_PLAYER_BAN], [s]));
6269 MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s);
6270 if NetUseMaster then
6271 g_Net_Slist_Update;
6272 end;
6273 end else
6274 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6275 end
6276 else if cmd = 'unban' then
6277 begin
6278 if g_Game_IsServer and g_Game_IsNet then
6279 begin
6280 if Length(P) < 2 then
6281 begin
6282 g_Console_Add('unban <IP Address>');
6283 Exit;
6284 end;
6285 if P[1] = '' then
6286 begin
6287 g_Console_Add('unban <IP Address>');
6288 Exit;
6289 end;
6291 if g_Net_UnbanHost(P[1]) then
6292 begin
6293 g_Console_Add(Format(_lc[I_MSG_UNBAN_OK], [P[1]]));
6294 g_Net_SaveBanList();
6295 end else
6296 g_Console_Add(Format(_lc[I_MSG_UNBAN_FAIL], [P[1]]));
6297 end else
6298 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6299 end
6300 else if cmd = 'clientlist' then
6301 begin
6302 if g_Game_IsServer and g_Game_IsNet then
6303 begin
6304 b := 0;
6305 if NetClients <> nil then
6306 for a := Low(NetClients) to High(NetClients) do
6307 if NetClients[a].Used and (NetClients[a].Peer <> nil) then
6308 begin
6309 plr := g_Player_Get(NetClients[a].Player);
6310 if plr = nil then continue;
6311 Inc(b);
6312 g_Console_Add(Format('#%2d: %-15s | %s', [a,
6313 IpToStr(NetClients[a].Peer^.address.host), plr.Name]));
6314 end;
6315 if b = 0 then
6316 g_Console_Add(_lc[I_MSG_NOCLIENTS]);
6317 end else
6318 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6319 end
6320 else if cmd = 'connect' then
6321 begin
6322 if (NetMode = NET_NONE) then
6323 begin
6324 if Length(P) < 2 then
6325 begin
6326 g_Console_Add('connect <IP> [port] [password]');
6327 Exit;
6328 end;
6329 if P[1] = '' then
6330 begin
6331 g_Console_Add('connect <IP> [port] [password]');
6332 Exit;
6333 end;
6335 if Length(P) > 2 then
6336 prt := StrToIntDef(P[2], 25666)
6337 else
6338 prt := 25666;
6340 if Length(P) > 3 then
6341 pw := P[3]
6342 else
6343 pw := '';
6345 g_Game_StartClient(P[1], prt, pw);
6346 end;
6347 end
6348 else if cmd = 'disconnect' then
6349 begin
6350 if (NetMode = NET_CLIENT) then
6351 g_Net_Disconnect();
6352 end
6353 else if cmd = 'reconnect' then
6354 begin
6355 if (NetMode = NET_SERVER) then
6356 Exit;
6358 if (NetMode = NET_CLIENT) then
6359 begin
6360 g_Net_Disconnect();
6361 gExit := EXIT_SIMPLE;
6362 EndGame;
6363 end;
6365 //TODO: Use last successful password to reconnect, instead of ''
6366 g_Game_StartClient(NetClientIP, NetClientPort, '');
6367 end
6368 else if (cmd = 'addbot') or
6369 (cmd = 'bot_add') then
6370 begin
6371 if Length(P) > 1 then
6372 g_Bot_Add(TEAM_NONE, StrToIntDef(P[1], 2))
6373 else
6374 g_Bot_Add(TEAM_NONE, 2);
6375 end
6376 else if cmd = 'bot_addlist' then
6377 begin
6378 if Length(P) > 1 then
6379 if Length(P) = 2 then
6380 g_Bot_AddList(TEAM_NONE, P[1], StrToIntDef(P[1], -1))
6381 else
6382 g_Bot_AddList(IfThen(P[2] = 'red', TEAM_RED, TEAM_BLUE), P[1], StrToIntDef(P[1], -1));
6383 end
6384 else if cmd = 'bot_removeall' then
6385 g_Bot_RemoveAll()
6386 else if cmd = 'chat' then
6387 begin
6388 if g_Game_IsNet then
6389 begin
6390 if Length(P) > 1 then
6391 begin
6392 for a := 1 to High(P) do
6393 chstr := chstr + P[a] + ' ';
6395 if Length(chstr) > 200 then SetLength(chstr, 200);
6397 if Length(chstr) < 1 then
6398 begin
6399 g_Console_Add('chat <text>');
6400 Exit;
6401 end;
6403 chstr := b_Text_Format(chstr);
6404 if g_Game_IsClient then
6405 MC_SEND_Chat(chstr, NET_CHAT_PLAYER)
6406 else
6407 MH_SEND_Chat(gPlayer1Settings.Name + ': ' + chstr, NET_CHAT_PLAYER);
6408 end
6409 else
6410 g_Console_Add('chat <text>');
6411 end else
6412 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
6413 end
6414 else if cmd = 'teamchat' then
6415 begin
6416 if g_Game_IsNet and (gGameSettings.GameMode in [GM_TDM, GM_CTF]) then
6417 begin
6418 if Length(P) > 1 then
6419 begin
6420 for a := 1 to High(P) do
6421 chstr := chstr + P[a] + ' ';
6423 if Length(chstr) > 200 then SetLength(chstr, 200);
6425 if Length(chstr) < 1 then
6426 begin
6427 g_Console_Add('teamchat <text>');
6428 Exit;
6429 end;
6431 chstr := b_Text_Format(chstr);
6432 if g_Game_IsClient then
6433 MC_SEND_Chat(chstr, NET_CHAT_TEAM)
6434 else
6435 MH_SEND_Chat(gPlayer1Settings.Name + ': ' + chstr, NET_CHAT_TEAM,
6436 gPlayer1Settings.Team);
6437 end
6438 else
6439 g_Console_Add('teamchat <text>');
6440 end else
6441 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
6442 end
6443 else if cmd = 'game' then
6444 begin
6445 if gGameSettings.GameType <> GT_NONE then
6446 begin
6447 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
6448 Exit;
6449 end;
6450 if Length(P) = 1 then
6451 begin
6452 g_Console_Add(cmd + ' <WAD> [MAP] [# players]');
6453 Exit;
6454 end;
6455 // Èãðà åù¸ íå çàïóùåíà, ñíà÷àëà íàì íàäî çàãðóçèòü êàêîé-òî WAD
6456 P[1] := addWadExtension(P[1]);
6457 if FileExists(MapsDir + P[1]) then
6458 begin
6459 // Åñëè êàðòà íå óêàçàíà, áåð¸ì ïåðâóþ êàðòó â ôàéëå
6460 if Length(P) < 3 then
6461 begin
6462 SetLength(P, 3);
6463 P[2] := g_Game_GetFirstMap(MapsDir + P[1]);
6464 end;
6466 s := P[1] + ':\' + UpperCase(P[2]);
6468 if g_Map_Exist(MapsDir + s) then
6469 begin
6470 // Çàïóñêàåì ñâîþ èãðó
6471 g_Game_Free();
6472 with gGameSettings do
6473 begin
6474 GameMode := g_Game_TextToMode(gcGameMode);
6475 if gSwitchGameMode <> GM_NONE then
6476 GameMode := gSwitchGameMode;
6477 if GameMode = GM_NONE then GameMode := GM_DM;
6478 if GameMode = GM_SINGLE then GameMode := GM_COOP;
6479 b := 1;
6480 if Length(P) >= 4 then
6481 b := StrToIntDef(P[3], 1);
6482 g_Game_StartCustom(s, GameMode, TimeLimit,
6483 GoalLimit, MaxLives, Options, b);
6484 end;
6485 end
6486 else
6487 if P[2] = '' then
6488 g_Console_Add(Format(_lc[I_MSG_NO_MAPS], [P[1]]))
6489 else
6490 g_Console_Add(Format(_lc[I_MSG_NO_MAP_FALLBACK], [UpperCase(P[2]), P[1]]));
6491 end else
6492 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]));
6493 end
6494 else if cmd = 'host' then
6495 begin
6496 if gGameSettings.GameType <> GT_NONE then
6497 begin
6498 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
6499 Exit;
6500 end;
6501 if Length(P) < 4 then
6502 begin
6503 g_Console_Add(cmd + ' <listen IP> <port> <WAD> [MAP] [# players]');
6504 Exit;
6505 end;
6506 if not StrToIp(P[1], listen) then
6507 Exit;
6508 prt := StrToIntDef(P[2], 25666);
6510 P[3] := addWadExtension(P[3]);
6511 if FileExists(MapsDir + P[3]) then
6512 begin
6513 // Åñëè êàðòà íå óêàçàíà, áåð¸ì ïåðâóþ êàðòó â ôàéëå
6514 if Length(P) < 5 then
6515 begin
6516 SetLength(P, 5);
6517 P[4] := g_Game_GetFirstMap(MapsDir + P[1]);
6518 end;
6520 s := P[3] + ':\' + UpperCase(P[4]);
6522 if g_Map_Exist(MapsDir + s) then
6523 begin
6524 // Çàïóñêàåì ñâîþ èãðó
6525 g_Game_Free();
6526 with gGameSettings do
6527 begin
6528 GameMode := g_Game_TextToMode(gcGameMode);
6529 if gSwitchGameMode <> GM_NONE then
6530 GameMode := gSwitchGameMode;
6531 if GameMode = GM_NONE then GameMode := GM_DM;
6532 if GameMode = GM_SINGLE then GameMode := GM_COOP;
6533 b := 0;
6534 if Length(P) >= 6 then
6535 b := StrToIntDef(P[5], 0);
6536 g_Game_StartServer(s, GameMode, TimeLimit,
6537 GoalLimit, MaxLives, Options, b, listen, prt);
6538 end;
6539 end
6540 else
6541 if P[4] = '' then
6542 g_Console_Add(Format(_lc[I_MSG_NO_MAPS], [P[3]]))
6543 else
6544 g_Console_Add(Format(_lc[I_MSG_NO_MAP_FALLBACK], [UpperCase(P[4]), P[3]]));
6545 end else
6546 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[3]]));
6547 end
6548 else if cmd = 'map' then
6549 begin
6550 if Length(P) = 1 then
6551 begin
6552 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
6553 begin
6554 g_Console_Add(cmd + ' <MAP>');
6555 g_Console_Add(cmd + ' <WAD> [MAP]');
6556 end else
6557 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
6558 end else
6559 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
6560 begin
6561 // Èä¸ò ñâîÿ èãðà èëè ñåðâåð
6562 if Length(P) < 3 then
6563 begin
6564 // Ïåðâûé ïàðàìåòð - ëèáî êàðòà, ëèáî èìÿ WAD ôàéëà
6565 s := UpperCase(P[1]);
6566 if g_Map_Exist(MapsDir + gGameSettings.WAD + ':\' + s) then
6567 begin // Êàðòà íàøëàñü
6568 gExitByTrigger := False;
6569 if gGameOn then
6570 begin // Èä¸ò èãðà - çàâåðøàåì óðîâåíü
6571 gNextMap := s;
6572 gExit := EXIT_ENDLEVELCUSTOM;
6573 end
6574 else // Èíòåðìèññèÿ - ñðàçó çàãðóæàåì êàðòó
6575 g_Game_ChangeMap(s);
6576 end else
6577 begin
6578 // Òàêîé êàðòû íåò, èùåì WAD ôàéë
6579 P[1] := addWadExtension(P[1]);
6580 g_Console_Add(Format(_lc[I_MSG_NO_MAP_FALLBACK], [s, P[1]]));
6581 if FileExists(MapsDir + P[1]) then
6582 begin
6583 // Ïàðàìåòðà êàðòû íåò, ïîýòîìó ñòàâèì ïåðâóþ èç ôàéëà
6584 SetLength(P, 3);
6585 P[2] := g_Game_GetFirstMap(MapsDir + P[1]);
6587 s := P[1] + ':\' + P[2];
6589 if g_Map_Exist(MapsDir + s) then
6590 begin
6591 gExitByTrigger := False;
6592 if gGameOn then
6593 begin // Èä¸ò èãðà - çàâåðøàåì óðîâåíü
6594 gNextMap := s;
6595 gExit := EXIT_ENDLEVELCUSTOM;
6596 end
6597 else // Èíòåðìèññèÿ - ñðàçó çàãðóæàåì êàðòó
6598 g_Game_ChangeMap(s);
6599 end else
6600 if P[2] = '' then
6601 g_Console_Add(Format(_lc[I_MSG_NO_MAPS], [P[1]]))
6602 else
6603 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [P[2]]));
6604 end else
6605 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]));
6606 end;
6607 end else
6608 begin
6609 // Óêàçàíî äâà ïàðàìåòðà, çíà÷èò ïåðâûé - WAD ôàéë, à âòîðîé - êàðòà
6610 P[1] := addWadExtension(P[1]);
6611 if FileExists(MapsDir + P[1]) then
6612 begin
6613 // Íàøëè WAD ôàéë
6614 P[2] := UpperCase(P[2]);
6615 s := P[1] + ':\' + P[2];
6617 if g_Map_Exist(MapsDir + s) then
6618 begin // Íàøëè êàðòó
6619 gExitByTrigger := False;
6620 if gGameOn then
6621 begin // Èä¸ò èãðà - çàâåðøàåì óðîâåíü
6622 gNextMap := s;
6623 gExit := EXIT_ENDLEVELCUSTOM;
6624 end
6625 else // Èíòåðìèññèÿ - ñðàçó çàãðóæàåì êàðòó
6626 g_Game_ChangeMap(s);
6627 end else
6628 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [P[2]]));
6629 end else
6630 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]));
6631 end;
6632 end else
6633 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
6634 end
6635 else if cmd = 'nextmap' then
6636 begin
6637 if not(gGameOn or (gState = STATE_INTERCUSTOM)) then
6638 g_Console_Add(_lc[I_MSG_NOT_GAME])
6639 else begin
6640 nm := True;
6641 if Length(P) = 1 then
6642 begin
6643 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
6644 begin
6645 g_Console_Add(cmd + ' <MAP>');
6646 g_Console_Add(cmd + ' <WAD> [MAP]');
6647 end else begin
6648 nm := False;
6649 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
6650 end;
6651 end else
6652 begin
6653 nm := False;
6654 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
6655 begin
6656 if Length(P) < 3 then
6657 begin
6658 // Ïåðâûé ïàðàìåòð - ëèáî êàðòà, ëèáî èìÿ WAD ôàéëà
6659 s := UpperCase(P[1]);
6660 if g_Map_Exist(MapsDir + gGameSettings.WAD + ':\' + s) then
6661 begin // Êàðòà íàøëàñü
6662 gExitByTrigger := False;
6663 gNextMap := s;
6664 nm := True;
6665 end else
6666 begin
6667 // Òàêîé êàðòû íåò, èùåì WAD ôàéë
6668 P[1] := addWadExtension(P[1]);
6669 g_Console_Add(Format(_lc[I_MSG_NO_MAP_FALLBACK], [s, P[1]]));
6670 if FileExists(MapsDir + P[1]) then
6671 begin
6672 // Ïàðàìåòðà êàðòû íåò, ïîýòîìó ñòàâèì ïåðâóþ èç ôàéëà
6673 SetLength(P, 3);
6674 P[2] := g_Game_GetFirstMap(MapsDir + P[1]);
6676 s := P[1] + ':\' + P[2];
6678 if g_Map_Exist(MapsDir + s) then
6679 begin // Óñòàíàâëèâàåì êàðòó
6680 gExitByTrigger := False;
6681 gNextMap := s;
6682 nm := True;
6683 end else
6684 if P[2] = '' then
6685 g_Console_Add(Format(_lc[I_MSG_NO_MAPS], [P[1]]))
6686 else
6687 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [P[2]]));
6688 end else
6689 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]));
6690 end;
6691 end else
6692 begin
6693 // Óêàçàíî äâà ïàðàìåòðà, çíà÷èò ïåðâûé - WAD ôàéë, à âòîðîé - êàðòà
6694 P[1] := addWadExtension(P[1]);
6695 if FileExists(MapsDir + P[1]) then
6696 begin
6697 // Íàøëè WAD ôàéë
6698 P[2] := UpperCase(P[2]);
6699 s := P[1] + ':\' + P[2];
6701 if g_Map_Exist(MapsDir + s) then
6702 begin // Íàøëè êàðòó
6703 gExitByTrigger := False;
6704 gNextMap := s;
6705 nm := True;
6706 end else
6707 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [P[2]]));
6708 end else
6709 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]));
6710 end;
6711 end else
6712 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
6713 end;
6714 if nm then
6715 if gNextMap = '' then
6716 g_Console_Add(_lc[I_MSG_NEXTMAP_UNSET])
6717 else
6718 g_Console_Add(Format(_lc[I_MSG_NEXTMAP_SET], [gNextMap]));
6719 end;
6720 end
6721 else if (cmd = 'endmap') or (cmd = 'goodbye') then
6722 begin
6723 if not gGameOn then
6724 g_Console_Add(_lc[I_MSG_NOT_GAME])
6725 else
6726 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
6727 begin
6728 gExitByTrigger := False;
6729 // Ñëåäóþùàÿ êàðòà íå çàäàíà, ïðîáóåì íàéòè òðèããåð Âûõîä
6730 if (gNextMap = '') and (gTriggers <> nil) then
6731 for a := 0 to High(gTriggers) do
6732 if gTriggers[a].TriggerType = TRIGGER_EXIT then
6733 begin
6734 gExitByTrigger := True;
6735 //gNextMap := gTriggers[a].Data.MapName;
6736 gNextMap := gTriggers[a].tgcMap;
6737 Break;
6738 end;
6739 // Èùåì ñëåäóþùóþ êàðòó â WAD ôàéëå
6740 if gNextMap = '' then
6741 gNextMap := g_Game_GetNextMap();
6742 // Ïðîâåðÿåì, íå çàäàí ëè WAD ôàéë ðåñóðñíîé ñòðîêîé
6743 if not isWadPath(gNextMap) then
6744 s := gGameSettings.WAD + ':\' + gNextMap
6745 else
6746 s := gNextMap;
6747 // Åñëè êàðòà íàéäåíà, âûõîäèì ñ óðîâíÿ
6748 if g_Map_Exist(MapsDir + s) then
6749 gExit := EXIT_ENDLEVELCUSTOM
6750 else
6751 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [gNextMap]));
6752 end else
6753 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
6754 end
6755 else if (cmd = 'event') then
6756 begin
6757 if (Length(P) <= 1) then
6758 begin
6759 for a := 0 to High(gEvents) do
6760 if gEvents[a].Command = '' then
6761 g_Console_Add(gEvents[a].Name + ' <none>')
6762 else
6763 g_Console_Add(gEvents[a].Name + ' "' + gEvents[a].Command + '"');
6764 Exit;
6765 end;
6766 if (Length(P) = 2) then
6767 begin
6768 for a := 0 to High(gEvents) do
6769 if gEvents[a].Name = P[1] then
6770 if gEvents[a].Command = '' then
6771 g_Console_Add(gEvents[a].Name + ' <none>')
6772 else
6773 g_Console_Add(gEvents[a].Name + ' "' + gEvents[a].Command + '"');
6774 Exit;
6775 end;
6776 for a := 0 to High(gEvents) do
6777 if gEvents[a].Name = P[1] then
6778 begin
6779 gEvents[a].Command := '';
6780 for b := 2 to High(P) do
6781 if Pos(' ', P[b]) = 0 then
6782 gEvents[a].Command := gEvents[a].Command + ' ' + P[b]
6783 else
6784 gEvents[a].Command := gEvents[a].Command + ' "' + P[b] + '"';
6785 gEvents[a].Command := Trim(gEvents[a].Command);
6786 Exit;
6787 end;
6788 end
6789 else if cmd = 'suicide' then
6790 begin
6791 if gGameOn then
6792 begin
6793 if g_Game_IsClient then
6794 MC_SEND_CheatRequest(NET_CHEAT_SUICIDE)
6795 else
6796 begin
6797 if gPlayer1 <> nil then
6798 gPlayer1.Damage(SUICIDE_DAMAGE, gPlayer1.UID, 0, 0, HIT_SELF);
6799 if gPlayer2 <> nil then
6800 gPlayer2.Damage(SUICIDE_DAMAGE, gPlayer2.UID, 0, 0, HIT_SELF);
6801 end;
6802 end;
6803 end
6804 else if cmd = 'screenshot' then
6805 begin
6806 g_TakeScreenShot()
6807 end
6808 else if cmd = 'togglechat' then
6809 begin
6810 g_Console_Chat_Switch(False);
6811 gSkipFirstChar := not g_Console_Interactive()
6812 end
6813 else if cmd = 'toggleteamchat' then
6814 begin
6815 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
6816 begin
6817 g_Console_Chat_Switch(True);
6818 gSkipFirstChar := not g_Console_Interactive()
6819 end
6820 end
6821 else if cmd = 'weapon' then
6822 begin
6823 if Length(p) = 2 then
6824 begin
6825 a := WP_FIRST + StrToInt(p[1]) - 1;
6826 if (a >= WP_FIRST) and (a <= WP_LAST) then
6827 gSelectWeapon[0, a] := True
6828 end
6829 end
6830 else if (cmd = 'p1_weapon') or (cmd = 'p2_weapon') then
6831 begin
6832 if Length(p) = 2 then
6833 begin
6834 a := WP_FIRST + StrToInt(p[1]) - 1;
6835 b := ord(cmd[2]) - ord('1');
6836 if (a >= WP_FIRST) and (a <= WP_LAST) then
6837 gSelectWeapon[b, a] := True
6838 end
6839 end
6840 // Êîìàíäû Ñâîåé èãðû:
6841 else if gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT] then
6842 begin
6843 if cmd = 'bot_addred' then
6844 begin
6845 if Length(P) > 1 then
6846 g_Bot_Add(TEAM_RED, StrToIntDef(P[1], 2))
6847 else
6848 g_Bot_Add(TEAM_RED, 2);
6849 end
6850 else if cmd = 'bot_addblue' then
6851 begin
6852 if Length(P) > 1 then
6853 g_Bot_Add(TEAM_BLUE, StrToIntDef(P[1], 2))
6854 else
6855 g_Bot_Add(TEAM_BLUE, 2);
6856 end
6857 else if cmd = 'spectate' then
6858 begin
6859 if not gGameOn then
6860 Exit;
6861 g_Game_Spectate();
6862 end
6863 else if cmd = 'say' then
6864 begin
6865 if g_Game_IsServer and g_Game_IsNet then
6866 begin
6867 if Length(P) > 1 then
6868 begin
6869 chstr := '';
6870 for a := 1 to High(P) do
6871 chstr := chstr + P[a] + ' ';
6873 if Length(chstr) > 200 then SetLength(chstr, 200);
6875 if Length(chstr) < 1 then
6876 begin
6877 g_Console_Add('say <text>');
6878 Exit;
6879 end;
6881 chstr := b_Text_Format(chstr);
6882 MH_SEND_Chat(chstr, NET_CHAT_PLAYER);
6883 end
6884 else g_Console_Add('say <text>');
6885 end else
6886 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6887 end
6888 else if cmd = 'tell' then
6889 begin
6890 if g_Game_IsServer and g_Game_IsNet then
6891 begin
6892 if (Length(P) > 2) and (P[1] <> '') then
6893 begin
6894 chstr := '';
6895 for a := 2 to High(P) do
6896 chstr := chstr + P[a] + ' ';
6898 if Length(chstr) > 200 then SetLength(chstr, 200);
6900 if Length(chstr) < 1 then
6901 begin
6902 g_Console_Add('tell <playername> <text>');
6903 Exit;
6904 end;
6906 pl := g_Net_Client_ByName(P[1]);
6907 if pl <> nil then
6908 MH_SEND_Chat(b_Text_Format(chstr), NET_CHAT_PLAYER, pl^.ID)
6909 else
6910 g_Console_Add(Format(_lc[I_NET_ERR_NAME404], [P[1]]));
6911 end
6912 else g_Console_Add('tell <playername> <text>');
6913 end else
6914 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6915 end
6916 else if (cmd = 'overtime') and not g_Game_IsClient then
6917 begin
6918 if (Length(P) = 1) or (StrToIntDef(P[1], -1) <= 0) then
6919 Exit;
6920 // Äîïîëíèòåëüíîå âðåìÿ:
6921 gGameSettings.TimeLimit := (gTime - gGameStartTime) div 1000 + Word(StrToIntDef(P[1], 0));
6923 g_Console_Add(Format(_lc[I_MSG_TIME_LIMIT],
6924 [gGameSettings.TimeLimit div 3600,
6925 (gGameSettings.TimeLimit div 60) mod 60,
6926 gGameSettings.TimeLimit mod 60]));
6927 if g_Game_IsNet then MH_SEND_GameSettings;
6928 end
6929 else if (cmd = 'rcon_password') and g_Game_IsClient then
6930 begin
6931 if (Length(P) <= 1) then
6932 g_Console_Add('rcon_password <password>')
6933 else
6934 MC_SEND_RCONPassword(P[1]);
6935 end
6936 else if cmd = 'rcon' then
6937 begin
6938 if g_Game_IsClient then
6939 begin
6940 if Length(P) > 1 then
6941 begin
6942 chstr := '';
6943 for a := 1 to High(P) do
6944 chstr := chstr + P[a] + ' ';
6946 if Length(chstr) > 200 then SetLength(chstr, 200);
6948 if Length(chstr) < 1 then
6949 begin
6950 g_Console_Add('rcon <command>');
6951 Exit;
6952 end;
6954 MC_SEND_RCONCommand(chstr);
6955 end
6956 else g_Console_Add('rcon <command>');
6957 end;
6958 end
6959 else if cmd = 'ready' then
6960 begin
6961 if g_Game_IsServer and (gLMSRespawn = LMS_RESPAWN_WARMUP) then
6962 gLMSRespawnTime := gTime + 100;
6963 end
6964 else if (cmd = 'callvote') and g_Game_IsNet then
6965 begin
6966 if Length(P) > 1 then
6967 begin
6968 chstr := '';
6969 for a := 1 to High(P) do begin
6970 if a > 1 then chstr := chstr + ' ';
6971 chstr := chstr + P[a];
6972 end;
6974 if Length(chstr) > 200 then SetLength(chstr, 200);
6976 if Length(chstr) < 1 then
6977 begin
6978 g_Console_Add('callvote <command>');
6979 Exit;
6980 end;
6982 if g_Game_IsClient then
6983 MC_SEND_Vote(True, chstr)
6984 else
6985 g_Game_StartVote(chstr, gPlayer1Settings.Name);
6986 g_Console_Process('vote', True);
6987 end
6988 else
6989 g_Console_Add('callvote <command>');
6990 end
6991 else if (cmd = 'vote') and g_Game_IsNet then
6992 begin
6993 if g_Game_IsClient then
6994 MC_SEND_Vote(False)
6995 else if gVoteInProgress then
6996 begin
6997 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
6998 a := Floor((NetClientCount+1)/2.0) + 1
6999 else
7000 a := Floor(NetClientCount/2.0) + 1;
7001 if gVoted then
7002 begin
7003 Dec(gVoteCount);
7004 gVoted := False;
7005 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_REVOKED], [gPlayer1Settings.Name, gVoteCount, a]), True);
7006 MH_SEND_VoteEvent(NET_VE_REVOKE, gPlayer1Settings.Name, 'a', gVoteCount, a);
7007 end
7008 else
7009 begin
7010 Inc(gVoteCount);
7011 gVoted := True;
7012 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_VOTE], [gPlayer1Settings.Name, gVoteCount, a]), True);
7013 MH_SEND_VoteEvent(NET_VE_VOTE, gPlayer1Settings.Name, 'a', gVoteCount, a);
7014 g_Game_CheckVote;
7015 end;
7016 end;
7017 end
7018 end;
7019 end;
7021 procedure g_TakeScreenShot();
7022 var
7023 a: Word;
7024 FileName: string;
7025 ssdir, t: string;
7026 st: TStream;
7027 ok: Boolean;
7028 begin
7029 if e_NoGraphics then Exit;
7030 ssdir := GameDir+'/screenshots';
7031 if not findFileCI(ssdir, true) then
7032 begin
7033 // try to create dir
7034 try
7035 CreateDir(ssdir);
7036 except
7037 end;
7038 if not findFileCI(ssdir, true) then exit; // alas
7039 end;
7040 try
7041 for a := 1 to High(Word) do
7042 begin
7043 FileName := Format(ssdir+'screenshot%.3d.png', [a]);
7044 t := FileName;
7045 if findFileCI(t, true) then continue;
7046 if not findFileCI(FileName) then
7047 begin
7048 ok := false;
7049 st := createDiskFile(FileName);
7050 try
7051 e_MakeScreenshot(st, gScreenWidth, gScreenHeight);
7052 ok := true;
7053 finally
7054 st.Free();
7055 end;
7056 if not ok then try DeleteFile(FileName); except end else g_Console_Add(Format(_lc[I_CONSOLE_SCREENSHOT], [ExtractFileName(FileName)]));
7057 break;
7058 end;
7059 end;
7060 except
7061 end;
7062 end;
7064 procedure g_Game_InGameMenu(Show: Boolean);
7065 begin
7066 if (g_ActiveWindow = nil) and Show then
7067 begin
7068 if gGameSettings.GameType = GT_SINGLE then
7069 g_GUI_ShowWindow('GameSingleMenu')
7070 else
7071 begin
7072 if g_Game_IsClient then
7073 g_GUI_ShowWindow('GameClientMenu')
7074 else
7075 if g_Game_IsNet then
7076 g_GUI_ShowWindow('GameServerMenu')
7077 else
7078 g_GUI_ShowWindow('GameCustomMenu');
7079 end;
7080 g_Sound_PlayEx('MENU_OPEN');
7082 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
7083 if (not g_Game_IsNet) then
7084 g_Game_Pause(True);
7085 end
7086 else
7087 if (g_ActiveWindow <> nil) and (not Show) then
7088 begin
7089 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
7090 if (not g_Game_IsNet) then
7091 g_Game_Pause(False);
7092 end;
7093 end;
7095 procedure g_Game_Pause (Enable: Boolean);
7096 var
7097 oldPause: Boolean;
7098 begin
7099 if not gGameOn then exit;
7101 if not (gGameSettings.GameType in [GT_SINGLE, GT_CUSTOM]) then exit;
7103 oldPause := gPause;
7104 gPauseMain := Enable;
7106 if (gPause <> oldPause) then g_Game_PauseAllSounds(gPause);
7107 end;
7109 procedure g_Game_HolmesPause (Enable: Boolean);
7110 var
7111 oldPause: Boolean;
7112 begin
7113 if not gGameOn then exit;
7114 if not (gGameSettings.GameType in [GT_SINGLE, GT_CUSTOM]) then exit;
7116 oldPause := gPause;
7117 gPauseHolmes := Enable;
7119 if (gPause <> oldPause) then g_Game_PauseAllSounds(gPause);
7120 end;
7122 procedure g_Game_PauseAllSounds(Enable: Boolean);
7123 var
7124 i: Integer;
7125 begin
7126 // Òðèããåðû:
7127 if gTriggers <> nil then
7128 for i := 0 to High(gTriggers) do
7129 with gTriggers[i] do
7130 if (TriggerType = TRIGGER_SOUND) and
7131 (Sound <> nil) and
7132 Sound.IsPlaying() then
7133 begin
7134 Sound.Pause(Enable);
7135 end;
7137 // Çâóêè èãðîêîâ:
7138 if gPlayers <> nil then
7139 for i := 0 to High(gPlayers) do
7140 if gPlayers[i] <> nil then
7141 gPlayers[i].PauseSounds(Enable);
7143 // Ìóçûêà:
7144 if gMusic <> nil then
7145 gMusic.Pause(Enable);
7146 end;
7148 procedure g_Game_StopAllSounds(all: Boolean);
7149 var
7150 i: Integer;
7151 begin
7152 if gTriggers <> nil then
7153 for i := 0 to High(gTriggers) do
7154 with gTriggers[i] do
7155 if (TriggerType = TRIGGER_SOUND) and
7156 (Sound <> nil) then
7157 Sound.Stop();
7159 if gMusic <> nil then
7160 gMusic.Stop();
7162 if all then
7163 e_StopChannels();
7164 end;
7166 procedure g_Game_UpdateTriggerSounds();
7167 var
7168 i: Integer;
7169 begin
7170 if gTriggers <> nil then
7171 for i := 0 to High(gTriggers) do
7172 with gTriggers[i] do
7173 if (TriggerType = TRIGGER_SOUND) and
7174 (Sound <> nil) and
7175 (tgcLocal) and
7176 Sound.IsPlaying() then
7177 begin
7178 if ((gPlayer1 <> nil) and g_CollidePoint(gPlayer1.GameX, gPlayer1.GameY, X, Y, Width, Height)) or
7179 ((gPlayer2 <> nil) and g_CollidePoint(gPlayer2.GameX, gPlayer2.GameY, X, Y, Width, Height)) then
7180 begin
7181 Sound.SetPan(0.5 - tgcPan/255.0);
7182 Sound.SetVolume(tgcVolume/255.0);
7183 end
7184 else
7185 Sound.SetCoords(X+(Width div 2), Y+(Height div 2), tgcVolume/255.0);
7186 end;
7187 end;
7189 function g_Game_IsWatchedPlayer(UID: Word): Boolean;
7190 begin
7191 Result := False;
7192 if (gPlayer1 <> nil) and (gPlayer1.UID = UID) then
7193 begin
7194 Result := True;
7195 Exit;
7196 end;
7197 if (gPlayer2 <> nil) and (gPlayer2.UID = UID) then
7198 begin
7199 Result := True;
7200 Exit;
7201 end;
7202 if gSpectMode <> SPECT_PLAYERS then
7203 Exit;
7204 if gSpectPID1 = UID then
7205 begin
7206 Result := True;
7207 Exit;
7208 end;
7209 if gSpectViewTwo and (gSpectPID2 = UID) then
7210 begin
7211 Result := True;
7212 Exit;
7213 end;
7214 end;
7216 function g_Game_IsWatchedTeam(Team: Byte): Boolean;
7217 var
7218 Pl: TPlayer;
7219 begin
7220 Result := False;
7221 if (gPlayer1 <> nil) and (gPlayer1.Team = Team) then
7222 begin
7223 Result := True;
7224 Exit;
7225 end;
7226 if (gPlayer2 <> nil) and (gPlayer2.Team = Team) then
7227 begin
7228 Result := True;
7229 Exit;
7230 end;
7231 if gSpectMode <> SPECT_PLAYERS then
7232 Exit;
7233 Pl := g_Player_Get(gSpectPID1);
7234 if (Pl <> nil) and (Pl.Team = Team) then
7235 begin
7236 Result := True;
7237 Exit;
7238 end;
7239 if gSpectViewTwo then
7240 begin
7241 Pl := g_Player_Get(gSpectPID2);
7242 if (Pl <> nil) and (Pl.Team = Team) then
7243 begin
7244 Result := True;
7245 Exit;
7246 end;
7247 end;
7248 end;
7250 procedure g_Game_Message(Msg: string; Time: Word);
7251 begin
7252 MessageLineLength := (gScreenWidth - 204) div e_CharFont_GetMaxWidth(gMenuFont);
7253 MessageText := b_Text_Wrap(b_Text_Format(Msg), MessageLineLength);
7254 MessageTime := Time;
7255 end;
7257 procedure g_Game_ChatSound(Text: String; Taunt: Boolean = True);
7258 const
7259 punct: Array[0..13] of String =
7260 ('.', ',', ':', ';', '!', '?', '(', ')', '''', '"', '/', '\', '*', '^');
7261 var
7262 i, j: Integer;
7263 ok: Boolean;
7264 fpText: String;
7266 function IsPunctuation(S: String): Boolean;
7267 var
7268 i: Integer;
7269 begin
7270 Result := False;
7271 if Length(S) <> 1 then
7272 Exit;
7273 for i := Low(punct) to High(punct) do
7274 if S = punct[i] then
7275 begin
7276 Result := True;
7277 break;
7278 end;
7279 end;
7280 function FilterPunctuation(S: String): String;
7281 var
7282 i: Integer;
7283 begin
7284 for i := Low(punct) to High(punct) do
7285 S := StringReplace(S, punct[i], ' ', [rfReplaceAll]);
7286 Result := S;
7287 end;
7288 begin
7289 ok := False;
7291 if gUseChatSounds and Taunt and (gChatSounds <> nil) and (Pos(': ', Text) > 0) then
7292 begin
7293 // remove player name
7294 Delete(Text, 1, Pos(': ', Text) + 2 - 1);
7295 // for FullWord check
7296 Text := toLowerCase1251(' ' + Text + ' ');
7297 fpText := FilterPunctuation(Text);
7299 for i := 0 to Length(gChatSounds) - 1 do
7300 begin
7301 ok := True;
7302 for j := 0 to Length(gChatSounds[i].Tags) - 1 do
7303 begin
7304 if gChatSounds[i].FullWord and (not IsPunctuation(gChatSounds[i].Tags[j])) then
7305 ok := Pos(' ' + gChatSounds[i].Tags[j] + ' ', fpText) > 0
7306 else
7307 ok := Pos(gChatSounds[i].Tags[j], Text) > 0;
7308 if not ok then
7309 break;
7310 end;
7311 if ok then
7312 begin
7313 gChatSounds[i].Sound.Play();
7314 break;
7315 end;
7316 end;
7317 end;
7318 if not ok then
7319 g_Sound_PlayEx('SOUND_GAME_RADIO');
7320 end;
7322 procedure g_Game_Announce_GoodShot(SpawnerUID: Word);
7323 var
7324 a: Integer;
7325 begin
7326 case gAnnouncer of
7327 ANNOUNCE_NONE:
7328 Exit;
7329 ANNOUNCE_ME,
7330 ANNOUNCE_MEPLUS:
7331 if not g_Game_IsWatchedPlayer(SpawnerUID) then
7332 Exit;
7333 end;
7334 for a := 0 to 3 do
7335 if goodsnd[a].IsPlaying() then
7336 Exit;
7338 goodsnd[Random(4)].Play();
7339 end;
7341 procedure g_Game_Announce_KillCombo(Param: Integer);
7342 var
7343 UID: Word;
7344 c, n: Byte;
7345 Pl: TPlayer;
7346 Name: String;
7347 begin
7348 UID := Param and $FFFF;
7349 c := Param shr 16;
7350 if c < 2 then
7351 Exit;
7353 Pl := g_Player_Get(UID);
7354 if Pl = nil then
7355 Name := '?'
7356 else
7357 Name := Pl.Name;
7359 case c of
7360 2: begin
7361 n := 0;
7362 g_Console_Add(Format(_lc[I_PLAYER_KILL_2X], [Name]), True);
7363 end;
7364 3: begin
7365 n := 1;
7366 g_Console_Add(Format(_lc[I_PLAYER_KILL_3X], [Name]), True);
7367 end;
7368 4: begin
7369 n := 2;
7370 g_Console_Add(Format(_lc[I_PLAYER_KILL_4X], [Name]), True);
7371 end;
7372 else begin
7373 n := 3;
7374 g_Console_Add(Format(_lc[I_PLAYER_KILL_MX], [Name]), True);
7375 end;
7376 end;
7378 case gAnnouncer of
7379 ANNOUNCE_NONE:
7380 Exit;
7381 ANNOUNCE_ME:
7382 if not g_Game_IsWatchedPlayer(UID) then
7383 Exit;
7384 ANNOUNCE_MEPLUS:
7385 if (not g_Game_IsWatchedPlayer(UID)) and (c < 4) then
7386 Exit;
7387 end;
7389 if killsnd[n].IsPlaying() then
7390 killsnd[n].Stop();
7391 killsnd[n].Play();
7392 end;
7394 procedure g_Game_Announce_BodyKill(SpawnerUID: Word);
7395 var
7396 a: Integer;
7397 begin
7398 case gAnnouncer of
7399 ANNOUNCE_NONE:
7400 Exit;
7401 ANNOUNCE_ME,
7402 ANNOUNCE_MEPLUS:
7403 if not g_Game_IsWatchedPlayer(SpawnerUID) then
7404 Exit;
7405 end;
7406 for a := 0 to 2 do
7407 if hahasnd[a].IsPlaying() then
7408 Exit;
7410 hahasnd[Random(3)].Play();
7411 end;
7413 procedure g_Game_StartVote(Command, Initiator: string);
7414 var
7415 Need: Integer;
7416 begin
7417 if not gVotesEnabled then Exit;
7418 if gGameSettings.GameType <> GT_SERVER then Exit;
7419 if gVoteInProgress or gVotePassed then
7420 begin
7421 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_INPROGRESS], [gVoteCommand]), True);
7422 MH_SEND_VoteEvent(NET_VE_INPROGRESS, gVoteCommand);
7423 Exit;
7424 end;
7425 gVoteInProgress := True;
7426 gVotePassed := False;
7427 gVoteTimer := gTime + gVoteTimeout * 1000;
7428 gVoteCount := 0;
7429 gVoted := False;
7430 gVoteCommand := Command;
7432 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
7433 Need := Floor((NetClientCount+1)/2.0)+1
7434 else
7435 Need := Floor(NetClientCount/2.0)+1;
7436 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_STARTED], [Initiator, Command, Need]), True);
7437 MH_SEND_VoteEvent(NET_VE_STARTED, Initiator, Command, Need);
7438 end;
7440 procedure g_Game_CheckVote;
7441 var
7442 I, Need: Integer;
7443 begin
7444 if gGameSettings.GameType <> GT_SERVER then Exit;
7445 if not gVoteInProgress then Exit;
7447 if (gTime >= gVoteTimer) then
7448 begin
7449 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
7450 Need := Floor((NetClientCount+1)/2.0) + 1
7451 else
7452 Need := Floor(NetClientCount/2.0) + 1;
7453 if gVoteCount >= Need then
7454 begin
7455 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_PASSED], [gVoteCommand]), True);
7456 MH_SEND_VoteEvent(NET_VE_PASSED, gVoteCommand);
7457 gVotePassed := True;
7458 gVoteCmdTimer := gTime + 5000;
7459 end
7460 else
7461 begin
7462 g_Console_Add(_lc[I_MESSAGE_VOTE_FAILED], True);
7463 MH_SEND_VoteEvent(NET_VE_FAILED);
7464 end;
7465 if NetClients <> nil then
7466 for I := Low(NetClients) to High(NetClients) do
7467 if NetClients[i].Used then
7468 NetClients[i].Voted := False;
7469 gVoteInProgress := False;
7470 gVoted := False;
7471 gVoteCount := 0;
7472 end
7473 else
7474 begin
7475 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
7476 Need := Floor((NetClientCount+1)/2.0) + 1
7477 else
7478 Need := Floor(NetClientCount/2.0) + 1;
7479 if gVoteCount >= Need then
7480 begin
7481 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_PASSED], [gVoteCommand]), True);
7482 MH_SEND_VoteEvent(NET_VE_PASSED, gVoteCommand);
7483 gVoteInProgress := False;
7484 gVotePassed := True;
7485 gVoteCmdTimer := gTime + 5000;
7486 gVoted := False;
7487 gVoteCount := 0;
7488 if NetClients <> nil then
7489 for I := Low(NetClients) to High(NetClients) do
7490 if NetClients[i].Used then
7491 NetClients[i].Voted := False;
7492 end;
7493 end;
7494 end;
7496 procedure g_Game_LoadMapList(FileName: string);
7497 var
7498 ListFile: TextFile;
7499 s: string;
7500 begin
7501 MapList := nil;
7502 MapIndex := -1;
7504 if not FileExists(FileName) then Exit;
7506 AssignFile(ListFile, FileName);
7507 Reset(ListFile);
7508 while not EOF(ListFile) do
7509 begin
7510 ReadLn(ListFile, s);
7512 s := Trim(s);
7513 if s = '' then Continue;
7515 SetLength(MapList, Length(MapList)+1);
7516 MapList[High(MapList)] := s;
7517 end;
7518 CloseFile(ListFile);
7519 end;
7521 procedure g_Game_SetDebugMode();
7522 begin
7523 gDebugMode := True;
7524 // ×èòû (äàæå â ñâîåé èãðå):
7525 gCheats := True;
7526 end;
7528 procedure g_Game_SetLoadingText(Text: String; Max: Integer; reWrite: Boolean);
7529 var
7530 i: Word;
7531 begin
7532 if Length(LoadingStat.Msgs) = 0 then
7533 Exit;
7535 with LoadingStat do
7536 begin
7537 if not reWrite then
7538 begin // Ïåðåõîäèì íà ñëåäóþùóþ ñòðîêó èëè ñêðîëëèðóåì:
7539 if NextMsg = Length(Msgs) then
7540 begin // scroll
7541 for i := 0 to High(Msgs)-1 do
7542 Msgs[i] := Msgs[i+1];
7543 end
7544 else
7545 Inc(NextMsg);
7546 end else
7547 if NextMsg = 0 then
7548 Inc(NextMsg);
7550 Msgs[NextMsg-1] := Text;
7551 CurValue := 0;
7552 MaxValue := Max;
7553 ShowCount := 0;
7554 PBarWasHere := false;
7555 end;
7557 g_ActiveWindow := nil;
7559 ProcessLoading(true);
7560 end;
7562 procedure g_Game_StepLoading(Value: Integer = -1);
7563 begin
7564 with LoadingStat do
7565 begin
7566 if Value = -1 then
7567 begin
7568 Inc(CurValue);
7569 Inc(ShowCount);
7570 end
7571 else
7572 CurValue := Value;
7573 if (ShowCount > LOADING_SHOW_STEP) or (Value > -1) then
7574 begin
7575 ShowCount := 0;
7576 ProcessLoading();
7577 end;
7578 end;
7579 end;
7581 procedure g_Game_ClearLoading();
7582 var
7583 len: Word;
7584 begin
7585 with LoadingStat do
7586 begin
7587 CurValue := 0;
7588 MaxValue := 0;
7589 ShowCount := 0;
7590 len := ((gScreenHeight div 3)*2 - 50) div LOADING_INTERLINE;
7591 if len < 1 then len := 1;
7592 SetLength(Msgs, len);
7593 for len := Low(Msgs) to High(Msgs) do
7594 Msgs[len] := '';
7595 NextMsg := 0;
7596 PBarWasHere := false;
7597 end;
7598 end;
7600 procedure Parse_Params(var pars: TParamStrValues);
7601 var
7602 i: Integer;
7603 s: String;
7604 begin
7605 SetLength(pars, 0);
7606 i := 1;
7607 while i <= ParamCount do
7608 begin
7609 s := ParamStr(i);
7610 if (s[1] = '-') and (Length(s) > 1) then
7611 begin
7612 if (s[2] = '-') and (Length(s) > 2) then
7613 begin // Îäèíî÷íûé ïàðàìåòð
7614 SetLength(pars, Length(pars) + 1);
7615 with pars[High(pars)] do
7616 begin
7617 Name := LowerCase(s);
7618 Value := '+';
7619 end;
7620 end
7621 else
7622 if (i < ParamCount) then
7623 begin // Ïàðàìåòð ñî çíà÷åíèåì
7624 Inc(i);
7625 SetLength(pars, Length(pars) + 1);
7626 with pars[High(pars)] do
7627 begin
7628 Name := LowerCase(s);
7629 Value := LowerCase(ParamStr(i));
7630 end;
7631 end;
7632 end;
7634 Inc(i);
7635 end;
7636 end;
7638 function Find_Param_Value(var pars: TParamStrValues; aName: String): String;
7639 var
7640 i: Integer;
7641 begin
7642 Result := '';
7643 for i := 0 to High(pars) do
7644 if pars[i].Name = aName then
7645 begin
7646 Result := pars[i].Value;
7647 Break;
7648 end;
7649 end;
7651 procedure g_Game_Process_Params();
7652 var
7653 pars: TParamStrValues;
7654 map: String;
7655 GMode, n: Byte;
7656 LimT, LimS: Integer;
7657 Opt: LongWord;
7658 Lives: Integer;
7659 s: String;
7660 Port: Integer;
7661 ip: String;
7662 F: TextFile;
7663 begin
7664 Parse_Params(pars);
7666 // Debug mode:
7667 s := Find_Param_Value(pars, '--debug');
7668 if (s <> '') then
7669 begin
7670 g_Game_SetDebugMode();
7671 s := Find_Param_Value(pars, '--netdump');
7672 if (s <> '') then
7673 NetDump := True;
7674 end;
7676 // Connect when game loads
7677 ip := Find_Param_Value(pars, '-connect');
7679 if ip <> '' then
7680 begin
7681 s := Find_Param_Value(pars, '-port');
7682 if (s = '') or not TryStrToInt(s, Port) then
7683 Port := 25666;
7685 s := Find_Param_Value(pars, '-pw');
7687 g_Game_StartClient(ip, Port, s);
7688 Exit;
7689 end;
7691 s := LowerCase(Find_Param_Value(pars, '-dbg-mainwad'));
7692 if (s <> '') then
7693 begin
7694 gDefaultMegawadStart := s;
7695 end;
7697 if (Find_Param_Value(pars, '--dbg-mainwad-restore') <> '') or
7698 (Find_Param_Value(pars, '--dbg-mainwad-default') <> '') then
7699 begin
7700 gDefaultMegawadStart := DF_Default_Megawad_Start;
7701 end;
7703 // Start map when game loads:
7704 map := LowerCase(Find_Param_Value(pars, '-map'));
7705 if isWadPath(map) then
7706 begin
7707 // Game mode:
7708 s := Find_Param_Value(pars, '-gm');
7709 GMode := g_Game_TextToMode(s);
7710 if GMode = GM_NONE then GMode := GM_DM;
7711 if GMode = GM_SINGLE then GMode := GM_COOP;
7713 // Time limit:
7714 s := Find_Param_Value(pars, '-limt');
7715 if (s = '') or (not TryStrToInt(s, LimT)) then
7716 LimT := 0;
7717 if LimT < 0 then
7718 LimT := 0;
7720 // Goal limit:
7721 s := Find_Param_Value(pars, '-lims');
7722 if (s = '') or (not TryStrToInt(s, LimS)) then
7723 LimS := 0;
7724 if LimS < 0 then
7725 LimS := 0;
7727 // Lives limit:
7728 s := Find_Param_Value(pars, '-lives');
7729 if (s = '') or (not TryStrToInt(s, Lives)) then
7730 Lives := 0;
7731 if Lives < 0 then
7732 Lives := 0;
7734 // Options:
7735 s := Find_Param_Value(pars, '-opt');
7736 if (s = '') then
7737 Opt := GAME_OPTION_ALLOWEXIT or GAME_OPTION_BOTVSPLAYER or GAME_OPTION_BOTVSMONSTER
7738 else
7739 Opt := StrToIntDef(s, 0);
7740 if Opt = 0 then
7741 Opt := GAME_OPTION_ALLOWEXIT or GAME_OPTION_BOTVSPLAYER or GAME_OPTION_BOTVSMONSTER;
7743 // Close after map:
7744 s := Find_Param_Value(pars, '--close');
7745 if (s <> '') then
7746 gMapOnce := True;
7748 // Override map to test:
7749 s := LowerCase(Find_Param_Value(pars, '-testmap'));
7750 if s <> '' then
7751 gTestMap := MapsDir + s;
7753 // Delete test map after play:
7754 s := Find_Param_Value(pars, '--testdelete');
7755 if (s <> '') then
7756 begin
7757 gMapToDelete := MapsDir + map;
7758 e_WriteLog('"--testdelete" is deprecated, use --tempdelete.', TMsgType.Fatal);
7759 Halt(1);
7760 end;
7762 // Delete temporary WAD after play:
7763 s := Find_Param_Value(pars, '--tempdelete');
7764 if (s <> '') and (gTestMap <> '') then
7765 begin
7766 gMapToDelete := gTestMap;
7767 gTempDelete := True;
7768 end;
7770 // Number of players:
7771 s := Find_Param_Value(pars, '-pl');
7772 if (s = '') then
7773 n := 1
7774 else
7775 n := StrToIntDef(s, 1);
7777 // Start:
7778 s := Find_Param_Value(pars, '-port');
7779 if (s = '') or not TryStrToInt(s, Port) then
7780 g_Game_StartCustom(map, GMode, LimT, LimS, Lives, Opt, n)
7781 else
7782 g_Game_StartServer(map, GMode, LimT, LimS, Lives, Opt, n, 0, Port);
7783 end;
7785 // Execute script when game loads:
7786 s := Find_Param_Value(pars, '-exec');
7787 if s <> '' then
7788 begin
7789 if not isWadPath(s) then
7790 s := GameDir + '/' + s;
7792 {$I-}
7793 AssignFile(F, s);
7794 Reset(F);
7795 if IOResult <> 0 then
7796 begin
7797 e_WriteLog(Format(_lc[I_SIMPLE_ERROR], ['Failed to read file: ' + s]), TMsgType.Warning);
7798 g_Console_Add(Format(_lc[I_CONSOLE_ERROR_READ], [s]));
7799 CloseFile(F);
7800 Exit;
7801 end;
7802 e_WriteLog('Executing script: ' + s, TMsgType.Notify);
7803 g_Console_Add(Format(_lc[I_CONSOLE_EXEC], [s]));
7805 while not EOF(F) do
7806 begin
7807 ReadLn(F, s);
7808 if IOResult <> 0 then
7809 begin
7810 e_WriteLog(Format(_lc[I_SIMPLE_ERROR], ['Failed to read file: ' + s]), TMsgType.Warning);
7811 g_Console_Add(Format(_lc[I_CONSOLE_ERROR_READ], [s]));
7812 CloseFile(F);
7813 Exit;
7814 end;
7815 if Pos('#', s) <> 1 then // script comment
7816 g_Console_Process(s, True);
7817 end;
7819 CloseFile(F);
7820 {$I+}
7821 end;
7823 SetLength(pars, 0);
7824 end;
7826 begin
7827 conRegVar('pf_draw_frame', @g_profile_frame_draw, 'draw frame rendering profiles', 'render profiles');
7828 //conRegVar('pf_update_frame', @g_profile_frame_update, 'draw frame updating profiles', 'update profiles');
7829 conRegVar('pf_coldet', @g_profile_collision, 'draw collision detection profiles', 'coldet profiles');
7830 conRegVar('pf_los', @g_profile_los, 'draw monster LOS profiles', 'monster LOS profiles');
7832 conRegVar('r_sq_draw', @gdbg_map_use_accel_render, 'accelerated spatial queries in rendering', 'accelerated rendering');
7833 conRegVar('cd_sq_enabled', @gdbg_map_use_accel_coldet, 'accelerated spatial queries in map coldet', 'accelerated map coldet');
7834 conRegVar('mon_sq_enabled', @gmon_debug_use_sqaccel, 'accelerated spatial queries for monsters', 'accelerated monster coldet');
7835 conRegVar('wtrace_sq_enabled', @gwep_debug_fast_trace, 'accelerated spatial queries for weapon hitscan trace', 'accelerated weapon hitscan');
7837 conRegVar('pr_enabled', @gpart_dbg_enabled, 'enable/disable particles', 'particles');
7838 conRegVar('pr_phys_enabled', @gpart_dbg_phys_enabled, 'enable/disable particle physics', 'particle physics');
7840 conRegVar('los_enabled', @gmon_dbg_los_enabled, 'enable/disable monster LOS calculations', 'monster LOS', true);
7841 conRegVar('mon_think', @gmon_debug_think, 'enable/disable monster thinking', 'monster thinking', true);
7843 {$IFDEF ENABLE_HOLMES}
7844 conRegVar('dbg_holmes', @g_holmes_enabled, 'enable/disable Holmes', 'Holmes', true);
7845 {$ENDIF}
7847 conRegVar('dbg_ignore_level_bounds', @g_dbg_ignore_bounds, 'ignore level bounds', '', false);
7849 conRegVar('r_scale', @g_dbg_scale, 0.01, 100.0, 'render scale', '', false);
7851 conRegVar('light_enabled', @gwin_k8_enable_light_experiments, 'enable/disable dynamic lighting', 'lighting');
7852 conRegVar('light_player_halo', @g_playerLight, 'enable/disable player halo', 'player light halo');
7854 conRegVar('r_smallmap_align_h', @r_smallmap_h, 'halign: 0: left; 1: center; 2: right', 'horizontal aligning of small maps');
7855 conRegVar('r_smallmap_align_v', @r_smallmap_v, 'valign: 0: top; 1: center; 2: bottom', 'vertial aligning of small maps');
7857 conRegVar('r_showfps', @gShowFPS, 'draw fps counter', 'draw fps counter');
7858 end.