From 8139f5976c209ec3d7d3b46c46664f93ce5c124a Mon Sep 17 00:00:00 2001 From: Jaka Kranjc Date: Wed, 11 Aug 2010 00:05:34 +0200 Subject: [PATCH] implemented iwd2 class mask matching --- gemrb/core/GameScript/Objects.cpp | 11 +++++++++-- gemrb/core/Scriptable/Actor.cpp | 12 ++++++++++++ gemrb/core/Scriptable/Actor.h | 2 ++ 3 files changed, 23 insertions(+), 2 deletions(-) diff --git a/gemrb/core/GameScript/Objects.cpp b/gemrb/core/GameScript/Objects.cpp index eef4bb885..8f39cd35c 100644 --- a/gemrb/core/GameScript/Objects.cpp +++ b/gemrb/core/GameScript/Objects.cpp @@ -1082,11 +1082,18 @@ int GameScript::ID_Class(Actor *actor, int parameter) return value > 0; } +// IE_CLASS holds only one class, not a bitmask like with iwd2 kits. The ids values +// are friendly to binary comparison, so we just need to build such a class value int GameScript::ID_ClassMask(Actor *actor, int parameter) { + // maybe we're lucky... int value = actor->GetStat(IE_CLASS); - if (parameter==value) return 1; - //check on multiclass + if (parameter&(1<<(value-1))) return 1; + + // otherwise iterate over all the classes + value = actor->GetClassMask(); + + if (parameter&value) return 1; return 0; } diff --git a/gemrb/core/Scriptable/Actor.cpp b/gemrb/core/Scriptable/Actor.cpp index 7c80be5e9..2aca41c52 100644 --- a/gemrb/core/Scriptable/Actor.cpp +++ b/gemrb/core/Scriptable/Actor.cpp @@ -137,6 +137,7 @@ static const int levelslotsbg[21]={ISFIGHTER, ISMAGE, ISFIGHTER, ISCLERIC, ISTHI static const int levelslotsiwd2[11]={IE_LEVELFIGHTER,IE_LEVELMAGE,IE_LEVELTHIEF, IE_LEVELBARBARIAN,IE_LEVELBARD,IE_LEVELCLERIC,IE_LEVELDRUID,IE_LEVELMONK, IE_LEVELPALADIN,IE_LEVELRANGER,IE_LEVELSORCEROR}; +static const unsigned int classesiwd2[ISCLASSES]={5, 11, 9, 1, 2, 3, 4, 6, 7, 8, 10}; //stat values are 0-255, so a byte is enough static ieByte featstats[MAX_FEATS]={0 @@ -6598,3 +6599,14 @@ bool Actor::PCInDark() const return false; } +int Actor::GetClassMask() +{ + int classmask = 0; + for (int i=0; i < ISCLASSES; i++) { + if (Modified[levelslotsiwd2[i]] > 0) { + classmask |= 1<<(classesiwd2[i]-1); + } + } + + return classmask; +} diff --git a/gemrb/core/Scriptable/Actor.h b/gemrb/core/Scriptable/Actor.h index f1c5b6479..79d70cd7c 100644 --- a/gemrb/core/Scriptable/Actor.h +++ b/gemrb/core/Scriptable/Actor.h @@ -683,5 +683,7 @@ public: bool InvalidSpellTarget(int spellnum, Actor *caster, int range); /* returns true if the lightmap under the actor is dark */ bool PCInDark() const; + /* computes the actor's classmask (iwd2) */ + int GetClassMask(); }; #endif -- 2.11.4.GIT