DEADSOFTWARE

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