Skip to content

Commit

Permalink
Add more useful demographics
Browse files Browse the repository at this point in the history
'i' - Improvements: total number of normal improvements in all cities
'a' - Agriculture: total food surplus (after consumption and upkeep)
'g' - Gold Income: total gold income (before upkeep costs)
'w' - Wonders: total number of wonders, Great and small.

Agriculture value takes the surplus after consumption and upkeep like the
Production value also does. Wonders includes Palace as it counts as a small
wonder.

Gold income takes the income _before_ upkeep costs at least for now, since
that number is easier to access. Otherwise all the different
gold_upkeep_style settings would need to be dealt with separately. (Though
player_get_expected_income() could perhaps be used.)

Also, reorder Research after Production and Economy to have the
production values in the same order as shown in the city view.

Idea from Hans Lemurson: http://forum.freeciv.org/f/viewtopic.php?f=13&t=90396

Ported from: longturn/freeciv@d5888eaab4
  • Loading branch information
psampathkumar authored and jwrober committed Aug 4, 2022
1 parent c3ffa9b commit 813d07c
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 10 deletions.
4 changes: 4 additions & 0 deletions common/player.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,19 @@ struct player_score {
int wonders;
int techs;
int techout;
int goldout;
int landarea;
int settledarea;
int population; // in thousand of citizen
int cities;
int improvements;
int all_wonders;
int units;
int pollution;
int literacy;
int bnp;
int mfg;
int food;
int spaceship;
int units_built; // Number of units this player produced.
int units_killed; // Number of enemy units killed.
Expand Down
96 changes: 90 additions & 6 deletions server/report.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,21 +129,26 @@ struct city_score_entry {
int value;
};

static int get_great_wonders(const struct player *pplayer);
static int get_total_score(const struct player *pplayer);
static int get_league_score(const struct player *pplayer);
static int get_population(const struct player *pplayer);
static int get_landarea(const struct player *pplayer);
static int get_settledarea(const struct player *pplayer);
static int get_research(const struct player *pplayer);
static int get_income(const struct player *pplayer);
static int get_production(const struct player *pplayer);
static int get_economics(const struct player *pplayer);
static int get_agriculture(const struct player *pplayer);
static int get_pollution(const struct player *pplayer);
static int get_mil_service(const struct player *pplayer);
static int get_culture(const struct player *pplayer);
static int get_pop(
const struct player
*pplayer); /* this would better be named get_citizenunits or such */
static int get_cities(const struct player *pplayer);
static int get_improvements(const struct player *pplayer);
static int get_all_wonders(const struct player *pplayer);
static int get_mil_units(const struct player *pplayer);
static int get_units_built(const struct player *pplayer);
static int get_units_killed(const struct player *pplayer);
Expand All @@ -153,12 +158,16 @@ static const char *area_to_text(int value);
static const char *percent_to_text(int value);
static const char *production_to_text(int value);
static const char *economics_to_text(int value);
static const char *agriculture_to_text(int value);
static const char *science_to_text(int value);
static const char *income_to_text(int value);
static const char *mil_service_to_text(int value);
static const char *pollution_to_text(int value);
static const char *culture_to_text(int value);
static const char *citizenunits_to_text(int value);
static const char *cities_to_text(int value);
static const char *improvements_to_text(int value);
static const char *wonders_to_text(int value);
static const char *mil_units_to_text(int value);
static const char *score_to_text(int value);

Expand All @@ -180,13 +189,17 @@ static struct dem_row {
{'N', N_("Population"), get_population, population_to_text, true},
{'n', N_("Population"), get_pop, citizenunits_to_text, true},
{'c', N_("Cities"), get_cities, cities_to_text, true},
{'i', N_("Improvements"), get_improvements, improvements_to_text, true},
{'w', N_("Wonders"), get_all_wonders, wonders_to_text, true},
{'A', N_("Land Area"), get_landarea, area_to_text, true},
{'S', N_("Settled Area"), get_settledarea, area_to_text, true},
{'R', N_("Research Speed"), get_research, science_to_text, true},
// TRANS: How literate people are.
{'L', N_("?ability:Literacy"), get_literacy, percent_to_text, true},
{'a', N_("Agriculture"), get_agriculture, agriculture_to_text, true},
{'P', N_("Production"), get_production, production_to_text, true},
{'E', N_("Economics"), get_economics, economics_to_text, true},
{'g', N_("Gold Income"), get_income, income_to_text, true},
{'R', N_("Research Speed"), get_research, science_to_text, true},
{'M', N_("Military Service"), get_mil_service, mil_service_to_text,
false},
{'m', N_("Military Units"), get_mil_units, mil_units_to_text, true},
Expand Down Expand Up @@ -549,6 +562,14 @@ static int get_research(const struct player *pplayer)
return pplayer->score.techout;
}

/**
Gold income
*/
static int get_income(const struct player *pplayer)
{
return pplayer->score.goldout;
}

/**
Production of player
*/
Expand All @@ -565,6 +586,14 @@ static int get_economics(const struct player *pplayer)
return pplayer->score.bnp;
}

/**
Food output
*/
static int get_agriculture(const struct player *pplayer)
{
return pplayer->score.food;
}

/**
Pollution of player
*/
Expand Down Expand Up @@ -597,6 +626,22 @@ static int get_cities(const struct player *pplayer)
return pplayer->score.cities;
}

/**
Number of buildings in cities (not wonders)
*/
static int get_improvements(const struct player *pplayer)
{
return pplayer->score.improvements;
}

/**
All wonders, including small wonders
*/
static int get_all_wonders(const struct player *pplayer)
{
return pplayer->score.all_wonders;
}

