diff --git a/lua/acf/core/classes/fuel_tanks/registration.lua b/lua/acf/core/classes/fuel_tanks/registration.lua index 18c3d53f9..0b9f3ceb2 100644 --- a/lua/acf/core/classes/fuel_tanks/registration.lua +++ b/lua/acf/core/classes/fuel_tanks/registration.lua @@ -22,6 +22,10 @@ end function FuelTanks.RegisterItem(ID, ClassID, Data) local Class = Classes.AddGroupItem(ID, ClassID, Entries, Data) + if Class.Name == nil then + Class.Name = "Fuel Box" + end + if Class.IsExplosive == nil then Class.IsExplosive = true end diff --git a/lua/acf/core/globals.lua b/lua/acf/core/globals.lua index 1254fc003..ea6e11c4a 100644 --- a/lua/acf/core/globals.lua +++ b/lua/acf/core/globals.lua @@ -124,6 +124,9 @@ do -- ACF global vars 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.FuelMinSize = 6 -- Defines the shortest possible length of fuel tanks for all their axises, in gmu + ACF.FuelMaxSize = 96 -- Defines the highest possible length of fuel tanks for all their axises, in gmu + ACF.FuelArmor = 5 -- How many millimeters of armor fuel tanks have 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. diff --git a/lua/acf/entities/fuel_tanks/box.lua b/lua/acf/entities/fuel_tanks/box.lua new file mode 100644 index 000000000..ef89f21f0 --- /dev/null +++ b/lua/acf/entities/fuel_tanks/box.lua @@ -0,0 +1,335 @@ +local FuelTanks = ACF.Classes.FuelTanks + +-- Preserving flavor text from older fuel tank sizes +local FuelDescSentences = { + "Seriously consider walking.", + "Will keep a kart running all day.", + "Dinghy.", + "Outboard motor.", + "Clown car.", + "Fuel pancake.", + "Lawn tractors.", + "Small tractor tank.", + "Fuel. Will keep you going for awhile.", + "Gas stations? We don't need no stinking gas stations!", + "Beep beep.", + "Mini Cooper.", + "Good bit of go-juice.", + "Land boat.", + "Conformal fuel tank; fits narrow spaces.", + "Compact car.", + "Sedan.", + "Truck.", + "With great capacity, comes great responsibili--VROOOOM", + "Popular with arsonists.", + "Fire juice.", + "Trees are gay anyway.", + "Arson material.", + "What's a gas station?", + "\'MURRICA FUCKYEAH!", + "Got gas?", + "Drive across the desert without a fuck to give.", + "May contain Mesozoic ghosts.", + "Conformal fuel tank; does what all its friends do.", + "Certified 100% dinosaur juice.", + "Will last you a while.", + "Sloshy sloshy!", + "What's global warming?", + "Tank Tank.", +} + +FuelTanks.Register("FTS_B", { + Name = "Fuel Box", + Description = "Scalable fuel box; required for engines to work.", + IsScalable = true, + Model = "models/fueltank/fueltank_4x4x4.mdl", + Shape = "Box", + NameType = "Tank", + IsExplosive = true, + Unlinkable = false, + Preview = { + FOV = 120, + }, + CalcVolume = function(Size, Wall) + local InteriorVolume = (Size.x - Wall) * (Size.y - Wall) * (Size.z - Wall) -- Math degree + + local Area = (2 * Size.x * Size.y) + (2 * Size.y * Size.z) + (2 * Size.x * Size.z) + local Volume = InteriorVolume - (Area * Wall) + + return Volume, Area + end, + CalcOverlaySize = function(Entity) + local X, Y, Z = Entity:GetSize():Unpack() + X = math.Round(X, 2) + Y = math.Round(Y, 2) + Z = math.Round(Z, 2) + + return "Size: " .. X .. "x" .. Y .. "x" .. Z .. "\n\n" + end, + MenuSettings = function(SizeX, SizeY, SizeZ, FuelList) + SizeX:SetVisible(true) + SizeY:SetVisible(true) + SizeZ:SetVisible(true) + FuelList:SetVisible(false) + + SizeX:SetText("Tank Length") + SizeZ:SetText("Tank Height") + end, + FuelDescText = function() + return FuelDescSentences[math.random(33)] + end +}) + +do + FuelTanks.RegisterItem("Box", "FTS_B", { + Name = "Fuel Box", + Description = "", -- Blank to allow for dynamic descriptions better + }) +end + +-- NOTE: The X and Y values for older containers are swapped on purpose to match old model shapes + +do -- Size 1 container compatibility + FuelTanks.AddAlias("FTS_B", "FTS_1") + + FuelTanks.RegisterItem("Tank_1x1x1", "FTS_B", { + Size = Vector(10, 10, 10), + Shape = "Box" + }) + + FuelTanks.RegisterItem("Tank_1x1x2", "FTS_B", { + Size = Vector(10, 10, 20), + Shape = "Box" + }) + + FuelTanks.RegisterItem("Tank_1x1x4", "FTS_B", { + Size = Vector(10, 10, 40), + Shape = "Box" + }) + + FuelTanks.RegisterItem("Tank_1x2x1", "FTS_B", { + Size = Vector(20, 10, 10), + Shape = "Box" + }) + + FuelTanks.RegisterItem("Tank_1x2x2", "FTS_B", { + Size = Vector(20, 10, 20), + Shape = "Box" + }) + + FuelTanks.RegisterItem("Tank_1x2x4", "FTS_B", { + Size = Vector(20, 10, 40), + Shape = "Box" + }) + + FuelTanks.RegisterItem("Tank_1x4x1", "FTS_B", { + Size = Vector(40, 10, 10), + Shape = "Box" + }) + + FuelTanks.RegisterItem("Tank_1x4x2", "FTS_B", { + Size = Vector(40, 10, 20), + Shape = "Box" + }) + + FuelTanks.RegisterItem("Tank_1x4x4", "FTS_B", { + Size = Vector(40, 10, 40), + Shape = "Box" + }) + + FuelTanks.RegisterItem("Tank_1x6x1", "FTS_B", { + Size = Vector(60, 10, 10), + Shape = "Box" + }) + + FuelTanks.RegisterItem("Tank_1x6x2", "FTS_B", { + Size = Vector(60, 10, 20), + Shape = "Box" + }) + + FuelTanks.RegisterItem("Tank_1x6x4", "FTS_B", { + Size = Vector(60, 10, 40), + Shape = "Box" + }) + + FuelTanks.RegisterItem("Tank_1x8x1", "FTS_B", { + Size = Vector(80, 10, 10), + Shape = "Box" + }) + + FuelTanks.RegisterItem("Tank_1x8x2", "FTS_B", { + Size = Vector(80, 10, 20), + Shape = "Box" + }) + + FuelTanks.RegisterItem("Tank_1x8x4", "FTS_B", { + Size = Vector(80, 10, 40), + Shape = "Box" + }) +end + +do -- Size 2 container compatibility + FuelTanks.AddAlias("FTS_B", "FTS_2") + + FuelTanks.RegisterItem("Tank_2x2x1", "FTS_B", { + Size = Vector(20, 20, 10), + Shape = "Box" + }) + + FuelTanks.RegisterItem("Tank_2x2x2", "FTS_B", { + Size = Vector(20, 20, 20), + Shape = "Box" + }) + + FuelTanks.RegisterItem("Tank_2x2x4", "FTS_B", { + Size = Vector(20, 20, 40), + Shape = "Box" + }) + + FuelTanks.RegisterItem("Tank_2x4x1", "FTS_B", { + Size = Vector(40, 20, 10), + Shape = "Box" + }) + + FuelTanks.RegisterItem("Tank_2x4x2", "FTS_B", { + Size = Vector(40, 20, 20), + Shape = "Box" + }) + + FuelTanks.RegisterItem("Tank_2x4x4", "FTS_B", { + Size = Vector(40, 20, 40), + Shape = "Box" + }) + + FuelTanks.RegisterItem("Tank_2x6x1", "FTS_B", { + Size = Vector(60, 20, 10), + Shape = "Box" + }) + + FuelTanks.RegisterItem("Tank_2x6x2", "FTS_B", { + Size = Vector(60, 20, 20), + Shape = "Box" + }) + + FuelTanks.RegisterItem("Tank_2x6x4", "FTS_B", { + Size = Vector(60, 20, 40), + Shape = "Box" + }) + + FuelTanks.RegisterItem("Tank_2x8x1", "FTS_B", { + Size = Vector(80, 20, 10), + Shape = "Box" + }) + + FuelTanks.RegisterItem("Tank_2x8x2", "FTS_B", { + Size = Vector(80, 20, 20), + Shape = "Box" + }) + + FuelTanks.RegisterItem("Tank_2x8x4", "FTS_B", { + Size = Vector(80, 20, 40), + Shape = "Box" + }) +end + +do -- Size 4 container compatibility + FuelTanks.AddAlias("FTS_B", "FTS_4") + + FuelTanks.RegisterItem("Tank_4x4x1", "FTS_B", { + Size = Vector(40, 40, 10), + Shape = "Box" + }) + + FuelTanks.RegisterItem("Tank_4x4x2", "FTS_B", { + Size = Vector(40, 40, 20), + Shape = "Box" + }) + + FuelTanks.RegisterItem("Tank_4x4x4", "FTS_B", { + Size = Vector(40, 40, 40), + Shape = "Box" + }) + + FuelTanks.RegisterItem("Tank_4x6x1", "FTS_B", { + Size = Vector(60, 40, 10), + Shape = "Box" + }) + + FuelTanks.RegisterItem("Tank_4x6x2", "FTS_B", { + Size = Vector(60, 40, 20), + Shape = "Box" + }) + + FuelTanks.RegisterItem("Tank_4x6x4", "FTS_B", { + Size = Vector(60, 40, 40), + Shape = "Box" + }) + + FuelTanks.RegisterItem("Tank_4x8x1", "FTS_B", { + Size = Vector(80, 40, 10), + Shape = "Box" + }) + + FuelTanks.RegisterItem("Tank_4x8x2", "FTS_B", { + Size = Vector(80, 40, 20), + Shape = "Box" + }) + + FuelTanks.RegisterItem("Tank_4x8x4", "FTS_B", { + Size = Vector(80, 40, 40), + Shape = "Box" + }) +end + +do -- Size 6 container compatibility + FuelTanks.AddAlias("FTS_B", "FTS_6") + + FuelTanks.RegisterItem("Tank_6x6x1", "FTS_B", { + Size = Vector(60, 60, 10), + Shape = "Box" + }) + + FuelTanks.RegisterItem("Tank_6x6x2", "FTS_B", { + Size = Vector(60, 60, 20), + Shape = "Box" + }) + + FuelTanks.RegisterItem("Tank_6x6x4", "FTS_B", { + Size = Vector(60, 60, 40), + Shape = "Box" + }) + + FuelTanks.RegisterItem("Tank_6x8x1", "FTS_B", { + Size = Vector(80, 60, 10), + Shape = "Box" + }) + + FuelTanks.RegisterItem("Tank_6x8x2", "FTS_B", { + Size = Vector(80, 60, 20), + Shape = "Box" + }) + + FuelTanks.RegisterItem("Tank_6x8x4", "FTS_B", { + Size = Vector(80, 60, 40), + Shape = "Box" + }) +end + +do -- Size 8 container compatibility + FuelTanks.AddAlias("FTS_B", "FTS_8") + + FuelTanks.RegisterItem("Tank_8x8x1", "FTS_B", { + Size = Vector(80, 80, 10), + Shape = "Box" + }) + + FuelTanks.RegisterItem("Tank_8x8x2", "FTS_B", { + Size = Vector(80, 80, 20), + Shape = "Box" + }) + + FuelTanks.RegisterItem("Tank_8x8x4", "FTS_B", { + Size = Vector(80, 80, 40), + Shape = "Box" + }) +end \ No newline at end of file diff --git a/lua/acf/entities/fuel_tanks/drum.lua b/lua/acf/entities/fuel_tanks/drum.lua new file mode 100644 index 000000000..b2854e20d --- /dev/null +++ b/lua/acf/entities/fuel_tanks/drum.lua @@ -0,0 +1,61 @@ +local FuelTanks = ACF.Classes.FuelTanks + +FuelTanks.Register("FTS_D", { + Name = "Fuel Drum", + Description = "Scalable fuel drum; required for engines to work.", + IsScalable = true, + Model = "models/props_c17/oildrum001_explosive.mdl", + Shape = "Drum", + NameType = "Drum", + IsExplosive = true, + Unlinkable = false, + Preview = { + FOV = 120, + }, + CalcVolume = function(Size, Wall) + local Radius = Size.x / 2 + local InteriorVolume = math.pi * ((Radius - Wall) ^ 2) * (Size.z - Wall) + + local Area = 2 * math.pi * Radius * (Radius + Size.z) + local Volume = InteriorVolume - (Area * Wall) + + return Volume, Area + end, + CalcOverlaySize = function(Entity) + local D, _, H = Entity:GetSize():Unpack() + D = math.Round(D, 2) + H = math.Round(H, 2) + + return "Diameter: " .. D .. "\nHeight: " .. H .. "\n\n" + end, + VerifyData = function(Data, _) -- Diameter needs to be made equal for the X and Y dimensions + Data.Size.y = Data.Size.x + end, + MenuSettings = function(SizeX, SizeY, SizeZ, FuelList) + SizeX:SetVisible(true) + SizeY:SetVisible(false) + -- Purposely hide height slider before showing to prevent a minor visual bug when switching from box to drum + SizeZ:SetVisible(false) + SizeZ:SetVisible(true) + FuelList:SetVisible(false) + + SizeX:SetText("Drum Diameter") + SizeZ:SetText("Drum Height") + end +}) + +do + FuelTanks.RegisterItem("Drum", "FTS_D", { + Name = "Fuel Drum", + Description = "Tends to explode when shot.", + }) +end + +do -- Old drum tank compatibility + FuelTanks.RegisterItem("Fuel_Drum", "FTS_D", { + Name = "Fuel Drum", + Size = Vector(28, 28, 45), + Model = "models/props_c17/oildrum001_explosive.mdl", + Shape = "Drum" + }) +end \ No newline at end of file diff --git a/lua/acf/entities/fuel_tanks/misc.lua b/lua/acf/entities/fuel_tanks/misc.lua index eed6de7fe..aadbd3a04 100644 --- a/lua/acf/entities/fuel_tanks/misc.lua +++ b/lua/acf/entities/fuel_tanks/misc.lua @@ -1,24 +1,11 @@ local FuelTanks = ACF.Classes.FuelTanks - FuelTanks.Register("FTS_M", { Name = "Miscellaneous", - Description = "Random fuel tank models, some of them can only be used for refueling.", + Description = "Random fuel tank models; some of them can only be used for refueling.", }) do - FuelTanks.RegisterItem("Fuel_Drum","FTS_M", { - Name = "Fuel Drum", - Description = "Tends to explode when shot.", - Model = "models/props_c17/oildrum001_explosive.mdl", - SurfaceArea = 5128.9, - Volume = 26794.4, - Shape = "Drum", - Preview = { - FOV = 120, - }, - }) - FuelTanks.RegisterItem("Jerry_Can","FTS_M", { Name = "Jerry Can", Description = "Handy portable fuel container.", @@ -37,7 +24,7 @@ do Model = "models/props_wasteland/horizontalcoolingtank04.mdl", SurfaceArea = 127505.5, Volume = 2102493.3, - Shape = "Drum", + Shape = "Elliptical", IsExplosive = false, Unlinkable = true, }) @@ -48,11 +35,11 @@ do Model = "models/props_wasteland/coolingtank02.mdl", SurfaceArea = 144736.3, Volume = 2609960, - Shape = "Drum", + Shape = "Elliptical", IsExplosive = false, Unlinkable = true, Preview = { FOV = 125, }, }) -end +end \ No newline at end of file diff --git a/lua/acf/entities/fuel_tanks/size_eight.lua b/lua/acf/entities/fuel_tanks/size_eight.lua deleted file mode 100644 index f0137a447..000000000 --- a/lua/acf/entities/fuel_tanks/size_eight.lua +++ /dev/null @@ -1,43 +0,0 @@ -local FuelTanks = ACF.Classes.FuelTanks - - -FuelTanks.Register("FTS_8", { - Name = "Size 8 Container", - Description = "Size 8 fuel containers, required for engines to work.", -}) - -do - FuelTanks.RegisterItem("Tank_8x8x1","FTS_8", { - Name = "8x8x1 Container", - Description = "Sloshy sloshy!", - Model = "models/fueltank/fueltank_8x8x1.mdl", - SurfaceArea = 15524.8, - Volume = 64794.2, - Shape = "Box", - Preview = { - Height = 60, - FOV = 60, - }, - }) - - FuelTanks.RegisterItem("Tank_8x8x2","FTS_8", { - Name = "8x8x2 Container", - Description = "What's global warming?", - Model = "models/fueltank/fueltank_8x8x2.mdl", - SurfaceArea = 18086.4, - Volume = 125868.9, - Shape = "Box", - Preview = { - FOV = 60, - }, - }) - - FuelTanks.RegisterItem("Tank_8x8x4","FTS_8", { - Name = "8x8x4 Container", - Description = "Tank Tank.", - Model = "models/fueltank/fueltank_8x8x4.mdl", - SurfaceArea = 23957.6, - Volume = 246845.3, - Shape = "Box", - }) -end diff --git a/lua/acf/entities/fuel_tanks/size_four.lua b/lua/acf/entities/fuel_tanks/size_four.lua deleted file mode 100644 index ffe94684e..000000000 --- a/lua/acf/entities/fuel_tanks/size_four.lua +++ /dev/null @@ -1,119 +0,0 @@ -local FuelTanks = ACF.Classes.FuelTanks - - -FuelTanks.Register("FTS_4", { - Name = "Size 4 Container", - Description = "Size 4 fuel containers, required for engines to work.", -}) - -do - FuelTanks.RegisterItem("Tank_4x4x1","FTS_4", { - Name = "4x4x1 Container", - Description = "Sedan.", - Model = "models/fueltank/fueltank_4x4x1.mdl", - SurfaceArea = 4619.1, - Volume = 16539.8, - Shape = "Box", - Preview = { - FOV = 65, - }, - }) - - FuelTanks.RegisterItem("Tank_4x4x2","FTS_4", { - Name = "4x4x2 Container", - Description = "Land boat.", - Model = "models/fueltank/fueltank_4x4x2.mdl", - SurfaceArea = 6071.4, - Volume = 32165.2, - Shape = "Box", - Preview = { - FOV = 85, - }, - }) - - FuelTanks.RegisterItem("Tank_4x4x4","FTS_4", { - Name = "4x4x4 Container", - Description = "Popular with arsonists.", - Model = "models/fueltank/fueltank_4x4x4.mdl", - SurfaceArea = 9145.3, - Volume = 62900.1, - Shape = "Box", - Preview = { - FOV = 115, - }, - }) - - FuelTanks.RegisterItem("Tank_4x6x1","FTS_4", { - Name = "4x6x1 Container", - Description = "Conformal fuel tank, fits in tight spaces.", - Model = "models/fueltank/fueltank_4x6x1.mdl", - SurfaceArea = 6553.6, - Volume = 24918.6, - Shape = "Box", - Preview = { - Height = 90, - FOV = 60, - }, - }) - - FuelTanks.RegisterItem("Tank_4x6x2","FTS_4", { - Name = "4x6x2 Container", - Description = "Fire juice.", - Model = "models/fueltank/fueltank_4x6x2.mdl", - SurfaceArea = 8425.3, - Volume = 48581.2, - Shape = "Box", - Preview = { - FOV = 80, - }, - }) - - FuelTanks.RegisterItem("Tank_4x6x4","FTS_4", { - Name = "4x6x4 Container", - Description = "Trees are gay anyway.", - Model = "models/fueltank/fueltank_4x6x4.mdl", - SurfaceArea = 12200.6, - Volume = 94640, - Shape = "Box", - Preview = { - FOV = 105, - }, - }) - - FuelTanks.RegisterItem("Tank_4x8x1","FTS_4", { - Name = "4x8x1 Container", - Description = "Arson material.", - Model = "models/fueltank/fueltank_4x8x1.mdl", - SurfaceArea = 8328.2, - Volume = 32541.9, - Shape = "Box", - Preview = { - Height = 80, - FOV = 60, - }, - }) - - FuelTanks.RegisterItem("Tank_4x8x2","FTS_4", { - Name = "4x8x2 Container", - Description = "What's a gas station?", - Model = "models/fueltank/fueltank_4x8x2.mdl", - SurfaceArea = 10419.5, - Volume = 63167.1, - Shape = "Box", - Preview = { - FOV = 70, - }, - }) - - FuelTanks.RegisterItem("Tank_4x8x4","FTS_4", { - Name = "4x8x4 Container", - Description = "\'MURRICA FUCKYEAH!", - Model = "models/fueltank/fueltank_4x8x4.mdl", - SurfaceArea = 14993.3, - Volume = 123693.2, - Shape = "Box", - Preview = { - FOV = 100, - }, - }) -end diff --git a/lua/acf/entities/fuel_tanks/size_one.lua b/lua/acf/entities/fuel_tanks/size_one.lua deleted file mode 100644 index 20252a864..000000000 --- a/lua/acf/entities/fuel_tanks/size_one.lua +++ /dev/null @@ -1,187 +0,0 @@ -local FuelTanks = ACF.Classes.FuelTanks - - -FuelTanks.Register("FTS_1", { - Name = "Size 1 Container", - Description = "Size 1 fuel containers, required for engines to work.", -}) - -do - FuelTanks.RegisterItem("Tank_1x1x1","FTS_1", { - Name = "1x1x1 Container", - Description = "Seriously consider walking.", - Model = "models/fueltank/fueltank_1x1x1.mdl", - SurfaceArea = 590.5, - Volume = 1019.9, - Shape = "Box", - Preview = { - FOV = 115, - }, - }) - - FuelTanks.RegisterItem("Tank_1x1x2","FTS_1", { - Name = "1x1x2 Container", - Description = "Will keep a kart running all day.", - Model = "models/fueltank/fueltank_1x1x2.mdl", - SurfaceArea = 974, - Volume = 1983.1, - Shape = "Box", - Preview = { - FOV = 125, - }, - }) - - FuelTanks.RegisterItem("Tank_1x1x4","FTS_1", { - Name = "1x1x4 Container", - Description = "Dinghy", - Model = "models/fueltank/fueltank_1x1x4.mdl", - SurfaceArea = 1777.4, - Volume = 3995.1, - Shape = "Box", - Preview = { - FOV = 125, - }, - }) - - FuelTanks.RegisterItem("Tank_1x2x1","FTS_1", { - Name = "1x2x1 Container", - Description = "Will keep a kart running all day.", - Model = "models/fueltank/fueltank_1x2x1.mdl", - SurfaceArea = 995, - Volume = 2062.5, - Shape = "Box", - Preview = { - FOV = 100, - }, - }) - - FuelTanks.RegisterItem("Tank_1x2x2","FTS_1", { - Name = "1x2x2 Container", - Description = "Dinghy", - Model = "models/fueltank/fueltank_1x2x2.mdl", - SurfaceArea = 1590.8, - Volume = 4070.9, - Shape = "Box", - Preview = { - FOV = 120, - }, - }) - - FuelTanks.RegisterItem("Tank_1x2x4","FTS_1", { - Name = "1x2x4 Container", - Description = "Outboard motor.", - Model = "models/fueltank/fueltank_1x2x4.mdl", - SurfaceArea = 2796.6, - Volume = 8119.2, - Shape = "Box", - Preview = { - FOV = 125, - }, - }) - - FuelTanks.RegisterItem("Tank_1x4x1","FTS_1", { - Name = "1x4x1 Container", - Description = "Dinghy", - Model = "models/fueltank/fueltank_1x4x1.mdl", - SurfaceArea = 1745.6, - Volume = 3962, - Shape = "Box", - Preview = { - FOV = 75, - }, - }) - - FuelTanks.RegisterItem("Tank_1x4x2","FTS_1", { - Name = "1x4x2 Container", - Description = "Clown car.", - Model = "models/fueltank/fueltank_1x4x2.mdl", - SurfaceArea = 2753.9, - Volume = 8018, - Shape = "Box", - Preview = { - FOV = 105, - }, - }) - - FuelTanks.RegisterItem("Tank_1x4x4","FTS_1", { - Name = "1x4x4 Container", - Description = "Fuel pancake.", - Model = "models/fueltank/fueltank_1x4x4.mdl", - SurfaceArea = 4761, - Volume = 16030.4, - Shape = "Box", - Preview = { - FOV = 125, - }, - }) - - FuelTanks.RegisterItem("Tank_1x6x1","FTS_1", { - Name = "1x6x1 Container", - Description = "Lawn tractors.", - Model = "models/fueltank/fueltank_1x6x1.mdl", - SurfaceArea = 2535.3, - Volume = 5973.1, - Shape = "Box", - Preview = { - FOV = 60, - }, - }) - - FuelTanks.RegisterItem("Tank_1x6x2","FTS_1", { - Name = "1x6x2 Container", - Description = "Small tractor tank.", - Model = "models/fueltank/fueltank_1x6x2.mdl", - SurfaceArea = 3954.1, - Volume = 12100.3, - Shape = "Box", - }) - - FuelTanks.RegisterItem("Tank_1x6x4","FTS_1", { - Name = "1x6x4 Container", - Description = "Fuel. Will keep you going for awhile.", - Model = "models/fueltank/fueltank_1x6x4.mdl", - SurfaceArea = 6743.3, - Volume = 24109.4, - Shape = "Box", - Preview = { - FOV = 115, - }, - }) - - FuelTanks.RegisterItem("Tank_1x8x1","FTS_1", { - Name = "1x8x1 Container", - Description = "Clown car.", - Model = "models/fueltank/fueltank_1x8x1.mdl", - SurfaceArea = 3315.5, - Volume = 7962.4, - Shape = "Box", - Preview = { - Height = 80, - FOV = 60, - }, - }) - - FuelTanks.RegisterItem("Tank_1x8x2","FTS_1", { - Name = "1x8x2 Container", - Description = "Gas stations? We don't need no stinking gas stations!", - Model = "models/fueltank/fueltank_1x8x2.mdl", - SurfaceArea = 5113.7, - Volume = 16026.2, - Shape = "Box", - Preview = { - FOV = 75, - }, - }) - - FuelTanks.RegisterItem("Tank_1x8x4","FTS_1", { - Name = "1x8x4 Container", - Description = "Beep beep.", - Model = "models/fueltank/fueltank_1x8x4.mdl", - SurfaceArea = 8696, - Volume = 31871, - Shape = "Box", - Preview = { - FOV = 110, - }, - }) -end diff --git a/lua/acf/entities/fuel_tanks/size_six.lua b/lua/acf/entities/fuel_tanks/size_six.lua deleted file mode 100644 index bd76c46bb..000000000 --- a/lua/acf/entities/fuel_tanks/size_six.lua +++ /dev/null @@ -1,83 +0,0 @@ -local FuelTanks = ACF.Classes.FuelTanks - - -FuelTanks.Register("FTS_6", { - Name = "Size 6 Container", - Description = "Size 6 fuel containers, required for engines to work.", -}) - -do - FuelTanks.RegisterItem("Tank_6x6x1","FTS_6", { - Name = "6x6x1 Container", - Description = "Got gas?", - Model = "models/fueltank/fueltank_6x6x1.mdl", - SurfaceArea = 9405.2, - Volume = 37278.5, - Shape = "Box", - Preview = { - Height = 70, - FOV = 60, - }, - }) - - FuelTanks.RegisterItem("Tank_6x6x2","FTS_6", { - Name = "6x6x2 Container", - Description = "Drive across the desert without a fuck to give.", - Model = "models/fueltank/fueltank_6x6x2.mdl", - SurfaceArea = 11514.5, - Volume = 73606.2, - Shape = "Box", - Preview = { - FOV = 70, - }, - }) - - FuelTanks.RegisterItem("Tank_6x6x4","FTS_6", { - Name = "6x6x4 Container", - Description = "May contain Mesozoic ghosts.", - Model = "models/fueltank/fueltank_6x6x4.mdl", - SurfaceArea = 16028.8, - Volume = 143269, - Shape = "Box", - Preview = { - FOV = 100, - }, - }) - - FuelTanks.RegisterItem("Tank_6x8x1","FTS_6", { - Name = "6x8x1 Container", - Description = "Conformal fuel tank, does what all its friends do.", - Model = "models/fueltank/fueltank_6x8x1.mdl", - SurfaceArea = 12131.1, - Volume = 48480.2, - Shape = "Box", - Preview = { - Height = 70, - FOV = 60, - }, - }) - - FuelTanks.RegisterItem("Tank_6x8x2","FTS_6", { - Name = "6x8x2 Container", - Description = "Certified 100% dinosaur juice.", - Model = "models/fueltank/fueltank_6x8x2.mdl", - SurfaceArea = 14403.8, - Volume = 95065.5, - Shape = "Box", - Preview = { - FOV = 60, - }, - }) - - FuelTanks.RegisterItem("Tank_6x8x4","FTS_6", { - Name = "6x8x4 Container", - Description = "Will last you a while.", - Model = "models/fueltank/fueltank_6x8x4.mdl", - SurfaceArea = 19592.4, - Volume = 187296.4, - Shape = "Box", - Preview = { - FOV = 95, - }, - }) -end diff --git a/lua/acf/entities/fuel_tanks/size_two.lua b/lua/acf/entities/fuel_tanks/size_two.lua deleted file mode 100644 index 7b53874d9..000000000 --- a/lua/acf/entities/fuel_tanks/size_two.lua +++ /dev/null @@ -1,153 +0,0 @@ -local FuelTanks = ACF.Classes.FuelTanks - - -FuelTanks.Register("FTS_2", { - Name = "Size 2 Container", - Description = "Size 2 fuel containers, required for engines to work.", -}) - -do - FuelTanks.RegisterItem("Tank_2x2x1","FTS_2", { - Name = "2x2x1 Container", - Description = "Dinghy", - Model = "models/fueltank/fueltank_2x2x1.mdl", - SurfaceArea = 1592.2, - Volume = 4285.2, - Shape = "Box", - }) - - FuelTanks.RegisterItem("Tank_2x2x2","FTS_2", { - Name = "2x2x2 Container", - Description = "Clown car.", - Model = "models/fueltank/fueltank_2x2x2.mdl", - SurfaceArea = 2360.4, - Volume = 8212.9, - Shape = "Box", - Preview = { - FOV = 115, - }, - }) - - FuelTanks.RegisterItem("Tank_2x2x4","FTS_2", { - Name = "2x2x4 Container", - Description = "Mini Cooper.", - Model = "models/fueltank/fueltank_2x2x4.mdl", - SurfaceArea = 3988.6, - Volume = 16362, - Shape = "Box", - Preview = { - FOV = 123, - }, - }) - - FuelTanks.RegisterItem("Tank_2x4x1","FTS_2", { - Name = "2x4x1 Container", - Description = "Good bit of go-juice.", - Model = "models/fueltank/fueltank_2x4x1.mdl", - SurfaceArea = 2808.8, - Volume = 8628, - Shape = "Box", - Preview = { - Height = 100, - FOV = 60, - }, - }) - - FuelTanks.RegisterItem("Tank_2x4x2","FTS_2", { - Name = "2x4x2 Container", - Description = "Mini Cooper.", - Model = "models/fueltank/fueltank_2x4x2.mdl", - SurfaceArea = 3996.1, - Volume = 16761.4, - Shape = "Box", - Preview = { - FOV = 80, - }, - }) - - FuelTanks.RegisterItem("Tank_2x4x4","FTS_2", { - Name = "2x4x4 Container", - Description = "Land boat.", - Model = "models/fueltank/fueltank_2x4x4.mdl", - SurfaceArea = 6397.3, - Volume = 32854.4, - Shape = "Box", - Preview = { - FOV = 100, - }, - }) - - FuelTanks.RegisterItem("Tank_2x6x1","FTS_2", { - Name = "2x6x1 Container", - Description = "Conformal fuel tank, fits narrow spaces.", - Model = "models/fueltank/fueltank_2x6x1.mdl", - SurfaceArea = 3861.4, - Volume = 12389.9, - Shape = "Box", - Preview = { - Height = 75, - FOV = 60, - }, - }) - - FuelTanks.RegisterItem("Tank_2x6x2","FTS_2", { - Name = "2x6x2 Container", - Description = "Compact car.", - Model = "models/fueltank/fueltank_2x6x2.mdl", - SurfaceArea = 5388, - Volume = 24127.7, - Shape = "Box", - Preview = { - FOV = 65, - }, - }) - - FuelTanks.RegisterItem("Tank_2x6x4","FTS_2", { - Name = "2x6x4 Container", - Description = "Sedan.", - Model = "models/fueltank/fueltank_2x6x4.mdl", - SurfaceArea = 8485.6, - Volume = 47537.2, - Shape = "Box", - Preview = { - FOV = 115, - }, - }) - - FuelTanks.RegisterItem("Tank_2x8x1","FTS_2", { - Name = "2x8x1 Container", - Description = "Conformal fuel tank, fits into tight spaces", - Model = "models/fueltank/fueltank_2x8x1.mdl", - SurfaceArea = 5094.5, - Volume = 16831.8, - Shape = "Box", - Preview = { - Height = 90, - FOV = 60, - }, - }) - - FuelTanks.RegisterItem("Tank_2x8x2","FTS_2", { - Name = "2x8x2 Container", - Description = "Truck.", - Model = "models/fueltank/fueltank_2x8x2.mdl", - SurfaceArea = 6980, - Volume = 32275.9, - Shape = "Box", - Preview = { - FOV = 80, - }, - }) - - FuelTanks.RegisterItem("Tank_2x8x4","FTS_2", { - Name = "2x8x4 Container", - Description = "With great capacity, comes great responsibili--VROOOOM", - Model = "models/fueltank/fueltank_2x8x4.mdl", - SurfaceArea = 10898.2, - Volume = 63976, - Shape = "Box", - Preview = { - FOV = 110, - }, - }) -end diff --git a/lua/acf/entities/fuel_types/electric.lua b/lua/acf/entities/fuel_types/electric.lua index 1fff37f8a..760d4e5c0 100644 --- a/lua/acf/entities/fuel_types/electric.lua +++ b/lua/acf/entities/fuel_types/electric.lua @@ -1,21 +1,27 @@ local ACF = ACF local FuelTypes = ACF.Classes.FuelTypes - FuelTypes.Register("Electric", { - Name = "Lit-Ion Battery", - Density = 3.89, - ConsumptionText = function(PeakkW, _, Efficiency) + Name = "Lit-Ion Battery", + Density = 3.89, + ConsumptionText = function(PeakkW, _, Efficiency) local Text = "Peak Energy Consumption :\n%s kW - %s MJ/min" local Rate = ACF.FuelRate * PeakkW / Efficiency return Text:format(math.Round(Rate, 2), math.Round(Rate * 0.06, 2)) end, - FuelTankText = function(Capacity, Mass) - local Text = "Charge : %s kW per hour - %s MJ\nMass : %s" + FuelTankText = function(Capacity, Mass) + local Text = "Tank Armor : %s mm\nCharge : %s kW per hour - %s MJ\nMass : %s" local kWh = math.Round(Capacity * ACF.LiIonED, 2) local MJ = math.Round(Capacity * ACF.LiIonED * 3.6, 2) - return Text:format(kWh, MJ, ACF.GetProperMass(Mass)) + return Text:format(ACF.FuelArmor, kWh, MJ, ACF.GetProperMass(Mass)) end, + FuelTankOverlayText = function(Fuel) + local Text = "Charge Level: %s kWh / %s MJ" + local KiloWatt = math.Round(Fuel, 2) + local Joules = math.Round(Fuel * 3.6, 2) + + return Text:format(KiloWatt, Joules) + end }) diff --git a/lua/acf/menu/items_cl/engines.lua b/lua/acf/menu/items_cl/engines.lua index a4bbc53e0..d89714ac2 100644 --- a/lua/acf/menu/items_cl/engines.lua +++ b/lua/acf/menu/items_cl/engines.lua @@ -12,12 +12,13 @@ local RPMText = [[ %s %s]] -local PowerText = [[ +local PowerText = [[ Peak Torque : %s Nm - %s ft-lb @ %s RPM Peak Power : %s kW - %s HP @ %s RPM]] local ConsumptionText = [[ %s Consumption : %s L/min - %s gal/min @ %s RPM]] +local TankSize = Vector() local function UpdateEngineStats(Label, Data) local RPM = Data.RPM @@ -74,10 +75,55 @@ local function CreateMenu(Menu) local EngineStats = EngineBase:AddLabel() Menu:AddTitle("Fuel Tank Settings") - + local FuelType = Menu:AddComboBox() local FuelClass = Menu:AddComboBox() + + local Min = ACF.FuelMinSize + local Max = ACF.FuelMaxSize + + local SizeX = Menu:AddSlider("Tank Length", Min, Max) + SizeX:SetClientData("TankSizeX", "OnValueChanged") + SizeX:DefineSetter(function(Panel, _, _, Value) + local X = math.Round(Value) + + Panel:SetValue(X) + + TankSize.x = X + + FuelType:UpdateFuelText() + + return X + end) + + local SizeY = Menu:AddSlider("Tank Width", Min, Max) + SizeY:SetClientData("TankSizeY", "OnValueChanged") + SizeY:DefineSetter(function(Panel, _, _, Value) + local Y = math.Round(Value) + + Panel:SetValue(Y) + + TankSize.y = Y + + FuelType:UpdateFuelText() + + return Y + end) + + local SizeZ = Menu:AddSlider("Tank Height", Min, Max) + SizeZ:SetClientData("TankSizeZ", "OnValueChanged") + SizeZ:DefineSetter(function(Panel, _, _, Value) + local Z = math.Round(Value) + + Panel:SetValue(Z) + + TankSize.z = Z + + FuelType:UpdateFuelText() + + return Z + end) + 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) @@ -128,6 +174,16 @@ local function CreateMenu(Menu) self.Selected = Data ACF.LoadSortedList(FuelList, Data.Items, "ID") + + -- Set up fuel tank settings as specified by the class + if Data.MenuSettings then + Data.MenuSettings(SizeX, SizeY, SizeZ, FuelList) + else + SizeX:SetVisible(false) + SizeY:SetVisible(false) + SizeZ:SetVisible(false) + FuelList:SetVisible(true) + end end function FuelList:OnSelect(Index, _, Data) @@ -139,12 +195,15 @@ local function CreateMenu(Menu) local ClassData = FuelClass.Selected local ClassDesc = ClassData.Description - self.Description = (ClassDesc and (ClassDesc .. "\n\n") or "") .. Data.Description + self.Description = (ClassDesc and (ClassDesc .. "\n\n") or "") + if Data.Description then + self.Description = self.Description .. Data.Description + end ACF.SetClientData("FuelTank", Data.ID) - FuelPreview:UpdateModel(Data.Model) - FuelPreview:UpdateSettings(Data.Preview) + FuelPreview:UpdateModel(Data.Model or ClassData.Model) + FuelPreview:UpdateSettings(Data.Preview or ClassData.Preview) FuelType:UpdateFuelText() end @@ -167,21 +226,37 @@ local function CreateMenu(Menu) local FuelTank = FuelList.Selected local TextFunc = self.Selected.FuelTankText local FuelText = "" + local FuelDescText = "" + + local Wall = ACF.FuelArmor * ACF.MmToInch -- Wall thickness in inches + local ClassData = FuelClass.Selected + local Volume, Area + + if ClassData.CalcVolume then + Volume, Area = ClassData.CalcVolume(TankSize, Wall) + else + Area = FuelTank.SurfaceArea + Volume = FuelTank.Volume - (FuelTank.SurfaceArea * Wall) -- Total volume of tank (cu in), reduced by wall thickness + end + + if ClassData.FuelDescText then + FuelDescText = ClassData.FuelDescText() + else + FuelDescText = "" + end - 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 Capacity = Volume * ACF.gCmToKgIn * ACF.TankVolumeMul -- Internal volume available for fuel in liters + 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 if TextFunc then FuelText = FuelText .. TextFunc(Capacity, Mass, EmptyMass) else - local Text = "Capacity : %s L - %s gal\nFull Mass : %s\nEmpty Mass : %s\n" + local Text = "Tank Armor : %s mm\nCapacity : %s L - %s gal\nFull Mass : %s\nEmpty Mass : %s" local Liters = math.Round(Capacity, 2) local Gallons = math.Round(Capacity * 0.264172, 2) - FuelText = FuelText .. Text:format(Liters, Gallons, ACF.GetProperMass(Mass), ACF.GetProperMass(EmptyMass)) + FuelText = FuelText .. Text:format(ACF.FuelArmor, Liters, Gallons, ACF.GetProperMass(Mass), ACF.GetProperMass(EmptyMass)) end if not FuelTank.IsExplosive then @@ -192,7 +267,7 @@ local function CreateMenu(Menu) FuelText = FuelText .. "\n\nThis fuel tank cannot be linked to other ACF entities." end - FuelDesc:SetText(FuelList.Description) + FuelDesc:SetText(FuelList.Description .. FuelDescText) FuelInfo:SetText(FuelText) end diff --git a/lua/entities/acf_fueltank/init.lua b/lua/entities/acf_fueltank/init.lua index 68963c0e5..625c84a7e 100644 --- a/lua/entities/acf_fueltank/init.lua +++ b/lua/entities/acf_fueltank/init.lua @@ -16,7 +16,6 @@ local RefillDist = ACF.RefillDistance * ACF.RefillDistance local TimerCreate = timer.Create local TimerExists = timer.Exists local HookRun = hook.Run -local Wall = 0.03937 --wall thickness in inches (1mm) local function CanRefuel(Refill, Tank, Distance) if Refill == Tank then return false end @@ -50,16 +49,45 @@ do -- Spawn and Update functions } local function VerifyData(Data) - if not Data.FuelTank then - Data.FuelTank = Data.SizeId or Data.Id or "Jerry_Can" + if not isstring(Data.FuelTank) then + Data.FuelTank = Data.SizeId or Data.Id end local Class = Classes.GetGroup(FuelTanks, Data.FuelTank) if not Class then - Data.FuelTank = "Jerry_Can" + Data.FuelTank = "Box" - Class = Classes.GetGroup(FuelTanks, "Jerry_Can") + Class = FuelTanks.Get("Box") + elseif FuelTanks.IsAlias(Data.FuelTank) then + Data.FuelTank = Class.ID + end + + if Class.IsScalable then + local FuelTank = FuelTanks.GetItem(Class.ID, Data.FuelTank) + + if FuelTank and FuelTank.Size then + Data.FuelTank = Class.ID + Data.Size = Vector(FuelTank.Size) + elseif not isvector(Data.Size) then + local X = ACF.CheckNumber(Data.TankSizeX, 24) + local Y = ACF.CheckNumber(Data.TankSizeY, 24) + local Z = ACF.CheckNumber(Data.TankSizeZ, 24) + + Data.Size = Vector(X, Y, Z) + end + + do -- Clamping size + local Min = ACF.FuelMinSize + local Max = ACF.FuelMaxSize + local Size = Data.Size + + Size.x = math.Clamp(math.Round(Size.x), Min, Max) + Size.y = math.Clamp(math.Round(Size.y), Min, Max) + Size.z = math.Clamp(math.Round(Size.z), Min, Max) + end + else + Data.Size = nil end -- Making sure to provide a valid fuel type @@ -81,48 +109,57 @@ do -- Spawn and Update functions local Percentage = Entity.Capacity and Entity.Fuel / Entity.Capacity or 1 Entity.ACF = Entity.ACF or {} - Entity.ACF.Model = FuelTank.Model -- Must be set before changing model - - Entity:SetModel(FuelTank.Model) + Entity.ACF.Model = FuelTank and FuelTank.Model or Class.Model -- Must be set before changing model + Entity.ClassData = Class - Entity:PhysicsInit(SOLID_VPHYSICS) - Entity:SetMoveType(MOVETYPE_VPHYSICS) - - local PhysObj = Entity:GetPhysicsObject() - local Area = PhysObj:GetSurfaceArea() + if Class.IsScalable then + Entity:SetSize(Data.Size) + else + Entity:SetModel(Entity.ACF.Model) + Entity:PhysicsInit(SOLID_VPHYSICS, true) + Entity:SetMoveType(MOVETYPE_VPHYSICS) + end -- Storing all the relevant information on the entity for duping for _, V in ipairs(Entity.DataStore) do Entity[V] = Data[V] end - Entity.Name = FuelTank.Name - Entity.ShortName = Entity.FuelTank + local Volume, Area + local Wall = ACF.FuelArmor * ACF.MmToInch -- Wall thickness in inches + + if Class.CalcVolume then + Volume, Area = Class.CalcVolume(Data.Size, Wall) + else -- Default to finding surface area/volume based off physics object instead + local PhysObj = Entity:GetPhysicsObject() + + Area = PhysObj:GetSurfaceArea() + Volume = PhysObj:GetVolume() - (Area * Wall) -- Total volume of tank (cu in), reduced by wall thickness + end + + local NameType = " " .. (Class.NameType or 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 = 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.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), - } - } + Entity.Capacity = Volume * ACF.gCmToKgIn * ACF.TankVolumeMul -- Internal volume available for fuel in liters + Entity.EmptyMass = (Area * Wall) * 16.387 * 0.0079 -- Total wall volume * cu in to cc * density of steel (kg/cc) + Entity.IsExplosive = FuelTank and FuelTank.IsExplosive or Class.IsExplosive + Entity.NoLinks = FuelTank and FuelTank.Unlinkable or Class.Unlinkable + Entity.Shape = FuelTank and FuelTank.Shape or Class.Shape 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.Liters = Entity.Capacity --batteries capacity is different from internal volume + Entity.Name = "Electric Battery" + Entity.Liters = Entity.Capacity -- Batteries capacity is different from internal volume Entity.Capacity = Entity.Capacity * ACF.LiIonED end + Entity:SetNWString("WireName", "ACF " .. Entity.Name) + Entity.Fuel = Percentage * Entity.Capacity ACF.Activate(Entity, true) @@ -133,6 +170,16 @@ do -- Spawn and Update functions WireLib.TriggerOutput(Entity, "Capacity", Entity.Capacity) end + hook.Add("ACF_CanUpdateEntity", "ACF Fuel Tank Size Update", function(Entity, Data) + 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.TankSizeX = nil + Data.TankSizeY = nil + Data.TankSizeZ = nil + end) + function MakeACF_FuelTank(Player, Pos, Angle, Data) VerifyData(Data) @@ -140,6 +187,7 @@ do -- Spawn and Update functions local FuelTank = FuelTanks.GetItem(Class.ID, Data.FuelTank) local FuelType = FuelTypes.Get(Data.FuelType) local Limit = Class.LimitConVar.Name + local Model = Class.Model or FuelTank and FuelTank.Model if not Player:CheckLimit(Limit) then return end @@ -152,6 +200,7 @@ do -- Spawn and Update functions if not IsValid(Tank) then return end Tank:SetPlayer(Player) + Tank:SetScaledModel(Model) Tank:SetAngles(Angle) Tank:SetPos(Pos) Tank:Spawn() @@ -195,7 +244,7 @@ do -- Spawn and Update functions return Tank end - Entities.Register("acf_fueltank", MakeACF_FuelTank, "FuelTank", "FuelType") + Entities.Register("acf_fueltank", MakeACF_FuelTank, "FuelTank", "FuelType", "Size") ACF.RegisterLinkSource("acf_fueltank", "Engines") @@ -270,9 +319,9 @@ end --===============================================================================================-- function ENT:ACF_Activate(Recalc) - local PhysObj = self.ACF.PhysObj + 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 @@ -308,17 +357,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) @@ -359,7 +408,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.ACF.PhysObj + local PhysObj = Entity:GetPhysicsObject() if IsValid(PhysObj) then Entity.ACF.Mass = Mass @@ -385,9 +434,13 @@ do -- Mass Update end do -- Overlay Update - local Text = "%s\n\nFuel Type: %s\n%s" + local Classes = ACF.Classes + local FuelTypes = Classes.FuelTypes + + local Text = "%s\n\n%sFuel Type: %s\n%s" function ENT:UpdateOverlayText() + local Size = "" local Status, Content if self.Leaking > 0 then @@ -396,19 +449,24 @@ do -- Overlay Update Status = self:CanConsume() and "Providing Fuel" or "Idle" end - if self.FuelType == "Electric" then -- TODO: Replace hardcoded stuff - local KiloWatt = math.Round(self.Fuel, 1) - local Joules = math.Round(self.Fuel * 3.6, 1) + local Class = self.ClassData - Content = "Charge Level: " .. KiloWatt .. " kWh / " .. Joules .. " MJ" + if Class and Class.CalcOverlaySize then + Size = Class.CalcOverlaySize(self) + end + + local FuelType = FuelTypes.Get(self.FuelType) + + if FuelType and FuelType.FuelTankOverlayText then + Content = FuelType.FuelTankOverlayText(self.Fuel) else - local Liters = math.Round(self.Fuel, 1) - local Gallons = math.Round(self.Fuel * 0.264172, 1) + local Liters = math.Round(self.Fuel, 2) + local Gallons = math.Round(self.Fuel * 0.264172, 2) Content = "Fuel Remaining: " .. Liters .. " liters / " .. Gallons .. " gallons" end - return Text:format(Status, self.FuelType, Content) + return Text:format(Status, Size, self.FuelType, Content) end end @@ -445,14 +503,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() @@ -499,3 +557,22 @@ function ENT:OnRemove() WireLib.Remove(self) end + +function ENT:OnResized(Size) + do -- Calculate new empty mass + local Wall = ACF.FuelArmor * ACF.MmToInch -- Wall thickness in inches + local Class = self.ClassData + local _, Area = Class.CalcVolume(Size, Wall) + + local Mass = (Area * Wall) * 16.387 * 0.0079 -- Total wall volume * cu in to cc * density of steel (kg/cc) + + self.EmptyMass = Mass + end + + self.HitBoxes = { + Main = { + Pos = self:OBBCenter(), + Scale = Size, + } + } +end \ No newline at end of file diff --git a/lua/entities/acf_fueltank/shared.lua b/lua/entities/acf_fueltank/shared.lua index cb8b4e803..5ca70c9c2 100644 --- a/lua/entities/acf_fueltank/shared.lua +++ b/lua/entities/acf_fueltank/shared.lua @@ -1,8 +1,8 @@ -DEFINE_BASECLASS("acf_base_simple") +DEFINE_BASECLASS("acf_base_scalable") ENT.PrintName = "ACF Fuel Tank" ENT.WireDebugName = "ACF Fuel Tank" ENT.PluralName = "ACF Fuel Tanks" ENT.IsACFFuelTank = true -cleanup.Register("acf_fueltank") +cleanup.Register("acf_fueltank") \ No newline at end of file