DEADSOFTWARE

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