From 4f77328c2d32b4cf15eb905e6d282c900eef02ba Mon Sep 17 00:00:00 2001 From: Hondacrx Date: Thu, 14 Aug 2025 20:43:05 -0400 Subject: [PATCH] Core/Vehicles: Added field to set a default pitch Port From (https://github.com/TrinityCore/TrinityCore/commit/47440e9dd2f5cad5d274e61a1ce8e559b80d0496) --- Source/Game/Entities/Vehicle.cs | 12 +++++++++++ Source/Game/Globals/ObjectManager.cs | 32 ++++++++++++++++++++++++---- 2 files changed, 40 insertions(+), 4 deletions(-) diff --git a/Source/Game/Entities/Vehicle.cs b/Source/Game/Entities/Vehicle.cs index 5e66d0649..f968351a0 100644 --- a/Source/Game/Entities/Vehicle.cs +++ b/Source/Game/Entities/Vehicle.cs @@ -459,6 +459,8 @@ namespace Game.Entities _me.AddUnitMovementFlag2(MovementFlag2.AlwaysAllowPitching); if (vehicleFlags.HasAnyFlag(VehicleFlags.Fullspeedpitching)) _me.AddUnitMovementFlag2(MovementFlag2.FullSpeedPitching); + + _me.m_movementInfo.Pitch = GetPitch(); } public VehicleSeatRecord GetSeatForPassenger(Unit passenger) @@ -569,6 +571,15 @@ namespace Game.Entities return TimeSpan.FromMilliseconds(1); } + float GetPitch() + { + VehicleTemplate vehicleTemplate = Global.ObjectMgr.GetVehicleTemplate(this); + if (vehicleTemplate != null && vehicleTemplate.Pitch.HasValue) + return vehicleTemplate.Pitch.Value; + + return Math.Clamp(0.0f, _vehicleInfo.PitchMin, _vehicleInfo.PitchMax); + } + public string GetDebugInfo() { StringBuilder str = new StringBuilder("Vehicle seats:\n"); @@ -820,6 +831,7 @@ namespace Game.Entities public class VehicleTemplate { public TimeSpan DespawnDelay; + public float? Pitch; } public class VehicleSeatAddon diff --git a/Source/Game/Globals/ObjectManager.cs b/Source/Game/Globals/ObjectManager.cs index 322594b19..432bc7dc4 100644 --- a/Source/Game/Globals/ObjectManager.cs +++ b/Source/Game/Globals/ObjectManager.cs @@ -11363,8 +11363,8 @@ namespace Game _vehicleTemplateStore.Clear(); - // 0 1 - SQLResult result = DB.World.Query("SELECT creatureId, despawnDelayMs FROM vehicle_template"); + // 0 1 2 + SQLResult result = DB.World.Query("SELECT creatureId, despawnDelayMs, Pitch FROM vehicle_template"); if (result.IsEmpty()) { Log.outInfo(LogFilter.ServerLoading, "Loaded 0 vehicle template. DB table `vehicle_template` is empty."); @@ -11375,14 +11375,38 @@ namespace Game { uint creatureId = result.Read(0); - if (GetCreatureTemplate(creatureId) == null) + CreatureTemplate creatureInfo = GetCreatureTemplate(creatureId); + if (creatureInfo == null) { - Log.outError(LogFilter.Sql, $"Table `vehicle_template`: Vehicle {creatureId} does not exist."); + Log.outError(LogFilter.Sql, $"Table `vehicle_template`: Creature (Entry: {creatureId}) does not exist."); + continue; + } + + if (creatureInfo.VehicleId == 0) + { + Log.outError(LogFilter.Sql, $"Table `vehicle_template`: Creature (Entry: {creatureId}) is not a vehicle."); continue; } VehicleTemplate vehicleTemplate = new(); vehicleTemplate.DespawnDelay = TimeSpan.FromMilliseconds(result.Read(1)); + + if (!result.IsNull(2)) + { + var vehicle = CliDB.VehicleStorage.LookupByKey(creatureInfo.VehicleId); + if (vehicle == null) + continue; + + float pitch = result.Read(2); + if (pitch < vehicle.PitchMin || pitch > vehicle.PitchMax) + { + Log.outError(LogFilter.Sql, $"Table `vehicle_template`: Creature (Entry: {creatureId}) has invalid Pitch ({pitch}).`. Ignoring"); + continue; + } + + vehicleTemplate.Pitch = pitch; + } + _vehicleTemplateStore[creatureId] = vehicleTemplate; } while (result.NextRow());