webperimental: enable restrictinfra by default...
[freeciv.git] / common / improvement.h
bloba90410b95920128997b541b409d338e9a0d71d1d
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 /* 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"
64 /* Used in the network protocol. */
65 BV_DEFINE(bv_imprs, B_LAST);
67 /* Type of improvement. (Read from buildings.ruleset file.) */
68 struct impr_type {
69 Impr_type_id item_number;
70 struct name_translation name;
71 bool disabled; /* Does not really exist - hole in improvements array */
72 char graphic_str[MAX_LEN_NAME]; /* city icon of improv. */
73 char graphic_alt[MAX_LEN_NAME]; /* city icon of improv. */
74 struct requirement_vector reqs;
75 struct requirement_vector obsolete_by;
76 int build_cost; /* Use wrappers to access this. */
77 int upkeep;
78 int sabotage; /* Base chance of diplomat sabotage succeeding. */
79 enum impr_genus_id genus; /* genus; e.g. GreatWonder */
80 bv_impr_flags flags;
81 struct strvec *helptext;
82 char soundtag[MAX_LEN_NAME];
83 char soundtag_alt[MAX_LEN_NAME];
85 /* Cache */
86 bool allows_units;
87 bool allows_extras;
88 bool prevents_disaster;
89 bool protects_vs_actions;
94 /* General improvement accessor functions. */
95 Impr_type_id improvement_count(void);
96 Impr_type_id improvement_index(const struct impr_type *pimprove);
97 Impr_type_id improvement_number(const struct impr_type *pimprove);
99 struct impr_type *improvement_by_number(const Impr_type_id id);
101 struct impr_type *valid_improvement(struct impr_type *pimprove);
102 struct impr_type *valid_improvement_by_number(const Impr_type_id id);
104 struct impr_type *improvement_by_rule_name(const char *name);
105 struct impr_type *improvement_by_translated_name(const char *name);
107 const char *improvement_rule_name(const struct impr_type *pimprove);
108 const char *improvement_name_translation(const struct impr_type *pimprove);
110 /* General improvement flag accessor routines */
111 bool improvement_has_flag(const struct impr_type *pimprove,
112 enum impr_flag_id flag);
114 /* Ancillary routines */
115 int impr_build_shield_cost(const struct impr_type *pimprove);
116 int impr_buy_gold_cost(const struct impr_type *pimprove, int shields_in_stock);
117 int impr_sell_gold(const struct impr_type *pimprove);
119 bool is_improvement_visible(const struct impr_type *pimprove);
121 bool is_great_wonder(const struct impr_type *pimprove);
122 bool is_small_wonder(const struct impr_type *pimprove);
123 bool is_wonder(const struct impr_type *pimprove);
124 bool is_improvement(const struct impr_type *pimprove);
125 bool is_special_improvement(const struct impr_type *pimprove);
127 bool can_improvement_go_obsolete(const struct impr_type *pimprove);
129 bool can_sell_building(struct impr_type *pimprove);
130 bool can_city_sell_building(const struct city *pcity,
131 struct impr_type *pimprove);
132 enum test_result test_player_sell_building_now(struct player *pplayer,
133 struct city *pcity,
134 struct impr_type *pimprove);
136 struct impr_type *improvement_replacement(const struct impr_type *pimprove);
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)
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)
148 void wonder_built(const struct city *pcity, const struct impr_type *pimprove);
149 void wonder_destroyed(const struct city *pcity,
150 const struct impr_type *pimprove);
152 bool wonder_is_lost(const struct player *pplayer,
153 const struct impr_type *pimprove);
154 bool wonder_is_built(const struct player *pplayer,
155 const struct impr_type *pimprove);
156 struct city *city_from_wonder(const struct player *pplayer,
157 const struct impr_type *pimprove);
159 bool great_wonder_is_built(const struct impr_type *pimprove);
160 bool great_wonder_is_destroyed(const struct impr_type *pimprove);
161 bool great_wonder_is_available(const struct impr_type *pimprove);
162 struct city *city_from_great_wonder(const struct impr_type *pimprove);
163 struct player *great_wonder_owner(const struct impr_type *pimprove);
165 bool small_wonder_is_built(const struct player *pplayer,
166 const struct impr_type *pimprove);
167 struct city *city_from_small_wonder(const struct player *pplayer,
168 const struct impr_type *pimprove);
170 /* player related improvement functions */
171 bool improvement_obsolete(const struct player *pplayer,
172 const struct impr_type *pimprove,
173 const struct city *pcity);
174 bool is_improvement_productive(const struct city *pcity,
175 struct impr_type *pimprove);
176 bool is_improvement_redundant(const struct city *pcity,
177 struct impr_type *pimprove);
179 bool can_player_build_improvement_direct(const struct player *p,
180 struct impr_type *pimprove);
181 bool can_player_build_improvement_later(const struct player *p,
182 struct impr_type *pimprove);
183 bool can_player_build_improvement_now(const struct player *p,
184 struct impr_type *pimprove);
186 /* Initialization and iteration */
187 void improvements_init(void);
188 void improvements_free(void);
190 void improvement_feature_cache_init(void);
192 struct impr_type *improvement_array_first(void);
193 const struct impr_type *improvement_array_last(void);
195 #define improvement_iterate(_p) \
197 struct impr_type *_p = improvement_array_first(); \
198 if (NULL != _p) { \
199 for (; _p <= improvement_array_last(); _p++) {
201 #define improvement_iterate_end \
206 #define improvement_active_iterate(_p) \
207 improvement_iterate(_p) { \
208 if (!_p->disabled) {
210 #define improvement_active_iterate_end \
212 } improvement_iterate_end;
214 #ifdef __cplusplus
216 #endif /* __cplusplus */
218 #endif /* FC__IMPROVEMENT_H */