Freeciv-3.1
Loading...
Searching...
No Matches
Data Structures | Macros | Enumerations | Functions | Variables
report.c File Reference
#include <stdio.h>
#include <string.h>
#include "bitvector.h"
#include "fciconv.h"
#include "fcintl.h"
#include "log.h"
#include "mem.h"
#include "rand.h"
#include "support.h"
#include "achievements.h"
#include "calendar.h"
#include "connection.h"
#include "events.h"
#include "game.h"
#include "government.h"
#include "packets.h"
#include "player.h"
#include "research.h"
#include "specialist.h"
#include "unitlist.h"
#include "version.h"
#include "citytools.h"
#include "plrhand.h"
#include "score.h"
#include "srv_main.h"
#include "report.h"

Go to the source code of this file.

Data Structures

struct  plrdata_slot
 
struct  logging_civ_score
 
struct  player_score_entry
 
struct  city_score_entry
 
struct  dem_row
 
struct  dem_col
 

Macros

#define HISTORIAN_FIRST   HISTORIAN_RICHEST
 
#define HISTORIAN_LAST   HISTORIAN_LARGEST
 
#define MAX_SCORELOG_LINE_LEN   (119 + 1)
 
#define GOOD_PLAYER(p)   ((p)->is_alive && !is_barbarian(p))
 

Enumerations

enum  historian_type {
  HISTORIAN_RICHEST =0 , HISTORIAN_ADVANCED =1 , HISTORIAN_MILITARY =2 , HISTORIAN_HAPPIEST =3 ,
  HISTORIAN_LARGEST =4
}
 
enum  dem_flag { DEM_COL_QUANTITY , DEM_COL_RANK , DEM_COL_BEST , DEM_COL_LAST }
 

Functions

static void plrdata_slot_init (struct plrdata_slot *plrdata, const char *name)
 
static void plrdata_slot_replace (struct plrdata_slot *plrdata, const char *name)
 
static void plrdata_slot_free (struct plrdata_slot *plrdata)
 
static void page_conn_etype (struct conn_list *dest, const char *caption, const char *headline, const char *lines, enum event_type event)
 
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_production (const struct player *pplayer)
 
static int get_economics (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 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 * science_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)
 
 BV_DEFINE (bv_cols, DEM_COL_LAST)
 
static int secompare (const void *a, const void *b)
 
static void historian_generic (struct history_report *report, enum historian_type which_news)
 
void send_current_history_report (struct conn_list *dest)
 
static int nr_wonders (struct city *pcity)
 
void report_top_five_cities (struct conn_list *dest)
 
void report_wonders_of_the_world (struct conn_list *dest)
 
static int get_pop (const struct player *pplayer)
 
static int get_real_pop (const struct player *pplayer)
 
static int get_cities (const struct player *pplayer)
 
static int get_techs (const struct player *pplayer)
 
static int get_munits (const struct player *pplayer)
 
static int get_settlers (const struct player *pplayer)
 
static int get_wonders (const struct player *pplayer)
 
static int get_techout (const struct player *pplayer)
 
static int get_literacy2 (const struct player *pplayer)
 
static int get_spaceship (const struct player *pplayer)
 
static int get_units_built (const struct player *pplayer)
 
static int get_units_killed (const struct player *pplayer)
 
static int get_units_lost (const struct player *pplayer)
 
static int get_gold (const struct player *pplayer)
 
static int get_taxrate (const struct player *pplayer)
 
static int get_scirate (const struct player *pplayer)
 
static int get_luxrate (const struct player *pplayer)
 
static int get_riots (const struct player *pplayer)
 
static int get_happypop (const struct player *pplayer)
 
static int get_contentpop (const struct player *pplayer)
 
static int get_unhappypop (const struct player *pplayer)
 
static int get_specialists (const struct player *pplayer)
 
static int get_gov (const struct player *pplayer)
 
static int get_corruption (const struct player *pplayer)
 
static int get_total_score (const struct player *pplayer)
 
static const char * value_units (int val, const char *uni)
 
static void dem_line_item (char *outptr, size_t out_size, struct player *pplayer, struct dem_row *prow, bv_cols selcols)
 
bool is_valid_demography (const char *demography, int *error)
 
void report_demographics (struct connection *pconn)
 
void report_achievements (struct connection *pconn)
 
static bool scan_score_log (char *id)
 
void log_civ_score_init (void)
 
void log_civ_score_free (void)
 
void log_civ_score_now (void)
 
void make_history_report (void)
 
void report_final_scores (struct conn_list *dest)
 
void page_conn (struct conn_list *dest, const char *caption, const char *headline, const char *lines)
 
