Improve creature attack click

This commit is contained in:
Eduardo Bart 2012-08-21 21:27:48 -03:00
parent 868abf3ef6
commit 3d7e80ea7a
4 changed files with 29 additions and 3 deletions

View File

@ -265,7 +265,8 @@ void Creature::walk(const Position& oldPos, const Position& newPos)
// get walk direction // get walk direction
m_lastStepDirection = oldPos.getDirectionFromPosition(newPos); m_lastStepDirection = oldPos.getDirectionFromPosition(newPos);
m_lastStepPosition = newPos; m_lastStepFromPosition = oldPos;
m_lastStepToPosition = newPos;
// set current walking direction // set current walking direction
setDirection(m_lastStepDirection); setDirection(m_lastStepDirection);
@ -627,7 +628,7 @@ int Creature::getStepDuration()
{ {
int groundSpeed = 0; int groundSpeed = 0;
Position tilePos = m_lastStepPosition; Position tilePos = m_lastStepToPosition;
if(!tilePos.isValid()) if(!tilePos.isValid())
tilePos = m_position; tilePos = m_position;
const TilePtr& tile = g_map.getTile(tilePos); const TilePtr& tile = g_map.getTile(tilePos);

View File

@ -85,6 +85,9 @@ public:
Point getDrawOffset(); Point getDrawOffset();
int getStepDuration(); int getStepDuration();
Point getWalkOffset() { return m_walkOffset; } Point getWalkOffset() { return m_walkOffset; }
Position getLastStepFromPosition() { return m_lastStepFromPosition; }
Position getLastStepToPosition() { return m_lastStepToPosition; }
float getStepProgress() { return m_walkTimer.ticksElapsed() / getStepDuration(); }
virtual Point getDisplacement(); virtual Point getDisplacement();
virtual int getDisplacementX(); virtual int getDisplacementX();
virtual int getDisplacementY(); virtual int getDisplacementY();
@ -154,7 +157,8 @@ protected:
Point m_walkOffset; Point m_walkOffset;
Otc::Direction m_walkTurnDirection; Otc::Direction m_walkTurnDirection;
Otc::Direction m_lastStepDirection; Otc::Direction m_lastStepDirection;
Position m_lastStepPosition; Position m_lastStepFromPosition;
Position m_lastStepToPosition;
Position m_oldPosition; Position m_oldPosition;
}; };

View File

@ -371,6 +371,26 @@ CreaturePtr Tile::getTopCreature()
} }
if(!creature && !m_walkingCreatures.empty()) if(!creature && !m_walkingCreatures.empty())
creature = m_walkingCreatures.back(); creature = m_walkingCreatures.back();
// check for walking creatures in tiles around
if(!creature) {
for(int xi=-1;xi<=1;++xi) {
for(int yi=-1;yi<=1;++yi) {
Position pos = m_position.translated(xi, yi);
if(pos == m_position)
continue;
const TilePtr& tile = g_map.getTile(pos);
if(tile) {
for(const CreaturePtr& c : tile->getCreatures()) {
if(c->isWalking() && c->getLastStepFromPosition() == m_position && c->getStepProgress() < 0.75f) {
creature = c;
}
}
}
}
}
}
return creature; return creature;
} }

View File

@ -85,6 +85,7 @@ public:
int getDrawElevation() { return m_drawElevation; } int getDrawElevation() { return m_drawElevation; }
std::vector<ItemPtr> getItems(); std::vector<ItemPtr> getItems();
std::vector<CreaturePtr> getCreatures(); std::vector<CreaturePtr> getCreatures();
std::vector<CreaturePtr> getWalkingCreatures() { return m_walkingCreatures; }
std::vector<ThingPtr> getThings() { return m_things; } std::vector<ThingPtr> getThings() { return m_things; }
ItemPtr getGround(); ItemPtr getGround();
int getGroundSpeed(); int getGroundSpeed();