Entity work

- Add in bool cheks
- Fix component class files so they compile and link
- Fin inheritance
This commit is contained in:
David Markowitz 2023-06-25 21:47:35 -07:00
parent fee1025982
commit 9121bf41c5
14 changed files with 327 additions and 308 deletions

View File

@ -1,5 +1,5 @@
#include "BaseRacingControlComponent.h" #include "BaseRacingControlComponent.h"
BaseRacingControlComponent::BaseRacingControlComponent(Entity* parent) : Component(parent) { BaseRacingControlComponent::BaseRacingControlComponent(Entity* parent, int32_t componentId) : ScriptedActivityComponent(parent, componentId) {
} }

View File

@ -9,7 +9,7 @@ class Entity;
class BaseRacingControlComponent : public ScriptedActivityComponent { class BaseRacingControlComponent : public ScriptedActivityComponent {
public: public:
inline static const eReplicaComponentType ComponentType = eReplicaComponentType::RACING_CONTROL; inline static const eReplicaComponentType ComponentType = eReplicaComponentType::RACING_CONTROL;
BaseRacingControlComponent(Entity* parent); BaseRacingControlComponent(Entity* parent, int32_t componentId);
}; };

View File

@ -11,6 +11,7 @@ set(DGAME_DCOMPONENTS_SOURCES "AchievementVendorComponent.cpp"
"ControllablePhysicsComponent.cpp" "ControllablePhysicsComponent.cpp"
"DestroyableComponent.cpp" "DestroyableComponent.cpp"
"DonationVendorComponent.cpp" "DonationVendorComponent.cpp"
"GateRushControlComponent.cpp"
"InventoryComponent.cpp" "InventoryComponent.cpp"
"ItemComponent.cpp" "ItemComponent.cpp"
"LevelProgressionComponent.cpp" "LevelProgressionComponent.cpp"

View File

@ -1,5 +1,5 @@
#include "GateRushControlComponent.h" #include "GateRushControlComponent.h"
GateRushControlComponent::GateRushControlComponent(Entity* parent) : BaseRacingControlComponent(parent) { GateRushControlComponent::GateRushControlComponent(Entity* parent, int32_t componentId) : BaseRacingControlComponent(parent, componentId) {
} }

View File

@ -9,7 +9,7 @@ class Entity;
class GateRushControlComponent : public BaseRacingControlComponent { class GateRushControlComponent : public BaseRacingControlComponent {
public: public:
inline static const eReplicaComponentType ComponentType = eReplicaComponentType::GATE_RUSH_CONTROL; inline static const eReplicaComponentType ComponentType = eReplicaComponentType::GATE_RUSH_CONTROL;
GateRushControlComponent(Entity* parent); GateRushControlComponent(Entity* parent, int32_t componentId);
}; };
#endif //!__GATERUSHCONTROLCOMPONENT__H__ #endif //!__GATERUSHCONTROLCOMPONENT__H__

View File

@ -4,12 +4,12 @@
ItemComponent::ItemComponent(Entity* parent) : Component(parent) { ItemComponent::ItemComponent(Entity* parent) : Component(parent) {
m_Parent = parent; m_ParentEntity = parent;
m_DirtyItemInfo = false; m_DirtyItemInfo = false;
m_UgId = m_Parent->GetVarAs<LWOOBJID>(u"userModelID"); m_UgId = m_ParentEntity->GetVarAs<LWOOBJID>(u"userModelID");
if (m_UgId == LWOOBJID_EMPTY) m_UgId = m_Parent->GetObjectID(); if (m_UgId == LWOOBJID_EMPTY) m_UgId = m_ParentEntity->GetObjectID();
m_UgModerationStatus = eUgcModerationStatus::NoStatus; m_UgModerationStatus = eUgcModerationStatus::NoStatus;

View File

@ -2,6 +2,6 @@
#include "Entity.h" #include "Entity.h"
MinigameControlComponent::MinigameControlComponent(Entity* parent) : Component(parent) { MinigameControlComponent::MinigameControlComponent(Entity* parent) : ActivityComponent(parent) {
} }

View File

@ -13,7 +13,7 @@ class Entity;
*/ */
class MutableModelBehaviorComponent : public Component { class MutableModelBehaviorComponent : public Component {
public: public:
static const eReplicaComponentType ComponentType = eReplicaComponentType::MODEL; static const eReplicaComponentType ComponentType = eReplicaComponentType::MODEL_BEHAVIOR;
MutableModelBehaviorComponent(Entity* parent); MutableModelBehaviorComponent(Entity* parent);

View File

@ -25,7 +25,7 @@
#include "CppScripts.h" #include "CppScripts.h"
QuickBuildComponent::QuickBuildComponent(Entity* entity, uint32_t componentId) : Component(entity) { QuickBuildComponent::QuickBuildComponent(Entity* entity, uint32_t componentId) : ActivityComponent(entity) {
m_ComponentId = componentId; m_ComponentId = componentId;
std::u16string checkPreconditions = entity->GetVar<std::u16string>(u"CheckPrecondition"); std::u16string checkPreconditions = entity->GetVar<std::u16string>(u"CheckPrecondition");

View File

@ -29,7 +29,7 @@
#define M_PI 3.14159265358979323846264338327950288 #define M_PI 3.14159265358979323846264338327950288
#endif #endif
RacingControlComponent::RacingControlComponent(Entity* parent) : BaseRacingControlComponent(parent) { RacingControlComponent::RacingControlComponent(Entity* parent, int32_t componentId) : BaseRacingControlComponent(parent, componentId) {
m_PathName = u"MainPath"; m_PathName = u"MainPath";
m_RemainingLaps = 3; m_RemainingLaps = 3;
m_LeadingPlayer = LWOOBJID_EMPTY; m_LeadingPlayer = LWOOBJID_EMPTY;

View File

@ -107,7 +107,7 @@ class RacingControlComponent : public BaseRacingControlComponent {
public: public:
inline static const eReplicaComponentType ComponentType = eReplicaComponentType::RACING_CONTROL; inline static const eReplicaComponentType ComponentType = eReplicaComponentType::RACING_CONTROL;
RacingControlComponent(Entity* parentEntity); RacingControlComponent(Entity* parentEntity, int32_t componentId);
~RacingControlComponent(); ~RacingControlComponent();
void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags); void Serialize(RakNet::BitStream* outBitStream, bool bIsInitialUpdate, unsigned int& flags);

View File

@ -0,0 +1,5 @@
#include "RacingSoundTriggerComponent.h"
RacingSoundTriggerComponent::RacingSoundTriggerComponent(Entity* parent) : SoundTriggerComponent(parent) {
}

View File

@ -53,12 +53,6 @@ public:
m_DirtyVendor = true; m_DirtyVendor = true;
} }
/**
* Gets the list if items the vendor sells.
* @return the list of items.
*/
std::map<LOT, int>& GetInventory();
/** /**
* Refresh the inventory of this vendor. * Refresh the inventory of this vendor.
*/ */

View File

@ -226,9 +226,7 @@ void Entity::Initialize() {
bool hasProximityMonitorComponent = false; bool hasProximityMonitorComponent = false;
bool hasScriptComponent = false; bool hasScriptComponent = false;
bool hasDroppedLootComponent = false; bool hasDroppedLootComponent = false;
bool hasModelBehaviors = false;
uint32_t physicsComponentID = -1; uint32_t physicsComponentID = -1;
uint32_t modelType = -1;
// A few edge cases to tackle first // A few edge cases to tackle first
const auto triggerInfo = GetVarAsString(u"trigger_id"); const auto triggerInfo = GetVarAsString(u"trigger_id");
@ -251,14 +249,18 @@ void Entity::Initialize() {
for (const auto& [componentTemplate, componentId] : components) { for (const auto& [componentTemplate, componentId] : components) {
switch (componentTemplate) { switch (componentTemplate) {
case eReplicaComponentType::CONTROLLABLE_PHYSICS: case eReplicaComponentType::CONTROLLABLE_PHYSICS:
if (hasPhysicsComponent) continue;
AddComponent<ControllablePhysicsComponent>(); AddComponent<ControllablePhysicsComponent>();
physicsComponentID = componentId;
hasPhysicsComponent = true; hasPhysicsComponent = true;
break; break;
case eReplicaComponentType::RENDER: case eReplicaComponentType::RENDER:
AddComponent<RenderComponent>(); AddComponent<RenderComponent>();
break; break;
case eReplicaComponentType::SIMPLE_PHYSICS: case eReplicaComponentType::SIMPLE_PHYSICS:
if (hasPhysicsComponent) continue;
AddComponent<SimplePhysicsComponent>(componentId); AddComponent<SimplePhysicsComponent>(componentId);
physicsComponentID = componentId;
hasPhysicsComponent = true; hasPhysicsComponent = true;
break; break;
case eReplicaComponentType::CHARACTER: case eReplicaComponentType::CHARACTER:
@ -276,13 +278,16 @@ void Entity::Initialize() {
script = ScriptComponent::GetScriptName(this, componentId); script = ScriptComponent::GetScriptName(this, componentId);
} }
AddComponent<ScriptComponent>(script); // Technically this should check for if the script name is empty and not create a component if it is. AddComponent<ScriptComponent>(script); // Technically this should check for if the script name is empty and not create a component if it is.
hasScriptComponent = true;
break; break;
} }
case eReplicaComponentType::BOUNCER: case eReplicaComponentType::BOUNCER:
AddComponent<BouncerComponent>(); AddComponent<BouncerComponent>();
break; break;
case eReplicaComponentType::DESTROYABLE: case eReplicaComponentType::DESTROYABLE:
if (!HasComponent(eReplicaComponentType::DESTROYABLE)) AddComponent<DestroyableComponent>(componentId); if (hasDestroyableComponent) continue;
AddComponent<DestroyableComponent>(componentId);
hasDestroyableComponent = true;
break; break;
case eReplicaComponentType::SKILL: case eReplicaComponentType::SKILL:
AddComponent<SkillComponent>(); AddComponent<SkillComponent>();
@ -292,7 +297,9 @@ void Entity::Initialize() {
break; break;
case eReplicaComponentType::VENDOR: case eReplicaComponentType::VENDOR:
AddComponent<VendorComponent>(); AddComponent<VendorComponent>();
if (!hasProximityMonitorComponent) AddComponent<ProximityMonitorComponent>(); if (hasProximityMonitorComponent) continue;
AddComponent<ProximityMonitorComponent>();
hasProximityMonitorComponent = true;
break; break;
case eReplicaComponentType::INVENTORY: case eReplicaComponentType::INVENTORY:
AddComponent<InventoryComponent>(); AddComponent<InventoryComponent>();
@ -301,7 +308,9 @@ void Entity::Initialize() {
AddComponent<ShootingGalleryComponent>(); AddComponent<ShootingGalleryComponent>();
break; break;
case eReplicaComponentType::RIGID_BODY_PHANTOM_PHYSICS: case eReplicaComponentType::RIGID_BODY_PHANTOM_PHYSICS:
if (hasPhysicsComponent) continue;
AddComponent<RigidbodyPhantomPhysicsComponent>(); AddComponent<RigidbodyPhantomPhysicsComponent>();
physicsComponentID = componentId;
hasPhysicsComponent = true; hasPhysicsComponent = true;
break; break;
case eReplicaComponentType::COLLECTIBLE: case eReplicaComponentType::COLLECTIBLE:
@ -317,15 +326,17 @@ void Entity::Initialize() {
AddComponent<MovementAIComponent>(); AddComponent<MovementAIComponent>();
break; break;
case eReplicaComponentType::HAVOK_VEHICLE_PHYSICS: { case eReplicaComponentType::HAVOK_VEHICLE_PHYSICS: {
if (hasPhysicsComponent) continue;
if (GetVar<bool>(u"use_simple_physics")) { if (GetVar<bool>(u"use_simple_physics")) {
AddComponent<SimplePhysicsComponent>(componentId); AddComponent<SimplePhysicsComponent>(componentId);
} else { } else {
auto* havokVehiclePhysicsComponent = AddComponent<HavokVehiclePhysicsComponent>(componentId); auto* havokVehiclePhysicsComponent = AddComponent<HavokVehiclePhysicsComponent>();
if (havokVehiclePhysicsComponent) { if (havokVehiclePhysicsComponent) {
havokVehiclePhysicsComponent->SetPosition(m_DefaultPosition); havokVehiclePhysicsComponent->SetPosition(m_DefaultPosition);
havokVehiclePhysicsComponent->SetRotation(m_DefaultRotation); havokVehiclePhysicsComponent->SetRotation(m_DefaultRotation);
} }
} }
physicsComponentID = componentId;
m_IsGhostingCandidate = false; m_IsGhostingCandidate = false;
hasPhysicsComponent = true; hasPhysicsComponent = true;
break; break;
@ -342,38 +353,37 @@ void Entity::Initialize() {
m_IsGhostingCandidate = false; m_IsGhostingCandidate = false;
break; break;
case eReplicaComponentType::PHANTOM_PHYSICS: { case eReplicaComponentType::PHANTOM_PHYSICS: {
if (hasPhysicsComponent) continue;
auto* phantomPhysicsComponent = AddComponent<PhantomPhysicsComponent>(); auto* phantomPhysicsComponent = AddComponent<PhantomPhysicsComponent>();
if (phantomPhysicsComponent) phantomPhysicsComponent->SetPhysicsEffectActive(false); if (phantomPhysicsComponent) phantomPhysicsComponent->SetPhysicsEffectActive(false);
physicsComponentID = componentId;
hasPhysicsComponent = true; hasPhysicsComponent = true;
m_IsGhostingCandidate = false; m_IsGhostingCandidate = false;
break; break;
} }
case eReplicaComponentType::MODEL_BEHAVIOR: { case eReplicaComponentType::MODEL_BEHAVIOR: {
// Get Model Type form ldf/DB AddComponent<ModelBehaviorComponent>();
if (!hasModelBehaviors && !hasPhysicsComponent){ // Get Model Type form ldf
AddComponent<SimplePhysicsComponent>(physicsComponentID); if (!hasPhysicsComponent) {
hasPhysicsComponent = true; uint32_t modelType = -1;
} else if (!hasPhysicsComponent) { if (modelType == 0) {
if (modelType == 0){ if (physicsComponentID == -1) physicsComponentID = 4246U;
if(physicsComponentID == -1) physicsComponentID = 4246U; AddComponent<ControllablePhysicsComponent>();
AddComponent<ControllablePhysicsComponent>(physicsComponentID);
hasPhysicsComponent = true; hasPhysicsComponent = true;
} else { } else {
if(physicsComponentID == -1) physicsComponentID = 4247U; if (physicsComponentID == -1) physicsComponentID = 4247U;
AddComponent<SimplePhysicsComponent>(physicsComponentID); AddComponent<SimplePhysicsComponent>(physicsComponentID);
hasPhysicsComponent = true; hasPhysicsComponent = true;
} }
} }
AddComponent<ModelBehaviorComponent>(); if (hasDestroyableComponent) continue;
if (!HasComponent(eReplicaComponentType::DESTROYABLE)) {
auto* destroyableComponent = AddComponent<DestroyableComponent>(componentId); auto* destroyableComponent = AddComponent<DestroyableComponent>(componentId);
if (destroyableComponent) { if (!destroyableComponent) continue;
destroyableComponent->SetHealth(1); destroyableComponent->SetHealth(1);
destroyableComponent->SetMaxHealth(1.0f); destroyableComponent->SetMaxHealth(1.0f);
destroyableComponent->SetFaction(-1, true); destroyableComponent->SetFaction(-1, true);
destroyableComponent->SetIsSmashable(true); destroyableComponent->SetIsSmashable(true);
} hasDestroyableComponent = true;
}
break; break;
} }
case eReplicaComponentType::PROPERTY_ENTRANCE: case eReplicaComponentType::PROPERTY_ENTRANCE:
@ -384,7 +394,9 @@ void Entity::Initialize() {
break; break;
case eReplicaComponentType::QUICK_BUILD: case eReplicaComponentType::QUICK_BUILD:
AddComponent<QuickBuildComponent>(componentId); AddComponent<QuickBuildComponent>(componentId);
if (!HasComponent(eReplicaComponentType::DESTROYABLE)) AddComponent<DestroyableComponent>(componentId); if (hasDestroyableComponent) continue;
AddComponent<DestroyableComponent>(componentId);
hasDestroyableComponent = true;
break; break;
case eReplicaComponentType::SWITCH: case eReplicaComponentType::SWITCH:
AddComponent<SwitchComponent>(); AddComponent<SwitchComponent>();
@ -418,7 +430,7 @@ void Entity::Initialize() {
AddComponent<RocketLaunchpadControlComponent>(componentId); AddComponent<RocketLaunchpadControlComponent>(componentId);
break; break;
case eReplicaComponentType::RACING_CONTROL: case eReplicaComponentType::RACING_CONTROL:
AddComponent<RacingControlComponent>(); AddComponent<RacingControlComponent>(componentId);
m_IsGhostingCandidate = false; m_IsGhostingCandidate = false;
break; break;
case eReplicaComponentType::MISSION_OFFER: case eReplicaComponentType::MISSION_OFFER:
@ -453,10 +465,12 @@ void Entity::Initialize() {
break; break;
case eReplicaComponentType::DONATION_VENDOR: case eReplicaComponentType::DONATION_VENDOR:
AddComponent<DonationVendorComponent>(); AddComponent<DonationVendorComponent>();
if (!hasProximityMonitorComponent) AddComponent<ProximityMonitorComponent>(); if (hasProximityMonitorComponent) continue;
AddComponent<ProximityMonitorComponent>();
hasProximityMonitorComponent = true;
break; break;
case eReplicaComponentType::GATE_RUSH_CONTROL: case eReplicaComponentType::GATE_RUSH_CONTROL:
AddComponent<GateRushControlComponent>(); AddComponent<GateRushControlComponent>(componentId);
break; break;
case eReplicaComponentType::RACING_SOUND_TRIGGER: case eReplicaComponentType::RACING_SOUND_TRIGGER:
AddComponent<RacingSoundTriggerComponent>(); AddComponent<RacingSoundTriggerComponent>();
@ -465,15 +479,20 @@ void Entity::Initialize() {
AddComponent<AchievementVendorComponent>(); AddComponent<AchievementVendorComponent>();
break; break;
case eReplicaComponentType::PROJECTILE_PHYSICS: case eReplicaComponentType::PROJECTILE_PHYSICS:
if (hasPhysicsComponent) continue;
// AddComponent<ProjectilePhysicsComponent>(); // AddComponent<ProjectilePhysicsComponent>();
physicsComponentID = componentId;
hasPhysicsComponent = true; hasPhysicsComponent = true;
break; break;
case eReplicaComponentType::VEHICLE_PHYSICS: case eReplicaComponentType::VEHICLE_PHYSICS:
if (hasPhysicsComponent) continue;
// AddComponent<VehiclePhysicsComponent>(); // AddComponent<VehiclePhysicsComponent>();
physicsComponentID = componentId;
hasPhysicsComponent = true; hasPhysicsComponent = true;
break; break;
case eReplicaComponentType::PHYSICS_SYSTEM: case eReplicaComponentType::PHYSICS_SYSTEM:
// AddComponent<PhysicsSystemComponent>(); // AddComponent<PhysicsSystemComponent>();
physicsComponentID = componentId;
hasPhysicsComponent = true; hasPhysicsComponent = true;
break; break;
case eReplicaComponentType::GHOST: case eReplicaComponentType::GHOST: