Freeciv-3.2
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. */
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);
82Impr_type_id improvement_number(const struct impr_type *pimprove);
83
85
86const struct impr_type *valid_improvement(const struct impr_type *pimprove);
88
89struct impr_type *improvement_by_rule_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);
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);
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
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
195
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 */
#define BV_DEFINE(name, bits)
Definition bitvector.h:132
char * incite_cost
Definition comments.c:75
int Impr_type_id
Definition fc_types.h:376
test_result
Definition fc_types.h:1245
#define MAX_LEN_NAME
Definition fc_types.h:66
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)
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)
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)
void wonder_built(const struct city *pcity, const struct impr_type *pimprove)
bool great_wonder_is_destroyed(const struct impr_type *pimprove)
bool wonder_is_lost(const struct player *pplayer, 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)
bool wonder_is_built(const struct player *pplayer, const struct impr_type *pimprove)
int impr_base_build_shield_cost(const struct impr_type *pimprove)
Impr_type_id improvement_number(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)
const char * improvement_rule_name(const struct impr_type *pimprove)
bool is_improvement_visible(const struct impr_type *pimprove)
struct city * city_from_wonder(const struct player *pplayer, const struct impr_type *pimprove)
Impr_type_id improvement_index(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)
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 wonder_destroyed(const struct city *pcity, const struct impr_type *pimprove)
void set_user_impr_flag_name(enum impr_flag_id id, const char *name, const char *helptxt)
bool is_convert_improvement(const struct impr_type *pimprove)
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:320
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