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