struct history_reporthistory_report_get (void)
 

Variables

struct history_report latest_history_report = { -2 }
 
static struct logging_civ_scorescore_log = NULL
 
static const char * historian_message []
 
static const char * historian_name []
 
static const char scorelog_magic [] = "#FREECIV SCORELOG2 "
 
static struct dem_row rowtable []
 
static struct dem_col coltable [] = {{'q'}, {'r'}, {'b'}}
 
static const char * ranking []
 

Macro Definition Documentation

◆ GOOD_PLAYER

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

Definition at line 155 of file report.c.

◆ HISTORIAN_FIRST

#define HISTORIAN_FIRST   HISTORIAN_RICHEST

Definition at line 86 of file report.c.

◆ HISTORIAN_LAST

#define HISTORIAN_LAST   HISTORIAN_LARGEST

Definition at line 87 of file report.c.

◆ MAX_SCORELOG_LINE_LEN

#define MAX_SCORELOG_LINE_LEN   (119 + 1)

Definition at line 122 of file report.c.

Enumeration Type Documentation

◆ dem_flag

enum dem_flag
Enumerator
DEM_COL_QUANTITY 
DEM_COL_RANK 
DEM_COL_BEST 
DEM_COL_LAST 

Definition at line 181 of file report.c.

◆ historian_type

Enumerator
HISTORIAN_RICHEST 
HISTORIAN_ADVANCED 
HISTORIAN_MILITARY 
HISTORIAN_HAPPIEST 
HISTORIAN_LARGEST 

Definition at line 79 of file report.c.

Function Documentation

◆ area_to_text()

static const char * area_to_text ( int  value)
static

Helper functions which transform the given value to a string depending on the unit.

Definition at line 806 of file report.c.

◆ BV_DEFINE()

BV_DEFINE ( bv_cols  ,
DEM_COL_LAST   
)

◆ culture_to_text()

static const char * culture_to_text ( int  value)
static

Construct string containing value followed by unit suitable for culture stats.

Definition at line 873 of file report.c.

◆ dem_line_item()

static void dem_line_item ( char *  outptr,
size_t  out_size,
struct player pplayer,
struct dem_row prow,
bv_cols  selcols 
)
static

Construct one demographics line.

Definition at line 882 of file report.c.

Referenced by report_demographics().

◆ economics_to_text()

static const char * economics_to_text ( int  value)
static

Construct string containing value followed by unit suitable for economics stats.

Definition at line 836 of file report.c.

◆ get_cities()

static int get_cities ( const struct player pplayer)
static

Number of cities

Definition at line 558 of file report.c.

Referenced by log_civ_score_now(), and report_final_scores().

◆ get_contentpop()

static int get_contentpop ( const struct player pplayer)
static

Number of content citizens

Definition at line 723 of file report.c.

Referenced by log_civ_score_now().

◆ get_corruption()

static int get_corruption ( const struct player pplayer)
static

Total corruption

Definition at line 761 of file report.c.

Referenced by log_civ_score_now().

◆ get_culture()

static int get_culture ( const struct player pplayer)
static

Culture score

Definition at line 783 of file report.c.

Referenced by log_civ_score_now(), and report_final_scores().

◆ get_economics()

static int get_economics ( const struct player pplayer)
static

BNP of player

Definition at line 534 of file report.c.

Referenced by log_civ_score_now(), and report_final_scores().

◆ get_gold()

static int get_gold ( const struct player pplayer)
static

Amount of gold.

Definition at line 667 of file report.c.

Referenced by log_civ_score_now().

◆ get_gov()

static int get_gov ( const struct player pplayer)
static

Current government

Definition at line 753 of file report.c.

Referenced by log_civ_score_now().

◆ get_happypop()

static int get_happypop ( const struct player pplayer)
static

Number of happy citizens

Definition at line 715 of file report.c.

Referenced by log_civ_score_now().

◆ get_landarea()

static int get_landarea ( const struct player pplayer)
static

Land area controlled by player

Definition at line 502 of file report.c.

Referenced by log_civ_score_now(), and report_final_scores().

◆ get_literacy2()

static int get_literacy2 ( const struct player pplayer)
static

Literacy score calculated one way. See also get_literacy() to see alternative way.

Definition at line 627 of file report.c.

Referenced by log_civ_score_now().

◆ get_luxrate()

static int get_luxrate ( const struct player pplayer)
static

Luxury rate

Definition at line 691 of file report.c.

Referenced by log_civ_score_now().

◆ get_mil_service()

static int get_mil_service ( const struct player pplayer)
static

Military service length

Definition at line 550 of file report.c.

