DEADSOFTWARE

engine: yet another attempt to fix map downloading (YAATFMD); "no time to loose!"
[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(ExtractFileName(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 e_LogWritefln('using downloaded client map wad [%s] for [%s]', [gWAD, NewWAD], TMsgType.Notify);
5086 NewWAD := gWAD;
5088 g_Game_LoadWAD(NewWAD);
5089 result := NewWAD;
5092 if LowerCase(NewWAD) = LowerCase(gGameSettings.WAD) then Exit;
5093 gWAD := g_Res_SearchSameWAD(MapsDir, ExtractFileName(NewWAD), WHash);
5094 if gWAD = '' then
5095 begin
5096 g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
5097 gWAD := g_Res_DownloadMapWAD(ExtractFileName(NewWAD), WHash);
5098 if gWAD = '' then
5099 begin
5100 g_Game_Free();
5101 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_WAD], [ExtractFileName(NewWAD)]));
5102 Exit;
5103 end;
5104 end;
5105 NewWAD := ExtractRelativePath(MapsDir, gWAD);
5106 g_Game_LoadWAD(NewWAD);
5108 end;
5110 procedure g_Game_RestartRound(NoMapRestart: Boolean = False);
5111 var
5112 i, n, nb, nr: Integer;
5114 function monRespawn (mon: TMonster): Boolean;
5115 begin
5116 result := false; // don't stop
5117 if not mon.FNoRespawn then mon.Respawn();
5118 end;
5120 begin
5121 if not g_Game_IsServer then Exit;
5122 if gLMSRespawn = LMS_RESPAWN_NONE then Exit;
5123 gLMSRespawn := LMS_RESPAWN_NONE;
5124 gLMSRespawnTime := 0;
5125 MessageTime := 0;
5127 if (gGameSettings.GameMode = GM_COOP) and not NoMapRestart then
5128 begin
5129 gMissionFailed := True;
5130 g_Game_RestartLevel;
5131 Exit;
5132 end;
5134 n := 0; nb := 0; nr := 0;
5135 for i := Low(gPlayers) to High(gPlayers) do
5136 if (gPlayers[i] <> nil) and
5137 ((not gPlayers[i].FSpectator) or gPlayers[i].FWantsInGame or
5138 (gPlayers[i] is TBot)) then
5139 begin
5140 Inc(n);
5141 if gPlayers[i].Team = TEAM_RED then Inc(nr)
5142 else if gPlayers[i].Team = TEAM_BLUE then Inc(nb)
5143 end;
5145 if (n < 2) or ((gGameSettings.GameMode = GM_TDM) and ((nr = 0) or (nb = 0))) then
5146 begin
5147 // wait a second until the fuckers finally decide to join
5148 gLMSRespawn := LMS_RESPAWN_WARMUP;
5149 gLMSRespawnTime := gTime + 1000;
5150 gLMSSoftSpawn := NoMapRestart;
5151 Exit;
5152 end;
5154 g_Player_RemoveAllCorpses;
5155 g_Game_Message(_lc[I_MESSAGE_LMS_START], 144);
5156 if g_Game_IsNet then
5157 MH_SEND_GameEvent(NET_EV_LMS_START);
5159 for i := Low(gPlayers) to High(gPlayers) do
5160 begin
5161 if gPlayers[i] = nil then continue;
5162 if gPlayers[i] is TBot then gPlayers[i].FWantsInGame := True;
5163 // don't touch normal spectators
5164 if gPlayers[i].FSpectator and not gPlayers[i].FWantsInGame then
5165 begin
5166 gPlayers[i].FNoRespawn := True;
5167 gPlayers[i].Lives := 0;
5168 if g_Game_IsNet then
5169 MH_SEND_PlayerStats(gPlayers[I].UID);
5170 continue;
5171 end;
5172 gPlayers[i].FNoRespawn := False;
5173 gPlayers[i].Lives := gGameSettings.MaxLives;
5174 gPlayers[i].Respawn(False, True);
5175 if gGameSettings.GameMode = GM_COOP then
5176 begin
5177 gPlayers[i].Frags := 0;
5178 gPlayers[i].RecallState;
5179 end;
5180 if (gPlayer1 = nil) and (gLMSPID1 > 0) then
5181 gPlayer1 := g_Player_Get(gLMSPID1);
5182 if (gPlayer2 = nil) and (gLMSPID2 > 0) then
5183 gPlayer2 := g_Player_Get(gLMSPID2);
5184 end;
5186 g_Items_RestartRound();
5189 g_Mons_ForEach(monRespawn);
5191 gLMSSoftSpawn := False;
5192 end;
5194 function g_Game_GetFirstMap(WAD: String): String;
5195 begin
5196 Result := '';
5198 MapList := g_Map_GetMapsList(WAD);
5199 if MapList = nil then
5200 Exit;
5202 SortSArray(MapList);
5203 Result := MapList[Low(MapList)];
5205 if not g_Map_Exist(WAD + ':\' + Result) then
5206 Result := '';
5208 MapList := nil;
5209 end;
5211 function g_Game_GetNextMap(): String;
5212 var
5213 I: Integer;
5214 Map: string;
5215 begin
5216 Result := '';
5218 MapList := g_Map_GetMapsList(gGameSettings.WAD);
5219 if MapList = nil then
5220 Exit;
5222 Map := g_ExtractFileName(gMapInfo.Map);
5224 SortSArray(MapList);
5225 MapIndex := -255;
5226 for I := Low(MapList) to High(MapList) do
5227 if Map = MapList[I] then
5228 begin
5229 MapIndex := I;
5230 Break;
5231 end;
5233 if MapIndex <> -255 then
5234 begin
5235 if MapIndex = High(MapList) then
5236 Result := MapList[Low(MapList)]
5237 else
5238 Result := MapList[MapIndex + 1];
5240 if not g_Map_Exist(gGameSettings.WAD + ':\' + Result) then Result := Map;
5241 end;
5243 MapList := nil;
5244 end;
5246 procedure g_Game_NextLevel();
5247 begin
5248 if gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF, GM_COOP] then
5249 gExit := EXIT_ENDLEVELCUSTOM
5250 else
5251 begin
5252 gExit := EXIT_ENDLEVELSINGLE;
5253 Exit;
5254 end;
5256 if gNextMap <> '' then Exit;
5257 gNextMap := g_Game_GetNextMap();
5258 end;
5260 function g_Game_IsTestMap(): Boolean;
5261 begin
5262 result := StrEquCI1251(TEST_MAP_NAME, g_ExtractFileName(gMapInfo.Map));
5263 end;
5265 procedure g_Game_DeleteTestMap();
5266 var
5267 a: Integer;
5268 //MapName: AnsiString;
5269 WadName: string;
5271 WAD: TWADFile;
5272 MapList: SSArray;
5273 time: Integer;
5275 begin
5276 a := Pos('.wad:\', toLowerCase1251(gMapToDelete));
5277 if (a = 0) then a := Pos('.wad:/', toLowerCase1251(gMapToDelete));
5278 if (a = 0) then exit;
5280 // Âûäåëÿåì èìÿ wad-ôàéëà è èìÿ êàðòû
5281 WadName := Copy(gMapToDelete, 1, a+3);
5282 Delete(gMapToDelete, 1, a+5);
5283 gMapToDelete := UpperCase(gMapToDelete);
5284 //MapName := '';
5285 //CopyMemory(@MapName[0], @gMapToDelete[1], Min(16, Length(gMapToDelete)));
5288 // Èìÿ êàðòû íå ñòàíäàðòíîå òåñòîâîå:
5289 if MapName <> TEST_MAP_NAME then
5290 Exit;
5292 if not gTempDelete then
5293 begin
5294 time := g_GetFileTime(WadName);
5295 WAD := TWADFile.Create();
5297 // ×èòàåì Wad-ôàéë:
5298 if not WAD.ReadFile(WadName) then
5299 begin // Íåò òàêîãî WAD-ôàéëà
5300 WAD.Free();
5301 Exit;
5302 end;
5304 // Ñîñòàâëÿåì ñïèñîê êàðò è èùåì íóæíóþ:
5305 WAD.CreateImage();
5306 MapList := WAD.GetResourcesList('');
5308 if MapList <> nil then
5309 for a := 0 to High(MapList) do
5310 if MapList[a] = MapName then
5311 begin
5312 // Óäàëÿåì è ñîõðàíÿåì:
5313 WAD.RemoveResource('', MapName);
5314 WAD.SaveTo(WadName);
5315 Break;
5316 end;
5318 WAD.Free();
5319 g_SetFileTime(WadName, time);
5320 end else
5322 if gTempDelete then DeleteFile(WadName);
5323 end;
5325 procedure GameCVars(P: SSArray);
5326 var
5327 a, b: Integer;
5328 stat: TPlayerStatArray;
5329 cmd, s: string;
5330 config: TConfig;
5331 begin
5332 stat := nil;
5333 cmd := LowerCase(P[0]);
5334 if (cmd = 'g_friendlyfire') and not g_Game_IsClient then
5335 begin
5336 with gGameSettings do
5337 begin
5338 if (Length(P) > 1) and
5339 ((P[1] = '1') or (P[1] = '0')) then
5340 begin
5341 if (P[1][1] = '1') then
5342 Options := Options or GAME_OPTION_TEAMDAMAGE
5343 else
5344 Options := Options and (not GAME_OPTION_TEAMDAMAGE);
5345 end;
5347 if (LongBool(Options and GAME_OPTION_TEAMDAMAGE)) then
5348 g_Console_Add(_lc[I_MSG_FRIENDLY_FIRE_ON])
5349 else
5350 g_Console_Add(_lc[I_MSG_FRIENDLY_FIRE_OFF]);
5352 if g_Game_IsNet then MH_SEND_GameSettings;
5353 end;
5354 end
5355 else if (cmd = 'g_weaponstay') and not g_Game_IsClient then
5356 begin
5357 with gGameSettings do
5358 begin
5359 if (Length(P) > 1) and
5360 ((P[1] = '1') or (P[1] = '0')) then
5361 begin
5362 if (P[1][1] = '1') then
5363 Options := Options or GAME_OPTION_WEAPONSTAY
5364 else
5365 Options := Options and (not GAME_OPTION_WEAPONSTAY);
5366 end;
5368 if (LongBool(Options and GAME_OPTION_WEAPONSTAY)) then
5369 g_Console_Add(_lc[I_MSG_WEAPONSTAY_ON])
5370 else
5371 g_Console_Add(_lc[I_MSG_WEAPONSTAY_OFF]);
5373 if g_Game_IsNet then MH_SEND_GameSettings;
5374 end;
5375 end
5376 else if cmd = 'g_gamemode' then
5377 begin
5378 a := g_Game_TextToMode(P[1]);
5379 if a = GM_SINGLE then a := GM_COOP;
5380 if (Length(P) > 1) and (a <> GM_NONE) and (not g_Game_IsClient) then
5381 begin
5382 gSwitchGameMode := a;
5383 if (gGameOn and (gGameSettings.GameMode = GM_SINGLE)) or
5384 (gState = STATE_INTERSINGLE) then
5385 gSwitchGameMode := GM_SINGLE;
5386 if not gGameOn then
5387 gGameSettings.GameMode := gSwitchGameMode;
5388 end;
5389 if gSwitchGameMode = gGameSettings.GameMode then
5390 g_Console_Add(Format(_lc[I_MSG_GAMEMODE_CURRENT],
5391 [g_Game_ModeToText(gGameSettings.GameMode)]))
5392 else
5393 g_Console_Add(Format(_lc[I_MSG_GAMEMODE_CHANGE],
5394 [g_Game_ModeToText(gGameSettings.GameMode),
5395 g_Game_ModeToText(gSwitchGameMode)]));
5396 end
5397 else if (cmd = 'g_allow_exit') and not g_Game_IsClient then
5398 begin
5399 with gGameSettings do
5400 begin
5401 if (Length(P) > 1) and
5402 ((P[1] = '1') or (P[1] = '0')) then
5403 begin
5404 if (P[1][1] = '1') then
5405 Options := Options or GAME_OPTION_ALLOWEXIT
5406 else
5407 Options := Options and (not GAME_OPTION_ALLOWEXIT);
5408 end;
5410 if (LongBool(Options and GAME_OPTION_ALLOWEXIT)) then
5411 g_Console_Add(_lc[I_MSG_ALLOWEXIT_ON])
5412 else
5413 g_Console_Add(_lc[I_MSG_ALLOWEXIT_OFF]);
5414 g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
5416 if g_Game_IsNet then MH_SEND_GameSettings;
5417 end;
5418 end
5419 else if (cmd = 'g_allow_monsters') and not g_Game_IsClient then
5420 begin
5421 with gGameSettings do
5422 begin
5423 if (Length(P) > 1) and
5424 ((P[1] = '1') or (P[1] = '0')) then
5425 begin
5426 if (P[1][1] = '1') then
5427 Options := Options or GAME_OPTION_MONSTERS
5428 else
5429 Options := Options and (not GAME_OPTION_MONSTERS);
5430 end;
5432 if (LongBool(Options and GAME_OPTION_MONSTERS)) then
5433 g_Console_Add(_lc[I_MSG_ALLOWMON_ON])
5434 else
5435 g_Console_Add(_lc[I_MSG_ALLOWMON_OFF]);
5436 g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
5438 if g_Game_IsNet then MH_SEND_GameSettings;
5439 end;
5440 end
5441 else if (cmd = 'g_bot_vsplayers') and not g_Game_IsClient then
5442 begin
5443 with gGameSettings do
5444 begin
5445 if (Length(P) > 1) and
5446 ((P[1] = '1') or (P[1] = '0')) then
5447 begin
5448 if (P[1][1] = '1') then
5449 Options := Options or GAME_OPTION_BOTVSPLAYER
5450 else
5451 Options := Options and (not GAME_OPTION_BOTVSPLAYER);
5452 end;
5454 if (LongBool(Options and GAME_OPTION_BOTVSPLAYER)) then
5455 g_Console_Add(_lc[I_MSG_BOTSVSPLAYERS_ON])
5456 else
5457 g_Console_Add(_lc[I_MSG_BOTSVSPLAYERS_OFF]);
5459 if g_Game_IsNet then MH_SEND_GameSettings;
5460 end;
5461 end
5462 else if (cmd = 'g_bot_vsmonsters') and not g_Game_IsClient then
5463 begin
5464 with gGameSettings do
5465 begin
5466 if (Length(P) > 1) and
5467 ((P[1] = '1') or (P[1] = '0')) then
5468 begin
5469 if (P[1][1] = '1') then
5470 Options := Options or GAME_OPTION_BOTVSMONSTER
5471 else
5472 Options := Options and (not GAME_OPTION_BOTVSMONSTER);
5473 end;
5475 if (LongBool(Options and GAME_OPTION_BOTVSMONSTER)) then
5476 g_Console_Add(_lc[I_MSG_BOTSVSMONSTERS_ON])
5477 else
5478 g_Console_Add(_lc[I_MSG_BOTSVSMONSTERS_OFF]);
5480 if g_Game_IsNet then MH_SEND_GameSettings;
5481 end;
5482 end
5483 else if (cmd = 'g_warmuptime') and not g_Game_IsClient then
5484 begin
5485 if Length(P) > 1 then
5486 begin
5487 if StrToIntDef(P[1], gGameSettings.WarmupTime) = 0 then
5488 gGameSettings.WarmupTime := 30
5489 else
5490 gGameSettings.WarmupTime := StrToIntDef(P[1], gGameSettings.WarmupTime);
5491 end;
5493 g_Console_Add(Format(_lc[I_MSG_WARMUP],
5494 [gGameSettings.WarmupTime]));
5495 g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
5496 end
5497 else if cmd = 'net_interp' then
5498 begin
5499 if (Length(P) > 1) then
5500 NetInterpLevel := StrToIntDef(P[1], NetInterpLevel);
5501 g_Console_Add('net_interp = ' + IntToStr(NetInterpLevel));
5502 s := e_GetWriteableDir(ConfigDirs);
5503 if s <> '' then
5504 begin
5505 config := TConfig.CreateFile(s + '/' + CONFIG_FILENAME);
5506 config.WriteInt('Client', 'InterpolationSteps', NetInterpLevel);
5507 config.SaveFile(s + '/' + CONFIG_FILENAME);
5508 config.Free
5509 end
5510 end
5511 else if cmd = 'net_forceplayerupdate' then
5512 begin
5513 if (Length(P) > 1) and ((P[1] = '1') or (P[1] = '0')) then
5514 NetForcePlayerUpdate := (P[1][1] = '1');
5516 if NetForcePlayerUpdate then
5517 g_Console_Add('net_forceplayerupdate = 1')
5518 else
5519 g_Console_Add('net_forceplayerupdate = 0');
5521 s := e_GetWriteableDir(ConfigDirs);
5522 if s <> '' then
5523 begin
5524 config := TConfig.CreateFile(s + '/' + CONFIG_FILENAME);
5525 config.WriteBool('Client', 'ForcePlayerUpdate', NetForcePlayerUpdate);
5526 config.SaveFile(s + '/' + CONFIG_FILENAME);
5527 config.Free
5528 end
5529 end
5530 else if cmd = 'net_predictself' then
5531 begin
5532 if (Length(P) > 1) and
5533 ((P[1] = '1') or (P[1] = '0')) then
5534 NetPredictSelf := (P[1][1] = '1');
5536 if NetPredictSelf then
5537 g_Console_Add('net_predictself = 1')
5538 else
5539 g_Console_Add('net_predictself = 0');
5541 s := e_GetWriteableDir(ConfigDirs);
5542 if s <> '' then
5543 begin
5544 config := TConfig.CreateFile(s + '/' + CONFIG_FILENAME);
5545 config.WriteBool('Client', 'PredictSelf', NetPredictSelf);
5546 config.SaveFile(s + '/' + CONFIG_FILENAME);
5547 config.Free
5548 end
5549 end
5550 else if cmd = 'sv_name' then
5551 begin
5552 if (Length(P) > 1) and (Length(P[1]) > 0) then
5553 begin
5554 NetServerName := P[1];
5555 if Length(NetServerName) > 64 then
5556 SetLength(NetServerName, 64);
5557 g_Net_Slist_ServerRenamed();
5558 end;
5560 g_Console_Add(cmd + ' = "' + NetServerName + '"');
5561 end
5562 else if cmd = 'sv_passwd' then
5563 begin
5564 if (Length(P) > 1) and (Length(P[1]) > 0) then
5565 begin
5566 NetPassword := P[1];
5567 if Length(NetPassword) > 24 then
5568 SetLength(NetPassword, 24);
5569 g_Net_Slist_ServerRenamed();
5570 end;
5572 g_Console_Add(cmd + ' = "' + AnsiLowerCase(NetPassword) + '"');
5573 end
5574 else if cmd = 'sv_maxplrs' then
5575 begin
5576 if (Length(P) > 1) then
5577 begin
5578 NetMaxClients := Min(Max(StrToIntDef(P[1], NetMaxClients), 1), NET_MAXCLIENTS);
5579 if g_Game_IsServer and g_Game_IsNet then
5580 begin
5581 b := 0;
5582 for a := 0 to High(NetClients) do
5583 begin
5584 if NetClients[a].Used then
5585 begin
5586 Inc(b);
5587 if b > NetMaxClients then
5588 begin
5589 s := g_Player_Get(NetClients[a].Player).Name;
5590 enet_peer_disconnect(NetClients[a].Peer, NET_DISC_FULL);
5591 g_Console_Add(Format(_lc[I_PLAYER_KICK], [s]));
5592 MH_SEND_GameEvent(NET_EV_PLAYER_KICK, 0, s);
5593 end;
5594 end;
5595 end;
5596 g_Net_Slist_ServerRenamed();
5597 end;
5598 end;
5600 g_Console_Add(cmd + ' = ' + IntToStr(NetMaxClients));
5601 end
5602 else if cmd = 'sv_public' then
5603 begin
5604 if (Length(P) > 1) then
5605 begin
5606 NetUseMaster := StrToIntDef(P[1], Byte(NetUseMaster)) > 0;
5607 if NetUseMaster then g_Net_Slist_Public() else g_Net_Slist_Private();
5608 end;
5610 g_Console_Add(cmd + ' = ' + IntToStr(Byte(NetUseMaster)));
5611 end
5612 else if cmd = 'sv_intertime' then
5613 begin
5614 if (Length(P) > 1) then
5615 gDefInterTime := Min(Max(StrToIntDef(P[1], gDefInterTime), -1), 120);
5617 g_Console_Add(cmd + ' = ' + IntToStr(gDefInterTime));
5618 end
5619 else if cmd = 'p1_name' then
5620 begin
5621 if (Length(P) > 1) and gGameOn then
5622 begin
5623 if g_Game_IsClient then
5624 begin
5625 gPlayer1Settings.Name := b_Text_Unformat(P[1]);
5626 MC_SEND_PlayerSettings;
5627 end
5628 else
5629 if gPlayer1 <> nil then
5630 begin
5631 gPlayer1.Name := b_Text_Unformat(P[1]);
5632 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer1.UID);
5633 end
5634 else
5635 gPlayer1Settings.Name := b_Text_Unformat(P[1]);
5636 end;
5637 end
5638 else if cmd = 'p2_name' then
5639 begin
5640 if (Length(P) > 1) and gGameOn then
5641 begin
5642 if g_Game_IsClient then
5643 begin
5644 gPlayer2Settings.Name := b_Text_Unformat(P[1]);
5645 MC_SEND_PlayerSettings;
5646 end
5647 else
5648 if gPlayer2 <> nil then
5649 begin
5650 gPlayer2.Name := b_Text_Unformat(P[1]);
5651 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer2.UID);
5652 end
5653 else
5654 gPlayer2Settings.Name := b_Text_Unformat(P[1]);
5655 end;
5656 end
5657 else if cmd = 'p1_color' then
5658 begin
5659 if Length(P) > 3 then
5660 if g_Game_IsClient then
5661 begin
5662 gPlayer1Settings.Color := _RGB(EnsureRange(StrToIntDef(P[1], 0), 0, 255),
5663 EnsureRange(StrToIntDef(P[2], 0), 0, 255),
5664 EnsureRange(StrToIntDef(P[3], 0), 0, 255));
5665 MC_SEND_PlayerSettings;
5666 end
5667 else
5668 if gPlayer1 <> nil then
5669 begin
5670 gPlayer1.Model.SetColor(EnsureRange(StrToIntDef(P[1], 0), 0, 255),
5671 EnsureRange(StrToIntDef(P[2], 0), 0, 255),
5672 EnsureRange(StrToIntDef(P[3], 0), 0, 255));
5673 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer1.UID);
5674 end
5675 else
5676 gPlayer1Settings.Color := _RGB(EnsureRange(StrToIntDef(P[1], 0), 0, 255),
5677 EnsureRange(StrToIntDef(P[2], 0), 0, 255),
5678 EnsureRange(StrToIntDef(P[3], 0), 0, 255));
5679 end
5680 else if (cmd = 'p2_color') and not g_Game_IsNet then
5681 begin
5682 if Length(P) > 3 then
5683 if g_Game_IsClient then
5684 begin
5685 gPlayer2Settings.Color := _RGB(EnsureRange(StrToIntDef(P[1], 0), 0, 255),
5686 EnsureRange(StrToIntDef(P[2], 0), 0, 255),
5687 EnsureRange(StrToIntDef(P[3], 0), 0, 255));
5688 MC_SEND_PlayerSettings;
5689 end
5690 else
5691 if gPlayer2 <> nil then
5692 begin
5693 gPlayer2.Model.SetColor(EnsureRange(StrToIntDef(P[1], 0), 0, 255),
5694 EnsureRange(StrToIntDef(P[2], 0), 0, 255),
5695 EnsureRange(StrToIntDef(P[3], 0), 0, 255));
5696 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer2.UID);
5697 end
5698 else
5699 gPlayer2Settings.Color := _RGB(EnsureRange(StrToIntDef(P[1], 0), 0, 255),
5700 EnsureRange(StrToIntDef(P[2], 0), 0, 255),
5701 EnsureRange(StrToIntDef(P[3], 0), 0, 255));
5702 end
5703 else if gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT] then
5704 begin
5705 if cmd = 'r_showscore' then
5706 begin
5707 if (Length(P) > 1) and
5708 ((P[1] = '1') or (P[1] = '0')) then
5709 gShowGoals := (P[1][1] = '1');
5711 if gShowGoals then
5712 g_Console_Add(_lc[I_MSG_SCORE_ON])
5713 else
5714 g_Console_Add(_lc[I_MSG_SCORE_OFF]);
5715 end
5716 else if cmd = 'r_showstat' then
5717 begin
5718 if (Length(P) > 1) and
5719 ((P[1] = '1') or (P[1] = '0')) then
5720 gShowStat := (P[1][1] = '1');
5722 if gShowStat then
5723 g_Console_Add(_lc[I_MSG_STATS_ON])
5724 else
5725 g_Console_Add(_lc[I_MSG_STATS_OFF]);
5726 end
5727 else if cmd = 'r_showkillmsg' then
5728 begin
5729 if (Length(P) > 1) and
5730 ((P[1] = '1') or (P[1] = '0')) then
5731 gShowKillMsg := (P[1][1] = '1');
5733 if gShowKillMsg then
5734 g_Console_Add(_lc[I_MSG_KILL_MSGS_ON])
5735 else
5736 g_Console_Add(_lc[I_MSG_KILL_MSGS_OFF]);
5737 end
5738 else if cmd = 'r_showlives' then
5739 begin
5740 if (Length(P) > 1) and
5741 ((P[1] = '1') or (P[1] = '0')) then
5742 gShowLives := (P[1][1] = '1');
5744 if gShowLives then
5745 g_Console_Add(_lc[I_MSG_LIVES_ON])
5746 else
5747 g_Console_Add(_lc[I_MSG_LIVES_OFF]);
5748 end
5749 else if cmd = 'r_showspect' then
5750 begin
5751 if (Length(P) > 1) and
5752 ((P[1] = '1') or (P[1] = '0')) then
5753 gSpectHUD := (P[1][1] = '1');
5755 if gSpectHUD then
5756 g_Console_Add(_lc[I_MSG_SPECT_HUD_ON])
5757 else
5758 g_Console_Add(_lc[I_MSG_SPECT_HUD_OFF]);
5759 end
5760 else if cmd = 'r_showping' then
5761 begin
5762 if (Length(P) > 1) and
5763 ((P[1] = '1') or (P[1] = '0')) then
5764 gShowPing := (P[1][1] = '1');
5766 if gShowPing then
5767 g_Console_Add(_lc[I_MSG_PING_ON])
5768 else
5769 g_Console_Add(_lc[I_MSG_PING_OFF]);
5770 end
5771 else if (cmd = 'g_scorelimit') and not g_Game_IsClient then
5772 begin
5773 if Length(P) > 1 then
5774 begin
5775 if StrToIntDef(P[1], gGameSettings.GoalLimit) = 0 then
5776 gGameSettings.GoalLimit := 0
5777 else
5778 begin
5779 b := 0;
5781 if gGameSettings.GameMode = GM_DM then
5782 begin // DM
5783 stat := g_Player_GetStats();
5784 if stat <> nil then
5785 for a := 0 to High(stat) do
5786 if stat[a].Frags > b then
5787 b := stat[a].Frags;
5788 end
5789 else // TDM/CTF
5790 b := Max(gTeamStat[TEAM_RED].Goals, gTeamStat[TEAM_BLUE].Goals);
5792 gGameSettings.GoalLimit := Max(StrToIntDef(P[1], gGameSettings.GoalLimit), b);
5793 end;
5795 if g_Game_IsNet then MH_SEND_GameSettings;
5796 end;
5798 g_Console_Add(Format(_lc[I_MSG_SCORE_LIMIT], [gGameSettings.GoalLimit]));
5799 end
5800 else if (cmd = 'g_timelimit') and not g_Game_IsClient then
5801 begin
5802 if (Length(P) > 1) and (StrToIntDef(P[1], -1) >= 0) then
5803 gGameSettings.TimeLimit := StrToIntDef(P[1], -1);
5805 g_Console_Add(Format(_lc[I_MSG_TIME_LIMIT],
5806 [gGameSettings.TimeLimit div 3600,
5807 (gGameSettings.TimeLimit div 60) mod 60,
5808 gGameSettings.TimeLimit mod 60]));
5809 if g_Game_IsNet then MH_SEND_GameSettings;
5810 end
5811 else if (cmd = 'g_maxlives') and not g_Game_IsClient then
5812 begin
5813 if Length(P) > 1 then
5814 begin
5815 if StrToIntDef(P[1], gGameSettings.MaxLives) = 0 then
5816 gGameSettings.MaxLives := 0
5817 else
5818 begin
5819 b := 0;
5820 stat := g_Player_GetStats();
5821 if stat <> nil then
5822 for a := 0 to High(stat) do
5823 if stat[a].Lives > b then
5824 b := stat[a].Lives;
5825 gGameSettings.MaxLives :=
5826 Max(StrToIntDef(P[1], gGameSettings.MaxLives), b);
5827 end;
5828 end;
5830 g_Console_Add(Format(_lc[I_MSG_LIVES],
5831 [gGameSettings.MaxLives]));
5832 if g_Game_IsNet then MH_SEND_GameSettings;
5833 end;
5834 end;
5835 end;
5837 procedure PrintHeapStats();
5838 var
5839 hs: TFPCHeapStatus;
5840 begin
5841 hs := GetFPCHeapStatus();
5842 e_LogWriteLn ('v===== heap status =====v');
5843 e_LogWriteFln('max heap size = %d k', [hs.MaxHeapSize div 1024]);
5844 e_LogWriteFln('max heap used = %d k', [hs.MaxHeapUsed div 1024]);
5845 e_LogWriteFln('cur heap size = %d k', [hs.CurrHeapSize div 1024]);
5846 e_LogWriteFln('cur heap used = %d k', [hs.CurrHeapUsed div 1024]);
5847 e_LogWriteFln('cur heap free = %d k', [hs.CurrHeapFree div 1024]);
5848 e_LogWriteLn ('^=======================^');
5849 end;
5851 procedure DebugCommands(P: SSArray);
5852 var
5853 a, b: Integer;
5854 cmd: string;
5855 //pt: TDFPoint;
5856 mon: TMonster;
5857 begin
5858 // Êîìàíäû îòëàäî÷íîãî ðåæèìà:
5859 if {gDebugMode}conIsCheatsEnabled then
5860 begin
5861 cmd := LowerCase(P[0]);
5862 if cmd = 'd_window' then
5863 begin
5864 g_Console_Add(Format('gWinPosX = %d, gWinPosY %d', [gWinPosX, gWinPosY]));
5865 g_Console_Add(Format('gWinRealPosX = %d, gWinRealPosY %d', [gWinRealPosX, gWinRealPosY]));
5866 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth, gScreenHeight]));
5867 g_Console_Add(Format('gWinSizeX = %d, gWinSizeY = %d', [gWinSizeX, gWinSizeY]));
5868 g_Console_Add(Format('Frame X = %d, Y = %d, Caption Y = %d', [gWinFrameX, gWinFrameY, gWinCaption]));
5869 end
5870 else if cmd = 'd_sounds' then
5871 begin
5872 if (Length(P) > 1) and
5873 ((P[1] = '1') or (P[1] = '0')) then
5874 g_Debug_Sounds := (P[1][1] = '1');
5876 g_Console_Add(Format('d_sounds is %d', [Byte(g_Debug_Sounds)]));
5877 end
5878 else if cmd = 'd_frames' then
5879 begin
5880 if (Length(P) > 1) and
5881 ((P[1] = '1') or (P[1] = '0')) then
5882 g_Debug_Frames := (P[1][1] = '1');
5884 g_Console_Add(Format('d_frames is %d', [Byte(g_Debug_Frames)]));
5885 end
5886 else if cmd = 'd_winmsg' then
5887 begin
5888 if (Length(P) > 1) and
5889 ((P[1] = '1') or (P[1] = '0')) then
5890 g_Debug_WinMsgs := (P[1][1] = '1');
5892 g_Console_Add(Format('d_winmsg is %d', [Byte(g_Debug_WinMsgs)]));
5893 end
5894 else if (cmd = 'd_monoff') and not g_Game_IsNet then
5895 begin
5896 if (Length(P) > 1) and
5897 ((P[1] = '1') or (P[1] = '0')) then
5898 g_Debug_MonsterOff := (P[1][1] = '1');
5900 g_Console_Add(Format('d_monoff is %d', [Byte(g_debug_MonsterOff)]));
5901 end
5902 else if (cmd = 'd_botoff') and not g_Game_IsNet then
5903 begin
5904 if Length(P) > 1 then
5905 case P[1][1] of
5906 '0': g_debug_BotAIOff := 0;
5907 '1': g_debug_BotAIOff := 1;
5908 '2': g_debug_BotAIOff := 2;
5909 '3': g_debug_BotAIOff := 3;
5910 end;
5912 g_Console_Add(Format('d_botoff is %d', [g_debug_BotAIOff]));
5913 end
5914 else if cmd = 'd_monster' then
5915 begin
5916 if gGameOn and (gPlayer1 <> nil) and (gPlayer1.alive) and (not g_Game_IsNet) then
5917 if Length(P) < 2 then
5918 begin
5919 g_Console_Add(cmd + ' [ID | Name] [behaviour]');
5920 g_Console_Add('ID | Name');
5921 for b := MONSTER_DEMON to MONSTER_MAN do
5922 g_Console_Add(Format('%2d | %s', [b, g_Mons_NameByTypeId(b)]));
5923 conwriteln('behav. num'#10'normal 0'#10'killer 1'#10'maniac 2'#10'insane 3'#10'cannibal 4'#10'good 5');
5924 end else
5925 begin
5926 a := StrToIntDef(P[1], 0);
5927 if (a < MONSTER_DEMON) or (a > MONSTER_MAN) then
5928 a := g_Mons_TypeIdByName(P[1]);
5930 if (a < MONSTER_DEMON) or (a > MONSTER_MAN) then
5931 g_Console_Add(Format(_lc[I_MSG_NO_MONSTER], [P[1]]))
5932 else
5933 begin
5934 with gPlayer1.Obj do
5935 begin
5936 mon := g_Monsters_Create(a,
5937 X + Rect.X + (Rect.Width div 2),
5938 Y + Rect.Y + Rect.Height,
5939 gPlayer1.Direction, True);
5940 end;
5941 if (Length(P) > 2) and (mon <> nil) then
5942 begin
5943 if (CompareText(P[2], 'normal') = 0) then mon.MonsterBehaviour := BH_NORMAL
5944 else if (CompareText(P[2], 'killer') = 0) then mon.MonsterBehaviour := BH_KILLER
5945 else if (CompareText(P[2], 'maniac') = 0) then mon.MonsterBehaviour := BH_MANIAC
5946 else if (CompareText(P[2], 'insane') = 0) then mon.MonsterBehaviour := BH_INSANE
5947 else if (CompareText(P[2], 'cannibal') = 0) then mon.MonsterBehaviour := BH_CANNIBAL
5948 else if (CompareText(P[2], 'good') = 0) then mon.MonsterBehaviour := BH_GOOD
5949 else if (CompareText(P[2], 'friend') = 0) then mon.MonsterBehaviour := BH_GOOD
5950 else if (CompareText(P[2], 'friendly') = 0) then mon.MonsterBehaviour := BH_GOOD
5951 else mon.MonsterBehaviour := Min(Max(StrToIntDef(P[2], BH_NORMAL), BH_NORMAL), BH_GOOD);
5952 end;
5953 end;
5954 end;
5955 end
5956 else if (cmd = 'd_health') then
5957 begin
5958 if (Length(P) > 1) and
5959 ((P[1] = '1') or (P[1] = '0')) then
5960 g_debug_HealthBar := (P[1][1] = '1');
5962 g_Console_Add(Format('d_health is %d', [Byte(g_debug_HealthBar)]));
5963 end
5964 else if (cmd = 'd_player') then
5965 begin
5966 if (Length(P) > 1) and
5967 ((P[1] = '1') or (P[1] = '0')) then
5968 g_debug_Player := (P[1][1] = '1');
5970 g_Console_Add(Format(cmd + ' is %d', [Byte(g_Debug_Player)]));
5971 end
5972 else if (cmd = 'd_mem') then
5973 begin
5974 PrintHeapStats();
5975 end;
5976 end
5977 else
5978 g_Console_Add(_lc[I_MSG_NOT_DEBUG]);
5979 end;
5982 procedure GameCheats(P: SSArray);
5983 var
5984 cmd: string;
5985 f, a: Integer;
5986 plr: TPlayer;
5987 begin
5988 if (not gGameOn) or (not conIsCheatsEnabled) then
5989 begin
5990 g_Console_Add('not available');
5991 exit;
5992 end;
5993 plr := gPlayer1;
5994 if plr = nil then
5995 begin
5996 g_Console_Add('where is the player?!');
5997 exit;
5998 end;
5999 cmd := LowerCase(P[0]);
6000 // god
6001 if cmd = 'god' then
6002 begin
6003 plr.GodMode := not plr.GodMode;
6004 if plr.GodMode then g_Console_Add('player is godlike now') else g_Console_Add('player is mortal now');
6005 exit;
6006 end;
6007 // give <health|exit|weapons|air|suit|jetpack|berserk|all>
6008 if cmd = 'give' then
6009 begin
6010 if length(P) < 2 then begin g_Console_Add('give what?!'); exit; end;
6011 for f := 1 to High(P) do
6012 begin
6013 cmd := LowerCase(P[f]);
6014 if cmd = 'health' then begin plr.RestoreHealthArmor(); g_Console_Add('player feels himself better'); continue; end;
6015 if (cmd = 'all') {or (cmd = 'weapons')} then begin plr.AllRulez(False); g_Console_Add('player got the gifts'); continue; end;
6016 if cmd = 'exit' then
6017 begin
6018 if gTriggers <> nil then
6019 begin
6020 for a := 0 to High(gTriggers) do
6021 begin
6022 if gTriggers[a].TriggerType = TRIGGER_EXIT then
6023 begin
6024 g_Console_Add('player left the map');
6025 gExitByTrigger := True;
6026 //g_Game_ExitLevel(gTriggers[a].Data.MapName);
6027 g_Game_ExitLevel(gTriggers[a].tgcMap);
6028 break;
6029 end;
6030 end;
6031 end;
6032 continue;
6033 end;
6035 if cmd = 'air' then begin plr.GiveItem(ITEM_OXYGEN); g_Console_Add('player got some air'); continue; end;
6036 if cmd = 'jetpack' then begin plr.GiveItem(ITEM_JETPACK); g_Console_Add('player got a jetpack'); continue; end;
6037 if cmd = 'suit' then begin plr.GiveItem(ITEM_SUIT); g_Console_Add('player got an envirosuit'); continue; end;
6038 if cmd = 'berserk' then begin plr.GiveItem(ITEM_MEDKIT_BLACK); g_Console_Add('player got a berserk pack'); continue; end;
6039 if cmd = 'backpack' then begin plr.GiveItem(ITEM_AMMO_BACKPACK); g_Console_Add('player got a backpack'); continue; end;
6041 if cmd = 'helmet' then begin plr.GiveItem(ITEM_HELMET); g_Console_Add('player got a helmet'); continue; end;
6042 if cmd = 'bottle' then begin plr.GiveItem(ITEM_BOTTLE); g_Console_Add('player got a bottle of health'); continue; end;
6044 if cmd = 'stimpack' then begin plr.GiveItem(ITEM_MEDKIT_SMALL); g_Console_Add('player got a stimpack'); continue; end;
6045 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;
6047 if cmd = 'greenarmor' then begin plr.GiveItem(ITEM_ARMOR_GREEN); g_Console_Add('player got a security armor'); continue; end;
6048 if cmd = 'bluearmor' then begin plr.GiveItem(ITEM_ARMOR_BLUE); g_Console_Add('player got a combat armor'); continue; end;
6050 if (cmd = 'megasphere') or (cmd = 'mega') then begin plr.GiveItem(ITEM_SPHERE_BLUE); g_Console_Add('player got a megasphere'); continue; end;
6051 if (cmd = 'soulsphere') or (cmd = 'soul')then begin plr.GiveItem(ITEM_SPHERE_WHITE); g_Console_Add('player got a soul sphere'); continue; end;
6053 if (cmd = 'invul') or (cmd = 'invulnerability') then begin plr.GiveItem(ITEM_INVUL); g_Console_Add('player got invulnerability'); continue; end;
6054 if (cmd = 'invis') or (cmd = 'invisibility') then begin plr.GiveItem(ITEM_INVIS); g_Console_Add('player got invisibility'); continue; end;
6056 if cmd = 'redkey' then begin plr.GiveItem(ITEM_KEY_RED); g_Console_Add('player got the red key'); continue; end;
6057 if cmd = 'greenkey' then begin plr.GiveItem(ITEM_KEY_GREEN); g_Console_Add('player got the green key'); continue; end;
6058 if cmd = 'bluekey' then begin plr.GiveItem(ITEM_KEY_BLUE); g_Console_Add('player got the blue key'); continue; end;
6060 if (cmd = 'shotgun') or (cmd = 'sg') then begin plr.GiveItem(ITEM_WEAPON_SHOTGUN1); g_Console_Add('player got a shotgun'); continue; end;
6061 if (cmd = 'supershotgun') or (cmd = 'ssg') then begin plr.GiveItem(ITEM_WEAPON_SHOTGUN2); g_Console_Add('player got a supershotgun'); continue; end;
6062 if cmd = 'chaingun' then begin plr.GiveItem(ITEM_WEAPON_CHAINGUN); g_Console_Add('player got a chaingun'); continue; end;
6063 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;
6064 if cmd = 'plasmagun' then begin plr.GiveItem(ITEM_WEAPON_PLASMA); g_Console_Add('player got a plasma gun'); continue; end;
6065 if cmd = 'bfg' then begin plr.GiveItem(ITEM_WEAPON_BFG); g_Console_Add('player got a BFG-9000'); continue; end;
6067 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;
6068 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;
6069 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;
6070 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;
6071 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;
6072 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;
6074 if cmd = 'superchaingun' then begin plr.GiveItem(ITEM_WEAPON_SUPERPULEMET); g_Console_Add('player got a superchaingun'); continue; end;
6075 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;
6077 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;
6078 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;
6080 if cmd = 'chainsaw' then begin plr.GiveItem(ITEM_WEAPON_SAW); g_Console_Add('player got a chainsaw'); continue; end;
6082 if cmd = 'ammo' then
6083 begin
6084 plr.GiveItem(ITEM_AMMO_SHELLS_BOX);
6085 plr.GiveItem(ITEM_AMMO_BULLETS_BOX);
6086 plr.GiveItem(ITEM_AMMO_CELL_BIG);
6087 plr.GiveItem(ITEM_AMMO_ROCKET_BOX);
6088 plr.GiveItem(ITEM_AMMO_FUELCAN);
6089 g_Console_Add('player got some ammo');
6090 continue;
6091 end;
6093 if cmd = 'clip' then begin plr.GiveItem(ITEM_AMMO_BULLETS); g_Console_Add('player got some bullets'); continue; end;
6094 if cmd = 'bullets' then begin plr.GiveItem(ITEM_AMMO_BULLETS_BOX); g_Console_Add('player got a box of bullets'); continue; end;
6096 if cmd = 'shells' then begin plr.GiveItem(ITEM_AMMO_SHELLS); g_Console_Add('player got some shells'); continue; end;
6097 if cmd = 'shellbox' then begin plr.GiveItem(ITEM_AMMO_SHELLS_BOX); g_Console_Add('player got a box of shells'); continue; end;
6099 if cmd = 'cells' then begin plr.GiveItem(ITEM_AMMO_CELL); g_Console_Add('player got some cells'); continue; end;
6100 if cmd = 'battery' then begin plr.GiveItem(ITEM_AMMO_CELL_BIG); g_Console_Add('player got cell battery'); continue; end;
6102 if cmd = 'rocket' then begin plr.GiveItem(ITEM_AMMO_ROCKET); g_Console_Add('player got a rocket'); continue; end;
6103 if cmd = 'rocketbox' then begin plr.GiveItem(ITEM_AMMO_ROCKET_BOX); g_Console_Add('player got some rockets'); continue; end;
6105 if (cmd = 'fuel') or (cmd = 'fuelcan') then begin plr.GiveItem(ITEM_AMMO_FUELCAN); g_Console_Add('player got fuel canister'); continue; end;
6107 if cmd = 'weapons' then
6108 begin
6109 plr.GiveItem(ITEM_WEAPON_SHOTGUN1);
6110 plr.GiveItem(ITEM_WEAPON_SHOTGUN2);
6111 plr.GiveItem(ITEM_WEAPON_CHAINGUN);
6112 plr.GiveItem(ITEM_WEAPON_ROCKETLAUNCHER);
6113 plr.GiveItem(ITEM_WEAPON_PLASMA);
6114 plr.GiveItem(ITEM_WEAPON_BFG);
6115 g_Console_Add('player got weapons');
6116 continue;
6117 end;
6119 if cmd = 'keys' then
6120 begin
6121 plr.GiveItem(ITEM_KEY_RED);
6122 plr.GiveItem(ITEM_KEY_GREEN);
6123 plr.GiveItem(ITEM_KEY_BLUE);
6124 g_Console_Add('player got all keys');
6125 continue;
6126 end;
6128 g_Console_Add('i don''t know how to give '''+cmd+'''!');
6129 end;
6130 exit;
6131 end;
6132 // open
6133 if cmd = 'open' then
6134 begin
6135 g_Console_Add('player activated sesame');
6136 g_Triggers_OpenAll();
6137 exit;
6138 end;
6139 // fly
6140 if cmd = 'fly' then
6141 begin
6142 gFly := not gFly;
6143 if gFly then g_Console_Add('player feels himself lighter') else g_Console_Add('player lost his wings');
6144 exit;
6145 end;
6146 // noclip
6147 if cmd = 'noclip' then
6148 begin
6149 plr.SwitchNoClip;
6150 g_Console_Add('wall hardeness adjusted');
6151 exit;
6152 end;
6153 // notarget
6154 if cmd = 'notarget' then
6155 begin
6156 plr.NoTarget := not plr.NoTarget;
6157 if plr.NoTarget then g_Console_Add('player hides in shadows') else g_Console_Add('player is brave again');
6158 exit;
6159 end;
6160 // noreload
6161 if cmd = 'noreload' then
6162 begin
6163 plr.NoReload := not plr.NoReload;
6164 if plr.NoReload then g_Console_Add('player is action hero now') else g_Console_Add('player is ordinary man now');
6165 exit;
6166 end;
6167 // speedy
6168 if cmd = 'speedy' then
6169 begin
6170 MAX_RUNVEL := 32-MAX_RUNVEL;
6171 g_Console_Add('speed adjusted');
6172 exit;
6173 end;
6174 // jumpy
6175 if cmd = 'jumpy' then
6176 begin
6177 VEL_JUMP := 30-VEL_JUMP;
6178 g_Console_Add('jump height adjusted');
6179 exit;
6180 end;
6181 // automap
6182 if cmd = 'automap' then
6183 begin
6184 gShowMap := not gShowMap;
6185 if gShowMap then g_Console_Add('player gains second sight') else g_Console_Add('player lost second sight');
6186 exit;
6187 end;
6188 // aimline
6189 if cmd = 'aimline' then
6190 begin
6191 gAimLine := not gAimLine;
6192 if gAimLine then g_Console_Add('player gains laser sight') else g_Console_Add('player lost laser sight');
6193 exit;
6194 end;
6195 end;
6197 procedure GameCommands(P: SSArray);
6198 var
6199 a, b: Integer;
6200 s, pw: String;
6201 chstr: string;
6202 cmd: string;
6203 pl: pTNetClient = nil;
6204 plr: TPlayer;
6205 prt: Word;
6206 nm: Boolean;
6207 listen: LongWord;
6208 found: Boolean;
6209 begin
6210 // Îáùèå êîìàíäû:
6211 cmd := LowerCase(P[0]);
6212 chstr := '';
6213 if (cmd = 'quit') or
6214 (cmd = 'exit') then
6215 begin
6216 g_Game_Free();
6217 g_Game_Quit();
6218 Exit;
6219 end
6220 else if cmd = 'pause' then
6221 begin
6222 if (g_ActiveWindow = nil) then
6223 g_Game_Pause(not gPauseMain);
6224 end
6225 else if cmd = 'endgame' then
6226 gExit := EXIT_SIMPLE
6227 else if cmd = 'restart' then
6228 begin
6229 if gGameOn or (gState in [STATE_INTERSINGLE, STATE_INTERCUSTOM]) then
6230 begin
6231 if g_Game_IsClient then
6232 begin
6233 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6234 Exit;
6235 end;
6236 g_Game_Restart();
6237 end else
6238 g_Console_Add(_lc[I_MSG_NOT_GAME]);
6239 end
6240 else if cmd = 'kick' then
6241 begin
6242 if g_Game_IsServer then
6243 begin
6244 if Length(P) < 2 then
6245 begin
6246 g_Console_Add('kick <name>');
6247 Exit;
6248 end;
6249 if P[1] = '' then
6250 begin
6251 g_Console_Add('kick <name>');
6252 Exit;
6253 end;
6255 if g_Game_IsNet then
6256 pl := g_Net_Client_ByName(P[1]);
6257 if (pl <> nil) then
6258 begin
6259 s := g_Net_ClientName_ByID(pl^.ID);
6260 enet_peer_disconnect(pl^.Peer, NET_DISC_KICK);
6261 g_Console_Add(Format(_lc[I_PLAYER_KICK], [s]));
6262 MH_SEND_GameEvent(NET_EV_PLAYER_KICK, 0, s);
6263 g_Net_Slist_ServerPlayerLeaves();
6264 end else if gPlayers <> nil then
6265 for a := Low(gPlayers) to High(gPlayers) do
6266 if gPlayers[a] <> nil then
6267 if Copy(LowerCase(gPlayers[a].Name), 1, Length(P[1])) = LowerCase(P[1]) then
6268 begin
6269 // Íå îòêëþ÷àòü îñíîâíûõ èãðîêîâ â ñèíãëå
6270 if not(gPlayers[a] is TBot) and (gGameSettings.GameType = GT_SINGLE) then
6271 continue;
6272 gPlayers[a].Lives := 0;
6273 gPlayers[a].Kill(K_SIMPLEKILL, 0, HIT_DISCON);
6274 g_Console_Add(Format(_lc[I_PLAYER_LEAVE], [gPlayers[a].Name]), True);
6275 g_Player_Remove(gPlayers[a].UID);
6276 g_Net_Slist_ServerPlayerLeaves();
6277 // Åñëè íå ïåðåìåøàòü, ïðè äîáàâëåíèè íîâûõ áîòîâ ïîÿâÿòñÿ ñòàðûå
6278 g_Bot_MixNames();
6279 end;
6280 end else
6281 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
6282 end
6283 else if cmd = 'kick_id' then
6284 begin
6285 if g_Game_IsServer and g_Game_IsNet then
6286 begin
6287 if Length(P) < 2 then
6288 begin
6289 g_Console_Add('kick_id <client ID>');
6290 Exit;
6291 end;
6292 if P[1] = '' then
6293 begin
6294 g_Console_Add('kick_id <client ID>');
6295 Exit;
6296 end;
6298 a := StrToIntDef(P[1], 0);
6299 if (NetClients <> nil) and (a <= High(NetClients)) then
6300 begin
6301 if NetClients[a].Used and (NetClients[a].Peer <> nil) then
6302 begin
6303 s := g_Net_ClientName_ByID(NetClients[a].ID);
6304 enet_peer_disconnect(NetClients[a].Peer, NET_DISC_KICK);
6305 g_Console_Add(Format(_lc[I_PLAYER_KICK], [s]));
6306 MH_SEND_GameEvent(NET_EV_PLAYER_KICK, 0, s);
6307 g_Net_Slist_ServerPlayerLeaves();
6308 end;
6309 end;
6310 end else
6311 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6312 end
6313 else if cmd = 'ban' then
6314 begin
6315 if g_Game_IsServer and g_Game_IsNet then
6316 begin
6317 if Length(P) < 2 then
6318 begin
6319 g_Console_Add('ban <name>');
6320 Exit;
6321 end;
6322 if P[1] = '' then
6323 begin
6324 g_Console_Add('ban <name>');
6325 Exit;
6326 end;
6328 pl := g_Net_Client_ByName(P[1]);
6329 if (pl <> nil) then
6330 begin
6331 s := g_Net_ClientName_ByID(pl^.ID);
6332 g_Net_BanHost(pl^.Peer^.address.host, False);
6333 enet_peer_disconnect(pl^.Peer, NET_DISC_TEMPBAN);
6334 g_Console_Add(Format(_lc[I_PLAYER_BAN], [s]));
6335 MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s);
6336 g_Net_Slist_ServerPlayerLeaves();
6337 end else
6338 g_Console_Add(Format(_lc[I_NET_ERR_NAME404], [P[1]]));
6339 end else
6340 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6341 end
6342 else if cmd = 'ban_id' then
6343 begin
6344 if g_Game_IsServer and g_Game_IsNet then
6345 begin
6346 if Length(P) < 2 then
6347 begin
6348 g_Console_Add('ban_id <client ID>');
6349 Exit;
6350 end;
6351 if P[1] = '' then
6352 begin
6353 g_Console_Add('ban_id <client ID>');
6354 Exit;
6355 end;
6357 a := StrToIntDef(P[1], 0);
6358 if (NetClients <> nil) and (a <= High(NetClients)) then
6359 if NetClients[a].Used and (NetClients[a].Peer <> nil) then
6360 begin
6361 s := g_Net_ClientName_ByID(NetClients[a].ID);
6362 g_Net_BanHost(NetClients[a].Peer^.address.host, False);
6363 enet_peer_disconnect(NetClients[a].Peer, NET_DISC_TEMPBAN);
6364 g_Console_Add(Format(_lc[I_PLAYER_BAN], [s]));
6365 MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s);
6366 g_Net_Slist_ServerPlayerLeaves();
6367 end;
6368 end else
6369 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6370 end
6371 else if cmd = 'permban' then
6372 begin
6373 if g_Game_IsServer and g_Game_IsNet then
6374 begin
6375 if Length(P) < 2 then
6376 begin
6377 g_Console_Add('permban <name>');
6378 Exit;
6379 end;
6380 if P[1] = '' then
6381 begin
6382 g_Console_Add('permban <name>');
6383 Exit;
6384 end;
6386 pl := g_Net_Client_ByName(P[1]);
6387 if (pl <> nil) then
6388 begin
6389 s := g_Net_ClientName_ByID(pl^.ID);
6390 g_Net_BanHost(pl^.Peer^.address.host);
6391 enet_peer_disconnect(pl^.Peer, NET_DISC_BAN);
6392 g_Net_SaveBanList();
6393 g_Console_Add(Format(_lc[I_PLAYER_BAN], [s]));
6394 MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s);
6395 g_Net_Slist_ServerPlayerLeaves();
6396 end else
6397 g_Console_Add(Format(_lc[I_NET_ERR_NAME404], [P[1]]));
6398 end else
6399 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6400 end
6401 else if cmd = 'permban_id' then
6402 begin
6403 if g_Game_IsServer and g_Game_IsNet then
6404 begin
6405 if Length(P) < 2 then
6406 begin
6407 g_Console_Add('permban_id <client ID>');
6408 Exit;
6409 end;
6410 if P[1] = '' then
6411 begin
6412 g_Console_Add('permban_id <client ID>');
6413 Exit;
6414 end;
6416 a := StrToIntDef(P[1], 0);
6417 if (NetClients <> nil) and (a <= High(NetClients)) then
6418 if NetClients[a].Used and (NetClients[a].Peer <> nil) then
6419 begin
6420 s := g_Net_ClientName_ByID(NetClients[a].ID);
6421 g_Net_BanHost(NetClients[a].Peer^.address.host);
6422 enet_peer_disconnect(NetClients[a].Peer, NET_DISC_BAN);
6423 g_Net_SaveBanList();
6424 g_Console_Add(Format(_lc[I_PLAYER_BAN], [s]));
6425 MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s);
6426 g_Net_Slist_ServerPlayerLeaves();
6427 end;
6428 end else
6429 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6430 end
6431 else if cmd = 'unban' then
6432 begin
6433 if g_Game_IsServer and g_Game_IsNet then
6434 begin
6435 if Length(P) < 2 then
6436 begin
6437 g_Console_Add('unban <IP Address>');
6438 Exit;
6439 end;
6440 if P[1] = '' then
6441 begin
6442 g_Console_Add('unban <IP Address>');
6443 Exit;
6444 end;
6446 if g_Net_UnbanHost(P[1]) then
6447 begin
6448 g_Console_Add(Format(_lc[I_MSG_UNBAN_OK], [P[1]]));
6449 g_Net_SaveBanList();
6450 end else
6451 g_Console_Add(Format(_lc[I_MSG_UNBAN_FAIL], [P[1]]));
6452 end else
6453 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6454 end
6455 else if cmd = 'clientlist' then
6456 begin
6457 if g_Game_IsServer and g_Game_IsNet then
6458 begin
6459 b := 0;
6460 if NetClients <> nil then
6461 for a := Low(NetClients) to High(NetClients) do
6462 if NetClients[a].Used and (NetClients[a].Peer <> nil) then
6463 begin
6464 plr := g_Player_Get(NetClients[a].Player);
6465 if plr = nil then continue;
6466 Inc(b);
6467 g_Console_Add(Format('#%2d: %-15s | %s', [a,
6468 IpToStr(NetClients[a].Peer^.address.host), plr.Name]));
6469 end;
6470 if b = 0 then
6471 g_Console_Add(_lc[I_MSG_NOCLIENTS]);
6472 end else
6473 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6474 end
6475 else if cmd = 'connect' then
6476 begin
6477 if (NetMode = NET_NONE) then
6478 begin
6479 if Length(P) < 2 then
6480 begin
6481 g_Console_Add('connect <IP> [port] [password]');
6482 Exit;
6483 end;
6484 if P[1] = '' then
6485 begin
6486 g_Console_Add('connect <IP> [port] [password]');
6487 Exit;
6488 end;
6490 if Length(P) > 2 then
6491 prt := StrToIntDef(P[2], 25666)
6492 else
6493 prt := 25666;
6495 if Length(P) > 3 then
6496 pw := P[3]
6497 else
6498 pw := '';
6500 g_Game_StartClient(P[1], prt, pw);
6501 end;
6502 end
6503 else if cmd = 'disconnect' then
6504 begin
6505 if (NetMode = NET_CLIENT) then
6506 g_Net_Disconnect();
6507 end
6508 else if cmd = 'reconnect' then
6509 begin
6510 if (NetMode = NET_SERVER) then
6511 Exit;
6513 if (NetMode = NET_CLIENT) then
6514 begin
6515 g_Net_Disconnect();
6516 gExit := EXIT_SIMPLE;
6517 EndGame;
6518 end;
6520 //TODO: Use last successful password to reconnect, instead of ''
6521 g_Game_StartClient(NetClientIP, NetClientPort, '');
6522 end
6523 else if (cmd = 'addbot') or
6524 (cmd = 'bot_add') then
6525 begin
6526 if Length(P) > 2 then
6527 g_Bot_Add(TEAM_NONE, StrToIntDef(P[1], 2), StrToIntDef(P[2], 100))
6528 else if Length(P) > 1 then
6529 g_Bot_Add(TEAM_NONE, StrToIntDef(P[1], 2))
6530 else
6531 g_Bot_Add(TEAM_NONE, 2);
6532 end
6533 else if cmd = 'bot_addlist' then
6534 begin
6535 if Length(P) > 1 then
6536 begin
6537 if Length(P) = 2 then
6538 g_Bot_AddList(TEAM_NONE, P[1], StrToIntDef(P[1], -1))
6539 else if Length(P) = 3 then
6540 g_Bot_AddList(TEAM_NONE, P[1], StrToIntDef(P[1], -1), StrToIntDef(P[2], 100))
6541 else
6542 g_Bot_AddList(IfThen(P[2] = 'red', TEAM_RED, TEAM_BLUE), P[1], StrToIntDef(P[1], -1));
6543 end;
6544 end
6545 else if cmd = 'bot_removeall' then
6546 g_Bot_RemoveAll()
6547 else if cmd = 'chat' then
6548 begin
6549 if g_Game_IsNet then
6550 begin
6551 if Length(P) > 1 then
6552 begin
6553 for a := 1 to High(P) do
6554 chstr := chstr + P[a] + ' ';
6556 if Length(chstr) > 200 then SetLength(chstr, 200);
6558 if Length(chstr) < 1 then
6559 begin
6560 g_Console_Add('chat <text>');
6561 Exit;
6562 end;
6564 chstr := b_Text_Format(chstr);
6565 if g_Game_IsClient then
6566 MC_SEND_Chat(chstr, NET_CHAT_PLAYER)
6567 else
6568 MH_SEND_Chat(gPlayer1Settings.Name + ': ' + chstr, NET_CHAT_PLAYER);
6569 end
6570 else
6571 g_Console_Add('chat <text>');
6572 end else
6573 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
6574 end
6575 else if cmd = 'teamchat' then
6576 begin
6577 if g_Game_IsNet and (gGameSettings.GameMode in [GM_TDM, GM_CTF]) then
6578 begin
6579 if Length(P) > 1 then
6580 begin
6581 for a := 1 to High(P) do
6582 chstr := chstr + P[a] + ' ';
6584 if Length(chstr) > 200 then SetLength(chstr, 200);
6586 if Length(chstr) < 1 then
6587 begin
6588 g_Console_Add('teamchat <text>');
6589 Exit;
6590 end;
6592 chstr := b_Text_Format(chstr);
6593 if g_Game_IsClient then
6594 MC_SEND_Chat(chstr, NET_CHAT_TEAM)
6595 else
6596 MH_SEND_Chat(gPlayer1Settings.Name + ': ' + chstr, NET_CHAT_TEAM,
6597 gPlayer1Settings.Team);
6598 end
6599 else
6600 g_Console_Add('teamchat <text>');
6601 end else
6602 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
6603 end
6604 else if cmd = 'game' then
6605 begin
6606 if gGameSettings.GameType <> GT_NONE then
6607 begin
6608 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
6609 Exit;
6610 end;
6611 if Length(P) = 1 then
6612 begin
6613 g_Console_Add(cmd + ' <WAD> [MAP] [# players]');
6614 Exit;
6615 end;
6616 // game not started yet, load fist map from some wad
6617 found := false;
6618 s := addWadExtension(P[1]);
6619 found := e_FindResource(AllMapDirs, s);
6620 P[1] := s;
6621 if found then
6622 begin
6623 P[1] := ExpandFileName(P[1]);
6624 // if map not choosed then set first map
6625 if Length(P) < 3 then
6626 begin
6627 SetLength(P, 3);
6628 P[2] := g_Game_GetFirstMap(P[1]);
6629 end;
6631 s := P[1] + ':\' + UpperCase(P[2]);
6633 if g_Map_Exist(s) then
6634 begin
6635 // start game
6636 g_Game_Free();
6637 with gGameSettings do
6638 begin
6639 GameMode := g_Game_TextToMode(gcGameMode);
6640 if gSwitchGameMode <> GM_NONE then
6641 GameMode := gSwitchGameMode;
6642 if GameMode = GM_NONE then GameMode := GM_DM;
6643 if GameMode = GM_SINGLE then GameMode := GM_COOP;
6644 b := 1;
6645 if Length(P) >= 4 then
6646 b := StrToIntDef(P[3], 1);
6647 g_Game_StartCustom(s, GameMode, TimeLimit,
6648 GoalLimit, MaxLives, Options, b);
6649 end;
6650 end
6651 else
6652 if P[2] = '' then
6653 g_Console_Add(Format(_lc[I_MSG_NO_MAPS], [P[1]]))
6654 else
6655 g_Console_Add(Format(_lc[I_MSG_NO_MAP_FALLBACK], [UpperCase(P[2]), P[1]]));
6656 end else
6657 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]));
6658 end
6659 else if cmd = 'host' then
6660 begin
6661 if gGameSettings.GameType <> GT_NONE then
6662 begin
6663 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
6664 Exit;
6665 end;
6666 if Length(P) < 4 then
6667 begin
6668 g_Console_Add(cmd + ' <listen IP> <port> <WAD> [MAP] [# players]');
6669 Exit;
6670 end;
6671 if not StrToIp(P[1], listen) then
6672 Exit;
6673 prt := StrToIntDef(P[2], 25666);
6675 s := addWadExtension(P[3]);
6676 found := e_FindResource(AllMapDirs, s);
6677 P[3] := s;
6678 if found then
6679 begin
6680 // get first map in wad, if not specified
6681 if Length(P) < 5 then
6682 begin
6683 SetLength(P, 5);
6684 P[4] := g_Game_GetFirstMap(P[1]);
6685 end;
6686 s := P[3] + ':\' + UpperCase(P[4]);
6687 if g_Map_Exist(s) then
6688 begin
6689 // start game
6690 g_Game_Free();
6691 with gGameSettings do
6692 begin
6693 GameMode := g_Game_TextToMode(gcGameMode);
6694 if gSwitchGameMode <> GM_NONE then GameMode := gSwitchGameMode;
6695 if GameMode = GM_NONE then GameMode := GM_DM;
6696 if GameMode = GM_SINGLE then GameMode := GM_COOP;
6697 b := 0;
6698 if Length(P) >= 6 then
6699 b := StrToIntDef(P[5], 0);
6700 g_Game_StartServer(s, GameMode, TimeLimit, GoalLimit, MaxLives, Options, b, listen, prt)
6701 end
6702 end
6703 else
6704 begin
6705 if P[4] = '' then
6706 g_Console_Add(Format(_lc[I_MSG_NO_MAPS], [P[3]]))
6707 else
6708 g_Console_Add(Format(_lc[I_MSG_NO_MAP_FALLBACK], [UpperCase(P[4]), P[3]]))
6709 end
6710 end
6711 else
6712 begin
6713 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[3]]))
6714 end
6715 end
6716 else if cmd = 'map' then
6717 begin
6718 if Length(P) = 1 then
6719 begin
6720 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
6721 begin
6722 g_Console_Add(cmd + ' <MAP>');
6723 g_Console_Add(cmd + ' <WAD> [MAP]')
6724 end
6725 else
6726 begin
6727 g_Console_Add(_lc[I_MSG_GM_UNAVAIL])
6728 end
6729 end
6730 else
6731 begin
6732 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
6733 begin
6734 if Length(P) < 3 then
6735 begin
6736 // first param is map or wad
6737 s := UpperCase(P[1]);
6738 if g_Map_Exist(gGameSettings.WAD + ':\' + s) then
6739 begin
6740 gExitByTrigger := False;
6741 if gGameOn then
6742 begin
6743 // already in game, finish current map
6744 gNextMap := s;
6745 gExit := EXIT_ENDLEVELCUSTOM;
6746 end
6747 else
6748 begin
6749 // intermission, so change map immediately
6750 g_Game_ChangeMap(s)
6751 end
6752 end
6753 else
6754 begin
6755 s := P[1];
6756 found := e_FindResource(AllMapDirs, s);
6757 P[1] := s;
6758 g_Console_Add(Format(_lc[I_MSG_NO_MAP_FALLBACK], [s, 'WAD ' + P[1]]));
6759 if found then
6760 begin
6761 // no such map, found wad
6762 pw := P[1];
6763 SetLength(P, 3);
6764 P[1] := ExpandFileName(pw);
6765 P[2] := g_Game_GetFirstMap(P[1]);
6766 s := P[1] + ':\' + P[2];
6767 if g_Map_Exist(s) then
6768 begin
6769 gExitByTrigger := False;
6770 if gGameOn then
6771 begin
6772 // already in game, finish current map
6773 gNextMap := s;
6774 gExit := EXIT_ENDLEVELCUSTOM
6775 end
6776 else
6777 begin
6778 // intermission, so change map immediately
6779 g_Game_ChangeMap(s)
6780 end
6781 end
6782 else
6783 begin
6784 if P[2] = '' then
6785 g_Console_Add(Format(_lc[I_MSG_NO_MAPS], [P[1]]))
6786 else
6787 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [P[2]]))
6788 end
6789 end
6790 else
6791 begin
6792 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]))
6793 end
6794 end;
6795 end
6796 else
6797 begin
6798 s := addWadExtension(P[1]);
6799 found := e_FindResource(AllMapDirs, s);
6800 P[1] := s;
6801 if found then
6802 begin
6803 P[2] := UpperCase(P[2]);
6804 s := P[1] + ':\' + P[2];
6805 if g_Map_Exist(s) then
6806 begin
6807 gExitByTrigger := False;
6808 if gGameOn then
6809 begin
6810 gNextMap := s;
6811 gExit := EXIT_ENDLEVELCUSTOM
6812 end
6813 else
6814 begin
6815 g_Game_ChangeMap(s)
6816 end
6817 end
6818 else
6819 begin
6820 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [P[2]]))
6821 end
6822 end
6823 else
6824 begin
6825 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]))
6826 end
6827 end
6828 end
6829 else
6830 begin
6831 g_Console_Add(_lc[I_MSG_GM_UNAVAIL])
6832 end
6833 end
6834 end
6835 else if cmd = 'nextmap' then
6836 begin
6837 if not(gGameOn or (gState = STATE_INTERCUSTOM)) then
6838 begin
6839 g_Console_Add(_lc[I_MSG_NOT_GAME])
6840 end
6841 else
6842 begin
6843 nm := True;
6844 if Length(P) = 1 then
6845 begin
6846 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
6847 begin
6848 g_Console_Add(cmd + ' <MAP>');
6849 g_Console_Add(cmd + ' <WAD> [MAP]');
6850 end
6851 else
6852 begin
6853 nm := False;
6854 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
6855 end;
6856 end
6857 else
6858 begin
6859 nm := False;
6860 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
6861 begin
6862 if Length(P) < 3 then
6863 begin
6864 // first param is map or wad
6865 s := UpperCase(P[1]);
6866 if g_Map_Exist(gGameSettings.WAD + ':\' + s) then
6867 begin
6868 // map founded
6869 gExitByTrigger := False;
6870 gNextMap := s;
6871 nm := True;
6872 end
6873 else
6874 begin
6875 // no such map, found wad
6876 pw := addWadExtension(P[1]);
6877 found := e_FindResource(MapDirs, pw);
6878 if not found then
6879 found := e_FindResource(WadDirs, pw);
6880 P[1] := pw;
6881 g_Console_Add(Format(_lc[I_MSG_NO_MAP_FALLBACK], [s, P[1]]));
6882 if found then
6883 begin
6884 // map not specified, select first map
6885 SetLength(P, 3);
6886 P[2] := g_Game_GetFirstMap(P[1]);
6887 s := P[1] + ':\' + P[2];
6888 if g_Map_Exist(s) then
6889 begin
6890 gExitByTrigger := False;
6891 gNextMap := s;
6892 nm := True
6893 end
6894 else
6895 begin
6896 if P[2] = '' then
6897 g_Console_Add(Format(_lc[I_MSG_NO_MAPS], [P[1]]))
6898 else
6899 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [P[2]]))
6900 end
6901 end
6902 else
6903 begin
6904 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]))
6905 end
6906 end
6907 end
6908 else
6909 begin
6910 // specified two params wad + map
6911 pw := addWadExtension(P[1]);
6912 found := e_FindResource(MapDirs, pw);
6913 if not found then
6914 found := e_FindResource(MapDirs, pw);
6915 P[1] := pw;
6916 if found then
6917 begin
6918 P[2] := UpperCase(P[2]);
6919 s := P[1] + ':\' + P[2];
6920 if g_Map_Exist(s) then
6921 begin
6922 gExitByTrigger := False;
6923 gNextMap := s;
6924 nm := True
6925 end
6926 else
6927 begin
6928 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [P[2]]))
6929 end
6930 end
6931 else
6932 begin
6933 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]))
6934 end
6935 end
6936 end
6937 else
6938 begin
6939 g_Console_Add(_lc[I_MSG_GM_UNAVAIL])
6940 end
6941 end;
6942 if nm then
6943 begin
6944 if gNextMap = '' then
6945 g_Console_Add(_lc[I_MSG_NEXTMAP_UNSET])
6946 else
6947 g_Console_Add(Format(_lc[I_MSG_NEXTMAP_SET], [gNextMap]))
6948 end
6949 end
6950 end
6951 else if (cmd = 'endmap') or (cmd = 'goodbye') then
6952 begin
6953 if not gGameOn then
6954 begin
6955 g_Console_Add(_lc[I_MSG_NOT_GAME])
6956 end
6957 else
6958 begin
6959 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
6960 begin
6961 gExitByTrigger := False;
6962 // next map not specified, try to find trigger EXIT
6963 if (gNextMap = '') and (gTriggers <> nil) then
6964 begin
6965 for a := 0 to High(gTriggers) do
6966 begin
6967 if gTriggers[a].TriggerType = TRIGGER_EXIT then
6968 begin
6969 gExitByTrigger := True;
6970 //gNextMap := gTriggers[a].Data.MapName;
6971 gNextMap := gTriggers[a].tgcMap;
6972 Break
6973 end
6974 end
6975 end;
6976 if gNextMap = '' then
6977 gNextMap := g_Game_GetNextMap();
6978 if not isWadPath(gNextMap) then
6979 s := gGameSettings.WAD + ':\' + gNextMap
6980 else
6981 s := gNextMap;
6982 if g_Map_Exist(s) then
6983 gExit := EXIT_ENDLEVELCUSTOM
6984 else
6985 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [gNextMap]))
6986 end
6987 else
6988 begin
6989 g_Console_Add(_lc[I_MSG_GM_UNAVAIL])
6990 end
6991 end
6992 end
6993 else if (cmd = 'event') then
6994 begin
6995 if (Length(P) <= 1) then
6996 begin
6997 for a := 0 to High(gEvents) do
6998 if gEvents[a].Command = '' then
6999 g_Console_Add(gEvents[a].Name + ' <none>')
7000 else
7001 g_Console_Add(gEvents[a].Name + ' "' + gEvents[a].Command + '"');
7002 Exit;
7003 end;
7004 if (Length(P) = 2) then
7005 begin
7006 for a := 0 to High(gEvents) do
7007 if gEvents[a].Name = P[1] then
7008 if gEvents[a].Command = '' then
7009 g_Console_Add(gEvents[a].Name + ' <none>')
7010 else
7011 g_Console_Add(gEvents[a].Name + ' "' + gEvents[a].Command + '"');
7012 Exit;
7013 end;
7014 for a := 0 to High(gEvents) do
7015 if gEvents[a].Name = P[1] then
7016 begin
7017 gEvents[a].Command := '';
7018 for b := 2 to High(P) do
7019 if Pos(' ', P[b]) = 0 then
7020 gEvents[a].Command := gEvents[a].Command + ' ' + P[b]
7021 else
7022 gEvents[a].Command := gEvents[a].Command + ' "' + P[b] + '"';
7023 gEvents[a].Command := Trim(gEvents[a].Command);
7024 Exit;
7025 end;
7026 end
7027 else if cmd = 'suicide' then
7028 begin
7029 if gGameOn then
7030 begin
7031 if g_Game_IsClient then
7032 MC_SEND_CheatRequest(NET_CHEAT_SUICIDE)
7033 else
7034 begin
7035 if gPlayer1 <> nil then
7036 gPlayer1.Damage(SUICIDE_DAMAGE, gPlayer1.UID, 0, 0, HIT_SELF);
7037 if gPlayer2 <> nil then
7038 gPlayer2.Damage(SUICIDE_DAMAGE, gPlayer2.UID, 0, 0, HIT_SELF);
7039 end;
7040 end;
7041 end
7042 else if cmd = 'screenshot' then
7043 begin
7044 g_TakeScreenShot()
7045 end
7046 else if cmd = 'weapon' then
7047 begin
7048 if Length(p) = 2 then
7049 begin
7050 a := WP_FIRST + StrToInt(p[1]) - 1;
7051 if (a >= WP_FIRST) and (a <= WP_LAST) then
7052 gSelectWeapon[0, a] := True
7053 end
7054 end
7055 else if (cmd = 'p1_weapon') or (cmd = 'p2_weapon') then
7056 begin
7057 if Length(p) = 2 then
7058 begin
7059 a := WP_FIRST + StrToInt(p[1]) - 1;
7060 b := ord(cmd[2]) - ord('1');
7061 if (a >= WP_FIRST) and (a <= WP_LAST) then
7062 gSelectWeapon[b, a] := True
7063 end
7064 end
7065 // Êîìàíäû Ñâîåé èãðû:
7066 else if gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT] then
7067 begin
7068 if cmd = 'bot_addred' then
7069 begin
7070 if Length(P) > 1 then
7071 g_Bot_Add(TEAM_RED, StrToIntDef(P[1], 2))
7072 else
7073 g_Bot_Add(TEAM_RED, 2);
7074 end
7075 else if cmd = 'bot_addblue' then
7076 begin
7077 if Length(P) > 1 then
7078 g_Bot_Add(TEAM_BLUE, StrToIntDef(P[1], 2))
7079 else
7080 g_Bot_Add(TEAM_BLUE, 2);
7081 end
7082 else if cmd = 'spectate' then
7083 begin
7084 if not gGameOn then
7085 Exit;
7086 g_Game_Spectate();
7087 end
7088 else if cmd = 'say' then
7089 begin
7090 if g_Game_IsServer and g_Game_IsNet then
7091 begin
7092 if Length(P) > 1 then
7093 begin
7094 chstr := '';
7095 for a := 1 to High(P) do
7096 chstr := chstr + P[a] + ' ';
7098 if Length(chstr) > 200 then SetLength(chstr, 200);
7100 if Length(chstr) < 1 then
7101 begin
7102 g_Console_Add('say <text>');
7103 Exit;
7104 end;
7106 chstr := b_Text_Format(chstr);
7107 MH_SEND_Chat(chstr, NET_CHAT_PLAYER);
7108 end
7109 else g_Console_Add('say <text>');
7110 end else
7111 g_Console_Add(_lc[I_MSG_SERVERONLY]);
7112 end
7113 else if cmd = 'tell' then
7114 begin
7115 if g_Game_IsServer and g_Game_IsNet then
7116 begin
7117 if (Length(P) > 2) and (P[1] <> '') then
7118 begin
7119 chstr := '';
7120 for a := 2 to High(P) do
7121 chstr := chstr + P[a] + ' ';
7123 if Length(chstr) > 200 then SetLength(chstr, 200);
7125 if Length(chstr) < 1 then
7126 begin
7127 g_Console_Add('tell <playername> <text>');
7128 Exit;
7129 end;
7131 pl := g_Net_Client_ByName(P[1]);
7132 if pl <> nil then
7133 MH_SEND_Chat(b_Text_Format(chstr), NET_CHAT_PLAYER, pl^.ID)
7134 else
7135 g_Console_Add(Format(_lc[I_NET_ERR_NAME404], [P[1]]));
7136 end
7137 else g_Console_Add('tell <playername> <text>');
7138 end else
7139 g_Console_Add(_lc[I_MSG_SERVERONLY]);
7140 end
7141 else if (cmd = 'overtime') and not g_Game_IsClient then
7142 begin
7143 if (Length(P) = 1) or (StrToIntDef(P[1], -1) <= 0) then
7144 Exit;
7145 // Äîïîëíèòåëüíîå âðåìÿ:
7146 gGameSettings.TimeLimit := (gTime - gGameStartTime) div 1000 + Word(StrToIntDef(P[1], 0));
7148 g_Console_Add(Format(_lc[I_MSG_TIME_LIMIT],
7149 [gGameSettings.TimeLimit div 3600,
7150 (gGameSettings.TimeLimit div 60) mod 60,
7151 gGameSettings.TimeLimit mod 60]));
7152 if g_Game_IsNet then MH_SEND_GameSettings;
7153 end
7154 else if (cmd = 'rcon_password') and g_Game_IsClient then
7155 begin
7156 if (Length(P) <= 1) then
7157 g_Console_Add('rcon_password <password>')
7158 else
7159 MC_SEND_RCONPassword(P[1]);
7160 end
7161 else if cmd = 'rcon' then
7162 begin
7163 if g_Game_IsClient then
7164 begin
7165 if Length(P) > 1 then
7166 begin
7167 chstr := '';
7168 for a := 1 to High(P) do
7169 chstr := chstr + P[a] + ' ';
7171 if Length(chstr) > 200 then SetLength(chstr, 200);
7173 if Length(chstr) < 1 then
7174 begin
7175 g_Console_Add('rcon <command>');
7176 Exit;
7177 end;
7179 MC_SEND_RCONCommand(chstr);
7180 end
7181 else g_Console_Add('rcon <command>');
7182 end;
7183 end
7184 else if cmd = 'ready' then
7185 begin
7186 if g_Game_IsServer and (gLMSRespawn = LMS_RESPAWN_WARMUP) then
7187 gLMSRespawnTime := gTime + 100;
7188 end
7189 else if (cmd = 'callvote') and g_Game_IsNet then
7190 begin
7191 if Length(P) > 1 then
7192 begin
7193 chstr := '';
7194 for a := 1 to High(P) do begin
7195 if a > 1 then chstr := chstr + ' ';
7196 chstr := chstr + P[a];
7197 end;
7199 if Length(chstr) > 200 then SetLength(chstr, 200);
7201 if Length(chstr) < 1 then
7202 begin
7203 g_Console_Add('callvote <command>');
7204 Exit;
7205 end;
7207 if g_Game_IsClient then
7208 MC_SEND_Vote(True, chstr)
7209 else
7210 g_Game_StartVote(chstr, gPlayer1Settings.Name);
7211 g_Console_Process('vote', True);
7212 end
7213 else
7214 g_Console_Add('callvote <command>');
7215 end
7216 else if (cmd = 'vote') and g_Game_IsNet then
7217 begin
7218 if g_Game_IsClient then
7219 MC_SEND_Vote(False)
7220 else if gVoteInProgress then
7221 begin
7222 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
7223 a := Floor((NetClientCount+1)/2.0) + 1
7224 else
7225 a := Floor(NetClientCount/2.0) + 1;
7226 if gVoted then
7227 begin
7228 Dec(gVoteCount);
7229 gVoted := False;
7230 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_REVOKED], [gPlayer1Settings.Name, gVoteCount, a]), True);
7231 MH_SEND_VoteEvent(NET_VE_REVOKE, gPlayer1Settings.Name, 'a', gVoteCount, a);
7232 end
7233 else
7234 begin
7235 Inc(gVoteCount);
7236 gVoted := True;
7237 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_VOTE], [gPlayer1Settings.Name, gVoteCount, a]), True);
7238 MH_SEND_VoteEvent(NET_VE_VOTE, gPlayer1Settings.Name, 'a', gVoteCount, a);
7239 g_Game_CheckVote;
7240 end;
7241 end;
7242 end
7243 end;
7244 end;
7246 procedure g_TakeScreenShot;
7247 var s: TStream; t: TDateTime; dir, date, name: String;
7248 begin
7249 if e_NoGraphics then Exit;
7250 try
7251 t := Now;
7252 dir := e_GetWriteableDir(ScreenshotDirs);
7253 DateTimeToString(date, 'yyyy-mm-dd-hh-nn-ss', t);
7254 name := e_CatPath(dir, 'screenshot-' + date + '.png');
7255 s := createDiskFile(name);
7256 try
7257 e_MakeScreenshot(s, gScreenWidth, gScreenHeight);
7258 s.Free;
7259 g_Console_Add(Format(_lc[I_CONSOLE_SCREENSHOT], [name]))
7260 except
7261 g_Console_Add(Format(_lc[I_CONSOLE_ERROR_WRITE], [name]));
7262 s.Free;
7263 DeleteFile(name)
7264 end
7265 except
7266 g_Console_Add('oh shit, i can''t create screenshot!')
7267 end
7268 end;
7270 procedure g_Game_InGameMenu(Show: Boolean);
7271 begin
7272 if (g_ActiveWindow = nil) and Show then
7273 begin
7274 if gGameSettings.GameType = GT_SINGLE then
7275 g_GUI_ShowWindow('GameSingleMenu')
7276 else
7277 begin
7278 if g_Game_IsClient then
7279 g_GUI_ShowWindow('GameClientMenu')
7280 else
7281 if g_Game_IsNet then
7282 g_GUI_ShowWindow('GameServerMenu')
7283 else
7284 g_GUI_ShowWindow('GameCustomMenu');
7285 end;
7286 g_Sound_PlayEx('MENU_OPEN');
7288 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
7289 if (not g_Game_IsNet) then
7290 g_Game_Pause(True);
7291 end
7292 else
7293 if (g_ActiveWindow <> nil) and (not Show) then
7294 begin
7295 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
7296 if (not g_Game_IsNet) then
7297 g_Game_Pause(False);
7298 end;
7299 end;
7301 procedure g_Game_Pause (Enable: Boolean);
7302 var
7303 oldPause: Boolean;
7304 begin
7305 if not gGameOn then exit;
7307 if not (gGameSettings.GameType in [GT_SINGLE, GT_CUSTOM]) then exit;
7309 oldPause := gPause;
7310 gPauseMain := Enable;
7312 if (gPause <> oldPause) then g_Game_PauseAllSounds(gPause);
7313 end;
7315 procedure g_Game_HolmesPause (Enable: Boolean);
7316 var
7317 oldPause: Boolean;
7318 begin
7319 if not gGameOn then exit;
7320 if not (gGameSettings.GameType in [GT_SINGLE, GT_CUSTOM]) then exit;
7322 oldPause := gPause;
7323 gPauseHolmes := Enable;
7325 if (gPause <> oldPause) then g_Game_PauseAllSounds(gPause);
7326 end;
7328 procedure g_Game_PauseAllSounds(Enable: Boolean);
7329 var
7330 i: Integer;
7331 begin
7332 // Òðèããåðû:
7333 if gTriggers <> nil then
7334 for i := 0 to High(gTriggers) do
7335 with gTriggers[i] do
7336 if (TriggerType = TRIGGER_SOUND) and
7337 (Sound <> nil) and
7338 Sound.IsPlaying() then
7339 begin
7340 Sound.Pause(Enable);
7341 end;
7343 // Çâóêè èãðîêîâ:
7344 if gPlayers <> nil then
7345 for i := 0 to High(gPlayers) do
7346 if gPlayers[i] <> nil then
7347 gPlayers[i].PauseSounds(Enable);
7349 // Ìóçûêà:
7350 if gMusic <> nil then
7351 gMusic.Pause(Enable);
7352 end;
7354 procedure g_Game_StopAllSounds(all: Boolean);
7355 var
7356 i: Integer;
7357 begin
7358 if gTriggers <> nil then
7359 for i := 0 to High(gTriggers) do
7360 with gTriggers[i] do
7361 if (TriggerType = TRIGGER_SOUND) and
7362 (Sound <> nil) then
7363 Sound.Stop();
7365 if gMusic <> nil then
7366 gMusic.Stop();
7368 if all then
7369 e_StopChannels();
7370 end;
7372 procedure g_Game_UpdateTriggerSounds;
7373 var i: Integer;
7374 begin
7375 if gTriggers <> nil then
7376 for i := 0 to High(gTriggers) do
7377 with gTriggers[i] do
7378 if (TriggerType = TRIGGER_SOUND) and (Sound <> nil) and tgcLocal and Sound.IsPlaying() then
7379 Sound.SetCoordsRect(X, Y, Width, Height, tgcVolume / 255.0)
7380 end;
7382 function g_Game_IsWatchedPlayer(UID: Word): Boolean;
7383 begin
7384 Result := False;
7385 if (gPlayer1 <> nil) and (gPlayer1.UID = UID) then
7386 begin
7387 Result := True;
7388 Exit;
7389 end;
7390 if (gPlayer2 <> nil) and (gPlayer2.UID = UID) then
7391 begin
7392 Result := True;
7393 Exit;
7394 end;
7395 if gSpectMode <> SPECT_PLAYERS then
7396 Exit;
7397 if gSpectPID1 = UID then
7398 begin
7399 Result := True;
7400 Exit;
7401 end;
7402 if gSpectViewTwo and (gSpectPID2 = UID) then
7403 begin
7404 Result := True;
7405 Exit;
7406 end;
7407 end;
7409 function g_Game_IsWatchedTeam(Team: Byte): Boolean;
7410 var
7411 Pl: TPlayer;
7412 begin
7413 Result := False;
7414 if (gPlayer1 <> nil) and (gPlayer1.Team = Team) then
7415 begin
7416 Result := True;
7417 Exit;
7418 end;
7419 if (gPlayer2 <> nil) and (gPlayer2.Team = Team) then
7420 begin
7421 Result := True;
7422 Exit;
7423 end;
7424 if gSpectMode <> SPECT_PLAYERS then
7425 Exit;
7426 Pl := g_Player_Get(gSpectPID1);
7427 if (Pl <> nil) and (Pl.Team = Team) then
7428 begin
7429 Result := True;
7430 Exit;
7431 end;
7432 if gSpectViewTwo then
7433 begin
7434 Pl := g_Player_Get(gSpectPID2);
7435 if (Pl <> nil) and (Pl.Team = Team) then
7436 begin
7437 Result := True;
7438 Exit;
7439 end;
7440 end;
7441 end;
7443 procedure g_Game_Message(Msg: string; Time: Word);
7444 begin
7445 MessageLineLength := (gScreenWidth - 204) div e_CharFont_GetMaxWidth(gMenuFont);
7446 MessageText := b_Text_Wrap(b_Text_Format(Msg), MessageLineLength);
7447 MessageTime := Time;
7448 end;
7450 procedure g_Game_ChatSound(Text: String; Taunt: Boolean = True);
7451 const
7452 punct: Array[0..13] of String =
7453 ('.', ',', ':', ';', '!', '?', '(', ')', '''', '"', '/', '\', '*', '^');
7454 var
7455 i, j: Integer;
7456 ok: Boolean;
7457 fpText: String;
7459 function IsPunctuation(S: String): Boolean;
7460 var
7461 i: Integer;
7462 begin
7463 Result := False;
7464 if Length(S) <> 1 then
7465 Exit;
7466 for i := Low(punct) to High(punct) do
7467 if S = punct[i] then
7468 begin
7469 Result := True;
7470 break;
7471 end;
7472 end;
7473 function FilterPunctuation(S: String): String;
7474 var
7475 i: Integer;
7476 begin
7477 for i := Low(punct) to High(punct) do
7478 S := StringReplace(S, punct[i], ' ', [rfReplaceAll]);
7479 Result := S;
7480 end;
7481 begin
7482 ok := False;
7484 if gUseChatSounds and Taunt and (gChatSounds <> nil) and (Pos(': ', Text) > 0) then
7485 begin
7486 // remove player name
7487 Delete(Text, 1, Pos(': ', Text) + 2 - 1);
7488 // for FullWord check
7489 Text := toLowerCase1251(' ' + Text + ' ');
7490 fpText := FilterPunctuation(Text);
7492 for i := 0 to Length(gChatSounds) - 1 do
7493 begin
7494 ok := True;
7495 for j := 0 to Length(gChatSounds[i].Tags) - 1 do
7496 begin
7497 if gChatSounds[i].FullWord and (not IsPunctuation(gChatSounds[i].Tags[j])) then
7498 ok := Pos(' ' + gChatSounds[i].Tags[j] + ' ', fpText) > 0
7499 else
7500 ok := Pos(gChatSounds[i].Tags[j], Text) > 0;
7501 if not ok then
7502 break;
7503 end;
7504 if ok then
7505 begin
7506 gChatSounds[i].Sound.Play();
7507 break;
7508 end;
7509 end;
7510 end;
7511 if not ok then
7512 g_Sound_PlayEx('SOUND_GAME_RADIO');
7513 end;
7515 procedure g_Game_Announce_GoodShot(SpawnerUID: Word);
7516 var
7517 a: Integer;
7518 begin
7519 case gAnnouncer of
7520 ANNOUNCE_NONE:
7521 Exit;
7522 ANNOUNCE_ME,
7523 ANNOUNCE_MEPLUS:
7524 if not g_Game_IsWatchedPlayer(SpawnerUID) then
7525 Exit;
7526 end;
7527 for a := 0 to 3 do
7528 if goodsnd[a].IsPlaying() then
7529 Exit;
7531 goodsnd[Random(4)].Play();
7532 end;
7534 procedure g_Game_Announce_KillCombo(Param: Integer);
7535 var
7536 UID: Word;
7537 c, n: Byte;
7538 Pl: TPlayer;
7539 Name: String;
7540 begin
7541 UID := Param and $FFFF;
7542 c := Param shr 16;
7543 if c < 2 then
7544 Exit;
7546 Pl := g_Player_Get(UID);
7547 if Pl = nil then
7548 Name := '?'
7549 else
7550 Name := Pl.Name;
7552 case c of
7553 2: begin
7554 n := 0;
7555 g_Console_Add(Format(_lc[I_PLAYER_KILL_2X], [Name]), True);
7556 end;
7557 3: begin
7558 n := 1;
7559 g_Console_Add(Format(_lc[I_PLAYER_KILL_3X], [Name]), True);
7560 end;
7561 4: begin
7562 n := 2;
7563 g_Console_Add(Format(_lc[I_PLAYER_KILL_4X], [Name]), True);
7564 end;
7565 else begin
7566 n := 3;
7567 g_Console_Add(Format(_lc[I_PLAYER_KILL_MX], [Name]), True);
7568 end;
7569 end;
7571 case gAnnouncer of
7572 ANNOUNCE_NONE:
7573 Exit;
7574 ANNOUNCE_ME:
7575 if not g_Game_IsWatchedPlayer(UID) then
7576 Exit;
7577 ANNOUNCE_MEPLUS:
7578 if (not g_Game_IsWatchedPlayer(UID)) and (c < 4) then
7579 Exit;
7580 end;
7582 if killsnd[n].IsPlaying() then
7583 killsnd[n].Stop();
7584 killsnd[n].Play();
7585 end;
7587 procedure g_Game_Announce_BodyKill(SpawnerUID: Word);
7588 var
7589 a: Integer;
7590 begin
7591 case gAnnouncer of
7592 ANNOUNCE_NONE:
7593 Exit;
7594 ANNOUNCE_ME,
7595 ANNOUNCE_MEPLUS:
7596 if not g_Game_IsWatchedPlayer(SpawnerUID) then
7597 Exit;
7598 end;
7599 for a := 0 to 2 do
7600 if hahasnd[a].IsPlaying() then
7601 Exit;
7603 hahasnd[Random(3)].Play();
7604 end;
7606 procedure g_Game_StartVote(Command, Initiator: string);
7607 var
7608 Need: Integer;
7609 begin
7610 if not gVotesEnabled then Exit;
7611 if gGameSettings.GameType <> GT_SERVER then Exit;
7612 if gVoteInProgress or gVotePassed then
7613 begin
7614 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_INPROGRESS], [gVoteCommand]), True);
7615 MH_SEND_VoteEvent(NET_VE_INPROGRESS, gVoteCommand);
7616 Exit;
7617 end;
7618 gVoteInProgress := True;
7619 gVotePassed := False;
7620 gVoteTimer := gTime + gVoteTimeout * 1000;
7621 gVoteCount := 0;
7622 gVoted := False;
7623 gVoteCommand := Command;
7625 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
7626 Need := Floor((NetClientCount+1)/2.0)+1
7627 else
7628 Need := Floor(NetClientCount/2.0)+1;
7629 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_STARTED], [Initiator, Command, Need]), True);
7630 MH_SEND_VoteEvent(NET_VE_STARTED, Initiator, Command, Need);
7631 end;
7633 procedure g_Game_CheckVote;
7634 var
7635 I, Need: Integer;
7636 begin
7637 if gGameSettings.GameType <> GT_SERVER then Exit;
7638 if not gVoteInProgress then Exit;
7640 if (gTime >= gVoteTimer) then
7641 begin
7642 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
7643 Need := Floor((NetClientCount+1)/2.0) + 1
7644 else
7645 Need := Floor(NetClientCount/2.0) + 1;
7646 if gVoteCount >= Need then
7647 begin
7648 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_PASSED], [gVoteCommand]), True);
7649 MH_SEND_VoteEvent(NET_VE_PASSED, gVoteCommand);
7650 gVotePassed := True;
7651 gVoteCmdTimer := gTime + 5000;
7652 end
7653 else
7654 begin
7655 g_Console_Add(_lc[I_MESSAGE_VOTE_FAILED], True);
7656 MH_SEND_VoteEvent(NET_VE_FAILED);
7657 end;
7658 if NetClients <> nil then
7659 for I := Low(NetClients) to High(NetClients) do
7660 if NetClients[i].Used then
7661 NetClients[i].Voted := False;
7662 gVoteInProgress := False;
7663 gVoted := False;
7664 gVoteCount := 0;
7665 end
7666 else
7667 begin
7668 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
7669 Need := Floor((NetClientCount+1)/2.0) + 1
7670 else
7671 Need := Floor(NetClientCount/2.0) + 1;
7672 if gVoteCount >= Need then
7673 begin
7674 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_PASSED], [gVoteCommand]), True);
7675 MH_SEND_VoteEvent(NET_VE_PASSED, gVoteCommand);
7676 gVoteInProgress := False;
7677 gVotePassed := True;
7678 gVoteCmdTimer := gTime + 5000;
7679 gVoted := False;
7680 gVoteCount := 0;
7681 if NetClients <> nil then
7682 for I := Low(NetClients) to High(NetClients) do
7683 if NetClients[i].Used then
7684 NetClients[i].Voted := False;
7685 end;
7686 end;
7687 end;
7689 procedure g_Game_LoadMapList(FileName: string);
7690 var
7691 ListFile: TextFile;
7692 s: string;
7693 begin
7694 MapList := nil;
7695 MapIndex := -1;
7697 if not FileExists(FileName) then Exit;
7699 AssignFile(ListFile, FileName);
7700 Reset(ListFile);
7701 while not EOF(ListFile) do
7702 begin
7703 ReadLn(ListFile, s);
7705 s := Trim(s);
7706 if s = '' then Continue;
7708 SetLength(MapList, Length(MapList)+1);
7709 MapList[High(MapList)] := s;
7710 end;
7711 CloseFile(ListFile);
7712 end;
7714 procedure g_Game_SetDebugMode();
7715 begin
7716 gDebugMode := True;
7717 // ×èòû (äàæå â ñâîåé èãðå):
7718 gCheats := True;
7719 end;
7721 procedure g_Game_SetLoadingText(Text: String; Max: Integer; reWrite: Boolean);
7722 var
7723 i: Word;
7724 begin
7725 if Length(LoadingStat.Msgs) = 0 then
7726 Exit;
7728 with LoadingStat do
7729 begin
7730 if not reWrite then
7731 begin // Ïåðåõîäèì íà ñëåäóþùóþ ñòðîêó èëè ñêðîëëèðóåì:
7732 if NextMsg = Length(Msgs) then
7733 begin // scroll
7734 for i := 0 to High(Msgs)-1 do
7735 Msgs[i] := Msgs[i+1];
7736 end
7737 else
7738 Inc(NextMsg);
7739 end else
7740 if NextMsg = 0 then
7741 Inc(NextMsg);
7743 Msgs[NextMsg-1] := Text;
7744 CurValue := 0;
7745 MaxValue := Max;
7746 ShowCount := 0;
7747 PBarWasHere := false;
7748 end;
7750 g_ActiveWindow := nil;
7752 ProcessLoading(true);
7753 end;
7755 procedure g_Game_StepLoading(Value: Integer = -1);
7756 begin
7757 with LoadingStat do
7758 begin
7759 if Value = -1 then
7760 begin
7761 Inc(CurValue);
7762 Inc(ShowCount);
7763 end
7764 else
7765 CurValue := Value;
7766 if (ShowCount > LOADING_SHOW_STEP) or (Value > -1) then
7767 begin
7768 ShowCount := 0;
7769 ProcessLoading();
7770 end;
7771 end;
7772 end;
7774 procedure g_Game_ClearLoading();
7775 var
7776 len: Word;
7777 begin
7778 with LoadingStat do
7779 begin
7780 CurValue := 0;
7781 MaxValue := 0;
7782 ShowCount := 0;
7783 len := ((gScreenHeight div 3)*2 - 50) div LOADING_INTERLINE;
7784 if len < 1 then len := 1;
7785 SetLength(Msgs, len);
7786 for len := Low(Msgs) to High(Msgs) do
7787 Msgs[len] := '';
7788 NextMsg := 0;
7789 PBarWasHere := false;
7790 end;
7791 end;
7793 procedure Parse_Params(var pars: TParamStrValues);
7794 var
7795 i: Integer;
7796 s: String;
7797 begin
7798 SetLength(pars, 0);
7799 i := 1;
7800 while i <= ParamCount do
7801 begin
7802 s := ParamStr(i);
7803 if (s[1] = '-') and (Length(s) > 1) then
7804 begin
7805 if (s[2] = '-') and (Length(s) > 2) then
7806 begin // Îäèíî÷íûé ïàðàìåòð
7807 SetLength(pars, Length(pars) + 1);
7808 with pars[High(pars)] do
7809 begin
7810 Name := LowerCase(s);
7811 Value := '+';
7812 end;
7813 end
7814 else
7815 if (i < ParamCount) then
7816 begin // Ïàðàìåòð ñî çíà÷åíèåì
7817 Inc(i);
7818 SetLength(pars, Length(pars) + 1);
7819 with pars[High(pars)] do
7820 begin
7821 Name := LowerCase(s);
7822 Value := LowerCase(ParamStr(i));
7823 end;
7824 end;
7825 end;
7827 Inc(i);
7828 end;
7829 end;
7831 function Find_Param_Value(var pars: TParamStrValues; aName: String): String;
7832 var
7833 i: Integer;
7834 begin
7835 Result := '';
7836 for i := 0 to High(pars) do
7837 if pars[i].Name = aName then
7838 begin
7839 Result := pars[i].Value;
7840 Break;
7841 end;
7842 end;
7844 procedure g_Game_Process_Params();
7845 var
7846 pars: TParamStrValues;
7847 map: String;
7848 GMode, n: Byte;
7849 LimT, LimS: Integer;
7850 Opt: LongWord;
7851 Lives: Integer;
7852 s: String;
7853 Port: Integer;
7854 ip: String;
7855 F: TextFile;
7856 begin
7857 Parse_Params(pars);
7859 // Debug mode:
7860 s := Find_Param_Value(pars, '--debug');
7861 if (s <> '') then
7862 begin
7863 g_Game_SetDebugMode();
7864 s := Find_Param_Value(pars, '--netdump');
7865 if (s <> '') then
7866 NetDump := True;
7867 end;
7869 // Connect when game loads
7870 ip := Find_Param_Value(pars, '-connect');
7872 if ip <> '' then
7873 begin
7874 s := Find_Param_Value(pars, '-port');
7875 if (s = '') or not TryStrToInt(s, Port) then
7876 Port := 25666;
7878 s := Find_Param_Value(pars, '-pw');
7880 g_Game_StartClient(ip, Port, s);
7881 Exit;
7882 end;
7884 s := LowerCase(Find_Param_Value(pars, '-dbg-mainwad'));
7885 if (s <> '') then
7886 begin
7887 gDefaultMegawadStart := s;
7888 end;
7890 if (Find_Param_Value(pars, '--dbg-mainwad-restore') <> '') or
7891 (Find_Param_Value(pars, '--dbg-mainwad-default') <> '') then
7892 begin
7893 gDefaultMegawadStart := DF_Default_Megawad_Start;
7894 end;
7896 // Start map when game loads:
7897 map := LowerCase(Find_Param_Value(pars, '-map'));
7898 if isWadPath(map) then
7899 begin
7900 // Game mode:
7901 s := Find_Param_Value(pars, '-gm');
7902 GMode := g_Game_TextToMode(s);
7903 if GMode = GM_NONE then GMode := GM_DM;
7904 if GMode = GM_SINGLE then GMode := GM_COOP;
7906 // Time limit:
7907 s := Find_Param_Value(pars, '-limt');
7908 if (s = '') or (not TryStrToInt(s, LimT)) then
7909 LimT := 0;
7910 if LimT < 0 then
7911 LimT := 0;
7913 // Goal limit:
7914 s := Find_Param_Value(pars, '-lims');
7915 if (s = '') or (not TryStrToInt(s, LimS)) then
7916 LimS := 0;
7917 if LimS < 0 then
7918 LimS := 0;
7920 // Lives limit:
7921 s := Find_Param_Value(pars, '-lives');
7922 if (s = '') or (not TryStrToInt(s, Lives)) then
7923 Lives := 0;
7924 if Lives < 0 then
7925 Lives := 0;
7927 // Options:
7928 s := Find_Param_Value(pars, '-opt');
7929 if (s = '') then
7930 Opt := GAME_OPTION_ALLOWEXIT or GAME_OPTION_BOTVSPLAYER or GAME_OPTION_BOTVSMONSTER
7931 else
7932 Opt := StrToIntDef(s, 0);
7933 if Opt = 0 then
7934 Opt := GAME_OPTION_ALLOWEXIT or GAME_OPTION_BOTVSPLAYER or GAME_OPTION_BOTVSMONSTER;
7936 // Close after map:
7937 s := Find_Param_Value(pars, '--close');
7938 if (s <> '') then
7939 gMapOnce := True;
7941 // Override map to test:
7942 s := LowerCase(Find_Param_Value(pars, '-testmap'));
7943 if s <> '' then
7944 begin
7945 if e_IsValidResourceName(s) then
7946 e_FindResource(AllMapDirs, s);
7947 gTestMap := ExpandFileName(s);
7948 end;
7950 // Delete test map after play:
7951 s := Find_Param_Value(pars, '--testdelete');
7952 if (s <> '') then
7953 begin
7954 //gMapToDelete := MapsDir + map;
7955 e_WriteLog('"--testdelete" is deprecated, use --tempdelete.', TMsgType.Fatal);
7956 Halt(1);
7957 end;
7959 // Delete temporary WAD after play:
7960 s := Find_Param_Value(pars, '--tempdelete');
7961 if (s <> '') and (gTestMap <> '') then
7962 begin
7963 gMapToDelete := gTestMap;
7964 gTempDelete := True;
7965 end;
7967 // Number of players:
7968 s := Find_Param_Value(pars, '-pl');
7969 if (s = '') then
7970 n := DEFAULT_PLAYERS
7971 else
7972 n := StrToIntDef(s, DEFAULT_PLAYERS);
7974 // Start:
7975 s := Find_Param_Value(pars, '-port');
7976 if (s = '') or not TryStrToInt(s, Port) then
7977 g_Game_StartCustom(map, GMode, LimT, LimS, Lives, Opt, n)
7978 else
7979 g_Game_StartServer(map, GMode, LimT, LimS, Lives, Opt, n, 0, Port);
7980 end;
7982 // Execute script when game loads:
7983 s := Find_Param_Value(pars, '-exec');
7984 if s <> '' then
7985 begin
7986 // if not isWadPath(s) then
7987 // s := GameDir + '/' + s;
7989 {$I-}
7990 AssignFile(F, s);
7991 Reset(F);
7992 if IOResult <> 0 then
7993 begin
7994 e_WriteLog(Format(_lc[I_SIMPLE_ERROR], ['Failed to read file: ' + s]), TMsgType.Warning);
7995 g_Console_Add(Format(_lc[I_CONSOLE_ERROR_READ], [s]));
7996 CloseFile(F);
7997 Exit;
7998 end;
7999 e_WriteLog('Executing script: ' + s, TMsgType.Notify);
8000 g_Console_Add(Format(_lc[I_CONSOLE_EXEC], [s]));
8002 while not EOF(F) do
8003 begin
8004 ReadLn(F, s);
8005 if IOResult <> 0 then
8006 begin
8007 e_WriteLog(Format(_lc[I_SIMPLE_ERROR], ['Failed to read file: ' + s]), TMsgType.Warning);
8008 g_Console_Add(Format(_lc[I_CONSOLE_ERROR_READ], [s]));
8009 CloseFile(F);
8010 Exit;
8011 end;
8012 if Pos('#', s) <> 1 then // script comment
8013 g_Console_Process(s, True);
8014 end;
8016 CloseFile(F);
8017 {$I+}
8018 end;
8020 SetLength(pars, 0);
8021 end;
8023 begin
8024 conRegVar('pf_draw_frame', @g_profile_frame_draw, 'draw frame rendering profiles', 'render profiles');
8025 //conRegVar('pf_update_frame', @g_profile_frame_update, 'draw frame updating profiles', 'update profiles');
8026 conRegVar('pf_coldet', @g_profile_collision, 'draw collision detection profiles', 'coldet profiles');
8027 conRegVar('pf_los', @g_profile_los, 'draw monster LOS profiles', 'monster LOS profiles');
8029 conRegVar('r_sq_draw', @gdbg_map_use_accel_render, 'accelerated spatial queries in rendering', 'accelerated rendering');
8030 conRegVar('cd_sq_enabled', @gdbg_map_use_accel_coldet, 'accelerated spatial queries in map coldet', 'accelerated map coldet');
8031 conRegVar('mon_sq_enabled', @gmon_debug_use_sqaccel, 'accelerated spatial queries for monsters', 'accelerated monster coldet');
8032 conRegVar('wtrace_sq_enabled', @gwep_debug_fast_trace, 'accelerated spatial queries for weapon hitscan trace', 'accelerated weapon hitscan');
8034 conRegVar('pr_enabled', @gpart_dbg_enabled, 'enable/disable particles', 'particles');
8035 conRegVar('pr_phys_enabled', @gpart_dbg_phys_enabled, 'enable/disable particle physics', 'particle physics');
8037 conRegVar('los_enabled', @gmon_dbg_los_enabled, 'enable/disable monster LOS calculations', 'monster LOS', true);
8038 conRegVar('mon_think', @gmon_debug_think, 'enable/disable monster thinking', 'monster thinking', true);
8040 {$IFDEF ENABLE_HOLMES}
8041 conRegVar('dbg_holmes', @g_holmes_enabled, 'enable/disable Holmes', 'Holmes', true);
8042 {$ENDIF}
8044 conRegVar('dbg_ignore_level_bounds', @g_dbg_ignore_bounds, 'ignore level bounds', '', false);
8046 conRegVar('r_scale', @g_dbg_scale, 0.01, 100.0, 'render scale', '', false);
8048 conRegVar('light_enabled', @gwin_k8_enable_light_experiments, 'enable/disable dynamic lighting', 'lighting');
8049 conRegVar('light_player_halo', @g_playerLight, 'enable/disable player halo', 'player light halo');
8051 conRegVar('r_smallmap_align_h', @r_smallmap_h, 'halign: 0: left; 1: center; 2: right', 'horizontal aligning of small maps');
8052 conRegVar('r_smallmap_align_v', @r_smallmap_v, 'valign: 0: top; 1: center; 2: bottom', 'vertial aligning of small maps');
8054 conRegVar('r_showfps', @gShowFPS, 'draw fps counter', 'draw fps counter');
8055 conRegVar('r_showtime', @gShowTime, 'show game time', 'show game time');
8056 end.