DEADSOFTWARE

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