DEADSOFTWARE

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