Freeciv21
Develop your civilization from humble roots to a global empire
infracache.cpp File Reference
#include "city.h"
#include "game.h"
#include "map.h"
#include "player.h"
#include "tile.h"
#include "maphand.h"
#include "advbuilding.h"
#include "autosettlers.h"
#include "infracache.h"
+ Include dependency graph for infracache.cpp:

Go to the source code of this file.

Classes

struct  worker_activity_cache
 

Functions

static int adv_calc_irrigate_transform (const struct city *pcity, const struct tile *ptile)
 Calculate the benefit of irrigating the given tile. More...
 
static int adv_calc_mine_transform (const struct city *pcity, const struct tile *ptile)
 Calculate the benefit of mining the given tile. More...
 
static int adv_calc_transform (const struct city *pcity, const struct tile *ptile)
 Calculate the benefit of transforming the given tile. More...
 
static int adv_calc_extra (const struct city *pcity, const struct tile *ptile, const struct extra_type *pextra)
 Calculate the benefit of building an extra at the given tile. More...
 
static int adv_calc_rmextra (const struct city *pcity, const struct tile *ptile, const struct extra_type *pextra)
 Calculate the benefit of removing an extra from the given tile. More...
 
void initialize_infrastructure_cache (struct player *pplayer)
 Do all tile improvement calculations and cache them for later. More...
 
int city_tile_value (const struct city *pcity, const struct tile *ptile, int foodneed, int prodneed)
 Returns a measure of goodness of a tile to pcity. More...
 
void adv_city_worker_act_set (struct city *pcity, int city_tile_index, enum unit_activity act_id, int value)
 Set the value for activity 'doing' on tile 'city_tile_index' of city 'pcity'. More...
 
int adv_city_worker_act_get (const struct city *pcity, int city_tile_index, enum unit_activity act_id)
 Return the value for activity 'doing' on tile 'city_tile_index' of city 'pcity'. More...
 
void adv_city_worker_extra_set (struct city *pcity, int city_tile_index, const struct extra_type *pextra, int value)
 Set the value for extra on tile 'city_tile_index' of city 'pcity'. More...
 
void adv_city_worker_rmextra_set (struct city *pcity, int city_tile_index, const struct extra_type *pextra, int value)
 Set the value for extra removal on tile 'city_tile_index' of city 'pcity'. More...
 
int adv_city_worker_extra_get (const struct city *pcity, int city_tile_index, const struct extra_type *pextra)
 Return the value for extra on tile 'city_tile_index' of city 'pcity'. More...
 
int adv_city_worker_rmextra_get (const struct city *pcity, int city_tile_index, const struct extra_type *pextra)
 Return the value for extra removal on tile 'city_tile_index' of city 'pcity'. More...
 
void adv_city_update (struct city *pcity)
 Update the memory allocated for AI city handling. More...
 
void adv_city_alloc (struct city *pcity)
 Allocate advisors related city data. More...
 
void adv_city_free (struct city *pcity)
 Free advisors related city data. More...
 

Function Documentation

◆ adv_calc_extra()

static int adv_calc_extra ( const struct city pcity,
const struct tile ptile,
const struct extra_type pextra 
)
static

Calculate the benefit of building an extra at the given tile.

