Feat vehicle gun improv (#291)

This commit is contained in:
Quentin E. / iDeath 2022-06-27 15:59:25 +02:00 committed by GitHub
parent 747af10277
commit a64f016412
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 48 additions and 32 deletions

View File

@ -2,23 +2,30 @@
#include "core/enums.hpp" #include "core/enums.hpp"
#include "util/math.hpp" #include "util/math.hpp"
#include "util/vehicle.hpp" #include "util/vehicle.hpp"
#include "gui.hpp"
namespace big namespace big
{ {
static auto last_time = std::chrono::steady_clock::now();
void looped::weapons_vehicle_gun() void looped::weapons_vehicle_gun()
{ {
bool bVehicleGun = g->weapons.custom_weapon == CustomWeapon::VEHICLE_GUN; const bool is_vehicle_gun_selected = g->weapons.custom_weapon == CustomWeapon::VEHICLE_GUN;
if (bVehicleGun) const auto time_now = std::chrono::steady_clock::now();
{
if (PAD::IS_DISABLED_CONTROL_PRESSED(0, (int)ControllerInputs::INPUT_AIM)) const auto elapsed_time_in_ms = std::chrono::duration_cast<std::chrono::milliseconds>(time_now - last_time).count();
{
if (PAD::IS_DISABLED_CONTROL_JUST_RELEASED(0, (int)ControllerInputs::INPUT_ATTACK)) if (is_vehicle_gun_selected &&
!g_gui.m_opened &&
elapsed_time_in_ms >= 100 &&
PAD::IS_DISABLED_CONTROL_PRESSED(0, (int)ControllerInputs::INPUT_ATTACK))
{ {
Vector3 location = self::pos; Vector3 location = self::pos;
Vector3 rot = CAM::GET_GAMEPLAY_CAM_ROT(2); constexpr int rotation_order = 2;
Vector3 rot = CAM::GET_GAMEPLAY_CAM_ROT(rotation_order);
float pitch = math::deg_to_rad(rot.x); // vertical float pitch = math::deg_to_rad(rot.x); // vertical
//float roll = rot.y; //float roll = rot.y;
float yaw = math::deg_to_rad(rot.z + 90); // horizontal float yaw = math::deg_to_rad(rot.z + 90); // horizontal
@ -33,16 +40,23 @@ namespace big
ENTITY::GET_ENTITY_HEADING(self::ped) ENTITY::GET_ENTITY_HEADING(self::ped)
); );
Vector3 velocity;
dist = 150.f; dist = 150.f;
velocity.x = dist * cos(pitch) * cos(yaw); Vector3 velocity
velocity.y = dist * sin(yaw) * cos(pitch); {
velocity.z = dist * sin(pitch); dist * cos(pitch) * cos(yaw),
dist * sin(yaw) * cos(pitch),
dist * sin(pitch)
};
ENTITY::SET_ENTITY_ROTATION(veh, rot.x, rot.y, rot.z, 2, 1); ENTITY::SET_ENTITY_ROTATION(veh, rot.x, rot.y, rot.z, rotation_order, 1);
ENTITY::SET_ENTITY_VELOCITY(veh, velocity.x, velocity.y, velocity.z); ENTITY::SET_ENTITY_VELOCITY(veh, velocity.x, velocity.y, velocity.z);
}
} // flagging the veh as no longer needed so that the game can remove it
// when reaching the maximum vehicle limit,
// allowing the vehicle gun to keep working
ENTITY::SET_VEHICLE_AS_NO_LONGER_NEEDED(&veh);
last_time = time_now;
} }
} }
} }

View File

@ -89,8 +89,10 @@ namespace big
switch (selected) switch (selected)
{ {
case CustomWeapon::VEHICLE_GUN: case CustomWeapon::VEHICLE_GUN:
ImGui::Text("Shooting Model:"); components::input_text_with_hint(
ImGui::InputText("##vehicle_gun_model", g->weapons.vehicle_gun_model, 12); "Shooting Model",
"Name of the vehicle model",
g->weapons.vehicle_gun_model, sizeof(g->weapons.vehicle_gun_model));
break; break;
} }