DEADSOFTWARE

fmod -> sdl2 mixer, first part: we have music now; still no advanced stuff
[d2df-sdl.git] / src / game / g_game.pas
1 unit g_game;
3 interface
5 uses
6 g_basic, g_player, e_graphics, Classes, g_res_downloader,
7 SysUtils, g_sound, g_gui, MAPSTRUCT, WADEDITOR, md5;
9 type
10 TGameSettings = record
11 GameType: Byte;
12 GameMode: Byte;
13 TimeLimit: Word;
14 GoalLimit: Word;
15 WarmupTime: Word;
16 MaxLives: Byte;
17 Options: LongWord;
18 WAD: String;
19 end;
21 TGameEvent = record
22 Name: String;
23 Command: String;
24 end;
26 TDelayedEvent = record
27 Pending: Boolean;
28 Time: LongWord;
29 DEType: Byte;
30 DENum: Integer;
31 DEStr: String;
32 end;
34 TPlayerSettings = record
35 Name: String;
36 Model: String;
37 Color: TRGB;
38 Team: Byte;
39 end;
41 TMegaWADInfo = record
42 Name: String;
43 Description: String;
44 Author: String;
45 Pic: String;
46 end;
48 THearPoint = record
49 Active: Boolean;
50 Coords: TPoint;
51 end;
53 function g_Game_IsNet(): Boolean;
54 function g_Game_IsServer(): Boolean;
55 function g_Game_IsClient(): Boolean;
56 procedure g_Game_Init();
57 procedure g_Game_Free();
58 procedure g_Game_LoadData();
59 procedure g_Game_FreeData();
60 procedure g_Game_Update();
61 procedure g_Game_Draw();
62 procedure g_Game_Quit();
63 procedure g_Game_SetupScreenSize();
64 procedure g_Game_ChangeResolution(newWidth, newHeight: Word; nowFull, nowMax: Boolean);
65 function g_Game_ModeToText(Mode: Byte): string;
66 function g_Game_TextToMode(Mode: string): Byte;
67 procedure g_Game_ExecuteEvent(Name: String);
68 function g_Game_DelayEvent(DEType: Byte; Time: LongWord; Num: Integer = 0; Str: String = ''): Integer;
69 procedure g_Game_AddPlayer(Team: Byte = TEAM_NONE);
70 procedure g_Game_RemovePlayer();
71 procedure g_Game_Spectate();
72 procedure g_Game_SpectateCenterView();
73 procedure g_Game_StartSingle(Map: String; TwoPlayers: Boolean; nPlayers: Byte);
74 procedure g_Game_StartCustom(Map: String; GameMode: Byte; TimeLimit, GoalLimit: Word; MaxLives: Byte; Options: LongWord; nPlayers: Byte);
75 procedure g_Game_StartServer(Map: String; GameMode: Byte; TimeLimit, GoalLimit: Word; MaxLives: Byte; Options: LongWord; nPlayers: Byte; IPAddr: LongWord; Port: Word);
76 procedure g_Game_StartClient(Addr: String; Port: Word; PW: String);
77 procedure g_Game_Restart();
78 procedure g_Game_RestartLevel();
79 procedure g_Game_RestartRound(NoMapRestart: Boolean = False);
80 procedure g_Game_ClientWAD(NewWAD: String; WHash: TMD5Digest);
81 procedure g_Game_SaveOptions();
82 function g_Game_StartMap(Map: String; Force: Boolean = False): Boolean;
83 procedure g_Game_ChangeMap(MapPath: String);
84 procedure g_Game_ExitLevel(Map: Char16);
85 function g_Game_GetFirstMap(WAD: String): String;
86 function g_Game_GetNextMap(): String;
87 procedure g_Game_NextLevel();
88 procedure g_Game_Pause(Enable: Boolean);
89 procedure g_Game_InGameMenu(Show: Boolean);
90 function g_Game_IsWatchedPlayer(UID: Word): Boolean;
91 function g_Game_IsWatchedTeam(Team: Byte): Boolean;
92 procedure g_Game_Message(Msg: String; Time: Word);
93 procedure g_Game_LoadMapList(FileName: String);
94 procedure g_Game_PauseAllSounds(Enable: Boolean);
95 procedure g_Game_StopAllSounds(all: Boolean);
96 procedure g_Game_UpdateTriggerSounds();
97 function g_Game_GetMegaWADInfo(WAD: String): TMegaWADInfo;
98 procedure g_Game_Announce_GoodShot(SpawnerUID: Word);
99 procedure g_Game_Announce_KillCombo(Param: Integer);
100 procedure g_Game_StartVote(Command, Initiator: string);
101 procedure g_Game_CheckVote;
102 procedure g_TakeScreenShot();
103 procedure g_FatalError(Text: String);
104 procedure g_SimpleError(Text: String);
105 function g_Game_IsTestMap(): Boolean;
106 procedure g_Game_DeleteTestMap();
107 procedure GameCVars(P: SArray);
108 procedure GameCommands(P: SArray);
109 procedure DebugCommands(P: SArray);
110 procedure g_Game_Process_Params;
111 procedure g_Game_SetLoadingText(Text: String; Max: Integer; reWrite: Boolean);
112 procedure g_Game_StepLoading();
113 procedure g_Game_ClearLoading();
114 procedure g_Game_SetDebugMode();
115 procedure DrawLoadingStat();
117 { procedure SetWinPause(Enable: Boolean); }
119 const
120 GAME_TICK = 28;
122 LOADING_SHOW_STEP = 100;
123 LOADING_INTERLINE = 20;
125 GT_NONE = 0;
126 GT_SINGLE = 1;
127 GT_CUSTOM = 2;
128 GT_SERVER = 3;
129 GT_CLIENT = 4;
131 GM_NONE = 0;
132 GM_DM = 1;
133 GM_TDM = 2;
134 GM_CTF = 3;
135 GM_COOP = 4;
136 GM_SINGLE = 5;
138 MESSAGE_DIKEY = WM_USER + 1;
140 EXIT_QUIT = 1;
141 EXIT_SIMPLE = 2;
142 EXIT_RESTART = 3;
143 EXIT_ENDLEVELSINGLE = 4;
144 EXIT_ENDLEVELCUSTOM = 5;
146 GAME_OPTION_RESERVED = 1;
147 GAME_OPTION_TEAMDAMAGE = 2;
148 GAME_OPTION_ALLOWEXIT = 4;
149 GAME_OPTION_WEAPONSTAY = 8;
150 GAME_OPTION_MONSTERS = 16;
151 GAME_OPTION_BOTVSPLAYER = 32;
152 GAME_OPTION_BOTVSMONSTER = 64;
154 STATE_NONE = 0;
155 STATE_MENU = 1;
156 STATE_FOLD = 2;
157 STATE_INTERCUSTOM = 3;
158 STATE_INTERSINGLE = 4;
159 STATE_INTERTEXT = 5;
160 STATE_INTERPIC = 6;
161 STATE_ENDPIC = 7;
162 STATE_SLIST = 8;
164 LMS_RESPAWN_NONE = 0;
165 LMS_RESPAWN_WARMUP = 1;
166 LMS_RESPAWN_FINAL = 2;
168 SPECT_NONE = 0;
169 SPECT_STATS = 1;
170 SPECT_MAPVIEW = 2;
171 SPECT_PLAYERS = 3;
173 DE_GLOBEVENT = 0;
174 DE_BFGHIT = 1;
175 DE_KILLCOMBO = 2;
177 ANNOUNCE_NONE = 0;
178 ANNOUNCE_ME = 1;
179 ANNOUNCE_MEPLUS = 2;
180 ANNOUNCE_ALL = 3;
182 CONFIG_FILENAME = 'Doom2DF.cfg';
183 LOG_FILENAME = 'Doom2DF.log';
185 TEST_MAP_NAME = '$$$_TEST_$$$';
187 STD_PLAYER_MODEL = 'Doomer';
189 var
190 gStdFont: DWORD;
191 gGameSettings: TGameSettings;
192 gPlayer1Settings: TPlayerSettings;
193 gPlayer2Settings: TPlayerSettings;
194 gGameOn: Boolean;
195 gPlayerScreenSize: TPoint;
196 gPlayer1ScreenCoord: TPoint;
197 gPlayer2ScreenCoord: TPoint;
198 gPlayer1: TPlayer = nil;
199 gPlayer2: TPlayer = nil;
200 gPlayerDrawn: TPlayer = nil;
201 gTime: LongWord;
202 gSwitchGameMode: Byte = GM_DM;
203 gHearPoint1, gHearPoint2: THearPoint;
204 gSoundEffectsDF: Boolean = False;
205 gSoundTriggerTime: Word = 0;
206 gAnnouncer: Byte = ANNOUNCE_NONE;
207 goodsnd: array[0..3] of TPlayableSound;
208 killsnd: array[0..3] of TPlayableSound;
209 gDefInterTime: ShortInt = -1;
210 gInterEndTime: LongWord = 0;
211 gInterTime: LongWord = 0;
212 gServInterTime: Byte = 0;
213 gGameStartTime: LongWord = 0;
214 gTotalMonsters: Integer = 0;
215 gPause: Boolean;
216 gShowTime: Boolean = True;
217 gShowFPS: Boolean = False;
218 gShowGoals: Boolean = True;
219 gShowStat: Boolean = True;
220 gShowKillMsg: Boolean = True;
221 gShowLives: Boolean = True;
222 gShowPing: Boolean = False;
223 gShowMap: Boolean = False;
224 gExit: Byte = 0;
225 gState: Byte = STATE_NONE;
226 sX, sY: Integer;
227 sWidth, sHeight: Word;
228 gSpectMode: Byte = SPECT_NONE;
229 gSpectHUD: Boolean = True;
230 gSpectKeyPress: Boolean = False;
231 gSpectX: Integer = 0;
232 gSpectY: Integer = 0;
233 gSpectStep: Byte = 8;
234 gSpectViewTwo: Boolean = False;
235 gSpectPID1: Integer = -1;
236 gSpectPID2: Integer = -1;
237 gMusic: TMusic = nil;
238 gLoadGameMode: Boolean;
239 gCheats: Boolean = False;
240 gMapOnce: Boolean = False;
241 gMapToDelete: String;
242 gTempDelete: Boolean = False;
243 gLastMap: Boolean = False;
244 gWinPosX, gWinPosY: Integer;
245 gWinSizeX, gWinSizeY: Integer;
246 gWinFrameX, gWinFrameY, gWinCaption: Integer;
247 gWinActive: Boolean = False;
248 gResolutionChange: Boolean = False;
249 gRC_Width, gRC_Height: Word;
250 gRC_FullScreen, gRC_Maximized: Boolean;
251 gLanguageChange: Boolean = False;
252 gDebugMode: Boolean = False;
253 g_debug_Sounds: Boolean = False;
254 g_debug_Frames: Boolean = False;
255 g_debug_WinMsgs: Boolean = False;
256 g_debug_MonsterOff: Boolean = False;
257 g_debug_BotAIOff: Byte = 0;
258 g_debug_HealthBar: Boolean = False;
259 g_Debug_Player: Boolean = False;
260 gCoopMonstersKilled: Word = 0;
261 gCoopSecretsFound: Word = 0;
262 gCoopTotalMonstersKilled: Word = 0;
263 gCoopTotalSecretsFound: Word = 0;
264 gCoopTotalMonsters: Word = 0;
265 gCoopTotalSecrets: Word = 0;
266 gStatsOff: Boolean = False;
267 gStatsPressed: Boolean = False;
268 gExitByTrigger: Boolean = False;
269 gNextMap: String = '';
270 gLMSRespawn: Byte = LMS_RESPAWN_NONE;
271 gLMSRespawnTime: Cardinal = 0;
272 gLMSSoftSpawn: Boolean = False;
273 gMissionFailed: Boolean = False;
274 gVoteInProgress: Boolean = False;
275 gVotePassed: Boolean = False;
276 gVoteCommand: string = '';
277 gVoteTimer: Cardinal = 0;
278 gVoteCmdTimer: Cardinal = 0;
279 gVoteCount: Integer = 0;
280 gVoteTimeout: Cardinal = 30;
281 gVoted: Boolean = False;
282 gVotesEnabled: Boolean = True;
283 gEvents: Array of TGameEvent;
284 gDelayedEvents: Array of TDelayedEvent;
286 P1MoveButton: Byte = 0;
287 P2MoveButton: Byte = 0;
289 implementation
291 uses
292 g_textures, g_main, g_window, g_menu,
293 e_input, e_log, g_console, g_items, g_map,
294 g_playermodel, g_gfx, g_options, g_weapons, Math,
295 g_triggers, MAPDEF, g_monsters, e_sound, CONFIG,
296 BinEditor, g_language, g_net, SDL,
297 ENet, e_fixedbuffer, g_netmsg, g_netmaster, GL, GLExt;
299 type
300 TEndCustomGameStat = record
301 PlayerStat: TPlayerStatArray;
302 TeamStat: TTeamStat;
303 GameTime: LongWord;
304 GameMode: Byte;
305 Map, MapName: String;
306 end;
308 TEndSingleGameStat = record
309 PlayerStat: Array [0..1] of record
310 Kills: Integer;
311 Secrets: Integer;
312 end;
313 GameTime: LongWord;
314 TwoPlayers: Boolean;
315 TotalSecrets: Integer;
316 end;
318 TLoadingStat = record
319 CurValue: Integer;
320 MaxValue: Integer;
321 ShowCount: Integer;
322 Msgs: Array of String;
323 NextMsg: Word;
324 end;
326 TParamStrValue = record
327 Name: String;
328 Value: String;
329 end;
331 TParamStrValues = Array of TParamStrValue;
333 const
334 INTER_ACTION_TEXT = 1;
335 INTER_ACTION_PIC = 2;
336 INTER_ACTION_MUSIC = 3;
338 var
339 FPS, UPS: Word;
340 FPSCounter, UPSCounter: Word;
341 FPSTime, UPSTime: LongWord;
342 DataLoaded: Boolean = False;
343 LastScreenShot: Int64;
344 IsDrawStat: Boolean = False;
345 CustomStat: TEndCustomGameStat;
346 SingleStat: TEndSingleGameStat;
347 LoadingStat: TLoadingStat;
348 EndingGameCounter: Byte = 0;
349 MessageText: String;
350 MessageTime: Word;
351 MapList: SArray = nil;
352 MapIndex: Integer = -1;
353 MegaWAD: record
354 info: TMegaWADInfo;
355 endpic: String;
356 endmus: String;
357 res: record
358 text: Array of ShortString;
359 anim: Array of ShortString;
360 pic: Array of ShortString;
361 mus: Array of ShortString;
362 end;
363 triggers: Array of record
364 event: ShortString;
365 actions: Array of record
366 action, p1, p2: Integer;
367 end;
368 end;
369 cur_trigger: Integer;
370 cur_action: Integer;
371 end;
372 //InterPic: String;
373 InterText: record
374 lines: SArray;
375 img: String;
376 cur_line: Integer;
377 cur_char: Integer;
378 counter: Integer;
379 endtext: Boolean;
380 end;
382 function Compare(a, b: TPlayerStat): Integer;
383 begin
384 if a.Spectator then Result := 1
385 else if b.Spectator then Result := -1
386 else if a.Frags < b.Frags then Result := 1
387 else if a.Frags > b.Frags then Result := -1
388 else if a.Deaths < b.Deaths then Result := -1
389 else if a.Deaths > b.Deaths then Result := 1
390 else if a.Kills < b.Kills then Result := -1
391 else Result := 1;
392 end;
394 procedure SortGameStat(var stat: TPlayerStatArray);
395 var
396 I, J: Integer;
397 T: TPlayerStat;
398 begin
399 if stat = nil then Exit;
401 for I := High(stat) downto Low(stat) do
402 for J := Low(stat) to High(stat) - 1 do
403 if Compare(stat[J], stat[J + 1]) = 1 then
404 begin
405 T := stat[J];
406 stat[J] := stat[J + 1];
407 stat[J + 1] := T;
408 end;
409 end;
411 function g_Game_ModeToText(Mode: Byte): string;
412 begin
413 Result := '';
414 case Mode of
415 GM_DM: Result := _lc[I_MENU_GAME_TYPE_DM];
416 GM_TDM: Result := _lc[I_MENU_GAME_TYPE_TDM];
417 GM_CTF: Result := _lc[I_MENU_GAME_TYPE_CTF];
418 GM_COOP: Result := _lc[I_MENU_GAME_TYPE_COOP];
419 GM_SINGLE: Result := _lc[I_MENU_GAME_TYPE_SINGLE];
420 end;
421 end;
423 function g_Game_TextToMode(Mode: string): Byte;
424 begin
425 Result := GM_NONE;
426 Mode := UpperCase(Mode);
427 if Mode = _lc[I_MENU_GAME_TYPE_DM] then
428 begin
429 Result := GM_DM;
430 Exit;
431 end;
432 if Mode = _lc[I_MENU_GAME_TYPE_TDM] then
433 begin
434 Result := GM_TDM;
435 Exit;
436 end;
437 if Mode = _lc[I_MENU_GAME_TYPE_CTF] then
438 begin
439 Result := GM_CTF;
440 Exit;
441 end;
442 if Mode = _lc[I_MENU_GAME_TYPE_COOP] then
443 begin
444 Result := GM_COOP;
445 Exit;
446 end;
447 if Mode = _lc[I_MENU_GAME_TYPE_SINGLE] then
448 begin
449 Result := GM_SINGLE;
450 Exit;
451 end;
452 end;
454 function g_Game_IsNet(): Boolean;
455 begin
456 Result := (gGameSettings.GameType in [GT_SERVER, GT_CLIENT]);
457 end;
459 function g_Game_IsServer(): Boolean;
460 begin
461 Result := (gGameSettings.GameType in [GT_SINGLE, GT_CUSTOM, GT_SERVER]);
462 end;
464 function g_Game_IsClient(): Boolean;
465 begin
466 Result := (gGameSettings.GameType = GT_CLIENT);
467 end;
469 function g_Game_GetMegaWADInfo(WAD: String): TMegaWADInfo;
470 var
471 w: TWADEditor_1;
472 cfg: TConfig;
473 p: Pointer;
474 len: Integer;
475 begin
476 Result.name := ExtractFileName(WAD);
477 Result.description := '';
478 Result.author := '';
480 w := TWADEditor_1.Create();
481 w.ReadFile(WAD);
483 if not w.GetResource('', 'INTERSCRIPT', p, len) then
484 begin
485 w.Free();
486 Exit;
487 end;
489 cfg := TConfig.CreateMem(p, len);
490 Result.name := cfg.ReadStr('megawad', 'name', ExtractFileName(WAD));
491 Result.description := cfg.ReadStr('megawad', 'description', '');
492 Result.author := cfg.ReadStr('megawad', 'author', '');
493 Result.pic := cfg.ReadStr('megawad', 'pic', '');
494 cfg.Free();
496 FreeMem(p);
497 end;
499 procedure g_Game_FreeWAD();
500 var
501 a: Integer;
502 begin
503 for a := 0 to High(MegaWAD.res.pic) do
504 if MegaWAD.res.pic[a] <> '' then
505 g_Texture_Delete(MegaWAD.res.pic[a]);
507 for a := 0 to High(MegaWAD.res.mus) do
508 if MegaWAD.res.mus[a] <> '' then
509 g_Sound_Delete(MegaWAD.res.mus[a]);
511 MegaWAD.res.pic := nil;
512 MegaWAD.res.text := nil;
513 MegaWAD.res.anim := nil;
514 MegaWAD.res.mus := nil;
515 MegaWAD.triggers := nil;
517 g_Texture_Delete('TEXTURE_endpic');
518 g_Sound_Delete('MUSIC_endmus');
520 ZeroMemory(@MegaWAD, SizeOf(MegaWAD));
521 gGameSettings.WAD := '';
522 end;
524 procedure g_Game_LoadWAD(WAD: string);
525 var
526 w: TWADEditor_1;
527 cfg: TConfig;
528 p: Pointer;
529 {b, }len: Integer;
530 s: string;
531 begin
532 g_Game_FreeWAD();
533 gGameSettings.WAD := WAD;
534 if not (gGameSettings.GameMode in [GM_COOP, GM_SINGLE]) then
535 Exit;
537 MegaWAD.info := g_Game_GetMegaWADInfo(MapsDir + WAD);
539 w := TWADEditor_1.Create();
540 w.ReadFile(MapsDir + WAD);
542 if not w.GetResource('', 'INTERSCRIPT', p, len) then
543 begin
544 w.Free();
545 Exit;
546 end;
548 cfg := TConfig.CreateMem(p, len);
550 {b := 1;
551 while True do
552 begin
553 s := cfg.ReadStr('pic', 'pic'+IntToStr(b), '');
554 if s = '' then Break;
555 b := b+1;
557 SetLength(MegaWAD.res.pic, Length(MegaWAD.res.pic)+1);
558 MegaWAD.res.pic[High(MegaWAD.res.pic)] := s;
560 g_Texture_CreateWADEx(s, s);
561 end;
563 b := 1;
564 while True do
565 begin
566 s := cfg.ReadStr('mus', 'mus'+IntToStr(b), '');
567 if s = '' then Break;
568 b := b+1;
570 SetLength(MegaWAD.res.mus, Length(MegaWAD.res.mus)+1);
571 MegaWAD.res.mus[High(MegaWAD.res.mus)] := s;
573 g_Music_CreateWADEx(s, s);
574 end;}
576 MegaWAD.endpic := cfg.ReadStr('megawad', 'endpic', '');
577 if MegaWAD.endpic <> '' then
578 begin
579 g_ProcessResourceStr(MegaWAD.endpic, @s, nil, nil);
580 if s = '' then s := MapsDir+WAD else s := GameDir+'/wads/';
581 g_Texture_CreateWADEx('TEXTURE_endpic', s+MegaWAD.endpic);
582 end;
583 MegaWAD.endmus := cfg.ReadStr('megawad', 'endmus', 'Standart.wad:D2DMUS\ÊÎÍÅÖ');
584 if MegaWAD.endmus <> '' then
585 begin
586 g_ProcessResourceStr(MegaWAD.endmus, @s, nil, nil);
587 if s = '' then s := MapsDir+WAD else s := GameDir+'/wads/';
588 g_Sound_CreateWADEx('MUSIC_endmus', s+MegaWAD.endmus, True);
589 end;
591 cfg.Free();
592 FreeMem(p);
593 w.Free();
594 end;
596 {procedure start_trigger(t: string);
597 begin
598 end;
600 function next_trigger(): Boolean;
601 begin
602 end;}
604 procedure DisableCheats();
605 begin
606 MAX_RUNVEL := 8;
607 VEL_JUMP := 10;
608 gFly := False;
610 if gPlayer1 <> nil then gPlayer1.GodMode := False;
611 if gPlayer2 <> nil then gPlayer2.GodMode := False;
612 if gPlayer1 <> nil then gPlayer1.NoTarget := False;
613 if gPlayer2 <> nil then gPlayer2.NoTarget := False;
614 end;
616 procedure g_Game_ExecuteEvent(Name: String);
617 var
618 a: Integer;
619 begin
620 if Name = '' then
621 Exit;
622 if gEvents = nil then
623 Exit;
624 for a := 0 to High(gEvents) do
625 if gEvents[a].Name = Name then
626 begin
627 if gEvents[a].Command <> '' then
628 g_Console_Process(gEvents[a].Command, True);
629 break;
630 end;
631 end;
633 function g_Game_DelayEvent(DEType: Byte; Time: LongWord; Num: Integer = 0; Str: String = ''): Integer;
634 var
635 a, n: Integer;
636 begin
637 n := -1;
638 if gDelayedEvents <> nil then
639 for a := 0 to High(gDelayedEvents) do
640 if not gDelayedEvents[a].Pending then
641 begin
642 n := a;
643 break;
644 end;
645 if n = -1 then
646 begin
647 SetLength(gDelayedEvents, Length(gDelayedEvents) + 1);
648 n := High(gDelayedEvents);
649 end;
650 gDelayedEvents[n].Pending := True;
651 gDelayedEvents[n].DEType := DEType;
652 gDelayedEvents[n].DENum := Num;
653 gDelayedEvents[n].DEStr := Str;
654 if DEType = DE_GLOBEVENT then
655 gDelayedEvents[n].Time := (GetTimer() div 1000) + Time
656 else
657 gDelayedEvents[n].Time := gTime + Time;
658 Result := n;
659 end;
661 procedure EndGame();
662 var
663 a: Integer;
664 FileName, SectionName, ResName: string;
665 begin
666 if g_Game_IsNet and g_Game_IsServer then
667 MH_SEND_GameEvent(NET_EV_MAPEND, Byte(gMissionFailed));
669 // Ñòîï èãðà:
670 gPause := False;
671 gGameOn := False;
673 g_Game_StopAllSounds(False);
675 MessageTime := 0;
676 MessageText := '';
678 EndingGameCounter := 0;
679 g_ActiveWindow := nil;
681 gLMSRespawn := LMS_RESPAWN_NONE;
682 gLMSRespawnTime := 0;
684 case gExit of
685 EXIT_SIMPLE: // Âûõîä ÷åðåç ìåíþ èëè êîíåö òåñòà
686 begin
687 g_Game_Free();
689 if gMapOnce then
690 begin // Ýòî áûë òåñò
691 g_Game_Quit();
692 end
693 else
694 begin // Âûõîä â ãëàâíîå ìåíþ
695 gMusic.SetByName('MUSIC_MENU');
696 gMusic.Play();
697 if gState <> STATE_SLIST then
698 begin
699 g_GUI_ShowWindow('MainMenu');
700 gState := STATE_MENU;
701 end else
702 begin
703 // Îáíîâëÿåì ñïèñîê ñåðâåðîâ
704 slReturnPressed := True;
705 if g_Net_Slist_Fetch(slCurrent) then
706 begin
707 if slCurrent = nil then
708 slWaitStr := _lc[I_NET_SLIST_NOSERVERS];
709 end
710 else
711 slWaitStr := _lc[I_NET_SLIST_ERROR];
712 end;
714 g_Game_ExecuteEvent('ongameend');
715 end;
716 end;
718 EXIT_RESTART: // Íà÷àòü óðîâåíü ñíà÷àëà
719 begin
720 if not g_Game_IsClient then g_Game_Restart();
721 end;
723 EXIT_ENDLEVELCUSTOM: // Çàêîí÷èëñÿ óðîâåíü â Ñâîåé èãðå
724 begin
725 // Ñòàòèñòèêà Ñâîåé èãðû:
726 g_ProcessResourceStr(gMapInfo.Map, FileName, SectionName, ResName);
728 CustomStat.GameTime := gTime;
729 CustomStat.Map := ExtractFileName(FileName)+':'+ResName;
730 CustomStat.MapName := gMapInfo.Name;
731 CustomStat.GameMode := gGameSettings.GameMode;
732 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
733 CustomStat.TeamStat := gTeamStat;
735 CustomStat.PlayerStat := nil;
737 // Ñòàòèñòèêà èãðîêîâ:
738 if gPlayers <> nil then
739 begin
740 for a := 0 to High(gPlayers) do
741 if gPlayers[a] <> nil then
742 begin
743 SetLength(CustomStat.PlayerStat, Length(CustomStat.PlayerStat)+1);
744 with CustomStat.PlayerStat[High(CustomStat.PlayerStat)] do
745 begin
746 Name := gPlayers[a].Name;
747 Frags := gPlayers[a].Frags;
748 Deaths := gPlayers[a].Death;
749 Kills := gPlayers[a].Kills;
750 Team := gPlayers[a].Team;
751 Color := gPlayers[a].Model.Color;
752 Spectator := gPlayers[a].FSpectator;
753 end;
754 end;
756 SortGameStat(CustomStat.PlayerStat);
757 end;
759 g_Game_ExecuteEvent('onmapend');
761 // Çàòóõàþùèé ýêðàí:
762 EndingGameCounter := 255;
763 gState := STATE_FOLD;
764 gInterTime := 0;
765 if gDefInterTime < 0 then
766 gInterEndTime := IfThen((gGameSettings.GameType = GT_SERVER) and (gPlayer1 = nil), 15000, 25000)
767 else
768 gInterEndTime := gDefInterTime * 1000;
769 end;
771 EXIT_ENDLEVELSINGLE: // Çàêîí÷èëñÿ óðîâåíü â Îäèíî÷íîé èãðå
772 begin
773 // Ñòàòèñòèêà Îäèíî÷íîé èãðû:
774 SingleStat.GameTime := gTime;
775 SingleStat.TwoPlayers := gPlayer2 <> nil;
776 SingleStat.TotalSecrets := gSecretsCount;
777 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
778 SingleStat.PlayerStat[0].Kills := gPlayer1.MonsterKills;
779 SingleStat.PlayerStat[0].Secrets := gPlayer1.Secrets;
780 // Ñòàòèñòèêà âòîðîãî èãðîêà (åñëè åñòü):
781 if SingleStat.TwoPlayers then
782 begin
783 SingleStat.PlayerStat[1].Kills := gPlayer2.MonsterKills;
784 SingleStat.PlayerStat[1].Secrets := gPlayer2.Secrets;
785 end;
787 g_Game_ExecuteEvent('onmapend');
789 // Åñòü åùå êàðòû:
790 if gNextMap <> '' then
791 begin
792 gMusic.SetByName('MUSIC_INTERMUS');
793 gMusic.Play();
794 gState := STATE_INTERSINGLE;
796 g_Game_ExecuteEvent('oninter');
797 end
798 else // Áîëüøå íåò êàðò
799 begin
800 // Çàòóõàþùèé ýêðàí:
801 EndingGameCounter := 255;
802 gState := STATE_FOLD;
803 end;
804 end;
805 end;
807 // Îêîí÷àíèå îáðàáîòàíî:
808 if gExit <> EXIT_QUIT then
809 gExit := 0;
810 end;
812 procedure DrawStat();
813 var
814 pc, x, y, w, h: Integer;
815 w1, w2, w3, w4: Integer;
816 a, aa: Integer;
817 cw, ch, r, g, b, rr, gg, bb: Byte;
818 s1, s2, s3: String;
819 _y: Integer;
820 stat: TPlayerStatArray;
821 wad, map: string;
822 mapstr: string;
823 begin
824 s1 := '';
825 s2 := '';
826 s3 := '';
827 pc := g_Player_GetCount;
828 e_TextureFontGetSize(gStdFont, cw, ch);
830 w := gScreenWidth-(gScreenWidth div 5);
831 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
832 h := 32+ch*(11+pc)
833 else
834 h := 40+ch*5+(ch+8)*pc;
835 x := (gScreenWidth div 2)-(w div 2);
836 y := (gScreenHeight div 2)-(h div 2);
838 e_DrawFillQuad(x, y, x+w-1, y+h-1, 64, 64, 64, 32);
839 e_DrawQuad(x, y, x+w-1, y+h-1, 255, 127, 0);
841 g_ProcessResourceStr(gMapInfo.Map, @wad, nil, @map);
842 wad := ExtractFileName(wad);
843 mapstr := wad + ':\' + map + ' - ' + gMapInfo.Name;
845 case gGameSettings.GameMode of
846 GM_DM:
847 begin
848 if gGameSettings.MaxLives = 0 then
849 s1 := _lc[I_GAME_DM]
850 else
851 s1 := _lc[I_GAME_LMS];
852 s2 := Format(_lc[I_GAME_FRAG_LIMIT], [gGameSettings.GoalLimit]);
853 s3 := Format(_lc[I_GAME_TIME_LIMIT], [gGameSettings.TimeLimit div 3600, (gGameSettings.TimeLimit div 60) mod 60, gGameSettings.TimeLimit mod 60]);
854 end;
856 GM_TDM:
857 begin
858 if gGameSettings.MaxLives = 0 then
859 s1 := _lc[I_GAME_TDM]
860 else
861 s1 := _lc[I_GAME_TLMS];
862 s2 := Format(_lc[I_GAME_FRAG_LIMIT], [gGameSettings.GoalLimit]);
863 s3 := Format(_lc[I_GAME_TIME_LIMIT], [gGameSettings.TimeLimit div 3600, (gGameSettings.TimeLimit div 60) mod 60, gGameSettings.TimeLimit mod 60]);
864 end;
866 GM_CTF:
867 begin
868 s1 := _lc[I_GAME_CTF];
869 s2 := Format(_lc[I_GAME_SCORE_LIMIT], [gGameSettings.GoalLimit]);
870 s3 := Format(_lc[I_GAME_TIME_LIMIT], [gGameSettings.TimeLimit div 3600, (gGameSettings.TimeLimit div 60) mod 60, gGameSettings.TimeLimit mod 60]);
871 end;
873 GM_COOP:
874 begin
875 if gGameSettings.MaxLives = 0 then
876 s1 := _lc[I_GAME_COOP]
877 else
878 s1 := _lc[I_GAME_SURV];
879 s2 := _lc[I_GAME_MONSTERS] + ' ' + IntToStr(gCoopMonstersKilled) + '/' + IntToStr(gTotalMonsters);
880 s3 := _lc[I_GAME_SECRETS] + ' ' + IntToStr(gCoopSecretsFound) + '/' + IntToStr(gSecretsCount);
881 end;
883 else
884 begin
885 s1 := '';
886 s2 := '';
887 end;
888 end;
890 _y := y+8;
891 e_TextureFontPrintEx(x+(w div 2)-(Length(s1)*cw div 2), _y, s1, gStdFont, 255, 255, 255, 1);
892 _y := _y+ch+8;
893 e_TextureFontPrintEx(x+(w div 2)-(Length(mapstr)*cw div 2), _y, mapstr, gStdFont, 200, 200, 200, 1);
894 _y := _y+ch+8;
895 e_TextureFontPrintEx(x+16, _y, s2, gStdFont, 200, 200, 200, 1);
897 e_TextureFontPrintEx(x+w-16-(Length(s3))*cw, _y, s3,
898 gStdFont, 200, 200, 200, 1);
900 if NetMode = NET_SERVER then
901 e_TextureFontPrintEx(x+8, y + 8, _lc[I_NET_SERVER], gStdFont, 255, 255, 255, 1)
902 else
903 if NetMode = NET_CLIENT then
904 e_TextureFontPrintEx(x+8, y + 8,
905 NetClientIP + ':' + IntToStr(NetClientPort), gStdFont, 255, 255, 255, 1);
907 if pc = 0 then
908 Exit;
909 stat := g_Player_GetStats();
910 SortGameStat(stat);
912 w2 := (w-16) div 6 + 48; // øèðèíà 2 ñòîëáöà
913 w3 := (w-16) div 6; // øèðèíà 3 è 4 ñòîëáöîâ
914 w4 := w3;
915 w1 := w-16-w2-w3-w4; // îñòàâøååñÿ ïðîñòðàíñòâî - äëÿ öâåòà è èìåíè èãðîêà
917 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
918 begin
919 _y := _y+ch+ch;
921 for a := TEAM_RED to TEAM_BLUE do
922 begin
923 if a = TEAM_RED then
924 begin
925 s1 := _lc[I_GAME_TEAM_RED];
926 r := 255;
927 g := 0;
928 b := 0;
929 end
930 else
931 begin
932 s1 := _lc[I_GAME_TEAM_BLUE];
933 r := 0;
934 g := 0;
935 b := 255;
936 end;
938 e_TextureFontPrintEx(x+16, _y, s1, gStdFont, r, g, b, 1);
939 e_TextureFontPrintEx(x+w1+16, _y, IntToStr(gTeamStat[a].Goals),
940 gStdFont, r, g, b, 1);
942 _y := _y+ch+(ch div 4);
943 e_DrawLine(1, x+16, _y, x+w-16, _y, r, g, b);
944 _y := _y+(ch div 4);
946 for aa := 0 to High(stat) do
947 if stat[aa].Team = a then
948 with stat[aa] do
949 begin
950 if Spectator then
951 begin
952 rr := r div 2;
953 gg := g div 2;
954 bb := b div 2;
955 end
956 else
957 begin
958 rr := r;
959 gg := g;
960 bb := b;
961 end;
962 // Èìÿ
963 e_TextureFontPrintEx(x+16, _y, Name, gStdFont, rr, gg, bb, 1);
964 // Ïèíã/ïîòåðè
965 e_TextureFontPrintEx(x+w1+16, _y, Format(_lc[I_GAME_PING_MS], [Ping, Loss]), gStdFont, rr, gg, bb, 1);
966 // Ôðàãè
967 e_TextureFontPrintEx(x+w1+w2+16, _y, IntToStr(Frags), gStdFont, rr, gg, bb, 1);
968 // Ñìåðòè
969 e_TextureFontPrintEx(x+w1+w2+w3+16, _y, IntToStr(Deaths), gStdFont, rr, gg, bb, 1);
970 _y := _y+ch;
971 end;
973 _y := _y+ch;
974 end;
975 end
976 else if gGameSettings.GameMode in [GM_DM, GM_COOP] then
977 begin
978 _y := _y+ch+ch;
979 e_TextureFontPrintEx(x+16, _y, _lc[I_GAME_PLAYER_NAME], gStdFont, 255, 127, 0, 1);
980 e_TextureFontPrintEx(x+16+w1, _y, _lc[I_GAME_PING], gStdFont, 255, 127, 0, 1);
981 e_TextureFontPrintEx(x+16+w1+w2, _y, _lc[I_GAME_FRAGS], gStdFont, 255, 127, 0, 1);
982 e_TextureFontPrintEx(x+16+w1+w2+w3, _y, _lc[I_GAME_DEATHS], gStdFont, 255, 127, 0, 1);
984 _y := _y+ch+8;
985 for aa := 0 to High(stat) do
986 with stat[aa] do
987 begin
988 if Spectator then
989 begin
990 r := 127;
991 g := 64;
992 end
993 else
994 begin
995 r := 255;
996 g := 127;
997 end;
998 // Öâåò èãðîêà
999 e_DrawFillQuad(x+16, _y+4, x+32-1, _y+16+4-1, Color.R, Color.G, Color.B, 0);
1000 e_DrawQuad(x+16, _y+4, x+32-1, _y+16+4-1, 192, 192, 192);
1001 // Èìÿ
1002 e_TextureFontPrintEx(x+16+16+8, _y+4, Name, gStdFont, r, g, 0, 1);
1003 // Ïèíã/ïîòåðè
1004 e_TextureFontPrintEx(x+w1+16, _y+4, Format(_lc[I_GAME_PING_MS], [Ping, Loss]), gStdFont, r, g, 0, 1);
1005 // Ôðàãè
1006 e_TextureFontPrintEx(x+w1+w2+16, _y+4, IntToStr(Frags), gStdFont, r, g, 0, 1);
1007 // Ñìåðòè
1008 e_TextureFontPrintEx(x+w1+w2+w3+16, _y+4, IntToStr(Deaths), gStdFont, r, g, 0, 1);
1009 _y := _y+ch+8;
1010 end;
1011 end
1012 end;
1014 procedure g_Game_Init();
1015 var
1016 SR: TSearchRec;
1017 begin
1018 gExit := 0;
1019 gMapToDelete := '';
1020 gTempDelete := False;
1022 g_Texture_CreateWADEx('MENU_BACKGROUND', GameWAD+':TEXTURES\TITLE');
1023 g_Texture_CreateWADEx('INTER', GameWAD+':TEXTURES\INTER');
1024 g_Texture_CreateWADEx('ENDGAME_EN', GameWAD+':TEXTURES\ENDGAME_EN');
1025 g_Texture_CreateWADEx('ENDGAME_RU', GameWAD+':TEXTURES\ENDGAME_RU');
1027 LoadStdFont('STDTXT', 'STDFONT', gStdFont);
1028 LoadFont('MENUTXT', 'MENUFONT', gMenuFont);
1029 LoadFont('SMALLTXT', 'SMALLFONT', gMenuSmallFont);
1031 g_Game_ClearLoading();
1032 g_Game_SetLoadingText(Format('Doom 2D: Forever %s', [GAME_VERSION]), 0, False);
1033 g_Game_SetLoadingText('', 0, False);
1035 g_Game_SetLoadingText(_lc[I_LOAD_CONSOLE], 0, False);
1036 g_Console_Init();
1038 g_Game_SetLoadingText(_lc[I_LOAD_MODELS], 0, False);
1039 g_PlayerModel_LoadData();
1041 if FindFirst(ModelsDir+'*.wad', faAnyFile, SR) = 0 then
1042 repeat
1043 if not g_PlayerModel_Load(ModelsDir+SR.Name) then
1044 e_WriteLog(Format('Error loading model %s', [SR.Name]), MSG_WARNING);
1045 until FindNext(SR) <> 0;
1046 FindClose(SR);
1048 gGameOn := False;
1049 gPause := False;
1050 gTime := 0;
1051 LastScreenShot := 0;
1053 {e_MouseInfo.Accel := 1.0;}
1055 g_Game_SetLoadingText(_lc[I_LOAD_GAME_DATA], 0, False);
1056 g_Game_LoadData();
1058 g_Game_SetLoadingText(_lc[I_LOAD_MUSIC], 0, False);
1059 g_Sound_CreateWADEx('MUSIC_INTERMUS', GameWAD+':MUSIC\INTERMUS', True);
1060 g_Sound_CreateWADEx('MUSIC_MENU', GameWAD+':MUSIC\MENU', True);
1061 g_Sound_CreateWADEx('MUSIC_ROUNDMUS', GameWAD+':MUSIC\ROUNDMUS', True);
1062 g_Sound_CreateWADEx('MUSIC_STDENDMUS', GameWAD+':MUSIC\ENDMUS', True);
1064 g_Game_SetLoadingText(_lc[I_LOAD_MENUS], 0, False);
1065 g_Menu_Init();
1067 gMusic := TMusic.Create();
1068 gMusic.SetByName('MUSIC_MENU');
1069 gMusic.Play();
1071 gGameSettings.WarmupTime := 30;
1073 gState := STATE_MENU;
1075 SetLength(gEvents, 6);
1076 gEvents[0].Name := 'ongamestart';
1077 gEvents[1].Name := 'ongameend';
1078 gEvents[2].Name := 'onmapstart';
1079 gEvents[3].Name := 'onmapend';
1080 gEvents[4].Name := 'oninter';
1081 gEvents[5].Name := 'onwadend';
1082 end;
1084 procedure g_Game_Free();
1085 begin
1086 if NetMode = NET_CLIENT then g_Net_Disconnect();
1087 if NetMode = NET_SERVER then g_Net_Host_Die();
1089 g_Map_Free();
1090 g_Player_Free();
1091 g_Player_RemoveAllCorpses();
1093 gGameSettings.GameType := GT_NONE;
1094 if gGameSettings.GameMode = GM_SINGLE then
1095 gGameSettings.GameMode := GM_DM;
1096 gSwitchGameMode := gGameSettings.GameMode;
1098 gChatShow := False;
1099 gExitByTrigger := False;
1100 end;
1102 function IsActivePlayer(p: TPlayer): Boolean;
1103 begin
1104 Result := False;
1105 if p = nil then
1106 Exit;
1107 Result := (not p.FDummy) and (not p.FSpectator);
1108 end;
1110 function GetActivePlayer_ByID(ID: Integer): TPlayer;
1111 var
1112 a: Integer;
1113 begin
1114 Result := nil;
1115 if ID < 0 then
1116 Exit;
1117 if gPlayers = nil then
1118 Exit;
1119 for a := Low(gPlayers) to High(gPlayers) do
1120 if IsActivePlayer(gPlayers[a]) then
1121 begin
1122 if gPlayers[a].UID <> ID then
1123 continue;
1124 Result := gPlayers[a];
1125 break;
1126 end;
1127 end;
1129 function GetActivePlayerID_Next(Skip: Integer = -1): Integer;
1130 var
1131 a, idx: Integer;
1132 ids: Array of Word;
1133 begin
1134 Result := -1;
1135 if gPlayers = nil then
1136 Exit;
1137 SetLength(ids, 0);
1138 idx := -1;
1139 for a := Low(gPlayers) to High(gPlayers) do
1140 if IsActivePlayer(gPlayers[a]) then
1141 begin
1142 SetLength(ids, Length(ids) + 1);
1143 ids[High(ids)] := gPlayers[a].UID;
1144 if gPlayers[a].UID = Skip then
1145 idx := High(ids);
1146 end;
1147 if Length(ids) = 0 then
1148 Exit;
1149 if idx = -1 then
1150 Result := ids[0]
1151 else
1152 Result := ids[(idx + 1) mod Length(ids)];
1153 end;
1155 function GetActivePlayerID_Prev(Skip: Integer = -1): Integer;
1156 var
1157 a, idx: Integer;
1158 ids: Array of Word;
1159 begin
1160 Result := -1;
1161 if gPlayers = nil then
1162 Exit;
1163 SetLength(ids, 0);
1164 idx := -1;
1165 for a := Low(gPlayers) to High(gPlayers) do
1166 if IsActivePlayer(gPlayers[a]) then
1167 begin
1168 SetLength(ids, Length(ids) + 1);
1169 ids[High(ids)] := gPlayers[a].UID;
1170 if gPlayers[a].UID = Skip then
1171 idx := High(ids);
1172 end;
1173 if Length(ids) = 0 then
1174 Exit;
1175 if idx = -1 then
1176 Result := ids[Length(ids) - 1]
1177 else
1178 Result := ids[(Length(ids) - 1 + idx) mod Length(ids)];
1179 end;
1181 procedure g_Game_Update();
1182 var
1183 Msg: g_gui.TMessage;
1184 Time: Int64;
1185 a: Byte;
1186 w: Word;
1187 i, b: Integer;
1188 begin
1189 // Ïîðà âûêëþ÷àòü èãðó:
1190 if gExit = EXIT_QUIT then
1191 Exit;
1192 // Èãðà çàêîí÷èëàñü - îáðàáàòûâàåì:
1193 if gExit <> 0 then
1194 begin
1195 EndGame();
1196 if gExit = EXIT_QUIT then
1197 Exit;
1198 end;
1200 // ×èòàåì êëàâèàòóðó è äæîéñòèê, åñëè îêíî àêòèâíî:
1201 e_PollInput();
1203 // Îáíîâëÿåì êîíñîëü (äâèæåíèå è ñîîáùåíèÿ):
1204 g_Console_Update();
1206 if (NetMode = NET_NONE) and (g_Game_IsNet) and (gGameOn or (gState in [STATE_FOLD, STATE_INTERCUSTOM])) then
1207 begin
1208 gExit := EXIT_SIMPLE;
1209 EndGame();
1210 Exit;
1211 end;
1213 case gState of
1214 STATE_INTERSINGLE, // Ñòàòèñòêà ïîñëå ïðîõîæäåíèÿ óðîâíÿ â Îäèíî÷íîé èãðå
1215 STATE_INTERCUSTOM, // Ñòàòèñòêà ïîñëå ïðîõîæäåíèÿ óðîâíÿ â Ñâîåé èãðå
1216 STATE_INTERTEXT, // Òåêñò ìåæäó óðîâíÿìè
1217 STATE_INTERPIC: // Êàðòèíêà ìåæäó óðîâíÿìè
1218 begin
1219 if g_Game_IsNet and g_Game_IsServer then
1220 begin
1221 gInterTime := gInterTime + GAME_TICK;
1222 a := Min((gInterEndTime - gInterTime) div 1000 + 1, 255);
1223 if a <> gServInterTime then
1224 begin
1225 gServInterTime := a;
1226 MH_SEND_TimeSync(gServInterTime);
1227 end;
1228 end;
1230 if (not g_Game_IsClient) and
1233 (e_KeyPressed(IK_RETURN) or e_KeyPressed(IK_KPRETURN) or e_KeyPressed(IK_SPACE))
1234 and (not gJustChatted) and (not gConsoleShow) and (not gChatShow)
1235 and (g_ActiveWindow = nil)
1237 or (g_Game_IsNet and (gInterTime > gInterEndTime))
1239 then
1240 begin // Íàæàëè <Enter>/<Ïðîáåë> èëè ïðîøëî äîñòàòî÷íî âðåìåíè:
1241 g_Game_StopAllSounds(True);
1243 if gMapOnce then // Ýòî áûë òåñò
1244 gExit := EXIT_SIMPLE
1245 else
1246 if gNextMap <> '' then // Ïåðåõîäèì íà ñëåäóþùóþ êàðòó
1247 g_Game_ChangeMap(gNextMap)
1248 else // Ñëåäóþùåé êàðòû íåò
1249 begin
1250 if gGameSettings.GameType in [GT_CUSTOM, GT_SERVER] then
1251 begin
1252 // Âûõîä â ãëàâíîå ìåíþ:
1253 g_Game_Free;
1254 g_GUI_ShowWindow('MainMenu');
1255 gMusic.SetByName('MUSIC_MENU');
1256 gMusic.Play();
1257 gState := STATE_MENU;
1258 end else
1259 begin
1260 // Ôèíàëüíàÿ êàðòèíêà:
1261 g_Game_ExecuteEvent('onwadend');
1262 g_Game_Free();
1263 if not gMusic.SetByName('MUSIC_endmus') then
1264 gMusic.SetByName('MUSIC_STDENDMUS');
1265 gMusic.Play();
1266 gState := STATE_ENDPIC;
1267 end;
1268 g_Game_ExecuteEvent('ongameend');
1269 end;
1271 Exit;
1272 end;
1274 if gState = STATE_INTERTEXT then
1275 if InterText.counter > 0 then
1276 InterText.counter := InterText.counter - 1;
1277 end;
1279 STATE_FOLD: // Çàòóõàíèå ýêðàíà
1280 begin
1281 if EndingGameCounter = 0 then
1282 begin
1283 // Çàêîí÷èëñÿ óðîâåíü â Ñâîåé èãðå:
1284 if gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT] then
1285 begin
1286 if gLastMap and (gGameSettings.GameMode = GM_COOP) then
1287 begin
1288 g_Game_ExecuteEvent('onwadend');
1289 if not gMusic.SetByName('MUSIC_endmus') then
1290 gMusic.SetByName('MUSIC_STDENDMUS');
1291 end
1292 else
1293 gMusic.SetByName('MUSIC_ROUNDMUS');
1295 gMusic.Play();
1296 gState := STATE_INTERCUSTOM;
1297 end
1298 else // Çàêîí÷èëàñü ïîñëåäíÿÿ êàðòà â Îäèíî÷íîé èãðå
1299 begin
1300 gMusic.SetByName('MUSIC_INTERMUS');
1301 gMusic.Play();
1302 gState := STATE_INTERSINGLE;
1303 end;
1304 g_Game_ExecuteEvent('oninter');
1305 end
1306 else
1307 DecMin(EndingGameCounter, 6, 0);
1308 end;
1310 STATE_ENDPIC: // Êàðòèíêà îêîí÷àíèÿ ìåãàÂàäà
1311 begin
1312 if gMapOnce then // Ýòî áûë òåñò
1313 begin
1314 gExit := EXIT_SIMPLE;
1315 Exit;
1316 end;
1317 end;
1319 STATE_SLIST:
1320 g_Serverlist_Control(slCurrent);
1321 end;
1323 if g_Game_IsNet then
1324 if not gConsoleShow then
1325 if not gChatShow then
1326 begin
1327 if g_ActiveWindow = nil then
1328 begin
1329 if e_KeyPressed(gGameControls.GameControls.Chat) then
1330 g_Console_Chat_Switch(False)
1331 else if (e_KeyPressed(gGameControls.GameControls.TeamChat)) and
1332 (gGameSettings.GameMode in [GM_TDM, GM_CTF]) then
1333 g_Console_Chat_Switch(True);
1334 end;
1335 end else
1336 if not gChatEnter then
1337 if (not e_KeyPressed(gGameControls.GameControls.Chat))
1338 and (not e_KeyPressed(gGameControls.GameControls.TeamChat)) then
1339 gChatEnter := True;
1341 // Ñòàòèñòèêà ïî Tab:
1342 if gGameOn then
1343 IsDrawStat := (not gConsoleShow) and (not gChatShow) and
1344 (gGameSettings.GameType <> GT_SINGLE) and
1345 e_KeyPressed(gGameControls.GameControls.Stat);
1347 // Èãðà èäåò:
1348 if gGameOn and not gPause and (gState <> STATE_FOLD) then
1349 begin
1350 // Âðåìÿ += 28 ìèëëèñåêóíä:
1351 gTime := gTime + GAME_TICK;
1353 // Ñîîáùåíèå ïîñåðåäèíå ýêðàíà:
1354 if MessageTime = 0 then
1355 MessageText := '';
1356 if MessageTime > 0 then
1357 MessageTime := MessageTime - 1;
1359 if (g_Game_IsServer) then
1360 begin
1361 // Áûë çàäàí ëèìèò âðåìåíè:
1362 if (gGameSettings.TimeLimit > 0) then
1363 if (gTime - gGameStartTime) div 1000 >= gGameSettings.TimeLimit then
1364 begin // Îí ïðîøåë => êîíåö óðîâíÿ
1365 g_Game_NextLevel();
1366 Exit;
1367 end;
1369 // Íàäî ðåñïàâíèòü èãðîêîâ â LMS:
1370 if (gLMSRespawn > LMS_RESPAWN_NONE) and (gLMSRespawnTime < gTime) then
1371 g_Game_RestartRound(gLMSSoftSpawn);
1373 // Ïðîâåðèì ðåçóëüòàò ãîëîñîâàíèÿ, åñëè âðåìÿ ïðîøëî
1374 if gVoteInProgress and (gVoteTimer < gTime) then
1375 g_Game_CheckVote
1376 else if gVotePassed and (gVoteCmdTimer < gTime) then
1377 begin
1378 g_Console_Process(gVoteCommand);
1379 gVoteCommand := '';
1380 gVotePassed := False;
1381 end;
1383 // Çàìåðÿåì âðåìÿ çàõâàòà ôëàãîâ
1384 if gFlags[FLAG_RED].State = FLAG_STATE_CAPTURED then
1385 gFlags[FLAG_RED].CaptureTime := gFlags[FLAG_RED].CaptureTime + GAME_TICK;
1386 if gFlags[FLAG_BLUE].State = FLAG_STATE_CAPTURED then
1387 gFlags[FLAG_BLUE].CaptureTime := gFlags[FLAG_BLUE].CaptureTime + GAME_TICK;
1389 // Áûë çàäàí ëèìèò ïîáåä:
1390 if (gGameSettings.GoalLimit > 0) then
1391 begin
1392 b := 0;
1394 if gGameSettings.GameMode = GM_DM then
1395 begin // Â DM èùåì èãðîêà ñ max ôðàãàìè
1396 for i := 0 to High(gPlayers) do
1397 if gPlayers[i] <> nil then
1398 if gPlayers[i].Frags > b then
1399 b := gPlayers[i].Frags;
1400 end
1401 else
1402 if gGameSettings.GameMode in [GM_TDM, GM_CTF] then
1403 begin //  CTF/TDM âûáèðàåì êîìàíäó ñ íàèáîëüøèì ñ÷åòîì
1404 b := Max(gTeamStat[TEAM_RED].Goals, gTeamStat[TEAM_BLUE].Goals);
1405 end;
1407 // Ëèìèò ïîáåä íàáðàí => êîíåö óðîâíÿ:
1408 if b >= gGameSettings.GoalLimit then
1409 begin
1410 g_Game_NextLevel();
1411 Exit;
1412 end;
1413 end;
1415 // Îáðàáàòûâàåì êëàâèøè èãðîêîâ:
1416 if gPlayer1 <> nil then gPlayer1.ReleaseKeys();
1417 if gPlayer2 <> nil then gPlayer2.ReleaseKeys();
1418 if (not gConsoleShow) and (not gChatShow) and (g_ActiveWindow = nil) then
1419 begin
1420 // Ïåðâûé èãðîê:
1421 if gPlayer1 <> nil then
1422 with gGameControls.P1Control do
1423 begin
1424 if e_KeyPressed(KeyLeft) and (not e_KeyPressed(KeyRight)) then
1425 P1MoveButton := 1 // Íàæàòà òîëüêî "Âëåâî"
1426 else
1427 if (not e_KeyPressed(KeyLeft)) and e_KeyPressed(KeyRight) then
1428 P1MoveButton := 2 // Íàæàòà òîëüêî "Âïðàâî"
1429 else
1430 if (not e_KeyPressed(KeyLeft)) and (not e_KeyPressed(KeyRight)) then
1431 P1MoveButton := 0; // Íå íàæàòû íè "Âëåâî", íè "Âïðàâî"
1433 // Ñåé÷àñ èëè ðàíüøå áûëè íàæàòû "Âëåâî"/"Âïðàâî" => ïåðåäàåì èãðîêó:
1434 if P1MoveButton = 1 then
1435 gPlayer1.PressKey(KEY_LEFT)
1436 else
1437 if P1MoveButton = 2 then
1438 gPlayer1.PressKey(KEY_RIGHT);
1440 // Ðàíüøå áûëà íàæàòà "Âïðàâî", à ñåé÷àñ "Âëåâî" => áåæèì âïðàâî, ñìîòðèì âëåâî:
1441 if (P1MoveButton = 2) and e_KeyPressed(KeyLeft) then
1442 gPlayer1.SetDirection(D_LEFT)
1443 else
1444 // Ðàíüøå áûëà íàæàòà "Âëåâî", à ñåé÷àñ "Âïðàâî" => áåæèì âëåâî, ñìîòðèì âïðàâî:
1445 if (P1MoveButton = 1) and e_KeyPressed(KeyRight) then
1446 gPlayer1.SetDirection(D_RIGHT)
1447 else
1448 // ×òî-òî áûëî íàæàòî è íå èçìåíèëîñü => êóäà áåæèì, òóäà è ñìîòðèì:
1449 if P1MoveButton <> 0 then
1450 gPlayer1.SetDirection(TDirection(P1MoveButton-1));
1452 // Îñòàëüíûå êëàâèøè:
1453 if e_KeyPressed(KeyJump) then gPlayer1.PressKey(KEY_JUMP);
1454 if e_KeyPressed(KeyUp) then gPlayer1.PressKey(KEY_UP);
1455 if e_KeyPressed(KeyDown) then gPlayer1.PressKey(KEY_DOWN);
1456 if e_KeyPressed(KeyFire) then gPlayer1.PressKey(KEY_FIRE);
1457 if e_KeyPressed(KeyNextWeapon) then gPlayer1.PressKey(KEY_NEXTWEAPON);
1458 if e_KeyPressed(KeyPrevWeapon) then gPlayer1.PressKey(KEY_PREVWEAPON);
1459 if e_KeyPressed(KeyOpen) then gPlayer1.PressKey(KEY_OPEN);
1460 end;
1461 // Âòîðîé èãðîê:
1462 if gPlayer2 <> nil then
1463 with gGameControls.P2Control do
1464 begin
1465 if e_KeyPressed(KeyLeft) and (not e_KeyPressed(KeyRight)) then
1466 P2MoveButton := 1 // Íàæàòà òîëüêî "Âëåâî"
1467 else
1468 if (not e_KeyPressed(KeyLeft)) and e_KeyPressed(KeyRight) then
1469 P2MoveButton := 2 // Íàæàòà òîëüêî "Âïðàâî"
1470 else
1471 if (not e_KeyPressed(KeyLeft)) and (not e_KeyPressed(KeyRight)) then
1472 P2MoveButton := 0; // Íå íàæàòû íè "Âëåâî", íè "Âïðàâî"
1474 // Ñåé÷àñ èëè ðàíüøå áûëè íàæàòû "Âëåâî"/"Âïðàâî" => ïåðåäàåì èãðîêó:
1475 if P2MoveButton = 1 then
1476 gPlayer2.PressKey(KEY_LEFT, 1000)
1477 else
1478 if P2MoveButton = 2 then
1479 gPlayer2.PressKey(KEY_RIGHT, 1000);
1481 // Ðàíüøå áûëà íàæàòà "Âïðàâî", à ñåé÷àñ "Âëåâî" => áåæèì âïðàâî, ñìîòðèì âëåâî:
1482 if (P2MoveButton = 2) and e_KeyPressed(KeyLeft) then
1483 gPlayer2.SetDirection(D_LEFT)
1484 else
1485 // Ðàíüøå áûëà íàæàòà "Âëåâî", à ñåé÷àñ "Âïðàâî" => áåæèì âëåâî, ñìîòðèì âïðàâî:
1486 if (P2MoveButton = 1) and e_KeyPressed(KeyRight) then
1487 gPlayer2.SetDirection(D_RIGHT)
1488 else
1489 // ×òî-òî áûëî íàæàòî è íå èçìåíèëîñü => êóäà áåæèì, òóäà è ñìîòðèì:
1490 if P2MoveButton <> 0 then
1491 gPlayer2.SetDirection(TDirection(P2MoveButton-1));
1493 // Îñòàëüíûå êëàâèøè:
1494 if e_KeyPressed(KeyJump) then gPlayer2.PressKey(KEY_JUMP, 1000);
1495 if e_KeyPressed(KeyUp) then gPlayer2.PressKey(KEY_UP, 1000);
1496 if e_KeyPressed(KeyDown) then gPlayer2.PressKey(KEY_DOWN, 1000);
1497 if e_KeyPressed(KeyFire) then gPlayer2.PressKey(KEY_FIRE);
1498 if e_KeyPressed(KeyNextWeapon) then gPlayer2.PressKey(KEY_NEXTWEAPON);
1499 if e_KeyPressed(KeyPrevWeapon) then gPlayer2.PressKey(KEY_PREVWEAPON);
1500 if e_KeyPressed(KeyOpen) then gPlayer2.PressKey(KEY_OPEN);
1501 end;
1502 end // if not console
1503 else
1504 if g_Game_IsNet and (gPlayer1 <> nil) then
1505 gPlayer1.PressKey(KEY_CHAT, 10000);
1507 end; // if server
1509 // Íàáëþäàòåëü
1510 if (gPlayer1 = nil) and (gPlayer2 = nil) and
1511 (not gConsoleShow) and (not gChatShow) and (g_ActiveWindow = nil) then
1512 begin
1513 if not gSpectKeyPress then
1514 begin
1515 if e_KeyPressed(gGameControls.P1Control.KeyJump) then
1516 begin
1517 // switch spect mode
1518 case gSpectMode of
1519 SPECT_NONE: ; // not spectator
1520 SPECT_STATS,
1521 SPECT_MAPVIEW: Inc(gSpectMode);
1522 SPECT_PLAYERS: gSpectMode := SPECT_STATS; // reset to 1
1523 end;
1524 gSpectKeyPress := True;
1525 end;
1526 if gSpectMode = SPECT_MAPVIEW then
1527 begin
1528 if e_KeyPressed(gGameControls.P1Control.KeyLeft) then
1529 gSpectX := Max(gSpectX - gSpectStep, 0);
1530 if e_KeyPressed(gGameControls.P1Control.KeyRight) then
1531 gSpectX := Min(gSpectX + gSpectStep, gMapInfo.Width - gScreenWidth);
1532 if e_KeyPressed(gGameControls.P1Control.KeyUp) then
1533 gSpectY := Max(gSpectY - gSpectStep, 0);
1534 if e_KeyPressed(gGameControls.P1Control.KeyDown) then
1535 gSpectY := Min(gSpectY + gSpectStep, gMapInfo.Height - gScreenHeight);
1536 if e_KeyPressed(gGameControls.P1Control.KeyPrevWeapon) then
1537 begin
1538 // decrease step
1539 if gSpectStep > 4 then gSpectStep := gSpectStep shr 1;
1540 gSpectKeyPress := True;
1541 end;
1542 if e_KeyPressed(gGameControls.P1Control.KeyNextWeapon) then
1543 begin
1544 // increase step
1545 if gSpectStep < 64 then gSpectStep := gSpectStep shl 1;
1546 gSpectKeyPress := True;
1547 end;
1548 end;
1549 if gSpectMode = SPECT_PLAYERS then
1550 begin
1551 if e_KeyPressed(gGameControls.P1Control.KeyUp) then
1552 begin
1553 // add second view
1554 gSpectViewTwo := True;
1555 gSpectKeyPress := True;
1556 end;
1557 if e_KeyPressed(gGameControls.P1Control.KeyDown) then
1558 begin
1559 // remove second view
1560 gSpectViewTwo := False;
1561 gSpectKeyPress := True;
1562 end;
1563 if e_KeyPressed(gGameControls.P1Control.KeyLeft) then
1564 begin
1565 // prev player (view 1)
1566 gSpectPID1 := GetActivePlayerID_Prev(gSpectPID1);
1567 gSpectKeyPress := True;
1568 end;
1569 if e_KeyPressed(gGameControls.P1Control.KeyRight) then
1570 begin
1571 // next player (view 1)
1572 gSpectPID1 := GetActivePlayerID_Next(gSpectPID1);
1573 gSpectKeyPress := True;
1574 end;
1575 if e_KeyPressed(gGameControls.P1Control.KeyPrevWeapon) then
1576 begin
1577 // prev player (view 2)
1578 gSpectPID2 := GetActivePlayerID_Prev(gSpectPID2);
1579 gSpectKeyPress := True;
1580 end;
1581 if e_KeyPressed(gGameControls.P1Control.KeyNextWeapon) then
1582 begin
1583 // next player (view 2)
1584 gSpectPID2 := GetActivePlayerID_Next(gSpectPID2);
1585 gSpectKeyPress := True;
1586 end;
1587 end;
1588 end
1589 else
1590 if (not e_KeyPressed(gGameControls.P1Control.KeyJump)) and
1591 (not e_KeyPressed(gGameControls.P1Control.KeyLeft)) and
1592 (not e_KeyPressed(gGameControls.P1Control.KeyRight)) and
1593 (not e_KeyPressed(gGameControls.P1Control.KeyUp)) and
1594 (not e_KeyPressed(gGameControls.P1Control.KeyDown)) and
1595 (not e_KeyPressed(gGameControls.P1Control.KeyPrevWeapon)) and
1596 (not e_KeyPressed(gGameControls.P1Control.KeyNextWeapon)) then
1597 gSpectKeyPress := False;
1598 end;
1600 // Îáíîâëÿåì âñå îñòàëüíîå:
1601 g_Map_Update();
1602 g_Items_Update();
1603 g_Triggers_Update();
1604 g_Weapon_Update();
1605 g_Monsters_Update();
1606 g_GFX_Update();
1607 g_Player_UpdateAll();
1608 g_Player_UpdatePhysicalObjects();
1609 if gGameSettings.GameType = GT_SERVER then
1610 if Length(gMonstersSpawned) > 0 then
1611 begin
1612 for I := 0 to High(gMonstersSpawned) do
1613 MH_SEND_MonsterSpawn(gMonstersSpawned[I]);
1614 SetLength(gMonstersSpawned, 0);
1615 end;
1617 if (gSoundTriggerTime > 8) then
1618 begin
1619 g_Game_UpdateTriggerSounds();
1620 gSoundTriggerTime := 0;
1621 end
1622 else
1623 Inc(gSoundTriggerTime);
1625 if (NetMode = NET_SERVER) then
1626 begin
1627 Inc(NetTimeToUpdate);
1628 Inc(NetTimeToReliable);
1629 if NetTimeToReliable >= NetRelupdRate then
1630 begin
1631 for I := 0 to High(gPlayers) do
1632 if gPlayers[I] <> nil then
1633 MH_SEND_PlayerPos(True, gPlayers[I].UID);
1635 if gMonsters <> nil then
1636 for I := 0 to High(gMonsters) do
1637 if gMonsters[I] <> nil then
1638 begin
1639 if (gMonsters[I].MonsterType = MONSTER_BARREL) then
1640 begin
1641 if (gMonsters[I].GameVelX <> 0) or (gMonsters[I].GameVelY <> 0) then
1642 MH_SEND_MonsterPos(gMonsters[I].UID);
1643 end
1644 else
1645 if (gMonsters[I].MonsterState <> MONSTATE_SLEEP) then
1646 if (gMonsters[I].MonsterState <> MONSTATE_DEAD) or
1647 (gMonsters[I].GameVelX <> 0) or
1648 (gMonsters[I].GameVelY <> 0) then
1649 MH_SEND_MonsterPos(gMonsters[I].UID);
1650 end;
1652 NetTimeToReliable := 0;
1653 NetTimeToUpdate := NetUpdateRate;
1654 end
1655 else if NetTimeToUpdate >= NetUpdateRate then
1656 begin
1657 if gPlayers <> nil then
1658 for I := 0 to High(gPlayers) do
1659 if gPlayers[I] <> nil then
1660 MH_SEND_PlayerPos(False, gPlayers[I].UID);
1662 if gMonsters <> nil then
1663 for I := 0 to High(gMonsters) do
1664 if gMonsters[I] <> nil then
1665 begin
1666 if (gMonsters[I].MonsterType = MONSTER_BARREL) then
1667 begin
1668 if (gMonsters[I].GameVelX <> 0) or (gMonsters[I].GameVelY <> 0) then
1669 MH_SEND_MonsterPos(gMonsters[I].UID);
1670 end
1671 else
1672 if (gMonsters[I].MonsterState <> MONSTATE_SLEEP) then
1673 if (gMonsters[I].MonsterState <> MONSTATE_DEAD) or
1674 (gMonsters[I].GameVelX <> 0) or
1675 (gMonsters[I].GameVelY <> 0) then
1676 MH_SEND_MonsterPos(gMonsters[I].UID);
1677 end;
1679 NetTimeToUpdate := 0;
1680 end;
1682 if NetUseMaster then
1683 if gTime >= NetTimeToMaster then
1684 begin
1685 if (NetMHost = nil) or (NetMPeer = nil) then
1686 if not g_Net_Slist_Connect then
1687 g_Console_Add(_lc[I_NET_MSG_ERROR] + _lc[I_NET_SLIST_ERROR]);
1689 g_Net_Slist_Update;
1690 NetTimeToMaster := gTime + NetMasterRate;
1691 end;
1692 end
1693 else
1694 if NetMode = NET_CLIENT then
1695 MC_SEND_PlayerPos();
1696 end; // if gameOn ...
1698 // Àêòèâíî îêíî èíòåðôåéñà - ïåðåäàåì êëàâèøè åìó:
1699 if g_ActiveWindow <> nil then
1700 begin
1701 w := e_GetFirstKeyPressed();
1703 if (w <> IK_INVALID) then
1704 begin
1705 Msg.Msg := MESSAGE_DIKEY;
1706 Msg.wParam := w;
1707 g_ActiveWindow.OnMessage(Msg);
1708 end;
1710 // Åñëè îíî îò ýòîãî íå çàêðûëîñü, òî îáíîâëÿåì:
1711 if g_ActiveWindow <> nil then
1712 g_ActiveWindow.Update();
1714 // Íóæíî ñìåíèòü ðàçðåøåíèå:
1715 if gResolutionChange then
1716 begin
1717 e_WriteLog('Changing resolution', MSG_NOTIFY);
1718 g_Game_ChangeResolution(gRC_Width, gRC_Height, gRC_FullScreen, gRC_Maximized);
1719 gResolutionChange := False;
1720 end;
1722 // Íóæíî ñìåíèòü ÿçûê:
1723 if gLanguageChange then
1724 begin
1725 //e_WriteLog('Read language file', MSG_NOTIFY);
1726 //g_Language_Load(DataDir + gLanguage + '.txt');
1727 g_Language_Set(gLanguage);
1728 g_Menu_Reset();
1729 gLanguageChange := False;
1730 end;
1731 end;
1733 // Äåëàåì ñêðèíøîò (íå ÷àùå 200 ìèëëèñåêóíä):
1734 if e_KeyPressed(gGameControls.GameControls.TakeScreenshot) then
1735 if (GetTimer()-LastScreenShot) > 200000 then
1736 begin
1737 g_TakeScreenShot();
1738 LastScreenShot := GetTimer();
1739 end;
1741 // Ãîðÿ÷àÿ êëàâèøà äëÿ âûçîâà ìåíþ âûõîäà èç èãðû (F10):
1742 if e_KeyPressed(IK_F10) and
1743 gGameOn and
1744 (not gConsoleShow) and
1745 (g_ActiveWindow = nil) then
1746 begin
1747 KeyPress(IK_F10);
1748 end;
1750 Time := GetTimer() div 1000;
1752 // Îáðàáîòêà îòëîæåííûõ ñîáûòèé:
1753 if gDelayedEvents <> nil then
1754 for a := 0 to High(gDelayedEvents) do
1755 if gDelayedEvents[a].Pending and
1757 ((gDelayedEvents[a].DEType = DE_GLOBEVENT) and (gDelayedEvents[a].Time <= Time)) or
1758 ((gDelayedEvents[a].DEType > DE_GLOBEVENT) and (gDelayedEvents[a].Time <= gTime))
1759 ) then
1760 begin
1761 case gDelayedEvents[a].DEType of
1762 DE_GLOBEVENT:
1763 g_Game_ExecuteEvent(gDelayedEvents[a].DEStr);
1764 DE_BFGHIT:
1765 if gGameOn then
1766 g_Game_Announce_GoodShot(gDelayedEvents[a].DENum);
1767 DE_KILLCOMBO:
1768 if gGameOn then
1769 begin
1770 g_Game_Announce_KillCombo(gDelayedEvents[a].DENum);
1771 if g_Game_IsNet and g_Game_IsServer then
1772 MH_SEND_GameEvent(NET_EV_KILLCOMBO, gDelayedEvents[a].DENum);
1773 end;
1774 end;
1775 gDelayedEvents[a].Pending := False;
1776 end;
1778 // Êàæäóþ ñåêóíäó îáíîâëÿåì ñ÷åò÷èê îáíîâëåíèé:
1779 UPSCounter := UPSCounter + 1;
1780 if Time - UPSTime >= 1000 then
1781 begin
1782 UPS := UPSCounter;
1783 UPSCounter := 0;
1784 UPSTime := Time;
1785 end;
1786 end;
1788 procedure g_Game_LoadData();
1789 begin
1790 if DataLoaded then Exit;
1792 e_WriteLog('Loading game data...', MSG_NOTIFY);
1794 g_Texture_CreateWADEx('NOTEXTURE', GameWAD+':TEXTURES\NOTEXTURE');
1795 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUD', GameWAD+':TEXTURES\HUD');
1796 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDAIR', GameWAD+':TEXTURES\AIRBAR');
1797 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDJET', GameWAD+':TEXTURES\JETBAR');
1798 g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDBG', GameWAD+':TEXTURES\HUDBG');
1799 g_Texture_CreateWADEx('TEXTURE_PLAYER_ARMORHUD', GameWAD+':TEXTURES\ARMORHUD');
1800 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG', GameWAD+':TEXTURES\FLAGHUD_RB');
1801 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_S', GameWAD+':TEXTURES\FLAGHUD_RS');
1802 g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_D', GameWAD+':TEXTURES\FLAGHUD_RD');
1803 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG', GameWAD+':TEXTURES\FLAGHUD_BB');
1804 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_S', GameWAD+':TEXTURES\FLAGHUD_BS');
1805 g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_D', GameWAD+':TEXTURES\FLAGHUD_BD');
1806 g_Texture_CreateWADEx('TEXTURE_PLAYER_TALKBUBBLE', GameWAD+':TEXTURES\TALKBUBBLE');
1807 g_Texture_CreateWADEx('TEXTURE_PLAYER_INVULPENTA', GameWAD+':TEXTURES\PENTA');
1808 g_Frames_CreateWAD(nil, 'FRAMES_TELEPORT', GameWAD+':TEXTURES\TELEPORT', 64, 64, 10, False);
1809 g_Sound_CreateWADEx('SOUND_GAME_TELEPORT', GameWAD+':SOUNDS\TELEPORT');
1810 g_Sound_CreateWADEx('SOUND_GAME_NOTELEPORT', GameWAD+':SOUNDS\NOTELEPORT');
1811 g_Sound_CreateWADEx('SOUND_GAME_DOOROPEN', GameWAD+':SOUNDS\DOOROPEN');
1812 g_Sound_CreateWADEx('SOUND_GAME_DOORCLOSE', GameWAD+':SOUNDS\DOORCLOSE');
1813 g_Sound_CreateWADEx('SOUND_GAME_BULK1', GameWAD+':SOUNDS\BULK1');
1814 g_Sound_CreateWADEx('SOUND_GAME_BULK2', GameWAD+':SOUNDS\BULK2');
1815 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE1', GameWAD+':SOUNDS\BUBBLE1');
1816 g_Sound_CreateWADEx('SOUND_GAME_BUBBLE2', GameWAD+':SOUNDS\BUBBLE2');
1817 g_Sound_CreateWADEx('SOUND_GAME_SWITCH1', GameWAD+':SOUNDS\SWITCH1');
1818 g_Sound_CreateWADEx('SOUND_GAME_SWITCH0', GameWAD+':SOUNDS\SWITCH0');
1819 g_Sound_CreateWADEx('SOUND_GAME_RADIO', GameWAD+':SOUNDS\RADIO');
1820 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD1', GameWAD+':SOUNDS\GOOD1');
1821 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD2', GameWAD+':SOUNDS\GOOD2');
1822 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD3', GameWAD+':SOUNDS\GOOD3');
1823 g_Sound_CreateWADEx('SOUND_ANNOUNCER_GOOD4', GameWAD+':SOUNDS\GOOD4');
1824 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL2X', GameWAD+':SOUNDS\KILL2X');
1825 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL3X', GameWAD+':SOUNDS\KILL3X');
1826 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILL4X', GameWAD+':SOUNDS\KILL4X');
1827 g_Sound_CreateWADEx('SOUND_ANNOUNCER_KILLMX', GameWAD+':SOUNDS\KILLMX');
1829 goodsnd[0] := TPlayableSound.Create();
1830 goodsnd[1] := TPlayableSound.Create();
1831 goodsnd[2] := TPlayableSound.Create();
1832 goodsnd[3] := TPlayableSound.Create();
1834 goodsnd[0].SetByName('SOUND_ANNOUNCER_GOOD1');
1835 goodsnd[1].SetByName('SOUND_ANNOUNCER_GOOD2');
1836 goodsnd[2].SetByName('SOUND_ANNOUNCER_GOOD3');
1837 goodsnd[3].SetByName('SOUND_ANNOUNCER_GOOD4');
1839 killsnd[0] := TPlayableSound.Create();
1840 killsnd[1] := TPlayableSound.Create();
1841 killsnd[2] := TPlayableSound.Create();
1842 killsnd[3] := TPlayableSound.Create();
1844 killsnd[0].SetByName('SOUND_ANNOUNCER_KILL2X');
1845 killsnd[1].SetByName('SOUND_ANNOUNCER_KILL3X');
1846 killsnd[2].SetByName('SOUND_ANNOUNCER_KILL4X');
1847 killsnd[3].SetByName('SOUND_ANNOUNCER_KILLMX');
1849 g_Game_SetLoadingText(_lc[I_LOAD_ITEMS_DATA], 0, False);
1850 g_Items_LoadData();
1852 g_Game_SetLoadingText(_lc[I_LOAD_WEAPONS_DATA], 0, False);
1853 g_Weapon_LoadData();
1855 g_Monsters_LoadData();
1857 DataLoaded := True;
1858 end;
1860 procedure g_Game_FreeData();
1861 begin
1862 if not DataLoaded then Exit;
1864 g_Items_FreeData();
1865 g_Weapon_FreeData();
1866 g_Monsters_FreeData();
1868 e_WriteLog('Releasing game data...', MSG_NOTIFY);
1870 g_Texture_Delete('NOTEXTURE');
1871 g_Texture_Delete('TEXTURE_PLAYER_HUD');
1872 g_Texture_Delete('TEXTURE_PLAYER_HUDBG');
1873 g_Texture_Delete('TEXTURE_PLAYER_ARMORHUD');
1874 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG');
1875 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_S');
1876 g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_D');
1877 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG');
1878 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_S');
1879 g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_D');
1880 g_Texture_Delete('TEXTURE_PLAYER_TALKBUBBLE');
1881 g_Texture_Delete('TEXTURE_PLAYER_INVULPENTA');
1882 g_Frames_DeleteByName('FRAMES_TELEPORT');
1883 g_Sound_Delete('SOUND_GAME_TELEPORT');
1884 g_Sound_Delete('SOUND_GAME_NOTELEPORT');
1885 g_Sound_Delete('SOUND_GAME_DOOROPEN');
1886 g_Sound_Delete('SOUND_GAME_DOORCLOSE');
1887 g_Sound_Delete('SOUND_GAME_BULK1');
1888 g_Sound_Delete('SOUND_GAME_BULK2');
1889 g_Sound_Delete('SOUND_GAME_BUBBLE1');
1890 g_Sound_Delete('SOUND_GAME_BUBBLE2');
1891 g_Sound_Delete('SOUND_GAME_SWITCH1');
1892 g_Sound_Delete('SOUND_GAME_SWITCH0');
1894 goodsnd[0].Free();
1895 goodsnd[1].Free();
1896 goodsnd[2].Free();
1897 goodsnd[3].Free();
1899 g_Sound_Delete('SOUND_ANNOUNCER_GOOD1');
1900 g_Sound_Delete('SOUND_ANNOUNCER_GOOD2');
1901 g_Sound_Delete('SOUND_ANNOUNCER_GOOD3');
1902 g_Sound_Delete('SOUND_ANNOUNCER_GOOD4');
1904 killsnd[0].Free();
1905 killsnd[1].Free();
1906 killsnd[2].Free();
1907 killsnd[3].Free();
1909 g_Sound_Delete('SOUND_ANNOUNCER_KILL2X');
1910 g_Sound_Delete('SOUND_ANNOUNCER_KILL3X');
1911 g_Sound_Delete('SOUND_ANNOUNCER_KILL4X');
1912 g_Sound_Delete('SOUND_ANNOUNCER_KILLMX');
1914 DataLoaded := False;
1915 end;
1917 procedure DrawCustomStat();
1918 var
1919 pc, x, y, w, _y,
1920 w1, w2, w3,
1921 t, p, m: Integer;
1922 ww1, hh1: Word;
1923 ww2, hh2, r, g, b, rr, gg, bb: Byte;
1924 s1, s2, topstr: String;
1925 begin
1926 e_TextureFontGetSize(gStdFont, ww2, hh2);
1928 e_PollInput();
1929 if e_KeyPressed(IK_TAB) then
1930 begin
1931 if not gStatsPressed then
1932 begin
1933 gStatsOff := not gStatsOff;
1934 gStatsPressed := True;
1935 end;
1936 end
1937 else
1938 gStatsPressed := False;
1940 if gStatsOff then
1941 begin
1942 s1 := _lc[I_MENU_INTER_NOTICE_TAB];
1943 w := (Length(s1) * ww2) div 2;
1944 x := gScreenWidth div 2 - w;
1945 y := 8;
1946 e_TextureFontPrint(x, y, s1, gStdFont);
1947 Exit;
1948 end;
1950 if (gGameSettings.GameMode = GM_COOP) then
1951 begin
1952 if gMissionFailed then
1953 topstr := _lc[I_MENU_INTER_MISSION_FAIL]
1954 else
1955 topstr := _lc[I_MENU_INTER_LEVEL_COMPLETE];
1956 end
1957 else
1958 topstr := _lc[I_MENU_INTER_ROUND_OVER];
1960 e_CharFont_GetSize(gMenuFont, topstr, ww1, hh1);
1961 e_CharFont_Print(gMenuFont, (gScreenWidth div 2)-(ww1 div 2), 16, topstr);
1963 if g_Game_IsNet then
1964 begin
1965 topstr := Format(_lc[I_MENU_INTER_NOTICE_TIME], [gServInterTime]);
1966 if not gChatShow then
1967 e_TextureFontPrintEx((gScreenWidth div 2)-(Length(topstr)*ww2 div 2),
1968 gScreenHeight-(hh2+4)*2, topstr, gStdFont, 255, 255, 255, 1);
1969 end;
1971 if g_Game_IsClient then
1972 topstr := _lc[I_MENU_INTER_NOTICE_MAP]
1973 else
1974 topstr := _lc[I_MENU_INTER_NOTICE_SPACE];
1975 if not gChatShow then
1976 e_TextureFontPrintEx((gScreenWidth div 2)-(Length(topstr)*ww2 div 2),
1977 gScreenHeight-(hh2+4), topstr, gStdFont, 255, 255, 255, 1);
1979 x := 32;
1980 y := 16+hh1+16;
1982 w := gScreenWidth-x*2;
1984 w2 := (w-16) div 6;
1985 w3 := w2;
1986 w1 := w-16-w2-w3;
1988 e_DrawFillQuad(x, y, gScreenWidth-x-1, gScreenHeight-y-1, 64, 64, 64, 32);
1989 e_DrawQuad(x, y, gScreenWidth-x-1, gScreenHeight-y-1, 255, 127, 0);
1991 m := Max(Length(_lc[I_MENU_MAP])+1, Length(_lc[I_GAME_GAME_TIME])+1)*ww2;
1993 case CustomStat.GameMode of
1994 GM_DM:
1995 begin
1996 if gGameSettings.MaxLives = 0 then
1997 s1 := _lc[I_GAME_DM]
1998 else
1999 s1 := _lc[I_GAME_LMS];
2000 end;
2001 GM_TDM:
2002 begin
2003 if gGameSettings.MaxLives = 0 then
2004 s1 := _lc[I_GAME_TDM]
2005 else
2006 s1 := _lc[I_GAME_TLMS];
2007 end;
2008 GM_CTF: s1 := _lc[I_GAME_CTF];
2009 GM_COOP:
2010 begin
2011 if gGameSettings.MaxLives = 0 then
2012 s1 := _lc[I_GAME_COOP]
2013 else
2014 s1 := _lc[I_GAME_SURV];
2015 end;
2016 else s1 := '';
2017 end;
2019 _y := y+16;
2020 e_TextureFontPrintEx(x+(w div 2)-(Length(s1)*ww2 div 2), _y, s1, gStdFont, 255, 255, 255, 1);
2021 _y := _y+8;
2023 _y := _y+16;
2024 e_TextureFontPrintEx(x+8, _y, _lc[I_MENU_MAP], gStdFont, 255, 127, 0, 1);
2025 e_TextureFontPrint(x+8+m, _y, Format('%s - %s', [CustomStat.Map, CustomStat.MapName]), gStdFont);
2027 _y := _y+16;
2028 e_TextureFontPrintEx(x+8, _y, _lc[I_GAME_GAME_TIME], gStdFont, 255, 127, 0, 1);
2029 e_TextureFontPrint(x+8+m, _y, Format('%d:%.2d:%.2d', [CustomStat.GameTime div 1000 div 3600,
2030 (CustomStat.GameTime div 1000 div 60) mod 60,
2031 CustomStat.GameTime div 1000 mod 60]), gStdFont);
2033 pc := Length(CustomStat.PlayerStat);
2034 if pc = 0 then Exit;
2036 if CustomStat.GameMode = GM_COOP then
2037 begin
2038 m := Max(Length(_lc[I_GAME_MONSTERS])+1, Length(_lc[I_GAME_SECRETS])+1)*ww2;
2039 _y := _y+32;
2040 s2 := _lc[I_GAME_MONSTERS];
2041 e_TextureFontPrintEx(x+8, _y, s2, gStdFont, 255, 127, 0, 1);
2042 e_TextureFontPrintEx(x+8+m, _y, IntToStr(gCoopMonstersKilled) + '/' + IntToStr(gTotalMonsters), gStdFont, 255, 255, 255, 1);
2043 _y := _y+16;
2044 s2 := _lc[I_GAME_SECRETS];
2045 e_TextureFontPrintEx(x+8, _y, s2, gStdFont, 255, 127, 0, 1);
2046 e_TextureFontPrintEx(x+8+m, _y, IntToStr(gCoopSecretsFound) + '/' + IntToStr(gSecretsCount), gStdFont, 255, 255, 255, 1);
2047 if gLastMap then
2048 begin
2049 m := Max(Length(_lc[I_GAME_MONSTERS_TOTAL])+1, Length(_lc[I_GAME_SECRETS_TOTAL])+1)*ww2;
2050 _y := _y-16;
2051 s2 := _lc[I_GAME_MONSTERS_TOTAL];
2052 e_TextureFontPrintEx(x+250, _y, s2, gStdFont, 255, 127, 0, 1);
2053 e_TextureFontPrintEx(x+250+m, _y, IntToStr(gCoopTotalMonstersKilled) + '/' + IntToStr(gCoopTotalMonsters), gStdFont, 255, 255, 255, 1);
2054 _y := _y+16;
2055 s2 := _lc[I_GAME_SECRETS_TOTAL];
2056 e_TextureFontPrintEx(x+250, _y, s2, gStdFont, 255, 127, 0, 1);
2057 e_TextureFontPrintEx(x+250+m, _y, IntToStr(gCoopTotalSecretsFound) + '/' + IntToStr(gCoopTotalSecrets), gStdFont, 255, 255, 255, 1);
2058 end;
2059 end;
2061 if CustomStat.GameMode in [GM_TDM, GM_CTF] then
2062 begin
2063 _y := _y+16+16;
2065 with CustomStat do
2066 if TeamStat[TEAM_RED].Goals > TeamStat[TEAM_BLUE].Goals then s1 := _lc[I_GAME_WIN_RED]
2067 else if TeamStat[TEAM_BLUE].Goals > TeamStat[TEAM_RED].Goals then s1 := _lc[I_GAME_WIN_BLUE]
2068 else s1 := _lc[I_GAME_WIN_DRAW];
2070 e_TextureFontPrintEx(x+8+(w div 2)-(Length(s1)*ww2 div 2), _y, s1, gStdFont, 255, 255, 255, 1);
2071 _y := _y+40;
2073 for t := TEAM_RED to TEAM_BLUE do
2074 begin
2075 if t = TEAM_RED then
2076 begin
2077 e_TextureFontPrintEx(x+8, _y, _lc[I_GAME_TEAM_RED],
2078 gStdFont, 255, 0, 0, 1);
2079 e_TextureFontPrintEx(x+w1+8, _y, IntToStr(CustomStat.TeamStat[TEAM_RED].Goals),
2080 gStdFont, 255, 0, 0, 1);
2081 r := 255;
2082 g := 0;
2083 b := 0;
2084 end
2085 else
2086 begin
2087 e_TextureFontPrintEx(x+8, _y, _lc[I_GAME_TEAM_BLUE],
2088 gStdFont, 0, 0, 255, 1);
2089 e_TextureFontPrintEx(x+w1+8, _y, IntToStr(CustomStat.TeamStat[TEAM_BLUE].Goals),
2090 gStdFont, 0, 0, 255, 1);
2091 r := 0;
2092 g := 0;
2093 b := 255;
2094 end;
2096 e_DrawLine(1, x+8, _y+20, x-8+w, _y+20, r, g, b);
2097 _y := _y+24;
2099 for p := 0 to High(CustomStat.PlayerStat) do
2100 if CustomStat.PlayerStat[p].Team = t then
2101 with CustomStat.PlayerStat[p] do
2102 begin
2103 if Spectator then
2104 begin
2105 rr := r div 2;
2106 gg := g div 2;
2107 bb := b div 2;
2108 end
2109 else
2110 begin
2111 rr := r;
2112 gg := g;
2113 bb := b;
2114 end;
2115 e_TextureFontPrintEx(x+8, _y, Name, gStdFont, rr, gg, bb, 1);
2116 e_TextureFontPrintEx(x+w1+8, _y, IntToStr(Frags), gStdFont, rr, gg, bb, 1);
2117 e_TextureFontPrintEx(x+w1+w2+8, _y, IntToStr(Deaths), gStdFont, rr, gg, bb, 1);
2118 _y := _y+24;
2119 end;
2121 _y := _y+16+16;
2122 end;
2123 end
2124 else if CustomStat.GameMode in [GM_DM, GM_COOP] then
2125 begin
2126 _y := _y+40;
2127 e_TextureFontPrintEx(x+8, _y, _lc[I_GAME_PLAYER_NAME], gStdFont, 255, 127, 0, 1);
2128 e_TextureFontPrintEx(x+8+w1, _y, _lc[I_GAME_FRAGS], gStdFont, 255, 127, 0, 1);
2129 e_TextureFontPrintEx(x+8+w1+w2, _y, _lc[I_GAME_DEATHS], gStdFont, 255, 127, 0, 1);
2131 _y := _y+24;
2132 for p := 0 to High(CustomStat.PlayerStat) do
2133 with CustomStat.PlayerStat[p] do
2134 begin
2135 e_DrawFillQuad(x+8, _y+4, x+24-1, _y+16+4-1, Color.R, Color.G, Color.B, 0);
2137 if Spectator then
2138 r := 127
2139 else
2140 r := 255;
2142 e_TextureFontPrintEx(x+8+16+8, _y+4, Name, gStdFont, r, r, r, 1, True);
2143 e_TextureFontPrintEx(x+w1+8+16+8, _y+4, IntToStr(Frags), gStdFont, r, r, r, 1, True);
2144 e_TextureFontPrintEx(x+w1+w2+8+16+8, _y+4, IntToStr(Deaths), gStdFont, r, r, r, 1, True);
2145 _y := _y+24;
2146 end;
2147 end;
2148 end;
2150 procedure DrawSingleStat();
2151 var
2152 tm, key_x, val_x, y: Integer;
2153 w1, w2, h: Word;
2154 s1, s2: String;
2156 procedure player_stat(n: Integer);
2157 var
2158 kpm: Real;
2160 begin
2161 // "Kills: # / #":
2162 s1 := Format(' %d ', [SingleStat.PlayerStat[n].Kills]);
2163 s2 := Format(' %d', [gTotalMonsters]);
2165 e_CharFont_Print(gMenuFont, key_x, y, _lc[I_MENU_INTER_KILLS]);
2166 e_CharFont_PrintEx(gMenuFont, val_x, y, s1, _RGB(255, 0, 0));
2167 e_CharFont_GetSize(gMenuFont, s1, w1, h);
2168 e_CharFont_Print(gMenuFont, val_x+w1, y, '/');
2169 s1 := s1 + '/';
2170 e_CharFont_GetSize(gMenuFont, s1, w1, h);
2171 e_CharFont_PrintEx(gMenuFont, val_x+w1, y, s2, _RGB(255, 0, 0));
2173 // "Kills-per-minute: ##.#":
2174 s1 := _lc[I_MENU_INTER_KPM];
2175 if tm > 0 then
2176 kpm := (SingleStat.PlayerStat[n].Kills / tm) * 60
2177 else
2178 kpm := SingleStat.PlayerStat[n].Kills;
2179 s2 := Format(' %.1f', [kpm]);
2181 e_CharFont_Print(gMenuFont, key_x, y+32, s1);
2182 e_CharFont_PrintEx(gMenuFont, val_x, y+32, s2, _RGB(255, 0, 0));
2184 // "Secrets found: # / #":
2185 s1 := Format(' %d ', [SingleStat.PlayerStat[n].Secrets]);
2186 s2 := Format(' %d', [SingleStat.TotalSecrets]);
2188 e_CharFont_Print(gMenuFont, key_x, y+64, _lc[I_MENU_INTER_SECRETS]);
2189 e_CharFont_PrintEx(gMenuFont, val_x, y+64, s1, _RGB(255, 0, 0));
2190 e_CharFont_GetSize(gMenuFont, s1, w1, h);
2191 e_CharFont_Print(gMenuFont, val_x+w1, y+64, '/');
2192 s1 := s1 + '/';
2193 e_CharFont_GetSize(gMenuFont, s1, w1, h);
2194 e_CharFont_PrintEx(gMenuFont, val_x+w1, y+64, s2, _RGB(255, 0, 0));
2195 end;
2197 begin
2198 // "Level Complete":
2199 e_CharFont_GetSize(gMenuFont, _lc[I_MENU_INTER_LEVEL_COMPLETE], w1, h);
2200 e_CharFont_Print(gMenuFont, (gScreenWidth-w1) div 2, 32, _lc[I_MENU_INTER_LEVEL_COMPLETE]);
2202 // Îïðåäåëÿåì êîîðäèíàòû âûðàâíèâàíèÿ ïî ñàìîé äëèííîé ñòðîêå:
2203 s1 := _lc[I_MENU_INTER_KPM];
2204 e_CharFont_GetSize(gMenuFont, s1, w1, h);
2205 Inc(w1, 16);
2206 s1 := ' 9999.9';
2207 e_CharFont_GetSize(gMenuFont, s1, w2, h);
2209 key_x := (gScreenWidth-w1-w2) div 2;
2210 val_x := key_x + w1;
2212 // "Time: #:##:##":
2213 tm := SingleStat.GameTime div 1000;
2214 s1 := _lc[I_MENU_INTER_TIME];
2215 s2 := Format(' %d:%.2d:%.2d', [tm div (60*60), (tm mod (60*60)) div 60, tm mod 60]);
2217 e_CharFont_Print(gMenuFont, key_x, 80, s1);
2218 e_CharFont_PrintEx(gMenuFont, val_x, 80, s2, _RGB(255, 0, 0));
2220 if SingleStat.TwoPlayers then
2221 begin
2222 // "Player 1":
2223 s1 := _lc[I_MENU_PLAYER_1];
2224 e_CharFont_GetSize(gMenuFont, s1, w1, h);
2225 e_CharFont_Print(gMenuFont, (gScreenWidth-w1) div 2, 128, s1);
2227 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
2228 y := 176;
2229 player_stat(0);
2231 // "Player 2":
2232 s1 := _lc[I_MENU_PLAYER_2];
2233 e_CharFont_GetSize(gMenuFont, s1, w1, h);
2234 e_CharFont_Print(gMenuFont, (gScreenWidth-w1) div 2, 288, s1);
2236 // Ñòàòèñòèêà âòîðîãî èãðîêà:
2237 y := 336;
2238 player_stat(1);
2239 end
2240 else
2241 begin
2242 // Ñòàòèñòèêà ïåðâîãî èãðîêà:
2243 y := 128;
2244 player_stat(0);
2245 end;
2246 end;
2248 procedure DrawLoadingStat();
2249 var
2250 ww, hh: Word;
2251 xx, yy, i: Integer;
2252 s: String;
2253 begin
2254 if Length(LoadingStat.Msgs) = 0 then
2255 Exit;
2257 e_CharFont_GetSize(gMenuFont, _lc[I_MENU_LOADING], ww, hh);
2258 yy := (gScreenHeight div 3);
2259 e_CharFont_Print(gMenuFont, (gScreenWidth div 2)-(ww div 2), yy-2*hh, _lc[I_MENU_LOADING]);
2260 xx := (gScreenWidth div 3);
2262 with LoadingStat do
2263 for i := 0 to NextMsg-1 do
2264 begin
2265 if (i = (NextMsg-1)) and (MaxValue > 0) then
2266 s := Format('%s: %d/%d', [Msgs[i], CurValue, MaxValue])
2267 else
2268 s := Msgs[i];
2270 e_CharFont_PrintEx(gMenuSmallFont, xx, yy, s, _RGB(255, 0, 0));
2271 yy := yy + LOADING_INTERLINE;
2272 end;
2273 end;
2275 procedure DrawMinimap(p: TPlayer; RenderRect: TRect);
2276 var
2277 a, aX, aY, aX2, aY2, Scale, ScaleSz: Integer;
2278 begin
2279 if (gMapInfo.Width > RenderRect.Right - RenderRect.Left) or
2280 (gMapInfo.Height > RenderRect.Bottom - RenderRect.Top) then
2281 begin
2282 Scale := 1;
2283 // Ñêîëüêî ïèêñåëîâ êàðòû â 1 ïèêñåëå ìèíè-êàðòû:
2284 ScaleSz := 16 div Scale;
2285 // Ðàçìåðû ìèíè-êàðòû:
2286 aX := max(gMapInfo.Width div ScaleSz, 1);
2287 aY := max(gMapInfo.Height div ScaleSz, 1);
2288 // Ðàìêà êàðòû:
2289 e_DrawFillQuad(0, 0, aX-1, aY-1, 0, 0, 0, 0);
2291 if gWalls <> nil then
2292 begin
2293 // Ðèñóåì ñòåíû:
2294 for a := 0 to High(gWalls) do
2295 with gWalls[a] do
2296 if PanelType <> 0 then
2297 begin
2298 // Ëåâûé âåðõíèé óãîë:
2299 aX := X div ScaleSz;
2300 aY := Y div ScaleSz;
2301 // Ðàçìåðû:
2302 aX2 := max(Width div ScaleSz, 1);
2303 aY2 := max(Height div ScaleSz, 1);
2304 // Ïðàâûé íèæíèé óãîë:
2305 aX2 := aX + aX2 - 1;
2306 aY2 := aY + aY2 - 1;
2308 case PanelType of
2309 PANEL_WALL: e_DrawFillQuad(aX, aY, aX2, aY2, 208, 208, 208, 0);
2310 PANEL_OPENDOOR, PANEL_CLOSEDOOR:
2311 if Enabled then e_DrawFillQuad(aX, aY, aX2, aY2, 160, 160, 160, 0);
2312 end;
2313 end;
2314 end;
2315 if gSteps <> nil then
2316 begin
2317 // Ðèñóåì ñòóïåíè:
2318 for a := 0 to High(gSteps) do
2319 with gSteps[a] do
2320 if PanelType <> 0 then
2321 begin
2322 // Ëåâûé âåðõíèé óãîë:
2323 aX := X div ScaleSz;
2324 aY := Y div ScaleSz;
2325 // Ðàçìåðû:
2326 aX2 := max(Width div ScaleSz, 1);
2327 aY2 := max(Height div ScaleSz, 1);
2328 // Ïðàâûé íèæíèé óãîë:
2329 aX2 := aX + aX2 - 1;
2330 aY2 := aY + aY2 - 1;
2332 e_DrawFillQuad(aX, aY, aX2, aY2, 128, 128, 128, 0);
2333 end;
2334 end;
2335 if gLifts <> nil then
2336 begin
2337 // Ðèñóåì ëèôòû:
2338 for a := 0 to High(gLifts) do
2339 with gLifts[a] do
2340 if PanelType <> 0 then
2341 begin
2342 // Ëåâûé âåðõíèé óãîë:
2343 aX := X div ScaleSz;
2344 aY := Y div ScaleSz;
2345 // Ðàçìåðû:
2346 aX2 := max(Width div ScaleSz, 1);
2347 aY2 := max(Height div ScaleSz, 1);
2348 // Ïðàâûé íèæíèé óãîë:
2349 aX2 := aX + aX2 - 1;
2350 aY2 := aY + aY2 - 1;
2352 case LiftType of
2353 0: e_DrawFillQuad(aX, aY, aX2, aY2, 116, 72, 36, 0);
2354 1: e_DrawFillQuad(aX, aY, aX2, aY2, 116, 124, 96, 0);
2355 2: e_DrawFillQuad(aX, aY, aX2, aY2, 200, 80, 4, 0);
2356 3: e_DrawFillQuad(aX, aY, aX2, aY2, 252, 140, 56, 0);
2357 end;
2358 end;
2359 end;
2360 if gWater <> nil then
2361 begin
2362 // Ðèñóåì âîäó:
2363 for a := 0 to High(gWater) do
2364 with gWater[a] do
2365 if PanelType <> 0 then
2366 begin
2367 // Ëåâûé âåðõíèé óãîë:
2368 aX := X div ScaleSz;
2369 aY := Y div ScaleSz;
2370 // Ðàçìåðû:
2371 aX2 := max(Width div ScaleSz, 1);
2372 aY2 := max(Height div ScaleSz, 1);
2373 // Ïðàâûé íèæíèé óãîë:
2374 aX2 := aX + aX2 - 1;
2375 aY2 := aY + aY2 - 1;
2377 e_DrawFillQuad(aX, aY, aX2, aY2, 0, 0, 192, 0);
2378 end;
2379 end;
2380 if gAcid1 <> nil then
2381 begin
2382 // Ðèñóåì êèñëîòó 1:
2383 for a := 0 to High(gAcid1) do
2384 with gAcid1[a] do
2385 if PanelType <> 0 then
2386 begin
2387 // Ëåâûé âåðõíèé óãîë:
2388 aX := X div ScaleSz;
2389 aY := Y div ScaleSz;
2390 // Ðàçìåðû:
2391 aX2 := max(Width div ScaleSz, 1);
2392 aY2 := max(Height div ScaleSz, 1);
2393 // Ïðàâûé íèæíèé óãîë:
2394 aX2 := aX + aX2 - 1;
2395 aY2 := aY + aY2 - 1;
2397 e_DrawFillQuad(aX, aY, aX2, aY2, 0, 176, 0, 0);
2398 end;
2399 end;
2400 if gAcid2 <> nil then
2401 begin
2402 // Ðèñóåì êèñëîòó 2:
2403 for a := 0 to High(gAcid2) do
2404 with gAcid2[a] do
2405 if PanelType <> 0 then
2406 begin
2407 // Ëåâûé âåðõíèé óãîë:
2408 aX := X div ScaleSz;
2409 aY := Y div ScaleSz;
2410 // Ðàçìåðû:
2411 aX2 := max(Width div ScaleSz, 1);
2412 aY2 := max(Height div ScaleSz, 1);
2413 // Ïðàâûé íèæíèé óãîë:
2414 aX2 := aX + aX2 - 1;
2415 aY2 := aY + aY2 - 1;
2417 e_DrawFillQuad(aX, aY, aX2, aY2, 176, 0, 0, 0);
2418 end;
2419 end;
2420 if gPlayers <> nil then
2421 begin
2422 // Ðèñóåì èãðîêîâ:
2423 for a := 0 to High(gPlayers) do
2424 if gPlayers[a] <> nil then with gPlayers[a] do
2425 if Live then begin
2426 // Ëåâûé âåðõíèé óãîë:
2427 aX := Obj.X div ScaleSz + 1;
2428 aY := Obj.Y div ScaleSz + 1;
2429 // Ðàçìåðû:
2430 aX2 := max(Obj.Rect.Width div ScaleSz, 1);
2431 aY2 := max(Obj.Rect.Height div ScaleSz, 1);
2432 // Ïðàâûé íèæíèé óãîë:
2433 aX2 := aX + aX2 - 1;
2434 aY2 := aY + aY2 - 1;
2436 if gPlayers[a] = p then
2437 e_DrawFillQuad(aX, aY, aX2, aY2, 0, 255, 0, 0)
2438 else
2439 case Team of
2440 TEAM_RED: e_DrawFillQuad(aX, aY, aX2, aY2, 255, 0, 0, 0);
2441 TEAM_BLUE: e_DrawFillQuad(aX, aY, aX2, aY2, 0, 0, 255, 0);
2442 else e_DrawFillQuad(aX, aY, aX2, aY2, 255, 128, 0, 0);
2443 end;
2444 end;
2445 end;
2446 if gMonsters <> nil then
2447 begin
2448 // Ðèñóåì ìîíñòðîâ:
2449 for a := 0 to High(gMonsters) do
2450 if gMonsters[a] <> nil then with gMonsters[a] do
2451 if Live then begin
2452 // Ëåâûé âåðõíèé óãîë:
2453 aX := Obj.X div ScaleSz + 1;
2454 aY := Obj.Y div ScaleSz + 1;
2455 // Ðàçìåðû:
2456 aX2 := max(Obj.Rect.Width div ScaleSz, 1);
2457 aY2 := max(Obj.Rect.Height div ScaleSz, 1);
2458 // Ïðàâûé íèæíèé óãîë:
2459 aX2 := aX + aX2 - 1;
2460 aY2 := aY + aY2 - 1;
2462 e_DrawFillQuad(aX, aY, aX2, aY2, 255, 255, 0, 0);
2463 end;
2464 end;
2465 end;
2466 end;
2468 procedure DrawMapView(x, y, w, h: Integer);
2469 var
2470 bx, by: Integer;
2471 begin
2472 glPushMatrix();
2474 bx := Round(x/(gMapInfo.Width - w)*(gBackSize.X - w));
2475 by := Round(y/(gMapInfo.Height - h)*(gBackSize.Y - h));
2476 g_Map_DrawBack(-bx, -by);
2478 sX := x;
2479 sY := y;
2480 sWidth := w;
2481 sHeight := h;
2483 glTranslatef(-x, -y, 0);
2485 g_Map_DrawPanels(PANEL_BACK);
2486 g_Map_DrawPanels(PANEL_STEP);
2487 g_Items_Draw();
2488 g_Weapon_Draw();
2489 g_Player_DrawShells();
2490 g_Player_DrawAll();
2491 g_Player_DrawCorpses();
2492 g_Map_DrawPanels(PANEL_WALL);
2493 g_Monsters_Draw();
2494 g_Map_DrawPanels(PANEL_CLOSEDOOR);
2495 g_GFX_Draw();
2496 g_Map_DrawFlags();
2497 g_Map_DrawPanels(PANEL_ACID1);
2498 g_Map_DrawPanels(PANEL_ACID2);
2499 g_Map_DrawPanels(PANEL_WATER);
2500 g_Map_DrawPanels(PANEL_FORE);
2501 if g_debug_HealthBar then
2502 begin
2503 g_Monsters_DrawHealth();
2504 g_Player_DrawHealth();
2505 end;
2507 glPopMatrix();
2508 end;
2510 procedure DrawPlayer(p: TPlayer);
2511 var
2512 px, py, a, b, c, d: Integer;
2513 //R: TRect;
2514 begin
2515 if (p = nil) or (p.FDummy) then
2516 begin
2517 glPushMatrix();
2518 g_Map_DrawBack(0, 0);
2519 glPopMatrix();
2520 Exit;
2521 end;
2523 gPlayerDrawn := p;
2525 glPushMatrix();
2527 px := p.GameX + PLAYER_RECT_CX;
2528 py := p.GameY + PLAYER_RECT_CY;
2530 if px > (gPlayerScreenSize.X div 2) then
2531 a := -px + (gPlayerScreenSize.X div 2)
2532 else
2533 a := 0;
2534 if py > (gPlayerScreenSize.Y div 2) then
2535 b := -py + (gPlayerScreenSize.Y div 2)
2536 else
2537 b := 0;
2538 if px > (gMapInfo.Width - (gPlayerScreenSize.X div 2)) then
2539 a := -gMapInfo.Width + gPlayerScreenSize.X;
2540 if py > (gMapInfo.Height - (gPlayerScreenSize.Y div 2)) then
2541 b := -gMapInfo.Height + gPlayerScreenSize.Y;
2542 if gMapInfo.Width <= gPlayerScreenSize.X then
2543 a := 0;
2544 if gMapInfo.Height <= gPlayerScreenSize.Y then
2545 b := 0;
2547 if p.IncCam <> 0 then
2548 begin
2549 if py > (gMapInfo.Height - (gPlayerScreenSize.Y div 2)) then
2550 begin
2551 if p.IncCam > 120-(py-(gMapInfo.Height-(gPlayerScreenSize.Y div 2))) then
2552 p.IncCam := 120-(py-(gMapInfo.Height-(gPlayerScreenSize.Y div 2)));
2553 end;
2555 if py < (gPlayerScreenSize.Y div 2) then
2556 begin
2557 if p.IncCam < -120+((gPlayerScreenSize.Y div 2)-py) then
2558 p.IncCam := -120+((gPlayerScreenSize.Y div 2)-py);
2559 end;
2561 if p.IncCam < 0 then
2562 while (py+(gPlayerScreenSize.Y div 2)-p.IncCam > gMapInfo.Height) and
2563 (p.IncCam < 0) do
2564 p.IncCam := p.IncCam + 1;
2566 if p.IncCam > 0 then
2567 while (py-(gPlayerScreenSize.Y div 2)-p.IncCam < 0) and
2568 (p.IncCam > 0) do
2569 p.IncCam := p.IncCam - 1;
2570 end;
2572 if (px< gPlayerScreenSize.X div 2) or
2573 (gMapInfo.Width-gPlayerScreenSize.X <= 256) then
2574 c := 0
2575 else
2576 if (px > gMapInfo.Width-(gPlayerScreenSize.X div 2)) then
2577 c := gBackSize.X - gPlayerScreenSize.X
2578 else
2579 c := Round((px-(gPlayerScreenSize.X div 2))/(gMapInfo.Width-gPlayerScreenSize.X)*(gBackSize.X-gPlayerScreenSize.X));
2581 if (py-p.IncCam <= gPlayerScreenSize.Y div 2) or
2582 (gMapInfo.Height-gPlayerScreenSize.Y <= 256) then
2583 d := 0
2584 else
2585 if (py-p.IncCam >= gMapInfo.Height-(gPlayerScreenSize.Y div 2)) then
2586 d := gBackSize.Y - gPlayerScreenSize.Y
2587 else
2588 d := Round((py-p.IncCam-(gPlayerScreenSize.Y div 2))/(gMapInfo.Height-gPlayerScreenSize.Y)*(gBackSize.Y-gPlayerScreenSize.Y));
2590 g_Map_DrawBack(-c, -d);
2592 sX := -a;
2593 sY := -(b+p.IncCam);
2594 sWidth := gPlayerScreenSize.X;
2595 sHeight := gPlayerScreenSize.Y;
2597 glTranslatef(a, b+p.IncCam, 0);
2599 g_Map_DrawPanels(PANEL_BACK);
2600 g_Map_DrawPanels(PANEL_STEP);
2601 g_Items_Draw();
2602 g_Weapon_Draw();
2603 g_Player_DrawShells();
2604 g_Player_DrawAll();
2605 g_Player_DrawCorpses();
2606 g_Map_DrawPanels(PANEL_WALL);
2607 g_Monsters_Draw();
2608 g_Map_DrawPanels(PANEL_CLOSEDOOR);
2609 g_GFX_Draw();
2610 g_Map_DrawFlags();
2611 g_Map_DrawPanels(PANEL_ACID1);
2612 g_Map_DrawPanels(PANEL_ACID2);
2613 g_Map_DrawPanels(PANEL_WATER);
2614 g_Map_DrawPanels(PANEL_FORE);
2615 if g_debug_HealthBar then
2616 begin
2617 g_Monsters_DrawHealth();
2618 g_Player_DrawHealth();
2619 end;
2621 if p.FSpectator then
2622 e_TextureFontPrintEx(p.GameX + PLAYER_RECT_CX - 4,
2623 p.GameY + PLAYER_RECT_CY - 4,
2624 'X', gStdFont, 255, 255, 255, 1, True);
2626 for a := 0 to High(gCollideMap) do
2627 for b := 0 to High(gCollideMap[a]) do
2628 begin
2629 d := 0;
2630 if ByteBool(gCollideMap[a, b] and MARK_WALL) then
2631 d := d + 1;
2632 if ByteBool(gCollideMap[a, b] and MARK_DOOR) then
2633 d := d + 2;
2635 case d of
2636 1: e_DrawPoint(1, b, a, 200, 200, 200);
2637 2: e_DrawPoint(1, b, a, 64, 64, 255);
2638 3: e_DrawPoint(1, b, a, 255, 0, 255);
2639 end;
2640 end;
2643 glPopMatrix();
2645 p.DrawPain();
2646 p.DrawPickup();
2647 p.DrawRulez();
2648 //if gShowMap then
2649 //DrawMinimap(p, _TRect(0, 0, 128, 128));
2650 if g_Debug_Player then
2651 g_Player_DrawDebug(p);
2652 p.DrawGUI();
2653 end;
2655 procedure g_Game_Draw();
2656 var
2657 ID: DWORD;
2658 w, h: Word;
2659 ww, hh: Byte;
2660 Time: Int64;
2661 back: string;
2662 plView1, plView2: TPlayer;
2663 Split: Boolean;
2664 begin
2665 if gExit = EXIT_QUIT then Exit;
2667 Time := GetTimer() div 1000;
2668 FPSCounter := FPSCounter+1;
2669 if Time - FPSTime >= 1000 then
2670 begin
2671 FPS := FPSCounter;
2672 FPSCounter := 0;
2673 FPSTime := Time;
2674 end;
2676 if gGameOn or (gState = STATE_FOLD) then
2677 begin
2678 if (gPlayer1 <> nil) and (gPlayer2 <> nil) then
2679 begin
2680 gSpectMode := SPECT_NONE;
2681 if not gRevertPlayers then
2682 begin
2683 plView1 := gPlayer1;
2684 plView2 := gPlayer2;
2685 end
2686 else
2687 begin
2688 plView1 := gPlayer2;
2689 plView2 := gPlayer1;
2690 end;
2691 end
2692 else
2693 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
2694 begin
2695 gSpectMode := SPECT_NONE;
2696 if gPlayer2 = nil then
2697 plView1 := gPlayer1
2698 else
2699 plView1 := gPlayer2;
2700 plView2 := nil;
2701 end
2702 else
2703 begin
2704 plView1 := nil;
2705 plView2 := nil;
2706 end;
2708 if (plView1 = nil) and (plView2 = nil) and (gSpectMode = SPECT_NONE) then
2709 gSpectMode := SPECT_STATS;
2711 if gSpectMode = SPECT_PLAYERS then
2712 if gPlayers <> nil then
2713 begin
2714 plView1 := GetActivePlayer_ByID(gSpectPID1);
2715 if plView1 = nil then
2716 begin
2717 gSpectPID1 := GetActivePlayerID_Next();
2718 plView1 := GetActivePlayer_ByID(gSpectPID1);
2719 end;
2720 if gSpectViewTwo then
2721 begin
2722 plView2 := GetActivePlayer_ByID(gSpectPID2);
2723 if plView2 = nil then
2724 begin
2725 gSpectPID2 := GetActivePlayerID_Next();
2726 plView2 := GetActivePlayer_ByID(gSpectPID2);
2727 end;
2728 end;
2729 end;
2731 if gSpectMode = SPECT_MAPVIEW then
2732 begin
2733 // Ðåæèì ïðîñìîòðà êàðòû
2734 Split := False;
2735 e_SetViewPort(0, 0, gScreenWidth, gScreenHeight);
2736 DrawMapView(gSpectX, gSpectY, gScreenWidth, gScreenHeight);
2737 gHearPoint1.Active := True;
2738 gHearPoint1.Coords.X := gScreenWidth div 2 + gSpectX;
2739 gHearPoint1.Coords.Y := gScreenHeight div 2 + gSpectY;
2740 gHearPoint2.Active := False;
2741 end
2742 else
2743 begin
2744 Split := (plView1 <> nil) and (plView2 <> nil);
2746 // Òî÷êè ñëóõà èãðîêîâ
2747 if plView1 <> nil then
2748 begin
2749 gHearPoint1.Active := True;
2750 gHearPoint1.Coords.X := plView1.GameX;
2751 gHearPoint1.Coords.Y := plView1.GameY;
2752 end else
2753 gHearPoint1.Active := False;
2754 if plView2 <> nil then
2755 begin
2756 gHearPoint2.Active := True;
2757 gHearPoint2.Coords.X := plView2.GameX;
2758 gHearPoint2.Coords.Y := plView2.GameY;
2759 end else
2760 gHearPoint2.Active := False;
2762 // Ðàçìåð ýêðàíîâ èãðîêîâ:
2763 gPlayerScreenSize.X := gScreenWidth-196;
2764 if Split then
2765 begin
2766 gPlayerScreenSize.Y := gScreenHeight div 2;
2767 if gScreenHeight mod 2 = 0 then
2768 Dec(gPlayerScreenSize.Y);
2769 end
2770 else
2771 gPlayerScreenSize.Y := gScreenHeight;
2773 if Split then
2774 if gScreenHeight mod 2 = 0 then
2775 e_SetViewPort(0, gPlayerScreenSize.Y+2, gPlayerScreenSize.X+196, gPlayerScreenSize.Y)
2776 else
2777 e_SetViewPort(0, gPlayerScreenSize.Y+1, gPlayerScreenSize.X+196, gPlayerScreenSize.Y);
2779 DrawPlayer(plView1);
2780 gPlayer1ScreenCoord.X := sX;
2781 gPlayer1ScreenCoord.Y := sY;
2783 if Split then
2784 begin
2785 e_SetViewPort(0, 0, gPlayerScreenSize.X+196, gPlayerScreenSize.Y);
2787 DrawPlayer(plView2);
2788 gPlayer2ScreenCoord.X := sX;
2789 gPlayer2ScreenCoord.Y := sY;
2790 end;
2792 e_SetViewPort(0, 0, gScreenWidth, gScreenHeight);
2794 if Split then
2795 e_DrawLine(2, 0, gScreenHeight div 2, gScreenWidth, gScreenHeight div 2, 0, 0, 0);
2796 end;
2798 if MessageText <> '' then
2799 begin
2800 w := 0;
2801 h := 0;
2802 e_CharFont_GetSizeFmt(gMenuFont, MessageText, w, h);
2803 if Split then
2804 e_CharFont_PrintFmt(gMenuFont, (gScreenWidth div 2)-(w div 2),
2805 (gScreenHeight div 2)-(h div 2), MessageText)
2806 else
2807 e_CharFont_PrintFmt(gMenuFont, (gScreenWidth div 2)-(w div 2),
2808 Round(gScreenHeight / 2.75)-(h div 2), MessageText);
2809 end;
2811 if IsDrawStat or (gSpectMode = 1) then DrawStat();
2813 if gSpectHUD and (not gChatShow) and (gSpectMode <> SPECT_NONE) then
2814 begin
2815 // Draw spectator GUI
2816 ww := 0;
2817 hh := 0;
2818 e_TextureFontGetSize(gStdFont, ww, hh);
2819 case gSpectMode of
2820 SPECT_STATS:
2821 e_TextureFontPrintEx(0, gScreenHeight - (hh+2)*2, 'MODE: Stats', gStdFont, 255, 255, 255, 1);
2822 SPECT_MAPVIEW:
2823 e_TextureFontPrintEx(0, gScreenHeight - (hh+2)*2, 'MODE: Observe Map', gStdFont, 255, 255, 255, 1);
2824 SPECT_PLAYERS:
2825 e_TextureFontPrintEx(0, gScreenHeight - (hh+2)*2, 'MODE: Watch Players', gStdFont, 255, 255, 255, 1);
2826 end;
2827 e_TextureFontPrintEx(2*ww, gScreenHeight - (hh+2), '< jump >', gStdFont, 255, 255, 255, 1);
2828 if gSpectMode = SPECT_MAPVIEW then
2829 begin
2830 e_TextureFontPrintEx(22*ww, gScreenHeight - (hh+2)*2, '[-]', gStdFont, 255, 255, 255, 1);
2831 e_TextureFontPrintEx(26*ww, gScreenHeight - (hh+2)*2, 'Step ' + IntToStr(gSpectStep), gStdFont, 255, 255, 255, 1);
2832 e_TextureFontPrintEx(34*ww, gScreenHeight - (hh+2)*2, '[+]', gStdFont, 255, 255, 255, 1);
2833 e_TextureFontPrintEx(18*ww, gScreenHeight - (hh+2), '<prev weap>', gStdFont, 255, 255, 255, 1);
2834 e_TextureFontPrintEx(30*ww, gScreenHeight - (hh+2), '<next weap>', gStdFont, 255, 255, 255, 1);
2835 end;
2836 if gSpectMode = SPECT_PLAYERS then
2837 begin
2838 e_TextureFontPrintEx(22*ww, gScreenHeight - (hh+2)*2, 'Player 1', gStdFont, 255, 255, 255, 1);
2839 e_TextureFontPrintEx(20*ww, gScreenHeight - (hh+2), '<left/right>', gStdFont, 255, 255, 255, 1);
2840 if gSpectViewTwo then
2841 begin
2842 e_TextureFontPrintEx(37*ww, gScreenHeight - (hh+2)*2, 'Player 2', gStdFont, 255, 255, 255, 1);
2843 e_TextureFontPrintEx(34*ww, gScreenHeight - (hh+2), '<prev w/next w>', gStdFont, 255, 255, 255, 1);
2844 e_TextureFontPrintEx(52*ww, gScreenHeight - (hh+2)*2, '2x View', gStdFont, 255, 255, 255, 1);
2845 e_TextureFontPrintEx(51*ww, gScreenHeight - (hh+2), '<up/down>', gStdFont, 255, 255, 255, 1);
2846 end
2847 else
2848 begin
2849 e_TextureFontPrintEx(35*ww, gScreenHeight - (hh+2)*2, '2x View', gStdFont, 255, 255, 255, 1);
2850 e_TextureFontPrintEx(34*ww, gScreenHeight - (hh+2), '<up/down>', gStdFont, 255, 255, 255, 1);
2851 end;
2852 end;
2853 end;
2854 end;
2856 if gPause and gGameOn and (g_ActiveWindow = nil) then
2857 begin
2858 e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
2860 e_CharFont_GetSize(gMenuFont, _lc[I_MENU_PAUSE], w, h);
2861 e_CharFont_Print(gMenuFont, (gScreenWidth div 2)-(w div 2),
2862 (gScreenHeight div 2)-(h div 2), _lc[I_MENU_PAUSE]);
2863 end;
2865 if not gGameOn then
2866 begin
2867 if (gState = STATE_MENU) then
2868 begin
2869 if ((g_ActiveWindow = nil) or (g_ActiveWindow.BackTexture = '')) then
2870 begin
2871 if g_Texture_Get('MENU_BACKGROUND', ID) then
2872 e_DrawSize(ID, 0, 0, 0, False, False, gScreenWidth, gScreenHeight)
2873 else e_Clear(GL_COLOR_BUFFER_BIT, 0, 0, 0);
2874 end;
2875 if g_ActiveWindow <> nil then
2876 e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
2877 end;
2879 if gState = STATE_FOLD then
2880 e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 0, 0, 0, EndingGameCounter);
2882 if gState = STATE_INTERCUSTOM then
2883 begin
2884 if gLastMap and (gGameSettings.GameMode = GM_COOP) then
2885 begin
2886 back := 'TEXTURE_endpic';
2887 if not g_Texture_Get(back, ID) then
2888 back := _lc[I_TEXTURE_ENDPIC];
2889 end
2890 else
2891 back := 'INTER';
2893 if g_Texture_Get(back, ID) then
2894 e_DrawSize(ID, 0, 0, 0, False, False, gScreenWidth, gScreenHeight)
2895 else
2896 e_Clear(GL_COLOR_BUFFER_BIT, 0, 0, 0);
2898 DrawCustomStat();
2900 if g_ActiveWindow <> nil then
2901 e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
2902 end;
2904 if gState = STATE_INTERSINGLE then
2905 begin
2906 if EndingGameCounter > 0 then
2907 e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 0, 0, 0, EndingGameCounter)
2908 else
2909 begin
2910 back := 'INTER';
2912 if g_Texture_Get(back, ID) then
2913 e_DrawSize(ID, 0, 0, 0, False, False, gScreenWidth, gScreenHeight)
2914 else
2915 e_Clear(GL_COLOR_BUFFER_BIT, 0, 0, 0);
2917 DrawSingleStat();
2919 if g_ActiveWindow <> nil then
2920 e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
2921 end;
2922 end;
2924 if gState = STATE_ENDPIC then
2925 begin
2926 ID := DWORD(-1);
2927 if not g_Texture_Get('TEXTURE_endpic', ID) then
2928 g_Texture_Get(_lc[I_TEXTURE_ENDPIC], ID);
2930 if ID <> DWORD(-1) then
2931 e_DrawSize(ID, 0, 0, 0, False, False, gScreenWidth, gScreenHeight)
2932 else
2933 e_Clear(GL_COLOR_BUFFER_BIT, 0, 0, 0);
2935 if g_ActiveWindow <> nil then
2936 e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
2937 end;
2939 if gState = STATE_SLIST then
2940 begin
2941 if g_Texture_Get('MENU_BACKGROUND', ID) then
2942 begin
2943 e_DrawSize(ID, 0, 0, 0, False, False, gScreenWidth, gScreenHeight);
2944 e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
2945 end;
2946 g_Serverlist_Draw(slCurrent);
2947 end;
2948 end;
2950 if g_ActiveWindow <> nil then
2951 begin
2952 if gGameOn then
2953 e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
2954 g_ActiveWindow.Draw();
2955 end;
2957 g_Console_Draw();
2959 {FIXME
2960 if g_debug_Sounds and gGameOn then
2961 begin
2962 for w := 0 to High(e_SoundsArray) do
2963 for h := 0 to e_SoundsArray[w].nRefs do
2964 e_DrawPoint(1, w+100, h+100, 255, 0, 0);
2965 end;
2968 if gShowFPS then
2969 begin
2970 e_TextureFontPrint(0, 0, Format('FPS: %d', [FPS]), gStdFont);
2971 e_TextureFontPrint(0, 16, Format('UPS: %d', [UPS]), gStdFont);
2972 end;
2974 if gGameOn and gShowTime and (gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT]) then
2975 e_TextureFontPrint(gScreenWidth-72, 0,
2976 Format('%d:%.2d:%.2d', [gTime div 1000 div 3600, (gTime div 1000 div 60) mod 60, gTime div 1000 mod 60]),
2977 gStdFont);
2978 end;
2980 procedure g_Game_Quit();
2981 begin
2982 g_Game_StopAllSounds(True);
2983 gMusic.Free();
2984 g_Game_SaveOptions();
2985 g_Game_FreeData();
2986 g_PlayerModel_FreeData();
2987 g_Texture_DeleteAll();
2988 g_Frames_DeleteAll();
2989 g_Menu_Free();
2991 if NetInitDone then g_Net_Free;
2993 // Íàäî óäàëèòü êàðòó ïîñëå òåñòà:
2994 if gMapToDelete <> '' then
2995 g_Game_DeleteTestMap();
2997 gExit := EXIT_QUIT;
2998 PushExitEvent();
2999 end;
3001 procedure g_FatalError(Text: String);
3002 begin
3003 g_Console_Add(Format(_lc[I_FATAL_ERROR], [Text]), True);
3004 e_WriteLog(Format(_lc[I_FATAL_ERROR], [Text]), MSG_WARNING);
3006 gExit := EXIT_SIMPLE;
3007 end;
3009 procedure g_SimpleError(Text: String);
3010 begin
3011 g_Console_Add(Format(_lc[I_SIMPLE_ERROR], [Text]), True);
3012 e_WriteLog(Format(_lc[I_SIMPLE_ERROR], [Text]), MSG_WARNING);
3013 end;
3015 procedure g_Game_SetupScreenSize();
3016 var
3017 d: Single;
3018 begin
3019 // Ðàçìåð ýêðàíîâ èãðîêîâ:
3020 gPlayerScreenSize.X := gScreenWidth-196;
3021 if (gPlayer1 <> nil) and (gPlayer2 <> nil) then
3022 gPlayerScreenSize.Y := gScreenHeight div 2
3023 else
3024 gPlayerScreenSize.Y := gScreenHeight;
3026 // Ðàçìåð çàäíåãî ïëàíà:
3027 if BackID <> DWORD(-1) then
3028 begin
3029 d := SKY_STRETCH;
3031 if (gScreenWidth*d > gMapInfo.Width) or
3032 (gScreenHeight*d > gMapInfo.Height) then
3033 d := 1.0;
3035 gBackSize.X := Round(gScreenWidth*d);
3036 gBackSize.Y := Round(gScreenHeight*d);
3037 end;
3038 end;
3040 procedure g_Game_ChangeResolution(newWidth, newHeight: Word; nowFull, nowMax: Boolean);
3041 begin
3042 g_Window_SetSize(newWidth, newHeight, nowFull);
3043 end;
3045 procedure g_Game_AddPlayer(Team: Byte = TEAM_NONE);
3046 begin
3047 if ((not gGameOn) and (gState <> STATE_INTERCUSTOM))
3048 or (not (gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT])) then
3049 Exit;
3050 if gPlayer1 = nil then
3051 begin
3052 if g_Game_IsClient then
3053 begin
3054 if NetPlrUID1 > -1 then
3055 begin
3056 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE);
3057 gPlayer1 := g_Player_Get(NetPlrUID1);
3058 end;
3059 Exit;
3060 end;
3062 if not (Team in [TEAM_RED, TEAM_BLUE]) then
3063 Team := gPlayer1Settings.Team;
3065 // Ñîçäàíèå ïåðâîãî èãðîêà:
3066 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
3067 gPlayer1Settings.Color,
3068 Team, False));
3069 if gPlayer1 = nil then
3070 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]))
3071 else
3072 begin
3073 gPlayer1.Name := gPlayer1Settings.Name;
3074 g_Console_Add(Format(_lc[I_PLAYER_JOIN], [gPlayer1.Name]), True);
3075 if g_Game_IsServer and g_Game_IsNet then
3076 MH_SEND_PlayerCreate(gPlayer1.UID);
3077 gPlayer1.Respawn(False, True);
3079 if g_Game_IsNet and NetUseMaster then
3080 g_Net_Slist_Update;
3081 end;
3083 Exit;
3084 end;
3085 if gPlayer2 = nil then
3086 begin
3087 if g_Game_IsClient then
3088 begin
3089 if NetPlrUID2 > -1 then
3090 gPlayer2 := g_Player_Get(NetPlrUID2);
3091 Exit;
3092 end;
3094 if not (Team in [TEAM_RED, TEAM_BLUE]) then
3095 Team := gPlayer2Settings.Team;
3097 // Ñîçäàíèå âòîðîãî èãðîêà:
3098 gPlayer2 := g_Player_Get(g_Player_Create(gPlayer2Settings.Model,
3099 gPlayer2Settings.Color,
3100 Team, False));
3101 if gPlayer2 = nil then
3102 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [2]))
3103 else
3104 begin
3105 gPlayer2.Name := gPlayer2Settings.Name;
3106 g_Console_Add(Format(_lc[I_PLAYER_JOIN], [gPlayer2.Name]), True);
3107 if g_Game_IsServer and g_Game_IsNet then
3108 MH_SEND_PlayerCreate(gPlayer2.UID);
3109 gPlayer2.Respawn(False, True);
3111 if g_Game_IsNet and NetUseMaster then
3112 g_Net_Slist_Update;
3113 end;
3115 Exit;
3116 end;
3117 end;
3119 procedure g_Game_RemovePlayer();
3120 var
3121 Pl: TPlayer;
3122 begin
3123 if ((not gGameOn) and (gState <> STATE_INTERCUSTOM))
3124 or (not (gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT])) then
3125 Exit;
3126 Pl := gPlayer2;
3127 if Pl <> nil then
3128 begin
3129 if g_Game_IsServer then
3130 begin
3131 Pl.Lives := 0;
3132 Pl.Kill(K_SIMPLEKILL, 0, HIT_DISCON);
3133 g_Console_Add(Format(_lc[I_PLAYER_LEAVE], [Pl.Name]), True);
3134 g_Player_Remove(Pl.UID);
3136 if g_Game_IsNet and NetUseMaster then
3137 g_Net_Slist_Update;
3138 end else
3139 gPlayer2 := nil;
3140 Exit;
3141 end;
3142 Pl := gPlayer1;
3143 if Pl <> nil then
3144 begin
3145 if g_Game_IsServer then
3146 begin
3147 Pl.Lives := 0;
3148 Pl.Kill(K_SIMPLEKILL, 0, HIT_DISCON);
3149 g_Console_Add(Format(_lc[I_PLAYER_LEAVE], [Pl.Name]), True);
3150 g_Player_Remove(Pl.UID);
3152 if g_Game_IsNet and NetUseMaster then
3153 g_Net_Slist_Update;
3154 end else
3155 begin
3156 gPlayer1 := nil;
3157 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE);
3158 end;
3159 Exit;
3160 end;
3161 end;
3163 procedure g_Game_Spectate();
3164 begin
3165 g_Game_RemovePlayer();
3166 if gPlayer1 <> nil then
3167 g_Game_RemovePlayer();
3168 end;
3170 procedure g_Game_SpectateCenterView();
3171 begin
3172 gSpectX := Max(gMapInfo.Width div 2 - gScreenWidth div 2, 0);
3173 gSpectY := Max(gMapInfo.Height div 2 - gScreenHeight div 2, 0);
3174 end;
3176 procedure g_Game_StartSingle(Map: String; TwoPlayers: Boolean; nPlayers: Byte);
3177 var
3178 i, nPl: Integer;
3179 begin
3180 g_Game_Free();
3182 e_WriteLog('Starting singleplayer game...', MSG_NOTIFY);
3184 g_Game_ClearLoading();
3186 // Íàñòðîéêè èãðû:
3187 FillByte(gGameSettings, SizeOf(TGameSettings), 0);
3188 gAimLine := False;
3189 gShowMap := False;
3190 gGameSettings.GameType := GT_SINGLE;
3191 gGameSettings.MaxLives := 0;
3192 gGameSettings.Options := gGameSettings.Options + GAME_OPTION_ALLOWEXIT;
3193 gGameSettings.Options := gGameSettings.Options + GAME_OPTION_MONSTERS;
3194 gGameSettings.Options := gGameSettings.Options + GAME_OPTION_BOTVSMONSTER;
3195 gSwitchGameMode := GM_SINGLE;
3197 g_Game_ExecuteEvent('ongamestart');
3199 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
3200 g_Game_SetupScreenSize();
3202 // Ñîçäàíèå ïåðâîãî èãðîêà:
3203 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
3204 gPlayer1Settings.Color,
3205 gPlayer1Settings.Team, False));
3206 if gPlayer1 = nil then
3207 begin
3208 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]));
3209 Exit;
3210 end;
3212 gPlayer1.Name := gPlayer1Settings.Name;
3213 nPl := 1;
3215 // Ñîçäàíèå âòîðîãî èãðîêà, åñëè åñòü:
3216 if TwoPlayers then
3217 begin
3218 gPlayer2 := g_Player_Get(g_Player_Create(gPlayer2Settings.Model,
3219 gPlayer2Settings.Color,
3220 gPlayer2Settings.Team, False));
3221 if gPlayer2 = nil then
3222 begin
3223 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [2]));
3224 Exit;
3225 end;
3227 gPlayer2.Name := gPlayer2Settings.Name;
3228 Inc(nPl);
3229 end;
3231 // Çàãðóçêà è çàïóñê êàðòû:
3232 if not g_Game_StartMap(MAP, True) then
3233 begin
3234 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [gGameSettings.WAD + ':\' + MAP]));
3235 Exit;
3236 end;
3238 // Íàñòðîéêè èãðîêîâ è áîòîâ:
3239 g_Player_Init();
3241 // Ñîçäàåì áîòîâ:
3242 for i := nPl+1 to nPlayers do
3243 g_Player_Create(STD_PLAYER_MODEL, _RGB(0, 0, 0), 0, True);
3244 end;
3246 procedure g_Game_StartCustom(Map: String; GameMode: Byte;
3247 TimeLimit, GoalLimit: Word;
3248 MaxLives: Byte;
3249 Options: LongWord; nPlayers: Byte);
3250 var
3251 i, nPl: Integer;
3252 begin
3253 g_Game_Free();
3255 e_WriteLog('Starting custom game...', MSG_NOTIFY);
3257 g_Game_ClearLoading();
3259 // Íàñòðîéêè èãðû:
3260 gGameSettings.GameType := GT_CUSTOM;
3261 gGameSettings.GameMode := GameMode;
3262 gSwitchGameMode := GameMode;
3263 gGameSettings.TimeLimit := TimeLimit;
3264 gGameSettings.GoalLimit := GoalLimit;
3265 gGameSettings.MaxLives := IfThen(GameMode = GM_CTF, 0, MaxLives);
3266 gGameSettings.Options := Options;
3268 gCoopTotalMonstersKilled := 0;
3269 gCoopTotalSecretsFound := 0;
3270 gCoopTotalMonsters := 0;
3271 gCoopTotalSecrets := 0;
3272 gAimLine := False;
3273 gShowMap := False;
3275 g_Game_ExecuteEvent('ongamestart');
3277 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
3278 g_Game_SetupScreenSize();
3280 // Ðåæèì íàáëþäàòåëÿ:
3281 if nPlayers = 0 then
3282 begin
3283 gPlayer1 := nil;
3284 gPlayer2 := nil;
3285 end;
3287 nPl := 0;
3288 if nPlayers >= 1 then
3289 begin
3290 // Ñîçäàíèå ïåðâîãî èãðîêà:
3291 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
3292 gPlayer1Settings.Color,
3293 gPlayer1Settings.Team, False));
3294 if gPlayer1 = nil then
3295 begin
3296 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]));
3297 Exit;
3298 end;
3300 gPlayer1.Name := gPlayer1Settings.Name;
3301 Inc(nPl);
3302 end;
3304 if nPlayers >= 2 then
3305 begin
3306 // Ñîçäàíèå âòîðîãî èãðîêà:
3307 gPlayer2 := g_Player_Get(g_Player_Create(gPlayer2Settings.Model,
3308 gPlayer2Settings.Color,
3309 gPlayer2Settings.Team, False));
3310 if gPlayer2 = nil then
3311 begin
3312 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [2]));
3313 Exit;
3314 end;
3316 gPlayer2.Name := gPlayer2Settings.Name;
3317 Inc(nPl);
3318 end;
3320 // Çàãðóçêà è çàïóñê êàðòû:
3321 if not g_Game_StartMap(Map, True) then
3322 begin
3323 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [Map]));
3324 Exit;
3325 end;
3327 // Íåò òî÷åê ïîÿâëåíèÿ:
3328 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1) +
3329 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2) +
3330 g_Map_GetPointCount(RESPAWNPOINT_DM) +
3331 g_Map_GetPointCount(RESPAWNPOINT_RED)+
3332 g_Map_GetPointCount(RESPAWNPOINT_BLUE)) < 1 then
3333 begin
3334 g_FatalError(_lc[I_GAME_ERROR_GET_SPAWN]);
3335 Exit;
3336 end;
3338 // Íàñòðîéêè èãðîêîâ è áîòîâ:
3339 g_Player_Init();
3341 // Ñîçäàåì áîòîâ:
3342 for i := nPl+1 to nPlayers do
3343 g_Player_Create(STD_PLAYER_MODEL, _RGB(0, 0, 0), 0, True);
3344 end;
3346 procedure g_Game_StartServer(Map: String; GameMode: Byte;
3347 TimeLimit, GoalLimit: Word; MaxLives: Byte;
3348 Options: LongWord; nPlayers: Byte;
3349 IPAddr: LongWord; Port: Word);
3350 begin
3351 g_Game_Free();
3353 e_WriteLog('Starting net game (server)...', MSG_NOTIFY);
3355 g_Game_ClearLoading();
3357 // Íàñòðîéêè èãðû:
3358 gGameSettings.GameType := GT_SERVER;
3359 gGameSettings.GameMode := GameMode;
3360 gSwitchGameMode := GameMode;
3361 gGameSettings.TimeLimit := TimeLimit;
3362 gGameSettings.GoalLimit := GoalLimit;
3363 gGameSettings.MaxLives := IfThen(GameMode = GM_CTF, 0, MaxLives);
3364 gGameSettings.Options := Options;
3366 gCoopTotalMonstersKilled := 0;
3367 gCoopTotalSecretsFound := 0;
3368 gCoopTotalMonsters := 0;
3369 gCoopTotalSecrets := 0;
3370 gAimLine := False;
3371 gShowMap := False;
3373 g_Game_ExecuteEvent('ongamestart');
3375 // Óñòàíîâêà ðàçìåðîâ îêíà èãðîêà
3376 g_Game_SetupScreenSize();
3378 // Ðåæèì íàáëþäàòåëÿ:
3379 if nPlayers = 0 then
3380 begin
3381 gPlayer1 := nil;
3382 gPlayer2 := nil;
3383 end;
3385 if nPlayers >= 1 then
3386 begin
3387 // Ñîçäàíèå ïåðâîãî èãðîêà:
3388 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
3389 gPlayer1Settings.Color,
3390 gPlayer1Settings.Team, False));
3391 if gPlayer1 = nil then
3392 begin
3393 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]));
3394 Exit;
3395 end;
3397 gPlayer1.Name := gPlayer1Settings.Name;
3398 end;
3400 if nPlayers >= 2 then
3401 begin
3402 // Ñîçäàíèå âòîðîãî èãðîêà:
3403 gPlayer2 := g_Player_Get(g_Player_Create(gPlayer2Settings.Model,
3404 gPlayer2Settings.Color,
3405 gPlayer2Settings.Team, False));
3406 if gPlayer2 = nil then
3407 begin
3408 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [2]));
3409 Exit;
3410 end;
3412 gPlayer2.Name := gPlayer2Settings.Name;
3413 end;
3415 // Ñòàðòóåì ñåðâåð
3416 if not g_Net_Host(IPAddr, Port, NetMaxClients) then
3417 begin
3418 g_FatalError(_lc[I_NET_MSG] + _lc[I_NET_ERR_HOST]);
3419 Exit;
3420 end;
3422 g_Net_Slist_Set(NetSlistIP, NetSlistPort);
3424 // Çàãðóçêà è çàïóñê êàðòû:
3425 if not g_Game_StartMap(Map, True) then
3426 begin
3427 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [Map]));
3428 Exit;
3429 end;
3431 // Íåò òî÷åê ïîÿâëåíèÿ:
3432 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1) +
3433 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2) +
3434 g_Map_GetPointCount(RESPAWNPOINT_DM) +
3435 g_Map_GetPointCount(RESPAWNPOINT_RED)+
3436 g_Map_GetPointCount(RESPAWNPOINT_BLUE)) < 1 then
3437 begin
3438 g_FatalError(_lc[I_GAME_ERROR_GET_SPAWN]);
3439 Exit;
3440 end;
3442 // Íàñòðîéêè èãðîêîâ è áîòîâ:
3443 g_Player_Init();
3445 NetState := NET_STATE_GAME;
3446 end;
3448 procedure g_Game_StartClient(Addr: String; Port: Word; PW: String);
3449 var
3450 Map: String;
3451 WadName: string;
3452 Ptr: Pointer;
3453 T: Cardinal;
3454 MID: Byte;
3455 State: Byte;
3456 OuterLoop: Boolean;
3457 newResPath: string;
3458 begin
3459 g_Game_Free();
3461 State := 0;
3462 e_WriteLog('Starting net game (client)...', MSG_NOTIFY);
3463 e_WriteLog('NET: Trying to connect to ' + Addr + ':' + IntToStr(Port) + '...', MSG_NOTIFY);
3465 g_Game_ClearLoading();
3467 // Íàñòðîéêè èãðû:
3468 gGameSettings.GameType := GT_CLIENT;
3470 gCoopTotalMonstersKilled := 0;
3471 gCoopTotalSecretsFound := 0;
3472 gCoopTotalMonsters := 0;
3473 gCoopTotalSecrets := 0;
3474 gAimLine := False;
3475 gShowMap := False;
3477 g_Game_ExecuteEvent('ongamestart');
3479 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
3480 g_Game_SetupScreenSize();
3482 NetState := NET_STATE_AUTH;
3484 g_Game_SetLoadingText(_lc[I_LOAD_CONNECT], 0, False);
3485 // Ñòàðòóåì êëèåíò
3486 if not g_Net_Connect(Addr, Port) then
3487 begin
3488 g_FatalError(_lc[I_NET_MSG] + _lc[I_NET_ERR_CONN]);
3489 NetState := NET_STATE_NONE;
3490 Exit;
3491 end;
3493 g_Game_SetLoadingText(_lc[I_LOAD_SEND_INFO], 0, False);
3494 MC_SEND_Info(PW);
3495 g_Game_SetLoadingText(_lc[I_LOAD_WAIT_INFO], 0, False);
3497 OuterLoop := True;
3498 while OuterLoop do
3499 begin
3500 while (enet_host_service(NetHost, @NetEvent, 0) > 0) do
3501 begin
3502 if (NetEvent.kind = ENET_EVENT_TYPE_RECEIVE) then
3503 begin
3504 Ptr := NetEvent.packet^.data;
3505 e_Raw_Seek(0);
3507 MID := e_Raw_Read_Byte(Ptr);
3509 if (MID = NET_MSG_INFO) and (State = 0) then
3510 begin
3511 NetMyID := e_Raw_Read_Byte(Ptr);
3512 NetPlrUID1 := e_Raw_Read_Word(Ptr);
3514 WadName := e_Raw_Read_String(Ptr);
3515 Map := e_Raw_Read_String(Ptr);
3517 gWADHash := e_Raw_Read_MD5(Ptr);
3519 gGameSettings.GameMode := e_Raw_Read_Byte(Ptr);
3520 gSwitchGameMode := gGameSettings.GameMode;
3521 gGameSettings.GoalLimit := e_Raw_Read_Word(Ptr);
3522 gGameSettings.TimeLimit := e_Raw_Read_Word(Ptr);
3523 gGameSettings.MaxLives := e_Raw_Read_Byte(Ptr);
3524 gGameSettings.Options := e_Raw_Read_LongWord(Ptr);
3525 T := e_Raw_Read_LongWord(Ptr);
3527 newResPath := g_Res_SearchSameWAD(MapsDir, WadName, gWADHash);
3528 if newResPath = '' then
3529 begin
3530 g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
3531 newResPath := g_Res_DownloadWAD(WadName);
3532 if newResPath = '' then
3533 begin
3534 g_FatalError(_lc[I_NET_ERR_HASH]);
3535 enet_packet_destroy(NetEvent.packet);
3536 NetState := NET_STATE_NONE;
3537 Exit;
3538 end;
3539 end;
3540 newResPath := ExtractRelativePath(MapsDir, newResPath);
3542 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
3543 gPlayer1Settings.Color,
3544 gPlayer1Settings.Team, False));
3546 if gPlayer1 = nil then
3547 begin
3548 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]));
3550 enet_packet_destroy(NetEvent.packet);
3551 NetState := NET_STATE_NONE;
3552 Exit;
3553 end;
3555 gPlayer1.Name := gPlayer1Settings.Name;
3556 gPlayer1.UID := NetPlrUID1;
3557 gPlayer1.Reset(True);
3559 if not g_Game_StartMap(newResPath + ':\' + Map, True) then
3560 begin
3561 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [WadName + ':\' + Map]));
3563 enet_packet_destroy(NetEvent.packet);
3564 NetState := NET_STATE_NONE;
3565 Exit;
3566 end;
3568 gTime := T;
3570 State := 1;
3571 OuterLoop := False;
3572 enet_packet_destroy(NetEvent.packet);
3573 break;
3574 end
3575 else
3576 enet_packet_destroy(NetEvent.packet);
3577 end
3578 else
3579 if (NetEvent.kind = ENET_EVENT_TYPE_DISCONNECT) then
3580 begin
3581 State := 0;
3582 if (NetEvent.data <= NET_DISC_MAX) then
3583 g_Console_Add(_lc[I_NET_MSG_ERROR] + _lc[I_NET_ERR_CONN] + ' ' +
3584 _lc[TStrings_Locale(Cardinal(I_NET_DISC_NONE) + NetEvent.data)], True);
3585 OuterLoop := False;
3586 Break;
3587 end;
3588 end;
3590 ProcessLoading();
3592 e_PollInput();
3594 if e_KeyPressed(IK_ESCAPE) or e_KeyPressed(IK_SPACE) then
3595 begin
3596 State := 0;
3597 break;
3598 end;
3599 end;
3601 if State <> 1 then
3602 begin
3603 g_FatalError(_lc[I_NET_MSG] + _lc[I_NET_ERR_CONN]);
3604 NetState := NET_STATE_NONE;
3605 Exit;
3606 end;
3608 gLMSRespawn := LMS_RESPAWN_NONE;
3609 gLMSRespawnTime := 0;
3611 g_Player_Init();
3612 NetState := NET_STATE_GAME;
3613 MC_SEND_FullStateRequest;
3614 e_WriteLog('NET: Connection successful.', MSG_NOTIFY);
3615 end;
3617 procedure g_Game_SaveOptions();
3618 begin
3619 g_Options_Write_Video(GameDir+'/'+CONFIG_FILENAME);
3620 end;
3622 procedure g_Game_ChangeMap(MapPath: String);
3623 var
3624 Force: Boolean;
3625 begin
3626 g_Game_ClearLoading();
3628 Force := gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF];
3629 // Åñëè óðîâåíü çàâåðøèëñÿ ïî òðèããåðó Âûõîä, íå î÷èùàòü èíâåíòàðü
3630 if gExitByTrigger then
3631 begin
3632 Force := False;
3633 gExitByTrigger := False;
3634 end;
3635 if not g_Game_StartMap(MapPath, Force) then
3636 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [MapPath]));
3637 end;
3639 procedure g_Game_Restart();
3640 var
3641 Map: string;
3642 begin
3643 if g_Game_IsClient then
3644 Exit;
3645 g_ProcessResourceStr(gMapInfo.Map, nil, nil, @Map);
3647 MessageTime := 0;
3648 gGameOn := False;
3649 g_Game_ClearLoading();
3650 g_Game_StartMap(Map, True);
3651 end;
3653 function g_Game_StartMap(Map: String; Force: Boolean = False): Boolean;
3654 var
3655 NewWAD, ResName: String;
3656 I: Integer;
3657 begin
3658 g_Map_Free();
3659 g_Player_RemoveAllCorpses();
3661 if (not g_Game_IsClient) and
3662 (gSwitchGameMode <> gGameSettings.GameMode) and
3663 (gGameSettings.GameMode <> GM_SINGLE) then
3664 begin
3665 if gSwitchGameMode = GM_CTF then
3666 gGameSettings.MaxLives := 0;
3667 gGameSettings.GameMode := gSwitchGameMode;
3668 Force := True;
3669 end else
3670 gSwitchGameMode := gGameSettings.GameMode;
3672 g_Player_ResetTeams();
3674 if Pos(':\', Map) > 0 then
3675 begin
3676 g_ProcessResourceStr(Map, @NewWAD, nil, @ResName);
3677 if g_Game_IsServer then
3678 begin
3679 gWADHash := MD5File(MapsDir + NewWAD);
3680 g_Game_LoadWAD(NewWAD);
3681 end else
3682 // hash recieved in MC_RECV_GameEvent -> NET_EV_MAPSTART
3683 g_Game_ClientWAD(NewWAD, gWADHash);
3684 end else
3685 ResName := Map;
3687 Result := g_Map_Load(MapsDir + gGameSettings.WAD + ':\' + ResName);
3688 if Result then
3689 begin
3690 g_Player_ResetAll(Force or gLastMap, gGameSettings.GameType = GT_SINGLE);
3692 gState := STATE_NONE;
3693 g_ActiveWindow := nil;
3694 gGameOn := True;
3696 DisableCheats();
3697 ResetTimer();
3699 if gGameSettings.GameMode = GM_CTF then
3700 begin
3701 g_Map_ResetFlag(FLAG_RED);
3702 g_Map_ResetFlag(FLAG_BLUE);
3703 // CTF, à ôëàãîâ íåò:
3704 if not g_Map_HaveFlagPoints() then
3705 g_SimpleError(_lc[I_GAME_ERROR_CTF]);
3706 end;
3707 end
3708 else
3709 begin
3710 gState := STATE_MENU;
3711 gGameOn := False;
3712 end;
3714 gExit := 0;
3715 gPause := False;
3716 gTime := 0;
3717 NetTimeToUpdate := 1;
3718 NetTimeToReliable := 0;
3719 NetTimeToMaster := NetMasterRate;
3720 gLMSRespawn := LMS_RESPAWN_NONE;
3721 gLMSRespawnTime := 0;
3722 gMissionFailed := False;
3723 gNextMap := '';
3725 gCoopMonstersKilled := 0;
3726 gCoopSecretsFound := 0;
3728 gVoteInProgress := False;
3729 gVotePassed := False;
3730 gVoteCount := 0;
3731 gVoted := False;
3733 gStatsOff := False;
3735 if not gGameOn then Exit;
3737 g_Game_SpectateCenterView();
3739 if (gGameSettings.MaxLives > 0) and (gGameSettings.WarmupTime > 0) then
3740 begin
3741 gLMSRespawn := LMS_RESPAWN_WARMUP;
3742 gLMSRespawnTime := gTime + gGameSettings.WarmupTime*1000;
3743 gLMSSoftSpawn := True;
3744 if NetMode = NET_SERVER then
3745 MH_SEND_GameEvent(NET_EV_LMS_WARMUP, (gLMSRespawnTime - gTime) div 1000)
3746 else
3747 g_Console_Add(Format(_lc[I_MSG_WARMUP_START], [(gLMSRespawnTime - gTime) div 1000]), True);
3748 end;
3750 if NetMode = NET_SERVER then
3751 begin
3752 MH_SEND_GameEvent(NET_EV_MAPSTART, gGameSettings.GameMode, Map);
3754 // Ìàñòåðñåðâåð
3755 if NetUseMaster then
3756 begin
3757 if (NetMHost = nil) or (NetMPeer = nil) then
3758 if not g_Net_Slist_Connect then
3759 g_Console_Add(_lc[I_NET_MSG_ERROR] + _lc[I_NET_SLIST_ERROR]);
3761 g_Net_Slist_Update;
3762 end;
3764 if NetClients <> nil then
3765 for I := 0 to High(NetClients) do
3766 if NetClients[I].Used then
3767 begin
3768 NetClients[I].Voted := False;
3769 if NetClients[I].RequestedFullUpdate then
3770 begin
3771 MH_SEND_Everything((NetClients[I].State = NET_STATE_AUTH), I);
3772 NetClients[I].RequestedFullUpdate := False;
3773 end;
3774 end;
3776 g_Net_UnbanNonPermHosts();
3777 end;
3779 if gLastMap then
3780 begin
3781 gCoopTotalMonstersKilled := 0;
3782 gCoopTotalSecretsFound := 0;
3783 gCoopTotalMonsters := 0;
3784 gCoopTotalSecrets := 0;
3785 gLastMap := False;
3786 end;
3788 g_Game_ExecuteEvent('onmapstart');
3789 end;
3791 procedure SetFirstLevel();
3792 begin
3793 gNextMap := '';
3795 MapList := g_Map_GetMapsList(MapsDir + gGameSettings.WAD);
3796 if MapList = nil then
3797 Exit;
3799 SortSArray(MapList);
3800 gNextMap := MapList[Low(MapList)];
3802 MapList := nil;
3803 end;
3805 procedure g_Game_ExitLevel(Map: Char16);
3806 begin
3807 gNextMap := Map;
3809 gCoopTotalMonstersKilled := gCoopTotalMonstersKilled + gCoopMonstersKilled;
3810 gCoopTotalSecretsFound := gCoopTotalSecretsFound + gCoopSecretsFound;
3811 gCoopTotalMonsters := gCoopTotalMonsters + gTotalMonsters;
3812 gCoopTotalSecrets := gCoopTotalSecrets + gSecretsCount;
3814 // Âûøëè â âûõîä â Îäèíî÷íîé èãðå:
3815 if gGameSettings.GameType = GT_SINGLE then
3816 gExit := EXIT_ENDLEVELSINGLE
3817 else // Âûøëè â âûõîä â Ñâîåé èãðå
3818 begin
3819 gExit := EXIT_ENDLEVELCUSTOM;
3820 if gGameSettings.GameMode = GM_COOP then
3821 g_Player_RememberAll;
3823 if not g_Map_Exist(MapsDir + gGameSettings.WAD + ':\' + gNextMap) then
3824 begin
3825 gLastMap := True;
3826 if gGameSettings.GameMode = GM_COOP then
3827 gStatsOff := True;
3829 gStatsPressed := True;
3830 gNextMap := 'MAP01';
3832 if not g_Map_Exist(MapsDir + gGameSettings.WAD + ':\' + gNextMap) then
3833 g_Game_NextLevel;
3835 if g_Game_IsNet then
3836 begin
3837 MH_SEND_GameStats();
3838 MH_SEND_CoopStats();
3839 end;
3840 end;
3841 end;
3842 end;
3844 procedure g_Game_RestartLevel();
3845 var
3846 Map: string;
3847 begin
3848 if gGameSettings.GameMode = GM_SINGLE then
3849 begin
3850 g_Game_Restart();
3851 Exit;
3852 end;
3853 gExit := EXIT_ENDLEVELCUSTOM;
3854 g_ProcessResourceStr(gMapInfo.Map, nil, nil, @Map);
3855 gNextMap := Map;
3856 end;
3858 procedure g_Game_ClientWAD(NewWAD: String; WHash: TMD5Digest);
3859 var
3860 gWAD: String;
3861 begin
3862 if LowerCase(NewWAD) = LowerCase(gGameSettings.WAD) then
3863 Exit;
3864 if not g_Game_IsClient then
3865 Exit;
3866 gWAD := g_Res_SearchSameWAD(MapsDir, ExtractFileName(NewWAD), WHash);
3867 if gWAD = '' then
3868 begin
3869 g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
3870 gWAD := g_Res_DownloadWAD(ExtractFileName(NewWAD));
3871 if gWAD = '' then
3872 begin
3873 g_Game_Free();
3874 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_WAD], [ExtractFileName(NewWAD)]));
3875 Exit;
3876 end;
3877 end;
3878 NewWAD := ExtractRelativePath(MapsDir, gWAD);
3879 g_Game_LoadWAD(NewWAD);
3880 end;
3882 procedure g_Game_RestartRound(NoMapRestart: Boolean = False);
3883 var
3884 i, n, nb, nr: Integer;
3885 begin
3886 if not g_Game_IsServer then Exit;
3887 if gLMSRespawn = LMS_RESPAWN_NONE then Exit;
3888 gLMSRespawn := LMS_RESPAWN_NONE;
3889 gLMSRespawnTime := 0;
3890 MessageTime := 0;
3892 if (gGameSettings.GameMode = GM_COOP) and not NoMapRestart then
3893 begin
3894 gMissionFailed := True;
3895 g_Game_RestartLevel;
3896 Exit;
3897 end;
3899 n := 0; nb := 0; nr := 0;
3900 for i := Low(gPlayers) to High(gPlayers) do
3901 if (gPlayers[i] <> nil) and
3902 ((not gPlayers[i].FSpectator) or gPlayers[i].FWantsInGame or
3903 (gPlayers[i] is TBot)) then
3904 begin
3905 Inc(n);
3906 if gPlayers[i].Team = TEAM_RED then Inc(nr)
3907 else if gPlayers[i].Team = TEAM_BLUE then Inc(nb)
3908 end;
3910 if (n < 2) or ((gGameSettings.GameMode = GM_TDM) and ((nr = 0) or (nb = 0))) then
3911 begin
3912 // wait a second until the fuckers finally decide to join
3913 gLMSRespawn := LMS_RESPAWN_WARMUP;
3914 gLMSRespawnTime := gTime + 1000;
3915 gLMSSoftSpawn := NoMapRestart;
3916 Exit;
3917 end;
3919 g_Player_RemoveAllCorpses;
3920 g_Game_Message(_lc[I_MESSAGE_LMS_START], 144);
3921 if g_Game_IsNet then
3922 MH_SEND_GameEvent(NET_EV_LMS_START);
3924 for i := Low(gPlayers) to High(gPlayers) do
3925 begin
3926 if gPlayers[i] = nil then continue;
3927 if gPlayers[i] is TBot then gPlayers[i].FWantsInGame := True;
3928 // don't touch normal spectators
3929 if gPlayers[i].FSpectator and not gPlayers[i].FWantsInGame then
3930 begin
3931 gPlayers[i].FNoRespawn := True;
3932 gPlayers[i].Lives := 0;
3933 if g_Game_IsNet then
3934 MH_SEND_PlayerStats(gPlayers[I].UID);
3935 continue;
3936 end;
3937 gPlayers[i].FNoRespawn := False;
3938 gPlayers[i].Lives := gGameSettings.MaxLives;
3939 gPlayers[i].Respawn(False, True);
3940 if gGameSettings.GameMode = GM_COOP then
3941 begin
3942 gPlayers[i].Frags := 0;
3943 gPlayers[i].RecallState;
3944 end;
3945 if (gPlayer1 = nil) and (gLMSPID1 > 0) then
3946 gPlayer1 := g_Player_Get(gLMSPID1);
3947 if (gPlayer2 = nil) and (gLMSPID2 > 0) then
3948 gPlayer2 := g_Player_Get(gLMSPID2);
3949 end;
3951 for i := Low(gItems) to High(gItems) do
3952 begin
3953 if gItems[i].Respawnable then
3954 begin
3955 gItems[i].QuietRespawn := True;
3956 gItems[i].RespawnTime := 0;
3957 end
3958 else
3959 begin
3960 g_Items_Remove(i);
3961 if g_Game_IsNet then MH_SEND_ItemDestroy(True, i);
3962 end;
3963 end;
3965 for i := Low(gMonsters) to High(gMonsters) do
3966 begin
3967 if (gMonsters[i] <> nil) and not gMonsters[i].FNoRespawn then
3968 gMonsters[i].Respawn;
3969 end;
3971 gLMSSoftSpawn := False;
3972 end;
3974 function g_Game_GetFirstMap(WAD: String): String;
3975 begin
3976 Result := '';
3978 MapList := g_Map_GetMapsList(WAD);
3979 if MapList = nil then
3980 Exit;
3982 SortSArray(MapList);
3983 Result := MapList[Low(MapList)];
3985 if not g_Map_Exist(WAD + ':\' + Result) then
3986 Result := '';
3988 MapList := nil;
3989 end;
3991 function g_Game_GetNextMap(): String;
3992 var
3993 I: Integer;
3994 Map: string;
3995 begin
3996 Result := '';
3998 MapList := g_Map_GetMapsList(MapsDir + gGameSettings.WAD);
3999 if MapList = nil then
4000 Exit;
4002 g_ProcessResourceStr(gMapInfo.Map, nil, nil, @Map);
4004 SortSArray(MapList);
4005 MapIndex := -255;
4006 for I := Low(MapList) to High(MapList) do
4007 if Map = MapList[I] then
4008 begin
4009 MapIndex := I;
4010 Break;
4011 end;
4013 if MapIndex <> -255 then
4014 begin
4015 if MapIndex = High(MapList) then
4016 Result := MapList[Low(MapList)]
4017 else
4018 Result := MapList[MapIndex + 1];
4020 if not g_Map_Exist(MapsDir + gGameSettings.WAD + ':\' + Result) then Result := Map;
4021 end;
4023 MapList := nil;
4024 end;
4026 procedure g_Game_NextLevel();
4027 begin
4028 if gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF, GM_COOP] then
4029 gExit := EXIT_ENDLEVELCUSTOM
4030 else
4031 begin
4032 gExit := EXIT_ENDLEVELSINGLE;
4033 Exit;
4034 end;
4036 if gNextMap <> '' then Exit;
4037 gNextMap := g_Game_GetNextMap();
4038 end;
4040 function g_Game_IsTestMap(): Boolean;
4041 var
4042 FName, Sect, Res: String;
4043 begin
4044 g_ProcessResourceStr(gMapInfo.Map, FName, Sect, Res);
4045 Result := UpperCase(Res) = TEST_MAP_NAME;
4046 end;
4048 procedure g_Game_DeleteTestMap();
4049 var
4050 WAD: TWADEditor_1;
4051 MapName: Char16;
4052 MapList: SArray;
4053 a, time: Integer;
4054 WadName: string;
4055 begin
4056 a := Pos('.wad:\', gMapToDelete);
4057 if a = 0 then
4058 Exit;
4060 // Âûäåëÿåì èìÿ wad-ôàéëà è èìÿ êàðòû:
4061 WadName := Copy(gMapToDelete, 1, a + 3);
4062 Delete(gMapToDelete, 1, a + 5);
4063 gMapToDelete := UpperCase(gMapToDelete);
4064 MapName := '';
4065 CopyMemory(@MapName[0], @gMapToDelete[1], Min(16, Length(gMapToDelete)));
4067 // Èìÿ êàðòû íå ñòàíäàðòíîå òåñòîâîå:
4068 if MapName <> TEST_MAP_NAME then
4069 Exit;
4071 if not gTempDelete then
4072 begin
4073 time := g_GetFileTime(WadName);
4074 WAD := TWADEditor_1.Create();
4076 // ×èòàåì Wad-ôàéë:
4077 if not WAD.ReadFile(WadName) then
4078 begin // Íåò òàêîãî WAD-ôàéëà
4079 WAD.Free();
4080 Exit;
4081 end;
4083 // Ñîñòàâëÿåì ñïèñîê êàðò è èùåì íóæíóþ:
4084 WAD.CreateImage();
4085 MapList := WAD.GetResourcesList('');
4087 if MapList <> nil then
4088 for a := 0 to High(MapList) do
4089 if MapList[a] = MapName then
4090 begin
4091 // Óäàëÿåì è ñîõðàíÿåì:
4092 WAD.RemoveResource('', MapName);
4093 WAD.SaveTo(WadName);
4094 Break;
4095 end;
4097 WAD.Free();
4098 g_SetFileTime(WadName, time);
4099 end else
4100 DeleteFile(WadName);
4101 end;
4103 procedure GameCVars(P: SArray);
4104 var
4105 a, b: Integer;
4106 stat: TPlayerStatArray;
4107 cmd, s: string;
4108 config: TConfig;
4109 begin
4110 stat := nil;
4111 cmd := LowerCase(P[0]);
4112 if cmd = 'r_showfps' then
4113 begin
4114 if (Length(P) > 1) and
4115 ((P[1] = '1') or (P[1] = '0')) then
4116 gShowFPS := (P[1][1] = '1');
4118 if gShowFPS then
4119 g_Console_Add(_lc[I_MSG_SHOW_FPS_ON])
4120 else
4121 g_Console_Add(_lc[I_MSG_SHOW_FPS_OFF]);
4122 end
4123 else if (cmd = 'g_friendlyfire') and not g_Game_IsClient then
4124 begin
4125 with gGameSettings do
4126 begin
4127 if (Length(P) > 1) and
4128 ((P[1] = '1') or (P[1] = '0')) then
4129 begin
4130 if (P[1][1] = '1') then
4131 Options := Options or GAME_OPTION_TEAMDAMAGE
4132 else
4133 Options := Options and (not GAME_OPTION_TEAMDAMAGE);
4134 end;
4136 if (LongBool(Options and GAME_OPTION_TEAMDAMAGE)) then
4137 g_Console_Add(_lc[I_MSG_FRIENDLY_FIRE_ON])
4138 else
4139 g_Console_Add(_lc[I_MSG_FRIENDLY_FIRE_OFF]);
4141 if g_Game_IsNet then MH_SEND_GameSettings;
4142 end;
4143 end
4144 else if (cmd = 'g_weaponstay') and not g_Game_IsClient then
4145 begin
4146 with gGameSettings do
4147 begin
4148 if (Length(P) > 1) and
4149 ((P[1] = '1') or (P[1] = '0')) then
4150 begin
4151 if (P[1][1] = '1') then
4152 Options := Options or GAME_OPTION_WEAPONSTAY
4153 else
4154 Options := Options and (not GAME_OPTION_WEAPONSTAY);
4155 end;
4157 if (LongBool(Options and GAME_OPTION_WEAPONSTAY)) then
4158 g_Console_Add(_lc[I_MSG_WEAPONSTAY_ON])
4159 else
4160 g_Console_Add(_lc[I_MSG_WEAPONSTAY_OFF]);
4162 if g_Game_IsNet then MH_SEND_GameSettings;
4163 end;
4164 end
4165 else if cmd = 'g_gamemode' then
4166 begin
4167 a := g_Game_TextToMode(P[1]);
4168 if a = GM_SINGLE then a := GM_COOP;
4169 if (Length(P) > 1) and (a <> GM_NONE) and (not g_Game_IsClient) then
4170 begin
4171 gSwitchGameMode := a;
4172 if (gGameOn and (gGameSettings.GameMode = GM_SINGLE)) or
4173 (gState = STATE_INTERSINGLE) then
4174 gSwitchGameMode := GM_SINGLE;
4175 if not gGameOn then
4176 gGameSettings.GameMode := gSwitchGameMode;
4177 end;
4178 if gSwitchGameMode = gGameSettings.GameMode then
4179 g_Console_Add(Format(_lc[I_MSG_GAMEMODE_CURRENT],
4180 [g_Game_ModeToText(gGameSettings.GameMode)]))
4181 else
4182 g_Console_Add(Format(_lc[I_MSG_GAMEMODE_CHANGE],
4183 [g_Game_ModeToText(gGameSettings.GameMode),
4184 g_Game_ModeToText(gSwitchGameMode)]));
4185 end
4186 else if (cmd = 'g_allow_exit') and not g_Game_IsClient then
4187 begin
4188 with gGameSettings do
4189 begin
4190 if (Length(P) > 1) and
4191 ((P[1] = '1') or (P[1] = '0')) then
4192 begin
4193 if (P[1][1] = '1') then
4194 Options := Options or GAME_OPTION_ALLOWEXIT
4195 else
4196 Options := Options and (not GAME_OPTION_ALLOWEXIT);
4197 end;
4199 if (LongBool(Options and GAME_OPTION_ALLOWEXIT)) then
4200 g_Console_Add(_lc[I_MSG_ALLOWEXIT_ON])
4201 else
4202 g_Console_Add(_lc[I_MSG_ALLOWEXIT_OFF]);
4203 g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
4205 if g_Game_IsNet then MH_SEND_GameSettings;
4206 end;
4207 end
4208 else if (cmd = 'g_allow_monsters') and not g_Game_IsClient then
4209 begin
4210 with gGameSettings do
4211 begin
4212 if (Length(P) > 1) and
4213 ((P[1] = '1') or (P[1] = '0')) then
4214 begin
4215 if (P[1][1] = '1') then
4216 Options := Options or GAME_OPTION_MONSTERS
4217 else
4218 Options := Options and (not GAME_OPTION_MONSTERS);
4219 end;
4221 if (LongBool(Options and GAME_OPTION_MONSTERS)) then
4222 g_Console_Add(_lc[I_MSG_ALLOWMON_ON])
4223 else
4224 g_Console_Add(_lc[I_MSG_ALLOWMON_OFF]);
4225 g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
4227 if g_Game_IsNet then MH_SEND_GameSettings;
4228 end;
4229 end
4230 else if (cmd = 'g_bot_vsplayers') and not g_Game_IsClient then
4231 begin
4232 with gGameSettings do
4233 begin
4234 if (Length(P) > 1) and
4235 ((P[1] = '1') or (P[1] = '0')) then
4236 begin
4237 if (P[1][1] = '1') then
4238 Options := Options or GAME_OPTION_BOTVSPLAYER
4239 else
4240 Options := Options and (not GAME_OPTION_BOTVSPLAYER);
4241 end;
4243 if (LongBool(Options and GAME_OPTION_BOTVSPLAYER)) then
4244 g_Console_Add(_lc[I_MSG_BOTSVSPLAYERS_ON])
4245 else
4246 g_Console_Add(_lc[I_MSG_BOTSVSPLAYERS_OFF]);
4248 if g_Game_IsNet then MH_SEND_GameSettings;
4249 end;
4250 end
4251 else if (cmd = 'g_bot_vsmonsters') and not g_Game_IsClient then
4252 begin
4253 with gGameSettings do
4254 begin
4255 if (Length(P) > 1) and
4256 ((P[1] = '1') or (P[1] = '0')) then
4257 begin
4258 if (P[1][1] = '1') then
4259 Options := Options or GAME_OPTION_BOTVSMONSTER
4260 else
4261 Options := Options and (not GAME_OPTION_BOTVSMONSTER);
4262 end;
4264 if (LongBool(Options and GAME_OPTION_BOTVSMONSTER)) then
4265 g_Console_Add(_lc[I_MSG_BOTSVSMONSTERS_ON])
4266 else
4267 g_Console_Add(_lc[I_MSG_BOTSVSMONSTERS_OFF]);
4269 if g_Game_IsNet then MH_SEND_GameSettings;
4270 end;
4271 end
4272 else if (cmd = 'g_warmuptime') and not g_Game_IsClient then
4273 begin
4274 if Length(P) > 1 then
4275 begin
4276 if StrToIntDef(P[1], gGameSettings.WarmupTime) = 0 then
4277 gGameSettings.WarmupTime := 30
4278 else
4279 gGameSettings.WarmupTime := StrToIntDef(P[1], gGameSettings.WarmupTime);
4280 end;
4282 g_Console_Add(Format(_lc[I_MSG_WARMUP],
4283 [gGameSettings.WarmupTime]));
4284 g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
4285 end
4286 else if cmd = 'net_interp' then
4287 begin
4288 if (Length(P) > 1) then
4289 NetInterpLevel := StrToIntDef(P[1], NetInterpLevel);
4291 g_Console_Add('net_interp = ' + IntToStr(NetInterpLevel));
4292 config := TConfig.CreateFile(GameDir+'/'+CONFIG_FILENAME);
4293 config.WriteInt('Client', 'InterpolationSteps', NetInterpLevel);
4294 config.SaveFile(GameDir+'/'+CONFIG_FILENAME);
4295 config.Free();
4296 end
4297 else if cmd = 'net_forceplayerupdate' then
4298 begin
4299 if (Length(P) > 1) and
4300 ((P[1] = '1') or (P[1] = '0')) then
4301 NetForcePlayerUpdate := (P[1][1] = '1');
4303 if NetForcePlayerUpdate then
4304 g_Console_Add('net_forceplayerupdate = 1')
4305 else
4306 g_Console_Add('net_forceplayerupdate = 0');
4307 config := TConfig.CreateFile(GameDir+'/'+CONFIG_FILENAME);
4308 config.WriteBool('Client', 'ForcePlayerUpdate', NetForcePlayerUpdate);
4309 config.SaveFile(GameDir+'/'+CONFIG_FILENAME);
4310 config.Free();
4311 end
4312 else if cmd = 'net_predictself' then
4313 begin
4314 if (Length(P) > 1) and
4315 ((P[1] = '1') or (P[1] = '0')) then
4316 NetPredictSelf := (P[1][1] = '1');
4318 if NetPredictSelf then
4319 g_Console_Add('net_predictself = 1')
4320 else
4321 g_Console_Add('net_predictself = 0');
4322 config := TConfig.CreateFile(GameDir+'/'+CONFIG_FILENAME);
4323 config.WriteBool('Client', 'PredictSelf', NetPredictSelf);
4324 config.SaveFile(GameDir+'/'+CONFIG_FILENAME);
4325 config.Free();
4326 end
4327 else if cmd = 'sv_name' then
4328 begin
4329 if (Length(P) > 1) and (Length(P[1]) > 0) then
4330 begin
4331 NetServerName := P[1];
4332 if Length(NetServerName) > 64 then
4333 SetLength(NetServerName, 64);
4334 if g_Game_IsServer and g_Game_IsNet and NetUseMaster then
4335 g_Net_Slist_Update;
4336 end;
4338 g_Console_Add(cmd + ' = "' + NetServerName + '"');
4339 end
4340 else if cmd = 'sv_passwd' then
4341 begin
4342 if (Length(P) > 1) and (Length(P[1]) > 0) then
4343 begin
4344 NetPassword := P[1];
4345 if Length(NetPassword) > 24 then
4346 SetLength(NetPassword, 24);
4347 if g_Game_IsServer and g_Game_IsNet and NetUseMaster then
4348 g_Net_Slist_Update;
4349 end;
4351 g_Console_Add(cmd + ' = "' + AnsiLowerCase(NetPassword) + '"');
4352 end
4353 else if cmd = 'sv_maxplrs' then
4354 begin
4355 if (Length(P) > 1) then
4356 begin
4357 NetMaxClients := Min(Max(StrToIntDef(P[1], NetMaxClients), 1), NET_MAXCLIENTS);
4358 if g_Game_IsServer and g_Game_IsNet then
4359 begin
4360 b := 0;
4361 for a := 0 to High(NetClients) do
4362 if NetClients[a].Used then
4363 begin
4364 Inc(b);
4365 if b > NetMaxClients then
4366 begin
4367 s := g_Player_Get(NetClients[a].Player).Name;
4368 enet_peer_disconnect(NetClients[a].Peer, NET_DISC_FULL);
4369 g_Console_Add(Format(_lc[I_PLAYER_KICK], [s]));
4370 MH_SEND_GameEvent(NET_EV_PLAYER_KICK, 0, s);
4371 end;
4372 end;
4373 if NetUseMaster then
4374 g_Net_Slist_Update;
4375 end;
4376 end;
4378 g_Console_Add(cmd + ' = ' + IntToStr(NetMaxClients));
4379 end
4380 else if cmd = 'sv_public' then
4381 begin
4382 if (Length(P) > 1) then
4383 begin
4384 NetUseMaster := StrToIntDef(P[1], Byte(NetUseMaster)) > 0;
4385 if g_Game_IsServer and g_Game_IsNet then
4386 if NetUseMaster then
4387 begin
4388 if NetMPeer = nil then
4389 if not g_Net_Slist_Connect() then
4390 g_Console_Add(_lc[I_NET_MSG_ERROR] + _lc[I_NET_SLIST_ERROR]);
4391 g_Net_Slist_Update();
4392 end
4393 else
4394 if NetMPeer <> nil then
4395 g_Net_Slist_Disconnect();
4396 end;
4398 g_Console_Add(cmd + ' = ' + IntToStr(Byte(NetUseMaster)));
4399 end
4400 else if cmd = 'sv_intertime' then
4401 begin
4402 if (Length(P) > 1) then
4403 gDefInterTime := Min(Max(StrToIntDef(P[1], gDefInterTime), -1), 120);
4405 g_Console_Add(cmd + ' = ' + IntToStr(gDefInterTime));
4406 end
4407 else if cmd = 'p1_name' then
4408 begin
4409 if (Length(P) > 1) and gGameOn then
4410 begin
4411 if g_Game_IsClient then
4412 begin
4413 gPlayer1Settings.Name := b_Text_Unformat(P[1]);
4414 MC_SEND_PlayerSettings;
4415 end
4416 else
4417 if gPlayer1 <> nil then
4418 begin
4419 gPlayer1.Name := b_Text_Unformat(P[1]);
4420 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer1.UID);
4421 end
4422 else
4423 gPlayer1Settings.Name := b_Text_Unformat(P[1]);
4424 end;
4425 end
4426 else if cmd = 'p2_name' then
4427 begin
4428 if (Length(P) > 1) and gGameOn then
4429 begin
4430 if g_Game_IsClient then
4431 begin
4432 gPlayer2Settings.Name := b_Text_Unformat(P[1]);
4433 MC_SEND_PlayerSettings;
4434 end
4435 else
4436 if gPlayer2 <> nil then
4437 begin
4438 gPlayer2.Name := b_Text_Unformat(P[1]);
4439 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer2.UID);
4440 end
4441 else
4442 gPlayer2Settings.Name := b_Text_Unformat(P[1]);
4443 end;
4444 end
4445 else if cmd = 'p1_color' then
4446 begin
4447 if Length(P) > 3 then
4448 if g_Game_IsClient then
4449 begin
4450 gPlayer1Settings.Color := _RGB(EnsureRange(StrToIntDef(P[1], 0), 0, 255),
4451 EnsureRange(StrToIntDef(P[2], 0), 0, 255),
4452 EnsureRange(StrToIntDef(P[3], 0), 0, 255));
4453 MC_SEND_PlayerSettings;
4454 end
4455 else
4456 if gPlayer1 <> nil then
4457 begin
4458 gPlayer1.Model.SetColor(EnsureRange(StrToIntDef(P[1], 0), 0, 255),
4459 EnsureRange(StrToIntDef(P[2], 0), 0, 255),
4460 EnsureRange(StrToIntDef(P[3], 0), 0, 255));
4461 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer1.UID);
4462 end
4463 else
4464 gPlayer1Settings.Color := _RGB(EnsureRange(StrToIntDef(P[1], 0), 0, 255),
4465 EnsureRange(StrToIntDef(P[2], 0), 0, 255),
4466 EnsureRange(StrToIntDef(P[3], 0), 0, 255));
4467 end
4468 else if (cmd = 'p2_color') and not g_Game_IsNet then
4469 begin
4470 if Length(P) > 3 then
4471 if g_Game_IsClient then
4472 begin
4473 gPlayer2Settings.Color := _RGB(EnsureRange(StrToIntDef(P[1], 0), 0, 255),
4474 EnsureRange(StrToIntDef(P[2], 0), 0, 255),
4475 EnsureRange(StrToIntDef(P[3], 0), 0, 255));
4476 MC_SEND_PlayerSettings;
4477 end
4478 else
4479 if gPlayer2 <> nil then
4480 begin
4481 gPlayer2.Model.SetColor(EnsureRange(StrToIntDef(P[1], 0), 0, 255),
4482 EnsureRange(StrToIntDef(P[2], 0), 0, 255),
4483 EnsureRange(StrToIntDef(P[3], 0), 0, 255));
4484 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer2.UID);
4485 end
4486 else
4487 gPlayer2Settings.Color := _RGB(EnsureRange(StrToIntDef(P[1], 0), 0, 255),
4488 EnsureRange(StrToIntDef(P[2], 0), 0, 255),
4489 EnsureRange(StrToIntDef(P[3], 0), 0, 255));
4490 end
4491 else if gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT] then
4492 begin
4493 if cmd = 'r_showtime' then
4494 begin
4495 if (Length(P) > 1) and
4496 ((P[1] = '1') or (P[1] = '0')) then
4497 gShowTime := (P[1][1] = '1');
4499 if gShowTime then
4500 g_Console_Add(_lc[I_MSG_TIME_ON])
4501 else
4502 g_Console_Add(_lc[I_MSG_TIME_OFF]);
4503 end
4504 else if cmd = 'r_showscore' then
4505 begin
4506 if (Length(P) > 1) and
4507 ((P[1] = '1') or (P[1] = '0')) then
4508 gShowGoals := (P[1][1] = '1');
4510 if gShowGoals then
4511 g_Console_Add(_lc[I_MSG_SCORE_ON])
4512 else
4513 g_Console_Add(_lc[I_MSG_SCORE_OFF]);
4514 end
4515 else if cmd = 'r_showstat' then
4516 begin
4517 if (Length(P) > 1) and
4518 ((P[1] = '1') or (P[1] = '0')) then
4519 gShowStat := (P[1][1] = '1');
4521 if gShowStat then
4522 g_Console_Add(_lc[I_MSG_STATS_ON])
4523 else
4524 g_Console_Add(_lc[I_MSG_STATS_OFF]);
4525 end
4526 else if cmd = 'r_showkillmsg' then
4527 begin
4528 if (Length(P) > 1) and
4529 ((P[1] = '1') or (P[1] = '0')) then
4530 gShowKillMsg := (P[1][1] = '1');
4532 if gShowKillMsg then
4533 g_Console_Add(_lc[I_MSG_KILL_MSGS_ON])
4534 else
4535 g_Console_Add(_lc[I_MSG_KILL_MSGS_OFF]);
4536 end
4537 else if cmd = 'r_showlives' then
4538 begin
4539 if (Length(P) > 1) and
4540 ((P[1] = '1') or (P[1] = '0')) then
4541 gShowLives := (P[1][1] = '1');
4543 if gShowLives then
4544 g_Console_Add(_lc[I_MSG_LIVES_ON])
4545 else
4546 g_Console_Add(_lc[I_MSG_LIVES_OFF]);
4547 end
4548 else if cmd = 'r_showspect' then
4549 begin
4550 if (Length(P) > 1) and
4551 ((P[1] = '1') or (P[1] = '0')) then
4552 gSpectHUD := (P[1][1] = '1');
4554 if gSpectHUD then
4555 g_Console_Add(_lc[I_MSG_SPECT_HUD_ON])
4556 else
4557 g_Console_Add(_lc[I_MSG_SPECT_HUD_OFF]);
4558 end
4559 else if cmd = 'r_showping' then
4560 begin
4561 if (Length(P) > 1) and
4562 ((P[1] = '1') or (P[1] = '0')) then
4563 gShowPing := (P[1][1] = '1');
4565 if gShowPing then
4566 g_Console_Add(_lc[I_MSG_PING_ON])
4567 else
4568 g_Console_Add(_lc[I_MSG_PING_OFF]);
4569 end
4570 else if (cmd = 'g_scorelimit') and not g_Game_IsClient then
4571 begin
4572 if Length(P) > 1 then
4573 begin
4574 if StrToIntDef(P[1], gGameSettings.GoalLimit) = 0 then
4575 gGameSettings.GoalLimit := 0
4576 else
4577 begin
4578 b := 0;
4580 if gGameSettings.GameMode = GM_DM then
4581 begin // DM
4582 stat := g_Player_GetStats();
4583 if stat <> nil then
4584 for a := 0 to High(stat) do
4585 if stat[a].Frags > b then
4586 b := stat[a].Frags;
4587 end
4588 else // TDM/CTF
4589 b := Max(gTeamStat[TEAM_RED].Goals, gTeamStat[TEAM_BLUE].Goals);
4591 gGameSettings.GoalLimit := Max(StrToIntDef(P[1], gGameSettings.GoalLimit), b);
4592 end;
4594 if g_Game_IsNet then MH_SEND_GameSettings;
4595 end;
4597 g_Console_Add(Format(_lc[I_MSG_SCORE_LIMIT], [gGameSettings.GoalLimit]));
4598 end
4599 else if (cmd = 'g_timelimit') and not g_Game_IsClient then
4600 begin
4601 if (Length(P) > 1) and (StrToIntDef(P[1], -1) >= 0) then
4602 gGameSettings.TimeLimit := StrToIntDef(P[1], -1);
4604 g_Console_Add(Format(_lc[I_MSG_TIME_LIMIT],
4605 [gGameSettings.TimeLimit div 3600,
4606 (gGameSettings.TimeLimit div 60) mod 60,
4607 gGameSettings.TimeLimit mod 60]));
4608 if g_Game_IsNet then MH_SEND_GameSettings;
4609 end
4610 else if (cmd = 'g_maxlives') and not g_Game_IsClient then
4611 begin
4612 if Length(P) > 1 then
4613 begin
4614 if StrToIntDef(P[1], gGameSettings.MaxLives) = 0 then
4615 gGameSettings.MaxLives := 0
4616 else
4617 begin
4618 b := 0;
4619 stat := g_Player_GetStats();
4620 if stat <> nil then
4621 for a := 0 to High(stat) do
4622 if stat[a].Lives > b then
4623 b := stat[a].Lives;
4624 gGameSettings.MaxLives :=
4625 Max(StrToIntDef(P[1], gGameSettings.MaxLives), b);
4626 end;
4627 end;
4629 g_Console_Add(Format(_lc[I_MSG_LIVES],
4630 [gGameSettings.MaxLives]));
4631 if g_Game_IsNet then MH_SEND_GameSettings;
4632 end;
4633 end;
4634 end;
4636 procedure DebugCommands(P: SArray);
4637 var
4638 a, b: Integer;
4639 cmd: string;
4640 //pt: TPoint;
4641 begin
4642 // Êîìàíäû îòëàäî÷íîãî ðåæèìà:
4643 if gDebugMode then
4644 begin
4645 cmd := LowerCase(P[0]);
4646 if cmd = 'd_window' then
4647 begin
4648 g_Console_Add(Format('gWinPosX = %d, gWinPosY %d', [gWinPosX, gWinPosY]));
4649 g_Console_Add(Format('gWinRealPosX = %d, gWinRealPosY %d', [gWinRealPosX, gWinRealPosY]));
4650 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth, gScreenHeight]));
4651 g_Console_Add(Format('gWinSizeX = %d, gWinSizeY = %d', [gWinSizeX, gWinSizeY]));
4652 g_Console_Add(Format('Frame X = %d, Y = %d, Caption Y = %d', [gWinFrameX, gWinFrameY, gWinCaption]));
4653 end
4654 else if cmd = 'd_sounds' then
4655 begin
4656 if (Length(P) > 1) and
4657 ((P[1] = '1') or (P[1] = '0')) then
4658 g_Debug_Sounds := (P[1][1] = '1');
4660 g_Console_Add(Format('d_sounds is %d', [Byte(g_Debug_Sounds)]));
4661 end
4662 else if cmd = 'd_frames' then
4663 begin
4664 if (Length(P) > 1) and
4665 ((P[1] = '1') or (P[1] = '0')) then
4666 g_Debug_Frames := (P[1][1] = '1');
4668 g_Console_Add(Format('d_frames is %d', [Byte(g_Debug_Frames)]));
4669 end
4670 else if cmd = 'd_winmsg' then
4671 begin
4672 if (Length(P) > 1) and
4673 ((P[1] = '1') or (P[1] = '0')) then
4674 g_Debug_WinMsgs := (P[1][1] = '1');
4676 g_Console_Add(Format('d_winmsg is %d', [Byte(g_Debug_WinMsgs)]));
4677 end
4678 else if (cmd = 'd_monoff') and not g_Game_IsNet then
4679 begin
4680 if (Length(P) > 1) and
4681 ((P[1] = '1') or (P[1] = '0')) then
4682 g_Debug_MonsterOff := (P[1][1] = '1');
4684 g_Console_Add(Format('d_monoff is %d', [Byte(g_debug_MonsterOff)]));
4685 end
4686 else if (cmd = 'd_botoff') and not g_Game_IsNet then
4687 begin
4688 if Length(P) > 1 then
4689 case P[1][1] of
4690 '0': g_debug_BotAIOff := 0;
4691 '1': g_debug_BotAIOff := 1;
4692 '2': g_debug_BotAIOff := 2;
4693 '3': g_debug_BotAIOff := 3;
4694 end;
4696 g_Console_Add(Format('d_botoff is %d', [g_debug_BotAIOff]));
4697 end
4698 else if cmd = 'd_monster' then
4699 begin
4700 if gGameOn and (gPlayer1 <> nil) and (gPlayer1.Live) and (not g_Game_IsNet) then
4701 if Length(P) < 2 then
4702 begin
4703 g_Console_Add(cmd + ' [ID | Name] [behaviour]');
4704 g_Console_Add('ID | Name');
4705 for b := MONSTER_DEMON to MONSTER_MAN do
4706 g_Console_Add(Format('%2d | %s', [b, g_Monsters_GetNameByID(b)]));
4707 end else
4708 begin
4709 a := StrToIntDef(P[1], 0);
4710 if (a < MONSTER_DEMON) or (a > MONSTER_MAN) then
4711 a := g_Monsters_GetIDByName(P[1]);
4713 if (a < MONSTER_DEMON) or (a > MONSTER_MAN) then
4714 g_Console_Add(Format(_lc[I_MSG_NO_MONSTER], [P[1]]))
4715 else
4716 begin
4717 with gPlayer1.Obj do
4718 b := g_Monsters_Create(a,
4719 X + Rect.X + (Rect.Width div 2),
4720 Y + Rect.Y + Rect.Height,
4721 gPlayer1.Direction, True);
4722 if (Length(P) > 2) and (b >= 0) then
4723 gMonsters[b].MonsterBehaviour := Min(Max(StrToIntDef(P[2], BH_NORMAL), BH_NORMAL), BH_GOOD);
4724 end;
4725 end;
4726 end
4727 else if (cmd = 'd_health') then
4728 begin
4729 if (Length(P) > 1) and
4730 ((P[1] = '1') or (P[1] = '0')) then
4731 g_debug_HealthBar := (P[1][1] = '1');
4733 g_Console_Add(Format('d_health is %d', [Byte(g_debug_HealthBar)]));
4734 end
4735 else if (cmd = 'd_player') then
4736 begin
4737 if (Length(P) > 1) and
4738 ((P[1] = '1') or (P[1] = '0')) then
4739 g_debug_Player := (P[1][1] = '1');
4741 g_Console_Add(Format(cmd + ' is %d', [Byte(g_Debug_Player)]));
4742 end
4743 else if (cmd = 'd_joy') then
4744 begin
4745 for a := 1 to 8 do
4746 g_Console_Add(e_JoystickStateToString(a));
4747 end;
4748 end
4749 else
4750 g_Console_Add(_lc[I_MSG_NOT_DEBUG]);
4751 end;
4753 procedure GameCommands(P: SArray);
4754 var
4755 a, b: Integer;
4756 s, pw: String;
4757 chstr: string;
4758 cmd: string;
4759 pl: pTNetClient = nil;
4760 plr: TPlayer;
4761 prt: Word;
4762 nm: Boolean;
4763 listen: LongWord;
4764 begin
4765 // Îáùèå êîìàíäû:
4766 cmd := LowerCase(P[0]);
4767 chstr := '';
4768 if (cmd = 'quit') or
4769 (cmd = 'exit') then
4770 begin
4771 g_Game_Free();
4772 g_Game_Quit();
4773 Exit;
4774 end
4775 else if cmd = 'pause' then
4776 begin
4777 if (g_ActiveWindow = nil) then
4778 g_Game_Pause(not gPause);
4779 end
4780 else if cmd = 'endgame' then
4781 gExit := EXIT_SIMPLE
4782 else if cmd = 'restart' then
4783 begin
4784 if gGameOn or (gState in [STATE_INTERSINGLE, STATE_INTERCUSTOM]) then
4785 begin
4786 if g_Game_IsClient then
4787 begin
4788 g_Console_Add(_lc[I_MSG_SERVERONLY]);
4789 Exit;
4790 end;
4791 g_Game_Restart();
4792 end else
4793 g_Console_Add(_lc[I_MSG_NOT_GAME]);
4794 end
4795 else if cmd = 'kick' then
4796 begin
4797 if g_Game_IsServer then
4798 begin
4799 if Length(P) < 2 then
4800 begin
4801 g_Console_Add('kick <name>');
4802 Exit;
4803 end;
4804 if P[1] = '' then
4805 begin
4806 g_Console_Add('kick <name>');
4807 Exit;
4808 end;
4810 if g_Game_IsNet then
4811 pl := g_Net_Client_ByName(P[1]);
4812 if (pl <> nil) then
4813 begin
4814 s := g_Net_ClientName_ByID(pl^.ID);
4815 enet_peer_disconnect(pl^.Peer, NET_DISC_KICK);
4816 g_Console_Add(Format(_lc[I_PLAYER_KICK], [s]));
4817 MH_SEND_GameEvent(NET_EV_PLAYER_KICK, 0, s);
4818 if NetUseMaster then
4819 g_Net_Slist_Update;
4820 end else if gPlayers <> nil then
4821 for a := Low(gPlayers) to High(gPlayers) do
4822 if gPlayers[a] <> nil then
4823 if Copy(LowerCase(gPlayers[a].Name), 1, Length(P[1])) = LowerCase(P[1]) then
4824 begin
4825 // Íå îòêëþ÷àòü îñíîâíûõ èãðîêîâ â ñèíãëå
4826 if not(gPlayers[a] is TBot) and (gGameSettings.GameType = GT_SINGLE) then
4827 continue;
4828 gPlayers[a].Lives := 0;
4829 gPlayers[a].Kill(K_SIMPLEKILL, 0, HIT_DISCON);
4830 g_Console_Add(Format(_lc[I_PLAYER_LEAVE], [gPlayers[a].Name]), True);
4831 g_Player_Remove(gPlayers[a].UID);
4832 if NetUseMaster then
4833 g_Net_Slist_Update;
4834 // Åñëè íå ïåðåìåøàòü, ïðè äîáàâëåíèè íîâûõ áîòîâ ïîÿâÿòñÿ ñòàðûå
4835 g_Bot_MixNames();
4836 end;
4837 end else
4838 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
4839 end
4840 else if cmd = 'kick_id' then
4841 begin
4842 if g_Game_IsServer and g_Game_IsNet then
4843 begin
4844 if Length(P) < 2 then
4845 begin
4846 g_Console_Add('kick_id <client ID>');
4847 Exit;
4848 end;
4849 if P[1] = '' then
4850 begin
4851 g_Console_Add('kick_id <client ID>');
4852 Exit;
4853 end;
4855 a := StrToIntDef(P[1], 0);
4856 if (NetClients <> nil) and (a <= High(NetClients)) then
4857 begin
4858 if NetClients[a].Used and (NetClients[a].Peer <> nil) then
4859 begin
4860 s := g_Net_ClientName_ByID(NetClients[a].ID);
4861 enet_peer_disconnect(NetClients[a].Peer, NET_DISC_KICK);
4862 g_Console_Add(Format(_lc[I_PLAYER_KICK], [s]));
4863 MH_SEND_GameEvent(NET_EV_PLAYER_KICK, 0, s);
4864 if NetUseMaster then
4865 g_Net_Slist_Update;
4866 end;
4867 end;
4868 end else
4869 g_Console_Add(_lc[I_MSG_SERVERONLY]);
4870 end
4871 else if cmd = 'ban' then
4872 begin
4873 if g_Game_IsServer and g_Game_IsNet then
4874 begin
4875 if Length(P) < 2 then
4876 begin
4877 g_Console_Add('ban <name>');
4878 Exit;
4879 end;
4880 if P[1] = '' then
4881 begin
4882 g_Console_Add('ban <name>');
4883 Exit;
4884 end;
4886 pl := g_Net_Client_ByName(P[1]);
4887 if (pl <> nil) then
4888 begin
4889 s := g_Net_ClientName_ByID(pl^.ID);
4890 g_Net_BanHost(pl^.Peer^.address.host, False);
4891 enet_peer_disconnect(pl^.Peer, NET_DISC_TEMPBAN);
4892 g_Console_Add(Format(_lc[I_PLAYER_BAN], [s]));
4893 MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s);
4894 if NetUseMaster then
4895 g_Net_Slist_Update;
4896 end else
4897 g_Console_Add(Format(_lc[I_NET_ERR_NAME404], [P[1]]));
4898 end else
4899 g_Console_Add(_lc[I_MSG_SERVERONLY]);
4900 end
4901 else if cmd = 'ban_id' then
4902 begin
4903 if g_Game_IsServer and g_Game_IsNet then
4904 begin
4905 if Length(P) < 2 then
4906 begin
4907 g_Console_Add('ban_id <client ID>');
4908 Exit;
4909 end;
4910 if P[1] = '' then
4911 begin
4912 g_Console_Add('ban_id <client ID>');
4913 Exit;
4914 end;
4916 a := StrToIntDef(P[1], 0);
4917 if (NetClients <> nil) and (a <= High(NetClients)) then
4918 if NetClients[a].Used and (NetClients[a].Peer <> nil) then
4919 begin
4920 s := g_Net_ClientName_ByID(NetClients[a].ID);
4921 g_Net_BanHost(NetClients[a].Peer^.address.host, False);
4922 enet_peer_disconnect(NetClients[a].Peer, NET_DISC_TEMPBAN);
4923 g_Console_Add(Format(_lc[I_PLAYER_BAN], [s]));
4924 MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s);
4925 if NetUseMaster then
4926 g_Net_Slist_Update;
4927 end;
4928 end else
4929 g_Console_Add(_lc[I_MSG_SERVERONLY]);
4930 end
4931 else if cmd = 'permban' then
4932 begin
4933 if g_Game_IsServer and g_Game_IsNet then
4934 begin
4935 if Length(P) < 2 then
4936 begin
4937 g_Console_Add('permban <name>');
4938 Exit;
4939 end;
4940 if P[1] = '' then
4941 begin
4942 g_Console_Add('permban <name>');
4943 Exit;
4944 end;
4946 pl := g_Net_Client_ByName(P[1]);
4947 if (pl <> nil) then
4948 begin
4949 s := g_Net_ClientName_ByID(pl^.ID);
4950 g_Net_BanHost(pl^.Peer^.address.host);
4951 enet_peer_disconnect(pl^.Peer, NET_DISC_BAN);
4952 g_Net_SaveBanList();
4953 g_Console_Add(Format(_lc[I_PLAYER_BAN], [s]));
4954 MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s);
4955 if NetUseMaster then
4956 g_Net_Slist_Update;
4957 end else
4958 g_Console_Add(Format(_lc[I_NET_ERR_NAME404], [P[1]]));
4959 end else
4960 g_Console_Add(_lc[I_MSG_SERVERONLY]);
4961 end
4962 else if cmd = 'permban_id' then
4963 begin
4964 if g_Game_IsServer and g_Game_IsNet then
4965 begin
4966 if Length(P) < 2 then
4967 begin
4968 g_Console_Add('permban_id <client ID>');
4969 Exit;
4970 end;
4971 if P[1] = '' then
4972 begin
4973 g_Console_Add('permban_id <client ID>');
4974 Exit;
4975 end;
4977 a := StrToIntDef(P[1], 0);
4978 if (NetClients <> nil) and (a <= High(NetClients)) then
4979 if NetClients[a].Used and (NetClients[a].Peer <> nil) then
4980 begin
4981 s := g_Net_ClientName_ByID(NetClients[a].ID);
4982 g_Net_BanHost(NetClients[a].Peer^.address.host);
4983 enet_peer_disconnect(NetClients[a].Peer, NET_DISC_BAN);
4984 g_Net_SaveBanList();
4985 g_Console_Add(Format(_lc[I_PLAYER_BAN], [s]));
4986 MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s);
4987 if NetUseMaster then
4988 g_Net_Slist_Update;
4989 end;
4990 end else
4991 g_Console_Add(_lc[I_MSG_SERVERONLY]);
4992 end
4993 else if cmd = 'unban' then
4994 begin
4995 if g_Game_IsServer and g_Game_IsNet then
4996 begin
4997 if Length(P) < 2 then
4998 begin
4999 g_Console_Add('unban <IP Address>');
5000 Exit;
5001 end;
5002 if P[1] = '' then
5003 begin
5004 g_Console_Add('unban <IP Address>');
5005 Exit;
5006 end;
5008 if g_Net_UnbanHost(P[1]) then
5009 begin
5010 g_Console_Add(Format(_lc[I_MSG_UNBAN_OK], [P[1]]));
5011 g_Net_SaveBanList();
5012 end else
5013 g_Console_Add(Format(_lc[I_MSG_UNBAN_FAIL], [P[1]]));
5014 end else
5015 g_Console_Add(_lc[I_MSG_SERVERONLY]);
5016 end
5017 else if cmd = 'clientlist' then
5018 begin
5019 if g_Game_IsServer and g_Game_IsNet then
5020 begin
5021 b := 0;
5022 if NetClients <> nil then
5023 for a := Low(NetClients) to High(NetClients) do
5024 if NetClients[a].Used and (NetClients[a].Peer <> nil) then
5025 begin
5026 plr := g_Player_Get(NetClients[a].Player);
5027 if plr = nil then continue;
5028 Inc(b);
5029 g_Console_Add(Format('#%2d: %-15s | %s', [a,
5030 IpToStr(NetClients[a].Peer^.address.host), plr.Name]));
5031 end;
5032 if b = 0 then
5033 g_Console_Add(_lc[I_MSG_NOCLIENTS]);
5034 end else
5035 g_Console_Add(_lc[I_MSG_SERVERONLY]);
5036 end
5037 else if cmd = 'connect' then
5038 begin
5039 if (NetMode = NET_NONE) then
5040 begin
5041 if Length(P) < 2 then
5042 begin
5043 g_Console_Add('connect <IP> [port] [password]');
5044 Exit;
5045 end;
5046 if P[1] = '' then
5047 begin
5048 g_Console_Add('connect <IP> [port] [password]');
5049 Exit;
5050 end;
5052 if Length(P) > 2 then
5053 prt := StrToIntDef(P[2], 25666)
5054 else
5055 prt := 25666;
5057 if Length(P) > 3 then
5058 pw := P[3]
5059 else
5060 pw := '';
5062 g_Game_StartClient(P[1], prt, pw);
5063 end;
5064 end
5065 else if cmd = 'disconnect' then
5066 begin
5067 if (NetMode = NET_CLIENT) then
5068 g_Net_Disconnect();
5069 end
5070 else if cmd = 'reconnect' then
5071 begin
5072 if (NetMode = NET_SERVER) then
5073 Exit;
5075 if (NetMode = NET_CLIENT) then
5076 begin
5077 g_Net_Disconnect();
5078 gExit := EXIT_SIMPLE;
5079 EndGame;
5080 end;
5082 //TODO: Use last successful password to reconnect, instead of ''
5083 g_Game_StartClient(NetClientIP, NetClientPort, '');
5084 end
5085 else if (cmd = 'addbot') or
5086 (cmd = 'bot_add') then
5087 begin
5088 if Length(P) > 1 then
5089 g_Bot_Add(TEAM_NONE, StrToIntDef(P[1], 2))
5090 else
5091 g_Bot_Add(TEAM_NONE, 2);
5092 end
5093 else if cmd = 'bot_addlist' then
5094 begin
5095 if Length(P) > 1 then
5096 if Length(P) = 2 then
5097 g_Bot_AddList(TEAM_NONE, P[1], StrToIntDef(P[1], -1))
5098 else
5099 g_Bot_AddList(IfThen(P[2] = 'red', TEAM_RED, TEAM_BLUE), P[1], StrToIntDef(P[1], -1));
5100 end
5101 else if cmd = 'bot_removeall' then
5102 g_Bot_RemoveAll()
5103 else if cmd = 'chat' then
5104 begin
5105 if g_Game_IsNet then
5106 begin
5107 if Length(P) > 1 then
5108 begin
5109 for a := 1 to High(P) do
5110 chstr := chstr + P[a] + ' ';
5112 if Length(chstr) > 200 then SetLength(chstr, 200);
5114 if Length(chstr) < 1 then
5115 begin
5116 g_Console_Add('chat <text>');
5117 Exit;
5118 end;
5120 chstr := b_Text_Format(chstr);
5121 if g_Game_IsClient then
5122 MC_SEND_Chat(chstr, NET_CHAT_PLAYER)
5123 else
5124 MH_SEND_Chat(gPlayer1Settings.Name + ': ' + chstr, NET_CHAT_PLAYER);
5125 end
5126 else
5127 g_Console_Add('chat <text>');
5128 end else
5129 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
5130 end
5131 else if cmd = 'teamchat' then
5132 begin
5133 if g_Game_IsNet and (gGameSettings.GameMode in [GM_TDM, GM_CTF]) then
5134 begin
5135 if Length(P) > 1 then
5136 begin
5137 for a := 1 to High(P) do
5138 chstr := chstr + P[a] + ' ';
5140 if Length(chstr) > 200 then SetLength(chstr, 200);
5142 if Length(chstr) < 1 then
5143 begin
5144 g_Console_Add('teamchat <text>');
5145 Exit;
5146 end;
5148 chstr := b_Text_Format(chstr);
5149 if g_Game_IsClient then
5150 MC_SEND_Chat(chstr, NET_CHAT_TEAM)
5151 else
5152 MH_SEND_Chat(gPlayer1Settings.Name + ': ' + chstr, NET_CHAT_TEAM,
5153 gPlayer1Settings.Team);
5154 end
5155 else
5156 g_Console_Add('teamchat <text>');
5157 end else
5158 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
5159 end
5160 else if cmd = 'game' then
5161 begin
5162 if gGameSettings.GameType <> GT_NONE then
5163 begin
5164 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
5165 Exit;
5166 end;
5167 if Length(P) = 1 then
5168 begin
5169 g_Console_Add(cmd + ' <WAD> [MAP] [# players]');
5170 Exit;
5171 end;
5172 // Èãðà åù¸ íå çàïóùåíà, ñíà÷àëà íàì íàäî çàãðóçèòü êàêîé-òî WAD
5173 if Pos('.wad', LowerCase(P[1])) = 0 then
5174 P[1] := P[1] + '.wad';
5176 if FileExists(MapsDir + P[1]) then
5177 begin
5178 // Åñëè êàðòà íå óêàçàíà, áåð¸ì ïåðâóþ êàðòó â ôàéëå
5179 if Length(P) < 3 then
5180 begin
5181 SetLength(P, 3);
5182 P[2] := g_Game_GetFirstMap(MapsDir + P[1]);
5183 end;
5185 s := P[1] + ':\' + UpperCase(P[2]);
5187 if g_Map_Exist(MapsDir + s) then
5188 begin
5189 // Çàïóñêàåì ñâîþ èãðó
5190 g_Game_Free();
5191 with gGameSettings do
5192 begin
5193 GameMode := g_Game_TextToMode(gcGameMode);
5194 if gSwitchGameMode <> GM_NONE then
5195 GameMode := gSwitchGameMode;
5196 if GameMode = GM_NONE then GameMode := GM_DM;
5197 if GameMode = GM_SINGLE then GameMode := GM_COOP;
5198 b := 1;
5199 if Length(P) >= 4 then
5200 b := StrToIntDef(P[3], 1);
5201 g_Game_StartCustom(s, GameMode, TimeLimit,
5202 GoalLimit, MaxLives, Options, b);
5203 end;
5204 end
5205 else
5206 if P[2] = '' then
5207 g_Console_Add(Format(_lc[I_MSG_NO_MAPS], [P[1]]))
5208 else
5209 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [UpperCase(P[2])]));
5210 end else
5211 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]));
5212 end
5213 else if cmd = 'host' then
5214 begin
5215 if gGameSettings.GameType <> GT_NONE then
5216 begin
5217 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
5218 Exit;
5219 end;
5220 if Length(P) < 4 then
5221 begin
5222 g_Console_Add(cmd + ' <listen IP> <port> <WAD> [MAP] [# players]');
5223 Exit;
5224 end;
5225 if not StrToIp(P[1], listen) then
5226 Exit;
5227 prt := StrToIntDef(P[2], 25666);
5229 if Pos('.wad', LowerCase(P[3])) = 0 then
5230 P[3] := P[3] + '.wad';
5232 if FileExists(MapsDir + P[3]) then
5233 begin
5234 // Åñëè êàðòà íå óêàçàíà, áåð¸ì ïåðâóþ êàðòó â ôàéëå
5235 if Length(P) < 5 then
5236 begin
5237 SetLength(P, 5);
5238 P[4] := g_Game_GetFirstMap(MapsDir + P[1]);
5239 end;
5241 s := P[3] + ':\' + UpperCase(P[4]);
5243 if g_Map_Exist(MapsDir + s) then
5244 begin
5245 // Çàïóñêàåì ñâîþ èãðó
5246 g_Game_Free();
5247 with gGameSettings do
5248 begin
5249 GameMode := g_Game_TextToMode(gcGameMode);
5250 if gSwitchGameMode <> GM_NONE then
5251 GameMode := gSwitchGameMode;
5252 if GameMode = GM_NONE then GameMode := GM_DM;
5253 if GameMode = GM_SINGLE then GameMode := GM_COOP;
5254 b := 0;
5255 if Length(P) >= 6 then
5256 b := StrToIntDef(P[5], 0);
5257 g_Game_StartServer(s, GameMode, TimeLimit,
5258 GoalLimit, MaxLives, Options, b, listen, prt);
5259 end;
5260 end
5261 else
5262 if P[4] = '' then
5263 g_Console_Add(Format(_lc[I_MSG_NO_MAPS], [P[3]]))
5264 else
5265 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [UpperCase(P[4])]));
5266 end else
5267 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[3]]));
5268 end
5269 else if cmd = 'map' then
5270 begin
5271 if Length(P) = 1 then
5272 begin
5273 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
5274 begin
5275 g_Console_Add(cmd + ' <MAP>');
5276 g_Console_Add(cmd + ' <WAD> [MAP]');
5277 end else
5278 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
5279 end else
5280 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
5281 begin
5282 // Èä¸ò ñâîÿ èãðà èëè ñåðâåð
5283 if Length(P) < 3 then
5284 begin
5285 // Ïåðâûé ïàðàìåòð - ëèáî êàðòà, ëèáî èìÿ WAD ôàéëà
5286 s := UpperCase(P[1]);
5287 if g_Map_Exist(MapsDir + gGameSettings.WAD + ':\' + s) then
5288 begin // Êàðòà íàøëàñü
5289 gExitByTrigger := False;
5290 if gGameOn then
5291 begin // Èä¸ò èãðà - çàâåðøàåì óðîâåíü
5292 gNextMap := s;
5293 gExit := EXIT_ENDLEVELCUSTOM;
5294 end
5295 else // Èíòåðìèññèÿ - ñðàçó çàãðóæàåì êàðòó
5296 g_Game_ChangeMap(s);
5297 end else
5298 begin
5299 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [s]));
5300 // Òàêîé êàðòû íåò, èùåì WAD ôàéë
5301 if Pos('.wad', LowerCase(P[1])) = 0 then
5302 P[1] := P[1] + '.wad';
5304 if FileExists(MapsDir + P[1]) then
5305 begin
5306 // Ïàðàìåòðà êàðòû íåò, ïîýòîìó ñòàâèì ïåðâóþ èç ôàéëà
5307 SetLength(P, 3);
5308 P[2] := g_Game_GetFirstMap(MapsDir + P[1]);
5310 s := P[1] + ':\' + P[2];
5312 if g_Map_Exist(MapsDir + s) then
5313 begin
5314 gExitByTrigger := False;
5315 if gGameOn then
5316 begin // Èä¸ò èãðà - çàâåðøàåì óðîâåíü
5317 gNextMap := s;
5318 gExit := EXIT_ENDLEVELCUSTOM;
5319 end
5320 else // Èíòåðìèññèÿ - ñðàçó çàãðóæàåì êàðòó
5321 g_Game_ChangeMap(s);
5322 end else
5323 if P[2] = '' then
5324 g_Console_Add(Format(_lc[I_MSG_NO_MAPS], [P[1]]))
5325 else
5326 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [P[2]]));
5327 end else
5328 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]));
5329 end;
5330 end else
5331 begin
5332 // Óêàçàíî äâà ïàðàìåòðà, çíà÷èò ïåðâûé - WAD ôàéë, à âòîðîé - êàðòà
5333 if Pos('.wad', LowerCase(P[1])) = 0 then
5334 P[1] := P[1] + '.wad';
5336 if FileExists(MapsDir + P[1]) then
5337 begin
5338 // Íàøëè WAD ôàéë
5339 P[2] := UpperCase(P[2]);
5340 s := P[1] + ':\' + P[2];
5342 if g_Map_Exist(MapsDir + s) then
5343 begin // Íàøëè êàðòó
5344 gExitByTrigger := False;
5345 if gGameOn then
5346 begin // Èä¸ò èãðà - çàâåðøàåì óðîâåíü
5347 gNextMap := s;
5348 gExit := EXIT_ENDLEVELCUSTOM;
5349 end
5350 else // Èíòåðìèññèÿ - ñðàçó çàãðóæàåì êàðòó
5351 g_Game_ChangeMap(s);
5352 end else
5353 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [P[2]]));
5354 end else
5355 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]));
5356 end;
5357 end else
5358 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
5359 end
5360 else if cmd = 'nextmap' then
5361 begin
5362 if not(gGameOn or (gState = STATE_INTERCUSTOM)) then
5363 g_Console_Add(_lc[I_MSG_NOT_GAME])
5364 else begin
5365 nm := True;
5366 if Length(P) = 1 then
5367 begin
5368 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
5369 begin
5370 g_Console_Add(cmd + ' <MAP>');
5371 g_Console_Add(cmd + ' <WAD> [MAP]');
5372 end else begin
5373 nm := False;
5374 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
5375 end;
5376 end else
5377 begin
5378 nm := False;
5379 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
5380 begin
5381 if Length(P) < 3 then
5382 begin
5383 // Ïåðâûé ïàðàìåòð - ëèáî êàðòà, ëèáî èìÿ WAD ôàéëà
5384 s := UpperCase(P[1]);
5385 if g_Map_Exist(MapsDir + gGameSettings.WAD + ':\' + s) then
5386 begin // Êàðòà íàøëàñü
5387 gExitByTrigger := False;
5388 gNextMap := s;
5389 nm := True;
5390 end else
5391 begin
5392 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [s]));
5393 // Òàêîé êàðòû íåò, èùåì WAD ôàéë
5394 if Pos('.wad', LowerCase(P[1])) = 0 then
5395 P[1] := P[1] + '.wad';
5397 if FileExists(MapsDir + P[1]) then
5398 begin
5399 // Ïàðàìåòðà êàðòû íåò, ïîýòîìó ñòàâèì ïåðâóþ èç ôàéëà
5400 SetLength(P, 3);
5401 P[2] := g_Game_GetFirstMap(MapsDir + P[1]);
5403 s := P[1] + ':\' + P[2];
5405 if g_Map_Exist(MapsDir + s) then
5406 begin // Óñòàíàâëèâàåì êàðòó
5407 gExitByTrigger := False;
5408 gNextMap := s;
5409 nm := True;
5410 end else
5411 if P[2] = '' then
5412 g_Console_Add(Format(_lc[I_MSG_NO_MAPS], [P[1]]))
5413 else
5414 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [P[2]]));
5415 end else
5416 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]));
5417 end;
5418 end else
5419 begin
5420 // Óêàçàíî äâà ïàðàìåòðà, çíà÷èò ïåðâûé - WAD ôàéë, à âòîðîé - êàðòà
5421 if Pos('.wad', LowerCase(P[1])) = 0 then
5422 P[1] := P[1] + '.wad';
5424 if FileExists(MapsDir + P[1]) then
5425 begin
5426 // Íàøëè WAD ôàéë
5427 P[2] := UpperCase(P[2]);
5428 s := P[1] + ':\' + P[2];
5430 if g_Map_Exist(MapsDir + s) then
5431 begin // Íàøëè êàðòó
5432 gExitByTrigger := False;
5433 gNextMap := s;
5434 nm := True;
5435 end else
5436 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [P[2]]));
5437 end else
5438 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]));
5439 end;
5440 end else
5441 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
5442 end;
5443 if nm then
5444 if gNextMap = '' then
5445 g_Console_Add(_lc[I_MSG_NEXTMAP_UNSET])
5446 else
5447 g_Console_Add(Format(_lc[I_MSG_NEXTMAP_SET], [gNextMap]));
5448 end;
5449 end
5450 else if (cmd = 'endmap') or (cmd = 'goodbye') then
5451 begin
5452 if not gGameOn then
5453 g_Console_Add(_lc[I_MSG_NOT_GAME])
5454 else
5455 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
5456 begin
5457 gExitByTrigger := False;
5458 // Ñëåäóþùàÿ êàðòà íå çàäàíà, ïðîáóåì íàéòè òðèããåð Âûõîä
5459 if (gNextMap = '') and (gTriggers <> nil) then
5460 for a := 0 to High(gTriggers) do
5461 if gTriggers[a].TriggerType = TRIGGER_EXIT then
5462 begin
5463 gExitByTrigger := True;
5464 gNextMap := gTriggers[a].Data.MapName;
5465 Break;
5466 end;
5467 // Èùåì ñëåäóþùóþ êàðòó â WAD ôàéëå
5468 if gNextMap = '' then
5469 gNextMap := g_Game_GetNextMap();
5470 // Ïðîâåðÿåì, íå çàäàí ëè WAD ôàéë ðåñóðñíîé ñòðîêîé
5471 if Pos(':\', gNextMap) = 0 then
5472 s := gGameSettings.WAD + ':\' + gNextMap
5473 else
5474 s := gNextMap;
5475 // Åñëè êàðòà íàéäåíà, âûõîäèì ñ óðîâíÿ
5476 if g_Map_Exist(MapsDir + s) then
5477 gExit := EXIT_ENDLEVELCUSTOM
5478 else
5479 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [gNextMap]));
5480 end else
5481 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
5482 end
5483 else if (cmd = 'event') then
5484 begin
5485 if (Length(P) <= 1) then
5486 begin
5487 for a := 0 to High(gEvents) do
5488 if gEvents[a].Command = '' then
5489 g_Console_Add(gEvents[a].Name + ' <none>')
5490 else
5491 g_Console_Add(gEvents[a].Name + ' "' + gEvents[a].Command + '"');
5492 Exit;
5493 end;
5494 if (Length(P) = 2) then
5495 begin
5496 for a := 0 to High(gEvents) do
5497 if gEvents[a].Name = P[1] then
5498 if gEvents[a].Command = '' then
5499 g_Console_Add(gEvents[a].Name + ' <none>')
5500 else
5501 g_Console_Add(gEvents[a].Name + ' "' + gEvents[a].Command + '"');
5502 Exit;
5503 end;
5504 for a := 0 to High(gEvents) do
5505 if gEvents[a].Name = P[1] then
5506 begin
5507 gEvents[a].Command := '';
5508 for b := 2 to High(P) do
5509 if Pos(' ', P[b]) = 0 then
5510 gEvents[a].Command := gEvents[a].Command + ' ' + P[b]
5511 else
5512 gEvents[a].Command := gEvents[a].Command + ' "' + P[b] + '"';
5513 gEvents[a].Command := Trim(gEvents[a].Command);
5514 Exit;
5515 end;
5516 end
5517 // Êîìàíäû Ñâîåé èãðû:
5518 else if gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT] then
5519 begin
5520 if cmd = 'bot_addred' then
5521 begin
5522 if Length(P) > 1 then
5523 g_Bot_Add(TEAM_RED, StrToIntDef(P[1], 2))
5524 else
5525 g_Bot_Add(TEAM_RED, 2);
5526 end
5527 else if cmd = 'bot_addblue' then
5528 begin
5529 if Length(P) > 1 then
5530 g_Bot_Add(TEAM_BLUE, StrToIntDef(P[1], 2))
5531 else
5532 g_Bot_Add(TEAM_BLUE, 2);
5533 end
5534 else if cmd = 'suicide' then
5535 begin
5536 if gGameOn then
5537 begin
5538 if g_Game_IsClient then
5539 MC_SEND_CheatRequest(NET_CHEAT_SUICIDE)
5540 else
5541 begin
5542 if gPlayer1 <> nil then
5543 gPlayer1.Damage(SUICIDE_DAMAGE, gPlayer1.UID, 0, 0, HIT_SELF);
5544 if gPlayer2 <> nil then
5545 gPlayer2.Damage(SUICIDE_DAMAGE, gPlayer2.UID, 0, 0, HIT_SELF);
5546 end;
5547 end;
5548 end
5549 else if cmd = 'spectate' then
5550 begin
5551 if not gGameOn then
5552 Exit;
5553 g_Game_Spectate();
5554 end
5555 else if cmd = 'say' then
5556 begin
5557 if g_Game_IsServer and g_Game_IsNet then
5558 begin
5559 if Length(P) > 1 then
5560 begin
5561 chstr := '';
5562 for a := 1 to High(P) do
5563 chstr := chstr + P[a] + ' ';
5565 if Length(chstr) > 200 then SetLength(chstr, 200);
5567 if Length(chstr) < 1 then
5568 begin
5569 g_Console_Add('say <text>');
5570 Exit;
5571 end;
5573 chstr := b_Text_Format(chstr);
5574 MH_SEND_Chat(chstr, NET_CHAT_PLAYER);
5575 end
5576 else g_Console_Add('say <text>');
5577 end else
5578 g_Console_Add(_lc[I_MSG_SERVERONLY]);
5579 end
5580 else if cmd = 'tell' then
5581 begin
5582 if g_Game_IsServer and g_Game_IsNet then
5583 begin
5584 if (Length(P) > 2) and (P[1] <> '') then
5585 begin
5586 chstr := '';
5587 for a := 2 to High(P) do
5588 chstr := chstr + P[a] + ' ';
5590 if Length(chstr) > 200 then SetLength(chstr, 200);
5592 if Length(chstr) < 1 then
5593 begin
5594 g_Console_Add('tell <playername> <text>');
5595 Exit;
5596 end;
5598 pl := g_Net_Client_ByName(P[1]);
5599 if pl <> nil then
5600 MH_SEND_Chat(b_Text_Format(chstr), NET_CHAT_PLAYER, pl^.ID)
5601 else
5602 g_Console_Add(Format(_lc[I_NET_ERR_NAME404], [P[1]]));
5603 end
5604 else g_Console_Add('tell <playername> <text>');
5605 end else
5606 g_Console_Add(_lc[I_MSG_SERVERONLY]);
5607 end
5608 else if (cmd = 'overtime') and not g_Game_IsClient then
5609 begin
5610 if (Length(P) = 1) or (StrToIntDef(P[1], -1) <= 0) then
5611 Exit;
5612 // Äîïîëíèòåëüíîå âðåìÿ:
5613 gGameSettings.TimeLimit := (gTime - gGameStartTime) div 1000 + Word(StrToIntDef(P[1], 0));
5615 g_Console_Add(Format(_lc[I_MSG_TIME_LIMIT],
5616 [gGameSettings.TimeLimit div 3600,
5617 (gGameSettings.TimeLimit div 60) mod 60,
5618 gGameSettings.TimeLimit mod 60]));
5619 if g_Game_IsNet then MH_SEND_GameSettings;
5620 end
5621 else if (cmd = 'rcon_password') and g_Game_IsClient then
5622 begin
5623 if (Length(P) <= 1) then
5624 g_Console_Add('rcon_password <password>')
5625 else
5626 MC_SEND_RCONPassword(P[1]);
5627 end
5628 else if cmd = 'rcon' then
5629 begin
5630 if g_Game_IsClient then
5631 begin
5632 if Length(P) > 1 then
5633 begin
5634 chstr := '';
5635 for a := 1 to High(P) do
5636 chstr := chstr + P[a] + ' ';
5638 if Length(chstr) > 200 then SetLength(chstr, 200);
5640 if Length(chstr) < 1 then
5641 begin
5642 g_Console_Add('rcon <command>');
5643 Exit;
5644 end;
5646 MC_SEND_RCONCommand(chstr);
5647 end
5648 else g_Console_Add('rcon <command>');
5649 end;
5650 end
5651 else if cmd = 'ready' then
5652 begin
5653 if g_Game_IsServer and (gLMSRespawn = LMS_RESPAWN_WARMUP) then
5654 gLMSRespawnTime := gTime + 100;
5655 end
5656 else if (cmd = 'callvote') and g_Game_IsNet then
5657 begin
5658 if Length(P) > 1 then
5659 begin
5660 chstr := '';
5661 for a := 1 to High(P) do begin
5662 if a > 1 then chstr := chstr + ' ';
5663 chstr := chstr + P[a];
5664 end;
5666 if Length(chstr) > 200 then SetLength(chstr, 200);
5668 if Length(chstr) < 1 then
5669 begin
5670 g_Console_Add('callvote <command>');
5671 Exit;
5672 end;
5674 if g_Game_IsClient then
5675 MC_SEND_Vote(True, chstr)
5676 else
5677 g_Game_StartVote(chstr, gPlayer1Settings.Name);
5678 g_Console_Process('vote', True);
5679 end
5680 else
5681 g_Console_Add('callvote <command>');
5682 end
5683 else if (cmd = 'vote') and g_Game_IsNet then
5684 begin
5685 if g_Game_IsClient then
5686 MC_SEND_Vote(False)
5687 else if gVoteInProgress then
5688 begin
5689 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
5690 a := Floor((NetClientCount+1)/2.0) + 1
5691 else
5692 a := Floor(NetClientCount/2.0) + 1;
5693 if gVoted then
5694 begin
5695 Dec(gVoteCount);
5696 gVoted := False;
5697 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_REVOKED], [gPlayer1Settings.Name, gVoteCount, a]), True);
5698 MH_SEND_VoteEvent(NET_VE_REVOKE, gPlayer1Settings.Name, 'a', gVoteCount, a);
5699 end
5700 else
5701 begin
5702 Inc(gVoteCount);
5703 gVoted := True;
5704 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_VOTE], [gPlayer1Settings.Name, gVoteCount, a]), True);
5705 MH_SEND_VoteEvent(NET_VE_VOTE, gPlayer1Settings.Name, 'a', gVoteCount, a);
5706 g_Game_CheckVote;
5707 end;
5708 end;
5709 end
5710 end;
5711 end;
5713 procedure g_TakeScreenShot();
5714 var
5715 a: Word;
5716 FileName: String;
5717 begin
5718 for a := 1 to High(Word) do
5719 begin
5720 FileName := Format(GameDir+'/Screenshots/Screenshot%.3d.bmp', [a]);
5721 if not FileExists(FileName) then
5722 begin
5723 e_MakeScreenshot(FileName, gScreenWidth, gScreenHeight);
5724 g_Console_Add(Format(_lc[I_CONSOLE_SCREENSHOT], [ExtractFileName(FileName)]));
5725 Break;
5726 end;
5727 end;
5728 end;
5730 procedure g_Game_InGameMenu(Show: Boolean);
5731 begin
5732 if (g_ActiveWindow = nil) and Show then
5733 begin
5734 if gGameSettings.GameType = GT_SINGLE then
5735 g_GUI_ShowWindow('GameSingleMenu')
5736 else
5737 begin
5738 if g_Game_IsClient then
5739 g_GUI_ShowWindow('GameClientMenu')
5740 else
5741 if g_Game_IsNet then
5742 g_GUI_ShowWindow('GameServerMenu')
5743 else
5744 g_GUI_ShowWindow('GameCustomMenu');
5745 end;
5746 g_Sound_PlayEx('MENU_OPEN');
5748 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
5749 if (not g_Game_IsNet) then
5750 g_Game_Pause(True);
5751 end
5752 else
5753 if (g_ActiveWindow <> nil) and (not Show) then
5754 begin
5755 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
5756 if (not g_Game_IsNet) then
5757 g_Game_Pause(False);
5758 end;
5759 end;
5761 procedure g_Game_Pause(Enable: Boolean);
5762 begin
5763 if not gGameOn then
5764 Exit;
5766 if gPause = Enable then
5767 Exit;
5769 if not (gGameSettings.GameType in [GT_SINGLE, GT_CUSTOM]) then
5770 Exit;
5772 gPause := Enable;
5773 g_Game_PauseAllSounds(Enable);
5774 end;
5776 procedure g_Game_PauseAllSounds(Enable: Boolean);
5777 var
5778 i: Integer;
5779 begin
5780 // Òðèããåðû:
5781 if gTriggers <> nil then
5782 for i := 0 to High(gTriggers) do
5783 with gTriggers[i] do
5784 if (TriggerType = TRIGGER_SOUND) and
5785 (Sound <> nil) and
5786 Sound.IsPlaying() then
5787 begin
5788 Sound.Pause(Enable);
5789 end;
5791 // Çâóêè èãðîêîâ:
5792 if gPlayers <> nil then
5793 for i := 0 to High(gPlayers) do
5794 if gPlayers[i] <> nil then
5795 gPlayers[i].PauseSounds(Enable);
5797 // Ìóçûêà:
5798 if gMusic <> nil then
5799 gMusic.Pause(Enable);
5800 end;
5802 procedure g_Game_StopAllSounds(all: Boolean);
5803 var
5804 i: Integer;
5805 begin
5806 if gTriggers <> nil then
5807 for i := 0 to High(gTriggers) do
5808 with gTriggers[i] do
5809 if (TriggerType = TRIGGER_SOUND) and
5810 (Sound <> nil) then
5811 Sound.Stop();
5813 if gMusic <> nil then
5814 gMusic.Stop();
5816 if all then
5817 e_StopChannels();
5818 end;
5820 procedure g_Game_UpdateTriggerSounds();
5821 var
5822 i: Integer;
5823 begin
5824 if gTriggers <> nil then
5825 for i := 0 to High(gTriggers) do
5826 with gTriggers[i] do
5827 if (TriggerType = TRIGGER_SOUND) and
5828 (Sound <> nil) and
5829 (Data.Local) and
5830 Sound.IsPlaying() then
5831 begin
5832 if ((gPlayer1 <> nil) and g_CollidePoint(gPlayer1.GameX, gPlayer1.GameY, X, Y, Width, Height)) or
5833 ((gPlayer2 <> nil) and g_CollidePoint(gPlayer2.GameX, gPlayer2.GameY, X, Y, Width, Height)) then
5834 begin
5835 Sound.SetPan(0.5 - Data.Pan/255.0);
5836 Sound.SetVolume(Data.Volume/255.0);
5837 end
5838 else
5839 Sound.SetCoords(X+(Width div 2), Y+(Height div 2), Data.Volume/255.0);
5840 end;
5841 end;
5843 function g_Game_IsWatchedPlayer(UID: Word): Boolean;
5844 begin
5845 Result := False;
5846 if (gPlayer1 <> nil) and (gPlayer1.UID = UID) then
5847 begin
5848 Result := True;
5849 Exit;
5850 end;
5851 if (gPlayer2 <> nil) and (gPlayer2.UID = UID) then
5852 begin
5853 Result := True;
5854 Exit;
5855 end;
5856 if gSpectMode <> SPECT_PLAYERS then
5857 Exit;
5858 if gSpectPID1 = UID then
5859 begin
5860 Result := True;
5861 Exit;
5862 end;
5863 if gSpectViewTwo and (gSpectPID2 = UID) then
5864 begin
5865 Result := True;
5866 Exit;
5867 end;
5868 end;
5870 function g_Game_IsWatchedTeam(Team: Byte): Boolean;
5871 var
5872 Pl: TPlayer;
5873 begin
5874 Result := False;
5875 if (gPlayer1 <> nil) and (gPlayer1.Team = Team) then
5876 begin
5877 Result := True;
5878 Exit;
5879 end;
5880 if (gPlayer2 <> nil) and (gPlayer2.Team = Team) then
5881 begin
5882 Result := True;
5883 Exit;
5884 end;
5885 if gSpectMode <> SPECT_PLAYERS then
5886 Exit;
5887 Pl := g_Player_Get(gSpectPID1);
5888 if (Pl <> nil) and (Pl.Team = Team) then
5889 begin
5890 Result := True;
5891 Exit;
5892 end;
5893 if gSpectViewTwo then
5894 begin
5895 Pl := g_Player_Get(gSpectPID2);
5896 if (Pl <> nil) and (Pl.Team = Team) then
5897 begin
5898 Result := True;
5899 Exit;
5900 end;
5901 end;
5902 end;
5904 procedure g_Game_Message(Msg: string; Time: Word);
5905 begin
5906 MessageText := b_Text_Format(Msg);
5907 MessageTime := Time;
5908 end;
5910 procedure g_Game_Announce_GoodShot(SpawnerUID: Word);
5911 var
5912 a: Integer;
5913 begin
5914 case gAnnouncer of
5915 ANNOUNCE_NONE:
5916 Exit;
5917 ANNOUNCE_ME,
5918 ANNOUNCE_MEPLUS:
5919 if not g_Game_IsWatchedPlayer(SpawnerUID) then
5920 Exit;
5921 end;
5922 for a := 0 to 3 do
5923 if goodsnd[a].IsPlaying() then
5924 Exit;
5926 goodsnd[Random(4)].Play();
5927 end;
5929 procedure g_Game_Announce_KillCombo(Param: Integer);
5930 var
5931 UID: Word;
5932 c, n: Byte;
5933 Pl: TPlayer;
5934 Name: String;
5935 begin
5936 UID := Param and $FFFF;
5937 c := Param shr 16;
5938 if c < 2 then
5939 Exit;
5941 Pl := g_Player_Get(UID);
5942 if Pl = nil then
5943 Name := '?'
5944 else
5945 Name := Pl.Name;
5947 case c of
5948 2: begin
5949 n := 0;
5950 g_Console_Add(Format(_lc[I_PLAYER_KILL_2X], [Name]), True);
5951 end;
5952 3: begin
5953 n := 1;
5954 g_Console_Add(Format(_lc[I_PLAYER_KILL_3X], [Name]), True);
5955 end;
5956 4: begin
5957 n := 2;
5958 g_Console_Add(Format(_lc[I_PLAYER_KILL_4X], [Name]), True);
5959 end;
5960 else begin
5961 n := 3;
5962 g_Console_Add(Format(_lc[I_PLAYER_KILL_MX], [Name]), True);
5963 end;
5964 end;
5966 case gAnnouncer of
5967 ANNOUNCE_NONE:
5968 Exit;
5969 ANNOUNCE_ME:
5970 if not g_Game_IsWatchedPlayer(UID) then
5971 Exit;
5972 ANNOUNCE_MEPLUS:
5973 if (not g_Game_IsWatchedPlayer(UID)) and (c < 4) then
5974 Exit;
5975 end;
5977 if killsnd[n].IsPlaying() then
5978 killsnd[n].Stop();
5979 killsnd[n].Play();
5980 end;
5982 procedure g_Game_StartVote(Command, Initiator: string);
5983 var
5984 Need: Integer;
5985 begin
5986 if not gVotesEnabled then Exit;
5987 if gGameSettings.GameType <> GT_SERVER then Exit;
5988 if gVoteInProgress or gVotePassed then
5989 begin
5990 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_INPROGRESS], [gVoteCommand]), True);
5991 MH_SEND_VoteEvent(NET_VE_INPROGRESS, gVoteCommand);
5992 Exit;
5993 end;
5994 gVoteInProgress := True;
5995 gVotePassed := False;
5996 gVoteTimer := gTime + gVoteTimeout * 1000;
5997 gVoteCount := 0;
5998 gVoted := False;
5999 gVoteCommand := Command;
6001 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
6002 Need := Floor((NetClientCount+1)/2.0)+1
6003 else
6004 Need := Floor(NetClientCount/2.0)+1;
6005 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_STARTED], [Initiator, Command, Need]), True);
6006 MH_SEND_VoteEvent(NET_VE_STARTED, Initiator, Command, Need);
6007 end;
6009 procedure g_Game_CheckVote;
6010 var
6011 I, Need: Integer;
6012 begin
6013 if gGameSettings.GameType <> GT_SERVER then Exit;
6014 if not gVoteInProgress then Exit;
6016 if (gTime >= gVoteTimer) then
6017 begin
6018 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
6019 Need := Floor((NetClientCount+1)/2.0) + 1
6020 else
6021 Need := Floor(NetClientCount/2.0) + 1;
6022 if gVoteCount >= Need then
6023 begin
6024 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_PASSED], [gVoteCommand]), True);
6025 MH_SEND_VoteEvent(NET_VE_PASSED, gVoteCommand);
6026 gVotePassed := True;
6027 gVoteCmdTimer := gTime + 5000;
6028 end
6029 else
6030 begin
6031 g_Console_Add(_lc[I_MESSAGE_VOTE_FAILED], True);
6032 MH_SEND_VoteEvent(NET_VE_FAILED);
6033 end;
6034 if NetClients <> nil then
6035 for I := Low(NetClients) to High(NetClients) do
6036 if NetClients[i].Used then
6037 NetClients[i].Voted := False;
6038 gVoteInProgress := False;
6039 gVoted := False;
6040 gVoteCount := 0;
6041 end
6042 else
6043 begin
6044 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
6045 Need := Floor((NetClientCount+1)/2.0) + 1
6046 else
6047 Need := Floor(NetClientCount/2.0) + 1;
6048 if gVoteCount >= Need then
6049 begin
6050 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_PASSED], [gVoteCommand]), True);
6051 MH_SEND_VoteEvent(NET_VE_PASSED, gVoteCommand);
6052 gVoteInProgress := False;
6053 gVotePassed := True;
6054 gVoteCmdTimer := gTime + 5000;
6055 gVoted := False;
6056 gVoteCount := 0;
6057 if NetClients <> nil then
6058 for I := Low(NetClients) to High(NetClients) do
6059 if NetClients[i].Used then
6060 NetClients[i].Voted := False;
6061 end;
6062 end;
6063 end;
6065 procedure g_Game_LoadMapList(FileName: string);
6066 var
6067 ListFile: TextFile;
6068 s: string;
6069 begin
6070 MapList := nil;
6071 MapIndex := -1;
6073 if not FileExists(FileName) then Exit;
6075 AssignFile(ListFile, FileName);
6076 Reset(ListFile);
6077 while not EOF(ListFile) do
6078 begin
6079 ReadLn(ListFile, s);
6081 s := Trim(s);
6082 if s = '' then Continue;
6084 SetLength(MapList, Length(MapList)+1);
6085 MapList[High(MapList)] := s;
6086 end;
6087 CloseFile(ListFile);
6088 end;
6090 procedure g_Game_SetDebugMode();
6091 begin
6092 gDebugMode := True;
6093 // ×èòû (äàæå â ñâîåé èãðå):
6094 gCheats := True;
6095 end;
6097 procedure g_Game_SetLoadingText(Text: String; Max: Integer; reWrite: Boolean);
6098 var
6099 i: Word;
6100 begin
6101 if Length(LoadingStat.Msgs) = 0 then
6102 Exit;
6104 with LoadingStat do
6105 begin
6106 if not reWrite then
6107 begin // Ïåðåõîäèì íà ñëåäóþùóþ ñòðîêó èëè ñêðîëëèðóåì:
6108 if NextMsg = Length(Msgs) then
6109 begin // scroll
6110 for i := 0 to High(Msgs)-1 do
6111 Msgs[i] := Msgs[i+1];
6112 end
6113 else
6114 Inc(NextMsg);
6115 end else
6116 if NextMsg = 0 then
6117 Inc(NextMsg);
6119 Msgs[NextMsg-1] := Text;
6120 CurValue := 0;
6121 MaxValue := Max;
6122 ShowCount := 0;
6123 end;
6125 g_ActiveWindow := nil;
6127 ProcessLoading;
6128 end;
6130 procedure g_Game_StepLoading();
6131 begin
6132 with LoadingStat do
6133 begin
6134 Inc(CurValue);
6135 Inc(ShowCount);
6136 if (ShowCount > LOADING_SHOW_STEP) then
6137 begin
6138 ShowCount := 0;
6139 ProcessLoading;
6140 end;
6141 end;
6142 end;
6144 procedure g_Game_ClearLoading();
6145 var
6146 len: Word;
6147 begin
6148 with LoadingStat do
6149 begin
6150 CurValue := 0;
6151 MaxValue := 0;
6152 ShowCount := 0;
6153 len := ((gScreenHeight div 3)*2 - 50) div LOADING_INTERLINE;
6154 if len < 1 then len := 1;
6155 SetLength(Msgs, len);
6156 for len := Low(Msgs) to High(Msgs) do
6157 Msgs[len] := '';
6158 NextMsg := 0;
6159 end;
6160 end;
6162 procedure Parse_Params(var pars: TParamStrValues);
6163 var
6164 i: Integer;
6165 s: String;
6166 begin
6167 SetLength(pars, 0);
6168 i := 1;
6169 while i <= ParamCount do
6170 begin
6171 s := ParamStr(i);
6172 if (s[1] = '-') and (Length(s) > 1) then
6173 begin
6174 if (s[2] = '-') and (Length(s) > 2) then
6175 begin // Îäèíî÷íûé ïàðàìåòð
6176 SetLength(pars, Length(pars) + 1);
6177 with pars[High(pars)] do
6178 begin
6179 Name := LowerCase(s);
6180 Value := '+';
6181 end;
6182 end
6183 else
6184 if (i < ParamCount) then
6185 begin // Ïàðàìåòð ñî çíà÷åíèåì
6186 Inc(i);
6187 SetLength(pars, Length(pars) + 1);
6188 with pars[High(pars)] do
6189 begin
6190 Name := LowerCase(s);
6191 Value := LowerCase(ParamStr(i));
6192 end;
6193 end;
6194 end;
6196 Inc(i);
6197 end;
6198 end;
6200 function Find_Param_Value(var pars: TParamStrValues; aName: String): String;
6201 var
6202 i: Integer;
6203 begin
6204 Result := '';
6205 for i := 0 to High(pars) do
6206 if pars[i].Name = aName then
6207 begin
6208 Result := pars[i].Value;
6209 Break;
6210 end;
6211 end;
6213 procedure g_Game_Process_Params();
6214 var
6215 pars: TParamStrValues;
6216 map: String;
6217 GMode, n: Byte;
6218 LimT, LimS: Integer;
6219 Opt: LongWord;
6220 Lives: Integer;
6221 s: String;
6222 Port: Integer;
6223 ip: String;
6224 F: TextFile;
6225 begin
6226 Parse_Params(pars);
6228 // Debug mode:
6229 s := Find_Param_Value(pars, '--debug');
6230 if (s <> '') then
6231 g_Game_SetDebugMode();
6233 // Connect when game loads
6234 ip := Find_Param_Value(pars, '-connect');
6236 if ip <> '' then
6237 begin
6238 s := Find_Param_Value(pars, '-port');
6239 if (s = '') or not TryStrToInt(s, Port) then
6240 Port := 25666;
6242 s := Find_Param_Value(pars, '-pw');
6244 g_Game_StartClient(ip, Port, s);
6245 Exit;
6246 end;
6248 // Start map when game loads:
6249 map := LowerCase(Find_Param_Value(pars, '-map'));
6250 if (map <> '') and (Pos('.wad:\', map) > 0) then
6251 begin
6252 // Game mode:
6253 s := Find_Param_Value(pars, '-gm');
6254 GMode := g_Game_TextToMode(s);
6255 if GMode = GM_NONE then GMode := GM_DM;
6256 if GMode = GM_SINGLE then GMode := GM_COOP;
6258 // Time limit:
6259 s := Find_Param_Value(pars, '-limt');
6260 if (s = '') or (not TryStrToInt(s, LimT)) then
6261 LimT := 0;
6262 if LimT < 0 then
6263 LimT := 0;
6265 // Goal limit:
6266 s := Find_Param_Value(pars, '-lims');
6267 if (s = '') or (not TryStrToInt(s, LimS)) then
6268 LimS := 0;
6269 if LimS < 0 then
6270 LimS := 0;
6272 // Lives limit:
6273 s := Find_Param_Value(pars, '-lives');
6274 if (s = '') or (not TryStrToInt(s, Lives)) then
6275 Lives := 0;
6276 if Lives < 0 then
6277 Lives := 0;
6279 // Options:
6280 s := Find_Param_Value(pars, '-opt');
6281 if (s = '') then
6282 Opt := GAME_OPTION_ALLOWEXIT or GAME_OPTION_BOTVSPLAYER or GAME_OPTION_BOTVSMONSTER
6283 else
6284 Opt := StrToIntDef(s, 0);
6285 if Opt = 0 then
6286 Opt := GAME_OPTION_ALLOWEXIT or GAME_OPTION_BOTVSPLAYER or GAME_OPTION_BOTVSMONSTER;
6288 // Close after map:
6289 s := Find_Param_Value(pars, '--close');
6290 if (s <> '') then
6291 gMapOnce := True;
6293 // Delete test map after play:
6294 s := Find_Param_Value(pars, '--testdelete');
6295 if (s <> '') then
6296 gMapToDelete := MapsDir + map;
6298 // Delete temporary WAD after play:
6299 s := Find_Param_Value(pars, '--tempdelete');
6300 if (s <> '') then
6301 begin
6302 gMapToDelete := MapsDir + map;
6303 gTempDelete := True;
6304 end;
6306 // Number of players:
6307 s := Find_Param_Value(pars, '-pl');
6308 if (s = '') then
6309 n := 1
6310 else
6311 n := StrToIntDef(s, 1);
6313 // Start:
6314 s := Find_Param_Value(pars, '-port');
6315 if (s = '') or not TryStrToInt(s, Port) then
6316 g_Game_StartCustom(map, GMode, LimT, LimS, Lives, Opt, n)
6317 else
6318 g_Game_StartServer(map, GMode, LimT, LimS, Lives, Opt, n, 0, Port);
6319 end;
6321 // Execute script when game loads:
6322 s := Find_Param_Value(pars, '-exec');
6323 if s <> '' then
6324 begin
6325 if Pos(':\', s) = 0 then
6326 s := GameDir + '/' + s;
6328 {$I-}
6329 AssignFile(F, s);
6330 Reset(F);
6331 if IOResult <> 0 then
6332 begin
6333 e_WriteLog(Format(_lc[I_SIMPLE_ERROR], ['Failed to read file: ' + s]), MSG_WARNING);
6334 g_Console_Add(Format(_lc[I_CONSOLE_ERROR_READ], [s]));
6335 CloseFile(F);
6336 Exit;
6337 end;
6338 e_WriteLog('Executing script: ' + s, MSG_NOTIFY);
6339 g_Console_Add(Format(_lc[I_CONSOLE_EXEC], [s]));
6341 while not EOF(F) do
6342 begin
6343 ReadLn(F, s);
6344 if IOResult <> 0 then
6345 begin
6346 e_WriteLog(Format(_lc[I_SIMPLE_ERROR], ['Failed to read file: ' + s]), MSG_WARNING);
6347 g_Console_Add(Format(_lc[I_CONSOLE_ERROR_READ], [s]));
6348 CloseFile(F);
6349 Exit;
6350 end;
6351 if Pos('#', s) <> 1 then // script comment
6352 g_Console_Process(s, True);
6353 end;
6355 CloseFile(F);
6356 {$I+}
6357 end;
6359 SetLength(pars, 0);
6360 end;
6362 end.