[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 a patch that adds hacks to fix some of the extra bits: the
citymap and "cartesian" iterators. It is a hack; don't try playing it
except under topologies 12-15.
jason
Index: client/citydlg_common.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/citydlg_common.c,v
retrieving revision 1.30
diff -u -r1.30 citydlg_common.c
--- client/citydlg_common.c 9 Mar 2004 19:10:40 -0000 1.30
+++ client/citydlg_common.c 1 Apr 2004 22:38:56 -0000
@@ -36,7 +36,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;
}
@@ -48,7 +48,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;
}
@@ -60,6 +60,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,
@@ -67,15 +71,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.98
diff -u -r1.98 mapview_common.c
--- client/mapview_common.c 29 Mar 2004 19:17:06 -0000 1.98
+++ client/mapview_common.c 1 Apr 2004 22:38:56 -0000
@@ -741,21 +741,51 @@
void put_red_frame_tile(struct canvas *pcanvas,
int canvas_x, int canvas_y)
{
+ /* TODO: hex */
if (is_isometric) {
+ /* Top right. */
canvas_put_line(pcanvas, COLOR_STD_RED, LINE_TILE_FRAME,
- canvas_x + NORMAL_TILE_WIDTH / 2 - 1, canvas_y,
- NORMAL_TILE_WIDTH / 2, NORMAL_TILE_HEIGHT / 2 - 1);
+ canvas_x + (NORMAL_TILE_WIDTH + hex_side) / 2 - 1,
+ canvas_y,
+ (NORMAL_TILE_WIDTH - 2 * hex_side) / 2,
+ NORMAL_TILE_HEIGHT / 2 - 1);
+
+ /* Bottom right. */
canvas_put_line(pcanvas, COLOR_STD_RED, LINE_TILE_FRAME,
- canvas_x + NORMAL_TILE_WIDTH - 1,
+ canvas_x + NORMAL_TILE_WIDTH - hex_side / 2 - 1,
canvas_y + NORMAL_TILE_HEIGHT / 2 - 1,
- -NORMAL_TILE_WIDTH / 2, NORMAL_TILE_HEIGHT / 2);
+ -(NORMAL_TILE_WIDTH - 2 * hex_side) / 2,
+ NORMAL_TILE_HEIGHT / 2);
+
+ /* Bottom. */
+ if (hex_side > 0) {
+ canvas_put_line(pcanvas, COLOR_STD_RED, LINE_TILE_FRAME,
+ canvas_x + (NORMAL_TILE_WIDTH - hex_side) / 2,
+ canvas_y + NORMAL_TILE_HEIGHT - 1,
+ hex_side, 0);
+ }
+
+ /* Bottom left. */
canvas_put_line(pcanvas, COLOR_STD_RED, LINE_TILE_FRAME,
- canvas_x + NORMAL_TILE_WIDTH / 2 - 1,
+ canvas_x + (NORMAL_TILE_WIDTH - hex_side) / 2 - 1,
canvas_y + NORMAL_TILE_HEIGHT - 1,
- -(NORMAL_TILE_WIDTH / 2 - 1), -NORMAL_TILE_HEIGHT / 2);
+ -((NORMAL_TILE_WIDTH - 2 * hex_side) / 2 - 1),
+ -NORMAL_TILE_HEIGHT / 2);
+
+ /* Top left. */
canvas_put_line(pcanvas, COLOR_STD_RED, LINE_TILE_FRAME,
- canvas_x, canvas_y + NORMAL_TILE_HEIGHT / 2 - 1,
- NORMAL_TILE_WIDTH / 2 - 1, -(NORMAL_TILE_HEIGHT / 2 - 1));
+ canvas_x + hex_side / 2,
+ canvas_y + NORMAL_TILE_HEIGHT / 2 - 1,
+ (NORMAL_TILE_WIDTH - 2 * hex_side) / 2 - 1,
+ -(NORMAL_TILE_HEIGHT / 2 - 1));
+
+ /* Top. */
+ if (hex_side > 0) {
+ canvas_put_line(pcanvas, COLOR_STD_RED, LINE_TILE_FRAME,
+ canvas_x + (NORMAL_TILE_WIDTH - hex_side) / 2,
+ canvas_y,
+ hex_side, 0);
+ }
} else {
canvas_put_line(pcanvas, COLOR_STD_RED, LINE_NORMAL,
canvas_x, canvas_y, NORMAL_TILE_WIDTH - 1, 0);
@@ -1019,15 +1049,37 @@
if ((draw & D_M_L) && MAPSTEP(x1, y1, map_x, map_y, DIR8_WEST)
&& this_owner != (adjc_owner = map_get_owner(x1, y1))
&& tile_get_known(x1, y1)) {
+ int startx = canvas_x + hex_side / 2;
+ int starty = canvas_y + NORMAL_TILE_HEIGHT / 2 - 1;
+ int dx = (NORMAL_TILE_WIDTH - 2 * hex_side) / 2;
+ int dy = -NORMAL_TILE_HEIGHT / 2;
+
if (adjc_owner) {
canvas_put_line(pcanvas, player_color(adjc_owner), LINE_BORDER,
- canvas_x, canvas_y + NORMAL_TILE_HEIGHT / 2 - 1,
- NORMAL_TILE_WIDTH / 2, -NORMAL_TILE_HEIGHT / 2);
+ startx, starty, dx, dy);
}
if (this_owner) {
canvas_put_line(pcanvas, player_color(this_owner), LINE_BORDER,
- canvas_x, canvas_y + NORMAL_TILE_HEIGHT / 2 + 1,
- NORMAL_TILE_WIDTH / 2, -NORMAL_TILE_HEIGHT / 2);
+ startx, starty, dx, dy);
+ }
+ }
+
+ if (hex_side != 0
+ && (draw & D_M_LR) && MAPSTEP(x1, y1, map_x, map_y, DIR8_NORTHWEST)
+ && this_owner != (adjc_owner = map_get_owner(x1, y1))
+ && tile_get_known(x1, y1)) {
+ int startx = canvas_x + (NORMAL_TILE_WIDTH - hex_side) / 2;
+ int starty = canvas_y;
+ int dx = hex_side;
+ int dy = 0;
+
+ if (adjc_owner) {
+ canvas_put_line(pcanvas, player_color(adjc_owner), LINE_BORDER,
+ startx, starty, dx, dy);
+ }
+ if (this_owner) {
+ canvas_put_line(pcanvas, player_color(this_owner), LINE_BORDER,
+ startx, starty, dx, dy);
}
}
@@ -1035,15 +1087,18 @@
if ((draw & D_M_R) && MAPSTEP(x1, y1, map_x, map_y, DIR8_NORTH)
&& this_owner != (adjc_owner = map_get_owner(x1, y1))
&& tile_get_known(x1, y1)) {
+ int startx = canvas_x + (NORMAL_TILE_WIDTH + hex_side) / 2;
+ int starty = canvas_y - 1;
+ int dx = (NORMAL_TILE_WIDTH - 2 * hex_side) / 2;
+ int dy = NORMAL_TILE_HEIGHT / 2;
+
if (adjc_owner) {
canvas_put_line(pcanvas, player_color(adjc_owner), LINE_BORDER,
- canvas_x + NORMAL_TILE_WIDTH / 2, canvas_y - 1,
- NORMAL_TILE_WIDTH / 2, NORMAL_TILE_HEIGHT / 2);
+ startx, starty, dx, dy);
}
if (this_owner) {
canvas_put_line(pcanvas, player_color(this_owner), LINE_BORDER,
- canvas_x + NORMAL_TILE_WIDTH / 2, canvas_y + 1,
- NORMAL_TILE_WIDTH / 2, NORMAL_TILE_HEIGHT / 2);
+ startx, starty, dx, dy);
}
}
}
@@ -1467,6 +1522,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.356
diff -u -r1.356 packhand.c
--- client/packhand.c 30 Mar 2004 19:00:15 -0000 1.356
+++ client/packhand.c 1 Apr 2004 22:38:57 -0000
@@ -375,7 +375,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;
@@ -489,18 +489,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: client/tilespec.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/tilespec.c,v
retrieving revision 1.155
diff -u -r1.155 tilespec.c
--- client/tilespec.c 30 Mar 2004 19:07:31 -0000 1.155
+++ client/tilespec.c 1 Apr 2004 22:38:57 -0000
@@ -76,6 +76,7 @@
int OVERVIEW_TILE_HEIGHT = 2;
bool is_isometric;
+int hex_side;
char *city_names_font;
char *city_productions_font_name;
@@ -662,6 +663,7 @@
free(fname);
return tilespec_read_toplevel(NULL);
}
+ hex_side = secfile_lookup_int_default(file, 0, "tilespec.hex_side");
NORMAL_TILE_WIDTH = secfile_lookup_int(file, "tilespec.normal_tile_width");
NORMAL_TILE_HEIGHT = secfile_lookup_int(file, "tilespec.normal_tile_height");
Index: client/tilespec.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/tilespec.h,v
retrieving revision 1.59
diff -u -r1.59 tilespec.h
--- client/tilespec.h 30 Mar 2004 19:07:32 -0000 1.59
+++ client/tilespec.h 1 Apr 2004 22:38:57 -0000
@@ -270,6 +270,7 @@
extern int OVERVIEW_TILE_HEIGHT;
extern bool is_isometric;
+extern int hex_side;
/* name of font to use to draw city names on main map */
Index: client/gui-gtk-2.0/mapview.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/client/gui-gtk-2.0/mapview.c,v
retrieving revision 1.112
diff -u -r1.112 mapview.c
--- client/gui-gtk-2.0/mapview.c 31 Mar 2004 18:42:45 -0000 1.112
+++ client/gui-gtk-2.0/mapview.c 1 Apr 2004 22:38:58 -0000
@@ -1204,15 +1204,15 @@
/*** Map grid ***/
if (draw_map_grid && !tile_hilited) {
- /* we draw the 2 lines on top of the tile; the buttom lines will be
+ /* we draw the 3 lines on top of the tile; the buttom lines will be
drawn by the tiles underneath. */
if (draw & D_M_R) {
gdk_gc_set_foreground(thin_line_gc,
colors_standard[get_grid_color
(x, y, x, y - 1)]);
gdk_draw_line(pm, thin_line_gc,
- canvas_x + NORMAL_TILE_WIDTH / 2, canvas_y,
- canvas_x + NORMAL_TILE_WIDTH,
+ canvas_x + (NORMAL_TILE_WIDTH + hex_side) / 2, canvas_y,
+ canvas_x + NORMAL_TILE_WIDTH - hex_side / 2,
canvas_y + NORMAL_TILE_HEIGHT / 2);
}
@@ -1221,8 +1221,18 @@
colors_standard[get_grid_color
(x, y, x - 1, y)]);
gdk_draw_line(pm, thin_line_gc,
- canvas_x, canvas_y + NORMAL_TILE_HEIGHT / 2,
- canvas_x + NORMAL_TILE_WIDTH / 2, canvas_y);
+ canvas_x + hex_side / 2,
+ canvas_y + NORMAL_TILE_HEIGHT / 2,
+ canvas_x + (NORMAL_TILE_WIDTH - hex_side) / 2, canvas_y);
+ }
+
+ if (hex_side > 0 && (draw & D_M_LR)) {
+ gdk_gc_set_foreground(thin_line_gc,
+ colors_standard[get_grid_color
+ (x, y, x - 1, y - 1)]);
+ gdk_draw_line(pm, thin_line_gc,
+ canvas_x + (NORMAL_TILE_WIDTH - hex_side) / 2, canvas_y,
+ canvas_x + (NORMAL_TILE_WIDTH + hex_side) / 2, canvas_y);
}
}
Index: common/city.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/city.c,v
retrieving revision 1.205
diff -u -r1.205 city.c
--- common/city.c 22 Mar 2004 20:58:11 -0000 1.205
+++ common/city.c 1 Apr 2004 22:38:58 -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.140
diff -u -r1.140 city.h
--- common/city.h 26 Feb 2004 04:05:10 -0000 1.140
+++ common/city.h 1 Apr 2004 22:38:58 -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 1 Apr 2004 22:38:58 -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.4
diff -u -r1.4 dataio.h
--- common/dataio.h 28 Nov 2003 17:37:21 -0000 1.4
+++ common/dataio.h 1 Apr 2004 22:38:58 -0000
@@ -67,7 +67,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.163
diff -u -r1.163 map.c
--- common/map.c 26 Feb 2004 13:19:47 -0000 1.163
+++ common/map.c 1 Apr 2004 22:38:59 -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);
}
/***************************************************************
@@ -608,8 +648,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;
@@ -1508,10 +1549,10 @@
return DIR8_SOUTHWEST;
case DIR8_NORTHWEST:
return DIR8_WEST;
- default:
- assert(0);
- return -1;
}
+
+ assert(0);
+ return -1;
}
/**************************************************************************
@@ -1520,18 +1561,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.177
diff -u -r1.177 map.h
--- common/map.h 26 Feb 2004 13:19:47 -0000 1.177
+++ common/map.h 1 Apr 2004 22:38:59 -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))
@@ -468,13 +471,10 @@
/* Iterate through all tiles adjacent to a tile */
#define adjc_iterate(RI_center_x, RI_center_y, RI_x_itr, RI_y_itr) \
{ \
- square_iterate(RI_center_x, RI_center_y, 1, RI_x_itr, RI_y_itr) { \
- if (RI_x_itr == RI_center_x && RI_y_itr == RI_center_y) { \
- continue; \
- }
+ adjc_dir_iterate(RI_center_x, RI_center_y, RI_x_itr, RI_y_itr, _dir) {
#define adjc_iterate_end \
- } square_iterate_end; \
+ } adjc_dir_iterate_end; \
}
/* Iterate through all tiles adjacent to a tile. dir_itr is the
@@ -488,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; \
@@ -554,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);
@@ -566,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. */
@@ -606,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.14
diff -u -r1.14 packets.def
--- common/packets.def 30 Mar 2004 19:00:15 -0000 1.14
+++ common/packets.def 1 Apr 2004 22:38:59 -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)
@@ -407,7 +407,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.15
diff -u -r1.15 packets_gen.c
--- common/packets_gen.c 30 Mar 2004 19:00:15 -0000 1.15
+++ common/packets_gen.c 1 Apr 2004 22:39:00 -0000
@@ -4495,7 +4495,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);
@@ -4772,10 +4779,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;
@@ -4977,7 +4984,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.12
diff -u -r1.12 packets_gen.h
--- common/packets_gen.h 30 Mar 2004 19:00:16 -0000 1.12
+++ common/packets_gen.h 1 Apr 2004 22:39:00 -0000
@@ -200,7 +200,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 1 Apr 2004 22:39:01 -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.131
diff -u -r1.131 mapgen.c
--- server/mapgen.c 12 Mar 2004 05:50:48 -0000 1.131
+++ server/mapgen.c 1 Apr 2004 22:39:02 -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 1 Apr 2004 22:39:02 -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.157
diff -u -r1.157 srv_main.c
--- server/srv_main.c 26 Mar 2004 18:11:32 -0000 1.157
+++ server/srv_main.c 1 Apr 2004 22:39:02 -0000
@@ -1603,7 +1603,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.311
diff -u -r1.311 stdinhand.c
--- server/stdinhand.c 26 Mar 2004 16:45:13 -0000 1.311
+++ server/stdinhand.c 1 Apr 2004 22:39:03 -0000
@@ -249,10 +249,14 @@
N_("Two-dimensional maps can wrap at the north-south or \n"
"east-west edges, and use a cartesian or isometric \n"
"rectangular grid. See the manual for further explanation.\n"
- " 0 Flat Earth (unwrapped) 4 Flat Earth (isometric)\n"
- " 1 Earth (wraps E-W) 5 Earth (isometric)\n"
- " 2 Uranus (wraps N-S) 6 Uranus (isometric)\n"
- " 3 Donut World (wraps N-S, E-W) 7 Donut World (isometric)"
+ " 0 Flat Earth (unwrapped)\n"
+ " 4 => isometric, 8 => hexagonal; 12 => iso-hex\n"
+ " 1 Earth (wraps E-W)\n"
+ " 5 => isometric, 9 => hexagonal; 13 => iso-hex\n"
+ " 2 Uranus (wraps N-S)\n"
+ " 6 => isometric, 10 => hexagonal; 14 => iso-hex\n"
+ " 3 Donut World (wraps N-S, E-W)\n"
+ " 7 => isometric, 11 => hexagonal; 15 => iso-hex"
), NULL,
MAP_MIN_TOPO, MAP_MAX_TOPO, MAP_DEFAULT_TOPO)
- [Freeciv-Dev] Re: (PR#7481) meta-ticket for hex maps,
Jason Short <=
|
|