The return value is the goodness of the tile after the extra is built. This should be compared to the goodness of the tile currently (see city_tile_value(); note that this depends on the AI's weighting values).

This function does not calculate the benefit of being able to quickly move units (i.e., of connecting the civilization). See road_bonus() for that calculation.

Definition at line 182 of file infracache.cpp.

Referenced by initialize_infrastructure_cache().

◆ adv_calc_irrigate_transform()

static int adv_calc_irrigate_transform ( const struct city pcity,
const struct tile ptile 
)
static

Calculate the benefit of irrigating the given tile.

The return value is the goodness of the tile after the irrigation. This should be compared to the goodness of the tile currently (see city_tile_value(); note that this depends on the AI's weighting values).

Definition at line 57 of file infracache.cpp.

Referenced by initialize_infrastructure_cache().

◆ adv_calc_mine_transform()

static int adv_calc_mine_transform ( const struct city pcity,
const struct tile ptile 
)
static

Calculate the benefit of mining the given tile.

The return value is the goodness of the tile after the mining. This should be compared to the goodness of the tile currently (see city_tile_value(); note that this depends on the AI's weighting values).

Definition at line 97 of file infracache.cpp.

Referenced by initialize_infrastructure_cache().

◆ adv_calc_rmextra()

static int adv_calc_rmextra ( const struct city pcity,
const struct tile ptile,
const struct extra_type pextra 
)
static

Calculate the benefit of removing an extra from the given tile.

The return value is the goodness of the tile after the extra is removed. This should be compared to the goodness of the tile currently (see city_tile_value(); note that this depends on the AI's weighting values).

Definition at line 218 of file infracache.cpp.

Referenced by initialize_infrastructure_cache().

◆ adv_calc_transform()

static int adv_calc_transform ( const struct city pcity,
const struct tile ptile 
)
static

Calculate the benefit of transforming the given tile.

The return value is the goodness of the tile after the transform. This should be compared to the goodness of the tile currently (see city_tile_value(); note that this depends on the AI's weighting values).

Definition at line 137 of file infracache.cpp.

Referenced by initialize_infrastructure_cache().

◆ adv_city_alloc()

void adv_city_alloc ( struct city pcity)

Allocate advisors related city data.

Definition at line 498 of file infracache.cpp.

Referenced by create_city(), sg_load_player_cities(), and texai_city_info_recv().

◆ adv_city_free()

void adv_city_free ( struct city pcity)

Free advisors related city data.

Definition at line 510 of file infracache.cpp.

Referenced by remove_city(), server_game_free(), sg_load_player_cities(), and texai_city_destruction_recv().

◆ adv_city_update()

void adv_city_update ( struct city pcity)

Update the memory allocated for AI city handling.

Definition at line 472 of file infracache.cpp.

Referenced by adv_city_alloc(), adv_city_worker_act_set(), adv_city_worker_extra_set(), adv_city_worker_rmextra_set(), and city_map_update_radius_sq().

◆ adv_city_worker_act_get()

int adv_city_worker_act_get ( const struct city pcity,
int  city_tile_index,
enum unit_activity  act_id 
)

Return the value for activity 'doing' on tile 'city_tile_index' of city 'pcity'.

Definition at line 362 of file infracache.cpp.

Referenced by settler_evaluate_improvements(), tai_tile_worker_task_select(), and texai_tile_worker_task_select().

◆ adv_city_worker_act_set()

void adv_city_worker_act_set ( struct city pcity,
int  city_tile_index,
enum unit_activity  act_id,
int  value 
)

Set the value for activity 'doing' on tile 'city_tile_index' of city 'pcity'.

Definition at line 336 of file infracache.cpp.

Referenced by initialize_infrastructure_cache().

◆ adv_city_worker_extra_get()

int adv_city_worker_extra_get ( const struct city pcity,
int  city_tile_index,
const struct extra_type pextra 
)

Return the value for extra on tile 'city_tile_index' of city 'pcity'.

Definition at line 434 of file infracache.cpp.

Referenced by settler_evaluate_improvements(), tai_tile_worker_task_select(), and texai_tile_worker_task_select().

◆ adv_city_worker_extra_set()

void adv_city_worker_extra_set ( struct city pcity,
int  city_tile_index,
const struct extra_type pextra,
int  value 
)

Set the value for extra on tile 'city_tile_index' of city 'pcity'.

Definition at line 380 of file infracache.cpp.

Referenced by initialize_infrastructure_cache().

◆ adv_city_worker_rmextra_get()

int adv_city_worker_rmextra_get ( const struct city pcity,
int  city_tile_index,
const struct extra_type pextra 
)

Return the value for extra removal on tile 'city_tile_index' of city 'pcity'.

Definition at line 453 of file infracache.cpp.

Referenced by settler_evaluate_improvements(), tai_tile_worker_task_select(), and texai_tile_worker_task_select().

◆ adv_city_worker_rmextra_set()

void adv_city_worker_rmextra_set ( struct city pcity,
int  city_tile_index,
const struct extra_type pextra,
int  value 
)

Set the value for extra removal on tile 'city_tile_index' of city 'pcity'.

Definition at line 407 of file infracache.cpp.

Referenced by initialize_infrastructure_cache().

◆ city_tile_value()

int city_tile_value ( const struct city pcity,
const struct tile ptile,
int  foodneed,
int  prodneed 
)

Returns a measure of goodness of a tile to pcity.

FIXME: foodneed and prodneed are always 0.

Definition at line 305 of file infracache.cpp.

Referenced by adv_calc_extra(), adv_calc_irrigate_transform(), adv_calc_mine_transform(), adv_calc_rmextra(), adv_calc_transform(), settler_evaluate_improvements(), tai_tile_worker_task_select(), and texai_tile_worker_task_select().

◆ initialize_infrastructure_cache()

void initialize_infrastructure_cache ( struct player pplayer)

Do all tile improvement calculations and cache them for later.

These values are used in settler_evaluate_improvements() so this function must be called before doing that. Currently this is only done when handling auto-settlers or when the AI contemplates building worker units.

Definition at line 245 of file infracache.cpp.

Referenced by auto_settlers_player(), dai_do_build_city(), and dai_manage_cities().