DEADSOFTWARE

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