Permalink
Browse files

Linear search is not required here.

  • Loading branch information...
1 parent 359e9d3 commit f4d0105422ed482ae4bd694f02bc1fe112cf1abd @piotrrak piotrrak committed Dec 26, 2012
Showing with 12 additions and 12 deletions.
  1. +6 −6 src/Avatar.cpp
  2. +6 −6 src/Enemy.cpp
View
@@ -706,12 +706,12 @@ bool Avatar::takeHit(const Hazard &h) {
// apply elemental resistance
int vulnerable;
- for (unsigned int i=0; i<stats.vulnerable.size(); i++) {
- if (h.trait_elemental == (signed)i) {
- if (MAX_RESIST < stats.vulnerable[i] && stats.vulnerable[i] < 100) vulnerable = MAX_RESIST;
- else vulnerable = stats.vulnerable[i];
- dmg = (dmg * vulnerable) / 100;
- }
+ if (h.trait_elemental >= 0 && unsigned(h.trait_elemental) < stats.vulnerable.size())
+ {
+ unsigned i = h.trait_elemental;
+ if (MAX_RESIST < stats.vulnerable[i] && stats.vulnerable[i] < 100) vulnerable = MAX_RESIST;
+ else vulnerable = stats.vulnerable[i];
+ dmg = (dmg * vulnerable) / 100;
}
if (!h.trait_armor_penetration) { // armor penetration ignores all absorption
View
@@ -179,12 +179,12 @@ bool Enemy::takeHit(const Hazard &h) {
// apply elemental resistance
int vulnerable;
- for (unsigned int i=0; i<stats.vulnerable.size(); i++) {
- if (h.trait_elemental == (signed)i) {
- if (MAX_RESIST < stats.vulnerable[i] && stats.vulnerable[i] < 100) vulnerable = MAX_RESIST;
- else vulnerable = stats.vulnerable[i];
- dmg = (dmg * vulnerable) / 100;
- }
+ if (h.trait_elemental >= 0 && unsigned(h.trait_elemental) < stats.vulnerable.size())
+ {
+ unsigned i = h.trait_elemental;
+ if (MAX_RESIST < stats.vulnerable[i] && stats.vulnerable[i] < 100) vulnerable = MAX_RESIST;
+ else vulnerable = stats.vulnerable[i];
+ dmg = (dmg * vulnerable) / 100;
}
if (!h.trait_armor_penetration) { // armor penetration ignores all absorption

0 comments on commit f4d0105

Please sign in to comment.