Possessor and possessable additions (#619)

* possessor-fixup and possessable additions

* comment and docstring fixes

* fix possessable initialization

* split animation flags into it's own header
remove unnecessary checks
This commit is contained in:
Aaron Kimbrell
2022-07-08 22:25:15 -05:00
committed by GitHub
parent 22b2516107
commit 3865a186a7
8 changed files with 178 additions and 89 deletions

View File

@@ -208,8 +208,9 @@ void Entity::Initialize()
m_Components.insert(std::make_pair(COMPONENT_TYPE_ZONE_CONTROL, nullptr));
}
if (compRegistryTable->GetByIDAndType(m_TemplateID, COMPONENT_TYPE_POSSESSABLE) > 0) {
m_Components.insert(std::make_pair(COMPONENT_TYPE_POSSESSABLE, new PossessableComponent(this)));
uint32_t possessableComponentId = compRegistryTable->GetByIDAndType(m_TemplateID, COMPONENT_TYPE_POSSESSABLE);
if (possessableComponentId > 0) {
m_Components.insert(std::make_pair(COMPONENT_TYPE_POSSESSABLE, new PossessableComponent(this, possessableComponentId)));
}
if (compRegistryTable->GetByIDAndType(m_TemplateID, COMPONENT_TYPE_MODULE_ASSEMBLY) > 0) {

View File

@@ -1,51 +1,43 @@
#include "PossessableComponent.h"
#include "PossessorComponent.h"
#include "EntityManager.h"
#include "Item.h"
PossessableComponent::PossessableComponent(Entity* parent) : Component(parent)
{
m_Possessor = LWOOBJID_EMPTY;
PossessableComponent::PossessableComponent(Entity* parent, uint32_t componentId) : Component(parent){
m_Possessor = LWOOBJID_EMPTY;
// Get the possession Type from the CDClient
auto query = CDClientDatabase::CreatePreppedStmt("SELECT possessionType, depossessOnHit FROM PossessableComponent WHERE id = ?;");
query.bind(1, static_cast<int>(componentId));
auto result = query.execQuery();
// Should a result not exist for this default to attached visible
if (!result.eof()) {
m_PossessionType = static_cast<ePossessionType>(result.getIntField(0, 0));
m_DepossessOnHit = static_cast<bool>(result.getIntField(1, 0));
} else {
m_PossessionType = ePossessionType::ATTACHED_VISIBLE;
m_DepossessOnHit = false;
}
result.finalize();
}
PossessableComponent::~PossessableComponent()
{
}
void PossessableComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags) {
outBitStream->Write(m_DirtyPossessable || bIsInitialUpdate);
if (m_DirtyPossessable || bIsInitialUpdate) {
m_DirtyPossessable = false;
outBitStream->Write(m_Possessor != LWOOBJID_EMPTY);
if (m_Possessor != LWOOBJID_EMPTY) outBitStream->Write(m_Possessor);
void PossessableComponent::SetPossessor(LWOOBJID value)
{
m_Possessor = value;
}
outBitStream->Write(m_AnimationFlag != eAnimationFlags::IDLE_INVALID);
if(m_AnimationFlag != eAnimationFlags::IDLE_INVALID) outBitStream->Write(m_AnimationFlag);
LWOOBJID PossessableComponent::GetPossessor() const
{
return m_Possessor;
}
void PossessableComponent::Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags)
{
outBitStream->Write(m_Possessor != LWOOBJID_EMPTY);
if (m_Possessor != LWOOBJID_EMPTY)
{
outBitStream->Write1();
outBitStream->Write(m_Possessor);
outBitStream->Write0();
outBitStream->Write0();
}
}
void PossessableComponent::Update(float deltaTime)
{
outBitStream->Write(m_ImmediatelyDepossess);
}
}
void PossessableComponent::OnUse(Entity* originator) {
PossessorComponent* possessorComponent;
if (originator->TryGetComponent(COMPONENT_TYPE_POSSESSOR, possessorComponent)) {
SetPossessor(originator->GetObjectID());
possessorComponent->SetPossessable(m_Parent->GetObjectID());
EntityManager::Instance()->SerializeEntity(m_Parent);
EntityManager::Instance()->SerializeEntity(originator);
}
}
// TODO: Implement this
}

View File

@@ -3,44 +3,96 @@
#include "BitStream.h"
#include "Entity.h"
#include "Component.h"
#include "Item.h"
#include "PossessorComponent.h"
#include "eAninmationFlags.h"
/**
* Represents an entity that can be controlled by some other entity, generally used by cars to indicate that some
* player is controlling it.
*/
class PossessableComponent : public Component {
public:
static const uint32_t ComponentType = COMPONENT_TYPE_POSSESSABLE;
PossessableComponent(Entity* parentEntity);
~PossessableComponent() override;
public:
static const uint32_t ComponentType = COMPONENT_TYPE_POSSESSABLE;
void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags);
void Update(float deltaTime) override;
PossessableComponent(Entity* parentEntity, uint32_t componentId);
/**
* Sets the possessor of this entity
* @param value the ID of the possessor to set
*/
void SetPossessor(LWOOBJID value);
void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags);
/**
* Returns the possessor of this entity
* @return the possessor of this entitythe
*/
LWOOBJID GetPossessor() const;
/**
* Sets the possessor of this entity
* @param value the ID of the possessor to set
*/
void SetPossessor(LWOOBJID value) { m_Possessor = value; m_DirtyPossessable = true;};
/**
* Handles an OnUsed event by some other entity, if said entity has a PossessorComponent it becomes the possessor
* of this entity
* @param originator the entity that caused the event to trigger
*/
void OnUse(Entity* originator) override;
/**
* Returns the possessor of this entity
* @return the possessor of this entity
*/
LWOOBJID GetPossessor() const { return m_Possessor; };
private:
/**
* Sets the animation Flag of the possessable
* @param value the animation flag to set to
*/
void SetAnimationFlag(eAnimationFlags value) { m_AnimationFlag = value; m_DirtyPossessable = true;};
/**
* Returns the possession type of this entity
* @return the possession type of this entity
*/
ePossessionType GetPossessionType() const { return m_PossessionType; };
/**
* Returns if the entity should deposses on hit
* @return if the entity should deposses on hit
*/
bool GetDepossessOnHit() const { return m_DepossessOnHit; };
/**
* Forcibly depossess the entity
*/
void ForceDepossess() { m_ImmediatelyDepossess = true; m_DirtyPossessable = true;};
/**
* Handles an OnUsed event by some other entity, if said entity has a Possessor it becomes the possessor
* of this entity
* @param originator the entity that caused the event to trigger
*/
void OnUse(Entity* originator) override;
private:
/**
* @brief Whether the possessor is dirty
*/
bool m_DirtyPossessable = true;
/**
* @brief The possessor of this entity, e.g. the entity that controls this entity
*/
LWOOBJID m_Possessor = LWOOBJID_EMPTY;
/**
* @brief The type of possesstion to use on this entity
*/
ePossessionType m_PossessionType = ePossessionType::NO_POSSESSION;
/**
* @brief Should the possessable be dismount on hit
*/
bool m_DepossessOnHit = false;
/**
* @brief What animaiton flag to use
*
*/
eAnimationFlags m_AnimationFlag = eAnimationFlags::IDLE_INVALID;
/**
* @brief Should this be immediately depossessed
*
*/
bool m_ImmediatelyDepossess = false;
/**
* The possessor of this entity, e.g. the entity that controls this entity
*/
LWOOBJID m_Possessor;
};

