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

Freeciv-3.3

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/* Used in the network protocol. */
47 BV_DEFINE(bv_imprs, B_LAST);
48
49/* Type of improvement. (Read from buildings.ruleset file.) */
50 struct impr_type {
51 Impr_type_id item_number;
52 struct name_translation name;
53 bool ruledit_disabled; /* Doesn't really exist - hole in improvements array */
54 void *ruledit_dlg;
55 char graphic_str[MAX_LEN_NAME]; /* City icon of improv. */
56 char graphic_alt[MAX_LEN_NAME]; /* City icon of improv. */
57 char graphic_alt2[MAX_LEN_NAME]; /* City icon of improv. */
58 struct requirement_vector reqs;
59 struct requirement_vector obsolete_by;
60 int build_cost; /* Use wrappers to access this. */
61 int upkeep;
62 int sabotage; /* Base chance of diplomat sabotage succeeding. */
63 enum impr_genus_id genus; /* Genus; e.g. GreatWonder */
64 bv_impr_flags flags;
65 struct strvec *helptext;
66 char soundtag[MAX_LEN_NAME];
67 char soundtag_alt[MAX_LEN_NAME];
68 char soundtag_alt2[MAX_LEN_NAME];
69
70 /* Cache */
71 bool allows_units;
72 bool allows_extras;
73 bool prevents_disaster;
74 bool protects_vs_actions;
75 bool allows_actions;
76};
77
78
79/* General improvement accessor functions. */
80 Impr_type_id improvement_count(void);
81 Impr_type_id improvement_index(const struct impr_type *pimprove);
82 Impr_type_id improvement_number(const struct impr_type *pimprove);
83
84struct impr_type *improvement_by_number(const Impr_type_id id);
85
86const struct impr_type *valid_improvement(const struct impr_type *pimprove);
87const struct impr_type *valid_improvement_by_number(const Impr_type_id id);
88
89struct impr_type *improvement_by_rule_name(const char *name);
90struct impr_type *improvement_by_translated_name(const char *name);
91
92const char *improvement_rule_name(const struct impr_type *pimprove);
93const char *improvement_name_translation(const struct impr_type *pimprove);
94
95/* General improvement flag accessor routines */
96bool improvement_has_flag(const struct impr_type *pimprove,
97 enum impr_flag_id flag);
98
99void user_impr_flags_init(void);
100void impr_flags_free(void);
101void set_user_impr_flag_name(enum impr_flag_id id,
102 const char *name,
103 const char *helptxt);
104const char *impr_flag_helptxt(enum impr_flag_id id);
105
106/* Ancillary routines */
107int impr_build_shield_cost(const struct city *pcity,
108 const struct impr_type *pimprove);
109int impr_base_build_shield_cost(const struct impr_type *pimprove);
110int impr_estimate_build_shield_cost(const struct player *pplayer,
111 const struct tile *ptile,
112 const struct impr_type *pimprove);
113int impr_buy_gold_cost(const struct city *pcity, const struct impr_type *pimprove,
114 int shields_in_stock);
115int impr_sell_gold(const struct impr_type *pimprove);
116
117bool is_improvement_visible(const struct impr_type *pimprove);
118
119bool is_great_wonder(const struct impr_type *pimprove);
120bool is_small_wonder(const struct impr_type *pimprove);
121bool is_wonder(const struct impr_type *pimprove);
122bool is_improvement(const struct impr_type *pimprove);
123bool is_special_improvement(const struct impr_type *pimprove);
124bool is_convert_improvement(const struct impr_type *pimprove);
125
126bool can_improvement_go_obsolete(const struct impr_type *pimprove);
127
128bool can_sell_building(const struct impr_type *pimprove);
129bool can_city_sell_building(const struct city *pcity,
130 const struct impr_type *pimprove);
131bool is_building_sellable(const struct impr_type *pimprove);
132enum test_result test_player_sell_building_now(struct player *pplayer,
133 struct city *pcity,
134 const struct impr_type *pimprove);
135
136const struct impr_type *improvement_replacement(const struct impr_type *pimprove);
137
138/* Macros for struct packet_game_info::great_wonder_owners[]. */
139#define WONDER_DESTROYED (MAX_NUM_PLAYER_SLOTS + 1) /* Used as player id. */
140#define WONDER_NOT_OWNED (MAX_NUM_PLAYER_SLOTS + 2) /* Used as player id. */
141#define WONDER_OWNED(player_id) ((player_id) < MAX_NUM_PLAYER_SLOTS)
142
143/* Macros for struct player::wonders[]. */
144#define WONDER_LOST (-1) /* Used as city id. */
145#define WONDER_NOT_BUILT 0 /* Used as city id. */
146#define WONDER_BUILT(city_id) ((city_id) > 0)
147
148void wonder_built(const struct city *pcity, const struct impr_type *pimprove);
149void wonder_destroyed(const struct city *pcity,
150 const struct impr_type *pimprove);
151
152bool wonder_is_lost(const struct player *pplayer,
153 const struct impr_type *pimprove);
154bool wonder_is_built(const struct player *pplayer,
155 const struct impr_type *pimprove);
156struct city *city_from_wonder(const struct player *pplayer,
157 const struct impr_type *pimprove);
158bool wonder_visible_to_player(const struct impr_type *wonder,
159 const struct player *pplayer,
160 const struct player *owner,
161 enum fc_tristate embassy);
162
163bool great_wonder_is_built(const struct impr_type *pimprove);
164bool great_wonder_is_destroyed(const struct impr_type *pimprove);
165bool great_wonder_is_available(const struct impr_type *pimprove);
166struct city *city_from_great_wonder(const struct impr_type *pimprove);
167struct player *great_wonder_owner(const struct impr_type *pimprove);
168
169bool small_wonder_is_built(const struct player *pplayer,
170 const struct impr_type *pimprove);
171struct city *city_from_small_wonder(const struct player *pplayer,
172 const struct impr_type *pimprove);
173
174/* player related improvement functions */
175bool improvement_obsolete(const struct player *pplayer,
176 const struct impr_type *pimprove,
177 const struct city *pcity);
178bool is_improvement_productive(const struct city *pcity,
179 const struct impr_type *pimprove);
180bool is_improvement_redundant(const struct city *pcity,
181 const struct impr_type *pimprove);
182
183bool can_player_build_improvement_direct(const struct player *p,
184 const struct impr_type *pimprove);
185bool can_player_build_improvement_later(const struct player *p,
186 const struct impr_type *pimprove);
187bool can_player_build_improvement_now(const struct player *p,
188 struct impr_type *pimprove);
189
190/* Initialization and iteration */
191void improvements_init(void);
192void improvements_free(void);
193
194void improvement_feature_cache_init(void);
195
196struct impr_type *improvement_array_first(void);
197const struct impr_type *improvement_array_last(void);
198
199#define improvement_iterate(_p) \
200{ \
201 struct impr_type *_p = improvement_array_first(); \
202 if (NULL != _p) { \
203 for (; _p <= improvement_array_last(); _p++) {
204
205#define improvement_iterate_end \
206 } \
207 } \
208}
209
210#define improvement_re_active_iterate(_p) \
211 improvement_iterate(_p) { \
212 if (!_p->ruledit_disabled) {
213
214#define improvement_re_active_iterate_end \
215 } \
216 } improvement_iterate_end;
217
218#define genus_iterate(_p) \
219 { \
220 enum impr_genus_id _p; \
221 for (_p = (enum impr_genus_id)0; _p < IG_COUNT; \
222 _p = (enum impr_genus_id)((int)_p + 1)) {
223
224#define genus_iterate_end \
225 } \
226 }
227
228#ifdef __cplusplus
229}
230#endif /* __cplusplus */
231
232#endif /* FC__IMPROVEMENT_H */
bitvector.h
BV_DEFINE
#define BV_DEFINE(name, bits)
Definition bitvector.h:132
incite_cost
char * incite_cost
Definition comments.c:74
fc_types.h
Impr_type_id
int Impr_type_id
Definition fc_types.h:380
test_result
test_result
Definition fc_types.h:1255
MAX_LEN_NAME
#define MAX_LEN_NAME
Definition fc_types.h:66
owner
struct city * owner
Definition citydlg.c:220
valid_improvement
const struct impr_type * valid_improvement(const struct impr_type *pimprove)
Definition improvement.c:211
improvement_by_number
struct impr_type * improvement_by_number(const Impr_type_id id)
Definition improvement.c:194
can_sell_building
bool can_sell_building(const struct impr_type *pimprove)
Definition improvement.c:1091
impr_sell_gold
int impr_sell_gold(const struct impr_type *pimprove)
Definition improvement.c:334
improvements_init
void improvements_init(void)
Definition improvement.c:48
is_building_sellable
bool is_building_sellable(const struct impr_type *pimprove)
Definition improvement.c:1110
improvement_array_last
const struct impr_type * improvement_array_last(void)
Definition improvement.c:153
valid_improvement_by_number
const struct impr_type * valid_improvement_by_number(const Impr_type_id id)
Definition improvement.c:234
can_city_sell_building
bool can_city_sell_building(const struct city *pcity, const struct impr_type *pimprove)
Definition improvement.c:1100
can_player_build_improvement_direct
bool can_player_build_improvement_direct(const struct player *p, const struct impr_type *pimprove)
Definition improvement.c:664
great_wonder_is_built
bool great_wonder_is_built(const struct impr_type *pimprove)
Definition improvement.c:982
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:1120
user_impr_flags_init
void user_impr_flags_init(void)
Definition improvement.c:1160
is_special_improvement
bool is_special_improvement(const struct impr_type *pimprove)
Definition improvement.c:797
is_improvement_redundant
bool is_improvement_redundant(const struct city *pcity, const struct impr_type *pimprove)
Definition improvement.c:641
can_player_build_improvement_later
bool can_player_build_improvement_later(const struct player *p, const struct impr_type *pimprove)
Definition improvement.c:739
wonder_built
void wonder_built(const struct city *pcity, const struct impr_type *pimprove)
Definition improvement.c:819
great_wonder_is_destroyed
bool great_wonder_is_destroyed(const struct impr_type *pimprove)
Definition improvement.c:993
wonder_is_lost
bool wonder_is_lost(const struct player *pplayer, const struct impr_type *pimprove)
Definition improvement.c:863
can_player_build_improvement_now
bool can_player_build_improvement_now(const struct player *p, struct impr_type *pimprove)
Definition improvement.c:722
is_improvement
bool is_improvement(const struct impr_type *pimprove)
Definition improvement.c:788
wonder_is_built
bool wonder_is_built(const struct player *pplayer, const struct impr_type *pimprove)
Definition improvement.c:876
impr_base_build_shield_cost
int impr_base_build_shield_cost(const struct impr_type *pimprove)
Definition improvement.c:261
improvement_number
Impr_type_id improvement_number(const struct impr_type *pimprove)
Definition improvement.c:184
small_wonder_is_built
bool small_wonder_is_built(const struct player *pplayer, const struct impr_type *pimprove)
Definition improvement.c:1064
can_improvement_go_obsolete
bool can_improvement_go_obsolete(const struct impr_type *pimprove)
Definition improvement.c:403
improvement_rule_name
const char * improvement_rule_name(const struct impr_type *pimprove)
Definition improvement.c:252
is_improvement_visible
bool is_improvement_visible(const struct impr_type *pimprove)
Definition improvement.c:393
city_from_wonder
struct city * city_from_wonder(const struct player *pplayer, const struct impr_type *pimprove)
Definition improvement.c:891
improvement_index
Impr_type_id improvement_index(const struct impr_type *pimprove)
Definition improvement.c:175
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:306
impr_build_shield_cost
int impr_build_shield_cost(const struct city *pcity, const struct impr_type *pimprove)
Definition improvement.c:294
is_wonder
bool is_wonder(const struct impr_type *pimprove)
Definition improvement.c:343
is_great_wonder
bool is_great_wonder(const struct impr_type *pimprove)
Definition improvement.c:772
improvement_obsolete
bool improvement_obsolete(const struct player *pplayer, const struct impr_type *pimprove, const struct city *pcity)
Definition improvement.c:411
improvement_by_translated_name
struct impr_type * improvement_by_translated_name(const char *name)
Definition improvement.c:352
improvement_feature_cache_init
void improvement_feature_cache_init(void)
Definition improvement.c:92
improvement_has_flag
bool improvement_has_flag(const struct impr_type *pimprove, enum impr_flag_id flag)
Definition improvement.c:383
improvement_by_rule_name
struct impr_type * improvement_by_rule_name(const char *name)
Definition improvement.c:367
city_from_small_wonder
struct city * city_from_small_wonder(const struct player *pplayer, const struct impr_type *pimprove)
Definition improvement.c:1076
wonder_destroyed
void wonder_destroyed(const struct city *pcity, const struct impr_type *pimprove)
Definition improvement.c:839
set_user_impr_flag_name
void set_user_impr_flag_name(enum impr_flag_id id, const char *name, const char *helptxt)
Definition improvement.c:1184
is_convert_improvement
bool is_convert_improvement(const struct impr_type *pimprove)
Definition improvement.c:811
impr_flags_free
void impr_flags_free(void)
Definition improvement.c:1172
wonder_visible_to_player
bool wonder_visible_to_player(const struct impr_type *wonder, const struct player *pplayer, const struct player *owner, enum fc_tristate embassy)
Definition improvement.c:944
impr_flag_helptxt
const char * impr_flag_helptxt(enum impr_flag_id id)
Definition improvement.c:1225
improvement_name_translation
const char * improvement_name_translation(const struct impr_type *pimprove)
Definition improvement.c:243
city_from_great_wonder
struct city * city_from_great_wonder(const struct impr_type *pimprove)
Definition improvement.c:1016
improvement_count
Impr_type_id improvement_count(void)
Definition improvement.c:164
is_small_wonder
bool is_small_wonder(const struct impr_type *pimprove)
Definition improvement.c:780
B_LAST
#define B_LAST
Definition improvement.h:42
improvement_array_first
struct impr_type * improvement_array_first(void)
Definition improvement.c:142
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:273
improvement_replacement
const struct impr_type * improvement_replacement(const struct impr_type *pimprove)
Definition improvement.c:1146
great_wonder_owner
struct player * great_wonder_owner(const struct impr_type *pimprove)
Definition improvement.c:1048
great_wonder_is_available
bool great_wonder_is_available(const struct impr_type *pimprove)
Definition improvement.c:1004
improvements_free
void improvements_free(void)
Definition improvement.c:82
is_improvement_productive
bool is_improvement_productive(const struct city *pcity, const struct impr_type *pimprove)
Definition improvement.c:620
name
const char * name
Definition inputfile.c:127
name_translation.h
requirements.h
fc_tristate
fc_tristate
Definition shared.h:46
city
Definition city.h:320
impr_type
Definition improvement.h:50
impr_type::allows_actions
bool allows_actions
Definition improvement.h:75
impr_type::build_cost
int build_cost
Definition improvement.h:60
impr_type::graphic_str
char graphic_str[MAX_LEN_NAME]
Definition improvement.h:55
impr_type::upkeep
int upkeep
Definition improvement.h:61
impr_type::graphic_alt2
char graphic_alt2[MAX_LEN_NAME]
Definition improvement.h:57
impr_type::genus
enum impr_genus_id genus
Definition improvement.h:63
impr_type::graphic_alt
char graphic_alt[MAX_LEN_NAME]
Definition improvement.h:56
impr_type::ruledit_disabled
bool ruledit_disabled
Definition improvement.h:53
impr_type::protects_vs_actions
bool protects_vs_actions
Definition improvement.h:74
impr_type::obsolete_by
struct requirement_vector obsolete_by
Definition improvement.h:59
impr_type::item_number
Impr_type_id item_number
Definition improvement.h:51
impr_type::prevents_disaster
bool prevents_disaster
Definition improvement.h:73
impr_type::sabotage
int sabotage
Definition improvement.h:62
impr_type::soundtag_alt
char soundtag_alt[MAX_LEN_NAME]
Definition improvement.h:67
impr_type::soundtag_alt2
char soundtag_alt2[MAX_LEN_NAME]
Definition improvement.h:68
impr_type::reqs
struct requirement_vector reqs
Definition improvement.h:58
impr_type::allows_extras
bool allows_extras
Definition improvement.h:72
impr_type::helptext
struct strvec * helptext
Definition improvement.h:65
impr_type::allows_units
bool allows_units
Definition improvement.h:71
impr_type::name
struct name_translation name
Definition improvement.h:52
impr_type::flags
bv_impr_flags flags
Definition improvement.h:64
impr_type::soundtag
char soundtag[MAX_LEN_NAME]
Definition improvement.h:66
impr_type::ruledit_dlg
void * ruledit_dlg
Definition improvement.h:54
name_translation
Definition name_translation.h:35
player
Definition player.h:249
strvec
Definition string_vector.c:29
tile
Definition tile.h:50
support.h