1
0
forked from mirrors/0ad

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.
This commit is contained in:
bb
2020-10-10 15:12:17 +00:00
parent 76ebb66241
commit c93bd91ef6
3 changed files with 25 additions and 15 deletions
+9 -4
View File
@@ -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<float, const std::string&>("GetRepeatTime", type);
}
virtual float GetRepeatTime(const std::string& type) const
{
return m_Script.Call<float, const std::string&>("GetRepeatTime", type);
}
virtual std::vector<CStr> GetAttackTypes() const
{
return m_Script.Call<std::vector<CStr>>("GetAttackTypes");
}
};
REGISTER_COMPONENT_SCRIPT_WRAPPER(AttackScripted)
@@ -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<CStr> GetAttackTypes() const = 0;
DECLARE_INTERFACE_TYPE(Attack)
};
@@ -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<ICmpAttack> cmpAttack(m.Simulation2, m.Entity);
if (cmpAttack)
for (const CStr& type : cmpAttack->GetAttackTypes())
if (anim == "attack_" + type.LowerCase())
{
repeatTime = GetRepeatTimeByAttackType(type);
break;
}
}
CmpPtr<ICmpVisual> 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)