diff --git a/dCommon/dCommonVars.h b/dCommon/dCommonVars.h index a52a1dc6..4cbdb61c 100644 --- a/dCommon/dCommonVars.h +++ b/dCommon/dCommonVars.h @@ -407,8 +407,8 @@ enum eReplicaComponentType : int32_t { COMPONENT_TYPE_MISSION = 84, //!< The Mission Component COMPONENT_TYPE_ROCKET_LAUNCH_LUP = 97, //!< The LUP Launchpad Componen COMPONENT_TYPE_RAIL_ACTIVATOR = 104, - COMPONENT_TYPE_POSSESSOR = 107, //!< The Component 107 - COMPONENT_TYPE_POSSESSABLE = 108, //!< The Component 108 + COMPONENT_TYPE_POSSESSABLE = 108, //!< The Possessable Component + COMPONENT_TYPE_POSSESSOR = 110, //!< The Possessor Component COMPONENT_TYPE_BUILD_BORDER = 114, //!< The Build Border Component COMPONENT_TYPE_DESTROYABLE = 1000, //!< The Destroyable Component diff --git a/dGame/Entity.cpp b/dGame/Entity.cpp index 01c1540b..bb7e0335 100644 --- a/dGame/Entity.cpp +++ b/dGame/Entity.cpp @@ -435,6 +435,8 @@ void Entity::Initialize() }*/ if (compRegistryTable->GetByIDAndType(m_TemplateID, COMPONENT_TYPE_CHARACTER) > 0 || m_Character) { + // Character Component always has a possessor component + m_Components.insert(std::make_pair(COMPONENT_TYPE_POSSESSOR, new PossessorComponent(this))); CharacterComponent* comp = new CharacterComponent(this, m_Character); m_Components.insert(std::make_pair(COMPONENT_TYPE_CHARACTER, comp)); } @@ -606,10 +608,6 @@ void Entity::Initialize() m_Components.insert(std::make_pair(COMPONENT_TYPE_RENDER, render)); } - if ((compRegistryTable->GetByIDAndType(m_TemplateID, COMPONENT_TYPE_POSSESSOR) > 0) || m_Character) { - m_Components.insert(std::make_pair(COMPONENT_TYPE_POSSESSOR, new PossessorComponent(this))); - } - if ((compRegistryTable->GetByIDAndType(m_TemplateID, COMPONENT_TYPE_MISSION_OFFER) > 0) || m_Character) { m_Components.insert(std::make_pair(COMPONENT_TYPE_MISSION_OFFER, new MissionOfferComponent(this, m_TemplateID))); } @@ -1057,8 +1055,15 @@ void Entity::WriteComponents(RakNet::BitStream* outBitStream, eReplicaPacketType } CharacterComponent* characterComponent; - if (TryGetComponent(COMPONENT_TYPE_CHARACTER, characterComponent)) - { + if (TryGetComponent(COMPONENT_TYPE_CHARACTER, characterComponent)) { + + PossessorComponent* possessorComponent; + if (TryGetComponent(COMPONENT_TYPE_POSSESSOR, possessorComponent)) { + possessorComponent->Serialize(outBitStream, bIsInitialUpdate, flags); + } else { + // Should never happen, but just to be safe + outBitStream->Write0(); + } characterComponent->Serialize(outBitStream, bIsInitialUpdate, flags); } @@ -1164,11 +1169,10 @@ void Entity::WriteComponents(RakNet::BitStream* outBitStream, eReplicaPacketType outBitStream->Write(0x40000000); } - PossessorComponent* possessorComponent; - if (TryGetComponent(COMPONENT_TYPE_POSSESSOR, possessorComponent)) - { - possessorComponent->Serialize(outBitStream, bIsInitialUpdate, flags); - } + // BBB Component, unused currently + // Need to to write0 so that is serlaizese correctly + // TODO: Implement BBB Component + outBitStream->Write0(); /* if (m_Trigger != nullptr) diff --git a/dGame/dComponents/CharacterComponent.cpp b/dGame/dComponents/CharacterComponent.cpp index f7941af8..14354cb5 100644 --- a/dGame/dComponents/CharacterComponent.cpp +++ b/dGame/dComponents/CharacterComponent.cpp @@ -10,7 +10,6 @@ #include "InventoryComponent.h" #include "ControllablePhysicsComponent.h" #include "EntityManager.h" -#include "PossessorComponent.h" #include "VehiclePhysicsComponent.h" #include "GameMessages.h" #include "Item.h" @@ -81,13 +80,6 @@ CharacterComponent::~CharacterComponent() { } void CharacterComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags) { - outBitStream->Write(m_IsRacing); - if (m_IsRacing) { - outBitStream->Write1(); - outBitStream->Write(m_VehicleObjectID); - outBitStream->Write(0); - } - outBitStream->Write1(); outBitStream->Write(m_Level); outBitStream->Write0(); diff --git a/dGame/dComponents/CharacterComponent.h b/dGame/dComponents/CharacterComponent.h index 99c8a098..2a0d860b 100644 --- a/dGame/dComponents/CharacterComponent.h +++ b/dGame/dComponents/CharacterComponent.h @@ -143,24 +143,6 @@ public: */ void SetIsRacing(bool isRacing) { m_IsRacing = isRacing; } - /** - * Gets the (optional) object ID of the vehicle the character is currently in - * @return the object ID of the vehilce the character is in - */ - const LWOOBJID GetVehicleObjectID() const { return m_VehicleObjectID; } - - /** - * Sets the (optional) object ID of the vehicle the character is currently in - * @param vehicleObjectID the ID of the vehicle the character is in - */ - void SetVehicleObjectID(LWOOBJID vehicleObjectID) { m_VehicleObjectID = vehicleObjectID; } - - /** - * Sets the possesible type that's currently used, merely used by the shooting gallery if it's 0 - * @param value the possesible type to set - */ - void SetPossessableType(uint8_t value) { m_PossessableType = value; } - /** * Gets whether this character has PvP enabled, allowing combat between players * @return @@ -304,11 +286,6 @@ private: */ bool m_IsRacing; - /** - * The object ID of the vehicle the character is currently in - */ - LWOOBJID m_VehicleObjectID; - /** * Possessible type, used by the shooting gallery */ diff --git a/dGame/dComponents/InventoryComponent.cpp b/dGame/dComponents/InventoryComponent.cpp index e47f5bb5..950536ab 100644 --- a/dGame/dComponents/InventoryComponent.cpp +++ b/dGame/dComponents/InventoryComponent.cpp @@ -986,19 +986,11 @@ void InventoryComponent::EquipItem(Item* item, const bool skipChecks) // #107 auto* possessorComponent = m_Parent->GetComponent(); - if (possessorComponent != nullptr) - { - previousPossessorID = possessorComponent->GetPossessable(); - possessorComponent->SetPossessable(carEntity->GetObjectID()); - } + if (possessorComponent) possessorComponent->SetPossessable(carEntity->GetObjectID()); auto* characterComponent = m_Parent->GetComponent(); - if (characterComponent != nullptr) - { - characterComponent->SetIsRacing(true); - characterComponent->SetVehicleObjectID(carEntity->GetObjectID()); - } + if (characterComponent) characterComponent->SetIsRacing(true); EntityManager::Instance()->ConstructEntity(carEntity); EntityManager::Instance()->SerializeEntity(m_Parent); diff --git a/dGame/dComponents/PossessorComponent.cpp b/dGame/dComponents/PossessorComponent.cpp index 4f532805..4ace324b 100644 --- a/dGame/dComponents/PossessorComponent.cpp +++ b/dGame/dComponents/PossessorComponent.cpp @@ -1,35 +1,21 @@ #include "PossessorComponent.h" -PossessorComponent::PossessorComponent(Entity* parent) : Component(parent) -{ - m_Possessable = LWOOBJID_EMPTY; +PossessorComponent::PossessorComponent(Entity* parent) : Component(parent) { + m_Possessable = LWOOBJID_EMPTY; } -PossessorComponent::~PossessorComponent() -{ - -} +PossessorComponent::~PossessorComponent() {} -void PossessorComponent::SetPossessable(LWOOBJID value) -{ - m_Possessable = value; -} -LWOOBJID PossessorComponent::GetPossessable() const -{ - return m_Possessable; -} -void PossessorComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags) -{ - outBitStream->Write(m_Possessable != LWOOBJID_EMPTY); - if (m_Possessable != LWOOBJID_EMPTY) - { - outBitStream->Write(m_Possessable); - } -} - -void PossessorComponent::Update(float deltaTime) -{ - +void PossessorComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags) { + outBitStream->Write(m_DirtyPossesor || bIsInitialUpdate); + if (m_DirtyPossesor || bIsInitialUpdate) { + m_DirtyPossesor = false; + outBitStream->Write(m_Possessable != LWOOBJID_EMPTY); + if (m_Possessable != LWOOBJID_EMPTY) { + outBitStream->Write(m_Possessable); + } + outBitStream->Write(m_PossessableType); + } } diff --git a/dGame/dComponents/PossessorComponent.h b/dGame/dComponents/PossessorComponent.h index 0c1a436e..f3389274 100644 --- a/dGame/dComponents/PossessorComponent.h +++ b/dGame/dComponents/PossessorComponent.h @@ -8,31 +8,48 @@ * Represents an entity that can posess other entities. Generally used by players to drive a car. */ class PossessorComponent : public Component { -public: - static const uint32_t ComponentType = COMPONENT_TYPE_POSSESSOR; - - PossessorComponent(Entity* parent); - ~PossessorComponent() override; + public: + static const uint32_t ComponentType = COMPONENT_TYPE_POSSESSOR; - void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags); - void Update(float deltaTime) override; + PossessorComponent(Entity* parent); + ~PossessorComponent() override; - /** - * Sets the entity that this entity is possessing - * @param value the ID of the entity this ID should posess - */ - void SetPossessable(LWOOBJID value); + void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags); - /** - * Returns the entity that this entity is currently posessing - * @return the entity that this entity is currently posessing - */ - LWOOBJID GetPossessable() const; + /** + * Sets the entity that this entity is possessing + * @param value the ID of the entity this ID should posess + */ + void SetPossessable(LWOOBJID value) { m_Possessable = value; m_DirtyPossesor = true; } -private: + /** + * Sets the possesible type that's currently used, merely used by the shooting gallery if it's 0 + * @param value the possesible type to set + */ + void SetPossessableType(uint8_t value) { m_PossessableType = value; m_DirtyPossesor = true; } - /** - * The ID of the entity this entity is possessing (e.g. the ID of a car) - */ - LWOOBJID m_Possessable; + /** + * Returns the entity that this entity is currently posessing + * @return the entity that this entity is currently posessing + */ + LWOOBJID GetPossessable() const { return m_Possessable; } + + private: + + /** + * The ID of the entity this entity is possessing (e.g. the ID of a car) + */ + LWOOBJID m_Possessable; + + /** + * @brief possessable type + * + */ + uint8_t m_PossessableType; + + /** + * @brief if the possessor is dirty + * + */ + bool m_DirtyPossesor; }; diff --git a/dGame/dComponents/RacingControlComponent.cpp b/dGame/dComponents/RacingControlComponent.cpp index 1d86b274..d8794114 100644 --- a/dGame/dComponents/RacingControlComponent.cpp +++ b/dGame/dComponents/RacingControlComponent.cpp @@ -219,7 +219,6 @@ void RacingControlComponent::LoadPlayerVehicle(Entity *player, if (characterComponent != nullptr) { characterComponent->SetIsRacing(true); - characterComponent->SetVehicleObjectID(carEntity->GetObjectID()); } // Init the player's racing entry. diff --git a/dScripts/SGCannon.cpp b/dScripts/SGCannon.cpp index 3912364c..2deacdde 100644 --- a/dScripts/SGCannon.cpp +++ b/dScripts/SGCannon.cpp @@ -107,9 +107,12 @@ void SGCannon::OnActivityStateChangeRequest(Entity *self, LWOOBJID senderID, int if (characterComponent != nullptr) { characterComponent->SetIsRacing(true); - characterComponent->SetVehicleObjectID(self->GetObjectID()); - characterComponent->SetPossessableType(0); characterComponent->SetCurrentActivity(2); + auto possessor = player->GetComponent(); + if(possessor) { + possessor->SetPossessable(self->GetObjectID()); + possessor->SetPossessableType(0); + } EntityManager::Instance()->SerializeEntity(player); }