[Freeciv-Dev] Re: (PR#18390) [Bug] Pathfinding & UCF_TERRAIN_SPEED
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: |
[Freeciv-Dev] Re: (PR#18390) [Bug] Pathfinding & UCF_TERRAIN_SPEED |
From: |
"Marko Lindqvist" <cazfi74@xxxxxxxxx> |
Date: |
Sat, 8 Jul 2006 04:47:46 -0700 |
Reply-to: |
bugs@xxxxxxxxxxx |
<URL: http://bugs.freeciv.org/Ticket/Display.html?id=18390 >
Marko Lindqvist wrote:
>
> Pathfinding does not care about UCF_TERRAIN_SPEED flag. Also
> generate_warmap() seems to be affected.
First attempt to fix pathfinding part. Some minor bugs fixed in the
process, mainly dealing with passengers entering/leaving ferry.
- ML
diff -Nurd -X.diff_ignore freeciv/ai/aitools.c freeciv/ai/aitools.c
--- freeciv/ai/aitools.c 2006-07-07 22:29:52.953125000 +0300
+++ freeciv/ai/aitools.c 2006-07-08 03:20:27.093750000 +0300
@@ -1005,8 +1005,8 @@
}
/* Try not to end move next to an enemy if we can avoid it by waiting */
- if (punit->moves_left <= map_move_cost(punit, ptile)
- && unit_move_rate(punit) > map_move_cost(punit, ptile)
+ if (punit->moves_left <= map_move_cost_unit(punit, ptile)
+ && unit_move_rate(punit) > map_move_cost_unit(punit, ptile)
&& enemies_at(punit, ptile)
&& !enemies_at(punit, punit->tile)) {
UNIT_LOG(LOG_DEBUG, punit, "ending move early to stay out of trouble");
diff -Nurd -X.diff_ignore freeciv/common/aicore/path_finding.h
freeciv/common/aicore/path_finding.h
--- freeciv/common/aicore/path_finding.h 2006-07-08 00:24:00.484375000
+0300
+++ freeciv/common/aicore/path_finding.h 2006-07-08 02:08:49.343750000
+0300
@@ -320,6 +320,7 @@
int fuel; /* Should be 1 for units without fuel. */
struct player *owner;
+ struct unit_type *utype;
bv_flags unit_flags; /* Like F_MARINE and F_TRIREME */
bool omniscience; /* Do we care if the tile is visible? */
diff -Nurd -X.diff_ignore freeciv/common/aicore/pf_tools.c
freeciv/common/aicore/pf_tools.c
--- freeciv/common/aicore/pf_tools.c 2006-07-07 22:30:46.468750000 +0300
+++ freeciv/common/aicore/pf_tools.c 2006-07-08 14:33:46.359375000 +0300
@@ -30,6 +30,20 @@
static void pft_fill_unit_default_parameter(struct pf_parameter *parameter,
struct unit *punit);
+/*************************************************************
+ Cost of moving one normal step.
+*************************************************************/
+static inline int single_move_cost(const struct pf_parameter *param,
+ const struct tile *src_tile,
+ const struct tile *dest_tile)
+{
+ if (unit_class_flag(get_unit_class(param->utype), UCF_TERRAIN_SPEED)) {
+ return map_move_cost(src_tile, dest_tile);
+ } else {
+ return SINGLE_MOVE;
+ }
+}
+
/* ===================== Move Cost Callbacks ========================= */
/*************************************************************
@@ -40,8 +54,11 @@
static int seamove(const struct tile *ptile, enum direction8 dir,
const struct tile *ptile1, struct pf_parameter *param)
{
- if (is_ocean(ptile1->terrain) || ptile1->city
- || is_non_allied_unit_tile(ptile1, param->owner)) {
+ if (is_ocean(ptile1->terrain)) {
+ return single_move_cost(param, ptile, ptile1);
+ } else if (ptile1->city
+ || is_non_allied_unit_tile(ptile1, param->owner)) {
+ /* Entering port or shore bombardment */
return SINGLE_MOVE;
} else {
return PF_IMPOSSIBLE_MC;
@@ -55,7 +72,7 @@
const struct tile *ptile1,
struct pf_parameter *param)
{
- return SINGLE_MOVE; /* simple, eh? */
+ return single_move_cost(param, ptile, ptile1);
}
/*************************************************************
@@ -66,9 +83,10 @@
const struct tile *ptile1,
struct pf_parameter *param)
{
- /* MOVE_COST_FOR_VALID_SEA_STEP means ships can move between */
- if (map_move_cost_ai(ptile, ptile1) == MOVE_COST_FOR_VALID_SEA_STEP
- && !is_non_allied_city_tile(ptile1, param->owner)) {
+ if (is_ocean(ptile1->terrain)) {
+ return single_move_cost(param, ptile, ptile1);
+ } else if (is_allied_city_tile(ptile1, param->owner)) {
+ /* Entering port */
return SINGLE_MOVE;
} else {
return PF_IMPOSSIBLE_MC;
@@ -86,14 +104,17 @@
const struct tile *ptile1,
struct pf_parameter *param)
{
- if (is_ocean(ptile->terrain)) {
- return SINGLE_MOVE;
- } else if (is_allied_city_tile(ptile, param->owner)
- && is_ocean(ptile1->terrain)) {
+ if (is_allied_city_tile(ptile, param->owner)
+ && is_ocean(ptile1->terrain)) {
+ return single_move_cost(param, ptile, ptile1);
+ } else if (!is_ocean(ptile->terrain)) {
+ return PF_IMPOSSIBLE_MC;
+ } else if (is_ocean(ptile1->terrain)) {
+ return single_move_cost(param, ptile, ptile1);
+ } else {
+ /* Entering port or bombardment */
return SINGLE_MOVE;
}
-
- return PF_IMPOSSIBLE_MC;
}
/**********************************************************************
@@ -108,10 +129,13 @@
if (is_non_allied_unit_tile(src_tile, param->owner)) {
return PF_IMPOSSIBLE_MC;
}
+ if (is_ocean(dest_tile->terrain)) {
+ return single_move_cost(param, src_tile, dest_tile);
+ }
return SINGLE_MOVE;
} else if (is_allied_city_tile(src_tile, param->owner)
&& is_ocean(dest_tile->terrain)) {
- return SINGLE_MOVE;
+ return single_move_cost(param, src_tile, dest_tile);
}
return PF_IMPOSSIBLE_MC;
@@ -139,10 +163,10 @@
|| is_non_allied_city_tile(ptile1, param->owner))) {
move_cost = PF_IMPOSSIBLE_MC;
} else {
- move_cost = terrain1->movement_cost * SINGLE_MOVE;
+ move_cost = single_move_cost(param, ptile, ptile1);
}
} else {
- move_cost = map_move_cost_ai(ptile, ptile1);
+ move_cost = single_move_cost(param, ptile, ptile1);
}
return move_cost;
@@ -174,7 +198,7 @@
move_cost = tgt_tile->terrain->movement_cost * SINGLE_MOVE;
} else if (BV_ISSET(param->unit_flags, F_MARINES)) {
/* Can attack!! */
- move_cost = SINGLE_MOVE;
+ move_cost = single_move_cost(param, src_tile, tgt_tile);
} else {
move_cost = PF_IMPOSSIBLE_MC;
}
@@ -189,8 +213,7 @@
/* Attack! */
move_cost = SINGLE_MOVE;
} else {
- /* Normal move */
- move_cost = map_move_cost_ai(src_tile, tgt_tile);
+ move_cost = single_move_cost(param, src_tile, tgt_tile);
}
}
@@ -210,7 +233,7 @@
} else if (is_ocean(terrain1)) {
move_cost = SINGLE_MOVE;
} else {
- move_cost = ptile->move_cost[dir];
+ move_cost = single_move_cost(param, ptile, ptile1);
}
which will achieve the same without call-back.
************************************************************/
@@ -223,10 +246,8 @@
if (is_ocean(terrain1)) {
move_cost = SINGLE_MOVE;
- } else if (is_ocean(ptile->terrain)) {
- move_cost = terrain1->movement_cost * SINGLE_MOVE;
} else {
- move_cost = map_move_cost_ai(ptile, ptile1);
+ move_cost = single_move_cost(param, ptile, ptile1);
}
return move_cost;
@@ -287,9 +308,12 @@
} else {
move_cost = MOVE_COST_ROAD;
}
+ } else if (unit_class_flag(get_unit_class(param->utype),
+ UCF_TERRAIN_SPEED)) {
+ move_cost = (map_move_cost(ptile, ptile1) != 0
+ ? MOVE_COST_ROAD : 0);
} else {
- move_cost = (map_move_cost_ai(ptile, ptile1) != 0
- ? MOVE_COST_ROAD : 0);
+ move_cost = SINGLE_MOVE;
}
return move_cost;
}
@@ -819,6 +843,7 @@
parameter->fuel_left_initially = 1;
}
parameter->owner = unit_owner(punit);
+ parameter->utype = unit_type(punit);
parameter->unit_flags = unit_type(punit)->flags;
parameter->omniscience = !ai_handicap(unit_owner(punit), H_MAP);
diff -Nurd -X.diff_ignore freeciv/common/map.c freeciv/common/map.c
--- freeciv/common/map.c 2006-07-08 02:57:21.734375000 +0300
+++ freeciv/common/map.c 2006-07-08 03:16:12.375000000 +0300
@@ -652,6 +652,7 @@
return SINGLE_MOVE/3;
}
if (!native) {
+ /* Loading to transport or entering port */
return SINGLE_MOVE;
}
if (tile_has_special(t1, S_ROAD) && tile_has_special(t2, S_ROAD)) {
@@ -735,12 +736,20 @@
The cost to move punit from where it is to tile x,y.
It is assumed the move is a valid one, e.g. the tiles are adjacent.
***************************************************************/
-int map_move_cost(struct unit *punit, const struct tile *ptile)
+int map_move_cost_unit(struct unit *punit, const struct tile *ptile)
{
return tile_move_cost_ptrs(punit, punit->tile, ptile);
}
/***************************************************************
+ Move cost between two tiles
+***************************************************************/
+int map_move_cost(const struct tile *src_tile, const struct tile *dst_tile)
+{
+ return tile_move_cost_ptrs(NULL, src_tile, dst_tile);
+}
+
+/***************************************************************
...
***************************************************************/
bool is_tiles_adjacent(const struct tile *tile0, const struct tile *tile1)
diff -Nurd -X.diff_ignore freeciv/common/map.h freeciv/common/map.h
--- freeciv/common/map.h 2006-07-07 22:30:46.984375000 +0300
+++ freeciv/common/map.h 2006-07-08 03:16:02.421875000 +0300
@@ -243,8 +243,9 @@
bool is_tiles_adjacent(const struct tile *ptile0, const struct tile *ptile1);
bool is_move_cardinal(const struct tile *src_tile,
const struct tile *dst_tile);
-int map_move_cost(struct unit *punit, const struct tile *ptile);
+int map_move_cost_unit(struct unit *punit, const struct tile *ptile);
int map_move_cost_ai(const struct tile *tile0, const struct tile *tile1);
+int map_move_cost(const struct tile *src_tile, const struct tile *dst_tile);
bool is_safe_ocean(const struct tile *ptile);
bool is_cardinally_adj_to_ocean(const struct tile *ptile);
bv_special get_tile_infrastructure_set(const struct tile *ptile,
diff -Nurd -X.diff_ignore freeciv/server/diplomats.c freeciv/server/diplomats.c
--- freeciv/server/diplomats.c 2006-07-07 22:32:38.437500000 +0300
+++ freeciv/server/diplomats.c 2006-07-08 03:21:24.734375000 +0300
@@ -1002,7 +1002,7 @@
static void diplomat_charge_movement (struct unit *pdiplomat, struct tile
*ptile)
{
pdiplomat->moves_left -=
- map_move_cost (pdiplomat, ptile);
+ map_move_cost_unit(pdiplomat, ptile);
if (pdiplomat->moves_left < 0) {
pdiplomat->moves_left = 0;
}
diff -Nurd -X.diff_ignore freeciv/server/unithand.c freeciv/server/unithand.c
--- freeciv/server/unithand.c 2006-07-08 00:15:12.718750000 +0300
+++ freeciv/server/unithand.c 2006-07-08 03:22:58.359375000 +0300
@@ -1137,7 +1137,7 @@
}
if (can_unit_move_to_tile_with_notify(punit, pdesttile, igzoc)) {
- int move_cost = map_move_cost(punit, pdesttile);
+ int move_cost = map_move_cost_unit(punit, pdesttile);
(void) move_unit(punit, pdesttile, move_cost);
|
|