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. */
65BV_DEFINE(bv_imprs, B_LAST);
66
67/* Type of improvement. (Read from buildings.ruleset file.) */
68struct impr_type {
71 bool ruledit_disabled; /* Does not really exist - hole in improvements array */
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;
85
86 /* Cache */
92};
93
94
95/* General improvement accessor functions. */
97Impr_type_id improvement_index(const struct impr_type *pimprove);
98Impr_type_id improvement_number(const struct impr_type *pimprove);
99
101
102const struct impr_type *valid_improvement(const struct impr_type *pimprove);
104
105struct impr_type *improvement_by_rule_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);
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
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
201
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 */
#define BV_DEFINE(name, bits)
Definition bitvector.h:132
int Impr_type_id
Definition fc_types.h:346
test_result
Definition fc_types.h:1097
#define MAX_LEN_NAME
Definition fc_types.h:66
struct city * owner
Definition citydlg.c:219
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:46
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)
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:90
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)
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)
bool wonder_visible_to_player(const struct impr_type *wonder, const struct player *pplayer, const struct player *owner)
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:80
bool is_improvement_productive(const struct city *pcity, const struct impr_type *pimprove)
const char * name
Definition inputfile.c:127
Definition city.h:309
bool allows_actions
Definition improvement.h:91
int build_cost
Definition improvement.h:77
char graphic_str[MAX_LEN_NAME]
Definition improvement.h:73
enum impr_genus_id genus
Definition improvement.h:80
char graphic_alt[MAX_LEN_NAME]
Definition improvement.h:74
bool ruledit_disabled
Definition improvement.h:71
bool protects_vs_actions
Definition improvement.h:90
struct requirement_vector obsolete_by
Definition improvement.h:76
Impr_type_id item_number
Definition improvement.h:69
bool prevents_disaster
Definition improvement.h:89
char soundtag_alt[MAX_LEN_NAME]
Definition improvement.h:84
struct requirement_vector reqs
Definition improvement.h:75
bool allows_extras
Definition improvement.h:88
struct strvec * helptext
Definition improvement.h:82
bool allows_units
Definition improvement.h:87
struct name_translation name
Definition improvement.h:70
bv_impr_flags flags
Definition improvement.h:81
char soundtag[MAX_LEN_NAME]
Definition improvement.h:83
void * ruledit_dlg
Definition improvement.h:72
Definition tile.h:49