Core/Vehicles: Added field to set a default pitch (#30878)

(cherry picked from commit 47440e9dd2)

# Conflicts:
#	sql/old/4.4.x/world/25021_2025_05_11/2025_05_11_03_world.sql
This commit is contained in:
Meji
2025-05-11 22:00:41 +02:00
committed by Ovahlord
parent c093df0f9c
commit 20a31ea9d8
5 changed files with 42 additions and 4 deletions

View File

@@ -0,0 +1,2 @@
ALTER TABLE `vehicle_template`
ADD `Pitch` FLOAT DEFAULT NULL AFTER `despawnDelayMs`;

View File

@@ -632,6 +632,8 @@ void Vehicle::InitMovementInfoForBase()
_me->AddExtraUnitMovementFlag(MOVEMENTFLAG2_ALWAYS_ALLOW_PITCHING);
if (vehicleFlags & VEHICLE_FLAG_FULLSPEEDPITCHING)
_me->AddExtraUnitMovementFlag(MOVEMENTFLAG2_FULL_SPEED_PITCHING);
_me->m_movementInfo.pitch = GetPitch();
}
/**
@@ -966,6 +968,15 @@ Milliseconds Vehicle::GetDespawnDelay()
return 1ms;
}
float Vehicle::GetPitch()
{
if (VehicleTemplate const* vehicleTemplate = sObjectMgr->GetVehicleTemplate(this))
if (vehicleTemplate->Pitch)
return *vehicleTemplate->Pitch;
return std::clamp(0.0f, _vehicleInfo->PitchMin, _vehicleInfo->PitchMax);
}
std::string Vehicle::GetDebugInfo() const
{
std::stringstream sstr;

View File

@@ -71,6 +71,7 @@ class TC_GAME_API Vehicle final : public TransportBase
void RemovePendingEventsForPassenger(Unit* passenger);
Milliseconds GetDespawnDelay();
float GetPitch();
std::string GetDebugInfo() const;

View File

@@ -144,6 +144,7 @@ struct VehicleAccessory
struct VehicleTemplate
{
Milliseconds DespawnDelay = Milliseconds::zero();
Optional<float> Pitch;
};
typedef std::vector<VehicleAccessory> VehicleAccessoryList;

View File

@@ -3266,8 +3266,8 @@ void ObjectMgr::LoadVehicleTemplate()
_vehicleTemplateStore.clear();
// 0 1
QueryResult result = WorldDatabase.Query("SELECT creatureId, despawnDelayMs FROM vehicle_template");
// 0 1 2
QueryResult result = WorldDatabase.Query("SELECT creatureId, despawnDelayMs, Pitch FROM vehicle_template");
if (!result)
{
@@ -3281,15 +3281,38 @@ void ObjectMgr::LoadVehicleTemplate()
uint32 creatureId = fields[0].GetUInt32();
if (!GetCreatureTemplate(creatureId))
CreatureTemplate const* creatureInfo = GetCreatureTemplate(creatureId);
if (!creatureInfo)
{
TC_LOG_ERROR("sql.sql", "Table `vehicle_template`: Vehicle {} does not exist.", creatureId);
TC_LOG_ERROR("sql.sql", "Table `vehicle_template`: Creature (Entry: {}) does not exist.", creatureId);
continue;
}
if (!creatureInfo->VehicleId)
{
TC_LOG_ERROR("sql.sql", "Table `vehicle_template`: Creature (Entry: {}) is not a vehicle.", creatureId);
continue;
}
VehicleTemplate& vehicleTemplate = _vehicleTemplateStore[creatureId];
vehicleTemplate.DespawnDelay = Milliseconds(fields[1].GetInt32());
if (!fields[2].IsNull())
{
VehicleEntry const* vehicle = sVehicleStore.LookupEntry(creatureInfo->VehicleId);
if (!vehicle)
continue;
float pitch = fields[2].GetFloat();
if (pitch < vehicle->PitchMin || pitch > vehicle->PitchMax)
{
TC_LOG_ERROR("sql.sql", "Table `vehicle_template`: Creature (Entry: {}) has invalid Pitch ({}).`. Ignoring",
creatureId, pitch);
continue;
}
vehicleTemplate.Pitch = pitch;
}
} while (result->NextRow());
TC_LOG_INFO("server.loading", ">> Loaded {} Vehicle Template entries in {} ms", _vehicleTemplateStore.size(), GetMSTimeDiffToNow(oldMSTime));