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