[Freeciv-Dev] (PR#11571) What is the target_type for?
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
<URL: http://bugs.freeciv.org/Ticket/Display.html?id=11571 >
Here's an updated patch. Vasco, I don't see why this should be
particularly slower.
-jason
Index: ai/aicity.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/ai/aicity.c,v
retrieving revision 1.207
diff -u -r1.207 aicity.c
--- ai/aicity.c 29 Mar 2005 12:24:45 -0000 1.207
+++ ai/aicity.c 31 Mar 2005 01:55:33 -0000
@@ -271,7 +271,7 @@
struct requirement *mypreq;
bool useful;
- if (is_effect_disabled(TARGET_BUILDING, pplayer, pcity,
+ if (is_effect_disabled(pplayer, pcity,
id, NULL, peffect)) {
CITY_LOG(LOG_DEBUG, pcity, "%s has a disabled effect: %s",
get_improvement_name(id), effect_type_name(peffect->type));
@@ -288,7 +288,7 @@
mypreq = preq;
continue;
}
- if (!is_req_active(TARGET_BUILDING, pplayer, pcity, id, NULL, preq)) {
+ if (!is_req_active(pplayer, pcity, id, NULL, preq)) {
useful = FALSE;
break;
}
Index: common/city.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/city.c,v
retrieving revision 1.322
diff -u -r1.322 city.c
--- common/city.c 26 Mar 2005 13:36:53 -0000 1.322
+++ common/city.c 31 Mar 2005 01:55:34 -0000
@@ -667,7 +667,7 @@
return FALSE;
}
- return are_reqs_active(TARGET_CITY, city_owner(pcity), pcity, B_LAST, NULL,
+ return are_reqs_active(city_owner(pcity), pcity, B_LAST, NULL,
game.rgame.specialists[type].req, MAX_NUM_REQS);
}
@@ -1245,7 +1245,7 @@
while ((replace = city_styles[prev].replaced_by) != -1) {
prev = replace;
- if (are_reqs_active(TARGET_PLAYER, plr, NULL, B_LAST, NULL,
+ if (are_reqs_active(plr, NULL, B_LAST, NULL,
city_styles[replace].req, MAX_NUM_REQS)) {
style = replace;
}
Index: common/effects.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/effects.c,v
retrieving revision 1.25
diff -u -r1.25 effects.c
--- common/effects.c 30 Mar 2005 22:01:16 -0000 1.25
+++ common/effects.c 31 Mar 2005 01:55:34 -0000
@@ -551,15 +551,14 @@
active (an effect is active if all of its enabling requirements and
none of its disabling ones are active).
**************************************************************************/
-bool is_effect_disabled(enum target_type target,
- const struct player *target_player,
+bool is_effect_disabled(const struct player *target_player,
const struct city *target_city,
Impr_Type_id target_building,
const struct tile *target_tile,
const struct effect *peffect)
{
requirement_list_iterate(peffect->nreqs, preq) {
- if (is_req_active(target, target_player, target_city, target_building,
+ if (is_req_active(target_player, target_city, target_building,
target_tile, preq)) {
return TRUE;
}
@@ -572,15 +571,14 @@
active (an effect is active if all of its enabling requirements and
none of its disabling ones are active).
**************************************************************************/
-static bool is_effect_enabled(enum target_type target,
- const struct player *target_player,
+static bool is_effect_enabled(const struct player *target_player,
const struct city *target_city,
Impr_Type_id target_building,
const struct tile *target_tile,
const struct effect *peffect)
{
requirement_list_iterate(peffect->reqs, preq) {
- if (!is_req_active(target, target_player, target_city, target_building,
+ if (!is_req_active(target_player, target_city, target_building,
target_tile, preq)) {
return FALSE;
}
@@ -597,15 +595,14 @@
(player,city,building,tile) give the exact target
peffect gives the exact effect value
**************************************************************************/
-static bool is_effect_active(enum target_type target,
- const struct player *plr,
+static bool is_effect_active(const struct player *plr,
const struct city *pcity,
Impr_Type_id building,
const struct tile *ptile,
const struct effect *peffect)
{
- return is_effect_enabled(target, plr, pcity, building, ptile, peffect)
- && !is_effect_disabled(target, plr, pcity, building, ptile, peffect);
+ return is_effect_enabled(plr, pcity, building, ptile, peffect)
+ && !is_effect_disabled(plr, pcity, building, ptile, peffect);
}
/**************************************************************************
@@ -620,14 +617,13 @@
source gives the source type of the effect
peffect gives the exact effect value
**************************************************************************/
-bool is_effect_useful(enum target_type target,
- const struct player *target_player,
+bool is_effect_useful(const struct player *target_player,
const struct city *target_city,
Impr_Type_id target_building,
const struct tile *target_tile,
Impr_Type_id source, const struct effect *peffect)
{
- if (is_effect_disabled(target, target_player, target_city,
+ if (is_effect_disabled(target_player, target_city,
target_building, target_tile, peffect)) {
return FALSE;
}
@@ -636,7 +632,7 @@
&& preq->source.value.building == source) {
continue;
}
- if (!is_req_active(target, target_player, target_city, target_building,
+ if (!is_req_active(target_player, target_city, target_building,
target_tile, preq)) {
return FALSE;
}
@@ -667,7 +663,7 @@
/* We use TARGET_BUILDING as the lowest common denominator. Note that
* the building is its own target - but whether this is actually
* checked depends on the range of the effect. */
- if (!is_effect_disabled(TARGET_BUILDING, city_owner(pcity), pcity,
+ if (!is_effect_disabled(city_owner(pcity), pcity,
building, NULL, peffect)) {
return FALSE;
}
@@ -688,7 +684,6 @@
is done with it.
**************************************************************************/
static int get_target_bonus_effects(struct effect_list *plist,
- enum target_type target,
const struct player *target_player,
const struct city *target_city,
Impr_Type_id target_building,
@@ -700,7 +695,7 @@
/* Loop over all effects of this type. */
effect_list_iterate(get_effects(effect_type), peffect) {
/* For each effect, see if it is active. */
- if (is_effect_active(target, target_player, target_city,
+ if (is_effect_active(target_player, target_city,
target_building, target_tile, peffect)) {
/* And if so add on the value. */
bonus += peffect->value;
@@ -719,7 +714,7 @@
**************************************************************************/
int get_world_bonus(enum effect_type effect_type)
{
- return get_target_bonus_effects(NULL, TARGET_WORLD,
+ return get_target_bonus_effects(NULL,
NULL, NULL, B_LAST, NULL, effect_type);
}
@@ -729,7 +724,8 @@
int get_player_bonus(const struct player *pplayer,
enum effect_type effect_type)
{
- return get_target_bonus_effects(NULL, TARGET_PLAYER,
+ assert(pplayer != NULL);
+ return get_target_bonus_effects(NULL,
pplayer, NULL, B_LAST, NULL,
effect_type);
}
@@ -739,7 +735,8 @@
**************************************************************************/
int get_city_bonus(const struct city *pcity, enum effect_type effect_type)
{
- return get_target_bonus_effects(NULL, TARGET_CITY,
+ assert(pcity != NULL);
+ return get_target_bonus_effects(NULL,
city_owner(pcity), pcity, B_LAST, NULL,
effect_type);
}
@@ -750,7 +747,8 @@
int get_city_tile_bonus(const struct city *pcity, const struct tile *ptile,
enum effect_type effect_type)
{
- return get_target_bonus_effects(NULL, TARGET_CITY,
+ assert(pcity != NULL && ptile != NULL);
+ return get_target_bonus_effects(NULL,
city_owner(pcity), pcity, B_LAST, ptile,
effect_type);
}
@@ -761,7 +759,8 @@
int get_building_bonus(const struct city *pcity, Impr_Type_id id,
enum effect_type effect_type)
{
- return get_target_bonus_effects(NULL, TARGET_CITY,
+ assert(pcity != NULL && id != B_LAST);
+ return get_target_bonus_effects(NULL,
city_owner(pcity), pcity, id, NULL,
effect_type);
}
@@ -776,7 +775,8 @@
const struct player *pplayer,
enum effect_type effect_type)
{
- return get_target_bonus_effects(plist, TARGET_PLAYER,
+ assert(pplayer != NULL);
+ return get_target_bonus_effects(plist,
pplayer, NULL, B_LAST, NULL,
effect_type);
}
@@ -791,7 +791,8 @@
const struct city *pcity,
enum effect_type effect_type)
{
- return get_target_bonus_effects(plist, TARGET_CITY,
+ assert(pcity != NULL);
+ return get_target_bonus_effects(plist,
city_owner(pcity), pcity, B_LAST, NULL,
effect_type);
}
@@ -820,7 +821,7 @@
if (peffect->type != effect_type) {
continue;
}
- if (is_effect_useful(TARGET_BUILDING, city_owner(pcity),
+ if (is_effect_useful(city_owner(pcity),
pcity, id, NULL, id, peffect)) {
power += peffect->value;
}
Index: common/effects.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/effects.h,v
retrieving revision 1.15
diff -u -r1.15 effects.h
--- common/effects.h 30 Mar 2005 22:01:16 -0000 1.15
+++ common/effects.h 31 Mar 2005 01:55:34 -0000
@@ -156,8 +156,7 @@
void recv_ruleset_effect_req(struct packet_ruleset_effect_req *packet);
void send_ruleset_cache(struct conn_list *dest);
-bool is_effect_useful(enum target_type target,
- const struct player *target_player,
+bool is_effect_useful(const struct player *target_player,
const struct city *target_pcity,
Impr_Type_id target_building,
const struct tile *target_tile,
@@ -176,8 +175,7 @@
/* miscellaneous auxiliary effects functions */
struct effect_list *get_req_source_effects(struct req_source *psource);
-bool is_effect_disabled(enum target_type target,
- const struct player *target_player,
+bool is_effect_disabled(const struct player *target_player,
const struct city *target_city,
Impr_Type_id target_building,
const struct tile *target_tile,
Index: common/government.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/government.c,v
retrieving revision 1.50
diff -u -r1.50 government.c
--- common/government.c 28 Mar 2005 17:14:57 -0000 1.50
+++ common/government.c 31 Mar 2005 01:55:34 -0000
@@ -205,7 +205,7 @@
return TRUE;
}
- return are_reqs_active(TARGET_PLAYER, pplayer, NULL, B_LAST, NULL,
+ return are_reqs_active(pplayer, NULL, B_LAST, NULL,
gov->req, MAX_NUM_REQS);
}
Index: common/requirements.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/requirements.c,v
retrieving revision 1.9
diff -u -r1.9 requirements.c
--- common/requirements.c 30 Mar 2005 22:01:16 -0000 1.9
+++ common/requirements.c 31 Mar 2005 01:55:34 -0000
@@ -302,29 +302,6 @@
}
/****************************************************************************
- Is this target possible for the range involved?
-
- For instance a city-ranged requirement can't have a player as it's target.
- See the comment at enum target_type.
-****************************************************************************/
-static bool is_target_possible(enum target_type target,
- enum req_range range)
-{
- switch (target) {
- case TARGET_WORLD:
- return (range >= REQ_RANGE_WORLD);
- case TARGET_PLAYER:
- return (range >= REQ_RANGE_PLAYER);
- case TARGET_CITY:
- return (range >= REQ_RANGE_CITY);
- case TARGET_BUILDING:
- return (range >= REQ_RANGE_LOCAL);
- }
- assert(0);
- return FALSE;
-}
-
-/****************************************************************************
Returns the number of total world buildings (this includes buildings
that have been destroyed).
****************************************************************************/
@@ -443,8 +420,7 @@
the number of available sources. However not all source caches exist: if
the cache doesn't exist then we return 0.
****************************************************************************/
-int count_buildings_in_range(enum target_type target,
- const struct player *target_player,
+int count_buildings_in_range(const struct player *target_player,
const struct city *target_city,
Impr_Type_id target_building,
enum req_range range, bool survives,
@@ -471,23 +447,27 @@
case REQ_RANGE_WORLD:
return num_world_buildings(source);
case REQ_RANGE_PLAYER:
- return num_player_buildings(target_player, source);
+ return target_player ? num_player_buildings(target_player, source) : 0;
case REQ_RANGE_CONTINENT:
- {
+ if (target_player) {
int continent = map_get_continent(target_city->tile);
return num_continent_buildings(target_player, continent, source);
+ } else {
+ return 0;
}
case REQ_RANGE_CITY:
- return num_city_buildings(target_city, source);
+ return target_city ? num_city_buildings(target_city, source) : 0;
case REQ_RANGE_LOCAL:
- if (target_building == source) {
+ if (target_building != B_LAST && target_building == source) {
return num_city_buildings(target_city, source);
} else {
+ /* TODO: other local targets */
return 0;
}
- case REQ_RANGE_LAST:
case REQ_RANGE_ADJACENT:
+ return 0;
+ case REQ_RANGE_LAST:
break;
}
assert(0);
@@ -497,8 +477,7 @@
/****************************************************************************
Is there a source tech within range of the target?
****************************************************************************/
-static bool is_tech_in_range(enum target_type target,
- const struct player *target_player,
+static bool is_tech_in_range(const struct player *target_player,
enum req_range range,
Tech_Type_id tech)
{
@@ -523,8 +502,7 @@
/****************************************************************************
Is there a source special within range of the target?
****************************************************************************/
-static bool is_special_in_range(enum target_type target,
- const struct tile *target_tile,
+static bool is_special_in_range(const struct tile *target_tile,
enum req_range range, bool survives,
enum tile_special_type special)
@@ -554,8 +532,7 @@
/****************************************************************************
Is there a source tile within range of the target?
****************************************************************************/
-static bool is_terrain_in_range(enum target_type target,
- const struct tile *target_tile,
+static bool is_terrain_in_range(const struct tile *target_tile,
enum req_range range, bool survives,
Terrain_type_id terrain)
{
@@ -592,17 +569,12 @@
for instance if you have TARGET_CITY pass the city's owner as the target
player as well as the city itself as the target city.
****************************************************************************/
-bool is_req_active(enum target_type target,
- const struct player *target_player,
+bool is_req_active(const struct player *target_player,
const struct city *target_city,
Impr_Type_id target_building,
const struct tile *target_tile,
const struct requirement *req)
{
- if (!is_target_possible(target, req->range)) {
- return FALSE;
- }
-
/* Note the target may actually not exist. In particular, effects that
* have a REQ_SPECIAL or REQ_TERRAIN may often be passed to this function
* with a city as their target. In this case the requirement is simply
@@ -612,7 +584,7 @@
return TRUE;
case REQ_TECH:
/* The requirement is filled if the player owns the tech. */
- return is_tech_in_range(target, target_player, req->range,
+ return is_tech_in_range(target_player, req->range,
req->source.value.tech);
case REQ_GOV:
/* The requirement is filled if the player is using the government. */
@@ -622,16 +594,16 @@
/* The requirement is filled if there's at least one of the building
* in the city. (This is a slightly nonstandard use of
* count_sources_in_range.) */
- return (count_buildings_in_range(target, target_player, target_city,
+ return (count_buildings_in_range(target_player, target_city,
target_building,
req->range, req->survives,
req->source.value.building) > 0);
case REQ_SPECIAL:
- return is_special_in_range(target, target_tile,
+ return is_special_in_range(target_tile,
req->range, req->survives,
req->source.value.special);
case REQ_TERRAIN:
- return is_terrain_in_range(target, target_tile,
+ return is_terrain_in_range(target_tile,
req->range, req->survives,
req->source.value.terrain);
case REQ_LAST:
@@ -656,8 +628,7 @@
for instance if you have TARGET_CITY pass the city's owner as the target
player as well as the city itself as the target city.
****************************************************************************/
-bool are_reqs_active(enum target_type target,
- const struct player *target_player,
+bool are_reqs_active(const struct player *target_player,
const struct city *target_city,
Impr_Type_id target_building,
const struct tile *target_tile,
@@ -668,7 +639,7 @@
for (i = 0; i < num_reqs; i++) {
if (reqs[i].source.type == REQ_NONE) {
break; /* Short-circuit any more checks. */
- } else if (!is_req_active(target, target_player, target_city,
+ } else if (!is_req_active(target_player, target_city,
target_building, target_tile,
&reqs[i])) {
return FALSE;
Index: common/requirements.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/requirements.h,v
retrieving revision 1.6
diff -u -r1.6 requirements.h
--- common/requirements.h 30 Mar 2005 22:01:16 -0000 1.6
+++ common/requirements.h 31 Mar 2005 01:55:34 -0000
@@ -41,16 +41,6 @@
REQ_RANGE_LAST /* keep this last */
};
-/* An requirement is targeted at a certain target type. For building and
- * unit reqs the target will be a city; for tech reqs it will be a player;
- * for effect reqs it may be anything. */
-enum target_type {
- TARGET_WORLD,
- TARGET_PLAYER,
- TARGET_CITY,
- TARGET_BUILDING
-};
-
/* A requirement source. */
struct req_source {
enum req_source_type type; /* source type */
@@ -102,21 +92,18 @@
struct requirement req_from_values(int type, int range,
bool survives, int value);
-bool is_req_active(enum target_type target,
- const struct player *target_player,
+bool is_req_active(const struct player *target_player,
const struct city *target_city,
Impr_Type_id target_building,
const struct tile *target_tile,
const struct requirement *req);
-bool are_reqs_active(enum target_type target,
- const struct player *target_player,
+bool are_reqs_active(const struct player *target_player,
const struct city *target_city,
Impr_Type_id target_building,
const struct tile *target_tile,
const struct requirement *reqs, int num_reqs);
-int count_buildings_in_range(enum target_type target,
- const struct player *target_player,
+int count_buildings_in_range(const struct player *target_player,
const struct city *target_city,
Impr_Type_id target_building,
enum req_range range, bool survives,
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Freeciv-Dev] (PR#11571) What is the target_type for?,
Jason Short <=
|
|