Skip to content

Commit

Permalink
fix(creature): canSee fucntion logic
Browse files Browse the repository at this point in the history
  • Loading branch information
JoaoCRDias committed Aug 18, 2022
1 parent 398ddba commit 25b5773
Showing 1 changed file with 4 additions and 15 deletions.
19 changes: 4 additions & 15 deletions src/creatures/creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,23 +49,12 @@ Creature::~Creature()

bool Creature::canSee(const Position& myPos, const Position& pos, int32_t viewRangeX, int32_t viewRangeY)
{
if (myPos.z <= 7) {
//we are on ground level or above (7 -> 0)
//view is from 7 -> 0
if (pos.z > 7) {
return false;
}
} else if (myPos.z >= 8) {
//we are underground (8 -> 15)
//view is +/- 2 from the floor we stand on
if (Position::getDistanceZ(myPos, pos) > 2) {
if (myPos.z != pos.z) {
return false;
}
}

const int_fast32_t offsetz = myPos.getZ() - pos.getZ();
return (pos.getX() >= myPos.getX() - viewRangeX + offsetz) && (pos.getX() <= myPos.getX() + viewRangeX + offsetz)
&& (pos.getY() >= myPos.getY() - viewRangeY + offsetz) && (pos.getY() <= myPos.getY() + viewRangeY + offsetz);
return (pos.getX() >= myPos.getX() - viewRangeX) && (pos.getX() <= myPos.getX() + viewRangeX)
&& (pos.getY() >= myPos.getY() - viewRangeY) && (pos.getY() <= myPos.getY() + viewRangeY);
}

bool Creature::canSee(const Position& pos) const
Expand Down Expand Up @@ -765,7 +754,7 @@ bool Creature::dropCorpse(Creature* lastHitCreature, Creature* mostDamageCreatur
int32_t money = 0;
for (Item* item : corpse->getContainer()->getItems()) {
if (uint32_t worth = item->getWorth(); worth > 0) {
money += worth;
money += worth;
g_game().internalRemoveItem(item);
}
}
Expand Down

0 comments on commit 25b5773

Please sign in to comment.