View File

@@ -4,6 +4,14 @@
#include "Entity.h"
#include "Component.h"
// possession types
enum class ePossessionType : uint8_t {
NO_POSSESSION = 0,
ATTACHED_VISIBLE,
NOT_ATTACHED_VISIBLE,
NOT_ATTACHED_NOT_VISIBLE,
};
/**
* Represents an entity that can posess other entities. Generally used by players to drive a car.
*/
@@ -22,34 +30,34 @@ class PossessorComponent : public Component {
*/
void SetPossessable(LWOOBJID value) { m_Possessable = value; m_DirtyPossesor = true; }
/**
* 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; }
/**
* Returns the entity that this entity is currently posessing
* @return the entity that this entity is currently posessing
*/
LWOOBJID GetPossessable() const { return m_Possessable; }
/**
* 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(ePossessionType value) { m_PossessableType = value; m_DirtyPossesor = true; }
private:
/**
* The ID of the entity this entity is possessing (e.g. the ID of a car)
*/
LWOOBJID m_Possessable;
LWOOBJID m_Possessable = LWOOBJID_EMPTY;
/**
* @brief possessable type
*
*/
uint8_t m_PossessableType;
ePossessionType m_PossessableType = ePossessionType::NO_POSSESSION;
/**
* @brief if the possessor is dirty
*
*/
bool m_DirtyPossesor;
bool m_DirtyPossesor = false;
};

View File

@@ -212,6 +212,7 @@ void RacingControlComponent::LoadPlayerVehicle(Entity *player,
if (possessorComponent != nullptr) {
possessorComponent->SetPossessable(carEntity->GetObjectID());
possessorComponent->SetPossessableType(ePossessionType::ATTACHED_VISIBLE); // for racing it's always Attached_Visible
}
// Set the player's current activity as racing.