Referenced by report_final_scores().

◆ get_munits()

static int get_munits ( const struct player pplayer)
static

Number of military units

Definition at line 574 of file report.c.

Referenced by log_civ_score_now().

◆ get_pollution()

static int get_pollution ( const struct player pplayer)
static

Pollution of player

Definition at line 542 of file report.c.

Referenced by log_civ_score_now().

◆ get_pop()

static int get_pop ( const struct player pplayer)
static

Number of citizen units of player

Definition at line 486 of file report.c.

Referenced by get_real_pop(), and log_civ_score_now().

◆ get_population()

static int get_population ( const struct player pplayer)
static

Population of player

Definition at line 478 of file report.c.

◆ get_production()

static int get_production ( const struct player pplayer)
static

Production of player

Definition at line 526 of file report.c.

Referenced by log_civ_score_now(), and report_final_scores().

◆ get_real_pop()

static int get_real_pop ( const struct player pplayer)
static

Number of citizens of player

Definition at line 494 of file report.c.

Referenced by report_final_scores().

◆ get_research()

static int get_research ( const struct player pplayer)
static

Research speed

Definition at line 518 of file report.c.

Referenced by report_final_scores().

◆ get_riots()

static int get_riots ( const struct player pplayer)
static

Number of rioting cities

Definition at line 699 of file report.c.

Referenced by log_civ_score_now().

◆ get_scirate()

static int get_scirate ( const struct player pplayer)
static

Science rate

Definition at line 683 of file report.c.

Referenced by log_civ_score_now().

◆ get_settledarea()

static int get_settledarea ( const struct player pplayer)
static

Area settled.

Definition at line 510 of file report.c.

Referenced by log_civ_score_now(), and report_final_scores().

◆ get_settlers()

static int get_settlers ( const struct player pplayer)
static

Number of city building units.

Definition at line 591 of file report.c.

Referenced by log_civ_score_now().

◆ get_spaceship()

static int get_spaceship ( const struct player pplayer)
static

Spaceship score

Definition at line 635 of file report.c.

Referenced by log_civ_score_now(), and report_final_scores().

◆ get_specialists()

static int get_specialists ( const struct player pplayer)
static

Number of specialists.

Definition at line 739 of file report.c.

Referenced by log_civ_score_now().

◆ get_taxrate()

static int get_taxrate ( const struct player pplayer)
static

Tax rate

Definition at line 675 of file report.c.

Referenced by log_civ_score_now().

◆ get_techout()

static int get_techout ( const struct player pplayer)
static

Technology output

Definition at line 618 of file report.c.

Referenced by log_civ_score_now().

◆ get_techs()

static int get_techs ( const struct player pplayer)
static

Number of techs

Definition at line 566 of file report.c.

Referenced by log_civ_score_now(), and report_final_scores().

◆ get_total_score()

static int get_total_score ( const struct player pplayer)
static

Total score

Definition at line 775 of file report.c.

Referenced by log_civ_score_now().

◆ get_unhappypop()

static int get_unhappypop ( const struct player pplayer)
static

Number of unhappy citizens

Definition at line 731 of file report.c.

Referenced by log_civ_score_now().

◆ get_units_built()

static int get_units_built ( const struct player pplayer)
static

Number of units built

Definition at line 643 of file report.c.

Referenced by log_civ_score_now(), and report_final_scores().

◆ get_units_killed()

static int get_units_killed ( const struct player pplayer)
static

Number of units killed

Definition at line 651 of file report.c.

Referenced by log_civ_score_now(), and report_final_scores().

◆ get_units_lost()

static int get_units_lost ( const struct player pplayer)
static

Number of units lost

Definition at line 659 of file report.c.

Referenced by log_civ_score_now(), and report_final_scores().

◆ get_wonders()

static int get_wonders ( const struct player pplayer)
static

Wonder score

Definition at line 610 of file report.c.

Referenced by log_civ_score_now(), and report_final_scores().

◆ historian_generic()

static void historian_generic ( struct history_report report,
enum historian_type  which_news 
)
static

Construct Historian Report

Definition at line 238 of file report.c.

Referenced by make_history_report().

◆ history_report_get()

struct history_report * history_report_get ( void  )

Return current history report

Definition at line 1689 of file report.c.

Referenced by sg_load_history(), sg_load_history(), and sg_save_history().

◆ is_valid_demography()

bool is_valid_demography ( const char *  demography,
int *  error 
)

Verify that a given demography string is valid. See game.demography. If the string is not valid the index of the first invalid character is return as 'error'.

Other settings callback functions are in settings.c, but this one uses static values from this file so it's done separately.

