Skip to content

Commit

Permalink
Remove debug code
Browse files Browse the repository at this point in the history
I think this is all of it but maybe there's still something in a different file that I missed
  • Loading branch information
thecraftianman committed Oct 7, 2023
1 parent f86a4a2 commit e76fb44
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 103 deletions.
7 changes: 0 additions & 7 deletions lua/acf/menu/items_cl/engines.lua
Original file line number Diff line number Diff line change
Expand Up @@ -160,9 +160,7 @@ local function CreateMenu(Menu)
return Z
end)

--local FuelClass = Menu:AddComboBox()
local FuelList = Menu:AddComboBox()
--local FuelType = Menu:AddComboBox()
local FuelBase = Menu:AddCollapsible("Fuel Tank Information")
local FuelDesc = FuelBase:AddLabel()
local FuelPreview = FuelBase:AddModelPreview(nil, true)
Expand Down Expand Up @@ -267,9 +265,6 @@ local function CreateMenu(Menu)

ACF.SetClientData("FuelType", Data.ID)

--FuelPreview:UpdateModel(Data.Model or "models/fueltank/fueltank_4x4x4.mdl")
--FuelPreview:UpdateSettings({ FOV = 120 })

self:UpdateFuelText()
end

Expand Down Expand Up @@ -309,8 +304,6 @@ local function CreateMenu(Menu)
FuelDescText = ""
end

--local Wall = ACF.FuelArmor * ACF.MmToInch -- Wall thickness in inches
--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 = Area * 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
Expand Down
121 changes: 25 additions & 96 deletions lua/entities/acf_fueltank/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -50,40 +50,21 @@ do -- Spawn and Update functions
}

local function VerifyData(Data)
PrintTable(Data)
--[[
if Data.Id then -- Updating old fuel tanks
local Tank = FuelTanks.Get(Data.Id)
if Tank then -- Pre-scalable tank remnants
Data.Offset = Vector(Tank.Offset)
--Data.Size = Vector(Tank.Size)
local SizeValues = string.Explode("x", string.Split(Data.FuelTank, "_"))
PrintTable(SizeValues)
local X = ACF.CheckNumber(SizeValues[1] * 10, 24)
local Y = ACF.CheckNumber(SizeValues[2] * 10, 24)
local Z = ACF.CheckNumber(SizeValues[3] * 10, 24)
Data.Size = Vector(X, Y, Z)
Data.NeedsOffset = true
end
]]
if string.StartsWith(Data.FuelTank, "Tank_") then
-- Deriving box dimensions from the FuelTank string because there is no size
local SizeString = string.Split(Data.FuelTank, "_")
local SizeValues = string.Explode("x", SizeString[2])
PrintTable(SizeValues)

-- The X and Y values are swapped on purpose to match old model shapes
local X = ACF.CheckNumber(SizeValues[2] * 10, 24)
local Y = ACF.CheckNumber(SizeValues[1] * 10, 24)
local Z = ACF.CheckNumber(SizeValues[3] * 10, 24)

Data.Size = Vector(X, Y, Z)
-- Data.NeedsOffset = true
--elseif OldTank == "Jerry_Can" then
--Data.Size = Vector(20, 8, 30) -- Matches gascan001a model size
Data.FuelTank = "Box"
elseif Data.FuelTank == "Fuel_Drum" then
Data.Size = Vector(28, 28, 45) -- Matches oildrum001 model size
Data.FuelTank = "Drum"
end

if not isvector(Data.Size) then
Expand All @@ -107,11 +88,11 @@ do -- Spawn and Update functions
Size.y = math.Clamp(math.Round(Size.y), Min, Max)
Size.z = math.Clamp(math.Round(Size.z), Min, Max)
end
--[[

if not Data.FuelTank then
Data.FuelTank = Data.SizeId or Data.Id or "Jerry_Can"
end
]]

local Class = Classes.GetGroup(FuelTanks, Data.FuelTank)

