From 5848599c6026db3f093b1a4717a42b68a8c13654 Mon Sep 17 00:00:00 2001 From: Sixhei Tartari <42782503+Democles85@users.noreply.github.com> Date: Fri, 16 Jun 2023 14:27:47 +0200 Subject: [PATCH] feat(Vehicle): Added keep engine running functionality (#1426) --- src/backend/backend.cpp | 4 +-- .../looped/vehicle/keep_engine_running.cpp | 29 +++++++++++++++++++ src/core/globals.hpp | 3 +- src/util/vehicle.hpp | 10 +++---- src/views/vehicle/view_vehicle.cpp | 2 ++ 5 files changed, 40 insertions(+), 8 deletions(-) create mode 100644 src/backend/looped/vehicle/keep_engine_running.cpp diff --git a/src/backend/backend.cpp b/src/backend/backend.cpp index b11f45eb..74f7f759 100644 --- a/src/backend/backend.cpp +++ b/src/backend/backend.cpp @@ -6,9 +6,9 @@ #include "script_patches.hpp" #include "services/context_menu/context_menu_service.hpp" #include "services/orbital_drone/orbital_drone.hpp" +#include "services/squad_spawner/squad_spawner.hpp" #include "services/tunables/tunables_service.hpp" #include "services/vehicle/vehicle_control_service.hpp" -#include "services/squad_spawner/squad_spawner.hpp" #include "thread_pool.hpp" @@ -203,7 +203,7 @@ namespace big while (true) { g_squad_spawner_service.tick(); - + script::get_current()->yield(); } } diff --git a/src/backend/looped/vehicle/keep_engine_running.cpp b/src/backend/looped/vehicle/keep_engine_running.cpp new file mode 100644 index 00000000..d3551409 --- /dev/null +++ b/src/backend/looped/vehicle/keep_engine_running.cpp @@ -0,0 +1,29 @@ +#include "backend/looped_command.hpp" +#include "natives.hpp" + +namespace big +{ + class keep_engine_running : looped_command + { + using looped_command::looped_command; + + virtual void on_tick() override + { + if (ENTITY::DOES_ENTITY_EXIST(self::veh) && !VEHICLE::GET_IS_VEHICLE_ENGINE_RUNNING(self::veh)) + { + VEHICLE::SET_VEHICLE_KEEP_ENGINE_ON_WHEN_ABANDONED(self::veh, true); + } + } + + virtual void on_disable() override + { + if (ENTITY::DOES_ENTITY_EXIST(self::veh) && VEHICLE::GET_IS_VEHICLE_ENGINE_RUNNING(self::veh)) + { + VEHICLE::SET_VEHICLE_KEEP_ENGINE_ON_WHEN_ABANDONED(self::veh, false); + } + } + }; + + keep_engine_running g_keep_engine_running("keepengine", "Keep Engine Running", "Keeps the engine running when you exit the vehicle", + g.vehicle.keep_engine_running); +} \ No newline at end of file diff --git a/src/core/globals.hpp b/src/core/globals.hpp index 0d99b555..efc0c51b 100644 --- a/src/core/globals.hpp +++ b/src/core/globals.hpp @@ -641,6 +641,7 @@ namespace big bool no_water_collision = false; bool disable_engine_auto_start = false; bool change_engine_state_immediately = false; + bool keep_engine_running = false; bool vehinvisibility = false; bool localveh_visibility = false; bool localped_visibility = true; @@ -649,7 +650,7 @@ namespace big bool unlimited_weapons = false; bool siren_mute = false; - NLOHMANN_DEFINE_TYPE_INTRUSIVE(vehicle, speedo_meter, fly, rainbow_paint, speed_unit, god_mode, proof_bullet, proof_fire, proof_collision, proof_melee, proof_explosion, proof_steam, proof_water, proof_mask, auto_drive_destination, auto_drive_style, auto_drive_speed, auto_turn_signals, boost_behavior, drive_on_water, horn_boost, instant_brake, block_homing, seatbelt, turn_signals, vehicle_jump, keep_vehicle_repaired, no_water_collision, disable_engine_auto_start, change_engine_state_immediately, vehinvisibility, localveh_visibility, localped_visibility, keep_on_ground, no_collision, unlimited_weapons, siren_mute) + NLOHMANN_DEFINE_TYPE_INTRUSIVE(vehicle, speedo_meter, fly, rainbow_paint, speed_unit, god_mode, proof_bullet, proof_fire, proof_collision, proof_melee, proof_explosion, proof_steam, proof_water, proof_mask, auto_drive_destination, auto_drive_style, auto_drive_speed, auto_turn_signals, boost_behavior, drive_on_water, horn_boost, instant_brake, block_homing, seatbelt, turn_signals, vehicle_jump, keep_vehicle_repaired, no_water_collision, disable_engine_auto_start, change_engine_state_immediately, keep_engine_running, vehinvisibility, localveh_visibility, localped_visibility, keep_on_ground, no_collision, unlimited_weapons, siren_mute) } vehicle{}; struct weapons diff --git a/src/util/vehicle.hpp b/src/util/vehicle.hpp index 93b8be0e..1416ca62 100644 --- a/src/util/vehicle.hpp +++ b/src/util/vehicle.hpp @@ -48,7 +48,7 @@ namespace big::vehicle { Vector3 min, max, result; MISC::GET_MODEL_DIMENSIONS(hash, &min, &max); - result = max - min; + result = max - min; y_offset = result.y; } else if (!spawn_inside) @@ -613,15 +613,15 @@ namespace big::vehicle inline void max_vehicle_performance(Vehicle veh) { - if(entity::take_control_of(veh)) + if (entity::take_control_of(veh)) { VehicleModType perfomance_mods[] = {MOD_ENGINE, MOD_BRAKES, MOD_TRANSMISSION, MOD_SUSPENSION, MOD_ARMOR, MOD_NITROUS, MOD_TURBO}; VEHICLE::SET_VEHICLE_MOD_KIT(veh, 0); - for(auto mod_slot : perfomance_mods) + for (auto mod_slot : perfomance_mods) { - if(mod_slot != MOD_NITROUS && mod_slot != MOD_TURBO) - VEHICLE::SET_VEHICLE_MOD(veh, mod_slot, VEHICLE::GET_NUM_VEHICLE_MODS(veh, mod_slot) -1, true); + if (mod_slot != MOD_NITROUS && mod_slot != MOD_TURBO) + VEHICLE::SET_VEHICLE_MOD(veh, mod_slot, VEHICLE::GET_NUM_VEHICLE_MODS(veh, mod_slot) - 1, true); else VEHICLE::TOGGLE_VEHICLE_MOD(veh, mod_slot, true); } diff --git a/src/views/vehicle/view_vehicle.cpp b/src/views/vehicle/view_vehicle.cpp index c116f72d..414e7be4 100644 --- a/src/views/vehicle/view_vehicle.cpp +++ b/src/views/vehicle/view_vehicle.cpp @@ -52,6 +52,8 @@ namespace big ImGui::Checkbox("DISABLE_ENGINE_AUTO_START"_T.data(), &g.vehicle.disable_engine_auto_start); ImGui::SameLine(); ImGui::Checkbox("CHANGE_STATE_IMMEDIATELY"_T.data(), &g.vehicle.change_engine_state_immediately); + ImGui::SameLine(); + components::command_checkbox<"keepengine">(); ImGui::Separator();