DEADSOFTWARE

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