Skip to content

Commit

Permalink
[14059] Vehicle: Implement vehicle seat exit customization
Browse files Browse the repository at this point in the history
  • Loading branch information
killerwife committed May 18, 2022
1 parent 418d7a1 commit aa6e3b9
Show file tree
Hide file tree
Showing 10 changed files with 144 additions and 6 deletions.
16 changes: 14 additions & 2 deletions sql/base/mangos.sql
Expand Up @@ -24,7 +24,7 @@ CREATE TABLE `db_version` (
`version` varchar(120) DEFAULT NULL,
`creature_ai_version` varchar(120) DEFAULT NULL,
`cache_id` int(10) DEFAULT '0',
`required_14058_01_mangos_quest_maxlevel` bit(1) DEFAULT NULL
`required_14059_01_mangos_vehicle_seat_accessory` bit(1) DEFAULT NULL
) ENGINE=MyISAM DEFAULT CHARSET=utf8 ROW_FORMAT=DYNAMIC COMMENT='Used DB version notes';

--
Expand Down Expand Up @@ -5496,7 +5496,7 @@ DROP TABLE IF EXISTS `npc_spellclick_spells`;
CREATE TABLE `npc_spellclick_spells` (
`npc_entry` int(10) unsigned NOT NULL COMMENT 'reference to creature_template',
`spell_id` int(10) unsigned NOT NULL COMMENT 'spell which should be casted ',
`quest_start` mediumint(8) unsigned NOT NULL COMMENT 'reference to quest_template',
`quest_start` mediumint(8) unsigned NOT NULL DEFAULT '0' COMMENT 'reference to quest_template',
`quest_start_active` tinyint(1) unsigned NOT NULL DEFAULT '0',
`quest_end` mediumint(8) unsigned NOT NULL DEFAULT '0',
`cast_flags` tinyint(3) unsigned NOT NULL COMMENT 'first bit defines caster: 1=player, 0=creature; second bit defines target, same mapping as caster bit',
Expand Down Expand Up @@ -20059,6 +20059,18 @@ LOCK TABLES `vehicle_accessory` WRITE;
/*!40000 ALTER TABLE `vehicle_accessory` ENABLE KEYS */;
UNLOCK TABLES;

DROP TABLE IF EXISTS vehicle_seat_addon;
CREATE TABLE vehicle_seat_addon(
`SeatEntry` INT(11) UNSIGNED NOT NULL,
`SeatOrientation` FLOAT NOT NULL DEFAULT 0,
`ExitParamX` FLOAT NOT NULL DEFAULT 0,
`ExitParamY` FLOAT NOT NULL DEFAULT 0,
`ExitParamZ` FLOAT NOT NULL DEFAULT 0,
`ExitParamO` FLOAT NOT NULL DEFAULT 0,
`ExitParamValue` TINYINT(1) NOT NULL DEFAULT 0,
PRIMARY KEY(`SeatEntry`)
);

--
-- Table structure for table `waypoint_path`
--
Expand Down
17 changes: 17 additions & 0 deletions sql/updates/mangos/14059_01_mangos_vehicle_seat_accessory.sql
@@ -0,0 +1,17 @@
ALTER TABLE db_version CHANGE COLUMN required_14058_01_mangos_quest_maxlevel required_14059_01_mangos_vehicle_seat_accessory bit;

DROP TABLE IF EXISTS vehicle_seat_addon;
CREATE TABLE vehicle_seat_addon(
`SeatEntry` INT(11) UNSIGNED NOT NULL,
`SeatOrientation` FLOAT NOT NULL DEFAULT 0,
`ExitParamX` FLOAT NOT NULL DEFAULT 0,
`ExitParamY` FLOAT NOT NULL DEFAULT 0,
`ExitParamZ` FLOAT NOT NULL DEFAULT 0,
`ExitParamO` FLOAT NOT NULL DEFAULT 0,
`ExitParamValue` TINYINT(1) NOT NULL DEFAULT 0,
PRIMARY KEY(`SeatEntry`)
);

ALTER TABLE npc_spellclick_spells MODIFY `quest_start` MEDIUMINT(7) UNSIGNED NOT NULL DEFAULT '0';


8 changes: 8 additions & 0 deletions src/game/Entities/Object.cpp
Expand Up @@ -3201,6 +3201,14 @@ float Position::GetDistance(Position const& other) const
return distsq;
}

