DEADSOFTWARE

c5e144c7c0dfaad252644494be24bf65de0e092e
[d2df-sdl.git] / src / game / g_game.pas
1 unit g_game;
3 interface
5 uses
6 g_basic, g_player, e_graphics, Classes, g_res_downloader,
7 SysUtils, g_sound, g_gui, MAPSTRUCT, WADEDITOR, md5;
9 type
10 TGameSettings = record
11 GameType: Byte;
12 GameMode: Byte;
13 TimeLimit: Word;
14 GoalLimit: Word;
15 WarmupTime: Word;
16 MaxLives: Byte;
17 Options: LongWord;
18 WAD: String;
19 end;
21 TGameEvent = record
22 Name: String;
23 Command: String;
24 end;
26 TDelayedEvent = record
27 Pending: Boolean;
28 Time: LongWord;
29 DEType: Byte;
30 DENum: Integer;
31 DEStr: String;
32 end;
34 TPlayerSettings = record
35 Name: String;
36 Model: String;
37 Color: TRGB;
38 Team: Byte;
39 end;
41 TMegaWADInfo = record
42 Name: String;
43 Description: String;
44 Author: String;
45 Pic: String;
46 end;
48 THearPoint = record
49 Active: Boolean;
50 Coords: TPoint;
51 end;
53 function g_Game_IsNet(): Boolean;
54 function g_Game_IsServer(): Boolean;
55 function g_Game_IsClient(): Boolean;
56 procedure g_Game_Init();
57 procedure g_Game_Free();
58 procedure g_Game_LoadData();
59 procedure g_Game_FreeData();
60 procedure g_Game_Update();
61 procedure g_Game_Draw();
62 procedure g_Game_Quit();
63 procedure g_Game_SetupScreenSize();
64 procedure g_Game_ChangeResolution(newWidth, newHeight: Word; nowFull, nowMax: Boolean);
65 function g_Game_ModeToText(Mode: Byte): string;
66 function g_Game_TextToMode(Mode: string): Byte;
67 procedure g_Game_ExecuteEvent(Name: String);
68 function g_Game_DelayEvent(DEType: Byte; Time: LongWord; Num: Integer = 0; Str: String = ''): Integer;
69 procedure g_Game_AddPlayer(Team: Byte = TEAM_NONE);
70 procedure g_Game_RemovePlayer();
71 procedure g_Game_Spectate();
72 procedure g_Game_SpectateCenterView();
73 procedure g_Game_StartSingle(Map: String; TwoPlayers: Boolean; nPlayers: Byte);
74 procedure g_Game_StartCustom(Map: String; GameMode: Byte; TimeLimit, GoalLimit: Word; MaxLives: Byte; Options: LongWord; nPlayers: Byte);
75 procedure g_Game_StartServer(Map: String; GameMode: Byte; TimeLimit, GoalLimit: Word; MaxLives: Byte; Options: LongWord; nPlayers: Byte; IPAddr: LongWord; Port: Word);
76 procedure g_Game_StartClient(Addr: String; Port: Word; PW: String);
77 procedure g_Game_Restart();
78 procedure g_Game_RestartLevel();
79 procedure g_Game_RestartRound(NoMapRestart: Boolean = False);
80 procedure g_Game_ClientWAD(NewWAD: String; WHash: TMD5Digest);
81 procedure g_Game_SaveOptions();
82 function g_Game_StartMap(Map: String; Force: Boolean = False): Boolean;
83 procedure g_Game_ChangeMap(MapPath: String);
84 procedure g_Game_ExitLevel(Map: Char16);
85 function g_Game_GetFirstMap(WAD: String): String;
86 function g_Game_GetNextMap(): String;
87 procedure g_Game_NextLevel();
88 procedure g_Game_Pause(Enable: Boolean);
89 procedure g_Game_InGameMenu(Show: Boolean);
90 function g_Game_IsWatchedPlayer(UID: Word): Boolean;
91 function g_Game_IsWatchedTeam(Team: Byte): Boolean;
92 procedure g_Game_Message(Msg: String; Time: Word);
93 procedure g_Game_LoadMapList(FileName: String);
94 procedure g_Game_PauseAllSounds(Enable: Boolean);
95 procedure g_Game_StopAllSounds(all: Boolean);
96 procedure g_Game_UpdateTriggerSounds();
97 function g_Game_GetMegaWADInfo(WAD: String): TMegaWADInfo;
98 procedure g_Game_Announce_GoodShot(SpawnerUID: Word);
99 procedure g_Game_Announce_KillCombo(Param: Integer);
100 procedure g_Game_StartVote(Command, Initiator: string);
101 procedure g_Game_CheckVote;
102 procedure g_TakeScreenShot();
103 procedure g_FatalError(Text: String);
104 procedure g_SimpleError(Text: String);
105 function g_Game_IsTestMap(): Boolean;
106 procedure g_Game_DeleteTestMap();
107 procedure GameCVars(P: SArray);
108 procedure GameCommands(P: SArray);
109 procedure DebugCommands(P: SArray);
110 procedure g_Game_Process_Params;
111 procedure g_Game_SetLoadingText(Text: String; Max: Integer; reWrite: Boolean);
112 procedure g_Game_StepLoading();
113 procedure g_Game_ClearLoading();
114 procedure g_Game_SetDebugMode();
115 procedure DrawLoadingStat();
117 { procedure SetWinPause(Enable: Boolean); }
119 const
120 GAME_TICK = 28;
122 LOADING_SHOW_STEP = 100;
123 LOADING_INTERLINE = 20;
125 GT_NONE = 0;
126 GT_SINGLE = 1;
127 GT_CUSTOM = 2;
128 GT_SERVER = 3;
129 GT_CLIENT = 4;
131 GM_NONE = 0;
132 GM_DM = 1;
133 GM_TDM = 2;
134 GM_CTF = 3;
135 GM_COOP = 4;
136 GM_SINGLE = 5;
138 MESSAGE_DIKEY = WM_USER + 1;
140 EXIT_QUIT = 1;
141 EXIT_SIMPLE = 2;
142 EXIT_RESTART = 3;
143 EXIT_ENDLEVELSINGLE = 4;
144 EXIT_ENDLEVELCUSTOM = 5;
146 GAME_OPTION_RESERVED = 1;
147 GAME_OPTION_TEAMDAMAGE = 2;
148 GAME_OPTION_ALLOWEXIT = 4;
149 GAME_OPTION_WEAPONSTAY = 8;
150 GAME_OPTION_MONSTERS = 16;
151 GAME_OPTION_BOTVSPLAYER = 32;
152 GAME_OPTION_BOTVSMONSTER = 64;
154 STATE_NONE = 0;
155 STATE_MENU = 1;
156 STATE_FOLD = 2;
157 STATE_INTERCUSTOM = 3;
158 STATE_INTERSINGLE = 4;
159 STATE_INTERTEXT = 5;
160 STATE_INTERPIC = 6;
161 STATE_ENDPIC = 7;
162 STATE_SLIST = 8;
164 LMS_RESPAWN_NONE = 0;
165 LMS_RESPAWN_WARMUP = 1;
166 LMS_RESPAWN_FINAL = 2;
168 SPECT_NONE = 0;
169 SPECT_STATS = 1;
170 SPECT_MAPVIEW = 2;
171 SPECT_PLAYERS = 3;
173 DE_GLOBEVENT = 0;
174 DE_BFGHIT = 1;
175 DE_KILLCOMBO = 2;
177 ANNOUNCE_NONE = 0;
178 ANNOUNCE_ME = 1;
179 ANNOUNCE_MEPLUS = 2;
180 ANNOUNCE_ALL = 3;
182 CONFIG_FILENAME = 'Doom2DF.cfg';
183 LOG_FILENAME = 'Doom2DF.log';
185 TEST_MAP_NAME = '$$$_TEST_$$$';
187 STD_PLAYER_MODEL = 'Doomer';
189 var
190 gStdFont: DWORD;
191 gGameSettings: TGameSettings;
192 gPlayer1Settings: TPlayerSettings;
193 gPlayer2Settings: TPlayerSettings;
194 gGameOn: Boolean;
195 gPlayerScreenSize: TPoint;
196 gPlayer1ScreenCoord: TPoint;
197 gPlayer2ScreenCoord: TPoint;
198 gPlayer1: TPlayer = nil;
199 gPlayer2: TPlayer = nil;
200 gPlayerDrawn: TPlayer = nil;
201 gTime: LongWord;
202 gSwitchGameMode: Byte = GM_DM;
203 gHearPoint1, gHearPoint2: THearPoint;
204 gSoundEffectsDF: Boolean = False;
205 gSoundTriggerTime: Word = 0;
206 gAnnouncer: Byte = ANNOUNCE_NONE;
207 goodsnd: array[0..3] of TPlayableSound;
208 killsnd: array[0..3] of TPlayableSound;
209 gDefInterTime: ShortInt = -1;
210 gInterEndTime: LongWord = 0;
211 gInterTime: LongWord = 0;
212 gServInterTime: Byte = 0;
213 gGameStartTime: LongWord = 0;
214 gTotalMonsters: Integer = 0;
215 gPause: Boolean;
216 gShowTime: Boolean = True;
217 gShowFPS: Boolean = False;
218 gShowGoals: Boolean = True;
219 gShowStat: Boolean = True;
220 gShowKillMsg: Boolean = True;
221 gShowLives: Boolean = True;
222 gShowPing: Boolean = False;
223 gShowMap: Boolean = False;
224 gExit: Byte = 0;
225 gState: Byte = STATE_NONE;
226 sX, sY: Integer;
227 sWidth, sHeight: Word;
228 gSpectMode: Byte = SPECT_NONE;
229 gSpectHUD: Boolean = True;
230 gSpectKeyPress: Boolean = False;
231 gSpectX: Integer = 0;
232 gSpectY: Integer = 0;
233 gSpectStep: Byte = 8;
234 gSpectViewTwo: Boolean = False;
235 gSpectPID1: Integer = -1;
236 gSpectPID2: Integer = -1;
237 gMusic: TMusic = nil;
238 gLoadGameMode: Boolean;
239 gCheats: Boolean = False;
240 gMapOnce: Boolean = False;
241 gMapToDelete: String;
242 gTempDelete: Boolean = False;
243 gLastMap: Boolean = False;
244 gWinPosX, gWinPosY: Integer;
245 gWinSizeX, gWinSizeY: Integer;
246 gWinFrameX, gWinFrameY, gWinCaption: Integer;
247 gWinActive: Boolean = False;
248 gResolutionChange: Boolean = False;
249 gRC_Width, gRC_Height: Word;
250 gRC_FullScreen, gRC_Maximized: Boolean;
251 gLanguageChange: Boolean = False;
252 gDebugMode: Boolean = False;
253 g_debug_Sounds: Boolean = False;
254 g_debug_Frames: Boolean = False;
255 g_debug_WinMsgs: Boolean = False;
256 g_debug_MonsterOff: Boolean = False;
257 g_debug_BotAIOff: Byte = 0;
258 g_debug_HealthBar: Boolean = False;
259 g_Debug_Player: Boolean = False;
260 gCoopMonstersKilled: Word = 0;
261 gCoopSecretsFound: Word = 0;
262 gCoopTotalMonstersKilled: Word = 0;
263 gCoopTotalSecretsFound: Word = 0;
264 gCoopTotalMonsters: Word = 0;
265 gCoopTotalSecrets: Word = 0;
266 gStatsOff: Boolean = False;
267 gStatsPressed: Boolean = False;
268 gExitByTrigger: Boolean = False;
269 gNextMap: String = '';
270 gLMSRespawn: Byte = LMS_RESPAWN_NONE;
271 gLMSRespawnTime: Cardinal = 0;
272 gLMSSoftSpawn: Boolean = False;
273 gMissionFailed: Boolean = False;
274 gVoteInProgress: Boolean = False;
275 gVotePassed: Boolean = False;
276 gVoteCommand: string = '';
277 gVoteTimer: Cardinal = 0;
278 gVoteCmdTimer: Cardinal = 0;
279 gVoteCount: Integer = 0;
280 gVoteTimeout: Cardinal = 30;
281 gVoted: Boolean = False;
282 gVotesEnabled: Boolean = True;
283 gEvents: Array of TGameEvent;
284 gDelayedEvents: Array of TDelayedEvent;
286 P1MoveButton: Byte = 0;
287 P2MoveButton: Byte = 0;
289 implementation
291 uses
292 g_textures, g_main, g_window, g_menu,
293 e_input, e_log, g_console, g_items, g_map,
294 g_playermodel, g_gfx, g_options, g_weapons, Math,
295 g_triggers, MAPDEF, g_monsters, e_sound, CONFIG,
296 BinEditor, g_language, g_net, SDL,
297 ENet, e_fixedbuffer, g_netmsg, g_netmaster, GL, GLExt,
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 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: 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
2670 //DrawMinimap(p, _TRect(0, 0, 128, 128));
2671 if g_Debug_Player then
2672 g_Player_DrawDebug(p);
2673 p.DrawGUI();
2674 end;
2676 procedure g_Game_Draw();
2677 var
2678 ID: DWORD;
2679 w, h: Word;
2680 ww, hh: Byte;
2681 Time: Int64;
2682 back: string;
2683 plView1, plView2: TPlayer;
2684 Split: Boolean;
2685 begin
2686 if gExit = EXIT_QUIT then Exit;
2688 Time := GetTimer() div 1000;
2689 FPSCounter := FPSCounter+1;
2690 if Time - FPSTime >= 1000 then
2691 begin
2692 FPS := FPSCounter;
2693 FPSCounter := 0;
2694 FPSTime := Time;
2695 end;
2697 if gGameOn or (gState = STATE_FOLD) then
2698 begin
2699 if (gPlayer1 <> nil) and (gPlayer2 <> nil) then
2700 begin
2701 gSpectMode := SPECT_NONE;
2702 if not gRevertPlayers then
2703 begin
2704 plView1 := gPlayer1;
2705 plView2 := gPlayer2;
2706 end
2707 else
2708 begin
2709 plView1 := gPlayer2;
2710 plView2 := gPlayer1;
2711 end;
2712 end
2713 else
2714 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
2715 begin
2716 gSpectMode := SPECT_NONE;
2717 if gPlayer2 = nil then
2718 plView1 := gPlayer1
2719 else
2720 plView1 := gPlayer2;
2721 plView2 := nil;
2722 end
2723 else
2724 begin
2725 plView1 := nil;
2726 plView2 := nil;
2727 end;
2729 if (plView1 = nil) and (plView2 = nil) and (gSpectMode = SPECT_NONE) then
2730 gSpectMode := SPECT_STATS;
2732 if gSpectMode = SPECT_PLAYERS then
2733 if gPlayers <> nil then
2734 begin
2735 plView1 := GetActivePlayer_ByID(gSpectPID1);
2736 if plView1 = nil then
2737 begin
2738 gSpectPID1 := GetActivePlayerID_Next();
2739 plView1 := GetActivePlayer_ByID(gSpectPID1);
2740 end;
2741 if gSpectViewTwo then
2742 begin
2743 plView2 := GetActivePlayer_ByID(gSpectPID2);
2744 if plView2 = nil then
2745 begin
2746 gSpectPID2 := GetActivePlayerID_Next();
2747 plView2 := GetActivePlayer_ByID(gSpectPID2);
2748 end;
2749 end;
2750 end;
2752 if gSpectMode = SPECT_MAPVIEW then
2753 begin
2754 // Ðåæèì ïðîñìîòðà êàðòû
2755 Split := False;
2756 e_SetViewPort(0, 0, gScreenWidth, gScreenHeight);
2757 DrawMapView(gSpectX, gSpectY, gScreenWidth, gScreenHeight);
2758 gHearPoint1.Active := True;
2759 gHearPoint1.Coords.X := gScreenWidth div 2 + gSpectX;
2760 gHearPoint1.Coords.Y := gScreenHeight div 2 + gSpectY;
2761 gHearPoint2.Active := False;
2762 end
2763 else
2764 begin
2765 Split := (plView1 <> nil) and (plView2 <> nil);
2767 // Òî÷êè ñëóõà èãðîêîâ
2768 if plView1 <> nil then
2769 begin
2770 gHearPoint1.Active := True;
2771 gHearPoint1.Coords.X := plView1.GameX;
2772 gHearPoint1.Coords.Y := plView1.GameY;
2773 end else
2774 gHearPoint1.Active := False;
2775 if plView2 <> nil then
2776 begin
2777 gHearPoint2.Active := True;
2778 gHearPoint2.Coords.X := plView2.GameX;
2779 gHearPoint2.Coords.Y := plView2.GameY;
2780 end else
2781 gHearPoint2.Active := False;
2783 // Ðàçìåð ýêðàíîâ èãðîêîâ:
2784 gPlayerScreenSize.X := gScreenWidth-196;
2785 if Split then
2786 begin
2787 gPlayerScreenSize.Y := gScreenHeight div 2;
2788 if gScreenHeight mod 2 = 0 then
2789 Dec(gPlayerScreenSize.Y);
2790 end
2791 else
2792 gPlayerScreenSize.Y := gScreenHeight;
2794 if Split then
2795 if gScreenHeight mod 2 = 0 then
2796 e_SetViewPort(0, gPlayerScreenSize.Y+2, gPlayerScreenSize.X+196, gPlayerScreenSize.Y)
2797 else
2798 e_SetViewPort(0, gPlayerScreenSize.Y+1, gPlayerScreenSize.X+196, gPlayerScreenSize.Y);
2800 DrawPlayer(plView1);
2801 gPlayer1ScreenCoord.X := sX;
2802 gPlayer1ScreenCoord.Y := sY;
2804 if Split then
2805 begin
2806 e_SetViewPort(0, 0, gPlayerScreenSize.X+196, gPlayerScreenSize.Y);
2808 DrawPlayer(plView2);
2809 gPlayer2ScreenCoord.X := sX;
2810 gPlayer2ScreenCoord.Y := sY;
2811 end;
2813 e_SetViewPort(0, 0, gScreenWidth, gScreenHeight);
2815 if Split then
2816 e_DrawLine(2, 0, gScreenHeight div 2, gScreenWidth, gScreenHeight div 2, 0, 0, 0);
2817 end;
2819 if MessageText <> '' then
2820 begin
2821 w := 0;
2822 h := 0;
2823 e_CharFont_GetSizeFmt(gMenuFont, MessageText, w, h);
2824 if Split then
2825 e_CharFont_PrintFmt(gMenuFont, (gScreenWidth div 2)-(w div 2),
2826 (gScreenHeight div 2)-(h div 2), MessageText)
2827 else
2828 e_CharFont_PrintFmt(gMenuFont, (gScreenWidth div 2)-(w div 2),
2829 Round(gScreenHeight / 2.75)-(h div 2), MessageText);
2830 end;
2832 if IsDrawStat or (gSpectMode = 1) then DrawStat();
2834 if gSpectHUD and (not gChatShow) and (gSpectMode <> SPECT_NONE) then
2835 begin
2836 // Draw spectator GUI
2837 ww := 0;
2838 hh := 0;
2839 e_TextureFontGetSize(gStdFont, ww, hh);
2840 case gSpectMode of
2841 SPECT_STATS:
2842 e_TextureFontPrintEx(0, gScreenHeight - (hh+2)*2, 'MODE: Stats', gStdFont, 255, 255, 255, 1);
2843 SPECT_MAPVIEW:
2844 e_TextureFontPrintEx(0, gScreenHeight - (hh+2)*2, 'MODE: Observe Map', gStdFont, 255, 255, 255, 1);
2845 SPECT_PLAYERS:
2846 e_TextureFontPrintEx(0, gScreenHeight - (hh+2)*2, 'MODE: Watch Players', gStdFont, 255, 255, 255, 1);
2847 end;
2848 e_TextureFontPrintEx(2*ww, gScreenHeight - (hh+2), '< jump >', gStdFont, 255, 255, 255, 1);
2849 if gSpectMode = SPECT_MAPVIEW then
2850 begin
2851 e_TextureFontPrintEx(22*ww, gScreenHeight - (hh+2)*2, '[-]', gStdFont, 255, 255, 255, 1);
2852 e_TextureFontPrintEx(26*ww, gScreenHeight - (hh+2)*2, 'Step ' + IntToStr(gSpectStep), gStdFont, 255, 255, 255, 1);
2853 e_TextureFontPrintEx(34*ww, gScreenHeight - (hh+2)*2, '[+]', gStdFont, 255, 255, 255, 1);
2854 e_TextureFontPrintEx(18*ww, gScreenHeight - (hh+2), '<prev weap>', gStdFont, 255, 255, 255, 1);
2855 e_TextureFontPrintEx(30*ww, gScreenHeight - (hh+2), '<next weap>', gStdFont, 255, 255, 255, 1);
2856 end;
2857 if gSpectMode = SPECT_PLAYERS then
2858 begin
2859 e_TextureFontPrintEx(22*ww, gScreenHeight - (hh+2)*2, 'Player 1', gStdFont, 255, 255, 255, 1);
2860 e_TextureFontPrintEx(20*ww, gScreenHeight - (hh+2), '<left/right>', gStdFont, 255, 255, 255, 1);
2861 if gSpectViewTwo then
2862 begin
2863 e_TextureFontPrintEx(37*ww, gScreenHeight - (hh+2)*2, 'Player 2', gStdFont, 255, 255, 255, 1);
2864 e_TextureFontPrintEx(34*ww, gScreenHeight - (hh+2), '<prev w/next w>', gStdFont, 255, 255, 255, 1);
2865 e_TextureFontPrintEx(52*ww, gScreenHeight - (hh+2)*2, '2x View', gStdFont, 255, 255, 255, 1);
2866 e_TextureFontPrintEx(51*ww, gScreenHeight - (hh+2), '<up/down>', gStdFont, 255, 255, 255, 1);
2867 end
2868 else
2869 begin
2870 e_TextureFontPrintEx(35*ww, gScreenHeight - (hh+2)*2, '2x View', gStdFont, 255, 255, 255, 1);
2871 e_TextureFontPrintEx(34*ww, gScreenHeight - (hh+2), '<up/down>', gStdFont, 255, 255, 255, 1);
2872 end;
2873 end;
2874 end;
2875 end;
2877 if gPause and gGameOn and (g_ActiveWindow = nil) then
2878 begin
2879 e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
2881 e_CharFont_GetSize(gMenuFont, _lc[I_MENU_PAUSE], w, h);
2882 e_CharFont_Print(gMenuFont, (gScreenWidth div 2)-(w div 2),
2883 (gScreenHeight div 2)-(h div 2), _lc[I_MENU_PAUSE]);
2884 end;
2886 if not gGameOn then
2887 begin
2888 if (gState = STATE_MENU) then
2889 begin
2890 if ((g_ActiveWindow = nil) or (g_ActiveWindow.BackTexture = '')) then
2891 begin
2892 if g_Texture_Get('MENU_BACKGROUND', ID) then
2893 e_DrawSize(ID, 0, 0, 0, False, False, gScreenWidth, gScreenHeight)
2894 else e_Clear(GL_COLOR_BUFFER_BIT, 0, 0, 0);
2895 end;
2896 if g_ActiveWindow <> nil then
2897 e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
2898 end;
2900 if gState = STATE_FOLD then
2901 e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 0, 0, 0, EndingGameCounter);
2903 if gState = STATE_INTERCUSTOM then
2904 begin
2905 if gLastMap and (gGameSettings.GameMode = GM_COOP) then
2906 begin
2907 back := 'TEXTURE_endpic';
2908 if not g_Texture_Get(back, ID) then
2909 back := _lc[I_TEXTURE_ENDPIC];
2910 end
2911 else
2912 back := 'INTER';
2914 if g_Texture_Get(back, ID) then
2915 e_DrawSize(ID, 0, 0, 0, False, False, gScreenWidth, gScreenHeight)
2916 else
2917 e_Clear(GL_COLOR_BUFFER_BIT, 0, 0, 0);
2919 DrawCustomStat();
2921 if g_ActiveWindow <> nil then
2922 e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
2923 end;
2925 if gState = STATE_INTERSINGLE then
2926 begin
2927 if EndingGameCounter > 0 then
2928 e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 0, 0, 0, EndingGameCounter)
2929 else
2930 begin
2931 back := 'INTER';
2933 if g_Texture_Get(back, ID) then
2934 e_DrawSize(ID, 0, 0, 0, False, False, gScreenWidth, gScreenHeight)
2935 else
2936 e_Clear(GL_COLOR_BUFFER_BIT, 0, 0, 0);
2938 DrawSingleStat();
2940 if g_ActiveWindow <> nil then
2941 e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
2942 end;
2943 end;
2945 if gState = STATE_ENDPIC then
2946 begin
2947 ID := DWORD(-1);
2948 if not g_Texture_Get('TEXTURE_endpic', ID) then
2949 g_Texture_Get(_lc[I_TEXTURE_ENDPIC], ID);
2951 if ID <> DWORD(-1) then
2952 e_DrawSize(ID, 0, 0, 0, False, False, gScreenWidth, gScreenHeight)
2953 else
2954 e_Clear(GL_COLOR_BUFFER_BIT, 0, 0, 0);
2956 if g_ActiveWindow <> nil then
2957 e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
2958 end;
2960 if gState = STATE_SLIST then
2961 begin
2962 if g_Texture_Get('MENU_BACKGROUND', ID) then
2963 begin
2964 e_DrawSize(ID, 0, 0, 0, False, False, gScreenWidth, gScreenHeight);
2965 e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
2966 end;
2967 g_Serverlist_Draw(slCurrent);
2968 end;
2969 end;
2971 if g_ActiveWindow <> nil then
2972 begin
2973 if gGameOn then
2974 e_DrawFillQuad(0, 0, gScreenWidth-1, gScreenHeight-1, 48, 48, 48, 180);
2975 g_ActiveWindow.Draw();
2976 end;
2978 g_Console_Draw();
2980 if g_debug_Sounds and gGameOn then
2981 begin
2982 for w := 0 to High(e_SoundsArray) do
2983 for h := 0 to e_SoundsArray[w].nRefs do
2984 e_DrawPoint(1, w+100, h+100, 255, 0, 0);
2985 end;
2987 if gShowFPS then
2988 begin
2989 e_TextureFontPrint(0, 0, Format('FPS: %d', [FPS]), gStdFont);
2990 e_TextureFontPrint(0, 16, Format('UPS: %d', [UPS]), gStdFont);
2991 end;
2993 if gGameOn and gShowTime and (gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT]) then
2994 e_TextureFontPrint(gScreenWidth-72, 0,
2995 Format('%d:%.2d:%.2d', [gTime div 1000 div 3600, (gTime div 1000 div 60) mod 60, gTime div 1000 mod 60]),
2996 gStdFont);
2997 end;
2999 procedure g_Game_Quit();
3000 begin
3001 g_Game_StopAllSounds(True);
3002 gMusic.Free();
3003 g_Game_SaveOptions();
3004 g_Game_FreeData();
3005 g_PlayerModel_FreeData();
3006 g_Texture_DeleteAll();
3007 g_Frames_DeleteAll();
3008 g_Menu_Free();
3010 if NetInitDone then g_Net_Free;
3012 // Íàäî óäàëèòü êàðòó ïîñëå òåñòà:
3013 if gMapToDelete <> '' then
3014 g_Game_DeleteTestMap();
3016 gExit := EXIT_QUIT;
3017 PushExitEvent();
3018 end;
3020 procedure g_FatalError(Text: String);
3021 begin
3022 g_Console_Add(Format(_lc[I_FATAL_ERROR], [Text]), True);
3023 e_WriteLog(Format(_lc[I_FATAL_ERROR], [Text]), MSG_WARNING);
3025 gExit := EXIT_SIMPLE;
3026 end;
3028 procedure g_SimpleError(Text: String);
3029 begin
3030 g_Console_Add(Format(_lc[I_SIMPLE_ERROR], [Text]), True);
3031 e_WriteLog(Format(_lc[I_SIMPLE_ERROR], [Text]), MSG_WARNING);
3032 end;
3034 procedure g_Game_SetupScreenSize();
3035 var
3036 d: Single;
3037 begin
3038 // Ðàçìåð ýêðàíîâ èãðîêîâ:
3039 gPlayerScreenSize.X := gScreenWidth-196;
3040 if (gPlayer1 <> nil) and (gPlayer2 <> nil) then
3041 gPlayerScreenSize.Y := gScreenHeight div 2
3042 else
3043 gPlayerScreenSize.Y := gScreenHeight;
3045 // Ðàçìåð çàäíåãî ïëàíà:
3046 if BackID <> DWORD(-1) then
3047 begin
3048 d := SKY_STRETCH;
3050 if (gScreenWidth*d > gMapInfo.Width) or
3051 (gScreenHeight*d > gMapInfo.Height) then
3052 d := 1.0;
3054 gBackSize.X := Round(gScreenWidth*d);
3055 gBackSize.Y := Round(gScreenHeight*d);
3056 end;
3057 end;
3059 procedure g_Game_ChangeResolution(newWidth, newHeight: Word; nowFull, nowMax: Boolean);
3060 begin
3061 g_Window_SetSize(newWidth, newHeight, nowFull);
3062 end;
3064 procedure g_Game_AddPlayer(Team: Byte = TEAM_NONE);
3065 begin
3066 if ((not gGameOn) and (gState <> STATE_INTERCUSTOM))
3067 or (not (gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT])) then
3068 Exit;
3069 if gPlayer1 = nil then
3070 begin
3071 if g_Game_IsClient then
3072 begin
3073 if NetPlrUID1 > -1 then
3074 begin
3075 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE);
3076 gPlayer1 := g_Player_Get(NetPlrUID1);
3077 end;
3078 Exit;
3079 end;
3081 if not (Team in [TEAM_RED, TEAM_BLUE]) then
3082 Team := gPlayer1Settings.Team;
3084 // Ñîçäàíèå ïåðâîãî èãðîêà:
3085 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
3086 gPlayer1Settings.Color,
3087 Team, False));
3088 if gPlayer1 = nil then
3089 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]))
3090 else
3091 begin
3092 gPlayer1.Name := gPlayer1Settings.Name;
3093 g_Console_Add(Format(_lc[I_PLAYER_JOIN], [gPlayer1.Name]), True);
3094 if g_Game_IsServer and g_Game_IsNet then
3095 MH_SEND_PlayerCreate(gPlayer1.UID);
3096 gPlayer1.Respawn(False, True);
3098 if g_Game_IsNet and NetUseMaster then
3099 g_Net_Slist_Update;
3100 end;
3102 Exit;
3103 end;
3104 if gPlayer2 = nil then
3105 begin
3106 if g_Game_IsClient then
3107 begin
3108 if NetPlrUID2 > -1 then
3109 gPlayer2 := g_Player_Get(NetPlrUID2);
3110 Exit;
3111 end;
3113 if not (Team in [TEAM_RED, TEAM_BLUE]) then
3114 Team := gPlayer2Settings.Team;
3116 // Ñîçäàíèå âòîðîãî èãðîêà:
3117 gPlayer2 := g_Player_Get(g_Player_Create(gPlayer2Settings.Model,
3118 gPlayer2Settings.Color,
3119 Team, False));
3120 if gPlayer2 = nil then
3121 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [2]))
3122 else
3123 begin
3124 gPlayer2.Name := gPlayer2Settings.Name;
3125 g_Console_Add(Format(_lc[I_PLAYER_JOIN], [gPlayer2.Name]), True);
3126 if g_Game_IsServer and g_Game_IsNet then
3127 MH_SEND_PlayerCreate(gPlayer2.UID);
3128 gPlayer2.Respawn(False, True);
3130 if g_Game_IsNet and NetUseMaster then
3131 g_Net_Slist_Update;
3132 end;
3134 Exit;
3135 end;
3136 end;
3138 procedure g_Game_RemovePlayer();
3139 var
3140 Pl: TPlayer;
3141 begin
3142 if ((not gGameOn) and (gState <> STATE_INTERCUSTOM))
3143 or (not (gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT])) then
3144 Exit;
3145 Pl := gPlayer2;
3146 if Pl <> nil then
3147 begin
3148 if g_Game_IsServer then
3149 begin
3150 Pl.Lives := 0;
3151 Pl.Kill(K_SIMPLEKILL, 0, HIT_DISCON);
3152 g_Console_Add(Format(_lc[I_PLAYER_LEAVE], [Pl.Name]), True);
3153 g_Player_Remove(Pl.UID);
3155 if g_Game_IsNet and NetUseMaster then
3156 g_Net_Slist_Update;
3157 end else
3158 gPlayer2 := nil;
3159 Exit;
3160 end;
3161 Pl := gPlayer1;
3162 if Pl <> nil then
3163 begin
3164 if g_Game_IsServer then
3165 begin
3166 Pl.Lives := 0;
3167 Pl.Kill(K_SIMPLEKILL, 0, HIT_DISCON);
3168 g_Console_Add(Format(_lc[I_PLAYER_LEAVE], [Pl.Name]), True);
3169 g_Player_Remove(Pl.UID);
3171 if g_Game_IsNet and NetUseMaster then
3172 g_Net_Slist_Update;
3173 end else
3174 begin
3175 gPlayer1 := nil;
3176 MC_SEND_CheatRequest(NET_CHEAT_SPECTATE);
3177 end;
3178 Exit;
3179 end;
3180 end;
3182 procedure g_Game_Spectate();
3183 begin
3184 g_Game_RemovePlayer();
3185 if gPlayer1 <> nil then
3186 g_Game_RemovePlayer();
3187 end;
3189 procedure g_Game_SpectateCenterView();
3190 begin
3191 gSpectX := Max(gMapInfo.Width div 2 - gScreenWidth div 2, 0);
3192 gSpectY := Max(gMapInfo.Height div 2 - gScreenHeight div 2, 0);
3193 end;
3195 procedure g_Game_StartSingle(Map: String; TwoPlayers: Boolean; nPlayers: Byte);
3196 var
3197 i, nPl: Integer;
3198 begin
3199 g_Game_Free();
3201 e_WriteLog('Starting singleplayer game...', MSG_NOTIFY);
3203 g_Game_ClearLoading();
3205 // Íàñòðîéêè èãðû:
3206 FillByte(gGameSettings, SizeOf(TGameSettings), 0);
3207 gAimLine := False;
3208 gShowMap := False;
3209 gGameSettings.GameType := GT_SINGLE;
3210 gGameSettings.MaxLives := 0;
3211 gGameSettings.Options := gGameSettings.Options + GAME_OPTION_ALLOWEXIT;
3212 gGameSettings.Options := gGameSettings.Options + GAME_OPTION_MONSTERS;
3213 gGameSettings.Options := gGameSettings.Options + GAME_OPTION_BOTVSMONSTER;
3214 gSwitchGameMode := GM_SINGLE;
3216 g_Game_ExecuteEvent('ongamestart');
3218 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
3219 g_Game_SetupScreenSize();
3221 // Ñîçäàíèå ïåðâîãî èãðîêà:
3222 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
3223 gPlayer1Settings.Color,
3224 gPlayer1Settings.Team, False));
3225 if gPlayer1 = nil then
3226 begin
3227 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]));
3228 Exit;
3229 end;
3231 gPlayer1.Name := gPlayer1Settings.Name;
3232 nPl := 1;
3234 // Ñîçäàíèå âòîðîãî èãðîêà, åñëè åñòü:
3235 if TwoPlayers then
3236 begin
3237 gPlayer2 := g_Player_Get(g_Player_Create(gPlayer2Settings.Model,
3238 gPlayer2Settings.Color,
3239 gPlayer2Settings.Team, False));
3240 if gPlayer2 = nil then
3241 begin
3242 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [2]));
3243 Exit;
3244 end;
3246 gPlayer2.Name := gPlayer2Settings.Name;
3247 Inc(nPl);
3248 end;
3250 // Çàãðóçêà è çàïóñê êàðòû:
3251 if not g_Game_StartMap(MAP, True) then
3252 begin
3253 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [gGameSettings.WAD + ':\' + MAP]));
3254 Exit;
3255 end;
3257 // Íàñòðîéêè èãðîêîâ è áîòîâ:
3258 g_Player_Init();
3260 // Ñîçäàåì áîòîâ:
3261 for i := nPl+1 to nPlayers do
3262 g_Player_Create(STD_PLAYER_MODEL, _RGB(0, 0, 0), 0, True);
3263 end;
3265 procedure g_Game_StartCustom(Map: String; GameMode: Byte;
3266 TimeLimit, GoalLimit: Word;
3267 MaxLives: Byte;
3268 Options: LongWord; nPlayers: Byte);
3269 var
3270 i, nPl: Integer;
3271 begin
3272 g_Game_Free();
3274 e_WriteLog('Starting custom game...', MSG_NOTIFY);
3276 g_Game_ClearLoading();
3278 // Íàñòðîéêè èãðû:
3279 gGameSettings.GameType := GT_CUSTOM;
3280 gGameSettings.GameMode := GameMode;
3281 gSwitchGameMode := GameMode;
3282 gGameSettings.TimeLimit := TimeLimit;
3283 gGameSettings.GoalLimit := GoalLimit;
3284 gGameSettings.MaxLives := IfThen(GameMode = GM_CTF, 0, MaxLives);
3285 gGameSettings.Options := Options;
3287 gCoopTotalMonstersKilled := 0;
3288 gCoopTotalSecretsFound := 0;
3289 gCoopTotalMonsters := 0;
3290 gCoopTotalSecrets := 0;
3291 gAimLine := False;
3292 gShowMap := False;
3294 g_Game_ExecuteEvent('ongamestart');
3296 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
3297 g_Game_SetupScreenSize();
3299 // Ðåæèì íàáëþäàòåëÿ:
3300 if nPlayers = 0 then
3301 begin
3302 gPlayer1 := nil;
3303 gPlayer2 := nil;
3304 end;
3306 nPl := 0;
3307 if nPlayers >= 1 then
3308 begin
3309 // Ñîçäàíèå ïåðâîãî èãðîêà:
3310 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
3311 gPlayer1Settings.Color,
3312 gPlayer1Settings.Team, False));
3313 if gPlayer1 = nil then
3314 begin
3315 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]));
3316 Exit;
3317 end;
3319 gPlayer1.Name := gPlayer1Settings.Name;
3320 Inc(nPl);
3321 end;
3323 if nPlayers >= 2 then
3324 begin
3325 // Ñîçäàíèå âòîðîãî èãðîêà:
3326 gPlayer2 := g_Player_Get(g_Player_Create(gPlayer2Settings.Model,
3327 gPlayer2Settings.Color,
3328 gPlayer2Settings.Team, False));
3329 if gPlayer2 = nil then
3330 begin
3331 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [2]));
3332 Exit;
3333 end;
3335 gPlayer2.Name := gPlayer2Settings.Name;
3336 Inc(nPl);
3337 end;
3339 // Çàãðóçêà è çàïóñê êàðòû:
3340 if not g_Game_StartMap(Map, True) then
3341 begin
3342 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [Map]));
3343 Exit;
3344 end;
3346 // Íåò òî÷åê ïîÿâëåíèÿ:
3347 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1) +
3348 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2) +
3349 g_Map_GetPointCount(RESPAWNPOINT_DM) +
3350 g_Map_GetPointCount(RESPAWNPOINT_RED)+
3351 g_Map_GetPointCount(RESPAWNPOINT_BLUE)) < 1 then
3352 begin
3353 g_FatalError(_lc[I_GAME_ERROR_GET_SPAWN]);
3354 Exit;
3355 end;
3357 // Íàñòðîéêè èãðîêîâ è áîòîâ:
3358 g_Player_Init();
3360 // Ñîçäàåì áîòîâ:
3361 for i := nPl+1 to nPlayers do
3362 g_Player_Create(STD_PLAYER_MODEL, _RGB(0, 0, 0), 0, True);
3363 end;
3365 procedure g_Game_StartServer(Map: String; GameMode: Byte;
3366 TimeLimit, GoalLimit: Word; MaxLives: Byte;
3367 Options: LongWord; nPlayers: Byte;
3368 IPAddr: LongWord; Port: Word);
3369 begin
3370 g_Game_Free();
3372 e_WriteLog('Starting net game (server)...', MSG_NOTIFY);
3374 g_Game_ClearLoading();
3376 // Íàñòðîéêè èãðû:
3377 gGameSettings.GameType := GT_SERVER;
3378 gGameSettings.GameMode := GameMode;
3379 gSwitchGameMode := GameMode;
3380 gGameSettings.TimeLimit := TimeLimit;
3381 gGameSettings.GoalLimit := GoalLimit;
3382 gGameSettings.MaxLives := IfThen(GameMode = GM_CTF, 0, MaxLives);
3383 gGameSettings.Options := Options;
3385 gCoopTotalMonstersKilled := 0;
3386 gCoopTotalSecretsFound := 0;
3387 gCoopTotalMonsters := 0;
3388 gCoopTotalSecrets := 0;
3389 gAimLine := False;
3390 gShowMap := False;
3392 g_Game_ExecuteEvent('ongamestart');
3394 // Óñòàíîâêà ðàçìåðîâ îêíà èãðîêà
3395 g_Game_SetupScreenSize();
3397 // Ðåæèì íàáëþäàòåëÿ:
3398 if nPlayers = 0 then
3399 begin
3400 gPlayer1 := nil;
3401 gPlayer2 := nil;
3402 end;
3404 if nPlayers >= 1 then
3405 begin
3406 // Ñîçäàíèå ïåðâîãî èãðîêà:
3407 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
3408 gPlayer1Settings.Color,
3409 gPlayer1Settings.Team, False));
3410 if gPlayer1 = nil then
3411 begin
3412 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]));
3413 Exit;
3414 end;
3416 gPlayer1.Name := gPlayer1Settings.Name;
3417 end;
3419 if nPlayers >= 2 then
3420 begin
3421 // Ñîçäàíèå âòîðîãî èãðîêà:
3422 gPlayer2 := g_Player_Get(g_Player_Create(gPlayer2Settings.Model,
3423 gPlayer2Settings.Color,
3424 gPlayer2Settings.Team, False));
3425 if gPlayer2 = nil then
3426 begin
3427 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [2]));
3428 Exit;
3429 end;
3431 gPlayer2.Name := gPlayer2Settings.Name;
3432 end;
3434 // Ñòàðòóåì ñåðâåð
3435 if not g_Net_Host(IPAddr, Port, NetMaxClients) then
3436 begin
3437 g_FatalError(_lc[I_NET_MSG] + _lc[I_NET_ERR_HOST]);
3438 Exit;
3439 end;
3441 g_Net_Slist_Set(NetSlistIP, NetSlistPort);
3443 // Çàãðóçêà è çàïóñê êàðòû:
3444 if not g_Game_StartMap(Map, True) then
3445 begin
3446 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [Map]));
3447 Exit;
3448 end;
3450 // Íåò òî÷åê ïîÿâëåíèÿ:
3451 if (g_Map_GetPointCount(RESPAWNPOINT_PLAYER1) +
3452 g_Map_GetPointCount(RESPAWNPOINT_PLAYER2) +
3453 g_Map_GetPointCount(RESPAWNPOINT_DM) +
3454 g_Map_GetPointCount(RESPAWNPOINT_RED)+
3455 g_Map_GetPointCount(RESPAWNPOINT_BLUE)) < 1 then
3456 begin
3457 g_FatalError(_lc[I_GAME_ERROR_GET_SPAWN]);
3458 Exit;
3459 end;
3461 // Íàñòðîéêè èãðîêîâ è áîòîâ:
3462 g_Player_Init();
3464 NetState := NET_STATE_GAME;
3465 end;
3467 procedure g_Game_StartClient(Addr: String; Port: Word; PW: String);
3468 var
3469 Map: String;
3470 WadName: string;
3471 Ptr: Pointer;
3472 T: Cardinal;
3473 MID: Byte;
3474 State: Byte;
3475 OuterLoop: Boolean;
3476 newResPath: string;
3477 begin
3478 g_Game_Free();
3480 State := 0;
3481 e_WriteLog('Starting net game (client)...', MSG_NOTIFY);
3482 e_WriteLog('NET: Trying to connect to ' + Addr + ':' + IntToStr(Port) + '...', MSG_NOTIFY);
3484 g_Game_ClearLoading();
3486 // Íàñòðîéêè èãðû:
3487 gGameSettings.GameType := GT_CLIENT;
3489 gCoopTotalMonstersKilled := 0;
3490 gCoopTotalSecretsFound := 0;
3491 gCoopTotalMonsters := 0;
3492 gCoopTotalSecrets := 0;
3493 gAimLine := False;
3494 gShowMap := False;
3496 g_Game_ExecuteEvent('ongamestart');
3498 // Óñòàíîâêà ðàçìåðîâ îêîí èãðîêîâ:
3499 g_Game_SetupScreenSize();
3501 NetState := NET_STATE_AUTH;
3503 g_Game_SetLoadingText(_lc[I_LOAD_CONNECT], 0, False);
3504 // Ñòàðòóåì êëèåíò
3505 if not g_Net_Connect(Addr, Port) then
3506 begin
3507 g_FatalError(_lc[I_NET_MSG] + _lc[I_NET_ERR_CONN]);
3508 NetState := NET_STATE_NONE;
3509 Exit;
3510 end;
3512 g_Game_SetLoadingText(_lc[I_LOAD_SEND_INFO], 0, False);
3513 MC_SEND_Info(PW);
3514 g_Game_SetLoadingText(_lc[I_LOAD_WAIT_INFO], 0, False);
3516 OuterLoop := True;
3517 while OuterLoop do
3518 begin
3519 while (enet_host_service(NetHost, @NetEvent, 0) > 0) do
3520 begin
3521 if (NetEvent.kind = ENET_EVENT_TYPE_RECEIVE) then
3522 begin
3523 Ptr := NetEvent.packet^.data;
3524 e_Raw_Seek(0);
3526 MID := e_Raw_Read_Byte(Ptr);
3528 if (MID = NET_MSG_INFO) and (State = 0) then
3529 begin
3530 NetMyID := e_Raw_Read_Byte(Ptr);
3531 NetPlrUID1 := e_Raw_Read_Word(Ptr);
3533 WadName := e_Raw_Read_String(Ptr);
3534 Map := e_Raw_Read_String(Ptr);
3536 gWADHash := e_Raw_Read_MD5(Ptr);
3538 gGameSettings.GameMode := e_Raw_Read_Byte(Ptr);
3539 gSwitchGameMode := gGameSettings.GameMode;
3540 gGameSettings.GoalLimit := e_Raw_Read_Word(Ptr);
3541 gGameSettings.TimeLimit := e_Raw_Read_Word(Ptr);
3542 gGameSettings.MaxLives := e_Raw_Read_Byte(Ptr);
3543 gGameSettings.Options := e_Raw_Read_LongWord(Ptr);
3544 T := e_Raw_Read_LongWord(Ptr);
3546 newResPath := g_Res_SearchSameWAD(MapsDir, WadName, gWADHash);
3547 if newResPath = '' then
3548 begin
3549 g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
3550 newResPath := g_Res_DownloadWAD(WadName);
3551 if newResPath = '' then
3552 begin
3553 g_FatalError(_lc[I_NET_ERR_HASH]);
3554 enet_packet_destroy(NetEvent.packet);
3555 NetState := NET_STATE_NONE;
3556 Exit;
3557 end;
3558 end;
3559 newResPath := ExtractRelativePath(MapsDir, newResPath);
3561 gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model,
3562 gPlayer1Settings.Color,
3563 gPlayer1Settings.Team, False));
3565 if gPlayer1 = nil then
3566 begin
3567 g_FatalError(Format(_lc[I_GAME_ERROR_PLAYER_CREATE], [1]));
3569 enet_packet_destroy(NetEvent.packet);
3570 NetState := NET_STATE_NONE;
3571 Exit;
3572 end;
3574 gPlayer1.Name := gPlayer1Settings.Name;
3575 gPlayer1.UID := NetPlrUID1;
3576 gPlayer1.Reset(True);
3578 if not g_Game_StartMap(newResPath + ':\' + Map, True) then
3579 begin
3580 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [WadName + ':\' + Map]));
3582 enet_packet_destroy(NetEvent.packet);
3583 NetState := NET_STATE_NONE;
3584 Exit;
3585 end;
3587 gTime := T;
3589 State := 1;
3590 OuterLoop := False;
3591 enet_packet_destroy(NetEvent.packet);
3592 break;
3593 end
3594 else
3595 enet_packet_destroy(NetEvent.packet);
3596 end
3597 else
3598 if (NetEvent.kind = ENET_EVENT_TYPE_DISCONNECT) then
3599 begin
3600 State := 0;
3601 if (NetEvent.data <= NET_DISC_MAX) then
3602 g_Console_Add(_lc[I_NET_MSG_ERROR] + _lc[I_NET_ERR_CONN] + ' ' +
3603 _lc[TStrings_Locale(Cardinal(I_NET_DISC_NONE) + NetEvent.data)], True);
3604 OuterLoop := False;
3605 Break;
3606 end;
3607 end;
3609 ProcessLoading();
3611 e_PollInput();
3613 if e_KeyPressed(IK_ESCAPE) or e_KeyPressed(IK_SPACE) then
3614 begin
3615 State := 0;
3616 break;
3617 end;
3618 end;
3620 if State <> 1 then
3621 begin
3622 g_FatalError(_lc[I_NET_MSG] + _lc[I_NET_ERR_CONN]);
3623 NetState := NET_STATE_NONE;
3624 Exit;
3625 end;
3627 gLMSRespawn := LMS_RESPAWN_NONE;
3628 gLMSRespawnTime := 0;
3630 g_Player_Init();
3631 NetState := NET_STATE_GAME;
3632 MC_SEND_FullStateRequest;
3633 e_WriteLog('NET: Connection successful.', MSG_NOTIFY);
3634 end;
3636 procedure g_Game_SaveOptions();
3637 begin
3638 g_Options_Write_Video(GameDir+'/'+CONFIG_FILENAME);
3639 end;
3641 procedure g_Game_ChangeMap(MapPath: String);
3642 var
3643 Force: Boolean;
3644 begin
3645 g_Game_ClearLoading();
3647 Force := gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF];
3648 // Åñëè óðîâåíü çàâåðøèëñÿ ïî òðèããåðó Âûõîä, íå î÷èùàòü èíâåíòàðü
3649 if gExitByTrigger then
3650 begin
3651 Force := False;
3652 gExitByTrigger := False;
3653 end;
3654 if not g_Game_StartMap(MapPath, Force) then
3655 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_LOAD], [MapPath]));
3656 end;
3658 procedure g_Game_Restart();
3659 var
3660 Map: string;
3661 begin
3662 if g_Game_IsClient then
3663 Exit;
3664 g_ProcessResourceStr(gMapInfo.Map, nil, nil, @Map);
3666 MessageTime := 0;
3667 gGameOn := False;
3668 g_Game_ClearLoading();
3669 g_Game_StartMap(Map, True);
3670 end;
3672 function g_Game_StartMap(Map: String; Force: Boolean = False): Boolean;
3673 var
3674 NewWAD, ResName: String;
3675 I: Integer;
3676 begin
3677 g_Map_Free();
3678 g_Player_RemoveAllCorpses();
3680 if (not g_Game_IsClient) and
3681 (gSwitchGameMode <> gGameSettings.GameMode) and
3682 (gGameSettings.GameMode <> GM_SINGLE) then
3683 begin
3684 if gSwitchGameMode = GM_CTF then
3685 gGameSettings.MaxLives := 0;
3686 gGameSettings.GameMode := gSwitchGameMode;
3687 Force := True;
3688 end else
3689 gSwitchGameMode := gGameSettings.GameMode;
3691 g_Player_ResetTeams();
3693 if Pos(':\', Map) > 0 then
3694 begin
3695 g_ProcessResourceStr(Map, @NewWAD, nil, @ResName);
3696 if g_Game_IsServer then
3697 begin
3698 gWADHash := MD5File(MapsDir + NewWAD);
3699 g_Game_LoadWAD(NewWAD);
3700 end else
3701 // hash recieved in MC_RECV_GameEvent -> NET_EV_MAPSTART
3702 g_Game_ClientWAD(NewWAD, gWADHash);
3703 end else
3704 ResName := Map;
3706 Result := g_Map_Load(MapsDir + gGameSettings.WAD + ':\' + ResName);
3707 if Result then
3708 begin
3709 g_Player_ResetAll(Force or gLastMap, gGameSettings.GameType = GT_SINGLE);
3711 gState := STATE_NONE;
3712 g_ActiveWindow := nil;
3713 gGameOn := True;
3715 DisableCheats();
3716 ResetTimer();
3718 if gGameSettings.GameMode = GM_CTF then
3719 begin
3720 g_Map_ResetFlag(FLAG_RED);
3721 g_Map_ResetFlag(FLAG_BLUE);
3722 // CTF, à ôëàãîâ íåò:
3723 if not g_Map_HaveFlagPoints() then
3724 g_SimpleError(_lc[I_GAME_ERROR_CTF]);
3725 end;
3726 end
3727 else
3728 begin
3729 gState := STATE_MENU;
3730 gGameOn := False;
3731 end;
3733 gExit := 0;
3734 gPause := False;
3735 gTime := 0;
3736 NetTimeToUpdate := 1;
3737 NetTimeToReliable := 0;
3738 NetTimeToMaster := NetMasterRate;
3739 gLMSRespawn := LMS_RESPAWN_NONE;
3740 gLMSRespawnTime := 0;
3741 gMissionFailed := False;
3742 gNextMap := '';
3744 gCoopMonstersKilled := 0;
3745 gCoopSecretsFound := 0;
3747 gVoteInProgress := False;
3748 gVotePassed := False;
3749 gVoteCount := 0;
3750 gVoted := False;
3752 gStatsOff := False;
3754 if not gGameOn then Exit;
3756 g_Game_SpectateCenterView();
3758 if (gGameSettings.MaxLives > 0) and (gGameSettings.WarmupTime > 0) then
3759 begin
3760 gLMSRespawn := LMS_RESPAWN_WARMUP;
3761 gLMSRespawnTime := gTime + gGameSettings.WarmupTime*1000;
3762 gLMSSoftSpawn := True;
3763 if NetMode = NET_SERVER then
3764 MH_SEND_GameEvent(NET_EV_LMS_WARMUP, (gLMSRespawnTime - gTime) div 1000)
3765 else
3766 g_Console_Add(Format(_lc[I_MSG_WARMUP_START], [(gLMSRespawnTime - gTime) div 1000]), True);
3767 end;
3769 if NetMode = NET_SERVER then
3770 begin
3771 MH_SEND_GameEvent(NET_EV_MAPSTART, gGameSettings.GameMode, Map);
3773 // Ìàñòåðñåðâåð
3774 if NetUseMaster then
3775 begin
3776 if (NetMHost = nil) or (NetMPeer = nil) then
3777 if not g_Net_Slist_Connect then
3778 g_Console_Add(_lc[I_NET_MSG_ERROR] + _lc[I_NET_SLIST_ERROR]);
3780 g_Net_Slist_Update;
3781 end;
3783 if NetClients <> nil then
3784 for I := 0 to High(NetClients) do
3785 if NetClients[I].Used then
3786 begin
3787 NetClients[I].Voted := False;
3788 if NetClients[I].RequestedFullUpdate then
3789 begin
3790 MH_SEND_Everything((NetClients[I].State = NET_STATE_AUTH), I);
3791 NetClients[I].RequestedFullUpdate := False;
3792 end;
3793 end;
3795 g_Net_UnbanNonPermHosts();
3796 end;
3798 if gLastMap then
3799 begin
3800 gCoopTotalMonstersKilled := 0;
3801 gCoopTotalSecretsFound := 0;
3802 gCoopTotalMonsters := 0;
3803 gCoopTotalSecrets := 0;
3804 gLastMap := False;
3805 end;
3807 g_Game_ExecuteEvent('onmapstart');
3808 end;
3810 procedure SetFirstLevel();
3811 begin
3812 gNextMap := '';
3814 MapList := g_Map_GetMapsList(MapsDir + gGameSettings.WAD);
3815 if MapList = nil then
3816 Exit;
3818 SortSArray(MapList);
3819 gNextMap := MapList[Low(MapList)];
3821 MapList := nil;
3822 end;
3824 procedure g_Game_ExitLevel(Map: Char16);
3825 begin
3826 gNextMap := Map;
3828 gCoopTotalMonstersKilled := gCoopTotalMonstersKilled + gCoopMonstersKilled;
3829 gCoopTotalSecretsFound := gCoopTotalSecretsFound + gCoopSecretsFound;
3830 gCoopTotalMonsters := gCoopTotalMonsters + gTotalMonsters;
3831 gCoopTotalSecrets := gCoopTotalSecrets + gSecretsCount;
3833 // Âûøëè â âûõîä â Îäèíî÷íîé èãðå:
3834 if gGameSettings.GameType = GT_SINGLE then
3835 gExit := EXIT_ENDLEVELSINGLE
3836 else // Âûøëè â âûõîä â Ñâîåé èãðå
3837 begin
3838 gExit := EXIT_ENDLEVELCUSTOM;
3839 if gGameSettings.GameMode = GM_COOP then
3840 g_Player_RememberAll;
3842 if not g_Map_Exist(MapsDir + gGameSettings.WAD + ':\' + gNextMap) then
3843 begin
3844 gLastMap := True;
3845 if gGameSettings.GameMode = GM_COOP then
3846 gStatsOff := True;
3848 gStatsPressed := True;
3849 gNextMap := 'MAP01';
3851 if not g_Map_Exist(MapsDir + gGameSettings.WAD + ':\' + gNextMap) then
3852 g_Game_NextLevel;
3854 if g_Game_IsNet then
3855 begin
3856 MH_SEND_GameStats();
3857 MH_SEND_CoopStats();
3858 end;
3859 end;
3860 end;
3861 end;
3863 procedure g_Game_RestartLevel();
3864 var
3865 Map: string;
3866 begin
3867 if gGameSettings.GameMode = GM_SINGLE then
3868 begin
3869 g_Game_Restart();
3870 Exit;
3871 end;
3872 gExit := EXIT_ENDLEVELCUSTOM;
3873 g_ProcessResourceStr(gMapInfo.Map, nil, nil, @Map);
3874 gNextMap := Map;
3875 end;
3877 procedure g_Game_ClientWAD(NewWAD: String; WHash: TMD5Digest);
3878 var
3879 gWAD: String;
3880 begin
3881 if LowerCase(NewWAD) = LowerCase(gGameSettings.WAD) then
3882 Exit;
3883 if not g_Game_IsClient then
3884 Exit;
3885 gWAD := g_Res_SearchSameWAD(MapsDir, ExtractFileName(NewWAD), WHash);
3886 if gWAD = '' then
3887 begin
3888 g_Game_SetLoadingText(_lc[I_LOAD_DL_RES], 0, False);
3889 gWAD := g_Res_DownloadWAD(ExtractFileName(NewWAD));
3890 if gWAD = '' then
3891 begin
3892 g_Game_Free();
3893 g_FatalError(Format(_lc[I_GAME_ERROR_MAP_WAD], [ExtractFileName(NewWAD)]));
3894 Exit;
3895 end;
3896 end;
3897 NewWAD := ExtractRelativePath(MapsDir, gWAD);
3898 g_Game_LoadWAD(NewWAD);
3899 end;
3901 procedure g_Game_RestartRound(NoMapRestart: Boolean = False);
3902 var
3903 i, n, nb, nr: Integer;
3904 begin
3905 if not g_Game_IsServer then Exit;
3906 if gLMSRespawn = LMS_RESPAWN_NONE then Exit;
3907 gLMSRespawn := LMS_RESPAWN_NONE;
3908 gLMSRespawnTime := 0;
3909 MessageTime := 0;
3911 if (gGameSettings.GameMode = GM_COOP) and not NoMapRestart then
3912 begin
3913 gMissionFailed := True;
3914 g_Game_RestartLevel;
3915 Exit;
3916 end;
3918 n := 0; nb := 0; nr := 0;
3919 for i := Low(gPlayers) to High(gPlayers) do
3920 if (gPlayers[i] <> nil) and
3921 ((not gPlayers[i].FSpectator) or gPlayers[i].FWantsInGame or
3922 (gPlayers[i] is TBot)) then
3923 begin
3924 Inc(n);
3925 if gPlayers[i].Team = TEAM_RED then Inc(nr)
3926 else if gPlayers[i].Team = TEAM_BLUE then Inc(nb)
3927 end;
3929 if (n < 2) or ((gGameSettings.GameMode = GM_TDM) and ((nr = 0) or (nb = 0))) then
3930 begin
3931 // wait a second until the fuckers finally decide to join
3932 gLMSRespawn := LMS_RESPAWN_WARMUP;
3933 gLMSRespawnTime := gTime + 1000;
3934 gLMSSoftSpawn := NoMapRestart;
3935 Exit;
3936 end;
3938 g_Player_RemoveAllCorpses;
3939 g_Game_Message(_lc[I_MESSAGE_LMS_START], 144);
3940 if g_Game_IsNet then
3941 MH_SEND_GameEvent(NET_EV_LMS_START);
3943 for i := Low(gPlayers) to High(gPlayers) do
3944 begin
3945 if gPlayers[i] = nil then continue;
3946 if gPlayers[i] is TBot then gPlayers[i].FWantsInGame := True;
3947 // don't touch normal spectators
3948 if gPlayers[i].FSpectator and not gPlayers[i].FWantsInGame then
3949 begin
3950 gPlayers[i].FNoRespawn := True;
3951 gPlayers[i].Lives := 0;
3952 if g_Game_IsNet then
3953 MH_SEND_PlayerStats(gPlayers[I].UID);
3954 continue;
3955 end;
3956 gPlayers[i].FNoRespawn := False;
3957 gPlayers[i].Lives := gGameSettings.MaxLives;
3958 gPlayers[i].Respawn(False, True);
3959 if gGameSettings.GameMode = GM_COOP then
3960 begin
3961 gPlayers[i].Frags := 0;
3962 gPlayers[i].RecallState;
3963 end;
3964 if (gPlayer1 = nil) and (gLMSPID1 > 0) then
3965 gPlayer1 := g_Player_Get(gLMSPID1);
3966 if (gPlayer2 = nil) and (gLMSPID2 > 0) then
3967 gPlayer2 := g_Player_Get(gLMSPID2);
3968 end;
3970 for i := Low(gItems) to High(gItems) do
3971 begin
3972 if gItems[i].Respawnable then
3973 begin
3974 gItems[i].QuietRespawn := True;
3975 gItems[i].RespawnTime := 0;
3976 end
3977 else
3978 begin
3979 g_Items_Remove(i);
3980 if g_Game_IsNet then MH_SEND_ItemDestroy(True, i);
3981 end;
3982 end;
3984 for i := Low(gMonsters) to High(gMonsters) do
3985 begin
3986 if (gMonsters[i] <> nil) and not gMonsters[i].FNoRespawn then
3987 gMonsters[i].Respawn;
3988 end;
3990 gLMSSoftSpawn := False;
3991 end;
3993 function g_Game_GetFirstMap(WAD: String): String;
3994 begin
3995 Result := '';
3997 MapList := g_Map_GetMapsList(WAD);
3998 if MapList = nil then
3999 Exit;
4001 SortSArray(MapList);
4002 Result := MapList[Low(MapList)];
4004 if not g_Map_Exist(WAD + ':\' + Result) then
4005 Result := '';
4007 MapList := nil;
4008 end;
4010 function g_Game_GetNextMap(): String;
4011 var
4012 I: Integer;
4013 Map: string;
4014 begin
4015 Result := '';
4017 MapList := g_Map_GetMapsList(MapsDir + gGameSettings.WAD);
4018 if MapList = nil then
4019 Exit;
4021 g_ProcessResourceStr(gMapInfo.Map, nil, nil, @Map);
4023 SortSArray(MapList);
4024 MapIndex := -255;
4025 for I := Low(MapList) to High(MapList) do
4026 if Map = MapList[I] then
4027 begin
4028 MapIndex := I;
4029 Break;
4030 end;
4032 if MapIndex <> -255 then
4033 begin
4034 if MapIndex = High(MapList) then
4035 Result := MapList[Low(MapList)]
4036 else
4037 Result := MapList[MapIndex + 1];
4039 if not g_Map_Exist(MapsDir + gGameSettings.WAD + ':\' + Result) then Result := Map;
4040 end;
4042 MapList := nil;
4043 end;
4045 procedure g_Game_NextLevel();
4046 begin
4047 if gGameSettings.GameMode in [GM_DM, GM_TDM, GM_CTF, GM_COOP] then
4048 gExit := EXIT_ENDLEVELCUSTOM
4049 else
4050 begin
4051 gExit := EXIT_ENDLEVELSINGLE;
4052 Exit;
4053 end;
4055 if gNextMap <> '' then Exit;
4056 gNextMap := g_Game_GetNextMap();
4057 end;
4059 function g_Game_IsTestMap(): Boolean;
4060 var
4061 FName, Sect, Res: String;
4062 begin
4063 g_ProcessResourceStr(gMapInfo.Map, FName, Sect, Res);
4064 Result := UpperCase(Res) = TEST_MAP_NAME;
4065 end;
4067 procedure g_Game_DeleteTestMap();
4068 var
4069 a: Integer;
4070 MapName: Char16;
4071 WadName: string;
4073 WAD: TWADEditor_1;
4074 MapList: SArray;
4075 time: Integer;
4077 begin
4078 a := Pos('.wad:\', gMapToDelete);
4079 if a = 0 then
4080 Exit;
4082 // Âûäåëÿåì èìÿ wad-ôàéëà è èìÿ êàðòû:
4083 WadName := Copy(gMapToDelete, 1, a + 3);
4084 Delete(gMapToDelete, 1, a + 5);
4085 gMapToDelete := UpperCase(gMapToDelete);
4086 MapName := '';
4087 CopyMemory(@MapName[0], @gMapToDelete[1], Min(16, Length(gMapToDelete)));
4090 // Èìÿ êàðòû íå ñòàíäàðòíîå òåñòîâîå:
4091 if MapName <> TEST_MAP_NAME then
4092 Exit;
4094 if not gTempDelete then
4095 begin
4096 time := g_GetFileTime(WadName);
4097 WAD := TWADEditor_1.Create();
4099 // ×èòàåì Wad-ôàéë:
4100 if not WAD.ReadFile(WadName) then
4101 begin // Íåò òàêîãî WAD-ôàéëà
4102 WAD.Free();
4103 Exit;
4104 end;
4106 // Ñîñòàâëÿåì ñïèñîê êàðò è èùåì íóæíóþ:
4107 WAD.CreateImage();
4108 MapList := WAD.GetResourcesList('');
4110 if MapList <> nil then
4111 for a := 0 to High(MapList) do
4112 if MapList[a] = MapName then
4113 begin
4114 // Óäàëÿåì è ñîõðàíÿåì:
4115 WAD.RemoveResource('', MapName);
4116 WAD.SaveTo(WadName);
4117 Break;
4118 end;
4120 WAD.Free();
4121 g_SetFileTime(WadName, time);
4122 end else
4124 if gTempDelete then DeleteFile(WadName);
4125 end;
4127 procedure GameCVars(P: SArray);
4128 var
4129 a, b: Integer;
4130 stat: TPlayerStatArray;
4131 cmd, s: string;
4132 config: TConfig;
4133 begin
4134 stat := nil;
4135 cmd := LowerCase(P[0]);
4136 if cmd = 'r_showfps' then
4137 begin
4138 if (Length(P) > 1) and
4139 ((P[1] = '1') or (P[1] = '0')) then
4140 gShowFPS := (P[1][1] = '1');
4142 if gShowFPS then
4143 g_Console_Add(_lc[I_MSG_SHOW_FPS_ON])
4144 else
4145 g_Console_Add(_lc[I_MSG_SHOW_FPS_OFF]);
4146 end
4147 else if (cmd = 'g_friendlyfire') and not g_Game_IsClient then
4148 begin
4149 with gGameSettings do
4150 begin
4151 if (Length(P) > 1) and
4152 ((P[1] = '1') or (P[1] = '0')) then
4153 begin
4154 if (P[1][1] = '1') then
4155 Options := Options or GAME_OPTION_TEAMDAMAGE
4156 else
4157 Options := Options and (not GAME_OPTION_TEAMDAMAGE);
4158 end;
4160 if (LongBool(Options and GAME_OPTION_TEAMDAMAGE)) then
4161 g_Console_Add(_lc[I_MSG_FRIENDLY_FIRE_ON])
4162 else
4163 g_Console_Add(_lc[I_MSG_FRIENDLY_FIRE_OFF]);
4165 if g_Game_IsNet then MH_SEND_GameSettings;
4166 end;
4167 end
4168 else if (cmd = 'g_weaponstay') and not g_Game_IsClient then
4169 begin
4170 with gGameSettings do
4171 begin
4172 if (Length(P) > 1) and
4173 ((P[1] = '1') or (P[1] = '0')) then
4174 begin
4175 if (P[1][1] = '1') then
4176 Options := Options or GAME_OPTION_WEAPONSTAY
4177 else
4178 Options := Options and (not GAME_OPTION_WEAPONSTAY);
4179 end;
4181 if (LongBool(Options and GAME_OPTION_WEAPONSTAY)) then
4182 g_Console_Add(_lc[I_MSG_WEAPONSTAY_ON])
4183 else
4184 g_Console_Add(_lc[I_MSG_WEAPONSTAY_OFF]);
4186 if g_Game_IsNet then MH_SEND_GameSettings;
4187 end;
4188 end
4189 else if cmd = 'g_gamemode' then
4190 begin
4191 a := g_Game_TextToMode(P[1]);
4192 if a = GM_SINGLE then a := GM_COOP;
4193 if (Length(P) > 1) and (a <> GM_NONE) and (not g_Game_IsClient) then
4194 begin
4195 gSwitchGameMode := a;
4196 if (gGameOn and (gGameSettings.GameMode = GM_SINGLE)) or
4197 (gState = STATE_INTERSINGLE) then
4198 gSwitchGameMode := GM_SINGLE;
4199 if not gGameOn then
4200 gGameSettings.GameMode := gSwitchGameMode;
4201 end;
4202 if gSwitchGameMode = gGameSettings.GameMode then
4203 g_Console_Add(Format(_lc[I_MSG_GAMEMODE_CURRENT],
4204 [g_Game_ModeToText(gGameSettings.GameMode)]))
4205 else
4206 g_Console_Add(Format(_lc[I_MSG_GAMEMODE_CHANGE],
4207 [g_Game_ModeToText(gGameSettings.GameMode),
4208 g_Game_ModeToText(gSwitchGameMode)]));
4209 end
4210 else if (cmd = 'g_allow_exit') and not g_Game_IsClient then
4211 begin
4212 with gGameSettings do
4213 begin
4214 if (Length(P) > 1) and
4215 ((P[1] = '1') or (P[1] = '0')) then
4216 begin
4217 if (P[1][1] = '1') then
4218 Options := Options or GAME_OPTION_ALLOWEXIT
4219 else
4220 Options := Options and (not GAME_OPTION_ALLOWEXIT);
4221 end;
4223 if (LongBool(Options and GAME_OPTION_ALLOWEXIT)) then
4224 g_Console_Add(_lc[I_MSG_ALLOWEXIT_ON])
4225 else
4226 g_Console_Add(_lc[I_MSG_ALLOWEXIT_OFF]);
4227 g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
4229 if g_Game_IsNet then MH_SEND_GameSettings;
4230 end;
4231 end
4232 else if (cmd = 'g_allow_monsters') and not g_Game_IsClient then
4233 begin
4234 with gGameSettings do
4235 begin
4236 if (Length(P) > 1) and
4237 ((P[1] = '1') or (P[1] = '0')) then
4238 begin
4239 if (P[1][1] = '1') then
4240 Options := Options or GAME_OPTION_MONSTERS
4241 else
4242 Options := Options and (not GAME_OPTION_MONSTERS);
4243 end;
4245 if (LongBool(Options and GAME_OPTION_MONSTERS)) then
4246 g_Console_Add(_lc[I_MSG_ALLOWMON_ON])
4247 else
4248 g_Console_Add(_lc[I_MSG_ALLOWMON_OFF]);
4249 g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
4251 if g_Game_IsNet then MH_SEND_GameSettings;
4252 end;
4253 end
4254 else if (cmd = 'g_bot_vsplayers') and not g_Game_IsClient then
4255 begin
4256 with gGameSettings do
4257 begin
4258 if (Length(P) > 1) and
4259 ((P[1] = '1') or (P[1] = '0')) then
4260 begin
4261 if (P[1][1] = '1') then
4262 Options := Options or GAME_OPTION_BOTVSPLAYER
4263 else
4264 Options := Options and (not GAME_OPTION_BOTVSPLAYER);
4265 end;
4267 if (LongBool(Options and GAME_OPTION_BOTVSPLAYER)) then
4268 g_Console_Add(_lc[I_MSG_BOTSVSPLAYERS_ON])
4269 else
4270 g_Console_Add(_lc[I_MSG_BOTSVSPLAYERS_OFF]);
4272 if g_Game_IsNet then MH_SEND_GameSettings;
4273 end;
4274 end
4275 else if (cmd = 'g_bot_vsmonsters') and not g_Game_IsClient then
4276 begin
4277 with gGameSettings do
4278 begin
4279 if (Length(P) > 1) and
4280 ((P[1] = '1') or (P[1] = '0')) then
4281 begin
4282 if (P[1][1] = '1') then
4283 Options := Options or GAME_OPTION_BOTVSMONSTER
4284 else
4285 Options := Options and (not GAME_OPTION_BOTVSMONSTER);
4286 end;
4288 if (LongBool(Options and GAME_OPTION_BOTVSMONSTER)) then
4289 g_Console_Add(_lc[I_MSG_BOTSVSMONSTERS_ON])
4290 else
4291 g_Console_Add(_lc[I_MSG_BOTSVSMONSTERS_OFF]);
4293 if g_Game_IsNet then MH_SEND_GameSettings;
4294 end;
4295 end
4296 else if (cmd = 'g_warmuptime') and not g_Game_IsClient then
4297 begin
4298 if Length(P) > 1 then
4299 begin
4300 if StrToIntDef(P[1], gGameSettings.WarmupTime) = 0 then
4301 gGameSettings.WarmupTime := 30
4302 else
4303 gGameSettings.WarmupTime := StrToIntDef(P[1], gGameSettings.WarmupTime);
4304 end;
4306 g_Console_Add(Format(_lc[I_MSG_WARMUP],
4307 [gGameSettings.WarmupTime]));
4308 g_Console_Add(_lc[I_MSG_ONMAPCHANGE]);
4309 end
4310 else if cmd = 'net_interp' then
4311 begin
4312 if (Length(P) > 1) then
4313 NetInterpLevel := StrToIntDef(P[1], NetInterpLevel);
4315 g_Console_Add('net_interp = ' + IntToStr(NetInterpLevel));
4316 config := TConfig.CreateFile(GameDir+'/'+CONFIG_FILENAME);
4317 config.WriteInt('Client', 'InterpolationSteps', NetInterpLevel);
4318 config.SaveFile(GameDir+'/'+CONFIG_FILENAME);
4319 config.Free();
4320 end
4321 else if cmd = 'net_forceplayerupdate' then
4322 begin
4323 if (Length(P) > 1) and
4324 ((P[1] = '1') or (P[1] = '0')) then
4325 NetForcePlayerUpdate := (P[1][1] = '1');
4327 if NetForcePlayerUpdate then
4328 g_Console_Add('net_forceplayerupdate = 1')
4329 else
4330 g_Console_Add('net_forceplayerupdate = 0');
4331 config := TConfig.CreateFile(GameDir+'/'+CONFIG_FILENAME);
4332 config.WriteBool('Client', 'ForcePlayerUpdate', NetForcePlayerUpdate);
4333 config.SaveFile(GameDir+'/'+CONFIG_FILENAME);
4334 config.Free();
4335 end
4336 else if cmd = 'net_predictself' then
4337 begin
4338 if (Length(P) > 1) and
4339 ((P[1] = '1') or (P[1] = '0')) then
4340 NetPredictSelf := (P[1][1] = '1');
4342 if NetPredictSelf then
4343 g_Console_Add('net_predictself = 1')
4344 else
4345 g_Console_Add('net_predictself = 0');
4346 config := TConfig.CreateFile(GameDir+'/'+CONFIG_FILENAME);
4347 config.WriteBool('Client', 'PredictSelf', NetPredictSelf);
4348 config.SaveFile(GameDir+'/'+CONFIG_FILENAME);
4349 config.Free();
4350 end
4351 else if cmd = 'sv_name' then
4352 begin
4353 if (Length(P) > 1) and (Length(P[1]) > 0) then
4354 begin
4355 NetServerName := P[1];
4356 if Length(NetServerName) > 64 then
4357 SetLength(NetServerName, 64);
4358 if g_Game_IsServer and g_Game_IsNet and NetUseMaster then
4359 g_Net_Slist_Update;
4360 end;
4362 g_Console_Add(cmd + ' = "' + NetServerName + '"');
4363 end
4364 else if cmd = 'sv_passwd' then
4365 begin
4366 if (Length(P) > 1) and (Length(P[1]) > 0) then
4367 begin
4368 NetPassword := P[1];
4369 if Length(NetPassword) > 24 then
4370 SetLength(NetPassword, 24);
4371 if g_Game_IsServer and g_Game_IsNet and NetUseMaster then
4372 g_Net_Slist_Update;
4373 end;
4375 g_Console_Add(cmd + ' = "' + AnsiLowerCase(NetPassword) + '"');
4376 end
4377 else if cmd = 'sv_maxplrs' then
4378 begin
4379 if (Length(P) > 1) then
4380 begin
4381 NetMaxClients := Min(Max(StrToIntDef(P[1], NetMaxClients), 1), NET_MAXCLIENTS);
4382 if g_Game_IsServer and g_Game_IsNet then
4383 begin
4384 b := 0;
4385 for a := 0 to High(NetClients) do
4386 if NetClients[a].Used then
4387 begin
4388 Inc(b);
4389 if b > NetMaxClients then
4390 begin
4391 s := g_Player_Get(NetClients[a].Player).Name;
4392 enet_peer_disconnect(NetClients[a].Peer, NET_DISC_FULL);
4393 g_Console_Add(Format(_lc[I_PLAYER_KICK], [s]));
4394 MH_SEND_GameEvent(NET_EV_PLAYER_KICK, 0, s);
4395 end;
4396 end;
4397 if NetUseMaster then
4398 g_Net_Slist_Update;
4399 end;
4400 end;
4402 g_Console_Add(cmd + ' = ' + IntToStr(NetMaxClients));
4403 end
4404 else if cmd = 'sv_public' then
4405 begin
4406 if (Length(P) > 1) then
4407 begin
4408 NetUseMaster := StrToIntDef(P[1], Byte(NetUseMaster)) > 0;
4409 if g_Game_IsServer and g_Game_IsNet then
4410 if NetUseMaster then
4411 begin
4412 if NetMPeer = nil then
4413 if not g_Net_Slist_Connect() then
4414 g_Console_Add(_lc[I_NET_MSG_ERROR] + _lc[I_NET_SLIST_ERROR]);
4415 g_Net_Slist_Update();
4416 end
4417 else
4418 if NetMPeer <> nil then
4419 g_Net_Slist_Disconnect();
4420 end;
4422 g_Console_Add(cmd + ' = ' + IntToStr(Byte(NetUseMaster)));
4423 end
4424 else if cmd = 'sv_intertime' then
4425 begin
4426 if (Length(P) > 1) then
4427 gDefInterTime := Min(Max(StrToIntDef(P[1], gDefInterTime), -1), 120);
4429 g_Console_Add(cmd + ' = ' + IntToStr(gDefInterTime));
4430 end
4431 else if cmd = 'p1_name' then
4432 begin
4433 if (Length(P) > 1) and gGameOn then
4434 begin
4435 if g_Game_IsClient then
4436 begin
4437 gPlayer1Settings.Name := b_Text_Unformat(P[1]);
4438 MC_SEND_PlayerSettings;
4439 end
4440 else
4441 if gPlayer1 <> nil then
4442 begin
4443 gPlayer1.Name := b_Text_Unformat(P[1]);
4444 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer1.UID);
4445 end
4446 else
4447 gPlayer1Settings.Name := b_Text_Unformat(P[1]);
4448 end;
4449 end
4450 else if cmd = 'p2_name' then
4451 begin
4452 if (Length(P) > 1) and gGameOn then
4453 begin
4454 if g_Game_IsClient then
4455 begin
4456 gPlayer2Settings.Name := b_Text_Unformat(P[1]);
4457 MC_SEND_PlayerSettings;
4458 end
4459 else
4460 if gPlayer2 <> nil then
4461 begin
4462 gPlayer2.Name := b_Text_Unformat(P[1]);
4463 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer2.UID);
4464 end
4465 else
4466 gPlayer2Settings.Name := b_Text_Unformat(P[1]);
4467 end;
4468 end
4469 else if cmd = 'p1_color' then
4470 begin
4471 if Length(P) > 3 then
4472 if g_Game_IsClient then
4473 begin
4474 gPlayer1Settings.Color := _RGB(EnsureRange(StrToIntDef(P[1], 0), 0, 255),
4475 EnsureRange(StrToIntDef(P[2], 0), 0, 255),
4476 EnsureRange(StrToIntDef(P[3], 0), 0, 255));
4477 MC_SEND_PlayerSettings;
4478 end
4479 else
4480 if gPlayer1 <> nil then
4481 begin
4482 gPlayer1.Model.SetColor(EnsureRange(StrToIntDef(P[1], 0), 0, 255),
4483 EnsureRange(StrToIntDef(P[2], 0), 0, 255),
4484 EnsureRange(StrToIntDef(P[3], 0), 0, 255));
4485 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer1.UID);
4486 end
4487 else
4488 gPlayer1Settings.Color := _RGB(EnsureRange(StrToIntDef(P[1], 0), 0, 255),
4489 EnsureRange(StrToIntDef(P[2], 0), 0, 255),
4490 EnsureRange(StrToIntDef(P[3], 0), 0, 255));
4491 end
4492 else if (cmd = 'p2_color') and not g_Game_IsNet then
4493 begin
4494 if Length(P) > 3 then
4495 if g_Game_IsClient then
4496 begin
4497 gPlayer2Settings.Color := _RGB(EnsureRange(StrToIntDef(P[1], 0), 0, 255),
4498 EnsureRange(StrToIntDef(P[2], 0), 0, 255),
4499 EnsureRange(StrToIntDef(P[3], 0), 0, 255));
4500 MC_SEND_PlayerSettings;
4501 end
4502 else
4503 if gPlayer2 <> nil then
4504 begin
4505 gPlayer2.Model.SetColor(EnsureRange(StrToIntDef(P[1], 0), 0, 255),
4506 EnsureRange(StrToIntDef(P[2], 0), 0, 255),
4507 EnsureRange(StrToIntDef(P[3], 0), 0, 255));
4508 if g_Game_IsNet then MH_SEND_PlayerSettings(gPlayer2.UID);
4509 end
4510 else
4511 gPlayer2Settings.Color := _RGB(EnsureRange(StrToIntDef(P[1], 0), 0, 255),
4512 EnsureRange(StrToIntDef(P[2], 0), 0, 255),
4513 EnsureRange(StrToIntDef(P[3], 0), 0, 255));
4514 end
4515 else if gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT] then
4516 begin
4517 if cmd = 'r_showtime' then
4518 begin
4519 if (Length(P) > 1) and
4520 ((P[1] = '1') or (P[1] = '0')) then
4521 gShowTime := (P[1][1] = '1');
4523 if gShowTime then
4524 g_Console_Add(_lc[I_MSG_TIME_ON])
4525 else
4526 g_Console_Add(_lc[I_MSG_TIME_OFF]);
4527 end
4528 else if cmd = 'r_showscore' then
4529 begin
4530 if (Length(P) > 1) and
4531 ((P[1] = '1') or (P[1] = '0')) then
4532 gShowGoals := (P[1][1] = '1');
4534 if gShowGoals then
4535 g_Console_Add(_lc[I_MSG_SCORE_ON])
4536 else
4537 g_Console_Add(_lc[I_MSG_SCORE_OFF]);
4538 end
4539 else if cmd = 'r_showstat' then
4540 begin
4541 if (Length(P) > 1) and
4542 ((P[1] = '1') or (P[1] = '0')) then
4543 gShowStat := (P[1][1] = '1');
4545 if gShowStat then
4546 g_Console_Add(_lc[I_MSG_STATS_ON])
4547 else
4548 g_Console_Add(_lc[I_MSG_STATS_OFF]);
4549 end
4550 else if cmd = 'r_showkillmsg' then
4551 begin
4552 if (Length(P) > 1) and
4553 ((P[1] = '1') or (P[1] = '0')) then
4554 gShowKillMsg := (P[1][1] = '1');
4556 if gShowKillMsg then
4557 g_Console_Add(_lc[I_MSG_KILL_MSGS_ON])
4558 else
4559 g_Console_Add(_lc[I_MSG_KILL_MSGS_OFF]);
4560 end
4561 else if cmd = 'r_showlives' then
4562 begin
4563 if (Length(P) > 1) and
4564 ((P[1] = '1') or (P[1] = '0')) then
4565 gShowLives := (P[1][1] = '1');
4567 if gShowLives then
4568 g_Console_Add(_lc[I_MSG_LIVES_ON])
4569 else
4570 g_Console_Add(_lc[I_MSG_LIVES_OFF]);
4571 end
4572 else if cmd = 'r_showspect' then
4573 begin
4574 if (Length(P) > 1) and
4575 ((P[1] = '1') or (P[1] = '0')) then
4576 gSpectHUD := (P[1][1] = '1');
4578 if gSpectHUD then
4579 g_Console_Add(_lc[I_MSG_SPECT_HUD_ON])
4580 else
4581 g_Console_Add(_lc[I_MSG_SPECT_HUD_OFF]);
4582 end
4583 else if cmd = 'r_showping' then
4584 begin
4585 if (Length(P) > 1) and
4586 ((P[1] = '1') or (P[1] = '0')) then
4587 gShowPing := (P[1][1] = '1');
4589 if gShowPing then
4590 g_Console_Add(_lc[I_MSG_PING_ON])
4591 else
4592 g_Console_Add(_lc[I_MSG_PING_OFF]);
4593 end
4594 else if (cmd = 'g_scorelimit') and not g_Game_IsClient then
4595 begin
4596 if Length(P) > 1 then
4597 begin
4598 if StrToIntDef(P[1], gGameSettings.GoalLimit) = 0 then
4599 gGameSettings.GoalLimit := 0
4600 else
4601 begin
4602 b := 0;
4604 if gGameSettings.GameMode = GM_DM then
4605 begin // DM
4606 stat := g_Player_GetStats();
4607 if stat <> nil then
4608 for a := 0 to High(stat) do
4609 if stat[a].Frags > b then
4610 b := stat[a].Frags;
4611 end
4612 else // TDM/CTF
4613 b := Max(gTeamStat[TEAM_RED].Goals, gTeamStat[TEAM_BLUE].Goals);
4615 gGameSettings.GoalLimit := Max(StrToIntDef(P[1], gGameSettings.GoalLimit), b);
4616 end;
4618 if g_Game_IsNet then MH_SEND_GameSettings;
4619 end;
4621 g_Console_Add(Format(_lc[I_MSG_SCORE_LIMIT], [gGameSettings.GoalLimit]));
4622 end
4623 else if (cmd = 'g_timelimit') and not g_Game_IsClient then
4624 begin
4625 if (Length(P) > 1) and (StrToIntDef(P[1], -1) >= 0) then
4626 gGameSettings.TimeLimit := StrToIntDef(P[1], -1);
4628 g_Console_Add(Format(_lc[I_MSG_TIME_LIMIT],
4629 [gGameSettings.TimeLimit div 3600,
4630 (gGameSettings.TimeLimit div 60) mod 60,
4631 gGameSettings.TimeLimit mod 60]));
4632 if g_Game_IsNet then MH_SEND_GameSettings;
4633 end
4634 else if (cmd = 'g_maxlives') and not g_Game_IsClient then
4635 begin
4636 if Length(P) > 1 then
4637 begin
4638 if StrToIntDef(P[1], gGameSettings.MaxLives) = 0 then
4639 gGameSettings.MaxLives := 0
4640 else
4641 begin
4642 b := 0;
4643 stat := g_Player_GetStats();
4644 if stat <> nil then
4645 for a := 0 to High(stat) do
4646 if stat[a].Lives > b then
4647 b := stat[a].Lives;
4648 gGameSettings.MaxLives :=
4649 Max(StrToIntDef(P[1], gGameSettings.MaxLives), b);
4650 end;
4651 end;
4653 g_Console_Add(Format(_lc[I_MSG_LIVES],
4654 [gGameSettings.MaxLives]));
4655 if g_Game_IsNet then MH_SEND_GameSettings;
4656 end;
4657 end;
4658 end;
4660 procedure DebugCommands(P: SArray);
4661 var
4662 a, b: Integer;
4663 cmd: string;
4664 //pt: TPoint;
4665 begin
4666 // Êîìàíäû îòëàäî÷íîãî ðåæèìà:
4667 if gDebugMode then
4668 begin
4669 cmd := LowerCase(P[0]);
4670 if cmd = 'd_window' then
4671 begin
4672 g_Console_Add(Format('gWinPosX = %d, gWinPosY %d', [gWinPosX, gWinPosY]));
4673 g_Console_Add(Format('gWinRealPosX = %d, gWinRealPosY %d', [gWinRealPosX, gWinRealPosY]));
4674 g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth, gScreenHeight]));
4675 g_Console_Add(Format('gWinSizeX = %d, gWinSizeY = %d', [gWinSizeX, gWinSizeY]));
4676 g_Console_Add(Format('Frame X = %d, Y = %d, Caption Y = %d', [gWinFrameX, gWinFrameY, gWinCaption]));
4677 end
4678 else if cmd = 'd_sounds' then
4679 begin
4680 if (Length(P) > 1) and
4681 ((P[1] = '1') or (P[1] = '0')) then
4682 g_Debug_Sounds := (P[1][1] = '1');
4684 g_Console_Add(Format('d_sounds is %d', [Byte(g_Debug_Sounds)]));
4685 end
4686 else if cmd = 'd_frames' then
4687 begin
4688 if (Length(P) > 1) and
4689 ((P[1] = '1') or (P[1] = '0')) then
4690 g_Debug_Frames := (P[1][1] = '1');
4692 g_Console_Add(Format('d_frames is %d', [Byte(g_Debug_Frames)]));
4693 end
4694 else if cmd = 'd_winmsg' then
4695 begin
4696 if (Length(P) > 1) and
4697 ((P[1] = '1') or (P[1] = '0')) then
4698 g_Debug_WinMsgs := (P[1][1] = '1');
4700 g_Console_Add(Format('d_winmsg is %d', [Byte(g_Debug_WinMsgs)]));
4701 end
4702 else if (cmd = 'd_monoff') and not g_Game_IsNet then
4703 begin
4704 if (Length(P) > 1) and
4705 ((P[1] = '1') or (P[1] = '0')) then
4706 g_Debug_MonsterOff := (P[1][1] = '1');
4708 g_Console_Add(Format('d_monoff is %d', [Byte(g_debug_MonsterOff)]));
4709 end
4710 else if (cmd = 'd_botoff') and not g_Game_IsNet then
4711 begin
4712 if Length(P) > 1 then
4713 case P[1][1] of
4714 '0': g_debug_BotAIOff := 0;
4715 '1': g_debug_BotAIOff := 1;
4716 '2': g_debug_BotAIOff := 2;
4717 '3': g_debug_BotAIOff := 3;
4718 end;
4720 g_Console_Add(Format('d_botoff is %d', [g_debug_BotAIOff]));
4721 end
4722 else if cmd = 'd_monster' then
4723 begin
4724 if gGameOn and (gPlayer1 <> nil) and (gPlayer1.Live) and (not g_Game_IsNet) then
4725 if Length(P) < 2 then
4726 begin
4727 g_Console_Add(cmd + ' [ID | Name] [behaviour]');
4728 g_Console_Add('ID | Name');
4729 for b := MONSTER_DEMON to MONSTER_MAN do
4730 g_Console_Add(Format('%2d | %s', [b, g_Monsters_GetNameByID(b)]));
4731 end else
4732 begin
4733 a := StrToIntDef(P[1], 0);
4734 if (a < MONSTER_DEMON) or (a > MONSTER_MAN) then
4735 a := g_Monsters_GetIDByName(P[1]);
4737 if (a < MONSTER_DEMON) or (a > MONSTER_MAN) then
4738 g_Console_Add(Format(_lc[I_MSG_NO_MONSTER], [P[1]]))
4739 else
4740 begin
4741 with gPlayer1.Obj do
4742 b := g_Monsters_Create(a,
4743 X + Rect.X + (Rect.Width div 2),
4744 Y + Rect.Y + Rect.Height,
4745 gPlayer1.Direction, True);
4746 if (Length(P) > 2) and (b >= 0) then
4747 gMonsters[b].MonsterBehaviour := Min(Max(StrToIntDef(P[2], BH_NORMAL), BH_NORMAL), BH_GOOD);
4748 end;
4749 end;
4750 end
4751 else if (cmd = 'd_health') then
4752 begin
4753 if (Length(P) > 1) and
4754 ((P[1] = '1') or (P[1] = '0')) then
4755 g_debug_HealthBar := (P[1][1] = '1');
4757 g_Console_Add(Format('d_health is %d', [Byte(g_debug_HealthBar)]));
4758 end
4759 else if (cmd = 'd_player') then
4760 begin
4761 if (Length(P) > 1) and
4762 ((P[1] = '1') or (P[1] = '0')) then
4763 g_debug_Player := (P[1][1] = '1');
4765 g_Console_Add(Format(cmd + ' is %d', [Byte(g_Debug_Player)]));
4766 end
4767 else if (cmd = 'd_joy') then
4768 begin
4769 for a := 1 to 8 do
4770 g_Console_Add(e_JoystickStateToString(a));
4771 end;
4772 end
4773 else
4774 g_Console_Add(_lc[I_MSG_NOT_DEBUG]);
4775 end;
4777 procedure GameCommands(P: SArray);
4778 var
4779 a, b: Integer;
4780 s, pw: String;
4781 chstr: string;
4782 cmd: string;
4783 pl: pTNetClient = nil;
4784 plr: TPlayer;
4785 prt: Word;
4786 nm: Boolean;
4787 listen: LongWord;
4788 begin
4789 // Îáùèå êîìàíäû:
4790 cmd := LowerCase(P[0]);
4791 chstr := '';
4792 if (cmd = 'quit') or
4793 (cmd = 'exit') then
4794 begin
4795 g_Game_Free();
4796 g_Game_Quit();
4797 Exit;
4798 end
4799 else if cmd = 'pause' then
4800 begin
4801 if (g_ActiveWindow = nil) then
4802 g_Game_Pause(not gPause);
4803 end
4804 else if cmd = 'endgame' then
4805 gExit := EXIT_SIMPLE
4806 else if cmd = 'restart' then
4807 begin
4808 if gGameOn or (gState in [STATE_INTERSINGLE, STATE_INTERCUSTOM]) then
4809 begin
4810 if g_Game_IsClient then
4811 begin
4812 g_Console_Add(_lc[I_MSG_SERVERONLY]);
4813 Exit;
4814 end;
4815 g_Game_Restart();
4816 end else
4817 g_Console_Add(_lc[I_MSG_NOT_GAME]);
4818 end
4819 else if cmd = 'kick' then
4820 begin
4821 if g_Game_IsServer then
4822 begin
4823 if Length(P) < 2 then
4824 begin
4825 g_Console_Add('kick <name>');
4826 Exit;
4827 end;
4828 if P[1] = '' then
4829 begin
4830 g_Console_Add('kick <name>');
4831 Exit;
4832 end;
4834 if g_Game_IsNet then
4835 pl := g_Net_Client_ByName(P[1]);
4836 if (pl <> nil) then
4837 begin
4838 s := g_Net_ClientName_ByID(pl^.ID);
4839 enet_peer_disconnect(pl^.Peer, NET_DISC_KICK);
4840 g_Console_Add(Format(_lc[I_PLAYER_KICK], [s]));
4841 MH_SEND_GameEvent(NET_EV_PLAYER_KICK, 0, s);
4842 if NetUseMaster then
4843 g_Net_Slist_Update;
4844 end else if gPlayers <> nil then
4845 for a := Low(gPlayers) to High(gPlayers) do
4846 if gPlayers[a] <> nil then
4847 if Copy(LowerCase(gPlayers[a].Name), 1, Length(P[1])) = LowerCase(P[1]) then
4848 begin
4849 // Íå îòêëþ÷àòü îñíîâíûõ èãðîêîâ â ñèíãëå
4850 if not(gPlayers[a] is TBot) and (gGameSettings.GameType = GT_SINGLE) then
4851 continue;
4852 gPlayers[a].Lives := 0;
4853 gPlayers[a].Kill(K_SIMPLEKILL, 0, HIT_DISCON);
4854 g_Console_Add(Format(_lc[I_PLAYER_LEAVE], [gPlayers[a].Name]), True);
4855 g_Player_Remove(gPlayers[a].UID);
4856 if NetUseMaster then
4857 g_Net_Slist_Update;
4858 // Åñëè íå ïåðåìåøàòü, ïðè äîáàâëåíèè íîâûõ áîòîâ ïîÿâÿòñÿ ñòàðûå
4859 g_Bot_MixNames();
4860 end;
4861 end else
4862 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
4863 end
4864 else if cmd = 'kick_id' then
4865 begin
4866 if g_Game_IsServer and g_Game_IsNet then
4867 begin
4868 if Length(P) < 2 then
4869 begin
4870 g_Console_Add('kick_id <client ID>');
4871 Exit;
4872 end;
4873 if P[1] = '' then
4874 begin
4875 g_Console_Add('kick_id <client ID>');
4876 Exit;
4877 end;
4879 a := StrToIntDef(P[1], 0);
4880 if (NetClients <> nil) and (a <= High(NetClients)) then
4881 begin
4882 if NetClients[a].Used and (NetClients[a].Peer <> nil) then
4883 begin
4884 s := g_Net_ClientName_ByID(NetClients[a].ID);
4885 enet_peer_disconnect(NetClients[a].Peer, NET_DISC_KICK);
4886 g_Console_Add(Format(_lc[I_PLAYER_KICK], [s]));
4887 MH_SEND_GameEvent(NET_EV_PLAYER_KICK, 0, s);
4888 if NetUseMaster then
4889 g_Net_Slist_Update;
4890 end;
4891 end;
4892 end else
4893 g_Console_Add(_lc[I_MSG_SERVERONLY]);
4894 end
4895 else if cmd = 'ban' then
4896 begin
4897 if g_Game_IsServer and g_Game_IsNet then
4898 begin
4899 if Length(P) < 2 then
4900 begin
4901 g_Console_Add('ban <name>');
4902 Exit;
4903 end;
4904 if P[1] = '' then
4905 begin
4906 g_Console_Add('ban <name>');
4907 Exit;
4908 end;
4910 pl := g_Net_Client_ByName(P[1]);
4911 if (pl <> nil) then
4912 begin
4913 s := g_Net_ClientName_ByID(pl^.ID);
4914 g_Net_BanHost(pl^.Peer^.address.host, False);
4915 enet_peer_disconnect(pl^.Peer, NET_DISC_TEMPBAN);
4916 g_Console_Add(Format(_lc[I_PLAYER_BAN], [s]));
4917 MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s);
4918 if NetUseMaster then
4919 g_Net_Slist_Update;
4920 end else
4921 g_Console_Add(Format(_lc[I_NET_ERR_NAME404], [P[1]]));
4922 end else
4923 g_Console_Add(_lc[I_MSG_SERVERONLY]);
4924 end
4925 else if cmd = 'ban_id' then
4926 begin
4927 if g_Game_IsServer and g_Game_IsNet then
4928 begin
4929 if Length(P) < 2 then
4930 begin
4931 g_Console_Add('ban_id <client ID>');
4932 Exit;
4933 end;
4934 if P[1] = '' then
4935 begin
4936 g_Console_Add('ban_id <client ID>');
4937 Exit;
4938 end;
4940 a := StrToIntDef(P[1], 0);
4941 if (NetClients <> nil) and (a <= High(NetClients)) then
4942 if NetClients[a].Used and (NetClients[a].Peer <> nil) then
4943 begin
4944 s := g_Net_ClientName_ByID(NetClients[a].ID);
4945 g_Net_BanHost(NetClients[a].Peer^.address.host, False);
4946 enet_peer_disconnect(NetClients[a].Peer, NET_DISC_TEMPBAN);
4947 g_Console_Add(Format(_lc[I_PLAYER_BAN], [s]));
4948 MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s);
4949 if NetUseMaster then
4950 g_Net_Slist_Update;
4951 end;
4952 end else
4953 g_Console_Add(_lc[I_MSG_SERVERONLY]);
4954 end
4955 else if cmd = 'permban' then
4956 begin
4957 if g_Game_IsServer and g_Game_IsNet then
4958 begin
4959 if Length(P) < 2 then
4960 begin
4961 g_Console_Add('permban <name>');
4962 Exit;
4963 end;
4964 if P[1] = '' then
4965 begin
4966 g_Console_Add('permban <name>');
4967 Exit;
4968 end;
4970 pl := g_Net_Client_ByName(P[1]);
4971 if (pl <> nil) then
4972 begin
4973 s := g_Net_ClientName_ByID(pl^.ID);
4974 g_Net_BanHost(pl^.Peer^.address.host);
4975 enet_peer_disconnect(pl^.Peer, NET_DISC_BAN);
4976 g_Net_SaveBanList();
4977 g_Console_Add(Format(_lc[I_PLAYER_BAN], [s]));
4978 MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s);
4979 if NetUseMaster then
4980 g_Net_Slist_Update;
4981 end else
4982 g_Console_Add(Format(_lc[I_NET_ERR_NAME404], [P[1]]));
4983 end else
4984 g_Console_Add(_lc[I_MSG_SERVERONLY]);
4985 end
4986 else if cmd = 'permban_id' then
4987 begin
4988 if g_Game_IsServer and g_Game_IsNet then
4989 begin
4990 if Length(P) < 2 then
4991 begin
4992 g_Console_Add('permban_id <client ID>');
4993 Exit;
4994 end;
4995 if P[1] = '' then
4996 begin
4997 g_Console_Add('permban_id <client ID>');
4998 Exit;
4999 end;
5001 a := StrToIntDef(P[1], 0);
5002 if (NetClients <> nil) and (a <= High(NetClients)) then
5003 if NetClients[a].Used and (NetClients[a].Peer <> nil) then
5004 begin
5005 s := g_Net_ClientName_ByID(NetClients[a].ID);
5006 g_Net_BanHost(NetClients[a].Peer^.address.host);
5007 enet_peer_disconnect(NetClients[a].Peer, NET_DISC_BAN);
5008 g_Net_SaveBanList();
5009 g_Console_Add(Format(_lc[I_PLAYER_BAN], [s]));
5010 MH_SEND_GameEvent(NET_EV_PLAYER_BAN, 0, s);
5011 if NetUseMaster then
5012 g_Net_Slist_Update;
5013 end;
5014 end else
5015 g_Console_Add(_lc[I_MSG_SERVERONLY]);
5016 end
5017 else if cmd = 'unban' then
5018 begin
5019 if g_Game_IsServer and g_Game_IsNet then
5020 begin
5021 if Length(P) < 2 then
5022 begin
5023 g_Console_Add('unban <IP Address>');
5024 Exit;
5025 end;
5026 if P[1] = '' then
5027 begin
5028 g_Console_Add('unban <IP Address>');
5029 Exit;
5030 end;
5032 if g_Net_UnbanHost(P[1]) then
5033 begin
5034 g_Console_Add(Format(_lc[I_MSG_UNBAN_OK], [P[1]]));
5035 g_Net_SaveBanList();
5036 end else
5037 g_Console_Add(Format(_lc[I_MSG_UNBAN_FAIL], [P[1]]));
5038 end else
5039 g_Console_Add(_lc[I_MSG_SERVERONLY]);
5040 end
5041 else if cmd = 'clientlist' then
5042 begin
5043 if g_Game_IsServer and g_Game_IsNet then
5044 begin
5045 b := 0;
5046 if NetClients <> nil then
5047 for a := Low(NetClients) to High(NetClients) do
5048 if NetClients[a].Used and (NetClients[a].Peer <> nil) then
5049 begin
5050 plr := g_Player_Get(NetClients[a].Player);
5051 if plr = nil then continue;
5052 Inc(b);
5053 g_Console_Add(Format('#%2d: %-15s | %s', [a,
5054 IpToStr(NetClients[a].Peer^.address.host), plr.Name]));
5055 end;
5056 if b = 0 then
5057 g_Console_Add(_lc[I_MSG_NOCLIENTS]);
5058 end else
5059 g_Console_Add(_lc[I_MSG_SERVERONLY]);
5060 end
5061 else if cmd = 'connect' then
5062 begin
5063 if (NetMode = NET_NONE) then
5064 begin
5065 if Length(P) < 2 then
5066 begin
5067 g_Console_Add('connect <IP> [port] [password]');
5068 Exit;
5069 end;
5070 if P[1] = '' then
5071 begin
5072 g_Console_Add('connect <IP> [port] [password]');
5073 Exit;
5074 end;
5076 if Length(P) > 2 then
5077 prt := StrToIntDef(P[2], 25666)
5078 else
5079 prt := 25666;
5081 if Length(P) > 3 then
5082 pw := P[3]
5083 else
5084 pw := '';
5086 g_Game_StartClient(P[1], prt, pw);
5087 end;
5088 end
5089 else if cmd = 'disconnect' then
5090 begin
5091 if (NetMode = NET_CLIENT) then
5092 g_Net_Disconnect();
5093 end
5094 else if cmd = 'reconnect' then
5095 begin
5096 if (NetMode = NET_SERVER) then
5097 Exit;
5099 if (NetMode = NET_CLIENT) then
5100 begin
5101 g_Net_Disconnect();
5102 gExit := EXIT_SIMPLE;
5103 EndGame;
5104 end;
5106 //TODO: Use last successful password to reconnect, instead of ''
5107 g_Game_StartClient(NetClientIP, NetClientPort, '');
5108 end
5109 else if (cmd = 'addbot') or
5110 (cmd = 'bot_add') then
5111 begin
5112 if Length(P) > 1 then
5113 g_Bot_Add(TEAM_NONE, StrToIntDef(P[1], 2))
5114 else
5115 g_Bot_Add(TEAM_NONE, 2);
5116 end
5117 else if cmd = 'bot_addlist' then
5118 begin
5119 if Length(P) > 1 then
5120 if Length(P) = 2 then
5121 g_Bot_AddList(TEAM_NONE, P[1], StrToIntDef(P[1], -1))
5122 else
5123 g_Bot_AddList(IfThen(P[2] = 'red', TEAM_RED, TEAM_BLUE), P[1], StrToIntDef(P[1], -1));
5124 end
5125 else if cmd = 'bot_removeall' then
5126 g_Bot_RemoveAll()
5127 else if cmd = 'chat' then
5128 begin
5129 if g_Game_IsNet then
5130 begin
5131 if Length(P) > 1 then
5132 begin
5133 for a := 1 to High(P) do
5134 chstr := chstr + P[a] + ' ';
5136 if Length(chstr) > 200 then SetLength(chstr, 200);
5138 if Length(chstr) < 1 then
5139 begin
5140 g_Console_Add('chat <text>');
5141 Exit;
5142 end;
5144 chstr := b_Text_Format(chstr);
5145 if g_Game_IsClient then
5146 MC_SEND_Chat(chstr, NET_CHAT_PLAYER)
5147 else
5148 MH_SEND_Chat(gPlayer1Settings.Name + ': ' + chstr, NET_CHAT_PLAYER);
5149 end
5150 else
5151 g_Console_Add('chat <text>');
5152 end else
5153 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
5154 end
5155 else if cmd = 'teamchat' then
5156 begin
5157 if g_Game_IsNet and (gGameSettings.GameMode in [GM_TDM, GM_CTF]) then
5158 begin
5159 if Length(P) > 1 then
5160 begin
5161 for a := 1 to High(P) do
5162 chstr := chstr + P[a] + ' ';
5164 if Length(chstr) > 200 then SetLength(chstr, 200);
5166 if Length(chstr) < 1 then
5167 begin
5168 g_Console_Add('teamchat <text>');
5169 Exit;
5170 end;
5172 chstr := b_Text_Format(chstr);
5173 if g_Game_IsClient then
5174 MC_SEND_Chat(chstr, NET_CHAT_TEAM)
5175 else
5176 MH_SEND_Chat(gPlayer1Settings.Name + ': ' + chstr, NET_CHAT_TEAM,
5177 gPlayer1Settings.Team);
5178 end
5179 else
5180 g_Console_Add('teamchat <text>');
5181 end else
5182 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
5183 end
5184 else if cmd = 'game' then
5185 begin
5186 if gGameSettings.GameType <> GT_NONE then
5187 begin
5188 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
5189 Exit;
5190 end;
5191 if Length(P) = 1 then
5192 begin
5193 g_Console_Add(cmd + ' <WAD> [MAP] [# players]');
5194 Exit;
5195 end;
5196 // Èãðà åù¸ íå çàïóùåíà, ñíà÷àëà íàì íàäî çàãðóçèòü êàêîé-òî WAD
5197 P[1] := addWadExtension(P[1]);
5198 if FileExists(MapsDir + P[1]) then
5199 begin
5200 // Åñëè êàðòà íå óêàçàíà, áåð¸ì ïåðâóþ êàðòó â ôàéëå
5201 if Length(P) < 3 then
5202 begin
5203 SetLength(P, 3);
5204 P[2] := g_Game_GetFirstMap(MapsDir + P[1]);
5205 end;
5207 s := P[1] + ':\' + UpperCase(P[2]);
5209 if g_Map_Exist(MapsDir + s) then
5210 begin
5211 // Çàïóñêàåì ñâîþ èãðó
5212 g_Game_Free();
5213 with gGameSettings do
5214 begin
5215 GameMode := g_Game_TextToMode(gcGameMode);
5216 if gSwitchGameMode <> GM_NONE then
5217 GameMode := gSwitchGameMode;
5218 if GameMode = GM_NONE then GameMode := GM_DM;
5219 if GameMode = GM_SINGLE then GameMode := GM_COOP;
5220 b := 1;
5221 if Length(P) >= 4 then
5222 b := StrToIntDef(P[3], 1);
5223 g_Game_StartCustom(s, GameMode, TimeLimit,
5224 GoalLimit, MaxLives, Options, b);
5225 end;
5226 end
5227 else
5228 if P[2] = '' then
5229 g_Console_Add(Format(_lc[I_MSG_NO_MAPS], [P[1]]))
5230 else
5231 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [UpperCase(P[2])]));
5232 end else
5233 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]));
5234 end
5235 else if cmd = 'host' then
5236 begin
5237 if gGameSettings.GameType <> GT_NONE then
5238 begin
5239 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
5240 Exit;
5241 end;
5242 if Length(P) < 4 then
5243 begin
5244 g_Console_Add(cmd + ' <listen IP> <port> <WAD> [MAP] [# players]');
5245 Exit;
5246 end;
5247 if not StrToIp(P[1], listen) then
5248 Exit;
5249 prt := StrToIntDef(P[2], 25666);
5251 P[3] := addWadExtension(P[3]);
5252 if FileExists(MapsDir + P[3]) then
5253 begin
5254 // Åñëè êàðòà íå óêàçàíà, áåð¸ì ïåðâóþ êàðòó â ôàéëå
5255 if Length(P) < 5 then
5256 begin
5257 SetLength(P, 5);
5258 P[4] := g_Game_GetFirstMap(MapsDir + P[1]);
5259 end;
5261 s := P[3] + ':\' + UpperCase(P[4]);
5263 if g_Map_Exist(MapsDir + s) then
5264 begin
5265 // Çàïóñêàåì ñâîþ èãðó
5266 g_Game_Free();
5267 with gGameSettings do
5268 begin
5269 GameMode := g_Game_TextToMode(gcGameMode);
5270 if gSwitchGameMode <> GM_NONE then
5271 GameMode := gSwitchGameMode;
5272 if GameMode = GM_NONE then GameMode := GM_DM;
5273 if GameMode = GM_SINGLE then GameMode := GM_COOP;
5274 b := 0;
5275 if Length(P) >= 6 then
5276 b := StrToIntDef(P[5], 0);
5277 g_Game_StartServer(s, GameMode, TimeLimit,
5278 GoalLimit, MaxLives, Options, b, listen, prt);
5279 end;
5280 end
5281 else
5282 if P[4] = '' then
5283 g_Console_Add(Format(_lc[I_MSG_NO_MAPS], [P[3]]))
5284 else
5285 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [UpperCase(P[4])]));
5286 end else
5287 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[3]]));
5288 end
5289 else if cmd = 'map' then
5290 begin
5291 if Length(P) = 1 then
5292 begin
5293 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
5294 begin
5295 g_Console_Add(cmd + ' <MAP>');
5296 g_Console_Add(cmd + ' <WAD> [MAP]');
5297 end else
5298 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
5299 end else
5300 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
5301 begin
5302 // Èä¸ò ñâîÿ èãðà èëè ñåðâåð
5303 if Length(P) < 3 then
5304 begin
5305 // Ïåðâûé ïàðàìåòð - ëèáî êàðòà, ëèáî èìÿ WAD ôàéëà
5306 s := UpperCase(P[1]);
5307 if g_Map_Exist(MapsDir + gGameSettings.WAD + ':\' + s) then
5308 begin // Êàðòà íàøëàñü
5309 gExitByTrigger := False;
5310 if gGameOn then
5311 begin // Èä¸ò èãðà - çàâåðøàåì óðîâåíü
5312 gNextMap := s;
5313 gExit := EXIT_ENDLEVELCUSTOM;
5314 end
5315 else // Èíòåðìèññèÿ - ñðàçó çàãðóæàåì êàðòó
5316 g_Game_ChangeMap(s);
5317 end else
5318 begin
5319 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [s]));
5320 // Òàêîé êàðòû íåò, èùåì WAD ôàéë
5321 P[1] := addWadExtension(P[1]);
5322 if FileExists(MapsDir + P[1]) then
5323 begin
5324 // Ïàðàìåòðà êàðòû íåò, ïîýòîìó ñòàâèì ïåðâóþ èç ôàéëà
5325 SetLength(P, 3);
5326 P[2] := g_Game_GetFirstMap(MapsDir + P[1]);
5328 s := P[1] + ':\' + P[2];
5330 if g_Map_Exist(MapsDir + s) then
5331 begin
5332 gExitByTrigger := False;
5333 if gGameOn then
5334 begin // Èä¸ò èãðà - çàâåðøàåì óðîâåíü
5335 gNextMap := s;
5336 gExit := EXIT_ENDLEVELCUSTOM;
5337 end
5338 else // Èíòåðìèññèÿ - ñðàçó çàãðóæàåì êàðòó
5339 g_Game_ChangeMap(s);
5340 end else
5341 if P[2] = '' then
5342 g_Console_Add(Format(_lc[I_MSG_NO_MAPS], [P[1]]))
5343 else
5344 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [P[2]]));
5345 end else
5346 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]));
5347 end;
5348 end else
5349 begin
5350 // Óêàçàíî äâà ïàðàìåòðà, çíà÷èò ïåðâûé - WAD ôàéë, à âòîðîé - êàðòà
5351 P[1] := addWadExtension(P[1]);
5352 if FileExists(MapsDir + P[1]) then
5353 begin
5354 // Íàøëè WAD ôàéë
5355 P[2] := UpperCase(P[2]);
5356 s := P[1] + ':\' + P[2];
5358 if g_Map_Exist(MapsDir + s) then
5359 begin // Íàøëè êàðòó
5360 gExitByTrigger := False;
5361 if gGameOn then
5362 begin // Èä¸ò èãðà - çàâåðøàåì óðîâåíü
5363 gNextMap := s;
5364 gExit := EXIT_ENDLEVELCUSTOM;
5365 end
5366 else // Èíòåðìèññèÿ - ñðàçó çàãðóæàåì êàðòó
5367 g_Game_ChangeMap(s);
5368 end else
5369 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [P[2]]));
5370 end else
5371 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]));
5372 end;
5373 end else
5374 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
5375 end
5376 else if cmd = 'nextmap' then
5377 begin
5378 if not(gGameOn or (gState = STATE_INTERCUSTOM)) then
5379 g_Console_Add(_lc[I_MSG_NOT_GAME])
5380 else begin
5381 nm := True;
5382 if Length(P) = 1 then
5383 begin
5384 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
5385 begin
5386 g_Console_Add(cmd + ' <MAP>');
5387 g_Console_Add(cmd + ' <WAD> [MAP]');
5388 end else begin
5389 nm := False;
5390 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
5391 end;
5392 end else
5393 begin
5394 nm := False;
5395 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
5396 begin
5397 if Length(P) < 3 then
5398 begin
5399 // Ïåðâûé ïàðàìåòð - ëèáî êàðòà, ëèáî èìÿ WAD ôàéëà
5400 s := UpperCase(P[1]);
5401 if g_Map_Exist(MapsDir + gGameSettings.WAD + ':\' + s) then
5402 begin // Êàðòà íàøëàñü
5403 gExitByTrigger := False;
5404 gNextMap := s;
5405 nm := True;
5406 end else
5407 begin
5408 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [s]));
5409 // Òàêîé êàðòû íåò, èùåì WAD ôàéë
5410 P[1] := addWadExtension(P[1]);
5411 if FileExists(MapsDir + P[1]) then
5412 begin
5413 // Ïàðàìåòðà êàðòû íåò, ïîýòîìó ñòàâèì ïåðâóþ èç ôàéëà
5414 SetLength(P, 3);
5415 P[2] := g_Game_GetFirstMap(MapsDir + P[1]);
5417 s := P[1] + ':\' + P[2];
5419 if g_Map_Exist(MapsDir + s) then
5420 begin // Óñòàíàâëèâàåì êàðòó
5421 gExitByTrigger := False;
5422 gNextMap := s;
5423 nm := True;
5424 end else
5425 if P[2] = '' then
5426 g_Console_Add(Format(_lc[I_MSG_NO_MAPS], [P[1]]))
5427 else
5428 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [P[2]]));
5429 end else
5430 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]));
5431 end;
5432 end else
5433 begin
5434 // Óêàçàíî äâà ïàðàìåòðà, çíà÷èò ïåðâûé - WAD ôàéë, à âòîðîé - êàðòà
5435 P[1] := addWadExtension(P[1]);
5436 if FileExists(MapsDir + P[1]) then
5437 begin
5438 // Íàøëè WAD ôàéë
5439 P[2] := UpperCase(P[2]);
5440 s := P[1] + ':\' + P[2];
5442 if g_Map_Exist(MapsDir + s) then
5443 begin // Íàøëè êàðòó
5444 gExitByTrigger := False;
5445 gNextMap := s;
5446 nm := True;
5447 end else
5448 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [P[2]]));
5449 end else
5450 g_Console_Add(Format(_lc[I_MSG_NO_WAD], [P[1]]));
5451 end;
5452 end else
5453 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
5454 end;
5455 if nm then
5456 if gNextMap = '' then
5457 g_Console_Add(_lc[I_MSG_NEXTMAP_UNSET])
5458 else
5459 g_Console_Add(Format(_lc[I_MSG_NEXTMAP_SET], [gNextMap]));
5460 end;
5461 end
5462 else if (cmd = 'endmap') or (cmd = 'goodbye') then
5463 begin
5464 if not gGameOn then
5465 g_Console_Add(_lc[I_MSG_NOT_GAME])
5466 else
5467 if g_Game_IsServer and (gGameSettings.GameType <> GT_SINGLE) then
5468 begin
5469 gExitByTrigger := False;
5470 // Ñëåäóþùàÿ êàðòà íå çàäàíà, ïðîáóåì íàéòè òðèããåð Âûõîä
5471 if (gNextMap = '') and (gTriggers <> nil) then
5472 for a := 0 to High(gTriggers) do
5473 if gTriggers[a].TriggerType = TRIGGER_EXIT then
5474 begin
5475 gExitByTrigger := True;
5476 gNextMap := gTriggers[a].Data.MapName;
5477 Break;
5478 end;
5479 // Èùåì ñëåäóþùóþ êàðòó â WAD ôàéëå
5480 if gNextMap = '' then
5481 gNextMap := g_Game_GetNextMap();
5482 // Ïðîâåðÿåì, íå çàäàí ëè WAD ôàéë ðåñóðñíîé ñòðîêîé
5483 if Pos(':\', gNextMap) = 0 then
5484 s := gGameSettings.WAD + ':\' + gNextMap
5485 else
5486 s := gNextMap;
5487 // Åñëè êàðòà íàéäåíà, âûõîäèì ñ óðîâíÿ
5488 if g_Map_Exist(MapsDir + s) then
5489 gExit := EXIT_ENDLEVELCUSTOM
5490 else
5491 g_Console_Add(Format(_lc[I_MSG_NO_MAP], [gNextMap]));
5492 end else
5493 g_Console_Add(_lc[I_MSG_GM_UNAVAIL]);
5494 end
5495 else if (cmd = 'event') then
5496 begin
5497 if (Length(P) <= 1) then
5498 begin
5499 for a := 0 to High(gEvents) do
5500 if gEvents[a].Command = '' then
5501 g_Console_Add(gEvents[a].Name + ' <none>')
5502 else
5503 g_Console_Add(gEvents[a].Name + ' "' + gEvents[a].Command + '"');
5504 Exit;
5505 end;
5506 if (Length(P) = 2) then
5507 begin
5508 for a := 0 to High(gEvents) do
5509 if gEvents[a].Name = P[1] then
5510 if gEvents[a].Command = '' then
5511 g_Console_Add(gEvents[a].Name + ' <none>')
5512 else
5513 g_Console_Add(gEvents[a].Name + ' "' + gEvents[a].Command + '"');
5514 Exit;
5515 end;
5516 for a := 0 to High(gEvents) do
5517 if gEvents[a].Name = P[1] then
5518 begin
5519 gEvents[a].Command := '';
5520 for b := 2 to High(P) do
5521 if Pos(' ', P[b]) = 0 then
5522 gEvents[a].Command := gEvents[a].Command + ' ' + P[b]
5523 else
5524 gEvents[a].Command := gEvents[a].Command + ' "' + P[b] + '"';
5525 gEvents[a].Command := Trim(gEvents[a].Command);
5526 Exit;
5527 end;
5528 end
5529 // Êîìàíäû Ñâîåé èãðû:
5530 else if gGameSettings.GameType in [GT_CUSTOM, GT_SERVER, GT_CLIENT] then
5531 begin
5532 if cmd = 'bot_addred' then
5533 begin
5534 if Length(P) > 1 then
5535 g_Bot_Add(TEAM_RED, StrToIntDef(P[1], 2))
5536 else
5537 g_Bot_Add(TEAM_RED, 2);
5538 end
5539 else if cmd = 'bot_addblue' then
5540 begin
5541 if Length(P) > 1 then
5542 g_Bot_Add(TEAM_BLUE, StrToIntDef(P[1], 2))
5543 else
5544 g_Bot_Add(TEAM_BLUE, 2);
5545 end
5546 else if cmd = 'suicide' then
5547 begin
5548 if gGameOn then
5549 begin
5550 if g_Game_IsClient then
5551 MC_SEND_CheatRequest(NET_CHEAT_SUICIDE)
5552 else
5553 begin
5554 if gPlayer1 <> nil then
5555 gPlayer1.Damage(SUICIDE_DAMAGE, gPlayer1.UID, 0, 0, HIT_SELF);
5556 if gPlayer2 <> nil then
5557 gPlayer2.Damage(SUICIDE_DAMAGE, gPlayer2.UID, 0, 0, HIT_SELF);
5558 end;
5559 end;
5560 end
5561 else if cmd = 'spectate' then
5562 begin
5563 if not gGameOn then
5564 Exit;
5565 g_Game_Spectate();
5566 end
5567 else if cmd = 'say' then
5568 begin
5569 if g_Game_IsServer and g_Game_IsNet then
5570 begin
5571 if Length(P) > 1 then
5572 begin
5573 chstr := '';
5574 for a := 1 to High(P) do
5575 chstr := chstr + P[a] + ' ';
5577 if Length(chstr) > 200 then SetLength(chstr, 200);
5579 if Length(chstr) < 1 then
5580 begin
5581 g_Console_Add('say <text>');
5582 Exit;
5583 end;
5585 chstr := b_Text_Format(chstr);
5586 MH_SEND_Chat(chstr, NET_CHAT_PLAYER);
5587 end
5588 else g_Console_Add('say <text>');
5589 end else
5590 g_Console_Add(_lc[I_MSG_SERVERONLY]);
5591 end
5592 else if cmd = 'tell' then
5593 begin
5594 if g_Game_IsServer and g_Game_IsNet then
5595 begin
5596 if (Length(P) > 2) and (P[1] <> '') then
5597 begin
5598 chstr := '';
5599 for a := 2 to High(P) do
5600 chstr := chstr + P[a] + ' ';
5602 if Length(chstr) > 200 then SetLength(chstr, 200);
5604 if Length(chstr) < 1 then
5605 begin
5606 g_Console_Add('tell <playername> <text>');
5607 Exit;
5608 end;
5610 pl := g_Net_Client_ByName(P[1]);
5611 if pl <> nil then
5612 MH_SEND_Chat(b_Text_Format(chstr), NET_CHAT_PLAYER, pl^.ID)
5613 else
5614 g_Console_Add(Format(_lc[I_NET_ERR_NAME404], [P[1]]));
5615 end
5616 else g_Console_Add('tell <playername> <text>');
5617 end else
5618 g_Console_Add(_lc[I_MSG_SERVERONLY]);
5619 end
5620 else if (cmd = 'overtime') and not g_Game_IsClient then
5621 begin
5622 if (Length(P) = 1) or (StrToIntDef(P[1], -1) <= 0) then
5623 Exit;
5624 // Äîïîëíèòåëüíîå âðåìÿ:
5625 gGameSettings.TimeLimit := (gTime - gGameStartTime) div 1000 + Word(StrToIntDef(P[1], 0));
5627 g_Console_Add(Format(_lc[I_MSG_TIME_LIMIT],
5628 [gGameSettings.TimeLimit div 3600,
5629 (gGameSettings.TimeLimit div 60) mod 60,
5630 gGameSettings.TimeLimit mod 60]));
5631 if g_Game_IsNet then MH_SEND_GameSettings;
5632 end
5633 else if (cmd = 'rcon_password') and g_Game_IsClient then
5634 begin
5635 if (Length(P) <= 1) then
5636 g_Console_Add('rcon_password <password>')
5637 else
5638 MC_SEND_RCONPassword(P[1]);
5639 end
5640 else if cmd = 'rcon' then
5641 begin
5642 if g_Game_IsClient then
5643 begin
5644 if Length(P) > 1 then
5645 begin
5646 chstr := '';
5647 for a := 1 to High(P) do
5648 chstr := chstr + P[a] + ' ';
5650 if Length(chstr) > 200 then SetLength(chstr, 200);
5652 if Length(chstr) < 1 then
5653 begin
5654 g_Console_Add('rcon <command>');
5655 Exit;
5656 end;
5658 MC_SEND_RCONCommand(chstr);
5659 end
5660 else g_Console_Add('rcon <command>');
5661 end;
5662 end
5663 else if cmd = 'ready' then
5664 begin
5665 if g_Game_IsServer and (gLMSRespawn = LMS_RESPAWN_WARMUP) then
5666 gLMSRespawnTime := gTime + 100;
5667 end
5668 else if (cmd = 'callvote') and g_Game_IsNet then
5669 begin
5670 if Length(P) > 1 then
5671 begin
5672 chstr := '';
5673 for a := 1 to High(P) do begin
5674 if a > 1 then chstr := chstr + ' ';
5675 chstr := chstr + P[a];
5676 end;
5678 if Length(chstr) > 200 then SetLength(chstr, 200);
5680 if Length(chstr) < 1 then
5681 begin
5682 g_Console_Add('callvote <command>');
5683 Exit;
5684 end;
5686 if g_Game_IsClient then
5687 MC_SEND_Vote(True, chstr)
5688 else
5689 g_Game_StartVote(chstr, gPlayer1Settings.Name);
5690 g_Console_Process('vote', True);
5691 end
5692 else
5693 g_Console_Add('callvote <command>');
5694 end
5695 else if (cmd = 'vote') and g_Game_IsNet then
5696 begin
5697 if g_Game_IsClient then
5698 MC_SEND_Vote(False)
5699 else if gVoteInProgress then
5700 begin
5701 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
5702 a := Floor((NetClientCount+1)/2.0) + 1
5703 else
5704 a := Floor(NetClientCount/2.0) + 1;
5705 if gVoted then
5706 begin
5707 Dec(gVoteCount);
5708 gVoted := False;
5709 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_REVOKED], [gPlayer1Settings.Name, gVoteCount, a]), True);
5710 MH_SEND_VoteEvent(NET_VE_REVOKE, gPlayer1Settings.Name, 'a', gVoteCount, a);
5711 end
5712 else
5713 begin
5714 Inc(gVoteCount);
5715 gVoted := True;
5716 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_VOTE], [gPlayer1Settings.Name, gVoteCount, a]), True);
5717 MH_SEND_VoteEvent(NET_VE_VOTE, gPlayer1Settings.Name, 'a', gVoteCount, a);
5718 g_Game_CheckVote;
5719 end;
5720 end;
5721 end
5722 end;
5723 end;
5725 procedure g_TakeScreenShot();
5726 var
5727 a: Word;
5728 FileName: String;
5729 begin
5730 for a := 1 to High(Word) do
5731 begin
5732 FileName := Format(GameDir+'/Screenshots/Screenshot%.3d.bmp', [a]);
5733 if not FileExists(FileName) then
5734 begin
5735 e_MakeScreenshot(FileName, gScreenWidth, gScreenHeight);
5736 g_Console_Add(Format(_lc[I_CONSOLE_SCREENSHOT], [ExtractFileName(FileName)]));
5737 Break;
5738 end;
5739 end;
5740 end;
5742 procedure g_Game_InGameMenu(Show: Boolean);
5743 begin
5744 if (g_ActiveWindow = nil) and Show then
5745 begin
5746 if gGameSettings.GameType = GT_SINGLE then
5747 g_GUI_ShowWindow('GameSingleMenu')
5748 else
5749 begin
5750 if g_Game_IsClient then
5751 g_GUI_ShowWindow('GameClientMenu')
5752 else
5753 if g_Game_IsNet then
5754 g_GUI_ShowWindow('GameServerMenu')
5755 else
5756 g_GUI_ShowWindow('GameCustomMenu');
5757 end;
5758 g_Sound_PlayEx('MENU_OPEN');
5760 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
5761 if (not g_Game_IsNet) then
5762 g_Game_Pause(True);
5763 end
5764 else
5765 if (g_ActiveWindow <> nil) and (not Show) then
5766 begin
5767 // Ïàóçà ïðè ìåíþ òîëüêî â îäèíî÷íîé èãðå:
5768 if (not g_Game_IsNet) then
5769 g_Game_Pause(False);
5770 end;
5771 end;
5773 procedure g_Game_Pause(Enable: Boolean);
5774 begin
5775 if not gGameOn then
5776 Exit;
5778 if gPause = Enable then
5779 Exit;
5781 if not (gGameSettings.GameType in [GT_SINGLE, GT_CUSTOM]) then
5782 Exit;
5784 gPause := Enable;
5785 g_Game_PauseAllSounds(Enable);
5786 end;
5788 procedure g_Game_PauseAllSounds(Enable: Boolean);
5789 var
5790 i: Integer;
5791 begin
5792 // Òðèããåðû:
5793 if gTriggers <> nil then
5794 for i := 0 to High(gTriggers) do
5795 with gTriggers[i] do
5796 if (TriggerType = TRIGGER_SOUND) and
5797 (Sound <> nil) and
5798 Sound.IsPlaying() then
5799 begin
5800 Sound.Pause(Enable);
5801 end;
5803 // Çâóêè èãðîêîâ:
5804 if gPlayers <> nil then
5805 for i := 0 to High(gPlayers) do
5806 if gPlayers[i] <> nil then
5807 gPlayers[i].PauseSounds(Enable);
5809 // Ìóçûêà:
5810 if gMusic <> nil then
5811 gMusic.Pause(Enable);
5812 end;
5814 procedure g_Game_StopAllSounds(all: Boolean);
5815 var
5816 i: Integer;
5817 begin
5818 if gTriggers <> nil then
5819 for i := 0 to High(gTriggers) do
5820 with gTriggers[i] do
5821 if (TriggerType = TRIGGER_SOUND) and
5822 (Sound <> nil) then
5823 Sound.Stop();
5825 if gMusic <> nil then
5826 gMusic.Stop();
5828 if all then
5829 e_StopChannels();
5830 end;
5832 procedure g_Game_UpdateTriggerSounds();
5833 var
5834 i: Integer;
5835 begin
5836 if gTriggers <> nil then
5837 for i := 0 to High(gTriggers) do
5838 with gTriggers[i] do
5839 if (TriggerType = TRIGGER_SOUND) and
5840 (Sound <> nil) and
5841 (Data.Local) and
5842 Sound.IsPlaying() then
5843 begin
5844 if ((gPlayer1 <> nil) and g_CollidePoint(gPlayer1.GameX, gPlayer1.GameY, X, Y, Width, Height)) or
5845 ((gPlayer2 <> nil) and g_CollidePoint(gPlayer2.GameX, gPlayer2.GameY, X, Y, Width, Height)) then
5846 begin
5847 Sound.SetPan(0.5 - Data.Pan/255.0);
5848 Sound.SetVolume(Data.Volume/255.0);
5849 end
5850 else
5851 Sound.SetCoords(X+(Width div 2), Y+(Height div 2), Data.Volume/255.0);
5852 end;
5853 end;
5855 function g_Game_IsWatchedPlayer(UID: Word): Boolean;
5856 begin
5857 Result := False;
5858 if (gPlayer1 <> nil) and (gPlayer1.UID = UID) then
5859 begin
5860 Result := True;
5861 Exit;
5862 end;
5863 if (gPlayer2 <> nil) and (gPlayer2.UID = UID) then
5864 begin
5865 Result := True;
5866 Exit;
5867 end;
5868 if gSpectMode <> SPECT_PLAYERS then
5869 Exit;
5870 if gSpectPID1 = UID then
5871 begin
5872 Result := True;
5873 Exit;
5874 end;
5875 if gSpectViewTwo and (gSpectPID2 = UID) then
5876 begin
5877 Result := True;
5878 Exit;
5879 end;
5880 end;
5882 function g_Game_IsWatchedTeam(Team: Byte): Boolean;
5883 var
5884 Pl: TPlayer;
5885 begin
5886 Result := False;
5887 if (gPlayer1 <> nil) and (gPlayer1.Team = Team) then
5888 begin
5889 Result := True;
5890 Exit;
5891 end;
5892 if (gPlayer2 <> nil) and (gPlayer2.Team = Team) then
5893 begin
5894 Result := True;
5895 Exit;
5896 end;
5897 if gSpectMode <> SPECT_PLAYERS then
5898 Exit;
5899 Pl := g_Player_Get(gSpectPID1);
5900 if (Pl <> nil) and (Pl.Team = Team) then
5901 begin
5902 Result := True;
5903 Exit;
5904 end;
5905 if gSpectViewTwo then
5906 begin
5907 Pl := g_Player_Get(gSpectPID2);
5908 if (Pl <> nil) and (Pl.Team = Team) then
5909 begin
5910 Result := True;
5911 Exit;
5912 end;
5913 end;
5914 end;
5916 procedure g_Game_Message(Msg: string; Time: Word);
5917 begin
5918 MessageText := b_Text_Format(Msg);
5919 MessageTime := Time;
5920 end;
5922 procedure g_Game_Announce_GoodShot(SpawnerUID: Word);
5923 var
5924 a: Integer;
5925 begin
5926 case gAnnouncer of
5927 ANNOUNCE_NONE:
5928 Exit;
5929 ANNOUNCE_ME,
5930 ANNOUNCE_MEPLUS:
5931 if not g_Game_IsWatchedPlayer(SpawnerUID) then
5932 Exit;
5933 end;
5934 for a := 0 to 3 do
5935 if goodsnd[a].IsPlaying() then
5936 Exit;
5938 goodsnd[Random(4)].Play();
5939 end;
5941 procedure g_Game_Announce_KillCombo(Param: Integer);
5942 var
5943 UID: Word;
5944 c, n: Byte;
5945 Pl: TPlayer;
5946 Name: String;
5947 begin
5948 UID := Param and $FFFF;
5949 c := Param shr 16;
5950 if c < 2 then
5951 Exit;
5953 Pl := g_Player_Get(UID);
5954 if Pl = nil then
5955 Name := '?'
5956 else
5957 Name := Pl.Name;
5959 case c of
5960 2: begin
5961 n := 0;
5962 g_Console_Add(Format(_lc[I_PLAYER_KILL_2X], [Name]), True);
5963 end;
5964 3: begin
5965 n := 1;
5966 g_Console_Add(Format(_lc[I_PLAYER_KILL_3X], [Name]), True);
5967 end;
5968 4: begin
5969 n := 2;
5970 g_Console_Add(Format(_lc[I_PLAYER_KILL_4X], [Name]), True);
5971 end;
5972 else begin
5973 n := 3;
5974 g_Console_Add(Format(_lc[I_PLAYER_KILL_MX], [Name]), True);
5975 end;
5976 end;
5978 case gAnnouncer of
5979 ANNOUNCE_NONE:
5980 Exit;
5981 ANNOUNCE_ME:
5982 if not g_Game_IsWatchedPlayer(UID) then
5983 Exit;
5984 ANNOUNCE_MEPLUS:
5985 if (not g_Game_IsWatchedPlayer(UID)) and (c < 4) then
5986 Exit;
5987 end;
5989 if killsnd[n].IsPlaying() then
5990 killsnd[n].Stop();
5991 killsnd[n].Play();
5992 end;
5994 procedure g_Game_StartVote(Command, Initiator: string);
5995 var
5996 Need: Integer;
5997 begin
5998 if not gVotesEnabled then Exit;
5999 if gGameSettings.GameType <> GT_SERVER then Exit;
6000 if gVoteInProgress or gVotePassed then
6001 begin
6002 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_INPROGRESS], [gVoteCommand]), True);
6003 MH_SEND_VoteEvent(NET_VE_INPROGRESS, gVoteCommand);
6004 Exit;
6005 end;
6006 gVoteInProgress := True;
6007 gVotePassed := False;
6008 gVoteTimer := gTime + gVoteTimeout * 1000;
6009 gVoteCount := 0;
6010 gVoted := False;
6011 gVoteCommand := Command;
6013 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
6014 Need := Floor((NetClientCount+1)/2.0)+1
6015 else
6016 Need := Floor(NetClientCount/2.0)+1;
6017 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_STARTED], [Initiator, Command, Need]), True);
6018 MH_SEND_VoteEvent(NET_VE_STARTED, Initiator, Command, Need);
6019 end;
6021 procedure g_Game_CheckVote;
6022 var
6023 I, Need: Integer;
6024 begin
6025 if gGameSettings.GameType <> GT_SERVER then Exit;
6026 if not gVoteInProgress then Exit;
6028 if (gTime >= gVoteTimer) then
6029 begin
6030 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
6031 Need := Floor((NetClientCount+1)/2.0) + 1
6032 else
6033 Need := Floor(NetClientCount/2.0) + 1;
6034 if gVoteCount >= Need then
6035 begin
6036 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_PASSED], [gVoteCommand]), True);
6037 MH_SEND_VoteEvent(NET_VE_PASSED, gVoteCommand);
6038 gVotePassed := True;
6039 gVoteCmdTimer := gTime + 5000;
6040 end
6041 else
6042 begin
6043 g_Console_Add(_lc[I_MESSAGE_VOTE_FAILED], True);
6044 MH_SEND_VoteEvent(NET_VE_FAILED);
6045 end;
6046 if NetClients <> nil then
6047 for I := Low(NetClients) to High(NetClients) do
6048 if NetClients[i].Used then
6049 NetClients[i].Voted := False;
6050 gVoteInProgress := False;
6051 gVoted := False;
6052 gVoteCount := 0;
6053 end
6054 else
6055 begin
6056 if (gPlayer1 <> nil) or (gPlayer2 <> nil) then
6057 Need := Floor((NetClientCount+1)/2.0) + 1
6058 else
6059 Need := Floor(NetClientCount/2.0) + 1;
6060 if gVoteCount >= Need then
6061 begin
6062 g_Console_Add(Format(_lc[I_MESSAGE_VOTE_PASSED], [gVoteCommand]), True);
6063 MH_SEND_VoteEvent(NET_VE_PASSED, gVoteCommand);
6064 gVoteInProgress := False;
6065 gVotePassed := True;
6066 gVoteCmdTimer := gTime + 5000;
6067 gVoted := False;
6068 gVoteCount := 0;
6069 if NetClients <> nil then
6070 for I := Low(NetClients) to High(NetClients) do
6071 if NetClients[i].Used then
6072 NetClients[i].Voted := False;
6073 end;
6074 end;
6075 end;
6077 procedure g_Game_LoadMapList(FileName: string);
6078 var
6079 ListFile: TextFile;
6080 s: string;
6081 begin
6082 MapList := nil;
6083 MapIndex := -1;
6085 if not FileExists(FileName) then Exit;
6087 AssignFile(ListFile, FileName);
6088 Reset(ListFile);
6089 while not EOF(ListFile) do
6090 begin
6091 ReadLn(ListFile, s);
6093 s := Trim(s);
6094 if s = '' then Continue;
6096 SetLength(MapList, Length(MapList)+1);
6097 MapList[High(MapList)] := s;
6098 end;
6099 CloseFile(ListFile);
6100 end;
6102 procedure g_Game_SetDebugMode();
6103 begin
6104 gDebugMode := True;
6105 // ×èòû (äàæå â ñâîåé èãðå):
6106 gCheats := True;
6107 end;
6109 procedure g_Game_SetLoadingText(Text: String; Max: Integer; reWrite: Boolean);
6110 var
6111 i: Word;
6112 begin
6113 if Length(LoadingStat.Msgs) = 0 then
6114 Exit;
6116 with LoadingStat do
6117 begin
6118 if not reWrite then
6119 begin // Ïåðåõîäèì íà ñëåäóþùóþ ñòðîêó èëè ñêðîëëèðóåì:
6120 if NextMsg = Length(Msgs) then
6121 begin // scroll
6122 for i := 0 to High(Msgs)-1 do
6123 Msgs[i] := Msgs[i+1];
6124 end
6125 else
6126 Inc(NextMsg);
6127 end else
6128 if NextMsg = 0 then
6129 Inc(NextMsg);
6131 Msgs[NextMsg-1] := Text;
6132 CurValue := 0;
6133 MaxValue := Max;
6134 ShowCount := 0;
6135 end;
6137 g_ActiveWindow := nil;
6139 ProcessLoading;
6140 end;
6142 procedure g_Game_StepLoading();
6143 begin
6144 with LoadingStat do
6145 begin
6146 Inc(CurValue);
6147 Inc(ShowCount);
6148 if (ShowCount > LOADING_SHOW_STEP) then
6149 begin
6150 ShowCount := 0;
6151 ProcessLoading;
6152 end;
6153 end;
6154 end;
6156 procedure g_Game_ClearLoading();
6157 var
6158 len: Word;
6159 begin
6160 with LoadingStat do
6161 begin
6162 CurValue := 0;
6163 MaxValue := 0;
6164 ShowCount := 0;
6165 len := ((gScreenHeight div 3)*2 - 50) div LOADING_INTERLINE;
6166 if len < 1 then len := 1;
6167 SetLength(Msgs, len);
6168 for len := Low(Msgs) to High(Msgs) do
6169 Msgs[len] := '';
6170 NextMsg := 0;
6171 end;
6172 end;
6174 procedure Parse_Params(var pars: TParamStrValues);
6175 var
6176 i: Integer;
6177 s: String;
6178 begin
6179 SetLength(pars, 0);
6180 i := 1;
6181 while i <= ParamCount do
6182 begin
6183 s := ParamStr(i);
6184 if (s[1] = '-') and (Length(s) > 1) then
6185 begin
6186 if (s[2] = '-') and (Length(s) > 2) then
6187 begin // Îäèíî÷íûé ïàðàìåòð
6188 SetLength(pars, Length(pars) + 1);
6189 with pars[High(pars)] do
6190 begin
6191 Name := LowerCase(s);
6192 Value := '+';
6193 end;
6194 end
6195 else
6196 if (i < ParamCount) then
6197 begin // Ïàðàìåòð ñî çíà÷åíèåì
6198 Inc(i);
6199 SetLength(pars, Length(pars) + 1);
6200 with pars[High(pars)] do
6201 begin
6202 Name := LowerCase(s);
6203 Value := LowerCase(ParamStr(i));
6204 end;
6205 end;
6206 end;
6208 Inc(i);
6209 end;
6210 end;
6212 function Find_Param_Value(var pars: TParamStrValues; aName: String): String;
6213 var
6214 i: Integer;
6215 begin
6216 Result := '';
6217 for i := 0 to High(pars) do
6218 if pars[i].Name = aName then
6219 begin
6220 Result := pars[i].Value;
6221 Break;
6222 end;
6223 end;
6225 procedure g_Game_Process_Params();
6226 var
6227 pars: TParamStrValues;
6228 map: String;
6229 GMode, n: Byte;
6230 LimT, LimS: Integer;
6231 Opt: LongWord;
6232 Lives: Integer;
6233 s: String;
6234 Port: Integer;
6235 ip: String;
6236 F: TextFile;
6237 begin
6238 Parse_Params(pars);
6240 // Debug mode:
6241 s := Find_Param_Value(pars, '--debug');
6242 if (s <> '') then
6243 g_Game_SetDebugMode();
6245 // Connect when game loads
6246 ip := Find_Param_Value(pars, '-connect');
6248 if ip <> '' then
6249 begin
6250 s := Find_Param_Value(pars, '-port');
6251 if (s = '') or not TryStrToInt(s, Port) then
6252 Port := 25666;
6254 s := Find_Param_Value(pars, '-pw');
6256 g_Game_StartClient(ip, Port, s);
6257 Exit;
6258 end;
6260 // Start map when game loads:
6261 map := LowerCase(Find_Param_Value(pars, '-map'));
6262 if isWadPath(map) then
6263 begin
6264 // Game mode:
6265 s := Find_Param_Value(pars, '-gm');
6266 GMode := g_Game_TextToMode(s);
6267 if GMode = GM_NONE then GMode := GM_DM;
6268 if GMode = GM_SINGLE then GMode := GM_COOP;
6270 // Time limit:
6271 s := Find_Param_Value(pars, '-limt');
6272 if (s = '') or (not TryStrToInt(s, LimT)) then
6273 LimT := 0;
6274 if LimT < 0 then
6275 LimT := 0;
6277 // Goal limit:
6278 s := Find_Param_Value(pars, '-lims');
6279 if (s = '') or (not TryStrToInt(s, LimS)) then
6280 LimS := 0;
6281 if LimS < 0 then
6282 LimS := 0;
6284 // Lives limit:
6285 s := Find_Param_Value(pars, '-lives');
6286 if (s = '') or (not TryStrToInt(s, Lives)) then
6287 Lives := 0;
6288 if Lives < 0 then
6289 Lives := 0;
6291 // Options:
6292 s := Find_Param_Value(pars, '-opt');
6293 if (s = '') then
6294 Opt := GAME_OPTION_ALLOWEXIT or GAME_OPTION_BOTVSPLAYER or GAME_OPTION_BOTVSMONSTER
6295 else
6296 Opt := StrToIntDef(s, 0);
6297 if Opt = 0 then
6298 Opt := GAME_OPTION_ALLOWEXIT or GAME_OPTION_BOTVSPLAYER or GAME_OPTION_BOTVSMONSTER;
6300 // Close after map:
6301 s := Find_Param_Value(pars, '--close');
6302 if (s <> '') then
6303 gMapOnce := True;
6305 // Delete test map after play:
6306 s := Find_Param_Value(pars, '--testdelete');
6307 if (s <> '') then
6308 begin
6309 gMapToDelete := MapsDir + map;
6310 e_WriteLog('"--testdelete" argument doesn''t supported anymore!', MSG_FATALERROR);
6311 Halt(1);
6312 end;
6314 // Delete temporary WAD after play:
6315 s := Find_Param_Value(pars, '--tempdelete');
6316 if (s <> '') then
6317 begin
6318 gMapToDelete := MapsDir + map;
6319 gTempDelete := True;
6320 end;
6322 // Number of players:
6323 s := Find_Param_Value(pars, '-pl');
6324 if (s = '') then
6325 n := 1
6326 else
6327 n := StrToIntDef(s, 1);
6329 // Start:
6330 s := Find_Param_Value(pars, '-port');
6331 if (s = '') or not TryStrToInt(s, Port) then
6332 g_Game_StartCustom(map, GMode, LimT, LimS, Lives, Opt, n)
6333 else
6334 g_Game_StartServer(map, GMode, LimT, LimS, Lives, Opt, n, 0, Port);
6335 end;
6337 // Execute script when game loads:
6338 s := Find_Param_Value(pars, '-exec');
6339 if s <> '' then
6340 begin
6341 if Pos(':\', s) = 0 then
6342 s := GameDir + '/' + s;
6344 {$I-}
6345 AssignFile(F, s);
6346 Reset(F);
6347 if IOResult <> 0 then
6348 begin
6349 e_WriteLog(Format(_lc[I_SIMPLE_ERROR], ['Failed to read file: ' + s]), MSG_WARNING);
6350 g_Console_Add(Format(_lc[I_CONSOLE_ERROR_READ], [s]));
6351 CloseFile(F);
6352 Exit;
6353 end;
6354 e_WriteLog('Executing script: ' + s, MSG_NOTIFY);
6355 g_Console_Add(Format(_lc[I_CONSOLE_EXEC], [s]));
6357 while not EOF(F) do
6358 begin
6359 ReadLn(F, s);
6360 if IOResult <> 0 then
6361 begin
6362 e_WriteLog(Format(_lc[I_SIMPLE_ERROR], ['Failed to read file: ' + s]), MSG_WARNING);
6363 g_Console_Add(Format(_lc[I_CONSOLE_ERROR_READ], [s]));
6364 CloseFile(F);
6365 Exit;
6366 end;
6367 if Pos('#', s) <> 1 then // script comment
6368 g_Console_Process(s, True);
6369 end;
6371 CloseFile(F);
6372 {$I+}
6373 end;
6375 SetLength(pars, 0);
6376 end;
6378 end.