Skip to content

Commit

Permalink
Add the ability to turn trade into pollution
Browse files Browse the repository at this point in the history
This adds a Pollu_Trade_Pct effect that can be used to generate
pollution from trade. This may be more realistic for trade-based
governments like Democracy.

Requested by Hawk.
Closes #2446.
  • Loading branch information
lmoureaux authored and jwrober committed Dec 24, 2024
1 parent 691af7b commit ecd7c71
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 14 deletions.
3 changes: 2 additions & 1 deletion ai/default/daicity.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1479,7 +1479,8 @@ adv_want dai_city_want(struct player *pplayer, struct city *acity,
want += prod[O_FOOD] * adv->food_priority;
if (prod[O_SHIELD] != 0) {
want += prod[O_SHIELD] * adv->shield_priority;
want -= city_pollution(acity, prod[O_SHIELD]) * adv->pollution_priority;
want -= city_pollution(acity, prod[O_SHIELD], prod[O_TRADE])
* adv->pollution_priority;
}
want += prod[O_LUXURY] * adv->luxury_priority;
want += prod[O_SCIENCE] * adv->science_priority;
Expand Down
1 change: 1 addition & 0 deletions ai/default/daieffects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ adv_want dai_effect_value(struct player *pplayer, struct government *gov,
case EFT_POLLU_POP_PCT:
case EFT_POLLU_POP_PCT_2:
case EFT_POLLU_PROD_PCT:
case EFT_POLLU_TRADE_PCT:
case EFT_OUTPUT_BONUS:
case EFT_OUTPUT_BONUS_2:
case EFT_OUTPUT_ADD_TILE:
Expand Down
6 changes: 4 additions & 2 deletions client/citydlg_common.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -666,16 +666,18 @@ QString get_city_dialog_illness_text(const struct city *pcity)
*/
QString get_city_dialog_pollution_text(const struct city *pcity)
{
int pollu, prod, pop, mod;
int pollu, prod, trade, pop, mod;
struct city_sum *sum = city_sum_new(Q_("?city_pollution:%+4.0f : %s"));

/* On the server, pollution is calculated before production is deducted
* for disorder; we need to compensate for that */
pollu = city_pollution_types(
pcity, pcity->prod[O_SHIELD] + pcity->unhappy_penalty[O_SHIELD], &prod,
pcity, pcity->prod[O_SHIELD] + pcity->unhappy_penalty[O_SHIELD],
pcity->prod[O_TRADE] + pcity->unhappy_penalty[O_TRADE], &prod, &trade,
&pop, &mod);

city_sum_add(sum, prod, Q_("?city_pollution:Pollution from shields"));
city_sum_add(sum, trade, Q_("?city_pollution:Pollution from trade"));
city_sum_add(sum, pop, Q_("?city_pollution:Pollution from citizens"));
city_sum_add(sum, mod, Q_("?city_pollution:Pollution modifier"));
return city_sum_print(sum, false,
Expand Down
28 changes: 19 additions & 9 deletions common/city.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2649,14 +2649,19 @@ static inline void unhappy_city_check(struct city *pcity)
Calculate the pollution from production and population in the city.
*/
int city_pollution_types(const struct city *pcity, int shield_total,
int *pollu_prod, int *pollu_pop, int *pollu_mod)
int trade_total, int *pollu_prod, int *pollu_trade,
int *pollu_pop, int *pollu_mod)
{
int prod, pop, mod;
int prod, trade, pop, mod;

// Add one one pollution per shield, multipled by the bonus.
prod = 100 + get_city_bonus(pcity, EFT_POLLU_PROD_PCT);
prod = shield_total * MAX(prod, 0) / 100;

// Add pollution per trade, multipled by the effect.
trade = get_city_bonus(pcity, EFT_POLLU_TRADE_PCT);
trade = trade_total * MAX(trade, 0) / 100;

// Add one pollution per citizen for baseline combined bonus (100%).
pop = (100 + get_city_bonus(pcity, EFT_POLLU_POP_PCT))
* (100 + get_city_bonus(pcity, EFT_POLLU_POP_PCT_2)) / 100;
Expand All @@ -2668,23 +2673,27 @@ int city_pollution_types(const struct city *pcity, int shield_total,
if (pollu_prod) {
*pollu_prod = prod;
}
if (pollu_trade) {
*pollu_trade = trade;
}
if (pollu_pop) {
*pollu_pop = pop;
}
if (pollu_mod) {
*pollu_mod = mod;
}
return MAX(prod + pop + mod, 0);
return MAX(prod + trade + pop + mod, 0);
}

/**
Calculate pollution for the city. The shield_total must be passed in
(most callers will want to pass pcity->shield_prod).
Calculate pollution for the city. The shield_total and trade_total must
be passed in (most callers will want to pass pcity->shield_prod).
*/
int city_pollution(const struct city *pcity, int shield_total)
int city_pollution(const struct city *pcity, int shield_total,
int trade_total)
{
return city_pollution_types(pcity, shield_total, nullptr, nullptr,
nullptr);
return city_pollution_types(pcity, shield_total, trade_total, nullptr,
nullptr, nullptr, nullptr);
}

/**
Expand Down Expand Up @@ -3065,7 +3074,8 @@ void city_refresh_from_main_map(
citizen_base_mood(pcity);
/* Note that pollution is calculated before unhappy_city_check() makes
* deductions for disorder; so a city in disorder still causes pollution */
pcity->pollution = city_pollution(pcity, pcity->prod[O_SHIELD]);
pcity->pollution =
city_pollution(pcity, pcity->prod[O_SHIELD], pcity->prod[O_TRADE]);

happy_copy(pcity, FEELING_LUXURY);
citizen_happy_luxury(pcity); // with our new found luxuries
Expand Down
6 changes: 4 additions & 2 deletions common/city.h
Original file line number Diff line number Diff line change
Expand Up @@ -733,8 +733,10 @@ void city_styles_free();
void add_tax_income(const struct player *pplayer, int trade, int *output);
int get_city_tithes_bonus(const struct city *pcity);
int city_pollution_types(const struct city *pcity, int shield_total,
int *pollu_prod, int *pollu_pop, int *pollu_mod);
int city_pollution(const struct city *pcity, int shield_total);
int trade_total, int *pollu_prod, int *pollu_trade,
int *pollu_pop, int *pollu_mod);
int city_pollution(const struct city *pcity, int shield_total,
int trade_total);
int city_illness_calc(const struct city *pcity, int *ill_base, int *ill_size,
int *ill_trade, int *ill_pollution);
bool city_had_recent_plague(const struct city *pcity);
Expand Down
1 change: 1 addition & 0 deletions common/effects.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1074,6 +1074,7 @@ QString effect_type_unit_text(effect_type type, int value)
case EFT_POLLU_POP_PCT:
case EFT_POLLU_POP_PCT_2:
case EFT_POLLU_PROD_PCT:
case EFT_POLLU_TRADE_PCT:
case EFT_INCITE_COST_PCT:
case EFT_SPY_RESISTANT:
case EFT_VETERAN_COMBAT:
Expand Down
2 changes: 2 additions & 0 deletions common/effects.h
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,8 @@
#define SPECENUM_VALUE134NAME "Nuke_Infrastructure_Pct"
#define SPECENUM_VALUE135 EFT_GROWTH_SURPLUS_PCT
#define SPECENUM_VALUE135NAME "Growth_Surplus_Pct"
#define SPECENUM_VALUE136 EFT_POLLU_TRADE_PCT
#define SPECENUM_VALUE136NAME "Pollu_Trade_Pct"
// keep this last
#define SPECENUM_COUNT EFT_COUNT
#include "specenum_gen.h"
Expand Down
5 changes: 5 additions & 0 deletions docs/Modding/Rulesets/effects.rst
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,11 @@ Pollu_Pop_Pct_2
i.e. 1 pollution per citizen). This factor is applied after :ref:`Pollu_Pop_Pct <effect-pollu-pop-pct>`,
so is multiplicative with it.

.. _effect-pollu-trade-pct:

Pollu_Trade_Pct
Each trade generates AMOUNT percent of pollution.

.. _effect-pollu-prod-pct:

Pollu_Prod_Pct
Expand Down

0 comments on commit ecd7c71

Please sign in to comment.