From 9d3bd194ee1189e436a1ffd5893a8c6dd634294c Mon Sep 17 00:00:00 2001 From: Relintai Date: Wed, 19 Feb 2020 08:39:30 +0100 Subject: [PATCH] Added support for Entity relations. --- entities/entity.cpp | 50 +++++++++++++++++++++++++++++++++++++++++++++ entities/entity.h | 11 ++++++++++ entity_enums.cpp | 5 +++++ entity_enums.h | 12 +++++++++-- 4 files changed, 76 insertions(+), 2 deletions(-) diff --git a/entities/entity.cpp b/entities/entity.cpp index a8cc8db..04861f7 100644 --- a/entities/entity.cpp +++ b/entities/entity.cpp @@ -116,6 +116,47 @@ void Entity::setc_entity_type(EntityEnums::EntityType value) { _c_entity_type = value; } +//Relations +EntityEnums::EntityRelationType Entity::gets_relation_to_bind(Node *to) { + Entity *e = Object::cast_to(to); + + ERR_FAIL_COND_V(!ObjectDB::instance_validate(e), EntityEnums::ENTITY_RELATION_TYPE_NEUTRAL); + + return gets_relation_to(e); +} +EntityEnums::EntityRelationType Entity::gets_relation_to(Entity *to) { + ERR_FAIL_COND_V(!ObjectDB::instance_validate(to), EntityEnums::ENTITY_RELATION_TYPE_NEUTRAL); + + return static_cast(static_cast(call("_gets_relation_to", to))); +} + +EntityEnums::EntityRelationType Entity::_gets_relation_to(Node *to) { + if (to == this) + return EntityEnums::ENTITY_RELATION_TYPE_FRIENDLY; + + return EntityEnums::ENTITY_RELATION_TYPE_HOSTILE; +} + +EntityEnums::EntityRelationType Entity::getc_relation_to_bind(Node *to) { + Entity *e = Object::cast_to(to); + + ERR_FAIL_COND_V(!ObjectDB::instance_validate(e), EntityEnums::ENTITY_RELATION_TYPE_NEUTRAL); + + return getc_relation_to(e); +} +EntityEnums::EntityRelationType Entity::getc_relation_to(Entity *to) { + ERR_FAIL_COND_V(!ObjectDB::instance_validate(to), EntityEnums::ENTITY_RELATION_TYPE_NEUTRAL); + + return static_cast(static_cast(call("_getc_relation_to", to))); +} + +EntityEnums::EntityRelationType Entity::_getc_relation_to(Node *to) { + if (to == this) + return EntityEnums::ENTITY_RELATION_TYPE_FRIENDLY; + + return EntityEnums::ENTITY_RELATION_TYPE_HOSTILE; +} + //EntityInteractionType EntityEnums::EntityInteractionType Entity::gets_entity_interaction_type() { return _s_interaction_type; @@ -6297,6 +6338,15 @@ void Entity::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::INT, "cseed"), "setc_seed", "getc_seed"); //Interaction type + BIND_VMETHOD(MethodInfo("_gets_relation_to", PropertyInfo(Variant::OBJECT, "to", PROPERTY_HINT_RESOURCE_TYPE, "Entity"))); + BIND_VMETHOD(MethodInfo("_getc_relation_to", PropertyInfo(Variant::OBJECT, "to", PROPERTY_HINT_RESOURCE_TYPE, "Entity"))); + + ClassDB::bind_method(D_METHOD("gets_relation_to", "to"), &Entity::gets_relation_to_bind); + ClassDB::bind_method(D_METHOD("_gets_relation_to", "to"), &Entity::_gets_relation_to); + + ClassDB::bind_method(D_METHOD("getc_relation_to", "to"), &Entity::getc_relation_to_bind); + ClassDB::bind_method(D_METHOD("_getc_relation_to", "to"), &Entity::_getc_relation_to); + ClassDB::bind_method(D_METHOD("gets_entity_interaction_type"), &Entity::gets_entity_interaction_type); ClassDB::bind_method(D_METHOD("sets_entity_interaction_type", "value"), &Entity::sets_entity_interaction_type); ADD_PROPERTY(PropertyInfo(Variant::INT, "sentity_interaction_type", PROPERTY_HINT_ENUM, EntityEnums::BINDING_STRING_ENTITY_INTERACTION_TYPE), "sets_entity_interaction_type", "gets_entity_interaction_type"); diff --git a/entities/entity.h b/entities/entity.h index 468c768..7502905 100644 --- a/entities/entity.h +++ b/entities/entity.h @@ -219,6 +219,17 @@ public: EntityEnums::EntityType getc_entity_type(); void setc_entity_type(EntityEnums::EntityType value); + //Relations + EntityEnums::EntityRelationType gets_relation_to_bind(Node *to); + EntityEnums::EntityRelationType gets_relation_to(Entity *to); + + EntityEnums::EntityRelationType _gets_relation_to(Node *to); + + EntityEnums::EntityRelationType getc_relation_to_bind(Node *to); + EntityEnums::EntityRelationType getc_relation_to(Entity *to); + + EntityEnums::EntityRelationType _getc_relation_to(Node *to); + //EntityInteractionType EntityEnums::EntityInteractionType gets_entity_interaction_type(); void sets_entity_interaction_type(EntityEnums::EntityInteractionType value); diff --git a/entity_enums.cpp b/entity_enums.cpp index b63ed98..8f88de9 100644 --- a/entity_enums.cpp +++ b/entity_enums.cpp @@ -30,6 +30,7 @@ const String EntityEnums::BINDING_STRING_ENTITY_STATE_TYPES = "None,Stun,Root,Fr const String EntityEnums::BINDING_STRING_CHARCATER_SKELETON_POINTS = "Root,Pelvis,Spine,Spine 1,Spine 2,Neck,Head,Left Clavicle,Left upper Arm,Left Forearm,Left Hand,Left Thumb Base,Left Thumb End,Left Fingers Base,Left Fingers End,Right Clavicle,Right upper Arm,Right Forearm,Right Hand,Right Thumb Base,Right Thumb End,Right Fingers Base,Right Fingers End,Left Thigh,Left Calf,Left Foot,Right Thigh,Right Calf,Right Foot"; const String EntityEnums::BINDING_STRING_AI_STATES = "Off,Rest,Patrol,Follow Path,Regenerate,Attack,Pet Follow,Pet Stop,Pet Attack"; const String EntityEnums::BINDING_STRING_ENTITY_IMMUNITY_FLAGS = "Stun,Root,Freeze,Silence,Disorient,Fear,Burning,Cold,Pacify,Magic,Poison,Physical,Curse,Bleed,Melee,Holy,Shadow,Nature,Fire,Frost,Lightning,Chaos,Slow,Crit,AOE,Damage,Fall Damage,Projectile,Debuff,Attacks"; +const String EntityEnums::BINDING_STRING_ENTITY_RELATION_TYPE = "Neutral,Friendly,Hostile"; const String EntityEnums::BINDING_STRING_ENTITY_INTERACTION_TYPE = "Normal,Speak,Loot,Use,None"; const String EntityEnums::BINDING_STRING_ENTITY_PLAYSTYLE_TYPE = "Melee,Spell,Hybrid,None"; const String EntityEnums::BINDING_STRING_ENTITY_GENDER = "Male,Female"; @@ -175,6 +176,10 @@ void EntityEnums::_bind_methods() { BIND_ENUM_CONSTANT(ENTITY_IMMUNITY_FLAG_DEBUFF); BIND_ENUM_CONSTANT(ENTITY_IMMUNITY_FLAG_ATTACKS); + BIND_ENUM_CONSTANT(ENTITY_RELATION_TYPE_NEUTRAL); + BIND_ENUM_CONSTANT(ENTITY_RELATION_TYPE_FRIENDLY); + BIND_ENUM_CONSTANT(ENTITY_RELATION_TYPE_HOSTILE); + BIND_ENUM_CONSTANT(ENITIY_INTERACTION_TYPE_NORMAL); BIND_ENUM_CONSTANT(ENITIY_INTERACTION_TYPE_SPEAK); BIND_ENUM_CONSTANT(ENITIY_INTERACTION_TYPE_LOOT); diff --git a/entity_enums.h b/entity_enums.h index 341bbf4..e3fce95 100644 --- a/entity_enums.h +++ b/entity_enums.h @@ -39,6 +39,7 @@ public: static const String BINDING_STRING_AI_STATES; static const String BINDING_STRING_PET_STATES; static const String BINDING_STRING_ENTITY_IMMUNITY_FLAGS; + static const String BINDING_STRING_ENTITY_RELATION_TYPE; static const String BINDING_STRING_ENTITY_INTERACTION_TYPE; static const String BINDING_STRING_ENTITY_PLAYSTYLE_TYPE; static const String BINDING_STRING_ENTITY_GENDER; @@ -234,8 +235,14 @@ public: AI_STATE_MAX, }; + enum EntityRelationType { + ENTITY_RELATION_TYPE_NEUTRAL = 0, + ENTITY_RELATION_TYPE_FRIENDLY, + ENTITY_RELATION_TYPE_HOSTILE, + }; + enum EntityInteractionType { - ENITIY_INTERACTION_TYPE_NORMAL, + ENITIY_INTERACTION_TYPE_NORMAL = 0, ENITIY_INTERACTION_TYPE_SPEAK, ENITIY_INTERACTION_TYPE_LOOT, ENITIY_INTERACTION_TYPE_USE, @@ -243,7 +250,7 @@ public: }; enum EntityClassPlaystyleType { - ENTITY_CLASS_PLAYSTYLE_TYPE_MELEE, + ENTITY_CLASS_PLAYSTYLE_TYPE_MELEE = 0, ENTITY_CLASS_PLAYSTYLE_TYPE_SPELL, ENTITY_CLASS_PLAYSTYLE_TYPE_HYBRID, ENTITY_CLASS_PLAYSTYLE_TYPE_NONE, @@ -281,6 +288,7 @@ VARIANT_ENUM_CAST(EntityEnums::EntityStateTypeIndexes); VARIANT_ENUM_CAST(EntityEnums::CharacterSkeletonPoints); VARIANT_ENUM_CAST(EntityEnums::AIStates); VARIANT_ENUM_CAST(EntityEnums::EntityImmunityFlags); +VARIANT_ENUM_CAST(EntityEnums::EntityRelationType); VARIANT_ENUM_CAST(EntityEnums::EntityInteractionType); VARIANT_ENUM_CAST(EntityEnums::EntityClassPlaystyleType); VARIANT_ENUM_CAST(EntityEnums::EntityGender);