X-Git-Url: http://deadsoftware.ru/gitweb?a=blobdiff_plain;f=src%2Fgame%2Fg_game.pas;h=d7b9b2d020e1d2a2d12e4550da90fa192526ea12;hb=656407d4bcc9419011375f19ad756d9ab7254f89;hp=85f85894e86ff92a0226c26257836bd0f878f519;hpb=53a532345838de82821c8711ae5e2e35d34892c4;p=d2df-sdl.git diff --git a/src/game/g_game.pas b/src/game/g_game.pas index 85f8589..d7b9b2d 100644 --- a/src/game/g_game.pas +++ b/src/game/g_game.pas @@ -17,12 +17,15 @@ unit g_game; interface -uses - SysUtils, Classes, - MAPDEF, - g_base, g_basic, g_player, r_graphics, g_res_downloader, - g_sound, g_gui, utils, md5, mempool, xprofiler, - g_touch, g_weapons; + uses + {$IFDEF ENABLE_MENU} + g_gui, + {$ENDIF} + SysUtils, Classes, MAPDEF, + g_base, g_basic, g_player, g_res_downloader, + g_sound, utils, md5, mempool, xprofiler, + g_weapons + ; type TGameSettings = record @@ -91,8 +94,6 @@ procedure g_Game_FreeData(); procedure g_Game_Update(); procedure g_Game_PreUpdate(); procedure g_Game_Quit(); -procedure g_Game_SetupScreenSize(); -procedure g_Game_ChangeResolution(newWidth, newHeight: Word; nowFull, nowMax: Boolean); function g_Game_ModeToText(Mode: Byte): string; function g_Game_TextToMode(Mode: string): Byte; procedure g_Game_ExecuteEvent(Name: String); @@ -117,7 +118,6 @@ function g_Game_GetNextMap(): String; procedure g_Game_NextLevel(); procedure g_Game_Pause(Enable: Boolean); procedure g_Game_HolmesPause(Enable: Boolean); -procedure g_Game_InGameMenu(Show: Boolean); function g_Game_IsWatchedPlayer(UID: Word): Boolean; function g_Game_IsWatchedTeam(Team: Byte): Boolean; procedure g_Game_Message(Msg: String; Time: Word); @@ -132,7 +132,6 @@ procedure g_Game_Announce_KillCombo(Param: Integer); procedure g_Game_Announce_BodyKill(SpawnerUID: Word); procedure g_Game_StartVote(Command, Initiator: string); procedure g_Game_CheckVote; -procedure g_TakeScreenShot(Filename: string = ''); procedure g_FatalError(Text: String); procedure g_SimpleError(Text: String); function g_Game_IsTestMap(): Boolean; @@ -144,23 +143,27 @@ procedure GameCommands(P: SSArray); procedure GameCheats(P: SSArray); procedure DebugCommands(P: SSArray); procedure g_Game_Process_Params; -procedure g_Game_SetLoadingText(Text: String; Max: Integer; reWrite: Boolean); -procedure g_Game_StepLoading(Value: Integer = -1); -procedure g_Game_ClearLoading(); procedure g_Game_SetDebugMode(); function IsActivePlayer(p: TPlayer): Boolean; function GetActivePlayerID_Next(Skip: Integer = -1): Integer; procedure SortGameStat(var stat: TPlayerStatArray); + +{$IFDEF ENABLE_MENU} + procedure g_Game_InGameMenu(Show: Boolean); +{$ENDIF} +{$IFDEF ENABLE_SYSTEM} + procedure CharPress (C: AnsiChar); +{$ENDIF} + + procedure KeyPress (K: Word); + { procedure SetWinPause(Enable: Boolean); } const GAME_TICK = 28; - LOADING_SHOW_STEP = 100; - LOADING_INTERLINE = 20; - GT_NONE = 0; GT_SINGLE = 1; GT_CUSTOM = 2; @@ -174,8 +177,6 @@ const GM_COOP = 4; GM_SINGLE = 5; - MESSAGE_DIKEY = WM_USER + 1; - EXIT_QUIT = 1; EXIT_SIMPLE = 2; EXIT_RESTART = 3; @@ -240,21 +241,18 @@ const STATFILE_VERSION = $03; var - gStdFont: DWORD; gGameSettings: TGameSettings; gPlayer1Settings: TPlayerSettings; gPlayer2Settings: TPlayerSettings; gGameOn: Boolean; gPlayerScreenSize: TDFPoint; - gPlayer1ScreenCoord: TDFPoint; - gPlayer2ScreenCoord: TDFPoint; gPlayer1: TPlayer = nil; gPlayer2: TPlayer = nil; - gPlayerDrawn: TPlayer = nil; gTime: LongWord; gLerpFactor: Single = 1.0; gSwitchGameMode: Byte = GM_DM; gHearPoint1, gHearPoint2: THearPoint; + gMaxDist: Integer = 1; // for sound gSoundEffectsDF: Boolean = False; gSoundTriggerTime: Word = 0; gAnnouncer: Integer = ANNOUNCE_NONE; @@ -314,12 +312,9 @@ var gRC_FullScreen, gRC_Maximized: Boolean; gLanguageChange: Boolean = False; gDebugMode: Boolean = False; - g_debug_Sounds: Boolean = False; - g_debug_Frames: Boolean = False; g_debug_WinMsgs: Boolean = False; g_debug_MonsterOff: Boolean = False; g_debug_BotAIOff: Byte = 0; - g_debug_HealthBar: Boolean = False; g_Debug_Player: Boolean = False; gCoopMonstersKilled: Word = 0; gCoopSecretsFound: Word = 0; @@ -381,6 +376,7 @@ var g_rlayer_water: Boolean = true; g_rlayer_fore: Boolean = true; + wNeedTimeReset: Boolean = false; procedure g_ResetDynlights (); procedure g_AddDynLight (x, y, radius: Integer; r, g, b, a: Single); @@ -408,15 +404,6 @@ function gPause (): Boolean; inline; TotalSecrets: Integer; end; - TLoadingStat = record - CurValue: Integer; - MaxValue: Integer; - ShowCount: Integer; - Msgs: Array of String; - NextMsg: Word; - PBarWasHere: Boolean; // did we draw a progress bar for this message? - end; - TDynLight = record x, y, radius: Integer; r, g, b, a: Single; @@ -429,8 +416,6 @@ function gPause (): Boolean; inline; StatShotDone: Boolean; StatFilename: string = ''; // used by stat screenshot to save with the same name as the csv SingleStat: TEndSingleGameStat; - hasPBarGfx: Boolean; - LoadingStat: TLoadingStat; MessageText: String; IsDrawStat: Boolean; EndingGameCounter: Byte; @@ -438,21 +423,401 @@ function gPause (): Boolean; inline; g_playerLight: Boolean; g_dynLights: array of TDynLight = nil; g_dynLightCount: Integer = 0; + EndPicPath: AnsiString; // full path, used by render implementation uses -{$INCLUDE ../nogl/noGLuses.inc} -{$IFDEF ENABLE_HOLMES} - g_holmes, -{$ENDIF} - e_texture, e_res, g_textures, g_window, g_menu, - e_input, e_log, g_console, r_console, g_items, g_map, g_panel, - g_playermodel, g_gfx, g_options, Math, + {$IFDEF ENABLE_HOLMES} + g_holmes, + {$ENDIF} + {$IFDEF ENABLE_MENU} + g_menu, + {$ENDIF} + {$IFDEF ENABLE_GFX} + g_gfx, + {$ENDIF} + {$IFDEF ENABLE_GIBS} + g_gibs, + {$ENDIF} + {$IFDEF ENABLE_SHELLS} + g_shells, + {$ENDIF} + {$IFDEF ENABLE_CORPSES} + g_corpses, + {$ENDIF} + {$IFDEF ENABLE_RENDER} + r_render, + {$ENDIF} + {$IFDEF ENABLE_SYSTEM} + g_system, + {$ENDIF} + e_res, g_window, + e_input, e_log, g_console, g_items, g_map, g_panel, + g_playermodel, g_options, Math, g_triggers, g_monsters, e_sound, CONFIG, - g_language, g_net, g_main, g_phys, + g_language, g_net, g_phys, ENet, e_msg, g_netmsg, g_netmaster, - sfs, wadreader, g_system, r_playermodel; + sfs, wadreader; + + var + charbuff: packed array [0..15] of AnsiChar = ( + ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ' + ); + +function Translit (const S: AnsiString): AnsiString; +var + i: Integer; +begin + Result := S; + for i := 1 to Length(Result) do + begin + case Result[i] of + #$C9: Result[i] := 'Q'; + #$D6: Result[i] := 'W'; + #$D3: Result[i] := 'E'; + #$CA: Result[i] := 'R'; + #$C5: Result[i] := 'T'; + #$CD: Result[i] := 'Y'; + #$C3: Result[i] := 'U'; + #$D8: Result[i] := 'I'; + #$D9: Result[i] := 'O'; + #$C7: Result[i] := 'P'; + #$D5: Result[i] := '['; //Chr(219); + #$DA: Result[i] := ']'; //Chr(221); + #$D4: Result[i] := 'A'; + #$DB: Result[i] := 'S'; + #$C2: Result[i] := 'D'; + #$C0: Result[i] := 'F'; + #$CF: Result[i] := 'G'; + #$D0: Result[i] := 'H'; + #$CE: Result[i] := 'J'; + #$CB: Result[i] := 'K'; + #$C4: Result[i] := 'L'; + #$C6: Result[i] := ';'; //Chr(186); + #$DD: Result[i] := #39; //Chr(222); + #$DF: Result[i] := 'Z'; + #$D7: Result[i] := 'X'; + #$D1: Result[i] := 'C'; + #$CC: Result[i] := 'V'; + #$C8: Result[i] := 'B'; + #$D2: Result[i] := 'N'; + #$DC: Result[i] := 'M'; + #$C1: Result[i] := ','; //Chr(188); + #$DE: Result[i] := '.'; //Chr(190); + end; + end; +end; + + +function CheckCheat (ct: TStrings_Locale; eofs: Integer=0): Boolean; +var + ls1, ls2: string; +begin + ls1 := CheatEng[ct]; + ls2 := Translit(CheatRus[ct]); + if length(ls1) = 0 then ls1 := '~'; + if length(ls2) = 0 then ls2 := '~'; + result := + (Copy(charbuff, 17-Length(ls1)-eofs, Length(ls1)) = ls1) or + (Translit(Copy(charbuff, 17-Length(ls1)-eofs, Length(ls1))) = ls1) or + (Copy(charbuff, 17-Length(ls2)-eofs, Length(ls2)) = ls2) or + (Translit(Copy(charbuff, 17-Length(ls2)-eofs, Length(ls2))) = ls2); + { + if ct = I_GAME_CHEAT_JETPACK then + begin + e_WriteLog('ls1: ['+ls1+']', MSG_NOTIFY); + e_WriteLog('ls2: ['+ls2+']', MSG_NOTIFY); + e_WriteLog('bf0: ['+Copy(charbuff, 17-Length(ls1)-eofs, Length(ls1))+']', MSG_NOTIFY); + e_WriteLog('bf1: ['+Translit(Copy(charbuff, 17-Length(ls1)-eofs, Length(ls1)))+']', MSG_NOTIFY); + e_WriteLog('bf2: ['+Copy(charbuff, 17-Length(ls2)-eofs, Length(ls2))+']', MSG_NOTIFY); + e_WriteLog('bf3: ['+Translit(Copy(charbuff, 17-Length(ls2)-eofs, Length(ls2)))+']', MSG_NOTIFY); + end; + } +end; + +procedure Cheat (); +const + CHEAT_DAMAGE = 500; +label + Cheated; +var + s, s2: string; + c: ShortString; + a: Integer; +begin + { + if (not gGameOn) or (not gCheats) or ((gGameSettings.GameType <> GT_SINGLE) and + (gGameSettings.GameMode <> GM_COOP) and (not gDebugMode)) + or g_Game_IsNet then Exit; + } + if not gGameOn then exit; + if not conIsCheatsEnabled then exit; + + s := 'SOUND_GAME_RADIO'; + + // + if CheckCheat(I_GAME_CHEAT_GODMODE) then + begin + if gPlayer1 <> nil then gPlayer1.GodMode := not gPlayer1.GodMode; + if gPlayer2 <> nil then gPlayer2.GodMode := not gPlayer2.GodMode; + goto Cheated; + end; + // RAMBO + if CheckCheat(I_GAME_CHEAT_WEAPONS) then + begin + if gPlayer1 <> nil then gPlayer1.AllRulez(False); + if gPlayer2 <> nil then gPlayer2.AllRulez(False); + goto Cheated; + end; + // TANK + if CheckCheat(I_GAME_CHEAT_HEALTH) then + begin + if gPlayer1 <> nil then gPlayer1.AllRulez(True); + if gPlayer2 <> nil then gPlayer2.AllRulez(True); + goto Cheated; + end; + // IDDQD + if CheckCheat(I_GAME_CHEAT_DEATH) then + begin + if gPlayer1 <> nil then gPlayer1.Damage(CHEAT_DAMAGE, 0, 0, 0, HIT_TRAP); + if gPlayer2 <> nil then gPlayer2.Damage(CHEAT_DAMAGE, 0, 0, 0, HIT_TRAP); + s := 'SOUND_MONSTER_HAHA'; + goto Cheated; + end; + // + if CheckCheat(I_GAME_CHEAT_DOORS) then + begin + g_Triggers_OpenAll(); + goto Cheated; + end; + // GOODBYE + if CheckCheat(I_GAME_CHEAT_NEXTMAP) then + begin + if gTriggers <> nil then + for a := 0 to High(gTriggers) do + if gTriggers[a].TriggerType = TRIGGER_EXIT then + begin + gExitByTrigger := True; + //g_Game_ExitLevel(gTriggers[a].Data.MapName); + g_Game_ExitLevel(gTriggers[a].tgcMap); + Break; + end; + goto Cheated; + end; + // + s2 := Copy(charbuff, 15, 2); + if CheckCheat(I_GAME_CHEAT_CHANGEMAP, 2) and (s2[1] >= '0') and (s2[1] <= '9') and (s2[2] >= '0') and (s2[2] <= '9') then + begin + if g_Map_Exist(gGameSettings.WAD + ':\MAP' + s2) then + begin + c := 'MAP' + s2; + g_Game_ExitLevel(c); + end; + goto Cheated; + end; + // + if CheckCheat(I_GAME_CHEAT_FLY) then + begin + gFly := not gFly; + goto Cheated; + end; + // BULLFROG + if CheckCheat(I_GAME_CHEAT_JUMPS) then + begin + VEL_JUMP := 30-VEL_JUMP; + goto Cheated; + end; + // FORMULA1 + if CheckCheat(I_GAME_CHEAT_SPEED) then + begin + MAX_RUNVEL := 32-MAX_RUNVEL; + goto Cheated; + end; + // CONDOM + if CheckCheat(I_GAME_CHEAT_SUIT) then + begin + if gPlayer1 <> nil then gPlayer1.GiveItem(ITEM_SUIT); + if gPlayer2 <> nil then gPlayer2.GiveItem(ITEM_SUIT); + goto Cheated; + end; + // + if CheckCheat(I_GAME_CHEAT_AIR) then + begin + if gPlayer1 <> nil then gPlayer1.GiveItem(ITEM_OXYGEN); + if gPlayer2 <> nil then gPlayer2.GiveItem(ITEM_OXYGEN); + goto Cheated; + end; + // PURELOVE + if CheckCheat(I_GAME_CHEAT_BERSERK) then + begin + if gPlayer1 <> nil then gPlayer1.GiveItem(ITEM_MEDKIT_BLACK); + if gPlayer2 <> nil then gPlayer2.GiveItem(ITEM_MEDKIT_BLACK); + goto Cheated; + end; + // + if CheckCheat(I_GAME_CHEAT_JETPACK) then + begin + if gPlayer1 <> nil then gPlayer1.GiveItem(ITEM_JETPACK); + if gPlayer2 <> nil then gPlayer2.GiveItem(ITEM_JETPACK); + goto Cheated; + end; + // CASPER + if CheckCheat(I_GAME_CHEAT_NOCLIP) then + begin + if gPlayer1 <> nil then gPlayer1.SwitchNoClip; + if gPlayer2 <> nil then gPlayer2.SwitchNoClip; + goto Cheated; + end; + // + if CheckCheat(I_GAME_CHEAT_NOTARGET) then + begin + if gPlayer1 <> nil then gPlayer1.NoTarget := not gPlayer1.NoTarget; + if gPlayer2 <> nil then gPlayer2.NoTarget := not gPlayer2.NoTarget; + goto Cheated; + end; + // INFERNO + if CheckCheat(I_GAME_CHEAT_NORELOAD) then + begin + if gPlayer1 <> nil then gPlayer1.NoReload := not gPlayer1.NoReload; + if gPlayer2 <> nil then gPlayer2.NoReload := not gPlayer2.NoReload; + goto Cheated; + end; + if CheckCheat(I_GAME_CHEAT_AIMLINE) then + begin + gAimLine := not gAimLine; + goto Cheated; + end; + if CheckCheat(I_GAME_CHEAT_AUTOMAP) then + begin + gShowMap := not gShowMap; + goto Cheated; + end; + Exit; + +Cheated: + g_Sound_PlayEx(s); +end; + + +{$IFDEF ENABLE_MENU} +procedure KeyPress (K: Word); + var Msg: g_gui.TMessage; +begin + case K of + VK_ESCAPE: // : + begin + if (g_ActiveWindow <> nil) then + begin + Msg.Msg := WM_KEYDOWN; + Msg.WParam := VK_ESCAPE; + g_ActiveWindow.OnMessage(Msg); + if (not g_Game_IsNet) and (g_ActiveWindow = nil) then g_Game_Pause(false); //Fn loves to do this + end + else if (gState <> STATE_FOLD) then + begin + if gGameOn or (gState = STATE_INTERSINGLE) or (gState = STATE_INTERCUSTOM) then + begin + g_Game_InGameMenu(True); + end + else if (gExit = 0) and (gState <> STATE_SLIST) then + begin + if (gState <> STATE_MENU) then + begin + if (NetMode <> NET_NONE) then + begin + g_Game_StopAllSounds(True); + g_Game_Free; + gState := STATE_MENU; + Exit; + end; + end; + g_GUI_ShowWindow('MainMenu'); + g_Sound_PlayEx('MENU_OPEN'); + end; + end; + end; + + IK_F2, IK_F3, IK_F4, IK_F5, IK_F6, IK_F7, IK_F10: + begin // .. � + if gGameOn and (not gConsoleShow) and (not gChatShow) then + begin + while (g_ActiveWindow <> nil) do g_GUI_HideWindow(False); + if (not g_Game_IsNet) then g_Game_Pause(True); + case K of + IK_F2: g_Menu_Show_SaveMenu(); + IK_F3: g_Menu_Show_LoadMenu(); + IK_F4: g_Menu_Show_GameSetGame(); + IK_F5: g_Menu_Show_OptionsVideo(); + IK_F6: g_Menu_Show_OptionsSound(); + IK_F7: g_Menu_Show_EndGameMenu(); + IK_F10: g_Menu_Show_QuitGameMenu(); + end; + end; + end; + + else + begin + gJustChatted := False; + if gConsoleShow or gChatShow then + begin + g_Console_Control(K); + end + else if (g_ActiveWindow <> nil) then + begin + Msg.Msg := WM_KEYDOWN; + Msg.WParam := K; + g_ActiveWindow.OnMessage(Msg); + end + else if (gState = STATE_MENU) then + begin + g_GUI_ShowWindow('MainMenu'); + g_Sound_PlayEx('MENU_OPEN'); + end; + end; + end; +end; +{$ELSE} + procedure KeyPress (K: Word); + begin + gJustChatted := False; + if gConsoleShow or gChatShow then + begin + g_Console_Control(K); + end + end; +{$ENDIF} + +{$IFDEF ENABLE_SYSTEM} + procedure CharPress (C: AnsiChar); + {$IFDEF ENABLE_MENU} + var Msg: g_gui.TMessage; + {$ENDIF} + var a: Integer; + begin + if gConsoleShow or gChatShow then + begin + g_Console_Char(C); + end + {$IFDEF ENABLE_MENU} + else if g_ActiveWindow <> nil then + begin + Msg.Msg := WM_CHAR; + Msg.WParam := Ord(C); + g_ActiveWindow.OnMessage(Msg); + end + {$ENDIF} + else + begin + for a := 0 to 14 do + begin + charbuff[a] := charbuff[a + 1]; + end; + charbuff[15] := upcase1251(C); + Cheat; + end; + end; +{$ENDIF} // ////////////////////////////////////////////////////////////////////////// // @@ -551,7 +916,6 @@ var UPSTime: LongWord; DataLoaded: Boolean = False; MessageTime: Word; - MessageLineLength: Integer = 80; MapList: SSArray = nil; MapIndex: Integer = -1; InterReadyTime: Integer = -1; @@ -560,22 +924,7 @@ var info: TMegaWADInfo; endpic: String; endmus: String; - res: record - text: Array of ShortString; - anim: Array of ShortString; - pic: Array of ShortString; - mus: Array of ShortString; - end; - triggers: Array of record - event: ShortString; - actions: Array of record - action, p1, p2: Integer; - end; - end; - cur_trigger: Integer; - cur_action: Integer; end; - //InterPic: String; InterText: record lines: SSArray; img: String; @@ -679,12 +1028,9 @@ end; procedure ClearDebugCvars(); begin - g_debug_Sounds := False; - g_debug_Frames := False; g_debug_WinMsgs := False; g_debug_MonsterOff := False; g_debug_BotAIOff := 0; - g_debug_HealthBar := False; g_Debug_Player := False; end; @@ -776,37 +1122,20 @@ begin FreeMem(p); end; -procedure g_Game_FreeWAD(); -var - a: Integer; -begin - for a := 0 to High(MegaWAD.res.pic) do - if MegaWAD.res.pic[a] <> '' then - g_Texture_Delete(MegaWAD.res.pic[a]); - - for a := 0 to High(MegaWAD.res.mus) do - if MegaWAD.res.mus[a] <> '' then - g_Sound_Delete(MegaWAD.res.mus[a]); - - MegaWAD.res.pic := nil; - MegaWAD.res.text := nil; - MegaWAD.res.anim := nil; - MegaWAD.res.mus := nil; - MegaWAD.triggers := nil; - - g_Texture_Delete('TEXTURE_endpic'); - g_Sound_Delete('MUSIC_endmus'); - - ZeroMemory(@MegaWAD, SizeOf(MegaWAD)); - gGameSettings.WAD := ''; -end; + procedure g_Game_FreeWAD; + begin + EndPicPath := ''; + g_Sound_Delete('MUSIC_endmus'); + ZeroMemory(@MegaWAD, SizeOf(MegaWAD)); + gGameSettings.WAD := ''; + end; procedure g_Game_LoadWAD(WAD: string); var w: TWADFile; cfg: TConfig; p: Pointer; - {b, }len: Integer; + len: Integer; s: AnsiString; begin g_Game_FreeWAD(); @@ -827,40 +1156,11 @@ begin cfg := TConfig.CreateMem(p, len); - {b := 1; - while True do - begin - s := cfg.ReadStr('pic', 'pic'+IntToStr(b), ''); - if s = '' then Break; - b := b+1; - - SetLength(MegaWAD.res.pic, Length(MegaWAD.res.pic)+1); - MegaWAD.res.pic[High(MegaWAD.res.pic)] := s; - - g_Texture_CreateWADEx(s, s); - end; - - b := 1; - while True do - begin - s := cfg.ReadStr('mus', 'mus'+IntToStr(b), ''); - if s = '' then Break; - b := b+1; - - SetLength(MegaWAD.res.mus, Length(MegaWAD.res.mus)+1); - MegaWAD.res.mus[High(MegaWAD.res.mus)] := s; - - g_Music_CreateWADEx(s, s); - end;} - + EndPicPath := ''; MegaWAD.endpic := cfg.ReadStr('megawad', 'endpic', ''); if MegaWAD.endpic <> '' then - begin - TEXTUREFILTER := GL_LINEAR; - s := e_GetResourcePath(WadDirs, MegaWAD.endpic, WAD); - g_Texture_CreateWADEx('TEXTURE_endpic', s); - TEXTUREFILTER := GL_NEAREST; - end; + EndPicPath := e_GetResourcePath(WadDirs, MegaWAD.endpic, WAD); + MegaWAD.endmus := cfg.ReadStr('megawad', 'endmus', 'Standart.wad:D2DMUS\КОНЕЦ'); if MegaWAD.endmus <> '' then begin @@ -937,7 +1237,7 @@ begin gDelayedEvents[n].DENum := Num; gDelayedEvents[n].DEStr := Str; if DEType = DE_GLOBEVENT then - gDelayedEvents[n].Time := (sys_GetTicks() {div 1000}) + Time + gDelayedEvents[n].Time := (GetTickCount64() {div 1000}) + Time else gDelayedEvents[n].Time := gTime + Time; Result := n; @@ -963,7 +1263,10 @@ begin MessageText := ''; EndingGameCounter := 0; + +{$IFDEF ENABLE_MENU} g_ActiveWindow := nil; +{$ENDIF} gLMSRespawn := LMS_RESPAWN_NONE; gLMSRespawnTime := 0; @@ -972,20 +1275,23 @@ begin EXIT_SIMPLE: // Выход через меню или конец теста begin g_Game_Free(); - if gMapOnce then - begin // Это был тест - g_Game_Quit(); - end + begin // Это был тест + g_Game_Quit(); + end else - begin // Выход в главное меню + begin // Выход в главное меню + {$IFDEF DISABLE_MENU} + gState := STATE_MENU; // ??? + {$ELSE} gMusic.SetByName('MUSIC_MENU'); gMusic.Play(); if gState <> STATE_SLIST then begin g_GUI_ShowWindow('MainMenu'); gState := STATE_MENU; - end else + end + else begin // Обновляем список серверов slReturnPressed := True; @@ -998,9 +1304,9 @@ begin slWaitStr := _lc[I_NET_SLIST_ERROR]; g_Serverlist_GenerateTable(slCurrent, slTable); end; - - g_Game_ExecuteEvent('ongameend'); - end; + {$ENDIF} + g_Game_ExecuteEvent('ongameend'); + end; end; EXIT_RESTART: // Начать уровень сначала @@ -1115,12 +1421,6 @@ begin end; procedure g_Game_Init(); -var - SR: TSearchRec; - knownFiles: array of AnsiString = nil; - found: Boolean; - wext, s: AnsiString; - f: Integer; begin gExit := 0; gMapToDelete := ''; @@ -1129,65 +1429,6 @@ begin sfsGCDisable(); // temporary disable removing of temporary volumes try - TEXTUREFILTER := GL_LINEAR; - g_Texture_CreateWADEx('MENU_BACKGROUND', GameWAD+':TEXTURES\TITLE'); - g_Texture_CreateWADEx('INTER', GameWAD+':TEXTURES\INTER'); - g_Texture_CreateWADEx('ENDGAME_EN', GameWAD+':TEXTURES\ENDGAME_EN'); - g_Texture_CreateWADEx('ENDGAME_RU', GameWAD+':TEXTURES\ENDGAME_RU'); - TEXTUREFILTER := GL_NEAREST; - - LoadStdFont('STDTXT', 'STDFONT', gStdFont); - LoadFont('MENUTXT', 'MENUFONT', gMenuFont); - LoadFont('SMALLTXT', 'SMALLFONT', gMenuSmallFont); - - g_Game_ClearLoading(); - g_Game_SetLoadingText(Format('Doom 2D: Forever %s', [GAME_VERSION]), 0, False); - g_Game_SetLoadingText('', 0, False); - - g_Game_SetLoadingText(_lc[I_LOAD_CONSOLE], 0, False); - r_Console_Init; - g_Console_Init(); - - g_Game_SetLoadingText(_lc[I_LOAD_MODELS], 0, False); - r_PlayerModel_Initialize; - - // load models from all possible wad types, in all known directories - // this does a loosy job (linear search, ooph!), but meh - for wext in wadExtensions do - begin - for f := High(ModelDirs) downto Low(ModelDirs) do - begin - if (FindFirst(ModelDirs[f]+DirectorySeparator+'*'+wext, faAnyFile, SR) = 0) then - begin - repeat - found := false; - for s in knownFiles do - begin - if (strEquCI1251(forceFilenameExt(SR.Name, ''), forceFilenameExt(ExtractFileName(s), ''))) then - begin - found := true; - break; - end; - end; - if not found then - begin - SetLength(knownFiles, length(knownFiles)+1); - knownFiles[High(knownFiles)] := ModelDirs[f]+DirectorySeparator+SR.Name; - end; - until (FindNext(SR) <> 0); - end; - FindClose(SR); - end; - end; - - if (length(knownFiles) = 0) then raise Exception.Create('no player models found!'); - - if (length(knownFiles) = 1) then e_LogWriteln('1 player model found.', TMsgType.Notify) else e_LogWritefln('%d player models found.', [Integer(length(knownFiles))], TMsgType.Notify); - for s in knownFiles do - begin - if not g_PlayerModel_Load(s) then e_LogWritefln('Error loading model "%s"', [s], TMsgType.Warning); - end; - gGameOn := false; gPauseMain := false; gPauseHolmes := false; @@ -1195,7 +1436,6 @@ begin {e_MouseInfo.Accel := 1.0;} - g_Game_SetLoadingText(_lc[I_LOAD_GAME_DATA], 0, False); g_Game_LoadData(); g_Game_SetLoadingText(_lc[I_LOAD_MUSIC], 0, False); @@ -1204,11 +1444,6 @@ begin g_Sound_CreateWADEx('MUSIC_ROUNDMUS', GameWAD+':MUSIC\ROUNDMUS', True, True); g_Sound_CreateWADEx('MUSIC_STDENDMUS', GameWAD+':MUSIC\ENDMUS', True); -{$IFNDEF HEADLESS} - g_Game_SetLoadingText(_lc[I_LOAD_MENUS], 0, False); - g_Menu_Init(); -{$ENDIF} - gMusic := TMusic.Create(); gMusic.SetByName('MUSIC_MENU'); gMusic.Play(); @@ -1236,7 +1471,16 @@ begin g_Map_Free(freeTextures); g_Player_Free(); - g_Player_RemoveAllCorpses(); + + {$IFDEF ENABLE_GIBS} + g_Gibs_RemoveAll; + {$ENDIF} + {$IFDEF ENABLE_SHELLS} + g_Shells_RemoveAll; + {$ENDIF} + {$IFDEF ENABLE_CORPSES} + g_Corpses_RemoveAll; + {$ENDIF} gGameSettings.GameType := GT_NONE; if gGameSettings.GameMode = GM_SINGLE then @@ -1438,6 +1682,7 @@ begin end end; +{$IFDEF ENABLE_MENU} // HACK: add dynlight here if gwin_k8_enable_light_experiments then begin @@ -1452,6 +1697,7 @@ begin end; if gwin_has_stencil and g_playerLight then g_AddDynLight(plr.GameX+32, plr.GameY+40, 128, 1, 1, 0, 0.6); +{$ENDIF} end; // HACK: don't have a "key was pressed" function @@ -1473,13 +1719,69 @@ begin g_Weapon_PreUpdate(); end; + procedure g_Game_SetupHearPoints; + var p1, p2: TPlayer; a, b: Integer; + begin + p1 := nil; + p2 := nil; + gHearPoint1.Active := false; + gHearPoint2.Active := false; + if gSpectMode = SPECT_MAPVIEW then + begin + // TODO something better (render dependency) + gHearPoint1.Active := true; + gHearPoint1.Coords.X := gSpectX + gScreenWidth div 2; + gHearPoint1.Coords.Y := gSpectY + gScreenHeight div 2; + end + else if gSpectMode = SPECT_PLAYERS then + begin + p1 := g_Player_Get(gSpectPID1); + if gSpectViewTwo then + p2 := g_Player_Get(gSpectPID2); + end + else if gSpectMode = SPECT_NONE then + begin + p1 := gPlayer1; + p2 := gPlayer2; + end; + if p1 <> nil then + begin + gHearPoint1.Active := true; + gHearPoint1.Coords.X := p1.obj.x + p1.obj.rect.width div 2; + gHearPoint1.Coords.Y := p1.obj.y + p1.obj.rect.height div 2; + end; + if (p2 <> nil) and (p1 <> p2) then + begin + gHearPoint2.Active := true; + gHearPoint2.Coords.X := p2.obj.x + p2.obj.rect.width div 2; + gHearPoint2.Coords.Y := p2.obj.y + p2.obj.rect.height div 2; + end; + // TODO something better (render dependency) + if (p1 <> nil) and (p2 <> nil) then + begin + gPlayerScreenSize.X := gScreenWidth - 196; + gPlayerScreenSize.Y := gScreenHeight div 2; + end + else + begin + gPlayerScreenSize.X := gScreenWidth - 196; + gPlayerScreenSize.Y := gScreenHeight; + end; + // sound distance + if gMapInfo.Height > gPlayerScreenSize.Y then a := gMapInfo.Height - gPlayerScreenSize.Y else a := gMapInfo.Height; + if gMapInfo.Width > gPlayerScreenSize.X then b := gMapInfo.Width - gPlayerScreenSize.X else b := gMapInfo.Width; + gMaxDist := Trunc(Hypot(a, b)); + end; + procedure g_Game_Update(); -var - Msg: g_gui.TMessage; - Time: Int64; - a: Byte; - w: Word; - i, b: Integer; + var + {$IFDEF ENABLE_MENU} + Msg: g_gui.TMessage; + w: Word; + {$ENDIF} + Time: Int64; + a: Byte; + i, b: Integer; function sendMonsPos (mon: TMonster): Boolean; begin @@ -1518,6 +1820,8 @@ var var reliableUpdate: Boolean; + rSpectX0, rSpectY0: Integer; + rSpectX1, rSpectY1: Integer; begin g_ResetDynlights(); framePool.reset(); @@ -1537,7 +1841,6 @@ begin // no need to, as we'll do it in event handler // Обновляем консоль (движение и сообщения): - r_Console_Update; g_Console_Update(); if (NetMode = NET_NONE) and (g_Game_IsNet) and (gGameOn or (gState in [STATE_FOLD, STATE_INTERCUSTOM])) then @@ -1577,7 +1880,9 @@ begin e_KeyPressed(JOY2_ATTACK) or e_KeyPressed(JOY3_ATTACK) ) and (not gJustChatted) and (not gConsoleShow) and (not gChatShow) +{$IFDEF ENABLE_MENU} and (g_ActiveWindow = nil) +{$ENDIF} ) or (g_Game_IsNet and ((gInterTime > gInterEndTime) or ((gInterReadyCount >= NetClientCount) and (NetClientCount > 0)))) ) @@ -1596,9 +1901,11 @@ begin begin // Выход в главное меню: g_Game_Free; +{$IFDEF ENABLE_MENU} g_GUI_ShowWindow('MainMenu'); gMusic.SetByName('MUSIC_MENU'); gMusic.Play(); +{$ENDIF} gState := STATE_MENU; end else begin @@ -1624,7 +1931,9 @@ begin e_KeyPressed(JOY2_ATTACK) or e_KeyPressed(JOY3_ATTACK) ) and (not gJustChatted) and (not gConsoleShow) and (not gChatShow) +{$IFDEF ENABLE_MENU} and (g_ActiveWindow = nil) +{$ENDIF} ) then begin @@ -1685,7 +1994,22 @@ begin // Статистика по Tab: if gGameOn then + begin IsDrawStat := (not gConsoleShow) and (not gChatShow) and (gGameSettings.GameType <> GT_SINGLE) and g_Console_Action(ACTION_SCORES); + end + else + begin + if g_Console_Action(ACTION_SCORES) then + begin + if not gStatsPressed then + begin + gStatsOff := not gStatsOff; + gStatsPressed := True; + end; + end + else + gStatsPressed := False; + end; // Игра идет: if gGameOn and not gPause and (gState <> STATE_FOLD) then @@ -1758,7 +2082,11 @@ begin // Обрабатываем клавиши игроков: if gPlayer1 <> nil then gPlayer1.ReleaseKeys(); if gPlayer2 <> nil then gPlayer2.ReleaseKeys(); +{$IFDEF DISABLE_MENU} + if (not gConsoleShow) and (not gChatShow) then +{$ELSE} if (not gConsoleShow) and (not gChatShow) and (g_ActiveWindow = nil) then +{$ENDIF} begin ProcessPlayerControls(gPlayer1, 0, P1MoveButton); ProcessPlayerControls(gPlayer2, 1, P2MoveButton); @@ -1770,9 +2098,21 @@ begin // process weapon switch queue end; // if server - // Наблюдатель - if (gPlayer1 = nil) and (gPlayer2 = nil) and - (not gConsoleShow) and (not gChatShow) and (g_ActiveWindow = nil) then + // Spectator + + {$IFDEF ENABLE_RENDER} + r_Render_GetSpectatorLimits(rSpectX0, rSpectY0, rSpectX1, rSpectY1); + {$ELSE} + rSpectX0 := 0; rSpectY0 := 0; + rSpectX1 := gMapInfo.Width - 1; rSpectY1 := gMapInfo.Height - 1; + {$ENDIF} + + if (gPlayer1 = nil) and (gPlayer2 = nil) + and (not gConsoleShow) and (not gChatShow) +{$IFDEF ENABLE_MENU} + and (g_ActiveWindow = nil) +{$ENDIF} + then begin if not gSpectKeyPress then begin @@ -1790,14 +2130,10 @@ begin if (gSpectMode = SPECT_MAPVIEW) and (not gSpectAuto) then begin - if gPlayerAction[0, ACTION_MOVELEFT] then - gSpectX := Max(gSpectX - gSpectStep, 0); - if gPlayerAction[0, ACTION_MOVERIGHT] then - gSpectX := Min(gSpectX + gSpectStep, gMapInfo.Width - gScreenWidth); - if gPlayerAction[0, ACTION_LOOKUP] then - gSpectY := Max(gSpectY - gSpectStep, 0); - if gPlayerAction[0, ACTION_LOOKDOWN] then - gSpectY := Min(gSpectY + gSpectStep, gMapInfo.Height - gScreenHeight); + if gPlayerAction[0, ACTION_MOVELEFT] then gSpectX := gSpectX - gSpectStep; + if gPlayerAction[0, ACTION_MOVERIGHT] then gSpectX := gSpectX + gSpectStep; + if gPlayerAction[0, ACTION_LOOKUP] then gSpectY := gSpectY - gSpectStep; + if gPlayerAction[0, ACTION_LOOKDOWN] then gSpectY := gSpectY + gSpectStep; if gWeaponAction[0, WP_PREV] then begin // decrease step @@ -1882,12 +2218,12 @@ begin begin if gSpectMode = SPECT_MAPVIEW then begin - i := Min(Max(gSpectX + gSpectAutoStepX, 0), gMapInfo.Width - gScreenWidth); + i := Min(Max(gSpectX + gSpectAutoStepX, rSpectX0), rSpectX1); if i = gSpectX then gSpectAutoNext := gTime else gSpectX := i; - i := Min(Max(gSpectY + gSpectAutoStepY, 0), gMapInfo.Height - gScreenHeight); + i := Min(Max(gSpectY + gSpectAutoStepY, rSpectY0), rSpectY1); if i = gSpectY then gSpectAutoNext := gTime else @@ -1901,15 +2237,15 @@ begin case gSpectMode of SPECT_MAPVIEW: begin - gSpectX := Random(gMapInfo.Width - gScreenWidth); - gSpectY := Random(gMapInfo.Height - gScreenHeight); + gSpectX := rSpectX0 + Random(rSpectX1 - rSpectX0); + gSpectY := rSpectY0 + Random(rSpectY1 - rSpectY0); gSpectAutoStepX := Random(9) - 4; gSpectAutoStepY := Random(9) - 4; - if ((gSpectX < 800) and (gSpectAutoStepX < 0)) or - ((gSpectX > gMapInfo.Width - gScreenWidth - 800) and (gSpectAutoStepX > 0)) then + if ((gSpectX < rSpectX0) and (gSpectAutoStepX < 0)) or + ((gSpectX > rSpectX1) and (gSpectAutoStepX > 0)) then gSpectAutoStepX := gSpectAutoStepX * -1; - if ((gSpectY < 800) and (gSpectAutoStepY < 0)) or - ((gSpectY > gMapInfo.Height - gScreenHeight - 800) and (gSpectAutoStepY > 0)) then + if ((gSpectY < rSpectY0) and (gSpectAutoStepY < 0)) or + ((gSpectY > rSpectY1) and (gSpectAutoStepY > 0)) then gSpectAutoStepY := gSpectAutoStepY * -1; end; SPECT_PLAYERS: @@ -1925,17 +2261,56 @@ begin end; end; end; + + if gSpectMode = SPECT_MAPVIEW then + begin + gSpectX := Max(gSpectX, rSpectX0); + gSpectX := Min(gSpectX, rSpectX1); + gSpectY := Max(gSpectY, rSpectY0); + gSpectY := Min(gSpectY, rSpectY1); + end; end; + (* spectator state check from render *) + + if (gPlayer1 = nil) and (gPlayer2 = nil) then + begin + (* no local players -> automatically enable to spectator mode *) + if gSpectMode = SPECT_NONE then gSpectMode := SPECT_STATS; + end + else + begin + (* at least one local player -> automatically disable spectator mode *) + gSpectMode := SPECT_NONE; + end; + + if IsActivePlayer(g_Player_Get(gSpectPID1)) = false then + gSpectPID1 := GetActivePlayerID_Next(); + + if IsActivePlayer(g_Player_Get(gSpectPID2)) = false then + gSpectPID2 := GetActivePlayerID_Next(); + + g_Game_SetupHearPoints; + // Обновляем все остальное: g_Map_Update(); g_Items_Update(); g_Triggers_Update(); g_Weapon_Update(); g_Monsters_Update(); - g_GFX_Update(); + {$IFDEF ENABLE_GFX} + g_GFX_Update; + {$ENDIF} g_Player_UpdateAll(); - g_Player_UpdatePhysicalObjects(); + {$IFDEF ENABLE_GIBS} + g_Gibs_Update; + {$ENDIF} + {$IFDEF ENABLE_CORPSES} + g_Corpses_Update; + {$ENDIF} + {$IFDEF ENABLE_SHELLS} + g_Shells_Update; + {$ENDIF} // server: send newly spawned monsters unconditionally if (gGameSettings.GameType = GT_SERVER) then @@ -2026,6 +2401,7 @@ begin end; // if gameOn ... // Активно окно интерфейса - передаем клавиши ему: +{$IFDEF ENABLE_MENU} if g_ActiveWindow <> nil then begin w := e_GetFirstKeyPressed(); @@ -2044,8 +2420,10 @@ begin // Нужно сменить разрешение: if gResolutionChange then begin - e_WriteLog('Changing resolution', TMsgType.Notify); - g_Game_ChangeResolution(gRC_Width, gRC_Height, gRC_FullScreen, gRC_Maximized); + {$IFDEF ENABLE_RENDER} + e_WriteLog('Changing resolution', TMsgType.Notify); + r_Render_Apply; + {$ENDIF} gResolutionChange := False; g_ActiveWindow := nil; end; @@ -2056,9 +2434,7 @@ begin //e_WriteLog('Read language file', MSG_NOTIFY); //g_Language_Load(DataDir + gLanguage + '.txt'); g_Language_Set(gLanguage); -{$IFNDEF HEADLESS} g_Menu_Reset(); -{$ENDIF} gLanguageChange := False; end; end; @@ -2071,8 +2447,9 @@ begin begin KeyPress(IK_F10); end; +{$ENDIF} - Time := sys_GetTicks() {div 1000}; + Time := GetTickCount64() {div 1000}; // Обработка отложенных событий: if gDelayedEvents <> nil then @@ -2177,61 +2554,12 @@ begin end; procedure g_Game_LoadData(); -var - wl, hl: Integer; - wr, hr: Integer; - wb, hb: Integer; - wm, hm: Integer; begin if DataLoaded then Exit; e_WriteLog('Loading game data...', TMsgType.Notify); + g_Game_SetLoadingText(_lc[I_LOAD_GAME_DATA], 0, False); - g_Texture_CreateWADEx('NOTEXTURE', GameWAD+':TEXTURES\NOTEXTURE'); - g_Texture_CreateWADEx('TEXTURE_PLAYER_HUD', GameWAD+':TEXTURES\HUD'); - g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDAIR', GameWAD+':TEXTURES\AIRBAR'); - g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDJET', GameWAD+':TEXTURES\JETBAR'); - g_Texture_CreateWADEx('TEXTURE_PLAYER_HUDBG', GameWAD+':TEXTURES\HUDBG'); - g_Texture_CreateWADEx('TEXTURE_PLAYER_ARMORHUD', GameWAD+':TEXTURES\ARMORHUD'); - g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG', GameWAD+':TEXTURES\FLAGHUD_R_BASE'); - g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_S', GameWAD+':TEXTURES\FLAGHUD_R_STOLEN'); - g_Texture_CreateWADEx('TEXTURE_PLAYER_REDFLAG_D', GameWAD+':TEXTURES\FLAGHUD_R_DROP'); - g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG', GameWAD+':TEXTURES\FLAGHUD_B_BASE'); - g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_S', GameWAD+':TEXTURES\FLAGHUD_B_STOLEN'); - g_Texture_CreateWADEx('TEXTURE_PLAYER_BLUEFLAG_D', GameWAD+':TEXTURES\FLAGHUD_B_DROP'); - g_Texture_CreateWADEx('TEXTURE_PLAYER_TALKBUBBLE', GameWAD+':TEXTURES\TALKBUBBLE'); - g_Texture_CreateWADEx('TEXTURE_PLAYER_INVULPENTA', GameWAD+':TEXTURES\PENTA'); - g_Texture_CreateWADEx('TEXTURE_PLAYER_INDICATOR', GameWAD+':TEXTURES\PLRIND'); - - hasPBarGfx := true; - if not g_Texture_CreateWADEx('UI_GFX_PBAR_LEFT', GameWAD+':TEXTURES\LLEFT') then hasPBarGfx := false; - if not g_Texture_CreateWADEx('UI_GFX_PBAR_MARKER', GameWAD+':TEXTURES\LMARKER') then hasPBarGfx := false; - if not g_Texture_CreateWADEx('UI_GFX_PBAR_MIDDLE', GameWAD+':TEXTURES\LMIDDLE') then hasPBarGfx := false; - if not g_Texture_CreateWADEx('UI_GFX_PBAR_RIGHT', GameWAD+':TEXTURES\LRIGHT') then hasPBarGfx := false; - - if hasPBarGfx then - begin - g_Texture_GetSize('UI_GFX_PBAR_LEFT', wl, hl); - g_Texture_GetSize('UI_GFX_PBAR_RIGHT', wr, hr); - g_Texture_GetSize('UI_GFX_PBAR_MIDDLE', wb, hb); - g_Texture_GetSize('UI_GFX_PBAR_MARKER', wm, hm); - if (wl > 0) and (hl > 0) and (wr > 0) and (hr = hl) and (wb > 0) and (hb = hl) and (wm > 0) and (hm > 0) and (hm <= hl) then - begin - // yay! - end - else - begin - hasPBarGfx := false; - end; - end; - - g_Frames_CreateWAD(nil, 'FRAMES_TELEPORT', GameWAD+':TEXTURES\TELEPORT', 64, 64, 10, False); - g_Frames_CreateWAD(nil, 'FRAMES_PUNCH', GameWAD+':WEAPONS\PUNCH', 64, 64, 4, False); - g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_UP', GameWAD+':WEAPONS\PUNCH_UP', 64, 64, 4, False); - g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_DN', GameWAD+':WEAPONS\PUNCH_DN', 64, 64, 4, False); - g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK', GameWAD+':WEAPONS\PUNCHB', 64, 64, 4, False); - g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK_UP', GameWAD+':WEAPONS\PUNCHB_UP', 64, 64, 4, False); - g_Frames_CreateWAD(nil, 'FRAMES_PUNCH_BERSERK_DN', GameWAD+':WEAPONS\PUNCHB_DN', 64, 64, 4, False); g_Sound_CreateWADEx('SOUND_GAME_TELEPORT', GameWAD+':SOUNDS\TELEPORT'); g_Sound_CreateWADEx('SOUND_GAME_NOTELEPORT', GameWAD+':SOUNDS\NOTELEPORT'); g_Sound_CreateWADEx('SOUND_GAME_SECRET', GameWAD+':SOUNDS\SECRET'); @@ -2313,10 +2641,8 @@ begin g_Game_LoadChatSounds(GameWAD+':CHATSND\SNDCFG'); - g_Game_SetLoadingText(_lc[I_LOAD_ITEMS_DATA], 0, False); g_Items_LoadData(); - g_Game_SetLoadingText(_lc[I_LOAD_WEAPONS_DATA], 0, False); g_Weapon_LoadData(); g_Monsters_LoadData(); @@ -2329,13 +2655,10 @@ begin g_Game_StopAllSounds(True); gMusic.Free(); g_Game_FreeData(); - r_PlayerModel_Finalize; g_PlayerModel_FreeData(); - g_Texture_DeleteAll(); - g_Frames_DeleteAll(); -{$IFNDEF HEADLESS} - //g_Menu_Free(); //k8: this segfaults after resolution change; who cares? -{$ENDIF} + {$IFDEF ENABLE_MENU} + // g_Menu_Free(); //k8: this segfaults after resolution change; who cares? + {$ENDIF} if NetInitDone then g_Net_Free; @@ -2344,7 +2667,10 @@ begin g_Game_DeleteTestMap(); gExit := EXIT_QUIT; - sys_RequestQuit; + + {$IFDEF ENABLE_SYSTEM} + sys_RequestQuit; + {$ENDIF} end; procedure g_Game_FreeData(); @@ -2357,25 +2683,6 @@ begin e_WriteLog('Releasing game data...', TMsgType.Notify); - g_Texture_Delete('NOTEXTURE'); - g_Texture_Delete('TEXTURE_PLAYER_HUD'); - g_Texture_Delete('TEXTURE_PLAYER_HUDBG'); - g_Texture_Delete('TEXTURE_PLAYER_ARMORHUD'); - g_Texture_Delete('TEXTURE_PLAYER_REDFLAG'); - g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_S'); - g_Texture_Delete('TEXTURE_PLAYER_REDFLAG_D'); - g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG'); - g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_S'); - g_Texture_Delete('TEXTURE_PLAYER_BLUEFLAG_D'); - g_Texture_Delete('TEXTURE_PLAYER_TALKBUBBLE'); - g_Texture_Delete('TEXTURE_PLAYER_INVULPENTA'); - g_Frames_DeleteByName('FRAMES_TELEPORT'); - g_Frames_DeleteByName('FRAMES_PUNCH'); - g_Frames_DeleteByName('FRAMES_PUNCH_UP'); - g_Frames_DeleteByName('FRAMES_PUNCH_DN'); - g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK'); - g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK_UP'); - g_Frames_DeleteByName('FRAMES_PUNCH_BERSERK_DN'); g_Sound_Delete('SOUND_GAME_TELEPORT'); g_Sound_Delete('SOUND_GAME_NOTELEPORT'); g_Sound_Delete('SOUND_GAME_SECRET'); @@ -2455,50 +2762,6 @@ begin e_WriteLog(Format(_lc[I_SIMPLE_ERROR], [Text]), TMsgType.Warning); end; -procedure g_Game_SetupScreenSize(); -const - RES_FACTOR = 4.0 / 3.0; -var - s: Single; - rf: Single; - bw, bh: Word; -begin -// Размер экранов игроков: - gPlayerScreenSize.X := gScreenWidth-196; - if (gPlayer1 <> nil) and (gPlayer2 <> nil) then - gPlayerScreenSize.Y := gScreenHeight div 2 - else - gPlayerScreenSize.Y := gScreenHeight; - -// Размер заднего плана: - if BackID <> DWORD(-1) then - begin - s := SKY_STRETCH; - if (gScreenWidth*s > gMapInfo.Width) or - (gScreenHeight*s > gMapInfo.Height) then - begin - gBackSize.X := gScreenWidth; - gBackSize.Y := gScreenHeight; - end - else - begin - e_GetTextureSize(BackID, @bw, @bh); - rf := Single(bw) / Single(bh); - if (rf > RES_FACTOR) then bw := Round(Single(bh) * RES_FACTOR) - else if (rf < RES_FACTOR) then bh := Round(Single(bw) / RES_FACTOR); - s := Max(gScreenWidth / bw, gScreenHeight / bh); - if (s < 1.0) then s := 1.0; - gBackSize.X := Round(bw*s); - gBackSize.Y := Round(bh*s); - end; - end; -end; - -procedure g_Game_ChangeResolution(newWidth, newHeight: Word; nowFull, nowMax: Boolean); -begin - sys_SetDisplayMode(newWidth, newHeight, gBPP, nowFull, nowMax); -end; - procedure g_Game_AddPlayer(Team: Byte = TEAM_NONE); begin if ((not gGameOn) and (gState <> STATE_INTERCUSTOM)) @@ -2668,9 +2931,6 @@ begin g_Game_ExecuteEvent('ongamestart'); -// Установка размеров окон игроков: - g_Game_SetupScreenSize(); - // Создание первого игрока: gPlayer1 := g_Player_Get(g_Player_Create(gPlayer1Settings.Model, gPlayer1Settings.Color, @@ -2760,9 +3020,6 @@ begin g_Game_ExecuteEvent('ongamestart'); -// Установка размеров окон игроков: - g_Game_SetupScreenSize(); - // Режим наблюдателя: if nPlayers = 0 then begin @@ -2874,9 +3131,6 @@ begin g_Game_ExecuteEvent('ongamestart'); -// Установка размеров окна игрока - g_Game_SetupScreenSize(); - // Режим наблюдателя: if nPlayers = 0 then begin @@ -2998,9 +3252,6 @@ begin g_Game_ExecuteEvent('ongamestart'); -// Установка размеров окон игроков: - g_Game_SetupScreenSize(); - NetState := NET_STATE_AUTH; g_Game_SetLoadingText(_lc[I_LOAD_CONNECT], 0, False); @@ -3197,7 +3448,16 @@ var nws: AnsiString; begin g_Map_Free((Map <> gCurrentMapFileName) and (oldMapPath <> gCurrentMapFileName)); - g_Player_RemoveAllCorpses(); + + {$IFDEF ENABLE_GIBS} + g_Gibs_RemoveAll; + {$ENDIF} + {$IFDEF ENABLE_SHELLS} + g_Shells_RemoveAll; + {$ENDIF} + {$IFDEF ENABLE_CORPSES} + g_Corpses_RemoveAll; + {$ENDIF} if (not g_Game_IsClient) and (gSwitchGameMode <> gGameSettings.GameMode) and @@ -3269,14 +3529,20 @@ begin end; if Result then begin + {$IFDEF ENABLE_RENDER} + r_Render_LoadTextures; + r_Render_Reset; + {$ENDIF} g_Player_ResetAll(Force or gLastMap, gGameSettings.GameType = GT_SINGLE); gState := STATE_NONE; - g_ActiveWindow := nil; + {$IFDEF ENABLE_MENU} + g_ActiveWindow := nil; + {$ENDIF} gGameOn := True; DisableCheats(); - ResetTimer(); + wNeedTimeReset := True; if gGameSettings.GameMode = GM_CTF then begin @@ -3522,7 +3788,16 @@ begin Exit; end; - g_Player_RemoveAllCorpses; + {$IFDEF ENABLE_GIBS} + g_Gibs_RemoveAll; + {$ENDIF} + {$IFDEF ENABLE_SHELLS} + g_Shells_RemoveAll; + {$ENDIF} + {$IFDEF ENABLE_CORPSES} + g_Corpses_RemoveAll; + {$ENDIF} + g_Game_Message(_lc[I_MESSAGE_LMS_START], 144); if g_Game_IsNet then MH_SEND_GameEvent(NET_EV_LMS_START); @@ -3881,12 +4156,18 @@ begin begin if Length(p) = 2 then begin - a := Max(0, StrToIntDef(p[1], 0)); - g_GFX_SetMax(a) + {$IFDEF ENABLE_GFX} + a := Max(0, StrToIntDef(p[1], 0)); + g_GFX_SetMax(a) + {$ENDIF} end else if Length(p) = 1 then begin - e_LogWritefln('%s', [g_GFX_GetMax()]) + {$IFDEF ENABLE_GFX} + e_LogWritefln('%s', [g_GFX_GetMax()]) + {$ELSE} + e_LogWritefln('%s', [0]) + {$ENDIF} end else begin @@ -3897,12 +4178,18 @@ begin begin if Length(p) = 2 then begin - a := Max(0, StrToIntDef(p[1], 0)); - g_Shells_SetMax(a) + {$IFDEF ENABLE_SHELLS} + a := Max(0, StrToIntDef(p[1], 0)); + g_Shells_SetMax(a) + {$ENDIF} end else if Length(p) = 1 then begin - e_LogWritefln('%s', [g_Shells_GetMax()]) + {$IFDEF ENABLE_SHELLS} + e_LogWritefln('%s', [g_Shells_GetMax()]) + {$ELSE} + e_LogWritefln('%s', [0]) + {$ENDIF} end else begin @@ -3913,12 +4200,18 @@ begin begin if Length(p) = 2 then begin - a := Max(0, StrToIntDef(p[1], 0)); - g_Gibs_SetMax(a) + {$IFDEF ENABLE_GIBS} + a := Max(0, StrToIntDef(p[1], 0)); + g_Gibs_SetMax(a) + {$ENDIF} end else if Length(p) = 1 then begin - e_LogWritefln('%s', [g_Gibs_GetMax()]) + {$IFDEF ENABLE_GIBS} + e_LogWritefln('%s', [g_Gibs_GetMax()]) + {$ELSE} + e_LogWritefln('%s', [0]) + {$ENDIF} end else begin @@ -3929,12 +4222,18 @@ begin begin if Length(p) = 2 then begin - a := Max(0, StrToIntDef(p[1], 0)); - g_Corpses_SetMax(a) + {$IFDEF ENABLE_CORPSES} + a := Max(0, StrToIntDef(p[1], 0)); + g_Corpses_SetMax(a) + {$ENDIF} end else if Length(p) = 1 then begin - e_LogWritefln('%s', [g_Corpses_GetMax()]) + {$IFDEF ENABLE_CORPSES} + e_LogWritefln('%s', [g_Corpses_GetMax()]) + {$ELSE} + e_LogWritefln('%s', [0]) + {$ENDIF} end else begin @@ -4385,22 +4684,6 @@ begin g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth, gScreenHeight])); g_Console_Add(Format('gScreenWidth = %d, gScreenHeight = %d', [gScreenWidth, gScreenHeight])); end - else if cmd = 'd_sounds' then - begin - if (Length(P) > 1) and - ((P[1] = '1') or (P[1] = '0')) then - g_Debug_Sounds := (P[1][1] = '1'); - - g_Console_Add(Format('d_sounds is %d', [Byte(g_Debug_Sounds)])); - end - else if cmd = 'd_frames' then - begin - if (Length(P) > 1) and - ((P[1] = '1') or (P[1] = '0')) then - g_Debug_Frames := (P[1][1] = '1'); - - g_Console_Add(Format('d_frames is %d', [Byte(g_Debug_Frames)])); - end else if cmd = 'd_winmsg' then begin if (Length(P) > 1) and @@ -4471,14 +4754,6 @@ begin end; end; end - else if (cmd = 'd_health') then - begin - if (Length(P) > 1) and - ((P[1] = '1') or (P[1] = '0')) then - g_debug_HealthBar := (P[1][1] = '1'); - - g_Console_Add(Format('d_health is %d', [Byte(g_debug_HealthBar)])); - end else if (cmd = 'd_player') then begin if (Length(P) > 1) and @@ -4730,8 +5005,12 @@ begin chstr := ''; if cmd = 'pause' then begin - if (g_ActiveWindow = nil) then + {$IFDEF ENABLE_MENU} + if (g_ActiveWindow = nil) then + g_Game_Pause(not gPauseMain); + {$ELSE} g_Game_Pause(not gPauseMain); + {$ENDIF} end else if cmd = 'endgame' then gExit := EXIT_SIMPLE @@ -5690,7 +5969,9 @@ begin end else if cmd = 'screenshot' then begin - g_TakeScreenShot() + {$IFDEF ENABLE_RENDER} + r_Render_RequestScreenShot; + {$ENDIF} end else if (cmd = 'weapnext') or (cmd = 'weapprev') then begin @@ -5974,17 +6255,10 @@ begin g_Game_Free(); g_Game_Quit(); end; +{$IFDEF ENABLE_RENDER} 'r_reset': - begin - gRC_Width := Max(1, gRC_Width); - gRC_Height := Max(1, gRC_Height); - gBPP := Max(1, gBPP); - if sys_SetDisplayMode(gRC_Width, gRC_Height, gBPP, gRC_FullScreen, gRC_Maximized) = True then - e_LogWriteln('resolution changed') - else - e_LogWriteln('resolution not changed'); - sys_EnableVSync(gVSync); - end; + r_Render_Apply; +{$ENDIF} 'r_maxfps': begin if Length(p) = 2 then @@ -6030,36 +6304,7 @@ begin end; end; -procedure g_TakeScreenShot(Filename: string = ''); - var s: TStream; t: TDateTime; dir, date, name: String; -begin - if e_NoGraphics then Exit; - try - dir := e_GetWriteableDir(ScreenshotDirs); - - if Filename = '' then - begin - t := Now; - DateTimeToString(date, 'yyyy-mm-dd-hh-nn-ss', t); - Filename := 'screenshot-' + date; - end; - - name := e_CatPath(dir, Filename + '.png'); - s := createDiskFile(name); - try - e_MakeScreenshot(s, gWinSizeX, gWinSizeY); - s.Free; - g_Console_Add(Format(_lc[I_CONSOLE_SCREENSHOT], [name])) - except - g_Console_Add(Format(_lc[I_CONSOLE_ERROR_WRITE], [name])); - s.Free; - DeleteFile(name) - end - except - g_Console_Add('oh shit, i can''t create screenshot!') - end -end; - +{$IFDEF ENABLE_MENU} procedure g_Game_InGameMenu(Show: Boolean); begin if (g_ActiveWindow = nil) and Show then @@ -6090,6 +6335,7 @@ begin g_Game_Pause(False); end; end; +{$ENDIF} procedure g_Game_Pause (Enable: Boolean); var @@ -6233,12 +6479,11 @@ begin end; end; -procedure g_Game_Message(Msg: string; Time: Word); -begin - MessageLineLength := (gScreenWidth - 204) div e_CharFont_GetMaxWidth(gMenuFont); - MessageText := b_Text_Wrap(b_Text_Format(Msg), MessageLineLength); - MessageTime := Time; -end; + procedure g_Game_Message (Msg: string; Time: Word); + begin + MessageText := Msg; + MessageTime := Time; + end; procedure g_Game_ChatSound(Text: String; Taunt: Boolean = True); const @@ -6510,78 +6755,6 @@ begin gCheats := True; end; -procedure g_Game_SetLoadingText(Text: String; Max: Integer; reWrite: Boolean); -var - i: Word; -begin - if Length(LoadingStat.Msgs) = 0 then - Exit; - - with LoadingStat do - begin - if not reWrite then - begin // Переходим на следующую строку или скроллируем: - if NextMsg = Length(Msgs) then - begin // scroll - for i := 0 to High(Msgs)-1 do - Msgs[i] := Msgs[i+1]; - end - else - Inc(NextMsg); - end else - if NextMsg = 0 then - Inc(NextMsg); - - Msgs[NextMsg-1] := Text; - CurValue := 0; - MaxValue := Max; - ShowCount := 0; - PBarWasHere := false; - end; - - g_ActiveWindow := nil; - ProcessLoading(True); -end; - -procedure g_Game_StepLoading(Value: Integer = -1); -begin - with LoadingStat do - begin - if Value = -1 then - begin - Inc(CurValue); - Inc(ShowCount); - end - else - CurValue := Value; - - if (ShowCount > LOADING_SHOW_STEP) or (Value > -1) then - begin - ShowCount := 0; - ProcessLoading(False); - end; - end; -end; - -procedure g_Game_ClearLoading(); -var - len: Word; -begin - with LoadingStat do - begin - CurValue := 0; - MaxValue := 0; - ShowCount := 0; - len := ((gScreenHeight div 3)*2 - 50) div LOADING_INTERLINE; - if len < 1 then len := 1; - SetLength(Msgs, len); - for len := Low(Msgs) to High(Msgs) do - Msgs[len] := ''; - NextMsg := 0; - PBarWasHere := false; - end; -end; - procedure Parse_Params(var pars: TParamStrValues); var i: Integer; @@ -6816,13 +6989,14 @@ begin conRegVar('pf_coldet', @g_profile_collision, 'draw collision detection profiles', 'coldet profiles'); conRegVar('pf_los', @g_profile_los, 'draw monster LOS profiles', 'monster LOS profiles'); - conRegVar('r_sq_draw', @gdbg_map_use_accel_render, 'accelerated spatial queries in rendering', 'accelerated rendering'); conRegVar('cd_sq_enabled', @gdbg_map_use_accel_coldet, 'accelerated spatial queries in map coldet', 'accelerated map coldet'); conRegVar('mon_sq_enabled', @gmon_debug_use_sqaccel, 'accelerated spatial queries for monsters', 'accelerated monster coldet'); conRegVar('wtrace_sq_enabled', @gwep_debug_fast_trace, 'accelerated spatial queries for weapon hitscan trace', 'accelerated weapon hitscan'); +{$IFDEF ENABLE_GFX} conRegVar('pr_enabled', @gpart_dbg_enabled, 'enable/disable particles', 'particles'); conRegVar('pr_phys_enabled', @gpart_dbg_phys_enabled, 'enable/disable particle physics', 'particle physics'); +{$ENDIF} conRegVar('los_enabled', @gmon_dbg_los_enabled, 'enable/disable monster LOS calculations', 'monster LOS', true); conRegVar('mon_think', @gmon_debug_think, 'enable/disable monster thinking', 'monster thinking', true); @@ -6833,9 +7007,6 @@ begin conRegVar('dbg_ignore_level_bounds', @g_dbg_ignore_bounds, 'ignore level bounds', '', false); - conRegVar('r_scale', @g_dbg_scale, 0.01, 100.0, 'render scale', '', false); - conRegVar('r_resolution_scale', @r_pixel_scale, 0.01, 100.0, 'upscale factor', '', false); - conRegVar('light_enabled', @gwin_k8_enable_light_experiments, 'enable/disable dynamic lighting', 'lighting'); conRegVar('light_player_halo', @g_playerLight, 'enable/disable player halo', 'player light halo');