if not Class then
Expand Down Expand Up @@ -140,36 +121,19 @@ do -- Spawn and Update functions

Entity.ACF = Entity.ACF or {}
Entity.ACF.Model = FuelTank.Model -- Must be set before changing model
print(Entity.ACF.Model)
--Entity:SetSize(Data.Size)
--Entity:SetScaledModel(FuelTank.Model)
print(FuelTank.ID)

if FuelTank.ID ~= "Box" and FuelTank.ID ~= "Drum" then
Entity:SetModel(FuelTank.Model)
Entity:PhysicsInit(SOLID_VPHYSICS, true)
Entity:SetMoveType(MOVETYPE_VPHYSICS)
end

--Entity:PhysicsInit(SOLID_VPHYSICS)
--Entity:SetMoveType(MOVETYPE_VPHYSICS)

--local PhysObj = Entity:GetPhysicsObject()
--local Area = PhysObj:GetSurfaceArea()

-- Storing all the relevant information on the entity for duping
for _, V in ipairs(Entity.DataStore) do
Entity[V] = Data[V]
end

local Size = Data.Size

--local ExteriorVolume = Size.x * Size.y * Size.z
-- local InteriorVolume = (Size.x - Wall) * (Size.y - Wall) * (Size.z - Wall) -- Math degree
-- local SurfaceArea = (2 * Size.x * Size.y) + (2 * Size.y * Size.z) + (2 * Size.x * Size.z)

-- local Volume = InteriorVolume - (SurfaceArea * Wall)
-- print(Volume)

local Volume, Area, NameType

if FuelTank.ID == "Box" then
Expand All @@ -182,13 +146,12 @@ do -- Spawn and Update functions

Entity:SetSize(Data.Size)
elseif FuelTank.ID == "Drum" then
--local ExteriorVolume = math.pi * (Size.x ^ 2) * Size.z
local Radius = Size.x / 2
local InteriorVolume = math.pi * ((Radius - Wall) ^ 2) * (Size.z - Wall)
Area = 2 * math.pi * Radius * (Radius + Size.z)

Volume = InteriorVolume - (Area * Wall)
print(Volume)

NameType = " Drum"

Entity:SetSize(Data.Size)
Expand All @@ -199,34 +162,21 @@ do -- Spawn and Update functions
Volume = PhysObj:GetVolume() - (Area * Wall) -- Total volume of tank (cu in), reduced by wall thickness

NameType = " " .. FuelTank.Name

--Entity.EmptyMass = (Area * Wall) * 16.387 * 0.0079 -- total wall volume * cu in to cc * density of steel (kg/cc)
end

Entity.Name = Entity.FuelType .. NameType --FuelTank.Name
Entity.Name = Entity.FuelType .. NameType
Entity.ShortName = Entity.FuelType
Entity.EntType = Class.Name
Entity.ClassData = Class
Entity.FuelDensity = FuelType.Density
--Entity.Volume = PhysObj:GetVolume() - (Area * Wall) -- total volume of tank (cu in), reduced by wall thickness
Entity.Capacity = Volume * ACF.gCmToKgIn * ACF.TankVolumeMul * 0.4774-- Entity.Volume * ACF.gCmToKgIn * ACF.TankVolumeMul * 0.4774 --internal volume available for fuel in liters, with magic realism number
Entity.EmptyMass = (Area * Wall) * 16.387 * (7.9 / 1000) -- total wall volume * cu in to cc * density of steel (kg/cc)
Entity.Capacity = Volume * ACF.gCmToKgIn * ACF.TankVolumeMul * 0.4774 -- Internal volume available for fuel in liters, with magic realism number
Entity.EmptyMass = (Area * Wall) * 16.387 * 0.0079 -- Total wall volume * cu in to cc * density of steel (kg/cc)
Entity.IsExplosive = FuelTank.IsExplosive
Entity.NoLinks = FuelTank.Unlinkable
--[[
Entity.HitBoxes = {
Main = {
Pos = Entity:OBBCenter(),
Scale = (Entity:OBBMaxs() - Entity:OBBMins()) - Vector(0.5, 0.5, 0.5),
}
}
]]

