DEADSOFTWARE

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