diff --git a/lua/entities/gmod_tardis/modules/sh_flight.lua b/lua/entities/gmod_tardis/modules/sh_flight.lua index 4c52c07ab..9a67b3247 100644 --- a/lua/entities/gmod_tardis/modules/sh_flight.lua +++ b/lua/entities/gmod_tardis/modules/sh_flight.lua @@ -1,5 +1,45 @@ -- 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=false, + 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) + return + end + print("TARDIS boost speed has been set to "..nvnum) + TARDIS:SetSetting("boost-speed", nvnum, true) + end, "UpdateOnChange") +end + -- Binds TARDIS:AddKeyBind("flight-toggle",{ name="Toggle Flight", @@ -78,18 +118,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, @@ -98,12 +127,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 @@ -121,7 +150,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) @@ -136,7 +165,7 @@ if SERVER then return true end end) - + ENT:AddHook("CanTurnOffFloat", "flight", function(self) if self:GetData("flight") then return false end end) @@ -146,7 +175,7 @@ if SERVER then return false end end) - + ENT:AddHook("ThirdPerson", "flight", function(self,ply,enabled) if enabled then if IsValid(self.pilot) then @@ -181,7 +210,7 @@ if SERVER then end end end) - + ENT:AddHook("PilotChanged","flight",function(self,old,new) self:SetData("pilot",new,true) self:SendMessage("PilotChanged",function() @@ -189,21 +218,17 @@ if SERVER then net.WriteEntity(new) 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() 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 @@ -218,10 +243,14 @@ 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 local p=self.pilot local eye=p:GetTardisData("viewang") @@ -230,12 +259,35 @@ 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() + + if door and TARDIS:GetSetting("opened-door-no-boost", true, self:GetCreator()) then + force_mult = 0.25 + 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 + 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) + end + end + + force = force * force_mult + vforce = vforce * force_mult + rforce = rforce * 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) @@ -261,27 +313,33 @@ 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 - - if self.spindir==0 then - tilt=0 - elseif self.spindir==1 then - tforce=-tforce + + if not spin or brakes then + tilt = 0 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) - - if not (self.spindir==0) then - local twist=Vector(0,0,vell/tforce) + + + -- 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) + + if spin and not brakes then + local twist = Vector(0, 0, -spindir * math.sqrt(vell / tforce)) ph:AddAngleVelocity(twist) end local angbrake=angvel*-0.015 @@ -302,8 +360,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 @@ -328,14 +386,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) diff --git a/lua/entities/gmod_tardis/modules/sh_spin.lua b/lua/entities/gmod_tardis/modules/sh_spin.lua new file mode 100644 index 000000000..5038fbf11 --- /dev/null +++ b/lua/entities/gmod_tardis/modules/sh_spin.lua @@ -0,0 +1,84 @@ +-- 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=true, + type="bool", + option=true, + networked=true +}) + +if CLIENT then return end + + +ENT:AddHook("Initialize", "spin", function(self) + self:SetData("spindir", -1) + self:SetData("spindir_prev", 0) +end) + +function ENT:ToggleSpin() + local current = self:GetData("spindir", -1) + 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) + 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) + local prev = self:GetData("spindir_prev", 0) + + self:SetData("spindir_prev", -prev) + self:SetData("spindir", -current) +end + +function ENT:GetSpinDir() + return self:GetData("spindir", -1) +end + +function ENT:SetSpinDir(dir) + return self:SetData("spindir", dir) +end + +function ENT:GetSpinDirText(show_next) + local current = self:GetData("spindir", -1) + if show_next == true then + current = self:GetData("spindir_prev", 0) + 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 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:GetSpinDir() ~= 0 then + self:SetData("spindir_before_door", current) + self:SetData("spindir_prev", current) + self:SetData("spindir", 0) + 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 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_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 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 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") 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 new file mode 100644 index 000000000..5bdcf4eaa --- /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 = "Spin direction", + 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/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 diff --git a/lua/tardis/controls/sh_control_vortexflight.lua b/lua/tardis/controls/sh_control_vortex_flight.lua similarity index 93% rename from lua/tardis/controls/sh_control_vortexflight.lua rename to lua/tardis/controls/sh_control_vortex_flight.lua index fe314d860..ea1c492c9 100644 --- a/lua/tardis/controls/sh_control_vortexflight.lua +++ b/lua/tardis/controls/sh_control_vortex_flight.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/interiors/default.lua b/lua/tardis/interiors/default.lua index 3ed40515c..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,6 +127,8 @@ T.Interior = { default_sonicdispenser = "sonic_dispenser", default_sonic_inserted = SonicModelExists() and "sonic_dispenser", default_helmic = "thirdperson", + default_atomaccel = "spin_toggle", + default_directionalpointer = "spin_switch", }, 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 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) 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