Skip to content

Commit

Permalink
Add new demographics
Browse files Browse the repository at this point in the history
- Scores showup in demographics
- A new score for league games in lt.net
Score = N_techs^1. 7 + N_units_built + 3xN_units_killedx[N_units_killed/(N_units_lost+1)]^0.5

Ported from: longturn/freeciv@4cc9e68e05
  • Loading branch information
psampathkumar authored and jwrober committed Aug 4, 2022
1 parent 9b8f160 commit c3ffa9b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
31 changes: 31 additions & 0 deletions server/report.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

#include <cstdio>
#include <cstring>
#include <math.h>

// utility
#include "bitvector.h"
Expand Down Expand Up @@ -128,6 +129,8 @@ struct city_score_entry {
int value;
};

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);
Expand Down Expand Up @@ -157,6 +160,7 @@ 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 *mil_units_to_text(int value);
static const char *score_to_text(int value);

#define GOOD_PLAYER(p) ((p)->is_alive && !is_barbarian(p))

Expand All @@ -170,6 +174,9 @@ static struct dem_row {
const char *(*to_text)(int);
bool greater_values_are_better;
} rowtable[] = {
{'s', N_("Score"), get_total_score, score_to_text, true},
{'z', N_("League Score"), get_league_score, score_to_text,
true}, // z cuz inverted s. B)
{'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},
Expand Down Expand Up @@ -814,6 +821,21 @@ static int get_total_score(const struct player *pplayer)
return pplayer->score.game;
}

/**
League score
Score = N_techs^1. 7 + N_units_built +
3xN_units_killedx[N_units_killed/(N_units_lost+1)]^0.5
*/
static int get_league_score(const struct player *pplayer)
{
return (int) (pow((double) pplayer->score.techs, 1.7)
+ pplayer->score.units_built
+ (3 * pplayer->score.units_killed
* pow((double) pplayer->score.units_killed
/ (pplayer->score.units_lost + 1),
0.5)));
}

/**
Culture score
*/
Expand Down Expand Up @@ -940,6 +962,15 @@ 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
score stats.
*/
static const char *score_to_text(int value)
{
return value_units(value, PL_(" point", " points", value));
}

/**
Construct one demographics line.
*/
Expand Down
2 changes: 2 additions & 0 deletions server/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2816,6 +2816,8 @@ static struct setting settings[] = {
"the inclusion of a line of information in the Demographics "
"report.\n"
"The characters and their meanings are:\n"
" s = include Score\n"
" z = include League Score\n"
" N = include Population\n"
" n = include Population in Citizen Units\n"
" c = include Cities\n"
Expand Down

0 comments on commit c3ffa9b

Please sign in to comment.