[Freeciv-Dev] (PR#8561) can_unit_do_activity_targeted_at
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
<URL: http://rt.freeciv.org/Ticket/Display.html?id=8561 >
This patch introduces a new function can_unit_do_activity_targeted_at.
This function does exactly what it sounds like :-).
There are no users yet. However it is a generally pretty useful
function I think, and is specifically useful for connect-as-orders.
An alternative is to use virtual units. I.e., the caller changes the
unit's location before passing it to can_unit_do_activity_targeted.
Most other functions do it via the _at method, however.
jason
? cma_weirdness
? client/gui-qpe
? data/civ3
? data/womoks
Index: common/unit.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/unit.c,v
retrieving revision 1.204
diff -u -r1.204 unit.c
--- common/unit.c 20 Apr 2004 16:17:39 -0000 1.204
+++ common/unit.c 21 Apr 2004 05:15:38 -0000
@@ -756,21 +756,33 @@
}
/**************************************************************************
-Note that if you make changes here you should also change the code for
-autosettlers in server/settler.c. The code there does not use this function
-as it would be a ajor CPU hog.
+ Return whether the unit can do the targeted activity at its current
+ location.
**************************************************************************/
bool can_unit_do_activity_targeted(struct unit *punit,
enum unit_activity activity,
enum tile_special_type target)
{
- struct player *pplayer;
- struct tile *ptile;
- struct tile_type *type;
-
- pplayer = unit_owner(punit);
- ptile = map_get_tile(punit->x, punit->y);
- type = get_tile_type(ptile->terrain);
+ return can_unit_do_activity_targeted_at(punit, activity, target,
+ punit->x, punit->y);
+}
+
+/**************************************************************************
+ Return TRUE if the unit can do the targeted activity at the given
+ location.
+
+ Note that if you make changes here you should also change the code for
+ autosettlers in server/settler.c. The code there does not use this
+ function as it would be a major CPU hog.
+**************************************************************************/
+bool can_unit_do_activity_targeted_at(struct unit *punit,
+ enum unit_activity activity,
+ enum tile_special_type target,
+ int map_x, int map_y)
+{
+ struct player *pplayer = unit_owner(punit);
+ struct tile *ptile = map_get_tile(map_x, map_y);
+ struct tile_type *type = get_tile_type(ptile->terrain);
switch(activity) {
case ACTIVITY_IDLE:
@@ -800,11 +812,11 @@
(ptile->terrain!=type->mining_result &&
type->mining_result!=T_LAST &&
(!is_ocean(ptile->terrain) || is_ocean(type->mining_result) ||
- can_reclaim_ocean(punit->x, punit->y)) &&
+ can_reclaim_ocean(map_x, map_y)) &&
(is_ocean(ptile->terrain) || !is_ocean(type->mining_result) ||
- can_channel_land(punit->x, punit->y)) &&
+ can_channel_land(map_x, map_y)) &&
(!is_ocean(type->mining_result) ||
- !(map_get_city(punit->x, punit->y)))) )) {
+ !(map_get_city(map_x, map_y)))) )) {
unit_list_iterate(ptile->units, tunit) {
if(tunit->activity==ACTIVITY_IRRIGATE) return FALSE;
}
@@ -821,15 +833,15 @@
(!tile_has_special(ptile, S_FARMLAND) &&
player_knows_techs_with_flag(pplayer, TF_FARMLAND))) &&
( (ptile->terrain==type->irrigation_result &&
- is_water_adjacent_to_tile(punit->x, punit->y)) ||
+ is_water_adjacent_to_tile(map_x, map_y)) ||
(ptile->terrain!=type->irrigation_result &&
type->irrigation_result!=T_LAST &&
(!is_ocean(ptile->terrain) || is_ocean(type->irrigation_result) ||
- can_reclaim_ocean(punit->x, punit->y)) &&
+ can_reclaim_ocean(map_x, map_y)) &&
(is_ocean(ptile->terrain) || !is_ocean(type->irrigation_result) ||
- can_channel_land(punit->x, punit->y)) &&
+ can_channel_land(map_x, map_y)) &&
(!is_ocean(type->irrigation_result) ||
- !(map_get_city(punit->x, punit->y)))) )) {
+ !(map_get_city(map_x, map_y)))) )) {
unit_list_iterate(ptile->units, tunit) {
if(tunit->activity==ACTIVITY_MINE) return FALSE;
}
@@ -848,7 +860,7 @@
case ACTIVITY_FORTRESS:
return (unit_flag(punit, F_SETTLERS) &&
- !map_get_city(punit->x, punit->y) &&
+ !map_get_city(map_x, map_y) &&
player_knows_techs_with_flag(pplayer, TF_FORTRESS) &&
!tile_has_special(ptile, S_FORTRESS) && !is_ocean(ptile->terrain));
@@ -864,11 +876,7 @@
/* if the tile has road, the terrain must be ok.. */
return (terrain_control.may_road &&
unit_flag(punit, F_SETTLERS) &&
- (tile_has_special(ptile, S_ROAD) ||
- (punit->connecting &&
- (type->road_time != 0 &&
- (!tile_has_special(ptile, S_RIVER)
- || player_knows_techs_with_flag(pplayer, TF_BRIDGE))))) &&
+ tile_has_special(ptile, S_ROAD) &&
!tile_has_special(ptile, S_RAILROAD) &&
player_knows_techs_with_flag(pplayer, TF_RAILROAD));
@@ -878,7 +886,7 @@
enum tile_special_type psworking;
if (pspresent != S_NO_SPECIAL && is_ground_unit(punit)) {
- psworking = get_unit_tile_pillage_set(punit->x, punit->y);
+ psworking = get_unit_tile_pillage_set(map_x, map_y);
if (ptile->city && (contains_special(target, S_ROAD) ||
contains_special(target, S_RAILROAD))) {
return FALSE;
@@ -909,18 +917,22 @@
(type->transform_result!=T_LAST) &&
(ptile->terrain!=type->transform_result) &&
(!is_ocean(ptile->terrain) || is_ocean(type->transform_result) ||
- can_reclaim_ocean(punit->x, punit->y)) &&
+ can_reclaim_ocean(map_x, map_y)) &&
(is_ocean(ptile->terrain) || !is_ocean(type->transform_result) ||
- can_channel_land(punit->x, punit->y)) &&
+ can_channel_land(map_x, map_y)) &&
(!is_ocean(type->transform_result) ||
- !(map_get_city(punit->x, punit->y))) &&
+ !(map_get_city(map_x, map_y))) &&
unit_flag(punit, F_TRANSFORM));
- default:
- freelog(LOG_ERROR, "Unknown activity %d in
can_unit_do_activity_targeted()",
- activity);
- return FALSE;
+ case ACTIVITY_PATROL_UNUSED:
+ case ACTIVITY_LAST:
+ case ACTIVITY_UNKNOWN:
+ break;
}
+ freelog(LOG_ERROR,
+ "Unknown activity %d in can_unit_do_activity_targeted_at()",
+ activity);
+ return FALSE;
}
/**************************************************************************
Index: common/unit.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/unit.h,v
retrieving revision 1.114
diff -u -r1.114 unit.h
--- common/unit.h 14 Apr 2004 11:19:45 -0000 1.114
+++ common/unit.h 21 Apr 2004 05:15:38 -0000
@@ -251,6 +251,10 @@
bool can_unit_do_activity_targeted(struct unit *punit,
enum unit_activity activity,
enum tile_special_type target);
+bool can_unit_do_activity_targeted_at(struct unit *punit,
+ enum unit_activity activity,
+ enum tile_special_type target,
+ int map_x, int map_y);
void set_unit_activity(struct unit *punit, enum unit_activity new_activity);
void set_unit_activity_targeted(struct unit *punit,
enum unit_activity new_activity,
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Freeciv-Dev] (PR#8561) can_unit_do_activity_targeted_at,
Jason Short <=
|
|