diff options
| author | Ovah <dreadkiller@gmx.de> | 2020-02-08 20:47:46 +0100 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-02-08 20:47:46 +0100 |
| commit | 98d6c501d7c1a7a632c6ff8b1d46c7d0d4ae5b37 (patch) | |
| tree | 8b4e5fc77bacc7bf22681ce229b09c0741ccbeb9 /src | |
| parent | 58313fc33092236b4eedbbfb25e10ab42bec6b0e (diff) | |
Core/Vehicles: implement vehicle seat addon table to specify seat ori… (#24112)
* Core/Vehicles: implement vehicle seat addon table to specify seat orientation offsets and exit positions in form of offsets or absolute positions
* converted Traveler's Tundra Mammoth to seat addon table data
* first follow batch
* whoopsie
* Core/Vehicles: go from local copies to pointers
* Update and rename 2020_99_99_99_world.sql to 2020_02_08_01_world.sql
Co-authored-by: Giacomo Pozzoni <giacomopoz@gmail.com>
Diffstat (limited to 'src')
| -rw-r--r-- | src/server/game/Entities/Unit/Unit.cpp | 12 | ||||
| -rwxr-xr-x | src/server/game/Entities/Vehicle/Vehicle.cpp | 38 | ||||
| -rw-r--r-- | src/server/game/Entities/Vehicle/Vehicle.h | 1 | ||||
| -rw-r--r-- | src/server/game/Entities/Vehicle/VehicleDefines.h | 26 | ||||
| -rw-r--r-- | src/server/game/Globals/ObjectMgr.cpp | 56 | ||||
| -rw-r--r-- | src/server/game/Globals/ObjectMgr.h | 12 | ||||
| -rw-r--r-- | src/server/game/World/World.cpp | 3 | ||||
| -rw-r--r-- | src/server/scripts/World/npcs_special.cpp | 35 |
8 files changed, 143 insertions, 40 deletions
diff --git a/src/server/game/Entities/Unit/Unit.cpp b/src/server/game/Entities/Unit/Unit.cpp index 7640d6ece0b..193e4228cfc 100644 --- a/src/server/game/Entities/Unit/Unit.cpp +++ b/src/server/game/Entities/Unit/Unit.cpp @@ -12545,6 +12545,7 @@ void Unit::_ExitVehicle(Position const* exitPosition) return; // This should be done before dismiss, because there may be some aura removal + VehicleSeatAddon const* seatAddon = m_vehicle->GetSeatAddonForSeatOfPassenger(this); Vehicle* vehicle = m_vehicle->RemovePassenger(this); Player* player = ToPlayer(); @@ -12575,7 +12576,18 @@ void Unit::_ExitVehicle(Position const* exitPosition) // Set exit position to vehicle position and use the current orientation pos = vehicle->GetBase()->GetPosition(); pos.SetOrientation(GetOrientation()); + + // To-do: snap this hook out of existance sScriptMgr->ModifyVehiclePassengerExitPos(this, vehicle, pos); + + // Change exit position based on seat entry addon data + if (seatAddon) + { + if (seatAddon->ExitParameter == VehicleExitParameters::VehicleExitParamOffset) + pos.RelocateOffset({ seatAddon->ExitParameterX, seatAddon->ExitParameterY, seatAddon->ExitParameterZ, seatAddon->ExitParameterO }); + else if (seatAddon->ExitParameter == VehicleExitParameters::VehicleExitParamDest) + pos.Relocate({ seatAddon->ExitParameterX, seatAddon->ExitParameterY, seatAddon->ExitParameterZ, seatAddon->ExitParameterO }); + } } float height = pos.GetPositionZ() + vehicle->GetBase()->GetCollisionHeight(); diff --git a/src/server/game/Entities/Vehicle/Vehicle.cpp b/src/server/game/Entities/Vehicle/Vehicle.cpp index 85b999dc93a..c19b489fb94 100755 --- a/src/server/game/Entities/Vehicle/Vehicle.cpp +++ b/src/server/game/Entities/Vehicle/Vehicle.cpp @@ -41,7 +41,8 @@ UsableSeatNum(0), _me(unit), _vehicleInfo(vehInfo), _creatureEntry(creatureEntry if (uint32 seatId = _vehicleInfo->m_seatID[i]) if (VehicleSeatEntry const* veSeat = sVehicleSeatStore.LookupEntry(seatId)) { - Seats.insert(std::make_pair(i, VehicleSeat(veSeat))); + VehicleSeatAddon const* addon = sObjectMgr->GetVehicleSeatAddon(seatId); + Seats.insert(std::make_pair(i, VehicleSeat(veSeat, addon))); if (veSeat->CanEnterOrExit()) ++UsableSeatNum; } @@ -346,6 +347,28 @@ SeatMap::const_iterator Vehicle::GetNextEmptySeat(int8 seatId, bool next) const } /** + * @fn VehicleSeatAddon const* Vehicle::GetSeatAddonForSeatOfPassenger(Unit const* passenger) const + * + * @brief Gets the vehicle seat addon data for the seat of a passenger + * + * @author Ovahlord + * @date 28-1-2020 + * + * @param passenger Identifier for the current seat user + * + * @return The seat addon data for the currently used seat of a passenger + */ + +VehicleSeatAddon const* Vehicle::GetSeatAddonForSeatOfPassenger(Unit const* passenger) const +{ + for (SeatMap::const_iterator itr = Seats.begin(); itr != Seats.end(); itr++) + if (!itr->second.IsEmpty() && itr->second.Passenger.Guid == passenger->GetGUID()) + return itr->second.SeatAddon; + + return nullptr; +} + +/** * @fn void Vehicle::InstallAccessory(uint32 entry, int8 seatId, bool minion, uint8 type, * uint32 summonTime) * @@ -809,6 +832,7 @@ bool VehicleJoinEvent::Execute(uint64, uint32) Passenger->RemoveAurasByType(SPELL_AURA_MOUNTED); VehicleSeatEntry const* veSeat = Seat->second.SeatInfo; + VehicleSeatAddon const* veSeatAddon = Seat->second.SeatAddon; Player* player = Passenger->ToPlayer(); if (player) @@ -827,8 +851,14 @@ bool VehicleJoinEvent::Execute(uint64, uint32) if (veSeat->HasFlag(VEHICLE_SEAT_FLAG_PASSENGER_NOT_SELECTABLE)) Passenger->SetFlag(UNIT_FIELD_FLAGS, UNIT_FLAG_NOT_SELECTABLE); + + float o = veSeatAddon ? veSeatAddon->SeatOrientationOffset : 0.f; + float x = veSeat->m_attachmentOffsetX; + float y = veSeat->m_attachmentOffsetY; + float z = veSeat->m_attachmentOffsetZ; + Passenger->AddUnitMovementFlag(MOVEMENTFLAG_ONTRANSPORT); - Passenger->m_movementInfo.transport.pos.Relocate(veSeat->m_attachmentOffsetX, veSeat->m_attachmentOffsetY, veSeat->m_attachmentOffsetZ); + Passenger->m_movementInfo.transport.pos.Relocate(x, y, z, o); Passenger->m_movementInfo.transport.time = 0; Passenger->m_movementInfo.transport.seat = Seat->first; Passenger->m_movementInfo.transport.guid = Target->GetBase()->GetGUID(); @@ -851,8 +881,8 @@ bool VehicleJoinEvent::Execute(uint64, uint32) Movement::MoveSplineInit init(Passenger); init.DisableTransportPathTransformations(); - init.MoveTo(veSeat->m_attachmentOffsetX, veSeat->m_attachmentOffsetY, veSeat->m_attachmentOffsetZ, false, true); - init.SetFacing(0.0f); + init.MoveTo(x, y, z, false, true); + init.SetFacing(o); init.SetTransportEnter(); Passenger->GetMotionMaster()->LaunchMoveSpline(std::move(init), EVENT_VEHICLE_BOARD, MOTION_PRIORITY_HIGHEST); diff --git a/src/server/game/Entities/Vehicle/Vehicle.h b/src/server/game/Entities/Vehicle/Vehicle.h index b13444b4a8f..b3d3650a787 100644 --- a/src/server/game/Entities/Vehicle/Vehicle.h +++ b/src/server/game/Entities/Vehicle/Vehicle.h @@ -52,6 +52,7 @@ class TC_GAME_API Vehicle : public TransportBase bool HasEmptySeat(int8 seatId) const; Unit* GetPassenger(int8 seatId) const; SeatMap::const_iterator GetNextEmptySeat(int8 seatId, bool next) const; + VehicleSeatAddon const* GetSeatAddonForSeatOfPassenger(Unit const* passenger) const; uint8 GetAvailableSeatCount() const; bool AddPassenger(Unit* passenger, int8 seatId = -1); diff --git a/src/server/game/Entities/Vehicle/VehicleDefines.h b/src/server/game/Entities/Vehicle/VehicleDefines.h index ddac5210142..9fed8fdb131 100644 --- a/src/server/game/Entities/Vehicle/VehicleDefines.h +++ b/src/server/game/Entities/Vehicle/VehicleDefines.h @@ -53,6 +53,14 @@ enum VehicleSpells VEHICLE_SPELL_PARACHUTE = 45472 }; +enum class VehicleExitParameters +{ + VehicleExitParamNone = 0, // provided parameters will be ignored + VehicleExitParamOffset = 1, // provided parameters will be used as offset values + VehicleExitParamDest = 2, // provided parameters will be used as absolute destination + VehicleExitParamMax +}; + struct PassengerInfo { ObjectGuid Guid; @@ -65,9 +73,24 @@ struct PassengerInfo } }; +struct VehicleSeatAddon +{ + VehicleSeatAddon() { } + VehicleSeatAddon(float orientatonOffset, float exitX, float exitY, float exitZ, float exitO, uint8 param) : + SeatOrientationOffset(orientatonOffset), ExitParameterX(exitX), ExitParameterY(exitY), ExitParameterZ(exitZ), + ExitParameterO(exitO), ExitParameter(VehicleExitParameters(param)) { } + + float SeatOrientationOffset = 0.f; + float ExitParameterX = 0.f; + float ExitParameterY = 0.f; + float ExitParameterZ = 0.f; + float ExitParameterO = 0.f; + VehicleExitParameters ExitParameter = VehicleExitParameters::VehicleExitParamNone; +}; + struct VehicleSeat { - explicit VehicleSeat(VehicleSeatEntry const* seatInfo) : SeatInfo(seatInfo) + explicit VehicleSeat(VehicleSeatEntry const* seatInfo, VehicleSeatAddon const* seatAddon) : SeatInfo(seatInfo), SeatAddon(seatAddon) { Passenger.Reset(); } @@ -75,6 +98,7 @@ struct VehicleSeat bool IsEmpty() const { return Passenger.Guid.IsEmpty(); } VehicleSeatEntry const* SeatInfo; + VehicleSeatAddon const* SeatAddon; PassengerInfo Passenger; }; diff --git a/src/server/game/Globals/ObjectMgr.cpp b/src/server/game/Globals/ObjectMgr.cpp index f89ea0564ef..21f4731fdf4 100644 --- a/src/server/game/Globals/ObjectMgr.cpp +++ b/src/server/game/Globals/ObjectMgr.cpp @@ -3614,6 +3614,62 @@ void ObjectMgr::LoadVehicleAccessories() TC_LOG_INFO("server.loading", ">> Loaded %u Vehicle Accessories in %u ms", count, GetMSTimeDiffToNow(oldMSTime)); } +void ObjectMgr::LoadVehicleSeatAddon() +{ + uint32 oldMSTime = getMSTime(); + + _vehicleSeatAddonStore.clear(); // needed for reload case + + uint32 count = 0; + + // 0 1 2 3 4 5 6 + QueryResult result = WorldDatabase.Query("SELECT `SeatEntry`, `SeatOrientation`, `ExitParamX`, `ExitParamY`, `ExitParamZ`, `ExitParamO`, `ExitParamValue` FROM `vehicle_seat_addon`"); + + if (!result) + { + TC_LOG_ERROR("server.loading", ">> Loaded 0 vehicle seat addons. DB table `vehicle_seat_addon` is empty."); + return; + } + + do + { + Field* fields = result->Fetch(); + + uint32 seatID = fields[0].GetUInt32(); + float orientation = fields[1].GetFloat(); + float exitX = fields[2].GetFloat(); + float exitY = fields[3].GetFloat(); + float exitZ = fields[4].GetFloat(); + float exitO = fields[5].GetFloat(); + uint8 exitParam = fields[6].GetUInt8(); + + if (!sVehicleSeatStore.LookupEntry(seatID)) + { + TC_LOG_ERROR("sql.sql", "Table `vehicle_seat_addon`: SeatID: %u does not exist in VehicleSeat.dbc. Skipping entry.", seatID); + continue; + } + + // Sanitizing values + if (orientation > float(M_PI * 2)) + { + TC_LOG_ERROR("sql.sql", "Table `vehicle_seat_addon`: SeatID: %u is using invalid angle offset value (%f). Set Value to 0.", seatID, orientation); + orientation = 0.0f; + } + + if (exitParam >= AsUnderlyingType(VehicleExitParameters::VehicleExitParamMax)) + { + TC_LOG_ERROR("sql.sql", "Table `vehicle_seat_addon`: SeatID: %u is using invalid exit parameter value (%u). Setting to 0 (none).", seatID, exitParam); + continue; + } + + _vehicleSeatAddonStore[seatID] = VehicleSeatAddon(orientation, exitX, exitY, exitZ, exitO, exitParam); + + ++count; + } while (result->NextRow()); + + TC_LOG_INFO("server.loading", ">> Loaded %u Vehicle Seat Addon entries in %u ms", count, GetMSTimeDiffToNow(oldMSTime)); +} + void ObjectMgr::LoadPetLevelInfo() { uint32 oldMSTime = getMSTime(); diff --git a/src/server/game/Globals/ObjectMgr.h b/src/server/game/Globals/ObjectMgr.h index 8f8c33962a2..b66d2f24ec8 100644 --- a/src/server/game/Globals/ObjectMgr.h +++ b/src/server/game/Globals/ObjectMgr.h @@ -564,6 +564,7 @@ typedef std::unordered_map<uint32, QuestOfferRewardLocale> QuestOfferRewardLocal typedef std::unordered_map<uint32, QuestRequestItemsLocale> QuestRequestItemsLocaleContainer; typedef std::unordered_map<uint32, NpcTextLocale> NpcTextLocaleContainer; typedef std::unordered_map<uint32, PageTextLocale> PageTextLocaleContainer; +typedef std::unordered_map<uint32, VehicleSeatAddon> VehicleSeatAddonContainer; struct GossipMenuItemsLocale { @@ -1195,6 +1196,7 @@ class TC_GAME_API ObjectMgr void LoadMailLevelRewards(); void LoadVehicleTemplateAccessories(); void LoadVehicleAccessories(); + void LoadVehicleSeatAddon(); void LoadGossipText(); @@ -1555,6 +1557,15 @@ class TC_GAME_API ObjectMgr bool IsTransportMap(uint32 mapId) const { return _transportMaps.count(mapId) != 0; } + VehicleSeatAddon const* GetVehicleSeatAddon(uint32 seatId) const + { + VehicleSeatAddonContainer::const_iterator itr = _vehicleSeatAddonStore.find(seatId); + if (itr == _vehicleSeatAddonStore.end()) + return nullptr; + + return &itr->second; + } + private: // first free id for selected id type uint32 _auctionId; @@ -1716,6 +1727,7 @@ class TC_GAME_API ObjectMgr std::set<uint32> _transportMaps; // Helper container storing map ids that are for transports only, loaded from gameobject_template PlayerTotemModelMap _playerTotemModel; + VehicleSeatAddonContainer _vehicleSeatAddonStore; }; #define sObjectMgr ObjectMgr::instance() diff --git a/src/server/game/World/World.cpp b/src/server/game/World/World.cpp index 1e771937422..32ed92267ee 100644 --- a/src/server/game/World/World.cpp +++ b/src/server/game/World/World.cpp @@ -1852,6 +1852,9 @@ void World::SetInitialWorldSettings() TC_LOG_INFO("server.loading", "Loading Vehicle Accessories..."); sObjectMgr->LoadVehicleAccessories(); // must be after LoadCreatureTemplates() and LoadNPCSpellClickSpells() + TC_LOG_INFO("server.loading", "Loading Vehicle Seat Addon Data..."); + sObjectMgr->LoadVehicleSeatAddon(); // must be after loading DBC + TC_LOG_INFO("server.loading", "Loading SpellArea Data..."); // must be after quest load sSpellMgr->LoadSpellAreas(); diff --git a/src/server/scripts/World/npcs_special.cpp b/src/server/scripts/World/npcs_special.cpp index b035dc7f304..128a76acf1d 100644 --- a/src/server/scripts/World/npcs_special.cpp +++ b/src/server/scripts/World/npcs_special.cpp @@ -2880,40 +2880,6 @@ public: } }; -enum TravelerTundraMammothNPCs -{ - NPC_HAKMUD_OF_ARGUS = 32638, - NPC_GNIMO = 32639, - NPC_DRIX_BLACKWRENCH = 32641, - NPC_MOJODISHU = 32642 -}; - -class npc_traveler_tundra_mammoth_exit_pos : public UnitScript -{ -public: - npc_traveler_tundra_mammoth_exit_pos() : UnitScript("npc_traveler_tundra_mammoth_exit_pos") { } - - void ModifyVehiclePassengerExitPos(Unit* passenger, Vehicle* /*vehicle*/, Position& pos) - { - if (passenger->GetTypeId() == TYPEID_UNIT) - { - switch (passenger->GetEntry()) - { - // Right side - case NPC_DRIX_BLACKWRENCH: - case NPC_GNIMO: - pos.RelocateOffset({ -2.0f, -2.0f, 0.0f, 0.0f }); - break; - // Left side - case NPC_MOJODISHU: - case NPC_HAKMUD_OF_ARGUS: - pos.RelocateOffset({ -2.0f, 2.0f, 0.0f, 0.0f }); - break; - } - } - } -}; - void AddSC_npcs_special() { new npc_air_force_bots(); @@ -2941,5 +2907,4 @@ void AddSC_npcs_special() new npc_train_wrecker(); new npc_argent_squire_gruntling(); new npc_bountiful_table(); - new npc_traveler_tundra_mammoth_exit_pos(); } |
