DEADSOFTWARE

sdl sound: now it seems to work (much better, lol)
[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 if g_debug_Sounds and gGameOn then
2960 begin
2961 for w := 0 to High(e_SoundsArray) do
2962 for h := 0 to e_SoundsArray[w].nRefs do
2963 e_DrawPoint(1, w+100, h+100, 255, 0, 0);
2964 end;
2966 if gShowFPS then
2967 begin
2968 e_TextureFontPrint(0, 0, Format('FPS: %d', [FPS]), gStdFont);
2969 e_TextureFontPrint(0, 16, Format('UPS: %d', [UPS]), gStdFont);
2970 end;
2972 if gGameOn and gShowTime and (gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT]) then
2973 e_TextureFontPrint(gScreenWidth-72, 0,
2974 Format('%d:%.2d:%.2d', [gTime div 1000 div 3600, (gTime div 1000 div 60) mod 60, gTime div 1000 mod 60]),
2975 gStdFont);
2976 end;
2978 procedure g_Game_Quit();
2979 begin
2980 g_Game_StopAllSounds(True);
2981 gMusic.Free();
2982 g_Game_SaveOptions();
2983 g_Game_FreeData();
2984 g_PlayerModel_FreeData();
2985 g_Texture_DeleteAll();
2986 g_Frames_DeleteAll();
2987 g_Menu_Free();
2989 if NetInitDone then g_Net_Free;
2991 // Íàäî óäàëèòü êàðòó ïîñëå òåñòà:
2992 if gMapToDelete <> '' then
2993 g_Game_DeleteTestMap();
2995 gExit := EXIT_QUIT;
2996 PushExitEvent();
2997 end;
2999 procedure g_FatalError(Text: String);
3000 begin
3001 g_Console_Add(Format(_lc[I_FATAL_ERROR], [Text]), True);
3002 e_WriteLog(Format(_lc[I_FATAL_ERROR], [Text]), MSG_WARNING);
3004 gExit := EXIT_SIMPLE;
3005 end;
3007 procedure g_SimpleError(Text: String);
3008 begin
3009 g_Console_Add(Format(_lc[I_SIMPLE_ERROR], [Text]), True);
3010 e_WriteLog(Format(_lc[I_SIMPLE_ERROR], [Text]), MSG_WARNING);
3011 end;
3013 procedure g_Game_SetupScreenSize();
3014 var
3015 d: Single;
3016 begin
3017 // Ðàçìåð ýêðàíîâ èãðîêîâ:
3018 gPlayerScreenSize.X := gScreenWidth-196;
3019 if (gPlayer1 <> nil) and (gPlayer2 <> nil) then
3020 gPlayerScreenSize.Y := gScreenHeight div 2
3021 else
3022 gPlayerScreenSize.Y := gScreenHeight;
3024 // Ðàçìåð çàäíåãî ïëàíà:
3025 if BackID <> DWORD(-1) then
3026 begin
3027 d := SKY_STRETCH;
3029 if (gScreenWidth*d > gMapInfo.Width) or
3030 (gScreenHeight*d > gMapInfo.Height) then
3031 d := 1.0;
3033 gBackSize.X := Round(gScreenWidth*d);
3034 gBackSize.Y := Round(gScreenHeight*d);
3035 end;
3036 end;
3038 procedure g_Game_ChangeResolution(newWidth, newHeight: Word; nowFull, nowMax: Boolean);
3039 begin
3040 g_Window_SetSize(newWidth, newHeight, nowFull);
3041 end;
3043 procedure g_Game_AddPlayer(Team: Byte = TEAM_NONE);
3044 begin
3045 if ((not gGameOn) and (gState <> STATE_INTERCUSTOM))
3046 or (not (gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT])) then
3047 Exit;
3048 if gPlayer1 = nil then
3049 begin
3050 if g_Game_IsClient then
3051 begin
3052 if NetPlrUID1 > -1 then
3053 begin
3054 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE);
3055 gPlayer1 := g_Player_Get(NetPlrUID1);
3056 end;
3057 Exit;
3058 end;
3060 if not (Team in [TEAM_RED, TEAM_BLUE]) then
3061 Team := gPlayer1Settings.Team;
3063 // Ñîçäàíèå ïåðâîãî èãðîêà:
3064 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
3065 gPlayer1Settings.Color,
3066 Team, False));
3067 if gPlayer1 = nil then
3068 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]))
3069 else
3070 begin
3071 gPlayer1.Name := gPlayer1Settings.Name;
3072 g_Console_Add(Format(_lc[I_PLAYER_JOIN], [gPlayer1.Name]), True);
3073 if g_Game_IsServer and g_Game_IsNet then
3074 MH_SEND_PlayerCreate(gPlayer1.UID);
3075 gPlayer1.Respawn(False, True);
3077 if g_Game_IsNet and NetUseMaster then
3078 g_Net_Slist_Update;
3079 end;
3081 Exit;
3082 end;
3083 if gPlayer2 = nil then
3084 begin
3085 if g_Game_IsClient then
3086 begin
3087 if NetPlrUID2 > -1 then
3088 gPlayer2 := g_Player_Get(NetPlrUID2);
3089 Exit;
3090 end;
3092 if not (Team in [TEAM_RED, TEAM_BLUE]) then
3093 Team := gPlayer2Settings.Team;
3095 // Ñîçäàíèå âòîðîãî èãðîêà:
3096 gPlayer2 := g_Player_Get(g_Player_Create(gPlayer2Settings.Model,
3097 gPlayer2Settings.Color,
3098 Team, False));
3099 if gPlayer2 = nil then
3100 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [2]))
3101 else
3102 begin
3103 gPlayer2.Name := gPlayer2Settings.Name;
3104 g_Console_Add(Format(_lc[I_PLAYER_JOIN], [gPlayer2.Name]), True);
3105 if g_Game_IsServer and g_Game_IsNet then
3106 MH_SEND_PlayerCreate(gPlayer2.UID);
3107 gPlayer2.Respawn(False, True);
3109 if g_Game_IsNet and NetUseMaster then
3110 g_Net_Slist_Update;
3111 end;
3113 Exit;
3114 end;
3115 end;
3117 procedure g_Game_RemovePlayer();
3118 var
3119 Pl: TPlayer;
3120 begin
3121 if ((not gGameOn) and (gState <> STATE_INTERCUSTOM))
3122 or (not (gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT])) then
3123 Exit;
3124 Pl := gPlayer2;
3125 if Pl <> nil then
3126 begin
3127 if g_Game_IsServer then
3128 begin
3129 Pl.Lives := 0;
3130 Pl.Kill(K_SIMPLEKILL, 0, HIT_DISCON);
3131 g_Console_Add(Format(_lc[I_PLAYER_LEAVE], [Pl.Name]), True);
3132 g_Player_Remove(Pl.UID);
3134 if g_Game_IsNet and NetUseMaster then
3135 g_Net_Slist_Update;
3136 end else
3137 gPlayer2 := nil;
3138 Exit;
3139 end;
3140 Pl := gPlayer1;
3141 if Pl <> nil then
3142 begin
3143 if g_Game_IsServer then
3144 begin
3145 Pl.Lives := 0;
3146 Pl.Kill(K_SIMPLEKILL, 0, HIT_DISCON);
3147 g_Console_Add(Format(_lc[I_PLAYER_LEAVE], [Pl.Name]), True);
3148 g_Player_Remove(Pl.UID);
3150 if g_Game_IsNet and NetUseMaster then
3151 g_Net_Slist_Update;
3152 end else
3153 begin
3154 gPlayer1 := nil;
3155 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE);
3156 end;
3157 Exit;
3158 end;
3159 end;
3161 procedure g_Game_Spectate();
3162 begin
3163 g_Game_RemovePlayer();
3164 if gPlayer1 <> nil then
3165 g_Game_RemovePlayer();
3166 end;
3168 procedure g_Game_SpectateCenterView();
3169 begin
3170 gSpectX := Max(gMapInfo.Width div 2 - gScreenWidth div 2, 0);
3171 gSpectY := Max(gMapInfo.Height div 2 - gScreenHeight div 2, 0);
3172 end;
3174 procedure g_Game_StartSingle(Map: String; TwoPlayers: Boolean; nPlayers: Byte);
3175 var
3176 i, nPl: Integer;
3177 begin
3178 g_Game_Free();
3180 e_WriteLog('Starting singleplayer game...', MSG_NOTIFY);
3182 g_Game_ClearLoading();
3184 // Íàñòðîéêè èãðû:
3185 FillByte(gGameSettings, SizeOf(TGameSettings), 0);
3186 gAimLine := False;
3187 gShowMap := False;
3188 gGameSettings.GameType := GT_SINGLE;
3189 gGameSettings.MaxLives := 0;
3190 gGameSettings.Options := gGameSettings.Options + GAME_OPTION_ALLOWEXIT;
3191 gGameSettings.Options := gGameSettings.Options + GAME_OPTION_MONSTERS;
3192 gGameSettings.Options := gGameSettings.Options + GAME_OPTION_BOTVSMONSTER;
3193 gSwitchGameMode := GM_SINGLE;
3195 g_Game_ExecuteEvent('ongamestart');
3197 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
3198 g_Game_SetupScreenSize();
3200 // Ñîçäàíèå ïåðâîãî èãðîêà:
3201 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
3202 gPlayer1Settings.Color,
3203 gPlayer1Settings.Team, False));
3204 if gPlayer1 = nil then
3205 begin
3206 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]));
3207 Exit;
3208 end;
3210 gPlayer1.Name := gPlayer1Settings.Name;
3211 nPl := 1;
3213 // Ñîçäàíèå âòîðîãî èãðîêà, åñëè åñòü:
3214 if TwoPlayers then
3215 begin
3216 gPlayer2 := g_Player_Get(g_Player_Create(gPlayer2Settings.Model,
3217 gPlayer2Settings.Color,
3218 gPlayer2Settings.Team, False));
3219 if gPlayer2 = nil then
3220 begin
3221 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [2]));
3222 Exit;
3223 end;
3225 gPlayer2.Name := gPlayer2Settings.Name;
3226 Inc(nPl);
3227 end;
3229 // Çàãðóçêà è çàïóñê êàðòû:
3230 if not g_Game_StartMap(MAP, True) then
3231 begin
3232 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [gGameSettings.WAD + ':\' + MAP]));
3233 Exit;
3234 end;
3236 // Íàñòðîéêè èãðîêîâ è áîòîâ:
3237 g_Player_Init();
3239 // Ñîçäàåì áîòîâ:
3240 for i := nPl+1 to nPlayers do
3241 g_Player_Create(STD_PLAYER_MODEL, _RGB(0, 0, 0), 0, True);
3242 end;
3244 procedure g_Game_StartCustom(Map: String; GameMode: Byte;
3245 TimeLimit, GoalLimit: Word;
3246 MaxLives: Byte;
3247 Options: LongWord; nPlayers: Byte);
3248 var
3249 i, nPl: Integer;
3250 begin
3251 g_Game_Free();
3253 e_WriteLog('Starting custom game...', MSG_NOTIFY);
3255 g_Game_ClearLoading();
3257 // Íàñòðîéêè èãðû:
3258 gGameSettings.GameType := GT_CUSTOM;
3259 gGameSettings.GameMode := GameMode;
3260 gSwitchGameMode := GameMode;
3261 gGameSettings.TimeLimit := TimeLimit;
3262 gGameSettings.GoalLimit := GoalLimit;
3263 gGameSettings.MaxLives := IfThen(GameMode = GM_CTF, 0, MaxLives);
3264 gGameSettings.Options := Options;
3266 gCoopTotalMonstersKilled := 0;
3267 gCoopTotalSecretsFound := 0;
3268 gCoopTotalMonsters := 0;
3269 gCoopTotalSecrets := 0;
3270 gAimLine := False;
3271 gShowMap := False;
3273 g_Game_ExecuteEvent('ongamestart');
3275 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
3276 g_Game_SetupScreenSize();
3278 // Ðåæèì íàáëþäàòåëÿ:
3279 if nPlayers = 0 then
3280 begin
3281 gPlayer1 := nil;
3282 gPlayer2 := nil;
3283 end;
3285 nPl := 0;
3286 if nPlayers >= 1 then
3287 begin
3288 // Ñîçäàíèå ïåðâîãî èãðîêà:
3289 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
3290 gPlayer1Settings.Color,
3291 gPlayer1Settings.Team, False));
3292 if gPlayer1 = nil then
3293 begin
3294 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]));
3295 Exit;
3296 end;
3298 gPlayer1.Name := gPlayer1Settings.Name;
3299 Inc(nPl);
3300 end;
3302 if nPlayers >= 2 then
3303 begin
3304 // Ñîçäàíèå âòîðîãî èãðîêà:
3305 gPlayer2 := g_Player_Get(g_Player_Create(gPlayer2Settings.Model,
3306 gPlayer2Settings.Color,
3307 gPlayer2Settings.Team, False));
3308 if gPlayer2 = nil then
3309 begin
3310 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [2]));
3311 Exit;
3312 end;
3314 gPlayer2.Name := gPlayer2Settings.Name;
3315 Inc(nPl);
3316 end;
3318 // Çàãðóçêà è çàïóñê êàðòû:
3319 if not g_Game_StartMap(Map, True) then
3320 begin
3321 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [Map]));
3322 Exit;
3323 end;
3325 // Íåò òî÷åê ïîÿâëåíèÿ:
3326 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1) +
3327 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2) +
3328 g_Map_GetPointCount(RESPAWNPOINT_DM) +
3329 g_Map_GetPointCount(RESPAWNPOINT_RED)+
3330 g_Map_GetPointCount(RESPAWNPOINT_BLUE)) < 1 then
3331 begin
3332 g_FatalError(_lc[I_GAME_ERROR_GET_SPAWN]);
3333 Exit;
3334 end;
3336 // Íàñòðîéêè èãðîêîâ è áîòîâ:
3337 g_Player_Init();
3339 // Ñîçäàåì áîòîâ:
3340 for i := nPl+1 to nPlayers do
3341 g_Player_Create(STD_PLAYER_MODEL, _RGB(0, 0, 0), 0, True);
3342 end;
3344 procedure g_Game_StartServer(Map: String; GameMode: Byte;
3345 TimeLimit, GoalLimit: Word; MaxLives: Byte;
3346 Options: LongWord; nPlayers: Byte;
3347 IPAddr: LongWord; Port: Word);
3348 begin
3349 g_Game_Free();
3351 e_WriteLog('Starting net game (server)...', MSG_NOTIFY);
3353 g_Game_ClearLoading();
3355 // Íàñòðîéêè èãðû:
3356 gGameSettings.GameType := GT_SERVER;
3357 gGameSettings.GameMode := GameMode;
3358 gSwitchGameMode := GameMode;
3359 gGameSettings.TimeLimit := TimeLimit;
3360 gGameSettings.GoalLimit := GoalLimit;
3361 gGameSettings.MaxLives := IfThen(GameMode = GM_CTF, 0, MaxLives);
3362 gGameSettings.Options := Options;
3364 gCoopTotalMonstersKilled := 0;
3365 gCoopTotalSecretsFound := 0;
3366 gCoopTotalMonsters := 0;
3367 gCoopTotalSecrets := 0;
3368 gAimLine := False;
3369 gShowMap := False;
3371 g_Game_ExecuteEvent('ongamestart');
3373 // Óñòàíîâêà ðàçìåðîâ îêíà èãðîêà
3374 g_Game_SetupScreenSize();
3376 // Ðåæèì íàáëþäàòåëÿ:
3377 if nPlayers = 0 then
3378 begin
3379 gPlayer1 := nil;
3380 gPlayer2 := nil;
3381 end;
3383 if nPlayers >= 1 then
3384 begin
3385 // Ñîçäàíèå ïåðâîãî èãðîêà:
3386 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
3387 gPlayer1Settings.Color,
3388 gPlayer1Settings.Team, False));
3389 if gPlayer1 = nil then
3390 begin
3391 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]));
3392 Exit;
3393 end;
3395 gPlayer1.Name := gPlayer1Settings.Name;
3396 end;
3398 if nPlayers >= 2 then
3399 begin
3400 // Ñîçäàíèå âòîðîãî èãðîêà:
3401 gPlayer2 := g_Player_Get(g_Player_Create(gPlayer2Settings.Model,
3402 gPlayer2Settings.Color,
3403 gPlayer2Settings.Team, False));
3404 if gPlayer2 = nil then
3405 begin
3406 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [2]));
3407 Exit;
3408 end;
3410 gPlayer2.Name := gPlayer2Settings.Name;
3411 end;
3413 // Ñòàðòóåì ñåðâåð
3414 if not g_Net_Host(IPAddr, Port, NetMaxClients) then
3415 begin
3416 g_FatalError(_lc[I_NET_MSG] + _lc[I_NET_ERR_HOST]);
3417 Exit;
3418 end;
3420 g_Net_Slist_Set(NetSlistIP, NetSlistPort);
3422 // Çàãðóçêà è çàïóñê êàðòû:
3423 if not g_Game_StartMap(Map, True) then
3424 begin
3425 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [Map]));
3426 Exit;
3427 end;
3429 // Íåò òî÷åê ïîÿâëåíèÿ:
3430 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1) +
3431 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2) +
3432 g_Map_GetPointCount(RESPAWNPOINT_DM) +
3433 g_Map_GetPointCount(RESPAWNPOINT_RED)+
3434 g_Map_GetPointCount(RESPAWNPOINT_BLUE)) < 1 then
3435 begin
3436 g_FatalError(_lc[I_GAME_ERROR_GET_SPAWN]);
3437 Exit;
3438 end;
3440 // Íàñòðîéêè èãðîêîâ è áîòîâ:
3441 g_Player_Init();
3443 NetState := NET_STATE_GAME;
3444 end;
3446 procedure g_Game_StartClient(Addr: String; Port: Word; PW: String);
3447 var
3448 Map: String;
3449 WadName: string;
3450 Ptr: Pointer;
3451 T: Cardinal;
3452 MID: Byte;
3453 State: Byte;
3454 OuterLoop: Boolean;
3455 newResPath: string;
3456 begin
3457 g_Game_Free();
3459 State := 0;
3460 e_WriteLog('Starting net game (client)...', MSG_NOTIFY);
3461 e_WriteLog('NET: Trying to connect to ' + Addr + ':' + IntToStr(Port) + '...', MSG_NOTIFY);
3463 g_Game_ClearLoading();
3465 // Íàñòðîéêè èãðû:
3466 gGameSettings.GameType := GT_CLIENT;
3468 gCoopTotalMonstersKilled := 0;
3469 gCoopTotalSecretsFound := 0;
3470 gCoopTotalMonsters := 0;
3471 gCoopTotalSecrets := 0;
3472 gAimLine := False;
3473 gShowMap := False;
3475 g_Game_ExecuteEvent('ongamestart');
3477 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
3478 g_Game_SetupScreenSize();
3480 NetState := NET_STATE_AUTH;
3482 g_Game_SetLoadingText(_lc[I_LOAD_CONNECT], 0, False);
3483 // Ñòàðòóåì êëèåíò
3484 if not g_Net_Connect(Addr, Port) then
3485 begin
3486 g_FatalError(_lc[I_NET_MSG] + _lc[I_NET_ERR_CONN]);
3487 NetState := NET_STATE_NONE;
3488 Exit;
3489 end;
3491 g_Game_SetLoadingText(_lc[I_LOAD_SEND_INFO], 0, False);
3492 MC_SEND_Info(PW);
3493 g_Game_SetLoadingText(_lc[I_LOAD_WAIT_INFO], 0, False);
3495 OuterLoop := True;
3496 while OuterLoop do
3497 begin
3498 while (enet_host_service(NetHost, @NetEvent, 0) > 0) do
3499 begin
3500 if (NetEvent.kind = ENET_EVENT_TYPE_RECEIVE) then
3501 begin
3502 Ptr := NetEvent.packet^.data;
3503 e_Raw_Seek(0);
3505 MID := e_Raw_Read_Byte(Ptr);
3507 if (MID = NET_MSG_INFO) and (State = 0) then
3508 begin
3509 NetMyID := e_Raw_Read_Byte(Ptr);
3510 NetPlrUID1 := e_Raw_Read_Word(Ptr);
3512 WadName := e_Raw_Read_String(Ptr);
3513 Map := e_Raw_Read_String(Ptr);
3515 gWADHash := e_Raw_Read_MD5(Ptr);
3517 gGameSettings.GameMode := e_Raw_Read_Byte(Ptr);
3518 gSwitchGameMode := gGameSettings.GameMode;
3519 gGameSettings.GoalLimit := e_Raw_Read_Word(Ptr);
3520 gGameSettings.TimeLimit := e_Raw_Read_Word(Ptr);
3521 gGameSettings.MaxLives := e_Raw_Read_Byte(Ptr);
3522 gGameSettings.Options := e_Raw_Read_LongWord(Ptr);
3523 T := e_Raw_Read_LongWord(Ptr);
3525 newResPath := g_Res_SearchSameWAD(MapsDir, WadName, gWADHash);
3526 if newResPath = '' then
3527 begin
3528 g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
3529 newResPath := g_Res_DownloadWAD(WadName);
3530 if newResPath = '' then
3531 begin
3532 g_FatalError(_lc[I_NET_ERR_HASH]);
3533 enet_packet_destroy(NetEvent.packet);
3534 NetState := NET_STATE_NONE;
3535 Exit;
3536 end;
3537 end;
3538 newResPath := ExtractRelativePath(MapsDir, newResPath);
3540 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
3541 gPlayer1Settings.Color,
3542 gPlayer1Settings.Team, False));
3544 if gPlayer1 = nil then
3545 begin
3546 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]));
3548 enet_packet_destroy(NetEvent.packet);
3549 NetState := NET_STATE_NONE;
3550 Exit;
3551 end;
3553 gPlayer1.Name := gPlayer1Settings.Name;
3554 gPlayer1.UID := NetPlrUID1;
3555 gPlayer1.Reset(True);
3557 if not g_Game_StartMap(newResPath + ':\' + Map, True) then
3558 begin
3559 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [WadName + ':\' + Map]));
3561 enet_packet_destroy(NetEvent.packet);
3562 NetState := NET_STATE_NONE;
3563 Exit;
3564 end;
3566 gTime := T;
3568 State := 1;
3569 OuterLoop := False;
3570 enet_packet_destroy(NetEvent.packet);
3571 break;
3572 end
3573 else
3574 enet_packet_destroy(NetEvent.packet);
3575 end
3576 else
3577 if (NetEvent.kind = ENET_EVENT_TYPE_DISCONNECT) then
3578 begin
3579 State := 0;
3580 if (NetEvent.data <= NET_DISC_MAX) then
3581 g_Console_Add(_lc[I_NET_MSG_ERROR] + _lc[I_NET_ERR_CONN] + ' ' +
3582 _lc[TStrings_Locale(Cardinal(I_NET_DISC_NONE) + NetEvent.data)], True);
3583 OuterLoop := False;
3584 Break;
3585 end;
3586 end;
3588 ProcessLoading();
3590 e_PollInput();
3592 if e_KeyPressed(IK_ESCAPE) or e_KeyPressed(IK_SPACE) then
3593 begin
3594 State := 0;
3595 break;
3596 end;
3597 end;
3599 if State <> 1 then
3600 begin
3601 g_FatalError(_lc[I_NET_MSG] + _lc[I_NET_ERR_CONN]);
3602 NetState := NET_STATE_NONE;
3603 Exit;
3604 end;
3606 gLMSRespawn := LMS_RESPAWN_NONE;
3607 gLMSRespawnTime := 0;
3609 g_Player_Init();
3610 NetState := NET_STATE_GAME;
3611 MC_SEND_FullStateRequest;
3612 e_WriteLog('NET: Connection successful.', MSG_NOTIFY);
3613 end;
3615 procedure g_Game_SaveOptions();
3616 begin
3617 g_Options_Write_Video(GameDir+'/'+CONFIG_FILENAME);
3618 end;
3620 procedure g_Game_ChangeMap(MapPath: String);
3621 var
3622 Force: Boolean;
3623 begin
3624 g_Game_ClearLoading();
3626 Force := gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF];
3627 // Åñëè óðîâåíü çàâåðøèëñÿ ïî òðèããåðó Âûõîä, íå î÷èùàòü èíâåíòàðü
3628 if gExitByTrigger then
3629 begin
3630 Force := False;
3631 gExitByTrigger := False;
3632 end;
3633 if not g_Game_StartMap(MapPath, Force) then
3634 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [MapPath]));
3635 end;
3637 procedure g_Game_Restart();
3638 var
3639 Map: string;
3640 begin
3641 if g_Game_IsClient then
3642 Exit;
3643 g_ProcessResourceStr(gMapInfo.Map, nil, nil, @Map);
3645 MessageTime := 0;
3646 gGameOn := False;
3647 g_Game_ClearLoading();
3648 g_Game_StartMap(Map, True);
3649 end;
3651 function g_Game_StartMap(Map: String; Force: Boolean = False): Boolean;
3652 var
3653 NewWAD, ResName: String;
3654 I: Integer;
3655 begin
3656 g_Map_Free();
3657 g_Player_RemoveAllCorpses();
3659 if (not g_Game_IsClient) and
3660 (gSwitchGameMode <> gGameSettings.GameMode) and
3661 (gGameSettings.GameMode <> GM_SINGLE) then
3662 begin
3663 if gSwitchGameMode = GM_CTF then
3664 gGameSettings.MaxLives := 0;
3665 gGameSettings.GameMode := gSwitchGameMode;
3666 Force := True;
3667 end else
3668 gSwitchGameMode := gGameSettings.GameMode;
3670 g_Player_ResetTeams();
3672 if Pos(':\', Map) > 0 then
3673 begin
3674 g_ProcessResourceStr(Map, @NewWAD, nil, @ResName);
3675 if g_Game_IsServer then
3676 begin
3677 gWADHash := MD5File(MapsDir + NewWAD);
3678 g_Game_LoadWAD(NewWAD);
3679 end else
3680 // hash recieved in MC_RECV_GameEvent -> NET_EV_MAPSTART
3681 g_Game_ClientWAD(NewWAD, gWADHash);
3682 end else
3683 ResName := Map;
3685 Result := g_Map_Load(MapsDir + gGameSettings.WAD + ':\' + ResName);
3686 if Result then
3687 begin
3688 g_Player_ResetAll(Force or gLastMap, gGameSettings.GameType = GT_SINGLE);
3690 gState := STATE_NONE;
3691 g_ActiveWindow := nil;
3692 gGameOn := True;
3694 DisableCheats();
3695 ResetTimer();
3697 if gGameSettings.GameMode = GM_CTF then
3698 begin
3699 g_Map_ResetFlag(FLAG_RED);
3700 g_Map_ResetFlag(FLAG_BLUE);
3701 // CTF, à ôëàãîâ íåò:
3702 if not g_Map_HaveFlagPoints() then
3703 g_SimpleError(_lc[I_GAME_ERROR_CTF]);
3704 end;
3705 end
3706 else
3707 begin
3708 gState := STATE_MENU;
3709 gGameOn := False;
3710 end;
3712 gExit := 0;
3713 gPause := False;
3714 gTime := 0;
3715 NetTimeToUpdate := 1;
3716 NetTimeToReliable := 0;
3717 NetTimeToMaster := NetMasterRate;
3718 gLMSRespawn := LMS_RESPAWN_NONE;
3719 gLMSRespawnTime := 0;
3720 gMissionFailed := False;
3721 gNextMap := '';
3723 gCoopMonstersKilled := 0;
3724 gCoopSecretsFound := 0;
3726 gVoteInProgress := False;
3727 gVotePassed := False;
3728 gVoteCount := 0;
3729 gVoted := False;
3731 gStatsOff := False;
3733 if not gGameOn then Exit;
3735 g_Game_SpectateCenterView();
3737 if (gGameSettings.MaxLives > 0) and (gGameSettings.WarmupTime > 0) then
3738 begin
3739 gLMSRespawn := LMS_RESPAWN_WARMUP;
3740 gLMSRespawnTime := gTime + gGameSettings.WarmupTime*1000;
3741 gLMSSoftSpawn := True;
3742 if NetMode = NET_SERVER then
3743 MH_SEND_GameEvent(NET_EV_LMS_WARMUP, (gLMSRespawnTime - gTime) div 1000)
3744 else
3745 g_Console_Add(Format(_lc[I_MSG_WARMUP_START], [(gLMSRespawnTime - gTime) div 1000]), True);
3746 end;
3748 if NetMode = NET_SERVER then
3749 begin
3750 MH_SEND_GameEvent(NET_EV_MAPSTART, gGameSettings.GameMode, Map);
3752 // Ìàñòåðñåðâåð
3753 if NetUseMaster then
3754 begin
3755 if (NetMHost = nil) or (NetMPeer = nil) then
3756 if not g_Net_Slist_Connect then
3757 g_Console_Add(_lc[I_NET_MSG_ERROR] + _lc[I_NET_SLIST_ERROR]);
3759 g_Net_Slist_Update;
3760 end;
3762 if NetClients <> nil then
3763 for I := 0 to High(NetClients) do
3764 if NetClients[I].Used then
3765 begin
3766 NetClients[I].Voted := False;
3767 if NetClients[I].RequestedFullUpdate then
3768 begin
3769 MH_SEND_Everything((NetClients[I].State = NET_STATE_AUTH), I);
3770 NetClients[I].RequestedFullUpdate := False;
3771 end;
3772 end;
3774 g_Net_UnbanNonPermHosts();
3775 end;
3777 if gLastMap then
3778 begin
3779 gCoopTotalMonstersKilled := 0;
3780 gCoopTotalSecretsFound := 0;
3781 gCoopTotalMonsters := 0;
3782 gCoopTotalSecrets := 0;
3783 gLastMap := False;
3784 end;
3786 g_Game_ExecuteEvent('onmapstart');
3787 end;
3789 procedure SetFirstLevel();
3790 begin
3791 gNextMap := '';
3793 MapList := g_Map_GetMapsList(MapsDir + gGameSettings.WAD);
3794 if MapList = nil then
3795 Exit;
3797 SortSArray(MapList);
3798 gNextMap := MapList[Low(MapList)];
3800 MapList := nil;
3801 end;
3803 procedure g_Game_ExitLevel(Map: Char16);
3804 begin
3805 gNextMap := Map;
3807 gCoopTotalMonstersKilled := gCoopTotalMonstersKilled + gCoopMonstersKilled;
3808 gCoopTotalSecretsFound := gCoopTotalSecretsFound + gCoopSecretsFound;
3809 gCoopTotalMonsters := gCoopTotalMonsters + gTotalMonsters;
3810 gCoopTotalSecrets := gCoopTotalSecrets + gSecretsCount;
3812 // Âûøëè â âûõîä â Îäèíî÷íîé èãðå:
3813 if gGameSettings.GameType = GT_SINGLE then
3814 gExit := EXIT_ENDLEVELSINGLE
3815 else // Âûøëè â âûõîä â Ñâîåé èãðå
3816 begin
3817 gExit := EXIT_ENDLEVELCUSTOM;
3818 if gGameSettings.GameMode = GM_COOP then
3819 g_Player_RememberAll;
3821 if not g_Map_Exist(MapsDir + gGameSettings.WAD + ':\' + gNextMap) then
3822 begin
3823 gLastMap := True;
3824 if gGameSettings.GameMode = GM_COOP then
3825 gStatsOff := True;
3827 gStatsPressed := True;
3828 gNextMap := 'MAP01';
3830 if not g_Map_Exist(MapsDir + gGameSettings.WAD + ':\' + gNextMap) then
3831 g_Game_NextLevel;
3833 if g_Game_IsNet then
3834 begin
3835 MH_SEND_GameStats();
3836 MH_SEND_CoopStats();
3837 end;
3838 end;
3839 end;
3840 end;
3842 procedure g_Game_RestartLevel();
3843 var
3844 Map: string;
3845 begin
3846 if gGameSettings.GameMode = GM_SINGLE then
3847 begin
3848 g_Game_Restart();
3849 Exit;
3850 end;
3851 gExit := EXIT_ENDLEVELCUSTOM;
3852 g_ProcessResourceStr(gMapInfo.Map, nil, nil, @Map);
3853 gNextMap := Map;
3854 end;
3856 procedure g_Game_ClientWAD(NewWAD: String; WHash: TMD5Digest);
3857 var
3858 gWAD: String;
3859 begin
3860 if LowerCase(NewWAD) = LowerCase(gGameSettings.WAD) then
3861 Exit;
3862 if not g_Game_IsClient then
3863 Exit;
3864 gWAD := g_Res_SearchSameWAD(MapsDir, ExtractFileName(NewWAD), WHash);
3865 if gWAD = '' then
3866 begin
3867 g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
3868 gWAD := g_Res_DownloadWAD(ExtractFileName(NewWAD));
3869 if gWAD = '' then
3870 begin
3871 g_Game_Free();
3872 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_WAD], [ExtractFileName(NewWAD)]));
3873 Exit;
3874 end;
3875 end;
3876 NewWAD := ExtractRelativePath(MapsDir, gWAD);
3877 g_Game_LoadWAD(NewWAD);
3878 end;
3880 procedure g_Game_RestartRound(NoMapRestart: Boolean = False);
3881 var
3882 i, n, nb, nr: Integer;
3883 begin
3884 if not g_Game_IsServer then Exit;
3885 if gLMSRespawn = LMS_RESPAWN_NONE then Exit;
3886 gLMSRespawn := LMS_RESPAWN_NONE;
3887 gLMSRespawnTime := 0;
3888 MessageTime := 0;
3890 if (gGameSettings.GameMode = GM_COOP) and not NoMapRestart then
3891 begin
3892 gMissionFailed := True;
3893 g_Game_RestartLevel;
3894 Exit;
3895 end;
3897 n := 0; nb := 0; nr := 0;
3898 for i := Low(gPlayers) to High(gPlayers) do
3899 if (gPlayers[i] <> nil) and
3900 ((not gPlayers[i].FSpectator) or gPlayers[i].FWantsInGame or
3901 (gPlayers[i] is TBot)) then
3902 begin
3903 Inc(n);
3904 if gPlayers[i].Team = TEAM_RED then Inc(nr)
3905 else if gPlayers[i].Team = TEAM_BLUE then Inc(nb)
3906 end;
3908 if (n < 2) or ((gGameSettings.GameMode = GM_TDM) and ((nr = 0) or (nb = 0))) then
3909 begin
3910 // wait a second until the fuckers finally decide to join
3911 gLMSRespawn := LMS_RESPAWN_WARMUP;
3912 gLMSRespawnTime := gTime + 1000;
3913 gLMSSoftSpawn := NoMapRestart;
3914 Exit;
3915 end;
3917 g_Player_RemoveAllCorpses;
3918 g_Game_Message(_lc[I_MESSAGE_LMS_START], 144);
3919 if g_Game_IsNet then
3920 MH_SEND_GameEvent(NET_EV_LMS_START);
3922 for i := Low(gPlayers) to High(gPlayers) do
3923 begin
3924 if gPlayers[i] = nil then continue;
3925 if gPlayers[i] is TBot then gPlayers[i].FWantsInGame := True;
3926 // don't touch normal spectators
3927 if gPlayers[i].FSpectator and not gPlayers[i].FWantsInGame then
3928 begin
3929 gPlayers[i].FNoRespawn := True;
3930 gPlayers[i].Lives := 0;
3931 if g_Game_IsNet then
3932 MH_SEND_PlayerStats(gPlayers[I].UID);
3933 continue;
3934 end;
3935 gPlayers[i].FNoRespawn := False;
3936 gPlayers[i].Lives := gGameSettings.MaxLives;
3937 gPlayers[i].Respawn(False, True);
3938 if gGameSettings.GameMode = GM_COOP then
3939 begin
3940 gPlayers[i].Frags := 0;
3941 gPlayers[i].RecallState;
3942 end;
3943 if (gPlayer1 = nil) and (gLMSPID1 > 0) then
3944 gPlayer1 := g_Player_Get(gLMSPID1);
3945 if (gPlayer2 = nil) and (gLMSPID2 > 0) then
3946 gPlayer2 := g_Player_Get(gLMSPID2);
3947 end;
3949 for i := Low(gItems) to High(gItems) do
3950 begin
3951 if gItems[i].Respawnable then
3952 begin
3953 gItems[i].QuietRespawn := True;
3954 gItems[i].RespawnTime := 0;
3955 end
3956 else
3957 begin
3958 g_Items_Remove(i);
3959 if g_Game_IsNet then MH_SEND_ItemDestroy(True, i);
3960 end;
3961 end;
3963 for i := Low(gMonsters) to High(gMonsters) do
3964 begin
3965 if (gMonsters[i] <> nil) and not gMonsters[i].FNoRespawn then
3966 gMonsters[i].Respawn;
3967 end;
3969 gLMSSoftSpawn := False;
3970 end;
3972 function g_Game_GetFirstMap(WAD: String): String;
3973 begin
3974 Result := '';
3976 MapList := g_Map_GetMapsList(WAD);
3977 if MapList = nil then
3978 Exit;
3980 SortSArray(MapList);
3981 Result := MapList[Low(MapList)];
3983 if not g_Map_Exist(WAD + ':\' + Result) then
3984 Result := '';
3986 MapList := nil;
3987 end;
3989 function g_Game_GetNextMap(): String;
3990 var
3991 I: Integer;
3992 Map: string;
3993 begin
3994 Result := '';
3996 MapList := g_Map_GetMapsList(MapsDir + gGameSettings.WAD);
3997 if MapList = nil then
3998 Exit;
4000 g_ProcessResourceStr(gMapInfo.Map, nil, nil, @Map);
4002 SortSArray(MapList);
4003 MapIndex := -255;
4004 for I := Low(MapList) to High(MapList) do
4005 if Map = MapList[I] then
4006 begin
4007 MapIndex := I;
4008 Break;
4009 end;
4011 if MapIndex <> -255 then
4012 begin
4013 if MapIndex = High(MapList) then
4014 Result := MapList[Low(MapList)]
4015 else
4016 Result := MapList[MapIndex + 1];
4018 if not g_Map_Exist(MapsDir + gGameSettings.WAD + ':\' + Result) then Result := Map;
4019 end;
4021 MapList := nil;
4022 end;
4024 procedure g_Game_NextLevel();
4025 begin
4026 if gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF, GM_COOP] then
4027 gExit := EXIT_ENDLEVELCUSTOM
4028 else
4029 begin
4030 gExit := EXIT_ENDLEVELSINGLE;
4031 Exit;
4032 end;
4034 if gNextMap <> '' then Exit;
4035 gNextMap := g_Game_GetNextMap();
4036 end;
4038 function g_Game_IsTestMap(): Boolean;
4039 var
4040 FName, Sect, Res: String;
4041 begin
4042 g_ProcessResourceStr(gMapInfo.Map, FName, Sect, Res);
4043 Result := UpperCase(Res) = TEST_MAP_NAME;
4044 end;
4046 procedure g_Game_DeleteTestMap();
4047 var
4048 WAD: TWADEditor_1;
4049 MapName: Char16;
4050 MapList: SArray;
4051 a, time: Integer;
4052 WadName: string;
4053 begin
4054 a := Pos('.wad:\', gMapToDelete);
4055 if a = 0 then
4056 Exit;
4058 // Âûäåëÿåì èìÿ wad-ôàéëà è èìÿ êàðòû:
4059 WadName := Copy(gMapToDelete, 1, a + 3);
4060 Delete(gMapToDelete, 1, a + 5);
4061 gMapToDelete := UpperCase(gMapToDelete);
4062 MapName := '';
4063 CopyMemory(@MapName[0], @gMapToDelete[1], Min(16, Length(gMapToDelete)));
4065 // Èìÿ êàðòû íå ñòàíäàðòíîå òåñòîâîå:
4066 if MapName <> TEST_MAP_NAME then
4067 Exit;
4069 if not gTempDelete then
4070 begin
4071 time := g_GetFileTime(WadName);
4072 WAD := TWADEditor_1.Create();
4074 // ×èòàåì Wad-ôàéë:
4075 if not WAD.ReadFile(WadName) then
4076 begin // Íåò òàêîãî WAD-ôàéëà
4077 WAD.Free();
4078 Exit;
4079 end;
4081 // Ñîñòàâëÿåì ñïèñîê êàðò è èùåì íóæíóþ:
4082 WAD.CreateImage();
4083 MapList := WAD.GetResourcesList('');
4085 if MapList <> nil then
4086 for a := 0 to High(MapList) do
4087 if MapList[a] = MapName then
4088 begin
4089 // Óäàëÿåì è ñîõðàíÿåì:
4090 WAD.RemoveResource('', MapName);
4091 WAD.SaveTo(WadName);
4092 Break;
4093 end;
4095 WAD.Free();
4096 g_SetFileTime(WadName, time);
4097 end else
4098 DeleteFile(WadName);
4099 end;
4101 procedure GameCVars(P: SArray);
4102 var
4103 a, b: Integer;
4104 stat: TPlayerStatArray;
4105 cmd, s: string;
4106 config: TConfig;
4107 begin
4108 stat := nil;
4109 cmd := LowerCase(P[0]);
4110 if cmd = 'r_showfps' then
4111 begin
4112 if (Length(P) > 1) and
4113 ((P[1] = '1') or (P[1] = '0')) then
4114 gShowFPS := (P[1][1] = '1');
4116 if gShowFPS then
4117 g_Console_Add(_lc[I_MSG_SHOW_FPS_ON])
4118 else
4119 g_Console_Add(_lc[I_MSG_SHOW_FPS_OFF]);
4120 end
4121 else if (cmd = 'g_friendlyfire') and not g_Game_IsClient then
4122 begin
4123 with gGameSettings do
4124 begin
4125 if (Length(P) > 1) and
4126 ((P[1] = '1') or (P[1] = '0')) then
4127 begin
4128 if (P[1][1] = '1') then
4129 Options := Options or GAME_OPTION_TEAMDAMAGE
4130 else
4131 Options := Options and (not GAME_OPTION_TEAMDAMAGE);
4132 end;
4134 if (LongBool(Options and GAME_OPTION_TEAMDAMAGE)) then
4135 g_Console_Add(_lc[I_MSG_FRIENDLY_FIRE_ON])
4136 else
4137 g_Console_Add(_lc[I_MSG_FRIENDLY_FIRE_OFF]);
4139 if g_Game_IsNet then MH_SEND_GameSettings;
4140 end;
4141 end
4142 else if (cmd = 'g_weaponstay') and not g_Game_IsClient then
4143 begin
4144 with gGameSettings do
4145 begin
4146 if (Length(P) > 1) and
4147 ((P[1] = '1') or (P[1] = '0')) then
4148 begin
4149 if (P[1][1] = '1') then
4150 Options := Options or GAME_OPTION_WEAPONSTAY
4151 else
4152 Options := Options and (not GAME_OPTION_WEAPONSTAY);
4153 end;
4155 if (LongBool(Options and GAME_OPTION_WEAPONSTAY)) then
4156 g_Console_Add(_lc[I_MSG_WEAPONSTAY_ON])
4157 else
4158 g_Console_Add(_lc[I_MSG_WEAPONSTAY_OFF]);
4160 if g_Game_IsNet then MH_SEND_GameSettings;
4161 end;
4162 end
4163 else if cmd = 'g_gamemode' then
4164 begin
4165 a := g_Game_TextToMode(P[1]);
4166 if a = GM_SINGLE then a := GM_COOP;
4167 if (Length(P) > 1) and (a <> GM_NONE) and (not g_Game_IsClient) then
4168 begin
4169 gSwitchGameMode := a;
4170 if (gGameOn and (gGameSettings.GameMode = GM_SINGLE)) or
4171 (gState = STATE_INTERSINGLE) then
4172 gSwitchGameMode := GM_SINGLE;
4173 if not gGameOn then
4174 gGameSettings.GameMode := gSwitchGameMode;
4175 end;
4176 if gSwitchGameMode = gGameSettings.GameMode then
4177 g_Console_Add(Format(_lc[I_MSG_GAMEMODE_CURRENT],
4178 [g_Game_ModeToText(gGameSettings.GameMode)]))
4179 else
4180 g_Console_Add(Format(_lc[I_MSG_GAMEMODE_CHANGE],
4181 [g_Game_ModeToText(gGameSettings.GameMode),
4182 g_Game_ModeToText(gSwitchGameMode)]));
4183 end
4184 else if (cmd = 'g_allow_exit') and not g_Game_IsClient then
4185 begin
4186 with gGameSettings do
4187 begin
4188 if (Length(P) > 1) and
4189 ((P[1] = '1') or (P[1] = '0')) then
4190 begin
4191 if (P[1][1] = '1') then
4192 Options := Options or GAME_OPTION_ALLOWEXIT
4193 else
4194 Options := Options and (not GAME_OPTION_ALLOWEXIT);
4195 end;
4197 if (LongBool(Options and GAME_OPTION_ALLOWEXIT)) then
4198 g_Console_Add(_lc[I_MSG_ALLOWEXIT_ON])
4199 else
4200 g_Console_Add(_lc[I_MSG_ALLOWEXIT_OFF]);
4201 g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
4203 if g_Game_IsNet then MH_SEND_GameSettings;
4204 end;
4205 end
4206 else if (cmd = 'g_allow_monsters') and not g_Game_IsClient then
4207 begin
4208 with gGameSettings do
4209 begin
4210 if (Length(P) > 1) and
4211 ((P[1] = '1') or (P[1] = '0')) then
4212 begin
4213 if (P[1][1] = '1') then
4214 Options := Options or GAME_OPTION_MONSTERS
4215 else
4216 Options := Options and (not GAME_OPTION_MONSTERS);
4217 end;
4219 if (LongBool(Options and GAME_OPTION_MONSTERS)) then
4220 g_Console_Add(_lc[I_MSG_ALLOWMON_ON])
4221 else
4222 g_Console_Add(_lc[I_MSG_ALLOWMON_OFF]);
4223 g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
4225 if g_Game_IsNet then MH_SEND_GameSettings;
4226 end;
4227 end
4228 else if (cmd = 'g_bot_vsplayers') and not g_Game_IsClient then
4229 begin
4230 with gGameSettings do
4231 begin
4232 if (Length(P) > 1) and
4233 ((P[1] = '1') or (P[1] = '0')) then
4234 begin
4235 if (P[1][1] = '1') then
4236 Options := Options or GAME_OPTION_BOTVSPLAYER
4237 else
4238 Options := Options and (not GAME_OPTION_BOTVSPLAYER);
4239 end;
4241 if (LongBool(Options and GAME_OPTION_BOTVSPLAYER)) then
4242 g_Console_Add(_lc[I_MSG_BOTSVSPLAYERS_ON])
4243 else
4244 g_Console_Add(_lc[I_MSG_BOTSVSPLAYERS_OFF]);
4246 if g_Game_IsNet then MH_SEND_GameSettings;
4247 end;
4248 end
4249 else if (cmd = 'g_bot_vsmonsters') and not g_Game_IsClient then
4250 begin
4251 with gGameSettings do
4252 begin
4253 if (Length(P) > 1) and
4254 ((P[1] = '1') or (P[1] = '0')) then
4255 begin
4256 if (P[1][1] = '1') then
4257 Options := Options or GAME_OPTION_BOTVSMONSTER
4258 else
4259 Options := Options and (not GAME_OPTION_BOTVSMONSTER);
4260 end;
4262 if (LongBool(Options and GAME_OPTION_BOTVSMONSTER)) then
4263 g_Console_Add(_lc[I_MSG_BOTSVSMONSTERS_ON])
4264 else
4265 g_Console_Add(_lc[I_MSG_BOTSVSMONSTERS_OFF]);
4267 if g_Game_IsNet then MH_SEND_GameSettings;
4268 end;
4269 end
4270 else if (cmd = 'g_warmuptime') and not g_Game_IsClient then
4271 begin
4272 if Length(P) > 1 then
4273 begin
4274 if StrToIntDef(P[1], gGameSettings.WarmupTime) = 0 then
4275 gGameSettings.WarmupTime := 30
4276 else
4277 gGameSettings.WarmupTime := StrToIntDef(P[1], gGameSettings.WarmupTime);
4278 end;
4280 g_Console_Add(Format(_lc[I_MSG_WARMUP],
4281 [gGameSettings.WarmupTime]));
4282 g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
4283 end
4284 else if cmd = 'net_interp' then
4285 begin
4286 if (Length(P) > 1) then
4287 NetInterpLevel := StrToIntDef(P[1], NetInterpLevel);
4289 g_Console_Add('net_interp = ' + IntToStr(NetInterpLevel));
4290 config := TConfig.CreateFile(GameDir+'/'+CONFIG_FILENAME);
4291 config.WriteInt('Client', 'InterpolationSteps', NetInterpLevel);
4292 config.SaveFile(GameDir+'/'+CONFIG_FILENAME);
4293 config.Free();
4294 end
4295 else if cmd = 'net_forceplayerupdate' then
4296 begin
4297 if (Length(P) > 1) and
4298 ((P[1] = '1') or (P[1] = '0')) then
4299 NetForcePlayerUpdate := (P[1][1] = '1');
4301 if NetForcePlayerUpdate then
4302 g_Console_Add('net_forceplayerupdate = 1')
4303 else
4304 g_Console_Add('net_forceplayerupdate = 0');
4305 config := TConfig.CreateFile(GameDir+'/'+CONFIG_FILENAME);
4306 config.WriteBool('Client', 'ForcePlayerUpdate', NetForcePlayerUpdate);
4307 config.SaveFile(GameDir+'/'+CONFIG_FILENAME);
4308 config.Free();
4309 end
4310 else if cmd = 'net_predictself' then
4311 begin
4312 if (Length(P) > 1) and
4313 ((P[1] = '1') or (P[1] = '0')) then
4314 NetPredictSelf := (P[1][1] = '1');
4316 if NetPredictSelf then
4317 g_Console_Add('net_predictself = 1')
4318 else
4319 g_Console_Add('net_predictself = 0');
4320 config := TConfig.CreateFile(GameDir+'/'+CONFIG_FILENAME);
4321 config.WriteBool('Client', 'PredictSelf', NetPredictSelf);
4322 config.SaveFile(GameDir+'/'+CONFIG_FILENAME);
4323 config.Free();
4324 end
4325 else if cmd = 'sv_name' then
4326 begin
4327 if (Length(P) > 1) and (Length(P[1]) > 0) then
4328 begin
4329 NetServerName := P[1];
4330 if Length(NetServerName) > 64 then
4331 SetLength(NetServerName, 64);
4332 if g_Game_IsServer and g_Game_IsNet and NetUseMaster then
4333 g_Net_Slist_Update;
4334 end;
4336 g_Console_Add(cmd + ' = "' + NetServerName + '"');
4337 end
4338 else if cmd = 'sv_passwd' then
4339 begin
4340 if (Length(P) > 1) and (Length(P[1]) > 0) then
4341 begin
4342 NetPassword := P[1];
4343 if Length(NetPassword) > 24 then
4344 SetLength(NetPassword, 24);
4345 if g_Game_IsServer and g_Game_IsNet and NetUseMaster then
4346 g_Net_Slist_Update;
4347 end;
4349 g_Console_Add(cmd + ' = "' + AnsiLowerCase(NetPassword) + '"');
4350 end
4351 else if cmd = 'sv_maxplrs' then
4352 begin
4353 if (Length(P) > 1) then
4354 begin
4355 NetMaxClients := Min(Max(StrToIntDef(P[1], NetMaxClients), 1), NET_MAXCLIENTS);
4356 if g_Game_IsServer and g_Game_IsNet then
4357 begin
4358 b := 0;
4359 for a := 0 to High(NetClients) do
4360 if NetClients[a].Used then
4361 begin
4362 Inc(b);
4363 if b > NetMaxClients then
4364 begin
4365 s := g_Player_Get(NetClients[a].Player).Name;
4366 enet_peer_disconnect(NetClients[a].Peer, NET_DISC_FULL);
4367 g_Console_Add(Format(_lc[I_PLAYER_KICK], [s]));
4368 MH_SEND_GameEvent(NET_EV_PLAYER_KICK, 0, s);
4369 end;
4370 end;
4371 if NetUseMaster then
4372 g_Net_Slist_Update;
4373 end;
4374 end;
4376 g_Console_Add(cmd + ' = ' + IntToStr(NetMaxClients));
4377 end
4378 else if cmd = 'sv_public' then
4379 begin
4380 if (Length(P) > 1) then
4381 begin
4382 NetUseMaster := StrToIntDef(P[1], Byte(NetUseMaster)) > 0;
4383 if g_Game_IsServer and g_Game_IsNet then
4384 if NetUseMaster then
4385 begin
4386 if NetMPeer = nil then
4387 if not g_Net_Slist_Connect() then
4388 g_Console_Add(_lc[I_NET_MSG_ERROR] + _lc[I_NET_SLIST_ERROR]);
4389 g_Net_Slist_Update();
4390 end
4391 else
4392 if NetMPeer <> nil then
4393 g_Net_Slist_Disconnect();
4394 end;
4396 g_Console_Add(cmd + ' = ' + IntToStr(Byte(NetUseMaster)));
4397 end
4398 else if cmd = 'sv_intertime' then
4399 begin
4400 if (Length(P) > 1) then
4401 gDefInterTime := Min(Max(StrToIntDef(P[1], gDefInterTime), -1), 120);
4403 g_Console_Add(cmd + ' = ' + IntToStr(gDefInterTime));
4404 end
4405 else if cmd = 'p1_name' then
4406 begin
4407 if (Length(P) > 1) and gGameOn then
4408 begin
4409 if g_Game_IsClient then
4410 begin
4411 gPlayer1Settings.Name := b_Text_Unformat(P[1]);
4412 MC_SEND_PlayerSettings;
4413 end
4414 else
4415 if gPlayer1 <> nil then
4416 begin
4417 gPlayer1.Name := b_Text_Unformat(P[1]);
4418 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer1.UID);
4419 end
4420 else
4421 gPlayer1Settings.Name := b_Text_Unformat(P[1]);
4422 end;
4423 end
4424 else if cmd = 'p2_name' then
4425 begin
4426 if (Length(P) > 1) and gGameOn then
4427 begin
4428 if g_Game_IsClient then
4429 begin
4430 gPlayer2Settings.Name := b_Text_Unformat(P[1]);
4431 MC_SEND_PlayerSettings;
4432 end
4433 else
4434 if gPlayer2 <> nil then
4435 begin
4436 gPlayer2.Name := b_Text_Unformat(P[1]);
4437 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer2.UID);
4438 end
4439 else
4440 gPlayer2Settings.Name := b_Text_Unformat(P[1]);
4441 end;
4442 end
4443 else if cmd = 'p1_color' then
4444 begin
4445 if Length(P) > 3 then
4446 if g_Game_IsClient then
4447 begin
4448 gPlayer1Settings.Color := _RGB(EnsureRange(StrToIntDef(P[1], 0), 0, 255),
4449 EnsureRange(StrToIntDef(P[2], 0), 0, 255),
4450 EnsureRange(StrToIntDef(P[3], 0), 0, 255));
4451 MC_SEND_PlayerSettings;
4452 end
4453 else
4454 if gPlayer1 <> nil then
4455 begin
4456 gPlayer1.Model.SetColor(EnsureRange(StrToIntDef(P[1], 0), 0, 255),
4457 EnsureRange(StrToIntDef(P[2], 0), 0, 255),
4458 EnsureRange(StrToIntDef(P[3], 0), 0, 255));
4459 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer1.UID);
4460 end
4461 else
4462 gPlayer1Settings.Color := _RGB(EnsureRange(StrToIntDef(P[1], 0), 0, 255),
4463 EnsureRange(StrToIntDef(P[2], 0), 0, 255),
4464 EnsureRange(StrToIntDef(P[3], 0), 0, 255));
4465 end
4466 else if (cmd = 'p2_color') and not g_Game_IsNet then
4467 begin
4468 if Length(P) > 3 then
4469 if g_Game_IsClient then
4470 begin
4471 gPlayer2Settings.Color := _RGB(EnsureRange(StrToIntDef(P[1], 0), 0, 255),
4472 EnsureRange(StrToIntDef(P[2], 0), 0, 255),
4473 EnsureRange(StrToIntDef(P[3], 0), 0, 255));
4474 MC_SEND_PlayerSettings;
4475 end
4476 else
4477 if gPlayer2 <> nil then
4478 begin
4479 gPlayer2.Model.SetColor(EnsureRange(StrToIntDef(P[1], 0), 0, 255),
4480 EnsureRange(StrToIntDef(P[2], 0), 0, 255),
4481 EnsureRange(StrToIntDef(P[3], 0), 0, 255));
4482 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer2.UID);
4483 end
4484 else
4485 gPlayer2Settings.Color := _RGB(EnsureRange(StrToIntDef(P[1], 0), 0, 255),
4486 EnsureRange(StrToIntDef(P[2], 0), 0, 255),
4487 EnsureRange(StrToIntDef(P[3], 0), 0, 255));
4488 end
4489 else if gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT] then
4490 begin
4491 if cmd = 'r_showtime' then
4492 begin
4493 if (Length(P) > 1) and
4494 ((P[1] = '1') or (P[1] = '0')) then
4495 gShowTime := (P[1][1] = '1');
4497 if gShowTime then
4498 g_Console_Add(_lc[I_MSG_TIME_ON])
4499 else
4500 g_Console_Add(_lc[I_MSG_TIME_OFF]);
4501 end
4502 else if cmd = 'r_showscore' then
4503 begin
4504 if (Length(P) > 1) and
4505 ((P[1] = '1') or (P[1] = '0')) then
4506 gShowGoals := (P[1][1] = '1');
4508 if gShowGoals then
4509 g_Console_Add(_lc[I_MSG_SCORE_ON])
4510 else
4511 g_Console_Add(_lc[I_MSG_SCORE_OFF]);
4512 end
4513 else if cmd = 'r_showstat' then
4514 begin
4515 if (Length(P) > 1) and
4516 ((P[1] = '1') or (P[1] = '0')) then
4517 gShowStat := (P[1][1] = '1');
4519 if gShowStat then
4520 g_Console_Add(_lc[I_MSG_STATS_ON])
4521 else
4522 g_Console_Add(_lc[I_MSG_STATS_OFF]);
4523 end
4524 else if cmd = 'r_showkillmsg' then
4525 begin
4526 if (Length(P) > 1) and
4527 ((P[1] = '1') or (P[1] = '0')) then
4528 gShowKillMsg := (P[1][1] = '1');
4530 if gShowKillMsg then
4531 g_Console_Add(_lc[I_MSG_KILL_MSGS_ON])
4532 else
4533 g_Console_Add(_lc[I_MSG_KILL_MSGS_OFF]);
4534 end
4535 else if cmd = 'r_showlives' then
4536 begin
4537 if (Length(P) > 1) and
4538 ((P[1] = '1') or (P[1] = '0')) then
4539 gShowLives := (P[1][1] = '1');
4541 if gShowLives then
4542 g_Console_Add(_lc[I_MSG_LIVES_ON])
4543 else
4544 g_Console_Add(_lc[I_MSG_LIVES_OFF]);
4545 end
4546 else if cmd = 'r_showspect' then
4547 begin
4548 if (Length(P) > 1) and
4549 ((P[1] = '1') or (P[1] = '0')) then
4550 gSpectHUD := (P[1][1] = '1');
4552 if gSpectHUD then
4553 g_Console_Add(_lc[I_MSG_SPECT_HUD_ON])
4554 else
4555 g_Console_Add(_lc[I_MSG_SPECT_HUD_OFF]);
4556 end
4557 else if cmd = 'r_showping' then
4558 begin
4559 if (Length(P) > 1) and
4560 ((P[1] = '1') or (P[1] = '0')) then
4561 gShowPing := (P[1][1] = '1');
4563 if gShowPing then
4564 g_Console_Add(_lc[I_MSG_PING_ON])
4565 else
4566 g_Console_Add(_lc[I_MSG_PING_OFF]);
4567 end
4568 else if (cmd = 'g_scorelimit') and not g_Game_IsClient then
4569 begin
4570 if Length(P) > 1 then
4571 begin
4572 if StrToIntDef(P[1], gGameSettings.GoalLimit) = 0 then
4573 gGameSettings.GoalLimit := 0
4574 else
4575 begin
4576 b := 0;
4578 if gGameSettings.GameMode = GM_DM then
4579 begin // DM
4580 stat := g_Player_GetStats();
4581 if stat <> nil then
4582 for a := 0 to High(stat) do
4583 if stat[a].Frags > b then
4584 b := stat[a].Frags;
4585 end
4586 else // TDM/CTF
4587 b := Max(gTeamStat[TEAM_RED].Goals, gTeamStat[TEAM_BLUE].Goals);
4589 gGameSettings.GoalLimit := Max(StrToIntDef(P[1], gGameSettings.GoalLimit), b);
4590 end;
4592 if g_Game_IsNet then MH_SEND_GameSettings;
4593 end;
4595 g_Console_Add(Format(_lc[I_MSG_SCORE_LIMIT], [gGameSettings.GoalLimit]));
4596 end
4597 else if (cmd = 'g_timelimit') and not g_Game_IsClient then
4598 begin
4599 if (Length(P) > 1) and (StrToIntDef(P[1], -1) >= 0) then
4600 gGameSettings.TimeLimit := StrToIntDef(P[1], -1);
4602 g_Console_Add(Format(_lc[I_MSG_TIME_LIMIT],
4603 [gGameSettings.TimeLimit div 3600,
4604 (gGameSettings.TimeLimit div 60) mod 60,
4605 gGameSettings.TimeLimit mod 60]));
4606 if g_Game_IsNet then MH_SEND_GameSettings;
4607 end
4608 else if (cmd = 'g_maxlives') and not g_Game_IsClient then
4609 begin
4610 if Length(P) > 1 then
4611 begin
4612 if StrToIntDef(P[1], gGameSettings.MaxLives) = 0 then
4613 gGameSettings.MaxLives := 0
4614 else
4615 begin
4616 b := 0;
4617 stat := g_Player_GetStats();
4618 if stat <> nil then
4619 for a := 0 to High(stat) do
4620 if stat[a].Lives > b then
4621 b := stat[a].Lives;
4622 gGameSettings.MaxLives :=
4623 Max(StrToIntDef(P[1], gGameSettings.MaxLives), b);
4624 end;
4625 end;
4627 g_Console_Add(Format(_lc[I_MSG_LIVES],
4628 [gGameSettings.MaxLives]));
4629 if g_Game_IsNet then MH_SEND_GameSettings;
4630 end;
4631 end;
4632 end;
4634 procedure DebugCommands(P: SArray);
4635 var
4636 a, b: Integer;
4637 cmd: string;
4638 //pt: TPoint;
4639 begin
4640 // Êîìàíäû îòëàäî÷íîãî ðåæèìà:
4641 if gDebugMode then
4642 begin
4643 cmd := LowerCase(P[0]);
4644 if cmd = 'd_window' then
4645 begin
4646 g_Console_Add(Format('gWinPosX = %d, gWinPosY %d', [gWinPosX, gWinPosY]));
4647 g_Console_Add(Format('gWinRealPosX = %d, gWinRealPosY %d', [gWinRealPosX, gWinRealPosY]));
4648 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth, gScreenHeight]));
4649 g_Console_Add(Format('gWinSizeX = %d, gWinSizeY = %d', [gWinSizeX, gWinSizeY]));
4650 g_Console_Add(Format('Frame X = %d, Y = %d, Caption Y = %d', [gWinFrameX, gWinFrameY, gWinCaption]));
4651 end
4652 else if cmd = 'd_sounds' then
4653 begin
4654 if (Length(P) > 1) and
4655 ((P[1] = '1') or (P[1] = '0')) then
4656 g_Debug_Sounds := (P[1][1] = '1');
4658 g_Console_Add(Format('d_sounds is %d', [Byte(g_Debug_Sounds)]));
4659 end
4660 else if cmd = 'd_frames' then
4661 begin
4662 if (Length(P) > 1) and
4663 ((P[1] = '1') or (P[1] = '0')) then
4664 g_Debug_Frames := (P[1][1] = '1');
4666 g_Console_Add(Format('d_frames is %d', [Byte(g_Debug_Frames)]));
4667 end
4668 else if cmd = 'd_winmsg' then
4669 begin
4670 if (Length(P) > 1) and
4671 ((P[1] = '1') or (P[1] = '0')) then
4672 g_Debug_WinMsgs := (P[1][1] = '1');
4674 g_Console_Add(Format('d_winmsg is %d', [Byte(g_Debug_WinMsgs)]));
4675 end
4676 else if (cmd = 'd_monoff') and not g_Game_IsNet then
4677 begin
4678 if (Length(P) > 1) and
4679 ((P[1] = '1') or (P[1] = '0')) then
4680 g_Debug_MonsterOff := (P[1][1] = '1');
4682 g_Console_Add(Format('d_monoff is %d', [Byte(g_debug_MonsterOff)]));
4683 end
4684 else if (cmd = 'd_botoff') and not g_Game_IsNet then
4685 begin
4686 if Length(P) > 1 then
4687 case P[1][1] of
4688 '0': g_debug_BotAIOff := 0;
4689 '1': g_debug_BotAIOff := 1;
4690 '2': g_debug_BotAIOff := 2;
4691 '3': g_debug_BotAIOff := 3;
4692 end;
4694 g_Console_Add(Format('d_botoff is %d', [g_debug_BotAIOff]));
4695 end
4696 else if cmd = 'd_monster' then
4697 begin
4698 if gGameOn and (gPlayer1 <> nil) and (gPlayer1.Live) and (not g_Game_IsNet) then
4699 if Length(P) < 2 then
4700 begin
4701 g_Console_Add(cmd + ' [ID | Name] [behaviour]');
4702 g_Console_Add('ID | Name');
4703 for b := MONSTER_DEMON to MONSTER_MAN do
4704 g_Console_Add(Format('%2d | %s', [b, g_Monsters_GetNameByID(b)]));
4705 end else
4706 begin
4707 a := StrToIntDef(P[1], 0);
4708 if (a < MONSTER_DEMON) or (a > MONSTER_MAN) then
4709 a := g_Monsters_GetIDByName(P[1]);
4711 if (a < MONSTER_DEMON) or (a > MONSTER_MAN) then
4712 g_Console_Add(Format(_lc[I_MSG_NO_MONSTER], [P[1]]))
4713 else
4714 begin
4715 with gPlayer1.Obj do
4716 b := g_Monsters_Create(a,
4717 X + Rect.X + (Rect.Width div 2),
4718 Y + Rect.Y + Rect.Height,
4719 gPlayer1.Direction, True);
4720 if (Length(P) > 2) and (b >= 0) then
4721 gMonsters[b].MonsterBehaviour := Min(Max(StrToIntDef(P[2], BH_NORMAL), BH_NORMAL), BH_GOOD);
4722 end;
4723 end;
4724 end
4725 else if (cmd = 'd_health') then
4726 begin
4727 if (Length(P) > 1) and
4728 ((P[1] = '1') or (P[1] = '0')) then
4729 g_debug_HealthBar := (P[1][1] = '1');
4731 g_Console_Add(Format('d_health is %d', [Byte(g_debug_HealthBar)]));
4732 end
4733 else if (cmd = 'd_player') then
4734 begin
4735 if (Length(P) > 1) and
4736 ((P[1] = '1') or (P[1] = '0')) then
4737 g_debug_Player := (P[1][1] = '1');
4739 g_Console_Add(Format(cmd + ' is %d', [Byte(g_Debug_Player)]));
4740 end
4741 else if (cmd = 'd_joy') then
4742 begin
4743 for a := 1 to 8 do
4744 g_Console_Add(e_JoystickStateToString(a));
4745 end;
4746 end
4747 else
4748 g_Console_Add(_lc[I_MSG_NOT_DEBUG]);
4749 end;
4751 procedure GameCommands(P: SArray);
4752 var
4753 a, b: Integer;
4754 s, pw: String;
4755 chstr: string;
4756 cmd: string;
4757 pl: pTNetClient = nil;
4758 plr: TPlayer;
4759 prt: Word;
4760 nm: Boolean;
4761 listen: LongWord;
4762 begin
4763 // Îáùèå êîìàíäû:
4764 cmd := LowerCase(P[0]);
4765 chstr := '';
4766 if (cmd = 'quit') or
4767 (cmd = 'exit') then
4768 begin
4769 g_Game_Free();
4770 g_Game_Quit();
4771 Exit;
4772 end
4773 else if cmd = 'pause' then
4774 begin
4775 if (g_ActiveWindow = nil) then
4776 g_Game_Pause(not gPause);
4777 end
4778 else if cmd = 'endgame' then
4779 gExit := EXIT_SIMPLE
4780 else if cmd = 'restart' then
4781 begin
4782 if gGameOn or (gState in [STATE_INTERSINGLE, STATE_INTERCUSTOM]) then
4783 begin
4784 if g_Game_IsClient then
4785 begin
4786 g_Console_Add(_lc[I_MSG_SERVERONLY]);
4787 Exit;
4788 end;
4789 g_Game_Restart();
4790 end else
4791 g_Console_Add(_lc[I_MSG_NOT_GAME]);
4792 end
4793 else if cmd = 'kick' then
4794 begin
4795 if g_Game_IsServer then
4796 begin
4797 if Length(P) < 2 then
4798 begin
4799 g_Console_Add('kick <name>');
4800 Exit;
4801 end;
4802 if P[1] = '' then
4803 begin
4804 g_Console_Add('kick <name>');
4805 Exit;
4806 end;
4808 if g_Game_IsNet then
4809 pl := g_Net_Client_ByName(P[1]);
4810 if (pl <> nil) then
4811 begin
4812 s := g_Net_ClientName_ByID(pl^.ID);
4813 enet_peer_disconnect(pl^.Peer, NET_DISC_KICK);
4814 g_Console_Add(Format(_lc[I_PLAYER_KICK], [s]));
4815 MH_SEND_GameEvent(NET_EV_PLAYER_KICK, 0, s);
4816 if NetUseMaster then
4817 g_Net_Slist_Update;
4818 end else if gPlayers <> nil then
4819 for a := Low(gPlayers) to High(gPlayers) do
4820 if gPlayers[a] <> nil then
4821 if Copy(LowerCase(gPlayers[a].Name), 1, Length(P[1])) = LowerCase(P[1]) then
4822 begin
4823 // Íå îòêëþ÷àòü îñíîâíûõ èãðîêîâ â ñèíãëå
4824 if not(gPlayers[a] is TBot) and (gGameSettings.GameType = GT_SINGLE) then
4825 continue;
4826 gPlayers[a].Lives := 0;
4827 gPlayers[a].Kill(K_SIMPLEKILL, 0, HIT_DISCON);
4828 g_Console_Add(Format(_lc[I_PLAYER_LEAVE], [gPlayers[a].Name]), True);
4829 g_Player_Remove(gPlayers[a].UID);
4830 if NetUseMaster then
4831 g_Net_Slist_Update;
4832 // Åñëè íå ïåðåìåøàòü, ïðè äîáàâëåíèè íîâûõ áîòîâ ïîÿâÿòñÿ ñòàðûå
4833 g_Bot_MixNames();
4834 end;
4835 end else
4836 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
4837 end
4838 else if cmd = 'kick_id' then
4839 begin
4840 if g_Game_IsServer and g_Game_IsNet then
4841 begin
4842 if Length(P) < 2 then
4843 begin
4844 g_Console_Add('kick_id <client ID>');
4845 Exit;
4846 end;
4847 if P[1] = '' then
4848 begin
4849 g_Console_Add('kick_id <client ID>');
4850 Exit;
4851 end;
4853 a := StrToIntDef(P[1], 0);
4854 if (NetClients <> nil) and (a <= High(NetClients)) then
4855 begin
4856 if NetClients[a].Used and (NetClients[a].Peer <> nil) then
4857 begin
4858 s := g_Net_ClientName_ByID(NetClients[a].ID);
4859 enet_peer_disconnect(NetClients[a].Peer, NET_DISC_KICK);
4860 g_Console_Add(Format(_lc[I_PLAYER_KICK], [s]));
4861 MH_SEND_GameEvent(NET_EV_PLAYER_KICK, 0, s);
4862 if NetUseMaster then
4863 g_Net_Slist_Update;
4864 end;
4865 end;
4866 end else
4867 g_Console_Add(_lc[I_MSG_SERVERONLY]);
4868 end
4869 else if cmd = 'ban' then
4870 begin
4871 if g_Game_IsServer and g_Game_IsNet then
4872 begin
4873 if Length(P) < 2 then
4874 begin
4875 g_Console_Add('ban <name>');
4876 Exit;
4877 end;
4878 if P[1] = '' then
4879 begin
4880 g_Console_Add('ban <name>');
4881 Exit;
4882 end;
4884 pl := g_Net_Client_ByName(P[1]);
4885 if (pl <> nil) then
4886 begin
4887 s := g_Net_ClientName_ByID(pl^.ID);
4888 g_Net_BanHost(pl^.Peer^.address.host, False);
4889 enet_peer_disconnect(pl^.Peer, NET_DISC_TEMPBAN);
4890 g_Console_Add(Format(_lc[I_PLAYER_BAN], [s]));
4891 MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s);
4892 if NetUseMaster then
4893 g_Net_Slist_Update;
4894 end else
4895 g_Console_Add(Format(_lc[I_NET_ERR_NAME404], [P[1]]));
4896 end else
4897 g_Console_Add(_lc[I_MSG_SERVERONLY]);
4898 end
4899 else if cmd = 'ban_id' then
4900 begin
4901 if g_Game_IsServer and g_Game_IsNet then
4902 begin
4903 if Length(P) < 2 then
4904 begin
4905 g_Console_Add('ban_id <client ID>');
4906 Exit;
4907 end;
4908 if P[1] = '' then
4909 begin
4910 g_Console_Add('ban_id <client ID>');
4911 Exit;
4912 end;
4914 a := StrToIntDef(P[1], 0);
4915 if (NetClients <> nil) and (a <= High(NetClients)) then
4916 if NetClients[a].Used and (NetClients[a].Peer <> nil) then
4917 begin
4918 s := g_Net_ClientName_ByID(NetClients[a].ID);
4919 g_Net_BanHost(NetClients[a].Peer^.address.host, False);
4920 enet_peer_disconnect(NetClients[a].Peer, NET_DISC_TEMPBAN);
4921 g_Console_Add(Format(_lc[I_PLAYER_BAN], [s]));
4922 MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s);
4923 if NetUseMaster then
4924 g_Net_Slist_Update;
4925 end;
4926 end else
4927 g_Console_Add(_lc[I_MSG_SERVERONLY]);
4928 end
4929 else if cmd = 'permban' then
4930 begin
4931 if g_Game_IsServer and g_Game_IsNet then
4932 begin
4933 if Length(P) < 2 then
4934 begin
4935 g_Console_Add('permban <name>');
4936 Exit;
4937 end;
4938 if P[1] = '' then
4939 begin
4940 g_Console_Add('permban <name>');
4941 Exit;
4942 end;
4944 pl := g_Net_Client_ByName(P[1]);
4945 if (pl <> nil) then
4946 begin
4947 s := g_Net_ClientName_ByID(pl^.ID);
4948 g_Net_BanHost(pl^.Peer^.address.host);
4949 enet_peer_disconnect(pl^.Peer, NET_DISC_BAN);
4950 g_Net_SaveBanList();
4951 g_Console_Add(Format(_lc[I_PLAYER_BAN], [s]));
4952 MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s);
4953 if NetUseMaster then
4954 g_Net_Slist_Update;
4955 end else
4956 g_Console_Add(Format(_lc[I_NET_ERR_NAME404], [P[1]]));
4957 end else
4958 g_Console_Add(_lc[I_MSG_SERVERONLY]);
4959 end
4960 else if cmd = 'permban_id' then
4961 begin
4962 if g_Game_IsServer and g_Game_IsNet then
4963 begin
4964 if Length(P) < 2 then
4965 begin
4966 g_Console_Add('permban_id <client ID>');
4967 Exit;
4968 end;
4969 if P[1] = '' then
4970 begin
4971 g_Console_Add('permban_id <client ID>');
4972 Exit;
4973 end;
4975 a := StrToIntDef(P[1], 0);
4976 if (NetClients <> nil) and (a <= High(NetClients)) then
4977 if NetClients[a].Used and (NetClients[a].Peer <> nil) then
4978 begin
4979 s := g_Net_ClientName_ByID(NetClients[a].ID);
4980 g_Net_BanHost(NetClients[a].Peer^.address.host);
4981 enet_peer_disconnect(NetClients[a].Peer, NET_DISC_BAN);
4982 g_Net_SaveBanList();
4983 g_Console_Add(Format(_lc[I_PLAYER_BAN], [s]));
4984 MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s);
4985 if NetUseMaster then
4986 g_Net_Slist_Update;
4987 end;
4988 end else
4989 g_Console_Add(_lc[I_MSG_SERVERONLY]);
4990 end
4991 else if cmd = 'unban' then
4992 begin
4993 if g_Game_IsServer and g_Game_IsNet then
4994 begin
4995 if Length(P) < 2 then
4996 begin
4997 g_Console_Add('unban <IP Address>');
4998 Exit;
4999 end;
5000 if P[1] = '' then
5001 begin
5002 g_Console_Add('unban <IP Address>');
5003 Exit;
5004 end;
5006 if g_Net_UnbanHost(P[1]) then
5007 begin
5008 g_Console_Add(Format(_lc[I_MSG_UNBAN_OK], [P[1]]));
5009 g_Net_SaveBanList();
5010 end else
5011 g_Console_Add(Format(_lc[I_MSG_UNBAN_FAIL], [P[1]]));
5012 end else
5013 g_Console_Add(_lc[I_MSG_SERVERONLY]);
5014 end
5015 else if cmd = 'clientlist' then
5016 begin
5017 if g_Game_IsServer and g_Game_IsNet then
5018 begin
5019 b := 0;
5020 if NetClients <> nil then
5021 for a := Low(NetClients) to High(NetClients) do
5022 if NetClients[a].Used and (NetClients[a].Peer <> nil) then
5023 begin
5024 plr := g_Player_Get(NetClients[a].Player);
5025 if plr = nil then continue;
5026 Inc(b);
5027 g_Console_Add(Format('#%2d: %-15s | %s', [a,
5028 IpToStr(NetClients[a].Peer^.address.host), plr.Name]));
5029 end;
5030 if b = 0 then
5031 g_Console_Add(_lc[I_MSG_NOCLIENTS]);
5032 end else
5033 g_Console_Add(_lc[I_MSG_SERVERONLY]);
5034 end
5035 else if cmd = 'connect' then
5036 begin
5037 if (NetMode = NET_NONE) then
5038 begin
5039 if Length(P) < 2 then
5040 begin
5041 g_Console_Add('connect <IP> [port] [password]');
5042 Exit;
5043 end;
5044 if P[1] = '' then
5045 begin
5046 g_Console_Add('connect <IP> [port] [password]');
5047 Exit;
5048 end;
5050 if Length(P) > 2 then
5051 prt := StrToIntDef(P[2], 25666)
5052 else
5053 prt := 25666;
5055 if Length(P) > 3 then
5056 pw := P[3]
5057 else
5058 pw := '';
5060 g_Game_StartClient(P[1], prt, pw);
5061 end;
5062 end
5063 else if cmd = 'disconnect' then
5064 begin
5065 if (NetMode = NET_CLIENT) then
5066 g_Net_Disconnect();
5067 end
5068 else if cmd = 'reconnect' then
5069 begin
5070 if (NetMode = NET_SERVER) then
5071 Exit;
5073 if (NetMode = NET_CLIENT) then
5074 begin
5075 g_Net_Disconnect();
5076 gExit := EXIT_SIMPLE;
5077 EndGame;
5078 end;
5080 //TODO: Use last successful password to reconnect, instead of ''
5081 g_Game_StartClient(NetClientIP, NetClientPort, '');
5082 end
5083 else if (cmd = 'addbot') or
5084 (cmd = 'bot_add') then
5085 begin
5086 if Length(P) > 1 then
5087 g_Bot_Add(TEAM_NONE, StrToIntDef(P[1], 2))
5088 else
5089 g_Bot_Add(TEAM_NONE, 2);
5090 end
5091 else if cmd = 'bot_addlist' then
5092 begin
5093 if Length(P) > 1 then
5094 if Length(P) = 2 then
5095 g_Bot_AddList(TEAM_NONE, P[1], StrToIntDef(P[1], -1))
5096 else
5097 g_Bot_AddList(IfThen(P[2] = 'red', TEAM_RED, TEAM_BLUE), P[1], StrToIntDef(P[1], -1));
5098 end
5099 else if cmd = 'bot_removeall' then
5100 g_Bot_RemoveAll()
5101 else if cmd = 'chat' then
5102 begin
5103 if g_Game_IsNet then
5104 begin
5105 if Length(P) > 1 then
5106 begin
5107 for a := 1 to High(P) do
5108 chstr := chstr + P[a] + ' ';
5110 if Length(chstr) > 200 then SetLength(chstr, 200);
5112 if Length(chstr) < 1 then
5113 begin
5114 g_Console_Add('chat <text>');
5115 Exit;
5116 end;
5118 chstr := b_Text_Format(chstr);
5119 if g_Game_IsClient then
5120 MC_SEND_Chat(chstr, NET_CHAT_PLAYER)
5121 else
5122 MH_SEND_Chat(gPlayer1Settings.Name + ': ' + chstr, NET_CHAT_PLAYER);
5123 end
5124 else
5125 g_Console_Add('chat <text>');
5126 end else
5127 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
5128 end
5129 else if cmd = 'teamchat' then
5130 begin
5131 if g_Game_IsNet and (gGameSettings.GameMode in [GM_TDM, GM_CTF]) then
5132 begin
5133 if Length(P) > 1 then
5134 begin
5135 for a := 1 to High(P) do
5136 chstr := chstr + P[a] + ' ';
5138 if Length(chstr) > 200 then SetLength(chstr, 200);
5140 if Length(chstr) < 1 then
5141 begin
5142 g_Console_Add('teamchat <text>');
5143 Exit;
5144 end;
5146 chstr := b_Text_Format(chstr);
5147 if g_Game_IsClient then
5148 MC_SEND_Chat(chstr, NET_CHAT_TEAM)
5149 else
5150 MH_SEND_Chat(gPlayer1Settings.Name + ': ' + chstr, NET_CHAT_TEAM,
5151 gPlayer1Settings.Team);
5152 end
5153 else
5154 g_Console_Add('teamchat <text>');
5155 end else
5156 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
5157 end
5158 else if cmd = 'game' then
5159 begin
5160 if gGameSettings.GameType <> GT_NONE then
5161 begin
5162 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
5163 Exit;
5164 end;
5165 if Length(P) = 1 then
5166 begin
5167 g_Console_Add(cmd + ' <WAD> [MAP] [# players]');
5168 Exit;
5169 end;
5170 // Èãðà åù¸ íå çàïóùåíà, ñíà÷àëà íàì íàäî çàãðóçèòü êàêîé-òî WAD
5171 if Pos('.wad', LowerCase(P[1])) = 0 then
5172 P[1] := P[1] + '.wad';
5174 if FileExists(MapsDir + P[1]) then
5175 begin
5176 // Åñëè êàðòà íå óêàçàíà, áåð¸ì ïåðâóþ êàðòó â ôàéëå
5177 if Length(P) < 3 then
5178 begin
5179 SetLength(P, 3);
5180 P[2] := g_Game_GetFirstMap(MapsDir + P[1]);
5181 end;
5183 s := P[1] + ':\' + UpperCase(P[2]);
5185 if g_Map_Exist(MapsDir + s) then
5186 begin
5187 // Çàïóñêàåì ñâîþ èãðó
5188 g_Game_Free();
5189 with gGameSettings do
5190 begin
5191 GameMode := g_Game_TextToMode(gcGameMode);
5192 if gSwitchGameMode <> GM_NONE then
5193 GameMode := gSwitchGameMode;
5194 if GameMode = GM_NONE then GameMode := GM_DM;
5195 if GameMode = GM_SINGLE then GameMode := GM_COOP;
5196 b := 1;
5197 if Length(P) >= 4 then
5198 b := StrToIntDef(P[3], 1);
5199 g_Game_StartCustom(s, GameMode, TimeLimit,
5200 GoalLimit, MaxLives, Options, b);
5201 end;
5202 end
5203 else
5204 if P[2] = '' then
5205 g_Console_Add(Format(_lc[I_MSG_NO_MAPS], [P[1]]))
5206 else
5207 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [UpperCase(P[2])]));
5208 end else
5209 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]));
5210 end
5211 else if cmd = 'host' then
5212 begin
5213 if gGameSettings.GameType <> GT_NONE then
5214 begin
5215 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
5216 Exit;
5217 end;
5218 if Length(P) < 4 then
5219 begin
5220 g_Console_Add(cmd + ' <listen IP> <port> <WAD> [MAP] [# players]');
5221 Exit;
5222 end;
5223 if not StrToIp(P[1], listen) then
5224 Exit;
5225 prt := StrToIntDef(P[2], 25666);
5227 if Pos('.wad', LowerCase(P[3])) = 0 then
5228 P[3] := P[3] + '.wad';
5230 if FileExists(MapsDir + P[3]) then
5231 begin
5232 // Åñëè êàðòà íå óêàçàíà, áåð¸ì ïåðâóþ êàðòó â ôàéëå
5233 if Length(P) < 5 then
5234 begin
5235 SetLength(P, 5);
5236 P[4] := g_Game_GetFirstMap(MapsDir + P[1]);
5237 end;
5239 s := P[3] + ':\' + UpperCase(P[4]);
5241 if g_Map_Exist(MapsDir + s) then
5242 begin
5243 // Çàïóñêàåì ñâîþ èãðó
5244 g_Game_Free();
5245 with gGameSettings do
5246 begin
5247 GameMode := g_Game_TextToMode(gcGameMode);
5248 if gSwitchGameMode <> GM_NONE then
5249 GameMode := gSwitchGameMode;
5250 if GameMode = GM_NONE then GameMode := GM_DM;
5251 if GameMode = GM_SINGLE then GameMode := GM_COOP;
5252 b := 0;
5253 if Length(P) >= 6 then
5254 b := StrToIntDef(P[5], 0);
5255 g_Game_StartServer(s, GameMode, TimeLimit,
5256 GoalLimit, MaxLives, Options, b, listen, prt);
5257 end;
5258 end
5259 else
5260 if P[4] = '' then
5261 g_Console_Add(Format(_lc[I_MSG_NO_MAPS], [P[3]]))
5262 else
5263 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [UpperCase(P[4])]));
5264 end else
5265 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[3]]));
5266 end
5267 else if cmd = 'map' then
5268 begin
5269 if Length(P) = 1 then
5270 begin
5271 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
5272 begin
5273 g_Console_Add(cmd + ' <MAP>');
5274 g_Console_Add(cmd + ' <WAD> [MAP]');
5275 end else
5276 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
5277 end else
5278 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
5279 begin
5280 // Èä¸ò ñâîÿ èãðà èëè ñåðâåð
5281 if Length(P) < 3 then
5282 begin
5283 // Ïåðâûé ïàðàìåòð - ëèáî êàðòà, ëèáî èìÿ WAD ôàéëà
5284 s := UpperCase(P[1]);
5285 if g_Map_Exist(MapsDir + gGameSettings.WAD + ':\' + s) then
5286 begin // Êàðòà íàøëàñü
5287 gExitByTrigger := False;
5288 if gGameOn then
5289 begin // Èä¸ò èãðà - çàâåðøàåì óðîâåíü
5290 gNextMap := s;
5291 gExit := EXIT_ENDLEVELCUSTOM;
5292 end
5293 else // Èíòåðìèññèÿ - ñðàçó çàãðóæàåì êàðòó
5294 g_Game_ChangeMap(s);
5295 end else
5296 begin
5297 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [s]));
5298 // Òàêîé êàðòû íåò, èùåì WAD ôàéë
5299 if Pos('.wad', LowerCase(P[1])) = 0 then
5300 P[1] := P[1] + '.wad';
5302 if FileExists(MapsDir + P[1]) then
5303 begin
5304 // Ïàðàìåòðà êàðòû íåò, ïîýòîìó ñòàâèì ïåðâóþ èç ôàéëà
5305 SetLength(P, 3);
5306 P[2] := g_Game_GetFirstMap(MapsDir + P[1]);
5308 s := P[1] + ':\' + P[2];
5310 if g_Map_Exist(MapsDir + s) then
5311 begin
5312 gExitByTrigger := False;
5313 if gGameOn then
5314 begin // Èä¸ò èãðà - çàâåðøàåì óðîâåíü
5315 gNextMap := s;
5316 gExit := EXIT_ENDLEVELCUSTOM;
5317 end
5318 else // Èíòåðìèññèÿ - ñðàçó çàãðóæàåì êàðòó
5319 g_Game_ChangeMap(s);
5320 end else
5321 if P[2] = '' then
5322 g_Console_Add(Format(_lc[I_MSG_NO_MAPS], [P[1]]))
5323 else
5324 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [P[2]]));
5325 end else
5326 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]));
5327 end;
5328 end else
5329 begin
5330 // Óêàçàíî äâà ïàðàìåòðà, çíà÷èò ïåðâûé - WAD ôàéë, à âòîðîé - êàðòà
5331 if Pos('.wad', LowerCase(P[1])) = 0 then
5332 P[1] := P[1] + '.wad';
5334 if FileExists(MapsDir + P[1]) then
5335 begin
5336 // Íàøëè WAD ôàéë
5337 P[2] := UpperCase(P[2]);
5338 s := P[1] + ':\' + P[2];
5340 if g_Map_Exist(MapsDir + s) then
5341 begin // Íàøëè êàðòó
5342 gExitByTrigger := False;
5343 if gGameOn then
5344 begin // Èä¸ò èãðà - çàâåðøàåì óðîâåíü
5345 gNextMap := s;
5346 gExit := EXIT_ENDLEVELCUSTOM;
5347 end
5348 else // Èíòåðìèññèÿ - ñðàçó çàãðóæàåì êàðòó
5349 g_Game_ChangeMap(s);
5350 end else
5351 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [P[2]]));
5352 end else
5353 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]));
5354 end;
5355 end else
5356 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
5357 end
5358 else if cmd = 'nextmap' then
5359 begin
5360 if not(gGameOn or (gState = STATE_INTERCUSTOM)) then
5361 g_Console_Add(_lc[I_MSG_NOT_GAME])
5362 else begin
5363 nm := True;
5364 if Length(P) = 1 then
5365 begin
5366 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
5367 begin
5368 g_Console_Add(cmd + ' <MAP>');
5369 g_Console_Add(cmd + ' <WAD> [MAP]');
5370 end else begin
5371 nm := False;
5372 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
5373 end;
5374 end else
5375 begin
5376 nm := False;
5377 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
5378 begin
5379 if Length(P) < 3 then
5380 begin
5381 // Ïåðâûé ïàðàìåòð - ëèáî êàðòà, ëèáî èìÿ WAD ôàéëà
5382 s := UpperCase(P[1]);
5383 if g_Map_Exist(MapsDir + gGameSettings.WAD + ':\' + s) then
5384 begin // Êàðòà íàøëàñü
5385 gExitByTrigger := False;
5386 gNextMap := s;
5387 nm := True;
5388 end else
5389 begin
5390 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [s]));
5391 // Òàêîé êàðòû íåò, èùåì WAD ôàéë
5392 if Pos('.wad', LowerCase(P[1])) = 0 then
5393 P[1] := P[1] + '.wad';
5395 if FileExists(MapsDir + P[1]) then
5396 begin
5397 // Ïàðàìåòðà êàðòû íåò, ïîýòîìó ñòàâèì ïåðâóþ èç ôàéëà
5398 SetLength(P, 3);
5399 P[2] := g_Game_GetFirstMap(MapsDir + P[1]);
5401 s := P[1] + ':\' + P[2];
5403 if g_Map_Exist(MapsDir + s) then
5404 begin // Óñòàíàâëèâàåì êàðòó
5405 gExitByTrigger := False;
5406 gNextMap := s;
5407 nm := True;
5408 end else
5409 if P[2] = '' then
5410 g_Console_Add(Format(_lc[I_MSG_NO_MAPS], [P[1]]))
5411 else
5412 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [P[2]]));
5413 end else
5414 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]));
5415 end;
5416 end else
5417 begin
5418 // Óêàçàíî äâà ïàðàìåòðà, çíà÷èò ïåðâûé - WAD ôàéë, à âòîðîé - êàðòà
5419 if Pos('.wad', LowerCase(P[1])) = 0 then
5420 P[1] := P[1] + '.wad';
5422 if FileExists(MapsDir + P[1]) then
5423 begin
5424 // Íàøëè WAD ôàéë
5425 P[2] := UpperCase(P[2]);
5426 s := P[1] + ':\' + P[2];
5428 if g_Map_Exist(MapsDir + s) then
5429 begin // Íàøëè êàðòó
5430 gExitByTrigger := False;
5431 gNextMap := s;
5432 nm := True;
5433 end else
5434 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [P[2]]));
5435 end else
5436 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]));
5437 end;
5438 end else
5439 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
5440 end;
5441 if nm then
5442 if gNextMap = '' then
5443 g_Console_Add(_lc[I_MSG_NEXTMAP_UNSET])
5444 else
5445 g_Console_Add(Format(_lc[I_MSG_NEXTMAP_SET], [gNextMap]));
5446 end;
5447 end
5448 else if (cmd = 'endmap') or (cmd = 'goodbye') then
5449 begin
5450 if not gGameOn then
5451 g_Console_Add(_lc[I_MSG_NOT_GAME])
5452 else
5453 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
5454 begin
5455 gExitByTrigger := False;
5456 // Ñëåäóþùàÿ êàðòà íå çàäàíà, ïðîáóåì íàéòè òðèããåð Âûõîä
5457 if (gNextMap = '') and (gTriggers <> nil) then
5458 for a := 0 to High(gTriggers) do
5459 if gTriggers[a].TriggerType = TRIGGER_EXIT then
5460 begin
5461 gExitByTrigger := True;
5462 gNextMap := gTriggers[a].Data.MapName;
5463 Break;
5464 end;
5465 // Èùåì ñëåäóþùóþ êàðòó â WAD ôàéëå
5466 if gNextMap = '' then
5467 gNextMap := g_Game_GetNextMap();
5468 // Ïðîâåðÿåì, íå çàäàí ëè WAD ôàéë ðåñóðñíîé ñòðîêîé
5469 if Pos(':\', gNextMap) = 0 then
5470 s := gGameSettings.WAD + ':\' + gNextMap
5471 else
5472 s := gNextMap;
5473 // Åñëè êàðòà íàéäåíà, âûõîäèì ñ óðîâíÿ
5474 if g_Map_Exist(MapsDir + s) then
5475 gExit := EXIT_ENDLEVELCUSTOM
5476 else
5477 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [gNextMap]));
5478 end else
5479 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
5480 end
5481 else if (cmd = 'event') then
5482 begin
5483 if (Length(P) <= 1) then
5484 begin
5485 for a := 0 to High(gEvents) do
5486 if gEvents[a].Command = '' then
5487 g_Console_Add(gEvents[a].Name + ' <none>')
5488 else
5489 g_Console_Add(gEvents[a].Name + ' "' + gEvents[a].Command + '"');
5490 Exit;
5491 end;
5492 if (Length(P) = 2) then
5493 begin
5494 for a := 0 to High(gEvents) do
5495 if gEvents[a].Name = P[1] then
5496 if gEvents[a].Command = '' then
5497 g_Console_Add(gEvents[a].Name + ' <none>')
5498 else
5499 g_Console_Add(gEvents[a].Name + ' "' + gEvents[a].Command + '"');
5500 Exit;
5501 end;
5502 for a := 0 to High(gEvents) do
5503 if gEvents[a].Name = P[1] then
5504 begin
5505 gEvents[a].Command := '';
5506 for b := 2 to High(P) do
5507 if Pos(' ', P[b]) = 0 then
5508 gEvents[a].Command := gEvents[a].Command + ' ' + P[b]
5509 else
5510 gEvents[a].Command := gEvents[a].Command + ' "' + P[b] + '"';
5511 gEvents[a].Command := Trim(gEvents[a].Command);
5512 Exit;
5513 end;
5514 end
5515 // Êîìàíäû Ñâîåé èãðû:
5516 else if gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT] then
5517 begin
5518 if cmd = 'bot_addred' then
5519 begin
5520 if Length(P) > 1 then
5521 g_Bot_Add(TEAM_RED, StrToIntDef(P[1], 2))
5522 else
5523 g_Bot_Add(TEAM_RED, 2);
5524 end
5525 else if cmd = 'bot_addblue' then
5526 begin
5527 if Length(P) > 1 then
5528 g_Bot_Add(TEAM_BLUE, StrToIntDef(P[1], 2))
5529 else
5530 g_Bot_Add(TEAM_BLUE, 2);
5531 end
5532 else if cmd = 'suicide' then
5533 begin
5534 if gGameOn then
5535 begin
5536 if g_Game_IsClient then
5537 MC_SEND_CheatRequest(NET_CHEAT_SUICIDE)
5538 else
5539 begin
5540 if gPlayer1 <> nil then
5541 gPlayer1.Damage(SUICIDE_DAMAGE, gPlayer1.UID, 0, 0, HIT_SELF);
5542 if gPlayer2 <> nil then
5543 gPlayer2.Damage(SUICIDE_DAMAGE, gPlayer2.UID, 0, 0, HIT_SELF);
5544 end;
5545 end;
5546 end
5547 else if cmd = 'spectate' then
5548 begin
5549 if not gGameOn then
5550 Exit;
5551 g_Game_Spectate();
5552 end
5553 else if cmd = 'say' then
5554 begin
5555 if g_Game_IsServer and g_Game_IsNet then
5556 begin
5557 if Length(P) > 1 then
5558 begin
5559 chstr := '';
5560 for a := 1 to High(P) do
5561 chstr := chstr + P[a] + ' ';
5563 if Length(chstr) > 200 then SetLength(chstr, 200);
5565 if Length(chstr) < 1 then
5566 begin
5567 g_Console_Add('say <text>');
5568 Exit;
5569 end;
5571 chstr := b_Text_Format(chstr);
5572 MH_SEND_Chat(chstr, NET_CHAT_PLAYER);
5573 end
5574 else g_Console_Add('say <text>');
5575 end else
5576 g_Console_Add(_lc[I_MSG_SERVERONLY]);
5577 end
5578 else if cmd = 'tell' then
5579 begin
5580 if g_Game_IsServer and g_Game_IsNet then
5581 begin
5582 if (Length(P) > 2) and (P[1] <> '') then
5583 begin
5584 chstr := '';
5585 for a := 2 to High(P) do
5586 chstr := chstr + P[a] + ' ';
5588 if Length(chstr) > 200 then SetLength(chstr, 200);
5590 if Length(chstr) < 1 then
5591 begin
5592 g_Console_Add('tell <playername> <text>');
5593 Exit;
5594 end;
5596 pl := g_Net_Client_ByName(P[1]);
5597 if pl <> nil then
5598 MH_SEND_Chat(b_Text_Format(chstr), NET_CHAT_PLAYER, pl^.ID)
5599 else
5600 g_Console_Add(Format(_lc[I_NET_ERR_NAME404], [P[1]]));
5601 end
5602 else g_Console_Add('tell <playername> <text>');
5603 end else
5604 g_Console_Add(_lc[I_MSG_SERVERONLY]);
5605 end
5606 else if (cmd = 'overtime') and not g_Game_IsClient then
5607 begin
5608 if (Length(P) = 1) or (StrToIntDef(P[1], -1) <= 0) then
5609 Exit;
5610 // Äîïîëíèòåëüíîå âðåìÿ:
5611 gGameSettings.TimeLimit := (gTime - gGameStartTime) div 1000 + Word(StrToIntDef(P[1], 0));
5613 g_Console_Add(Format(_lc[I_MSG_TIME_LIMIT],
5614 [gGameSettings.TimeLimit div 3600,
5615 (gGameSettings.TimeLimit div 60) mod 60,
5616 gGameSettings.TimeLimit mod 60]));
5617 if g_Game_IsNet then MH_SEND_GameSettings;
5618 end
5619 else if (cmd = 'rcon_password') and g_Game_IsClient then
5620 begin
5621 if (Length(P) <= 1) then
5622 g_Console_Add('rcon_password <password>')
5623 else
5624 MC_SEND_RCONPassword(P[1]);
5625 end
5626 else if cmd = 'rcon' then
5627 begin
5628 if g_Game_IsClient then
5629 begin
5630 if Length(P) > 1 then
5631 begin
5632 chstr := '';
5633 for a := 1 to High(P) do
5634 chstr := chstr + P[a] + ' ';
5636 if Length(chstr) > 200 then SetLength(chstr, 200);
5638 if Length(chstr) < 1 then
5639 begin
5640 g_Console_Add('rcon <command>');
5641 Exit;
5642 end;
5644 MC_SEND_RCONCommand(chstr);
5645 end
5646 else g_Console_Add('rcon <command>');
5647 end;
5648 end
5649 else if cmd = 'ready' then
5650 begin
5651 if g_Game_IsServer and (gLMSRespawn = LMS_RESPAWN_WARMUP) then
5652 gLMSRespawnTime := gTime + 100;
5653 end
5654 else if (cmd = 'callvote') and g_Game_IsNet then
5655 begin
5656 if Length(P) > 1 then
5657 begin
5658 chstr := '';
5659 for a := 1 to High(P) do begin
5660 if a > 1 then chstr := chstr + ' ';
5661 chstr := chstr + P[a];
5662 end;
5664 if Length(chstr) > 200 then SetLength(chstr, 200);
5666 if Length(chstr) < 1 then
5667 begin
5668 g_Console_Add('callvote <command>');
5669 Exit;
5670 end;
5672 if g_Game_IsClient then
5673 MC_SEND_Vote(True, chstr)
5674 else
5675 g_Game_StartVote(chstr, gPlayer1Settings.Name);
5676 g_Console_Process('vote', True);
5677 end
5678 else
5679 g_Console_Add('callvote <command>');
5680 end
5681 else if (cmd = 'vote') and g_Game_IsNet then
5682 begin
5683 if g_Game_IsClient then
5684 MC_SEND_Vote(False)
5685 else if gVoteInProgress then
5686 begin
5687 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
5688 a := Floor((NetClientCount+1)/2.0) + 1
5689 else
5690 a := Floor(NetClientCount/2.0) + 1;
5691 if gVoted then
5692 begin
5693 Dec(gVoteCount);
5694 gVoted := False;
5695 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_REVOKED], [gPlayer1Settings.Name, gVoteCount, a]), True);
5696 MH_SEND_VoteEvent(NET_VE_REVOKE, gPlayer1Settings.Name, 'a', gVoteCount, a);
5697 end
5698 else
5699 begin
5700 Inc(gVoteCount);
5701 gVoted := True;
5702 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_VOTE], [gPlayer1Settings.Name, gVoteCount, a]), True);
5703 MH_SEND_VoteEvent(NET_VE_VOTE, gPlayer1Settings.Name, 'a', gVoteCount, a);
5704 g_Game_CheckVote;
5705 end;
5706 end;
5707 end
5708 end;
5709 end;
5711 procedure g_TakeScreenShot();
5712 var
5713 a: Word;
5714 FileName: String;
5715 begin
5716 for a := 1 to High(Word) do
5717 begin
5718 FileName := Format(GameDir+'/Screenshots/Screenshot%.3d.bmp', [a]);
5719 if not FileExists(FileName) then
5720 begin
5721 e_MakeScreenshot(FileName, gScreenWidth, gScreenHeight);
5722 g_Console_Add(Format(_lc[I_CONSOLE_SCREENSHOT], [ExtractFileName(FileName)]));
5723 Break;
5724 end;
5725 end;
5726 end;
5728 procedure g_Game_InGameMenu(Show: Boolean);
5729 begin
5730 if (g_ActiveWindow = nil) and Show then
5731 begin
5732 if gGameSettings.GameType = GT_SINGLE then
5733 g_GUI_ShowWindow('GameSingleMenu')
5734 else
5735 begin
5736 if g_Game_IsClient then
5737 g_GUI_ShowWindow('GameClientMenu')
5738 else
5739 if g_Game_IsNet then
5740 g_GUI_ShowWindow('GameServerMenu')
5741 else
5742 g_GUI_ShowWindow('GameCustomMenu');
5743 end;
5744 g_Sound_PlayEx('MENU_OPEN');
5746 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
5747 if (not g_Game_IsNet) then
5748 g_Game_Pause(True);
5749 end
5750 else
5751 if (g_ActiveWindow <> nil) and (not Show) then
5752 begin
5753 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
5754 if (not g_Game_IsNet) then
5755 g_Game_Pause(False);
5756 end;
5757 end;
5759 procedure g_Game_Pause(Enable: Boolean);
5760 begin
5761 if not gGameOn then
5762 Exit;
5764 if gPause = Enable then
5765 Exit;
5767 if not (gGameSettings.GameType in [GT_SINGLE, GT_CUSTOM]) then
5768 Exit;
5770 gPause := Enable;
5771 g_Game_PauseAllSounds(Enable);
5772 end;
5774 procedure g_Game_PauseAllSounds(Enable: Boolean);
5775 var
5776 i: Integer;
5777 begin
5778 // Òðèããåðû:
5779 if gTriggers <> nil then
5780 for i := 0 to High(gTriggers) do
5781 with gTriggers[i] do
5782 if (TriggerType = TRIGGER_SOUND) and
5783 (Sound <> nil) and
5784 Sound.IsPlaying() then
5785 begin
5786 Sound.Pause(Enable);
5787 end;
5789 // Çâóêè èãðîêîâ:
5790 if gPlayers <> nil then
5791 for i := 0 to High(gPlayers) do
5792 if gPlayers[i] <> nil then
5793 gPlayers[i].PauseSounds(Enable);
5795 // Ìóçûêà:
5796 if gMusic <> nil then
5797 gMusic.Pause(Enable);
5798 end;
5800 procedure g_Game_StopAllSounds(all: Boolean);
5801 var
5802 i: Integer;
5803 begin
5804 if gTriggers <> nil then
5805 for i := 0 to High(gTriggers) do
5806 with gTriggers[i] do
5807 if (TriggerType = TRIGGER_SOUND) and
5808 (Sound <> nil) then
5809 Sound.Stop();
5811 if gMusic <> nil then
5812 gMusic.Stop();
5814 if all then
5815 e_StopChannels();
5816 end;
5818 procedure g_Game_UpdateTriggerSounds();
5819 var
5820 i: Integer;
5821 begin
5822 if gTriggers <> nil then
5823 for i := 0 to High(gTriggers) do
5824 with gTriggers[i] do
5825 if (TriggerType = TRIGGER_SOUND) and
5826 (Sound <> nil) and
5827 (Data.Local) and
5828 Sound.IsPlaying() then
5829 begin
5830 if ((gPlayer1 <> nil) and g_CollidePoint(gPlayer1.GameX, gPlayer1.GameY, X, Y, Width, Height)) or
5831 ((gPlayer2 <> nil) and g_CollidePoint(gPlayer2.GameX, gPlayer2.GameY, X, Y, Width, Height)) then
5832 begin
5833 Sound.SetPan(0.5 - Data.Pan/255.0);
5834 Sound.SetVolume(Data.Volume/255.0);
5835 end
5836 else
5837 Sound.SetCoords(X+(Width div 2), Y+(Height div 2), Data.Volume/255.0);
5838 end;
5839 end;
5841 function g_Game_IsWatchedPlayer(UID: Word): Boolean;
5842 begin
5843 Result := False;
5844 if (gPlayer1 <> nil) and (gPlayer1.UID = UID) then
5845 begin
5846 Result := True;
5847 Exit;
5848 end;
5849 if (gPlayer2 <> nil) and (gPlayer2.UID = UID) then
5850 begin
5851 Result := True;
5852 Exit;
5853 end;
5854 if gSpectMode <> SPECT_PLAYERS then
5855 Exit;
5856 if gSpectPID1 = UID then
5857 begin
5858 Result := True;
5859 Exit;
5860 end;
5861 if gSpectViewTwo and (gSpectPID2 = UID) then
5862 begin
5863 Result := True;
5864 Exit;
5865 end;
5866 end;
5868 function g_Game_IsWatchedTeam(Team: Byte): Boolean;
5869 var
5870 Pl: TPlayer;
5871 begin
5872 Result := False;
5873 if (gPlayer1 <> nil) and (gPlayer1.Team = Team) then
5874 begin
5875 Result := True;
5876 Exit;
5877 end;
5878 if (gPlayer2 <> nil) and (gPlayer2.Team = Team) then
5879 begin
5880 Result := True;
5881 Exit;
5882 end;
5883 if gSpectMode <> SPECT_PLAYERS then
5884 Exit;
5885 Pl := g_Player_Get(gSpectPID1);
5886 if (Pl <> nil) and (Pl.Team = Team) then
5887 begin
5888 Result := True;
5889 Exit;
5890 end;
5891 if gSpectViewTwo then
5892 begin
5893 Pl := g_Player_Get(gSpectPID2);
5894 if (Pl <> nil) and (Pl.Team = Team) then
5895 begin
5896 Result := True;
5897 Exit;
5898 end;
5899 end;
5900 end;
5902 procedure g_Game_Message(Msg: string; Time: Word);
5903 begin
5904 MessageText := b_Text_Format(Msg);
5905 MessageTime := Time;
5906 end;
5908 procedure g_Game_Announce_GoodShot(SpawnerUID: Word);
5909 var
5910 a: Integer;
5911 begin
5912 case gAnnouncer of
5913 ANNOUNCE_NONE:
5914 Exit;
5915 ANNOUNCE_ME,
5916 ANNOUNCE_MEPLUS:
5917 if not g_Game_IsWatchedPlayer(SpawnerUID) then
5918 Exit;
5919 end;
5920 for a := 0 to 3 do
5921 if goodsnd[a].IsPlaying() then
5922 Exit;
5924 goodsnd[Random(4)].Play();
5925 end;
5927 procedure g_Game_Announce_KillCombo(Param: Integer);
5928 var
5929 UID: Word;
5930 c, n: Byte;
5931 Pl: TPlayer;
5932 Name: String;
5933 begin
5934 UID := Param and $FFFF;
5935 c := Param shr 16;
5936 if c < 2 then
5937 Exit;
5939 Pl := g_Player_Get(UID);
5940 if Pl = nil then
5941 Name := '?'
5942 else
5943 Name := Pl.Name;
5945 case c of
5946 2: begin
5947 n := 0;
5948 g_Console_Add(Format(_lc[I_PLAYER_KILL_2X], [Name]), True);
5949 end;
5950 3: begin
5951 n := 1;
5952 g_Console_Add(Format(_lc[I_PLAYER_KILL_3X], [Name]), True);
5953 end;
5954 4: begin
5955 n := 2;
5956 g_Console_Add(Format(_lc[I_PLAYER_KILL_4X], [Name]), True);
5957 end;
5958 else begin
5959 n := 3;
5960 g_Console_Add(Format(_lc[I_PLAYER_KILL_MX], [Name]), True);
5961 end;
5962 end;
5964 case gAnnouncer of
5965 ANNOUNCE_NONE:
5966 Exit;
5967 ANNOUNCE_ME:
5968 if not g_Game_IsWatchedPlayer(UID) then
5969 Exit;
5970 ANNOUNCE_MEPLUS:
5971 if (not g_Game_IsWatchedPlayer(UID)) and (c < 4) then
5972 Exit;
5973 end;
5975 if killsnd[n].IsPlaying() then
5976 killsnd[n].Stop();
5977 killsnd[n].Play();
5978 end;
5980 procedure g_Game_StartVote(Command, Initiator: string);
5981 var
5982 Need: Integer;
5983 begin
5984 if not gVotesEnabled then Exit;
5985 if gGameSettings.GameType <> GT_SERVER then Exit;
5986 if gVoteInProgress or gVotePassed then
5987 begin
5988 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_INPROGRESS], [gVoteCommand]), True);
5989 MH_SEND_VoteEvent(NET_VE_INPROGRESS, gVoteCommand);
5990 Exit;
5991 end;
5992 gVoteInProgress := True;
5993 gVotePassed := False;
5994 gVoteTimer := gTime + gVoteTimeout * 1000;
5995 gVoteCount := 0;
5996 gVoted := False;
5997 gVoteCommand := Command;
5999 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
6000 Need := Floor((NetClientCount+1)/2.0)+1
6001 else
6002 Need := Floor(NetClientCount/2.0)+1;
6003 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_STARTED], [Initiator, Command, Need]), True);
6004 MH_SEND_VoteEvent(NET_VE_STARTED, Initiator, Command, Need);
6005 end;
6007 procedure g_Game_CheckVote;
6008 var
6009 I, Need: Integer;
6010 begin
6011 if gGameSettings.GameType <> GT_SERVER then Exit;
6012 if not gVoteInProgress then Exit;
6014 if (gTime >= gVoteTimer) then
6015 begin
6016 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
6017 Need := Floor((NetClientCount+1)/2.0) + 1
6018 else
6019 Need := Floor(NetClientCount/2.0) + 1;
6020 if gVoteCount >= Need then
6021 begin
6022 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_PASSED], [gVoteCommand]), True);
6023 MH_SEND_VoteEvent(NET_VE_PASSED, gVoteCommand);
6024 gVotePassed := True;
6025 gVoteCmdTimer := gTime + 5000;
6026 end
6027 else
6028 begin
6029 g_Console_Add(_lc[I_MESSAGE_VOTE_FAILED], True);
6030 MH_SEND_VoteEvent(NET_VE_FAILED);
6031 end;
6032 if NetClients <> nil then
6033 for I := Low(NetClients) to High(NetClients) do
6034 if NetClients[i].Used then
6035 NetClients[i].Voted := False;
6036 gVoteInProgress := False;
6037 gVoted := False;
6038 gVoteCount := 0;
6039 end
6040 else
6041 begin
6042 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
6043 Need := Floor((NetClientCount+1)/2.0) + 1
6044 else
6045 Need := Floor(NetClientCount/2.0) + 1;
6046 if gVoteCount >= Need then
6047 begin
6048 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_PASSED], [gVoteCommand]), True);
6049 MH_SEND_VoteEvent(NET_VE_PASSED, gVoteCommand);
6050 gVoteInProgress := False;
6051 gVotePassed := True;
6052 gVoteCmdTimer := gTime + 5000;
6053 gVoted := False;
6054 gVoteCount := 0;
6055 if NetClients <> nil then
6056 for I := Low(NetClients) to High(NetClients) do
6057 if NetClients[i].Used then
6058 NetClients[i].Voted := False;
6059 end;
6060 end;
6061 end;
6063 procedure g_Game_LoadMapList(FileName: string);
6064 var
6065 ListFile: TextFile;
6066 s: string;
6067 begin
6068 MapList := nil;
6069 MapIndex := -1;
6071 if not FileExists(FileName) then Exit;
6073 AssignFile(ListFile, FileName);
6074 Reset(ListFile);
6075 while not EOF(ListFile) do
6076 begin
6077 ReadLn(ListFile, s);
6079 s := Trim(s);
6080 if s = '' then Continue;
6082 SetLength(MapList, Length(MapList)+1);
6083 MapList[High(MapList)] := s;
6084 end;
6085 CloseFile(ListFile);
6086 end;
6088 procedure g_Game_SetDebugMode();
6089 begin
6090 gDebugMode := True;
6091 // ×èòû (äàæå â ñâîåé èãðå):
6092 gCheats := True;
6093 end;
6095 procedure g_Game_SetLoadingText(Text: String; Max: Integer; reWrite: Boolean);
6096 var
6097 i: Word;
6098 begin
6099 if Length(LoadingStat.Msgs) = 0 then
6100 Exit;
6102 with LoadingStat do
6103 begin
6104 if not reWrite then
6105 begin // Ïåðåõîäèì íà ñëåäóþùóþ ñòðîêó èëè ñêðîëëèðóåì:
6106 if NextMsg = Length(Msgs) then
6107 begin // scroll
6108 for i := 0 to High(Msgs)-1 do
6109 Msgs[i] := Msgs[i+1];
6110 end
6111 else
6112 Inc(NextMsg);
6113 end else
6114 if NextMsg = 0 then
6115 Inc(NextMsg);
6117 Msgs[NextMsg-1] := Text;
6118 CurValue := 0;
6119 MaxValue := Max;
6120 ShowCount := 0;
6121 end;
6123 g_ActiveWindow := nil;
6125 ProcessLoading;
6126 end;
6128 procedure g_Game_StepLoading();
6129 begin
6130 with LoadingStat do
6131 begin
6132 Inc(CurValue);
6133 Inc(ShowCount);
6134 if (ShowCount > LOADING_SHOW_STEP) then
6135 begin
6136 ShowCount := 0;
6137 ProcessLoading;
6138 end;
6139 end;
6140 end;
6142 procedure g_Game_ClearLoading();
6143 var
6144 len: Word;
6145 begin
6146 with LoadingStat do
6147 begin
6148 CurValue := 0;
6149 MaxValue := 0;
6150 ShowCount := 0;
6151 len := ((gScreenHeight div 3)*2 - 50) div LOADING_INTERLINE;
6152 if len < 1 then len := 1;
6153 SetLength(Msgs, len);
6154 for len := Low(Msgs) to High(Msgs) do
6155 Msgs[len] := '';
6156 NextMsg := 0;
6157 end;
6158 end;
6160 procedure Parse_Params(var pars: TParamStrValues);
6161 var
6162 i: Integer;
6163 s: String;
6164 begin
6165 SetLength(pars, 0);
6166 i := 1;
6167 while i <= ParamCount do
6168 begin
6169 s := ParamStr(i);
6170 if (s[1] = '-') and (Length(s) > 1) then
6171 begin
6172 if (s[2] = '-') and (Length(s) > 2) then
6173 begin // Îäèíî÷íûé ïàðàìåòð
6174 SetLength(pars, Length(pars) + 1);
6175 with pars[High(pars)] do
6176 begin
6177 Name := LowerCase(s);
6178 Value := '+';
6179 end;
6180 end
6181 else
6182 if (i < ParamCount) then
6183 begin // Ïàðàìåòð ñî çíà÷åíèåì
6184 Inc(i);
6185 SetLength(pars, Length(pars) + 1);
6186 with pars[High(pars)] do
6187 begin
6188 Name := LowerCase(s);
6189 Value := LowerCase(ParamStr(i));
6190 end;
6191 end;
6192 end;
6194 Inc(i);
6195 end;
6196 end;
6198 function Find_Param_Value(var pars: TParamStrValues; aName: String): String;
6199 var
6200 i: Integer;
6201 begin
6202 Result := '';
6203 for i := 0 to High(pars) do
6204 if pars[i].Name = aName then
6205 begin
6206 Result := pars[i].Value;
6207 Break;
6208 end;
6209 end;
6211 procedure g_Game_Process_Params();
6212 var
6213 pars: TParamStrValues;
6214 map: String;
6215 GMode, n: Byte;
6216 LimT, LimS: Integer;
6217 Opt: LongWord;
6218 Lives: Integer;
6219 s: String;
6220 Port: Integer;
6221 ip: String;
6222 F: TextFile;
6223 begin
6224 Parse_Params(pars);
6226 // Debug mode:
6227 s := Find_Param_Value(pars, '--debug');
6228 if (s <> '') then
6229 g_Game_SetDebugMode();
6231 // Connect when game loads
6232 ip := Find_Param_Value(pars, '-connect');
6234 if ip <> '' then
6235 begin
6236 s := Find_Param_Value(pars, '-port');
6237 if (s = '') or not TryStrToInt(s, Port) then
6238 Port := 25666;
6240 s := Find_Param_Value(pars, '-pw');
6242 g_Game_StartClient(ip, Port, s);
6243 Exit;
6244 end;
6246 // Start map when game loads:
6247 map := LowerCase(Find_Param_Value(pars, '-map'));
6248 if (map <> '') and (Pos('.wad:\', map) > 0) then
6249 begin
6250 // Game mode:
6251 s := Find_Param_Value(pars, '-gm');
6252 GMode := g_Game_TextToMode(s);
6253 if GMode = GM_NONE then GMode := GM_DM;
6254 if GMode = GM_SINGLE then GMode := GM_COOP;
6256 // Time limit:
6257 s := Find_Param_Value(pars, '-limt');
6258 if (s = '') or (not TryStrToInt(s, LimT)) then
6259 LimT := 0;
6260 if LimT < 0 then
6261 LimT := 0;
6263 // Goal limit:
6264 s := Find_Param_Value(pars, '-lims');
6265 if (s = '') or (not TryStrToInt(s, LimS)) then
6266 LimS := 0;
6267 if LimS < 0 then
6268 LimS := 0;
6270 // Lives limit:
6271 s := Find_Param_Value(pars, '-lives');
6272 if (s = '') or (not TryStrToInt(s, Lives)) then
6273 Lives := 0;
6274 if Lives < 0 then
6275 Lives := 0;
6277 // Options:
6278 s := Find_Param_Value(pars, '-opt');
6279 if (s = '') then
6280 Opt := GAME_OPTION_ALLOWEXIT or GAME_OPTION_BOTVSPLAYER or GAME_OPTION_BOTVSMONSTER
6281 else
6282 Opt := StrToIntDef(s, 0);
6283 if Opt = 0 then
6284 Opt := GAME_OPTION_ALLOWEXIT or GAME_OPTION_BOTVSPLAYER or GAME_OPTION_BOTVSMONSTER;
6286 // Close after map:
6287 s := Find_Param_Value(pars, '--close');
6288 if (s <> '') then
6289 gMapOnce := True;
6291 // Delete test map after play:
6292 s := Find_Param_Value(pars, '--testdelete');
6293 if (s <> '') then
6294 gMapToDelete := MapsDir + map;
6296 // Delete temporary WAD after play:
6297 s := Find_Param_Value(pars, '--tempdelete');
6298 if (s <> '') then
6299 begin
6300 gMapToDelete := MapsDir + map;
6301 gTempDelete := True;
6302 end;
6304 // Number of players:
6305 s := Find_Param_Value(pars, '-pl');
6306 if (s = '') then
6307 n := 1
6308 else
6309 n := StrToIntDef(s, 1);
6311 // Start:
6312 s := Find_Param_Value(pars, '-port');
6313 if (s = '') or not TryStrToInt(s, Port) then
6314 g_Game_StartCustom(map, GMode, LimT, LimS, Lives, Opt, n)
6315 else
6316 g_Game_StartServer(map, GMode, LimT, LimS, Lives, Opt, n, 0, Port);
6317 end;
6319 // Execute script when game loads:
6320 s := Find_Param_Value(pars, '-exec');
6321 if s <> '' then
6322 begin
6323 if Pos(':\', s) = 0 then
6324 s := GameDir + '/' + s;
6326 {$I-}
6327 AssignFile(F, s);
6328 Reset(F);
6329 if IOResult <> 0 then
6330 begin
6331 e_WriteLog(Format(_lc[I_SIMPLE_ERROR], ['Failed to read file: ' + s]), MSG_WARNING);
6332 g_Console_Add(Format(_lc[I_CONSOLE_ERROR_READ], [s]));
6333 CloseFile(F);
6334 Exit;
6335 end;
6336 e_WriteLog('Executing script: ' + s, MSG_NOTIFY);
6337 g_Console_Add(Format(_lc[I_CONSOLE_EXEC], [s]));
6339 while not EOF(F) do
6340 begin
6341 ReadLn(F, s);
6342 if IOResult <> 0 then
6343 begin
6344 e_WriteLog(Format(_lc[I_SIMPLE_ERROR], ['Failed to read file: ' + s]), MSG_WARNING);
6345 g_Console_Add(Format(_lc[I_CONSOLE_ERROR_READ], [s]));
6346 CloseFile(F);
6347 Exit;
6348 end;
6349 if Pos('#', s) <> 1 then // script comment
6350 g_Console_Process(s, True);
6351 end;
6353 CloseFile(F);
6354 {$I+}
6355 end;
6357 SetLength(pars, 0);
6358 end;
6360 end.