Index: client/goto.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/client/goto.c,v retrieving revision 1.53 diff -u -r1.53 goto.c --- client/goto.c 2003/07/07 19:14:36 1.53 +++ client/goto.c 2003/07/19 16:04:15 @@ -319,10 +319,11 @@ } /********************************************************************** - PF callback to prohibit going into the unknown. + PF callback to prohibit going into the unknown. Also makes sure we + don't plan our route through enemy city/tile. ***********************************************************************/ -static enum tile_behavior get_TB(int x, int y, enum known_type known, - struct pf_parameter *param) +static enum tile_behavior get_TB_aggr(int x, int y, enum known_type known, + struct pf_parameter *param) { struct tile *ptile = map_get_tile(x, y); @@ -338,6 +339,24 @@ } /********************************************************************** + PF callback to prohibit going into the unknown. Also makes sure we + don't plan to attack anyone. +***********************************************************************/ +static enum tile_behavior get_TB_peace(int x, int y, enum known_type known, + struct pf_parameter *param) +{ + struct tile *ptile = map_get_tile(x, y); + + if (known == TILE_UNKNOWN + || is_non_allied_unit_tile(ptile, param->owner) + || is_non_allied_city_tile(ptile, param->owner)) { + /* Can't attack */ + return TB_IGNORE; + } + return TB_NORMAL; +} + +/********************************************************************** Enter the goto state: activate, prepare PF-template and add the initial part. ***********************************************************************/ @@ -353,7 +372,11 @@ assert(goto_map.template.get_EC == NULL); goto_map.template.get_EC = get_EC; assert(goto_map.template.get_TB == NULL); - goto_map.template.get_TB = get_TB; + if (unit_type(punit)->attack_strength > 0) { + goto_map.template.get_TB = get_TB_aggr; + } else { + goto_map.template.get_TB = get_TB_peace; + } goto_map.template.turn_mode = TM_WORST_TIME; add_part(); Index: common/aicore/pf_tools.c =================================================================== RCS file: /home/freeciv/CVS/freeciv/common/aicore/pf_tools.c,v retrieving revision 1.4 diff -u -r1.4 pf_tools.c --- common/aicore/pf_tools.c 2003/07/19 15:13:54 1.4 +++ common/aicore/pf_tools.c 2003/07/19 16:04:16 @@ -24,21 +24,39 @@ /* ===================== Move Cost Callbacks ========================= */ /************************************************************* - SINGLE_MOVE cost function for SEA_MOVING - Note: this is a reversable function + A cost function for SEA_MOVING. Allows shore bombardment. + Should be used in conjunction with a TB callback which + prohibits going through an enemy city/tile. *************************************************************/ -static int single_seamove(int x, int y, enum direction8 dir, - int x1, int y1, struct pf_parameter *param) +static int seamove(int x, int y, enum direction8 dir, + int x1, int y1, struct pf_parameter *param) { /* MOVE_COST_FOR_VALID_SEA_STEP means ships can move between */ - if (map_get_tile(x, y)->move_cost[dir] - == MOVE_COST_FOR_VALID_SEA_STEP) { + if (map_get_tile(x, y)->move_cost[dir] == MOVE_COST_FOR_VALID_SEA_STEP + || is_non_allied_unit_tile(map_get_tile(x1, y1), param->owner) + || is_non_allied_city_tile(map_get_tile(x1, y1), param->owner)) { return SINGLE_MOVE; } else { return PF_IMPOSSIBLE_MC; } } +/************************************************************* + A cost function for SEA_MOVING. Does not allow shore + bombardment. +*************************************************************/ +static int seamove_no_bombard(int x, int y, enum direction8 dir, + int x1, int y1, struct pf_parameter *param) +{ + /* MOVE_COST_FOR_VALID_SEA_STEP means ships can move between */ + if (map_get_tile(x, y)->move_cost[dir] == MOVE_COST_FOR_VALID_SEA_STEP + && !is_non_allied_city_tile(map_get_tile(x1, y1), param->owner)) { + return SINGLE_MOVE; + } else { + return PF_IMPOSSIBLE_MC; + } +} + /************************************************************ A cost function for a sea unit which allows going one step into the land (shore bombardment). @@ -287,7 +305,11 @@ } break; case SEA_MOVING: - parameter->get_MC = single_seamove; + if (unit_flag(punit, F_NO_LAND_ATTACK)) { + parameter->get_MC = seamove_no_bombard; + } else { + parameter->get_MC = seamove; + } break; default: die("unknown move_type");