DEADSOFTWARE

net: mostly restored master-comm logic
[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 // process master server communications
1681 g_Net_Slist_Pulse();
1683 case gState of
1684 STATE_INTERSINGLE, // Ñòàòèñòêà ïîñëå ïðîõîæäåíèÿ óðîâíÿ â Îäèíî÷íîé èãðå
1685 STATE_INTERCUSTOM, // Ñòàòèñòêà ïîñëå ïðîõîæäåíèÿ óðîâíÿ â Ñâîåé èãðå
1686 STATE_INTERTEXT, // Òåêñò ìåæäó óðîâíÿìè
1687 STATE_INTERPIC: // Êàðòèíêà ìåæäó óðîâíÿìè
1688 begin
1689 if g_Game_IsNet and g_Game_IsServer then
1690 begin
1691 gInterTime := gInterTime + GAME_TICK;
1692 a := Min((gInterEndTime - gInterTime) div 1000 + 1, 255);
1693 if a <> gServInterTime then
1694 begin
1695 gServInterTime := a;
1696 MH_SEND_TimeSync(gServInterTime);
1697 end;
1698 end;
1700 if (not g_Game_IsClient) and
1704 e_KeyPressed(IK_RETURN) or e_KeyPressed(IK_KPRETURN) or e_KeyPressed(IK_SPACE) or
1705 e_KeyPressed(VK_FIRE) or e_KeyPressed(VK_OPEN) or
1706 e_KeyPressed(JOY0_ATTACK) or e_KeyPressed(JOY1_ATTACK) or
1707 e_KeyPressed(JOY2_ATTACK) or e_KeyPressed(JOY3_ATTACK)
1709 and (not gJustChatted) and (not gConsoleShow) and (not gChatShow)
1710 and (g_ActiveWindow = nil)
1712 or (g_Game_IsNet and ((gInterTime > gInterEndTime) or (gInterReadyCount >= NetClientCount)))
1714 then
1715 begin // Íàæàëè <Enter>/<Ïðîáåë> èëè ïðîøëî äîñòàòî÷íî âðåìåíè:
1716 g_Game_StopAllSounds(True);
1718 if gMapOnce then // Ýòî áûë òåñò
1719 gExit := EXIT_SIMPLE
1720 else
1721 if gNextMap <> '' then // Ïåðåõîäèì íà ñëåäóþùóþ êàðòó
1722 g_Game_ChangeMap(gNextMap)
1723 else // Ñëåäóþùåé êàðòû íåò
1724 begin
1725 if gGameSettings.GameType in [GT_CUSTOM, GT_SERVER] then
1726 begin
1727 // Âûõîä â ãëàâíîå ìåíþ:
1728 g_Game_Free;
1729 g_GUI_ShowWindow('MainMenu');
1730 gMusic.SetByName('MUSIC_MENU');
1731 gMusic.Play();
1732 gState := STATE_MENU;
1733 end else
1734 begin
1735 // Ôèíàëüíàÿ êàðòèíêà:
1736 g_Game_ExecuteEvent('onwadend');
1737 g_Game_Free();
1738 if not gMusic.SetByName('MUSIC_endmus') then
1739 gMusic.SetByName('MUSIC_STDENDMUS');
1740 gMusic.Play();
1741 gState := STATE_ENDPIC;
1742 end;
1743 g_Game_ExecuteEvent('ongameend');
1744 end;
1746 Exit;
1747 end
1748 else if g_Game_IsClient and
1751 e_KeyPressed(IK_RETURN) or e_KeyPressed(IK_KPRETURN) or e_KeyPressed(IK_SPACE) or
1752 e_KeyPressed(VK_FIRE) or e_KeyPressed(VK_OPEN) or
1753 e_KeyPressed(JOY0_ATTACK) or e_KeyPressed(JOY1_ATTACK) or
1754 e_KeyPressed(JOY2_ATTACK) or e_KeyPressed(JOY3_ATTACK)
1756 and (not gJustChatted) and (not gConsoleShow) and (not gChatShow)
1757 and (g_ActiveWindow = nil)
1759 then
1760 begin
1761 // ready / unready
1762 InterReady();
1763 end;
1765 if gState = STATE_INTERTEXT then
1766 if InterText.counter > 0 then
1767 InterText.counter := InterText.counter - 1;
1768 end;
1770 STATE_FOLD: // Çàòóõàíèå ýêðàíà
1771 begin
1772 if EndingGameCounter = 0 then
1773 begin
1774 // Çàêîí÷èëñÿ óðîâåíü â Ñâîåé èãðå:
1775 if gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT] then
1776 begin
1777 InterReadyTime := -1;
1778 if gLastMap and (gGameSettings.GameMode = GM_COOP) then
1779 begin
1780 g_Game_ExecuteEvent('onwadend');
1781 if not gMusic.SetByName('MUSIC_endmus') then
1782 gMusic.SetByName('MUSIC_STDENDMUS');
1783 end
1784 else
1785 gMusic.SetByName('MUSIC_ROUNDMUS');
1787 gMusic.Play();
1788 gState := STATE_INTERCUSTOM;
1789 e_UnpressAllKeys();
1790 end
1791 else // Çàêîí÷èëàñü ïîñëåäíÿÿ êàðòà â Îäèíî÷íîé èãðå
1792 begin
1793 gMusic.SetByName('MUSIC_INTERMUS');
1794 gMusic.Play();
1795 gState := STATE_INTERSINGLE;
1796 e_UnpressAllKeys();
1797 end;
1798 g_Game_ExecuteEvent('oninter');
1799 end
1800 else
1801 DecMin(EndingGameCounter, 6, 0);
1802 end;
1804 STATE_ENDPIC: // Êàðòèíêà îêîí÷àíèÿ ìåãàÂàäà
1805 begin
1806 if gMapOnce then // Ýòî áûë òåñò
1807 begin
1808 gExit := EXIT_SIMPLE;
1809 Exit;
1810 end;
1811 end;
1813 STATE_SLIST:
1814 g_Serverlist_Control(slCurrent, slTable);
1815 end;
1817 // Ñòàòèñòèêà ïî Tab:
1818 if gGameOn then
1819 IsDrawStat := (not gConsoleShow) and (not gChatShow) and (gGameSettings.GameType <> GT_SINGLE) and g_Console_Action(ACTION_SCORES);
1821 // Èãðà èäåò:
1822 if gGameOn and not gPause and (gState <> STATE_FOLD) then
1823 begin
1824 // Âðåìÿ += 28 ìèëëèñåêóíä:
1825 gTime := gTime + GAME_TICK;
1827 // Ñîîáùåíèå ïîñåðåäèíå ýêðàíà:
1828 if MessageTime = 0 then
1829 MessageText := '';
1830 if MessageTime > 0 then
1831 MessageTime := MessageTime - 1;
1833 if (g_Game_IsServer) then
1834 begin
1835 // Áûë çàäàí ëèìèò âðåìåíè:
1836 if (gGameSettings.TimeLimit > 0) then
1837 if (gTime - gGameStartTime) div 1000 >= gGameSettings.TimeLimit then
1838 begin // Îí ïðîøåë => êîíåö óðîâíÿ
1839 g_Game_NextLevel();
1840 Exit;
1841 end;
1843 // Íàäî ðåñïàâíèòü èãðîêîâ â LMS:
1844 if (gLMSRespawn > LMS_RESPAWN_NONE) and (gLMSRespawnTime < gTime) then
1845 g_Game_RestartRound(gLMSSoftSpawn);
1847 // Ïðîâåðèì ðåçóëüòàò ãîëîñîâàíèÿ, åñëè âðåìÿ ïðîøëî
1848 if gVoteInProgress and (gVoteTimer < gTime) then
1849 g_Game_CheckVote
1850 else if gVotePassed and (gVoteCmdTimer < gTime) then
1851 begin
1852 g_Console_Process(gVoteCommand);
1853 gVoteCommand := '';
1854 gVotePassed := False;
1855 end;
1857 // Çàìåðÿåì âðåìÿ çàõâàòà ôëàãîâ
1858 if gFlags[FLAG_RED].State = FLAG_STATE_CAPTURED then
1859 gFlags[FLAG_RED].CaptureTime := gFlags[FLAG_RED].CaptureTime + GAME_TICK;
1860 if gFlags[FLAG_BLUE].State = FLAG_STATE_CAPTURED then
1861 gFlags[FLAG_BLUE].CaptureTime := gFlags[FLAG_BLUE].CaptureTime + GAME_TICK;
1863 // Áûë çàäàí ëèìèò ïîáåä:
1864 if (gGameSettings.GoalLimit > 0) then
1865 begin
1866 b := 0;
1868 if gGameSettings.GameMode = GM_DM then
1869 begin // Â DM èùåì èãðîêà ñ max ôðàãàìè
1870 for i := 0 to High(gPlayers) do
1871 if gPlayers[i] <> nil then
1872 if gPlayers[i].Frags > b then
1873 b := gPlayers[i].Frags;
1874 end
1875 else
1876 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
1877 begin //  CTF/TDM âûáèðàåì êîìàíäó ñ íàèáîëüøèì ñ÷åòîì
1878 b := Max(gTeamStat[TEAM_RED].Goals, gTeamStat[TEAM_BLUE].Goals);
1879 end;
1881 // Ëèìèò ïîáåä íàáðàí => êîíåö óðîâíÿ:
1882 if b >= gGameSettings.GoalLimit then
1883 begin
1884 g_Game_NextLevel();
1885 Exit;
1886 end;
1887 end;
1889 // Îáðàáàòûâàåì êëàâèøè èãðîêîâ:
1890 if gPlayer1 <> nil then gPlayer1.ReleaseKeys();
1891 if gPlayer2 <> nil then gPlayer2.ReleaseKeys();
1892 if (not gConsoleShow) and (not gChatShow) and (g_ActiveWindow = nil) then
1893 begin
1894 ProcessPlayerControls(gPlayer1, 0, P1MoveButton);
1895 ProcessPlayerControls(gPlayer2, 1, P2MoveButton);
1896 end // if not console
1897 else
1898 begin
1899 if g_Game_IsNet and (gPlayer1 <> nil) then gPlayer1.PressKey(KEY_CHAT, 10000);
1900 end;
1901 // process weapon switch queue
1902 end; // if server
1904 // Íàáëþäàòåëü
1905 if (gPlayer1 = nil) and (gPlayer2 = nil) and
1906 (not gConsoleShow) and (not gChatShow) and (g_ActiveWindow = nil) then
1907 begin
1908 if not gSpectKeyPress then
1909 begin
1910 if gPlayerAction[0, ACTION_JUMP] and (not gSpectAuto) then
1911 begin
1912 // switch spect mode
1913 case gSpectMode of
1914 SPECT_NONE: ; // not spectator
1915 SPECT_STATS,
1916 SPECT_MAPVIEW: Inc(gSpectMode);
1917 SPECT_PLAYERS: gSpectMode := SPECT_STATS; // reset to 1
1918 end;
1919 gSpectKeyPress := True;
1920 end;
1921 if (gSpectMode = SPECT_MAPVIEW)
1922 and (not gSpectAuto) then
1923 begin
1924 if gPlayerAction[0, ACTION_MOVELEFT] then
1925 gSpectX := Max(gSpectX - gSpectStep, 0);
1926 if gPlayerAction[0, ACTION_MOVERIGHT] then
1927 gSpectX := Min(gSpectX + gSpectStep, gMapInfo.Width - gScreenWidth);
1928 if gPlayerAction[0, ACTION_LOOKUP] then
1929 gSpectY := Max(gSpectY - gSpectStep, 0);
1930 if gPlayerAction[0, ACTION_LOOKDOWN] then
1931 gSpectY := Min(gSpectY + gSpectStep, gMapInfo.Height - gScreenHeight);
1932 if gPlayerAction[0, ACTION_WEAPPREV] then
1933 begin
1934 // decrease step
1935 if gSpectStep > 4 then gSpectStep := gSpectStep shr 1;
1936 gSpectKeyPress := True;
1937 end;
1938 if gPlayerAction[0, ACTION_WEAPNEXT] then
1939 begin
1940 // increase step
1941 if gSpectStep < 64 then gSpectStep := gSpectStep shl 1;
1942 gSpectKeyPress := True;
1943 end;
1944 end;
1945 if (gSpectMode = SPECT_PLAYERS)
1946 and (not gSpectAuto) then
1947 begin
1948 if gPlayerAction[0, ACTION_LOOKUP] then
1949 begin
1950 // add second view
1951 gSpectViewTwo := True;
1952 gSpectKeyPress := True;
1953 end;
1954 if gPlayerAction[0, ACTION_LOOKDOWN] then
1955 begin
1956 // remove second view
1957 gSpectViewTwo := False;
1958 gSpectKeyPress := True;
1959 end;
1960 if gPlayerAction[0, ACTION_MOVELEFT] then
1961 begin
1962 // prev player (view 1)
1963 gSpectPID1 := GetActivePlayerID_Prev(gSpectPID1);
1964 gSpectKeyPress := True;
1965 end;
1966 if gPlayerAction[0, ACTION_MOVERIGHT] then
1967 begin
1968 // next player (view 1)
1969 gSpectPID1 := GetActivePlayerID_Next(gSpectPID1);
1970 gSpectKeyPress := True;
1971 end;
1972 if gPlayerAction[0, ACTION_WEAPPREV] then
1973 begin
1974 // prev player (view 2)
1975 gSpectPID2 := GetActivePlayerID_Prev(gSpectPID2);
1976 gSpectKeyPress := True;
1977 end;
1978 if gPlayerAction[0, ACTION_WEAPNEXT] then
1979 begin
1980 // next player (view 2)
1981 gSpectPID2 := GetActivePlayerID_Next(gSpectPID2);
1982 gSpectKeyPress := True;
1983 end;
1984 end;
1985 if gPlayerAction[0, ACTION_ATTACK] then
1986 begin
1987 if (gSpectMode = SPECT_STATS) and (not gSpectAuto) then
1988 begin
1989 gSpectAuto := True;
1990 gSpectAutoNext := 0;
1991 gSpectViewTwo := False;
1992 gSpectKeyPress := True;
1993 end
1994 else
1995 if gSpectAuto then
1996 begin
1997 gSpectMode := SPECT_STATS;
1998 gSpectAuto := False;
1999 gSpectKeyPress := True;
2000 end;
2001 end;
2002 end
2003 else
2004 if (not gPlayerAction[0, ACTION_JUMP]) and
2005 (not gPlayerAction[0, ACTION_ATTACK]) and
2006 (not gPlayerAction[0, ACTION_MOVELEFT]) and
2007 (not gPlayerAction[0, ACTION_MOVERIGHT]) and
2008 (not gPlayerAction[0, ACTION_LOOKUP]) and
2009 (not gPlayerAction[0, ACTION_LOOKDOWN]) and
2010 (not gPlayerAction[0, ACTION_WEAPPREV]) and
2011 (not gPlayerAction[0, ACTION_WEAPNEXT]) then
2012 gSpectKeyPress := False;
2014 if gSpectAuto then
2015 begin
2016 if gSpectMode = SPECT_MAPVIEW then
2017 begin
2018 i := Min(Max(gSpectX + gSpectAutoStepX, 0), gMapInfo.Width - gScreenWidth);
2019 if i = gSpectX then
2020 gSpectAutoNext := gTime
2021 else
2022 gSpectX := i;
2023 i := Min(Max(gSpectY + gSpectAutoStepY, 0), gMapInfo.Height - gScreenHeight);
2024 if i = gSpectY then
2025 gSpectAutoNext := gTime
2026 else
2027 gSpectY := i;
2028 end;
2029 if gSpectAutoNext <= gTime then
2030 begin
2031 if gSpectAutoNext > 0 then
2032 begin
2033 gSpectMode := GetRandomSpectMode(gSpectMode);
2034 case gSpectMode of
2035 SPECT_MAPVIEW:
2036 begin
2037 gSpectX := Random(gMapInfo.Width - gScreenWidth);
2038 gSpectY := Random(gMapInfo.Height - gScreenHeight);
2039 gSpectAutoStepX := Random(9) - 4;
2040 gSpectAutoStepY := Random(9) - 4;
2041 if ((gSpectX < 800) and (gSpectAutoStepX < 0)) or
2042 ((gSpectX > gMapInfo.Width - gScreenWidth - 800) and (gSpectAutoStepX > 0)) then
2043 gSpectAutoStepX := gSpectAutoStepX * -1;
2044 if ((gSpectY < 800) and (gSpectAutoStepY < 0)) or
2045 ((gSpectY > gMapInfo.Height - gScreenHeight - 800) and (gSpectAutoStepY > 0)) then
2046 gSpectAutoStepY := gSpectAutoStepY * -1;
2047 end;
2048 SPECT_PLAYERS:
2049 begin
2050 gSpectPID1 := GetActivePlayerID_Random(gSpectPID1);
2051 end;
2052 end;
2053 end;
2054 case gSpectMode of
2055 SPECT_STATS: gSpectAutoNext := gTime + (Random(3) + 5) * 1000;
2056 SPECT_MAPVIEW: gSpectAutoNext := gTime + (Random(4) + 7) * 1000;
2057 SPECT_PLAYERS: gSpectAutoNext := gTime + (Random(7) + 8) * 1000;
2058 end;
2059 end;
2060 end;
2061 end;
2063 // Îáíîâëÿåì âñå îñòàëüíîå:
2064 g_Map_Update();
2065 g_Items_Update();
2066 g_Triggers_Update();
2067 g_Weapon_Update();
2068 g_Monsters_Update();
2069 g_GFX_Update();
2070 g_Player_UpdateAll();
2071 g_Player_UpdatePhysicalObjects();
2073 // server: send newly spawned monsters unconditionally
2074 if (gGameSettings.GameType = GT_SERVER) then
2075 begin
2076 if (Length(gMonstersSpawned) > 0) then
2077 begin
2078 for I := 0 to High(gMonstersSpawned) do MH_SEND_MonsterSpawn(gMonstersSpawned[I]);
2079 SetLength(gMonstersSpawned, 0);
2080 end;
2081 end;
2083 if (gSoundTriggerTime > 8) then
2084 begin
2085 g_Game_UpdateTriggerSounds();
2086 gSoundTriggerTime := 0;
2087 end
2088 else
2089 begin
2090 Inc(gSoundTriggerTime);
2091 end;
2093 if (NetMode = NET_SERVER) then
2094 begin
2095 Inc(NetTimeToUpdate);
2096 Inc(NetTimeToReliable);
2098 // send monster updates
2099 if (NetTimeToReliable >= NetRelupdRate) or (NetTimeToUpdate >= NetUpdateRate) then
2100 begin
2101 // send all monsters (periodic sync)
2102 reliableUpdate := (NetTimeToReliable >= NetRelupdRate);
2104 for I := 0 to High(gPlayers) do
2105 begin
2106 if (gPlayers[I] <> nil) then MH_SEND_PlayerPos(reliableUpdate, gPlayers[I].UID);
2107 end;
2109 g_Mons_ForEach(sendMonsPos);
2111 if reliableUpdate then
2112 begin
2113 NetTimeToReliable := 0;
2114 NetTimeToUpdate := NetUpdateRate;
2115 end
2116 else
2117 begin
2118 NetTimeToUpdate := 0;
2119 end;
2120 end
2121 else
2122 begin
2123 // send only mosters with some unexpected changes
2124 g_Mons_ForEach(sendMonsPosUnexpected);
2125 end;
2127 // send unexpected platform changes
2128 g_Map_NetSendInterestingPanels();
2130 g_Net_Slist_ServerUpdate();
2132 if NetUseMaster then
2133 begin
2134 if (gTime >= NetTimeToMaster) or g_Net_Slist_IsConnectionInProgress then
2135 begin
2136 if (not g_Net_Slist_IsConnectionActive) then g_Net_Slist_Connect(false); // non-blocking connection to the master
2137 g_Net_Slist_Update;
2138 NetTimeToMaster := gTime + NetMasterRate;
2139 end;
2140 end;
2142 end
2143 else if (NetMode = NET_CLIENT) then
2144 begin
2145 MC_SEND_PlayerPos();
2146 end;
2147 end; // if gameOn ...
2149 // Àêòèâíî îêíî èíòåðôåéñà - ïåðåäàåì êëàâèøè åìó:
2150 if g_ActiveWindow <> nil then
2151 begin
2152 w := e_GetFirstKeyPressed();
2154 if (w <> IK_INVALID) then
2155 begin
2156 Msg.Msg := MESSAGE_DIKEY;
2157 Msg.wParam := w;
2158 g_ActiveWindow.OnMessage(Msg);
2159 end;
2161 // Åñëè îíî îò ýòîãî íå çàêðûëîñü, òî îáíîâëÿåì:
2162 if g_ActiveWindow <> nil then
2163 g_ActiveWindow.Update();
2165 // Íóæíî ñìåíèòü ðàçðåøåíèå:
2166 if gResolutionChange then
2167 begin
2168 e_WriteLog('Changing resolution', TMsgType.Notify);
2169 g_Game_ChangeResolution(gRC_Width, gRC_Height, gRC_FullScreen, gRC_Maximized);
2170 gResolutionChange := False;
2171 g_ActiveWindow := nil;
2172 end;
2174 // Íóæíî ñìåíèòü ÿçûê:
2175 if gLanguageChange then
2176 begin
2177 //e_WriteLog('Read language file', MSG_NOTIFY);
2178 //g_Language_Load(DataDir + gLanguage + '.txt');
2179 g_Language_Set(gLanguage);
2180 {$IFNDEF HEADLESS}
2181 g_Menu_Reset();
2182 {$ENDIF}
2183 gLanguageChange := False;
2184 end;
2185 end;
2187 // Ãîðÿ÷àÿ êëàâèøà äëÿ âûçîâà ìåíþ âûõîäà èç èãðû (F10):
2188 if e_KeyPressed(IK_F10) and
2189 gGameOn and
2190 (not gConsoleShow) and
2191 (g_ActiveWindow = nil) then
2192 begin
2193 KeyPress(IK_F10);
2194 end;
2196 Time := sys_GetTicks() {div 1000};
2198 // Îáðàáîòêà îòëîæåííûõ ñîáûòèé:
2199 if gDelayedEvents <> nil then
2200 for a := 0 to High(gDelayedEvents) do
2201 if gDelayedEvents[a].Pending and
2203 ((gDelayedEvents[a].DEType = DE_GLOBEVENT) and (gDelayedEvents[a].Time <= Time)) or
2204 ((gDelayedEvents[a].DEType > DE_GLOBEVENT) and (gDelayedEvents[a].Time <= gTime))
2205 ) then
2206 begin
2207 case gDelayedEvents[a].DEType of
2208 DE_GLOBEVENT:
2209 g_Game_ExecuteEvent(gDelayedEvents[a].DEStr);
2210 DE_BFGHIT:
2211 if gGameOn then
2212 g_Game_Announce_GoodShot(gDelayedEvents[a].DENum);
2213 DE_KILLCOMBO:
2214 if gGameOn then
2215 begin
2216 g_Game_Announce_KillCombo(gDelayedEvents[a].DENum);
2217 if g_Game_IsNet and g_Game_IsServer then
2218 MH_SEND_GameEvent(NET_EV_KILLCOMBO, gDelayedEvents[a].DENum);
2219 end;
2220 DE_BODYKILL:
2221 if gGameOn then
2222 g_Game_Announce_BodyKill(gDelayedEvents[a].DENum);
2223 end;
2224 gDelayedEvents[a].Pending := False;
2225 end;
2227 // Êàæäóþ ñåêóíäó îáíîâëÿåì ñ÷åò÷èê îáíîâëåíèé:
2228 UPSCounter := UPSCounter + 1;
2229 if Time - UPSTime >= 1000 then
2230 begin
2231 UPS := UPSCounter;
2232 UPSCounter := 0;
2233 UPSTime := Time;
2234 end;
2236 if gGameOn then
2237 begin
2238 g_Weapon_AddDynLights();
2239 g_Items_AddDynLights();
2240 end;
2241 end;
2243 procedure g_Game_LoadChatSounds(Resource: string);
2244 var
2245 WAD: TWADFile;
2246 FileName, Snd: string;
2247 p: Pointer;
2248 len, cnt, tags, i, j: Integer;
2249 cfg: TConfig;
2250 begin
2251 FileName := g_ExtractWadName(Resource);
2253 WAD := TWADFile.Create();
2254 WAD.ReadFile(FileName);
2256 if not WAD.GetResource(g_ExtractFilePathName(Resource), p, len) then
2257 begin
2258 gChatSounds := nil;
2259 WAD.Free();
2260 Exit;
2261 end;
2263 cfg := TConfig.CreateMem(p, len);
2264 cnt := cfg.ReadInt('ChatSounds', 'Count', 0);
2266 SetLength(gChatSounds, cnt);
2267 for i := 0 to Length(gChatSounds) - 1 do
2268 begin
2269 gChatSounds[i].Sound := nil;
2270 Snd := Trim(cfg.ReadStr(IntToStr(i), 'Sound', ''));
2271 tags := cfg.ReadInt(IntToStr(i), 'Tags', 0);
2272 if (Snd = '') or (Tags <= 0) then
2273 continue;
2274 g_Sound_CreateWADEx('SOUND_CHAT_MACRO' + IntToStr(i), GameWAD+':'+Snd);
2275 gChatSounds[i].Sound := TPlayableSound.Create();
2276 gChatSounds[i].Sound.SetByName('SOUND_CHAT_MACRO' + IntToStr(i));
2277 SetLength(gChatSounds[i].Tags, tags);
2278 for j := 0 to tags - 1 do
2279 gChatSounds[i].Tags[j] := toLowerCase1251(cfg.ReadStr(IntToStr(i), 'Tag' + IntToStr(j), ''));
2280 gChatSounds[i].FullWord := cfg.ReadBool(IntToStr(i), 'FullWord', False);
2281 end;
2283 cfg.Free();
2284 WAD.Free();
2285 end;
2287 procedure g_Game_FreeChatSounds();
2288 var
2289 i: Integer;
2290 begin
2291 for i := 0 to Length(gChatSounds) - 1 do
2292 begin
2293 gChatSounds[i].Sound.Free();
2294 g_Sound_Delete('SOUND_CHAT_MACRO' + IntToStr(i));
2295 end;
2296 SetLength(gChatSounds, 0);
2297 gChatSounds := nil;
2298 end;
2300 procedure g_Game_LoadData();
2301 var
2302 wl, hl: Integer;
2303 wr, hr: Integer;
2304 wb, hb: Integer;
2305 wm, hm: Integer;
2306 begin
2307 if DataLoaded then Exit;
2309 e_WriteLog('Loading game data...', TMsgType.Notify);
2311 g_Texture_CreateWADEx('NOTEXTURE', GameWAD+':TEXTURES\NOTEXTURE');
2312 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUD', GameWAD+':TEXTURES\HUD');
2313 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDAIR', GameWAD+':TEXTURES\AIRBAR');
2314 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDJET', GameWAD+':TEXTURES\JETBAR');
2315 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDBG', GameWAD+':TEXTURES\HUDBG');
2316 g_Texture_CreateWADEx('TEXTURE_PLAYER_ARMORHUD', GameWAD+':TEXTURES\ARMORHUD');
2317 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG', GameWAD+':TEXTURES\FLAGHUD_R_BASE');
2318 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_S', GameWAD+':TEXTURES\FLAGHUD_R_STOLEN');
2319 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_D', GameWAD+':TEXTURES\FLAGHUD_R_DROP');
2320 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG', GameWAD+':TEXTURES\FLAGHUD_B_BASE');
2321 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_S', GameWAD+':TEXTURES\FLAGHUD_B_STOLEN');
2322 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_D', GameWAD+':TEXTURES\FLAGHUD_B_DROP');
2323 g_Texture_CreateWADEx('TEXTURE_PLAYER_TALKBUBBLE', GameWAD+':TEXTURES\TALKBUBBLE');
2324 g_Texture_CreateWADEx('TEXTURE_PLAYER_INVULPENTA', GameWAD+':TEXTURES\PENTA');
2325 g_Texture_CreateWADEx('TEXTURE_PLAYER_INDICATOR', GameWAD+':TEXTURES\PLRIND');
2327 hasPBarGfx := true;
2328 if not g_Texture_CreateWADEx('UI_GFX_PBAR_LEFT', GameWAD+':TEXTURES\LLEFT') then hasPBarGfx := false;
2329 if not g_Texture_CreateWADEx('UI_GFX_PBAR_MARKER', GameWAD+':TEXTURES\LMARKER') then hasPBarGfx := false;
2330 if not g_Texture_CreateWADEx('UI_GFX_PBAR_MIDDLE', GameWAD+':TEXTURES\LMIDDLE') then hasPBarGfx := false;
2331 if not g_Texture_CreateWADEx('UI_GFX_PBAR_RIGHT', GameWAD+':TEXTURES\LRIGHT') then hasPBarGfx := false;
2333 if hasPBarGfx then
2334 begin
2335 g_Texture_GetSize('UI_GFX_PBAR_LEFT', wl, hl);
2336 g_Texture_GetSize('UI_GFX_PBAR_RIGHT', wr, hr);
2337 g_Texture_GetSize('UI_GFX_PBAR_MIDDLE', wb, hb);
2338 g_Texture_GetSize('UI_GFX_PBAR_MARKER', wm, hm);
2339 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
2340 begin
2341 // yay!
2342 end
2343 else
2344 begin
2345 hasPBarGfx := false;
2346 end;
2347 end;
2349 g_Frames_CreateWAD(nil, 'FRAMES_TELEPORT', GameWAD+':TEXTURES\TELEPORT', 64, 64, 10, False);
2350 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH', GameWAD+':WEAPONS\PUNCH', 64, 64, 4, False);
2351 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_UP', GameWAD+':WEAPONS\PUNCH_UP', 64, 64, 4, False);
2352 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_DN', GameWAD+':WEAPONS\PUNCH_DN', 64, 64, 4, False);
2353 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK', GameWAD+':WEAPONS\PUNCHB', 64, 64, 4, False);
2354 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK_UP', GameWAD+':WEAPONS\PUNCHB_UP', 64, 64, 4, False);
2355 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK_DN', GameWAD+':WEAPONS\PUNCHB_DN', 64, 64, 4, False);
2356 g_Sound_CreateWADEx('SOUND_GAME_TELEPORT', GameWAD+':SOUNDS\TELEPORT');
2357 g_Sound_CreateWADEx('SOUND_GAME_NOTELEPORT', GameWAD+':SOUNDS\NOTELEPORT');
2358 g_Sound_CreateWADEx('SOUND_GAME_SECRET', GameWAD+':SOUNDS\SECRET');
2359 g_Sound_CreateWADEx('SOUND_GAME_DOOROPEN', GameWAD+':SOUNDS\DOOROPEN');
2360 g_Sound_CreateWADEx('SOUND_GAME_DOORCLOSE', GameWAD+':SOUNDS\DOORCLOSE');
2361 g_Sound_CreateWADEx('SOUND_GAME_BULK1', GameWAD+':SOUNDS\BULK1');
2362 g_Sound_CreateWADEx('SOUND_GAME_BULK2', GameWAD+':SOUNDS\BULK2');
2363 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE1', GameWAD+':SOUNDS\BUBBLE1');
2364 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE2', GameWAD+':SOUNDS\BUBBLE2');
2365 g_Sound_CreateWADEx('SOUND_GAME_BURNING', GameWAD+':SOUNDS\BURNING');
2366 g_Sound_CreateWADEx('SOUND_GAME_SWITCH1', GameWAD+':SOUNDS\SWITCH1');
2367 g_Sound_CreateWADEx('SOUND_GAME_SWITCH0', GameWAD+':SOUNDS\SWITCH0');
2368 g_Sound_CreateWADEx('SOUND_GAME_RADIO', GameWAD+':SOUNDS\RADIO');
2369 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD1', GameWAD+':SOUNDS\GOOD1');
2370 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD2', GameWAD+':SOUNDS\GOOD2');
2371 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD3', GameWAD+':SOUNDS\GOOD3');
2372 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD4', GameWAD+':SOUNDS\GOOD4');
2373 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL2X', GameWAD+':SOUNDS\KILL2X');
2374 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL3X', GameWAD+':SOUNDS\KILL3X');
2375 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL4X', GameWAD+':SOUNDS\KILL4X');
2376 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILLMX', GameWAD+':SOUNDS\KILLMX');
2377 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA1', GameWAD+':SOUNDS\MUHAHA1');
2378 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA2', GameWAD+':SOUNDS\MUHAHA2');
2379 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA3', GameWAD+':SOUNDS\MUHAHA3');
2380 g_Sound_CreateWADEx('SOUND_CTF_GET1', GameWAD+':SOUNDS\GETFLAG1');
2381 g_Sound_CreateWADEx('SOUND_CTF_GET2', GameWAD+':SOUNDS\GETFLAG2');
2382 g_Sound_CreateWADEx('SOUND_CTF_LOST1', GameWAD+':SOUNDS\LOSTFLG1');
2383 g_Sound_CreateWADEx('SOUND_CTF_LOST2', GameWAD+':SOUNDS\LOSTFLG2');
2384 g_Sound_CreateWADEx('SOUND_CTF_RETURN1', GameWAD+':SOUNDS\RETFLAG1');
2385 g_Sound_CreateWADEx('SOUND_CTF_RETURN2', GameWAD+':SOUNDS\RETFLAG2');
2386 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE1', GameWAD+':SOUNDS\CAPFLAG1');
2387 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE2', GameWAD+':SOUNDS\CAPFLAG2');
2389 goodsnd[0] := TPlayableSound.Create();
2390 goodsnd[1] := TPlayableSound.Create();
2391 goodsnd[2] := TPlayableSound.Create();
2392 goodsnd[3] := TPlayableSound.Create();
2394 goodsnd[0].SetByName('SOUND_ANNOUNCER_GOOD1');
2395 goodsnd[1].SetByName('SOUND_ANNOUNCER_GOOD2');
2396 goodsnd[2].SetByName('SOUND_ANNOUNCER_GOOD3');
2397 goodsnd[3].SetByName('SOUND_ANNOUNCER_GOOD4');
2399 killsnd[0] := TPlayableSound.Create();
2400 killsnd[1] := TPlayableSound.Create();
2401 killsnd[2] := TPlayableSound.Create();
2402 killsnd[3] := TPlayableSound.Create();
2404 killsnd[0].SetByName('SOUND_ANNOUNCER_KILL2X');
2405 killsnd[1].SetByName('SOUND_ANNOUNCER_KILL3X');
2406 killsnd[2].SetByName('SOUND_ANNOUNCER_KILL4X');
2407 killsnd[3].SetByName('SOUND_ANNOUNCER_KILLMX');
2409 hahasnd[0] := TPlayableSound.Create();
2410 hahasnd[1] := TPlayableSound.Create();
2411 hahasnd[2] := TPlayableSound.Create();
2413 hahasnd[0].SetByName('SOUND_ANNOUNCER_MUHAHA1');
2414 hahasnd[1].SetByName('SOUND_ANNOUNCER_MUHAHA2');
2415 hahasnd[2].SetByName('SOUND_ANNOUNCER_MUHAHA3');
2417 sound_get_flag[0] := TPlayableSound.Create();
2418 sound_get_flag[1] := TPlayableSound.Create();
2419 sound_lost_flag[0] := TPlayableSound.Create();
2420 sound_lost_flag[1] := TPlayableSound.Create();
2421 sound_ret_flag[0] := TPlayableSound.Create();
2422 sound_ret_flag[1] := TPlayableSound.Create();
2423 sound_cap_flag[0] := TPlayableSound.Create();
2424 sound_cap_flag[1] := TPlayableSound.Create();
2426 sound_get_flag[0].SetByName('SOUND_CTF_GET1');
2427 sound_get_flag[1].SetByName('SOUND_CTF_GET2');
2428 sound_lost_flag[0].SetByName('SOUND_CTF_LOST1');
2429 sound_lost_flag[1].SetByName('SOUND_CTF_LOST2');
2430 sound_ret_flag[0].SetByName('SOUND_CTF_RETURN1');
2431 sound_ret_flag[1].SetByName('SOUND_CTF_RETURN2');
2432 sound_cap_flag[0].SetByName('SOUND_CTF_CAPTURE1');
2433 sound_cap_flag[1].SetByName('SOUND_CTF_CAPTURE2');
2435 g_Game_LoadChatSounds(GameWAD+':CHATSND\SNDCFG');
2437 g_Game_SetLoadingText(_lc[I_LOAD_ITEMS_DATA], 0, False);
2438 g_Items_LoadData();
2440 g_Game_SetLoadingText(_lc[I_LOAD_WEAPONS_DATA], 0, False);
2441 g_Weapon_LoadData();
2443 g_Monsters_LoadData();
2445 DataLoaded := True;
2446 end;
2448 procedure g_Game_FreeData();
2449 begin
2450 if not DataLoaded then Exit;
2452 g_Items_FreeData();
2453 g_Weapon_FreeData();
2454 g_Monsters_FreeData();
2456 e_WriteLog('Releasing game data...', TMsgType.Notify);
2458 g_Texture_Delete('NOTEXTURE');
2459 g_Texture_Delete('TEXTURE_PLAYER_HUD');
2460 g_Texture_Delete('TEXTURE_PLAYER_HUDBG');
2461 g_Texture_Delete('TEXTURE_PLAYER_ARMORHUD');
2462 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG');
2463 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_S');
2464 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_D');
2465 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG');
2466 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_S');
2467 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_D');
2468 g_Texture_Delete('TEXTURE_PLAYER_TALKBUBBLE');
2469 g_Texture_Delete('TEXTURE_PLAYER_INVULPENTA');
2470 g_Frames_DeleteByName('FRAMES_TELEPORT');
2471 g_Frames_DeleteByName('FRAMES_PUNCH');
2472 g_Frames_DeleteByName('FRAMES_PUNCH_UP');
2473 g_Frames_DeleteByName('FRAMES_PUNCH_DN');
2474 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK');
2475 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK_UP');
2476 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK_DN');
2477 g_Sound_Delete('SOUND_GAME_TELEPORT');
2478 g_Sound_Delete('SOUND_GAME_NOTELEPORT');
2479 g_Sound_Delete('SOUND_GAME_SECRET');
2480 g_Sound_Delete('SOUND_GAME_DOOROPEN');
2481 g_Sound_Delete('SOUND_GAME_DOORCLOSE');
2482 g_Sound_Delete('SOUND_GAME_BULK1');
2483 g_Sound_Delete('SOUND_GAME_BULK2');
2484 g_Sound_Delete('SOUND_GAME_BUBBLE1');
2485 g_Sound_Delete('SOUND_GAME_BUBBLE2');
2486 g_Sound_Delete('SOUND_GAME_BURNING');
2487 g_Sound_Delete('SOUND_GAME_SWITCH1');
2488 g_Sound_Delete('SOUND_GAME_SWITCH0');
2490 goodsnd[0].Free();
2491 goodsnd[1].Free();
2492 goodsnd[2].Free();
2493 goodsnd[3].Free();
2495 g_Sound_Delete('SOUND_ANNOUNCER_GOOD1');
2496 g_Sound_Delete('SOUND_ANNOUNCER_GOOD2');
2497 g_Sound_Delete('SOUND_ANNOUNCER_GOOD3');
2498 g_Sound_Delete('SOUND_ANNOUNCER_GOOD4');
2500 killsnd[0].Free();
2501 killsnd[1].Free();
2502 killsnd[2].Free();
2503 killsnd[3].Free();
2505 g_Sound_Delete('SOUND_ANNOUNCER_KILL2X');
2506 g_Sound_Delete('SOUND_ANNOUNCER_KILL3X');
2507 g_Sound_Delete('SOUND_ANNOUNCER_KILL4X');
2508 g_Sound_Delete('SOUND_ANNOUNCER_KILLMX');
2510 hahasnd[0].Free();
2511 hahasnd[1].Free();
2512 hahasnd[2].Free();
2514 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA1');
2515 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA2');
2516 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA3');
2518 sound_get_flag[0].Free();
2519 sound_get_flag[1].Free();
2520 sound_lost_flag[0].Free();
2521 sound_lost_flag[1].Free();
2522 sound_ret_flag[0].Free();
2523 sound_ret_flag[1].Free();
2524 sound_cap_flag[0].Free();
2525 sound_cap_flag[1].Free();
2527 g_Sound_Delete('SOUND_CTF_GET1');
2528 g_Sound_Delete('SOUND_CTF_GET2');
2529 g_Sound_Delete('SOUND_CTF_LOST1');
2530 g_Sound_Delete('SOUND_CTF_LOST2');
2531 g_Sound_Delete('SOUND_CTF_RETURN1');
2532 g_Sound_Delete('SOUND_CTF_RETURN2');
2533 g_Sound_Delete('SOUND_CTF_CAPTURE1');
2534 g_Sound_Delete('SOUND_CTF_CAPTURE2');
2536 g_Game_FreeChatSounds();
2538 DataLoaded := False;
2539 end;
2541 procedure DrawCustomStat();
2542 var
2543 pc, x, y, w, _y,
2544 w1, w2, w3,
2545 t, p, m: Integer;
2546 ww1, hh1: Word;
2547 ww2, hh2, r, g, b, rr, gg, bb: Byte;
2548 s1, s2, topstr: String;
2549 begin
2550 e_TextureFontGetSize(gStdFont, ww2, hh2);
2552 sys_HandleInput;
2554 if g_Console_Action(ACTION_SCORES) then
2555 begin
2556 if not gStatsPressed then
2557 begin
2558 gStatsOff := not gStatsOff;
2559 gStatsPressed := True;
2560 end;
2561 end
2562 else
2563 gStatsPressed := False;
2565 if gStatsOff then
2566 begin
2567 s1 := _lc[I_MENU_INTER_NOTICE_TAB];
2568 w := (Length(s1) * ww2) div 2;
2569 x := gScreenWidth div 2 - w;
2570 y := 8;
2571 e_TextureFontPrint(x, y, s1, gStdFont);
2572 Exit;
2573 end;
2575 if (gGameSettings.GameMode = GM_COOP) then
2576 begin
2577 if gMissionFailed then
2578 topstr := _lc[I_MENU_INTER_MISSION_FAIL]
2579 else
2580 topstr := _lc[I_MENU_INTER_LEVEL_COMPLETE];
2581 end
2582 else
2583 topstr := _lc[I_MENU_INTER_ROUND_OVER];
2585 e_CharFont_GetSize(gMenuFont, topstr, ww1, hh1);
2586 e_CharFont_Print(gMenuFont, (gScreenWidth div 2)-(ww1 div 2), 16, topstr);
2588 if g_Game_IsNet then
2589 begin
2590 topstr := Format(_lc[I_MENU_INTER_NOTICE_TIME], [gServInterTime]);
2591 if not gChatShow then
2592 e_TextureFontPrintEx((gScreenWidth div 2)-(Length(topstr)*ww2 div 2),
2593 gScreenHeight-(hh2+4)*2, topstr, gStdFont, 255, 255, 255, 1);
2594 end;
2596 if g_Game_IsClient then
2597 topstr := _lc[I_MENU_INTER_NOTICE_MAP]
2598 else
2599 topstr := _lc[I_MENU_INTER_NOTICE_SPACE];
2600 if not gChatShow then
2601 e_TextureFontPrintEx((gScreenWidth div 2)-(Length(topstr)*ww2 div 2),
2602 gScreenHeight-(hh2+4), topstr, gStdFont, 255, 255, 255, 1);
2604 x := 32;
2605 y := 16+hh1+16;
2607 w := gScreenWidth-x*2;
2609 w2 := (w-16) div 6;
2610 w3 := w2;
2611 w1 := w-16-w2-w3;
2613 e_DrawFillQuad(x, y, gScreenWidth-x-1, gScreenHeight-y-1, 64, 64, 64, 32);
2614 e_DrawQuad(x, y, gScreenWidth-x-1, gScreenHeight-y-1, 255, 127, 0);
2616 m := Max(Length(_lc[I_MENU_MAP])+1, Length(_lc[I_GAME_GAME_TIME])+1)*ww2;
2618 case CustomStat.GameMode of
2619 GM_DM:
2620 begin
2621 if gGameSettings.MaxLives = 0 then
2622 s1 := _lc[I_GAME_DM]
2623 else
2624 s1 := _lc[I_GAME_LMS];
2625 end;
2626 GM_TDM:
2627 begin
2628 if gGameSettings.MaxLives = 0 then
2629 s1 := _lc[I_GAME_TDM]
2630 else
2631 s1 := _lc[I_GAME_TLMS];
2632 end;
2633 GM_CTF: s1 := _lc[I_GAME_CTF];
2634 GM_COOP:
2635 begin
2636 if gGameSettings.MaxLives = 0 then
2637 s1 := _lc[I_GAME_COOP]
2638 else
2639 s1 := _lc[I_GAME_SURV];
2640 end;
2641 else s1 := '';
2642 end;
2644 _y := y+16;
2645 e_TextureFontPrintEx(x+(w div 2)-(Length(s1)*ww2 div 2), _y, s1, gStdFont, 255, 255, 255, 1);
2646 _y := _y+8;
2648 _y := _y+16;
2649 e_TextureFontPrintEx(x+8, _y, _lc[I_MENU_MAP], gStdFont, 255, 127, 0, 1);
2650 e_TextureFontPrint(x+8+m, _y, Format('%s - %s', [CustomStat.Map, CustomStat.MapName]), gStdFont);
2652 _y := _y+16;
2653 e_TextureFontPrintEx(x+8, _y, _lc[I_GAME_GAME_TIME], gStdFont, 255, 127, 0, 1);
2654 e_TextureFontPrint(x+8+m, _y, Format('%d:%.2d:%.2d', [CustomStat.GameTime div 1000 div 3600,
2655 (CustomStat.GameTime div 1000 div 60) mod 60,
2656 CustomStat.GameTime div 1000 mod 60]), gStdFont);
2658 pc := Length(CustomStat.PlayerStat);
2659 if pc = 0 then Exit;
2661 if CustomStat.GameMode = GM_COOP then
2662 begin
2663 m := Max(Length(_lc[I_GAME_MONSTERS])+1, Length(_lc[I_GAME_SECRETS])+1)*ww2;
2664 _y := _y+32;
2665 s2 := _lc[I_GAME_MONSTERS];
2666 e_TextureFontPrintEx(x+8, _y, s2, gStdFont, 255, 127, 0, 1);
2667 e_TextureFontPrintEx(x+8+m, _y, IntToStr(gCoopMonstersKilled) + '/' + IntToStr(gTotalMonsters), gStdFont, 255, 255, 255, 1);
2668 _y := _y+16;
2669 s2 := _lc[I_GAME_SECRETS];
2670 e_TextureFontPrintEx(x+8, _y, s2, gStdFont, 255, 127, 0, 1);
2671 e_TextureFontPrintEx(x+8+m, _y, IntToStr(gCoopSecretsFound) + '/' + IntToStr(gSecretsCount), gStdFont, 255, 255, 255, 1);
2672 if gLastMap then
2673 begin
2674 m := Max(Length(_lc[I_GAME_MONSTERS_TOTAL])+1, Length(_lc[I_GAME_SECRETS_TOTAL])+1)*ww2;
2675 _y := _y-16;
2676 s2 := _lc[I_GAME_MONSTERS_TOTAL];
2677 e_TextureFontPrintEx(x+250, _y, s2, gStdFont, 255, 127, 0, 1);
2678 e_TextureFontPrintEx(x+250+m, _y, IntToStr(gCoopTotalMonstersKilled) + '/' + IntToStr(gCoopTotalMonsters), gStdFont, 255, 255, 255, 1);
2679 _y := _y+16;
2680 s2 := _lc[I_GAME_SECRETS_TOTAL];
2681 e_TextureFontPrintEx(x+250, _y, s2, gStdFont, 255, 127, 0, 1);
2682 e_TextureFontPrintEx(x+250+m, _y, IntToStr(gCoopTotalSecretsFound) + '/' + IntToStr(gCoopTotalSecrets), gStdFont, 255, 255, 255, 1);
2683 end;
2684 end;
2686 if CustomStat.GameMode in [GM_TDM, GM_CTF] then
2687 begin
2688 _y := _y+16+16;
2690 with CustomStat do
2691 if TeamStat[TEAM_RED].Goals > TeamStat[TEAM_BLUE].Goals then s1 := _lc[I_GAME_WIN_RED]
2692 else if TeamStat[TEAM_BLUE].Goals > TeamStat[TEAM_RED].Goals then s1 := _lc[I_GAME_WIN_BLUE]
2693 else s1 := _lc[I_GAME_WIN_DRAW];
2695 e_TextureFontPrintEx(x+8+(w div 2)-(Length(s1)*ww2 div 2), _y, s1, gStdFont, 255, 255, 255, 1);
2696 _y := _y+40;
2698 for t := TEAM_RED to TEAM_BLUE do
2699 begin
2700 if t = TEAM_RED then
2701 begin
2702 e_TextureFontPrintEx(x+8, _y, _lc[I_GAME_TEAM_RED],
2703 gStdFont, 255, 0, 0, 1);
2704 e_TextureFontPrintEx(x+w1+8, _y, IntToStr(CustomStat.TeamStat[TEAM_RED].Goals),
2705 gStdFont, 255, 0, 0, 1);
2706 r := 255;
2707 g := 0;
2708 b := 0;
2709 end
2710 else
2711 begin
2712 e_TextureFontPrintEx(x+8, _y, _lc[I_GAME_TEAM_BLUE],
2713 gStdFont, 0, 0, 255, 1);
2714 e_TextureFontPrintEx(x+w1+8, _y, IntToStr(CustomStat.TeamStat[TEAM_BLUE].Goals),
2715 gStdFont, 0, 0, 255, 1);
2716 r := 0;
2717 g := 0;
2718 b := 255;
2719 end;
2721 e_DrawLine(1, x+8, _y+20, x-8+w, _y+20, r, g, b);
2722 _y := _y+24;
2724 for p := 0 to High(CustomStat.PlayerStat) do
2725 if CustomStat.PlayerStat[p].Team = t then
2726 with CustomStat.PlayerStat[p] do
2727 begin
2728 if Spectator then
2729 begin
2730 rr := r div 2;
2731 gg := g div 2;
2732 bb := b div 2;
2733 end
2734 else
2735 begin
2736 rr := r;
2737 gg := g;
2738 bb := b;
2739 end;
2740 if (gPlayers[Num] <> nil) and (gPlayers[Num].FReady) then
2741 e_TextureFontPrintEx(x+16, _y, Name + ' *', gStdFont, rr, gg, bb, 1)
2742 else
2743 e_TextureFontPrintEx(x+16, _y, Name, gStdFont, rr, gg, bb, 1);
2744 e_TextureFontPrintEx(x+w1+16, _y, IntToStr(Frags), gStdFont, rr, gg, bb, 1);
2745 e_TextureFontPrintEx(x+w1+w2+16, _y, IntToStr(Deaths), gStdFont, rr, gg, bb, 1);
2746 _y := _y+24;
2747 end;
2749 _y := _y+16+16;
2750 end;
2751 end
2752 else if CustomStat.GameMode in [GM_DM, GM_COOP] then
2753 begin
2754 _y := _y+40;
2755 e_TextureFontPrintEx(x+8, _y, _lc[I_GAME_PLAYER_NAME], gStdFont, 255, 127, 0, 1);
2756 e_TextureFontPrintEx(x+8+w1, _y, _lc[I_GAME_FRAGS], gStdFont, 255, 127, 0, 1);
2757 e_TextureFontPrintEx(x+8+w1+w2, _y, _lc[I_GAME_DEATHS], gStdFont, 255, 127, 0, 1);
2759 _y := _y+24;
2760 for p := 0 to High(CustomStat.PlayerStat) do
2761 with CustomStat.PlayerStat[p] do
2762 begin
2763 e_DrawFillQuad(x+8, _y+4, x+24-1, _y+16+4-1, Color.R, Color.G, Color.B, 0);
2765 if Spectator then
2766 r := 127
2767 else
2768 r := 255;
2770 if (gPlayers[Num] <> nil) and (gPlayers[Num].FReady) then
2771 e_TextureFontPrintEx(x+8+16+8, _y+4, Name + ' *', gStdFont, r, r, r, 1, True)
2772 else
2773 e_TextureFontPrintEx(x+8+16+8, _y+4, Name, gStdFont, r, r, r, 1, True);
2774 e_TextureFontPrintEx(x+w1+8+16+8, _y+4, IntToStr(Frags), gStdFont, r, r, r, 1, True);
2775 e_TextureFontPrintEx(x+w1+w2+8+16+8, _y+4, IntToStr(Deaths), gStdFont, r, r, r, 1, True);
2776 _y := _y+24;
2777 end;
2778 end;
2779 end;
2781 procedure DrawSingleStat();
2782 var
2783 tm, key_x, val_x, y: Integer;
2784 w1, w2, h: Word;
2785 s1, s2: String;
2787 procedure player_stat(n: Integer);
2788 var
2789 kpm: Real;
2791 begin
2792 // "Kills: # / #":
2793 s1 := Format(' %d ', [SingleStat.PlayerStat[n].Kills]);
2794 s2 := Format(' %d', [gTotalMonsters]);
2796 e_CharFont_Print(gMenuFont, key_x, y, _lc[I_MENU_INTER_KILLS]);
2797 e_CharFont_PrintEx(gMenuFont, val_x, y, s1, _RGB(255, 0, 0));
2798 e_CharFont_GetSize(gMenuFont, s1, w1, h);
2799 e_CharFont_Print(gMenuFont, val_x+w1, y, '/');
2800 s1 := s1 + '/';
2801 e_CharFont_GetSize(gMenuFont, s1, w1, h);
2802 e_CharFont_PrintEx(gMenuFont, val_x+w1, y, s2, _RGB(255, 0, 0));
2804 // "Kills-per-minute: ##.#":
2805 s1 := _lc[I_MENU_INTER_KPM];
2806 if tm > 0 then
2807 kpm := (SingleStat.PlayerStat[n].Kills / tm) * 60
2808 else
2809 kpm := SingleStat.PlayerStat[n].Kills;
2810 s2 := Format(' %.1f', [kpm]);
2812 e_CharFont_Print(gMenuFont, key_x, y+32, s1);
2813 e_CharFont_PrintEx(gMenuFont, val_x, y+32, s2, _RGB(255, 0, 0));
2815 // "Secrets found: # / #":
2816 s1 := Format(' %d ', [SingleStat.PlayerStat[n].Secrets]);
2817 s2 := Format(' %d', [SingleStat.TotalSecrets]);
2819 e_CharFont_Print(gMenuFont, key_x, y+64, _lc[I_MENU_INTER_SECRETS]);
2820 e_CharFont_PrintEx(gMenuFont, val_x, y+64, s1, _RGB(255, 0, 0));
2821 e_CharFont_GetSize(gMenuFont, s1, w1, h);
2822 e_CharFont_Print(gMenuFont, val_x+w1, y+64, '/');
2823 s1 := s1 + '/';
2824 e_CharFont_GetSize(gMenuFont, s1, w1, h);
2825 e_CharFont_PrintEx(gMenuFont, val_x+w1, y+64, s2, _RGB(255, 0, 0));
2826 end;
2828 begin
2829 // "Level Complete":
2830 e_CharFont_GetSize(gMenuFont, _lc[I_MENU_INTER_LEVEL_COMPLETE], w1, h);
2831 e_CharFont_Print(gMenuFont, (gScreenWidth-w1) div 2, 32, _lc[I_MENU_INTER_LEVEL_COMPLETE]);
2833 // Îïðåäåëÿåì êîîðäèíàòû âûðàâíèâàíèÿ ïî ñàìîé äëèííîé ñòðîêå:
2834 s1 := _lc[I_MENU_INTER_KPM];
2835 e_CharFont_GetSize(gMenuFont, s1, w1, h);
2836 Inc(w1, 16);
2837 s1 := ' 9999.9';
2838 e_CharFont_GetSize(gMenuFont, s1, w2, h);
2840 key_x := (gScreenWidth-w1-w2) div 2;
2841 val_x := key_x + w1;
2843 // "Time: #:##:##":
2844 tm := SingleStat.GameTime div 1000;
2845 s1 := _lc[I_MENU_INTER_TIME];
2846 s2 := Format(' %d:%.2d:%.2d', [tm div (60*60), (tm mod (60*60)) div 60, tm mod 60]);
2848 e_CharFont_Print(gMenuFont, key_x, 80, s1);
2849 e_CharFont_PrintEx(gMenuFont, val_x, 80, s2, _RGB(255, 0, 0));
2851 if SingleStat.TwoPlayers then
2852 begin
2853 // "Player 1":
2854 s1 := _lc[I_MENU_PLAYER_1];
2855 e_CharFont_GetSize(gMenuFont, s1, w1, h);
2856 e_CharFont_Print(gMenuFont, (gScreenWidth-w1) div 2, 128, s1);
2858 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
2859 y := 176;
2860 player_stat(0);
2862 // "Player 2":
2863 s1 := _lc[I_MENU_PLAYER_2];
2864 e_CharFont_GetSize(gMenuFont, s1, w1, h);
2865 e_CharFont_Print(gMenuFont, (gScreenWidth-w1) div 2, 288, s1);
2867 // Ñòàòèñòèêà âòîðîãî èãðîêà:
2868 y := 336;
2869 player_stat(1);
2870 end
2871 else
2872 begin
2873 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
2874 y := 128;
2875 player_stat(0);
2876 end;
2877 end;
2879 procedure DrawLoadingStat();
2880 procedure drawRect (x, y, w, h: Integer);
2881 begin
2882 if (w < 1) or (h < 1) then exit;
2883 glBegin(GL_QUADS);
2884 glVertex2f(x+0.375, y+0.375);
2885 glVertex2f(x+w+0.375, y+0.375);
2886 glVertex2f(x+w+0.375, y+h+0.375);
2887 glVertex2f(x+0.375, y+h+0.375);
2888 glEnd();
2889 end;
2891 function drawPBar (cur, total: Integer; washere: Boolean): Boolean;
2892 var
2893 rectW, rectH: Integer;
2894 x0, y0: Integer;
2895 wdt: Integer;
2896 wl, hl: Integer;
2897 wr, hr: Integer;
2898 wb, hb: Integer;
2899 wm, hm: Integer;
2900 idl, idr, idb, idm: LongWord;
2901 f, my: Integer;
2902 begin
2903 result := false;
2904 if (total < 1) then exit;
2905 if (cur < 1) then exit; // don't blink
2906 if (not washere) and (cur >= total) then exit; // don't blink
2907 //if (cur < 0) then cur := 0;
2908 //if (cur > total) then cur := total;
2909 result := true;
2911 if (hasPBarGfx) then
2912 begin
2913 g_Texture_Get('UI_GFX_PBAR_LEFT', idl);
2914 g_Texture_GetSize('UI_GFX_PBAR_LEFT', wl, hl);
2915 g_Texture_Get('UI_GFX_PBAR_RIGHT', idr);
2916 g_Texture_GetSize('UI_GFX_PBAR_RIGHT', wr, hr);
2917 g_Texture_Get('UI_GFX_PBAR_MIDDLE', idb);
2918 g_Texture_GetSize('UI_GFX_PBAR_MIDDLE', wb, hb);
2919 g_Texture_Get('UI_GFX_PBAR_MARKER', idm);
2920 g_Texture_GetSize('UI_GFX_PBAR_MARKER', wm, hm);
2922 //rectW := gScreenWidth-360;
2923 rectW := trunc(624.0*gScreenWidth/1024.0);
2924 rectH := hl;
2926 x0 := (gScreenWidth-rectW) div 2;
2927 y0 := gScreenHeight-rectH-64;
2928 if (y0 < 2) then y0 := 2;
2930 glEnable(GL_SCISSOR_TEST);
2932 // left and right
2933 glScissor(x0, gScreenHeight-y0-rectH, rectW, rectH);
2934 e_DrawSize(idl, x0, y0, 0, true, false, wl, hl);
2935 e_DrawSize(idr, x0+rectW-wr, y0, 0, true, false, wr, hr);
2937 // body
2938 glScissor(x0+wl, gScreenHeight-y0-rectH, rectW-wl-wr, rectH);
2939 f := x0+wl;
2940 while (f < x0+rectW) do
2941 begin
2942 e_DrawSize(idb, f, y0, 0, true, false, wb, hb);
2943 f += wb;
2944 end;
2946 // filled part
2947 wdt := (rectW-wl-wr)*cur div total;
2948 if (wdt > rectW-wl-wr) then wdt := rectW-wr-wr;
2949 if (wdt > 0) then
2950 begin
2951 my := y0; // don't be so smart, ketmar: +(rectH-wm) div 2;
2952 glScissor(x0+wl, gScreenHeight-my-rectH, wdt, hm);
2953 f := x0+wl;
2954 while (wdt > 0) do
2955 begin
2956 e_DrawSize(idm, f, y0, 0, true, false, wm, hm);
2957 f += wm;
2958 wdt -= wm;
2959 end;
2960 end;
2962 glScissor(0, 0, gScreenWidth, gScreenHeight);
2963 end
2964 else
2965 begin
2966 rectW := gScreenWidth-64;
2967 rectH := 16;
2969 x0 := (gScreenWidth-rectW) div 2;
2970 y0 := gScreenHeight-rectH-64;
2971 if (y0 < 2) then y0 := 2;
2973 glDisable(GL_BLEND);
2974 glDisable(GL_TEXTURE_2D);
2976 //glClearColor(0, 0, 0, 0);
2977 //glClear(GL_COLOR_BUFFER_BIT);
2979 glColor4ub(127, 127, 127, 255);
2980 drawRect(x0-2, y0-2, rectW+4, rectH+4);
2982 glColor4ub(0, 0, 0, 255);
2983 drawRect(x0-1, y0-1, rectW+2, rectH+2);
2985 glColor4ub(127, 127, 127, 255);
2986 wdt := rectW*cur div total;
2987 if (wdt > rectW) then wdt := rectW;
2988 drawRect(x0, y0, wdt, rectH);
2989 end;
2990 end;
2992 var
2993 ww, hh: Word;
2994 xx, yy, i: Integer;
2995 s: String;
2996 begin
2997 if (Length(LoadingStat.Msgs) = 0) then exit;
2999 e_CharFont_GetSize(gMenuFont, _lc[I_MENU_LOADING], ww, hh);
3000 yy := (gScreenHeight div 3);
3001 e_CharFont_Print(gMenuFont, (gScreenWidth div 2)-(ww div 2), yy-2*hh, _lc[I_MENU_LOADING]);
3002 xx := (gScreenWidth div 3);
3004 with LoadingStat do
3005 begin
3006 for i := 0 to NextMsg-1 do
3007 begin
3008 if (i = (NextMsg-1)) and (MaxValue > 0) then
3009 s := Format('%s: %d/%d', [Msgs[i], CurValue, MaxValue])
3010 else
3011 s := Msgs[i];
3013 e_CharFont_PrintEx(gMenuSmallFont, xx, yy, s, _RGB(255, 0, 0));
3014 yy := yy + LOADING_INTERLINE;
3015 PBarWasHere := drawPBar(CurValue, MaxValue, PBarWasHere);
3016 end;
3017 end;
3018 end;
3020 procedure DrawMenuBackground(tex: AnsiString);
3021 var
3022 w, h: Word;
3023 ID: DWord;
3025 begin
3026 if g_Texture_Get(tex, ID) then
3027 begin
3028 e_Clear(GL_COLOR_BUFFER_BIT, 0, 0, 0);
3029 e_GetTextureSize(ID, @w, @h);
3030 if w = h then
3031 w := round(w * 1.333 * (gScreenHeight / h))
3032 else
3033 w := trunc(w * (gScreenHeight / h));
3034 e_DrawSize(ID, (gScreenWidth - w) div 2, 0, 0, False, False, w, gScreenHeight);
3035 end
3036 else e_Clear(GL_COLOR_BUFFER_BIT, 0, 0, 0);
3037 end;
3039 procedure DrawMinimap(p: TPlayer; RenderRect: e_graphics.TRect);
3040 var
3041 a, aX, aY, aX2, aY2, Scale, ScaleSz: Integer;
3043 function monDraw (mon: TMonster): Boolean;
3044 begin
3045 result := false; // don't stop
3046 with mon do
3047 begin
3048 if alive then
3049 begin
3050 // Ëåâûé âåðõíèé óãîë
3051 aX := Obj.X div ScaleSz + 1;
3052 aY := Obj.Y div ScaleSz + 1;
3053 // Ðàçìåðû
3054 aX2 := max(Obj.Rect.Width div ScaleSz, 1);
3055 aY2 := max(Obj.Rect.Height div ScaleSz, 1);
3056 // Ïðàâûé íèæíèé óãîë
3057 aX2 := aX + aX2 - 1;
3058 aY2 := aY + aY2 - 1;
3059 e_DrawFillQuad(aX, aY, aX2, aY2, 255, 255, 0, 0);
3060 end;
3061 end;
3062 end;
3064 begin
3065 if (gMapInfo.Width > RenderRect.Right - RenderRect.Left) or
3066 (gMapInfo.Height > RenderRect.Bottom - RenderRect.Top) then
3067 begin
3068 Scale := 1;
3069 // Ñêîëüêî ïèêñåëîâ êàðòû â 1 ïèêñåëå ìèíè-êàðòû:
3070 ScaleSz := 16 div Scale;
3071 // Ðàçìåðû ìèíè-êàðòû:
3072 aX := max(gMapInfo.Width div ScaleSz, 1);
3073 aY := max(gMapInfo.Height div ScaleSz, 1);
3074 // Ðàìêà êàðòû:
3075 e_DrawFillQuad(0, 0, aX-1, aY-1, 0, 0, 0, 0);
3077 if gWalls <> nil then
3078 begin
3079 // Ðèñóåì ñòåíû:
3080 for a := 0 to High(gWalls) do
3081 with gWalls[a] do
3082 if PanelType <> 0 then
3083 begin
3084 // Ëåâûé âåðõíèé óãîë:
3085 aX := X div ScaleSz;
3086 aY := Y div ScaleSz;
3087 // Ðàçìåðû:
3088 aX2 := max(Width div ScaleSz, 1);
3089 aY2 := max(Height div ScaleSz, 1);
3090 // Ïðàâûé íèæíèé óãîë:
3091 aX2 := aX + aX2 - 1;
3092 aY2 := aY + aY2 - 1;
3094 case PanelType of
3095 PANEL_WALL: e_DrawFillQuad(aX, aY, aX2, aY2, 208, 208, 208, 0);
3096 PANEL_OPENDOOR, PANEL_CLOSEDOOR:
3097 if Enabled then e_DrawFillQuad(aX, aY, aX2, aY2, 160, 160, 160, 0);
3098 end;
3099 end;
3100 end;
3101 if gSteps <> nil then
3102 begin
3103 // Ðèñóåì ñòóïåíè:
3104 for a := 0 to High(gSteps) do
3105 with gSteps[a] do
3106 if PanelType <> 0 then
3107 begin
3108 // Ëåâûé âåðõíèé óãîë:
3109 aX := X div ScaleSz;
3110 aY := Y div ScaleSz;
3111 // Ðàçìåðû:
3112 aX2 := max(Width div ScaleSz, 1);
3113 aY2 := max(Height div ScaleSz, 1);
3114 // Ïðàâûé íèæíèé óãîë:
3115 aX2 := aX + aX2 - 1;
3116 aY2 := aY + aY2 - 1;
3118 e_DrawFillQuad(aX, aY, aX2, aY2, 128, 128, 128, 0);
3119 end;
3120 end;
3121 if gLifts <> nil then
3122 begin
3123 // Ðèñóåì ëèôòû:
3124 for a := 0 to High(gLifts) do
3125 with gLifts[a] do
3126 if PanelType <> 0 then
3127 begin
3128 // Ëåâûé âåðõíèé óãîë:
3129 aX := X div ScaleSz;
3130 aY := Y div ScaleSz;
3131 // Ðàçìåðû:
3132 aX2 := max(Width div ScaleSz, 1);
3133 aY2 := max(Height div ScaleSz, 1);
3134 // Ïðàâûé íèæíèé óãîë:
3135 aX2 := aX + aX2 - 1;
3136 aY2 := aY + aY2 - 1;
3138 case LiftType of
3139 LIFTTYPE_UP: e_DrawFillQuad(aX, aY, aX2, aY2, 116, 72, 36, 0);
3140 LIFTTYPE_DOWN: e_DrawFillQuad(aX, aY, aX2, aY2, 116, 124, 96, 0);
3141 LIFTTYPE_LEFT: e_DrawFillQuad(aX, aY, aX2, aY2, 200, 80, 4, 0);
3142 LIFTTYPE_RIGHT: e_DrawFillQuad(aX, aY, aX2, aY2, 252, 140, 56, 0);
3143 end;
3144 end;
3145 end;
3146 if gWater <> nil then
3147 begin
3148 // Ðèñóåì âîäó:
3149 for a := 0 to High(gWater) do
3150 with gWater[a] do
3151 if PanelType <> 0 then
3152 begin
3153 // Ëåâûé âåðõíèé óãîë:
3154 aX := X div ScaleSz;
3155 aY := Y div ScaleSz;
3156 // Ðàçìåðû:
3157 aX2 := max(Width div ScaleSz, 1);
3158 aY2 := max(Height div ScaleSz, 1);
3159 // Ïðàâûé íèæíèé óãîë:
3160 aX2 := aX + aX2 - 1;
3161 aY2 := aY + aY2 - 1;
3163 e_DrawFillQuad(aX, aY, aX2, aY2, 0, 0, 192, 0);
3164 end;
3165 end;
3166 if gAcid1 <> nil then
3167 begin
3168 // Ðèñóåì êèñëîòó 1:
3169 for a := 0 to High(gAcid1) do
3170 with gAcid1[a] do
3171 if PanelType <> 0 then
3172 begin
3173 // Ëåâûé âåðõíèé óãîë:
3174 aX := X div ScaleSz;
3175 aY := Y div ScaleSz;
3176 // Ðàçìåðû:
3177 aX2 := max(Width div ScaleSz, 1);
3178 aY2 := max(Height div ScaleSz, 1);
3179 // Ïðàâûé íèæíèé óãîë:
3180 aX2 := aX + aX2 - 1;
3181 aY2 := aY + aY2 - 1;
3183 e_DrawFillQuad(aX, aY, aX2, aY2, 0, 176, 0, 0);
3184 end;
3185 end;
3186 if gAcid2 <> nil then
3187 begin
3188 // Ðèñóåì êèñëîòó 2:
3189 for a := 0 to High(gAcid2) do
3190 with gAcid2[a] do
3191 if PanelType <> 0 then
3192 begin
3193 // Ëåâûé âåðõíèé óãîë:
3194 aX := X div ScaleSz;
3195 aY := Y div ScaleSz;
3196 // Ðàçìåðû:
3197 aX2 := max(Width div ScaleSz, 1);
3198 aY2 := max(Height div ScaleSz, 1);
3199 // Ïðàâûé íèæíèé óãîë:
3200 aX2 := aX + aX2 - 1;
3201 aY2 := aY + aY2 - 1;
3203 e_DrawFillQuad(aX, aY, aX2, aY2, 176, 0, 0, 0);
3204 end;
3205 end;
3206 if gPlayers <> nil then
3207 begin
3208 // Ðèñóåì èãðîêîâ:
3209 for a := 0 to High(gPlayers) do
3210 if gPlayers[a] <> nil then with gPlayers[a] do
3211 if alive then begin
3212 // Ëåâûé âåðõíèé óãîë:
3213 aX := Obj.X div ScaleSz + 1;
3214 aY := Obj.Y div ScaleSz + 1;
3215 // Ðàçìåðû:
3216 aX2 := max(Obj.Rect.Width div ScaleSz, 1);
3217 aY2 := max(Obj.Rect.Height div ScaleSz, 1);
3218 // Ïðàâûé íèæíèé óãîë:
3219 aX2 := aX + aX2 - 1;
3220 aY2 := aY + aY2 - 1;
3222 if gPlayers[a] = p then
3223 e_DrawFillQuad(aX, aY, aX2, aY2, 0, 255, 0, 0)
3224 else
3225 case Team of
3226 TEAM_RED: e_DrawFillQuad(aX, aY, aX2, aY2, 255, 0, 0, 0);
3227 TEAM_BLUE: e_DrawFillQuad(aX, aY, aX2, aY2, 0, 0, 255, 0);
3228 else e_DrawFillQuad(aX, aY, aX2, aY2, 255, 128, 0, 0);
3229 end;
3230 end;
3231 end;
3232 // Ðèñóåì ìîíñòðîâ
3233 g_Mons_ForEach(monDraw);
3234 end;
3235 end;
3238 procedure renderAmbientQuad (hasAmbient: Boolean; constref ambColor: TDFColor);
3239 begin
3240 if not hasAmbient then exit;
3241 e_AmbientQuad(sX, sY, sWidth, sHeight, ambColor.r, ambColor.g, ambColor.b, ambColor.a);
3242 end;
3245 // setup sX, sY, sWidth, sHeight, and transformation matrix before calling this!
3246 //FIXME: broken for splitscreen mode
3247 procedure renderDynLightsInternal ();
3248 var
3249 //hasAmbient: Boolean;
3250 //ambColor: TDFColor;
3251 lln: Integer;
3252 lx, ly, lrad: Integer;
3253 scxywh: array[0..3] of GLint;
3254 wassc: Boolean;
3255 begin
3256 if e_NoGraphics then exit;
3258 //TODO: lights should be in separate grid, i think
3259 // but on the other side: grid may be slower for dynlights, as their lifetime is short
3260 if (not gwin_k8_enable_light_experiments) or (not gwin_has_stencil) or (g_dynLightCount < 1) then exit;
3262 // rendering mode
3263 //ambColor := gCurrentMap['light_ambient'].rgba;
3264 //hasAmbient := (not ambColor.isOpaque) or (not ambColor.isBlack);
3266 { // this will multiply incoming color to alpha from framebuffer
3267 glEnable(GL_BLEND);
3268 glBlendFunc(GL_DST_ALPHA, GL_ONE);
3271 (*
3272 * light rendering: (INVALID!)
3273 * glStencilFunc(GL_EQUAL, 0, $ff);
3274 * for each light:
3275 * glClear(GL_STENCIL_BUFFER_BIT);
3276 * glStencilOp(GL_KEEP, GL_KEEP, GL_INCR);
3277 * draw shadow volume into stencil buffer
3278 * glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); // modify color buffer
3279 * glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); // don't modify stencil buffer
3280 * turn off blending
3281 * draw color-less quad with light alpha (WARNING! don't touch color!)
3282 * glEnable(GL_BLEND);
3283 * glBlendFunc(GL_DST_ALPHA, GL_ONE);
3284 * draw all geometry up to and including walls (with alpha-testing, probably) -- this does lighting
3285 *)
3286 wassc := (glIsEnabled(GL_SCISSOR_TEST) <> 0);
3287 if wassc then glGetIntegerv(GL_SCISSOR_BOX, @scxywh[0]) else glGetIntegerv(GL_VIEWPORT, @scxywh[0]);
3289 // setup OpenGL parameters
3290 glStencilMask($FFFFFFFF);
3291 glStencilFunc(GL_ALWAYS, 0, $FFFFFFFF);
3292 glEnable(GL_STENCIL_TEST);
3293 glEnable(GL_SCISSOR_TEST);
3294 glClear(GL_STENCIL_BUFFER_BIT);
3295 glStencilFunc(GL_EQUAL, 0, $ff);
3297 for lln := 0 to g_dynLightCount-1 do
3298 begin
3299 lx := g_dynLights[lln].x;
3300 ly := g_dynLights[lln].y;
3301 lrad := g_dynLights[lln].radius;
3302 if (lrad < 3) then continue;
3304 if (lx-sX+lrad < 0) then continue;
3305 if (ly-sY+lrad < 0) then continue;
3306 if (lx-sX-lrad >= gPlayerScreenSize.X) then continue;
3307 if (ly-sY-lrad >= gPlayerScreenSize.Y) then continue;
3309 // set scissor to optimize drawing
3310 if (g_dbg_scale = 1.0) then
3311 begin
3312 glScissor((lx-sX)-lrad+2, gPlayerScreenSize.Y-(ly-sY)-lrad-1+2, lrad*2-4, lrad*2-4);
3313 end
3314 else
3315 begin
3316 glScissor(0, 0, gWinSizeX, gWinSizeY);
3317 end;
3318 // no need to clear stencil buffer, light blitting will do it for us... but only for normal scale
3319 if (g_dbg_scale <> 1.0) then glClear(GL_STENCIL_BUFFER_BIT);
3320 glStencilOp(GL_KEEP, GL_KEEP, GL_INCR);
3321 // draw extruded panels
3322 glDisable(GL_TEXTURE_2D);
3323 glDisable(GL_BLEND);
3324 glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); // no need to modify color buffer
3325 if (lrad > 4) then g_Map_DrawPanelShadowVolumes(lx, ly, lrad);
3326 // render light texture
3327 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); // modify color buffer
3328 glStencilOp(GL_ZERO, GL_ZERO, GL_ZERO); // draw light, and clear stencil buffer
3329 // blend it
3330 glEnable(GL_BLEND);
3331 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
3332 glEnable(GL_TEXTURE_2D);
3333 // color and opacity
3334 glColor4f(g_dynLights[lln].r, g_dynLights[lln].g, g_dynLights[lln].b, g_dynLights[lln].a);
3335 glBindTexture(GL_TEXTURE_2D, g_Texture_Light());
3336 glBegin(GL_QUADS);
3337 glTexCoord2f(0.0, 0.0); glVertex2i(lx-lrad, ly-lrad); // top-left
3338 glTexCoord2f(1.0, 0.0); glVertex2i(lx+lrad, ly-lrad); // top-right
3339 glTexCoord2f(1.0, 1.0); glVertex2i(lx+lrad, ly+lrad); // bottom-right
3340 glTexCoord2f(0.0, 1.0); glVertex2i(lx-lrad, ly+lrad); // bottom-left
3341 glEnd();
3342 end;
3344 // done
3345 glDisable(GL_STENCIL_TEST);
3346 glDisable(GL_BLEND);
3347 glDisable(GL_SCISSOR_TEST);
3348 //glScissor(0, 0, sWidth, sHeight);
3350 glScissor(scxywh[0], scxywh[1], scxywh[2], scxywh[3]);
3351 if wassc then glEnable(GL_SCISSOR_TEST) else glDisable(GL_SCISSOR_TEST);
3352 end;
3355 function fixViewportForScale (): Boolean;
3356 var
3357 nx0, ny0, nw, nh: Integer;
3358 begin
3359 result := false;
3360 if (g_dbg_scale <> 1.0) then
3361 begin
3362 result := true;
3363 nx0 := round(sX-(gPlayerScreenSize.X-(sWidth*g_dbg_scale))/2/g_dbg_scale);
3364 ny0 := round(sY-(gPlayerScreenSize.Y-(sHeight*g_dbg_scale))/2/g_dbg_scale);
3365 nw := round(sWidth/g_dbg_scale);
3366 nh := round(sHeight/g_dbg_scale);
3367 sX := nx0;
3368 sY := ny0;
3369 sWidth := nw;
3370 sHeight := nh;
3371 end;
3372 end;
3375 // setup sX, sY, sWidth, sHeight, and transformation matrix before calling this!
3376 // WARNING! this WILL CALL `glTranslatef()`, but won't restore matrices!
3377 procedure renderMapInternal (backXOfs, backYOfs: Integer; setTransMatrix: Boolean);
3378 type
3379 TDrawCB = procedure ();
3381 var
3382 hasAmbient: Boolean;
3383 ambColor: TDFColor;
3384 doAmbient: Boolean = false;
3386 procedure drawPanelType (profname: AnsiString; panType: DWord; doDraw: Boolean);
3387 var
3388 tagmask: Integer;
3389 pan: TPanel;
3390 begin
3391 if (profileFrameDraw <> nil) then profileFrameDraw.sectionBegin(profname);
3392 if gdbg_map_use_accel_render then
3393 begin
3394 tagmask := panelTypeToTag(panType);
3395 while (gDrawPanelList.count > 0) do
3396 begin
3397 pan := TPanel(gDrawPanelList.front());
3398 if ((pan.tag and tagmask) = 0) then break;
3399 if doDraw then pan.Draw(doAmbient, ambColor);
3400 gDrawPanelList.popFront();
3401 end;
3402 end
3403 else
3404 begin
3405 if doDraw then g_Map_DrawPanels(panType, hasAmbient, ambColor);
3406 end;
3407 if (profileFrameDraw <> nil) then profileFrameDraw.sectionEnd();
3408 end;
3410 procedure drawOther (profname: AnsiString; cb: TDrawCB);
3411 begin
3412 if (profileFrameDraw <> nil) then profileFrameDraw.sectionBegin(profname);
3413 if assigned(cb) then cb();
3414 if (profileFrameDraw <> nil) then profileFrameDraw.sectionEnd();
3415 end;
3417 begin
3418 if (profileFrameDraw <> nil) then profileFrameDraw.sectionBegin('total');
3420 // our accelerated renderer will collect all panels to gDrawPanelList
3421 // we can use panel tag to render level parts (see GridTagXXX in g_map.pas)
3422 if (profileFrameDraw <> nil) then profileFrameDraw.sectionBegin('collect');
3423 if gdbg_map_use_accel_render then
3424 begin
3425 g_Map_CollectDrawPanels(sX, sY, sWidth, sHeight);
3426 end;
3427 if (profileFrameDraw <> nil) then profileFrameDraw.sectionEnd();
3429 if (profileFrameDraw <> nil) then profileFrameDraw.sectionBegin('skyback');
3430 g_Map_DrawBack(backXOfs, backYOfs);
3431 if (profileFrameDraw <> nil) then profileFrameDraw.sectionEnd();
3433 if setTransMatrix then
3434 begin
3435 //if (g_dbg_scale <> 1.0) then glTranslatef(0.0, -0.375/2, 0);
3436 glScalef(g_dbg_scale, g_dbg_scale, 1.0);
3437 glTranslatef(-sX, -sY, 0);
3438 end;
3440 // rendering mode
3441 ambColor := gCurrentMap['light_ambient'].rgba;
3442 hasAmbient := (not ambColor.isOpaque) or (not ambColor.isBlack);
3445 if hasAmbient then
3446 begin
3447 //writeln('color: (', ambColor.r, ',', ambColor.g, ',', ambColor.b, ',', ambColor.a, ')');
3448 glColor4ub(ambColor.r, ambColor.g, ambColor.b, ambColor.a);
3449 glClear(GL_COLOR_BUFFER_BIT);
3450 end;
3452 //writeln('color: (', ambColor.r, ',', ambColor.g, ',', ambColor.b, ',', ambColor.a, ')');
3455 drawPanelType('*back', PANEL_BACK, g_rlayer_back);
3456 drawPanelType('*step', PANEL_STEP, g_rlayer_step);
3457 drawOther('items', @g_Items_Draw);
3458 drawOther('weapons', @g_Weapon_Draw);
3459 drawOther('shells', @g_Player_DrawShells);
3460 drawOther('drawall', @g_Player_DrawAll);
3461 drawOther('corpses', @g_Player_DrawCorpses);
3462 drawPanelType('*wall', PANEL_WALL, g_rlayer_wall);
3463 drawOther('monsters', @g_Monsters_Draw);
3464 drawOther('itemdrop', @g_Items_DrawDrop);
3465 drawPanelType('*door', PANEL_CLOSEDOOR, g_rlayer_door);
3466 drawOther('gfx', @g_GFX_Draw);
3467 drawOther('flags', @g_Map_DrawFlags);
3468 drawPanelType('*acid1', PANEL_ACID1, g_rlayer_acid1);
3469 drawPanelType('*acid2', PANEL_ACID2, g_rlayer_acid2);
3470 drawPanelType('*water', PANEL_WATER, g_rlayer_water);
3471 drawOther('dynlights', @renderDynLightsInternal);
3473 if hasAmbient {and ((not g_playerLight) or (not gwin_has_stencil) or (g_dynLightCount < 1))} then
3474 begin
3475 renderAmbientQuad(hasAmbient, ambColor);
3476 end;
3478 doAmbient := true;
3479 drawPanelType('*fore', PANEL_FORE, g_rlayer_fore);
3482 if g_debug_HealthBar then
3483 begin
3484 g_Monsters_DrawHealth();
3485 g_Player_DrawHealth();
3486 end;
3488 if (profileFrameDraw <> nil) then profileFrameDraw.mainEnd(); // map rendering
3489 end;
3492 procedure DrawMapView(x, y, w, h: Integer);
3494 var
3495 bx, by: Integer;
3496 begin
3497 glPushMatrix();
3499 bx := Round(x/(gMapInfo.Width - w)*(gBackSize.X - w));
3500 by := Round(y/(gMapInfo.Height - h)*(gBackSize.Y - h));
3502 sX := x;
3503 sY := y;
3504 sWidth := w;
3505 sHeight := h;
3507 fixViewportForScale();
3508 renderMapInternal(-bx, -by, true);
3510 glPopMatrix();
3511 end;
3514 procedure DrawPlayer(p: TPlayer);
3515 var
3516 px, py, a, b, c, d, i: Integer;
3517 //R: TRect;
3518 begin
3519 if (p = nil) or (p.FDummy) then
3520 begin
3521 glPushMatrix();
3522 g_Map_DrawBack(0, 0);
3523 glPopMatrix();
3524 Exit;
3525 end;
3527 if (profileFrameDraw = nil) then profileFrameDraw := TProfiler.Create('RENDER', g_profile_history_size);
3528 if (profileFrameDraw <> nil) then profileFrameDraw.mainBegin(g_profile_frame_draw);
3530 gPlayerDrawn := p;
3532 glPushMatrix();
3534 px := p.GameX + PLAYER_RECT_CX;
3535 py := p.GameY + PLAYER_RECT_CY+p.Obj.slopeUpLeft;
3537 if (g_dbg_scale = 1.0) and (not g_dbg_ignore_bounds) then
3538 begin
3539 if (px > (gPlayerScreenSize.X div 2)) then a := -px+(gPlayerScreenSize.X div 2) else a := 0;
3540 if (py > (gPlayerScreenSize.Y div 2)) then b := -py+(gPlayerScreenSize.Y div 2) else b := 0;
3542 if (px > gMapInfo.Width-(gPlayerScreenSize.X div 2)) then a := -gMapInfo.Width+gPlayerScreenSize.X;
3543 if (py > gMapInfo.Height-(gPlayerScreenSize.Y div 2)) then b := -gMapInfo.Height+gPlayerScreenSize.Y;
3545 if (gMapInfo.Width = gPlayerScreenSize.X) then a := 0
3546 else if (gMapInfo.Width < gPlayerScreenSize.X) then
3547 begin
3548 // hcenter
3549 a := (gPlayerScreenSize.X-gMapInfo.Width) div 2;
3550 end;
3552 if (gMapInfo.Height = gPlayerScreenSize.Y) then b := 0
3553 else if (gMapInfo.Height < gPlayerScreenSize.Y) then
3554 begin
3555 // vcenter
3556 b := (gPlayerScreenSize.Y-gMapInfo.Height) div 2;
3557 end;
3558 end
3559 else
3560 begin
3561 // scaled, ignore level bounds
3562 a := -px+(gPlayerScreenSize.X div 2);
3563 b := -py+(gPlayerScreenSize.Y div 2);
3564 end;
3566 if p.IncCam <> 0 then
3567 begin
3568 if py > gMapInfo.Height-(gPlayerScreenSize.Y div 2) then
3569 begin
3570 if p.IncCam > 120-(py-(gMapInfo.Height-(gPlayerScreenSize.Y div 2))) then
3571 begin
3572 p.IncCam := 120-(py-(gMapInfo.Height-(gPlayerScreenSize.Y div 2)));
3573 end;
3574 end;
3576 if py < gPlayerScreenSize.Y div 2 then
3577 begin
3578 if p.IncCam < -120+((gPlayerScreenSize.Y div 2)-py) then
3579 begin
3580 p.IncCam := -120+((gPlayerScreenSize.Y div 2)-py);
3581 end;
3582 end;
3584 if p.IncCam < 0 then
3585 begin
3586 while (py+(gPlayerScreenSize.Y div 2)-p.IncCam > gMapInfo.Height) and (p.IncCam < 0) do p.IncCam := p.IncCam+1; //Inc(p.IncCam);
3587 end;
3589 if p.IncCam > 0 then
3590 begin
3591 while (py-(gPlayerScreenSize.Y div 2)-p.IncCam < 0) and (p.IncCam > 0) do p.IncCam := p.IncCam-1; //Dec(p.IncCam);
3592 end;
3593 end;
3595 if (px < gPlayerScreenSize.X div 2) or (gMapInfo.Width-gPlayerScreenSize.X <= 256) then c := 0
3596 else if (px > gMapInfo.Width-(gPlayerScreenSize.X div 2)) then c := gBackSize.X-gPlayerScreenSize.X
3597 else c := round((px-(gPlayerScreenSize.X div 2))/(gMapInfo.Width-gPlayerScreenSize.X)*(gBackSize.X-gPlayerScreenSize.X));
3599 if (py-p.IncCam <= gPlayerScreenSize.Y div 2) or (gMapInfo.Height-gPlayerScreenSize.Y <= 256) then d := 0
3600 else if (py-p.IncCam >= gMapInfo.Height-(gPlayerScreenSize.Y div 2)) then d := gBackSize.Y-gPlayerScreenSize.Y
3601 else d := round((py-p.IncCam-(gPlayerScreenSize.Y div 2))/(gMapInfo.Height-gPlayerScreenSize.Y)*(gBackSize.Y-gPlayerScreenSize.Y));
3603 sX := -a;
3604 sY := -(b+p.IncCam);
3605 sWidth := gPlayerScreenSize.X;
3606 sHeight := gPlayerScreenSize.Y;
3608 //glTranslatef(a, b+p.IncCam, 0);
3610 //if (p = gPlayer1) and (g_dbg_scale >= 1.0) then g_Holmes_plrViewSize(sWidth, sHeight);
3612 //conwritefln('OLD: (%s,%s)-(%s,%s)', [sX, sY, sWidth, sHeight]);
3613 fixViewportForScale();
3614 //conwritefln(' (%s,%s)-(%s,%s)', [sX, sY, sWidth, sHeight]);
3616 if (g_dbg_scale <> 1.0) and (not g_dbg_ignore_bounds) then
3617 begin
3618 if (sX+sWidth > gMapInfo.Width) then sX := gMapInfo.Width-sWidth;
3619 if (sY+sHeight > gMapInfo.Height) then sY := gMapInfo.Height-sHeight;
3620 if (sX < 0) then sX := 0;
3621 if (sY < 0) then sY := 0;
3623 if (gBackSize.X <= gPlayerScreenSize.X) or (gMapInfo.Width <= sWidth) then c := 0 else c := trunc((gBackSize.X-gPlayerScreenSize.X)*sX/(gMapInfo.Width-sWidth));
3624 if (gBackSize.Y <= gPlayerScreenSize.Y) or (gMapInfo.Height <= sHeight) then d := 0 else d := trunc((gBackSize.Y-gPlayerScreenSize.Y)*sY/(gMapInfo.Height-sHeight));
3625 end;
3627 //r_smallmap_h: 0: left; 1: center; 2: right
3628 //r_smallmap_v: 0: top; 1: center; 2: bottom
3629 // horiz small map?
3630 if (gMapInfo.Width = sWidth) then
3631 begin
3632 sX := 0;
3633 end
3634 else if (gMapInfo.Width < sWidth) then
3635 begin
3636 case r_smallmap_h of
3637 1: sX := -((sWidth-gMapInfo.Width) div 2); // center
3638 2: sX := -(sWidth-gMapInfo.Width); // right
3639 else sX := 0; // left
3640 end;
3641 end;
3642 // vert small map?
3643 if (gMapInfo.Height = sHeight) then
3644 begin
3645 sY := 0;
3646 end
3647 else if (gMapInfo.Height < sHeight) then
3648 begin
3649 case r_smallmap_v of
3650 1: sY := -((sHeight-gMapInfo.Height) div 2); // center
3651 2: sY := -(sHeight-gMapInfo.Height); // bottom
3652 else sY := 0; // top
3653 end;
3654 end;
3656 p.viewPortX := sX;
3657 p.viewPortY := sY;
3658 p.viewPortW := sWidth;
3659 p.viewPortH := sHeight;
3661 {$IFDEF ENABLE_HOLMES}
3662 if (p = gPlayer1) then
3663 begin
3664 g_Holmes_plrViewPos(sX, sY);
3665 g_Holmes_plrViewSize(sWidth, sHeight);
3666 end;
3667 {$ENDIF}
3669 renderMapInternal(-c, -d, true);
3671 if (gGameSettings.GameMode <> GM_SINGLE) and (gPlayerIndicator > 0) then
3672 case gPlayerIndicator of
3673 1:
3674 p.DrawIndicator(_RGB(255, 255, 255));
3676 2:
3677 for i := 0 to High(gPlayers) do
3678 if gPlayers[i] <> nil then
3679 if gPlayers[i] = p then p.DrawIndicator(_RGB(255, 255, 255))
3680 else if (gPlayers[i].Team = p.Team) and (gPlayers[i].Team <> TEAM_NONE) then
3681 if gPlayerIndicatorStyle = 1 then
3682 gPlayers[i].DrawIndicator(_RGB(192, 192, 192))
3683 else gPlayers[i].DrawIndicator(gPlayers[i].GetColor);
3684 end;
3686 if p.FSpectator then
3687 e_TextureFontPrintEx(p.GameX + PLAYER_RECT_CX - 4,
3688 p.GameY + PLAYER_RECT_CY - 4,
3689 'X', gStdFont, 255, 255, 255, 1, True);
3691 for a := 0 to High(gCollideMap) do
3692 for b := 0 to High(gCollideMap[a]) do
3693 begin
3694 d := 0;
3695 if ByteBool(gCollideMap[a, b] and MARK_WALL) then
3696 d := d + 1;
3697 if ByteBool(gCollideMap[a, b] and MARK_DOOR) then
3698 d := d + 2;
3700 case d of
3701 1: e_DrawPoint(1, b, a, 200, 200, 200);
3702 2: e_DrawPoint(1, b, a, 64, 64, 255);
3703 3: e_DrawPoint(1, b, a, 255, 0, 255);
3704 end;
3705 end;
3708 glPopMatrix();
3710 p.DrawPain();
3711 p.DrawPickup();
3712 p.DrawRulez();
3713 if gShowMap then DrawMinimap(p, _TRect(0, 0, 128, 128));
3714 if g_Debug_Player then
3715 g_Player_DrawDebug(p);
3716 p.DrawGUI();
3717 end;
3719 procedure drawProfilers ();
3720 var
3721 px: Integer = -1;
3722 py: Integer = -1;
3723 begin
3724 if g_profile_frame_draw and (profileFrameDraw <> nil) then px := px-drawProfiles(px, py, profileFrameDraw);
3725 if g_profile_collision and (profMapCollision <> nil) then begin px := px-drawProfiles(px, py, profMapCollision); py -= calcProfilesHeight(profMonsLOS); end;
3726 if g_profile_los and (profMonsLOS <> nil) then begin px := px-drawProfiles(px, py, profMonsLOS); py -= calcProfilesHeight(profMonsLOS); end;
3727 end;
3729 procedure g_Game_Draw();
3730 var
3731 ID: DWORD;
3732 w, h: Word;
3733 ww, hh: Byte;
3734 Time: Int64;
3735 back: string;
3736 plView1, plView2: TPlayer;
3737 Split: Boolean;
3738 begin
3739 if gExit = EXIT_QUIT then Exit;
3741 Time := sys_GetTicks() {div 1000};
3742 FPSCounter := FPSCounter+1;
3743 if Time - FPSTime >= 1000 then
3744 begin
3745 FPS := FPSCounter;
3746 FPSCounter := 0;
3747 FPSTime := Time;
3748 end;
3750 if gGameOn or (gState = STATE_FOLD) then
3751 begin
3752 if (gPlayer1 <> nil) and (gPlayer2 <> nil) then
3753 begin
3754 gSpectMode := SPECT_NONE;
3755 if not gRevertPlayers then
3756 begin
3757 plView1 := gPlayer1;
3758 plView2 := gPlayer2;
3759 end
3760 else
3761 begin
3762 plView1 := gPlayer2;
3763 plView2 := gPlayer1;
3764 end;
3765 end
3766 else
3767 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
3768 begin
3769 gSpectMode := SPECT_NONE;
3770 if gPlayer2 = nil then
3771 plView1 := gPlayer1
3772 else
3773 plView1 := gPlayer2;
3774 plView2 := nil;
3775 end
3776 else
3777 begin
3778 plView1 := nil;
3779 plView2 := nil;
3780 end;
3782 if (plView1 = nil) and (plView2 = nil) and (gSpectMode = SPECT_NONE) then
3783 gSpectMode := SPECT_STATS;
3785 if gSpectMode = SPECT_PLAYERS then
3786 if gPlayers <> nil then
3787 begin
3788 plView1 := GetActivePlayer_ByID(gSpectPID1);
3789 if plView1 = nil then
3790 begin
3791 gSpectPID1 := GetActivePlayerID_Next();
3792 plView1 := GetActivePlayer_ByID(gSpectPID1);
3793 end;
3794 if gSpectViewTwo then
3795 begin
3796 plView2 := GetActivePlayer_ByID(gSpectPID2);
3797 if plView2 = nil then
3798 begin
3799 gSpectPID2 := GetActivePlayerID_Next();
3800 plView2 := GetActivePlayer_ByID(gSpectPID2);
3801 end;
3802 end;
3803 end;
3805 if gSpectMode = SPECT_MAPVIEW then
3806 begin
3807 // Ðåæèì ïðîñìîòðà êàðòû
3808 Split := False;
3809 e_SetViewPort(0, 0, gScreenWidth, gScreenHeight);
3810 DrawMapView(gSpectX, gSpectY, gScreenWidth, gScreenHeight);
3811 gHearPoint1.Active := True;
3812 gHearPoint1.Coords.X := gScreenWidth div 2 + gSpectX;
3813 gHearPoint1.Coords.Y := gScreenHeight div 2 + gSpectY;
3814 gHearPoint2.Active := False;
3815 end
3816 else
3817 begin
3818 Split := (plView1 <> nil) and (plView2 <> nil);
3820 // Òî÷êè ñëóõà èãðîêîâ
3821 if plView1 <> nil then
3822 begin
3823 gHearPoint1.Active := True;
3824 gHearPoint1.Coords.X := plView1.GameX + PLAYER_RECT.Width;
3825 gHearPoint1.Coords.Y := plView1.GameY + PLAYER_RECT.Height DIV 2;
3826 end else
3827 gHearPoint1.Active := False;
3828 if plView2 <> nil then
3829 begin
3830 gHearPoint2.Active := True;
3831 gHearPoint2.Coords.X := plView2.GameX + PLAYER_RECT.Width;
3832 gHearPoint2.Coords.Y := plView2.GameY + PLAYER_RECT.Height DIV 2;
3833 end else
3834 gHearPoint2.Active := False;
3836 // Ðàçìåð ýêðàíîâ èãðîêîâ:
3837 gPlayerScreenSize.X := gScreenWidth-196;
3838 if Split then
3839 begin
3840 gPlayerScreenSize.Y := gScreenHeight div 2;
3841 if gScreenHeight mod 2 = 0 then
3842 Dec(gPlayerScreenSize.Y);
3843 end
3844 else
3845 gPlayerScreenSize.Y := gScreenHeight;
3847 if Split then
3848 if gScreenHeight mod 2 = 0 then
3849 e_SetViewPort(0, gPlayerScreenSize.Y+2, gPlayerScreenSize.X+196, gPlayerScreenSize.Y)
3850 else
3851 e_SetViewPort(0, gPlayerScreenSize.Y+1, gPlayerScreenSize.X+196, gPlayerScreenSize.Y);
3853 DrawPlayer(plView1);
3854 gPlayer1ScreenCoord.X := sX;
3855 gPlayer1ScreenCoord.Y := sY;
3857 if Split then
3858 begin
3859 e_SetViewPort(0, 0, gPlayerScreenSize.X+196, gPlayerScreenSize.Y);
3861 DrawPlayer(plView2);
3862 gPlayer2ScreenCoord.X := sX;
3863 gPlayer2ScreenCoord.Y := sY;
3864 end;
3866 e_SetViewPort(0, 0, gScreenWidth, gScreenHeight);
3868 if Split then
3869 e_DrawLine(2, 0, gScreenHeight div 2, gScreenWidth, gScreenHeight div 2, 0, 0, 0);
3870 end;
3872 {$IFDEF ENABLE_HOLMES}
3873 // draw inspector
3874 if (g_holmes_enabled) then g_Holmes_Draw();
3875 {$ENDIF}
3877 if MessageText <> '' then
3878 begin
3879 w := 0;
3880 h := 0;
3881 e_CharFont_GetSizeFmt(gMenuFont, MessageText, w, h);
3882 if Split then
3883 e_CharFont_PrintFmt(gMenuFont, (gScreenWidth div 2)-(w div 2),
3884 (gScreenHeight div 2)-(h div 2), MessageText)
3885 else
3886 e_CharFont_PrintFmt(gMenuFont, (gScreenWidth div 2)-(w div 2),
3887 Round(gScreenHeight / 2.75)-(h div 2), MessageText);
3888 end;
3890 if IsDrawStat or (gSpectMode = 1) then DrawStat();
3892 if gSpectHUD and (not gChatShow) and (gSpectMode <> SPECT_NONE) and (not gSpectAuto) then
3893 begin
3894 // Draw spectator GUI
3895 ww := 0;
3896 hh := 0;
3897 e_TextureFontGetSize(gStdFont, ww, hh);
3898 case gSpectMode of
3899 SPECT_STATS:
3900 e_TextureFontPrintEx(0, gScreenHeight - (hh+2)*2, 'MODE: Stats', gStdFont, 255, 255, 255, 1);
3901 SPECT_MAPVIEW:
3902 e_TextureFontPrintEx(0, gScreenHeight - (hh+2)*2, 'MODE: Observe Map', gStdFont, 255, 255, 255, 1);
3903 SPECT_PLAYERS:
3904 e_TextureFontPrintEx(0, gScreenHeight - (hh+2)*2, 'MODE: Watch Players', gStdFont, 255, 255, 255, 1);
3905 end;
3906 e_TextureFontPrintEx(2*ww, gScreenHeight - (hh+2), '< jump >', gStdFont, 255, 255, 255, 1);
3907 if gSpectMode = SPECT_STATS then
3908 begin
3909 e_TextureFontPrintEx(16*ww, gScreenHeight - (hh+2)*2, 'Autoview', gStdFont, 255, 255, 255, 1);
3910 e_TextureFontPrintEx(16*ww, gScreenHeight - (hh+2), '< fire >', gStdFont, 255, 255, 255, 1);
3911 end;
3912 if gSpectMode = SPECT_MAPVIEW then
3913 begin
3914 e_TextureFontPrintEx(22*ww, gScreenHeight - (hh+2)*2, '[-]', gStdFont, 255, 255, 255, 1);
3915 e_TextureFontPrintEx(26*ww, gScreenHeight - (hh+2)*2, 'Step ' + IntToStr(gSpectStep), gStdFont, 255, 255, 255, 1);
3916 e_TextureFontPrintEx(34*ww, gScreenHeight - (hh+2)*2, '[+]', gStdFont, 255, 255, 255, 1);
3917 e_TextureFontPrintEx(18*ww, gScreenHeight - (hh+2), '<prev weap>', gStdFont, 255, 255, 255, 1);
3918 e_TextureFontPrintEx(30*ww, gScreenHeight - (hh+2), '<next weap>', gStdFont, 255, 255, 255, 1);
3919 end;
3920 if gSpectMode = SPECT_PLAYERS then
3921 begin
3922 e_TextureFontPrintEx(22*ww, gScreenHeight - (hh+2)*2, 'Player 1', gStdFont, 255, 255, 255, 1);
3923 e_TextureFontPrintEx(20*ww, gScreenHeight - (hh+2), '<left/right>', gStdFont, 255, 255, 255, 1);
3924 if gSpectViewTwo then
3925 begin
3926 e_TextureFontPrintEx(37*ww, gScreenHeight - (hh+2)*2, 'Player 2', gStdFont, 255, 255, 255, 1);
3927 e_TextureFontPrintEx(34*ww, gScreenHeight - (hh+2), '<prev w/next w>', gStdFont, 255, 255, 255, 1);
3928 e_TextureFontPrintEx(52*ww, gScreenHeight - (hh+2)*2, '2x View', gStdFont, 255, 255, 255, 1);
3929 e_TextureFontPrintEx(51*ww, gScreenHeight - (hh+2), '<up/down>', gStdFont, 255, 255, 255, 1);
3930 end
3931 else
3932 begin
3933 e_TextureFontPrintEx(35*ww, gScreenHeight - (hh+2)*2, '2x View', gStdFont, 255, 255, 255, 1);
3934 e_TextureFontPrintEx(34*ww, gScreenHeight - (hh+2), '<up/down>', gStdFont, 255, 255, 255, 1);
3935 end;
3936 end;
3937 end;
3938 end;
3940 if gPauseMain and gGameOn and (g_ActiveWindow = nil) then
3941 begin
3942 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
3943 e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
3945 e_CharFont_GetSize(gMenuFont, _lc[I_MENU_PAUSE], w, h);
3946 e_CharFont_Print(gMenuFont, (gScreenWidth div 2)-(w div 2),
3947 (gScreenHeight div 2)-(h div 2), _lc[I_MENU_PAUSE]);
3948 end;
3950 if not gGameOn then
3951 begin
3952 if (gState = STATE_MENU) then
3953 begin
3954 if (g_ActiveWindow = nil) or (g_ActiveWindow.BackTexture = '') then DrawMenuBackground('MENU_BACKGROUND');
3955 // F3 at menu will show game loading dialog
3956 if e_KeyPressed(IK_F3) then g_Menu_Show_LoadMenu(true);
3957 if (g_ActiveWindow <> nil) then
3958 begin
3959 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
3960 e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
3961 end
3962 else
3963 begin
3964 // F3 at titlepic will show game loading dialog
3965 if e_KeyPressed(IK_F3) then
3966 begin
3967 g_Menu_Show_LoadMenu(true);
3968 if (g_ActiveWindow <> nil) then e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
3969 end;
3970 end;
3971 end;
3973 if gState = STATE_FOLD then
3974 begin
3975 e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 0, 0, 0, EndingGameCounter);
3976 end;
3978 if gState = STATE_INTERCUSTOM then
3979 begin
3980 if gLastMap and (gGameSettings.GameMode = GM_COOP) then
3981 begin
3982 back := 'TEXTURE_endpic';
3983 if not g_Texture_Get(back, ID) then
3984 back := _lc[I_TEXTURE_ENDPIC];
3985 end
3986 else
3987 back := 'INTER';
3989 DrawMenuBackground(back);
3991 DrawCustomStat();
3993 if g_ActiveWindow <> nil then
3994 begin
3995 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
3996 e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
3997 end;
3998 end;
4000 if gState = STATE_INTERSINGLE then
4001 begin
4002 if EndingGameCounter > 0 then
4003 begin
4004 e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 0, 0, 0, EndingGameCounter);
4005 end
4006 else
4007 begin
4008 back := 'INTER';
4010 DrawMenuBackground(back);
4012 DrawSingleStat();
4014 if g_ActiveWindow <> nil then
4015 begin
4016 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4017 e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
4018 end;
4019 end;
4020 end;
4022 if gState = STATE_ENDPIC then
4023 begin
4024 ID := DWORD(-1);
4025 if g_Texture_Get('TEXTURE_endpic', ID) then DrawMenuBackground('TEXTURE_endpic')
4026 else DrawMenuBackground(_lc[I_TEXTURE_ENDPIC]);
4028 if g_ActiveWindow <> nil then
4029 begin
4030 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4031 e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
4032 end;
4033 end;
4035 if gState = STATE_SLIST then
4036 begin
4037 // if g_Texture_Get('MENU_BACKGROUND', ID) then
4038 // begin
4039 // e_DrawSize(ID, 0, 0, 0, False, False, gScreenWidth, gScreenHeight);
4040 // //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4041 // end;
4042 DrawMenuBackground('MENU_BACKGROUND');
4043 e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
4044 g_Serverlist_Draw(slCurrent, slTable);
4045 end;
4046 end;
4048 if g_ActiveWindow <> nil then
4049 begin
4050 if gGameOn then
4051 begin
4052 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4053 e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
4054 end;
4055 g_ActiveWindow.Draw();
4056 end;
4058 {$IFNDEF HEADLESS}
4059 g_Console_Draw();
4060 {$ENDIF}
4062 if g_debug_Sounds and gGameOn then
4063 begin
4064 for w := 0 to High(e_SoundsArray) do
4065 for h := 0 to e_SoundsArray[w].nRefs do
4066 e_DrawPoint(1, w+100, h+100, 255, 0, 0);
4067 end;
4069 if gShowFPS then
4070 begin
4071 e_TextureFontPrint(0, 0, Format('FPS: %d', [FPS]), gStdFont);
4072 e_TextureFontPrint(0, 16, Format('UPS: %d', [UPS]), gStdFont);
4073 end;
4075 if gGameOn and gShowTime then
4076 drawTime(gScreenWidth-72, gScreenHeight-16);
4078 if gGameOn then drawProfilers();
4080 {$IFDEF ENABLE_HOLMES}
4081 g_Holmes_DrawUI();
4082 {$ENDIF}
4084 g_Touch_Draw;
4085 end;
4087 procedure g_Game_Quit();
4088 begin
4089 g_Game_StopAllSounds(True);
4090 gMusic.Free();
4091 g_Game_SaveOptions();
4092 g_Game_FreeData();
4093 g_PlayerModel_FreeData();
4094 g_Texture_DeleteAll();
4095 g_Frames_DeleteAll();
4096 {$IFNDEF HEADLESS}
4097 //g_Menu_Free(); //k8: this segfaults after resolution change; who cares?
4098 {$ENDIF}
4100 if NetInitDone then g_Net_Free;
4102 // Íàäî óäàëèòü êàðòó ïîñëå òåñòà:
4103 if gMapToDelete <> '' then
4104 g_Game_DeleteTestMap();
4106 gExit := EXIT_QUIT;
4107 sys_RequestQuit;
4108 end;
4110 procedure g_FatalError(Text: String);
4111 begin
4112 g_Console_Add(Format(_lc[I_FATAL_ERROR], [Text]), True);
4113 e_WriteLog(Format(_lc[I_FATAL_ERROR], [Text]), TMsgType.Warning);
4115 gExit := EXIT_SIMPLE;
4116 end;
4118 procedure g_SimpleError(Text: String);
4119 begin
4120 g_Console_Add(Format(_lc[I_SIMPLE_ERROR], [Text]), True);
4121 e_WriteLog(Format(_lc[I_SIMPLE_ERROR], [Text]), TMsgType.Warning);
4122 end;
4124 procedure g_Game_SetupScreenSize();
4125 const
4126 RES_FACTOR = 4.0 / 3.0;
4127 var
4128 s: Single;
4129 rf: Single;
4130 bw, bh: Word;
4131 begin
4132 // Ðàçìåð ýêðàíîâ èãðîêîâ:
4133 gPlayerScreenSize.X := gScreenWidth-196;
4134 if (gPlayer1 <> nil) and (gPlayer2 <> nil) then
4135 gPlayerScreenSize.Y := gScreenHeight div 2
4136 else
4137 gPlayerScreenSize.Y := gScreenHeight;
4139 // Ðàçìåð çàäíåãî ïëàíà:
4140 if BackID <> DWORD(-1) then
4141 begin
4142 s := SKY_STRETCH;
4143 if (gScreenWidth*s > gMapInfo.Width) or
4144 (gScreenHeight*s > gMapInfo.Height) then
4145 begin
4146 gBackSize.X := gScreenWidth;
4147 gBackSize.Y := gScreenHeight;
4148 end
4149 else
4150 begin
4151 e_GetTextureSize(BackID, @bw, @bh);
4152 rf := Single(bw) / Single(bh);
4153 if (rf > RES_FACTOR) then bw := Round(Single(bh) * RES_FACTOR)
4154 else if (rf < RES_FACTOR) then bh := Round(Single(bw) / RES_FACTOR);
4155 s := Max(gScreenWidth / bw, gScreenHeight / bh);
4156 if (s < 1.0) then s := 1.0;
4157 gBackSize.X := Round(bw*s);
4158 gBackSize.Y := Round(bh*s);
4159 end;
4160 end;
4161 end;
4163 procedure g_Game_ChangeResolution(newWidth, newHeight: Word; nowFull, nowMax: Boolean);
4164 begin
4165 sys_SetDisplayMode(newWidth, newHeight, gBPP, nowFull);
4166 end;
4168 procedure g_Game_AddPlayer(Team: Byte = TEAM_NONE);
4169 begin
4170 if ((not gGameOn) and (gState <> STATE_INTERCUSTOM))
4171 or (not (gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT])) then
4172 Exit;
4173 if gPlayer1 = nil then
4174 begin
4175 if g_Game_IsClient then
4176 begin
4177 if NetPlrUID1 > -1 then
4178 begin
4179 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE);
4180 gPlayer1 := g_Player_Get(NetPlrUID1);
4181 end;
4182 Exit;
4183 end;
4185 if not (Team in [TEAM_RED, TEAM_BLUE]) then
4186 Team := gPlayer1Settings.Team;
4188 // Ñîçäàíèå ïåðâîãî èãðîêà:
4189 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
4190 gPlayer1Settings.Color,
4191 Team, False));
4192 if gPlayer1 = nil then
4193 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]))
4194 else
4195 begin
4196 gPlayer1.Name := gPlayer1Settings.Name;
4197 g_Console_Add(Format(_lc[I_PLAYER_JOIN], [gPlayer1.Name]), True);
4198 if g_Game_IsServer and g_Game_IsNet then
4199 MH_SEND_PlayerCreate(gPlayer1.UID);
4200 gPlayer1.Respawn(False, True);
4201 g_Net_Slist_ServerPlayerComes();
4202 end;
4204 Exit;
4205 end;
4206 if gPlayer2 = nil then
4207 begin
4208 if g_Game_IsClient then
4209 begin
4210 if NetPlrUID2 > -1 then
4211 gPlayer2 := g_Player_Get(NetPlrUID2);
4212 Exit;
4213 end;
4215 if not (Team in [TEAM_RED, TEAM_BLUE]) then
4216 Team := gPlayer2Settings.Team;
4218 // Ñîçäàíèå âòîðîãî èãðîêà:
4219 gPlayer2 := g_Player_Get(g_Player_Create(gPlayer2Settings.Model,
4220 gPlayer2Settings.Color,
4221 Team, False));
4222 if gPlayer2 = nil then
4223 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [2]))
4224 else
4225 begin
4226 gPlayer2.Name := gPlayer2Settings.Name;
4227 g_Console_Add(Format(_lc[I_PLAYER_JOIN], [gPlayer2.Name]), True);
4228 if g_Game_IsServer and g_Game_IsNet then
4229 MH_SEND_PlayerCreate(gPlayer2.UID);
4230 gPlayer2.Respawn(False, True);
4231 g_Net_Slist_ServerPlayerComes();
4232 end;
4234 Exit;
4235 end;
4236 end;
4238 procedure g_Game_RemovePlayer();
4239 var
4240 Pl: TPlayer;
4241 begin
4242 if ((not gGameOn) and (gState <> STATE_INTERCUSTOM))
4243 or (not (gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT])) then
4244 Exit;
4245 Pl := gPlayer2;
4246 if Pl <> nil then
4247 begin
4248 if g_Game_IsServer then
4249 begin
4250 Pl.Lives := 0;
4251 Pl.Kill(K_SIMPLEKILL, 0, HIT_DISCON);
4252 g_Console_Add(Format(_lc[I_PLAYER_LEAVE], [Pl.Name]), True);
4253 g_Player_Remove(Pl.UID);
4254 g_Net_Slist_ServerPlayerLeaves();
4255 end else
4256 gPlayer2 := nil;
4257 Exit;
4258 end;
4259 Pl := gPlayer1;
4260 if Pl <> nil then
4261 begin
4262 if g_Game_IsServer then
4263 begin
4264 Pl.Lives := 0;
4265 Pl.Kill(K_SIMPLEKILL, 0, HIT_DISCON);
4266 g_Console_Add(Format(_lc[I_PLAYER_LEAVE], [Pl.Name]), True);
4267 g_Player_Remove(Pl.UID);
4268 g_Net_Slist_ServerPlayerLeaves();
4269 end else
4270 begin
4271 gPlayer1 := nil;
4272 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE);
4273 end;
4274 Exit;
4275 end;
4276 g_Net_Slist_ServerPlayerLeaves();
4277 end;
4279 procedure g_Game_Spectate();
4280 begin
4281 g_Game_RemovePlayer();
4282 if gPlayer1 <> nil then
4283 g_Game_RemovePlayer();
4284 end;
4286 procedure g_Game_SpectateCenterView();
4287 begin
4288 gSpectX := Max(gMapInfo.Width div 2 - gScreenWidth div 2, 0);
4289 gSpectY := Max(gMapInfo.Height div 2 - gScreenHeight div 2, 0);
4290 end;
4292 procedure g_Game_StartSingle(Map: String; TwoPlayers: Boolean; nPlayers: Byte);
4293 var
4294 i, nPl: Integer;
4295 tmps: AnsiString;
4296 begin
4297 g_Game_Free();
4299 e_WriteLog('Starting singleplayer game...', TMsgType.Notify);
4301 g_Game_ClearLoading();
4303 // Íàñòðîéêè èãðû:
4304 FillByte(gGameSettings, SizeOf(TGameSettings), 0);
4305 gAimLine := False;
4306 gShowMap := False;
4307 gGameSettings.GameType := GT_SINGLE;
4308 gGameSettings.MaxLives := 0;
4309 gGameSettings.Options := gGameSettings.Options + GAME_OPTION_ALLOWEXIT;
4310 gGameSettings.Options := gGameSettings.Options + GAME_OPTION_MONSTERS;
4311 gGameSettings.Options := gGameSettings.Options + GAME_OPTION_BOTVSMONSTER;
4312 gSwitchGameMode := GM_SINGLE;
4314 g_Game_ExecuteEvent('ongamestart');
4316 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
4317 g_Game_SetupScreenSize();
4319 // Ñîçäàíèå ïåðâîãî èãðîêà:
4320 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
4321 gPlayer1Settings.Color,
4322 gPlayer1Settings.Team, False));
4323 if gPlayer1 = nil then
4324 begin
4325 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]));
4326 Exit;
4327 end;
4329 gPlayer1.Name := gPlayer1Settings.Name;
4330 nPl := 1;
4332 // Ñîçäàíèå âòîðîãî èãðîêà, åñëè åñòü:
4333 if TwoPlayers then
4334 begin
4335 gPlayer2 := g_Player_Get(g_Player_Create(gPlayer2Settings.Model,
4336 gPlayer2Settings.Color,
4337 gPlayer2Settings.Team, False));
4338 if gPlayer2 = nil then
4339 begin
4340 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [2]));
4341 Exit;
4342 end;
4344 gPlayer2.Name := gPlayer2Settings.Name;
4345 Inc(nPl);
4346 end;
4348 // Çàãðóçêà è çàïóñê êàðòû:
4349 if not g_Game_StartMap(MAP, True) then
4350 begin
4351 if (Pos(':\', Map) > 0) or (Pos(':/', Map) > 0) then tmps := Map else tmps := gGameSettings.WAD + ':\' + MAP;
4352 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [tmps]));
4353 Exit;
4354 end;
4356 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4357 g_Player_Init();
4359 // Ñîçäàåì áîòîâ:
4360 for i := nPl+1 to nPlayers do
4361 g_Player_Create(STD_PLAYER_MODEL, _RGB(0, 0, 0), 0, True);
4362 end;
4364 procedure g_Game_StartCustom(Map: String; GameMode: Byte;
4365 TimeLimit, GoalLimit: Word;
4366 MaxLives: Byte;
4367 Options: LongWord; nPlayers: Byte);
4368 var
4369 i, nPl: Integer;
4370 begin
4371 g_Game_Free();
4373 e_WriteLog('Starting custom game...', TMsgType.Notify);
4375 g_Game_ClearLoading();
4377 // Íàñòðîéêè èãðû:
4378 gGameSettings.GameType := GT_CUSTOM;
4379 gGameSettings.GameMode := GameMode;
4380 gSwitchGameMode := GameMode;
4381 gGameSettings.TimeLimit := TimeLimit;
4382 gGameSettings.GoalLimit := GoalLimit;
4383 gGameSettings.MaxLives := IfThen(GameMode = GM_CTF, 0, MaxLives);
4384 gGameSettings.Options := Options;
4386 gCoopTotalMonstersKilled := 0;
4387 gCoopTotalSecretsFound := 0;
4388 gCoopTotalMonsters := 0;
4389 gCoopTotalSecrets := 0;
4390 gAimLine := False;
4391 gShowMap := False;
4393 g_Game_ExecuteEvent('ongamestart');
4395 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
4396 g_Game_SetupScreenSize();
4398 // Ðåæèì íàáëþäàòåëÿ:
4399 if nPlayers = 0 then
4400 begin
4401 gPlayer1 := nil;
4402 gPlayer2 := nil;
4403 end;
4405 nPl := 0;
4406 if nPlayers >= 1 then
4407 begin
4408 // Ñîçäàíèå ïåðâîãî èãðîêà:
4409 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
4410 gPlayer1Settings.Color,
4411 gPlayer1Settings.Team, False));
4412 if gPlayer1 = nil then
4413 begin
4414 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]));
4415 Exit;
4416 end;
4418 gPlayer1.Name := gPlayer1Settings.Name;
4419 Inc(nPl);
4420 end;
4422 if nPlayers >= 2 then
4423 begin
4424 // Ñîçäàíèå âòîðîãî èãðîêà:
4425 gPlayer2 := g_Player_Get(g_Player_Create(gPlayer2Settings.Model,
4426 gPlayer2Settings.Color,
4427 gPlayer2Settings.Team, False));
4428 if gPlayer2 = nil then
4429 begin
4430 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [2]));
4431 Exit;
4432 end;
4434 gPlayer2.Name := gPlayer2Settings.Name;
4435 Inc(nPl);
4436 end;
4438 // Çàãðóçêà è çàïóñê êàðòû:
4439 if not g_Game_StartMap(Map, True) then
4440 begin
4441 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [Map]));
4442 Exit;
4443 end;
4445 // Íåò òî÷åê ïîÿâëåíèÿ:
4446 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1) +
4447 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2) +
4448 g_Map_GetPointCount(RESPAWNPOINT_DM) +
4449 g_Map_GetPointCount(RESPAWNPOINT_RED)+
4450 g_Map_GetPointCount(RESPAWNPOINT_BLUE)) < 1 then
4451 begin
4452 g_FatalError(_lc[I_GAME_ERROR_GET_SPAWN]);
4453 Exit;
4454 end;
4456 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4457 g_Player_Init();
4459 // Ñîçäàåì áîòîâ:
4460 for i := nPl+1 to nPlayers do
4461 g_Player_Create(STD_PLAYER_MODEL, _RGB(0, 0, 0), 0, True);
4462 end;
4464 procedure g_Game_StartServer(Map: String; GameMode: Byte;
4465 TimeLimit, GoalLimit: Word; MaxLives: Byte;
4466 Options: LongWord; nPlayers: Byte;
4467 IPAddr: LongWord; Port: Word);
4468 begin
4469 g_Game_Free();
4470 g_Net_Slist_ServerClosed();
4472 e_WriteLog('Starting net game (server)...', TMsgType.Notify);
4474 g_Game_ClearLoading();
4476 // Íàñòðîéêè èãðû:
4477 gGameSettings.GameType := GT_SERVER;
4478 gGameSettings.GameMode := GameMode;
4479 gSwitchGameMode := GameMode;
4480 gGameSettings.TimeLimit := TimeLimit;
4481 gGameSettings.GoalLimit := GoalLimit;
4482 gGameSettings.MaxLives := IfThen(GameMode = GM_CTF, 0, MaxLives);
4483 gGameSettings.Options := Options;
4485 gCoopTotalMonstersKilled := 0;
4486 gCoopTotalSecretsFound := 0;
4487 gCoopTotalMonsters := 0;
4488 gCoopTotalSecrets := 0;
4489 gAimLine := False;
4490 gShowMap := False;
4492 g_Game_ExecuteEvent('ongamestart');
4494 // Óñòàíîâêà ðàçìåðîâ îêíà èãðîêà
4495 g_Game_SetupScreenSize();
4497 // Ðåæèì íàáëþäàòåëÿ:
4498 if nPlayers = 0 then
4499 begin
4500 gPlayer1 := nil;
4501 gPlayer2 := nil;
4502 end;
4504 if nPlayers >= 1 then
4505 begin
4506 // Ñîçäàíèå ïåðâîãî èãðîêà:
4507 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
4508 gPlayer1Settings.Color,
4509 gPlayer1Settings.Team, False));
4510 if gPlayer1 = nil then
4511 begin
4512 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]));
4513 Exit;
4514 end;
4516 gPlayer1.Name := gPlayer1Settings.Name;
4517 end;
4519 if nPlayers >= 2 then
4520 begin
4521 // Ñîçäàíèå âòîðîãî èãðîêà:
4522 gPlayer2 := g_Player_Get(g_Player_Create(gPlayer2Settings.Model,
4523 gPlayer2Settings.Color,
4524 gPlayer2Settings.Team, False));
4525 if gPlayer2 = nil then
4526 begin
4527 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [2]));
4528 Exit;
4529 end;
4531 gPlayer2.Name := gPlayer2Settings.Name;
4532 end;
4534 g_Game_SetLoadingText(_lc[I_LOAD_HOST], 0, False);
4535 if NetForwardPorts then
4536 g_Game_SetLoadingText(_lc[I_LOAD_PORTS], 0, False);
4538 // Ñòàðòóåì ñåðâåð
4539 if not g_Net_Host(IPAddr, Port, NetMaxClients) then
4540 begin
4541 g_FatalError(_lc[I_NET_MSG] + _lc[I_NET_ERR_HOST]);
4542 Exit;
4543 end;
4545 g_Net_Slist_Set(NetSlistIP, NetSlistPort);
4547 g_Net_Slist_ServerStarted();
4549 // Çàãðóçêà è çàïóñê êàðòû:
4550 if not g_Game_StartMap(Map, True) then
4551 begin
4552 g_Net_Slist_ServerClosed();
4553 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [Map]));
4554 Exit;
4555 end;
4557 // Íåò òî÷åê ïîÿâëåíèÿ:
4558 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1) +
4559 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2) +
4560 g_Map_GetPointCount(RESPAWNPOINT_DM) +
4561 g_Map_GetPointCount(RESPAWNPOINT_RED)+
4562 g_Map_GetPointCount(RESPAWNPOINT_BLUE)) < 1 then
4563 begin
4564 g_Net_Slist_ServerClosed();
4565 g_FatalError(_lc[I_GAME_ERROR_GET_SPAWN]);
4566 Exit;
4567 end;
4569 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4570 g_Player_Init();
4572 g_Net_Slist_ServerMapStarted();
4573 NetState := NET_STATE_GAME;
4574 end;
4576 procedure g_Game_StartClient(Addr: String; Port: Word; PW: String);
4577 var
4578 Map: String;
4579 WadName: string;
4580 Ptr: Pointer;
4581 T: Cardinal;
4582 MID: Byte;
4583 State: Byte;
4584 OuterLoop: Boolean;
4585 newResPath: string;
4586 InMsg: TMsg;
4587 begin
4588 g_Game_Free();
4590 State := 0;
4591 e_WriteLog('Starting net game (client)...', TMsgType.Notify);
4592 e_WriteLog('NET: Trying to connect to ' + Addr + ':' + IntToStr(Port) + '...', TMsgType.Notify);
4594 g_Game_ClearLoading();
4596 // Íàñòðîéêè èãðû:
4597 gGameSettings.GameType := GT_CLIENT;
4599 gCoopTotalMonstersKilled := 0;
4600 gCoopTotalSecretsFound := 0;
4601 gCoopTotalMonsters := 0;
4602 gCoopTotalSecrets := 0;
4603 gAimLine := False;
4604 gShowMap := False;
4606 g_Game_ExecuteEvent('ongamestart');
4608 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
4609 g_Game_SetupScreenSize();
4611 NetState := NET_STATE_AUTH;
4613 g_Game_SetLoadingText(_lc[I_LOAD_CONNECT], 0, False);
4615 // create (or update) map/resource databases
4616 g_Res_CreateDatabases(true);
4618 // Ñòàðòóåì êëèåíò
4619 if not g_Net_Connect(Addr, Port) then
4620 begin
4621 g_FatalError(_lc[I_NET_MSG] + _lc[I_NET_ERR_CONN]);
4622 NetState := NET_STATE_NONE;
4623 Exit;
4624 end;
4626 g_Game_SetLoadingText(_lc[I_LOAD_SEND_INFO], 0, False);
4627 MC_SEND_Info(PW);
4628 g_Game_SetLoadingText(_lc[I_LOAD_WAIT_INFO], 0, False);
4630 OuterLoop := True;
4631 while OuterLoop do
4632 begin
4633 while (enet_host_service(NetHost, @NetEvent, 50) > 0) do
4634 begin
4635 if (NetEvent.kind = ENET_EVENT_TYPE_RECEIVE) then
4636 begin
4637 if (NetEvent.channelID = NET_CHAN_DOWNLOAD_EX) then
4638 begin
4639 // ignore all download packets, they're processed by separate code
4640 enet_packet_destroy(NetEvent.packet);
4641 continue;
4642 end;
4643 Ptr := NetEvent.packet^.data;
4644 if not InMsg.Init(Ptr, NetEvent.packet^.dataLength, True) then
4645 begin
4646 enet_packet_destroy(NetEvent.packet);
4647 continue;
4648 end;
4650 InMsg.ReadLongWord(); // skip size
4651 MID := InMsg.ReadByte();
4653 if (MID = NET_MSG_INFO) and (State = 0) then
4654 begin
4655 NetMyID := InMsg.ReadByte();
4656 NetPlrUID1 := InMsg.ReadWord();
4658 WadName := InMsg.ReadString();
4659 Map := InMsg.ReadString();
4661 gWADHash := InMsg.ReadMD5();
4663 gGameSettings.GameMode := InMsg.ReadByte();
4664 gSwitchGameMode := gGameSettings.GameMode;
4665 gGameSettings.GoalLimit := InMsg.ReadWord();
4666 gGameSettings.TimeLimit := InMsg.ReadWord();
4667 gGameSettings.MaxLives := InMsg.ReadByte();
4668 gGameSettings.Options := InMsg.ReadLongWord();
4669 T := InMsg.ReadLongWord();
4671 //newResPath := g_Res_SearchSameWAD(MapsDir, WadName, gWADHash);
4672 //if newResPath = '' then
4673 begin
4674 //g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
4675 newResPath := g_Res_DownloadMapWAD(WadName, gWADHash);
4676 if newResPath = '' then
4677 begin
4678 g_FatalError(_lc[I_NET_ERR_HASH]);
4679 enet_packet_destroy(NetEvent.packet);
4680 NetState := NET_STATE_NONE;
4681 Exit;
4682 end;
4683 e_LogWritefln('using downloaded map wad [%s] for [%s]`', [newResPath, WadName], TMsgType.Notify);
4684 end;
4685 newResPath := ExtractRelativePath(MapsDir, newResPath);
4687 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
4688 gPlayer1Settings.Color,
4689 gPlayer1Settings.Team, False));
4691 if gPlayer1 = nil then
4692 begin
4693 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]));
4695 enet_packet_destroy(NetEvent.packet);
4696 NetState := NET_STATE_NONE;
4697 Exit;
4698 end;
4700 gPlayer1.Name := gPlayer1Settings.Name;
4701 gPlayer1.UID := NetPlrUID1;
4702 gPlayer1.Reset(True);
4704 if not g_Game_StartMap(newResPath + ':\' + Map, True) then
4705 begin
4706 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [WadName + ':\' + Map]));
4708 enet_packet_destroy(NetEvent.packet);
4709 NetState := NET_STATE_NONE;
4710 Exit;
4711 end;
4713 gTime := T;
4715 State := 1;
4716 OuterLoop := False;
4717 enet_packet_destroy(NetEvent.packet);
4718 break;
4719 end
4720 else
4721 enet_packet_destroy(NetEvent.packet);
4722 end
4723 else
4724 begin
4725 if (NetEvent.kind = ENET_EVENT_TYPE_DISCONNECT) then
4726 begin
4727 State := 0;
4728 if (NetEvent.data <= NET_DISC_MAX) then
4729 g_Console_Add(_lc[I_NET_MSG_ERROR] + _lc[I_NET_ERR_CONN] + ' ' +
4730 _lc[TStrings_Locale(Cardinal(I_NET_DISC_NONE) + NetEvent.data)], True);
4731 OuterLoop := False;
4732 Break;
4733 end;
4734 end;
4735 end;
4737 ProcessLoading(true);
4739 if g_Net_UserRequestExit() then
4740 begin
4741 State := 0;
4742 break;
4743 end;
4744 end;
4746 if State <> 1 then
4747 begin
4748 g_FatalError(_lc[I_NET_MSG] + _lc[I_NET_ERR_CONN]);
4749 NetState := NET_STATE_NONE;
4750 Exit;
4751 end;
4753 gLMSRespawn := LMS_RESPAWN_NONE;
4754 gLMSRespawnTime := 0;
4756 g_Player_Init();
4757 NetState := NET_STATE_GAME;
4758 MC_SEND_FullStateRequest;
4759 e_WriteLog('NET: Connection successful.', TMsgType.Notify);
4760 end;
4762 procedure g_Game_SaveOptions();
4763 begin
4764 g_Options_Write_Video(GameDir+'/'+CONFIG_FILENAME);
4765 end;
4767 procedure g_Game_ChangeMap(const MapPath: String);
4768 var
4769 Force: Boolean;
4770 begin
4771 g_Game_ClearLoading();
4773 Force := gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF];
4774 // Åñëè óðîâåíü çàâåðøèëñÿ ïî òðèããåðó Âûõîä, íå î÷èùàòü èíâåíòàðü
4775 if gExitByTrigger then
4776 begin
4777 Force := False;
4778 gExitByTrigger := False;
4779 end;
4780 if not g_Game_StartMap(MapPath, Force) then
4781 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [MapPath]));
4782 end;
4784 procedure g_Game_Restart();
4785 var
4786 Map: string;
4787 begin
4788 if g_Game_IsClient then
4789 Exit;
4790 map := g_ExtractFileName(gMapInfo.Map);
4792 MessageTime := 0;
4793 gGameOn := False;
4794 g_Game_ClearLoading();
4795 g_Game_StartMap(Map, True, gCurrentMapFileName);
4796 end;
4798 function g_Game_StartMap(Map: String; Force: Boolean = False; const oldMapPath: AnsiString=''): Boolean;
4799 var
4800 NewWAD, ResName: String;
4801 I: Integer;
4802 nws: AnsiString;
4803 begin
4804 g_Map_Free((Map <> gCurrentMapFileName) and (oldMapPath <> gCurrentMapFileName));
4805 g_Player_RemoveAllCorpses();
4807 if (not g_Game_IsClient) and
4808 (gSwitchGameMode <> gGameSettings.GameMode) and
4809 (gGameSettings.GameMode <> GM_SINGLE) then
4810 begin
4811 if gSwitchGameMode = GM_CTF then
4812 gGameSettings.MaxLives := 0;
4813 gGameSettings.GameMode := gSwitchGameMode;
4814 Force := True;
4815 end else
4816 gSwitchGameMode := gGameSettings.GameMode;
4818 g_Player_ResetTeams();
4820 if isWadPath(Map) then
4821 begin
4822 NewWAD := g_ExtractWadName(Map);
4823 ResName := g_ExtractFileName(Map);
4824 if g_Game_IsServer then
4825 begin
4826 nws := findDiskWad(MapsDir+NewWAD);
4827 if (length(nws) = 0) then
4828 begin
4829 ResName := '';
4830 end
4831 else
4832 begin
4833 if (g_Game_IsNet) then gWADHash := MD5File(nws);
4834 //writeln('********: nws=', nws, ' : Map=', Map, ' : nw=', NewWAD, ' : resname=', ResName);
4835 g_Game_LoadWAD(NewWAD);
4836 end;
4837 end else
4838 // hash received in MC_RECV_GameEvent -> NET_EV_MAPSTART
4839 g_Game_ClientWAD(NewWAD, gWADHash);
4840 end else
4841 ResName := Map;
4843 //writeln('********: gsw=', gGameSettings.WAD, '; rn=', ResName);
4844 Result := (ResName <> '') and g_Map_Load(MapsDir + gGameSettings.WAD + ':\' + ResName);
4845 if Result then
4846 begin
4847 g_Player_ResetAll(Force or gLastMap, gGameSettings.GameType = GT_SINGLE);
4849 gState := STATE_NONE;
4850 g_ActiveWindow := nil;
4851 gGameOn := True;
4853 DisableCheats();
4854 ResetTimer();
4856 if gGameSettings.GameMode = GM_CTF then
4857 begin
4858 g_Map_ResetFlag(FLAG_RED);
4859 g_Map_ResetFlag(FLAG_BLUE);
4860 // CTF, à ôëàãîâ íåò:
4861 if not g_Map_HaveFlagPoints() then
4862 g_SimpleError(_lc[I_GAME_ERROR_CTF]);
4863 end;
4864 end
4865 else
4866 begin
4867 gState := STATE_MENU;
4868 gGameOn := False;
4869 end;
4871 gExit := 0;
4872 gPauseMain := false;
4873 gPauseHolmes := false;
4874 gTime := 0;
4875 NetTimeToUpdate := 1;
4876 NetTimeToReliable := 0;
4877 NetTimeToMaster := NetMasterRate;
4878 gLMSRespawn := LMS_RESPAWN_NONE;
4879 gLMSRespawnTime := 0;
4880 gMissionFailed := False;
4881 gNextMap := '';
4883 gCoopMonstersKilled := 0;
4884 gCoopSecretsFound := 0;
4886 gVoteInProgress := False;
4887 gVotePassed := False;
4888 gVoteCount := 0;
4889 gVoted := False;
4891 gStatsOff := False;
4893 if not gGameOn then Exit;
4895 g_Game_SpectateCenterView();
4897 if (gGameSettings.MaxLives > 0) and (gGameSettings.WarmupTime > 0) then
4898 begin
4899 gLMSRespawn := LMS_RESPAWN_WARMUP;
4900 gLMSRespawnTime := gTime + gGameSettings.WarmupTime*1000;
4901 gLMSSoftSpawn := True;
4902 if NetMode = NET_SERVER then
4903 MH_SEND_GameEvent(NET_EV_LMS_WARMUP, (gLMSRespawnTime - gTime) div 1000)
4904 else
4905 g_Console_Add(Format(_lc[I_MSG_WARMUP_START], [(gLMSRespawnTime - gTime) div 1000]), True);
4906 end;
4908 if NetMode = NET_SERVER then
4909 begin
4910 MH_SEND_GameEvent(NET_EV_MAPSTART, gGameSettings.GameMode, Map);
4912 // Ìàñòåðñåðâåð
4913 g_Net_Slist_ServerMapStarted();
4915 if NetClients <> nil then
4916 for I := 0 to High(NetClients) do
4917 if NetClients[I].Used then
4918 begin
4919 NetClients[I].Voted := False;
4920 if NetClients[I].RequestedFullUpdate then
4921 begin
4922 MH_SEND_Everything((NetClients[I].State = NET_STATE_AUTH), I);
4923 NetClients[I].RequestedFullUpdate := False;
4924 end;
4925 end;
4927 g_Net_UnbanNonPermHosts();
4928 end;
4930 if gLastMap then
4931 begin
4932 gCoopTotalMonstersKilled := 0;
4933 gCoopTotalSecretsFound := 0;
4934 gCoopTotalMonsters := 0;
4935 gCoopTotalSecrets := 0;
4936 gLastMap := False;
4937 end;
4939 g_Game_ExecuteEvent('onmapstart');
4940 end;
4942 procedure SetFirstLevel();
4943 begin
4944 gNextMap := '';
4946 MapList := g_Map_GetMapsList(MapsDir + gGameSettings.WAD);
4947 if MapList = nil then
4948 Exit;
4950 SortSArray(MapList);
4951 gNextMap := MapList[Low(MapList)];
4953 MapList := nil;
4954 end;
4956 procedure g_Game_ExitLevel(const Map: AnsiString);
4957 begin
4958 gNextMap := Map;
4960 gCoopTotalMonstersKilled := gCoopTotalMonstersKilled + gCoopMonstersKilled;
4961 gCoopTotalSecretsFound := gCoopTotalSecretsFound + gCoopSecretsFound;
4962 gCoopTotalMonsters := gCoopTotalMonsters + gTotalMonsters;
4963 gCoopTotalSecrets := gCoopTotalSecrets + gSecretsCount;
4965 // Âûøëè â âûõîä â Îäèíî÷íîé èãðå:
4966 if gGameSettings.GameType = GT_SINGLE then
4967 gExit := EXIT_ENDLEVELSINGLE
4968 else // Âûøëè â âûõîä â Ñâîåé èãðå
4969 begin
4970 gExit := EXIT_ENDLEVELCUSTOM;
4971 if gGameSettings.GameMode = GM_COOP then
4972 g_Player_RememberAll;
4974 if not g_Map_Exist(MapsDir + gGameSettings.WAD + ':\' + gNextMap) then
4975 begin
4976 gLastMap := True;
4977 if gGameSettings.GameMode = GM_COOP then
4978 gStatsOff := True;
4980 gStatsPressed := True;
4981 gNextMap := 'MAP01';
4983 if not g_Map_Exist(MapsDir + gGameSettings.WAD + ':\' + gNextMap) then
4984 g_Game_NextLevel;
4986 if g_Game_IsNet then
4987 begin
4988 MH_SEND_GameStats();
4989 MH_SEND_CoopStats();
4990 end;
4991 end;
4992 end;
4993 end;
4995 procedure g_Game_RestartLevel();
4996 var
4997 Map: string;
4998 begin
4999 if gGameSettings.GameMode = GM_SINGLE then
5000 begin
5001 g_Game_Restart();
5002 Exit;
5003 end;
5004 gExit := EXIT_ENDLEVELCUSTOM;
5005 Map := g_ExtractFileName(gMapInfo.Map);
5006 gNextMap := Map;
5007 end;
5009 procedure g_Game_ClientWAD(NewWAD: String; const WHash: TMD5Digest);
5010 var
5011 gWAD, xwad: String;
5012 begin
5013 if not g_Game_IsClient then Exit;
5014 //e_LogWritefln('*** g_Game_ClientWAD: `%s`', [NewWAD]);
5016 gWAD := g_Res_DownloadMapWAD(ExtractFileName(NewWAD), WHash);
5017 if gWAD = '' then
5018 begin
5019 g_Game_Free();
5020 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_WAD], [ExtractFileName(NewWAD)]));
5021 Exit;
5022 end;
5024 xwad := ExtractRelativePath(MapsDir, gWAD);
5025 e_LogWritefln('using downloaded client map wad [%s] for [%s]`', [xwad, NewWAD], TMsgType.Notify);
5026 NewWAD := xwad;
5027 g_Game_LoadWAD(NewWAD);
5030 if LowerCase(NewWAD) = LowerCase(gGameSettings.WAD) then Exit;
5031 gWAD := g_Res_SearchSameWAD(MapsDir, ExtractFileName(NewWAD), WHash);
5032 if gWAD = '' then
5033 begin
5034 g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
5035 gWAD := g_Res_DownloadMapWAD(ExtractFileName(NewWAD), WHash);
5036 if gWAD = '' then
5037 begin
5038 g_Game_Free();
5039 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_WAD], [ExtractFileName(NewWAD)]));
5040 Exit;
5041 end;
5042 end;
5043 NewWAD := ExtractRelativePath(MapsDir, gWAD);
5044 g_Game_LoadWAD(NewWAD);
5046 end;
5048 procedure g_Game_RestartRound(NoMapRestart: Boolean = False);
5049 var
5050 i, n, nb, nr: Integer;
5052 function monRespawn (mon: TMonster): Boolean;
5053 begin
5054 result := false; // don't stop
5055 if not mon.FNoRespawn then mon.Respawn();
5056 end;
5058 begin
5059 if not g_Game_IsServer then Exit;
5060 if gLMSRespawn = LMS_RESPAWN_NONE then Exit;
5061 gLMSRespawn := LMS_RESPAWN_NONE;
5062 gLMSRespawnTime := 0;
5063 MessageTime := 0;
5065 if (gGameSettings.GameMode = GM_COOP) and not NoMapRestart then
5066 begin
5067 gMissionFailed := True;
5068 g_Game_RestartLevel;
5069 Exit;
5070 end;
5072 n := 0; nb := 0; nr := 0;
5073 for i := Low(gPlayers) to High(gPlayers) do
5074 if (gPlayers[i] <> nil) and
5075 ((not gPlayers[i].FSpectator) or gPlayers[i].FWantsInGame or
5076 (gPlayers[i] is TBot)) then
5077 begin
5078 Inc(n);
5079 if gPlayers[i].Team = TEAM_RED then Inc(nr)
5080 else if gPlayers[i].Team = TEAM_BLUE then Inc(nb)
5081 end;
5083 if (n < 2) or ((gGameSettings.GameMode = GM_TDM) and ((nr = 0) or (nb = 0))) then
5084 begin
5085 // wait a second until the fuckers finally decide to join
5086 gLMSRespawn := LMS_RESPAWN_WARMUP;
5087 gLMSRespawnTime := gTime + 1000;
5088 gLMSSoftSpawn := NoMapRestart;
5089 Exit;
5090 end;
5092 g_Player_RemoveAllCorpses;
5093 g_Game_Message(_lc[I_MESSAGE_LMS_START], 144);
5094 if g_Game_IsNet then
5095 MH_SEND_GameEvent(NET_EV_LMS_START);
5097 for i := Low(gPlayers) to High(gPlayers) do
5098 begin
5099 if gPlayers[i] = nil then continue;
5100 if gPlayers[i] is TBot then gPlayers[i].FWantsInGame := True;
5101 // don't touch normal spectators
5102 if gPlayers[i].FSpectator and not gPlayers[i].FWantsInGame then
5103 begin
5104 gPlayers[i].FNoRespawn := True;
5105 gPlayers[i].Lives := 0;
5106 if g_Game_IsNet then
5107 MH_SEND_PlayerStats(gPlayers[I].UID);
5108 continue;
5109 end;
5110 gPlayers[i].FNoRespawn := False;
5111 gPlayers[i].Lives := gGameSettings.MaxLives;
5112 gPlayers[i].Respawn(False, True);
5113 if gGameSettings.GameMode = GM_COOP then
5114 begin
5115 gPlayers[i].Frags := 0;
5116 gPlayers[i].RecallState;
5117 end;
5118 if (gPlayer1 = nil) and (gLMSPID1 > 0) then
5119 gPlayer1 := g_Player_Get(gLMSPID1);
5120 if (gPlayer2 = nil) and (gLMSPID2 > 0) then
5121 gPlayer2 := g_Player_Get(gLMSPID2);
5122 end;
5124 g_Items_RestartRound();
5127 g_Mons_ForEach(monRespawn);
5129 gLMSSoftSpawn := False;
5130 end;
5132 function g_Game_GetFirstMap(WAD: String): String;
5133 begin
5134 Result := '';
5136 MapList := g_Map_GetMapsList(WAD);
5137 if MapList = nil then
5138 Exit;
5140 SortSArray(MapList);
5141 Result := MapList[Low(MapList)];
5143 if not g_Map_Exist(WAD + ':\' + Result) then
5144 Result := '';
5146 MapList := nil;
5147 end;
5149 function g_Game_GetNextMap(): String;
5150 var
5151 I: Integer;
5152 Map: string;
5153 begin
5154 Result := '';
5156 MapList := g_Map_GetMapsList(MapsDir + gGameSettings.WAD);
5157 if MapList = nil then
5158 Exit;
5160 Map := g_ExtractFileName(gMapInfo.Map);
5162 SortSArray(MapList);
5163 MapIndex := -255;
5164 for I := Low(MapList) to High(MapList) do
5165 if Map = MapList[I] then
5166 begin
5167 MapIndex := I;
5168 Break;
5169 end;
5171 if MapIndex <> -255 then
5172 begin
5173 if MapIndex = High(MapList) then
5174 Result := MapList[Low(MapList)]
5175 else
5176 Result := MapList[MapIndex + 1];
5178 if not g_Map_Exist(MapsDir + gGameSettings.WAD + ':\' + Result) then Result := Map;
5179 end;
5181 MapList := nil;
5182 end;
5184 procedure g_Game_NextLevel();
5185 begin
5186 if gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF, GM_COOP] then
5187 gExit := EXIT_ENDLEVELCUSTOM
5188 else
5189 begin
5190 gExit := EXIT_ENDLEVELSINGLE;
5191 Exit;
5192 end;
5194 if gNextMap <> '' then Exit;
5195 gNextMap := g_Game_GetNextMap();
5196 end;
5198 function g_Game_IsTestMap(): Boolean;
5199 begin
5200 result := StrEquCI1251(TEST_MAP_NAME, g_ExtractFileName(gMapInfo.Map));
5201 end;
5203 procedure g_Game_DeleteTestMap();
5204 var
5205 a: Integer;
5206 //MapName: AnsiString;
5207 WadName: string;
5209 WAD: TWADFile;
5210 MapList: SSArray;
5211 time: Integer;
5213 begin
5214 a := Pos('.wad:\', toLowerCase1251(gMapToDelete));
5215 if (a = 0) then a := Pos('.wad:/', toLowerCase1251(gMapToDelete));
5216 if (a = 0) then exit;
5218 // Âûäåëÿåì èìÿ wad-ôàéëà è èìÿ êàðòû
5219 WadName := Copy(gMapToDelete, 1, a+3);
5220 Delete(gMapToDelete, 1, a+5);
5221 gMapToDelete := UpperCase(gMapToDelete);
5222 //MapName := '';
5223 //CopyMemory(@MapName[0], @gMapToDelete[1], Min(16, Length(gMapToDelete)));
5226 // Èìÿ êàðòû íå ñòàíäàðòíîå òåñòîâîå:
5227 if MapName <> TEST_MAP_NAME then
5228 Exit;
5230 if not gTempDelete then
5231 begin
5232 time := g_GetFileTime(WadName);
5233 WAD := TWADFile.Create();
5235 // ×èòàåì Wad-ôàéë:
5236 if not WAD.ReadFile(WadName) then
5237 begin // Íåò òàêîãî WAD-ôàéëà
5238 WAD.Free();
5239 Exit;
5240 end;
5242 // Ñîñòàâëÿåì ñïèñîê êàðò è èùåì íóæíóþ:
5243 WAD.CreateImage();
5244 MapList := WAD.GetResourcesList('');
5246 if MapList <> nil then
5247 for a := 0 to High(MapList) do
5248 if MapList[a] = MapName then
5249 begin
5250 // Óäàëÿåì è ñîõðàíÿåì:
5251 WAD.RemoveResource('', MapName);
5252 WAD.SaveTo(WadName);
5253 Break;
5254 end;
5256 WAD.Free();
5257 g_SetFileTime(WadName, time);
5258 end else
5260 if gTempDelete then DeleteFile(WadName);
5261 end;
5263 procedure GameCVars(P: SSArray);
5264 var
5265 a, b: Integer;
5266 stat: TPlayerStatArray;
5267 cmd, s: string;
5268 config: TConfig;
5269 begin
5270 stat := nil;
5271 cmd := LowerCase(P[0]);
5272 if (cmd = 'g_friendlyfire') and not g_Game_IsClient then
5273 begin
5274 with gGameSettings do
5275 begin
5276 if (Length(P) > 1) and
5277 ((P[1] = '1') or (P[1] = '0')) then
5278 begin
5279 if (P[1][1] = '1') then
5280 Options := Options or GAME_OPTION_TEAMDAMAGE
5281 else
5282 Options := Options and (not GAME_OPTION_TEAMDAMAGE);
5283 end;
5285 if (LongBool(Options and GAME_OPTION_TEAMDAMAGE)) then
5286 g_Console_Add(_lc[I_MSG_FRIENDLY_FIRE_ON])
5287 else
5288 g_Console_Add(_lc[I_MSG_FRIENDLY_FIRE_OFF]);
5290 if g_Game_IsNet then MH_SEND_GameSettings;
5291 end;
5292 end
5293 else if (cmd = 'g_weaponstay') and not g_Game_IsClient then
5294 begin
5295 with gGameSettings do
5296 begin
5297 if (Length(P) > 1) and
5298 ((P[1] = '1') or (P[1] = '0')) then
5299 begin
5300 if (P[1][1] = '1') then
5301 Options := Options or GAME_OPTION_WEAPONSTAY
5302 else
5303 Options := Options and (not GAME_OPTION_WEAPONSTAY);
5304 end;
5306 if (LongBool(Options and GAME_OPTION_WEAPONSTAY)) then
5307 g_Console_Add(_lc[I_MSG_WEAPONSTAY_ON])
5308 else
5309 g_Console_Add(_lc[I_MSG_WEAPONSTAY_OFF]);
5311 if g_Game_IsNet then MH_SEND_GameSettings;
5312 end;
5313 end
5314 else if cmd = 'g_gamemode' then
5315 begin
5316 a := g_Game_TextToMode(P[1]);
5317 if a = GM_SINGLE then a := GM_COOP;
5318 if (Length(P) > 1) and (a <> GM_NONE) and (not g_Game_IsClient) then
5319 begin
5320 gSwitchGameMode := a;
5321 if (gGameOn and (gGameSettings.GameMode = GM_SINGLE)) or
5322 (gState = STATE_INTERSINGLE) then
5323 gSwitchGameMode := GM_SINGLE;
5324 if not gGameOn then
5325 gGameSettings.GameMode := gSwitchGameMode;
5326 end;
5327 if gSwitchGameMode = gGameSettings.GameMode then
5328 g_Console_Add(Format(_lc[I_MSG_GAMEMODE_CURRENT],
5329 [g_Game_ModeToText(gGameSettings.GameMode)]))
5330 else
5331 g_Console_Add(Format(_lc[I_MSG_GAMEMODE_CHANGE],
5332 [g_Game_ModeToText(gGameSettings.GameMode),
5333 g_Game_ModeToText(gSwitchGameMode)]));
5334 end
5335 else if (cmd = 'g_allow_exit') and not g_Game_IsClient then
5336 begin
5337 with gGameSettings do
5338 begin
5339 if (Length(P) > 1) and
5340 ((P[1] = '1') or (P[1] = '0')) then
5341 begin
5342 if (P[1][1] = '1') then
5343 Options := Options or GAME_OPTION_ALLOWEXIT
5344 else
5345 Options := Options and (not GAME_OPTION_ALLOWEXIT);
5346 end;
5348 if (LongBool(Options and GAME_OPTION_ALLOWEXIT)) then
5349 g_Console_Add(_lc[I_MSG_ALLOWEXIT_ON])
5350 else
5351 g_Console_Add(_lc[I_MSG_ALLOWEXIT_OFF]);
5352 g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
5354 if g_Game_IsNet then MH_SEND_GameSettings;
5355 end;
5356 end
5357 else if (cmd = 'g_allow_monsters') and not g_Game_IsClient then
5358 begin
5359 with gGameSettings do
5360 begin
5361 if (Length(P) > 1) and
5362 ((P[1] = '1') or (P[1] = '0')) then
5363 begin
5364 if (P[1][1] = '1') then
5365 Options := Options or GAME_OPTION_MONSTERS
5366 else
5367 Options := Options and (not GAME_OPTION_MONSTERS);
5368 end;
5370 if (LongBool(Options and GAME_OPTION_MONSTERS)) then
5371 g_Console_Add(_lc[I_MSG_ALLOWMON_ON])
5372 else
5373 g_Console_Add(_lc[I_MSG_ALLOWMON_OFF]);
5374 g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
5376 if g_Game_IsNet then MH_SEND_GameSettings;
5377 end;
5378 end
5379 else if (cmd = 'g_bot_vsplayers') and not g_Game_IsClient then
5380 begin
5381 with gGameSettings do
5382 begin
5383 if (Length(P) > 1) and
5384 ((P[1] = '1') or (P[1] = '0')) then
5385 begin
5386 if (P[1][1] = '1') then
5387 Options := Options or GAME_OPTION_BOTVSPLAYER
5388 else
5389 Options := Options and (not GAME_OPTION_BOTVSPLAYER);
5390 end;
5392 if (LongBool(Options and GAME_OPTION_BOTVSPLAYER)) then
5393 g_Console_Add(_lc[I_MSG_BOTSVSPLAYERS_ON])
5394 else
5395 g_Console_Add(_lc[I_MSG_BOTSVSPLAYERS_OFF]);
5397 if g_Game_IsNet then MH_SEND_GameSettings;
5398 end;
5399 end
5400 else if (cmd = 'g_bot_vsmonsters') and not g_Game_IsClient then
5401 begin
5402 with gGameSettings do
5403 begin
5404 if (Length(P) > 1) and
5405 ((P[1] = '1') or (P[1] = '0')) then
5406 begin
5407 if (P[1][1] = '1') then
5408 Options := Options or GAME_OPTION_BOTVSMONSTER
5409 else
5410 Options := Options and (not GAME_OPTION_BOTVSMONSTER);
5411 end;
5413 if (LongBool(Options and GAME_OPTION_BOTVSMONSTER)) then
5414 g_Console_Add(_lc[I_MSG_BOTSVSMONSTERS_ON])
5415 else
5416 g_Console_Add(_lc[I_MSG_BOTSVSMONSTERS_OFF]);
5418 if g_Game_IsNet then MH_SEND_GameSettings;
5419 end;
5420 end
5421 else if (cmd = 'g_warmuptime') and not g_Game_IsClient then
5422 begin
5423 if Length(P) > 1 then
5424 begin
5425 if StrToIntDef(P[1], gGameSettings.WarmupTime) = 0 then
5426 gGameSettings.WarmupTime := 30
5427 else
5428 gGameSettings.WarmupTime := StrToIntDef(P[1], gGameSettings.WarmupTime);
5429 end;
5431 g_Console_Add(Format(_lc[I_MSG_WARMUP],
5432 [gGameSettings.WarmupTime]));
5433 g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
5434 end
5435 else if cmd = 'net_interp' then
5436 begin
5437 if (Length(P) > 1) then
5438 NetInterpLevel := StrToIntDef(P[1], NetInterpLevel);
5440 g_Console_Add('net_interp = ' + IntToStr(NetInterpLevel));
5441 config := TConfig.CreateFile(GameDir+'/'+CONFIG_FILENAME);
5442 config.WriteInt('Client', 'InterpolationSteps', NetInterpLevel);
5443 config.SaveFile(GameDir+'/'+CONFIG_FILENAME);
5444 config.Free();
5445 end
5446 else if cmd = 'net_forceplayerupdate' then
5447 begin
5448 if (Length(P) > 1) and
5449 ((P[1] = '1') or (P[1] = '0')) then
5450 NetForcePlayerUpdate := (P[1][1] = '1');
5452 if NetForcePlayerUpdate then
5453 g_Console_Add('net_forceplayerupdate = 1')
5454 else
5455 g_Console_Add('net_forceplayerupdate = 0');
5456 config := TConfig.CreateFile(GameDir+'/'+CONFIG_FILENAME);
5457 config.WriteBool('Client', 'ForcePlayerUpdate', NetForcePlayerUpdate);
5458 config.SaveFile(GameDir+'/'+CONFIG_FILENAME);
5459 config.Free();
5460 end
5461 else if cmd = 'net_predictself' then
5462 begin
5463 if (Length(P) > 1) and
5464 ((P[1] = '1') or (P[1] = '0')) then
5465 NetPredictSelf := (P[1][1] = '1');
5467 if NetPredictSelf then
5468 g_Console_Add('net_predictself = 1')
5469 else
5470 g_Console_Add('net_predictself = 0');
5471 config := TConfig.CreateFile(GameDir+'/'+CONFIG_FILENAME);
5472 config.WriteBool('Client', 'PredictSelf', NetPredictSelf);
5473 config.SaveFile(GameDir+'/'+CONFIG_FILENAME);
5474 config.Free();
5475 end
5476 else if cmd = 'sv_name' then
5477 begin
5478 if (Length(P) > 1) and (Length(P[1]) > 0) then
5479 begin
5480 NetServerName := P[1];
5481 if Length(NetServerName) > 64 then
5482 SetLength(NetServerName, 64);
5483 g_Net_Slist_ServerRenamed();
5484 end;
5486 g_Console_Add(cmd + ' = "' + NetServerName + '"');
5487 end
5488 else if cmd = 'sv_passwd' then
5489 begin
5490 if (Length(P) > 1) and (Length(P[1]) > 0) then
5491 begin
5492 NetPassword := P[1];
5493 if Length(NetPassword) > 24 then
5494 SetLength(NetPassword, 24);
5495 g_Net_Slist_ServerRenamed();
5496 end;
5498 g_Console_Add(cmd + ' = "' + AnsiLowerCase(NetPassword) + '"');
5499 end
5500 else if cmd = 'sv_maxplrs' then
5501 begin
5502 if (Length(P) > 1) then
5503 begin
5504 NetMaxClients := Min(Max(StrToIntDef(P[1], NetMaxClients), 1), NET_MAXCLIENTS);
5505 if g_Game_IsServer and g_Game_IsNet then
5506 begin
5507 b := 0;
5508 for a := 0 to High(NetClients) do
5509 begin
5510 if NetClients[a].Used then
5511 begin
5512 Inc(b);
5513 if b > NetMaxClients then
5514 begin
5515 s := g_Player_Get(NetClients[a].Player).Name;
5516 enet_peer_disconnect(NetClients[a].Peer, NET_DISC_FULL);
5517 g_Console_Add(Format(_lc[I_PLAYER_KICK], [s]));
5518 MH_SEND_GameEvent(NET_EV_PLAYER_KICK, 0, s);
5519 end;
5520 end;
5521 end;
5522 g_Net_Slist_ServerRenamed();
5523 end;
5524 end;
5526 g_Console_Add(cmd + ' = ' + IntToStr(NetMaxClients));
5527 end
5528 else if cmd = 'sv_public' then
5529 begin
5530 if (Length(P) > 1) then
5531 begin
5532 NetUseMaster := StrToIntDef(P[1], Byte(NetUseMaster)) > 0;
5533 if NetUseMaster then g_Net_Slist_Public() else g_Net_Slist_Private();
5534 end;
5536 g_Console_Add(cmd + ' = ' + IntToStr(Byte(NetUseMaster)));
5537 end
5538 else if cmd = 'sv_intertime' then
5539 begin
5540 if (Length(P) > 1) then
5541 gDefInterTime := Min(Max(StrToIntDef(P[1], gDefInterTime), -1), 120);
5543 g_Console_Add(cmd + ' = ' + IntToStr(gDefInterTime));
5544 end
5545 else if cmd = 'p1_name' then
5546 begin
5547 if (Length(P) > 1) and gGameOn then
5548 begin
5549 if g_Game_IsClient then
5550 begin
5551 gPlayer1Settings.Name := b_Text_Unformat(P[1]);
5552 MC_SEND_PlayerSettings;
5553 end
5554 else
5555 if gPlayer1 <> nil then
5556 begin
5557 gPlayer1.Name := b_Text_Unformat(P[1]);
5558 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer1.UID);
5559 end
5560 else
5561 gPlayer1Settings.Name := b_Text_Unformat(P[1]);
5562 end;
5563 end
5564 else if cmd = 'p2_name' then
5565 begin
5566 if (Length(P) > 1) and gGameOn then
5567 begin
5568 if g_Game_IsClient then
5569 begin
5570 gPlayer2Settings.Name := b_Text_Unformat(P[1]);
5571 MC_SEND_PlayerSettings;
5572 end
5573 else
5574 if gPlayer2 <> nil then
5575 begin
5576 gPlayer2.Name := b_Text_Unformat(P[1]);
5577 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer2.UID);
5578 end
5579 else
5580 gPlayer2Settings.Name := b_Text_Unformat(P[1]);
5581 end;
5582 end
5583 else if cmd = 'p1_color' then
5584 begin
5585 if Length(P) > 3 then
5586 if g_Game_IsClient then
5587 begin
5588 gPlayer1Settings.Color := _RGB(EnsureRange(StrToIntDef(P[1], 0), 0, 255),
5589 EnsureRange(StrToIntDef(P[2], 0), 0, 255),
5590 EnsureRange(StrToIntDef(P[3], 0), 0, 255));
5591 MC_SEND_PlayerSettings;
5592 end
5593 else
5594 if gPlayer1 <> nil then
5595 begin
5596 gPlayer1.Model.SetColor(EnsureRange(StrToIntDef(P[1], 0), 0, 255),
5597 EnsureRange(StrToIntDef(P[2], 0), 0, 255),
5598 EnsureRange(StrToIntDef(P[3], 0), 0, 255));
5599 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer1.UID);
5600 end
5601 else
5602 gPlayer1Settings.Color := _RGB(EnsureRange(StrToIntDef(P[1], 0), 0, 255),
5603 EnsureRange(StrToIntDef(P[2], 0), 0, 255),
5604 EnsureRange(StrToIntDef(P[3], 0), 0, 255));
5605 end
5606 else if (cmd = 'p2_color') and not g_Game_IsNet then
5607 begin
5608 if Length(P) > 3 then
5609 if g_Game_IsClient then
5610 begin
5611 gPlayer2Settings.Color := _RGB(EnsureRange(StrToIntDef(P[1], 0), 0, 255),
5612 EnsureRange(StrToIntDef(P[2], 0), 0, 255),
5613 EnsureRange(StrToIntDef(P[3], 0), 0, 255));
5614 MC_SEND_PlayerSettings;
5615 end
5616 else
5617 if gPlayer2 <> nil then
5618 begin
5619 gPlayer2.Model.SetColor(EnsureRange(StrToIntDef(P[1], 0), 0, 255),
5620 EnsureRange(StrToIntDef(P[2], 0), 0, 255),
5621 EnsureRange(StrToIntDef(P[3], 0), 0, 255));
5622 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer2.UID);
5623 end
5624 else
5625 gPlayer2Settings.Color := _RGB(EnsureRange(StrToIntDef(P[1], 0), 0, 255),
5626 EnsureRange(StrToIntDef(P[2], 0), 0, 255),
5627 EnsureRange(StrToIntDef(P[3], 0), 0, 255));
5628 end
5629 else if gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT] then
5630 begin
5631 if cmd = 'r_showscore' then
5632 begin
5633 if (Length(P) > 1) and
5634 ((P[1] = '1') or (P[1] = '0')) then
5635 gShowGoals := (P[1][1] = '1');
5637 if gShowGoals then
5638 g_Console_Add(_lc[I_MSG_SCORE_ON])
5639 else
5640 g_Console_Add(_lc[I_MSG_SCORE_OFF]);
5641 end
5642 else if cmd = 'r_showstat' then
5643 begin
5644 if (Length(P) > 1) and
5645 ((P[1] = '1') or (P[1] = '0')) then
5646 gShowStat := (P[1][1] = '1');
5648 if gShowStat then
5649 g_Console_Add(_lc[I_MSG_STATS_ON])
5650 else
5651 g_Console_Add(_lc[I_MSG_STATS_OFF]);
5652 end
5653 else if cmd = 'r_showkillmsg' then
5654 begin
5655 if (Length(P) > 1) and
5656 ((P[1] = '1') or (P[1] = '0')) then
5657 gShowKillMsg := (P[1][1] = '1');
5659 if gShowKillMsg then
5660 g_Console_Add(_lc[I_MSG_KILL_MSGS_ON])
5661 else
5662 g_Console_Add(_lc[I_MSG_KILL_MSGS_OFF]);
5663 end
5664 else if cmd = 'r_showlives' then
5665 begin
5666 if (Length(P) > 1) and
5667 ((P[1] = '1') or (P[1] = '0')) then
5668 gShowLives := (P[1][1] = '1');
5670 if gShowLives then
5671 g_Console_Add(_lc[I_MSG_LIVES_ON])
5672 else
5673 g_Console_Add(_lc[I_MSG_LIVES_OFF]);
5674 end
5675 else if cmd = 'r_showspect' then
5676 begin
5677 if (Length(P) > 1) and
5678 ((P[1] = '1') or (P[1] = '0')) then
5679 gSpectHUD := (P[1][1] = '1');
5681 if gSpectHUD then
5682 g_Console_Add(_lc[I_MSG_SPECT_HUD_ON])
5683 else
5684 g_Console_Add(_lc[I_MSG_SPECT_HUD_OFF]);
5685 end
5686 else if cmd = 'r_showping' then
5687 begin
5688 if (Length(P) > 1) and
5689 ((P[1] = '1') or (P[1] = '0')) then
5690 gShowPing := (P[1][1] = '1');
5692 if gShowPing then
5693 g_Console_Add(_lc[I_MSG_PING_ON])
5694 else
5695 g_Console_Add(_lc[I_MSG_PING_OFF]);
5696 end
5697 else if (cmd = 'g_scorelimit') and not g_Game_IsClient then
5698 begin
5699 if Length(P) > 1 then
5700 begin
5701 if StrToIntDef(P[1], gGameSettings.GoalLimit) = 0 then
5702 gGameSettings.GoalLimit := 0
5703 else
5704 begin
5705 b := 0;
5707 if gGameSettings.GameMode = GM_DM then
5708 begin // DM
5709 stat := g_Player_GetStats();
5710 if stat <> nil then
5711 for a := 0 to High(stat) do
5712 if stat[a].Frags > b then
5713 b := stat[a].Frags;
5714 end
5715 else // TDM/CTF
5716 b := Max(gTeamStat[TEAM_RED].Goals, gTeamStat[TEAM_BLUE].Goals);
5718 gGameSettings.GoalLimit := Max(StrToIntDef(P[1], gGameSettings.GoalLimit), b);
5719 end;
5721 if g_Game_IsNet then MH_SEND_GameSettings;
5722 end;
5724 g_Console_Add(Format(_lc[I_MSG_SCORE_LIMIT], [gGameSettings.GoalLimit]));
5725 end
5726 else if (cmd = 'g_timelimit') and not g_Game_IsClient then
5727 begin
5728 if (Length(P) > 1) and (StrToIntDef(P[1], -1) >= 0) then
5729 gGameSettings.TimeLimit := StrToIntDef(P[1], -1);
5731 g_Console_Add(Format(_lc[I_MSG_TIME_LIMIT],
5732 [gGameSettings.TimeLimit div 3600,
5733 (gGameSettings.TimeLimit div 60) mod 60,
5734 gGameSettings.TimeLimit mod 60]));
5735 if g_Game_IsNet then MH_SEND_GameSettings;
5736 end
5737 else if (cmd = 'g_maxlives') and not g_Game_IsClient then
5738 begin
5739 if Length(P) > 1 then
5740 begin
5741 if StrToIntDef(P[1], gGameSettings.MaxLives) = 0 then
5742 gGameSettings.MaxLives := 0
5743 else
5744 begin
5745 b := 0;
5746 stat := g_Player_GetStats();
5747 if stat <> nil then
5748 for a := 0 to High(stat) do
5749 if stat[a].Lives > b then
5750 b := stat[a].Lives;
5751 gGameSettings.MaxLives :=
5752 Max(StrToIntDef(P[1], gGameSettings.MaxLives), b);
5753 end;
5754 end;
5756 g_Console_Add(Format(_lc[I_MSG_LIVES],
5757 [gGameSettings.MaxLives]));
5758 if g_Game_IsNet then MH_SEND_GameSettings;
5759 end;
5760 end;
5761 end;
5763 procedure PrintHeapStats();
5764 var
5765 hs: TFPCHeapStatus;
5766 begin
5767 hs := GetFPCHeapStatus();
5768 e_LogWriteLn ('v===== heap status =====v');
5769 e_LogWriteFln('max heap size = %d k', [hs.MaxHeapSize div 1024]);
5770 e_LogWriteFln('max heap used = %d k', [hs.MaxHeapUsed div 1024]);
5771 e_LogWriteFln('cur heap size = %d k', [hs.CurrHeapSize div 1024]);
5772 e_LogWriteFln('cur heap used = %d k', [hs.CurrHeapUsed div 1024]);
5773 e_LogWriteFln('cur heap free = %d k', [hs.CurrHeapFree div 1024]);
5774 e_LogWriteLn ('^=======================^');
5775 end;
5777 procedure DebugCommands(P: SSArray);
5778 var
5779 a, b: Integer;
5780 cmd: string;
5781 //pt: TDFPoint;
5782 mon: TMonster;
5783 begin
5784 // Êîìàíäû îòëàäî÷íîãî ðåæèìà:
5785 if {gDebugMode}conIsCheatsEnabled then
5786 begin
5787 cmd := LowerCase(P[0]);
5788 if cmd = 'd_window' then
5789 begin
5790 g_Console_Add(Format('gWinPosX = %d, gWinPosY %d', [gWinPosX, gWinPosY]));
5791 g_Console_Add(Format('gWinRealPosX = %d, gWinRealPosY %d', [gWinRealPosX, gWinRealPosY]));
5792 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth, gScreenHeight]));
5793 g_Console_Add(Format('gWinSizeX = %d, gWinSizeY = %d', [gWinSizeX, gWinSizeY]));
5794 g_Console_Add(Format('Frame X = %d, Y = %d, Caption Y = %d', [gWinFrameX, gWinFrameY, gWinCaption]));
5795 end
5796 else if cmd = 'd_sounds' then
5797 begin
5798 if (Length(P) > 1) and
5799 ((P[1] = '1') or (P[1] = '0')) then
5800 g_Debug_Sounds := (P[1][1] = '1');
5802 g_Console_Add(Format('d_sounds is %d', [Byte(g_Debug_Sounds)]));
5803 end
5804 else if cmd = 'd_frames' then
5805 begin
5806 if (Length(P) > 1) and
5807 ((P[1] = '1') or (P[1] = '0')) then
5808 g_Debug_Frames := (P[1][1] = '1');
5810 g_Console_Add(Format('d_frames is %d', [Byte(g_Debug_Frames)]));
5811 end
5812 else if cmd = 'd_winmsg' then
5813 begin
5814 if (Length(P) > 1) and
5815 ((P[1] = '1') or (P[1] = '0')) then
5816 g_Debug_WinMsgs := (P[1][1] = '1');
5818 g_Console_Add(Format('d_winmsg is %d', [Byte(g_Debug_WinMsgs)]));
5819 end
5820 else if (cmd = 'd_monoff') and not g_Game_IsNet then
5821 begin
5822 if (Length(P) > 1) and
5823 ((P[1] = '1') or (P[1] = '0')) then
5824 g_Debug_MonsterOff := (P[1][1] = '1');
5826 g_Console_Add(Format('d_monoff is %d', [Byte(g_debug_MonsterOff)]));
5827 end
5828 else if (cmd = 'd_botoff') and not g_Game_IsNet then
5829 begin
5830 if Length(P) > 1 then
5831 case P[1][1] of
5832 '0': g_debug_BotAIOff := 0;
5833 '1': g_debug_BotAIOff := 1;
5834 '2': g_debug_BotAIOff := 2;
5835 '3': g_debug_BotAIOff := 3;
5836 end;
5838 g_Console_Add(Format('d_botoff is %d', [g_debug_BotAIOff]));
5839 end
5840 else if cmd = 'd_monster' then
5841 begin
5842 if gGameOn and (gPlayer1 <> nil) and (gPlayer1.alive) and (not g_Game_IsNet) then
5843 if Length(P) < 2 then
5844 begin
5845 g_Console_Add(cmd + ' [ID | Name] [behaviour]');
5846 g_Console_Add('ID | Name');
5847 for b := MONSTER_DEMON to MONSTER_MAN do
5848 g_Console_Add(Format('%2d | %s', [b, g_Mons_NameByTypeId(b)]));
5849 conwriteln('behav. num'#10'normal 0'#10'killer 1'#10'maniac 2'#10'insane 3'#10'cannibal 4'#10'good 5');
5850 end else
5851 begin
5852 a := StrToIntDef(P[1], 0);
5853 if (a < MONSTER_DEMON) or (a > MONSTER_MAN) then
5854 a := g_Mons_TypeIdByName(P[1]);
5856 if (a < MONSTER_DEMON) or (a > MONSTER_MAN) then
5857 g_Console_Add(Format(_lc[I_MSG_NO_MONSTER], [P[1]]))
5858 else
5859 begin
5860 with gPlayer1.Obj do
5861 begin
5862 mon := g_Monsters_Create(a,
5863 X + Rect.X + (Rect.Width div 2),
5864 Y + Rect.Y + Rect.Height,
5865 gPlayer1.Direction, True);
5866 end;
5867 if (Length(P) > 2) and (mon <> nil) then
5868 begin
5869 if (CompareText(P[2], 'normal') = 0) then mon.MonsterBehaviour := BH_NORMAL
5870 else if (CompareText(P[2], 'killer') = 0) then mon.MonsterBehaviour := BH_KILLER
5871 else if (CompareText(P[2], 'maniac') = 0) then mon.MonsterBehaviour := BH_MANIAC
5872 else if (CompareText(P[2], 'insane') = 0) then mon.MonsterBehaviour := BH_INSANE
5873 else if (CompareText(P[2], 'cannibal') = 0) then mon.MonsterBehaviour := BH_CANNIBAL
5874 else if (CompareText(P[2], 'good') = 0) then mon.MonsterBehaviour := BH_GOOD
5875 else if (CompareText(P[2], 'friend') = 0) then mon.MonsterBehaviour := BH_GOOD
5876 else if (CompareText(P[2], 'friendly') = 0) then mon.MonsterBehaviour := BH_GOOD
5877 else mon.MonsterBehaviour := Min(Max(StrToIntDef(P[2], BH_NORMAL), BH_NORMAL), BH_GOOD);
5878 end;
5879 end;
5880 end;
5881 end
5882 else if (cmd = 'd_health') then
5883 begin
5884 if (Length(P) > 1) and
5885 ((P[1] = '1') or (P[1] = '0')) then
5886 g_debug_HealthBar := (P[1][1] = '1');
5888 g_Console_Add(Format('d_health is %d', [Byte(g_debug_HealthBar)]));
5889 end
5890 else if (cmd = 'd_player') then
5891 begin
5892 if (Length(P) > 1) and
5893 ((P[1] = '1') or (P[1] = '0')) then
5894 g_debug_Player := (P[1][1] = '1');
5896 g_Console_Add(Format(cmd + ' is %d', [Byte(g_Debug_Player)]));
5897 end
5898 else if (cmd = 'd_mem') then
5899 begin
5900 PrintHeapStats();
5901 end;
5902 end
5903 else
5904 g_Console_Add(_lc[I_MSG_NOT_DEBUG]);
5905 end;
5908 procedure GameCheats(P: SSArray);
5909 var
5910 cmd: string;
5911 f, a: Integer;
5912 plr: TPlayer;
5913 begin
5914 if (not gGameOn) or (not conIsCheatsEnabled) then
5915 begin
5916 g_Console_Add('not available');
5917 exit;
5918 end;
5919 plr := gPlayer1;
5920 if plr = nil then
5921 begin
5922 g_Console_Add('where is the player?!');
5923 exit;
5924 end;
5925 cmd := LowerCase(P[0]);
5926 // god
5927 if cmd = 'god' then
5928 begin
5929 plr.GodMode := not plr.GodMode;
5930 if plr.GodMode then g_Console_Add('player is godlike now') else g_Console_Add('player is mortal now');
5931 exit;
5932 end;
5933 // give <health|exit|weapons|air|suit|jetpack|berserk|all>
5934 if cmd = 'give' then
5935 begin
5936 if length(P) < 2 then begin g_Console_Add('give what?!'); exit; end;
5937 for f := 1 to High(P) do
5938 begin
5939 cmd := LowerCase(P[f]);
5940 if cmd = 'health' then begin plr.RestoreHealthArmor(); g_Console_Add('player feels himself better'); continue; end;
5941 if (cmd = 'all') {or (cmd = 'weapons')} then begin plr.AllRulez(False); g_Console_Add('player got the gifts'); continue; end;
5942 if cmd = 'exit' then
5943 begin
5944 if gTriggers <> nil then
5945 begin
5946 for a := 0 to High(gTriggers) do
5947 begin
5948 if gTriggers[a].TriggerType = TRIGGER_EXIT then
5949 begin
5950 g_Console_Add('player left the map');
5951 gExitByTrigger := True;
5952 //g_Game_ExitLevel(gTriggers[a].Data.MapName);
5953 g_Game_ExitLevel(gTriggers[a].tgcMap);
5954 break;
5955 end;
5956 end;
5957 end;
5958 continue;
5959 end;
5961 if cmd = 'air' then begin plr.GiveItem(ITEM_OXYGEN); g_Console_Add('player got some air'); continue; end;
5962 if cmd = 'jetpack' then begin plr.GiveItem(ITEM_JETPACK); g_Console_Add('player got a jetpack'); continue; end;
5963 if cmd = 'suit' then begin plr.GiveItem(ITEM_SUIT); g_Console_Add('player got an envirosuit'); continue; end;
5964 if cmd = 'berserk' then begin plr.GiveItem(ITEM_MEDKIT_BLACK); g_Console_Add('player got a berserk pack'); continue; end;
5965 if cmd = 'backpack' then begin plr.GiveItem(ITEM_AMMO_BACKPACK); g_Console_Add('player got a backpack'); continue; end;
5967 if cmd = 'helmet' then begin plr.GiveItem(ITEM_HELMET); g_Console_Add('player got a helmet'); continue; end;
5968 if cmd = 'bottle' then begin plr.GiveItem(ITEM_BOTTLE); g_Console_Add('player got a bottle of health'); continue; end;
5970 if cmd = 'stimpack' then begin plr.GiveItem(ITEM_MEDKIT_SMALL); g_Console_Add('player got a stimpack'); continue; end;
5971 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;
5973 if cmd = 'greenarmor' then begin plr.GiveItem(ITEM_ARMOR_GREEN); g_Console_Add('player got a security armor'); continue; end;
5974 if cmd = 'bluearmor' then begin plr.GiveItem(ITEM_ARMOR_BLUE); g_Console_Add('player got a combat armor'); continue; end;
5976 if (cmd = 'megasphere') or (cmd = 'mega') then begin plr.GiveItem(ITEM_SPHERE_BLUE); g_Console_Add('player got a megasphere'); continue; end;
5977 if (cmd = 'soulsphere') or (cmd = 'soul')then begin plr.GiveItem(ITEM_SPHERE_WHITE); g_Console_Add('player got a soul sphere'); continue; end;
5979 if (cmd = 'invul') or (cmd = 'invulnerability') then begin plr.GiveItem(ITEM_INVUL); g_Console_Add('player got invulnerability'); continue; end;
5980 if (cmd = 'invis') or (cmd = 'invisibility') then begin plr.GiveItem(ITEM_INVIS); g_Console_Add('player got invisibility'); continue; end;
5982 if cmd = 'redkey' then begin plr.GiveItem(ITEM_KEY_RED); g_Console_Add('player got the red key'); continue; end;
5983 if cmd = 'greenkey' then begin plr.GiveItem(ITEM_KEY_GREEN); g_Console_Add('player got the green key'); continue; end;
5984 if cmd = 'bluekey' then begin plr.GiveItem(ITEM_KEY_BLUE); g_Console_Add('player got the blue key'); continue; end;
5986 if (cmd = 'shotgun') or (cmd = 'sg') then begin plr.GiveItem(ITEM_WEAPON_SHOTGUN1); g_Console_Add('player got a shotgun'); continue; end;
5987 if (cmd = 'supershotgun') or (cmd = 'ssg') then begin plr.GiveItem(ITEM_WEAPON_SHOTGUN2); g_Console_Add('player got a supershotgun'); continue; end;
5988 if cmd = 'chaingun' then begin plr.GiveItem(ITEM_WEAPON_CHAINGUN); g_Console_Add('player got a chaingun'); continue; end;
5989 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;
5990 if cmd = 'plasmagun' then begin plr.GiveItem(ITEM_WEAPON_PLASMA); g_Console_Add('player got a plasma gun'); continue; end;
5991 if cmd = 'bfg' then begin plr.GiveItem(ITEM_WEAPON_BFG); g_Console_Add('player got a BFG-9000'); continue; end;
5993 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;
5994 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;
5995 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;
5996 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;
5997 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;
5998 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;
6000 if cmd = 'superchaingun' then begin plr.GiveItem(ITEM_WEAPON_SUPERPULEMET); g_Console_Add('player got a superchaingun'); continue; end;
6001 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;
6003 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;
6004 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;
6006 if cmd = 'chainsaw' then begin plr.GiveItem(ITEM_WEAPON_SAW); g_Console_Add('player got a chainsaw'); continue; end;
6008 if cmd = 'ammo' then
6009 begin
6010 plr.GiveItem(ITEM_AMMO_SHELLS_BOX);
6011 plr.GiveItem(ITEM_AMMO_BULLETS_BOX);
6012 plr.GiveItem(ITEM_AMMO_CELL_BIG);
6013 plr.GiveItem(ITEM_AMMO_ROCKET_BOX);
6014 plr.GiveItem(ITEM_AMMO_FUELCAN);
6015 g_Console_Add('player got some ammo');
6016 continue;
6017 end;
6019 if cmd = 'clip' then begin plr.GiveItem(ITEM_AMMO_BULLETS); g_Console_Add('player got some bullets'); continue; end;
6020 if cmd = 'bullets' then begin plr.GiveItem(ITEM_AMMO_BULLETS_BOX); g_Console_Add('player got a box of bullets'); continue; end;
6022 if cmd = 'shells' then begin plr.GiveItem(ITEM_AMMO_SHELLS); g_Console_Add('player got some shells'); continue; end;
6023 if cmd = 'shellbox' then begin plr.GiveItem(ITEM_AMMO_SHELLS_BOX); g_Console_Add('player got a box of shells'); continue; end;
6025 if cmd = 'cells' then begin plr.GiveItem(ITEM_AMMO_CELL); g_Console_Add('player got some cells'); continue; end;
6026 if cmd = 'battery' then begin plr.GiveItem(ITEM_AMMO_CELL_BIG); g_Console_Add('player got cell battery'); continue; end;
6028 if cmd = 'rocket' then begin plr.GiveItem(ITEM_AMMO_ROCKET); g_Console_Add('player got a rocket'); continue; end;
6029 if cmd = 'rocketbox' then begin plr.GiveItem(ITEM_AMMO_ROCKET_BOX); g_Console_Add('player got some rockets'); continue; end;
6031 if (cmd = 'fuel') or (cmd = 'fuelcan') then begin plr.GiveItem(ITEM_AMMO_FUELCAN); g_Console_Add('player got fuel canister'); continue; end;
6033 if cmd = 'weapons' then
6034 begin
6035 plr.GiveItem(ITEM_WEAPON_SHOTGUN1);
6036 plr.GiveItem(ITEM_WEAPON_SHOTGUN2);
6037 plr.GiveItem(ITEM_WEAPON_CHAINGUN);
6038 plr.GiveItem(ITEM_WEAPON_ROCKETLAUNCHER);
6039 plr.GiveItem(ITEM_WEAPON_PLASMA);
6040 plr.GiveItem(ITEM_WEAPON_BFG);
6041 g_Console_Add('player got weapons');
6042 continue;
6043 end;
6045 if cmd = 'keys' then
6046 begin
6047 plr.GiveItem(ITEM_KEY_RED);
6048 plr.GiveItem(ITEM_KEY_GREEN);
6049 plr.GiveItem(ITEM_KEY_BLUE);
6050 g_Console_Add('player got all keys');
6051 continue;
6052 end;
6054 g_Console_Add('i don''t know how to give '''+cmd+'''!');
6055 end;
6056 exit;
6057 end;
6058 // open
6059 if cmd = 'open' then
6060 begin
6061 g_Console_Add('player activated sesame');
6062 g_Triggers_OpenAll();
6063 exit;
6064 end;
6065 // fly
6066 if cmd = 'fly' then
6067 begin
6068 gFly := not gFly;
6069 if gFly then g_Console_Add('player feels himself lighter') else g_Console_Add('player lost his wings');
6070 exit;
6071 end;
6072 // noclip
6073 if cmd = 'noclip' then
6074 begin
6075 plr.SwitchNoClip;
6076 g_Console_Add('wall hardeness adjusted');
6077 exit;
6078 end;
6079 // notarget
6080 if cmd = 'notarget' then
6081 begin
6082 plr.NoTarget := not plr.NoTarget;
6083 if plr.NoTarget then g_Console_Add('player hides in shadows') else g_Console_Add('player is brave again');
6084 exit;
6085 end;
6086 // noreload
6087 if cmd = 'noreload' then
6088 begin
6089 plr.NoReload := not plr.NoReload;
6090 if plr.NoReload then g_Console_Add('player is action hero now') else g_Console_Add('player is ordinary man now');
6091 exit;
6092 end;
6093 // speedy
6094 if cmd = 'speedy' then
6095 begin
6096 MAX_RUNVEL := 32-MAX_RUNVEL;
6097 g_Console_Add('speed adjusted');
6098 exit;
6099 end;
6100 // jumpy
6101 if cmd = 'jumpy' then
6102 begin
6103 VEL_JUMP := 30-VEL_JUMP;
6104 g_Console_Add('jump height adjusted');
6105 exit;
6106 end;
6107 // automap
6108 if cmd = 'automap' then
6109 begin
6110 gShowMap := not gShowMap;
6111 if gShowMap then g_Console_Add('player gains second sight') else g_Console_Add('player lost second sight');
6112 exit;
6113 end;
6114 // aimline
6115 if cmd = 'aimline' then
6116 begin
6117 gAimLine := not gAimLine;
6118 if gAimLine then g_Console_Add('player gains laser sight') else g_Console_Add('player lost laser sight');
6119 exit;
6120 end;
6121 end;
6123 procedure GameCommands(P: SSArray);
6124 var
6125 a, b: Integer;
6126 s, pw: String;
6127 chstr: string;
6128 cmd: string;
6129 pl: pTNetClient = nil;
6130 plr: TPlayer;
6131 prt: Word;
6132 nm: Boolean;
6133 listen: LongWord;
6134 begin
6135 // Îáùèå êîìàíäû:
6136 cmd := LowerCase(P[0]);
6137 chstr := '';
6138 if (cmd = 'quit') or
6139 (cmd = 'exit') then
6140 begin
6141 g_Game_Free();
6142 g_Game_Quit();
6143 Exit;
6144 end
6145 else if cmd = 'pause' then
6146 begin
6147 if (g_ActiveWindow = nil) then
6148 g_Game_Pause(not gPauseMain);
6149 end
6150 else if cmd = 'endgame' then
6151 gExit := EXIT_SIMPLE
6152 else if cmd = 'restart' then
6153 begin
6154 if gGameOn or (gState in [STATE_INTERSINGLE, STATE_INTERCUSTOM]) then
6155 begin
6156 if g_Game_IsClient then
6157 begin
6158 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6159 Exit;
6160 end;
6161 g_Game_Restart();
6162 end else
6163 g_Console_Add(_lc[I_MSG_NOT_GAME]);
6164 end
6165 else if cmd = 'kick' then
6166 begin
6167 if g_Game_IsServer then
6168 begin
6169 if Length(P) < 2 then
6170 begin
6171 g_Console_Add('kick <name>');
6172 Exit;
6173 end;
6174 if P[1] = '' then
6175 begin
6176 g_Console_Add('kick <name>');
6177 Exit;
6178 end;
6180 if g_Game_IsNet then
6181 pl := g_Net_Client_ByName(P[1]);
6182 if (pl <> nil) then
6183 begin
6184 s := g_Net_ClientName_ByID(pl^.ID);
6185 enet_peer_disconnect(pl^.Peer, NET_DISC_KICK);
6186 g_Console_Add(Format(_lc[I_PLAYER_KICK], [s]));
6187 MH_SEND_GameEvent(NET_EV_PLAYER_KICK, 0, s);
6188 g_Net_Slist_ServerPlayerLeaves();
6189 end else if gPlayers <> nil then
6190 for a := Low(gPlayers) to High(gPlayers) do
6191 if gPlayers[a] <> nil then
6192 if Copy(LowerCase(gPlayers[a].Name), 1, Length(P[1])) = LowerCase(P[1]) then
6193 begin
6194 // Íå îòêëþ÷àòü îñíîâíûõ èãðîêîâ â ñèíãëå
6195 if not(gPlayers[a] is TBot) and (gGameSettings.GameType = GT_SINGLE) then
6196 continue;
6197 gPlayers[a].Lives := 0;
6198 gPlayers[a].Kill(K_SIMPLEKILL, 0, HIT_DISCON);
6199 g_Console_Add(Format(_lc[I_PLAYER_LEAVE], [gPlayers[a].Name]), True);
6200 g_Player_Remove(gPlayers[a].UID);
6201 g_Net_Slist_ServerPlayerLeaves();
6202 // Åñëè íå ïåðåìåøàòü, ïðè äîáàâëåíèè íîâûõ áîòîâ ïîÿâÿòñÿ ñòàðûå
6203 g_Bot_MixNames();
6204 end;
6205 end else
6206 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
6207 end
6208 else if cmd = 'kick_id' then
6209 begin
6210 if g_Game_IsServer and g_Game_IsNet then
6211 begin
6212 if Length(P) < 2 then
6213 begin
6214 g_Console_Add('kick_id <client ID>');
6215 Exit;
6216 end;
6217 if P[1] = '' then
6218 begin
6219 g_Console_Add('kick_id <client ID>');
6220 Exit;
6221 end;
6223 a := StrToIntDef(P[1], 0);
6224 if (NetClients <> nil) and (a <= High(NetClients)) then
6225 begin
6226 if NetClients[a].Used and (NetClients[a].Peer <> nil) then
6227 begin
6228 s := g_Net_ClientName_ByID(NetClients[a].ID);
6229 enet_peer_disconnect(NetClients[a].Peer, NET_DISC_KICK);
6230 g_Console_Add(Format(_lc[I_PLAYER_KICK], [s]));
6231 MH_SEND_GameEvent(NET_EV_PLAYER_KICK, 0, s);
6232 g_Net_Slist_ServerPlayerLeaves();
6233 end;
6234 end;
6235 end else
6236 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6237 end
6238 else if cmd = 'ban' then
6239 begin
6240 if g_Game_IsServer and g_Game_IsNet then
6241 begin
6242 if Length(P) < 2 then
6243 begin
6244 g_Console_Add('ban <name>');
6245 Exit;
6246 end;
6247 if P[1] = '' then
6248 begin
6249 g_Console_Add('ban <name>');
6250 Exit;
6251 end;
6253 pl := g_Net_Client_ByName(P[1]);
6254 if (pl <> nil) then
6255 begin
6256 s := g_Net_ClientName_ByID(pl^.ID);
6257 g_Net_BanHost(pl^.Peer^.address.host, False);
6258 enet_peer_disconnect(pl^.Peer, NET_DISC_TEMPBAN);
6259 g_Console_Add(Format(_lc[I_PLAYER_BAN], [s]));
6260 MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s);
6261 g_Net_Slist_ServerPlayerLeaves();
6262 end else
6263 g_Console_Add(Format(_lc[I_NET_ERR_NAME404], [P[1]]));
6264 end else
6265 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6266 end
6267 else if cmd = 'ban_id' then
6268 begin
6269 if g_Game_IsServer and g_Game_IsNet then
6270 begin
6271 if Length(P) < 2 then
6272 begin
6273 g_Console_Add('ban_id <client ID>');
6274 Exit;
6275 end;
6276 if P[1] = '' then
6277 begin
6278 g_Console_Add('ban_id <client ID>');
6279 Exit;
6280 end;
6282 a := StrToIntDef(P[1], 0);
6283 if (NetClients <> nil) and (a <= High(NetClients)) then
6284 if NetClients[a].Used and (NetClients[a].Peer <> nil) then
6285 begin
6286 s := g_Net_ClientName_ByID(NetClients[a].ID);
6287 g_Net_BanHost(NetClients[a].Peer^.address.host, False);
6288 enet_peer_disconnect(NetClients[a].Peer, NET_DISC_TEMPBAN);
6289 g_Console_Add(Format(_lc[I_PLAYER_BAN], [s]));
6290 MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s);
6291 g_Net_Slist_ServerPlayerLeaves();
6292 end;
6293 end else
6294 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6295 end
6296 else if cmd = 'permban' then
6297 begin
6298 if g_Game_IsServer and g_Game_IsNet then
6299 begin
6300 if Length(P) < 2 then
6301 begin
6302 g_Console_Add('permban <name>');
6303 Exit;
6304 end;
6305 if P[1] = '' then
6306 begin
6307 g_Console_Add('permban <name>');
6308 Exit;
6309 end;
6311 pl := g_Net_Client_ByName(P[1]);
6312 if (pl <> nil) then
6313 begin
6314 s := g_Net_ClientName_ByID(pl^.ID);
6315 g_Net_BanHost(pl^.Peer^.address.host);
6316 enet_peer_disconnect(pl^.Peer, NET_DISC_BAN);
6317 g_Net_SaveBanList();
6318 g_Console_Add(Format(_lc[I_PLAYER_BAN], [s]));
6319 MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s);
6320 g_Net_Slist_ServerPlayerLeaves();
6321 end else
6322 g_Console_Add(Format(_lc[I_NET_ERR_NAME404], [P[1]]));
6323 end else
6324 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6325 end
6326 else if cmd = 'permban_id' then
6327 begin
6328 if g_Game_IsServer and g_Game_IsNet then
6329 begin
6330 if Length(P) < 2 then
6331 begin
6332 g_Console_Add('permban_id <client ID>');
6333 Exit;
6334 end;
6335 if P[1] = '' then
6336 begin
6337 g_Console_Add('permban_id <client ID>');
6338 Exit;
6339 end;
6341 a := StrToIntDef(P[1], 0);
6342 if (NetClients <> nil) and (a <= High(NetClients)) then
6343 if NetClients[a].Used and (NetClients[a].Peer <> nil) then
6344 begin
6345 s := g_Net_ClientName_ByID(NetClients[a].ID);
6346 g_Net_BanHost(NetClients[a].Peer^.address.host);
6347 enet_peer_disconnect(NetClients[a].Peer, NET_DISC_BAN);
6348 g_Net_SaveBanList();
6349 g_Console_Add(Format(_lc[I_PLAYER_BAN], [s]));
6350 MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s);
6351 g_Net_Slist_ServerPlayerLeaves();
6352 end;
6353 end else
6354 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6355 end
6356 else if cmd = 'unban' then
6357 begin
6358 if g_Game_IsServer and g_Game_IsNet then
6359 begin
6360 if Length(P) < 2 then
6361 begin
6362 g_Console_Add('unban <IP Address>');
6363 Exit;
6364 end;
6365 if P[1] = '' then
6366 begin
6367 g_Console_Add('unban <IP Address>');
6368 Exit;
6369 end;
6371 if g_Net_UnbanHost(P[1]) then
6372 begin
6373 g_Console_Add(Format(_lc[I_MSG_UNBAN_OK], [P[1]]));
6374 g_Net_SaveBanList();
6375 end else
6376 g_Console_Add(Format(_lc[I_MSG_UNBAN_FAIL], [P[1]]));
6377 end else
6378 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6379 end
6380 else if cmd = 'clientlist' then
6381 begin
6382 if g_Game_IsServer and g_Game_IsNet then
6383 begin
6384 b := 0;
6385 if NetClients <> nil then
6386 for a := Low(NetClients) to High(NetClients) do
6387 if NetClients[a].Used and (NetClients[a].Peer <> nil) then
6388 begin
6389 plr := g_Player_Get(NetClients[a].Player);
6390 if plr = nil then continue;
6391 Inc(b);
6392 g_Console_Add(Format('#%2d: %-15s | %s', [a,
6393 IpToStr(NetClients[a].Peer^.address.host), plr.Name]));
6394 end;
6395 if b = 0 then
6396 g_Console_Add(_lc[I_MSG_NOCLIENTS]);
6397 end else
6398 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6399 end
6400 else if cmd = 'connect' then
6401 begin
6402 if (NetMode = NET_NONE) then
6403 begin
6404 if Length(P) < 2 then
6405 begin
6406 g_Console_Add('connect <IP> [port] [password]');
6407 Exit;
6408 end;
6409 if P[1] = '' then
6410 begin
6411 g_Console_Add('connect <IP> [port] [password]');
6412 Exit;
6413 end;
6415 if Length(P) > 2 then
6416 prt := StrToIntDef(P[2], 25666)
6417 else
6418 prt := 25666;
6420 if Length(P) > 3 then
6421 pw := P[3]
6422 else
6423 pw := '';
6425 g_Game_StartClient(P[1], prt, pw);
6426 end;
6427 end
6428 else if cmd = 'disconnect' then
6429 begin
6430 if (NetMode = NET_CLIENT) then
6431 g_Net_Disconnect();
6432 end
6433 else if cmd = 'reconnect' then
6434 begin
6435 if (NetMode = NET_SERVER) then
6436 Exit;
6438 if (NetMode = NET_CLIENT) then
6439 begin
6440 g_Net_Disconnect();
6441 gExit := EXIT_SIMPLE;
6442 EndGame;
6443 end;
6445 //TODO: Use last successful password to reconnect, instead of ''
6446 g_Game_StartClient(NetClientIP, NetClientPort, '');
6447 end
6448 else if (cmd = 'addbot') or
6449 (cmd = 'bot_add') then
6450 begin
6451 if Length(P) > 2 then
6452 g_Bot_Add(TEAM_NONE, StrToIntDef(P[1], 2), StrToIntDef(P[2], 100))
6453 else if Length(P) > 1 then
6454 g_Bot_Add(TEAM_NONE, StrToIntDef(P[1], 2))
6455 else
6456 g_Bot_Add(TEAM_NONE, 2);
6457 end
6458 else if cmd = 'bot_addlist' then
6459 begin
6460 if Length(P) > 1 then
6461 begin
6462 if Length(P) = 2 then
6463 g_Bot_AddList(TEAM_NONE, P[1], StrToIntDef(P[1], -1))
6464 else if Length(P) = 3 then
6465 g_Bot_AddList(TEAM_NONE, P[1], StrToIntDef(P[1], -1), StrToIntDef(P[2], 100))
6466 else
6467 g_Bot_AddList(IfThen(P[2] = 'red', TEAM_RED, TEAM_BLUE), P[1], StrToIntDef(P[1], -1));
6468 end;
6469 end
6470 else if cmd = 'bot_removeall' then
6471 g_Bot_RemoveAll()
6472 else if cmd = 'chat' then
6473 begin
6474 if g_Game_IsNet then
6475 begin
6476 if Length(P) > 1 then
6477 begin
6478 for a := 1 to High(P) do
6479 chstr := chstr + P[a] + ' ';
6481 if Length(chstr) > 200 then SetLength(chstr, 200);
6483 if Length(chstr) < 1 then
6484 begin
6485 g_Console_Add('chat <text>');
6486 Exit;
6487 end;
6489 chstr := b_Text_Format(chstr);
6490 if g_Game_IsClient then
6491 MC_SEND_Chat(chstr, NET_CHAT_PLAYER)
6492 else
6493 MH_SEND_Chat(gPlayer1Settings.Name + ': ' + chstr, NET_CHAT_PLAYER);
6494 end
6495 else
6496 g_Console_Add('chat <text>');
6497 end else
6498 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
6499 end
6500 else if cmd = 'teamchat' then
6501 begin
6502 if g_Game_IsNet and (gGameSettings.GameMode in [GM_TDM, GM_CTF]) then
6503 begin
6504 if Length(P) > 1 then
6505 begin
6506 for a := 1 to High(P) do
6507 chstr := chstr + P[a] + ' ';
6509 if Length(chstr) > 200 then SetLength(chstr, 200);
6511 if Length(chstr) < 1 then
6512 begin
6513 g_Console_Add('teamchat <text>');
6514 Exit;
6515 end;
6517 chstr := b_Text_Format(chstr);
6518 if g_Game_IsClient then
6519 MC_SEND_Chat(chstr, NET_CHAT_TEAM)
6520 else
6521 MH_SEND_Chat(gPlayer1Settings.Name + ': ' + chstr, NET_CHAT_TEAM,
6522 gPlayer1Settings.Team);
6523 end
6524 else
6525 g_Console_Add('teamchat <text>');
6526 end else
6527 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
6528 end
6529 else if cmd = 'game' then
6530 begin
6531 if gGameSettings.GameType <> GT_NONE then
6532 begin
6533 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
6534 Exit;
6535 end;
6536 if Length(P) = 1 then
6537 begin
6538 g_Console_Add(cmd + ' <WAD> [MAP] [# players]');
6539 Exit;
6540 end;
6541 // Èãðà åù¸ íå çàïóùåíà, ñíà÷àëà íàì íàäî çàãðóçèòü êàêîé-òî WAD
6542 P[1] := addWadExtension(P[1]);
6543 if FileExists(MapsDir + P[1]) then
6544 begin
6545 // Åñëè êàðòà íå óêàçàíà, áåð¸ì ïåðâóþ êàðòó â ôàéëå
6546 if Length(P) < 3 then
6547 begin
6548 SetLength(P, 3);
6549 P[2] := g_Game_GetFirstMap(MapsDir + P[1]);
6550 end;
6552 s := P[1] + ':\' + UpperCase(P[2]);
6554 if g_Map_Exist(MapsDir + s) then
6555 begin
6556 // Çàïóñêàåì ñâîþ èãðó
6557 g_Game_Free();
6558 with gGameSettings do
6559 begin
6560 GameMode := g_Game_TextToMode(gcGameMode);
6561 if gSwitchGameMode <> GM_NONE then
6562 GameMode := gSwitchGameMode;
6563 if GameMode = GM_NONE then GameMode := GM_DM;
6564 if GameMode = GM_SINGLE then GameMode := GM_COOP;
6565 b := 1;
6566 if Length(P) >= 4 then
6567 b := StrToIntDef(P[3], 1);
6568 g_Game_StartCustom(s, GameMode, TimeLimit,
6569 GoalLimit, MaxLives, Options, b);
6570 end;
6571 end
6572 else
6573 if P[2] = '' then
6574 g_Console_Add(Format(_lc[I_MSG_NO_MAPS], [P[1]]))
6575 else
6576 g_Console_Add(Format(_lc[I_MSG_NO_MAP_FALLBACK], [UpperCase(P[2]), P[1]]));
6577 end else
6578 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]));
6579 end
6580 else if cmd = 'host' then
6581 begin
6582 if gGameSettings.GameType <> GT_NONE then
6583 begin
6584 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
6585 Exit;
6586 end;
6587 if Length(P) < 4 then
6588 begin
6589 g_Console_Add(cmd + ' <listen IP> <port> <WAD> [MAP] [# players]');
6590 Exit;
6591 end;
6592 if not StrToIp(P[1], listen) then
6593 Exit;
6594 prt := StrToIntDef(P[2], 25666);
6596 P[3] := addWadExtension(P[3]);
6597 if FileExists(MapsDir + P[3]) then
6598 begin
6599 // Åñëè êàðòà íå óêàçàíà, áåð¸ì ïåðâóþ êàðòó â ôàéëå
6600 if Length(P) < 5 then
6601 begin
6602 SetLength(P, 5);
6603 P[4] := g_Game_GetFirstMap(MapsDir + P[1]);
6604 end;
6606 s := P[3] + ':\' + UpperCase(P[4]);
6608 if g_Map_Exist(MapsDir + s) then
6609 begin
6610 // Çàïóñêàåì ñâîþ èãðó
6611 g_Game_Free();
6612 with gGameSettings do
6613 begin
6614 GameMode := g_Game_TextToMode(gcGameMode);
6615 if gSwitchGameMode <> GM_NONE then
6616 GameMode := gSwitchGameMode;
6617 if GameMode = GM_NONE then GameMode := GM_DM;
6618 if GameMode = GM_SINGLE then GameMode := GM_COOP;
6619 b := 0;
6620 if Length(P) >= 6 then
6621 b := StrToIntDef(P[5], 0);
6622 g_Game_StartServer(s, GameMode, TimeLimit,
6623 GoalLimit, MaxLives, Options, b, listen, prt);
6624 end;
6625 end
6626 else
6627 if P[4] = '' then
6628 g_Console_Add(Format(_lc[I_MSG_NO_MAPS], [P[3]]))
6629 else
6630 g_Console_Add(Format(_lc[I_MSG_NO_MAP_FALLBACK], [UpperCase(P[4]), P[3]]));
6631 end else
6632 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[3]]));
6633 end
6634 else if cmd = 'map' then
6635 begin
6636 if Length(P) = 1 then
6637 begin
6638 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
6639 begin
6640 g_Console_Add(cmd + ' <MAP>');
6641 g_Console_Add(cmd + ' <WAD> [MAP]');
6642 end else
6643 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
6644 end else
6645 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
6646 begin
6647 // Èä¸ò ñâîÿ èãðà èëè ñåðâåð
6648 if Length(P) < 3 then
6649 begin
6650 // Ïåðâûé ïàðàìåòð - ëèáî êàðòà, ëèáî èìÿ WAD ôàéëà
6651 s := UpperCase(P[1]);
6652 if g_Map_Exist(MapsDir + gGameSettings.WAD + ':\' + s) then
6653 begin // Êàðòà íàøëàñü
6654 gExitByTrigger := False;
6655 if gGameOn then
6656 begin // Èä¸ò èãðà - çàâåðøàåì óðîâåíü
6657 gNextMap := s;
6658 gExit := EXIT_ENDLEVELCUSTOM;
6659 end
6660 else // Èíòåðìèññèÿ - ñðàçó çàãðóæàåì êàðòó
6661 g_Game_ChangeMap(s);
6662 end else
6663 begin
6664 // Òàêîé êàðòû íåò, èùåì WAD ôàéë
6665 pw := findDiskWad(MapsDir + P[1]);
6666 g_Console_Add(Format(_lc[I_MSG_NO_MAP_FALLBACK], [s, 'WAD ' + P[1]]));
6667 if FileExists(pw) then
6668 begin
6669 // Ïàðàìåòðà êàðòû íåò, ïîýòîìó ñòàâèì ïåðâóþ èç ôàéëà
6670 SetLength(P, 3);
6671 P[1] := ExtractRelativePath(MapsDir, pw);
6672 P[2] := g_Game_GetFirstMap(MapsDir + P[1]);
6674 s := P[1] + ':\' + P[2];
6676 if g_Map_Exist(MapsDir + s) then
6677 begin
6678 gExitByTrigger := False;
6679 if gGameOn then
6680 begin // Èä¸ò èãðà - çàâåðøàåì óðîâåíü
6681 gNextMap := s;
6682 gExit := EXIT_ENDLEVELCUSTOM;
6683 end
6684 else // Èíòåðìèññèÿ - ñðàçó çàãðóæàåì êàðòó
6685 g_Game_ChangeMap(s);
6686 end else
6687 if P[2] = '' then
6688 g_Console_Add(Format(_lc[I_MSG_NO_MAPS], [P[1]]))
6689 else
6690 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [P[2]]));
6691 end else
6692 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]));
6693 end;
6694 end else
6695 begin
6696 // Óêàçàíî äâà ïàðàìåòðà, çíà÷èò ïåðâûé - WAD ôàéë, à âòîðîé - êàðòà
6697 P[1] := addWadExtension(P[1]);
6698 if FileExists(MapsDir + P[1]) then
6699 begin
6700 // Íàøëè WAD ôàéë
6701 P[2] := UpperCase(P[2]);
6702 s := P[1] + ':\' + P[2];
6704 if g_Map_Exist(MapsDir + s) then
6705 begin // Íàøëè êàðòó
6706 gExitByTrigger := False;
6707 if gGameOn then
6708 begin // Èä¸ò èãðà - çàâåðøàåì óðîâåíü
6709 gNextMap := s;
6710 gExit := EXIT_ENDLEVELCUSTOM;
6711 end
6712 else // Èíòåðìèññèÿ - ñðàçó çàãðóæàåì êàðòó
6713 g_Game_ChangeMap(s);
6714 end else
6715 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [P[2]]));
6716 end else
6717 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]));
6718 end;
6719 end else
6720 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
6721 end
6722 else if cmd = 'nextmap' then
6723 begin
6724 if not(gGameOn or (gState = STATE_INTERCUSTOM)) then
6725 g_Console_Add(_lc[I_MSG_NOT_GAME])
6726 else begin
6727 nm := True;
6728 if Length(P) = 1 then
6729 begin
6730 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
6731 begin
6732 g_Console_Add(cmd + ' <MAP>');
6733 g_Console_Add(cmd + ' <WAD> [MAP]');
6734 end else begin
6735 nm := False;
6736 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
6737 end;
6738 end else
6739 begin
6740 nm := False;
6741 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
6742 begin
6743 if Length(P) < 3 then
6744 begin
6745 // Ïåðâûé ïàðàìåòð - ëèáî êàðòà, ëèáî èìÿ WAD ôàéëà
6746 s := UpperCase(P[1]);
6747 if g_Map_Exist(MapsDir + gGameSettings.WAD + ':\' + s) then
6748 begin // Êàðòà íàøëàñü
6749 gExitByTrigger := False;
6750 gNextMap := s;
6751 nm := True;
6752 end else
6753 begin
6754 // Òàêîé êàðòû íåò, èùåì WAD ôàéë
6755 P[1] := addWadExtension(P[1]);
6756 g_Console_Add(Format(_lc[I_MSG_NO_MAP_FALLBACK], [s, P[1]]));
6757 if FileExists(MapsDir + P[1]) then
6758 begin
6759 // Ïàðàìåòðà êàðòû íåò, ïîýòîìó ñòàâèì ïåðâóþ èç ôàéëà
6760 SetLength(P, 3);
6761 P[2] := g_Game_GetFirstMap(MapsDir + P[1]);
6763 s := P[1] + ':\' + P[2];
6765 if g_Map_Exist(MapsDir + s) then
6766 begin // Óñòàíàâëèâàåì êàðòó
6767 gExitByTrigger := False;
6768 gNextMap := s;
6769 nm := True;
6770 end else
6771 if P[2] = '' then
6772 g_Console_Add(Format(_lc[I_MSG_NO_MAPS], [P[1]]))
6773 else
6774 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [P[2]]));
6775 end else
6776 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]));
6777 end;
6778 end else
6779 begin
6780 // Óêàçàíî äâà ïàðàìåòðà, çíà÷èò ïåðâûé - WAD ôàéë, à âòîðîé - êàðòà
6781 P[1] := addWadExtension(P[1]);
6782 if FileExists(MapsDir + P[1]) then
6783 begin
6784 // Íàøëè WAD ôàéë
6785 P[2] := UpperCase(P[2]);
6786 s := P[1] + ':\' + P[2];
6788 if g_Map_Exist(MapsDir + s) then
6789 begin // Íàøëè êàðòó
6790 gExitByTrigger := False;
6791 gNextMap := s;
6792 nm := True;
6793 end else
6794 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [P[2]]));
6795 end else
6796 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]));
6797 end;
6798 end else
6799 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
6800 end;
6801 if nm then
6802 if gNextMap = '' then
6803 g_Console_Add(_lc[I_MSG_NEXTMAP_UNSET])
6804 else
6805 g_Console_Add(Format(_lc[I_MSG_NEXTMAP_SET], [gNextMap]));
6806 end;
6807 end
6808 else if (cmd = 'endmap') or (cmd = 'goodbye') then
6809 begin
6810 if not gGameOn then
6811 g_Console_Add(_lc[I_MSG_NOT_GAME])
6812 else
6813 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
6814 begin
6815 gExitByTrigger := False;
6816 // Ñëåäóþùàÿ êàðòà íå çàäàíà, ïðîáóåì íàéòè òðèããåð Âûõîä
6817 if (gNextMap = '') and (gTriggers <> nil) then
6818 for a := 0 to High(gTriggers) do
6819 if gTriggers[a].TriggerType = TRIGGER_EXIT then
6820 begin
6821 gExitByTrigger := True;
6822 //gNextMap := gTriggers[a].Data.MapName;
6823 gNextMap := gTriggers[a].tgcMap;
6824 Break;
6825 end;
6826 // Èùåì ñëåäóþùóþ êàðòó â WAD ôàéëå
6827 if gNextMap = '' then
6828 gNextMap := g_Game_GetNextMap();
6829 // Ïðîâåðÿåì, íå çàäàí ëè WAD ôàéë ðåñóðñíîé ñòðîêîé
6830 if not isWadPath(gNextMap) then
6831 s := gGameSettings.WAD + ':\' + gNextMap
6832 else
6833 s := gNextMap;
6834 // Åñëè êàðòà íàéäåíà, âûõîäèì ñ óðîâíÿ
6835 if g_Map_Exist(MapsDir + s) then
6836 gExit := EXIT_ENDLEVELCUSTOM
6837 else
6838 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [gNextMap]));
6839 end else
6840 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
6841 end
6842 else if (cmd = 'event') then
6843 begin
6844 if (Length(P) <= 1) then
6845 begin
6846 for a := 0 to High(gEvents) do
6847 if gEvents[a].Command = '' then
6848 g_Console_Add(gEvents[a].Name + ' <none>')
6849 else
6850 g_Console_Add(gEvents[a].Name + ' "' + gEvents[a].Command + '"');
6851 Exit;
6852 end;
6853 if (Length(P) = 2) then
6854 begin
6855 for a := 0 to High(gEvents) do
6856 if gEvents[a].Name = P[1] then
6857 if gEvents[a].Command = '' then
6858 g_Console_Add(gEvents[a].Name + ' <none>')
6859 else
6860 g_Console_Add(gEvents[a].Name + ' "' + gEvents[a].Command + '"');
6861 Exit;
6862 end;
6863 for a := 0 to High(gEvents) do
6864 if gEvents[a].Name = P[1] then
6865 begin
6866 gEvents[a].Command := '';
6867 for b := 2 to High(P) do
6868 if Pos(' ', P[b]) = 0 then
6869 gEvents[a].Command := gEvents[a].Command + ' ' + P[b]
6870 else
6871 gEvents[a].Command := gEvents[a].Command + ' "' + P[b] + '"';
6872 gEvents[a].Command := Trim(gEvents[a].Command);
6873 Exit;
6874 end;
6875 end
6876 else if cmd = 'suicide' then
6877 begin
6878 if gGameOn then
6879 begin
6880 if g_Game_IsClient then
6881 MC_SEND_CheatRequest(NET_CHEAT_SUICIDE)
6882 else
6883 begin
6884 if gPlayer1 <> nil then
6885 gPlayer1.Damage(SUICIDE_DAMAGE, gPlayer1.UID, 0, 0, HIT_SELF);
6886 if gPlayer2 <> nil then
6887 gPlayer2.Damage(SUICIDE_DAMAGE, gPlayer2.UID, 0, 0, HIT_SELF);
6888 end;
6889 end;
6890 end
6891 else if cmd = 'screenshot' then
6892 begin
6893 g_TakeScreenShot()
6894 end
6895 else if cmd = 'weapon' then
6896 begin
6897 if Length(p) = 2 then
6898 begin
6899 a := WP_FIRST + StrToInt(p[1]) - 1;
6900 if (a >= WP_FIRST) and (a <= WP_LAST) then
6901 gSelectWeapon[0, a] := True
6902 end
6903 end
6904 else if (cmd = 'p1_weapon') or (cmd = 'p2_weapon') then
6905 begin
6906 if Length(p) = 2 then
6907 begin
6908 a := WP_FIRST + StrToInt(p[1]) - 1;
6909 b := ord(cmd[2]) - ord('1');
6910 if (a >= WP_FIRST) and (a <= WP_LAST) then
6911 gSelectWeapon[b, a] := True
6912 end
6913 end
6914 // Êîìàíäû Ñâîåé èãðû:
6915 else if gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT] then
6916 begin
6917 if cmd = 'bot_addred' then
6918 begin
6919 if Length(P) > 1 then
6920 g_Bot_Add(TEAM_RED, StrToIntDef(P[1], 2))
6921 else
6922 g_Bot_Add(TEAM_RED, 2);
6923 end
6924 else if cmd = 'bot_addblue' then
6925 begin
6926 if Length(P) > 1 then
6927 g_Bot_Add(TEAM_BLUE, StrToIntDef(P[1], 2))
6928 else
6929 g_Bot_Add(TEAM_BLUE, 2);
6930 end
6931 else if cmd = 'spectate' then
6932 begin
6933 if not gGameOn then
6934 Exit;
6935 g_Game_Spectate();
6936 end
6937 else if cmd = 'say' then
6938 begin
6939 if g_Game_IsServer and g_Game_IsNet then
6940 begin
6941 if Length(P) > 1 then
6942 begin
6943 chstr := '';
6944 for a := 1 to High(P) do
6945 chstr := chstr + P[a] + ' ';
6947 if Length(chstr) > 200 then SetLength(chstr, 200);
6949 if Length(chstr) < 1 then
6950 begin
6951 g_Console_Add('say <text>');
6952 Exit;
6953 end;
6955 chstr := b_Text_Format(chstr);
6956 MH_SEND_Chat(chstr, NET_CHAT_PLAYER);
6957 end
6958 else g_Console_Add('say <text>');
6959 end else
6960 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6961 end
6962 else if cmd = 'tell' then
6963 begin
6964 if g_Game_IsServer and g_Game_IsNet then
6965 begin
6966 if (Length(P) > 2) and (P[1] <> '') then
6967 begin
6968 chstr := '';
6969 for a := 2 to High(P) do
6970 chstr := chstr + P[a] + ' ';
6972 if Length(chstr) > 200 then SetLength(chstr, 200);
6974 if Length(chstr) < 1 then
6975 begin
6976 g_Console_Add('tell <playername> <text>');
6977 Exit;
6978 end;
6980 pl := g_Net_Client_ByName(P[1]);
6981 if pl <> nil then
6982 MH_SEND_Chat(b_Text_Format(chstr), NET_CHAT_PLAYER, pl^.ID)
6983 else
6984 g_Console_Add(Format(_lc[I_NET_ERR_NAME404], [P[1]]));
6985 end
6986 else g_Console_Add('tell <playername> <text>');
6987 end else
6988 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6989 end
6990 else if (cmd = 'overtime') and not g_Game_IsClient then
6991 begin
6992 if (Length(P) = 1) or (StrToIntDef(P[1], -1) <= 0) then
6993 Exit;
6994 // Äîïîëíèòåëüíîå âðåìÿ:
6995 gGameSettings.TimeLimit := (gTime - gGameStartTime) div 1000 + Word(StrToIntDef(P[1], 0));
6997 g_Console_Add(Format(_lc[I_MSG_TIME_LIMIT],
6998 [gGameSettings.TimeLimit div 3600,
6999 (gGameSettings.TimeLimit div 60) mod 60,
7000 gGameSettings.TimeLimit mod 60]));
7001 if g_Game_IsNet then MH_SEND_GameSettings;
7002 end
7003 else if (cmd = 'rcon_password') and g_Game_IsClient then
7004 begin
7005 if (Length(P) <= 1) then
7006 g_Console_Add('rcon_password <password>')
7007 else
7008 MC_SEND_RCONPassword(P[1]);
7009 end
7010 else if cmd = 'rcon' then
7011 begin
7012 if g_Game_IsClient then
7013 begin
7014 if Length(P) > 1 then
7015 begin
7016 chstr := '';
7017 for a := 1 to High(P) do
7018 chstr := chstr + P[a] + ' ';
7020 if Length(chstr) > 200 then SetLength(chstr, 200);
7022 if Length(chstr) < 1 then
7023 begin
7024 g_Console_Add('rcon <command>');
7025 Exit;
7026 end;
7028 MC_SEND_RCONCommand(chstr);
7029 end
7030 else g_Console_Add('rcon <command>');
7031 end;
7032 end
7033 else if cmd = 'ready' then
7034 begin
7035 if g_Game_IsServer and (gLMSRespawn = LMS_RESPAWN_WARMUP) then
7036 gLMSRespawnTime := gTime + 100;
7037 end
7038 else if (cmd = 'callvote') and g_Game_IsNet then
7039 begin
7040 if Length(P) > 1 then
7041 begin
7042 chstr := '';
7043 for a := 1 to High(P) do begin
7044 if a > 1 then chstr := chstr + ' ';
7045 chstr := chstr + P[a];
7046 end;
7048 if Length(chstr) > 200 then SetLength(chstr, 200);
7050 if Length(chstr) < 1 then
7051 begin
7052 g_Console_Add('callvote <command>');
7053 Exit;
7054 end;
7056 if g_Game_IsClient then
7057 MC_SEND_Vote(True, chstr)
7058 else
7059 g_Game_StartVote(chstr, gPlayer1Settings.Name);
7060 g_Console_Process('vote', True);
7061 end
7062 else
7063 g_Console_Add('callvote <command>');
7064 end
7065 else if (cmd = 'vote') and g_Game_IsNet then
7066 begin
7067 if g_Game_IsClient then
7068 MC_SEND_Vote(False)
7069 else if gVoteInProgress then
7070 begin
7071 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
7072 a := Floor((NetClientCount+1)/2.0) + 1
7073 else
7074 a := Floor(NetClientCount/2.0) + 1;
7075 if gVoted then
7076 begin
7077 Dec(gVoteCount);
7078 gVoted := False;
7079 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_REVOKED], [gPlayer1Settings.Name, gVoteCount, a]), True);
7080 MH_SEND_VoteEvent(NET_VE_REVOKE, gPlayer1Settings.Name, 'a', gVoteCount, a);
7081 end
7082 else
7083 begin
7084 Inc(gVoteCount);
7085 gVoted := True;
7086 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_VOTE], [gPlayer1Settings.Name, gVoteCount, a]), True);
7087 MH_SEND_VoteEvent(NET_VE_VOTE, gPlayer1Settings.Name, 'a', gVoteCount, a);
7088 g_Game_CheckVote;
7089 end;
7090 end;
7091 end
7092 end;
7093 end;
7095 procedure g_TakeScreenShot();
7096 var
7097 a: Word;
7098 FileName: string;
7099 ssdir, t: string;
7100 st: TStream;
7101 ok: Boolean;
7102 begin
7103 if e_NoGraphics then Exit;
7104 ssdir := GameDir+'/screenshots';
7105 if not findFileCI(ssdir, true) then
7106 begin
7107 // try to create dir
7108 try
7109 CreateDir(ssdir);
7110 except
7111 end;
7112 if not findFileCI(ssdir, true) then exit; // alas
7113 end;
7114 try
7115 for a := 1 to High(Word) do
7116 begin
7117 FileName := Format(ssdir+'screenshot%.3d.png', [a]);
7118 t := FileName;
7119 if findFileCI(t, true) then continue;
7120 if not findFileCI(FileName) then
7121 begin
7122 ok := false;
7123 st := createDiskFile(FileName);
7124 try
7125 e_MakeScreenshot(st, gScreenWidth, gScreenHeight);
7126 ok := true;
7127 finally
7128 st.Free();
7129 end;
7130 if not ok then try DeleteFile(FileName); except end else g_Console_Add(Format(_lc[I_CONSOLE_SCREENSHOT], [ExtractFileName(FileName)]));
7131 break;
7132 end;
7133 end;
7134 except
7135 end;
7136 end;
7138 procedure g_Game_InGameMenu(Show: Boolean);
7139 begin
7140 if (g_ActiveWindow = nil) and Show then
7141 begin
7142 if gGameSettings.GameType = GT_SINGLE then
7143 g_GUI_ShowWindow('GameSingleMenu')
7144 else
7145 begin
7146 if g_Game_IsClient then
7147 g_GUI_ShowWindow('GameClientMenu')
7148 else
7149 if g_Game_IsNet then
7150 g_GUI_ShowWindow('GameServerMenu')
7151 else
7152 g_GUI_ShowWindow('GameCustomMenu');
7153 end;
7154 g_Sound_PlayEx('MENU_OPEN');
7156 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
7157 if (not g_Game_IsNet) then
7158 g_Game_Pause(True);
7159 end
7160 else
7161 if (g_ActiveWindow <> nil) and (not Show) then
7162 begin
7163 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
7164 if (not g_Game_IsNet) then
7165 g_Game_Pause(False);
7166 end;
7167 end;
7169 procedure g_Game_Pause (Enable: Boolean);
7170 var
7171 oldPause: Boolean;
7172 begin
7173 if not gGameOn then exit;
7175 if not (gGameSettings.GameType in [GT_SINGLE, GT_CUSTOM]) then exit;
7177 oldPause := gPause;
7178 gPauseMain := Enable;
7180 if (gPause <> oldPause) then g_Game_PauseAllSounds(gPause);
7181 end;
7183 procedure g_Game_HolmesPause (Enable: Boolean);
7184 var
7185 oldPause: Boolean;
7186 begin
7187 if not gGameOn then exit;
7188 if not (gGameSettings.GameType in [GT_SINGLE, GT_CUSTOM]) then exit;
7190 oldPause := gPause;
7191 gPauseHolmes := Enable;
7193 if (gPause <> oldPause) then g_Game_PauseAllSounds(gPause);
7194 end;
7196 procedure g_Game_PauseAllSounds(Enable: Boolean);
7197 var
7198 i: Integer;
7199 begin
7200 // Òðèããåðû:
7201 if gTriggers <> nil then
7202 for i := 0 to High(gTriggers) do
7203 with gTriggers[i] do
7204 if (TriggerType = TRIGGER_SOUND) and
7205 (Sound <> nil) and
7206 Sound.IsPlaying() then
7207 begin
7208 Sound.Pause(Enable);
7209 end;
7211 // Çâóêè èãðîêîâ:
7212 if gPlayers <> nil then
7213 for i := 0 to High(gPlayers) do
7214 if gPlayers[i] <> nil then
7215 gPlayers[i].PauseSounds(Enable);
7217 // Ìóçûêà:
7218 if gMusic <> nil then
7219 gMusic.Pause(Enable);
7220 end;
7222 procedure g_Game_StopAllSounds(all: Boolean);
7223 var
7224 i: Integer;
7225 begin
7226 if gTriggers <> nil then
7227 for i := 0 to High(gTriggers) do
7228 with gTriggers[i] do
7229 if (TriggerType = TRIGGER_SOUND) and
7230 (Sound <> nil) then
7231 Sound.Stop();
7233 if gMusic <> nil then
7234 gMusic.Stop();
7236 if all then
7237 e_StopChannels();
7238 end;
7240 procedure g_Game_UpdateTriggerSounds;
7241 var i: Integer;
7242 begin
7243 if gTriggers <> nil then
7244 for i := 0 to High(gTriggers) do
7245 with gTriggers[i] do
7246 if (TriggerType = TRIGGER_SOUND) and (Sound <> nil) and tgcLocal and Sound.IsPlaying() then
7247 Sound.SetCoordsRect(X, Y, Width, Height, tgcVolume / 255.0)
7248 end;
7250 function g_Game_IsWatchedPlayer(UID: Word): Boolean;
7251 begin
7252 Result := False;
7253 if (gPlayer1 <> nil) and (gPlayer1.UID = UID) then
7254 begin
7255 Result := True;
7256 Exit;
7257 end;
7258 if (gPlayer2 <> nil) and (gPlayer2.UID = UID) then
7259 begin
7260 Result := True;
7261 Exit;
7262 end;
7263 if gSpectMode <> SPECT_PLAYERS then
7264 Exit;
7265 if gSpectPID1 = UID then
7266 begin
7267 Result := True;
7268 Exit;
7269 end;
7270 if gSpectViewTwo and (gSpectPID2 = UID) then
7271 begin
7272 Result := True;
7273 Exit;
7274 end;
7275 end;
7277 function g_Game_IsWatchedTeam(Team: Byte): Boolean;
7278 var
7279 Pl: TPlayer;
7280 begin
7281 Result := False;
7282 if (gPlayer1 <> nil) and (gPlayer1.Team = Team) then
7283 begin
7284 Result := True;
7285 Exit;
7286 end;
7287 if (gPlayer2 <> nil) and (gPlayer2.Team = Team) then
7288 begin
7289 Result := True;
7290 Exit;
7291 end;
7292 if gSpectMode <> SPECT_PLAYERS then
7293 Exit;
7294 Pl := g_Player_Get(gSpectPID1);
7295 if (Pl <> nil) and (Pl.Team = Team) then
7296 begin
7297 Result := True;
7298 Exit;
7299 end;
7300 if gSpectViewTwo then
7301 begin
7302 Pl := g_Player_Get(gSpectPID2);
7303 if (Pl <> nil) and (Pl.Team = Team) then
7304 begin
7305 Result := True;
7306 Exit;
7307 end;
7308 end;
7309 end;
7311 procedure g_Game_Message(Msg: string; Time: Word);
7312 begin
7313 MessageLineLength := (gScreenWidth - 204) div e_CharFont_GetMaxWidth(gMenuFont);
7314 MessageText := b_Text_Wrap(b_Text_Format(Msg), MessageLineLength);
7315 MessageTime := Time;
7316 end;
7318 procedure g_Game_ChatSound(Text: String; Taunt: Boolean = True);
7319 const
7320 punct: Array[0..13] of String =
7321 ('.', ',', ':', ';', '!', '?', '(', ')', '''', '"', '/', '\', '*', '^');
7322 var
7323 i, j: Integer;
7324 ok: Boolean;
7325 fpText: String;
7327 function IsPunctuation(S: String): Boolean;
7328 var
7329 i: Integer;
7330 begin
7331 Result := False;
7332 if Length(S) <> 1 then
7333 Exit;
7334 for i := Low(punct) to High(punct) do
7335 if S = punct[i] then
7336 begin
7337 Result := True;
7338 break;
7339 end;
7340 end;
7341 function FilterPunctuation(S: String): String;
7342 var
7343 i: Integer;
7344 begin
7345 for i := Low(punct) to High(punct) do
7346 S := StringReplace(S, punct[i], ' ', [rfReplaceAll]);
7347 Result := S;
7348 end;
7349 begin
7350 ok := False;
7352 if gUseChatSounds and Taunt and (gChatSounds <> nil) and (Pos(': ', Text) > 0) then
7353 begin
7354 // remove player name
7355 Delete(Text, 1, Pos(': ', Text) + 2 - 1);
7356 // for FullWord check
7357 Text := toLowerCase1251(' ' + Text + ' ');
7358 fpText := FilterPunctuation(Text);
7360 for i := 0 to Length(gChatSounds) - 1 do
7361 begin
7362 ok := True;
7363 for j := 0 to Length(gChatSounds[i].Tags) - 1 do
7364 begin
7365 if gChatSounds[i].FullWord and (not IsPunctuation(gChatSounds[i].Tags[j])) then
7366 ok := Pos(' ' + gChatSounds[i].Tags[j] + ' ', fpText) > 0
7367 else
7368 ok := Pos(gChatSounds[i].Tags[j], Text) > 0;
7369 if not ok then
7370 break;
7371 end;
7372 if ok then
7373 begin
7374 gChatSounds[i].Sound.Play();
7375 break;
7376 end;
7377 end;
7378 end;
7379 if not ok then
7380 g_Sound_PlayEx('SOUND_GAME_RADIO');
7381 end;
7383 procedure g_Game_Announce_GoodShot(SpawnerUID: Word);
7384 var
7385 a: Integer;
7386 begin
7387 case gAnnouncer of
7388 ANNOUNCE_NONE:
7389 Exit;
7390 ANNOUNCE_ME,
7391 ANNOUNCE_MEPLUS:
7392 if not g_Game_IsWatchedPlayer(SpawnerUID) then
7393 Exit;
7394 end;
7395 for a := 0 to 3 do
7396 if goodsnd[a].IsPlaying() then
7397 Exit;
7399 goodsnd[Random(4)].Play();
7400 end;
7402 procedure g_Game_Announce_KillCombo(Param: Integer);
7403 var
7404 UID: Word;
7405 c, n: Byte;
7406 Pl: TPlayer;
7407 Name: String;
7408 begin
7409 UID := Param and $FFFF;
7410 c := Param shr 16;
7411 if c < 2 then
7412 Exit;
7414 Pl := g_Player_Get(UID);
7415 if Pl = nil then
7416 Name := '?'
7417 else
7418 Name := Pl.Name;
7420 case c of
7421 2: begin
7422 n := 0;
7423 g_Console_Add(Format(_lc[I_PLAYER_KILL_2X], [Name]), True);
7424 end;
7425 3: begin
7426 n := 1;
7427 g_Console_Add(Format(_lc[I_PLAYER_KILL_3X], [Name]), True);
7428 end;
7429 4: begin
7430 n := 2;
7431 g_Console_Add(Format(_lc[I_PLAYER_KILL_4X], [Name]), True);
7432 end;
7433 else begin
7434 n := 3;
7435 g_Console_Add(Format(_lc[I_PLAYER_KILL_MX], [Name]), True);
7436 end;
7437 end;
7439 case gAnnouncer of
7440 ANNOUNCE_NONE:
7441 Exit;
7442 ANNOUNCE_ME:
7443 if not g_Game_IsWatchedPlayer(UID) then
7444 Exit;
7445 ANNOUNCE_MEPLUS:
7446 if (not g_Game_IsWatchedPlayer(UID)) and (c < 4) then
7447 Exit;
7448 end;
7450 if killsnd[n].IsPlaying() then
7451 killsnd[n].Stop();
7452 killsnd[n].Play();
7453 end;
7455 procedure g_Game_Announce_BodyKill(SpawnerUID: Word);
7456 var
7457 a: Integer;
7458 begin
7459 case gAnnouncer of
7460 ANNOUNCE_NONE:
7461 Exit;
7462 ANNOUNCE_ME,
7463 ANNOUNCE_MEPLUS:
7464 if not g_Game_IsWatchedPlayer(SpawnerUID) then
7465 Exit;
7466 end;
7467 for a := 0 to 2 do
7468 if hahasnd[a].IsPlaying() then
7469 Exit;
7471 hahasnd[Random(3)].Play();
7472 end;
7474 procedure g_Game_StartVote(Command, Initiator: string);
7475 var
7476 Need: Integer;
7477 begin
7478 if not gVotesEnabled then Exit;
7479 if gGameSettings.GameType <> GT_SERVER then Exit;
7480 if gVoteInProgress or gVotePassed then
7481 begin
7482 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_INPROGRESS], [gVoteCommand]), True);
7483 MH_SEND_VoteEvent(NET_VE_INPROGRESS, gVoteCommand);
7484 Exit;
7485 end;
7486 gVoteInProgress := True;
7487 gVotePassed := False;
7488 gVoteTimer := gTime + gVoteTimeout * 1000;
7489 gVoteCount := 0;
7490 gVoted := False;
7491 gVoteCommand := Command;
7493 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
7494 Need := Floor((NetClientCount+1)/2.0)+1
7495 else
7496 Need := Floor(NetClientCount/2.0)+1;
7497 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_STARTED], [Initiator, Command, Need]), True);
7498 MH_SEND_VoteEvent(NET_VE_STARTED, Initiator, Command, Need);
7499 end;
7501 procedure g_Game_CheckVote;
7502 var
7503 I, Need: Integer;
7504 begin
7505 if gGameSettings.GameType <> GT_SERVER then Exit;
7506 if not gVoteInProgress then Exit;
7508 if (gTime >= gVoteTimer) then
7509 begin
7510 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
7511 Need := Floor((NetClientCount+1)/2.0) + 1
7512 else
7513 Need := Floor(NetClientCount/2.0) + 1;
7514 if gVoteCount >= Need then
7515 begin
7516 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_PASSED], [gVoteCommand]), True);
7517 MH_SEND_VoteEvent(NET_VE_PASSED, gVoteCommand);
7518 gVotePassed := True;
7519 gVoteCmdTimer := gTime + 5000;
7520 end
7521 else
7522 begin
7523 g_Console_Add(_lc[I_MESSAGE_VOTE_FAILED], True);
7524 MH_SEND_VoteEvent(NET_VE_FAILED);
7525 end;
7526 if NetClients <> nil then
7527 for I := Low(NetClients) to High(NetClients) do
7528 if NetClients[i].Used then
7529 NetClients[i].Voted := False;
7530 gVoteInProgress := False;
7531 gVoted := False;
7532 gVoteCount := 0;
7533 end
7534 else
7535 begin
7536 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
7537 Need := Floor((NetClientCount+1)/2.0) + 1
7538 else
7539 Need := Floor(NetClientCount/2.0) + 1;
7540 if gVoteCount >= Need then
7541 begin
7542 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_PASSED], [gVoteCommand]), True);
7543 MH_SEND_VoteEvent(NET_VE_PASSED, gVoteCommand);
7544 gVoteInProgress := False;
7545 gVotePassed := True;
7546 gVoteCmdTimer := gTime + 5000;
7547 gVoted := False;
7548 gVoteCount := 0;
7549 if NetClients <> nil then
7550 for I := Low(NetClients) to High(NetClients) do
7551 if NetClients[i].Used then
7552 NetClients[i].Voted := False;
7553 end;
7554 end;
7555 end;
7557 procedure g_Game_LoadMapList(FileName: string);
7558 var
7559 ListFile: TextFile;
7560 s: string;
7561 begin
7562 MapList := nil;
7563 MapIndex := -1;
7565 if not FileExists(FileName) then Exit;
7567 AssignFile(ListFile, FileName);
7568 Reset(ListFile);
7569 while not EOF(ListFile) do
7570 begin
7571 ReadLn(ListFile, s);
7573 s := Trim(s);
7574 if s = '' then Continue;
7576 SetLength(MapList, Length(MapList)+1);
7577 MapList[High(MapList)] := s;
7578 end;
7579 CloseFile(ListFile);
7580 end;
7582 procedure g_Game_SetDebugMode();
7583 begin
7584 gDebugMode := True;
7585 // ×èòû (äàæå â ñâîåé èãðå):
7586 gCheats := True;
7587 end;
7589 procedure g_Game_SetLoadingText(Text: String; Max: Integer; reWrite: Boolean);
7590 var
7591 i: Word;
7592 begin
7593 if Length(LoadingStat.Msgs) = 0 then
7594 Exit;
7596 with LoadingStat do
7597 begin
7598 if not reWrite then
7599 begin // Ïåðåõîäèì íà ñëåäóþùóþ ñòðîêó èëè ñêðîëëèðóåì:
7600 if NextMsg = Length(Msgs) then
7601 begin // scroll
7602 for i := 0 to High(Msgs)-1 do
7603 Msgs[i] := Msgs[i+1];
7604 end
7605 else
7606 Inc(NextMsg);
7607 end else
7608 if NextMsg = 0 then
7609 Inc(NextMsg);
7611 Msgs[NextMsg-1] := Text;
7612 CurValue := 0;
7613 MaxValue := Max;
7614 ShowCount := 0;
7615 PBarWasHere := false;
7616 end;
7618 g_ActiveWindow := nil;
7620 ProcessLoading(true);
7621 end;
7623 procedure g_Game_StepLoading(Value: Integer = -1);
7624 begin
7625 with LoadingStat do
7626 begin
7627 if Value = -1 then
7628 begin
7629 Inc(CurValue);
7630 Inc(ShowCount);
7631 end
7632 else
7633 CurValue := Value;
7634 if (ShowCount > LOADING_SHOW_STEP) or (Value > -1) then
7635 begin
7636 ShowCount := 0;
7637 ProcessLoading();
7638 end;
7639 end;
7640 end;
7642 procedure g_Game_ClearLoading();
7643 var
7644 len: Word;
7645 begin
7646 with LoadingStat do
7647 begin
7648 CurValue := 0;
7649 MaxValue := 0;
7650 ShowCount := 0;
7651 len := ((gScreenHeight div 3)*2 - 50) div LOADING_INTERLINE;
7652 if len < 1 then len := 1;
7653 SetLength(Msgs, len);
7654 for len := Low(Msgs) to High(Msgs) do
7655 Msgs[len] := '';
7656 NextMsg := 0;
7657 PBarWasHere := false;
7658 end;
7659 end;
7661 procedure Parse_Params(var pars: TParamStrValues);
7662 var
7663 i: Integer;
7664 s: String;
7665 begin
7666 SetLength(pars, 0);
7667 i := 1;
7668 while i <= ParamCount do
7669 begin
7670 s := ParamStr(i);
7671 if (s[1] = '-') and (Length(s) > 1) then
7672 begin
7673 if (s[2] = '-') and (Length(s) > 2) then
7674 begin // Îäèíî÷íûé ïàðàìåòð
7675 SetLength(pars, Length(pars) + 1);
7676 with pars[High(pars)] do
7677 begin
7678 Name := LowerCase(s);
7679 Value := '+';
7680 end;
7681 end
7682 else
7683 if (i < ParamCount) then
7684 begin // Ïàðàìåòð ñî çíà÷åíèåì
7685 Inc(i);
7686 SetLength(pars, Length(pars) + 1);
7687 with pars[High(pars)] do
7688 begin
7689 Name := LowerCase(s);
7690 Value := LowerCase(ParamStr(i));
7691 end;
7692 end;
7693 end;
7695 Inc(i);
7696 end;
7697 end;
7699 function Find_Param_Value(var pars: TParamStrValues; aName: String): String;
7700 var
7701 i: Integer;
7702 begin
7703 Result := '';
7704 for i := 0 to High(pars) do
7705 if pars[i].Name = aName then
7706 begin
7707 Result := pars[i].Value;
7708 Break;
7709 end;
7710 end;
7712 procedure g_Game_Process_Params();
7713 var
7714 pars: TParamStrValues;
7715 map: String;
7716 GMode, n: Byte;
7717 LimT, LimS: Integer;
7718 Opt: LongWord;
7719 Lives: Integer;
7720 s: String;
7721 Port: Integer;
7722 ip: String;
7723 F: TextFile;
7724 begin
7725 Parse_Params(pars);
7727 // Debug mode:
7728 s := Find_Param_Value(pars, '--debug');
7729 if (s <> '') then
7730 begin
7731 g_Game_SetDebugMode();
7732 s := Find_Param_Value(pars, '--netdump');
7733 if (s <> '') then
7734 NetDump := True;
7735 end;
7737 // Connect when game loads
7738 ip := Find_Param_Value(pars, '-connect');
7740 if ip <> '' then
7741 begin
7742 s := Find_Param_Value(pars, '-port');
7743 if (s = '') or not TryStrToInt(s, Port) then
7744 Port := 25666;
7746 s := Find_Param_Value(pars, '-pw');
7748 g_Game_StartClient(ip, Port, s);
7749 Exit;
7750 end;
7752 s := LowerCase(Find_Param_Value(pars, '-dbg-mainwad'));
7753 if (s <> '') then
7754 begin
7755 gDefaultMegawadStart := s;
7756 end;
7758 if (Find_Param_Value(pars, '--dbg-mainwad-restore') <> '') or
7759 (Find_Param_Value(pars, '--dbg-mainwad-default') <> '') then
7760 begin
7761 gDefaultMegawadStart := DF_Default_Megawad_Start;
7762 end;
7764 // Start map when game loads:
7765 map := LowerCase(Find_Param_Value(pars, '-map'));
7766 if isWadPath(map) then
7767 begin
7768 // Game mode:
7769 s := Find_Param_Value(pars, '-gm');
7770 GMode := g_Game_TextToMode(s);
7771 if GMode = GM_NONE then GMode := GM_DM;
7772 if GMode = GM_SINGLE then GMode := GM_COOP;
7774 // Time limit:
7775 s := Find_Param_Value(pars, '-limt');
7776 if (s = '') or (not TryStrToInt(s, LimT)) then
7777 LimT := 0;
7778 if LimT < 0 then
7779 LimT := 0;
7781 // Goal limit:
7782 s := Find_Param_Value(pars, '-lims');
7783 if (s = '') or (not TryStrToInt(s, LimS)) then
7784 LimS := 0;
7785 if LimS < 0 then
7786 LimS := 0;
7788 // Lives limit:
7789 s := Find_Param_Value(pars, '-lives');
7790 if (s = '') or (not TryStrToInt(s, Lives)) then
7791 Lives := 0;
7792 if Lives < 0 then
7793 Lives := 0;
7795 // Options:
7796 s := Find_Param_Value(pars, '-opt');
7797 if (s = '') then
7798 Opt := GAME_OPTION_ALLOWEXIT or GAME_OPTION_BOTVSPLAYER or GAME_OPTION_BOTVSMONSTER
7799 else
7800 Opt := StrToIntDef(s, 0);
7801 if Opt = 0 then
7802 Opt := GAME_OPTION_ALLOWEXIT or GAME_OPTION_BOTVSPLAYER or GAME_OPTION_BOTVSMONSTER;
7804 // Close after map:
7805 s := Find_Param_Value(pars, '--close');
7806 if (s <> '') then
7807 gMapOnce := True;
7809 // Override map to test:
7810 s := LowerCase(Find_Param_Value(pars, '-testmap'));
7811 if s <> '' then
7812 gTestMap := MapsDir + s;
7814 // Delete test map after play:
7815 s := Find_Param_Value(pars, '--testdelete');
7816 if (s <> '') then
7817 begin
7818 gMapToDelete := MapsDir + map;
7819 e_WriteLog('"--testdelete" is deprecated, use --tempdelete.', TMsgType.Fatal);
7820 Halt(1);
7821 end;
7823 // Delete temporary WAD after play:
7824 s := Find_Param_Value(pars, '--tempdelete');
7825 if (s <> '') and (gTestMap <> '') then
7826 begin
7827 gMapToDelete := gTestMap;
7828 gTempDelete := True;
7829 end;
7831 // Number of players:
7832 s := Find_Param_Value(pars, '-pl');
7833 if (s = '') then
7834 n := DEFAULT_PLAYERS
7835 else
7836 n := StrToIntDef(s, DEFAULT_PLAYERS);
7838 // Start:
7839 s := Find_Param_Value(pars, '-port');
7840 if (s = '') or not TryStrToInt(s, Port) then
7841 g_Game_StartCustom(map, GMode, LimT, LimS, Lives, Opt, n)
7842 else
7843 g_Game_StartServer(map, GMode, LimT, LimS, Lives, Opt, n, 0, Port);
7844 end;
7846 // Execute script when game loads:
7847 s := Find_Param_Value(pars, '-exec');
7848 if s <> '' then
7849 begin
7850 if not isWadPath(s) then
7851 s := GameDir + '/' + s;
7853 {$I-}
7854 AssignFile(F, s);
7855 Reset(F);
7856 if IOResult <> 0 then
7857 begin
7858 e_WriteLog(Format(_lc[I_SIMPLE_ERROR], ['Failed to read file: ' + s]), TMsgType.Warning);
7859 g_Console_Add(Format(_lc[I_CONSOLE_ERROR_READ], [s]));
7860 CloseFile(F);
7861 Exit;
7862 end;
7863 e_WriteLog('Executing script: ' + s, TMsgType.Notify);
7864 g_Console_Add(Format(_lc[I_CONSOLE_EXEC], [s]));
7866 while not EOF(F) do
7867 begin
7868 ReadLn(F, s);
7869 if IOResult <> 0 then
7870 begin
7871 e_WriteLog(Format(_lc[I_SIMPLE_ERROR], ['Failed to read file: ' + s]), TMsgType.Warning);
7872 g_Console_Add(Format(_lc[I_CONSOLE_ERROR_READ], [s]));
7873 CloseFile(F);
7874 Exit;
7875 end;
7876 if Pos('#', s) <> 1 then // script comment
7877 g_Console_Process(s, True);
7878 end;
7880 CloseFile(F);
7881 {$I+}
7882 end;
7884 SetLength(pars, 0);
7885 end;
7887 begin
7888 conRegVar('pf_draw_frame', @g_profile_frame_draw, 'draw frame rendering profiles', 'render profiles');
7889 //conRegVar('pf_update_frame', @g_profile_frame_update, 'draw frame updating profiles', 'update profiles');
7890 conRegVar('pf_coldet', @g_profile_collision, 'draw collision detection profiles', 'coldet profiles');
7891 conRegVar('pf_los', @g_profile_los, 'draw monster LOS profiles', 'monster LOS profiles');
7893 conRegVar('r_sq_draw', @gdbg_map_use_accel_render, 'accelerated spatial queries in rendering', 'accelerated rendering');
7894 conRegVar('cd_sq_enabled', @gdbg_map_use_accel_coldet, 'accelerated spatial queries in map coldet', 'accelerated map coldet');
7895 conRegVar('mon_sq_enabled', @gmon_debug_use_sqaccel, 'accelerated spatial queries for monsters', 'accelerated monster coldet');
7896 conRegVar('wtrace_sq_enabled', @gwep_debug_fast_trace, 'accelerated spatial queries for weapon hitscan trace', 'accelerated weapon hitscan');
7898 conRegVar('pr_enabled', @gpart_dbg_enabled, 'enable/disable particles', 'particles');
7899 conRegVar('pr_phys_enabled', @gpart_dbg_phys_enabled, 'enable/disable particle physics', 'particle physics');
7901 conRegVar('los_enabled', @gmon_dbg_los_enabled, 'enable/disable monster LOS calculations', 'monster LOS', true);
7902 conRegVar('mon_think', @gmon_debug_think, 'enable/disable monster thinking', 'monster thinking', true);
7904 {$IFDEF ENABLE_HOLMES}
7905 conRegVar('dbg_holmes', @g_holmes_enabled, 'enable/disable Holmes', 'Holmes', true);
7906 {$ENDIF}
7908 conRegVar('dbg_ignore_level_bounds', @g_dbg_ignore_bounds, 'ignore level bounds', '', false);
7910 conRegVar('r_scale', @g_dbg_scale, 0.01, 100.0, 'render scale', '', false);
7912 conRegVar('light_enabled', @gwin_k8_enable_light_experiments, 'enable/disable dynamic lighting', 'lighting');
7913 conRegVar('light_player_halo', @g_playerLight, 'enable/disable player halo', 'player light halo');
7915 conRegVar('r_smallmap_align_h', @r_smallmap_h, 'halign: 0: left; 1: center; 2: right', 'horizontal aligning of small maps');
7916 conRegVar('r_smallmap_align_v', @r_smallmap_v, 'valign: 0: top; 1: center; 2: bottom', 'vertial aligning of small maps');
7918 conRegVar('r_showfps', @gShowFPS, 'draw fps counter', 'draw fps counter');
7919 conRegVar('r_showtime', @gShowTime, 'show game time', 'show game time');
7920 end.