Freeciv-3.3
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 "road.h"
29#include "terrain.h"
30#include "unitlist.h"
31
32struct player;
33
34/* Network, order dependent */
40
41/* Convenience macro for accessing tile coordinates. This should only be
42 * used for debugging. */
43#define TILE_XY(ptile) ((ptile) ? index_to_map_pos_x(tile_index(ptile)) \
44 : -1), \
45 ((ptile) ? index_to_map_pos_y(tile_index(ptile)) \
46 : -1)
47
48#define TILE_INDEX_NONE (-1)
49
50struct tile {
51 int index; /* Index coordinate of the tile. Used to calculate (x, y) pairs
52 * (index_to_map_pos()) and (nat_x, nat_y) pairs
53 * (index_to_native_pos()). */
56 struct extra_type *resource; /* NULL for no resource */
57 struct terrain *terrain; /* NULL for unknown tiles */
58 struct unit_list *units;
59 struct city *worked; /* NULL for not worked */
60 struct player *owner; /* NULL for not owned */
64 struct tile *claimer;
66 char *label; /* NULL for no label */
68};
69
70/* 'struct tile_list' and related functions. */
71#define SPECLIST_TAG tile
72#define SPECLIST_TYPE struct tile
73#include "speclist.h"
74#define tile_list_iterate(tile_list, ptile) \
75 TYPED_LIST_ITERATE(struct tile, tile_list, ptile)
76#define tile_list_iterate_end LIST_ITERATE_END
77
78/* 'struct tile_hash' and related functions. */
79#define SPECHASH_TAG tile
80#define SPECHASH_IKEY_TYPE struct tile *
81#define SPECHASH_IDATA_TYPE void *
82#include "spechash.h"
83#define tile_hash_iterate(hash, ptile) \
84 TYPED_HASH_KEYS_ITERATE(struct tile *, hash, ptile)
85#define tile_hash_iterate_end HASH_KEYS_ITERATE_END
86
87
88/* Tile accessor functions. */
89#define tile_index(_pt_) (_pt_)->index
90
91struct city *tile_city(const struct tile *ptile);
92
93#define tile_continent(_tile) ((_tile)->continent)
94/* Continent_id tile_continent(const struct tile *ptile); */
95void tile_set_continent(struct tile *ptile, Continent_id val);
96
97#define tile_owner(_tile) ((_tile)->owner)
98/* struct player *tile_owner(const struct tile *ptile); */
99void tile_set_owner(struct tile *ptile, struct player *pplayer,
100 struct tile *claimer);
101#define tile_claimer(_tile) ((_tile)->claimer)
102
103#define tile_resource(_tile) ((_tile)->resource)
104static inline bool tile_resource_is_valid(const struct tile *ptile)
105{ return ptile->resource != NULL
106 && BV_ISSET(ptile->extras, ptile->resource->id);
107}
108/* const struct resource *tile_resource(const struct tile *ptile); */
109void tile_set_resource(struct tile *ptile, struct extra_type *presource);
110
111#define tile_terrain(_tile) ((_tile)->terrain)
112/* struct terrain *tile_terrain(const struct tile *ptile); */
113void tile_set_terrain(struct tile *ptile, struct terrain *pterrain);
114
115#define tile_worked(_tile) ((_tile)->worked)
116/* struct city *tile_worked(const struct tile *ptile); */
117void tile_set_worked(struct tile *ptile, struct city *pcity);
118
119const bv_extras *tile_extras_safe(const struct tile *ptile);
120const bv_extras *tile_extras_null(void);
121static inline const bv_extras *tile_extras(const struct tile *ptile)
122{
123 return &(ptile->extras);
124}
125
126bool tile_has_base(const struct tile *ptile, const struct base_type *pbase);
127int tile_has_not_aggressive_extra_for_unit(const struct tile *ptile,
128 const struct unit_type *punittype);
129bool tile_has_refuel_extra(const struct tile *ptile,
130 const struct unit_class *uclass);
131bool tile_has_native_base(const struct tile *ptile,
132 const struct unit_type *punittype);
133bool tile_has_claimable_base(const struct tile *ptile,
134 const struct unit_type *punittype);
135int tile_extras_defense_bonus(const struct tile *ptile,
136 const struct unit_type *punittype);
137int tile_extras_class_defense_bonus(const struct tile *ptile,
138 const struct unit_class *pclass);
139
140bool tile_has_road(const struct tile *ptile, const struct road_type *proad);
141bool tile_has_road_flag(const struct tile *ptile, enum road_flag_id flag);
142int tile_roads_output_incr(const struct tile *ptile, enum output_type_id o);
143int tile_roads_output_bonus(const struct tile *ptile, enum output_type_id o);
144bool tile_has_river(const struct tile *tile);
145
146bool tile_extra_apply(struct tile *ptile, struct extra_type *tgt);
147bool tile_extra_rm_apply(struct tile *ptile, struct extra_type *tgt);
148#define tile_has_extra(ptile, pextra) BV_ISSET(ptile->extras, extra_index(pextra))
149bool tile_has_conflicting_extra(const struct tile *ptile, const struct extra_type *pextra);
150bool tile_has_visible_extra(const struct tile *ptile, const struct extra_type *pextra);
151bool tile_has_cause_extra(const struct tile *ptile, enum extra_cause cause);
152void tile_add_extra(struct tile *ptile, const struct extra_type *pextra);
153void tile_remove_extra(struct tile *ptile, const struct extra_type *pextra);
154bool tile_has_extra_flag(const struct tile *ptile, enum extra_flag_id flag);
155
156/* Vision related */
157enum known_type tile_get_known(const struct tile *ptile,
158 const struct player *pplayer);
159
160bool tile_is_seen(const struct tile *target_tile,
161 const struct player *pow_player);
162
163/* A somewhat arbitrary integer value. Activity times are multiplied by
164 * this amount, and divided by them later before being used. This may
165 * help to avoid rounding errors; however it should probably be removed. */
166#define ACTIVITY_FACTOR 10
167int tile_activity_time(enum unit_activity activity,
168 const struct tile *ptile,
169 const struct extra_type *tgt);
170
171/* These are higher-level functions that handle side effects on the tile. */
172void tile_change_terrain(struct tile *ptile, struct terrain *pterrain);
173bool tile_apply_activity(struct tile *ptile, Activity_type_id act,
174 struct extra_type *tgt);
175
176#define TILE_LB_TERRAIN_RIVER (1 << 0)
177#define TILE_LB_RIVER_RESOURCE (1 << 1)
178#define TILE_LB_RESOURCE_POLL (1 << 2)
179const char *tile_get_info_text(const struct tile *ptile,
180 bool include_nuisances, int linebreaks);
181
182/* Virtual tiles are tiles that do not exist on the game map. */
183struct tile *tile_virtual_new(const struct tile *ptile);
184void tile_virtual_destroy(struct tile *vtile);
185
186bool tile_map_check(struct civ_map *nmap, struct tile *vtile);
187
188void *tile_hash_key(const struct tile *ptile);
189
190bool tile_set_label(struct tile *ptile, const char *label);
191
192bool tile_is_placing(const struct tile *ptile);
193
194#ifdef __cplusplus
195}
196#endif /* __cplusplus */
197
198#endif /* FC__TILE_H */
#define BV_ISSET(bv, bit)
Definition bitvector.h:86
char * incite_cost
Definition comments.c:76
struct unit struct city struct unit struct tile * target_tile
Definition dialogs_g.h:57
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit struct unit int const struct action *paction struct unit struct city * pcity
Definition dialogs_g.h:78
enum unit_activity Activity_type_id
Definition fc_types.h:238
output_type_id
Definition fc_types.h:100
signed short Continent_id
Definition fc_types.h:231
Definition city.h:317
int id
Definition extras.h:89
Definition tile.h:50
char * spec_sprite
Definition tile.h:67
char * label
Definition tile.h:66
int altitude
Definition tile.h:65
int index
Definition tile.h:51
bv_extras extras
Definition tile.h:55
struct extra_type * resource
Definition tile.h:56
struct unit_list * units
Definition tile.h:58
struct player * extras_owner
Definition tile.h:63
struct terrain * terrain
Definition tile.h:57
int infra_turns
Definition tile.h:62
struct extra_type * placing
Definition tile.h:61
struct city * worked
Definition tile.h:59
struct player * owner
Definition tile.h:60
Continent_id continent
Definition tile.h:54
struct tile * claimer
Definition tile.h:64
int tile_extras_class_defense_bonus(const struct tile *ptile, const struct unit_class *pclass)
Definition tile.c:242
void tile_add_extra(struct tile *ptile, const struct extra_type *pextra)
Definition tile.c:955
int tile_roads_output_bonus(const struct tile *ptile, enum output_type_id o)
Definition tile.c:291
bool tile_has_extra_flag(const struct tile *ptile, enum extra_flag_id flag)
Definition tile.c:886
bool tile_has_claimable_base(const struct tile *ptile, const struct unit_type *punittype)
Definition tile.c:215
void tile_set_terrain(struct tile *ptile, struct terrain *pterrain)
Definition tile.c:124
void tile_virtual_destroy(struct tile *vtile)
Definition tile.c:1035
bool tile_extra_apply(struct tile *ptile, struct extra_type *tgt)
Definition tile.c:575
bool tile_is_placing(const struct tile *ptile)
Definition tile.c:1131
const bv_extras * tile_extras_null(void)
Definition tile.c:166
bool tile_has_river(const struct tile *tile)
Definition tile.c:852
bool tile_apply_activity(struct tile *ptile, Activity_type_id act, struct extra_type *tgt)
Definition tile.c:681
bool tile_map_check(struct civ_map *nmap, struct tile *vtile)
Definition tile.c:1067
bool tile_has_base(const struct tile *ptile, const struct base_type *pbase)
Definition tile.c:836
void tile_remove_extra(struct tile *ptile, const struct extra_type *pextra)
Definition tile.c:965
void tile_change_terrain(struct tile *ptile, struct terrain *pterrain)
Definition tile.c:496
bool tile_has_visible_extra(const struct tile *ptile, const struct extra_type *pextra)
Definition tile.c:917
bool tile_has_refuel_extra(const struct tile *ptile, const struct unit_class *uclass)
Definition tile.c:309
static bool tile_resource_is_valid(const struct tile *ptile)
Definition tile.h:104
int tile_extras_defense_bonus(const struct tile *ptile, const struct unit_type *punittype)
Definition tile.c:233
bool tile_has_road(const struct tile *ptile, const struct road_type *proad)
Definition tile.c:844
bool tile_has_conflicting_extra(const struct tile *ptile, const struct extra_type *pextra)
Definition tile.c:901
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:407
int tile_activity_time(enum unit_activity activity, const struct tile *ptile, const struct extra_type *tgt)
Definition tile.c:418
struct tile * tile_virtual_new(const struct tile *ptile)
Definition tile.c:981
known_type
Definition tile.h:35
@ TILE_KNOWN_UNSEEN
Definition tile.h:37
@ TILE_UNKNOWN
Definition tile.h:36
@ TILE_KNOWN_SEEN
Definition tile.h:38
bool tile_has_native_base(const struct tile *ptile, const struct unit_type *punittype)
Definition tile.c:324
int tile_roads_output_incr(const struct tile *ptile, enum output_type_id o)
Definition tile.c:271
void * tile_hash_key(const struct tile *ptile)
Definition tile.c:1085
bool tile_extra_rm_apply(struct tile *ptile, struct extra_type *tgt)
Definition tile.c:601
bool tile_set_label(struct tile *ptile, const char *label)
Definition tile.c:1097
void tile_set_resource(struct tile *ptile, struct extra_type *presource)
Definition tile.c:349
int tile_has_not_aggressive_extra_for_unit(const struct tile *ptile, const struct unit_type *punittype)
Definition tile.c:196
enum known_type tile_get_known(const struct tile *ptile, const struct player *pplayer)
Definition tile.c:392
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:771
bool tile_has_road_flag(const struct tile *ptile, enum road_flag_id flag)
Definition tile.c:868
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:941
static const bv_extras * tile_extras(const struct tile *ptile)
Definition tile.h:121
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:382