diff -urd -X work2/diff_ignore freeciv.current/ai/aiunit.c work2/ai/aiunit.c --- freeciv.current/ai/aiunit.c Sat Aug 25 11:23:36 2001 +++ work2/ai/aiunit.c Sat Aug 25 19:04:22 2001 @@ -99,18 +99,16 @@ int could_unit_move_to_tile(struct unit *punit, int src_x, int src_y, int dest_x, int dest_y) { - enum move_reason reason; - int result; + enum unit_move_result result; result = - can_unit_move_to_tile_with_reason(punit->type, unit_owner(punit), - punit->activity, punit->connecting, - punit->x, punit->y, dest_x, dest_y, - 0, &reason); - if (result) + test_unit_move_to_tile(punit->type, unit_owner(punit), + punit->activity, punit->connecting, + punit->x, punit->y, dest_x, dest_y, 0); + if (result == MR_OK) return 1; - if (reason == MR_ZOC) { + if (result == MR_ZOC) { if (could_be_my_zoc(punit, src_x, src_y)) return -1; } @@ -267,7 +265,7 @@ if (unknown > most_unknown && (landnear || !unit_flag(punit->type, F_TRIREME)) && map_get_continent(x1, y1) == con - && can_unit_move_to_tile(punit, x1, y1, 0) + && can_unit_move_to_tile_with_notify(punit, x1, y1, 0) && !((pcity = map_get_city(x1,y1)) && (unit_flag(punit->type, F_DIPLOMAT) || unit_flag(punit->type, F_CARAVAN))) @@ -2240,7 +2238,7 @@ y = map_adjust_y(leader->y + dy); if (warmap.cost[x][y] > safest - && can_unit_move_to_tile(leader, x, y, FALSE)) { + && can_unit_move_to_tile_with_notify(leader, x, y, FALSE)) { safest = warmap.cost[x][y]; freelog(LOG_DEBUG, "Barbarian leader: safest is %d, %d, safeness %d", x, y, safest); diff -urd -X work2/diff_ignore freeciv.current/common/unit.c work2/common/unit.c --- freeciv.current/common/unit.c Sat Aug 25 11:23:36 2001 +++ work2/common/unit.c Sat Aug 25 19:30:54 2001 @@ -1205,6 +1205,17 @@ return zoc_ok_move_gen(punit, punit->x, punit->y, x, y); } +int can_unit_move_to_tile(Unit_Type_id type, + struct player *unit_owner, + enum unit_activity activity, + int connecting, int src_x, + int src_y, int dest_x, int dest_y, int igzoc) +{ + return MR_OK == test_unit_move_to_tile(type, unit_owner, activity, + connecting, src_x, + src_y, dest_x, dest_y, igzoc); +} + /************************************************************************** unit can be moved if: 1) the unit is idle or on goto or connecting. @@ -1219,38 +1230,32 @@ 9) there is not a peaceful but un-allied city on the target tile 10) there is no non-allied unit blocking (zoc) [or igzoc is true] **************************************************************************/ -int can_unit_move_to_tile_with_reason(Unit_Type_id type, - struct player *unit_owner, - enum unit_activity activity, - int connecting, int src_x, int src_y, - int dest_x, int dest_y, int igzoc, - enum move_reason *reason) +enum unit_move_result test_unit_move_to_tile(Unit_Type_id type, + struct player *unit_owner, + enum unit_activity activity, + int connecting, int src_x, + int src_y, int dest_x, + int dest_y, int igzoc) { struct tile *pfromtile, *ptotile; int zoc; struct city *pcity; - /* To allow people to pass us NULL if they don't need the reason argument. */ - enum move_reason dummy; - if (!reason) { - reason = &dummy; - } - /* 1) */ if (activity != ACTIVITY_IDLE && activity != ACTIVITY_GOTO && activity != ACTIVITY_PATROL && !connecting) { - return 0; + return MR_BAD_ACTIVITY; } /* 2) */ if (!normalize_map_pos(&dest_x, &dest_y)) { - return 0; + return MR_BAD_MAP_POSITION; } /* 3) */ if (!is_tiles_adjacent(src_x, src_y, dest_x, dest_y)) { - return 0; + return MR_BAD_DESTINATION; } pfromtile = map_get_tile(src_x, src_y); @@ -1258,14 +1263,14 @@ /* 4) */ if (is_non_allied_unit_tile(ptotile, unit_owner)) { - return 0; + return MR_DESTINATION_OCCUPIED_BY_NON_ALLIED_UNIT; } if (unit_types[type].move_type == LAND_MOVING) { /* 5) */ if (ptotile->terrain == T_OCEAN && ground_unit_transporter_capacity(dest_x, dest_y, unit_owner) <= 0) { - return 0; + return MR_NO_SEA_TRANSPORTER_CAPACITY; } /* Moving from ocean */ @@ -1273,8 +1278,7 @@ /* 6) */ if (!unit_flag(type, F_MARINES) && is_enemy_city_tile(ptotile, unit_owner)) { - *reason = MR_INVALID_TYPE_FOR_CITY_TAKE_OVER; - return 0; + return MR_BAD_TYPE_FOR_CITY_TAKE_OVER; } } } else if (unit_types[type].move_type == SEA_MOVING) { @@ -1282,21 +1286,20 @@ if (ptotile->terrain != T_OCEAN && ptotile->terrain != T_UNKNOWN && !is_allied_city_tile(ptotile, unit_owner)) { - return 0; + + return MR_DESTINATION_OCCUPIED_BY_NON_ALLIED_CITY; } } /* 8) */ if (is_non_attack_unit_tile(ptotile, unit_owner)) { - *reason = MR_NO_WAR; - return 0; + return MR_NO_WAR; } /* 9) */ pcity = ptotile->city; if (pcity && pplayers_non_attack(city_owner(pcity), unit_owner)) { - *reason = MR_NO_WAR; - return 0; + return MR_NO_WAR; } /* 10) */ @@ -1304,10 +1307,10 @@ || can_step_taken_wrt_to_zoc(type, unit_owner, src_x, src_y, dest_x, dest_y); if (!zoc) { - *reason = MR_ZOC; + return MR_ZOC; } - return zoc; + return MR_OK; } /* diff -urd -X work2/diff_ignore freeciv.current/common/unit.h work2/common/unit.h --- freeciv.current/common/unit.h Sat Aug 25 11:23:36 2001 +++ work2/common/unit.h Sat Aug 25 18:53:24 2001 @@ -62,8 +62,12 @@ ROUTE_GOTO, ROUTE_PATROL }; -enum move_reason { - MR_OTHER, MR_INVALID_TYPE_FOR_CITY_TAKE_OVER, MR_NO_WAR, MR_ZOC +enum unit_move_result { + MR_OK, MR_BAD_TYPE_FOR_CITY_TAKE_OVER, MR_NO_WAR, MR_ZOC, + MR_BAD_ACTIVITY, MR_BAD_DESTINATION, MR_BAD_MAP_POSITION, + MR_DESTINATION_OCCUPIED_BY_NON_ALLIED_UNIT, + MR_NO_SEA_TRANSPORTER_CAPACITY, + MR_DESTINATION_OCCUPIED_BY_NON_ALLIED_CITY }; enum add_build_city_result { @@ -241,13 +245,17 @@ int can_step_taken_wrt_to_zoc(Unit_Type_id type, struct player *unit_owner, int src_x, int src_y, int dest_x, int dest_y); - -int can_unit_move_to_tile_with_reason(Unit_Type_id type, - struct player *unit_owner, - enum unit_activity activity, - int connecting, int src_x, int src_y, - int dest_x, int dest_y, int igzoc, - enum move_reason *reason); +int can_unit_move_to_tile(Unit_Type_id type, + struct player *unit_owner, + enum unit_activity activity, + int connecting, int src_x, + int src_y, int dest_x, int dest_y, int igzoc); +enum unit_move_result test_unit_move_to_tile(Unit_Type_id type, + struct player *unit_owner, + enum unit_activity activity, + int connecting, int src_x, + int src_y, int dest_x, + int dest_y, int igzoc); int unit_type_really_ignores_zoc(Unit_Type_id type); int zoc_ok_move_gen(struct unit *punit, int x1, int y1, int x2, int y2); int zoc_ok_move(struct unit *punit, int x, int y); diff -urd -X work2/diff_ignore freeciv.current/server/barbarian.c work2/server/barbarian.c --- freeciv.current/server/barbarian.c Sat Aug 25 11:23:36 2001 +++ work2/server/barbarian.c Sat Aug 25 19:04:58 2001 @@ -236,8 +236,9 @@ send_unit_info( 0, punit2); while(1) { rand_neighbour(x, y, &xu, &yu); - if( can_unit_move_to_tile(punit2, xu, yu, TRUE) ) break; - if( can_unit_move_to_tile(punit2, xb, yb, TRUE) ) { + if (can_unit_move_to_tile_with_notify(punit2, xu, yu, TRUE)) + break; + if (can_unit_move_to_tile_with_notify(punit2, xb, yb, TRUE)) { xu = xb; yu = yb; break; } diff -urd -X work2/diff_ignore freeciv.current/server/unithand.c work2/server/unithand.c --- freeciv.current/server/unithand.c Sat Aug 25 11:23:36 2001 +++ work2/server/unithand.c Sat Aug 25 19:08:58 2001 @@ -875,7 +875,7 @@ packet.action_type = DIPLOMAT_CLIENT_POPUP_DIALOG; lsend_packet_diplomat_action(player_reply_dest(pplayer), &packet); return 0; - } else if (!can_unit_move_to_tile(punit, dest_x, dest_y, igzoc)) { + } else if (!can_unit_move_to_tile_with_notify(punit, dest_x, dest_y, igzoc)) { notify_player_ex(pplayer, punit->x, punit->y, E_NOEVENT, map_get_terrain(punit->x, punit->y)==T_OCEAN ? _("Game: Diplomats cannot act from sea.") @@ -1014,7 +1014,7 @@ } /******* ok now move the unit *******/ - if(can_unit_move_to_tile(punit, dest_x, dest_y, igzoc) && + if(can_unit_move_to_tile_with_notify(punit, dest_x, dest_y, igzoc) && try_move_unit(punit, dest_x, dest_y)) { int src_x = punit->x; int src_y = punit->y; diff -urd -X work2/diff_ignore freeciv.current/server/unittools.c work2/server/unittools.c --- freeciv.current/server/unittools.c Sat Aug 25 11:53:27 2001 +++ work2/server/unittools.c Sat Aug 25 19:16:43 2001 @@ -3047,22 +3047,20 @@ /************************************************************************** ... **************************************************************************/ -int can_unit_move_to_tile(struct unit *punit, int dest_x, int dest_y, - int igzoc) +int can_unit_move_to_tile_with_notify(struct unit *punit, int dest_x, + int dest_y, int igzoc) { - enum move_reason reason; - int result; + enum unit_move_result reason; int src_x = punit->x, src_y = punit->y; - result = - can_unit_move_to_tile_with_reason(punit->type, unit_owner(punit), - punit->activity, punit->connecting, - punit->x, punit->y, dest_x, dest_y, - igzoc, &reason); - if (result) + reason = + test_unit_move_to_tile(punit->type, unit_owner(punit), + punit->activity, punit->connecting, + punit->x, punit->y, dest_x, dest_y, igzoc); + if (reason == MR_OK) return 1; - if (reason == MR_INVALID_TYPE_FOR_CITY_TAKE_OVER) { + if (reason == MR_BAD_TYPE_FOR_CITY_TAKE_OVER) { char *units_str = get_units_with_flag_string(F_MARINES); if (units_str) { notify_player_ex(unit_owner(punit), src_x, src_y, diff -urd -X work2/diff_ignore freeciv.current/server/unittools.h work2/server/unittools.h --- freeciv.current/server/unittools.h Mon Aug 13 16:09:42 2001 +++ work2/server/unittools.h Sat Aug 25 18:56:35 2001 @@ -26,7 +26,8 @@ /* move check related */ -int can_unit_move_to_tile(struct unit *punit, int dest_x, int dest_y, int igzoc); +int can_unit_move_to_tile_with_notify(struct unit *punit, int dest_x, + int dest_y, int igzoc); /* turn update related */