Skip to content

Commit

Permalink
Merge pull request #374 from thecraftianman/replace-gamemode
Browse files Browse the repository at this point in the history
Replace gamemode with separate settings
  • Loading branch information
TwistedTail committed Sep 24, 2023
2 parents 11fefdc + f6193e1 commit bcd2f4b
Show file tree
Hide file tree
Showing 9 changed files with 137 additions and 123 deletions.
15 changes: 7 additions & 8 deletions lua/acf/core/globals.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ do -- ACF global vars
ACF.ModelData = ACF.ModelData or { Models = {} }

-- General Settings
ACF.Gamemode = 2 -- Gamemode of the server. 1 = Sandbox, 2 = Classic, 3 = Competitive
ACF.LegalChecks = true -- Whether or not IsLegal checks should be run on ACF entities
ACF.Year = 1945
ACF.IllegalDisableTime = 30 -- Time in seconds for an entity to be disabled when it fails ACF.IsLegal
ACF.RestrictInfo = true -- If enabled, players will be only allowed to get info from entities they're allowed to mess with.
Expand Down Expand Up @@ -103,7 +103,7 @@ do -- ACF global vars
ACF.CopperDensity = 8.96e-3 -- kg/cm^3

-- Debris
ACF.ChildDebris = 50 -- higher is more debris props; Chance = ACF.ChildDebris / num_children; Only applies to children of acf-killed parent props
ACF.ChildDebris = 50 -- Higher is more debris props; Chance = ACF.ChildDebris / num_children; Only applies to children of acf-killed parent props
ACF.DebrisIgniteChance = 0.25
ACF.ValidDebris = { -- Whitelist for things that can be turned into debris
acf_ammo = true,
Expand All @@ -121,13 +121,12 @@ do -- ACF global vars
ACF.GunInaccuracyBias = 2 -- Higher numbers make shots more likely to be inaccurate. Choose between 0.5 to 4. Default is 2 (unbiased).

-- Fuel
ACF.FuelRate = 1 --multiplier for fuel usage, 1.0 is approx real world
ACF.RequireFuel = true -- Whether or not fuel usage should be required for engines
ACF.FuelRate = 27.8 -- Multiplier for fuel usage, 1.0 is approx real world
ACF.FuelFactor = 1 -- Multiplier for ACF.FuelRate
ACF.CompFuelRate = 27.8 -- Extra multiplier for fuel consumption on servers with ACF Gamemode set to Competitive
ACF.CompFuelFactor = 1 -- Multiplier for ACF.CompFuelRate
ACF.TankVolumeMul = 1 -- multiplier for fuel tank capacity, 1.0 is approx real world
ACF.TankVolumeMul = 1 -- Multiplier for fuel tank capacity, 1.0 is approx real world
ACF.LiIonED = 0.458 -- li-ion energy density: kw hours / liter
ACF.RefillDistance = 300 --Distance in which ammo crate starts refilling.
ACF.RefillDistance = 300 -- Distance in which ammo crate starts refilling.
ACF.RefillSpeed = 700 -- (ACF.RefillSpeed / RoundMass) / Distance
ACF.RefuelSpeed = 20 -- Liters per second * ACF.FuelRate
end
Expand Down Expand Up @@ -287,4 +286,4 @@ do -- Smoke/Wind -----------------------------------
ACF.SmokeWind = net.ReadFloat()
end)
end
end ------------------------------------------------
end ------------------------------------------------
8 changes: 4 additions & 4 deletions lua/acf/core/validation_sv.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ local NoCollision = { -- These prevent ACF bullets from hitting an entity
end
]]--
function ACF.IsLegal(Entity)
if ACF.Gamemode == 1 then return true end -- Gamemode is set to Sandbox, legal checks don't apply
if not ACF.LegalChecks then return true end -- Legal checks are disabled

local Phys = Entity:GetPhysicsObject()

Expand Down Expand Up @@ -103,7 +103,7 @@ function ACF.CheckLegal(Entity)
return false
end

