Commit 747d8d65 authored by louiz’'s avatar louiz’

Blink on a valid position only

parent f3ebb2e0
......@@ -75,3 +75,46 @@ bool Location::is_position_valid(World* world, const Position& pos) const
}
return true;
}
Position Location::find_nearest_free_position(World* world, const Position& pos) const
{
if (this->is_position_valid(world, pos))
return pos;
int distance = 20;
int i = 1;
Position res = pos;
// that's ugly, but well
while (true)
{
res.y = pos.y - distance*i;
for (auto x = pos.x - (distance*i); x <= pos.x + (distance*i); x += distance)
{
res.x = x;
if (this->is_position_valid(world, res))
return res;
}
res.y = pos.y + distance*i;
for (auto x = pos.x - (distance*i); x <= pos.x + (distance*i); x += distance)
{
res.x = x;
if (this->is_position_valid(world, res))
return res;
}
res.x = pos.x + distance*i;
for (auto y = pos.y - (distance*i); y <= pos.y + (distance*i); y += distance)
{
res.y = y;
if (this->is_position_valid(world, res))
return res;
}
res.x = pos.x - distance*i;
for (auto y = pos.y - (distance*i); y <= pos.y + (distance*i); y += distance)
{
res.y = y;
if (this->is_position_valid(world, res))
return res;
}
i++;
}
}
......@@ -29,6 +29,7 @@ public:
bool is_obstructing_position(const Position& pos,
const Fix16& width) const;
bool is_position_valid(World* world, const Position& pos) const;
Position find_nearest_free_position(World* world, const Position& pos) const;
private:
Fix16 width;
......
......@@ -29,9 +29,9 @@ bool BlinkTask::tick(World* world)
if (!this->cast_point_reached)
{
log_debug("blinking right now");
this->location->position() = this->location->find_nearest_free_position(world, this->destination);
world->callbacks->ability_casted(this->entity, AbilityType::Blink,
nullptr, this->destination);
this->location->position() = this->destination;
nullptr, this->location->position());
this->cast_point_reached = true;
}
if (this->backswing)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment