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.

The max length of the demography string is 15, so not all will fit.
Something like 'nciAaPEgRmOCqrb' still does, though.

Idea from Hans Lemurson: http://forum.freeciv.org/f/viewtopic.php?f=13&t=90396
  • Loading branch information
itvirta committed Nov 11, 2020
1 parent 3b9ed95 commit d5888ea
Show file tree
Hide file tree
Showing 4 changed files with 116 additions and 12 deletions.
4 changes: 4 additions & 0 deletions common/player.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,15 +86,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: 88 additions & 8 deletions server/report.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,30 +130,39 @@ struct city_score_entry {
int value;
};

static int get_great_wonders(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 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);

#define GOOD_PLAYER(p) ((p)->is_alive && !is_barbarian(p))
Expand All @@ -172,13 +181,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 },
{'O', N_("Pollution"), get_pollution, pollution_to_text, FALSE },
Expand Down Expand Up @@ -528,6 +541,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 @@ -544,6 +565,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 @@ -576,6 +605,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 @@ -621,9 +666,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 @@ -855,6 +900,16 @@ 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 */
return value_units(value, PL_(" M bushels", " M bushels", value));
}

/**************************************************************************
Construct string containing value followed by unit suitable for
science stats.
Expand All @@ -864,6 +919,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 All @@ -873,8 +937,6 @@ static const char *mil_service_to_text(int value)
return value_units(value, PL_(" month", " months", value));
}



/**************************************************************************
Construct string containing value followed by unit suitable for
pollution stats.
Expand All @@ -900,7 +962,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 All @@ -921,6 +983,24 @@ static const char *cities_to_text(int value)
return value_units(value, PL_(" city", " cities", 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 @@ -1386,7 +1466,7 @@ void log_civ_score_now(void)
{"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 @@ -1603,7 +1683,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
18 changes: 17 additions & 1 deletion server/score.c
Original file line number Diff line number Diff line change
Expand Up @@ -264,14 +264,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 @@ -294,8 +298,20 @@ 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.c
Original file line number Diff line number Diff line change
Expand Up @@ -2868,12 +2868,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"
" O = include Pollution\n"
Expand Down

0 comments on commit d5888ea

Please sign in to comment.