Skip to content

Commit

Permalink
Expand the city dialog text for nationality
Browse files Browse the repository at this point in the history
Explain the rules and give the result of the calculation. The rule sentence is
not fully correct but it's easier to understand than the actual mechanism.
Hopefully helps with longturn#269.
  • Loading branch information
lmoureaux committed Aug 7, 2022
1 parent d115cfc commit 7055e35
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 26 deletions.
73 changes: 48 additions & 25 deletions client/text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "clientutils.h"
#include "combat.h"
#include "culture.h"
#include "effects.h"
#include "fc_types.h" // LINE_BREAK
#include "game.h"
#include "government.h"
Expand Down Expand Up @@ -1388,42 +1389,64 @@ QString text_happiness_buildings(const struct city *pcity)
}

/**
Describing nationality effects that affect happiness.
* Describing nationality effects that affect happiness.
*/
const QString text_happiness_nationality(const struct city *pcity)
QString text_happiness_nationality(const struct city *pcity)
{
QString str;
int enemies = 0;
if (auto effects = get_effects(EFT_ENEMY_CITIZEN_UNHAPPY_PCT);
!game.info.citizen_nationality || effect_list_size(effects) == 0) {
// Disabled in the ruleset
effect_list_destroy(effects);
return QString();
}

str = _("Nationality: ") + qendl();
auto str = QStringLiteral("<p>");
str +=
_("The presence of enemy citizens can create additional unhappiness.");
str += QStringLiteral(" ");

if (game.info.citizen_nationality) {
if (get_city_bonus(pcity, EFT_ENEMY_CITIZEN_UNHAPPY_PCT) > 0) {
struct player *owner = city_owner(pcity);
int pct = get_city_bonus(pcity, EFT_ENEMY_CITIZEN_UNHAPPY_PCT);
if (pct == 0) {
str += _("However, it is not the case in this city.");
return str + QStringLiteral("</p>");
}

citizens_foreign_iterate(pcity, pslot, nationality)
{
if (pplayers_at_war(owner, player_slot_get_player(pslot))) {
enemies += nationality;
}
}
citizens_foreign_iterate_end;
// This is not exactly correct, but gives a first idea.
int num = std::ceil(100. / pct);
str += QString(PL_("For every %1 citizen of an enemy nation, one citizen "
"becomes unhappy.",
"For every %1 citizens of an enemy nation, one citizen "
"becomes unhappy.",
num))
.arg(num);
str += QStringLiteral("</p><p>");

if (enemies > 0) {
str += QString(PL_("%1 enemy nationalist", "%1 enemy nationalists",
enemies))
.arg(QString::number(enemies));
}
int enemies = 0;
const auto owner = city_owner(pcity);
citizens_foreign_iterate(pcity, pslot, nationality)
{
if (pplayers_at_war(owner, player_slot_get_player(pslot))) {
enemies += nationality;
}
}
citizens_foreign_iterate_end;

if (enemies == 0) {
str += QString(_("None."));
}
if (enemies == 0) {
str += _("There is <b>no enemy citizen</b> in this city.");
} else {
str += QString(_("Disabled."));
auto unhappy = enemies * pct / 100;
// TRANS: Pluralized on "enemy citizen"
str +=
QString(PL_("There is %1 enemy citizen in this city, resulting in "
"<b>%2 additional unhappy.</b>",
"There are %1 enemy citizens in this city, resulting "
"in <b>%2 additional unhappy.</b>",
enemies))
.arg(enemies)
.arg(unhappy);
}

return str.trimmed();
return str + QStringLiteral("</p>");
}

/**
Expand Down
2 changes: 1 addition & 1 deletion client/text.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ const QString act_sel_action_tool_tip(const struct action *paction,
const struct act_prob prob);

QString text_happiness_buildings(const struct city *pcity);
const QString text_happiness_nationality(const struct city *pcity);
QString text_happiness_nationality(const struct city *pcity);
QString text_happiness_cities(const struct city *pcity);
QString text_happiness_luxuries(const struct city *pcity);
const QString text_happiness_units(const struct city *pcity);
Expand Down

0 comments on commit 7055e35

Please sign in to comment.