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"
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 {
public:
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"
"DestroyableComponent.cpp"
"DonationVendorComponent.cpp"
"GateRushControlComponent.cpp"
"InventoryComponent.cpp"
"ItemComponent.cpp"
"LevelProgressionComponent.cpp"

View File

@ -1,5 +1,5 @@
#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 {
public:
inline static const eReplicaComponentType ComponentType = eReplicaComponentType::GATE_RUSH_CONTROL;
GateRushControlComponent(Entity* parent);
GateRushControlComponent(Entity* parent, int32_t componentId);
};
#endif //!__GATERUSHCONTROLCOMPONENT__H__

View File

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

View File

@ -2,6 +2,6 @@
#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 {
public:
static const eReplicaComponentType ComponentType = eReplicaComponentType::MODEL;
static const eReplicaComponentType ComponentType = eReplicaComponentType::MODEL_BEHAVIOR;
MutableModelBehaviorComponent(Entity* parent);

View File

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

View File

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

View File

@ -107,7 +107,7 @@ class RacingControlComponent : public BaseRacingControlComponent {
public:
inline static const eReplicaComponentType ComponentType = eReplicaComponentType::RACING_CONTROL;
RacingControlComponent(Entity* parentEntity);
RacingControlComponent(Entity* parentEntity, int32_t componentId);
~RacingControlComponent();
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;
}
/**
* Gets the list if items the vendor sells.
* @return the list of items.
*/
std::map<LOT, int>& GetInventory();
/**
* Refresh the inventory of this vendor.
*/

View File

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