diff --git a/lua/entities/acf_engine/cl_init.lua b/lua/entities/acf_engine/cl_init.lua index 50b951a8..53bda2b7 100644 --- a/lua/entities/acf_engine/cl_init.lua +++ b/lua/entities/acf_engine/cl_init.lua @@ -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 @@ -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 @@ -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 @@ -86,11 +101,10 @@ 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) @@ -98,9 +112,10 @@ do -- Overlay 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() @@ -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 \ No newline at end of file diff --git a/lua/entities/acf_engine/init.lua b/lua/entities/acf_engine/init.lua index 56c0343c..31cb0dee 100644 --- a/lua/entities/acf_engine/init.lua +++ b/lua/entities/acf_engine/init.lua @@ -921,6 +921,7 @@ do -- NET SURFER 2.0 if IsValid(Entity) then local Outputs = {} + local FuelTanks = {} local Data = { Driveshaft = Entity.Out } @@ -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) diff --git a/lua/entities/acf_gearbox/cl_init.lua b/lua/entities/acf_gearbox/cl_init.lua index 5f555bc9..8839c976 100644 --- a/lua/entities/acf_gearbox/cl_init.lua +++ b/lua/entities/acf_gearbox/cl_init.lua @@ -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 @@ -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) @@ -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() @@ -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 @@ -124,6 +136,27 @@ 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 @@ -131,9 +164,9 @@ do -- Overlay 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) @@ -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) diff --git a/lua/entities/acf_gun/cl_init.lua b/lua/entities/acf_gun/cl_init.lua index 03974de9..73804b6b 100644 --- a/lua/entities/acf_gun/cl_init.lua +++ b/lua/entities/acf_gun/cl_init.lua @@ -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 @@ -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 \ No newline at end of file diff --git a/lua/entities/acf_gun/init.lua b/lua/entities/acf_gun/init.lua index b721215e..95b29621 100644 --- a/lua/entities/acf_gun/init.lua +++ b/lua/entities/acf_gun/init.lua @@ -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 diff --git a/lua/entities/acf_seat_alias/init.lua b/lua/entities/acf_seat_alias/init.lua index 53c7c90c..f251cfec 100644 --- a/lua/entities/acf_seat_alias/init.lua +++ b/lua/entities/acf_seat_alias/init.lua @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/lua/weapons/gmod_tool/stools/acf_menu.lua b/lua/weapons/gmod_tool/stools/acf_menu.lua index 1dd86d54..c2888fb7 100644 --- a/lua/weapons/gmod_tool/stools/acf_menu.lua +++ b/lua/weapons/gmod_tool/stools/acf_menu.lua @@ -32,7 +32,7 @@ if CLIENT then if (IsValid(Entity) and Entity.CleanupOverlay) or IsValid(self.LastEntity) then if IsValid(self.LastEntity) and self.LastEntity ~= Entity then self.LastEntity:CleanupOverlay() end - self.LastEntity = Entity + if Entity.CleanupOverlay then self.LastEntity = Entity else self.LastEntity = nil end end if not IsValid(Entity) then return end