[Freeciv-Dev] (PR#9593) another autosettlers patch
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
<URL: http://rt.freeciv.org/Ticket/Display.html?id=9593 >
This patch improves ai_calc_irrigate, ai_calc_mine, and
ai_calc_transform a bit more.
- It checks TER_NO_CITIES rather than is_ocean when changing the terrain
type.
- The special-case for not auto-irrigation of city centers is removed.
This makes removing auto-irrigation easier (which may be desirable at
some point) and has practically no disadvantages.
- ai_calc_mine now handles changing the terrain. This will calculate
the advantage of mining grassland into forest, for instance.
- ai_calc_transform and ai_calc_mine don't hard-code the source terrain
types. Doing so is totally unnecessary since all the information is
encoded in the ruleset.
- Changes the structure of the functions slightly to be more similar. I
added an "r" variable to ai_calc_irrigate and ai_calc_mine.
- Fixes some random style, adds some comments.
jason
? diff
Index: server/settlers.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/settlers.c,v
retrieving revision 1.186
diff -u -r1.186 settlers.c
--- server/settlers.c 3 Aug 2004 03:08:54 -0000 1.186
+++ server/settlers.c 3 Aug 2004 03:55:48 -0000
@@ -571,23 +571,22 @@
enum tile_terrain_type t = ptile->terrain;
struct tile_type *type = get_tile_type(t);
enum tile_special_type s = ptile->special;
+ enum tile_terrain_type r = type->irrigation_result;
- if (ptile->terrain != type->irrigation_result
- && type->irrigation_result != T_LAST) {
+ if (t != r && r != T_LAST) {
/* Irrigation would change the terrain type, clearing the mine
* in the process. Calculate the benefit of doing so. */
- if (ptile->city && is_ocean(type->irrigation_result)) {
+ if (ptile->city && terrain_has_flag(r, TER_NO_CITIES)) {
return -1;
}
- ptile->terrain = type->irrigation_result;
+ ptile->terrain = r;
map_clear_special(mx, my, S_MINE);
m = city_tile_value(pcity, cx, cy, 0, 0);
ptile->terrain = t;
ptile->special = s;
return m;
- } else if (ptile->terrain == type->irrigation_result
+ } else if (t == r
&& !tile_has_special(ptile, S_IRRIGATION)
- && !ptile->city
&& is_wet_or_is_wet_cardinal_around(pplayer, mx, my)) {
/* The tile is currently unirrigated; irrigating it would put an
* S_IRRIGATE on it replacing any S_MINE already there. Calculate
@@ -598,11 +597,10 @@
ptile->special = s;
assert(ptile->terrain == t);
return m;
- } else if (ptile->terrain == type->irrigation_result
+ } else if (t == r
&& tile_has_special(ptile, S_IRRIGATION)
&& !tile_has_special(ptile, S_FARMLAND)
&& player_knows_techs_with_flag(pplayer, TF_FARMLAND)
- && !ptile->city
&& is_wet_or_is_wet_cardinal_around(pplayer, mx, my)) {
/* The tile is currently irrigated; irrigating it more puts an
* S_FARMLAND on it. Calculate the benefit of doing so. */
@@ -633,22 +631,34 @@
{
int m;
struct tile *ptile = map_get_tile(mx, my);
+ enum tile_terrain_type t = ptile->terrain;
+ struct tile_type *type = get_tile_type(t);
enum tile_special_type s = ptile->special;
+ enum tile_terrain_type r = type->mining_result;
- /* FIXME: currently this only handles building a mine on a hill or
- * mountain terrain. It should instead work the same way as
- * ai_calc_irrigate does, by looking at mining_result. */
-
- if ((ptile->terrain == T_HILLS || ptile->terrain == T_MOUNTAINS)
- && !tile_has_special(ptile, S_MINE)) {
- /* The tile is currently unmined; mining it would put an S_MINE
- * on it replacing any S_IRRIGATION/S_FARMLAND already there. Calculate
+ if (t != r && r != T_LAST) {
+ /* Mining would change the terrain type, clearing the irrigation
+ * in the process. Calculate the benefit of doing so. */
+ if (ptile->city && terrain_has_flag(r, TER_NO_CITIES)) {
+ return -1;
+ }
+ ptile->terrain = r;
+ map_clear_special(mx, my, S_IRRIGATION);
+ map_clear_special(mx, my, S_FARMLAND);
+ m = city_tile_value(pcity, cx, cy, 0, 0);
+ ptile->terrain = t;
+ ptile->special = s;
+ return m;
+ } else if (t == r && !tile_has_special(ptile, S_MINE)) {
+ /* The tile is currently unmined; mining it would put an S_MINE on it
+ * replacing any S_IRRIGATION/S_FARMLAND already there. Calculate
* the benefit of doing so. */
map_clear_special(mx, my, S_IRRIGATION);
map_clear_special(mx, my, S_FARMLAND);
map_set_special(mx, my, S_MINE);
m = city_tile_value(pcity, cx, cy, 0, 0);
ptile->special = s;
+ assert(ptile->terrain == t);
return m;
} else {
return -1;
@@ -656,7 +666,16 @@
}
/**************************************************************************
- Calculates the value of doing a terrain transformation.
+ Calculate the benefit of transforming the given tile.
+
+ (mx, my) is the map position of the tile.
+ (cx, cy) is the city position of the tile with respect to pcity.
+ pplayer is the player under consideration.
+
+ The return value is the goodness of the tile after the transform. This
+ should be compared to the goodness of the tile currently (see
+ city_tile_value(); note that this depends on the AI's weighting
+ values).
**************************************************************************/
static int ai_calc_transform(struct city *pcity, int cx, int cy, int mx,
int my)
@@ -675,17 +694,16 @@
return -1;
}
- if ((t == T_ARCTIC || t == T_DESERT || t == T_JUNGLE || t == T_SWAMP ||
- t == T_TUNDRA || t == T_MOUNTAINS) && r != T_LAST) {
- if (is_ocean(r) && ptile->city) {
+ if (t != r && r != T_LAST) {
+ if (ptile->city && terrain_has_flag(r, TER_NO_CITIES)) {
return -1;
}
ptile->terrain = r;
- if (get_tile_type(r)->mining_result != r)
+ if (get_tile_type(r)->mining_result != r) {
map_clear_special(mx, my, S_MINE);
-
+ }
if (get_tile_type(r)->irrigation_result != r) {
map_clear_special(mx, my, S_FARMLAND);
map_clear_special(mx, my, S_IRRIGATION);
@@ -694,8 +712,10 @@
m = city_tile_value(pcity, cx, cy, 0, 0);
ptile->terrain = t;
ptile->special = s;
- return(m);
- } else return(-1);
+ return m;
+ } else {
+ return -1;
+ }
}
/**************************************************************************
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Freeciv-Dev] (PR#9593) another autosettlers patch,
Jason Short <=
|
|