DEADSOFTWARE

game: rename "rulez-random" commands
[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, version 3 of the License ONLY.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14 *)
15 {$INCLUDE ../shared/a_modes.inc}
16 unit g_game;
18 interface
20 uses
21 SysUtils, Classes,
22 MAPDEF,
23 g_basic, g_player, e_graphics, g_res_downloader,
24 g_sound, g_gui, utils, md5, mempool, xprofiler,
25 g_touch, g_weapons;
27 type
28 TGameSettings = record
29 GameType: Byte;
30 GameMode: Byte;
31 TimeLimit: Word;
32 ScoreLimit: Word;
33 WarmupTime: Word;
34 SpawnInvul: Word;
35 ItemRespawnTime: Word;
36 RulezTimeMultiplier: Word;
37 MaxLives: Byte;
38 Options: LongWord;
39 WAD: String;
40 end;
42 TGameEvent = record
43 Name: String;
44 Command: String;
45 end;
47 TDelayedEvent = record
48 Pending: Boolean;
49 Time: LongWord;
50 DEType: Byte;
51 DENum: Integer;
52 DEStr: String;
53 end;
55 TChatSound = record
56 Sound: TPlayableSound;
57 Tags: Array of String;
58 FullWord: Boolean;
59 end;
61 TPlayerSettings = record
62 Name: String;
63 Model: String;
64 Color: TRGB;
65 Team: Byte;
66 // ones below are sent only to the server
67 WeaponSwitch: Byte;
68 WeaponPreferences: Array[WP_FIRST..WP_LAST+1] of Byte;
69 SwitchToEmpty: Byte;
70 SkipFist: Byte;
71 end;
73 TMegaWADInfo = record
74 Name: String;
75 Description: String;
76 Author: String;
77 Pic: String;
78 end;
80 THearPoint = record
81 Active: Boolean;
82 Coords: TDFPoint;
83 end;
85 function g_Game_IsNet(): Boolean;
86 function g_Game_IsServer(): Boolean;
87 function g_Game_IsClient(): Boolean;
88 procedure g_Game_Init();
89 procedure g_Game_Free (freeTextures: Boolean=true);
90 procedure g_Game_LoadData();
91 procedure g_Game_FreeData();
92 procedure g_Game_Update();
93 procedure g_Game_PreUpdate();
94 procedure g_Game_Draw();
95 procedure g_Game_Quit();
96 procedure g_Game_SetupScreenSize();
97 procedure g_Game_ChangeResolution(newWidth, newHeight: Word; nowFull, nowMax: Boolean);
98 function g_Game_ModeToText(Mode: Byte): string;
99 function g_Game_TextToMode(Mode: string): Byte;
100 procedure g_Game_ExecuteEvent(Name: String);
101 function g_Game_DelayEvent(DEType: Byte; Time: LongWord; Num: Integer = 0; Str: String = ''): Integer;
102 procedure g_Game_AddPlayer(Team: Byte = TEAM_NONE);
103 procedure g_Game_RemovePlayer();
104 procedure g_Game_Spectate();
105 procedure g_Game_SpectateCenterView();
106 procedure g_Game_StartSingle(Map: String; TwoPlayers: Boolean; nPlayers: Byte);
107 procedure g_Game_StartCustom(Map: String; GameMode: Byte; TimeLimit, ScoreLimit: Word; MaxLives: Byte; Options: LongWord; nPlayers: Byte);
108 procedure g_Game_StartServer(Map: String; GameMode: Byte; TimeLimit, ScoreLimit: Word; MaxLives: Byte; Options: LongWord; nPlayers: Byte; IPAddr: LongWord; Port: Word);
109 procedure g_Game_StartClient(Addr: String; Port: Word; PW: String);
110 procedure g_Game_Restart();
111 procedure g_Game_RestartLevel();
112 procedure g_Game_RestartRound(NoMapRestart: Boolean = False);
113 function g_Game_ClientWAD (NewWAD: String; const WHash: TMD5Digest): AnsiString;
114 function g_Game_StartMap(asMegawad: Boolean; Map: String; Force: Boolean = False; const oldMapPath: AnsiString=''): Boolean;
115 procedure g_Game_ChangeMap(const MapPath: String);
116 procedure g_Game_ExitLevel(const Map: AnsiString);
117 function g_Game_GetFirstMap(WAD: String): String;
118 function g_Game_GetNextMap(): String;
119 procedure g_Game_NextLevel();
120 procedure g_Game_Pause(Enable: Boolean);
121 procedure g_Game_HolmesPause(Enable: Boolean);
122 procedure g_Game_InGameMenu(Show: Boolean);
123 function g_Game_IsWatchedPlayer(UID: Word): Boolean;
124 function g_Game_IsWatchedTeam(Team: Byte): Boolean;
125 procedure g_Game_Message(Msg: String; Time: Word);
126 procedure g_Game_LoadMapList(FileName: String);
127 procedure g_Game_PauseAllSounds(Enable: Boolean);
128 procedure g_Game_StopAllSounds(all: Boolean);
129 procedure g_Game_UpdateTriggerSounds();
130 function g_Game_GetMegaWADInfo(WAD: String): TMegaWADInfo;
131 procedure g_Game_ChatSound(Text: String; Taunt: Boolean = True);
132 procedure g_Game_Announce_GoodShot(SpawnerUID: Word);
133 procedure g_Game_Announce_KillCombo(Param: Integer);
134 procedure g_Game_Announce_BodyKill(SpawnerUID: Word);
135 procedure g_Game_Effect_Bubbles(fX, fY: Integer; count: Word; devX, devY: Byte; Silent: Boolean = False);
136 procedure g_Game_StartVote(Command, Initiator: string);
137 procedure g_Game_CheckVote;
138 procedure g_TakeScreenShot(Filename: string = '');
139 procedure g_FatalError(Text: String);
140 procedure g_SimpleError(Text: String);
141 function g_Game_IsTestMap(): Boolean;
142 procedure g_Game_DeleteTestMap();
143 procedure GameCVars(P: SSArray);
144 procedure PlayerSettingsCVars(P: SSArray);
145 procedure SystemCommands(P: SSArray);
146 procedure GameCommands(P: SSArray);
147 procedure GameCheats(P: SSArray);
148 procedure DebugCommands(P: SSArray);
149 procedure g_Game_Process_Params;
150 procedure g_Game_SetLoadingText(Text: String; Max: Integer; reWrite: Boolean);
151 procedure g_Game_StepLoading(Value: Integer = -1);
152 procedure g_Game_ClearLoading();
153 procedure g_Game_SetDebugMode();
154 procedure DrawLoadingStat();
155 procedure DrawMenuBackground(tex: AnsiString);
157 { procedure SetWinPause(Enable: Boolean); }
159 const
160 GAME_TICK = 28;
162 LOADING_SHOW_STEP = 100;
163 LOADING_INTERLINE = 20;
165 GT_NONE = 0;
166 GT_SINGLE = 1;
167 GT_CUSTOM = 2;
168 GT_SERVER = 3;
169 GT_CLIENT = 4;
171 GM_NONE = 0;
172 GM_DM = 1;
173 GM_TDM = 2;
174 GM_CTF = 3;
175 GM_COOP = 4;
176 GM_SINGLE = 5;
178 MESSAGE_DIKEY = WM_USER + 1;
180 EXIT_QUIT = 1;
181 EXIT_SIMPLE = 2;
182 EXIT_RESTART = 3;
183 EXIT_ENDLEVELSINGLE = 4;
184 EXIT_ENDLEVELCUSTOM = 5;
186 GAME_OPTION_RESERVED = 1;
187 GAME_OPTION_TEAMDAMAGE = 2;
188 GAME_OPTION_ALLOWEXIT = 4;
189 GAME_OPTION_WEAPONSTAY = 8;
190 GAME_OPTION_MONSTERS = 16;
191 GAME_OPTION_BOTVSPLAYER = 32;
192 GAME_OPTION_BOTVSMONSTER = 64;
193 GAME_OPTION_DMKEYS = 128;
194 GAME_OPTION_TEAMHITTRACE = 256;
195 GAME_OPTION_TEAMHITPROJECTILE = 512;
196 GAME_OPTION_TEAMABSORBDAMAGE = 1024;
197 GAME_OPTION_ALLOWDROPFLAG = 2048;
198 GAME_OPTION_THROWFLAG = 4096;
199 GAME_OPTION_RULEZRANDOM = 8192;
201 STATE_NONE = 0;
202 STATE_MENU = 1;
203 STATE_FOLD = 2;
204 STATE_INTERCUSTOM = 3;
205 STATE_INTERSINGLE = 4;
206 STATE_INTERTEXT = 5;
207 STATE_INTERPIC = 6;
208 STATE_ENDPIC = 7;
209 STATE_SLIST = 8;
211 LMS_RESPAWN_NONE = 0;
212 LMS_RESPAWN_WARMUP = 1;
213 LMS_RESPAWN_FINAL = 2;
215 SPECT_NONE = 0;
216 SPECT_STATS = 1;
217 SPECT_MAPVIEW = 2;
218 SPECT_PLAYERS = 3;
220 DE_GLOBEVENT = 0;
221 DE_BFGHIT = 1;
222 DE_KILLCOMBO = 2;
223 DE_BODYKILL = 3;
225 ANNOUNCE_NONE = 0;
226 ANNOUNCE_ME = 1;
227 ANNOUNCE_MEPLUS = 2;
228 ANNOUNCE_ALL = 3;
230 CONFIG_FILENAME = 'Doom2DF.cfg';
232 TEST_MAP_NAME = '$$$_TEST_$$$';
234 STD_PLAYER_MODEL = 'Doomer';
236 {$IFDEF HEADLESS}
237 DEFAULT_PLAYERS = 0;
238 {$ELSE}
239 DEFAULT_PLAYERS = 1;
240 {$ENDIF}
242 STATFILE_VERSION = $03;
244 var
245 gStdFont: DWORD;
246 gGameSettings: TGameSettings;
247 gPlayer1Settings: TPlayerSettings;
248 gPlayer2Settings: TPlayerSettings;
249 gGameOn: Boolean;
250 gPlayerScreenSize: TDFPoint;
251 gPlayer1ScreenCoord: TDFPoint;
252 gPlayer2ScreenCoord: TDFPoint;
253 gPlayer1: TPlayer = nil;
254 gPlayer2: TPlayer = nil;
255 gPlayerDrawn: TPlayer = nil;
256 gTime: LongWord;
257 gLerpFactor: Single = 1.0;
258 gSwitchGameMode: Byte = GM_DM;
259 gHearPoint1, gHearPoint2: THearPoint;
260 gSoundEffectsDF: Boolean = False;
261 gSoundTriggerTime: Word = 0;
262 gAnnouncer: Integer = ANNOUNCE_NONE;
263 goodsnd: array[0..3] of TPlayableSound;
264 killsnd: array[0..3] of TPlayableSound;
265 hahasnd: array[0..2] of TPlayableSound;
266 sound_get_flag: array[0..1] of TPlayableSound;
267 sound_lost_flag: array[0..1] of TPlayableSound;
268 sound_ret_flag: array[0..1] of TPlayableSound;
269 sound_cap_flag: array[0..1] of TPlayableSound;
270 gBodyKillEvent: Integer = -1;
271 gDefInterTime: ShortInt = -1;
272 gInterEndTime: LongWord = 0;
273 gInterTime: LongWord = 0;
274 gServInterTime: Byte = 0;
275 gGameStartTime: LongWord = 0;
276 gTotalMonsters: Integer = 0;
277 gPauseMain: Boolean = false;
278 gPauseHolmes: Boolean = false;
279 gShowTime: Boolean = False;
280 gShowFPS: Boolean = False;
281 gShowScore: Boolean = True;
282 gShowStat: Boolean = True;
283 gShowPIDs: Boolean = False;
284 gShowKillMsg: Boolean = True;
285 gShowLives: Boolean = True;
286 gShowPing: Boolean = False;
287 gShowMap: Boolean = False;
288 gExit: Byte = 0;
289 gState: Byte = STATE_NONE;
290 sX, sY: Integer;
291 sWidth, sHeight: Word;
292 gSpectMode: Byte = SPECT_NONE;
293 gSpectHUD: Boolean = True;
294 gSpectKeyPress: Boolean = False;
295 gSpectX: Integer = 0;
296 gSpectY: Integer = 0;
297 gSpectStep: Byte = 8;
298 gSpectViewTwo: Boolean = False;
299 gSpectPID1: Integer = -1;
300 gSpectPID2: Integer = -1;
301 gSpectAuto: Boolean = False;
302 gSpectAutoNext: LongWord;
303 gSpectAutoStepX: Integer;
304 gSpectAutoStepY: Integer;
305 gMusic: TMusic = nil;
306 gLoadGameMode: Boolean;
307 gCheats: Boolean = False;
308 gMapOnce: Boolean = False;
309 gMapToDelete: String;
310 gTempDelete: Boolean = False;
311 gLastMap: Boolean = False;
312 gScreenWidth: Word;
313 gScreenHeight: Word;
314 gResolutionChange: Boolean = False;
315 gRC_Width, gRC_Height: Integer;
316 gRC_FullScreen, gRC_Maximized: Boolean;
317 gLanguageChange: Boolean = False;
318 gDebugMode: Boolean = False;
319 g_debug_Sounds: Boolean = False;
320 g_debug_Frames: Boolean = False;
321 g_debug_WinMsgs: Boolean = False;
322 g_debug_MonsterOff: Boolean = False;
323 g_debug_BotAIOff: Byte = 0;
324 g_debug_HealthBar: Boolean = False;
325 g_Debug_Player: Boolean = False;
326 gCoopMonstersKilled: Word = 0;
327 gCoopSecretsFound: Word = 0;
328 gCoopTotalMonstersKilled: Word = 0;
329 gCoopTotalSecretsFound: Word = 0;
330 gCoopTotalMonsters: Word = 0;
331 gCoopTotalSecrets: Word = 0;
332 gStatsOff: Boolean = False;
333 gStatsPressed: Boolean = False;
334 gExitByTrigger: Boolean = False;
335 gNextMap: String = '';
336 gLMSRespawn: Byte = LMS_RESPAWN_NONE;
337 gLMSRespawnTime: Cardinal = 0;
338 gLMSSoftSpawn: Boolean = False;
339 gMissionFailed: Boolean = False;
340 gVoteInProgress: Boolean = False;
341 gVotePassed: Boolean = False;
342 gVoteCommand: string = '';
343 gVoteTimer: Cardinal = 0;
344 gVoteCmdTimer: Cardinal = 0;
345 gVoteCount: Integer = 0;
346 gVoteTimeout: Cardinal = 30;
347 gVoted: Boolean = False;
348 gVotesEnabled: Boolean = True;
349 gEvents: Array of TGameEvent;
350 gDelayedEvents: Array of TDelayedEvent;
351 gUseChatSounds: Boolean = True;
352 gChatSounds: Array of TChatSound;
353 gWeaponAction: Array [0..1, WP_FACT..WP_LACT] of Boolean; // [player, weapon_action]
354 gSelectWeapon: Array [0..1, WP_FIRST..WP_LAST] of Boolean; // [player, weapon]
355 gInterReadyCount: Integer = 0;
356 gMaxBots: Integer = 127;
358 g_dbg_ignore_bounds: Boolean = false;
359 r_smallmap_h: Integer = 0; // 0: left; 1: center; 2: right
360 r_smallmap_v: Integer = 2; // 0: top; 1: center; 2: bottom
362 // move button values:
363 // bits 0-1: l/r state:
364 // 0: neither left, nor right pressed
365 // 1: left pressed
366 // 2: right pressed
367 // bits 4-5: l/r state when strafe was pressed
368 P1MoveButton: Byte = 0;
369 P2MoveButton: Byte = 0;
371 g_profile_frame_update: Boolean = false;
372 g_profile_frame_draw: Boolean = false;
373 g_profile_collision: Boolean = false;
374 g_profile_los: Boolean = false;
375 g_profile_history_size: Integer = 1000;
377 g_rlayer_back: Boolean = true;
378 g_rlayer_step: Boolean = true;
379 g_rlayer_wall: Boolean = true;
380 g_rlayer_door: Boolean = true;
381 g_rlayer_acid1: Boolean = true;
382 g_rlayer_acid2: Boolean = true;
383 g_rlayer_water: Boolean = true;
384 g_rlayer_fore: Boolean = true;
387 procedure g_ResetDynlights ();
388 procedure g_AddDynLight (x, y, radius: Integer; r, g, b, a: Single);
389 procedure g_DynLightExplosion (x, y, radius: Integer; r, g, b: Single);
391 function conIsCheatsEnabled (): Boolean; inline;
392 function gPause (): Boolean; inline;
395 implementation
397 uses
398 {$INCLUDE ../nogl/noGLuses.inc}
399 {$IFDEF ENABLE_HOLMES}
400 g_holmes,
401 {$ENDIF}
402 e_texture, e_res, g_textures, g_window, g_menu,
403 e_input, e_log, g_console, g_items, g_map, g_panel,
404 g_playermodel, g_gfx, g_options, Math,
405 g_triggers, g_monsters, e_sound, CONFIG,
406 g_language, g_net, g_main, g_phys,
407 ENet, e_msg, g_netmsg, g_netmaster,
408 sfs, wadreader, g_system;
411 var
412 hasPBarGfx: Boolean = false;
415 // ////////////////////////////////////////////////////////////////////////// //
416 function gPause (): Boolean; inline; begin result := gPauseMain or gPauseHolmes; end;
419 // ////////////////////////////////////////////////////////////////////////// //
420 function conIsCheatsEnabled (): Boolean; inline;
421 begin
422 result := false;
423 if g_Game_IsNet then exit;
424 if not gDebugMode then
425 begin
426 //if not gCheats then exit;
427 if not (gGameSettings.GameType in [GT_SINGLE, GT_CUSTOM]) then exit;
428 if not (gGameSettings.GameMode in [GM_COOP, GM_SINGLE]) then exit;
429 end;
430 result := true;
431 end;
434 // ////////////////////////////////////////////////////////////////////////// //
435 var
436 profileFrameDraw: TProfiler = nil;
439 // ////////////////////////////////////////////////////////////////////////// //
440 type
441 TDynLight = record
442 x, y, radius: Integer;
443 r, g, b, a: Single;
444 exploCount: Integer;
445 exploRadius: Integer;
446 end;
448 var
449 g_dynLights: array of TDynLight = nil;
450 g_dynLightCount: Integer = 0;
451 g_playerLight: Boolean = false;
453 procedure g_ResetDynlights ();
454 var
455 lnum, idx: Integer;
456 begin
457 if not gwin_has_stencil then begin g_dynLightCount := 0; exit; end;
458 lnum := 0;
459 for idx := 0 to g_dynLightCount-1 do
460 begin
461 if g_dynLights[idx].exploCount = -666 then
462 begin
463 // skip it
464 end
465 else
466 begin
467 // explosion
468 Inc(g_dynLights[idx].exploCount);
469 if (g_dynLights[idx].exploCount < 10) then
470 begin
471 g_dynLights[idx].radius := g_dynLights[idx].exploRadius+g_dynLights[idx].exploCount*8;
472 g_dynLights[idx].a := 0.4+g_dynLights[idx].exploCount/10;
473 if (g_dynLights[idx].a > 0.8) then g_dynLights[idx].a := 0.8;
474 if lnum <> idx then g_dynLights[lnum] := g_dynLights[idx];
475 Inc(lnum);
476 end;
477 end;
478 end;
479 g_dynLightCount := lnum;
480 end;
482 procedure g_AddDynLight (x, y, radius: Integer; r, g, b, a: Single);
483 begin
484 if not gwin_has_stencil then exit;
485 if g_dynLightCount = length(g_dynLights) then SetLength(g_dynLights, g_dynLightCount+1024);
486 g_dynLights[g_dynLightCount].x := x;
487 g_dynLights[g_dynLightCount].y := y;
488 g_dynLights[g_dynLightCount].radius := radius;
489 g_dynLights[g_dynLightCount].r := r;
490 g_dynLights[g_dynLightCount].g := g;
491 g_dynLights[g_dynLightCount].b := b;
492 g_dynLights[g_dynLightCount].a := a;
493 g_dynLights[g_dynLightCount].exploCount := -666;
494 Inc(g_dynLightCount);
495 end;
497 procedure g_DynLightExplosion (x, y, radius: Integer; r, g, b: Single);
498 begin
499 if not gwin_has_stencil then exit;
500 if g_dynLightCount = length(g_dynLights) then SetLength(g_dynLights, g_dynLightCount+1024);
501 g_dynLights[g_dynLightCount].x := x;
502 g_dynLights[g_dynLightCount].y := y;
503 g_dynLights[g_dynLightCount].radius := 0;
504 g_dynLights[g_dynLightCount].exploRadius := radius;
505 g_dynLights[g_dynLightCount].r := r;
506 g_dynLights[g_dynLightCount].g := g;
507 g_dynLights[g_dynLightCount].b := b;
508 g_dynLights[g_dynLightCount].a := 0;
509 g_dynLights[g_dynLightCount].exploCount := 0;
510 Inc(g_dynLightCount);
511 end;
514 // ////////////////////////////////////////////////////////////////////////// //
515 function calcProfilesHeight (prof: TProfiler): Integer;
516 begin
517 result := 0;
518 if (prof = nil) then exit;
519 if (length(prof.bars) = 0) then exit;
520 result := length(prof.bars)*(16+2);
521 end;
523 // returns width
524 function drawProfiles (x, y: Integer; prof: TProfiler): Integer;
525 var
526 wdt, hgt: Integer;
527 yy: Integer;
528 ii: Integer;
529 begin
530 result := 0;
531 if (prof = nil) then exit;
532 // gScreenWidth
533 if (length(prof.bars) = 0) then exit;
534 wdt := 192;
535 hgt := calcProfilesHeight(prof);
536 if (x < 0) then x := gScreenWidth-(wdt-1)+x;
537 if (y < 0) then y := gScreenHeight-(hgt-1)+y;
538 // background
539 //e_DrawFillQuad(x, y, x+wdt-1, y+hgt-1, 255, 255, 255, 200, B_BLEND);
540 //e_DrawFillQuad(x, y, x+wdt-1, y+hgt-1, 20, 20, 20, 0, B_NONE);
541 e_DarkenQuadWH(x, y, wdt, hgt, 150);
542 // title
543 yy := y+2;
544 for ii := 0 to High(prof.bars) do
545 begin
546 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);
547 Inc(yy, 16+2);
548 end;
549 result := wdt;
550 end;
553 // ////////////////////////////////////////////////////////////////////////// //
554 type
555 TEndCustomGameStat = record
556 PlayerStat: TPlayerStatArray;
557 TeamStat: TTeamStat;
558 GameTime: LongWord;
559 GameMode: Byte;
560 Map, MapName: String;
561 end;
563 TEndSingleGameStat = record
564 PlayerStat: Array [0..1] of record
565 Kills: Integer;
566 Secrets: Integer;
567 end;
568 GameTime: LongWord;
569 TwoPlayers: Boolean;
570 TotalSecrets: Integer;
571 end;
573 TLoadingStat = record
574 CurValue: Integer;
575 MaxValue: Integer;
576 ShowCount: Integer;
577 Msgs: Array of String;
578 NextMsg: Word;
579 PBarWasHere: Boolean; // did we draw a progress bar for this message?
580 end;
582 TParamStrValue = record
583 Name: String;
584 Value: String;
585 end;
587 TParamStrValues = Array of TParamStrValue;
589 const
590 INTER_ACTION_TEXT = 1;
591 INTER_ACTION_PIC = 2;
592 INTER_ACTION_MUSIC = 3;
594 var
595 FPS, UPS: Word;
596 FPSCounter, UPSCounter: Word;
597 FPSTime, UPSTime: LongWord;
598 DataLoaded: Boolean = False;
599 IsDrawStat: Boolean = False;
600 CustomStat: TEndCustomGameStat;
601 SingleStat: TEndSingleGameStat;
602 LoadingStat: TLoadingStat;
603 EndingGameCounter: Byte = 0;
604 MessageText: String;
605 MessageTime: Word;
606 MessageLineLength: Integer = 80;
607 MapList: SSArray = nil;
608 MapIndex: Integer = -1;
609 InterReadyTime: Integer = -1;
610 StatShotDone: Boolean = False;
611 StatFilename: string = ''; // used by stat screenshot to save with the same name as the csv
612 StatDate: string = '';
613 MegaWAD: record
614 info: TMegaWADInfo;
615 endpic: String;
616 endmus: String;
617 res: record
618 text: Array of ShortString;
619 anim: Array of ShortString;
620 pic: Array of ShortString;
621 mus: Array of ShortString;
622 end;
623 triggers: Array of record
624 event: ShortString;
625 actions: Array of record
626 action, p1, p2: Integer;
627 end;
628 end;
629 cur_trigger: Integer;
630 cur_action: Integer;
631 end;
632 //InterPic: String;
633 InterText: record
634 lines: SSArray;
635 img: String;
636 cur_line: Integer;
637 cur_char: Integer;
638 counter: Integer;
639 endtext: Boolean;
640 end;
642 function Compare(a, b: TPlayerStat): Integer;
643 begin
644 if a.Spectator then Result := 1
645 else if b.Spectator then Result := -1
646 else if a.Frags < b.Frags then Result := 1
647 else if a.Frags > b.Frags then Result := -1
648 else if a.Deaths < b.Deaths then Result := -1
649 else if a.Deaths > b.Deaths then Result := 1
650 else if a.Kills < b.Kills then Result := -1
651 else Result := 1;
652 end;
654 procedure SortGameStat(var stat: TPlayerStatArray);
655 var
656 I, J: Integer;
657 T: TPlayerStat;
658 begin
659 if stat = nil then Exit;
661 for I := High(stat) downto Low(stat) do
662 for J := Low(stat) to High(stat) - 1 do
663 if Compare(stat[J], stat[J + 1]) = 1 then
664 begin
665 T := stat[J];
666 stat[J] := stat[J + 1];
667 stat[J + 1] := T;
668 end;
669 end;
671 // saves a shitty CSV containing the game stats passed to it
672 procedure SaveGameStat(Stat: TEndCustomGameStat; Path: string);
673 var
674 s: TextFile;
675 dir, fname, map, mode, etime: String;
676 I: Integer;
677 begin
678 try
679 dir := e_GetWriteableDir(StatsDirs);
680 // stats are placed in stats/yy/mm/dd/*.csv
681 fname := e_CatPath(dir, Path);
682 ForceDirectories(fname); // ensure yy/mm/dd exists within the stats dir
683 fname := e_CatPath(fname, StatFilename + '.csv');
684 AssignFile(s, fname);
685 try
686 SetTextCodePage(s, CP_UTF8);
687 Rewrite(s);
688 // line 1: stats ver, datetime, server name, map name, game mode, time limit, score limit, dmflags, game time, num players
689 if g_Game_IsNet then fname := NetServerName else fname := '';
690 map := g_ExtractWadNameNoPath(gMapInfo.Map) + ':/' + g_ExtractFileName(gMapInfo.Map);
691 mode := g_Game_ModeToText(Stat.GameMode);
692 etime := Format('%d:%.2d:%.2d', [
693 Stat.GameTime div 1000 div 3600,
694 (Stat.GameTime div 1000 div 60) mod 60,
695 Stat.GameTime div 1000 mod 60
696 ]);
697 WriteLn(s, 'stats_ver,datetime,server,map,mode,timelimit,scorelimit,dmflags,time,num_players');
698 WriteLn(s, Format('%d,%s,%s,%s,%s,%u,%u,%u,%s,%d', [
699 STATFILE_VERSION,
700 StatDate,
701 dquoteStr(fname),
702 dquoteStr(map),
703 mode,
704 gGameSettings.TimeLimit,
705 gGameSettings.ScoreLimit,
706 gGameSettings.Options,
707 etime,
708 Length(Stat.PlayerStat)
709 ]));
710 // line 2: game specific shit
711 // if it's a team game: red score, blue score
712 // if it's a coop game: monsters killed, monsters total, secrets found, secrets total
713 // otherwise nothing
714 if Stat.GameMode in [GM_TDM, GM_CTF] then
715 WriteLn(s,
716 Format('red_score,blue_score' + LineEnding + '%d,%d', [Stat.TeamStat[TEAM_RED].Score, Stat.TeamStat[TEAM_BLUE].Score]))
717 else if Stat.GameMode in [GM_COOP, GM_SINGLE] then
718 WriteLn(s,
719 Format('mon_killed,mon_total,secrets_found,secrets_total' + LineEnding + '%d,%d,%d,%d',[gCoopMonstersKilled, gTotalMonsters, gCoopSecretsFound, gSecretsCount]));
720 // lines 3-...: team, player name, frags, deaths
721 WriteLn(s, 'team,name,frags,deaths');
722 for I := Low(Stat.PlayerStat) to High(Stat.PlayerStat) do
723 with Stat.PlayerStat[I] do
724 WriteLn(s, Format('%d,%s,%d,%d', [Team, dquoteStr(Name), Frags, Deaths]));
725 except
726 g_Console_Add(Format(_lc[I_CONSOLE_ERROR_WRITE], [fname]));
727 end;
728 except
729 g_Console_Add('could not create gamestats file "' + fname + '"');
730 end;
731 CloseFile(s);
732 end;
734 procedure ClearDebugCvars();
735 begin
736 g_debug_Sounds := False;
737 g_debug_Frames := False;
738 g_debug_WinMsgs := False;
739 g_debug_MonsterOff := False;
740 g_debug_BotAIOff := 0;
741 g_debug_HealthBar := False;
742 g_Debug_Player := False;
743 end;
745 function g_Game_ModeToText(Mode: Byte): string;
746 begin
747 Result := '';
748 case Mode of
749 GM_DM: Result := _lc[I_MENU_GAME_TYPE_DM];
750 GM_TDM: Result := _lc[I_MENU_GAME_TYPE_TDM];
751 GM_CTF: Result := _lc[I_MENU_GAME_TYPE_CTF];
752 GM_COOP: Result := _lc[I_MENU_GAME_TYPE_COOP];
753 GM_SINGLE: Result := _lc[I_MENU_GAME_TYPE_SINGLE];
754 end;
755 end;
757 function g_Game_TextToMode(Mode: string): Byte;
758 begin
759 Result := GM_NONE;
760 Mode := UpperCase(Mode);
761 if Mode = _lc[I_MENU_GAME_TYPE_DM] then
762 begin
763 Result := GM_DM;
764 Exit;
765 end;
766 if Mode = _lc[I_MENU_GAME_TYPE_TDM] then
767 begin
768 Result := GM_TDM;
769 Exit;
770 end;
771 if Mode = _lc[I_MENU_GAME_TYPE_CTF] then
772 begin
773 Result := GM_CTF;
774 Exit;
775 end;
776 if Mode = _lc[I_MENU_GAME_TYPE_COOP] then
777 begin
778 Result := GM_COOP;
779 Exit;
780 end;
781 if Mode = _lc[I_MENU_GAME_TYPE_SINGLE] then
782 begin
783 Result := GM_SINGLE;
784 Exit;
785 end;
786 end;
788 function g_Game_IsNet(): Boolean;
789 begin
790 Result := (gGameSettings.GameType in [GT_SERVER, GT_CLIENT]);
791 end;
793 function g_Game_IsServer(): Boolean;
794 begin
795 Result := (gGameSettings.GameType in [GT_SINGLE, GT_CUSTOM, GT_SERVER]);
796 end;
798 function g_Game_IsClient(): Boolean;
799 begin
800 Result := (gGameSettings.GameType = GT_CLIENT);
801 end;
803 function g_Game_GetMegaWADInfo(WAD: String): TMegaWADInfo;
804 var
805 w: TWADFile;
806 cfg: TConfig;
807 p: Pointer;
808 len: Integer;
809 begin
810 Result.name := ExtractFileName(WAD);
811 Result.description := '';
812 Result.author := '';
814 w := TWADFile.Create();
815 w.ReadFile(WAD);
817 if not w.GetResource('INTERSCRIPT', p, len) then
818 begin
819 w.Free();
820 Exit;
821 end;
823 cfg := TConfig.CreateMem(p, len);
824 Result.name := cfg.ReadStr('megawad', 'name', ExtractFileName(WAD));
825 Result.description := cfg.ReadStr('megawad', 'description', '');
826 Result.author := cfg.ReadStr('megawad', 'author', '');
827 Result.pic := cfg.ReadStr('megawad', 'pic', '');
828 cfg.Free();
830 FreeMem(p);
831 end;
833 procedure g_Game_FreeWAD();
834 var
835 a: Integer;
836 begin
837 for a := 0 to High(MegaWAD.res.pic) do
838 if MegaWAD.res.pic[a] <> '' then
839 g_Texture_Delete(MegaWAD.res.pic[a]);
841 for a := 0 to High(MegaWAD.res.mus) do
842 if MegaWAD.res.mus[a] <> '' then
843 g_Sound_Delete(MegaWAD.res.mus[a]);
845 MegaWAD.res.pic := nil;
846 MegaWAD.res.text := nil;
847 MegaWAD.res.anim := nil;
848 MegaWAD.res.mus := nil;
849 MegaWAD.triggers := nil;
851 g_Texture_Delete('TEXTURE_endpic');
852 g_Sound_Delete('MUSIC_endmus');
854 ZeroMemory(@MegaWAD, SizeOf(MegaWAD));
855 gGameSettings.WAD := '';
856 end;
858 procedure g_Game_LoadWAD(WAD: string);
859 var
860 w: TWADFile;
861 cfg: TConfig;
862 p: Pointer;
863 {b, }len: Integer;
864 s: AnsiString;
865 begin
866 g_Game_FreeWAD();
867 gGameSettings.WAD := WAD;
868 if not (gGameSettings.GameMode in [GM_COOP, GM_SINGLE]) then
869 Exit;
871 MegaWAD.info := g_Game_GetMegaWADInfo(WAD);
873 w := TWADFile.Create();
874 w.ReadFile(WAD);
876 if not w.GetResource('INTERSCRIPT', p, len) then
877 begin
878 w.Free();
879 Exit;
880 end;
882 cfg := TConfig.CreateMem(p, len);
884 {b := 1;
885 while True do
886 begin
887 s := cfg.ReadStr('pic', 'pic'+IntToStr(b), '');
888 if s = '' then Break;
889 b := b+1;
891 SetLength(MegaWAD.res.pic, Length(MegaWAD.res.pic)+1);
892 MegaWAD.res.pic[High(MegaWAD.res.pic)] := s;
894 g_Texture_CreateWADEx(s, s);
895 end;
897 b := 1;
898 while True do
899 begin
900 s := cfg.ReadStr('mus', 'mus'+IntToStr(b), '');
901 if s = '' then Break;
902 b := b+1;
904 SetLength(MegaWAD.res.mus, Length(MegaWAD.res.mus)+1);
905 MegaWAD.res.mus[High(MegaWAD.res.mus)] := s;
907 g_Music_CreateWADEx(s, s);
908 end;}
910 MegaWAD.endpic := cfg.ReadStr('megawad', 'endpic', '');
911 if MegaWAD.endpic <> '' then
912 begin
913 TEXTUREFILTER := GL_LINEAR;
914 s := e_GetResourcePath(WadDirs, MegaWAD.endpic, WAD);
915 g_Texture_CreateWADEx('TEXTURE_endpic', s);
916 TEXTUREFILTER := GL_NEAREST;
917 end;
918 MegaWAD.endmus := cfg.ReadStr('megawad', 'endmus', 'Standart.wad:D2DMUS\ÊÎÍÅÖ');
919 if MegaWAD.endmus <> '' then
920 begin
921 s := e_GetResourcePath(WadDirs, MegaWAD.endmus, WAD);
922 g_Sound_CreateWADEx('MUSIC_endmus', s, True);
923 end;
925 cfg.Free();
926 FreeMem(p);
927 w.Free();
928 end;
930 {procedure start_trigger(t: string);
931 begin
932 end;
934 function next_trigger(): Boolean;
935 begin
936 end;}
938 procedure DisableCheats();
939 begin
940 MAX_RUNVEL := 8;
941 VEL_JUMP := 10;
942 gFly := False;
944 if gPlayer1 <> nil then gPlayer1.GodMode := False;
945 if gPlayer2 <> nil then gPlayer2.GodMode := False;
946 if gPlayer1 <> nil then gPlayer1.NoTarget := False;
947 if gPlayer2 <> nil then gPlayer2.NoTarget := False;
949 {$IF DEFINED(D2F_DEBUG)}
950 if gPlayer1 <> nil then gPlayer1.NoTarget := True;
951 gAimLine := g_dbg_aimline_on;
952 {$ENDIF}
953 end;
955 procedure g_Game_ExecuteEvent(Name: String);
956 var
957 a: Integer;
958 begin
959 if Name = '' then
960 Exit;
961 if gEvents = nil then
962 Exit;
963 for a := 0 to High(gEvents) do
964 if gEvents[a].Name = Name then
965 begin
966 if gEvents[a].Command <> '' then
967 g_Console_Process(gEvents[a].Command, True);
968 break;
969 end;
970 end;
972 function g_Game_DelayEvent(DEType: Byte; Time: LongWord; Num: Integer = 0; Str: String = ''): Integer;
973 var
974 a, n: Integer;
975 begin
976 n := -1;
977 if gDelayedEvents <> nil then
978 for a := 0 to High(gDelayedEvents) do
979 if not gDelayedEvents[a].Pending then
980 begin
981 n := a;
982 break;
983 end;
984 if n = -1 then
985 begin
986 SetLength(gDelayedEvents, Length(gDelayedEvents) + 1);
987 n := High(gDelayedEvents);
988 end;
989 gDelayedEvents[n].Pending := True;
990 gDelayedEvents[n].DEType := DEType;
991 gDelayedEvents[n].DENum := Num;
992 gDelayedEvents[n].DEStr := Str;
993 if DEType = DE_GLOBEVENT then
994 gDelayedEvents[n].Time := (sys_GetTicks() {div 1000}) + Time
995 else
996 gDelayedEvents[n].Time := gTime + Time;
997 Result := n;
998 end;
1000 procedure EndGame();
1001 var
1002 a: Integer;
1003 FileName: string;
1004 t: TDateTime;
1005 begin
1006 if g_Game_IsNet and g_Game_IsServer then
1007 MH_SEND_GameEvent(NET_EV_MAPEND, Byte(gMissionFailed));
1009 // Ñòîï èãðà:
1010 gPauseMain := false;
1011 gPauseHolmes := false;
1012 gGameOn := false;
1014 g_Game_StopAllSounds(False);
1016 MessageTime := 0;
1017 MessageText := '';
1019 EndingGameCounter := 0;
1020 g_ActiveWindow := nil;
1022 gLMSRespawn := LMS_RESPAWN_NONE;
1023 gLMSRespawnTime := 0;
1025 case gExit of
1026 EXIT_SIMPLE: // Âûõîä ÷åðåç ìåíþ èëè êîíåö òåñòà
1027 begin
1028 g_Game_Free();
1030 if gMapOnce then
1031 begin // Ýòî áûë òåñò
1032 g_Game_Quit();
1033 end
1034 else
1035 begin // Âûõîä â ãëàâíîå ìåíþ
1036 gMusic.SetByName('MUSIC_MENU');
1037 gMusic.Play();
1038 if gState <> STATE_SLIST then
1039 begin
1040 g_GUI_ShowWindow('MainMenu');
1041 gState := STATE_MENU;
1042 end else
1043 begin
1044 // Îáíîâëÿåì ñïèñîê ñåðâåðîâ
1045 slReturnPressed := True;
1046 if g_Net_Slist_Fetch(slCurrent) then
1047 begin
1048 if slCurrent = nil then
1049 slWaitStr := _lc[I_NET_SLIST_NOSERVERS];
1050 end
1051 else
1052 slWaitStr := _lc[I_NET_SLIST_ERROR];
1053 g_Serverlist_GenerateTable(slCurrent, slTable);
1054 end;
1056 g_Game_ExecuteEvent('ongameend');
1057 end;
1058 end;
1060 EXIT_RESTART: // Íà÷àòü óðîâåíü ñíà÷àëà
1061 begin
1062 if not g_Game_IsClient then g_Game_Restart();
1063 end;
1065 EXIT_ENDLEVELCUSTOM: // Çàêîí÷èëñÿ óðîâåíü â Ñâîåé èãðå
1066 begin
1067 // Ñòàòèñòèêà Ñâîåé èãðû:
1068 FileName := g_ExtractWadName(gMapInfo.Map);
1070 CustomStat.GameTime := gTime;
1071 CustomStat.Map := ExtractFileName(FileName)+':'+g_ExtractFileName(gMapInfo.Map); //ResName;
1072 CustomStat.MapName := gMapInfo.Name;
1073 CustomStat.GameMode := gGameSettings.GameMode;
1074 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
1075 CustomStat.TeamStat := gTeamStat;
1077 CustomStat.PlayerStat := nil;
1079 // Ñòàòèñòèêà èãðîêîâ:
1080 if gPlayers <> nil then
1081 begin
1082 for a := 0 to High(gPlayers) do
1083 if gPlayers[a] <> nil then
1084 begin
1085 SetLength(CustomStat.PlayerStat, Length(CustomStat.PlayerStat)+1);
1086 with CustomStat.PlayerStat[High(CustomStat.PlayerStat)] do
1087 begin
1088 Num := a;
1089 Name := gPlayers[a].Name;
1090 Frags := gPlayers[a].Frags;
1091 Deaths := gPlayers[a].Death;
1092 Kills := gPlayers[a].Kills;
1093 Team := gPlayers[a].Team;
1094 Color := gPlayers[a].Model.Color;
1095 Spectator := gPlayers[a].FSpectator;
1096 end;
1097 end;
1099 SortGameStat(CustomStat.PlayerStat);
1101 if (gSaveStats or gScreenshotStats) and (Length(CustomStat.PlayerStat) > 1) then
1102 begin
1103 t := Now;
1104 if g_Game_IsNet then StatFilename := NetServerName else StatFilename := 'local';
1105 StatDate := FormatDateTime('yymmdd_hhnnss', t);
1106 StatFilename := StatFilename + '_' + CustomStat.Map + '_' + g_Game_ModeToText(CustomStat.GameMode);
1107 StatFilename := sanitizeFilename(StatFilename) + '_' + StatDate;
1108 if gSaveStats then
1109 SaveGameStat(CustomStat, FormatDateTime('yyyy"/"mm"/"dd', t));
1110 end;
1112 StatShotDone := False;
1113 end;
1115 g_Game_ExecuteEvent('onmapend');
1116 if not g_Game_IsClient then g_Player_ResetReady;
1117 gInterReadyCount := 0;
1119 // Çàòóõàþùèé ýêðàí:
1120 EndingGameCounter := 255;
1121 gState := STATE_FOLD;
1122 gInterTime := 0;
1123 if gDefInterTime < 0 then
1124 gInterEndTime := IfThen((gGameSettings.GameType = GT_SERVER) and (gPlayer1 = nil), 15000, 25000)
1125 else
1126 gInterEndTime := gDefInterTime * 1000;
1127 end;
1129 EXIT_ENDLEVELSINGLE: // Çàêîí÷èëñÿ óðîâåíü â Îäèíî÷íîé èãðå
1130 begin
1131 // Ñòàòèñòèêà Îäèíî÷íîé èãðû:
1132 SingleStat.GameTime := gTime;
1133 SingleStat.TwoPlayers := gPlayer2 <> nil;
1134 SingleStat.TotalSecrets := gSecretsCount;
1135 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
1136 SingleStat.PlayerStat[0].Kills := gPlayer1.MonsterKills;
1137 SingleStat.PlayerStat[0].Secrets := gPlayer1.Secrets;
1138 // Ñòàòèñòèêà âòîðîãî èãðîêà (åñëè åñòü):
1139 if SingleStat.TwoPlayers then
1140 begin
1141 SingleStat.PlayerStat[1].Kills := gPlayer2.MonsterKills;
1142 SingleStat.PlayerStat[1].Secrets := gPlayer2.Secrets;
1143 end;
1145 g_Game_ExecuteEvent('onmapend');
1147 // Åñòü åùå êàðòû:
1148 if gNextMap <> '' then
1149 begin
1150 gMusic.SetByName('MUSIC_INTERMUS');
1151 gMusic.Play();
1152 gState := STATE_INTERSINGLE;
1153 e_UnpressAllKeys();
1155 g_Game_ExecuteEvent('oninter');
1156 end
1157 else // Áîëüøå íåò êàðò
1158 begin
1159 // Çàòóõàþùèé ýêðàí:
1160 EndingGameCounter := 255;
1161 gState := STATE_FOLD;
1162 end;
1163 end;
1164 end;
1166 // Îêîí÷àíèå îáðàáîòàíî:
1167 if gExit <> EXIT_QUIT then
1168 gExit := 0;
1169 end;
1171 procedure drawTime(X, Y: Integer); inline;
1172 begin
1173 e_TextureFontPrint(x, y,
1174 Format('%d:%.2d:%.2d', [
1175 gTime div 1000 div 3600,
1176 (gTime div 1000 div 60) mod 60,
1177 gTime div 1000 mod 60
1178 ]),
1179 gStdFont);
1180 end;
1182 procedure DrawStat();
1183 var
1184 pc, x, y, w, h: Integer;
1185 w1, w2, w3, w4: Integer;
1186 a, aa: Integer;
1187 cw, ch, r, g, b, rr, gg, bb: Byte;
1188 s1, s2, s3: String;
1189 _y: Integer;
1190 stat: TPlayerStatArray;
1191 wad, map: string;
1192 mapstr: string;
1193 namestr: string;
1194 begin
1195 s1 := '';
1196 s2 := '';
1197 s3 := '';
1198 pc := g_Player_GetCount;
1199 e_TextureFontGetSize(gStdFont, cw, ch);
1201 w := gScreenWidth-(gScreenWidth div 5);
1202 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
1203 h := 32+ch*(11+pc)
1204 else
1205 h := 40+ch*5+(ch+8)*pc;
1206 x := (gScreenWidth div 2)-(w div 2);
1207 y := (gScreenHeight div 2)-(h div 2);
1209 e_DrawFillQuad(x, y, x+w-1, y+h-1, 64, 64, 64, 32);
1210 e_DrawQuad(x, y, x+w-1, y+h-1, 255, 127, 0);
1212 drawTime(x+w-78, y+8);
1214 wad := g_ExtractWadNameNoPath(gMapInfo.Map);
1215 map := g_ExtractFileName(gMapInfo.Map);
1216 mapstr := wad + ':\' + map + ' - ' + gMapInfo.Name;
1218 case gGameSettings.GameMode of
1219 GM_DM:
1220 begin
1221 if gGameSettings.MaxLives = 0 then
1222 s1 := _lc[I_GAME_DM]
1223 else
1224 s1 := _lc[I_GAME_LMS];
1225 s2 := Format(_lc[I_GAME_FRAG_LIMIT], [gGameSettings.ScoreLimit]);
1226 s3 := Format(_lc[I_GAME_TIME_LIMIT], [gGameSettings.TimeLimit div 3600, (gGameSettings.TimeLimit div 60) mod 60, gGameSettings.TimeLimit mod 60]);
1227 end;
1229 GM_TDM:
1230 begin
1231 if gGameSettings.MaxLives = 0 then
1232 s1 := _lc[I_GAME_TDM]
1233 else
1234 s1 := _lc[I_GAME_TLMS];
1235 s2 := Format(_lc[I_GAME_FRAG_LIMIT], [gGameSettings.ScoreLimit]);
1236 s3 := Format(_lc[I_GAME_TIME_LIMIT], [gGameSettings.TimeLimit div 3600, (gGameSettings.TimeLimit div 60) mod 60, gGameSettings.TimeLimit mod 60]);
1237 end;
1239 GM_CTF:
1240 begin
1241 s1 := _lc[I_GAME_CTF];
1242 s2 := Format(_lc[I_GAME_SCORE_LIMIT], [gGameSettings.ScoreLimit]);
1243 s3 := Format(_lc[I_GAME_TIME_LIMIT], [gGameSettings.TimeLimit div 3600, (gGameSettings.TimeLimit div 60) mod 60, gGameSettings.TimeLimit mod 60]);
1244 end;
1246 GM_COOP:
1247 begin
1248 if gGameSettings.MaxLives = 0 then
1249 s1 := _lc[I_GAME_COOP]
1250 else
1251 s1 := _lc[I_GAME_SURV];
1252 s2 := _lc[I_GAME_MONSTERS] + ' ' + IntToStr(gCoopMonstersKilled) + '/' + IntToStr(gTotalMonsters);
1253 s3 := _lc[I_GAME_SECRETS] + ' ' + IntToStr(gCoopSecretsFound) + '/' + IntToStr(gSecretsCount);
1254 end;
1256 else
1257 begin
1258 s1 := '';
1259 s2 := '';
1260 end;
1261 end;
1263 _y := y+8;
1264 e_TextureFontPrintEx(x+(w div 2)-(Length(s1)*cw div 2), _y, s1, gStdFont, 255, 255, 255, 1);
1265 _y := _y+ch+8;
1266 e_TextureFontPrintEx(x+(w div 2)-(Length(mapstr)*cw div 2), _y, mapstr, gStdFont, 200, 200, 200, 1);
1267 _y := _y+ch+8;
1268 e_TextureFontPrintEx(x+16, _y, s2, gStdFont, 200, 200, 200, 1);
1270 e_TextureFontPrintEx(x+w-16-(Length(s3))*cw, _y, s3,
1271 gStdFont, 200, 200, 200, 1);
1273 if NetMode = NET_SERVER then
1274 e_TextureFontPrintEx(x+8, y + 8, _lc[I_NET_SERVER], gStdFont, 255, 255, 255, 1)
1275 else
1276 if NetMode = NET_CLIENT then
1277 e_TextureFontPrintEx(x+8, y + 8,
1278 NetClientIP + ':' + IntToStr(NetClientPort), gStdFont, 255, 255, 255, 1);
1280 if pc = 0 then
1281 Exit;
1282 stat := g_Player_GetStats();
1283 SortGameStat(stat);
1285 w2 := (w-16) div 6 + 48; // øèðèíà 2 ñòîëáöà
1286 w3 := (w-16) div 6; // øèðèíà 3 è 4 ñòîëáöîâ
1287 w4 := w3;
1288 w1 := w-16-w2-w3-w4; // îñòàâøååñÿ ïðîñòðàíñòâî - äëÿ öâåòà è èìåíè èãðîêà
1290 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
1291 begin
1292 _y := _y+ch+ch;
1294 for a := TEAM_RED to TEAM_BLUE do
1295 begin
1296 if a = TEAM_RED then
1297 begin
1298 s1 := _lc[I_GAME_TEAM_RED];
1299 r := 255;
1300 g := 0;
1301 b := 0;
1302 end
1303 else
1304 begin
1305 s1 := _lc[I_GAME_TEAM_BLUE];
1306 r := 0;
1307 g := 0;
1308 b := 255;
1309 end;
1311 e_TextureFontPrintEx(x+16, _y, s1, gStdFont, r, g, b, 1);
1312 e_TextureFontPrintEx(x+w1+16, _y, IntToStr(gTeamStat[a].Score),
1313 gStdFont, r, g, b, 1);
1315 _y := _y+ch+(ch div 4);
1316 e_DrawLine(1, x+16, _y, x+w-16, _y, r, g, b);
1317 _y := _y+(ch div 4);
1319 for aa := 0 to High(stat) do
1320 if stat[aa].Team = a then
1321 with stat[aa] do
1322 begin
1323 if Spectator then
1324 begin
1325 rr := r div 2;
1326 gg := g div 2;
1327 bb := b div 2;
1328 end
1329 else
1330 begin
1331 rr := r;
1332 gg := g;
1333 bb := b;
1334 end;
1335 if gShowPIDs then
1336 namestr := Format('[%5d] %s', [UID, Name])
1337 else
1338 namestr := Name;
1339 // Èìÿ
1340 e_TextureFontPrintEx(x+16, _y, namestr, gStdFont, rr, gg, bb, 1);
1341 // Ïèíã/ïîòåðè
1342 e_TextureFontPrintEx(x+w1+16, _y, Format(_lc[I_GAME_PING_MS], [Ping, Loss]), gStdFont, rr, gg, bb, 1);
1343 // Ôðàãè
1344 e_TextureFontPrintEx(x+w1+w2+16, _y, IntToStr(Frags), gStdFont, rr, gg, bb, 1);
1345 // Ñìåðòè
1346 e_TextureFontPrintEx(x+w1+w2+w3+16, _y, IntToStr(Deaths), gStdFont, rr, gg, bb, 1);
1347 _y := _y+ch;
1348 end;
1350 _y := _y+ch;
1351 end;
1352 end
1353 else if gGameSettings.GameMode in [GM_DM, GM_COOP] then
1354 begin
1355 _y := _y+ch+ch;
1356 e_TextureFontPrintEx(x+16, _y, _lc[I_GAME_PLAYER_NAME], gStdFont, 255, 127, 0, 1);
1357 e_TextureFontPrintEx(x+16+w1, _y, _lc[I_GAME_PING], gStdFont, 255, 127, 0, 1);
1358 e_TextureFontPrintEx(x+16+w1+w2, _y, _lc[I_GAME_FRAGS], gStdFont, 255, 127, 0, 1);
1359 e_TextureFontPrintEx(x+16+w1+w2+w3, _y, _lc[I_GAME_DEATHS], gStdFont, 255, 127, 0, 1);
1361 _y := _y+ch+8;
1362 for aa := 0 to High(stat) do
1363 with stat[aa] do
1364 begin
1365 if Spectator then
1366 begin
1367 r := 127;
1368 g := 64;
1369 end
1370 else
1371 begin
1372 r := 255;
1373 g := 127;
1374 end;
1375 if gShowPIDs then
1376 namestr := Format('[%5d] %s', [UID, Name])
1377 else
1378 namestr := Name;
1379 // Öâåò èãðîêà
1380 e_DrawFillQuad(x+16, _y+4, x+32-1, _y+16+4-1, Color.R, Color.G, Color.B, 0);
1381 e_DrawQuad(x+16, _y+4, x+32-1, _y+16+4-1, 192, 192, 192);
1382 // Èìÿ
1383 e_TextureFontPrintEx(x+16+16+8, _y+4, namestr, gStdFont, r, g, 0, 1);
1384 // Ïèíã/ïîòåðè
1385 e_TextureFontPrintEx(x+w1+16, _y+4, Format(_lc[I_GAME_PING_MS], [Ping, Loss]), gStdFont, r, g, 0, 1);
1386 // Ôðàãè
1387 e_TextureFontPrintEx(x+w1+w2+16, _y+4, IntToStr(Frags), gStdFont, r, g, 0, 1);
1388 // Ñìåðòè
1389 e_TextureFontPrintEx(x+w1+w2+w3+16, _y+4, IntToStr(Deaths), gStdFont, r, g, 0, 1);
1390 _y := _y+ch+8;
1391 end;
1392 end
1393 end;
1395 procedure g_Game_Init();
1396 var
1397 SR: TSearchRec;
1398 knownFiles: array of AnsiString = nil;
1399 found: Boolean;
1400 wext, s: AnsiString;
1401 f: Integer;
1402 begin
1403 gExit := 0;
1404 gMapToDelete := '';
1405 gTempDelete := False;
1407 sfsGCDisable(); // temporary disable removing of temporary volumes
1409 try
1410 TEXTUREFILTER := GL_LINEAR;
1411 g_Texture_CreateWADEx('MENU_BACKGROUND', GameWAD+':TEXTURES\TITLE');
1412 g_Texture_CreateWADEx('INTER', GameWAD+':TEXTURES\INTER');
1413 g_Texture_CreateWADEx('ENDGAME_EN', GameWAD+':TEXTURES\ENDGAME_EN');
1414 g_Texture_CreateWADEx('ENDGAME_RU', GameWAD+':TEXTURES\ENDGAME_RU');
1415 TEXTUREFILTER := GL_NEAREST;
1417 LoadStdFont('STDTXT', 'STDFONT', gStdFont);
1418 LoadFont('MENUTXT', 'MENUFONT', gMenuFont);
1419 LoadFont('SMALLTXT', 'SMALLFONT', gMenuSmallFont);
1421 g_Game_ClearLoading();
1422 g_Game_SetLoadingText(Format('Doom 2D: Forever %s', [GAME_VERSION]), 0, False);
1423 g_Game_SetLoadingText('', 0, False);
1425 g_Game_SetLoadingText(_lc[I_LOAD_CONSOLE], 0, False);
1426 g_Console_Init();
1428 g_Game_SetLoadingText(_lc[I_LOAD_MODELS], 0, False);
1429 g_PlayerModel_LoadData();
1431 // load models from all possible wad types, in all known directories
1432 // this does a loosy job (linear search, ooph!), but meh
1433 for wext in wadExtensions do
1434 begin
1435 for f := High(ModelDirs) downto Low(ModelDirs) do
1436 begin
1437 if (FindFirst(ModelDirs[f]+DirectorySeparator+'*'+wext, faAnyFile, SR) = 0) then
1438 begin
1439 repeat
1440 found := false;
1441 for s in knownFiles do
1442 begin
1443 if (strEquCI1251(forceFilenameExt(SR.Name, ''), forceFilenameExt(ExtractFileName(s), ''))) then
1444 begin
1445 found := true;
1446 break;
1447 end;
1448 end;
1449 if not found then
1450 begin
1451 SetLength(knownFiles, length(knownFiles)+1);
1452 knownFiles[High(knownFiles)] := ModelDirs[f]+DirectorySeparator+SR.Name;
1453 end;
1454 until (FindNext(SR) <> 0);
1455 end;
1456 FindClose(SR);
1457 end;
1458 end;
1460 if (length(knownFiles) = 0) then raise Exception.Create('no player models found!');
1462 if (length(knownFiles) = 1) then e_LogWriteln('1 player model found.', TMsgType.Notify) else e_LogWritefln('%d player models found.', [Integer(length(knownFiles))], TMsgType.Notify);
1463 for s in knownFiles do
1464 begin
1465 if not g_PlayerModel_Load(s) then e_LogWritefln('Error loading model "%s"', [s], TMsgType.Warning);
1466 end;
1468 gGameOn := false;
1469 gPauseMain := false;
1470 gPauseHolmes := false;
1471 gTime := 0;
1473 {e_MouseInfo.Accel := 1.0;}
1475 g_Game_SetLoadingText(_lc[I_LOAD_GAME_DATA], 0, False);
1476 g_Game_LoadData();
1478 g_Game_SetLoadingText(_lc[I_LOAD_MUSIC], 0, False);
1479 g_Sound_CreateWADEx('MUSIC_INTERMUS', GameWAD+':MUSIC\INTERMUS', True);
1480 g_Sound_CreateWADEx('MUSIC_MENU', GameWAD+':MUSIC\MENU', True);
1481 g_Sound_CreateWADEx('MUSIC_ROUNDMUS', GameWAD+':MUSIC\ROUNDMUS', True, True);
1482 g_Sound_CreateWADEx('MUSIC_STDENDMUS', GameWAD+':MUSIC\ENDMUS', True);
1484 {$IFNDEF HEADLESS}
1485 g_Game_SetLoadingText(_lc[I_LOAD_MENUS], 0, False);
1486 g_Menu_Init();
1487 {$ENDIF}
1489 gMusic := TMusic.Create();
1490 gMusic.SetByName('MUSIC_MENU');
1491 gMusic.Play();
1493 gGameSettings.WarmupTime := 30;
1495 gState := STATE_MENU;
1497 SetLength(gEvents, 6);
1498 gEvents[0].Name := 'ongamestart';
1499 gEvents[1].Name := 'ongameend';
1500 gEvents[2].Name := 'onmapstart';
1501 gEvents[3].Name := 'onmapend';
1502 gEvents[4].Name := 'oninter';
1503 gEvents[5].Name := 'onwadend';
1504 finally
1505 sfsGCEnable(); // enable releasing unused volumes
1506 end;
1507 end;
1509 procedure g_Game_Free(freeTextures: Boolean=true);
1510 begin
1511 if NetMode = NET_CLIENT then g_Net_Disconnect();
1512 if NetMode = NET_SERVER then g_Net_Host_Die();
1514 g_Map_Free(freeTextures);
1515 g_Player_Free();
1516 g_Player_RemoveAllCorpses();
1518 gGameSettings.GameType := GT_NONE;
1519 if gGameSettings.GameMode = GM_SINGLE then
1520 gGameSettings.GameMode := GM_DM;
1521 gSwitchGameMode := gGameSettings.GameMode;
1523 gChatShow := False;
1524 gExitByTrigger := False;
1525 end;
1527 function IsActivePlayer(p: TPlayer): Boolean;
1528 begin
1529 Result := False;
1530 if p = nil then
1531 Exit;
1532 Result := (not p.FDummy) and (not p.FSpectator);
1533 end;
1535 function GetActivePlayer_ByID(ID: Integer): TPlayer;
1536 var
1537 a: Integer;
1538 begin
1539 Result := nil;
1540 if ID < 0 then
1541 Exit;
1542 if gPlayers = nil then
1543 Exit;
1544 for a := Low(gPlayers) to High(gPlayers) do
1545 if IsActivePlayer(gPlayers[a]) then
1546 begin
1547 if gPlayers[a].UID <> ID then
1548 continue;
1549 Result := gPlayers[a];
1550 break;
1551 end;
1552 end;
1554 function GetActivePlayerID_Next(Skip: Integer = -1): Integer;
1555 var
1556 a, idx: Integer;
1557 ids: Array of Word;
1558 begin
1559 Result := -1;
1560 if gPlayers = nil then
1561 Exit;
1562 SetLength(ids, 0);
1563 idx := -1;
1564 for a := Low(gPlayers) to High(gPlayers) do
1565 if IsActivePlayer(gPlayers[a]) then
1566 begin
1567 SetLength(ids, Length(ids) + 1);
1568 ids[High(ids)] := gPlayers[a].UID;
1569 if gPlayers[a].UID = Skip then
1570 idx := High(ids);
1571 end;
1572 if Length(ids) = 0 then
1573 Exit;
1574 if idx = -1 then
1575 Result := ids[0]
1576 else
1577 Result := ids[(idx + 1) mod Length(ids)];
1578 end;
1580 function GetActivePlayerID_Prev(Skip: Integer = -1): Integer;
1581 var
1582 a, idx: Integer;
1583 ids: Array of Word;
1584 begin
1585 Result := -1;
1586 if gPlayers = nil then
1587 Exit;
1588 SetLength(ids, 0);
1589 idx := -1;
1590 for a := Low(gPlayers) to High(gPlayers) do
1591 if IsActivePlayer(gPlayers[a]) then
1592 begin
1593 SetLength(ids, Length(ids) + 1);
1594 ids[High(ids)] := gPlayers[a].UID;
1595 if gPlayers[a].UID = Skip then
1596 idx := High(ids);
1597 end;
1598 if Length(ids) = 0 then
1599 Exit;
1600 if idx = -1 then
1601 Result := ids[Length(ids) - 1]
1602 else
1603 Result := ids[(Length(ids) - 1 + idx) mod Length(ids)];
1604 end;
1606 function GetActivePlayerID_Random(Skip: Integer = -1): Integer;
1607 var
1608 a, idx: Integer;
1609 ids: Array of Word;
1610 begin
1611 Result := -1;
1612 if gPlayers = nil then
1613 Exit;
1614 SetLength(ids, 0);
1615 idx := -1;
1616 for a := Low(gPlayers) to High(gPlayers) do
1617 if IsActivePlayer(gPlayers[a]) then
1618 begin
1619 SetLength(ids, Length(ids) + 1);
1620 ids[High(ids)] := gPlayers[a].UID;
1621 if gPlayers[a].UID = Skip then
1622 idx := High(ids);
1623 end;
1624 if Length(ids) = 0 then
1625 Exit;
1626 if Length(ids) = 1 then
1627 begin
1628 Result := ids[0];
1629 Exit;
1630 end;
1631 Result := ids[Random(Length(ids))];
1632 a := 10;
1633 while (idx <> -1) and (Result = Skip) and (a > 0) do
1634 begin
1635 Result := ids[Random(Length(ids))];
1636 Dec(a);
1637 end;
1638 end;
1640 function GetRandomSpectMode(Current: Byte): Byte;
1641 label
1642 retry;
1643 begin
1644 Result := Current;
1645 retry:
1646 case Random(7) of
1647 0: Result := SPECT_STATS;
1648 1: Result := SPECT_MAPVIEW;
1649 2: Result := SPECT_MAPVIEW;
1650 3: Result := SPECT_PLAYERS;
1651 4: Result := SPECT_PLAYERS;
1652 5: Result := SPECT_PLAYERS;
1653 6: Result := SPECT_PLAYERS;
1654 end;
1655 if (Current in [SPECT_STATS, SPECT_MAPVIEW]) and (Current = Result) then
1656 goto retry;
1657 end;
1659 procedure ProcessPlayerControls (plr: TPlayer; p: Integer; var MoveButton: Byte);
1660 var
1661 time: Word;
1662 strafeDir: Byte;
1663 i: Integer;
1664 begin
1665 if (plr = nil) then exit;
1666 if (p = 2) then time := 1000 else time := 1;
1667 strafeDir := MoveButton shr 4;
1668 MoveButton := MoveButton and $0F;
1670 if gPlayerAction[p, ACTION_MOVELEFT] and (not gPlayerAction[p, ACTION_MOVERIGHT]) then
1671 MoveButton := 1 // Íàæàòà òîëüêî "Âëåâî"
1672 else if (not gPlayerAction[p, ACTION_MOVELEFT]) and gPlayerAction[p, ACTION_MOVERIGHT] then
1673 MoveButton := 2 // Íàæàòà òîëüêî "Âïðàâî"
1674 else if (not gPlayerAction[p, ACTION_MOVELEFT]) and (not gPlayerAction[p, ACTION_MOVERIGHT]) then
1675 MoveButton := 0; // Íå íàæàòû íè "Âëåâî", íè "Âïðàâî"
1677 // Ñåé÷àñ èëè ðàíüøå áûëè íàæàòû "Âëåâî"/"Âïðàâî" => ïåðåäàåì èãðîêó:
1678 if MoveButton = 1 then
1679 plr.PressKey(KEY_LEFT, time)
1680 else if MoveButton = 2 then
1681 plr.PressKey(KEY_RIGHT, time);
1683 // if we have "strafe" key, turn off old strafe mechanics
1684 if gPlayerAction[p, ACTION_STRAFE] then
1685 begin
1686 // new strafe mechanics
1687 if (strafeDir = 0) then
1688 strafeDir := MoveButton; // start strafing
1689 // now set direction according to strafe (reversed)
1690 if (strafeDir = 2) then
1691 plr.SetDirection(TDirection.D_LEFT)
1692 else if (strafeDir = 1) then
1693 plr.SetDirection(TDirection.D_RIGHT)
1694 end
1695 else
1696 begin
1697 strafeDir := 0; // not strafing anymore
1698 // Ðàíüøå áûëà íàæàòà "Âïðàâî", à ñåé÷àñ "Âëåâî" => áåæèì âïðàâî, ñìîòðèì âëåâî:
1699 if (MoveButton = 2) and gPlayerAction[p, ACTION_MOVELEFT] then
1700 plr.SetDirection(TDirection.D_LEFT)
1701 // Ðàíüøå áûëà íàæàòà "Âëåâî", à ñåé÷àñ "Âïðàâî" => áåæèì âëåâî, ñìîòðèì âïðàâî:
1702 else if (MoveButton = 1) and gPlayerAction[p, ACTION_MOVERIGHT] then
1703 plr.SetDirection(TDirection.D_RIGHT)
1704 // ×òî-òî áûëî íàæàòî è íå èçìåíèëîñü => êóäà áåæèì, òóäà è ñìîòðèì:
1705 else if MoveButton <> 0 then
1706 plr.SetDirection(TDirection(MoveButton-1))
1707 end;
1709 // fix movebutton state
1710 MoveButton := MoveButton or (strafeDir shl 4);
1712 // Îñòàëüíûå êëàâèøè:
1713 if gPlayerAction[p, ACTION_JUMP] then plr.PressKey(KEY_JUMP, time);
1714 if gPlayerAction[p, ACTION_LOOKUP] then plr.PressKey(KEY_UP, time);
1715 if gPlayerAction[p, ACTION_LOOKDOWN] then plr.PressKey(KEY_DOWN, time);
1716 if gPlayerAction[p, ACTION_ATTACK] then plr.PressKey(KEY_FIRE);
1717 if gPlayerAction[p, ACTION_ACTIVATE] then plr.PressKey(KEY_OPEN);
1719 for i := WP_FACT to WP_LACT do
1720 begin
1721 if gWeaponAction[p, i] then
1722 begin
1723 plr.ProcessWeaponAction(i);
1724 gWeaponAction[p, i] := False
1725 end
1726 end;
1728 for i := WP_FIRST to WP_LAST do
1729 begin
1730 if gSelectWeapon[p, i] then
1731 begin
1732 plr.QueueWeaponSwitch(i); // all choices are passed there, and god will take the best
1733 gSelectWeapon[p, i] := False
1734 end
1735 end;
1737 // HACK: add dynlight here
1738 if gwin_k8_enable_light_experiments then
1739 begin
1740 if e_KeyPressed(IK_F8) and gGameOn and (not gConsoleShow) and (g_ActiveWindow = nil) then
1741 begin
1742 g_playerLight := true;
1743 end;
1744 if e_KeyPressed(IK_F9) and gGameOn and (not gConsoleShow) and (g_ActiveWindow = nil) then
1745 begin
1746 g_playerLight := false;
1747 end;
1748 end;
1750 if gwin_has_stencil and g_playerLight then g_AddDynLight(plr.GameX+32, plr.GameY+40, 128, 1, 1, 0, 0.6);
1751 end;
1753 // HACK: don't have a "key was pressed" function
1754 procedure InterReady();
1755 begin
1756 if InterReadyTime > gTime then Exit;
1757 InterReadyTime := gTime + 3000;
1758 MC_SEND_CheatRequest(NET_CHEAT_READY);
1759 end;
1761 procedure g_Game_PreUpdate();
1762 begin
1763 // these are in separate PreUpdate functions because they can interact during Update()
1764 // and are synced over the net
1765 // we don't care that much about corpses and gibs
1766 g_Player_PreUpdate();
1767 g_Monsters_PreUpdate();
1768 g_Items_PreUpdate();
1769 g_Weapon_PreUpdate();
1770 end;
1772 procedure g_Game_Update();
1773 var
1774 Msg: g_gui.TMessage;
1775 Time: Int64;
1776 a: Byte;
1777 w: Word;
1778 i, b: Integer;
1780 function sendMonsPos (mon: TMonster): Boolean;
1781 begin
1782 result := false; // don't stop
1783 // this will also reset "need-send" flag
1784 if mon.gncNeedSend then
1785 begin
1786 MH_SEND_MonsterPos(mon.UID);
1787 end
1788 else if (mon.MonsterType = MONSTER_BARREL) then
1789 begin
1790 if (mon.GameVelX <> 0) or (mon.GameVelY <> 0) then MH_SEND_MonsterPos(mon.UID);
1791 end
1792 else if (mon.MonsterState <> MONSTATE_SLEEP) then
1793 begin
1794 if (mon.MonsterState <> MONSTATE_DEAD) or (mon.GameVelX <> 0) or (mon.GameVelY <> 0) then MH_SEND_MonsterPos(mon.UID);
1795 end;
1796 end;
1798 function sendMonsPosUnexpected (mon: TMonster): Boolean;
1799 begin
1800 result := false; // don't stop
1801 // this will also reset "need-send" flag
1802 if mon.gncNeedSend then MH_SEND_MonsterPos(mon.UID);
1803 end;
1805 function sendItemPos (it: PItem): Boolean;
1806 begin
1807 result := false; // don't stop
1808 if it.needSend then
1809 begin
1810 MH_SEND_ItemPos(it.myId);
1811 it.needSend := False;
1812 end;
1813 end;
1815 var
1816 reliableUpdate: Boolean;
1817 begin
1818 g_ResetDynlights();
1819 framePool.reset();
1821 // Ïîðà âûêëþ÷àòü èãðó:
1822 if gExit = EXIT_QUIT then
1823 Exit;
1824 // Èãðà çàêîí÷èëàñü - îáðàáàòûâàåì:
1825 if gExit <> 0 then
1826 begin
1827 EndGame();
1828 if gExit = EXIT_QUIT then
1829 Exit;
1830 end;
1832 // ×èòàåì êëàâèàòóðó è äæîéñòèê, åñëè îêíî àêòèâíî
1833 // no need to, as we'll do it in event handler
1835 // Îáíîâëÿåì êîíñîëü (äâèæåíèå è ñîîáùåíèÿ):
1836 g_Console_Update();
1838 if (NetMode = NET_NONE) and (g_Game_IsNet) and (gGameOn or (gState in [STATE_FOLD, STATE_INTERCUSTOM])) then
1839 begin
1840 gExit := EXIT_SIMPLE;
1841 EndGame();
1842 Exit;
1843 end;
1845 // process master server communications
1846 g_Net_Slist_Pulse();
1848 case gState of
1849 STATE_INTERSINGLE, // Ñòàòèñòêà ïîñëå ïðîõîæäåíèÿ óðîâíÿ â Îäèíî÷íîé èãðå
1850 STATE_INTERCUSTOM, // Ñòàòèñòêà ïîñëå ïðîõîæäåíèÿ óðîâíÿ â Ñâîåé èãðå
1851 STATE_INTERTEXT, // Òåêñò ìåæäó óðîâíÿìè
1852 STATE_INTERPIC: // Êàðòèíêà ìåæäó óðîâíÿìè
1853 begin
1854 if g_Game_IsNet and g_Game_IsServer then
1855 begin
1856 gInterTime := gInterTime + GAME_TICK;
1857 a := Min((gInterEndTime - gInterTime) div 1000 + 1, 255);
1858 if a <> gServInterTime then
1859 begin
1860 gServInterTime := a;
1861 MH_SEND_TimeSync(gServInterTime);
1862 end;
1863 end;
1865 if (not g_Game_IsClient) and
1869 e_KeyPressed(IK_RETURN) or e_KeyPressed(IK_KPRETURN) or e_KeyPressed(IK_SPACE) or
1870 e_KeyPressed(VK_FIRE) or e_KeyPressed(VK_OPEN) or
1871 e_KeyPressed(JOY0_ATTACK) or e_KeyPressed(JOY1_ATTACK) or
1872 e_KeyPressed(JOY2_ATTACK) or e_KeyPressed(JOY3_ATTACK)
1874 and (not gJustChatted) and (not gConsoleShow) and (not gChatShow)
1875 and (g_ActiveWindow = nil)
1877 or (g_Game_IsNet and ((gInterTime > gInterEndTime) or ((gInterReadyCount >= NetClientCount) and (NetClientCount > 0))))
1879 then
1880 begin // Íàæàëè <Enter>/<Ïðîáåë> èëè ïðîøëî äîñòàòî÷íî âðåìåíè:
1881 g_Game_StopAllSounds(True);
1883 if gMapOnce then // Ýòî áûë òåñò
1884 gExit := EXIT_SIMPLE
1885 else
1886 if gNextMap <> '' then // Ïåðåõîäèì íà ñëåäóþùóþ êàðòó
1887 g_Game_ChangeMap(gNextMap)
1888 else // Ñëåäóþùåé êàðòû íåò
1889 begin
1890 if gGameSettings.GameType in [GT_CUSTOM, GT_SERVER] then
1891 begin
1892 // Âûõîä â ãëàâíîå ìåíþ:
1893 g_Game_Free;
1894 g_GUI_ShowWindow('MainMenu');
1895 gMusic.SetByName('MUSIC_MENU');
1896 gMusic.Play();
1897 gState := STATE_MENU;
1898 end else
1899 begin
1900 // Ôèíàëüíàÿ êàðòèíêà:
1901 g_Game_ExecuteEvent('onwadend');
1902 g_Game_Free();
1903 if not gMusic.SetByName('MUSIC_endmus') then
1904 gMusic.SetByName('MUSIC_STDENDMUS');
1905 gMusic.Play();
1906 gState := STATE_ENDPIC;
1907 end;
1908 g_Game_ExecuteEvent('ongameend');
1909 end;
1911 Exit;
1912 end
1913 else if g_Game_IsClient and
1916 e_KeyPressed(IK_RETURN) or e_KeyPressed(IK_KPRETURN) or e_KeyPressed(IK_SPACE) or
1917 e_KeyPressed(VK_FIRE) or e_KeyPressed(VK_OPEN) or
1918 e_KeyPressed(JOY0_ATTACK) or e_KeyPressed(JOY1_ATTACK) or
1919 e_KeyPressed(JOY2_ATTACK) or e_KeyPressed(JOY3_ATTACK)
1921 and (not gJustChatted) and (not gConsoleShow) and (not gChatShow)
1922 and (g_ActiveWindow = nil)
1924 then
1925 begin
1926 // ready / unready
1927 InterReady();
1928 end;
1930 if gState = STATE_INTERTEXT then
1931 if InterText.counter > 0 then
1932 InterText.counter := InterText.counter - 1;
1933 end;
1935 STATE_FOLD: // Çàòóõàíèå ýêðàíà
1936 begin
1937 if EndingGameCounter = 0 then
1938 begin
1939 // Çàêîí÷èëñÿ óðîâåíü â Ñâîåé èãðå:
1940 if gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT] then
1941 begin
1942 gState := STATE_INTERCUSTOM;
1943 InterReadyTime := -1;
1944 if gLastMap and (gGameSettings.GameMode = GM_COOP) then
1945 begin
1946 g_Game_ExecuteEvent('onwadend');
1947 if not gMusic.SetByName('MUSIC_endmus') then
1948 gMusic.SetByName('MUSIC_STDENDMUS');
1949 end
1950 else
1951 gMusic.SetByName('MUSIC_ROUNDMUS');
1952 gMusic.Play();
1953 e_UnpressAllKeys();
1954 end
1955 else // Çàêîí÷èëàñü ïîñëåäíÿÿ êàðòà â Îäèíî÷íîé èãðå
1956 begin
1957 gMusic.SetByName('MUSIC_INTERMUS');
1958 gMusic.Play();
1959 gState := STATE_INTERSINGLE;
1960 e_UnpressAllKeys();
1961 end;
1962 g_Game_ExecuteEvent('oninter');
1963 end
1964 else
1965 DecMin(EndingGameCounter, 6, 0);
1966 end;
1968 STATE_ENDPIC: // Êàðòèíêà îêîí÷àíèÿ ìåãàÂàäà
1969 begin
1970 if gMapOnce then // Ýòî áûë òåñò
1971 begin
1972 gExit := EXIT_SIMPLE;
1973 Exit;
1974 end;
1975 end;
1977 STATE_SLIST:
1978 g_Serverlist_Control(slCurrent, slTable);
1979 end;
1981 // Ñòàòèñòèêà ïî Tab:
1982 if gGameOn then
1983 IsDrawStat := (not gConsoleShow) and (not gChatShow) and (gGameSettings.GameType <> GT_SINGLE) and g_Console_Action(ACTION_SCORES);
1985 // Èãðà èäåò:
1986 if gGameOn and not gPause and (gState <> STATE_FOLD) then
1987 begin
1988 // Âðåìÿ += 28 ìèëëèñåêóíä:
1989 gTime := gTime + GAME_TICK;
1991 // Ñîîáùåíèå ïîñåðåäèíå ýêðàíà:
1992 if MessageTime = 0 then
1993 MessageText := '';
1994 if MessageTime > 0 then
1995 MessageTime := MessageTime - 1;
1997 if (g_Game_IsServer) then
1998 begin
1999 // Áûë çàäàí ëèìèò âðåìåíè:
2000 if (gGameSettings.TimeLimit > 0) then
2001 if (gTime - gGameStartTime) div 1000 >= gGameSettings.TimeLimit then
2002 begin // Îí ïðîøåë => êîíåö óðîâíÿ
2003 g_Game_NextLevel();
2004 Exit;
2005 end;
2007 // Íàäî ðåñïàâíèòü èãðîêîâ â LMS:
2008 if (gLMSRespawn > LMS_RESPAWN_NONE) and (gLMSRespawnTime < gTime) then
2009 g_Game_RestartRound(gLMSSoftSpawn);
2011 // Ïðîâåðèì ðåçóëüòàò ãîëîñîâàíèÿ, åñëè âðåìÿ ïðîøëî
2012 if gVoteInProgress and (gVoteTimer < gTime) then
2013 g_Game_CheckVote
2014 else if gVotePassed and (gVoteCmdTimer < gTime) then
2015 begin
2016 g_Console_Process(gVoteCommand);
2017 gVoteCommand := '';
2018 gVotePassed := False;
2019 end;
2021 // Çàìåðÿåì âðåìÿ çàõâàòà ôëàãîâ
2022 if gFlags[FLAG_RED].State = FLAG_STATE_CAPTURED then
2023 gFlags[FLAG_RED].CaptureTime := gFlags[FLAG_RED].CaptureTime + GAME_TICK;
2024 if gFlags[FLAG_BLUE].State = FLAG_STATE_CAPTURED then
2025 gFlags[FLAG_BLUE].CaptureTime := gFlags[FLAG_BLUE].CaptureTime + GAME_TICK;
2027 // Áûë çàäàí ëèìèò ïîáåä:
2028 if (gGameSettings.ScoreLimit > 0) then
2029 begin
2030 b := 0;
2032 if gGameSettings.GameMode = GM_DM then
2033 begin // Â DM èùåì èãðîêà ñ max ôðàãàìè
2034 for i := 0 to High(gPlayers) do
2035 if gPlayers[i] <> nil then
2036 if gPlayers[i].Frags > b then
2037 b := gPlayers[i].Frags;
2038 end
2039 else
2040 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
2041 begin //  CTF/TDM âûáèðàåì êîìàíäó ñ íàèáîëüøèì ñ÷åòîì
2042 b := Max(gTeamStat[TEAM_RED].Score, gTeamStat[TEAM_BLUE].Score);
2043 end;
2045 // Ëèìèò ïîáåä íàáðàí => êîíåö óðîâíÿ:
2046 if b >= gGameSettings.ScoreLimit then
2047 begin
2048 g_Game_NextLevel();
2049 Exit;
2050 end;
2051 end;
2053 // Îáðàáàòûâàåì êëàâèøè èãðîêîâ:
2054 if gPlayer1 <> nil then gPlayer1.ReleaseKeys();
2055 if gPlayer2 <> nil then gPlayer2.ReleaseKeys();
2056 if (not gConsoleShow) and (not gChatShow) and (g_ActiveWindow = nil) then
2057 begin
2058 ProcessPlayerControls(gPlayer1, 0, P1MoveButton);
2059 ProcessPlayerControls(gPlayer2, 1, P2MoveButton);
2060 end // if not console
2061 else
2062 begin
2063 if g_Game_IsNet and (gPlayer1 <> nil) then gPlayer1.PressKey(KEY_CHAT, 10000);
2064 end;
2065 // process weapon switch queue
2066 end; // if server
2068 // Íàáëþäàòåëü
2069 if (gPlayer1 = nil) and (gPlayer2 = nil) and
2070 (not gConsoleShow) and (not gChatShow) and (g_ActiveWindow = nil) then
2071 begin
2072 if not gSpectKeyPress then
2073 begin
2074 if gPlayerAction[0, ACTION_JUMP] and (not gSpectAuto) then
2075 begin
2076 // switch spect mode
2077 case gSpectMode of
2078 SPECT_NONE: ; // not spectator
2079 SPECT_STATS,
2080 SPECT_MAPVIEW: Inc(gSpectMode);
2081 SPECT_PLAYERS: gSpectMode := SPECT_STATS; // reset to 1
2082 end;
2083 gSpectKeyPress := True;
2084 end;
2085 if (gSpectMode = SPECT_MAPVIEW)
2086 and (not gSpectAuto) then
2087 begin
2088 if gPlayerAction[0, ACTION_MOVELEFT] then
2089 gSpectX := Max(gSpectX - gSpectStep, 0);
2090 if gPlayerAction[0, ACTION_MOVERIGHT] then
2091 gSpectX := Min(gSpectX + gSpectStep, gMapInfo.Width - gScreenWidth);
2092 if gPlayerAction[0, ACTION_LOOKUP] then
2093 gSpectY := Max(gSpectY - gSpectStep, 0);
2094 if gPlayerAction[0, ACTION_LOOKDOWN] then
2095 gSpectY := Min(gSpectY + gSpectStep, gMapInfo.Height - gScreenHeight);
2096 if gWeaponAction[0, WP_PREV] then
2097 begin
2098 // decrease step
2099 if gSpectStep > 4 then gSpectStep := gSpectStep shr 1;
2100 gWeaponAction[0, WP_PREV] := False;
2101 end;
2102 if gWeaponAction[0, WP_NEXT] then
2103 begin
2104 // increase step
2105 if gSpectStep < 64 then gSpectStep := gSpectStep shl 1;
2106 gWeaponAction[0, WP_NEXT] := False;
2107 end;
2108 end;
2109 if (gSpectMode = SPECT_PLAYERS)
2110 and (not gSpectAuto) then
2111 begin
2112 if gPlayerAction[0, ACTION_LOOKUP] then
2113 begin
2114 // add second view
2115 gSpectViewTwo := True;
2116 gSpectKeyPress := True;
2117 end;
2118 if gPlayerAction[0, ACTION_LOOKDOWN] then
2119 begin
2120 // remove second view
2121 gSpectViewTwo := False;
2122 gSpectKeyPress := True;
2123 end;
2124 if gPlayerAction[0, ACTION_MOVELEFT] then
2125 begin
2126 // prev player (view 1)
2127 gSpectPID1 := GetActivePlayerID_Prev(gSpectPID1);
2128 gSpectKeyPress := True;
2129 end;
2130 if gPlayerAction[0, ACTION_MOVERIGHT] then
2131 begin
2132 // next player (view 1)
2133 gSpectPID1 := GetActivePlayerID_Next(gSpectPID1);
2134 gSpectKeyPress := True;
2135 end;
2136 if gWeaponAction[0, WP_PREV] then
2137 begin
2138 // prev player (view 2)
2139 gSpectPID2 := GetActivePlayerID_Prev(gSpectPID2);
2140 gWeaponAction[0, WP_PREV] := False;
2141 end;
2142 if gWeaponAction[0, WP_NEXT] then
2143 begin
2144 // next player (view 2)
2145 gSpectPID2 := GetActivePlayerID_Next(gSpectPID2);
2146 gWeaponAction[0, WP_NEXT] := False;
2147 end;
2148 end;
2149 if gPlayerAction[0, ACTION_ATTACK] then
2150 begin
2151 if (gSpectMode = SPECT_STATS) and (not gSpectAuto) then
2152 begin
2153 gSpectAuto := True;
2154 gSpectAutoNext := 0;
2155 gSpectViewTwo := False;
2156 gSpectKeyPress := True;
2157 end
2158 else
2159 if gSpectAuto then
2160 begin
2161 gSpectMode := SPECT_STATS;
2162 gSpectAuto := False;
2163 gSpectKeyPress := True;
2164 end;
2165 end;
2166 end
2167 else
2168 if (not gPlayerAction[0, ACTION_JUMP]) and
2169 (not gPlayerAction[0, ACTION_ATTACK]) and
2170 (not gPlayerAction[0, ACTION_MOVELEFT]) and
2171 (not gPlayerAction[0, ACTION_MOVERIGHT]) and
2172 (not gPlayerAction[0, ACTION_LOOKUP]) and
2173 (not gPlayerAction[0, ACTION_LOOKDOWN]) then
2174 gSpectKeyPress := False;
2176 if gSpectAuto then
2177 begin
2178 if gSpectMode = SPECT_MAPVIEW then
2179 begin
2180 i := Min(Max(gSpectX + gSpectAutoStepX, 0), gMapInfo.Width - gScreenWidth);
2181 if i = gSpectX then
2182 gSpectAutoNext := gTime
2183 else
2184 gSpectX := i;
2185 i := Min(Max(gSpectY + gSpectAutoStepY, 0), gMapInfo.Height - gScreenHeight);
2186 if i = gSpectY then
2187 gSpectAutoNext := gTime
2188 else
2189 gSpectY := i;
2190 end;
2191 if gSpectAutoNext <= gTime then
2192 begin
2193 if gSpectAutoNext > 0 then
2194 begin
2195 gSpectMode := GetRandomSpectMode(gSpectMode);
2196 case gSpectMode of
2197 SPECT_MAPVIEW:
2198 begin
2199 gSpectX := Random(gMapInfo.Width - gScreenWidth);
2200 gSpectY := Random(gMapInfo.Height - gScreenHeight);
2201 gSpectAutoStepX := Random(9) - 4;
2202 gSpectAutoStepY := Random(9) - 4;
2203 if ((gSpectX < 800) and (gSpectAutoStepX < 0)) or
2204 ((gSpectX > gMapInfo.Width - gScreenWidth - 800) and (gSpectAutoStepX > 0)) then
2205 gSpectAutoStepX := gSpectAutoStepX * -1;
2206 if ((gSpectY < 800) and (gSpectAutoStepY < 0)) or
2207 ((gSpectY > gMapInfo.Height - gScreenHeight - 800) and (gSpectAutoStepY > 0)) then
2208 gSpectAutoStepY := gSpectAutoStepY * -1;
2209 end;
2210 SPECT_PLAYERS:
2211 begin
2212 gSpectPID1 := GetActivePlayerID_Random(gSpectPID1);
2213 end;
2214 end;
2215 end;
2216 case gSpectMode of
2217 SPECT_STATS: gSpectAutoNext := gTime + (Random(3) + 5) * 1000;
2218 SPECT_MAPVIEW: gSpectAutoNext := gTime + (Random(4) + 7) * 1000;
2219 SPECT_PLAYERS: gSpectAutoNext := gTime + (Random(7) + 8) * 1000;
2220 end;
2221 end;
2222 end;
2223 end;
2225 // Îáíîâëÿåì âñå îñòàëüíîå:
2226 g_Map_Update();
2227 g_Items_Update();
2228 g_Triggers_Update();
2229 g_Weapon_Update();
2230 g_Monsters_Update();
2231 g_GFX_Update();
2232 g_Player_UpdateAll();
2233 g_Player_UpdatePhysicalObjects();
2235 // server: send newly spawned monsters unconditionally
2236 if (gGameSettings.GameType = GT_SERVER) then
2237 begin
2238 if (Length(gMonstersSpawned) > 0) then
2239 begin
2240 for I := 0 to High(gMonstersSpawned) do MH_SEND_MonsterSpawn(gMonstersSpawned[I]);
2241 SetLength(gMonstersSpawned, 0);
2242 end;
2243 end;
2245 if (gSoundTriggerTime > 8) then
2246 begin
2247 g_Game_UpdateTriggerSounds();
2248 gSoundTriggerTime := 0;
2249 end
2250 else
2251 begin
2252 Inc(gSoundTriggerTime);
2253 end;
2255 if (NetMode = NET_SERVER) then
2256 begin
2257 Inc(NetTimeToUpdate);
2258 Inc(NetTimeToReliable);
2260 // send monster updates
2261 if (NetTimeToReliable >= NetRelupdRate) or (NetTimeToUpdate >= NetUpdateRate) then
2262 begin
2263 // send all monsters (periodic sync)
2264 reliableUpdate := (NetTimeToReliable >= NetRelupdRate);
2266 for I := 0 to High(gPlayers) do
2267 begin
2268 if (gPlayers[I] <> nil) then MH_SEND_PlayerPos(reliableUpdate, gPlayers[I].UID);
2269 end;
2271 g_Mons_ForEach(sendMonsPos);
2273 // update flags that aren't stationary
2274 if gGameSettings.GameMode = GM_CTF then
2275 for I := FLAG_RED to FLAG_BLUE do
2276 if gFlags[I].NeedSend then
2277 begin
2278 gFlags[I].NeedSend := False;
2279 MH_SEND_FlagPos(I);
2280 end;
2282 // update items that aren't stationary
2283 g_Items_ForEachAlive(sendItemPos);
2285 if reliableUpdate then
2286 begin
2287 NetTimeToReliable := 0;
2288 NetTimeToUpdate := NetUpdateRate;
2289 end
2290 else
2291 begin
2292 NetTimeToUpdate := 0;
2293 end;
2294 end
2295 else
2296 begin
2297 // send only mosters with some unexpected changes
2298 g_Mons_ForEach(sendMonsPosUnexpected);
2299 end;
2301 // send unexpected platform changes
2302 g_Map_NetSendInterestingPanels();
2304 g_Net_Slist_ServerUpdate();
2306 if NetUseMaster then
2307 begin
2308 if (gTime >= NetTimeToMaster) or g_Net_Slist_IsConnectionInProgress then
2309 begin
2310 if (not g_Net_Slist_IsConnectionActive) then g_Net_Slist_Connect(false); // non-blocking connection to the master
2311 g_Net_Slist_Update;
2312 NetTimeToMaster := gTime + NetMasterRate;
2313 end;
2314 end;
2316 end
2317 else if (NetMode = NET_CLIENT) then
2318 begin
2319 MC_SEND_PlayerPos();
2320 end;
2321 end; // if gameOn ...
2323 // Àêòèâíî îêíî èíòåðôåéñà - ïåðåäàåì êëàâèøè åìó:
2324 if g_ActiveWindow <> nil then
2325 begin
2326 w := e_GetFirstKeyPressed();
2328 if (w <> IK_INVALID) then
2329 begin
2330 Msg.Msg := MESSAGE_DIKEY;
2331 Msg.wParam := w;
2332 g_ActiveWindow.OnMessage(Msg);
2333 end;
2335 // Åñëè îíî îò ýòîãî íå çàêðûëîñü, òî îáíîâëÿåì:
2336 if g_ActiveWindow <> nil then
2337 g_ActiveWindow.Update();
2339 // Íóæíî ñìåíèòü ðàçðåøåíèå:
2340 if gResolutionChange then
2341 begin
2342 e_WriteLog('Changing resolution', TMsgType.Notify);
2343 g_Game_ChangeResolution(gRC_Width, gRC_Height, gRC_FullScreen, gRC_Maximized);
2344 gResolutionChange := False;
2345 g_ActiveWindow := nil;
2346 end;
2348 // Íóæíî ñìåíèòü ÿçûê:
2349 if gLanguageChange then
2350 begin
2351 //e_WriteLog('Read language file', MSG_NOTIFY);
2352 //g_Language_Load(DataDir + gLanguage + '.txt');
2353 g_Language_Set(gLanguage);
2354 {$IFNDEF HEADLESS}
2355 g_Menu_Reset();
2356 {$ENDIF}
2357 gLanguageChange := False;
2358 end;
2359 end;
2361 // Ãîðÿ÷àÿ êëàâèøà äëÿ âûçîâà ìåíþ âûõîäà èç èãðû (F10):
2362 if e_KeyPressed(IK_F10) and
2363 gGameOn and
2364 (not gConsoleShow) and
2365 (g_ActiveWindow = nil) then
2366 begin
2367 KeyPress(IK_F10);
2368 end;
2370 Time := sys_GetTicks() {div 1000};
2372 // Îáðàáîòêà îòëîæåííûõ ñîáûòèé:
2373 if gDelayedEvents <> nil then
2374 for a := 0 to High(gDelayedEvents) do
2375 if gDelayedEvents[a].Pending and
2377 ((gDelayedEvents[a].DEType = DE_GLOBEVENT) and (gDelayedEvents[a].Time <= Time)) or
2378 ((gDelayedEvents[a].DEType > DE_GLOBEVENT) and (gDelayedEvents[a].Time <= gTime))
2379 ) then
2380 begin
2381 case gDelayedEvents[a].DEType of
2382 DE_GLOBEVENT:
2383 g_Game_ExecuteEvent(gDelayedEvents[a].DEStr);
2384 DE_BFGHIT:
2385 if gGameOn then
2386 g_Game_Announce_GoodShot(gDelayedEvents[a].DENum);
2387 DE_KILLCOMBO:
2388 if gGameOn then
2389 begin
2390 g_Game_Announce_KillCombo(gDelayedEvents[a].DENum);
2391 if g_Game_IsNet and g_Game_IsServer then
2392 MH_SEND_GameEvent(NET_EV_KILLCOMBO, gDelayedEvents[a].DENum);
2393 end;
2394 DE_BODYKILL:
2395 if gGameOn then
2396 g_Game_Announce_BodyKill(gDelayedEvents[a].DENum);
2397 end;
2398 gDelayedEvents[a].Pending := False;
2399 end;
2401 // Êàæäóþ ñåêóíäó îáíîâëÿåì ñ÷åò÷èê îáíîâëåíèé:
2402 UPSCounter := UPSCounter + 1;
2403 if Time - UPSTime >= 1000 then
2404 begin
2405 UPS := UPSCounter;
2406 UPSCounter := 0;
2407 UPSTime := Time;
2408 end;
2410 if gGameOn then
2411 begin
2412 g_Weapon_AddDynLights();
2413 g_Items_AddDynLights();
2414 end;
2415 end;
2417 procedure g_Game_LoadChatSounds(Resource: string);
2418 var
2419 WAD: TWADFile;
2420 FileName, Snd: string;
2421 p: Pointer;
2422 len, cnt, tags, i, j: Integer;
2423 cfg: TConfig;
2424 begin
2425 FileName := g_ExtractWadName(Resource);
2427 WAD := TWADFile.Create();
2428 WAD.ReadFile(FileName);
2430 if not WAD.GetResource(g_ExtractFilePathName(Resource), p, len) then
2431 begin
2432 gChatSounds := nil;
2433 WAD.Free();
2434 Exit;
2435 end;
2437 cfg := TConfig.CreateMem(p, len);
2438 cnt := cfg.ReadInt('ChatSounds', 'Count', 0);
2440 SetLength(gChatSounds, cnt);
2441 for i := 0 to Length(gChatSounds) - 1 do
2442 begin
2443 gChatSounds[i].Sound := nil;
2444 Snd := Trim(cfg.ReadStr(IntToStr(i), 'Sound', ''));
2445 tags := cfg.ReadInt(IntToStr(i), 'Tags', 0);
2446 if (Snd = '') or (Tags <= 0) then
2447 continue;
2448 g_Sound_CreateWADEx('SOUND_CHAT_MACRO' + IntToStr(i), GameWAD+':'+Snd);
2449 gChatSounds[i].Sound := TPlayableSound.Create();
2450 gChatSounds[i].Sound.SetByName('SOUND_CHAT_MACRO' + IntToStr(i));
2451 SetLength(gChatSounds[i].Tags, tags);
2452 for j := 0 to tags - 1 do
2453 gChatSounds[i].Tags[j] := toLowerCase1251(cfg.ReadStr(IntToStr(i), 'Tag' + IntToStr(j), ''));
2454 gChatSounds[i].FullWord := cfg.ReadBool(IntToStr(i), 'FullWord', False);
2455 end;
2457 cfg.Free();
2458 WAD.Free();
2459 end;
2461 procedure g_Game_FreeChatSounds();
2462 var
2463 i: Integer;
2464 begin
2465 for i := 0 to Length(gChatSounds) - 1 do
2466 begin
2467 gChatSounds[i].Sound.Free();
2468 g_Sound_Delete('SOUND_CHAT_MACRO' + IntToStr(i));
2469 end;
2470 SetLength(gChatSounds, 0);
2471 gChatSounds := nil;
2472 end;
2474 procedure g_Game_LoadData();
2475 var
2476 wl, hl: Integer;
2477 wr, hr: Integer;
2478 wb, hb: Integer;
2479 wm, hm: Integer;
2480 begin
2481 if DataLoaded then Exit;
2483 e_WriteLog('Loading game data...', TMsgType.Notify);
2485 g_Texture_CreateWADEx('NOTEXTURE', GameWAD+':TEXTURES\NOTEXTURE');
2486 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUD', GameWAD+':TEXTURES\HUD');
2487 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDAIR', GameWAD+':TEXTURES\AIRBAR');
2488 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDJET', GameWAD+':TEXTURES\JETBAR');
2489 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDBG', GameWAD+':TEXTURES\HUDBG');
2490 g_Texture_CreateWADEx('TEXTURE_PLAYER_ARMORHUD', GameWAD+':TEXTURES\ARMORHUD');
2491 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG', GameWAD+':TEXTURES\FLAGHUD_R_BASE');
2492 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_S', GameWAD+':TEXTURES\FLAGHUD_R_STOLEN');
2493 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_D', GameWAD+':TEXTURES\FLAGHUD_R_DROP');
2494 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG', GameWAD+':TEXTURES\FLAGHUD_B_BASE');
2495 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_S', GameWAD+':TEXTURES\FLAGHUD_B_STOLEN');
2496 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_D', GameWAD+':TEXTURES\FLAGHUD_B_DROP');
2497 g_Texture_CreateWADEx('TEXTURE_PLAYER_TALKBUBBLE', GameWAD+':TEXTURES\TALKBUBBLE');
2498 g_Texture_CreateWADEx('TEXTURE_PLAYER_INVULPENTA', GameWAD+':TEXTURES\PENTA');
2499 g_Texture_CreateWADEx('TEXTURE_PLAYER_INDICATOR', GameWAD+':TEXTURES\PLRIND');
2501 hasPBarGfx := true;
2502 if not g_Texture_CreateWADEx('UI_GFX_PBAR_LEFT', GameWAD+':TEXTURES\LLEFT') then hasPBarGfx := false;
2503 if not g_Texture_CreateWADEx('UI_GFX_PBAR_MARKER', GameWAD+':TEXTURES\LMARKER') then hasPBarGfx := false;
2504 if not g_Texture_CreateWADEx('UI_GFX_PBAR_MIDDLE', GameWAD+':TEXTURES\LMIDDLE') then hasPBarGfx := false;
2505 if not g_Texture_CreateWADEx('UI_GFX_PBAR_RIGHT', GameWAD+':TEXTURES\LRIGHT') then hasPBarGfx := false;
2507 if hasPBarGfx then
2508 begin
2509 g_Texture_GetSize('UI_GFX_PBAR_LEFT', wl, hl);
2510 g_Texture_GetSize('UI_GFX_PBAR_RIGHT', wr, hr);
2511 g_Texture_GetSize('UI_GFX_PBAR_MIDDLE', wb, hb);
2512 g_Texture_GetSize('UI_GFX_PBAR_MARKER', wm, hm);
2513 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
2514 begin
2515 // yay!
2516 end
2517 else
2518 begin
2519 hasPBarGfx := false;
2520 end;
2521 end;
2523 g_Frames_CreateWAD(nil, 'FRAMES_TELEPORT', GameWAD+':TEXTURES\TELEPORT', 64, 64, 10, False);
2524 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH', GameWAD+':WEAPONS\PUNCH', 64, 64, 4, False);
2525 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_UP', GameWAD+':WEAPONS\PUNCH_UP', 64, 64, 4, False);
2526 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_DN', GameWAD+':WEAPONS\PUNCH_DN', 64, 64, 4, False);
2527 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK', GameWAD+':WEAPONS\PUNCHB', 64, 64, 4, False);
2528 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK_UP', GameWAD+':WEAPONS\PUNCHB_UP', 64, 64, 4, False);
2529 g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK_DN', GameWAD+':WEAPONS\PUNCHB_DN', 64, 64, 4, False);
2530 g_Sound_CreateWADEx('SOUND_GAME_TELEPORT', GameWAD+':SOUNDS\TELEPORT');
2531 g_Sound_CreateWADEx('SOUND_GAME_NOTELEPORT', GameWAD+':SOUNDS\NOTELEPORT');
2532 g_Sound_CreateWADEx('SOUND_GAME_SECRET', GameWAD+':SOUNDS\SECRET');
2533 g_Sound_CreateWADEx('SOUND_GAME_DOOROPEN', GameWAD+':SOUNDS\DOOROPEN');
2534 g_Sound_CreateWADEx('SOUND_GAME_DOORCLOSE', GameWAD+':SOUNDS\DOORCLOSE');
2535 g_Sound_CreateWADEx('SOUND_GAME_BULK1', GameWAD+':SOUNDS\BULK1');
2536 g_Sound_CreateWADEx('SOUND_GAME_BULK2', GameWAD+':SOUNDS\BULK2');
2537 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE1', GameWAD+':SOUNDS\BUBBLE1');
2538 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE2', GameWAD+':SOUNDS\BUBBLE2');
2539 g_Sound_CreateWADEx('SOUND_GAME_BURNING', GameWAD+':SOUNDS\BURNING');
2540 g_Sound_CreateWADEx('SOUND_GAME_SWITCH1', GameWAD+':SOUNDS\SWITCH1');
2541 g_Sound_CreateWADEx('SOUND_GAME_SWITCH0', GameWAD+':SOUNDS\SWITCH0');
2542 g_Sound_CreateWADEx('SOUND_GAME_RADIO', GameWAD+':SOUNDS\RADIO');
2543 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD1', GameWAD+':SOUNDS\GOOD1');
2544 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD2', GameWAD+':SOUNDS\GOOD2');
2545 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD3', GameWAD+':SOUNDS\GOOD3');
2546 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD4', GameWAD+':SOUNDS\GOOD4');
2547 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL2X', GameWAD+':SOUNDS\KILL2X');
2548 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL3X', GameWAD+':SOUNDS\KILL3X');
2549 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL4X', GameWAD+':SOUNDS\KILL4X');
2550 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILLMX', GameWAD+':SOUNDS\KILLMX');
2551 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA1', GameWAD+':SOUNDS\MUHAHA1');
2552 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA2', GameWAD+':SOUNDS\MUHAHA2');
2553 g_Sound_CreateWADEx('SOUND_ANNOUNCER_MUHAHA3', GameWAD+':SOUNDS\MUHAHA3');
2554 g_Sound_CreateWADEx('SOUND_CTF_GET1', GameWAD+':SOUNDS\GETFLAG1');
2555 g_Sound_CreateWADEx('SOUND_CTF_GET2', GameWAD+':SOUNDS\GETFLAG2');
2556 g_Sound_CreateWADEx('SOUND_CTF_LOST1', GameWAD+':SOUNDS\LOSTFLG1');
2557 g_Sound_CreateWADEx('SOUND_CTF_LOST2', GameWAD+':SOUNDS\LOSTFLG2');
2558 g_Sound_CreateWADEx('SOUND_CTF_RETURN1', GameWAD+':SOUNDS\RETFLAG1');
2559 g_Sound_CreateWADEx('SOUND_CTF_RETURN2', GameWAD+':SOUNDS\RETFLAG2');
2560 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE1', GameWAD+':SOUNDS\CAPFLAG1');
2561 g_Sound_CreateWADEx('SOUND_CTF_CAPTURE2', GameWAD+':SOUNDS\CAPFLAG2');
2563 goodsnd[0] := TPlayableSound.Create();
2564 goodsnd[1] := TPlayableSound.Create();
2565 goodsnd[2] := TPlayableSound.Create();
2566 goodsnd[3] := TPlayableSound.Create();
2568 goodsnd[0].SetByName('SOUND_ANNOUNCER_GOOD1');
2569 goodsnd[1].SetByName('SOUND_ANNOUNCER_GOOD2');
2570 goodsnd[2].SetByName('SOUND_ANNOUNCER_GOOD3');
2571 goodsnd[3].SetByName('SOUND_ANNOUNCER_GOOD4');
2573 killsnd[0] := TPlayableSound.Create();
2574 killsnd[1] := TPlayableSound.Create();
2575 killsnd[2] := TPlayableSound.Create();
2576 killsnd[3] := TPlayableSound.Create();
2578 killsnd[0].SetByName('SOUND_ANNOUNCER_KILL2X');
2579 killsnd[1].SetByName('SOUND_ANNOUNCER_KILL3X');
2580 killsnd[2].SetByName('SOUND_ANNOUNCER_KILL4X');
2581 killsnd[3].SetByName('SOUND_ANNOUNCER_KILLMX');
2583 hahasnd[0] := TPlayableSound.Create();
2584 hahasnd[1] := TPlayableSound.Create();
2585 hahasnd[2] := TPlayableSound.Create();
2587 hahasnd[0].SetByName('SOUND_ANNOUNCER_MUHAHA1');
2588 hahasnd[1].SetByName('SOUND_ANNOUNCER_MUHAHA2');
2589 hahasnd[2].SetByName('SOUND_ANNOUNCER_MUHAHA3');
2591 sound_get_flag[0] := TPlayableSound.Create();
2592 sound_get_flag[1] := TPlayableSound.Create();
2593 sound_lost_flag[0] := TPlayableSound.Create();
2594 sound_lost_flag[1] := TPlayableSound.Create();
2595 sound_ret_flag[0] := TPlayableSound.Create();
2596 sound_ret_flag[1] := TPlayableSound.Create();
2597 sound_cap_flag[0] := TPlayableSound.Create();
2598 sound_cap_flag[1] := TPlayableSound.Create();
2600 sound_get_flag[0].SetByName('SOUND_CTF_GET1');
2601 sound_get_flag[1].SetByName('SOUND_CTF_GET2');
2602 sound_lost_flag[0].SetByName('SOUND_CTF_LOST1');
2603 sound_lost_flag[1].SetByName('SOUND_CTF_LOST2');
2604 sound_ret_flag[0].SetByName('SOUND_CTF_RETURN1');
2605 sound_ret_flag[1].SetByName('SOUND_CTF_RETURN2');
2606 sound_cap_flag[0].SetByName('SOUND_CTF_CAPTURE1');
2607 sound_cap_flag[1].SetByName('SOUND_CTF_CAPTURE2');
2609 g_Game_LoadChatSounds(GameWAD+':CHATSND\SNDCFG');
2611 g_Game_SetLoadingText(_lc[I_LOAD_ITEMS_DATA], 0, False);
2612 g_Items_LoadData();
2614 g_Game_SetLoadingText(_lc[I_LOAD_WEAPONS_DATA], 0, False);
2615 g_Weapon_LoadData();
2617 g_Monsters_LoadData();
2619 DataLoaded := True;
2620 end;
2622 procedure g_Game_FreeData();
2623 begin
2624 if not DataLoaded then Exit;
2626 g_Items_FreeData();
2627 g_Weapon_FreeData();
2628 g_Monsters_FreeData();
2630 e_WriteLog('Releasing game data...', TMsgType.Notify);
2632 g_Texture_Delete('NOTEXTURE');
2633 g_Texture_Delete('TEXTURE_PLAYER_HUD');
2634 g_Texture_Delete('TEXTURE_PLAYER_HUDBG');
2635 g_Texture_Delete('TEXTURE_PLAYER_ARMORHUD');
2636 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG');
2637 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_S');
2638 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_D');
2639 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG');
2640 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_S');
2641 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_D');
2642 g_Texture_Delete('TEXTURE_PLAYER_TALKBUBBLE');
2643 g_Texture_Delete('TEXTURE_PLAYER_INVULPENTA');
2644 g_Frames_DeleteByName('FRAMES_TELEPORT');
2645 g_Frames_DeleteByName('FRAMES_PUNCH');
2646 g_Frames_DeleteByName('FRAMES_PUNCH_UP');
2647 g_Frames_DeleteByName('FRAMES_PUNCH_DN');
2648 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK');
2649 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK_UP');
2650 g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK_DN');
2651 g_Sound_Delete('SOUND_GAME_TELEPORT');
2652 g_Sound_Delete('SOUND_GAME_NOTELEPORT');
2653 g_Sound_Delete('SOUND_GAME_SECRET');
2654 g_Sound_Delete('SOUND_GAME_DOOROPEN');
2655 g_Sound_Delete('SOUND_GAME_DOORCLOSE');
2656 g_Sound_Delete('SOUND_GAME_BULK1');
2657 g_Sound_Delete('SOUND_GAME_BULK2');
2658 g_Sound_Delete('SOUND_GAME_BUBBLE1');
2659 g_Sound_Delete('SOUND_GAME_BUBBLE2');
2660 g_Sound_Delete('SOUND_GAME_BURNING');
2661 g_Sound_Delete('SOUND_GAME_SWITCH1');
2662 g_Sound_Delete('SOUND_GAME_SWITCH0');
2664 goodsnd[0].Free();
2665 goodsnd[1].Free();
2666 goodsnd[2].Free();
2667 goodsnd[3].Free();
2669 g_Sound_Delete('SOUND_ANNOUNCER_GOOD1');
2670 g_Sound_Delete('SOUND_ANNOUNCER_GOOD2');
2671 g_Sound_Delete('SOUND_ANNOUNCER_GOOD3');
2672 g_Sound_Delete('SOUND_ANNOUNCER_GOOD4');
2674 killsnd[0].Free();
2675 killsnd[1].Free();
2676 killsnd[2].Free();
2677 killsnd[3].Free();
2679 g_Sound_Delete('SOUND_ANNOUNCER_KILL2X');
2680 g_Sound_Delete('SOUND_ANNOUNCER_KILL3X');
2681 g_Sound_Delete('SOUND_ANNOUNCER_KILL4X');
2682 g_Sound_Delete('SOUND_ANNOUNCER_KILLMX');
2684 hahasnd[0].Free();
2685 hahasnd[1].Free();
2686 hahasnd[2].Free();
2688 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA1');
2689 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA2');
2690 g_Sound_Delete('SOUND_ANNOUNCER_MUHAHA3');
2692 sound_get_flag[0].Free();
2693 sound_get_flag[1].Free();
2694 sound_lost_flag[0].Free();
2695 sound_lost_flag[1].Free();
2696 sound_ret_flag[0].Free();
2697 sound_ret_flag[1].Free();
2698 sound_cap_flag[0].Free();
2699 sound_cap_flag[1].Free();
2701 g_Sound_Delete('SOUND_CTF_GET1');
2702 g_Sound_Delete('SOUND_CTF_GET2');
2703 g_Sound_Delete('SOUND_CTF_LOST1');
2704 g_Sound_Delete('SOUND_CTF_LOST2');
2705 g_Sound_Delete('SOUND_CTF_RETURN1');
2706 g_Sound_Delete('SOUND_CTF_RETURN2');
2707 g_Sound_Delete('SOUND_CTF_CAPTURE1');
2708 g_Sound_Delete('SOUND_CTF_CAPTURE2');
2710 g_Game_FreeChatSounds();
2712 DataLoaded := False;
2713 end;
2715 procedure DrawCustomStat();
2716 var
2717 pc, x, y, w, _y,
2718 w1, w2, w3,
2719 t, p, m: Integer;
2720 ww1, hh1: Word;
2721 ww2, hh2, r, g, b, rr, gg, bb: Byte;
2722 s1, s2, topstr: String;
2723 begin
2724 e_TextureFontGetSize(gStdFont, ww2, hh2);
2726 sys_HandleInput;
2728 if g_Console_Action(ACTION_SCORES) then
2729 begin
2730 if not gStatsPressed then
2731 begin
2732 gStatsOff := not gStatsOff;
2733 gStatsPressed := True;
2734 end;
2735 end
2736 else
2737 gStatsPressed := False;
2739 if gStatsOff then
2740 begin
2741 s1 := _lc[I_MENU_INTER_NOTICE_TAB];
2742 w := (Length(s1) * ww2) div 2;
2743 x := gScreenWidth div 2 - w;
2744 y := 8;
2745 e_TextureFontPrint(x, y, s1, gStdFont);
2746 Exit;
2747 end;
2749 if (gGameSettings.GameMode = GM_COOP) then
2750 begin
2751 if gMissionFailed then
2752 topstr := _lc[I_MENU_INTER_MISSION_FAIL]
2753 else
2754 topstr := _lc[I_MENU_INTER_LEVEL_COMPLETE];
2755 end
2756 else
2757 topstr := _lc[I_MENU_INTER_ROUND_OVER];
2759 e_CharFont_GetSize(gMenuFont, topstr, ww1, hh1);
2760 e_CharFont_Print(gMenuFont, (gScreenWidth div 2)-(ww1 div 2), 16, topstr);
2762 if g_Game_IsNet then
2763 begin
2764 topstr := Format(_lc[I_MENU_INTER_NOTICE_TIME], [gServInterTime]);
2765 if not gChatShow then
2766 e_TextureFontPrintEx((gScreenWidth div 2)-(Length(topstr)*ww2 div 2),
2767 gScreenHeight-(hh2+4)*2, topstr, gStdFont, 255, 255, 255, 1);
2768 end;
2770 if g_Game_IsClient then
2771 topstr := _lc[I_MENU_INTER_NOTICE_MAP]
2772 else
2773 topstr := _lc[I_MENU_INTER_NOTICE_SPACE];
2774 if not gChatShow then
2775 e_TextureFontPrintEx((gScreenWidth div 2)-(Length(topstr)*ww2 div 2),
2776 gScreenHeight-(hh2+4), topstr, gStdFont, 255, 255, 255, 1);
2778 x := 32;
2779 y := 16+hh1+16;
2781 w := gScreenWidth-x*2;
2783 w2 := (w-16) div 6;
2784 w3 := w2;
2785 w1 := w-16-w2-w3;
2787 e_DrawFillQuad(x, y, gScreenWidth-x-1, gScreenHeight-y-1, 64, 64, 64, 32);
2788 e_DrawQuad(x, y, gScreenWidth-x-1, gScreenHeight-y-1, 255, 127, 0);
2790 m := Max(Length(_lc[I_MENU_MAP])+1, Length(_lc[I_GAME_GAME_TIME])+1)*ww2;
2792 case CustomStat.GameMode of
2793 GM_DM:
2794 begin
2795 if gGameSettings.MaxLives = 0 then
2796 s1 := _lc[I_GAME_DM]
2797 else
2798 s1 := _lc[I_GAME_LMS];
2799 end;
2800 GM_TDM:
2801 begin
2802 if gGameSettings.MaxLives = 0 then
2803 s1 := _lc[I_GAME_TDM]
2804 else
2805 s1 := _lc[I_GAME_TLMS];
2806 end;
2807 GM_CTF: s1 := _lc[I_GAME_CTF];
2808 GM_COOP:
2809 begin
2810 if gGameSettings.MaxLives = 0 then
2811 s1 := _lc[I_GAME_COOP]
2812 else
2813 s1 := _lc[I_GAME_SURV];
2814 end;
2815 else s1 := '';
2816 end;
2818 _y := y+16;
2819 e_TextureFontPrintEx(x+(w div 2)-(Length(s1)*ww2 div 2), _y, s1, gStdFont, 255, 255, 255, 1);
2820 _y := _y+8;
2822 _y := _y+16;
2823 e_TextureFontPrintEx(x+8, _y, _lc[I_MENU_MAP], gStdFont, 255, 127, 0, 1);
2824 e_TextureFontPrint(x+8+m, _y, Format('%s - %s', [CustomStat.Map, CustomStat.MapName]), gStdFont);
2826 _y := _y+16;
2827 e_TextureFontPrintEx(x+8, _y, _lc[I_GAME_GAME_TIME], gStdFont, 255, 127, 0, 1);
2828 e_TextureFontPrint(x+8+m, _y, Format('%d:%.2d:%.2d', [CustomStat.GameTime div 1000 div 3600,
2829 (CustomStat.GameTime div 1000 div 60) mod 60,
2830 CustomStat.GameTime div 1000 mod 60]), gStdFont);
2832 pc := Length(CustomStat.PlayerStat);
2833 if pc = 0 then Exit;
2835 if CustomStat.GameMode = GM_COOP then
2836 begin
2837 m := Max(Length(_lc[I_GAME_MONSTERS])+1, Length(_lc[I_GAME_SECRETS])+1)*ww2;
2838 _y := _y+32;
2839 s2 := _lc[I_GAME_MONSTERS];
2840 e_TextureFontPrintEx(x+8, _y, s2, gStdFont, 255, 127, 0, 1);
2841 e_TextureFontPrintEx(x+8+m, _y, IntToStr(gCoopMonstersKilled) + '/' + IntToStr(gTotalMonsters), gStdFont, 255, 255, 255, 1);
2842 _y := _y+16;
2843 s2 := _lc[I_GAME_SECRETS];
2844 e_TextureFontPrintEx(x+8, _y, s2, gStdFont, 255, 127, 0, 1);
2845 e_TextureFontPrintEx(x+8+m, _y, IntToStr(gCoopSecretsFound) + '/' + IntToStr(gSecretsCount), gStdFont, 255, 255, 255, 1);
2846 if gLastMap then
2847 begin
2848 m := Max(Length(_lc[I_GAME_MONSTERS_TOTAL])+1, Length(_lc[I_GAME_SECRETS_TOTAL])+1)*ww2;
2849 _y := _y-16;
2850 s2 := _lc[I_GAME_MONSTERS_TOTAL];
2851 e_TextureFontPrintEx(x+250, _y, s2, gStdFont, 255, 127, 0, 1);
2852 e_TextureFontPrintEx(x+250+m, _y, IntToStr(gCoopTotalMonstersKilled) + '/' + IntToStr(gCoopTotalMonsters), gStdFont, 255, 255, 255, 1);
2853 _y := _y+16;
2854 s2 := _lc[I_GAME_SECRETS_TOTAL];
2855 e_TextureFontPrintEx(x+250, _y, s2, gStdFont, 255, 127, 0, 1);
2856 e_TextureFontPrintEx(x+250+m, _y, IntToStr(gCoopTotalSecretsFound) + '/' + IntToStr(gCoopTotalSecrets), gStdFont, 255, 255, 255, 1);
2857 end;
2858 end;
2860 if CustomStat.GameMode in [GM_TDM, GM_CTF] then
2861 begin
2862 _y := _y+16+16;
2864 with CustomStat do
2865 if TeamStat[TEAM_RED].Score > TeamStat[TEAM_BLUE].Score then s1 := _lc[I_GAME_WIN_RED]
2866 else if TeamStat[TEAM_BLUE].Score > TeamStat[TEAM_RED].Score then s1 := _lc[I_GAME_WIN_BLUE]
2867 else s1 := _lc[I_GAME_WIN_DRAW];
2869 e_TextureFontPrintEx(x+8+(w div 2)-(Length(s1)*ww2 div 2), _y, s1, gStdFont, 255, 255, 255, 1);
2870 _y := _y+40;
2872 for t := TEAM_RED to TEAM_BLUE do
2873 begin
2874 if t = TEAM_RED then
2875 begin
2876 e_TextureFontPrintEx(x+8, _y, _lc[I_GAME_TEAM_RED],
2877 gStdFont, 255, 0, 0, 1);
2878 e_TextureFontPrintEx(x+w1+8, _y, IntToStr(CustomStat.TeamStat[TEAM_RED].Score),
2879 gStdFont, 255, 0, 0, 1);
2880 r := 255;
2881 g := 0;
2882 b := 0;
2883 end
2884 else
2885 begin
2886 e_TextureFontPrintEx(x+8, _y, _lc[I_GAME_TEAM_BLUE],
2887 gStdFont, 0, 0, 255, 1);
2888 e_TextureFontPrintEx(x+w1+8, _y, IntToStr(CustomStat.TeamStat[TEAM_BLUE].Score),
2889 gStdFont, 0, 0, 255, 1);
2890 r := 0;
2891 g := 0;
2892 b := 255;
2893 end;
2895 e_DrawLine(1, x+8, _y+20, x-8+w, _y+20, r, g, b);
2896 _y := _y+24;
2898 for p := 0 to High(CustomStat.PlayerStat) do
2899 if CustomStat.PlayerStat[p].Team = t then
2900 with CustomStat.PlayerStat[p] do
2901 begin
2902 if Spectator then
2903 begin
2904 rr := r div 2;
2905 gg := g div 2;
2906 bb := b div 2;
2907 end
2908 else
2909 begin
2910 rr := r;
2911 gg := g;
2912 bb := b;
2913 end;
2914 if (gPlayers[Num] <> nil) and (gPlayers[Num].FReady) then
2915 e_TextureFontPrintEx(x+16, _y, Name + ' *', gStdFont, rr, gg, bb, 1)
2916 else
2917 e_TextureFontPrintEx(x+16, _y, Name, gStdFont, rr, gg, bb, 1);
2918 e_TextureFontPrintEx(x+w1+16, _y, IntToStr(Frags), gStdFont, rr, gg, bb, 1);
2919 e_TextureFontPrintEx(x+w1+w2+16, _y, IntToStr(Deaths), gStdFont, rr, gg, bb, 1);
2920 _y := _y+24;
2921 end;
2923 _y := _y+16+16;
2924 end;
2925 end
2926 else if CustomStat.GameMode in [GM_DM, GM_COOP] then
2927 begin
2928 _y := _y+40;
2929 e_TextureFontPrintEx(x+8, _y, _lc[I_GAME_PLAYER_NAME], gStdFont, 255, 127, 0, 1);
2930 e_TextureFontPrintEx(x+8+w1, _y, _lc[I_GAME_FRAGS], gStdFont, 255, 127, 0, 1);
2931 e_TextureFontPrintEx(x+8+w1+w2, _y, _lc[I_GAME_DEATHS], gStdFont, 255, 127, 0, 1);
2933 _y := _y+24;
2934 for p := 0 to High(CustomStat.PlayerStat) do
2935 with CustomStat.PlayerStat[p] do
2936 begin
2937 e_DrawFillQuad(x+8, _y+4, x+24-1, _y+16+4-1, Color.R, Color.G, Color.B, 0);
2939 if Spectator then
2940 r := 127
2941 else
2942 r := 255;
2944 if (gPlayers[Num] <> nil) and (gPlayers[Num].FReady) then
2945 e_TextureFontPrintEx(x+8+16+8, _y+4, Name + ' *', gStdFont, r, r, r, 1, True)
2946 else
2947 e_TextureFontPrintEx(x+8+16+8, _y+4, Name, gStdFont, r, r, r, 1, True);
2948 e_TextureFontPrintEx(x+w1+8+16+8, _y+4, IntToStr(Frags), gStdFont, r, r, r, 1, True);
2949 e_TextureFontPrintEx(x+w1+w2+8+16+8, _y+4, IntToStr(Deaths), gStdFont, r, r, r, 1, True);
2950 _y := _y+24;
2951 end;
2952 end;
2954 // HACK: take stats screenshot immediately after the first frame of the stats showing
2955 if gScreenshotStats and (not StatShotDone) and (Length(CustomStat.PlayerStat) > 1) then
2956 begin
2957 g_TakeScreenShot('stats/' + StatFilename);
2958 StatShotDone := True;
2959 end;
2960 end;
2962 procedure DrawSingleStat();
2963 var
2964 tm, key_x, val_x, y: Integer;
2965 w1, w2, h: Word;
2966 s1, s2: String;
2968 procedure player_stat(n: Integer);
2969 var
2970 kpm: Real;
2972 begin
2973 // "Kills: # / #":
2974 s1 := Format(' %d ', [SingleStat.PlayerStat[n].Kills]);
2975 s2 := Format(' %d', [gTotalMonsters]);
2977 e_CharFont_Print(gMenuFont, key_x, y, _lc[I_MENU_INTER_KILLS]);
2978 e_CharFont_PrintEx(gMenuFont, val_x, y, s1, _RGB(255, 0, 0));
2979 e_CharFont_GetSize(gMenuFont, s1, w1, h);
2980 e_CharFont_Print(gMenuFont, val_x+w1, y, '/');
2981 s1 := s1 + '/';
2982 e_CharFont_GetSize(gMenuFont, s1, w1, h);
2983 e_CharFont_PrintEx(gMenuFont, val_x+w1, y, s2, _RGB(255, 0, 0));
2985 // "Kills-per-minute: ##.#":
2986 s1 := _lc[I_MENU_INTER_KPM];
2987 if tm > 0 then
2988 kpm := (SingleStat.PlayerStat[n].Kills / tm) * 60
2989 else
2990 kpm := SingleStat.PlayerStat[n].Kills;
2991 s2 := Format(' %.1f', [kpm]);
2993 e_CharFont_Print(gMenuFont, key_x, y+32, s1);
2994 e_CharFont_PrintEx(gMenuFont, val_x, y+32, s2, _RGB(255, 0, 0));
2996 // "Secrets found: # / #":
2997 s1 := Format(' %d ', [SingleStat.PlayerStat[n].Secrets]);
2998 s2 := Format(' %d', [SingleStat.TotalSecrets]);
3000 e_CharFont_Print(gMenuFont, key_x, y+64, _lc[I_MENU_INTER_SECRETS]);
3001 e_CharFont_PrintEx(gMenuFont, val_x, y+64, s1, _RGB(255, 0, 0));
3002 e_CharFont_GetSize(gMenuFont, s1, w1, h);
3003 e_CharFont_Print(gMenuFont, val_x+w1, y+64, '/');
3004 s1 := s1 + '/';
3005 e_CharFont_GetSize(gMenuFont, s1, w1, h);
3006 e_CharFont_PrintEx(gMenuFont, val_x+w1, y+64, s2, _RGB(255, 0, 0));
3007 end;
3009 begin
3010 // "Level Complete":
3011 e_CharFont_GetSize(gMenuFont, _lc[I_MENU_INTER_LEVEL_COMPLETE], w1, h);
3012 e_CharFont_Print(gMenuFont, (gScreenWidth-w1) div 2, 32, _lc[I_MENU_INTER_LEVEL_COMPLETE]);
3014 // Îïðåäåëÿåì êîîðäèíàòû âûðàâíèâàíèÿ ïî ñàìîé äëèííîé ñòðîêå:
3015 s1 := _lc[I_MENU_INTER_KPM];
3016 e_CharFont_GetSize(gMenuFont, s1, w1, h);
3017 Inc(w1, 16);
3018 s1 := ' 9999.9';
3019 e_CharFont_GetSize(gMenuFont, s1, w2, h);
3021 key_x := (gScreenWidth-w1-w2) div 2;
3022 val_x := key_x + w1;
3024 // "Time: #:##:##":
3025 tm := SingleStat.GameTime div 1000;
3026 s1 := _lc[I_MENU_INTER_TIME];
3027 s2 := Format(' %d:%.2d:%.2d', [tm div (60*60), (tm mod (60*60)) div 60, tm mod 60]);
3029 e_CharFont_Print(gMenuFont, key_x, 80, s1);
3030 e_CharFont_PrintEx(gMenuFont, val_x, 80, s2, _RGB(255, 0, 0));
3032 if SingleStat.TwoPlayers then
3033 begin
3034 // "Player 1":
3035 s1 := _lc[I_MENU_PLAYER_1];
3036 e_CharFont_GetSize(gMenuFont, s1, w1, h);
3037 e_CharFont_Print(gMenuFont, (gScreenWidth-w1) div 2, 128, s1);
3039 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
3040 y := 176;
3041 player_stat(0);
3043 // "Player 2":
3044 s1 := _lc[I_MENU_PLAYER_2];
3045 e_CharFont_GetSize(gMenuFont, s1, w1, h);
3046 e_CharFont_Print(gMenuFont, (gScreenWidth-w1) div 2, 288, s1);
3048 // Ñòàòèñòèêà âòîðîãî èãðîêà:
3049 y := 336;
3050 player_stat(1);
3051 end
3052 else
3053 begin
3054 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
3055 y := 128;
3056 player_stat(0);
3057 end;
3058 end;
3060 procedure DrawLoadingStat();
3061 procedure drawRect (x, y, w, h: Integer);
3062 begin
3063 if (w < 1) or (h < 1) then exit;
3064 glBegin(GL_QUADS);
3065 glVertex2f(x+0.375, y+0.375);
3066 glVertex2f(x+w+0.375, y+0.375);
3067 glVertex2f(x+w+0.375, y+h+0.375);
3068 glVertex2f(x+0.375, y+h+0.375);
3069 glEnd();
3070 end;
3072 function drawPBar (cur, total: Integer; washere: Boolean): Boolean;
3073 var
3074 rectW, rectH: Integer;
3075 x0, y0: Integer;
3076 wdt: Integer;
3077 wl, hl: Integer;
3078 wr, hr: Integer;
3079 wb, hb: Integer;
3080 wm, hm: Integer;
3081 idl, idr, idb, idm: LongWord;
3082 f, my: Integer;
3083 begin
3084 result := false;
3085 if (total < 1) then exit;
3086 if (cur < 1) then exit; // don't blink
3087 if (not washere) and (cur >= total) then exit; // don't blink
3088 //if (cur < 0) then cur := 0;
3089 //if (cur > total) then cur := total;
3090 result := true;
3092 if (hasPBarGfx) then
3093 begin
3094 g_Texture_Get('UI_GFX_PBAR_LEFT', idl);
3095 g_Texture_GetSize('UI_GFX_PBAR_LEFT', wl, hl);
3096 g_Texture_Get('UI_GFX_PBAR_RIGHT', idr);
3097 g_Texture_GetSize('UI_GFX_PBAR_RIGHT', wr, hr);
3098 g_Texture_Get('UI_GFX_PBAR_MIDDLE', idb);
3099 g_Texture_GetSize('UI_GFX_PBAR_MIDDLE', wb, hb);
3100 g_Texture_Get('UI_GFX_PBAR_MARKER', idm);
3101 g_Texture_GetSize('UI_GFX_PBAR_MARKER', wm, hm);
3103 //rectW := gScreenWidth-360;
3104 rectW := trunc(624.0*gScreenWidth/1024.0);
3105 rectH := hl;
3107 x0 := (gScreenWidth-rectW) div 2;
3108 y0 := gScreenHeight-rectH-64;
3109 if (y0 < 2) then y0 := 2;
3111 glEnable(GL_SCISSOR_TEST);
3113 // left and right
3114 glScissor(x0, gScreenHeight-y0-rectH, rectW, rectH);
3115 e_DrawSize(idl, x0, y0, 0, true, false, wl, hl);
3116 e_DrawSize(idr, x0+rectW-wr, y0, 0, true, false, wr, hr);
3118 // body
3119 glScissor(x0+wl, gScreenHeight-y0-rectH, rectW-wl-wr, rectH);
3120 f := x0+wl;
3121 while (f < x0+rectW) do
3122 begin
3123 e_DrawSize(idb, f, y0, 0, true, false, wb, hb);
3124 f += wb;
3125 end;
3127 // filled part
3128 wdt := (rectW-wl-wr)*cur div total;
3129 if (wdt > rectW-wl-wr) then wdt := rectW-wr-wr;
3130 if (wdt > 0) then
3131 begin
3132 my := y0; // don't be so smart, ketmar: +(rectH-wm) div 2;
3133 glScissor(x0+wl, gScreenHeight-my-rectH, wdt, hm);
3134 f := x0+wl;
3135 while (wdt > 0) do
3136 begin
3137 e_DrawSize(idm, f, y0, 0, true, false, wm, hm);
3138 f += wm;
3139 wdt -= wm;
3140 end;
3141 end;
3143 glScissor(0, 0, gScreenWidth, gScreenHeight);
3144 end
3145 else
3146 begin
3147 rectW := gScreenWidth-64;
3148 rectH := 16;
3150 x0 := (gScreenWidth-rectW) div 2;
3151 y0 := gScreenHeight-rectH-64;
3152 if (y0 < 2) then y0 := 2;
3154 glDisable(GL_BLEND);
3155 glDisable(GL_TEXTURE_2D);
3157 //glClearColor(0, 0, 0, 0);
3158 //glClear(GL_COLOR_BUFFER_BIT);
3160 glColor4ub(127, 127, 127, 255);
3161 drawRect(x0-2, y0-2, rectW+4, rectH+4);
3163 glColor4ub(0, 0, 0, 255);
3164 drawRect(x0-1, y0-1, rectW+2, rectH+2);
3166 glColor4ub(127, 127, 127, 255);
3167 wdt := rectW*cur div total;
3168 if (wdt > rectW) then wdt := rectW;
3169 drawRect(x0, y0, wdt, rectH);
3170 end;
3171 end;
3173 var
3174 ww, hh: Word;
3175 xx, yy, i: Integer;
3176 s: String;
3177 begin
3178 if (Length(LoadingStat.Msgs) = 0) then exit;
3180 e_CharFont_GetSize(gMenuFont, _lc[I_MENU_LOADING], ww, hh);
3181 yy := (gScreenHeight div 3);
3182 e_CharFont_Print(gMenuFont, (gScreenWidth div 2)-(ww div 2), yy-2*hh, _lc[I_MENU_LOADING]);
3183 xx := (gScreenWidth div 3);
3185 with LoadingStat do
3186 begin
3187 for i := 0 to NextMsg-1 do
3188 begin
3189 if (i = (NextMsg-1)) and (MaxValue > 0) then
3190 s := Format('%s: %d/%d', [Msgs[i], CurValue, MaxValue])
3191 else
3192 s := Msgs[i];
3194 e_CharFont_PrintEx(gMenuSmallFont, xx, yy, s, _RGB(255, 0, 0));
3195 yy := yy + LOADING_INTERLINE;
3196 PBarWasHere := drawPBar(CurValue, MaxValue, PBarWasHere);
3197 end;
3198 end;
3199 end;
3201 procedure DrawMenuBackground(tex: AnsiString);
3202 var
3203 w, h: Word;
3204 ID: DWord;
3206 begin
3207 if g_Texture_Get(tex, ID) then
3208 begin
3209 e_Clear(GL_COLOR_BUFFER_BIT, 0, 0, 0);
3210 e_GetTextureSize(ID, @w, @h);
3211 if w = h then
3212 w := round(w * 1.333 * (gScreenHeight / h))
3213 else
3214 w := trunc(w * (gScreenHeight / h));
3215 e_DrawSize(ID, (gScreenWidth - w) div 2, 0, 0, False, False, w, gScreenHeight);
3216 end
3217 else e_Clear(GL_COLOR_BUFFER_BIT, 0, 0, 0);
3218 end;
3220 procedure DrawMinimap(p: TPlayer; RenderRect: e_graphics.TRect);
3221 var
3222 a, aX, aY, aX2, aY2, Scale, ScaleSz: Integer;
3224 function monDraw (mon: TMonster): Boolean;
3225 begin
3226 result := false; // don't stop
3227 with mon do
3228 begin
3229 if alive then
3230 begin
3231 // Ëåâûé âåðõíèé óãîë
3232 aX := Obj.X div ScaleSz + 1;
3233 aY := Obj.Y div ScaleSz + 1;
3234 // Ðàçìåðû
3235 aX2 := max(Obj.Rect.Width div ScaleSz, 1);
3236 aY2 := max(Obj.Rect.Height div ScaleSz, 1);
3237 // Ïðàâûé íèæíèé óãîë
3238 aX2 := aX + aX2 - 1;
3239 aY2 := aY + aY2 - 1;
3240 e_DrawFillQuad(aX, aY, aX2, aY2, 255, 255, 0, 0);
3241 end;
3242 end;
3243 end;
3245 begin
3246 if (gMapInfo.Width > RenderRect.Right - RenderRect.Left) or
3247 (gMapInfo.Height > RenderRect.Bottom - RenderRect.Top) then
3248 begin
3249 Scale := 1;
3250 // Ñêîëüêî ïèêñåëîâ êàðòû â 1 ïèêñåëå ìèíè-êàðòû:
3251 ScaleSz := 16 div Scale;
3252 // Ðàçìåðû ìèíè-êàðòû:
3253 aX := max(gMapInfo.Width div ScaleSz, 1);
3254 aY := max(gMapInfo.Height div ScaleSz, 1);
3255 // Ðàìêà êàðòû:
3256 e_DrawFillQuad(0, 0, aX-1, aY-1, 0, 0, 0, 0);
3258 if gWalls <> nil then
3259 begin
3260 // Ðèñóåì ñòåíû:
3261 for a := 0 to High(gWalls) do
3262 with gWalls[a] do
3263 if PanelType <> 0 then
3264 begin
3265 // Ëåâûé âåðõíèé óãîë:
3266 aX := X div ScaleSz;
3267 aY := Y div ScaleSz;
3268 // Ðàçìåðû:
3269 aX2 := max(Width div ScaleSz, 1);
3270 aY2 := max(Height div ScaleSz, 1);
3271 // Ïðàâûé íèæíèé óãîë:
3272 aX2 := aX + aX2 - 1;
3273 aY2 := aY + aY2 - 1;
3275 case PanelType of
3276 PANEL_WALL: e_DrawFillQuad(aX, aY, aX2, aY2, 208, 208, 208, 0);
3277 PANEL_OPENDOOR, PANEL_CLOSEDOOR:
3278 if Enabled then e_DrawFillQuad(aX, aY, aX2, aY2, 160, 160, 160, 0);
3279 end;
3280 end;
3281 end;
3282 if gSteps <> nil then
3283 begin
3284 // Ðèñóåì ñòóïåíè:
3285 for a := 0 to High(gSteps) do
3286 with gSteps[a] do
3287 if PanelType <> 0 then
3288 begin
3289 // Ëåâûé âåðõíèé óãîë:
3290 aX := X div ScaleSz;
3291 aY := Y div ScaleSz;
3292 // Ðàçìåðû:
3293 aX2 := max(Width div ScaleSz, 1);
3294 aY2 := max(Height div ScaleSz, 1);
3295 // Ïðàâûé íèæíèé óãîë:
3296 aX2 := aX + aX2 - 1;
3297 aY2 := aY + aY2 - 1;
3299 e_DrawFillQuad(aX, aY, aX2, aY2, 128, 128, 128, 0);
3300 end;
3301 end;
3302 if gLifts <> nil then
3303 begin
3304 // Ðèñóåì ëèôòû:
3305 for a := 0 to High(gLifts) do
3306 with gLifts[a] do
3307 if PanelType <> 0 then
3308 begin
3309 // Ëåâûé âåðõíèé óãîë:
3310 aX := X div ScaleSz;
3311 aY := Y div ScaleSz;
3312 // Ðàçìåðû:
3313 aX2 := max(Width div ScaleSz, 1);
3314 aY2 := max(Height div ScaleSz, 1);
3315 // Ïðàâûé íèæíèé óãîë:
3316 aX2 := aX + aX2 - 1;
3317 aY2 := aY + aY2 - 1;
3319 case LiftType of
3320 LIFTTYPE_UP: e_DrawFillQuad(aX, aY, aX2, aY2, 116, 72, 36, 0);
3321 LIFTTYPE_DOWN: e_DrawFillQuad(aX, aY, aX2, aY2, 116, 124, 96, 0);
3322 LIFTTYPE_LEFT: e_DrawFillQuad(aX, aY, aX2, aY2, 200, 80, 4, 0);
3323 LIFTTYPE_RIGHT: e_DrawFillQuad(aX, aY, aX2, aY2, 252, 140, 56, 0);
3324 end;
3325 end;
3326 end;
3327 if gWater <> nil then
3328 begin
3329 // Ðèñóåì âîäó:
3330 for a := 0 to High(gWater) do
3331 with gWater[a] do
3332 if PanelType <> 0 then
3333 begin
3334 // Ëåâûé âåðõíèé óãîë:
3335 aX := X div ScaleSz;
3336 aY := Y div ScaleSz;
3337 // Ðàçìåðû:
3338 aX2 := max(Width div ScaleSz, 1);
3339 aY2 := max(Height div ScaleSz, 1);
3340 // Ïðàâûé íèæíèé óãîë:
3341 aX2 := aX + aX2 - 1;
3342 aY2 := aY + aY2 - 1;
3344 e_DrawFillQuad(aX, aY, aX2, aY2, 0, 0, 192, 0);
3345 end;
3346 end;
3347 if gAcid1 <> nil then
3348 begin
3349 // Ðèñóåì êèñëîòó 1:
3350 for a := 0 to High(gAcid1) do
3351 with gAcid1[a] do
3352 if PanelType <> 0 then
3353 begin
3354 // Ëåâûé âåðõíèé óãîë:
3355 aX := X div ScaleSz;
3356 aY := Y div ScaleSz;
3357 // Ðàçìåðû:
3358 aX2 := max(Width div ScaleSz, 1);
3359 aY2 := max(Height div ScaleSz, 1);
3360 // Ïðàâûé íèæíèé óãîë:
3361 aX2 := aX + aX2 - 1;
3362 aY2 := aY + aY2 - 1;
3364 e_DrawFillQuad(aX, aY, aX2, aY2, 0, 176, 0, 0);
3365 end;
3366 end;
3367 if gAcid2 <> nil then
3368 begin
3369 // Ðèñóåì êèñëîòó 2:
3370 for a := 0 to High(gAcid2) do
3371 with gAcid2[a] do
3372 if PanelType <> 0 then
3373 begin
3374 // Ëåâûé âåðõíèé óãîë:
3375 aX := X div ScaleSz;
3376 aY := Y div ScaleSz;
3377 // Ðàçìåðû:
3378 aX2 := max(Width div ScaleSz, 1);
3379 aY2 := max(Height div ScaleSz, 1);
3380 // Ïðàâûé íèæíèé óãîë:
3381 aX2 := aX + aX2 - 1;
3382 aY2 := aY + aY2 - 1;
3384 e_DrawFillQuad(aX, aY, aX2, aY2, 176, 0, 0, 0);
3385 end;
3386 end;
3387 if gPlayers <> nil then
3388 begin
3389 // Ðèñóåì èãðîêîâ:
3390 for a := 0 to High(gPlayers) do
3391 if gPlayers[a] <> nil then with gPlayers[a] do
3392 if alive then begin
3393 // Ëåâûé âåðõíèé óãîë:
3394 aX := Obj.X div ScaleSz + 1;
3395 aY := Obj.Y div ScaleSz + 1;
3396 // Ðàçìåðû:
3397 aX2 := max(Obj.Rect.Width div ScaleSz, 1);
3398 aY2 := max(Obj.Rect.Height div ScaleSz, 1);
3399 // Ïðàâûé íèæíèé óãîë:
3400 aX2 := aX + aX2 - 1;
3401 aY2 := aY + aY2 - 1;
3403 if gPlayers[a] = p then
3404 e_DrawFillQuad(aX, aY, aX2, aY2, 0, 255, 0, 0)
3405 else
3406 case Team of
3407 TEAM_RED: e_DrawFillQuad(aX, aY, aX2, aY2, 255, 0, 0, 0);
3408 TEAM_BLUE: e_DrawFillQuad(aX, aY, aX2, aY2, 0, 0, 255, 0);
3409 else e_DrawFillQuad(aX, aY, aX2, aY2, 255, 128, 0, 0);
3410 end;
3411 end;
3412 end;
3413 // Ðèñóåì ìîíñòðîâ
3414 g_Mons_ForEach(monDraw);
3415 end;
3416 end;
3419 procedure renderAmbientQuad (hasAmbient: Boolean; constref ambColor: TDFColor);
3420 begin
3421 if not hasAmbient then exit;
3422 e_AmbientQuad(sX, sY, sWidth, sHeight, ambColor.r, ambColor.g, ambColor.b, ambColor.a);
3423 end;
3426 // setup sX, sY, sWidth, sHeight, and transformation matrix before calling this!
3427 //FIXME: broken for splitscreen mode
3428 procedure renderDynLightsInternal ();
3429 var
3430 //hasAmbient: Boolean;
3431 //ambColor: TDFColor;
3432 lln: Integer;
3433 lx, ly, lrad: Integer;
3434 scxywh: array[0..3] of GLint;
3435 wassc: Boolean;
3436 begin
3437 if e_NoGraphics then exit;
3439 //TODO: lights should be in separate grid, i think
3440 // but on the other side: grid may be slower for dynlights, as their lifetime is short
3441 if (not gwin_k8_enable_light_experiments) or (not gwin_has_stencil) or (g_dynLightCount < 1) then exit;
3443 // rendering mode
3444 //ambColor := gCurrentMap['light_ambient'].rgba;
3445 //hasAmbient := (not ambColor.isOpaque) or (not ambColor.isBlack);
3447 { // this will multiply incoming color to alpha from framebuffer
3448 glEnable(GL_BLEND);
3449 glBlendFunc(GL_DST_ALPHA, GL_ONE);
3452 (*
3453 * light rendering: (INVALID!)
3454 * glStencilFunc(GL_EQUAL, 0, $ff);
3455 * for each light:
3456 * glClear(GL_STENCIL_BUFFER_BIT);
3457 * glStencilOp(GL_KEEP, GL_KEEP, GL_INCR);
3458 * draw shadow volume into stencil buffer
3459 * glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); // modify color buffer
3460 * glStencilOp(GL_KEEP, GL_KEEP, GL_KEEP); // don't modify stencil buffer
3461 * turn off blending
3462 * draw color-less quad with light alpha (WARNING! don't touch color!)
3463 * glEnable(GL_BLEND);
3464 * glBlendFunc(GL_DST_ALPHA, GL_ONE);
3465 * draw all geometry up to and including walls (with alpha-testing, probably) -- this does lighting
3466 *)
3467 wassc := (glIsEnabled(GL_SCISSOR_TEST) <> 0);
3468 if wassc then glGetIntegerv(GL_SCISSOR_BOX, @scxywh[0]) else glGetIntegerv(GL_VIEWPORT, @scxywh[0]);
3470 // setup OpenGL parameters
3471 glStencilMask($FFFFFFFF);
3472 glStencilFunc(GL_ALWAYS, 0, $FFFFFFFF);
3473 glEnable(GL_STENCIL_TEST);
3474 glEnable(GL_SCISSOR_TEST);
3475 glClear(GL_STENCIL_BUFFER_BIT);
3476 glStencilFunc(GL_EQUAL, 0, $ff);
3478 for lln := 0 to g_dynLightCount-1 do
3479 begin
3480 lx := g_dynLights[lln].x;
3481 ly := g_dynLights[lln].y;
3482 lrad := g_dynLights[lln].radius;
3483 if (lrad < 3) then continue;
3485 if (lx-sX+lrad < 0) then continue;
3486 if (ly-sY+lrad < 0) then continue;
3487 if (lx-sX-lrad >= gPlayerScreenSize.X) then continue;
3488 if (ly-sY-lrad >= gPlayerScreenSize.Y) then continue;
3490 // set scissor to optimize drawing
3491 if (g_dbg_scale = 1.0) then
3492 begin
3493 glScissor((lx-sX)-lrad+2, gPlayerScreenSize.Y-(ly-sY)-lrad-1+2, lrad*2-4, lrad*2-4);
3494 end
3495 else
3496 begin
3497 glScissor(0, 0, gScreenWidth, gScreenHeight);
3498 end;
3499 // no need to clear stencil buffer, light blitting will do it for us... but only for normal scale
3500 if (g_dbg_scale <> 1.0) then glClear(GL_STENCIL_BUFFER_BIT);
3501 glStencilOp(GL_KEEP, GL_KEEP, GL_INCR);
3502 // draw extruded panels
3503 glDisable(GL_TEXTURE_2D);
3504 glDisable(GL_BLEND);
3505 glColorMask(GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE); // no need to modify color buffer
3506 if (lrad > 4) then g_Map_DrawPanelShadowVolumes(lx, ly, lrad);
3507 // render light texture
3508 glColorMask(GL_TRUE, GL_TRUE, GL_TRUE, GL_TRUE); // modify color buffer
3509 glStencilOp(GL_ZERO, GL_ZERO, GL_ZERO); // draw light, and clear stencil buffer
3510 // blend it
3511 glEnable(GL_BLEND);
3512 glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
3513 glEnable(GL_TEXTURE_2D);
3514 // color and opacity
3515 glColor4f(g_dynLights[lln].r, g_dynLights[lln].g, g_dynLights[lln].b, g_dynLights[lln].a);
3516 glBindTexture(GL_TEXTURE_2D, g_Texture_Light());
3517 glBegin(GL_QUADS);
3518 glTexCoord2f(0.0, 0.0); glVertex2i(lx-lrad, ly-lrad); // top-left
3519 glTexCoord2f(1.0, 0.0); glVertex2i(lx+lrad, ly-lrad); // top-right
3520 glTexCoord2f(1.0, 1.0); glVertex2i(lx+lrad, ly+lrad); // bottom-right
3521 glTexCoord2f(0.0, 1.0); glVertex2i(lx-lrad, ly+lrad); // bottom-left
3522 glEnd();
3523 end;
3525 // done
3526 glDisable(GL_STENCIL_TEST);
3527 glDisable(GL_BLEND);
3528 glDisable(GL_SCISSOR_TEST);
3529 //glScissor(0, 0, sWidth, sHeight);
3531 glScissor(scxywh[0], scxywh[1], scxywh[2], scxywh[3]);
3532 if wassc then glEnable(GL_SCISSOR_TEST) else glDisable(GL_SCISSOR_TEST);
3533 end;
3536 function fixViewportForScale (): Boolean;
3537 var
3538 nx0, ny0, nw, nh: Integer;
3539 begin
3540 result := false;
3541 if (g_dbg_scale <> 1.0) then
3542 begin
3543 result := true;
3544 nx0 := round(sX-(gPlayerScreenSize.X-(sWidth*g_dbg_scale))/2/g_dbg_scale);
3545 ny0 := round(sY-(gPlayerScreenSize.Y-(sHeight*g_dbg_scale))/2/g_dbg_scale);
3546 nw := round(sWidth/g_dbg_scale);
3547 nh := round(sHeight/g_dbg_scale);
3548 sX := nx0;
3549 sY := ny0;
3550 sWidth := nw;
3551 sHeight := nh;
3552 end;
3553 end;
3556 // setup sX, sY, sWidth, sHeight, and transformation matrix before calling this!
3557 // WARNING! this WILL CALL `glTranslatef()`, but won't restore matrices!
3558 procedure renderMapInternal (backXOfs, backYOfs: Integer; setTransMatrix: Boolean);
3559 type
3560 TDrawCB = procedure ();
3562 var
3563 hasAmbient: Boolean;
3564 ambColor: TDFColor;
3565 doAmbient: Boolean = false;
3567 procedure drawPanelType (profname: AnsiString; panType: DWord; doDraw: Boolean);
3568 var
3569 tagmask: Integer;
3570 pan: TPanel;
3571 begin
3572 if (profileFrameDraw <> nil) then profileFrameDraw.sectionBegin(profname);
3573 if gdbg_map_use_accel_render then
3574 begin
3575 tagmask := panelTypeToTag(panType);
3576 while (gDrawPanelList.count > 0) do
3577 begin
3578 pan := TPanel(gDrawPanelList.front());
3579 if ((pan.tag and tagmask) = 0) then break;
3580 if doDraw then pan.Draw(doAmbient, ambColor);
3581 gDrawPanelList.popFront();
3582 end;
3583 end
3584 else
3585 begin
3586 if doDraw then g_Map_DrawPanels(panType, hasAmbient, ambColor);
3587 end;
3588 if (profileFrameDraw <> nil) then profileFrameDraw.sectionEnd();
3589 end;
3591 procedure drawOther (profname: AnsiString; cb: TDrawCB);
3592 begin
3593 if (profileFrameDraw <> nil) then profileFrameDraw.sectionBegin(profname);
3594 if assigned(cb) then cb();
3595 if (profileFrameDraw <> nil) then profileFrameDraw.sectionEnd();
3596 end;
3598 begin
3599 if (profileFrameDraw <> nil) then profileFrameDraw.sectionBegin('total');
3601 // our accelerated renderer will collect all panels to gDrawPanelList
3602 // we can use panel tag to render level parts (see GridTagXXX in g_map.pas)
3603 if (profileFrameDraw <> nil) then profileFrameDraw.sectionBegin('collect');
3604 if gdbg_map_use_accel_render then
3605 begin
3606 g_Map_CollectDrawPanels(sX, sY, sWidth, sHeight);
3607 end;
3608 if (profileFrameDraw <> nil) then profileFrameDraw.sectionEnd();
3610 if (profileFrameDraw <> nil) then profileFrameDraw.sectionBegin('skyback');
3611 g_Map_DrawBack(backXOfs, backYOfs);
3612 if (profileFrameDraw <> nil) then profileFrameDraw.sectionEnd();
3614 if setTransMatrix then
3615 begin
3616 //if (g_dbg_scale <> 1.0) then glTranslatef(0.0, -0.375/2, 0);
3617 glScalef(g_dbg_scale, g_dbg_scale, 1.0);
3618 glTranslatef(-sX, -sY, 0);
3619 end;
3621 // rendering mode
3622 ambColor := gCurrentMap['light_ambient'].rgba;
3623 hasAmbient := (not ambColor.isOpaque) or (not ambColor.isBlack);
3626 if hasAmbient then
3627 begin
3628 //writeln('color: (', ambColor.r, ',', ambColor.g, ',', ambColor.b, ',', ambColor.a, ')');
3629 glColor4ub(ambColor.r, ambColor.g, ambColor.b, ambColor.a);
3630 glClear(GL_COLOR_BUFFER_BIT);
3631 end;
3633 //writeln('color: (', ambColor.r, ',', ambColor.g, ',', ambColor.b, ',', ambColor.a, ')');
3636 drawPanelType('*back', PANEL_BACK, g_rlayer_back);
3637 drawPanelType('*step', PANEL_STEP, g_rlayer_step);
3638 drawOther('items', @g_Items_Draw);
3639 drawOther('weapons', @g_Weapon_Draw);
3640 drawOther('shells', @g_Player_DrawShells);
3641 drawOther('drawall', @g_Player_DrawAll);
3642 drawOther('corpses', @g_Player_DrawCorpses);
3643 drawPanelType('*wall', PANEL_WALL, g_rlayer_wall);
3644 drawOther('monsters', @g_Monsters_Draw);
3645 drawOther('itemdrop', @g_Items_DrawDrop);
3646 drawPanelType('*door', PANEL_CLOSEDOOR, g_rlayer_door);
3647 drawOther('gfx', @g_GFX_Draw);
3648 drawOther('flags', @g_Map_DrawFlags);
3649 drawPanelType('*acid1', PANEL_ACID1, g_rlayer_acid1);
3650 drawPanelType('*acid2', PANEL_ACID2, g_rlayer_acid2);
3651 drawPanelType('*water', PANEL_WATER, g_rlayer_water);
3652 drawOther('dynlights', @renderDynLightsInternal);
3654 if hasAmbient {and ((not g_playerLight) or (not gwin_has_stencil) or (g_dynLightCount < 1))} then
3655 begin
3656 renderAmbientQuad(hasAmbient, ambColor);
3657 end;
3659 doAmbient := true;
3660 drawPanelType('*fore', PANEL_FORE, g_rlayer_fore);
3663 if g_debug_HealthBar then
3664 begin
3665 g_Monsters_DrawHealth();
3666 g_Player_DrawHealth();
3667 end;
3669 if (profileFrameDraw <> nil) then profileFrameDraw.mainEnd(); // map rendering
3670 end;
3673 procedure DrawMapView(x, y, w, h: Integer);
3675 var
3676 bx, by: Integer;
3677 begin
3678 glPushMatrix();
3680 bx := Round(x/(gMapInfo.Width - w)*(gBackSize.X - w));
3681 by := Round(y/(gMapInfo.Height - h)*(gBackSize.Y - h));
3683 sX := x;
3684 sY := y;
3685 sWidth := w;
3686 sHeight := h;
3688 fixViewportForScale();
3689 renderMapInternal(-bx, -by, true);
3691 glPopMatrix();
3692 end;
3695 procedure DrawPlayer(p: TPlayer);
3696 var
3697 px, py, a, b, c, d, i, fX, fY: Integer;
3698 camObj: TObj;
3699 //R: TRect;
3700 begin
3701 if (p = nil) or (p.FDummy) then
3702 begin
3703 glPushMatrix();
3704 g_Map_DrawBack(0, 0);
3705 glPopMatrix();
3706 Exit;
3707 end;
3709 if (profileFrameDraw = nil) then profileFrameDraw := TProfiler.Create('RENDER', g_profile_history_size);
3710 if (profileFrameDraw <> nil) then profileFrameDraw.mainBegin(g_profile_frame_draw);
3712 gPlayerDrawn := p;
3714 glPushMatrix();
3716 camObj := p.getCameraObj();
3717 camObj.lerp(gLerpFactor, fX, fY);
3718 px := fX + PLAYER_RECT_CX;
3719 py := fY + PLAYER_RECT_CY+nlerp(p.SlopeOld, camObj.slopeUpLeft, gLerpFactor);
3721 if (g_dbg_scale = 1.0) and (not g_dbg_ignore_bounds) then
3722 begin
3723 if (px > (gPlayerScreenSize.X div 2)) then a := -px+(gPlayerScreenSize.X div 2) else a := 0;
3724 if (py > (gPlayerScreenSize.Y div 2)) then b := -py+(gPlayerScreenSize.Y div 2) else b := 0;
3726 if (px > gMapInfo.Width-(gPlayerScreenSize.X div 2)) then a := -gMapInfo.Width+gPlayerScreenSize.X;
3727 if (py > gMapInfo.Height-(gPlayerScreenSize.Y div 2)) then b := -gMapInfo.Height+gPlayerScreenSize.Y;
3729 if (gMapInfo.Width = gPlayerScreenSize.X) then a := 0
3730 else if (gMapInfo.Width < gPlayerScreenSize.X) then
3731 begin
3732 // hcenter
3733 a := (gPlayerScreenSize.X-gMapInfo.Width) div 2;
3734 end;
3736 if (gMapInfo.Height = gPlayerScreenSize.Y) then b := 0
3737 else if (gMapInfo.Height < gPlayerScreenSize.Y) then
3738 begin
3739 // vcenter
3740 b := (gPlayerScreenSize.Y-gMapInfo.Height) div 2;
3741 end;
3742 end
3743 else
3744 begin
3745 // scaled, ignore level bounds
3746 a := -px+(gPlayerScreenSize.X div 2);
3747 b := -py+(gPlayerScreenSize.Y div 2);
3748 end;
3750 sX := -a;
3751 sY := -b;
3752 sWidth := gPlayerScreenSize.X;
3753 sHeight := gPlayerScreenSize.Y;
3754 fixViewportForScale();
3756 i := py - (sY + sHeight div 2);
3757 if (p.IncCam > 0) then
3758 begin
3759 // clamp to level bounds
3760 if (sY - p.IncCam < 0) then
3761 p.IncCam := nclamp(sY, 0, 120);
3762 // clamp around player position
3763 if (i > 0) then
3764 p.IncCam := nclamp(p.IncCam, 0, max(0, 120 - i));
3765 end
3766 else if (p.IncCam < 0) then
3767 begin
3768 // clamp to level bounds
3769 if (sY + sHeight - p.IncCam > gMapInfo.Height) then
3770 p.IncCam := nclamp(sY + sHeight - gMapInfo.Height, -120, 0);
3771 // clamp around player position
3772 if (i < 0) then
3773 p.IncCam := nclamp(p.IncCam, min(0, -120 - i), 0);
3774 end;
3776 sY := sY - nlerp(p.IncCamOld, p.IncCam, gLerpFactor);
3778 if (not g_dbg_ignore_bounds) then
3779 begin
3780 if (sX+sWidth > gMapInfo.Width) then sX := gMapInfo.Width-sWidth;
3781 if (sY+sHeight > gMapInfo.Height) then sY := gMapInfo.Height-sHeight;
3782 if (sX < 0) then sX := 0;
3783 if (sY < 0) then sY := 0;
3784 end;
3786 if (gBackSize.X <= gPlayerScreenSize.X) or (gMapInfo.Width <= sWidth) then c := 0 else c := trunc((gBackSize.X-gPlayerScreenSize.X)*sX/(gMapInfo.Width-sWidth));
3787 if (gBackSize.Y <= gPlayerScreenSize.Y) or (gMapInfo.Height <= sHeight) then d := 0 else d := trunc((gBackSize.Y-gPlayerScreenSize.Y)*sY/(gMapInfo.Height-sHeight));
3789 //r_smallmap_h: 0: left; 1: center; 2: right
3790 //r_smallmap_v: 0: top; 1: center; 2: bottom
3791 // horiz small map?
3792 if (gMapInfo.Width = sWidth) then
3793 begin
3794 sX := 0;
3795 end
3796 else if (gMapInfo.Width < sWidth) then
3797 begin
3798 case r_smallmap_h of
3799 1: sX := -((sWidth-gMapInfo.Width) div 2); // center
3800 2: sX := -(sWidth-gMapInfo.Width); // right
3801 else sX := 0; // left
3802 end;
3803 end;
3804 // vert small map?
3805 if (gMapInfo.Height = sHeight) then
3806 begin
3807 sY := 0;
3808 end
3809 else if (gMapInfo.Height < sHeight) then
3810 begin
3811 case r_smallmap_v of
3812 1: sY := -((sHeight-gMapInfo.Height) div 2); // center
3813 2: sY := -(sHeight-gMapInfo.Height); // bottom
3814 else sY := 0; // top
3815 end;
3816 end;
3818 p.viewPortX := sX;
3819 p.viewPortY := sY;
3820 p.viewPortW := sWidth;
3821 p.viewPortH := sHeight;
3823 {$IFDEF ENABLE_HOLMES}
3824 if (p = gPlayer1) then
3825 begin
3826 g_Holmes_plrViewPos(sX, sY);
3827 g_Holmes_plrViewSize(sWidth, sHeight);
3828 end;
3829 {$ENDIF}
3831 renderMapInternal(-c, -d, true);
3833 if (gGameSettings.GameMode <> GM_SINGLE) and (gPlayerIndicator > 0) then
3834 case gPlayerIndicator of
3835 1:
3836 p.DrawIndicator(_RGB(255, 255, 255));
3838 2:
3839 for i := 0 to High(gPlayers) do
3840 if gPlayers[i] <> nil then
3841 if gPlayers[i] = p then p.DrawIndicator(_RGB(255, 255, 255))
3842 else if (gPlayers[i].Team = p.Team) and (gPlayers[i].Team <> TEAM_NONE) then
3843 if gPlayerIndicatorStyle = 1 then
3844 gPlayers[i].DrawIndicator(_RGB(192, 192, 192))
3845 else gPlayers[i].DrawIndicator(gPlayers[i].GetColor);
3846 end;
3849 for a := 0 to High(gCollideMap) do
3850 for b := 0 to High(gCollideMap[a]) do
3851 begin
3852 d := 0;
3853 if ByteBool(gCollideMap[a, b] and MARK_WALL) then
3854 d := d + 1;
3855 if ByteBool(gCollideMap[a, b] and MARK_DOOR) then
3856 d := d + 2;
3858 case d of
3859 1: e_DrawPoint(1, b, a, 200, 200, 200);
3860 2: e_DrawPoint(1, b, a, 64, 64, 255);
3861 3: e_DrawPoint(1, b, a, 255, 0, 255);
3862 end;
3863 end;
3866 glPopMatrix();
3868 p.DrawPain();
3869 p.DrawPickup();
3870 p.DrawRulez();
3871 if gShowMap then DrawMinimap(p, _TRect(0, 0, 128, 128));
3872 if g_Debug_Player then
3873 g_Player_DrawDebug(p);
3874 p.DrawGUI();
3875 end;
3877 procedure drawProfilers ();
3878 var
3879 px: Integer = -1;
3880 py: Integer = -1;
3881 begin
3882 if g_profile_frame_draw and (profileFrameDraw <> nil) then px := px-drawProfiles(px, py, profileFrameDraw);
3883 if g_profile_collision and (profMapCollision <> nil) then begin px := px-drawProfiles(px, py, profMapCollision); py -= calcProfilesHeight(profMonsLOS); end;
3884 if g_profile_los and (profMonsLOS <> nil) then begin px := px-drawProfiles(px, py, profMonsLOS); py -= calcProfilesHeight(profMonsLOS); end;
3885 end;
3887 procedure g_Game_Draw();
3888 var
3889 ID: DWORD;
3890 w, h: Word;
3891 ww, hh: Byte;
3892 Time: Int64;
3893 back: string;
3894 plView1, plView2: TPlayer;
3895 Split: Boolean;
3896 begin
3897 if gExit = EXIT_QUIT then Exit;
3899 Time := sys_GetTicks() {div 1000};
3900 FPSCounter := FPSCounter+1;
3901 if Time - FPSTime >= 1000 then
3902 begin
3903 FPS := FPSCounter;
3904 FPSCounter := 0;
3905 FPSTime := Time;
3906 end;
3908 e_SetRendertarget(True);
3909 e_SetViewPort(0, 0, gScreenWidth, gScreenHeight);
3911 if gGameOn or (gState = STATE_FOLD) then
3912 begin
3913 if (gPlayer1 <> nil) and (gPlayer2 <> nil) then
3914 begin
3915 gSpectMode := SPECT_NONE;
3916 if not gRevertPlayers then
3917 begin
3918 plView1 := gPlayer1;
3919 plView2 := gPlayer2;
3920 end
3921 else
3922 begin
3923 plView1 := gPlayer2;
3924 plView2 := gPlayer1;
3925 end;
3926 end
3927 else
3928 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
3929 begin
3930 gSpectMode := SPECT_NONE;
3931 if gPlayer2 = nil then
3932 plView1 := gPlayer1
3933 else
3934 plView1 := gPlayer2;
3935 plView2 := nil;
3936 end
3937 else
3938 begin
3939 plView1 := nil;
3940 plView2 := nil;
3941 end;
3943 if (plView1 = nil) and (plView2 = nil) and (gSpectMode = SPECT_NONE) then
3944 gSpectMode := SPECT_STATS;
3946 if gSpectMode = SPECT_PLAYERS then
3947 if gPlayers <> nil then
3948 begin
3949 plView1 := GetActivePlayer_ByID(gSpectPID1);
3950 if plView1 = nil then
3951 begin
3952 gSpectPID1 := GetActivePlayerID_Next();
3953 plView1 := GetActivePlayer_ByID(gSpectPID1);
3954 end;
3955 if gSpectViewTwo then
3956 begin
3957 plView2 := GetActivePlayer_ByID(gSpectPID2);
3958 if plView2 = nil then
3959 begin
3960 gSpectPID2 := GetActivePlayerID_Next();
3961 plView2 := GetActivePlayer_ByID(gSpectPID2);
3962 end;
3963 end;
3964 end;
3966 if gSpectMode = SPECT_MAPVIEW then
3967 begin
3968 // Ðåæèì ïðîñìîòðà êàðòû
3969 Split := False;
3970 e_SetViewPort(0, 0, gScreenWidth, gScreenHeight);
3971 DrawMapView(gSpectX, gSpectY, gScreenWidth, gScreenHeight);
3972 gHearPoint1.Active := True;
3973 gHearPoint1.Coords.X := gScreenWidth div 2 + gSpectX;
3974 gHearPoint1.Coords.Y := gScreenHeight div 2 + gSpectY;
3975 gHearPoint2.Active := False;
3976 end
3977 else
3978 begin
3979 Split := (plView1 <> nil) and (plView2 <> nil);
3981 // Òî÷êè ñëóõà èãðîêîâ
3982 if plView1 <> nil then
3983 begin
3984 gHearPoint1.Active := True;
3985 gHearPoint1.Coords.X := plView1.GameX + PLAYER_RECT.Width;
3986 gHearPoint1.Coords.Y := plView1.GameY + PLAYER_RECT.Height DIV 2;
3987 end else
3988 gHearPoint1.Active := False;
3989 if plView2 <> nil then
3990 begin
3991 gHearPoint2.Active := True;
3992 gHearPoint2.Coords.X := plView2.GameX + PLAYER_RECT.Width;
3993 gHearPoint2.Coords.Y := plView2.GameY + PLAYER_RECT.Height DIV 2;
3994 end else
3995 gHearPoint2.Active := False;
3997 // Ðàçìåð ýêðàíîâ èãðîêîâ:
3998 gPlayerScreenSize.X := gScreenWidth-196;
3999 if Split then
4000 begin
4001 gPlayerScreenSize.Y := gScreenHeight div 2;
4002 if gScreenHeight mod 2 = 0 then
4003 Dec(gPlayerScreenSize.Y);
4004 end
4005 else
4006 gPlayerScreenSize.Y := gScreenHeight;
4008 if Split then
4009 if gScreenHeight mod 2 = 0 then
4010 e_SetViewPort(0, gPlayerScreenSize.Y+2, gPlayerScreenSize.X+196, gPlayerScreenSize.Y)
4011 else
4012 e_SetViewPort(0, gPlayerScreenSize.Y+1, gPlayerScreenSize.X+196, gPlayerScreenSize.Y);
4014 DrawPlayer(plView1);
4015 gPlayer1ScreenCoord.X := sX;
4016 gPlayer1ScreenCoord.Y := sY;
4018 if Split then
4019 begin
4020 e_SetViewPort(0, 0, gPlayerScreenSize.X+196, gPlayerScreenSize.Y);
4022 DrawPlayer(plView2);
4023 gPlayer2ScreenCoord.X := sX;
4024 gPlayer2ScreenCoord.Y := sY;
4025 end;
4027 e_SetViewPort(0, 0, gScreenWidth, gScreenHeight);
4029 if Split then
4030 e_DrawLine(2, 0, gScreenHeight div 2, gScreenWidth, gScreenHeight div 2, 0, 0, 0);
4031 end;
4033 {$IFDEF ENABLE_HOLMES}
4034 // draw inspector
4035 if (g_holmes_enabled) then g_Holmes_Draw();
4036 {$ENDIF}
4038 if MessageText <> '' then
4039 begin
4040 w := 0;
4041 h := 0;
4042 e_CharFont_GetSizeFmt(gMenuFont, MessageText, w, h);
4043 if Split then
4044 e_CharFont_PrintFmt(gMenuFont, (gScreenWidth div 2)-(w div 2),
4045 (gScreenHeight div 2)-(h div 2), MessageText)
4046 else
4047 e_CharFont_PrintFmt(gMenuFont, (gScreenWidth div 2)-(w div 2),
4048 Round(gScreenHeight / 2.75)-(h div 2), MessageText);
4049 end;
4051 if IsDrawStat or (gSpectMode = SPECT_STATS) then
4052 DrawStat();
4054 if gSpectHUD and (not gChatShow) and (gSpectMode <> SPECT_NONE) and (not gSpectAuto) then
4055 begin
4056 // Draw spectator GUI
4057 ww := 0;
4058 hh := 0;
4059 e_TextureFontGetSize(gStdFont, ww, hh);
4060 case gSpectMode of
4061 SPECT_STATS:
4062 e_TextureFontPrintEx(0, gScreenHeight - (hh+2)*2, 'MODE: Stats', gStdFont, 255, 255, 255, 1);
4063 SPECT_MAPVIEW:
4064 e_TextureFontPrintEx(0, gScreenHeight - (hh+2)*2, 'MODE: Observe Map', gStdFont, 255, 255, 255, 1);
4065 SPECT_PLAYERS:
4066 e_TextureFontPrintEx(0, gScreenHeight - (hh+2)*2, 'MODE: Watch Players', gStdFont, 255, 255, 255, 1);
4067 end;
4068 e_TextureFontPrintEx(2*ww, gScreenHeight - (hh+2), '< jump >', gStdFont, 255, 255, 255, 1);
4069 if gSpectMode = SPECT_STATS then
4070 begin
4071 e_TextureFontPrintEx(16*ww, gScreenHeight - (hh+2)*2, 'Autoview', gStdFont, 255, 255, 255, 1);
4072 e_TextureFontPrintEx(16*ww, gScreenHeight - (hh+2), '< fire >', gStdFont, 255, 255, 255, 1);
4073 end;
4074 if gSpectMode = SPECT_MAPVIEW then
4075 begin
4076 e_TextureFontPrintEx(22*ww, gScreenHeight - (hh+2)*2, '[-]', gStdFont, 255, 255, 255, 1);
4077 e_TextureFontPrintEx(26*ww, gScreenHeight - (hh+2)*2, 'Step ' + IntToStr(gSpectStep), gStdFont, 255, 255, 255, 1);
4078 e_TextureFontPrintEx(34*ww, gScreenHeight - (hh+2)*2, '[+]', gStdFont, 255, 255, 255, 1);
4079 e_TextureFontPrintEx(18*ww, gScreenHeight - (hh+2), '<prev weap>', gStdFont, 255, 255, 255, 1);
4080 e_TextureFontPrintEx(30*ww, gScreenHeight - (hh+2), '<next weap>', gStdFont, 255, 255, 255, 1);
4081 end;
4082 if gSpectMode = SPECT_PLAYERS then
4083 begin
4084 e_TextureFontPrintEx(22*ww, gScreenHeight - (hh+2)*2, 'Player 1', gStdFont, 255, 255, 255, 1);
4085 e_TextureFontPrintEx(20*ww, gScreenHeight - (hh+2), '<left/right>', gStdFont, 255, 255, 255, 1);
4086 if gSpectViewTwo then
4087 begin
4088 e_TextureFontPrintEx(37*ww, gScreenHeight - (hh+2)*2, 'Player 2', gStdFont, 255, 255, 255, 1);
4089 e_TextureFontPrintEx(34*ww, gScreenHeight - (hh+2), '<prev w/next w>', gStdFont, 255, 255, 255, 1);
4090 e_TextureFontPrintEx(52*ww, gScreenHeight - (hh+2)*2, '2x View', gStdFont, 255, 255, 255, 1);
4091 e_TextureFontPrintEx(51*ww, gScreenHeight - (hh+2), '<up/down>', gStdFont, 255, 255, 255, 1);
4092 end
4093 else
4094 begin
4095 e_TextureFontPrintEx(35*ww, gScreenHeight - (hh+2)*2, '2x View', gStdFont, 255, 255, 255, 1);
4096 e_TextureFontPrintEx(34*ww, gScreenHeight - (hh+2), '<up/down>', gStdFont, 255, 255, 255, 1);
4097 end;
4098 end;
4099 end;
4100 end;
4102 if gPauseMain and gGameOn and (g_ActiveWindow = nil) then
4103 begin
4104 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4105 e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
4107 e_CharFont_GetSize(gMenuFont, _lc[I_MENU_PAUSE], w, h);
4108 e_CharFont_Print(gMenuFont, (gScreenWidth div 2)-(w div 2),
4109 (gScreenHeight div 2)-(h div 2), _lc[I_MENU_PAUSE]);
4110 end;
4112 if not gGameOn then
4113 begin
4114 if (gState = STATE_MENU) then
4115 begin
4116 if (g_ActiveWindow = nil) or (g_ActiveWindow.BackTexture = '') then DrawMenuBackground('MENU_BACKGROUND');
4117 // F3 at menu will show game loading dialog
4118 if e_KeyPressed(IK_F3) then g_Menu_Show_LoadMenu(true);
4119 if (g_ActiveWindow <> nil) then
4120 begin
4121 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4122 e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
4123 end
4124 else
4125 begin
4126 // F3 at titlepic will show game loading dialog
4127 if e_KeyPressed(IK_F3) then
4128 begin
4129 g_Menu_Show_LoadMenu(true);
4130 if (g_ActiveWindow <> nil) then e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
4131 end;
4132 end;
4133 end;
4135 if gState = STATE_FOLD then
4136 begin
4137 e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 0, 0, 0, EndingGameCounter);
4138 end;
4140 if gState = STATE_INTERCUSTOM then
4141 begin
4142 if gLastMap and (gGameSettings.GameMode = GM_COOP) then
4143 begin
4144 back := 'TEXTURE_endpic';
4145 if not g_Texture_Get(back, ID) then
4146 back := _lc[I_TEXTURE_ENDPIC];
4147 end
4148 else
4149 back := 'INTER';
4151 DrawMenuBackground(back);
4153 DrawCustomStat();
4155 if g_ActiveWindow <> nil then
4156 begin
4157 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4158 e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
4159 end;
4160 end;
4162 if gState = STATE_INTERSINGLE then
4163 begin
4164 if EndingGameCounter > 0 then
4165 begin
4166 e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 0, 0, 0, EndingGameCounter);
4167 end
4168 else
4169 begin
4170 back := 'INTER';
4172 DrawMenuBackground(back);
4174 DrawSingleStat();
4176 if g_ActiveWindow <> nil then
4177 begin
4178 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4179 e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
4180 end;
4181 end;
4182 end;
4184 if gState = STATE_ENDPIC then
4185 begin
4186 ID := DWORD(-1);
4187 if g_Texture_Get('TEXTURE_endpic', ID) then DrawMenuBackground('TEXTURE_endpic')
4188 else DrawMenuBackground(_lc[I_TEXTURE_ENDPIC]);
4190 if g_ActiveWindow <> nil then
4191 begin
4192 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4193 e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
4194 end;
4195 end;
4197 if gState = STATE_SLIST then
4198 begin
4199 // if g_Texture_Get('MENU_BACKGROUND', ID) then
4200 // begin
4201 // e_DrawSize(ID, 0, 0, 0, False, False, gScreenWidth, gScreenHeight);
4202 // //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4203 // end;
4204 DrawMenuBackground('MENU_BACKGROUND');
4205 e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
4206 g_Serverlist_Draw(slCurrent, slTable);
4207 end;
4208 end;
4210 if g_ActiveWindow <> nil then
4211 begin
4212 if gGameOn then
4213 begin
4214 //e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
4215 e_DarkenQuadWH(0, 0, gScreenWidth, gScreenHeight, 150);
4216 end;
4217 g_ActiveWindow.Draw();
4218 end;
4220 {$IFNDEF HEADLESS}
4221 g_Console_Draw();
4222 {$ENDIF}
4224 if g_debug_Sounds and gGameOn then
4225 begin
4226 for w := 0 to High(e_SoundsArray) do
4227 for h := 0 to e_SoundsArray[w].nRefs do
4228 e_DrawPoint(1, w+100, h+100, 255, 0, 0);
4229 end;
4231 if gShowFPS then
4232 begin
4233 e_TextureFontPrint(0, 0, Format('FPS: %d', [FPS]), gStdFont);
4234 e_TextureFontPrint(0, 16, Format('UPS: %d', [UPS]), gStdFont);
4235 end;
4237 if gGameOn and gShowTime then
4238 drawTime(gScreenWidth-72, gScreenHeight-16);
4240 if gGameOn then drawProfilers();
4242 // TODO: draw this after the FBO and remap mouse click coordinates
4244 {$IFDEF ENABLE_HOLMES}
4245 g_Holmes_DrawUI();
4246 {$ENDIF}
4248 // blit framebuffer to screen
4250 e_SetRendertarget(False);
4251 e_SetViewPort(0, 0, gWinSizeX, gWinSizeY);
4252 e_BlitFramebuffer(gWinSizeX, gWinSizeY);
4254 // draw the overlay stuff on top of it
4256 g_Touch_Draw;
4257 end;
4259 procedure g_Game_Quit();
4260 begin
4261 g_Game_StopAllSounds(True);
4262 gMusic.Free();
4263 g_Game_FreeData();
4264 g_PlayerModel_FreeData();
4265 g_Texture_DeleteAll();
4266 g_Frames_DeleteAll();
4267 {$IFNDEF HEADLESS}
4268 //g_Menu_Free(); //k8: this segfaults after resolution change; who cares?
4269 {$ENDIF}
4271 if NetInitDone then g_Net_Free;
4273 // Íàäî óäàëèòü êàðòó ïîñëå òåñòà:
4274 if gMapToDelete <> '' then
4275 g_Game_DeleteTestMap();
4277 gExit := EXIT_QUIT;
4278 sys_RequestQuit;
4279 end;
4281 procedure g_FatalError(Text: String);
4282 begin
4283 g_Console_Add(Format(_lc[I_FATAL_ERROR], [Text]), True);
4284 e_WriteLog(Format(_lc[I_FATAL_ERROR], [Text]), TMsgType.Warning);
4286 gExit := EXIT_SIMPLE;
4287 if gGameOn then EndGame;
4288 end;
4290 procedure g_SimpleError(Text: String);
4291 begin
4292 g_Console_Add(Format(_lc[I_SIMPLE_ERROR], [Text]), True);
4293 e_WriteLog(Format(_lc[I_SIMPLE_ERROR], [Text]), TMsgType.Warning);
4294 end;
4296 procedure g_Game_SetupScreenSize();
4297 const
4298 RES_FACTOR = 4.0 / 3.0;
4299 var
4300 s: Single;
4301 rf: Single;
4302 bw, bh: Word;
4303 begin
4304 // Ðàçìåð ýêðàíîâ èãðîêîâ:
4305 gPlayerScreenSize.X := gScreenWidth-196;
4306 if (gPlayer1 <> nil) and (gPlayer2 <> nil) then
4307 gPlayerScreenSize.Y := gScreenHeight div 2
4308 else
4309 gPlayerScreenSize.Y := gScreenHeight;
4311 // Ðàçìåð çàäíåãî ïëàíà:
4312 if BackID <> DWORD(-1) then
4313 begin
4314 s := SKY_STRETCH;
4315 if (gScreenWidth*s > gMapInfo.Width) or
4316 (gScreenHeight*s > gMapInfo.Height) then
4317 begin
4318 gBackSize.X := gScreenWidth;
4319 gBackSize.Y := gScreenHeight;
4320 end
4321 else
4322 begin
4323 e_GetTextureSize(BackID, @bw, @bh);
4324 rf := Single(bw) / Single(bh);
4325 if (rf > RES_FACTOR) then bw := Round(Single(bh) * RES_FACTOR)
4326 else if (rf < RES_FACTOR) then bh := Round(Single(bw) / RES_FACTOR);
4327 s := Max(gScreenWidth / bw, gScreenHeight / bh);
4328 if (s < 1.0) then s := 1.0;
4329 gBackSize.X := Round(bw*s);
4330 gBackSize.Y := Round(bh*s);
4331 end;
4332 end;
4333 end;
4335 procedure g_Game_ChangeResolution(newWidth, newHeight: Word; nowFull, nowMax: Boolean);
4336 begin
4337 sys_SetDisplayMode(newWidth, newHeight, gBPP, nowFull, nowMax);
4338 end;
4340 procedure g_Game_AddPlayer(Team: Byte = TEAM_NONE);
4341 begin
4342 if ((not gGameOn) and (gState <> STATE_INTERCUSTOM))
4343 or (not (gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT])) then
4344 Exit;
4346 if (gGameSettings.MaxLives > 0) and (gLMSRespawn = LMS_RESPAWN_NONE) then
4347 Exit;
4349 if gPlayer1 = nil then
4350 begin
4351 if g_Game_IsClient then
4352 begin
4353 if NetPlrUID1 > -1 then
4354 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE);
4355 Exit;
4356 end;
4358 if not (Team in [TEAM_RED, TEAM_BLUE]) then
4359 Team := gPlayer1Settings.Team;
4361 // Ñîçäàíèå ïåðâîãî èãðîêà:
4362 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
4363 gPlayer1Settings.Color,
4364 Team, False));
4365 if gPlayer1 = nil then
4366 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]))
4367 else
4368 begin
4369 gPlayer1.Name := gPlayer1Settings.Name;
4370 gPlayer1.WeapSwitchMode := gPlayer1Settings.WeaponSwitch;
4371 gPlayer1.setWeaponPrefs(gPlayer1Settings.WeaponPreferences);
4372 gPlayer1.SwitchToEmpty := gPlayer1Settings.SwitchToEmpty;
4373 gPlayer1.SkipFist := gPlayer1Settings.SkipFist;
4374 g_Console_Add(Format(_lc[I_PLAYER_JOIN], [gPlayer1.Name]), True);
4375 if g_Game_IsServer and g_Game_IsNet then
4376 MH_SEND_PlayerCreate(gPlayer1.UID);
4377 gPlayer1.Respawn(False, True);
4378 g_Net_Slist_ServerPlayerComes();
4379 end;
4381 Exit;
4382 end;
4383 if gPlayer2 = nil then
4384 begin
4385 if g_Game_IsClient then
4386 begin
4387 if NetPlrUID2 > -1 then
4388 gPlayer2 := g_Player_Get(NetPlrUID2);
4389 Exit;
4390 end;
4392 if not (Team in [TEAM_RED, TEAM_BLUE]) then
4393 Team := gPlayer2Settings.Team;
4395 // Ñîçäàíèå âòîðîãî èãðîêà:
4396 gPlayer2 := g_Player_Get(g_Player_Create(gPlayer2Settings.Model,
4397 gPlayer2Settings.Color,
4398 Team, False));
4399 if gPlayer2 = nil then
4400 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [2]))
4401 else
4402 begin
4403 gPlayer2.Name := gPlayer2Settings.Name;
4404 gPlayer2.WeapSwitchMode := gPlayer2Settings.WeaponSwitch;
4405 gPlayer2.setWeaponPrefs(gPlayer2Settings.WeaponPreferences);
4406 gPlayer2.SwitchToEmpty := gPlayer2Settings.SwitchToEmpty;
4407 gPlayer2.SkipFist := gPlayer2Settings.SkipFist;
4408 g_Console_Add(Format(_lc[I_PLAYER_JOIN], [gPlayer2.Name]), True);
4409 if g_Game_IsServer and g_Game_IsNet then
4410 MH_SEND_PlayerCreate(gPlayer2.UID);
4411 gPlayer2.Respawn(False, True);
4412 g_Net_Slist_ServerPlayerComes();
4413 end;
4415 Exit;
4416 end;
4417 end;
4419 procedure g_Game_RemovePlayer();
4420 var
4421 Pl: TPlayer;
4422 begin
4423 if ((not gGameOn) and (gState <> STATE_INTERCUSTOM))
4424 or (not (gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT])) then
4425 Exit;
4426 Pl := gPlayer2;
4427 if Pl <> nil then
4428 begin
4429 if g_Game_IsServer then
4430 begin
4431 Pl.Lives := 0;
4432 Pl.Kill(K_SIMPLEKILL, 0, HIT_DISCON);
4433 g_Console_Add(Format(_lc[I_PLAYER_LEAVE], [Pl.Name]), True);
4434 g_Player_Remove(Pl.UID);
4435 g_Net_Slist_ServerPlayerLeaves();
4436 end
4437 else
4438 begin
4439 gSpectLatchPID2 := Pl.UID;
4440 gPlayer2 := nil;
4441 end;
4442 Exit;
4443 end;
4444 Pl := gPlayer1;
4445 if Pl <> nil then
4446 begin
4447 if g_Game_IsServer then
4448 begin
4449 Pl.Lives := 0;
4450 Pl.Kill(K_SIMPLEKILL, 0, HIT_DISCON);
4451 g_Console_Add(Format(_lc[I_PLAYER_LEAVE], [Pl.Name]), True);
4452 g_Player_Remove(Pl.UID);
4453 g_Net_Slist_ServerPlayerLeaves();
4454 end else
4455 begin
4456 gSpectLatchPID1 := Pl.UID;
4457 gPlayer1 := nil;
4458 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE);
4459 end;
4460 Exit;
4461 end;
4462 g_Net_Slist_ServerPlayerLeaves();
4463 end;
4465 procedure g_Game_Spectate();
4466 begin
4467 g_Game_RemovePlayer();
4468 if gPlayer1 <> nil then
4469 g_Game_RemovePlayer();
4470 end;
4472 procedure g_Game_SpectateCenterView();
4473 begin
4474 gSpectX := Max(gMapInfo.Width div 2 - gScreenWidth div 2, 0);
4475 gSpectY := Max(gMapInfo.Height div 2 - gScreenHeight div 2, 0);
4476 end;
4478 procedure g_Game_StartSingle(Map: String; TwoPlayers: Boolean; nPlayers: Byte);
4479 var
4480 i, nPl: Integer;
4481 tmps: AnsiString;
4482 begin
4483 g_Game_Free();
4485 e_WriteLog('Starting singleplayer game...', TMsgType.Notify);
4487 g_Game_ClearLoading();
4489 // Íàñòðîéêè èãðû:
4490 FillByte(gGameSettings, SizeOf(TGameSettings), 0);
4491 gAimLine := False;
4492 gShowMap := False;
4493 gGameSettings.GameType := GT_SINGLE;
4494 gGameSettings.MaxLives := 0;
4495 gGameSettings.Options := gGameSettings.Options + GAME_OPTION_ALLOWEXIT;
4496 gGameSettings.Options := gGameSettings.Options + GAME_OPTION_MONSTERS;
4497 gGameSettings.Options := gGameSettings.Options + GAME_OPTION_BOTVSMONSTER;
4498 gGameSettings.Options := gGameSettings.Options + GAME_OPTION_TEAMHITPROJECTILE;
4499 gGameSettings.Options := gGameSettings.Options + GAME_OPTION_TEAMHITTRACE;
4500 gGameSettings.Options := gGameSettings.Options + GAME_OPTION_RULEZRANDOM;
4501 gSwitchGameMode := GM_SINGLE;
4503 gLMSRespawn := LMS_RESPAWN_NONE;
4504 gLMSRespawnTime := 0;
4505 gSpectLatchPID1 := 0;
4506 gSpectLatchPID2 := 0;
4508 g_Game_ExecuteEvent('ongamestart');
4510 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
4511 g_Game_SetupScreenSize();
4513 // Ñîçäàíèå ïåðâîãî èãðîêà:
4514 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
4515 gPlayer1Settings.Color,
4516 gPlayer1Settings.Team, False));
4517 if gPlayer1 = nil then
4518 begin
4519 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]));
4520 Exit;
4521 end;
4523 gPlayer1.Name := gPlayer1Settings.Name;
4524 gPlayer1.WeapSwitchMode := gPlayer1Settings.WeaponSwitch;
4525 gPlayer1.setWeaponPrefs(gPlayer1Settings.WeaponPreferences);
4526 gPlayer1.SwitchToEmpty := gPlayer1Settings.SwitchToEmpty;
4527 gPlayer1.SkipFist := gPlayer1Settings.SkipFist;
4528 nPl := 1;
4530 // Ñîçäàíèå âòîðîãî èãðîêà, åñëè åñòü:
4531 if TwoPlayers then
4532 begin
4533 gPlayer2 := g_Player_Get(g_Player_Create(gPlayer2Settings.Model,
4534 gPlayer2Settings.Color,
4535 gPlayer2Settings.Team, False));
4536 if gPlayer2 = nil then
4537 begin
4538 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [2]));
4539 Exit;
4540 end;
4542 gPlayer2.Name := gPlayer2Settings.Name;
4543 gPlayer2.WeapSwitchMode := gPlayer2Settings.WeaponSwitch;
4544 gPlayer2.setWeaponPrefs(gPlayer2Settings.WeaponPreferences);
4545 gPlayer2.SwitchToEmpty := gPlayer2Settings.SwitchToEmpty;
4546 gPlayer2.SkipFist := gPlayer2Settings.SkipFist;
4547 Inc(nPl);
4548 end;
4550 // Çàãðóçêà è çàïóñê êàðòû:
4551 if not g_Game_StartMap(false{asMegawad}, MAP, True) then
4552 begin
4553 if (Pos(':\', Map) > 0) or (Pos(':/', Map) > 0) then tmps := Map else tmps := gGameSettings.WAD + ':\' + MAP;
4554 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [tmps]));
4555 Exit;
4556 end;
4558 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4559 g_Player_Init();
4561 // Ñîçäàåì áîòîâ:
4562 for i := nPl+1 to nPlayers do
4563 g_Player_Create(STD_PLAYER_MODEL, _RGB(0, 0, 0), 0, True);
4564 end;
4566 procedure g_Game_StartCustom(Map: String; GameMode: Byte;
4567 TimeLimit, ScoreLimit: Word;
4568 MaxLives: Byte;
4569 Options: LongWord; nPlayers: Byte);
4570 var
4571 i, nPl: Integer;
4572 begin
4573 g_Game_Free();
4575 e_WriteLog('Starting custom game...', TMsgType.Notify);
4577 g_Game_ClearLoading();
4579 // Íàñòðîéêè èãðû:
4580 gGameSettings.GameType := GT_CUSTOM;
4581 gGameSettings.GameMode := GameMode;
4582 gSwitchGameMode := GameMode;
4583 gGameSettings.TimeLimit := TimeLimit;
4584 gGameSettings.ScoreLimit := ScoreLimit;
4585 gGameSettings.MaxLives := IfThen(GameMode = GM_CTF, 0, MaxLives);
4586 gGameSettings.Options := Options;
4588 gCoopTotalMonstersKilled := 0;
4589 gCoopTotalSecretsFound := 0;
4590 gCoopTotalMonsters := 0;
4591 gCoopTotalSecrets := 0;
4592 gAimLine := False;
4593 gShowMap := False;
4595 gLMSRespawn := LMS_RESPAWN_NONE;
4596 gLMSRespawnTime := 0;
4597 gSpectLatchPID1 := 0;
4598 gSpectLatchPID2 := 0;
4600 g_Game_ExecuteEvent('ongamestart');
4602 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
4603 g_Game_SetupScreenSize();
4605 // Ðåæèì íàáëþäàòåëÿ:
4606 if nPlayers = 0 then
4607 begin
4608 gPlayer1 := nil;
4609 gPlayer2 := nil;
4610 end;
4612 nPl := 0;
4613 if nPlayers >= 1 then
4614 begin
4615 // Ñîçäàíèå ïåðâîãî èãðîêà:
4616 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
4617 gPlayer1Settings.Color,
4618 gPlayer1Settings.Team, False));
4619 if gPlayer1 = nil then
4620 begin
4621 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]));
4622 Exit;
4623 end;
4625 gPlayer1.Name := gPlayer1Settings.Name;
4626 gPlayer1.WeapSwitchMode := gPlayer1Settings.WeaponSwitch;
4627 gPlayer1.setWeaponPrefs(gPlayer1Settings.WeaponPreferences);
4628 gPlayer1.SwitchToEmpty := gPlayer1Settings.SwitchToEmpty;
4629 gPlayer1.SkipFist := gPlayer1Settings.SkipFist;
4630 Inc(nPl);
4631 end;
4633 if nPlayers >= 2 then
4634 begin
4635 // Ñîçäàíèå âòîðîãî èãðîêà:
4636 gPlayer2 := g_Player_Get(g_Player_Create(gPlayer2Settings.Model,
4637 gPlayer2Settings.Color,
4638 gPlayer2Settings.Team, False));
4639 if gPlayer2 = nil then
4640 begin
4641 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [2]));
4642 Exit;
4643 end;
4645 gPlayer2.Name := gPlayer2Settings.Name;
4646 gPlayer2.WeapSwitchMode := gPlayer2Settings.WeaponSwitch;
4647 gPlayer2.setWeaponPrefs(gPlayer2Settings.WeaponPreferences);
4648 gPlayer2.SwitchToEmpty := gPlayer2Settings.SwitchToEmpty;
4649 gPlayer2.SkipFist := gPlayer2Settings.SkipFist;
4650 Inc(nPl);
4651 end;
4653 // Çàãðóçêà è çàïóñê êàðòû:
4654 if not g_Game_StartMap(true{asMegawad}, Map, True) then
4655 begin
4656 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [Map]));
4657 Exit;
4658 end;
4660 // Íåò òî÷åê ïîÿâëåíèÿ:
4661 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1) +
4662 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2) +
4663 g_Map_GetPointCount(RESPAWNPOINT_DM) +
4664 g_Map_GetPointCount(RESPAWNPOINT_RED)+
4665 g_Map_GetPointCount(RESPAWNPOINT_BLUE)) < 1 then
4666 begin
4667 g_FatalError(_lc[I_GAME_ERROR_GET_SPAWN]);
4668 Exit;
4669 end;
4671 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4672 g_Player_Init();
4674 // Ñîçäàåì áîòîâ:
4675 for i := nPl+1 to nPlayers do
4676 g_Player_Create(STD_PLAYER_MODEL, _RGB(0, 0, 0), 0, True);
4677 end;
4679 procedure g_Game_StartServer(Map: String; GameMode: Byte;
4680 TimeLimit, ScoreLimit: Word; MaxLives: Byte;
4681 Options: LongWord; nPlayers: Byte;
4682 IPAddr: LongWord; Port: Word);
4683 begin
4684 g_Game_Free();
4685 g_Net_Slist_ServerClosed();
4687 e_WriteLog('Starting net game (server)...', TMsgType.Notify);
4689 g_Game_ClearLoading();
4691 ClearDebugCvars();
4693 // Íàñòðîéêè èãðû:
4694 gGameSettings.GameType := GT_SERVER;
4695 gGameSettings.GameMode := GameMode;
4696 gSwitchGameMode := GameMode;
4697 gGameSettings.TimeLimit := TimeLimit;
4698 gGameSettings.ScoreLimit := ScoreLimit;
4699 gGameSettings.MaxLives := IfThen(GameMode = GM_CTF, 0, MaxLives);
4700 gGameSettings.Options := Options;
4702 gCoopTotalMonstersKilled := 0;
4703 gCoopTotalSecretsFound := 0;
4704 gCoopTotalMonsters := 0;
4705 gCoopTotalSecrets := 0;
4706 gAimLine := False;
4707 gShowMap := False;
4709 gLMSRespawn := LMS_RESPAWN_NONE;
4710 gLMSRespawnTime := 0;
4711 gSpectLatchPID1 := 0;
4712 gSpectLatchPID2 := 0;
4714 g_Game_ExecuteEvent('ongamestart');
4716 // Óñòàíîâêà ðàçìåðîâ îêíà èãðîêà
4717 g_Game_SetupScreenSize();
4719 // Ðåæèì íàáëþäàòåëÿ:
4720 if nPlayers = 0 then
4721 begin
4722 gPlayer1 := nil;
4723 gPlayer2 := nil;
4724 end;
4726 if nPlayers >= 1 then
4727 begin
4728 // Ñîçäàíèå ïåðâîãî èãðîêà:
4729 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
4730 gPlayer1Settings.Color,
4731 gPlayer1Settings.Team, False));
4732 if gPlayer1 = nil then
4733 begin
4734 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]));
4735 Exit;
4736 end;
4738 gPlayer1.Name := gPlayer1Settings.Name;
4739 gPlayer1.WeapSwitchMode := gPlayer1Settings.WeaponSwitch;
4740 gPlayer1.setWeaponPrefs(gPlayer1Settings.WeaponPreferences);
4741 gPlayer1.SwitchToEmpty := gPlayer1Settings.SwitchToEmpty;
4742 gPlayer1.SkipFist := gPlayer1Settings.SkipFist;
4743 end;
4745 if nPlayers >= 2 then
4746 begin
4747 // Ñîçäàíèå âòîðîãî èãðîêà:
4748 gPlayer2 := g_Player_Get(g_Player_Create(gPlayer2Settings.Model,
4749 gPlayer2Settings.Color,
4750 gPlayer2Settings.Team, False));
4751 if gPlayer2 = nil then
4752 begin
4753 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [2]));
4754 Exit;
4755 end;
4757 gPlayer2.Name := gPlayer2Settings.Name;
4758 gPlayer2.WeapSwitchMode := gPlayer2Settings.WeaponSwitch;
4759 gPlayer2.setWeaponPrefs(gPlayer2Settings.WeaponPreferences);
4760 gPlayer2.SwitchToEmpty := gPlayer2Settings.SwitchToEmpty;
4761 gPlayer2.SkipFist := gPlayer2Settings.SkipFist;
4762 end;
4764 g_Game_SetLoadingText(_lc[I_LOAD_HOST], 0, False);
4765 if NetForwardPorts then
4766 g_Game_SetLoadingText(_lc[I_LOAD_PORTS], 0, False);
4768 // Ñòàðòóåì ñåðâåð
4769 if not g_Net_Host(IPAddr, Port, NetMaxClients) then
4770 begin
4771 g_FatalError(_lc[I_NET_MSG] + Format(_lc[I_NET_ERR_HOST], [Port]));
4772 Exit;
4773 end;
4775 g_Net_Slist_Set(NetMasterList);
4777 g_Net_Slist_ServerStarted();
4779 // Çàãðóçêà è çàïóñê êàðòû:
4780 if not g_Game_StartMap(false{asMegawad}, Map, True) then
4781 begin
4782 g_Net_Slist_ServerClosed();
4783 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [Map]));
4784 Exit;
4785 end;
4787 // Íåò òî÷åê ïîÿâëåíèÿ:
4788 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1) +
4789 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2) +
4790 g_Map_GetPointCount(RESPAWNPOINT_DM) +
4791 g_Map_GetPointCount(RESPAWNPOINT_RED)+
4792 g_Map_GetPointCount(RESPAWNPOINT_BLUE)) < 1 then
4793 begin
4794 g_Net_Slist_ServerClosed();
4795 g_FatalError(_lc[I_GAME_ERROR_GET_SPAWN]);
4796 Exit;
4797 end;
4799 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4800 g_Player_Init();
4802 g_Net_Slist_ServerMapStarted();
4803 NetState := NET_STATE_GAME;
4804 end;
4806 procedure g_Game_StartClient(Addr: String; Port: Word; PW: String);
4807 var
4808 Map: String;
4809 WadName: string;
4810 Ptr: Pointer;
4811 T: Cardinal;
4812 MID: Byte;
4813 State: Byte;
4814 OuterLoop: Boolean;
4815 newResPath: string;
4816 InMsg: TMsg;
4817 begin
4818 g_Game_Free();
4820 State := 0;
4821 e_WriteLog('Starting net game (client)...', TMsgType.Notify);
4822 e_WriteLog('NET: Trying to connect to ' + Addr + ':' + IntToStr(Port) + '...', TMsgType.Notify);
4824 g_Game_ClearLoading();
4826 ClearDebugCvars();
4828 // Íàñòðîéêè èãðû:
4829 gGameSettings.GameType := GT_CLIENT;
4831 gCoopTotalMonstersKilled := 0;
4832 gCoopTotalSecretsFound := 0;
4833 gCoopTotalMonsters := 0;
4834 gCoopTotalSecrets := 0;
4835 gAimLine := False;
4836 gShowMap := False;
4838 g_Game_ExecuteEvent('ongamestart');
4840 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
4841 g_Game_SetupScreenSize();
4843 NetState := NET_STATE_AUTH;
4845 g_Game_SetLoadingText(_lc[I_LOAD_CONNECT], 0, False);
4847 // create (or update) map/resource databases
4848 g_Res_CreateDatabases(true);
4850 gLMSRespawn := LMS_RESPAWN_NONE;
4851 gLMSRespawnTime := 0;
4852 gSpectLatchPID1 := 0;
4853 gSpectLatchPID2 := 0;
4855 // Ñòàðòóåì êëèåíò
4856 if not g_Net_Connect(Addr, Port) then
4857 begin
4858 g_FatalError(_lc[I_NET_MSG] + _lc[I_NET_ERR_CONN]);
4859 NetState := NET_STATE_NONE;
4860 Exit;
4861 end;
4863 g_Game_SetLoadingText(_lc[I_LOAD_SEND_INFO], 0, False);
4864 MC_SEND_Info(PW);
4865 g_Game_SetLoadingText(_lc[I_LOAD_WAIT_INFO], 0, False);
4867 OuterLoop := True;
4868 while OuterLoop do
4869 begin
4870 // fuck! https://www.mail-archive.com/enet-discuss@cubik.org/msg00852.html
4871 // tl;dr: on shitdows, we can get -1 sometimes, and it is *NOT* a failure.
4872 // thank you, enet. let's ignore failures altogether then.
4873 while (enet_host_service(NetHost, @NetEvent, 50) > 0) do
4874 begin
4875 if (NetEvent.kind = ENET_EVENT_TYPE_RECEIVE) then
4876 begin
4877 Ptr := NetEvent.packet^.data;
4878 if not InMsg.Init(Ptr, NetEvent.packet^.dataLength, True) then
4879 begin
4880 enet_packet_destroy(NetEvent.packet);
4881 continue;
4882 end;
4884 InMsg.ReadLongWord(); // skip size
4885 MID := InMsg.ReadByte();
4887 if (MID = NET_MSG_INFO) and (State = 0) then
4888 begin
4889 NetMyID := InMsg.ReadByte();
4890 NetPlrUID1 := InMsg.ReadWord();
4892 WadName := InMsg.ReadString();
4893 Map := InMsg.ReadString();
4895 gWADHash := InMsg.ReadMD5();
4897 gGameSettings.GameMode := InMsg.ReadByte();
4898 gSwitchGameMode := gGameSettings.GameMode;
4899 gGameSettings.ScoreLimit := InMsg.ReadWord();
4900 gGameSettings.TimeLimit := InMsg.ReadWord();
4901 gGameSettings.MaxLives := InMsg.ReadByte();
4902 gGameSettings.Options := InMsg.ReadLongWord();
4903 T := InMsg.ReadLongWord();
4905 //newResPath := g_Res_SearchSameWAD(MapsDir, WadName, gWADHash);
4906 //if newResPath = '' then
4907 begin
4908 //g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
4909 newResPath := g_Res_DownloadMapWAD(ExtractFileName(WadName), gWADHash);
4910 if newResPath = '' then
4911 begin
4912 g_FatalError(_lc[I_NET_ERR_HASH]);
4913 enet_packet_destroy(NetEvent.packet);
4914 NetState := NET_STATE_NONE;
4915 Exit;
4916 end;
4917 e_LogWritefln('using downloaded map wad [%s] for [%s]`', [newResPath, WadName], TMsgType.Notify);
4918 end;
4919 //newResPath := ExtractRelativePath(MapsDir, newResPath);
4922 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
4923 gPlayer1Settings.Color,
4924 gPlayer1Settings.Team, False));
4926 if gPlayer1 = nil then
4927 begin
4928 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]));
4930 enet_packet_destroy(NetEvent.packet);
4931 NetState := NET_STATE_NONE;
4932 Exit;
4933 end;
4935 gPlayer1.Name := gPlayer1Settings.Name;
4936 gPlayer1.WeapSwitchMode := gPlayer1Settings.WeaponSwitch;
4937 gPlayer1.setWeaponPrefs(gPlayer1Settings.WeaponPreferences);
4938 gPlayer1.SwitchToEmpty := gPlayer1Settings.SwitchToEmpty;
4939 gPlayer1.SkipFist := gPlayer1Settings.SkipFist;
4940 gPlayer1.UID := NetPlrUID1;
4941 gPlayer1.Reset(True);
4943 if not g_Game_StartMap(false{asMegawad}, newResPath + ':\' + Map, True) then
4944 begin
4945 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [WadName + ':\' + Map]));
4947 enet_packet_destroy(NetEvent.packet);
4948 NetState := NET_STATE_NONE;
4949 Exit;
4950 end;
4952 gTime := T;
4954 State := 1;
4955 OuterLoop := False;
4956 enet_packet_destroy(NetEvent.packet);
4957 break;
4958 end
4959 else
4960 enet_packet_destroy(NetEvent.packet);
4961 end
4962 else
4963 begin
4964 if (NetEvent.kind = ENET_EVENT_TYPE_DISCONNECT) then
4965 begin
4966 State := 0;
4967 if (NetEvent.data <= NET_DISC_MAX) then
4968 g_Console_Add(_lc[I_NET_MSG_ERROR] + _lc[I_NET_ERR_CONN] + ' ' +
4969 _lc[TStrings_Locale(Cardinal(I_NET_DISC_NONE) + NetEvent.data)], True);
4970 OuterLoop := False;
4971 Break;
4972 end;
4973 end;
4974 end;
4976 ProcessLoading(True);
4977 if g_Net_UserRequestExit() then
4978 begin
4979 State := 0;
4980 break;
4981 end;
4982 end;
4984 if State <> 1 then
4985 begin
4986 g_FatalError(_lc[I_NET_MSG] + _lc[I_NET_ERR_CONN]);
4987 NetState := NET_STATE_NONE;
4988 Exit;
4989 end;
4991 g_Player_Init();
4992 NetState := NET_STATE_GAME;
4993 MC_SEND_FullStateRequest;
4994 e_WriteLog('NET: Connection successful.', TMsgType.Notify);
4995 end;
4997 var
4998 lastAsMegaWad: Boolean = false;
5000 procedure g_Game_ChangeMap(const MapPath: String);
5001 var
5002 Force: Boolean;
5003 begin
5004 g_Game_ClearLoading();
5006 Force := gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF];
5007 // Åñëè óðîâåíü çàâåðøèëñÿ ïî òðèããåðó Âûõîä, íå î÷èùàòü èíâåíòàðü
5008 if gExitByTrigger then
5009 begin
5010 Force := False;
5011 gExitByTrigger := False;
5012 end;
5013 if not g_Game_StartMap(lastAsMegaWad, MapPath, Force) then
5014 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [MapPath]));
5015 end;
5017 procedure g_Game_Restart();
5018 var
5019 Map: string;
5020 begin
5021 if g_Game_IsClient then
5022 Exit;
5023 map := g_ExtractFileName(gMapInfo.Map);
5024 e_LogWritefln('g_Game_Restart: map = "%s" gCurrentMapFileName = "%s"', [map, gCurrentMapFileName]);
5026 MessageTime := 0;
5027 gGameOn := False;
5028 g_Game_ClearLoading();
5029 g_Game_StartMap(lastAsMegaWad, Map, True, gCurrentMapFileName);
5030 end;
5032 function g_Game_StartMap (asMegawad: Boolean; Map: String; Force: Boolean = False; const oldMapPath: AnsiString=''): Boolean;
5033 var
5034 NewWAD, ResName: String;
5035 I: Integer;
5036 nws: AnsiString;
5037 begin
5038 g_Map_Free((Map <> gCurrentMapFileName) and (oldMapPath <> gCurrentMapFileName));
5039 g_Player_RemoveAllCorpses();
5041 if (not g_Game_IsClient) and
5042 (gSwitchGameMode <> gGameSettings.GameMode) and
5043 (gGameSettings.GameMode <> GM_SINGLE) then
5044 begin
5045 if gSwitchGameMode = GM_CTF then
5046 gGameSettings.MaxLives := 0;
5047 gGameSettings.GameMode := gSwitchGameMode;
5048 Force := True;
5049 end else
5050 gSwitchGameMode := gGameSettings.GameMode;
5052 g_Player_ResetTeams();
5054 lastAsMegaWad := asMegawad;
5055 if isWadPath(Map) then
5056 begin
5057 NewWAD := g_ExtractWadName(Map);
5058 ResName := g_ExtractFileName(Map);
5059 if g_Game_IsServer then
5060 begin
5061 nws := findDiskWad(NewWAD);
5062 //writeln('000: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
5063 if (asMegawad) then
5064 begin
5065 if (length(nws) = 0) then nws := e_FindWad(MegawadDirs, NewWAD);
5066 if (length(nws) = 0) then nws := e_FindWad(MapDirs, NewWAD);
5067 end
5068 else
5069 begin
5070 if (length(nws) = 0) then nws := e_FindWad(MapDirs, NewWAD);
5071 if (length(nws) = 0) then nws := e_FindWad(MegawadDirs, NewWAD);
5072 end;
5073 //if (length(nws) = 0) then nws := e_FindWad(MapDownloadDirs, NewWAD);
5074 //writeln('001: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
5075 //nws := NewWAD;
5076 if (length(nws) = 0) then
5077 begin
5078 ResName := ''; // failed
5079 end
5080 else
5081 begin
5082 NewWAD := nws;
5083 if (g_Game_IsNet) then gWADHash := MD5File(nws);
5084 //writeln('********: nws=', nws, ' : Map=', Map, ' : nw=', NewWAD, ' : resname=', ResName);
5085 g_Game_LoadWAD(NewWAD);
5086 end;
5087 end
5088 else
5089 begin
5090 // hash received in MC_RECV_GameEvent -> NET_EV_MAPSTART
5091 NewWAD := g_Game_ClientWAD(NewWAD, gWADHash);
5092 end;
5093 end
5094 else
5095 begin
5096 NewWAD := gGameSettings.WAD;
5097 ResName := Map;
5098 end;
5100 gTime := 0;
5102 //writeln('********: gsw=', gGameSettings.WAD, '; rn=', ResName);
5103 result := false;
5104 if (ResName <> '') and (NewWAD <> '') then
5105 begin
5106 //result := g_Map_Load(gGameSettings.WAD + ':\' + ResName);
5107 result := g_Map_Load(NewWAD+':\'+ResName);
5108 end;
5109 if Result then
5110 begin
5111 g_Player_ResetAll(Force or gLastMap, gGameSettings.GameType = GT_SINGLE);
5113 gState := STATE_NONE;
5114 g_ActiveWindow := nil;
5115 gGameOn := True;
5117 DisableCheats();
5118 ResetTimer();
5120 if gGameSettings.GameMode = GM_CTF then
5121 begin
5122 g_Map_ResetFlag(FLAG_RED);
5123 g_Map_ResetFlag(FLAG_BLUE);
5124 // CTF, à ôëàãîâ íåò:
5125 if not g_Map_HaveFlagPoints() then
5126 g_SimpleError(_lc[I_GAME_ERROR_CTF]);
5127 end;
5128 end
5129 else
5130 begin
5131 gState := STATE_MENU;
5132 gGameOn := False;
5133 end;
5135 gExit := 0;
5136 gPauseMain := false;
5137 gPauseHolmes := false;
5138 NetTimeToUpdate := 1;
5139 NetTimeToReliable := 0;
5140 NetTimeToMaster := NetMasterRate;
5141 gSpectLatchPID1 := 0;
5142 gSpectLatchPID2 := 0;
5143 gMissionFailed := False;
5144 gNextMap := '';
5146 gCoopMonstersKilled := 0;
5147 gCoopSecretsFound := 0;
5149 gVoteInProgress := False;
5150 gVotePassed := False;
5151 gVoteCount := 0;
5152 gVoted := False;
5154 gStatsOff := False;
5156 if not gGameOn then Exit;
5158 g_Game_SpectateCenterView();
5160 if g_Game_IsServer then
5161 begin
5162 if (gGameSettings.MaxLives > 0) and (gGameSettings.WarmupTime > 0) then
5163 begin
5164 gLMSRespawn := LMS_RESPAWN_WARMUP;
5165 gLMSRespawnTime := gTime + gGameSettings.WarmupTime*1000;
5166 gLMSSoftSpawn := True;
5167 if g_Game_IsNet then
5168 MH_SEND_GameEvent(NET_EV_LMS_WARMUP, gLMSRespawnTime - gTime);
5169 end
5170 else
5171 begin
5172 gLMSRespawn := LMS_RESPAWN_NONE;
5173 gLMSRespawnTime := 0;
5174 end;
5175 end;
5177 if NetMode = NET_SERVER then
5178 begin
5179 // reset full state flags
5180 if NetClients <> nil then
5181 for I := 0 to High(NetClients) do
5182 NetClients[I].FullUpdateSent := False;
5184 MH_SEND_GameEvent(NET_EV_MAPSTART, gGameSettings.GameMode, Map);
5186 // Ìàñòåðñåðâåð
5187 g_Net_Slist_ServerMapStarted();
5189 if NetClients <> nil then
5190 for I := 0 to High(NetClients) do
5191 if NetClients[I].Used then
5192 begin
5193 NetClients[I].Voted := False;
5194 if NetClients[I].RequestedFullUpdate then
5195 begin
5196 MH_SEND_Everything((NetClients[I].State = NET_STATE_AUTH), I);
5197 NetClients[I].RequestedFullUpdate := False;
5198 end;
5199 end;
5201 g_Net_UnbanNonPerm();
5202 end;
5204 if gLastMap then
5205 begin
5206 gCoopTotalMonstersKilled := 0;
5207 gCoopTotalSecretsFound := 0;
5208 gCoopTotalMonsters := 0;
5209 gCoopTotalSecrets := 0;
5210 gLastMap := False;
5211 end;
5213 g_Game_ExecuteEvent('onmapstart');
5214 end;
5216 procedure SetFirstLevel;
5217 begin
5218 gNextMap := '';
5220 MapList := g_Map_GetMapsList(gGameSettings.WAD);
5221 if MapList = nil then
5222 Exit;
5224 SortSArray(MapList);
5225 gNextMap := MapList[Low(MapList)];
5227 MapList := nil;
5228 end;
5230 procedure g_Game_ExitLevel(const Map: AnsiString);
5231 begin
5232 gNextMap := Map;
5234 gCoopTotalMonstersKilled := gCoopTotalMonstersKilled + gCoopMonstersKilled;
5235 gCoopTotalSecretsFound := gCoopTotalSecretsFound + gCoopSecretsFound;
5236 gCoopTotalMonsters := gCoopTotalMonsters + gTotalMonsters;
5237 gCoopTotalSecrets := gCoopTotalSecrets + gSecretsCount;
5239 // Âûøëè â âûõîä â Îäèíî÷íîé èãðå:
5240 if gGameSettings.GameType = GT_SINGLE then
5241 gExit := EXIT_ENDLEVELSINGLE
5242 else // Âûøëè â âûõîä â Ñâîåé èãðå
5243 begin
5244 gExit := EXIT_ENDLEVELCUSTOM;
5245 if gGameSettings.GameMode = GM_COOP then
5246 g_Player_RememberAll;
5248 if not g_Map_Exist(gGameSettings.WAD + ':\' + gNextMap) then
5249 begin
5250 gLastMap := True;
5251 if gGameSettings.GameMode = GM_COOP then
5252 gStatsOff := True;
5254 gStatsPressed := True;
5255 gNextMap := 'MAP01';
5257 if not g_Map_Exist(gGameSettings.WAD + ':\' + gNextMap) then
5258 g_Game_NextLevel;
5260 if g_Game_IsNet then
5261 begin
5262 MH_SEND_GameStats();
5263 MH_SEND_CoopStats();
5264 end;
5265 end;
5266 end;
5267 end;
5269 procedure g_Game_RestartLevel();
5270 var
5271 Map: string;
5272 begin
5273 if gGameSettings.GameMode = GM_SINGLE then
5274 begin
5275 g_Game_Restart();
5276 Exit;
5277 end;
5278 gExit := EXIT_ENDLEVELCUSTOM;
5279 Map := g_ExtractFileName(gMapInfo.Map);
5280 gNextMap := Map;
5281 end;
5283 function g_Game_ClientWAD (NewWAD: String; const WHash: TMD5Digest): AnsiString;
5284 var
5285 gWAD{, xwad}: String;
5286 begin
5287 result := NewWAD;
5288 if not g_Game_IsClient then Exit;
5289 //e_LogWritefln('*** g_Game_ClientWAD: `%s`', [NewWAD]);
5291 gWAD := g_Res_DownloadMapWAD(ExtractFileName(NewWAD), WHash);
5292 if gWAD = '' then
5293 begin
5294 result := '';
5295 g_Game_Free();
5296 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_WAD], [ExtractFileName(NewWAD)]));
5297 Exit;
5298 end;
5300 e_LogWritefln('using downloaded client map wad [%s] for [%s]', [gWAD, NewWAD], TMsgType.Notify);
5301 NewWAD := gWAD;
5303 g_Game_LoadWAD(NewWAD);
5304 result := NewWAD;
5307 if LowerCase(NewWAD) = LowerCase(gGameSettings.WAD) then Exit;
5308 gWAD := g_Res_SearchSameWAD(MapsDir, ExtractFileName(NewWAD), WHash);
5309 if gWAD = '' then
5310 begin
5311 g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
5312 gWAD := g_Res_DownloadMapWAD(ExtractFileName(NewWAD), WHash);
5313 if gWAD = '' then
5314 begin
5315 g_Game_Free();
5316 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_WAD], [ExtractFileName(NewWAD)]));
5317 Exit;
5318 end;
5319 end;
5320 NewWAD := ExtractRelativePath(MapsDir, gWAD);
5321 g_Game_LoadWAD(NewWAD);
5323 end;
5325 procedure g_Game_RestartRound(NoMapRestart: Boolean = False);
5326 var
5327 i, n, nb, nr: Integer;
5328 begin
5329 if not g_Game_IsServer then Exit;
5330 if gLMSRespawn = LMS_RESPAWN_NONE then Exit;
5331 gLMSRespawn := LMS_RESPAWN_NONE;
5332 gLMSRespawnTime := 0;
5333 MessageTime := 0;
5335 if (gGameSettings.GameMode = GM_COOP) and not NoMapRestart then
5336 begin
5337 gMissionFailed := True;
5338 g_Game_RestartLevel;
5339 Exit;
5340 end;
5342 n := 0; nb := 0; nr := 0;
5343 for i := Low(gPlayers) to High(gPlayers) do
5344 if (gPlayers[i] <> nil) and
5345 ((not gPlayers[i].FSpectator) or gPlayers[i].FWantsInGame or
5346 (gPlayers[i] is TBot)) then
5347 begin
5348 Inc(n);
5349 if gPlayers[i].Team = TEAM_RED then Inc(nr)
5350 else if gPlayers[i].Team = TEAM_BLUE then Inc(nb)
5351 end;
5353 if (n < 1) or ((gGameSettings.GameMode = GM_TDM) and ((nr = 0) or (nb = 0))) then
5354 begin
5355 // wait a second until the fuckers finally decide to join
5356 gLMSRespawn := LMS_RESPAWN_WARMUP;
5357 gLMSRespawnTime := gTime + gGameSettings.WarmupTime*1000;
5358 gLMSSoftSpawn := NoMapRestart;
5359 if g_Game_IsNet then
5360 MH_SEND_GameEvent(NET_EV_LMS_WARMUP, gLMSRespawnTime - gTime);
5361 Exit;
5362 end;
5364 g_Player_RemoveAllCorpses;
5365 g_Game_Message(_lc[I_MESSAGE_LMS_START], 144);
5366 if g_Game_IsNet then
5367 MH_SEND_GameEvent(NET_EV_LMS_START);
5369 for i := Low(gPlayers) to High(gPlayers) do
5370 begin
5371 if gPlayers[i] = nil then continue;
5372 if gPlayers[i] is TBot then gPlayers[i].FWantsInGame := True;
5373 // don't touch normal spectators
5374 if gPlayers[i].FSpectator and not gPlayers[i].FWantsInGame then
5375 begin
5376 gPlayers[i].FNoRespawn := True;
5377 gPlayers[i].Lives := 0;
5378 if g_Game_IsNet then
5379 MH_SEND_PlayerStats(gPlayers[I].UID);
5380 continue;
5381 end;
5382 gPlayers[i].FNoRespawn := False;
5383 gPlayers[i].Lives := gGameSettings.MaxLives;
5384 gPlayers[i].Respawn(False, True);
5385 if gGameSettings.GameMode = GM_COOP then
5386 begin
5387 gPlayers[i].Frags := 0;
5388 gPlayers[i].RecallState;
5389 end;
5390 if (gPlayer1 = nil) and (gSpectLatchPID1 > 0) then
5391 gPlayer1 := g_Player_Get(gSpectLatchPID1);
5392 if (gPlayer2 = nil) and (gSpectLatchPID2 > 0) then
5393 gPlayer2 := g_Player_Get(gSpectLatchPID2);
5394 end;
5396 g_Items_RestartRound();
5398 gLMSSoftSpawn := False;
5399 end;
5401 function g_Game_GetFirstMap(WAD: String): String;
5402 begin
5403 Result := '';
5405 MapList := g_Map_GetMapsList(WAD);
5406 if MapList = nil then
5407 Exit;
5409 SortSArray(MapList);
5410 Result := MapList[Low(MapList)];
5412 if not g_Map_Exist(WAD + ':\' + Result) then
5413 Result := '';
5415 MapList := nil;
5416 end;
5418 function g_Game_GetNextMap(): String;
5419 var
5420 I: Integer;
5421 Map: string;
5422 begin
5423 Result := '';
5425 MapList := g_Map_GetMapsList(gGameSettings.WAD);
5426 if MapList = nil then
5427 Exit;
5429 Map := g_ExtractFileName(gMapInfo.Map);
5431 SortSArray(MapList);
5432 MapIndex := -255;
5433 for I := Low(MapList) to High(MapList) do
5434 if Map = MapList[I] then
5435 begin
5436 MapIndex := I;
5437 Break;
5438 end;
5440 if MapIndex <> -255 then
5441 begin
5442 if MapIndex = High(MapList) then
5443 Result := MapList[Low(MapList)]
5444 else
5445 Result := MapList[MapIndex + 1];
5447 if not g_Map_Exist(gGameSettings.WAD + ':\' + Result) then Result := Map;
5448 end;
5450 MapList := nil;
5451 end;
5453 procedure g_Game_NextLevel();
5454 begin
5455 if gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF, GM_COOP] then
5456 gExit := EXIT_ENDLEVELCUSTOM
5457 else
5458 begin
5459 gExit := EXIT_ENDLEVELSINGLE;
5460 Exit;
5461 end;
5463 if gNextMap <> '' then Exit;
5464 gNextMap := g_Game_GetNextMap();
5465 end;
5467 function g_Game_IsTestMap(): Boolean;
5468 begin
5469 result := StrEquCI1251(TEST_MAP_NAME, g_ExtractFileName(gMapInfo.Map));
5470 end;
5472 procedure g_Game_DeleteTestMap();
5473 var
5474 a: Integer;
5475 //MapName: AnsiString;
5476 WadName: string;
5478 WAD: TWADFile;
5479 MapList: SSArray;
5480 time: Integer;
5482 begin
5483 a := Pos('.wad:\', toLowerCase1251(gMapToDelete));
5484 if (a = 0) then a := Pos('.wad:/', toLowerCase1251(gMapToDelete));
5485 if (a = 0) then exit;
5487 // Âûäåëÿåì èìÿ wad-ôàéëà è èìÿ êàðòû
5488 WadName := Copy(gMapToDelete, 1, a+3);
5489 Delete(gMapToDelete, 1, a+5);
5490 gMapToDelete := UpperCase(gMapToDelete);
5491 //MapName := '';
5492 //CopyMemory(@MapName[0], @gMapToDelete[1], Min(16, Length(gMapToDelete)));
5495 // Èìÿ êàðòû íå ñòàíäàðòíîå òåñòîâîå:
5496 if MapName <> TEST_MAP_NAME then
5497 Exit;
5499 if not gTempDelete then
5500 begin
5501 time := g_GetFileTime(WadName);
5502 WAD := TWADFile.Create();
5504 // ×èòàåì Wad-ôàéë:
5505 if not WAD.ReadFile(WadName) then
5506 begin // Íåò òàêîãî WAD-ôàéëà
5507 WAD.Free();
5508 Exit;
5509 end;
5511 // Ñîñòàâëÿåì ñïèñîê êàðò è èùåì íóæíóþ:
5512 WAD.CreateImage();
5513 MapList := WAD.GetResourcesList('');
5515 if MapList <> nil then
5516 for a := 0 to High(MapList) do
5517 if MapList[a] = MapName then
5518 begin
5519 // Óäàëÿåì è ñîõðàíÿåì:
5520 WAD.RemoveResource('', MapName);
5521 WAD.SaveTo(WadName);
5522 Break;
5523 end;
5525 WAD.Free();
5526 g_SetFileTime(WadName, time);
5527 end else
5529 if gTempDelete then DeleteFile(WadName);
5530 end;
5532 procedure GameCVars(P: SSArray);
5533 var
5534 a, b: Integer;
5535 stat: TPlayerStatArray;
5536 cmd: string;
5537 it: PItem;
5539 procedure ParseGameFlag(Flag: LongWord; OffMsg, OnMsg: TStrings_Locale; OnMapChange: Boolean = False);
5540 var
5541 x: Boolean;
5542 begin
5543 if Length(P) > 1 then
5544 begin
5545 x := P[1] = '1';
5547 if x then
5548 gsGameFlags := gsGameFlags or Flag
5549 else
5550 gsGameFlags := gsGameFlags and (not Flag);
5552 if g_Game_IsServer then
5553 begin
5554 if x then
5555 gGameSettings.Options := gGameSettings.Options or Flag
5556 else
5557 gGameSettings.Options := gGameSettings.Options and (not Flag);
5558 if g_Game_IsNet then MH_SEND_GameSettings;
5559 end;
5560 end;
5562 if LongBool(gsGameFlags and Flag) then
5563 g_Console_Add(_lc[OnMsg])
5564 else
5565 g_Console_Add(_lc[OffMsg]);
5567 if OnMapChange and g_Game_IsServer then
5568 g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
5569 end;
5571 begin
5572 stat := nil;
5573 cmd := LowerCase(P[0]);
5575 if cmd = 'g_gamemode' then
5576 begin
5577 if (Length(P) > 1) then
5578 begin
5579 a := g_Game_TextToMode(P[1]);
5580 if a = GM_SINGLE then a := GM_COOP;
5581 gsGameMode := g_Game_ModeToText(a);
5582 if g_Game_IsServer then
5583 begin
5584 gSwitchGameMode := a;
5585 if (gGameOn and (gGameSettings.GameMode = GM_SINGLE)) or
5586 (gState = STATE_INTERSINGLE) then
5587 gSwitchGameMode := GM_SINGLE;
5588 if not gGameOn then
5589 gGameSettings.GameMode := gSwitchGameMode;
5590 end;
5591 end;
5593 if gSwitchGameMode = gGameSettings.GameMode then
5594 g_Console_Add(Format(_lc[I_MSG_GAMEMODE_CURRENT],
5595 [g_Game_ModeToText(gGameSettings.GameMode)]))
5596 else
5597 g_Console_Add(Format(_lc[I_MSG_GAMEMODE_CHANGE],
5598 [g_Game_ModeToText(gGameSettings.GameMode),
5599 g_Game_ModeToText(gSwitchGameMode)]));
5600 end
5601 else if cmd = 'g_friendlyfire' then
5602 begin
5603 ParseGameFlag(GAME_OPTION_TEAMDAMAGE, I_MSG_FRIENDLY_FIRE_OFF, I_MSG_FRIENDLY_FIRE_ON);
5604 end
5605 else if cmd = 'g_friendly_absorb_damage' then
5606 begin
5607 ParseGameFlag(GAME_OPTION_TEAMABSORBDAMAGE, I_MSG_FRIENDLY_ABSORB_DAMAGE_OFF, I_MSG_FRIENDLY_ABSORB_DAMAGE_ON);
5608 end
5609 else if cmd = 'g_friendly_hit_trace' then
5610 begin
5611 ParseGameFlag(GAME_OPTION_TEAMHITTRACE, I_MSG_FRIENDLY_HIT_TRACE_OFF, I_MSG_FRIENDLY_HIT_TRACE_ON);
5612 end
5613 else if cmd = 'g_friendly_hit_projectile' then
5614 begin
5615 ParseGameFlag(GAME_OPTION_TEAMHITPROJECTILE, I_MSG_FRIENDLY_PROJECT_TRACE_OFF, I_MSG_FRIENDLY_PROJECT_TRACE_ON);
5616 end
5617 else if cmd = 'g_powerup_randomize_respawn' then
5618 begin
5619 ParseGameFlag(GAME_OPTION_RULEZRANDOM, I_MSG_RULEZ_RANDOM_OFF, I_MSG_RULEZ_RANDOM_ON);
5620 end
5621 else if cmd = 'g_weaponstay' then
5622 begin
5623 ParseGameFlag(GAME_OPTION_WEAPONSTAY, I_MSG_WEAPONSTAY_OFF, I_MSG_WEAPONSTAY_ON);
5624 end
5625 else if cmd = 'g_allow_exit' then
5626 begin
5627 ParseGameFlag(GAME_OPTION_ALLOWEXIT, I_MSG_ALLOWEXIT_OFF, I_MSG_ALLOWEXIT_ON, True);
5628 end
5629 else if cmd = 'g_allow_monsters' then
5630 begin
5631 ParseGameFlag(GAME_OPTION_MONSTERS, I_MSG_ALLOWMON_OFF, I_MSG_ALLOWMON_ON, True);
5632 end
5633 else if cmd = 'g_allow_dropflag' then
5634 begin
5635 ParseGameFlag(GAME_OPTION_ALLOWDROPFLAG, I_MSG_ALLOWDROPFLAG_OFF, I_MSG_ALLOWDROPFLAG_ON);
5636 end
5637 else if cmd = 'g_throw_flag' then
5638 begin
5639 ParseGameFlag(GAME_OPTION_THROWFLAG, I_MSG_THROWFLAG_OFF, I_MSG_THROWFLAG_ON);
5640 end
5641 else if cmd = 'g_bot_vsplayers' then
5642 begin
5643 ParseGameFlag(GAME_OPTION_BOTVSPLAYER, I_MSG_BOTSVSPLAYERS_OFF, I_MSG_BOTSVSPLAYERS_ON);
5644 end
5645 else if cmd = 'g_bot_vsmonsters' then
5646 begin
5647 ParseGameFlag(GAME_OPTION_BOTVSMONSTER, I_MSG_BOTSVSMONSTERS_OFF, I_MSG_BOTSVSMONSTERS_ON);
5648 end
5649 else if cmd = 'g_dm_keys' then
5650 begin
5651 ParseGameFlag(GAME_OPTION_DMKEYS, I_MSG_DMKEYS_OFF, I_MSG_DMKEYS_ON, True);
5652 end
5653 else if cmd = 'g_gameflags' then
5654 begin
5655 if Length(P) > 1 then
5656 begin
5657 gsGameFlags := StrToDWordDef(P[1], gsGameFlags);
5658 if g_Game_IsServer then
5659 begin
5660 gGameSettings.Options := gsGameFlags;
5661 if g_Game_IsNet then MH_SEND_GameSettings;
5662 end;
5663 end;
5665 g_Console_Add(Format('%s %u', [cmd, gsGameFlags]));
5666 end
5667 else if cmd = 'g_warmup_time' then
5668 begin
5669 if Length(P) > 1 then
5670 begin
5671 gsWarmupTime := nclamp(StrToIntDef(P[1], gsWarmupTime), 0, $FFFF);
5672 if g_Game_IsServer then
5673 begin
5674 gGameSettings.WarmupTime := gsWarmupTime;
5675 // extend warmup if it's already going
5676 if gLMSRespawn = LMS_RESPAWN_WARMUP then
5677 begin
5678 gLMSRespawnTime := gTime + gsWarmupTime * 1000;
5679 if g_Game_IsNet then MH_SEND_GameEvent(NET_EV_LMS_WARMUP, gLMSRespawnTime - gTime);
5680 end;
5681 if g_Game_IsNet then MH_SEND_GameSettings;
5682 end;
5683 end;
5685 g_Console_Add(Format(_lc[I_MSG_WARMUP], [Integer(gsWarmupTime)]));
5686 if g_Game_IsServer then g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
5687 end
5688 else if cmd = 'g_spawn_invul' then
5689 begin
5690 if Length(P) > 1 then
5691 begin
5692 gsSpawnInvul := nclamp(StrToIntDef(P[1], gsSpawnInvul), 0, $FFFF);
5693 if g_Game_IsServer then
5694 begin
5695 gGameSettings.SpawnInvul := gsSpawnInvul;
5696 if g_Game_IsNet then MH_SEND_GameSettings;
5697 end;
5698 end;
5700 g_Console_Add(Format('%s %d', [cmd, Integer(gsSpawnInvul)]));
5701 end
5702 else if cmd = 'g_item_respawn_time' then
5703 begin
5704 if Length(P) > 1 then
5705 begin
5706 gsItemRespawnTime := nclamp(StrToIntDef(P[1], gsItemRespawnTime), 0, $FFFF);
5707 if g_Game_IsServer then
5708 begin
5709 gGameSettings.ItemRespawnTime := gsItemRespawnTime;
5710 if g_Game_IsNet then MH_SEND_GameSettings;
5711 end;
5712 end;
5714 g_Console_Add(Format('%s %d', [cmd, Integer(gsItemRespawnTime)]));
5715 if g_Game_IsServer then g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
5716 end
5717 else if cmd = 'g_powerup_time_multiplier' then
5718 begin
5719 if Length(P) > 1 then
5720 begin
5721 gsRulezTimeMultiplier := nclamp(StrToIntDef(P[1], gsRulezTimeMultiplier), 0, $FFFF);
5722 if g_Game_IsServer then
5723 begin
5724 gGameSettings.RulezTimeMultiplier := gsRulezTimeMultiplier;
5725 if g_Game_IsNet then MH_SEND_GameSettings;
5726 end;
5727 end;
5729 g_Console_Add(Format('%s %d', [cmd, Integer(gsRulezTimeMultiplier)]));
5730 if g_Game_IsServer then g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
5731 end
5732 else if cmd = 'sv_intertime' then
5733 begin
5734 if (Length(P) > 1) then
5735 gDefInterTime := Min(Max(StrToIntDef(P[1], gDefInterTime), -1), 120);
5737 g_Console_Add(cmd + ' = ' + IntToStr(gDefInterTime));
5738 end
5739 else if cmd = 'g_max_particles' then
5740 begin
5741 if Length(p) = 2 then
5742 begin
5743 a := Max(0, StrToIntDef(p[1], 0));
5744 g_GFX_SetMax(a)
5745 end
5746 else if Length(p) = 1 then
5747 begin
5748 e_LogWritefln('%s', [g_GFX_GetMax()])
5749 end
5750 else
5751 begin
5752 e_LogWritefln('usage: %s <n>', [cmd])
5753 end
5754 end
5755 else if cmd = 'g_max_shells' then
5756 begin
5757 if Length(p) = 2 then
5758 begin
5759 a := Max(0, StrToIntDef(p[1], 0));
5760 g_Shells_SetMax(a)
5761 end
5762 else if Length(p) = 1 then
5763 begin
5764 e_LogWritefln('%s', [g_Shells_GetMax()])
5765 end
5766 else
5767 begin
5768 e_LogWritefln('usage: %s <n>', [cmd])
5769 end
5770 end
5771 else if cmd = 'g_max_gibs' then
5772 begin
5773 if Length(p) = 2 then
5774 begin
5775 a := Max(0, StrToIntDef(p[1], 0));
5776 g_Gibs_SetMax(a)
5777 end
5778 else if Length(p) = 1 then
5779 begin
5780 e_LogWritefln('%s', [g_Gibs_GetMax()])
5781 end
5782 else
5783 begin
5784 e_LogWritefln('usage: %s <n>', [cmd])
5785 end
5786 end
5787 else if cmd = 'g_max_corpses' then
5788 begin
5789 if Length(p) = 2 then
5790 begin
5791 a := Max(0, StrToIntDef(p[1], 0));
5792 g_Corpses_SetMax(a)
5793 end
5794 else if Length(p) = 1 then
5795 begin
5796 e_LogWritefln('%s', [g_Corpses_GetMax()])
5797 end
5798 else
5799 begin
5800 e_LogWritefln('usage: %s <n>', [cmd])
5801 end
5802 end
5803 else if cmd = 'g_force_model' then
5804 begin
5805 if Length(p) = 2 then
5806 begin
5807 a := StrToIntDef(p[1], 0);
5808 g_Force_Model_Set(a);
5809 if (g_Force_Model_Get() <> 0) and (gPlayers <> nil) then
5810 begin
5811 for a := Low(gPlayers) to High(gPlayers) do
5812 begin
5813 if (gPlayers[a] <> nil) then
5814 begin
5815 if (gPlayers[a].UID = gPlayer1.UID) then
5816 continue
5817 else if (gPlayer2 <> nil) and (gPlayers[a].UID = gPlayer2.UID) then
5818 continue;
5819 gPlayers[a].setModel(g_Forced_Model_GetName());
5820 end;
5821 end
5822 end
5823 else if (g_Force_Model_Get() = 0) and (gPlayers <> nil) then
5824 begin
5825 for a := Low(gPlayers) to High(gPlayers) do
5826 begin
5827 if (gPlayers[a] <> nil) then
5828 begin
5829 if (gPlayers[a].UID = gPlayer1.UID) then
5830 continue
5831 else if (gPlayer2 <> nil) and (gPlayers[a].UID = gPlayer2.UID) then
5832 continue;
5833 gPlayers[a].setModel(gPlayers[a].FActualModelName);
5834 end;
5835 end
5836 end
5837 end
5838 end
5839 else if cmd = 'g_force_model_name' then
5840 begin
5841 if (Length(P) > 1) then
5842 begin
5843 cmd := b_Text_Unformat(P[1]);
5844 g_Forced_Model_SetName(cmd);
5845 if (g_Force_Model_Get() <> 0) and (gPlayers <> nil) then
5846 begin
5847 for a := Low(gPlayers) to High(gPlayers) do
5848 begin
5849 if (gPlayers[a] <> nil) then
5850 begin
5851 if (gPlayers[a].UID = gPlayer1.UID) then
5852 continue
5853 else if (gPlayer2 <> nil) and (gPlayers[a].UID = gPlayer2.UID) then
5854 continue;
5855 gPlayers[a].setModel(g_Forced_Model_GetName());
5856 end;
5857 end
5858 end
5859 end
5860 end
5861 else if cmd = 'g_scorelimit' then
5862 begin
5863 if Length(P) > 1 then
5864 begin
5865 gsScoreLimit := nclamp(StrToIntDef(P[1], gsScoreLimit), 0, $FFFF);
5867 if g_Game_IsServer then
5868 begin
5869 b := 0;
5870 if gGameSettings.GameMode = GM_DM then
5871 begin // DM
5872 stat := g_Player_GetStats();
5873 if stat <> nil then
5874 for a := 0 to High(stat) do
5875 if stat[a].Frags > b then
5876 b := stat[a].Frags;
5877 end
5878 else // TDM/CTF
5879 b := Max(gTeamStat[TEAM_RED].Score, gTeamStat[TEAM_BLUE].Score);
5881 // if someone has a higher score, set it to that instead
5882 gsScoreLimit := max(gsScoreLimit, b);
5883 gGameSettings.ScoreLimit := gsScoreLimit;
5885 if g_Game_IsNet then MH_SEND_GameSettings;
5886 end;
5887 end;
5889 g_Console_Add(Format(_lc[I_MSG_SCORE_LIMIT], [Integer(gsScoreLimit)]));
5890 end
5891 else if cmd = 'g_timelimit' then
5892 begin
5893 if Length(P) > 1 then
5894 begin
5895 gsTimeLimit := nclamp(StrToIntDef(P[1], gsTimeLimit), 0, $FFFF);
5896 if g_Game_IsServer then
5897 begin
5898 gGameSettings.TimeLimit := gsTimeLimit;
5899 if g_Game_IsNet then MH_SEND_GameSettings;
5900 end;
5901 end;
5902 g_Console_Add(Format(_lc[I_MSG_TIME_LIMIT],
5903 [gsTimeLimit div 3600,
5904 (gsTimeLimit div 60) mod 60,
5905 gsTimeLimit mod 60]));
5906 end
5907 else if cmd = 'g_max_bots' then
5908 begin
5909 if Length(P) > 1 then
5910 gMaxBots := nclamp(StrToIntDef(P[1], gMaxBots), 0, 127);
5911 g_Console_Add('g_max_bots = ' + IntToStr(gMaxBots));
5912 end
5913 else if cmd = 'g_maxlives' then
5914 begin
5915 if Length(P) > 1 then
5916 begin
5917 gsMaxLives := nclamp(StrToIntDef(P[1], gsMaxLives), 0, $FFFF);
5918 if g_Game_IsServer then
5919 begin
5920 gGameSettings.MaxLives := gsMaxLives;
5921 if g_Game_IsNet then MH_SEND_GameSettings;
5922 end;
5923 end;
5925 g_Console_Add(Format(_lc[I_MSG_LIVES], [Integer(gsMaxLives)]));
5926 end;
5927 end;
5929 procedure PlayerSettingsCVars(P: SSArray);
5930 var
5931 cmd: string;
5932 team: Byte;
5934 function ParseTeam(s: string): Byte;
5935 begin
5936 result := 0;
5937 case s of
5938 'red', '1': result := TEAM_RED;
5939 'blue', '2': result := TEAM_BLUE;
5940 else result := TEAM_NONE;
5941 end;
5942 end;
5943 begin
5944 cmd := LowerCase(P[0]);
5945 case cmd of
5946 'p1_name':
5947 begin
5948 if (Length(P) > 1) then
5949 begin
5950 gPlayer1Settings.Name := b_Text_Unformat(P[1]);
5951 if g_Game_IsClient then
5952 MC_SEND_PlayerSettings
5953 else if gGameOn and (gPlayer1 <> nil) then
5954 begin
5955 gPlayer1.Name := b_Text_Unformat(P[1]);
5956 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer1.UID);
5957 end;
5958 end;
5959 end;
5960 'p2_name':
5961 begin
5962 if (Length(P) > 1) then
5963 begin
5964 gPlayer2Settings.Name := b_Text_Unformat(P[1]);
5965 if g_Game_IsClient then
5966 MC_SEND_PlayerSettings
5967 else if gGameOn and (gPlayer2 <> nil) then
5968 begin
5969 gPlayer2.Name := b_Text_Unformat(P[1]);
5970 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer2.UID);
5971 end;
5972 end;
5973 end;
5974 'p1_color':
5975 begin
5976 if Length(P) > 3 then
5977 begin
5978 gPlayer1Settings.Color := _RGB(EnsureRange(StrToIntDef(P[1], 0), 0, 255),
5979 EnsureRange(StrToIntDef(P[2], 0), 0, 255),
5980 EnsureRange(StrToIntDef(P[3], 0), 0, 255));
5981 if g_Game_IsClient then
5982 MC_SEND_PlayerSettings
5983 else if gGameOn and (gPlayer1 <> nil) then
5984 begin
5985 gPlayer1.SetColor(gPlayer1Settings.Color);
5986 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer1.UID);
5987 end;
5988 end;
5989 end;
5990 'p2_color':
5991 begin
5992 if Length(P) > 3 then
5993 begin
5994 gPlayer2Settings.Color := _RGB(EnsureRange(StrToIntDef(P[1], 0), 0, 255),
5995 EnsureRange(StrToIntDef(P[2], 0), 0, 255),
5996 EnsureRange(StrToIntDef(P[3], 0), 0, 255));
5997 if g_Game_IsClient then
5998 MC_SEND_PlayerSettings
5999 else if gGameOn and (gPlayer2 <> nil) then
6000 begin
6001 gPlayer2.SetColor(gPlayer2Settings.Color);
6002 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer2.UID);
6003 end;
6004 end;
6005 end;
6006 'p1_model':
6007 begin
6008 if (Length(P) > 1) then
6009 begin
6010 gPlayer1Settings.Model := P[1];
6011 if g_Game_IsClient then
6012 MC_SEND_PlayerSettings
6013 else if gGameOn and (gPlayer1 <> nil) then
6014 begin
6015 gPlayer1.FActualModelName := gPlayer1Settings.Model;
6016 gPlayer1.SetModel(gPlayer1Settings.Model);
6017 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer1.UID);
6018 end;
6019 end;
6020 end;
6021 'p2_model':
6022 begin
6023 if (Length(P) > 1) then
6024 begin
6025 gPlayer2Settings.Model := P[1];
6026 if g_Game_IsClient then
6027 MC_SEND_PlayerSettings
6028 else if gGameOn and (gPlayer2 <> nil) then
6029 begin
6030 gPlayer2.FActualModelName := gPlayer2Settings.Model;
6031 gPlayer2.SetModel(gPlayer2Settings.Model);
6032 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer2.UID);
6033 end;
6034 end;
6035 end;
6036 'p1_team':
6037 begin
6038 // TODO: switch teams if in game or store this separately
6039 if (Length(P) > 1) then
6040 begin
6041 team := ParseTeam(P[1]);
6042 if team = TEAM_NONE then
6043 g_Console_Add('expected ''red'', ''blue'', 1 or 2')
6044 else if not gGameOn and not g_Game_IsNet then
6045 gPlayer1Settings.Team := team
6046 else
6047 g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
6048 end;
6049 end;
6050 'p2_team':
6051 begin
6052 // TODO: switch teams if in game or store this separately
6053 if (Length(P) > 1) then
6054 begin
6055 team := ParseTeam(P[1]);
6056 if team = TEAM_NONE then
6057 g_Console_Add('expected ''red'', ''blue'', 1 or 2')
6058 else if not gGameOn and not g_Game_IsNet then
6059 gPlayer2Settings.Team := team
6060 else
6061 g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
6062 end;
6063 end;
6064 'p1_autoswitch':
6065 begin
6066 if (Length(P) = 2) then
6067 gPlayer1Settings.WeaponSwitch := EnsureRange(StrTointDef(P[1], 0), 0, 2);
6068 end;
6069 'p2_autoswitch':
6070 begin
6071 if (Length(P) = 2) then
6072 gPlayer2Settings.WeaponSwitch := EnsureRange(StrTointDef(P[1], 0), 0, 2);
6073 end;
6074 'p1_switch_empty':
6075 begin
6076 if (Length(P) = 2) then
6077 gPlayer1Settings.SwitchToEmpty := EnsureRange(StrTointDef(P[1], 0), 0, 1);
6078 end;
6079 'p2_switch_empty':
6080 begin
6081 if (Length(P) = 2) then
6082 gPlayer2Settings.SwitchToEmpty := EnsureRange(StrTointDef(P[1], 0), 0, 1);
6083 end;
6084 'p1_skip_fist':
6085 begin
6086 if (Length(P) = 2) then
6087 gPlayer1Settings.SkipFist := EnsureRange(StrTointDef(P[1], 0), 0, 1);
6088 end;
6089 'p2_skip_fist':
6090 begin
6091 if (Length(P) = 2) then
6092 gPlayer2Settings.SkipFist := EnsureRange(StrTointDef(P[1], 0), 0, 1);
6093 end;
6094 'p1_priority_kastet':
6095 begin
6096 if (Length(P) = 2) then
6097 gPlayer1Settings.WeaponPreferences[WEAPON_KASTET] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6098 end;
6099 'p2_priority_kastet':
6100 begin
6101 if (Length(P) = 2) then
6102 gPlayer2Settings.WeaponPreferences[WEAPON_KASTET] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6103 end;
6104 'p1_priority_saw':
6105 begin
6106 if (Length(P) = 2) then
6107 gPlayer1Settings.WeaponPreferences[WEAPON_SAW] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6108 end;
6109 'p2_priority_saw':
6110 begin
6111 if (Length(P) = 2) then
6112 gPlayer2Settings.WeaponPreferences[WEAPON_SAW] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6113 end;
6114 'p1_priority_pistol':
6115 begin
6116 if (Length(P) = 2) then
6117 gPlayer1Settings.WeaponPreferences[WEAPON_KASTET] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6118 end;
6119 'p2_priority_pistol':
6120 begin
6121 if (Length(P) = 2) then
6122 gPlayer2Settings.WeaponPreferences[WEAPON_KASTET] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6123 end;
6124 'p1_priority_shotgun1':
6125 begin
6126 if (Length(P) = 2) then
6127 gPlayer1Settings.WeaponPreferences[WEAPON_SHOTGUN1] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6128 end;
6129 'p2_priority_shotgun1':
6130 begin
6131 if (Length(P) = 2) then
6132 gPlayer2Settings.WeaponPreferences[WEAPON_SHOTGUN1] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6133 end;
6134 'p1_priority_shotgun2':
6135 begin
6136 if (Length(P) = 2) then
6137 gPlayer1Settings.WeaponPreferences[WEAPON_SHOTGUN2] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6138 end;
6139 'p2_priority_shotgun2':
6140 begin
6141 if (Length(P) = 2) then
6142 gPlayer2Settings.WeaponPreferences[WEAPON_SHOTGUN2] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6143 end;
6144 'p1_priority_chaingun':
6145 begin
6146 if (Length(P) = 2) then
6147 gPlayer1Settings.WeaponPreferences[WEAPON_CHAINGUN] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6148 end;
6149 'p2_priority_chaingun':
6150 begin
6151 if (Length(P) = 2) then
6152 gPlayer2Settings.WeaponPreferences[WEAPON_CHAINGUN] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6153 end;
6154 'p1_priority_rocketlauncher':
6155 begin
6156 if (Length(P) = 2) then
6157 gPlayer1Settings.WeaponPreferences[WEAPON_ROCKETLAUNCHER] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6158 end;
6159 'p2_priority_rocketlauncher':
6160 begin
6161 if (Length(P) = 2) then
6162 gPlayer2Settings.WeaponPreferences[WEAPON_ROCKETLAUNCHER] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6163 end;
6164 'p1_priority_plasma':
6165 begin
6166 if (Length(P) = 2) then
6167 gPlayer1Settings.WeaponPreferences[WEAPON_PLASMA] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6168 end;
6169 'p2_priority_plasma':
6170 begin
6171 if (Length(P) = 2) then
6172 gPlayer2Settings.WeaponPreferences[WEAPON_PLASMA] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6173 end;
6174 'p1_priority_bfg':
6175 begin
6176 if (Length(P) = 2) then
6177 gPlayer1Settings.WeaponPreferences[WEAPON_BFG] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6178 end;
6179 'p2_priority_bfg':
6180 begin
6181 if (Length(P) = 2) then
6182 gPlayer2Settings.WeaponPreferences[WEAPON_BFG] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6183 end;
6184 'p1_priority_super':
6185 begin
6186 if (Length(P) = 2) then
6187 gPlayer1Settings.WeaponPreferences[WEAPON_SUPERPULEMET] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6188 end;
6189 'p2_priority_super':
6190 begin
6191 if (Length(P) = 2) then
6192 gPlayer2Settings.WeaponPreferences[WEAPON_SUPERPULEMET] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6193 end;
6194 'p1_priority_flamethrower':
6195 begin
6196 if (Length(P) = 2) then
6197 gPlayer1Settings.WeaponPreferences[WEAPON_FLAMETHROWER] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6198 end;
6199 'p2_priority_flamethrower':
6200 begin
6201 if (Length(P) = 2) then
6202 gPlayer2Settings.WeaponPreferences[WEAPON_FLAMETHROWER] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6203 end;
6204 'p1_priority_berserk':
6205 begin
6206 if (Length(P) = 2) then
6207 gPlayer1Settings.WeaponPreferences[WP_LAST+1] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6208 end;
6209 'p2_priority_berserk':
6210 begin
6211 if (Length(P) = 2) then
6212 gPlayer2Settings.WeaponPreferences[WP_LAST+1] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6213 end;
6214 end;
6215 end;
6217 procedure PrintHeapStats();
6218 var
6219 hs: TFPCHeapStatus;
6220 begin
6221 hs := GetFPCHeapStatus();
6222 e_LogWriteLn ('v===== heap status =====v');
6223 e_LogWriteFln('max heap size = %d k', [hs.MaxHeapSize div 1024]);
6224 e_LogWriteFln('max heap used = %d k', [hs.MaxHeapUsed div 1024]);
6225 e_LogWriteFln('cur heap size = %d k', [hs.CurrHeapSize div 1024]);
6226 e_LogWriteFln('cur heap used = %d k', [hs.CurrHeapUsed div 1024]);
6227 e_LogWriteFln('cur heap free = %d k', [hs.CurrHeapFree div 1024]);
6228 e_LogWriteLn ('^=======================^');
6229 end;
6231 procedure DebugCommands(P: SSArray);
6232 var
6233 a, b: Integer;
6234 cmd: string;
6235 //pt: TDFPoint;
6236 mon: TMonster;
6237 begin
6238 // Êîìàíäû îòëàäî÷íîãî ðåæèìà:
6239 if {gDebugMode}conIsCheatsEnabled then
6240 begin
6241 cmd := LowerCase(P[0]);
6242 if cmd = 'd_window' then
6243 begin
6244 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth, gScreenHeight]));
6245 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth, gScreenHeight]));
6246 end
6247 else if cmd = 'd_sounds' then
6248 begin
6249 if (Length(P) > 1) and
6250 ((P[1] = '1') or (P[1] = '0')) then
6251 g_Debug_Sounds := (P[1][1] = '1');
6253 g_Console_Add(Format('d_sounds is %d', [Byte(g_Debug_Sounds)]));
6254 end
6255 else if cmd = 'd_frames' then
6256 begin
6257 if (Length(P) > 1) and
6258 ((P[1] = '1') or (P[1] = '0')) then
6259 g_Debug_Frames := (P[1][1] = '1');
6261 g_Console_Add(Format('d_frames is %d', [Byte(g_Debug_Frames)]));
6262 end
6263 else if cmd = 'd_winmsg' then
6264 begin
6265 if (Length(P) > 1) and
6266 ((P[1] = '1') or (P[1] = '0')) then
6267 g_Debug_WinMsgs := (P[1][1] = '1');
6269 g_Console_Add(Format('d_winmsg is %d', [Byte(g_Debug_WinMsgs)]));
6270 end
6271 else if (cmd = 'd_monoff') and not g_Game_IsNet then
6272 begin
6273 if (Length(P) > 1) and
6274 ((P[1] = '1') or (P[1] = '0')) then
6275 g_Debug_MonsterOff := (P[1][1] = '1');
6277 g_Console_Add(Format('d_monoff is %d', [Byte(g_debug_MonsterOff)]));
6278 end
6279 else if (cmd = 'd_botoff') and not g_Game_IsNet then
6280 begin
6281 if Length(P) > 1 then
6282 case P[1][1] of
6283 '0': g_debug_BotAIOff := 0;
6284 '1': g_debug_BotAIOff := 1;
6285 '2': g_debug_BotAIOff := 2;
6286 '3': g_debug_BotAIOff := 3;
6287 end;
6289 g_Console_Add(Format('d_botoff is %d', [g_debug_BotAIOff]));
6290 end
6291 else if cmd = 'd_monster' then
6292 begin
6293 if gGameOn and (gPlayer1 <> nil) and (gPlayer1.alive) and (not g_Game_IsNet) then
6294 if Length(P) < 2 then
6295 begin
6296 g_Console_Add(cmd + ' [ID | Name] [behaviour]');
6297 g_Console_Add('ID | Name');
6298 for b := MONSTER_DEMON to MONSTER_MAN do
6299 g_Console_Add(Format('%2d | %s', [b, g_Mons_NameByTypeId(b)]));
6300 conwriteln('behav. num'#10'normal 0'#10'killer 1'#10'maniac 2'#10'insane 3'#10'cannibal 4'#10'good 5');
6301 end else
6302 begin
6303 a := StrToIntDef(P[1], 0);
6304 if (a < MONSTER_DEMON) or (a > MONSTER_MAN) then
6305 a := g_Mons_TypeIdByName(P[1]);
6307 if (a < MONSTER_DEMON) or (a > MONSTER_MAN) then
6308 g_Console_Add(Format(_lc[I_MSG_NO_MONSTER], [P[1]]))
6309 else
6310 begin
6311 with gPlayer1.Obj do
6312 begin
6313 mon := g_Monsters_Create(a,
6314 X + Rect.X + (Rect.Width div 2),
6315 Y + Rect.Y + Rect.Height,
6316 gPlayer1.Direction, True);
6317 end;
6318 if (Length(P) > 2) and (mon <> nil) then
6319 begin
6320 if (CompareText(P[2], 'normal') = 0) then mon.MonsterBehaviour := BH_NORMAL
6321 else if (CompareText(P[2], 'killer') = 0) then mon.MonsterBehaviour := BH_KILLER
6322 else if (CompareText(P[2], 'maniac') = 0) then mon.MonsterBehaviour := BH_MANIAC
6323 else if (CompareText(P[2], 'insane') = 0) then mon.MonsterBehaviour := BH_INSANE
6324 else if (CompareText(P[2], 'cannibal') = 0) then mon.MonsterBehaviour := BH_CANNIBAL
6325 else if (CompareText(P[2], 'good') = 0) then mon.MonsterBehaviour := BH_GOOD
6326 else if (CompareText(P[2], 'friend') = 0) then mon.MonsterBehaviour := BH_GOOD
6327 else if (CompareText(P[2], 'friendly') = 0) then mon.MonsterBehaviour := BH_GOOD
6328 else mon.MonsterBehaviour := Min(Max(StrToIntDef(P[2], BH_NORMAL), BH_NORMAL), BH_GOOD);
6329 end;
6330 end;
6331 end;
6332 end
6333 else if (cmd = 'd_health') then
6334 begin
6335 if (Length(P) > 1) and
6336 ((P[1] = '1') or (P[1] = '0')) then
6337 g_debug_HealthBar := (P[1][1] = '1');
6339 g_Console_Add(Format('d_health is %d', [Byte(g_debug_HealthBar)]));
6340 end
6341 else if (cmd = 'd_player') then
6342 begin
6343 if (Length(P) > 1) and
6344 ((P[1] = '1') or (P[1] = '0')) then
6345 g_debug_Player := (P[1][1] = '1');
6347 g_Console_Add(Format(cmd + ' is %d', [Byte(g_Debug_Player)]));
6348 end
6349 else if (cmd = 'd_mem') then
6350 begin
6351 PrintHeapStats();
6352 end;
6353 end
6354 else
6355 g_Console_Add(_lc[I_MSG_NOT_DEBUG]);
6356 end;
6359 procedure GameCheats(P: SSArray);
6360 var
6361 cmd: string;
6362 f, a: Integer;
6363 plr: TPlayer;
6364 begin
6365 if (not gGameOn) or (not conIsCheatsEnabled) then
6366 begin
6367 g_Console_Add('not available');
6368 exit;
6369 end;
6370 plr := gPlayer1;
6371 if plr = nil then
6372 begin
6373 g_Console_Add('where is the player?!');
6374 exit;
6375 end;
6376 cmd := LowerCase(P[0]);
6377 // god
6378 if cmd = 'god' then
6379 begin
6380 plr.GodMode := not plr.GodMode;
6381 if plr.GodMode then g_Console_Add('player is godlike now') else g_Console_Add('player is mortal now');
6382 exit;
6383 end;
6384 // give <health|exit|weapons|air|suit|jetpack|berserk|all>
6385 if cmd = 'give' then
6386 begin
6387 if length(P) < 2 then begin g_Console_Add('give what?!'); exit; end;
6388 for f := 1 to High(P) do
6389 begin
6390 cmd := LowerCase(P[f]);
6391 if cmd = 'health' then begin plr.RestoreHealthArmor(); g_Console_Add('player feels himself better'); continue; end;
6392 if (cmd = 'all') {or (cmd = 'weapons')} then begin plr.AllRulez(False); g_Console_Add('player got the gifts'); continue; end;
6393 if cmd = 'exit' then
6394 begin
6395 if gTriggers <> nil then
6396 begin
6397 for a := 0 to High(gTriggers) do
6398 begin
6399 if gTriggers[a].TriggerType = TRIGGER_EXIT then
6400 begin
6401 g_Console_Add('player left the map');
6402 gExitByTrigger := True;
6403 //g_Game_ExitLevel(gTriggers[a].Data.MapName);
6404 g_Game_ExitLevel(gTriggers[a].tgcMap);
6405 break;
6406 end;
6407 end;
6408 end;
6409 continue;
6410 end;
6412 if cmd = 'air' then begin plr.GiveItem(ITEM_OXYGEN); g_Console_Add('player got some air'); continue; end;
6413 if cmd = 'jetpack' then begin plr.GiveItem(ITEM_JETPACK); g_Console_Add('player got a jetpack'); continue; end;
6414 if cmd = 'suit' then begin plr.GiveItem(ITEM_SUIT); g_Console_Add('player got an envirosuit'); continue; end;
6415 if cmd = 'berserk' then begin plr.GiveItem(ITEM_MEDKIT_BLACK); g_Console_Add('player got a berserk pack'); continue; end;
6416 if cmd = 'backpack' then begin plr.GiveItem(ITEM_AMMO_BACKPACK); g_Console_Add('player got a backpack'); continue; end;
6418 if cmd = 'helmet' then begin plr.GiveItem(ITEM_HELMET); g_Console_Add('player got a helmet'); continue; end;
6419 if cmd = 'bottle' then begin plr.GiveItem(ITEM_BOTTLE); g_Console_Add('player got a bottle of health'); continue; end;
6421 if cmd = 'stimpack' then begin plr.GiveItem(ITEM_MEDKIT_SMALL); g_Console_Add('player got a stimpack'); continue; end;
6422 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;
6424 if cmd = 'greenarmor' then begin plr.GiveItem(ITEM_ARMOR_GREEN); g_Console_Add('player got a security armor'); continue; end;
6425 if cmd = 'bluearmor' then begin plr.GiveItem(ITEM_ARMOR_BLUE); g_Console_Add('player got a combat armor'); continue; end;
6427 if (cmd = 'megasphere') or (cmd = 'mega') then begin plr.GiveItem(ITEM_SPHERE_BLUE); g_Console_Add('player got a megasphere'); continue; end;
6428 if (cmd = 'soulsphere') or (cmd = 'soul')then begin plr.GiveItem(ITEM_SPHERE_WHITE); g_Console_Add('player got a soul sphere'); continue; end;
6430 if (cmd = 'invul') or (cmd = 'invulnerability') then begin plr.GiveItem(ITEM_INVUL); g_Console_Add('player got invulnerability'); continue; end;
6431 if (cmd = 'invis') or (cmd = 'invisibility') then begin plr.GiveItem(ITEM_INVIS); g_Console_Add('player got invisibility'); continue; end;
6433 if cmd = 'redkey' then begin plr.GiveItem(ITEM_KEY_RED); g_Console_Add('player got the red key'); continue; end;
6434 if cmd = 'greenkey' then begin plr.GiveItem(ITEM_KEY_GREEN); g_Console_Add('player got the green key'); continue; end;
6435 if cmd = 'bluekey' then begin plr.GiveItem(ITEM_KEY_BLUE); g_Console_Add('player got the blue key'); continue; end;
6437 if (cmd = 'shotgun') or (cmd = 'sg') then begin plr.GiveItem(ITEM_WEAPON_SHOTGUN1); g_Console_Add('player got a shotgun'); continue; end;
6438 if (cmd = 'supershotgun') or (cmd = 'ssg') then begin plr.GiveItem(ITEM_WEAPON_SHOTGUN2); g_Console_Add('player got a supershotgun'); continue; end;
6439 if cmd = 'chaingun' then begin plr.GiveItem(ITEM_WEAPON_CHAINGUN); g_Console_Add('player got a chaingun'); continue; end;
6440 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;
6441 if cmd = 'plasmagun' then begin plr.GiveItem(ITEM_WEAPON_PLASMA); g_Console_Add('player got a plasma gun'); continue; end;
6442 if cmd = 'bfg' then begin plr.GiveItem(ITEM_WEAPON_BFG); g_Console_Add('player got a BFG-9000'); continue; end;
6444 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;
6445 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;
6446 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;
6447 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;
6448 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;
6449 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;
6451 if cmd = 'superchaingun' then begin plr.GiveItem(ITEM_WEAPON_SUPERPULEMET); g_Console_Add('player got a superchaingun'); continue; end;
6452 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;
6454 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;
6455 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;
6457 if cmd = 'chainsaw' then begin plr.GiveItem(ITEM_WEAPON_SAW); g_Console_Add('player got a chainsaw'); continue; end;
6459 if cmd = 'ammo' then
6460 begin
6461 plr.GiveItem(ITEM_AMMO_SHELLS_BOX);
6462 plr.GiveItem(ITEM_AMMO_BULLETS_BOX);
6463 plr.GiveItem(ITEM_AMMO_CELL_BIG);
6464 plr.GiveItem(ITEM_AMMO_ROCKET_BOX);
6465 plr.GiveItem(ITEM_AMMO_FUELCAN);
6466 g_Console_Add('player got some ammo');
6467 continue;
6468 end;
6470 if cmd = 'clip' then begin plr.GiveItem(ITEM_AMMO_BULLETS); g_Console_Add('player got some bullets'); continue; end;
6471 if cmd = 'bullets' then begin plr.GiveItem(ITEM_AMMO_BULLETS_BOX); g_Console_Add('player got a box of bullets'); continue; end;
6473 if cmd = 'shells' then begin plr.GiveItem(ITEM_AMMO_SHELLS); g_Console_Add('player got some shells'); continue; end;
6474 if cmd = 'shellbox' then begin plr.GiveItem(ITEM_AMMO_SHELLS_BOX); g_Console_Add('player got a box of shells'); continue; end;
6476 if cmd = 'cells' then begin plr.GiveItem(ITEM_AMMO_CELL); g_Console_Add('player got some cells'); continue; end;
6477 if cmd = 'battery' then begin plr.GiveItem(ITEM_AMMO_CELL_BIG); g_Console_Add('player got cell battery'); continue; end;
6479 if cmd = 'rocket' then begin plr.GiveItem(ITEM_AMMO_ROCKET); g_Console_Add('player got a rocket'); continue; end;
6480 if cmd = 'rocketbox' then begin plr.GiveItem(ITEM_AMMO_ROCKET_BOX); g_Console_Add('player got some rockets'); continue; end;
6482 if (cmd = 'fuel') or (cmd = 'fuelcan') then begin plr.GiveItem(ITEM_AMMO_FUELCAN); g_Console_Add('player got fuel canister'); continue; end;
6484 if cmd = 'weapons' then
6485 begin
6486 plr.GiveItem(ITEM_WEAPON_SHOTGUN1);
6487 plr.GiveItem(ITEM_WEAPON_SHOTGUN2);
6488 plr.GiveItem(ITEM_WEAPON_CHAINGUN);
6489 plr.GiveItem(ITEM_WEAPON_ROCKETLAUNCHER);
6490 plr.GiveItem(ITEM_WEAPON_PLASMA);
6491 plr.GiveItem(ITEM_WEAPON_BFG);
6492 g_Console_Add('player got weapons');
6493 continue;
6494 end;
6496 if cmd = 'keys' then
6497 begin
6498 plr.GiveItem(ITEM_KEY_RED);
6499 plr.GiveItem(ITEM_KEY_GREEN);
6500 plr.GiveItem(ITEM_KEY_BLUE);
6501 g_Console_Add('player got all keys');
6502 continue;
6503 end;
6505 g_Console_Add('i don''t know how to give '''+cmd+'''!');
6506 end;
6507 exit;
6508 end;
6509 // open
6510 if cmd = 'open' then
6511 begin
6512 g_Console_Add('player activated sesame');
6513 g_Triggers_OpenAll();
6514 exit;
6515 end;
6516 // fly
6517 if cmd = 'fly' then
6518 begin
6519 gFly := not gFly;
6520 if gFly then g_Console_Add('player feels himself lighter') else g_Console_Add('player lost his wings');
6521 exit;
6522 end;
6523 // noclip
6524 if cmd = 'noclip' then
6525 begin
6526 plr.SwitchNoClip;
6527 g_Console_Add('wall hardeness adjusted');
6528 exit;
6529 end;
6530 // notarget
6531 if cmd = 'notarget' then
6532 begin
6533 plr.NoTarget := not plr.NoTarget;
6534 if plr.NoTarget then g_Console_Add('player hides in shadows') else g_Console_Add('player is brave again');
6535 exit;
6536 end;
6537 // noreload
6538 if cmd = 'noreload' then
6539 begin
6540 plr.NoReload := not plr.NoReload;
6541 if plr.NoReload then g_Console_Add('player is action hero now') else g_Console_Add('player is ordinary man now');
6542 exit;
6543 end;
6544 // speedy
6545 if cmd = 'speedy' then
6546 begin
6547 MAX_RUNVEL := 32-MAX_RUNVEL;
6548 g_Console_Add('speed adjusted');
6549 exit;
6550 end;
6551 // jumpy
6552 if cmd = 'jumpy' then
6553 begin
6554 VEL_JUMP := 30-VEL_JUMP;
6555 g_Console_Add('jump height adjusted');
6556 exit;
6557 end;
6558 // automap
6559 if cmd = 'automap' then
6560 begin
6561 gShowMap := not gShowMap;
6562 if gShowMap then g_Console_Add('player gains second sight') else g_Console_Add('player lost second sight');
6563 exit;
6564 end;
6565 // aimline
6566 if cmd = 'aimline' then
6567 begin
6568 gAimLine := not gAimLine;
6569 if gAimLine then g_Console_Add('player gains laser sight') else g_Console_Add('player lost laser sight');
6570 exit;
6571 end;
6572 end;
6574 procedure GameCommands(P: SSArray);
6575 var
6576 a, b: Integer;
6577 s, pw: String;
6578 chstr: string;
6579 cmd: string;
6580 pl: pTNetClient = nil;
6581 plr: TPlayer;
6582 prt: Word;
6583 nm: Boolean;
6584 listen: LongWord;
6585 found: Boolean;
6586 t: Byte;
6587 begin
6588 // Îáùèå êîìàíäû:
6589 cmd := LowerCase(P[0]);
6590 chstr := '';
6591 if cmd = 'pause' then
6592 begin
6593 if (g_ActiveWindow = nil) then
6594 g_Game_Pause(not gPauseMain);
6595 end
6596 else if cmd = 'endgame' then
6597 gExit := EXIT_SIMPLE
6598 else if cmd = 'restart' then
6599 begin
6600 if gGameOn or (gState in [STATE_INTERSINGLE, STATE_INTERCUSTOM]) then
6601 begin
6602 if g_Game_IsClient then
6603 begin
6604 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6605 Exit;
6606 end;
6607 g_Game_Restart();
6608 end else
6609 g_Console_Add(_lc[I_MSG_NOT_GAME]);
6610 end
6611 else if cmd = 'kick' then
6612 begin
6613 if g_Game_IsServer then
6614 begin
6615 if Length(P) < 2 then
6616 begin
6617 g_Console_Add('kick <name>');
6618 Exit;
6619 end;
6620 if P[1] = '' then
6621 begin
6622 g_Console_Add('kick <name>');
6623 Exit;
6624 end;
6626 if g_Game_IsNet then
6627 pl := g_Net_Client_ByName(P[1]);
6628 if (pl <> nil) then
6629 begin
6630 s := g_Net_ClientName_ByID(pl^.ID);
6631 g_Net_Host_Kick(pl^.ID, NET_DISC_KICK);
6632 g_Console_Add(Format(_lc[I_PLAYER_KICK], [s]));
6633 MH_SEND_GameEvent(NET_EV_PLAYER_KICK, 0, s);
6634 g_Net_Slist_ServerPlayerLeaves();
6635 end else if gPlayers <> nil then
6636 for a := Low(gPlayers) to High(gPlayers) do
6637 if gPlayers[a] <> nil then
6638 if Copy(LowerCase(gPlayers[a].Name), 1, Length(P[1])) = LowerCase(P[1]) then
6639 begin
6640 // Íå îòêëþ÷àòü îñíîâíûõ èãðîêîâ â ñèíãëå
6641 if not(gPlayers[a] is TBot) and (gGameSettings.GameType = GT_SINGLE) then
6642 continue;
6643 gPlayers[a].Lives := 0;
6644 gPlayers[a].Kill(K_SIMPLEKILL, 0, HIT_DISCON);
6645 g_Console_Add(Format(_lc[I_PLAYER_LEAVE], [gPlayers[a].Name]), True);
6646 g_Player_Remove(gPlayers[a].UID);
6647 g_Net_Slist_ServerPlayerLeaves();
6648 // Åñëè íå ïåðåìåøàòü, ïðè äîáàâëåíèè íîâûõ áîòîâ ïîÿâÿòñÿ ñòàðûå
6649 g_Bot_MixNames();
6650 end;
6651 end else
6652 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
6653 end
6654 else if cmd = 'kick_id' then
6655 begin
6656 if g_Game_IsServer and g_Game_IsNet then
6657 begin
6658 if Length(P) < 2 then
6659 begin
6660 g_Console_Add('kick_id <client ID>');
6661 Exit;
6662 end;
6663 if P[1] = '' then
6664 begin
6665 g_Console_Add('kick_id <client ID>');
6666 Exit;
6667 end;
6669 a := StrToIntDef(P[1], 0);
6670 if (NetClients <> nil) and (a <= High(NetClients)) then
6671 begin
6672 if NetClients[a].Used and (NetClients[a].Peer <> nil) then
6673 begin
6674 s := g_Net_ClientName_ByID(NetClients[a].ID);
6675 g_Net_Host_Kick(NetClients[a].ID, NET_DISC_KICK);
6676 g_Console_Add(Format(_lc[I_PLAYER_KICK], [s]));
6677 MH_SEND_GameEvent(NET_EV_PLAYER_KICK, 0, s);
6678 g_Net_Slist_ServerPlayerLeaves();
6679 end;
6680 end;
6681 end else
6682 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6683 end
6684 else if cmd = 'kick_pid' then
6685 begin
6686 if g_Game_IsServer and g_Game_IsNet then
6687 begin
6688 if Length(P) < 2 then
6689 begin
6690 g_Console_Add('kick_pid <player ID>');
6691 Exit;
6692 end;
6693 if P[1] = '' then
6694 begin
6695 g_Console_Add('kick_pid <player ID>');
6696 Exit;
6697 end;
6699 a := StrToIntDef(P[1], 0);
6700 pl := g_Net_Client_ByPlayer(a);
6701 if (pl <> nil) and pl^.Used and (pl^.Peer <> nil) then
6702 begin
6703 s := g_Net_ClientName_ByID(pl^.ID);
6704 g_Net_Host_Kick(pl^.ID, NET_DISC_KICK);
6705 g_Console_Add(Format(_lc[I_PLAYER_KICK], [s]));
6706 MH_SEND_GameEvent(NET_EV_PLAYER_KICK, 0, s);
6707 g_Net_Slist_ServerPlayerLeaves();
6708 end;
6709 end else
6710 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6711 end
6712 else if cmd = 'ban' then
6713 begin
6714 if g_Game_IsServer and g_Game_IsNet then
6715 begin
6716 if Length(P) < 2 then
6717 begin
6718 g_Console_Add('ban <name>');
6719 Exit;
6720 end;
6721 if P[1] = '' then
6722 begin
6723 g_Console_Add('ban <name>');
6724 Exit;
6725 end;
6727 pl := g_Net_Client_ByName(P[1]);
6728 if (pl <> nil) then
6729 g_Net_Host_Ban(pl, False)
6730 else
6731 g_Console_Add(Format(_lc[I_NET_ERR_NAME404], [P[1]]));
6732 end else
6733 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6734 end
6735 else if cmd = 'ban_id' then
6736 begin
6737 if g_Game_IsServer and g_Game_IsNet then
6738 begin
6739 if Length(P) < 2 then
6740 begin
6741 g_Console_Add('ban_id <client ID>');
6742 Exit;
6743 end;
6744 if P[1] = '' then
6745 begin
6746 g_Console_Add('ban_id <client ID>');
6747 Exit;
6748 end;
6750 a := StrToIntDef(P[1], 0);
6751 if (NetClients <> nil) and (a <= High(NetClients)) then
6752 if NetClients[a].Used and (NetClients[a].Peer <> nil) then
6753 g_Net_Host_Ban(pl, False);
6754 end else
6755 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6756 end
6757 else if cmd = 'ban_pid' then
6758 begin
6759 if g_Game_IsServer and g_Game_IsNet then
6760 begin
6761 if Length(P) < 2 then
6762 begin
6763 g_Console_Add('ban_pid <player ID>');
6764 Exit;
6765 end;
6766 if P[1] = '' then
6767 begin
6768 g_Console_Add('ban_pid <player ID>');
6769 Exit;
6770 end;
6772 a := StrToIntDef(P[1], 0);
6773 pl := g_Net_Client_ByPlayer(a);
6774 if (pl <> nil) and pl^.Used and (pl^.Peer <> nil) then
6775 g_Net_Host_Ban(pl, False);
6776 end else
6777 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6778 end
6779 else if cmd = 'permban' then
6780 begin
6781 if g_Game_IsServer and g_Game_IsNet then
6782 begin
6783 if Length(P) < 2 then
6784 begin
6785 g_Console_Add('permban <name>');
6786 Exit;
6787 end;
6788 if P[1] = '' then
6789 begin
6790 g_Console_Add('permban <name>');
6791 Exit;
6792 end;
6794 pl := g_Net_Client_ByName(P[1]);
6795 if (pl <> nil) then
6796 g_Net_Host_Ban(pl, True)
6797 else
6798 g_Console_Add(Format(_lc[I_NET_ERR_NAME404], [P[1]]));
6799 end else
6800 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6801 end
6802 else if cmd = 'permban_id' then
6803 begin
6804 if g_Game_IsServer and g_Game_IsNet then
6805 begin
6806 if Length(P) < 2 then
6807 begin
6808 g_Console_Add('permban_id <client ID>');
6809 Exit;
6810 end;
6811 if P[1] = '' then
6812 begin
6813 g_Console_Add('permban_id <client ID>');
6814 Exit;
6815 end;
6817 a := StrToIntDef(P[1], 0);
6818 if (NetClients <> nil) and (a <= High(NetClients)) then
6819 if NetClients[a].Used and (NetClients[a].Peer <> nil) then
6820 g_Net_Host_Ban(@NetClients[a], True);
6821 end else
6822 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6823 end
6824 else if cmd = 'permban_pid' then
6825 begin
6826 if g_Game_IsServer and g_Game_IsNet then
6827 begin
6828 if Length(P) < 2 then
6829 begin
6830 g_Console_Add('permban_pid <player ID>');
6831 Exit;
6832 end;
6833 if P[1] = '' then
6834 begin
6835 g_Console_Add('permban_pid <player ID>');
6836 Exit;
6837 end;
6839 a := StrToIntDef(P[1], 0);
6840 pl := g_Net_Client_ByPlayer(a);
6841 if (pl <> nil) and pl^.Used and (pl^.Peer <> nil) then
6842 g_Net_Host_Ban(pl, True);
6843 end else
6844 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6845 end
6846 else if cmd = 'permban_ip' then
6847 begin
6848 if g_Game_IsServer and g_Game_IsNet then
6849 begin
6850 if Length(P) < 2 then
6851 begin
6852 g_Console_Add('permban_ip <IP address>');
6853 Exit;
6854 end;
6855 if P[1] = '' then
6856 begin
6857 g_Console_Add('permban_ip <IP address>');
6858 Exit;
6859 end;
6861 g_Net_BanAddress(P[1]);
6862 g_Net_SaveBanList();
6863 g_Console_Add(Format(_lc[I_PLAYER_BAN], [P[1]]));
6864 end else
6865 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6866 end
6867 else if cmd = 'unban' then
6868 begin
6869 if g_Game_IsServer and g_Game_IsNet then
6870 begin
6871 if Length(P) < 2 then
6872 begin
6873 g_Console_Add('unban <IP Address>');
6874 Exit;
6875 end;
6876 if P[1] = '' then
6877 begin
6878 g_Console_Add('unban <IP Address>');
6879 Exit;
6880 end;
6882 if g_Net_UnbanAddress(P[1]) then
6883 begin
6884 g_Console_Add(Format(_lc[I_MSG_UNBAN_OK], [P[1]]));
6885 g_Net_SaveBanList();
6886 end else
6887 g_Console_Add(Format(_lc[I_MSG_UNBAN_FAIL], [P[1]]));
6888 end else
6889 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6890 end
6891 else if cmd = 'clientlist' then
6892 begin
6893 if g_Game_IsServer and g_Game_IsNet then
6894 begin
6895 b := 0;
6896 if NetClients <> nil then
6897 for a := Low(NetClients) to High(NetClients) do
6898 if NetClients[a].Used and (NetClients[a].Peer <> nil) then
6899 begin
6900 plr := g_Player_Get(NetClients[a].Player);
6901 if plr = nil then continue;
6902 Inc(b);
6903 g_Console_Add(Format('#%2d: %-15s | %s', [a,
6904 IpToStr(NetClients[a].Peer^.address.host), plr.Name]));
6905 end;
6906 if b = 0 then
6907 g_Console_Add(_lc[I_MSG_NOCLIENTS]);
6908 end else
6909 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6910 end
6911 else if cmd = 'connect' then
6912 begin
6913 if (NetMode = NET_NONE) then
6914 begin
6915 if Length(P) < 2 then
6916 begin
6917 g_Console_Add('connect <IP> [port] [password]');
6918 Exit;
6919 end;
6920 if P[1] = '' then
6921 begin
6922 g_Console_Add('connect <IP> [port] [password]');
6923 Exit;
6924 end;
6926 if Length(P) > 2 then
6927 prt := StrToIntDef(P[2], 25666)
6928 else
6929 prt := 25666;
6931 if Length(P) > 3 then
6932 pw := P[3]
6933 else
6934 pw := '';
6936 g_Game_StartClient(P[1], prt, pw);
6937 end;
6938 end
6939 else if cmd = 'disconnect' then
6940 begin
6941 if (NetMode = NET_CLIENT) then
6942 g_Net_Disconnect();
6943 end
6944 else if cmd = 'reconnect' then
6945 begin
6946 if (NetMode = NET_SERVER) then
6947 Exit;
6949 if (NetMode = NET_CLIENT) then
6950 begin
6951 g_Net_Disconnect();
6952 gExit := EXIT_SIMPLE;
6953 EndGame;
6954 end;
6956 //TODO: Use last successful password to reconnect, instead of ''
6957 g_Game_StartClient(NetClientIP, NetClientPort, '');
6958 end
6959 else if (cmd = 'addbot') or
6960 (cmd = 'bot_add') then
6961 begin
6962 case Length(P) of
6963 1: g_Bot_Add(TEAM_NONE, 2);
6964 2: g_Bot_Add(TEAM_NONE, StrToIntDef(P[1], 2));
6965 else
6966 g_Bot_Add(TEAM_NONE, StrToIntDef(P[1], 2), StrToIntDef(P[2], 100));
6967 end;
6968 end
6969 else if cmd = 'bot_addlist' then
6970 begin
6971 case Length(P) of
6972 1: g_Bot_AddList(TEAM_NONE, '');
6973 2: g_Bot_AddList(TEAM_NONE, P[1], StrToIntDef(P[1], -1));
6974 else
6975 if P[2] = 'red' then
6976 t := TEAM_RED
6977 else if P[2] = 'blue' then
6978 t := TEAM_BLUE
6979 else
6980 t := TEAM_NONE;
6982 if Length(P) = 3
6983 then g_Bot_AddList(t, P[1], StrToIntDef(P[1], -1))
6984 else g_Bot_AddList(t, P[1], StrToIntDef(P[1], -1), StrToIntDef(P[3], 100));
6985 end;
6986 end
6987 else if cmd = 'bot_removeall' then
6988 g_Bot_RemoveAll()
6989 else if cmd = 'chat' then
6990 begin
6991 if g_Game_IsNet then
6992 begin
6993 if Length(P) > 1 then
6994 begin
6995 for a := 1 to High(P) do
6996 chstr := chstr + P[a] + ' ';
6998 if Length(chstr) > 200 then SetLength(chstr, 200);
7000 if Length(chstr) < 1 then
7001 begin
7002 g_Console_Add('chat <text>');
7003 Exit;
7004 end;
7006 chstr := b_Text_Format(chstr);
7007 if g_Game_IsClient then
7008 MC_SEND_Chat(chstr, NET_CHAT_PLAYER)
7009 else
7010 MH_SEND_Chat(gPlayer1Settings.Name + ': ' + chstr, NET_CHAT_PLAYER);
7011 end
7012 else
7013 g_Console_Add('chat <text>');
7014 end else
7015 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
7016 end
7017 else if cmd = 'teamchat' then
7018 begin
7019 if g_Game_IsNet and (gGameSettings.GameMode in [GM_TDM, GM_CTF]) then
7020 begin
7021 if Length(P) > 1 then
7022 begin
7023 for a := 1 to High(P) do
7024 chstr := chstr + P[a] + ' ';
7026 if Length(chstr) > 200 then SetLength(chstr, 200);
7028 if Length(chstr) < 1 then
7029 begin
7030 g_Console_Add('teamchat <text>');
7031 Exit;
7032 end;
7034 chstr := b_Text_Format(chstr);
7035 if g_Game_IsClient then
7036 MC_SEND_Chat(chstr, NET_CHAT_TEAM)
7037 else
7038 MH_SEND_Chat(gPlayer1Settings.Name + ': ' + chstr, NET_CHAT_TEAM,
7039 gPlayer1Settings.Team);
7040 end
7041 else
7042 g_Console_Add('teamchat <text>');
7043 end else
7044 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
7045 end
7046 else if (cmd = 'an') or (cmd = 'announce') then
7047 begin
7048 if g_Game_IsNet then
7049 begin
7050 if Length(P) > 1 then
7051 begin
7052 for a := 1 to High(P) do
7053 chstr := chstr + P[a] + ' ';
7055 if Length(chstr) > 200 then SetLength(chstr, 200);
7057 if Length(chstr) < 1 then
7058 begin
7059 g_Console_Add('announce <text>');
7060 Exit;
7061 end;
7063 chstr := 'centerprint 100 ' + b_Text_Format(chstr);
7064 if g_Game_IsClient then
7065 MC_SEND_RCONCommand(chstr)
7066 else
7067 g_Console_Process(chstr, True);
7068 end
7069 else
7070 g_Console_Add('announce <text>');
7071 end else
7072 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
7073 end
7074 else if cmd = 'game' then
7075 begin
7076 if gGameSettings.GameType <> GT_NONE then
7077 begin
7078 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
7079 Exit;
7080 end;
7081 if Length(P) = 1 then
7082 begin
7083 g_Console_Add(cmd + ' <WAD> [MAP] [# players]');
7084 Exit;
7085 end;
7086 // game not started yet, load fist map from some wad
7087 found := false;
7088 s := addWadExtension(P[1]);
7089 found := e_FindResource(AllMapDirs, s);
7090 P[1] := s;
7091 if found then
7092 begin
7093 P[1] := ExpandFileName(P[1]);
7094 // if map not choosed then set first map
7095 if Length(P) < 3 then
7096 begin
7097 SetLength(P, 3);
7098 P[2] := g_Game_GetFirstMap(P[1]);
7099 end;
7101 s := P[1] + ':\' + UpperCase(P[2]);
7103 if g_Map_Exist(s) then
7104 begin
7105 // start game
7106 g_Game_Free();
7107 with gGameSettings do
7108 begin
7109 Options := gsGameFlags;
7110 GameMode := g_Game_TextToMode(gsGameMode);
7111 if gSwitchGameMode <> GM_NONE then
7112 GameMode := gSwitchGameMode;
7113 if GameMode = GM_NONE then GameMode := GM_DM;
7114 if GameMode = GM_SINGLE then GameMode := GM_COOP;
7115 b := 1;
7116 if Length(P) >= 4 then
7117 b := StrToIntDef(P[3], 1);
7118 g_Game_StartCustom(s, GameMode, TimeLimit,
7119 ScoreLimit, MaxLives, Options, b);
7120 end;
7121 end
7122 else
7123 if P[2] = '' then
7124 g_Console_Add(Format(_lc[I_MSG_NO_MAPS], [P[1]]))
7125 else
7126 g_Console_Add(Format(_lc[I_MSG_NO_MAP_FALLBACK], [UpperCase(P[2]), P[1]]));
7127 end else
7128 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]));
7129 end
7130 else if cmd = 'host' then
7131 begin
7132 if gGameSettings.GameType <> GT_NONE then
7133 begin
7134 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
7135 Exit;
7136 end;
7137 if Length(P) < 4 then
7138 begin
7139 g_Console_Add(cmd + ' <listen IP> <port> <WAD> [MAP] [# players]');
7140 Exit;
7141 end;
7142 if not StrToIp(P[1], listen) then
7143 Exit;
7144 prt := StrToIntDef(P[2], 25666);
7146 s := addWadExtension(P[3]);
7147 found := e_FindResource(AllMapDirs, s);
7148 P[3] := s;
7149 if found then
7150 begin
7151 // get first map in wad, if not specified
7152 if Length(P) < 5 then
7153 begin
7154 SetLength(P, 5);
7155 P[4] := g_Game_GetFirstMap(P[1]);
7156 end;
7157 s := P[3] + ':\' + UpperCase(P[4]);
7158 if g_Map_Exist(s) then
7159 begin
7160 // start game
7161 g_Game_Free();
7162 with gGameSettings do
7163 begin
7164 Options := gsGameFlags;
7165 GameMode := g_Game_TextToMode(gsGameMode);
7166 if gSwitchGameMode <> GM_NONE then GameMode := gSwitchGameMode;
7167 if GameMode = GM_NONE then GameMode := GM_DM;
7168 if GameMode = GM_SINGLE then GameMode := GM_COOP;
7169 b := 0;
7170 if Length(P) >= 6 then
7171 b := StrToIntDef(P[5], 0);
7172 g_Game_StartServer(s, GameMode, TimeLimit, ScoreLimit, MaxLives, Options, b, listen, prt)
7173 end
7174 end
7175 else
7176 begin
7177 if P[4] = '' then
7178 g_Console_Add(Format(_lc[I_MSG_NO_MAPS], [P[3]]))
7179 else
7180 g_Console_Add(Format(_lc[I_MSG_NO_MAP_FALLBACK], [UpperCase(P[4]), P[3]]))
7181 end
7182 end
7183 else
7184 begin
7185 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[3]]))
7186 end
7187 end
7188 else if cmd = 'map' then
7189 begin
7190 if Length(P) = 1 then
7191 begin
7192 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
7193 begin
7194 g_Console_Add(cmd + ' <MAP>');
7195 g_Console_Add(cmd + ' <WAD> [MAP]')
7196 end
7197 else
7198 begin
7199 g_Console_Add(_lc[I_MSG_GM_UNAVAIL])
7200 end
7201 end
7202 else if not e_IsValidResourceName(P[1]) then
7203 begin
7204 g_Console_Add('wad name must not be absolute or relative');
7205 end
7206 else
7207 begin
7208 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
7209 begin
7210 if Length(P) < 3 then
7211 begin
7212 // first param is map or wad
7213 s := UpperCase(P[1]);
7214 if g_Map_Exist(gGameSettings.WAD + ':\' + s) then
7215 begin
7216 gExitByTrigger := False;
7217 if gGameOn then
7218 begin
7219 // already in game, finish current map
7220 gNextMap := s;
7221 gExit := EXIT_ENDLEVELCUSTOM;
7222 end
7223 else
7224 begin
7225 // intermission, so change map immediately
7226 g_Game_ChangeMap(s)
7227 end
7228 end
7229 else
7230 begin
7231 s := P[1];
7232 found := e_FindResource(AllMapDirs, s);
7233 P[1] := s;
7234 g_Console_Add(Format(_lc[I_MSG_NO_MAP_FALLBACK], [s, 'WAD ' + P[1]]));
7235 if found then
7236 begin
7237 // no such map, found wad
7238 pw := P[1];
7239 SetLength(P, 3);
7240 P[1] := ExpandFileName(pw);
7241 P[2] := g_Game_GetFirstMap(P[1]);
7242 s := P[1] + ':\' + P[2];
7243 if g_Map_Exist(s) then
7244 begin
7245 gExitByTrigger := False;
7246 if gGameOn then
7247 begin
7248 // already in game, finish current map
7249 gNextMap := s;
7250 gExit := EXIT_ENDLEVELCUSTOM
7251 end
7252 else
7253 begin
7254 // intermission, so change map immediately
7255 g_Game_ChangeMap(s)
7256 end
7257 end
7258 else
7259 begin
7260 if P[2] = '' then
7261 g_Console_Add(Format(_lc[I_MSG_NO_MAPS], [P[1]]))
7262 else
7263 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [P[2]]))
7264 end
7265 end
7266 else
7267 begin
7268 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]))
7269 end
7270 end;
7271 end
7272 else
7273 begin
7274 s := addWadExtension(P[1]);
7275 found := e_FindResource(AllMapDirs, s);
7276 P[1] := s;
7277 if found then
7278 begin
7279 P[2] := UpperCase(P[2]);
7280 s := P[1] + ':\' + P[2];
7281 if g_Map_Exist(s) then
7282 begin
7283 gExitByTrigger := False;
7284 if gGameOn then
7285 begin
7286 gNextMap := s;
7287 gExit := EXIT_ENDLEVELCUSTOM
7288 end
7289 else
7290 begin
7291 g_Game_ChangeMap(s)
7292 end
7293 end
7294 else
7295 begin
7296 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [P[2]]))
7297 end
7298 end
7299 else
7300 begin
7301 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]))
7302 end
7303 end
7304 end
7305 else
7306 begin
7307 g_Console_Add(_lc[I_MSG_GM_UNAVAIL])
7308 end
7309 end
7310 end
7311 else if cmd = 'nextmap' then
7312 begin
7313 if not(gGameOn or (gState = STATE_INTERCUSTOM)) then
7314 begin
7315 g_Console_Add(_lc[I_MSG_NOT_GAME])
7316 end
7317 else
7318 begin
7319 nm := True;
7320 if Length(P) = 1 then
7321 begin
7322 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
7323 begin
7324 g_Console_Add(cmd + ' <MAP>');
7325 g_Console_Add(cmd + ' <WAD> [MAP]');
7326 end
7327 else
7328 begin
7329 nm := False;
7330 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
7331 end;
7332 end
7333 else if not e_IsValidResourceName(P[1]) then
7334 begin
7335 g_Console_Add('wad name must not be absolute or relative');
7336 end
7337 else
7338 begin
7339 nm := False;
7340 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
7341 begin
7342 if Length(P) < 3 then
7343 begin
7344 // first param is map or wad
7345 s := UpperCase(P[1]);
7346 if g_Map_Exist(gGameSettings.WAD + ':\' + s) then
7347 begin
7348 // map founded
7349 gExitByTrigger := False;
7350 gNextMap := s;
7351 nm := True;
7352 end
7353 else
7354 begin
7355 // no such map, found wad
7356 pw := addWadExtension(P[1]);
7357 found := e_FindResource(MapDirs, pw);
7358 if not found then
7359 found := e_FindResource(WadDirs, pw);
7360 P[1] := pw;
7361 g_Console_Add(Format(_lc[I_MSG_NO_MAP_FALLBACK], [s, P[1]]));
7362 if found then
7363 begin
7364 // map not specified, select first map
7365 SetLength(P, 3);
7366 P[2] := g_Game_GetFirstMap(P[1]);
7367 s := P[1] + ':\' + P[2];
7368 if g_Map_Exist(s) then
7369 begin
7370 gExitByTrigger := False;
7371 gNextMap := s;
7372 nm := True
7373 end
7374 else
7375 begin
7376 if P[2] = '' then
7377 g_Console_Add(Format(_lc[I_MSG_NO_MAPS], [P[1]]))
7378 else
7379 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [P[2]]))
7380 end
7381 end
7382 else
7383 begin
7384 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]))
7385 end
7386 end
7387 end
7388 else
7389 begin
7390 // specified two params wad + map
7391 pw := addWadExtension(P[1]);
7392 found := e_FindResource(MapDirs, pw);
7393 if not found then
7394 found := e_FindResource(MapDirs, pw);
7395 P[1] := pw;
7396 if found then
7397 begin
7398 P[2] := UpperCase(P[2]);
7399 s := P[1] + ':\' + P[2];
7400 if g_Map_Exist(s) then
7401 begin
7402 gExitByTrigger := False;
7403 gNextMap := s;
7404 nm := True
7405 end
7406 else
7407 begin
7408 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [P[2]]))
7409 end
7410 end
7411 else
7412 begin
7413 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]))
7414 end
7415 end
7416 end
7417 else
7418 begin
7419 g_Console_Add(_lc[I_MSG_GM_UNAVAIL])
7420 end
7421 end;
7422 if nm then
7423 begin
7424 if gNextMap = '' then
7425 g_Console_Add(_lc[I_MSG_NEXTMAP_UNSET])
7426 else
7427 g_Console_Add(Format(_lc[I_MSG_NEXTMAP_SET], [gNextMap]))
7428 end
7429 end
7430 end
7431 else if (cmd = 'endmap') or (cmd = 'goodbye') then
7432 begin
7433 if not gGameOn then
7434 begin
7435 g_Console_Add(_lc[I_MSG_NOT_GAME])
7436 end
7437 else
7438 begin
7439 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
7440 begin
7441 gExitByTrigger := False;
7442 // next map not specified, try to find trigger EXIT
7443 if (gNextMap = '') and (gTriggers <> nil) then
7444 begin
7445 for a := 0 to High(gTriggers) do
7446 begin
7447 if gTriggers[a].TriggerType = TRIGGER_EXIT then
7448 begin
7449 gExitByTrigger := True;
7450 //gNextMap := gTriggers[a].Data.MapName;
7451 gNextMap := gTriggers[a].tgcMap;
7452 Break
7453 end
7454 end
7455 end;
7456 if gNextMap = '' then
7457 gNextMap := g_Game_GetNextMap();
7458 if not isWadPath(gNextMap) then
7459 s := gGameSettings.WAD + ':\' + gNextMap
7460 else
7461 s := gNextMap;
7462 if g_Map_Exist(s) then
7463 gExit := EXIT_ENDLEVELCUSTOM
7464 else
7465 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [gNextMap]))
7466 end
7467 else
7468 begin
7469 g_Console_Add(_lc[I_MSG_GM_UNAVAIL])
7470 end
7471 end
7472 end
7473 else if (cmd = 'event') then
7474 begin
7475 if (Length(P) <= 1) then
7476 begin
7477 for a := 0 to High(gEvents) do
7478 if gEvents[a].Command = '' then
7479 g_Console_Add(gEvents[a].Name + ' <none>')
7480 else
7481 g_Console_Add(gEvents[a].Name + ' "' + gEvents[a].Command + '"');
7482 Exit;
7483 end;
7484 if (Length(P) = 2) then
7485 begin
7486 for a := 0 to High(gEvents) do
7487 if gEvents[a].Name = P[1] then
7488 if gEvents[a].Command = '' then
7489 g_Console_Add(gEvents[a].Name + ' <none>')
7490 else
7491 g_Console_Add(gEvents[a].Name + ' "' + gEvents[a].Command + '"');
7492 Exit;
7493 end;
7494 for a := 0 to High(gEvents) do
7495 if gEvents[a].Name = P[1] then
7496 begin
7497 gEvents[a].Command := '';
7498 for b := 2 to High(P) do
7499 if Pos(' ', P[b]) = 0 then
7500 gEvents[a].Command := gEvents[a].Command + ' ' + P[b]
7501 else
7502 gEvents[a].Command := gEvents[a].Command + ' "' + P[b] + '"';
7503 gEvents[a].Command := Trim(gEvents[a].Command);
7504 Exit;
7505 end;
7506 end
7507 else if cmd = 'suicide' then
7508 begin
7509 if gGameOn then
7510 begin
7511 if g_Game_IsClient then
7512 MC_SEND_CheatRequest(NET_CHEAT_SUICIDE)
7513 else
7514 begin
7515 if gPlayer1 <> nil then
7516 gPlayer1.Damage(SUICIDE_DAMAGE, gPlayer1.UID, 0, 0, HIT_SELF);
7517 if gPlayer2 <> nil then
7518 gPlayer2.Damage(SUICIDE_DAMAGE, gPlayer2.UID, 0, 0, HIT_SELF);
7519 end;
7520 end;
7521 end
7522 else if cmd = 'screenshot' then
7523 begin
7524 g_TakeScreenShot()
7525 end
7526 else if (cmd = 'weapnext') or (cmd = 'weapprev') then
7527 begin
7528 a := 1 - (ord(cmd[5]) - ord('n'));
7529 if a = -1 then
7530 gWeaponAction[0, WP_PREV] := True;
7531 if a = 1 then
7532 gWeaponAction[0, WP_NEXT] := True;
7533 end
7534 else if cmd = 'weapon' then
7535 begin
7536 if Length(p) = 2 then
7537 begin
7538 a := WP_FIRST + StrToIntDef(p[1], 0) - 1;
7539 if (a >= WP_FIRST) and (a <= WP_LAST) then
7540 gSelectWeapon[0, a] := True
7541 end
7542 end
7543 else if (cmd = 'p1_weapnext') or (cmd = 'p1_weapprev')
7544 or (cmd = 'p2_weapnext') or (cmd = 'p2_weapprev') then
7545 begin
7546 a := 1 - (ord(cmd[8]) - ord('n'));
7547 b := ord(cmd[2]) - ord('1');
7548 if a = -1 then
7549 gWeaponAction[b, WP_PREV] := True;
7550 if a = 1 then
7551 gWeaponAction[b, WP_NEXT] := True;
7552 end
7553 else if (cmd = 'p1_weapon') or (cmd = 'p2_weapon') then
7554 begin
7555 if Length(p) = 2 then
7556 begin
7557 a := WP_FIRST + StrToIntDef(p[1], 0) - 1;
7558 b := ord(cmd[2]) - ord('1');
7559 if (a >= WP_FIRST) and (a <= WP_LAST) then
7560 gSelectWeapon[b, a] := True
7561 end
7562 end
7563 else if (cmd = 'p1_weapbest') or (cmd = 'p2_weapbest') then
7564 begin
7565 b := ord(cmd[2]) - ord('1');
7566 if b = 0 then
7567 gSelectWeapon[b, gPlayer1.GetMorePrefered()] := True
7568 else
7569 gSelectWeapon[b, gPlayer2.GetMorePrefered()] := True;
7570 end
7571 else if (cmd = 'dropflag') then
7572 begin
7573 if g_Game_IsServer then
7574 begin
7575 if gPlayer2 <> nil then gPlayer2.TryDropFlag();
7576 if gPlayer1 <> nil then gPlayer1.TryDropFlag();
7577 end
7578 else
7579 MC_SEND_CheatRequest(NET_CHEAT_DROPFLAG);
7580 end
7581 else if (cmd = 'p1_dropflag') or (cmd = 'p2_dropflag') then
7582 begin
7583 b := ord(cmd[2]) - ord('1');
7584 if g_Game_IsServer then
7585 begin
7586 if (b = 1) and (gPlayer2 <> nil) then gPlayer2.TryDropFlag()
7587 else if (b = 0) and (gPlayer1 <> nil) then gPlayer1.TryDropFlag();
7588 end
7589 else
7590 MC_SEND_CheatRequest(NET_CHEAT_DROPFLAG);
7591 end
7592 // Êîìàíäû Ñâîåé èãðû:
7593 else if gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT] then
7594 begin
7595 if cmd = 'bot_addred' then
7596 begin
7597 if Length(P) > 1 then
7598 g_Bot_Add(TEAM_RED, StrToIntDef(P[1], 2))
7599 else
7600 g_Bot_Add(TEAM_RED, 2);
7601 end
7602 else if cmd = 'bot_addblue' then
7603 begin
7604 if Length(P) > 1 then
7605 g_Bot_Add(TEAM_BLUE, StrToIntDef(P[1], 2))
7606 else
7607 g_Bot_Add(TEAM_BLUE, 2);
7608 end
7609 else if cmd = 'spectate' then
7610 begin
7611 if not gGameOn then
7612 Exit;
7613 g_Game_Spectate();
7614 end
7615 else if cmd = 'say' then
7616 begin
7617 if g_Game_IsServer and g_Game_IsNet then
7618 begin
7619 if Length(P) > 1 then
7620 begin
7621 chstr := '';
7622 for a := 1 to High(P) do
7623 chstr := chstr + P[a] + ' ';
7625 if Length(chstr) > 200 then SetLength(chstr, 200);
7627 if Length(chstr) < 1 then
7628 begin
7629 g_Console_Add('say <text>');
7630 Exit;
7631 end;
7633 chstr := b_Text_Format(chstr);
7634 MH_SEND_Chat(chstr, NET_CHAT_PLAYER);
7635 end
7636 else g_Console_Add('say <text>');
7637 end else
7638 g_Console_Add(_lc[I_MSG_SERVERONLY]);
7639 end
7640 else if cmd = 'tell' then
7641 begin
7642 if g_Game_IsServer and g_Game_IsNet then
7643 begin
7644 if (Length(P) > 2) and (P[1] <> '') then
7645 begin
7646 chstr := '';
7647 for a := 2 to High(P) do
7648 chstr := chstr + P[a] + ' ';
7650 if Length(chstr) > 200 then SetLength(chstr, 200);
7652 if Length(chstr) < 1 then
7653 begin
7654 g_Console_Add('tell <playername> <text>');
7655 Exit;
7656 end;
7658 pl := g_Net_Client_ByName(P[1]);
7659 if pl <> nil then
7660 MH_SEND_Chat(b_Text_Format(chstr), NET_CHAT_PLAYER, pl^.ID)
7661 else
7662 g_Console_Add(Format(_lc[I_NET_ERR_NAME404], [P[1]]));
7663 end
7664 else g_Console_Add('tell <playername> <text>');
7665 end else
7666 g_Console_Add(_lc[I_MSG_SERVERONLY]);
7667 end
7668 else if cmd = 'centerprint' then
7669 begin
7670 if (Length(P) > 2) and (P[1] <> '') then
7671 begin
7672 chstr := '';
7673 for a := 2 to High(P) do
7674 chstr := chstr + P[a] + ' ';
7676 if Length(chstr) > 200 then SetLength(chstr, 200);
7678 if Length(chstr) < 1 then
7679 begin
7680 g_Console_Add('centerprint <timeout> <text>');
7681 Exit;
7682 end;
7684 a := StrToIntDef(P[1], 100);
7685 chstr := b_Text_Format(chstr);
7686 g_Game_Message(chstr, a);
7687 if g_Game_IsNet and g_Game_IsServer then
7688 MH_SEND_GameEvent(NET_EV_BIGTEXT, a, chstr);
7689 end
7690 else g_Console_Add('centerprint <timeout> <text>');
7691 end
7692 else if (cmd = 'overtime') and not g_Game_IsClient then
7693 begin
7694 if (Length(P) = 1) or (StrToIntDef(P[1], -1) <= 0) then
7695 Exit;
7696 // Äîïîëíèòåëüíîå âðåìÿ:
7697 gGameSettings.TimeLimit := (gTime - gGameStartTime) div 1000 + Word(StrToIntDef(P[1], 0));
7699 g_Console_Add(Format(_lc[I_MSG_TIME_LIMIT],
7700 [gGameSettings.TimeLimit div 3600,
7701 (gGameSettings.TimeLimit div 60) mod 60,
7702 gGameSettings.TimeLimit mod 60]));
7703 if g_Game_IsNet then MH_SEND_GameSettings;
7704 end
7705 else if (cmd = 'rcon_password') and g_Game_IsClient then
7706 begin
7707 if (Length(P) <= 1) then
7708 g_Console_Add('rcon_password <password>')
7709 else
7710 MC_SEND_RCONPassword(P[1]);
7711 end
7712 else if cmd = 'rcon' then
7713 begin
7714 if g_Game_IsClient then
7715 begin
7716 if Length(P) > 1 then
7717 begin
7718 chstr := '';
7719 for a := 1 to High(P) do
7720 chstr := chstr + P[a] + ' ';
7722 if Length(chstr) > 200 then SetLength(chstr, 200);
7724 if Length(chstr) < 1 then
7725 begin
7726 g_Console_Add('rcon <command>');
7727 Exit;
7728 end;
7730 MC_SEND_RCONCommand(chstr);
7731 end
7732 else g_Console_Add('rcon <command>');
7733 end;
7734 end
7735 else if cmd = 'ready' then
7736 begin
7737 if g_Game_IsServer and (gLMSRespawn = LMS_RESPAWN_WARMUP) then
7738 gLMSRespawnTime := gTime + 100;
7739 end
7740 else if (cmd = 'callvote') and g_Game_IsNet then
7741 begin
7742 if Length(P) > 1 then
7743 begin
7744 chstr := '';
7745 for a := 1 to High(P) do begin
7746 if a > 1 then chstr := chstr + ' ';
7747 chstr := chstr + P[a];
7748 end;
7750 if Length(chstr) > 200 then SetLength(chstr, 200);
7752 if Length(chstr) < 1 then
7753 begin
7754 g_Console_Add('callvote <command>');
7755 Exit;
7756 end;
7758 if g_Game_IsClient then
7759 MC_SEND_Vote(True, chstr)
7760 else
7761 g_Game_StartVote(chstr, gPlayer1Settings.Name);
7762 g_Console_Process('vote', True);
7763 end
7764 else
7765 g_Console_Add('callvote <command>');
7766 end
7767 else if (cmd = 'vote') and g_Game_IsNet then
7768 begin
7769 if g_Game_IsClient then
7770 MC_SEND_Vote(False)
7771 else if gVoteInProgress then
7772 begin
7773 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
7774 a := Floor((NetClientCount+1)/2.0) + 1
7775 else
7776 a := Floor(NetClientCount/2.0) + 1;
7777 if gVoted then
7778 begin
7779 Dec(gVoteCount);
7780 gVoted := False;
7781 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_REVOKED], [gPlayer1Settings.Name, gVoteCount, a]), True);
7782 MH_SEND_VoteEvent(NET_VE_REVOKE, gPlayer1Settings.Name, 'a', gVoteCount, a);
7783 end
7784 else
7785 begin
7786 Inc(gVoteCount);
7787 gVoted := True;
7788 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_VOTE], [gPlayer1Settings.Name, gVoteCount, a]), True);
7789 MH_SEND_VoteEvent(NET_VE_VOTE, gPlayer1Settings.Name, 'a', gVoteCount, a);
7790 g_Game_CheckVote;
7791 end;
7792 end;
7793 end
7794 end;
7795 end;
7797 procedure SystemCommands(P: SSArray);
7798 var
7799 cmd: string;
7800 begin
7801 cmd := LowerCase(P[0]);
7802 case cmd of
7803 'exit', 'quit':
7804 begin
7805 g_Game_Free();
7806 g_Game_Quit();
7807 end;
7808 'r_reset':
7809 begin
7810 gRC_Width := Max(1, gRC_Width);
7811 gRC_Height := Max(1, gRC_Height);
7812 gBPP := Max(1, gBPP);
7813 if sys_SetDisplayMode(gRC_Width, gRC_Height, gBPP, gRC_FullScreen, gRC_Maximized) = True then
7814 e_LogWriteln('resolution changed')
7815 else
7816 e_LogWriteln('resolution not changed');
7817 sys_EnableVSync(gVSync);
7818 end;
7819 'r_maxfps':
7820 begin
7821 if Length(p) = 2 then
7822 begin
7823 gMaxFPS := StrToIntDef(p[1], gMaxFPS);
7824 if gMaxFPS > 0 then
7825 gFrameTime := 1000 div gMaxFPS
7826 else
7827 gFrameTime := 0;
7828 end;
7829 e_LogWritefln('r_maxfps %d', [gMaxFPS]);
7830 end;
7831 'g_language':
7832 begin
7833 if Length(p) = 2 then
7834 begin
7835 gAskLanguage := true;
7836 gLanguage := LANGUAGE_ENGLISH;
7837 case LowerCase(p[1]) of
7838 'english':
7839 begin
7840 gAskLanguage := false;
7841 gLanguage := LANGUAGE_ENGLISH;
7842 end;
7843 'russian':
7844 begin
7845 gAskLanguage := false;
7846 gLanguage := LANGUAGE_RUSSIAN;
7847 end;
7848 'ask':
7849 begin
7850 gAskLanguage := true;
7851 gLanguage := LANGUAGE_ENGLISH;
7852 end;
7853 end;
7854 g_Language_Set(gLanguage);
7855 end
7856 else
7857 begin
7858 e_LogWritefln('usage: %s <English|Russian|Ask>', [cmd]);
7859 end
7860 end;
7861 end;
7862 end;
7864 procedure g_TakeScreenShot(Filename: string = '');
7865 var s: TStream; t: TDateTime; dir, date, name: String;
7866 begin
7867 if e_NoGraphics then Exit;
7868 try
7869 dir := e_GetWriteableDir(ScreenshotDirs);
7871 if Filename = '' then
7872 begin
7873 t := Now;
7874 DateTimeToString(date, 'yyyy-mm-dd-hh-nn-ss', t);
7875 Filename := 'screenshot-' + date;
7876 end;
7878 name := e_CatPath(dir, Filename + '.png');
7879 s := createDiskFile(name);
7880 try
7881 e_MakeScreenshot(s, gWinSizeX, gWinSizeY);
7882 s.Free;
7883 g_Console_Add(Format(_lc[I_CONSOLE_SCREENSHOT], [name]))
7884 except
7885 g_Console_Add(Format(_lc[I_CONSOLE_ERROR_WRITE], [name]));
7886 s.Free;
7887 DeleteFile(name)
7888 end
7889 except
7890 g_Console_Add('oh shit, i can''t create screenshot!')
7891 end
7892 end;
7894 procedure g_Game_InGameMenu(Show: Boolean);
7895 begin
7896 if (g_ActiveWindow = nil) and Show then
7897 begin
7898 if gGameSettings.GameType = GT_SINGLE then
7899 g_GUI_ShowWindow('GameSingleMenu')
7900 else
7901 begin
7902 if g_Game_IsClient then
7903 g_GUI_ShowWindow('GameClientMenu')
7904 else
7905 if g_Game_IsNet then
7906 g_GUI_ShowWindow('GameServerMenu')
7907 else
7908 g_GUI_ShowWindow('GameCustomMenu');
7909 end;
7910 g_Sound_PlayEx('MENU_OPEN');
7912 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
7913 if (not g_Game_IsNet) then
7914 g_Game_Pause(True);
7915 end
7916 else
7917 if (g_ActiveWindow <> nil) and (not Show) then
7918 begin
7919 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
7920 if (not g_Game_IsNet) then
7921 g_Game_Pause(False);
7922 end;
7923 end;
7925 procedure g_Game_Pause (Enable: Boolean);
7926 var
7927 oldPause: Boolean;
7928 begin
7929 if not gGameOn then exit;
7931 if not (gGameSettings.GameType in [GT_SINGLE, GT_CUSTOM]) then exit;
7933 oldPause := gPause;
7934 gPauseMain := Enable;
7936 if (gPause <> oldPause) then g_Game_PauseAllSounds(gPause);
7937 end;
7939 procedure g_Game_HolmesPause (Enable: Boolean);
7940 var
7941 oldPause: Boolean;
7942 begin
7943 if not gGameOn then exit;
7944 if not (gGameSettings.GameType in [GT_SINGLE, GT_CUSTOM]) then exit;
7946 oldPause := gPause;
7947 gPauseHolmes := Enable;
7949 if (gPause <> oldPause) then g_Game_PauseAllSounds(gPause);
7950 end;
7952 procedure g_Game_PauseAllSounds(Enable: Boolean);
7953 var
7954 i: Integer;
7955 begin
7956 // Òðèããåðû:
7957 if gTriggers <> nil then
7958 for i := 0 to High(gTriggers) do
7959 with gTriggers[i] do
7960 if (TriggerType = TRIGGER_SOUND) and
7961 (Sound <> nil) and
7962 Sound.IsPlaying() then
7963 begin
7964 Sound.Pause(Enable);
7965 end;
7967 // Çâóêè èãðîêîâ:
7968 if gPlayers <> nil then
7969 for i := 0 to High(gPlayers) do
7970 if gPlayers[i] <> nil then
7971 gPlayers[i].PauseSounds(Enable);
7973 // Ìóçûêà:
7974 if gMusic <> nil then
7975 gMusic.Pause(Enable);
7976 end;
7978 procedure g_Game_StopAllSounds(all: Boolean);
7979 var
7980 i: Integer;
7981 begin
7982 if gTriggers <> nil then
7983 for i := 0 to High(gTriggers) do
7984 with gTriggers[i] do
7985 if (TriggerType = TRIGGER_SOUND) and
7986 (Sound <> nil) then
7987 Sound.Stop();
7989 if gMusic <> nil then
7990 gMusic.Stop();
7992 if all then
7993 e_StopChannels();
7994 end;
7996 procedure g_Game_UpdateTriggerSounds;
7997 var i: Integer;
7998 begin
7999 if gTriggers <> nil then
8000 for i := 0 to High(gTriggers) do
8001 with gTriggers[i] do
8002 if (TriggerType = TRIGGER_SOUND) and (Sound <> nil) and tgcLocal and Sound.IsPlaying() then
8003 Sound.SetCoordsRect(X, Y, Width, Height, tgcVolume / 255.0)
8004 end;
8006 function g_Game_IsWatchedPlayer(UID: Word): Boolean;
8007 begin
8008 Result := False;
8009 if (gPlayer1 <> nil) and (gPlayer1.UID = UID) then
8010 begin
8011 Result := True;
8012 Exit;
8013 end;
8014 if (gPlayer2 <> nil) and (gPlayer2.UID = UID) then
8015 begin
8016 Result := True;
8017 Exit;
8018 end;
8019 if gSpectMode <> SPECT_PLAYERS then
8020 Exit;
8021 if gSpectPID1 = UID then
8022 begin
8023 Result := True;
8024 Exit;
8025 end;
8026 if gSpectViewTwo and (gSpectPID2 = UID) then
8027 begin
8028 Result := True;
8029 Exit;
8030 end;
8031 end;
8033 function g_Game_IsWatchedTeam(Team: Byte): Boolean;
8034 var
8035 Pl: TPlayer;
8036 begin
8037 Result := False;
8038 if (gPlayer1 <> nil) and (gPlayer1.Team = Team) then
8039 begin
8040 Result := True;
8041 Exit;
8042 end;
8043 if (gPlayer2 <> nil) and (gPlayer2.Team = Team) then
8044 begin
8045 Result := True;
8046 Exit;
8047 end;
8048 if gSpectMode <> SPECT_PLAYERS then
8049 Exit;
8050 Pl := g_Player_Get(gSpectPID1);
8051 if (Pl <> nil) and (Pl.Team = Team) then
8052 begin
8053 Result := True;
8054 Exit;
8055 end;
8056 if gSpectViewTwo then
8057 begin
8058 Pl := g_Player_Get(gSpectPID2);
8059 if (Pl <> nil) and (Pl.Team = Team) then
8060 begin
8061 Result := True;
8062 Exit;
8063 end;
8064 end;
8065 end;
8067 procedure g_Game_Message(Msg: string; Time: Word);
8068 begin
8069 MessageLineLength := (gScreenWidth - 204) div e_CharFont_GetMaxWidth(gMenuFont);
8070 MessageText := b_Text_Wrap(b_Text_Format(Msg), MessageLineLength);
8071 MessageTime := Time;
8072 end;
8074 procedure g_Game_ChatSound(Text: String; Taunt: Boolean = True);
8075 const
8076 punct: Array[0..13] of String =
8077 ('.', ',', ':', ';', '!', '?', '(', ')', '''', '"', '/', '\', '*', '^');
8078 var
8079 i, j: Integer;
8080 ok: Boolean;
8081 fpText: String;
8083 function IsPunctuation(S: String): Boolean;
8084 var
8085 i: Integer;
8086 begin
8087 Result := False;
8088 if Length(S) <> 1 then
8089 Exit;
8090 for i := Low(punct) to High(punct) do
8091 if S = punct[i] then
8092 begin
8093 Result := True;
8094 break;
8095 end;
8096 end;
8097 function FilterPunctuation(S: String): String;
8098 var
8099 i: Integer;
8100 begin
8101 for i := Low(punct) to High(punct) do
8102 S := StringReplace(S, punct[i], ' ', [rfReplaceAll]);
8103 Result := S;
8104 end;
8105 begin
8106 ok := False;
8108 if gUseChatSounds and Taunt and (gChatSounds <> nil) and (Pos(': ', Text) > 0) then
8109 begin
8110 // remove player name
8111 Delete(Text, 1, Pos(': ', Text) + 2 - 1);
8112 // for FullWord check
8113 Text := toLowerCase1251(' ' + Text + ' ');
8114 fpText := FilterPunctuation(Text);
8116 for i := 0 to Length(gChatSounds) - 1 do
8117 begin
8118 ok := True;
8119 for j := 0 to Length(gChatSounds[i].Tags) - 1 do
8120 begin
8121 if gChatSounds[i].FullWord and (not IsPunctuation(gChatSounds[i].Tags[j])) then
8122 ok := Pos(' ' + gChatSounds[i].Tags[j] + ' ', fpText) > 0
8123 else
8124 ok := Pos(gChatSounds[i].Tags[j], Text) > 0;
8125 if not ok then
8126 break;
8127 end;
8128 if ok then
8129 begin
8130 gChatSounds[i].Sound.Play();
8131 break;
8132 end;
8133 end;
8134 end;
8135 if not ok then
8136 g_Sound_PlayEx('SOUND_GAME_RADIO');
8137 end;
8139 procedure g_Game_Announce_GoodShot(SpawnerUID: Word);
8140 var
8141 a: Integer;
8142 begin
8143 case gAnnouncer of
8144 ANNOUNCE_NONE:
8145 Exit;
8146 ANNOUNCE_ME,
8147 ANNOUNCE_MEPLUS:
8148 if not g_Game_IsWatchedPlayer(SpawnerUID) then
8149 Exit;
8150 end;
8151 for a := 0 to 3 do
8152 if goodsnd[a].IsPlaying() then
8153 Exit;
8155 goodsnd[Random(4)].Play();
8156 end;
8158 procedure g_Game_Announce_KillCombo(Param: Integer);
8159 var
8160 UID: Word;
8161 c, n: Byte;
8162 Pl: TPlayer;
8163 Name: String;
8164 begin
8165 UID := Param and $FFFF;
8166 c := Param shr 16;
8167 if c < 2 then
8168 Exit;
8170 Pl := g_Player_Get(UID);
8171 if Pl = nil then
8172 Name := '?'
8173 else
8174 Name := Pl.Name;
8176 case c of
8177 2: begin
8178 n := 0;
8179 g_Console_Add(Format(_lc[I_PLAYER_KILL_2X], [Name]), True);
8180 end;
8181 3: begin
8182 n := 1;
8183 g_Console_Add(Format(_lc[I_PLAYER_KILL_3X], [Name]), True);
8184 end;
8185 4: begin
8186 n := 2;
8187 g_Console_Add(Format(_lc[I_PLAYER_KILL_4X], [Name]), True);
8188 end;
8189 else begin
8190 n := 3;
8191 g_Console_Add(Format(_lc[I_PLAYER_KILL_MX], [Name]), True);
8192 end;
8193 end;
8195 case gAnnouncer of
8196 ANNOUNCE_NONE:
8197 Exit;
8198 ANNOUNCE_ME:
8199 if not g_Game_IsWatchedPlayer(UID) then
8200 Exit;
8201 ANNOUNCE_MEPLUS:
8202 if (not g_Game_IsWatchedPlayer(UID)) and (c < 4) then
8203 Exit;
8204 end;
8206 if killsnd[n].IsPlaying() then
8207 killsnd[n].Stop();
8208 killsnd[n].Play();
8209 end;
8211 procedure g_Game_Announce_BodyKill(SpawnerUID: Word);
8212 var
8213 a: Integer;
8214 begin
8215 case gAnnouncer of
8216 ANNOUNCE_NONE:
8217 Exit;
8218 ANNOUNCE_ME:
8219 if not g_Game_IsWatchedPlayer(SpawnerUID) then
8220 Exit;
8221 end;
8222 for a := 0 to 2 do
8223 if hahasnd[a].IsPlaying() then
8224 Exit;
8226 hahasnd[Random(3)].Play();
8227 end;
8229 procedure g_Game_Effect_Bubbles (fX, fY: Integer; count: Word; devX, devY: Byte; Silent: Boolean);
8230 begin
8231 g_GFX_Bubbles(fX, fY, count, devX, devY);
8232 if not Silent then if Random(2) = 0
8233 then g_Sound_PlayExAt('SOUND_GAME_BUBBLE1', fX, fY)
8234 else g_Sound_PlayExAt('SOUND_GAME_BUBBLE2', fX, fY);
8235 end;
8237 procedure g_Game_StartVote(Command, Initiator: string);
8238 var
8239 Need: Integer;
8240 begin
8241 if not gVotesEnabled then Exit;
8242 if gGameSettings.GameType <> GT_SERVER then Exit;
8243 if gVoteInProgress or gVotePassed then
8244 begin
8245 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_INPROGRESS], [gVoteCommand]), True);
8246 MH_SEND_VoteEvent(NET_VE_INPROGRESS, gVoteCommand);
8247 Exit;
8248 end;
8249 gVoteInProgress := True;
8250 gVotePassed := False;
8251 gVoteTimer := gTime + gVoteTimeout * 1000;
8252 gVoteCount := 0;
8253 gVoted := False;
8254 gVoteCommand := Command;
8256 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
8257 Need := Floor((NetClientCount+1)/2.0)+1
8258 else
8259 Need := Floor(NetClientCount/2.0)+1;
8260 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_STARTED], [Initiator, Command, Need]), True);
8261 MH_SEND_VoteEvent(NET_VE_STARTED, Initiator, Command, Need);
8262 end;
8264 procedure g_Game_CheckVote;
8265 var
8266 I, Need: Integer;
8267 begin
8268 if gGameSettings.GameType <> GT_SERVER then Exit;
8269 if not gVoteInProgress then Exit;
8271 if (gTime >= gVoteTimer) then
8272 begin
8273 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
8274 Need := Floor((NetClientCount+1)/2.0) + 1
8275 else
8276 Need := Floor(NetClientCount/2.0) + 1;
8277 if gVoteCount >= Need then
8278 begin
8279 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_PASSED], [gVoteCommand]), True);
8280 MH_SEND_VoteEvent(NET_VE_PASSED, gVoteCommand);
8281 gVotePassed := True;
8282 gVoteCmdTimer := gTime + 5000;
8283 end
8284 else
8285 begin
8286 g_Console_Add(_lc[I_MESSAGE_VOTE_FAILED], True);
8287 MH_SEND_VoteEvent(NET_VE_FAILED);
8288 end;
8289 if NetClients <> nil then
8290 for I := Low(NetClients) to High(NetClients) do
8291 if NetClients[i].Used then
8292 NetClients[i].Voted := False;
8293 gVoteInProgress := False;
8294 gVoted := False;
8295 gVoteCount := 0;
8296 end
8297 else
8298 begin
8299 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
8300 Need := Floor((NetClientCount+1)/2.0) + 1
8301 else
8302 Need := Floor(NetClientCount/2.0) + 1;
8303 if gVoteCount >= Need then
8304 begin
8305 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_PASSED], [gVoteCommand]), True);
8306 MH_SEND_VoteEvent(NET_VE_PASSED, gVoteCommand);
8307 gVoteInProgress := False;
8308 gVotePassed := True;
8309 gVoteCmdTimer := gTime + 5000;
8310 gVoted := False;
8311 gVoteCount := 0;
8312 if NetClients <> nil then
8313 for I := Low(NetClients) to High(NetClients) do
8314 if NetClients[i].Used then
8315 NetClients[i].Voted := False;
8316 end;
8317 end;
8318 end;
8320 procedure g_Game_LoadMapList(FileName: string);
8321 var
8322 ListFile: TextFile;
8323 s: string;
8324 begin
8325 MapList := nil;
8326 MapIndex := -1;
8328 if not FileExists(FileName) then Exit;
8330 AssignFile(ListFile, FileName);
8331 Reset(ListFile);
8332 while not EOF(ListFile) do
8333 begin
8334 ReadLn(ListFile, s);
8336 s := Trim(s);
8337 if s = '' then Continue;
8339 SetLength(MapList, Length(MapList)+1);
8340 MapList[High(MapList)] := s;
8341 end;
8342 CloseFile(ListFile);
8343 end;
8345 procedure g_Game_SetDebugMode();
8346 begin
8347 gDebugMode := True;
8348 // ×èòû (äàæå â ñâîåé èãðå):
8349 gCheats := True;
8350 end;
8352 procedure g_Game_SetLoadingText(Text: String; Max: Integer; reWrite: Boolean);
8353 var
8354 i: Word;
8355 begin
8356 if Length(LoadingStat.Msgs) = 0 then
8357 Exit;
8359 with LoadingStat do
8360 begin
8361 if not reWrite then
8362 begin // Ïåðåõîäèì íà ñëåäóþùóþ ñòðîêó èëè ñêðîëëèðóåì:
8363 if NextMsg = Length(Msgs) then
8364 begin // scroll
8365 for i := 0 to High(Msgs)-1 do
8366 Msgs[i] := Msgs[i+1];
8367 end
8368 else
8369 Inc(NextMsg);
8370 end else
8371 if NextMsg = 0 then
8372 Inc(NextMsg);
8374 Msgs[NextMsg-1] := Text;
8375 CurValue := 0;
8376 MaxValue := Max;
8377 ShowCount := 0;
8378 PBarWasHere := false;
8379 end;
8381 g_ActiveWindow := nil;
8382 ProcessLoading(True);
8383 end;
8385 procedure g_Game_StepLoading(Value: Integer = -1);
8386 begin
8387 with LoadingStat do
8388 begin
8389 if Value = -1 then
8390 begin
8391 Inc(CurValue);
8392 Inc(ShowCount);
8393 end
8394 else
8395 CurValue := Value;
8397 if (ShowCount > LOADING_SHOW_STEP) or (Value > -1) then
8398 begin
8399 ShowCount := 0;
8400 ProcessLoading(False);
8401 end;
8402 end;
8403 end;
8405 procedure g_Game_ClearLoading();
8406 var
8407 len: Word;
8408 begin
8409 with LoadingStat do
8410 begin
8411 CurValue := 0;
8412 MaxValue := 0;
8413 ShowCount := 0;
8414 len := ((gScreenHeight div 3)*2 - 50) div LOADING_INTERLINE;
8415 if len < 1 then len := 1;
8416 SetLength(Msgs, len);
8417 for len := Low(Msgs) to High(Msgs) do
8418 Msgs[len] := '';
8419 NextMsg := 0;
8420 PBarWasHere := false;
8421 end;
8422 end;
8424 procedure Parse_Params(var pars: TParamStrValues);
8425 var
8426 i: Integer;
8427 s: String;
8428 begin
8429 SetLength(pars, 0);
8430 i := 1;
8431 while i <= ParamCount do
8432 begin
8433 s := ParamStr(i);
8434 if (Length(s) > 1) and (s[1] = '-') then
8435 begin
8436 if (Length(s) > 2) and (s[2] = '-') then
8437 begin // Îäèíî÷íûé ïàðàìåòð
8438 SetLength(pars, Length(pars) + 1);
8439 with pars[High(pars)] do
8440 begin
8441 Name := LowerCase(s);
8442 Value := '+';
8443 end;
8444 end
8445 else
8446 if (i < ParamCount) then
8447 begin // Ïàðàìåòð ñî çíà÷åíèåì
8448 Inc(i);
8449 SetLength(pars, Length(pars) + 1);
8450 with pars[High(pars)] do
8451 begin
8452 Name := LowerCase(s);
8453 Value := LowerCase(ParamStr(i));
8454 end;
8455 end;
8456 end;
8458 Inc(i);
8459 end;
8460 end;
8462 function Find_Param_Value(var pars: TParamStrValues; aName: String): String;
8463 var
8464 i: Integer;
8465 begin
8466 Result := '';
8467 for i := 0 to High(pars) do
8468 if pars[i].Name = aName then
8469 begin
8470 Result := pars[i].Value;
8471 Break;
8472 end;
8473 end;
8475 procedure g_Game_Process_Params();
8476 var
8477 pars: TParamStrValues;
8478 map: String;
8479 GMode, n: Byte;
8480 LimT, LimS: Integer;
8481 Opt: LongWord;
8482 Lives: Integer;
8483 s: String;
8484 Port: Integer;
8485 ip: String;
8486 F: TextFile;
8487 begin
8488 Parse_Params(pars);
8490 // Debug mode:
8491 s := Find_Param_Value(pars, '--debug');
8492 if (s <> '') then
8493 begin
8494 g_Game_SetDebugMode();
8495 s := Find_Param_Value(pars, '--netdump');
8496 if (s <> '') then
8497 NetDump := True;
8498 end;
8500 // Connect when game loads
8501 ip := Find_Param_Value(pars, '-connect');
8503 if ip <> '' then
8504 begin
8505 s := Find_Param_Value(pars, '-port');
8506 if (s = '') or not TryStrToInt(s, Port) then
8507 Port := 25666;
8509 s := Find_Param_Value(pars, '-pw');
8511 g_Game_StartClient(ip, Port, s);
8512 Exit;
8513 end;
8515 s := LowerCase(Find_Param_Value(pars, '-dbg-mainwad'));
8516 if (s <> '') then
8517 begin
8518 gDefaultMegawadStart := s;
8519 end;
8521 if (Find_Param_Value(pars, '--dbg-mainwad-restore') <> '') or
8522 (Find_Param_Value(pars, '--dbg-mainwad-default') <> '') then
8523 begin
8524 gDefaultMegawadStart := DF_Default_Megawad_Start;
8525 end;
8527 // Start map when game loads:
8528 map := LowerCase(Find_Param_Value(pars, '-map'));
8529 if isWadPath(map) then
8530 begin
8531 // Game mode:
8532 s := Find_Param_Value(pars, '-gm');
8533 GMode := g_Game_TextToMode(s);
8534 if GMode = GM_NONE then GMode := GM_DM;
8535 if GMode = GM_SINGLE then GMode := GM_COOP;
8537 // Time limit:
8538 s := Find_Param_Value(pars, '-limt');
8539 if (s = '') or (not TryStrToInt(s, LimT)) then
8540 LimT := 0;
8541 if LimT < 0 then
8542 LimT := 0;
8544 // Score limit:
8545 s := Find_Param_Value(pars, '-lims');
8546 if (s = '') or (not TryStrToInt(s, LimS)) then
8547 LimS := 0;
8548 if LimS < 0 then
8549 LimS := 0;
8551 // Lives limit:
8552 s := Find_Param_Value(pars, '-lives');
8553 if (s = '') or (not TryStrToInt(s, Lives)) then
8554 Lives := 0;
8555 if Lives < 0 then
8556 Lives := 0;
8558 // Options:
8559 s := Find_Param_Value(pars, '-opt');
8560 if (s = '') then
8561 Opt := gsGameFlags
8562 else
8563 Opt := StrToIntDef(s, 0);
8565 // Close after map:
8566 s := Find_Param_Value(pars, '--close');
8567 if (s <> '') then
8568 gMapOnce := True;
8570 // Override map to test:
8571 s := LowerCase(Find_Param_Value(pars, '-testmap'));
8572 if s <> '' then
8573 begin
8574 if e_IsValidResourceName(s) then
8575 e_FindResource(AllMapDirs, s);
8576 gTestMap := ExpandFileName(s);
8577 end;
8579 // Delete test map after play:
8580 s := Find_Param_Value(pars, '--testdelete');
8581 if (s <> '') then
8582 begin
8583 //gMapToDelete := MapsDir + map;
8584 e_WriteLog('"--testdelete" is deprecated, use --tempdelete.', TMsgType.Fatal);
8585 Halt(1);
8586 end;
8588 // Delete temporary WAD after play:
8589 s := Find_Param_Value(pars, '--tempdelete');
8590 if (s <> '') and (gTestMap <> '') then
8591 begin
8592 gMapToDelete := gTestMap;
8593 gTempDelete := True;
8594 end;
8596 // Number of players:
8597 s := Find_Param_Value(pars, '-pl');
8598 if (s = '') then
8599 n := DEFAULT_PLAYERS
8600 else
8601 n := StrToIntDef(s, DEFAULT_PLAYERS);
8603 // Start:
8604 s := Find_Param_Value(pars, '-port');
8605 if (s = '') or not TryStrToInt(s, Port) then
8606 g_Game_StartCustom(map, GMode, LimT, LimS, Lives, Opt, n)
8607 else
8608 g_Game_StartServer(map, GMode, LimT, LimS, Lives, Opt, n, 0, Port);
8609 end;
8611 // Execute script when game loads:
8612 s := Find_Param_Value(pars, '-exec');
8613 if s <> '' then
8614 begin
8615 // if not isWadPath(s) then
8616 // s := GameDir + '/' + s;
8618 {$I-}
8619 AssignFile(F, s);
8620 Reset(F);
8621 if IOResult <> 0 then
8622 begin
8623 e_WriteLog(Format(_lc[I_SIMPLE_ERROR], ['Failed to read file: ' + s]), TMsgType.Warning);
8624 g_Console_Add(Format(_lc[I_CONSOLE_ERROR_READ], [s]));
8625 CloseFile(F);
8626 Exit;
8627 end;
8628 e_WriteLog('Executing script: ' + s, TMsgType.Notify);
8629 g_Console_Add(Format(_lc[I_CONSOLE_EXEC], [s]));
8631 while not EOF(F) do
8632 begin
8633 ReadLn(F, s);
8634 if IOResult <> 0 then
8635 begin
8636 e_WriteLog(Format(_lc[I_SIMPLE_ERROR], ['Failed to read file: ' + s]), TMsgType.Warning);
8637 g_Console_Add(Format(_lc[I_CONSOLE_ERROR_READ], [s]));
8638 CloseFile(F);
8639 Exit;
8640 end;
8641 if Pos('#', s) <> 1 then // script comment
8642 g_Console_Process(s, True);
8643 end;
8645 CloseFile(F);
8646 {$I+}
8647 end;
8649 SetLength(pars, 0);
8650 end;
8652 begin
8653 conRegVar('pf_draw_frame', @g_profile_frame_draw, 'draw frame rendering profiles', 'render profiles');
8654 //conRegVar('pf_update_frame', @g_profile_frame_update, 'draw frame updating profiles', 'update profiles');
8655 conRegVar('pf_coldet', @g_profile_collision, 'draw collision detection profiles', 'coldet profiles');
8656 conRegVar('pf_los', @g_profile_los, 'draw monster LOS profiles', 'monster LOS profiles');
8658 conRegVar('r_sq_draw', @gdbg_map_use_accel_render, 'accelerated spatial queries in rendering', 'accelerated rendering');
8659 conRegVar('cd_sq_enabled', @gdbg_map_use_accel_coldet, 'accelerated spatial queries in map coldet', 'accelerated map coldet');
8660 conRegVar('mon_sq_enabled', @gmon_debug_use_sqaccel, 'accelerated spatial queries for monsters', 'accelerated monster coldet');
8661 conRegVar('wtrace_sq_enabled', @gwep_debug_fast_trace, 'accelerated spatial queries for weapon hitscan trace', 'accelerated weapon hitscan');
8663 conRegVar('pr_enabled', @gpart_dbg_enabled, 'enable/disable particles', 'particles');
8664 conRegVar('pr_phys_enabled', @gpart_dbg_phys_enabled, 'enable/disable particle physics', 'particle physics');
8666 conRegVar('los_enabled', @gmon_dbg_los_enabled, 'enable/disable monster LOS calculations', 'monster LOS', true);
8667 conRegVar('mon_think', @gmon_debug_think, 'enable/disable monster thinking', 'monster thinking', true);
8669 {$IFDEF ENABLE_HOLMES}
8670 conRegVar('dbg_holmes', @g_holmes_enabled, 'enable/disable Holmes', 'Holmes', true);
8671 {$ENDIF}
8673 conRegVar('dbg_ignore_level_bounds', @g_dbg_ignore_bounds, 'ignore level bounds', '', false);
8675 conRegVar('r_scale', @g_dbg_scale, 0.01, 100.0, 'render scale', '', false);
8676 conRegVar('r_resolution_scale', @r_pixel_scale, 0.01, 100.0, 'upscale factor', '', false);
8678 conRegVar('light_enabled', @gwin_k8_enable_light_experiments, 'enable/disable dynamic lighting', 'lighting');
8679 conRegVar('light_player_halo', @g_playerLight, 'enable/disable player halo', 'player light halo');
8681 conRegVar('r_smallmap_align_h', @r_smallmap_h, 'halign: 0: left; 1: center; 2: right', 'horizontal aligning of small maps');
8682 conRegVar('r_smallmap_align_v', @r_smallmap_v, 'valign: 0: top; 1: center; 2: bottom', 'vertial aligning of small maps');
8684 conRegVar('r_showfps', @gShowFPS, 'draw fps counter', 'draw fps counter');
8685 conRegVar('r_showtime', @gShowTime, 'show game time', 'show game time');
8686 conRegVar('r_showping', @gShowPing, 'show ping', 'show ping');
8687 conRegVar('r_showscore', @gShowScore, 'show score', 'show score');
8688 conRegVar('r_showkillmsg', @gShowKillMsg, 'show kill log', 'show kill log');
8689 conRegVar('r_showlives', @gShowLives, 'show lives', 'show lives');
8690 conRegVar('r_showspect', @gSpectHUD, 'show spectator hud', 'show spectator hud');
8691 conRegVar('r_showstat', @gShowStat, 'show stats', 'show stats');
8692 conRegVar('r_showpids', @gShowPIDs, 'show PIDs', 'show PIDs');
8693 end.