WireIO.SetupInputs(Entity, Inputs, Data, Class, FuelTank, FuelType)
WireIO.SetupOutputs(Entity, Outputs, Data, Class, FuelTank, FuelType)

--Entity:SetNWString("WireName", "ACF " .. Entity.Name)

if Entity.FuelType == "Electric" then
Entity.Name = "Electric Battery"
Entity.Liters = Entity.Capacity -- Batteries capacity is different from internal volume
Expand All @@ -249,27 +199,20 @@ do -- Spawn and Update functions
if not Entity.IsACFFuelTank then return end
if Data.Size then return end -- The menu won't send it like this

Data.Size = Entity:GetSize()
Data.Size = Entity:GetSize()
Data.TankSizeX = nil
Data.TankSizeY = nil
Data.TankSizeZ = nil
end)

hook.Add("PlayerSpawnedProp", "ACF Test", function(_, mdl, ent)
if mdl ~= "models/fueltank/fueltank_4x4x4.mdl" then return end
print("prop vol: " .. ent:GetPhysicsObject():GetVolume() - (ent:GetPhysicsObject():GetSurfaceArea() * Wall))
print("prop sa: " .. ent:GetPhysicsObject():GetSurfaceArea())
end)

--local TestOffset = Angle(0, -90, 90)
function MakeACF_FuelTank(Player, Pos, Angle, Data)
VerifyData(Data)

local Class = Classes.GetGroup(FuelTanks, Data.FuelTank)
local FuelTank = FuelTanks.GetItem(Class.ID, Data.FuelTank)
local FuelType = FuelTypes.Get(Data.FuelType)
local Limit = Class.LimitConVar.Name
local Model = FuelTank.Model --"models/holograms/hq_rcube_thick.mdl"
local Model = FuelTank.Model

if not Player:CheckLimit(Limit) then return end

Expand All @@ -280,19 +223,11 @@ do -- Spawn and Update functions
local Tank = ents.Create("acf_fueltank")

if not IsValid(Tank) then return end
--[[
print(Data.NeedsOffset)
if Data.NeedsOffset then
Angle = Angle + TestOffset
Data.NeedsOffset = nil
end
]]
--Tank:SetMaterial("phoenix_storms/Future_vents")

Tank:SetPlayer(Player)
if FuelTank.ID == "Box" or FuelTank.ID == "Drum" then
Tank:SetScaledModel(Model)
end
--Tank:SetScaledModel(Model)
Tank:SetAngles(Angle)
Tank:SetPos(Pos)
Tank:Spawn()
Expand Down Expand Up @@ -413,7 +348,7 @@ end
function ENT:ACF_Activate(Recalc)
local PhysObj = self:GetPhysicsObject()
local Area = PhysObj:GetSurfaceArea() * 6.45
local Armour = self.EmptyMass * 1000 / Area / 0.78 * ACF.ArmorMod --So we get the equivalent thickness of that prop in mm if all it's weight was a steel plate
local Armour = self.EmptyMass * 1000 / Area / 0.78 * ACF.ArmorMod -- So we get the equivalent thickness of that prop in mm if all it's weight was a steel plate
local Health = Area / ACF.Threshold
local Percent = 1

Expand Down Expand Up @@ -449,17 +384,17 @@ function ENT:ACF_OnDamage(DmgResult, DmgInfo)
return HitRes
end

