DEADSOFTWARE

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