DEADSOFTWARE

game: do not use absolute path in wad selection widgets (it looks ugly, and [almost...
[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 function g_Game_ClientWAD (NewWAD: String; const WHash: TMD5Digest): AnsiString;
105 procedure g_Game_SaveOptions();
106 function g_Game_StartMap(asMegawad: Boolean; 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, e_res, 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: AnsiString;
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(WAD);
774 w := TWADFile.Create();
775 w.ReadFile(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 TEXTUREFILTER := GL_LINEAR;
815 s := e_GetResourcePath(WadDirs, MegaWAD.endpic, WAD);
816 g_Texture_CreateWADEx('TEXTURE_endpic', s);
817 TEXTUREFILTER := GL_NEAREST;
818 end;
819 MegaWAD.endmus := cfg.ReadStr('megawad', 'endmus', 'Standart.wad:D2DMUS\ÊÎÍÅÖ');
820 if MegaWAD.endmus <> '' then
821 begin
822 s := e_GetResourcePath(WadDirs, MegaWAD.endmus, WAD);
823 g_Sound_CreateWADEx('MUSIC_endmus', s, True);
824 end;
826 cfg.Free();
827 FreeMem(p);
828 w.Free();
829 end;
831 {procedure start_trigger(t: string);
832 begin
833 end;
835 function next_trigger(): Boolean;
836 begin
837 end;}
839 procedure DisableCheats();
840 begin
841 MAX_RUNVEL := 8;
842 VEL_JUMP := 10;
843 gFly := False;
845 if gPlayer1 <> nil then gPlayer1.GodMode := False;
846 if gPlayer2 <> nil then gPlayer2.GodMode := False;
847 if gPlayer1 <> nil then gPlayer1.NoTarget := False;
848 if gPlayer2 <> nil then gPlayer2.NoTarget := False;
850 {$IF DEFINED(D2F_DEBUG)}
851 if gPlayer1 <> nil then gPlayer1.NoTarget := True;
852 gAimLine := g_dbg_aimline_on;
853 {$ENDIF}
854 end;
856 procedure g_Game_ExecuteEvent(Name: String);
857 var
858 a: Integer;
859 begin
860 if Name = '' then
861 Exit;
862 if gEvents = nil then
863 Exit;
864 for a := 0 to High(gEvents) do
865 if gEvents[a].Name = Name then
866 begin
867 if gEvents[a].Command <> '' then
868 g_Console_Process(gEvents[a].Command, True);
869 break;
870 end;
871 end;
873 function g_Game_DelayEvent(DEType: Byte; Time: LongWord; Num: Integer = 0; Str: String = ''): Integer;
874 var
875 a, n: Integer;
876 begin
877 n := -1;
878 if gDelayedEvents <> nil then
879 for a := 0 to High(gDelayedEvents) do
880 if not gDelayedEvents[a].Pending then
881 begin
882 n := a;
883 break;
884 end;
885 if n = -1 then
886 begin
887 SetLength(gDelayedEvents, Length(gDelayedEvents) + 1);
888 n := High(gDelayedEvents);
889 end;
890 gDelayedEvents[n].Pending := True;
891 gDelayedEvents[n].DEType := DEType;
892 gDelayedEvents[n].DENum := Num;
893 gDelayedEvents[n].DEStr := Str;
894 if DEType = DE_GLOBEVENT then
895 gDelayedEvents[n].Time := (sys_GetTicks() {div 1000}) + Time
896 else
897 gDelayedEvents[n].Time := gTime + Time;
898 Result := n;
899 end;
901 procedure EndGame();
902 var
903 a: Integer;
904 FileName: string;
905 begin
906 if g_Game_IsNet and g_Game_IsServer then
907 MH_SEND_GameEvent(NET_EV_MAPEND, Byte(gMissionFailed));
909 // Ñòîï èãðà:
910 gPauseMain := false;
911 gPauseHolmes := false;
912 gGameOn := false;
914 g_Game_StopAllSounds(False);
916 MessageTime := 0;
917 MessageText := '';
919 EndingGameCounter := 0;
920 g_ActiveWindow := nil;
922 gLMSRespawn := LMS_RESPAWN_NONE;
923 gLMSRespawnTime := 0;
925 case gExit of
926 EXIT_SIMPLE: // Âûõîä ÷åðåç ìåíþ èëè êîíåö òåñòà
927 begin
928 g_Game_Free();
930 if gMapOnce then
931 begin // Ýòî áûë òåñò
932 g_Game_Quit();
933 end
934 else
935 begin // Âûõîä â ãëàâíîå ìåíþ
936 gMusic.SetByName('MUSIC_MENU');
937 gMusic.Play();
938 if gState <> STATE_SLIST then
939 begin
940 g_GUI_ShowWindow('MainMenu');
941 gState := STATE_MENU;
942 end else
943 begin
944 // Îáíîâëÿåì ñïèñîê ñåðâåðîâ
945 slReturnPressed := True;
946 if g_Net_Slist_Fetch(slCurrent) then
947 begin
948 if slCurrent = nil then
949 slWaitStr := _lc[I_NET_SLIST_NOSERVERS];
950 end
951 else
952 slWaitStr := _lc[I_NET_SLIST_ERROR];
953 g_Serverlist_GenerateTable(slCurrent, slTable);
954 end;
956 g_Game_ExecuteEvent('ongameend');
957 end;
958 end;
960 EXIT_RESTART: // Íà÷àòü óðîâåíü ñíà÷àëà
961 begin
962 if not g_Game_IsClient then g_Game_Restart();
963 end;
965 EXIT_ENDLEVELCUSTOM: // Çàêîí÷èëñÿ óðîâåíü â Ñâîåé èãðå
966 begin
967 // Ñòàòèñòèêà Ñâîåé èãðû:
968 FileName := g_ExtractWadName(gMapInfo.Map);
970 CustomStat.GameTime := gTime;
971 CustomStat.Map := ExtractFileName(FileName)+':'+g_ExtractFileName(gMapInfo.Map); //ResName;
972 CustomStat.MapName := gMapInfo.Name;
973 CustomStat.GameMode := gGameSettings.GameMode;
974 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
975 CustomStat.TeamStat := gTeamStat;
977 CustomStat.PlayerStat := nil;
979 // Ñòàòèñòèêà èãðîêîâ:
980 if gPlayers <> nil then
981 begin
982 for a := 0 to High(gPlayers) do
983 if gPlayers[a] <> nil then
984 begin
985 SetLength(CustomStat.PlayerStat, Length(CustomStat.PlayerStat)+1);
986 with CustomStat.PlayerStat[High(CustomStat.PlayerStat)] do
987 begin
988 Num := a;
989 Name := gPlayers[a].Name;
990 Frags := gPlayers[a].Frags;
991 Deaths := gPlayers[a].Death;
992 Kills := gPlayers[a].Kills;
993 Team := gPlayers[a].Team;
994 Color := gPlayers[a].Model.Color;
995 Spectator := gPlayers[a].FSpectator;
996 end;
997 end;
999 SortGameStat(CustomStat.PlayerStat);
1000 end;
1002 g_Game_ExecuteEvent('onmapend');
1003 if not g_Game_IsClient then g_Player_ResetReady;
1004 gInterReadyCount := 0;
1006 // Çàòóõàþùèé ýêðàí:
1007 EndingGameCounter := 255;
1008 gState := STATE_FOLD;
1009 gInterTime := 0;
1010 if gDefInterTime < 0 then
1011 gInterEndTime := IfThen((gGameSettings.GameType = GT_SERVER) and (gPlayer1 = nil), 15000, 25000)
1012 else
1013 gInterEndTime := gDefInterTime * 1000;
1014 end;
1016 EXIT_ENDLEVELSINGLE: // Çàêîí÷èëñÿ óðîâåíü â Îäèíî÷íîé èãðå
1017 begin
1018 // Ñòàòèñòèêà Îäèíî÷íîé èãðû:
1019 SingleStat.GameTime := gTime;
1020 SingleStat.TwoPlayers := gPlayer2 <> nil;
1021 SingleStat.TotalSecrets := gSecretsCount;
1022 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
1023 SingleStat.PlayerStat[0].Kills := gPlayer1.MonsterKills;
1024 SingleStat.PlayerStat[0].Secrets := gPlayer1.Secrets;
1025 // Ñòàòèñòèêà âòîðîãî èãðîêà (åñëè åñòü):
1026 if SingleStat.TwoPlayers then
1027 begin
1028 SingleStat.PlayerStat[1].Kills := gPlayer2.MonsterKills;
1029 SingleStat.PlayerStat[1].Secrets := gPlayer2.Secrets;
1030 end;
1032 g_Game_ExecuteEvent('onmapend');
1034 // Åñòü åùå êàðòû:
1035 if gNextMap <> '' then
1036 begin
1037 gMusic.SetByName('MUSIC_INTERMUS');
1038 gMusic.Play();
1039 gState := STATE_INTERSINGLE;
1040 e_UnpressAllKeys();
1042 g_Game_ExecuteEvent('oninter');
1043 end
1044 else // Áîëüøå íåò êàðò
1045 begin
1046 // Çàòóõàþùèé ýêðàí:
1047 EndingGameCounter := 255;
1048 gState := STATE_FOLD;
1049 end;
1050 end;
1051 end;
1053 // Îêîí÷àíèå îáðàáîòàíî:
1054 if gExit <> EXIT_QUIT then
1055 gExit := 0;
1056 end;
1058 procedure drawTime(X, Y: Integer); inline;
1059 begin
1060 e_TextureFontPrint(x, y,
1061 Format('%d:%.2d:%.2d', [
1062 gTime div 1000 div 3600,
1063 (gTime div 1000 div 60) mod 60,
1064 gTime div 1000 mod 60
1065 ]),
1066 gStdFont);
1067 end;
1069 procedure DrawStat();
1070 var
1071 pc, x, y, w, h: Integer;
1072 w1, w2, w3, w4: Integer;
1073 a, aa: Integer;
1074 cw, ch, r, g, b, rr, gg, bb: Byte;
1075 s1, s2, s3: String;
1076 _y: Integer;
1077 stat: TPlayerStatArray;
1078 wad, map: string;
1079 mapstr: string;
1080 begin
1081 s1 := '';
1082 s2 := '';
1083 s3 := '';
1084 pc := g_Player_GetCount;
1085 e_TextureFontGetSize(gStdFont, cw, ch);
1087 w := gScreenWidth-(gScreenWidth div 5);
1088 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
1089 h := 32+ch*(11+pc)
1090 else
1091 h := 40+ch*5+(ch+8)*pc;
1092 x := (gScreenWidth div 2)-(w div 2);
1093 y := (gScreenHeight div 2)-(h div 2);
1095 e_DrawFillQuad(x, y, x+w-1, y+h-1, 64, 64, 64, 32);
1096 e_DrawQuad(x, y, x+w-1, y+h-1, 255, 127, 0);
1098 drawTime(x+w-78, y+8);
1100 wad := g_ExtractWadNameNoPath(gMapInfo.Map);
1101 map := g_ExtractFileName(gMapInfo.Map);
1102 mapstr := wad + ':\' + map + ' - ' + gMapInfo.Name;
1104 case gGameSettings.GameMode of
1105 GM_DM:
1106 begin
1107 if gGameSettings.MaxLives = 0 then
1108 s1 := _lc[I_GAME_DM]
1109 else
1110 s1 := _lc[I_GAME_LMS];
1111 s2 := Format(_lc[I_GAME_FRAG_LIMIT], [gGameSettings.GoalLimit]);
1112 s3 := Format(_lc[I_GAME_TIME_LIMIT], [gGameSettings.TimeLimit div 3600, (gGameSettings.TimeLimit div 60) mod 60, gGameSettings.TimeLimit mod 60]);
1113 end;
1115 GM_TDM:
1116 begin
1117 if gGameSettings.MaxLives = 0 then
1118 s1 := _lc[I_GAME_TDM]
1119 else
1120 s1 := _lc[I_GAME_TLMS];
1121 s2 := Format(_lc[I_GAME_FRAG_LIMIT], [gGameSettings.GoalLimit]);
1122 s3 := Format(_lc[I_GAME_TIME_LIMIT], [gGameSettings.TimeLimit div 3600, (gGameSettings.TimeLimit div 60) mod 60, gGameSettings.TimeLimit mod 60]);
1123 end;
1125 GM_CTF:
1126 begin
1127 s1 := _lc[I_GAME_CTF];
1128 s2 := Format(_lc[I_GAME_SCORE_LIMIT], [gGameSettings.GoalLimit]);
1129 s3 := Format(_lc[I_GAME_TIME_LIMIT], [gGameSettings.TimeLimit div 3600, (gGameSettings.TimeLimit div 60) mod 60, gGameSettings.TimeLimit mod 60]);
1130 end;
1132 GM_COOP:
1133 begin
1134 if gGameSettings.MaxLives = 0 then
1135 s1 := _lc[I_GAME_COOP]
1136 else
1137 s1 := _lc[I_GAME_SURV];
1138 s2 := _lc[I_GAME_MONSTERS] + ' ' + IntToStr(gCoopMonstersKilled) + '/' + IntToStr(gTotalMonsters);
1139 s3 := _lc[I_GAME_SECRETS] + ' ' + IntToStr(gCoopSecretsFound) + '/' + IntToStr(gSecretsCount);
1140 end;
1142 else
1143 begin
1144 s1 := '';
1145 s2 := '';
1146 end;
1147 end;
1149 _y := y+8;
1150 e_TextureFontPrintEx(x+(w div 2)-(Length(s1)*cw div 2), _y, s1, gStdFont, 255, 255, 255, 1);
1151 _y := _y+ch+8;
1152 e_TextureFontPrintEx(x+(w div 2)-(Length(mapstr)*cw div 2), _y, mapstr, gStdFont, 200, 200, 200, 1);
1153 _y := _y+ch+8;
1154 e_TextureFontPrintEx(x+16, _y, s2, gStdFont, 200, 200, 200, 1);
1156 e_TextureFontPrintEx(x+w-16-(Length(s3))*cw, _y, s3,
1157 gStdFont, 200, 200, 200, 1);
1159 if NetMode = NET_SERVER then
1160 e_TextureFontPrintEx(x+8, y + 8, _lc[I_NET_SERVER], gStdFont, 255, 255, 255, 1)
1161 else
1162 if NetMode = NET_CLIENT then
1163 e_TextureFontPrintEx(x+8, y + 8,
1164 NetClientIP + ':' + IntToStr(NetClientPort), gStdFont, 255, 255, 255, 1);
1166 if pc = 0 then
1167 Exit;
1168 stat := g_Player_GetStats();
1169 SortGameStat(stat);
1171 w2 := (w-16) div 6 + 48; // øèðèíà 2 ñòîëáöà
1172 w3 := (w-16) div 6; // øèðèíà 3 è 4 ñòîëáöîâ
1173 w4 := w3;
1174 w1 := w-16-w2-w3-w4; // îñòàâøååñÿ ïðîñòðàíñòâî - äëÿ öâåòà è èìåíè èãðîêà
1176 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
1177 begin
1178 _y := _y+ch+ch;
1180 for a := TEAM_RED to TEAM_BLUE do
1181 begin
1182 if a = TEAM_RED then
1183 begin
1184 s1 := _lc[I_GAME_TEAM_RED];
1185 r := 255;
1186 g := 0;
1187 b := 0;
1188 end
1189 else
1190 begin
1191 s1 := _lc[I_GAME_TEAM_BLUE];
1192 r := 0;
1193 g := 0;
1194 b := 255;
1195 end;
1197 e_TextureFontPrintEx(x+16, _y, s1, gStdFont, r, g, b, 1);
1198 e_TextureFontPrintEx(x+w1+16, _y, IntToStr(gTeamStat[a].Goals),
1199 gStdFont, r, g, b, 1);
1201 _y := _y+ch+(ch div 4);
1202 e_DrawLine(1, x+16, _y, x+w-16, _y, r, g, b);
1203 _y := _y+(ch div 4);
1205 for aa := 0 to High(stat) do
1206 if stat[aa].Team = a then
1207 with stat[aa] do
1208 begin
1209 if Spectator then
1210 begin
1211 rr := r div 2;
1212 gg := g div 2;
1213 bb := b div 2;
1214 end
1215 else
1216 begin
1217 rr := r;
1218 gg := g;
1219 bb := b;
1220 end;
1221 // Èìÿ
1222 e_TextureFontPrintEx(x+16, _y, Name, gStdFont, rr, gg, bb, 1);
1223 // Ïèíã/ïîòåðè
1224 e_TextureFontPrintEx(x+w1+16, _y, Format(_lc[I_GAME_PING_MS], [Ping, Loss]), gStdFont, rr, gg, bb, 1);
1225 // Ôðàãè
1226 e_TextureFontPrintEx(x+w1+w2+16, _y, IntToStr(Frags), gStdFont, rr, gg, bb, 1);
1227 // Ñìåðòè
1228 e_TextureFontPrintEx(x+w1+w2+w3+16, _y, IntToStr(Deaths), gStdFont, rr, gg, bb, 1);
1229 _y := _y+ch;
1230 end;
1232 _y := _y+ch;
1233 end;
1234 end
1235 else if gGameSettings.GameMode in [GM_DM, GM_COOP] then
1236 begin
1237 _y := _y+ch+ch;
1238 e_TextureFontPrintEx(x+16, _y, _lc[I_GAME_PLAYER_NAME], gStdFont, 255, 127, 0, 1);
1239 e_TextureFontPrintEx(x+16+w1, _y, _lc[I_GAME_PING], gStdFont, 255, 127, 0, 1);
1240 e_TextureFontPrintEx(x+16+w1+w2, _y, _lc[I_GAME_FRAGS], gStdFont, 255, 127, 0, 1);
1241 e_TextureFontPrintEx(x+16+w1+w2+w3, _y, _lc[I_GAME_DEATHS], gStdFont, 255, 127, 0, 1);
1243 _y := _y+ch+8;
1244 for aa := 0 to High(stat) do
1245 with stat[aa] do
1246 begin
1247 if Spectator then
1248 begin
1249 r := 127;
1250 g := 64;
1251 end
1252 else
1253 begin
1254 r := 255;
1255 g := 127;
1256 end;
1257 // Öâåò èãðîêà
1258 e_DrawFillQuad(x+16, _y+4, x+32-1, _y+16+4-1, Color.R, Color.G, Color.B, 0);
1259 e_DrawQuad(x+16, _y+4, x+32-1, _y+16+4-1, 192, 192, 192);
1260 // Èìÿ
1261 e_TextureFontPrintEx(x+16+16+8, _y+4, Name, gStdFont, r, g, 0, 1);
1262 // Ïèíã/ïîòåðè
1263 e_TextureFontPrintEx(x+w1+16, _y+4, Format(_lc[I_GAME_PING_MS], [Ping, Loss]), gStdFont, r, g, 0, 1);
1264 // Ôðàãè
1265 e_TextureFontPrintEx(x+w1+w2+16, _y+4, IntToStr(Frags), gStdFont, r, g, 0, 1);
1266 // Ñìåðòè
1267 e_TextureFontPrintEx(x+w1+w2+w3+16, _y+4, IntToStr(Deaths), gStdFont, r, g, 0, 1);
1268 _y := _y+ch+8;
1269 end;
1270 end
1271 end;
1273 procedure g_Game_Init();
1274 var
1275 SR: TSearchRec;
1276 knownFiles: array of AnsiString = nil;
1277 found: Boolean;
1278 wext, s: AnsiString;
1279 f: Integer;
1280 begin
1281 gExit := 0;
1282 gMapToDelete := '';
1283 gTempDelete := False;
1285 sfsGCDisable(); // temporary disable removing of temporary volumes
1287 try
1288 TEXTUREFILTER := GL_LINEAR;
1289 g_Texture_CreateWADEx('MENU_BACKGROUND', GameWAD+':TEXTURES\TITLE');
1290 g_Texture_CreateWADEx('INTER', GameWAD+':TEXTURES\INTER');
1291 g_Texture_CreateWADEx('ENDGAME_EN', GameWAD+':TEXTURES\ENDGAME_EN');
1292 g_Texture_CreateWADEx('ENDGAME_RU', GameWAD+':TEXTURES\ENDGAME_RU');
1293 TEXTUREFILTER := GL_NEAREST;
1295 LoadStdFont('STDTXT', 'STDFONT', gStdFont);
1296 LoadFont('MENUTXT', 'MENUFONT', gMenuFont);
1297 LoadFont('SMALLTXT', 'SMALLFONT', gMenuSmallFont);
1299 g_Game_ClearLoading();
1300 g_Game_SetLoadingText(Format('Doom 2D: Forever %s', [GAME_VERSION]), 0, False);
1301 g_Game_SetLoadingText('', 0, False);
1303 g_Game_SetLoadingText(_lc[I_LOAD_CONSOLE], 0, False);
1304 g_Console_Init();
1306 g_Game_SetLoadingText(_lc[I_LOAD_MODELS], 0, False);
1307 g_PlayerModel_LoadData();
1309 // load models from all possible wad types, in all known directories
1310 // this does a loosy job (linear search, ooph!), but meh
1311 for wext in wadExtensions do
1312 begin
1313 for f := High(ModelDirs) downto Low(ModelDirs) do
1314 begin
1315 if (FindFirst(ModelDirs[f]+DirectorySeparator+'*'+wext, faAnyFile, SR) = 0) then
1316 begin
1317 repeat
1318 found := false;
1319 for s in knownFiles do
1320 begin
1321 if (strEquCI1251(forceFilenameExt(SR.Name, ''), forceFilenameExt(ExtractFileName(s), ''))) then
1322 begin
1323 found := true;
1324 break;
1325 end;
1326 end;
1327 if not found then
1328 begin
1329 SetLength(knownFiles, length(knownFiles)+1);
1330 knownFiles[High(knownFiles)] := ModelDirs[f]+DirectorySeparator+SR.Name;
1331 end;
1332 until (FindNext(SR) <> 0);
1333 end;
1334 FindClose(SR);
1335 end;
1336 end;
1338 if (length(knownFiles) = 0) then raise Exception.Create('no player models found!');
1340 if (length(knownFiles) = 1) then e_LogWriteln('1 player model found.', TMsgType.Notify) else e_LogWritefln('%d player models found.', [Integer(length(knownFiles))], TMsgType.Notify);
1341 for s in knownFiles do
1342 begin
1343 if not g_PlayerModel_Load(s) then e_LogWritefln('Error loading model "%s"', [s], TMsgType.Warning);
1344 end;
1346 gGameOn := false;
1347 gPauseMain := false;
1348 gPauseHolmes := false;
1349 gTime := 0;
1351 {e_MouseInfo.Accel := 1.0;}
1353 g_Game_SetLoadingText(_lc[I_LOAD_GAME_DATA], 0, False);
1354 g_Game_LoadData();
1356 g_Game_SetLoadingText(_lc[I_LOAD_MUSIC], 0, False);
1357 g_Sound_CreateWADEx('MUSIC_INTERMUS', GameWAD+':MUSIC\INTERMUS', True);
1358 g_Sound_CreateWADEx('MUSIC_MENU', GameWAD+':MUSIC\MENU', True);
1359 g_Sound_CreateWADEx('MUSIC_ROUNDMUS', GameWAD+':MUSIC\ROUNDMUS', True, True);
1360 g_Sound_CreateWADEx('MUSIC_STDENDMUS', GameWAD+':MUSIC\ENDMUS', True);
1362 {$IFNDEF HEADLESS}
1363 g_Game_SetLoadingText(_lc[I_LOAD_MENUS], 0, False);
1364 g_Menu_Init();
1365 {$ENDIF}
1367 gMusic := TMusic.Create();
1368 gMusic.SetByName('MUSIC_MENU');
1369 gMusic.Play();
1371 gGameSettings.WarmupTime := 30;
1373 gState := STATE_MENU;
1375 SetLength(gEvents, 6);
1376 gEvents[0].Name := 'ongamestart';
1377 gEvents[1].Name := 'ongameend';
1378 gEvents[2].Name := 'onmapstart';
1379 gEvents[3].Name := 'onmapend';
1380 gEvents[4].Name := 'oninter';
1381 gEvents[5].Name := 'onwadend';
1382 finally
1383 sfsGCEnable(); // enable releasing unused volumes
1384 end;
1385 end;
1387 procedure g_Game_Free(freeTextures: Boolean=true);
1388 begin
1389 if NetMode = NET_CLIENT then g_Net_Disconnect();
1390 if NetMode = NET_SERVER then g_Net_Host_Die();
1392 g_Map_Free(freeTextures);
1393 g_Player_Free();
1394 g_Player_RemoveAllCorpses();
1396 gGameSettings.GameType := GT_NONE;
1397 if gGameSettings.GameMode = GM_SINGLE then
1398 gGameSettings.GameMode := GM_DM;
1399 gSwitchGameMode := gGameSettings.GameMode;
1401 gChatShow := False;
1402 gExitByTrigger := False;
1403 end;
1405 function IsActivePlayer(p: TPlayer): Boolean;
1406 begin
1407 Result := False;
1408 if p = nil then
1409 Exit;
1410 Result := (not p.FDummy) and (not p.FSpectator);
1411 end;
1413 function GetActivePlayer_ByID(ID: Integer): TPlayer;
1414 var
1415 a: Integer;
1416 begin
1417 Result := nil;
1418 if ID < 0 then
1419 Exit;
1420 if gPlayers = nil then
1421 Exit;
1422 for a := Low(gPlayers) to High(gPlayers) do
1423 if IsActivePlayer(gPlayers[a]) then
1424 begin
1425 if gPlayers[a].UID <> ID then
1426 continue;
1427 Result := gPlayers[a];
1428 break;
1429 end;
1430 end;
1432 function GetActivePlayerID_Next(Skip: Integer = -1): Integer;
1433 var
1434 a, idx: Integer;
1435 ids: Array of Word;
1436 begin
1437 Result := -1;
1438 if gPlayers = nil then
1439 Exit;
1440 SetLength(ids, 0);
1441 idx := -1;
1442 for a := Low(gPlayers) to High(gPlayers) do
1443 if IsActivePlayer(gPlayers[a]) then
1444 begin
1445 SetLength(ids, Length(ids) + 1);
1446 ids[High(ids)] := gPlayers[a].UID;
1447 if gPlayers[a].UID = Skip then
1448 idx := High(ids);
1449 end;
1450 if Length(ids) = 0 then
1451 Exit;
1452 if idx = -1 then
1453 Result := ids[0]
1454 else
1455 Result := ids[(idx + 1) mod Length(ids)];
1456 end;
1458 function GetActivePlayerID_Prev(Skip: Integer = -1): Integer;
1459 var
1460 a, idx: Integer;
1461 ids: Array of Word;
1462 begin
1463 Result := -1;
1464 if gPlayers = nil then
1465 Exit;
1466 SetLength(ids, 0);
1467 idx := -1;
1468 for a := Low(gPlayers) to High(gPlayers) do
1469 if IsActivePlayer(gPlayers[a]) then
1470 begin
1471 SetLength(ids, Length(ids) + 1);
1472 ids[High(ids)] := gPlayers[a].UID;
1473 if gPlayers[a].UID = Skip then
1474 idx := High(ids);
1475 end;
1476 if Length(ids) = 0 then
1477 Exit;
1478 if idx = -1 then
1479 Result := ids[Length(ids) - 1]
1480 else
1481 Result := ids[(Length(ids) - 1 + idx) mod Length(ids)];
1482 end;
1484 function GetActivePlayerID_Random(Skip: Integer = -1): Integer;
1485 var
1486 a, idx: Integer;
1487 ids: Array of Word;
1488 begin
1489 Result := -1;
1490 if gPlayers = nil then
1491 Exit;
1492 SetLength(ids, 0);
1493 idx := -1;
1494 for a := Low(gPlayers) to High(gPlayers) do
1495 if IsActivePlayer(gPlayers[a]) then
1496 begin
1497 SetLength(ids, Length(ids) + 1);
1498 ids[High(ids)] := gPlayers[a].UID;
1499 if gPlayers[a].UID = Skip then
1500 idx := High(ids);
1501 end;
1502 if Length(ids) = 0 then
1503 Exit;
1504 if Length(ids) = 1 then
1505 begin
1506 Result := ids[0];
1507 Exit;
1508 end;
1509 Result := ids[Random(Length(ids))];
1510 a := 10;
1511 while (idx <> -1) and (Result = Skip) and (a > 0) do
1512 begin
1513 Result := ids[Random(Length(ids))];
1514 Dec(a);
1515 end;
1516 end;
1518 function GetRandomSpectMode(Current: Byte): Byte;
1519 label
1520 retry;
1521 begin
1522 Result := Current;
1523 retry:
1524 case Random(7) of
1525 0: Result := SPECT_STATS;
1526 1: Result := SPECT_MAPVIEW;
1527 2: Result := SPECT_MAPVIEW;
1528 3: Result := SPECT_PLAYERS;
1529 4: Result := SPECT_PLAYERS;
1530 5: Result := SPECT_PLAYERS;
1531 6: Result := SPECT_PLAYERS;
1532 end;
1533 if (Current in [SPECT_STATS, SPECT_MAPVIEW]) and (Current = Result) then
1534 goto retry;
1535 end;
1537 procedure ProcessPlayerControls (plr: TPlayer; p: Integer; var MoveButton: Byte);
1538 var
1539 time: Word;
1540 strafeDir: Byte;
1541 i: Integer;
1542 begin
1543 if (plr = nil) then exit;
1544 if (p = 2) then time := 1000 else time := 1;
1545 strafeDir := MoveButton shr 4;
1546 MoveButton := MoveButton and $0F;
1548 if gPlayerAction[p, ACTION_MOVELEFT] and (not gPlayerAction[p, ACTION_MOVERIGHT]) then
1549 MoveButton := 1 // Íàæàòà òîëüêî "Âëåâî"
1550 else if (not gPlayerAction[p, ACTION_MOVELEFT]) and gPlayerAction[p, ACTION_MOVERIGHT] then
1551 MoveButton := 2 // Íàæàòà òîëüêî "Âïðàâî"
1552 else if (not gPlayerAction[p, ACTION_MOVELEFT]) and (not gPlayerAction[p, ACTION_MOVERIGHT]) then
1553 MoveButton := 0; // Íå íàæàòû íè "Âëåâî", íè "Âïðàâî"
1555 // Ñåé÷àñ èëè ðàíüøå áûëè íàæàòû "Âëåâî"/"Âïðàâî" => ïåðåäàåì èãðîêó:
1556 if MoveButton = 1 then
1557 plr.PressKey(KEY_LEFT, time)
1558 else if MoveButton = 2 then
1559 plr.PressKey(KEY_RIGHT, time);
1561 // if we have "strafe" key, turn off old strafe mechanics
1562 if gPlayerAction[p, ACTION_STRAFE] then
1563 begin
1564 // new strafe mechanics
1565 if (strafeDir = 0) then
1566 strafeDir := MoveButton; // start strafing
1567 // now set direction according to strafe (reversed)
1568 if (strafeDir = 2) then
1569 plr.SetDirection(TDirection.D_LEFT)
1570 else if (strafeDir = 1) then
1571 plr.SetDirection(TDirection.D_RIGHT)
1572 end
1573 else
1574 begin
1575 strafeDir := 0; // not strafing anymore
1576 // Ðàíüøå áûëà íàæàòà "Âïðàâî", à ñåé÷àñ "Âëåâî" => áåæèì âïðàâî, ñìîòðèì âëåâî:
1577 if (MoveButton = 2) and gPlayerAction[p, ACTION_MOVELEFT] then
1578 plr.SetDirection(TDirection.D_LEFT)
1579 // Ðàíüøå áûëà íàæàòà "Âëåâî", à ñåé÷àñ "Âïðàâî" => áåæèì âëåâî, ñìîòðèì âïðàâî:
1580 else if (MoveButton = 1) and gPlayerAction[p, ACTION_MOVERIGHT] then
1581 plr.SetDirection(TDirection.D_RIGHT)
1582 // ×òî-òî áûëî íàæàòî è íå èçìåíèëîñü => êóäà áåæèì, òóäà è ñìîòðèì:
1583 else if MoveButton <> 0 then
1584 plr.SetDirection(TDirection(MoveButton-1))
1585 end;
1587 // fix movebutton state
1588 MoveButton := MoveButton or (strafeDir shl 4);
1590 // Îñòàëüíûå êëàâèøè:
1591 if gPlayerAction[p, ACTION_JUMP] then plr.PressKey(KEY_JUMP, time);
1592 if gPlayerAction[p, ACTION_LOOKUP] then plr.PressKey(KEY_UP, time);
1593 if gPlayerAction[p, ACTION_LOOKDOWN] then plr.PressKey(KEY_DOWN, time);
1594 if gPlayerAction[p, ACTION_ATTACK] then plr.PressKey(KEY_FIRE);
1595 if gPlayerAction[p, ACTION_WEAPNEXT] then plr.PressKey(KEY_NEXTWEAPON);
1596 if gPlayerAction[p, ACTION_WEAPPREV] then plr.PressKey(KEY_PREVWEAPON);
1597 if gPlayerAction[p, ACTION_ACTIVATE] then plr.PressKey(KEY_OPEN);
1599 gPlayerAction[p, ACTION_WEAPNEXT] := False; // HACK, remove after readyweaon&pendinweapon implementation
1600 gPlayerAction[p, ACTION_WEAPPREV] := False; // HACK, remove after readyweaon&pendinweapon implementation
1602 for i := WP_FIRST to WP_LAST do
1603 begin
1604 if gSelectWeapon[p, i] then
1605 begin
1606 plr.QueueWeaponSwitch(i); // all choices are passed there, and god will take the best
1607 gSelectWeapon[p, i] := False
1608 end
1609 end;
1611 // HACK: add dynlight here
1612 if gwin_k8_enable_light_experiments then
1613 begin
1614 if e_KeyPressed(IK_F8) and gGameOn and (not gConsoleShow) and (g_ActiveWindow = nil) then
1615 begin
1616 g_playerLight := true;
1617 end;
1618 if e_KeyPressed(IK_F9) and gGameOn and (not gConsoleShow) and (g_ActiveWindow = nil) then
1619 begin
1620 g_playerLight := false;
1621 end;
1622 end;
1624 if gwin_has_stencil and g_playerLight then g_AddDynLight(plr.GameX+32, plr.GameY+40, 128, 1, 1, 0, 0.6);
1625 end;
1627 // HACK: don't have a "key was pressed" function
1628 procedure InterReady();
1629 begin
1630 if InterReadyTime > gTime then Exit;
1631 InterReadyTime := gTime + 3000;
1632 MC_SEND_CheatRequest(NET_CHEAT_READY);
1633 end;
1635 procedure g_Game_Update();
1636 var
1637 Msg: g_gui.TMessage;
1638 Time: Int64;
1639 a: Byte;
1640 w: Word;
1641 i, b: Integer;
1643 function sendMonsPos (mon: TMonster): Boolean;
1644 begin
1645 result := false; // don't stop
1646 // this will also reset "need-send" flag
1647 if mon.gncNeedSend then
1648 begin
1649 MH_SEND_MonsterPos(mon.UID);
1650 end
1651 else if (mon.MonsterType = MONSTER_BARREL) then
1652 begin
1653 if (mon.GameVelX <> 0) or (mon.GameVelY <> 0) then MH_SEND_MonsterPos(mon.UID);
1654 end
1655 else if (mon.MonsterState <> MONSTATE_SLEEP) then
1656 begin
1657 if (mon.MonsterState <> MONSTATE_DEAD) or (mon.GameVelX <> 0) or (mon.GameVelY <> 0) then MH_SEND_MonsterPos(mon.UID);
1658 end;
1659 end;
1661 function sendMonsPosUnexpected (mon: TMonster): Boolean;
1662 begin
1663 result := false; // don't stop
1664 // this will also reset "need-send" flag
1665 if mon.gncNeedSend then MH_SEND_MonsterPos(mon.UID);
1666 end;
1668 var
1669 reliableUpdate: Boolean;
1670 begin
1671 g_ResetDynlights();
1672 framePool.reset();
1674 // Ïîðà âûêëþ÷àòü èãðó:
1675 if gExit = EXIT_QUIT then
1676 Exit;
1677 // Èãðà çàêîí÷èëàñü - îáðàáàòûâàåì:
1678 if gExit <> 0 then
1679 begin
1680 EndGame();
1681 if gExit = EXIT_QUIT then
1682 Exit;
1683 end;
1685 // ×èòàåì êëàâèàòóðó è äæîéñòèê, åñëè îêíî àêòèâíî
1686 // no need to, as we'll do it in event handler
1688 // Îáíîâëÿåì êîíñîëü (äâèæåíèå è ñîîáùåíèÿ):
1689 g_Console_Update();
1691 if (NetMode = NET_NONE) and (g_Game_IsNet) and (gGameOn or (gState in [STATE_FOLD, STATE_INTERCUSTOM])) then
1692 begin
1693 gExit := EXIT_SIMPLE;
1694 EndGame();
1695 Exit;
1696 end;
1698 // process master server communications
1699 g_Net_Slist_Pulse();
1701 case gState of
1702 STATE_INTERSINGLE, // Ñòàòèñòêà ïîñëå ïðîõîæäåíèÿ óðîâíÿ â Îäèíî÷íîé èãðå
1703 STATE_INTERCUSTOM, // Ñòàòèñòêà ïîñëå ïðîõîæäåíèÿ óðîâíÿ â Ñâîåé èãðå
1704 STATE_INTERTEXT, // Òåêñò ìåæäó óðîâíÿìè
1705 STATE_INTERPIC: // Êàðòèíêà ìåæäó óðîâíÿìè
1706 begin
1707 if g_Game_IsNet and g_Game_IsServer then
1708 begin
1709 gInterTime := gInterTime + GAME_TICK;
1710 a := Min((gInterEndTime - gInterTime) div 1000 + 1, 255);
1711 if a <> gServInterTime then
1712 begin
1713 gServInterTime := a;
1714 MH_SEND_TimeSync(gServInterTime);
1715 end;
1716 end;
1718 if (not g_Game_IsClient) and
1722 e_KeyPressed(IK_RETURN) or e_KeyPressed(IK_KPRETURN) or e_KeyPressed(IK_SPACE) or
1723 e_KeyPressed(VK_FIRE) or e_KeyPressed(VK_OPEN) or
1724 e_KeyPressed(JOY0_ATTACK) or e_KeyPressed(JOY1_ATTACK) or
1725 e_KeyPressed(JOY2_ATTACK) or e_KeyPressed(JOY3_ATTACK)
1727 and (not gJustChatted) and (not gConsoleShow) and (not gChatShow)
1728 and (g_ActiveWindow = nil)
1730 or (g_Game_IsNet and ((gInterTime > gInterEndTime) or (gInterReadyCount >= NetClientCount)))
1732 then
1733 begin // Íàæàëè <Enter>/<Ïðîáåë> èëè ïðîøëî äîñòàòî÷íî âðåìåíè:
1734 g_Game_StopAllSounds(True);
1736 if gMapOnce then // Ýòî áûë òåñò
1737 gExit := EXIT_SIMPLE
1738 else
1739 if gNextMap <> '' then // Ïåðåõîäèì íà ñëåäóþùóþ êàðòó
1740 g_Game_ChangeMap(gNextMap)
1741 else // Ñëåäóþùåé êàðòû íåò
1742 begin
1743 if gGameSettings.GameType in [GT_CUSTOM, GT_SERVER] then
1744 begin
1745 // Âûõîä â ãëàâíîå ìåíþ:
1746 g_Game_Free;
1747 g_GUI_ShowWindow('MainMenu');
1748 gMusic.SetByName('MUSIC_MENU');
1749 gMusic.Play();
1750 gState := STATE_MENU;
1751 end else
1752 begin
1753 // Ôèíàëüíàÿ êàðòèíêà:
1754 g_Game_ExecuteEvent('onwadend');
1755 g_Game_Free();
1756 if not gMusic.SetByName('MUSIC_endmus') then
1757 gMusic.SetByName('MUSIC_STDENDMUS');
1758 gMusic.Play();
1759 gState := STATE_ENDPIC;
1760 end;
1761 g_Game_ExecuteEvent('ongameend');
1762 end;
1764 Exit;
1765 end
1766 else if g_Game_IsClient and
1769 e_KeyPressed(IK_RETURN) or e_KeyPressed(IK_KPRETURN) or e_KeyPressed(IK_SPACE) or
1770 e_KeyPressed(VK_FIRE) or e_KeyPressed(VK_OPEN) or
1771 e_KeyPressed(JOY0_ATTACK) or e_KeyPressed(JOY1_ATTACK) or
1772 e_KeyPressed(JOY2_ATTACK) or e_KeyPressed(JOY3_ATTACK)
1774 and (not gJustChatted) and (not gConsoleShow) and (not gChatShow)
1775 and (g_ActiveWindow = nil)
1777 then
1778 begin
1779 // ready / unready
1780 InterReady();
1781 end;
1783 if gState = STATE_INTERTEXT then
1784 if InterText.counter > 0 then
1785 InterText.counter := InterText.counter - 1;
1786 end;
1788 STATE_FOLD: // Çàòóõàíèå ýêðàíà
1789 begin
1790 if EndingGameCounter = 0 then
1791 begin
1792 // Çàêîí÷èëñÿ óðîâåíü â Ñâîåé èãðå:
1793 if gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT] then
1794 begin
1795 InterReadyTime := -1;
1796 if gLastMap and (gGameSettings.GameMode = GM_COOP) then
1797 begin
1798 g_Game_ExecuteEvent('onwadend');
1799 if not gMusic.SetByName('MUSIC_endmus') then
1800 gMusic.SetByName('MUSIC_STDENDMUS');
1801 end
1802 else
1803 gMusic.SetByName('MUSIC_ROUNDMUS');
1805 gMusic.Play();
1806 gState := STATE_INTERCUSTOM;
1807 e_UnpressAllKeys();
1808 end
1809 else // Çàêîí÷èëàñü ïîñëåäíÿÿ êàðòà â Îäèíî÷íîé èãðå
1810 begin
1811 gMusic.SetByName('MUSIC_INTERMUS');
1812 gMusic.Play();
1813 gState := STATE_INTERSINGLE;
1814 e_UnpressAllKeys();
1815 end;
1816 g_Game_ExecuteEvent('oninter');
1817 end
1818 else
1819 DecMin(EndingGameCounter, 6, 0);
1820 end;
1822 STATE_ENDPIC: // Êàðòèíêà îêîí÷àíèÿ ìåãàÂàäà
1823 begin
1824 if gMapOnce then // Ýòî áûë òåñò
1825 begin
1826 gExit := EXIT_SIMPLE;
1827 Exit;
1828 end;
1829 end;
1831 STATE_SLIST:
1832 g_Serverlist_Control(slCurrent, slTable);
1833 end;
1835 // Ñòàòèñòèêà ïî Tab:
1836 if gGameOn then
1837 IsDrawStat := (not gConsoleShow) and (not gChatShow) and (gGameSettings.GameType <> GT_SINGLE) and g_Console_Action(ACTION_SCORES);
1839 // Èãðà èäåò:
1840 if gGameOn and not gPause and (gState <> STATE_FOLD) then
1841 begin
1842 // Âðåìÿ += 28 ìèëëèñåêóíä:
1843 gTime := gTime + GAME_TICK;
1845 // Ñîîáùåíèå ïîñåðåäèíå ýêðàíà:
1846 if MessageTime = 0 then
1847 MessageText := '';
1848 if MessageTime > 0 then
1849 MessageTime := MessageTime - 1;
1851 if (g_Game_IsServer) then
1852 begin
1853 // Áûë çàäàí ëèìèò âðåìåíè:
1854 if (gGameSettings.TimeLimit > 0) then
1855 if (gTime - gGameStartTime) div 1000 >= gGameSettings.TimeLimit then
1856 begin // Îí ïðîøåë => êîíåö óðîâíÿ
1857 g_Game_NextLevel();
1858 Exit;
1859 end;
1861 // Íàäî ðåñïàâíèòü èãðîêîâ â LMS:
1862 if (gLMSRespawn > LMS_RESPAWN_NONE) and (gLMSRespawnTime < gTime) then
1863 g_Game_RestartRound(gLMSSoftSpawn);
1865 // Ïðîâåðèì ðåçóëüòàò ãîëîñîâàíèÿ, åñëè âðåìÿ ïðîøëî
1866 if gVoteInProgress and (gVoteTimer < gTime) then
1867 g_Game_CheckVote
1868 else if gVotePassed and (gVoteCmdTimer < gTime) then
1869 begin
1870 g_Console_Process(gVoteCommand);
1871 gVoteCommand := '';
1872 gVotePassed := False;
1873 end;
1875 // Çàìåðÿåì âðåìÿ çàõâàòà ôëàãîâ
1876 if gFlags[FLAG_RED].State = FLAG_STATE_CAPTURED then
1877 gFlags[FLAG_RED].CaptureTime := gFlags[FLAG_RED].CaptureTime + GAME_TICK;
1878 if gFlags[FLAG_BLUE].State = FLAG_STATE_CAPTURED then
1879 gFlags[FLAG_BLUE].CaptureTime := gFlags[FLAG_BLUE].CaptureTime + GAME_TICK;
1881 // Áûë çàäàí ëèìèò ïîáåä:
1882 if (gGameSettings.GoalLimit > 0) then
1883 begin
1884 b := 0;
1886 if gGameSettings.GameMode = GM_DM then
1887 begin // Â DM èùåì èãðîêà ñ max ôðàãàìè
1888 for i := 0 to High(gPlayers) do
1889 if gPlayers[i] <> nil then
1890 if gPlayers[i].Frags > b then
1891 b := gPlayers[i].Frags;
1892 end
1893 else
1894 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
1895 begin //  CTF/TDM âûáèðàåì êîìàíäó ñ íàèáîëüøèì ñ÷åòîì
1896 b := Max(gTeamStat[TEAM_RED].Goals, gTeamStat[TEAM_BLUE].Goals);
1897 end;
1899 // Ëèìèò ïîáåä íàáðàí => êîíåö óðîâíÿ:
1900 if b >= gGameSettings.GoalLimit then
1901 begin
1902 g_Game_NextLevel();
1903 Exit;
1904 end;
1905 end;
1907 // Îáðàáàòûâàåì êëàâèøè èãðîêîâ:
1908 if gPlayer1 <> nil then gPlayer1.ReleaseKeys();
1909 if gPlayer2 <> nil then gPlayer2.ReleaseKeys();
1910 if (not gConsoleShow) and (not gChatShow) and (g_ActiveWindow = nil) then
1911 begin
1912 ProcessPlayerControls(gPlayer1, 0, P1MoveButton);
1913 ProcessPlayerControls(gPlayer2, 1, P2MoveButton);
1914 end // if not console
1915 else
1916 begin
1917 if g_Game_IsNet and (gPlayer1 <> nil) then gPlayer1.PressKey(KEY_CHAT, 10000);
1918 end;
1919 // process weapon switch queue
1920 end; // if server
1922 // Íàáëþäàòåëü
1923 if (gPlayer1 = nil) and (gPlayer2 = nil) and
1924 (not gConsoleShow) and (not gChatShow) and (g_ActiveWindow = nil) then
1925 begin
1926 if not gSpectKeyPress then
1927 begin
1928 if gPlayerAction[0, ACTION_JUMP] and (not gSpectAuto) then
1929 begin
1930 // switch spect mode
1931 case gSpectMode of
1932 SPECT_NONE: ; // not spectator
1933 SPECT_STATS,
1934 SPECT_MAPVIEW: Inc(gSpectMode);
1935 SPECT_PLAYERS: gSpectMode := SPECT_STATS; // reset to 1
1936 end;
1937 gSpectKeyPress := True;
1938 end;
1939 if (gSpectMode = SPECT_MAPVIEW)
1940 and (not gSpectAuto) then
1941 begin
1942 if gPlayerAction[0, ACTION_MOVELEFT] then
1943 gSpectX := Max(gSpectX - gSpectStep, 0);
1944 if gPlayerAction[0, ACTION_MOVERIGHT] then
1945 gSpectX := Min(gSpectX + gSpectStep, gMapInfo.Width - gScreenWidth);
1946 if gPlayerAction[0, ACTION_LOOKUP] then
1947 gSpectY := Max(gSpectY - gSpectStep, 0);
1948 if gPlayerAction[0, ACTION_LOOKDOWN] then
1949 gSpectY := Min(gSpectY + gSpectStep, gMapInfo.Height - gScreenHeight);
1950 if gPlayerAction[0, ACTION_WEAPPREV] then
1951 begin
1952 // decrease step
1953 if gSpectStep > 4 then gSpectStep := gSpectStep shr 1;
1954 gSpectKeyPress := True;
1955 end;
1956 if gPlayerAction[0, ACTION_WEAPNEXT] then
1957 begin
1958 // increase step
1959 if gSpectStep < 64 then gSpectStep := gSpectStep shl 1;
1960 gSpectKeyPress := True;
1961 end;
1962 end;
1963 if (gSpectMode = SPECT_PLAYERS)
1964 and (not gSpectAuto) then
1965 begin
1966 if gPlayerAction[0, ACTION_LOOKUP] then
1967 begin
1968 // add second view
1969 gSpectViewTwo := True;
1970 gSpectKeyPress := True;
1971 end;
1972 if gPlayerAction[0, ACTION_LOOKDOWN] then
1973 begin
1974 // remove second view
1975 gSpectViewTwo := False;
1976 gSpectKeyPress := True;
1977 end;
1978 if gPlayerAction[0, ACTION_MOVELEFT] then
1979 begin
1980 // prev player (view 1)
1981 gSpectPID1 := GetActivePlayerID_Prev(gSpectPID1);
1982 gSpectKeyPress := True;
1983 end;
1984 if gPlayerAction[0, ACTION_MOVERIGHT] then
1985 begin
1986 // next player (view 1)
1987 gSpectPID1 := GetActivePlayerID_Next(gSpectPID1);
1988 gSpectKeyPress := True;
1989 end;
1990 if gPlayerAction[0, ACTION_WEAPPREV] then
1991 begin
1992 // prev player (view 2)
1993 gSpectPID2 := GetActivePlayerID_Prev(gSpectPID2);
1994 gSpectKeyPress := True;
1995 end;
1996 if gPlayerAction[0, ACTION_WEAPNEXT] then
1997 begin
1998 // next player (view 2)
1999 gSpectPID2 := GetActivePlayerID_Next(gSpectPID2);
2000 gSpectKeyPress := True;
2001 end;
2002 end;
2003 if gPlayerAction[0, ACTION_ATTACK] then
2004 begin
2005 if (gSpectMode = SPECT_STATS) and (not gSpectAuto) then
2006 begin
2007 gSpectAuto := True;
2008 gSpectAutoNext := 0;
2009 gSpectViewTwo := False;
2010 gSpectKeyPress := True;
2011 end
2012 else
2013 if gSpectAuto then
2014 begin
2015 gSpectMode := SPECT_STATS;
2016 gSpectAuto := False;
2017 gSpectKeyPress := True;
2018 end;
2019 end;
2020 end
2021 else
2022 if (not gPlayerAction[0, ACTION_JUMP]) and
2023 (not gPlayerAction[0, ACTION_ATTACK]) and
2024 (not gPlayerAction[0, ACTION_MOVELEFT]) and
2025 (not gPlayerAction[0, ACTION_MOVERIGHT]) and
2026 (not gPlayerAction[0, ACTION_LOOKUP]) and
2027 (not gPlayerAction[0, ACTION_LOOKDOWN]) and
2028 (not gPlayerAction[0, ACTION_WEAPPREV]) and
2029 (not gPlayerAction[0, ACTION_WEAPNEXT]) then
2030 gSpectKeyPress := False;
2032 if gSpectAuto then
2033 begin
2034 if gSpectMode = SPECT_MAPVIEW then
2035 begin
2036 i := Min(Max(gSpectX + gSpectAutoStepX, 0), gMapInfo.Width - gScreenWidth);
2037 if i = gSpectX then
2038 gSpectAutoNext := gTime
2039 else
2040 gSpectX := i;
2041 i := Min(Max(gSpectY + gSpectAutoStepY, 0), gMapInfo.Height - gScreenHeight);
2042 if i = gSpectY then
2043 gSpectAutoNext := gTime
2044 else
2045 gSpectY := i;
2046 end;
2047 if gSpectAutoNext <= gTime then
2048 begin
2049 if gSpectAutoNext > 0 then
2050 begin
2051 gSpectMode := GetRandomSpectMode(gSpectMode);
2052 case gSpectMode of
2053 SPECT_MAPVIEW:
2054 begin
2055 gSpectX := Random(gMapInfo.Width - gScreenWidth);
2056 gSpectY := Random(gMapInfo.Height - gScreenHeight);
2057 gSpectAutoStepX := Random(9) - 4;
2058 gSpectAutoStepY := Random(9) - 4;
2059 if ((gSpectX < 800) and (gSpectAutoStepX < 0)) or
2060 ((gSpectX > gMapInfo.Width - gScreenWidth - 800) and (gSpectAutoStepX > 0)) then
2061 gSpectAutoStepX := gSpectAutoStepX * -1;
2062 if ((gSpectY < 800) and (gSpectAutoStepY < 0)) or
2063 ((gSpectY > gMapInfo.Height - gScreenHeight - 800) and (gSpectAutoStepY > 0)) then
2064 gSpectAutoStepY := gSpectAutoStepY * -1;
2065 end;
2066 SPECT_PLAYERS:
2067 begin
2068 gSpectPID1 := GetActivePlayerID_Random(gSpectPID1);
2069 end;
2070 end;
2071 end;
2072 case gSpectMode of
2073 SPECT_STATS: gSpectAutoNext := gTime + (Random(3) + 5) * 1000;
2074 SPECT_MAPVIEW: gSpectAutoNext := gTime + (Random(4) + 7) * 1000;
2075 SPECT_PLAYERS: gSpectAutoNext := gTime + (Random(7) + 8) * 1000;
2076 end;
2077 end;
2078 end;
2079 end;
2081 // Îáíîâëÿåì âñå îñòàëüíîå:
2082 g_Map_Update();
2083 g_Items_Update();
2084 g_Triggers_Update();
2085 g_Weapon_Update();
2086 g_Monsters_Update();
2087 g_GFX_Update();
2088 g_Player_UpdateAll();
2089 g_Player_UpdatePhysicalObjects();
2091 // server: send newly spawned monsters unconditionally
2092 if (gGameSettings.GameType = GT_SERVER) then
2093 begin
2094 if (Length(gMonstersSpawned) > 0) then
2095 begin
2096 for I := 0 to High(gMonstersSpawned) do MH_SEND_MonsterSpawn(gMonstersSpawned[I]);
2097 SetLength(gMonstersSpawned, 0);
2098 end;
2099 end;
2101 if (gSoundTriggerTime > 8) then
2102 begin
2103 g_Game_UpdateTriggerSounds();
2104 gSoundTriggerTime := 0;
2105 end
2106 else
2107 begin
2108 Inc(gSoundTriggerTime);
2109 end;
2111 if (NetMode = NET_SERVER) then
2112 begin
2113 Inc(NetTimeToUpdate);
2114 Inc(NetTimeToReliable);
2116 // send monster updates
2117 if (NetTimeToReliable >= NetRelupdRate) or (NetTimeToUpdate >= NetUpdateRate) then
2118 begin
2119 // send all monsters (periodic sync)
2120 reliableUpdate := (NetTimeToReliable >= NetRelupdRate);
2122 for I := 0 to High(gPlayers) do
2123 begin
2124 if (gPlayers[I] <> nil) then MH_SEND_PlayerPos(reliableUpdate, gPlayers[I].UID);
2125 end;
2127 g_Mons_ForEach(sendMonsPos);
2129 if reliableUpdate then
2130 begin
2131 NetTimeToReliable := 0;
2132 NetTimeToUpdate := NetUpdateRate;
2133 end
2134 else
2135 begin
2136 NetTimeToUpdate := 0;
2137 end;
2138 end
2139 else
2140 begin
2141 // send only mosters with some unexpected changes
2142 g_Mons_ForEach(sendMonsPosUnexpected);
2143 end;
2145 // send unexpected platform changes
2146 g_Map_NetSendInterestingPanels();
2148 g_Net_Slist_ServerUpdate();
2150 if NetUseMaster then
2151 begin
2152 if (gTime >= NetTimeToMaster) or g_Net_Slist_IsConnectionInProgress then
2153 begin
2154 if (not g_Net_Slist_IsConnectionActive) then g_Net_Slist_Connect(false); // non-blocking connection to the master
2155 g_Net_Slist_Update;
2156 NetTimeToMaster := gTime + NetMasterRate;
2157 end;
2158 end;
2160 end
2161 else if (NetMode = NET_CLIENT) then
2162 begin
2163 MC_SEND_PlayerPos();
2164 end;
2165 end; // if gameOn ...
2167 // Àêòèâíî îêíî èíòåðôåéñà - ïåðåäàåì êëàâèøè åìó:
2168 if g_ActiveWindow <> nil then
2169 begin
2170 w := e_GetFirstKeyPressed();
2172 if (w <> IK_INVALID) then
2173 begin
2174 Msg.Msg := MESSAGE_DIKEY;
2175 Msg.wParam := w;
2176 g_ActiveWindow.OnMessage(Msg);
2177 end;
2179 // Åñëè îíî îò ýòîãî íå çàêðûëîñü, òî îáíîâëÿåì:
2180 if g_ActiveWindow <> nil then
2181 g_ActiveWindow.Update();
2183 // Íóæíî ñìåíèòü ðàçðåøåíèå:
2184 if gResolutionChange then
2185 begin
2186 e_WriteLog('Changing resolution', TMsgType.Notify);
2187 g_Game_ChangeResolution(gRC_Width, gRC_Height, gRC_FullScreen, gRC_Maximized);
2188 gResolutionChange := False;
2189 g_ActiveWindow := nil;
2190 end;
2192 // Íóæíî ñìåíèòü ÿçûê:
2193 if gLanguageChange then
2194 begin
2195 //e_WriteLog('Read language file', MSG_NOTIFY);
2196 //g_Language_Load(DataDir + gLanguage + '.txt');
2197 g_Language_Set(gLanguage);
2198 {$IFNDEF HEADLESS}
2199 g_Menu_Reset();
2200 {$ENDIF}
2201 gLanguageChange := False;
2202 end;
2203 end;
2205 // Ãîðÿ÷àÿ êëàâèøà äëÿ âûçîâà ìåíþ âûõîäà èç èãðû (F10):
2206 if e_KeyPressed(IK_F10) and
2207 gGameOn and
2208 (not gConsoleShow) and
2209 (g_ActiveWindow = nil) then
2210 begin
2211 KeyPress(IK_F10);
2212 end;
2214 Time := sys_GetTicks() {div 1000};
2216 // Îáðàáîòêà îòëîæåííûõ ñîáûòèé:
2217 if gDelayedEvents <> nil then
2218 for a := 0 to High(gDelayedEvents) do
2219 if gDelayedEvents[a].Pending and
2221 ((gDelayedEvents[a].DEType = DE_GLOBEVENT) and (gDelayedEvents[a].Time <= Time)) or
2222 ((gDelayedEvents[a].DEType > DE_GLOBEVENT) and (gDelayedEvents[a].Time <= gTime))
2223 ) then
2224 begin
2225 case gDelayedEvents[a].DEType of
2226 DE_GLOBEVENT:
2227 g_Game_ExecuteEvent(gDelayedEvents[a].DEStr);
2228 DE_BFGHIT:
2229 if gGameOn then
2230 g_Game_Announce_GoodShot(gDelayedEvents[a].DENum);
2231 DE_KILLCOMBO:
2232 if gGameOn then
2233 begin
2234 g_Game_Announce_KillCombo(gDelayedEvents[a].DENum);
2235 if g_Game_IsNet and g_Game_IsServer then
2236 MH_SEND_GameEvent(NET_EV_KILLCOMBO, gDelayedEvents[a].DENum);
2237 end;
2238 DE_BODYKILL:
2239 if gGameOn then
2240 g_Game_Announce_BodyKill(gDelayedEvents[a].DENum);
2241 end;
2242 gDelayedEvents[a].Pending := False;
2243 end;
2245 // Êàæäóþ ñåêóíäó îáíîâëÿåì ñ÷åò÷èê îáíîâëåíèé:
2246 UPSCounter := UPSCounter + 1;
2247 if Time - UPSTime >= 1000 then
2248 begin
2249 UPS := UPSCounter;
2250 UPSCounter := 0;
2251 UPSTime := Time;
2252 end;
2254 if gGameOn then
2255 begin
2256 g_Weapon_AddDynLights();
2257 g_Items_AddDynLights();
2258 end;
2259 end;
2261 procedure g_Game_LoadChatSounds(Resource: string);
2262 var
2263 WAD: TWADFile;
2264 FileName, Snd: string;
2265 p: Pointer;
2266 len, cnt, tags, i, j: Integer;
2267 cfg: TConfig;
2268 begin
2269 FileName := g_ExtractWadName(Resource);
2271 WAD := TWADFile.Create();
2272 WAD.ReadFile(FileName);
2274 if not WAD.GetResource(g_ExtractFilePathName(Resource), p, len) then
2275 begin
2276 gChatSounds := nil;
2277 WAD.Free();
2278 Exit;
2279 end;
2281 cfg := TConfig.CreateMem(p, len);
2282 cnt := cfg.ReadInt('ChatSounds', 'Count', 0);
2284 SetLength(gChatSounds, cnt);
2285 for i := 0 to Length(gChatSounds) - 1 do
2286 begin
2287 gChatSounds[i].Sound := nil;
2288 Snd := Trim(cfg.ReadStr(IntToStr(i), 'Sound', ''));
2289 tags := cfg.ReadInt(IntToStr(i), 'Tags', 0);
2290 if (Snd = '') or (Tags <= 0) then
2291 continue;
2292 g_Sound_CreateWADEx('SOUND_CHAT_MACRO' + IntToStr(i), GameWAD+':'+Snd);
2293 gChatSounds[i].Sound := TPlayableSound.Create();
2294 gChatSounds[i].Sound.SetByName('SOUND_CHAT_MACRO' + IntToStr(i));
2295 SetLength(gChatSounds[i].Tags, tags);
2296 for j := 0 to tags - 1 do
2297 gChatSounds[i].Tags[j] := toLowerCase1251(cfg.ReadStr(IntToStr(i), 'Tag' + IntToStr(j), ''));
2298 gChatSounds[i].FullWord := cfg.ReadBool(IntToStr(i), 'FullWord', False);
2299 end;
2301 cfg.Free();
2302 WAD.Free();
2303 end;
2305 procedure g_Game_FreeChatSounds();
2306 var
2307 i: Integer;
2308 begin
2309 for i := 0 to Length(gChatSounds) - 1 do
2310 begin
2311 gChatSounds[i].Sound.Free();
2312 g_Sound_Delete('SOUND_CHAT_MACRO' + IntToStr(i));
2313 end;
2314 SetLength(gChatSounds, 0);
2315 gChatSounds := nil;
2316 end;
2318 procedure g_Game_LoadData();
2319 var
2320 wl, hl: Integer;
2321 wr, hr: Integer;
2322 wb, hb: Integer;
2323 wm, hm: Integer;
2324 begin
2325 if DataLoaded then Exit;
2327 e_WriteLog('Loading game data...', TMsgType.Notify);
2329 g_Texture_CreateWADEx('NOTEXTURE', GameWAD+':TEXTURES\NOTEXTURE');
2330 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUD', GameWAD+':TEXTURES\HUD');
2331 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDAIR', GameWAD+':TEXTURES\AIRBAR');
2332 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDJET', GameWAD+':TEXTURES\JETBAR');
2333 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDBG', GameWAD+':TEXTURES\HUDBG');
2334 g_Texture_CreateWADEx('TEXTURE_PLAYER_ARMORHUD', GameWAD+':TEXTURES\ARMORHUD');
2335 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG', GameWAD+':TEXTURES\FLAGHUD_R_BASE');
2336 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_S', GameWAD+':TEXTURES\FLAGHUD_R_STOLEN');
2337 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_D', GameWAD+':TEXTURES\FLAGHUD_R_DROP');
2338 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG', GameWAD+':TEXTURES\FLAGHUD_B_BASE');
2339 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_S', GameWAD+':TEXTURES\FLAGHUD_B_STOLEN');
2340 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_D', GameWAD+':TEXTURES\FLAGHUD_B_DROP');
2341 g_Texture_CreateWADEx('TEXTURE_PLAYER_TALKBUBBLE', GameWAD+':TEXTURES\TALKBUBBLE');
2342 g_Texture_CreateWADEx('TEXTURE_PLAYER_INVULPENTA', GameWAD+':TEXTURES\PENTA');
2343 g_Texture_CreateWADEx('TEXTURE_PLAYER_INDICATOR', GameWAD+':TEXTURES\PLRIND');
2345 hasPBarGfx := true;
2346 if not g_Texture_CreateWADEx('UI_GFX_PBAR_LEFT', GameWAD+':TEXTURES\LLEFT') then hasPBarGfx := false;
2347 if not g_Texture_CreateWADEx('UI_GFX_PBAR_MARKER', GameWAD+':TEXTURES\LMARKER') then hasPBarGfx := false;
2348 if not g_Texture_CreateWADEx('UI_GFX_PBAR_MIDDLE', GameWAD+':TEXTURES\LMIDDLE') then hasPBarGfx := false;
2349 if not g_Texture_CreateWADEx('UI_GFX_PBAR_RIGHT', GameWAD+':TEXTURES\LRIGHT') then hasPBarGfx := false;
2351 if hasPBarGfx then
2352 begin
2353 g_Texture_GetSize('UI_GFX_PBAR_LEFT', wl, hl);
2354 g_Texture_GetSize('UI_GFX_PBAR_RIGHT', wr, hr);
2355 g_Texture_GetSize('UI_GFX_PBAR_MIDDLE', wb, hb);
2356 g_Texture_GetSize('UI_GFX_PBAR_MARKER', wm, hm);
2357 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
2358 begin
2359 // yay!
2360 end
2361 else
2362 begin
2363 hasPBarGfx := false;
2364 end;
2365 end;
2367 g_Frames_CreateWAD(nil, 'FRAMES_TELEPORT', GameWAD+':TEXTURES\TELEPORT', 64, 64, 10, False);
2368 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH', GameWAD+':WEAPONS\PUNCH', 64, 64, 4, False);
2369 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_UP', GameWAD+':WEAPONS\PUNCH_UP', 64, 64, 4, False);
2370 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_DN', GameWAD+':WEAPONS\PUNCH_DN', 64, 64, 4, False);
2371 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK', GameWAD+':WEAPONS\PUNCHB', 64, 64, 4, False);
2372 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK_UP', GameWAD+':WEAPONS\PUNCHB_UP', 64, 64, 4, False);
2373 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK_DN', GameWAD+':WEAPONS\PUNCHB_DN', 64, 64, 4, False);
2374 g_Sound_CreateWADEx('SOUND_GAME_TELEPORT', GameWAD+':SOUNDS\TELEPORT');
2375 g_Sound_CreateWADEx('SOUND_GAME_NOTELEPORT', GameWAD+':SOUNDS\NOTELEPORT');
2376 g_Sound_CreateWADEx('SOUND_GAME_SECRET', GameWAD+':SOUNDS\SECRET');
2377 g_Sound_CreateWADEx('SOUND_GAME_DOOROPEN', GameWAD+':SOUNDS\DOOROPEN');
2378 g_Sound_CreateWADEx('SOUND_GAME_DOORCLOSE', GameWAD+':SOUNDS\DOORCLOSE');
2379 g_Sound_CreateWADEx('SOUND_GAME_BULK1', GameWAD+':SOUNDS\BULK1');
2380 g_Sound_CreateWADEx('SOUND_GAME_BULK2', GameWAD+':SOUNDS\BULK2');
2381 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE1', GameWAD+':SOUNDS\BUBBLE1');
2382 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE2', GameWAD+':SOUNDS\BUBBLE2');
2383 g_Sound_CreateWADEx('SOUND_GAME_BURNING', GameWAD+':SOUNDS\BURNING');
2384 g_Sound_CreateWADEx('SOUND_GAME_SWITCH1', GameWAD+':SOUNDS\SWITCH1');
2385 g_Sound_CreateWADEx('SOUND_GAME_SWITCH0', GameWAD+':SOUNDS\SWITCH0');
2386 g_Sound_CreateWADEx('SOUND_GAME_RADIO', GameWAD+':SOUNDS\RADIO');
2387 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD1', GameWAD+':SOUNDS\GOOD1');
2388 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD2', GameWAD+':SOUNDS\GOOD2');
2389 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD3', GameWAD+':SOUNDS\GOOD3');
2390 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD4', GameWAD+':SOUNDS\GOOD4');
2391 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL2X', GameWAD+':SOUNDS\KILL2X');
2392 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL3X', GameWAD+':SOUNDS\KILL3X');
2393 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL4X', GameWAD+':SOUNDS\KILL4X');
2394 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILLMX', GameWAD+':SOUNDS\KILLMX');
2395 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA1', GameWAD+':SOUNDS\MUHAHA1');
2396 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA2', GameWAD+':SOUNDS\MUHAHA2');
2397 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA3', GameWAD+':SOUNDS\MUHAHA3');
2398 g_Sound_CreateWADEx('SOUND_CTF_GET1', GameWAD+':SOUNDS\GETFLAG1');
2399 g_Sound_CreateWADEx('SOUND_CTF_GET2', GameWAD+':SOUNDS\GETFLAG2');
2400 g_Sound_CreateWADEx('SOUND_CTF_LOST1', GameWAD+':SOUNDS\LOSTFLG1');
2401 g_Sound_CreateWADEx('SOUND_CTF_LOST2', GameWAD+':SOUNDS\LOSTFLG2');
2402 g_Sound_CreateWADEx('SOUND_CTF_RETURN1', GameWAD+':SOUNDS\RETFLAG1');
2403 g_Sound_CreateWADEx('SOUND_CTF_RETURN2', GameWAD+':SOUNDS\RETFLAG2');
2404 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE1', GameWAD+':SOUNDS\CAPFLAG1');
2405 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE2', GameWAD+':SOUNDS\CAPFLAG2');
2407 goodsnd[0] := TPlayableSound.Create();
2408 goodsnd[1] := TPlayableSound.Create();
2409 goodsnd[2] := TPlayableSound.Create();
2410 goodsnd[3] := TPlayableSound.Create();
2412 goodsnd[0].SetByName('SOUND_ANNOUNCER_GOOD1');
2413 goodsnd[1].SetByName('SOUND_ANNOUNCER_GOOD2');
2414 goodsnd[2].SetByName('SOUND_ANNOUNCER_GOOD3');
2415 goodsnd[3].SetByName('SOUND_ANNOUNCER_GOOD4');
2417 killsnd[0] := TPlayableSound.Create();
2418 killsnd[1] := TPlayableSound.Create();
2419 killsnd[2] := TPlayableSound.Create();
2420 killsnd[3] := TPlayableSound.Create();
2422 killsnd[0].SetByName('SOUND_ANNOUNCER_KILL2X');
2423 killsnd[1].SetByName('SOUND_ANNOUNCER_KILL3X');
2424 killsnd[2].SetByName('SOUND_ANNOUNCER_KILL4X');
2425 killsnd[3].SetByName('SOUND_ANNOUNCER_KILLMX');
2427 hahasnd[0] := TPlayableSound.Create();
2428 hahasnd[1] := TPlayableSound.Create();
2429 hahasnd[2] := TPlayableSound.Create();
2431 hahasnd[0].SetByName('SOUND_ANNOUNCER_MUHAHA1');
2432 hahasnd[1].SetByName('SOUND_ANNOUNCER_MUHAHA2');
2433 hahasnd[2].SetByName('SOUND_ANNOUNCER_MUHAHA3');
2435 sound_get_flag[0] := TPlayableSound.Create();
2436 sound_get_flag[1] := TPlayableSound.Create();
2437 sound_lost_flag[0] := TPlayableSound.Create();
2438 sound_lost_flag[1] := TPlayableSound.Create();
2439 sound_ret_flag[0] := TPlayableSound.Create();
2440 sound_ret_flag[1] := TPlayableSound.Create();
2441 sound_cap_flag[0] := TPlayableSound.Create();
2442 sound_cap_flag[1] := TPlayableSound.Create();
2444 sound_get_flag[0].SetByName('SOUND_CTF_GET1');
2445 sound_get_flag[1].SetByName('SOUND_CTF_GET2');
2446 sound_lost_flag[0].SetByName('SOUND_CTF_LOST1');
2447 sound_lost_flag[1].SetByName('SOUND_CTF_LOST2');
2448 sound_ret_flag[0].SetByName('SOUND_CTF_RETURN1');
2449 sound_ret_flag[1].SetByName('SOUND_CTF_RETURN2');
2450 sound_cap_flag[0].SetByName('SOUND_CTF_CAPTURE1');
2451 sound_cap_flag[1].SetByName('SOUND_CTF_CAPTURE2');
2453 g_Game_LoadChatSounds(GameWAD+':CHATSND\SNDCFG');
2455 g_Game_SetLoadingText(_lc[I_LOAD_ITEMS_DATA], 0, False);
2456 g_Items_LoadData();
2458 g_Game_SetLoadingText(_lc[I_LOAD_WEAPONS_DATA], 0, False);
2459 g_Weapon_LoadData();
2461 g_Monsters_LoadData();
2463 DataLoaded := True;
2464 end;
2466 procedure g_Game_FreeData();
2467 begin
2468 if not DataLoaded then Exit;
2470 g_Items_FreeData();
2471 g_Weapon_FreeData();
2472 g_Monsters_FreeData();
2474 e_WriteLog('Releasing game data...', TMsgType.Notify);
2476 g_Texture_Delete('NOTEXTURE');
2477 g_Texture_Delete('TEXTURE_PLAYER_HUD');
2478 g_Texture_Delete('TEXTURE_PLAYER_HUDBG');
2479 g_Texture_Delete('TEXTURE_PLAYER_ARMORHUD');
2480 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG');
2481 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_S');
2482 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_D');
2483 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG');
2484 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_S');
2485 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_D');
2486 g_Texture_Delete('TEXTURE_PLAYER_TALKBUBBLE');
2487 g_Texture_Delete('TEXTURE_PLAYER_INVULPENTA');
2488 g_Frames_DeleteByName('FRAMES_TELEPORT');
2489 g_Frames_DeleteByName('FRAMES_PUNCH');
2490 g_Frames_DeleteByName('FRAMES_PUNCH_UP');
2491 g_Frames_DeleteByName('FRAMES_PUNCH_DN');
2492 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK');
2493 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK_UP');
2494 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK_DN');
2495 g_Sound_Delete('SOUND_GAME_TELEPORT');
2496 g_Sound_Delete('SOUND_GAME_NOTELEPORT');
2497 g_Sound_Delete('SOUND_GAME_SECRET');
2498 g_Sound_Delete('SOUND_GAME_DOOROPEN');
2499 g_Sound_Delete('SOUND_GAME_DOORCLOSE');
2500 g_Sound_Delete('SOUND_GAME_BULK1');
2501 g_Sound_Delete('SOUND_GAME_BULK2');
2502 g_Sound_Delete('SOUND_GAME_BUBBLE1');
2503 g_Sound_Delete('SOUND_GAME_BUBBLE2');
2504 g_Sound_Delete('SOUND_GAME_BURNING');
2505 g_Sound_Delete('SOUND_GAME_SWITCH1');
2506 g_Sound_Delete('SOUND_GAME_SWITCH0');
2508 goodsnd[0].Free();
2509 goodsnd[1].Free();
2510 goodsnd[2].Free();
2511 goodsnd[3].Free();
2513 g_Sound_Delete('SOUND_ANNOUNCER_GOOD1');
2514 g_Sound_Delete('SOUND_ANNOUNCER_GOOD2');
2515 g_Sound_Delete('SOUND_ANNOUNCER_GOOD3');
2516 g_Sound_Delete('SOUND_ANNOUNCER_GOOD4');
2518 killsnd[0].Free();
2519 killsnd[1].Free();
2520 killsnd[2].Free();
2521 killsnd[3].Free();
2523 g_Sound_Delete('SOUND_ANNOUNCER_KILL2X');
2524 g_Sound_Delete('SOUND_ANNOUNCER_KILL3X');
2525 g_Sound_Delete('SOUND_ANNOUNCER_KILL4X');
2526 g_Sound_Delete('SOUND_ANNOUNCER_KILLMX');
2528 hahasnd[0].Free();
2529 hahasnd[1].Free();
2530 hahasnd[2].Free();
2532 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA1');
2533 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA2');
2534 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA3');
2536 sound_get_flag[0].Free();
2537 sound_get_flag[1].Free();
2538 sound_lost_flag[0].Free();
2539 sound_lost_flag[1].Free();
2540 sound_ret_flag[0].Free();
2541 sound_ret_flag[1].Free();
2542 sound_cap_flag[0].Free();
2543 sound_cap_flag[1].Free();
2545 g_Sound_Delete('SOUND_CTF_GET1');
2546 g_Sound_Delete('SOUND_CTF_GET2');
2547 g_Sound_Delete('SOUND_CTF_LOST1');
2548 g_Sound_Delete('SOUND_CTF_LOST2');
2549 g_Sound_Delete('SOUND_CTF_RETURN1');
2550 g_Sound_Delete('SOUND_CTF_RETURN2');
2551 g_Sound_Delete('SOUND_CTF_CAPTURE1');
2552 g_Sound_Delete('SOUND_CTF_CAPTURE2');
2554 g_Game_FreeChatSounds();
2556 DataLoaded := False;
2557 end;
2559 procedure DrawCustomStat();
2560 var
2561 pc, x, y, w, _y,
2562 w1, w2, w3,
2563 t, p, m: Integer;
2564 ww1, hh1: Word;
2565 ww2, hh2, r, g, b, rr, gg, bb: Byte;
2566 s1, s2, topstr: String;
2567 begin
2568 e_TextureFontGetSize(gStdFont, ww2, hh2);
2570 sys_HandleInput;
2572 if g_Console_Action(ACTION_SCORES) then
2573 begin
2574 if not gStatsPressed then
2575 begin
2576 gStatsOff := not gStatsOff;
2577 gStatsPressed := True;
2578 end;
2579 end
2580 else
2581 gStatsPressed := False;
2583 if gStatsOff then
2584 begin
2585 s1 := _lc[I_MENU_INTER_NOTICE_TAB];
2586 w := (Length(s1) * ww2) div 2;
2587 x := gScreenWidth div 2 - w;
2588 y := 8;
2589 e_TextureFontPrint(x, y, s1, gStdFont);
2590 Exit;
2591 end;
2593 if (gGameSettings.GameMode = GM_COOP) then
2594 begin
2595 if gMissionFailed then
2596 topstr := _lc[I_MENU_INTER_MISSION_FAIL]
2597 else
2598 topstr := _lc[I_MENU_INTER_LEVEL_COMPLETE];
2599 end
2600 else
2601 topstr := _lc[I_MENU_INTER_ROUND_OVER];
2603 e_CharFont_GetSize(gMenuFont, topstr, ww1, hh1);
2604 e_CharFont_Print(gMenuFont, (gScreenWidth div 2)-(ww1 div 2), 16, topstr);
2606 if g_Game_IsNet then
2607 begin
2608 topstr := Format(_lc[I_MENU_INTER_NOTICE_TIME], [gServInterTime]);
2609 if not gChatShow then
2610 e_TextureFontPrintEx((gScreenWidth div 2)-(Length(topstr)*ww2 div 2),
2611 gScreenHeight-(hh2+4)*2, topstr, gStdFont, 255, 255, 255, 1);
2612 end;
2614 if g_Game_IsClient then
2615 topstr := _lc[I_MENU_INTER_NOTICE_MAP]
2616 else
2617 topstr := _lc[I_MENU_INTER_NOTICE_SPACE];
2618 if not gChatShow then
2619 e_TextureFontPrintEx((gScreenWidth div 2)-(Length(topstr)*ww2 div 2),
2620 gScreenHeight-(hh2+4), topstr, gStdFont, 255, 255, 255, 1);
2622 x := 32;
2623 y := 16+hh1+16;
2625 w := gScreenWidth-x*2;
2627 w2 := (w-16) div 6;
2628 w3 := w2;
2629 w1 := w-16-w2-w3;
2631 e_DrawFillQuad(x, y, gScreenWidth-x-1, gScreenHeight-y-1, 64, 64, 64, 32);
2632 e_DrawQuad(x, y, gScreenWidth-x-1, gScreenHeight-y-1, 255, 127, 0);
2634 m := Max(Length(_lc[I_MENU_MAP])+1, Length(_lc[I_GAME_GAME_TIME])+1)*ww2;
2636 case CustomStat.GameMode of
2637 GM_DM:
2638 begin
2639 if gGameSettings.MaxLives = 0 then
2640 s1 := _lc[I_GAME_DM]
2641 else
2642 s1 := _lc[I_GAME_LMS];
2643 end;
2644 GM_TDM:
2645 begin
2646 if gGameSettings.MaxLives = 0 then
2647 s1 := _lc[I_GAME_TDM]
2648 else
2649 s1 := _lc[I_GAME_TLMS];
2650 end;
2651 GM_CTF: s1 := _lc[I_GAME_CTF];
2652 GM_COOP:
2653 begin
2654 if gGameSettings.MaxLives = 0 then
2655 s1 := _lc[I_GAME_COOP]
2656 else
2657 s1 := _lc[I_GAME_SURV];
2658 end;
2659 else s1 := '';
2660 end;
2662 _y := y+16;
2663 e_TextureFontPrintEx(x+(w div 2)-(Length(s1)*ww2 div 2), _y, s1, gStdFont, 255, 255, 255, 1);
2664 _y := _y+8;
2666 _y := _y+16;
2667 e_TextureFontPrintEx(x+8, _y, _lc[I_MENU_MAP], gStdFont, 255, 127, 0, 1);
2668 e_TextureFontPrint(x+8+m, _y, Format('%s - %s', [CustomStat.Map, CustomStat.MapName]), gStdFont);
2670 _y := _y+16;
2671 e_TextureFontPrintEx(x+8, _y, _lc[I_GAME_GAME_TIME], gStdFont, 255, 127, 0, 1);
2672 e_TextureFontPrint(x+8+m, _y, Format('%d:%.2d:%.2d', [CustomStat.GameTime div 1000 div 3600,
2673 (CustomStat.GameTime div 1000 div 60) mod 60,
2674 CustomStat.GameTime div 1000 mod 60]), gStdFont);
2676 pc := Length(CustomStat.PlayerStat);
2677 if pc = 0 then Exit;
2679 if CustomStat.GameMode = GM_COOP then
2680 begin
2681 m := Max(Length(_lc[I_GAME_MONSTERS])+1, Length(_lc[I_GAME_SECRETS])+1)*ww2;
2682 _y := _y+32;
2683 s2 := _lc[I_GAME_MONSTERS];
2684 e_TextureFontPrintEx(x+8, _y, s2, gStdFont, 255, 127, 0, 1);
2685 e_TextureFontPrintEx(x+8+m, _y, IntToStr(gCoopMonstersKilled) + '/' + IntToStr(gTotalMonsters), gStdFont, 255, 255, 255, 1);
2686 _y := _y+16;
2687 s2 := _lc[I_GAME_SECRETS];
2688 e_TextureFontPrintEx(x+8, _y, s2, gStdFont, 255, 127, 0, 1);
2689 e_TextureFontPrintEx(x+8+m, _y, IntToStr(gCoopSecretsFound) + '/' + IntToStr(gSecretsCount), gStdFont, 255, 255, 255, 1);
2690 if gLastMap then
2691 begin
2692 m := Max(Length(_lc[I_GAME_MONSTERS_TOTAL])+1, Length(_lc[I_GAME_SECRETS_TOTAL])+1)*ww2;
2693 _y := _y-16;
2694 s2 := _lc[I_GAME_MONSTERS_TOTAL];
2695 e_TextureFontPrintEx(x+250, _y, s2, gStdFont, 255, 127, 0, 1);
2696 e_TextureFontPrintEx(x+250+m, _y, IntToStr(gCoopTotalMonstersKilled) + '/' + IntToStr(gCoopTotalMonsters), gStdFont, 255, 255, 255, 1);
2697 _y := _y+16;
2698 s2 := _lc[I_GAME_SECRETS_TOTAL];
2699 e_TextureFontPrintEx(x+250, _y, s2, gStdFont, 255, 127, 0, 1);
2700 e_TextureFontPrintEx(x+250+m, _y, IntToStr(gCoopTotalSecretsFound) + '/' + IntToStr(gCoopTotalSecrets), gStdFont, 255, 255, 255, 1);
2701 end;
2702 end;
2704 if CustomStat.GameMode in [GM_TDM, GM_CTF] then
2705 begin
2706 _y := _y+16+16;
2708 with CustomStat do
2709 if TeamStat[TEAM_RED].Goals > TeamStat[TEAM_BLUE].Goals then s1 := _lc[I_GAME_WIN_RED]
2710 else if TeamStat[TEAM_BLUE].Goals > TeamStat[TEAM_RED].Goals then s1 := _lc[I_GAME_WIN_BLUE]
2711 else s1 := _lc[I_GAME_WIN_DRAW];
2713 e_TextureFontPrintEx(x+8+(w div 2)-(Length(s1)*ww2 div 2), _y, s1, gStdFont, 255, 255, 255, 1);
2714 _y := _y+40;
2716 for t := TEAM_RED to TEAM_BLUE do
2717 begin
2718 if t = TEAM_RED then
2719 begin
2720 e_TextureFontPrintEx(x+8, _y, _lc[I_GAME_TEAM_RED],
2721 gStdFont, 255, 0, 0, 1);
2722 e_TextureFontPrintEx(x+w1+8, _y, IntToStr(CustomStat.TeamStat[TEAM_RED].Goals),
2723 gStdFont, 255, 0, 0, 1);
2724 r := 255;
2725 g := 0;
2726 b := 0;
2727 end
2728 else
2729 begin
2730 e_TextureFontPrintEx(x+8, _y, _lc[I_GAME_TEAM_BLUE],
2731 gStdFont, 0, 0, 255, 1);
2732 e_TextureFontPrintEx(x+w1+8, _y, IntToStr(CustomStat.TeamStat[TEAM_BLUE].Goals),
2733 gStdFont, 0, 0, 255, 1);
2734 r := 0;
2735 g := 0;
2736 b := 255;
2737 end;
2739 e_DrawLine(1, x+8, _y+20, x-8+w, _y+20, r, g, b);
2740 _y := _y+24;
2742 for p := 0 to High(CustomStat.PlayerStat) do
2743 if CustomStat.PlayerStat[p].Team = t then
2744 with CustomStat.PlayerStat[p] do
2745 begin
2746 if Spectator then
2747 begin
2748 rr := r div 2;
2749 gg := g div 2;
2750 bb := b div 2;
2751 end
2752 else
2753 begin
2754 rr := r;
2755 gg := g;
2756 bb := b;
2757 end;
2758 if (gPlayers[Num] <> nil) and (gPlayers[Num].FReady) then
2759 e_TextureFontPrintEx(x+16, _y, Name + ' *', gStdFont, rr, gg, bb, 1)
2760 else
2761 e_TextureFontPrintEx(x+16, _y, Name, gStdFont, rr, gg, bb, 1);
2762 e_TextureFontPrintEx(x+w1+16, _y, IntToStr(Frags), gStdFont, rr, gg, bb, 1);
2763 e_TextureFontPrintEx(x+w1+w2+16, _y, IntToStr(Deaths), gStdFont, rr, gg, bb, 1);
2764 _y := _y+24;
2765 end;
2767 _y := _y+16+16;
2768 end;
2769 end
2770 else if CustomStat.GameMode in [GM_DM, GM_COOP] then
2771 begin
2772 _y := _y+40;
2773 e_TextureFontPrintEx(x+8, _y, _lc[I_GAME_PLAYER_NAME], gStdFont, 255, 127, 0, 1);
2774 e_TextureFontPrintEx(x+8+w1, _y, _lc[I_GAME_FRAGS], gStdFont, 255, 127, 0, 1);
2775 e_TextureFontPrintEx(x+8+w1+w2, _y, _lc[I_GAME_DEATHS], gStdFont, 255, 127, 0, 1);
2777 _y := _y+24;
2778 for p := 0 to High(CustomStat.PlayerStat) do
2779 with CustomStat.PlayerStat[p] do
2780 begin
2781 e_DrawFillQuad(x+8, _y+4, x+24-1, _y+16+4-1, Color.R, Color.G, Color.B, 0);
2783 if Spectator then
2784 r := 127
2785 else
2786 r := 255;
2788 if (gPlayers[Num] <> nil) and (gPlayers[Num].FReady) then
2789 e_TextureFontPrintEx(x+8+16+8, _y+4, Name + ' *', gStdFont, r, r, r, 1, True)
2790 else
2791 e_TextureFontPrintEx(x+8+16+8, _y+4, Name, gStdFont, r, r, r, 1, True);
2792 e_TextureFontPrintEx(x+w1+8+16+8, _y+4, IntToStr(Frags), gStdFont, r, r, r, 1, True);
2793 e_TextureFontPrintEx(x+w1+w2+8+16+8, _y+4, IntToStr(Deaths), gStdFont, r, r, r, 1, True);
2794 _y := _y+24;
2795 end;
2796 end;
2797 end;
2799 procedure DrawSingleStat();
2800 var
2801 tm, key_x, val_x, y: Integer;
2802 w1, w2, h: Word;
2803 s1, s2: String;
2805 procedure player_stat(n: Integer);
2806 var
2807 kpm: Real;
2809 begin
2810 // "Kills: # / #":
2811 s1 := Format(' %d ', [SingleStat.PlayerStat[n].Kills]);
2812 s2 := Format(' %d', [gTotalMonsters]);
2814 e_CharFont_Print(gMenuFont, key_x, y, _lc[I_MENU_INTER_KILLS]);
2815 e_CharFont_PrintEx(gMenuFont, val_x, y, s1, _RGB(255, 0, 0));
2816 e_CharFont_GetSize(gMenuFont, s1, w1, h);
2817 e_CharFont_Print(gMenuFont, val_x+w1, y, '/');
2818 s1 := s1 + '/';
2819 e_CharFont_GetSize(gMenuFont, s1, w1, h);
2820 e_CharFont_PrintEx(gMenuFont, val_x+w1, y, s2, _RGB(255, 0, 0));
2822 // "Kills-per-minute: ##.#":
2823 s1 := _lc[I_MENU_INTER_KPM];
2824 if tm > 0 then
2825 kpm := (SingleStat.PlayerStat[n].Kills / tm) * 60
2826 else
2827 kpm := SingleStat.PlayerStat[n].Kills;
2828 s2 := Format(' %.1f', [kpm]);
2830 e_CharFont_Print(gMenuFont, key_x, y+32, s1);
2831 e_CharFont_PrintEx(gMenuFont, val_x, y+32, s2, _RGB(255, 0, 0));
2833 // "Secrets found: # / #":
2834 s1 := Format(' %d ', [SingleStat.PlayerStat[n].Secrets]);
2835 s2 := Format(' %d', [SingleStat.TotalSecrets]);
2837 e_CharFont_Print(gMenuFont, key_x, y+64, _lc[I_MENU_INTER_SECRETS]);
2838 e_CharFont_PrintEx(gMenuFont, val_x, y+64, s1, _RGB(255, 0, 0));
2839 e_CharFont_GetSize(gMenuFont, s1, w1, h);
2840 e_CharFont_Print(gMenuFont, val_x+w1, y+64, '/');
2841 s1 := s1 + '/';
2842 e_CharFont_GetSize(gMenuFont, s1, w1, h);
2843 e_CharFont_PrintEx(gMenuFont, val_x+w1, y+64, s2, _RGB(255, 0, 0));
2844 end;
2846 begin
2847 // "Level Complete":
2848 e_CharFont_GetSize(gMenuFont, _lc[I_MENU_INTER_LEVEL_COMPLETE], w1, h);
2849 e_CharFont_Print(gMenuFont, (gScreenWidth-w1) div 2, 32, _lc[I_MENU_INTER_LEVEL_COMPLETE]);
2851 // Îïðåäåëÿåì êîîðäèíàòû âûðàâíèâàíèÿ ïî ñàìîé äëèííîé ñòðîêå:
2852 s1 := _lc[I_MENU_INTER_KPM];
2853 e_CharFont_GetSize(gMenuFont, s1, w1, h);
2854 Inc(w1, 16);
2855 s1 := ' 9999.9';
2856 e_CharFont_GetSize(gMenuFont, s1, w2, h);
2858 key_x := (gScreenWidth-w1-w2) div 2;
2859 val_x := key_x + w1;
2861 // "Time: #:##:##":
2862 tm := SingleStat.GameTime div 1000;
2863 s1 := _lc[I_MENU_INTER_TIME];
2864 s2 := Format(' %d:%.2d:%.2d', [tm div (60*60), (tm mod (60*60)) div 60, tm mod 60]);
2866 e_CharFont_Print(gMenuFont, key_x, 80, s1);
2867 e_CharFont_PrintEx(gMenuFont, val_x, 80, s2, _RGB(255, 0, 0));
2869 if SingleStat.TwoPlayers then
2870 begin
2871 // "Player 1":
2872 s1 := _lc[I_MENU_PLAYER_1];
2873 e_CharFont_GetSize(gMenuFont, s1, w1, h);
2874 e_CharFont_Print(gMenuFont, (gScreenWidth-w1) div 2, 128, s1);
2876 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
2877 y := 176;
2878 player_stat(0);
2880 // "Player 2":
2881 s1 := _lc[I_MENU_PLAYER_2];
2882 e_CharFont_GetSize(gMenuFont, s1, w1, h);
2883 e_CharFont_Print(gMenuFont, (gScreenWidth-w1) div 2, 288, s1);
2885 // Ñòàòèñòèêà âòîðîãî èãðîêà:
2886 y := 336;
2887 player_stat(1);
2888 end
2889 else
2890 begin
2891 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
2892 y := 128;
2893 player_stat(0);
2894 end;
2895 end;
2897 procedure DrawLoadingStat();
2898 procedure drawRect (x, y, w, h: Integer);
2899 begin
2900 if (w < 1) or (h < 1) then exit;
2901 glBegin(GL_QUADS);
2902 glVertex2f(x+0.375, y+0.375);
2903 glVertex2f(x+w+0.375, y+0.375);
2904 glVertex2f(x+w+0.375, y+h+0.375);
2905 glVertex2f(x+0.375, y+h+0.375);
2906 glEnd();
2907 end;
2909 function drawPBar (cur, total: Integer; washere: Boolean): Boolean;
2910 var
2911 rectW, rectH: Integer;
2912 x0, y0: Integer;
2913 wdt: Integer;
2914 wl, hl: Integer;
2915 wr, hr: Integer;
2916 wb, hb: Integer;
2917 wm, hm: Integer;
2918 idl, idr, idb, idm: LongWord;
2919 f, my: Integer;
2920 begin
2921 result := false;
2922 if (total < 1) then exit;
2923 if (cur < 1) then exit; // don't blink
2924 if (not washere) and (cur >= total) then exit; // don't blink
2925 //if (cur < 0) then cur := 0;
2926 //if (cur > total) then cur := total;
2927 result := true;
2929 if (hasPBarGfx) then
2930 begin
2931 g_Texture_Get('UI_GFX_PBAR_LEFT', idl);
2932 g_Texture_GetSize('UI_GFX_PBAR_LEFT', wl, hl);
2933 g_Texture_Get('UI_GFX_PBAR_RIGHT', idr);
2934 g_Texture_GetSize('UI_GFX_PBAR_RIGHT', wr, hr);
2935 g_Texture_Get('UI_GFX_PBAR_MIDDLE', idb);
2936 g_Texture_GetSize('UI_GFX_PBAR_MIDDLE', wb, hb);
2937 g_Texture_Get('UI_GFX_PBAR_MARKER', idm);
2938 g_Texture_GetSize('UI_GFX_PBAR_MARKER', wm, hm);
2940 //rectW := gScreenWidth-360;
2941 rectW := trunc(624.0*gScreenWidth/1024.0);
2942 rectH := hl;
2944 x0 := (gScreenWidth-rectW) div 2;
2945 y0 := gScreenHeight-rectH-64;
2946 if (y0 < 2) then y0 := 2;
2948 glEnable(GL_SCISSOR_TEST);
2950 // left and right
2951 glScissor(x0, gScreenHeight-y0-rectH, rectW, rectH);
2952 e_DrawSize(idl, x0, y0, 0, true, false, wl, hl);
2953 e_DrawSize(idr, x0+rectW-wr, y0, 0, true, false, wr, hr);
2955 // body
2956 glScissor(x0+wl, gScreenHeight-y0-rectH, rectW-wl-wr, rectH);
2957 f := x0+wl;
2958 while (f < x0+rectW) do
2959 begin
2960 e_DrawSize(idb, f, y0, 0, true, false, wb, hb);
2961 f += wb;
2962 end;
2964 // filled part
2965 wdt := (rectW-wl-wr)*cur div total;
2966 if (wdt > rectW-wl-wr) then wdt := rectW-wr-wr;
2967 if (wdt > 0) then
2968 begin
2969 my := y0; // don't be so smart, ketmar: +(rectH-wm) div 2;
2970 glScissor(x0+wl, gScreenHeight-my-rectH, wdt, hm);
2971 f := x0+wl;
2972 while (wdt > 0) do
2973 begin
2974 e_DrawSize(idm, f, y0, 0, true, false, wm, hm);
2975 f += wm;
2976 wdt -= wm;
2977 end;
2978 end;
2980 glScissor(0, 0, gScreenWidth, gScreenHeight);
2981 end
2982 else
2983 begin
2984 rectW := gScreenWidth-64;
2985 rectH := 16;
2987 x0 := (gScreenWidth-rectW) div 2;
2988 y0 := gScreenHeight-rectH-64;
2989 if (y0 < 2) then y0 := 2;
2991 glDisable(GL_BLEND);
2992 glDisable(GL_TEXTURE_2D);
2994 //glClearColor(0, 0, 0, 0);
2995 //glClear(GL_COLOR_BUFFER_BIT);
2997 glColor4ub(127, 127, 127, 255);
2998 drawRect(x0-2, y0-2, rectW+4, rectH+4);
3000 glColor4ub(0, 0, 0, 255);
3001 drawRect(x0-1, y0-1, rectW+2, rectH+2);
3003 glColor4ub(127, 127, 127, 255);
3004 wdt := rectW*cur div total;
3005 if (wdt > rectW) then wdt := rectW;
3006 drawRect(x0, y0, wdt, rectH);
3007 end;
3008 end;
3010 var
3011 ww, hh: Word;
3012 xx, yy, i: Integer;
3013 s: String;
3014 begin
3015 if (Length(LoadingStat.Msgs) = 0) then exit;
3017 e_CharFont_GetSize(gMenuFont, _lc[I_MENU_LOADING], ww, hh);
3018 yy := (gScreenHeight div 3);
3019 e_CharFont_Print(gMenuFont, (gScreenWidth div 2)-(ww div 2), yy-2*hh, _lc[I_MENU_LOADING]);
3020 xx := (gScreenWidth div 3);
3022 with LoadingStat do
3023 begin
3024 for i := 0 to NextMsg-1 do
3025 begin
3026 if (i = (NextMsg-1)) and (MaxValue > 0) then
3027 s := Format('%s: %d/%d', [Msgs[i], CurValue, MaxValue])
3028 else
3029 s := Msgs[i];
3031 e_CharFont_PrintEx(gMenuSmallFont, xx, yy, s, _RGB(255, 0, 0));
3032 yy := yy + LOADING_INTERLINE;
3033 PBarWasHere := drawPBar(CurValue, MaxValue, PBarWasHere);
3034 end;
3035 end;
3036 end;
3038 procedure DrawMenuBackground(tex: AnsiString);
3039 var
3040 w, h: Word;
3041 ID: DWord;
3043 begin
3044 if g_Texture_Get(tex, ID) then
3045 begin
3046 e_Clear(GL_COLOR_BUFFER_BIT, 0, 0, 0);
3047 e_GetTextureSize(ID, @w, @h);
3048 if w = h then
3049 w := round(w * 1.333 * (gScreenHeight / h))
3050 else
3051 w := trunc(w * (gScreenHeight / h));
3052 e_DrawSize(ID, (gScreenWidth - w) div 2, 0, 0, False, False, w, gScreenHeight);
3053 end
3054 else e_Clear(GL_COLOR_BUFFER_BIT, 0, 0, 0);
3055 end;
3057 procedure DrawMinimap(p: TPlayer; RenderRect: e_graphics.TRect);
3058 var
3059 a, aX, aY, aX2, aY2, Scale, ScaleSz: Integer;
3061 function monDraw (mon: TMonster): Boolean;
3062 begin
3063 result := false; // don't stop
3064 with mon do
3065 begin
3066 if alive then
3067 begin
3068 // Ëåâûé âåðõíèé óãîë
3069 aX := Obj.X div ScaleSz + 1;
3070 aY := Obj.Y div ScaleSz + 1;
3071 // Ðàçìåðû
3072 aX2 := max(Obj.Rect.Width div ScaleSz, 1);
3073 aY2 := max(Obj.Rect.Height div ScaleSz, 1);
3074 // Ïðàâûé íèæíèé óãîë
3075 aX2 := aX + aX2 - 1;
3076 aY2 := aY + aY2 - 1;
3077 e_DrawFillQuad(aX, aY, aX2, aY2, 255, 255, 0, 0);
3078 end;
3079 end;
3080 end;
3082 begin
3083 if (gMapInfo.Width > RenderRect.Right - RenderRect.Left) or
3084 (gMapInfo.Height > RenderRect.Bottom - RenderRect.Top) then
3085 begin
3086 Scale := 1;
3087 // Ñêîëüêî ïèêñåëîâ êàðòû â 1 ïèêñåëå ìèíè-êàðòû:
3088 ScaleSz := 16 div Scale;
3089 // Ðàçìåðû ìèíè-êàðòû:
3090 aX := max(gMapInfo.Width div ScaleSz, 1);
3091 aY := max(gMapInfo.Height div ScaleSz, 1);
3092 // Ðàìêà êàðòû:
3093 e_DrawFillQuad(0, 0, aX-1, aY-1, 0, 0, 0, 0);
3095 if gWalls <> nil then
3096 begin
3097 // Ðèñóåì ñòåíû:
3098 for a := 0 to High(gWalls) do
3099 with gWalls[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 case PanelType of
3113 PANEL_WALL: e_DrawFillQuad(aX, aY, aX2, aY2, 208, 208, 208, 0);
3114 PANEL_OPENDOOR, PANEL_CLOSEDOOR:
3115 if Enabled then e_DrawFillQuad(aX, aY, aX2, aY2, 160, 160, 160, 0);
3116 end;
3117 end;
3118 end;
3119 if gSteps <> nil then
3120 begin
3121 // Ðèñóåì ñòóïåíè:
3122 for a := 0 to High(gSteps) do
3123 with gSteps[a] do
3124 if PanelType <> 0 then
3125 begin
3126 // Ëåâûé âåðõíèé óãîë:
3127 aX := X div ScaleSz;
3128 aY := Y div ScaleSz;
3129 // Ðàçìåðû:
3130 aX2 := max(Width div ScaleSz, 1);
3131 aY2 := max(Height div ScaleSz, 1);
3132 // Ïðàâûé íèæíèé óãîë:
3133 aX2 := aX + aX2 - 1;
3134 aY2 := aY + aY2 - 1;
3136 e_DrawFillQuad(aX, aY, aX2, aY2, 128, 128, 128, 0);
3137 end;
3138 end;
3139 if gLifts <> nil then
3140 begin
3141 // Ðèñóåì ëèôòû:
3142 for a := 0 to High(gLifts) do
3143 with gLifts[a] do
3144 if PanelType <> 0 then
3145 begin
3146 // Ëåâûé âåðõíèé óãîë:
3147 aX := X div ScaleSz;
3148 aY := Y div ScaleSz;
3149 // Ðàçìåðû:
3150 aX2 := max(Width div ScaleSz, 1);
3151 aY2 := max(Height div ScaleSz, 1);
3152 // Ïðàâûé íèæíèé óãîë:
3153 aX2 := aX + aX2 - 1;
3154 aY2 := aY + aY2 - 1;
3156 case LiftType of
3157 LIFTTYPE_UP: e_DrawFillQuad(aX, aY, aX2, aY2, 116, 72, 36, 0);
3158 LIFTTYPE_DOWN: e_DrawFillQuad(aX, aY, aX2, aY2, 116, 124, 96, 0);
3159 LIFTTYPE_LEFT: e_DrawFillQuad(aX, aY, aX2, aY2, 200, 80, 4, 0);
3160 LIFTTYPE_RIGHT: e_DrawFillQuad(aX, aY, aX2, aY2, 252, 140, 56, 0);
3161 end;
3162 end;
3163 end;
3164 if gWater <> nil then
3165 begin
3166 // Ðèñóåì âîäó:
3167 for a := 0 to High(gWater) do
3168 with gWater[a] do
3169 if PanelType <> 0 then
3170 begin
3171 // Ëåâûé âåðõíèé óãîë:
3172 aX := X div ScaleSz;
3173 aY := Y div ScaleSz;
3174 // Ðàçìåðû:
3175 aX2 := max(Width div ScaleSz, 1);
3176 aY2 := max(Height div ScaleSz, 1);
3177 // Ïðàâûé íèæíèé óãîë:
3178 aX2 := aX + aX2 - 1;
3179 aY2 := aY + aY2 - 1;
3181 e_DrawFillQuad(aX, aY, aX2, aY2, 0, 0, 192, 0);
3182 end;
3183 end;
3184 if gAcid1 <> nil then
3185 begin
3186 // Ðèñóåì êèñëîòó 1:
3187 for a := 0 to High(gAcid1) do
3188 with gAcid1[a] do
3189 if PanelType <> 0 then
3190 begin
3191 // Ëåâûé âåðõíèé óãîë:
3192 aX := X div ScaleSz;
3193 aY := Y div ScaleSz;
3194 // Ðàçìåðû:
3195 aX2 := max(Width div ScaleSz, 1);
3196 aY2 := max(Height div ScaleSz, 1);
3197 // Ïðàâûé íèæíèé óãîë:
3198 aX2 := aX + aX2 - 1;
3199 aY2 := aY + aY2 - 1;
3201 e_DrawFillQuad(aX, aY, aX2, aY2, 0, 176, 0, 0);
3202 end;
3203 end;
3204 if gAcid2 <> nil then
3205 begin
3206 // Ðèñóåì êèñëîòó 2:
3207 for a := 0 to High(gAcid2) do
3208 with gAcid2[a] do
3209 if PanelType <> 0 then
3210 begin
3211 // Ëåâûé âåðõíèé óãîë:
3212 aX := X div ScaleSz;
3213 aY := Y div ScaleSz;
3214 // Ðàçìåðû:
3215 aX2 := max(Width div ScaleSz, 1);
3216 aY2 := max(Height div ScaleSz, 1);
3217 // Ïðàâûé íèæíèé óãîë:
3218 aX2 := aX + aX2 - 1;
3219 aY2 := aY + aY2 - 1;
3221 e_DrawFillQuad(aX, aY, aX2, aY2, 176, 0, 0, 0);
3222 end;
3223 end;
3224 if gPlayers <> nil then
3225 begin
3226 // Ðèñóåì èãðîêîâ:
3227 for a := 0 to High(gPlayers) do
3228 if gPlayers[a] <> nil then with gPlayers[a] do
3229 if alive then begin
3230 // Ëåâûé âåðõíèé óãîë:
3231 aX := Obj.X div ScaleSz + 1;
3232 aY := Obj.Y div ScaleSz + 1;
3233 // Ðàçìåðû:
3234 aX2 := max(Obj.Rect.Width div ScaleSz, 1);
3235 aY2 := max(Obj.Rect.Height div ScaleSz, 1);
3236 // Ïðàâûé íèæíèé óãîë:
3237 aX2 := aX + aX2 - 1;
3238 aY2 := aY + aY2 - 1;
3240 if gPlayers[a] = p then
3241 e_DrawFillQuad(aX, aY, aX2, aY2, 0, 255, 0, 0)
3242 else
3243 case Team of
3244 TEAM_RED: e_DrawFillQuad(aX, aY, aX2, aY2, 255, 0, 0, 0);
3245 TEAM_BLUE: e_DrawFillQuad(aX, aY, aX2, aY2, 0, 0, 255, 0);
3246 else e_DrawFillQuad(aX, aY, aX2, aY2, 255, 128, 0, 0);
3247 end;
3248 end;
3249 end;
3250 // Ðèñóåì ìîíñòðîâ
3251 g_Mons_ForEach(monDraw);
3252 end;
3253 end;
3256 procedure renderAmbientQuad (hasAmbient: Boolean; constref ambColor: TDFColor);
3257 begin
3258 if not hasAmbient then exit;
3259 e_AmbientQuad(sX, sY, sWidth, sHeight, ambColor.r, ambColor.g, ambColor.b, ambColor.a);
3260 end;
3263 // setup sX, sY, sWidth, sHeight, and transformation matrix before calling this!
3264 //FIXME: broken for splitscreen mode
3265 procedure renderDynLightsInternal ();
3266 var
3267 //hasAmbient: Boolean;
3268 //ambColor: TDFColor;
3269 lln: Integer;
3270 lx, ly, lrad: Integer;
3271 scxywh: array[0..3] of GLint;
3272 wassc: Boolean;
3273 begin
3274 if e_NoGraphics then exit;
3276 //TODO: lights should be in separate grid, i think
3277 // but on the other side: grid may be slower for dynlights, as their lifetime is short
3278 if (not gwin_k8_enable_light_experiments) or (not gwin_has_stencil) or (g_dynLightCount < 1) then exit;
3280 // rendering mode
3281 //ambColor := gCurrentMap['light_ambient'].rgba;
3282 //hasAmbient := (not ambColor.isOpaque) or (not ambColor.isBlack);
3284 { // this will multiply incoming color to alpha from framebuffer
3285 glEnable(GL_BLEND);
3286 glBlendFunc(GL_DST_ALPHA, GL_ONE);
3289 (*
3290 * light rendering: (INVALID!)
3291 * glStencilFunc(GL_EQUAL, 0, $ff);
3292 * for each light:
3293 * glClear(GL_STENCIL_BUFFER_BIT);
3294 * glStencilOp(GL_KEEP, GL_KEEP, GL_INCR);
3295 * draw shadow volume into stencil buffer
3296 * glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); // modify color buffer
3297 * glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); // don't modify stencil buffer
3298 * turn off blending
3299 * draw color-less quad with light alpha (WARNING! don't touch color!)
3300 * glEnable(GL_BLEND);
3301 * glBlendFunc(GL_DST_ALPHA, GL_ONE);
3302 * draw all geometry up to and including walls (with alpha-testing, probably) -- this does lighting
3303 *)
3304 wassc := (glIsEnabled(GL_SCISSOR_TEST) <> 0);
3305 if wassc then glGetIntegerv(GL_SCISSOR_BOX, @scxywh[0]) else glGetIntegerv(GL_VIEWPORT, @scxywh[0]);
3307 // setup OpenGL parameters
3308 glStencilMask($FFFFFFFF);
3309 glStencilFunc(GL_ALWAYS, 0, $FFFFFFFF);
3310 glEnable(GL_STENCIL_TEST);
3311 glEnable(GL_SCISSOR_TEST);
3312 glClear(GL_STENCIL_BUFFER_BIT);
3313 glStencilFunc(GL_EQUAL, 0, $ff);
3315 for lln := 0 to g_dynLightCount-1 do
3316 begin
3317 lx := g_dynLights[lln].x;
3318 ly := g_dynLights[lln].y;
3319 lrad := g_dynLights[lln].radius;
3320 if (lrad < 3) then continue;
3322 if (lx-sX+lrad < 0) then continue;
3323 if (ly-sY+lrad < 0) then continue;
3324 if (lx-sX-lrad >= gPlayerScreenSize.X) then continue;
3325 if (ly-sY-lrad >= gPlayerScreenSize.Y) then continue;
3327 // set scissor to optimize drawing
3328 if (g_dbg_scale = 1.0) then
3329 begin
3330 glScissor((lx-sX)-lrad+2, gPlayerScreenSize.Y-(ly-sY)-lrad-1+2, lrad*2-4, lrad*2-4);
3331 end
3332 else
3333 begin
3334 glScissor(0, 0, gWinSizeX, gWinSizeY);
3335 end;
3336 // no need to clear stencil buffer, light blitting will do it for us... but only for normal scale
3337 if (g_dbg_scale <> 1.0) then glClear(GL_STENCIL_BUFFER_BIT);
3338 glStencilOp(GL_KEEP, GL_KEEP, GL_INCR);
3339 // draw extruded panels
3340 glDisable(GL_TEXTURE_2D);
3341 glDisable(GL_BLEND);
3342 glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); // no need to modify color buffer
3343 if (lrad > 4) then g_Map_DrawPanelShadowVolumes(lx, ly, lrad);
3344 // render light texture
3345 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); // modify color buffer
3346 glStencilOp(GL_ZERO, GL_ZERO, GL_ZERO); // draw light, and clear stencil buffer
3347 // blend it
3348 glEnable(GL_BLEND);
3349 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
3350 glEnable(GL_TEXTURE_2D);
3351 // color and opacity
3352 glColor4f(g_dynLights[lln].r, g_dynLights[lln].g, g_dynLights[lln].b, g_dynLights[lln].a);
3353 glBindTexture(GL_TEXTURE_2D, g_Texture_Light());
3354 glBegin(GL_QUADS);
3355 glTexCoord2f(0.0, 0.0); glVertex2i(lx-lrad, ly-lrad); // top-left
3356 glTexCoord2f(1.0, 0.0); glVertex2i(lx+lrad, ly-lrad); // top-right
3357 glTexCoord2f(1.0, 1.0); glVertex2i(lx+lrad, ly+lrad); // bottom-right
3358 glTexCoord2f(0.0, 1.0); glVertex2i(lx-lrad, ly+lrad); // bottom-left
3359 glEnd();
3360 end;
3362 // done
3363 glDisable(GL_STENCIL_TEST);
3364 glDisable(GL_BLEND);
3365 glDisable(GL_SCISSOR_TEST);
3366 //glScissor(0, 0, sWidth, sHeight);
3368 glScissor(scxywh[0], scxywh[1], scxywh[2], scxywh[3]);
3369 if wassc then glEnable(GL_SCISSOR_TEST) else glDisable(GL_SCISSOR_TEST);
3370 end;
3373 function fixViewportForScale (): Boolean;
3374 var
3375 nx0, ny0, nw, nh: Integer;
3376 begin
3377 result := false;
3378 if (g_dbg_scale <> 1.0) then
3379 begin
3380 result := true;
3381 nx0 := round(sX-(gPlayerScreenSize.X-(sWidth*g_dbg_scale))/2/g_dbg_scale);
3382 ny0 := round(sY-(gPlayerScreenSize.Y-(sHeight*g_dbg_scale))/2/g_dbg_scale);
3383 nw := round(sWidth/g_dbg_scale);
3384 nh := round(sHeight/g_dbg_scale);
3385 sX := nx0;
3386 sY := ny0;
3387 sWidth := nw;
3388 sHeight := nh;
3389 end;
3390 end;
3393 // setup sX, sY, sWidth, sHeight, and transformation matrix before calling this!
3394 // WARNING! this WILL CALL `glTranslatef()`, but won't restore matrices!
3395 procedure renderMapInternal (backXOfs, backYOfs: Integer; setTransMatrix: Boolean);
3396 type
3397 TDrawCB = procedure ();
3399 var
3400 hasAmbient: Boolean;
3401 ambColor: TDFColor;
3402 doAmbient: Boolean = false;
3404 procedure drawPanelType (profname: AnsiString; panType: DWord; doDraw: Boolean);
3405 var
3406 tagmask: Integer;
3407 pan: TPanel;
3408 begin
3409 if (profileFrameDraw <> nil) then profileFrameDraw.sectionBegin(profname);
3410 if gdbg_map_use_accel_render then
3411 begin
3412 tagmask := panelTypeToTag(panType);
3413 while (gDrawPanelList.count > 0) do
3414 begin
3415 pan := TPanel(gDrawPanelList.front());
3416 if ((pan.tag and tagmask) = 0) then break;
3417 if doDraw then pan.Draw(doAmbient, ambColor);
3418 gDrawPanelList.popFront();
3419 end;
3420 end
3421 else
3422 begin
3423 if doDraw then g_Map_DrawPanels(panType, hasAmbient, ambColor);
3424 end;
3425 if (profileFrameDraw <> nil) then profileFrameDraw.sectionEnd();
3426 end;
3428 procedure drawOther (profname: AnsiString; cb: TDrawCB);
3429 begin
3430 if (profileFrameDraw <> nil) then profileFrameDraw.sectionBegin(profname);
3431 if assigned(cb) then cb();
3432 if (profileFrameDraw <> nil) then profileFrameDraw.sectionEnd();
3433 end;
3435 begin
3436 if (profileFrameDraw <> nil) then profileFrameDraw.sectionBegin('total');
3438 // our accelerated renderer will collect all panels to gDrawPanelList
3439 // we can use panel tag to render level parts (see GridTagXXX in g_map.pas)
3440 if (profileFrameDraw <> nil) then profileFrameDraw.sectionBegin('collect');
3441 if gdbg_map_use_accel_render then
3442 begin
3443 g_Map_CollectDrawPanels(sX, sY, sWidth, sHeight);
3444 end;
3445 if (profileFrameDraw <> nil) then profileFrameDraw.sectionEnd();
3447 if (profileFrameDraw <> nil) then profileFrameDraw.sectionBegin('skyback');
3448 g_Map_DrawBack(backXOfs, backYOfs);
3449 if (profileFrameDraw <> nil) then profileFrameDraw.sectionEnd();
3451 if setTransMatrix then
3452 begin
3453 //if (g_dbg_scale <> 1.0) then glTranslatef(0.0, -0.375/2, 0);
3454 glScalef(g_dbg_scale, g_dbg_scale, 1.0);
3455 glTranslatef(-sX, -sY, 0);
3456 end;
3458 // rendering mode
3459 ambColor := gCurrentMap['light_ambient'].rgba;
3460 hasAmbient := (not ambColor.isOpaque) or (not ambColor.isBlack);
3463 if hasAmbient then
3464 begin
3465 //writeln('color: (', ambColor.r, ',', ambColor.g, ',', ambColor.b, ',', ambColor.a, ')');
3466 glColor4ub(ambColor.r, ambColor.g, ambColor.b, ambColor.a);
3467 glClear(GL_COLOR_BUFFER_BIT);
3468 end;
3470 //writeln('color: (', ambColor.r, ',', ambColor.g, ',', ambColor.b, ',', ambColor.a, ')');
3473 drawPanelType('*back', PANEL_BACK, g_rlayer_back);
3474 drawPanelType('*step', PANEL_STEP, g_rlayer_step);
3475 drawOther('items', @g_Items_Draw);
3476 drawOther('weapons', @g_Weapon_Draw);
3477 drawOther('shells', @g_Player_DrawShells);
3478 drawOther('drawall', @g_Player_DrawAll);
3479 drawOther('corpses', @g_Player_DrawCorpses);
3480 drawPanelType('*wall', PANEL_WALL, g_rlayer_wall);
3481 drawOther('monsters', @g_Monsters_Draw);
3482 drawOther('itemdrop', @g_Items_DrawDrop);
3483 drawPanelType('*door', PANEL_CLOSEDOOR, g_rlayer_door);
3484 drawOther('gfx', @g_GFX_Draw);
3485 drawOther('flags', @g_Map_DrawFlags);
3486 drawPanelType('*acid1', PANEL_ACID1, g_rlayer_acid1);
3487 drawPanelType('*acid2', PANEL_ACID2, g_rlayer_acid2);
3488 drawPanelType('*water', PANEL_WATER, g_rlayer_water);
3489 drawOther('dynlights', @renderDynLightsInternal);
3491 if hasAmbient {and ((not g_playerLight) or (not gwin_has_stencil) or (g_dynLightCount < 1))} then
3492 begin
3493 renderAmbientQuad(hasAmbient, ambColor);
3494 end;
3496 doAmbient := true;
3497 drawPanelType('*fore', PANEL_FORE, g_rlayer_fore);
3500 if g_debug_HealthBar then
3501 begin
3502 g_Monsters_DrawHealth();
3503 g_Player_DrawHealth();
3504 end;
3506 if (profileFrameDraw <> nil) then profileFrameDraw.mainEnd(); // map rendering
3507 end;
3510 procedure DrawMapView(x, y, w, h: Integer);
3512 var
3513 bx, by: Integer;
3514 begin
3515 glPushMatrix();
3517 bx := Round(x/(gMapInfo.Width - w)*(gBackSize.X - w));
3518 by := Round(y/(gMapInfo.Height - h)*(gBackSize.Y - h));
3520 sX := x;
3521 sY := y;
3522 sWidth := w;
3523 sHeight := h;
3525 fixViewportForScale();
3526 renderMapInternal(-bx, -by, true);
3528 glPopMatrix();
3529 end;
3532 procedure DrawPlayer(p: TPlayer);
3533 var
3534 px, py, a, b, c, d, i: Integer;
3535 //R: TRect;
3536 begin
3537 if (p = nil) or (p.FDummy) then
3538 begin
3539 glPushMatrix();
3540 g_Map_DrawBack(0, 0);
3541 glPopMatrix();
3542 Exit;
3543 end;
3545 if (profileFrameDraw = nil) then profileFrameDraw := TProfiler.Create('RENDER', g_profile_history_size);
3546 if (profileFrameDraw <> nil) then profileFrameDraw.mainBegin(g_profile_frame_draw);
3548 gPlayerDrawn := p;
3550 glPushMatrix();
3552 px := p.GameX + PLAYER_RECT_CX;
3553 py := p.GameY + PLAYER_RECT_CY+p.Obj.slopeUpLeft;
3555 if (g_dbg_scale = 1.0) and (not g_dbg_ignore_bounds) then
3556 begin
3557 if (px > (gPlayerScreenSize.X div 2)) then a := -px+(gPlayerScreenSize.X div 2) else a := 0;
3558 if (py > (gPlayerScreenSize.Y div 2)) then b := -py+(gPlayerScreenSize.Y div 2) else b := 0;
3560 if (px > gMapInfo.Width-(gPlayerScreenSize.X div 2)) then a := -gMapInfo.Width+gPlayerScreenSize.X;
3561 if (py > gMapInfo.Height-(gPlayerScreenSize.Y div 2)) then b := -gMapInfo.Height+gPlayerScreenSize.Y;
3563 if (gMapInfo.Width = gPlayerScreenSize.X) then a := 0
3564 else if (gMapInfo.Width < gPlayerScreenSize.X) then
3565 begin
3566 // hcenter
3567 a := (gPlayerScreenSize.X-gMapInfo.Width) div 2;
3568 end;
3570 if (gMapInfo.Height = gPlayerScreenSize.Y) then b := 0
3571 else if (gMapInfo.Height < gPlayerScreenSize.Y) then
3572 begin
3573 // vcenter
3574 b := (gPlayerScreenSize.Y-gMapInfo.Height) div 2;
3575 end;
3576 end
3577 else
3578 begin
3579 // scaled, ignore level bounds
3580 a := -px+(gPlayerScreenSize.X div 2);
3581 b := -py+(gPlayerScreenSize.Y div 2);
3582 end;
3584 if p.IncCam <> 0 then
3585 begin
3586 if py > gMapInfo.Height-(gPlayerScreenSize.Y div 2) then
3587 begin
3588 if p.IncCam > 120-(py-(gMapInfo.Height-(gPlayerScreenSize.Y div 2))) then
3589 begin
3590 p.IncCam := 120-(py-(gMapInfo.Height-(gPlayerScreenSize.Y div 2)));
3591 end;
3592 end;
3594 if py < gPlayerScreenSize.Y div 2 then
3595 begin
3596 if p.IncCam < -120+((gPlayerScreenSize.Y div 2)-py) then
3597 begin
3598 p.IncCam := -120+((gPlayerScreenSize.Y div 2)-py);
3599 end;
3600 end;
3602 if p.IncCam < 0 then
3603 begin
3604 while (py+(gPlayerScreenSize.Y div 2)-p.IncCam > gMapInfo.Height) and (p.IncCam < 0) do p.IncCam := p.IncCam+1; //Inc(p.IncCam);
3605 end;
3607 if p.IncCam > 0 then
3608 begin
3609 while (py-(gPlayerScreenSize.Y div 2)-p.IncCam < 0) and (p.IncCam > 0) do p.IncCam := p.IncCam-1; //Dec(p.IncCam);
3610 end;
3611 end;
3613 if (px < gPlayerScreenSize.X div 2) or (gMapInfo.Width-gPlayerScreenSize.X <= 256) then c := 0
3614 else if (px > gMapInfo.Width-(gPlayerScreenSize.X div 2)) then c := gBackSize.X-gPlayerScreenSize.X
3615 else c := round((px-(gPlayerScreenSize.X div 2))/(gMapInfo.Width-gPlayerScreenSize.X)*(gBackSize.X-gPlayerScreenSize.X));
3617 if (py-p.IncCam <= gPlayerScreenSize.Y div 2) or (gMapInfo.Height-gPlayerScreenSize.Y <= 256) then d := 0
3618 else if (py-p.IncCam >= gMapInfo.Height-(gPlayerScreenSize.Y div 2)) then d := gBackSize.Y-gPlayerScreenSize.Y
3619 else d := round((py-p.IncCam-(gPlayerScreenSize.Y div 2))/(gMapInfo.Height-gPlayerScreenSize.Y)*(gBackSize.Y-gPlayerScreenSize.Y));
3621 sX := -a;
3622 sY := -(b+p.IncCam);
3623 sWidth := gPlayerScreenSize.X;
3624 sHeight := gPlayerScreenSize.Y;
3626 //glTranslatef(a, b+p.IncCam, 0);
3628 //if (p = gPlayer1) and (g_dbg_scale >= 1.0) then g_Holmes_plrViewSize(sWidth, sHeight);
3630 //conwritefln('OLD: (%s,%s)-(%s,%s)', [sX, sY, sWidth, sHeight]);
3631 fixViewportForScale();
3632 //conwritefln(' (%s,%s)-(%s,%s)', [sX, sY, sWidth, sHeight]);
3634 if (g_dbg_scale <> 1.0) and (not g_dbg_ignore_bounds) then
3635 begin
3636 if (sX+sWidth > gMapInfo.Width) then sX := gMapInfo.Width-sWidth;
3637 if (sY+sHeight > gMapInfo.Height) then sY := gMapInfo.Height-sHeight;
3638 if (sX < 0) then sX := 0;
3639 if (sY < 0) then sY := 0;
3641 if (gBackSize.X <= gPlayerScreenSize.X) or (gMapInfo.Width <= sWidth) then c := 0 else c := trunc((gBackSize.X-gPlayerScreenSize.X)*sX/(gMapInfo.Width-sWidth));
3642 if (gBackSize.Y <= gPlayerScreenSize.Y) or (gMapInfo.Height <= sHeight) then d := 0 else d := trunc((gBackSize.Y-gPlayerScreenSize.Y)*sY/(gMapInfo.Height-sHeight));
3643 end;
3645 //r_smallmap_h: 0: left; 1: center; 2: right
3646 //r_smallmap_v: 0: top; 1: center; 2: bottom
3647 // horiz small map?
3648 if (gMapInfo.Width = sWidth) then
3649 begin
3650 sX := 0;
3651 end
3652 else if (gMapInfo.Width < sWidth) then
3653 begin
3654 case r_smallmap_h of
3655 1: sX := -((sWidth-gMapInfo.Width) div 2); // center
3656 2: sX := -(sWidth-gMapInfo.Width); // right
3657 else sX := 0; // left
3658 end;
3659 end;
3660 // vert small map?
3661 if (gMapInfo.Height = sHeight) then
3662 begin
3663 sY := 0;
3664 end
3665 else if (gMapInfo.Height < sHeight) then
3666 begin
3667 case r_smallmap_v of
3668 1: sY := -((sHeight-gMapInfo.Height) div 2); // center
3669 2: sY := -(sHeight-gMapInfo.Height); // bottom
3670 else sY := 0; // top
3671 end;
3672 end;
3674 p.viewPortX := sX;
3675 p.viewPortY := sY;
3676 p.viewPortW := sWidth;
3677 p.viewPortH := sHeight;
3679 {$IFDEF ENABLE_HOLMES}
3680 if (p = gPlayer1) then
3681 begin
3682 g_Holmes_plrViewPos(sX, sY);
3683 g_Holmes_plrViewSize(sWidth, sHeight);
3684 end;
3685 {$ENDIF}
3687 renderMapInternal(-c, -d, true);
3689 if (gGameSettings.GameMode <> GM_SINGLE) and (gPlayerIndicator > 0) then
3690 case gPlayerIndicator of
3691 1:
3692 p.DrawIndicator(_RGB(255, 255, 255));
3694 2:
3695 for i := 0 to High(gPlayers) do
3696 if gPlayers[i] <> nil then
3697 if gPlayers[i] = p then p.DrawIndicator(_RGB(255, 255, 255))
3698 else if (gPlayers[i].Team = p.Team) and (gPlayers[i].Team <> TEAM_NONE) then
3699 if gPlayerIndicatorStyle = 1 then
3700 gPlayers[i].DrawIndicator(_RGB(192, 192, 192))
3701 else gPlayers[i].DrawIndicator(gPlayers[i].GetColor);
3702 end;
3704 if p.FSpectator then
3705 e_TextureFontPrintEx(p.GameX + PLAYER_RECT_CX - 4,
3706 p.GameY + PLAYER_RECT_CY - 4,
3707 'X', gStdFont, 255, 255, 255, 1, True);
3709 for a := 0 to High(gCollideMap) do
3710 for b := 0 to High(gCollideMap[a]) do
3711 begin
3712 d := 0;
3713 if ByteBool(gCollideMap[a, b] and MARK_WALL) then
3714 d := d + 1;
3715 if ByteBool(gCollideMap[a, b] and MARK_DOOR) then
3716 d := d + 2;
3718 case d of
3719 1: e_DrawPoint(1, b, a, 200, 200, 200);
3720 2: e_DrawPoint(1, b, a, 64, 64, 255);
3721 3: e_DrawPoint(1, b, a, 255, 0, 255);
3722 end;
3723 end;
3726 glPopMatrix();
3728 p.DrawPain();
3729 p.DrawPickup();
3730 p.DrawRulez();
3731 if gShowMap then DrawMinimap(p, _TRect(0, 0, 128, 128));
3732 if g_Debug_Player then
3733 g_Player_DrawDebug(p);
3734 p.DrawGUI();
3735 end;
3737 procedure drawProfilers ();
3738 var
3739 px: Integer = -1;
3740 py: Integer = -1;
3741 begin
3742 if g_profile_frame_draw and (profileFrameDraw <> nil) then px := px-drawProfiles(px, py, profileFrameDraw);
3743 if g_profile_collision and (profMapCollision <> nil) then begin px := px-drawProfiles(px, py, profMapCollision); py -= calcProfilesHeight(profMonsLOS); end;
3744 if g_profile_los and (profMonsLOS <> nil) then begin px := px-drawProfiles(px, py, profMonsLOS); py -= calcProfilesHeight(profMonsLOS); end;
3745 end;
3747 procedure g_Game_Draw();
3748 var
3749 ID: DWORD;
3750 w, h: Word;
3751 ww, hh: Byte;
3752 Time: Int64;
3753 back: string;
3754 plView1, plView2: TPlayer;
3755 Split: Boolean;
3756 begin
3757 if gExit = EXIT_QUIT then Exit;
3759 Time := sys_GetTicks() {div 1000};
3760 FPSCounter := FPSCounter+1;
3761 if Time - FPSTime >= 1000 then
3762 begin
3763 FPS := FPSCounter;
3764 FPSCounter := 0;
3765 FPSTime := Time;
3766 end;
3768 if gGameOn or (gState = STATE_FOLD) then
3769 begin
3770 if (gPlayer1 <> nil) and (gPlayer2 <> nil) then
3771 begin
3772 gSpectMode := SPECT_NONE;
3773 if not gRevertPlayers then
3774 begin
3775 plView1 := gPlayer1;
3776 plView2 := gPlayer2;
3777 end
3778 else
3779 begin
3780 plView1 := gPlayer2;
3781 plView2 := gPlayer1;
3782 end;
3783 end
3784 else
3785 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
3786 begin
3787 gSpectMode := SPECT_NONE;
3788 if gPlayer2 = nil then
3789 plView1 := gPlayer1
3790 else
3791 plView1 := gPlayer2;
3792 plView2 := nil;
3793 end
3794 else
3795 begin
3796 plView1 := nil;
3797 plView2 := nil;
3798 end;
3800 if (plView1 = nil) and (plView2 = nil) and (gSpectMode = SPECT_NONE) then
3801 gSpectMode := SPECT_STATS;
3803 if gSpectMode = SPECT_PLAYERS then
3804 if gPlayers <> nil then
3805 begin
3806 plView1 := GetActivePlayer_ByID(gSpectPID1);
3807 if plView1 = nil then
3808 begin
3809 gSpectPID1 := GetActivePlayerID_Next();
3810 plView1 := GetActivePlayer_ByID(gSpectPID1);
3811 end;
3812 if gSpectViewTwo then
3813 begin
3814 plView2 := GetActivePlayer_ByID(gSpectPID2);
3815 if plView2 = nil then
3816 begin
3817 gSpectPID2 := GetActivePlayerID_Next();
3818 plView2 := GetActivePlayer_ByID(gSpectPID2);
3819 end;
3820 end;
3821 end;
3823 if gSpectMode = SPECT_MAPVIEW then
3824 begin
3825 // Ðåæèì ïðîñìîòðà êàðòû
3826 Split := False;
3827 e_SetViewPort(0, 0, gScreenWidth, gScreenHeight);
3828 DrawMapView(gSpectX, gSpectY, gScreenWidth, gScreenHeight);
3829 gHearPoint1.Active := True;
3830 gHearPoint1.Coords.X := gScreenWidth div 2 + gSpectX;
3831 gHearPoint1.Coords.Y := gScreenHeight div 2 + gSpectY;
3832 gHearPoint2.Active := False;
3833 end
3834 else
3835 begin
3836 Split := (plView1 <> nil) and (plView2 <> nil);
3838 // Òî÷êè ñëóõà èãðîêîâ
3839 if plView1 <> nil then
3840 begin
3841 gHearPoint1.Active := True;
3842 gHearPoint1.Coords.X := plView1.GameX + PLAYER_RECT.Width;
3843 gHearPoint1.Coords.Y := plView1.GameY + PLAYER_RECT.Height DIV 2;
3844 end else
3845 gHearPoint1.Active := False;
3846 if plView2 <> nil then
3847 begin
3848 gHearPoint2.Active := True;
3849 gHearPoint2.Coords.X := plView2.GameX + PLAYER_RECT.Width;
3850 gHearPoint2.Coords.Y := plView2.GameY + PLAYER_RECT.Height DIV 2;
3851 end else
3852 gHearPoint2.Active := False;
3854 // Ðàçìåð ýêðàíîâ èãðîêîâ:
3855 gPlayerScreenSize.X := gScreenWidth-196;
3856 if Split then
3857 begin
3858 gPlayerScreenSize.Y := gScreenHeight div 2;
3859 if gScreenHeight mod 2 = 0 then
3860 Dec(gPlayerScreenSize.Y);
3861 end
3862 else
3863 gPlayerScreenSize.Y := gScreenHeight;
3865 if Split then
3866 if gScreenHeight mod 2 = 0 then
3867 e_SetViewPort(0, gPlayerScreenSize.Y+2, gPlayerScreenSize.X+196, gPlayerScreenSize.Y)
3868 else
3869 e_SetViewPort(0, gPlayerScreenSize.Y+1, gPlayerScreenSize.X+196, gPlayerScreenSize.Y);
3871 DrawPlayer(plView1);
3872 gPlayer1ScreenCoord.X := sX;
3873 gPlayer1ScreenCoord.Y := sY;
3875 if Split then
3876 begin
3877 e_SetViewPort(0, 0, gPlayerScreenSize.X+196, gPlayerScreenSize.Y);
3879 DrawPlayer(plView2);
3880 gPlayer2ScreenCoord.X := sX;
3881 gPlayer2ScreenCoord.Y := sY;
3882 end;
3884 e_SetViewPort(0, 0, gScreenWidth, gScreenHeight);
3886 if Split then
3887 e_DrawLine(2, 0, gScreenHeight div 2, gScreenWidth, gScreenHeight div 2, 0, 0, 0);
3888 end;
3890 {$IFDEF ENABLE_HOLMES}
3891 // draw inspector
3892 if (g_holmes_enabled) then g_Holmes_Draw();
3893 {$ENDIF}
3895 if MessageText <> '' then
3896 begin
3897 w := 0;
3898 h := 0;
3899 e_CharFont_GetSizeFmt(gMenuFont, MessageText, w, h);
3900 if Split then
3901 e_CharFont_PrintFmt(gMenuFont, (gScreenWidth div 2)-(w div 2),
3902 (gScreenHeight div 2)-(h div 2), MessageText)
3903 else
3904 e_CharFont_PrintFmt(gMenuFont, (gScreenWidth div 2)-(w div 2),
3905 Round(gScreenHeight / 2.75)-(h div 2), MessageText);
3906 end;
3908 if IsDrawStat or (gSpectMode = 1) then DrawStat();
3910 if gSpectHUD and (not gChatShow) and (gSpectMode <> SPECT_NONE) and (not gSpectAuto) then
3911 begin
3912 // Draw spectator GUI
3913 ww := 0;
3914 hh := 0;
3915 e_TextureFontGetSize(gStdFont, ww, hh);
3916 case gSpectMode of
3917 SPECT_STATS:
3918 e_TextureFontPrintEx(0, gScreenHeight - (hh+2)*2, 'MODE: Stats', gStdFont, 255, 255, 255, 1);
3919 SPECT_MAPVIEW:
3920 e_TextureFontPrintEx(0, gScreenHeight - (hh+2)*2, 'MODE: Observe Map', gStdFont, 255, 255, 255, 1);
3921 SPECT_PLAYERS:
3922 e_TextureFontPrintEx(0, gScreenHeight - (hh+2)*2, 'MODE: Watch Players', gStdFont, 255, 255, 255, 1);
3923 end;
3924 e_TextureFontPrintEx(2*ww, gScreenHeight - (hh+2), '< jump >', gStdFont, 255, 255, 255, 1);
3925 if gSpectMode = SPECT_STATS then
3926 begin
3927 e_TextureFontPrintEx(16*ww, gScreenHeight - (hh+2)*2, 'Autoview', gStdFont, 255, 255, 255, 1);
3928 e_TextureFontPrintEx(16*ww, gScreenHeight - (hh+2), '< fire >', gStdFont, 255, 255, 255, 1);
3929 end;
3930 if gSpectMode = SPECT_MAPVIEW then
3931 begin
3932 e_TextureFontPrintEx(22*ww, gScreenHeight - (hh+2)*2, '[-]', gStdFont, 255, 255, 255, 1);
3933 e_TextureFontPrintEx(26*ww, gScreenHeight - (hh+2)*2, 'Step ' + IntToStr(gSpectStep), gStdFont, 255, 255, 255, 1);
3934 e_TextureFontPrintEx(34*ww, gScreenHeight - (hh+2)*2, '[+]', gStdFont, 255, 255, 255, 1);
3935 e_TextureFontPrintEx(18*ww, gScreenHeight - (hh+2), '<prev weap>', gStdFont, 255, 255, 255, 1);
3936 e_TextureFontPrintEx(30*ww, gScreenHeight - (hh+2), '<next weap>', gStdFont, 255, 255, 255, 1);
3937 end;
3938 if gSpectMode = SPECT_PLAYERS then
3939 begin
3940 e_TextureFontPrintEx(22*ww, gScreenHeight - (hh+2)*2, 'Player 1', gStdFont, 255, 255, 255, 1);
3941 e_TextureFontPrintEx(20*ww, gScreenHeight - (hh+2), '<left/right>', gStdFont, 255, 255, 255, 1);
3942 if gSpectViewTwo then
3943 begin
3944 e_TextureFontPrintEx(37*ww, gScreenHeight - (hh+2)*2, 'Player 2', gStdFont, 255, 255, 255, 1);
3945 e_TextureFontPrintEx(34*ww, gScreenHeight - (hh+2), '<prev w/next w>', gStdFont, 255, 255, 255, 1);
3946 e_TextureFontPrintEx(52*ww, gScreenHeight - (hh+2)*2, '2x View', gStdFont, 255, 255, 255, 1);
3947 e_TextureFontPrintEx(51*ww, gScreenHeight - (hh+2), '<up/down>', gStdFont, 255, 255, 255, 1);
3948 end
3949 else
3950 begin
3951 e_TextureFontPrintEx(35*ww, gScreenHeight - (hh+2)*2, '2x View', gStdFont, 255, 255, 255, 1);
3952 e_TextureFontPrintEx(34*ww, gScreenHeight - (hh+2), '<up/down>', gStdFont, 255, 255, 255, 1);
3953 end;
3954 end;
3955 end;
3956 end;
3958 if gPauseMain and gGameOn and (g_ActiveWindow = nil) then
3959 begin
3960 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
3961 e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
3963 e_CharFont_GetSize(gMenuFont, _lc[I_MENU_PAUSE], w, h);
3964 e_CharFont_Print(gMenuFont, (gScreenWidth div 2)-(w div 2),
3965 (gScreenHeight div 2)-(h div 2), _lc[I_MENU_PAUSE]);
3966 end;
3968 if not gGameOn then
3969 begin
3970 if (gState = STATE_MENU) then
3971 begin
3972 if (g_ActiveWindow = nil) or (g_ActiveWindow.BackTexture = '') then DrawMenuBackground('MENU_BACKGROUND');
3973 // F3 at menu will show game loading dialog
3974 if e_KeyPressed(IK_F3) then g_Menu_Show_LoadMenu(true);
3975 if (g_ActiveWindow <> nil) then
3976 begin
3977 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
3978 e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
3979 end
3980 else
3981 begin
3982 // F3 at titlepic will show game loading dialog
3983 if e_KeyPressed(IK_F3) then
3984 begin
3985 g_Menu_Show_LoadMenu(true);
3986 if (g_ActiveWindow <> nil) then e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
3987 end;
3988 end;
3989 end;
3991 if gState = STATE_FOLD then
3992 begin
3993 e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 0, 0, 0, EndingGameCounter);
3994 end;
3996 if gState = STATE_INTERCUSTOM then
3997 begin
3998 if gLastMap and (gGameSettings.GameMode = GM_COOP) then
3999 begin
4000 back := 'TEXTURE_endpic';
4001 if not g_Texture_Get(back, ID) then
4002 back := _lc[I_TEXTURE_ENDPIC];
4003 end
4004 else
4005 back := 'INTER';
4007 DrawMenuBackground(back);
4009 DrawCustomStat();
4011 if g_ActiveWindow <> nil then
4012 begin
4013 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4014 e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
4015 end;
4016 end;
4018 if gState = STATE_INTERSINGLE then
4019 begin
4020 if EndingGameCounter > 0 then
4021 begin
4022 e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 0, 0, 0, EndingGameCounter);
4023 end
4024 else
4025 begin
4026 back := 'INTER';
4028 DrawMenuBackground(back);
4030 DrawSingleStat();
4032 if g_ActiveWindow <> nil then
4033 begin
4034 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4035 e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
4036 end;
4037 end;
4038 end;
4040 if gState = STATE_ENDPIC then
4041 begin
4042 ID := DWORD(-1);
4043 if g_Texture_Get('TEXTURE_endpic', ID) then DrawMenuBackground('TEXTURE_endpic')
4044 else DrawMenuBackground(_lc[I_TEXTURE_ENDPIC]);
4046 if g_ActiveWindow <> nil then
4047 begin
4048 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4049 e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
4050 end;
4051 end;
4053 if gState = STATE_SLIST then
4054 begin
4055 // if g_Texture_Get('MENU_BACKGROUND', ID) then
4056 // begin
4057 // e_DrawSize(ID, 0, 0, 0, False, False, gScreenWidth, gScreenHeight);
4058 // //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4059 // end;
4060 DrawMenuBackground('MENU_BACKGROUND');
4061 e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
4062 g_Serverlist_Draw(slCurrent, slTable);
4063 end;
4064 end;
4066 if g_ActiveWindow <> nil then
4067 begin
4068 if gGameOn then
4069 begin
4070 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4071 e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
4072 end;
4073 g_ActiveWindow.Draw();
4074 end;
4076 {$IFNDEF HEADLESS}
4077 g_Console_Draw();
4078 {$ENDIF}
4080 if g_debug_Sounds and gGameOn then
4081 begin
4082 for w := 0 to High(e_SoundsArray) do
4083 for h := 0 to e_SoundsArray[w].nRefs do
4084 e_DrawPoint(1, w+100, h+100, 255, 0, 0);
4085 end;
4087 if gShowFPS then
4088 begin
4089 e_TextureFontPrint(0, 0, Format('FPS: %d', [FPS]), gStdFont);
4090 e_TextureFontPrint(0, 16, Format('UPS: %d', [UPS]), gStdFont);
4091 end;
4093 if gGameOn and gShowTime then
4094 drawTime(gScreenWidth-72, gScreenHeight-16);
4096 if gGameOn then drawProfilers();
4098 {$IFDEF ENABLE_HOLMES}
4099 g_Holmes_DrawUI();
4100 {$ENDIF}
4102 g_Touch_Draw;
4103 end;
4105 procedure g_Game_Quit();
4106 begin
4107 g_Game_StopAllSounds(True);
4108 gMusic.Free();
4109 g_Game_SaveOptions();
4110 g_Game_FreeData();
4111 g_PlayerModel_FreeData();
4112 g_Texture_DeleteAll();
4113 g_Frames_DeleteAll();
4114 {$IFNDEF HEADLESS}
4115 //g_Menu_Free(); //k8: this segfaults after resolution change; who cares?
4116 {$ENDIF}
4118 if NetInitDone then g_Net_Free;
4120 // Íàäî óäàëèòü êàðòó ïîñëå òåñòà:
4121 if gMapToDelete <> '' then
4122 g_Game_DeleteTestMap();
4124 gExit := EXIT_QUIT;
4125 sys_RequestQuit;
4126 end;
4128 procedure g_FatalError(Text: String);
4129 begin
4130 g_Console_Add(Format(_lc[I_FATAL_ERROR], [Text]), True);
4131 e_WriteLog(Format(_lc[I_FATAL_ERROR], [Text]), TMsgType.Warning);
4133 gExit := EXIT_SIMPLE;
4134 end;
4136 procedure g_SimpleError(Text: String);
4137 begin
4138 g_Console_Add(Format(_lc[I_SIMPLE_ERROR], [Text]), True);
4139 e_WriteLog(Format(_lc[I_SIMPLE_ERROR], [Text]), TMsgType.Warning);
4140 end;
4142 procedure g_Game_SetupScreenSize();
4143 const
4144 RES_FACTOR = 4.0 / 3.0;
4145 var
4146 s: Single;
4147 rf: Single;
4148 bw, bh: Word;
4149 begin
4150 // Ðàçìåð ýêðàíîâ èãðîêîâ:
4151 gPlayerScreenSize.X := gScreenWidth-196;
4152 if (gPlayer1 <> nil) and (gPlayer2 <> nil) then
4153 gPlayerScreenSize.Y := gScreenHeight div 2
4154 else
4155 gPlayerScreenSize.Y := gScreenHeight;
4157 // Ðàçìåð çàäíåãî ïëàíà:
4158 if BackID <> DWORD(-1) then
4159 begin
4160 s := SKY_STRETCH;
4161 if (gScreenWidth*s > gMapInfo.Width) or
4162 (gScreenHeight*s > gMapInfo.Height) then
4163 begin
4164 gBackSize.X := gScreenWidth;
4165 gBackSize.Y := gScreenHeight;
4166 end
4167 else
4168 begin
4169 e_GetTextureSize(BackID, @bw, @bh);
4170 rf := Single(bw) / Single(bh);
4171 if (rf > RES_FACTOR) then bw := Round(Single(bh) * RES_FACTOR)
4172 else if (rf < RES_FACTOR) then bh := Round(Single(bw) / RES_FACTOR);
4173 s := Max(gScreenWidth / bw, gScreenHeight / bh);
4174 if (s < 1.0) then s := 1.0;
4175 gBackSize.X := Round(bw*s);
4176 gBackSize.Y := Round(bh*s);
4177 end;
4178 end;
4179 end;
4181 procedure g_Game_ChangeResolution(newWidth, newHeight: Word; nowFull, nowMax: Boolean);
4182 begin
4183 sys_SetDisplayMode(newWidth, newHeight, gBPP, nowFull);
4184 end;
4186 procedure g_Game_AddPlayer(Team: Byte = TEAM_NONE);
4187 begin
4188 if ((not gGameOn) and (gState <> STATE_INTERCUSTOM))
4189 or (not (gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT])) then
4190 Exit;
4191 if gPlayer1 = nil then
4192 begin
4193 if g_Game_IsClient then
4194 begin
4195 if NetPlrUID1 > -1 then
4196 begin
4197 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE);
4198 gPlayer1 := g_Player_Get(NetPlrUID1);
4199 end;
4200 Exit;
4201 end;
4203 if not (Team in [TEAM_RED, TEAM_BLUE]) then
4204 Team := gPlayer1Settings.Team;
4206 // Ñîçäàíèå ïåðâîãî èãðîêà:
4207 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
4208 gPlayer1Settings.Color,
4209 Team, False));
4210 if gPlayer1 = nil then
4211 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]))
4212 else
4213 begin
4214 gPlayer1.Name := gPlayer1Settings.Name;
4215 g_Console_Add(Format(_lc[I_PLAYER_JOIN], [gPlayer1.Name]), True);
4216 if g_Game_IsServer and g_Game_IsNet then
4217 MH_SEND_PlayerCreate(gPlayer1.UID);
4218 gPlayer1.Respawn(False, True);
4219 g_Net_Slist_ServerPlayerComes();
4220 end;
4222 Exit;
4223 end;
4224 if gPlayer2 = nil then
4225 begin
4226 if g_Game_IsClient then
4227 begin
4228 if NetPlrUID2 > -1 then
4229 gPlayer2 := g_Player_Get(NetPlrUID2);
4230 Exit;
4231 end;
4233 if not (Team in [TEAM_RED, TEAM_BLUE]) then
4234 Team := gPlayer2Settings.Team;
4236 // Ñîçäàíèå âòîðîãî èãðîêà:
4237 gPlayer2 := g_Player_Get(g_Player_Create(gPlayer2Settings.Model,
4238 gPlayer2Settings.Color,
4239 Team, False));
4240 if gPlayer2 = nil then
4241 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [2]))
4242 else
4243 begin
4244 gPlayer2.Name := gPlayer2Settings.Name;
4245 g_Console_Add(Format(_lc[I_PLAYER_JOIN], [gPlayer2.Name]), True);
4246 if g_Game_IsServer and g_Game_IsNet then
4247 MH_SEND_PlayerCreate(gPlayer2.UID);
4248 gPlayer2.Respawn(False, True);
4249 g_Net_Slist_ServerPlayerComes();
4250 end;
4252 Exit;
4253 end;
4254 end;
4256 procedure g_Game_RemovePlayer();
4257 var
4258 Pl: TPlayer;
4259 begin
4260 if ((not gGameOn) and (gState <> STATE_INTERCUSTOM))
4261 or (not (gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT])) then
4262 Exit;
4263 Pl := gPlayer2;
4264 if Pl <> nil then
4265 begin
4266 if g_Game_IsServer then
4267 begin
4268 Pl.Lives := 0;
4269 Pl.Kill(K_SIMPLEKILL, 0, HIT_DISCON);
4270 g_Console_Add(Format(_lc[I_PLAYER_LEAVE], [Pl.Name]), True);
4271 g_Player_Remove(Pl.UID);
4272 g_Net_Slist_ServerPlayerLeaves();
4273 end else
4274 gPlayer2 := nil;
4275 Exit;
4276 end;
4277 Pl := gPlayer1;
4278 if Pl <> nil then
4279 begin
4280 if g_Game_IsServer then
4281 begin
4282 Pl.Lives := 0;
4283 Pl.Kill(K_SIMPLEKILL, 0, HIT_DISCON);
4284 g_Console_Add(Format(_lc[I_PLAYER_LEAVE], [Pl.Name]), True);
4285 g_Player_Remove(Pl.UID);
4286 g_Net_Slist_ServerPlayerLeaves();
4287 end else
4288 begin
4289 gPlayer1 := nil;
4290 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE);
4291 end;
4292 Exit;
4293 end;
4294 g_Net_Slist_ServerPlayerLeaves();
4295 end;
4297 procedure g_Game_Spectate();
4298 begin
4299 g_Game_RemovePlayer();
4300 if gPlayer1 <> nil then
4301 g_Game_RemovePlayer();
4302 end;
4304 procedure g_Game_SpectateCenterView();
4305 begin
4306 gSpectX := Max(gMapInfo.Width div 2 - gScreenWidth div 2, 0);
4307 gSpectY := Max(gMapInfo.Height div 2 - gScreenHeight div 2, 0);
4308 end;
4310 procedure g_Game_StartSingle(Map: String; TwoPlayers: Boolean; nPlayers: Byte);
4311 var
4312 i, nPl: Integer;
4313 tmps: AnsiString;
4314 begin
4315 g_Game_Free();
4317 e_WriteLog('Starting singleplayer game...', TMsgType.Notify);
4319 g_Game_ClearLoading();
4321 // Íàñòðîéêè èãðû:
4322 FillByte(gGameSettings, SizeOf(TGameSettings), 0);
4323 gAimLine := False;
4324 gShowMap := False;
4325 gGameSettings.GameType := GT_SINGLE;
4326 gGameSettings.MaxLives := 0;
4327 gGameSettings.Options := gGameSettings.Options + GAME_OPTION_ALLOWEXIT;
4328 gGameSettings.Options := gGameSettings.Options + GAME_OPTION_MONSTERS;
4329 gGameSettings.Options := gGameSettings.Options + GAME_OPTION_BOTVSMONSTER;
4330 gSwitchGameMode := GM_SINGLE;
4332 g_Game_ExecuteEvent('ongamestart');
4334 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
4335 g_Game_SetupScreenSize();
4337 // Ñîçäàíèå ïåðâîãî èãðîêà:
4338 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
4339 gPlayer1Settings.Color,
4340 gPlayer1Settings.Team, False));
4341 if gPlayer1 = nil then
4342 begin
4343 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]));
4344 Exit;
4345 end;
4347 gPlayer1.Name := gPlayer1Settings.Name;
4348 nPl := 1;
4350 // Ñîçäàíèå âòîðîãî èãðîêà, åñëè åñòü:
4351 if TwoPlayers then
4352 begin
4353 gPlayer2 := g_Player_Get(g_Player_Create(gPlayer2Settings.Model,
4354 gPlayer2Settings.Color,
4355 gPlayer2Settings.Team, False));
4356 if gPlayer2 = nil then
4357 begin
4358 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [2]));
4359 Exit;
4360 end;
4362 gPlayer2.Name := gPlayer2Settings.Name;
4363 Inc(nPl);
4364 end;
4366 // Çàãðóçêà è çàïóñê êàðòû:
4367 if not g_Game_StartMap(false{asMegawad}, MAP, True) then
4368 begin
4369 if (Pos(':\', Map) > 0) or (Pos(':/', Map) > 0) then tmps := Map else tmps := gGameSettings.WAD + ':\' + MAP;
4370 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [tmps]));
4371 Exit;
4372 end;
4374 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4375 g_Player_Init();
4377 // Ñîçäàåì áîòîâ:
4378 for i := nPl+1 to nPlayers do
4379 g_Player_Create(STD_PLAYER_MODEL, _RGB(0, 0, 0), 0, True);
4380 end;
4382 procedure g_Game_StartCustom(Map: String; GameMode: Byte;
4383 TimeLimit, GoalLimit: Word;
4384 MaxLives: Byte;
4385 Options: LongWord; nPlayers: Byte);
4386 var
4387 i, nPl: Integer;
4388 begin
4389 g_Game_Free();
4391 e_WriteLog('Starting custom game...', TMsgType.Notify);
4393 g_Game_ClearLoading();
4395 // Íàñòðîéêè èãðû:
4396 gGameSettings.GameType := GT_CUSTOM;
4397 gGameSettings.GameMode := GameMode;
4398 gSwitchGameMode := GameMode;
4399 gGameSettings.TimeLimit := TimeLimit;
4400 gGameSettings.GoalLimit := GoalLimit;
4401 gGameSettings.MaxLives := IfThen(GameMode = GM_CTF, 0, MaxLives);
4402 gGameSettings.Options := Options;
4404 gCoopTotalMonstersKilled := 0;
4405 gCoopTotalSecretsFound := 0;
4406 gCoopTotalMonsters := 0;
4407 gCoopTotalSecrets := 0;
4408 gAimLine := False;
4409 gShowMap := False;
4411 g_Game_ExecuteEvent('ongamestart');
4413 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
4414 g_Game_SetupScreenSize();
4416 // Ðåæèì íàáëþäàòåëÿ:
4417 if nPlayers = 0 then
4418 begin
4419 gPlayer1 := nil;
4420 gPlayer2 := nil;
4421 end;
4423 nPl := 0;
4424 if nPlayers >= 1 then
4425 begin
4426 // Ñîçäàíèå ïåðâîãî èãðîêà:
4427 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
4428 gPlayer1Settings.Color,
4429 gPlayer1Settings.Team, False));
4430 if gPlayer1 = nil then
4431 begin
4432 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]));
4433 Exit;
4434 end;
4436 gPlayer1.Name := gPlayer1Settings.Name;
4437 Inc(nPl);
4438 end;
4440 if nPlayers >= 2 then
4441 begin
4442 // Ñîçäàíèå âòîðîãî èãðîêà:
4443 gPlayer2 := g_Player_Get(g_Player_Create(gPlayer2Settings.Model,
4444 gPlayer2Settings.Color,
4445 gPlayer2Settings.Team, False));
4446 if gPlayer2 = nil then
4447 begin
4448 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [2]));
4449 Exit;
4450 end;
4452 gPlayer2.Name := gPlayer2Settings.Name;
4453 Inc(nPl);
4454 end;
4456 // Çàãðóçêà è çàïóñê êàðòû:
4457 if not g_Game_StartMap(true{asMegawad}, Map, True) then
4458 begin
4459 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [Map]));
4460 Exit;
4461 end;
4463 // Íåò òî÷åê ïîÿâëåíèÿ:
4464 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1) +
4465 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2) +
4466 g_Map_GetPointCount(RESPAWNPOINT_DM) +
4467 g_Map_GetPointCount(RESPAWNPOINT_RED)+
4468 g_Map_GetPointCount(RESPAWNPOINT_BLUE)) < 1 then
4469 begin
4470 g_FatalError(_lc[I_GAME_ERROR_GET_SPAWN]);
4471 Exit;
4472 end;
4474 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4475 g_Player_Init();
4477 // Ñîçäàåì áîòîâ:
4478 for i := nPl+1 to nPlayers do
4479 g_Player_Create(STD_PLAYER_MODEL, _RGB(0, 0, 0), 0, True);
4480 end;
4482 procedure g_Game_StartServer(Map: String; GameMode: Byte;
4483 TimeLimit, GoalLimit: Word; MaxLives: Byte;
4484 Options: LongWord; nPlayers: Byte;
4485 IPAddr: LongWord; Port: Word);
4486 begin
4487 g_Game_Free();
4488 g_Net_Slist_ServerClosed();
4490 e_WriteLog('Starting net game (server)...', TMsgType.Notify);
4492 g_Game_ClearLoading();
4494 // Íàñòðîéêè èãðû:
4495 gGameSettings.GameType := GT_SERVER;
4496 gGameSettings.GameMode := GameMode;
4497 gSwitchGameMode := GameMode;
4498 gGameSettings.TimeLimit := TimeLimit;
4499 gGameSettings.GoalLimit := GoalLimit;
4500 gGameSettings.MaxLives := IfThen(GameMode = GM_CTF, 0, MaxLives);
4501 gGameSettings.Options := Options;
4503 gCoopTotalMonstersKilled := 0;
4504 gCoopTotalSecretsFound := 0;
4505 gCoopTotalMonsters := 0;
4506 gCoopTotalSecrets := 0;
4507 gAimLine := False;
4508 gShowMap := False;
4510 g_Game_ExecuteEvent('ongamestart');
4512 // Óñòàíîâêà ðàçìåðîâ îêíà èãðîêà
4513 g_Game_SetupScreenSize();
4515 // Ðåæèì íàáëþäàòåëÿ:
4516 if nPlayers = 0 then
4517 begin
4518 gPlayer1 := nil;
4519 gPlayer2 := nil;
4520 end;
4522 if nPlayers >= 1 then
4523 begin
4524 // Ñîçäàíèå ïåðâîãî èãðîêà:
4525 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
4526 gPlayer1Settings.Color,
4527 gPlayer1Settings.Team, False));
4528 if gPlayer1 = nil then
4529 begin
4530 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]));
4531 Exit;
4532 end;
4534 gPlayer1.Name := gPlayer1Settings.Name;
4535 end;
4537 if nPlayers >= 2 then
4538 begin
4539 // Ñîçäàíèå âòîðîãî èãðîêà:
4540 gPlayer2 := g_Player_Get(g_Player_Create(gPlayer2Settings.Model,
4541 gPlayer2Settings.Color,
4542 gPlayer2Settings.Team, False));
4543 if gPlayer2 = nil then
4544 begin
4545 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [2]));
4546 Exit;
4547 end;
4549 gPlayer2.Name := gPlayer2Settings.Name;
4550 end;
4552 g_Game_SetLoadingText(_lc[I_LOAD_HOST], 0, False);
4553 if NetForwardPorts then
4554 g_Game_SetLoadingText(_lc[I_LOAD_PORTS], 0, False);
4556 // Ñòàðòóåì ñåðâåð
4557 if not g_Net_Host(IPAddr, Port, NetMaxClients) then
4558 begin
4559 g_FatalError(_lc[I_NET_MSG] + _lc[I_NET_ERR_HOST]);
4560 Exit;
4561 end;
4563 g_Net_Slist_Set(NetSlistIP, NetSlistPort, NetSlistList);
4565 g_Net_Slist_ServerStarted();
4567 // Çàãðóçêà è çàïóñê êàðòû:
4568 if not g_Game_StartMap(false{asMegawad}, Map, True) then
4569 begin
4570 g_Net_Slist_ServerClosed();
4571 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [Map]));
4572 Exit;
4573 end;
4575 // Íåò òî÷åê ïîÿâëåíèÿ:
4576 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1) +
4577 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2) +
4578 g_Map_GetPointCount(RESPAWNPOINT_DM) +
4579 g_Map_GetPointCount(RESPAWNPOINT_RED)+
4580 g_Map_GetPointCount(RESPAWNPOINT_BLUE)) < 1 then
4581 begin
4582 g_Net_Slist_ServerClosed();
4583 g_FatalError(_lc[I_GAME_ERROR_GET_SPAWN]);
4584 Exit;
4585 end;
4587 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4588 g_Player_Init();
4590 g_Net_Slist_ServerMapStarted();
4591 NetState := NET_STATE_GAME;
4592 end;
4594 procedure g_Game_StartClient(Addr: String; Port: Word; PW: String);
4595 var
4596 Map: String;
4597 WadName: string;
4598 Ptr: Pointer;
4599 T: Cardinal;
4600 MID: Byte;
4601 State: Byte;
4602 OuterLoop: Boolean;
4603 newResPath: string;
4604 InMsg: TMsg;
4605 begin
4606 g_Game_Free();
4608 State := 0;
4609 e_WriteLog('Starting net game (client)...', TMsgType.Notify);
4610 e_WriteLog('NET: Trying to connect to ' + Addr + ':' + IntToStr(Port) + '...', TMsgType.Notify);
4612 g_Game_ClearLoading();
4614 // Íàñòðîéêè èãðû:
4615 gGameSettings.GameType := GT_CLIENT;
4617 gCoopTotalMonstersKilled := 0;
4618 gCoopTotalSecretsFound := 0;
4619 gCoopTotalMonsters := 0;
4620 gCoopTotalSecrets := 0;
4621 gAimLine := False;
4622 gShowMap := False;
4624 g_Game_ExecuteEvent('ongamestart');
4626 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
4627 g_Game_SetupScreenSize();
4629 NetState := NET_STATE_AUTH;
4631 g_Game_SetLoadingText(_lc[I_LOAD_CONNECT], 0, False);
4633 // create (or update) map/resource databases
4634 g_Res_CreateDatabases(true);
4636 // Ñòàðòóåì êëèåíò
4637 if not g_Net_Connect(Addr, Port) then
4638 begin
4639 g_FatalError(_lc[I_NET_MSG] + _lc[I_NET_ERR_CONN]);
4640 NetState := NET_STATE_NONE;
4641 Exit;
4642 end;
4644 g_Game_SetLoadingText(_lc[I_LOAD_SEND_INFO], 0, False);
4645 MC_SEND_Info(PW);
4646 g_Game_SetLoadingText(_lc[I_LOAD_WAIT_INFO], 0, False);
4648 OuterLoop := True;
4649 while OuterLoop do
4650 begin
4651 // fuck! https://www.mail-archive.com/enet-discuss@cubik.org/msg00852.html
4652 // tl;dr: on shitdows, we can get -1 sometimes, and it is *NOT* a failure.
4653 // thank you, enet. let's ignore failures altogether then.
4654 while (enet_host_service(NetHost, @NetEvent, 50) > 0) do
4655 begin
4656 if (NetEvent.kind = ENET_EVENT_TYPE_RECEIVE) then
4657 begin
4658 if (NetEvent.channelID = NET_CHAN_DOWNLOAD_EX) then
4659 begin
4660 // ignore all download packets, they're processed by separate code
4661 enet_packet_destroy(NetEvent.packet);
4662 continue;
4663 end;
4664 Ptr := NetEvent.packet^.data;
4665 if not InMsg.Init(Ptr, NetEvent.packet^.dataLength, True) then
4666 begin
4667 enet_packet_destroy(NetEvent.packet);
4668 continue;
4669 end;
4671 InMsg.ReadLongWord(); // skip size
4672 MID := InMsg.ReadByte();
4674 if (MID = NET_MSG_INFO) and (State = 0) then
4675 begin
4676 NetMyID := InMsg.ReadByte();
4677 NetPlrUID1 := InMsg.ReadWord();
4679 WadName := InMsg.ReadString();
4680 Map := InMsg.ReadString();
4682 gWADHash := InMsg.ReadMD5();
4684 gGameSettings.GameMode := InMsg.ReadByte();
4685 gSwitchGameMode := gGameSettings.GameMode;
4686 gGameSettings.GoalLimit := InMsg.ReadWord();
4687 gGameSettings.TimeLimit := InMsg.ReadWord();
4688 gGameSettings.MaxLives := InMsg.ReadByte();
4689 gGameSettings.Options := InMsg.ReadLongWord();
4690 T := InMsg.ReadLongWord();
4692 //newResPath := g_Res_SearchSameWAD(MapsDir, WadName, gWADHash);
4693 //if newResPath = '' then
4694 begin
4695 //g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
4696 newResPath := g_Res_DownloadMapWAD(WadName, gWADHash);
4697 if newResPath = '' then
4698 begin
4699 g_FatalError(_lc[I_NET_ERR_HASH]);
4700 enet_packet_destroy(NetEvent.packet);
4701 NetState := NET_STATE_NONE;
4702 Exit;
4703 end;
4704 e_LogWritefln('using downloaded map wad [%s] for [%s]`', [newResPath, WadName], TMsgType.Notify);
4705 end;
4706 //newResPath := ExtractRelativePath(MapsDir, newResPath);
4709 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
4710 gPlayer1Settings.Color,
4711 gPlayer1Settings.Team, False));
4713 if gPlayer1 = nil then
4714 begin
4715 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]));
4717 enet_packet_destroy(NetEvent.packet);
4718 NetState := NET_STATE_NONE;
4719 Exit;
4720 end;
4722 gPlayer1.Name := gPlayer1Settings.Name;
4723 gPlayer1.UID := NetPlrUID1;
4724 gPlayer1.Reset(True);
4726 if not g_Game_StartMap(false{asMegawad}, newResPath + ':\' + Map, True) then
4727 begin
4728 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [WadName + ':\' + Map]));
4730 enet_packet_destroy(NetEvent.packet);
4731 NetState := NET_STATE_NONE;
4732 Exit;
4733 end;
4735 gTime := T;
4737 State := 1;
4738 OuterLoop := False;
4739 enet_packet_destroy(NetEvent.packet);
4740 break;
4741 end
4742 else
4743 enet_packet_destroy(NetEvent.packet);
4744 end
4745 else
4746 begin
4747 if (NetEvent.kind = ENET_EVENT_TYPE_DISCONNECT) then
4748 begin
4749 State := 0;
4750 if (NetEvent.data <= NET_DISC_MAX) then
4751 g_Console_Add(_lc[I_NET_MSG_ERROR] + _lc[I_NET_ERR_CONN] + ' ' +
4752 _lc[TStrings_Locale(Cardinal(I_NET_DISC_NONE) + NetEvent.data)], True);
4753 OuterLoop := False;
4754 Break;
4755 end;
4756 end;
4757 end;
4759 ProcessLoading(true);
4761 if g_Net_UserRequestExit() then
4762 begin
4763 State := 0;
4764 break;
4765 end;
4766 end;
4768 if State <> 1 then
4769 begin
4770 g_FatalError(_lc[I_NET_MSG] + _lc[I_NET_ERR_CONN]);
4771 NetState := NET_STATE_NONE;
4772 Exit;
4773 end;
4775 gLMSRespawn := LMS_RESPAWN_NONE;
4776 gLMSRespawnTime := 0;
4778 g_Player_Init();
4779 NetState := NET_STATE_GAME;
4780 MC_SEND_FullStateRequest;
4781 e_WriteLog('NET: Connection successful.', TMsgType.Notify);
4782 end;
4784 procedure g_Game_SaveOptions;
4785 var s: AnsiString;
4786 begin
4787 s := e_GetWriteableDir(ConfigDirs);
4788 if s <> '' then
4789 g_Options_Write_Video(s + '/' + CONFIG_FILENAME)
4790 else
4791 e_LogWritefln('unable to find or create directory for configs', []);
4792 end;
4794 var
4795 lastAsMegaWad: Boolean = false;
4797 procedure g_Game_ChangeMap(const MapPath: String);
4798 var
4799 Force: Boolean;
4800 begin
4801 g_Game_ClearLoading();
4803 Force := gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF];
4804 // Åñëè óðîâåíü çàâåðøèëñÿ ïî òðèããåðó Âûõîä, íå î÷èùàòü èíâåíòàðü
4805 if gExitByTrigger then
4806 begin
4807 Force := False;
4808 gExitByTrigger := False;
4809 end;
4810 if not g_Game_StartMap(lastAsMegaWad, MapPath, Force) then
4811 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [MapPath]));
4812 end;
4814 procedure g_Game_Restart();
4815 var
4816 Map: string;
4817 begin
4818 if g_Game_IsClient then
4819 Exit;
4820 map := g_ExtractFileName(gMapInfo.Map);
4821 e_LogWritefln('g_Game_Restart: map = "%s" gCurrentMapFileName = "%s"', [map, gCurrentMapFileName]);
4823 MessageTime := 0;
4824 gGameOn := False;
4825 g_Game_ClearLoading();
4826 g_Game_StartMap(lastAsMegaWad, Map, True, gCurrentMapFileName);
4827 end;
4829 function g_Game_StartMap (asMegawad: Boolean; Map: String; Force: Boolean = False; const oldMapPath: AnsiString=''): Boolean;
4830 var
4831 NewWAD, ResName: String;
4832 I: Integer;
4833 nws: AnsiString;
4834 begin
4835 g_Map_Free((Map <> gCurrentMapFileName) and (oldMapPath <> gCurrentMapFileName));
4836 g_Player_RemoveAllCorpses();
4838 if (not g_Game_IsClient) and
4839 (gSwitchGameMode <> gGameSettings.GameMode) and
4840 (gGameSettings.GameMode <> GM_SINGLE) then
4841 begin
4842 if gSwitchGameMode = GM_CTF then
4843 gGameSettings.MaxLives := 0;
4844 gGameSettings.GameMode := gSwitchGameMode;
4845 Force := True;
4846 end else
4847 gSwitchGameMode := gGameSettings.GameMode;
4849 g_Player_ResetTeams();
4851 lastAsMegaWad := asMegawad;
4852 if isWadPath(Map) then
4853 begin
4854 NewWAD := g_ExtractWadName(Map);
4855 ResName := g_ExtractFileName(Map);
4856 if g_Game_IsServer then
4857 begin
4858 nws := findDiskWad(NewWAD);
4859 //writeln('000: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
4860 if (asMegawad) then
4861 begin
4862 if (length(nws) = 0) then nws := e_FindWad(MegawadDirs, NewWAD);
4863 if (length(nws) = 0) then nws := e_FindWad(MapDirs, NewWAD);
4864 end
4865 else
4866 begin
4867 if (length(nws) = 0) then nws := e_FindWad(MapDirs, NewWAD);
4868 if (length(nws) = 0) then nws := e_FindWad(MegawadDirs, NewWAD);
4869 end;
4870 //if (length(nws) = 0) then nws := e_FindWad(MapDownloadDirs, NewWAD);
4871 //writeln('001: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
4872 //nws := NewWAD;
4873 if (length(nws) = 0) then
4874 begin
4875 ResName := ''; // failed
4876 end
4877 else
4878 begin
4879 NewWAD := nws;
4880 if (g_Game_IsNet) then gWADHash := MD5File(nws);
4881 //writeln('********: nws=', nws, ' : Map=', Map, ' : nw=', NewWAD, ' : resname=', ResName);
4882 g_Game_LoadWAD(NewWAD);
4883 end;
4884 end
4885 else
4886 begin
4887 // hash received in MC_RECV_GameEvent -> NET_EV_MAPSTART
4888 NewWAD := g_Game_ClientWAD(NewWAD, gWADHash);
4889 end;
4890 end
4891 else
4892 begin
4893 NewWAD := gGameSettings.WAD;
4894 ResName := Map;
4895 end;
4897 //writeln('********: gsw=', gGameSettings.WAD, '; rn=', ResName);
4898 result := false;
4899 if (ResName <> '') and (NewWAD <> '') then
4900 begin
4901 //result := g_Map_Load(gGameSettings.WAD + ':\' + ResName);
4902 result := g_Map_Load(NewWAD+':\'+ResName);
4903 end;
4904 if Result then
4905 begin
4906 g_Player_ResetAll(Force or gLastMap, gGameSettings.GameType = GT_SINGLE);
4908 gState := STATE_NONE;
4909 g_ActiveWindow := nil;
4910 gGameOn := True;
4912 DisableCheats();
4913 ResetTimer();
4915 if gGameSettings.GameMode = GM_CTF then
4916 begin
4917 g_Map_ResetFlag(FLAG_RED);
4918 g_Map_ResetFlag(FLAG_BLUE);
4919 // CTF, à ôëàãîâ íåò:
4920 if not g_Map_HaveFlagPoints() then
4921 g_SimpleError(_lc[I_GAME_ERROR_CTF]);
4922 end;
4923 end
4924 else
4925 begin
4926 gState := STATE_MENU;
4927 gGameOn := False;
4928 end;
4930 gExit := 0;
4931 gPauseMain := false;
4932 gPauseHolmes := false;
4933 gTime := 0;
4934 NetTimeToUpdate := 1;
4935 NetTimeToReliable := 0;
4936 NetTimeToMaster := NetMasterRate;
4937 gLMSRespawn := LMS_RESPAWN_NONE;
4938 gLMSRespawnTime := 0;
4939 gMissionFailed := False;
4940 gNextMap := '';
4942 gCoopMonstersKilled := 0;
4943 gCoopSecretsFound := 0;
4945 gVoteInProgress := False;
4946 gVotePassed := False;
4947 gVoteCount := 0;
4948 gVoted := False;
4950 gStatsOff := False;
4952 if not gGameOn then Exit;
4954 g_Game_SpectateCenterView();
4956 if (gGameSettings.MaxLives > 0) and (gGameSettings.WarmupTime > 0) then
4957 begin
4958 gLMSRespawn := LMS_RESPAWN_WARMUP;
4959 gLMSRespawnTime := gTime + gGameSettings.WarmupTime*1000;
4960 gLMSSoftSpawn := True;
4961 if NetMode = NET_SERVER then
4962 MH_SEND_GameEvent(NET_EV_LMS_WARMUP, (gLMSRespawnTime - gTime) div 1000)
4963 else
4964 g_Console_Add(Format(_lc[I_MSG_WARMUP_START], [(gLMSRespawnTime - gTime) div 1000]), True);
4965 end;
4967 if NetMode = NET_SERVER then
4968 begin
4969 MH_SEND_GameEvent(NET_EV_MAPSTART, gGameSettings.GameMode, Map);
4971 // Ìàñòåðñåðâåð
4972 g_Net_Slist_ServerMapStarted();
4974 if NetClients <> nil then
4975 for I := 0 to High(NetClients) do
4976 if NetClients[I].Used then
4977 begin
4978 NetClients[I].Voted := False;
4979 if NetClients[I].RequestedFullUpdate then
4980 begin
4981 MH_SEND_Everything((NetClients[I].State = NET_STATE_AUTH), I);
4982 NetClients[I].RequestedFullUpdate := False;
4983 end;
4984 end;
4986 g_Net_UnbanNonPermHosts();
4987 end;
4989 if gLastMap then
4990 begin
4991 gCoopTotalMonstersKilled := 0;
4992 gCoopTotalSecretsFound := 0;
4993 gCoopTotalMonsters := 0;
4994 gCoopTotalSecrets := 0;
4995 gLastMap := False;
4996 end;
4998 g_Game_ExecuteEvent('onmapstart');
4999 end;
5001 procedure SetFirstLevel;
5002 begin
5003 gNextMap := '';
5005 MapList := g_Map_GetMapsList(gGameSettings.WAD);
5006 if MapList = nil then
5007 Exit;
5009 SortSArray(MapList);
5010 gNextMap := MapList[Low(MapList)];
5012 MapList := nil;
5013 end;
5015 procedure g_Game_ExitLevel(const Map: AnsiString);
5016 begin
5017 gNextMap := Map;
5019 gCoopTotalMonstersKilled := gCoopTotalMonstersKilled + gCoopMonstersKilled;
5020 gCoopTotalSecretsFound := gCoopTotalSecretsFound + gCoopSecretsFound;
5021 gCoopTotalMonsters := gCoopTotalMonsters + gTotalMonsters;
5022 gCoopTotalSecrets := gCoopTotalSecrets + gSecretsCount;
5024 // Âûøëè â âûõîä â Îäèíî÷íîé èãðå:
5025 if gGameSettings.GameType = GT_SINGLE then
5026 gExit := EXIT_ENDLEVELSINGLE
5027 else // Âûøëè â âûõîä â Ñâîåé èãðå
5028 begin
5029 gExit := EXIT_ENDLEVELCUSTOM;
5030 if gGameSettings.GameMode = GM_COOP then
5031 g_Player_RememberAll;
5033 if not g_Map_Exist(gGameSettings.WAD + ':\' + gNextMap) then
5034 begin
5035 gLastMap := True;
5036 if gGameSettings.GameMode = GM_COOP then
5037 gStatsOff := True;
5039 gStatsPressed := True;
5040 gNextMap := 'MAP01';
5042 if not g_Map_Exist(gGameSettings.WAD + ':\' + gNextMap) then
5043 g_Game_NextLevel;
5045 if g_Game_IsNet then
5046 begin
5047 MH_SEND_GameStats();
5048 MH_SEND_CoopStats();
5049 end;
5050 end;
5051 end;
5052 end;
5054 procedure g_Game_RestartLevel();
5055 var
5056 Map: string;
5057 begin
5058 if gGameSettings.GameMode = GM_SINGLE then
5059 begin
5060 g_Game_Restart();
5061 Exit;
5062 end;
5063 gExit := EXIT_ENDLEVELCUSTOM;
5064 Map := g_ExtractFileName(gMapInfo.Map);
5065 gNextMap := Map;
5066 end;
5068 function g_Game_ClientWAD (NewWAD: String; const WHash: TMD5Digest): AnsiString;
5069 var
5070 gWAD{, xwad}: String;
5071 begin
5072 result := NewWAD;
5073 if not g_Game_IsClient then Exit;
5074 //e_LogWritefln('*** g_Game_ClientWAD: `%s`', [NewWAD]);
5076 gWAD := g_Res_DownloadMapWAD(ExtractFileName(NewWAD), WHash);
5077 if gWAD = '' then
5078 begin
5079 result := '';
5080 g_Game_Free();
5081 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_WAD], [ExtractFileName(NewWAD)]));
5082 Exit;
5083 end;
5085 (*
5086 xwad := ExtractRelativePath(MapsDir, gWAD);
5087 e_LogWritefln('using downloaded client map wad [%s] for [%s]`', [xwad, NewWAD], TMsgType.Notify);
5088 NewWAD := xwad;
5089 g_Game_LoadWAD(NewWAD);
5090 *)
5092 e_LogWritefln('using downloaded client map wad [%s]`', [NewWAD], TMsgType.Notify);
5093 g_Game_LoadWAD(NewWAD);
5094 result := NewWAD;
5097 if LowerCase(NewWAD) = LowerCase(gGameSettings.WAD) then Exit;
5098 gWAD := g_Res_SearchSameWAD(MapsDir, ExtractFileName(NewWAD), WHash);
5099 if gWAD = '' then
5100 begin
5101 g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
5102 gWAD := g_Res_DownloadMapWAD(ExtractFileName(NewWAD), WHash);
5103 if gWAD = '' then
5104 begin
5105 g_Game_Free();
5106 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_WAD], [ExtractFileName(NewWAD)]));
5107 Exit;
5108 end;
5109 end;
5110 NewWAD := ExtractRelativePath(MapsDir, gWAD);
5111 g_Game_LoadWAD(NewWAD);
5113 end;
5115 procedure g_Game_RestartRound(NoMapRestart: Boolean = False);
5116 var
5117 i, n, nb, nr: Integer;
5119 function monRespawn (mon: TMonster): Boolean;
5120 begin
5121 result := false; // don't stop
5122 if not mon.FNoRespawn then mon.Respawn();
5123 end;
5125 begin
5126 if not g_Game_IsServer then Exit;
5127 if gLMSRespawn = LMS_RESPAWN_NONE then Exit;
5128 gLMSRespawn := LMS_RESPAWN_NONE;
5129 gLMSRespawnTime := 0;
5130 MessageTime := 0;
5132 if (gGameSettings.GameMode = GM_COOP) and not NoMapRestart then
5133 begin
5134 gMissionFailed := True;
5135 g_Game_RestartLevel;
5136 Exit;
5137 end;
5139 n := 0; nb := 0; nr := 0;
5140 for i := Low(gPlayers) to High(gPlayers) do
5141 if (gPlayers[i] <> nil) and
5142 ((not gPlayers[i].FSpectator) or gPlayers[i].FWantsInGame or
5143 (gPlayers[i] is TBot)) then
5144 begin
5145 Inc(n);
5146 if gPlayers[i].Team = TEAM_RED then Inc(nr)
5147 else if gPlayers[i].Team = TEAM_BLUE then Inc(nb)
5148 end;
5150 if (n < 2) or ((gGameSettings.GameMode = GM_TDM) and ((nr = 0) or (nb = 0))) then
5151 begin
5152 // wait a second until the fuckers finally decide to join
5153 gLMSRespawn := LMS_RESPAWN_WARMUP;
5154 gLMSRespawnTime := gTime + 1000;
5155 gLMSSoftSpawn := NoMapRestart;
5156 Exit;
5157 end;
5159 g_Player_RemoveAllCorpses;
5160 g_Game_Message(_lc[I_MESSAGE_LMS_START], 144);
5161 if g_Game_IsNet then
5162 MH_SEND_GameEvent(NET_EV_LMS_START);
5164 for i := Low(gPlayers) to High(gPlayers) do
5165 begin
5166 if gPlayers[i] = nil then continue;
5167 if gPlayers[i] is TBot then gPlayers[i].FWantsInGame := True;
5168 // don't touch normal spectators
5169 if gPlayers[i].FSpectator and not gPlayers[i].FWantsInGame then
5170 begin
5171 gPlayers[i].FNoRespawn := True;
5172 gPlayers[i].Lives := 0;
5173 if g_Game_IsNet then
5174 MH_SEND_PlayerStats(gPlayers[I].UID);
5175 continue;
5176 end;
5177 gPlayers[i].FNoRespawn := False;
5178 gPlayers[i].Lives := gGameSettings.MaxLives;
5179 gPlayers[i].Respawn(False, True);
5180 if gGameSettings.GameMode = GM_COOP then
5181 begin
5182 gPlayers[i].Frags := 0;
5183 gPlayers[i].RecallState;
5184 end;
5185 if (gPlayer1 = nil) and (gLMSPID1 > 0) then
5186 gPlayer1 := g_Player_Get(gLMSPID1);
5187 if (gPlayer2 = nil) and (gLMSPID2 > 0) then
5188 gPlayer2 := g_Player_Get(gLMSPID2);
5189 end;
5191 g_Items_RestartRound();
5194 g_Mons_ForEach(monRespawn);
5196 gLMSSoftSpawn := False;
5197 end;
5199 function g_Game_GetFirstMap(WAD: String): String;
5200 begin
5201 Result := '';
5203 MapList := g_Map_GetMapsList(WAD);
5204 if MapList = nil then
5205 Exit;
5207 SortSArray(MapList);
5208 Result := MapList[Low(MapList)];
5210 if not g_Map_Exist(WAD + ':\' + Result) then
5211 Result := '';
5213 MapList := nil;
5214 end;
5216 function g_Game_GetNextMap(): String;
5217 var
5218 I: Integer;
5219 Map: string;
5220 begin
5221 Result := '';
5223 MapList := g_Map_GetMapsList(gGameSettings.WAD);
5224 if MapList = nil then
5225 Exit;
5227 Map := g_ExtractFileName(gMapInfo.Map);
5229 SortSArray(MapList);
5230 MapIndex := -255;
5231 for I := Low(MapList) to High(MapList) do
5232 if Map = MapList[I] then
5233 begin
5234 MapIndex := I;
5235 Break;
5236 end;
5238 if MapIndex <> -255 then
5239 begin
5240 if MapIndex = High(MapList) then
5241 Result := MapList[Low(MapList)]
5242 else
5243 Result := MapList[MapIndex + 1];
5245 if not g_Map_Exist(gGameSettings.WAD + ':\' + Result) then Result := Map;
5246 end;
5248 MapList := nil;
5249 end;
5251 procedure g_Game_NextLevel();
5252 begin
5253 if gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF, GM_COOP] then
5254 gExit := EXIT_ENDLEVELCUSTOM
5255 else
5256 begin
5257 gExit := EXIT_ENDLEVELSINGLE;
5258 Exit;
5259 end;
5261 if gNextMap <> '' then Exit;
5262 gNextMap := g_Game_GetNextMap();
5263 end;
5265 function g_Game_IsTestMap(): Boolean;
5266 begin
5267 result := StrEquCI1251(TEST_MAP_NAME, g_ExtractFileName(gMapInfo.Map));
5268 end;
5270 procedure g_Game_DeleteTestMap();
5271 var
5272 a: Integer;
5273 //MapName: AnsiString;
5274 WadName: string;
5276 WAD: TWADFile;
5277 MapList: SSArray;
5278 time: Integer;
5280 begin
5281 a := Pos('.wad:\', toLowerCase1251(gMapToDelete));
5282 if (a = 0) then a := Pos('.wad:/', toLowerCase1251(gMapToDelete));
5283 if (a = 0) then exit;
5285 // Âûäåëÿåì èìÿ wad-ôàéëà è èìÿ êàðòû
5286 WadName := Copy(gMapToDelete, 1, a+3);
5287 Delete(gMapToDelete, 1, a+5);
5288 gMapToDelete := UpperCase(gMapToDelete);
5289 //MapName := '';
5290 //CopyMemory(@MapName[0], @gMapToDelete[1], Min(16, Length(gMapToDelete)));
5293 // Èìÿ êàðòû íå ñòàíäàðòíîå òåñòîâîå:
5294 if MapName <> TEST_MAP_NAME then
5295 Exit;
5297 if not gTempDelete then
5298 begin
5299 time := g_GetFileTime(WadName);
5300 WAD := TWADFile.Create();
5302 // ×èòàåì Wad-ôàéë:
5303 if not WAD.ReadFile(WadName) then
5304 begin // Íåò òàêîãî WAD-ôàéëà
5305 WAD.Free();
5306 Exit;
5307 end;
5309 // Ñîñòàâëÿåì ñïèñîê êàðò è èùåì íóæíóþ:
5310 WAD.CreateImage();
5311 MapList := WAD.GetResourcesList('');
5313 if MapList <> nil then
5314 for a := 0 to High(MapList) do
5315 if MapList[a] = MapName then
5316 begin
5317 // Óäàëÿåì è ñîõðàíÿåì:
5318 WAD.RemoveResource('', MapName);
5319 WAD.SaveTo(WadName);
5320 Break;
5321 end;
5323 WAD.Free();
5324 g_SetFileTime(WadName, time);
5325 end else
5327 if gTempDelete then DeleteFile(WadName);
5328 end;
5330 procedure GameCVars(P: SSArray);
5331 var
5332 a, b: Integer;
5333 stat: TPlayerStatArray;
5334 cmd, s: string;
5335 config: TConfig;
5336 begin
5337 stat := nil;
5338 cmd := LowerCase(P[0]);
5339 if (cmd = 'g_friendlyfire') and not g_Game_IsClient then
5340 begin
5341 with gGameSettings do
5342 begin
5343 if (Length(P) > 1) and
5344 ((P[1] = '1') or (P[1] = '0')) then
5345 begin
5346 if (P[1][1] = '1') then
5347 Options := Options or GAME_OPTION_TEAMDAMAGE
5348 else
5349 Options := Options and (not GAME_OPTION_TEAMDAMAGE);
5350 end;
5352 if (LongBool(Options and GAME_OPTION_TEAMDAMAGE)) then
5353 g_Console_Add(_lc[I_MSG_FRIENDLY_FIRE_ON])
5354 else
5355 g_Console_Add(_lc[I_MSG_FRIENDLY_FIRE_OFF]);
5357 if g_Game_IsNet then MH_SEND_GameSettings;
5358 end;
5359 end
5360 else if (cmd = 'g_weaponstay') and not g_Game_IsClient then
5361 begin
5362 with gGameSettings do
5363 begin
5364 if (Length(P) > 1) and
5365 ((P[1] = '1') or (P[1] = '0')) then
5366 begin
5367 if (P[1][1] = '1') then
5368 Options := Options or GAME_OPTION_WEAPONSTAY
5369 else
5370 Options := Options and (not GAME_OPTION_WEAPONSTAY);
5371 end;
5373 if (LongBool(Options and GAME_OPTION_WEAPONSTAY)) then
5374 g_Console_Add(_lc[I_MSG_WEAPONSTAY_ON])
5375 else
5376 g_Console_Add(_lc[I_MSG_WEAPONSTAY_OFF]);
5378 if g_Game_IsNet then MH_SEND_GameSettings;
5379 end;
5380 end
5381 else if cmd = 'g_gamemode' then
5382 begin
5383 a := g_Game_TextToMode(P[1]);
5384 if a = GM_SINGLE then a := GM_COOP;
5385 if (Length(P) > 1) and (a <> GM_NONE) and (not g_Game_IsClient) then
5386 begin
5387 gSwitchGameMode := a;
5388 if (gGameOn and (gGameSettings.GameMode = GM_SINGLE)) or
5389 (gState = STATE_INTERSINGLE) then
5390 gSwitchGameMode := GM_SINGLE;
5391 if not gGameOn then
5392 gGameSettings.GameMode := gSwitchGameMode;
5393 end;
5394 if gSwitchGameMode = gGameSettings.GameMode then
5395 g_Console_Add(Format(_lc[I_MSG_GAMEMODE_CURRENT],
5396 [g_Game_ModeToText(gGameSettings.GameMode)]))
5397 else
5398 g_Console_Add(Format(_lc[I_MSG_GAMEMODE_CHANGE],
5399 [g_Game_ModeToText(gGameSettings.GameMode),
5400 g_Game_ModeToText(gSwitchGameMode)]));
5401 end
5402 else if (cmd = 'g_allow_exit') and not g_Game_IsClient then
5403 begin
5404 with gGameSettings do
5405 begin
5406 if (Length(P) > 1) and
5407 ((P[1] = '1') or (P[1] = '0')) then
5408 begin
5409 if (P[1][1] = '1') then
5410 Options := Options or GAME_OPTION_ALLOWEXIT
5411 else
5412 Options := Options and (not GAME_OPTION_ALLOWEXIT);
5413 end;
5415 if (LongBool(Options and GAME_OPTION_ALLOWEXIT)) then
5416 g_Console_Add(_lc[I_MSG_ALLOWEXIT_ON])
5417 else
5418 g_Console_Add(_lc[I_MSG_ALLOWEXIT_OFF]);
5419 g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
5421 if g_Game_IsNet then MH_SEND_GameSettings;
5422 end;
5423 end
5424 else if (cmd = 'g_allow_monsters') and not g_Game_IsClient then
5425 begin
5426 with gGameSettings do
5427 begin
5428 if (Length(P) > 1) and
5429 ((P[1] = '1') or (P[1] = '0')) then
5430 begin
5431 if (P[1][1] = '1') then
5432 Options := Options or GAME_OPTION_MONSTERS
5433 else
5434 Options := Options and (not GAME_OPTION_MONSTERS);
5435 end;
5437 if (LongBool(Options and GAME_OPTION_MONSTERS)) then
5438 g_Console_Add(_lc[I_MSG_ALLOWMON_ON])
5439 else
5440 g_Console_Add(_lc[I_MSG_ALLOWMON_OFF]);
5441 g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
5443 if g_Game_IsNet then MH_SEND_GameSettings;
5444 end;
5445 end
5446 else if (cmd = 'g_bot_vsplayers') and not g_Game_IsClient then
5447 begin
5448 with gGameSettings do
5449 begin
5450 if (Length(P) > 1) and
5451 ((P[1] = '1') or (P[1] = '0')) then
5452 begin
5453 if (P[1][1] = '1') then
5454 Options := Options or GAME_OPTION_BOTVSPLAYER
5455 else
5456 Options := Options and (not GAME_OPTION_BOTVSPLAYER);
5457 end;
5459 if (LongBool(Options and GAME_OPTION_BOTVSPLAYER)) then
5460 g_Console_Add(_lc[I_MSG_BOTSVSPLAYERS_ON])
5461 else
5462 g_Console_Add(_lc[I_MSG_BOTSVSPLAYERS_OFF]);
5464 if g_Game_IsNet then MH_SEND_GameSettings;
5465 end;
5466 end
5467 else if (cmd = 'g_bot_vsmonsters') and not g_Game_IsClient then
5468 begin
5469 with gGameSettings do
5470 begin
5471 if (Length(P) > 1) and
5472 ((P[1] = '1') or (P[1] = '0')) then
5473 begin
5474 if (P[1][1] = '1') then
5475 Options := Options or GAME_OPTION_BOTVSMONSTER
5476 else
5477 Options := Options and (not GAME_OPTION_BOTVSMONSTER);
5478 end;
5480 if (LongBool(Options and GAME_OPTION_BOTVSMONSTER)) then
5481 g_Console_Add(_lc[I_MSG_BOTSVSMONSTERS_ON])
5482 else
5483 g_Console_Add(_lc[I_MSG_BOTSVSMONSTERS_OFF]);
5485 if g_Game_IsNet then MH_SEND_GameSettings;
5486 end;
5487 end
5488 else if (cmd = 'g_warmuptime') and not g_Game_IsClient then
5489 begin
5490 if Length(P) > 1 then
5491 begin
5492 if StrToIntDef(P[1], gGameSettings.WarmupTime) = 0 then
5493 gGameSettings.WarmupTime := 30
5494 else
5495 gGameSettings.WarmupTime := StrToIntDef(P[1], gGameSettings.WarmupTime);
5496 end;
5498 g_Console_Add(Format(_lc[I_MSG_WARMUP],
5499 [gGameSettings.WarmupTime]));
5500 g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
5501 end
5502 else if cmd = 'net_interp' then
5503 begin
5504 if (Length(P) > 1) then
5505 NetInterpLevel := StrToIntDef(P[1], NetInterpLevel);
5506 g_Console_Add('net_interp = ' + IntToStr(NetInterpLevel));
5507 s := e_GetWriteableDir(ConfigDirs);
5508 if s <> '' then
5509 begin
5510 config := TConfig.CreateFile(s + '/' + CONFIG_FILENAME);
5511 config.WriteInt('Client', 'InterpolationSteps', NetInterpLevel);
5512 config.SaveFile(s + '/' + CONFIG_FILENAME);
5513 config.Free
5514 end
5515 end
5516 else if cmd = 'net_forceplayerupdate' then
5517 begin
5518 if (Length(P) > 1) and ((P[1] = '1') or (P[1] = '0')) then
5519 NetForcePlayerUpdate := (P[1][1] = '1');
5521 if NetForcePlayerUpdate then
5522 g_Console_Add('net_forceplayerupdate = 1')
5523 else
5524 g_Console_Add('net_forceplayerupdate = 0');
5526 s := e_GetWriteableDir(ConfigDirs);
5527 if s <> '' then
5528 begin
5529 config := TConfig.CreateFile(s + '/' + CONFIG_FILENAME);
5530 config.WriteBool('Client', 'ForcePlayerUpdate', NetForcePlayerUpdate);
5531 config.SaveFile(s + '/' + CONFIG_FILENAME);
5532 config.Free
5533 end
5534 end
5535 else if cmd = 'net_predictself' then
5536 begin
5537 if (Length(P) > 1) and
5538 ((P[1] = '1') or (P[1] = '0')) then
5539 NetPredictSelf := (P[1][1] = '1');
5541 if NetPredictSelf then
5542 g_Console_Add('net_predictself = 1')
5543 else
5544 g_Console_Add('net_predictself = 0');
5546 s := e_GetWriteableDir(ConfigDirs);
5547 if s <> '' then
5548 begin
5549 config := TConfig.CreateFile(s + '/' + CONFIG_FILENAME);
5550 config.WriteBool('Client', 'PredictSelf', NetPredictSelf);
5551 config.SaveFile(s + '/' + CONFIG_FILENAME);
5552 config.Free
5553 end
5554 end
5555 else if cmd = 'sv_name' then
5556 begin
5557 if (Length(P) > 1) and (Length(P[1]) > 0) then
5558 begin
5559 NetServerName := P[1];
5560 if Length(NetServerName) > 64 then
5561 SetLength(NetServerName, 64);
5562 g_Net_Slist_ServerRenamed();
5563 end;
5565 g_Console_Add(cmd + ' = "' + NetServerName + '"');
5566 end
5567 else if cmd = 'sv_passwd' then
5568 begin
5569 if (Length(P) > 1) and (Length(P[1]) > 0) then
5570 begin
5571 NetPassword := P[1];
5572 if Length(NetPassword) > 24 then
5573 SetLength(NetPassword, 24);
5574 g_Net_Slist_ServerRenamed();
5575 end;
5577 g_Console_Add(cmd + ' = "' + AnsiLowerCase(NetPassword) + '"');
5578 end
5579 else if cmd = 'sv_maxplrs' then
5580 begin
5581 if (Length(P) > 1) then
5582 begin
5583 NetMaxClients := Min(Max(StrToIntDef(P[1], NetMaxClients), 1), NET_MAXCLIENTS);
5584 if g_Game_IsServer and g_Game_IsNet then
5585 begin
5586 b := 0;
5587 for a := 0 to High(NetClients) do
5588 begin
5589 if NetClients[a].Used then
5590 begin
5591 Inc(b);
5592 if b > NetMaxClients then
5593 begin
5594 s := g_Player_Get(NetClients[a].Player).Name;
5595 enet_peer_disconnect(NetClients[a].Peer, NET_DISC_FULL);
5596 g_Console_Add(Format(_lc[I_PLAYER_KICK], [s]));
5597 MH_SEND_GameEvent(NET_EV_PLAYER_KICK, 0, s);
5598 end;
5599 end;
5600 end;
5601 g_Net_Slist_ServerRenamed();
5602 end;
5603 end;
5605 g_Console_Add(cmd + ' = ' + IntToStr(NetMaxClients));
5606 end
5607 else if cmd = 'sv_public' then
5608 begin
5609 if (Length(P) > 1) then
5610 begin
5611 NetUseMaster := StrToIntDef(P[1], Byte(NetUseMaster)) > 0;
5612 if NetUseMaster then g_Net_Slist_Public() else g_Net_Slist_Private();
5613 end;
5615 g_Console_Add(cmd + ' = ' + IntToStr(Byte(NetUseMaster)));
5616 end
5617 else if cmd = 'sv_intertime' then
5618 begin
5619 if (Length(P) > 1) then
5620 gDefInterTime := Min(Max(StrToIntDef(P[1], gDefInterTime), -1), 120);
5622 g_Console_Add(cmd + ' = ' + IntToStr(gDefInterTime));
5623 end
5624 else if cmd = 'p1_name' then
5625 begin
5626 if (Length(P) > 1) and gGameOn then
5627 begin
5628 if g_Game_IsClient then
5629 begin
5630 gPlayer1Settings.Name := b_Text_Unformat(P[1]);
5631 MC_SEND_PlayerSettings;
5632 end
5633 else
5634 if gPlayer1 <> nil then
5635 begin
5636 gPlayer1.Name := b_Text_Unformat(P[1]);
5637 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer1.UID);
5638 end
5639 else
5640 gPlayer1Settings.Name := b_Text_Unformat(P[1]);
5641 end;
5642 end
5643 else if cmd = 'p2_name' then
5644 begin
5645 if (Length(P) > 1) and gGameOn then
5646 begin
5647 if g_Game_IsClient then
5648 begin
5649 gPlayer2Settings.Name := b_Text_Unformat(P[1]);
5650 MC_SEND_PlayerSettings;
5651 end
5652 else
5653 if gPlayer2 <> nil then
5654 begin
5655 gPlayer2.Name := b_Text_Unformat(P[1]);
5656 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer2.UID);
5657 end
5658 else
5659 gPlayer2Settings.Name := b_Text_Unformat(P[1]);
5660 end;
5661 end
5662 else if cmd = 'p1_color' then
5663 begin
5664 if Length(P) > 3 then
5665 if g_Game_IsClient then
5666 begin
5667 gPlayer1Settings.Color := _RGB(EnsureRange(StrToIntDef(P[1], 0), 0, 255),
5668 EnsureRange(StrToIntDef(P[2], 0), 0, 255),
5669 EnsureRange(StrToIntDef(P[3], 0), 0, 255));
5670 MC_SEND_PlayerSettings;
5671 end
5672 else
5673 if gPlayer1 <> nil then
5674 begin
5675 gPlayer1.Model.SetColor(EnsureRange(StrToIntDef(P[1], 0), 0, 255),
5676 EnsureRange(StrToIntDef(P[2], 0), 0, 255),
5677 EnsureRange(StrToIntDef(P[3], 0), 0, 255));
5678 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer1.UID);
5679 end
5680 else
5681 gPlayer1Settings.Color := _RGB(EnsureRange(StrToIntDef(P[1], 0), 0, 255),
5682 EnsureRange(StrToIntDef(P[2], 0), 0, 255),
5683 EnsureRange(StrToIntDef(P[3], 0), 0, 255));
5684 end
5685 else if (cmd = 'p2_color') and not g_Game_IsNet then
5686 begin
5687 if Length(P) > 3 then
5688 if g_Game_IsClient then
5689 begin
5690 gPlayer2Settings.Color := _RGB(EnsureRange(StrToIntDef(P[1], 0), 0, 255),
5691 EnsureRange(StrToIntDef(P[2], 0), 0, 255),
5692 EnsureRange(StrToIntDef(P[3], 0), 0, 255));
5693 MC_SEND_PlayerSettings;
5694 end
5695 else
5696 if gPlayer2 <> nil then
5697 begin
5698 gPlayer2.Model.SetColor(EnsureRange(StrToIntDef(P[1], 0), 0, 255),
5699 EnsureRange(StrToIntDef(P[2], 0), 0, 255),
5700 EnsureRange(StrToIntDef(P[3], 0), 0, 255));
5701 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer2.UID);
5702 end
5703 else
5704 gPlayer2Settings.Color := _RGB(EnsureRange(StrToIntDef(P[1], 0), 0, 255),
5705 EnsureRange(StrToIntDef(P[2], 0), 0, 255),
5706 EnsureRange(StrToIntDef(P[3], 0), 0, 255));
5707 end
5708 else if gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT] then
5709 begin
5710 if cmd = 'r_showscore' then
5711 begin
5712 if (Length(P) > 1) and
5713 ((P[1] = '1') or (P[1] = '0')) then
5714 gShowGoals := (P[1][1] = '1');
5716 if gShowGoals then
5717 g_Console_Add(_lc[I_MSG_SCORE_ON])
5718 else
5719 g_Console_Add(_lc[I_MSG_SCORE_OFF]);
5720 end
5721 else if cmd = 'r_showstat' then
5722 begin
5723 if (Length(P) > 1) and
5724 ((P[1] = '1') or (P[1] = '0')) then
5725 gShowStat := (P[1][1] = '1');
5727 if gShowStat then
5728 g_Console_Add(_lc[I_MSG_STATS_ON])
5729 else
5730 g_Console_Add(_lc[I_MSG_STATS_OFF]);
5731 end
5732 else if cmd = 'r_showkillmsg' then
5733 begin
5734 if (Length(P) > 1) and
5735 ((P[1] = '1') or (P[1] = '0')) then
5736 gShowKillMsg := (P[1][1] = '1');
5738 if gShowKillMsg then
5739 g_Console_Add(_lc[I_MSG_KILL_MSGS_ON])
5740 else
5741 g_Console_Add(_lc[I_MSG_KILL_MSGS_OFF]);
5742 end
5743 else if cmd = 'r_showlives' then
5744 begin
5745 if (Length(P) > 1) and
5746 ((P[1] = '1') or (P[1] = '0')) then
5747 gShowLives := (P[1][1] = '1');
5749 if gShowLives then
5750 g_Console_Add(_lc[I_MSG_LIVES_ON])
5751 else
5752 g_Console_Add(_lc[I_MSG_LIVES_OFF]);
5753 end
5754 else if cmd = 'r_showspect' then
5755 begin
5756 if (Length(P) > 1) and
5757 ((P[1] = '1') or (P[1] = '0')) then
5758 gSpectHUD := (P[1][1] = '1');
5760 if gSpectHUD then
5761 g_Console_Add(_lc[I_MSG_SPECT_HUD_ON])
5762 else
5763 g_Console_Add(_lc[I_MSG_SPECT_HUD_OFF]);
5764 end
5765 else if cmd = 'r_showping' then
5766 begin
5767 if (Length(P) > 1) and
5768 ((P[1] = '1') or (P[1] = '0')) then
5769 gShowPing := (P[1][1] = '1');
5771 if gShowPing then
5772 g_Console_Add(_lc[I_MSG_PING_ON])
5773 else
5774 g_Console_Add(_lc[I_MSG_PING_OFF]);
5775 end
5776 else if (cmd = 'g_scorelimit') and not g_Game_IsClient then
5777 begin
5778 if Length(P) > 1 then
5779 begin
5780 if StrToIntDef(P[1], gGameSettings.GoalLimit) = 0 then
5781 gGameSettings.GoalLimit := 0
5782 else
5783 begin
5784 b := 0;
5786 if gGameSettings.GameMode = GM_DM then
5787 begin // DM
5788 stat := g_Player_GetStats();
5789 if stat <> nil then
5790 for a := 0 to High(stat) do
5791 if stat[a].Frags > b then
5792 b := stat[a].Frags;
5793 end
5794 else // TDM/CTF
5795 b := Max(gTeamStat[TEAM_RED].Goals, gTeamStat[TEAM_BLUE].Goals);
5797 gGameSettings.GoalLimit := Max(StrToIntDef(P[1], gGameSettings.GoalLimit), b);
5798 end;
5800 if g_Game_IsNet then MH_SEND_GameSettings;
5801 end;
5803 g_Console_Add(Format(_lc[I_MSG_SCORE_LIMIT], [gGameSettings.GoalLimit]));
5804 end
5805 else if (cmd = 'g_timelimit') and not g_Game_IsClient then
5806 begin
5807 if (Length(P) > 1) and (StrToIntDef(P[1], -1) >= 0) then
5808 gGameSettings.TimeLimit := StrToIntDef(P[1], -1);
5810 g_Console_Add(Format(_lc[I_MSG_TIME_LIMIT],
5811 [gGameSettings.TimeLimit div 3600,
5812 (gGameSettings.TimeLimit div 60) mod 60,
5813 gGameSettings.TimeLimit mod 60]));
5814 if g_Game_IsNet then MH_SEND_GameSettings;
5815 end
5816 else if (cmd = 'g_maxlives') and not g_Game_IsClient then
5817 begin
5818 if Length(P) > 1 then
5819 begin
5820 if StrToIntDef(P[1], gGameSettings.MaxLives) = 0 then
5821 gGameSettings.MaxLives := 0
5822 else
5823 begin
5824 b := 0;
5825 stat := g_Player_GetStats();
5826 if stat <> nil then
5827 for a := 0 to High(stat) do
5828 if stat[a].Lives > b then
5829 b := stat[a].Lives;
5830 gGameSettings.MaxLives :=
5831 Max(StrToIntDef(P[1], gGameSettings.MaxLives), b);
5832 end;
5833 end;
5835 g_Console_Add(Format(_lc[I_MSG_LIVES],
5836 [gGameSettings.MaxLives]));
5837 if g_Game_IsNet then MH_SEND_GameSettings;
5838 end;
5839 end;
5840 end;
5842 procedure PrintHeapStats();
5843 var
5844 hs: TFPCHeapStatus;
5845 begin
5846 hs := GetFPCHeapStatus();
5847 e_LogWriteLn ('v===== heap status =====v');
5848 e_LogWriteFln('max heap size = %d k', [hs.MaxHeapSize div 1024]);
5849 e_LogWriteFln('max heap used = %d k', [hs.MaxHeapUsed div 1024]);
5850 e_LogWriteFln('cur heap size = %d k', [hs.CurrHeapSize div 1024]);
5851 e_LogWriteFln('cur heap used = %d k', [hs.CurrHeapUsed div 1024]);
5852 e_LogWriteFln('cur heap free = %d k', [hs.CurrHeapFree div 1024]);
5853 e_LogWriteLn ('^=======================^');
5854 end;
5856 procedure DebugCommands(P: SSArray);
5857 var
5858 a, b: Integer;
5859 cmd: string;
5860 //pt: TDFPoint;
5861 mon: TMonster;
5862 begin
5863 // Êîìàíäû îòëàäî÷íîãî ðåæèìà:
5864 if {gDebugMode}conIsCheatsEnabled then
5865 begin
5866 cmd := LowerCase(P[0]);
5867 if cmd = 'd_window' then
5868 begin
5869 g_Console_Add(Format('gWinPosX = %d, gWinPosY %d', [gWinPosX, gWinPosY]));
5870 g_Console_Add(Format('gWinRealPosX = %d, gWinRealPosY %d', [gWinRealPosX, gWinRealPosY]));
5871 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth, gScreenHeight]));
5872 g_Console_Add(Format('gWinSizeX = %d, gWinSizeY = %d', [gWinSizeX, gWinSizeY]));
5873 g_Console_Add(Format('Frame X = %d, Y = %d, Caption Y = %d', [gWinFrameX, gWinFrameY, gWinCaption]));
5874 end
5875 else if cmd = 'd_sounds' then
5876 begin
5877 if (Length(P) > 1) and
5878 ((P[1] = '1') or (P[1] = '0')) then
5879 g_Debug_Sounds := (P[1][1] = '1');
5881 g_Console_Add(Format('d_sounds is %d', [Byte(g_Debug_Sounds)]));
5882 end
5883 else if cmd = 'd_frames' then
5884 begin
5885 if (Length(P) > 1) and
5886 ((P[1] = '1') or (P[1] = '0')) then
5887 g_Debug_Frames := (P[1][1] = '1');
5889 g_Console_Add(Format('d_frames is %d', [Byte(g_Debug_Frames)]));
5890 end
5891 else if cmd = 'd_winmsg' then
5892 begin
5893 if (Length(P) > 1) and
5894 ((P[1] = '1') or (P[1] = '0')) then
5895 g_Debug_WinMsgs := (P[1][1] = '1');
5897 g_Console_Add(Format('d_winmsg is %d', [Byte(g_Debug_WinMsgs)]));
5898 end
5899 else if (cmd = 'd_monoff') and not g_Game_IsNet then
5900 begin
5901 if (Length(P) > 1) and
5902 ((P[1] = '1') or (P[1] = '0')) then
5903 g_Debug_MonsterOff := (P[1][1] = '1');
5905 g_Console_Add(Format('d_monoff is %d', [Byte(g_debug_MonsterOff)]));
5906 end
5907 else if (cmd = 'd_botoff') and not g_Game_IsNet then
5908 begin
5909 if Length(P) > 1 then
5910 case P[1][1] of
5911 '0': g_debug_BotAIOff := 0;
5912 '1': g_debug_BotAIOff := 1;
5913 '2': g_debug_BotAIOff := 2;
5914 '3': g_debug_BotAIOff := 3;
5915 end;
5917 g_Console_Add(Format('d_botoff is %d', [g_debug_BotAIOff]));
5918 end
5919 else if cmd = 'd_monster' then
5920 begin
5921 if gGameOn and (gPlayer1 <> nil) and (gPlayer1.alive) and (not g_Game_IsNet) then
5922 if Length(P) < 2 then
5923 begin
5924 g_Console_Add(cmd + ' [ID | Name] [behaviour]');
5925 g_Console_Add('ID | Name');
5926 for b := MONSTER_DEMON to MONSTER_MAN do
5927 g_Console_Add(Format('%2d | %s', [b, g_Mons_NameByTypeId(b)]));
5928 conwriteln('behav. num'#10'normal 0'#10'killer 1'#10'maniac 2'#10'insane 3'#10'cannibal 4'#10'good 5');
5929 end else
5930 begin
5931 a := StrToIntDef(P[1], 0);
5932 if (a < MONSTER_DEMON) or (a > MONSTER_MAN) then
5933 a := g_Mons_TypeIdByName(P[1]);
5935 if (a < MONSTER_DEMON) or (a > MONSTER_MAN) then
5936 g_Console_Add(Format(_lc[I_MSG_NO_MONSTER], [P[1]]))
5937 else
5938 begin
5939 with gPlayer1.Obj do
5940 begin
5941 mon := g_Monsters_Create(a,
5942 X + Rect.X + (Rect.Width div 2),
5943 Y + Rect.Y + Rect.Height,
5944 gPlayer1.Direction, True);
5945 end;
5946 if (Length(P) > 2) and (mon <> nil) then
5947 begin
5948 if (CompareText(P[2], 'normal') = 0) then mon.MonsterBehaviour := BH_NORMAL
5949 else if (CompareText(P[2], 'killer') = 0) then mon.MonsterBehaviour := BH_KILLER
5950 else if (CompareText(P[2], 'maniac') = 0) then mon.MonsterBehaviour := BH_MANIAC
5951 else if (CompareText(P[2], 'insane') = 0) then mon.MonsterBehaviour := BH_INSANE
5952 else if (CompareText(P[2], 'cannibal') = 0) then mon.MonsterBehaviour := BH_CANNIBAL
5953 else if (CompareText(P[2], 'good') = 0) then mon.MonsterBehaviour := BH_GOOD
5954 else if (CompareText(P[2], 'friend') = 0) then mon.MonsterBehaviour := BH_GOOD
5955 else if (CompareText(P[2], 'friendly') = 0) then mon.MonsterBehaviour := BH_GOOD
5956 else mon.MonsterBehaviour := Min(Max(StrToIntDef(P[2], BH_NORMAL), BH_NORMAL), BH_GOOD);
5957 end;
5958 end;
5959 end;
5960 end
5961 else if (cmd = 'd_health') then
5962 begin
5963 if (Length(P) > 1) and
5964 ((P[1] = '1') or (P[1] = '0')) then
5965 g_debug_HealthBar := (P[1][1] = '1');
5967 g_Console_Add(Format('d_health is %d', [Byte(g_debug_HealthBar)]));
5968 end
5969 else if (cmd = 'd_player') then
5970 begin
5971 if (Length(P) > 1) and
5972 ((P[1] = '1') or (P[1] = '0')) then
5973 g_debug_Player := (P[1][1] = '1');
5975 g_Console_Add(Format(cmd + ' is %d', [Byte(g_Debug_Player)]));
5976 end
5977 else if (cmd = 'd_mem') then
5978 begin
5979 PrintHeapStats();
5980 end;
5981 end
5982 else
5983 g_Console_Add(_lc[I_MSG_NOT_DEBUG]);
5984 end;
5987 procedure GameCheats(P: SSArray);
5988 var
5989 cmd: string;
5990 f, a: Integer;
5991 plr: TPlayer;
5992 begin
5993 if (not gGameOn) or (not conIsCheatsEnabled) then
5994 begin
5995 g_Console_Add('not available');
5996 exit;
5997 end;
5998 plr := gPlayer1;
5999 if plr = nil then
6000 begin
6001 g_Console_Add('where is the player?!');
6002 exit;
6003 end;
6004 cmd := LowerCase(P[0]);
6005 // god
6006 if cmd = 'god' then
6007 begin
6008 plr.GodMode := not plr.GodMode;
6009 if plr.GodMode then g_Console_Add('player is godlike now') else g_Console_Add('player is mortal now');
6010 exit;
6011 end;
6012 // give <health|exit|weapons|air|suit|jetpack|berserk|all>
6013 if cmd = 'give' then
6014 begin
6015 if length(P) < 2 then begin g_Console_Add('give what?!'); exit; end;
6016 for f := 1 to High(P) do
6017 begin
6018 cmd := LowerCase(P[f]);
6019 if cmd = 'health' then begin plr.RestoreHealthArmor(); g_Console_Add('player feels himself better'); continue; end;
6020 if (cmd = 'all') {or (cmd = 'weapons')} then begin plr.AllRulez(False); g_Console_Add('player got the gifts'); continue; end;
6021 if cmd = 'exit' then
6022 begin
6023 if gTriggers <> nil then
6024 begin
6025 for a := 0 to High(gTriggers) do
6026 begin
6027 if gTriggers[a].TriggerType = TRIGGER_EXIT then
6028 begin
6029 g_Console_Add('player left the map');
6030 gExitByTrigger := True;
6031 //g_Game_ExitLevel(gTriggers[a].Data.MapName);
6032 g_Game_ExitLevel(gTriggers[a].tgcMap);
6033 break;
6034 end;
6035 end;
6036 end;
6037 continue;
6038 end;
6040 if cmd = 'air' then begin plr.GiveItem(ITEM_OXYGEN); g_Console_Add('player got some air'); continue; end;
6041 if cmd = 'jetpack' then begin plr.GiveItem(ITEM_JETPACK); g_Console_Add('player got a jetpack'); continue; end;
6042 if cmd = 'suit' then begin plr.GiveItem(ITEM_SUIT); g_Console_Add('player got an envirosuit'); continue; end;
6043 if cmd = 'berserk' then begin plr.GiveItem(ITEM_MEDKIT_BLACK); g_Console_Add('player got a berserk pack'); continue; end;
6044 if cmd = 'backpack' then begin plr.GiveItem(ITEM_AMMO_BACKPACK); g_Console_Add('player got a backpack'); continue; end;
6046 if cmd = 'helmet' then begin plr.GiveItem(ITEM_HELMET); g_Console_Add('player got a helmet'); continue; end;
6047 if cmd = 'bottle' then begin plr.GiveItem(ITEM_BOTTLE); g_Console_Add('player got a bottle of health'); continue; end;
6049 if cmd = 'stimpack' then begin plr.GiveItem(ITEM_MEDKIT_SMALL); g_Console_Add('player got a stimpack'); continue; end;
6050 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;
6052 if cmd = 'greenarmor' then begin plr.GiveItem(ITEM_ARMOR_GREEN); g_Console_Add('player got a security armor'); continue; end;
6053 if cmd = 'bluearmor' then begin plr.GiveItem(ITEM_ARMOR_BLUE); g_Console_Add('player got a combat armor'); continue; end;
6055 if (cmd = 'megasphere') or (cmd = 'mega') then begin plr.GiveItem(ITEM_SPHERE_BLUE); g_Console_Add('player got a megasphere'); continue; end;
6056 if (cmd = 'soulsphere') or (cmd = 'soul')then begin plr.GiveItem(ITEM_SPHERE_WHITE); g_Console_Add('player got a soul sphere'); continue; end;
6058 if (cmd = 'invul') or (cmd = 'invulnerability') then begin plr.GiveItem(ITEM_INVUL); g_Console_Add('player got invulnerability'); continue; end;
6059 if (cmd = 'invis') or (cmd = 'invisibility') then begin plr.GiveItem(ITEM_INVIS); g_Console_Add('player got invisibility'); continue; end;
6061 if cmd = 'redkey' then begin plr.GiveItem(ITEM_KEY_RED); g_Console_Add('player got the red key'); continue; end;
6062 if cmd = 'greenkey' then begin plr.GiveItem(ITEM_KEY_GREEN); g_Console_Add('player got the green key'); continue; end;
6063 if cmd = 'bluekey' then begin plr.GiveItem(ITEM_KEY_BLUE); g_Console_Add('player got the blue key'); continue; end;
6065 if (cmd = 'shotgun') or (cmd = 'sg') then begin plr.GiveItem(ITEM_WEAPON_SHOTGUN1); g_Console_Add('player got a shotgun'); continue; end;
6066 if (cmd = 'supershotgun') or (cmd = 'ssg') then begin plr.GiveItem(ITEM_WEAPON_SHOTGUN2); g_Console_Add('player got a supershotgun'); continue; end;
6067 if cmd = 'chaingun' then begin plr.GiveItem(ITEM_WEAPON_CHAINGUN); g_Console_Add('player got a chaingun'); continue; end;
6068 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;
6069 if cmd = 'plasmagun' then begin plr.GiveItem(ITEM_WEAPON_PLASMA); g_Console_Add('player got a plasma gun'); continue; end;
6070 if cmd = 'bfg' then begin plr.GiveItem(ITEM_WEAPON_BFG); g_Console_Add('player got a BFG-9000'); continue; end;
6072 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;
6073 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;
6074 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;
6075 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;
6076 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;
6077 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;
6079 if cmd = 'superchaingun' then begin plr.GiveItem(ITEM_WEAPON_SUPERPULEMET); g_Console_Add('player got a superchaingun'); continue; end;
6080 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;
6082 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;
6083 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;
6085 if cmd = 'chainsaw' then begin plr.GiveItem(ITEM_WEAPON_SAW); g_Console_Add('player got a chainsaw'); continue; end;
6087 if cmd = 'ammo' then
6088 begin
6089 plr.GiveItem(ITEM_AMMO_SHELLS_BOX);
6090 plr.GiveItem(ITEM_AMMO_BULLETS_BOX);
6091 plr.GiveItem(ITEM_AMMO_CELL_BIG);
6092 plr.GiveItem(ITEM_AMMO_ROCKET_BOX);
6093 plr.GiveItem(ITEM_AMMO_FUELCAN);
6094 g_Console_Add('player got some ammo');
6095 continue;
6096 end;
6098 if cmd = 'clip' then begin plr.GiveItem(ITEM_AMMO_BULLETS); g_Console_Add('player got some bullets'); continue; end;
6099 if cmd = 'bullets' then begin plr.GiveItem(ITEM_AMMO_BULLETS_BOX); g_Console_Add('player got a box of bullets'); continue; end;
6101 if cmd = 'shells' then begin plr.GiveItem(ITEM_AMMO_SHELLS); g_Console_Add('player got some shells'); continue; end;
6102 if cmd = 'shellbox' then begin plr.GiveItem(ITEM_AMMO_SHELLS_BOX); g_Console_Add('player got a box of shells'); continue; end;
6104 if cmd = 'cells' then begin plr.GiveItem(ITEM_AMMO_CELL); g_Console_Add('player got some cells'); continue; end;
6105 if cmd = 'battery' then begin plr.GiveItem(ITEM_AMMO_CELL_BIG); g_Console_Add('player got cell battery'); continue; end;
6107 if cmd = 'rocket' then begin plr.GiveItem(ITEM_AMMO_ROCKET); g_Console_Add('player got a rocket'); continue; end;
6108 if cmd = 'rocketbox' then begin plr.GiveItem(ITEM_AMMO_ROCKET_BOX); g_Console_Add('player got some rockets'); continue; end;
6110 if (cmd = 'fuel') or (cmd = 'fuelcan') then begin plr.GiveItem(ITEM_AMMO_FUELCAN); g_Console_Add('player got fuel canister'); continue; end;
6112 if cmd = 'weapons' then
6113 begin
6114 plr.GiveItem(ITEM_WEAPON_SHOTGUN1);
6115 plr.GiveItem(ITEM_WEAPON_SHOTGUN2);
6116 plr.GiveItem(ITEM_WEAPON_CHAINGUN);
6117 plr.GiveItem(ITEM_WEAPON_ROCKETLAUNCHER);
6118 plr.GiveItem(ITEM_WEAPON_PLASMA);
6119 plr.GiveItem(ITEM_WEAPON_BFG);
6120 g_Console_Add('player got weapons');
6121 continue;
6122 end;
6124 if cmd = 'keys' then
6125 begin
6126 plr.GiveItem(ITEM_KEY_RED);
6127 plr.GiveItem(ITEM_KEY_GREEN);
6128 plr.GiveItem(ITEM_KEY_BLUE);
6129 g_Console_Add('player got all keys');
6130 continue;
6131 end;
6133 g_Console_Add('i don''t know how to give '''+cmd+'''!');
6134 end;
6135 exit;
6136 end;
6137 // open
6138 if cmd = 'open' then
6139 begin
6140 g_Console_Add('player activated sesame');
6141 g_Triggers_OpenAll();
6142 exit;
6143 end;
6144 // fly
6145 if cmd = 'fly' then
6146 begin
6147 gFly := not gFly;
6148 if gFly then g_Console_Add('player feels himself lighter') else g_Console_Add('player lost his wings');
6149 exit;
6150 end;
6151 // noclip
6152 if cmd = 'noclip' then
6153 begin
6154 plr.SwitchNoClip;
6155 g_Console_Add('wall hardeness adjusted');
6156 exit;
6157 end;
6158 // notarget
6159 if cmd = 'notarget' then
6160 begin
6161 plr.NoTarget := not plr.NoTarget;
6162 if plr.NoTarget then g_Console_Add('player hides in shadows') else g_Console_Add('player is brave again');
6163 exit;
6164 end;
6165 // noreload
6166 if cmd = 'noreload' then
6167 begin
6168 plr.NoReload := not plr.NoReload;
6169 if plr.NoReload then g_Console_Add('player is action hero now') else g_Console_Add('player is ordinary man now');
6170 exit;
6171 end;
6172 // speedy
6173 if cmd = 'speedy' then
6174 begin
6175 MAX_RUNVEL := 32-MAX_RUNVEL;
6176 g_Console_Add('speed adjusted');
6177 exit;
6178 end;
6179 // jumpy
6180 if cmd = 'jumpy' then
6181 begin
6182 VEL_JUMP := 30-VEL_JUMP;
6183 g_Console_Add('jump height adjusted');
6184 exit;
6185 end;
6186 // automap
6187 if cmd = 'automap' then
6188 begin
6189 gShowMap := not gShowMap;
6190 if gShowMap then g_Console_Add('player gains second sight') else g_Console_Add('player lost second sight');
6191 exit;
6192 end;
6193 // aimline
6194 if cmd = 'aimline' then
6195 begin
6196 gAimLine := not gAimLine;
6197 if gAimLine then g_Console_Add('player gains laser sight') else g_Console_Add('player lost laser sight');
6198 exit;
6199 end;
6200 end;
6202 procedure GameCommands(P: SSArray);
6203 var
6204 a, b: Integer;
6205 s, pw: String;
6206 chstr: string;
6207 cmd: string;
6208 pl: pTNetClient = nil;
6209 plr: TPlayer;
6210 prt: Word;
6211 nm: Boolean;
6212 listen: LongWord;
6213 found: Boolean;
6214 begin
6215 // Îáùèå êîìàíäû:
6216 cmd := LowerCase(P[0]);
6217 chstr := '';
6218 if (cmd = 'quit') or
6219 (cmd = 'exit') then
6220 begin
6221 g_Game_Free();
6222 g_Game_Quit();
6223 Exit;
6224 end
6225 else if cmd = 'pause' then
6226 begin
6227 if (g_ActiveWindow = nil) then
6228 g_Game_Pause(not gPauseMain);
6229 end
6230 else if cmd = 'endgame' then
6231 gExit := EXIT_SIMPLE
6232 else if cmd = 'restart' then
6233 begin
6234 if gGameOn or (gState in [STATE_INTERSINGLE, STATE_INTERCUSTOM]) then
6235 begin
6236 if g_Game_IsClient then
6237 begin
6238 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6239 Exit;
6240 end;
6241 g_Game_Restart();
6242 end else
6243 g_Console_Add(_lc[I_MSG_NOT_GAME]);
6244 end
6245 else if cmd = 'kick' then
6246 begin
6247 if g_Game_IsServer then
6248 begin
6249 if Length(P) < 2 then
6250 begin
6251 g_Console_Add('kick <name>');
6252 Exit;
6253 end;
6254 if P[1] = '' then
6255 begin
6256 g_Console_Add('kick <name>');
6257 Exit;
6258 end;
6260 if g_Game_IsNet then
6261 pl := g_Net_Client_ByName(P[1]);
6262 if (pl <> nil) then
6263 begin
6264 s := g_Net_ClientName_ByID(pl^.ID);
6265 enet_peer_disconnect(pl^.Peer, NET_DISC_KICK);
6266 g_Console_Add(Format(_lc[I_PLAYER_KICK], [s]));
6267 MH_SEND_GameEvent(NET_EV_PLAYER_KICK, 0, s);
6268 g_Net_Slist_ServerPlayerLeaves();
6269 end else if gPlayers <> nil then
6270 for a := Low(gPlayers) to High(gPlayers) do
6271 if gPlayers[a] <> nil then
6272 if Copy(LowerCase(gPlayers[a].Name), 1, Length(P[1])) = LowerCase(P[1]) then
6273 begin
6274 // Íå îòêëþ÷àòü îñíîâíûõ èãðîêîâ â ñèíãëå
6275 if not(gPlayers[a] is TBot) and (gGameSettings.GameType = GT_SINGLE) then
6276 continue;
6277 gPlayers[a].Lives := 0;
6278 gPlayers[a].Kill(K_SIMPLEKILL, 0, HIT_DISCON);
6279 g_Console_Add(Format(_lc[I_PLAYER_LEAVE], [gPlayers[a].Name]), True);
6280 g_Player_Remove(gPlayers[a].UID);
6281 g_Net_Slist_ServerPlayerLeaves();
6282 // Åñëè íå ïåðåìåøàòü, ïðè äîáàâëåíèè íîâûõ áîòîâ ïîÿâÿòñÿ ñòàðûå
6283 g_Bot_MixNames();
6284 end;
6285 end else
6286 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
6287 end
6288 else if cmd = 'kick_id' then
6289 begin
6290 if g_Game_IsServer and g_Game_IsNet then
6291 begin
6292 if Length(P) < 2 then
6293 begin
6294 g_Console_Add('kick_id <client ID>');
6295 Exit;
6296 end;
6297 if P[1] = '' then
6298 begin
6299 g_Console_Add('kick_id <client ID>');
6300 Exit;
6301 end;
6303 a := StrToIntDef(P[1], 0);
6304 if (NetClients <> nil) and (a <= High(NetClients)) then
6305 begin
6306 if NetClients[a].Used and (NetClients[a].Peer <> nil) then
6307 begin
6308 s := g_Net_ClientName_ByID(NetClients[a].ID);
6309 enet_peer_disconnect(NetClients[a].Peer, NET_DISC_KICK);
6310 g_Console_Add(Format(_lc[I_PLAYER_KICK], [s]));
6311 MH_SEND_GameEvent(NET_EV_PLAYER_KICK, 0, s);
6312 g_Net_Slist_ServerPlayerLeaves();
6313 end;
6314 end;
6315 end else
6316 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6317 end
6318 else if cmd = 'ban' then
6319 begin
6320 if g_Game_IsServer and g_Game_IsNet then
6321 begin
6322 if Length(P) < 2 then
6323 begin
6324 g_Console_Add('ban <name>');
6325 Exit;
6326 end;
6327 if P[1] = '' then
6328 begin
6329 g_Console_Add('ban <name>');
6330 Exit;
6331 end;
6333 pl := g_Net_Client_ByName(P[1]);
6334 if (pl <> nil) then
6335 begin
6336 s := g_Net_ClientName_ByID(pl^.ID);
6337 g_Net_BanHost(pl^.Peer^.address.host, False);
6338 enet_peer_disconnect(pl^.Peer, NET_DISC_TEMPBAN);
6339 g_Console_Add(Format(_lc[I_PLAYER_BAN], [s]));
6340 MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s);
6341 g_Net_Slist_ServerPlayerLeaves();
6342 end else
6343 g_Console_Add(Format(_lc[I_NET_ERR_NAME404], [P[1]]));
6344 end else
6345 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6346 end
6347 else if cmd = 'ban_id' then
6348 begin
6349 if g_Game_IsServer and g_Game_IsNet then
6350 begin
6351 if Length(P) < 2 then
6352 begin
6353 g_Console_Add('ban_id <client ID>');
6354 Exit;
6355 end;
6356 if P[1] = '' then
6357 begin
6358 g_Console_Add('ban_id <client ID>');
6359 Exit;
6360 end;
6362 a := StrToIntDef(P[1], 0);
6363 if (NetClients <> nil) and (a <= High(NetClients)) then
6364 if NetClients[a].Used and (NetClients[a].Peer <> nil) then
6365 begin
6366 s := g_Net_ClientName_ByID(NetClients[a].ID);
6367 g_Net_BanHost(NetClients[a].Peer^.address.host, False);
6368 enet_peer_disconnect(NetClients[a].Peer, NET_DISC_TEMPBAN);
6369 g_Console_Add(Format(_lc[I_PLAYER_BAN], [s]));
6370 MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s);
6371 g_Net_Slist_ServerPlayerLeaves();
6372 end;
6373 end else
6374 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6375 end
6376 else if cmd = 'permban' then
6377 begin
6378 if g_Game_IsServer and g_Game_IsNet then
6379 begin
6380 if Length(P) < 2 then
6381 begin
6382 g_Console_Add('permban <name>');
6383 Exit;
6384 end;
6385 if P[1] = '' then
6386 begin
6387 g_Console_Add('permban <name>');
6388 Exit;
6389 end;
6391 pl := g_Net_Client_ByName(P[1]);
6392 if (pl <> nil) then
6393 begin
6394 s := g_Net_ClientName_ByID(pl^.ID);
6395 g_Net_BanHost(pl^.Peer^.address.host);
6396 enet_peer_disconnect(pl^.Peer, NET_DISC_BAN);
6397 g_Net_SaveBanList();
6398 g_Console_Add(Format(_lc[I_PLAYER_BAN], [s]));
6399 MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s);
6400 g_Net_Slist_ServerPlayerLeaves();
6401 end else
6402 g_Console_Add(Format(_lc[I_NET_ERR_NAME404], [P[1]]));
6403 end else
6404 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6405 end
6406 else if cmd = 'permban_id' then
6407 begin
6408 if g_Game_IsServer and g_Game_IsNet then
6409 begin
6410 if Length(P) < 2 then
6411 begin
6412 g_Console_Add('permban_id <client ID>');
6413 Exit;
6414 end;
6415 if P[1] = '' then
6416 begin
6417 g_Console_Add('permban_id <client ID>');
6418 Exit;
6419 end;
6421 a := StrToIntDef(P[1], 0);
6422 if (NetClients <> nil) and (a <= High(NetClients)) then
6423 if NetClients[a].Used and (NetClients[a].Peer <> nil) then
6424 begin
6425 s := g_Net_ClientName_ByID(NetClients[a].ID);
6426 g_Net_BanHost(NetClients[a].Peer^.address.host);
6427 enet_peer_disconnect(NetClients[a].Peer, NET_DISC_BAN);
6428 g_Net_SaveBanList();
6429 g_Console_Add(Format(_lc[I_PLAYER_BAN], [s]));
6430 MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s);
6431 g_Net_Slist_ServerPlayerLeaves();
6432 end;
6433 end else
6434 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6435 end
6436 else if cmd = 'unban' then
6437 begin
6438 if g_Game_IsServer and g_Game_IsNet then
6439 begin
6440 if Length(P) < 2 then
6441 begin
6442 g_Console_Add('unban <IP Address>');
6443 Exit;
6444 end;
6445 if P[1] = '' then
6446 begin
6447 g_Console_Add('unban <IP Address>');
6448 Exit;
6449 end;
6451 if g_Net_UnbanHost(P[1]) then
6452 begin
6453 g_Console_Add(Format(_lc[I_MSG_UNBAN_OK], [P[1]]));
6454 g_Net_SaveBanList();
6455 end else
6456 g_Console_Add(Format(_lc[I_MSG_UNBAN_FAIL], [P[1]]));
6457 end else
6458 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6459 end
6460 else if cmd = 'clientlist' then
6461 begin
6462 if g_Game_IsServer and g_Game_IsNet then
6463 begin
6464 b := 0;
6465 if NetClients <> nil then
6466 for a := Low(NetClients) to High(NetClients) do
6467 if NetClients[a].Used and (NetClients[a].Peer <> nil) then
6468 begin
6469 plr := g_Player_Get(NetClients[a].Player);
6470 if plr = nil then continue;
6471 Inc(b);
6472 g_Console_Add(Format('#%2d: %-15s | %s', [a,
6473 IpToStr(NetClients[a].Peer^.address.host), plr.Name]));
6474 end;
6475 if b = 0 then
6476 g_Console_Add(_lc[I_MSG_NOCLIENTS]);
6477 end else
6478 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6479 end
6480 else if cmd = 'connect' then
6481 begin
6482 if (NetMode = NET_NONE) then
6483 begin
6484 if Length(P) < 2 then
6485 begin
6486 g_Console_Add('connect <IP> [port] [password]');
6487 Exit;
6488 end;
6489 if P[1] = '' then
6490 begin
6491 g_Console_Add('connect <IP> [port] [password]');
6492 Exit;
6493 end;
6495 if Length(P) > 2 then
6496 prt := StrToIntDef(P[2], 25666)
6497 else
6498 prt := 25666;
6500 if Length(P) > 3 then
6501 pw := P[3]
6502 else
6503 pw := '';
6505 g_Game_StartClient(P[1], prt, pw);
6506 end;
6507 end
6508 else if cmd = 'disconnect' then
6509 begin
6510 if (NetMode = NET_CLIENT) then
6511 g_Net_Disconnect();
6512 end
6513 else if cmd = 'reconnect' then
6514 begin
6515 if (NetMode = NET_SERVER) then
6516 Exit;
6518 if (NetMode = NET_CLIENT) then
6519 begin
6520 g_Net_Disconnect();
6521 gExit := EXIT_SIMPLE;
6522 EndGame;
6523 end;
6525 //TODO: Use last successful password to reconnect, instead of ''
6526 g_Game_StartClient(NetClientIP, NetClientPort, '');
6527 end
6528 else if (cmd = 'addbot') or
6529 (cmd = 'bot_add') then
6530 begin
6531 if Length(P) > 2 then
6532 g_Bot_Add(TEAM_NONE, StrToIntDef(P[1], 2), StrToIntDef(P[2], 100))
6533 else if Length(P) > 1 then
6534 g_Bot_Add(TEAM_NONE, StrToIntDef(P[1], 2))
6535 else
6536 g_Bot_Add(TEAM_NONE, 2);
6537 end
6538 else if cmd = 'bot_addlist' then
6539 begin
6540 if Length(P) > 1 then
6541 begin
6542 if Length(P) = 2 then
6543 g_Bot_AddList(TEAM_NONE, P[1], StrToIntDef(P[1], -1))
6544 else if Length(P) = 3 then
6545 g_Bot_AddList(TEAM_NONE, P[1], StrToIntDef(P[1], -1), StrToIntDef(P[2], 100))
6546 else
6547 g_Bot_AddList(IfThen(P[2] = 'red', TEAM_RED, TEAM_BLUE), P[1], StrToIntDef(P[1], -1));
6548 end;
6549 end
6550 else if cmd = 'bot_removeall' then
6551 g_Bot_RemoveAll()
6552 else if cmd = 'chat' then
6553 begin
6554 if g_Game_IsNet then
6555 begin
6556 if Length(P) > 1 then
6557 begin
6558 for a := 1 to High(P) do
6559 chstr := chstr + P[a] + ' ';
6561 if Length(chstr) > 200 then SetLength(chstr, 200);
6563 if Length(chstr) < 1 then
6564 begin
6565 g_Console_Add('chat <text>');
6566 Exit;
6567 end;
6569 chstr := b_Text_Format(chstr);
6570 if g_Game_IsClient then
6571 MC_SEND_Chat(chstr, NET_CHAT_PLAYER)
6572 else
6573 MH_SEND_Chat(gPlayer1Settings.Name + ': ' + chstr, NET_CHAT_PLAYER);
6574 end
6575 else
6576 g_Console_Add('chat <text>');
6577 end else
6578 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
6579 end
6580 else if cmd = 'teamchat' then
6581 begin
6582 if g_Game_IsNet and (gGameSettings.GameMode in [GM_TDM, GM_CTF]) then
6583 begin
6584 if Length(P) > 1 then
6585 begin
6586 for a := 1 to High(P) do
6587 chstr := chstr + P[a] + ' ';
6589 if Length(chstr) > 200 then SetLength(chstr, 200);
6591 if Length(chstr) < 1 then
6592 begin
6593 g_Console_Add('teamchat <text>');
6594 Exit;
6595 end;
6597 chstr := b_Text_Format(chstr);
6598 if g_Game_IsClient then
6599 MC_SEND_Chat(chstr, NET_CHAT_TEAM)
6600 else
6601 MH_SEND_Chat(gPlayer1Settings.Name + ': ' + chstr, NET_CHAT_TEAM,
6602 gPlayer1Settings.Team);
6603 end
6604 else
6605 g_Console_Add('teamchat <text>');
6606 end else
6607 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
6608 end
6609 else if cmd = 'game' then
6610 begin
6611 if gGameSettings.GameType <> GT_NONE then
6612 begin
6613 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
6614 Exit;
6615 end;
6616 if Length(P) = 1 then
6617 begin
6618 g_Console_Add(cmd + ' <WAD> [MAP] [# players]');
6619 Exit;
6620 end;
6621 // game not started yet, load fist map from some wad
6622 found := false;
6623 s := addWadExtension(P[1]);
6624 found := e_FindResource(AllMapDirs, s);
6625 P[1] := s;
6626 if found then
6627 begin
6628 P[1] := ExpandFileName(P[1]);
6629 // if map not choosed then set first map
6630 if Length(P) < 3 then
6631 begin
6632 SetLength(P, 3);
6633 P[2] := g_Game_GetFirstMap(P[1]);
6634 end;
6636 s := P[1] + ':\' + UpperCase(P[2]);
6638 if g_Map_Exist(s) then
6639 begin
6640 // start game
6641 g_Game_Free();
6642 with gGameSettings do
6643 begin
6644 GameMode := g_Game_TextToMode(gcGameMode);
6645 if gSwitchGameMode <> GM_NONE then
6646 GameMode := gSwitchGameMode;
6647 if GameMode = GM_NONE then GameMode := GM_DM;
6648 if GameMode = GM_SINGLE then GameMode := GM_COOP;
6649 b := 1;
6650 if Length(P) >= 4 then
6651 b := StrToIntDef(P[3], 1);
6652 g_Game_StartCustom(s, GameMode, TimeLimit,
6653 GoalLimit, MaxLives, Options, b);
6654 end;
6655 end
6656 else
6657 if P[2] = '' then
6658 g_Console_Add(Format(_lc[I_MSG_NO_MAPS], [P[1]]))
6659 else
6660 g_Console_Add(Format(_lc[I_MSG_NO_MAP_FALLBACK], [UpperCase(P[2]), P[1]]));
6661 end else
6662 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]));
6663 end
6664 else if cmd = 'host' then
6665 begin
6666 if gGameSettings.GameType <> GT_NONE then
6667 begin
6668 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
6669 Exit;
6670 end;
6671 if Length(P) < 4 then
6672 begin
6673 g_Console_Add(cmd + ' <listen IP> <port> <WAD> [MAP] [# players]');
6674 Exit;
6675 end;
6676 if not StrToIp(P[1], listen) then
6677 Exit;
6678 prt := StrToIntDef(P[2], 25666);
6680 s := addWadExtension(P[3]);
6681 found := e_FindResource(AllMapDirs, s);
6682 P[3] := s;
6683 if found then
6684 begin
6685 // get first map in wad, if not specified
6686 if Length(P) < 5 then
6687 begin
6688 SetLength(P, 5);
6689 P[4] := g_Game_GetFirstMap(P[1]);
6690 end;
6691 s := P[3] + ':\' + UpperCase(P[4]);
6692 if g_Map_Exist(s) then
6693 begin
6694 // start game
6695 g_Game_Free();
6696 with gGameSettings do
6697 begin
6698 GameMode := g_Game_TextToMode(gcGameMode);
6699 if gSwitchGameMode <> GM_NONE then GameMode := gSwitchGameMode;
6700 if GameMode = GM_NONE then GameMode := GM_DM;
6701 if GameMode = GM_SINGLE then GameMode := GM_COOP;
6702 b := 0;
6703 if Length(P) >= 6 then
6704 b := StrToIntDef(P[5], 0);
6705 g_Game_StartServer(s, GameMode, TimeLimit, GoalLimit, MaxLives, Options, b, listen, prt)
6706 end
6707 end
6708 else
6709 begin
6710 if P[4] = '' then
6711 g_Console_Add(Format(_lc[I_MSG_NO_MAPS], [P[3]]))
6712 else
6713 g_Console_Add(Format(_lc[I_MSG_NO_MAP_FALLBACK], [UpperCase(P[4]), P[3]]))
6714 end
6715 end
6716 else
6717 begin
6718 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[3]]))
6719 end
6720 end
6721 else if cmd = 'map' then
6722 begin
6723 if Length(P) = 1 then
6724 begin
6725 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
6726 begin
6727 g_Console_Add(cmd + ' <MAP>');
6728 g_Console_Add(cmd + ' <WAD> [MAP]')
6729 end
6730 else
6731 begin
6732 g_Console_Add(_lc[I_MSG_GM_UNAVAIL])
6733 end
6734 end
6735 else
6736 begin
6737 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
6738 begin
6739 if Length(P) < 3 then
6740 begin
6741 // first param is map or wad
6742 s := UpperCase(P[1]);
6743 if g_Map_Exist(gGameSettings.WAD + ':\' + s) then
6744 begin
6745 gExitByTrigger := False;
6746 if gGameOn then
6747 begin
6748 // already in game, finish current map
6749 gNextMap := s;
6750 gExit := EXIT_ENDLEVELCUSTOM;
6751 end
6752 else
6753 begin
6754 // intermission, so change map immediately
6755 g_Game_ChangeMap(s)
6756 end
6757 end
6758 else
6759 begin
6760 s := P[1];
6761 found := e_FindResource(AllMapDirs, s);
6762 P[1] := s;
6763 g_Console_Add(Format(_lc[I_MSG_NO_MAP_FALLBACK], [s, 'WAD ' + P[1]]));
6764 if found then
6765 begin
6766 // no such map, found wad
6767 pw := P[1];
6768 SetLength(P, 3);
6769 P[1] := ExpandFileName(pw);
6770 P[2] := g_Game_GetFirstMap(P[1]);
6771 s := P[1] + ':\' + P[2];
6772 if g_Map_Exist(s) then
6773 begin
6774 gExitByTrigger := False;
6775 if gGameOn then
6776 begin
6777 // already in game, finish current map
6778 gNextMap := s;
6779 gExit := EXIT_ENDLEVELCUSTOM
6780 end
6781 else
6782 begin
6783 // intermission, so change map immediately
6784 g_Game_ChangeMap(s)
6785 end
6786 end
6787 else
6788 begin
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
6794 end
6795 else
6796 begin
6797 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]))
6798 end
6799 end;
6800 end
6801 else
6802 begin
6803 s := addWadExtension(P[1]);
6804 found := e_FindResource(AllMapDirs, s);
6805 P[1] := s;
6806 if found then
6807 begin
6808 P[2] := UpperCase(P[2]);
6809 s := P[1] + ':\' + P[2];
6810 if g_Map_Exist(s) then
6811 begin
6812 gExitByTrigger := False;
6813 if gGameOn then
6814 begin
6815 gNextMap := s;
6816 gExit := EXIT_ENDLEVELCUSTOM
6817 end
6818 else
6819 begin
6820 g_Game_ChangeMap(s)
6821 end
6822 end
6823 else
6824 begin
6825 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [P[2]]))
6826 end
6827 end
6828 else
6829 begin
6830 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]))
6831 end
6832 end
6833 end
6834 else
6835 begin
6836 g_Console_Add(_lc[I_MSG_GM_UNAVAIL])
6837 end
6838 end
6839 end
6840 else if cmd = 'nextmap' then
6841 begin
6842 if not(gGameOn or (gState = STATE_INTERCUSTOM)) then
6843 begin
6844 g_Console_Add(_lc[I_MSG_NOT_GAME])
6845 end
6846 else
6847 begin
6848 nm := True;
6849 if Length(P) = 1 then
6850 begin
6851 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
6852 begin
6853 g_Console_Add(cmd + ' <MAP>');
6854 g_Console_Add(cmd + ' <WAD> [MAP]');
6855 end
6856 else
6857 begin
6858 nm := False;
6859 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
6860 end;
6861 end
6862 else
6863 begin
6864 nm := False;
6865 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
6866 begin
6867 if Length(P) < 3 then
6868 begin
6869 // first param is map or wad
6870 s := UpperCase(P[1]);
6871 if g_Map_Exist(gGameSettings.WAD + ':\' + s) then
6872 begin
6873 // map founded
6874 gExitByTrigger := False;
6875 gNextMap := s;
6876 nm := True;
6877 end
6878 else
6879 begin
6880 // no such map, found wad
6881 pw := addWadExtension(P[1]);
6882 found := e_FindResource(MapDirs, pw);
6883 if not found then
6884 found := e_FindResource(WadDirs, pw);
6885 P[1] := pw;
6886 g_Console_Add(Format(_lc[I_MSG_NO_MAP_FALLBACK], [s, P[1]]));
6887 if found then
6888 begin
6889 // map not specified, select first map
6890 SetLength(P, 3);
6891 P[2] := g_Game_GetFirstMap(P[1]);
6892 s := P[1] + ':\' + P[2];
6893 if g_Map_Exist(s) then
6894 begin
6895 gExitByTrigger := False;
6896 gNextMap := s;
6897 nm := True
6898 end
6899 else
6900 begin
6901 if P[2] = '' then
6902 g_Console_Add(Format(_lc[I_MSG_NO_MAPS], [P[1]]))
6903 else
6904 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [P[2]]))
6905 end
6906 end
6907 else
6908 begin
6909 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]))
6910 end
6911 end
6912 end
6913 else
6914 begin
6915 // specified two params wad + map
6916 pw := addWadExtension(P[1]);
6917 found := e_FindResource(MapDirs, pw);
6918 if not found then
6919 found := e_FindResource(MapDirs, pw);
6920 P[1] := pw;
6921 if found then
6922 begin
6923 P[2] := UpperCase(P[2]);
6924 s := P[1] + ':\' + P[2];
6925 if g_Map_Exist(s) then
6926 begin
6927 gExitByTrigger := False;
6928 gNextMap := s;
6929 nm := True
6930 end
6931 else
6932 begin
6933 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [P[2]]))
6934 end
6935 end
6936 else
6937 begin
6938 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]))
6939 end
6940 end
6941 end
6942 else
6943 begin
6944 g_Console_Add(_lc[I_MSG_GM_UNAVAIL])
6945 end
6946 end;
6947 if nm then
6948 begin
6949 if gNextMap = '' then
6950 g_Console_Add(_lc[I_MSG_NEXTMAP_UNSET])
6951 else
6952 g_Console_Add(Format(_lc[I_MSG_NEXTMAP_SET], [gNextMap]))
6953 end
6954 end
6955 end
6956 else if (cmd = 'endmap') or (cmd = 'goodbye') then
6957 begin
6958 if not gGameOn then
6959 begin
6960 g_Console_Add(_lc[I_MSG_NOT_GAME])
6961 end
6962 else
6963 begin
6964 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
6965 begin
6966 gExitByTrigger := False;
6967 // next map not specified, try to find trigger EXIT
6968 if (gNextMap = '') and (gTriggers <> nil) then
6969 begin
6970 for a := 0 to High(gTriggers) do
6971 begin
6972 if gTriggers[a].TriggerType = TRIGGER_EXIT then
6973 begin
6974 gExitByTrigger := True;
6975 //gNextMap := gTriggers[a].Data.MapName;
6976 gNextMap := gTriggers[a].tgcMap;
6977 Break
6978 end
6979 end
6980 end;
6981 if gNextMap = '' then
6982 gNextMap := g_Game_GetNextMap();
6983 if not isWadPath(gNextMap) then
6984 s := gGameSettings.WAD + ':\' + gNextMap
6985 else
6986 s := gNextMap;
6987 if g_Map_Exist(s) then
6988 gExit := EXIT_ENDLEVELCUSTOM
6989 else
6990 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [gNextMap]))
6991 end
6992 else
6993 begin
6994 g_Console_Add(_lc[I_MSG_GM_UNAVAIL])
6995 end
6996 end
6997 end
6998 else if (cmd = 'event') then
6999 begin
7000 if (Length(P) <= 1) then
7001 begin
7002 for a := 0 to High(gEvents) do
7003 if gEvents[a].Command = '' then
7004 g_Console_Add(gEvents[a].Name + ' <none>')
7005 else
7006 g_Console_Add(gEvents[a].Name + ' "' + gEvents[a].Command + '"');
7007 Exit;
7008 end;
7009 if (Length(P) = 2) then
7010 begin
7011 for a := 0 to High(gEvents) do
7012 if gEvents[a].Name = P[1] then
7013 if gEvents[a].Command = '' then
7014 g_Console_Add(gEvents[a].Name + ' <none>')
7015 else
7016 g_Console_Add(gEvents[a].Name + ' "' + gEvents[a].Command + '"');
7017 Exit;
7018 end;
7019 for a := 0 to High(gEvents) do
7020 if gEvents[a].Name = P[1] then
7021 begin
7022 gEvents[a].Command := '';
7023 for b := 2 to High(P) do
7024 if Pos(' ', P[b]) = 0 then
7025 gEvents[a].Command := gEvents[a].Command + ' ' + P[b]
7026 else
7027 gEvents[a].Command := gEvents[a].Command + ' "' + P[b] + '"';
7028 gEvents[a].Command := Trim(gEvents[a].Command);
7029 Exit;
7030 end;
7031 end
7032 else if cmd = 'suicide' then
7033 begin
7034 if gGameOn then
7035 begin
7036 if g_Game_IsClient then
7037 MC_SEND_CheatRequest(NET_CHEAT_SUICIDE)
7038 else
7039 begin
7040 if gPlayer1 <> nil then
7041 gPlayer1.Damage(SUICIDE_DAMAGE, gPlayer1.UID, 0, 0, HIT_SELF);
7042 if gPlayer2 <> nil then
7043 gPlayer2.Damage(SUICIDE_DAMAGE, gPlayer2.UID, 0, 0, HIT_SELF);
7044 end;
7045 end;
7046 end
7047 else if cmd = 'screenshot' then
7048 begin
7049 g_TakeScreenShot()
7050 end
7051 else if cmd = 'weapon' then
7052 begin
7053 if Length(p) = 2 then
7054 begin
7055 a := WP_FIRST + StrToInt(p[1]) - 1;
7056 if (a >= WP_FIRST) and (a <= WP_LAST) then
7057 gSelectWeapon[0, a] := True
7058 end
7059 end
7060 else if (cmd = 'p1_weapon') or (cmd = 'p2_weapon') then
7061 begin
7062 if Length(p) = 2 then
7063 begin
7064 a := WP_FIRST + StrToInt(p[1]) - 1;
7065 b := ord(cmd[2]) - ord('1');
7066 if (a >= WP_FIRST) and (a <= WP_LAST) then
7067 gSelectWeapon[b, a] := True
7068 end
7069 end
7070 // Êîìàíäû Ñâîåé èãðû:
7071 else if gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT] then
7072 begin
7073 if cmd = 'bot_addred' then
7074 begin
7075 if Length(P) > 1 then
7076 g_Bot_Add(TEAM_RED, StrToIntDef(P[1], 2))
7077 else
7078 g_Bot_Add(TEAM_RED, 2);
7079 end
7080 else if cmd = 'bot_addblue' then
7081 begin
7082 if Length(P) > 1 then
7083 g_Bot_Add(TEAM_BLUE, StrToIntDef(P[1], 2))
7084 else
7085 g_Bot_Add(TEAM_BLUE, 2);
7086 end
7087 else if cmd = 'spectate' then
7088 begin
7089 if not gGameOn then
7090 Exit;
7091 g_Game_Spectate();
7092 end
7093 else if cmd = 'say' then
7094 begin
7095 if g_Game_IsServer and g_Game_IsNet then
7096 begin
7097 if Length(P) > 1 then
7098 begin
7099 chstr := '';
7100 for a := 1 to High(P) do
7101 chstr := chstr + P[a] + ' ';
7103 if Length(chstr) > 200 then SetLength(chstr, 200);
7105 if Length(chstr) < 1 then
7106 begin
7107 g_Console_Add('say <text>');
7108 Exit;
7109 end;
7111 chstr := b_Text_Format(chstr);
7112 MH_SEND_Chat(chstr, NET_CHAT_PLAYER);
7113 end
7114 else g_Console_Add('say <text>');
7115 end else
7116 g_Console_Add(_lc[I_MSG_SERVERONLY]);
7117 end
7118 else if cmd = 'tell' then
7119 begin
7120 if g_Game_IsServer and g_Game_IsNet then
7121 begin
7122 if (Length(P) > 2) and (P[1] <> '') then
7123 begin
7124 chstr := '';
7125 for a := 2 to High(P) do
7126 chstr := chstr + P[a] + ' ';
7128 if Length(chstr) > 200 then SetLength(chstr, 200);
7130 if Length(chstr) < 1 then
7131 begin
7132 g_Console_Add('tell <playername> <text>');
7133 Exit;
7134 end;
7136 pl := g_Net_Client_ByName(P[1]);
7137 if pl <> nil then
7138 MH_SEND_Chat(b_Text_Format(chstr), NET_CHAT_PLAYER, pl^.ID)
7139 else
7140 g_Console_Add(Format(_lc[I_NET_ERR_NAME404], [P[1]]));
7141 end
7142 else g_Console_Add('tell <playername> <text>');
7143 end else
7144 g_Console_Add(_lc[I_MSG_SERVERONLY]);
7145 end
7146 else if (cmd = 'overtime') and not g_Game_IsClient then
7147 begin
7148 if (Length(P) = 1) or (StrToIntDef(P[1], -1) <= 0) then
7149 Exit;
7150 // Äîïîëíèòåëüíîå âðåìÿ:
7151 gGameSettings.TimeLimit := (gTime - gGameStartTime) div 1000 + Word(StrToIntDef(P[1], 0));
7153 g_Console_Add(Format(_lc[I_MSG_TIME_LIMIT],
7154 [gGameSettings.TimeLimit div 3600,
7155 (gGameSettings.TimeLimit div 60) mod 60,
7156 gGameSettings.TimeLimit mod 60]));
7157 if g_Game_IsNet then MH_SEND_GameSettings;
7158 end
7159 else if (cmd = 'rcon_password') and g_Game_IsClient then
7160 begin
7161 if (Length(P) <= 1) then
7162 g_Console_Add('rcon_password <password>')
7163 else
7164 MC_SEND_RCONPassword(P[1]);
7165 end
7166 else if cmd = 'rcon' then
7167 begin
7168 if g_Game_IsClient then
7169 begin
7170 if Length(P) > 1 then
7171 begin
7172 chstr := '';
7173 for a := 1 to High(P) do
7174 chstr := chstr + P[a] + ' ';
7176 if Length(chstr) > 200 then SetLength(chstr, 200);
7178 if Length(chstr) < 1 then
7179 begin
7180 g_Console_Add('rcon <command>');
7181 Exit;
7182 end;
7184 MC_SEND_RCONCommand(chstr);
7185 end
7186 else g_Console_Add('rcon <command>');
7187 end;
7188 end
7189 else if cmd = 'ready' then
7190 begin
7191 if g_Game_IsServer and (gLMSRespawn = LMS_RESPAWN_WARMUP) then
7192 gLMSRespawnTime := gTime + 100;
7193 end
7194 else if (cmd = 'callvote') and g_Game_IsNet then
7195 begin
7196 if Length(P) > 1 then
7197 begin
7198 chstr := '';
7199 for a := 1 to High(P) do begin
7200 if a > 1 then chstr := chstr + ' ';
7201 chstr := chstr + P[a];
7202 end;
7204 if Length(chstr) > 200 then SetLength(chstr, 200);
7206 if Length(chstr) < 1 then
7207 begin
7208 g_Console_Add('callvote <command>');
7209 Exit;
7210 end;
7212 if g_Game_IsClient then
7213 MC_SEND_Vote(True, chstr)
7214 else
7215 g_Game_StartVote(chstr, gPlayer1Settings.Name);
7216 g_Console_Process('vote', True);
7217 end
7218 else
7219 g_Console_Add('callvote <command>');
7220 end
7221 else if (cmd = 'vote') and g_Game_IsNet then
7222 begin
7223 if g_Game_IsClient then
7224 MC_SEND_Vote(False)
7225 else if gVoteInProgress then
7226 begin
7227 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
7228 a := Floor((NetClientCount+1)/2.0) + 1
7229 else
7230 a := Floor(NetClientCount/2.0) + 1;
7231 if gVoted then
7232 begin
7233 Dec(gVoteCount);
7234 gVoted := False;
7235 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_REVOKED], [gPlayer1Settings.Name, gVoteCount, a]), True);
7236 MH_SEND_VoteEvent(NET_VE_REVOKE, gPlayer1Settings.Name, 'a', gVoteCount, a);
7237 end
7238 else
7239 begin
7240 Inc(gVoteCount);
7241 gVoted := True;
7242 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_VOTE], [gPlayer1Settings.Name, gVoteCount, a]), True);
7243 MH_SEND_VoteEvent(NET_VE_VOTE, gPlayer1Settings.Name, 'a', gVoteCount, a);
7244 g_Game_CheckVote;
7245 end;
7246 end;
7247 end
7248 end;
7249 end;
7251 procedure g_TakeScreenShot;
7252 var s: TStream; t: TDateTime; date, name: String;
7253 begin
7254 if e_NoGraphics then Exit;
7255 t := Now;
7256 DateTimeToString(date, 'yyyy-mm-dd-hh-nn-ss', t);
7257 name := 'screenshot-' + date + '.png';
7258 try
7259 s := e_CreateResource(ScreenshotDirs, name);
7260 e_MakeScreenshot(s, gScreenWidth, gScreenHeight);
7261 g_Console_Add(Format(_lc[I_CONSOLE_SCREENSHOT], [name]))
7262 except
7263 g_Console_Add('oh shit, i can''t create screenshot!')
7264 end
7265 end;
7267 procedure g_Game_InGameMenu(Show: Boolean);
7268 begin
7269 if (g_ActiveWindow = nil) and Show then
7270 begin
7271 if gGameSettings.GameType = GT_SINGLE then
7272 g_GUI_ShowWindow('GameSingleMenu')
7273 else
7274 begin
7275 if g_Game_IsClient then
7276 g_GUI_ShowWindow('GameClientMenu')
7277 else
7278 if g_Game_IsNet then
7279 g_GUI_ShowWindow('GameServerMenu')
7280 else
7281 g_GUI_ShowWindow('GameCustomMenu');
7282 end;
7283 g_Sound_PlayEx('MENU_OPEN');
7285 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
7286 if (not g_Game_IsNet) then
7287 g_Game_Pause(True);
7288 end
7289 else
7290 if (g_ActiveWindow <> nil) and (not Show) then
7291 begin
7292 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
7293 if (not g_Game_IsNet) then
7294 g_Game_Pause(False);
7295 end;
7296 end;
7298 procedure g_Game_Pause (Enable: Boolean);
7299 var
7300 oldPause: Boolean;
7301 begin
7302 if not gGameOn then exit;
7304 if not (gGameSettings.GameType in [GT_SINGLE, GT_CUSTOM]) then exit;
7306 oldPause := gPause;
7307 gPauseMain := Enable;
7309 if (gPause <> oldPause) then g_Game_PauseAllSounds(gPause);
7310 end;
7312 procedure g_Game_HolmesPause (Enable: Boolean);
7313 var
7314 oldPause: Boolean;
7315 begin
7316 if not gGameOn then exit;
7317 if not (gGameSettings.GameType in [GT_SINGLE, GT_CUSTOM]) then exit;
7319 oldPause := gPause;
7320 gPauseHolmes := Enable;
7322 if (gPause <> oldPause) then g_Game_PauseAllSounds(gPause);
7323 end;
7325 procedure g_Game_PauseAllSounds(Enable: Boolean);
7326 var
7327 i: Integer;
7328 begin
7329 // Òðèããåðû:
7330 if gTriggers <> nil then
7331 for i := 0 to High(gTriggers) do
7332 with gTriggers[i] do
7333 if (TriggerType = TRIGGER_SOUND) and
7334 (Sound <> nil) and
7335 Sound.IsPlaying() then
7336 begin
7337 Sound.Pause(Enable);
7338 end;
7340 // Çâóêè èãðîêîâ:
7341 if gPlayers <> nil then
7342 for i := 0 to High(gPlayers) do
7343 if gPlayers[i] <> nil then
7344 gPlayers[i].PauseSounds(Enable);
7346 // Ìóçûêà:
7347 if gMusic <> nil then
7348 gMusic.Pause(Enable);
7349 end;
7351 procedure g_Game_StopAllSounds(all: Boolean);
7352 var
7353 i: Integer;
7354 begin
7355 if gTriggers <> nil then
7356 for i := 0 to High(gTriggers) do
7357 with gTriggers[i] do
7358 if (TriggerType = TRIGGER_SOUND) and
7359 (Sound <> nil) then
7360 Sound.Stop();
7362 if gMusic <> nil then
7363 gMusic.Stop();
7365 if all then
7366 e_StopChannels();
7367 end;
7369 procedure g_Game_UpdateTriggerSounds;
7370 var i: Integer;
7371 begin
7372 if gTriggers <> nil then
7373 for i := 0 to High(gTriggers) do
7374 with gTriggers[i] do
7375 if (TriggerType = TRIGGER_SOUND) and (Sound <> nil) and tgcLocal and Sound.IsPlaying() then
7376 Sound.SetCoordsRect(X, Y, Width, Height, tgcVolume / 255.0)
7377 end;
7379 function g_Game_IsWatchedPlayer(UID: Word): Boolean;
7380 begin
7381 Result := False;
7382 if (gPlayer1 <> nil) and (gPlayer1.UID = UID) then
7383 begin
7384 Result := True;
7385 Exit;
7386 end;
7387 if (gPlayer2 <> nil) and (gPlayer2.UID = UID) then
7388 begin
7389 Result := True;
7390 Exit;
7391 end;
7392 if gSpectMode <> SPECT_PLAYERS then
7393 Exit;
7394 if gSpectPID1 = UID then
7395 begin
7396 Result := True;
7397 Exit;
7398 end;
7399 if gSpectViewTwo and (gSpectPID2 = UID) then
7400 begin
7401 Result := True;
7402 Exit;
7403 end;
7404 end;
7406 function g_Game_IsWatchedTeam(Team: Byte): Boolean;
7407 var
7408 Pl: TPlayer;
7409 begin
7410 Result := False;
7411 if (gPlayer1 <> nil) and (gPlayer1.Team = Team) then
7412 begin
7413 Result := True;
7414 Exit;
7415 end;
7416 if (gPlayer2 <> nil) and (gPlayer2.Team = Team) then
7417 begin
7418 Result := True;
7419 Exit;
7420 end;
7421 if gSpectMode <> SPECT_PLAYERS then
7422 Exit;
7423 Pl := g_Player_Get(gSpectPID1);
7424 if (Pl <> nil) and (Pl.Team = Team) then
7425 begin
7426 Result := True;
7427 Exit;
7428 end;
7429 if gSpectViewTwo then
7430 begin
7431 Pl := g_Player_Get(gSpectPID2);
7432 if (Pl <> nil) and (Pl.Team = Team) then
7433 begin
7434 Result := True;
7435 Exit;
7436 end;
7437 end;
7438 end;
7440 procedure g_Game_Message(Msg: string; Time: Word);
7441 begin
7442 MessageLineLength := (gScreenWidth - 204) div e_CharFont_GetMaxWidth(gMenuFont);
7443 MessageText := b_Text_Wrap(b_Text_Format(Msg), MessageLineLength);
7444 MessageTime := Time;
7445 end;
7447 procedure g_Game_ChatSound(Text: String; Taunt: Boolean = True);
7448 const
7449 punct: Array[0..13] of String =
7450 ('.', ',', ':', ';', '!', '?', '(', ')', '''', '"', '/', '\', '*', '^');
7451 var
7452 i, j: Integer;
7453 ok: Boolean;
7454 fpText: String;
7456 function IsPunctuation(S: String): Boolean;
7457 var
7458 i: Integer;
7459 begin
7460 Result := False;
7461 if Length(S) <> 1 then
7462 Exit;
7463 for i := Low(punct) to High(punct) do
7464 if S = punct[i] then
7465 begin
7466 Result := True;
7467 break;
7468 end;
7469 end;
7470 function FilterPunctuation(S: String): String;
7471 var
7472 i: Integer;
7473 begin
7474 for i := Low(punct) to High(punct) do
7475 S := StringReplace(S, punct[i], ' ', [rfReplaceAll]);
7476 Result := S;
7477 end;
7478 begin
7479 ok := False;
7481 if gUseChatSounds and Taunt and (gChatSounds <> nil) and (Pos(': ', Text) > 0) then
7482 begin
7483 // remove player name
7484 Delete(Text, 1, Pos(': ', Text) + 2 - 1);
7485 // for FullWord check
7486 Text := toLowerCase1251(' ' + Text + ' ');
7487 fpText := FilterPunctuation(Text);
7489 for i := 0 to Length(gChatSounds) - 1 do
7490 begin
7491 ok := True;
7492 for j := 0 to Length(gChatSounds[i].Tags) - 1 do
7493 begin
7494 if gChatSounds[i].FullWord and (not IsPunctuation(gChatSounds[i].Tags[j])) then
7495 ok := Pos(' ' + gChatSounds[i].Tags[j] + ' ', fpText) > 0
7496 else
7497 ok := Pos(gChatSounds[i].Tags[j], Text) > 0;
7498 if not ok then
7499 break;
7500 end;
7501 if ok then
7502 begin
7503 gChatSounds[i].Sound.Play();
7504 break;
7505 end;
7506 end;
7507 end;
7508 if not ok then
7509 g_Sound_PlayEx('SOUND_GAME_RADIO');
7510 end;
7512 procedure g_Game_Announce_GoodShot(SpawnerUID: Word);
7513 var
7514 a: Integer;
7515 begin
7516 case gAnnouncer of
7517 ANNOUNCE_NONE:
7518 Exit;
7519 ANNOUNCE_ME,
7520 ANNOUNCE_MEPLUS:
7521 if not g_Game_IsWatchedPlayer(SpawnerUID) then
7522 Exit;
7523 end;
7524 for a := 0 to 3 do
7525 if goodsnd[a].IsPlaying() then
7526 Exit;
7528 goodsnd[Random(4)].Play();
7529 end;
7531 procedure g_Game_Announce_KillCombo(Param: Integer);
7532 var
7533 UID: Word;
7534 c, n: Byte;
7535 Pl: TPlayer;
7536 Name: String;
7537 begin
7538 UID := Param and $FFFF;
7539 c := Param shr 16;
7540 if c < 2 then
7541 Exit;
7543 Pl := g_Player_Get(UID);
7544 if Pl = nil then
7545 Name := '?'
7546 else
7547 Name := Pl.Name;
7549 case c of
7550 2: begin
7551 n := 0;
7552 g_Console_Add(Format(_lc[I_PLAYER_KILL_2X], [Name]), True);
7553 end;
7554 3: begin
7555 n := 1;
7556 g_Console_Add(Format(_lc[I_PLAYER_KILL_3X], [Name]), True);
7557 end;
7558 4: begin
7559 n := 2;
7560 g_Console_Add(Format(_lc[I_PLAYER_KILL_4X], [Name]), True);
7561 end;
7562 else begin
7563 n := 3;
7564 g_Console_Add(Format(_lc[I_PLAYER_KILL_MX], [Name]), True);
7565 end;
7566 end;
7568 case gAnnouncer of
7569 ANNOUNCE_NONE:
7570 Exit;
7571 ANNOUNCE_ME:
7572 if not g_Game_IsWatchedPlayer(UID) then
7573 Exit;
7574 ANNOUNCE_MEPLUS:
7575 if (not g_Game_IsWatchedPlayer(UID)) and (c < 4) then
7576 Exit;
7577 end;
7579 if killsnd[n].IsPlaying() then
7580 killsnd[n].Stop();
7581 killsnd[n].Play();
7582 end;
7584 procedure g_Game_Announce_BodyKill(SpawnerUID: Word);
7585 var
7586 a: Integer;
7587 begin
7588 case gAnnouncer of
7589 ANNOUNCE_NONE:
7590 Exit;
7591 ANNOUNCE_ME,
7592 ANNOUNCE_MEPLUS:
7593 if not g_Game_IsWatchedPlayer(SpawnerUID) then
7594 Exit;
7595 end;
7596 for a := 0 to 2 do
7597 if hahasnd[a].IsPlaying() then
7598 Exit;
7600 hahasnd[Random(3)].Play();
7601 end;
7603 procedure g_Game_StartVote(Command, Initiator: string);
7604 var
7605 Need: Integer;
7606 begin
7607 if not gVotesEnabled then Exit;
7608 if gGameSettings.GameType <> GT_SERVER then Exit;
7609 if gVoteInProgress or gVotePassed then
7610 begin
7611 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_INPROGRESS], [gVoteCommand]), True);
7612 MH_SEND_VoteEvent(NET_VE_INPROGRESS, gVoteCommand);
7613 Exit;
7614 end;
7615 gVoteInProgress := True;
7616 gVotePassed := False;
7617 gVoteTimer := gTime + gVoteTimeout * 1000;
7618 gVoteCount := 0;
7619 gVoted := False;
7620 gVoteCommand := Command;
7622 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
7623 Need := Floor((NetClientCount+1)/2.0)+1
7624 else
7625 Need := Floor(NetClientCount/2.0)+1;
7626 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_STARTED], [Initiator, Command, Need]), True);
7627 MH_SEND_VoteEvent(NET_VE_STARTED, Initiator, Command, Need);
7628 end;
7630 procedure g_Game_CheckVote;
7631 var
7632 I, Need: Integer;
7633 begin
7634 if gGameSettings.GameType <> GT_SERVER then Exit;
7635 if not gVoteInProgress then Exit;
7637 if (gTime >= gVoteTimer) then
7638 begin
7639 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
7640 Need := Floor((NetClientCount+1)/2.0) + 1
7641 else
7642 Need := Floor(NetClientCount/2.0) + 1;
7643 if gVoteCount >= Need then
7644 begin
7645 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_PASSED], [gVoteCommand]), True);
7646 MH_SEND_VoteEvent(NET_VE_PASSED, gVoteCommand);
7647 gVotePassed := True;
7648 gVoteCmdTimer := gTime + 5000;
7649 end
7650 else
7651 begin
7652 g_Console_Add(_lc[I_MESSAGE_VOTE_FAILED], True);
7653 MH_SEND_VoteEvent(NET_VE_FAILED);
7654 end;
7655 if NetClients <> nil then
7656 for I := Low(NetClients) to High(NetClients) do
7657 if NetClients[i].Used then
7658 NetClients[i].Voted := False;
7659 gVoteInProgress := False;
7660 gVoted := False;
7661 gVoteCount := 0;
7662 end
7663 else
7664 begin
7665 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
7666 Need := Floor((NetClientCount+1)/2.0) + 1
7667 else
7668 Need := Floor(NetClientCount/2.0) + 1;
7669 if gVoteCount >= Need then
7670 begin
7671 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_PASSED], [gVoteCommand]), True);
7672 MH_SEND_VoteEvent(NET_VE_PASSED, gVoteCommand);
7673 gVoteInProgress := False;
7674 gVotePassed := True;
7675 gVoteCmdTimer := gTime + 5000;
7676 gVoted := False;
7677 gVoteCount := 0;
7678 if NetClients <> nil then
7679 for I := Low(NetClients) to High(NetClients) do
7680 if NetClients[i].Used then
7681 NetClients[i].Voted := False;
7682 end;
7683 end;
7684 end;
7686 procedure g_Game_LoadMapList(FileName: string);
7687 var
7688 ListFile: TextFile;
7689 s: string;
7690 begin
7691 MapList := nil;
7692 MapIndex := -1;
7694 if not FileExists(FileName) then Exit;
7696 AssignFile(ListFile, FileName);
7697 Reset(ListFile);
7698 while not EOF(ListFile) do
7699 begin
7700 ReadLn(ListFile, s);
7702 s := Trim(s);
7703 if s = '' then Continue;
7705 SetLength(MapList, Length(MapList)+1);
7706 MapList[High(MapList)] := s;
7707 end;
7708 CloseFile(ListFile);
7709 end;
7711 procedure g_Game_SetDebugMode();
7712 begin
7713 gDebugMode := True;
7714 // ×èòû (äàæå â ñâîåé èãðå):
7715 gCheats := True;
7716 end;
7718 procedure g_Game_SetLoadingText(Text: String; Max: Integer; reWrite: Boolean);
7719 var
7720 i: Word;
7721 begin
7722 if Length(LoadingStat.Msgs) = 0 then
7723 Exit;
7725 with LoadingStat do
7726 begin
7727 if not reWrite then
7728 begin // Ïåðåõîäèì íà ñëåäóþùóþ ñòðîêó èëè ñêðîëëèðóåì:
7729 if NextMsg = Length(Msgs) then
7730 begin // scroll
7731 for i := 0 to High(Msgs)-1 do
7732 Msgs[i] := Msgs[i+1];
7733 end
7734 else
7735 Inc(NextMsg);
7736 end else
7737 if NextMsg = 0 then
7738 Inc(NextMsg);
7740 Msgs[NextMsg-1] := Text;
7741 CurValue := 0;
7742 MaxValue := Max;
7743 ShowCount := 0;
7744 PBarWasHere := false;
7745 end;
7747 g_ActiveWindow := nil;
7749 ProcessLoading(true);
7750 end;
7752 procedure g_Game_StepLoading(Value: Integer = -1);
7753 begin
7754 with LoadingStat do
7755 begin
7756 if Value = -1 then
7757 begin
7758 Inc(CurValue);
7759 Inc(ShowCount);
7760 end
7761 else
7762 CurValue := Value;
7763 if (ShowCount > LOADING_SHOW_STEP) or (Value > -1) then
7764 begin
7765 ShowCount := 0;
7766 ProcessLoading();
7767 end;
7768 end;
7769 end;
7771 procedure g_Game_ClearLoading();
7772 var
7773 len: Word;
7774 begin
7775 with LoadingStat do
7776 begin
7777 CurValue := 0;
7778 MaxValue := 0;
7779 ShowCount := 0;
7780 len := ((gScreenHeight div 3)*2 - 50) div LOADING_INTERLINE;
7781 if len < 1 then len := 1;
7782 SetLength(Msgs, len);
7783 for len := Low(Msgs) to High(Msgs) do
7784 Msgs[len] := '';
7785 NextMsg := 0;
7786 PBarWasHere := false;
7787 end;
7788 end;
7790 procedure Parse_Params(var pars: TParamStrValues);
7791 var
7792 i: Integer;
7793 s: String;
7794 begin
7795 SetLength(pars, 0);
7796 i := 1;
7797 while i <= ParamCount do
7798 begin
7799 s := ParamStr(i);
7800 if (s[1] = '-') and (Length(s) > 1) then
7801 begin
7802 if (s[2] = '-') and (Length(s) > 2) then
7803 begin // Îäèíî÷íûé ïàðàìåòð
7804 SetLength(pars, Length(pars) + 1);
7805 with pars[High(pars)] do
7806 begin
7807 Name := LowerCase(s);
7808 Value := '+';
7809 end;
7810 end
7811 else
7812 if (i < ParamCount) then
7813 begin // Ïàðàìåòð ñî çíà÷åíèåì
7814 Inc(i);
7815 SetLength(pars, Length(pars) + 1);
7816 with pars[High(pars)] do
7817 begin
7818 Name := LowerCase(s);
7819 Value := LowerCase(ParamStr(i));
7820 end;
7821 end;
7822 end;
7824 Inc(i);
7825 end;
7826 end;
7828 function Find_Param_Value(var pars: TParamStrValues; aName: String): String;
7829 var
7830 i: Integer;
7831 begin
7832 Result := '';
7833 for i := 0 to High(pars) do
7834 if pars[i].Name = aName then
7835 begin
7836 Result := pars[i].Value;
7837 Break;
7838 end;
7839 end;
7841 procedure g_Game_Process_Params();
7842 var
7843 pars: TParamStrValues;
7844 map: String;
7845 GMode, n: Byte;
7846 LimT, LimS: Integer;
7847 Opt: LongWord;
7848 Lives: Integer;
7849 s: String;
7850 Port: Integer;
7851 ip: String;
7852 F: TextFile;
7853 begin
7854 Parse_Params(pars);
7856 // Debug mode:
7857 s := Find_Param_Value(pars, '--debug');
7858 if (s <> '') then
7859 begin
7860 g_Game_SetDebugMode();
7861 s := Find_Param_Value(pars, '--netdump');
7862 if (s <> '') then
7863 NetDump := True;
7864 end;
7866 // Connect when game loads
7867 ip := Find_Param_Value(pars, '-connect');
7869 if ip <> '' then
7870 begin
7871 s := Find_Param_Value(pars, '-port');
7872 if (s = '') or not TryStrToInt(s, Port) then
7873 Port := 25666;
7875 s := Find_Param_Value(pars, '-pw');
7877 g_Game_StartClient(ip, Port, s);
7878 Exit;
7879 end;
7881 s := LowerCase(Find_Param_Value(pars, '-dbg-mainwad'));
7882 if (s <> '') then
7883 begin
7884 gDefaultMegawadStart := s;
7885 end;
7887 if (Find_Param_Value(pars, '--dbg-mainwad-restore') <> '') or
7888 (Find_Param_Value(pars, '--dbg-mainwad-default') <> '') then
7889 begin
7890 gDefaultMegawadStart := DF_Default_Megawad_Start;
7891 end;
7893 // Start map when game loads:
7894 map := LowerCase(Find_Param_Value(pars, '-map'));
7895 if isWadPath(map) then
7896 begin
7897 // Game mode:
7898 s := Find_Param_Value(pars, '-gm');
7899 GMode := g_Game_TextToMode(s);
7900 if GMode = GM_NONE then GMode := GM_DM;
7901 if GMode = GM_SINGLE then GMode := GM_COOP;
7903 // Time limit:
7904 s := Find_Param_Value(pars, '-limt');
7905 if (s = '') or (not TryStrToInt(s, LimT)) then
7906 LimT := 0;
7907 if LimT < 0 then
7908 LimT := 0;
7910 // Goal limit:
7911 s := Find_Param_Value(pars, '-lims');
7912 if (s = '') or (not TryStrToInt(s, LimS)) then
7913 LimS := 0;
7914 if LimS < 0 then
7915 LimS := 0;
7917 // Lives limit:
7918 s := Find_Param_Value(pars, '-lives');
7919 if (s = '') or (not TryStrToInt(s, Lives)) then
7920 Lives := 0;
7921 if Lives < 0 then
7922 Lives := 0;
7924 // Options:
7925 s := Find_Param_Value(pars, '-opt');
7926 if (s = '') then
7927 Opt := GAME_OPTION_ALLOWEXIT or GAME_OPTION_BOTVSPLAYER or GAME_OPTION_BOTVSMONSTER
7928 else
7929 Opt := StrToIntDef(s, 0);
7930 if Opt = 0 then
7931 Opt := GAME_OPTION_ALLOWEXIT or GAME_OPTION_BOTVSPLAYER or GAME_OPTION_BOTVSMONSTER;
7933 // Close after map:
7934 s := Find_Param_Value(pars, '--close');
7935 if (s <> '') then
7936 gMapOnce := True;
7938 // Override map to test:
7939 s := LowerCase(Find_Param_Value(pars, '-testmap'));
7940 if s <> '' then
7941 begin
7942 if e_IsValidResourceName(s) then
7943 e_FindResource(AllMapDirs, s);
7944 gTestMap := ExpandFileName(s);
7945 end;
7947 // Delete test map after play:
7948 s := Find_Param_Value(pars, '--testdelete');
7949 if (s <> '') then
7950 begin
7951 //gMapToDelete := MapsDir + map;
7952 e_WriteLog('"--testdelete" is deprecated, use --tempdelete.', TMsgType.Fatal);
7953 Halt(1);
7954 end;
7956 // Delete temporary WAD after play:
7957 s := Find_Param_Value(pars, '--tempdelete');
7958 if (s <> '') and (gTestMap <> '') then
7959 begin
7960 gMapToDelete := gTestMap;
7961 gTempDelete := True;
7962 end;
7964 // Number of players:
7965 s := Find_Param_Value(pars, '-pl');
7966 if (s = '') then
7967 n := DEFAULT_PLAYERS
7968 else
7969 n := StrToIntDef(s, DEFAULT_PLAYERS);
7971 // Start:
7972 s := Find_Param_Value(pars, '-port');
7973 if (s = '') or not TryStrToInt(s, Port) then
7974 g_Game_StartCustom(map, GMode, LimT, LimS, Lives, Opt, n)
7975 else
7976 g_Game_StartServer(map, GMode, LimT, LimS, Lives, Opt, n, 0, Port);
7977 end;
7979 // Execute script when game loads:
7980 s := Find_Param_Value(pars, '-exec');
7981 if s <> '' then
7982 begin
7983 // if not isWadPath(s) then
7984 // s := GameDir + '/' + s;
7986 {$I-}
7987 AssignFile(F, s);
7988 Reset(F);
7989 if IOResult <> 0 then
7990 begin
7991 e_WriteLog(Format(_lc[I_SIMPLE_ERROR], ['Failed to read file: ' + s]), TMsgType.Warning);
7992 g_Console_Add(Format(_lc[I_CONSOLE_ERROR_READ], [s]));
7993 CloseFile(F);
7994 Exit;
7995 end;
7996 e_WriteLog('Executing script: ' + s, TMsgType.Notify);
7997 g_Console_Add(Format(_lc[I_CONSOLE_EXEC], [s]));
7999 while not EOF(F) do
8000 begin
8001 ReadLn(F, s);
8002 if IOResult <> 0 then
8003 begin
8004 e_WriteLog(Format(_lc[I_SIMPLE_ERROR], ['Failed to read file: ' + s]), TMsgType.Warning);
8005 g_Console_Add(Format(_lc[I_CONSOLE_ERROR_READ], [s]));
8006 CloseFile(F);
8007 Exit;
8008 end;
8009 if Pos('#', s) <> 1 then // script comment
8010 g_Console_Process(s, True);
8011 end;
8013 CloseFile(F);
8014 {$I+}
8015 end;
8017 SetLength(pars, 0);
8018 end;
8020 begin
8021 conRegVar('pf_draw_frame', @g_profile_frame_draw, 'draw frame rendering profiles', 'render profiles');
8022 //conRegVar('pf_update_frame', @g_profile_frame_update, 'draw frame updating profiles', 'update profiles');
8023 conRegVar('pf_coldet', @g_profile_collision, 'draw collision detection profiles', 'coldet profiles');
8024 conRegVar('pf_los', @g_profile_los, 'draw monster LOS profiles', 'monster LOS profiles');
8026 conRegVar('r_sq_draw', @gdbg_map_use_accel_render, 'accelerated spatial queries in rendering', 'accelerated rendering');
8027 conRegVar('cd_sq_enabled', @gdbg_map_use_accel_coldet, 'accelerated spatial queries in map coldet', 'accelerated map coldet');
8028 conRegVar('mon_sq_enabled', @gmon_debug_use_sqaccel, 'accelerated spatial queries for monsters', 'accelerated monster coldet');
8029 conRegVar('wtrace_sq_enabled', @gwep_debug_fast_trace, 'accelerated spatial queries for weapon hitscan trace', 'accelerated weapon hitscan');
8031 conRegVar('pr_enabled', @gpart_dbg_enabled, 'enable/disable particles', 'particles');
8032 conRegVar('pr_phys_enabled', @gpart_dbg_phys_enabled, 'enable/disable particle physics', 'particle physics');
8034 conRegVar('los_enabled', @gmon_dbg_los_enabled, 'enable/disable monster LOS calculations', 'monster LOS', true);
8035 conRegVar('mon_think', @gmon_debug_think, 'enable/disable monster thinking', 'monster thinking', true);
8037 {$IFDEF ENABLE_HOLMES}
8038 conRegVar('dbg_holmes', @g_holmes_enabled, 'enable/disable Holmes', 'Holmes', true);
8039 {$ENDIF}
8041 conRegVar('dbg_ignore_level_bounds', @g_dbg_ignore_bounds, 'ignore level bounds', '', false);
8043 conRegVar('r_scale', @g_dbg_scale, 0.01, 100.0, 'render scale', '', false);
8045 conRegVar('light_enabled', @gwin_k8_enable_light_experiments, 'enable/disable dynamic lighting', 'lighting');
8046 conRegVar('light_player_halo', @g_playerLight, 'enable/disable player halo', 'player light halo');
8048 conRegVar('r_smallmap_align_h', @r_smallmap_h, 'halign: 0: left; 1: center; 2: right', 'horizontal aligning of small maps');
8049 conRegVar('r_smallmap_align_v', @r_smallmap_v, 'valign: 0: top; 1: center; 2: bottom', 'vertial aligning of small maps');
8051 conRegVar('r_showfps', @gShowFPS, 'draw fps counter', 'draw fps counter');
8052 conRegVar('r_showtime', @gShowTime, 'show game time', 'show game time');
8053 end.