14 #include <fc_config.h>
76 enum event_type
event);
85 #define HISTORIAN_FIRST HISTORIAN_RICHEST
86 #define HISTORIAN_LAST HISTORIAN_LARGEST
90 N_(
"%s %s reports on the RICHEST Civilizations in the World."),
92 N_(
"%s %s reports on the most ADVANCED Civilizations in the World."),
94 N_(
"%s %s reports on the most MILITARIZED Civilizations in the World."),
96 N_(
"%s %s reports on the HAPPIEST Civilizations in the World."),
98 N_(
"%s %s reports on the LARGEST Civilizations in the World.")};
106 N_(
"Pliny the Elder"),
172 #define GOOD_PLAYER(p) ((p)->is_alive && !is_barbarian(p))
181 const char *(*to_text)(int);
220 N_(
"%2d: The Supreme %s"),
222 N_(
"%2d: The Magnificent %s"),
224 N_(
"%2d: The Great %s"),
226 N_(
"%2d: The Glorious %s"),
228 N_(
"%2d: The Excellent %s"),
230 N_(
"%2d: The Eminent %s"),
232 N_(
"%2d: The Distinguished %s"),
234 N_(
"%2d: The Average %s"),
236 N_(
"%2d: The Mediocre %s"),
238 N_(
"%2d: The Ordinary %s"),
240 N_(
"%2d: The Pathetic %s"),
242 N_(
"%2d: The Useless %s"),
244 N_(
"%2d: The Valueless %s"),
246 N_(
"%2d: The Worthless %s"),
248 N_(
"%2d: The Wretched %s"),
266 int i, j = 0, rank = 0;
273 switch (which_news) {
275 size[j].value = pplayer->economic.gold;
282 size[j].value = pplayer->score.units;
285 size[j].value = (((pplayer->score.happy - pplayer->score.unhappy
286 - 2 * pplayer->score.angry)
294 size[j].player = pplayer;
301 report->
body[0] =
'\0';
302 for (i = 0; i < j; i++) {
356 const int NUM_BEST_CITIES = 5;
358 const int WONDER_FACTOR = 5;
363 for (i = 0; i < NUM_BEST_CITIES; i++) {
365 size[i].city =
nullptr;
375 if (value_of_pcity >
size[NUM_BEST_CITIES - 1].
value) {
376 size[NUM_BEST_CITIES - 1].value = value_of_pcity;
377 size[NUM_BEST_CITIES - 1].city = pcity;
386 for (i = 0; i < NUM_BEST_CITIES; i++) {
404 _(
"%2d: The %s City of %s (%s) of size %d, "), i + 1,
410 _(
"%2d: The %s City of %s of size %d, "), i + 1,
417 cat_snprintf(buffer,
sizeof(buffer),
_(
"with no Great Wonders\n"));
420 buffer,
sizeof(buffer),
421 PL_(
"with %d Great Wonder\n",
"with %d Great Wonders\n", wonders),
426 _(
"The Five Greatest Cities in the World!"), buffer);
452 _(
"%s in %s (%s, %s)\n"),
456 qUtf8Printable(team_name));
464 cat_snprintf(buffer,
sizeof(buffer),
_(
"%s has been DESTROYED\n"),
478 if (VUT_IMPROVEMENT == pcity->production.kind
479 && pcity->production.value.building == i) {
487 _(
"(building %s in %s (%s, %s))\n"),
491 qUtf8Printable(team_name));
494 buffer,
sizeof(buffer),
_(
"(building %s in %s (%s))\n"),
507 page_conn(dest,
_(
"Traveler's Report:"),
_(
"Wonders of the World"),
536 return 1000 *
get_pop(pplayer);
789 if (pcity->anarchy > 0) {
852 result += pcity->waste[
O_TRADE];
874 return (
int) (pow((
double) pplayer->
score.
techs, 1.7)
898 qCritical(
"String truncated in value_units()!");
929 int clip =
MAX(0, value);
953 return value_units(value,
PL_(
" M bushels",
" M bushels", value));
1044 return value_units(value,
PL_(
" improvement",
" improvements", value));
1092 struct player *best_player = pplayer;
1093 int best_value =
nullptr != pplayer ? prow->
get_value(pplayer) : 0;
1103 best_player = other;
1110 if (
nullptr == pplayer
1112 && (pplayer != best_player))) {
1130 int len = qstrlen(demography), i;
1134 for (i = 0; i <
len; i++) {
1140 if (demography[i] ==
coltable[j].key) {
1152 if (demography[i] ==
rowtable[j].key) {
1159 if (error !=
nullptr) {
1203 || !anyrows || numcols == 0) {
1205 _(
"Sorry, the Demographics report is unavailable."),
"");
1231 page_conn(pconn->
self,
_(
"Demographics Report:"), civbuf, buffer);
1243 if (pplayer ==
nullptr) {
1292 delete[] plrdata->
name;
1293 plrdata->
name =
nullptr;
1305 int line_nr, turn, plr_no, spaces;
1307 char plr_name[120], line[120], *ptr;
1315 for (line_nr = 1;; line_nr++) {
1320 qCritical(
"[%s:-] Can't read scorelog file header!",
1325 ptr = strchr(line,
'\n');
1327 qCritical(
"[%s:%d] Line too long!",
game.
server.scorefile, line_nr);
1334 qCritical(
"[%s:%d] Bad file magic!",
game.
server.scorefile, line_nr);
1339 if (strncmp(line,
"id ", qstrlen(
"id ")) == 0) {
1340 if (strlen(
id) > 0) {
1341 qCritical(
"[%s:%d] Multiple ID entries!",
game.
server.scorefile,
1346 if (strcmp(
id,
server.game_identifier) != 0) {
1347 qCritical(
"[%s:%d] IDs don't match! game='%s' scorelog='%s'",
1354 if (strncmp(line,
"turn ", qstrlen(
"turn ")) == 0) {
1355 if (sscanf(line + qstrlen(
"turn "),
"%d", &turn) != 1) {
1356 qCritical(
"[%s:%d] Bad line (turn)!",
game.
server.scorefile,
1365 if (strncmp(line,
"addplayer ", qstrlen(
"addplayer ")) == 0) {
1367 != std::sscanf(line + qstrlen(
"addplayer "),
"%d %d %s", &turn,
1368 &plr_no, plr_name)) {
1369 qCritical(
"[%s:%d] Bad line (addplayer)!",
game.
server.scorefile,
1375 ptr = line + qstrlen(
"addplayer ");
1377 while (*ptr !=
'\0' && spaces < 2) {
1383 fc_snprintf(plr_name,
sizeof(plr_name),
"%s", ptr);
1384 log_debug(
"add player '%s' (from line %d: '%s')", plr_name, line_nr,
1388 qCritical(
"[%s:%d] Invalid player number: %d!",
1394 if (plrdata->
name !=
nullptr) {
1395 qCritical(
"[%s:%d] Two names for one player (id %d)!",
1403 if (strncmp(line,
"delplayer ", qstrlen(
"delplayer ")) == 0) {
1405 != sscanf(line + qstrlen(
"delplayer "),
"%d %d", &turn, &plr_no)) {
1406 qCritical(
"[%s:%d] Bad line (delplayer)!",
game.
server.scorefile,
1412 qCritical(
"[%s:%d] Invalid player number: %d!",
1418 if (plrdata->
name ==
nullptr) {
1419 qCritical(
"[%s:%d] Trying to remove undefined player (id %d)!",
1429 qCritical(
"[%s:-] Scorelog contains no turn!",
game.
server.scorefile);
1433 if (strlen(
id) == 0) {
1434 qCritical(
"[%s:-] Scorelog contains no ID!",
game.
server.scorefile);
1439 qCritical(
"[%s:-] Scorelog doesn't match savegame!",
1507 enum { SL_CREATE, SL_APPEND, SL_UNSPEC } oper = SL_UNSPEC;
1513 static const struct {
1515 int (*get_value)(
const struct player *);
1571 goto log_civ_score_disable;
1584 qCritical(
"Can't open scorelog file '%s' for creation!",
1586 goto log_civ_score_disable;
1590 "# For a specification of the format of this "
1591 "see doc/README.scorelog or \n"
1593 "<https://raw.githubusercontent.com/freeciv/"
1594 "freeciv/master/doc/README.scorelog>.\n"
1598 for (i = 0; i <
ARRAY_SIZE(score_tags); i++) {
1599 fprintf(
score_log->
fp,
"tag %d %s\n", i, score_tags[i].name);
1605 qCritical(
"Can't open scorelog file '%s' for appending!",
1607 goto log_civ_score_disable;
1611 qCritical(
"[%s] bad operation %d", __FUNCTION__,
1612 static_cast<int>(oper));
1613 goto log_civ_score_disable;
1647 if (
is_ai(pplayer)) {
1670 if (
is_ai(pplayer) && plrdata->
name ==
nullptr) {
1679 log_debug(
"player names does not match '%s' != '%s'",
1692 for (i = 0; i <
ARRAY_SIZE(score_tags); i++) {
1710 log_civ_score_disable:
1743 static const struct {
1745 int (*score)(
const struct player *);
1746 } score_categories[] = {
1768 const size_t score_categories_num =
ARRAY_SIZE(score_categories);
1772 struct packet_endgame_report packet;
1780 packet.category_num = score_categories_num;
1781 for (j = 0; j < score_categories_num; j++) {
1782 sz_strlcpy(packet.category_name[j], score_categories[j].name);
1789 size[i].value = pplayer->score.game;
1790 size[i].player = pplayer;
1798 packet.player_num = i;
1800 lsend_packet_endgame_report(dest, &packet);
1802 for (i = 0; i < packet.player_num; i++) {
1803 struct packet_endgame_player ppacket;
1804 const struct player *pplayer =
size[i].player;
1806 ppacket.category_num = score_categories_num;
1808 ppacket.score =
size[i].value;
1809 for (j = 0; j < score_categories_num; j++) {
1810 ppacket.category_score[j] = score_categories[j].score(pplayer);
1815 lsend_packet_endgame_player(dest, &ppacket);
1841 enum event_type
event)
1843 struct packet_page_msg packet;
1849 packet.event =
event;
1858 lsend_packet_page_msg(dest, &packet);
1860 for (i = 0; i < packet.parts; i++) {
1861 struct packet_page_msg_part part;
1866 part.lines[plen] =
'\0';
1868 lsend_packet_page_msg_part(dest, &part);
bool achievement_player_has(const struct achievement *pach, const struct player *pplayer)
Has the given player got the achievement?
int get_literacy(const struct player *pplayer)
Literacy score calculated one way.
const char * achievement_name_translation(struct achievement *pach)
Return translated name of this achievement type.
#define achievements_iterate_end
#define achievements_iterate(_ach_)
bool BV_ISSET(const BV &bv, int bit)
const char * calendar_text()
Produce a statically allocated textual representation of the current calendar time.
struct player * city_owner(const struct city *pcity)
Return the owner of the city.
const char * city_name_get(const struct city *pcity)
Return the name of the city.
const char * city_improvement_name_translation(const struct city *pcity, const struct impr_type *pimprove)
Return the extended name of the building.
citizens city_size_get(const struct city *pcity)
Get the city size.
#define city_list_iterate(citylist, pcity)
#define city_list_iterate_end
#define city_built_iterate(_pcity, _p)
#define city_built_iterate_end
#define MAX_LEN_GAME_IDENTIFIER
#define MAX_NUM_PLAYER_SLOTS
size_t get_internal_string_length(const char *text)
Return the length, in characters, of the string.
#define PL_(String1, String2, n)
const char * population_to_text(int thousand_citizen)
Return a prettily formatted string containing the population text.
int civ_population(const struct player *pplayer)
Count the # of thousand citizen in a civilisation.
#define GAME_DEFAULT_SCORETURN
struct government * government_of_player(const struct player *pplayer)
Return the government of a player.
const char * government_name_for_player(const struct player *pplayer)
Return the (translated) name of the given government of a player.
Government_type_id government_number(const struct government *pgovern)
Return the government index.
struct city * city_from_great_wonder(const struct impr_type *pimprove)
Get the world city with this great wonder.
bool great_wonder_is_destroyed(const struct impr_type *pimprove)
Returns whether this wonder has been destroyed.
bool is_great_wonder(const struct impr_type *pimprove)
Is this building a great wonder?
const char * improvement_name_translation(const struct impr_type *pimprove)
Return the (translated) name of the given improvement.
#define improvement_iterate_end
#define improvement_iterate(_p)
#define fc_assert_ret(condition)
#define fc_assert(condition)
#define fc_assert_ret_val(condition, val)
#define log_debug(message,...)
const char * nation_plural_for_player(const struct player *pplayer)
Return the (translated) plural noun of the given nation of a player.
const char * nation_adjective_for_player(const struct player *pplayer)
Return the (translated) adjective for the given nation of a player.
bool player_slot_is_used(const struct player_slot *pslot)
Returns TRUE is this slot is "used" i.e.
int player_number(const struct player *pplayer)
Return the player index/number/id.
int player_count()
Return the number of players.
int player_slot_index(const struct player_slot *pslot)
Returns the index of the player slot.
int player_index(const struct player *pplayer)
Return the player index.
struct player * player_slot_get_player(const struct player_slot *pslot)
Returns the team corresponding to the slot.
const char * player_name(const struct player *pplayer)
Return the leader name of the player.
bool player_has_embassy(const struct player *pplayer, const struct player *pplayer2)
Check if pplayer has an embassy with pplayer2.
#define players_iterate_end
#define players_iterate(_pplayer)
static bool is_barbarian(const struct player *pplayer)
#define player_slots_iterate(_pslot)
#define player_slots_iterate_end
#define shuffled_players_iterate_end
#define shuffled_players_iterate(NAME_pplayer)
static int get_units_killed(const struct player *pplayer)
Number of units killed.
static int get_units_built(const struct player *pplayer)
Number of units built.
static int get_contentpop(const struct player *pplayer)
Number of content citizens.
static struct logging_civ_score * score_log
static int nr_wonders(struct city *pcity)
Returns the number of wonders the given city has.
static const char * ranking[]
void report_final_scores(struct conn_list *dest)
Inform clients about player scores and statistics when the game ends.
static const char * economics_to_text(int value)
Construct string containing value followed by unit suitable for economics stats.
static const char * production_to_text(int value)
Construct string containing value followed by unit suitable for production stats.
static int get_munits(const struct player *pplayer)
Number of military units.
static const char * science_to_text(int value)
Construct string containing value followed by unit suitable for science stats.
static int get_pollution(const struct player *pplayer)
Pollution of player.
static int get_all_wonders(const struct player *pplayer)
All wonders, including small wonders.
static int get_economics(const struct player *pplayer)
BNP of player.
static const char * value_units(int val, const char *uni)
Construct string containing value and its unit.
void log_civ_score_init()
Initialize score logging system.
static int get_techs(const struct player *pplayer)
Number of techs.
static void plrdata_slot_init(struct plrdata_slot *plrdata, const char *name)
Allocate and initialize plrdata slot.
static void page_conn_etype(struct conn_list *dest, const char *caption, const char *headline, const char *lines, enum event_type event)
This function pops up a non-modal message dialog on the player's desktop.
static int get_pop(const struct player *pplayer)
Number of citizen units of player.
static int get_riots(const struct player *pplayer)
Number of rioting cities.
static const char * mil_units_to_text(int value)
Construct string containing value followed by unit suitable for military unit stats.
static void historian_generic(struct history_report *report, enum historian_type which_news)
Construct Historian Report.
static const char * pollution_to_text(int value)
Construct string containing value followed by unit suitable for pollution stats.
static void plrdata_slot_replace(struct plrdata_slot *plrdata, const char *name)
Replace plrdata slot with new one named according to input parameter.
static int get_production(const struct player *pplayer)
Production of player.
struct history_report latest_history_report
static bool scan_score_log(char *id)
Reads the whole file denoted by fp.
static int get_scirate(const struct player *pplayer)
Science rate.
static int get_taxrate(const struct player *pplayer)
Tax rate.
static const char * score_to_text(int value)
Construct string containing value followed by unit suitable for score stats.
void send_current_history_report(struct conn_list *dest)
Send history report of this turn.
static int get_great_wonders(const struct player *pplayer)
Great wonders for wonder score.
static int get_spaceship(const struct player *pplayer)
Spaceship score.
void report_wonders_of_the_world(struct conn_list *dest)
Send report listing all built and destroyed wonders, and wonders currently being built.
static int get_league_score(const struct player *pplayer)
League score Score = N_techs^1.
void report_demographics(struct connection *pconn)
Send demographics report; what gets reported depends on value of demographics server option.
static const char * historian_message[]
static int get_corruption(const struct player *pplayer)
Total corruption.
void make_history_report()
Produce random history report if it's time for one.
static int get_landarea(const struct player *pplayer)
Land area controlled by player.
static int get_total_score(const struct player *pplayer)
Total score.
static const char * area_to_text(int value)
Helper functions which transform the given value to a string depending on the unit.
static const char scorelog_magic[]
static int get_population(const struct player *pplayer)
Helper functions which return the value for the given player.
static struct dem_col coltable[]
static const char * historian_name[]
void report_top_five_cities(struct conn_list *dest)
Send report listing the "best" 5 cities in the world.
static int get_improvements(const struct player *pplayer)
Number of buildings in cities (not wonders)
static int get_mil_units(const struct player *pplayer)
Military units.
static int get_culture(const struct player *pplayer)
Culture score.
static int get_income(const struct player *pplayer)
Gold income.
BV_DEFINE(bv_cols, DEM_COL_LAST)
static int get_techout(const struct player *pplayer)
Technology output.
static int get_specialists(const struct player *pplayer)
Number of specialists.
static struct dem_row rowtable[]
static int get_unhappypop(const struct player *pplayer)
Number of unhappy citizens.
static const char * citizenunits_to_text(int value)
Construct string containing value followed by unit suitable for citizen unit stats.
static const char * wonders_to_text(int value)
Construct string containing value followed by unit suitable for wonders stats.
static int get_agriculture(const struct player *pplayer)
Food output.
bool is_valid_demography(const char *demography, int *error)
Verify that a given demography string is valid.
static int get_settledarea(const struct player *pplayer)
Area settled.
void page_conn(struct conn_list *dest, const char *caption, const char *headline, const char *lines)
This function pops up a non-modal message dialog on the player's desktop.
void log_civ_score_free()
Free resources allocated for score logging system.
static const char * agriculture_to_text(int value)
Construct string containing value followed by unit suitable for agriculture stats.
static int get_literacy2(const struct player *pplayer)
Literacy score calculated one way.
static void dem_line_item(char *outptr, size_t out_size, struct player *pplayer, struct dem_row *prow, bv_cols selcols)
Construct one demographics line.
static const char * culture_to_text(int value)
Construct string containing value followed by unit suitable for culture stats.
static int get_mil_service(const struct player *pplayer)
Military service length.
void report_achievements(struct connection *pconn)
Send achievements list.
static const char * cities_to_text(int value)
Construct string containing value followed by unit suitable for city stats.
static const char * percent_to_text(int value)
Construct string containing value followed by ''.
void log_civ_score_now()
Create a log file of the civilizations so you can see what was happening.
static int secompare(const void *a, const void *b)
Compare two player score entries.
static int get_happypop(const struct player *pplayer)
Number of happy citizens.
static void plrdata_slot_free(struct plrdata_slot *plrdata)
Free resources allocated for plrdata slot.
static int get_settlers(const struct player *pplayer)
Number of city building units.
static int get_real_pop(const struct player *pplayer)
Number of citizens of player.
static const char * improvements_to_text(int value)
Construct string containing value followed by unit suitable for improvement stats.
static int get_luxrate(const struct player *pplayer)
Luxury rate.
static int get_units_lost(const struct player *pplayer)
Number of units lost.
static int get_gold(const struct player *pplayer)
Amount of gold.
static const char * income_to_text(int value)
Construct string containing value followed by unit suitable for gold income stats.
static int get_cities(const struct player *pplayer)
Number of cities.
static const char * mil_service_to_text(int value)
Construct string containing value followed by unit suitable for military service stats.
static int get_gov(const struct player *pplayer)
Current government.
struct history_report * history_report_get()
Return current history report.
static int get_research(const struct player *pplayer)
Research speed.
struct research * research_get(const struct player *pplayer)
Returns the research structure associated with the player.
int total_player_citizens(const struct player *pplayer)
Return the total number of citizens in the player's nation.
const char * int_to_text(unsigned int number)
Return a prettily formatted string containing the given number.
#define specialist_type_iterate_end
#define specialist_type_iterate(sp)
struct civ_game::@28::@32 server
struct conn_list * est_connections
struct packet_game_info info
struct packet_scenario_info scenario
const char *(* to_text)(int)
int(* get_value)(const struct player *)
bool greater_values_are_better
char title[REPORT_TITLESIZE]
char body[REPORT_BODYSIZE]
struct plrdata_slot * plrdata
const struct player * player
struct city_list * cities
struct player_economic economic
struct player_score score
int fc_snprintf(char *str, size_t n, const char *format,...)
See also fc_utf8_snprintf_trunc(), fc_utf8_snprintf_rep().
size_t fc_strlcpy(char *dest, const char *src, size_t n)
fc_strlcpy() provides utf-8 version of (non-standard) function strlcpy() It is intended as more user-...
size_t fc_strlcat(char *dest, const char *src, size_t n)
fc_strlcat() provides utf-8 version of (non-standard) function strlcat() It is intended as more user-...
int cat_snprintf(char *str, size_t n, const char *format,...)
cat_snprintf is like a combination of fc_snprintf and fc_strlcat; it does snprintf to the end of an e...
FILE * fc_fopen(const char *filename, const char *opentype)
Wrapper function for fopen() with filename conversion to local encoding on Windows.
#define sz_strlcpy(dest, src)
#define sz_strlcat(dest, src)
int team_count()
Return the current number of teams.
int team_pretty_name(const struct team *pteam, QString &buf)
Set in 'buf' the name of the team 'pteam' in a format like "team <team_name>".
bool is_military_unit(const struct unit *punit)
Military units are capable of enforcing martial law.
bool unit_can_do_action(const struct unit *punit, const action_id act_id)
Return TRUE iff this unit can do the specified generalized (ruleset defined) action enabler controlle...
#define unit_list_iterate(unitlist, punit)
#define unit_list_iterate_end
const char * freeciv21_version()
Returns the raw version string.