DEADSOFTWARE

removing dfwad writing abilities; removed "--testdelete" argument
[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 a: Integer;
4049 MapName: Char16;
4050 WadName: string;
4052 WAD: TWADEditor_1;
4053 MapList: SArray;
4054 time: Integer;
4056 begin
4057 a := Pos('.wad:\', gMapToDelete);
4058 if a = 0 then
4059 Exit;
4061 // Âûäåëÿåì èìÿ wad-ôàéëà è èìÿ êàðòû:
4062 WadName := Copy(gMapToDelete, 1, a + 3);
4063 Delete(gMapToDelete, 1, a + 5);
4064 gMapToDelete := UpperCase(gMapToDelete);
4065 MapName := '';
4066 CopyMemory(@MapName[0], @gMapToDelete[1], Min(16, Length(gMapToDelete)));
4069 // Èìÿ êàðòû íå ñòàíäàðòíîå òåñòîâîå:
4070 if MapName <> TEST_MAP_NAME then
4071 Exit;
4073 if not gTempDelete then
4074 begin
4075 time := g_GetFileTime(WadName);
4076 WAD := TWADEditor_1.Create();
4078 // ×èòàåì Wad-ôàéë:
4079 if not WAD.ReadFile(WadName) then
4080 begin // Íåò òàêîãî WAD-ôàéëà
4081 WAD.Free();
4082 Exit;
4083 end;
4085 // Ñîñòàâëÿåì ñïèñîê êàðò è èùåì íóæíóþ:
4086 WAD.CreateImage();
4087 MapList := WAD.GetResourcesList('');
4089 if MapList <> nil then
4090 for a := 0 to High(MapList) do
4091 if MapList[a] = MapName then
4092 begin
4093 // Óäàëÿåì è ñîõðàíÿåì:
4094 WAD.RemoveResource('', MapName);
4095 WAD.SaveTo(WadName);
4096 Break;
4097 end;
4099 WAD.Free();
4100 g_SetFileTime(WadName, time);
4101 end else
4103 if gTempDelete then DeleteFile(WadName);
4104 end;
4106 procedure GameCVars(P: SArray);
4107 var
4108 a, b: Integer;
4109 stat: TPlayerStatArray;
4110 cmd, s: string;
4111 config: TConfig;
4112 begin
4113 stat := nil;
4114 cmd := LowerCase(P[0]);
4115 if cmd = 'r_showfps' then
4116 begin
4117 if (Length(P) > 1) and
4118 ((P[1] = '1') or (P[1] = '0')) then
4119 gShowFPS := (P[1][1] = '1');
4121 if gShowFPS then
4122 g_Console_Add(_lc[I_MSG_SHOW_FPS_ON])
4123 else
4124 g_Console_Add(_lc[I_MSG_SHOW_FPS_OFF]);
4125 end
4126 else if (cmd = 'g_friendlyfire') and not g_Game_IsClient then
4127 begin
4128 with gGameSettings do
4129 begin
4130 if (Length(P) > 1) and
4131 ((P[1] = '1') or (P[1] = '0')) then
4132 begin
4133 if (P[1][1] = '1') then
4134 Options := Options or GAME_OPTION_TEAMDAMAGE
4135 else
4136 Options := Options and (not GAME_OPTION_TEAMDAMAGE);
4137 end;
4139 if (LongBool(Options and GAME_OPTION_TEAMDAMAGE)) then
4140 g_Console_Add(_lc[I_MSG_FRIENDLY_FIRE_ON])
4141 else
4142 g_Console_Add(_lc[I_MSG_FRIENDLY_FIRE_OFF]);
4144 if g_Game_IsNet then MH_SEND_GameSettings;
4145 end;
4146 end
4147 else if (cmd = 'g_weaponstay') and not g_Game_IsClient then
4148 begin
4149 with gGameSettings do
4150 begin
4151 if (Length(P) > 1) and
4152 ((P[1] = '1') or (P[1] = '0')) then
4153 begin
4154 if (P[1][1] = '1') then
4155 Options := Options or GAME_OPTION_WEAPONSTAY
4156 else
4157 Options := Options and (not GAME_OPTION_WEAPONSTAY);
4158 end;
4160 if (LongBool(Options and GAME_OPTION_WEAPONSTAY)) then
4161 g_Console_Add(_lc[I_MSG_WEAPONSTAY_ON])
4162 else
4163 g_Console_Add(_lc[I_MSG_WEAPONSTAY_OFF]);
4165 if g_Game_IsNet then MH_SEND_GameSettings;
4166 end;
4167 end
4168 else if cmd = 'g_gamemode' then
4169 begin
4170 a := g_Game_TextToMode(P[1]);
4171 if a = GM_SINGLE then a := GM_COOP;
4172 if (Length(P) > 1) and (a <> GM_NONE) and (not g_Game_IsClient) then
4173 begin
4174 gSwitchGameMode := a;
4175 if (gGameOn and (gGameSettings.GameMode = GM_SINGLE)) or
4176 (gState = STATE_INTERSINGLE) then
4177 gSwitchGameMode := GM_SINGLE;
4178 if not gGameOn then
4179 gGameSettings.GameMode := gSwitchGameMode;
4180 end;
4181 if gSwitchGameMode = gGameSettings.GameMode then
4182 g_Console_Add(Format(_lc[I_MSG_GAMEMODE_CURRENT],
4183 [g_Game_ModeToText(gGameSettings.GameMode)]))
4184 else
4185 g_Console_Add(Format(_lc[I_MSG_GAMEMODE_CHANGE],
4186 [g_Game_ModeToText(gGameSettings.GameMode),
4187 g_Game_ModeToText(gSwitchGameMode)]));
4188 end
4189 else if (cmd = 'g_allow_exit') and not g_Game_IsClient then
4190 begin
4191 with gGameSettings do
4192 begin
4193 if (Length(P) > 1) and
4194 ((P[1] = '1') or (P[1] = '0')) then
4195 begin
4196 if (P[1][1] = '1') then
4197 Options := Options or GAME_OPTION_ALLOWEXIT
4198 else
4199 Options := Options and (not GAME_OPTION_ALLOWEXIT);
4200 end;
4202 if (LongBool(Options and GAME_OPTION_ALLOWEXIT)) then
4203 g_Console_Add(_lc[I_MSG_ALLOWEXIT_ON])
4204 else
4205 g_Console_Add(_lc[I_MSG_ALLOWEXIT_OFF]);
4206 g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
4208 if g_Game_IsNet then MH_SEND_GameSettings;
4209 end;
4210 end
4211 else if (cmd = 'g_allow_monsters') and not g_Game_IsClient then
4212 begin
4213 with gGameSettings do
4214 begin
4215 if (Length(P) > 1) and
4216 ((P[1] = '1') or (P[1] = '0')) then
4217 begin
4218 if (P[1][1] = '1') then
4219 Options := Options or GAME_OPTION_MONSTERS
4220 else
4221 Options := Options and (not GAME_OPTION_MONSTERS);
4222 end;
4224 if (LongBool(Options and GAME_OPTION_MONSTERS)) then
4225 g_Console_Add(_lc[I_MSG_ALLOWMON_ON])
4226 else
4227 g_Console_Add(_lc[I_MSG_ALLOWMON_OFF]);
4228 g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
4230 if g_Game_IsNet then MH_SEND_GameSettings;
4231 end;
4232 end
4233 else if (cmd = 'g_bot_vsplayers') and not g_Game_IsClient then
4234 begin
4235 with gGameSettings do
4236 begin
4237 if (Length(P) > 1) and
4238 ((P[1] = '1') or (P[1] = '0')) then
4239 begin
4240 if (P[1][1] = '1') then
4241 Options := Options or GAME_OPTION_BOTVSPLAYER
4242 else
4243 Options := Options and (not GAME_OPTION_BOTVSPLAYER);
4244 end;
4246 if (LongBool(Options and GAME_OPTION_BOTVSPLAYER)) then
4247 g_Console_Add(_lc[I_MSG_BOTSVSPLAYERS_ON])
4248 else
4249 g_Console_Add(_lc[I_MSG_BOTSVSPLAYERS_OFF]);
4251 if g_Game_IsNet then MH_SEND_GameSettings;
4252 end;
4253 end
4254 else if (cmd = 'g_bot_vsmonsters') and not g_Game_IsClient then
4255 begin
4256 with gGameSettings do
4257 begin
4258 if (Length(P) > 1) and
4259 ((P[1] = '1') or (P[1] = '0')) then
4260 begin
4261 if (P[1][1] = '1') then
4262 Options := Options or GAME_OPTION_BOTVSMONSTER
4263 else
4264 Options := Options and (not GAME_OPTION_BOTVSMONSTER);
4265 end;
4267 if (LongBool(Options and GAME_OPTION_BOTVSMONSTER)) then
4268 g_Console_Add(_lc[I_MSG_BOTSVSMONSTERS_ON])
4269 else
4270 g_Console_Add(_lc[I_MSG_BOTSVSMONSTERS_OFF]);
4272 if g_Game_IsNet then MH_SEND_GameSettings;
4273 end;
4274 end
4275 else if (cmd = 'g_warmuptime') and not g_Game_IsClient then
4276 begin
4277 if Length(P) > 1 then
4278 begin
4279 if StrToIntDef(P[1], gGameSettings.WarmupTime) = 0 then
4280 gGameSettings.WarmupTime := 30
4281 else
4282 gGameSettings.WarmupTime := StrToIntDef(P[1], gGameSettings.WarmupTime);
4283 end;
4285 g_Console_Add(Format(_lc[I_MSG_WARMUP],
4286 [gGameSettings.WarmupTime]));
4287 g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
4288 end
4289 else if cmd = 'net_interp' then
4290 begin
4291 if (Length(P) > 1) then
4292 NetInterpLevel := StrToIntDef(P[1], NetInterpLevel);
4294 g_Console_Add('net_interp = ' + IntToStr(NetInterpLevel));
4295 config := TConfig.CreateFile(GameDir+'/'+CONFIG_FILENAME);
4296 config.WriteInt('Client', 'InterpolationSteps', NetInterpLevel);
4297 config.SaveFile(GameDir+'/'+CONFIG_FILENAME);
4298 config.Free();
4299 end
4300 else if cmd = 'net_forceplayerupdate' then
4301 begin
4302 if (Length(P) > 1) and
4303 ((P[1] = '1') or (P[1] = '0')) then
4304 NetForcePlayerUpdate := (P[1][1] = '1');
4306 if NetForcePlayerUpdate then
4307 g_Console_Add('net_forceplayerupdate = 1')
4308 else
4309 g_Console_Add('net_forceplayerupdate = 0');
4310 config := TConfig.CreateFile(GameDir+'/'+CONFIG_FILENAME);
4311 config.WriteBool('Client', 'ForcePlayerUpdate', NetForcePlayerUpdate);
4312 config.SaveFile(GameDir+'/'+CONFIG_FILENAME);
4313 config.Free();
4314 end
4315 else if cmd = 'net_predictself' then
4316 begin
4317 if (Length(P) > 1) and
4318 ((P[1] = '1') or (P[1] = '0')) then
4319 NetPredictSelf := (P[1][1] = '1');
4321 if NetPredictSelf then
4322 g_Console_Add('net_predictself = 1')
4323 else
4324 g_Console_Add('net_predictself = 0');
4325 config := TConfig.CreateFile(GameDir+'/'+CONFIG_FILENAME);
4326 config.WriteBool('Client', 'PredictSelf', NetPredictSelf);
4327 config.SaveFile(GameDir+'/'+CONFIG_FILENAME);
4328 config.Free();
4329 end
4330 else if cmd = 'sv_name' then
4331 begin
4332 if (Length(P) > 1) and (Length(P[1]) > 0) then
4333 begin
4334 NetServerName := P[1];
4335 if Length(NetServerName) > 64 then
4336 SetLength(NetServerName, 64);
4337 if g_Game_IsServer and g_Game_IsNet and NetUseMaster then
4338 g_Net_Slist_Update;
4339 end;
4341 g_Console_Add(cmd + ' = "' + NetServerName + '"');
4342 end
4343 else if cmd = 'sv_passwd' then
4344 begin
4345 if (Length(P) > 1) and (Length(P[1]) > 0) then
4346 begin
4347 NetPassword := P[1];
4348 if Length(NetPassword) > 24 then
4349 SetLength(NetPassword, 24);
4350 if g_Game_IsServer and g_Game_IsNet and NetUseMaster then
4351 g_Net_Slist_Update;
4352 end;
4354 g_Console_Add(cmd + ' = "' + AnsiLowerCase(NetPassword) + '"');
4355 end
4356 else if cmd = 'sv_maxplrs' then
4357 begin
4358 if (Length(P) > 1) then
4359 begin
4360 NetMaxClients := Min(Max(StrToIntDef(P[1], NetMaxClients), 1), NET_MAXCLIENTS);
4361 if g_Game_IsServer and g_Game_IsNet then
4362 begin
4363 b := 0;
4364 for a := 0 to High(NetClients) do
4365 if NetClients[a].Used then
4366 begin
4367 Inc(b);
4368 if b > NetMaxClients then
4369 begin
4370 s := g_Player_Get(NetClients[a].Player).Name;
4371 enet_peer_disconnect(NetClients[a].Peer, NET_DISC_FULL);
4372 g_Console_Add(Format(_lc[I_PLAYER_KICK], [s]));
4373 MH_SEND_GameEvent(NET_EV_PLAYER_KICK, 0, s);
4374 end;
4375 end;
4376 if NetUseMaster then
4377 g_Net_Slist_Update;
4378 end;
4379 end;
4381 g_Console_Add(cmd + ' = ' + IntToStr(NetMaxClients));
4382 end
4383 else if cmd = 'sv_public' then
4384 begin
4385 if (Length(P) > 1) then
4386 begin
4387 NetUseMaster := StrToIntDef(P[1], Byte(NetUseMaster)) > 0;
4388 if g_Game_IsServer and g_Game_IsNet then
4389 if NetUseMaster then
4390 begin
4391 if NetMPeer = nil then
4392 if not g_Net_Slist_Connect() then
4393 g_Console_Add(_lc[I_NET_MSG_ERROR] + _lc[I_NET_SLIST_ERROR]);
4394 g_Net_Slist_Update();
4395 end
4396 else
4397 if NetMPeer <> nil then
4398 g_Net_Slist_Disconnect();
4399 end;
4401 g_Console_Add(cmd + ' = ' + IntToStr(Byte(NetUseMaster)));
4402 end
4403 else if cmd = 'sv_intertime' then
4404 begin
4405 if (Length(P) > 1) then
4406 gDefInterTime := Min(Max(StrToIntDef(P[1], gDefInterTime), -1), 120);
4408 g_Console_Add(cmd + ' = ' + IntToStr(gDefInterTime));
4409 end
4410 else if cmd = 'p1_name' then
4411 begin
4412 if (Length(P) > 1) and gGameOn then
4413 begin
4414 if g_Game_IsClient then
4415 begin
4416 gPlayer1Settings.Name := b_Text_Unformat(P[1]);
4417 MC_SEND_PlayerSettings;
4418 end
4419 else
4420 if gPlayer1 <> nil then
4421 begin
4422 gPlayer1.Name := b_Text_Unformat(P[1]);
4423 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer1.UID);
4424 end
4425 else
4426 gPlayer1Settings.Name := b_Text_Unformat(P[1]);
4427 end;
4428 end
4429 else if cmd = 'p2_name' then
4430 begin
4431 if (Length(P) > 1) and gGameOn then
4432 begin
4433 if g_Game_IsClient then
4434 begin
4435 gPlayer2Settings.Name := b_Text_Unformat(P[1]);
4436 MC_SEND_PlayerSettings;
4437 end
4438 else
4439 if gPlayer2 <> nil then
4440 begin
4441 gPlayer2.Name := b_Text_Unformat(P[1]);
4442 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer2.UID);
4443 end
4444 else
4445 gPlayer2Settings.Name := b_Text_Unformat(P[1]);
4446 end;
4447 end
4448 else if cmd = 'p1_color' then
4449 begin
4450 if Length(P) > 3 then
4451 if g_Game_IsClient then
4452 begin
4453 gPlayer1Settings.Color := _RGB(EnsureRange(StrToIntDef(P[1], 0), 0, 255),
4454 EnsureRange(StrToIntDef(P[2], 0), 0, 255),
4455 EnsureRange(StrToIntDef(P[3], 0), 0, 255));
4456 MC_SEND_PlayerSettings;
4457 end
4458 else
4459 if gPlayer1 <> nil then
4460 begin
4461 gPlayer1.Model.SetColor(EnsureRange(StrToIntDef(P[1], 0), 0, 255),
4462 EnsureRange(StrToIntDef(P[2], 0), 0, 255),
4463 EnsureRange(StrToIntDef(P[3], 0), 0, 255));
4464 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer1.UID);
4465 end
4466 else
4467 gPlayer1Settings.Color := _RGB(EnsureRange(StrToIntDef(P[1], 0), 0, 255),
4468 EnsureRange(StrToIntDef(P[2], 0), 0, 255),
4469 EnsureRange(StrToIntDef(P[3], 0), 0, 255));
4470 end
4471 else if (cmd = 'p2_color') and not g_Game_IsNet then
4472 begin
4473 if Length(P) > 3 then
4474 if g_Game_IsClient then
4475 begin
4476 gPlayer2Settings.Color := _RGB(EnsureRange(StrToIntDef(P[1], 0), 0, 255),
4477 EnsureRange(StrToIntDef(P[2], 0), 0, 255),
4478 EnsureRange(StrToIntDef(P[3], 0), 0, 255));
4479 MC_SEND_PlayerSettings;
4480 end
4481 else
4482 if gPlayer2 <> nil then
4483 begin
4484 gPlayer2.Model.SetColor(EnsureRange(StrToIntDef(P[1], 0), 0, 255),
4485 EnsureRange(StrToIntDef(P[2], 0), 0, 255),
4486 EnsureRange(StrToIntDef(P[3], 0), 0, 255));
4487 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer2.UID);
4488 end
4489 else
4490 gPlayer2Settings.Color := _RGB(EnsureRange(StrToIntDef(P[1], 0), 0, 255),
4491 EnsureRange(StrToIntDef(P[2], 0), 0, 255),
4492 EnsureRange(StrToIntDef(P[3], 0), 0, 255));
4493 end
4494 else if gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT] then
4495 begin
4496 if cmd = 'r_showtime' then
4497 begin
4498 if (Length(P) > 1) and
4499 ((P[1] = '1') or (P[1] = '0')) then
4500 gShowTime := (P[1][1] = '1');
4502 if gShowTime then
4503 g_Console_Add(_lc[I_MSG_TIME_ON])
4504 else
4505 g_Console_Add(_lc[I_MSG_TIME_OFF]);
4506 end
4507 else if cmd = 'r_showscore' then
4508 begin
4509 if (Length(P) > 1) and
4510 ((P[1] = '1') or (P[1] = '0')) then
4511 gShowGoals := (P[1][1] = '1');
4513 if gShowGoals then
4514 g_Console_Add(_lc[I_MSG_SCORE_ON])
4515 else
4516 g_Console_Add(_lc[I_MSG_SCORE_OFF]);
4517 end
4518 else if cmd = 'r_showstat' then
4519 begin
4520 if (Length(P) > 1) and
4521 ((P[1] = '1') or (P[1] = '0')) then
4522 gShowStat := (P[1][1] = '1');
4524 if gShowStat then
4525 g_Console_Add(_lc[I_MSG_STATS_ON])
4526 else
4527 g_Console_Add(_lc[I_MSG_STATS_OFF]);
4528 end
4529 else if cmd = 'r_showkillmsg' then
4530 begin
4531 if (Length(P) > 1) and
4532 ((P[1] = '1') or (P[1] = '0')) then
4533 gShowKillMsg := (P[1][1] = '1');
4535 if gShowKillMsg then
4536 g_Console_Add(_lc[I_MSG_KILL_MSGS_ON])
4537 else
4538 g_Console_Add(_lc[I_MSG_KILL_MSGS_OFF]);
4539 end
4540 else if cmd = 'r_showlives' then
4541 begin
4542 if (Length(P) > 1) and
4543 ((P[1] = '1') or (P[1] = '0')) then
4544 gShowLives := (P[1][1] = '1');
4546 if gShowLives then
4547 g_Console_Add(_lc[I_MSG_LIVES_ON])
4548 else
4549 g_Console_Add(_lc[I_MSG_LIVES_OFF]);
4550 end
4551 else if cmd = 'r_showspect' then
4552 begin
4553 if (Length(P) > 1) and
4554 ((P[1] = '1') or (P[1] = '0')) then
4555 gSpectHUD := (P[1][1] = '1');
4557 if gSpectHUD then
4558 g_Console_Add(_lc[I_MSG_SPECT_HUD_ON])
4559 else
4560 g_Console_Add(_lc[I_MSG_SPECT_HUD_OFF]);
4561 end
4562 else if cmd = 'r_showping' then
4563 begin
4564 if (Length(P) > 1) and
4565 ((P[1] = '1') or (P[1] = '0')) then
4566 gShowPing := (P[1][1] = '1');
4568 if gShowPing then
4569 g_Console_Add(_lc[I_MSG_PING_ON])
4570 else
4571 g_Console_Add(_lc[I_MSG_PING_OFF]);
4572 end
4573 else if (cmd = 'g_scorelimit') and not g_Game_IsClient then
4574 begin
4575 if Length(P) > 1 then
4576 begin
4577 if StrToIntDef(P[1], gGameSettings.GoalLimit) = 0 then
4578 gGameSettings.GoalLimit := 0
4579 else
4580 begin
4581 b := 0;
4583 if gGameSettings.GameMode = GM_DM then
4584 begin // DM
4585 stat := g_Player_GetStats();
4586 if stat <> nil then
4587 for a := 0 to High(stat) do
4588 if stat[a].Frags > b then
4589 b := stat[a].Frags;
4590 end
4591 else // TDM/CTF
4592 b := Max(gTeamStat[TEAM_RED].Goals, gTeamStat[TEAM_BLUE].Goals);
4594 gGameSettings.GoalLimit := Max(StrToIntDef(P[1], gGameSettings.GoalLimit), b);
4595 end;
4597 if g_Game_IsNet then MH_SEND_GameSettings;
4598 end;
4600 g_Console_Add(Format(_lc[I_MSG_SCORE_LIMIT], [gGameSettings.GoalLimit]));
4601 end
4602 else if (cmd = 'g_timelimit') and not g_Game_IsClient then
4603 begin
4604 if (Length(P) > 1) and (StrToIntDef(P[1], -1) >= 0) then
4605 gGameSettings.TimeLimit := StrToIntDef(P[1], -1);
4607 g_Console_Add(Format(_lc[I_MSG_TIME_LIMIT],
4608 [gGameSettings.TimeLimit div 3600,
4609 (gGameSettings.TimeLimit div 60) mod 60,
4610 gGameSettings.TimeLimit mod 60]));
4611 if g_Game_IsNet then MH_SEND_GameSettings;
4612 end
4613 else if (cmd = 'g_maxlives') and not g_Game_IsClient then
4614 begin
4615 if Length(P) > 1 then
4616 begin
4617 if StrToIntDef(P[1], gGameSettings.MaxLives) = 0 then
4618 gGameSettings.MaxLives := 0
4619 else
4620 begin
4621 b := 0;
4622 stat := g_Player_GetStats();
4623 if stat <> nil then
4624 for a := 0 to High(stat) do
4625 if stat[a].Lives > b then
4626 b := stat[a].Lives;
4627 gGameSettings.MaxLives :=
4628 Max(StrToIntDef(P[1], gGameSettings.MaxLives), b);
4629 end;
4630 end;
4632 g_Console_Add(Format(_lc[I_MSG_LIVES],
4633 [gGameSettings.MaxLives]));
4634 if g_Game_IsNet then MH_SEND_GameSettings;
4635 end;
4636 end;
4637 end;
4639 procedure DebugCommands(P: SArray);
4640 var
4641 a, b: Integer;
4642 cmd: string;
4643 //pt: TPoint;
4644 begin
4645 // Êîìàíäû îòëàäî÷íîãî ðåæèìà:
4646 if gDebugMode then
4647 begin
4648 cmd := LowerCase(P[0]);
4649 if cmd = 'd_window' then
4650 begin
4651 g_Console_Add(Format('gWinPosX = %d, gWinPosY %d', [gWinPosX, gWinPosY]));
4652 g_Console_Add(Format('gWinRealPosX = %d, gWinRealPosY %d', [gWinRealPosX, gWinRealPosY]));
4653 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth, gScreenHeight]));
4654 g_Console_Add(Format('gWinSizeX = %d, gWinSizeY = %d', [gWinSizeX, gWinSizeY]));
4655 g_Console_Add(Format('Frame X = %d, Y = %d, Caption Y = %d', [gWinFrameX, gWinFrameY, gWinCaption]));
4656 end
4657 else if cmd = 'd_sounds' then
4658 begin
4659 if (Length(P) > 1) and
4660 ((P[1] = '1') or (P[1] = '0')) then
4661 g_Debug_Sounds := (P[1][1] = '1');
4663 g_Console_Add(Format('d_sounds is %d', [Byte(g_Debug_Sounds)]));
4664 end
4665 else if cmd = 'd_frames' then
4666 begin
4667 if (Length(P) > 1) and
4668 ((P[1] = '1') or (P[1] = '0')) then
4669 g_Debug_Frames := (P[1][1] = '1');
4671 g_Console_Add(Format('d_frames is %d', [Byte(g_Debug_Frames)]));
4672 end
4673 else if cmd = 'd_winmsg' then
4674 begin
4675 if (Length(P) > 1) and
4676 ((P[1] = '1') or (P[1] = '0')) then
4677 g_Debug_WinMsgs := (P[1][1] = '1');
4679 g_Console_Add(Format('d_winmsg is %d', [Byte(g_Debug_WinMsgs)]));
4680 end
4681 else if (cmd = 'd_monoff') and not g_Game_IsNet then
4682 begin
4683 if (Length(P) > 1) and
4684 ((P[1] = '1') or (P[1] = '0')) then
4685 g_Debug_MonsterOff := (P[1][1] = '1');
4687 g_Console_Add(Format('d_monoff is %d', [Byte(g_debug_MonsterOff)]));
4688 end
4689 else if (cmd = 'd_botoff') and not g_Game_IsNet then
4690 begin
4691 if Length(P) > 1 then
4692 case P[1][1] of
4693 '0': g_debug_BotAIOff := 0;
4694 '1': g_debug_BotAIOff := 1;
4695 '2': g_debug_BotAIOff := 2;
4696 '3': g_debug_BotAIOff := 3;
4697 end;
4699 g_Console_Add(Format('d_botoff is %d', [g_debug_BotAIOff]));
4700 end
4701 else if cmd = 'd_monster' then
4702 begin
4703 if gGameOn and (gPlayer1 <> nil) and (gPlayer1.Live) and (not g_Game_IsNet) then
4704 if Length(P) < 2 then
4705 begin
4706 g_Console_Add(cmd + ' [ID | Name] [behaviour]');
4707 g_Console_Add('ID | Name');
4708 for b := MONSTER_DEMON to MONSTER_MAN do
4709 g_Console_Add(Format('%2d | %s', [b, g_Monsters_GetNameByID(b)]));
4710 end else
4711 begin
4712 a := StrToIntDef(P[1], 0);
4713 if (a < MONSTER_DEMON) or (a > MONSTER_MAN) then
4714 a := g_Monsters_GetIDByName(P[1]);
4716 if (a < MONSTER_DEMON) or (a > MONSTER_MAN) then
4717 g_Console_Add(Format(_lc[I_MSG_NO_MONSTER], [P[1]]))
4718 else
4719 begin
4720 with gPlayer1.Obj do
4721 b := g_Monsters_Create(a,
4722 X + Rect.X + (Rect.Width div 2),
4723 Y + Rect.Y + Rect.Height,
4724 gPlayer1.Direction, True);
4725 if (Length(P) > 2) and (b >= 0) then
4726 gMonsters[b].MonsterBehaviour := Min(Max(StrToIntDef(P[2], BH_NORMAL), BH_NORMAL), BH_GOOD);
4727 end;
4728 end;
4729 end
4730 else if (cmd = 'd_health') then
4731 begin
4732 if (Length(P) > 1) and
4733 ((P[1] = '1') or (P[1] = '0')) then
4734 g_debug_HealthBar := (P[1][1] = '1');
4736 g_Console_Add(Format('d_health is %d', [Byte(g_debug_HealthBar)]));
4737 end
4738 else if (cmd = 'd_player') then
4739 begin
4740 if (Length(P) > 1) and
4741 ((P[1] = '1') or (P[1] = '0')) then
4742 g_debug_Player := (P[1][1] = '1');
4744 g_Console_Add(Format(cmd + ' is %d', [Byte(g_Debug_Player)]));
4745 end
4746 else if (cmd = 'd_joy') then
4747 begin
4748 for a := 1 to 8 do
4749 g_Console_Add(e_JoystickStateToString(a));
4750 end;
4751 end
4752 else
4753 g_Console_Add(_lc[I_MSG_NOT_DEBUG]);
4754 end;
4756 procedure GameCommands(P: SArray);
4757 var
4758 a, b: Integer;
4759 s, pw: String;
4760 chstr: string;
4761 cmd: string;
4762 pl: pTNetClient = nil;
4763 plr: TPlayer;
4764 prt: Word;
4765 nm: Boolean;
4766 listen: LongWord;
4767 begin
4768 // Îáùèå êîìàíäû:
4769 cmd := LowerCase(P[0]);
4770 chstr := '';
4771 if (cmd = 'quit') or
4772 (cmd = 'exit') then
4773 begin
4774 g_Game_Free();
4775 g_Game_Quit();
4776 Exit;
4777 end
4778 else if cmd = 'pause' then
4779 begin
4780 if (g_ActiveWindow = nil) then
4781 g_Game_Pause(not gPause);
4782 end
4783 else if cmd = 'endgame' then
4784 gExit := EXIT_SIMPLE
4785 else if cmd = 'restart' then
4786 begin
4787 if gGameOn or (gState in [STATE_INTERSINGLE, STATE_INTERCUSTOM]) then
4788 begin
4789 if g_Game_IsClient then
4790 begin
4791 g_Console_Add(_lc[I_MSG_SERVERONLY]);
4792 Exit;
4793 end;
4794 g_Game_Restart();
4795 end else
4796 g_Console_Add(_lc[I_MSG_NOT_GAME]);
4797 end
4798 else if cmd = 'kick' then
4799 begin
4800 if g_Game_IsServer then
4801 begin
4802 if Length(P) < 2 then
4803 begin
4804 g_Console_Add('kick <name>');
4805 Exit;
4806 end;
4807 if P[1] = '' then
4808 begin
4809 g_Console_Add('kick <name>');
4810 Exit;
4811 end;
4813 if g_Game_IsNet then
4814 pl := g_Net_Client_ByName(P[1]);
4815 if (pl <> nil) then
4816 begin
4817 s := g_Net_ClientName_ByID(pl^.ID);
4818 enet_peer_disconnect(pl^.Peer, NET_DISC_KICK);
4819 g_Console_Add(Format(_lc[I_PLAYER_KICK], [s]));
4820 MH_SEND_GameEvent(NET_EV_PLAYER_KICK, 0, s);
4821 if NetUseMaster then
4822 g_Net_Slist_Update;
4823 end else if gPlayers <> nil then
4824 for a := Low(gPlayers) to High(gPlayers) do
4825 if gPlayers[a] <> nil then
4826 if Copy(LowerCase(gPlayers[a].Name), 1, Length(P[1])) = LowerCase(P[1]) then
4827 begin
4828 // Íå îòêëþ÷àòü îñíîâíûõ èãðîêîâ â ñèíãëå
4829 if not(gPlayers[a] is TBot) and (gGameSettings.GameType = GT_SINGLE) then
4830 continue;
4831 gPlayers[a].Lives := 0;
4832 gPlayers[a].Kill(K_SIMPLEKILL, 0, HIT_DISCON);
4833 g_Console_Add(Format(_lc[I_PLAYER_LEAVE], [gPlayers[a].Name]), True);
4834 g_Player_Remove(gPlayers[a].UID);
4835 if NetUseMaster then
4836 g_Net_Slist_Update;
4837 // Åñëè íå ïåðåìåøàòü, ïðè äîáàâëåíèè íîâûõ áîòîâ ïîÿâÿòñÿ ñòàðûå
4838 g_Bot_MixNames();
4839 end;
4840 end else
4841 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
4842 end
4843 else if cmd = 'kick_id' then
4844 begin
4845 if g_Game_IsServer and g_Game_IsNet then
4846 begin
4847 if Length(P) < 2 then
4848 begin
4849 g_Console_Add('kick_id <client ID>');
4850 Exit;
4851 end;
4852 if P[1] = '' then
4853 begin
4854 g_Console_Add('kick_id <client ID>');
4855 Exit;
4856 end;
4858 a := StrToIntDef(P[1], 0);
4859 if (NetClients <> nil) and (a <= High(NetClients)) then
4860 begin
4861 if NetClients[a].Used and (NetClients[a].Peer <> nil) then
4862 begin
4863 s := g_Net_ClientName_ByID(NetClients[a].ID);
4864 enet_peer_disconnect(NetClients[a].Peer, NET_DISC_KICK);
4865 g_Console_Add(Format(_lc[I_PLAYER_KICK], [s]));
4866 MH_SEND_GameEvent(NET_EV_PLAYER_KICK, 0, s);
4867 if NetUseMaster then
4868 g_Net_Slist_Update;
4869 end;
4870 end;
4871 end else
4872 g_Console_Add(_lc[I_MSG_SERVERONLY]);
4873 end
4874 else if cmd = 'ban' then
4875 begin
4876 if g_Game_IsServer and g_Game_IsNet then
4877 begin
4878 if Length(P) < 2 then
4879 begin
4880 g_Console_Add('ban <name>');
4881 Exit;
4882 end;
4883 if P[1] = '' then
4884 begin
4885 g_Console_Add('ban <name>');
4886 Exit;
4887 end;
4889 pl := g_Net_Client_ByName(P[1]);
4890 if (pl <> nil) then
4891 begin
4892 s := g_Net_ClientName_ByID(pl^.ID);
4893 g_Net_BanHost(pl^.Peer^.address.host, False);
4894 enet_peer_disconnect(pl^.Peer, NET_DISC_TEMPBAN);
4895 g_Console_Add(Format(_lc[I_PLAYER_BAN], [s]));
4896 MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s);
4897 if NetUseMaster then
4898 g_Net_Slist_Update;
4899 end else
4900 g_Console_Add(Format(_lc[I_NET_ERR_NAME404], [P[1]]));
4901 end else
4902 g_Console_Add(_lc[I_MSG_SERVERONLY]);
4903 end
4904 else if cmd = 'ban_id' then
4905 begin
4906 if g_Game_IsServer and g_Game_IsNet then
4907 begin
4908 if Length(P) < 2 then
4909 begin
4910 g_Console_Add('ban_id <client ID>');
4911 Exit;
4912 end;
4913 if P[1] = '' then
4914 begin
4915 g_Console_Add('ban_id <client ID>');
4916 Exit;
4917 end;
4919 a := StrToIntDef(P[1], 0);
4920 if (NetClients <> nil) and (a <= High(NetClients)) then
4921 if NetClients[a].Used and (NetClients[a].Peer <> nil) then
4922 begin
4923 s := g_Net_ClientName_ByID(NetClients[a].ID);
4924 g_Net_BanHost(NetClients[a].Peer^.address.host, False);
4925 enet_peer_disconnect(NetClients[a].Peer, NET_DISC_TEMPBAN);
4926 g_Console_Add(Format(_lc[I_PLAYER_BAN], [s]));
4927 MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s);
4928 if NetUseMaster then
4929 g_Net_Slist_Update;
4930 end;
4931 end else
4932 g_Console_Add(_lc[I_MSG_SERVERONLY]);
4933 end
4934 else if cmd = 'permban' then
4935 begin
4936 if g_Game_IsServer and g_Game_IsNet then
4937 begin
4938 if Length(P) < 2 then
4939 begin
4940 g_Console_Add('permban <name>');
4941 Exit;
4942 end;
4943 if P[1] = '' then
4944 begin
4945 g_Console_Add('permban <name>');
4946 Exit;
4947 end;
4949 pl := g_Net_Client_ByName(P[1]);
4950 if (pl <> nil) then
4951 begin
4952 s := g_Net_ClientName_ByID(pl^.ID);
4953 g_Net_BanHost(pl^.Peer^.address.host);
4954 enet_peer_disconnect(pl^.Peer, NET_DISC_BAN);
4955 g_Net_SaveBanList();
4956 g_Console_Add(Format(_lc[I_PLAYER_BAN], [s]));
4957 MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s);
4958 if NetUseMaster then
4959 g_Net_Slist_Update;
4960 end else
4961 g_Console_Add(Format(_lc[I_NET_ERR_NAME404], [P[1]]));
4962 end else
4963 g_Console_Add(_lc[I_MSG_SERVERONLY]);
4964 end
4965 else if cmd = 'permban_id' then
4966 begin
4967 if g_Game_IsServer and g_Game_IsNet then
4968 begin
4969 if Length(P) < 2 then
4970 begin
4971 g_Console_Add('permban_id <client ID>');
4972 Exit;
4973 end;
4974 if P[1] = '' then
4975 begin
4976 g_Console_Add('permban_id <client ID>');
4977 Exit;
4978 end;
4980 a := StrToIntDef(P[1], 0);
4981 if (NetClients <> nil) and (a <= High(NetClients)) then
4982 if NetClients[a].Used and (NetClients[a].Peer <> nil) then
4983 begin
4984 s := g_Net_ClientName_ByID(NetClients[a].ID);
4985 g_Net_BanHost(NetClients[a].Peer^.address.host);
4986 enet_peer_disconnect(NetClients[a].Peer, NET_DISC_BAN);
4987 g_Net_SaveBanList();
4988 g_Console_Add(Format(_lc[I_PLAYER_BAN], [s]));
4989 MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s);
4990 if NetUseMaster then
4991 g_Net_Slist_Update;
4992 end;
4993 end else
4994 g_Console_Add(_lc[I_MSG_SERVERONLY]);
4995 end
4996 else if cmd = 'unban' then
4997 begin
4998 if g_Game_IsServer and g_Game_IsNet then
4999 begin
5000 if Length(P) < 2 then
5001 begin
5002 g_Console_Add('unban <IP Address>');
5003 Exit;
5004 end;
5005 if P[1] = '' then
5006 begin
5007 g_Console_Add('unban <IP Address>');
5008 Exit;
5009 end;
5011 if g_Net_UnbanHost(P[1]) then
5012 begin
5013 g_Console_Add(Format(_lc[I_MSG_UNBAN_OK], [P[1]]));
5014 g_Net_SaveBanList();
5015 end else
5016 g_Console_Add(Format(_lc[I_MSG_UNBAN_FAIL], [P[1]]));
5017 end else
5018 g_Console_Add(_lc[I_MSG_SERVERONLY]);
5019 end
5020 else if cmd = 'clientlist' then
5021 begin
5022 if g_Game_IsServer and g_Game_IsNet then
5023 begin
5024 b := 0;
5025 if NetClients <> nil then
5026 for a := Low(NetClients) to High(NetClients) do
5027 if NetClients[a].Used and (NetClients[a].Peer <> nil) then
5028 begin
5029 plr := g_Player_Get(NetClients[a].Player);
5030 if plr = nil then continue;
5031 Inc(b);
5032 g_Console_Add(Format('#%2d: %-15s | %s', [a,
5033 IpToStr(NetClients[a].Peer^.address.host), plr.Name]));
5034 end;
5035 if b = 0 then
5036 g_Console_Add(_lc[I_MSG_NOCLIENTS]);
5037 end else
5038 g_Console_Add(_lc[I_MSG_SERVERONLY]);
5039 end
5040 else if cmd = 'connect' then
5041 begin
5042 if (NetMode = NET_NONE) then
5043 begin
5044 if Length(P) < 2 then
5045 begin
5046 g_Console_Add('connect <IP> [port] [password]');
5047 Exit;
5048 end;
5049 if P[1] = '' then
5050 begin
5051 g_Console_Add('connect <IP> [port] [password]');
5052 Exit;
5053 end;
5055 if Length(P) > 2 then
5056 prt := StrToIntDef(P[2], 25666)
5057 else
5058 prt := 25666;
5060 if Length(P) > 3 then
5061 pw := P[3]
5062 else
5063 pw := '';
5065 g_Game_StartClient(P[1], prt, pw);
5066 end;
5067 end
5068 else if cmd = 'disconnect' then
5069 begin
5070 if (NetMode = NET_CLIENT) then
5071 g_Net_Disconnect();
5072 end
5073 else if cmd = 'reconnect' then
5074 begin
5075 if (NetMode = NET_SERVER) then
5076 Exit;
5078 if (NetMode = NET_CLIENT) then
5079 begin
5080 g_Net_Disconnect();
5081 gExit := EXIT_SIMPLE;
5082 EndGame;
5083 end;
5085 //TODO: Use last successful password to reconnect, instead of ''
5086 g_Game_StartClient(NetClientIP, NetClientPort, '');
5087 end
5088 else if (cmd = 'addbot') or
5089 (cmd = 'bot_add') then
5090 begin
5091 if Length(P) > 1 then
5092 g_Bot_Add(TEAM_NONE, StrToIntDef(P[1], 2))
5093 else
5094 g_Bot_Add(TEAM_NONE, 2);
5095 end
5096 else if cmd = 'bot_addlist' then
5097 begin
5098 if Length(P) > 1 then
5099 if Length(P) = 2 then
5100 g_Bot_AddList(TEAM_NONE, P[1], StrToIntDef(P[1], -1))
5101 else
5102 g_Bot_AddList(IfThen(P[2] = 'red', TEAM_RED, TEAM_BLUE), P[1], StrToIntDef(P[1], -1));
5103 end
5104 else if cmd = 'bot_removeall' then
5105 g_Bot_RemoveAll()
5106 else if cmd = 'chat' then
5107 begin
5108 if g_Game_IsNet then
5109 begin
5110 if Length(P) > 1 then
5111 begin
5112 for a := 1 to High(P) do
5113 chstr := chstr + P[a] + ' ';
5115 if Length(chstr) > 200 then SetLength(chstr, 200);
5117 if Length(chstr) < 1 then
5118 begin
5119 g_Console_Add('chat <text>');
5120 Exit;
5121 end;
5123 chstr := b_Text_Format(chstr);
5124 if g_Game_IsClient then
5125 MC_SEND_Chat(chstr, NET_CHAT_PLAYER)
5126 else
5127 MH_SEND_Chat(gPlayer1Settings.Name + ': ' + chstr, NET_CHAT_PLAYER);
5128 end
5129 else
5130 g_Console_Add('chat <text>');
5131 end else
5132 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
5133 end
5134 else if cmd = 'teamchat' then
5135 begin
5136 if g_Game_IsNet and (gGameSettings.GameMode in [GM_TDM, GM_CTF]) then
5137 begin
5138 if Length(P) > 1 then
5139 begin
5140 for a := 1 to High(P) do
5141 chstr := chstr + P[a] + ' ';
5143 if Length(chstr) > 200 then SetLength(chstr, 200);
5145 if Length(chstr) < 1 then
5146 begin
5147 g_Console_Add('teamchat <text>');
5148 Exit;
5149 end;
5151 chstr := b_Text_Format(chstr);
5152 if g_Game_IsClient then
5153 MC_SEND_Chat(chstr, NET_CHAT_TEAM)
5154 else
5155 MH_SEND_Chat(gPlayer1Settings.Name + ': ' + chstr, NET_CHAT_TEAM,
5156 gPlayer1Settings.Team);
5157 end
5158 else
5159 g_Console_Add('teamchat <text>');
5160 end else
5161 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
5162 end
5163 else if cmd = 'game' then
5164 begin
5165 if gGameSettings.GameType <> GT_NONE then
5166 begin
5167 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
5168 Exit;
5169 end;
5170 if Length(P) = 1 then
5171 begin
5172 g_Console_Add(cmd + ' <WAD> [MAP] [# players]');
5173 Exit;
5174 end;
5175 // Èãðà åù¸ íå çàïóùåíà, ñíà÷àëà íàì íàäî çàãðóçèòü êàêîé-òî WAD
5176 if Pos('.wad', LowerCase(P[1])) = 0 then
5177 P[1] := P[1] + '.wad';
5179 if FileExists(MapsDir + P[1]) then
5180 begin
5181 // Åñëè êàðòà íå óêàçàíà, áåð¸ì ïåðâóþ êàðòó â ôàéëå
5182 if Length(P) < 3 then
5183 begin
5184 SetLength(P, 3);
5185 P[2] := g_Game_GetFirstMap(MapsDir + P[1]);
5186 end;
5188 s := P[1] + ':\' + UpperCase(P[2]);
5190 if g_Map_Exist(MapsDir + s) then
5191 begin
5192 // Çàïóñêàåì ñâîþ èãðó
5193 g_Game_Free();
5194 with gGameSettings do
5195 begin
5196 GameMode := g_Game_TextToMode(gcGameMode);
5197 if gSwitchGameMode <> GM_NONE then
5198 GameMode := gSwitchGameMode;
5199 if GameMode = GM_NONE then GameMode := GM_DM;
5200 if GameMode = GM_SINGLE then GameMode := GM_COOP;
5201 b := 1;
5202 if Length(P) >= 4 then
5203 b := StrToIntDef(P[3], 1);
5204 g_Game_StartCustom(s, GameMode, TimeLimit,
5205 GoalLimit, MaxLives, Options, b);
5206 end;
5207 end
5208 else
5209 if P[2] = '' then
5210 g_Console_Add(Format(_lc[I_MSG_NO_MAPS], [P[1]]))
5211 else
5212 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [UpperCase(P[2])]));
5213 end else
5214 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]));
5215 end
5216 else if cmd = 'host' then
5217 begin
5218 if gGameSettings.GameType <> GT_NONE then
5219 begin
5220 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
5221 Exit;
5222 end;
5223 if Length(P) < 4 then
5224 begin
5225 g_Console_Add(cmd + ' <listen IP> <port> <WAD> [MAP] [# players]');
5226 Exit;
5227 end;
5228 if not StrToIp(P[1], listen) then
5229 Exit;
5230 prt := StrToIntDef(P[2], 25666);
5232 if Pos('.wad', LowerCase(P[3])) = 0 then
5233 P[3] := P[3] + '.wad';
5235 if FileExists(MapsDir + P[3]) then
5236 begin
5237 // Åñëè êàðòà íå óêàçàíà, áåð¸ì ïåðâóþ êàðòó â ôàéëå
5238 if Length(P) < 5 then
5239 begin
5240 SetLength(P, 5);
5241 P[4] := g_Game_GetFirstMap(MapsDir + P[1]);
5242 end;
5244 s := P[3] + ':\' + UpperCase(P[4]);
5246 if g_Map_Exist(MapsDir + s) then
5247 begin
5248 // Çàïóñêàåì ñâîþ èãðó
5249 g_Game_Free();
5250 with gGameSettings do
5251 begin
5252 GameMode := g_Game_TextToMode(gcGameMode);
5253 if gSwitchGameMode <> GM_NONE then
5254 GameMode := gSwitchGameMode;
5255 if GameMode = GM_NONE then GameMode := GM_DM;
5256 if GameMode = GM_SINGLE then GameMode := GM_COOP;
5257 b := 0;
5258 if Length(P) >= 6 then
5259 b := StrToIntDef(P[5], 0);
5260 g_Game_StartServer(s, GameMode, TimeLimit,
5261 GoalLimit, MaxLives, Options, b, listen, prt);
5262 end;
5263 end
5264 else
5265 if P[4] = '' then
5266 g_Console_Add(Format(_lc[I_MSG_NO_MAPS], [P[3]]))
5267 else
5268 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [UpperCase(P[4])]));
5269 end else
5270 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[3]]));
5271 end
5272 else if cmd = 'map' then
5273 begin
5274 if Length(P) = 1 then
5275 begin
5276 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
5277 begin
5278 g_Console_Add(cmd + ' <MAP>');
5279 g_Console_Add(cmd + ' <WAD> [MAP]');
5280 end else
5281 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
5282 end else
5283 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
5284 begin
5285 // Èä¸ò ñâîÿ èãðà èëè ñåðâåð
5286 if Length(P) < 3 then
5287 begin
5288 // Ïåðâûé ïàðàìåòð - ëèáî êàðòà, ëèáî èìÿ WAD ôàéëà
5289 s := UpperCase(P[1]);
5290 if g_Map_Exist(MapsDir + gGameSettings.WAD + ':\' + s) then
5291 begin // Êàðòà íàøëàñü
5292 gExitByTrigger := False;
5293 if gGameOn then
5294 begin // Èä¸ò èãðà - çàâåðøàåì óðîâåíü
5295 gNextMap := s;
5296 gExit := EXIT_ENDLEVELCUSTOM;
5297 end
5298 else // Èíòåðìèññèÿ - ñðàçó çàãðóæàåì êàðòó
5299 g_Game_ChangeMap(s);
5300 end else
5301 begin
5302 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [s]));
5303 // Òàêîé êàðòû íåò, èùåì WAD ôàéë
5304 if Pos('.wad', LowerCase(P[1])) = 0 then
5305 P[1] := P[1] + '.wad';
5307 if FileExists(MapsDir + P[1]) then
5308 begin
5309 // Ïàðàìåòðà êàðòû íåò, ïîýòîìó ñòàâèì ïåðâóþ èç ôàéëà
5310 SetLength(P, 3);
5311 P[2] := g_Game_GetFirstMap(MapsDir + P[1]);
5313 s := P[1] + ':\' + P[2];
5315 if g_Map_Exist(MapsDir + s) then
5316 begin
5317 gExitByTrigger := False;
5318 if gGameOn then
5319 begin // Èä¸ò èãðà - çàâåðøàåì óðîâåíü
5320 gNextMap := s;
5321 gExit := EXIT_ENDLEVELCUSTOM;
5322 end
5323 else // Èíòåðìèññèÿ - ñðàçó çàãðóæàåì êàðòó
5324 g_Game_ChangeMap(s);
5325 end else
5326 if P[2] = '' then
5327 g_Console_Add(Format(_lc[I_MSG_NO_MAPS], [P[1]]))
5328 else
5329 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [P[2]]));
5330 end else
5331 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]));
5332 end;
5333 end else
5334 begin
5335 // Óêàçàíî äâà ïàðàìåòðà, çíà÷èò ïåðâûé - WAD ôàéë, à âòîðîé - êàðòà
5336 if Pos('.wad', LowerCase(P[1])) = 0 then
5337 P[1] := P[1] + '.wad';
5339 if FileExists(MapsDir + P[1]) then
5340 begin
5341 // Íàøëè WAD ôàéë
5342 P[2] := UpperCase(P[2]);
5343 s := P[1] + ':\' + P[2];
5345 if g_Map_Exist(MapsDir + s) then
5346 begin // Íàøëè êàðòó
5347 gExitByTrigger := False;
5348 if gGameOn then
5349 begin // Èä¸ò èãðà - çàâåðøàåì óðîâåíü
5350 gNextMap := s;
5351 gExit := EXIT_ENDLEVELCUSTOM;
5352 end
5353 else // Èíòåðìèññèÿ - ñðàçó çàãðóæàåì êàðòó
5354 g_Game_ChangeMap(s);
5355 end else
5356 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [P[2]]));
5357 end else
5358 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]));
5359 end;
5360 end else
5361 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
5362 end
5363 else if cmd = 'nextmap' then
5364 begin
5365 if not(gGameOn or (gState = STATE_INTERCUSTOM)) then
5366 g_Console_Add(_lc[I_MSG_NOT_GAME])
5367 else begin
5368 nm := True;
5369 if Length(P) = 1 then
5370 begin
5371 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
5372 begin
5373 g_Console_Add(cmd + ' <MAP>');
5374 g_Console_Add(cmd + ' <WAD> [MAP]');
5375 end else begin
5376 nm := False;
5377 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
5378 end;
5379 end else
5380 begin
5381 nm := False;
5382 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
5383 begin
5384 if Length(P) < 3 then
5385 begin
5386 // Ïåðâûé ïàðàìåòð - ëèáî êàðòà, ëèáî èìÿ WAD ôàéëà
5387 s := UpperCase(P[1]);
5388 if g_Map_Exist(MapsDir + gGameSettings.WAD + ':\' + s) then
5389 begin // Êàðòà íàøëàñü
5390 gExitByTrigger := False;
5391 gNextMap := s;
5392 nm := True;
5393 end else
5394 begin
5395 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [s]));
5396 // Òàêîé êàðòû íåò, èùåì WAD ôàéë
5397 if Pos('.wad', LowerCase(P[1])) = 0 then
5398 P[1] := P[1] + '.wad';
5400 if FileExists(MapsDir + P[1]) then
5401 begin
5402 // Ïàðàìåòðà êàðòû íåò, ïîýòîìó ñòàâèì ïåðâóþ èç ôàéëà
5403 SetLength(P, 3);
5404 P[2] := g_Game_GetFirstMap(MapsDir + P[1]);
5406 s := P[1] + ':\' + P[2];
5408 if g_Map_Exist(MapsDir + s) then
5409 begin // Óñòàíàâëèâàåì êàðòó
5410 gExitByTrigger := False;
5411 gNextMap := s;
5412 nm := True;
5413 end else
5414 if P[2] = '' then
5415 g_Console_Add(Format(_lc[I_MSG_NO_MAPS], [P[1]]))
5416 else
5417 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [P[2]]));
5418 end else
5419 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]));
5420 end;
5421 end else
5422 begin
5423 // Óêàçàíî äâà ïàðàìåòðà, çíà÷èò ïåðâûé - WAD ôàéë, à âòîðîé - êàðòà
5424 if Pos('.wad', LowerCase(P[1])) = 0 then
5425 P[1] := P[1] + '.wad';
5427 if FileExists(MapsDir + P[1]) then
5428 begin
5429 // Íàøëè WAD ôàéë
5430 P[2] := UpperCase(P[2]);
5431 s := P[1] + ':\' + P[2];
5433 if g_Map_Exist(MapsDir + s) then
5434 begin // Íàøëè êàðòó
5435 gExitByTrigger := False;
5436 gNextMap := s;
5437 nm := True;
5438 end else
5439 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [P[2]]));
5440 end else
5441 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]));
5442 end;
5443 end else
5444 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
5445 end;
5446 if nm then
5447 if gNextMap = '' then
5448 g_Console_Add(_lc[I_MSG_NEXTMAP_UNSET])
5449 else
5450 g_Console_Add(Format(_lc[I_MSG_NEXTMAP_SET], [gNextMap]));
5451 end;
5452 end
5453 else if (cmd = 'endmap') or (cmd = 'goodbye') then
5454 begin
5455 if not gGameOn then
5456 g_Console_Add(_lc[I_MSG_NOT_GAME])
5457 else
5458 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
5459 begin
5460 gExitByTrigger := False;
5461 // Ñëåäóþùàÿ êàðòà íå çàäàíà, ïðîáóåì íàéòè òðèããåð Âûõîä
5462 if (gNextMap = '') and (gTriggers <> nil) then
5463 for a := 0 to High(gTriggers) do
5464 if gTriggers[a].TriggerType = TRIGGER_EXIT then
5465 begin
5466 gExitByTrigger := True;
5467 gNextMap := gTriggers[a].Data.MapName;
5468 Break;
5469 end;
5470 // Èùåì ñëåäóþùóþ êàðòó â WAD ôàéëå
5471 if gNextMap = '' then
5472 gNextMap := g_Game_GetNextMap();
5473 // Ïðîâåðÿåì, íå çàäàí ëè WAD ôàéë ðåñóðñíîé ñòðîêîé
5474 if Pos(':\', gNextMap) = 0 then
5475 s := gGameSettings.WAD + ':\' + gNextMap
5476 else
5477 s := gNextMap;
5478 // Åñëè êàðòà íàéäåíà, âûõîäèì ñ óðîâíÿ
5479 if g_Map_Exist(MapsDir + s) then
5480 gExit := EXIT_ENDLEVELCUSTOM
5481 else
5482 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [gNextMap]));
5483 end else
5484 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
5485 end
5486 else if (cmd = 'event') then
5487 begin
5488 if (Length(P) <= 1) then
5489 begin
5490 for a := 0 to High(gEvents) do
5491 if gEvents[a].Command = '' then
5492 g_Console_Add(gEvents[a].Name + ' <none>')
5493 else
5494 g_Console_Add(gEvents[a].Name + ' "' + gEvents[a].Command + '"');
5495 Exit;
5496 end;
5497 if (Length(P) = 2) then
5498 begin
5499 for a := 0 to High(gEvents) do
5500 if gEvents[a].Name = P[1] then
5501 if gEvents[a].Command = '' then
5502 g_Console_Add(gEvents[a].Name + ' <none>')
5503 else
5504 g_Console_Add(gEvents[a].Name + ' "' + gEvents[a].Command + '"');
5505 Exit;
5506 end;
5507 for a := 0 to High(gEvents) do
5508 if gEvents[a].Name = P[1] then
5509 begin
5510 gEvents[a].Command := '';
5511 for b := 2 to High(P) do
5512 if Pos(' ', P[b]) = 0 then
5513 gEvents[a].Command := gEvents[a].Command + ' ' + P[b]
5514 else
5515 gEvents[a].Command := gEvents[a].Command + ' "' + P[b] + '"';
5516 gEvents[a].Command := Trim(gEvents[a].Command);
5517 Exit;
5518 end;
5519 end
5520 // Êîìàíäû Ñâîåé èãðû:
5521 else if gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT] then
5522 begin
5523 if cmd = 'bot_addred' then
5524 begin
5525 if Length(P) > 1 then
5526 g_Bot_Add(TEAM_RED, StrToIntDef(P[1], 2))
5527 else
5528 g_Bot_Add(TEAM_RED, 2);
5529 end
5530 else if cmd = 'bot_addblue' then
5531 begin
5532 if Length(P) > 1 then
5533 g_Bot_Add(TEAM_BLUE, StrToIntDef(P[1], 2))
5534 else
5535 g_Bot_Add(TEAM_BLUE, 2);
5536 end
5537 else if cmd = 'suicide' then
5538 begin
5539 if gGameOn then
5540 begin
5541 if g_Game_IsClient then
5542 MC_SEND_CheatRequest(NET_CHEAT_SUICIDE)
5543 else
5544 begin
5545 if gPlayer1 <> nil then
5546 gPlayer1.Damage(SUICIDE_DAMAGE, gPlayer1.UID, 0, 0, HIT_SELF);
5547 if gPlayer2 <> nil then
5548 gPlayer2.Damage(SUICIDE_DAMAGE, gPlayer2.UID, 0, 0, HIT_SELF);
5549 end;
5550 end;
5551 end
5552 else if cmd = 'spectate' then
5553 begin
5554 if not gGameOn then
5555 Exit;
5556 g_Game_Spectate();
5557 end
5558 else if cmd = 'say' then
5559 begin
5560 if g_Game_IsServer and g_Game_IsNet then
5561 begin
5562 if Length(P) > 1 then
5563 begin
5564 chstr := '';
5565 for a := 1 to High(P) do
5566 chstr := chstr + P[a] + ' ';
5568 if Length(chstr) > 200 then SetLength(chstr, 200);
5570 if Length(chstr) < 1 then
5571 begin
5572 g_Console_Add('say <text>');
5573 Exit;
5574 end;
5576 chstr := b_Text_Format(chstr);
5577 MH_SEND_Chat(chstr, NET_CHAT_PLAYER);
5578 end
5579 else g_Console_Add('say <text>');
5580 end else
5581 g_Console_Add(_lc[I_MSG_SERVERONLY]);
5582 end
5583 else if cmd = 'tell' then
5584 begin
5585 if g_Game_IsServer and g_Game_IsNet then
5586 begin
5587 if (Length(P) > 2) and (P[1] <> '') then
5588 begin
5589 chstr := '';
5590 for a := 2 to High(P) do
5591 chstr := chstr + P[a] + ' ';
5593 if Length(chstr) > 200 then SetLength(chstr, 200);
5595 if Length(chstr) < 1 then
5596 begin
5597 g_Console_Add('tell <playername> <text>');
5598 Exit;
5599 end;
5601 pl := g_Net_Client_ByName(P[1]);
5602 if pl <> nil then
5603 MH_SEND_Chat(b_Text_Format(chstr), NET_CHAT_PLAYER, pl^.ID)
5604 else
5605 g_Console_Add(Format(_lc[I_NET_ERR_NAME404], [P[1]]));
5606 end
5607 else g_Console_Add('tell <playername> <text>');
5608 end else
5609 g_Console_Add(_lc[I_MSG_SERVERONLY]);
5610 end
5611 else if (cmd = 'overtime') and not g_Game_IsClient then
5612 begin
5613 if (Length(P) = 1) or (StrToIntDef(P[1], -1) <= 0) then
5614 Exit;
5615 // Äîïîëíèòåëüíîå âðåìÿ:
5616 gGameSettings.TimeLimit := (gTime - gGameStartTime) div 1000 + Word(StrToIntDef(P[1], 0));
5618 g_Console_Add(Format(_lc[I_MSG_TIME_LIMIT],
5619 [gGameSettings.TimeLimit div 3600,
5620 (gGameSettings.TimeLimit div 60) mod 60,
5621 gGameSettings.TimeLimit mod 60]));
5622 if g_Game_IsNet then MH_SEND_GameSettings;
5623 end
5624 else if (cmd = 'rcon_password') and g_Game_IsClient then
5625 begin
5626 if (Length(P) <= 1) then
5627 g_Console_Add('rcon_password <password>')
5628 else
5629 MC_SEND_RCONPassword(P[1]);
5630 end
5631 else if cmd = 'rcon' then
5632 begin
5633 if g_Game_IsClient then
5634 begin
5635 if Length(P) > 1 then
5636 begin
5637 chstr := '';
5638 for a := 1 to High(P) do
5639 chstr := chstr + P[a] + ' ';
5641 if Length(chstr) > 200 then SetLength(chstr, 200);
5643 if Length(chstr) < 1 then
5644 begin
5645 g_Console_Add('rcon <command>');
5646 Exit;
5647 end;
5649 MC_SEND_RCONCommand(chstr);
5650 end
5651 else g_Console_Add('rcon <command>');
5652 end;
5653 end
5654 else if cmd = 'ready' then
5655 begin
5656 if g_Game_IsServer and (gLMSRespawn = LMS_RESPAWN_WARMUP) then
5657 gLMSRespawnTime := gTime + 100;
5658 end
5659 else if (cmd = 'callvote') and g_Game_IsNet then
5660 begin
5661 if Length(P) > 1 then
5662 begin
5663 chstr := '';
5664 for a := 1 to High(P) do begin
5665 if a > 1 then chstr := chstr + ' ';
5666 chstr := chstr + P[a];
5667 end;
5669 if Length(chstr) > 200 then SetLength(chstr, 200);
5671 if Length(chstr) < 1 then
5672 begin
5673 g_Console_Add('callvote <command>');
5674 Exit;
5675 end;
5677 if g_Game_IsClient then
5678 MC_SEND_Vote(True, chstr)
5679 else
5680 g_Game_StartVote(chstr, gPlayer1Settings.Name);
5681 g_Console_Process('vote', True);
5682 end
5683 else
5684 g_Console_Add('callvote <command>');
5685 end
5686 else if (cmd = 'vote') and g_Game_IsNet then
5687 begin
5688 if g_Game_IsClient then
5689 MC_SEND_Vote(False)
5690 else if gVoteInProgress then
5691 begin
5692 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
5693 a := Floor((NetClientCount+1)/2.0) + 1
5694 else
5695 a := Floor(NetClientCount/2.0) + 1;
5696 if gVoted then
5697 begin
5698 Dec(gVoteCount);
5699 gVoted := False;
5700 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_REVOKED], [gPlayer1Settings.Name, gVoteCount, a]), True);
5701 MH_SEND_VoteEvent(NET_VE_REVOKE, gPlayer1Settings.Name, 'a', gVoteCount, a);
5702 end
5703 else
5704 begin
5705 Inc(gVoteCount);
5706 gVoted := True;
5707 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_VOTE], [gPlayer1Settings.Name, gVoteCount, a]), True);
5708 MH_SEND_VoteEvent(NET_VE_VOTE, gPlayer1Settings.Name, 'a', gVoteCount, a);
5709 g_Game_CheckVote;
5710 end;
5711 end;
5712 end
5713 end;
5714 end;
5716 procedure g_TakeScreenShot();
5717 var
5718 a: Word;
5719 FileName: String;
5720 begin
5721 for a := 1 to High(Word) do
5722 begin
5723 FileName := Format(GameDir+'/Screenshots/Screenshot%.3d.bmp', [a]);
5724 if not FileExists(FileName) then
5725 begin
5726 e_MakeScreenshot(FileName, gScreenWidth, gScreenHeight);
5727 g_Console_Add(Format(_lc[I_CONSOLE_SCREENSHOT], [ExtractFileName(FileName)]));
5728 Break;
5729 end;
5730 end;
5731 end;
5733 procedure g_Game_InGameMenu(Show: Boolean);
5734 begin
5735 if (g_ActiveWindow = nil) and Show then
5736 begin
5737 if gGameSettings.GameType = GT_SINGLE then
5738 g_GUI_ShowWindow('GameSingleMenu')
5739 else
5740 begin
5741 if g_Game_IsClient then
5742 g_GUI_ShowWindow('GameClientMenu')
5743 else
5744 if g_Game_IsNet then
5745 g_GUI_ShowWindow('GameServerMenu')
5746 else
5747 g_GUI_ShowWindow('GameCustomMenu');
5748 end;
5749 g_Sound_PlayEx('MENU_OPEN');
5751 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
5752 if (not g_Game_IsNet) then
5753 g_Game_Pause(True);
5754 end
5755 else
5756 if (g_ActiveWindow <> nil) and (not Show) then
5757 begin
5758 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
5759 if (not g_Game_IsNet) then
5760 g_Game_Pause(False);
5761 end;
5762 end;
5764 procedure g_Game_Pause(Enable: Boolean);
5765 begin
5766 if not gGameOn then
5767 Exit;
5769 if gPause = Enable then
5770 Exit;
5772 if not (gGameSettings.GameType in [GT_SINGLE, GT_CUSTOM]) then
5773 Exit;
5775 gPause := Enable;
5776 g_Game_PauseAllSounds(Enable);
5777 end;
5779 procedure g_Game_PauseAllSounds(Enable: Boolean);
5780 var
5781 i: Integer;
5782 begin
5783 // Òðèããåðû:
5784 if gTriggers <> nil then
5785 for i := 0 to High(gTriggers) do
5786 with gTriggers[i] do
5787 if (TriggerType = TRIGGER_SOUND) and
5788 (Sound <> nil) and
5789 Sound.IsPlaying() then
5790 begin
5791 Sound.Pause(Enable);
5792 end;
5794 // Çâóêè èãðîêîâ:
5795 if gPlayers <> nil then
5796 for i := 0 to High(gPlayers) do
5797 if gPlayers[i] <> nil then
5798 gPlayers[i].PauseSounds(Enable);
5800 // Ìóçûêà:
5801 if gMusic <> nil then
5802 gMusic.Pause(Enable);
5803 end;
5805 procedure g_Game_StopAllSounds(all: Boolean);
5806 var
5807 i: Integer;
5808 begin
5809 if gTriggers <> nil then
5810 for i := 0 to High(gTriggers) do
5811 with gTriggers[i] do
5812 if (TriggerType = TRIGGER_SOUND) and
5813 (Sound <> nil) then
5814 Sound.Stop();
5816 if gMusic <> nil then
5817 gMusic.Stop();
5819 if all then
5820 e_StopChannels();
5821 end;
5823 procedure g_Game_UpdateTriggerSounds();
5824 var
5825 i: Integer;
5826 begin
5827 if gTriggers <> nil then
5828 for i := 0 to High(gTriggers) do
5829 with gTriggers[i] do
5830 if (TriggerType = TRIGGER_SOUND) and
5831 (Sound <> nil) and
5832 (Data.Local) and
5833 Sound.IsPlaying() then
5834 begin
5835 if ((gPlayer1 <> nil) and g_CollidePoint(gPlayer1.GameX, gPlayer1.GameY, X, Y, Width, Height)) or
5836 ((gPlayer2 <> nil) and g_CollidePoint(gPlayer2.GameX, gPlayer2.GameY, X, Y, Width, Height)) then
5837 begin
5838 Sound.SetPan(0.5 - Data.Pan/255.0);
5839 Sound.SetVolume(Data.Volume/255.0);
5840 end
5841 else
5842 Sound.SetCoords(X+(Width div 2), Y+(Height div 2), Data.Volume/255.0);
5843 end;
5844 end;
5846 function g_Game_IsWatchedPlayer(UID: Word): Boolean;
5847 begin
5848 Result := False;
5849 if (gPlayer1 <> nil) and (gPlayer1.UID = UID) then
5850 begin
5851 Result := True;
5852 Exit;
5853 end;
5854 if (gPlayer2 <> nil) and (gPlayer2.UID = UID) then
5855 begin
5856 Result := True;
5857 Exit;
5858 end;
5859 if gSpectMode <> SPECT_PLAYERS then
5860 Exit;
5861 if gSpectPID1 = UID then
5862 begin
5863 Result := True;
5864 Exit;
5865 end;
5866 if gSpectViewTwo and (gSpectPID2 = UID) then
5867 begin
5868 Result := True;
5869 Exit;
5870 end;
5871 end;
5873 function g_Game_IsWatchedTeam(Team: Byte): Boolean;
5874 var
5875 Pl: TPlayer;
5876 begin
5877 Result := False;
5878 if (gPlayer1 <> nil) and (gPlayer1.Team = Team) then
5879 begin
5880 Result := True;
5881 Exit;
5882 end;
5883 if (gPlayer2 <> nil) and (gPlayer2.Team = Team) then
5884 begin
5885 Result := True;
5886 Exit;
5887 end;
5888 if gSpectMode <> SPECT_PLAYERS then
5889 Exit;
5890 Pl := g_Player_Get(gSpectPID1);
5891 if (Pl <> nil) and (Pl.Team = Team) then
5892 begin
5893 Result := True;
5894 Exit;
5895 end;
5896 if gSpectViewTwo then
5897 begin
5898 Pl := g_Player_Get(gSpectPID2);
5899 if (Pl <> nil) and (Pl.Team = Team) then
5900 begin
5901 Result := True;
5902 Exit;
5903 end;
5904 end;
5905 end;
5907 procedure g_Game_Message(Msg: string; Time: Word);
5908 begin
5909 MessageText := b_Text_Format(Msg);
5910 MessageTime := Time;
5911 end;
5913 procedure g_Game_Announce_GoodShot(SpawnerUID: Word);
5914 var
5915 a: Integer;
5916 begin
5917 case gAnnouncer of
5918 ANNOUNCE_NONE:
5919 Exit;
5920 ANNOUNCE_ME,
5921 ANNOUNCE_MEPLUS:
5922 if not g_Game_IsWatchedPlayer(SpawnerUID) then
5923 Exit;
5924 end;
5925 for a := 0 to 3 do
5926 if goodsnd[a].IsPlaying() then
5927 Exit;
5929 goodsnd[Random(4)].Play();
5930 end;
5932 procedure g_Game_Announce_KillCombo(Param: Integer);
5933 var
5934 UID: Word;
5935 c, n: Byte;
5936 Pl: TPlayer;
5937 Name: String;
5938 begin
5939 UID := Param and $FFFF;
5940 c := Param shr 16;
5941 if c < 2 then
5942 Exit;
5944 Pl := g_Player_Get(UID);
5945 if Pl = nil then
5946 Name := '?'
5947 else
5948 Name := Pl.Name;
5950 case c of
5951 2: begin
5952 n := 0;
5953 g_Console_Add(Format(_lc[I_PLAYER_KILL_2X], [Name]), True);
5954 end;
5955 3: begin
5956 n := 1;
5957 g_Console_Add(Format(_lc[I_PLAYER_KILL_3X], [Name]), True);
5958 end;
5959 4: begin
5960 n := 2;
5961 g_Console_Add(Format(_lc[I_PLAYER_KILL_4X], [Name]), True);
5962 end;
5963 else begin
5964 n := 3;
5965 g_Console_Add(Format(_lc[I_PLAYER_KILL_MX], [Name]), True);
5966 end;
5967 end;
5969 case gAnnouncer of
5970 ANNOUNCE_NONE:
5971 Exit;
5972 ANNOUNCE_ME:
5973 if not g_Game_IsWatchedPlayer(UID) then
5974 Exit;
5975 ANNOUNCE_MEPLUS:
5976 if (not g_Game_IsWatchedPlayer(UID)) and (c < 4) then
5977 Exit;
5978 end;
5980 if killsnd[n].IsPlaying() then
5981 killsnd[n].Stop();
5982 killsnd[n].Play();
5983 end;
5985 procedure g_Game_StartVote(Command, Initiator: string);
5986 var
5987 Need: Integer;
5988 begin
5989 if not gVotesEnabled then Exit;
5990 if gGameSettings.GameType <> GT_SERVER then Exit;
5991 if gVoteInProgress or gVotePassed then
5992 begin
5993 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_INPROGRESS], [gVoteCommand]), True);
5994 MH_SEND_VoteEvent(NET_VE_INPROGRESS, gVoteCommand);
5995 Exit;
5996 end;
5997 gVoteInProgress := True;
5998 gVotePassed := False;
5999 gVoteTimer := gTime + gVoteTimeout * 1000;
6000 gVoteCount := 0;
6001 gVoted := False;
6002 gVoteCommand := Command;
6004 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
6005 Need := Floor((NetClientCount+1)/2.0)+1
6006 else
6007 Need := Floor(NetClientCount/2.0)+1;
6008 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_STARTED], [Initiator, Command, Need]), True);
6009 MH_SEND_VoteEvent(NET_VE_STARTED, Initiator, Command, Need);
6010 end;
6012 procedure g_Game_CheckVote;
6013 var
6014 I, Need: Integer;
6015 begin
6016 if gGameSettings.GameType <> GT_SERVER then Exit;
6017 if not gVoteInProgress then Exit;
6019 if (gTime >= gVoteTimer) then
6020 begin
6021 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
6022 Need := Floor((NetClientCount+1)/2.0) + 1
6023 else
6024 Need := Floor(NetClientCount/2.0) + 1;
6025 if gVoteCount >= Need then
6026 begin
6027 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_PASSED], [gVoteCommand]), True);
6028 MH_SEND_VoteEvent(NET_VE_PASSED, gVoteCommand);
6029 gVotePassed := True;
6030 gVoteCmdTimer := gTime + 5000;
6031 end
6032 else
6033 begin
6034 g_Console_Add(_lc[I_MESSAGE_VOTE_FAILED], True);
6035 MH_SEND_VoteEvent(NET_VE_FAILED);
6036 end;
6037 if NetClients <> nil then
6038 for I := Low(NetClients) to High(NetClients) do
6039 if NetClients[i].Used then
6040 NetClients[i].Voted := False;
6041 gVoteInProgress := False;
6042 gVoted := False;
6043 gVoteCount := 0;
6044 end
6045 else
6046 begin
6047 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
6048 Need := Floor((NetClientCount+1)/2.0) + 1
6049 else
6050 Need := Floor(NetClientCount/2.0) + 1;
6051 if gVoteCount >= Need then
6052 begin
6053 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_PASSED], [gVoteCommand]), True);
6054 MH_SEND_VoteEvent(NET_VE_PASSED, gVoteCommand);
6055 gVoteInProgress := False;
6056 gVotePassed := True;
6057 gVoteCmdTimer := gTime + 5000;
6058 gVoted := False;
6059 gVoteCount := 0;
6060 if NetClients <> nil then
6061 for I := Low(NetClients) to High(NetClients) do
6062 if NetClients[i].Used then
6063 NetClients[i].Voted := False;
6064 end;
6065 end;
6066 end;
6068 procedure g_Game_LoadMapList(FileName: string);
6069 var
6070 ListFile: TextFile;
6071 s: string;
6072 begin
6073 MapList := nil;
6074 MapIndex := -1;
6076 if not FileExists(FileName) then Exit;
6078 AssignFile(ListFile, FileName);
6079 Reset(ListFile);
6080 while not EOF(ListFile) do
6081 begin
6082 ReadLn(ListFile, s);
6084 s := Trim(s);
6085 if s = '' then Continue;
6087 SetLength(MapList, Length(MapList)+1);
6088 MapList[High(MapList)] := s;
6089 end;
6090 CloseFile(ListFile);
6091 end;
6093 procedure g_Game_SetDebugMode();
6094 begin
6095 gDebugMode := True;
6096 // ×èòû (äàæå â ñâîåé èãðå):
6097 gCheats := True;
6098 end;
6100 procedure g_Game_SetLoadingText(Text: String; Max: Integer; reWrite: Boolean);
6101 var
6102 i: Word;
6103 begin
6104 if Length(LoadingStat.Msgs) = 0 then
6105 Exit;
6107 with LoadingStat do
6108 begin
6109 if not reWrite then
6110 begin // Ïåðåõîäèì íà ñëåäóþùóþ ñòðîêó èëè ñêðîëëèðóåì:
6111 if NextMsg = Length(Msgs) then
6112 begin // scroll
6113 for i := 0 to High(Msgs)-1 do
6114 Msgs[i] := Msgs[i+1];
6115 end
6116 else
6117 Inc(NextMsg);
6118 end else
6119 if NextMsg = 0 then
6120 Inc(NextMsg);
6122 Msgs[NextMsg-1] := Text;
6123 CurValue := 0;
6124 MaxValue := Max;
6125 ShowCount := 0;
6126 end;
6128 g_ActiveWindow := nil;
6130 ProcessLoading;
6131 end;
6133 procedure g_Game_StepLoading();
6134 begin
6135 with LoadingStat do
6136 begin
6137 Inc(CurValue);
6138 Inc(ShowCount);
6139 if (ShowCount > LOADING_SHOW_STEP) then
6140 begin
6141 ShowCount := 0;
6142 ProcessLoading;
6143 end;
6144 end;
6145 end;
6147 procedure g_Game_ClearLoading();
6148 var
6149 len: Word;
6150 begin
6151 with LoadingStat do
6152 begin
6153 CurValue := 0;
6154 MaxValue := 0;
6155 ShowCount := 0;
6156 len := ((gScreenHeight div 3)*2 - 50) div LOADING_INTERLINE;
6157 if len < 1 then len := 1;
6158 SetLength(Msgs, len);
6159 for len := Low(Msgs) to High(Msgs) do
6160 Msgs[len] := '';
6161 NextMsg := 0;
6162 end;
6163 end;
6165 procedure Parse_Params(var pars: TParamStrValues);
6166 var
6167 i: Integer;
6168 s: String;
6169 begin
6170 SetLength(pars, 0);
6171 i := 1;
6172 while i <= ParamCount do
6173 begin
6174 s := ParamStr(i);
6175 if (s[1] = '-') and (Length(s) > 1) then
6176 begin
6177 if (s[2] = '-') and (Length(s) > 2) then
6178 begin // Îäèíî÷íûé ïàðàìåòð
6179 SetLength(pars, Length(pars) + 1);
6180 with pars[High(pars)] do
6181 begin
6182 Name := LowerCase(s);
6183 Value := '+';
6184 end;
6185 end
6186 else
6187 if (i < ParamCount) then
6188 begin // Ïàðàìåòð ñî çíà÷åíèåì
6189 Inc(i);
6190 SetLength(pars, Length(pars) + 1);
6191 with pars[High(pars)] do
6192 begin
6193 Name := LowerCase(s);
6194 Value := LowerCase(ParamStr(i));
6195 end;
6196 end;
6197 end;
6199 Inc(i);
6200 end;
6201 end;
6203 function Find_Param_Value(var pars: TParamStrValues; aName: String): String;
6204 var
6205 i: Integer;
6206 begin
6207 Result := '';
6208 for i := 0 to High(pars) do
6209 if pars[i].Name = aName then
6210 begin
6211 Result := pars[i].Value;
6212 Break;
6213 end;
6214 end;
6216 procedure g_Game_Process_Params();
6217 var
6218 pars: TParamStrValues;
6219 map: String;
6220 GMode, n: Byte;
6221 LimT, LimS: Integer;
6222 Opt: LongWord;
6223 Lives: Integer;
6224 s: String;
6225 Port: Integer;
6226 ip: String;
6227 F: TextFile;
6228 begin
6229 Parse_Params(pars);
6231 // Debug mode:
6232 s := Find_Param_Value(pars, '--debug');
6233 if (s <> '') then
6234 g_Game_SetDebugMode();
6236 // Connect when game loads
6237 ip := Find_Param_Value(pars, '-connect');
6239 if ip <> '' then
6240 begin
6241 s := Find_Param_Value(pars, '-port');
6242 if (s = '') or not TryStrToInt(s, Port) then
6243 Port := 25666;
6245 s := Find_Param_Value(pars, '-pw');
6247 g_Game_StartClient(ip, Port, s);
6248 Exit;
6249 end;
6251 // Start map when game loads:
6252 map := LowerCase(Find_Param_Value(pars, '-map'));
6253 if (map <> '') and (Pos('.wad:\', map) > 0) then
6254 begin
6255 // Game mode:
6256 s := Find_Param_Value(pars, '-gm');
6257 GMode := g_Game_TextToMode(s);
6258 if GMode = GM_NONE then GMode := GM_DM;
6259 if GMode = GM_SINGLE then GMode := GM_COOP;
6261 // Time limit:
6262 s := Find_Param_Value(pars, '-limt');
6263 if (s = '') or (not TryStrToInt(s, LimT)) then
6264 LimT := 0;
6265 if LimT < 0 then
6266 LimT := 0;
6268 // Goal limit:
6269 s := Find_Param_Value(pars, '-lims');
6270 if (s = '') or (not TryStrToInt(s, LimS)) then
6271 LimS := 0;
6272 if LimS < 0 then
6273 LimS := 0;
6275 // Lives limit:
6276 s := Find_Param_Value(pars, '-lives');
6277 if (s = '') or (not TryStrToInt(s, Lives)) then
6278 Lives := 0;
6279 if Lives < 0 then
6280 Lives := 0;
6282 // Options:
6283 s := Find_Param_Value(pars, '-opt');
6284 if (s = '') then
6285 Opt := GAME_OPTION_ALLOWEXIT or GAME_OPTION_BOTVSPLAYER or GAME_OPTION_BOTVSMONSTER
6286 else
6287 Opt := StrToIntDef(s, 0);
6288 if Opt = 0 then
6289 Opt := GAME_OPTION_ALLOWEXIT or GAME_OPTION_BOTVSPLAYER or GAME_OPTION_BOTVSMONSTER;
6291 // Close after map:
6292 s := Find_Param_Value(pars, '--close');
6293 if (s <> '') then
6294 gMapOnce := True;
6296 // Delete test map after play:
6297 s := Find_Param_Value(pars, '--testdelete');
6298 if (s <> '') then
6299 begin
6300 gMapToDelete := MapsDir + map;
6301 e_WriteLog('"--testdelete" argument doesn''t supported anymore!', MSG_FATALERROR);
6302 Halt(1);
6303 end;
6305 // Delete temporary WAD after play:
6306 s := Find_Param_Value(pars, '--tempdelete');
6307 if (s <> '') then
6308 begin
6309 gMapToDelete := MapsDir + map;
6310 gTempDelete := True;
6311 end;
6313 // Number of players:
6314 s := Find_Param_Value(pars, '-pl');
6315 if (s = '') then
6316 n := 1
6317 else
6318 n := StrToIntDef(s, 1);
6320 // Start:
6321 s := Find_Param_Value(pars, '-port');
6322 if (s = '') or not TryStrToInt(s, Port) then
6323 g_Game_StartCustom(map, GMode, LimT, LimS, Lives, Opt, n)
6324 else
6325 g_Game_StartServer(map, GMode, LimT, LimS, Lives, Opt, n, 0, Port);
6326 end;
6328 // Execute script when game loads:
6329 s := Find_Param_Value(pars, '-exec');
6330 if s <> '' then
6331 begin
6332 if Pos(':\', s) = 0 then
6333 s := GameDir + '/' + s;
6335 {$I-}
6336 AssignFile(F, s);
6337 Reset(F);
6338 if IOResult <> 0 then
6339 begin
6340 e_WriteLog(Format(_lc[I_SIMPLE_ERROR], ['Failed to read file: ' + s]), MSG_WARNING);
6341 g_Console_Add(Format(_lc[I_CONSOLE_ERROR_READ], [s]));
6342 CloseFile(F);
6343 Exit;
6344 end;
6345 e_WriteLog('Executing script: ' + s, MSG_NOTIFY);
6346 g_Console_Add(Format(_lc[I_CONSOLE_EXEC], [s]));
6348 while not EOF(F) do
6349 begin
6350 ReadLn(F, s);
6351 if IOResult <> 0 then
6352 begin
6353 e_WriteLog(Format(_lc[I_SIMPLE_ERROR], ['Failed to read file: ' + s]), MSG_WARNING);
6354 g_Console_Add(Format(_lc[I_CONSOLE_ERROR_READ], [s]));
6355 CloseFile(F);
6356 Exit;
6357 end;
6358 if Pos('#', s) <> 1 then // script comment
6359 g_Console_Process(s, True);
6360 end;
6362 CloseFile(F);
6363 {$I+}
6364 end;
6366 SetLength(pars, 0);
6367 end;
6369 end.