Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix disembarking without losing MP through adjacent transport #2025

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 3 additions & 13 deletions common/map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -759,19 +759,9 @@ int tile_move_cost_ptrs(const struct civ_map *nmap, const struct unit *punit,

} else if (!is_native_tile_to_class(pclass, t2)
|| !is_native_tile_to_class(pclass, t1)) {
if (tile_city(t1) == nullptr) {
/* Loading to/disembarking from transport. */

// UTYF_IGTER units get move benefit.
return (utype_has_flag(punittype, UTYF_IGTER) ? MOVE_COST_IGTER
: SINGLE_MOVE);
} else {
/* Entering/leaving port. */

// UTYF_IGTER units get move benefit.
return (utype_has_flag(punittype, UTYF_IGTER) ? MOVE_COST_IGTER
: SINGLE_MOVE);
}
// UTYF_IGTER units get move benefit.
return (utype_has_flag(punittype, UTYF_IGTER) ? MOVE_COST_IGTER
: SINGLE_MOVE);
}

cost = tile_terrain(t2)->movement_cost * SINGLE_MOVE;
Expand Down
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
2 changes: 1 addition & 1 deletion server/unithand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,7 @@ static bool do_disembark(struct player *act_player, struct unit *act_unit,
fc_assert_ret_val(tgt_tile, false);
fc_assert_ret_val(paction, false);

unit_move(act_unit, tgt_tile, move_cost, nullptr, false, false);
unit_move(act_unit, tgt_tile, move_cost, nullptr, true, false);

return true;
}
Expand Down
2 changes: 1 addition & 1 deletion server/unittools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2522,7 +2522,7 @@ void kill_unit(struct unit *pkiller, struct unit *punit, bool vet)
/* FIXME: Shouldn't unit_move_handling() be used here? This is
* the unit escaping by moving itself. It should therefore
* respect movement rules. */
unit_move(vunit, dsttile, move_cost, nullptr, false, false);
unit_move(vunit, dsttile, move_cost, nullptr, true, false);
num_escaped[player_index(vplayer)]++;
escaped = true;
unitcount--;
Expand Down
Loading