[Freeciv-Dev] workers not placed near city (PR#70)
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
Full_Name: Jeff Mallatt
Version: 1.8.1
OS: Linux
Submission from: (NULL) (199.103.194.35)
When placing workers around a city, they are preferentially placed far to the
north-west. There, they frequently interfere with workers from a neighboring
city. I believe workers should be placed near the city. This patch does that.
diff -Nur freeciv-old/common/city.c freeciv/common/city.c
--- freeciv-old/common/city.c Sat Jul 24 01:31:23 1999
+++ freeciv/common/city.c Sat Jul 24 11:22:58 1999
@@ -29,6 +29,23 @@
static int improvement_upkeep_asmiths(struct city *pcity, int i, int asmiths);
+
+/* Iterate a city map, from the center (the city) outwards */
+
+int city_map_iterate_outwards_indices[(CITY_MAP_SIZE*CITY_MAP_SIZE)-4][2] =
+{
+ { 2, 2 },
+
+ { 1, 2 }, { 2, 1 }, { 3, 2 }, { 2, 3 },
+ { 1, 3 }, { 1, 1 }, { 3, 1 }, { 3, 3 },
+
+ { 0, 2 }, { 2, 0 }, { 4, 2 }, { 2, 4 },
+ { 0, 3 }, { 0, 1 },
+ { 1, 0 }, { 3, 0 },
+ { 4, 1 }, { 4, 3 },
+ { 3, 4 }, { 1, 4 }
+};
+
/****************************************************************
All the city improvements:
Use get_improvement_type(id) to access the array.
diff -Nur freeciv-old/common/city.h freeciv/common/city.h
--- freeciv-old/common/city.h Wed Jul 21 07:55:32 1999
+++ freeciv/common/city.h Sat Jul 24 10:24:52 1999
@@ -91,6 +91,26 @@
if (! ((x == 0 || x == 4) && (y == 0 || y == 4)))
+/* Iterate a city map, from the center (the city) outwards */
+
+extern int
city_map_iterate_outwards_indices[(CITY_MAP_SIZE*CITY_MAP_SIZE)-4][2];
+
+#define city_map_iterate_outwards(x, y) { \
+ int city_map_iterate_outwards_index; \
+ for \
+ ( \
+ city_map_iterate_outwards_index = 0; \
+ city_map_iterate_outwards_index < (CITY_MAP_SIZE*CITY_MAP_SIZE)-4; \
+ city_map_iterate_outwards_index++ \
+ ) \
+ { \
+ x = city_map_iterate_outwards_indices[city_map_iterate_outwards_index][0];
\
+ y = city_map_iterate_outwards_indices[city_map_iterate_outwards_index][1];
+
+#define city_map_iterate_outwards_end } }
+
+
+
struct ai_choice {
int choice; /* what the advisor wants */
int want; /* how bad it wants it (0-100) */
diff -Nur freeciv-old/server/cityturn.c freeciv/server/cityturn.c
--- freeciv-old/server/cityturn.c Wed Jul 21 07:58:54 1999
+++ freeciv/server/cityturn.c Sat Jul 24 13:46:48 1999
@@ -589,7 +589,8 @@
bx=0;
by=0;
best = 0;
- city_map_iterate(x, y) {
+ /* try to work near the city */
+ city_map_iterate_outwards(x, y)
if(can_place_worker_here(pcity, x, y)) {
cur = city_tile_value(pcity, x, y, *foodneed, *prodneed) -
conflict[x][y];
if (cur > best) {
@@ -598,7 +599,7 @@
best = cur;
}
}
- }
+ city_map_iterate_outwards_end;
if(bx || by) {
set_worker_city(pcity, bx, by, C_TILE_WORKER);
(*workers)--; /* amazing what this did with no parens! -- Syela */
diff -Nur freeciv-old/server/settlers.c freeciv/server/settlers.c
--- freeciv-old/server/settlers.c Sat Jul 24 01:32:10 1999
+++ freeciv/server/settlers.c Sat Jul 24 11:38:59 1999
@@ -839,7 +839,8 @@
generate_warmap(mycity, punit);
city_list_iterate(pplayer->cities, pcity)
worst = worst_worker_tile_value(pcity);
- city_map_iterate(i, j) {
+ /* try to work near the city */
+ city_map_iterate_outwards(i, j)
if (get_worker_city(pcity, i, j) == C_TILE_UNAVAILABLE) continue;
x = map_adjust_x(pcity->x + i - 2);
y = pcity->y + j - 2; /* No adjust! */
@@ -979,7 +980,7 @@
best_newv=newv; gx=x; gy=y; best_oldv=oldv;
}
} /* end if we are a legal destination */
- } /* end city map iterate */
+ city_map_iterate_outwards_end;
city_list_iterate_end;
/** Found the best square to upgrade, have gx, gy, best_newv, best_act **/
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Freeciv-Dev] workers not placed near city (PR#70),
jjm <=
|
|