DEADSOFTWARE

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