Freeciv-3.4
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 (nullptr)
45
46/* Used in the network protocol. */
48
49/* Type of improvement. (Read from buildings.ruleset file.) */
50struct impr_type {
53 bool ruledit_disabled; /* Doesn't really exist - hole in improvements array */
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. */
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 */
69
70 /* Cache */
76};
77
78
79/* General improvement accessor functions. */
81Impr_type_id improvement_index(const struct impr_type *pimprove)
83Impr_type_id improvement_number(const struct impr_type *pimprove)
85
87
88const struct impr_type *valid_improvement(const struct impr_type *pimprove);
90
91struct impr_type *improvement_by_rule_name(const char *name);
93
94const char *improvement_rule_name(const struct impr_type *pimprove);
95const char *improvement_name_translation(const struct impr_type *pimprove);
96
97/* General improvement flag accessor routines */
98bool improvement_has_flag(const struct impr_type *pimprove,
99 enum impr_flag_id flag);
100
101void user_impr_flags_init(void);
102void impr_flags_free(void);
104 const char *name,
105 const char *helptxt);
106const char *impr_flag_helptxt(enum impr_flag_id id);
107
108/* Ancillary routines */
109int impr_build_shield_cost(const struct city *pcity,
110 const struct impr_type *pimprove);
111int impr_base_build_shield_cost(const struct impr_type *pimprove);
112int impr_estimate_build_shield_cost(const struct player *pplayer,
113 const struct tile *ptile,
114 const struct impr_type *pimprove);
115int impr_buy_gold_cost(const struct city *pcity, const struct impr_type *pimprove,
116 int shields_in_stock);
117int impr_sell_gold(const struct impr_type *pimprove);
118
119bool is_improvement_visible(const struct impr_type *pimprove);
120
121bool is_great_wonder(const struct impr_type *pimprove);
122bool is_small_wonder(const struct impr_type *pimprove);
123bool is_wonder(const struct impr_type *pimprove);
124bool is_improvement(const struct impr_type *pimprove);
125bool is_special_improvement(const struct impr_type *pimprove);
126bool is_convert_improvement(const struct impr_type *pimprove);
127
128bool can_improvement_go_obsolete(const struct impr_type *pimprove);
129
130bool can_sell_building(const struct impr_type *pimprove);
131bool can_city_sell_building(const struct city *pcity,
132 const struct impr_type *pimprove);
133bool is_building_sellable(const struct impr_type *pimprove);
135 struct city *pcity,
136 const struct impr_type *pimprove);
137
138const struct impr_type *improvement_replacement(const struct impr_type *pimprove);
139
140/* Macros for struct packet_game_info::great_wonder_owners[]. */
141#define WONDER_DESTROYED (MAX_NUM_PLAYER_SLOTS + 1) /* Used as player id. */
142#define WONDER_NOT_OWNED (MAX_NUM_PLAYER_SLOTS + 2) /* Used as player id. */
143#define WONDER_OWNED(player_id) ((player_id) < MAX_NUM_PLAYER_SLOTS)
144
145/* Macros for struct player::wonders[]. */
146#define WONDER_LOST (-1) /* Used as city id. */
147#define WONDER_NOT_BUILT 0 /* Used as city id. */
148#define WONDER_BUILT(city_id) ((city_id) > 0)
149
150void wonder_built(const struct city *pcity, const struct impr_type *pimprove)
152void wonder_destroyed(const struct city *pcity,
153 const struct impr_type *pimprove)
155
156bool wonder_is_lost(const struct player *pplayer,
157 const struct impr_type *pimprove)
159bool wonder_is_built(const struct player *pplayer,
160 const struct impr_type *pimprove)
162struct city *city_from_wonder(const struct player *pplayer,
163 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 enum fc_tristate embassy);
169
170bool great_wonder_is_built(const struct impr_type *pimprove);
171bool great_wonder_is_destroyed(const struct impr_type *pimprove);
172bool great_wonder_is_available(const struct impr_type *pimprove);
173struct city *city_from_great_wonder(const struct impr_type *pimprove);
174struct player *great_wonder_owner(const struct impr_type *pimprove);
175
176bool small_wonder_is_built(const struct player *pplayer,
177 const struct impr_type *pimprove);
178struct city *city_from_small_wonder(const struct player *pplayer,
179 const struct impr_type *pimprove);
180
181/* Player related improvement functions */
182bool improvement_obsolete(const struct player *pplayer,
183 const struct impr_type *pimprove,
184 const struct city *pcity);
185bool is_improvement_productive(const struct city *pcity,
186 const struct impr_type *pimprove);
187bool is_improvement_redundant(const struct city *pcity,
188 const struct impr_type *pimprove);
189
191 const struct impr_type *pimprove);
192bool can_player_build_improvement_later(const struct player *p,
193 const struct impr_type *pimprove);
194bool can_player_build_improvement_now(const struct player *p,
195 struct impr_type *pimprove);
196
197/* Initialization and iteration */
198void improvements_init(void);
199void improvements_free(void);
200
202
204const struct impr_type *improvement_array_last(void);
205
206#define improvement_iterate(_p) \
207{ \
208 struct impr_type *_p = improvement_array_first(); \
209 if (_p != nullptr) { \
210 for (; _p <= improvement_array_last(); _p++) {
211
212#define improvement_iterate_end \
213 } \
214 } \
215}
216
217#define improvement_re_active_iterate(_p) \
218 improvement_iterate(_p) { \
219 if (!_p->ruledit_disabled) {
220
221#define improvement_re_active_iterate_end \
222 } \
223 } improvement_iterate_end;
224
225#define genus_iterate(_p) \
226 { \
227 enum impr_genus_id _p; \
228 for (_p = (enum impr_genus_id)0; _p < IG_COUNT; \
229 _p = (enum impr_genus_id)((int)_p + 1)) {
230
231#define genus_iterate_end \
232 } \
233 }
234
235#ifdef __cplusplus
236}
237#endif /* __cplusplus */
238
239#endif /* FC__IMPROVEMENT_H */
#define BV_DEFINE(name, bits)
Definition bitvector.h:140
char * incite_cost
Definition comments.c:77
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
int Impr_type_id
Definition fc_types.h:237
test_result
Definition fc_types.h:940
#define MAX_LEN_NAME
Definition fc_types.h:68
struct city * owner
Definition citydlg.c:226
const struct impr_type * valid_improvement(const struct impr_type *pimprove)
struct impr_type * improvement_by_number(const Impr_type_id id)
bool can_sell_building(const struct impr_type *pimprove)
int impr_sell_gold(const struct impr_type *pimprove)
void improvements_init(void)
Definition improvement.c:48
bool is_building_sellable(const struct impr_type *pimprove)
void wonder_built(const struct city *pcity, const struct impr_type *pimprove) fc__attribute((nonnull(1)))
const struct impr_type * improvement_array_last(void)
const struct impr_type * valid_improvement_by_number(const Impr_type_id id)
bool can_city_sell_building(const struct city *pcity, const struct impr_type *pimprove)
bool can_player_build_improvement_direct(const struct player *p, const struct impr_type *pimprove)
bool great_wonder_is_built(const struct impr_type *pimprove)
struct city * city_from_wonder(const struct player *pplayer, const struct impr_type *pimprove) fc__attribute((nonnull(1)))
enum test_result test_player_sell_building_now(struct player *pplayer, struct city *pcity, const struct impr_type *pimprove)
void user_impr_flags_init(void)
bool is_special_improvement(const struct impr_type *pimprove)
bool is_improvement_redundant(const struct city *pcity, const struct impr_type *pimprove)
bool can_player_build_improvement_later(const struct player *p, const struct impr_type *pimprove)
bool great_wonder_is_destroyed(const struct impr_type *pimprove)
bool can_player_build_improvement_now(const struct player *p, struct impr_type *pimprove)
bool is_improvement(const struct impr_type *pimprove)
void wonder_destroyed(const struct city *pcity, const struct impr_type *pimprove) fc__attribute((nonnull(1)))
int impr_base_build_shield_cost(const struct impr_type *pimprove)
bool small_wonder_is_built(const struct player *pplayer, const struct impr_type *pimprove)
bool can_improvement_go_obsolete(const struct impr_type *pimprove)
Impr_type_id improvement_number(const struct impr_type *pimprove) fc__attribute((nonnull(1)))
const char * improvement_rule_name(const struct impr_type *pimprove)
bool is_improvement_visible(const struct impr_type *pimprove)
int impr_buy_gold_cost(const struct city *pcity, const struct impr_type *pimprove, int shields_in_stock)
int impr_build_shield_cost(const struct city *pcity, const struct impr_type *pimprove)
bool is_wonder(const struct impr_type *pimprove)
bool is_great_wonder(const struct impr_type *pimprove)
bool improvement_obsolete(const struct player *pplayer, const struct impr_type *pimprove, const struct city *pcity)
struct impr_type * improvement_by_translated_name(const char *name)
bool wonder_is_lost(const struct player *pplayer, const struct impr_type *pimprove) fc__attribute((nonnull(1)))
void improvement_feature_cache_init(void)
Definition improvement.c:92
bool improvement_has_flag(const struct impr_type *pimprove, enum impr_flag_id flag)
struct impr_type * improvement_by_rule_name(const char *name)
struct city * city_from_small_wonder(const struct player *pplayer, const struct impr_type *pimprove)
void set_user_impr_flag_name(enum impr_flag_id id, const char *name, const char *helptxt)
Impr_type_id improvement_index(const struct impr_type *pimprove) fc__attribute((nonnull(1)))
bool is_convert_improvement(const struct impr_type *pimprove)
bool wonder_is_built(const struct player *pplayer, const struct impr_type *pimprove) fc__attribute((nonnull(1)))
void impr_flags_free(void)
bool wonder_visible_to_player(const struct impr_type *wonder, const struct player *pplayer, const struct player *owner, enum fc_tristate embassy)
const char * impr_flag_helptxt(enum impr_flag_id id)
const char * improvement_name_translation(const struct impr_type *pimprove)
struct city * city_from_great_wonder(const struct impr_type *pimprove)
Impr_type_id improvement_count(void)
bool is_small_wonder(const struct impr_type *pimprove)
#define B_LAST
Definition improvement.h:42
struct impr_type * improvement_array_first(void)
int impr_estimate_build_shield_cost(const struct player *pplayer, const struct tile *ptile, const struct impr_type *pimprove)
const struct impr_type * improvement_replacement(const struct impr_type *pimprove)
struct player * great_wonder_owner(const struct impr_type *pimprove)
bool great_wonder_is_available(const struct impr_type *pimprove)
void improvements_free(void)
Definition improvement.c:82
bool is_improvement_productive(const struct city *pcity, const struct impr_type *pimprove)
const char * name
Definition inputfile.c:127
fc_tristate
Definition shared.h:46
Definition city.h:318
bool allows_actions
Definition improvement.h:75
int build_cost
Definition improvement.h:60
char graphic_str[MAX_LEN_NAME]
Definition improvement.h:55
char graphic_alt2[MAX_LEN_NAME]
Definition improvement.h:57
enum impr_genus_id genus
Definition improvement.h:63
char graphic_alt[MAX_LEN_NAME]
Definition improvement.h:56
bool ruledit_disabled
Definition improvement.h:53
bool protects_vs_actions
Definition improvement.h:74
struct requirement_vector obsolete_by
Definition improvement.h:59
Impr_type_id item_number
Definition improvement.h:51
bool prevents_disaster
Definition improvement.h:73
char soundtag_alt[MAX_LEN_NAME]
Definition improvement.h:67
char soundtag_alt2[MAX_LEN_NAME]
Definition improvement.h:68
struct requirement_vector reqs
Definition improvement.h:58
bool allows_extras
Definition improvement.h:72
struct strvec * helptext
Definition improvement.h:65
bool allows_units
Definition improvement.h:71
struct name_translation name
Definition improvement.h:52
bv_impr_flags flags
Definition improvement.h:64
char soundtag[MAX_LEN_NAME]
Definition improvement.h:66
void * ruledit_dlg
Definition improvement.h:54
Definition tile.h:50
#define fc__attribute(x)
Definition support.h:99