pass reference to spell target, so that summon can set the target and subsequent spell actions can access it
This commit is contained in:
parent
106db194bd
commit
0279cbffa2
25 changed files with 35 additions and 34 deletions
|
@ -71,7 +71,7 @@ public:
|
|||
Spell_AdjustVariable() : Var(NULL) {};
|
||||
~Spell_AdjustVariable() { delete [](this->Var); };
|
||||
virtual int Cast(CUnit &caster, const SpellType &spell,
|
||||
CUnit *target, const Vec2i &goalPos);
|
||||
CUnit *&target, const Vec2i &goalPos);
|
||||
virtual void Parse(lua_State *l, int startIndex, int endIndex);
|
||||
|
||||
private:
|
||||
|
|
|
@ -43,7 +43,7 @@ class Spell_AdjustVital : public SpellActionType
|
|||
public:
|
||||
Spell_AdjustVital() : SpellActionType(1), HP(0), Mana(0), Shield(0), MaxMultiCast(0) {};
|
||||
virtual int Cast(CUnit &caster, const SpellType &spell,
|
||||
CUnit *target, const Vec2i &goalPos);
|
||||
CUnit *&target, const Vec2i &goalPos);
|
||||
virtual void Parse(lua_State *l, int startIndex, int endIndex);
|
||||
|
||||
private:
|
||||
|
|
|
@ -43,7 +43,7 @@ class Spell_AreaAdjustVital : public SpellActionType
|
|||
public:
|
||||
Spell_AreaAdjustVital() : HP(0), Mana(0), Shield(0), Range(1), UseMana(false) {};
|
||||
virtual int Cast(CUnit &caster, const SpellType &spell,
|
||||
CUnit *target, const Vec2i &goalPos);
|
||||
CUnit *&target, const Vec2i &goalPos);
|
||||
virtual void Parse(lua_State *l, int startIndex, int endIndex);
|
||||
|
||||
private:
|
||||
|
|
|
@ -44,7 +44,7 @@ public:
|
|||
Spell_AreaBombardment() : Fields(0), Shards(0), Damage(0),
|
||||
StartOffsetX(0), StartOffsetY(0), Missile(NULL) {};
|
||||
virtual int Cast(CUnit &caster, const SpellType &spell,
|
||||
CUnit *target, const Vec2i &goalPos);
|
||||
CUnit *&target, const Vec2i &goalPos);
|
||||
virtual void Parse(lua_State *l, int startIndex, int endIndex);
|
||||
|
||||
private:
|
||||
|
|
|
@ -43,7 +43,7 @@ class Spell_Capture : public SpellActionType
|
|||
public:
|
||||
Spell_Capture() : SacrificeEnable(false), JoinToAIForce(false), Damage(0), DamagePercent(0) {};
|
||||
virtual int Cast(CUnit &caster, const SpellType &spell,
|
||||
CUnit *target, const Vec2i &goalPos);
|
||||
CUnit *&target, const Vec2i &goalPos);
|
||||
virtual void Parse(lua_State *l, int startIndex, int endIndex);
|
||||
|
||||
private:
|
||||
|
|
|
@ -43,7 +43,7 @@ class Spell_Demolish : public SpellActionType
|
|||
public:
|
||||
Spell_Demolish() : Damage(0), Range(0) {};
|
||||
virtual int Cast(CUnit &caster, const SpellType &spell,
|
||||
CUnit *target, const Vec2i &goalPos);
|
||||
CUnit *&target, const Vec2i &goalPos);
|
||||
virtual void Parse(lua_State *l, int startIndex, int endIndex);
|
||||
|
||||
private:
|
||||
|
|
|
@ -45,7 +45,7 @@ public:
|
|||
Spell_LuaCallback() : Func(NULL) {};
|
||||
~Spell_LuaCallback() { delete Func; };
|
||||
virtual int Cast(CUnit &caster, const SpellType &spell,
|
||||
CUnit *target, const Vec2i &goalPos);
|
||||
CUnit *&target, const Vec2i &goalPos);
|
||||
virtual void Parse(lua_State *l, int startIndex, int endIndex);
|
||||
|
||||
private:
|
||||
|
|
|
@ -43,7 +43,7 @@ class Spell_Polymorph : public SpellActionType
|
|||
public:
|
||||
Spell_Polymorph() : SpellActionType(1), NewForm(NULL), PlayerNeutral(0) {};
|
||||
virtual int Cast(CUnit &caster, const SpellType &spell,
|
||||
CUnit *target, const Vec2i &goalPos);
|
||||
CUnit *&target, const Vec2i &goalPos);
|
||||
virtual void Parse(lua_State *l, int startIndex, int endIndex);
|
||||
|
||||
private:
|
||||
|
|
|
@ -71,7 +71,7 @@ public:
|
|||
Spell_SpawnMissile() : Damage(0), TTL(-1), Delay(0), UseUnitVar(false),
|
||||
StartPoint(LocBaseCaster), EndPoint(LocBaseTarget), Missile(0) {}
|
||||
virtual int Cast(CUnit &caster, const SpellType &spell,
|
||||
CUnit *target, const Vec2i &goalPos);
|
||||
CUnit *&target, const Vec2i &goalPos);
|
||||
virtual void Parse(lua_State *lua, int startIndex, int endIndex);
|
||||
|
||||
private:
|
||||
|
|
|
@ -43,7 +43,7 @@ class Spell_SpawnPortal : public SpellActionType
|
|||
public:
|
||||
Spell_SpawnPortal() : PortalType(0), TTL(0), CurrentPlayer(false) {};
|
||||
virtual int Cast(CUnit &caster, const SpellType &spell,
|
||||
CUnit *target, const Vec2i &goalPos);
|
||||
CUnit *&target, const Vec2i &goalPos);
|
||||
virtual void Parse(lua_State *l, int startIndex, int endIndex);
|
||||
|
||||
private:
|
||||
|
|
|
@ -44,7 +44,7 @@ public:
|
|||
Spell_Summon() : SpellActionType(1), UnitType(NULL), TTL(0),
|
||||
RequireCorpse(false), JoinToAiForce(false) {};
|
||||
virtual int Cast(CUnit &caster, const SpellType &spell,
|
||||
CUnit *target, const Vec2i &goalPos);
|
||||
CUnit *&target, const Vec2i &goalPos);
|
||||
virtual void Parse(lua_State *l, int startIndex, int endIndex);
|
||||
|
||||
private:
|
||||
|
|
|
@ -42,7 +42,7 @@ class Spell_Teleport : public SpellActionType
|
|||
public:
|
||||
Spell_Teleport() : SpellActionType(0) {}
|
||||
virtual int Cast(CUnit &caster, const SpellType &spell,
|
||||
CUnit *target, const Vec2i &goalPos);
|
||||
CUnit *&target, const Vec2i &goalPos);
|
||||
virtual void Parse(lua_State *l, int startIndex, int endIndex);
|
||||
};
|
||||
|
||||
|
|
|
@ -67,7 +67,7 @@ public:
|
|||
virtual ~SpellActionType() {};
|
||||
|
||||
virtual int Cast(CUnit &caster, const SpellType &spell,
|
||||
CUnit *target, const Vec2i &goalPos) = 0;
|
||||
CUnit* &target, const Vec2i &goalPos) = 0;
|
||||
virtual void Parse(lua_State *l, int startIndex, int endIndex) = 0;
|
||||
|
||||
const int ModifyManaCaster;
|
||||
|
|
|
@ -116,7 +116,7 @@
|
|||
**
|
||||
** @return =!0 if spell should be repeated, 0 if not
|
||||
*/
|
||||
/* virtual */ int Spell_AdjustVariable::Cast(CUnit &caster, const SpellType &, CUnit *target, const Vec2i &/*goalPos*/)
|
||||
/* virtual */ int Spell_AdjustVariable::Cast(CUnit &caster, const SpellType &, CUnit *&target, const Vec2i &/*goalPos*/)
|
||||
{
|
||||
for (unsigned int i = 0; i < UnitTypeVar.GetNumberVariable(); ++i) {
|
||||
CUnit *unit = (this->Var[i].TargetIsCaster) ? &caster : target;
|
||||
|
|
|
@ -67,7 +67,7 @@
|
|||
**
|
||||
** @return =!0 if spell should be repeated, 0 if not
|
||||
*/
|
||||
/* virtual */ int Spell_AdjustVital::Cast(CUnit &caster, const SpellType &spell, CUnit *target, const Vec2i &/*goalPos*/)
|
||||
/* virtual */ int Spell_AdjustVital::Cast(CUnit &caster, const SpellType &spell, CUnit *&target, const Vec2i &/*goalPos*/)
|
||||
{
|
||||
if (!target) {
|
||||
return 0;
|
||||
|
|
|
@ -69,7 +69,7 @@
|
|||
**
|
||||
** @return =!0 if spell should be repeated, 0 if not
|
||||
*/
|
||||
/* virtual */ int Spell_AreaAdjustVital::Cast(CUnit &caster, const SpellType &spell, CUnit *target, const Vec2i &goalPos)
|
||||
/* virtual */ int Spell_AreaAdjustVital::Cast(CUnit &caster, const SpellType &spell, CUnit *&target, const Vec2i &goalPos)
|
||||
{
|
||||
const Vec2i range(this->Range, this->Range);
|
||||
const Vec2i typeSize(caster.Type->TileWidth, caster.Type->TileHeight);
|
||||
|
@ -80,22 +80,23 @@
|
|||
int hp = this->HP;
|
||||
int mana = this->Mana;
|
||||
int shield = this->Shield;
|
||||
CUnit* currentTarget;
|
||||
for (size_t j = 0; j != units.size(); ++j) {
|
||||
target = units[j];
|
||||
currentTarget = units[j];
|
||||
// if (!PassCondition(caster, spell, target, goalPos) {
|
||||
if (!CanCastSpell(caster, spell, target, goalPos)) {
|
||||
if (!CanCastSpell(caster, spell, currentTarget, goalPos)) {
|
||||
continue;
|
||||
}
|
||||
if (hp < 0) {
|
||||
HitUnit(&caster, *target, -hp);
|
||||
HitUnit(&caster, *currentTarget, -hp);
|
||||
} else {
|
||||
target->Variable[HP_INDEX].Value += hp;
|
||||
target->Variable[HP_INDEX].Value = std::min(target->Variable[HP_INDEX].Max, target->Variable[HP_INDEX].Value);
|
||||
currentTarget->Variable[HP_INDEX].Value += hp;
|
||||
currentTarget->Variable[HP_INDEX].Value = std::min(currentTarget->Variable[HP_INDEX].Max, currentTarget->Variable[HP_INDEX].Value);
|
||||
}
|
||||
target->Variable[MANA_INDEX].Value += mana;
|
||||
clamp(&target->Variable[MANA_INDEX].Value, 0, target->Variable[MANA_INDEX].Max);
|
||||
target->Variable[SHIELD_INDEX].Value += shield;
|
||||
clamp(&target->Variable[SHIELD_INDEX].Value, 0, target->Variable[SHIELD_INDEX].Max);
|
||||
currentTarget->Variable[MANA_INDEX].Value += mana;
|
||||
clamp(¤tTarget->Variable[MANA_INDEX].Value, 0, currentTarget->Variable[MANA_INDEX].Max);
|
||||
currentTarget->Variable[SHIELD_INDEX].Value += shield;
|
||||
clamp(¤tTarget->Variable[SHIELD_INDEX].Value, 0, currentTarget->Variable[SHIELD_INDEX].Max);
|
||||
}
|
||||
if (UseMana) {
|
||||
caster.Variable[MANA_INDEX].Value -= spell.ManaCost;
|
||||
|
|
|
@ -84,7 +84,7 @@
|
|||
** @internal: vladi: blizzard differs than original in this way:
|
||||
** original: launches 50 shards at 5 random spots x 10 for 25 mana.
|
||||
*/
|
||||
/* virtual */ int Spell_AreaBombardment::Cast(CUnit &caster, const SpellType &, CUnit *, const Vec2i &goalPos)
|
||||
/* virtual */ int Spell_AreaBombardment::Cast(CUnit &caster, const SpellType &, CUnit *&, const Vec2i &goalPos)
|
||||
{
|
||||
int fields = this->Fields;
|
||||
const int shards = this->Shards;
|
||||
|
|
|
@ -70,7 +70,7 @@
|
|||
**
|
||||
** @return =!0 if spell should be repeated, 0 if not
|
||||
*/
|
||||
/* virtual */ int Spell_Capture::Cast(CUnit &caster, const SpellType &spell, CUnit *target, const Vec2i &/*goalPos*/)
|
||||
/* virtual */ int Spell_Capture::Cast(CUnit &caster, const SpellType &spell, CUnit *&target, const Vec2i &/*goalPos*/)
|
||||
{
|
||||
if (!target || caster.Player == target->Player) {
|
||||
return 0;
|
||||
|
|
|
@ -63,7 +63,7 @@
|
|||
**
|
||||
** @return =!0 if spell should be repeated, 0 if not
|
||||
*/
|
||||
/* virtual */ int Spell_Demolish::Cast(CUnit &caster, const SpellType &, CUnit *, const Vec2i &goalPos)
|
||||
/* virtual */ int Spell_Demolish::Cast(CUnit &caster, const SpellType &, CUnit *&, const Vec2i &goalPos)
|
||||
{
|
||||
// Allow error margins. (Lame, I know)
|
||||
const Vec2i offset(this->Range + 2, this->Range + 2);
|
||||
|
|
|
@ -56,7 +56,7 @@
|
|||
**
|
||||
** @return =!0 if spell should be repeated, 0 if not
|
||||
*/
|
||||
/* virtual */ int Spell_LuaCallback::Cast(CUnit &caster, const SpellType &spell, CUnit *target, const Vec2i &goalPos)
|
||||
/* virtual */ int Spell_LuaCallback::Cast(CUnit &caster, const SpellType &spell, CUnit *&target, const Vec2i &goalPos)
|
||||
{
|
||||
if (this->Func) {
|
||||
this->Func->pushPreamble();
|
||||
|
|
|
@ -78,7 +78,7 @@
|
|||
**
|
||||
** @return =!0 if spell should be repeated, 0 if not
|
||||
*/
|
||||
/* virtual */ int Spell_Polymorph::Cast(CUnit &caster, const SpellType &spell, CUnit *target, const Vec2i &goalPos)
|
||||
/* virtual */ int Spell_Polymorph::Cast(CUnit &caster, const SpellType &spell, CUnit *&target, const Vec2i &goalPos)
|
||||
{
|
||||
if (!target) {
|
||||
return 0;
|
||||
|
|
|
@ -179,7 +179,7 @@ static void EvaluateMissileLocation(const SpellActionMissileLocation &location,
|
|||
**
|
||||
** @return =!0 if spell should be repeated, 0 if not
|
||||
*/
|
||||
/* virtual */ int Spell_SpawnMissile::Cast(CUnit &caster, const SpellType &, CUnit *target, const Vec2i &goalPos)
|
||||
/* virtual */ int Spell_SpawnMissile::Cast(CUnit &caster, const SpellType &, CUnit *&target, const Vec2i &goalPos)
|
||||
{
|
||||
PixelPos startPos;
|
||||
PixelPos endPos;
|
||||
|
|
|
@ -74,7 +74,7 @@
|
|||
**
|
||||
** @return =!0 if spell should be repeated, 0 if not
|
||||
*/
|
||||
/* virtual */ int Spell_SpawnPortal::Cast(CUnit &caster, const SpellType &, CUnit *, const Vec2i &goalPos)
|
||||
/* virtual */ int Spell_SpawnPortal::Cast(CUnit &caster, const SpellType &, CUnit *&, const Vec2i &goalPos)
|
||||
{
|
||||
// FIXME: vladi: cop should be placed only on explored land
|
||||
CUnit *portal = caster.Goal;
|
||||
|
|
|
@ -94,7 +94,7 @@ public:
|
|||
**
|
||||
** @return =!0 if spell should be repeated, 0 if not
|
||||
*/
|
||||
/* virtual */ int Spell_Summon::Cast(CUnit &caster, const SpellType &spell, CUnit *target, const Vec2i &goalPos)
|
||||
/* virtual */ int Spell_Summon::Cast(CUnit &caster, const SpellType &spell, CUnit *&target, const Vec2i &goalPos)
|
||||
{
|
||||
Vec2i pos = goalPos;
|
||||
bool cansummon;
|
||||
|
|
|
@ -56,7 +56,7 @@
|
|||
**
|
||||
** @return =!0 if spell should be repeated, 0 if not
|
||||
*/
|
||||
/* virtual */ int Spell_Teleport::Cast(CUnit &caster, const SpellType &spell, CUnit * /*target*/, const Vec2i &goalPos)
|
||||
/* virtual */ int Spell_Teleport::Cast(CUnit &caster, const SpellType &spell, CUnit *&, const Vec2i &goalPos)
|
||||
{
|
||||
if (Map.Info.IsPointOnMap(goalPos)) {
|
||||
unsigned int selected = caster.Selected;
|
||||
|
|
Loading…
Add table
Reference in a new issue