Replace the Unbribable_Units effect with the Bribe Unit action enabler
[freeciv.git] / common / effects.h
blobd19fa2083893a9030d46dfb9cc71908f40367c80
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_REVOLUTION_UNHAPPINESS
169 #define SPECENUM_VALUE60NAME "Revolution_Unhappiness"
170 #define SPECENUM_VALUE61 EFT_HAS_SENATE
171 #define SPECENUM_VALUE61NAME "Has_Senate"
172 #define SPECENUM_VALUE62 EFT_INSPIRE_PARTISANS
173 #define SPECENUM_VALUE62NAME "Inspire_Partisans"
174 #define SPECENUM_VALUE63 EFT_HAPPINESS_TO_GOLD
175 #define SPECENUM_VALUE63NAME "Happiness_To_Gold"
176 /* stupid special case; we hate it */
177 #define SPECENUM_VALUE64 EFT_FANATICS
178 #define SPECENUM_VALUE64NAME "Fanatics"
179 #define SPECENUM_VALUE65 EFT_NO_DIPLOMACY
180 #define SPECENUM_VALUE65NAME "No_Diplomacy"
181 #define SPECENUM_VALUE66 EFT_TRADE_REVENUE_BONUS
182 #define SPECENUM_VALUE66NAME "Trade_Revenue_Bonus"
183 /* multiply unhappy upkeep by this effect */
184 #define SPECENUM_VALUE67 EFT_UNHAPPY_FACTOR
185 #define SPECENUM_VALUE67NAME "Unhappy_Factor"
186 /* multiply upkeep by this effect */
187 #define SPECENUM_VALUE68 EFT_UPKEEP_FACTOR
188 #define SPECENUM_VALUE68NAME "Upkeep_Factor"
189 /* this many units are free from upkeep */
190 #define SPECENUM_VALUE69 EFT_UNIT_UPKEEP_FREE_PER_CITY
191 #define SPECENUM_VALUE69NAME "Unit_Upkeep_Free_Per_City"
192 #define SPECENUM_VALUE70 EFT_OUTPUT_WASTE
193 #define SPECENUM_VALUE70NAME "Output_Waste"
194 #define SPECENUM_VALUE71 EFT_OUTPUT_WASTE_BY_DISTANCE
195 #define SPECENUM_VALUE71NAME "Output_Waste_By_Distance"
196 /* -1 penalty to tiles producing more than this */
197 #define SPECENUM_VALUE72 EFT_OUTPUT_PENALTY_TILE
198 #define SPECENUM_VALUE72NAME "Output_Penalty_Tile"
199 #define SPECENUM_VALUE73 EFT_OUTPUT_INC_TILE_CELEBRATE
200 #define SPECENUM_VALUE73NAME "Output_Inc_Tile_Celebrate"
201 /* all citizens after this are unhappy */
202 #define SPECENUM_VALUE74 EFT_CITY_UNHAPPY_SIZE
203 #define SPECENUM_VALUE74NAME "City_Unhappy_Size"
204 /* add to default squared city radius */
205 #define SPECENUM_VALUE75 EFT_CITY_RADIUS_SQ
206 #define SPECENUM_VALUE75NAME "City_Radius_Sq"
207 /* number of build slots for units */
208 #define SPECENUM_VALUE76 EFT_CITY_BUILD_SLOTS
209 #define SPECENUM_VALUE76NAME "City_Build_Slots"
210 #define SPECENUM_VALUE77 EFT_UPGRADE_PRICE_PCT
211 #define SPECENUM_VALUE77NAME "Upgrade_Price_Pct"
212 /* City should use walls gfx */
213 #define SPECENUM_VALUE78 EFT_VISIBLE_WALLS
214 #define SPECENUM_VALUE78NAME "Visible_Walls"
215 #define SPECENUM_VALUE79 EFT_TECH_COST_FACTOR
216 #define SPECENUM_VALUE79NAME "Tech_Cost_Factor"
217 /* [x%] gold upkeep instead of [1] shield upkeep for units */
218 #define SPECENUM_VALUE80 EFT_SHIELD2GOLD_FACTOR
219 #define SPECENUM_VALUE80NAME "Shield2Gold_Factor"
220 #define SPECENUM_VALUE81 EFT_TILE_WORKABLE
221 #define SPECENUM_VALUE81NAME "Tile_Workable"
222 /* The index for the city image of the given city style. */
223 #define SPECENUM_VALUE82 EFT_CITY_IMAGE
224 #define SPECENUM_VALUE82NAME "City_Image"
225 #define SPECENUM_VALUE83 EFT_IRRIG_POSSIBLE
226 #define SPECENUM_VALUE83NAME "Irrig_Possible"
227 #define SPECENUM_VALUE84 EFT_MAX_TRADE_ROUTES
228 #define SPECENUM_VALUE84NAME "Max_Trade_Routes"
229 #define SPECENUM_VALUE85 EFT_GOV_CENTER
230 #define SPECENUM_VALUE85NAME "Gov_Center"
231 #define SPECENUM_VALUE86 EFT_TRANSFORM_POSSIBLE
232 #define SPECENUM_VALUE86NAME "Transform_Possible"
233 #define SPECENUM_VALUE87 EFT_MINING_POSSIBLE
234 #define SPECENUM_VALUE87NAME "Mining_Possible"
235 #define SPECENUM_VALUE88 EFT_IRRIG_TF_POSSIBLE
236 #define SPECENUM_VALUE88NAME "Irrig_TF_Possible"
237 #define SPECENUM_VALUE89 EFT_MINING_TF_POSSIBLE
238 #define SPECENUM_VALUE89NAME "Mining_TF_Possible"
239 #define SPECENUM_VALUE90 EFT_NOT_TECH_SOURCE
240 #define SPECENUM_VALUE90NAME "Not_Tech_Source"
241 #define SPECENUM_VALUE91 EFT_ENEMY_CITIZEN_UNHAPPY_PCT
242 #define SPECENUM_VALUE91NAME "Enemy_Citizen_Unhappy_Pct"
243 #define SPECENUM_VALUE92 EFT_IRRIGATION_PCT
244 #define SPECENUM_VALUE92NAME "Irrigation_Pct"
245 #define SPECENUM_VALUE93 EFT_MINING_PCT
246 #define SPECENUM_VALUE93NAME "Mining_Pct"
247 #define SPECENUM_VALUE94 EFT_OUTPUT_TILE_PUNISH_PCT
248 #define SPECENUM_VALUE94NAME "Output_Tile_Punish_Pct"
249 #define SPECENUM_VALUE95 EFT_UNIT_BRIBE_COST_PCT
250 #define SPECENUM_VALUE95NAME "Unit_Bribe_Cost_Pct"
251 #define SPECENUM_VALUE96 EFT_VICTORY
252 #define SPECENUM_VALUE96NAME "Victory"
253 #define SPECENUM_VALUE97 EFT_PERFORMANCE
254 #define SPECENUM_VALUE97NAME "Performance"
255 #define SPECENUM_VALUE98 EFT_HISTORY
256 #define SPECENUM_VALUE98NAME "History"
257 /* keep this last */
258 #define SPECENUM_COUNT EFT_COUNT
259 #include "specenum_gen.h"
261 /* An effect is provided by a source. If the source is present, and the
262 * other conditions (described below) are met, the effect will be active.
263 * Note the difference between effect and effect_type. */
264 struct effect {
265 enum effect_type type;
267 /* The "value" of the effect. The meaning of this varies between
268 * effects. When get_xxx_bonus() is called the value of all applicable
269 * effects will be summed up. */
270 int value;
272 /* An effect can have multiple requirements. The effect will only be
273 * active if all of these requirement are met. */
274 struct requirement_list *reqs;
276 /* An effect can have multiple negated requirements. The effect will
277 * only be active if none of these requirements are met. */
278 struct requirement_list *nreqs;
281 /* An effect_list is a list of effects. */
282 #define SPECLIST_TAG effect
283 #define SPECLIST_TYPE struct effect
284 #include "speclist.h"
285 #define effect_list_iterate(effect_list, peffect) \
286 TYPED_LIST_ITERATE(struct effect, effect_list, peffect)
287 #define effect_list_iterate_end LIST_ITERATE_END
289 struct effect *effect_new(enum effect_type type, int value);
290 void effect_req_append(struct effect *peffect, bool neg,
291 struct requirement *preq);
293 void get_effect_req_text(struct effect *peffect, char *buf, size_t buf_len);
295 /* ruleset cache creation and communication functions */
296 struct packet_ruleset_effect;
297 struct packet_ruleset_effect_req;
299 void ruleset_cache_init(void);
300 void ruleset_cache_free(void);
301 void recv_ruleset_effect(const struct packet_ruleset_effect *packet);
302 void recv_ruleset_effect_req(const struct packet_ruleset_effect_req *packet);
303 void send_ruleset_cache(struct conn_list *dest);
305 int effect_cumulative_max(enum effect_type type);
306 int effect_cumulative_min(enum effect_type type);
308 bool is_effect_useful(const struct player *target_player,
309 const struct player *other_player,
310 const struct city *target_pcity,
311 const struct impr_type *target_building,
312 const struct tile *target_tile,
313 const struct unit_type *target_unittype,
314 const struct output_type *target_output,
315 const struct specialist *target_specialist,
316 const struct impr_type *source,
317 const struct effect *effect,
318 const enum req_problem_type prob_type);
320 bool is_building_replaced(const struct city *pcity,
321 struct impr_type *pimprove,
322 const enum req_problem_type prob_type);
324 /* functions to know the bonuses a certain effect is granting */
325 int get_world_bonus(enum effect_type effect_type);
326 int get_player_bonus(const struct player *plr, enum effect_type effect_type);
327 int get_city_bonus(const struct city *pcity, enum effect_type effect_type);
328 int get_city_specialist_output_bonus(const struct city *pcity,
329 const struct specialist *pspecialist,
330 const struct output_type *poutput,
331 enum effect_type effect_type);
332 int get_city_tile_output_bonus(const struct city *pcity,
333 const struct tile *ptile,
334 const struct output_type *poutput,
335 enum effect_type effect_type);
336 int get_player_output_bonus(const struct player *pplayer,
337 const struct output_type *poutput,
338 enum effect_type effect_type);
339 int get_city_output_bonus(const struct city *pcity,
340 const struct output_type *poutput,
341 enum effect_type effect_type);
342 int get_building_bonus(const struct city *pcity,
343 const struct impr_type *building,
344 enum effect_type effect_type);
345 int get_unittype_bonus(const struct player *pplayer,
346 const struct tile *ptile, /* pcity is implied */
347 const struct unit_type *punittype,
348 enum effect_type effect_type);
349 int get_unit_bonus(const struct unit *punit, enum effect_type effect_type);
350 int get_tile_bonus(const struct tile *ptile, const struct unit *punit,
351 enum effect_type etype);
353 /* miscellaneous auxiliary effects functions */
354 struct effect_list *get_req_source_effects(struct universal *psource);
355 bool is_effect_disabled(const struct player *target_player,
356 const struct player *other_player,
357 const struct city *target_city,
358 const struct impr_type *target_building,
359 const struct tile *target_tile,
360 const struct unit_type *target_unittype,
361 const struct output_type *target_output,
362 const struct specialist *target_specialist,
363 const struct effect *peffect,
364 const enum req_problem_type prob_type);
366 int get_player_bonus_effects(struct effect_list *plist,
367 const struct player *pplayer, enum effect_type effect_type);
368 int get_city_bonus_effects(struct effect_list *plist,
369 const struct city *pcity,
370 const struct output_type *poutput,
371 enum effect_type effect_type);
373 int get_target_bonus_effects(struct effect_list *plist,
374 const struct player *target_player,
375 const struct player *other_player,
376 const struct city *target_city,
377 const struct impr_type *target_building,
378 const struct tile *target_tile,
379 const struct unit_type *target_unittype,
380 const struct output_type *target_output,
381 const struct specialist *target_specialist,
382 enum effect_type effect_type);
384 bool building_has_effect(const struct impr_type *pimprove,
385 enum effect_type effect_type);
386 int get_current_construction_bonus(const struct city *pcity,
387 enum effect_type effect_type,
388 const enum req_problem_type prob_type);
390 struct effect_list *get_effects(enum effect_type effect_type);
392 typedef bool (*iec_cb)(const struct effect*, void *data);
393 bool iterate_effect_cache(iec_cb cb, void *data);
395 #ifdef __cplusplus
397 #endif /* __cplusplus */
399 #endif /* FC__EFFECTS_H */