Clean up
This commit is contained in:
@ -1,8 +1,8 @@
|
||||
using GTA;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using GTA;
|
||||
using GTA.Native;
|
||||
using RageCoop.Core;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace RageCoop.Client
|
||||
{
|
||||
@ -15,101 +15,62 @@ namespace RageCoop.Client
|
||||
var veh = v.MainVehicle;
|
||||
VehicleDataFlags flags = 0;
|
||||
|
||||
if (veh.IsEngineRunning)
|
||||
{
|
||||
flags |= VehicleDataFlags.IsEngineRunning;
|
||||
}
|
||||
if (veh.IsEngineRunning) flags |= VehicleDataFlags.IsEngineRunning;
|
||||
|
||||
if (veh.AreLightsOn)
|
||||
{
|
||||
flags |= VehicleDataFlags.AreLightsOn;
|
||||
}
|
||||
if (veh.AreLightsOn) flags |= VehicleDataFlags.AreLightsOn;
|
||||
|
||||
if (veh.BrakePower >= 0.01f)
|
||||
{
|
||||
flags |= VehicleDataFlags.AreBrakeLightsOn;
|
||||
}
|
||||
if (veh.BrakePower >= 0.01f) flags |= VehicleDataFlags.AreBrakeLightsOn;
|
||||
|
||||
if (veh.AreHighBeamsOn)
|
||||
{
|
||||
flags |= VehicleDataFlags.AreHighBeamsOn;
|
||||
}
|
||||
if (veh.AreHighBeamsOn) flags |= VehicleDataFlags.AreHighBeamsOn;
|
||||
|
||||
if (veh.IsSirenActive)
|
||||
{
|
||||
flags |= VehicleDataFlags.IsSirenActive;
|
||||
}
|
||||
if (veh.IsSirenActive) flags |= VehicleDataFlags.IsSirenActive;
|
||||
|
||||
if (veh.IsDead)
|
||||
{
|
||||
flags |= VehicleDataFlags.IsDead;
|
||||
}
|
||||
if (veh.IsDead) flags |= VehicleDataFlags.IsDead;
|
||||
|
||||
if (Function.Call<bool>(Hash.IS_HORN_ACTIVE, veh.Handle))
|
||||
{
|
||||
flags |= VehicleDataFlags.IsHornActive;
|
||||
}
|
||||
if (Function.Call<bool>(Hash.IS_HORN_ACTIVE, veh.Handle)) flags |= VehicleDataFlags.IsHornActive;
|
||||
|
||||
if (v.IsSubmarineCar && Function.Call<bool>(Hash._GET_IS_SUBMARINE_VEHICLE_TRANSFORMED, veh.Handle))
|
||||
{
|
||||
flags |= VehicleDataFlags.IsTransformed;
|
||||
}
|
||||
|
||||
if (v.IsAircraft)
|
||||
{
|
||||
flags |= VehicleDataFlags.IsAircraft;
|
||||
}
|
||||
if (v.IsAircraft) flags |= VehicleDataFlags.IsAircraft;
|
||||
|
||||
if (v.IsDeluxo && veh.IsDeluxoHovering())
|
||||
{
|
||||
flags |= VehicleDataFlags.IsDeluxoHovering;
|
||||
}
|
||||
if (v.IsDeluxo && veh.IsDeluxoHovering()) flags |= VehicleDataFlags.IsDeluxoHovering;
|
||||
|
||||
if (v.HasRoof)
|
||||
{
|
||||
flags |= VehicleDataFlags.HasRoof;
|
||||
}
|
||||
if (v.HasRoof) flags |= VehicleDataFlags.HasRoof;
|
||||
|
||||
if (v.HasRocketBoost && veh.IsRocketBoostActive())
|
||||
{
|
||||
flags |= VehicleDataFlags.IsRocketBoostActive;
|
||||
}
|
||||
if (v.HasRocketBoost && veh.IsRocketBoostActive()) flags |= VehicleDataFlags.IsRocketBoostActive;
|
||||
|
||||
if (v.HasParachute && veh.IsParachuteActive())
|
||||
{
|
||||
flags |= VehicleDataFlags.IsParachuteActive;
|
||||
}
|
||||
if (v.HasParachute && veh.IsParachuteActive()) flags |= VehicleDataFlags.IsParachuteActive;
|
||||
|
||||
if (veh.IsOnFire)
|
||||
{
|
||||
flags |= VehicleDataFlags.IsOnFire;
|
||||
}
|
||||
if (veh.IsOnFire) flags |= VehicleDataFlags.IsOnFire;
|
||||
|
||||
return flags;
|
||||
}
|
||||
|
||||
public static bool IsRocketBoostActive(this Vehicle veh)
|
||||
{
|
||||
return Function.Call<bool>(Hash._IS_VEHICLE_ROCKET_BOOST_ACTIVE, veh);
|
||||
}
|
||||
|
||||
public static bool IsParachuteActive(this Vehicle veh)
|
||||
{
|
||||
return Function.Call<bool>((Hash)0x3DE51E9C80B116CF, veh);
|
||||
}
|
||||
|
||||
public static void SetRocketBoostActive(this Vehicle veh, bool toggle)
|
||||
{
|
||||
Function.Call(Hash._SET_VEHICLE_ROCKET_BOOST_ACTIVE, veh, toggle);
|
||||
}
|
||||
|
||||
public static void SetParachuteActive(this Vehicle veh, bool toggle)
|
||||
{
|
||||
Function.Call((Hash)0x0BFFB028B3DD0A97, veh, toggle);
|
||||
}
|
||||
|
||||
public static Dictionary<int, int> GetVehicleMods(this VehicleModCollection mods)
|
||||
{
|
||||
Dictionary<int, int> result = new Dictionary<int, int>();
|
||||
foreach (VehicleMod mod in mods.ToArray())
|
||||
{
|
||||
result.Add((int)mod.Type, mod.Index);
|
||||
}
|
||||
var result = new Dictionary<int, int>();
|
||||
foreach (var mod in mods.ToArray()) result.Add((int)mod.Type, mod.Index);
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -117,40 +78,25 @@ namespace RageCoop.Client
|
||||
{
|
||||
// Broken windows
|
||||
byte brokenWindows = 0;
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
for (var i = 0; i < 8; i++)
|
||||
if (!veh.Windows[(VehicleWindowIndex)i].IsIntact)
|
||||
{
|
||||
brokenWindows |= (byte)(1 << i);
|
||||
}
|
||||
}
|
||||
|
||||
// Broken doors
|
||||
byte brokenDoors = 0;
|
||||
byte openedDoors = 0;
|
||||
foreach (VehicleDoor door in veh.Doors)
|
||||
{
|
||||
foreach (var door in veh.Doors)
|
||||
if (door.IsBroken)
|
||||
{
|
||||
brokenDoors |= (byte)(1 << (byte)door.Index);
|
||||
}
|
||||
else if (door.IsOpen)
|
||||
{
|
||||
openedDoors |= (byte)(1 << (byte)door.Index);
|
||||
}
|
||||
}
|
||||
else if (door.IsOpen) openedDoors |= (byte)(1 << (byte)door.Index);
|
||||
|
||||
// Bursted tires
|
||||
short burstedTires = 0;
|
||||
foreach (VehicleWheel wheel in veh.Wheels.GetAllWheels())
|
||||
{
|
||||
foreach (var wheel in veh.Wheels.GetAllWheels())
|
||||
if (wheel.IsBursted)
|
||||
{
|
||||
burstedTires |= (short)(1 << (int)wheel.BoneId);
|
||||
}
|
||||
}
|
||||
|
||||
return new VehicleDamageModel()
|
||||
return new VehicleDamageModel
|
||||
{
|
||||
BrokenDoors = brokenDoors,
|
||||
OpenedDoors = openedDoors,
|
||||
@ -163,47 +109,37 @@ namespace RageCoop.Client
|
||||
|
||||
public static void SetDamageModel(this Vehicle veh, VehicleDamageModel model, bool leavedoors = true)
|
||||
{
|
||||
for (int i = 0; i < 8; i++)
|
||||
for (var i = 0; i < 8; i++)
|
||||
{
|
||||
var door = veh.Doors[(VehicleDoorIndex)i];
|
||||
if ((model.BrokenDoors & (byte)(1 << i)) != 0)
|
||||
{
|
||||
if (!door.IsBroken)
|
||||
{
|
||||
door.Break(leavedoors);
|
||||
}
|
||||
if (!door.IsBroken) door.Break(leavedoors);
|
||||
continue;
|
||||
}
|
||||
else if (door.IsBroken)
|
||||
|
||||
if (door.IsBroken)
|
||||
{
|
||||
// The vehicle can only fix a door if the vehicle was completely fixed
|
||||
veh.Repair();
|
||||
return;
|
||||
}
|
||||
|
||||
if ((model.OpenedDoors & (byte)(1 << i)) != 0)
|
||||
{
|
||||
if ((!door.IsOpen) && (!door.IsBroken))
|
||||
{
|
||||
door.Open();
|
||||
}
|
||||
if (!door.IsOpen && !door.IsBroken) door.Open();
|
||||
}
|
||||
else if (door.IsOpen)
|
||||
{
|
||||
if (!door.IsBroken) { door.Close(); }
|
||||
if (!door.IsBroken) door.Close();
|
||||
}
|
||||
|
||||
if ((model.BrokenWindows & (byte)(1 << i)) != 0)
|
||||
{
|
||||
veh.Windows[(VehicleWindowIndex)i].Smash();
|
||||
}
|
||||
else if (!veh.Windows[(VehicleWindowIndex)i].IsIntact)
|
||||
{
|
||||
veh.Windows[(VehicleWindowIndex)i].Repair();
|
||||
}
|
||||
else if (!veh.Windows[(VehicleWindowIndex)i].IsIntact) veh.Windows[(VehicleWindowIndex)i].Repair();
|
||||
}
|
||||
|
||||
foreach (VehicleWheel wheel in veh.Wheels)
|
||||
{
|
||||
foreach (var wheel in veh.Wheels)
|
||||
if ((model.BurstedTires & (short)(1 << (int)wheel.BoneId)) != 0)
|
||||
{
|
||||
if (!wheel.IsBursted)
|
||||
@ -216,7 +152,6 @@ namespace RageCoop.Client
|
||||
{
|
||||
wheel.Fix();
|
||||
}
|
||||
}
|
||||
|
||||
veh.IsLeftHeadLightBroken = model.LeftHeadLightBroken > 0;
|
||||
veh.IsRightHeadLightBroken = model.RightHeadLightBroken > 0;
|
||||
@ -224,19 +159,12 @@ namespace RageCoop.Client
|
||||
|
||||
public static Dictionary<int, int> GetPassengers(this Vehicle veh)
|
||||
{
|
||||
Dictionary<int, int> ps = new Dictionary<int, int>();
|
||||
var ps = new Dictionary<int, int>();
|
||||
var d = veh.Driver;
|
||||
if (d != null && d.IsSittingInVehicle())
|
||||
{
|
||||
ps.Add(-1, d.GetSyncEntity().ID);
|
||||
}
|
||||
foreach (Ped p in veh.Passengers)
|
||||
{
|
||||
if (d != null && d.IsSittingInVehicle()) ps.Add(-1, d.GetSyncEntity().ID);
|
||||
foreach (var p in veh.Passengers)
|
||||
if (p.IsSittingInVehicle())
|
||||
{
|
||||
ps.Add((int)p.SeatIndex, p.GetSyncEntity().ID);
|
||||
}
|
||||
}
|
||||
return ps;
|
||||
}
|
||||
|
||||
@ -244,25 +172,29 @@ namespace RageCoop.Client
|
||||
{
|
||||
Function.Call(Hash._SET_VEHICLE_HOVER_TRANSFORM_PERCENTAGE, deluxo, hover ? 1f : 0f);
|
||||
}
|
||||
|
||||
public static bool IsDeluxoHovering(this Vehicle deluxo)
|
||||
{
|
||||
return Math.Abs(deluxo.Bones[27].ForwardVector.GetCosTheta(deluxo.ForwardVector) - 1) > 0.05;
|
||||
}
|
||||
|
||||
public static void SetDeluxoWingRatio(this Vehicle v, float ratio)
|
||||
{
|
||||
Function.Call(Hash._SET_SPECIALFLIGHT_WING_RATIO, v, ratio);
|
||||
}
|
||||
|
||||
public static float GetDeluxoWingRatio(this Vehicle v)
|
||||
{
|
||||
return v.Bones[99].Position.DistanceTo(v.Bones[92].Position) - 1.43f;
|
||||
}
|
||||
|
||||
public static float GetNozzleAngel(this Vehicle plane)
|
||||
{
|
||||
return Function.Call<float>(Hash._GET_VEHICLE_FLIGHT_NOZZLE_POSITION, plane);
|
||||
}
|
||||
|
||||
public static bool HasNozzle(this Vehicle v)
|
||||
{
|
||||
|
||||
switch (v.Model.Hash)
|
||||
{
|
||||
// Hydra
|
||||
@ -280,14 +212,16 @@ namespace RageCoop.Client
|
||||
// Avenger
|
||||
case 408970549:
|
||||
return true;
|
||||
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static void SetNozzleAngel(this Vehicle plane, float ratio)
|
||||
{
|
||||
Function.Call(Hash.SET_VEHICLE_FLIGHT_NOZZLE_POSITION, plane, ratio);
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user