Freeciv-3.2
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 "nation.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 void page_conn (struct conn_list *dest, const char *caption, const char *headline, const char *lines)
 
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 chararea_to_text (int value)
 
static const charpercent_to_text (int value)
 
static const charproduction_to_text (int value)
 
static const chareconomics_to_text (int value)
 
static const charscience_to_text (int value)
 
static const charmil_service_to_text (int value)
 
static const charpollution_to_text (int value)
 
static const charculture_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_cities (struct conn_list *dest)
 
void report_wonders_of_the_world_long (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_units_used (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 charvalue_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)
 
struct history_reporthistory_report_get (void)
 

Variables

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

Macro Definition Documentation

◆ GOOD_PLAYER

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

Definition at line 159 of file report.c.

◆ HISTORIAN_FIRST

#define HISTORIAN_FIRST   HISTORIAN_RICHEST

Definition at line 90 of file report.c.

◆ HISTORIAN_LAST

#define HISTORIAN_LAST   HISTORIAN_LARGEST

Definition at line 91 of file report.c.

◆ MAX_SCORELOG_LINE_LEN

#define MAX_SCORELOG_LINE_LEN   (119 + 1)

Definition at line 126 of file report.c.

Enumeration Type Documentation

◆ dem_flag

Enumerator
DEM_COL_QUANTITY 
DEM_COL_RANK 
DEM_COL_BEST 
DEM_COL_LAST 

Definition at line 185 of file report.c.

◆ historian_type

Enumerator
HISTORIAN_RICHEST 
HISTORIAN_ADVANCED 
HISTORIAN_MILITARY 
HISTORIAN_HAPPIEST 
HISTORIAN_LARGEST 

Definition at line 83 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 938 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 1005 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 1014 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 968 of file report.c.

◆ get_cities()

static int get_cities ( const struct player pplayer)
static

Number of cities

Definition at line 682 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 855 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 893 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 915 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 658 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 799 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 885 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 847 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 626 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 751 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 823 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 674 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 698 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 666 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 610 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 602 of file report.c.

◆ get_production()

static int get_production ( const struct player pplayer)
static

Production of player

Definition at line 650 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 618 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 642 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 831 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 815 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 634 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 715 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 759 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 871 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 807 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 742 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 690 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 907 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 863 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 767 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 775 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 783 of file report.c.

Referenced by log_civ_score_now(), and report_final_scores().

◆ get_units_used()

static int get_units_used ( const struct player pplayer)
static

Number of units used

Definition at line 791 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 734 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 242 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 1824 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 1078 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 1434 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 1411 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 1464 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 1667 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 987 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 315 of file report.c.

Referenced by report_top_cities().

◆ page_conn()

static void page_conn ( struct conn_list dest,
const char caption,
const char headline,
const char lines 
)
static

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

Definition at line 1769 of file report.c.

Referenced by report_achievements(), report_demographics(), report_top_cities(), report_wonders_of_the_world(), and report_wonders_of_the_world_long().

◆ 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 1786 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 948 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 1242 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 1219 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 1231 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 996 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 957 of file report.c.

◆ report_achievements()

void report_achievements ( struct connection pconn)

Send achievements list

Definition at line 1189 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 1125 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 1689 of file report.c.

Referenced by connection_attach_real(), and srv_scores().

◆ report_top_cities()

void report_top_cities ( struct conn_list dest)

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

Definition at line 331 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 525 of file report.c.

Referenced by handle_report_req().

◆ report_wonders_of_the_world_long()

void report_wonders_of_the_world_long ( struct conn_list dest)

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

Definition at line 414 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 1257 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 978 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 233 of file report.c.

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

◆ send_current_history_report()

void send_current_history_report ( struct conn_list dest)

Send history report of this turn.

Definition at line 302 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 923 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 93 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 106 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 197 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:734
static const char * economics_to_text(int value)
Definition report.c:968
static const char * production_to_text(int value)
Definition report.c:957
static const char * science_to_text(int value)
Definition report.c:978
static int get_pollution(const struct player *pplayer)
Definition report.c:666
static int get_economics(const struct player *pplayer)
Definition report.c:658
static const char * pollution_to_text(int value)
Definition report.c:996
static int get_production(const struct player *pplayer)
Definition report.c:650
static int get_landarea(const struct player *pplayer)
Definition report.c:626
static const char * area_to_text(int value)
Definition report.c:938
static int get_population(const struct player *pplayer)
Definition report.c:602
static int get_culture(const struct player *pplayer)
Definition report.c:915
static int get_settledarea(const struct player *pplayer)
Definition report.c:634
static const char * culture_to_text(int value)
Definition report.c:1005
static int get_mil_service(const struct player *pplayer)
Definition report.c:674
static const char * percent_to_text(int value)
Definition report.c:948
static const char * mil_service_to_text(int value)
Definition report.c:987
static int get_research(const struct player *pplayer)
Definition report.c:642
#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 69 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 128 of file report.c.

Referenced by log_civ_score_now(), and scan_score_log().