DEADSOFTWARE

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