Improve creature attack click
This commit is contained in:
parent
868abf3ef6
commit
3d7e80ea7a
|
@ -265,7 +265,8 @@ void Creature::walk(const Position& oldPos, const Position& newPos)
|
|||
|
||||
// get walk direction
|
||||
m_lastStepDirection = oldPos.getDirectionFromPosition(newPos);
|
||||
m_lastStepPosition = newPos;
|
||||
m_lastStepFromPosition = oldPos;
|
||||
m_lastStepToPosition = newPos;
|
||||
|
||||
// set current walking direction
|
||||
setDirection(m_lastStepDirection);
|
||||
|
@ -627,7 +628,7 @@ int Creature::getStepDuration()
|
|||
{
|
||||
int groundSpeed = 0;
|
||||
|
||||
Position tilePos = m_lastStepPosition;
|
||||
Position tilePos = m_lastStepToPosition;
|
||||
if(!tilePos.isValid())
|
||||
tilePos = m_position;
|
||||
const TilePtr& tile = g_map.getTile(tilePos);
|
||||
|
|
|
@ -85,6 +85,9 @@ public:
|
|||
Point getDrawOffset();
|
||||
int getStepDuration();
|
||||
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 int getDisplacementX();
|
||||
virtual int getDisplacementY();
|
||||
|
@ -154,7 +157,8 @@ protected:
|
|||
Point m_walkOffset;
|
||||
Otc::Direction m_walkTurnDirection;
|
||||
Otc::Direction m_lastStepDirection;
|
||||
Position m_lastStepPosition;
|
||||
Position m_lastStepFromPosition;
|
||||
Position m_lastStepToPosition;
|
||||
Position m_oldPosition;
|
||||
};
|
||||
|
||||
|
|
|
@ -371,6 +371,26 @@ CreaturePtr Tile::getTopCreature()
|
|||
}
|
||||
if(!creature && !m_walkingCreatures.empty())
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -85,6 +85,7 @@ public:
|
|||
int getDrawElevation() { return m_drawElevation; }
|
||||
std::vector<ItemPtr> getItems();
|
||||
std::vector<CreaturePtr> getCreatures();
|
||||
std::vector<CreaturePtr> getWalkingCreatures() { return m_walkingCreatures; }
|
||||
std::vector<ThingPtr> getThings() { return m_things; }
|
||||
ItemPtr getGround();
|
||||
int getGroundSpeed();
|
||||
|
|
Loading…
Reference in New Issue