Freeciv-3.3: /fast/freeciv/nightly/main/common/tile.h Source File

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 */
35 enum known_type {
36 TILE_UNKNOWN = 0,
37 TILE_KNOWN_UNSEEN = 1,
38 TILE_KNOWN_SEEN = 2,
39};
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
50 struct 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()). */
54 Continent_id continent;
55 bv_extras extras;
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 */
61 struct extra_type *placing;
62 int infra_turns;
63 struct player *extras_owner;
64 struct tile *claimer;
65 int altitude;
66 char *label; /* NULL for no label */
67 char *spec_sprite;
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)
104 static 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);
121 static 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 */
base.h
bitvector.h
BV_ISSET
#define BV_ISSET(bv, bit)
Definition bitvector.h:78
incite_cost
char * incite_cost
Definition comments.c:74
target_tile
struct unit struct city struct unit struct tile * target_tile
Definition dialogs_g.h:57
extras.h
fc_types.h
Activity_type_id
enum unit_activity Activity_type_id
Definition fc_types.h:383
output_type_id
output_type_id
Definition fc_types.h:100
Continent_id
signed short Continent_id
Definition fc_types.h:376
road.h
spechash.h
speclist.h
base_type
Definition base.h:41
city
Definition city.h:320
civ_map
Definition map_types.h:71
extra_type
Definition extras.h:88
extra_type::id
int id
Definition extras.h:89
player
Definition player.h:249
road_type
Definition road.h:71
terrain
Definition terrain.h:75
tile
Definition tile.h:50
tile::spec_sprite
char * spec_sprite
Definition tile.h:67
tile::label
char * label
Definition tile.h:66
tile::altitude
int altitude
Definition tile.h:65
tile::index
int index
Definition tile.h:51
tile::extras
bv_extras extras
Definition tile.h:55
tile::resource
struct extra_type * resource
Definition tile.h:56
tile::units
struct unit_list * units
Definition tile.h:58
tile::extras_owner
struct player * extras_owner
Definition tile.h:63
tile::terrain
struct terrain * terrain
Definition tile.h:57
tile::infra_turns
int infra_turns
Definition tile.h:62
tile::placing
struct extra_type * placing
Definition tile.h:61
tile::worked
struct city * worked
Definition tile.h:59
tile::owner
struct player * owner
Definition tile.h:60
tile::continent
Continent_id continent
Definition tile.h:54
tile::claimer
struct tile * claimer
Definition tile.h:64
unit_class
Definition unittype.h:149
unit_type
Definition unittype.h:507
terrain.h
tile_extras_class_defense_bonus
int tile_extras_class_defense_bonus(const struct tile *ptile, const struct unit_class *pclass)
Definition tile.c:242
tile_add_extra
void tile_add_extra(struct tile *ptile, const struct extra_type *pextra)
Definition tile.c:955
tile_roads_output_bonus
int tile_roads_output_bonus(const struct tile *ptile, enum output_type_id o)
Definition tile.c:291
tile_has_extra_flag
bool tile_has_extra_flag(const struct tile *ptile, enum extra_flag_id flag)
Definition tile.c:886
tile_has_claimable_base
bool tile_has_claimable_base(const struct tile *ptile, const struct unit_type *punittype)
Definition tile.c:215
tile_set_terrain
void tile_set_terrain(struct tile *ptile, struct terrain *pterrain)
Definition tile.c:124
tile_virtual_destroy
void tile_virtual_destroy(struct tile *vtile)
Definition tile.c:1035
tile_extra_apply
bool tile_extra_apply(struct tile *ptile, struct extra_type *tgt)
Definition tile.c:575
tile_is_placing
bool tile_is_placing(const struct tile *ptile)
Definition tile.c:1131
tile_extras_null
const bv_extras * tile_extras_null(void)
Definition tile.c:166
tile_has_river
bool tile_has_river(const struct tile *tile)
Definition tile.c:852
tile_apply_activity
bool tile_apply_activity(struct tile *ptile, Activity_type_id act, struct extra_type *tgt)
Definition tile.c:681
tile_map_check
bool tile_map_check(struct civ_map *nmap, struct tile *vtile)
Definition tile.c:1067
tile_has_base
bool tile_has_base(const struct tile *ptile, const struct base_type *pbase)
Definition tile.c:836
tile_remove_extra
void tile_remove_extra(struct tile *ptile, const struct extra_type *pextra)
Definition tile.c:965
tile_change_terrain
void tile_change_terrain(struct tile *ptile, struct terrain *pterrain)
Definition tile.c:496
tile_has_visible_extra
bool tile_has_visible_extra(const struct tile *ptile, const struct extra_type *pextra)
Definition tile.c:917
tile_has_refuel_extra
bool tile_has_refuel_extra(const struct tile *ptile, const struct unit_class *uclass)
Definition tile.c:309
tile_resource_is_valid
static bool tile_resource_is_valid(const struct tile *ptile)
Definition tile.h:104
tile_extras_defense_bonus
int tile_extras_defense_bonus(const struct tile *ptile, const struct unit_type *punittype)
Definition tile.c:233
tile_has_road
bool tile_has_road(const struct tile *ptile, const struct road_type *proad)
Definition tile.c:844
tile_has_conflicting_extra
bool tile_has_conflicting_extra(const struct tile *ptile, const struct extra_type *pextra)
Definition tile.c:901
tile_set_owner
void tile_set_owner(struct tile *ptile, struct player *pplayer, struct tile *claimer)
Definition tile.c:69
tile_is_seen
bool tile_is_seen(const struct tile *target_tile, const struct player *pow_player)
Definition tile.c:407
tile_activity_time
int tile_activity_time(enum unit_activity activity, const struct tile *ptile, const struct extra_type *tgt)
Definition tile.c:418
tile_virtual_new
struct tile * tile_virtual_new(const struct tile *ptile)
Definition tile.c:981
known_type
known_type
Definition tile.h:35
TILE_KNOWN_UNSEEN
@ TILE_KNOWN_UNSEEN
Definition tile.h:37
TILE_UNKNOWN
@ TILE_UNKNOWN
Definition tile.h:36
TILE_KNOWN_SEEN
@ TILE_KNOWN_SEEN
Definition tile.h:38
tile_has_native_base
bool tile_has_native_base(const struct tile *ptile, const struct unit_type *punittype)
Definition tile.c:324
tile_roads_output_incr
int tile_roads_output_incr(const struct tile *ptile, enum output_type_id o)
Definition tile.c:271
tile_hash_key
void * tile_hash_key(const struct tile *ptile)
Definition tile.c:1085
tile_extra_rm_apply
bool tile_extra_rm_apply(struct tile *ptile, struct extra_type *tgt)
Definition tile.c:601
tile_set_label
bool tile_set_label(struct tile *ptile, const char *label)
Definition tile.c:1097
tile_set_resource
void tile_set_resource(struct tile *ptile, struct extra_type *presource)
Definition tile.c:349
tile_has_not_aggressive_extra_for_unit
int tile_has_not_aggressive_extra_for_unit(const struct tile *ptile, const struct unit_type *punittype)
Definition tile.c:196
tile_get_known
enum known_type tile_get_known(const struct tile *ptile, const struct player *pplayer)
Definition tile.c:392
tile_extras_safe
const bv_extras * tile_extras_safe(const struct tile *ptile)
Definition tile.c:181
tile_get_info_text
const char * tile_get_info_text(const struct tile *ptile, bool include_nuisances, int linebreaks)
Definition tile.c:771
tile_has_road_flag
bool tile_has_road_flag(const struct tile *ptile, enum road_flag_id flag)
Definition tile.c:868
tile_city
struct city * tile_city(const struct tile *ptile)
Definition tile.c:83
tile_has_cause_extra
bool tile_has_cause_extra(const struct tile *ptile, enum extra_cause cause)
Definition tile.c:941
tile_extras
static const bv_extras * tile_extras(const struct tile *ptile)
Definition tile.h:121
tile_set_worked
void tile_set_worked(struct tile *ptile, struct city *pcity)
Definition tile.c:106
tile_set_continent
void tile_set_continent(struct tile *ptile, Continent_id val)
Definition tile.c:382
unitlist.h