DEADSOFTWARE

Merge branch 'master' of ssh://repo.or.cz/d2df-sdl
[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 g_Texture_CreateWADEx('TEXTURE_endpic', s+MegaWAD.endpic);
819 end;
820 MegaWAD.endmus := cfg.ReadStr('megawad', 'endmus', 'Standart.wad:D2DMUS\ÊÎÍÅÖ');
821 if MegaWAD.endmus <> '' then
822 begin
823 s := g_ExtractWadName(MegaWAD.endmus);
824 if s = '' then s := MapsDir+WAD else s := GameDir+'/wads/';
825 g_Sound_CreateWADEx('MUSIC_endmus', s+MegaWAD.endmus, True);
826 end;
828 cfg.Free();
829 FreeMem(p);
830 w.Free();
831 end;
833 {procedure start_trigger(t: string);
834 begin
835 end;
837 function next_trigger(): Boolean;
838 begin
839 end;}
841 procedure DisableCheats();
842 begin
843 MAX_RUNVEL := 8;
844 VEL_JUMP := 10;
845 gFly := False;
847 if gPlayer1 <> nil then gPlayer1.GodMode := False;
848 if gPlayer2 <> nil then gPlayer2.GodMode := False;
849 if gPlayer1 <> nil then gPlayer1.NoTarget := False;
850 if gPlayer2 <> nil then gPlayer2.NoTarget := False;
852 {$IF DEFINED(D2F_DEBUG)}
853 if gPlayer1 <> nil then gPlayer1.NoTarget := True;
854 gAimLine := g_dbg_aimline_on;
855 {$ENDIF}
856 end;
858 procedure g_Game_ExecuteEvent(Name: String);
859 var
860 a: Integer;
861 begin
862 if Name = '' then
863 Exit;
864 if gEvents = nil then
865 Exit;
866 for a := 0 to High(gEvents) do
867 if gEvents[a].Name = Name then
868 begin
869 if gEvents[a].Command <> '' then
870 g_Console_Process(gEvents[a].Command, True);
871 break;
872 end;
873 end;
875 function g_Game_DelayEvent(DEType: Byte; Time: LongWord; Num: Integer = 0; Str: String = ''): Integer;
876 var
877 a, n: Integer;
878 begin
879 n := -1;
880 if gDelayedEvents <> nil then
881 for a := 0 to High(gDelayedEvents) do
882 if not gDelayedEvents[a].Pending then
883 begin
884 n := a;
885 break;
886 end;
887 if n = -1 then
888 begin
889 SetLength(gDelayedEvents, Length(gDelayedEvents) + 1);
890 n := High(gDelayedEvents);
891 end;
892 gDelayedEvents[n].Pending := True;
893 gDelayedEvents[n].DEType := DEType;
894 gDelayedEvents[n].DENum := Num;
895 gDelayedEvents[n].DEStr := Str;
896 if DEType = DE_GLOBEVENT then
897 gDelayedEvents[n].Time := (GetTimer() {div 1000}) + Time
898 else
899 gDelayedEvents[n].Time := gTime + Time;
900 Result := n;
901 end;
903 procedure EndGame();
904 var
905 a: Integer;
906 FileName: string;
907 begin
908 if g_Game_IsNet and g_Game_IsServer then
909 MH_SEND_GameEvent(NET_EV_MAPEND, Byte(gMissionFailed));
911 // Ñòîï èãðà:
912 gPauseMain := false;
913 gPauseHolmes := false;
914 gGameOn := false;
916 g_Game_StopAllSounds(False);
918 MessageTime := 0;
919 MessageText := '';
921 EndingGameCounter := 0;
922 g_ActiveWindow := nil;
924 gLMSRespawn := LMS_RESPAWN_NONE;
925 gLMSRespawnTime := 0;
927 case gExit of
928 EXIT_SIMPLE: // Âûõîä ÷åðåç ìåíþ èëè êîíåö òåñòà
929 begin
930 g_Game_Free();
932 if gMapOnce then
933 begin // Ýòî áûë òåñò
934 g_Game_Quit();
935 end
936 else
937 begin // Âûõîä â ãëàâíîå ìåíþ
938 gMusic.SetByName('MUSIC_MENU');
939 gMusic.Play();
940 if gState <> STATE_SLIST then
941 begin
942 g_GUI_ShowWindow('MainMenu');
943 gState := STATE_MENU;
944 end else
945 begin
946 // Îáíîâëÿåì ñïèñîê ñåðâåðîâ
947 slReturnPressed := True;
948 if g_Net_Slist_Fetch(slCurrent) then
949 begin
950 if slCurrent = nil then
951 slWaitStr := _lc[I_NET_SLIST_NOSERVERS];
952 end
953 else
954 slWaitStr := _lc[I_NET_SLIST_ERROR];
955 g_Serverlist_GenerateTable(slCurrent, slTable);
956 end;
958 g_Game_ExecuteEvent('ongameend');
959 end;
960 end;
962 EXIT_RESTART: // Íà÷àòü óðîâåíü ñíà÷àëà
963 begin
964 if not g_Game_IsClient then g_Game_Restart();
965 end;
967 EXIT_ENDLEVELCUSTOM: // Çàêîí÷èëñÿ óðîâåíü â Ñâîåé èãðå
968 begin
969 // Ñòàòèñòèêà Ñâîåé èãðû:
970 FileName := g_ExtractWadName(gMapInfo.Map);
972 CustomStat.GameTime := gTime;
973 CustomStat.Map := ExtractFileName(FileName)+':'+g_ExtractFileName(gMapInfo.Map); //ResName;
974 CustomStat.MapName := gMapInfo.Name;
975 CustomStat.GameMode := gGameSettings.GameMode;
976 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
977 CustomStat.TeamStat := gTeamStat;
979 CustomStat.PlayerStat := nil;
981 // Ñòàòèñòèêà èãðîêîâ:
982 if gPlayers <> nil then
983 begin
984 for a := 0 to High(gPlayers) do
985 if gPlayers[a] <> nil then
986 begin
987 SetLength(CustomStat.PlayerStat, Length(CustomStat.PlayerStat)+1);
988 with CustomStat.PlayerStat[High(CustomStat.PlayerStat)] do
989 begin
990 Num := a;
991 Name := gPlayers[a].Name;
992 Frags := gPlayers[a].Frags;
993 Deaths := gPlayers[a].Death;
994 Kills := gPlayers[a].Kills;
995 Team := gPlayers[a].Team;
996 Color := gPlayers[a].Model.Color;
997 Spectator := gPlayers[a].FSpectator;
998 end;
999 end;
1001 SortGameStat(CustomStat.PlayerStat);
1002 end;
1004 g_Game_ExecuteEvent('onmapend');
1005 if not g_Game_IsClient then g_Player_ResetReady;
1006 gInterReadyCount := 0;
1008 // Çàòóõàþùèé ýêðàí:
1009 EndingGameCounter := 255;
1010 gState := STATE_FOLD;
1011 gInterTime := 0;
1012 if gDefInterTime < 0 then
1013 gInterEndTime := IfThen((gGameSettings.GameType = GT_SERVER) and (gPlayer1 = nil), 15000, 25000)
1014 else
1015 gInterEndTime := gDefInterTime * 1000;
1016 end;
1018 EXIT_ENDLEVELSINGLE: // Çàêîí÷èëñÿ óðîâåíü â Îäèíî÷íîé èãðå
1019 begin
1020 // Ñòàòèñòèêà Îäèíî÷íîé èãðû:
1021 SingleStat.GameTime := gTime;
1022 SingleStat.TwoPlayers := gPlayer2 <> nil;
1023 SingleStat.TotalSecrets := gSecretsCount;
1024 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
1025 SingleStat.PlayerStat[0].Kills := gPlayer1.MonsterKills;
1026 SingleStat.PlayerStat[0].Secrets := gPlayer1.Secrets;
1027 // Ñòàòèñòèêà âòîðîãî èãðîêà (åñëè åñòü):
1028 if SingleStat.TwoPlayers then
1029 begin
1030 SingleStat.PlayerStat[1].Kills := gPlayer2.MonsterKills;
1031 SingleStat.PlayerStat[1].Secrets := gPlayer2.Secrets;
1032 end;
1034 g_Game_ExecuteEvent('onmapend');
1036 // Åñòü åùå êàðòû:
1037 if gNextMap <> '' then
1038 begin
1039 gMusic.SetByName('MUSIC_INTERMUS');
1040 gMusic.Play();
1041 gState := STATE_INTERSINGLE;
1042 e_UnpressAllKeys();
1044 g_Game_ExecuteEvent('oninter');
1045 end
1046 else // Áîëüøå íåò êàðò
1047 begin
1048 // Çàòóõàþùèé ýêðàí:
1049 EndingGameCounter := 255;
1050 gState := STATE_FOLD;
1051 end;
1052 end;
1053 end;
1055 // Îêîí÷àíèå îáðàáîòàíî:
1056 if gExit <> EXIT_QUIT then
1057 gExit := 0;
1058 end;
1060 procedure drawTime(X, Y: Integer); inline;
1061 begin
1062 e_TextureFontPrint(x, y,
1063 Format('%d:%.2d:%.2d', [
1064 gTime div 1000 div 3600,
1065 (gTime div 1000 div 60) mod 60,
1066 gTime div 1000 mod 60
1067 ]),
1068 gStdFont);
1069 end;
1071 procedure DrawStat();
1072 var
1073 pc, x, y, w, h: Integer;
1074 w1, w2, w3, w4: Integer;
1075 a, aa: Integer;
1076 cw, ch, r, g, b, rr, gg, bb: Byte;
1077 s1, s2, s3: String;
1078 _y: Integer;
1079 stat: TPlayerStatArray;
1080 wad, map: string;
1081 mapstr: string;
1082 begin
1083 s1 := '';
1084 s2 := '';
1085 s3 := '';
1086 pc := g_Player_GetCount;
1087 e_TextureFontGetSize(gStdFont, cw, ch);
1089 w := gScreenWidth-(gScreenWidth div 5);
1090 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
1091 h := 32+ch*(11+pc)
1092 else
1093 h := 40+ch*5+(ch+8)*pc;
1094 x := (gScreenWidth div 2)-(w div 2);
1095 y := (gScreenHeight div 2)-(h div 2);
1097 e_DrawFillQuad(x, y, x+w-1, y+h-1, 64, 64, 64, 32);
1098 e_DrawQuad(x, y, x+w-1, y+h-1, 255, 127, 0);
1100 drawTime(x+w-78, y+8);
1102 wad := g_ExtractWadNameNoPath(gMapInfo.Map);
1103 map := g_ExtractFileName(gMapInfo.Map);
1104 mapstr := wad + ':\' + map + ' - ' + gMapInfo.Name;
1106 case gGameSettings.GameMode of
1107 GM_DM:
1108 begin
1109 if gGameSettings.MaxLives = 0 then
1110 s1 := _lc[I_GAME_DM]
1111 else
1112 s1 := _lc[I_GAME_LMS];
1113 s2 := Format(_lc[I_GAME_FRAG_LIMIT], [gGameSettings.GoalLimit]);
1114 s3 := Format(_lc[I_GAME_TIME_LIMIT], [gGameSettings.TimeLimit div 3600, (gGameSettings.TimeLimit div 60) mod 60, gGameSettings.TimeLimit mod 60]);
1115 end;
1117 GM_TDM:
1118 begin
1119 if gGameSettings.MaxLives = 0 then
1120 s1 := _lc[I_GAME_TDM]
1121 else
1122 s1 := _lc[I_GAME_TLMS];
1123 s2 := Format(_lc[I_GAME_FRAG_LIMIT], [gGameSettings.GoalLimit]);
1124 s3 := Format(_lc[I_GAME_TIME_LIMIT], [gGameSettings.TimeLimit div 3600, (gGameSettings.TimeLimit div 60) mod 60, gGameSettings.TimeLimit mod 60]);
1125 end;
1127 GM_CTF:
1128 begin
1129 s1 := _lc[I_GAME_CTF];
1130 s2 := Format(_lc[I_GAME_SCORE_LIMIT], [gGameSettings.GoalLimit]);
1131 s3 := Format(_lc[I_GAME_TIME_LIMIT], [gGameSettings.TimeLimit div 3600, (gGameSettings.TimeLimit div 60) mod 60, gGameSettings.TimeLimit mod 60]);
1132 end;
1134 GM_COOP:
1135 begin
1136 if gGameSettings.MaxLives = 0 then
1137 s1 := _lc[I_GAME_COOP]
1138 else
1139 s1 := _lc[I_GAME_SURV];
1140 s2 := _lc[I_GAME_MONSTERS] + ' ' + IntToStr(gCoopMonstersKilled) + '/' + IntToStr(gTotalMonsters);
1141 s3 := _lc[I_GAME_SECRETS] + ' ' + IntToStr(gCoopSecretsFound) + '/' + IntToStr(gSecretsCount);
1142 end;
1144 else
1145 begin
1146 s1 := '';
1147 s2 := '';
1148 end;
1149 end;
1151 _y := y+8;
1152 e_TextureFontPrintEx(x+(w div 2)-(Length(s1)*cw div 2), _y, s1, gStdFont, 255, 255, 255, 1);
1153 _y := _y+ch+8;
1154 e_TextureFontPrintEx(x+(w div 2)-(Length(mapstr)*cw div 2), _y, mapstr, gStdFont, 200, 200, 200, 1);
1155 _y := _y+ch+8;
1156 e_TextureFontPrintEx(x+16, _y, s2, gStdFont, 200, 200, 200, 1);
1158 e_TextureFontPrintEx(x+w-16-(Length(s3))*cw, _y, s3,
1159 gStdFont, 200, 200, 200, 1);
1161 if NetMode = NET_SERVER then
1162 e_TextureFontPrintEx(x+8, y + 8, _lc[I_NET_SERVER], gStdFont, 255, 255, 255, 1)
1163 else
1164 if NetMode = NET_CLIENT then
1165 e_TextureFontPrintEx(x+8, y + 8,
1166 NetClientIP + ':' + IntToStr(NetClientPort), gStdFont, 255, 255, 255, 1);
1168 if pc = 0 then
1169 Exit;
1170 stat := g_Player_GetStats();
1171 SortGameStat(stat);
1173 w2 := (w-16) div 6 + 48; // øèðèíà 2 ñòîëáöà
1174 w3 := (w-16) div 6; // øèðèíà 3 è 4 ñòîëáöîâ
1175 w4 := w3;
1176 w1 := w-16-w2-w3-w4; // îñòàâøååñÿ ïðîñòðàíñòâî - äëÿ öâåòà è èìåíè èãðîêà
1178 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
1179 begin
1180 _y := _y+ch+ch;
1182 for a := TEAM_RED to TEAM_BLUE do
1183 begin
1184 if a = TEAM_RED then
1185 begin
1186 s1 := _lc[I_GAME_TEAM_RED];
1187 r := 255;
1188 g := 0;
1189 b := 0;
1190 end
1191 else
1192 begin
1193 s1 := _lc[I_GAME_TEAM_BLUE];
1194 r := 0;
1195 g := 0;
1196 b := 255;
1197 end;
1199 e_TextureFontPrintEx(x+16, _y, s1, gStdFont, r, g, b, 1);
1200 e_TextureFontPrintEx(x+w1+16, _y, IntToStr(gTeamStat[a].Goals),
1201 gStdFont, r, g, b, 1);
1203 _y := _y+ch+(ch div 4);
1204 e_DrawLine(1, x+16, _y, x+w-16, _y, r, g, b);
1205 _y := _y+(ch div 4);
1207 for aa := 0 to High(stat) do
1208 if stat[aa].Team = a then
1209 with stat[aa] do
1210 begin
1211 if Spectator then
1212 begin
1213 rr := r div 2;
1214 gg := g div 2;
1215 bb := b div 2;
1216 end
1217 else
1218 begin
1219 rr := r;
1220 gg := g;
1221 bb := b;
1222 end;
1223 // Èìÿ
1224 e_TextureFontPrintEx(x+16, _y, Name, gStdFont, rr, gg, bb, 1);
1225 // Ïèíã/ïîòåðè
1226 e_TextureFontPrintEx(x+w1+16, _y, Format(_lc[I_GAME_PING_MS], [Ping, Loss]), gStdFont, rr, gg, bb, 1);
1227 // Ôðàãè
1228 e_TextureFontPrintEx(x+w1+w2+16, _y, IntToStr(Frags), gStdFont, rr, gg, bb, 1);
1229 // Ñìåðòè
1230 e_TextureFontPrintEx(x+w1+w2+w3+16, _y, IntToStr(Deaths), gStdFont, rr, gg, bb, 1);
1231 _y := _y+ch;
1232 end;
1234 _y := _y+ch;
1235 end;
1236 end
1237 else if gGameSettings.GameMode in [GM_DM, GM_COOP] then
1238 begin
1239 _y := _y+ch+ch;
1240 e_TextureFontPrintEx(x+16, _y, _lc[I_GAME_PLAYER_NAME], gStdFont, 255, 127, 0, 1);
1241 e_TextureFontPrintEx(x+16+w1, _y, _lc[I_GAME_PING], gStdFont, 255, 127, 0, 1);
1242 e_TextureFontPrintEx(x+16+w1+w2, _y, _lc[I_GAME_FRAGS], gStdFont, 255, 127, 0, 1);
1243 e_TextureFontPrintEx(x+16+w1+w2+w3, _y, _lc[I_GAME_DEATHS], gStdFont, 255, 127, 0, 1);
1245 _y := _y+ch+8;
1246 for aa := 0 to High(stat) do
1247 with stat[aa] do
1248 begin
1249 if Spectator then
1250 begin
1251 r := 127;
1252 g := 64;
1253 end
1254 else
1255 begin
1256 r := 255;
1257 g := 127;
1258 end;
1259 // Öâåò èãðîêà
1260 e_DrawFillQuad(x+16, _y+4, x+32-1, _y+16+4-1, Color.R, Color.G, Color.B, 0);
1261 e_DrawQuad(x+16, _y+4, x+32-1, _y+16+4-1, 192, 192, 192);
1262 // Èìÿ
1263 e_TextureFontPrintEx(x+16+16+8, _y+4, Name, gStdFont, r, g, 0, 1);
1264 // Ïèíã/ïîòåðè
1265 e_TextureFontPrintEx(x+w1+16, _y+4, Format(_lc[I_GAME_PING_MS], [Ping, Loss]), gStdFont, r, g, 0, 1);
1266 // Ôðàãè
1267 e_TextureFontPrintEx(x+w1+w2+16, _y+4, IntToStr(Frags), gStdFont, r, g, 0, 1);
1268 // Ñìåðòè
1269 e_TextureFontPrintEx(x+w1+w2+w3+16, _y+4, IntToStr(Deaths), gStdFont, r, g, 0, 1);
1270 _y := _y+ch+8;
1271 end;
1272 end
1273 end;
1275 procedure g_Game_Init();
1276 var
1277 SR: TSearchRec;
1278 begin
1279 gExit := 0;
1280 gMapToDelete := '';
1281 gTempDelete := False;
1283 sfsGCDisable(); // temporary disable removing of temporary volumes
1285 try
1286 TEXTUREFILTER := GL_LINEAR;
1287 g_Texture_CreateWADEx('MENU_BACKGROUND', GameWAD+':TEXTURES\TITLE');
1288 g_Texture_CreateWADEx('INTER', GameWAD+':TEXTURES\INTER');
1289 g_Texture_CreateWADEx('ENDGAME_EN', GameWAD+':TEXTURES\ENDGAME_EN');
1290 g_Texture_CreateWADEx('ENDGAME_RU', GameWAD+':TEXTURES\ENDGAME_RU');
1291 TEXTUREFILTER := GL_NEAREST;
1293 LoadStdFont('STDTXT', 'STDFONT', gStdFont);
1294 LoadFont('MENUTXT', 'MENUFONT', gMenuFont);
1295 LoadFont('SMALLTXT', 'SMALLFONT', gMenuSmallFont);
1297 g_Game_ClearLoading();
1298 g_Game_SetLoadingText(Format('Doom 2D: Forever %s', [GAME_VERSION]), 0, False);
1299 g_Game_SetLoadingText('', 0, False);
1301 g_Game_SetLoadingText(_lc[I_LOAD_CONSOLE], 0, False);
1302 g_Console_Init();
1304 g_Game_SetLoadingText(_lc[I_LOAD_MODELS], 0, False);
1305 g_PlayerModel_LoadData();
1307 if FindFirst(ModelsDir+'*.wad', faAnyFile, SR) = 0 then
1308 repeat
1309 if not g_PlayerModel_Load(ModelsDir+SR.Name) then
1310 e_WriteLog(Format('Error loading model %s', [SR.Name]), TMsgType.Warning);
1311 until FindNext(SR) <> 0;
1312 FindClose(SR);
1314 if FindFirst(ModelsDir+'*.pk3', faAnyFile, SR) = 0 then
1315 repeat
1316 if not g_PlayerModel_Load(ModelsDir+SR.Name) then
1317 e_WriteLog(Format('Error loading model %s', [SR.Name]), TMsgType.Warning);
1318 until FindNext(SR) <> 0;
1319 FindClose(SR);
1321 if FindFirst(ModelsDir+'*.zip', faAnyFile, SR) = 0 then
1322 repeat
1323 if not g_PlayerModel_Load(ModelsDir+SR.Name) then
1324 e_WriteLog(Format('Error loading model %s', [SR.Name]), TMsgType.Warning);
1325 until FindNext(SR) <> 0;
1326 FindClose(SR);
1328 gGameOn := false;
1329 gPauseMain := false;
1330 gPauseHolmes := false;
1331 gTime := 0;
1333 {e_MouseInfo.Accel := 1.0;}
1335 g_Game_SetLoadingText(_lc[I_LOAD_GAME_DATA], 0, False);
1336 g_Game_LoadData();
1338 g_Game_SetLoadingText(_lc[I_LOAD_MUSIC], 0, False);
1339 g_Sound_CreateWADEx('MUSIC_INTERMUS', GameWAD+':MUSIC\INTERMUS', True);
1340 g_Sound_CreateWADEx('MUSIC_MENU', GameWAD+':MUSIC\MENU', True);
1341 g_Sound_CreateWADEx('MUSIC_ROUNDMUS', GameWAD+':MUSIC\ROUNDMUS', True, True);
1342 g_Sound_CreateWADEx('MUSIC_STDENDMUS', GameWAD+':MUSIC\ENDMUS', True);
1344 g_Game_SetLoadingText(_lc[I_LOAD_MENUS], 0, False);
1345 g_Menu_Init();
1347 gMusic := TMusic.Create();
1348 gMusic.SetByName('MUSIC_MENU');
1349 gMusic.Play();
1351 gGameSettings.WarmupTime := 30;
1353 gState := STATE_MENU;
1355 SetLength(gEvents, 6);
1356 gEvents[0].Name := 'ongamestart';
1357 gEvents[1].Name := 'ongameend';
1358 gEvents[2].Name := 'onmapstart';
1359 gEvents[3].Name := 'onmapend';
1360 gEvents[4].Name := 'oninter';
1361 gEvents[5].Name := 'onwadend';
1362 finally
1363 sfsGCEnable(); // enable releasing unused volumes
1364 end;
1365 end;
1367 procedure g_Game_Free(freeTextures: Boolean=true);
1368 begin
1369 if NetMode = NET_CLIENT then g_Net_Disconnect();
1370 if NetMode = NET_SERVER then g_Net_Host_Die();
1372 g_Map_Free(freeTextures);
1373 g_Player_Free();
1374 g_Player_RemoveAllCorpses();
1376 gGameSettings.GameType := GT_NONE;
1377 if gGameSettings.GameMode = GM_SINGLE then
1378 gGameSettings.GameMode := GM_DM;
1379 gSwitchGameMode := gGameSettings.GameMode;
1381 gChatShow := False;
1382 gExitByTrigger := False;
1383 end;
1385 function IsActivePlayer(p: TPlayer): Boolean;
1386 begin
1387 Result := False;
1388 if p = nil then
1389 Exit;
1390 Result := (not p.FDummy) and (not p.FSpectator);
1391 end;
1393 function GetActivePlayer_ByID(ID: Integer): TPlayer;
1394 var
1395 a: Integer;
1396 begin
1397 Result := nil;
1398 if ID < 0 then
1399 Exit;
1400 if gPlayers = nil then
1401 Exit;
1402 for a := Low(gPlayers) to High(gPlayers) do
1403 if IsActivePlayer(gPlayers[a]) then
1404 begin
1405 if gPlayers[a].UID <> ID then
1406 continue;
1407 Result := gPlayers[a];
1408 break;
1409 end;
1410 end;
1412 function GetActivePlayerID_Next(Skip: Integer = -1): Integer;
1413 var
1414 a, idx: Integer;
1415 ids: Array of Word;
1416 begin
1417 Result := -1;
1418 if gPlayers = nil then
1419 Exit;
1420 SetLength(ids, 0);
1421 idx := -1;
1422 for a := Low(gPlayers) to High(gPlayers) do
1423 if IsActivePlayer(gPlayers[a]) then
1424 begin
1425 SetLength(ids, Length(ids) + 1);
1426 ids[High(ids)] := gPlayers[a].UID;
1427 if gPlayers[a].UID = Skip then
1428 idx := High(ids);
1429 end;
1430 if Length(ids) = 0 then
1431 Exit;
1432 if idx = -1 then
1433 Result := ids[0]
1434 else
1435 Result := ids[(idx + 1) mod Length(ids)];
1436 end;
1438 function GetActivePlayerID_Prev(Skip: Integer = -1): Integer;
1439 var
1440 a, idx: Integer;
1441 ids: Array of Word;
1442 begin
1443 Result := -1;
1444 if gPlayers = nil then
1445 Exit;
1446 SetLength(ids, 0);
1447 idx := -1;
1448 for a := Low(gPlayers) to High(gPlayers) do
1449 if IsActivePlayer(gPlayers[a]) then
1450 begin
1451 SetLength(ids, Length(ids) + 1);
1452 ids[High(ids)] := gPlayers[a].UID;
1453 if gPlayers[a].UID = Skip then
1454 idx := High(ids);
1455 end;
1456 if Length(ids) = 0 then
1457 Exit;
1458 if idx = -1 then
1459 Result := ids[Length(ids) - 1]
1460 else
1461 Result := ids[(Length(ids) - 1 + idx) mod Length(ids)];
1462 end;
1464 function GetActivePlayerID_Random(Skip: Integer = -1): Integer;
1465 var
1466 a, idx: Integer;
1467 ids: Array of Word;
1468 begin
1469 Result := -1;
1470 if gPlayers = nil then
1471 Exit;
1472 SetLength(ids, 0);
1473 idx := -1;
1474 for a := Low(gPlayers) to High(gPlayers) do
1475 if IsActivePlayer(gPlayers[a]) then
1476 begin
1477 SetLength(ids, Length(ids) + 1);
1478 ids[High(ids)] := gPlayers[a].UID;
1479 if gPlayers[a].UID = Skip then
1480 idx := High(ids);
1481 end;
1482 if Length(ids) = 0 then
1483 Exit;
1484 if Length(ids) = 1 then
1485 begin
1486 Result := ids[0];
1487 Exit;
1488 end;
1489 Result := ids[Random(Length(ids))];
1490 a := 10;
1491 while (idx <> -1) and (Result = Skip) and (a > 0) do
1492 begin
1493 Result := ids[Random(Length(ids))];
1494 Dec(a);
1495 end;
1496 end;
1498 function GetRandomSpectMode(Current: Byte): Byte;
1499 label
1500 retry;
1501 begin
1502 Result := Current;
1503 retry:
1504 case Random(7) of
1505 0: Result := SPECT_STATS;
1506 1: Result := SPECT_MAPVIEW;
1507 2: Result := SPECT_MAPVIEW;
1508 3: Result := SPECT_PLAYERS;
1509 4: Result := SPECT_PLAYERS;
1510 5: Result := SPECT_PLAYERS;
1511 6: Result := SPECT_PLAYERS;
1512 end;
1513 if (Current in [SPECT_STATS, SPECT_MAPVIEW]) and (Current = Result) then
1514 goto retry;
1515 end;
1517 procedure ProcessPlayerControls (plr: TPlayer; p: Integer; var MoveButton: Byte);
1518 var
1519 time: Word;
1520 strafeDir: Byte;
1521 i: Integer;
1522 begin
1523 if (plr = nil) then exit;
1524 if (p = 2) then time := 1000 else time := 1;
1525 strafeDir := MoveButton shr 4;
1526 MoveButton := MoveButton and $0F;
1528 if gPlayerAction[p, ACTION_MOVELEFT] and (not gPlayerAction[p, ACTION_MOVERIGHT]) then
1529 MoveButton := 1 // Íàæàòà òîëüêî "Âëåâî"
1530 else if (not gPlayerAction[p, ACTION_MOVELEFT]) and gPlayerAction[p, ACTION_MOVERIGHT] then
1531 MoveButton := 2 // Íàæàòà òîëüêî "Âïðàâî"
1532 else if (not gPlayerAction[p, ACTION_MOVELEFT]) and (not gPlayerAction[p, ACTION_MOVERIGHT]) then
1533 MoveButton := 0; // Íå íàæàòû íè "Âëåâî", íè "Âïðàâî"
1535 // Ñåé÷àñ èëè ðàíüøå áûëè íàæàòû "Âëåâî"/"Âïðàâî" => ïåðåäàåì èãðîêó:
1536 if MoveButton = 1 then
1537 plr.PressKey(KEY_LEFT, time)
1538 else if MoveButton = 2 then
1539 plr.PressKey(KEY_RIGHT, time);
1541 // if we have "strafe" key, turn off old strafe mechanics
1542 if gPlayerAction[p, ACTION_STRAFE] then
1543 begin
1544 // new strafe mechanics
1545 if (strafeDir = 0) then
1546 strafeDir := MoveButton; // start strafing
1547 // now set direction according to strafe (reversed)
1548 if (strafeDir = 2) then
1549 plr.SetDirection(TDirection.D_LEFT)
1550 else if (strafeDir = 1) then
1551 plr.SetDirection(TDirection.D_RIGHT)
1552 end
1553 else
1554 begin
1555 strafeDir := 0; // not strafing anymore
1556 // Ðàíüøå áûëà íàæàòà "Âïðàâî", à ñåé÷àñ "Âëåâî" => áåæèì âïðàâî, ñìîòðèì âëåâî:
1557 if (MoveButton = 2) and gPlayerAction[p, ACTION_MOVELEFT] then
1558 plr.SetDirection(TDirection.D_LEFT)
1559 // Ðàíüøå áûëà íàæàòà "Âëåâî", à ñåé÷àñ "Âïðàâî" => áåæèì âëåâî, ñìîòðèì âïðàâî:
1560 else if (MoveButton = 1) and gPlayerAction[p, ACTION_MOVERIGHT] then
1561 plr.SetDirection(TDirection.D_RIGHT)
1562 // ×òî-òî áûëî íàæàòî è íå èçìåíèëîñü => êóäà áåæèì, òóäà è ñìîòðèì:
1563 else if MoveButton <> 0 then
1564 plr.SetDirection(TDirection(MoveButton-1))
1565 end;
1567 // fix movebutton state
1568 MoveButton := MoveButton or (strafeDir shl 4);
1570 // Îñòàëüíûå êëàâèøè:
1571 if gPlayerAction[p, ACTION_JUMP] then plr.PressKey(KEY_JUMP, time);
1572 if gPlayerAction[p, ACTION_LOOKUP] then plr.PressKey(KEY_UP, time);
1573 if gPlayerAction[p, ACTION_LOOKDOWN] then plr.PressKey(KEY_DOWN, time);
1574 if gPlayerAction[p, ACTION_ATTACK] then plr.PressKey(KEY_FIRE);
1575 if gPlayerAction[p, ACTION_WEAPNEXT] then plr.PressKey(KEY_NEXTWEAPON);
1576 if gPlayerAction[p, ACTION_WEAPPREV] then plr.PressKey(KEY_PREVWEAPON);
1577 if gPlayerAction[p, ACTION_ACTIVATE] then plr.PressKey(KEY_OPEN);
1579 gPlayerAction[p, ACTION_WEAPNEXT] := False; // HACK, remove after readyweaon&pendinweapon implementation
1580 gPlayerAction[p, ACTION_WEAPPREV] := False; // HACK, remove after readyweaon&pendinweapon implementation
1582 for i := WP_FIRST to WP_LAST do
1583 begin
1584 if gSelectWeapon[p, i] then
1585 begin
1586 plr.QueueWeaponSwitch(i); // all choices are passed there, and god will take the best
1587 gSelectWeapon[p, i] := False
1588 end
1589 end;
1591 // HACK: add dynlight here
1592 if gwin_k8_enable_light_experiments then
1593 begin
1594 if e_KeyPressed(IK_F8) and gGameOn and (not gConsoleShow) and (g_ActiveWindow = nil) then
1595 begin
1596 g_playerLight := true;
1597 end;
1598 if e_KeyPressed(IK_F9) and gGameOn and (not gConsoleShow) and (g_ActiveWindow = nil) then
1599 begin
1600 g_playerLight := false;
1601 end;
1602 end;
1604 if gwin_has_stencil and g_playerLight then g_AddDynLight(plr.GameX+32, plr.GameY+40, 128, 1, 1, 0, 0.6);
1605 end;
1607 // HACK: don't have a "key was pressed" function
1608 procedure InterReady();
1609 begin
1610 if InterReadyTime > gTime then Exit;
1611 InterReadyTime := gTime + 3000;
1612 MC_SEND_CheatRequest(NET_CHEAT_READY);
1613 end;
1615 procedure g_Game_Update();
1616 var
1617 Msg: g_gui.TMessage;
1618 Time: Int64;
1619 a: Byte;
1620 w: Word;
1621 i, b: Integer;
1623 function sendMonsPos (mon: TMonster): Boolean;
1624 begin
1625 result := false; // don't stop
1626 // this will also reset "need-send" flag
1627 if mon.gncNeedSend then
1628 begin
1629 MH_SEND_MonsterPos(mon.UID);
1630 end
1631 else if (mon.MonsterType = MONSTER_BARREL) then
1632 begin
1633 if (mon.GameVelX <> 0) or (mon.GameVelY <> 0) then MH_SEND_MonsterPos(mon.UID);
1634 end
1635 else if (mon.MonsterState <> MONSTATE_SLEEP) then
1636 begin
1637 if (mon.MonsterState <> MONSTATE_DEAD) or (mon.GameVelX <> 0) or (mon.GameVelY <> 0) then MH_SEND_MonsterPos(mon.UID);
1638 end;
1639 end;
1641 function sendMonsPosUnexpected (mon: TMonster): Boolean;
1642 begin
1643 result := false; // don't stop
1644 // this will also reset "need-send" flag
1645 if mon.gncNeedSend then MH_SEND_MonsterPos(mon.UID);
1646 end;
1648 var
1649 reliableUpdate: Boolean;
1650 begin
1651 g_ResetDynlights();
1652 framePool.reset();
1654 // Ïîðà âûêëþ÷àòü èãðó:
1655 if gExit = EXIT_QUIT then
1656 Exit;
1657 // Èãðà çàêîí÷èëàñü - îáðàáàòûâàåì:
1658 if gExit <> 0 then
1659 begin
1660 EndGame();
1661 if gExit = EXIT_QUIT then
1662 Exit;
1663 end;
1665 // ×èòàåì êëàâèàòóðó è äæîéñòèê, åñëè îêíî àêòèâíî
1666 // no need to, as we'll do it in event handler
1668 // Îáíîâëÿåì êîíñîëü (äâèæåíèå è ñîîáùåíèÿ):
1669 g_Console_Update();
1671 if (NetMode = NET_NONE) and (g_Game_IsNet) and (gGameOn or (gState in [STATE_FOLD, STATE_INTERCUSTOM])) then
1672 begin
1673 gExit := EXIT_SIMPLE;
1674 EndGame();
1675 Exit;
1676 end;
1678 case gState of
1679 STATE_INTERSINGLE, // Ñòàòèñòêà ïîñëå ïðîõîæäåíèÿ óðîâíÿ â Îäèíî÷íîé èãðå
1680 STATE_INTERCUSTOM, // Ñòàòèñòêà ïîñëå ïðîõîæäåíèÿ óðîâíÿ â Ñâîåé èãðå
1681 STATE_INTERTEXT, // Òåêñò ìåæäó óðîâíÿìè
1682 STATE_INTERPIC: // Êàðòèíêà ìåæäó óðîâíÿìè
1683 begin
1684 if g_Game_IsNet and g_Game_IsServer then
1685 begin
1686 gInterTime := gInterTime + GAME_TICK;
1687 a := Min((gInterEndTime - gInterTime) div 1000 + 1, 255);
1688 if a <> gServInterTime then
1689 begin
1690 gServInterTime := a;
1691 MH_SEND_TimeSync(gServInterTime);
1692 end;
1693 end;
1695 if (not g_Game_IsClient) and
1699 e_KeyPressed(IK_RETURN) or e_KeyPressed(IK_KPRETURN) or e_KeyPressed(IK_SPACE) or
1700 e_KeyPressed(VK_FIRE) or e_KeyPressed(VK_OPEN) or
1701 e_KeyPressed(JOY0_ATTACK) or e_KeyPressed(JOY1_ATTACK) or
1702 e_KeyPressed(JOY2_ATTACK) or e_KeyPressed(JOY3_ATTACK)
1704 and (not gJustChatted) and (not gConsoleShow) and (not gChatShow)
1705 and (g_ActiveWindow = nil)
1707 or (g_Game_IsNet and ((gInterTime > gInterEndTime) or (gInterReadyCount >= NetClientCount)))
1709 then
1710 begin // Íàæàëè <Enter>/<Ïðîáåë> èëè ïðîøëî äîñòàòî÷íî âðåìåíè:
1711 g_Game_StopAllSounds(True);
1713 if gMapOnce then // Ýòî áûë òåñò
1714 gExit := EXIT_SIMPLE
1715 else
1716 if gNextMap <> '' then // Ïåðåõîäèì íà ñëåäóþùóþ êàðòó
1717 g_Game_ChangeMap(gNextMap)
1718 else // Ñëåäóþùåé êàðòû íåò
1719 begin
1720 if gGameSettings.GameType in [GT_CUSTOM, GT_SERVER] then
1721 begin
1722 // Âûõîä â ãëàâíîå ìåíþ:
1723 g_Game_Free;
1724 g_GUI_ShowWindow('MainMenu');
1725 gMusic.SetByName('MUSIC_MENU');
1726 gMusic.Play();
1727 gState := STATE_MENU;
1728 end else
1729 begin
1730 // Ôèíàëüíàÿ êàðòèíêà:
1731 g_Game_ExecuteEvent('onwadend');
1732 g_Game_Free();
1733 if not gMusic.SetByName('MUSIC_endmus') then
1734 gMusic.SetByName('MUSIC_STDENDMUS');
1735 gMusic.Play();
1736 gState := STATE_ENDPIC;
1737 end;
1738 g_Game_ExecuteEvent('ongameend');
1739 end;
1741 Exit;
1742 end
1743 else if g_Game_IsClient and
1746 e_KeyPressed(IK_RETURN) or e_KeyPressed(IK_KPRETURN) or e_KeyPressed(IK_SPACE) or
1747 e_KeyPressed(VK_FIRE) or e_KeyPressed(VK_OPEN) or
1748 e_KeyPressed(JOY0_ATTACK) or e_KeyPressed(JOY1_ATTACK) or
1749 e_KeyPressed(JOY2_ATTACK) or e_KeyPressed(JOY3_ATTACK)
1751 and (not gJustChatted) and (not gConsoleShow) and (not gChatShow)
1752 and (g_ActiveWindow = nil)
1754 then
1755 begin
1756 // ready / unready
1757 InterReady();
1758 end;
1760 if gState = STATE_INTERTEXT then
1761 if InterText.counter > 0 then
1762 InterText.counter := InterText.counter - 1;
1763 end;
1765 STATE_FOLD: // Çàòóõàíèå ýêðàíà
1766 begin
1767 if EndingGameCounter = 0 then
1768 begin
1769 // Çàêîí÷èëñÿ óðîâåíü â Ñâîåé èãðå:
1770 if gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT] then
1771 begin
1772 InterReadyTime := -1;
1773 if gLastMap and (gGameSettings.GameMode = GM_COOP) then
1774 begin
1775 g_Game_ExecuteEvent('onwadend');
1776 if not gMusic.SetByName('MUSIC_endmus') then
1777 gMusic.SetByName('MUSIC_STDENDMUS');
1778 end
1779 else
1780 gMusic.SetByName('MUSIC_ROUNDMUS');
1782 gMusic.Play();
1783 gState := STATE_INTERCUSTOM;
1784 e_UnpressAllKeys();
1785 end
1786 else // Çàêîí÷èëàñü ïîñëåäíÿÿ êàðòà â Îäèíî÷íîé èãðå
1787 begin
1788 gMusic.SetByName('MUSIC_INTERMUS');
1789 gMusic.Play();
1790 gState := STATE_INTERSINGLE;
1791 e_UnpressAllKeys();
1792 end;
1793 g_Game_ExecuteEvent('oninter');
1794 end
1795 else
1796 DecMin(EndingGameCounter, 6, 0);
1797 end;
1799 STATE_ENDPIC: // Êàðòèíêà îêîí÷àíèÿ ìåãàÂàäà
1800 begin
1801 if gMapOnce then // Ýòî áûë òåñò
1802 begin
1803 gExit := EXIT_SIMPLE;
1804 Exit;
1805 end;
1806 end;
1808 STATE_SLIST:
1809 g_Serverlist_Control(slCurrent, slTable);
1810 end;
1812 // Ñòàòèñòèêà ïî Tab:
1813 if gGameOn then
1814 IsDrawStat := (not gConsoleShow) and (not gChatShow) and (gGameSettings.GameType <> GT_SINGLE) and g_Console_Action(ACTION_SCORES);
1816 // Èãðà èäåò:
1817 if gGameOn and not gPause and (gState <> STATE_FOLD) then
1818 begin
1819 // Âðåìÿ += 28 ìèëëèñåêóíä:
1820 gTime := gTime + GAME_TICK;
1822 // Ñîîáùåíèå ïîñåðåäèíå ýêðàíà:
1823 if MessageTime = 0 then
1824 MessageText := '';
1825 if MessageTime > 0 then
1826 MessageTime := MessageTime - 1;
1828 if (g_Game_IsServer) then
1829 begin
1830 // Áûë çàäàí ëèìèò âðåìåíè:
1831 if (gGameSettings.TimeLimit > 0) then
1832 if (gTime - gGameStartTime) div 1000 >= gGameSettings.TimeLimit then
1833 begin // Îí ïðîøåë => êîíåö óðîâíÿ
1834 g_Game_NextLevel();
1835 Exit;
1836 end;
1838 // Íàäî ðåñïàâíèòü èãðîêîâ â LMS:
1839 if (gLMSRespawn > LMS_RESPAWN_NONE) and (gLMSRespawnTime < gTime) then
1840 g_Game_RestartRound(gLMSSoftSpawn);
1842 // Ïðîâåðèì ðåçóëüòàò ãîëîñîâàíèÿ, åñëè âðåìÿ ïðîøëî
1843 if gVoteInProgress and (gVoteTimer < gTime) then
1844 g_Game_CheckVote
1845 else if gVotePassed and (gVoteCmdTimer < gTime) then
1846 begin
1847 g_Console_Process(gVoteCommand);
1848 gVoteCommand := '';
1849 gVotePassed := False;
1850 end;
1852 // Çàìåðÿåì âðåìÿ çàõâàòà ôëàãîâ
1853 if gFlags[FLAG_RED].State = FLAG_STATE_CAPTURED then
1854 gFlags[FLAG_RED].CaptureTime := gFlags[FLAG_RED].CaptureTime + GAME_TICK;
1855 if gFlags[FLAG_BLUE].State = FLAG_STATE_CAPTURED then
1856 gFlags[FLAG_BLUE].CaptureTime := gFlags[FLAG_BLUE].CaptureTime + GAME_TICK;
1858 // Áûë çàäàí ëèìèò ïîáåä:
1859 if (gGameSettings.GoalLimit > 0) then
1860 begin
1861 b := 0;
1863 if gGameSettings.GameMode = GM_DM then
1864 begin // Â DM èùåì èãðîêà ñ max ôðàãàìè
1865 for i := 0 to High(gPlayers) do
1866 if gPlayers[i] <> nil then
1867 if gPlayers[i].Frags > b then
1868 b := gPlayers[i].Frags;
1869 end
1870 else
1871 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
1872 begin //  CTF/TDM âûáèðàåì êîìàíäó ñ íàèáîëüøèì ñ÷åòîì
1873 b := Max(gTeamStat[TEAM_RED].Goals, gTeamStat[TEAM_BLUE].Goals);
1874 end;
1876 // Ëèìèò ïîáåä íàáðàí => êîíåö óðîâíÿ:
1877 if b >= gGameSettings.GoalLimit then
1878 begin
1879 g_Game_NextLevel();
1880 Exit;
1881 end;
1882 end;
1884 // Îáðàáàòûâàåì êëàâèøè èãðîêîâ:
1885 if gPlayer1 <> nil then gPlayer1.ReleaseKeys();
1886 if gPlayer2 <> nil then gPlayer2.ReleaseKeys();
1887 if (not gConsoleShow) and (not gChatShow) and (g_ActiveWindow = nil) then
1888 begin
1889 ProcessPlayerControls(gPlayer1, 0, P1MoveButton);
1890 ProcessPlayerControls(gPlayer2, 1, P2MoveButton);
1891 end // if not console
1892 else
1893 begin
1894 if g_Game_IsNet and (gPlayer1 <> nil) then gPlayer1.PressKey(KEY_CHAT, 10000);
1895 end;
1896 // process weapon switch queue
1897 end; // if server
1899 // Íàáëþäàòåëü
1900 if (gPlayer1 = nil) and (gPlayer2 = nil) and
1901 (not gConsoleShow) and (not gChatShow) and (g_ActiveWindow = nil) then
1902 begin
1903 if not gSpectKeyPress then
1904 begin
1905 if gPlayerAction[0, ACTION_JUMP] and (not gSpectAuto) then
1906 begin
1907 // switch spect mode
1908 case gSpectMode of
1909 SPECT_NONE: ; // not spectator
1910 SPECT_STATS,
1911 SPECT_MAPVIEW: Inc(gSpectMode);
1912 SPECT_PLAYERS: gSpectMode := SPECT_STATS; // reset to 1
1913 end;
1914 gSpectKeyPress := True;
1915 end;
1916 if (gSpectMode = SPECT_MAPVIEW)
1917 and (not gSpectAuto) then
1918 begin
1919 if gPlayerAction[0, ACTION_MOVELEFT] then
1920 gSpectX := Max(gSpectX - gSpectStep, 0);
1921 if gPlayerAction[0, ACTION_MOVERIGHT] then
1922 gSpectX := Min(gSpectX + gSpectStep, gMapInfo.Width - gScreenWidth);
1923 if gPlayerAction[0, ACTION_LOOKUP] then
1924 gSpectY := Max(gSpectY - gSpectStep, 0);
1925 if gPlayerAction[0, ACTION_LOOKDOWN] then
1926 gSpectY := Min(gSpectY + gSpectStep, gMapInfo.Height - gScreenHeight);
1927 if gPlayerAction[0, ACTION_WEAPPREV] then
1928 begin
1929 // decrease step
1930 if gSpectStep > 4 then gSpectStep := gSpectStep shr 1;
1931 gSpectKeyPress := True;
1932 end;
1933 if gPlayerAction[0, ACTION_WEAPNEXT] then
1934 begin
1935 // increase step
1936 if gSpectStep < 64 then gSpectStep := gSpectStep shl 1;
1937 gSpectKeyPress := True;
1938 end;
1939 end;
1940 if (gSpectMode = SPECT_PLAYERS)
1941 and (not gSpectAuto) then
1942 begin
1943 if gPlayerAction[0, ACTION_LOOKUP] then
1944 begin
1945 // add second view
1946 gSpectViewTwo := True;
1947 gSpectKeyPress := True;
1948 end;
1949 if gPlayerAction[0, ACTION_LOOKDOWN] then
1950 begin
1951 // remove second view
1952 gSpectViewTwo := False;
1953 gSpectKeyPress := True;
1954 end;
1955 if gPlayerAction[0, ACTION_MOVELEFT] then
1956 begin
1957 // prev player (view 1)
1958 gSpectPID1 := GetActivePlayerID_Prev(gSpectPID1);
1959 gSpectKeyPress := True;
1960 end;
1961 if gPlayerAction[0, ACTION_MOVERIGHT] then
1962 begin
1963 // next player (view 1)
1964 gSpectPID1 := GetActivePlayerID_Next(gSpectPID1);
1965 gSpectKeyPress := True;
1966 end;
1967 if gPlayerAction[0, ACTION_WEAPPREV] then
1968 begin
1969 // prev player (view 2)
1970 gSpectPID2 := GetActivePlayerID_Prev(gSpectPID2);
1971 gSpectKeyPress := True;
1972 end;
1973 if gPlayerAction[0, ACTION_WEAPNEXT] then
1974 begin
1975 // next player (view 2)
1976 gSpectPID2 := GetActivePlayerID_Next(gSpectPID2);
1977 gSpectKeyPress := True;
1978 end;
1979 end;
1980 if gPlayerAction[0, ACTION_ATTACK] then
1981 begin
1982 if (gSpectMode = SPECT_STATS) and (not gSpectAuto) then
1983 begin
1984 gSpectAuto := True;
1985 gSpectAutoNext := 0;
1986 gSpectViewTwo := False;
1987 gSpectKeyPress := True;
1988 end
1989 else
1990 if gSpectAuto then
1991 begin
1992 gSpectMode := SPECT_STATS;
1993 gSpectAuto := False;
1994 gSpectKeyPress := True;
1995 end;
1996 end;
1997 end
1998 else
1999 if (not gPlayerAction[0, ACTION_JUMP]) and
2000 (not gPlayerAction[0, ACTION_ATTACK]) and
2001 (not gPlayerAction[0, ACTION_MOVELEFT]) and
2002 (not gPlayerAction[0, ACTION_MOVERIGHT]) and
2003 (not gPlayerAction[0, ACTION_LOOKUP]) and
2004 (not gPlayerAction[0, ACTION_LOOKDOWN]) and
2005 (not gPlayerAction[0, ACTION_WEAPPREV]) and
2006 (not gPlayerAction[0, ACTION_WEAPNEXT]) then
2007 gSpectKeyPress := False;
2009 if gSpectAuto then
2010 begin
2011 if gSpectMode = SPECT_MAPVIEW then
2012 begin
2013 i := Min(Max(gSpectX + gSpectAutoStepX, 0), gMapInfo.Width - gScreenWidth);
2014 if i = gSpectX then
2015 gSpectAutoNext := gTime
2016 else
2017 gSpectX := i;
2018 i := Min(Max(gSpectY + gSpectAutoStepY, 0), gMapInfo.Height - gScreenHeight);
2019 if i = gSpectY then
2020 gSpectAutoNext := gTime
2021 else
2022 gSpectY := i;
2023 end;
2024 if gSpectAutoNext <= gTime then
2025 begin
2026 if gSpectAutoNext > 0 then
2027 begin
2028 gSpectMode := GetRandomSpectMode(gSpectMode);
2029 case gSpectMode of
2030 SPECT_MAPVIEW:
2031 begin
2032 gSpectX := Random(gMapInfo.Width - gScreenWidth);
2033 gSpectY := Random(gMapInfo.Height - gScreenHeight);
2034 gSpectAutoStepX := Random(9) - 4;
2035 gSpectAutoStepY := Random(9) - 4;
2036 if ((gSpectX < 800) and (gSpectAutoStepX < 0)) or
2037 ((gSpectX > gMapInfo.Width - gScreenWidth - 800) and (gSpectAutoStepX > 0)) then
2038 gSpectAutoStepX := gSpectAutoStepX * -1;
2039 if ((gSpectY < 800) and (gSpectAutoStepY < 0)) or
2040 ((gSpectY > gMapInfo.Height - gScreenHeight - 800) and (gSpectAutoStepY > 0)) then
2041 gSpectAutoStepY := gSpectAutoStepY * -1;
2042 end;
2043 SPECT_PLAYERS:
2044 begin
2045 gSpectPID1 := GetActivePlayerID_Random(gSpectPID1);
2046 end;
2047 end;
2048 end;
2049 case gSpectMode of
2050 SPECT_STATS: gSpectAutoNext := gTime + (Random(3) + 5) * 1000;
2051 SPECT_MAPVIEW: gSpectAutoNext := gTime + (Random(4) + 7) * 1000;
2052 SPECT_PLAYERS: gSpectAutoNext := gTime + (Random(7) + 8) * 1000;
2053 end;
2054 end;
2055 end;
2056 end;
2058 // Îáíîâëÿåì âñå îñòàëüíîå:
2059 g_Map_Update();
2060 g_Items_Update();
2061 g_Triggers_Update();
2062 g_Weapon_Update();
2063 g_Monsters_Update();
2064 g_GFX_Update();
2065 g_Player_UpdateAll();
2066 g_Player_UpdatePhysicalObjects();
2068 // server: send newly spawned monsters unconditionally
2069 if (gGameSettings.GameType = GT_SERVER) then
2070 begin
2071 if (Length(gMonstersSpawned) > 0) then
2072 begin
2073 for I := 0 to High(gMonstersSpawned) do MH_SEND_MonsterSpawn(gMonstersSpawned[I]);
2074 SetLength(gMonstersSpawned, 0);
2075 end;
2076 end;
2078 if (gSoundTriggerTime > 8) then
2079 begin
2080 g_Game_UpdateTriggerSounds();
2081 gSoundTriggerTime := 0;
2082 end
2083 else
2084 begin
2085 Inc(gSoundTriggerTime);
2086 end;
2088 if (NetMode = NET_SERVER) then
2089 begin
2090 Inc(NetTimeToUpdate);
2091 Inc(NetTimeToReliable);
2093 // send monster updates
2094 if (NetTimeToReliable >= NetRelupdRate) or (NetTimeToUpdate >= NetUpdateRate) then
2095 begin
2096 // send all monsters (periodic sync)
2097 reliableUpdate := (NetTimeToReliable >= NetRelupdRate);
2099 for I := 0 to High(gPlayers) do
2100 begin
2101 if (gPlayers[I] <> nil) then MH_SEND_PlayerPos(reliableUpdate, gPlayers[I].UID);
2102 end;
2104 g_Mons_ForEach(sendMonsPos);
2106 if reliableUpdate then
2107 begin
2108 NetTimeToReliable := 0;
2109 NetTimeToUpdate := NetUpdateRate;
2110 end
2111 else
2112 begin
2113 NetTimeToUpdate := 0;
2114 end;
2115 end
2116 else
2117 begin
2118 // send only mosters with some unexpected changes
2119 g_Mons_ForEach(sendMonsPosUnexpected);
2120 end;
2122 // send unexpected platform changes
2123 g_Map_NetSendInterestingPanels();
2125 if NetUseMaster then
2126 begin
2127 if gTime >= NetTimeToMaster then
2128 begin
2129 if (NetMHost = nil) or (NetMPeer = nil) then
2130 begin
2131 if not g_Net_Slist_Connect then g_Console_Add(_lc[I_NET_MSG_ERROR] + _lc[I_NET_SLIST_ERROR]);
2132 end;
2134 g_Net_Slist_Update;
2135 NetTimeToMaster := gTime + NetMasterRate;
2136 end;
2137 end;
2138 end
2139 else if (NetMode = NET_CLIENT) then
2140 begin
2141 MC_SEND_PlayerPos();
2142 end;
2143 end; // if gameOn ...
2145 // Àêòèâíî îêíî èíòåðôåéñà - ïåðåäàåì êëàâèøè åìó:
2146 if g_ActiveWindow <> nil then
2147 begin
2148 w := e_GetFirstKeyPressed();
2150 if (w <> IK_INVALID) then
2151 begin
2152 Msg.Msg := MESSAGE_DIKEY;
2153 Msg.wParam := w;
2154 g_ActiveWindow.OnMessage(Msg);
2155 end;
2157 // Åñëè îíî îò ýòîãî íå çàêðûëîñü, òî îáíîâëÿåì:
2158 if g_ActiveWindow <> nil then
2159 g_ActiveWindow.Update();
2161 // Íóæíî ñìåíèòü ðàçðåøåíèå:
2162 if gResolutionChange then
2163 begin
2164 e_WriteLog('Changing resolution', TMsgType.Notify);
2165 g_Game_ChangeResolution(gRC_Width, gRC_Height, gRC_FullScreen, gRC_Maximized);
2166 gResolutionChange := False;
2167 g_ActiveWindow := nil;
2168 end;
2170 // Íóæíî ñìåíèòü ÿçûê:
2171 if gLanguageChange then
2172 begin
2173 //e_WriteLog('Read language file', MSG_NOTIFY);
2174 //g_Language_Load(DataDir + gLanguage + '.txt');
2175 g_Language_Set(gLanguage);
2176 g_Menu_Reset();
2177 gLanguageChange := False;
2178 end;
2179 end;
2181 // Ãîðÿ÷àÿ êëàâèøà äëÿ âûçîâà ìåíþ âûõîäà èç èãðû (F10):
2182 if e_KeyPressed(IK_F10) and
2183 gGameOn and
2184 (not gConsoleShow) and
2185 (g_ActiveWindow = nil) then
2186 begin
2187 KeyPress(IK_F10);
2188 end;
2190 Time := GetTimer() {div 1000};
2192 // Îáðàáîòêà îòëîæåííûõ ñîáûòèé:
2193 if gDelayedEvents <> nil then
2194 for a := 0 to High(gDelayedEvents) do
2195 if gDelayedEvents[a].Pending and
2197 ((gDelayedEvents[a].DEType = DE_GLOBEVENT) and (gDelayedEvents[a].Time <= Time)) or
2198 ((gDelayedEvents[a].DEType > DE_GLOBEVENT) and (gDelayedEvents[a].Time <= gTime))
2199 ) then
2200 begin
2201 case gDelayedEvents[a].DEType of
2202 DE_GLOBEVENT:
2203 g_Game_ExecuteEvent(gDelayedEvents[a].DEStr);
2204 DE_BFGHIT:
2205 if gGameOn then
2206 g_Game_Announce_GoodShot(gDelayedEvents[a].DENum);
2207 DE_KILLCOMBO:
2208 if gGameOn then
2209 begin
2210 g_Game_Announce_KillCombo(gDelayedEvents[a].DENum);
2211 if g_Game_IsNet and g_Game_IsServer then
2212 MH_SEND_GameEvent(NET_EV_KILLCOMBO, gDelayedEvents[a].DENum);
2213 end;
2214 DE_BODYKILL:
2215 if gGameOn then
2216 g_Game_Announce_BodyKill(gDelayedEvents[a].DENum);
2217 end;
2218 gDelayedEvents[a].Pending := False;
2219 end;
2221 // Êàæäóþ ñåêóíäó îáíîâëÿåì ñ÷åò÷èê îáíîâëåíèé:
2222 UPSCounter := UPSCounter + 1;
2223 if Time - UPSTime >= 1000 then
2224 begin
2225 UPS := UPSCounter;
2226 UPSCounter := 0;
2227 UPSTime := Time;
2228 end;
2230 if gGameOn then
2231 begin
2232 g_Weapon_AddDynLights();
2233 g_Items_AddDynLights();
2234 end;
2235 end;
2237 procedure g_Game_LoadChatSounds(Resource: string);
2238 var
2239 WAD: TWADFile;
2240 FileName, Snd: string;
2241 p: Pointer;
2242 len, cnt, tags, i, j: Integer;
2243 cfg: TConfig;
2244 begin
2245 FileName := g_ExtractWadName(Resource);
2247 WAD := TWADFile.Create();
2248 WAD.ReadFile(FileName);
2250 if not WAD.GetResource(g_ExtractFilePathName(Resource), p, len) then
2251 begin
2252 gChatSounds := nil;
2253 WAD.Free();
2254 Exit;
2255 end;
2257 cfg := TConfig.CreateMem(p, len);
2258 cnt := cfg.ReadInt('ChatSounds', 'Count', 0);
2260 SetLength(gChatSounds, cnt);
2261 for i := 0 to Length(gChatSounds) - 1 do
2262 begin
2263 gChatSounds[i].Sound := nil;
2264 Snd := Trim(cfg.ReadStr(IntToStr(i), 'Sound', ''));
2265 tags := cfg.ReadInt(IntToStr(i), 'Tags', 0);
2266 if (Snd = '') or (Tags <= 0) then
2267 continue;
2268 g_Sound_CreateWADEx('SOUND_CHAT_MACRO' + IntToStr(i), GameWAD+':'+Snd);
2269 gChatSounds[i].Sound := TPlayableSound.Create();
2270 gChatSounds[i].Sound.SetByName('SOUND_CHAT_MACRO' + IntToStr(i));
2271 SetLength(gChatSounds[i].Tags, tags);
2272 for j := 0 to tags - 1 do
2273 gChatSounds[i].Tags[j] := toLowerCase1251(cfg.ReadStr(IntToStr(i), 'Tag' + IntToStr(j), ''));
2274 gChatSounds[i].FullWord := cfg.ReadBool(IntToStr(i), 'FullWord', False);
2275 end;
2277 cfg.Free();
2278 WAD.Free();
2279 end;
2281 procedure g_Game_FreeChatSounds();
2282 var
2283 i: Integer;
2284 begin
2285 for i := 0 to Length(gChatSounds) - 1 do
2286 begin
2287 gChatSounds[i].Sound.Free();
2288 g_Sound_Delete('SOUND_CHAT_MACRO' + IntToStr(i));
2289 end;
2290 SetLength(gChatSounds, 0);
2291 gChatSounds := nil;
2292 end;
2294 procedure g_Game_LoadData();
2295 var
2296 wl, hl: Integer;
2297 wr, hr: Integer;
2298 wb, hb: Integer;
2299 wm, hm: Integer;
2300 begin
2301 if DataLoaded then Exit;
2303 e_WriteLog('Loading game data...', TMsgType.Notify);
2305 g_Texture_CreateWADEx('NOTEXTURE', GameWAD+':TEXTURES\NOTEXTURE');
2306 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUD', GameWAD+':TEXTURES\HUD');
2307 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDAIR', GameWAD+':TEXTURES\AIRBAR');
2308 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDJET', GameWAD+':TEXTURES\JETBAR');
2309 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDBG', GameWAD+':TEXTURES\HUDBG');
2310 g_Texture_CreateWADEx('TEXTURE_PLAYER_ARMORHUD', GameWAD+':TEXTURES\ARMORHUD');
2311 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG', GameWAD+':TEXTURES\FLAGHUD_R_BASE');
2312 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_S', GameWAD+':TEXTURES\FLAGHUD_R_STOLEN');
2313 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_D', GameWAD+':TEXTURES\FLAGHUD_R_DROP');
2314 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG', GameWAD+':TEXTURES\FLAGHUD_B_BASE');
2315 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_S', GameWAD+':TEXTURES\FLAGHUD_B_STOLEN');
2316 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_D', GameWAD+':TEXTURES\FLAGHUD_B_DROP');
2317 g_Texture_CreateWADEx('TEXTURE_PLAYER_TALKBUBBLE', GameWAD+':TEXTURES\TALKBUBBLE');
2318 g_Texture_CreateWADEx('TEXTURE_PLAYER_INVULPENTA', GameWAD+':TEXTURES\PENTA');
2319 g_Texture_CreateWADEx('TEXTURE_PLAYER_INDICATOR', GameWAD+':TEXTURES\PLRIND');
2321 hasPBarGfx := true;
2322 if not g_Texture_CreateWADEx('UI_GFX_PBAR_LEFT', GameWAD+':TEXTURES\LLEFT') then hasPBarGfx := false;
2323 if not g_Texture_CreateWADEx('UI_GFX_PBAR_MARKER', GameWAD+':TEXTURES\LMARKER') then hasPBarGfx := false;
2324 if not g_Texture_CreateWADEx('UI_GFX_PBAR_MIDDLE', GameWAD+':TEXTURES\LMIDDLE') then hasPBarGfx := false;
2325 if not g_Texture_CreateWADEx('UI_GFX_PBAR_RIGHT', GameWAD+':TEXTURES\LRIGHT') then hasPBarGfx := false;
2327 if hasPBarGfx then
2328 begin
2329 g_Texture_GetSize('UI_GFX_PBAR_LEFT', wl, hl);
2330 g_Texture_GetSize('UI_GFX_PBAR_RIGHT', wr, hr);
2331 g_Texture_GetSize('UI_GFX_PBAR_MIDDLE', wb, hb);
2332 g_Texture_GetSize('UI_GFX_PBAR_MARKER', wm, hm);
2333 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
2334 begin
2335 // yay!
2336 end
2337 else
2338 begin
2339 hasPBarGfx := false;
2340 end;
2341 end;
2343 g_Frames_CreateWAD(nil, 'FRAMES_TELEPORT', GameWAD+':TEXTURES\TELEPORT', 64, 64, 10, False);
2344 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH', GameWAD+':WEAPONS\PUNCH', 64, 64, 4, False);
2345 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_UP', GameWAD+':WEAPONS\PUNCH_UP', 64, 64, 4, False);
2346 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_DN', GameWAD+':WEAPONS\PUNCH_DN', 64, 64, 4, False);
2347 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK', GameWAD+':WEAPONS\PUNCHB', 64, 64, 4, False);
2348 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK_UP', GameWAD+':WEAPONS\PUNCHB_UP', 64, 64, 4, False);
2349 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK_DN', GameWAD+':WEAPONS\PUNCHB_DN', 64, 64, 4, False);
2350 g_Sound_CreateWADEx('SOUND_GAME_TELEPORT', GameWAD+':SOUNDS\TELEPORT');
2351 g_Sound_CreateWADEx('SOUND_GAME_NOTELEPORT', GameWAD+':SOUNDS\NOTELEPORT');
2352 g_Sound_CreateWADEx('SOUND_GAME_SECRET', GameWAD+':SOUNDS\SECRET');
2353 g_Sound_CreateWADEx('SOUND_GAME_DOOROPEN', GameWAD+':SOUNDS\DOOROPEN');
2354 g_Sound_CreateWADEx('SOUND_GAME_DOORCLOSE', GameWAD+':SOUNDS\DOORCLOSE');
2355 g_Sound_CreateWADEx('SOUND_GAME_BULK1', GameWAD+':SOUNDS\BULK1');
2356 g_Sound_CreateWADEx('SOUND_GAME_BULK2', GameWAD+':SOUNDS\BULK2');
2357 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE1', GameWAD+':SOUNDS\BUBBLE1');
2358 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE2', GameWAD+':SOUNDS\BUBBLE2');
2359 g_Sound_CreateWADEx('SOUND_GAME_BURNING', GameWAD+':SOUNDS\BURNING');
2360 g_Sound_CreateWADEx('SOUND_GAME_SWITCH1', GameWAD+':SOUNDS\SWITCH1');
2361 g_Sound_CreateWADEx('SOUND_GAME_SWITCH0', GameWAD+':SOUNDS\SWITCH0');
2362 g_Sound_CreateWADEx('SOUND_GAME_RADIO', GameWAD+':SOUNDS\RADIO');
2363 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD1', GameWAD+':SOUNDS\GOOD1');
2364 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD2', GameWAD+':SOUNDS\GOOD2');
2365 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD3', GameWAD+':SOUNDS\GOOD3');
2366 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD4', GameWAD+':SOUNDS\GOOD4');
2367 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL2X', GameWAD+':SOUNDS\KILL2X');
2368 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL3X', GameWAD+':SOUNDS\KILL3X');
2369 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL4X', GameWAD+':SOUNDS\KILL4X');
2370 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILLMX', GameWAD+':SOUNDS\KILLMX');
2371 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA1', GameWAD+':SOUNDS\MUHAHA1');
2372 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA2', GameWAD+':SOUNDS\MUHAHA2');
2373 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA3', GameWAD+':SOUNDS\MUHAHA3');
2374 g_Sound_CreateWADEx('SOUND_CTF_GET1', GameWAD+':SOUNDS\GETFLAG1');
2375 g_Sound_CreateWADEx('SOUND_CTF_GET2', GameWAD+':SOUNDS\GETFLAG2');
2376 g_Sound_CreateWADEx('SOUND_CTF_LOST1', GameWAD+':SOUNDS\LOSTFLG1');
2377 g_Sound_CreateWADEx('SOUND_CTF_LOST2', GameWAD+':SOUNDS\LOSTFLG2');
2378 g_Sound_CreateWADEx('SOUND_CTF_RETURN1', GameWAD+':SOUNDS\RETFLAG1');
2379 g_Sound_CreateWADEx('SOUND_CTF_RETURN2', GameWAD+':SOUNDS\RETFLAG2');
2380 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE1', GameWAD+':SOUNDS\CAPFLAG1');
2381 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE2', GameWAD+':SOUNDS\CAPFLAG2');
2383 goodsnd[0] := TPlayableSound.Create();
2384 goodsnd[1] := TPlayableSound.Create();
2385 goodsnd[2] := TPlayableSound.Create();
2386 goodsnd[3] := TPlayableSound.Create();
2388 goodsnd[0].SetByName('SOUND_ANNOUNCER_GOOD1');
2389 goodsnd[1].SetByName('SOUND_ANNOUNCER_GOOD2');
2390 goodsnd[2].SetByName('SOUND_ANNOUNCER_GOOD3');
2391 goodsnd[3].SetByName('SOUND_ANNOUNCER_GOOD4');
2393 killsnd[0] := TPlayableSound.Create();
2394 killsnd[1] := TPlayableSound.Create();
2395 killsnd[2] := TPlayableSound.Create();
2396 killsnd[3] := TPlayableSound.Create();
2398 killsnd[0].SetByName('SOUND_ANNOUNCER_KILL2X');
2399 killsnd[1].SetByName('SOUND_ANNOUNCER_KILL3X');
2400 killsnd[2].SetByName('SOUND_ANNOUNCER_KILL4X');
2401 killsnd[3].SetByName('SOUND_ANNOUNCER_KILLMX');
2403 hahasnd[0] := TPlayableSound.Create();
2404 hahasnd[1] := TPlayableSound.Create();
2405 hahasnd[2] := TPlayableSound.Create();
2407 hahasnd[0].SetByName('SOUND_ANNOUNCER_MUHAHA1');
2408 hahasnd[1].SetByName('SOUND_ANNOUNCER_MUHAHA2');
2409 hahasnd[2].SetByName('SOUND_ANNOUNCER_MUHAHA3');
2411 sound_get_flag[0] := TPlayableSound.Create();
2412 sound_get_flag[1] := TPlayableSound.Create();
2413 sound_lost_flag[0] := TPlayableSound.Create();
2414 sound_lost_flag[1] := TPlayableSound.Create();
2415 sound_ret_flag[0] := TPlayableSound.Create();
2416 sound_ret_flag[1] := TPlayableSound.Create();
2417 sound_cap_flag[0] := TPlayableSound.Create();
2418 sound_cap_flag[1] := TPlayableSound.Create();
2420 sound_get_flag[0].SetByName('SOUND_CTF_GET1');
2421 sound_get_flag[1].SetByName('SOUND_CTF_GET2');
2422 sound_lost_flag[0].SetByName('SOUND_CTF_LOST1');
2423 sound_lost_flag[1].SetByName('SOUND_CTF_LOST2');
2424 sound_ret_flag[0].SetByName('SOUND_CTF_RETURN1');
2425 sound_ret_flag[1].SetByName('SOUND_CTF_RETURN2');
2426 sound_cap_flag[0].SetByName('SOUND_CTF_CAPTURE1');
2427 sound_cap_flag[1].SetByName('SOUND_CTF_CAPTURE2');
2429 g_Game_LoadChatSounds(GameWAD+':CHATSND\SNDCFG');
2431 g_Game_SetLoadingText(_lc[I_LOAD_ITEMS_DATA], 0, False);
2432 g_Items_LoadData();
2434 g_Game_SetLoadingText(_lc[I_LOAD_WEAPONS_DATA], 0, False);
2435 g_Weapon_LoadData();
2437 g_Monsters_LoadData();
2439 DataLoaded := True;
2440 end;
2442 procedure g_Game_FreeData();
2443 begin
2444 if not DataLoaded then Exit;
2446 g_Items_FreeData();
2447 g_Weapon_FreeData();
2448 g_Monsters_FreeData();
2450 e_WriteLog('Releasing game data...', TMsgType.Notify);
2452 g_Texture_Delete('NOTEXTURE');
2453 g_Texture_Delete('TEXTURE_PLAYER_HUD');
2454 g_Texture_Delete('TEXTURE_PLAYER_HUDBG');
2455 g_Texture_Delete('TEXTURE_PLAYER_ARMORHUD');
2456 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG');
2457 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_S');
2458 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_D');
2459 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG');
2460 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_S');
2461 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_D');
2462 g_Texture_Delete('TEXTURE_PLAYER_TALKBUBBLE');
2463 g_Texture_Delete('TEXTURE_PLAYER_INVULPENTA');
2464 g_Frames_DeleteByName('FRAMES_TELEPORT');
2465 g_Frames_DeleteByName('FRAMES_PUNCH');
2466 g_Frames_DeleteByName('FRAMES_PUNCH_UP');
2467 g_Frames_DeleteByName('FRAMES_PUNCH_DN');
2468 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK');
2469 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK_UP');
2470 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK_DN');
2471 g_Sound_Delete('SOUND_GAME_TELEPORT');
2472 g_Sound_Delete('SOUND_GAME_NOTELEPORT');
2473 g_Sound_Delete('SOUND_GAME_SECRET');
2474 g_Sound_Delete('SOUND_GAME_DOOROPEN');
2475 g_Sound_Delete('SOUND_GAME_DOORCLOSE');
2476 g_Sound_Delete('SOUND_GAME_BULK1');
2477 g_Sound_Delete('SOUND_GAME_BULK2');
2478 g_Sound_Delete('SOUND_GAME_BUBBLE1');
2479 g_Sound_Delete('SOUND_GAME_BUBBLE2');
2480 g_Sound_Delete('SOUND_GAME_BURNING');
2481 g_Sound_Delete('SOUND_GAME_SWITCH1');
2482 g_Sound_Delete('SOUND_GAME_SWITCH0');
2484 goodsnd[0].Free();
2485 goodsnd[1].Free();
2486 goodsnd[2].Free();
2487 goodsnd[3].Free();
2489 g_Sound_Delete('SOUND_ANNOUNCER_GOOD1');
2490 g_Sound_Delete('SOUND_ANNOUNCER_GOOD2');
2491 g_Sound_Delete('SOUND_ANNOUNCER_GOOD3');
2492 g_Sound_Delete('SOUND_ANNOUNCER_GOOD4');
2494 killsnd[0].Free();
2495 killsnd[1].Free();
2496 killsnd[2].Free();
2497 killsnd[3].Free();
2499 g_Sound_Delete('SOUND_ANNOUNCER_KILL2X');
2500 g_Sound_Delete('SOUND_ANNOUNCER_KILL3X');
2501 g_Sound_Delete('SOUND_ANNOUNCER_KILL4X');
2502 g_Sound_Delete('SOUND_ANNOUNCER_KILLMX');
2504 hahasnd[0].Free();
2505 hahasnd[1].Free();
2506 hahasnd[2].Free();
2508 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA1');
2509 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA2');
2510 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA3');
2512 sound_get_flag[0].Free();
2513 sound_get_flag[1].Free();
2514 sound_lost_flag[0].Free();
2515 sound_lost_flag[1].Free();
2516 sound_ret_flag[0].Free();
2517 sound_ret_flag[1].Free();
2518 sound_cap_flag[0].Free();
2519 sound_cap_flag[1].Free();
2521 g_Sound_Delete('SOUND_CTF_GET1');
2522 g_Sound_Delete('SOUND_CTF_GET2');
2523 g_Sound_Delete('SOUND_CTF_LOST1');
2524 g_Sound_Delete('SOUND_CTF_LOST2');
2525 g_Sound_Delete('SOUND_CTF_RETURN1');
2526 g_Sound_Delete('SOUND_CTF_RETURN2');
2527 g_Sound_Delete('SOUND_CTF_CAPTURE1');
2528 g_Sound_Delete('SOUND_CTF_CAPTURE2');
2530 g_Game_FreeChatSounds();
2532 DataLoaded := False;
2533 end;
2535 procedure DrawCustomStat();
2536 var
2537 pc, x, y, w, _y,
2538 w1, w2, w3,
2539 t, p, m: Integer;
2540 ww1, hh1: Word;
2541 ww2, hh2, r, g, b, rr, gg, bb: Byte;
2542 s1, s2, topstr: String;
2543 begin
2544 e_TextureFontGetSize(gStdFont, ww2, hh2);
2546 g_ProcessMessages();
2548 if g_Console_Action(ACTION_SCORES) then
2549 begin
2550 if not gStatsPressed then
2551 begin
2552 gStatsOff := not gStatsOff;
2553 gStatsPressed := True;
2554 end;
2555 end
2556 else
2557 gStatsPressed := False;
2559 if gStatsOff then
2560 begin
2561 s1 := _lc[I_MENU_INTER_NOTICE_TAB];
2562 w := (Length(s1) * ww2) div 2;
2563 x := gScreenWidth div 2 - w;
2564 y := 8;
2565 e_TextureFontPrint(x, y, s1, gStdFont);
2566 Exit;
2567 end;
2569 if (gGameSettings.GameMode = GM_COOP) then
2570 begin
2571 if gMissionFailed then
2572 topstr := _lc[I_MENU_INTER_MISSION_FAIL]
2573 else
2574 topstr := _lc[I_MENU_INTER_LEVEL_COMPLETE];
2575 end
2576 else
2577 topstr := _lc[I_MENU_INTER_ROUND_OVER];
2579 e_CharFont_GetSize(gMenuFont, topstr, ww1, hh1);
2580 e_CharFont_Print(gMenuFont, (gScreenWidth div 2)-(ww1 div 2), 16, topstr);
2582 if g_Game_IsNet then
2583 begin
2584 topstr := Format(_lc[I_MENU_INTER_NOTICE_TIME], [gServInterTime]);
2585 if not gChatShow then
2586 e_TextureFontPrintEx((gScreenWidth div 2)-(Length(topstr)*ww2 div 2),
2587 gScreenHeight-(hh2+4)*2, topstr, gStdFont, 255, 255, 255, 1);
2588 end;
2590 if g_Game_IsClient then
2591 topstr := _lc[I_MENU_INTER_NOTICE_MAP]
2592 else
2593 topstr := _lc[I_MENU_INTER_NOTICE_SPACE];
2594 if not gChatShow then
2595 e_TextureFontPrintEx((gScreenWidth div 2)-(Length(topstr)*ww2 div 2),
2596 gScreenHeight-(hh2+4), topstr, gStdFont, 255, 255, 255, 1);
2598 x := 32;
2599 y := 16+hh1+16;
2601 w := gScreenWidth-x*2;
2603 w2 := (w-16) div 6;
2604 w3 := w2;
2605 w1 := w-16-w2-w3;
2607 e_DrawFillQuad(x, y, gScreenWidth-x-1, gScreenHeight-y-1, 64, 64, 64, 32);
2608 e_DrawQuad(x, y, gScreenWidth-x-1, gScreenHeight-y-1, 255, 127, 0);
2610 m := Max(Length(_lc[I_MENU_MAP])+1, Length(_lc[I_GAME_GAME_TIME])+1)*ww2;
2612 case CustomStat.GameMode of
2613 GM_DM:
2614 begin
2615 if gGameSettings.MaxLives = 0 then
2616 s1 := _lc[I_GAME_DM]
2617 else
2618 s1 := _lc[I_GAME_LMS];
2619 end;
2620 GM_TDM:
2621 begin
2622 if gGameSettings.MaxLives = 0 then
2623 s1 := _lc[I_GAME_TDM]
2624 else
2625 s1 := _lc[I_GAME_TLMS];
2626 end;
2627 GM_CTF: s1 := _lc[I_GAME_CTF];
2628 GM_COOP:
2629 begin
2630 if gGameSettings.MaxLives = 0 then
2631 s1 := _lc[I_GAME_COOP]
2632 else
2633 s1 := _lc[I_GAME_SURV];
2634 end;
2635 else s1 := '';
2636 end;
2638 _y := y+16;
2639 e_TextureFontPrintEx(x+(w div 2)-(Length(s1)*ww2 div 2), _y, s1, gStdFont, 255, 255, 255, 1);
2640 _y := _y+8;
2642 _y := _y+16;
2643 e_TextureFontPrintEx(x+8, _y, _lc[I_MENU_MAP], gStdFont, 255, 127, 0, 1);
2644 e_TextureFontPrint(x+8+m, _y, Format('%s - %s', [CustomStat.Map, CustomStat.MapName]), gStdFont);
2646 _y := _y+16;
2647 e_TextureFontPrintEx(x+8, _y, _lc[I_GAME_GAME_TIME], gStdFont, 255, 127, 0, 1);
2648 e_TextureFontPrint(x+8+m, _y, Format('%d:%.2d:%.2d', [CustomStat.GameTime div 1000 div 3600,
2649 (CustomStat.GameTime div 1000 div 60) mod 60,
2650 CustomStat.GameTime div 1000 mod 60]), gStdFont);
2652 pc := Length(CustomStat.PlayerStat);
2653 if pc = 0 then Exit;
2655 if CustomStat.GameMode = GM_COOP then
2656 begin
2657 m := Max(Length(_lc[I_GAME_MONSTERS])+1, Length(_lc[I_GAME_SECRETS])+1)*ww2;
2658 _y := _y+32;
2659 s2 := _lc[I_GAME_MONSTERS];
2660 e_TextureFontPrintEx(x+8, _y, s2, gStdFont, 255, 127, 0, 1);
2661 e_TextureFontPrintEx(x+8+m, _y, IntToStr(gCoopMonstersKilled) + '/' + IntToStr(gTotalMonsters), gStdFont, 255, 255, 255, 1);
2662 _y := _y+16;
2663 s2 := _lc[I_GAME_SECRETS];
2664 e_TextureFontPrintEx(x+8, _y, s2, gStdFont, 255, 127, 0, 1);
2665 e_TextureFontPrintEx(x+8+m, _y, IntToStr(gCoopSecretsFound) + '/' + IntToStr(gSecretsCount), gStdFont, 255, 255, 255, 1);
2666 if gLastMap then
2667 begin
2668 m := Max(Length(_lc[I_GAME_MONSTERS_TOTAL])+1, Length(_lc[I_GAME_SECRETS_TOTAL])+1)*ww2;
2669 _y := _y-16;
2670 s2 := _lc[I_GAME_MONSTERS_TOTAL];
2671 e_TextureFontPrintEx(x+250, _y, s2, gStdFont, 255, 127, 0, 1);
2672 e_TextureFontPrintEx(x+250+m, _y, IntToStr(gCoopTotalMonstersKilled) + '/' + IntToStr(gCoopTotalMonsters), gStdFont, 255, 255, 255, 1);
2673 _y := _y+16;
2674 s2 := _lc[I_GAME_SECRETS_TOTAL];
2675 e_TextureFontPrintEx(x+250, _y, s2, gStdFont, 255, 127, 0, 1);
2676 e_TextureFontPrintEx(x+250+m, _y, IntToStr(gCoopTotalSecretsFound) + '/' + IntToStr(gCoopTotalSecrets), gStdFont, 255, 255, 255, 1);
2677 end;
2678 end;
2680 if CustomStat.GameMode in [GM_TDM, GM_CTF] then
2681 begin
2682 _y := _y+16+16;
2684 with CustomStat do
2685 if TeamStat[TEAM_RED].Goals > TeamStat[TEAM_BLUE].Goals then s1 := _lc[I_GAME_WIN_RED]
2686 else if TeamStat[TEAM_BLUE].Goals > TeamStat[TEAM_RED].Goals then s1 := _lc[I_GAME_WIN_BLUE]
2687 else s1 := _lc[I_GAME_WIN_DRAW];
2689 e_TextureFontPrintEx(x+8+(w div 2)-(Length(s1)*ww2 div 2), _y, s1, gStdFont, 255, 255, 255, 1);
2690 _y := _y+40;
2692 for t := TEAM_RED to TEAM_BLUE do
2693 begin
2694 if t = TEAM_RED then
2695 begin
2696 e_TextureFontPrintEx(x+8, _y, _lc[I_GAME_TEAM_RED],
2697 gStdFont, 255, 0, 0, 1);
2698 e_TextureFontPrintEx(x+w1+8, _y, IntToStr(CustomStat.TeamStat[TEAM_RED].Goals),
2699 gStdFont, 255, 0, 0, 1);
2700 r := 255;
2701 g := 0;
2702 b := 0;
2703 end
2704 else
2705 begin
2706 e_TextureFontPrintEx(x+8, _y, _lc[I_GAME_TEAM_BLUE],
2707 gStdFont, 0, 0, 255, 1);
2708 e_TextureFontPrintEx(x+w1+8, _y, IntToStr(CustomStat.TeamStat[TEAM_BLUE].Goals),
2709 gStdFont, 0, 0, 255, 1);
2710 r := 0;
2711 g := 0;
2712 b := 255;
2713 end;
2715 e_DrawLine(1, x+8, _y+20, x-8+w, _y+20, r, g, b);
2716 _y := _y+24;
2718 for p := 0 to High(CustomStat.PlayerStat) do
2719 if CustomStat.PlayerStat[p].Team = t then
2720 with CustomStat.PlayerStat[p] do
2721 begin
2722 if Spectator then
2723 begin
2724 rr := r div 2;
2725 gg := g div 2;
2726 bb := b div 2;
2727 end
2728 else
2729 begin
2730 rr := r;
2731 gg := g;
2732 bb := b;
2733 end;
2734 if (gPlayers[Num] <> nil) and (gPlayers[Num].FReady) then
2735 e_TextureFontPrintEx(x+16, _y, Name + ' *', gStdFont, rr, gg, bb, 1)
2736 else
2737 e_TextureFontPrintEx(x+16, _y, Name, gStdFont, rr, gg, bb, 1);
2738 e_TextureFontPrintEx(x+w1+16, _y, IntToStr(Frags), gStdFont, rr, gg, bb, 1);
2739 e_TextureFontPrintEx(x+w1+w2+16, _y, IntToStr(Deaths), gStdFont, rr, gg, bb, 1);
2740 _y := _y+24;
2741 end;
2743 _y := _y+16+16;
2744 end;
2745 end
2746 else if CustomStat.GameMode in [GM_DM, GM_COOP] then
2747 begin
2748 _y := _y+40;
2749 e_TextureFontPrintEx(x+8, _y, _lc[I_GAME_PLAYER_NAME], gStdFont, 255, 127, 0, 1);
2750 e_TextureFontPrintEx(x+8+w1, _y, _lc[I_GAME_FRAGS], gStdFont, 255, 127, 0, 1);
2751 e_TextureFontPrintEx(x+8+w1+w2, _y, _lc[I_GAME_DEATHS], gStdFont, 255, 127, 0, 1);
2753 _y := _y+24;
2754 for p := 0 to High(CustomStat.PlayerStat) do
2755 with CustomStat.PlayerStat[p] do
2756 begin
2757 e_DrawFillQuad(x+8, _y+4, x+24-1, _y+16+4-1, Color.R, Color.G, Color.B, 0);
2759 if Spectator then
2760 r := 127
2761 else
2762 r := 255;
2764 if (gPlayers[Num] <> nil) and (gPlayers[Num].FReady) then
2765 e_TextureFontPrintEx(x+8+16+8, _y+4, Name + ' *', gStdFont, r, r, r, 1, True)
2766 else
2767 e_TextureFontPrintEx(x+8+16+8, _y+4, Name, gStdFont, r, r, r, 1, True);
2768 e_TextureFontPrintEx(x+w1+8+16+8, _y+4, IntToStr(Frags), gStdFont, r, r, r, 1, True);
2769 e_TextureFontPrintEx(x+w1+w2+8+16+8, _y+4, IntToStr(Deaths), gStdFont, r, r, r, 1, True);
2770 _y := _y+24;
2771 end;
2772 end;
2773 end;
2775 procedure DrawSingleStat();
2776 var
2777 tm, key_x, val_x, y: Integer;
2778 w1, w2, h: Word;
2779 s1, s2: String;
2781 procedure player_stat(n: Integer);
2782 var
2783 kpm: Real;
2785 begin
2786 // "Kills: # / #":
2787 s1 := Format(' %d ', [SingleStat.PlayerStat[n].Kills]);
2788 s2 := Format(' %d', [gTotalMonsters]);
2790 e_CharFont_Print(gMenuFont, key_x, y, _lc[I_MENU_INTER_KILLS]);
2791 e_CharFont_PrintEx(gMenuFont, val_x, y, s1, _RGB(255, 0, 0));
2792 e_CharFont_GetSize(gMenuFont, s1, w1, h);
2793 e_CharFont_Print(gMenuFont, val_x+w1, y, '/');
2794 s1 := s1 + '/';
2795 e_CharFont_GetSize(gMenuFont, s1, w1, h);
2796 e_CharFont_PrintEx(gMenuFont, val_x+w1, y, s2, _RGB(255, 0, 0));
2798 // "Kills-per-minute: ##.#":
2799 s1 := _lc[I_MENU_INTER_KPM];
2800 if tm > 0 then
2801 kpm := (SingleStat.PlayerStat[n].Kills / tm) * 60
2802 else
2803 kpm := SingleStat.PlayerStat[n].Kills;
2804 s2 := Format(' %.1f', [kpm]);
2806 e_CharFont_Print(gMenuFont, key_x, y+32, s1);
2807 e_CharFont_PrintEx(gMenuFont, val_x, y+32, s2, _RGB(255, 0, 0));
2809 // "Secrets found: # / #":
2810 s1 := Format(' %d ', [SingleStat.PlayerStat[n].Secrets]);
2811 s2 := Format(' %d', [SingleStat.TotalSecrets]);
2813 e_CharFont_Print(gMenuFont, key_x, y+64, _lc[I_MENU_INTER_SECRETS]);
2814 e_CharFont_PrintEx(gMenuFont, val_x, y+64, s1, _RGB(255, 0, 0));
2815 e_CharFont_GetSize(gMenuFont, s1, w1, h);
2816 e_CharFont_Print(gMenuFont, val_x+w1, y+64, '/');
2817 s1 := s1 + '/';
2818 e_CharFont_GetSize(gMenuFont, s1, w1, h);
2819 e_CharFont_PrintEx(gMenuFont, val_x+w1, y+64, s2, _RGB(255, 0, 0));
2820 end;
2822 begin
2823 // "Level Complete":
2824 e_CharFont_GetSize(gMenuFont, _lc[I_MENU_INTER_LEVEL_COMPLETE], w1, h);
2825 e_CharFont_Print(gMenuFont, (gScreenWidth-w1) div 2, 32, _lc[I_MENU_INTER_LEVEL_COMPLETE]);
2827 // Îïðåäåëÿåì êîîðäèíàòû âûðàâíèâàíèÿ ïî ñàìîé äëèííîé ñòðîêå:
2828 s1 := _lc[I_MENU_INTER_KPM];
2829 e_CharFont_GetSize(gMenuFont, s1, w1, h);
2830 Inc(w1, 16);
2831 s1 := ' 9999.9';
2832 e_CharFont_GetSize(gMenuFont, s1, w2, h);
2834 key_x := (gScreenWidth-w1-w2) div 2;
2835 val_x := key_x + w1;
2837 // "Time: #:##:##":
2838 tm := SingleStat.GameTime div 1000;
2839 s1 := _lc[I_MENU_INTER_TIME];
2840 s2 := Format(' %d:%.2d:%.2d', [tm div (60*60), (tm mod (60*60)) div 60, tm mod 60]);
2842 e_CharFont_Print(gMenuFont, key_x, 80, s1);
2843 e_CharFont_PrintEx(gMenuFont, val_x, 80, s2, _RGB(255, 0, 0));
2845 if SingleStat.TwoPlayers then
2846 begin
2847 // "Player 1":
2848 s1 := _lc[I_MENU_PLAYER_1];
2849 e_CharFont_GetSize(gMenuFont, s1, w1, h);
2850 e_CharFont_Print(gMenuFont, (gScreenWidth-w1) div 2, 128, s1);
2852 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
2853 y := 176;
2854 player_stat(0);
2856 // "Player 2":
2857 s1 := _lc[I_MENU_PLAYER_2];
2858 e_CharFont_GetSize(gMenuFont, s1, w1, h);
2859 e_CharFont_Print(gMenuFont, (gScreenWidth-w1) div 2, 288, s1);
2861 // Ñòàòèñòèêà âòîðîãî èãðîêà:
2862 y := 336;
2863 player_stat(1);
2864 end
2865 else
2866 begin
2867 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
2868 y := 128;
2869 player_stat(0);
2870 end;
2871 end;
2873 procedure DrawLoadingStat();
2874 procedure drawRect (x, y, w, h: Integer);
2875 begin
2876 if (w < 1) or (h < 1) then exit;
2877 glBegin(GL_QUADS);
2878 glVertex2f(x+0.375, y+0.375);
2879 glVertex2f(x+w+0.375, y+0.375);
2880 glVertex2f(x+w+0.375, y+h+0.375);
2881 glVertex2f(x+0.375, y+h+0.375);
2882 glEnd();
2883 end;
2885 function drawPBar (cur, total: Integer; washere: Boolean): Boolean;
2886 var
2887 rectW, rectH: Integer;
2888 x0, y0: Integer;
2889 wdt: Integer;
2890 wl, hl: Integer;
2891 wr, hr: Integer;
2892 wb, hb: Integer;
2893 wm, hm: Integer;
2894 idl, idr, idb, idm: LongWord;
2895 f, my: Integer;
2896 begin
2897 result := false;
2898 if (total < 1) then exit;
2899 if (cur < 1) then exit; // don't blink
2900 if (not washere) and (cur >= total) then exit; // don't blink
2901 //if (cur < 0) then cur := 0;
2902 //if (cur > total) then cur := total;
2903 result := true;
2905 if (hasPBarGfx) then
2906 begin
2907 g_Texture_Get('UI_GFX_PBAR_LEFT', idl);
2908 g_Texture_GetSize('UI_GFX_PBAR_LEFT', wl, hl);
2909 g_Texture_Get('UI_GFX_PBAR_RIGHT', idr);
2910 g_Texture_GetSize('UI_GFX_PBAR_RIGHT', wr, hr);
2911 g_Texture_Get('UI_GFX_PBAR_MIDDLE', idb);
2912 g_Texture_GetSize('UI_GFX_PBAR_MIDDLE', wb, hb);
2913 g_Texture_Get('UI_GFX_PBAR_MARKER', idm);
2914 g_Texture_GetSize('UI_GFX_PBAR_MARKER', wm, hm);
2916 //rectW := gScreenWidth-360;
2917 rectW := trunc(624.0*gScreenWidth/1024.0);
2918 rectH := hl;
2920 x0 := (gScreenWidth-rectW) div 2;
2921 y0 := gScreenHeight-rectH-64;
2922 if (y0 < 2) then y0 := 2;
2924 glEnable(GL_SCISSOR_TEST);
2926 // left and right
2927 glScissor(x0, gScreenHeight-y0-rectH, rectW, rectH);
2928 e_DrawSize(idl, x0, y0, 0, true, false, wl, hl);
2929 e_DrawSize(idr, x0+rectW-wr, y0, 0, true, false, wr, hr);
2931 // body
2932 glScissor(x0+wl, gScreenHeight-y0-rectH, rectW-wl-wr, rectH);
2933 f := x0+wl;
2934 while (f < x0+rectW) do
2935 begin
2936 e_DrawSize(idb, f, y0, 0, true, false, wb, hb);
2937 f += wb;
2938 end;
2940 // filled part
2941 wdt := (rectW-wl-wr)*cur div total;
2942 if (wdt > rectW-wl-wr) then wdt := rectW-wr-wr;
2943 if (wdt > 0) then
2944 begin
2945 my := y0; // don't be so smart, ketmar: +(rectH-wm) div 2;
2946 glScissor(x0+wl, gScreenHeight-my-rectH, wdt, hm);
2947 f := x0+wl;
2948 while (wdt > 0) do
2949 begin
2950 e_DrawSize(idm, f, y0, 0, true, false, wm, hm);
2951 f += wm;
2952 wdt -= wm;
2953 end;
2954 end;
2956 glScissor(0, 0, gScreenWidth, gScreenHeight);
2957 end
2958 else
2959 begin
2960 rectW := gScreenWidth-64;
2961 rectH := 16;
2963 x0 := (gScreenWidth-rectW) div 2;
2964 y0 := gScreenHeight-rectH-64;
2965 if (y0 < 2) then y0 := 2;
2967 glDisable(GL_BLEND);
2968 glDisable(GL_TEXTURE_2D);
2970 //glClearColor(0, 0, 0, 0);
2971 //glClear(GL_COLOR_BUFFER_BIT);
2973 glColor4ub(127, 127, 127, 255);
2974 drawRect(x0-2, y0-2, rectW+4, rectH+4);
2976 glColor4ub(0, 0, 0, 255);
2977 drawRect(x0-1, y0-1, rectW+2, rectH+2);
2979 glColor4ub(127, 127, 127, 255);
2980 wdt := rectW*cur div total;
2981 if (wdt > rectW) then wdt := rectW;
2982 drawRect(x0, y0, wdt, rectH);
2983 end;
2984 end;
2986 var
2987 ww, hh: Word;
2988 xx, yy, i: Integer;
2989 s: String;
2990 begin
2991 if (Length(LoadingStat.Msgs) = 0) then exit;
2993 e_CharFont_GetSize(gMenuFont, _lc[I_MENU_LOADING], ww, hh);
2994 yy := (gScreenHeight div 3);
2995 e_CharFont_Print(gMenuFont, (gScreenWidth div 2)-(ww div 2), yy-2*hh, _lc[I_MENU_LOADING]);
2996 xx := (gScreenWidth div 3);
2998 with LoadingStat do
2999 begin
3000 for i := 0 to NextMsg-1 do
3001 begin
3002 if (i = (NextMsg-1)) and (MaxValue > 0) then
3003 s := Format('%s: %d/%d', [Msgs[i], CurValue, MaxValue])
3004 else
3005 s := Msgs[i];
3007 e_CharFont_PrintEx(gMenuSmallFont, xx, yy, s, _RGB(255, 0, 0));
3008 yy := yy + LOADING_INTERLINE;
3009 PBarWasHere := drawPBar(CurValue, MaxValue, PBarWasHere);
3010 end;
3011 end;
3012 end;
3014 procedure DrawMenuBackground(tex: AnsiString);
3015 var
3016 w, h: Word;
3017 ID: DWord;
3019 begin
3020 if g_Texture_Get(tex, ID) then
3021 begin
3022 e_Clear(GL_COLOR_BUFFER_BIT, 0, 0, 0);
3023 e_GetTextureSize(ID, @w, @h);
3024 if w = h then
3025 w := round(w * 1.333 * (gScreenHeight / h))
3026 else
3027 w := trunc(w * (gScreenHeight / h));
3028 e_DrawSize(ID, (gScreenWidth - w) div 2, 0, 0, False, False, w, gScreenHeight);
3029 end
3030 else e_Clear(GL_COLOR_BUFFER_BIT, 0, 0, 0);
3031 end;
3033 procedure DrawMinimap(p: TPlayer; RenderRect: e_graphics.TRect);
3034 var
3035 a, aX, aY, aX2, aY2, Scale, ScaleSz: Integer;
3037 function monDraw (mon: TMonster): Boolean;
3038 begin
3039 result := false; // don't stop
3040 with mon do
3041 begin
3042 if alive then
3043 begin
3044 // Ëåâûé âåðõíèé óãîë
3045 aX := Obj.X div ScaleSz + 1;
3046 aY := Obj.Y div ScaleSz + 1;
3047 // Ðàçìåðû
3048 aX2 := max(Obj.Rect.Width div ScaleSz, 1);
3049 aY2 := max(Obj.Rect.Height div ScaleSz, 1);
3050 // Ïðàâûé íèæíèé óãîë
3051 aX2 := aX + aX2 - 1;
3052 aY2 := aY + aY2 - 1;
3053 e_DrawFillQuad(aX, aY, aX2, aY2, 255, 255, 0, 0);
3054 end;
3055 end;
3056 end;
3058 begin
3059 if (gMapInfo.Width > RenderRect.Right - RenderRect.Left) or
3060 (gMapInfo.Height > RenderRect.Bottom - RenderRect.Top) then
3061 begin
3062 Scale := 1;
3063 // Ñêîëüêî ïèêñåëîâ êàðòû â 1 ïèêñåëå ìèíè-êàðòû:
3064 ScaleSz := 16 div Scale;
3065 // Ðàçìåðû ìèíè-êàðòû:
3066 aX := max(gMapInfo.Width div ScaleSz, 1);
3067 aY := max(gMapInfo.Height div ScaleSz, 1);
3068 // Ðàìêà êàðòû:
3069 e_DrawFillQuad(0, 0, aX-1, aY-1, 0, 0, 0, 0);
3071 if gWalls <> nil then
3072 begin
3073 // Ðèñóåì ñòåíû:
3074 for a := 0 to High(gWalls) do
3075 with gWalls[a] do
3076 if PanelType <> 0 then
3077 begin
3078 // Ëåâûé âåðõíèé óãîë:
3079 aX := X div ScaleSz;
3080 aY := Y div ScaleSz;
3081 // Ðàçìåðû:
3082 aX2 := max(Width div ScaleSz, 1);
3083 aY2 := max(Height div ScaleSz, 1);
3084 // Ïðàâûé íèæíèé óãîë:
3085 aX2 := aX + aX2 - 1;
3086 aY2 := aY + aY2 - 1;
3088 case PanelType of
3089 PANEL_WALL: e_DrawFillQuad(aX, aY, aX2, aY2, 208, 208, 208, 0);
3090 PANEL_OPENDOOR, PANEL_CLOSEDOOR:
3091 if Enabled then e_DrawFillQuad(aX, aY, aX2, aY2, 160, 160, 160, 0);
3092 end;
3093 end;
3094 end;
3095 if gSteps <> nil then
3096 begin
3097 // Ðèñóåì ñòóïåíè:
3098 for a := 0 to High(gSteps) do
3099 with gSteps[a] do
3100 if PanelType <> 0 then
3101 begin
3102 // Ëåâûé âåðõíèé óãîë:
3103 aX := X div ScaleSz;
3104 aY := Y div ScaleSz;
3105 // Ðàçìåðû:
3106 aX2 := max(Width div ScaleSz, 1);
3107 aY2 := max(Height div ScaleSz, 1);
3108 // Ïðàâûé íèæíèé óãîë:
3109 aX2 := aX + aX2 - 1;
3110 aY2 := aY + aY2 - 1;
3112 e_DrawFillQuad(aX, aY, aX2, aY2, 128, 128, 128, 0);
3113 end;
3114 end;
3115 if gLifts <> nil then
3116 begin
3117 // Ðèñóåì ëèôòû:
3118 for a := 0 to High(gLifts) do
3119 with gLifts[a] do
3120 if PanelType <> 0 then
3121 begin
3122 // Ëåâûé âåðõíèé óãîë:
3123 aX := X div ScaleSz;
3124 aY := Y div ScaleSz;
3125 // Ðàçìåðû:
3126 aX2 := max(Width div ScaleSz, 1);
3127 aY2 := max(Height div ScaleSz, 1);
3128 // Ïðàâûé íèæíèé óãîë:
3129 aX2 := aX + aX2 - 1;
3130 aY2 := aY + aY2 - 1;
3132 case LiftType of
3133 LIFTTYPE_UP: e_DrawFillQuad(aX, aY, aX2, aY2, 116, 72, 36, 0);
3134 LIFTTYPE_DOWN: e_DrawFillQuad(aX, aY, aX2, aY2, 116, 124, 96, 0);
3135 LIFTTYPE_LEFT: e_DrawFillQuad(aX, aY, aX2, aY2, 200, 80, 4, 0);
3136 LIFTTYPE_RIGHT: e_DrawFillQuad(aX, aY, aX2, aY2, 252, 140, 56, 0);
3137 end;
3138 end;
3139 end;
3140 if gWater <> nil then
3141 begin
3142 // Ðèñóåì âîäó:
3143 for a := 0 to High(gWater) do
3144 with gWater[a] do
3145 if PanelType <> 0 then
3146 begin
3147 // Ëåâûé âåðõíèé óãîë:
3148 aX := X div ScaleSz;
3149 aY := Y div ScaleSz;
3150 // Ðàçìåðû:
3151 aX2 := max(Width div ScaleSz, 1);
3152 aY2 := max(Height div ScaleSz, 1);
3153 // Ïðàâûé íèæíèé óãîë:
3154 aX2 := aX + aX2 - 1;
3155 aY2 := aY + aY2 - 1;
3157 e_DrawFillQuad(aX, aY, aX2, aY2, 0, 0, 192, 0);
3158 end;
3159 end;
3160 if gAcid1 <> nil then
3161 begin
3162 // Ðèñóåì êèñëîòó 1:
3163 for a := 0 to High(gAcid1) do
3164 with gAcid1[a] do
3165 if PanelType <> 0 then
3166 begin
3167 // Ëåâûé âåðõíèé óãîë:
3168 aX := X div ScaleSz;
3169 aY := Y div ScaleSz;
3170 // Ðàçìåðû:
3171 aX2 := max(Width div ScaleSz, 1);
3172 aY2 := max(Height div ScaleSz, 1);
3173 // Ïðàâûé íèæíèé óãîë:
3174 aX2 := aX + aX2 - 1;
3175 aY2 := aY + aY2 - 1;
3177 e_DrawFillQuad(aX, aY, aX2, aY2, 0, 176, 0, 0);
3178 end;
3179 end;
3180 if gAcid2 <> nil then
3181 begin
3182 // Ðèñóåì êèñëîòó 2:
3183 for a := 0 to High(gAcid2) do
3184 with gAcid2[a] do
3185 if PanelType <> 0 then
3186 begin
3187 // Ëåâûé âåðõíèé óãîë:
3188 aX := X div ScaleSz;
3189 aY := Y div ScaleSz;
3190 // Ðàçìåðû:
3191 aX2 := max(Width div ScaleSz, 1);
3192 aY2 := max(Height div ScaleSz, 1);
3193 // Ïðàâûé íèæíèé óãîë:
3194 aX2 := aX + aX2 - 1;
3195 aY2 := aY + aY2 - 1;
3197 e_DrawFillQuad(aX, aY, aX2, aY2, 176, 0, 0, 0);
3198 end;
3199 end;
3200 if gPlayers <> nil then
3201 begin
3202 // Ðèñóåì èãðîêîâ:
3203 for a := 0 to High(gPlayers) do
3204 if gPlayers[a] <> nil then with gPlayers[a] do
3205 if alive then begin
3206 // Ëåâûé âåðõíèé óãîë:
3207 aX := Obj.X div ScaleSz + 1;
3208 aY := Obj.Y div ScaleSz + 1;
3209 // Ðàçìåðû:
3210 aX2 := max(Obj.Rect.Width div ScaleSz, 1);
3211 aY2 := max(Obj.Rect.Height div ScaleSz, 1);
3212 // Ïðàâûé íèæíèé óãîë:
3213 aX2 := aX + aX2 - 1;
3214 aY2 := aY + aY2 - 1;
3216 if gPlayers[a] = p then
3217 e_DrawFillQuad(aX, aY, aX2, aY2, 0, 255, 0, 0)
3218 else
3219 case Team of
3220 TEAM_RED: e_DrawFillQuad(aX, aY, aX2, aY2, 255, 0, 0, 0);
3221 TEAM_BLUE: e_DrawFillQuad(aX, aY, aX2, aY2, 0, 0, 255, 0);
3222 else e_DrawFillQuad(aX, aY, aX2, aY2, 255, 128, 0, 0);
3223 end;
3224 end;
3225 end;
3226 // Ðèñóåì ìîíñòðîâ
3227 g_Mons_ForEach(monDraw);
3228 end;
3229 end;
3232 procedure renderAmbientQuad (hasAmbient: Boolean; constref ambColor: TDFColor);
3233 begin
3234 if not hasAmbient then exit;
3235 e_AmbientQuad(sX, sY, sWidth, sHeight, ambColor.r, ambColor.g, ambColor.b, ambColor.a);
3236 end;
3239 // setup sX, sY, sWidth, sHeight, and transformation matrix before calling this!
3240 //FIXME: broken for splitscreen mode
3241 procedure renderDynLightsInternal ();
3242 var
3243 //hasAmbient: Boolean;
3244 //ambColor: TDFColor;
3245 lln: Integer;
3246 lx, ly, lrad: Integer;
3247 scxywh: array[0..3] of GLint;
3248 wassc: Boolean;
3249 begin
3250 if e_NoGraphics then exit;
3252 //TODO: lights should be in separate grid, i think
3253 // but on the other side: grid may be slower for dynlights, as their lifetime is short
3254 if (not gwin_k8_enable_light_experiments) or (not gwin_has_stencil) or (g_dynLightCount < 1) then exit;
3256 // rendering mode
3257 //ambColor := gCurrentMap['light_ambient'].rgba;
3258 //hasAmbient := (not ambColor.isOpaque) or (not ambColor.isBlack);
3260 { // this will multiply incoming color to alpha from framebuffer
3261 glEnable(GL_BLEND);
3262 glBlendFunc(GL_DST_ALPHA, GL_ONE);
3265 (*
3266 * light rendering: (INVALID!)
3267 * glStencilFunc(GL_EQUAL, 0, $ff);
3268 * for each light:
3269 * glClear(GL_STENCIL_BUFFER_BIT);
3270 * glStencilOp(GL_KEEP, GL_KEEP, GL_INCR);
3271 * draw shadow volume into stencil buffer
3272 * glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); // modify color buffer
3273 * glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); // don't modify stencil buffer
3274 * turn off blending
3275 * draw color-less quad with light alpha (WARNING! don't touch color!)
3276 * glEnable(GL_BLEND);
3277 * glBlendFunc(GL_DST_ALPHA, GL_ONE);
3278 * draw all geometry up to and including walls (with alpha-testing, probably) -- this does lighting
3279 *)
3280 wassc := (glIsEnabled(GL_SCISSOR_TEST) <> 0);
3281 if wassc then glGetIntegerv(GL_SCISSOR_BOX, @scxywh[0]) else glGetIntegerv(GL_VIEWPORT, @scxywh[0]);
3283 // setup OpenGL parameters
3284 glStencilMask($FFFFFFFF);
3285 glStencilFunc(GL_ALWAYS, 0, $FFFFFFFF);
3286 glEnable(GL_STENCIL_TEST);
3287 glEnable(GL_SCISSOR_TEST);
3288 glClear(GL_STENCIL_BUFFER_BIT);
3289 glStencilFunc(GL_EQUAL, 0, $ff);
3291 for lln := 0 to g_dynLightCount-1 do
3292 begin
3293 lx := g_dynLights[lln].x;
3294 ly := g_dynLights[lln].y;
3295 lrad := g_dynLights[lln].radius;
3296 if (lrad < 3) then continue;
3298 if (lx-sX+lrad < 0) then continue;
3299 if (ly-sY+lrad < 0) then continue;
3300 if (lx-sX-lrad >= gPlayerScreenSize.X) then continue;
3301 if (ly-sY-lrad >= gPlayerScreenSize.Y) then continue;
3303 // set scissor to optimize drawing
3304 if (g_dbg_scale = 1.0) then
3305 begin
3306 glScissor((lx-sX)-lrad+2, gPlayerScreenSize.Y-(ly-sY)-lrad-1+2, lrad*2-4, lrad*2-4);
3307 end
3308 else
3309 begin
3310 glScissor(0, 0, gWinSizeX, gWinSizeY);
3311 end;
3312 // no need to clear stencil buffer, light blitting will do it for us... but only for normal scale
3313 if (g_dbg_scale <> 1.0) then glClear(GL_STENCIL_BUFFER_BIT);
3314 glStencilOp(GL_KEEP, GL_KEEP, GL_INCR);
3315 // draw extruded panels
3316 glDisable(GL_TEXTURE_2D);
3317 glDisable(GL_BLEND);
3318 glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); // no need to modify color buffer
3319 if (lrad > 4) then g_Map_DrawPanelShadowVolumes(lx, ly, lrad);
3320 // render light texture
3321 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); // modify color buffer
3322 glStencilOp(GL_ZERO, GL_ZERO, GL_ZERO); // draw light, and clear stencil buffer
3323 // blend it
3324 glEnable(GL_BLEND);
3325 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
3326 glEnable(GL_TEXTURE_2D);
3327 // color and opacity
3328 glColor4f(g_dynLights[lln].r, g_dynLights[lln].g, g_dynLights[lln].b, g_dynLights[lln].a);
3329 glBindTexture(GL_TEXTURE_2D, g_Texture_Light());
3330 glBegin(GL_QUADS);
3331 glTexCoord2f(0.0, 0.0); glVertex2i(lx-lrad, ly-lrad); // top-left
3332 glTexCoord2f(1.0, 0.0); glVertex2i(lx+lrad, ly-lrad); // top-right
3333 glTexCoord2f(1.0, 1.0); glVertex2i(lx+lrad, ly+lrad); // bottom-right
3334 glTexCoord2f(0.0, 1.0); glVertex2i(lx-lrad, ly+lrad); // bottom-left
3335 glEnd();
3336 end;
3338 // done
3339 glDisable(GL_STENCIL_TEST);
3340 glDisable(GL_BLEND);
3341 glDisable(GL_SCISSOR_TEST);
3342 //glScissor(0, 0, sWidth, sHeight);
3344 glScissor(scxywh[0], scxywh[1], scxywh[2], scxywh[3]);
3345 if wassc then glEnable(GL_SCISSOR_TEST) else glDisable(GL_SCISSOR_TEST);
3346 end;
3349 function fixViewportForScale (): Boolean;
3350 var
3351 nx0, ny0, nw, nh: Integer;
3352 begin
3353 result := false;
3354 if (g_dbg_scale <> 1.0) then
3355 begin
3356 result := true;
3357 nx0 := round(sX-(gPlayerScreenSize.X-(sWidth*g_dbg_scale))/2/g_dbg_scale);
3358 ny0 := round(sY-(gPlayerScreenSize.Y-(sHeight*g_dbg_scale))/2/g_dbg_scale);
3359 nw := round(sWidth/g_dbg_scale);
3360 nh := round(sHeight/g_dbg_scale);
3361 sX := nx0;
3362 sY := ny0;
3363 sWidth := nw;
3364 sHeight := nh;
3365 end;
3366 end;
3369 // setup sX, sY, sWidth, sHeight, and transformation matrix before calling this!
3370 // WARNING! this WILL CALL `glTranslatef()`, but won't restore matrices!
3371 procedure renderMapInternal (backXOfs, backYOfs: Integer; setTransMatrix: Boolean);
3372 type
3373 TDrawCB = procedure ();
3375 var
3376 hasAmbient: Boolean;
3377 ambColor: TDFColor;
3378 doAmbient: Boolean = false;
3380 procedure drawPanelType (profname: AnsiString; panType: DWord; doDraw: Boolean);
3381 var
3382 tagmask: Integer;
3383 pan: TPanel;
3384 begin
3385 if (profileFrameDraw <> nil) then profileFrameDraw.sectionBegin(profname);
3386 if gdbg_map_use_accel_render then
3387 begin
3388 tagmask := panelTypeToTag(panType);
3389 while (gDrawPanelList.count > 0) do
3390 begin
3391 pan := TPanel(gDrawPanelList.front());
3392 if ((pan.tag and tagmask) = 0) then break;
3393 if doDraw then pan.Draw(doAmbient, ambColor);
3394 gDrawPanelList.popFront();
3395 end;
3396 end
3397 else
3398 begin
3399 if doDraw then g_Map_DrawPanels(panType, hasAmbient, ambColor);
3400 end;
3401 if (profileFrameDraw <> nil) then profileFrameDraw.sectionEnd();
3402 end;
3404 procedure drawOther (profname: AnsiString; cb: TDrawCB);
3405 begin
3406 if (profileFrameDraw <> nil) then profileFrameDraw.sectionBegin(profname);
3407 if assigned(cb) then cb();
3408 if (profileFrameDraw <> nil) then profileFrameDraw.sectionEnd();
3409 end;
3411 begin
3412 if (profileFrameDraw <> nil) then profileFrameDraw.sectionBegin('total');
3414 // our accelerated renderer will collect all panels to gDrawPanelList
3415 // we can use panel tag to render level parts (see GridTagXXX in g_map.pas)
3416 if (profileFrameDraw <> nil) then profileFrameDraw.sectionBegin('collect');
3417 if gdbg_map_use_accel_render then
3418 begin
3419 g_Map_CollectDrawPanels(sX, sY, sWidth, sHeight);
3420 end;
3421 if (profileFrameDraw <> nil) then profileFrameDraw.sectionEnd();
3423 if (profileFrameDraw <> nil) then profileFrameDraw.sectionBegin('skyback');
3424 g_Map_DrawBack(backXOfs, backYOfs);
3425 if (profileFrameDraw <> nil) then profileFrameDraw.sectionEnd();
3427 if setTransMatrix then
3428 begin
3429 //if (g_dbg_scale <> 1.0) then glTranslatef(0.0, -0.375/2, 0);
3430 glScalef(g_dbg_scale, g_dbg_scale, 1.0);
3431 glTranslatef(-sX, -sY, 0);
3432 end;
3434 // rendering mode
3435 ambColor := gCurrentMap['light_ambient'].rgba;
3436 hasAmbient := (not ambColor.isOpaque) or (not ambColor.isBlack);
3439 if hasAmbient then
3440 begin
3441 //writeln('color: (', ambColor.r, ',', ambColor.g, ',', ambColor.b, ',', ambColor.a, ')');
3442 glColor4ub(ambColor.r, ambColor.g, ambColor.b, ambColor.a);
3443 glClear(GL_COLOR_BUFFER_BIT);
3444 end;
3446 //writeln('color: (', ambColor.r, ',', ambColor.g, ',', ambColor.b, ',', ambColor.a, ')');
3449 drawPanelType('*back', PANEL_BACK, g_rlayer_back);
3450 drawPanelType('*step', PANEL_STEP, g_rlayer_step);
3451 drawOther('items', @g_Items_Draw);
3452 drawOther('weapons', @g_Weapon_Draw);
3453 drawOther('shells', @g_Player_DrawShells);
3454 drawOther('drawall', @g_Player_DrawAll);
3455 drawOther('corpses', @g_Player_DrawCorpses);
3456 drawPanelType('*wall', PANEL_WALL, g_rlayer_wall);
3457 drawOther('monsters', @g_Monsters_Draw);
3458 drawOther('itemdrop', @g_Items_DrawDrop);
3459 drawPanelType('*door', PANEL_CLOSEDOOR, g_rlayer_door);
3460 drawOther('gfx', @g_GFX_Draw);
3461 drawOther('flags', @g_Map_DrawFlags);
3462 drawPanelType('*acid1', PANEL_ACID1, g_rlayer_acid1);
3463 drawPanelType('*acid2', PANEL_ACID2, g_rlayer_acid2);
3464 drawPanelType('*water', PANEL_WATER, g_rlayer_water);
3465 drawOther('dynlights', @renderDynLightsInternal);
3467 if hasAmbient {and ((not g_playerLight) or (not gwin_has_stencil) or (g_dynLightCount < 1))} then
3468 begin
3469 renderAmbientQuad(hasAmbient, ambColor);
3470 end;
3472 doAmbient := true;
3473 drawPanelType('*fore', PANEL_FORE, g_rlayer_fore);
3476 if g_debug_HealthBar then
3477 begin
3478 g_Monsters_DrawHealth();
3479 g_Player_DrawHealth();
3480 end;
3482 if (profileFrameDraw <> nil) then profileFrameDraw.mainEnd(); // map rendering
3483 end;
3486 procedure DrawMapView(x, y, w, h: Integer);
3488 var
3489 bx, by: Integer;
3490 begin
3491 glPushMatrix();
3493 bx := Round(x/(gMapInfo.Width - w)*(gBackSize.X - w));
3494 by := Round(y/(gMapInfo.Height - h)*(gBackSize.Y - h));
3496 sX := x;
3497 sY := y;
3498 sWidth := w;
3499 sHeight := h;
3501 fixViewportForScale();
3502 renderMapInternal(-bx, -by, true);
3504 glPopMatrix();
3505 end;
3508 procedure DrawPlayer(p: TPlayer);
3509 var
3510 px, py, a, b, c, d: Integer;
3511 //R: TRect;
3512 begin
3513 if (p = nil) or (p.FDummy) then
3514 begin
3515 glPushMatrix();
3516 g_Map_DrawBack(0, 0);
3517 glPopMatrix();
3518 Exit;
3519 end;
3521 if (profileFrameDraw = nil) then profileFrameDraw := TProfiler.Create('RENDER', g_profile_history_size);
3522 if (profileFrameDraw <> nil) then profileFrameDraw.mainBegin(g_profile_frame_draw);
3524 gPlayerDrawn := p;
3526 glPushMatrix();
3528 px := p.GameX + PLAYER_RECT_CX;
3529 py := p.GameY + PLAYER_RECT_CY+p.Obj.slopeUpLeft;
3531 if (g_dbg_scale = 1.0) and (not g_dbg_ignore_bounds) then
3532 begin
3533 if (px > (gPlayerScreenSize.X div 2)) then a := -px+(gPlayerScreenSize.X div 2) else a := 0;
3534 if (py > (gPlayerScreenSize.Y div 2)) then b := -py+(gPlayerScreenSize.Y div 2) else b := 0;
3536 if (px > gMapInfo.Width-(gPlayerScreenSize.X div 2)) then a := -gMapInfo.Width+gPlayerScreenSize.X;
3537 if (py > gMapInfo.Height-(gPlayerScreenSize.Y div 2)) then b := -gMapInfo.Height+gPlayerScreenSize.Y;
3539 if (gMapInfo.Width = gPlayerScreenSize.X) then a := 0
3540 else if (gMapInfo.Width < gPlayerScreenSize.X) then
3541 begin
3542 // hcenter
3543 a := (gPlayerScreenSize.X-gMapInfo.Width) div 2;
3544 end;
3546 if (gMapInfo.Height = gPlayerScreenSize.Y) then b := 0
3547 else if (gMapInfo.Height < gPlayerScreenSize.Y) then
3548 begin
3549 // vcenter
3550 b := (gPlayerScreenSize.Y-gMapInfo.Height) div 2;
3551 end;
3552 end
3553 else
3554 begin
3555 // scaled, ignore level bounds
3556 a := -px+(gPlayerScreenSize.X div 2);
3557 b := -py+(gPlayerScreenSize.Y div 2);
3558 end;
3560 if p.IncCam <> 0 then
3561 begin
3562 if py > gMapInfo.Height-(gPlayerScreenSize.Y div 2) then
3563 begin
3564 if p.IncCam > 120-(py-(gMapInfo.Height-(gPlayerScreenSize.Y div 2))) then
3565 begin
3566 p.IncCam := 120-(py-(gMapInfo.Height-(gPlayerScreenSize.Y div 2)));
3567 end;
3568 end;
3570 if py < gPlayerScreenSize.Y div 2 then
3571 begin
3572 if p.IncCam < -120+((gPlayerScreenSize.Y div 2)-py) then
3573 begin
3574 p.IncCam := -120+((gPlayerScreenSize.Y div 2)-py);
3575 end;
3576 end;
3578 if p.IncCam < 0 then
3579 begin
3580 while (py+(gPlayerScreenSize.Y div 2)-p.IncCam > gMapInfo.Height) and (p.IncCam < 0) do p.IncCam := p.IncCam+1; //Inc(p.IncCam);
3581 end;
3583 if p.IncCam > 0 then
3584 begin
3585 while (py-(gPlayerScreenSize.Y div 2)-p.IncCam < 0) and (p.IncCam > 0) do p.IncCam := p.IncCam-1; //Dec(p.IncCam);
3586 end;
3587 end;
3589 if (px < gPlayerScreenSize.X div 2) or (gMapInfo.Width-gPlayerScreenSize.X <= 256) then c := 0
3590 else if (px > gMapInfo.Width-(gPlayerScreenSize.X div 2)) then c := gBackSize.X-gPlayerScreenSize.X
3591 else c := round((px-(gPlayerScreenSize.X div 2))/(gMapInfo.Width-gPlayerScreenSize.X)*(gBackSize.X-gPlayerScreenSize.X));
3593 if (py-p.IncCam <= gPlayerScreenSize.Y div 2) or (gMapInfo.Height-gPlayerScreenSize.Y <= 256) then d := 0
3594 else if (py-p.IncCam >= gMapInfo.Height-(gPlayerScreenSize.Y div 2)) then d := gBackSize.Y-gPlayerScreenSize.Y
3595 else d := round((py-p.IncCam-(gPlayerScreenSize.Y div 2))/(gMapInfo.Height-gPlayerScreenSize.Y)*(gBackSize.Y-gPlayerScreenSize.Y));
3597 sX := -a;
3598 sY := -(b+p.IncCam);
3599 sWidth := gPlayerScreenSize.X;
3600 sHeight := gPlayerScreenSize.Y;
3602 //glTranslatef(a, b+p.IncCam, 0);
3604 //if (p = gPlayer1) and (g_dbg_scale >= 1.0) then g_Holmes_plrViewSize(sWidth, sHeight);
3606 //conwritefln('OLD: (%s,%s)-(%s,%s)', [sX, sY, sWidth, sHeight]);
3607 fixViewportForScale();
3608 //conwritefln(' (%s,%s)-(%s,%s)', [sX, sY, sWidth, sHeight]);
3610 if (g_dbg_scale <> 1.0) and (not g_dbg_ignore_bounds) then
3611 begin
3612 if (sX+sWidth > gMapInfo.Width) then sX := gMapInfo.Width-sWidth;
3613 if (sY+sHeight > gMapInfo.Height) then sY := gMapInfo.Height-sHeight;
3614 if (sX < 0) then sX := 0;
3615 if (sY < 0) then sY := 0;
3617 if (gBackSize.X <= gPlayerScreenSize.X) or (gMapInfo.Width <= sWidth) then c := 0 else c := trunc((gBackSize.X-gPlayerScreenSize.X)*sX/(gMapInfo.Width-sWidth));
3618 if (gBackSize.Y <= gPlayerScreenSize.Y) or (gMapInfo.Height <= sHeight) then d := 0 else d := trunc((gBackSize.Y-gPlayerScreenSize.Y)*sY/(gMapInfo.Height-sHeight));
3619 end;
3621 //r_smallmap_h: 0: left; 1: center; 2: right
3622 //r_smallmap_v: 0: top; 1: center; 2: bottom
3623 // horiz small map?
3624 if (gMapInfo.Width = sWidth) then
3625 begin
3626 sX := 0;
3627 end
3628 else if (gMapInfo.Width < sWidth) then
3629 begin
3630 case r_smallmap_h of
3631 1: sX := -((sWidth-gMapInfo.Width) div 2); // center
3632 2: sX := -(sWidth-gMapInfo.Width); // right
3633 else sX := 0; // left
3634 end;
3635 end;
3636 // vert small map?
3637 if (gMapInfo.Height = sHeight) then
3638 begin
3639 sY := 0;
3640 end
3641 else if (gMapInfo.Height < sHeight) then
3642 begin
3643 case r_smallmap_v of
3644 1: sY := -((sHeight-gMapInfo.Height) div 2); // center
3645 2: sY := -(sHeight-gMapInfo.Height); // bottom
3646 else sY := 0; // top
3647 end;
3648 end;
3650 p.viewPortX := sX;
3651 p.viewPortY := sY;
3652 p.viewPortW := sWidth;
3653 p.viewPortH := sHeight;
3655 {$IFDEF ENABLE_HOLMES}
3656 if (p = gPlayer1) then
3657 begin
3658 g_Holmes_plrViewPos(sX, sY);
3659 g_Holmes_plrViewSize(sWidth, sHeight);
3660 end;
3661 {$ENDIF}
3663 renderMapInternal(-c, -d, true);
3665 if (gGameSettings.GameMode <> GM_SINGLE) and gPlayerIndicator then
3666 p.DrawIndicator();
3667 if p.FSpectator then
3668 e_TextureFontPrintEx(p.GameX + PLAYER_RECT_CX - 4,
3669 p.GameY + PLAYER_RECT_CY - 4,
3670 'X', gStdFont, 255, 255, 255, 1, True);
3672 for a := 0 to High(gCollideMap) do
3673 for b := 0 to High(gCollideMap[a]) do
3674 begin
3675 d := 0;
3676 if ByteBool(gCollideMap[a, b] and MARK_WALL) then
3677 d := d + 1;
3678 if ByteBool(gCollideMap[a, b] and MARK_DOOR) then
3679 d := d + 2;
3681 case d of
3682 1: e_DrawPoint(1, b, a, 200, 200, 200);
3683 2: e_DrawPoint(1, b, a, 64, 64, 255);
3684 3: e_DrawPoint(1, b, a, 255, 0, 255);
3685 end;
3686 end;
3689 glPopMatrix();
3691 p.DrawPain();
3692 p.DrawPickup();
3693 p.DrawRulez();
3694 if gShowMap then DrawMinimap(p, _TRect(0, 0, 128, 128));
3695 if g_Debug_Player then
3696 g_Player_DrawDebug(p);
3697 p.DrawGUI();
3698 end;
3700 procedure drawProfilers ();
3701 var
3702 px: Integer = -1;
3703 py: Integer = -1;
3704 begin
3705 if g_profile_frame_draw and (profileFrameDraw <> nil) then px := px-drawProfiles(px, py, profileFrameDraw);
3706 if g_profile_collision and (profMapCollision <> nil) then begin px := px-drawProfiles(px, py, profMapCollision); py -= calcProfilesHeight(profMonsLOS); end;
3707 if g_profile_los and (profMonsLOS <> nil) then begin px := px-drawProfiles(px, py, profMonsLOS); py -= calcProfilesHeight(profMonsLOS); end;
3708 end;
3710 procedure g_Game_Draw();
3711 var
3712 ID: DWORD;
3713 w, h: Word;
3714 ww, hh: Byte;
3715 Time: Int64;
3716 back: string;
3717 plView1, plView2: TPlayer;
3718 Split: Boolean;
3719 begin
3720 if gExit = EXIT_QUIT then Exit;
3722 Time := GetTimer() {div 1000};
3723 FPSCounter := FPSCounter+1;
3724 if Time - FPSTime >= 1000 then
3725 begin
3726 FPS := FPSCounter;
3727 FPSCounter := 0;
3728 FPSTime := Time;
3729 end;
3731 if gGameOn or (gState = STATE_FOLD) then
3732 begin
3733 if (gPlayer1 <> nil) and (gPlayer2 <> nil) then
3734 begin
3735 gSpectMode := SPECT_NONE;
3736 if not gRevertPlayers then
3737 begin
3738 plView1 := gPlayer1;
3739 plView2 := gPlayer2;
3740 end
3741 else
3742 begin
3743 plView1 := gPlayer2;
3744 plView2 := gPlayer1;
3745 end;
3746 end
3747 else
3748 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
3749 begin
3750 gSpectMode := SPECT_NONE;
3751 if gPlayer2 = nil then
3752 plView1 := gPlayer1
3753 else
3754 plView1 := gPlayer2;
3755 plView2 := nil;
3756 end
3757 else
3758 begin
3759 plView1 := nil;
3760 plView2 := nil;
3761 end;
3763 if (plView1 = nil) and (plView2 = nil) and (gSpectMode = SPECT_NONE) then
3764 gSpectMode := SPECT_STATS;
3766 if gSpectMode = SPECT_PLAYERS then
3767 if gPlayers <> nil then
3768 begin
3769 plView1 := GetActivePlayer_ByID(gSpectPID1);
3770 if plView1 = nil then
3771 begin
3772 gSpectPID1 := GetActivePlayerID_Next();
3773 plView1 := GetActivePlayer_ByID(gSpectPID1);
3774 end;
3775 if gSpectViewTwo then
3776 begin
3777 plView2 := GetActivePlayer_ByID(gSpectPID2);
3778 if plView2 = nil then
3779 begin
3780 gSpectPID2 := GetActivePlayerID_Next();
3781 plView2 := GetActivePlayer_ByID(gSpectPID2);
3782 end;
3783 end;
3784 end;
3786 if gSpectMode = SPECT_MAPVIEW then
3787 begin
3788 // Ðåæèì ïðîñìîòðà êàðòû
3789 Split := False;
3790 e_SetViewPort(0, 0, gScreenWidth, gScreenHeight);
3791 DrawMapView(gSpectX, gSpectY, gScreenWidth, gScreenHeight);
3792 gHearPoint1.Active := True;
3793 gHearPoint1.Coords.X := gScreenWidth div 2 + gSpectX;
3794 gHearPoint1.Coords.Y := gScreenHeight div 2 + gSpectY;
3795 gHearPoint2.Active := False;
3796 end
3797 else
3798 begin
3799 Split := (plView1 <> nil) and (plView2 <> nil);
3801 // Òî÷êè ñëóõà èãðîêîâ
3802 if plView1 <> nil then
3803 begin
3804 gHearPoint1.Active := True;
3805 gHearPoint1.Coords.X := plView1.GameX;
3806 gHearPoint1.Coords.Y := plView1.GameY;
3807 end else
3808 gHearPoint1.Active := False;
3809 if plView2 <> nil then
3810 begin
3811 gHearPoint2.Active := True;
3812 gHearPoint2.Coords.X := plView2.GameX;
3813 gHearPoint2.Coords.Y := plView2.GameY;
3814 end else
3815 gHearPoint2.Active := False;
3817 // Ðàçìåð ýêðàíîâ èãðîêîâ:
3818 gPlayerScreenSize.X := gScreenWidth-196;
3819 if Split then
3820 begin
3821 gPlayerScreenSize.Y := gScreenHeight div 2;
3822 if gScreenHeight mod 2 = 0 then
3823 Dec(gPlayerScreenSize.Y);
3824 end
3825 else
3826 gPlayerScreenSize.Y := gScreenHeight;
3828 if Split then
3829 if gScreenHeight mod 2 = 0 then
3830 e_SetViewPort(0, gPlayerScreenSize.Y+2, gPlayerScreenSize.X+196, gPlayerScreenSize.Y)
3831 else
3832 e_SetViewPort(0, gPlayerScreenSize.Y+1, gPlayerScreenSize.X+196, gPlayerScreenSize.Y);
3834 DrawPlayer(plView1);
3835 gPlayer1ScreenCoord.X := sX;
3836 gPlayer1ScreenCoord.Y := sY;
3838 if Split then
3839 begin
3840 e_SetViewPort(0, 0, gPlayerScreenSize.X+196, gPlayerScreenSize.Y);
3842 DrawPlayer(plView2);
3843 gPlayer2ScreenCoord.X := sX;
3844 gPlayer2ScreenCoord.Y := sY;
3845 end;
3847 e_SetViewPort(0, 0, gScreenWidth, gScreenHeight);
3849 if Split then
3850 e_DrawLine(2, 0, gScreenHeight div 2, gScreenWidth, gScreenHeight div 2, 0, 0, 0);
3851 end;
3853 {$IFDEF ENABLE_HOLMES}
3854 // draw inspector
3855 if (g_holmes_enabled) then g_Holmes_Draw();
3856 {$ENDIF}
3858 if MessageText <> '' then
3859 begin
3860 w := 0;
3861 h := 0;
3862 e_CharFont_GetSizeFmt(gMenuFont, MessageText, w, h);
3863 if Split then
3864 e_CharFont_PrintFmt(gMenuFont, (gScreenWidth div 2)-(w div 2),
3865 (gScreenHeight div 2)-(h div 2), MessageText)
3866 else
3867 e_CharFont_PrintFmt(gMenuFont, (gScreenWidth div 2)-(w div 2),
3868 Round(gScreenHeight / 2.75)-(h div 2), MessageText);
3869 end;
3871 if IsDrawStat or (gSpectMode = 1) then DrawStat();
3873 if gSpectHUD and (not gChatShow) and (gSpectMode <> SPECT_NONE) and (not gSpectAuto) then
3874 begin
3875 // Draw spectator GUI
3876 ww := 0;
3877 hh := 0;
3878 e_TextureFontGetSize(gStdFont, ww, hh);
3879 case gSpectMode of
3880 SPECT_STATS:
3881 e_TextureFontPrintEx(0, gScreenHeight - (hh+2)*2, 'MODE: Stats', gStdFont, 255, 255, 255, 1);
3882 SPECT_MAPVIEW:
3883 e_TextureFontPrintEx(0, gScreenHeight - (hh+2)*2, 'MODE: Observe Map', gStdFont, 255, 255, 255, 1);
3884 SPECT_PLAYERS:
3885 e_TextureFontPrintEx(0, gScreenHeight - (hh+2)*2, 'MODE: Watch Players', gStdFont, 255, 255, 255, 1);
3886 end;
3887 e_TextureFontPrintEx(2*ww, gScreenHeight - (hh+2), '< jump >', gStdFont, 255, 255, 255, 1);
3888 if gSpectMode = SPECT_STATS then
3889 begin
3890 e_TextureFontPrintEx(16*ww, gScreenHeight - (hh+2)*2, 'Autoview', gStdFont, 255, 255, 255, 1);
3891 e_TextureFontPrintEx(16*ww, gScreenHeight - (hh+2), '< fire >', gStdFont, 255, 255, 255, 1);
3892 end;
3893 if gSpectMode = SPECT_MAPVIEW then
3894 begin
3895 e_TextureFontPrintEx(22*ww, gScreenHeight - (hh+2)*2, '[-]', gStdFont, 255, 255, 255, 1);
3896 e_TextureFontPrintEx(26*ww, gScreenHeight - (hh+2)*2, 'Step ' + IntToStr(gSpectStep), gStdFont, 255, 255, 255, 1);
3897 e_TextureFontPrintEx(34*ww, gScreenHeight - (hh+2)*2, '[+]', gStdFont, 255, 255, 255, 1);
3898 e_TextureFontPrintEx(18*ww, gScreenHeight - (hh+2), '<prev weap>', gStdFont, 255, 255, 255, 1);
3899 e_TextureFontPrintEx(30*ww, gScreenHeight - (hh+2), '<next weap>', gStdFont, 255, 255, 255, 1);
3900 end;
3901 if gSpectMode = SPECT_PLAYERS then
3902 begin
3903 e_TextureFontPrintEx(22*ww, gScreenHeight - (hh+2)*2, 'Player 1', gStdFont, 255, 255, 255, 1);
3904 e_TextureFontPrintEx(20*ww, gScreenHeight - (hh+2), '<left/right>', gStdFont, 255, 255, 255, 1);
3905 if gSpectViewTwo then
3906 begin
3907 e_TextureFontPrintEx(37*ww, gScreenHeight - (hh+2)*2, 'Player 2', gStdFont, 255, 255, 255, 1);
3908 e_TextureFontPrintEx(34*ww, gScreenHeight - (hh+2), '<prev w/next w>', gStdFont, 255, 255, 255, 1);
3909 e_TextureFontPrintEx(52*ww, gScreenHeight - (hh+2)*2, '2x View', gStdFont, 255, 255, 255, 1);
3910 e_TextureFontPrintEx(51*ww, gScreenHeight - (hh+2), '<up/down>', gStdFont, 255, 255, 255, 1);
3911 end
3912 else
3913 begin
3914 e_TextureFontPrintEx(35*ww, gScreenHeight - (hh+2)*2, '2x View', gStdFont, 255, 255, 255, 1);
3915 e_TextureFontPrintEx(34*ww, gScreenHeight - (hh+2), '<up/down>', gStdFont, 255, 255, 255, 1);
3916 end;
3917 end;
3918 end;
3919 end;
3921 if gPauseMain and gGameOn and (g_ActiveWindow = nil) then
3922 begin
3923 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
3924 e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
3926 e_CharFont_GetSize(gMenuFont, _lc[I_MENU_PAUSE], w, h);
3927 e_CharFont_Print(gMenuFont, (gScreenWidth div 2)-(w div 2),
3928 (gScreenHeight div 2)-(h div 2), _lc[I_MENU_PAUSE]);
3929 end;
3931 if not gGameOn then
3932 begin
3933 if (gState = STATE_MENU) then
3934 begin
3935 if (g_ActiveWindow = nil) or (g_ActiveWindow.BackTexture = '') then DrawMenuBackground('MENU_BACKGROUND');
3936 // F3 at menu will show game loading dialog
3937 if e_KeyPressed(IK_F3) then g_Menu_Show_LoadMenu(true);
3938 if (g_ActiveWindow <> nil) then
3939 begin
3940 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
3941 e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
3942 end
3943 else
3944 begin
3945 // F3 at titlepic will show game loading dialog
3946 if e_KeyPressed(IK_F3) then
3947 begin
3948 g_Menu_Show_LoadMenu(true);
3949 if (g_ActiveWindow <> nil) then e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
3950 end;
3951 end;
3952 end;
3954 if gState = STATE_FOLD then
3955 begin
3956 e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 0, 0, 0, EndingGameCounter);
3957 end;
3959 if gState = STATE_INTERCUSTOM then
3960 begin
3961 if gLastMap and (gGameSettings.GameMode = GM_COOP) then
3962 begin
3963 back := 'TEXTURE_endpic';
3964 if not g_Texture_Get(back, ID) then
3965 back := _lc[I_TEXTURE_ENDPIC];
3966 end
3967 else
3968 back := 'INTER';
3970 DrawMenuBackground(back);
3972 DrawCustomStat();
3974 if g_ActiveWindow <> nil then
3975 begin
3976 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
3977 e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
3978 end;
3979 end;
3981 if gState = STATE_INTERSINGLE then
3982 begin
3983 if EndingGameCounter > 0 then
3984 begin
3985 e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 0, 0, 0, EndingGameCounter);
3986 end
3987 else
3988 begin
3989 back := 'INTER';
3991 DrawMenuBackground(back);
3993 DrawSingleStat();
3995 if g_ActiveWindow <> nil then
3996 begin
3997 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
3998 e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
3999 end;
4000 end;
4001 end;
4003 if gState = STATE_ENDPIC then
4004 begin
4005 ID := DWORD(-1);
4006 if not g_Texture_Get('TEXTURE_endpic', ID) then
4007 g_Texture_Get(_lc[I_TEXTURE_ENDPIC], ID);
4009 if ID <> DWORD(-1) then
4010 e_DrawSize(ID, 0, 0, 0, False, False, gScreenWidth, gScreenHeight)
4011 else
4012 e_Clear(GL_COLOR_BUFFER_BIT, 0, 0, 0);
4014 if g_ActiveWindow <> nil then
4015 begin
4016 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4017 e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
4018 end;
4019 end;
4021 if gState = STATE_SLIST then
4022 begin
4023 // if g_Texture_Get('MENU_BACKGROUND', ID) then
4024 // begin
4025 // e_DrawSize(ID, 0, 0, 0, False, False, gScreenWidth, gScreenHeight);
4026 // //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4027 // end;
4028 DrawMenuBackground('MENU_BACKGROUND');
4029 e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
4030 g_Serverlist_Draw(slCurrent, slTable);
4031 end;
4032 end;
4034 if g_ActiveWindow <> nil then
4035 begin
4036 if gGameOn then
4037 begin
4038 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4039 e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
4040 end;
4041 g_ActiveWindow.Draw();
4042 end;
4044 g_Console_Draw();
4046 if g_debug_Sounds and gGameOn then
4047 begin
4048 for w := 0 to High(e_SoundsArray) do
4049 for h := 0 to e_SoundsArray[w].nRefs do
4050 e_DrawPoint(1, w+100, h+100, 255, 0, 0);
4051 end;
4053 if gShowFPS then
4054 begin
4055 e_TextureFontPrint(0, 0, Format('FPS: %d', [FPS]), gStdFont);
4056 e_TextureFontPrint(0, 16, Format('UPS: %d', [UPS]), gStdFont);
4057 end;
4059 if gGameOn and gShowTime then
4060 drawTime(gScreenWidth-72, gScreenHeight-16);
4062 if gGameOn then drawProfilers();
4064 {$IFDEF ENABLE_HOLMES}
4065 g_Holmes_DrawUI();
4066 {$ENDIF}
4068 g_Touch_Draw;
4069 end;
4071 procedure g_Game_Quit();
4072 begin
4073 g_Game_StopAllSounds(True);
4074 gMusic.Free();
4075 g_Game_SaveOptions();
4076 g_Game_FreeData();
4077 g_PlayerModel_FreeData();
4078 g_Texture_DeleteAll();
4079 g_Frames_DeleteAll();
4080 //g_Menu_Free(); //k8: this segfaults after resolution change; who cares?
4082 if NetInitDone then g_Net_Free;
4084 // Íàäî óäàëèòü êàðòó ïîñëå òåñòà:
4085 if gMapToDelete <> '' then
4086 g_Game_DeleteTestMap();
4088 gExit := EXIT_QUIT;
4089 PushExitEvent();
4090 end;
4092 procedure g_FatalError(Text: String);
4093 begin
4094 g_Console_Add(Format(_lc[I_FATAL_ERROR], [Text]), True);
4095 e_WriteLog(Format(_lc[I_FATAL_ERROR], [Text]), TMsgType.Warning);
4097 gExit := EXIT_SIMPLE;
4098 end;
4100 procedure g_SimpleError(Text: String);
4101 begin
4102 g_Console_Add(Format(_lc[I_SIMPLE_ERROR], [Text]), True);
4103 e_WriteLog(Format(_lc[I_SIMPLE_ERROR], [Text]), TMsgType.Warning);
4104 end;
4106 procedure g_Game_SetupScreenSize();
4107 const
4108 RES_FACTOR = 4.0 / 3.0;
4109 var
4110 s: Single;
4111 rf: Single;
4112 bw, bh: Word;
4113 begin
4114 // Ðàçìåð ýêðàíîâ èãðîêîâ:
4115 gPlayerScreenSize.X := gScreenWidth-196;
4116 if (gPlayer1 <> nil) and (gPlayer2 <> nil) then
4117 gPlayerScreenSize.Y := gScreenHeight div 2
4118 else
4119 gPlayerScreenSize.Y := gScreenHeight;
4121 // Ðàçìåð çàäíåãî ïëàíà:
4122 if BackID <> DWORD(-1) then
4123 begin
4124 s := SKY_STRETCH;
4125 if (gScreenWidth*s > gMapInfo.Width) or
4126 (gScreenHeight*s > gMapInfo.Height) then
4127 begin
4128 gBackSize.X := gScreenWidth;
4129 gBackSize.Y := gScreenHeight;
4130 end
4131 else
4132 begin
4133 e_GetTextureSize(BackID, @bw, @bh);
4134 rf := Single(bw) / Single(bh);
4135 if (rf > RES_FACTOR) then bw := Round(Single(bh) * RES_FACTOR)
4136 else if (rf < RES_FACTOR) then bh := Round(Single(bw) / RES_FACTOR);
4137 s := Max(gScreenWidth / bw, gScreenHeight / bh);
4138 if (s < 1.0) then s := 1.0;
4139 gBackSize.X := Round(bw*s);
4140 gBackSize.Y := Round(bh*s);
4141 end;
4142 end;
4143 end;
4145 procedure g_Game_ChangeResolution(newWidth, newHeight: Word; nowFull, nowMax: Boolean);
4146 begin
4147 g_Window_SetSize(newWidth, newHeight, nowFull);
4148 end;
4150 procedure g_Game_AddPlayer(Team: Byte = TEAM_NONE);
4151 begin
4152 if ((not gGameOn) and (gState <> STATE_INTERCUSTOM))
4153 or (not (gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT])) then
4154 Exit;
4155 if gPlayer1 = nil then
4156 begin
4157 if g_Game_IsClient then
4158 begin
4159 if NetPlrUID1 > -1 then
4160 begin
4161 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE);
4162 gPlayer1 := g_Player_Get(NetPlrUID1);
4163 end;
4164 Exit;
4165 end;
4167 if not (Team in [TEAM_RED, TEAM_BLUE]) then
4168 Team := gPlayer1Settings.Team;
4170 // Ñîçäàíèå ïåðâîãî èãðîêà:
4171 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
4172 gPlayer1Settings.Color,
4173 Team, False));
4174 if gPlayer1 = nil then
4175 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]))
4176 else
4177 begin
4178 gPlayer1.Name := gPlayer1Settings.Name;
4179 g_Console_Add(Format(_lc[I_PLAYER_JOIN], [gPlayer1.Name]), True);
4180 if g_Game_IsServer and g_Game_IsNet then
4181 MH_SEND_PlayerCreate(gPlayer1.UID);
4182 gPlayer1.Respawn(False, True);
4184 if g_Game_IsNet and NetUseMaster then
4185 g_Net_Slist_Update;
4186 end;
4188 Exit;
4189 end;
4190 if gPlayer2 = nil then
4191 begin
4192 if g_Game_IsClient then
4193 begin
4194 if NetPlrUID2 > -1 then
4195 gPlayer2 := g_Player_Get(NetPlrUID2);
4196 Exit;
4197 end;
4199 if not (Team in [TEAM_RED, TEAM_BLUE]) then
4200 Team := gPlayer2Settings.Team;
4202 // Ñîçäàíèå âòîðîãî èãðîêà:
4203 gPlayer2 := g_Player_Get(g_Player_Create(gPlayer2Settings.Model,
4204 gPlayer2Settings.Color,
4205 Team, False));
4206 if gPlayer2 = nil then
4207 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [2]))
4208 else
4209 begin
4210 gPlayer2.Name := gPlayer2Settings.Name;
4211 g_Console_Add(Format(_lc[I_PLAYER_JOIN], [gPlayer2.Name]), True);
4212 if g_Game_IsServer and g_Game_IsNet then
4213 MH_SEND_PlayerCreate(gPlayer2.UID);
4214 gPlayer2.Respawn(False, True);
4216 if g_Game_IsNet and NetUseMaster then
4217 g_Net_Slist_Update;
4218 end;
4220 Exit;
4221 end;
4222 end;
4224 procedure g_Game_RemovePlayer();
4225 var
4226 Pl: TPlayer;
4227 begin
4228 if ((not gGameOn) and (gState <> STATE_INTERCUSTOM))
4229 or (not (gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT])) then
4230 Exit;
4231 Pl := gPlayer2;
4232 if Pl <> nil then
4233 begin
4234 if g_Game_IsServer then
4235 begin
4236 Pl.Lives := 0;
4237 Pl.Kill(K_SIMPLEKILL, 0, HIT_DISCON);
4238 g_Console_Add(Format(_lc[I_PLAYER_LEAVE], [Pl.Name]), True);
4239 g_Player_Remove(Pl.UID);
4241 if g_Game_IsNet and NetUseMaster then
4242 g_Net_Slist_Update;
4243 end else
4244 gPlayer2 := nil;
4245 Exit;
4246 end;
4247 Pl := gPlayer1;
4248 if Pl <> nil then
4249 begin
4250 if g_Game_IsServer then
4251 begin
4252 Pl.Lives := 0;
4253 Pl.Kill(K_SIMPLEKILL, 0, HIT_DISCON);
4254 g_Console_Add(Format(_lc[I_PLAYER_LEAVE], [Pl.Name]), True);
4255 g_Player_Remove(Pl.UID);
4257 if g_Game_IsNet and NetUseMaster then
4258 g_Net_Slist_Update;
4259 end else
4260 begin
4261 gPlayer1 := nil;
4262 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE);
4263 end;
4264 Exit;
4265 end;
4266 end;
4268 procedure g_Game_Spectate();
4269 begin
4270 g_Game_RemovePlayer();
4271 if gPlayer1 <> nil then
4272 g_Game_RemovePlayer();
4273 end;
4275 procedure g_Game_SpectateCenterView();
4276 begin
4277 gSpectX := Max(gMapInfo.Width div 2 - gScreenWidth div 2, 0);
4278 gSpectY := Max(gMapInfo.Height div 2 - gScreenHeight div 2, 0);
4279 end;
4281 procedure g_Game_StartSingle(Map: String; TwoPlayers: Boolean; nPlayers: Byte);
4282 var
4283 i, nPl: Integer;
4284 tmps: AnsiString;
4285 begin
4286 g_Game_Free();
4288 e_WriteLog('Starting singleplayer game...', TMsgType.Notify);
4290 g_Game_ClearLoading();
4292 // Íàñòðîéêè èãðû:
4293 FillByte(gGameSettings, SizeOf(TGameSettings), 0);
4294 gAimLine := False;
4295 gShowMap := False;
4296 gGameSettings.GameType := GT_SINGLE;
4297 gGameSettings.MaxLives := 0;
4298 gGameSettings.Options := gGameSettings.Options + GAME_OPTION_ALLOWEXIT;
4299 gGameSettings.Options := gGameSettings.Options + GAME_OPTION_MONSTERS;
4300 gGameSettings.Options := gGameSettings.Options + GAME_OPTION_BOTVSMONSTER;
4301 gSwitchGameMode := GM_SINGLE;
4303 g_Game_ExecuteEvent('ongamestart');
4305 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
4306 g_Game_SetupScreenSize();
4308 // Ñîçäàíèå ïåðâîãî èãðîêà:
4309 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
4310 gPlayer1Settings.Color,
4311 gPlayer1Settings.Team, False));
4312 if gPlayer1 = nil then
4313 begin
4314 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]));
4315 Exit;
4316 end;
4318 gPlayer1.Name := gPlayer1Settings.Name;
4319 nPl := 1;
4321 // Ñîçäàíèå âòîðîãî èãðîêà, åñëè åñòü:
4322 if TwoPlayers then
4323 begin
4324 gPlayer2 := g_Player_Get(g_Player_Create(gPlayer2Settings.Model,
4325 gPlayer2Settings.Color,
4326 gPlayer2Settings.Team, False));
4327 if gPlayer2 = nil then
4328 begin
4329 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [2]));
4330 Exit;
4331 end;
4333 gPlayer2.Name := gPlayer2Settings.Name;
4334 Inc(nPl);
4335 end;
4337 // Çàãðóçêà è çàïóñê êàðòû:
4338 if not g_Game_StartMap(MAP, True) then
4339 begin
4340 if (Pos(':\', Map) > 0) or (Pos(':/', Map) > 0) then tmps := Map else tmps := gGameSettings.WAD + ':\' + MAP;
4341 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [tmps]));
4342 Exit;
4343 end;
4345 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4346 g_Player_Init();
4348 // Ñîçäàåì áîòîâ:
4349 for i := nPl+1 to nPlayers do
4350 g_Player_Create(STD_PLAYER_MODEL, _RGB(0, 0, 0), 0, True);
4351 end;
4353 procedure g_Game_StartCustom(Map: String; GameMode: Byte;
4354 TimeLimit, GoalLimit: Word;
4355 MaxLives: Byte;
4356 Options: LongWord; nPlayers: Byte);
4357 var
4358 i, nPl: Integer;
4359 begin
4360 g_Game_Free();
4362 e_WriteLog('Starting custom game...', TMsgType.Notify);
4364 g_Game_ClearLoading();
4366 // Íàñòðîéêè èãðû:
4367 gGameSettings.GameType := GT_CUSTOM;
4368 gGameSettings.GameMode := GameMode;
4369 gSwitchGameMode := GameMode;
4370 gGameSettings.TimeLimit := TimeLimit;
4371 gGameSettings.GoalLimit := GoalLimit;
4372 gGameSettings.MaxLives := IfThen(GameMode = GM_CTF, 0, MaxLives);
4373 gGameSettings.Options := Options;
4375 gCoopTotalMonstersKilled := 0;
4376 gCoopTotalSecretsFound := 0;
4377 gCoopTotalMonsters := 0;
4378 gCoopTotalSecrets := 0;
4379 gAimLine := False;
4380 gShowMap := False;
4382 g_Game_ExecuteEvent('ongamestart');
4384 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
4385 g_Game_SetupScreenSize();
4387 // Ðåæèì íàáëþäàòåëÿ:
4388 if nPlayers = 0 then
4389 begin
4390 gPlayer1 := nil;
4391 gPlayer2 := nil;
4392 end;
4394 nPl := 0;
4395 if nPlayers >= 1 then
4396 begin
4397 // Ñîçäàíèå ïåðâîãî èãðîêà:
4398 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
4399 gPlayer1Settings.Color,
4400 gPlayer1Settings.Team, False));
4401 if gPlayer1 = nil then
4402 begin
4403 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]));
4404 Exit;
4405 end;
4407 gPlayer1.Name := gPlayer1Settings.Name;
4408 Inc(nPl);
4409 end;
4411 if nPlayers >= 2 then
4412 begin
4413 // Ñîçäàíèå âòîðîãî èãðîêà:
4414 gPlayer2 := g_Player_Get(g_Player_Create(gPlayer2Settings.Model,
4415 gPlayer2Settings.Color,
4416 gPlayer2Settings.Team, False));
4417 if gPlayer2 = nil then
4418 begin
4419 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [2]));
4420 Exit;
4421 end;
4423 gPlayer2.Name := gPlayer2Settings.Name;
4424 Inc(nPl);
4425 end;
4427 // Çàãðóçêà è çàïóñê êàðòû:
4428 if not g_Game_StartMap(Map, True) then
4429 begin
4430 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [Map]));
4431 Exit;
4432 end;
4434 // Íåò òî÷åê ïîÿâëåíèÿ:
4435 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1) +
4436 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2) +
4437 g_Map_GetPointCount(RESPAWNPOINT_DM) +
4438 g_Map_GetPointCount(RESPAWNPOINT_RED)+
4439 g_Map_GetPointCount(RESPAWNPOINT_BLUE)) < 1 then
4440 begin
4441 g_FatalError(_lc[I_GAME_ERROR_GET_SPAWN]);
4442 Exit;
4443 end;
4445 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4446 g_Player_Init();
4448 // Ñîçäàåì áîòîâ:
4449 for i := nPl+1 to nPlayers do
4450 g_Player_Create(STD_PLAYER_MODEL, _RGB(0, 0, 0), 0, True);
4451 end;
4453 procedure g_Game_StartServer(Map: String; GameMode: Byte;
4454 TimeLimit, GoalLimit: Word; MaxLives: Byte;
4455 Options: LongWord; nPlayers: Byte;
4456 IPAddr: LongWord; Port: Word);
4457 begin
4458 g_Game_Free();
4460 e_WriteLog('Starting net game (server)...', TMsgType.Notify);
4462 g_Game_ClearLoading();
4464 // Íàñòðîéêè èãðû:
4465 gGameSettings.GameType := GT_SERVER;
4466 gGameSettings.GameMode := GameMode;
4467 gSwitchGameMode := GameMode;
4468 gGameSettings.TimeLimit := TimeLimit;
4469 gGameSettings.GoalLimit := GoalLimit;
4470 gGameSettings.MaxLives := IfThen(GameMode = GM_CTF, 0, MaxLives);
4471 gGameSettings.Options := Options;
4473 gCoopTotalMonstersKilled := 0;
4474 gCoopTotalSecretsFound := 0;
4475 gCoopTotalMonsters := 0;
4476 gCoopTotalSecrets := 0;
4477 gAimLine := False;
4478 gShowMap := False;
4480 g_Game_ExecuteEvent('ongamestart');
4482 // Óñòàíîâêà ðàçìåðîâ îêíà èãðîêà
4483 g_Game_SetupScreenSize();
4485 // Ðåæèì íàáëþäàòåëÿ:
4486 if nPlayers = 0 then
4487 begin
4488 gPlayer1 := nil;
4489 gPlayer2 := nil;
4490 end;
4492 if nPlayers >= 1 then
4493 begin
4494 // Ñîçäàíèå ïåðâîãî èãðîêà:
4495 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
4496 gPlayer1Settings.Color,
4497 gPlayer1Settings.Team, False));
4498 if gPlayer1 = nil then
4499 begin
4500 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]));
4501 Exit;
4502 end;
4504 gPlayer1.Name := gPlayer1Settings.Name;
4505 end;
4507 if nPlayers >= 2 then
4508 begin
4509 // Ñîçäàíèå âòîðîãî èãðîêà:
4510 gPlayer2 := g_Player_Get(g_Player_Create(gPlayer2Settings.Model,
4511 gPlayer2Settings.Color,
4512 gPlayer2Settings.Team, False));
4513 if gPlayer2 = nil then
4514 begin
4515 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [2]));
4516 Exit;
4517 end;
4519 gPlayer2.Name := gPlayer2Settings.Name;
4520 end;
4522 g_Game_SetLoadingText(_lc[I_LOAD_HOST], 0, False);
4523 if NetForwardPorts then
4524 g_Game_SetLoadingText(_lc[I_LOAD_PORTS], 0, False);
4526 // Ñòàðòóåì ñåðâåð
4527 if not g_Net_Host(IPAddr, Port, NetMaxClients) then
4528 begin
4529 g_FatalError(_lc[I_NET_MSG] + _lc[I_NET_ERR_HOST]);
4530 Exit;
4531 end;
4533 g_Net_Slist_Set(NetSlistIP, NetSlistPort);
4535 // Çàãðóçêà è çàïóñê êàðòû:
4536 if not g_Game_StartMap(Map, True) then
4537 begin
4538 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [Map]));
4539 Exit;
4540 end;
4542 // Íåò òî÷åê ïîÿâëåíèÿ:
4543 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1) +
4544 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2) +
4545 g_Map_GetPointCount(RESPAWNPOINT_DM) +
4546 g_Map_GetPointCount(RESPAWNPOINT_RED)+
4547 g_Map_GetPointCount(RESPAWNPOINT_BLUE)) < 1 then
4548 begin
4549 g_FatalError(_lc[I_GAME_ERROR_GET_SPAWN]);
4550 Exit;
4551 end;
4553 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4554 g_Player_Init();
4556 NetState := NET_STATE_GAME;
4557 end;
4559 procedure g_Game_StartClient(Addr: String; Port: Word; PW: String);
4560 var
4561 Map: String;
4562 WadName: string;
4563 Ptr: Pointer;
4564 T: Cardinal;
4565 MID: Byte;
4566 State: Byte;
4567 OuterLoop: Boolean;
4568 newResPath: string;
4569 InMsg: TMsg;
4570 begin
4571 g_Game_Free();
4573 State := 0;
4574 e_WriteLog('Starting net game (client)...', TMsgType.Notify);
4575 e_WriteLog('NET: Trying to connect to ' + Addr + ':' + IntToStr(Port) + '...', TMsgType.Notify);
4577 g_Game_ClearLoading();
4579 // Íàñòðîéêè èãðû:
4580 gGameSettings.GameType := GT_CLIENT;
4582 gCoopTotalMonstersKilled := 0;
4583 gCoopTotalSecretsFound := 0;
4584 gCoopTotalMonsters := 0;
4585 gCoopTotalSecrets := 0;
4586 gAimLine := False;
4587 gShowMap := False;
4589 g_Game_ExecuteEvent('ongamestart');
4591 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
4592 g_Game_SetupScreenSize();
4594 NetState := NET_STATE_AUTH;
4596 g_Game_SetLoadingText(_lc[I_LOAD_CONNECT], 0, False);
4597 // Ñòàðòóåì êëèåíò
4598 if not g_Net_Connect(Addr, Port) then
4599 begin
4600 g_FatalError(_lc[I_NET_MSG] + _lc[I_NET_ERR_CONN]);
4601 NetState := NET_STATE_NONE;
4602 Exit;
4603 end;
4605 g_Game_SetLoadingText(_lc[I_LOAD_SEND_INFO], 0, False);
4606 MC_SEND_Info(PW);
4607 g_Game_SetLoadingText(_lc[I_LOAD_WAIT_INFO], 0, False);
4609 OuterLoop := True;
4610 while OuterLoop do
4611 begin
4612 while (enet_host_service(NetHost, @NetEvent, 0) > 0) do
4613 begin
4614 if (NetEvent.kind = ENET_EVENT_TYPE_RECEIVE) then
4615 begin
4616 Ptr := NetEvent.packet^.data;
4617 if not InMsg.Init(Ptr, NetEvent.packet^.dataLength, True) then
4618 continue;
4620 MID := InMsg.ReadByte();
4622 if (MID = NET_MSG_INFO) and (State = 0) then
4623 begin
4624 NetMyID := InMsg.ReadByte();
4625 NetPlrUID1 := InMsg.ReadWord();
4627 WadName := InMsg.ReadString();
4628 Map := InMsg.ReadString();
4630 gWADHash := InMsg.ReadMD5();
4632 gGameSettings.GameMode := InMsg.ReadByte();
4633 gSwitchGameMode := gGameSettings.GameMode;
4634 gGameSettings.GoalLimit := InMsg.ReadWord();
4635 gGameSettings.TimeLimit := InMsg.ReadWord();
4636 gGameSettings.MaxLives := InMsg.ReadByte();
4637 gGameSettings.Options := InMsg.ReadLongWord();
4638 T := InMsg.ReadLongWord();
4640 newResPath := g_Res_SearchSameWAD(MapsDir, WadName, gWADHash);
4641 if newResPath = '' then
4642 begin
4643 g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
4644 newResPath := g_Res_DownloadWAD(WadName);
4645 if newResPath = '' then
4646 begin
4647 g_FatalError(_lc[I_NET_ERR_HASH]);
4648 enet_packet_destroy(NetEvent.packet);
4649 NetState := NET_STATE_NONE;
4650 Exit;
4651 end;
4652 end;
4653 newResPath := ExtractRelativePath(MapsDir, newResPath);
4655 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
4656 gPlayer1Settings.Color,
4657 gPlayer1Settings.Team, False));
4659 if gPlayer1 = nil then
4660 begin
4661 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]));
4663 enet_packet_destroy(NetEvent.packet);
4664 NetState := NET_STATE_NONE;
4665 Exit;
4666 end;
4668 gPlayer1.Name := gPlayer1Settings.Name;
4669 gPlayer1.UID := NetPlrUID1;
4670 gPlayer1.Reset(True);
4672 if not g_Game_StartMap(newResPath + ':\' + Map, True) then
4673 begin
4674 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [WadName + ':\' + Map]));
4676 enet_packet_destroy(NetEvent.packet);
4677 NetState := NET_STATE_NONE;
4678 Exit;
4679 end;
4681 gTime := T;
4683 State := 1;
4684 OuterLoop := False;
4685 enet_packet_destroy(NetEvent.packet);
4686 break;
4687 end
4688 else
4689 enet_packet_destroy(NetEvent.packet);
4690 end
4691 else
4692 begin
4693 if (NetEvent.kind = ENET_EVENT_TYPE_DISCONNECT) then
4694 begin
4695 State := 0;
4696 if (NetEvent.data <= NET_DISC_MAX) then
4697 g_Console_Add(_lc[I_NET_MSG_ERROR] + _lc[I_NET_ERR_CONN] + ' ' +
4698 _lc[TStrings_Locale(Cardinal(I_NET_DISC_NONE) + NetEvent.data)], True);
4699 OuterLoop := False;
4700 Break;
4701 end;
4702 end;
4703 end;
4705 ProcessLoading(true);
4707 if e_KeyPressed(IK_SPACE) or e_KeyPressed(IK_ESCAPE) or e_KeyPressed(VK_ESCAPE) or
4708 e_KeyPressed(JOY0_JUMP) or e_KeyPressed(JOY1_JUMP) or e_KeyPressed(JOY2_JUMP) or e_KeyPressed(JOY3_JUMP) then
4709 begin
4710 State := 0;
4711 break;
4712 end;
4713 end;
4715 if State <> 1 then
4716 begin
4717 g_FatalError(_lc[I_NET_MSG] + _lc[I_NET_ERR_CONN]);
4718 NetState := NET_STATE_NONE;
4719 Exit;
4720 end;
4722 gLMSRespawn := LMS_RESPAWN_NONE;
4723 gLMSRespawnTime := 0;
4725 g_Player_Init();
4726 NetState := NET_STATE_GAME;
4727 MC_SEND_FullStateRequest;
4728 e_WriteLog('NET: Connection successful.', TMsgType.Notify);
4729 end;
4731 procedure g_Game_SaveOptions();
4732 begin
4733 g_Options_Write_Video(GameDir+'/'+CONFIG_FILENAME);
4734 end;
4736 procedure g_Game_ChangeMap(const MapPath: String);
4737 var
4738 Force: Boolean;
4739 begin
4740 g_Game_ClearLoading();
4742 Force := gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF];
4743 // Åñëè óðîâåíü çàâåðøèëñÿ ïî òðèããåðó Âûõîä, íå î÷èùàòü èíâåíòàðü
4744 if gExitByTrigger then
4745 begin
4746 Force := False;
4747 gExitByTrigger := False;
4748 end;
4749 if not g_Game_StartMap(MapPath, Force) then
4750 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [MapPath]));
4751 end;
4753 procedure g_Game_Restart();
4754 var
4755 Map: string;
4756 begin
4757 if g_Game_IsClient then
4758 Exit;
4759 map := g_ExtractFileName(gMapInfo.Map);
4761 MessageTime := 0;
4762 gGameOn := False;
4763 g_Game_ClearLoading();
4764 g_Game_StartMap(Map, True, gCurrentMapFileName);
4765 end;
4767 function g_Game_StartMap(Map: String; Force: Boolean = False; const oldMapPath: AnsiString=''): Boolean;
4768 var
4769 NewWAD, ResName: String;
4770 I: Integer;
4771 begin
4772 g_Map_Free((Map <> gCurrentMapFileName) and (oldMapPath <> gCurrentMapFileName));
4773 g_Player_RemoveAllCorpses();
4775 if (not g_Game_IsClient) and
4776 (gSwitchGameMode <> gGameSettings.GameMode) and
4777 (gGameSettings.GameMode <> GM_SINGLE) then
4778 begin
4779 if gSwitchGameMode = GM_CTF then
4780 gGameSettings.MaxLives := 0;
4781 gGameSettings.GameMode := gSwitchGameMode;
4782 Force := True;
4783 end else
4784 gSwitchGameMode := gGameSettings.GameMode;
4786 g_Player_ResetTeams();
4788 if isWadPath(Map) then
4789 begin
4790 NewWAD := g_ExtractWadName(Map);
4791 ResName := g_ExtractFileName(Map);
4792 if g_Game_IsServer then
4793 begin
4794 gWADHash := MD5File(MapsDir + NewWAD);
4795 g_Game_LoadWAD(NewWAD);
4796 end else
4797 // hash received in MC_RECV_GameEvent -> NET_EV_MAPSTART
4798 g_Game_ClientWAD(NewWAD, gWADHash);
4799 end else
4800 ResName := Map;
4802 Result := g_Map_Load(MapsDir + gGameSettings.WAD + ':\' + ResName);
4803 if Result then
4804 begin
4805 g_Player_ResetAll(Force or gLastMap, gGameSettings.GameType = GT_SINGLE);
4807 gState := STATE_NONE;
4808 g_ActiveWindow := nil;
4809 gGameOn := True;
4811 DisableCheats();
4812 ResetTimer();
4814 if gGameSettings.GameMode = GM_CTF then
4815 begin
4816 g_Map_ResetFlag(FLAG_RED);
4817 g_Map_ResetFlag(FLAG_BLUE);
4818 // CTF, à ôëàãîâ íåò:
4819 if not g_Map_HaveFlagPoints() then
4820 g_SimpleError(_lc[I_GAME_ERROR_CTF]);
4821 end;
4822 end
4823 else
4824 begin
4825 gState := STATE_MENU;
4826 gGameOn := False;
4827 end;
4829 gExit := 0;
4830 gPauseMain := false;
4831 gPauseHolmes := false;
4832 gTime := 0;
4833 NetTimeToUpdate := 1;
4834 NetTimeToReliable := 0;
4835 NetTimeToMaster := NetMasterRate;
4836 gLMSRespawn := LMS_RESPAWN_NONE;
4837 gLMSRespawnTime := 0;
4838 gMissionFailed := False;
4839 gNextMap := '';
4841 gCoopMonstersKilled := 0;
4842 gCoopSecretsFound := 0;
4844 gVoteInProgress := False;
4845 gVotePassed := False;
4846 gVoteCount := 0;
4847 gVoted := False;
4849 gStatsOff := False;
4851 if not gGameOn then Exit;
4853 g_Game_SpectateCenterView();
4855 if (gGameSettings.MaxLives > 0) and (gGameSettings.WarmupTime > 0) then
4856 begin
4857 gLMSRespawn := LMS_RESPAWN_WARMUP;
4858 gLMSRespawnTime := gTime + gGameSettings.WarmupTime*1000;
4859 gLMSSoftSpawn := True;
4860 if NetMode = NET_SERVER then
4861 MH_SEND_GameEvent(NET_EV_LMS_WARMUP, (gLMSRespawnTime - gTime) div 1000)
4862 else
4863 g_Console_Add(Format(_lc[I_MSG_WARMUP_START], [(gLMSRespawnTime - gTime) div 1000]), True);
4864 end;
4866 if NetMode = NET_SERVER then
4867 begin
4868 MH_SEND_GameEvent(NET_EV_MAPSTART, gGameSettings.GameMode, Map);
4870 // Ìàñòåðñåðâåð
4871 if NetUseMaster then
4872 begin
4873 if (NetMHost = nil) or (NetMPeer = nil) then
4874 if not g_Net_Slist_Connect then
4875 g_Console_Add(_lc[I_NET_MSG_ERROR] + _lc[I_NET_SLIST_ERROR]);
4877 g_Net_Slist_Update;
4878 end;
4880 if NetClients <> nil then
4881 for I := 0 to High(NetClients) do
4882 if NetClients[I].Used then
4883 begin
4884 NetClients[I].Voted := False;
4885 if NetClients[I].RequestedFullUpdate then
4886 begin
4887 MH_SEND_Everything((NetClients[I].State = NET_STATE_AUTH), I);
4888 NetClients[I].RequestedFullUpdate := False;
4889 end;
4890 end;
4892 g_Net_UnbanNonPermHosts();
4893 end;
4895 if gLastMap then
4896 begin
4897 gCoopTotalMonstersKilled := 0;
4898 gCoopTotalSecretsFound := 0;
4899 gCoopTotalMonsters := 0;
4900 gCoopTotalSecrets := 0;
4901 gLastMap := False;
4902 end;
4904 g_Game_ExecuteEvent('onmapstart');
4905 end;
4907 procedure SetFirstLevel();
4908 begin
4909 gNextMap := '';
4911 MapList := g_Map_GetMapsList(MapsDir + gGameSettings.WAD);
4912 if MapList = nil then
4913 Exit;
4915 SortSArray(MapList);
4916 gNextMap := MapList[Low(MapList)];
4918 MapList := nil;
4919 end;
4921 procedure g_Game_ExitLevel(const Map: AnsiString);
4922 begin
4923 gNextMap := Map;
4925 gCoopTotalMonstersKilled := gCoopTotalMonstersKilled + gCoopMonstersKilled;
4926 gCoopTotalSecretsFound := gCoopTotalSecretsFound + gCoopSecretsFound;
4927 gCoopTotalMonsters := gCoopTotalMonsters + gTotalMonsters;
4928 gCoopTotalSecrets := gCoopTotalSecrets + gSecretsCount;
4930 // Âûøëè â âûõîä â Îäèíî÷íîé èãðå:
4931 if gGameSettings.GameType = GT_SINGLE then
4932 gExit := EXIT_ENDLEVELSINGLE
4933 else // Âûøëè â âûõîä â Ñâîåé èãðå
4934 begin
4935 gExit := EXIT_ENDLEVELCUSTOM;
4936 if gGameSettings.GameMode = GM_COOP then
4937 g_Player_RememberAll;
4939 if not g_Map_Exist(MapsDir + gGameSettings.WAD + ':\' + gNextMap) then
4940 begin
4941 gLastMap := True;
4942 if gGameSettings.GameMode = GM_COOP then
4943 gStatsOff := True;
4945 gStatsPressed := True;
4946 gNextMap := 'MAP01';
4948 if not g_Map_Exist(MapsDir + gGameSettings.WAD + ':\' + gNextMap) then
4949 g_Game_NextLevel;
4951 if g_Game_IsNet then
4952 begin
4953 MH_SEND_GameStats();
4954 MH_SEND_CoopStats();
4955 end;
4956 end;
4957 end;
4958 end;
4960 procedure g_Game_RestartLevel();
4961 var
4962 Map: string;
4963 begin
4964 if gGameSettings.GameMode = GM_SINGLE then
4965 begin
4966 g_Game_Restart();
4967 Exit;
4968 end;
4969 gExit := EXIT_ENDLEVELCUSTOM;
4970 Map := g_ExtractFileName(gMapInfo.Map);
4971 gNextMap := Map;
4972 end;
4974 procedure g_Game_ClientWAD(NewWAD: String; WHash: TMD5Digest);
4975 var
4976 gWAD: String;
4977 begin
4978 if LowerCase(NewWAD) = LowerCase(gGameSettings.WAD) then
4979 Exit;
4980 if not g_Game_IsClient then
4981 Exit;
4982 gWAD := g_Res_SearchSameWAD(MapsDir, ExtractFileName(NewWAD), WHash);
4983 if gWAD = '' then
4984 begin
4985 g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
4986 gWAD := g_Res_DownloadWAD(ExtractFileName(NewWAD));
4987 if gWAD = '' then
4988 begin
4989 g_Game_Free();
4990 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_WAD], [ExtractFileName(NewWAD)]));
4991 Exit;
4992 end;
4993 end;
4994 NewWAD := ExtractRelativePath(MapsDir, gWAD);
4995 g_Game_LoadWAD(NewWAD);
4996 end;
4998 procedure g_Game_RestartRound(NoMapRestart: Boolean = False);
4999 var
5000 i, n, nb, nr: Integer;
5002 function monRespawn (mon: TMonster): Boolean;
5003 begin
5004 result := false; // don't stop
5005 if not mon.FNoRespawn then mon.Respawn();
5006 end;
5008 begin
5009 if not g_Game_IsServer then Exit;
5010 if gLMSRespawn = LMS_RESPAWN_NONE then Exit;
5011 gLMSRespawn := LMS_RESPAWN_NONE;
5012 gLMSRespawnTime := 0;
5013 MessageTime := 0;
5015 if (gGameSettings.GameMode = GM_COOP) and not NoMapRestart then
5016 begin
5017 gMissionFailed := True;
5018 g_Game_RestartLevel;
5019 Exit;
5020 end;
5022 n := 0; nb := 0; nr := 0;
5023 for i := Low(gPlayers) to High(gPlayers) do
5024 if (gPlayers[i] <> nil) and
5025 ((not gPlayers[i].FSpectator) or gPlayers[i].FWantsInGame or
5026 (gPlayers[i] is TBot)) then
5027 begin
5028 Inc(n);
5029 if gPlayers[i].Team = TEAM_RED then Inc(nr)
5030 else if gPlayers[i].Team = TEAM_BLUE then Inc(nb)
5031 end;
5033 if (n < 2) or ((gGameSettings.GameMode = GM_TDM) and ((nr = 0) or (nb = 0))) then
5034 begin
5035 // wait a second until the fuckers finally decide to join
5036 gLMSRespawn := LMS_RESPAWN_WARMUP;
5037 gLMSRespawnTime := gTime + 1000;
5038 gLMSSoftSpawn := NoMapRestart;
5039 Exit;
5040 end;
5042 g_Player_RemoveAllCorpses;
5043 g_Game_Message(_lc[I_MESSAGE_LMS_START], 144);
5044 if g_Game_IsNet then
5045 MH_SEND_GameEvent(NET_EV_LMS_START);
5047 for i := Low(gPlayers) to High(gPlayers) do
5048 begin
5049 if gPlayers[i] = nil then continue;
5050 if gPlayers[i] is TBot then gPlayers[i].FWantsInGame := True;
5051 // don't touch normal spectators
5052 if gPlayers[i].FSpectator and not gPlayers[i].FWantsInGame then
5053 begin
5054 gPlayers[i].FNoRespawn := True;
5055 gPlayers[i].Lives := 0;
5056 if g_Game_IsNet then
5057 MH_SEND_PlayerStats(gPlayers[I].UID);
5058 continue;
5059 end;
5060 gPlayers[i].FNoRespawn := False;
5061 gPlayers[i].Lives := gGameSettings.MaxLives;
5062 gPlayers[i].Respawn(False, True);
5063 if gGameSettings.GameMode = GM_COOP then
5064 begin
5065 gPlayers[i].Frags := 0;
5066 gPlayers[i].RecallState;
5067 end;
5068 if (gPlayer1 = nil) and (gLMSPID1 > 0) then
5069 gPlayer1 := g_Player_Get(gLMSPID1);
5070 if (gPlayer2 = nil) and (gLMSPID2 > 0) then
5071 gPlayer2 := g_Player_Get(gLMSPID2);
5072 end;
5074 g_Items_RestartRound();
5077 g_Mons_ForEach(monRespawn);
5079 gLMSSoftSpawn := False;
5080 end;
5082 function g_Game_GetFirstMap(WAD: String): String;
5083 begin
5084 Result := '';
5086 MapList := g_Map_GetMapsList(WAD);
5087 if MapList = nil then
5088 Exit;
5090 SortSArray(MapList);
5091 Result := MapList[Low(MapList)];
5093 if not g_Map_Exist(WAD + ':\' + Result) then
5094 Result := '';
5096 MapList := nil;
5097 end;
5099 function g_Game_GetNextMap(): String;
5100 var
5101 I: Integer;
5102 Map: string;
5103 begin
5104 Result := '';
5106 MapList := g_Map_GetMapsList(MapsDir + gGameSettings.WAD);
5107 if MapList = nil then
5108 Exit;
5110 Map := g_ExtractFileName(gMapInfo.Map);
5112 SortSArray(MapList);
5113 MapIndex := -255;
5114 for I := Low(MapList) to High(MapList) do
5115 if Map = MapList[I] then
5116 begin
5117 MapIndex := I;
5118 Break;
5119 end;
5121 if MapIndex <> -255 then
5122 begin
5123 if MapIndex = High(MapList) then
5124 Result := MapList[Low(MapList)]
5125 else
5126 Result := MapList[MapIndex + 1];
5128 if not g_Map_Exist(MapsDir + gGameSettings.WAD + ':\' + Result) then Result := Map;
5129 end;
5131 MapList := nil;
5132 end;
5134 procedure g_Game_NextLevel();
5135 begin
5136 if gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF, GM_COOP] then
5137 gExit := EXIT_ENDLEVELCUSTOM
5138 else
5139 begin
5140 gExit := EXIT_ENDLEVELSINGLE;
5141 Exit;
5142 end;
5144 if gNextMap <> '' then Exit;
5145 gNextMap := g_Game_GetNextMap();
5146 end;
5148 function g_Game_IsTestMap(): Boolean;
5149 begin
5150 result := StrEquCI1251(TEST_MAP_NAME, g_ExtractFileName(gMapInfo.Map));
5151 end;
5153 procedure g_Game_DeleteTestMap();
5154 var
5155 a: Integer;
5156 //MapName: AnsiString;
5157 WadName: string;
5159 WAD: TWADFile;
5160 MapList: SSArray;
5161 time: Integer;
5163 begin
5164 a := Pos('.wad:\', toLowerCase1251(gMapToDelete));
5165 if (a = 0) then a := Pos('.wad:/', toLowerCase1251(gMapToDelete));
5166 if (a = 0) then exit;
5168 // Âûäåëÿåì èìÿ wad-ôàéëà è èìÿ êàðòû
5169 WadName := Copy(gMapToDelete, 1, a+3);
5170 Delete(gMapToDelete, 1, a+5);
5171 gMapToDelete := UpperCase(gMapToDelete);
5172 //MapName := '';
5173 //CopyMemory(@MapName[0], @gMapToDelete[1], Min(16, Length(gMapToDelete)));
5176 // Èìÿ êàðòû íå ñòàíäàðòíîå òåñòîâîå:
5177 if MapName <> TEST_MAP_NAME then
5178 Exit;
5180 if not gTempDelete then
5181 begin
5182 time := g_GetFileTime(WadName);
5183 WAD := TWADFile.Create();
5185 // ×èòàåì Wad-ôàéë:
5186 if not WAD.ReadFile(WadName) then
5187 begin // Íåò òàêîãî WAD-ôàéëà
5188 WAD.Free();
5189 Exit;
5190 end;
5192 // Ñîñòàâëÿåì ñïèñîê êàðò è èùåì íóæíóþ:
5193 WAD.CreateImage();
5194 MapList := WAD.GetResourcesList('');
5196 if MapList <> nil then
5197 for a := 0 to High(MapList) do
5198 if MapList[a] = MapName then
5199 begin
5200 // Óäàëÿåì è ñîõðàíÿåì:
5201 WAD.RemoveResource('', MapName);
5202 WAD.SaveTo(WadName);
5203 Break;
5204 end;
5206 WAD.Free();
5207 g_SetFileTime(WadName, time);
5208 end else
5210 if gTempDelete then DeleteFile(WadName);
5211 end;
5213 procedure GameCVars(P: SSArray);
5214 var
5215 a, b: Integer;
5216 stat: TPlayerStatArray;
5217 cmd, s: string;
5218 config: TConfig;
5219 begin
5220 stat := nil;
5221 cmd := LowerCase(P[0]);
5222 if (cmd = 'g_friendlyfire') and not g_Game_IsClient then
5223 begin
5224 with gGameSettings do
5225 begin
5226 if (Length(P) > 1) and
5227 ((P[1] = '1') or (P[1] = '0')) then
5228 begin
5229 if (P[1][1] = '1') then
5230 Options := Options or GAME_OPTION_TEAMDAMAGE
5231 else
5232 Options := Options and (not GAME_OPTION_TEAMDAMAGE);
5233 end;
5235 if (LongBool(Options and GAME_OPTION_TEAMDAMAGE)) then
5236 g_Console_Add(_lc[I_MSG_FRIENDLY_FIRE_ON])
5237 else
5238 g_Console_Add(_lc[I_MSG_FRIENDLY_FIRE_OFF]);
5240 if g_Game_IsNet then MH_SEND_GameSettings;
5241 end;
5242 end
5243 else if (cmd = 'g_weaponstay') and not g_Game_IsClient then
5244 begin
5245 with gGameSettings do
5246 begin
5247 if (Length(P) > 1) and
5248 ((P[1] = '1') or (P[1] = '0')) then
5249 begin
5250 if (P[1][1] = '1') then
5251 Options := Options or GAME_OPTION_WEAPONSTAY
5252 else
5253 Options := Options and (not GAME_OPTION_WEAPONSTAY);
5254 end;
5256 if (LongBool(Options and GAME_OPTION_WEAPONSTAY)) then
5257 g_Console_Add(_lc[I_MSG_WEAPONSTAY_ON])
5258 else
5259 g_Console_Add(_lc[I_MSG_WEAPONSTAY_OFF]);
5261 if g_Game_IsNet then MH_SEND_GameSettings;
5262 end;
5263 end
5264 else if cmd = 'g_gamemode' then
5265 begin
5266 a := g_Game_TextToMode(P[1]);
5267 if a = GM_SINGLE then a := GM_COOP;
5268 if (Length(P) > 1) and (a <> GM_NONE) and (not g_Game_IsClient) then
5269 begin
5270 gSwitchGameMode := a;
5271 if (gGameOn and (gGameSettings.GameMode = GM_SINGLE)) or
5272 (gState = STATE_INTERSINGLE) then
5273 gSwitchGameMode := GM_SINGLE;
5274 if not gGameOn then
5275 gGameSettings.GameMode := gSwitchGameMode;
5276 end;
5277 if gSwitchGameMode = gGameSettings.GameMode then
5278 g_Console_Add(Format(_lc[I_MSG_GAMEMODE_CURRENT],
5279 [g_Game_ModeToText(gGameSettings.GameMode)]))
5280 else
5281 g_Console_Add(Format(_lc[I_MSG_GAMEMODE_CHANGE],
5282 [g_Game_ModeToText(gGameSettings.GameMode),
5283 g_Game_ModeToText(gSwitchGameMode)]));
5284 end
5285 else if (cmd = 'g_allow_exit') and not g_Game_IsClient then
5286 begin
5287 with gGameSettings do
5288 begin
5289 if (Length(P) > 1) and
5290 ((P[1] = '1') or (P[1] = '0')) then
5291 begin
5292 if (P[1][1] = '1') then
5293 Options := Options or GAME_OPTION_ALLOWEXIT
5294 else
5295 Options := Options and (not GAME_OPTION_ALLOWEXIT);
5296 end;
5298 if (LongBool(Options and GAME_OPTION_ALLOWEXIT)) then
5299 g_Console_Add(_lc[I_MSG_ALLOWEXIT_ON])
5300 else
5301 g_Console_Add(_lc[I_MSG_ALLOWEXIT_OFF]);
5302 g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
5304 if g_Game_IsNet then MH_SEND_GameSettings;
5305 end;
5306 end
5307 else if (cmd = 'g_allow_monsters') and not g_Game_IsClient then
5308 begin
5309 with gGameSettings do
5310 begin
5311 if (Length(P) > 1) and
5312 ((P[1] = '1') or (P[1] = '0')) then
5313 begin
5314 if (P[1][1] = '1') then
5315 Options := Options or GAME_OPTION_MONSTERS
5316 else
5317 Options := Options and (not GAME_OPTION_MONSTERS);
5318 end;
5320 if (LongBool(Options and GAME_OPTION_MONSTERS)) then
5321 g_Console_Add(_lc[I_MSG_ALLOWMON_ON])
5322 else
5323 g_Console_Add(_lc[I_MSG_ALLOWMON_OFF]);
5324 g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
5326 if g_Game_IsNet then MH_SEND_GameSettings;
5327 end;
5328 end
5329 else if (cmd = 'g_bot_vsplayers') and not g_Game_IsClient then
5330 begin
5331 with gGameSettings do
5332 begin
5333 if (Length(P) > 1) and
5334 ((P[1] = '1') or (P[1] = '0')) then
5335 begin
5336 if (P[1][1] = '1') then
5337 Options := Options or GAME_OPTION_BOTVSPLAYER
5338 else
5339 Options := Options and (not GAME_OPTION_BOTVSPLAYER);
5340 end;
5342 if (LongBool(Options and GAME_OPTION_BOTVSPLAYER)) then
5343 g_Console_Add(_lc[I_MSG_BOTSVSPLAYERS_ON])
5344 else
5345 g_Console_Add(_lc[I_MSG_BOTSVSPLAYERS_OFF]);
5347 if g_Game_IsNet then MH_SEND_GameSettings;
5348 end;
5349 end
5350 else if (cmd = 'g_bot_vsmonsters') and not g_Game_IsClient then
5351 begin
5352 with gGameSettings do
5353 begin
5354 if (Length(P) > 1) and
5355 ((P[1] = '1') or (P[1] = '0')) then
5356 begin
5357 if (P[1][1] = '1') then
5358 Options := Options or GAME_OPTION_BOTVSMONSTER
5359 else
5360 Options := Options and (not GAME_OPTION_BOTVSMONSTER);
5361 end;
5363 if (LongBool(Options and GAME_OPTION_BOTVSMONSTER)) then
5364 g_Console_Add(_lc[I_MSG_BOTSVSMONSTERS_ON])
5365 else
5366 g_Console_Add(_lc[I_MSG_BOTSVSMONSTERS_OFF]);
5368 if g_Game_IsNet then MH_SEND_GameSettings;
5369 end;
5370 end
5371 else if (cmd = 'g_warmuptime') and not g_Game_IsClient then
5372 begin
5373 if Length(P) > 1 then
5374 begin
5375 if StrToIntDef(P[1], gGameSettings.WarmupTime) = 0 then
5376 gGameSettings.WarmupTime := 30
5377 else
5378 gGameSettings.WarmupTime := StrToIntDef(P[1], gGameSettings.WarmupTime);
5379 end;
5381 g_Console_Add(Format(_lc[I_MSG_WARMUP],
5382 [gGameSettings.WarmupTime]));
5383 g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
5384 end
5385 else if cmd = 'net_interp' then
5386 begin
5387 if (Length(P) > 1) then
5388 NetInterpLevel := StrToIntDef(P[1], NetInterpLevel);
5390 g_Console_Add('net_interp = ' + IntToStr(NetInterpLevel));
5391 config := TConfig.CreateFile(GameDir+'/'+CONFIG_FILENAME);
5392 config.WriteInt('Client', 'InterpolationSteps', NetInterpLevel);
5393 config.SaveFile(GameDir+'/'+CONFIG_FILENAME);
5394 config.Free();
5395 end
5396 else if cmd = 'net_forceplayerupdate' then
5397 begin
5398 if (Length(P) > 1) and
5399 ((P[1] = '1') or (P[1] = '0')) then
5400 NetForcePlayerUpdate := (P[1][1] = '1');
5402 if NetForcePlayerUpdate then
5403 g_Console_Add('net_forceplayerupdate = 1')
5404 else
5405 g_Console_Add('net_forceplayerupdate = 0');
5406 config := TConfig.CreateFile(GameDir+'/'+CONFIG_FILENAME);
5407 config.WriteBool('Client', 'ForcePlayerUpdate', NetForcePlayerUpdate);
5408 config.SaveFile(GameDir+'/'+CONFIG_FILENAME);
5409 config.Free();
5410 end
5411 else if cmd = 'net_predictself' then
5412 begin
5413 if (Length(P) > 1) and
5414 ((P[1] = '1') or (P[1] = '0')) then
5415 NetPredictSelf := (P[1][1] = '1');
5417 if NetPredictSelf then
5418 g_Console_Add('net_predictself = 1')
5419 else
5420 g_Console_Add('net_predictself = 0');
5421 config := TConfig.CreateFile(GameDir+'/'+CONFIG_FILENAME);
5422 config.WriteBool('Client', 'PredictSelf', NetPredictSelf);
5423 config.SaveFile(GameDir+'/'+CONFIG_FILENAME);
5424 config.Free();
5425 end
5426 else if cmd = 'sv_name' then
5427 begin
5428 if (Length(P) > 1) and (Length(P[1]) > 0) then
5429 begin
5430 NetServerName := P[1];
5431 if Length(NetServerName) > 64 then
5432 SetLength(NetServerName, 64);
5433 if g_Game_IsServer and g_Game_IsNet and NetUseMaster then
5434 g_Net_Slist_Update;
5435 end;
5437 g_Console_Add(cmd + ' = "' + NetServerName + '"');
5438 end
5439 else if cmd = 'sv_passwd' then
5440 begin
5441 if (Length(P) > 1) and (Length(P[1]) > 0) then
5442 begin
5443 NetPassword := P[1];
5444 if Length(NetPassword) > 24 then
5445 SetLength(NetPassword, 24);
5446 if g_Game_IsServer and g_Game_IsNet and NetUseMaster then
5447 g_Net_Slist_Update;
5448 end;
5450 g_Console_Add(cmd + ' = "' + AnsiLowerCase(NetPassword) + '"');
5451 end
5452 else if cmd = 'sv_maxplrs' then
5453 begin
5454 if (Length(P) > 1) then
5455 begin
5456 NetMaxClients := Min(Max(StrToIntDef(P[1], NetMaxClients), 1), NET_MAXCLIENTS);
5457 if g_Game_IsServer and g_Game_IsNet then
5458 begin
5459 b := 0;
5460 for a := 0 to High(NetClients) do
5461 if NetClients[a].Used then
5462 begin
5463 Inc(b);
5464 if b > NetMaxClients then
5465 begin
5466 s := g_Player_Get(NetClients[a].Player).Name;
5467 enet_peer_disconnect(NetClients[a].Peer, NET_DISC_FULL);
5468 g_Console_Add(Format(_lc[I_PLAYER_KICK], [s]));
5469 MH_SEND_GameEvent(NET_EV_PLAYER_KICK, 0, s);
5470 end;
5471 end;
5472 if NetUseMaster then
5473 g_Net_Slist_Update;
5474 end;
5475 end;
5477 g_Console_Add(cmd + ' = ' + IntToStr(NetMaxClients));
5478 end
5479 else if cmd = 'sv_public' then
5480 begin
5481 if (Length(P) > 1) then
5482 begin
5483 NetUseMaster := StrToIntDef(P[1], Byte(NetUseMaster)) > 0;
5484 if g_Game_IsServer and g_Game_IsNet then
5485 if NetUseMaster then
5486 begin
5487 if NetMPeer = nil then
5488 if not g_Net_Slist_Connect() then
5489 g_Console_Add(_lc[I_NET_MSG_ERROR] + _lc[I_NET_SLIST_ERROR]);
5490 g_Net_Slist_Update();
5491 end
5492 else
5493 if NetMPeer <> nil then
5494 g_Net_Slist_Disconnect();
5495 end;
5497 g_Console_Add(cmd + ' = ' + IntToStr(Byte(NetUseMaster)));
5498 end
5499 else if cmd = 'sv_intertime' then
5500 begin
5501 if (Length(P) > 1) then
5502 gDefInterTime := Min(Max(StrToIntDef(P[1], gDefInterTime), -1), 120);
5504 g_Console_Add(cmd + ' = ' + IntToStr(gDefInterTime));
5505 end
5506 else if cmd = 'p1_name' then
5507 begin
5508 if (Length(P) > 1) and gGameOn then
5509 begin
5510 if g_Game_IsClient then
5511 begin
5512 gPlayer1Settings.Name := b_Text_Unformat(P[1]);
5513 MC_SEND_PlayerSettings;
5514 end
5515 else
5516 if gPlayer1 <> nil then
5517 begin
5518 gPlayer1.Name := b_Text_Unformat(P[1]);
5519 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer1.UID);
5520 end
5521 else
5522 gPlayer1Settings.Name := b_Text_Unformat(P[1]);
5523 end;
5524 end
5525 else if cmd = 'p2_name' then
5526 begin
5527 if (Length(P) > 1) and gGameOn then
5528 begin
5529 if g_Game_IsClient then
5530 begin
5531 gPlayer2Settings.Name := b_Text_Unformat(P[1]);
5532 MC_SEND_PlayerSettings;
5533 end
5534 else
5535 if gPlayer2 <> nil then
5536 begin
5537 gPlayer2.Name := b_Text_Unformat(P[1]);
5538 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer2.UID);
5539 end
5540 else
5541 gPlayer2Settings.Name := b_Text_Unformat(P[1]);
5542 end;
5543 end
5544 else if cmd = 'p1_color' then
5545 begin
5546 if Length(P) > 3 then
5547 if g_Game_IsClient then
5548 begin
5549 gPlayer1Settings.Color := _RGB(EnsureRange(StrToIntDef(P[1], 0), 0, 255),
5550 EnsureRange(StrToIntDef(P[2], 0), 0, 255),
5551 EnsureRange(StrToIntDef(P[3], 0), 0, 255));
5552 MC_SEND_PlayerSettings;
5553 end
5554 else
5555 if gPlayer1 <> nil then
5556 begin
5557 gPlayer1.Model.SetColor(EnsureRange(StrToIntDef(P[1], 0), 0, 255),
5558 EnsureRange(StrToIntDef(P[2], 0), 0, 255),
5559 EnsureRange(StrToIntDef(P[3], 0), 0, 255));
5560 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer1.UID);
5561 end
5562 else
5563 gPlayer1Settings.Color := _RGB(EnsureRange(StrToIntDef(P[1], 0), 0, 255),
5564 EnsureRange(StrToIntDef(P[2], 0), 0, 255),
5565 EnsureRange(StrToIntDef(P[3], 0), 0, 255));
5566 end
5567 else if (cmd = 'p2_color') and not g_Game_IsNet then
5568 begin
5569 if Length(P) > 3 then
5570 if g_Game_IsClient then
5571 begin
5572 gPlayer2Settings.Color := _RGB(EnsureRange(StrToIntDef(P[1], 0), 0, 255),
5573 EnsureRange(StrToIntDef(P[2], 0), 0, 255),
5574 EnsureRange(StrToIntDef(P[3], 0), 0, 255));
5575 MC_SEND_PlayerSettings;
5576 end
5577 else
5578 if gPlayer2 <> nil then
5579 begin
5580 gPlayer2.Model.SetColor(EnsureRange(StrToIntDef(P[1], 0), 0, 255),
5581 EnsureRange(StrToIntDef(P[2], 0), 0, 255),
5582 EnsureRange(StrToIntDef(P[3], 0), 0, 255));
5583 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer2.UID);
5584 end
5585 else
5586 gPlayer2Settings.Color := _RGB(EnsureRange(StrToIntDef(P[1], 0), 0, 255),
5587 EnsureRange(StrToIntDef(P[2], 0), 0, 255),
5588 EnsureRange(StrToIntDef(P[3], 0), 0, 255));
5589 end
5590 else if gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT] then
5591 begin
5592 if cmd = 'r_showscore' then
5593 begin
5594 if (Length(P) > 1) and
5595 ((P[1] = '1') or (P[1] = '0')) then
5596 gShowGoals := (P[1][1] = '1');
5598 if gShowGoals then
5599 g_Console_Add(_lc[I_MSG_SCORE_ON])
5600 else
5601 g_Console_Add(_lc[I_MSG_SCORE_OFF]);
5602 end
5603 else if cmd = 'r_showstat' then
5604 begin
5605 if (Length(P) > 1) and
5606 ((P[1] = '1') or (P[1] = '0')) then
5607 gShowStat := (P[1][1] = '1');
5609 if gShowStat then
5610 g_Console_Add(_lc[I_MSG_STATS_ON])
5611 else
5612 g_Console_Add(_lc[I_MSG_STATS_OFF]);
5613 end
5614 else if cmd = 'r_showkillmsg' then
5615 begin
5616 if (Length(P) > 1) and
5617 ((P[1] = '1') or (P[1] = '0')) then
5618 gShowKillMsg := (P[1][1] = '1');
5620 if gShowKillMsg then
5621 g_Console_Add(_lc[I_MSG_KILL_MSGS_ON])
5622 else
5623 g_Console_Add(_lc[I_MSG_KILL_MSGS_OFF]);
5624 end
5625 else if cmd = 'r_showlives' then
5626 begin
5627 if (Length(P) > 1) and
5628 ((P[1] = '1') or (P[1] = '0')) then
5629 gShowLives := (P[1][1] = '1');
5631 if gShowLives then
5632 g_Console_Add(_lc[I_MSG_LIVES_ON])
5633 else
5634 g_Console_Add(_lc[I_MSG_LIVES_OFF]);
5635 end
5636 else if cmd = 'r_showspect' then
5637 begin
5638 if (Length(P) > 1) and
5639 ((P[1] = '1') or (P[1] = '0')) then
5640 gSpectHUD := (P[1][1] = '1');
5642 if gSpectHUD then
5643 g_Console_Add(_lc[I_MSG_SPECT_HUD_ON])
5644 else
5645 g_Console_Add(_lc[I_MSG_SPECT_HUD_OFF]);
5646 end
5647 else if cmd = 'r_showping' then
5648 begin
5649 if (Length(P) > 1) and
5650 ((P[1] = '1') or (P[1] = '0')) then
5651 gShowPing := (P[1][1] = '1');
5653 if gShowPing then
5654 g_Console_Add(_lc[I_MSG_PING_ON])
5655 else
5656 g_Console_Add(_lc[I_MSG_PING_OFF]);
5657 end
5658 else if (cmd = 'g_scorelimit') and not g_Game_IsClient then
5659 begin
5660 if Length(P) > 1 then
5661 begin
5662 if StrToIntDef(P[1], gGameSettings.GoalLimit) = 0 then
5663 gGameSettings.GoalLimit := 0
5664 else
5665 begin
5666 b := 0;
5668 if gGameSettings.GameMode = GM_DM then
5669 begin // DM
5670 stat := g_Player_GetStats();
5671 if stat <> nil then
5672 for a := 0 to High(stat) do
5673 if stat[a].Frags > b then
5674 b := stat[a].Frags;
5675 end
5676 else // TDM/CTF
5677 b := Max(gTeamStat[TEAM_RED].Goals, gTeamStat[TEAM_BLUE].Goals);
5679 gGameSettings.GoalLimit := Max(StrToIntDef(P[1], gGameSettings.GoalLimit), b);
5680 end;
5682 if g_Game_IsNet then MH_SEND_GameSettings;
5683 end;
5685 g_Console_Add(Format(_lc[I_MSG_SCORE_LIMIT], [gGameSettings.GoalLimit]));
5686 end
5687 else if (cmd = 'g_timelimit') and not g_Game_IsClient then
5688 begin
5689 if (Length(P) > 1) and (StrToIntDef(P[1], -1) >= 0) then
5690 gGameSettings.TimeLimit := StrToIntDef(P[1], -1);
5692 g_Console_Add(Format(_lc[I_MSG_TIME_LIMIT],
5693 [gGameSettings.TimeLimit div 3600,
5694 (gGameSettings.TimeLimit div 60) mod 60,
5695 gGameSettings.TimeLimit mod 60]));
5696 if g_Game_IsNet then MH_SEND_GameSettings;
5697 end
5698 else if (cmd = 'g_maxlives') and not g_Game_IsClient then
5699 begin
5700 if Length(P) > 1 then
5701 begin
5702 if StrToIntDef(P[1], gGameSettings.MaxLives) = 0 then
5703 gGameSettings.MaxLives := 0
5704 else
5705 begin
5706 b := 0;
5707 stat := g_Player_GetStats();
5708 if stat <> nil then
5709 for a := 0 to High(stat) do
5710 if stat[a].Lives > b then
5711 b := stat[a].Lives;
5712 gGameSettings.MaxLives :=
5713 Max(StrToIntDef(P[1], gGameSettings.MaxLives), b);
5714 end;
5715 end;
5717 g_Console_Add(Format(_lc[I_MSG_LIVES],
5718 [gGameSettings.MaxLives]));
5719 if g_Game_IsNet then MH_SEND_GameSettings;
5720 end;
5721 end;
5722 end;
5724 procedure PrintHeapStats();
5725 var
5726 hs: TFPCHeapStatus;
5727 begin
5728 hs := GetFPCHeapStatus();
5729 e_LogWriteLn ('v===== heap status =====v');
5730 e_LogWriteFln('max heap size = %d k', [hs.MaxHeapSize div 1024]);
5731 e_LogWriteFln('max heap used = %d k', [hs.MaxHeapUsed div 1024]);
5732 e_LogWriteFln('cur heap size = %d k', [hs.CurrHeapSize div 1024]);
5733 e_LogWriteFln('cur heap used = %d k', [hs.CurrHeapUsed div 1024]);
5734 e_LogWriteFln('cur heap free = %d k', [hs.CurrHeapFree div 1024]);
5735 e_LogWriteLn ('^=======================^');
5736 end;
5738 procedure DebugCommands(P: SSArray);
5739 var
5740 a, b: Integer;
5741 cmd: string;
5742 //pt: TDFPoint;
5743 mon: TMonster;
5744 begin
5745 // Êîìàíäû îòëàäî÷íîãî ðåæèìà:
5746 if {gDebugMode}conIsCheatsEnabled then
5747 begin
5748 cmd := LowerCase(P[0]);
5749 if cmd = 'd_window' then
5750 begin
5751 g_Console_Add(Format('gWinPosX = %d, gWinPosY %d', [gWinPosX, gWinPosY]));
5752 g_Console_Add(Format('gWinRealPosX = %d, gWinRealPosY %d', [gWinRealPosX, gWinRealPosY]));
5753 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth, gScreenHeight]));
5754 g_Console_Add(Format('gWinSizeX = %d, gWinSizeY = %d', [gWinSizeX, gWinSizeY]));
5755 g_Console_Add(Format('Frame X = %d, Y = %d, Caption Y = %d', [gWinFrameX, gWinFrameY, gWinCaption]));
5756 end
5757 else if cmd = 'd_sounds' then
5758 begin
5759 if (Length(P) > 1) and
5760 ((P[1] = '1') or (P[1] = '0')) then
5761 g_Debug_Sounds := (P[1][1] = '1');
5763 g_Console_Add(Format('d_sounds is %d', [Byte(g_Debug_Sounds)]));
5764 end
5765 else if cmd = 'd_frames' then
5766 begin
5767 if (Length(P) > 1) and
5768 ((P[1] = '1') or (P[1] = '0')) then
5769 g_Debug_Frames := (P[1][1] = '1');
5771 g_Console_Add(Format('d_frames is %d', [Byte(g_Debug_Frames)]));
5772 end
5773 else if cmd = 'd_winmsg' then
5774 begin
5775 if (Length(P) > 1) and
5776 ((P[1] = '1') or (P[1] = '0')) then
5777 g_Debug_WinMsgs := (P[1][1] = '1');
5779 g_Console_Add(Format('d_winmsg is %d', [Byte(g_Debug_WinMsgs)]));
5780 end
5781 else if (cmd = 'd_monoff') and not g_Game_IsNet then
5782 begin
5783 if (Length(P) > 1) and
5784 ((P[1] = '1') or (P[1] = '0')) then
5785 g_Debug_MonsterOff := (P[1][1] = '1');
5787 g_Console_Add(Format('d_monoff is %d', [Byte(g_debug_MonsterOff)]));
5788 end
5789 else if (cmd = 'd_botoff') and not g_Game_IsNet then
5790 begin
5791 if Length(P) > 1 then
5792 case P[1][1] of
5793 '0': g_debug_BotAIOff := 0;
5794 '1': g_debug_BotAIOff := 1;
5795 '2': g_debug_BotAIOff := 2;
5796 '3': g_debug_BotAIOff := 3;
5797 end;
5799 g_Console_Add(Format('d_botoff is %d', [g_debug_BotAIOff]));
5800 end
5801 else if cmd = 'd_monster' then
5802 begin
5803 if gGameOn and (gPlayer1 <> nil) and (gPlayer1.alive) and (not g_Game_IsNet) then
5804 if Length(P) < 2 then
5805 begin
5806 g_Console_Add(cmd + ' [ID | Name] [behaviour]');
5807 g_Console_Add('ID | Name');
5808 for b := MONSTER_DEMON to MONSTER_MAN do
5809 g_Console_Add(Format('%2d | %s', [b, g_Mons_NameByTypeId(b)]));
5810 conwriteln('behav. num'#10'normal 0'#10'killer 1'#10'maniac 2'#10'insane 3'#10'cannibal 4'#10'good 5');
5811 end else
5812 begin
5813 a := StrToIntDef(P[1], 0);
5814 if (a < MONSTER_DEMON) or (a > MONSTER_MAN) then
5815 a := g_Mons_TypeIdByName(P[1]);
5817 if (a < MONSTER_DEMON) or (a > MONSTER_MAN) then
5818 g_Console_Add(Format(_lc[I_MSG_NO_MONSTER], [P[1]]))
5819 else
5820 begin
5821 with gPlayer1.Obj do
5822 begin
5823 mon := g_Monsters_Create(a,
5824 X + Rect.X + (Rect.Width div 2),
5825 Y + Rect.Y + Rect.Height,
5826 gPlayer1.Direction, True);
5827 end;
5828 if (Length(P) > 2) and (mon <> nil) then
5829 begin
5830 if (CompareText(P[2], 'normal') = 0) then mon.MonsterBehaviour := BH_NORMAL
5831 else if (CompareText(P[2], 'killer') = 0) then mon.MonsterBehaviour := BH_KILLER
5832 else if (CompareText(P[2], 'maniac') = 0) then mon.MonsterBehaviour := BH_MANIAC
5833 else if (CompareText(P[2], 'insane') = 0) then mon.MonsterBehaviour := BH_INSANE
5834 else if (CompareText(P[2], 'cannibal') = 0) then mon.MonsterBehaviour := BH_CANNIBAL
5835 else if (CompareText(P[2], 'good') = 0) then mon.MonsterBehaviour := BH_GOOD
5836 else if (CompareText(P[2], 'friend') = 0) then mon.MonsterBehaviour := BH_GOOD
5837 else if (CompareText(P[2], 'friendly') = 0) then mon.MonsterBehaviour := BH_GOOD
5838 else mon.MonsterBehaviour := Min(Max(StrToIntDef(P[2], BH_NORMAL), BH_NORMAL), BH_GOOD);
5839 end;
5840 end;
5841 end;
5842 end
5843 else if (cmd = 'd_health') then
5844 begin
5845 if (Length(P) > 1) and
5846 ((P[1] = '1') or (P[1] = '0')) then
5847 g_debug_HealthBar := (P[1][1] = '1');
5849 g_Console_Add(Format('d_health is %d', [Byte(g_debug_HealthBar)]));
5850 end
5851 else if (cmd = 'd_player') then
5852 begin
5853 if (Length(P) > 1) and
5854 ((P[1] = '1') or (P[1] = '0')) then
5855 g_debug_Player := (P[1][1] = '1');
5857 g_Console_Add(Format(cmd + ' is %d', [Byte(g_Debug_Player)]));
5858 end
5859 else if (cmd = 'd_mem') then
5860 begin
5861 PrintHeapStats();
5862 end;
5863 end
5864 else
5865 g_Console_Add(_lc[I_MSG_NOT_DEBUG]);
5866 end;
5869 procedure GameCheats(P: SSArray);
5870 var
5871 cmd: string;
5872 f, a: Integer;
5873 plr: TPlayer;
5874 begin
5875 if (not gGameOn) or (not conIsCheatsEnabled) then
5876 begin
5877 g_Console_Add('not available');
5878 exit;
5879 end;
5880 plr := gPlayer1;
5881 if plr = nil then
5882 begin
5883 g_Console_Add('where is the player?!');
5884 exit;
5885 end;
5886 cmd := LowerCase(P[0]);
5887 // god
5888 if cmd = 'god' then
5889 begin
5890 plr.GodMode := not plr.GodMode;
5891 if plr.GodMode then g_Console_Add('player is godlike now') else g_Console_Add('player is mortal now');
5892 exit;
5893 end;
5894 // give <health|exit|weapons|air|suit|jetpack|berserk|all>
5895 if cmd = 'give' then
5896 begin
5897 if length(P) < 2 then begin g_Console_Add('give what?!'); exit; end;
5898 for f := 1 to High(P) do
5899 begin
5900 cmd := LowerCase(P[f]);
5901 if cmd = 'health' then begin plr.RestoreHealthArmor(); g_Console_Add('player feels himself better'); continue; end;
5902 if (cmd = 'all') {or (cmd = 'weapons')} then begin plr.AllRulez(False); g_Console_Add('player got the gifts'); continue; end;
5903 if cmd = 'exit' then
5904 begin
5905 if gTriggers <> nil then
5906 begin
5907 for a := 0 to High(gTriggers) do
5908 begin
5909 if gTriggers[a].TriggerType = TRIGGER_EXIT then
5910 begin
5911 g_Console_Add('player left the map');
5912 gExitByTrigger := True;
5913 //g_Game_ExitLevel(gTriggers[a].Data.MapName);
5914 g_Game_ExitLevel(gTriggers[a].tgcMap);
5915 break;
5916 end;
5917 end;
5918 end;
5919 continue;
5920 end;
5922 if cmd = 'air' then begin plr.GiveItem(ITEM_OXYGEN); g_Console_Add('player got some air'); continue; end;
5923 if cmd = 'jetpack' then begin plr.GiveItem(ITEM_JETPACK); g_Console_Add('player got a jetpack'); continue; end;
5924 if cmd = 'suit' then begin plr.GiveItem(ITEM_SUIT); g_Console_Add('player got an envirosuit'); continue; end;
5925 if cmd = 'berserk' then begin plr.GiveItem(ITEM_MEDKIT_BLACK); g_Console_Add('player got a berserk pack'); continue; end;
5926 if cmd = 'backpack' then begin plr.GiveItem(ITEM_AMMO_BACKPACK); g_Console_Add('player got a backpack'); continue; end;
5928 if cmd = 'helmet' then begin plr.GiveItem(ITEM_HELMET); g_Console_Add('player got a helmet'); continue; end;
5929 if cmd = 'bottle' then begin plr.GiveItem(ITEM_BOTTLE); g_Console_Add('player got a bottle of health'); continue; end;
5931 if cmd = 'stimpack' then begin plr.GiveItem(ITEM_MEDKIT_SMALL); g_Console_Add('player got a stimpack'); continue; end;
5932 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;
5934 if cmd = 'greenarmor' then begin plr.GiveItem(ITEM_ARMOR_GREEN); g_Console_Add('player got a security armor'); continue; end;
5935 if cmd = 'bluearmor' then begin plr.GiveItem(ITEM_ARMOR_BLUE); g_Console_Add('player got a combat armor'); continue; end;
5937 if (cmd = 'megasphere') or (cmd = 'mega') then begin plr.GiveItem(ITEM_SPHERE_BLUE); g_Console_Add('player got a megasphere'); continue; end;
5938 if (cmd = 'soulsphere') or (cmd = 'soul')then begin plr.GiveItem(ITEM_SPHERE_WHITE); g_Console_Add('player got a soul sphere'); continue; end;
5940 if (cmd = 'invul') or (cmd = 'invulnerability') then begin plr.GiveItem(ITEM_INVUL); g_Console_Add('player got invulnerability'); continue; end;
5941 if (cmd = 'invis') or (cmd = 'invisibility') then begin plr.GiveItem(ITEM_INVIS); g_Console_Add('player got invisibility'); continue; end;
5943 if cmd = 'redkey' then begin plr.GiveItem(ITEM_KEY_RED); g_Console_Add('player got the red key'); continue; end;
5944 if cmd = 'greenkey' then begin plr.GiveItem(ITEM_KEY_GREEN); g_Console_Add('player got the green key'); continue; end;
5945 if cmd = 'bluekey' then begin plr.GiveItem(ITEM_KEY_BLUE); g_Console_Add('player got the blue key'); continue; end;
5947 if (cmd = 'shotgun') or (cmd = 'sg') then begin plr.GiveItem(ITEM_WEAPON_SHOTGUN1); g_Console_Add('player got a shotgun'); continue; end;
5948 if (cmd = 'supershotgun') or (cmd = 'ssg') then begin plr.GiveItem(ITEM_WEAPON_SHOTGUN2); g_Console_Add('player got a supershotgun'); continue; end;
5949 if cmd = 'chaingun' then begin plr.GiveItem(ITEM_WEAPON_CHAINGUN); g_Console_Add('player got a chaingun'); continue; end;
5950 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;
5951 if cmd = 'plasmagun' then begin plr.GiveItem(ITEM_WEAPON_PLASMA); g_Console_Add('player got a plasma gun'); continue; end;
5952 if cmd = 'bfg' then begin plr.GiveItem(ITEM_WEAPON_BFG); g_Console_Add('player got a BFG-9000'); continue; end;
5954 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;
5955 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;
5956 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;
5957 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;
5958 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;
5959 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;
5961 if cmd = 'superchaingun' then begin plr.GiveItem(ITEM_WEAPON_SUPERPULEMET); g_Console_Add('player got a superchaingun'); continue; end;
5962 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;
5964 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;
5965 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;
5967 if cmd = 'chainsaw' then begin plr.GiveItem(ITEM_WEAPON_SAW); g_Console_Add('player got a chainsaw'); continue; end;
5969 if cmd = 'ammo' then
5970 begin
5971 plr.GiveItem(ITEM_AMMO_SHELLS_BOX);
5972 plr.GiveItem(ITEM_AMMO_BULLETS_BOX);
5973 plr.GiveItem(ITEM_AMMO_CELL_BIG);
5974 plr.GiveItem(ITEM_AMMO_ROCKET_BOX);
5975 plr.GiveItem(ITEM_AMMO_FUELCAN);
5976 g_Console_Add('player got some ammo');
5977 continue;
5978 end;
5980 if cmd = 'clip' then begin plr.GiveItem(ITEM_AMMO_BULLETS); g_Console_Add('player got some bullets'); continue; end;
5981 if cmd = 'bullets' then begin plr.GiveItem(ITEM_AMMO_BULLETS_BOX); g_Console_Add('player got a box of bullets'); continue; end;
5983 if cmd = 'shells' then begin plr.GiveItem(ITEM_AMMO_SHELLS); g_Console_Add('player got some shells'); continue; end;
5984 if cmd = 'shellbox' then begin plr.GiveItem(ITEM_AMMO_SHELLS_BOX); g_Console_Add('player got a box of shells'); continue; end;
5986 if cmd = 'cells' then begin plr.GiveItem(ITEM_AMMO_CELL); g_Console_Add('player got some cells'); continue; end;
5987 if cmd = 'battery' then begin plr.GiveItem(ITEM_AMMO_CELL_BIG); g_Console_Add('player got cell battery'); continue; end;
5989 if cmd = 'rocket' then begin plr.GiveItem(ITEM_AMMO_ROCKET); g_Console_Add('player got a rocket'); continue; end;
5990 if cmd = 'rocketbox' then begin plr.GiveItem(ITEM_AMMO_ROCKET_BOX); g_Console_Add('player got some rockets'); continue; end;
5992 if (cmd = 'fuel') or (cmd = 'fuelcan') then begin plr.GiveItem(ITEM_AMMO_FUELCAN); g_Console_Add('player got fuel canister'); continue; end;
5994 if cmd = 'weapons' then
5995 begin
5996 plr.GiveItem(ITEM_WEAPON_SHOTGUN1);
5997 plr.GiveItem(ITEM_WEAPON_SHOTGUN2);
5998 plr.GiveItem(ITEM_WEAPON_CHAINGUN);
5999 plr.GiveItem(ITEM_WEAPON_ROCKETLAUNCHER);
6000 plr.GiveItem(ITEM_WEAPON_PLASMA);
6001 plr.GiveItem(ITEM_WEAPON_BFG);
6002 g_Console_Add('player got weapons');
6003 continue;
6004 end;
6006 if cmd = 'keys' then
6007 begin
6008 plr.GiveItem(ITEM_KEY_RED);
6009 plr.GiveItem(ITEM_KEY_GREEN);
6010 plr.GiveItem(ITEM_KEY_BLUE);
6011 g_Console_Add('player got all keys');
6012 continue;
6013 end;
6015 g_Console_Add('i don''t know how to give '''+cmd+'''!');
6016 end;
6017 exit;
6018 end;
6019 // open
6020 if cmd = 'open' then
6021 begin
6022 g_Console_Add('player activated sesame');
6023 g_Triggers_OpenAll();
6024 exit;
6025 end;
6026 // fly
6027 if cmd = 'fly' then
6028 begin
6029 gFly := not gFly;
6030 if gFly then g_Console_Add('player feels himself lighter') else g_Console_Add('player lost his wings');
6031 exit;
6032 end;
6033 // noclip
6034 if cmd = 'noclip' then
6035 begin
6036 plr.SwitchNoClip;
6037 g_Console_Add('wall hardeness adjusted');
6038 exit;
6039 end;
6040 // notarget
6041 if cmd = 'notarget' then
6042 begin
6043 plr.NoTarget := not plr.NoTarget;
6044 if plr.NoTarget then g_Console_Add('player hides in shadows') else g_Console_Add('player is brave again');
6045 exit;
6046 end;
6047 // noreload
6048 if cmd = 'noreload' then
6049 begin
6050 plr.NoReload := not plr.NoReload;
6051 if plr.NoReload then g_Console_Add('player is action hero now') else g_Console_Add('player is ordinary man now');
6052 exit;
6053 end;
6054 // speedy
6055 if cmd = 'speedy' then
6056 begin
6057 MAX_RUNVEL := 32-MAX_RUNVEL;
6058 g_Console_Add('speed adjusted');
6059 exit;
6060 end;
6061 // jumpy
6062 if cmd = 'jumpy' then
6063 begin
6064 VEL_JUMP := 30-VEL_JUMP;
6065 g_Console_Add('jump height adjusted');
6066 exit;
6067 end;
6068 // automap
6069 if cmd = 'automap' then
6070 begin
6071 gShowMap := not gShowMap;
6072 if gShowMap then g_Console_Add('player gains second sight') else g_Console_Add('player lost second sight');
6073 exit;
6074 end;
6075 // aimline
6076 if cmd = 'aimline' then
6077 begin
6078 gAimLine := not gAimLine;
6079 if gAimLine then g_Console_Add('player gains laser sight') else g_Console_Add('player lost laser sight');
6080 exit;
6081 end;
6082 end;
6084 procedure GameCommands(P: SSArray);
6085 var
6086 a, b: Integer;
6087 s, pw: String;
6088 chstr: string;
6089 cmd: string;
6090 pl: pTNetClient = nil;
6091 plr: TPlayer;
6092 prt: Word;
6093 nm: Boolean;
6094 listen: LongWord;
6095 begin
6096 // Îáùèå êîìàíäû:
6097 cmd := LowerCase(P[0]);
6098 chstr := '';
6099 if (cmd = 'quit') or
6100 (cmd = 'exit') then
6101 begin
6102 g_Game_Free();
6103 g_Game_Quit();
6104 Exit;
6105 end
6106 else if cmd = 'pause' then
6107 begin
6108 if (g_ActiveWindow = nil) then
6109 g_Game_Pause(not gPauseMain);
6110 end
6111 else if cmd = 'endgame' then
6112 gExit := EXIT_SIMPLE
6113 else if cmd = 'restart' then
6114 begin
6115 if gGameOn or (gState in [STATE_INTERSINGLE, STATE_INTERCUSTOM]) then
6116 begin
6117 if g_Game_IsClient then
6118 begin
6119 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6120 Exit;
6121 end;
6122 g_Game_Restart();
6123 end else
6124 g_Console_Add(_lc[I_MSG_NOT_GAME]);
6125 end
6126 else if cmd = 'kick' then
6127 begin
6128 if g_Game_IsServer then
6129 begin
6130 if Length(P) < 2 then
6131 begin
6132 g_Console_Add('kick <name>');
6133 Exit;
6134 end;
6135 if P[1] = '' then
6136 begin
6137 g_Console_Add('kick <name>');
6138 Exit;
6139 end;
6141 if g_Game_IsNet then
6142 pl := g_Net_Client_ByName(P[1]);
6143 if (pl <> nil) then
6144 begin
6145 s := g_Net_ClientName_ByID(pl^.ID);
6146 enet_peer_disconnect(pl^.Peer, NET_DISC_KICK);
6147 g_Console_Add(Format(_lc[I_PLAYER_KICK], [s]));
6148 MH_SEND_GameEvent(NET_EV_PLAYER_KICK, 0, s);
6149 if NetUseMaster then
6150 g_Net_Slist_Update;
6151 end else if gPlayers <> nil then
6152 for a := Low(gPlayers) to High(gPlayers) do
6153 if gPlayers[a] <> nil then
6154 if Copy(LowerCase(gPlayers[a].Name), 1, Length(P[1])) = LowerCase(P[1]) then
6155 begin
6156 // Íå îòêëþ÷àòü îñíîâíûõ èãðîêîâ â ñèíãëå
6157 if not(gPlayers[a] is TBot) and (gGameSettings.GameType = GT_SINGLE) then
6158 continue;
6159 gPlayers[a].Lives := 0;
6160 gPlayers[a].Kill(K_SIMPLEKILL, 0, HIT_DISCON);
6161 g_Console_Add(Format(_lc[I_PLAYER_LEAVE], [gPlayers[a].Name]), True);
6162 g_Player_Remove(gPlayers[a].UID);
6163 if NetUseMaster then
6164 g_Net_Slist_Update;
6165 // Åñëè íå ïåðåìåøàòü, ïðè äîáàâëåíèè íîâûõ áîòîâ ïîÿâÿòñÿ ñòàðûå
6166 g_Bot_MixNames();
6167 end;
6168 end else
6169 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
6170 end
6171 else if cmd = 'kick_id' then
6172 begin
6173 if g_Game_IsServer and g_Game_IsNet then
6174 begin
6175 if Length(P) < 2 then
6176 begin
6177 g_Console_Add('kick_id <client ID>');
6178 Exit;
6179 end;
6180 if P[1] = '' then
6181 begin
6182 g_Console_Add('kick_id <client ID>');
6183 Exit;
6184 end;
6186 a := StrToIntDef(P[1], 0);
6187 if (NetClients <> nil) and (a <= High(NetClients)) then
6188 begin
6189 if NetClients[a].Used and (NetClients[a].Peer <> nil) then
6190 begin
6191 s := g_Net_ClientName_ByID(NetClients[a].ID);
6192 enet_peer_disconnect(NetClients[a].Peer, NET_DISC_KICK);
6193 g_Console_Add(Format(_lc[I_PLAYER_KICK], [s]));
6194 MH_SEND_GameEvent(NET_EV_PLAYER_KICK, 0, s);
6195 if NetUseMaster then
6196 g_Net_Slist_Update;
6197 end;
6198 end;
6199 end else
6200 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6201 end
6202 else if cmd = 'ban' then
6203 begin
6204 if g_Game_IsServer and g_Game_IsNet then
6205 begin
6206 if Length(P) < 2 then
6207 begin
6208 g_Console_Add('ban <name>');
6209 Exit;
6210 end;
6211 if P[1] = '' then
6212 begin
6213 g_Console_Add('ban <name>');
6214 Exit;
6215 end;
6217 pl := g_Net_Client_ByName(P[1]);
6218 if (pl <> nil) then
6219 begin
6220 s := g_Net_ClientName_ByID(pl^.ID);
6221 g_Net_BanHost(pl^.Peer^.address.host, False);
6222 enet_peer_disconnect(pl^.Peer, NET_DISC_TEMPBAN);
6223 g_Console_Add(Format(_lc[I_PLAYER_BAN], [s]));
6224 MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s);
6225 if NetUseMaster then
6226 g_Net_Slist_Update;
6227 end else
6228 g_Console_Add(Format(_lc[I_NET_ERR_NAME404], [P[1]]));
6229 end else
6230 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6231 end
6232 else if cmd = 'ban_id' then
6233 begin
6234 if g_Game_IsServer and g_Game_IsNet then
6235 begin
6236 if Length(P) < 2 then
6237 begin
6238 g_Console_Add('ban_id <client ID>');
6239 Exit;
6240 end;
6241 if P[1] = '' then
6242 begin
6243 g_Console_Add('ban_id <client ID>');
6244 Exit;
6245 end;
6247 a := StrToIntDef(P[1], 0);
6248 if (NetClients <> nil) and (a <= High(NetClients)) then
6249 if NetClients[a].Used and (NetClients[a].Peer <> nil) then
6250 begin
6251 s := g_Net_ClientName_ByID(NetClients[a].ID);
6252 g_Net_BanHost(NetClients[a].Peer^.address.host, False);
6253 enet_peer_disconnect(NetClients[a].Peer, NET_DISC_TEMPBAN);
6254 g_Console_Add(Format(_lc[I_PLAYER_BAN], [s]));
6255 MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s);
6256 if NetUseMaster then
6257 g_Net_Slist_Update;
6258 end;
6259 end else
6260 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6261 end
6262 else if cmd = 'permban' then
6263 begin
6264 if g_Game_IsServer and g_Game_IsNet then
6265 begin
6266 if Length(P) < 2 then
6267 begin
6268 g_Console_Add('permban <name>');
6269 Exit;
6270 end;
6271 if P[1] = '' then
6272 begin
6273 g_Console_Add('permban <name>');
6274 Exit;
6275 end;
6277 pl := g_Net_Client_ByName(P[1]);
6278 if (pl <> nil) then
6279 begin
6280 s := g_Net_ClientName_ByID(pl^.ID);
6281 g_Net_BanHost(pl^.Peer^.address.host);
6282 enet_peer_disconnect(pl^.Peer, NET_DISC_BAN);
6283 g_Net_SaveBanList();
6284 g_Console_Add(Format(_lc[I_PLAYER_BAN], [s]));
6285 MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s);
6286 if NetUseMaster then
6287 g_Net_Slist_Update;
6288 end else
6289 g_Console_Add(Format(_lc[I_NET_ERR_NAME404], [P[1]]));
6290 end else
6291 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6292 end
6293 else if cmd = 'permban_id' then
6294 begin
6295 if g_Game_IsServer and g_Game_IsNet then
6296 begin
6297 if Length(P) < 2 then
6298 begin
6299 g_Console_Add('permban_id <client ID>');
6300 Exit;
6301 end;
6302 if P[1] = '' then
6303 begin
6304 g_Console_Add('permban_id <client ID>');
6305 Exit;
6306 end;
6308 a := StrToIntDef(P[1], 0);
6309 if (NetClients <> nil) and (a <= High(NetClients)) then
6310 if NetClients[a].Used and (NetClients[a].Peer <> nil) then
6311 begin
6312 s := g_Net_ClientName_ByID(NetClients[a].ID);
6313 g_Net_BanHost(NetClients[a].Peer^.address.host);
6314 enet_peer_disconnect(NetClients[a].Peer, NET_DISC_BAN);
6315 g_Net_SaveBanList();
6316 g_Console_Add(Format(_lc[I_PLAYER_BAN], [s]));
6317 MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s);
6318 if NetUseMaster then
6319 g_Net_Slist_Update;
6320 end;
6321 end else
6322 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6323 end
6324 else if cmd = 'unban' then
6325 begin
6326 if g_Game_IsServer and g_Game_IsNet then
6327 begin
6328 if Length(P) < 2 then
6329 begin
6330 g_Console_Add('unban <IP Address>');
6331 Exit;
6332 end;
6333 if P[1] = '' then
6334 begin
6335 g_Console_Add('unban <IP Address>');
6336 Exit;
6337 end;
6339 if g_Net_UnbanHost(P[1]) then
6340 begin
6341 g_Console_Add(Format(_lc[I_MSG_UNBAN_OK], [P[1]]));
6342 g_Net_SaveBanList();
6343 end else
6344 g_Console_Add(Format(_lc[I_MSG_UNBAN_FAIL], [P[1]]));
6345 end else
6346 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6347 end
6348 else if cmd = 'clientlist' then
6349 begin
6350 if g_Game_IsServer and g_Game_IsNet then
6351 begin
6352 b := 0;
6353 if NetClients <> nil then
6354 for a := Low(NetClients) to High(NetClients) do
6355 if NetClients[a].Used and (NetClients[a].Peer <> nil) then
6356 begin
6357 plr := g_Player_Get(NetClients[a].Player);
6358 if plr = nil then continue;
6359 Inc(b);
6360 g_Console_Add(Format('#%2d: %-15s | %s', [a,
6361 IpToStr(NetClients[a].Peer^.address.host), plr.Name]));
6362 end;
6363 if b = 0 then
6364 g_Console_Add(_lc[I_MSG_NOCLIENTS]);
6365 end else
6366 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6367 end
6368 else if cmd = 'connect' then
6369 begin
6370 if (NetMode = NET_NONE) then
6371 begin
6372 if Length(P) < 2 then
6373 begin
6374 g_Console_Add('connect <IP> [port] [password]');
6375 Exit;
6376 end;
6377 if P[1] = '' then
6378 begin
6379 g_Console_Add('connect <IP> [port] [password]');
6380 Exit;
6381 end;
6383 if Length(P) > 2 then
6384 prt := StrToIntDef(P[2], 25666)
6385 else
6386 prt := 25666;
6388 if Length(P) > 3 then
6389 pw := P[3]
6390 else
6391 pw := '';
6393 g_Game_StartClient(P[1], prt, pw);
6394 end;
6395 end
6396 else if cmd = 'disconnect' then
6397 begin
6398 if (NetMode = NET_CLIENT) then
6399 g_Net_Disconnect();
6400 end
6401 else if cmd = 'reconnect' then
6402 begin
6403 if (NetMode = NET_SERVER) then
6404 Exit;
6406 if (NetMode = NET_CLIENT) then
6407 begin
6408 g_Net_Disconnect();
6409 gExit := EXIT_SIMPLE;
6410 EndGame;
6411 end;
6413 //TODO: Use last successful password to reconnect, instead of ''
6414 g_Game_StartClient(NetClientIP, NetClientPort, '');
6415 end
6416 else if (cmd = 'addbot') or
6417 (cmd = 'bot_add') then
6418 begin
6419 if Length(P) > 2 then
6420 g_Bot_Add(TEAM_NONE, StrToIntDef(P[1], 2), StrToIntDef(P[2], 100))
6421 else if Length(P) > 1 then
6422 g_Bot_Add(TEAM_NONE, StrToIntDef(P[1], 2))
6423 else
6424 g_Bot_Add(TEAM_NONE, 2);
6425 end
6426 else if cmd = 'bot_addlist' then
6427 begin
6428 if Length(P) > 1 then
6429 begin
6430 if Length(P) = 2 then
6431 g_Bot_AddList(TEAM_NONE, P[1], StrToIntDef(P[1], -1))
6432 else if Length(P) = 3 then
6433 g_Bot_AddList(TEAM_NONE, P[1], StrToIntDef(P[1], -1), StrToIntDef(P[2], 100))
6434 else
6435 g_Bot_AddList(IfThen(P[2] = 'red', TEAM_RED, TEAM_BLUE), P[1], StrToIntDef(P[1], -1));
6436 end;
6437 end
6438 else if cmd = 'bot_removeall' then
6439 g_Bot_RemoveAll()
6440 else if cmd = 'chat' then
6441 begin
6442 if g_Game_IsNet then
6443 begin
6444 if Length(P) > 1 then
6445 begin
6446 for a := 1 to High(P) do
6447 chstr := chstr + P[a] + ' ';
6449 if Length(chstr) > 200 then SetLength(chstr, 200);
6451 if Length(chstr) < 1 then
6452 begin
6453 g_Console_Add('chat <text>');
6454 Exit;
6455 end;
6457 chstr := b_Text_Format(chstr);
6458 if g_Game_IsClient then
6459 MC_SEND_Chat(chstr, NET_CHAT_PLAYER)
6460 else
6461 MH_SEND_Chat(gPlayer1Settings.Name + ': ' + chstr, NET_CHAT_PLAYER);
6462 end
6463 else
6464 g_Console_Add('chat <text>');
6465 end else
6466 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
6467 end
6468 else if cmd = 'teamchat' then
6469 begin
6470 if g_Game_IsNet and (gGameSettings.GameMode in [GM_TDM, GM_CTF]) then
6471 begin
6472 if Length(P) > 1 then
6473 begin
6474 for a := 1 to High(P) do
6475 chstr := chstr + P[a] + ' ';
6477 if Length(chstr) > 200 then SetLength(chstr, 200);
6479 if Length(chstr) < 1 then
6480 begin
6481 g_Console_Add('teamchat <text>');
6482 Exit;
6483 end;
6485 chstr := b_Text_Format(chstr);
6486 if g_Game_IsClient then
6487 MC_SEND_Chat(chstr, NET_CHAT_TEAM)
6488 else
6489 MH_SEND_Chat(gPlayer1Settings.Name + ': ' + chstr, NET_CHAT_TEAM,
6490 gPlayer1Settings.Team);
6491 end
6492 else
6493 g_Console_Add('teamchat <text>');
6494 end else
6495 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
6496 end
6497 else if cmd = 'game' then
6498 begin
6499 if gGameSettings.GameType <> GT_NONE then
6500 begin
6501 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
6502 Exit;
6503 end;
6504 if Length(P) = 1 then
6505 begin
6506 g_Console_Add(cmd + ' <WAD> [MAP] [# players]');
6507 Exit;
6508 end;
6509 // Èãðà åù¸ íå çàïóùåíà, ñíà÷àëà íàì íàäî çàãðóçèòü êàêîé-òî WAD
6510 P[1] := addWadExtension(P[1]);
6511 if FileExists(MapsDir + P[1]) then
6512 begin
6513 // Åñëè êàðòà íå óêàçàíà, áåð¸ì ïåðâóþ êàðòó â ôàéëå
6514 if Length(P) < 3 then
6515 begin
6516 SetLength(P, 3);
6517 P[2] := g_Game_GetFirstMap(MapsDir + P[1]);
6518 end;
6520 s := P[1] + ':\' + UpperCase(P[2]);
6522 if g_Map_Exist(MapsDir + s) then
6523 begin
6524 // Çàïóñêàåì ñâîþ èãðó
6525 g_Game_Free();
6526 with gGameSettings do
6527 begin
6528 GameMode := g_Game_TextToMode(gcGameMode);
6529 if gSwitchGameMode <> GM_NONE then
6530 GameMode := gSwitchGameMode;
6531 if GameMode = GM_NONE then GameMode := GM_DM;
6532 if GameMode = GM_SINGLE then GameMode := GM_COOP;
6533 b := 1;
6534 if Length(P) >= 4 then
6535 b := StrToIntDef(P[3], 1);
6536 g_Game_StartCustom(s, GameMode, TimeLimit,
6537 GoalLimit, MaxLives, Options, b);
6538 end;
6539 end
6540 else
6541 if P[2] = '' then
6542 g_Console_Add(Format(_lc[I_MSG_NO_MAPS], [P[1]]))
6543 else
6544 g_Console_Add(Format(_lc[I_MSG_NO_MAP_FALLBACK], [UpperCase(P[2]), P[1]]));
6545 end else
6546 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]));
6547 end
6548 else if cmd = 'host' then
6549 begin
6550 if gGameSettings.GameType <> GT_NONE then
6551 begin
6552 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
6553 Exit;
6554 end;
6555 if Length(P) < 4 then
6556 begin
6557 g_Console_Add(cmd + ' <listen IP> <port> <WAD> [MAP] [# players]');
6558 Exit;
6559 end;
6560 if not StrToIp(P[1], listen) then
6561 Exit;
6562 prt := StrToIntDef(P[2], 25666);
6564 P[3] := addWadExtension(P[3]);
6565 if FileExists(MapsDir + P[3]) then
6566 begin
6567 // Åñëè êàðòà íå óêàçàíà, áåð¸ì ïåðâóþ êàðòó â ôàéëå
6568 if Length(P) < 5 then
6569 begin
6570 SetLength(P, 5);
6571 P[4] := g_Game_GetFirstMap(MapsDir + P[1]);
6572 end;
6574 s := P[3] + ':\' + UpperCase(P[4]);
6576 if g_Map_Exist(MapsDir + s) then
6577 begin
6578 // Çàïóñêàåì ñâîþ èãðó
6579 g_Game_Free();
6580 with gGameSettings do
6581 begin
6582 GameMode := g_Game_TextToMode(gcGameMode);
6583 if gSwitchGameMode <> GM_NONE then
6584 GameMode := gSwitchGameMode;
6585 if GameMode = GM_NONE then GameMode := GM_DM;
6586 if GameMode = GM_SINGLE then GameMode := GM_COOP;
6587 b := 0;
6588 if Length(P) >= 6 then
6589 b := StrToIntDef(P[5], 0);
6590 g_Game_StartServer(s, GameMode, TimeLimit,
6591 GoalLimit, MaxLives, Options, b, listen, prt);
6592 end;
6593 end
6594 else
6595 if P[4] = '' then
6596 g_Console_Add(Format(_lc[I_MSG_NO_MAPS], [P[3]]))
6597 else
6598 g_Console_Add(Format(_lc[I_MSG_NO_MAP_FALLBACK], [UpperCase(P[4]), P[3]]));
6599 end else
6600 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[3]]));
6601 end
6602 else if cmd = 'map' then
6603 begin
6604 if Length(P) = 1 then
6605 begin
6606 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
6607 begin
6608 g_Console_Add(cmd + ' <MAP>');
6609 g_Console_Add(cmd + ' <WAD> [MAP]');
6610 end else
6611 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
6612 end else
6613 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
6614 begin
6615 // Èä¸ò ñâîÿ èãðà èëè ñåðâåð
6616 if Length(P) < 3 then
6617 begin
6618 // Ïåðâûé ïàðàìåòð - ëèáî êàðòà, ëèáî èìÿ WAD ôàéëà
6619 s := UpperCase(P[1]);
6620 if g_Map_Exist(MapsDir + gGameSettings.WAD + ':\' + s) then
6621 begin // Êàðòà íàøëàñü
6622 gExitByTrigger := False;
6623 if gGameOn then
6624 begin // Èä¸ò èãðà - çàâåðøàåì óðîâåíü
6625 gNextMap := s;
6626 gExit := EXIT_ENDLEVELCUSTOM;
6627 end
6628 else // Èíòåðìèññèÿ - ñðàçó çàãðóæàåì êàðòó
6629 g_Game_ChangeMap(s);
6630 end else
6631 begin
6632 // Òàêîé êàðòû íåò, èùåì WAD ôàéë
6633 pw := findDiskWad(MapsDir + P[1]);
6634 g_Console_Add(Format(_lc[I_MSG_NO_MAP_FALLBACK], [s, 'WAD ' + P[1]]));
6635 if FileExists(pw) then
6636 begin
6637 // Ïàðàìåòðà êàðòû íåò, ïîýòîìó ñòàâèì ïåðâóþ èç ôàéëà
6638 SetLength(P, 3);
6639 P[1] := ExtractRelativePath(MapsDir, pw);
6640 P[2] := g_Game_GetFirstMap(MapsDir + P[1]);
6642 s := P[1] + ':\' + P[2];
6644 if g_Map_Exist(MapsDir + s) then
6645 begin
6646 gExitByTrigger := False;
6647 if gGameOn then
6648 begin // Èä¸ò èãðà - çàâåðøàåì óðîâåíü
6649 gNextMap := s;
6650 gExit := EXIT_ENDLEVELCUSTOM;
6651 end
6652 else // Èíòåðìèññèÿ - ñðàçó çàãðóæàåì êàðòó
6653 g_Game_ChangeMap(s);
6654 end else
6655 if P[2] = '' then
6656 g_Console_Add(Format(_lc[I_MSG_NO_MAPS], [P[1]]))
6657 else
6658 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [P[2]]));
6659 end else
6660 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]));
6661 end;
6662 end else
6663 begin
6664 // Óêàçàíî äâà ïàðàìåòðà, çíà÷èò ïåðâûé - WAD ôàéë, à âòîðîé - êàðòà
6665 P[1] := addWadExtension(P[1]);
6666 if FileExists(MapsDir + P[1]) then
6667 begin
6668 // Íàøëè WAD ôàéë
6669 P[2] := UpperCase(P[2]);
6670 s := P[1] + ':\' + P[2];
6672 if g_Map_Exist(MapsDir + s) then
6673 begin // Íàøëè êàðòó
6674 gExitByTrigger := False;
6675 if gGameOn then
6676 begin // Èä¸ò èãðà - çàâåðøàåì óðîâåíü
6677 gNextMap := s;
6678 gExit := EXIT_ENDLEVELCUSTOM;
6679 end
6680 else // Èíòåðìèññèÿ - ñðàçó çàãðóæàåì êàðòó
6681 g_Game_ChangeMap(s);
6682 end else
6683 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [P[2]]));
6684 end else
6685 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]));
6686 end;
6687 end else
6688 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
6689 end
6690 else if cmd = 'nextmap' then
6691 begin
6692 if not(gGameOn or (gState = STATE_INTERCUSTOM)) then
6693 g_Console_Add(_lc[I_MSG_NOT_GAME])
6694 else begin
6695 nm := True;
6696 if Length(P) = 1 then
6697 begin
6698 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
6699 begin
6700 g_Console_Add(cmd + ' <MAP>');
6701 g_Console_Add(cmd + ' <WAD> [MAP]');
6702 end else begin
6703 nm := False;
6704 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
6705 end;
6706 end else
6707 begin
6708 nm := False;
6709 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
6710 begin
6711 if Length(P) < 3 then
6712 begin
6713 // Ïåðâûé ïàðàìåòð - ëèáî êàðòà, ëèáî èìÿ WAD ôàéëà
6714 s := UpperCase(P[1]);
6715 if g_Map_Exist(MapsDir + gGameSettings.WAD + ':\' + s) then
6716 begin // Êàðòà íàøëàñü
6717 gExitByTrigger := False;
6718 gNextMap := s;
6719 nm := True;
6720 end else
6721 begin
6722 // Òàêîé êàðòû íåò, èùåì WAD ôàéë
6723 P[1] := addWadExtension(P[1]);
6724 g_Console_Add(Format(_lc[I_MSG_NO_MAP_FALLBACK], [s, P[1]]));
6725 if FileExists(MapsDir + P[1]) then
6726 begin
6727 // Ïàðàìåòðà êàðòû íåò, ïîýòîìó ñòàâèì ïåðâóþ èç ôàéëà
6728 SetLength(P, 3);
6729 P[2] := g_Game_GetFirstMap(MapsDir + P[1]);
6731 s := P[1] + ':\' + P[2];
6733 if g_Map_Exist(MapsDir + s) then
6734 begin // Óñòàíàâëèâàåì êàðòó
6735 gExitByTrigger := False;
6736 gNextMap := s;
6737 nm := True;
6738 end else
6739 if P[2] = '' then
6740 g_Console_Add(Format(_lc[I_MSG_NO_MAPS], [P[1]]))
6741 else
6742 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [P[2]]));
6743 end else
6744 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]));
6745 end;
6746 end else
6747 begin
6748 // Óêàçàíî äâà ïàðàìåòðà, çíà÷èò ïåðâûé - WAD ôàéë, à âòîðîé - êàðòà
6749 P[1] := addWadExtension(P[1]);
6750 if FileExists(MapsDir + P[1]) then
6751 begin
6752 // Íàøëè WAD ôàéë
6753 P[2] := UpperCase(P[2]);
6754 s := P[1] + ':\' + P[2];
6756 if g_Map_Exist(MapsDir + s) then
6757 begin // Íàøëè êàðòó
6758 gExitByTrigger := False;
6759 gNextMap := s;
6760 nm := True;
6761 end else
6762 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [P[2]]));
6763 end else
6764 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]));
6765 end;
6766 end else
6767 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
6768 end;
6769 if nm then
6770 if gNextMap = '' then
6771 g_Console_Add(_lc[I_MSG_NEXTMAP_UNSET])
6772 else
6773 g_Console_Add(Format(_lc[I_MSG_NEXTMAP_SET], [gNextMap]));
6774 end;
6775 end
6776 else if (cmd = 'endmap') or (cmd = 'goodbye') then
6777 begin
6778 if not gGameOn then
6779 g_Console_Add(_lc[I_MSG_NOT_GAME])
6780 else
6781 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
6782 begin
6783 gExitByTrigger := False;
6784 // Ñëåäóþùàÿ êàðòà íå çàäàíà, ïðîáóåì íàéòè òðèããåð Âûõîä
6785 if (gNextMap = '') and (gTriggers <> nil) then
6786 for a := 0 to High(gTriggers) do
6787 if gTriggers[a].TriggerType = TRIGGER_EXIT then
6788 begin
6789 gExitByTrigger := True;
6790 //gNextMap := gTriggers[a].Data.MapName;
6791 gNextMap := gTriggers[a].tgcMap;
6792 Break;
6793 end;
6794 // Èùåì ñëåäóþùóþ êàðòó â WAD ôàéëå
6795 if gNextMap = '' then
6796 gNextMap := g_Game_GetNextMap();
6797 // Ïðîâåðÿåì, íå çàäàí ëè WAD ôàéë ðåñóðñíîé ñòðîêîé
6798 if not isWadPath(gNextMap) then
6799 s := gGameSettings.WAD + ':\' + gNextMap
6800 else
6801 s := gNextMap;
6802 // Åñëè êàðòà íàéäåíà, âûõîäèì ñ óðîâíÿ
6803 if g_Map_Exist(MapsDir + s) then
6804 gExit := EXIT_ENDLEVELCUSTOM
6805 else
6806 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [gNextMap]));
6807 end else
6808 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
6809 end
6810 else if (cmd = 'event') then
6811 begin
6812 if (Length(P) <= 1) then
6813 begin
6814 for a := 0 to High(gEvents) do
6815 if gEvents[a].Command = '' then
6816 g_Console_Add(gEvents[a].Name + ' <none>')
6817 else
6818 g_Console_Add(gEvents[a].Name + ' "' + gEvents[a].Command + '"');
6819 Exit;
6820 end;
6821 if (Length(P) = 2) then
6822 begin
6823 for a := 0 to High(gEvents) do
6824 if gEvents[a].Name = P[1] then
6825 if gEvents[a].Command = '' then
6826 g_Console_Add(gEvents[a].Name + ' <none>')
6827 else
6828 g_Console_Add(gEvents[a].Name + ' "' + gEvents[a].Command + '"');
6829 Exit;
6830 end;
6831 for a := 0 to High(gEvents) do
6832 if gEvents[a].Name = P[1] then
6833 begin
6834 gEvents[a].Command := '';
6835 for b := 2 to High(P) do
6836 if Pos(' ', P[b]) = 0 then
6837 gEvents[a].Command := gEvents[a].Command + ' ' + P[b]
6838 else
6839 gEvents[a].Command := gEvents[a].Command + ' "' + P[b] + '"';
6840 gEvents[a].Command := Trim(gEvents[a].Command);
6841 Exit;
6842 end;
6843 end
6844 else if cmd = 'suicide' then
6845 begin
6846 if gGameOn then
6847 begin
6848 if g_Game_IsClient then
6849 MC_SEND_CheatRequest(NET_CHEAT_SUICIDE)
6850 else
6851 begin
6852 if gPlayer1 <> nil then
6853 gPlayer1.Damage(SUICIDE_DAMAGE, gPlayer1.UID, 0, 0, HIT_SELF);
6854 if gPlayer2 <> nil then
6855 gPlayer2.Damage(SUICIDE_DAMAGE, gPlayer2.UID, 0, 0, HIT_SELF);
6856 end;
6857 end;
6858 end
6859 else if cmd = 'screenshot' then
6860 begin
6861 g_TakeScreenShot()
6862 end
6863 else if cmd = 'weapon' then
6864 begin
6865 if Length(p) = 2 then
6866 begin
6867 a := WP_FIRST + StrToInt(p[1]) - 1;
6868 if (a >= WP_FIRST) and (a <= WP_LAST) then
6869 gSelectWeapon[0, a] := True
6870 end
6871 end
6872 else if (cmd = 'p1_weapon') or (cmd = 'p2_weapon') then
6873 begin
6874 if Length(p) = 2 then
6875 begin
6876 a := WP_FIRST + StrToInt(p[1]) - 1;
6877 b := ord(cmd[2]) - ord('1');
6878 if (a >= WP_FIRST) and (a <= WP_LAST) then
6879 gSelectWeapon[b, a] := True
6880 end
6881 end
6882 // Êîìàíäû Ñâîåé èãðû:
6883 else if gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT] then
6884 begin
6885 if cmd = 'bot_addred' then
6886 begin
6887 if Length(P) > 1 then
6888 g_Bot_Add(TEAM_RED, StrToIntDef(P[1], 2))
6889 else
6890 g_Bot_Add(TEAM_RED, 2);
6891 end
6892 else if cmd = 'bot_addblue' then
6893 begin
6894 if Length(P) > 1 then
6895 g_Bot_Add(TEAM_BLUE, StrToIntDef(P[1], 2))
6896 else
6897 g_Bot_Add(TEAM_BLUE, 2);
6898 end
6899 else if cmd = 'spectate' then
6900 begin
6901 if not gGameOn then
6902 Exit;
6903 g_Game_Spectate();
6904 end
6905 else if cmd = 'say' then
6906 begin
6907 if g_Game_IsServer and g_Game_IsNet then
6908 begin
6909 if Length(P) > 1 then
6910 begin
6911 chstr := '';
6912 for a := 1 to High(P) do
6913 chstr := chstr + P[a] + ' ';
6915 if Length(chstr) > 200 then SetLength(chstr, 200);
6917 if Length(chstr) < 1 then
6918 begin
6919 g_Console_Add('say <text>');
6920 Exit;
6921 end;
6923 chstr := b_Text_Format(chstr);
6924 MH_SEND_Chat(chstr, NET_CHAT_PLAYER);
6925 end
6926 else g_Console_Add('say <text>');
6927 end else
6928 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6929 end
6930 else if cmd = 'tell' then
6931 begin
6932 if g_Game_IsServer and g_Game_IsNet then
6933 begin
6934 if (Length(P) > 2) and (P[1] <> '') then
6935 begin
6936 chstr := '';
6937 for a := 2 to High(P) do
6938 chstr := chstr + P[a] + ' ';
6940 if Length(chstr) > 200 then SetLength(chstr, 200);
6942 if Length(chstr) < 1 then
6943 begin
6944 g_Console_Add('tell <playername> <text>');
6945 Exit;
6946 end;
6948 pl := g_Net_Client_ByName(P[1]);
6949 if pl <> nil then
6950 MH_SEND_Chat(b_Text_Format(chstr), NET_CHAT_PLAYER, pl^.ID)
6951 else
6952 g_Console_Add(Format(_lc[I_NET_ERR_NAME404], [P[1]]));
6953 end
6954 else g_Console_Add('tell <playername> <text>');
6955 end else
6956 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6957 end
6958 else if (cmd = 'overtime') and not g_Game_IsClient then
6959 begin
6960 if (Length(P) = 1) or (StrToIntDef(P[1], -1) <= 0) then
6961 Exit;
6962 // Äîïîëíèòåëüíîå âðåìÿ:
6963 gGameSettings.TimeLimit := (gTime - gGameStartTime) div 1000 + Word(StrToIntDef(P[1], 0));
6965 g_Console_Add(Format(_lc[I_MSG_TIME_LIMIT],
6966 [gGameSettings.TimeLimit div 3600,
6967 (gGameSettings.TimeLimit div 60) mod 60,
6968 gGameSettings.TimeLimit mod 60]));
6969 if g_Game_IsNet then MH_SEND_GameSettings;
6970 end
6971 else if (cmd = 'rcon_password') and g_Game_IsClient then
6972 begin
6973 if (Length(P) <= 1) then
6974 g_Console_Add('rcon_password <password>')
6975 else
6976 MC_SEND_RCONPassword(P[1]);
6977 end
6978 else if cmd = 'rcon' then
6979 begin
6980 if g_Game_IsClient then
6981 begin
6982 if Length(P) > 1 then
6983 begin
6984 chstr := '';
6985 for a := 1 to High(P) do
6986 chstr := chstr + P[a] + ' ';
6988 if Length(chstr) > 200 then SetLength(chstr, 200);
6990 if Length(chstr) < 1 then
6991 begin
6992 g_Console_Add('rcon <command>');
6993 Exit;
6994 end;
6996 MC_SEND_RCONCommand(chstr);
6997 end
6998 else g_Console_Add('rcon <command>');
6999 end;
7000 end
7001 else if cmd = 'ready' then
7002 begin
7003 if g_Game_IsServer and (gLMSRespawn = LMS_RESPAWN_WARMUP) then
7004 gLMSRespawnTime := gTime + 100;
7005 end
7006 else if (cmd = 'callvote') and g_Game_IsNet then
7007 begin
7008 if Length(P) > 1 then
7009 begin
7010 chstr := '';
7011 for a := 1 to High(P) do begin
7012 if a > 1 then chstr := chstr + ' ';
7013 chstr := chstr + P[a];
7014 end;
7016 if Length(chstr) > 200 then SetLength(chstr, 200);
7018 if Length(chstr) < 1 then
7019 begin
7020 g_Console_Add('callvote <command>');
7021 Exit;
7022 end;
7024 if g_Game_IsClient then
7025 MC_SEND_Vote(True, chstr)
7026 else
7027 g_Game_StartVote(chstr, gPlayer1Settings.Name);
7028 g_Console_Process('vote', True);
7029 end
7030 else
7031 g_Console_Add('callvote <command>');
7032 end
7033 else if (cmd = 'vote') and g_Game_IsNet then
7034 begin
7035 if g_Game_IsClient then
7036 MC_SEND_Vote(False)
7037 else if gVoteInProgress then
7038 begin
7039 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
7040 a := Floor((NetClientCount+1)/2.0) + 1
7041 else
7042 a := Floor(NetClientCount/2.0) + 1;
7043 if gVoted then
7044 begin
7045 Dec(gVoteCount);
7046 gVoted := False;
7047 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_REVOKED], [gPlayer1Settings.Name, gVoteCount, a]), True);
7048 MH_SEND_VoteEvent(NET_VE_REVOKE, gPlayer1Settings.Name, 'a', gVoteCount, a);
7049 end
7050 else
7051 begin
7052 Inc(gVoteCount);
7053 gVoted := True;
7054 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_VOTE], [gPlayer1Settings.Name, gVoteCount, a]), True);
7055 MH_SEND_VoteEvent(NET_VE_VOTE, gPlayer1Settings.Name, 'a', gVoteCount, a);
7056 g_Game_CheckVote;
7057 end;
7058 end;
7059 end
7060 end;
7061 end;
7063 procedure g_TakeScreenShot();
7064 var
7065 a: Word;
7066 FileName: string;
7067 ssdir, t: string;
7068 st: TStream;
7069 ok: Boolean;
7070 begin
7071 if e_NoGraphics then Exit;
7072 ssdir := GameDir+'/screenshots';
7073 if not findFileCI(ssdir, true) then
7074 begin
7075 // try to create dir
7076 try
7077 CreateDir(ssdir);
7078 except
7079 end;
7080 if not findFileCI(ssdir, true) then exit; // alas
7081 end;
7082 try
7083 for a := 1 to High(Word) do
7084 begin
7085 FileName := Format(ssdir+'screenshot%.3d.png', [a]);
7086 t := FileName;
7087 if findFileCI(t, true) then continue;
7088 if not findFileCI(FileName) then
7089 begin
7090 ok := false;
7091 st := createDiskFile(FileName);
7092 try
7093 e_MakeScreenshot(st, gScreenWidth, gScreenHeight);
7094 ok := true;
7095 finally
7096 st.Free();
7097 end;
7098 if not ok then try DeleteFile(FileName); except end else g_Console_Add(Format(_lc[I_CONSOLE_SCREENSHOT], [ExtractFileName(FileName)]));
7099 break;
7100 end;
7101 end;
7102 except
7103 end;
7104 end;
7106 procedure g_Game_InGameMenu(Show: Boolean);
7107 begin
7108 if (g_ActiveWindow = nil) and Show then
7109 begin
7110 if gGameSettings.GameType = GT_SINGLE then
7111 g_GUI_ShowWindow('GameSingleMenu')
7112 else
7113 begin
7114 if g_Game_IsClient then
7115 g_GUI_ShowWindow('GameClientMenu')
7116 else
7117 if g_Game_IsNet then
7118 g_GUI_ShowWindow('GameServerMenu')
7119 else
7120 g_GUI_ShowWindow('GameCustomMenu');
7121 end;
7122 g_Sound_PlayEx('MENU_OPEN');
7124 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
7125 if (not g_Game_IsNet) then
7126 g_Game_Pause(True);
7127 end
7128 else
7129 if (g_ActiveWindow <> nil) and (not Show) then
7130 begin
7131 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
7132 if (not g_Game_IsNet) then
7133 g_Game_Pause(False);
7134 end;
7135 end;
7137 procedure g_Game_Pause (Enable: Boolean);
7138 var
7139 oldPause: Boolean;
7140 begin
7141 if not gGameOn then exit;
7143 if not (gGameSettings.GameType in [GT_SINGLE, GT_CUSTOM]) then exit;
7145 oldPause := gPause;
7146 gPauseMain := Enable;
7148 if (gPause <> oldPause) then g_Game_PauseAllSounds(gPause);
7149 end;
7151 procedure g_Game_HolmesPause (Enable: Boolean);
7152 var
7153 oldPause: Boolean;
7154 begin
7155 if not gGameOn then exit;
7156 if not (gGameSettings.GameType in [GT_SINGLE, GT_CUSTOM]) then exit;
7158 oldPause := gPause;
7159 gPauseHolmes := Enable;
7161 if (gPause <> oldPause) then g_Game_PauseAllSounds(gPause);
7162 end;
7164 procedure g_Game_PauseAllSounds(Enable: Boolean);
7165 var
7166 i: Integer;
7167 begin
7168 // Òðèããåðû:
7169 if gTriggers <> nil then
7170 for i := 0 to High(gTriggers) do
7171 with gTriggers[i] do
7172 if (TriggerType = TRIGGER_SOUND) and
7173 (Sound <> nil) and
7174 Sound.IsPlaying() then
7175 begin
7176 Sound.Pause(Enable);
7177 end;
7179 // Çâóêè èãðîêîâ:
7180 if gPlayers <> nil then
7181 for i := 0 to High(gPlayers) do
7182 if gPlayers[i] <> nil then
7183 gPlayers[i].PauseSounds(Enable);
7185 // Ìóçûêà:
7186 if gMusic <> nil then
7187 gMusic.Pause(Enable);
7188 end;
7190 procedure g_Game_StopAllSounds(all: Boolean);
7191 var
7192 i: Integer;
7193 begin
7194 if gTriggers <> nil then
7195 for i := 0 to High(gTriggers) do
7196 with gTriggers[i] do
7197 if (TriggerType = TRIGGER_SOUND) and
7198 (Sound <> nil) then
7199 Sound.Stop();
7201 if gMusic <> nil then
7202 gMusic.Stop();
7204 if all then
7205 e_StopChannels();
7206 end;
7208 procedure g_Game_UpdateTriggerSounds();
7209 var
7210 i: Integer;
7211 begin
7212 if gTriggers <> nil then
7213 for i := 0 to High(gTriggers) do
7214 with gTriggers[i] do
7215 if (TriggerType = TRIGGER_SOUND) and
7216 (Sound <> nil) and
7217 (tgcLocal) and
7218 Sound.IsPlaying() then
7219 begin
7220 if ((gPlayer1 <> nil) and g_CollidePoint(gPlayer1.GameX, gPlayer1.GameY, X, Y, Width, Height)) or
7221 ((gPlayer2 <> nil) and g_CollidePoint(gPlayer2.GameX, gPlayer2.GameY, X, Y, Width, Height)) then
7222 begin
7223 Sound.SetPan(0.5 - tgcPan/255.0);
7224 Sound.SetVolume(tgcVolume/255.0);
7225 end
7226 else
7227 Sound.SetCoords(X+(Width div 2), Y+(Height div 2), tgcVolume/255.0);
7228 end;
7229 end;
7231 function g_Game_IsWatchedPlayer(UID: Word): Boolean;
7232 begin
7233 Result := False;
7234 if (gPlayer1 <> nil) and (gPlayer1.UID = UID) then
7235 begin
7236 Result := True;
7237 Exit;
7238 end;
7239 if (gPlayer2 <> nil) and (gPlayer2.UID = UID) then
7240 begin
7241 Result := True;
7242 Exit;
7243 end;
7244 if gSpectMode <> SPECT_PLAYERS then
7245 Exit;
7246 if gSpectPID1 = UID then
7247 begin
7248 Result := True;
7249 Exit;
7250 end;
7251 if gSpectViewTwo and (gSpectPID2 = UID) then
7252 begin
7253 Result := True;
7254 Exit;
7255 end;
7256 end;
7258 function g_Game_IsWatchedTeam(Team: Byte): Boolean;
7259 var
7260 Pl: TPlayer;
7261 begin
7262 Result := False;
7263 if (gPlayer1 <> nil) and (gPlayer1.Team = Team) then
7264 begin
7265 Result := True;
7266 Exit;
7267 end;
7268 if (gPlayer2 <> nil) and (gPlayer2.Team = Team) then
7269 begin
7270 Result := True;
7271 Exit;
7272 end;
7273 if gSpectMode <> SPECT_PLAYERS then
7274 Exit;
7275 Pl := g_Player_Get(gSpectPID1);
7276 if (Pl <> nil) and (Pl.Team = Team) then
7277 begin
7278 Result := True;
7279 Exit;
7280 end;
7281 if gSpectViewTwo then
7282 begin
7283 Pl := g_Player_Get(gSpectPID2);
7284 if (Pl <> nil) and (Pl.Team = Team) then
7285 begin
7286 Result := True;
7287 Exit;
7288 end;
7289 end;
7290 end;
7292 procedure g_Game_Message(Msg: string; Time: Word);
7293 begin
7294 MessageLineLength := (gScreenWidth - 204) div e_CharFont_GetMaxWidth(gMenuFont);
7295 MessageText := b_Text_Wrap(b_Text_Format(Msg), MessageLineLength);
7296 MessageTime := Time;
7297 end;
7299 procedure g_Game_ChatSound(Text: String; Taunt: Boolean = True);
7300 const
7301 punct: Array[0..13] of String =
7302 ('.', ',', ':', ';', '!', '?', '(', ')', '''', '"', '/', '\', '*', '^');
7303 var
7304 i, j: Integer;
7305 ok: Boolean;
7306 fpText: String;
7308 function IsPunctuation(S: String): Boolean;
7309 var
7310 i: Integer;
7311 begin
7312 Result := False;
7313 if Length(S) <> 1 then
7314 Exit;
7315 for i := Low(punct) to High(punct) do
7316 if S = punct[i] then
7317 begin
7318 Result := True;
7319 break;
7320 end;
7321 end;
7322 function FilterPunctuation(S: String): String;
7323 var
7324 i: Integer;
7325 begin
7326 for i := Low(punct) to High(punct) do
7327 S := StringReplace(S, punct[i], ' ', [rfReplaceAll]);
7328 Result := S;
7329 end;
7330 begin
7331 ok := False;
7333 if gUseChatSounds and Taunt and (gChatSounds <> nil) and (Pos(': ', Text) > 0) then
7334 begin
7335 // remove player name
7336 Delete(Text, 1, Pos(': ', Text) + 2 - 1);
7337 // for FullWord check
7338 Text := toLowerCase1251(' ' + Text + ' ');
7339 fpText := FilterPunctuation(Text);
7341 for i := 0 to Length(gChatSounds) - 1 do
7342 begin
7343 ok := True;
7344 for j := 0 to Length(gChatSounds[i].Tags) - 1 do
7345 begin
7346 if gChatSounds[i].FullWord and (not IsPunctuation(gChatSounds[i].Tags[j])) then
7347 ok := Pos(' ' + gChatSounds[i].Tags[j] + ' ', fpText) > 0
7348 else
7349 ok := Pos(gChatSounds[i].Tags[j], Text) > 0;
7350 if not ok then
7351 break;
7352 end;
7353 if ok then
7354 begin
7355 gChatSounds[i].Sound.Play();
7356 break;
7357 end;
7358 end;
7359 end;
7360 if not ok then
7361 g_Sound_PlayEx('SOUND_GAME_RADIO');
7362 end;
7364 procedure g_Game_Announce_GoodShot(SpawnerUID: Word);
7365 var
7366 a: Integer;
7367 begin
7368 case gAnnouncer of
7369 ANNOUNCE_NONE:
7370 Exit;
7371 ANNOUNCE_ME,
7372 ANNOUNCE_MEPLUS:
7373 if not g_Game_IsWatchedPlayer(SpawnerUID) then
7374 Exit;
7375 end;
7376 for a := 0 to 3 do
7377 if goodsnd[a].IsPlaying() then
7378 Exit;
7380 goodsnd[Random(4)].Play();
7381 end;
7383 procedure g_Game_Announce_KillCombo(Param: Integer);
7384 var
7385 UID: Word;
7386 c, n: Byte;
7387 Pl: TPlayer;
7388 Name: String;
7389 begin
7390 UID := Param and $FFFF;
7391 c := Param shr 16;
7392 if c < 2 then
7393 Exit;
7395 Pl := g_Player_Get(UID);
7396 if Pl = nil then
7397 Name := '?'
7398 else
7399 Name := Pl.Name;
7401 case c of
7402 2: begin
7403 n := 0;
7404 g_Console_Add(Format(_lc[I_PLAYER_KILL_2X], [Name]), True);
7405 end;
7406 3: begin
7407 n := 1;
7408 g_Console_Add(Format(_lc[I_PLAYER_KILL_3X], [Name]), True);
7409 end;
7410 4: begin
7411 n := 2;
7412 g_Console_Add(Format(_lc[I_PLAYER_KILL_4X], [Name]), True);
7413 end;
7414 else begin
7415 n := 3;
7416 g_Console_Add(Format(_lc[I_PLAYER_KILL_MX], [Name]), True);
7417 end;
7418 end;
7420 case gAnnouncer of
7421 ANNOUNCE_NONE:
7422 Exit;
7423 ANNOUNCE_ME:
7424 if not g_Game_IsWatchedPlayer(UID) then
7425 Exit;
7426 ANNOUNCE_MEPLUS:
7427 if (not g_Game_IsWatchedPlayer(UID)) and (c < 4) then
7428 Exit;
7429 end;
7431 if killsnd[n].IsPlaying() then
7432 killsnd[n].Stop();
7433 killsnd[n].Play();
7434 end;
7436 procedure g_Game_Announce_BodyKill(SpawnerUID: Word);
7437 var
7438 a: Integer;
7439 begin
7440 case gAnnouncer of
7441 ANNOUNCE_NONE:
7442 Exit;
7443 ANNOUNCE_ME,
7444 ANNOUNCE_MEPLUS:
7445 if not g_Game_IsWatchedPlayer(SpawnerUID) then
7446 Exit;
7447 end;
7448 for a := 0 to 2 do
7449 if hahasnd[a].IsPlaying() then
7450 Exit;
7452 hahasnd[Random(3)].Play();
7453 end;
7455 procedure g_Game_StartVote(Command, Initiator: string);
7456 var
7457 Need: Integer;
7458 begin
7459 if not gVotesEnabled then Exit;
7460 if gGameSettings.GameType <> GT_SERVER then Exit;
7461 if gVoteInProgress or gVotePassed then
7462 begin
7463 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_INPROGRESS], [gVoteCommand]), True);
7464 MH_SEND_VoteEvent(NET_VE_INPROGRESS, gVoteCommand);
7465 Exit;
7466 end;
7467 gVoteInProgress := True;
7468 gVotePassed := False;
7469 gVoteTimer := gTime + gVoteTimeout * 1000;
7470 gVoteCount := 0;
7471 gVoted := False;
7472 gVoteCommand := Command;
7474 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
7475 Need := Floor((NetClientCount+1)/2.0)+1
7476 else
7477 Need := Floor(NetClientCount/2.0)+1;
7478 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_STARTED], [Initiator, Command, Need]), True);
7479 MH_SEND_VoteEvent(NET_VE_STARTED, Initiator, Command, Need);
7480 end;
7482 procedure g_Game_CheckVote;
7483 var
7484 I, Need: Integer;
7485 begin
7486 if gGameSettings.GameType <> GT_SERVER then Exit;
7487 if not gVoteInProgress then Exit;
7489 if (gTime >= gVoteTimer) then
7490 begin
7491 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
7492 Need := Floor((NetClientCount+1)/2.0) + 1
7493 else
7494 Need := Floor(NetClientCount/2.0) + 1;
7495 if gVoteCount >= Need then
7496 begin
7497 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_PASSED], [gVoteCommand]), True);
7498 MH_SEND_VoteEvent(NET_VE_PASSED, gVoteCommand);
7499 gVotePassed := True;
7500 gVoteCmdTimer := gTime + 5000;
7501 end
7502 else
7503 begin
7504 g_Console_Add(_lc[I_MESSAGE_VOTE_FAILED], True);
7505 MH_SEND_VoteEvent(NET_VE_FAILED);
7506 end;
7507 if NetClients <> nil then
7508 for I := Low(NetClients) to High(NetClients) do
7509 if NetClients[i].Used then
7510 NetClients[i].Voted := False;
7511 gVoteInProgress := False;
7512 gVoted := False;
7513 gVoteCount := 0;
7514 end
7515 else
7516 begin
7517 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
7518 Need := Floor((NetClientCount+1)/2.0) + 1
7519 else
7520 Need := Floor(NetClientCount/2.0) + 1;
7521 if gVoteCount >= Need then
7522 begin
7523 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_PASSED], [gVoteCommand]), True);
7524 MH_SEND_VoteEvent(NET_VE_PASSED, gVoteCommand);
7525 gVoteInProgress := False;
7526 gVotePassed := True;
7527 gVoteCmdTimer := gTime + 5000;
7528 gVoted := False;
7529 gVoteCount := 0;
7530 if NetClients <> nil then
7531 for I := Low(NetClients) to High(NetClients) do
7532 if NetClients[i].Used then
7533 NetClients[i].Voted := False;
7534 end;
7535 end;
7536 end;
7538 procedure g_Game_LoadMapList(FileName: string);
7539 var
7540 ListFile: TextFile;
7541 s: string;
7542 begin
7543 MapList := nil;
7544 MapIndex := -1;
7546 if not FileExists(FileName) then Exit;
7548 AssignFile(ListFile, FileName);
7549 Reset(ListFile);
7550 while not EOF(ListFile) do
7551 begin
7552 ReadLn(ListFile, s);
7554 s := Trim(s);
7555 if s = '' then Continue;
7557 SetLength(MapList, Length(MapList)+1);
7558 MapList[High(MapList)] := s;
7559 end;
7560 CloseFile(ListFile);
7561 end;
7563 procedure g_Game_SetDebugMode();
7564 begin
7565 gDebugMode := True;
7566 // ×èòû (äàæå â ñâîåé èãðå):
7567 gCheats := True;
7568 end;
7570 procedure g_Game_SetLoadingText(Text: String; Max: Integer; reWrite: Boolean);
7571 var
7572 i: Word;
7573 begin
7574 if Length(LoadingStat.Msgs) = 0 then
7575 Exit;
7577 with LoadingStat do
7578 begin
7579 if not reWrite then
7580 begin // Ïåðåõîäèì íà ñëåäóþùóþ ñòðîêó èëè ñêðîëëèðóåì:
7581 if NextMsg = Length(Msgs) then
7582 begin // scroll
7583 for i := 0 to High(Msgs)-1 do
7584 Msgs[i] := Msgs[i+1];
7585 end
7586 else
7587 Inc(NextMsg);
7588 end else
7589 if NextMsg = 0 then
7590 Inc(NextMsg);
7592 Msgs[NextMsg-1] := Text;
7593 CurValue := 0;
7594 MaxValue := Max;
7595 ShowCount := 0;
7596 PBarWasHere := false;
7597 end;
7599 g_ActiveWindow := nil;
7601 ProcessLoading(true);
7602 end;
7604 procedure g_Game_StepLoading(Value: Integer = -1);
7605 begin
7606 with LoadingStat do
7607 begin
7608 if Value = -1 then
7609 begin
7610 Inc(CurValue);
7611 Inc(ShowCount);
7612 end
7613 else
7614 CurValue := Value;
7615 if (ShowCount > LOADING_SHOW_STEP) or (Value > -1) then
7616 begin
7617 ShowCount := 0;
7618 ProcessLoading();
7619 end;
7620 end;
7621 end;
7623 procedure g_Game_ClearLoading();
7624 var
7625 len: Word;
7626 begin
7627 with LoadingStat do
7628 begin
7629 CurValue := 0;
7630 MaxValue := 0;
7631 ShowCount := 0;
7632 len := ((gScreenHeight div 3)*2 - 50) div LOADING_INTERLINE;
7633 if len < 1 then len := 1;
7634 SetLength(Msgs, len);
7635 for len := Low(Msgs) to High(Msgs) do
7636 Msgs[len] := '';
7637 NextMsg := 0;
7638 PBarWasHere := false;
7639 end;
7640 end;
7642 procedure Parse_Params(var pars: TParamStrValues);
7643 var
7644 i: Integer;
7645 s: String;
7646 begin
7647 SetLength(pars, 0);
7648 i := 1;
7649 while i <= ParamCount do
7650 begin
7651 s := ParamStr(i);
7652 if (s[1] = '-') and (Length(s) > 1) then
7653 begin
7654 if (s[2] = '-') and (Length(s) > 2) then
7655 begin // Îäèíî÷íûé ïàðàìåòð
7656 SetLength(pars, Length(pars) + 1);
7657 with pars[High(pars)] do
7658 begin
7659 Name := LowerCase(s);
7660 Value := '+';
7661 end;
7662 end
7663 else
7664 if (i < ParamCount) then
7665 begin // Ïàðàìåòð ñî çíà÷åíèåì
7666 Inc(i);
7667 SetLength(pars, Length(pars) + 1);
7668 with pars[High(pars)] do
7669 begin
7670 Name := LowerCase(s);
7671 Value := LowerCase(ParamStr(i));
7672 end;
7673 end;
7674 end;
7676 Inc(i);
7677 end;
7678 end;
7680 function Find_Param_Value(var pars: TParamStrValues; aName: String): String;
7681 var
7682 i: Integer;
7683 begin
7684 Result := '';
7685 for i := 0 to High(pars) do
7686 if pars[i].Name = aName then
7687 begin
7688 Result := pars[i].Value;
7689 Break;
7690 end;
7691 end;
7693 procedure g_Game_Process_Params();
7694 var
7695 pars: TParamStrValues;
7696 map: String;
7697 GMode, n: Byte;
7698 LimT, LimS: Integer;
7699 Opt: LongWord;
7700 Lives: Integer;
7701 s: String;
7702 Port: Integer;
7703 ip: String;
7704 F: TextFile;
7705 begin
7706 Parse_Params(pars);
7708 // Debug mode:
7709 s := Find_Param_Value(pars, '--debug');
7710 if (s <> '') then
7711 begin
7712 g_Game_SetDebugMode();
7713 s := Find_Param_Value(pars, '--netdump');
7714 if (s <> '') then
7715 NetDump := True;
7716 end;
7718 // Connect when game loads
7719 ip := Find_Param_Value(pars, '-connect');
7721 if ip <> '' then
7722 begin
7723 s := Find_Param_Value(pars, '-port');
7724 if (s = '') or not TryStrToInt(s, Port) then
7725 Port := 25666;
7727 s := Find_Param_Value(pars, '-pw');
7729 g_Game_StartClient(ip, Port, s);
7730 Exit;
7731 end;
7733 s := LowerCase(Find_Param_Value(pars, '-dbg-mainwad'));
7734 if (s <> '') then
7735 begin
7736 gDefaultMegawadStart := s;
7737 end;
7739 if (Find_Param_Value(pars, '--dbg-mainwad-restore') <> '') or
7740 (Find_Param_Value(pars, '--dbg-mainwad-default') <> '') then
7741 begin
7742 gDefaultMegawadStart := DF_Default_Megawad_Start;
7743 end;
7745 // Start map when game loads:
7746 map := LowerCase(Find_Param_Value(pars, '-map'));
7747 if isWadPath(map) then
7748 begin
7749 // Game mode:
7750 s := Find_Param_Value(pars, '-gm');
7751 GMode := g_Game_TextToMode(s);
7752 if GMode = GM_NONE then GMode := GM_DM;
7753 if GMode = GM_SINGLE then GMode := GM_COOP;
7755 // Time limit:
7756 s := Find_Param_Value(pars, '-limt');
7757 if (s = '') or (not TryStrToInt(s, LimT)) then
7758 LimT := 0;
7759 if LimT < 0 then
7760 LimT := 0;
7762 // Goal limit:
7763 s := Find_Param_Value(pars, '-lims');
7764 if (s = '') or (not TryStrToInt(s, LimS)) then
7765 LimS := 0;
7766 if LimS < 0 then
7767 LimS := 0;
7769 // Lives limit:
7770 s := Find_Param_Value(pars, '-lives');
7771 if (s = '') or (not TryStrToInt(s, Lives)) then
7772 Lives := 0;
7773 if Lives < 0 then
7774 Lives := 0;
7776 // Options:
7777 s := Find_Param_Value(pars, '-opt');
7778 if (s = '') then
7779 Opt := GAME_OPTION_ALLOWEXIT or GAME_OPTION_BOTVSPLAYER or GAME_OPTION_BOTVSMONSTER
7780 else
7781 Opt := StrToIntDef(s, 0);
7782 if Opt = 0 then
7783 Opt := GAME_OPTION_ALLOWEXIT or GAME_OPTION_BOTVSPLAYER or GAME_OPTION_BOTVSMONSTER;
7785 // Close after map:
7786 s := Find_Param_Value(pars, '--close');
7787 if (s <> '') then
7788 gMapOnce := True;
7790 // Override map to test:
7791 s := LowerCase(Find_Param_Value(pars, '-testmap'));
7792 if s <> '' then
7793 gTestMap := MapsDir + s;
7795 // Delete test map after play:
7796 s := Find_Param_Value(pars, '--testdelete');
7797 if (s <> '') then
7798 begin
7799 gMapToDelete := MapsDir + map;
7800 e_WriteLog('"--testdelete" is deprecated, use --tempdelete.', TMsgType.Fatal);
7801 Halt(1);
7802 end;
7804 // Delete temporary WAD after play:
7805 s := Find_Param_Value(pars, '--tempdelete');
7806 if (s <> '') and (gTestMap <> '') then
7807 begin
7808 gMapToDelete := gTestMap;
7809 gTempDelete := True;
7810 end;
7812 // Number of players:
7813 s := Find_Param_Value(pars, '-pl');
7814 if (s = '') then
7815 n := DEFAULT_PLAYERS
7816 else
7817 n := StrToIntDef(s, DEFAULT_PLAYERS);
7819 // Start:
7820 s := Find_Param_Value(pars, '-port');
7821 if (s = '') or not TryStrToInt(s, Port) then
7822 g_Game_StartCustom(map, GMode, LimT, LimS, Lives, Opt, n)
7823 else
7824 g_Game_StartServer(map, GMode, LimT, LimS, Lives, Opt, n, 0, Port);
7825 end;
7827 // Execute script when game loads:
7828 s := Find_Param_Value(pars, '-exec');
7829 if s <> '' then
7830 begin
7831 if not isWadPath(s) then
7832 s := GameDir + '/' + s;
7834 {$I-}
7835 AssignFile(F, s);
7836 Reset(F);
7837 if IOResult <> 0 then
7838 begin
7839 e_WriteLog(Format(_lc[I_SIMPLE_ERROR], ['Failed to read file: ' + s]), TMsgType.Warning);
7840 g_Console_Add(Format(_lc[I_CONSOLE_ERROR_READ], [s]));
7841 CloseFile(F);
7842 Exit;
7843 end;
7844 e_WriteLog('Executing script: ' + s, TMsgType.Notify);
7845 g_Console_Add(Format(_lc[I_CONSOLE_EXEC], [s]));
7847 while not EOF(F) do
7848 begin
7849 ReadLn(F, s);
7850 if IOResult <> 0 then
7851 begin
7852 e_WriteLog(Format(_lc[I_SIMPLE_ERROR], ['Failed to read file: ' + s]), TMsgType.Warning);
7853 g_Console_Add(Format(_lc[I_CONSOLE_ERROR_READ], [s]));
7854 CloseFile(F);
7855 Exit;
7856 end;
7857 if Pos('#', s) <> 1 then // script comment
7858 g_Console_Process(s, True);
7859 end;
7861 CloseFile(F);
7862 {$I+}
7863 end;
7865 SetLength(pars, 0);
7866 end;
7868 begin
7869 conRegVar('pf_draw_frame', @g_profile_frame_draw, 'draw frame rendering profiles', 'render profiles');
7870 //conRegVar('pf_update_frame', @g_profile_frame_update, 'draw frame updating profiles', 'update profiles');
7871 conRegVar('pf_coldet', @g_profile_collision, 'draw collision detection profiles', 'coldet profiles');
7872 conRegVar('pf_los', @g_profile_los, 'draw monster LOS profiles', 'monster LOS profiles');
7874 conRegVar('r_sq_draw', @gdbg_map_use_accel_render, 'accelerated spatial queries in rendering', 'accelerated rendering');
7875 conRegVar('cd_sq_enabled', @gdbg_map_use_accel_coldet, 'accelerated spatial queries in map coldet', 'accelerated map coldet');
7876 conRegVar('mon_sq_enabled', @gmon_debug_use_sqaccel, 'accelerated spatial queries for monsters', 'accelerated monster coldet');
7877 conRegVar('wtrace_sq_enabled', @gwep_debug_fast_trace, 'accelerated spatial queries for weapon hitscan trace', 'accelerated weapon hitscan');
7879 conRegVar('pr_enabled', @gpart_dbg_enabled, 'enable/disable particles', 'particles');
7880 conRegVar('pr_phys_enabled', @gpart_dbg_phys_enabled, 'enable/disable particle physics', 'particle physics');
7882 conRegVar('los_enabled', @gmon_dbg_los_enabled, 'enable/disable monster LOS calculations', 'monster LOS', true);
7883 conRegVar('mon_think', @gmon_debug_think, 'enable/disable monster thinking', 'monster thinking', true);
7885 {$IFDEF ENABLE_HOLMES}
7886 conRegVar('dbg_holmes', @g_holmes_enabled, 'enable/disable Holmes', 'Holmes', true);
7887 {$ENDIF}
7889 conRegVar('dbg_ignore_level_bounds', @g_dbg_ignore_bounds, 'ignore level bounds', '', false);
7891 conRegVar('r_scale', @g_dbg_scale, 0.01, 100.0, 'render scale', '', false);
7893 conRegVar('light_enabled', @gwin_k8_enable_light_experiments, 'enable/disable dynamic lighting', 'lighting');
7894 conRegVar('light_player_halo', @g_playerLight, 'enable/disable player halo', 'player light halo');
7896 conRegVar('r_smallmap_align_h', @r_smallmap_h, 'halign: 0: left; 1: center; 2: right', 'horizontal aligning of small maps');
7897 conRegVar('r_smallmap_align_v', @r_smallmap_v, 'valign: 0: top; 1: center; 2: bottom', 'vertial aligning of small maps');
7899 conRegVar('r_showfps', @gShowFPS, 'draw fps counter', 'draw fps counter');
7900 conRegVar('r_showtime', @gShowTime, 'show game time', 'show game time');
7901 end.