Definition at line 946 of file report.c.

Referenced by demography_callback().

◆ log_civ_score_free()

void log_civ_score_free ( void  )

Free resources allocated for score logging system

Definition at line 1302 of file report.c.

Referenced by log_civ_score_now(), scorelog_action(), and server_game_free().

◆ log_civ_score_init()

void log_civ_score_init ( void  )

Initialize score logging system

Definition at line 1279 of file report.c.

Referenced by scorelog_action().

◆ log_civ_score_now()

void log_civ_score_now ( void  )

Create a log file of the civilizations so you can see what was happening.

Definition at line 1332 of file report.c.

Referenced by begin_turn(), and srv_scores().

◆ make_history_report()

void make_history_report ( void  )

Produce random history report if it's time for one.

Definition at line 1533 of file report.c.

Referenced by end_turn().

◆ mil_service_to_text()

static const char * mil_service_to_text ( int  value)
static

Construct string containing value followed by unit suitable for military service stats.

Definition at line 855 of file report.c.

◆ nr_wonders()

static int nr_wonders ( struct city pcity)
static

Returns the number of wonders the given city has.

Definition at line 311 of file report.c.

Referenced by report_top_five_cities().

◆ page_conn()

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

Definition at line 1634 of file report.c.

Referenced by report_achievements(), report_demographics(), report_top_five_cities(), and report_wonders_of_the_world().

◆ page_conn_etype()

static void page_conn_etype ( struct conn_list *  dest,
const char *  caption,
const char *  headline,
const char *  lines,
enum event_type  event 
)
static

This function pops up a non-modal message dialog on the player's desktop

event == E_REPORT: message should not be ignored by clients watching AI players with ai_popup_windows off. Example: Server Options, Demographics Report, etc.

event == E_BROADCAST_REPORT: message can safely be ignored by clients watching AI players with ai_popup_windows off. For example: Herodot's report... and similar messages.

Definition at line 1651 of file report.c.

Referenced by page_conn(), and send_current_history_report().

◆ percent_to_text()

static const char * percent_to_text ( int  value)
static

Construct string containing value followed by ''. So value is already considered to be in units of 1/100.

Definition at line 816 of file report.c.

◆ plrdata_slot_free()

static void plrdata_slot_free ( struct plrdata_slot plrdata)
static

Free resources allocated for plrdata slot.

Definition at line 1110 of file report.c.

Referenced by log_civ_score_now(), and scan_score_log().

◆ plrdata_slot_init()

static void plrdata_slot_init ( struct plrdata_slot plrdata,
const char *  name 
)
static

Allocate and initialize plrdata slot.

Definition at line 1087 of file report.c.

Referenced by log_civ_score_now(), and scan_score_log().

◆ plrdata_slot_replace()

static void plrdata_slot_replace ( struct plrdata_slot plrdata,
const char *  name 
)
static

Replace plrdata slot with new one named according to input parameter.

Definition at line 1099 of file report.c.

Referenced by log_civ_score_now(), and plrdata_slot_init().

◆ pollution_to_text()

static const char * pollution_to_text ( int  value)
static

Construct string containing value followed by unit suitable for pollution stats.

Definition at line 864 of file report.c.

◆ production_to_text()

static const char * production_to_text ( int  value)
static

Construct string containing value followed by unit suitable for production stats.

Definition at line 825 of file report.c.

◆ report_achievements()

void report_achievements ( struct connection pconn)

Send achievements list

Definition at line 1057 of file report.c.

Referenced by handle_report_req().

◆ report_demographics()

void report_demographics ( struct connection pconn)

Send demographics report; what gets reported depends on value of demographics server option.

Definition at line 993 of file report.c.

Referenced by handle_report_req().

◆ report_final_scores()

void report_final_scores ( struct conn_list *  dest)

Inform clients about player scores and statistics when the game ends. Called only from server/srv_main.c srv_scores()

Definition at line 1555 of file report.c.

Referenced by connection_attach_real(), and srv_scores().

◆ report_top_five_cities()

void report_top_five_cities ( struct conn_list *  dest)

Send report listing the "best" 5 cities in the world.

Definition at line 327 of file report.c.

Referenced by handle_report_req().

◆ report_wonders_of_the_world()

void report_wonders_of_the_world ( struct conn_list *  dest)

Send report listing all built and destroyed wonders, and wonders currently being built.

Definition at line 401 of file report.c.

Referenced by handle_report_req().

◆ scan_score_log()

static bool scan_score_log ( char *  id)
static

Reads the whole file denoted by fp. Sets last_turn and id to the values contained in the file. Returns the player_names indexed by player_no at the end of the log file.

