[Freeciv-Dev] (PR#12861) evaluate_improvements simplification
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
<URL: http://bugs.freeciv.org/Ticket/Display.html?id=12861 >
BTW here is my modified version of the patch.
? diff
Index: common/city.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/city.h,v
retrieving revision 1.206
diff -u -r1.206 city.h
--- common/city.h 21 Apr 2005 21:37:34 -0000 1.206
+++ common/city.h 24 Apr 2005 01:23:38 -0000
@@ -180,16 +180,9 @@
avoiding paradox */
bool celebrate; /* try to celebrate in this city */
- /* Used for caching when settlers evalueate which tile to improve,
- and when we place workers. */
- signed short int detox[CITY_MAP_SIZE][CITY_MAP_SIZE];
- signed short int derad[CITY_MAP_SIZE][CITY_MAP_SIZE];
- signed short int mine[CITY_MAP_SIZE][CITY_MAP_SIZE];
- signed short int irrigate[CITY_MAP_SIZE][CITY_MAP_SIZE];
- signed short int road[CITY_MAP_SIZE][CITY_MAP_SIZE];
- signed short int railroad[CITY_MAP_SIZE][CITY_MAP_SIZE];
- signed short int transform[CITY_MAP_SIZE][CITY_MAP_SIZE];
- signed short int tile_value[CITY_MAP_SIZE][CITY_MAP_SIZE];
+ /* Used for caching change in value from a worker performing
+ * a particular activity on a particular tile. */
+ int act_value[ACTIVITY_LAST][CITY_MAP_SIZE][CITY_MAP_SIZE];
/* so we can contemplate with warmap fresh and decide later */
/* These values are for builder (F_SETTLERS) and founder (F_CITIES) units.
Index: common/fc_types.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/fc_types.h,v
retrieving revision 1.19
diff -u -r1.19 fc_types.h
--- common/fc_types.h 18 Apr 2005 06:52:50 -0000 1.19
+++ common/fc_types.h 24 Apr 2005 01:23:38 -0000
@@ -46,6 +46,7 @@
typedef int Specialist_type_id;
typedef int Impr_Type_id;
typedef enum output_type Output_type_id;
+typedef enum unit_activity Activity_type_id;
typedef int Nation_Type_id;
typedef int Team_Type_id;
Index: common/unit.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/unit.h,v
retrieving revision 1.140
diff -u -r1.140 unit.h
--- common/unit.h 20 Apr 2005 02:57:06 -0000 1.140
+++ common/unit.h 24 Apr 2005 01:23:38 -0000
@@ -209,6 +209,17 @@
} \
}
+/* Iterates over the types of unit activity. */
+#define activity_type_iterate(act) \
+{ \
+ Activity_type_id act;
\
+ \
+ for (act = 0; act < ACTIVITY_LAST; act++) {
+
+#define activity_type_iterate_end \
+ } \
+}
+
struct unit *unit_list_find(const struct unit_list *This, int id);
void unit_list_sort_ord_map(struct unit_list *This);
Index: server/settlers.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/settlers.c,v
retrieving revision 1.229
diff -u -r1.229 settlers.c
--- server/settlers.c 23 Apr 2005 17:40:29 -0000 1.229
+++ server/settlers.c 24 Apr 2005 01:23:39 -0000
@@ -861,9 +861,6 @@
generate_warmap(mycity, punit);
city_list_iterate(pplayer->cities, pcity) {
-#ifdef REALLY_DEBUG_THIS
- freelog(LOG_DEBUG, "Evaluating improvements for %s...", pcity->name);
-#endif
/* try to work near the city */
city_map_checked_iterate(pcity->tile, i, j, ptile) {
if (get_worker_city(pcity, i, j) == C_TILE_UNAVAILABLE
@@ -886,93 +883,50 @@
/* now, consider various activities... */
- time = mv_turns
- + get_turns_for_activity_at(punit, ACTIVITY_IRRIGATE, ptile);
- consider_settler_action(pplayer, ACTIVITY_IRRIGATE, -1,
- pcity->ai.irrigate[i][j], oldv, in_use, time,
+ activity_type_iterate(act) {
+ if (pcity->ai.act_value[act][i][j] >= 0
+ && can_unit_do_activity_targeted_at(punit, act,
+ S_NO_SPECIAL, ptile)) {
+ int extra = 0;
+
+ time = mv_turns + get_turns_for_activity_at(punit, act, ptile);
+ if (act == ACTIVITY_ROAD) {
+ extra = road_bonus(ptile, S_ROAD) * 5;
+ if (can_rr) {
+ /* if we can make railroads eventually, consider making
+ * road here, and set extras and time to to consider
+ * railroads in main consider_settler_action call */
+ consider_settler_action(pplayer, ACTIVITY_ROAD,
+ extra,
+ pcity->ai.act_value[ACTIVITY_ROAD][i][j],
+ oldv, in_use, time,
&best_newv, &best_oldv, best_act, best_tile,
ptile);
- if (unit_flag(punit, F_TRANSFORM)) {
- time = mv_turns
- + get_turns_for_activity_at(punit, ACTIVITY_TRANSFORM, ptile);
- consider_settler_action(pplayer, ACTIVITY_TRANSFORM, -1,
- pcity->ai.transform[i][j], oldv, in_use, time,
- &best_newv, &best_oldv, best_act, best_tile,
- ptile);
- }
-
- time = mv_turns
- + get_turns_for_activity_at(punit, ACTIVITY_MINE, ptile);
- consider_settler_action(pplayer, ACTIVITY_MINE, -1,
- pcity->ai.mine[i][j], oldv, in_use, time,
- &best_newv, &best_oldv, best_act, best_tile,
- ptile);
+ act = ACTIVITY_RAILROAD;
- if (!tile_has_special(ptile, S_ROAD)) {
- time = mv_turns
- + get_turns_for_activity_at(punit, ACTIVITY_ROAD, ptile);
- consider_settler_action(pplayer, ACTIVITY_ROAD,
- road_bonus(ptile, S_ROAD) * 5,
- pcity->ai.road[i][j], oldv, in_use, time,
- &best_newv, &best_oldv, best_act, best_tile,
- ptile);
-
- if (can_rr) {
- /* Count road time plus rail time. */
- time += get_turns_for_activity_at(punit, ACTIVITY_RAILROAD, ptile);
- consider_settler_action(pplayer, ACTIVITY_ROAD,
- road_bonus(ptile, S_RAILROAD) * 3,
- pcity->ai.railroad[i][j], oldv,
- in_use, time,
+ /* Count road time plus rail time. */
+ time += get_turns_for_activity_at(punit, ACTIVITY_RAILROAD,
+ ptile);
+ }
+ } else if (act == ACTIVITY_RAILROAD) {
+ extra = road_bonus(ptile, S_RAILROAD) * 3;
+ } else if (act == ACTIVITY_FALLOUT) {
+ extra = pplayer->ai.frost;
+ } else if (act == ACTIVITY_POLLUTION) {
+ extra = pplayer->ai.warmth;
+ }
+
+ consider_settler_action(pplayer, act,
+ extra,
+ pcity->ai.act_value[act][i][j],
+ oldv, in_use, time,
&best_newv, &best_oldv,
best_act, best_tile,
ptile);
- }
- } else if (!tile_has_special(ptile, S_RAILROAD)
- && can_rr) {
- time = mv_turns
- + get_turns_for_activity_at(punit, ACTIVITY_RAILROAD, ptile);
- consider_settler_action(pplayer, ACTIVITY_RAILROAD,
- road_bonus(ptile, S_RAILROAD) * 3,
- pcity->ai.railroad[i][j], oldv, in_use, time,
- &best_newv, &best_oldv,
- best_act, best_tile,
- ptile);
- } /* end S_ROAD else */
-
- if (tile_has_special(ptile, S_POLLUTION)) {
- time = mv_turns
- + get_turns_for_activity_at(punit, ACTIVITY_POLLUTION, ptile);
- consider_settler_action(pplayer, ACTIVITY_POLLUTION,
- pplayer->ai.warmth,
- pcity->ai.detox[i][j], oldv, in_use, time,
- &best_newv, &best_oldv,
- best_act, best_tile,
- ptile);
- }
-
- if (tile_has_special(ptile, S_FALLOUT)) {
- time = mv_turns
- + get_turns_for_activity_at(punit, ACTIVITY_FALLOUT, ptile);
- consider_settler_action(pplayer, ACTIVITY_FALLOUT,
- pplayer->ai.frost,
- pcity->ai.derad[i][j], oldv, in_use, time,
- &best_newv, &best_oldv,
- best_act, best_tile,
- ptile);
- }
-
-#ifdef REALLY_DEBUG_THIS
- freelog(LOG_DEBUG,
- "(%d %d) I=%+-4d O=%+-4d M=%+-4d R=%+-4d RR=%+-4d P=%+-4d
N=%+-4d",
- i, j,
- pcity->ai.irrigate[i][j], pcity->ai.transform[i][j],
- pcity->ai.mine[i][j], pcity->ai.road[i][j],
- pcity->ai.railroad[i][j], pcity->ai.detox[i][j],
- pcity->ai.derad[i][j]);
-#endif
- } /* end if we are a legal destination */
+ } /* endif: can the worker perform this action */
+ } activity_type_iterate_end;
+ } /* endif: are we travelling to a legal destination? */
} city_map_checked_iterate_end;
} city_list_iterate_end;
@@ -1168,13 +1122,9 @@
int best = best_worker_tile_value(pcity);
city_map_iterate(city_x, city_y) {
- pcity->ai.detox[city_x][city_y] = -1;
- pcity->ai.derad[city_x][city_y] = -1;
- pcity->ai.mine[city_x][city_y] = -1;
- pcity->ai.irrigate[city_x][city_y] = -1;
- pcity->ai.transform[city_x][city_y] = -1;
- pcity->ai.road[city_x][city_y] = -1;
- pcity->ai.railroad[city_x][city_y] = -1;
+ activity_type_iterate(act) {
+ pcity->ai.act_value[act][city_x][city_y] = -1;
+ } activity_type_iterate_end;
} city_map_iterate_end;
city_map_checked_iterate(pcity->tile,
@@ -1184,24 +1134,24 @@
enum tile_special_type old_special = ptile->special;
#endif
- pcity->ai.detox[city_x][city_y]
+ pcity->ai.act_value[ACTIVITY_POLLUTION][city_x][city_y]
= ai_calc_pollution(pcity, city_x, city_y, best, ptile);
- pcity->ai.derad[city_x][city_y] =
- ai_calc_fallout(pcity, pplayer, city_x, city_y, best, ptile);
- pcity->ai.mine[city_x][city_y]
+ pcity->ai.act_value[ACTIVITY_FALLOUT][city_x][city_y]
+ = ai_calc_fallout(pcity, pplayer, city_x, city_y, best, ptile);
+ pcity->ai.act_value[ACTIVITY_MINE][city_x][city_y]
= ai_calc_mine(pcity, city_x, city_y, ptile);
- pcity->ai.irrigate[city_x][city_y]
+ pcity->ai.act_value[ACTIVITY_IRRIGATE][city_x][city_y]
= ai_calc_irrigate(pcity, pplayer, city_x, city_y, ptile);
- pcity->ai.transform[city_x][city_y]
+ pcity->ai.act_value[ACTIVITY_TRANSFORM][city_x][city_y]
= ai_calc_transform(pcity, city_x, city_y, ptile);
/* road_bonus() is handled dynamically later; it takes into
* account settlers that have already been assigned to building
* roads this turn. */
- pcity->ai.road[city_x][city_y]
+ pcity->ai.act_value[ACTIVITY_ROAD][city_x][city_y]
= ai_calc_road(pcity, pplayer, city_x, city_y, ptile);
- pcity->ai.railroad[city_x][city_y] =
- ai_calc_railroad(pcity, pplayer, city_x, city_y, ptile);
+ pcity->ai.act_value[ACTIVITY_RAILROAD][city_x][city_y]
+ = ai_calc_railroad(pcity, pplayer, city_x, city_y, ptile);
/* Make sure nothing was accidentally changed by these calculations. */
assert(old_terrain == ptile->terrain && old_special == ptile->special);
|
|