Skip to content
Browse files

split LastTarget into attack and spell target (LastSpellTarget) for iwd2

currently setting either clears the other, so melee does not override casting
immediately
  • Loading branch information...
1 parent 7b126e1 commit 8f9b1258b8f2f303fa1ff39e0f47e4514d258fa1 @lynxlynxlynx lynxlynxlynx committed Aug 10, 2013
View
2 gemrb/core/GUI/GameControl.cpp
@@ -806,7 +806,7 @@ bool GameControl::OnKeyRelease(unsigned char Key, unsigned short Mod)
if (target) {
src->SetSpellResRef(TestSpell);
src->CastSpell(target, false);
- if (src->LastTarget) {
+ if (src->LastSpellTarget) {
src->CastSpellEnd(0, 0);
} else {
src->CastSpellPointEnd(0, 0);
View
1 gemrb/core/GameScript/Actions.cpp
@@ -2102,6 +2102,7 @@ void GameScript::SetMyTarget(Scriptable* Sender, Action* parameters)
actor->LastTarget = 0;
return;
}
+ actor->LastSpellTarget = 0;
actor->LastTarget = tar->GetGlobalID();
}
View
6 gemrb/core/GameScript/GSUtils.cpp
@@ -2604,8 +2604,8 @@ inline static bool InterruptSpellcasting(Scriptable* Sender) {
// abort casting on invisible or dead targets
// not all spells should be interrupted on death - some for chunking, some for raising the dead
- if (Sender->LastTarget) {
- Actor *target = core->GetGame()->GetActorByGlobalID(Sender->LastTarget);
+ if (Sender->LastSpellTarget) {
+ Actor *target = core->GetGame()->GetActorByGlobalID(Sender->LastSpellTarget);
if (target) {
ieDword state = target->GetStat(IE_STATE_ID);
if (state & STATE_DEAD) {
@@ -2728,7 +2728,7 @@ void SpellCore(Scriptable *Sender, Action *parameters, int flags)
return;
}
- if (Sender->LastTarget) {
+ if (Sender->LastSpellTarget) {
//if target was set, fire spell
Sender->CastSpellEnd(level, flags&SC_INSTANT);
} else if(!Sender->LastTargetPos.isempty()) {
View
2 gemrb/core/GameScript/Objects.cpp
@@ -178,7 +178,7 @@ Targets *GameScript::SpellTarget(Scriptable *Sender, Targets *parameters, int ga
}
parameters->Clear();
if (actor) {
- Actor *target = actor->GetCurrentArea()->GetActorByGlobalID(actor->LastTarget);
+ Actor *target = actor->GetCurrentArea()->GetActorByGlobalID(actor->LastSpellTarget);
if (target) {
parameters->AddTarget(target, 0, ga_flags);
}
View
7 gemrb/core/GameScript/Triggers.cpp
@@ -2146,6 +2146,7 @@ int GameScript::SetLastMarkedObject(Scriptable* Sender, Trigger* parameters)
}
// TODO: should there be any more failure modes?
+// iwd2 only
int GameScript::SetSpellTarget(Scriptable* Sender, Trigger* parameters)
{
if (Sender->Type != ST_ACTOR) {
@@ -2156,11 +2157,13 @@ int GameScript::SetSpellTarget(Scriptable* Sender, Trigger* parameters)
Scriptable* tar = GetActorFromObject( Sender, parameters->objectParameter );
if (!tar) {
// we got called with Nothing to invalidate the target
- scr->LastTarget = 0;
+ scr->LastSpellTarget = 0;
scr->LastTargetPos.empty();
return 1;
}
- scr->LastTarget = tar->GetGlobalID();
+ scr->LastTarget = 0;
+ scr->LastTargetPos.empty();
+ scr->LastSpellTarget = tar->GetGlobalID();
return 1;
}
View
5 gemrb/core/Scriptable/Actor.cpp
@@ -4235,7 +4235,8 @@ void Actor::dump(StringBuffer& buffer) const
}
buffer.append("\n");
buffer.appendFormatted("WaitCounter: %d\n", (int) GetWait());
- buffer.appendFormatted("LastTarget: %d %s\n", LastTarget, GetActorNameByID(LastTarget));
+ buffer.appendFormatted("LastTarget: %d %s ", LastTarget, GetActorNameByID(LastTarget));
+ buffer.appendFormatted("LastSpellTarget: %d %s\n", LastSpellTarget, GetActorNameByID(LastSpellTarget));
buffer.appendFormatted("LastTalked: %d %s\n", LastTalker, GetActorNameByID(LastTalker));
inventory.dump(buffer);
spellbook.dump(buffer);
@@ -7105,6 +7106,8 @@ bool Actor::ShouldHibernate() {
return false;
if (!LastTargetPos.isempty()) //currently casting at the ground
return false;
+ if (LastSpellTarget) //currently casting at someone
+ return false;
if (InternalFlags&IF_JUSTDIED) // didn't have a chance to run a script
return false;
if (CurrentAction)
View
26 gemrb/core/Scriptable/Scriptable.cpp
@@ -110,6 +110,7 @@ Scriptable::Scriptable(ScriptableType type)
Pos.x = 0;
Pos.y = 0;
+ LastTarget = 0;
LastSpellOnMe = 0xffffffff;
ResetCastingState(NULL);
InterruptCasting = false;
@@ -493,6 +494,7 @@ void Scriptable::ClearActions()
WaitCounter = 0;
LastTarget = 0;
LastTargetPos.empty();
+ LastSpellTarget = 0;
if (Type == ST_ACTOR) {
Interrupt();
@@ -803,7 +805,7 @@ void Scriptable::CreateProjectile(const ieResRef SpellResRef, ieDword tgt, int l
}
}
if (tgt) {
- LastTarget = newact->GetGlobalID();
+ LastSpellTarget = newact->GetGlobalID();
LastTargetPos = newact->Pos;
} else {
// no better idea; I wonder if the original randomized point targets at all
@@ -937,8 +939,8 @@ void Scriptable::SendTriggerToAll(TriggerEntry entry)
inline void Scriptable::ResetCastingState(Actor *caster) {
SpellHeader = -1;
SpellResRef[0] = 0;
- LastTarget = 0;
LastTargetPos.empty();
+ LastSpellTarget = 0;
if (caster) {
memset(&(caster->wildSurgeMods), 0, sizeof(caster->wildSurgeMods));
}
@@ -1038,10 +1040,10 @@ void Scriptable::CastSpellEnd(int level, int no_stance)
}
if (SpellHeader == -1) {
- LastTarget = 0;
+ LastSpellTarget = 0;
return;
}
- if (!LastTarget) {
+ if (!LastSpellTarget) {
SpellHeader = -1;
return;
}
@@ -1059,7 +1061,7 @@ void Scriptable::CastSpellEnd(int level, int no_stance)
}
//if the projectile doesn't need to follow the target, then use the target position
- CreateProjectile(SpellResRef, LastTarget, level, GetSpellDistance(SpellResRef, this)==0xffffffff);
+ CreateProjectile(SpellResRef, LastSpellTarget, level, GetSpellDistance(SpellResRef, this)==0xffffffff);
//FIXME: this trigger affects actors whom the caster sees, not just the caster itself
// the original engine saves lasttrigger only in case of SpellCast, so we have to differentiate
ieDword spellID = ResolveSpellNumber(SpellResRef);
@@ -1076,7 +1078,7 @@ void Scriptable::CastSpellEnd(int level, int no_stance)
}
// TODO: maybe it should be set on effect application, since the data uses it with dispel magic and true sight a lot
- Actor *target = area->GetActorByGlobalID(LastTarget);
+ Actor *target = area->GetActorByGlobalID(LastSpellTarget);
if (target) {
target->AddTrigger(TriggerEntry(trigger_spellcastonme, GetGlobalID(), spellID));
target->LastSpellOnMe = spellID;
@@ -1231,7 +1233,7 @@ void Scriptable::DirectlyCastSpell(Scriptable *target, ieResRef spellref, int le
//if spell is illegal stop casting
int Scriptable::CastSpellPoint( const Point &target, bool deplete, bool instant, bool nointerrupt )
{
- LastTarget = 0;
+ LastSpellTarget = 0;
LastTargetPos.empty();
Actor *actor = NULL;
if (Type == ST_ACTOR) {
@@ -1265,7 +1267,7 @@ int Scriptable::CastSpellPoint( const Point &target, bool deplete, bool instant,
//if spell is illegal stop casting
int Scriptable::CastSpell( Scriptable* target, bool deplete, bool instant, bool nointerrupt )
{
- LastTarget = 0;
+ LastSpellTarget = 0;
LastTargetPos.empty();
Actor *actor = NULL;
if (Type == ST_ACTOR) {
@@ -1288,7 +1290,7 @@ int Scriptable::CastSpell( Scriptable* target, bool deplete, bool instant, bool
LastTargetPos = target->Pos;
if (target->Type==ST_ACTOR) {
- LastTarget = target->GetGlobalID();
+ LastSpellTarget = target->GetGlobalID();
}
if(!CheckWildSurge()) {
@@ -1474,10 +1476,10 @@ bool Scriptable::HandleHardcodedSurge(ieResRef surgeSpellRef, Spell *spl, Actor
tmp3 = caster->WMLevelMod; // also save caster level; the original didn't reroll the bonus
caster->Modified[IE_FORCESURGE] = 7;
caster->Modified[IE_SURGEMOD] = - caster->GetCasterLevel(spl->SpellType); // nulify the bonus
- if (LastTarget) {
- target = area->GetActorByGlobalID(LastTarget);
+ if (LastSpellTarget) {
+ target = area->GetActorByGlobalID(LastSpellTarget);
if (!target) {
- target = core->GetGame()->GetActorByGlobalID(LastTarget);
+ target = core->GetGame()->GetActorByGlobalID(LastSpellTarget);
}
}
if (!LastTargetPos.isempty()) {
View
2 gemrb/core/Scriptable/Scriptable.h
@@ -283,7 +283,7 @@ class GEM_EXPORT Scriptable {
// this is used by GUIScript :(
ieDword LastSpellOnMe; //Last spell cast on this scriptable
- ieDword LastTarget;
+ ieDword LastTarget, LastSpellTarget;
Point LastTargetPos;
int SpellHeader;
ieResRef SpellResRef;
View
2 gemrb/plugins/GUIScript/GUIScript.cpp
@@ -9135,7 +9135,7 @@ static PyObject* GemRB_ClearActions(PyObject * /*self*/, PyObject* args)
Py_INCREF( Py_None );
return Py_None;
}
- if (!(actor->GetNextStep()) && !actor->ModalState && !actor->LastTarget && actor->LastTargetPos.isempty()) {
+ if (!(actor->GetNextStep()) && !actor->ModalState && !actor->LastTarget && actor->LastTargetPos.isempty() && !actor->LastSpellTarget) {
Log(MESSAGE, "GuiScript","No breakable action!");
Py_INCREF( Py_None );
return Py_None;

0 comments on commit 8f9b125

Please sign in to comment.
Something went wrong with that request. Please try again.