From 3cb539b0937f6021001f499c804d6ba190aa2bcc Mon Sep 17 00:00:00 2001 From: Marko Lindqvist Date: Sat, 5 Nov 2022 09:45:10 +0200 Subject: [PATCH 33/33] Path finding: Make node cost an int Short was overflowing there when terrain move cost in fragments is high. Reported by Lexxie See osdn #46039 Signed-off-by: Marko Lindqvist --- common/aicore/path_finding.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/common/aicore/path_finding.c b/common/aicore/path_finding.c index 2df24b359c..8edc910cd0 100644 --- a/common/aicore/path_finding.c +++ b/common/aicore/path_finding.c @@ -204,7 +204,9 @@ static void pf_position_fill_start_tile(struct pf_position *pos, /* Node definition. Note we try to have the smallest data as possible. */ struct pf_normal_node { - signed short cost; /* total_MC. 'cost' may be negative, see comment in + /* Note that 'short' here would be followed with padding anyway, + * for alignment reasons, */ + signed int cost; /* total_MC. 'cost' may be negative, see comment in * pf_turns(). */ unsigned extra_cost; /* total_EC. Can be huge, (higher than 'cost'). */ unsigned dir_to_here : 4; /* Direction from which we came. It's @@ -940,7 +942,9 @@ static struct pf_map *pf_normal_map_new(const struct pf_parameter *parameter) /* Node definition. Note we try to have the smallest data as possible. */ struct pf_danger_node { - signed short cost; /* total_MC. 'cost' may be negative, see comment in + /* Note that 'short' here would be followed with padding anyway, + * for alignment reasons, */ + signed int cost; /* total_MC. 'cost' may be negative, see comment in * pf_turns(). */ unsigned extra_cost; /* total_EC. Can be huge, (higher than 'cost'). */ unsigned dir_to_here : 4; /* Direction from which we came. It's @@ -1942,7 +1946,9 @@ struct pf_fuel_pos; /* Node definition. Note we try to have the smallest data as possible. */ struct pf_fuel_node { - signed short cost; /* total_MC. 'cost' may be negative, see comment in + /* Note that 'short' here would be followed with padding anyway, + * for alignment reasons, */ + signed int cost; /* total_MC. 'cost' may be negative, see comment in * pf_turns(). */ unsigned extra_cost; /* total_EC. Can be huge, (higher than 'cost'). */ unsigned moves_left : 12; /* Moves left at this position. */ -- 2.35.1