local Ratio = (HitRes.Damage / self.ACF.Health) ^ 0.75 --chance to explode from sheer damage, small shots = small chance
local ExplodeChance = (1 - (self.Fuel / self.Capacity)) ^ 0.75 --chance to explode from fumes in tank, less fuel = more explodey
local Ratio = (HitRes.Damage / self.ACF.Health) ^ 0.75 -- Chance to explode from sheer damage, small shots = small chance
local ExplodeChance = (1 - (self.Fuel / self.Capacity)) ^ 0.75 -- Chance to explode from fumes in tank, less fuel = more explodey

--it's gonna blow
-- It's gonna blow
if math.random() < (ExplodeChance + Ratio) then
if HookRun("ACF_FuelExplode", self) == false then return HitRes end

self.Inflictor = Inflictor

self:Detonate()
else --spray some fuel around
else -- Spray some fuel around
self.Leaking = self.Leaking + self.Fuel * ((HitRes.Damage / self.ACF.Health) ^ 1.5) * 0.25

WireLib.TriggerOutput(self, "Leaking", self.Leaking > 0 and 1 or 0)
Expand Down Expand Up @@ -500,7 +435,7 @@ do -- Mass Update
local function UpdateMass(Entity)
local Fuel = Entity.FuelType == "Electric" and Entity.Liters or Entity.Fuel
local Mass = math.floor(Entity.EmptyMass + Fuel * Entity.FuelDensity)
local PhysObj = Entity:GetPhysicsObject() --Entity.ACF.PhysObj
local PhysObj = Entity:GetPhysicsObject()

if IsValid(PhysObj) then
Entity.ACF.Mass = Mass
Expand All @@ -526,18 +461,12 @@ do -- Mass Update
end

do -- Overlay Update
--local Text = "%s\n\nSize: %sx%sx%s\n\nFuel Type: %s\n%s"
local Text = "%s\n\n%sFuel Type: %s\n%s"

function ENT:UpdateOverlayText()
--local X, Y, Z = self:GetSize():Unpack()
local Size = ""
local Status, Content

--X = math.Round(X, 2)
--Y = math.Round(Y, 2)
--Z = math.Round(Z, 2)

if self.Leaking > 0 then
Status = "Leaking"
else
Expand All @@ -553,11 +482,11 @@ do -- Overlay Update

Size = "Size: " .. X .. "x" .. Y .. "x" .. Z .. "\n\n"
elseif FuelTank == "Drum" then
local R, _, H = self:GetSize():Unpack()
R = math.Round(R, 2)
local D, _, H = self:GetSize():Unpack()
D = math.Round(D, 2)
H = math.Round(H, 2)

Size = "Diameter: " .. R .. "\nHeight: " .. H .. "\n\n"
Size = "Diameter: " .. D .. "\nHeight: " .. H .. "\n\n"
end

if self.FuelType == "Electric" then -- TODO: Replace hardcoded stuff
Expand Down Expand Up @@ -609,14 +538,14 @@ function ENT:Think()
if self.Leaking > 0 then
self:Consume(self.Leaking)

self.Leaking = math.Clamp(self.Leaking - (1 / math.max(self.Fuel, 1)) ^ 0.5, 0, self.Fuel) --fuel tanks are self healing
self.Leaking = math.Clamp(self.Leaking - (1 / math.max(self.Fuel, 1)) ^ 0.5, 0, self.Fuel) -- Fuel tanks are self healing

WireLib.TriggerOutput(self, "Leaking", self.Leaking > 0 and 1 or 0)

self:NextThink(Clock.CurTime + 0.25)
end

--refuelling
-- Refuelling
if self.SupplyFuel and self:CanConsume() then
local DeltaTime = Clock.CurTime - self.LastThink
local Position = self:GetPos()
Expand Down Expand Up @@ -688,7 +617,7 @@ function ENT:OnResized(Size)
self.HitBoxes = {
Main = {
Pos = self:OBBCenter(),
Scale = Size, --(Entity:OBBMaxs() - Entity:OBBMins()) - Vector(0.5, 0.5, 0.5),
Scale = Size,
}
}
end

0 comments on commit e76fb44

Please sign in to comment.