Project

General

Profile

Bug #2369 » 0034-Send-at-max-MAX_LEN_ROUTE-goto-route-steps-to-the-se.patch

S3_2 - Marko Lindqvist, 10/17/2026 10:13 PM

View differences:

client/goto.c
/************************************************************************//**
Creates orders for a path as a goto or patrol route.
If route is too long, only MAX_LEN_ROUTE steps are written,
and final_order is not written as it should only come after the full route.
****************************************************************************/
static void make_path_orders(struct unit *punit, struct pf_path *path,
static bool make_path_orders(struct unit *punit, struct pf_path *path,
enum unit_orders orders,
struct unit_order *final_order,
struct unit_order *order_list,
......
{
int i;
struct tile *old_tile;
bool cut = FALSE;
fc_assert_ret(path != NULL);
fc_assert_ret_msg(unit_tile(punit) == path->positions[0].tile,
"Unit %d has moved without goto cancellation.",
punit->id);
fc_assert_ret(length != NULL);
fc_assert_ret_val(path != NULL, FALSE);
fc_assert_ret_val_msg(unit_tile(punit) == path->positions[0].tile, FALSE,
"Unit %d has moved without goto cancellation.",
punit->id);
fc_assert_ret_val(length != NULL, FALSE);
/* We skip the start position. */
*length = path->length - 1;
fc_assert(*length < MAX_LEN_ROUTE);
if (*length > MAX_LEN_ROUTE) {
*length = MAX_LEN_ROUTE;
cut = TRUE;
} else if (final_order && *length == MAX_LEN_ROUTE) {
/* Everything but the final_order fits */
cut = TRUE;
}
if (cut) {
log_warn(_("Too long goto route. Cut."));
}
fc_assert(*length <= MAX_LEN_ROUTE);
old_tile = path->positions[0].tile;
/* If the path has n positions it takes n-1 steps. */
for (i = 0; i < path->length - 1; i++) {
for (i = 0; i < *length; i++) {
struct tile *new_tile = path->positions[i + 1].tile;
if (same_pos(new_tile, old_tile)) {
......
}
}
if (final_order) {
if (final_order && !cut) {
/* Append the final order after moving to the target tile. */
order_list[i].order = final_order->order;
order_list[i].dir = final_order->dir;
......
if (dest_tile) {
*dest_tile = tile_index(old_tile);
}
return !cut;
}
/************************************************************************//**
(2-2/2)