DEADSOFTWARE

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