if ACF.Gamemode ~= 1 then
if ACF.LegalChecks then
TimerSimple(math.Rand(1, 3), function() -- Entity is legal... test again in random 1 to 3 seconds
if not IsValid(Entity) then return end

Expand Down Expand Up @@ -212,7 +212,7 @@ function ACF.Check(Entity, ForceUpdate) -- IsValid but for ACF
end

function ACF.Activate(Entity, Recalc)
--Density of steel = 7.8g cm3 so 7.8kg for a 1mx1m plate 1m thick
-- Density of steel = 7.8g cm3 so 7.8kg for a 1mx1m plate 1m thick
local PhysObj = Entity:GetPhysicsObject()

if not IsValid(PhysObj) then return end
Expand Down Expand Up @@ -246,4 +246,4 @@ end
-- Globalize ------------------------------------
ACF_CheckLegal = ACF.CheckLegal
ACF_Check = ACF.Check
ACF_Activate = ACF.Activate
ACF_Activate = ACF.Activate
6 changes: 3 additions & 3 deletions lua/acf/damage/permissions/permissions_sv.lua
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ hook.Add("Think", "ACF_DetectSZTransition", function()
plyzones[sid] = zone

if oldzone ~= zone then
hook.Call("ACF_PlayerChangedZone", GAMEMODE, ply, zone, oldzone)
hook.Run("ACF_PlayerChangedZone", ply, zone, oldzone)
end
end
end)
Expand Down Expand Up @@ -320,7 +320,7 @@ concommand.Add("ACF_SetPermissionMode", function(ply, _, args)
this.DefaultCanDamage = this.ModeDefaultAction[mode]
this.DamagePermission = this.Modes[mode]
printmsg(HUD_PRINTCONSOLE, "Command SUCCESSFUL: Current damage permission policy is now " .. mode .. "!")
hook.Call("ACF_ProtectionModeChanged", GAMEMODE, mode, oldmode)
hook.Run("ACF_ProtectionModeChanged", mode, oldmode)

return true
end
Expand Down Expand Up @@ -615,5 +615,5 @@ local m = table.KeyFromValue(this.Modes, this.DamagePermission)

if not m then
this.DamagePermission = function() end
hook.Call("ACF_ProtectionModeChanged", GAMEMODE, "default", nil)
hook.Run("ACF_ProtectionModeChanged", "default", nil)
end
117 changes: 75 additions & 42 deletions lua/acf/menu/data_callbacks.lua
Original file line number Diff line number Diff line change
@@ -1,28 +1,35 @@
local ACF = ACF
local GlobalFilter = ACF.GlobalFilter
local Message = SERVER and ACF.PrintLog or ACF.PrintToChat

local Names = {
[1] = "Sandbox",
[2] = "Classic",
[3] = "Competitive"
}
local Messages = ACF.Utilities.Messages
local Message = SERVER and Messages.PrintLog or Messages.PrintChat

local Settings = {
Gamemode = function(_, _, Value)
local Mode = math.Clamp(math.floor(tonumber(Value) or 2), 1, 3)
ServerDataAllowAdmin = function(_, _, Value)
local Bool = tobool(Value)

if Mode == ACF.Gamemode then return end
if ACF.AllowAdminData == Bool then return end

ACF.Gamemode = Mode
ACF.AllowAdminData = Bool

Message("Info", "ACF Gamemode has been changed to " .. Names[Mode])
end,
ServerDataAllowAdmin = function(_, _, Value)
ACF.AllowAdminData = tobool(Value)
Message("Info", "Admin server data access has been " .. (Bool and "enabled." or "disabled."))
end,
RestrictInfo = function(_, _, Value)
ACF.RestrictInfo = tobool(Value)
local Bool = tobool(Value)

if ACF.RestrictInfo == Bool then return end

ACF.RestrictInfo = Bool

Message("Info", "Entity information has been " .. (Bool and "restricted." or "unrestricted."))
end,
LegalChecks = function(_, _, Value)
local Bool = tobool(Value)

if ACF.LegalChecks == Bool then return end

ACF.LegalChecks = Bool

Message("Info", "Legality checks have been " .. (Bool and "enabled." or "disabled."))
end,
GunsCanFire = function(_, _, Value)
local Bool = tobool(Value)
Expand All @@ -31,7 +38,7 @@ local Settings = {

ACF.GunsCanFire = Bool

Message("Info", "ACF Gunfire has been " .. (Bool and "enabled." or "disabled."))
Message("Info", "Gunfire has been " .. (Bool and "enabled." or "disabled."))
end,
GunsCanSmoke = function(_, _, Value)
local Bool = tobool(Value)
Expand All @@ -40,7 +47,7 @@ local Settings = {

ACF.GunsCanSmoke = Bool

Message("Info", "ACF Gun sound and particles have been " .. (Bool and "enabled." or "disabled."))
Message("Info", "Gun sounds and particles have been " .. (Bool and "enabled." or "disabled."))
end,
RacksCanFire = function(_, _, Value)
local Bool = tobool(Value)
Expand All @@ -49,7 +56,16 @@ local Settings = {

ACF.RacksCanFire = Bool

Message("Info", "ACF Missile Racks have been " .. (Bool and "enabled." or "disabled."))
Message("Info", "Missile racks have been " .. (Bool and "enabled." or "disabled."))
end,
RequireFuel = function(_, _, Value)
local Bool = tobool(Value)

if ACF.RequireFuel == Bool then return end

ACF.RequireFuel = Bool

Message("Info", "Engine fuel requirements have been " .. (Bool and "enabled." or "disabled."))
end,
HealthFactor = function(_, _, Value)
local Factor = math.Clamp(math.Round(tonumber(Value) or 1, 2), 0.01, 2)
Expand All @@ -61,7 +77,7 @@ local Settings = {
ACF.HealthFactor = Factor
ACF.Threshold = ACF.Threshold / Old * Factor

Message("Info", "ACF Health Mod changed to a factor of " .. Factor)
Message("Info", "Health multiplier changed to a factor of " .. Factor .. ".")
end,
ArmorFactor = function(_, _, Value)
local Factor = math.Clamp(math.Round(tonumber(Value) or 1, 2), 0.01, 2)
Expand All @@ -73,7 +89,7 @@ local Settings = {
ACF.ArmorFactor = Factor
ACF.ArmorMod = ACF.ArmorMod / Old * Factor

Message("Info", "ACF Armor Mod changed to a factor of " .. Factor)
Message("Info", "Armor multiplier changed to a factor of " .. Factor .. ".")
end,
FuelFactor = function(_, _, Value)
local Factor = math.Clamp(math.Round(tonumber(Value) or 1, 2), 0.01, 2)
Expand All @@ -85,36 +101,53 @@ local Settings = {
ACF.FuelFactor = Factor
ACF.FuelRate = ACF.FuelRate / Old * Factor

Message("Info", "ACF Fuel Rate changed to a factor of " .. Factor)
Message("Info", "Fuel rate multiplier changed to a factor of " .. Factor .. ".")
end,
CompFuelFactor = function(_, _, Value)
local Factor = math.Clamp(math.Round(tonumber(Value) or 1, 2), 0.01, 2)

if ACF.CompFuelFactor == Factor then return end
HEPush = function(_, _, Value)
local Bool = tobool(Value)

local Old = ACF.CompFuelFactor
if ACF.HEPush == Bool then return end

ACF.CompFuelFactor = Factor
ACF.CompFuelRate = ACF.CompFuelRate / Old * Factor
ACF.HEPush = Bool

Message("Info", "ACF Competitive Fuel Rate changed to a factor of " .. Factor)
end,
HEPush = function(_, _, Value)
ACF.HEPush = tobool(Value)
Message("Info", "HE entity pushing has been " .. (Bool and "enabled." or "disabled."))
end,
KEPush = function(_, _, Value)
ACF.KEPush = tobool(Value)
local Bool = tobool(Value)

if ACF.KEPush == Bool then return end

ACF.KEPush = Bool

Message("Info", "Kinetic energy entity pushing has been " .. (Bool and "enabled." or "disabled."))
end,
RecoilPush = function(_, _, Value)
ACF.RecoilPush = tobool(Value)
local Bool = tobool(Value)

if ACF.RecoilPush == Bool then return end

ACF.RecoilPush = Bool

Message("Info", "Recoil entity pushing has been " .. (Bool and "enabled." or "disabled."))
end,
AllowFunEnts = function(_, _, Value)
ACF.AllowFunEnts = tobool(Value)
local Bool = tobool(Value)

if ACF.AllowFunEnts == Bool then return end

ACF.AllowFunEnts = Bool

Message("Info", "Fun Entities have been " .. (Bool and "enabled." or "disabled."))
end,
AllowProcArmor = function(_, _, Value)
local allowProcArmor = tobool(Value)
ACF.AllowProcArmor = allowProcArmor
GlobalFilter["acf_armor"] = not allowProcArmor
local Bool = tobool(Value)

if ACF.AllowProcArmor == Bool then return end

ACF.AllowProcArmor = Bool
GlobalFilter["acf_armor"] = not Bool

Message("Info", "Procedural armor has been " .. (Bool and "enabled." or "disabled."))
end,
WorkshopContent = function(_, _, Value)
local Bool = tobool(Value)
Expand All @@ -125,7 +158,7 @@ local Settings = {

if CLIENT then return end

Message("Info", "ACF Workshop Content download has been " .. (Bool and "enabled." or "disabled."))
Message("Info", "Workshop content download has been " .. (Bool and "enabled." or "disabled."))
end,
WorkshopExtras = function(_, _, Value)
local Bool = tobool(Value)
Expand All @@ -136,7 +169,7 @@ local Settings = {

if CLIENT then return end

Message("Info", "ACF Extra Workshop Content download has been " .. (Bool and "enabled." or "disabled."))
Message("Info", "Extra Workshop content download has been " .. (Bool and "enabled." or "disabled."))
end,
}

Expand All @@ -151,4 +184,4 @@ do -- Volume setting callback
Callback("Volume", "Volume Variable Callback", function(_, _, Value)
ACF.Volume = math.Clamp(tonumber(Value) or 1, 0, 1)
end)
end
end
19 changes: 7 additions & 12 deletions lua/acf/menu/items_cl/engines.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@ local ConsumptionText = [[
%s Consumption :
%s L/min - %s gal/min @ %s RPM]]

-- Fuel consumption is increased on competitive servers
local function GetEfficiencyMult()
return ACF.Gamemode == 3 and ACF.CompFuelRate or 1
end

local function UpdateEngineStats(Label, Data)
local RPM = Data.RPM
local PeakTqRPM = math.Round(Data.PeakTqRPM)
Expand All @@ -35,7 +30,7 @@ local function UpdateEngineStats(Label, Data)
local Torque = math.Round(Data.Torque)
local TorqueFeet = math.Round(Data.Torque * 0.73)
local Type = EngineTypes.Get(Data.Type)
local Efficiency = Type.Efficiency * GetEfficiencyMult()
local Efficiency = Type.Efficiency
local FuelList = ""

for K in pairs(Data.Fuel) do
Expand Down Expand Up @@ -173,11 +168,11 @@ local function CreateMenu(Menu)
local TextFunc = self.Selected.FuelTankText
local FuelText = ""

local Wall = 0.03937 --wall thickness in inches (1mm)
local Volume = FuelTank.Volume - (FuelTank.SurfaceArea * Wall) -- total volume of tank (cu in), reduced by wall thickness
local Capacity = Volume * ACF.gCmToKgIn * ACF.TankVolumeMul * 0.4774 --internal volume available for fuel in liters, with magic realism number
local EmptyMass = FuelTank.SurfaceArea * Wall * 16.387 * 0.0079 -- total wall volume * cu in to cc * density of steel (kg/cc)
local Mass = EmptyMass + Capacity * self.Selected.Density -- weight of tank + weight of fuel
local Wall = 0.03937 -- Wall thickness in inches (1mm)
local Volume = FuelTank.Volume - (FuelTank.SurfaceArea * Wall) -- Total volume of tank (cu in), reduced by wall thickness
local Capacity = Volume * ACF.gCmToKgIn * ACF.TankVolumeMul * 0.4774 -- Internal volume available for fuel in liters, with magic realism number
local EmptyMass = FuelTank.SurfaceArea * Wall * 16.387 * 0.0079 -- Total wall volume * cu in to cc * density of steel (kg/cc)
local Mass = EmptyMass + Capacity * self.Selected.Density -- Weight of tank + weight of fuel

if TextFunc then
FuelText = FuelText .. TextFunc(Capacity, Mass, EmptyMass)
Expand Down Expand Up @@ -205,4 +200,4 @@ local function CreateMenu(Menu)
ACF.LoadSortedList(FuelClass, FuelEntries, "ID")
end

ACF.AddMenuItem(201, "Entities", "Engines", "car", CreateMenu)
ACF.AddMenuItem(201, "Entities", "Engines", "car", CreateMenu)
Loading

0 comments on commit bcd2f4b

Please sign in to comment.