Returns TRUE iff the file had read successfully.

Definition at line 1125 of file report.c.

Referenced by log_civ_score_now().

◆ science_to_text()

static const char * science_to_text ( int  value)
static

Construct string containing value followed by unit suitable for science stats.

Definition at line 846 of file report.c.

◆ secompare()

static int secompare ( const void *  a,
const void *  b 
)
static

Compare two player score entries. Used as callback for qsort.

Definition at line 229 of file report.c.

Referenced by historian_generic(), report_final_scores(), and report_top_five_cities().

◆ send_current_history_report()

void send_current_history_report ( struct conn_list *  dest)

Send history report of this turn.

Definition at line 298 of file report.c.

Referenced by establish_new_connection(), and make_history_report().

◆ value_units()

static const char * value_units ( int  val,
const char *  uni 
)
static

Construct string containing value and its unit.

Definition at line 791 of file report.c.

Referenced by area_to_text(), culture_to_text(), economics_to_text(), mil_service_to_text(), percent_to_text(), pollution_to_text(), production_to_text(), and science_to_text().

Variable Documentation

◆ coltable

struct dem_col coltable[] = {{'q'}, {'r'}, {'b'}}
static

◆ historian_message

const char* historian_message[]
static
Initial value:
={
N_("%s %s reports on the RICHEST Civilizations in the World."),
N_("%s %s reports on the most ADVANCED Civilizations in the World."),
N_("%s %s reports on the most MILITARIZED Civilizations in the World."),
N_("%s %s reports on the HAPPIEST Civilizations in the World."),
}
#define N_(String)
Definition fcintl.h:69

Definition at line 89 of file report.c.

Referenced by historian_generic().

◆ historian_name

const char* historian_name[]
static
Initial value:
={
N_("Herodotus"),
N_("Thucydides"),
N_("Pliny the Elder"),
N_("Livy"),
N_("Toynbee"),
N_("Gibbon"),
N_("Ssu-ma Ch'ien"),
}

Definition at line 102 of file report.c.

Referenced by historian_generic().

◆ latest_history_report

struct history_report latest_history_report = { -2 }

◆ ranking

const char* ranking[]
static

Definition at line 193 of file report.c.

Referenced by historian_generic().

◆ rowtable

struct dem_row rowtable[]
static
Initial value:
= {
{'N', N_("Population"), get_population, population_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 },
{'L', N_("?ability:Literacy"), get_literacy, percent_to_text, TRUE },
{'P', N_("Production"), get_production, production_to_text, TRUE },
{'E', N_("Economics"), get_economics, economics_to_text, TRUE },
{'M', N_("Military Service"), get_mil_service, mil_service_to_text, FALSE },
{'O', N_("?stats:Pollution"), get_pollution, pollution_to_text, FALSE },
{'C', N_("Culture"), get_culture, culture_to_text, TRUE }
}
int get_literacy(const struct player *pplayer)
const char * population_to_text(int thousand_citizen)
Definition game.c:714
static const char * economics_to_text(int value)
Definition report.c:836
static const char * production_to_text(int value)
Definition report.c:825
static const char * science_to_text(int value)
Definition report.c:846
static int get_pollution(const struct player *pplayer)
Definition report.c:542
static int get_economics(const struct player *pplayer)
Definition report.c:534
static const char * pollution_to_text(int value)
Definition report.c:864
static int get_production(const struct player *pplayer)
Definition report.c:526
static int get_landarea(const struct player *pplayer)
Definition report.c:502
static const char * area_to_text(int value)
Definition report.c:806
static int get_population(const struct player *pplayer)
Definition report.c:478
static int get_culture(const struct player *pplayer)
Definition report.c:783
static int get_settledarea(const struct player *pplayer)
Definition report.c:510
static const char * culture_to_text(int value)
Definition report.c:873
static int get_mil_service(const struct player *pplayer)
Definition report.c:550
static const char * percent_to_text(int value)
Definition report.c:816
static const char * mil_service_to_text(int value)
Definition report.c:855
static int get_research(const struct player *pplayer)
Definition report.c:518
#define TRUE
Definition support.h:46
#define FALSE
Definition support.h:47

Referenced by is_valid_demography(), and report_demographics().

◆ score_log

struct logging_civ_score* score_log = NULL
static

Definition at line 68 of file report.c.

Referenced by log_civ_score_free(), log_civ_score_init(), log_civ_score_now(), and scan_score_log().

◆ scorelog_magic

const char scorelog_magic[] = "#FREECIV SCORELOG2 "
static

Definition at line 124 of file report.c.

Referenced by log_civ_score_now(), and scan_score_log().