DEADSOFTWARE

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