[Freeciv-Dev] Re: (PR#7481) meta-ticket for hex maps
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
<URL: http://rt.freeciv.org/Ticket/Display.html?id=7481 >
Here's an updated hex-topology patch.
It is still just a quick hack.
jason
Index: client/citydlg_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/citydlg_common.c,v
retrieving revision 1.31
diff -u -r1.31 citydlg_common.c
--- client/citydlg_common.c 4 Apr 2004 14:49:09 -0000 1.31
+++ client/citydlg_common.c 27 Apr 2004 06:18:15 -0000
@@ -37,7 +37,7 @@
int get_citydlg_canvas_width(void)
{
if (is_isometric) {
- return (CITY_MAP_SIZE - 1) * NORMAL_TILE_WIDTH;
+ return (CITY_MAP_SIZE - 2) * NORMAL_TILE_WIDTH;
} else {
return CITY_MAP_SIZE * NORMAL_TILE_WIDTH;
}
@@ -49,7 +49,7 @@
int get_citydlg_canvas_height(void)
{
if (is_isometric) {
- return (CITY_MAP_SIZE - 1) * NORMAL_TILE_HEIGHT;
+ return (CITY_MAP_SIZE) * NORMAL_TILE_HEIGHT;
} else {
return CITY_MAP_SIZE * NORMAL_TILE_HEIGHT;
}
@@ -61,6 +61,10 @@
**************************************************************************/
bool city_to_canvas_pos(int *canvas_x, int *canvas_y, int city_x, int city_y)
{
+ const int x0 = CITY_MAP_RADIUS, y0 = CITY_MAP_RADIUS;
+ const int width = get_citydlg_canvas_width();
+ const int height = get_citydlg_canvas_height();
+
if (is_isometric) {
/*
* The top-left corner is in the center of tile (-2, 2). However,
@@ -68,15 +72,18 @@
* subtract off half a tile in each direction. For a more
* rigorous example, see map_pos_to_canvas_pos().
*/
- int iso_x = (city_x - city_y) + (2 * CITY_MAP_RADIUS);
- int iso_y = (city_x + city_y) - (0);
+ int iso_x = (city_x - city_y) - (x0 - y0);
+ int iso_y = (city_x + city_y) - (x0 + y0);
- *canvas_x = (iso_x - 1) * NORMAL_TILE_WIDTH / 2;
- *canvas_y = (iso_y - 1) * NORMAL_TILE_HEIGHT / 2;
+ *canvas_x = iso_x * NORMAL_TILE_WIDTH / 2;
+ *canvas_y = iso_y * NORMAL_TILE_HEIGHT / 2;
} else {
- *canvas_x = city_x * NORMAL_TILE_WIDTH;
- *canvas_y = city_y * NORMAL_TILE_HEIGHT;
+ *canvas_x = (city_x - x0) * NORMAL_TILE_WIDTH;
+ *canvas_y = (city_y - y0) * NORMAL_TILE_HEIGHT;
}
+
+ *canvas_x += (width - NORMAL_TILE_WIDTH) / 2;
+ *canvas_y += (height - NORMAL_TILE_HEIGHT) / 2;
if (!is_valid_city_coords(city_x, city_y)) {
assert(FALSE);
Index: client/mapview_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/mapview_common.c,v
retrieving revision 1.108
diff -u -r1.108 mapview_common.c
--- client/mapview_common.c 26 Apr 2004 21:26:58 -0000 1.108
+++ client/mapview_common.c 27 Apr 2004 06:18:15 -0000
@@ -1628,6 +1628,7 @@
}
canvas_src_x += NORMAL_TILE_WIDTH/2;
canvas_src_y += NORMAL_TILE_HEIGHT/2;
+ assert(is_valid_dir(dir));
DIRSTEP(canvas_dest_x, canvas_dest_y, dir);
canvas_dest_x = canvas_src_x + (NORMAL_TILE_WIDTH * canvas_dest_x) / 2;
canvas_dest_y = canvas_src_y + (NORMAL_TILE_WIDTH * canvas_dest_y) / 2;
Index: client/packhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/packhand.c,v
retrieving revision 1.362
diff -u -r1.362 packhand.c
--- client/packhand.c 14 Apr 2004 17:18:36 -0000 1.362
+++ client/packhand.c 27 Apr 2004 06:18:16 -0000
@@ -380,7 +380,7 @@
**************************************************************************/
void handle_city_info(struct packet_city_info *packet)
{
- int i, x, y;
+ int i;
bool city_is_new, city_has_changed_owner = FALSE, need_effect_update = FALSE;
struct city *pcity;
bool popup, update_descriptions = FALSE;
@@ -494,18 +494,17 @@
pcity->caravan_shields=packet->caravan_shields;
pcity->last_turns_shield_surplus = packet->last_turns_shield_surplus;
- i=0;
- for(y=0; y<CITY_MAP_SIZE; y++) {
- for(x=0; x<CITY_MAP_SIZE; x++) {
- if (city_is_new) {
- /* Need to pre-initialize before set_worker_city() -- dwp */
- pcity->city_map[x][y] =
- is_valid_city_coords(x, y) ? C_TILE_EMPTY : C_TILE_UNAVAILABLE;
- }
- if (is_valid_city_coords(x, y)) {
- set_worker_city(pcity, x, y, packet->city_map[i] - '0');
- }
- i++;
+ for (i = 0; i < CITY_MAP_SIZE * CITY_MAP_SIZE; i++) {
+ const int x = i % CITY_MAP_SIZE, y = i / CITY_MAP_SIZE;
+
+ if (city_is_new) {
+ /* Need to pre-initialize before set_worker_city() -- dwp */
+ pcity->city_map[x][y] =
+ is_valid_city_coords(x, y) ? C_TILE_EMPTY : C_TILE_UNAVAILABLE;
+ }
+
+ if (is_valid_city_coords(x, y)) {
+ set_worker_city(pcity, x, y, packet->city_map[i]);
}
}
Index: common/city.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/city.c,v
retrieving revision 1.206
diff -u -r1.206 city.c
--- common/city.c 22 Apr 2004 22:58:28 -0000 1.206
+++ common/city.c 27 Apr 2004 06:18:16 -0000
@@ -62,14 +62,11 @@
{
{ 2, 2 },
- { 1, 2 }, { 2, 1 }, { 3, 2 }, { 2, 3 },
- { 1, 3 }, { 1, 1 }, { 3, 1 }, { 3, 3 },
+ { 1, 1 }, { 2, 1 }, { 1, 2 },
+ { 3, 3 }, { 2, 3 }, { 3, 2 },
- { 0, 2 }, { 2, 0 }, { 4, 2 }, { 2, 4 },
- { 0, 3 }, { 0, 1 },
- { 1, 0 }, { 3, 0 },
- { 4, 1 }, { 4, 3 },
- { 3, 4 }, { 1, 4 }
+ { 0, 2 }, { 0, 1 }, { 0, 0 }, { 1, 0 }, { 2, 0 }, { 3, 1 },
+ { 4, 2 }, { 4, 3 }, { 4, 4 }, { 3, 4 }, { 2, 4 }, { 1, 3 }
};
struct citystyle *city_styles = NULL;
@@ -79,15 +76,17 @@
**************************************************************************/
bool is_valid_city_coords(const int city_x, const int city_y)
{
- if ((city_x == 0 || city_x == CITY_MAP_SIZE-1)
- && (city_y == 0 || city_y == CITY_MAP_SIZE-1))
- return FALSE;
+ const int center_x = CITY_MAP_SIZE / 2, center_y = CITY_MAP_SIZE / 2;
+ int dx, dy;
+
if (city_x < 0 || city_y < 0
|| city_x >= CITY_MAP_SIZE
|| city_y >= CITY_MAP_SIZE)
return FALSE;
- return TRUE;
+ dx = city_x - center_x;
+ dy = city_y - center_y;
+ return vector_to_map_distance(dx, dy) <= CITY_MAP_RADIUS;
}
/**************************************************************************
@@ -185,8 +184,9 @@
**************************************************************************/
enum city_tile_type get_worker_city(struct city *pcity, int city_x, int city_y)
{
- if (!is_valid_city_coords(city_x, city_y))
+ if (!is_valid_city_coords(city_x, city_y)) {
return C_TILE_UNAVAILABLE;
+ }
return pcity->city_map[city_x][city_y];
}
Index: common/city.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/city.h,v
retrieving revision 1.141
diff -u -r1.141 city.h
--- common/city.h 22 Apr 2004 22:58:28 -0000 1.141
+++ common/city.h 27 Apr 2004 06:18:16 -0000
@@ -66,7 +66,7 @@
#define CITY_MAP_SIZE (CITY_MAP_RADIUS * 2 + 1)
/* Number of tiles a city can use */
-#define CITY_TILES (CITY_MAP_SIZE * CITY_MAP_SIZE - 4)
+#define CITY_TILES 19
#define INCITE_IMPOSSIBLE_COST (1000 * 1000 * 1000)
@@ -89,8 +89,7 @@
int x, y; \
for (y = 0; y < CITY_MAP_SIZE; y++) \
for (x = 0; x < CITY_MAP_SIZE; x++) \
- if (! ((x == 0 || x == (CITY_MAP_SIZE-1)) && \
- (y == 0 || y == (CITY_MAP_SIZE-1))) )
+ if (is_valid_city_coords(x, y))
#define city_map_iterate_end \
}
Index: common/dataio.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/dataio.c,v
retrieving revision 1.10
diff -u -r1.10 dataio.c
--- common/dataio.c 14 Feb 2004 02:21:25 -0000 1.10
+++ common/dataio.c 27 Apr 2004 06:18:16 -0000
@@ -53,10 +53,6 @@
#include "dataio.h"
-static const int city_map_index[20] = {
- 1, 2, 3, 5, 6, 7, 8, 9, 10, 11, 13, 14, 15, 16, 17, 18, 19, 21, 22, 23
-};
-
/**************************************************************************
...
**************************************************************************/
@@ -403,22 +399,6 @@
/**************************************************************************
...
**************************************************************************/
-void dio_put_city_map(struct data_out *dout, const char *value)
-{
- int i;
-
- for (i = 0; i < 20; i += 5) {
- dio_put_uint8(dout, (value[city_map_index[i]] - '0') * 81 +
- (value[city_map_index[i + 1]] - '0') * 27 +
- (value[city_map_index[i + 2]] - '0') * 9 +
- (value[city_map_index[i + 3]] - '0') * 3 +
- (value[city_map_index[i + 4]] - '0') * 1);
- }
-}
-
-/**************************************************************************
-...
-**************************************************************************/
void dio_get_uint8(struct data_in *din, int *dest)
{
if (enough_data(din, 1)) {
@@ -625,55 +605,6 @@
if (din->too_short) {
din->bad_bit_string = TRUE;
- }
-}
-
-/**************************************************************************
-...
-**************************************************************************/
-void dio_get_city_map(struct data_in *din, char *dest, size_t max_dest_size)
-{
- int i;
-
- if (dest) {
- assert(max_dest_size >= 26);
- dest[0] = '2';
- dest[4] = '2';
- dest[12] = '1';
- dest[20] = '2';
- dest[24] = '2';
- dest[25] = '\0';
- }
-
- if (!enough_data(din, 4)) {
- if (dest) {
- for (i = 0; i < 20;) {
- int j;
-
- for (j = 0; j < 5; j++) {
- dest[city_map_index[i++]] = '0';
- }
- }
- }
- return;
- }
-
- for (i = 0; i < 20;) {
- int j;
-
- dio_get_uint8(din, &j);
-
- if (dest) {
- dest[city_map_index[i++]] = '0' + j / 81;
- j %= 81;
- dest[city_map_index[i++]] = '0' + j / 27;
- j %= 27;
- dest[city_map_index[i++]] = '0' + j / 9;
- j %= 9;
- dest[city_map_index[i++]] = '0' + j / 3;
- j %= 3;
- dest[city_map_index[i++]] = '0' + j;
- }
}
}
Index: common/dataio.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/dataio.h,v
retrieving revision 1.5
diff -u -r1.5 dataio.h
--- common/dataio.h 10 Apr 2004 03:47:49 -0000 1.5
+++ common/dataio.h 27 Apr 2004 06:18:16 -0000
@@ -68,7 +68,6 @@
void dio_get_string(struct data_in *din, char *dest, size_t max_dest_size);
void dio_get_bit_string(struct data_in *din, char *dest,
size_t max_dest_size);
-void dio_get_city_map(struct data_in *din, char *dest, size_t max_dest_size);
void dio_get_tech_list(struct data_in *din, int *dest);
void dio_get_worklist(struct data_in *din, struct worklist *pwl);
void dio_get_diplstate(struct data_in *din, struct player_diplstate *pds);
Index: common/map.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/map.c,v
retrieving revision 1.165
diff -u -r1.165 map.c
--- common/map.c 20 Apr 2004 20:10:37 -0000 1.165
+++ common/map.c 27 Apr 2004 06:18:17 -0000
@@ -42,10 +42,6 @@
const int DIR_DX[8] = { -1, 0, 1, -1, 1, -1, 0, 1 };
const int DIR_DY[8] = { -1, -1, -1, 0, 0, 1, 1, 1 };
-/* like DIR_DX[] and DIR_DY[], only cartesian */
-const int CAR_DIR_DX[4] = {1, 0, -1, 0};
-const int CAR_DIR_DY[4] = {0, 1, 0, -1};
-
/* Names of specials.
* (These must correspond to enum tile_special_type in terrain.h.)
*/
@@ -323,11 +319,15 @@
***************************************************************/
int real_map_distance(int x0, int y0, int x1, int y1)
{
- int dx, dy;
+ if (topo_has_flag(TF_HEX)) {
+ return map_distance(x0, y0, x1, y1);
+ } else {
+ int dx, dy;
- map_distance_vector(&dx, &dy, x0, y0, x1, y1);
+ map_distance_vector(&dx, &dy, x0, y0, x1, y1);
- return MAX(abs(dx), abs(dy));
+ return MAX(abs(dx), abs(dy));
+ }
}
/***************************************************************
@@ -335,13 +335,53 @@
***************************************************************/
int sq_map_distance(int x0, int y0, int x1, int y1)
{
- /* We assume map_distance_vector gives us the vector with the
- minimum squared distance. Right now this is true. */
- int dx, dy;
+ if (topo_has_flag(TF_HEX)) {
+ int dist = map_distance(x0, y0, x1, y1);
- map_distance_vector(&dx, &dy, x0, y0, x1, y1);
+ /* In a hex map the pythagorean distance is not significantly different
+ * from the map distance. If you think about what the value's used
+ * for it becomes apparent the two should be the same. */
+ return dist * dist;
+ } else {
+ /* We assume map_distance_vector gives us the vector with the
+ * minimum squared distance. Right now this is true. */
+ int dx, dy;
+
+ map_distance_vector(&dx, &dy, x0, y0, x1, y1);
+
+ return dx * dx + dy * dy;
+ }
+}
- return (dx*dx + dy*dy);
+int vector_to_map_distance(int dx, int dy)
+{
+ if (topo_has_flag(TF_HEX)) {
+ if (topo_has_flag(TF_ISO)) {
+ /* Iso-hex: you can't move NE or SW. */
+ if ((dx < 0 && dy > 0)
+ || (dx > 0 && dy < 0)) {
+ /* Diagonal moves in this direction aren't allowed, so it will take
+ * the full number of moves. */
+ return abs(dx) + abs(dy);
+ } else {
+ /* Diagonal moves in this direction *are* allowed. */
+ return MAX(abs(dx), abs(dy));
+ }
+ } else {
+ /* Hex: you can't move SE or NW. */
+ if ((dx > 0 && dy > 0)
+ || (dx < 0 && dy < 0)) {
+ /* Diagonal moves in this direction aren't allowed, so it will take
+ * the full number of moves. */
+ return abs(dx) + abs(dy);
+ } else {
+ /* Diagonal moves in this direction *are* allowed. */
+ return MAX(abs(dx), abs(dy));
+ }
+ }
+ } else {
+ return abs(dx) + abs(dy);
+ }
}
/***************************************************************
@@ -355,7 +395,7 @@
map_distance_vector(&dx, &dy, x0, y0, x1, y1);
- return abs(dx) + abs(dy);
+ return vector_to_map_distance(dx, dy);
}
/***************************************************************
@@ -565,8 +605,9 @@
ptile = map_get_tile(x1, y1);
if (is_ocean(ptile->terrain)
|| tile_has_special(ptile, S_RIVER)
- || tile_has_special(ptile, S_IRRIGATION))
+ || tile_has_special(ptile, S_IRRIGATION)) {
return TRUE;
+ }
} cartesian_adjacent_iterate_end;
return FALSE;
@@ -1474,10 +1515,10 @@
return DIR8_SOUTHWEST;
case DIR8_NORTHWEST:
return DIR8_WEST;
- default:
- assert(0);
- return -1;
}
+
+ assert(0);
+ return -1;
}
/**************************************************************************
@@ -1486,18 +1527,20 @@
bool is_valid_dir(enum direction8 dir)
{
switch (dir) {
- case DIR8_NORTH:
+ case DIR8_SOUTHEAST:
+ case DIR8_NORTHWEST:
+ return !(topo_has_flag(TF_HEX) && !topo_has_flag(TF_ISO));
case DIR8_NORTHEAST:
+ case DIR8_SOUTHWEST:
+ return !(topo_has_flag(TF_HEX) && topo_has_flag(TF_ISO));
+ case DIR8_NORTH:
case DIR8_EAST:
- case DIR8_SOUTHEAST:
case DIR8_SOUTH:
- case DIR8_SOUTHWEST:
case DIR8_WEST:
- case DIR8_NORTHWEST:
return TRUE;
- default:
- return FALSE;
}
+
+ return FALSE;
}
/**************************************************************************
Index: common/map.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/map.h,v
retrieving revision 1.179
diff -u -r1.179 map.h
--- common/map.h 21 Apr 2004 19:01:57 -0000 1.179
+++ common/map.h 27 Apr 2004 06:18:17 -0000
@@ -150,7 +150,8 @@
/* Bit-values. */
TF_WRAPX = 1,
TF_WRAPY = 2,
- TF_ISO = 4
+ TF_ISO = 4,
+ TF_HEX = 8
};
#define CURRENT_TOPOLOGY (map.topology_id)
@@ -166,6 +167,7 @@
const char *map_get_tile_fpt_text(int x, int y);
struct tile *map_get_tile(int x, int y);
+int vector_to_map_distance(int dx, int dy);
int map_distance(int x0, int y0, int x1, int y1);
int real_map_distance(int x0, int y0, int x1, int y1);
int sq_map_distance(int x0, int y0, int x1, int y1);
@@ -199,13 +201,13 @@
/* Obscure math. See explanation in doc/HACKING. */
#define native_to_map_pos(pmap_x, pmap_y, nat_x, nat_y) \
- (topo_has_flag(TF_ISO) \
+ ((topo_has_flag(TF_ISO) || topo_has_flag(TF_HEX)) \
? (*(pmap_x) = ((nat_y) + ((nat_y) & 1)) / 2 + (nat_x), \
*(pmap_y) = (nat_y) - *(pmap_x) + map.xsize) \
: (*(pmap_x) = (nat_x), *(pmap_y) = (nat_y)))
#define map_to_native_pos(pnat_x, pnat_y, map_x, map_y) \
- (topo_has_flag(TF_ISO) \
+ ((topo_has_flag(TF_ISO) || topo_has_flag(TF_HEX)) \
? (*(pnat_y) = (map_x) + (map_y) - map.xsize, \
*(pnat_x) = (2 * (map_x) - *(pnat_y) - (*(pnat_y) & 1)) / 2) \
: (*(pnat_x) = (map_x), *(pnat_y) = (map_y)))
@@ -232,9 +234,10 @@
* we bend this rule here.
*/
#define MAPSTEP(dest_x, dest_y, src_x, src_y, dir) \
-( (dest_x) = (src_x) + DIR_DX[(dir)], \
- (dest_y) = (src_y) + DIR_DY[(dir)], \
- normalize_map_pos(&(dest_x), &(dest_y)))
+ (is_valid_dir(dir) \
+ && ((dest_x) = (src_x) + DIR_DX[(dir)], \
+ (dest_y) = (src_y) + DIR_DY[(dir)], \
+ normalize_map_pos(&(dest_x), &(dest_y))))
struct player *map_get_owner(int x, int y);
void map_set_owner(int x, int y, struct player *pplayer);
@@ -269,7 +272,7 @@
* TODO: implement this for iso-maps.
*/
#define IS_BORDER_MAP_POS(x, y, dist) \
- (topo_has_flag(TF_ISO) \
+ (topo_has_flag(TF_ISO) || topo_has_flag(TF_HEX) \
|| (x) < (dist) || (x) >= map.xsize - (dist) \
|| (y) < (dist) || (y) >= map.ysize - (dist))
@@ -485,6 +488,9 @@
int MACRO_center_y = (center_y); \
CHECK_MAP_POS(MACRO_center_x, MACRO_center_y); \
for (dir_itr = 0; dir_itr < 8; dir_itr++) { \
+ if (!is_valid_dir(dir_itr)) { \
+ continue;
\
+ } \
DIRSTEP(x_itr, y_itr, dir_itr); \
x_itr += MACRO_center_x; \
y_itr += MACRO_center_y; \
@@ -551,9 +557,23 @@
/* is the direction "cardinal"? Cardinal directions
* (also called cartesian) are the four main ones */
-#define DIR_IS_CARDINAL(dir) \
- ((dir) == DIR8_NORTH || (dir) == DIR8_EAST || \
- (dir) == DIR8_WEST || (dir) == DIR8_SOUTH)
+static inline bool DIR_IS_CARDINAL(enum direction8 dir)
+{
+ switch (dir) {
+ case DIR8_NORTH:
+ case DIR8_SOUTH:
+ case DIR8_EAST:
+ case DIR8_WEST:
+ return TRUE;
+ case DIR8_NORTHEAST:
+ case DIR8_NORTHWEST:
+ case DIR8_SOUTHEAST:
+ case DIR8_SOUTHWEST:
+ /* In hex all directions are "cardinal". */
+ return topo_has_flag(TF_HEX);
+ }
+ return FALSE;
+}
enum direction8 dir_cw(enum direction8 dir);
enum direction8 dir_ccw(enum direction8 dir);
@@ -563,26 +583,14 @@
extern const int DIR_DX[8];
extern const int DIR_DY[8];
-/* like DIR_DX[] and DIR_DY[], only cartesian */
-extern const int CAR_DIR_DX[4];
-extern const int CAR_DIR_DY[4];
-
#define cartesian_adjacent_iterate(x, y, IAC_x, IAC_y) \
{ \
- int IAC_i; \
- int IAC_x, IAC_y; \
- bool _is_border = IS_BORDER_MAP_POS(x, y, 1); \
- CHECK_MAP_POS(x, y); \
- for (IAC_i = 0; IAC_i < 4; IAC_i++) { \
- IAC_x = x + CAR_DIR_DX[IAC_i]; \
- IAC_y = y + CAR_DIR_DY[IAC_i]; \
- \
- if (_is_border && !normalize_map_pos(&IAC_x, &IAC_y)) { \
- continue; \
- }
+ adjc_dir_iterate(x, y, IAC_x, IAC_y, _dir) { \
+ if (DIR_IS_CARDINAL(_dir)) {
#define cartesian_adjacent_iterate_end \
- } \
+ } \
+ } adjc_dir_iterate_end; \
}
/* Used for network transmission; do not change. */
@@ -603,7 +611,7 @@
#define MAP_ORIGINAL_TOPO TF_WRAPX
#define MAP_DEFAULT_TOPO TF_WRAPX
#define MAP_MIN_TOPO 0
-#define MAP_MAX_TOPO 7
+#define MAP_MAX_TOPO 15
#define MAP_DEFAULT_SEED 0
#define MAP_MIN_SEED 0
Index: common/packets.def
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/packets.def,v
retrieving revision 1.21
diff -u -r1.21 packets.def
--- common/packets.def 24 Apr 2004 17:32:47 -0000 1.21
+++ common/packets.def 27 Apr 2004 06:18:17 -0000
@@ -151,7 +151,6 @@
type MEMORY = memory(unsigned char)
type STRING = string(char)
type BIT_STRING = bit_string(char)
-type CITY_MAP = city_map(char)
type WORKLIST = worklist(struct worklist)
type TECH_LIST = tech_list(int)
type EFFECT = effect(struct impr_effect)
@@ -169,6 +168,7 @@
type RIVER_MOVE = uint8(enum special_river_move)
type REPORT_TYPE = uint8(enum report_type)
type AUTH_TYPE = uint8(enum authentication_type)
+type CITY_MAP = uint8(enum city_tile_type)
type IMPR_RANGE = uint8(enum impr_range)
type DIRECTION = uint8(enum direction8)
type ORDERS = uint8(enum unit_orders)
@@ -408,7 +408,7 @@
WORKLIST worklist;
BIT_STRING improvements[B_LAST+1];
- CITY_MAP city_map[CITY_MAP_SIZE*CITY_MAP_SIZE+1];
+ CITY_MAP city_map[CITY_MAP_SIZE * CITY_MAP_SIZE];
BOOL did_buy, did_sell, was_happy, airlift, diplomat_investigate;
Index: common/packets_gen.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/packets_gen.c,v
retrieving revision 1.23
diff -u -r1.23 packets_gen.c
--- common/packets_gen.c 14 Apr 2004 11:19:44 -0000 1.23
+++ common/packets_gen.c 27 Apr 2004 06:18:19 -0000
@@ -4555,7 +4555,14 @@
dio_get_bit_string(&din, real_packet->improvements,
sizeof(real_packet->improvements));
}
if (BV_ISSET(fields, 39)) {
- dio_get_city_map(&din, real_packet->city_map,
sizeof(real_packet->city_map));
+
+ {
+ int i;
+
+ for (i = 0; i < CITY_MAP_SIZE * CITY_MAP_SIZE; i++) {
+ dio_get_uint8(&din, (int *) &real_packet->city_map[i]);
+ }
+ }
}
real_packet->did_buy = BV_ISSET(fields, 40);
real_packet->did_sell = BV_ISSET(fields, 41);
@@ -4832,10 +4839,10 @@
{
- differ = (CITY_MAP_SIZE*CITY_MAP_SIZE+1 !=
CITY_MAP_SIZE*CITY_MAP_SIZE+1);
+ differ = (CITY_MAP_SIZE * CITY_MAP_SIZE != CITY_MAP_SIZE *
CITY_MAP_SIZE);
if(!differ) {
int i;
- for (i = 0; i < CITY_MAP_SIZE*CITY_MAP_SIZE+1; i++) {
+ for (i = 0; i < CITY_MAP_SIZE * CITY_MAP_SIZE; i++) {
if (old->city_map[i] != real_packet->city_map[i]) {
differ = TRUE;
break;
@@ -5037,7 +5044,14 @@
dio_put_bit_string(&dout, real_packet->improvements);
}
if (BV_ISSET(fields, 39)) {
- dio_put_city_map(&dout, real_packet->city_map);
+
+ {
+ int i;
+
+ for (i = 0; i < CITY_MAP_SIZE * CITY_MAP_SIZE; i++) {
+ dio_put_uint8(&dout, real_packet->city_map[i]);
+ }
+ }
}
/* field 40 is folded into the header */
/* field 41 is folded into the header */
Index: common/packets_gen.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/packets_gen.h,v
retrieving revision 1.19
diff -u -r1.19 packets_gen.h
--- common/packets_gen.h 24 Apr 2004 17:32:47 -0000 1.19
+++ common/packets_gen.h 27 Apr 2004 06:18:19 -0000
@@ -201,7 +201,7 @@
int last_turns_shield_surplus;
struct worklist worklist;
char improvements[B_LAST+1];
- char city_map[CITY_MAP_SIZE*CITY_MAP_SIZE+1];
+ enum city_tile_type city_map[CITY_MAP_SIZE * CITY_MAP_SIZE];
bool did_buy;
bool did_sell;
bool was_happy;
Index: server/citytools.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/citytools.c,v
retrieving revision 1.257
diff -u -r1.257 citytools.c
--- server/citytools.c 22 Mar 2004 20:58:13 -0000 1.257
+++ server/citytools.c 27 Apr 2004 06:18:19 -0000
@@ -1101,10 +1101,11 @@
for (y_itr = 0; y_itr < CITY_MAP_SIZE; y_itr++) {
for (x_itr = 0; x_itr < CITY_MAP_SIZE; x_itr++) {
if (is_valid_city_coords(x_itr, y_itr)
- && city_can_work_tile(pcity, x_itr, y_itr))
+ && city_can_work_tile(pcity, x_itr, y_itr)) {
pcity->city_map[x_itr][y_itr] = C_TILE_EMPTY;
- else
+ } else {
pcity->city_map[x_itr][y_itr] = C_TILE_UNAVAILABLE;
+ }
}
}
@@ -1733,11 +1734,12 @@
packet->did_buy=pcity->did_buy;
packet->did_sell=pcity->did_sell;
packet->was_happy=pcity->was_happy;
- p=packet->city_map;
+
+ i = 0;
for(y=0; y<CITY_MAP_SIZE; y++)
- for(x=0; x<CITY_MAP_SIZE; x++)
- *p++=get_worker_city(pcity, x, y)+'0';
- *p='\0';
+ for(x=0; x<CITY_MAP_SIZE; x++) {
+ packet->city_map[x + y * CITY_MAP_SIZE] = get_worker_city(pcity, x, y);
+ }
p=packet->improvements;
Index: server/mapgen.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/mapgen.c,v
retrieving revision 1.132
diff -u -r1.132 mapgen.c
--- server/mapgen.c 20 Apr 2004 20:10:38 -0000 1.132
+++ server/mapgen.c 27 Apr 2004 06:18:20 -0000
@@ -580,9 +580,10 @@
for (func_num = 0; func_num < NUM_TEST_FUNCTIONS; func_num++) {
int best_val = -1;
/* first get the tile values for the function */
- for (dir = 0; dir < 4; dir++) {
- int x1 = x + CAR_DIR_DX[dir];
- int y1 = y + CAR_DIR_DY[dir];
+ adjc_dir_iterate(x, y, x1, y1, dir) {
+ if (!DIR_IS_CARDINAL(dir)) {
+ continue;
+ }
if (normalize_map_pos(&x1, &y1)
&& rd_direction_is_valid[dir]) {
rd_comparison_val[dir] = (test_funcs[func_num].func) (x1, y1);
@@ -592,22 +593,23 @@
best_val = MIN(rd_comparison_val[dir], best_val);
}
}
- }
+ } adjc_dir_iterate_end;
assert(best_val != -1);
/* should we abort? */
if (best_val > 0 && test_funcs[func_num].fatal) return FALSE;
/* mark the less attractive directions as invalid */
- for (dir = 0; dir < 4; dir++) {
- int x1 = x + CAR_DIR_DX[dir];
- int y1 = y + CAR_DIR_DY[dir];
+ adjc_dir_iterate(x, y, x1, y1, dir) {
+ if (!DIR_IS_CARDINAL(dir)) {
+ continue;
+ }
if (normalize_map_pos(&x1, &y1)
&& rd_direction_is_valid[dir]) {
if (rd_comparison_val[dir] != best_val)
rd_direction_is_valid[dir] = FALSE;
}
- }
+ } adjc_dir_iterate_end;
}
/* Directions evaluated with all functions. Now choose the best
@@ -621,16 +623,17 @@
case 0:
return FALSE; /* river aborted */
case 1:
- for (dir = 0; dir < 4; dir++) {
- int x1 = x + CAR_DIR_DX[dir];
- int y1 = y + CAR_DIR_DY[dir];
+ adjc_dir_iterate(x, y, x1, y1, dir) {
+ if (!DIR_IS_CARDINAL(dir)) {
+ continue;
+ }
if (normalize_map_pos(&x1, &y1)
&& rd_direction_is_valid[dir]) {
river_blockmark(x, y);
x = x1;
y = y1;
}
- }
+ } adjc_dir_iterate_end;
break;
default:
/* More than one possible direction; Let the random number
@@ -641,9 +644,10 @@
freelog(LOG_DEBUG, "mapgen.c: direction: %d", direction);
/* Find the direction that the random number generator selected. */
- for (dir = 0; dir < 4; dir++) {
- int x1 = x + CAR_DIR_DX[dir];
- int y1 = y + CAR_DIR_DY[dir];
+ adjc_dir_iterate(x, y, x1, y1, dir) {
+ if (!DIR_IS_CARDINAL(dir)) {
+ continue;
+ }
if (normalize_map_pos(&x1, &y1)
&& rd_direction_is_valid[dir]) {
if (direction > 0) direction--;
@@ -654,7 +658,7 @@
break;
}
}
- }
+ } adjc_dir_iterate_end;
break;
} /* end switch (rd_number_of_directions()) */
@@ -813,7 +817,7 @@
nat_set_terrain(x, 2, T_OCEAN);
/* Iso-maps need two lines of ocean. */
- if (myrand(2) != 0 || topo_has_flag(TF_ISO)) {
+ if (myrand(2) != 0 || (topo_has_flag(TF_ISO) && !topo_has_flag(TF_HEX))) {
nat_set_terrain(x, 1, T_OCEAN);
}
@@ -823,7 +827,7 @@
nat_set_terrain(x, map.ysize - 3, T_OCEAN);
- if (myrand(2) != 0 || topo_has_flag(TF_ISO)) {
+ if (myrand(2) != 0 || (topo_has_flag(TF_ISO) && topo_has_flag(TF_HEX))) {
nat_set_terrain(x, map.ysize - 2, T_OCEAN);
}
if (myrand(2) != 0) {
Index: server/settlers.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/settlers.c,v
retrieving revision 1.180
diff -u -r1.180 settlers.c
--- server/settlers.c 26 Feb 2004 03:24:16 -0000 1.180
+++ server/settlers.c 27 Apr 2004 06:18:20 -0000
@@ -551,7 +551,9 @@
if (is_wet(pplayer, x, y))
return TRUE;
+ freelog(LOG_NORMAL, "Searching wetness at %d,%d", x, y);
cartesian_adjacent_iterate(x, y, x1, y1) {
+ freelog(LOG_NORMAL, " %d,%d: %d.", x1, y1, is_wet(pplayer, x1, y1));
if (is_wet(pplayer, x1, y1))
return TRUE;
} cartesian_adjacent_iterate_end;
Index: server/srv_main.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/srv_main.c,v
retrieving revision 1.159
diff -u -r1.159 srv_main.c
--- server/srv_main.c 25 Apr 2004 19:03:40 -0000 1.159
+++ server/srv_main.c 27 Apr 2004 06:18:21 -0000
@@ -1615,7 +1615,7 @@
test_random1(200000);
#endif
- if (topo_has_flag(TF_ISO) && topo_has_flag(TF_WRAPY)
+ if ((topo_has_flag(TF_ISO) || topo_has_flag(TF_HEX)) &&
topo_has_flag(TF_WRAPY)
&& (map.ysize % 2 == 1)) {
/* To wrap north-south an iso-map must have even Y dimension. Since the
* X dimension is compressed this isn't an issue for east-west
Index: server/stdinhand.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/server/stdinhand.c,v
retrieving revision 1.315
diff -u -r1.315 stdinhand.c
--- server/stdinhand.c 24 Apr 2004 17:32:47 -0000 1.315
+++ server/stdinhand.c 27 Apr 2004 06:18:22 -0000
@@ -274,7 +274,15 @@
" 4 Flat Earth (isometric)\n"
" 5 Earth (isometric)\n"
" 6 Uranus (isometric)\n"
- " 7 Donut World (isometric)"
+ " 7 Donut World (isometric)\n"
+ " 8 Flat Earth (hexagonal)\n"
+ " 9 Earth (hexagonal)\n"
+ " 10 Uranus (hexagonal)\n"
+ " 11 Donut World (hexagonal)\n"
+ " 12 Flat Earth (iso-hex)\n"
+ " 13 Earth (iso-hex)\n"
+ " 14 Uranus (iso-hex)\n"
+ " 15 Donut World (iso-hex)"
), NULL,
MAP_MIN_TOPO, MAP_MAX_TOPO, MAP_DEFAULT_TOPO)
|
|