DEADSOFTWARE

put "{$MODE ...}" directive in each source file; removed trailing spaces, and convert...
[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 g_ProcessResourceStr(MegaWAD.endpic, @s, nil, nil);
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 g_ProcessResourceStr(MegaWAD.endmus, @s, nil, nil);
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, SectionName, ResName: 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 g_ProcessResourceStr(gMapInfo.Map, FileName, SectionName, ResName);
731 CustomStat.GameTime := gTime;
732 CustomStat.Map := ExtractFileName(FileName)+':'+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 g_ProcessResourceStr(gMapInfo.Map, @wad, nil, @map);
845 wad := ExtractFileName(wad);
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 g_ProcessResourceStr(gMapInfo.Map, nil, nil, @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 g_ProcessResourceStr(Map, @NewWAD, nil, @ResName);
3697 if g_Game_IsServer then
3698 begin
3699 gWADHash := MD5File(MapsDir + NewWAD);
3700 g_Game_LoadWAD(NewWAD);
3701 end else
3702 // hash recieved in MC_RECV_GameEvent -> NET_EV_MAPSTART
3703 g_Game_ClientWAD(NewWAD, gWADHash);
3704 end else
3705 ResName := Map;
3707 Result := g_Map_Load(MapsDir + gGameSettings.WAD + ':\' + ResName);
3708 if Result then
3709 begin
3710 g_Player_ResetAll(Force or gLastMap, gGameSettings.GameType = GT_SINGLE);
3712 gState := STATE_NONE;
3713 g_ActiveWindow := nil;
3714 gGameOn := True;
3716 DisableCheats();
3717 ResetTimer();
3719 if gGameSettings.GameMode = GM_CTF then
3720 begin
3721 g_Map_ResetFlag(FLAG_RED);
3722 g_Map_ResetFlag(FLAG_BLUE);
3723 // CTF, à ôëàãîâ íåò:
3724 if not g_Map_HaveFlagPoints() then
3725 g_SimpleError(_lc[I_GAME_ERROR_CTF]);
3726 end;
3727 end
3728 else
3729 begin
3730 gState := STATE_MENU;
3731 gGameOn := False;
3732 end;
3734 gExit := 0;
3735 gPause := False;
3736 gTime := 0;
3737 NetTimeToUpdate := 1;
3738 NetTimeToReliable := 0;
3739 NetTimeToMaster := NetMasterRate;
3740 gLMSRespawn := LMS_RESPAWN_NONE;
3741 gLMSRespawnTime := 0;
3742 gMissionFailed := False;
3743 gNextMap := '';
3745 gCoopMonstersKilled := 0;
3746 gCoopSecretsFound := 0;
3748 gVoteInProgress := False;
3749 gVotePassed := False;
3750 gVoteCount := 0;
3751 gVoted := False;
3753 gStatsOff := False;
3755 if not gGameOn then Exit;
3757 g_Game_SpectateCenterView();
3759 if (gGameSettings.MaxLives > 0) and (gGameSettings.WarmupTime > 0) then
3760 begin
3761 gLMSRespawn := LMS_RESPAWN_WARMUP;
3762 gLMSRespawnTime := gTime + gGameSettings.WarmupTime*1000;
3763 gLMSSoftSpawn := True;
3764 if NetMode = NET_SERVER then
3765 MH_SEND_GameEvent(NET_EV_LMS_WARMUP, (gLMSRespawnTime - gTime) div 1000)
3766 else
3767 g_Console_Add(Format(_lc[I_MSG_WARMUP_START], [(gLMSRespawnTime - gTime) div 1000]), True);
3768 end;
3770 if NetMode = NET_SERVER then
3771 begin
3772 MH_SEND_GameEvent(NET_EV_MAPSTART, gGameSettings.GameMode, Map);
3774 // Ìàñòåðñåðâåð
3775 if NetUseMaster then
3776 begin
3777 if (NetMHost = nil) or (NetMPeer = nil) then
3778 if not g_Net_Slist_Connect then
3779 g_Console_Add(_lc[I_NET_MSG_ERROR] + _lc[I_NET_SLIST_ERROR]);
3781 g_Net_Slist_Update;
3782 end;
3784 if NetClients <> nil then
3785 for I := 0 to High(NetClients) do
3786 if NetClients[I].Used then
3787 begin
3788 NetClients[I].Voted := False;
3789 if NetClients[I].RequestedFullUpdate then
3790 begin
3791 MH_SEND_Everything((NetClients[I].State = NET_STATE_AUTH), I);
3792 NetClients[I].RequestedFullUpdate := False;
3793 end;
3794 end;
3796 g_Net_UnbanNonPermHosts();
3797 end;
3799 if gLastMap then
3800 begin
3801 gCoopTotalMonstersKilled := 0;
3802 gCoopTotalSecretsFound := 0;
3803 gCoopTotalMonsters := 0;
3804 gCoopTotalSecrets := 0;
3805 gLastMap := False;
3806 end;
3808 g_Game_ExecuteEvent('onmapstart');
3809 end;
3811 procedure SetFirstLevel();
3812 begin
3813 gNextMap := '';
3815 MapList := g_Map_GetMapsList(MapsDir + gGameSettings.WAD);
3816 if MapList = nil then
3817 Exit;
3819 SortSArray(MapList);
3820 gNextMap := MapList[Low(MapList)];
3822 MapList := nil;
3823 end;
3825 procedure g_Game_ExitLevel(Map: Char16);
3826 begin
3827 gNextMap := Map;
3829 gCoopTotalMonstersKilled := gCoopTotalMonstersKilled + gCoopMonstersKilled;
3830 gCoopTotalSecretsFound := gCoopTotalSecretsFound + gCoopSecretsFound;
3831 gCoopTotalMonsters := gCoopTotalMonsters + gTotalMonsters;
3832 gCoopTotalSecrets := gCoopTotalSecrets + gSecretsCount;
3834 // Âûøëè â âûõîä â Îäèíî÷íîé èãðå:
3835 if gGameSettings.GameType = GT_SINGLE then
3836 gExit := EXIT_ENDLEVELSINGLE
3837 else // Âûøëè â âûõîä â Ñâîåé èãðå
3838 begin
3839 gExit := EXIT_ENDLEVELCUSTOM;
3840 if gGameSettings.GameMode = GM_COOP then
3841 g_Player_RememberAll;
3843 if not g_Map_Exist(MapsDir + gGameSettings.WAD + ':\' + gNextMap) then
3844 begin
3845 gLastMap := True;
3846 if gGameSettings.GameMode = GM_COOP then
3847 gStatsOff := True;
3849 gStatsPressed := True;
3850 gNextMap := 'MAP01';
3852 if not g_Map_Exist(MapsDir + gGameSettings.WAD + ':\' + gNextMap) then
3853 g_Game_NextLevel;
3855 if g_Game_IsNet then
3856 begin
3857 MH_SEND_GameStats();
3858 MH_SEND_CoopStats();
3859 end;
3860 end;
3861 end;
3862 end;
3864 procedure g_Game_RestartLevel();
3865 var
3866 Map: string;
3867 begin
3868 if gGameSettings.GameMode = GM_SINGLE then
3869 begin
3870 g_Game_Restart();
3871 Exit;
3872 end;
3873 gExit := EXIT_ENDLEVELCUSTOM;
3874 g_ProcessResourceStr(gMapInfo.Map, nil, nil, @Map);
3875 gNextMap := Map;
3876 end;
3878 procedure g_Game_ClientWAD(NewWAD: String; WHash: TMD5Digest);
3879 var
3880 gWAD: String;
3881 begin
3882 if LowerCase(NewWAD) = LowerCase(gGameSettings.WAD) then
3883 Exit;
3884 if not g_Game_IsClient then
3885 Exit;
3886 gWAD := g_Res_SearchSameWAD(MapsDir, ExtractFileName(NewWAD), WHash);
3887 if gWAD = '' then
3888 begin
3889 g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
3890 gWAD := g_Res_DownloadWAD(ExtractFileName(NewWAD));
3891 if gWAD = '' then
3892 begin
3893 g_Game_Free();
3894 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_WAD], [ExtractFileName(NewWAD)]));
3895 Exit;
3896 end;
3897 end;
3898 NewWAD := ExtractRelativePath(MapsDir, gWAD);
3899 g_Game_LoadWAD(NewWAD);
3900 end;
3902 procedure g_Game_RestartRound(NoMapRestart: Boolean = False);
3903 var
3904 i, n, nb, nr: Integer;
3905 begin
3906 if not g_Game_IsServer then Exit;
3907 if gLMSRespawn = LMS_RESPAWN_NONE then Exit;
3908 gLMSRespawn := LMS_RESPAWN_NONE;
3909 gLMSRespawnTime := 0;
3910 MessageTime := 0;
3912 if (gGameSettings.GameMode = GM_COOP) and not NoMapRestart then
3913 begin
3914 gMissionFailed := True;
3915 g_Game_RestartLevel;
3916 Exit;
3917 end;
3919 n := 0; nb := 0; nr := 0;
3920 for i := Low(gPlayers) to High(gPlayers) do
3921 if (gPlayers[i] <> nil) and
3922 ((not gPlayers[i].FSpectator) or gPlayers[i].FWantsInGame or
3923 (gPlayers[i] is TBot)) then
3924 begin
3925 Inc(n);
3926 if gPlayers[i].Team = TEAM_RED then Inc(nr)
3927 else if gPlayers[i].Team = TEAM_BLUE then Inc(nb)
3928 end;
3930 if (n < 2) or ((gGameSettings.GameMode = GM_TDM) and ((nr = 0) or (nb = 0))) then
3931 begin
3932 // wait a second until the fuckers finally decide to join
3933 gLMSRespawn := LMS_RESPAWN_WARMUP;
3934 gLMSRespawnTime := gTime + 1000;
3935 gLMSSoftSpawn := NoMapRestart;
3936 Exit;
3937 end;
3939 g_Player_RemoveAllCorpses;
3940 g_Game_Message(_lc[I_MESSAGE_LMS_START], 144);
3941 if g_Game_IsNet then
3942 MH_SEND_GameEvent(NET_EV_LMS_START);
3944 for i := Low(gPlayers) to High(gPlayers) do
3945 begin
3946 if gPlayers[i] = nil then continue;
3947 if gPlayers[i] is TBot then gPlayers[i].FWantsInGame := True;
3948 // don't touch normal spectators
3949 if gPlayers[i].FSpectator and not gPlayers[i].FWantsInGame then
3950 begin
3951 gPlayers[i].FNoRespawn := True;
3952 gPlayers[i].Lives := 0;
3953 if g_Game_IsNet then
3954 MH_SEND_PlayerStats(gPlayers[I].UID);
3955 continue;
3956 end;
3957 gPlayers[i].FNoRespawn := False;
3958 gPlayers[i].Lives := gGameSettings.MaxLives;
3959 gPlayers[i].Respawn(False, True);
3960 if gGameSettings.GameMode = GM_COOP then
3961 begin
3962 gPlayers[i].Frags := 0;
3963 gPlayers[i].RecallState;
3964 end;
3965 if (gPlayer1 = nil) and (gLMSPID1 > 0) then
3966 gPlayer1 := g_Player_Get(gLMSPID1);
3967 if (gPlayer2 = nil) and (gLMSPID2 > 0) then
3968 gPlayer2 := g_Player_Get(gLMSPID2);
3969 end;
3971 for i := Low(gItems) to High(gItems) do
3972 begin
3973 if gItems[i].Respawnable then
3974 begin
3975 gItems[i].QuietRespawn := True;
3976 gItems[i].RespawnTime := 0;
3977 end
3978 else
3979 begin
3980 g_Items_Remove(i);
3981 if g_Game_IsNet then MH_SEND_ItemDestroy(True, i);
3982 end;
3983 end;
3985 for i := Low(gMonsters) to High(gMonsters) do
3986 begin
3987 if (gMonsters[i] <> nil) and not gMonsters[i].FNoRespawn then
3988 gMonsters[i].Respawn;
3989 end;
3991 gLMSSoftSpawn := False;
3992 end;
3994 function g_Game_GetFirstMap(WAD: String): String;
3995 begin
3996 Result := '';
3998 MapList := g_Map_GetMapsList(WAD);
3999 if MapList = nil then
4000 Exit;
4002 SortSArray(MapList);
4003 Result := MapList[Low(MapList)];
4005 if not g_Map_Exist(WAD + ':\' + Result) then
4006 Result := '';
4008 MapList := nil;
4009 end;
4011 function g_Game_GetNextMap(): String;
4012 var
4013 I: Integer;
4014 Map: string;
4015 begin
4016 Result := '';
4018 MapList := g_Map_GetMapsList(MapsDir + gGameSettings.WAD);
4019 if MapList = nil then
4020 Exit;
4022 g_ProcessResourceStr(gMapInfo.Map, nil, nil, @Map);
4024 SortSArray(MapList);
4025 MapIndex := -255;
4026 for I := Low(MapList) to High(MapList) do
4027 if Map = MapList[I] then
4028 begin
4029 MapIndex := I;
4030 Break;
4031 end;
4033 if MapIndex <> -255 then
4034 begin
4035 if MapIndex = High(MapList) then
4036 Result := MapList[Low(MapList)]
4037 else
4038 Result := MapList[MapIndex + 1];
4040 if not g_Map_Exist(MapsDir + gGameSettings.WAD + ':\' + Result) then Result := Map;
4041 end;
4043 MapList := nil;
4044 end;
4046 procedure g_Game_NextLevel();
4047 begin
4048 if gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF, GM_COOP] then
4049 gExit := EXIT_ENDLEVELCUSTOM
4050 else
4051 begin
4052 gExit := EXIT_ENDLEVELSINGLE;
4053 Exit;
4054 end;
4056 if gNextMap <> '' then Exit;
4057 gNextMap := g_Game_GetNextMap();
4058 end;
4060 function g_Game_IsTestMap(): Boolean;
4061 var
4062 FName, Sect, Res: String;
4063 begin
4064 g_ProcessResourceStr(gMapInfo.Map, FName, Sect, Res);
4065 Result := UpperCase(Res) = TEST_MAP_NAME;
4066 end;
4068 procedure g_Game_DeleteTestMap();
4069 var
4070 a: Integer;
4071 MapName: Char16;
4072 WadName: string;
4074 WAD: TWADFile;
4075 MapList: SArray;
4076 time: Integer;
4078 begin
4079 a := Pos('.wad:\', gMapToDelete);
4080 if a = 0 then
4081 Exit;
4083 // Âûäåëÿåì èìÿ wad-ôàéëà è èìÿ êàðòû:
4084 WadName := Copy(gMapToDelete, 1, a + 3);
4085 Delete(gMapToDelete, 1, a + 5);
4086 gMapToDelete := UpperCase(gMapToDelete);
4087 MapName := '';
4088 CopyMemory(@MapName[0], @gMapToDelete[1], Min(16, Length(gMapToDelete)));
4091 // Èìÿ êàðòû íå ñòàíäàðòíîå òåñòîâîå:
4092 if MapName <> TEST_MAP_NAME then
4093 Exit;
4095 if not gTempDelete then
4096 begin
4097 time := g_GetFileTime(WadName);
4098 WAD := TWADFile.Create();
4100 // ×èòàåì Wad-ôàéë:
4101 if not WAD.ReadFile(WadName) then
4102 begin // Íåò òàêîãî WAD-ôàéëà
4103 WAD.Free();
4104 Exit;
4105 end;
4107 // Ñîñòàâëÿåì ñïèñîê êàðò è èùåì íóæíóþ:
4108 WAD.CreateImage();
4109 MapList := WAD.GetResourcesList('');
4111 if MapList <> nil then
4112 for a := 0 to High(MapList) do
4113 if MapList[a] = MapName then
4114 begin
4115 // Óäàëÿåì è ñîõðàíÿåì:
4116 WAD.RemoveResource('', MapName);
4117 WAD.SaveTo(WadName);
4118 Break;
4119 end;
4121 WAD.Free();
4122 g_SetFileTime(WadName, time);
4123 end else
4125 if gTempDelete then DeleteFile(WadName);
4126 end;
4128 procedure GameCVars(P: SArray);
4129 var
4130 a, b: Integer;
4131 stat: TPlayerStatArray;
4132 cmd, s: string;
4133 config: TConfig;
4134 begin
4135 stat := nil;
4136 cmd := LowerCase(P[0]);
4137 if cmd = 'r_showfps' then
4138 begin
4139 if (Length(P) > 1) and
4140 ((P[1] = '1') or (P[1] = '0')) then
4141 gShowFPS := (P[1][1] = '1');
4143 if gShowFPS then
4144 g_Console_Add(_lc[I_MSG_SHOW_FPS_ON])
4145 else
4146 g_Console_Add(_lc[I_MSG_SHOW_FPS_OFF]);
4147 end
4148 else if (cmd = 'g_friendlyfire') and not g_Game_IsClient then
4149 begin
4150 with gGameSettings do
4151 begin
4152 if (Length(P) > 1) and
4153 ((P[1] = '1') or (P[1] = '0')) then
4154 begin
4155 if (P[1][1] = '1') then
4156 Options := Options or GAME_OPTION_TEAMDAMAGE
4157 else
4158 Options := Options and (not GAME_OPTION_TEAMDAMAGE);
4159 end;
4161 if (LongBool(Options and GAME_OPTION_TEAMDAMAGE)) then
4162 g_Console_Add(_lc[I_MSG_FRIENDLY_FIRE_ON])
4163 else
4164 g_Console_Add(_lc[I_MSG_FRIENDLY_FIRE_OFF]);
4166 if g_Game_IsNet then MH_SEND_GameSettings;
4167 end;
4168 end
4169 else if (cmd = 'g_weaponstay') and not g_Game_IsClient then
4170 begin
4171 with gGameSettings do
4172 begin
4173 if (Length(P) > 1) and
4174 ((P[1] = '1') or (P[1] = '0')) then
4175 begin
4176 if (P[1][1] = '1') then
4177 Options := Options or GAME_OPTION_WEAPONSTAY
4178 else
4179 Options := Options and (not GAME_OPTION_WEAPONSTAY);
4180 end;
4182 if (LongBool(Options and GAME_OPTION_WEAPONSTAY)) then
4183 g_Console_Add(_lc[I_MSG_WEAPONSTAY_ON])
4184 else
4185 g_Console_Add(_lc[I_MSG_WEAPONSTAY_OFF]);
4187 if g_Game_IsNet then MH_SEND_GameSettings;
4188 end;
4189 end
4190 else if cmd = 'g_gamemode' then
4191 begin
4192 a := g_Game_TextToMode(P[1]);
4193 if a = GM_SINGLE then a := GM_COOP;
4194 if (Length(P) > 1) and (a <> GM_NONE) and (not g_Game_IsClient) then
4195 begin
4196 gSwitchGameMode := a;
4197 if (gGameOn and (gGameSettings.GameMode = GM_SINGLE)) or
4198 (gState = STATE_INTERSINGLE) then
4199 gSwitchGameMode := GM_SINGLE;
4200 if not gGameOn then
4201 gGameSettings.GameMode := gSwitchGameMode;
4202 end;
4203 if gSwitchGameMode = gGameSettings.GameMode then
4204 g_Console_Add(Format(_lc[I_MSG_GAMEMODE_CURRENT],
4205 [g_Game_ModeToText(gGameSettings.GameMode)]))
4206 else
4207 g_Console_Add(Format(_lc[I_MSG_GAMEMODE_CHANGE],
4208 [g_Game_ModeToText(gGameSettings.GameMode),
4209 g_Game_ModeToText(gSwitchGameMode)]));
4210 end
4211 else if (cmd = 'g_allow_exit') and not g_Game_IsClient then
4212 begin
4213 with gGameSettings do
4214 begin
4215 if (Length(P) > 1) and
4216 ((P[1] = '1') or (P[1] = '0')) then
4217 begin
4218 if (P[1][1] = '1') then
4219 Options := Options or GAME_OPTION_ALLOWEXIT
4220 else
4221 Options := Options and (not GAME_OPTION_ALLOWEXIT);
4222 end;
4224 if (LongBool(Options and GAME_OPTION_ALLOWEXIT)) then
4225 g_Console_Add(_lc[I_MSG_ALLOWEXIT_ON])
4226 else
4227 g_Console_Add(_lc[I_MSG_ALLOWEXIT_OFF]);
4228 g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
4230 if g_Game_IsNet then MH_SEND_GameSettings;
4231 end;
4232 end
4233 else if (cmd = 'g_allow_monsters') and not g_Game_IsClient then
4234 begin
4235 with gGameSettings do
4236 begin
4237 if (Length(P) > 1) and
4238 ((P[1] = '1') or (P[1] = '0')) then
4239 begin
4240 if (P[1][1] = '1') then
4241 Options := Options or GAME_OPTION_MONSTERS
4242 else
4243 Options := Options and (not GAME_OPTION_MONSTERS);
4244 end;
4246 if (LongBool(Options and GAME_OPTION_MONSTERS)) then
4247 g_Console_Add(_lc[I_MSG_ALLOWMON_ON])
4248 else
4249 g_Console_Add(_lc[I_MSG_ALLOWMON_OFF]);
4250 g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
4252 if g_Game_IsNet then MH_SEND_GameSettings;
4253 end;
4254 end
4255 else if (cmd = 'g_bot_vsplayers') and not g_Game_IsClient then
4256 begin
4257 with gGameSettings do
4258 begin
4259 if (Length(P) > 1) and
4260 ((P[1] = '1') or (P[1] = '0')) then
4261 begin
4262 if (P[1][1] = '1') then
4263 Options := Options or GAME_OPTION_BOTVSPLAYER
4264 else
4265 Options := Options and (not GAME_OPTION_BOTVSPLAYER);
4266 end;
4268 if (LongBool(Options and GAME_OPTION_BOTVSPLAYER)) then
4269 g_Console_Add(_lc[I_MSG_BOTSVSPLAYERS_ON])
4270 else
4271 g_Console_Add(_lc[I_MSG_BOTSVSPLAYERS_OFF]);
4273 if g_Game_IsNet then MH_SEND_GameSettings;
4274 end;
4275 end
4276 else if (cmd = 'g_bot_vsmonsters') and not g_Game_IsClient then
4277 begin
4278 with gGameSettings do
4279 begin
4280 if (Length(P) > 1) and
4281 ((P[1] = '1') or (P[1] = '0')) then
4282 begin
4283 if (P[1][1] = '1') then
4284 Options := Options or GAME_OPTION_BOTVSMONSTER
4285 else
4286 Options := Options and (not GAME_OPTION_BOTVSMONSTER);
4287 end;
4289 if (LongBool(Options and GAME_OPTION_BOTVSMONSTER)) then
4290 g_Console_Add(_lc[I_MSG_BOTSVSMONSTERS_ON])
4291 else
4292 g_Console_Add(_lc[I_MSG_BOTSVSMONSTERS_OFF]);
4294 if g_Game_IsNet then MH_SEND_GameSettings;
4295 end;
4296 end
4297 else if (cmd = 'g_warmuptime') and not g_Game_IsClient then
4298 begin
4299 if Length(P) > 1 then
4300 begin
4301 if StrToIntDef(P[1], gGameSettings.WarmupTime) = 0 then
4302 gGameSettings.WarmupTime := 30
4303 else
4304 gGameSettings.WarmupTime := StrToIntDef(P[1], gGameSettings.WarmupTime);
4305 end;
4307 g_Console_Add(Format(_lc[I_MSG_WARMUP],
4308 [gGameSettings.WarmupTime]));
4309 g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
4310 end
4311 else if cmd = 'net_interp' then
4312 begin
4313 if (Length(P) > 1) then
4314 NetInterpLevel := StrToIntDef(P[1], NetInterpLevel);
4316 g_Console_Add('net_interp = ' + IntToStr(NetInterpLevel));
4317 config := TConfig.CreateFile(GameDir+'/'+CONFIG_FILENAME);
4318 config.WriteInt('Client', 'InterpolationSteps', NetInterpLevel);
4319 config.SaveFile(GameDir+'/'+CONFIG_FILENAME);
4320 config.Free();
4321 end
4322 else if cmd = 'net_forceplayerupdate' then
4323 begin
4324 if (Length(P) > 1) and
4325 ((P[1] = '1') or (P[1] = '0')) then
4326 NetForcePlayerUpdate := (P[1][1] = '1');
4328 if NetForcePlayerUpdate then
4329 g_Console_Add('net_forceplayerupdate = 1')
4330 else
4331 g_Console_Add('net_forceplayerupdate = 0');
4332 config := TConfig.CreateFile(GameDir+'/'+CONFIG_FILENAME);
4333 config.WriteBool('Client', 'ForcePlayerUpdate', NetForcePlayerUpdate);
4334 config.SaveFile(GameDir+'/'+CONFIG_FILENAME);
4335 config.Free();
4336 end
4337 else if cmd = 'net_predictself' then
4338 begin
4339 if (Length(P) > 1) and
4340 ((P[1] = '1') or (P[1] = '0')) then
4341 NetPredictSelf := (P[1][1] = '1');
4343 if NetPredictSelf then
4344 g_Console_Add('net_predictself = 1')
4345 else
4346 g_Console_Add('net_predictself = 0');
4347 config := TConfig.CreateFile(GameDir+'/'+CONFIG_FILENAME);
4348 config.WriteBool('Client', 'PredictSelf', NetPredictSelf);
4349 config.SaveFile(GameDir+'/'+CONFIG_FILENAME);
4350 config.Free();
4351 end
4352 else if cmd = 'sv_name' then
4353 begin
4354 if (Length(P) > 1) and (Length(P[1]) > 0) then
4355 begin
4356 NetServerName := P[1];
4357 if Length(NetServerName) > 64 then
4358 SetLength(NetServerName, 64);
4359 if g_Game_IsServer and g_Game_IsNet and NetUseMaster then
4360 g_Net_Slist_Update;
4361 end;
4363 g_Console_Add(cmd + ' = "' + NetServerName + '"');
4364 end
4365 else if cmd = 'sv_passwd' then
4366 begin
4367 if (Length(P) > 1) and (Length(P[1]) > 0) then
4368 begin
4369 NetPassword := P[1];
4370 if Length(NetPassword) > 24 then
4371 SetLength(NetPassword, 24);
4372 if g_Game_IsServer and g_Game_IsNet and NetUseMaster then
4373 g_Net_Slist_Update;
4374 end;
4376 g_Console_Add(cmd + ' = "' + AnsiLowerCase(NetPassword) + '"');
4377 end
4378 else if cmd = 'sv_maxplrs' then
4379 begin
4380 if (Length(P) > 1) then
4381 begin
4382 NetMaxClients := Min(Max(StrToIntDef(P[1], NetMaxClients), 1), NET_MAXCLIENTS);
4383 if g_Game_IsServer and g_Game_IsNet then
4384 begin
4385 b := 0;
4386 for a := 0 to High(NetClients) do
4387 if NetClients[a].Used then
4388 begin
4389 Inc(b);
4390 if b > NetMaxClients then
4391 begin
4392 s := g_Player_Get(NetClients[a].Player).Name;
4393 enet_peer_disconnect(NetClients[a].Peer, NET_DISC_FULL);
4394 g_Console_Add(Format(_lc[I_PLAYER_KICK], [s]));
4395 MH_SEND_GameEvent(NET_EV_PLAYER_KICK, 0, s);
4396 end;
4397 end;
4398 if NetUseMaster then
4399 g_Net_Slist_Update;
4400 end;
4401 end;
4403 g_Console_Add(cmd + ' = ' + IntToStr(NetMaxClients));
4404 end
4405 else if cmd = 'sv_public' then
4406 begin
4407 if (Length(P) > 1) then
4408 begin
4409 NetUseMaster := StrToIntDef(P[1], Byte(NetUseMaster)) > 0;
4410 if g_Game_IsServer and g_Game_IsNet then
4411 if NetUseMaster then
4412 begin
4413 if NetMPeer = nil then
4414 if not g_Net_Slist_Connect() then
4415 g_Console_Add(_lc[I_NET_MSG_ERROR] + _lc[I_NET_SLIST_ERROR]);
4416 g_Net_Slist_Update();
4417 end
4418 else
4419 if NetMPeer <> nil then
4420 g_Net_Slist_Disconnect();
4421 end;
4423 g_Console_Add(cmd + ' = ' + IntToStr(Byte(NetUseMaster)));
4424 end
4425 else if cmd = 'sv_intertime' then
4426 begin
4427 if (Length(P) > 1) then
4428 gDefInterTime := Min(Max(StrToIntDef(P[1], gDefInterTime), -1), 120);
4430 g_Console_Add(cmd + ' = ' + IntToStr(gDefInterTime));
4431 end
4432 else if cmd = 'p1_name' then
4433 begin
4434 if (Length(P) > 1) and gGameOn then
4435 begin
4436 if g_Game_IsClient then
4437 begin
4438 gPlayer1Settings.Name := b_Text_Unformat(P[1]);
4439 MC_SEND_PlayerSettings;
4440 end
4441 else
4442 if gPlayer1 <> nil then
4443 begin
4444 gPlayer1.Name := b_Text_Unformat(P[1]);
4445 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer1.UID);
4446 end
4447 else
4448 gPlayer1Settings.Name := b_Text_Unformat(P[1]);
4449 end;
4450 end
4451 else if cmd = 'p2_name' then
4452 begin
4453 if (Length(P) > 1) and gGameOn then
4454 begin
4455 if g_Game_IsClient then
4456 begin
4457 gPlayer2Settings.Name := b_Text_Unformat(P[1]);
4458 MC_SEND_PlayerSettings;
4459 end
4460 else
4461 if gPlayer2 <> nil then
4462 begin
4463 gPlayer2.Name := b_Text_Unformat(P[1]);
4464 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer2.UID);
4465 end
4466 else
4467 gPlayer2Settings.Name := b_Text_Unformat(P[1]);
4468 end;
4469 end
4470 else if cmd = 'p1_color' then
4471 begin
4472 if Length(P) > 3 then
4473 if g_Game_IsClient then
4474 begin
4475 gPlayer1Settings.Color := _RGB(EnsureRange(StrToIntDef(P[1], 0), 0, 255),
4476 EnsureRange(StrToIntDef(P[2], 0), 0, 255),
4477 EnsureRange(StrToIntDef(P[3], 0), 0, 255));
4478 MC_SEND_PlayerSettings;
4479 end
4480 else
4481 if gPlayer1 <> nil then
4482 begin
4483 gPlayer1.Model.SetColor(EnsureRange(StrToIntDef(P[1], 0), 0, 255),
4484 EnsureRange(StrToIntDef(P[2], 0), 0, 255),
4485 EnsureRange(StrToIntDef(P[3], 0), 0, 255));
4486 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer1.UID);
4487 end
4488 else
4489 gPlayer1Settings.Color := _RGB(EnsureRange(StrToIntDef(P[1], 0), 0, 255),
4490 EnsureRange(StrToIntDef(P[2], 0), 0, 255),
4491 EnsureRange(StrToIntDef(P[3], 0), 0, 255));
4492 end
4493 else if (cmd = 'p2_color') and not g_Game_IsNet then
4494 begin
4495 if Length(P) > 3 then
4496 if g_Game_IsClient then
4497 begin
4498 gPlayer2Settings.Color := _RGB(EnsureRange(StrToIntDef(P[1], 0), 0, 255),
4499 EnsureRange(StrToIntDef(P[2], 0), 0, 255),
4500 EnsureRange(StrToIntDef(P[3], 0), 0, 255));
4501 MC_SEND_PlayerSettings;
4502 end
4503 else
4504 if gPlayer2 <> nil then
4505 begin
4506 gPlayer2.Model.SetColor(EnsureRange(StrToIntDef(P[1], 0), 0, 255),
4507 EnsureRange(StrToIntDef(P[2], 0), 0, 255),
4508 EnsureRange(StrToIntDef(P[3], 0), 0, 255));
4509 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer2.UID);
4510 end
4511 else
4512 gPlayer2Settings.Color := _RGB(EnsureRange(StrToIntDef(P[1], 0), 0, 255),
4513 EnsureRange(StrToIntDef(P[2], 0), 0, 255),
4514 EnsureRange(StrToIntDef(P[3], 0), 0, 255));
4515 end
4516 else if gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT] then
4517 begin
4518 if cmd = 'r_showtime' then
4519 begin
4520 if (Length(P) > 1) and
4521 ((P[1] = '1') or (P[1] = '0')) then
4522 gShowTime := (P[1][1] = '1');
4524 if gShowTime then
4525 g_Console_Add(_lc[I_MSG_TIME_ON])
4526 else
4527 g_Console_Add(_lc[I_MSG_TIME_OFF]);
4528 end
4529 else if cmd = 'r_showscore' then
4530 begin
4531 if (Length(P) > 1) and
4532 ((P[1] = '1') or (P[1] = '0')) then
4533 gShowGoals := (P[1][1] = '1');
4535 if gShowGoals then
4536 g_Console_Add(_lc[I_MSG_SCORE_ON])
4537 else
4538 g_Console_Add(_lc[I_MSG_SCORE_OFF]);
4539 end
4540 else if cmd = 'r_showstat' then
4541 begin
4542 if (Length(P) > 1) and
4543 ((P[1] = '1') or (P[1] = '0')) then
4544 gShowStat := (P[1][1] = '1');
4546 if gShowStat then
4547 g_Console_Add(_lc[I_MSG_STATS_ON])
4548 else
4549 g_Console_Add(_lc[I_MSG_STATS_OFF]);
4550 end
4551 else if cmd = 'r_showkillmsg' then
4552 begin
4553 if (Length(P) > 1) and
4554 ((P[1] = '1') or (P[1] = '0')) then
4555 gShowKillMsg := (P[1][1] = '1');
4557 if gShowKillMsg then
4558 g_Console_Add(_lc[I_MSG_KILL_MSGS_ON])
4559 else
4560 g_Console_Add(_lc[I_MSG_KILL_MSGS_OFF]);
4561 end
4562 else if cmd = 'r_showlives' then
4563 begin
4564 if (Length(P) > 1) and
4565 ((P[1] = '1') or (P[1] = '0')) then
4566 gShowLives := (P[1][1] = '1');
4568 if gShowLives then
4569 g_Console_Add(_lc[I_MSG_LIVES_ON])
4570 else
4571 g_Console_Add(_lc[I_MSG_LIVES_OFF]);
4572 end
4573 else if cmd = 'r_showspect' then
4574 begin
4575 if (Length(P) > 1) and
4576 ((P[1] = '1') or (P[1] = '0')) then
4577 gSpectHUD := (P[1][1] = '1');
4579 if gSpectHUD then
4580 g_Console_Add(_lc[I_MSG_SPECT_HUD_ON])
4581 else
4582 g_Console_Add(_lc[I_MSG_SPECT_HUD_OFF]);
4583 end
4584 else if cmd = 'r_showping' then
4585 begin
4586 if (Length(P) > 1) and
4587 ((P[1] = '1') or (P[1] = '0')) then
4588 gShowPing := (P[1][1] = '1');
4590 if gShowPing then
4591 g_Console_Add(_lc[I_MSG_PING_ON])
4592 else
4593 g_Console_Add(_lc[I_MSG_PING_OFF]);
4594 end
4595 else if (cmd = 'g_scorelimit') and not g_Game_IsClient then
4596 begin
4597 if Length(P) > 1 then
4598 begin
4599 if StrToIntDef(P[1], gGameSettings.GoalLimit) = 0 then
4600 gGameSettings.GoalLimit := 0
4601 else
4602 begin
4603 b := 0;
4605 if gGameSettings.GameMode = GM_DM then
4606 begin // DM
4607 stat := g_Player_GetStats();
4608 if stat <> nil then
4609 for a := 0 to High(stat) do
4610 if stat[a].Frags > b then
4611 b := stat[a].Frags;
4612 end
4613 else // TDM/CTF
4614 b := Max(gTeamStat[TEAM_RED].Goals, gTeamStat[TEAM_BLUE].Goals);
4616 gGameSettings.GoalLimit := Max(StrToIntDef(P[1], gGameSettings.GoalLimit), b);
4617 end;
4619 if g_Game_IsNet then MH_SEND_GameSettings;
4620 end;
4622 g_Console_Add(Format(_lc[I_MSG_SCORE_LIMIT], [gGameSettings.GoalLimit]));
4623 end
4624 else if (cmd = 'g_timelimit') and not g_Game_IsClient then
4625 begin
4626 if (Length(P) > 1) and (StrToIntDef(P[1], -1) >= 0) then
4627 gGameSettings.TimeLimit := StrToIntDef(P[1], -1);
4629 g_Console_Add(Format(_lc[I_MSG_TIME_LIMIT],
4630 [gGameSettings.TimeLimit div 3600,
4631 (gGameSettings.TimeLimit div 60) mod 60,
4632 gGameSettings.TimeLimit mod 60]));
4633 if g_Game_IsNet then MH_SEND_GameSettings;
4634 end
4635 else if (cmd = 'g_maxlives') and not g_Game_IsClient then
4636 begin
4637 if Length(P) > 1 then
4638 begin
4639 if StrToIntDef(P[1], gGameSettings.MaxLives) = 0 then
4640 gGameSettings.MaxLives := 0
4641 else
4642 begin
4643 b := 0;
4644 stat := g_Player_GetStats();
4645 if stat <> nil then
4646 for a := 0 to High(stat) do
4647 if stat[a].Lives > b then
4648 b := stat[a].Lives;
4649 gGameSettings.MaxLives :=
4650 Max(StrToIntDef(P[1], gGameSettings.MaxLives), b);
4651 end;
4652 end;
4654 g_Console_Add(Format(_lc[I_MSG_LIVES],
4655 [gGameSettings.MaxLives]));
4656 if g_Game_IsNet then MH_SEND_GameSettings;
4657 end;
4658 end;
4659 end;
4661 procedure DebugCommands(P: SArray);
4662 var
4663 a, b: Integer;
4664 cmd: string;
4665 //pt: TPoint;
4666 begin
4667 // Êîìàíäû îòëàäî÷íîãî ðåæèìà:
4668 if gDebugMode then
4669 begin
4670 cmd := LowerCase(P[0]);
4671 if cmd = 'd_window' then
4672 begin
4673 g_Console_Add(Format('gWinPosX = %d, gWinPosY %d', [gWinPosX, gWinPosY]));
4674 g_Console_Add(Format('gWinRealPosX = %d, gWinRealPosY %d', [gWinRealPosX, gWinRealPosY]));
4675 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth, gScreenHeight]));
4676 g_Console_Add(Format('gWinSizeX = %d, gWinSizeY = %d', [gWinSizeX, gWinSizeY]));
4677 g_Console_Add(Format('Frame X = %d, Y = %d, Caption Y = %d', [gWinFrameX, gWinFrameY, gWinCaption]));
4678 end
4679 else if cmd = 'd_sounds' then
4680 begin
4681 if (Length(P) > 1) and
4682 ((P[1] = '1') or (P[1] = '0')) then
4683 g_Debug_Sounds := (P[1][1] = '1');
4685 g_Console_Add(Format('d_sounds is %d', [Byte(g_Debug_Sounds)]));
4686 end
4687 else if cmd = 'd_frames' then
4688 begin
4689 if (Length(P) > 1) and
4690 ((P[1] = '1') or (P[1] = '0')) then
4691 g_Debug_Frames := (P[1][1] = '1');
4693 g_Console_Add(Format('d_frames is %d', [Byte(g_Debug_Frames)]));
4694 end
4695 else if cmd = 'd_winmsg' then
4696 begin
4697 if (Length(P) > 1) and
4698 ((P[1] = '1') or (P[1] = '0')) then
4699 g_Debug_WinMsgs := (P[1][1] = '1');
4701 g_Console_Add(Format('d_winmsg is %d', [Byte(g_Debug_WinMsgs)]));
4702 end
4703 else if (cmd = 'd_monoff') and not g_Game_IsNet then
4704 begin
4705 if (Length(P) > 1) and
4706 ((P[1] = '1') or (P[1] = '0')) then
4707 g_Debug_MonsterOff := (P[1][1] = '1');
4709 g_Console_Add(Format('d_monoff is %d', [Byte(g_debug_MonsterOff)]));
4710 end
4711 else if (cmd = 'd_botoff') and not g_Game_IsNet then
4712 begin
4713 if Length(P) > 1 then
4714 case P[1][1] of
4715 '0': g_debug_BotAIOff := 0;
4716 '1': g_debug_BotAIOff := 1;
4717 '2': g_debug_BotAIOff := 2;
4718 '3': g_debug_BotAIOff := 3;
4719 end;
4721 g_Console_Add(Format('d_botoff is %d', [g_debug_BotAIOff]));
4722 end
4723 else if cmd = 'd_monster' then
4724 begin
4725 if gGameOn and (gPlayer1 <> nil) and (gPlayer1.Live) and (not g_Game_IsNet) then
4726 if Length(P) < 2 then
4727 begin
4728 g_Console_Add(cmd + ' [ID | Name] [behaviour]');
4729 g_Console_Add('ID | Name');
4730 for b := MONSTER_DEMON to MONSTER_MAN do
4731 g_Console_Add(Format('%2d | %s', [b, g_Monsters_GetNameByID(b)]));
4732 end else
4733 begin
4734 a := StrToIntDef(P[1], 0);
4735 if (a < MONSTER_DEMON) or (a > MONSTER_MAN) then
4736 a := g_Monsters_GetIDByName(P[1]);
4738 if (a < MONSTER_DEMON) or (a > MONSTER_MAN) then
4739 g_Console_Add(Format(_lc[I_MSG_NO_MONSTER], [P[1]]))
4740 else
4741 begin
4742 with gPlayer1.Obj do
4743 b := g_Monsters_Create(a,
4744 X + Rect.X + (Rect.Width div 2),
4745 Y + Rect.Y + Rect.Height,
4746 gPlayer1.Direction, True);
4747 if (Length(P) > 2) and (b >= 0) then
4748 gMonsters[b].MonsterBehaviour := Min(Max(StrToIntDef(P[2], BH_NORMAL), BH_NORMAL), BH_GOOD);
4749 end;
4750 end;
4751 end
4752 else if (cmd = 'd_health') then
4753 begin
4754 if (Length(P) > 1) and
4755 ((P[1] = '1') or (P[1] = '0')) then
4756 g_debug_HealthBar := (P[1][1] = '1');
4758 g_Console_Add(Format('d_health is %d', [Byte(g_debug_HealthBar)]));
4759 end
4760 else if (cmd = 'd_player') then
4761 begin
4762 if (Length(P) > 1) and
4763 ((P[1] = '1') or (P[1] = '0')) then
4764 g_debug_Player := (P[1][1] = '1');
4766 g_Console_Add(Format(cmd + ' is %d', [Byte(g_Debug_Player)]));
4767 end
4768 else if (cmd = 'd_joy') then
4769 begin
4770 for a := 1 to 8 do
4771 g_Console_Add(e_JoystickStateToString(a));
4772 end;
4773 end
4774 else
4775 g_Console_Add(_lc[I_MSG_NOT_DEBUG]);
4776 end;
4779 procedure GameCheats(P: SArray);
4780 var
4781 cmd: string;
4782 f, a: Integer;
4783 plr: TPlayer;
4784 begin
4785 if (not gGameOn) or (not gCheats) or ((gGameSettings.GameType <> GT_SINGLE) and
4786 (gGameSettings.GameMode <> GM_COOP) and (not gDebugMode)) or g_Game_IsNet then
4787 begin
4788 g_Console_Add('not available');
4789 exit;
4790 end;
4791 plr := gPlayer1;
4792 if plr = nil then
4793 begin
4794 g_Console_Add('where is the player?!');
4795 exit;
4796 end;
4797 cmd := LowerCase(P[0]);
4798 // god
4799 if cmd = 'god' then
4800 begin
4801 plr.GodMode := not plr.GodMode;
4802 if plr.GodMode then g_Console_Add('player is godlike now') else g_Console_Add('player is mortal now');
4803 exit;
4804 end;
4805 // give <health|exit|weapons|air|suit|jetpack|berserk|all>
4806 if cmd = 'give' then
4807 begin
4808 if length(P) < 2 then begin g_Console_Add('give what?!'); exit; end;
4809 for f := 1 to High(P) do
4810 begin
4811 cmd := LowerCase(P[f]);
4812 if cmd = 'health' then begin plr.RestoreHealthArmor(); g_Console_Add('player feels himself better'); continue; end;
4813 if (cmd = 'all') or (cmd = 'weapons') then begin plr.AllRulez(False); g_Console_Add('player got the gifts'); continue; end;
4814 if cmd = 'exit' then
4815 begin
4816 if gTriggers <> nil then
4817 begin
4818 for a := 0 to High(gTriggers) do
4819 begin
4820 if gTriggers[a].TriggerType = TRIGGER_EXIT then
4821 begin
4822 g_Console_Add('player left the map');
4823 gExitByTrigger := True;
4824 g_Game_ExitLevel(gTriggers[a].Data.MapName);
4825 break;
4826 end;
4827 end;
4828 end;
4829 continue;
4830 end;
4831 if cmd = 'air' then begin plr.GiveItem(ITEM_OXYGEN); g_Console_Add('player got some air'); continue; end;
4832 if cmd = 'jetpack' then begin plr.GiveItem(ITEM_JETPACK); g_Console_Add('player got jetpack'); continue; end;
4833 if cmd = 'suit' then begin plr.GiveItem(ITEM_SUIT); g_Console_Add('player got envirosuit'); continue; end;
4834 if cmd = 'berserk' then begin plr.GiveItem(ITEM_MEDKIT_BLACK); g_Console_Add('player got berserk pack'); continue; end;
4835 g_Console_Add('i don''t know how to give '''+cmd+'''!');
4836 end;
4837 exit;
4838 end;
4839 // open
4840 if cmd = 'open' then
4841 begin
4842 g_Console_Add('player activated sesame');
4843 g_Triggers_OpenAll();
4844 exit;
4845 end;
4846 // fly
4847 if cmd = 'fly' then
4848 begin
4849 gFly := not gFly;
4850 if gFly then g_Console_Add('player feels himself lighter') else g_Console_Add('player lost his wings');
4851 exit;
4852 end;
4853 // noclip
4854 if cmd = 'noclip' then
4855 begin
4856 plr.SwitchNoClip;
4857 g_Console_Add('wall hardeness adjusted');
4858 exit;
4859 end;
4860 // notarget
4861 if cmd = 'notarget' then
4862 begin
4863 plr.NoTarget := not plr.NoTarget;
4864 if plr.NoTarget then g_Console_Add('player hides in shadows') else g_Console_Add('player is brave again');
4865 exit;
4866 end;
4867 // noreload
4868 if cmd = 'noreload' then
4869 begin
4870 plr.NoReload := not plr.NoReload;
4871 if plr.NoReload then g_Console_Add('player is action hero now') else g_Console_Add('player is ordinary man now');
4872 exit;
4873 end;
4874 // speedy
4875 if cmd = 'speedy' then
4876 begin
4877 MAX_RUNVEL := 32-MAX_RUNVEL;
4878 g_Console_Add('speed adjusted');
4879 exit;
4880 end;
4881 // jumpy
4882 if cmd = 'jumpy' then
4883 begin
4884 VEL_JUMP := 30-VEL_JUMP;
4885 g_Console_Add('jump height adjusted');
4886 exit;
4887 end;
4888 // automap
4889 if cmd = 'automap' then
4890 begin
4891 gShowMap := not gShowMap;
4892 if gShowMap then g_Console_Add('player gains second sight') else g_Console_Add('player lost second sight');
4893 exit;
4894 end;
4895 // aimline
4896 if cmd = 'aimline' then
4897 begin
4898 gAimLine := not gAimLine;
4899 if gAimLine then g_Console_Add('player gains laser sight') else g_Console_Add('player lost laser sight');
4900 exit;
4901 end;
4902 end;
4904 procedure GameCommands(P: SArray);
4905 var
4906 a, b: Integer;
4907 s, pw: String;
4908 chstr: string;
4909 cmd: string;
4910 pl: pTNetClient = nil;
4911 plr: TPlayer;
4912 prt: Word;
4913 nm: Boolean;
4914 listen: LongWord;
4915 begin
4916 // Îáùèå êîìàíäû:
4917 cmd := LowerCase(P[0]);
4918 chstr := '';
4919 if (cmd = 'quit') or
4920 (cmd = 'exit') then
4921 begin
4922 g_Game_Free();
4923 g_Game_Quit();
4924 Exit;
4925 end
4926 else if cmd = 'pause' then
4927 begin
4928 if (g_ActiveWindow = nil) then
4929 g_Game_Pause(not gPause);
4930 end
4931 else if cmd = 'endgame' then
4932 gExit := EXIT_SIMPLE
4933 else if cmd = 'restart' then
4934 begin
4935 if gGameOn or (gState in [STATE_INTERSINGLE, STATE_INTERCUSTOM]) then
4936 begin
4937 if g_Game_IsClient then
4938 begin
4939 g_Console_Add(_lc[I_MSG_SERVERONLY]);
4940 Exit;
4941 end;
4942 g_Game_Restart();
4943 end else
4944 g_Console_Add(_lc[I_MSG_NOT_GAME]);
4945 end
4946 else if cmd = 'kick' then
4947 begin
4948 if g_Game_IsServer then
4949 begin
4950 if Length(P) < 2 then
4951 begin
4952 g_Console_Add('kick <name>');
4953 Exit;
4954 end;
4955 if P[1] = '' then
4956 begin
4957 g_Console_Add('kick <name>');
4958 Exit;
4959 end;
4961 if g_Game_IsNet then
4962 pl := g_Net_Client_ByName(P[1]);
4963 if (pl <> nil) then
4964 begin
4965 s := g_Net_ClientName_ByID(pl^.ID);
4966 enet_peer_disconnect(pl^.Peer, NET_DISC_KICK);
4967 g_Console_Add(Format(_lc[I_PLAYER_KICK], [s]));
4968 MH_SEND_GameEvent(NET_EV_PLAYER_KICK, 0, s);
4969 if NetUseMaster then
4970 g_Net_Slist_Update;
4971 end else if gPlayers <> nil then
4972 for a := Low(gPlayers) to High(gPlayers) do
4973 if gPlayers[a] <> nil then
4974 if Copy(LowerCase(gPlayers[a].Name), 1, Length(P[1])) = LowerCase(P[1]) then
4975 begin
4976 // Íå îòêëþ÷àòü îñíîâíûõ èãðîêîâ â ñèíãëå
4977 if not(gPlayers[a] is TBot) and (gGameSettings.GameType = GT_SINGLE) then
4978 continue;
4979 gPlayers[a].Lives := 0;
4980 gPlayers[a].Kill(K_SIMPLEKILL, 0, HIT_DISCON);
4981 g_Console_Add(Format(_lc[I_PLAYER_LEAVE], [gPlayers[a].Name]), True);
4982 g_Player_Remove(gPlayers[a].UID);
4983 if NetUseMaster then
4984 g_Net_Slist_Update;
4985 // Åñëè íå ïåðåìåøàòü, ïðè äîáàâëåíèè íîâûõ áîòîâ ïîÿâÿòñÿ ñòàðûå
4986 g_Bot_MixNames();
4987 end;
4988 end else
4989 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
4990 end
4991 else if cmd = 'kick_id' then
4992 begin
4993 if g_Game_IsServer and g_Game_IsNet then
4994 begin
4995 if Length(P) < 2 then
4996 begin
4997 g_Console_Add('kick_id <client ID>');
4998 Exit;
4999 end;
5000 if P[1] = '' then
5001 begin
5002 g_Console_Add('kick_id <client ID>');
5003 Exit;
5004 end;
5006 a := StrToIntDef(P[1], 0);
5007 if (NetClients <> nil) and (a <= High(NetClients)) then
5008 begin
5009 if NetClients[a].Used and (NetClients[a].Peer <> nil) then
5010 begin
5011 s := g_Net_ClientName_ByID(NetClients[a].ID);
5012 enet_peer_disconnect(NetClients[a].Peer, NET_DISC_KICK);
5013 g_Console_Add(Format(_lc[I_PLAYER_KICK], [s]));
5014 MH_SEND_GameEvent(NET_EV_PLAYER_KICK, 0, s);
5015 if NetUseMaster then
5016 g_Net_Slist_Update;
5017 end;
5018 end;
5019 end else
5020 g_Console_Add(_lc[I_MSG_SERVERONLY]);
5021 end
5022 else if cmd = 'ban' then
5023 begin
5024 if g_Game_IsServer and g_Game_IsNet then
5025 begin
5026 if Length(P) < 2 then
5027 begin
5028 g_Console_Add('ban <name>');
5029 Exit;
5030 end;
5031 if P[1] = '' then
5032 begin
5033 g_Console_Add('ban <name>');
5034 Exit;
5035 end;
5037 pl := g_Net_Client_ByName(P[1]);
5038 if (pl <> nil) then
5039 begin
5040 s := g_Net_ClientName_ByID(pl^.ID);
5041 g_Net_BanHost(pl^.Peer^.address.host, False);
5042 enet_peer_disconnect(pl^.Peer, NET_DISC_TEMPBAN);
5043 g_Console_Add(Format(_lc[I_PLAYER_BAN], [s]));
5044 MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s);
5045 if NetUseMaster then
5046 g_Net_Slist_Update;
5047 end else
5048 g_Console_Add(Format(_lc[I_NET_ERR_NAME404], [P[1]]));
5049 end else
5050 g_Console_Add(_lc[I_MSG_SERVERONLY]);
5051 end
5052 else if cmd = 'ban_id' then
5053 begin
5054 if g_Game_IsServer and g_Game_IsNet then
5055 begin
5056 if Length(P) < 2 then
5057 begin
5058 g_Console_Add('ban_id <client ID>');
5059 Exit;
5060 end;
5061 if P[1] = '' then
5062 begin
5063 g_Console_Add('ban_id <client ID>');
5064 Exit;
5065 end;
5067 a := StrToIntDef(P[1], 0);
5068 if (NetClients <> nil) and (a <= High(NetClients)) then
5069 if NetClients[a].Used and (NetClients[a].Peer <> nil) then
5070 begin
5071 s := g_Net_ClientName_ByID(NetClients[a].ID);
5072 g_Net_BanHost(NetClients[a].Peer^.address.host, False);
5073 enet_peer_disconnect(NetClients[a].Peer, NET_DISC_TEMPBAN);
5074 g_Console_Add(Format(_lc[I_PLAYER_BAN], [s]));
5075 MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s);
5076 if NetUseMaster then
5077 g_Net_Slist_Update;
5078 end;
5079 end else
5080 g_Console_Add(_lc[I_MSG_SERVERONLY]);
5081 end
5082 else if cmd = 'permban' then
5083 begin
5084 if g_Game_IsServer and g_Game_IsNet then
5085 begin
5086 if Length(P) < 2 then
5087 begin
5088 g_Console_Add('permban <name>');
5089 Exit;
5090 end;
5091 if P[1] = '' then
5092 begin
5093 g_Console_Add('permban <name>');
5094 Exit;
5095 end;
5097 pl := g_Net_Client_ByName(P[1]);
5098 if (pl <> nil) then
5099 begin
5100 s := g_Net_ClientName_ByID(pl^.ID);
5101 g_Net_BanHost(pl^.Peer^.address.host);
5102 enet_peer_disconnect(pl^.Peer, NET_DISC_BAN);
5103 g_Net_SaveBanList();
5104 g_Console_Add(Format(_lc[I_PLAYER_BAN], [s]));
5105 MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s);
5106 if NetUseMaster then
5107 g_Net_Slist_Update;
5108 end else
5109 g_Console_Add(Format(_lc[I_NET_ERR_NAME404], [P[1]]));
5110 end else
5111 g_Console_Add(_lc[I_MSG_SERVERONLY]);
5112 end
5113 else if cmd = 'permban_id' then
5114 begin
5115 if g_Game_IsServer and g_Game_IsNet then
5116 begin
5117 if Length(P) < 2 then
5118 begin
5119 g_Console_Add('permban_id <client ID>');
5120 Exit;
5121 end;
5122 if P[1] = '' then
5123 begin
5124 g_Console_Add('permban_id <client ID>');
5125 Exit;
5126 end;
5128 a := StrToIntDef(P[1], 0);
5129 if (NetClients <> nil) and (a <= High(NetClients)) then
5130 if NetClients[a].Used and (NetClients[a].Peer <> nil) then
5131 begin
5132 s := g_Net_ClientName_ByID(NetClients[a].ID);
5133 g_Net_BanHost(NetClients[a].Peer^.address.host);
5134 enet_peer_disconnect(NetClients[a].Peer, NET_DISC_BAN);
5135 g_Net_SaveBanList();
5136 g_Console_Add(Format(_lc[I_PLAYER_BAN], [s]));
5137 MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s);
5138 if NetUseMaster then
5139 g_Net_Slist_Update;
5140 end;
5141 end else
5142 g_Console_Add(_lc[I_MSG_SERVERONLY]);
5143 end
5144 else if cmd = 'unban' then
5145 begin
5146 if g_Game_IsServer and g_Game_IsNet then
5147 begin
5148 if Length(P) < 2 then
5149 begin
5150 g_Console_Add('unban <IP Address>');
5151 Exit;
5152 end;
5153 if P[1] = '' then
5154 begin
5155 g_Console_Add('unban <IP Address>');
5156 Exit;
5157 end;
5159 if g_Net_UnbanHost(P[1]) then
5160 begin
5161 g_Console_Add(Format(_lc[I_MSG_UNBAN_OK], [P[1]]));
5162 g_Net_SaveBanList();
5163 end else
5164 g_Console_Add(Format(_lc[I_MSG_UNBAN_FAIL], [P[1]]));
5165 end else
5166 g_Console_Add(_lc[I_MSG_SERVERONLY]);
5167 end
5168 else if cmd = 'clientlist' then
5169 begin
5170 if g_Game_IsServer and g_Game_IsNet then
5171 begin
5172 b := 0;
5173 if NetClients <> nil then
5174 for a := Low(NetClients) to High(NetClients) do
5175 if NetClients[a].Used and (NetClients[a].Peer <> nil) then
5176 begin
5177 plr := g_Player_Get(NetClients[a].Player);
5178 if plr = nil then continue;
5179 Inc(b);
5180 g_Console_Add(Format('#%2d: %-15s | %s', [a,
5181 IpToStr(NetClients[a].Peer^.address.host), plr.Name]));
5182 end;
5183 if b = 0 then
5184 g_Console_Add(_lc[I_MSG_NOCLIENTS]);
5185 end else
5186 g_Console_Add(_lc[I_MSG_SERVERONLY]);
5187 end
5188 else if cmd = 'connect' then
5189 begin
5190 if (NetMode = NET_NONE) then
5191 begin
5192 if Length(P) < 2 then
5193 begin
5194 g_Console_Add('connect <IP> [port] [password]');
5195 Exit;
5196 end;
5197 if P[1] = '' then
5198 begin
5199 g_Console_Add('connect <IP> [port] [password]');
5200 Exit;
5201 end;
5203 if Length(P) > 2 then
5204 prt := StrToIntDef(P[2], 25666)
5205 else
5206 prt := 25666;
5208 if Length(P) > 3 then
5209 pw := P[3]
5210 else
5211 pw := '';
5213 g_Game_StartClient(P[1], prt, pw);
5214 end;
5215 end
5216 else if cmd = 'disconnect' then
5217 begin
5218 if (NetMode = NET_CLIENT) then
5219 g_Net_Disconnect();
5220 end
5221 else if cmd = 'reconnect' then
5222 begin
5223 if (NetMode = NET_SERVER) then
5224 Exit;
5226 if (NetMode = NET_CLIENT) then
5227 begin
5228 g_Net_Disconnect();
5229 gExit := EXIT_SIMPLE;
5230 EndGame;
5231 end;
5233 //TODO: Use last successful password to reconnect, instead of ''
5234 g_Game_StartClient(NetClientIP, NetClientPort, '');
5235 end
5236 else if (cmd = 'addbot') or
5237 (cmd = 'bot_add') then
5238 begin
5239 if Length(P) > 1 then
5240 g_Bot_Add(TEAM_NONE, StrToIntDef(P[1], 2))
5241 else
5242 g_Bot_Add(TEAM_NONE, 2);
5243 end
5244 else if cmd = 'bot_addlist' then
5245 begin
5246 if Length(P) > 1 then
5247 if Length(P) = 2 then
5248 g_Bot_AddList(TEAM_NONE, P[1], StrToIntDef(P[1], -1))
5249 else
5250 g_Bot_AddList(IfThen(P[2] = 'red', TEAM_RED, TEAM_BLUE), P[1], StrToIntDef(P[1], -1));
5251 end
5252 else if cmd = 'bot_removeall' then
5253 g_Bot_RemoveAll()
5254 else if cmd = 'chat' then
5255 begin
5256 if g_Game_IsNet then
5257 begin
5258 if Length(P) > 1 then
5259 begin
5260 for a := 1 to High(P) do
5261 chstr := chstr + P[a] + ' ';
5263 if Length(chstr) > 200 then SetLength(chstr, 200);
5265 if Length(chstr) < 1 then
5266 begin
5267 g_Console_Add('chat <text>');
5268 Exit;
5269 end;
5271 chstr := b_Text_Format(chstr);
5272 if g_Game_IsClient then
5273 MC_SEND_Chat(chstr, NET_CHAT_PLAYER)
5274 else
5275 MH_SEND_Chat(gPlayer1Settings.Name + ': ' + chstr, NET_CHAT_PLAYER);
5276 end
5277 else
5278 g_Console_Add('chat <text>');
5279 end else
5280 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
5281 end
5282 else if cmd = 'teamchat' then
5283 begin
5284 if g_Game_IsNet and (gGameSettings.GameMode in [GM_TDM, GM_CTF]) then
5285 begin
5286 if Length(P) > 1 then
5287 begin
5288 for a := 1 to High(P) do
5289 chstr := chstr + P[a] + ' ';
5291 if Length(chstr) > 200 then SetLength(chstr, 200);
5293 if Length(chstr) < 1 then
5294 begin
5295 g_Console_Add('teamchat <text>');
5296 Exit;
5297 end;
5299 chstr := b_Text_Format(chstr);
5300 if g_Game_IsClient then
5301 MC_SEND_Chat(chstr, NET_CHAT_TEAM)
5302 else
5303 MH_SEND_Chat(gPlayer1Settings.Name + ': ' + chstr, NET_CHAT_TEAM,
5304 gPlayer1Settings.Team);
5305 end
5306 else
5307 g_Console_Add('teamchat <text>');
5308 end else
5309 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
5310 end
5311 else if cmd = 'game' then
5312 begin
5313 if gGameSettings.GameType <> GT_NONE then
5314 begin
5315 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
5316 Exit;
5317 end;
5318 if Length(P) = 1 then
5319 begin
5320 g_Console_Add(cmd + ' <WAD> [MAP] [# players]');
5321 Exit;
5322 end;
5323 // Èãðà åù¸ íå çàïóùåíà, ñíà÷àëà íàì íàäî çàãðóçèòü êàêîé-òî WAD
5324 P[1] := addWadExtension(P[1]);
5325 if FileExists(MapsDir + P[1]) then
5326 begin
5327 // Åñëè êàðòà íå óêàçàíà, áåð¸ì ïåðâóþ êàðòó â ôàéëå
5328 if Length(P) < 3 then
5329 begin
5330 SetLength(P, 3);
5331 P[2] := g_Game_GetFirstMap(MapsDir + P[1]);
5332 end;
5334 s := P[1] + ':\' + UpperCase(P[2]);
5336 if g_Map_Exist(MapsDir + s) then
5337 begin
5338 // Çàïóñêàåì ñâîþ èãðó
5339 g_Game_Free();
5340 with gGameSettings do
5341 begin
5342 GameMode := g_Game_TextToMode(gcGameMode);
5343 if gSwitchGameMode <> GM_NONE then
5344 GameMode := gSwitchGameMode;
5345 if GameMode = GM_NONE then GameMode := GM_DM;
5346 if GameMode = GM_SINGLE then GameMode := GM_COOP;
5347 b := 1;
5348 if Length(P) >= 4 then
5349 b := StrToIntDef(P[3], 1);
5350 g_Game_StartCustom(s, GameMode, TimeLimit,
5351 GoalLimit, MaxLives, Options, b);
5352 end;
5353 end
5354 else
5355 if P[2] = '' then
5356 g_Console_Add(Format(_lc[I_MSG_NO_MAPS], [P[1]]))
5357 else
5358 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [UpperCase(P[2])]));
5359 end else
5360 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]));
5361 end
5362 else if cmd = 'host' then
5363 begin
5364 if gGameSettings.GameType <> GT_NONE then
5365 begin
5366 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
5367 Exit;
5368 end;
5369 if Length(P) < 4 then
5370 begin
5371 g_Console_Add(cmd + ' <listen IP> <port> <WAD> [MAP] [# players]');
5372 Exit;
5373 end;
5374 if not StrToIp(P[1], listen) then
5375 Exit;
5376 prt := StrToIntDef(P[2], 25666);
5378 P[3] := addWadExtension(P[3]);
5379 if FileExists(MapsDir + P[3]) then
5380 begin
5381 // Åñëè êàðòà íå óêàçàíà, áåð¸ì ïåðâóþ êàðòó â ôàéëå
5382 if Length(P) < 5 then
5383 begin
5384 SetLength(P, 5);
5385 P[4] := g_Game_GetFirstMap(MapsDir + P[1]);
5386 end;
5388 s := P[3] + ':\' + UpperCase(P[4]);
5390 if g_Map_Exist(MapsDir + s) then
5391 begin
5392 // Çàïóñêàåì ñâîþ èãðó
5393 g_Game_Free();
5394 with gGameSettings do
5395 begin
5396 GameMode := g_Game_TextToMode(gcGameMode);
5397 if gSwitchGameMode <> GM_NONE then
5398 GameMode := gSwitchGameMode;
5399 if GameMode = GM_NONE then GameMode := GM_DM;
5400 if GameMode = GM_SINGLE then GameMode := GM_COOP;
5401 b := 0;
5402 if Length(P) >= 6 then
5403 b := StrToIntDef(P[5], 0);
5404 g_Game_StartServer(s, GameMode, TimeLimit,
5405 GoalLimit, MaxLives, Options, b, listen, prt);
5406 end;
5407 end
5408 else
5409 if P[4] = '' then
5410 g_Console_Add(Format(_lc[I_MSG_NO_MAPS], [P[3]]))
5411 else
5412 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [UpperCase(P[4])]));
5413 end else
5414 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[3]]));
5415 end
5416 else if cmd = 'map' then
5417 begin
5418 if Length(P) = 1 then
5419 begin
5420 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
5421 begin
5422 g_Console_Add(cmd + ' <MAP>');
5423 g_Console_Add(cmd + ' <WAD> [MAP]');
5424 end else
5425 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
5426 end else
5427 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
5428 begin
5429 // Èä¸ò ñâîÿ èãðà èëè ñåðâåð
5430 if Length(P) < 3 then
5431 begin
5432 // Ïåðâûé ïàðàìåòð - ëèáî êàðòà, ëèáî èìÿ WAD ôàéëà
5433 s := UpperCase(P[1]);
5434 if g_Map_Exist(MapsDir + gGameSettings.WAD + ':\' + s) then
5435 begin // Êàðòà íàøëàñü
5436 gExitByTrigger := False;
5437 if gGameOn then
5438 begin // Èä¸ò èãðà - çàâåðøàåì óðîâåíü
5439 gNextMap := s;
5440 gExit := EXIT_ENDLEVELCUSTOM;
5441 end
5442 else // Èíòåðìèññèÿ - ñðàçó çàãðóæàåì êàðòó
5443 g_Game_ChangeMap(s);
5444 end else
5445 begin
5446 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [s]));
5447 // Òàêîé êàðòû íåò, èùåì WAD ôàéë
5448 P[1] := addWadExtension(P[1]);
5449 if FileExists(MapsDir + P[1]) then
5450 begin
5451 // Ïàðàìåòðà êàðòû íåò, ïîýòîìó ñòàâèì ïåðâóþ èç ôàéëà
5452 SetLength(P, 3);
5453 P[2] := g_Game_GetFirstMap(MapsDir + P[1]);
5455 s := P[1] + ':\' + P[2];
5457 if g_Map_Exist(MapsDir + s) then
5458 begin
5459 gExitByTrigger := False;
5460 if gGameOn then
5461 begin // Èä¸ò èãðà - çàâåðøàåì óðîâåíü
5462 gNextMap := s;
5463 gExit := EXIT_ENDLEVELCUSTOM;
5464 end
5465 else // Èíòåðìèññèÿ - ñðàçó çàãðóæàåì êàðòó
5466 g_Game_ChangeMap(s);
5467 end else
5468 if P[2] = '' then
5469 g_Console_Add(Format(_lc[I_MSG_NO_MAPS], [P[1]]))
5470 else
5471 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [P[2]]));
5472 end else
5473 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]));
5474 end;
5475 end else
5476 begin
5477 // Óêàçàíî äâà ïàðàìåòðà, çíà÷èò ïåðâûé - WAD ôàéë, à âòîðîé - êàðòà
5478 P[1] := addWadExtension(P[1]);
5479 if FileExists(MapsDir + P[1]) then
5480 begin
5481 // Íàøëè WAD ôàéë
5482 P[2] := UpperCase(P[2]);
5483 s := P[1] + ':\' + P[2];
5485 if g_Map_Exist(MapsDir + s) then
5486 begin // Íàøëè êàðòó
5487 gExitByTrigger := False;
5488 if gGameOn then
5489 begin // Èä¸ò èãðà - çàâåðøàåì óðîâåíü
5490 gNextMap := s;
5491 gExit := EXIT_ENDLEVELCUSTOM;
5492 end
5493 else // Èíòåðìèññèÿ - ñðàçó çàãðóæàåì êàðòó
5494 g_Game_ChangeMap(s);
5495 end else
5496 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [P[2]]));
5497 end else
5498 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]));
5499 end;
5500 end else
5501 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
5502 end
5503 else if cmd = 'nextmap' then
5504 begin
5505 if not(gGameOn or (gState = STATE_INTERCUSTOM)) then
5506 g_Console_Add(_lc[I_MSG_NOT_GAME])
5507 else begin
5508 nm := True;
5509 if Length(P) = 1 then
5510 begin
5511 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
5512 begin
5513 g_Console_Add(cmd + ' <MAP>');
5514 g_Console_Add(cmd + ' <WAD> [MAP]');
5515 end else begin
5516 nm := False;
5517 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
5518 end;
5519 end else
5520 begin
5521 nm := False;
5522 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
5523 begin
5524 if Length(P) < 3 then
5525 begin
5526 // Ïåðâûé ïàðàìåòð - ëèáî êàðòà, ëèáî èìÿ WAD ôàéëà
5527 s := UpperCase(P[1]);
5528 if g_Map_Exist(MapsDir + gGameSettings.WAD + ':\' + s) then
5529 begin // Êàðòà íàøëàñü
5530 gExitByTrigger := False;
5531 gNextMap := s;
5532 nm := True;
5533 end else
5534 begin
5535 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [s]));
5536 // Òàêîé êàðòû íåò, èùåì WAD ôàéë
5537 P[1] := addWadExtension(P[1]);
5538 if FileExists(MapsDir + P[1]) then
5539 begin
5540 // Ïàðàìåòðà êàðòû íåò, ïîýòîìó ñòàâèì ïåðâóþ èç ôàéëà
5541 SetLength(P, 3);
5542 P[2] := g_Game_GetFirstMap(MapsDir + P[1]);
5544 s := P[1] + ':\' + P[2];
5546 if g_Map_Exist(MapsDir + s) then
5547 begin // Óñòàíàâëèâàåì êàðòó
5548 gExitByTrigger := False;
5549 gNextMap := s;
5550 nm := True;
5551 end else
5552 if P[2] = '' then
5553 g_Console_Add(Format(_lc[I_MSG_NO_MAPS], [P[1]]))
5554 else
5555 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [P[2]]));
5556 end else
5557 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]));
5558 end;
5559 end else
5560 begin
5561 // Óêàçàíî äâà ïàðàìåòðà, çíà÷èò ïåðâûé - WAD ôàéë, à âòîðîé - êàðòà
5562 P[1] := addWadExtension(P[1]);
5563 if FileExists(MapsDir + P[1]) then
5564 begin
5565 // Íàøëè WAD ôàéë
5566 P[2] := UpperCase(P[2]);
5567 s := P[1] + ':\' + P[2];
5569 if g_Map_Exist(MapsDir + s) then
5570 begin // Íàøëè êàðòó
5571 gExitByTrigger := False;
5572 gNextMap := s;
5573 nm := True;
5574 end else
5575 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [P[2]]));
5576 end else
5577 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]));
5578 end;
5579 end else
5580 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
5581 end;
5582 if nm then
5583 if gNextMap = '' then
5584 g_Console_Add(_lc[I_MSG_NEXTMAP_UNSET])
5585 else
5586 g_Console_Add(Format(_lc[I_MSG_NEXTMAP_SET], [gNextMap]));
5587 end;
5588 end
5589 else if (cmd = 'endmap') or (cmd = 'goodbye') then
5590 begin
5591 if not gGameOn then
5592 g_Console_Add(_lc[I_MSG_NOT_GAME])
5593 else
5594 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
5595 begin
5596 gExitByTrigger := False;
5597 // Ñëåäóþùàÿ êàðòà íå çàäàíà, ïðîáóåì íàéòè òðèããåð Âûõîä
5598 if (gNextMap = '') and (gTriggers <> nil) then
5599 for a := 0 to High(gTriggers) do
5600 if gTriggers[a].TriggerType = TRIGGER_EXIT then
5601 begin
5602 gExitByTrigger := True;
5603 gNextMap := gTriggers[a].Data.MapName;
5604 Break;
5605 end;
5606 // Èùåì ñëåäóþùóþ êàðòó â WAD ôàéëå
5607 if gNextMap = '' then
5608 gNextMap := g_Game_GetNextMap();
5609 // Ïðîâåðÿåì, íå çàäàí ëè WAD ôàéë ðåñóðñíîé ñòðîêîé
5610 if Pos(':\', gNextMap) = 0 then
5611 s := gGameSettings.WAD + ':\' + gNextMap
5612 else
5613 s := gNextMap;
5614 // Åñëè êàðòà íàéäåíà, âûõîäèì ñ óðîâíÿ
5615 if g_Map_Exist(MapsDir + s) then
5616 gExit := EXIT_ENDLEVELCUSTOM
5617 else
5618 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [gNextMap]));
5619 end else
5620 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
5621 end
5622 else if (cmd = 'event') then
5623 begin
5624 if (Length(P) <= 1) then
5625 begin
5626 for a := 0 to High(gEvents) do
5627 if gEvents[a].Command = '' then
5628 g_Console_Add(gEvents[a].Name + ' <none>')
5629 else
5630 g_Console_Add(gEvents[a].Name + ' "' + gEvents[a].Command + '"');
5631 Exit;
5632 end;
5633 if (Length(P) = 2) then
5634 begin
5635 for a := 0 to High(gEvents) do
5636 if gEvents[a].Name = P[1] then
5637 if gEvents[a].Command = '' then
5638 g_Console_Add(gEvents[a].Name + ' <none>')
5639 else
5640 g_Console_Add(gEvents[a].Name + ' "' + gEvents[a].Command + '"');
5641 Exit;
5642 end;
5643 for a := 0 to High(gEvents) do
5644 if gEvents[a].Name = P[1] then
5645 begin
5646 gEvents[a].Command := '';
5647 for b := 2 to High(P) do
5648 if Pos(' ', P[b]) = 0 then
5649 gEvents[a].Command := gEvents[a].Command + ' ' + P[b]
5650 else
5651 gEvents[a].Command := gEvents[a].Command + ' "' + P[b] + '"';
5652 gEvents[a].Command := Trim(gEvents[a].Command);
5653 Exit;
5654 end;
5655 end
5656 // Êîìàíäû Ñâîåé èãðû:
5657 else if gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT] then
5658 begin
5659 if cmd = 'bot_addred' then
5660 begin
5661 if Length(P) > 1 then
5662 g_Bot_Add(TEAM_RED, StrToIntDef(P[1], 2))
5663 else
5664 g_Bot_Add(TEAM_RED, 2);
5665 end
5666 else if cmd = 'bot_addblue' then
5667 begin
5668 if Length(P) > 1 then
5669 g_Bot_Add(TEAM_BLUE, StrToIntDef(P[1], 2))
5670 else
5671 g_Bot_Add(TEAM_BLUE, 2);
5672 end
5673 else if cmd = 'suicide' then
5674 begin
5675 if gGameOn then
5676 begin
5677 if g_Game_IsClient then
5678 MC_SEND_CheatRequest(NET_CHEAT_SUICIDE)
5679 else
5680 begin
5681 if gPlayer1 <> nil then
5682 gPlayer1.Damage(SUICIDE_DAMAGE, gPlayer1.UID, 0, 0, HIT_SELF);
5683 if gPlayer2 <> nil then
5684 gPlayer2.Damage(SUICIDE_DAMAGE, gPlayer2.UID, 0, 0, HIT_SELF);
5685 end;
5686 end;
5687 end
5688 else if cmd = 'spectate' then
5689 begin
5690 if not gGameOn then
5691 Exit;
5692 g_Game_Spectate();
5693 end
5694 else if cmd = 'say' then
5695 begin
5696 if g_Game_IsServer and g_Game_IsNet then
5697 begin
5698 if Length(P) > 1 then
5699 begin
5700 chstr := '';
5701 for a := 1 to High(P) do
5702 chstr := chstr + P[a] + ' ';
5704 if Length(chstr) > 200 then SetLength(chstr, 200);
5706 if Length(chstr) < 1 then
5707 begin
5708 g_Console_Add('say <text>');
5709 Exit;
5710 end;
5712 chstr := b_Text_Format(chstr);
5713 MH_SEND_Chat(chstr, NET_CHAT_PLAYER);
5714 end
5715 else g_Console_Add('say <text>');
5716 end else
5717 g_Console_Add(_lc[I_MSG_SERVERONLY]);
5718 end
5719 else if cmd = 'tell' then
5720 begin
5721 if g_Game_IsServer and g_Game_IsNet then
5722 begin
5723 if (Length(P) > 2) and (P[1] <> '') then
5724 begin
5725 chstr := '';
5726 for a := 2 to High(P) do
5727 chstr := chstr + P[a] + ' ';
5729 if Length(chstr) > 200 then SetLength(chstr, 200);
5731 if Length(chstr) < 1 then
5732 begin
5733 g_Console_Add('tell <playername> <text>');
5734 Exit;
5735 end;
5737 pl := g_Net_Client_ByName(P[1]);
5738 if pl <> nil then
5739 MH_SEND_Chat(b_Text_Format(chstr), NET_CHAT_PLAYER, pl^.ID)
5740 else
5741 g_Console_Add(Format(_lc[I_NET_ERR_NAME404], [P[1]]));
5742 end
5743 else g_Console_Add('tell <playername> <text>');
5744 end else
5745 g_Console_Add(_lc[I_MSG_SERVERONLY]);
5746 end
5747 else if (cmd = 'overtime') and not g_Game_IsClient then
5748 begin
5749 if (Length(P) = 1) or (StrToIntDef(P[1], -1) <= 0) then
5750 Exit;
5751 // Äîïîëíèòåëüíîå âðåìÿ:
5752 gGameSettings.TimeLimit := (gTime - gGameStartTime) div 1000 + Word(StrToIntDef(P[1], 0));
5754 g_Console_Add(Format(_lc[I_MSG_TIME_LIMIT],
5755 [gGameSettings.TimeLimit div 3600,
5756 (gGameSettings.TimeLimit div 60) mod 60,
5757 gGameSettings.TimeLimit mod 60]));
5758 if g_Game_IsNet then MH_SEND_GameSettings;
5759 end
5760 else if (cmd = 'rcon_password') and g_Game_IsClient then
5761 begin
5762 if (Length(P) <= 1) then
5763 g_Console_Add('rcon_password <password>')
5764 else
5765 MC_SEND_RCONPassword(P[1]);
5766 end
5767 else if cmd = 'rcon' then
5768 begin
5769 if g_Game_IsClient then
5770 begin
5771 if Length(P) > 1 then
5772 begin
5773 chstr := '';
5774 for a := 1 to High(P) do
5775 chstr := chstr + P[a] + ' ';
5777 if Length(chstr) > 200 then SetLength(chstr, 200);
5779 if Length(chstr) < 1 then
5780 begin
5781 g_Console_Add('rcon <command>');
5782 Exit;
5783 end;
5785 MC_SEND_RCONCommand(chstr);
5786 end
5787 else g_Console_Add('rcon <command>');
5788 end;
5789 end
5790 else if cmd = 'ready' then
5791 begin
5792 if g_Game_IsServer and (gLMSRespawn = LMS_RESPAWN_WARMUP) then
5793 gLMSRespawnTime := gTime + 100;
5794 end
5795 else if (cmd = 'callvote') and g_Game_IsNet then
5796 begin
5797 if Length(P) > 1 then
5798 begin
5799 chstr := '';
5800 for a := 1 to High(P) do begin
5801 if a > 1 then chstr := chstr + ' ';
5802 chstr := chstr + P[a];
5803 end;
5805 if Length(chstr) > 200 then SetLength(chstr, 200);
5807 if Length(chstr) < 1 then
5808 begin
5809 g_Console_Add('callvote <command>');
5810 Exit;
5811 end;
5813 if g_Game_IsClient then
5814 MC_SEND_Vote(True, chstr)
5815 else
5816 g_Game_StartVote(chstr, gPlayer1Settings.Name);
5817 g_Console_Process('vote', True);
5818 end
5819 else
5820 g_Console_Add('callvote <command>');
5821 end
5822 else if (cmd = 'vote') and g_Game_IsNet then
5823 begin
5824 if g_Game_IsClient then
5825 MC_SEND_Vote(False)
5826 else if gVoteInProgress then
5827 begin
5828 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
5829 a := Floor((NetClientCount+1)/2.0) + 1
5830 else
5831 a := Floor(NetClientCount/2.0) + 1;
5832 if gVoted then
5833 begin
5834 Dec(gVoteCount);
5835 gVoted := False;
5836 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_REVOKED], [gPlayer1Settings.Name, gVoteCount, a]), True);
5837 MH_SEND_VoteEvent(NET_VE_REVOKE, gPlayer1Settings.Name, 'a', gVoteCount, a);
5838 end
5839 else
5840 begin
5841 Inc(gVoteCount);
5842 gVoted := True;
5843 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_VOTE], [gPlayer1Settings.Name, gVoteCount, a]), True);
5844 MH_SEND_VoteEvent(NET_VE_VOTE, gPlayer1Settings.Name, 'a', gVoteCount, a);
5845 g_Game_CheckVote;
5846 end;
5847 end;
5848 end
5849 end;
5850 end;
5852 procedure g_TakeScreenShot();
5853 var
5854 a: Word;
5855 FileName: string;
5856 ssdir, t: string;
5857 begin
5858 ssdir := GameDir+'/screenshots';
5859 if not findFileCI(ssdir, true) then
5860 begin
5861 // try to create dir
5862 try
5863 CreateDir(ssdir);
5864 except
5865 end;
5866 if not findFileCI(ssdir, true) then exit; // alas
5867 end;
5868 try
5869 for a := 1 to High(Word) do
5870 begin
5871 FileName := Format(ssdir+'screenshot%.3d.bmp', [a]);
5872 t := FileName;
5873 if findFileCI(t, true) then continue;
5874 if not findFileCI(FileName) then
5875 begin
5876 e_MakeScreenshot(FileName, gScreenWidth, gScreenHeight);
5877 g_Console_Add(Format(_lc[I_CONSOLE_SCREENSHOT], [ExtractFileName(FileName)]));
5878 Break;
5879 end;
5880 end;
5881 except
5882 end;
5883 end;
5885 procedure g_Game_InGameMenu(Show: Boolean);
5886 begin
5887 if (g_ActiveWindow = nil) and Show then
5888 begin
5889 if gGameSettings.GameType = GT_SINGLE then
5890 g_GUI_ShowWindow('GameSingleMenu')
5891 else
5892 begin
5893 if g_Game_IsClient then
5894 g_GUI_ShowWindow('GameClientMenu')
5895 else
5896 if g_Game_IsNet then
5897 g_GUI_ShowWindow('GameServerMenu')
5898 else
5899 g_GUI_ShowWindow('GameCustomMenu');
5900 end;
5901 g_Sound_PlayEx('MENU_OPEN');
5903 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
5904 if (not g_Game_IsNet) then
5905 g_Game_Pause(True);
5906 end
5907 else
5908 if (g_ActiveWindow <> nil) and (not Show) then
5909 begin
5910 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
5911 if (not g_Game_IsNet) then
5912 g_Game_Pause(False);
5913 end;
5914 end;
5916 procedure g_Game_Pause(Enable: Boolean);
5917 begin
5918 if not gGameOn then
5919 Exit;
5921 if gPause = Enable then
5922 Exit;
5924 if not (gGameSettings.GameType in [GT_SINGLE, GT_CUSTOM]) then
5925 Exit;
5927 gPause := Enable;
5928 g_Game_PauseAllSounds(Enable);
5929 end;
5931 procedure g_Game_PauseAllSounds(Enable: Boolean);
5932 var
5933 i: Integer;
5934 begin
5935 // Òðèããåðû:
5936 if gTriggers <> nil then
5937 for i := 0 to High(gTriggers) do
5938 with gTriggers[i] do
5939 if (TriggerType = TRIGGER_SOUND) and
5940 (Sound <> nil) and
5941 Sound.IsPlaying() then
5942 begin
5943 Sound.Pause(Enable);
5944 end;
5946 // Çâóêè èãðîêîâ:
5947 if gPlayers <> nil then
5948 for i := 0 to High(gPlayers) do
5949 if gPlayers[i] <> nil then
5950 gPlayers[i].PauseSounds(Enable);
5952 // Ìóçûêà:
5953 if gMusic <> nil then
5954 gMusic.Pause(Enable);
5955 end;
5957 procedure g_Game_StopAllSounds(all: Boolean);
5958 var
5959 i: Integer;
5960 begin
5961 if gTriggers <> nil then
5962 for i := 0 to High(gTriggers) do
5963 with gTriggers[i] do
5964 if (TriggerType = TRIGGER_SOUND) and
5965 (Sound <> nil) then
5966 Sound.Stop();
5968 if gMusic <> nil then
5969 gMusic.Stop();
5971 if all then
5972 e_StopChannels();
5973 end;
5975 procedure g_Game_UpdateTriggerSounds();
5976 var
5977 i: Integer;
5978 begin
5979 if gTriggers <> nil then
5980 for i := 0 to High(gTriggers) do
5981 with gTriggers[i] do
5982 if (TriggerType = TRIGGER_SOUND) and
5983 (Sound <> nil) and
5984 (Data.Local) and
5985 Sound.IsPlaying() then
5986 begin
5987 if ((gPlayer1 <> nil) and g_CollidePoint(gPlayer1.GameX, gPlayer1.GameY, X, Y, Width, Height)) or
5988 ((gPlayer2 <> nil) and g_CollidePoint(gPlayer2.GameX, gPlayer2.GameY, X, Y, Width, Height)) then
5989 begin
5990 Sound.SetPan(0.5 - Data.Pan/255.0);
5991 Sound.SetVolume(Data.Volume/255.0);
5992 end
5993 else
5994 Sound.SetCoords(X+(Width div 2), Y+(Height div 2), Data.Volume/255.0);
5995 end;
5996 end;
5998 function g_Game_IsWatchedPlayer(UID: Word): Boolean;
5999 begin
6000 Result := False;
6001 if (gPlayer1 <> nil) and (gPlayer1.UID = UID) then
6002 begin
6003 Result := True;
6004 Exit;
6005 end;
6006 if (gPlayer2 <> nil) and (gPlayer2.UID = UID) then
6007 begin
6008 Result := True;
6009 Exit;
6010 end;
6011 if gSpectMode <> SPECT_PLAYERS then
6012 Exit;
6013 if gSpectPID1 = UID then
6014 begin
6015 Result := True;
6016 Exit;
6017 end;
6018 if gSpectViewTwo and (gSpectPID2 = UID) then
6019 begin
6020 Result := True;
6021 Exit;
6022 end;
6023 end;
6025 function g_Game_IsWatchedTeam(Team: Byte): Boolean;
6026 var
6027 Pl: TPlayer;
6028 begin
6029 Result := False;
6030 if (gPlayer1 <> nil) and (gPlayer1.Team = Team) then
6031 begin
6032 Result := True;
6033 Exit;
6034 end;
6035 if (gPlayer2 <> nil) and (gPlayer2.Team = Team) then
6036 begin
6037 Result := True;
6038 Exit;
6039 end;
6040 if gSpectMode <> SPECT_PLAYERS then
6041 Exit;
6042 Pl := g_Player_Get(gSpectPID1);
6043 if (Pl <> nil) and (Pl.Team = Team) then
6044 begin
6045 Result := True;
6046 Exit;
6047 end;
6048 if gSpectViewTwo then
6049 begin
6050 Pl := g_Player_Get(gSpectPID2);
6051 if (Pl <> nil) and (Pl.Team = Team) then
6052 begin
6053 Result := True;
6054 Exit;
6055 end;
6056 end;
6057 end;
6059 procedure g_Game_Message(Msg: string; Time: Word);
6060 begin
6061 MessageText := b_Text_Format(Msg);
6062 MessageTime := Time;
6063 end;
6065 procedure g_Game_Announce_GoodShot(SpawnerUID: Word);
6066 var
6067 a: Integer;
6068 begin
6069 case gAnnouncer of
6070 ANNOUNCE_NONE:
6071 Exit;
6072 ANNOUNCE_ME,
6073 ANNOUNCE_MEPLUS:
6074 if not g_Game_IsWatchedPlayer(SpawnerUID) then
6075 Exit;
6076 end;
6077 for a := 0 to 3 do
6078 if goodsnd[a].IsPlaying() then
6079 Exit;
6081 goodsnd[Random(4)].Play();
6082 end;
6084 procedure g_Game_Announce_KillCombo(Param: Integer);
6085 var
6086 UID: Word;
6087 c, n: Byte;
6088 Pl: TPlayer;
6089 Name: String;
6090 begin
6091 UID := Param and $FFFF;
6092 c := Param shr 16;
6093 if c < 2 then
6094 Exit;
6096 Pl := g_Player_Get(UID);
6097 if Pl = nil then
6098 Name := '?'
6099 else
6100 Name := Pl.Name;
6102 case c of
6103 2: begin
6104 n := 0;
6105 g_Console_Add(Format(_lc[I_PLAYER_KILL_2X], [Name]), True);
6106 end;
6107 3: begin
6108 n := 1;
6109 g_Console_Add(Format(_lc[I_PLAYER_KILL_3X], [Name]), True);
6110 end;
6111 4: begin
6112 n := 2;
6113 g_Console_Add(Format(_lc[I_PLAYER_KILL_4X], [Name]), True);
6114 end;
6115 else begin
6116 n := 3;
6117 g_Console_Add(Format(_lc[I_PLAYER_KILL_MX], [Name]), True);
6118 end;
6119 end;
6121 case gAnnouncer of
6122 ANNOUNCE_NONE:
6123 Exit;
6124 ANNOUNCE_ME:
6125 if not g_Game_IsWatchedPlayer(UID) then
6126 Exit;
6127 ANNOUNCE_MEPLUS:
6128 if (not g_Game_IsWatchedPlayer(UID)) and (c < 4) then
6129 Exit;
6130 end;
6132 if killsnd[n].IsPlaying() then
6133 killsnd[n].Stop();
6134 killsnd[n].Play();
6135 end;
6137 procedure g_Game_StartVote(Command, Initiator: string);
6138 var
6139 Need: Integer;
6140 begin
6141 if not gVotesEnabled then Exit;
6142 if gGameSettings.GameType <> GT_SERVER then Exit;
6143 if gVoteInProgress or gVotePassed then
6144 begin
6145 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_INPROGRESS], [gVoteCommand]), True);
6146 MH_SEND_VoteEvent(NET_VE_INPROGRESS, gVoteCommand);
6147 Exit;
6148 end;
6149 gVoteInProgress := True;
6150 gVotePassed := False;
6151 gVoteTimer := gTime + gVoteTimeout * 1000;
6152 gVoteCount := 0;
6153 gVoted := False;
6154 gVoteCommand := Command;
6156 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
6157 Need := Floor((NetClientCount+1)/2.0)+1
6158 else
6159 Need := Floor(NetClientCount/2.0)+1;
6160 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_STARTED], [Initiator, Command, Need]), True);
6161 MH_SEND_VoteEvent(NET_VE_STARTED, Initiator, Command, Need);
6162 end;
6164 procedure g_Game_CheckVote;
6165 var
6166 I, Need: Integer;
6167 begin
6168 if gGameSettings.GameType <> GT_SERVER then Exit;
6169 if not gVoteInProgress then Exit;
6171 if (gTime >= gVoteTimer) then
6172 begin
6173 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
6174 Need := Floor((NetClientCount+1)/2.0) + 1
6175 else
6176 Need := Floor(NetClientCount/2.0) + 1;
6177 if gVoteCount >= Need then
6178 begin
6179 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_PASSED], [gVoteCommand]), True);
6180 MH_SEND_VoteEvent(NET_VE_PASSED, gVoteCommand);
6181 gVotePassed := True;
6182 gVoteCmdTimer := gTime + 5000;
6183 end
6184 else
6185 begin
6186 g_Console_Add(_lc[I_MESSAGE_VOTE_FAILED], True);
6187 MH_SEND_VoteEvent(NET_VE_FAILED);
6188 end;
6189 if NetClients <> nil then
6190 for I := Low(NetClients) to High(NetClients) do
6191 if NetClients[i].Used then
6192 NetClients[i].Voted := False;
6193 gVoteInProgress := False;
6194 gVoted := False;
6195 gVoteCount := 0;
6196 end
6197 else
6198 begin
6199 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
6200 Need := Floor((NetClientCount+1)/2.0) + 1
6201 else
6202 Need := Floor(NetClientCount/2.0) + 1;
6203 if gVoteCount >= Need then
6204 begin
6205 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_PASSED], [gVoteCommand]), True);
6206 MH_SEND_VoteEvent(NET_VE_PASSED, gVoteCommand);
6207 gVoteInProgress := False;
6208 gVotePassed := True;
6209 gVoteCmdTimer := gTime + 5000;
6210 gVoted := False;
6211 gVoteCount := 0;
6212 if NetClients <> nil then
6213 for I := Low(NetClients) to High(NetClients) do
6214 if NetClients[i].Used then
6215 NetClients[i].Voted := False;
6216 end;
6217 end;
6218 end;
6220 procedure g_Game_LoadMapList(FileName: string);
6221 var
6222 ListFile: TextFile;
6223 s: string;
6224 begin
6225 MapList := nil;
6226 MapIndex := -1;
6228 if not FileExists(FileName) then Exit;
6230 AssignFile(ListFile, FileName);
6231 Reset(ListFile);
6232 while not EOF(ListFile) do
6233 begin
6234 ReadLn(ListFile, s);
6236 s := Trim(s);
6237 if s = '' then Continue;
6239 SetLength(MapList, Length(MapList)+1);
6240 MapList[High(MapList)] := s;
6241 end;
6242 CloseFile(ListFile);
6243 end;
6245 procedure g_Game_SetDebugMode();
6246 begin
6247 gDebugMode := True;
6248 // ×èòû (äàæå â ñâîåé èãðå):
6249 gCheats := True;
6250 end;
6252 procedure g_Game_SetLoadingText(Text: String; Max: Integer; reWrite: Boolean);
6253 var
6254 i: Word;
6255 begin
6256 if Length(LoadingStat.Msgs) = 0 then
6257 Exit;
6259 with LoadingStat do
6260 begin
6261 if not reWrite then
6262 begin // Ïåðåõîäèì íà ñëåäóþùóþ ñòðîêó èëè ñêðîëëèðóåì:
6263 if NextMsg = Length(Msgs) then
6264 begin // scroll
6265 for i := 0 to High(Msgs)-1 do
6266 Msgs[i] := Msgs[i+1];
6267 end
6268 else
6269 Inc(NextMsg);
6270 end else
6271 if NextMsg = 0 then
6272 Inc(NextMsg);
6274 Msgs[NextMsg-1] := Text;
6275 CurValue := 0;
6276 MaxValue := Max;
6277 ShowCount := 0;
6278 end;
6280 g_ActiveWindow := nil;
6282 ProcessLoading;
6283 end;
6285 procedure g_Game_StepLoading();
6286 begin
6287 with LoadingStat do
6288 begin
6289 Inc(CurValue);
6290 Inc(ShowCount);
6291 if (ShowCount > LOADING_SHOW_STEP) then
6292 begin
6293 ShowCount := 0;
6294 ProcessLoading;
6295 end;
6296 end;
6297 end;
6299 procedure g_Game_ClearLoading();
6300 var
6301 len: Word;
6302 begin
6303 with LoadingStat do
6304 begin
6305 CurValue := 0;
6306 MaxValue := 0;
6307 ShowCount := 0;
6308 len := ((gScreenHeight div 3)*2 - 50) div LOADING_INTERLINE;
6309 if len < 1 then len := 1;
6310 SetLength(Msgs, len);
6311 for len := Low(Msgs) to High(Msgs) do
6312 Msgs[len] := '';
6313 NextMsg := 0;
6314 end;
6315 end;
6317 procedure Parse_Params(var pars: TParamStrValues);
6318 var
6319 i: Integer;
6320 s: String;
6321 begin
6322 SetLength(pars, 0);
6323 i := 1;
6324 while i <= ParamCount do
6325 begin
6326 s := ParamStr(i);
6327 if (s[1] = '-') and (Length(s) > 1) then
6328 begin
6329 if (s[2] = '-') and (Length(s) > 2) then
6330 begin // Îäèíî÷íûé ïàðàìåòð
6331 SetLength(pars, Length(pars) + 1);
6332 with pars[High(pars)] do
6333 begin
6334 Name := LowerCase(s);
6335 Value := '+';
6336 end;
6337 end
6338 else
6339 if (i < ParamCount) then
6340 begin // Ïàðàìåòð ñî çíà÷åíèåì
6341 Inc(i);
6342 SetLength(pars, Length(pars) + 1);
6343 with pars[High(pars)] do
6344 begin
6345 Name := LowerCase(s);
6346 Value := LowerCase(ParamStr(i));
6347 end;
6348 end;
6349 end;
6351 Inc(i);
6352 end;
6353 end;
6355 function Find_Param_Value(var pars: TParamStrValues; aName: String): String;
6356 var
6357 i: Integer;
6358 begin
6359 Result := '';
6360 for i := 0 to High(pars) do
6361 if pars[i].Name = aName then
6362 begin
6363 Result := pars[i].Value;
6364 Break;
6365 end;
6366 end;
6368 procedure g_Game_Process_Params();
6369 var
6370 pars: TParamStrValues;
6371 map: String;
6372 GMode, n: Byte;
6373 LimT, LimS: Integer;
6374 Opt: LongWord;
6375 Lives: Integer;
6376 s: String;
6377 Port: Integer;
6378 ip: String;
6379 F: TextFile;
6380 begin
6381 Parse_Params(pars);
6383 // Debug mode:
6384 s := Find_Param_Value(pars, '--debug');
6385 if (s <> '') then
6386 g_Game_SetDebugMode();
6388 // Connect when game loads
6389 ip := Find_Param_Value(pars, '-connect');
6391 if ip <> '' then
6392 begin
6393 s := Find_Param_Value(pars, '-port');
6394 if (s = '') or not TryStrToInt(s, Port) then
6395 Port := 25666;
6397 s := Find_Param_Value(pars, '-pw');
6399 g_Game_StartClient(ip, Port, s);
6400 Exit;
6401 end;
6403 // Start map when game loads:
6404 map := LowerCase(Find_Param_Value(pars, '-map'));
6405 if isWadPath(map) then
6406 begin
6407 // Game mode:
6408 s := Find_Param_Value(pars, '-gm');
6409 GMode := g_Game_TextToMode(s);
6410 if GMode = GM_NONE then GMode := GM_DM;
6411 if GMode = GM_SINGLE then GMode := GM_COOP;
6413 // Time limit:
6414 s := Find_Param_Value(pars, '-limt');
6415 if (s = '') or (not TryStrToInt(s, LimT)) then
6416 LimT := 0;
6417 if LimT < 0 then
6418 LimT := 0;
6420 // Goal limit:
6421 s := Find_Param_Value(pars, '-lims');
6422 if (s = '') or (not TryStrToInt(s, LimS)) then
6423 LimS := 0;
6424 if LimS < 0 then
6425 LimS := 0;
6427 // Lives limit:
6428 s := Find_Param_Value(pars, '-lives');
6429 if (s = '') or (not TryStrToInt(s, Lives)) then
6430 Lives := 0;
6431 if Lives < 0 then
6432 Lives := 0;
6434 // Options:
6435 s := Find_Param_Value(pars, '-opt');
6436 if (s = '') then
6437 Opt := GAME_OPTION_ALLOWEXIT or GAME_OPTION_BOTVSPLAYER or GAME_OPTION_BOTVSMONSTER
6438 else
6439 Opt := StrToIntDef(s, 0);
6440 if Opt = 0 then
6441 Opt := GAME_OPTION_ALLOWEXIT or GAME_OPTION_BOTVSPLAYER or GAME_OPTION_BOTVSMONSTER;
6443 // Close after map:
6444 s := Find_Param_Value(pars, '--close');
6445 if (s <> '') then
6446 gMapOnce := True;
6448 // Delete test map after play:
6449 s := Find_Param_Value(pars, '--testdelete');
6450 if (s <> '') then
6451 begin
6452 gMapToDelete := MapsDir + map;
6453 e_WriteLog('"--testdelete" is deprecated, use --tempdelete.', MSG_FATALERROR);
6454 Halt(1);
6455 end;
6457 // Delete temporary WAD after play:
6458 s := Find_Param_Value(pars, '--tempdelete');
6459 if (s <> '') then
6460 begin
6461 gMapToDelete := MapsDir + map;
6462 gTempDelete := True;
6463 end;
6465 // Number of players:
6466 s := Find_Param_Value(pars, '-pl');
6467 if (s = '') then
6468 n := 1
6469 else
6470 n := StrToIntDef(s, 1);
6472 // Start:
6473 s := Find_Param_Value(pars, '-port');
6474 if (s = '') or not TryStrToInt(s, Port) then
6475 g_Game_StartCustom(map, GMode, LimT, LimS, Lives, Opt, n)
6476 else
6477 g_Game_StartServer(map, GMode, LimT, LimS, Lives, Opt, n, 0, Port);
6478 end;
6480 // Execute script when game loads:
6481 s := Find_Param_Value(pars, '-exec');
6482 if s <> '' then
6483 begin
6484 if Pos(':\', s) = 0 then
6485 s := GameDir + '/' + s;
6487 {$I-}
6488 AssignFile(F, s);
6489 Reset(F);
6490 if IOResult <> 0 then
6491 begin
6492 e_WriteLog(Format(_lc[I_SIMPLE_ERROR], ['Failed to read file: ' + s]), MSG_WARNING);
6493 g_Console_Add(Format(_lc[I_CONSOLE_ERROR_READ], [s]));
6494 CloseFile(F);
6495 Exit;
6496 end;
6497 e_WriteLog('Executing script: ' + s, MSG_NOTIFY);
6498 g_Console_Add(Format(_lc[I_CONSOLE_EXEC], [s]));
6500 while not EOF(F) do
6501 begin
6502 ReadLn(F, s);
6503 if IOResult <> 0 then
6504 begin
6505 e_WriteLog(Format(_lc[I_SIMPLE_ERROR], ['Failed to read file: ' + s]), MSG_WARNING);
6506 g_Console_Add(Format(_lc[I_CONSOLE_ERROR_READ], [s]));
6507 CloseFile(F);
6508 Exit;
6509 end;
6510 if Pos('#', s) <> 1 then // script comment
6511 g_Console_Process(s, True);
6512 end;
6514 CloseFile(F);
6515 {$I+}
6516 end;
6518 SetLength(pars, 0);
6519 end;
6521 end.