Freeciv-3.1
Loading...
Searching...
No Matches
tile.h
Go to the documentation of this file.
1/***********************************************************************
2 Freeciv - Copyright (C) 2005 - The Freeciv Project
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; either version 2, or (at your option)
6 any later version.
7
8 This program is distributed in the hope that it will be useful,
9 but WITHOUT ANY WARRANTY; without even the implied warranty of
10 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 GNU General Public License for more details.
12***********************************************************************/
13
14#ifndef FC__TILE_H
15#define FC__TILE_H
16
17#ifdef __cplusplus
18extern "C" {
19#endif /* __cplusplus */
20
21/* utility */
22#include "bitvector.h"
23
24/* common */
25#include "base.h"
26#include "extras.h"
27#include "fc_types.h"
28#include "player.h"
29#include "road.h"
30#include "terrain.h"
31#include "unitlist.h"
32
33/* network, order dependent */
39
40/* Convenience macro for accessing tile coordinates. This should only be
41 * used for debugging. */
42#define TILE_XY(ptile) ((ptile) ? index_to_map_pos_x(tile_index(ptile)) \
43 : -1), \
44 ((ptile) ? index_to_map_pos_y(tile_index(ptile)) \
45 : -1)
46
47#define TILE_INDEX_NONE (-1)
48
49struct tile {
50 int index; /* Index coordinate of the tile. Used to calculate (x, y) pairs
51 * (index_to_map_pos()) and (nat_x, nat_y) pairs
52 * (index_to_native_pos()). */
54 bv_extras extras;
55 struct extra_type *resource; /* NULL for no resource */
56 struct terrain *terrain; /* NULL for unknown tiles */
57 struct unit_list *units;
58 struct city *worked; /* NULL for not worked */
59 struct player *owner; /* NULL for not owned */
63 struct tile *claimer;
64 char *label; /* NULL for no label */
66};
67
68/* 'struct tile_list' and related functions. */
69#define SPECLIST_TAG tile
70#define SPECLIST_TYPE struct tile
71#include "speclist.h"
72#define tile_list_iterate(tile_list, ptile) \
73 TYPED_LIST_ITERATE(struct tile, tile_list, ptile)
74#define tile_list_iterate_end LIST_ITERATE_END
75
76/* 'struct tile_hash' and related functions. */
77#define SPECHASH_TAG tile
78#define SPECHASH_IKEY_TYPE struct tile *
79#define SPECHASH_IDATA_TYPE void *
80#include "spechash.h"
81#define tile_hash_iterate(hash, ptile) \
82 TYPED_HASH_KEYS_ITERATE(struct tile *, hash, ptile)
83#define tile_hash_iterate_end HASH_KEYS_ITERATE_END
84
85
86/* Tile accessor functions. */
87#define tile_index(_pt_) (_pt_)->index
88
89struct city *tile_city(const struct tile *ptile);
90
91#define tile_continent(_tile) ((_tile)->continent)
92/* Continent_id tile_continent(const struct tile *ptile); */
93void tile_set_continent(struct tile *ptile, Continent_id val);
94
95#define tile_owner(_tile) ((_tile)->owner)
96/* struct player *tile_owner(const struct tile *ptile); */
97void tile_set_owner(struct tile *ptile, struct player *pplayer,
98 struct tile *claimer);
99#define tile_claimer(_tile) ((_tile)->claimer)
100
101#define tile_resource(_tile) ((_tile)->resource)
102static inline bool tile_resource_is_valid(const struct tile *ptile)
103{ return ptile->resource != NULL
104 && BV_ISSET(ptile->extras, ptile->resource->id);
105}
106/* const struct resource *tile_resource(const struct tile *ptile); */
107void tile_set_resource(struct tile *ptile, struct extra_type *presource);
108
109#define tile_terrain(_tile) ((_tile)->terrain)
110/* struct terrain *tile_terrain(const struct tile *ptile); */
111void tile_set_terrain(struct tile *ptile, struct terrain *pterrain);
112
113#define tile_worked(_tile) ((_tile)->worked)
114/* struct city *tile_worked(const struct tile *ptile); */
115void tile_set_worked(struct tile *ptile, struct city *pcity);
116
117const bv_extras *tile_extras_safe(const struct tile *ptile);
118const bv_extras *tile_extras_null(void);
119static inline const bv_extras *tile_extras(const struct tile *ptile)
120{
121 return &(ptile->extras);
122}
123
124bool tile_has_base(const struct tile *ptile, const struct base_type *pbase);
125bool tile_has_not_aggressive_extra_for_unit(const struct tile *ptile,
126 const struct unit_type *punittype);
127bool tile_has_refuel_extra(const struct tile *ptile,
128 const struct unit_class *uclass);
129bool tile_has_native_base(const struct tile *ptile,
130 const struct unit_type *punittype);
131bool tile_has_claimable_base(const struct tile *ptile,
132 const struct unit_type *punittype);
133int tile_extras_defense_bonus(const struct tile *ptile,
134 const struct unit_type *punittype);
135int tile_extras_class_defense_bonus(const struct tile *ptile,
136 const struct unit_class *pclass);
137
138bool tile_has_road(const struct tile *ptile, const struct road_type *proad);
139bool tile_has_road_flag(const struct tile *ptile, enum road_flag_id flag);
140int tile_roads_output_incr(const struct tile *ptile, enum output_type_id o);
141int tile_roads_output_bonus(const struct tile *ptile, enum output_type_id o);
142bool tile_has_river(const struct tile *tile);
143
144bool tile_extra_apply(struct tile *ptile, struct extra_type *tgt);
145bool tile_extra_rm_apply(struct tile *ptile, struct extra_type *tgt);
146#define tile_has_extra(ptile, pextra) BV_ISSET(ptile->extras, extra_index(pextra))
147bool tile_has_conflicting_extra(const struct tile *ptile, const struct extra_type *pextra);
148bool tile_has_visible_extra(const struct tile *ptile, const struct extra_type *pextra);
149bool tile_has_cause_extra(const struct tile *ptile, enum extra_cause cause);
150void tile_add_extra(struct tile *ptile, const struct extra_type *pextra);
151void tile_remove_extra(struct tile *ptile, const struct extra_type *pextra);
152bool tile_has_extra_flag(const struct tile *ptile, enum extra_flag_id flag);;
153
154/* Vision related */
155enum known_type tile_get_known(const struct tile *ptile,
156 const struct player *pplayer);
157
158bool tile_is_seen(const struct tile *target_tile,
159 const struct player *pow_player);
160
161/* A somewhat arbitrary integer value. Activity times are multiplied by
162 * this amount, and divided by them later before being used. This may
163 * help to avoid rounding errors; however it should probably be removed. */
164#define ACTIVITY_FACTOR 10
165int tile_activity_time(enum unit_activity activity,
166 const struct tile *ptile,
167 const struct extra_type *tgt);
168
169/* These are higher-level functions that handle side effects on the tile. */
170void tile_change_terrain(struct tile *ptile, struct terrain *pterrain);
171bool tile_apply_activity(struct tile *ptile, Activity_type_id act,
172 struct extra_type *tgt);
173
174#define TILE_LB_TERRAIN_RIVER (1 << 0)
175#define TILE_LB_RIVER_RESOURCE (1 << 1)
176#define TILE_LB_RESOURCE_POLL (1 << 2)
177const char *tile_get_info_text(const struct tile *ptile,
178 bool include_nuisances, int linebreaks);
179
180/* Virtual tiles are tiles that do not exist on the game map. */
181struct tile *tile_virtual_new(const struct tile *ptile);
182void tile_virtual_destroy(struct tile *vtile);
183
184bool tile_map_check(struct civ_map *nmap, struct tile *vtile);
185
186void *tile_hash_key(const struct tile *ptile);
187
188bool tile_set_label(struct tile *ptile, const char *label);
189
190bool tile_is_placing(const struct tile *ptile);
191
192#ifdef __cplusplus
193}
194#endif /* __cplusplus */
195
196#endif /* FC__TILE_H */
#define BV_ISSET(bv, bit)
Definition bitvector.h:78
struct unit struct city struct unit struct tile * target_tile
Definition dialogs_g.h:56
enum unit_activity Activity_type_id
Definition fc_types.h:349
output_type_id
Definition fc_types.h:90
signed short Continent_id
Definition fc_types.h:342
Definition city.h:309
int id
Definition extras.h:86
Definition tile.h:49
char * spec_sprite
Definition tile.h:65
char * label
Definition tile.h:64
int index
Definition tile.h:50
bv_extras extras
Definition tile.h:54
struct extra_type * resource
Definition tile.h:55
struct unit_list * units
Definition tile.h:57
struct player * extras_owner
Definition tile.h:62
struct terrain * terrain
Definition tile.h:56
int infra_turns
Definition tile.h:61
struct extra_type * placing
Definition tile.h:60
struct city * worked
Definition tile.h:58
struct player * owner
Definition tile.h:59
Continent_id continent
Definition tile.h:53
struct tile * claimer
Definition tile.h:63
int tile_extras_class_defense_bonus(const struct tile *ptile, const struct unit_class *pclass)
Definition tile.c:236
void tile_add_extra(struct tile *ptile, const struct extra_type *pextra)
Definition tile.c:940
int tile_roads_output_bonus(const struct tile *ptile, enum output_type_id o)
Definition tile.c:285
bool tile_has_extra_flag(const struct tile *ptile, enum extra_flag_id flag)
Definition tile.c:871
bool tile_has_not_aggressive_extra_for_unit(const struct tile *ptile, const struct unit_type *punittype)
Definition tile.c:193
bool tile_has_claimable_base(const struct tile *ptile, const struct unit_type *punittype)
Definition tile.c:209
void tile_set_terrain(struct tile *ptile, struct terrain *pterrain)
Definition tile.c:124
void tile_virtual_destroy(struct tile *vtile)
Definition tile.c:1018
bool tile_extra_apply(struct tile *ptile, struct extra_type *tgt)
Definition tile.c:552
bool tile_is_placing(const struct tile *ptile)
Definition tile.c:1114
const bv_extras * tile_extras_null(void)
Definition tile.c:166
bool tile_has_river(const struct tile *tile)
Definition tile.c:837
bool tile_apply_activity(struct tile *ptile, Activity_type_id act, struct extra_type *tgt)
Definition tile.c:658
bool tile_map_check(struct civ_map *nmap, struct tile *vtile)
Definition tile.c:1050
bool tile_has_base(const struct tile *ptile, const struct base_type *pbase)
Definition tile.c:821
void tile_remove_extra(struct tile *ptile, const struct extra_type *pextra)
Definition tile.c:950
void tile_change_terrain(struct tile *ptile, struct terrain *pterrain)
Definition tile.c:473
bool tile_has_visible_extra(const struct tile *ptile, const struct extra_type *pextra)
Definition tile.c:902
bool tile_has_refuel_extra(const struct tile *ptile, const struct unit_class *uclass)
Definition tile.c:303
static bool tile_resource_is_valid(const struct tile *ptile)
Definition tile.h:102
int tile_extras_defense_bonus(const struct tile *ptile, const struct unit_type *punittype)
Definition tile.c:227
bool tile_has_road(const struct tile *ptile, const struct road_type *proad)
Definition tile.c:829
bool tile_has_conflicting_extra(const struct tile *ptile, const struct extra_type *pextra)
Definition tile.c:886
void tile_set_owner(struct tile *ptile, struct player *pplayer, struct tile *claimer)
Definition tile.c:69
bool tile_is_seen(const struct tile *target_tile, const struct player *pow_player)
Definition tile.c:401
int tile_activity_time(enum unit_activity activity, const struct tile *ptile, const struct extra_type *tgt)
Definition tile.c:412
struct tile * tile_virtual_new(const struct tile *ptile)
Definition tile.c:966
known_type
Definition tile.h:34
@ TILE_KNOWN_UNSEEN
Definition tile.h:36
@ TILE_UNKNOWN
Definition tile.h:35
@ TILE_KNOWN_SEEN
Definition tile.h:37
bool tile_has_native_base(const struct tile *ptile, const struct unit_type *punittype)
Definition tile.c:318
int tile_roads_output_incr(const struct tile *ptile, enum output_type_id o)
Definition tile.c:265
void * tile_hash_key(const struct tile *ptile)
Definition tile.c:1068
bool tile_extra_rm_apply(struct tile *ptile, struct extra_type *tgt)
Definition tile.c:578
bool tile_set_label(struct tile *ptile, const char *label)
Definition tile.c:1080
void tile_set_resource(struct tile *ptile, struct extra_type *presource)
Definition tile.c:343
enum known_type tile_get_known(const struct tile *ptile, const struct player *pplayer)
Definition tile.c:386
const bv_extras * tile_extras_safe(const struct tile *ptile)
Definition tile.c:181
const char * tile_get_info_text(const struct tile *ptile, bool include_nuisances, int linebreaks)
Definition tile.c:756
bool tile_has_road_flag(const struct tile *ptile, enum road_flag_id flag)
Definition tile.c:853
struct city * tile_city(const struct tile *ptile)
Definition tile.c:83
bool tile_has_cause_extra(const struct tile *ptile, enum extra_cause cause)
Definition tile.c:926
static const bv_extras * tile_extras(const struct tile *ptile)
Definition tile.h:119
void tile_set_worked(struct tile *ptile, struct city *pcity)
Definition tile.c:106
void tile_set_continent(struct tile *ptile, Continent_id val)
Definition tile.c:376