<URL: http://bugs.freeciv.org/Ticket/Display.html?id=40567 >
Some tile helper functions that I needed to add for cleaner
virtual tile manipulation:
void tile_set_specials(struct tile *ptile, bv_special specials);
bv_bases tile_bases(const struct tile *ptile);
void tile_set_bases(struct tile *ptile, bv_bases bases);
bool tile_has_any_bases(const struct tile *ptile);
-----------------------------------------------------------------------
冬の夜に遠くのどこかで犬が吠えている。冷たいの?
diff --git a/common/tile.c b/common/tile.c
index cad4c4c..9fcba9d 100644
--- a/common/tile.c
+++ b/common/tile.c
@@ -119,6 +119,17 @@ bv_special tile_specials(const struct tile *ptile)
}
/****************************************************************************
+ Sets the tile's specials to those present in the given bit vector.
+****************************************************************************/
+void tile_set_specials(struct tile *ptile, bv_special specials)
+{
+ if (!ptile) {
+ return;
+ }
+ ptile->special = specials;
+}
+
+/****************************************************************************
Returns TRUE iff the given tile has the given special.
****************************************************************************/
bool tile_has_special(const struct tile *ptile,
@@ -136,6 +147,30 @@ bool tile_has_any_specials(const struct tile *ptile)
}
/****************************************************************************
+ Returns a bit vector of the bases present at the tile.
+****************************************************************************/
+bv_bases tile_bases(const struct tile *ptile)
+{
+ if (!ptile) {
+ bv_bases empty;
+ BV_CLR_ALL(empty);
+ return empty;
+ }
+ return ptile->bases;
+}
+
+/****************************************************************************
+ Set the bases on the tile to those present in the given bit vector.
+****************************************************************************/
+void tile_set_bases(struct tile *ptile, bv_bases bases)
+{
+ if (!ptile) {
+ return;
+ }
+ ptile->bases = bases;
+}
+
+/****************************************************************************
Adds base to tile.
FIXME: Should remove conflicting old base and return bool indicating that.
****************************************************************************/
@@ -666,6 +701,17 @@ bool tile_has_base(const struct tile *ptile, const struct base_type *pbase)
}
/****************************************************************************
+ Returns TRUE if the given tile has any bases on it.
+****************************************************************************/
+bool tile_has_any_bases(const struct tile *ptile)
+{
+ if (!ptile) {
+ return FALSE;
+ }
+ return BV_ISSET_ANY(ptile->bases);
+}
+
+/****************************************************************************
Returns a completely blank virtual tile (except for the unit list
vtile->units, which is created for you). Be sure to call virtual_tile_free
on it when it is no longer needed.
diff --git a/common/tile.h b/common/tile.h
index 93e7a5d..d3dc291 100644
--- a/common/tile.h
+++ b/common/tile.h
@@ -88,6 +88,7 @@ void tile_set_worked(struct tile *ptile, struct city *pcity);
/* Specials are a bit different */
bv_special tile_specials(const struct tile *ptile);
+void tile_set_specials(struct tile *ptile, bv_special specials);
bool tile_has_special(const struct tile *ptile,
enum tile_special_type to_test_for);
bool tile_has_any_specials(const struct tile *ptile);
@@ -95,7 +96,10 @@ 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);
+bv_bases tile_bases(const struct tile *ptile);
+void tile_set_bases(struct tile *ptile, bv_bases bases);
bool tile_has_base(const struct tile *ptile, const struct base_type *pbase);
+bool tile_has_any_bases(const struct tile *ptile);
void tile_add_base(struct tile *ptile, const struct base_type *pbase);
void tile_remove_base(struct tile *ptile, const struct base_type *pbase);
bool tile_has_base_flag(const struct tile *ptile, enum base_flag_id flag);
_______________________________________________
Freeciv-dev mailing list
[email protected]
https://mail.gna.org/listinfo/freeciv-dev