From 7199f0d5ec2df086f304507c53dc19f8e90ed781 Mon Sep 17 00:00:00 2001 From: Artiom Parygin Date: Sat, 4 Dec 2021 10:19:11 +0300 Subject: [PATCH 01/25] Spin control --- .../gmod_tardis/modules/sh_flight.lua | 28 ++----- .../gmod_tardis/modules/sh_vortex.lua | 4 +- lua/entities/gmod_tardis/modules/sv_spin.lua | 81 +++++++++++++++++++ lua/tardis/controls/sh_control_spin_cycle.lua | 20 +++++ .../controls/sh_control_spin_switch.lua | 18 +++++ .../controls/sh_control_spin_toggle.lua | 17 ++++ lua/tardis/interiors/default.lua | 1 + .../parts/default/default_int_atomaccel.lua | 17 ---- 8 files changed, 146 insertions(+), 40 deletions(-) create mode 100644 lua/entities/gmod_tardis/modules/sv_spin.lua create mode 100644 lua/tardis/controls/sh_control_spin_cycle.lua create mode 100644 lua/tardis/controls/sh_control_spin_switch.lua create mode 100644 lua/tardis/controls/sh_control_spin_toggle.lua diff --git a/lua/entities/gmod_tardis/modules/sh_flight.lua b/lua/entities/gmod_tardis/modules/sh_flight.lua index 4c52c07ab..beb3a15b7 100644 --- a/lua/entities/gmod_tardis/modules/sh_flight.lua +++ b/lua/entities/gmod_tardis/modules/sh_flight.lua @@ -78,18 +78,7 @@ TARDIS:AddKeyBind("flight-spindir",{ func=function(self,down,ply) if TARDIS:HUDScreenOpen(ply) then return end if down and ply==self.pilot then - local dir - if self.spindir==-1 then - self.spindir=0 - dir="none" - elseif self.spindir==0 then - self.spindir=1 - dir="clockwise" - elseif self.spindir==1 then - self.spindir=-1 - dir="anti-clockwise" - end - TARDIS:Message(ply, "Spin direction set to "..dir) + TARDIS:Control("spin_cycle", ply) end end, key=MOUSE_RIGHT, @@ -190,10 +179,6 @@ if SERVER then end) end) - ENT:AddHook("Initialize", "flight", function(self) - self.spindir=-1 - end) - ENT:AddHook("Think", "flight", function(self) if self:GetData("flight") then self.phys:Wake() @@ -269,9 +254,10 @@ if SERVER then end end - if self.spindir==0 then + local spindir = self:GetSpinDir() + if spindir==0 then tilt=0 - elseif self.spindir==1 then + elseif spindir == 1 then tforce=-tforce end @@ -280,7 +266,7 @@ if SERVER then ph:ApplyForceOffset( up*-(ang.r-tilt),cen-ri2*lev) ph:ApplyForceOffset(-up*-(ang.r-tilt),cen+ri2*lev) - if not (self.spindir==0) then + if spindir ~= 0 then local twist=Vector(0,0,vell/tforce) ph:AddAngleVelocity(twist) end @@ -302,8 +288,8 @@ if SERVER then end elseif name == "Spinmode" and TARDIS:CheckPP(e2.player, self) then local spindir = args[1] - self.spindir = spindir - return self.spindir + self:SetSpinDir(spindir) + return self:GetSpinDir() elseif name == "Track" and TARDIS:CheckPP(e2.player, self) then return 0 -- Not yet implemented end diff --git a/lua/entities/gmod_tardis/modules/sh_vortex.lua b/lua/entities/gmod_tardis/modules/sh_vortex.lua index 7d86c5904..a228693c6 100644 --- a/lua/entities/gmod_tardis/modules/sh_vortex.lua +++ b/lua/entities/gmod_tardis/modules/sh_vortex.lua @@ -56,8 +56,8 @@ if SERVER then elseif TARDIS:IsBindDown(self.pilot,"flight-right") then ph:AddAngleVelocity(Vector(0,0,-rforce)) end - elseif not (self.spindir==0) then - local twist=Vector(0,0,vel*mul*-self.spindir) + elseif not (self:GetSpinDir() == 0) then + local twist=Vector(0, 0, vel * mul * - self:GetSpinDir()) ph:AddAngleVelocity(twist) ph:ApplyForceOffset( up*-ang.p,cen-fwd2*lev) ph:ApplyForceOffset(-up*-ang.p,cen+fwd2*lev) diff --git a/lua/entities/gmod_tardis/modules/sv_spin.lua b/lua/entities/gmod_tardis/modules/sv_spin.lua new file mode 100644 index 000000000..0640590f4 --- /dev/null +++ b/lua/entities/gmod_tardis/modules/sv_spin.lua @@ -0,0 +1,81 @@ +-- Spin + +ENT:AddHook("Initialize", "spin", function(self) + self:SetSpinDir(-1) +end) + +function ENT:ToggleSpin() + local current = self:GetData("spindir", -1) + if current == 0 then + local prev = self:GetData("spindir_old", -1) + self:SetData("spindir", prev) + else + self:SetData("spindir_old", current) + self:SetData("spindir", 0) + end +end + +function ENT:CycleSpinDir() + local current = self:GetData("spindir", -1) + if current == -1 then + self:SetData("spindir", 0) + elseif current == 0 then + self:SetData("spindir", 1) + elseif current == 1 then + self:SetData("spindir", -1) + end +end + +function ENT:SwitchSpinDir() + local current = self:GetData("spindir", -1) + if current == 0 then + local prev = self:GetData("spindir_old", -1) + if prev == -1 then + self:SetData("spindir_old", 1) + elseif prev == 1 then + self:SetData("spindir_old", -1) + end + elseif current == -1 then + self:SetData("spindir", 1) + elseif current == 1 then + self:SetData("spindir", -1) + end +end + +function ENT:GetSpinDir() + return self:GetData("spindir", -1) +end + +function ENT:SetSpinDir(dir) + return self:SetData("spindir", dir) +end + +function ENT:GetSpinDirText(old) + local current = self:GetData("spindir", -1) + if old == true then + current = self:GetData("spindir_old", -1) + end + + if current == -1 then + return "anti-clockwise" + elseif current == 0 then + return "none" + elseif current == 1 then + return "clockwise" + end +end + +ENT:AddHook("ToggleDoor", "spin-dir", function(self,open) + if open and self:GetSpinDir() ~= 0 then + local current = self:GetData("spindir", -1) + self:SetData("spindir_before_door", current) + self:SetData("spindir", 0) + elseif not open and self:GetSpinDir() == 0 then + local prev = self:GetData("spindir_before_door", nil) + TARDIS:Debug(prev) + if prev ~= nil then + self:SetData("spindir_before_door", nil) + self:SetData("spindir", prev) + end + end +end) \ No newline at end of file diff --git a/lua/tardis/controls/sh_control_spin_cycle.lua b/lua/tardis/controls/sh_control_spin_cycle.lua new file mode 100644 index 000000000..64319fd37 --- /dev/null +++ b/lua/tardis/controls/sh_control_spin_cycle.lua @@ -0,0 +1,20 @@ +TARDIS:AddControl({ + id = "spin_cycle", + ext_func=function(self,ply) + self:CycleSpinDir() + TARDIS:Message(ply, "Spin direction set to " .. self:GetSpinDirText()) + end, + serveronly=true, + power_independent = false, + screen_button = { + virt_console = true, + mmenu = false, + toggle = false, + frame_type = {0, 1}, + text = "Spinning", + pressed_state_from_interior = false, + pressed_state_data = nil, + order = 16, + }, + tip_text = "Spin", +}) \ No newline at end of file diff --git a/lua/tardis/controls/sh_control_spin_switch.lua b/lua/tardis/controls/sh_control_spin_switch.lua new file mode 100644 index 000000000..abe35183d --- /dev/null +++ b/lua/tardis/controls/sh_control_spin_switch.lua @@ -0,0 +1,18 @@ +TARDIS:AddControl({ + id = "spin_switch", + ext_func=function(self,ply) + self:SwitchSpinDir() + if self:GetSpinDir() ~= 0 then + TARDIS:Message(ply, "Spin direction set to " .. self:GetSpinDirText()) + else + TARDIS:Message(ply, "Spin is disabled, but spin direction set to " .. self:GetSpinDirText(true)) + end + end, + serveronly=true, + power_independent = false, + screen_button = { + virt_console = false, + mmenu = false, + }, + tip_text = "Spin direction", +}) \ No newline at end of file diff --git a/lua/tardis/controls/sh_control_spin_toggle.lua b/lua/tardis/controls/sh_control_spin_toggle.lua new file mode 100644 index 000000000..2894ebf39 --- /dev/null +++ b/lua/tardis/controls/sh_control_spin_toggle.lua @@ -0,0 +1,17 @@ +TARDIS:AddControl({ + id = "spin_toggle", + ext_func=function(self,ply) + self:ToggleSpin() + if self:GetSpinDir() ~= 0 then + TARDIS:Message(ply, "Spin direction set to " .. self:GetSpinDirText()) + end + TARDIS:StatusMessage(ply, "Spin", (self:GetSpinDir() ~= 0)) + end, + serveronly=true, + power_independent = false, + screen_button = { + virt_console = false, + mmenu = false, + }, + tip_text = "Toggle spin", +}) \ No newline at end of file diff --git a/lua/tardis/interiors/default.lua b/lua/tardis/interiors/default.lua index 3ed40515c..e7e1f60e5 100644 --- a/lua/tardis/interiors/default.lua +++ b/lua/tardis/interiors/default.lua @@ -129,6 +129,7 @@ T.Interior = { default_sonicdispenser = "sonic_dispenser", default_sonic_inserted = SonicModelExists() and "sonic_dispenser", default_helmic = "thirdperson", + default_atomaccel = "spin_cycle", }, diff --git a/lua/tardis/parts/default/default_int_atomaccel.lua b/lua/tardis/parts/default/default_int_atomaccel.lua index 5cb8807cb..fedc95e07 100644 --- a/lua/tardis/parts/default/default_int_atomaccel.lua +++ b/lua/tardis/parts/default/default_int_atomaccel.lua @@ -8,21 +8,4 @@ PART.Model = "models/drmatt/tardis/atomaccel.mdl" PART.AutoSetup = true PART.Collision = true -if SERVER then - function PART:Use(ply) - local dir - if self.exterior.spindir==-1 then - self.exterior.spindir=0 - dir="none" - elseif self.exterior.spindir==0 then - self.exterior.spindir=1 - dir="clockwise" - elseif self.exterior.spindir==1 then - self.exterior.spindir=-1 - dir="anti-clockwise" - end - TARDIS:Message(ply, "Spin direction set to "..dir) - end -end - TARDIS:AddPart(PART) From 88f3f0816c8fbb70e2b550d58c02d0870d6cfc62 Mon Sep 17 00:00:00 2001 From: Artiom Parygin Date: Sat, 4 Dec 2021 10:29:35 +0300 Subject: [PATCH 02/25] Removed debug msg --- lua/entities/gmod_tardis/modules/sv_spin.lua | 1 - 1 file changed, 1 deletion(-) diff --git a/lua/entities/gmod_tardis/modules/sv_spin.lua b/lua/entities/gmod_tardis/modules/sv_spin.lua index 0640590f4..301e5a35a 100644 --- a/lua/entities/gmod_tardis/modules/sv_spin.lua +++ b/lua/entities/gmod_tardis/modules/sv_spin.lua @@ -72,7 +72,6 @@ ENT:AddHook("ToggleDoor", "spin-dir", function(self,open) self:SetData("spindir", 0) elseif not open and self:GetSpinDir() == 0 then local prev = self:GetData("spindir_before_door", nil) - TARDIS:Debug(prev) if prev ~= nil then self:SetData("spindir_before_door", nil) self:SetData("spindir", prev) From d21e85d92827429f6454a4e232e6b3309543ffed Mon Sep 17 00:00:00 2001 From: Artiom Parygin Date: Sun, 5 Dec 2021 19:43:13 +0300 Subject: [PATCH 03/25] Added setting for no spin with doors open --- lua/entities/gmod_tardis/modules/sv_spin.lua | 33 ++++++++++++++------ 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/lua/entities/gmod_tardis/modules/sv_spin.lua b/lua/entities/gmod_tardis/modules/sv_spin.lua index 301e5a35a..0abd1bf7a 100644 --- a/lua/entities/gmod_tardis/modules/sv_spin.lua +++ b/lua/entities/gmod_tardis/modules/sv_spin.lua @@ -65,16 +65,31 @@ function ENT:GetSpinDirText(old) end end + + +TARDIS:AddSetting({ + id="opened-door-no-spin", + name="Stop spinning when opened door", + desc="Should the TARDIS stop spinning when doors are opened in flight?", + section="Misc", + value=false, + type="bool", + option=true, + networked=true +}) + ENT:AddHook("ToggleDoor", "spin-dir", function(self,open) - if open and self:GetSpinDir() ~= 0 then - local current = self:GetData("spindir", -1) - self:SetData("spindir_before_door", current) - self:SetData("spindir", 0) - elseif not open and self:GetSpinDir() == 0 then - local prev = self:GetData("spindir_before_door", nil) - if prev ~= nil then - self:SetData("spindir_before_door", nil) - self:SetData("spindir", prev) + if TARDIS:GetSetting("opened-door-no-spin", false) then + if open and self:GetSpinDir() ~= 0 then + local current = self:GetData("spindir", -1) + self:SetData("spindir_before_door", current) + self:SetData("spindir", 0) + elseif not open and self:GetSpinDir() == 0 then + local prev = self:GetData("spindir_before_door", nil) + if prev ~= nil then + self:SetData("spindir_before_door", nil) + self:SetData("spindir", prev) + end end end end) \ No newline at end of file From 384f016b37b8bcbdecaa22ef7b339c0fb267020d Mon Sep 17 00:00:00 2001 From: Artiom Parygin Date: Sun, 5 Dec 2021 19:43:25 +0300 Subject: [PATCH 04/25] Added flight condition --- lua/entities/gmod_tardis/modules/sv_spin.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/entities/gmod_tardis/modules/sv_spin.lua b/lua/entities/gmod_tardis/modules/sv_spin.lua index 0abd1bf7a..561f836c7 100644 --- a/lua/entities/gmod_tardis/modules/sv_spin.lua +++ b/lua/entities/gmod_tardis/modules/sv_spin.lua @@ -80,7 +80,7 @@ TARDIS:AddSetting({ ENT:AddHook("ToggleDoor", "spin-dir", function(self,open) if TARDIS:GetSetting("opened-door-no-spin", false) then - if open and self:GetSpinDir() ~= 0 then + if open and self:GetData("flight") and self:GetSpinDir() ~= 0 then local current = self:GetData("spindir", -1) self:SetData("spindir_before_door", current) self:SetData("spindir", 0) From 3c71e849f7e40c1b374e9eeea4d394a2ea803a24 Mon Sep 17 00:00:00 2001 From: Artiom Parygin Date: Sun, 5 Dec 2021 20:05:25 +0300 Subject: [PATCH 05/25] Fixed the setting not working --- .../modules/{sv_spin.lua => sh_spin.lua} | 29 ++++++++++--------- 1 file changed, 15 insertions(+), 14 deletions(-) rename lua/entities/gmod_tardis/modules/{sv_spin.lua => sh_spin.lua} (93%) diff --git a/lua/entities/gmod_tardis/modules/sv_spin.lua b/lua/entities/gmod_tardis/modules/sh_spin.lua similarity index 93% rename from lua/entities/gmod_tardis/modules/sv_spin.lua rename to lua/entities/gmod_tardis/modules/sh_spin.lua index 561f836c7..ad7327baa 100644 --- a/lua/entities/gmod_tardis/modules/sv_spin.lua +++ b/lua/entities/gmod_tardis/modules/sh_spin.lua @@ -1,5 +1,19 @@ -- Spin +TARDIS:AddSetting({ + id="opened-door-no-spin", + name="Stop spinning with opened door", + desc="Should the TARDIS stop spinning when doors are opened in flight?", + section="Misc", + value=false, + type="bool", + option=true, + networked=true +}) + +if CLIENT then return end + + ENT:AddHook("Initialize", "spin", function(self) self:SetSpinDir(-1) end) @@ -65,21 +79,8 @@ function ENT:GetSpinDirText(old) end end - - -TARDIS:AddSetting({ - id="opened-door-no-spin", - name="Stop spinning when opened door", - desc="Should the TARDIS stop spinning when doors are opened in flight?", - section="Misc", - value=false, - type="bool", - option=true, - networked=true -}) - ENT:AddHook("ToggleDoor", "spin-dir", function(self,open) - if TARDIS:GetSetting("opened-door-no-spin", false) then + if TARDIS:GetSetting("opened-door-no-spin", false, self:GetCreator()) then if open and self:GetData("flight") and self:GetSpinDir() ~= 0 then local current = self:GetData("spindir", -1) self:SetData("spindir_before_door", current) From 38e05742b498389ffc0701ca98b8c251e382df40 Mon Sep 17 00:00:00 2001 From: Artiom Parygin Date: Sun, 5 Dec 2021 21:00:45 +0300 Subject: [PATCH 06/25] Optional boost changes --- .../gmod_tardis/modules/sh_flight.lua | 90 +++++++++++++------ 1 file changed, 63 insertions(+), 27 deletions(-) diff --git a/lua/entities/gmod_tardis/modules/sh_flight.lua b/lua/entities/gmod_tardis/modules/sh_flight.lua index beb3a15b7..a08bdd8b3 100644 --- a/lua/entities/gmod_tardis/modules/sh_flight.lua +++ b/lua/entities/gmod_tardis/modules/sh_flight.lua @@ -1,5 +1,18 @@ -- Flight +-- Settings + +TARDIS:AddSetting({ + id="opened-door-no-boost", + name="Disable boost with opened doors", + desc="Should the TARDIS boost stop working when doors are opened in flight?", + section="Misc", + value=true, + type="bool", + option=true, + networked=true +}) + -- Binds TARDIS:AddKeyBind("flight-toggle",{ name="Toggle Flight", @@ -87,12 +100,12 @@ TARDIS:AddKeyBind("flight-spindir",{ }) -if SERVER then +if SERVER then function ENT:ToggleFlight() local on = not self:GetData("flight",false) return self:SetFlight(on) end - + function ENT:SetFlight(on) if not on and self:CallHook("CanTurnOffFlight")==false then return false @@ -110,7 +123,7 @@ if SERVER then self:SetFloat(on) return true end - + ENT:AddHook("PowerToggled", "flight", function(self,on) if on and self:GetData("power-lastflight",false)==true then self:SetFlight(true) @@ -125,7 +138,7 @@ if SERVER then return true end end) - + ENT:AddHook("CanTurnOffFloat", "flight", function(self) if self:GetData("flight") then return false end end) @@ -135,7 +148,7 @@ if SERVER then return false end end) - + ENT:AddHook("ThirdPerson", "flight", function(self,ply,enabled) if enabled then if IsValid(self.pilot) then @@ -170,7 +183,7 @@ if SERVER then end end end) - + ENT:AddHook("PilotChanged","flight",function(self,old,new) self:SetData("pilot",new,true) self:SendMessage("PilotChanged",function() @@ -178,17 +191,17 @@ if SERVER then net.WriteEntity(new) end) end) - + ENT:AddHook("Think", "flight", function(self) if self:GetData("flight") then self.phys:Wake() end end) - + ENT:AddHook("PhysicsUpdate", "flight", function(self,ph) if self:GetData("flight") then local phm=FrameTime()*66 - + local up=self:GetUp() local ri2=self:GetRight() local left=ri2*-1 @@ -206,7 +219,9 @@ if SERVER then local tforce=400 local tilt=0 local control=self:CallHook("FlightControl")~=false - + + local spindir = self:GetSpinDir() + if self.pilot and IsValid(self.pilot) and control then local p=self.pilot local eye=p:GetTardisData("viewang") @@ -215,12 +230,34 @@ if SERVER then end local fwd=eye:Forward() local ri=eye:Right() - + if TARDIS:IsBindDown(self.pilot,"flight-boost") then - force=force*2.5 - vforce=vforce*2.5 - rforce=rforce*2.5 - tilt=5 + + local force_mult + local door = self:DoorOpen() + local spin = (spindir ~= 0) + + if door and TARDIS:GetSetting("opened-door-no-boost", true, self:GetCreator()) then + force_mult = 0.25 + local lastmsg = self.bad_flight_boost_msg + if lastmsg == nil or (lastmsg ~= nil and CurTime() - lastmsg > 5.5) then + self.bad_flight_boost_msg = CurTime() + TARDIS:ErrorMessage(self.pilot, "Boost doesn't work with doors open") + end + else + if self.bad_flight_boost_msg ~= nil then + self.bad_flight_boost_msg = nil + end + force_mult = spin and 3 or 2 + end + + tilt = 5 + force = force * force_mult + vforce = vforce * force_mult + rforce = rforce * force_mult + tforce = tforce * force_mult + elseif self.bad_flight_boost_msg ~= nil then + self.bad_flight_boost_msg = nil end if TARDIS:IsBindDown(self.pilot,"flight-forward") then ph:AddVelocity(fwd*force*phm) @@ -246,28 +283,27 @@ if SERVER then tilt=tilt+5 end end - + if TARDIS:IsBindDown(self.pilot,"flight-down") then ph:AddVelocity(-up*vforce*phm) elseif TARDIS:IsBindDown(self.pilot,"flight-up") then ph:AddVelocity(up*vforce*phm) end end - - local spindir = self:GetSpinDir() + if spindir==0 then tilt=0 elseif spindir == 1 then tforce=-tforce end - - ph:ApplyForceOffset( up*-ang.p,cen-fwd2*lev) - ph:ApplyForceOffset(-up*-ang.p,cen+fwd2*lev) - ph:ApplyForceOffset( up*-(ang.r-tilt),cen-ri2*lev) - ph:ApplyForceOffset(-up*-(ang.r-tilt),cen+ri2*lev) - + + ph:ApplyForceOffset( up * -ang.p, cen - fwd2 * lev) + ph:ApplyForceOffset(-up * -ang.p, cen + fwd2 * lev) + ph:ApplyForceOffset( up * -(ang.r - tilt), cen - ri2 * lev) + ph:ApplyForceOffset(-up * -(ang.r - tilt), cen + ri2 * lev) + if spindir ~= 0 then - local twist=Vector(0,0,vell/tforce) + local twist = Vector(0, 0, vell / tforce) ph:AddAngleVelocity(twist) end local angbrake=angvel*-0.015 @@ -314,14 +350,14 @@ else type="bool", option=true }) - + ENT:AddHook("OnRemove", "flight", function(self) if self.flightsound then self.flightsound:Stop() self.flightsound=nil end end) - + local function ChooseFlightSound(ent) if ent:GetData("health-warning", false) then ent.flightsound = CreateSound(ent, ent.metadata.Exterior.Sounds.FlightLoopDamaged) From a60fa3ea3ab3ea9ae3a6dba54ec0e03a2be4910c Mon Sep 17 00:00:00 2001 From: Artiom Parygin Date: Sun, 5 Dec 2021 21:18:04 +0300 Subject: [PATCH 07/25] Added tilt to the direction of flight --- lua/entities/gmod_tardis/modules/sh_flight.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lua/entities/gmod_tardis/modules/sh_flight.lua b/lua/entities/gmod_tardis/modules/sh_flight.lua index a08bdd8b3..ca060a491 100644 --- a/lua/entities/gmod_tardis/modules/sh_flight.lua +++ b/lua/entities/gmod_tardis/modules/sh_flight.lua @@ -297,6 +297,8 @@ if SERVER then tforce=-tforce end + ph:ApplyForceOffset( vel * 0.005, cen + up * lev) + ph:ApplyForceOffset(-vel * 0.005, cen - up * lev) ph:ApplyForceOffset( up * -ang.p, cen - fwd2 * lev) ph:ApplyForceOffset(-up * -ang.p, cen + fwd2 * lev) ph:ApplyForceOffset( up * -(ang.r - tilt), cen - ri2 * lev) From 6b355b3c76e018ce7eb5a131fa212ec9aa118f6a Mon Sep 17 00:00:00 2001 From: Artiom Parygin Date: Sun, 5 Dec 2021 21:24:57 +0300 Subject: [PATCH 08/25] Control placeholders and name fix --- lua/tardis/controls/sh_control_interior_lights.lua | 13 +++++++++++++ lua/tardis/controls/sh_control_shields.lua | 13 +++++++++++++ lua/tardis/controls/sh_control_spin_cycle.lua | 2 +- lua/tardis/controls/sh_control_stabilizers.lua | 13 +++++++++++++ 4 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 lua/tardis/controls/sh_control_interior_lights.lua create mode 100644 lua/tardis/controls/sh_control_shields.lua create mode 100644 lua/tardis/controls/sh_control_stabilizers.lua diff --git a/lua/tardis/controls/sh_control_interior_lights.lua b/lua/tardis/controls/sh_control_interior_lights.lua new file mode 100644 index 000000000..254fc0970 --- /dev/null +++ b/lua/tardis/controls/sh_control_interior_lights.lua @@ -0,0 +1,13 @@ +TARDIS:AddControl({ + id = "interior_lights", + ext_func=function(self,ply) + TARDIS:Message(ply, "This hasn't been implemented yet.") + end, + clientonly=true, + power_independent = false, + screen_button = { + virt_console = false, + mmenu = false, + }, + tip_text = "Lights", +}) \ No newline at end of file diff --git a/lua/tardis/controls/sh_control_shields.lua b/lua/tardis/controls/sh_control_shields.lua new file mode 100644 index 000000000..57e74cf2f --- /dev/null +++ b/lua/tardis/controls/sh_control_shields.lua @@ -0,0 +1,13 @@ +TARDIS:AddControl({ + id = "shields", + ext_func=function(self,ply) + TARDIS:Message(ply, "This hasn't been implemented yet.") + end, + clientonly=true, + power_independent = false, + screen_button = { + virt_console = false, + mmenu = false, + }, + tip_text = "Shields", +}) \ No newline at end of file diff --git a/lua/tardis/controls/sh_control_spin_cycle.lua b/lua/tardis/controls/sh_control_spin_cycle.lua index 64319fd37..5bdcf4eaa 100644 --- a/lua/tardis/controls/sh_control_spin_cycle.lua +++ b/lua/tardis/controls/sh_control_spin_cycle.lua @@ -11,7 +11,7 @@ TARDIS:AddControl({ mmenu = false, toggle = false, frame_type = {0, 1}, - text = "Spinning", + text = "Spin direction", pressed_state_from_interior = false, pressed_state_data = nil, order = 16, diff --git a/lua/tardis/controls/sh_control_stabilizers.lua b/lua/tardis/controls/sh_control_stabilizers.lua new file mode 100644 index 000000000..d7af0771b --- /dev/null +++ b/lua/tardis/controls/sh_control_stabilizers.lua @@ -0,0 +1,13 @@ +TARDIS:AddControl({ + id = "stabilizers", + ext_func=function(self,ply) + TARDIS:Message(ply, "This hasn't been implemented yet.") + end, + clientonly=true, + power_independent = false, + screen_button = { + virt_console = false, + mmenu = false, + }, + tip_text = "Flight stabilizers", +}) \ No newline at end of file From 93d733a84a13d343045e64ad7151e639089e4759 Mon Sep 17 00:00:00 2001 From: Artiom Parygin Date: Sun, 5 Dec 2021 21:35:27 +0300 Subject: [PATCH 09/25] Changed control name and message order --- .../controls/sh_control_vortexflight.lua | 2 +- lua/tardis/libraries/sh_messages.lua | 21 +++++++------------ 2 files changed, 9 insertions(+), 14 deletions(-) diff --git a/lua/tardis/controls/sh_control_vortexflight.lua b/lua/tardis/controls/sh_control_vortexflight.lua index fe314d860..ea1c492c9 100644 --- a/lua/tardis/controls/sh_control_vortexflight.lua +++ b/lua/tardis/controls/sh_control_vortexflight.lua @@ -18,5 +18,5 @@ TARDIS:AddControl({ id = "vortex_flight", pressed_state_data = "demat-fast", order = 8, }, - tip_text = "Vortex Flight Toggler", + tip_text = "Vortex Flight", }) \ No newline at end of file diff --git a/lua/tardis/libraries/sh_messages.lua b/lua/tardis/libraries/sh_messages.lua index 24e532931..2bc0224e3 100644 --- a/lua/tardis/libraries/sh_messages.lua +++ b/lua/tardis/libraries/sh_messages.lua @@ -61,24 +61,19 @@ function TARDIS:Message(ply, message, error) return end local style = self.msg_style - local fullmessage = "[TARDIS] "..message + + local prefix = "[TARDIS] " + local err = error and "ERROR: " or "" + if style == 0 then return end if style == 1 then - if error then - print("ERROR: "..fullmessage) - else - print(fullmessage) - end + print(prefix .. err .. message) return end if style == 2 then - if error then - LocalPlayer():ChatPrint("ERROR: "..fullmessage) - else - LocalPlayer():ChatPrint(fullmessage) - end + LocalPlayer():ChatPrint(prefix .. err .. message) return end if style == 3 then @@ -88,8 +83,8 @@ function TARDIS:Message(ply, message, error) else notifyType = NOTIFY_GENERIC end - notification.AddLegacy(fullmessage, notifyType, 5) - print(fullmessage) + notification.AddLegacy(prefix .. message, notifyType, 5) + print(prefix .. err .. message) return end end From 2c4c8d7bb801c844f2fdd9d2d89c29231dded52c Mon Sep 17 00:00:00 2001 From: Artiom Parygin Date: Sun, 5 Dec 2021 21:41:42 +0300 Subject: [PATCH 10/25] Renamed for consistency --- .../{sh_control_vortexflight.lua => sh_control_vortex_flight.lua} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename lua/tardis/controls/{sh_control_vortexflight.lua => sh_control_vortex_flight.lua} (100%) diff --git a/lua/tardis/controls/sh_control_vortexflight.lua b/lua/tardis/controls/sh_control_vortex_flight.lua similarity index 100% rename from lua/tardis/controls/sh_control_vortexflight.lua rename to lua/tardis/controls/sh_control_vortex_flight.lua From d880c75feeb673a61853daf12dfa06666a9c9a36 Mon Sep 17 00:00:00 2001 From: Artiom Parygin Date: Tue, 7 Dec 2021 07:46:51 +0300 Subject: [PATCH 11/25] SoundPos and UseBasic support --- lua/tardis/sh_parts.lua | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/lua/tardis/sh_parts.lua b/lua/tardis/sh_parts.lua index ed24ce4d4..7519d98c3 100644 --- a/lua/tardis/sh_parts.lua +++ b/lua/tardis/sh_parts.lua @@ -72,6 +72,9 @@ local overrides={ TARDIS:ErrorMessage(a, "Power is disabled. This control is blocked.") else if allowed~=false then + if self.HasUseBasic then + self.UseBasic(self,a,...) + end if SERVER and self.Control and (not self.HasUse) then TARDIS:Control(self.Control,a) else @@ -83,12 +86,20 @@ local overrides={ local on = self:GetOn() if self.PowerOffSound ~= false or self.interior:GetPower() then + local part_sound = nil + if self.SoundOff and on then - self:EmitSound(self.SoundOff) + part_sound = self.SoundOff elseif self.SoundOn and (not on) then - self:EmitSound(self.SoundOn) + part_sound = self.SoundOn elseif self.Sound then - self:EmitSound(self.Sound) + part_sound = self.Sound + end + + if part_sound and self.SoundPos then + sound.Play(part_sound, self:LocalToWorld(self.SoundPos)) + elseif part_sound then + self:EmitSound(part_sound) end end self:SetOn(not on) @@ -134,6 +145,7 @@ function TARDIS:AddPart(e) error("Duplicate part ID registered: " .. e.ID .. " (exists in both " .. parts[e.ID].source .. " and " .. source .. ")") end e=table.Copy(e) + e.HasUseBasic = e.UseBasic ~= nil e.HasUse = e.Use ~= nil e.Base = "gmod_tardis_part" local class="gmod_tardis_part_"..e.ID From 41717e4c22e29e4840c39bb11cc00c503e61b782 Mon Sep 17 00:00:00 2001 From: Artiom Parygin Date: Tue, 7 Dec 2021 15:40:08 +0300 Subject: [PATCH 12/25] Fixed spin toggle logic --- lua/entities/gmod_tardis/modules/sh_spin.lua | 62 ++++++++------------ 1 file changed, 25 insertions(+), 37 deletions(-) diff --git a/lua/entities/gmod_tardis/modules/sh_spin.lua b/lua/entities/gmod_tardis/modules/sh_spin.lua index ad7327baa..70e2237a3 100644 --- a/lua/entities/gmod_tardis/modules/sh_spin.lua +++ b/lua/entities/gmod_tardis/modules/sh_spin.lua @@ -15,45 +15,32 @@ if CLIENT then return end ENT:AddHook("Initialize", "spin", function(self) - self:SetSpinDir(-1) + self:SetData("spindir", -1) + self:SetData("spindir_prev", 0) end) function ENT:ToggleSpin() local current = self:GetData("spindir", -1) - if current == 0 then - local prev = self:GetData("spindir_old", -1) - self:SetData("spindir", prev) - else - self:SetData("spindir_old", current) - self:SetData("spindir", 0) - end + local prev = self:GetData("spindir_prev", 0) + + self:SetData("spindir_prev", current) + self:SetData("spindir", prev) end function ENT:CycleSpinDir() local current = self:GetData("spindir", -1) - if current == -1 then - self:SetData("spindir", 0) - elseif current == 0 then - self:SetData("spindir", 1) - elseif current == 1 then - self:SetData("spindir", -1) - end + local prev = self:GetData("spindir_prev", 0) + + self:SetData("spindir_prev", current) + self:SetData("spindir", -prev) end function ENT:SwitchSpinDir() local current = self:GetData("spindir", -1) - if current == 0 then - local prev = self:GetData("spindir_old", -1) - if prev == -1 then - self:SetData("spindir_old", 1) - elseif prev == 1 then - self:SetData("spindir_old", -1) - end - elseif current == -1 then - self:SetData("spindir", 1) - elseif current == 1 then - self:SetData("spindir", -1) - end + local prev = self:GetData("spindir_prev", 0) + + self:SetData("spindir_prev", -prev) + self:SetData("spindir", -current) end function ENT:GetSpinDir() @@ -64,10 +51,10 @@ function ENT:SetSpinDir(dir) return self:SetData("spindir", dir) end -function ENT:GetSpinDirText(old) +function ENT:GetSpinDirText(show_next) local current = self:GetData("spindir", -1) - if old == true then - current = self:GetData("spindir_old", -1) + if show_next == true then + current = self:GetData("spindir_prev", 0) end if current == -1 then @@ -81,16 +68,17 @@ end ENT:AddHook("ToggleDoor", "spin-dir", function(self,open) if TARDIS:GetSetting("opened-door-no-spin", false, self:GetCreator()) then + local current = self:GetData("spindir", -1) + local before = self:GetData("spindir_before_door", nil) + if open and self:GetData("flight") and self:GetSpinDir() ~= 0 then - local current = self:GetData("spindir", -1) self:SetData("spindir_before_door", current) + self:SetData("spindir_prev", current) self:SetData("spindir", 0) - elseif not open and self:GetSpinDir() == 0 then - local prev = self:GetData("spindir_before_door", nil) - if prev ~= nil then - self:SetData("spindir_before_door", nil) - self:SetData("spindir", prev) - end + elseif not open and self:GetSpinDir() == 0 and before ~= nil then + self:SetData("spindir_before_door", nil) + self:SetData("spindir_prev", current) + self:SetData("spindir", before) end end end) \ No newline at end of file From 7f4c10e5e7f0c32998d116c25b370e7987eea082 Mon Sep 17 00:00:00 2001 From: Artiom Parygin Date: Tue, 7 Dec 2021 15:55:35 +0300 Subject: [PATCH 13/25] Improved tilt --- lua/entities/gmod_tardis/modules/sh_flight.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/entities/gmod_tardis/modules/sh_flight.lua b/lua/entities/gmod_tardis/modules/sh_flight.lua index ca060a491..b15d4e880 100644 --- a/lua/entities/gmod_tardis/modules/sh_flight.lua +++ b/lua/entities/gmod_tardis/modules/sh_flight.lua @@ -251,7 +251,7 @@ if SERVER then force_mult = spin and 3 or 2 end - tilt = 5 + tilt = 3 force = force * force_mult vforce = vforce * force_mult rforce = rforce * force_mult From 85d5f07f1ce61589ddb3732116aef20167df7730 Mon Sep 17 00:00:00 2001 From: Artiom Parygin Date: Tue, 7 Dec 2021 23:11:12 +0300 Subject: [PATCH 14/25] Default interior controls --- lua/tardis/interiors/default.lua | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lua/tardis/interiors/default.lua b/lua/tardis/interiors/default.lua index e7e1f60e5..120934882 100644 --- a/lua/tardis/interiors/default.lua +++ b/lua/tardis/interiors/default.lua @@ -120,8 +120,6 @@ T.Interior = { default_biglever = "fastreturn", default_physlock = "physlock", default_isomorphic = "isomorphic", - default_atomaccel = nil, - default_directionalpointer = nil, default_float = "float", default_blacksticks = "cloak", default_longflighttoggle = "vortex_flight", @@ -129,7 +127,8 @@ T.Interior = { default_sonicdispenser = "sonic_dispenser", default_sonic_inserted = SonicModelExists() and "sonic_dispenser", default_helmic = "thirdperson", - default_atomaccel = "spin_cycle", + default_atomaccel = "spin_toggle", + default_directionalpointer = "spin_switch", }, From 08603a9dc4e09a4855ec3ebb40505c7d25884470 Mon Sep 17 00:00:00 2001 From: Artiom Parygin Date: Tue, 7 Dec 2021 23:12:00 +0300 Subject: [PATCH 15/25] Stop spinning with opened doors by default --- lua/entities/gmod_tardis/modules/sh_spin.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/entities/gmod_tardis/modules/sh_spin.lua b/lua/entities/gmod_tardis/modules/sh_spin.lua index 70e2237a3..47543e43d 100644 --- a/lua/entities/gmod_tardis/modules/sh_spin.lua +++ b/lua/entities/gmod_tardis/modules/sh_spin.lua @@ -5,7 +5,7 @@ TARDIS:AddSetting({ name="Stop spinning with opened door", desc="Should the TARDIS stop spinning when doors are opened in flight?", section="Misc", - value=false, + value=true, type="bool", option=true, networked=true From 3f514df905b41c2280e92840f8edca84ae5f7e13 Mon Sep 17 00:00:00 2001 From: Artiom Parygin Date: Tue, 7 Dec 2021 23:27:28 +0300 Subject: [PATCH 16/25] Improved the opened-doors-boost behaviour --- lua/entities/gmod_tardis/modules/sh_flight.lua | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lua/entities/gmod_tardis/modules/sh_flight.lua b/lua/entities/gmod_tardis/modules/sh_flight.lua index b15d4e880..5e6339697 100644 --- a/lua/entities/gmod_tardis/modules/sh_flight.lua +++ b/lua/entities/gmod_tardis/modules/sh_flight.lua @@ -221,6 +221,7 @@ if SERVER then local control=self:CallHook("FlightControl")~=false local spindir = self:GetSpinDir() + local brakes = false if self.pilot and IsValid(self.pilot) and control then local p=self.pilot @@ -239,6 +240,7 @@ if SERVER then if door and TARDIS:GetSetting("opened-door-no-boost", true, self:GetCreator()) then force_mult = 0.25 + brakes = true local lastmsg = self.bad_flight_boost_msg if lastmsg == nil or (lastmsg ~= nil and CurTime() - lastmsg > 5.5) then self.bad_flight_boost_msg = CurTime() @@ -255,7 +257,7 @@ if SERVER then force = force * force_mult vforce = vforce * force_mult rforce = rforce * force_mult - tforce = tforce * force_mult + tforce = tforce * math.max(force_mult, 2) -- avoid increased spinning elseif self.bad_flight_boost_msg ~= nil then self.bad_flight_boost_msg = nil end @@ -291,7 +293,7 @@ if SERVER then end end - if spindir==0 then + if spindir==0 or brakes then tilt=0 elseif spindir == 1 then tforce=-tforce From 2b29aa694bbac1f4ce8c6f14b879468818278f2c Mon Sep 17 00:00:00 2001 From: Artiom Parygin Date: Thu, 9 Dec 2021 08:05:00 +0300 Subject: [PATCH 17/25] Made no boost with opened door off by default --- lua/entities/gmod_tardis/modules/sh_flight.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/entities/gmod_tardis/modules/sh_flight.lua b/lua/entities/gmod_tardis/modules/sh_flight.lua index 5e6339697..24ca55e80 100644 --- a/lua/entities/gmod_tardis/modules/sh_flight.lua +++ b/lua/entities/gmod_tardis/modules/sh_flight.lua @@ -7,7 +7,7 @@ TARDIS:AddSetting({ name="Disable boost with opened doors", desc="Should the TARDIS boost stop working when doors are opened in flight?", section="Misc", - value=true, + value=false, type="bool", option=true, networked=true From 51203363b61dfc8b675ce4306e849bfa0119c86f Mon Sep 17 00:00:00 2001 From: Artiom Parygin Date: Fri, 10 Dec 2021 13:55:53 +0300 Subject: [PATCH 18/25] SetCollide() function --- lua/entities/gmod_tardis_part/init.lua | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lua/entities/gmod_tardis_part/init.lua b/lua/entities/gmod_tardis_part/init.lua index 16128f95e..91576b76c 100644 --- a/lua/entities/gmod_tardis_part/init.lua +++ b/lua/entities/gmod_tardis_part/init.lua @@ -6,4 +6,14 @@ function ENT:OnTakeDamage(dmginfo) if not self.ShouldTakeDamage then return end if self.parent:CallHook("ShouldTakeDamage",dmginfo)==false then return end self.parent:CallHook("OnTakeDamage", dmginfo) +end + +function ENT:SetCollide(collide, notrace) + if collide then + self:SetCollisionGroup(COLLISION_GROUP_NONE) + elseif notrace then + self:SetCollisionGroup(COLLISION_GROUP_IN_VEHICLE) + else + self:SetCollisionGroup(COLLISION_GROUP_WORLD) + end end \ No newline at end of file From 12215088ce595ed71e74b4e6a35ebe582bd7e6f2 Mon Sep 17 00:00:00 2001 From: Artiom Parygin Date: Fri, 10 Dec 2021 19:51:27 +0300 Subject: [PATCH 19/25] ScreensToggled() Hook --- .../gmod_tardis_interior/modules/sh_interior_screens.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/lua/entities/gmod_tardis_interior/modules/sh_interior_screens.lua b/lua/entities/gmod_tardis_interior/modules/sh_interior_screens.lua index d90dcaa41..1d9dc2f23 100644 --- a/lua/entities/gmod_tardis_interior/modules/sh_interior_screens.lua +++ b/lua/entities/gmod_tardis_interior/modules/sh_interior_screens.lua @@ -24,6 +24,7 @@ end function ENT:SetScreensOn(on) if not on or self:CallHook("CanEnableScreens") ~= false then self:SetData("screens_on", on, true) + self:CallHook("ScreensToggled", on) end return true end From 5758013fb27d2713413340b50fbb0aa8eeb71e08 Mon Sep 17 00:00:00 2001 From: Artiom Parygin Date: Fri, 10 Dec 2021 22:47:50 +0300 Subject: [PATCH 20/25] Forbade some door-related actions with no power --- lua/tardis/controls/sh_control_door.lua | 16 ++++++++++++++++ lua/tardis/controls/sh_control_doorlock.lua | 9 +++++++++ 2 files changed, 25 insertions(+) diff --git a/lua/tardis/controls/sh_control_door.lua b/lua/tardis/controls/sh_control_door.lua index 55fb44d2f..50fb1896b 100644 --- a/lua/tardis/controls/sh_control_door.lua +++ b/lua/tardis/controls/sh_control_door.lua @@ -2,6 +2,22 @@ TARDIS:AddControl({ id = "door", ext_func=function(self,ply) local oldstate = self:GetData("doorstate") + + if self:GetData("locked", false) then + TARDIS:ErrorMessage(ply, "The doors are locked.") + return + end + + if not self:GetPower() then + if not self.metadata.EnableClassicDoors or oldstate then + TARDIS:ErrorMessage(ply, "The door switch doesn't work.") + TARDIS:ErrorMessage(ply, "Power is disabled.") + return + end + TARDIS:Message(ply, "Using emergency power to open the door...") + TARDIS:ErrorMessage(ply, "Power is disabled.") + end + if self:ToggleDoor() then TARDIS:StatusMessage(ply, "Door", not oldstate, "opened", "closed") else diff --git a/lua/tardis/controls/sh_control_doorlock.lua b/lua/tardis/controls/sh_control_doorlock.lua index 6f6ad1505..015311413 100644 --- a/lua/tardis/controls/sh_control_doorlock.lua +++ b/lua/tardis/controls/sh_control_doorlock.lua @@ -1,6 +1,15 @@ TARDIS:AddControl({ id = "doorlock", ext_func=function(self,ply) + if not self:GetPower() and not self:GetData("locked", false) then + TARDIS:ErrorMessage(ply, "The door lock doesn't work.") + TARDIS:ErrorMessage(ply, "Power is disabled.") + return + elseif not self:GetPower() then + TARDIS:Message(ply, "Using emergency power to disengage the lock...") + TARDIS:ErrorMessage(ply, "Power is disabled.") + end + self:ToggleLocked(function(result) if result then TARDIS:StatusMessage(ply, "Door", self:GetData("locked"), "locked", "unlocked") From 140d9c43320d00bcb9618c831b96c86f95692c97 Mon Sep 17 00:00:00 2001 From: Matt Jeanes Date: Tue, 14 Dec 2021 11:06:31 +0000 Subject: [PATCH 21/25] some fixes to flight control - normal flight mechanics when opened-door-no-boost option is disabled - fixed spin being reversed when boosting with doors open when opened-door-no-boost option is enabled - always set spin direction when toggling door state regardless of in flight mode --- lua/entities/gmod_tardis/modules/sh_flight.lua | 16 +++++++++++----- lua/entities/gmod_tardis/modules/sh_spin.lua | 2 +- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/lua/entities/gmod_tardis/modules/sh_flight.lua b/lua/entities/gmod_tardis/modules/sh_flight.lua index 24ca55e80..5b1714e5d 100644 --- a/lua/entities/gmod_tardis/modules/sh_flight.lua +++ b/lua/entities/gmod_tardis/modules/sh_flight.lua @@ -247,17 +247,16 @@ if SERVER then TARDIS:ErrorMessage(self.pilot, "Boost doesn't work with doors open") end else + force_mult = 2.5 if self.bad_flight_boost_msg ~= nil then self.bad_flight_boost_msg = nil end - force_mult = spin and 3 or 2 end - tilt = 3 force = force * force_mult vforce = vforce * force_mult rforce = rforce * force_mult - tforce = tforce * math.max(force_mult, 2) -- avoid increased spinning + tilt = 5 elseif self.bad_flight_boost_msg ~= nil then self.bad_flight_boost_msg = nil end @@ -293,16 +292,23 @@ if SERVER then end end - if spindir==0 or brakes then + if spindir == 0 or brakes then tilt=0 - elseif spindir == 1 then + end + + if spindir == 1 then tforce=-tforce end + -- lean into the flight ph:ApplyForceOffset( vel * 0.005, cen + up * lev) ph:ApplyForceOffset(-vel * 0.005, cen - up * lev) + + -- stabilise pitch ph:ApplyForceOffset( up * -ang.p, cen - fwd2 * lev) ph:ApplyForceOffset(-up * -ang.p, cen + fwd2 * lev) + + -- stabilise roll and apply tilt ph:ApplyForceOffset( up * -(ang.r - tilt), cen - ri2 * lev) ph:ApplyForceOffset(-up * -(ang.r - tilt), cen + ri2 * lev) diff --git a/lua/entities/gmod_tardis/modules/sh_spin.lua b/lua/entities/gmod_tardis/modules/sh_spin.lua index 47543e43d..5038fbf11 100644 --- a/lua/entities/gmod_tardis/modules/sh_spin.lua +++ b/lua/entities/gmod_tardis/modules/sh_spin.lua @@ -71,7 +71,7 @@ ENT:AddHook("ToggleDoor", "spin-dir", function(self,open) local current = self:GetData("spindir", -1) local before = self:GetData("spindir_before_door", nil) - if open and self:GetData("flight") and self:GetSpinDir() ~= 0 then + if open and self:GetSpinDir() ~= 0 then self:SetData("spindir_before_door", current) self:SetData("spindir_prev", current) self:SetData("spindir", 0) From 269dd00fc8d8a2c77831ef67af6ad2cc2cd3ad10 Mon Sep 17 00:00:00 2001 From: Matt Jeanes Date: Tue, 14 Dec 2021 11:27:50 +0000 Subject: [PATCH 22/25] Decrease boost speed when doors are open slightly --- lua/entities/gmod_tardis/modules/sh_flight.lua | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lua/entities/gmod_tardis/modules/sh_flight.lua b/lua/entities/gmod_tardis/modules/sh_flight.lua index 5b1714e5d..b7f4946b9 100644 --- a/lua/entities/gmod_tardis/modules/sh_flight.lua +++ b/lua/entities/gmod_tardis/modules/sh_flight.lua @@ -247,7 +247,7 @@ if SERVER then TARDIS:ErrorMessage(self.pilot, "Boost doesn't work with doors open") end else - force_mult = 2.5 + force_mult = spin and 2.5 or 1.75 if self.bad_flight_boost_msg ~= nil then self.bad_flight_boost_msg = nil end @@ -295,7 +295,7 @@ if SERVER then if spindir == 0 or brakes then tilt=0 end - + if spindir == 1 then tforce=-tforce end From c3266dac9efda07282f312e4c14c0ab251c22465 Mon Sep 17 00:00:00 2001 From: Artiom Parygin Date: Tue, 14 Dec 2021 16:56:28 +0300 Subject: [PATCH 23/25] Another attempt to fix flight behaviour --- .../gmod_tardis/modules/sh_flight.lua | 55 ++++++++++++++----- 1 file changed, 42 insertions(+), 13 deletions(-) diff --git a/lua/entities/gmod_tardis/modules/sh_flight.lua b/lua/entities/gmod_tardis/modules/sh_flight.lua index b7f4946b9..e9e6aa7e5 100644 --- a/lua/entities/gmod_tardis/modules/sh_flight.lua +++ b/lua/entities/gmod_tardis/modules/sh_flight.lua @@ -7,12 +7,37 @@ TARDIS:AddSetting({ name="Disable boost with opened doors", desc="Should the TARDIS boost stop working when doors are opened in flight?", section="Misc", - value=false, + value=true, type="bool", option=true, networked=true }) +TARDIS:AddSetting({ + id="boost-speed", + name="Boost Speed", + desc="The increase of speed the TARDIS gets with the boost key enabled", + section="Misc", + type="number", + value=2.5, + min=1.0, + max=4.0, + networked=true +}) + +CreateConVar("tardis2_boost_speed", 2.5, {FCVAR_ARCHIVE, FCVAR_REPLICATED}, "TARDIS - Boost Speed") + +if SERVER then + cvars.AddChangeCallback("tardis2_boost_speed", function(cvname, oldvalue, newvalue) + local nvnum = tonumber(newvalue) + if nvnum < 1.0 or nvnum > 4.0 then + nvnum = math.max(1.0, math.min(4.0, nvnum)) + GetConVar("tardis2_boost_speed"):SetFloat(nvnum) + end + TARDIS:SetSetting("boost-speed", nvnum, true) + end, "UpdateOnChange") +end + -- Binds TARDIS:AddKeyBind("flight-toggle",{ name="Toggle Flight", @@ -216,11 +241,12 @@ if SERVER then local force=15 local vforce=5 local rforce=2 - local tforce=400 + local tforce=200 local tilt=0 local control=self:CallHook("FlightControl")~=false local spindir = self:GetSpinDir() + local spin = (spindir ~= 0) local brakes = false if self.pilot and IsValid(self.pilot) and control then @@ -236,27 +262,31 @@ if SERVER then local force_mult local door = self:DoorOpen() - local spin = (spindir ~= 0) if door and TARDIS:GetSetting("opened-door-no-boost", true, self:GetCreator()) then force_mult = 0.25 - brakes = true + brakes = true -- no spin, no tilt local lastmsg = self.bad_flight_boost_msg if lastmsg == nil or (lastmsg ~= nil and CurTime() - lastmsg > 5.5) then self.bad_flight_boost_msg = CurTime() TARDIS:ErrorMessage(self.pilot, "Boost doesn't work with doors open") end else - force_mult = spin and 2.5 or 1.75 if self.bad_flight_boost_msg ~= nil then self.bad_flight_boost_msg = nil end + force_mult = TARDIS:GetSetting("boost-speed") + if not spin then + force_mult = math.max(1, force_mult * 0.6) -- from 2.5 to 1.5 + end end force = force * force_mult vforce = vforce * force_mult rforce = rforce * force_mult - tilt = 5 + tilt = -4 -- has to be less to work together with tilt towards the speed direction + -- when moving with boost, -4 compensates +5 to make less tilt towards the sides + -- when not moving, and adds a small tilt to the side elseif self.bad_flight_boost_msg ~= nil then self.bad_flight_boost_msg = nil end @@ -292,13 +322,10 @@ if SERVER then end end - if spindir == 0 or brakes then - tilt=0 + if not spin or brakes then + tilt = 0 end - if spindir == 1 then - tforce=-tforce - end -- lean into the flight ph:ApplyForceOffset( vel * 0.005, cen + up * lev) @@ -312,8 +339,10 @@ if SERVER then ph:ApplyForceOffset( up * -(ang.r - tilt), cen - ri2 * lev) ph:ApplyForceOffset(-up * -(ang.r - tilt), cen + ri2 * lev) - if spindir ~= 0 then - local twist = Vector(0, 0, vell / tforce) + if spin and not brakes then + local twist = Vector(0, 0, -spindir * (0.008 + math.sqrt(vell / tforce))) + -- 0.008 adds an almost unnoticable rotation while staying at one point + -- adds some difference between flying and anti-gravs ph:AddAngleVelocity(twist) end local angbrake=angvel*-0.015 From 86088c582023de502b504eedf720aa6a9129b932 Mon Sep 17 00:00:00 2001 From: Artiom Parygin Date: Tue, 14 Dec 2021 17:00:12 +0300 Subject: [PATCH 24/25] Message for setting change --- lua/entities/gmod_tardis/modules/sh_flight.lua | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lua/entities/gmod_tardis/modules/sh_flight.lua b/lua/entities/gmod_tardis/modules/sh_flight.lua index e9e6aa7e5..4e422469d 100644 --- a/lua/entities/gmod_tardis/modules/sh_flight.lua +++ b/lua/entities/gmod_tardis/modules/sh_flight.lua @@ -33,7 +33,9 @@ if SERVER then if nvnum < 1.0 or nvnum > 4.0 then nvnum = math.max(1.0, math.min(4.0, nvnum)) GetConVar("tardis2_boost_speed"):SetFloat(nvnum) + return end + print("TARDIS boost speed has been set to "..nvnum) TARDIS:SetSetting("boost-speed", nvnum, true) end, "UpdateOnChange") end From 910d2456bbcebd88735ed8c3d9a44e6f3ad0f490 Mon Sep 17 00:00:00 2001 From: Matt Jeanes Date: Tue, 14 Dec 2021 14:18:25 +0000 Subject: [PATCH 25/25] adjusted tilt forces, removed small rotation while still and set opened-door-no-boost default back to false --- lua/entities/gmod_tardis/modules/sh_flight.lua | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/lua/entities/gmod_tardis/modules/sh_flight.lua b/lua/entities/gmod_tardis/modules/sh_flight.lua index 4e422469d..9a67b3247 100644 --- a/lua/entities/gmod_tardis/modules/sh_flight.lua +++ b/lua/entities/gmod_tardis/modules/sh_flight.lua @@ -7,7 +7,7 @@ TARDIS:AddSetting({ name="Disable boost with opened doors", desc="Should the TARDIS boost stop working when doors are opened in flight?", section="Misc", - value=true, + value=false, type="bool", option=true, networked=true @@ -279,16 +279,13 @@ if SERVER then end force_mult = TARDIS:GetSetting("boost-speed") if not spin then - force_mult = math.max(1, force_mult * 0.6) -- from 2.5 to 1.5 + force_mult = math.max(1, force_mult * 0.6) end end force = force * force_mult vforce = vforce * force_mult rforce = rforce * force_mult - tilt = -4 -- has to be less to work together with tilt towards the speed direction - -- when moving with boost, -4 compensates +5 to make less tilt towards the sides - -- when not moving, and adds a small tilt to the side elseif self.bad_flight_boost_msg ~= nil then self.bad_flight_boost_msg = nil end @@ -342,9 +339,7 @@ if SERVER then ph:ApplyForceOffset(-up * -(ang.r - tilt), cen + ri2 * lev) if spin and not brakes then - local twist = Vector(0, 0, -spindir * (0.008 + math.sqrt(vell / tforce))) - -- 0.008 adds an almost unnoticable rotation while staying at one point - -- adds some difference between flying and anti-gravs + local twist = Vector(0, 0, -spindir * math.sqrt(vell / tforce)) ph:AddAngleVelocity(twist) end local angbrake=angvel*-0.015