DEADSOFTWARE

Add weapbest command
[d2df-sdl.git] / src / game / g_game.pas
1 (* Copyright (C) Doom 2D: Forever Developers
2 *
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, version 3 of the License ONLY.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
14 *)
15 {$INCLUDE ../shared/a_modes.inc}
16 unit g_game;
18 interface
20 uses
21 SysUtils, Classes,
22 MAPDEF,
23 g_basic, g_player, e_graphics, g_res_downloader,
24 g_sound, g_gui, utils, md5, mempool, xprofiler,
25 g_touch, g_weapons;
27 type
28 TGameSettings = record
29 GameType: Byte;
30 GameMode: Byte;
31 TimeLimit: Word;
32 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 SwitchToFist: 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 g_Console_Add(Format(_lc[I_PLAYER_JOIN], [gPlayer1.Name]), True);
4358 if g_Game_IsServer and g_Game_IsNet then
4359 MH_SEND_PlayerCreate(gPlayer1.UID);
4360 gPlayer1.Respawn(False, True);
4361 g_Net_Slist_ServerPlayerComes();
4362 end;
4364 Exit;
4365 end;
4366 if gPlayer2 = nil then
4367 begin
4368 if g_Game_IsClient then
4369 begin
4370 if NetPlrUID2 > -1 then
4371 gPlayer2 := g_Player_Get(NetPlrUID2);
4372 Exit;
4373 end;
4375 if not (Team in [TEAM_RED, TEAM_BLUE]) then
4376 Team := gPlayer2Settings.Team;
4378 // Ñîçäàíèå âòîðîãî èãðîêà:
4379 gPlayer2 := g_Player_Get(g_Player_Create(gPlayer2Settings.Model,
4380 gPlayer2Settings.Color,
4381 Team, False));
4382 if gPlayer2 = nil then
4383 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [2]))
4384 else
4385 begin
4386 gPlayer2.Name := gPlayer2Settings.Name;
4387 gPlayer2.WeapSwitchMode := gPlayer2Settings.WeaponSwitch;
4388 gPlayer2.setWeaponPrefs(gPlayer2Settings.WeaponPreferences);
4389 gPlayer2.SwitchToEmpty := gPlayer2Settings.SwitchToEmpty;
4390 g_Console_Add(Format(_lc[I_PLAYER_JOIN], [gPlayer2.Name]), True);
4391 if g_Game_IsServer and g_Game_IsNet then
4392 MH_SEND_PlayerCreate(gPlayer2.UID);
4393 gPlayer2.Respawn(False, True);
4394 g_Net_Slist_ServerPlayerComes();
4395 end;
4397 Exit;
4398 end;
4399 end;
4401 procedure g_Game_RemovePlayer();
4402 var
4403 Pl: TPlayer;
4404 begin
4405 if ((not gGameOn) and (gState <> STATE_INTERCUSTOM))
4406 or (not (gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT])) then
4407 Exit;
4408 Pl := gPlayer2;
4409 if Pl <> nil then
4410 begin
4411 if g_Game_IsServer then
4412 begin
4413 Pl.Lives := 0;
4414 Pl.Kill(K_SIMPLEKILL, 0, HIT_DISCON);
4415 g_Console_Add(Format(_lc[I_PLAYER_LEAVE], [Pl.Name]), True);
4416 g_Player_Remove(Pl.UID);
4417 g_Net_Slist_ServerPlayerLeaves();
4418 end
4419 else
4420 begin
4421 gSpectLatchPID2 := Pl.UID;
4422 gPlayer2 := nil;
4423 end;
4424 Exit;
4425 end;
4426 Pl := gPlayer1;
4427 if Pl <> nil then
4428 begin
4429 if g_Game_IsServer then
4430 begin
4431 Pl.Lives := 0;
4432 Pl.Kill(K_SIMPLEKILL, 0, HIT_DISCON);
4433 g_Console_Add(Format(_lc[I_PLAYER_LEAVE], [Pl.Name]), True);
4434 g_Player_Remove(Pl.UID);
4435 g_Net_Slist_ServerPlayerLeaves();
4436 end else
4437 begin
4438 gSpectLatchPID1 := Pl.UID;
4439 gPlayer1 := nil;
4440 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE);
4441 end;
4442 Exit;
4443 end;
4444 g_Net_Slist_ServerPlayerLeaves();
4445 end;
4447 procedure g_Game_Spectate();
4448 begin
4449 g_Game_RemovePlayer();
4450 if gPlayer1 <> nil then
4451 g_Game_RemovePlayer();
4452 end;
4454 procedure g_Game_SpectateCenterView();
4455 begin
4456 gSpectX := Max(gMapInfo.Width div 2 - gScreenWidth div 2, 0);
4457 gSpectY := Max(gMapInfo.Height div 2 - gScreenHeight div 2, 0);
4458 end;
4460 procedure g_Game_StartSingle(Map: String; TwoPlayers: Boolean; nPlayers: Byte);
4461 var
4462 i, nPl: Integer;
4463 tmps: AnsiString;
4464 begin
4465 g_Game_Free();
4467 e_WriteLog('Starting singleplayer game...', TMsgType.Notify);
4469 g_Game_ClearLoading();
4471 // Íàñòðîéêè èãðû:
4472 FillByte(gGameSettings, SizeOf(TGameSettings), 0);
4473 gAimLine := False;
4474 gShowMap := False;
4475 gGameSettings.GameType := GT_SINGLE;
4476 gGameSettings.MaxLives := 0;
4477 gGameSettings.Options := gGameSettings.Options + GAME_OPTION_ALLOWEXIT;
4478 gGameSettings.Options := gGameSettings.Options + GAME_OPTION_MONSTERS;
4479 gGameSettings.Options := gGameSettings.Options + GAME_OPTION_BOTVSMONSTER;
4480 gGameSettings.Options := gGameSettings.Options + GAME_OPTION_TEAMHITPROJECTILE;
4481 gGameSettings.Options := gGameSettings.Options + GAME_OPTION_TEAMHITTRACE;
4482 gSwitchGameMode := GM_SINGLE;
4484 gLMSRespawn := LMS_RESPAWN_NONE;
4485 gLMSRespawnTime := 0;
4486 gSpectLatchPID1 := 0;
4487 gSpectLatchPID2 := 0;
4489 g_Game_ExecuteEvent('ongamestart');
4491 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
4492 g_Game_SetupScreenSize();
4494 // Ñîçäàíèå ïåðâîãî èãðîêà:
4495 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
4496 gPlayer1Settings.Color,
4497 gPlayer1Settings.Team, False));
4498 if gPlayer1 = nil then
4499 begin
4500 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]));
4501 Exit;
4502 end;
4504 gPlayer1.Name := gPlayer1Settings.Name;
4505 gPlayer1.WeapSwitchMode := gPlayer1Settings.WeaponSwitch;
4506 gPlayer1.setWeaponPrefs(gPlayer1Settings.WeaponPreferences);
4507 gPlayer1.SwitchToEmpty := gPlayer1Settings.SwitchToEmpty;
4508 nPl := 1;
4510 // Ñîçäàíèå âòîðîãî èãðîêà, åñëè åñòü:
4511 if TwoPlayers then
4512 begin
4513 gPlayer2 := g_Player_Get(g_Player_Create(gPlayer2Settings.Model,
4514 gPlayer2Settings.Color,
4515 gPlayer2Settings.Team, False));
4516 if gPlayer2 = nil then
4517 begin
4518 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [2]));
4519 Exit;
4520 end;
4522 gPlayer2.Name := gPlayer2Settings.Name;
4523 gPlayer2.WeapSwitchMode := gPlayer2Settings.WeaponSwitch;
4524 gPlayer2.setWeaponPrefs(gPlayer2Settings.WeaponPreferences);
4525 gPlayer2.SwitchToEmpty := gPlayer2Settings.SwitchToEmpty;
4526 Inc(nPl);
4527 end;
4529 // Çàãðóçêà è çàïóñê êàðòû:
4530 if not g_Game_StartMap(false{asMegawad}, MAP, True) then
4531 begin
4532 if (Pos(':\', Map) > 0) or (Pos(':/', Map) > 0) then tmps := Map else tmps := gGameSettings.WAD + ':\' + MAP;
4533 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [tmps]));
4534 Exit;
4535 end;
4537 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4538 g_Player_Init();
4540 // Ñîçäàåì áîòîâ:
4541 for i := nPl+1 to nPlayers do
4542 g_Player_Create(STD_PLAYER_MODEL, _RGB(0, 0, 0), 0, True);
4543 end;
4545 procedure g_Game_StartCustom(Map: String; GameMode: Byte;
4546 TimeLimit, GoalLimit: Word;
4547 MaxLives: Byte;
4548 Options: LongWord; nPlayers: Byte);
4549 var
4550 i, nPl: Integer;
4551 begin
4552 g_Game_Free();
4554 e_WriteLog('Starting custom game...', TMsgType.Notify);
4556 g_Game_ClearLoading();
4558 // Íàñòðîéêè èãðû:
4559 gGameSettings.GameType := GT_CUSTOM;
4560 gGameSettings.GameMode := GameMode;
4561 gSwitchGameMode := GameMode;
4562 gGameSettings.TimeLimit := TimeLimit;
4563 gGameSettings.GoalLimit := GoalLimit;
4564 gGameSettings.MaxLives := IfThen(GameMode = GM_CTF, 0, MaxLives);
4565 gGameSettings.Options := Options;
4567 gCoopTotalMonstersKilled := 0;
4568 gCoopTotalSecretsFound := 0;
4569 gCoopTotalMonsters := 0;
4570 gCoopTotalSecrets := 0;
4571 gAimLine := False;
4572 gShowMap := False;
4574 gLMSRespawn := LMS_RESPAWN_NONE;
4575 gLMSRespawnTime := 0;
4576 gSpectLatchPID1 := 0;
4577 gSpectLatchPID2 := 0;
4579 g_Game_ExecuteEvent('ongamestart');
4581 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
4582 g_Game_SetupScreenSize();
4584 // Ðåæèì íàáëþäàòåëÿ:
4585 if nPlayers = 0 then
4586 begin
4587 gPlayer1 := nil;
4588 gPlayer2 := nil;
4589 end;
4591 nPl := 0;
4592 if nPlayers >= 1 then
4593 begin
4594 // Ñîçäàíèå ïåðâîãî èãðîêà:
4595 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
4596 gPlayer1Settings.Color,
4597 gPlayer1Settings.Team, False));
4598 if gPlayer1 = nil then
4599 begin
4600 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]));
4601 Exit;
4602 end;
4604 gPlayer1.Name := gPlayer1Settings.Name;
4605 gPlayer1.WeapSwitchMode := gPlayer1Settings.WeaponSwitch;
4606 gPlayer1.setWeaponPrefs(gPlayer1Settings.WeaponPreferences);
4607 gPlayer1.SwitchToEmpty := gPlayer1Settings.SwitchToEmpty;
4608 Inc(nPl);
4609 end;
4611 if nPlayers >= 2 then
4612 begin
4613 // Ñîçäàíèå âòîðîãî èãðîêà:
4614 gPlayer2 := g_Player_Get(g_Player_Create(gPlayer2Settings.Model,
4615 gPlayer2Settings.Color,
4616 gPlayer2Settings.Team, False));
4617 if gPlayer2 = nil then
4618 begin
4619 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [2]));
4620 Exit;
4621 end;
4623 gPlayer2.Name := gPlayer2Settings.Name;
4624 gPlayer2.WeapSwitchMode := gPlayer2Settings.WeaponSwitch;
4625 gPlayer2.setWeaponPrefs(gPlayer2Settings.WeaponPreferences);
4626 gPlayer2.SwitchToEmpty := gPlayer2Settings.SwitchToEmpty;
4627 Inc(nPl);
4628 end;
4630 // Çàãðóçêà è çàïóñê êàðòû:
4631 if not g_Game_StartMap(true{asMegawad}, Map, True) then
4632 begin
4633 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [Map]));
4634 Exit;
4635 end;
4637 // Íåò òî÷åê ïîÿâëåíèÿ:
4638 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1) +
4639 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2) +
4640 g_Map_GetPointCount(RESPAWNPOINT_DM) +
4641 g_Map_GetPointCount(RESPAWNPOINT_RED)+
4642 g_Map_GetPointCount(RESPAWNPOINT_BLUE)) < 1 then
4643 begin
4644 g_FatalError(_lc[I_GAME_ERROR_GET_SPAWN]);
4645 Exit;
4646 end;
4648 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4649 g_Player_Init();
4651 // Ñîçäàåì áîòîâ:
4652 for i := nPl+1 to nPlayers do
4653 g_Player_Create(STD_PLAYER_MODEL, _RGB(0, 0, 0), 0, True);
4654 end;
4656 procedure g_Game_StartServer(Map: String; GameMode: Byte;
4657 TimeLimit, GoalLimit: Word; MaxLives: Byte;
4658 Options: LongWord; nPlayers: Byte;
4659 IPAddr: LongWord; Port: Word);
4660 begin
4661 g_Game_Free();
4662 g_Net_Slist_ServerClosed();
4664 e_WriteLog('Starting net game (server)...', TMsgType.Notify);
4666 g_Game_ClearLoading();
4668 // Íàñòðîéêè èãðû:
4669 gGameSettings.GameType := GT_SERVER;
4670 gGameSettings.GameMode := GameMode;
4671 gSwitchGameMode := GameMode;
4672 gGameSettings.TimeLimit := TimeLimit;
4673 gGameSettings.GoalLimit := GoalLimit;
4674 gGameSettings.MaxLives := IfThen(GameMode = GM_CTF, 0, MaxLives);
4675 gGameSettings.Options := Options;
4677 gCoopTotalMonstersKilled := 0;
4678 gCoopTotalSecretsFound := 0;
4679 gCoopTotalMonsters := 0;
4680 gCoopTotalSecrets := 0;
4681 gAimLine := False;
4682 gShowMap := False;
4684 gLMSRespawn := LMS_RESPAWN_NONE;
4685 gLMSRespawnTime := 0;
4686 gSpectLatchPID1 := 0;
4687 gSpectLatchPID2 := 0;
4689 g_Game_ExecuteEvent('ongamestart');
4691 // Óñòàíîâêà ðàçìåðîâ îêíà èãðîêà
4692 g_Game_SetupScreenSize();
4694 // Ðåæèì íàáëþäàòåëÿ:
4695 if nPlayers = 0 then
4696 begin
4697 gPlayer1 := nil;
4698 gPlayer2 := nil;
4699 end;
4701 if nPlayers >= 1 then
4702 begin
4703 // Ñîçäàíèå ïåðâîãî èãðîêà:
4704 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
4705 gPlayer1Settings.Color,
4706 gPlayer1Settings.Team, False));
4707 if gPlayer1 = nil then
4708 begin
4709 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]));
4710 Exit;
4711 end;
4713 gPlayer1.Name := gPlayer1Settings.Name;
4714 gPlayer1.WeapSwitchMode := gPlayer1Settings.WeaponSwitch;
4715 gPlayer1.setWeaponPrefs(gPlayer1Settings.WeaponPreferences);
4716 gPlayer1.SwitchToEmpty := gPlayer1Settings.SwitchToEmpty;
4717 end;
4719 if nPlayers >= 2 then
4720 begin
4721 // Ñîçäàíèå âòîðîãî èãðîêà:
4722 gPlayer2 := g_Player_Get(g_Player_Create(gPlayer2Settings.Model,
4723 gPlayer2Settings.Color,
4724 gPlayer2Settings.Team, False));
4725 if gPlayer2 = nil then
4726 begin
4727 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [2]));
4728 Exit;
4729 end;
4731 gPlayer2.Name := gPlayer2Settings.Name;
4732 gPlayer2.WeapSwitchMode := gPlayer2Settings.WeaponSwitch;
4733 gPlayer2.setWeaponPrefs(gPlayer2Settings.WeaponPreferences);
4734 gPlayer2.SwitchToEmpty := gPlayer2Settings.SwitchToEmpty;
4735 end;
4737 g_Game_SetLoadingText(_lc[I_LOAD_HOST], 0, False);
4738 if NetForwardPorts then
4739 g_Game_SetLoadingText(_lc[I_LOAD_PORTS], 0, False);
4741 // Ñòàðòóåì ñåðâåð
4742 if not g_Net_Host(IPAddr, Port, NetMaxClients) then
4743 begin
4744 g_FatalError(_lc[I_NET_MSG] + Format(_lc[I_NET_ERR_HOST], [Port]));
4745 Exit;
4746 end;
4748 g_Net_Slist_Set(NetMasterList);
4750 g_Net_Slist_ServerStarted();
4752 // Çàãðóçêà è çàïóñê êàðòû:
4753 if not g_Game_StartMap(false{asMegawad}, Map, True) then
4754 begin
4755 g_Net_Slist_ServerClosed();
4756 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [Map]));
4757 Exit;
4758 end;
4760 // Íåò òî÷åê ïîÿâëåíèÿ:
4761 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1) +
4762 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2) +
4763 g_Map_GetPointCount(RESPAWNPOINT_DM) +
4764 g_Map_GetPointCount(RESPAWNPOINT_RED)+
4765 g_Map_GetPointCount(RESPAWNPOINT_BLUE)) < 1 then
4766 begin
4767 g_Net_Slist_ServerClosed();
4768 g_FatalError(_lc[I_GAME_ERROR_GET_SPAWN]);
4769 Exit;
4770 end;
4772 // Íàñòðîéêè èãðîêîâ è áîòîâ:
4773 g_Player_Init();
4775 g_Net_Slist_ServerMapStarted();
4776 NetState := NET_STATE_GAME;
4777 end;
4779 procedure g_Game_StartClient(Addr: String; Port: Word; PW: String);
4780 var
4781 Map: String;
4782 WadName: string;
4783 Ptr: Pointer;
4784 T: Cardinal;
4785 MID: Byte;
4786 State: Byte;
4787 OuterLoop: Boolean;
4788 newResPath: string;
4789 InMsg: TMsg;
4790 begin
4791 g_Game_Free();
4793 State := 0;
4794 e_WriteLog('Starting net game (client)...', TMsgType.Notify);
4795 e_WriteLog('NET: Trying to connect to ' + Addr + ':' + IntToStr(Port) + '...', TMsgType.Notify);
4797 g_Game_ClearLoading();
4799 // Íàñòðîéêè èãðû:
4800 gGameSettings.GameType := GT_CLIENT;
4802 gCoopTotalMonstersKilled := 0;
4803 gCoopTotalSecretsFound := 0;
4804 gCoopTotalMonsters := 0;
4805 gCoopTotalSecrets := 0;
4806 gAimLine := False;
4807 gShowMap := False;
4809 g_Game_ExecuteEvent('ongamestart');
4811 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
4812 g_Game_SetupScreenSize();
4814 NetState := NET_STATE_AUTH;
4816 g_Game_SetLoadingText(_lc[I_LOAD_CONNECT], 0, False);
4818 // create (or update) map/resource databases
4819 g_Res_CreateDatabases(true);
4821 gLMSRespawn := LMS_RESPAWN_NONE;
4822 gLMSRespawnTime := 0;
4823 gSpectLatchPID1 := 0;
4824 gSpectLatchPID2 := 0;
4826 // Ñòàðòóåì êëèåíò
4827 if not g_Net_Connect(Addr, Port) then
4828 begin
4829 g_FatalError(_lc[I_NET_MSG] + _lc[I_NET_ERR_CONN]);
4830 NetState := NET_STATE_NONE;
4831 Exit;
4832 end;
4834 g_Game_SetLoadingText(_lc[I_LOAD_SEND_INFO], 0, False);
4835 MC_SEND_Info(PW);
4836 g_Game_SetLoadingText(_lc[I_LOAD_WAIT_INFO], 0, False);
4838 OuterLoop := True;
4839 while OuterLoop do
4840 begin
4841 // fuck! https://www.mail-archive.com/enet-discuss@cubik.org/msg00852.html
4842 // tl;dr: on shitdows, we can get -1 sometimes, and it is *NOT* a failure.
4843 // thank you, enet. let's ignore failures altogether then.
4844 while (enet_host_service(NetHost, @NetEvent, 50) > 0) do
4845 begin
4846 if (NetEvent.kind = ENET_EVENT_TYPE_RECEIVE) then
4847 begin
4848 if (NetEvent.channelID = NET_CHAN_DOWNLOAD_EX) then
4849 begin
4850 // ignore all download packets, they're processed by separate code
4851 enet_packet_destroy(NetEvent.packet);
4852 continue;
4853 end;
4854 Ptr := NetEvent.packet^.data;
4855 if not InMsg.Init(Ptr, NetEvent.packet^.dataLength, True) then
4856 begin
4857 enet_packet_destroy(NetEvent.packet);
4858 continue;
4859 end;
4861 InMsg.ReadLongWord(); // skip size
4862 MID := InMsg.ReadByte();
4864 if (MID = NET_MSG_INFO) and (State = 0) then
4865 begin
4866 NetMyID := InMsg.ReadByte();
4867 NetPlrUID1 := InMsg.ReadWord();
4869 WadName := InMsg.ReadString();
4870 Map := InMsg.ReadString();
4872 gWADHash := InMsg.ReadMD5();
4874 gGameSettings.GameMode := InMsg.ReadByte();
4875 gSwitchGameMode := gGameSettings.GameMode;
4876 gGameSettings.GoalLimit := InMsg.ReadWord();
4877 gGameSettings.TimeLimit := InMsg.ReadWord();
4878 gGameSettings.MaxLives := InMsg.ReadByte();
4879 gGameSettings.Options := InMsg.ReadLongWord();
4880 T := InMsg.ReadLongWord();
4882 //newResPath := g_Res_SearchSameWAD(MapsDir, WadName, gWADHash);
4883 //if newResPath = '' then
4884 begin
4885 //g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
4886 newResPath := g_Res_DownloadMapWAD(ExtractFileName(WadName), gWADHash);
4887 if newResPath = '' then
4888 begin
4889 g_FatalError(_lc[I_NET_ERR_HASH]);
4890 enet_packet_destroy(NetEvent.packet);
4891 NetState := NET_STATE_NONE;
4892 Exit;
4893 end;
4894 e_LogWritefln('using downloaded map wad [%s] for [%s]`', [newResPath, WadName], TMsgType.Notify);
4895 end;
4896 //newResPath := ExtractRelativePath(MapsDir, newResPath);
4899 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
4900 gPlayer1Settings.Color,
4901 gPlayer1Settings.Team, False));
4903 if gPlayer1 = nil then
4904 begin
4905 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]));
4907 enet_packet_destroy(NetEvent.packet);
4908 NetState := NET_STATE_NONE;
4909 Exit;
4910 end;
4912 gPlayer1.Name := gPlayer1Settings.Name;
4913 gPlayer1.WeapSwitchMode := gPlayer1Settings.WeaponSwitch;
4914 gPlayer1.setWeaponPrefs(gPlayer1Settings.WeaponPreferences);
4915 gPlayer1.SwitchToEmpty := gPlayer1Settings.SwitchToEmpty;
4916 gPlayer1.UID := NetPlrUID1;
4917 gPlayer1.Reset(True);
4919 if not g_Game_StartMap(false{asMegawad}, newResPath + ':\' + Map, True) then
4920 begin
4921 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [WadName + ':\' + Map]));
4923 enet_packet_destroy(NetEvent.packet);
4924 NetState := NET_STATE_NONE;
4925 Exit;
4926 end;
4928 gTime := T;
4930 State := 1;
4931 OuterLoop := False;
4932 enet_packet_destroy(NetEvent.packet);
4933 break;
4934 end
4935 else
4936 enet_packet_destroy(NetEvent.packet);
4937 end
4938 else
4939 begin
4940 if (NetEvent.kind = ENET_EVENT_TYPE_DISCONNECT) then
4941 begin
4942 State := 0;
4943 if (NetEvent.data <= NET_DISC_MAX) then
4944 g_Console_Add(_lc[I_NET_MSG_ERROR] + _lc[I_NET_ERR_CONN] + ' ' +
4945 _lc[TStrings_Locale(Cardinal(I_NET_DISC_NONE) + NetEvent.data)], True);
4946 OuterLoop := False;
4947 Break;
4948 end;
4949 end;
4950 end;
4952 ProcessLoading(true);
4954 if g_Net_UserRequestExit() then
4955 begin
4956 State := 0;
4957 break;
4958 end;
4959 end;
4961 if State <> 1 then
4962 begin
4963 g_FatalError(_lc[I_NET_MSG] + _lc[I_NET_ERR_CONN]);
4964 NetState := NET_STATE_NONE;
4965 Exit;
4966 end;
4968 g_Player_Init();
4969 NetState := NET_STATE_GAME;
4970 MC_SEND_FullStateRequest;
4971 e_WriteLog('NET: Connection successful.', TMsgType.Notify);
4972 end;
4974 var
4975 lastAsMegaWad: Boolean = false;
4977 procedure g_Game_ChangeMap(const MapPath: String);
4978 var
4979 Force: Boolean;
4980 begin
4981 g_Game_ClearLoading();
4983 Force := gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF];
4984 // Åñëè óðîâåíü çàâåðøèëñÿ ïî òðèããåðó Âûõîä, íå î÷èùàòü èíâåíòàðü
4985 if gExitByTrigger then
4986 begin
4987 Force := False;
4988 gExitByTrigger := False;
4989 end;
4990 if not g_Game_StartMap(lastAsMegaWad, MapPath, Force) then
4991 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [MapPath]));
4992 end;
4994 procedure g_Game_Restart();
4995 var
4996 Map: string;
4997 begin
4998 if g_Game_IsClient then
4999 Exit;
5000 map := g_ExtractFileName(gMapInfo.Map);
5001 e_LogWritefln('g_Game_Restart: map = "%s" gCurrentMapFileName = "%s"', [map, gCurrentMapFileName]);
5003 MessageTime := 0;
5004 gGameOn := False;
5005 g_Game_ClearLoading();
5006 g_Game_StartMap(lastAsMegaWad, Map, True, gCurrentMapFileName);
5007 end;
5009 function g_Game_StartMap (asMegawad: Boolean; Map: String; Force: Boolean = False; const oldMapPath: AnsiString=''): Boolean;
5010 var
5011 NewWAD, ResName: String;
5012 I: Integer;
5013 nws: AnsiString;
5014 begin
5015 g_Map_Free((Map <> gCurrentMapFileName) and (oldMapPath <> gCurrentMapFileName));
5016 g_Player_RemoveAllCorpses();
5018 if (not g_Game_IsClient) and
5019 (gSwitchGameMode <> gGameSettings.GameMode) and
5020 (gGameSettings.GameMode <> GM_SINGLE) then
5021 begin
5022 if gSwitchGameMode = GM_CTF then
5023 gGameSettings.MaxLives := 0;
5024 gGameSettings.GameMode := gSwitchGameMode;
5025 Force := True;
5026 end else
5027 gSwitchGameMode := gGameSettings.GameMode;
5029 g_Player_ResetTeams();
5031 lastAsMegaWad := asMegawad;
5032 if isWadPath(Map) then
5033 begin
5034 NewWAD := g_ExtractWadName(Map);
5035 ResName := g_ExtractFileName(Map);
5036 if g_Game_IsServer then
5037 begin
5038 nws := findDiskWad(NewWAD);
5039 //writeln('000: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
5040 if (asMegawad) then
5041 begin
5042 if (length(nws) = 0) then nws := e_FindWad(MegawadDirs, NewWAD);
5043 if (length(nws) = 0) then nws := e_FindWad(MapDirs, NewWAD);
5044 end
5045 else
5046 begin
5047 if (length(nws) = 0) then nws := e_FindWad(MapDirs, NewWAD);
5048 if (length(nws) = 0) then nws := e_FindWad(MegawadDirs, NewWAD);
5049 end;
5050 //if (length(nws) = 0) then nws := e_FindWad(MapDownloadDirs, NewWAD);
5051 //writeln('001: Map=[', Map, ']; nws=[', nws, ']; NewWAD=[', NewWAD, ']');
5052 //nws := NewWAD;
5053 if (length(nws) = 0) then
5054 begin
5055 ResName := ''; // failed
5056 end
5057 else
5058 begin
5059 NewWAD := nws;
5060 if (g_Game_IsNet) then gWADHash := MD5File(nws);
5061 //writeln('********: nws=', nws, ' : Map=', Map, ' : nw=', NewWAD, ' : resname=', ResName);
5062 g_Game_LoadWAD(NewWAD);
5063 end;
5064 end
5065 else
5066 begin
5067 // hash received in MC_RECV_GameEvent -> NET_EV_MAPSTART
5068 NewWAD := g_Game_ClientWAD(NewWAD, gWADHash);
5069 end;
5070 end
5071 else
5072 begin
5073 NewWAD := gGameSettings.WAD;
5074 ResName := Map;
5075 end;
5077 gTime := 0;
5079 //writeln('********: gsw=', gGameSettings.WAD, '; rn=', ResName);
5080 result := false;
5081 if (ResName <> '') and (NewWAD <> '') then
5082 begin
5083 //result := g_Map_Load(gGameSettings.WAD + ':\' + ResName);
5084 result := g_Map_Load(NewWAD+':\'+ResName);
5085 end;
5086 if Result then
5087 begin
5088 g_Player_ResetAll(Force or gLastMap, gGameSettings.GameType = GT_SINGLE);
5090 gState := STATE_NONE;
5091 g_ActiveWindow := nil;
5092 gGameOn := True;
5094 DisableCheats();
5095 ResetTimer();
5097 if gGameSettings.GameMode = GM_CTF then
5098 begin
5099 g_Map_ResetFlag(FLAG_RED);
5100 g_Map_ResetFlag(FLAG_BLUE);
5101 // CTF, à ôëàãîâ íåò:
5102 if not g_Map_HaveFlagPoints() then
5103 g_SimpleError(_lc[I_GAME_ERROR_CTF]);
5104 end;
5105 end
5106 else
5107 begin
5108 gState := STATE_MENU;
5109 gGameOn := False;
5110 end;
5112 gExit := 0;
5113 gPauseMain := false;
5114 gPauseHolmes := false;
5115 NetTimeToUpdate := 1;
5116 NetTimeToReliable := 0;
5117 NetTimeToMaster := NetMasterRate;
5118 gSpectLatchPID1 := 0;
5119 gSpectLatchPID2 := 0;
5120 gMissionFailed := False;
5121 gNextMap := '';
5123 gCoopMonstersKilled := 0;
5124 gCoopSecretsFound := 0;
5126 gVoteInProgress := False;
5127 gVotePassed := False;
5128 gVoteCount := 0;
5129 gVoted := False;
5131 gStatsOff := False;
5133 if not gGameOn then Exit;
5135 g_Game_SpectateCenterView();
5137 if g_Game_IsServer then
5138 begin
5139 if (gGameSettings.MaxLives > 0) and (gGameSettings.WarmupTime > 0) then
5140 begin
5141 gLMSRespawn := LMS_RESPAWN_WARMUP;
5142 gLMSRespawnTime := gTime + gGameSettings.WarmupTime*1000;
5143 gLMSSoftSpawn := True;
5144 if g_Game_IsNet then
5145 MH_SEND_GameEvent(NET_EV_LMS_WARMUP, gLMSRespawnTime - gTime);
5146 end
5147 else
5148 begin
5149 gLMSRespawn := LMS_RESPAWN_NONE;
5150 gLMSRespawnTime := 0;
5151 end;
5152 end;
5154 if NetMode = NET_SERVER then
5155 begin
5156 MH_SEND_GameEvent(NET_EV_MAPSTART, gGameSettings.GameMode, Map);
5158 // Ìàñòåðñåðâåð
5159 g_Net_Slist_ServerMapStarted();
5161 if NetClients <> nil then
5162 for I := 0 to High(NetClients) do
5163 if NetClients[I].Used then
5164 begin
5165 NetClients[I].Voted := False;
5166 if NetClients[I].RequestedFullUpdate then
5167 begin
5168 MH_SEND_Everything((NetClients[I].State = NET_STATE_AUTH), I);
5169 NetClients[I].RequestedFullUpdate := False;
5170 end;
5171 end;
5173 g_Net_UnbanNonPermHosts();
5174 end;
5176 if gLastMap then
5177 begin
5178 gCoopTotalMonstersKilled := 0;
5179 gCoopTotalSecretsFound := 0;
5180 gCoopTotalMonsters := 0;
5181 gCoopTotalSecrets := 0;
5182 gLastMap := False;
5183 end;
5185 g_Game_ExecuteEvent('onmapstart');
5186 end;
5188 procedure SetFirstLevel;
5189 begin
5190 gNextMap := '';
5192 MapList := g_Map_GetMapsList(gGameSettings.WAD);
5193 if MapList = nil then
5194 Exit;
5196 SortSArray(MapList);
5197 gNextMap := MapList[Low(MapList)];
5199 MapList := nil;
5200 end;
5202 procedure g_Game_ExitLevel(const Map: AnsiString);
5203 begin
5204 gNextMap := Map;
5206 gCoopTotalMonstersKilled := gCoopTotalMonstersKilled + gCoopMonstersKilled;
5207 gCoopTotalSecretsFound := gCoopTotalSecretsFound + gCoopSecretsFound;
5208 gCoopTotalMonsters := gCoopTotalMonsters + gTotalMonsters;
5209 gCoopTotalSecrets := gCoopTotalSecrets + gSecretsCount;
5211 // Âûøëè â âûõîä â Îäèíî÷íîé èãðå:
5212 if gGameSettings.GameType = GT_SINGLE then
5213 gExit := EXIT_ENDLEVELSINGLE
5214 else // Âûøëè â âûõîä â Ñâîåé èãðå
5215 begin
5216 gExit := EXIT_ENDLEVELCUSTOM;
5217 if gGameSettings.GameMode = GM_COOP then
5218 g_Player_RememberAll;
5220 if not g_Map_Exist(gGameSettings.WAD + ':\' + gNextMap) then
5221 begin
5222 gLastMap := True;
5223 if gGameSettings.GameMode = GM_COOP then
5224 gStatsOff := True;
5226 gStatsPressed := True;
5227 gNextMap := 'MAP01';
5229 if not g_Map_Exist(gGameSettings.WAD + ':\' + gNextMap) then
5230 g_Game_NextLevel;
5232 if g_Game_IsNet then
5233 begin
5234 MH_SEND_GameStats();
5235 MH_SEND_CoopStats();
5236 end;
5237 end;
5238 end;
5239 end;
5241 procedure g_Game_RestartLevel();
5242 var
5243 Map: string;
5244 begin
5245 if gGameSettings.GameMode = GM_SINGLE then
5246 begin
5247 g_Game_Restart();
5248 Exit;
5249 end;
5250 gExit := EXIT_ENDLEVELCUSTOM;
5251 Map := g_ExtractFileName(gMapInfo.Map);
5252 gNextMap := Map;
5253 end;
5255 function g_Game_ClientWAD (NewWAD: String; const WHash: TMD5Digest): AnsiString;
5256 var
5257 gWAD{, xwad}: String;
5258 begin
5259 result := NewWAD;
5260 if not g_Game_IsClient then Exit;
5261 //e_LogWritefln('*** g_Game_ClientWAD: `%s`', [NewWAD]);
5263 gWAD := g_Res_DownloadMapWAD(ExtractFileName(NewWAD), WHash);
5264 if gWAD = '' then
5265 begin
5266 result := '';
5267 g_Game_Free();
5268 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_WAD], [ExtractFileName(NewWAD)]));
5269 Exit;
5270 end;
5272 e_LogWritefln('using downloaded client map wad [%s] for [%s]', [gWAD, NewWAD], TMsgType.Notify);
5273 NewWAD := gWAD;
5275 g_Game_LoadWAD(NewWAD);
5276 result := NewWAD;
5279 if LowerCase(NewWAD) = LowerCase(gGameSettings.WAD) then Exit;
5280 gWAD := g_Res_SearchSameWAD(MapsDir, ExtractFileName(NewWAD), WHash);
5281 if gWAD = '' then
5282 begin
5283 g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
5284 gWAD := g_Res_DownloadMapWAD(ExtractFileName(NewWAD), WHash);
5285 if gWAD = '' then
5286 begin
5287 g_Game_Free();
5288 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_WAD], [ExtractFileName(NewWAD)]));
5289 Exit;
5290 end;
5291 end;
5292 NewWAD := ExtractRelativePath(MapsDir, gWAD);
5293 g_Game_LoadWAD(NewWAD);
5295 end;
5297 procedure g_Game_RestartRound(NoMapRestart: Boolean = False);
5298 var
5299 i, n, nb, nr: Integer;
5300 begin
5301 if not g_Game_IsServer then Exit;
5302 if gLMSRespawn = LMS_RESPAWN_NONE then Exit;
5303 gLMSRespawn := LMS_RESPAWN_NONE;
5304 gLMSRespawnTime := 0;
5305 MessageTime := 0;
5307 if (gGameSettings.GameMode = GM_COOP) and not NoMapRestart then
5308 begin
5309 gMissionFailed := True;
5310 g_Game_RestartLevel;
5311 Exit;
5312 end;
5314 n := 0; nb := 0; nr := 0;
5315 for i := Low(gPlayers) to High(gPlayers) do
5316 if (gPlayers[i] <> nil) and
5317 ((not gPlayers[i].FSpectator) or gPlayers[i].FWantsInGame or
5318 (gPlayers[i] is TBot)) then
5319 begin
5320 Inc(n);
5321 if gPlayers[i].Team = TEAM_RED then Inc(nr)
5322 else if gPlayers[i].Team = TEAM_BLUE then Inc(nb)
5323 end;
5325 if (n < 1) or ((gGameSettings.GameMode = GM_TDM) and ((nr = 0) or (nb = 0))) then
5326 begin
5327 // wait a second until the fuckers finally decide to join
5328 gLMSRespawn := LMS_RESPAWN_WARMUP;
5329 gLMSRespawnTime := gTime + gGameSettings.WarmupTime*1000;
5330 gLMSSoftSpawn := NoMapRestart;
5331 if g_Game_IsNet then
5332 MH_SEND_GameEvent(NET_EV_LMS_WARMUP, gLMSRespawnTime - gTime);
5333 Exit;
5334 end;
5336 g_Player_RemoveAllCorpses;
5337 g_Game_Message(_lc[I_MESSAGE_LMS_START], 144);
5338 if g_Game_IsNet then
5339 MH_SEND_GameEvent(NET_EV_LMS_START);
5341 for i := Low(gPlayers) to High(gPlayers) do
5342 begin
5343 if gPlayers[i] = nil then continue;
5344 if gPlayers[i] is TBot then gPlayers[i].FWantsInGame := True;
5345 // don't touch normal spectators
5346 if gPlayers[i].FSpectator and not gPlayers[i].FWantsInGame then
5347 begin
5348 gPlayers[i].FNoRespawn := True;
5349 gPlayers[i].Lives := 0;
5350 if g_Game_IsNet then
5351 MH_SEND_PlayerStats(gPlayers[I].UID);
5352 continue;
5353 end;
5354 gPlayers[i].FNoRespawn := False;
5355 gPlayers[i].Lives := gGameSettings.MaxLives;
5356 gPlayers[i].Respawn(False, True);
5357 if gGameSettings.GameMode = GM_COOP then
5358 begin
5359 gPlayers[i].Frags := 0;
5360 gPlayers[i].RecallState;
5361 end;
5362 if (gPlayer1 = nil) and (gSpectLatchPID1 > 0) then
5363 gPlayer1 := g_Player_Get(gSpectLatchPID1);
5364 if (gPlayer2 = nil) and (gSpectLatchPID2 > 0) then
5365 gPlayer2 := g_Player_Get(gSpectLatchPID2);
5366 end;
5368 g_Items_RestartRound();
5370 gLMSSoftSpawn := False;
5371 end;
5373 function g_Game_GetFirstMap(WAD: String): String;
5374 begin
5375 Result := '';
5377 MapList := g_Map_GetMapsList(WAD);
5378 if MapList = nil then
5379 Exit;
5381 SortSArray(MapList);
5382 Result := MapList[Low(MapList)];
5384 if not g_Map_Exist(WAD + ':\' + Result) then
5385 Result := '';
5387 MapList := nil;
5388 end;
5390 function g_Game_GetNextMap(): String;
5391 var
5392 I: Integer;
5393 Map: string;
5394 begin
5395 Result := '';
5397 MapList := g_Map_GetMapsList(gGameSettings.WAD);
5398 if MapList = nil then
5399 Exit;
5401 Map := g_ExtractFileName(gMapInfo.Map);
5403 SortSArray(MapList);
5404 MapIndex := -255;
5405 for I := Low(MapList) to High(MapList) do
5406 if Map = MapList[I] then
5407 begin
5408 MapIndex := I;
5409 Break;
5410 end;
5412 if MapIndex <> -255 then
5413 begin
5414 if MapIndex = High(MapList) then
5415 Result := MapList[Low(MapList)]
5416 else
5417 Result := MapList[MapIndex + 1];
5419 if not g_Map_Exist(gGameSettings.WAD + ':\' + Result) then Result := Map;
5420 end;
5422 MapList := nil;
5423 end;
5425 procedure g_Game_NextLevel();
5426 begin
5427 if gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF, GM_COOP] then
5428 gExit := EXIT_ENDLEVELCUSTOM
5429 else
5430 begin
5431 gExit := EXIT_ENDLEVELSINGLE;
5432 Exit;
5433 end;
5435 if gNextMap <> '' then Exit;
5436 gNextMap := g_Game_GetNextMap();
5437 end;
5439 function g_Game_IsTestMap(): Boolean;
5440 begin
5441 result := StrEquCI1251(TEST_MAP_NAME, g_ExtractFileName(gMapInfo.Map));
5442 end;
5444 procedure g_Game_DeleteTestMap();
5445 var
5446 a: Integer;
5447 //MapName: AnsiString;
5448 WadName: string;
5450 WAD: TWADFile;
5451 MapList: SSArray;
5452 time: Integer;
5454 begin
5455 a := Pos('.wad:\', toLowerCase1251(gMapToDelete));
5456 if (a = 0) then a := Pos('.wad:/', toLowerCase1251(gMapToDelete));
5457 if (a = 0) then exit;
5459 // Âûäåëÿåì èìÿ wad-ôàéëà è èìÿ êàðòû
5460 WadName := Copy(gMapToDelete, 1, a+3);
5461 Delete(gMapToDelete, 1, a+5);
5462 gMapToDelete := UpperCase(gMapToDelete);
5463 //MapName := '';
5464 //CopyMemory(@MapName[0], @gMapToDelete[1], Min(16, Length(gMapToDelete)));
5467 // Èìÿ êàðòû íå ñòàíäàðòíîå òåñòîâîå:
5468 if MapName <> TEST_MAP_NAME then
5469 Exit;
5471 if not gTempDelete then
5472 begin
5473 time := g_GetFileTime(WadName);
5474 WAD := TWADFile.Create();
5476 // ×èòàåì Wad-ôàéë:
5477 if not WAD.ReadFile(WadName) then
5478 begin // Íåò òàêîãî WAD-ôàéëà
5479 WAD.Free();
5480 Exit;
5481 end;
5483 // Ñîñòàâëÿåì ñïèñîê êàðò è èùåì íóæíóþ:
5484 WAD.CreateImage();
5485 MapList := WAD.GetResourcesList('');
5487 if MapList <> nil then
5488 for a := 0 to High(MapList) do
5489 if MapList[a] = MapName then
5490 begin
5491 // Óäàëÿåì è ñîõðàíÿåì:
5492 WAD.RemoveResource('', MapName);
5493 WAD.SaveTo(WadName);
5494 Break;
5495 end;
5497 WAD.Free();
5498 g_SetFileTime(WadName, time);
5499 end else
5501 if gTempDelete then DeleteFile(WadName);
5502 end;
5504 procedure GameCVars(P: SSArray);
5505 var
5506 a, b: Integer;
5507 stat: TPlayerStatArray;
5508 cmd: string;
5510 procedure ParseGameFlag(Flag: LongWord; OffMsg, OnMsg: TStrings_Locale; OnMapChange: Boolean = False);
5511 var
5512 x: Boolean;
5513 begin
5514 if Length(P) > 1 then
5515 begin
5516 x := P[1] = '1';
5518 if x then
5519 gsGameFlags := gsGameFlags or Flag
5520 else
5521 gsGameFlags := gsGameFlags and (not Flag);
5523 if g_Game_IsServer then
5524 begin
5525 if x then
5526 gGameSettings.Options := gGameSettings.Options or Flag
5527 else
5528 gGameSettings.Options := gGameSettings.Options and (not Flag);
5529 if g_Game_IsNet then MH_SEND_GameSettings;
5530 end;
5531 end;
5533 if LongBool(gsGameFlags and Flag) then
5534 g_Console_Add(_lc[OnMsg])
5535 else
5536 g_Console_Add(_lc[OffMsg]);
5538 if OnMapChange and g_Game_IsServer then
5539 g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
5540 end;
5542 begin
5543 stat := nil;
5544 cmd := LowerCase(P[0]);
5546 if cmd = 'g_gamemode' then
5547 begin
5548 if (Length(P) > 1) then
5549 begin
5550 a := g_Game_TextToMode(P[1]);
5551 if a = GM_SINGLE then a := GM_COOP;
5552 gsGameMode := g_Game_ModeToText(a);
5553 if g_Game_IsServer then
5554 begin
5555 gSwitchGameMode := a;
5556 if (gGameOn and (gGameSettings.GameMode = GM_SINGLE)) or
5557 (gState = STATE_INTERSINGLE) then
5558 gSwitchGameMode := GM_SINGLE;
5559 if not gGameOn then
5560 gGameSettings.GameMode := gSwitchGameMode;
5561 end;
5562 end;
5564 if gSwitchGameMode = gGameSettings.GameMode then
5565 g_Console_Add(Format(_lc[I_MSG_GAMEMODE_CURRENT],
5566 [g_Game_ModeToText(gGameSettings.GameMode)]))
5567 else
5568 g_Console_Add(Format(_lc[I_MSG_GAMEMODE_CHANGE],
5569 [g_Game_ModeToText(gGameSettings.GameMode),
5570 g_Game_ModeToText(gSwitchGameMode)]));
5571 end
5572 else if cmd = 'g_friendlyfire' then
5573 begin
5574 ParseGameFlag(GAME_OPTION_TEAMDAMAGE, I_MSG_FRIENDLY_FIRE_OFF, I_MSG_FRIENDLY_FIRE_ON);
5575 end
5576 else if cmd = 'g_friendly_absorb_damage' then
5577 begin
5578 ParseGameFlag(GAME_OPTION_TEAMABSORBDAMAGE, I_MSG_FRIENDLY_ABSORB_DAMAGE_OFF, I_MSG_FRIENDLY_ABSORB_DAMAGE_ON);
5579 end
5580 else if cmd = 'g_friendly_hit_trace' then
5581 begin
5582 ParseGameFlag(GAME_OPTION_TEAMHITTRACE, I_MSG_FRIENDLY_HIT_TRACE_OFF, I_MSG_FRIENDLY_HIT_TRACE_ON);
5583 end
5584 else if cmd = 'g_friendly_hit_projectile' then
5585 begin
5586 ParseGameFlag(GAME_OPTION_TEAMHITPROJECTILE, I_MSG_FRIENDLY_PROJECT_TRACE_OFF, I_MSG_FRIENDLY_PROJECT_TRACE_ON);
5587 end
5588 else if cmd = 'g_weaponstay' then
5589 begin
5590 ParseGameFlag(GAME_OPTION_WEAPONSTAY, I_MSG_WEAPONSTAY_OFF, I_MSG_WEAPONSTAY_ON);
5591 end
5592 else if cmd = 'g_allow_exit' then
5593 begin
5594 ParseGameFlag(GAME_OPTION_ALLOWEXIT, I_MSG_ALLOWEXIT_OFF, I_MSG_ALLOWEXIT_ON, True);
5595 end
5596 else if cmd = 'g_allow_monsters' then
5597 begin
5598 ParseGameFlag(GAME_OPTION_MONSTERS, I_MSG_ALLOWMON_OFF, I_MSG_ALLOWMON_ON, True);
5599 end
5600 else if cmd = 'g_allow_dropflag' then
5601 begin
5602 ParseGameFlag(GAME_OPTION_ALLOWDROPFLAG, I_MSG_ALLOWDROPFLAG_OFF, I_MSG_ALLOWDROPFLAG_ON);
5603 end
5604 else if cmd = 'g_throw_flag' then
5605 begin
5606 ParseGameFlag(GAME_OPTION_THROWFLAG, I_MSG_THROWFLAG_OFF, I_MSG_THROWFLAG_ON);
5607 end
5608 else if cmd = 'g_bot_vsplayers' then
5609 begin
5610 ParseGameFlag(GAME_OPTION_BOTVSPLAYER, I_MSG_BOTSVSPLAYERS_OFF, I_MSG_BOTSVSPLAYERS_ON);
5611 end
5612 else if cmd = 'g_bot_vsmonsters' then
5613 begin
5614 ParseGameFlag(GAME_OPTION_BOTVSMONSTER, I_MSG_BOTSVSMONSTERS_OFF, I_MSG_BOTSVSMONSTERS_ON);
5615 end
5616 else if cmd = 'g_dm_keys' then
5617 begin
5618 ParseGameFlag(GAME_OPTION_DMKEYS, I_MSG_DMKEYS_OFF, I_MSG_DMKEYS_ON, True);
5619 end
5620 else if cmd = 'g_gameflags' then
5621 begin
5622 if Length(P) > 1 then
5623 begin
5624 gsGameFlags := StrToDWordDef(P[1], gsGameFlags);
5625 if g_Game_IsServer then
5626 begin
5627 gGameSettings.Options := gsGameFlags;
5628 if g_Game_IsNet then MH_SEND_GameSettings;
5629 end;
5630 end;
5632 g_Console_Add(Format('%s %u', [cmd, gsGameFlags]));
5633 end
5634 else if cmd = 'g_warmup_time' then
5635 begin
5636 if Length(P) > 1 then
5637 begin
5638 gsWarmupTime := nclamp(StrToIntDef(P[1], gsWarmupTime), 0, $FFFF);
5639 if g_Game_IsServer then
5640 begin
5641 gGameSettings.WarmupTime := gsWarmupTime;
5642 // extend warmup if it's already going
5643 if gLMSRespawn = LMS_RESPAWN_WARMUP then
5644 begin
5645 gLMSRespawnTime := gTime + gsWarmupTime * 1000;
5646 if g_Game_IsNet then MH_SEND_GameEvent(NET_EV_LMS_WARMUP, gLMSRespawnTime - gTime);
5647 end;
5648 if g_Game_IsNet then MH_SEND_GameSettings;
5649 end;
5650 end;
5652 g_Console_Add(Format(_lc[I_MSG_WARMUP], [Integer(gsWarmupTime)]));
5653 if g_Game_IsServer then g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
5654 end
5655 else if cmd = 'g_spawn_invul' then
5656 begin
5657 if Length(P) > 1 then
5658 begin
5659 gsSpawnInvul := nclamp(StrToIntDef(P[1], gsSpawnInvul), 0, $FFFF);
5660 if g_Game_IsServer then
5661 begin
5662 gGameSettings.SpawnInvul := gsSpawnInvul;
5663 if g_Game_IsNet then MH_SEND_GameSettings;
5664 end;
5665 end;
5667 g_Console_Add(Format('%s %d', [cmd, Integer(gsSpawnInvul)]));
5668 end
5669 else if cmd = 'g_item_respawn_time' then
5670 begin
5671 if Length(P) > 1 then
5672 begin
5673 gsItemRespawnTime := nclamp(StrToIntDef(P[1], gsItemRespawnTime), 0, $FFFF);
5674 if g_Game_IsServer then
5675 begin
5676 gGameSettings.ItemRespawnTime := gsItemRespawnTime;
5677 if g_Game_IsNet then MH_SEND_GameSettings;
5678 end;
5679 end;
5681 g_Console_Add(Format('%s %d', [cmd, Integer(gsItemRespawnTime)]));
5682 if g_Game_IsServer then g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
5683 end
5684 else if cmd = 'sv_intertime' then
5685 begin
5686 if (Length(P) > 1) then
5687 gDefInterTime := Min(Max(StrToIntDef(P[1], gDefInterTime), -1), 120);
5689 g_Console_Add(cmd + ' = ' + IntToStr(gDefInterTime));
5690 end
5691 else if cmd = 'g_max_particles' then
5692 begin
5693 if Length(p) = 2 then
5694 begin
5695 a := Max(0, StrToInt(p[1]));
5696 g_GFX_SetMax(a)
5697 end
5698 else if Length(p) = 1 then
5699 begin
5700 e_LogWritefln('%s', [g_GFX_GetMax()])
5701 end
5702 else
5703 begin
5704 e_LogWritefln('usage: %s <n>', [cmd])
5705 end
5706 end
5707 else if cmd = 'g_max_shells' then
5708 begin
5709 if Length(p) = 2 then
5710 begin
5711 a := Max(0, StrToInt(p[1]));
5712 g_Shells_SetMax(a)
5713 end
5714 else if Length(p) = 1 then
5715 begin
5716 e_LogWritefln('%s', [g_Shells_GetMax()])
5717 end
5718 else
5719 begin
5720 e_LogWritefln('usage: %s <n>', [cmd])
5721 end
5722 end
5723 else if cmd = 'g_max_gibs' then
5724 begin
5725 if Length(p) = 2 then
5726 begin
5727 a := Max(0, StrToInt(p[1]));
5728 g_Gibs_SetMax(a)
5729 end
5730 else if Length(p) = 1 then
5731 begin
5732 e_LogWritefln('%s', [g_Gibs_GetMax()])
5733 end
5734 else
5735 begin
5736 e_LogWritefln('usage: %s <n>', [cmd])
5737 end
5738 end
5739 else if cmd = 'g_max_corpses' then
5740 begin
5741 if Length(p) = 2 then
5742 begin
5743 a := Max(0, StrToInt(p[1]));
5744 g_Corpses_SetMax(a)
5745 end
5746 else if Length(p) = 1 then
5747 begin
5748 e_LogWritefln('%s', [g_Corpses_GetMax()])
5749 end
5750 else
5751 begin
5752 e_LogWritefln('usage: %s <n>', [cmd])
5753 end
5754 end
5755 else if cmd = 'g_scorelimit' then
5756 begin
5757 if Length(P) > 1 then
5758 begin
5759 gsGoalLimit := nclamp(StrToIntDef(P[1], gsGoalLimit), 0, $FFFF);
5761 if g_Game_IsServer then
5762 begin
5763 b := 0;
5764 if gGameSettings.GameMode = GM_DM then
5765 begin // DM
5766 stat := g_Player_GetStats();
5767 if stat <> nil then
5768 for a := 0 to High(stat) do
5769 if stat[a].Frags > b then
5770 b := stat[a].Frags;
5771 end
5772 else // TDM/CTF
5773 b := Max(gTeamStat[TEAM_RED].Goals, gTeamStat[TEAM_BLUE].Goals);
5775 // if someone has a higher score, set it to that instead
5776 gsGoalLimit := max(gsGoalLimit, b);
5777 gGameSettings.GoalLimit := gsGoalLimit;
5779 if g_Game_IsNet then MH_SEND_GameSettings;
5780 end;
5781 end;
5783 g_Console_Add(Format(_lc[I_MSG_SCORE_LIMIT], [Integer(gsGoalLimit)]));
5784 end
5785 else if cmd = 'g_timelimit' then
5786 begin
5787 if Length(P) > 1 then
5788 begin
5789 gsTimeLimit := nclamp(StrToIntDef(P[1], gsTimeLimit), 0, $FFFF);
5790 if g_Game_IsServer then
5791 begin
5792 gGameSettings.TimeLimit := gsTimeLimit;
5793 if g_Game_IsNet then MH_SEND_GameSettings;
5794 end;
5795 end;
5796 g_Console_Add(Format(_lc[I_MSG_TIME_LIMIT],
5797 [gsTimeLimit div 3600,
5798 (gsTimeLimit div 60) mod 60,
5799 gsTimeLimit mod 60]));
5800 end
5801 else if cmd = 'g_maxlives' then
5802 begin
5803 if Length(P) > 1 then
5804 begin
5805 gsMaxLives := nclamp(StrToIntDef(P[1], gsMaxLives), 0, $FFFF);
5806 if g_Game_IsServer then
5807 begin
5808 gGameSettings.MaxLives := gsMaxLives;
5809 if g_Game_IsNet then MH_SEND_GameSettings;
5810 end;
5811 end;
5813 g_Console_Add(Format(_lc[I_MSG_LIVES], [Integer(gsMaxLives)]));
5814 end;
5815 end;
5817 procedure PlayerSettingsCVars(P: SSArray);
5818 var
5819 cmd: string;
5820 team: Byte;
5822 function ParseTeam(s: string): Byte;
5823 begin
5824 result := 0;
5825 case s of
5826 'red', '1': result := TEAM_RED;
5827 'blue', '2': result := TEAM_BLUE;
5828 else result := TEAM_NONE;
5829 end;
5830 end;
5831 begin
5832 cmd := LowerCase(P[0]);
5833 case cmd of
5834 'p1_name':
5835 begin
5836 if (Length(P) > 1) then
5837 begin
5838 gPlayer1Settings.Name := b_Text_Unformat(P[1]);
5839 if g_Game_IsClient then
5840 MC_SEND_PlayerSettings
5841 else if gGameOn and (gPlayer1 <> nil) then
5842 begin
5843 gPlayer1.Name := b_Text_Unformat(P[1]);
5844 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer1.UID);
5845 end;
5846 end;
5847 end;
5848 'p2_name':
5849 begin
5850 if (Length(P) > 1) then
5851 begin
5852 gPlayer2Settings.Name := b_Text_Unformat(P[1]);
5853 if g_Game_IsClient then
5854 MC_SEND_PlayerSettings
5855 else if gGameOn and (gPlayer2 <> nil) then
5856 begin
5857 gPlayer2.Name := b_Text_Unformat(P[1]);
5858 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer2.UID);
5859 end;
5860 end;
5861 end;
5862 'p1_color':
5863 begin
5864 if Length(P) > 3 then
5865 begin
5866 gPlayer1Settings.Color := _RGB(EnsureRange(StrToIntDef(P[1], 0), 0, 255),
5867 EnsureRange(StrToIntDef(P[2], 0), 0, 255),
5868 EnsureRange(StrToIntDef(P[3], 0), 0, 255));
5869 if g_Game_IsClient then
5870 MC_SEND_PlayerSettings
5871 else if gGameOn and (gPlayer1 <> nil) then
5872 begin
5873 gPlayer1.SetColor(gPlayer1Settings.Color);
5874 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer1.UID);
5875 end;
5876 end;
5877 end;
5878 'p2_color':
5879 begin
5880 if Length(P) > 3 then
5881 begin
5882 gPlayer2Settings.Color := _RGB(EnsureRange(StrToIntDef(P[1], 0), 0, 255),
5883 EnsureRange(StrToIntDef(P[2], 0), 0, 255),
5884 EnsureRange(StrToIntDef(P[3], 0), 0, 255));
5885 if g_Game_IsClient then
5886 MC_SEND_PlayerSettings
5887 else if gGameOn and (gPlayer2 <> nil) then
5888 begin
5889 gPlayer2.SetColor(gPlayer2Settings.Color);
5890 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer2.UID);
5891 end;
5892 end;
5893 end;
5894 'p1_model':
5895 begin
5896 if (Length(P) > 1) then
5897 begin
5898 gPlayer1Settings.Model := P[1];
5899 if g_Game_IsClient then
5900 MC_SEND_PlayerSettings
5901 else if gGameOn and (gPlayer1 <> nil) then
5902 begin
5903 gPlayer1.FActualModelName := gPlayer1Settings.Model;
5904 gPlayer1.SetModel(gPlayer1Settings.Model);
5905 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer1.UID);
5906 end;
5907 end;
5908 end;
5909 'p2_model':
5910 begin
5911 if (Length(P) > 1) then
5912 begin
5913 gPlayer2Settings.Model := P[1];
5914 if g_Game_IsClient then
5915 MC_SEND_PlayerSettings
5916 else if gGameOn and (gPlayer2 <> nil) then
5917 begin
5918 gPlayer2.FActualModelName := gPlayer2Settings.Model;
5919 gPlayer2.SetModel(gPlayer2Settings.Model);
5920 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer2.UID);
5921 end;
5922 end;
5923 end;
5924 'p1_team':
5925 begin
5926 // TODO: switch teams if in game or store this separately
5927 if (Length(P) > 1) then
5928 begin
5929 team := ParseTeam(P[1]);
5930 if team = TEAM_NONE then
5931 g_Console_Add('expected ''red'', ''blue'', 1 or 2')
5932 else if not gGameOn and not g_Game_IsNet then
5933 gPlayer1Settings.Team := team
5934 else
5935 g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
5936 end;
5937 end;
5938 'p2_team':
5939 begin
5940 // TODO: switch teams if in game or store this separately
5941 if (Length(P) > 1) then
5942 begin
5943 team := ParseTeam(P[1]);
5944 if team = TEAM_NONE then
5945 g_Console_Add('expected ''red'', ''blue'', 1 or 2')
5946 else if not gGameOn and not g_Game_IsNet then
5947 gPlayer2Settings.Team := team
5948 else
5949 g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
5950 end;
5951 end;
5952 'p1_autoswitch':
5953 begin
5954 if (Length(P) = 2) then
5955 gPlayer1Settings.WeaponSwitch := EnsureRange(StrTointDef(P[1], 0), 0, 2);
5956 end;
5957 'p2_autoswitch':
5958 begin
5959 if (Length(P) = 2) then
5960 gPlayer2Settings.WeaponSwitch := EnsureRange(StrTointDef(P[1], 0), 0, 2);
5961 end;
5962 'p1_switch_empty':
5963 begin
5964 if (Length(P) = 2) then
5965 gPlayer1Settings.SwitchToEmpty := EnsureRange(StrTointDef(P[1], 0), 0, 1);
5966 end;
5967 'p2_switch_empty':
5968 begin
5969 if (Length(P) = 2) then
5970 gPlayer2Settings.SwitchToEmpty := EnsureRange(StrTointDef(P[1], 0), 0, 1);
5971 end;
5972 'p1_priority_kastet':
5973 begin
5974 if (Length(P) = 2) then
5975 gPlayer1Settings.WeaponPreferences[WEAPON_KASTET] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
5976 end;
5977 'p2_priority_kastet':
5978 begin
5979 if (Length(P) = 2) then
5980 gPlayer2Settings.WeaponPreferences[WEAPON_KASTET] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
5981 end;
5982 'p1_priority_saw':
5983 begin
5984 if (Length(P) = 2) then
5985 gPlayer1Settings.WeaponPreferences[WEAPON_SAW] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
5986 end;
5987 'p2_priority_saw':
5988 begin
5989 if (Length(P) = 2) then
5990 gPlayer2Settings.WeaponPreferences[WEAPON_SAW] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
5991 end;
5992 'p1_priority_pistol':
5993 begin
5994 if (Length(P) = 2) then
5995 gPlayer1Settings.WeaponPreferences[WEAPON_KASTET] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
5996 end;
5997 'p2_priority_pistol':
5998 begin
5999 if (Length(P) = 2) then
6000 gPlayer2Settings.WeaponPreferences[WEAPON_KASTET] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6001 end;
6002 'p1_priority_shotgun1':
6003 begin
6004 if (Length(P) = 2) then
6005 gPlayer1Settings.WeaponPreferences[WEAPON_SHOTGUN1] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6006 end;
6007 'p2_priority_shotgun1':
6008 begin
6009 if (Length(P) = 2) then
6010 gPlayer2Settings.WeaponPreferences[WEAPON_SHOTGUN1] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6011 end;
6012 'p1_priority_shotgun2':
6013 begin
6014 if (Length(P) = 2) then
6015 gPlayer1Settings.WeaponPreferences[WEAPON_SHOTGUN2] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6016 end;
6017 'p2_priority_shotgun2':
6018 begin
6019 if (Length(P) = 2) then
6020 gPlayer2Settings.WeaponPreferences[WEAPON_SHOTGUN2] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6021 end;
6022 'p1_priority_chaingun':
6023 begin
6024 if (Length(P) = 2) then
6025 gPlayer1Settings.WeaponPreferences[WEAPON_CHAINGUN] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6026 end;
6027 'p2_priority_chaingun':
6028 begin
6029 if (Length(P) = 2) then
6030 gPlayer2Settings.WeaponPreferences[WEAPON_CHAINGUN] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6031 end;
6032 'p1_priority_rocketlauncher':
6033 begin
6034 if (Length(P) = 2) then
6035 gPlayer1Settings.WeaponPreferences[WEAPON_ROCKETLAUNCHER] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6036 end;
6037 'p2_priority_rocketlauncher':
6038 begin
6039 if (Length(P) = 2) then
6040 gPlayer2Settings.WeaponPreferences[WEAPON_ROCKETLAUNCHER] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6041 end;
6042 'p1_priority_plasma':
6043 begin
6044 if (Length(P) = 2) then
6045 gPlayer1Settings.WeaponPreferences[WEAPON_PLASMA] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6046 end;
6047 'p2_priority_plasma':
6048 begin
6049 if (Length(P) = 2) then
6050 gPlayer2Settings.WeaponPreferences[WEAPON_PLASMA] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6051 end;
6052 'p1_priority_bfg':
6053 begin
6054 if (Length(P) = 2) then
6055 gPlayer1Settings.WeaponPreferences[WEAPON_BFG] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6056 end;
6057 'p2_priority_bfg':
6058 begin
6059 if (Length(P) = 2) then
6060 gPlayer2Settings.WeaponPreferences[WEAPON_BFG] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6061 end;
6062 'p1_priority_super':
6063 begin
6064 if (Length(P) = 2) then
6065 gPlayer1Settings.WeaponPreferences[WEAPON_SUPERPULEMET] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6066 end;
6067 'p2_priority_super':
6068 begin
6069 if (Length(P) = 2) then
6070 gPlayer2Settings.WeaponPreferences[WEAPON_SUPERPULEMET] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6071 end;
6072 'p1_priority_flamethrower':
6073 begin
6074 if (Length(P) = 2) then
6075 gPlayer1Settings.WeaponPreferences[WEAPON_FLAMETHROWER] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6076 end;
6077 'p2_priority_flamethrower':
6078 begin
6079 if (Length(P) = 2) then
6080 gPlayer2Settings.WeaponPreferences[WEAPON_FLAMETHROWER] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6081 end;
6082 'p1_priority_berserk':
6083 begin
6084 if (Length(P) = 2) then
6085 gPlayer1Settings.WeaponPreferences[WP_LAST+1] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6086 end;
6087 'p2_priority_berserk':
6088 begin
6089 if (Length(P) = 2) then
6090 gPlayer2Settings.WeaponPreferences[WP_LAST+1] := EnsureRange(StrToIntDef(P[1], WP_FIRST), WP_FIRST, WP_LAST+1);
6091 end;
6092 end;
6093 end;
6095 procedure PrintHeapStats();
6096 var
6097 hs: TFPCHeapStatus;
6098 begin
6099 hs := GetFPCHeapStatus();
6100 e_LogWriteLn ('v===== heap status =====v');
6101 e_LogWriteFln('max heap size = %d k', [hs.MaxHeapSize div 1024]);
6102 e_LogWriteFln('max heap used = %d k', [hs.MaxHeapUsed div 1024]);
6103 e_LogWriteFln('cur heap size = %d k', [hs.CurrHeapSize div 1024]);
6104 e_LogWriteFln('cur heap used = %d k', [hs.CurrHeapUsed div 1024]);
6105 e_LogWriteFln('cur heap free = %d k', [hs.CurrHeapFree div 1024]);
6106 e_LogWriteLn ('^=======================^');
6107 end;
6109 procedure DebugCommands(P: SSArray);
6110 var
6111 a, b: Integer;
6112 cmd: string;
6113 //pt: TDFPoint;
6114 mon: TMonster;
6115 begin
6116 // Êîìàíäû îòëàäî÷íîãî ðåæèìà:
6117 if {gDebugMode}conIsCheatsEnabled then
6118 begin
6119 cmd := LowerCase(P[0]);
6120 if cmd = 'd_window' then
6121 begin
6122 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth, gScreenHeight]));
6123 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth, gScreenHeight]));
6124 end
6125 else if cmd = 'd_sounds' then
6126 begin
6127 if (Length(P) > 1) and
6128 ((P[1] = '1') or (P[1] = '0')) then
6129 g_Debug_Sounds := (P[1][1] = '1');
6131 g_Console_Add(Format('d_sounds is %d', [Byte(g_Debug_Sounds)]));
6132 end
6133 else if cmd = 'd_frames' then
6134 begin
6135 if (Length(P) > 1) and
6136 ((P[1] = '1') or (P[1] = '0')) then
6137 g_Debug_Frames := (P[1][1] = '1');
6139 g_Console_Add(Format('d_frames is %d', [Byte(g_Debug_Frames)]));
6140 end
6141 else if cmd = 'd_winmsg' then
6142 begin
6143 if (Length(P) > 1) and
6144 ((P[1] = '1') or (P[1] = '0')) then
6145 g_Debug_WinMsgs := (P[1][1] = '1');
6147 g_Console_Add(Format('d_winmsg is %d', [Byte(g_Debug_WinMsgs)]));
6148 end
6149 else if (cmd = 'd_monoff') and not g_Game_IsNet then
6150 begin
6151 if (Length(P) > 1) and
6152 ((P[1] = '1') or (P[1] = '0')) then
6153 g_Debug_MonsterOff := (P[1][1] = '1');
6155 g_Console_Add(Format('d_monoff is %d', [Byte(g_debug_MonsterOff)]));
6156 end
6157 else if (cmd = 'd_botoff') and not g_Game_IsNet then
6158 begin
6159 if Length(P) > 1 then
6160 case P[1][1] of
6161 '0': g_debug_BotAIOff := 0;
6162 '1': g_debug_BotAIOff := 1;
6163 '2': g_debug_BotAIOff := 2;
6164 '3': g_debug_BotAIOff := 3;
6165 end;
6167 g_Console_Add(Format('d_botoff is %d', [g_debug_BotAIOff]));
6168 end
6169 else if cmd = 'd_monster' then
6170 begin
6171 if gGameOn and (gPlayer1 <> nil) and (gPlayer1.alive) and (not g_Game_IsNet) then
6172 if Length(P) < 2 then
6173 begin
6174 g_Console_Add(cmd + ' [ID | Name] [behaviour]');
6175 g_Console_Add('ID | Name');
6176 for b := MONSTER_DEMON to MONSTER_MAN do
6177 g_Console_Add(Format('%2d | %s', [b, g_Mons_NameByTypeId(b)]));
6178 conwriteln('behav. num'#10'normal 0'#10'killer 1'#10'maniac 2'#10'insane 3'#10'cannibal 4'#10'good 5');
6179 end else
6180 begin
6181 a := StrToIntDef(P[1], 0);
6182 if (a < MONSTER_DEMON) or (a > MONSTER_MAN) then
6183 a := g_Mons_TypeIdByName(P[1]);
6185 if (a < MONSTER_DEMON) or (a > MONSTER_MAN) then
6186 g_Console_Add(Format(_lc[I_MSG_NO_MONSTER], [P[1]]))
6187 else
6188 begin
6189 with gPlayer1.Obj do
6190 begin
6191 mon := g_Monsters_Create(a,
6192 X + Rect.X + (Rect.Width div 2),
6193 Y + Rect.Y + Rect.Height,
6194 gPlayer1.Direction, True);
6195 end;
6196 if (Length(P) > 2) and (mon <> nil) then
6197 begin
6198 if (CompareText(P[2], 'normal') = 0) then mon.MonsterBehaviour := BH_NORMAL
6199 else if (CompareText(P[2], 'killer') = 0) then mon.MonsterBehaviour := BH_KILLER
6200 else if (CompareText(P[2], 'maniac') = 0) then mon.MonsterBehaviour := BH_MANIAC
6201 else if (CompareText(P[2], 'insane') = 0) then mon.MonsterBehaviour := BH_INSANE
6202 else if (CompareText(P[2], 'cannibal') = 0) then mon.MonsterBehaviour := BH_CANNIBAL
6203 else if (CompareText(P[2], 'good') = 0) then mon.MonsterBehaviour := BH_GOOD
6204 else if (CompareText(P[2], 'friend') = 0) then mon.MonsterBehaviour := BH_GOOD
6205 else if (CompareText(P[2], 'friendly') = 0) then mon.MonsterBehaviour := BH_GOOD
6206 else mon.MonsterBehaviour := Min(Max(StrToIntDef(P[2], BH_NORMAL), BH_NORMAL), BH_GOOD);
6207 end;
6208 end;
6209 end;
6210 end
6211 else if (cmd = 'd_health') then
6212 begin
6213 if (Length(P) > 1) and
6214 ((P[1] = '1') or (P[1] = '0')) then
6215 g_debug_HealthBar := (P[1][1] = '1');
6217 g_Console_Add(Format('d_health is %d', [Byte(g_debug_HealthBar)]));
6218 end
6219 else if (cmd = 'd_player') then
6220 begin
6221 if (Length(P) > 1) and
6222 ((P[1] = '1') or (P[1] = '0')) then
6223 g_debug_Player := (P[1][1] = '1');
6225 g_Console_Add(Format(cmd + ' is %d', [Byte(g_Debug_Player)]));
6226 end
6227 else if (cmd = 'd_mem') then
6228 begin
6229 PrintHeapStats();
6230 end;
6231 end
6232 else
6233 g_Console_Add(_lc[I_MSG_NOT_DEBUG]);
6234 end;
6237 procedure GameCheats(P: SSArray);
6238 var
6239 cmd: string;
6240 f, a: Integer;
6241 plr: TPlayer;
6242 begin
6243 if (not gGameOn) or (not conIsCheatsEnabled) then
6244 begin
6245 g_Console_Add('not available');
6246 exit;
6247 end;
6248 plr := gPlayer1;
6249 if plr = nil then
6250 begin
6251 g_Console_Add('where is the player?!');
6252 exit;
6253 end;
6254 cmd := LowerCase(P[0]);
6255 // god
6256 if cmd = 'god' then
6257 begin
6258 plr.GodMode := not plr.GodMode;
6259 if plr.GodMode then g_Console_Add('player is godlike now') else g_Console_Add('player is mortal now');
6260 exit;
6261 end;
6262 // give <health|exit|weapons|air|suit|jetpack|berserk|all>
6263 if cmd = 'give' then
6264 begin
6265 if length(P) < 2 then begin g_Console_Add('give what?!'); exit; end;
6266 for f := 1 to High(P) do
6267 begin
6268 cmd := LowerCase(P[f]);
6269 if cmd = 'health' then begin plr.RestoreHealthArmor(); g_Console_Add('player feels himself better'); continue; end;
6270 if (cmd = 'all') {or (cmd = 'weapons')} then begin plr.AllRulez(False); g_Console_Add('player got the gifts'); continue; end;
6271 if cmd = 'exit' then
6272 begin
6273 if gTriggers <> nil then
6274 begin
6275 for a := 0 to High(gTriggers) do
6276 begin
6277 if gTriggers[a].TriggerType = TRIGGER_EXIT then
6278 begin
6279 g_Console_Add('player left the map');
6280 gExitByTrigger := True;
6281 //g_Game_ExitLevel(gTriggers[a].Data.MapName);
6282 g_Game_ExitLevel(gTriggers[a].tgcMap);
6283 break;
6284 end;
6285 end;
6286 end;
6287 continue;
6288 end;
6290 if cmd = 'air' then begin plr.GiveItem(ITEM_OXYGEN); g_Console_Add('player got some air'); continue; end;
6291 if cmd = 'jetpack' then begin plr.GiveItem(ITEM_JETPACK); g_Console_Add('player got a jetpack'); continue; end;
6292 if cmd = 'suit' then begin plr.GiveItem(ITEM_SUIT); g_Console_Add('player got an envirosuit'); continue; end;
6293 if cmd = 'berserk' then begin plr.GiveItem(ITEM_MEDKIT_BLACK); g_Console_Add('player got a berserk pack'); continue; end;
6294 if cmd = 'backpack' then begin plr.GiveItem(ITEM_AMMO_BACKPACK); g_Console_Add('player got a backpack'); continue; end;
6296 if cmd = 'helmet' then begin plr.GiveItem(ITEM_HELMET); g_Console_Add('player got a helmet'); continue; end;
6297 if cmd = 'bottle' then begin plr.GiveItem(ITEM_BOTTLE); g_Console_Add('player got a bottle of health'); continue; end;
6299 if cmd = 'stimpack' then begin plr.GiveItem(ITEM_MEDKIT_SMALL); g_Console_Add('player got a stimpack'); continue; end;
6300 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;
6302 if cmd = 'greenarmor' then begin plr.GiveItem(ITEM_ARMOR_GREEN); g_Console_Add('player got a security armor'); continue; end;
6303 if cmd = 'bluearmor' then begin plr.GiveItem(ITEM_ARMOR_BLUE); g_Console_Add('player got a combat armor'); continue; end;
6305 if (cmd = 'megasphere') or (cmd = 'mega') then begin plr.GiveItem(ITEM_SPHERE_BLUE); g_Console_Add('player got a megasphere'); continue; end;
6306 if (cmd = 'soulsphere') or (cmd = 'soul')then begin plr.GiveItem(ITEM_SPHERE_WHITE); g_Console_Add('player got a soul sphere'); continue; end;
6308 if (cmd = 'invul') or (cmd = 'invulnerability') then begin plr.GiveItem(ITEM_INVUL); g_Console_Add('player got invulnerability'); continue; end;
6309 if (cmd = 'invis') or (cmd = 'invisibility') then begin plr.GiveItem(ITEM_INVIS); g_Console_Add('player got invisibility'); continue; end;
6311 if cmd = 'redkey' then begin plr.GiveItem(ITEM_KEY_RED); g_Console_Add('player got the red key'); continue; end;
6312 if cmd = 'greenkey' then begin plr.GiveItem(ITEM_KEY_GREEN); g_Console_Add('player got the green key'); continue; end;
6313 if cmd = 'bluekey' then begin plr.GiveItem(ITEM_KEY_BLUE); g_Console_Add('player got the blue key'); continue; end;
6315 if (cmd = 'shotgun') or (cmd = 'sg') then begin plr.GiveItem(ITEM_WEAPON_SHOTGUN1); g_Console_Add('player got a shotgun'); continue; end;
6316 if (cmd = 'supershotgun') or (cmd = 'ssg') then begin plr.GiveItem(ITEM_WEAPON_SHOTGUN2); g_Console_Add('player got a supershotgun'); continue; end;
6317 if cmd = 'chaingun' then begin plr.GiveItem(ITEM_WEAPON_CHAINGUN); g_Console_Add('player got a chaingun'); continue; end;
6318 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;
6319 if cmd = 'plasmagun' then begin plr.GiveItem(ITEM_WEAPON_PLASMA); g_Console_Add('player got a plasma gun'); continue; end;
6320 if cmd = 'bfg' then begin plr.GiveItem(ITEM_WEAPON_BFG); g_Console_Add('player got a BFG-9000'); continue; end;
6322 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;
6323 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;
6324 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;
6325 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;
6326 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;
6327 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;
6329 if cmd = 'superchaingun' then begin plr.GiveItem(ITEM_WEAPON_SUPERPULEMET); g_Console_Add('player got a superchaingun'); continue; end;
6330 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;
6332 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;
6333 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;
6335 if cmd = 'chainsaw' then begin plr.GiveItem(ITEM_WEAPON_SAW); g_Console_Add('player got a chainsaw'); continue; end;
6337 if cmd = 'ammo' then
6338 begin
6339 plr.GiveItem(ITEM_AMMO_SHELLS_BOX);
6340 plr.GiveItem(ITEM_AMMO_BULLETS_BOX);
6341 plr.GiveItem(ITEM_AMMO_CELL_BIG);
6342 plr.GiveItem(ITEM_AMMO_ROCKET_BOX);
6343 plr.GiveItem(ITEM_AMMO_FUELCAN);
6344 g_Console_Add('player got some ammo');
6345 continue;
6346 end;
6348 if cmd = 'clip' then begin plr.GiveItem(ITEM_AMMO_BULLETS); g_Console_Add('player got some bullets'); continue; end;
6349 if cmd = 'bullets' then begin plr.GiveItem(ITEM_AMMO_BULLETS_BOX); g_Console_Add('player got a box of bullets'); continue; end;
6351 if cmd = 'shells' then begin plr.GiveItem(ITEM_AMMO_SHELLS); g_Console_Add('player got some shells'); continue; end;
6352 if cmd = 'shellbox' then begin plr.GiveItem(ITEM_AMMO_SHELLS_BOX); g_Console_Add('player got a box of shells'); continue; end;
6354 if cmd = 'cells' then begin plr.GiveItem(ITEM_AMMO_CELL); g_Console_Add('player got some cells'); continue; end;
6355 if cmd = 'battery' then begin plr.GiveItem(ITEM_AMMO_CELL_BIG); g_Console_Add('player got cell battery'); continue; end;
6357 if cmd = 'rocket' then begin plr.GiveItem(ITEM_AMMO_ROCKET); g_Console_Add('player got a rocket'); continue; end;
6358 if cmd = 'rocketbox' then begin plr.GiveItem(ITEM_AMMO_ROCKET_BOX); g_Console_Add('player got some rockets'); continue; end;
6360 if (cmd = 'fuel') or (cmd = 'fuelcan') then begin plr.GiveItem(ITEM_AMMO_FUELCAN); g_Console_Add('player got fuel canister'); continue; end;
6362 if cmd = 'weapons' then
6363 begin
6364 plr.GiveItem(ITEM_WEAPON_SHOTGUN1);
6365 plr.GiveItem(ITEM_WEAPON_SHOTGUN2);
6366 plr.GiveItem(ITEM_WEAPON_CHAINGUN);
6367 plr.GiveItem(ITEM_WEAPON_ROCKETLAUNCHER);
6368 plr.GiveItem(ITEM_WEAPON_PLASMA);
6369 plr.GiveItem(ITEM_WEAPON_BFG);
6370 g_Console_Add('player got weapons');
6371 continue;
6372 end;
6374 if cmd = 'keys' then
6375 begin
6376 plr.GiveItem(ITEM_KEY_RED);
6377 plr.GiveItem(ITEM_KEY_GREEN);
6378 plr.GiveItem(ITEM_KEY_BLUE);
6379 g_Console_Add('player got all keys');
6380 continue;
6381 end;
6383 g_Console_Add('i don''t know how to give '''+cmd+'''!');
6384 end;
6385 exit;
6386 end;
6387 // open
6388 if cmd = 'open' then
6389 begin
6390 g_Console_Add('player activated sesame');
6391 g_Triggers_OpenAll();
6392 exit;
6393 end;
6394 // fly
6395 if cmd = 'fly' then
6396 begin
6397 gFly := not gFly;
6398 if gFly then g_Console_Add('player feels himself lighter') else g_Console_Add('player lost his wings');
6399 exit;
6400 end;
6401 // noclip
6402 if cmd = 'noclip' then
6403 begin
6404 plr.SwitchNoClip;
6405 g_Console_Add('wall hardeness adjusted');
6406 exit;
6407 end;
6408 // notarget
6409 if cmd = 'notarget' then
6410 begin
6411 plr.NoTarget := not plr.NoTarget;
6412 if plr.NoTarget then g_Console_Add('player hides in shadows') else g_Console_Add('player is brave again');
6413 exit;
6414 end;
6415 // noreload
6416 if cmd = 'noreload' then
6417 begin
6418 plr.NoReload := not plr.NoReload;
6419 if plr.NoReload then g_Console_Add('player is action hero now') else g_Console_Add('player is ordinary man now');
6420 exit;
6421 end;
6422 // speedy
6423 if cmd = 'speedy' then
6424 begin
6425 MAX_RUNVEL := 32-MAX_RUNVEL;
6426 g_Console_Add('speed adjusted');
6427 exit;
6428 end;
6429 // jumpy
6430 if cmd = 'jumpy' then
6431 begin
6432 VEL_JUMP := 30-VEL_JUMP;
6433 g_Console_Add('jump height adjusted');
6434 exit;
6435 end;
6436 // automap
6437 if cmd = 'automap' then
6438 begin
6439 gShowMap := not gShowMap;
6440 if gShowMap then g_Console_Add('player gains second sight') else g_Console_Add('player lost second sight');
6441 exit;
6442 end;
6443 // aimline
6444 if cmd = 'aimline' then
6445 begin
6446 gAimLine := not gAimLine;
6447 if gAimLine then g_Console_Add('player gains laser sight') else g_Console_Add('player lost laser sight');
6448 exit;
6449 end;
6450 end;
6452 procedure GameCommands(P: SSArray);
6453 var
6454 a, b: Integer;
6455 s, pw: String;
6456 chstr: string;
6457 cmd: string;
6458 pl: pTNetClient = nil;
6459 plr: TPlayer;
6460 prt: Word;
6461 nm: Boolean;
6462 listen: LongWord;
6463 found: Boolean;
6464 begin
6465 // Îáùèå êîìàíäû:
6466 cmd := LowerCase(P[0]);
6467 chstr := '';
6468 if cmd = 'pause' then
6469 begin
6470 if (g_ActiveWindow = nil) then
6471 g_Game_Pause(not gPauseMain);
6472 end
6473 else if cmd = 'endgame' then
6474 gExit := EXIT_SIMPLE
6475 else if cmd = 'restart' then
6476 begin
6477 if gGameOn or (gState in [STATE_INTERSINGLE, STATE_INTERCUSTOM]) then
6478 begin
6479 if g_Game_IsClient then
6480 begin
6481 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6482 Exit;
6483 end;
6484 g_Game_Restart();
6485 end else
6486 g_Console_Add(_lc[I_MSG_NOT_GAME]);
6487 end
6488 else if cmd = 'kick' then
6489 begin
6490 if g_Game_IsServer then
6491 begin
6492 if Length(P) < 2 then
6493 begin
6494 g_Console_Add('kick <name>');
6495 Exit;
6496 end;
6497 if P[1] = '' then
6498 begin
6499 g_Console_Add('kick <name>');
6500 Exit;
6501 end;
6503 if g_Game_IsNet then
6504 pl := g_Net_Client_ByName(P[1]);
6505 if (pl <> nil) then
6506 begin
6507 s := g_Net_ClientName_ByID(pl^.ID);
6508 enet_peer_disconnect(pl^.Peer, NET_DISC_KICK);
6509 g_Console_Add(Format(_lc[I_PLAYER_KICK], [s]));
6510 MH_SEND_GameEvent(NET_EV_PLAYER_KICK, 0, s);
6511 g_Net_Slist_ServerPlayerLeaves();
6512 end else if gPlayers <> nil then
6513 for a := Low(gPlayers) to High(gPlayers) do
6514 if gPlayers[a] <> nil then
6515 if Copy(LowerCase(gPlayers[a].Name), 1, Length(P[1])) = LowerCase(P[1]) then
6516 begin
6517 // Íå îòêëþ÷àòü îñíîâíûõ èãðîêîâ â ñèíãëå
6518 if not(gPlayers[a] is TBot) and (gGameSettings.GameType = GT_SINGLE) then
6519 continue;
6520 gPlayers[a].Lives := 0;
6521 gPlayers[a].Kill(K_SIMPLEKILL, 0, HIT_DISCON);
6522 g_Console_Add(Format(_lc[I_PLAYER_LEAVE], [gPlayers[a].Name]), True);
6523 g_Player_Remove(gPlayers[a].UID);
6524 g_Net_Slist_ServerPlayerLeaves();
6525 // Åñëè íå ïåðåìåøàòü, ïðè äîáàâëåíèè íîâûõ áîòîâ ïîÿâÿòñÿ ñòàðûå
6526 g_Bot_MixNames();
6527 end;
6528 end else
6529 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
6530 end
6531 else if cmd = 'kick_id' then
6532 begin
6533 if g_Game_IsServer and g_Game_IsNet then
6534 begin
6535 if Length(P) < 2 then
6536 begin
6537 g_Console_Add('kick_id <client ID>');
6538 Exit;
6539 end;
6540 if P[1] = '' then
6541 begin
6542 g_Console_Add('kick_id <client ID>');
6543 Exit;
6544 end;
6546 a := StrToIntDef(P[1], 0);
6547 if (NetClients <> nil) and (a <= High(NetClients)) then
6548 begin
6549 if NetClients[a].Used and (NetClients[a].Peer <> nil) then
6550 begin
6551 s := g_Net_ClientName_ByID(NetClients[a].ID);
6552 enet_peer_disconnect(NetClients[a].Peer, NET_DISC_KICK);
6553 g_Console_Add(Format(_lc[I_PLAYER_KICK], [s]));
6554 MH_SEND_GameEvent(NET_EV_PLAYER_KICK, 0, s);
6555 g_Net_Slist_ServerPlayerLeaves();
6556 end;
6557 end;
6558 end else
6559 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6560 end
6561 else if cmd = 'kick_pid' then
6562 begin
6563 if g_Game_IsServer and g_Game_IsNet then
6564 begin
6565 if Length(P) < 2 then
6566 begin
6567 g_Console_Add('kick_pid <player ID>');
6568 Exit;
6569 end;
6570 if P[1] = '' then
6571 begin
6572 g_Console_Add('kick_pid <player ID>');
6573 Exit;
6574 end;
6576 a := StrToIntDef(P[1], 0);
6577 pl := g_Net_Client_ByPlayer(a);
6578 if (pl <> nil) and pl^.Used and (pl^.Peer <> nil) then
6579 begin
6580 s := g_Net_ClientName_ByID(pl^.ID);
6581 enet_peer_disconnect(pl^.Peer, NET_DISC_KICK);
6582 g_Console_Add(Format(_lc[I_PLAYER_KICK], [s]));
6583 MH_SEND_GameEvent(NET_EV_PLAYER_KICK, 0, s);
6584 g_Net_Slist_ServerPlayerLeaves();
6585 end;
6586 end else
6587 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6588 end
6589 else if cmd = 'ban' then
6590 begin
6591 if g_Game_IsServer and g_Game_IsNet then
6592 begin
6593 if Length(P) < 2 then
6594 begin
6595 g_Console_Add('ban <name>');
6596 Exit;
6597 end;
6598 if P[1] = '' then
6599 begin
6600 g_Console_Add('ban <name>');
6601 Exit;
6602 end;
6604 pl := g_Net_Client_ByName(P[1]);
6605 if (pl <> nil) then
6606 begin
6607 s := g_Net_ClientName_ByID(pl^.ID);
6608 g_Net_BanHost(pl^.Peer^.address.host, False);
6609 enet_peer_disconnect(pl^.Peer, NET_DISC_TEMPBAN);
6610 g_Console_Add(Format(_lc[I_PLAYER_BAN], [s]));
6611 MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s);
6612 g_Net_Slist_ServerPlayerLeaves();
6613 end else
6614 g_Console_Add(Format(_lc[I_NET_ERR_NAME404], [P[1]]));
6615 end else
6616 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6617 end
6618 else if cmd = 'ban_id' then
6619 begin
6620 if g_Game_IsServer and g_Game_IsNet then
6621 begin
6622 if Length(P) < 2 then
6623 begin
6624 g_Console_Add('ban_id <client ID>');
6625 Exit;
6626 end;
6627 if P[1] = '' then
6628 begin
6629 g_Console_Add('ban_id <client ID>');
6630 Exit;
6631 end;
6633 a := StrToIntDef(P[1], 0);
6634 if (NetClients <> nil) and (a <= High(NetClients)) then
6635 if NetClients[a].Used and (NetClients[a].Peer <> nil) then
6636 begin
6637 s := g_Net_ClientName_ByID(NetClients[a].ID);
6638 g_Net_BanHost(NetClients[a].Peer^.address.host, False);
6639 enet_peer_disconnect(NetClients[a].Peer, NET_DISC_TEMPBAN);
6640 g_Console_Add(Format(_lc[I_PLAYER_BAN], [s]));
6641 MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s);
6642 g_Net_Slist_ServerPlayerLeaves();
6643 end;
6644 end else
6645 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6646 end
6647 else if cmd = 'ban_pid' then
6648 begin
6649 if g_Game_IsServer and g_Game_IsNet then
6650 begin
6651 if Length(P) < 2 then
6652 begin
6653 g_Console_Add('ban_pid <player ID>');
6654 Exit;
6655 end;
6656 if P[1] = '' then
6657 begin
6658 g_Console_Add('ban_pid <player ID>');
6659 Exit;
6660 end;
6662 a := StrToIntDef(P[1], 0);
6663 pl := g_Net_Client_ByPlayer(a);
6664 if (pl <> nil) and pl^.Used and (pl^.Peer <> nil) then
6665 begin
6666 s := g_Net_ClientName_ByID(pl^.ID);
6667 g_Net_BanHost(pl^.Peer^.address.host, False);
6668 enet_peer_disconnect(pl^.Peer, NET_DISC_TEMPBAN);
6669 g_Console_Add(Format(_lc[I_PLAYER_BAN], [s]));
6670 MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s);
6671 g_Net_Slist_ServerPlayerLeaves();
6672 end;
6673 end else
6674 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6675 end
6676 else if cmd = 'permban' then
6677 begin
6678 if g_Game_IsServer and g_Game_IsNet then
6679 begin
6680 if Length(P) < 2 then
6681 begin
6682 g_Console_Add('permban <name>');
6683 Exit;
6684 end;
6685 if P[1] = '' then
6686 begin
6687 g_Console_Add('permban <name>');
6688 Exit;
6689 end;
6691 pl := g_Net_Client_ByName(P[1]);
6692 if (pl <> nil) then
6693 begin
6694 s := g_Net_ClientName_ByID(pl^.ID);
6695 g_Net_BanHost(pl^.Peer^.address.host);
6696 enet_peer_disconnect(pl^.Peer, NET_DISC_BAN);
6697 g_Net_SaveBanList();
6698 g_Console_Add(Format(_lc[I_PLAYER_BAN], [s]));
6699 MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s);
6700 g_Net_Slist_ServerPlayerLeaves();
6701 end else
6702 g_Console_Add(Format(_lc[I_NET_ERR_NAME404], [P[1]]));
6703 end else
6704 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6705 end
6706 else if cmd = 'permban_id' then
6707 begin
6708 if g_Game_IsServer and g_Game_IsNet then
6709 begin
6710 if Length(P) < 2 then
6711 begin
6712 g_Console_Add('permban_id <client ID>');
6713 Exit;
6714 end;
6715 if P[1] = '' then
6716 begin
6717 g_Console_Add('permban_id <client ID>');
6718 Exit;
6719 end;
6721 a := StrToIntDef(P[1], 0);
6722 if (NetClients <> nil) and (a <= High(NetClients)) then
6723 if NetClients[a].Used and (NetClients[a].Peer <> nil) then
6724 begin
6725 s := g_Net_ClientName_ByID(NetClients[a].ID);
6726 g_Net_BanHost(NetClients[a].Peer^.address.host);
6727 enet_peer_disconnect(NetClients[a].Peer, NET_DISC_BAN);
6728 g_Net_SaveBanList();
6729 g_Console_Add(Format(_lc[I_PLAYER_BAN], [s]));
6730 MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s);
6731 g_Net_Slist_ServerPlayerLeaves();
6732 end;
6733 end else
6734 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6735 end
6736 else if cmd = 'permban_pid' then
6737 begin
6738 if g_Game_IsServer and g_Game_IsNet then
6739 begin
6740 if Length(P) < 2 then
6741 begin
6742 g_Console_Add('permban_pid <player ID>');
6743 Exit;
6744 end;
6745 if P[1] = '' then
6746 begin
6747 g_Console_Add('permban_pid <player ID>');
6748 Exit;
6749 end;
6751 a := StrToIntDef(P[1], 0);
6752 pl := g_Net_Client_ByPlayer(a);
6753 if (pl <> nil) and pl^.Used and (pl^.Peer <> nil) then
6754 begin
6755 s := g_Net_ClientName_ByID(pl^.ID);
6756 g_Net_BanHost(pl^.Peer^.address.host);
6757 enet_peer_disconnect(pl^.Peer, NET_DISC_BAN);
6758 g_Net_SaveBanList();
6759 g_Console_Add(Format(_lc[I_PLAYER_BAN], [s]));
6760 MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s);
6761 g_Net_Slist_ServerPlayerLeaves();
6762 end;
6763 end else
6764 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6765 end
6766 else if cmd = 'permban_ip' then
6767 begin
6768 if g_Game_IsServer and g_Game_IsNet then
6769 begin
6770 if Length(P) < 2 then
6771 begin
6772 g_Console_Add('permban_ip <IP address>');
6773 Exit;
6774 end;
6775 if P[1] = '' then
6776 begin
6777 g_Console_Add('permban_ip <IP address>');
6778 Exit;
6779 end;
6781 g_Net_BanHost(P[1]);
6782 g_Net_SaveBanList();
6783 g_Console_Add(Format(_lc[I_PLAYER_BAN], [P[1]]));
6784 end else
6785 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6786 end
6787 else if cmd = 'unban' then
6788 begin
6789 if g_Game_IsServer and g_Game_IsNet then
6790 begin
6791 if Length(P) < 2 then
6792 begin
6793 g_Console_Add('unban <IP Address>');
6794 Exit;
6795 end;
6796 if P[1] = '' then
6797 begin
6798 g_Console_Add('unban <IP Address>');
6799 Exit;
6800 end;
6802 if g_Net_UnbanHost(P[1]) then
6803 begin
6804 g_Console_Add(Format(_lc[I_MSG_UNBAN_OK], [P[1]]));
6805 g_Net_SaveBanList();
6806 end else
6807 g_Console_Add(Format(_lc[I_MSG_UNBAN_FAIL], [P[1]]));
6808 end else
6809 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6810 end
6811 else if cmd = 'clientlist' then
6812 begin
6813 if g_Game_IsServer and g_Game_IsNet then
6814 begin
6815 b := 0;
6816 if NetClients <> nil then
6817 for a := Low(NetClients) to High(NetClients) do
6818 if NetClients[a].Used and (NetClients[a].Peer <> nil) then
6819 begin
6820 plr := g_Player_Get(NetClients[a].Player);
6821 if plr = nil then continue;
6822 Inc(b);
6823 g_Console_Add(Format('#%2d: %-15s | %s', [a,
6824 IpToStr(NetClients[a].Peer^.address.host), plr.Name]));
6825 end;
6826 if b = 0 then
6827 g_Console_Add(_lc[I_MSG_NOCLIENTS]);
6828 end else
6829 g_Console_Add(_lc[I_MSG_SERVERONLY]);
6830 end
6831 else if cmd = 'connect' then
6832 begin
6833 if (NetMode = NET_NONE) then
6834 begin
6835 if Length(P) < 2 then
6836 begin
6837 g_Console_Add('connect <IP> [port] [password]');
6838 Exit;
6839 end;
6840 if P[1] = '' then
6841 begin
6842 g_Console_Add('connect <IP> [port] [password]');
6843 Exit;
6844 end;
6846 if Length(P) > 2 then
6847 prt := StrToIntDef(P[2], 25666)
6848 else
6849 prt := 25666;
6851 if Length(P) > 3 then
6852 pw := P[3]
6853 else
6854 pw := '';
6856 g_Game_StartClient(P[1], prt, pw);
6857 end;
6858 end
6859 else if cmd = 'disconnect' then
6860 begin
6861 if (NetMode = NET_CLIENT) then
6862 g_Net_Disconnect();
6863 end
6864 else if cmd = 'reconnect' then
6865 begin
6866 if (NetMode = NET_SERVER) then
6867 Exit;
6869 if (NetMode = NET_CLIENT) then
6870 begin
6871 g_Net_Disconnect();
6872 gExit := EXIT_SIMPLE;
6873 EndGame;
6874 end;
6876 //TODO: Use last successful password to reconnect, instead of ''
6877 g_Game_StartClient(NetClientIP, NetClientPort, '');
6878 end
6879 else if (cmd = 'addbot') or
6880 (cmd = 'bot_add') then
6881 begin
6882 if Length(P) > 2 then
6883 g_Bot_Add(TEAM_NONE, StrToIntDef(P[1], 2), StrToIntDef(P[2], 100))
6884 else if Length(P) > 1 then
6885 g_Bot_Add(TEAM_NONE, StrToIntDef(P[1], 2))
6886 else
6887 g_Bot_Add(TEAM_NONE, 2);
6888 end
6889 else if cmd = 'bot_addlist' then
6890 begin
6891 if Length(P) > 1 then
6892 begin
6893 if Length(P) = 2 then
6894 g_Bot_AddList(TEAM_NONE, P[1], StrToIntDef(P[1], -1))
6895 else if Length(P) = 3 then
6896 g_Bot_AddList(TEAM_NONE, P[1], StrToIntDef(P[1], -1), StrToIntDef(P[2], 100))
6897 else
6898 g_Bot_AddList(IfThen(P[2] = 'red', TEAM_RED, TEAM_BLUE), P[1], StrToIntDef(P[1], -1));
6899 end;
6900 end
6901 else if cmd = 'bot_removeall' then
6902 g_Bot_RemoveAll()
6903 else if cmd = 'chat' then
6904 begin
6905 if g_Game_IsNet then
6906 begin
6907 if Length(P) > 1 then
6908 begin
6909 for a := 1 to High(P) do
6910 chstr := chstr + P[a] + ' ';
6912 if Length(chstr) > 200 then SetLength(chstr, 200);
6914 if Length(chstr) < 1 then
6915 begin
6916 g_Console_Add('chat <text>');
6917 Exit;
6918 end;
6920 chstr := b_Text_Format(chstr);
6921 if g_Game_IsClient then
6922 MC_SEND_Chat(chstr, NET_CHAT_PLAYER)
6923 else
6924 MH_SEND_Chat(gPlayer1Settings.Name + ': ' + chstr, NET_CHAT_PLAYER);
6925 end
6926 else
6927 g_Console_Add('chat <text>');
6928 end else
6929 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
6930 end
6931 else if cmd = 'teamchat' then
6932 begin
6933 if g_Game_IsNet and (gGameSettings.GameMode in [GM_TDM, GM_CTF]) then
6934 begin
6935 if Length(P) > 1 then
6936 begin
6937 for a := 1 to High(P) do
6938 chstr := chstr + P[a] + ' ';
6940 if Length(chstr) > 200 then SetLength(chstr, 200);
6942 if Length(chstr) < 1 then
6943 begin
6944 g_Console_Add('teamchat <text>');
6945 Exit;
6946 end;
6948 chstr := b_Text_Format(chstr);
6949 if g_Game_IsClient then
6950 MC_SEND_Chat(chstr, NET_CHAT_TEAM)
6951 else
6952 MH_SEND_Chat(gPlayer1Settings.Name + ': ' + chstr, NET_CHAT_TEAM,
6953 gPlayer1Settings.Team);
6954 end
6955 else
6956 g_Console_Add('teamchat <text>');
6957 end else
6958 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
6959 end
6960 else if cmd = 'game' then
6961 begin
6962 if gGameSettings.GameType <> GT_NONE then
6963 begin
6964 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
6965 Exit;
6966 end;
6967 if Length(P) = 1 then
6968 begin
6969 g_Console_Add(cmd + ' <WAD> [MAP] [# players]');
6970 Exit;
6971 end;
6972 // game not started yet, load fist map from some wad
6973 found := false;
6974 s := addWadExtension(P[1]);
6975 found := e_FindResource(AllMapDirs, s);
6976 P[1] := s;
6977 if found then
6978 begin
6979 P[1] := ExpandFileName(P[1]);
6980 // if map not choosed then set first map
6981 if Length(P) < 3 then
6982 begin
6983 SetLength(P, 3);
6984 P[2] := g_Game_GetFirstMap(P[1]);
6985 end;
6987 s := P[1] + ':\' + UpperCase(P[2]);
6989 if g_Map_Exist(s) then
6990 begin
6991 // start game
6992 g_Game_Free();
6993 with gGameSettings do
6994 begin
6995 Options := gsGameFlags;
6996 GameMode := g_Game_TextToMode(gsGameMode);
6997 if gSwitchGameMode <> GM_NONE then
6998 GameMode := gSwitchGameMode;
6999 if GameMode = GM_NONE then GameMode := GM_DM;
7000 if GameMode = GM_SINGLE then GameMode := GM_COOP;
7001 b := 1;
7002 if Length(P) >= 4 then
7003 b := StrToIntDef(P[3], 1);
7004 g_Game_StartCustom(s, GameMode, TimeLimit,
7005 GoalLimit, MaxLives, Options, b);
7006 end;
7007 end
7008 else
7009 if P[2] = '' then
7010 g_Console_Add(Format(_lc[I_MSG_NO_MAPS], [P[1]]))
7011 else
7012 g_Console_Add(Format(_lc[I_MSG_NO_MAP_FALLBACK], [UpperCase(P[2]), P[1]]));
7013 end else
7014 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]));
7015 end
7016 else if cmd = 'host' then
7017 begin
7018 if gGameSettings.GameType <> GT_NONE then
7019 begin
7020 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
7021 Exit;
7022 end;
7023 if Length(P) < 4 then
7024 begin
7025 g_Console_Add(cmd + ' <listen IP> <port> <WAD> [MAP] [# players]');
7026 Exit;
7027 end;
7028 if not StrToIp(P[1], listen) then
7029 Exit;
7030 prt := StrToIntDef(P[2], 25666);
7032 s := addWadExtension(P[3]);
7033 found := e_FindResource(AllMapDirs, s);
7034 P[3] := s;
7035 if found then
7036 begin
7037 // get first map in wad, if not specified
7038 if Length(P) < 5 then
7039 begin
7040 SetLength(P, 5);
7041 P[4] := g_Game_GetFirstMap(P[1]);
7042 end;
7043 s := P[3] + ':\' + UpperCase(P[4]);
7044 if g_Map_Exist(s) then
7045 begin
7046 // start game
7047 g_Game_Free();
7048 with gGameSettings do
7049 begin
7050 Options := gsGameFlags;
7051 GameMode := g_Game_TextToMode(gsGameMode);
7052 if gSwitchGameMode <> GM_NONE then GameMode := gSwitchGameMode;
7053 if GameMode = GM_NONE then GameMode := GM_DM;
7054 if GameMode = GM_SINGLE then GameMode := GM_COOP;
7055 b := 0;
7056 if Length(P) >= 6 then
7057 b := StrToIntDef(P[5], 0);
7058 g_Game_StartServer(s, GameMode, TimeLimit, GoalLimit, MaxLives, Options, b, listen, prt)
7059 end
7060 end
7061 else
7062 begin
7063 if P[4] = '' then
7064 g_Console_Add(Format(_lc[I_MSG_NO_MAPS], [P[3]]))
7065 else
7066 g_Console_Add(Format(_lc[I_MSG_NO_MAP_FALLBACK], [UpperCase(P[4]), P[3]]))
7067 end
7068 end
7069 else
7070 begin
7071 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[3]]))
7072 end
7073 end
7074 else if cmd = 'map' then
7075 begin
7076 if Length(P) = 1 then
7077 begin
7078 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
7079 begin
7080 g_Console_Add(cmd + ' <MAP>');
7081 g_Console_Add(cmd + ' <WAD> [MAP]')
7082 end
7083 else
7084 begin
7085 g_Console_Add(_lc[I_MSG_GM_UNAVAIL])
7086 end
7087 end
7088 else
7089 begin
7090 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
7091 begin
7092 if Length(P) < 3 then
7093 begin
7094 // first param is map or wad
7095 s := UpperCase(P[1]);
7096 if g_Map_Exist(gGameSettings.WAD + ':\' + s) then
7097 begin
7098 gExitByTrigger := False;
7099 if gGameOn then
7100 begin
7101 // already in game, finish current map
7102 gNextMap := s;
7103 gExit := EXIT_ENDLEVELCUSTOM;
7104 end
7105 else
7106 begin
7107 // intermission, so change map immediately
7108 g_Game_ChangeMap(s)
7109 end
7110 end
7111 else
7112 begin
7113 s := P[1];
7114 found := e_FindResource(AllMapDirs, s);
7115 P[1] := s;
7116 g_Console_Add(Format(_lc[I_MSG_NO_MAP_FALLBACK], [s, 'WAD ' + P[1]]));
7117 if found then
7118 begin
7119 // no such map, found wad
7120 pw := P[1];
7121 SetLength(P, 3);
7122 P[1] := ExpandFileName(pw);
7123 P[2] := g_Game_GetFirstMap(P[1]);
7124 s := P[1] + ':\' + P[2];
7125 if g_Map_Exist(s) then
7126 begin
7127 gExitByTrigger := False;
7128 if gGameOn then
7129 begin
7130 // already in game, finish current map
7131 gNextMap := s;
7132 gExit := EXIT_ENDLEVELCUSTOM
7133 end
7134 else
7135 begin
7136 // intermission, so change map immediately
7137 g_Game_ChangeMap(s)
7138 end
7139 end
7140 else
7141 begin
7142 if P[2] = '' then
7143 g_Console_Add(Format(_lc[I_MSG_NO_MAPS], [P[1]]))
7144 else
7145 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [P[2]]))
7146 end
7147 end
7148 else
7149 begin
7150 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]))
7151 end
7152 end;
7153 end
7154 else
7155 begin
7156 s := addWadExtension(P[1]);
7157 found := e_FindResource(AllMapDirs, s);
7158 P[1] := s;
7159 if found then
7160 begin
7161 P[2] := UpperCase(P[2]);
7162 s := P[1] + ':\' + P[2];
7163 if g_Map_Exist(s) then
7164 begin
7165 gExitByTrigger := False;
7166 if gGameOn then
7167 begin
7168 gNextMap := s;
7169 gExit := EXIT_ENDLEVELCUSTOM
7170 end
7171 else
7172 begin
7173 g_Game_ChangeMap(s)
7174 end
7175 end
7176 else
7177 begin
7178 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [P[2]]))
7179 end
7180 end
7181 else
7182 begin
7183 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]))
7184 end
7185 end
7186 end
7187 else
7188 begin
7189 g_Console_Add(_lc[I_MSG_GM_UNAVAIL])
7190 end
7191 end
7192 end
7193 else if cmd = 'nextmap' then
7194 begin
7195 if not(gGameOn or (gState = STATE_INTERCUSTOM)) then
7196 begin
7197 g_Console_Add(_lc[I_MSG_NOT_GAME])
7198 end
7199 else
7200 begin
7201 nm := True;
7202 if Length(P) = 1 then
7203 begin
7204 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
7205 begin
7206 g_Console_Add(cmd + ' <MAP>');
7207 g_Console_Add(cmd + ' <WAD> [MAP]');
7208 end
7209 else
7210 begin
7211 nm := False;
7212 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
7213 end;
7214 end
7215 else
7216 begin
7217 nm := False;
7218 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
7219 begin
7220 if Length(P) < 3 then
7221 begin
7222 // first param is map or wad
7223 s := UpperCase(P[1]);
7224 if g_Map_Exist(gGameSettings.WAD + ':\' + s) then
7225 begin
7226 // map founded
7227 gExitByTrigger := False;
7228 gNextMap := s;
7229 nm := True;
7230 end
7231 else
7232 begin
7233 // no such map, found wad
7234 pw := addWadExtension(P[1]);
7235 found := e_FindResource(MapDirs, pw);
7236 if not found then
7237 found := e_FindResource(WadDirs, pw);
7238 P[1] := pw;
7239 g_Console_Add(Format(_lc[I_MSG_NO_MAP_FALLBACK], [s, P[1]]));
7240 if found then
7241 begin
7242 // map not specified, select first map
7243 SetLength(P, 3);
7244 P[2] := g_Game_GetFirstMap(P[1]);
7245 s := P[1] + ':\' + P[2];
7246 if g_Map_Exist(s) then
7247 begin
7248 gExitByTrigger := False;
7249 gNextMap := s;
7250 nm := True
7251 end
7252 else
7253 begin
7254 if P[2] = '' then
7255 g_Console_Add(Format(_lc[I_MSG_NO_MAPS], [P[1]]))
7256 else
7257 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [P[2]]))
7258 end
7259 end
7260 else
7261 begin
7262 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]))
7263 end
7264 end
7265 end
7266 else
7267 begin
7268 // specified two params wad + map
7269 pw := addWadExtension(P[1]);
7270 found := e_FindResource(MapDirs, pw);
7271 if not found then
7272 found := e_FindResource(MapDirs, pw);
7273 P[1] := pw;
7274 if found then
7275 begin
7276 P[2] := UpperCase(P[2]);
7277 s := P[1] + ':\' + P[2];
7278 if g_Map_Exist(s) then
7279 begin
7280 gExitByTrigger := False;
7281 gNextMap := s;
7282 nm := True
7283 end
7284 else
7285 begin
7286 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [P[2]]))
7287 end
7288 end
7289 else
7290 begin
7291 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]))
7292 end
7293 end
7294 end
7295 else
7296 begin
7297 g_Console_Add(_lc[I_MSG_GM_UNAVAIL])
7298 end
7299 end;
7300 if nm then
7301 begin
7302 if gNextMap = '' then
7303 g_Console_Add(_lc[I_MSG_NEXTMAP_UNSET])
7304 else
7305 g_Console_Add(Format(_lc[I_MSG_NEXTMAP_SET], [gNextMap]))
7306 end
7307 end
7308 end
7309 else if (cmd = 'endmap') or (cmd = 'goodbye') then
7310 begin
7311 if not gGameOn then
7312 begin
7313 g_Console_Add(_lc[I_MSG_NOT_GAME])
7314 end
7315 else
7316 begin
7317 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
7318 begin
7319 gExitByTrigger := False;
7320 // next map not specified, try to find trigger EXIT
7321 if (gNextMap = '') and (gTriggers <> nil) then
7322 begin
7323 for a := 0 to High(gTriggers) do
7324 begin
7325 if gTriggers[a].TriggerType = TRIGGER_EXIT then
7326 begin
7327 gExitByTrigger := True;
7328 //gNextMap := gTriggers[a].Data.MapName;
7329 gNextMap := gTriggers[a].tgcMap;
7330 Break
7331 end
7332 end
7333 end;
7334 if gNextMap = '' then
7335 gNextMap := g_Game_GetNextMap();
7336 if not isWadPath(gNextMap) then
7337 s := gGameSettings.WAD + ':\' + gNextMap
7338 else
7339 s := gNextMap;
7340 if g_Map_Exist(s) then
7341 gExit := EXIT_ENDLEVELCUSTOM
7342 else
7343 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [gNextMap]))
7344 end
7345 else
7346 begin
7347 g_Console_Add(_lc[I_MSG_GM_UNAVAIL])
7348 end
7349 end
7350 end
7351 else if (cmd = 'event') then
7352 begin
7353 if (Length(P) <= 1) then
7354 begin
7355 for a := 0 to High(gEvents) do
7356 if gEvents[a].Command = '' then
7357 g_Console_Add(gEvents[a].Name + ' <none>')
7358 else
7359 g_Console_Add(gEvents[a].Name + ' "' + gEvents[a].Command + '"');
7360 Exit;
7361 end;
7362 if (Length(P) = 2) then
7363 begin
7364 for a := 0 to High(gEvents) do
7365 if gEvents[a].Name = P[1] then
7366 if gEvents[a].Command = '' then
7367 g_Console_Add(gEvents[a].Name + ' <none>')
7368 else
7369 g_Console_Add(gEvents[a].Name + ' "' + gEvents[a].Command + '"');
7370 Exit;
7371 end;
7372 for a := 0 to High(gEvents) do
7373 if gEvents[a].Name = P[1] then
7374 begin
7375 gEvents[a].Command := '';
7376 for b := 2 to High(P) do
7377 if Pos(' ', P[b]) = 0 then
7378 gEvents[a].Command := gEvents[a].Command + ' ' + P[b]
7379 else
7380 gEvents[a].Command := gEvents[a].Command + ' "' + P[b] + '"';
7381 gEvents[a].Command := Trim(gEvents[a].Command);
7382 Exit;
7383 end;
7384 end
7385 else if cmd = 'suicide' then
7386 begin
7387 if gGameOn then
7388 begin
7389 if g_Game_IsClient then
7390 MC_SEND_CheatRequest(NET_CHEAT_SUICIDE)
7391 else
7392 begin
7393 if gPlayer1 <> nil then
7394 gPlayer1.Damage(SUICIDE_DAMAGE, gPlayer1.UID, 0, 0, HIT_SELF);
7395 if gPlayer2 <> nil then
7396 gPlayer2.Damage(SUICIDE_DAMAGE, gPlayer2.UID, 0, 0, HIT_SELF);
7397 end;
7398 end;
7399 end
7400 else if cmd = 'screenshot' then
7401 begin
7402 g_TakeScreenShot()
7403 end
7404 else if (cmd = 'weapnext') or (cmd = 'weapprev') then
7405 begin
7406 a := 1 - (ord(cmd[5]) - ord('n'));
7407 if a = -1 then
7408 gWeaponAction[0, WP_PREV] := True;
7409 if a = 1 then
7410 gWeaponAction[0, WP_NEXT] := True;
7411 end
7412 else if cmd = 'weapon' then
7413 begin
7414 if Length(p) = 2 then
7415 begin
7416 a := WP_FIRST + StrToInt(p[1]) - 1;
7417 if (a >= WP_FIRST) and (a <= WP_LAST) then
7418 gSelectWeapon[0, a] := True
7419 end
7420 end
7421 else if (cmd = 'p1_weapnext') or (cmd = 'p1_weapprev')
7422 or (cmd = 'p2_weapnext') or (cmd = 'p2_weapprev') then
7423 begin
7424 a := 1 - (ord(cmd[8]) - ord('n'));
7425 b := ord(cmd[2]) - ord('1');
7426 if a = -1 then
7427 gWeaponAction[b, WP_PREV] := True;
7428 if a = 1 then
7429 gWeaponAction[b, WP_NEXT] := True;
7430 end
7431 else if (cmd = 'p1_weapon') or (cmd = 'p2_weapon') then
7432 begin
7433 if Length(p) = 2 then
7434 begin
7435 a := WP_FIRST + StrToInt(p[1]) - 1;
7436 b := ord(cmd[2]) - ord('1');
7437 if (a >= WP_FIRST) and (a <= WP_LAST) then
7438 gSelectWeapon[b, a] := True
7439 end
7440 end
7441 else if (cmd = 'p1_weapbest') or (cmd = 'p2_weapbest') then
7442 begin
7443 b := ord(cmd[2]) - ord('1');
7444 if b = 0 then
7445 gSelectWeapon[b, gPlayer1.GetMorePrefered()] := True
7446 else
7447 gSelectWeapon[b, gPlayer2.GetMorePrefered()] := True;
7448 end
7449 else if (cmd = 'dropflag') then
7450 begin
7451 if g_Game_IsServer then
7452 begin
7453 if gPlayer2 <> nil then gPlayer2.TryDropFlag();
7454 if gPlayer1 <> nil then gPlayer1.TryDropFlag();
7455 end
7456 else
7457 MC_SEND_CheatRequest(NET_CHEAT_DROPFLAG);
7458 end
7459 else if (cmd = 'p1_dropflag') or (cmd = 'p2_dropflag') then
7460 begin
7461 b := ord(cmd[2]) - ord('1');
7462 if g_Game_IsServer then
7463 begin
7464 if (b = 1) and (gPlayer2 <> nil) then gPlayer2.TryDropFlag()
7465 else if (b = 0) and (gPlayer1 <> nil) then gPlayer1.TryDropFlag();
7466 end
7467 else
7468 MC_SEND_CheatRequest(NET_CHEAT_DROPFLAG);
7469 end
7470 // Êîìàíäû Ñâîåé èãðû:
7471 else if gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT] then
7472 begin
7473 if cmd = 'bot_addred' then
7474 begin
7475 if Length(P) > 1 then
7476 g_Bot_Add(TEAM_RED, StrToIntDef(P[1], 2))
7477 else
7478 g_Bot_Add(TEAM_RED, 2);
7479 end
7480 else if cmd = 'bot_addblue' then
7481 begin
7482 if Length(P) > 1 then
7483 g_Bot_Add(TEAM_BLUE, StrToIntDef(P[1], 2))
7484 else
7485 g_Bot_Add(TEAM_BLUE, 2);
7486 end
7487 else if cmd = 'spectate' then
7488 begin
7489 if not gGameOn then
7490 Exit;
7491 g_Game_Spectate();
7492 end
7493 else if cmd = 'say' then
7494 begin
7495 if g_Game_IsServer and g_Game_IsNet then
7496 begin
7497 if Length(P) > 1 then
7498 begin
7499 chstr := '';
7500 for a := 1 to High(P) do
7501 chstr := chstr + P[a] + ' ';
7503 if Length(chstr) > 200 then SetLength(chstr, 200);
7505 if Length(chstr) < 1 then
7506 begin
7507 g_Console_Add('say <text>');
7508 Exit;
7509 end;
7511 chstr := b_Text_Format(chstr);
7512 MH_SEND_Chat(chstr, NET_CHAT_PLAYER);
7513 end
7514 else g_Console_Add('say <text>');
7515 end else
7516 g_Console_Add(_lc[I_MSG_SERVERONLY]);
7517 end
7518 else if cmd = 'tell' then
7519 begin
7520 if g_Game_IsServer and g_Game_IsNet then
7521 begin
7522 if (Length(P) > 2) and (P[1] <> '') then
7523 begin
7524 chstr := '';
7525 for a := 2 to High(P) do
7526 chstr := chstr + P[a] + ' ';
7528 if Length(chstr) > 200 then SetLength(chstr, 200);
7530 if Length(chstr) < 1 then
7531 begin
7532 g_Console_Add('tell <playername> <text>');
7533 Exit;
7534 end;
7536 pl := g_Net_Client_ByName(P[1]);
7537 if pl <> nil then
7538 MH_SEND_Chat(b_Text_Format(chstr), NET_CHAT_PLAYER, pl^.ID)
7539 else
7540 g_Console_Add(Format(_lc[I_NET_ERR_NAME404], [P[1]]));
7541 end
7542 else g_Console_Add('tell <playername> <text>');
7543 end else
7544 g_Console_Add(_lc[I_MSG_SERVERONLY]);
7545 end
7546 else if cmd = 'centerprint' then
7547 begin
7548 if (Length(P) > 2) and (P[1] <> '') then
7549 begin
7550 chstr := '';
7551 for a := 2 to High(P) do
7552 chstr := chstr + P[a] + ' ';
7554 if Length(chstr) > 200 then SetLength(chstr, 200);
7556 if Length(chstr) < 1 then
7557 begin
7558 g_Console_Add('centerprint <timeout> <text>');
7559 Exit;
7560 end;
7562 a := StrToIntDef(P[1], 100);
7563 chstr := b_Text_Format(chstr);
7564 g_Game_Message(chstr, a);
7565 if g_Game_IsNet and g_Game_IsServer then
7566 MH_SEND_GameEvent(NET_EV_BIGTEXT, a, chstr);
7567 end
7568 else g_Console_Add('centerprint <timeout> <text>');
7569 end
7570 else if (cmd = 'overtime') and not g_Game_IsClient then
7571 begin
7572 if (Length(P) = 1) or (StrToIntDef(P[1], -1) <= 0) then
7573 Exit;
7574 // Äîïîëíèòåëüíîå âðåìÿ:
7575 gGameSettings.TimeLimit := (gTime - gGameStartTime) div 1000 + Word(StrToIntDef(P[1], 0));
7577 g_Console_Add(Format(_lc[I_MSG_TIME_LIMIT],
7578 [gGameSettings.TimeLimit div 3600,
7579 (gGameSettings.TimeLimit div 60) mod 60,
7580 gGameSettings.TimeLimit mod 60]));
7581 if g_Game_IsNet then MH_SEND_GameSettings;
7582 end
7583 else if (cmd = 'rcon_password') and g_Game_IsClient then
7584 begin
7585 if (Length(P) <= 1) then
7586 g_Console_Add('rcon_password <password>')
7587 else
7588 MC_SEND_RCONPassword(P[1]);
7589 end
7590 else if cmd = 'rcon' then
7591 begin
7592 if g_Game_IsClient then
7593 begin
7594 if Length(P) > 1 then
7595 begin
7596 chstr := '';
7597 for a := 1 to High(P) do
7598 chstr := chstr + P[a] + ' ';
7600 if Length(chstr) > 200 then SetLength(chstr, 200);
7602 if Length(chstr) < 1 then
7603 begin
7604 g_Console_Add('rcon <command>');
7605 Exit;
7606 end;
7608 MC_SEND_RCONCommand(chstr);
7609 end
7610 else g_Console_Add('rcon <command>');
7611 end;
7612 end
7613 else if cmd = 'ready' then
7614 begin
7615 if g_Game_IsServer and (gLMSRespawn = LMS_RESPAWN_WARMUP) then
7616 gLMSRespawnTime := gTime + 100;
7617 end
7618 else if (cmd = 'callvote') and g_Game_IsNet then
7619 begin
7620 if Length(P) > 1 then
7621 begin
7622 chstr := '';
7623 for a := 1 to High(P) do begin
7624 if a > 1 then chstr := chstr + ' ';
7625 chstr := chstr + P[a];
7626 end;
7628 if Length(chstr) > 200 then SetLength(chstr, 200);
7630 if Length(chstr) < 1 then
7631 begin
7632 g_Console_Add('callvote <command>');
7633 Exit;
7634 end;
7636 if g_Game_IsClient then
7637 MC_SEND_Vote(True, chstr)
7638 else
7639 g_Game_StartVote(chstr, gPlayer1Settings.Name);
7640 g_Console_Process('vote', True);
7641 end
7642 else
7643 g_Console_Add('callvote <command>');
7644 end
7645 else if (cmd = 'vote') and g_Game_IsNet then
7646 begin
7647 if g_Game_IsClient then
7648 MC_SEND_Vote(False)
7649 else if gVoteInProgress then
7650 begin
7651 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
7652 a := Floor((NetClientCount+1)/2.0) + 1
7653 else
7654 a := Floor(NetClientCount/2.0) + 1;
7655 if gVoted then
7656 begin
7657 Dec(gVoteCount);
7658 gVoted := False;
7659 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_REVOKED], [gPlayer1Settings.Name, gVoteCount, a]), True);
7660 MH_SEND_VoteEvent(NET_VE_REVOKE, gPlayer1Settings.Name, 'a', gVoteCount, a);
7661 end
7662 else
7663 begin
7664 Inc(gVoteCount);
7665 gVoted := True;
7666 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_VOTE], [gPlayer1Settings.Name, gVoteCount, a]), True);
7667 MH_SEND_VoteEvent(NET_VE_VOTE, gPlayer1Settings.Name, 'a', gVoteCount, a);
7668 g_Game_CheckVote;
7669 end;
7670 end;
7671 end
7672 end;
7673 end;
7675 procedure SystemCommands(P: SSArray);
7676 var
7677 cmd: string;
7678 begin
7679 cmd := LowerCase(P[0]);
7680 case cmd of
7681 'exit', 'quit':
7682 begin
7683 g_Game_Free();
7684 g_Game_Quit();
7685 end;
7686 'r_reset':
7687 begin
7688 gRC_Width := Max(1, gRC_Width);
7689 gRC_Height := Max(1, gRC_Height);
7690 gBPP := Max(1, gBPP);
7691 if sys_SetDisplayMode(gRC_Width, gRC_Height, gBPP, gRC_FullScreen, gRC_Maximized) = True then
7692 e_LogWriteln('resolution changed')
7693 else
7694 e_LogWriteln('resolution not changed');
7695 sys_EnableVSync(gVSync);
7696 end;
7697 'r_maxfps':
7698 begin
7699 if Length(p) = 2 then
7700 begin
7701 gMaxFPS := StrToIntDef(p[1], gMaxFPS);
7702 if gMaxFPS > 0 then
7703 gFrameTime := 1000 div gMaxFPS
7704 else
7705 gFrameTime := 0;
7706 end;
7707 e_LogWritefln('r_maxfps %d', [gMaxFPS]);
7708 end;
7709 'g_language':
7710 begin
7711 if Length(p) = 2 then
7712 begin
7713 gAskLanguage := true;
7714 gLanguage := LANGUAGE_ENGLISH;
7715 case LowerCase(p[1]) of
7716 'english':
7717 begin
7718 gAskLanguage := false;
7719 gLanguage := LANGUAGE_ENGLISH;
7720 end;
7721 'russian':
7722 begin
7723 gAskLanguage := false;
7724 gLanguage := LANGUAGE_RUSSIAN;
7725 end;
7726 'ask':
7727 begin
7728 gAskLanguage := true;
7729 gLanguage := LANGUAGE_ENGLISH;
7730 end;
7731 end;
7732 g_Language_Set(gLanguage);
7733 end
7734 else
7735 begin
7736 e_LogWritefln('usage: %s <English|Russian|Ask>', [cmd]);
7737 end
7738 end;
7739 end;
7740 end;
7742 procedure g_TakeScreenShot(Filename: string = '');
7743 var s: TStream; t: TDateTime; dir, date, name: String;
7744 begin
7745 if e_NoGraphics then Exit;
7746 try
7747 dir := e_GetWriteableDir(ScreenshotDirs);
7749 if Filename = '' then
7750 begin
7751 t := Now;
7752 DateTimeToString(date, 'yyyy-mm-dd-hh-nn-ss', t);
7753 Filename := 'screenshot-' + date;
7754 end;
7756 name := e_CatPath(dir, Filename + '.png');
7757 s := createDiskFile(name);
7758 try
7759 e_MakeScreenshot(s, gScreenWidth, gScreenHeight);
7760 s.Free;
7761 g_Console_Add(Format(_lc[I_CONSOLE_SCREENSHOT], [name]))
7762 except
7763 g_Console_Add(Format(_lc[I_CONSOLE_ERROR_WRITE], [name]));
7764 s.Free;
7765 DeleteFile(name)
7766 end
7767 except
7768 g_Console_Add('oh shit, i can''t create screenshot!')
7769 end
7770 end;
7772 procedure g_Game_InGameMenu(Show: Boolean);
7773 begin
7774 if (g_ActiveWindow = nil) and Show then
7775 begin
7776 if gGameSettings.GameType = GT_SINGLE then
7777 g_GUI_ShowWindow('GameSingleMenu')
7778 else
7779 begin
7780 if g_Game_IsClient then
7781 g_GUI_ShowWindow('GameClientMenu')
7782 else
7783 if g_Game_IsNet then
7784 g_GUI_ShowWindow('GameServerMenu')
7785 else
7786 g_GUI_ShowWindow('GameCustomMenu');
7787 end;
7788 g_Sound_PlayEx('MENU_OPEN');
7790 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
7791 if (not g_Game_IsNet) then
7792 g_Game_Pause(True);
7793 end
7794 else
7795 if (g_ActiveWindow <> nil) and (not Show) then
7796 begin
7797 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
7798 if (not g_Game_IsNet) then
7799 g_Game_Pause(False);
7800 end;
7801 end;
7803 procedure g_Game_Pause (Enable: Boolean);
7804 var
7805 oldPause: Boolean;
7806 begin
7807 if not gGameOn then exit;
7809 if not (gGameSettings.GameType in [GT_SINGLE, GT_CUSTOM]) then exit;
7811 oldPause := gPause;
7812 gPauseMain := Enable;
7814 if (gPause <> oldPause) then g_Game_PauseAllSounds(gPause);
7815 end;
7817 procedure g_Game_HolmesPause (Enable: Boolean);
7818 var
7819 oldPause: Boolean;
7820 begin
7821 if not gGameOn then exit;
7822 if not (gGameSettings.GameType in [GT_SINGLE, GT_CUSTOM]) then exit;
7824 oldPause := gPause;
7825 gPauseHolmes := Enable;
7827 if (gPause <> oldPause) then g_Game_PauseAllSounds(gPause);
7828 end;
7830 procedure g_Game_PauseAllSounds(Enable: Boolean);
7831 var
7832 i: Integer;
7833 begin
7834 // Òðèããåðû:
7835 if gTriggers <> nil then
7836 for i := 0 to High(gTriggers) do
7837 with gTriggers[i] do
7838 if (TriggerType = TRIGGER_SOUND) and
7839 (Sound <> nil) and
7840 Sound.IsPlaying() then
7841 begin
7842 Sound.Pause(Enable);
7843 end;
7845 // Çâóêè èãðîêîâ:
7846 if gPlayers <> nil then
7847 for i := 0 to High(gPlayers) do
7848 if gPlayers[i] <> nil then
7849 gPlayers[i].PauseSounds(Enable);
7851 // Ìóçûêà:
7852 if gMusic <> nil then
7853 gMusic.Pause(Enable);
7854 end;
7856 procedure g_Game_StopAllSounds(all: Boolean);
7857 var
7858 i: Integer;
7859 begin
7860 if gTriggers <> nil then
7861 for i := 0 to High(gTriggers) do
7862 with gTriggers[i] do
7863 if (TriggerType = TRIGGER_SOUND) and
7864 (Sound <> nil) then
7865 Sound.Stop();
7867 if gMusic <> nil then
7868 gMusic.Stop();
7870 if all then
7871 e_StopChannels();
7872 end;
7874 procedure g_Game_UpdateTriggerSounds;
7875 var i: Integer;
7876 begin
7877 if gTriggers <> nil then
7878 for i := 0 to High(gTriggers) do
7879 with gTriggers[i] do
7880 if (TriggerType = TRIGGER_SOUND) and (Sound <> nil) and tgcLocal and Sound.IsPlaying() then
7881 Sound.SetCoordsRect(X, Y, Width, Height, tgcVolume / 255.0)
7882 end;
7884 function g_Game_IsWatchedPlayer(UID: Word): Boolean;
7885 begin
7886 Result := False;
7887 if (gPlayer1 <> nil) and (gPlayer1.UID = UID) then
7888 begin
7889 Result := True;
7890 Exit;
7891 end;
7892 if (gPlayer2 <> nil) and (gPlayer2.UID = UID) then
7893 begin
7894 Result := True;
7895 Exit;
7896 end;
7897 if gSpectMode <> SPECT_PLAYERS then
7898 Exit;
7899 if gSpectPID1 = UID then
7900 begin
7901 Result := True;
7902 Exit;
7903 end;
7904 if gSpectViewTwo and (gSpectPID2 = UID) then
7905 begin
7906 Result := True;
7907 Exit;
7908 end;
7909 end;
7911 function g_Game_IsWatchedTeam(Team: Byte): Boolean;
7912 var
7913 Pl: TPlayer;
7914 begin
7915 Result := False;
7916 if (gPlayer1 <> nil) and (gPlayer1.Team = Team) then
7917 begin
7918 Result := True;
7919 Exit;
7920 end;
7921 if (gPlayer2 <> nil) and (gPlayer2.Team = Team) then
7922 begin
7923 Result := True;
7924 Exit;
7925 end;
7926 if gSpectMode <> SPECT_PLAYERS then
7927 Exit;
7928 Pl := g_Player_Get(gSpectPID1);
7929 if (Pl <> nil) and (Pl.Team = Team) then
7930 begin
7931 Result := True;
7932 Exit;
7933 end;
7934 if gSpectViewTwo then
7935 begin
7936 Pl := g_Player_Get(gSpectPID2);
7937 if (Pl <> nil) and (Pl.Team = Team) then
7938 begin
7939 Result := True;
7940 Exit;
7941 end;
7942 end;
7943 end;
7945 procedure g_Game_Message(Msg: string; Time: Word);
7946 begin
7947 MessageLineLength := (gScreenWidth - 204) div e_CharFont_GetMaxWidth(gMenuFont);
7948 MessageText := b_Text_Wrap(b_Text_Format(Msg), MessageLineLength);
7949 MessageTime := Time;
7950 end;
7952 procedure g_Game_ChatSound(Text: String; Taunt: Boolean = True);
7953 const
7954 punct: Array[0..13] of String =
7955 ('.', ',', ':', ';', '!', '?', '(', ')', '''', '"', '/', '\', '*', '^');
7956 var
7957 i, j: Integer;
7958 ok: Boolean;
7959 fpText: String;
7961 function IsPunctuation(S: String): Boolean;
7962 var
7963 i: Integer;
7964 begin
7965 Result := False;
7966 if Length(S) <> 1 then
7967 Exit;
7968 for i := Low(punct) to High(punct) do
7969 if S = punct[i] then
7970 begin
7971 Result := True;
7972 break;
7973 end;
7974 end;
7975 function FilterPunctuation(S: String): String;
7976 var
7977 i: Integer;
7978 begin
7979 for i := Low(punct) to High(punct) do
7980 S := StringReplace(S, punct[i], ' ', [rfReplaceAll]);
7981 Result := S;
7982 end;
7983 begin
7984 ok := False;
7986 if gUseChatSounds and Taunt and (gChatSounds <> nil) and (Pos(': ', Text) > 0) then
7987 begin
7988 // remove player name
7989 Delete(Text, 1, Pos(': ', Text) + 2 - 1);
7990 // for FullWord check
7991 Text := toLowerCase1251(' ' + Text + ' ');
7992 fpText := FilterPunctuation(Text);
7994 for i := 0 to Length(gChatSounds) - 1 do
7995 begin
7996 ok := True;
7997 for j := 0 to Length(gChatSounds[i].Tags) - 1 do
7998 begin
7999 if gChatSounds[i].FullWord and (not IsPunctuation(gChatSounds[i].Tags[j])) then
8000 ok := Pos(' ' + gChatSounds[i].Tags[j] + ' ', fpText) > 0
8001 else
8002 ok := Pos(gChatSounds[i].Tags[j], Text) > 0;
8003 if not ok then
8004 break;
8005 end;
8006 if ok then
8007 begin
8008 gChatSounds[i].Sound.Play();
8009 break;
8010 end;
8011 end;
8012 end;
8013 if not ok then
8014 g_Sound_PlayEx('SOUND_GAME_RADIO');
8015 end;
8017 procedure g_Game_Announce_GoodShot(SpawnerUID: Word);
8018 var
8019 a: Integer;
8020 begin
8021 case gAnnouncer of
8022 ANNOUNCE_NONE:
8023 Exit;
8024 ANNOUNCE_ME,
8025 ANNOUNCE_MEPLUS:
8026 if not g_Game_IsWatchedPlayer(SpawnerUID) then
8027 Exit;
8028 end;
8029 for a := 0 to 3 do
8030 if goodsnd[a].IsPlaying() then
8031 Exit;
8033 goodsnd[Random(4)].Play();
8034 end;
8036 procedure g_Game_Announce_KillCombo(Param: Integer);
8037 var
8038 UID: Word;
8039 c, n: Byte;
8040 Pl: TPlayer;
8041 Name: String;
8042 begin
8043 UID := Param and $FFFF;
8044 c := Param shr 16;
8045 if c < 2 then
8046 Exit;
8048 Pl := g_Player_Get(UID);
8049 if Pl = nil then
8050 Name := '?'
8051 else
8052 Name := Pl.Name;
8054 case c of
8055 2: begin
8056 n := 0;
8057 g_Console_Add(Format(_lc[I_PLAYER_KILL_2X], [Name]), True);
8058 end;
8059 3: begin
8060 n := 1;
8061 g_Console_Add(Format(_lc[I_PLAYER_KILL_3X], [Name]), True);
8062 end;
8063 4: begin
8064 n := 2;
8065 g_Console_Add(Format(_lc[I_PLAYER_KILL_4X], [Name]), True);
8066 end;
8067 else begin
8068 n := 3;
8069 g_Console_Add(Format(_lc[I_PLAYER_KILL_MX], [Name]), True);
8070 end;
8071 end;
8073 case gAnnouncer of
8074 ANNOUNCE_NONE:
8075 Exit;
8076 ANNOUNCE_ME:
8077 if not g_Game_IsWatchedPlayer(UID) then
8078 Exit;
8079 ANNOUNCE_MEPLUS:
8080 if (not g_Game_IsWatchedPlayer(UID)) and (c < 4) then
8081 Exit;
8082 end;
8084 if killsnd[n].IsPlaying() then
8085 killsnd[n].Stop();
8086 killsnd[n].Play();
8087 end;
8089 procedure g_Game_Announce_BodyKill(SpawnerUID: Word);
8090 var
8091 a: Integer;
8092 begin
8093 case gAnnouncer of
8094 ANNOUNCE_NONE:
8095 Exit;
8096 ANNOUNCE_ME:
8097 if not g_Game_IsWatchedPlayer(SpawnerUID) then
8098 Exit;
8099 end;
8100 for a := 0 to 2 do
8101 if hahasnd[a].IsPlaying() then
8102 Exit;
8104 hahasnd[Random(3)].Play();
8105 end;
8107 procedure g_Game_StartVote(Command, Initiator: string);
8108 var
8109 Need: Integer;
8110 begin
8111 if not gVotesEnabled then Exit;
8112 if gGameSettings.GameType <> GT_SERVER then Exit;
8113 if gVoteInProgress or gVotePassed then
8114 begin
8115 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_INPROGRESS], [gVoteCommand]), True);
8116 MH_SEND_VoteEvent(NET_VE_INPROGRESS, gVoteCommand);
8117 Exit;
8118 end;
8119 gVoteInProgress := True;
8120 gVotePassed := False;
8121 gVoteTimer := gTime + gVoteTimeout * 1000;
8122 gVoteCount := 0;
8123 gVoted := False;
8124 gVoteCommand := Command;
8126 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
8127 Need := Floor((NetClientCount+1)/2.0)+1
8128 else
8129 Need := Floor(NetClientCount/2.0)+1;
8130 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_STARTED], [Initiator, Command, Need]), True);
8131 MH_SEND_VoteEvent(NET_VE_STARTED, Initiator, Command, Need);
8132 end;
8134 procedure g_Game_CheckVote;
8135 var
8136 I, Need: Integer;
8137 begin
8138 if gGameSettings.GameType <> GT_SERVER then Exit;
8139 if not gVoteInProgress then Exit;
8141 if (gTime >= gVoteTimer) then
8142 begin
8143 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
8144 Need := Floor((NetClientCount+1)/2.0) + 1
8145 else
8146 Need := Floor(NetClientCount/2.0) + 1;
8147 if gVoteCount >= Need then
8148 begin
8149 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_PASSED], [gVoteCommand]), True);
8150 MH_SEND_VoteEvent(NET_VE_PASSED, gVoteCommand);
8151 gVotePassed := True;
8152 gVoteCmdTimer := gTime + 5000;
8153 end
8154 else
8155 begin
8156 g_Console_Add(_lc[I_MESSAGE_VOTE_FAILED], True);
8157 MH_SEND_VoteEvent(NET_VE_FAILED);
8158 end;
8159 if NetClients <> nil then
8160 for I := Low(NetClients) to High(NetClients) do
8161 if NetClients[i].Used then
8162 NetClients[i].Voted := False;
8163 gVoteInProgress := False;
8164 gVoted := False;
8165 gVoteCount := 0;
8166 end
8167 else
8168 begin
8169 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
8170 Need := Floor((NetClientCount+1)/2.0) + 1
8171 else
8172 Need := Floor(NetClientCount/2.0) + 1;
8173 if gVoteCount >= Need then
8174 begin
8175 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_PASSED], [gVoteCommand]), True);
8176 MH_SEND_VoteEvent(NET_VE_PASSED, gVoteCommand);
8177 gVoteInProgress := False;
8178 gVotePassed := True;
8179 gVoteCmdTimer := gTime + 5000;
8180 gVoted := False;
8181 gVoteCount := 0;
8182 if NetClients <> nil then
8183 for I := Low(NetClients) to High(NetClients) do
8184 if NetClients[i].Used then
8185 NetClients[i].Voted := False;
8186 end;
8187 end;
8188 end;
8190 procedure g_Game_LoadMapList(FileName: string);
8191 var
8192 ListFile: TextFile;
8193 s: string;
8194 begin
8195 MapList := nil;
8196 MapIndex := -1;
8198 if not FileExists(FileName) then Exit;
8200 AssignFile(ListFile, FileName);
8201 Reset(ListFile);
8202 while not EOF(ListFile) do
8203 begin
8204 ReadLn(ListFile, s);
8206 s := Trim(s);
8207 if s = '' then Continue;
8209 SetLength(MapList, Length(MapList)+1);
8210 MapList[High(MapList)] := s;
8211 end;
8212 CloseFile(ListFile);
8213 end;
8215 procedure g_Game_SetDebugMode();
8216 begin
8217 gDebugMode := True;
8218 // ×èòû (äàæå â ñâîåé èãðå):
8219 gCheats := True;
8220 end;
8222 procedure g_Game_SetLoadingText(Text: String; Max: Integer; reWrite: Boolean);
8223 var
8224 i: Word;
8225 begin
8226 if Length(LoadingStat.Msgs) = 0 then
8227 Exit;
8229 with LoadingStat do
8230 begin
8231 if not reWrite then
8232 begin // Ïåðåõîäèì íà ñëåäóþùóþ ñòðîêó èëè ñêðîëëèðóåì:
8233 if NextMsg = Length(Msgs) then
8234 begin // scroll
8235 for i := 0 to High(Msgs)-1 do
8236 Msgs[i] := Msgs[i+1];
8237 end
8238 else
8239 Inc(NextMsg);
8240 end else
8241 if NextMsg = 0 then
8242 Inc(NextMsg);
8244 Msgs[NextMsg-1] := Text;
8245 CurValue := 0;
8246 MaxValue := Max;
8247 ShowCount := 0;
8248 PBarWasHere := false;
8249 end;
8251 g_ActiveWindow := nil;
8253 ProcessLoading(true);
8254 end;
8256 procedure g_Game_StepLoading(Value: Integer = -1);
8257 begin
8258 with LoadingStat do
8259 begin
8260 if Value = -1 then
8261 begin
8262 Inc(CurValue);
8263 Inc(ShowCount);
8264 end
8265 else
8266 CurValue := Value;
8267 if (ShowCount > LOADING_SHOW_STEP) or (Value > -1) then
8268 begin
8269 ShowCount := 0;
8270 ProcessLoading();
8271 end;
8272 end;
8273 end;
8275 procedure g_Game_ClearLoading();
8276 var
8277 len: Word;
8278 begin
8279 with LoadingStat do
8280 begin
8281 CurValue := 0;
8282 MaxValue := 0;
8283 ShowCount := 0;
8284 len := ((gScreenHeight div 3)*2 - 50) div LOADING_INTERLINE;
8285 if len < 1 then len := 1;
8286 SetLength(Msgs, len);
8287 for len := Low(Msgs) to High(Msgs) do
8288 Msgs[len] := '';
8289 NextMsg := 0;
8290 PBarWasHere := false;
8291 end;
8292 end;
8294 procedure Parse_Params(var pars: TParamStrValues);
8295 var
8296 i: Integer;
8297 s: String;
8298 begin
8299 SetLength(pars, 0);
8300 i := 1;
8301 while i <= ParamCount do
8302 begin
8303 s := ParamStr(i);
8304 if (Length(s) > 1) and (s[1] = '-') then
8305 begin
8306 if (Length(s) > 2) and (s[2] = '-') then
8307 begin // Îäèíî÷íûé ïàðàìåòð
8308 SetLength(pars, Length(pars) + 1);
8309 with pars[High(pars)] do
8310 begin
8311 Name := LowerCase(s);
8312 Value := '+';
8313 end;
8314 end
8315 else
8316 if (i < ParamCount) then
8317 begin // Ïàðàìåòð ñî çíà÷åíèåì
8318 Inc(i);
8319 SetLength(pars, Length(pars) + 1);
8320 with pars[High(pars)] do
8321 begin
8322 Name := LowerCase(s);
8323 Value := LowerCase(ParamStr(i));
8324 end;
8325 end;
8326 end;
8328 Inc(i);
8329 end;
8330 end;
8332 function Find_Param_Value(var pars: TParamStrValues; aName: String): String;
8333 var
8334 i: Integer;
8335 begin
8336 Result := '';
8337 for i := 0 to High(pars) do
8338 if pars[i].Name = aName then
8339 begin
8340 Result := pars[i].Value;
8341 Break;
8342 end;
8343 end;
8345 procedure g_Game_Process_Params();
8346 var
8347 pars: TParamStrValues;
8348 map: String;
8349 GMode, n: Byte;
8350 LimT, LimS: Integer;
8351 Opt: LongWord;
8352 Lives: Integer;
8353 s: String;
8354 Port: Integer;
8355 ip: String;
8356 F: TextFile;
8357 begin
8358 Parse_Params(pars);
8360 // Debug mode:
8361 s := Find_Param_Value(pars, '--debug');
8362 if (s <> '') then
8363 begin
8364 g_Game_SetDebugMode();
8365 s := Find_Param_Value(pars, '--netdump');
8366 if (s <> '') then
8367 NetDump := True;
8368 end;
8370 // Connect when game loads
8371 ip := Find_Param_Value(pars, '-connect');
8373 if ip <> '' then
8374 begin
8375 s := Find_Param_Value(pars, '-port');
8376 if (s = '') or not TryStrToInt(s, Port) then
8377 Port := 25666;
8379 s := Find_Param_Value(pars, '-pw');
8381 g_Game_StartClient(ip, Port, s);
8382 Exit;
8383 end;
8385 s := LowerCase(Find_Param_Value(pars, '-dbg-mainwad'));
8386 if (s <> '') then
8387 begin
8388 gDefaultMegawadStart := s;
8389 end;
8391 if (Find_Param_Value(pars, '--dbg-mainwad-restore') <> '') or
8392 (Find_Param_Value(pars, '--dbg-mainwad-default') <> '') then
8393 begin
8394 gDefaultMegawadStart := DF_Default_Megawad_Start;
8395 end;
8397 // Start map when game loads:
8398 map := LowerCase(Find_Param_Value(pars, '-map'));
8399 if isWadPath(map) then
8400 begin
8401 // Game mode:
8402 s := Find_Param_Value(pars, '-gm');
8403 GMode := g_Game_TextToMode(s);
8404 if GMode = GM_NONE then GMode := GM_DM;
8405 if GMode = GM_SINGLE then GMode := GM_COOP;
8407 // Time limit:
8408 s := Find_Param_Value(pars, '-limt');
8409 if (s = '') or (not TryStrToInt(s, LimT)) then
8410 LimT := 0;
8411 if LimT < 0 then
8412 LimT := 0;
8414 // Goal limit:
8415 s := Find_Param_Value(pars, '-lims');
8416 if (s = '') or (not TryStrToInt(s, LimS)) then
8417 LimS := 0;
8418 if LimS < 0 then
8419 LimS := 0;
8421 // Lives limit:
8422 s := Find_Param_Value(pars, '-lives');
8423 if (s = '') or (not TryStrToInt(s, Lives)) then
8424 Lives := 0;
8425 if Lives < 0 then
8426 Lives := 0;
8428 // Options:
8429 s := Find_Param_Value(pars, '-opt');
8430 if (s = '') then
8431 Opt := gsGameFlags
8432 else
8433 Opt := StrToIntDef(s, 0);
8435 // Close after map:
8436 s := Find_Param_Value(pars, '--close');
8437 if (s <> '') then
8438 gMapOnce := True;
8440 // Override map to test:
8441 s := LowerCase(Find_Param_Value(pars, '-testmap'));
8442 if s <> '' then
8443 begin
8444 if e_IsValidResourceName(s) then
8445 e_FindResource(AllMapDirs, s);
8446 gTestMap := ExpandFileName(s);
8447 end;
8449 // Delete test map after play:
8450 s := Find_Param_Value(pars, '--testdelete');
8451 if (s <> '') then
8452 begin
8453 //gMapToDelete := MapsDir + map;
8454 e_WriteLog('"--testdelete" is deprecated, use --tempdelete.', TMsgType.Fatal);
8455 Halt(1);
8456 end;
8458 // Delete temporary WAD after play:
8459 s := Find_Param_Value(pars, '--tempdelete');
8460 if (s <> '') and (gTestMap <> '') then
8461 begin
8462 gMapToDelete := gTestMap;
8463 gTempDelete := True;
8464 end;
8466 // Number of players:
8467 s := Find_Param_Value(pars, '-pl');
8468 if (s = '') then
8469 n := DEFAULT_PLAYERS
8470 else
8471 n := StrToIntDef(s, DEFAULT_PLAYERS);
8473 // Start:
8474 s := Find_Param_Value(pars, '-port');
8475 if (s = '') or not TryStrToInt(s, Port) then
8476 g_Game_StartCustom(map, GMode, LimT, LimS, Lives, Opt, n)
8477 else
8478 g_Game_StartServer(map, GMode, LimT, LimS, Lives, Opt, n, 0, Port);
8479 end;
8481 // Execute script when game loads:
8482 s := Find_Param_Value(pars, '-exec');
8483 if s <> '' then
8484 begin
8485 // if not isWadPath(s) then
8486 // s := GameDir + '/' + s;
8488 {$I-}
8489 AssignFile(F, s);
8490 Reset(F);
8491 if IOResult <> 0 then
8492 begin
8493 e_WriteLog(Format(_lc[I_SIMPLE_ERROR], ['Failed to read file: ' + s]), TMsgType.Warning);
8494 g_Console_Add(Format(_lc[I_CONSOLE_ERROR_READ], [s]));
8495 CloseFile(F);
8496 Exit;
8497 end;
8498 e_WriteLog('Executing script: ' + s, TMsgType.Notify);
8499 g_Console_Add(Format(_lc[I_CONSOLE_EXEC], [s]));
8501 while not EOF(F) do
8502 begin
8503 ReadLn(F, s);
8504 if IOResult <> 0 then
8505 begin
8506 e_WriteLog(Format(_lc[I_SIMPLE_ERROR], ['Failed to read file: ' + s]), TMsgType.Warning);
8507 g_Console_Add(Format(_lc[I_CONSOLE_ERROR_READ], [s]));
8508 CloseFile(F);
8509 Exit;
8510 end;
8511 if Pos('#', s) <> 1 then // script comment
8512 g_Console_Process(s, True);
8513 end;
8515 CloseFile(F);
8516 {$I+}
8517 end;
8519 SetLength(pars, 0);
8520 end;
8522 begin
8523 conRegVar('pf_draw_frame', @g_profile_frame_draw, 'draw frame rendering profiles', 'render profiles');
8524 //conRegVar('pf_update_frame', @g_profile_frame_update, 'draw frame updating profiles', 'update profiles');
8525 conRegVar('pf_coldet', @g_profile_collision, 'draw collision detection profiles', 'coldet profiles');
8526 conRegVar('pf_los', @g_profile_los, 'draw monster LOS profiles', 'monster LOS profiles');
8528 conRegVar('r_sq_draw', @gdbg_map_use_accel_render, 'accelerated spatial queries in rendering', 'accelerated rendering');
8529 conRegVar('cd_sq_enabled', @gdbg_map_use_accel_coldet, 'accelerated spatial queries in map coldet', 'accelerated map coldet');
8530 conRegVar('mon_sq_enabled', @gmon_debug_use_sqaccel, 'accelerated spatial queries for monsters', 'accelerated monster coldet');
8531 conRegVar('wtrace_sq_enabled', @gwep_debug_fast_trace, 'accelerated spatial queries for weapon hitscan trace', 'accelerated weapon hitscan');
8533 conRegVar('pr_enabled', @gpart_dbg_enabled, 'enable/disable particles', 'particles');
8534 conRegVar('pr_phys_enabled', @gpart_dbg_phys_enabled, 'enable/disable particle physics', 'particle physics');
8536 conRegVar('los_enabled', @gmon_dbg_los_enabled, 'enable/disable monster LOS calculations', 'monster LOS', true);
8537 conRegVar('mon_think', @gmon_debug_think, 'enable/disable monster thinking', 'monster thinking', true);
8539 {$IFDEF ENABLE_HOLMES}
8540 conRegVar('dbg_holmes', @g_holmes_enabled, 'enable/disable Holmes', 'Holmes', true);
8541 {$ENDIF}
8543 conRegVar('dbg_ignore_level_bounds', @g_dbg_ignore_bounds, 'ignore level bounds', '', false);
8545 conRegVar('r_scale', @g_dbg_scale, 0.01, 100.0, 'render scale', '', false);
8546 conRegVar('r_resolution_scale', @r_pixel_scale, 0.01, 100.0, 'upscale factor', '', false);
8548 conRegVar('light_enabled', @gwin_k8_enable_light_experiments, 'enable/disable dynamic lighting', 'lighting');
8549 conRegVar('light_player_halo', @g_playerLight, 'enable/disable player halo', 'player light halo');
8551 conRegVar('r_smallmap_align_h', @r_smallmap_h, 'halign: 0: left; 1: center; 2: right', 'horizontal aligning of small maps');
8552 conRegVar('r_smallmap_align_v', @r_smallmap_v, 'valign: 0: top; 1: center; 2: bottom', 'vertial aligning of small maps');
8554 conRegVar('r_showfps', @gShowFPS, 'draw fps counter', 'draw fps counter');
8555 conRegVar('r_showtime', @gShowTime, 'show game time', 'show game time');
8556 conRegVar('r_showping', @gShowPing, 'show ping', 'show ping');
8557 conRegVar('r_showscore', @gShowGoals, 'show score', 'show score');
8558 conRegVar('r_showkillmsg', @gShowKillMsg, 'show kill log', 'show kill log');
8559 conRegVar('r_showlives', @gShowLives, 'show lives', 'show lives');
8560 conRegVar('r_showspect', @gSpectHUD, 'show spectator hud', 'show spectator hud');
8561 conRegVar('r_showstat', @gShowStat, 'show stats', 'show stats');
8562 conRegVar('r_showpids', @gShowPIDs, 'show PIDs', 'show PIDs');
8563 end.