DEADSOFTWARE

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