I18n markup: TRANS comments and missing no-c-format.
[freeciv.git] / common / effects.h
blob84a88b806906bbd91bffdce6890c890cef512fea
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__EFFECTS_H
14 #define FC__EFFECTS_H
16 #ifdef __cplusplus
17 extern "C" {
18 #endif /* __cplusplus */
20 #include "support.h" /* bool type */
21 #include "fc_types.h"
23 #include "connection.h"
25 struct requirement;
27 /* Type of effects. Add new values via SPECENUM_VALUE%d and
28 * SPECENUM_VALUE%dNAME at the end of the list.
29 * Used in the network protocol.
31 #define SPECENUM_NAME effect_type
32 #define SPECENUM_VALUE0 EFT_TECH_PARASITE
33 #define SPECENUM_VALUE0NAME "Tech_Parasite"
34 #define SPECENUM_VALUE1 EFT_AIRLIFT
35 #define SPECENUM_VALUE1NAME "Airlift"
36 #define SPECENUM_VALUE2 EFT_ANY_GOVERNMENT
37 #define SPECENUM_VALUE2NAME "Any_Government"
38 #define SPECENUM_VALUE3 EFT_CAPITAL_CITY
39 #define SPECENUM_VALUE3NAME "Capital_City"
40 #define SPECENUM_VALUE4 EFT_ENABLE_NUKE
41 #define SPECENUM_VALUE4NAME "Enable_Nuke"
42 #define SPECENUM_VALUE5 EFT_ENABLE_SPACE
43 #define SPECENUM_VALUE5NAME "Enable_Space"
44 #define SPECENUM_VALUE6 EFT_SPECIALIST_OUTPUT
45 #define SPECENUM_VALUE6NAME "Specialist_Output"
46 #define SPECENUM_VALUE7 EFT_OUTPUT_BONUS
47 #define SPECENUM_VALUE7NAME "Output_Bonus"
48 #define SPECENUM_VALUE8 EFT_OUTPUT_BONUS_2
49 #define SPECENUM_VALUE8NAME "Output_Bonus_2"
50 /* add to each worked tile */
51 #define SPECENUM_VALUE9 EFT_OUTPUT_ADD_TILE
52 #define SPECENUM_VALUE9NAME "Output_Add_Tile"
53 /* add to each worked tile that already has output */
54 #define SPECENUM_VALUE10 EFT_OUTPUT_INC_TILE
55 #define SPECENUM_VALUE10NAME "Output_Inc_Tile"
56 /* increase tile output by given % */
57 #define SPECENUM_VALUE11 EFT_OUTPUT_PER_TILE
58 #define SPECENUM_VALUE11NAME "Output_Per_Tile"
59 #define SPECENUM_VALUE12 EFT_OUTPUT_WASTE_PCT
60 #define SPECENUM_VALUE12NAME "Output_Waste_Pct"
61 #define SPECENUM_VALUE13 EFT_FORCE_CONTENT
62 #define SPECENUM_VALUE13NAME "Force_Content"
63 /* TODO: EFT_FORCE_CONTENT_PCT */
64 #define SPECENUM_VALUE14 EFT_GIVE_IMM_TECH
65 #define SPECENUM_VALUE14NAME "Give_Imm_Tech"
66 #define SPECENUM_VALUE15 EFT_GROWTH_FOOD
67 #define SPECENUM_VALUE15NAME "Growth_Food"
68 /* reduced illness due to buildings ... */
69 #define SPECENUM_VALUE16 EFT_HEALTH_PCT
70 #define SPECENUM_VALUE16NAME "Health_Pct"
71 #define SPECENUM_VALUE17 EFT_HAVE_EMBASSIES
72 #define SPECENUM_VALUE17NAME "Have_Embassies"
73 #define SPECENUM_VALUE18 EFT_MAKE_CONTENT
74 #define SPECENUM_VALUE18NAME "Make_Content"
75 #define SPECENUM_VALUE19 EFT_MAKE_CONTENT_MIL
76 #define SPECENUM_VALUE19NAME "Make_Content_Mil"
77 #define SPECENUM_VALUE20 EFT_MAKE_CONTENT_MIL_PER
78 #define SPECENUM_VALUE20NAME "Make_Content_Mil_Per"
79 /* TODO: EFT_MAKE_CONTENT_PCT */
80 #define SPECENUM_VALUE21 EFT_MAKE_HAPPY
81 #define SPECENUM_VALUE21NAME "Make_Happy"
82 #define SPECENUM_VALUE22 EFT_NO_ANARCHY
83 #define SPECENUM_VALUE22NAME "No_Anarchy"
84 #define SPECENUM_VALUE23 EFT_NUKE_PROOF
85 #define SPECENUM_VALUE23NAME "Nuke_Proof"
86 /* TODO: EFT_POLLU_ADJ */
87 /* TODO: EFT_POLLU_PCT */
88 /* TODO: EFT_POLLU_POP_ADJ */
89 #define SPECENUM_VALUE24 EFT_POLLU_POP_PCT
90 #define SPECENUM_VALUE24NAME "Pollu_Pop_Pct"
91 /* TODO: EFT_POLLU_PROD_ADJ */
92 #define SPECENUM_VALUE25 EFT_POLLU_PROD_PCT
93 #define SPECENUM_VALUE25NAME "Pollu_Prod_Pct"
94 /* TODO: EFT_PROD_PCT */
95 #define SPECENUM_VALUE26 EFT_REVEAL_CITIES
96 #define SPECENUM_VALUE26NAME "Reveal_Cities"
97 #define SPECENUM_VALUE27 EFT_REVEAL_MAP
98 #define SPECENUM_VALUE27NAME "Reveal_Map"
99 /* TODO: EFT_INCITE_DIST_ADJ */
100 #define SPECENUM_VALUE28 EFT_INCITE_COST_PCT
101 #define SPECENUM_VALUE28NAME "Incite_Cost_Pct"
102 #define SPECENUM_VALUE29 EFT_SIZE_ADJ
103 #define SPECENUM_VALUE29NAME "Size_Adj"
104 #define SPECENUM_VALUE30 EFT_SIZE_UNLIMIT
105 #define SPECENUM_VALUE30NAME "Size_Unlimit"
106 #define SPECENUM_VALUE31 EFT_SS_STRUCTURAL
107 #define SPECENUM_VALUE31NAME "SS_Structural"
108 #define SPECENUM_VALUE32 EFT_SS_COMPONENT
109 #define SPECENUM_VALUE32NAME "SS_Component"
110 #define SPECENUM_VALUE33 EFT_SS_MODULE
111 #define SPECENUM_VALUE33NAME "SS_Module"
112 #define SPECENUM_VALUE34 EFT_SPY_RESISTANT
113 #define SPECENUM_VALUE34NAME "Spy_Resistant"
114 #define SPECENUM_VALUE35 EFT_MOVE_BONUS
115 #define SPECENUM_VALUE35NAME "Move_Bonus"
116 #define SPECENUM_VALUE36 EFT_UNIT_NO_LOSE_POP
117 #define SPECENUM_VALUE36NAME "Unit_No_Lose_Pop"
118 #define SPECENUM_VALUE37 EFT_UNIT_RECOVER
119 #define SPECENUM_VALUE37NAME "Unit_Recover"
120 #define SPECENUM_VALUE38 EFT_UPGRADE_UNIT
121 #define SPECENUM_VALUE38NAME "Upgrade_Unit"
122 #define SPECENUM_VALUE39 EFT_UPKEEP_FREE
123 #define SPECENUM_VALUE39NAME "Upkeep_Free"
124 #define SPECENUM_VALUE40 EFT_TECH_UPKEEP_FREE
125 #define SPECENUM_VALUE40NAME "Tech_Upkeep_Free"
126 #define SPECENUM_VALUE41 EFT_NO_UNHAPPY
127 #define SPECENUM_VALUE41NAME "No_Unhappy"
128 #define SPECENUM_VALUE42 EFT_VETERAN_BUILD
129 #define SPECENUM_VALUE42NAME "Veteran_Build"
130 #define SPECENUM_VALUE43 EFT_VETERAN_COMBAT
131 #define SPECENUM_VALUE43NAME "Veteran_Combat"
132 #define SPECENUM_VALUE44 EFT_HP_REGEN
133 #define SPECENUM_VALUE44NAME "HP_Regen"
134 #define SPECENUM_VALUE45 EFT_CITY_VISION_RADIUS_SQ
135 #define SPECENUM_VALUE45NAME "City_Vision_Radius_Sq"
136 #define SPECENUM_VALUE46 EFT_UNIT_VISION_RADIUS_SQ
137 #define SPECENUM_VALUE46NAME "Unit_Vision_Radius_Sq"
138 /* Interacts with F_BADWALLATTACKER, ignored by F_IGWALL */
139 #define SPECENUM_VALUE47 EFT_DEFEND_BONUS
140 #define SPECENUM_VALUE47NAME "Defend_Bonus"
141 #define SPECENUM_VALUE48 EFT_NO_INCITE
142 #define SPECENUM_VALUE48NAME "No_Incite"
143 #define SPECENUM_VALUE49 EFT_GAIN_AI_LOVE
144 #define SPECENUM_VALUE49NAME "Gain_AI_Love"
145 #define SPECENUM_VALUE50 EFT_TURN_YEARS
146 #define SPECENUM_VALUE50NAME "Turn_Years"
147 #define SPECENUM_VALUE51 EFT_SLOW_DOWN_TIMELINE
148 #define SPECENUM_VALUE51NAME "Slow_Down_Timeline"
149 #define SPECENUM_VALUE52 EFT_CIVIL_WAR_CHANCE
150 #define SPECENUM_VALUE52NAME "Civil_War_Chance"
151 /* change of the migration score */
152 #define SPECENUM_VALUE53 EFT_MIGRATION_PCT
153 #define SPECENUM_VALUE53NAME "Migration_Pct"
154 /* +1 unhappy when more than this cities */
155 #define SPECENUM_VALUE54 EFT_EMPIRE_SIZE_BASE
156 #define SPECENUM_VALUE54NAME "Empire_Size_Base"
157 /* adds additional +1 unhappy steps to above */
158 #define SPECENUM_VALUE55 EFT_EMPIRE_SIZE_STEP
159 #define SPECENUM_VALUE55NAME "Empire_Size_Step"
160 #define SPECENUM_VALUE56 EFT_MAX_RATES
161 #define SPECENUM_VALUE56NAME "Max_Rates"
162 #define SPECENUM_VALUE57 EFT_MARTIAL_LAW_EACH
163 #define SPECENUM_VALUE57NAME "Martial_Law_Each"
164 #define SPECENUM_VALUE58 EFT_MARTIAL_LAW_MAX
165 #define SPECENUM_VALUE58NAME "Martial_Law_Max"
166 #define SPECENUM_VALUE59 EFT_RAPTURE_GROW
167 #define SPECENUM_VALUE59NAME "Rapture_Grow"
168 #define SPECENUM_VALUE60 EFT_UNBRIBABLE_UNITS
169 #define SPECENUM_VALUE60NAME "Unbribable_Units"
170 #define SPECENUM_VALUE61 EFT_REVOLUTION_WHEN_UNHAPPY
171 #define SPECENUM_VALUE61NAME "Revolution_When_Unhappy"
172 #define SPECENUM_VALUE62 EFT_HAS_SENATE
173 #define SPECENUM_VALUE62NAME "Has_Senate"
174 #define SPECENUM_VALUE63 EFT_INSPIRE_PARTISANS
175 #define SPECENUM_VALUE63NAME "Inspire_Partisans"
176 #define SPECENUM_VALUE64 EFT_HAPPINESS_TO_GOLD
177 #define SPECENUM_VALUE64NAME "Happiness_To_Gold"
178 /* stupid special case; we hate it */
179 #define SPECENUM_VALUE65 EFT_FANATICS
180 #define SPECENUM_VALUE65NAME "Fanatics"
181 #define SPECENUM_VALUE66 EFT_NO_DIPLOMACY
182 #define SPECENUM_VALUE66NAME "No_Diplomacy"
183 #define SPECENUM_VALUE67 EFT_TRADE_REVENUE_BONUS
184 #define SPECENUM_VALUE67NAME "Trade_Revenue_Bonus"
185 /* multiply unhappy upkeep by this effect */
186 #define SPECENUM_VALUE68 EFT_UNHAPPY_FACTOR
187 #define SPECENUM_VALUE68NAME "Unhappy_Factor"
188 /* multiply upkeep by this effect */
189 #define SPECENUM_VALUE69 EFT_UPKEEP_FACTOR
190 #define SPECENUM_VALUE69NAME "Upkeep_Factor"
191 /* this many units are free from upkeep */
192 #define SPECENUM_VALUE70 EFT_UNIT_UPKEEP_FREE_PER_CITY
193 #define SPECENUM_VALUE70NAME "Unit_Upkeep_Free_Per_City"
194 #define SPECENUM_VALUE71 EFT_OUTPUT_WASTE
195 #define SPECENUM_VALUE71NAME "Output_Waste"
196 #define SPECENUM_VALUE72 EFT_OUTPUT_WASTE_BY_DISTANCE
197 #define SPECENUM_VALUE72NAME "Output_Waste_By_Distance"
198 /* -1 penalty to tiles producing more than this */
199 #define SPECENUM_VALUE73 EFT_OUTPUT_PENALTY_TILE
200 #define SPECENUM_VALUE73NAME "Output_Penalty_Tile"
201 #define SPECENUM_VALUE74 EFT_OUTPUT_INC_TILE_CELEBRATE
202 #define SPECENUM_VALUE74NAME "Output_Inc_Tile_Celebrate"
203 /* all citizens after this are unhappy */
204 #define SPECENUM_VALUE75 EFT_CITY_UNHAPPY_SIZE
205 #define SPECENUM_VALUE75NAME "City_Unhappy_Size"
206 /* add to default squared city radius */
207 #define SPECENUM_VALUE76 EFT_CITY_RADIUS_SQ
208 #define SPECENUM_VALUE76NAME "City_Radius_Sq"
209 /* number of build slots for units */
210 #define SPECENUM_VALUE77 EFT_CITY_BUILD_SLOTS
211 #define SPECENUM_VALUE77NAME "City_Build_Slots"
212 #define SPECENUM_VALUE78 EFT_UPGRADE_PRICE_PCT
213 #define SPECENUM_VALUE78NAME "Upgrade_Price_Pct"
214 /* City should use walls gfx */
215 #define SPECENUM_VALUE79 EFT_VISIBLE_WALLS
216 #define SPECENUM_VALUE79NAME "Visible_Walls"
217 #define SPECENUM_VALUE80 EFT_TECH_COST_FACTOR
218 #define SPECENUM_VALUE80NAME "Tech_Cost_Factor"
219 /* [x%] gold upkeep instead of [1] shield upkeep for units */
220 #define SPECENUM_VALUE81 EFT_SHIELD2GOLD_FACTOR
221 #define SPECENUM_VALUE81NAME "Shield2Gold_Factor"
222 #define SPECENUM_VALUE82 EFT_TILE_WORKABLE
223 #define SPECENUM_VALUE82NAME "Tile_Workable"
224 /* The index for the city image of the given city style. */
225 #define SPECENUM_VALUE83 EFT_CITY_IMAGE
226 #define SPECENUM_VALUE83NAME "City_Image"
227 #define SPECENUM_VALUE84 EFT_IRRIG_POSSIBLE
228 #define SPECENUM_VALUE84NAME "Irrig_Possible"
229 #define SPECENUM_VALUE85 EFT_MAX_TRADE_ROUTES
230 #define SPECENUM_VALUE85NAME "Max_Trade_Routes"
231 #define SPECENUM_VALUE86 EFT_GOV_CENTER
232 #define SPECENUM_VALUE86NAME "Gov_Center"
233 #define SPECENUM_VALUE87 EFT_TRANSFORM_POSSIBLE
234 #define SPECENUM_VALUE87NAME "Transform_Possible"
235 #define SPECENUM_VALUE88 EFT_MINING_POSSIBLE
236 #define SPECENUM_VALUE88NAME "Mining_Possible"
237 #define SPECENUM_VALUE89 EFT_IRRIG_TF_POSSIBLE
238 #define SPECENUM_VALUE89NAME "Irrig_TF_Possible"
239 #define SPECENUM_VALUE90 EFT_MINING_TF_POSSIBLE
240 #define SPECENUM_VALUE90NAME "Mining_TF_Possible"
241 #define SPECENUM_VALUE91 EFT_NOT_TECH_SOURCE
242 #define SPECENUM_VALUE91NAME "Not_Tech_Source"
243 #define SPECENUM_VALUE92 EFT_ENEMY_CITIZEN_UNHAPPY_PCT
244 #define SPECENUM_VALUE92NAME "Enemy_Citizen_Unhappy_Pct"
245 /* keep this last */
246 #define SPECENUM_VALUE93 EFT_LAST
247 #include "specenum_gen.h"
249 /* An effect is provided by a source. If the source is present, and the
250 * other conditions (described below) are met, the effect will be active.
251 * Note the difference between effect and effect_type. */
252 struct effect {
253 enum effect_type type;
255 /* The "value" of the effect. The meaning of this varies between
256 * effects. When get_xxx_bonus() is called the value of all applicable
257 * effects will be summed up. */
258 int value;
260 /* An effect can have multiple requirements. The effect will only be
261 * active if all of these requirement are met. */
262 struct requirement_list *reqs;
264 /* An effect can have multiple negated requirements. The effect will
265 * only be active if none of these requirements are met. */
266 struct requirement_list *nreqs;
269 /* An effect_list is a list of effects. */
270 #define SPECLIST_TAG effect
271 #define SPECLIST_TYPE struct effect
272 #include "speclist.h"
273 #define effect_list_iterate(effect_list, peffect) \
274 TYPED_LIST_ITERATE(struct effect, effect_list, peffect)
275 #define effect_list_iterate_end LIST_ITERATE_END
277 struct effect *effect_new(enum effect_type type, int value);
278 void effect_req_append(struct effect *peffect, bool neg,
279 struct requirement *preq);
281 struct astring;
282 void get_effect_req_text(const struct effect *peffect,
283 char *buf, size_t buf_len);
284 void get_effect_list_req_text(const struct effect_list *plist,
285 struct astring *astr);
287 /* ruleset cache creation and communication functions */
288 struct packet_ruleset_effect;
289 struct packet_ruleset_effect_req;
291 void ruleset_cache_init(void);
292 void ruleset_cache_free(void);
293 void recv_ruleset_effect(const struct packet_ruleset_effect *packet);
294 void recv_ruleset_effect_req(const struct packet_ruleset_effect_req *packet);
295 void send_ruleset_cache(struct conn_list *dest);
297 int effect_cumulative_max(enum effect_type type, struct unit_type *for_unit);
298 int effect_cumulative_min(enum effect_type type, struct unit_type *for_unit);
300 bool is_effect_useful(const struct player *target_player,
301 const struct city *target_pcity,
302 const struct impr_type *target_building,
303 const struct tile *target_tile,
304 const struct unit_type *target_unittype,
305 const struct output_type *target_output,
306 const struct specialist *target_specialist,
307 const struct impr_type *source,
308 const struct effect *effect,
309 const enum req_problem_type prob_type);
311 bool is_building_replaced(const struct city *pcity,
312 struct impr_type *pimprove,
313 const enum req_problem_type prob_type);
315 /* functions to know the bonuses a certain effect is granting */
316 int get_world_bonus(enum effect_type effect_type);
317 int get_player_bonus(const struct player *plr, enum effect_type effect_type);
318 int get_city_bonus(const struct city *pcity, enum effect_type effect_type);
319 int get_city_specialist_output_bonus(const struct city *pcity,
320 const struct specialist *pspecialist,
321 const struct output_type *poutput,
322 enum effect_type effect_type);
323 int get_city_tile_output_bonus(const struct city *pcity,
324 const struct tile *ptile,
325 const struct output_type *poutput,
326 enum effect_type effect_type);
327 int get_player_output_bonus(const struct player *pplayer,
328 const struct output_type *poutput,
329 enum effect_type effect_type);
330 int get_city_output_bonus(const struct city *pcity,
331 const struct output_type *poutput,
332 enum effect_type effect_type);
333 int get_building_bonus(const struct city *pcity,
334 const struct impr_type *building,
335 enum effect_type effect_type);
336 int get_unittype_bonus(const struct player *pplayer,
337 const struct tile *ptile, /* pcity is implied */
338 const struct unit_type *punittype,
339 enum effect_type effect_type);
340 int get_unit_bonus(const struct unit *punit, enum effect_type effect_type);
341 int get_tile_bonus(const struct tile *ptile, const struct unit *punit,
342 enum effect_type etype);
344 /* miscellaneous auxiliary effects functions */
345 struct effect_list *get_req_source_effects(struct universal *psource);
346 bool is_effect_disabled(const struct player *target_player,
347 const struct city *target_city,
348 const struct impr_type *target_building,
349 const struct tile *target_tile,
350 const struct unit_type *target_unittype,
351 const struct output_type *target_output,
352 const struct specialist *target_specialist,
353 const struct effect *peffect,
354 const enum req_problem_type prob_type);
356 int get_player_bonus_effects(struct effect_list *plist,
357 const struct player *pplayer, enum effect_type effect_type);
358 int get_city_bonus_effects(struct effect_list *plist,
359 const struct city *pcity,
360 const struct output_type *poutput,
361 enum effect_type effect_type);
363 int get_target_bonus_effects(struct effect_list *plist,
364 const struct player *target_player,
365 const struct city *target_city,
366 const struct impr_type *target_building,
367 const struct tile *target_tile,
368 const struct unit_type *target_unittype,
369 const struct output_type *target_output,
370 const struct specialist *target_specialist,
371 enum effect_type effect_type);
373 bool building_has_effect(const struct impr_type *pimprove,
374 enum effect_type effect_type);
375 int get_current_construction_bonus(const struct city *pcity,
376 enum effect_type effect_type,
377 const enum req_problem_type prob_type);
379 struct effect_list *get_effects(enum effect_type effect_type);
381 typedef bool (*iec_cb)(const struct effect*);
382 bool iterate_effect_cache(iec_cb cb);
384 #ifdef __cplusplus
386 #endif /* __cplusplus */
388 #endif /* FC__EFFECTS_H */