DEADSOFTWARE

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