Rulesave saves trade.type and trade.bonus correctly.
[freeciv.git] / common / improvement.h
blob32f22b9451891e72e925840fec0043ddf40480d1
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.
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
16 #ifdef __cplusplus
17 extern "C" {
18 #endif /* __cplusplus */
20 /* City Improvements, including Wonders. (Alternatively "Buildings".) */
22 /* utility */
23 #include "bitvector.h"
24 #include "support.h" /* bool */
26 /* common */
27 #include "fc_types.h"
28 #include "name_translation.h"
29 #include "requirements.h"
31 struct strvec; /* Actually defined in "utility/string_vector.h". */
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.
38 * B_NEVER is the pointer equivalent replacement for B_LAST flag value.
40 * Used in the network protocol.
42 #define B_LAST MAX_NUM_ITEMS
44 #define B_NEVER (NULL)
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 #define SPECENUM_COUNT IF_COUNT
58 #define SPECENUM_BITVECTOR bv_impr_flags
59 #include "specenum_gen.h"
61 /* Used in the network protocol. */
62 #define SPECENUM_NAME impr_genus_id
63 #define SPECENUM_VALUE0 IG_GREAT_WONDER
64 #define SPECENUM_VALUE0NAME "GreatWonder"
65 #define SPECENUM_VALUE1 IG_SMALL_WONDER
66 #define SPECENUM_VALUE1NAME "SmallWonder"
67 #define SPECENUM_VALUE2 IG_IMPROVEMENT
68 #define SPECENUM_VALUE2NAME "Improvement"
69 #define SPECENUM_VALUE3 IG_SPECIAL
70 #define SPECENUM_VALUE3NAME "Special"
71 #include "specenum_gen.h"
73 /* Used in the network protocol. */
74 BV_DEFINE(bv_imprs, B_LAST);
76 /* Type of improvement. (Read from buildings.ruleset file.) */
77 struct impr_type {
78 Impr_type_id item_number;
79 struct name_translation name;
80 bool disabled; /* Does not really exist - hole in improvments array */
81 char graphic_str[MAX_LEN_NAME]; /* city icon of improv. */
82 char graphic_alt[MAX_LEN_NAME]; /* city icon of improv. */
83 struct requirement_vector reqs;
84 struct requirement_vector obsolete_by;
85 int build_cost; /* Use wrappers to access this. */
86 int upkeep;
87 int sabotage; /* Base chance of diplomat sabotage succeeding. */
88 enum impr_genus_id genus; /* genus; e.g. GreatWonder */
89 bv_impr_flags flags;
90 struct strvec *helptext;
91 char soundtag[MAX_LEN_NAME];
92 char soundtag_alt[MAX_LEN_NAME];
94 /* Cache */
95 bool allows_units;
96 bool allows_extras;
97 bool prevents_disaster;
98 bool protects_vs_actions;
103 /* General improvement accessor functions. */
104 Impr_type_id improvement_count(void);
105 Impr_type_id improvement_index(const struct impr_type *pimprove);
106 Impr_type_id improvement_number(const struct impr_type *pimprove);
108 struct impr_type *improvement_by_number(const Impr_type_id id);
110 struct impr_type *valid_improvement(struct impr_type *pimprove);
111 struct impr_type *valid_improvement_by_number(const Impr_type_id id);
113 struct impr_type *improvement_by_rule_name(const char *name);
114 struct impr_type *improvement_by_translated_name(const char *name);
116 const char *improvement_rule_name(const struct impr_type *pimprove);
117 const char *improvement_name_translation(const struct impr_type *pimprove);
119 /* General improvement flag accessor routines */
120 bool improvement_has_flag(const struct impr_type *pimprove,
121 enum impr_flag_id flag);
123 /* Ancillary routines */
124 int impr_build_shield_cost(const struct impr_type *pimprove);
125 int impr_buy_gold_cost(const struct impr_type *pimprove, int shields_in_stock);
126 int impr_sell_gold(const struct impr_type *pimprove);
128 bool is_improvement_visible(const struct impr_type *pimprove);
130 bool is_great_wonder(const struct impr_type *pimprove);
131 bool is_small_wonder(const struct impr_type *pimprove);
132 bool is_wonder(const struct impr_type *pimprove);
133 bool is_improvement(const struct impr_type *pimprove);
134 bool is_special_improvement(const struct impr_type *pimprove);
136 bool can_improvement_go_obsolete(const struct impr_type *pimprove);
138 bool can_sell_building(struct impr_type *pimprove);
139 bool can_city_sell_building(const struct city *pcity,
140 struct impr_type *pimprove);
141 enum test_result test_player_sell_building_now(struct player *pplayer,
142 struct city *pcity,
143 struct impr_type *pimprove);
145 struct impr_type *improvement_replacement(const struct impr_type *pimprove);
147 /* Macros for struct packet_game_info::great_wonder_owners[]. */
148 #define WONDER_DESTROYED (MAX_NUM_PLAYER_SLOTS + 1) /* Used as player id. */
149 #define WONDER_NOT_OWNED (MAX_NUM_PLAYER_SLOTS + 2) /* Used as player id. */
150 #define WONDER_OWNED(player_id) ((player_id) < MAX_NUM_PLAYER_SLOTS)
152 /* Macros for struct player::wonders[]. */
153 #define WONDER_LOST (-1) /* Used as city id. */
154 #define WONDER_NOT_BUILT 0 /* Used as city id. */
155 #define WONDER_BUILT(city_id) ((city_id) > 0)
157 void wonder_built(const struct city *pcity, const struct impr_type *pimprove);
158 void wonder_destroyed(const struct city *pcity,
159 const struct impr_type *pimprove);
161 bool wonder_is_lost(const struct player *pplayer,
162 const struct impr_type *pimprove);
163 bool wonder_is_built(const struct player *pplayer,
164 const struct impr_type *pimprove);
165 struct city *city_from_wonder(const struct player *pplayer,
166 const struct impr_type *pimprove);
168 bool great_wonder_is_built(const struct impr_type *pimprove);
169 bool great_wonder_is_destroyed(const struct impr_type *pimprove);
170 bool great_wonder_is_available(const struct impr_type *pimprove);
171 struct city *city_from_great_wonder(const struct impr_type *pimprove);
172 struct player *great_wonder_owner(const struct impr_type *pimprove);
174 bool small_wonder_is_built(const struct player *pplayer,
175 const struct impr_type *pimprove);
176 struct city *city_from_small_wonder(const struct player *pplayer,
177 const struct impr_type *pimprove);
179 /* player related improvement functions */
180 bool improvement_obsolete(const struct player *pplayer,
181 const struct impr_type *pimprove,
182 const struct city *pcity);
183 bool is_improvement_productive(const struct city *pcity,
184 struct impr_type *pimprove);
185 bool is_improvement_redundant(const struct city *pcity,
186 struct impr_type *pimprove);
188 bool can_player_build_improvement_direct(const struct player *p,
189 struct impr_type *pimprove);
190 bool can_player_build_improvement_later(const struct player *p,
191 struct impr_type *pimprove);
192 bool can_player_build_improvement_now(const struct player *p,
193 struct impr_type *pimprove);
195 /* Initialization and iteration */
196 void improvements_init(void);
197 void improvements_free(void);
199 void improvement_feature_cache_init(void);
201 struct impr_type *improvement_array_first(void);
202 const struct impr_type *improvement_array_last(void);
204 #define improvement_iterate(_p) \
206 struct impr_type *_p = improvement_array_first(); \
207 if (NULL != _p) { \
208 for (; _p <= improvement_array_last(); _p++) {
210 #define improvement_iterate_end \
215 #define improvement_active_iterate(_p) \
216 improvement_iterate(_p) { \
217 if (!_p->disabled) {
219 #define improvement_active_iterate_end \
221 } improvement_iterate_end;
223 #ifdef __cplusplus
225 #endif /* __cplusplus */
227 #endif /* FC__IMPROVEMENT_H */