Skip to content

Commit

Permalink
Account for unit loading after unload in path finding
Browse files Browse the repository at this point in the history
Since units are (now) automatically loaded back after unloading to a
non-native tile, make the goto code aware of this to avoid generating
invalid paths. Also unify the handling of ACTION_TRANSPORT_DISEMBARK1
and 2.
  • Loading branch information
lmoureaux committed Aug 30, 2023
1 parent aed78b9 commit 2111a76
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 20 deletions.
2 changes: 1 addition & 1 deletion common/path.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

#pragma once

#include <unit.h>
#include "unit.h"

#include <vector>

Expand Down
39 changes: 20 additions & 19 deletions common/path_finder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -397,26 +397,27 @@ void path_finder::path_finder_private::attempt_unload(detail::vertex &source)
// Nearby tiles
adjc_iterate(&(wld.map), probe.tile, target)
{
if (is_action_enabled_unit_on_tile(ACTION_TRANSPORT_DISEMBARK1, &probe,
target, nullptr)) {
auto next = source.child_for_action(ACTION_TRANSPORT_DISEMBARK1,
probe, target);
next.moved = true;
next.loaded = nullptr;
// See unithand.cpp:do_disembark
next.moves_left -= map_move_cost_unit(&(wld.map), &probe, target);
maybe_insert_vertex(next);
}
// Thanks sveinung
if (is_action_enabled_unit_on_tile(ACTION_TRANSPORT_DISEMBARK2, &probe,
target, nullptr)) {
auto next = source.child_for_action(ACTION_TRANSPORT_DISEMBARK2,
probe, target);
next.moved = true;
next.loaded = nullptr;
// See unithand.cpp:do_disembark
next.moves_left -= map_move_cost_unit(&(wld.map), &probe, target);
maybe_insert_vertex(next);
for (auto action :
{ACTION_TRANSPORT_DISEMBARK1, ACTION_TRANSPORT_DISEMBARK2}) {
if (is_action_enabled_unit_on_tile(action, &probe, target,
nullptr)) {
auto next = source.child_for_action(action, probe, target);
next.moved = true;
// See unithand.cpp:do_disembark
next.moves_left -= map_move_cost_unit(&(wld.map), &probe, target);

if (can_unit_survive_at_tile(&(wld.map), &probe, target)) {
next.loaded = nullptr;
} else {
// Unit need to load in a transport to survive
// FIXME Should consider some action enabler here... Server side
// code doesn't do it.
next.loaded = transporter_for_unit_at(&probe, target);
}

maybe_insert_vertex(next);
}
}
}
adjc_iterate_end;
Expand Down

0 comments on commit 2111a76

Please sign in to comment.