[Freeciv-Dev] Re: (PR#12861) evaluate_improvements simplification
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Subject: |
[Freeciv-Dev] Re: (PR#12861) evaluate_improvements simplification |
From: |
"Brian Dunstan" <bdunstan149@xxxxxxxxx> |
Date: |
Sat, 23 Apr 2005 20:54:12 -0700 |
Reply-to: |
bugs@xxxxxxxxxxx |
<URL: http://bugs.freeciv.org/Ticket/Display.html?id=12861 >
--- Jason Short <jdorje@xxxxxxxxxxxxxxxxxxxxx> wrote:
>
> <URL:
> http://bugs.freeciv.org/Ticket/Display.html?id=12861
> >
>
> As the attached savegame shows, autosettlers pretty
> much break under
> this patch.
>
> 1. Mountains aren't mined or transformed.
> 2. Deserts often aren't transformed.
> 3. Farmland often isn't built.
> 4. Roads aren't built on mined hills.
The attached patch should resolve these problems.
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
diff -Nur -Xfreeciv/diff_ignore freeciv/common/city.h
freeciv_ptwice/common/city.h
--- freeciv/common/city.h 2005-04-23 20:30:48.810531512 -0400
+++ freeciv_ptwice/common/city.h 2005-04-23 19:59:55.262313672 -0400
@@ -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.
diff -Nur -Xfreeciv/diff_ignore freeciv/common/fc_types.h
freeciv_ptwice/common/fc_types.h
--- freeciv/common/fc_types.h 2005-04-23 20:30:48.801532880 -0400
+++ freeciv_ptwice/common/fc_types.h 2005-04-23 19:59:55.253315040 -0400
@@ -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;
diff -Nur -Xfreeciv/diff_ignore freeciv/common/unit.h
freeciv_ptwice/common/unit.h
--- freeciv/common/unit.h 2005-04-23 20:30:48.808531816 -0400
+++ freeciv_ptwice/common/unit.h 2005-04-23 19:59:55.260313976 -0400
@@ -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);
diff -Nur -Xfreeciv/diff_ignore freeciv/server/settlers.c
freeciv_ptwice/server/settlers.c
--- freeciv/server/settlers.c 2005-04-23 20:30:48.776536680 -0400
+++ freeciv_ptwice/server/settlers.c 2005-04-23 20:07:20.122684616 -0400
@@ -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,52 @@
/* 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,
- &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);
-
- 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,
+ 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;
+ int base_value = pcity->ai.act_value[act][i][j];
+ 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);
+
+ base_value = pcity->ai.act_value[ACTIVITY_RAILROAD][i][j];
+
+ /* 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,
+ base_value, 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 +1124,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 +1136,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);
|
|