DEADSOFTWARE

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