void Position::RelocateOffset(Position const& offset)
{
x = GetPositionX() + (offset.GetPositionX() * std::cos(GetPositionO()) + offset.GetPositionY() * std::sin(GetPositionO() + float(M_PI)));
y = GetPositionY() + (offset.GetPositionY() * std::cos(GetPositionO()) + offset.GetPositionX() * std::sin(GetPositionO()));
z = GetPositionZ() + offset.GetPositionZ();
o = GetPositionO() + offset.GetPositionO();
}

std::string Position::to_string() const
{
return "X: " + std::to_string(x) + " Y: " + std::to_string(y) + " Z: " + std::to_string(z) + " O: " + std::to_string(o);
Expand Down
1 change: 1 addition & 0 deletions src/game/Entities/Object.h
Expand Up @@ -339,6 +339,7 @@ struct Position
bool IsEmpty() const { return x == 0.f && y == 0.f && z == 0.f; }
float GetAngle(const float x, const float y) const;
float GetDistance(Position const& other) const; // WARNING: Returns squared distance for performance reasons
void RelocateOffset(Position const& offset);
std::string to_string() const;
};

Expand Down
70 changes: 67 additions & 3 deletions src/game/Entities/Vehicle.cpp
Expand Up @@ -75,6 +75,52 @@ void ObjectMgr::LoadVehicleAccessory()
sLog.outString();
}

void ObjectMgr::LoadVehicleSeatParameters()
{
std::unique_ptr<QueryResult> result(WorldDatabase.Query("SELECT SeatEntry, SeatOrientation, ExitParamX, ExitParamY, ExitParamZ, ExitParamO, ExitParamValue FROM vehicle_seat_addon"));
if (!result)
{
BarGoLink bar(1);

bar.step();

sLog.outString(">> Loaded `vehicle_seat_addon`, table is empty!");
sLog.outString();
return;
}

BarGoLink bar(result->GetRowCount());

uint32 count = 0;
do
{
bar.step();
Field* fields = result->Fetch();

VehicleSeatParameters params;
params.seatEntry = fields[0].GetUInt32();
params.seatOrientation = fields[1].GetFloat();
params.exitParamX = fields[2].GetFloat();
params.exitParamY = fields[3].GetFloat();
params.exitParamZ = fields[4].GetFloat();
params.exitParamO = fields[5].GetFloat();
params.exitParamValue = fields[6].GetUInt8();

if (!sVehicleSeatStore.LookupEntry(params.seatEntry))
{
sLog.outErrorDb("Table `vehicle_seat_addon` has nonexistent seat %u entry, ignore. ", params.seatEntry);
continue;
}

m_seatParameters.emplace(params.seatEntry, params);

++count;
} while (result->NextRow());

sLog.outString(">> Loaded %u vehicle seat parameters.", count);
sLog.outString();
}

/**
* Constructor of VehicleInfo
*
Expand Down Expand Up @@ -376,9 +422,27 @@ void VehicleInfo::UnBoard(Unit* passenger, bool changeVehicle)
passenger->SetImmobilizedState(false);

Movement::MoveSplineInit init(*passenger);
// ToDo: Set proper unboard coordinates
Position pos = m_owner->GetPosition(m_owner->GetTransport());
init.MoveTo(pos.x, pos.y, pos.z);

Position exitPos = m_owner->GetPosition();
exitPos.o = passenger->GetOrientation();

if (VehicleSeatParameters const* params = sObjectMgr.GetVehicleSeatParameters(seatEntry->m_ID))
{
if (params->exitParamValue == SEAT_EXIT_PARAMS_OFFSET)
{
exitPos.RelocateOffset(Position(params->exitParamX, params->exitParamY, params->exitParamZ, params->exitParamO));
}
else if (params->exitParamValue == SEAT_EXIT_PARAMS_ABSOLUTE_POS)
{
exitPos.x = params->exitParamX;
exitPos.y = params->exitParamY;
exitPos.z = params->exitParamZ;
exitPos.o = params->exitParamZ;
}
}

init.MoveTo(exitPos.x, exitPos.y, exitPos.z);
init.SetFacing(exitPos.o);
init.SetExitVehicle();
init.Launch();

Expand Down
17 changes: 17 additions & 0 deletions src/game/Entities/Vehicle.h
Expand Up @@ -51,6 +51,23 @@ struct VehicleAccessory
uint32 passengerEntry;
};

enum ExitParamType
{
SEAT_EXIT_PARAMS_OFFSET = 1,
SEAT_EXIT_PARAMS_ABSOLUTE_POS = 2,
};

struct VehicleSeatParameters
{
uint32 seatEntry;
float seatOrientation;
float exitParamX;
float exitParamY;
float exitParamZ;
float exitParamO;
float exitParamValue;
};

typedef std::map<uint8 /*seatPosition*/, VehicleSeatEntry const*> VehicleSeatMap;

