DEADSOFTWARE

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