diff --git a/lua/entities/base_glide_car/cl_init.lua b/lua/entities/base_glide_car/cl_init.lua index 41407d9e..ff19f314 100644 --- a/lua/entities/base_glide_car/cl_init.lua +++ b/lua/entities/base_glide_car/cl_init.lua @@ -521,6 +521,9 @@ function ENT:DrawVehicleHUD( screenW, screenH ) local iconSize = size * 0.11 DrawIcon( x + size - iconSize, y + size - iconSize * 0.5, "glide/icons/engine.png", iconSize, self:IsEngineOn() and colors.icon or colors.iconDisabled ) + -- Cruise control state + DrawIcon( x + size - iconSize * 2.12, y + size - iconSize * 0.5, "glide/icons/cruise_control.png", iconSize, self:GetIsCruiseControlEnabled() and colors.icon or colors.iconDisabled ) + -- Engine RPM local stream = self.stream local meterR = r * 0.9 diff --git a/lua/entities/base_glide_car/init.lua b/lua/entities/base_glide_car/init.lua index 0ece1eaf..1384934d 100644 --- a/lua/entities/base_glide_car/init.lua +++ b/lua/entities/base_glide_car/init.lua @@ -187,7 +187,7 @@ end function ENT:OnDriverExit() local keepOn = IsValid( self.lastDriver ) and self.lastDriver:KeyDown( IN_WALK ) - if not self.hasTheDriverBeenRagdolled and not keepOn then + if not self.hasTheDriverBeenRagdolled and not keepOn and not self:GetIsCruiseControlEnabled() then self:TurnOff() end @@ -247,6 +247,19 @@ function ENT:OnSeatInput( seatIndex, action, pressed ) elseif action == "accelerate" and self:GetEngineState() == 0 and self:GetEngineRPM() < 1 then self:TurnOn() + elseif action == "toggle_cruise_control" then + self:SetIsCruiseControlEnabled( not self:GetIsCruiseControlEnabled() ) + + if not self:GetIsCruiseControlEnabled() then + self.cruiseTargetSpeed = 0 + end + + Glide.SendNotification( self:GetAllPlayers(), { + text = self:GetIsCruiseControlEnabled() and "#glide.notify.cruise_control_on" or "#glide.notify.cruise_control_off", + icon = "materials/glide/icons/car.png", + immediate = true, + formatArgs = { self:GetIsCruiseControlEnabled() and "on" or "off" } + } ) end if not self.inputManualShift then return end diff --git a/lua/entities/base_glide_car/shared.lua b/lua/entities/base_glide_car/shared.lua index 5b2b39ae..377e767d 100644 --- a/lua/entities/base_glide_car/shared.lua +++ b/lua/entities/base_glide_car/shared.lua @@ -34,6 +34,7 @@ function ENT:SetupDataTables() -- these slots when creating your own on child classes! self:NetworkVar( "Bool", "IsRedlining" ) self:NetworkVar( "Bool", "IsHonking" ) + self:NetworkVar( "Bool", "IsCruiseControlEnabled" ) self:NetworkVar( "Int", "SirenState" ) self:NetworkVar( "Int", "Gear" ) diff --git a/lua/entities/base_glide_car/sv_engine.lua b/lua/entities/base_glide_car/sv_engine.lua index fce0c69c..87d36409 100644 --- a/lua/entities/base_glide_car/sv_engine.lua +++ b/lua/entities/base_glide_car/sv_engine.lua @@ -30,6 +30,8 @@ function ENT:EngineInit() self.avgSideSlip = 0 self.avgPoweredRPM = 0 self.avgForwardSlip = 0 + + self.cruiseTargetSpeed = 0 end --- Returns a list of available transmission gears. @@ -269,6 +271,22 @@ function ENT:EngineThink( dt, selfTbl ) inputBrake = self:GetInputFloat( 1, "brake", selfTbl ) inputHandbrake = self:GetInputBool( 1, "handbrake", selfTbl ) + if self:GetIsCruiseControlEnabled() and not amphibiousMode then + if inputBrake > 0.1 or inputThrottle > 0.1 then + self:SetIsCruiseControlEnabled( false ) + selfTbl.cruiseTargetSpeed = 0 + else + if not selfTbl.cruiseTargetSpeed or selfTbl.cruiseTargetSpeed < 0.1 then + selfTbl.cruiseTargetSpeed = Max( selfTbl.forwardSpeed, 0 ) + end + + local cruiseThrottle = Clamp( ( selfTbl.cruiseTargetSpeed - selfTbl.forwardSpeed ) * 0.01, 0, 1 ) + + inputThrottle = Max( inputThrottle, cruiseThrottle ) + inputBrake = 0 + end + end + if amphibiousMode then selfTbl.burnout = 0 self:BoatEngineThink( dt ) diff --git a/lua/glide/sh_input.lua b/lua/glide/sh_input.lua index aedad742..84464b66 100644 --- a/lua/glide/sh_input.lua +++ b/lua/glide/sh_input.lua @@ -95,6 +95,7 @@ Glide.AddInputAction( "land_controls", "throttle_modifier", KEY_LSHIFT ) Glide.AddInputAction( "land_controls", "horn", KEY_R ) Glide.AddInputAction( "land_controls", "siren", KEY_L ) Glide.AddInputAction( "land_controls", "detach_trailer", KEY_K ) +Glide.AddInputAction( "land_controls", "toggle_cruise_control", KEY_C ) Glide.AddInputAction( "land_controls", "lean_forward", KEY_UP ) Glide.AddInputAction( "land_controls", "lean_back", KEY_DOWN ) diff --git a/materials/glide/icons/cruise_control.png b/materials/glide/icons/cruise_control.png new file mode 100644 index 00000000..07932406 Binary files /dev/null and b/materials/glide/icons/cruise_control.png differ diff --git a/resource/localization/en/glide_vehicles.properties b/resource/localization/en/glide_vehicles.properties index 29e406e7..8fb6c805 100644 --- a/resource/localization/en/glide_vehicles.properties +++ b/resource/localization/en/glide_vehicles.properties @@ -80,6 +80,7 @@ glide.input.siren=Siren glide.input.headlights=Toggle headlights glide.input.toggle_engine=Toggle engine glide.input.detach_trailer=Detach trailer +glide.input.cruise_control=Cruise control glide.input.throttle_modifier=Throttle modifier glide.input.throttle_mod_mode=Throttle modifier mode @@ -197,6 +198,8 @@ glide.notify.vehicle_locked=This vehicle has been locked, only the vehicle creat glide.notify.vehicle_unlocked=This vehicle has been unlocked, anyone can enter it. glide.notify.reduced_throttle_on=Reduced throttle. glide.notify.reduced_throttle_off=Full throttle. +glide.notify.cruise_control_on=You have activated cruise control. +glide.notify.cruise_control_off=You have deactivated cruise control. glide.notify.tip.headlights=Press %s to switch headlights.\n\nYou can also configure if they should turn on/off automatically when you are on a dim place. glide.notify.tip.homing_launcher=Hold the right mouse button to lock on occupied vehicles. glide.notify.tip.heli_controls=Use the mouse to aim the helicopter.\n\nYou can switch to WAC-like or GTA-like controls in the settings. diff --git a/resource/localization/fr/glide_vehicles.properties b/resource/localization/fr/glide_vehicles.properties index a0acac92..cd57e409 100644 --- a/resource/localization/fr/glide_vehicles.properties +++ b/resource/localization/fr/glide_vehicles.properties @@ -80,6 +80,7 @@ glide.input.siren=Sirène glide.input.headlights=Activer/désactiver les phares glide.input.toggle_engine=Allumer/éteindre le moteur glide.input.detach_trailer=Détacher la remorque +glide.input.cruise_control=Régulateur de vitesse glide.input.throttle_modifier=Modificateur d'accélérateur glide.input.throttle_mod_mode=Mode de modif. d'accélérateur @@ -198,6 +199,8 @@ glide.notify.vehicle_locked=Ce véhicule a été verrouillé, seuls le créateur glide.notify.vehicle_unlocked=Ce véhicule a été déverrouillé, tout le monde peut y entrer. glide.notify.reduced_throttle_on=Gaz réduit. glide.notify.reduced_throttle_off=Plein régime. +glide.notify.cruise_control_on=Vous avez activé le régulateur de vitesse. +glide.notify.cruise_control_off=Vous avez désactivé le régulateur de vitesse. glide.notify.tip.headlights=Appuyez sur %s pour allumer/éteindre les phares.\n\nVous pouvez également configurer leur activation/désactivation automatique dans les endroits sombres. glide.notify.tip.homing_launcher=Maintenez le clic droit pour verrouiller les véhicules occupés. glide.notify.tip.heli_controls=Utilisez la souris pour piloter l'hélicoptère.\n\nVous pouvez passer à des contrôles de style WAC ou GTA dans les paramètres.