Skip to content

Commit

Permalink
Merge pull request #712 from Wargus/doactionmove_war1gus
Browse files Browse the repository at this point in the history
Doactionmove war1gus
  • Loading branch information
Jarod42 authored Aug 18, 2024
2 parents 879c6cf + 09719a0 commit 90b3e15
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 12 deletions.
14 changes: 9 additions & 5 deletions src/action/action_move.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,9 @@ int DoActionMove(CUnit &unit)
Vec2i posd{}; // movement in tile.
int d{};

if (unit.Moving != 1 && (&unit.Type->Animations->Move != unit.Anim.CurrAnim || !unit.Anim.Wait)) {
if (unit.Moving != 1
&& (&unit.Type->Animations->Move != unit.Anim.CurrAnim
|| (unit.Anim.Wait == 0 && unit.Anim.Anim == 0))) {
if (unit.Anim.Unbreakable && unit.Moving > 1) {
// subtile movement, we're finished, but inside an unbreakable animation that we have to finish
int m = UnitShowAnimationScaled(unit, &unit.Type->Animations->Move, 1) >> 1;
Expand Down Expand Up @@ -242,9 +244,11 @@ int DoActionMove(CUnit &unit)
unit.Frame = unit.Type->StillFrame;
UnitHeadingFromDeltaXY(unit, posd);
} else {
posd.x = Heading2X[unit.Direction / NextDirection];
posd.y = Heading2Y[unit.Direction / NextDirection];
d = unit.pathFinderData->output.Length + 1;
const auto direction =
unit.pathFinderData->output.Path[unit.pathFinderData->output.Length - 1];
posd.x = Heading2X[direction];
posd.y = Heading2Y[direction];
d = unit.pathFinderData->output.Length;
}

unit.pathFinderData->output.Cycles++;// reset have to be manualy controlled by caller.
Expand All @@ -266,7 +270,7 @@ int DoActionMove(CUnit &unit)

// Finished move to next tile, set Moving to 0 so we recalculate the path
// next frame
if ((!unit.Anim.Unbreakable && !unit.IX && !unit.IY) || reached_next_tile ) {
if ((!unit.Anim.Unbreakable && !unit.IX && !unit.IY) || reached_next_tile) {
unit.Moving = 0;
}
return d;
Expand Down
4 changes: 2 additions & 2 deletions src/pathfinder/pathfinder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -445,12 +445,13 @@ std::pair<int, Vec2i> NextPathElement(CUnit &unit)
if (result == PF_REACHED) {
return {result, {}};
}
} else {
output.Length--;
}

Vec2i dir(Heading2X[(int) output.Path[output.Length - 1]],
Heading2Y[(int) output.Path[output.Length - 1]]);
int result = output.Length;
output.Length--;
if (!UnitCanBeAt(unit, unit.tilePos + dir)) {
// If obstructing unit is moving, wait for a bit.
if (output.Fast) {
Expand All @@ -474,7 +475,6 @@ std::pair<int, Vec2i> NextPathElement(CUnit &unit)
dir = {0, 0};
} else {
result = output.Length;
output.Length--;
}
}
}
Expand Down
10 changes: 5 additions & 5 deletions tests/stratagus/test_pathfinder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ TEST_CASE("PathFinding on clear map 128x128")

CHECK(d == dist);

CHECK(unit.pathFinderData->output.Length == dist - 1);
CHECK(dest == FollowedPath(unit.tilePos + dir, unit.pathFinderData->output));
CHECK(unit.pathFinderData->output.Length == dist);
CHECK(dest == FollowedPath(unit.tilePos, unit.pathFinderData->output));

unit.Orders.clear();
}
Expand All @@ -132,10 +132,10 @@ TEST_CASE("PathFinding on clear map 128x128")

CHECK(0 < d);
CHECK(d <= std::size(unit.pathFinderData->output.Path));
CHECK(unit.pathFinderData->output.Length + unit.pathFinderData->output.OverflowLength == dist - 1);
CHECK(unit.pathFinderData->output.Length + unit.pathFinderData->output.OverflowLength == dist);

CHECK(unit.pathFinderData->output.Length == d - 1);
CHECK(unit.tilePos + Vec2i(0, d) == FollowedPath(unit.tilePos + dir, unit.pathFinderData->output));
CHECK(unit.pathFinderData->output.Length == d);
CHECK(unit.tilePos + Vec2i(0, d) == FollowedPath(unit.tilePos, unit.pathFinderData->output));

unit.Orders.clear();
}
Expand Down

0 comments on commit 90b3e15

Please sign in to comment.