Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 16 additions & 2 deletions lua/acf/client/cl_acfmenu_gui.lua
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,9 @@ function PANEL:Init( )

local Mobility = HomeNode:AddNode( "Mobility" , "icon16/car.png" ) --Mobility folder
local Engines = Mobility:AddNode( "Engines" , ItemIcon )
local Gearboxes = Mobility:AddNode( "Gearboxes" , ItemIcon )
local FuelTanks = Mobility:AddNode( "Fuel Tanks" , ItemIcon )
local Gearboxes = Mobility:AddNode( "Gearboxes" , "icon16/cog.png" )
local FuelTanks = Mobility:AddNode( "Fuel Tanks" , "icon16/cog.png" )
local Radiators = Mobility:AddNode( "Radiators" , "icon16/cog.png" )

local EngineCatNodes = {} --Stores all Engine Cats Nodes (V12, V8, I4, etc)
local GearboxCatNodes = {} --Stores all Gearbox Cats Nodes (CVT, Transfer, etc)
Expand Down Expand Up @@ -273,6 +274,19 @@ function PANEL:Init( )

break
end

-------------------- Radiator folder --------------------

--Creates the only button to access to radiator config menu.
for _, RadiatorData in pairs(FinalContainer["Radiators"]) do

function Radiators:DoClick()
RunConsoleCommand( "acfmenu_type", RadiatorData.type )
acfmenupanel:UpdateDisplay( RadiatorData )
end

break
end
end
do
--[[==================================================
Expand Down
75 changes: 75 additions & 0 deletions lua/acf/server/sv_heat.lua
Original file line number Diff line number Diff line change
Expand Up @@ -280,3 +280,78 @@ function ACE_HeatFromEngine( Engine , Radiator ) --radiator?!? woooo
end
]]--

--ACE.AmbientTemp

--The following functions require any entity involved to:
--Have a specific heat defined
--Have a thermal transfer coefficient defined
--Surface area

function ACE_GetThermalMass(Ent)

local Mass = Ent.ThermalMass or -1

if Mass == -1 then
local Phys = Ent:GetPhysicsObject()
if Phys:IsValid() then
Mass = Phys:GetMass()
Ent.ThermalMass = Mass
else
Mass = 1000
end
end

return Mass
end

function ACE_AddThermalEnergy(Ent, KJ) --Used to add or remove thermal energy

local SpecificHeat = Ent.ACESpecificHeat or 0.9211 --Uses specific heat of aluminum if unavailable
local Mass = ACE_GetThermalMass(Ent)

local DeltaTemp = KJ / SpecificHeat / Mass

Ent.Heat = (Ent.Heat or ACE.AmbientTemp) + DeltaTemp
end

function ACE_EqualizeThermalEnergy(Ent1, Ent2) --Instantly balances the thermal energy of 2 objects. Useful for radiators or things one doesn't care for heat transfer rates with.

local SpecificHeat1 = Ent1.ACESpecificHeat or 0.9211 --Uses specific heat of aluminum if unavailable
local SpecificHeat2 = Ent2.ACESpecificHeat or 0.9211

local TMass1 = ACE_GetThermalMass(Ent1)
local TMass2 = ACE_GetThermalMass(Ent2)
local TotalMass = TMass1 + TMass2

local Ratio1 = TMass1/TotalMass
local Ratio2 = TMass2/TotalMass

local AvgSpecificHeat = SpecificHeat1 * Ratio1 + SpecificHeat2 * Ratio2

--I LOVE KELVIN AND HAVING TO RECONVERT EVERYTHING 4 TIMES!!!!!!!! :)

local ThermalEnergy1 = Ent1.Heat * SpecificHeat1 * TMass1
local ThermalEnergy2 = Ent2.Heat * SpecificHeat2 * TMass2
local TotalEnergy = ThermalEnergy1 + ThermalEnergy2

local FinalTemp = TotalEnergy / AvgSpecificHeat / TotalMass

Ent1.Heat = FinalTemp
Ent2.Heat = FinalTemp
end