/**
Expand Down
9 changes: 9 additions & 0 deletions src/game/Globals/ObjectMgr.cpp
Expand Up @@ -986,6 +986,15 @@ std::vector<std::pair<TypeID, uint32>> const& ObjectMgr::GetDbGuidsForTransport(
return (*m_guidsForMap.find(mapId)).second;
}

VehicleSeatParameters const* ObjectMgr::GetVehicleSeatParameters(uint32 seatEntry) const
{
auto itr = m_seatParameters.find(seatEntry);
if (itr == m_seatParameters.end())
return nullptr;

return &itr->second;
}

CreatureImmunityVector const* ObjectMgr::GetCreatureImmunitySet(uint32 entry, uint32 setId) const
{
auto itr = m_creatureImmunities.find(entry);
Expand Down
7 changes: 7 additions & 0 deletions src/game/Globals/ObjectMgr.h
Expand Up @@ -35,6 +35,7 @@
#include "Entities/ObjectGuid.h"
#include "Globals/Conditions.h"
#include "Maps/SpawnGroupDefines.h"
#include "Entities/Vehicle.h"

#include <map>
#include <climits>
Expand Down Expand Up @@ -803,6 +804,7 @@ class ObjectMgr
void LoadActiveEntities(Map* _map);

void LoadVehicleAccessory();
void LoadVehicleSeatParameters();

std::string GeneratePetName(uint32 entry);
uint32 GetBaseXP(uint32 level) const;
Expand Down Expand Up @@ -1260,6 +1262,9 @@ class ObjectMgr

// Transports
std::vector<std::pair<TypeID, uint32>> const& GetDbGuidsForTransport(uint32 mapId) const;

// Vehicles
VehicleSeatParameters const* GetVehicleSeatParameters(uint32 seatEntry) const;
protected:

// current locale settings
Expand Down Expand Up @@ -1433,6 +1438,8 @@ class ObjectMgr

std::map<uint32, uint32> m_transportMaps;
std::map<uint32, std::vector<std::pair<TypeID, uint32>>> m_guidsForMap; // used for transports only atm

std::map<uint32, VehicleSeatParameters> m_seatParameters;
};

#define sObjectMgr MaNGOS::Singleton<ObjectMgr>::Instance()
Expand Down
3 changes: 3 additions & 0 deletions src/game/World/World.cpp
Expand Up @@ -1087,6 +1087,9 @@ void World::SetInitialWorldSettings()
sLog.outString("Loading Vehicle Accessory..."); // must be after LoadCreatureTemplates
sObjectMgr.LoadVehicleAccessory();

sLog.outString("Loading Vehicle Seat Parameters..."); // must be after dbc load
sObjectMgr.LoadVehicleSeatParameters();

sLog.outString("Loading ItemRequiredTarget...");
sObjectMgr.LoadItemRequiredTarget();

Expand Down
2 changes: 1 addition & 1 deletion src/shared/revision_sql.h
Expand Up @@ -3,5 +3,5 @@
#define REVISION_DB_REALMD "required_14039_01_realmd_anticheat"
#define REVISION_DB_LOGS "required_14039_01_logs_anticheat"
#define REVISION_DB_CHARACTERS "required_14044_01_characters_extend_state"
#define REVISION_DB_MANGOS "required_14058_01_mangos_quest_maxlevel"
#define REVISION_DB_MANGOS "required_14059_01_mangos_vehicle_seat_accessory"
#endif // __REVISION_SQL_H__

0 comments on commit aa6e3b9

Please sign in to comment.