DEADSOFTWARE

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