Freeciv-3.2
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;
65 char *label; /* NULL for no label */
67};
68
69/* 'struct tile_list' and related functions. */
70#define SPECLIST_TAG tile
71#define SPECLIST_TYPE struct tile
72#include "speclist.h"
73#define tile_list_iterate(tile_list, ptile) \
74 TYPED_LIST_ITERATE(struct tile, tile_list, ptile)
75#define tile_list_iterate_end LIST_ITERATE_END
76
77/* 'struct tile_hash' and related functions. */
78#define SPECHASH_TAG tile
79#define SPECHASH_IKEY_TYPE struct tile *
80#define SPECHASH_IDATA_TYPE void *
81#include "spechash.h"
82#define tile_hash_iterate(hash, ptile) \
83 TYPED_HASH_KEYS_ITERATE(struct tile *, hash, ptile)
84#define tile_hash_iterate_end HASH_KEYS_ITERATE_END
85
86
87/* Tile accessor functions. */
88#define tile_index(_pt_) (_pt_)->index
89
90struct city *tile_city(const struct tile *ptile);
91
92#define tile_continent(_tile) ((_tile)->continent)
93/* Continent_id tile_continent(const struct tile *ptile); */
94void tile_set_continent(struct tile *ptile, Continent_id val);
95
96#define tile_owner(_tile) ((_tile)->owner)
97/* struct player *tile_owner(const struct tile *ptile); */
98void tile_set_owner(struct tile *ptile, struct player *pplayer,
99 struct tile *claimer);
100#define tile_claimer(_tile) ((_tile)->claimer)
101
102#define tile_resource(_tile) ((_tile)->resource)
103static inline bool tile_resource_is_valid(const struct tile *ptile)
104{ return ptile->resource != NULL
105 && BV_ISSET(ptile->extras, ptile->resource->id);
106}
107/* const struct resource *tile_resource(const struct tile *ptile); */
108void tile_set_resource(struct tile *ptile, struct extra_type *presource);
109
110#define tile_terrain(_tile) ((_tile)->terrain)
111/* struct terrain *tile_terrain(const struct tile *ptile); */
112void tile_set_terrain(struct tile *ptile, struct terrain *pterrain);
113
114#define tile_worked(_tile) ((_tile)->worked)
115/* struct city *tile_worked(const struct tile *ptile); */
116void tile_set_worked(struct tile *ptile, struct city *pcity);
117
118const bv_extras *tile_extras_safe(const struct tile *ptile);
119const bv_extras *tile_extras_null(void);
120static inline const bv_extras *tile_extras(const struct tile *ptile)
121{
122 return &(ptile->extras);
123}
124
125bool tile_has_base(const struct tile *ptile, const struct base_type *pbase);
126int tile_has_not_aggressive_extra_for_unit(const struct tile *ptile,
127 const struct unit_type *punittype);
128bool tile_has_refuel_extra(const struct tile *ptile,
129 const struct unit_class *uclass);
130bool tile_has_native_base(const struct tile *ptile,
131 const struct unit_type *punittype);
132bool tile_has_claimable_base(const struct tile *ptile,
133 const struct unit_type *punittype);
134int tile_extras_defense_bonus(const struct tile *ptile,
135 const struct unit_type *punittype);
136int tile_extras_class_defense_bonus(const struct tile *ptile,
137 const struct unit_class *pclass);
138
139bool tile_has_road(const struct tile *ptile, const struct road_type *proad);
140bool tile_has_road_flag(const struct tile *ptile, enum road_flag_id flag);
141int tile_roads_output_incr(const struct tile *ptile, enum output_type_id o);
142int tile_roads_output_bonus(const struct tile *ptile, enum output_type_id o);
143bool tile_has_river(const struct tile *tile);
144
145bool tile_extra_apply(struct tile *ptile, struct extra_type *tgt);
146bool tile_extra_rm_apply(struct tile *ptile, struct extra_type *tgt);
147#define tile_has_extra(ptile, pextra) BV_ISSET(ptile->extras, extra_index(pextra))
148bool tile_has_conflicting_extra(const struct tile *ptile, const struct extra_type *pextra);
149bool tile_has_visible_extra(const struct tile *ptile, const struct extra_type *pextra);
150bool tile_has_cause_extra(const struct tile *ptile, enum extra_cause cause);
151void tile_add_extra(struct tile *ptile, const struct extra_type *pextra);
152void tile_remove_extra(struct tile *ptile, const struct extra_type *pextra);
153bool tile_has_extra_flag(const struct tile *ptile, enum extra_flag_id flag);;
154
155/* Vision related */
156enum known_type tile_get_known(const struct tile *ptile,
157 const struct player *pplayer);
158
159bool tile_is_seen(const struct tile *target_tile,
160 const struct player *pow_player);
161
162/* A somewhat arbitrary integer value. Activity times are multiplied by
163 * this amount, and divided by them later before being used. This may
164 * help to avoid rounding errors; however it should probably be removed. */
165#define ACTIVITY_FACTOR 10
166int tile_activity_time(enum unit_activity activity,
167 const struct tile *ptile,
168 const struct extra_type *tgt);
169
170/* These are higher-level functions that handle side effects on the tile. */
171void tile_change_terrain(struct tile *ptile, struct terrain *pterrain);
172bool tile_apply_activity(struct tile *ptile, Activity_type_id act,
173 struct extra_type *tgt);
174
175#define TILE_LB_TERRAIN_RIVER (1 << 0)
176#define TILE_LB_RIVER_RESOURCE (1 << 1)
177#define TILE_LB_RESOURCE_POLL (1 << 2)
178const char *tile_get_info_text(const struct tile *ptile,
179 bool include_nuisances, int linebreaks);
180
181/* Virtual tiles are tiles that do not exist on the game map. */
182struct tile *tile_virtual_new(const struct tile *ptile);
183void tile_virtual_destroy(struct tile *vtile);
184
185bool tile_map_check(struct civ_map *nmap, struct tile *vtile);
186
187void *tile_hash_key(const struct tile *ptile);
188
189bool tile_set_label(struct tile *ptile, const char *label);
190
191bool tile_is_placing(const struct tile *ptile);
192
193#ifdef __cplusplus
194}
195#endif /* __cplusplus */
196
197#endif /* FC__TILE_H */
#define BV_ISSET(bv, bit)
Definition bitvector.h:78
char * incite_cost
Definition comments.c:75
struct unit struct city struct unit struct tile * target_tile
Definition dialogs_g.h:57
enum unit_activity Activity_type_id
Definition fc_types.h:379
output_type_id
Definition fc_types.h:100
signed short Continent_id
Definition fc_types.h:372
Definition city.h:320
int id
Definition extras.h:89
Definition tile.h:50
char * spec_sprite
Definition tile.h:66
char * label
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:1033
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:1129
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:1065
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:103
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:1083
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:1095
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:120
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