DEADSOFTWARE

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