Skip to content

Commit

Permalink
handle ApplyDamage and ApplyDamagePercent actions like the Damage effect
Browse files Browse the repository at this point in the history
Fixes "Unhandled damagetype" errors when using those actions. Also simplify
damage type calculation from item headers.
  • Loading branch information
fizzet committed Jun 15, 2013
1 parent 91a2371 commit e4f54b5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 16 deletions.
6 changes: 3 additions & 3 deletions gemrb/core/GameScript/Actions.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -4631,7 +4631,7 @@ void GameScript::ApplyDamage(Scriptable* Sender, Action* parameters)
} else { } else {
damager=damagee; damager=damagee;
} }
damagee->Damage(parameters->int0Parameter, parameters->int1Parameter, damager); damagee->Damage(parameters->int0Parameter, parameters->int1Parameter >> 16, damager);
} }


void GameScript::ApplyDamagePercent(Scriptable* Sender, Action* parameters) void GameScript::ApplyDamagePercent(Scriptable* Sender, Action* parameters)
Expand All @@ -4649,9 +4649,9 @@ void GameScript::ApplyDamagePercent(Scriptable* Sender, Action* parameters)
damager=damagee; damager=damagee;
} }
//this, if the percent is calculated from the current hp //this, if the percent is calculated from the current hp
damagee->Damage((parameters->int0Parameter*damagee->Modified[IE_HITPOINTS])/100, parameters->int1Parameter, damager); damagee->Damage((parameters->int0Parameter*damagee->Modified[IE_HITPOINTS])/100, parameters->int1Parameter >> 16, damager);
//this, if the percent is calculated from the max hp //this, if the percent is calculated from the max hp
//damagee->Damage(parameters->int0Parameter, parameters->int1Parameter, damager, MOD_PERCENT); //damagee->Damage(parameters->int0Parameter, parameters->int1Parameter >> 16, damager, MOD_PERCENT);
} }


void GameScript::Damage(Scriptable* Sender, Action* parameters) void GameScript::Damage(Scriptable* Sender, Action* parameters)
Expand Down
16 changes: 3 additions & 13 deletions gemrb/core/Item.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -269,24 +269,14 @@ std::vector<DMGOpcodeInfo> Item::GetDamageOpcodesDetails(ITMExtHeader *header) c
for (int i=0; i< header->FeatureCount; i++) { for (int i=0; i< header->FeatureCount; i++) {
Effect *fx = header->features+i; Effect *fx = header->features+i;
if (fx->Opcode == damage_opcode) { if (fx->Opcode == damage_opcode) {
// it's not the same damagetype, these are different values, so we need a translation // damagetype is the same as in dmgtype.ids but GemRB uses those values
// shifted by two bytes
// 0-3 -> 0 (crushing) // 0-3 -> 0 (crushing)
// 2^16+[0-3] -> 1 (acid) // 2^16+[0-3] -> 1 (acid)
// 2^17+[0-3] -> 2 (cold) // 2^17+[0-3] -> 2 (cold)
// 2^18+[0-3] -> 4 (electricity) // 2^18+[0-3] -> 4 (electricity)
// and so on. Should be fine up until DAMAGE_MAGICFIRE, where we may start making wrong lookups // and so on. Should be fine up until DAMAGE_MAGICFIRE, where we may start making wrong lookups
ieDword damagetype = fx->Parameter2; ieDword damagetype = fx->Parameter2 >> 16;
if (damagetype < 4) {
damagetype = 0;
} else {
// 2^(log2(damagetype)-15-1)
int pow = 0;
while (damagetype) {
damagetype = damagetype>>1;
pow++;
}
damagetype = 1<<(pow - 17);
}
it = core->DamageInfoMap.find(damagetype); it = core->DamageInfoMap.find(damagetype);
if (it == core->DamageInfoMap.end()) { if (it == core->DamageInfoMap.end()) {
print("Unhandled damagetype: %d", damagetype); print("Unhandled damagetype: %d", damagetype);
Expand Down

0 comments on commit e4f54b5

Please sign in to comment.