From c93bd91ef6f1ca20ca5258bed6d996a0afe79175 Mon Sep 17 00:00:00 2001 From: bb Date: Sat, 10 Oct 2020 15:12:17 +0000 Subject: [PATCH] Do not hardcode attacktypes in the engine/Atlas fixes 0ad79096bd refs #252, D368 Reviewed By: vladislavbelov Comments By: Stan, wraitii Differential Revision: D2998 This was SVN commit r24095. --- source/simulation2/components/ICmpAttack.cpp | 13 +++++++--- source/simulation2/components/ICmpAttack.h | 2 ++ .../tools/atlas/GameInterface/ActorViewer.cpp | 25 +++++++++++-------- 3 files changed, 25 insertions(+), 15 deletions(-) diff --git a/source/simulation2/components/ICmpAttack.cpp b/source/simulation2/components/ICmpAttack.cpp index 98ba53f400..f64f877f95 100644 --- a/source/simulation2/components/ICmpAttack.cpp +++ b/source/simulation2/components/ICmpAttack.cpp @@ -31,10 +31,15 @@ class CCmpAttackScripted : public ICmpAttack public: DEFAULT_SCRIPT_WRAPPER(AttackScripted) - virtual float GetRepeatTime(const std::string& type) const - { - return m_Script.Call("GetRepeatTime", type); - } + virtual float GetRepeatTime(const std::string& type) const + { + return m_Script.Call("GetRepeatTime", type); + } + + virtual std::vector GetAttackTypes() const + { + return m_Script.Call>("GetAttackTypes"); + } }; REGISTER_COMPONENT_SCRIPT_WRAPPER(AttackScripted) diff --git a/source/simulation2/components/ICmpAttack.h b/source/simulation2/components/ICmpAttack.h index 37e7a9e5d5..c3e210078e 100644 --- a/source/simulation2/components/ICmpAttack.h +++ b/source/simulation2/components/ICmpAttack.h @@ -18,12 +18,14 @@ #ifndef INCLUDED_ICMPATTACK #define INCLUDED_ICMPATTACK +#include "ps/CStr.h" #include "simulation2/system/Interface.h" class ICmpAttack : public IComponent { public: virtual float GetRepeatTime(const std::string& type) const = 0; + virtual std::vector GetAttackTypes() const = 0; DECLARE_INTERFACE_TYPE(Attack) }; diff --git a/source/tools/atlas/GameInterface/ActorViewer.cpp b/source/tools/atlas/GameInterface/ActorViewer.cpp index 43860df82b..e29c0cf58e 100644 --- a/source/tools/atlas/GameInterface/ActorViewer.cpp +++ b/source/tools/atlas/GameInterface/ActorViewer.cpp @@ -382,7 +382,7 @@ void ActorViewer::SetActor(const CStrW& name, const CStr& animation, player_id_t CStr anim = animation.LowerCase(); float speed = 1.0f; // Speed will be ignored if we have a repeat time. - float repeattime = 0.0f; + float repeatTime = 0.0f; m.CurrentSpeed = 0.0f; if (anim == "walk") { @@ -403,22 +403,25 @@ void ActorViewer::SetActor(const CStrW& name, const CStr& animation, player_id_t m.CurrentSpeed = speed; } - else if (anim == "attack_melee") - repeattime = GetRepeatTimeByAttackType("Melee"); - else if (anim == "attack_ranged") - repeattime = GetRepeatTimeByAttackType("Ranged"); - else if (anim == "attack_slaughter") - repeattime = GetRepeatTimeByAttackType("Slaughter"); - else if (anim == "attack_capture") - repeattime = GetRepeatTimeByAttackType("Capture"); + else if (anim.Find("attack_") == 0) + { + CmpPtr cmpAttack(m.Simulation2, m.Entity); + if (cmpAttack) + for (const CStr& type : cmpAttack->GetAttackTypes()) + if (anim == "attack_" + type.LowerCase()) + { + repeatTime = GetRepeatTimeByAttackType(type); + break; + } + } CmpPtr cmpVisual(m.Simulation2, m.Entity); if (cmpVisual) { // TODO: SetEntitySelection(anim) cmpVisual->SelectAnimation(anim, false, fixed::FromFloat(speed)); - if (repeattime) - cmpVisual->SetAnimationSyncRepeat(fixed::FromFloat(repeattime)); + if (repeatTime > 0.0f) + cmpVisual->SetAnimationSyncRepeat(fixed::FromFloat(repeatTime)); } // update prop list for new entity/animation (relies on needsAnimReload also getting called for entire entity changes)