Skip to content

Commit

Permalink
More overlays, also seat alias fixes
Browse files Browse the repository at this point in the history
Allowed the seat alias to recreate itself if it is able to (player still sitting) instead of being fully gone
Also fixed an issue with the seat alias overlay erroring

Further improvements to geartrain overlay (added connections within a gearbox)
Weapons overlay (shows linked ammo crates)
  • Loading branch information
LiddulBOFH committed May 28, 2024
1 parent 28cdcfe commit a2c6428
Show file tree
Hide file tree
Showing 7 changed files with 182 additions and 29 deletions.
39 changes: 32 additions & 7 deletions lua/entities/acf_engine/cl_init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,31 @@ do -- NET SURFER 2.0
local Engine = net.ReadEntity()
local Data = util.JSONToTable(net.ReadString())
local Outputs = util.JSONToTable(net.ReadString())
local Fuel = util.JSONToTable(net.ReadString())

local OutEnts = {}
local FuelTanks = {}

for _,E in ipairs(Outputs) do
local Ent = Entity(E)
local Pos = Ent:WorldToLocal(Ent:GetAttachment(Ent:LookupAttachment("input")).Pos)

OutEnts[#OutEnts + 1] = {Ent = Ent, Pos = Pos}
if IsValid(Ent) then
local Pos = Ent:WorldToLocal(Ent:GetAttachment(Ent:LookupAttachment("input")).Pos)

OutEnts[#OutEnts + 1] = {Ent = Ent, Pos = Pos}
end
end

for _,E in ipairs(Fuel) do
local Ent = Entity(E)

if IsValid(Ent) then
FuelTanks[#FuelTanks + 1] = {Ent = Ent}
end
end

Engine.Outputs = OutEnts
Engine.FuelTanks = FuelTanks

Engine.Driveshaft = Data.Driveshaft

Expand All @@ -61,7 +75,7 @@ end
do -- Overlay
-- Rendered is used to prevent re-rendering as part of the extended link rendering

local red = Color(255,0,0)
local source = Color(255,255,0)
local orange = Color(255,127,0)
function ENT:DrawLinks(Rendered)
if Rendered[self] then return end
Expand All @@ -78,6 +92,7 @@ do -- Overlay

-- draw links to gearboxes
local Perc = (Clock.CurTime / 2) % 1
local Rad = TimedCos(0.5, 2, 3, 0)

local OutPos = self:LocalToWorld(SelfTbl.Driveshaft)
for _,T in ipairs(SelfTbl.Outputs) do
Expand All @@ -86,21 +101,21 @@ do -- Overlay
if IsValid(E) then

local Pos = E:LocalToWorld(T.Pos)
--render.DrawLine(OutPos, Pos, color_white, true)
render.DrawBeam(OutPos, Pos, 2, 0, 0, color_black)
render.DrawBeam(OutPos, Pos, 1.5, 0, 0, color_white)
local SpherePos = LerpVector(Perc, OutPos, Pos)
render.DrawSphere(SpherePos, 2, 4, 3, orange)
render.DrawSphere(SpherePos, 1.5, 4, 3, orange)

if E.DrawLinks then
E:DrawLinks(Rendered,false)
end
end
end

render.DrawSphere(OutPos, 2, 4, 3, red)
render.DrawSphere(OutPos, Rad, 4, 3, source)
end

local FuelColor = Color(255,255,0,25)
function ENT:DrawOverlay()
local SelfTbl = self:GetTable()

Expand All @@ -113,11 +128,21 @@ do -- Overlay

render.SetColorMaterial()

if next(SelfTbl.FuelTanks) then
for _,T in ipairs(SelfTbl.FuelTanks) do
local E = T.Ent
if IsValid(E) then
render.DrawWireframeBox(E:GetPos(),E:GetAngles(),E:OBBMins(),E:OBBMaxs(),FuelColor,true)
render.DrawBox(E:GetPos(),E:GetAngles(),E:OBBMins(),E:OBBMaxs(),FuelColor)
end
end
end

self:DrawLinks({self = true}, true)

local OutTextPos = self:LocalToWorld(SelfTbl.Driveshaft):ToScreen()
cam.Start2D()
draw.SimpleTextOutlined("Output","ACF_Title",OutTextPos.x,OutTextPos.y,color_white,TEXT_ALIGN_CENTER,TEXT_ALIGN_CENTER,1,color_black)
draw.SimpleTextOutlined("Power Source","ACF_Title",OutTextPos.x,OutTextPos.y,color_white,TEXT_ALIGN_CENTER,TEXT_ALIGN_CENTER,1,color_black)
cam.End2D()
end
end
8 changes: 8 additions & 0 deletions lua/entities/acf_engine/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -921,6 +921,7 @@ do -- NET SURFER 2.0

if IsValid(Entity) then
local Outputs = {}
local FuelTanks = {}
local Data = {
Driveshaft = Entity.Out
}
Expand All @@ -931,10 +932,17 @@ do -- NET SURFER 2.0
end
end

if next(Entity.FuelTanks) then
for E in pairs(Entity.FuelTanks) do
FuelTanks[#FuelTanks + 1] = E:EntIndex()
end
end

net.Start("ACF_RequestEngineInfo")
net.WriteEntity(Entity)
net.WriteString(util.TableToJSON(Data))
net.WriteString(util.TableToJSON(Outputs))
net.WriteString(util.TableToJSON(FuelTanks))
net.Send(Ply)
end
end)
Expand Down
63 changes: 48 additions & 15 deletions lua/entities/acf_gearbox/cl_init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -35,28 +35,36 @@ do -- NET SURFER 2.0
for _,E in ipairs(Inputs) do
local Ent = Entity(E)

InEnts[#InEnts + 1] = {Ent = Ent}
if IsValid(Ent) then
InEnts[#InEnts + 1] = {Ent = Ent}
end
end

for _,E in ipairs(OutL) do
local Ent = Entity(E)
local Pos = Vector()

if Ent:GetClass() == "acf_gearbox" then
Pos = Ent:WorldToLocal(Ent:GetAttachment(Ent:LookupAttachment("input")).Pos)
end
if IsValid(Ent) then
local Pos = Vector()

if Ent:GetClass() == "acf_gearbox" then
Pos = Ent:WorldToLocal(Ent:GetAttachment(Ent:LookupAttachment("input")).Pos)
end

OutLEnts[#OutLEnts + 1] = {Ent = Ent, Pos = Pos}
OutLEnts[#OutLEnts + 1] = {Ent = Ent, Pos = Pos}
end
end
for _,E in ipairs(OutR) do
local Ent = Entity(E)
local Pos = Vector()

if Ent:GetClass() == "acf_gearbox" then
Pos = Ent:WorldToLocal(Ent:GetAttachment(Ent:LookupAttachment("input")).Pos)
end
if IsValid(Ent) then
local Pos = Vector()

OutREnts[#OutREnts + 1] = {Ent = Ent, Pos = Pos}
if Ent:GetClass() == "acf_gearbox" then
Pos = Ent:WorldToLocal(Ent:GetAttachment(Ent:LookupAttachment("input")).Pos)
end

OutREnts[#OutREnts + 1] = {Ent = Ent, Pos = Pos}
end
end

Gearbox.Inputs = InEnts
Expand All @@ -66,6 +74,7 @@ do -- NET SURFER 2.0
Gearbox.In = Data.In
Gearbox.OutL = Data.OutL
Gearbox.OutR = Data.OutR
Gearbox.Mid = (Data.OutL + Data.OutR) / 2

Gearbox.IsStraight = (Data.OutL == Data.OutR)

Expand Down Expand Up @@ -96,6 +105,8 @@ do -- Overlay
local teal = Color(0,195,255)
local red = Color(255,0,0)
local green = Color(0,255,0)
local innerConnection = Color(127,127,127)
local outerConnection = Color(255,255,255)
function ENT:DrawLinks(Rendered)
if Rendered[self] then return end
local SelfTbl = self:GetTable()
Expand All @@ -114,6 +125,7 @@ do -- Overlay
local InPos = self:LocalToWorld(SelfTbl.In)
local LeftPos = self:LocalToWorld(SelfTbl.OutL)
local RightPos = self:LocalToWorld(SelfTbl.OutR)
local MidPoint = self:LocalToWorld(SelfTbl.Mid)

-- Rendering more along the chain
for _,T in ipairs(SelfTbl.Inputs) do
Expand All @@ -124,16 +136,37 @@ do -- Overlay
end
end


if not SelfTbl.IsStraight then
render.DrawBeam(LeftPos, RightPos, 2, 0, 0, color_black)
render.DrawBeam(LeftPos, RightPos, 1.5, 0, 0, innerConnection)
render.DrawBeam(InPos, MidPoint, 2, 0, 0, color_black)
render.DrawBeam(InPos, MidPoint, 1.5, 0, 0, innerConnection)

local SpherePos1 = LerpVector(Perc, InPos, MidPoint)
render.DrawSphere(SpherePos1, 1.5, 4, 3, orange)
local SpherePos2 = LerpVector(Perc, MidPoint, LeftPos)
render.DrawSphere(SpherePos2, 1.5, 4, 3, orange)
local SpherePos3 = LerpVector(Perc, MidPoint, RightPos)
render.DrawSphere(SpherePos3, 1.5, 4, 3, orange)
else
render.DrawBeam(InPos, LeftPos, 2, 0, 0, color_black)
render.DrawBeam(InPos, LeftPos, 1.5, 0, 0, innerConnection)

local SpherePos1 = LerpVector(Perc, InPos, LeftPos)
render.DrawSphere(SpherePos1, 1.5, 4, 3, orange)
end

for _,T in ipairs(SelfTbl.OutputsL) do
local E = T.Ent

if IsValid(E) then

local Pos = E:LocalToWorld(T.Pos)
render.DrawBeam(LeftPos, Pos, 2, 0, 0, color_black)
render.DrawBeam(LeftPos, Pos, 1.5, 0, 0, color_white)
render.DrawBeam(LeftPos, Pos, 1.5, 0, 0, outerConnection)
local SpherePos = LerpVector(Perc, LeftPos, Pos)
render.DrawSphere(SpherePos, 2, 4, 3, orange)
render.DrawSphere(SpherePos, 1.5, 4, 3, orange)

if E.DrawLinks then
E:DrawLinks(Rendered,false)
Expand All @@ -150,9 +183,9 @@ do -- Overlay

local Pos = E:LocalToWorld(T.Pos)
render.DrawBeam(RightPos, Pos, 2, 0, 0, color_black)
render.DrawBeam(RightPos, Pos, 1.5, 0, 0, color_white)
render.DrawBeam(RightPos, Pos, 1.5, 0, 0, outerConnection)
local SpherePos = LerpVector(Perc, RightPos, Pos)
render.DrawSphere(SpherePos, 2, 4, 3, orange)
render.DrawSphere(SpherePos, 1.5, 4, 3, orange)

if E.DrawLinks then
E:DrawLinks(Rendered,false)
Expand Down
62 changes: 62 additions & 0 deletions lua/entities/acf_gun/cl_init.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
local ACF = ACF
local Clock = ACF.Utilities.Clock
local Queued = {}

DEFINE_BASECLASS("acf_base_scalable") -- Required to get the local BaseClass

Expand Down Expand Up @@ -72,3 +73,64 @@ function ENT:Animate(ReloadTime, LoadOnly)
self.LastFire = Clock.CurTime
self.Reload = ReloadTime
end

do -- Overlay/networking for that

function ENT:RequestGunInfo()
if Queued[self] then return end

Queued[self] = true

timer.Simple(5, function() Queued[self] = nil end)

net.Start("ACF.RequestGunInfo")
net.WriteEntity(self)
net.SendToServer()
end

net.Receive("ACF.RequestGunInfo",function()
local Gun = net.ReadEntity()
if not IsValid(Gun) then return end

Queued[Gun] = nil

local Crates = util.JSONToTable(net.ReadString())
local CrateEnts = {}

for _,E in ipairs(Crates) do
local Ent = Entity(E)

if IsValid(Ent) then
local Col = ColorAlpha(Ent:GetColor(),25)
CrateEnts[#CrateEnts + 1] = {Ent = Ent, Col = Col}
end
end

Gun.Crates = CrateEnts
Gun.Age = Clock.CurTime + 5
Gun.HasData = true
end)

function ENT:DrawOverlay()
local SelfTbl = self:GetTable()

if not SelfTbl.HasData then
self:RequestGunInfo()
return
elseif Clock.CurTime > SelfTbl.Age then
self:RequestGunInfo()
end

render.SetColorMaterial()

if next(SelfTbl.Crates) then
for _,T in ipairs(SelfTbl.Crates) do
local E = T.Ent
if IsValid(E) then
render.DrawWireframeBox(E:GetPos(),E:GetAngles(),E:OBBMins(),E:OBBMaxs(),T.Col,true)
render.DrawBox(E:GetPos(),E:GetAngles(),E:OBBMins(),E:OBBMaxs(),T.Col)
end
end
end
end
end
21 changes: 21 additions & 0 deletions lua/entities/acf_gun/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -830,6 +830,27 @@ do -- Metamethods --------------------------------
end
end -----------------------------------------

do -- Other networking
util.AddNetworkString("ACF.RequestGunInfo")
net.Receive("ACF.RequestGunInfo",function(_,Ply)
local Gun = net.ReadEntity()
if not IsValid(Gun) then return end

local AmmoCrates = {}

if next(Gun.Crates) then
for Crate in pairs(Gun.Crates) do
AmmoCrates[#AmmoCrates + 1] = Crate:EntIndex()
end
end

net.Start("ACF.RequestGunInfo")
net.WriteEntity(Gun)
net.WriteString(util.TableToJSON(AmmoCrates))
net.Send(Ply)
end)
end

do -- Misc ----------------------------------
function ENT:ACF_Activate(Recalc)
local PhysObj = self.ACF.PhysObj
Expand Down
16 changes: 10 additions & 6 deletions lua/entities/acf_seat_alias/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ do -- Spawn functions
Ent:EnableCustomCollisions()

local Ply = Vehicle:GetDriver()
Ent.Driver = Ply
Ent.Seat = Vehicle
Ent.AliasInfo = AliasInfo
Ent.Owner = Ply
Expand Down Expand Up @@ -101,9 +102,8 @@ do -- Metamethods
if not IsValid(SelfTbl.Seat) then self:Remove() end
if SelfTbl.Seat.AliasEnt ~= self then self:Remove() end

local Driver = SelfTbl.Seat:GetDriver()
if self:GetParent() ~= SelfTbl.Seat then if IsValid(Driver) then SelfTbl.Seat:GetDriver():ExitVehicle() else self:Remove() end end
if SelfTbl.Seat:GetModel() ~= SelfTbl.Seat._Alias.SeatModel then if IsValid(Driver) then SelfTbl.Seat:GetDriver():ExitVehicle() else self:Remove() end end
if self:GetParent() ~= SelfTbl.Seat then self:Remove() end
if SelfTbl.Seat:GetModel() ~= SelfTbl.Seat._Alias.SeatModel then self:Remove() end

self:NextThink(CurTime() + 15)
return true
Expand All @@ -126,8 +126,8 @@ do -- Metamethods
end

function ENT:ACF_OnDamage(DmgResult, DmgInfo)
local Ply = self:GetOwner()
if not (IsValid(Ply) and IsValid(self.Seat) and (Ply == self.Seat:GetDriver())) then print("Bullet hit alias with no valid player/seat, removing") self:Remove() return HitRes end
local Ply = self.Driver
if not (IsValid(Ply) and IsValid(self.Seat)) then self:Remove() return HitRes end
local HitRes = Damage.doSquishyDamage(Ply, DmgResult, DmgInfo)

return HitRes
Expand All @@ -136,8 +136,12 @@ do -- Metamethods
function ENT:OnRemove()
if IsValid(self.Seat) and (self.Seat.AliasEnt == self) then
self.Seat.AliasEnt = nil
end

if IsValid(self.Seat:GetDriver()) then self.Seat:GetDriver():ExitVehicle() end
if IsValid(self.Driver) then
local Seat = self.Seat
local Driver = self.Driver
timer.Simple(0,function() if IsValid(Seat) and IsValid(Driver) then ACF.ApplyAlias(Seat,Driver) end end)
end
end
end
Expand Down
Loading

0 comments on commit a2c6428

Please sign in to comment.