[Freeciv-Dev] (PR#12879) new file tile.[ch]
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
<URL: http://bugs.freeciv.org/Ticket/Display.html?id=12879 >
This patch makes a new file tile.c and tile.h. See also PR#12774.
Only a few simple accessor functions, plus the tile structure and
specvec types, are moved. More code can be moved but I stuck to the
simple bits for now.
-jason
Index: common/Makefile.am
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/Makefile.am,v
retrieving revision 1.55
diff -u -r1.55 Makefile.am
--- common/Makefile.am 14 Mar 2005 20:26:25 -0000 1.55
+++ common/Makefile.am 23 Apr 2005 19:59:41 -0000
@@ -55,6 +55,8 @@
tech.h \
terrain.c \
terrain.h \
+ tile.c \
+ tile.h \
unit.c \
unit.h \
unittype.c \
Index: common/map.c
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/map.c,v
retrieving revision 1.217
diff -u -r1.217 map.c
--- common/map.c 23 Apr 2005 17:40:26 -0000 1.217
+++ common/map.c 23 Apr 2005 19:59:41 -0000
@@ -437,22 +437,6 @@
}
}
-/**************************************************************************
- Return the player who owns this tile (or NULL if none).
-**************************************************************************/
-struct player *tile_get_owner(const struct tile *ptile)
-{
- return ptile->owner;
-}
-
-/**************************************************************************
- Set the owner of a tile (may be NULL).
-**************************************************************************/
-void tile_set_owner(struct tile *ptile, struct player *owner)
-{
- ptile->owner = owner;
-}
-
/***************************************************************
...
***************************************************************/
@@ -1131,95 +1115,6 @@
}
/***************************************************************
-...
-***************************************************************/
-Continent_id tile_get_continent(const struct tile *ptile)
-{
- return ptile->continent;
-}
-
-/***************************************************************
-...
-***************************************************************/
-void tile_set_continent(struct tile *ptile, Continent_id val)
-{
- ptile->continent = val;
-}
-
-/***************************************************************
-...
-***************************************************************/
-Terrain_type_id tile_get_terrain(const struct tile *ptile)
-{
- return ptile->terrain;
-}
-
-/***************************************************************
-...
-***************************************************************/
-void tile_set_terrain(struct tile *ptile, Terrain_type_id ter)
-{
- ptile->terrain = ter;
-}
-
-/***************************************************************
-...
-***************************************************************/
-enum tile_special_type tile_get_special(const struct tile *ptile)
-{
- return ptile->special;
-}
-
-/***************************************************************
- Returns TRUE iff the given tile has the given special.
-***************************************************************/
-bool tile_has_special(const struct tile *ptile,
- enum tile_special_type special)
-{
- return contains_special(ptile->special, special);
-}
-
-/***************************************************************
-...
-***************************************************************/
-void tile_set_special(struct tile *ptile, enum tile_special_type spe)
-{
- ptile->special |= spe;
-}
-
-/***************************************************************
-...
-***************************************************************/
-void tile_clear_special(struct tile *ptile, enum tile_special_type spe)
-{
- ptile->special &= ~spe;
-}
-
-/***************************************************************
- Remove any specials which may exist at these map co-ordinates.
-***************************************************************/
-void tile_clear_all_specials(struct tile *ptile)
-{
- ptile->special = S_NO_SPECIAL;
-}
-
-/***************************************************************
-...
-***************************************************************/
-struct city *tile_get_city(const struct tile *ptile)
-{
- return ptile->city;
-}
-
-/***************************************************************
-...
-***************************************************************/
-void tile_set_city(struct tile *ptile, struct city *pcity)
-{
- ptile->city = pcity;
-}
-
-/***************************************************************
Are (x1,y1) and (x2,y2) really the same when adjusted?
This function might be necessary ALOT of places...
***************************************************************/
Index: common/map.h
===================================================================
RCS file: /home/freeciv/CVS/freeciv/common/map.h,v
retrieving revision 1.239
diff -u -r1.239 map.h
--- common/map.h 23 Apr 2005 17:40:27 -0000 1.239
+++ common/map.h 23 Apr 2005 19:59:41 -0000
@@ -21,6 +21,7 @@
#include "game.h"
#include "player.h"
#include "terrain.h"
+#include "tile.h"
#include "unit.h"
/*
@@ -31,38 +32,6 @@
#define MOVE_COST_FOR_VALID_SEA_STEP (-3)
#define MOVE_COST_FOR_VALID_AIR_STEP (-3)
-/* Convenience macro for accessing tile coordinates. This should only be
- * used for debugging. */
-#define TILE_XY(ptile) ((ptile) ? (ptile)->x : -1), \
- ((ptile) ? (ptile)->y : -1)
-
-struct tile {
- const int x, y; /* Cartesian (map) coordinates of the tile. */
- const int nat_x, nat_y; /* Native coordinates of the tile. */
- const int index; /* Index coordinate of the tile. */
- Terrain_type_id terrain;
- enum tile_special_type special;
- struct city *city; /* city standing on the tile, NULL if none */
- struct unit_list *units;
- unsigned int known; /* A bitvector on the server side, an
- enum known_type on the client side.
- Player_no is index */
- int assigned; /* these can save a lot of CPU usage -- Syela */
- struct city *worked; /* city working tile, or NULL if none */
- Continent_id continent;
- struct player *owner; /* Player owning this tile, or NULL. */
- char *spec_sprite;
-};
-
-/* get 'struct tile_list' and related functions: */
-#define SPECLIST_TAG tile
-#define SPECLIST_TYPE struct tile
-#include "speclist.h"
-
-#define tile_list_iterate(tile_list, ptile) \
- TYPED_LIST_ITERATE(struct tile, tile_list, ptile)
-#define tile_list_iterate_end LIST_ITERATE_END
-
/****************************************************************
miscellaneous terrain information
*****************************************************************/
@@ -164,9 +133,6 @@
int get_direction_for_step(const struct tile *src_tile,
const struct tile *dst_tile);
-void tile_set_continent(struct tile *ptile, Continent_id val);
-Continent_id tile_get_continent(const struct tile *ptile);
-
/* Number of index coordinates (for sanity checks and allocations) */
#define MAP_INDEX_SIZE (map.xsize * map.ysize)
@@ -283,17 +249,6 @@
struct tile *native_pos_to_tile(int nat_x, int nat_y);
struct tile *index_to_tile(int index);
-struct player *tile_get_owner(const struct tile *ptile);
-void tile_set_owner(struct tile *ptile, struct player *pplayer);
-struct city *tile_get_city(const struct tile *ptile);
-void tile_set_city(struct tile *ptile, struct city *pcity);
-Terrain_type_id tile_get_terrain(const struct tile *ptile);
-enum tile_special_type tile_get_special(const struct tile *ptile);
-void tile_set_terrain(struct tile *ptile, Terrain_type_id ter);
-void tile_set_special(struct tile *ptile, enum tile_special_type spe);
-void tile_clear_special(struct tile *ptile, enum tile_special_type spe);
-void tile_clear_all_specials(struct tile *ptile);
-
bool is_real_map_pos(int x, int y);
bool is_normal_map_pos(int x, int y);
@@ -301,10 +256,6 @@
enum known_type map_get_known(const struct tile *ptile,
const struct player *pplayer);
-/* special testing */
-bool tile_has_special(const struct tile *ptile,
- enum tile_special_type to_test_for);
-
bool is_singular_tile(const struct tile *ptile, int dist);
bool normalize_map_pos(int *x, int *y);
struct tile *nearest_real_tile(int x, int y);
Index: common/tile.c
===================================================================
RCS file: common/tile.c
diff -N common/tile.c
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ common/tile.c 23 Apr 2005 19:59:41 -0000
@@ -0,0 +1,140 @@
+/**********************************************************************
+ Freeciv - Copyright (C) 2005 - The Freeciv Project
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+***********************************************************************/
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <assert.h>
+
+#include "tile.h"
+
+/****************************************************************************
+ Return the player who owns this tile (or NULL if none).
+****************************************************************************/
+struct player *tile_get_owner(const struct tile *ptile)
+{
+ return ptile->owner;
+}
+
+/****************************************************************************
+ Set the owner of a tile (may be NULL).
+****************************************************************************/
+void tile_set_owner(struct tile *ptile, struct player *owner)
+{
+ ptile->owner = owner;
+}
+
+/****************************************************************************
+ Return the city on this tile (or NULL if none).
+****************************************************************************/
+struct city *tile_get_city(const struct tile *ptile)
+{
+ return ptile->city;
+}
+
+/****************************************************************************
+ Set the city on the tile (may be NULL).
+****************************************************************************/
+void tile_set_city(struct tile *ptile, struct city *pcity)
+{
+ ptile->city = pcity;
+}
+
+/****************************************************************************
+ Return the terrain ID of the tile. Terrains are defined in the ruleset
+ (see terrain.h).
+****************************************************************************/
+Terrain_type_id tile_get_terrain(const struct tile *ptile)
+{
+ return ptile->terrain;
+}
+
+/****************************************************************************
+ Set the terrain ID of the tile. See tile_get_terrain.
+****************************************************************************/
+void tile_set_terrain(struct tile *ptile, Terrain_type_id ter)
+{
+ ptile->terrain = ter;
+}
+
+/****************************************************************************
+ Return the specials of the tile. See terrain.h.
+
+ Note that this returns a mask of _all_ the specials on the tile. To
+ check a specific special use tile_has_special.
+****************************************************************************/
+enum tile_special_type tile_get_special(const struct tile *ptile)
+{
+ return ptile->special;
+}
+
+/****************************************************************************
+ Returns TRUE iff the given tile has the given special.
+****************************************************************************/
+bool tile_has_special(const struct tile *ptile,
+ enum tile_special_type special)
+{
+ return contains_special(ptile->special, special);
+}
+
+/****************************************************************************
+ Add the given special or specials to the tile.
+
+ Note that this does not erase any existing specials already on the tile
+ (see tile_clear_special or tile_clear_all_specials for that). Also note
+ the special to be set may be a mask, so you can set more than one
+ special at a time (but this is not recommended).
+****************************************************************************/
+void tile_set_special(struct tile *ptile, enum tile_special_type spe)
+{
+ ptile->special |= spe;
+}
+
+/****************************************************************************
+ Clear the given special or specials from the tile.
+
+ This function clears all the specials set in the 'spe' mask from the
+ tile's set of specials. All other specials are unaffected.
+****************************************************************************/
+void tile_clear_special(struct tile *ptile, enum tile_special_type spe)
+{
+ ptile->special &= ~spe;
+}
+
+/****************************************************************************
+ Remove any and all specials from this tile.
+****************************************************************************/
+void tile_clear_all_specials(struct tile *ptile)
+{
+ assert((int)S_NO_SPECIAL == 0);
+ ptile->special = S_NO_SPECIAL;
+}
+
+/****************************************************************************
+ Return the continent ID of the tile. Typically land has a positive
+ continent number and ocean has a negative number; no tile should have
+ a 0 continent number.
+****************************************************************************/
+Continent_id tile_get_continent(const struct tile *ptile)
+{
+ return ptile->continent;
+}
+
+/****************************************************************************
+ Set the continent ID of the tile. See tile_get_continent.
+****************************************************************************/
+void tile_set_continent(struct tile *ptile, Continent_id val)
+{
+ ptile->continent = val;
+}
Index: common/tile.h
===================================================================
RCS file: common/tile.h
diff -N common/tile.h
--- /dev/null 1 Jan 1970 00:00:00 -0000
+++ common/tile.h 23 Apr 2005 19:59:41 -0000
@@ -0,0 +1,68 @@
+/**********************************************************************
+ Freeciv - Copyright (C) 2005 - The Freeciv Project
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ This program is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU General Public License for more details.
+***********************************************************************/
+
+#ifndef FC__TILE_H
+#define FC__TILE_H
+
+#include "fc_types.h"
+#include "terrain.h"
+
+/* Convenience macro for accessing tile coordinates. This should only be
+ * used for debugging. */
+#define TILE_XY(ptile) ((ptile) ? (ptile)->x : -1), \
+ ((ptile) ? (ptile)->y : -1)
+
+struct tile {
+ const int x, y; /* Cartesian (map) coordinates of the tile. */
+ const int nat_x, nat_y; /* Native coordinates of the tile. */
+ const int index; /* Index coordinate of the tile. */
+ Terrain_type_id terrain;
+ enum tile_special_type special;
+ struct city *city; /* city standing on the tile, NULL if none */
+ struct unit_list *units;
+ unsigned int known; /* A bitvector on the server side, an
+ enum known_type on the client side.
+ Player_no is index */
+ int assigned; /* these can save a lot of CPU usage -- Syela */
+ struct city *worked; /* city working tile, or NULL if none */
+ Continent_id continent;
+ struct player *owner; /* Player owning this tile, or NULL. */
+ char *spec_sprite;
+};
+
+/* get 'struct tile_list' and related functions: */
+#define SPECLIST_TAG tile
+#define SPECLIST_TYPE struct tile
+#include "speclist.h"
+
+#define tile_list_iterate(tile_list, ptile) \
+ TYPED_LIST_ITERATE(struct tile, tile_list, ptile)
+#define tile_list_iterate_end LIST_ITERATE_END
+
+/* Tile accessor functions. */
+struct player *tile_get_owner(const struct tile *ptile);
+void tile_set_owner(struct tile *ptile, struct player *pplayer);
+struct city *tile_get_city(const struct tile *ptile);
+void tile_set_city(struct tile *ptile, struct city *pcity);
+Terrain_type_id tile_get_terrain(const struct tile *ptile);
+void tile_set_terrain(struct tile *ptile, Terrain_type_id ter);
+enum tile_special_type tile_get_special(const struct tile *ptile);
+bool tile_has_special(const struct tile *ptile,
+ enum tile_special_type to_test_for);
+void tile_set_special(struct tile *ptile, enum tile_special_type spe);
+void tile_clear_special(struct tile *ptile, enum tile_special_type spe);
+void tile_clear_all_specials(struct tile *ptile);
+void tile_set_continent(struct tile *ptile, Continent_id val);
+Continent_id tile_get_continent(const struct tile *ptile);
+
+#endif /* FC__TILE_H */
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Freeciv-Dev] (PR#12879) new file tile.[ch],
Jason Short <=
|
|