function ACE_AtmosphericHeatDissipation(Ent, CoolingMultiplier, DeltaTime) --Could be optimized by breaking into more functions. The rate doesn't need to be calculated every iteration riiiiiiiigt?
local ThermalTransferCoefficient = Ent.AtmosphericCoefficient or 5 --5 W / M^2 * K, the thermal transfer coefficient of aluminum to air
local SurfaceArea = Ent.ThermalSurfaceArea --Area in meters squared

local TempDif = ACE.AmbientTemp - Ent.Heat

local TransferRate = ThermalTransferCoefficient * SurfaceArea * TempDif * CoolingMultiplier

--print(TransferRate * DeltaTime * ACF.ThermalTimeScale)
--print(TransferRate * ACF.ThermalTimeScale / DeltaTime / ACF.ThermalTimeScale) --1 Second cooling
ACE_AddThermalEnergy(Ent, TransferRate * DeltaTime * ACF.ThermalTimeScale)
end


--AtmosphericHeatExchange with speed--
25 changes: 25 additions & 0 deletions lua/acf/shared/ammocrates/ammocrates.lua
Original file line number Diff line number Diff line change
Expand Up @@ -276,3 +276,28 @@ ACE_DefineModelData("Cone",{
return volume
end
})

--Radiator. DefaultSize has issues with 3d vectors. Using external scaling for now.
ACE_DefineModelData("Radiator",{

Shape = "Radiator",
Model = "models/radiators/radiator_med.mdl", --Note: The model can be used as ID if needed.
physMaterial = "metal",
DefaultSize = 1, --Maybe later make scalable models support 3d hitboxes? Until then cope with it.
CustomMesh = { --Its a box anyways
{
Vector(17.8875, 2.25, 11.25),
Vector(17.8875, -2.25, 11.25),
Vector(-17.8875, 2.25, 11.25),
Vector(-17.8875, -2.25, 11.25),
Vector(17.8875, 2.25, -11.25),
Vector(17.8875, -2.25, -11.25),
Vector(-17.8875, 2.25, -11.25),
Vector(-17.8875, -2.25, -11.25)
},
},
volumefunction = function( L, W, H )
local volume = L * W * H
return volume
end
})
156 changes: 137 additions & 19 deletions lua/acf/shared/engines/ace_engine_properties.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,158 @@ ACF.FuelDensity = { --kg/liter
Petrol = 0.745,
Electric = 1.35 -- li-ion --WAS 3.1
}
ACF.FuelPowerDensity = { --KJ/liter
Diesel = 38.6,
Petrol = 33.6,
Electric = 1 --TODO: Find conversion units. Fine for now. Electric doesn't generate too much heat to be of concern.
}



ACF.PerFuelRelativeEfficiency = { --Efficiency multipliers when using various fuels
Diesel = 1.375, --42% more fuel efficicient but slightly less(1.02x) kg efficient for a unit of fuel.
Petrol = 1,
Electric = 1 --TODO: Find conversion units. Fine for now. Electric doesn't generate too much heat to be of concern.
}

--Power density of fuel. They're close enough so we'll use the density of gasoline to give engines the benefit of the doubt.
--This way we score efficiency more on the type of engine and less so fuel which will be seperated. Especially as we're scoring their efficiency as a type.
--local BasePetrol = 1/13 --13kWh per kg gasoline. or ~0.077 kg per kw hr
--local BaseDiesel = 1/12.6 --12.6kWh per kg Diesel. Or ~0.079 kg per kw hr

local BaseFuel = 1/13 --13kWh per kg or ~0.077 kg per kw hr. The fuel density of gasoline. Diesel is 12.6kWh per kg or ~0.079 kg per kw hr.

