[Freeciv-Dev] Re: (PR#2439) city iterator cleanup
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
On Fri, 29 Nov 2002, Gregory Berkolaiko via RT wrote:
>
> On Thu, 28 Nov 2002, Jason Short via RT wrote:
>
> > This patch was suggested by Per:
> >
> > It removes city_radius_iterate. This macro is not used, probably
> > shouldn't ever be used, and cannot be used because there is no
> > city_radius_iterate_end.
> >
> > It redefines map_city_radius_iterate to use city_map_checked_iterate. I
> > also change the parameter names, and add a comment on this iterator.
>
> Good patch. I love removing obsolete code.
>
> I was going to commit it and then I looked at how it's done and discovered
> that CITY_MAP_SIZE is a fake define and is hardcoded. So I couldn't fight
> off the temptation to add some comments on that. And also correct some
> mistakes... And comment formatting. Please check my English and
> commit...
>
> G.
patch is missing indeed...
:(
? civscore.log
Index: common/city.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/city.c,v
retrieving revision 1.170
diff -u -r1.170 city.c
--- common/city.c 2002/11/15 21:24:29 1.170
+++ common/city.c 2002/11/29 12:58:52
@@ -52,8 +52,7 @@
static int improvement_upkeep_asmiths(struct city *pcity, Impr_Type_id i,
bool asmiths);
-/* Iterate a city map, from the center (the city) outwards */
-
+/* Indices for city map iteration. Still hardcoded despite appearance! */
int city_map_iterate_outwards_indices[(CITY_MAP_SIZE*CITY_MAP_SIZE)-4][2] =
{
{ 2, 2 },
Index: common/city.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/city.h,v
retrieving revision 1.118
diff -u -r1.118 city.h
--- common/city.h 2002/11/25 19:18:09 1.118
+++ common/city.h 2002/11/29 12:58:52
@@ -58,8 +58,9 @@
/* for new city: default auto-attack options all on, others off: */
#define CITYOPT_DEFAULT (CITYOPT_AUTOATTACK_BITS)
-/* Diameter of the workable city area. Must be unequal.
- Some places in the code hardcodes this number (yet). */
+/* Diameter of the workable city area. Must be an odd number.
+ Some places in the code hardcodes this number, fx
+ city_map_iterate_outwards_indices */
#define CITY_MAP_SIZE 5
#define INCITE_IMPOSSIBLE_COST (1000 * 1000 * 1000)
@@ -72,7 +73,7 @@
/*
* Size of the biggest possible city.
*
-* The constant may be changed since it isn't externally visible.
+ * The constant may be changed since it isn't externally visible.
*/
#define MAX_CITY_SIZE 100
@@ -89,8 +90,7 @@
#define city_map_iterate_end \
}
-/* Iterate a city map, from the center (the city) outwards */
-
+/* Indices for city map iteration. Still hardcoded despite appearance! */
extern int
city_map_iterate_outwards_indices[(CITY_MAP_SIZE*CITY_MAP_SIZE)-4][2];
/* Iterate a city map, from the center (the city) outwards. x and y
@@ -117,7 +117,7 @@
* the city is given as a map position (x0,y0). cx and cy will be
* elements of [0,CITY_MAP_SIZE). mx and my will form the map position
* (mx,my).
-*/
+ */
#define city_map_checked_iterate(x0, y0, cx, cy, mx, my) { \
city_map_iterate_outwards(cx, cy) { \
int mx, my; \
@@ -127,31 +127,15 @@
} \
} city_map_iterate_outwards_end \
}
-
-/* Iterate a city radius: (dx,dy) centered on (0,0) */
-#define city_radius_iterate(dx, dy) \
- for (dy = -(int)(CITY_MAP_SIZE/2); dy<(int)(CITY_MAP_SIZE/2); dy++) \
- for (dx = -(int)(CITY_MAP_SIZE/2); dx<(int)(CITY_MAP_SIZE/2); dx++) \
- if (! ((dx == -(int)(CITY_MAP_SIZE/2) || dx == (int)(CITY_MAP_SIZE/2))
&& \
- (dy == -(int)(CITY_MAP_SIZE/2) || dy == (int)(CITY_MAP_SIZE/2))) )
-
-#define map_city_radius_iterate(city_x, city_y, x_itr, y_itr) \
+/* Does the same thing as city_map_checked_iterate, but keeps the city
+ * coordinates hidden. */
+#define map_city_radius_iterate(city_x, city_y, map_x, map_y) \
{ \
- int x_itr, y_itr; \
- int MCMI_x, MCMI_y; \
- for (MCMI_x = 0; MCMI_x < CITY_MAP_SIZE; MCMI_x++) { \
- for (MCMI_y = 0; MCMI_y < CITY_MAP_SIZE; MCMI_y++) { \
- if (! ((MCMI_x == 0 || MCMI_x == (CITY_MAP_SIZE-1)) \
- && (MCMI_y == 0 || MCMI_y == (CITY_MAP_SIZE-1))) ) { \
- if(!base_city_map_to_map(&x_itr, &y_itr, city_x, \
- city_y, MCMI_x, MCMI_y)) \
- continue;
+ city_map_checked_iterate(city_x, city_y, _cx, _cy, map_x, map_y) {
#define map_city_radius_iterate_end \
- } \
- } \
- } \
+ } city_map_checked_iterate_end; \
}
|
|