Freeciv-3.1: /fast/freeciv/nightly/S3_1/common/improvement.h Source File

Freeciv-3.1

Loading...
Searching...
No Matches
improvement.h
Go to the documentation of this file.
1/***********************************************************************
2 Freeciv - Copyright (C) 1996 - A Kjeldberg, L Gregersen, P Unold
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#ifndef FC__IMPROVEMENT_H
14#define FC__IMPROVEMENT_H
15
16#ifdef __cplusplus
17extern "C" {
18#endif /* __cplusplus */
19
20/* City Improvements, including Wonders. (Alternatively "Buildings".) */
21
22/* utility */
23#include "bitvector.h"
24#include "support.h" /* bool */
25
26/* common */
27#include "fc_types.h"
28#include "name_translation.h"
29#include "requirements.h"
30
31struct strvec; /* Actually defined in "utility/string_vector.h". */
32
33/* B_LAST is a value that is guaranteed to be larger than all
34 * actual Impr_type_id values. It is used as a flag value; it can
35 * also be used for fixed allocations to ensure ability to hold the
36 * full number of improvement types.
37 *
38 * B_NEVER is the pointer equivalent replacement for B_LAST flag value.
39 *
40 * Used in the network protocol.
41 */
42#define B_LAST MAX_NUM_BUILDINGS
43
44#define B_NEVER (NULL)
45
46/* Changing these breaks network compatibility. */
47#define SPECENUM_NAME impr_flag_id
48/* improvement should be visible to others without spying */
49#define SPECENUM_VALUE0 IF_VISIBLE_BY_OTHERS
50#define SPECENUM_VALUE0NAME "VisibleByOthers"
51/* this small wonder is moved to another city if game.savepalace is on. */
52#define SPECENUM_VALUE1 IF_SAVE_SMALL_WONDER
53#define SPECENUM_VALUE1NAME "SaveSmallWonder"
54/* when built, gives gold */
55#define SPECENUM_VALUE2 IF_GOLD
56#define SPECENUM_VALUE2NAME "Gold"
57/* Never destroyed by disasters */
58#define SPECENUM_VALUE3 IF_DISASTER_PROOF
59#define SPECENUM_VALUE3NAME "DisasterProof"
60#define SPECENUM_COUNT IF_COUNT
61#define SPECENUM_BITVECTOR bv_impr_flags
62#include "specenum_gen.h"
63
64/* Used in the network protocol. */
65 BV_DEFINE(bv_imprs, B_LAST);
66
67/* Type of improvement. (Read from buildings.ruleset file.) */
68 struct impr_type {
69 Impr_type_id item_number;
70 struct name_translation name;
71 bool ruledit_disabled; /* Does not really exist - hole in improvements array */
72 void *ruledit_dlg;
73 char graphic_str[MAX_LEN_NAME]; /* city icon of improv. */
74 char graphic_alt[MAX_LEN_NAME]; /* city icon of improv. */
75 struct requirement_vector reqs;
76 struct requirement_vector obsolete_by;
77 int build_cost; /* Use wrappers to access this. */
78 int upkeep;
79 int sabotage; /* Base chance of diplomat sabotage succeeding. */
80 enum impr_genus_id genus; /* genus; e.g. GreatWonder */
81 bv_impr_flags flags;
82 struct strvec *helptext;
83 char soundtag[MAX_LEN_NAME];
84 char soundtag_alt[MAX_LEN_NAME];
85
86 /* Cache */
87 bool allows_units;
88 bool allows_extras;
89 bool prevents_disaster;
90 bool protects_vs_actions;
91 bool allows_actions;
92};
93
94
95/* General improvement accessor functions. */
96 Impr_type_id improvement_count(void);
97 Impr_type_id improvement_index(const struct impr_type *pimprove);
98 Impr_type_id improvement_number(const struct impr_type *pimprove);
99
100struct impr_type *improvement_by_number(const Impr_type_id id);
101
102const struct impr_type *valid_improvement(const struct impr_type *pimprove);
103const struct impr_type *valid_improvement_by_number(const Impr_type_id id);
104
105struct impr_type *improvement_by_rule_name(const char *name);
106struct impr_type *improvement_by_translated_name(const char *name);
107
108const char *improvement_rule_name(const struct impr_type *pimprove);
109const char *improvement_name_translation(const struct impr_type *pimprove);
110
111/* General improvement flag accessor routines */
112bool improvement_has_flag(const struct impr_type *pimprove,
113 enum impr_flag_id flag);
114
115/* Ancillary routines */
116int impr_build_shield_cost(const struct city *pcity,
117 const struct impr_type *pimprove);
118int impr_base_build_shield_cost(const struct impr_type *pimprove);
119int impr_estimate_build_shield_cost(const struct player *pplayer,
120 const struct tile *ptile,
121 const struct impr_type *pimprove);
122int impr_buy_gold_cost(const struct city *pcity, const struct impr_type *pimprove,
123 int shields_in_stock);
124int impr_sell_gold(const struct impr_type *pimprove);
125
126bool is_improvement_visible(const struct impr_type *pimprove);
127
128bool is_great_wonder(const struct impr_type *pimprove);
129bool is_small_wonder(const struct impr_type *pimprove);
130bool is_wonder(const struct impr_type *pimprove);
131bool is_improvement(const struct impr_type *pimprove);
132bool is_special_improvement(const struct impr_type *pimprove);
133
134bool can_improvement_go_obsolete(const struct impr_type *pimprove);
135
136bool can_sell_building(const struct impr_type *pimprove);
137bool can_city_sell_building(const struct city *pcity,
138 const struct impr_type *pimprove);
139enum test_result test_player_sell_building_now(struct player *pplayer,
140 struct city *pcity,
141 const struct impr_type *pimprove);
142
143const struct impr_type *improvement_replacement(const struct impr_type *pimprove);
144
145/* Macros for struct packet_game_info::great_wonder_owners[]. */
146#define WONDER_DESTROYED (MAX_NUM_PLAYER_SLOTS + 1) /* Used as player id. */
147#define WONDER_NOT_OWNED (MAX_NUM_PLAYER_SLOTS + 2) /* Used as player id. */
148#define WONDER_OWNED(player_id) ((player_id) < MAX_NUM_PLAYER_SLOTS)
149
150/* Macros for struct player::wonders[]. */
151#define WONDER_LOST (-1) /* Used as city id. */
152#define WONDER_NOT_BUILT 0 /* Used as city id. */
153#define WONDER_BUILT(city_id) ((city_id) > 0)
154
155void wonder_built(const struct city *pcity, const struct impr_type *pimprove);
156void wonder_destroyed(const struct city *pcity,
157 const struct impr_type *pimprove);
158
159bool wonder_is_lost(const struct player *pplayer,
160 const struct impr_type *pimprove);
161bool wonder_is_built(const struct player *pplayer,
162 const struct impr_type *pimprove);
163struct city *city_from_wonder(const struct player *pplayer,
164 const struct impr_type *pimprove);
165bool wonder_visible_to_player(const struct impr_type *wonder,
166 const struct player *pplayer,
167 const struct player *owner);
168
169bool great_wonder_is_built(const struct impr_type *pimprove);
170bool great_wonder_is_destroyed(const struct impr_type *pimprove);
171bool great_wonder_is_available(const struct impr_type *pimprove);
172struct city *city_from_great_wonder(const struct impr_type *pimprove);
173struct player *great_wonder_owner(const struct impr_type *pimprove);
174
175bool small_wonder_is_built(const struct player *pplayer,
176 const struct impr_type *pimprove);
177struct city *city_from_small_wonder(const struct player *pplayer,
178 const struct impr_type *pimprove);
179
180/* player related improvement functions */
181bool improvement_obsolete(const struct player *pplayer,
182 const struct impr_type *pimprove,
183 const struct city *pcity);
184bool is_improvement_productive(const struct city *pcity,
185 const struct impr_type *pimprove);
186bool is_improvement_redundant(const struct city *pcity,
187 const struct impr_type *pimprove);
188
189bool can_player_build_improvement_direct(const struct player *p,
190 const struct impr_type *pimprove);
191bool can_player_build_improvement_later(const struct player *p,
192 const struct impr_type *pimprove);
193bool can_player_build_improvement_now(const struct player *p,
194 struct impr_type *pimprove);
195
196/* Initialization and iteration */
197void improvements_init(void);
198void improvements_free(void);
199
200void improvement_feature_cache_init(void);
201
202struct impr_type *improvement_array_first(void);
203const struct impr_type *improvement_array_last(void);
204
205#define improvement_iterate(_p) \
206{ \
207 struct impr_type *_p = improvement_array_first(); \
208 if (NULL != _p) { \
209 for (; _p <= improvement_array_last(); _p++) {
210
211#define improvement_iterate_end \
212 } \
213 } \
214}
215
216#define improvement_re_active_iterate(_p) \
217 improvement_iterate(_p) { \
218 if (!_p->ruledit_disabled) {
219
220#define improvement_re_active_iterate_end \
221 } \
222 } improvement_iterate_end;
223
224#define genus_iterate(_p) \
225 { \
226 enum impr_genus_id _p; \
227 for (_p = (enum impr_genus_id)0; _p < IG_COUNT; \
228 _p = (enum impr_genus_id)((int)_p + 1)) {
229
230#define genus_iterate_end \
231 } \
232 }
233
234#ifdef __cplusplus
235}
236#endif /* __cplusplus */
237
238#endif /* FC__IMPROVEMENT_H */
bitvector.h
BV_DEFINE
#define BV_DEFINE(name, bits)
Definition bitvector.h:132
fc_types.h
Impr_type_id
int Impr_type_id
Definition fc_types.h:346
test_result
test_result
Definition fc_types.h:1097
MAX_LEN_NAME
#define MAX_LEN_NAME
Definition fc_types.h:66
owner
struct city * owner
Definition citydlg.c:219
valid_improvement
const struct impr_type * valid_improvement(const struct impr_type *pimprove)
Definition improvement.c:209
improvement_by_number
struct impr_type * improvement_by_number(const Impr_type_id id)
Definition improvement.c:192
can_sell_building
bool can_sell_building(const struct impr_type *pimprove)
Definition improvement.c:1064
impr_sell_gold
int impr_sell_gold(const struct impr_type *pimprove)
Definition improvement.c:332
improvements_init
void improvements_init(void)
Definition improvement.c:46
improvement_array_last
const struct impr_type * improvement_array_last(void)
Definition improvement.c:151
valid_improvement_by_number
const struct impr_type * valid_improvement_by_number(const Impr_type_id id)
Definition improvement.c:232
can_city_sell_building
bool can_city_sell_building(const struct city *pcity, const struct impr_type *pimprove)
Definition improvement.c:1072
can_player_build_improvement_direct
bool can_player_build_improvement_direct(const struct player *p, const struct impr_type *pimprove)
Definition improvement.c:659
great_wonder_is_built
bool great_wonder_is_built(const struct impr_type *pimprove)
Definition improvement.c:955
test_player_sell_building_now
enum test_result test_player_sell_building_now(struct player *pplayer, struct city *pcity, const struct impr_type *pimprove)
Definition improvement.c:1083
is_special_improvement
bool is_special_improvement(const struct impr_type *pimprove)
Definition improvement.c:792
is_improvement_redundant
bool is_improvement_redundant(const struct city *pcity, const struct impr_type *pimprove)
Definition improvement.c:636
can_player_build_improvement_later
bool can_player_build_improvement_later(const struct player *p, const struct impr_type *pimprove)
Definition improvement.c:734
wonder_built
void wonder_built(const struct city *pcity, const struct impr_type *pimprove)
Definition improvement.c:800
great_wonder_is_destroyed
bool great_wonder_is_destroyed(const struct impr_type *pimprove)
Definition improvement.c:966
wonder_is_lost
bool wonder_is_lost(const struct player *pplayer, const struct impr_type *pimprove)
Definition improvement.c:844
can_player_build_improvement_now
bool can_player_build_improvement_now(const struct player *p, struct impr_type *pimprove)
Definition improvement.c:717
is_improvement
bool is_improvement(const struct impr_type *pimprove)
Definition improvement.c:783
wonder_is_built
bool wonder_is_built(const struct player *pplayer, const struct impr_type *pimprove)
Definition improvement.c:857
impr_base_build_shield_cost
int impr_base_build_shield_cost(const struct impr_type *pimprove)
Definition improvement.c:259
improvement_number
Impr_type_id improvement_number(const struct impr_type *pimprove)
Definition improvement.c:182
small_wonder_is_built
bool small_wonder_is_built(const struct player *pplayer, const struct impr_type *pimprove)
Definition improvement.c:1037
can_improvement_go_obsolete
bool can_improvement_go_obsolete(const struct impr_type *pimprove)
Definition improvement.c:401
improvement_rule_name
const char * improvement_rule_name(const struct impr_type *pimprove)
Definition improvement.c:250
is_improvement_visible
bool is_improvement_visible(const struct impr_type *pimprove)
Definition improvement.c:391
city_from_wonder
struct city * city_from_wonder(const struct player *pplayer, const struct impr_type *pimprove)
Definition improvement.c:872
improvement_index
Impr_type_id improvement_index(const struct impr_type *pimprove)
Definition improvement.c:173
impr_buy_gold_cost
int impr_buy_gold_cost(const struct city *pcity, const struct impr_type *pimprove, int shields_in_stock)
Definition improvement.c:304
impr_build_shield_cost
int impr_build_shield_cost(const struct city *pcity, const struct impr_type *pimprove)
Definition improvement.c:292
is_wonder
bool is_wonder(const struct impr_type *pimprove)
Definition improvement.c:341
is_great_wonder
bool is_great_wonder(const struct impr_type *pimprove)
Definition improvement.c:767
improvement_obsolete
bool improvement_obsolete(const struct player *pplayer, const struct impr_type *pimprove, const struct city *pcity)
Definition improvement.c:409
improvement_by_translated_name
struct impr_type * improvement_by_translated_name(const char *name)
Definition improvement.c:350
improvement_feature_cache_init
void improvement_feature_cache_init(void)
Definition improvement.c:90
improvement_has_flag
bool improvement_has_flag(const struct impr_type *pimprove, enum impr_flag_id flag)
Definition improvement.c:381
improvement_by_rule_name
struct impr_type * improvement_by_rule_name(const char *name)
Definition improvement.c:365
city_from_small_wonder
struct city * city_from_small_wonder(const struct player *pplayer, const struct impr_type *pimprove)
Definition improvement.c:1049
wonder_destroyed
void wonder_destroyed(const struct city *pcity, const struct impr_type *pimprove)
Definition improvement.c:820
improvement_name_translation
const char * improvement_name_translation(const struct impr_type *pimprove)
Definition improvement.c:241
city_from_great_wonder
struct city * city_from_great_wonder(const struct impr_type *pimprove)
Definition improvement.c:989
improvement_count
Impr_type_id improvement_count(void)
Definition improvement.c:162
is_small_wonder
bool is_small_wonder(const struct impr_type *pimprove)
Definition improvement.c:775
B_LAST
#define B_LAST
Definition improvement.h:42
improvement_array_first
struct impr_type * improvement_array_first(void)
Definition improvement.c:140
impr_estimate_build_shield_cost
int impr_estimate_build_shield_cost(const struct player *pplayer, const struct tile *ptile, const struct impr_type *pimprove)
Definition improvement.c:271
wonder_visible_to_player
bool wonder_visible_to_player(const struct impr_type *wonder, const struct player *pplayer, const struct player *owner)
Definition improvement.c:921
improvement_replacement
const struct impr_type * improvement_replacement(const struct impr_type *pimprove)
Definition improvement.c:1109
great_wonder_owner
struct player * great_wonder_owner(const struct impr_type *pimprove)
Definition improvement.c:1021
great_wonder_is_available
bool great_wonder_is_available(const struct impr_type *pimprove)
Definition improvement.c:977
improvements_free
void improvements_free(void)
Definition improvement.c:80
is_improvement_productive
bool is_improvement_productive(const struct city *pcity, const struct impr_type *pimprove)
Definition improvement.c:615
name
const char * name
Definition inputfile.c:127
name_translation.h
requirements.h
specenum_gen.h
city
Definition city.h:309
impr_type
Definition improvement.h:68
impr_type::allows_actions
bool allows_actions
Definition improvement.h:91
impr_type::build_cost
int build_cost
Definition improvement.h:77
impr_type::graphic_str
char graphic_str[MAX_LEN_NAME]
Definition improvement.h:73
impr_type::upkeep
int upkeep
Definition improvement.h:78
impr_type::genus
enum impr_genus_id genus
Definition improvement.h:80
impr_type::graphic_alt
char graphic_alt[MAX_LEN_NAME]
Definition improvement.h:74
impr_type::ruledit_disabled
bool ruledit_disabled
Definition improvement.h:71
impr_type::protects_vs_actions
bool protects_vs_actions
Definition improvement.h:90
impr_type::obsolete_by
struct requirement_vector obsolete_by
Definition improvement.h:76
impr_type::item_number
Impr_type_id item_number
Definition improvement.h:69
impr_type::prevents_disaster
bool prevents_disaster
Definition improvement.h:89
impr_type::sabotage
int sabotage
Definition improvement.h:79
impr_type::soundtag_alt
char soundtag_alt[MAX_LEN_NAME]
Definition improvement.h:84
impr_type::reqs
struct requirement_vector reqs
Definition improvement.h:75
impr_type::allows_extras
bool allows_extras
Definition improvement.h:88
impr_type::helptext
struct strvec * helptext
Definition improvement.h:82
impr_type::allows_units
bool allows_units
Definition improvement.h:87
impr_type::name
struct name_translation name
Definition improvement.h:70
impr_type::flags
bv_impr_flags flags
Definition improvement.h:81
impr_type::soundtag
char soundtag[MAX_LEN_NAME]
Definition improvement.h:83
impr_type::ruledit_dlg
void * ruledit_dlg
Definition improvement.h:72
name_translation
Definition name_translation.h:35
player
Definition player.h:249
strvec
Definition string_vector.c:29
tile
Definition tile.h:49
support.h