ACF.Efficiency = { --how efficient various engine types are, Final units are in kg/kWhr
GenericPetrol = (BaseFuel / 0.35), --Divide by % efficiency. Was 38%. Needs to be kept for other legacy engines.
GenericDiesel = (BaseFuel / 0.5), --Was 49% efficient. Was 38%. Needs to be kept for other legacy engines.

Single = (BaseFuel / 0.4), --Divide by % efficiency. Was 38%
I2 = (BaseFuel / 0.395), --Divide by % efficiency. Was 38%
I3 = (BaseFuel / 0.39), --Divide by % efficiency. Was 38%
I4 = (BaseFuel / 0.385), --Divide by % efficiency. Was 38%
I5 = (BaseFuel / 0.38), --Divide by % efficiency. Was 38%
I6 = (BaseFuel / 0.375), --Divide by % efficiency. Was 38%

B4 = (BaseFuel / 0.365), --Divide by % efficiency. Was 38%
B6 = (BaseFuel / 0.36), --Divide by % efficiency. Was 38%

ACF.Efficiency = { --how efficient various engine types are, higher is worse
GenericPetrol = 0.203, --kg per kw hr
GenericDiesel = 0.162, --up to 0.274
Turbine = 0.25, -- previously 0.231
Wankel = 0.223,
Radial = 0.267, -- 0.38 to 0.53
Electric = 0.6 --percent efficiency converting chemical kw into mechanical kw WAS 0.85
V2 = (BaseFuel / 0.35), --Divide by % efficiency. Was 38%
V4 = (BaseFuel / 0.345), --Divide by % efficiency. Was 38%
V6 = (BaseFuel / 0.34), --Divide by % efficiency. Was 38%
V8 = (BaseFuel / 0.335), --Divide by % efficiency. Was 38%
V10 = (BaseFuel / 0.33), --Divide by % efficiency. Was 38%
V12 = (BaseFuel / 0.325), --Divide by % efficiency. Was 38%

Turbine = (BaseFuel / 0.35), --Was 32% efficient. Somewhere between a turboshaft and turbofan.
--Turbofan = (BaseFuel / 0.4), --Was 32% efficient.
GroundTurbine = (BaseFuel / 0.3), --Was 32% efficient.
Wankel = (BaseFuel / 0.25), --Was 34%. Almost on par with regular petrol. Get. Outta. Here.
Radial = (BaseFuel / 0.28), --Was 30% efficient.

Racing = (BaseFuel / 0.2), --Racing duty engines meant for absurd speeds. Inefficient but power dense as hell.

Electric = 0.85 --percent efficiency converting chemical kw into mechanical kw WAS 0.85
}

ACF.TorqueScale = { --how fast damage drops torque, lower loses more % torque
GenericPetrol = 0.25,
GenericDiesel = 0.35,
Turbine = 0.2,
GenericDiesel = 0.5,

Single = 0.25,
I2 = 0.25,
I3 = 0.275,
I4 = 0.3,
I5 = 0.325,
I6 = 0.35,

B4 = 0.3,
B6 = 0.325,

V2 = 0.25,
V4 = 0.275,
V6 = 0.3,
V8 = 0.3,
V10 = 0.325,
V12 = 0.35,

Turbine = 0.15,
GroundTurbine = 0.2,
Wankel = 0.2,
Radial = 0.3,
Electric = 0.3 --WAS 0.5

Racing = 0.1,

Electric = 0.2
}

ACF.EngineHPMult = { --health multiplier for engines
GenericPetrol = 0.2,
GenericDiesel = 0.5,
Turbine = 0.125,
Wankel = 0.125,
Radial = 0.3,
Electric = 0.75

GenericPetrol = 0.15,
GenericDiesel = 0.2,

Single = 0.1,
I2 = 0.1,
I3 = 0.125,
I4 = 0.15,
I5 = 0.175,
I6 = 0.2,

B4 = 0.125,
B6 = 0.15,

V2 = 0.1,
V4 = 0.1,
V6 = 0.125,
V8 = 0.15,
V10 = 0.175,
V12 = 0.2,

Turbine = 0.05,
GroundTurbine = 0.05,
Wankel = 0.1,
Radial = 0.2,

Racing = 0.1,

Electric = 0.1
}


ACF.PerFuelTorqueCurveMul = { --Efficiency multipliers when using various fuels
Diesel = {1,1.64,1.43,1.12,0.9,0.89,0.93},
Petrol = {1,1,1,1,1,1,1},
Electric = {1,1,1,1,1,1,1}
}

--Use this to help design torque curves https://gist.github.com/CheezusChrust/7ccce5f5196d3adc95ab9573009f735a
ACF.GenericTorqueCurves = { --Default curves for engines that don't have one defined

GenericPetrol = {0.3, 0.55, 0.7, 0.85, 1, 0.9, 0.7},
GenericDiesel = {0.3, 0.9, 0.97, 1, 0.95, 0.9, 0.8, 0.65},
Turbine = {0.8, 1, 0.9, 0.8, 0.6, 0.4, 0.2, 0.1},
GenericDiesel = {0.3, 0.55, 0.7, 0.85, 1, 0.9, 0.7}, --Needed for legacy and extra engines. It's set the same as petrol because the diesel engines are modified to a diesel torque curve by the fueltype curve. True values = {0.3, 0.97, 1, 0.95, 0.9, 0.8, 0.65}

Single = {0.4, 0.65, 0.96, 1.0, 0.93, 0.8, 0.71},
I2 = {0.4, 0.65, 0.96, 1.0, 0.93, 0.8, 0.71}, --Inlines are similar to V-Block engines except with excellent low end torque and a generally more stable powerband. Made up for by being less energy dense.
I3 = {0.4, 0.62, 0.88, 1.0, 0.95, 0.82, 0.73},
I4 = {0.4, 0.52, 0.74, 0.95, 1.0, 0.85, 0.75},
I5 = {0.4, 0.49, 0.65, 0.82, 1, 0.92, 0.7},
I6 = {0.4, 0.48, 0.6, 0.76, 0.95, 1.0, 0.875},

B4 = {0.3, 0.48, 0.76, 1, 0.94, 0.74, 0.67}, --Boxer types have a wide torquey band with a narrow peak they produce peak power at.
B6 = {0.35, 0.49, 0.67, 0.87, 1, 0.85, 0.73},

V2 = {0.3, 0.65, 0.95, 1.0, 0.91, 0.8, 0.68},
V4 = {0.3, 0.65, 0.95, 1.0, 0.91, 0.8, 0.68}, --Excellent low end torque and torque over a wide range. But the least peak HP
V6 = {0.35, 0.6, 0.84, 1.0, 0.95, 0.81, 0.7}, --Good torque over a wide range but less high range power
V8 = {0.35, 0.52, 0.72, 0.92, 1.0, 0.85, 0.72}, --Good torque at the upper mid range and a relatively wide range. Results in good horsepower.
V10 = {0.35, 0.49, 0.65, 0.82, 1, 0.92, 0.66}, --A wide but narrower torque band than the V8. Geared slightly more towards peak horsepower.
V12 = {0.3, 0.4, 0.55, 0.72, 0.9, 1.0, 0.875}, --Trades instantaneous torque for higher RPM torque. Best for peak horsepower in the upper range.

Turbine = {1, 0.9, 0.8, 0.6, 0.4, 0.2, 0.1},
GroundTurbine = {1, 0.59, 0.58, 0.65, 0.72, 0.66, 0.57}, --Turbine with internal reduction gearing producing instantaneous torque. Reduced from true values because of the fueltype curve. True Values = {1, 0.97, 0.84, 0.73, 0.65, 0.59, 0.529}
Wankel = {0.35, 0.7, 0.85, 0.95, 1, 0.9, 0.7},
Radial = {0.6, 0.75, 0.85, 0.95, 0.98, 0.6},
Radial = {0.4, 0.5, 0.65, 0.75, 0.95, 1, 0.5},

Racing = {0.3, 0.4, 0.55, 0.72, 0.9, 1.0, 0.875}, --Significantly power dense engines designed for peak power output at the cost of longevity.

Electric = {1, 0.99, 0.95, 0.6, 0.2}
}
Loading
Loading