DEADSOFTWARE

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