/**
Number of techs
*/
Expand Down Expand Up @@ -646,9 +691,9 @@ static int get_settlers(const struct player *pplayer)
}

/**
Wonder score
Great wonders for wonder score
*/
static int get_wonders(const struct player *pplayer)
static int get_great_wonders(const struct player *pplayer)
{
return pplayer->score.wonders;
}
Expand Down Expand Up @@ -898,6 +943,18 @@ static const char *economics_to_text(int value)
return value_units(value, PL_(" M goods", " M goods", value));
}

/**
Construct string containing value followed by unit suitable for
agriculture stats.
*/
static const char *agriculture_to_text(int value)
{
/* TRANS: "M bushels" = million bushels, so always plural */
// FIXME: value can go negative for food

return value_units(value, PL_(" M bushels", " M bushels", value));
}

/**
Construct string containing value followed by unit suitable for
science stats.
Expand All @@ -907,6 +964,15 @@ static const char *science_to_text(int value)
return value_units(value, PL_(" bulb", " bulbs", value));
}

/**
Construct string containing value followed by unit suitable for
gold income stats.
*/
static const char *income_to_text(int value)
{
return value_units(value, PL_(" gold", " gold", value));
}

/**
Construct string containing value followed by unit suitable for
military service stats.
Expand Down Expand Up @@ -941,7 +1007,7 @@ static const char *culture_to_text(int value)
*/
static const char *citizenunits_to_text(int value)
{
return value_units(value, PL_(" citizen unit", " citizen units", value));
return value_units(value, PL_(" citizen", " citizens", value));
}

/**
Expand Down Expand Up @@ -971,6 +1037,24 @@ static const char *score_to_text(int value)
return value_units(value, PL_(" point", " points", value));
}

/**
Construct string containing value followed by unit suitable for
improvement stats.
*/
static const char *improvements_to_text(int value)
{
return value_units(value, PL_(" improvement", " improvements", value));
}

/**
Construct string containing value followed by unit suitable for
wonders stats.
*/
static const char *wonders_to_text(int value)
{
return value_units(value, PL_(" wonder", " wonders", value));
}

/**
Construct one demographics line.
*/
Expand Down Expand Up @@ -1440,7 +1524,7 @@ void log_civ_score_now()
{"munits", get_munits},
{"settlers", get_settlers}, // "original" tags end here

{"wonders", get_wonders},
{"wonders", get_great_wonders},
{"techout", get_techout},
{"landarea", get_landarea},
{"settledarea", get_settledarea},
Expand Down Expand Up @@ -1670,7 +1754,7 @@ void report_final_scores(struct conn_list *dest)
{N_("Cities\n"), get_cities},
{N_("Technologies\n"), get_techs},
{N_("Military Service\n(months)"), get_mil_service},
{N_("Wonders\n"), get_wonders},
{N_("Wonders\n"), get_great_wonders},
{N_("Research Speed\n(bulbs)"), get_research},
// TRANS: "sq. mi." is abbreviation for "square miles"
{N_("Land Area\n(sq. mi.)"), get_landarea},
Expand Down
20 changes: 19 additions & 1 deletion server/score.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,14 +268,18 @@ void calc_civ_score(struct player *pplayer)
pplayer->score.wonders = 0;
pplayer->score.techs = 0;
pplayer->score.techout = 0;
pplayer->score.goldout = 0;
pplayer->score.landarea = 0;
pplayer->score.settledarea = 0;
pplayer->score.population = 0;
pplayer->score.cities = 0;
pplayer->score.improvements = 0;
pplayer->score.all_wonders = 0;
pplayer->score.units = 0;
pplayer->score.pollution = 0;
pplayer->score.bnp = 0;
pplayer->score.mfg = 0;
pplayer->score.food = 0;
pplayer->score.literacy = 0;
pplayer->score.spaceship = 0;
pplayer->score.culture = player_culture(pplayer);
Expand All @@ -301,8 +305,22 @@ void calc_civ_score(struct player *pplayer)
pplayer->score.cities++;
pplayer->score.pollution += pcity->pollution;
pplayer->score.techout += pcity->prod[O_SCIENCE];
/* XXX: BEFORE upkeep paid (consider gold_upkeep_style) */
pplayer->score.goldout += pcity->prod[O_GOLD];
pplayer->score.bnp += pcity->surplus[O_TRADE];
pplayer->score.mfg += pcity->surplus[O_SHIELD];
pplayer->score.mfg += pcity->surplus[O_SHIELD]; /* after upkeep paid */
pplayer->score.food += pcity->surplus[O_FOOD]; /* after upkeep paid */

city_built_iterate(pcity, impr)
{
/* Great wonders are also counted separately */
if (is_improvement(impr)) {
pplayer->score.improvements++;
} else if (is_wonder(impr)) {
pplayer->score.all_wonders++;
}
}
city_built_iterate_end;

bonus = get_final_city_output_bonus(pcity, O_SCIENCE) - 100;
bonus = CLIP(0, bonus, 100);
Expand Down
10 changes: 7 additions & 3 deletions server/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2821,12 +2821,16 @@ static struct setting settings[] = {
" N = include Population\n"
" n = include Population in Citizen Units\n"
" c = include Cities\n"
" P = include Production\n"
" i = include Improvements\n"
" w = include Wonders\n"
" A = include Land Area\n"
" L = include Literacy\n"
" R = include Research Speed\n"
" S = include Settled Area\n"
" L = include Literacy\n"
" a = include Agriculture\n"
" P = include Production\n"
" E = include Economics\n"
" g = include Gold Income\n"
" R = include Research Speed\n"
" M = include Military Service\n"
" m = include Military Units\n"
" u = include Built Units\n"
Expand Down

0 comments on commit 813d07c

Please sign in to comment.