Freeciv21
Develop your civilization from humble roots to a global empire
aisettler.cpp File Reference
#include <QHash>
#include "support.h"
#include "timing.h"
#include "city.h"
#include "game.h"
#include "government.h"
#include "map.h"
#include "packets.h"
#include "player.h"
#include "workertask.h"
#include "citymap.h"
#include "pf_tools.h"
#include "citytools.h"
#include "maphand.h"
#include "srv_log.h"
#include "unithand.h"
#include "unittools.h"
#include "advdata.h"
#include "advgoto.h"
#include "advtools.h"
#include "autosettlers.h"
#include "infracache.h"
#include "handicaps.h"
#include "aidata.h"
#include "aiferry.h"
#include "ailog.h"
#include "aiplayer.h"
#include "aitools.h"
#include "aiunit.h"
#include "daicity.h"
#include "aisettler.h"
+ Include dependency graph for aisettler.cpp:

Go to the source code of this file.

Classes

struct  tile_data_cache
 
struct  ai_settler
 
struct  cityresult
 

Macros

#define RESULT_IS_ENOUGH   250
 
#define FERRY_TECH_WANT   500
 
#define GROWTH_PRIORITY   15
 
#define PERFECTION   3
 
#define GROWTH_POTENTIAL_DEEMPHASIS   8
 
#define NAVAL_EMPHASIS   20
 
#define DEFENSE_EMPHASIS   20
 

Functions

struct tile_data_cachetile_data_cache_new ()
 Allocate tile data cache. More...
 
struct tile_data_cachetile_data_cache_copy (const struct tile_data_cache *ptdc)
 Make copy of tile data cache. More...
 
static const struct tile_data_cachetdc_plr_get (struct ai_type *ait, struct player *plr, int tindex)
 Return player's tile data cache. More...
 
static void tdc_plr_set (struct ai_type *ait, struct player *plr, int tindex, const struct tile_data_cache *ptdc)
 Store player's tile data cache. More...
 
static std::unique_ptr< cityresultcityresult_fill (struct ai_type *ait, struct player *pplayer, struct tile *center)
 Fill cityresult struct with useful info about the city spot. More...
 
static bool food_starvation (const std::unique_ptr< cityresult > &result)
 Check if a city on this location would starve. More...
 
static bool shield_starvation (const std::unique_ptr< cityresult > &result)
 Check if a city on this location would lack shields. More...
 
static int result_defense_bonus (struct player *pplayer, const std::unique_ptr< cityresult > &result)
 Calculate defense bonus, which is a % of total results equal to a given % of the defense bonus %. More...
 
static int naval_bonus (const std::unique_ptr< cityresult > &result)
 Add bonus for coast. More...
 
static void print_cityresult (struct player *pplayer, const std::unique_ptr< cityresult > &cr)
 For debugging, print the city result table. More...
 
std::unique_ptr< cityresultcity_desirability (struct ai_type *ait, struct player *pplayer, struct unit *punit, struct tile *ptile)
 Calculates the desire for founding a new city at 'ptile'. More...
 
static std::unique_ptr< cityresultsettler_map_iterate (struct ai_type *ait, struct pf_parameter *parameter, struct unit *punit, int boat_cost)
 Find nearest and best city placement in a PF iteration according to "parameter". More...
 
static std::unique_ptr< cityresultfind_best_city_placement (struct ai_type *ait, struct unit *punit, bool look_for_boat, bool use_virt_boat)
 Find nearest and best city placement or (TODO) a city to immigrate to. More...
 
static bool dai_do_build_city (struct ai_type *ait, struct player *pplayer, struct unit *punit)
 Build a city and initialize AI infrastructure cache. More...
 
void dai_auto_settler_init (struct ai_plr *ai)
 Initialize ai settler engine. More...
 
void dai_auto_settler_run (struct ai_type *ait, struct player *pplayer, struct unit *punit, struct settlermap *state)
 Auto settler that can also build cities. More...
 
void dai_auto_settler_cont (struct ai_type *ait, struct player *pplayer, struct unit *punit, struct settlermap *state)
 Auto settler continuing its work. More...
 
void dai_auto_settler_reset (struct ai_type *ait, struct player *pplayer)
 Reset ai settler engine. More...
 
void dai_auto_settler_free (struct ai_plr *ai)
 Deinitialize ai settler engine. More...
 
void contemplate_new_city (struct ai_type *ait, struct city *pcity)
 Return want for city settler. More...
 

Macro Definition Documentation

◆ DEFENSE_EMPHASIS

#define DEFENSE_EMPHASIS   20

Definition at line 107 of file aisettler.cpp.

◆ FERRY_TECH_WANT

#define FERRY_TECH_WANT   500

Definition at line 87 of file aisettler.cpp.

◆ GROWTH_POTENTIAL_DEEMPHASIS

#define GROWTH_POTENTIAL_DEEMPHASIS   8

Definition at line 100 of file aisettler.cpp.

◆ GROWTH_PRIORITY

#define GROWTH_PRIORITY   15

Definition at line 89 of file aisettler.cpp.

◆ NAVAL_EMPHASIS

#define NAVAL_EMPHASIS   20

Definition at line 103 of file aisettler.cpp.

◆ PERFECTION

#define PERFECTION   3

Definition at line 95 of file aisettler.cpp.

◆ RESULT_IS_ENOUGH

#define RESULT_IS_ENOUGH   250

Definition at line 85 of file aisettler.cpp.

Function Documentation

◆ city_desirability()

std::unique_ptr< cityresult > city_desirability ( struct ai_type ait,
struct player pplayer,
struct unit punit,
struct tile ptile 
)

Calculates the desire for founding a new city at 'ptile'.

The citymap ensures that we do not build cities too close to each other. Returns nullptr if no place was found.

Definition at line 658 of file aisettler.cpp.

Referenced by settler_map_iterate().

◆ cityresult_fill()

static std::unique_ptr< cityresult > cityresult_fill ( struct ai_type ait,
struct player pplayer,
struct tile center 
)
static

Fill cityresult struct with useful info about the city spot.

It must contain valid x, y coordinates and total should be zero.

We assume whatever best government we are aiming for.

We always return valid other_x and other_y if total > 0.

Definition at line 227 of file aisettler.cpp.

Referenced by city_desirability().

◆ contemplate_new_city()

void contemplate_new_city ( struct ai_type ait,
struct city pcity 
)

Return want for city settler.

Note that we rely here on the fact that ai_settler_init() has been run while doing autosettlers.

Definition at line 1228 of file aisettler.cpp.

Referenced by dai_manage_cities().

◆ dai_auto_settler_cont()

void dai_auto_settler_cont ( struct ai_type ait,
struct player pplayer,
struct unit punit,
struct settlermap state 
)

Auto settler continuing its work.

Definition at line 1113 of file aisettler.cpp.

Referenced by cai_auto_settler_cont(), texwai_auto_settler_cont(), and twai_auto_settler_cont().

◆ dai_auto_settler_free()

void dai_auto_settler_free ( struct ai_plr ai)

Deinitialize ai settler engine.

Definition at line 1158 of file aisettler.cpp.

Referenced by dai_data_close().

◆ dai_auto_settler_init()

void dai_auto_settler_init ( struct ai_plr ai)

Initialize ai settler engine.

Definition at line 945 of file aisettler.cpp.

Referenced by dai_data_init().

◆ dai_auto_settler_reset()

void dai_auto_settler_reset ( struct ai_type ait,
struct player pplayer 
)

Reset ai settler engine.

Definition at line 1124 of file aisettler.cpp.

Referenced by cai_auto_settler_reset(), dai_manage_cities(), texwai_auto_settler_reset(), and twai_auto_settler_reset().

◆ dai_auto_settler_run()

void dai_auto_settler_run ( struct ai_type ait,
struct player pplayer,
struct unit punit,
struct settlermap state 
)

Auto settler that can also build cities.

Definition at line 964 of file aisettler.cpp.

Referenced by cai_auto_settler_run(), texwai_auto_settler_run(), and twai_auto_settler_run().

◆ dai_do_build_city()

static bool dai_do_build_city ( struct ai_type ait,
struct player pplayer,
struct unit punit 
)
static

Build a city and initialize AI infrastructure cache.

Definition at line 1172 of file aisettler.cpp.

Referenced by dai_auto_settler_run().

◆ find_best_city_placement()

static std::unique_ptr< cityresult > find_best_city_placement ( struct ai_type ait,
struct unit punit,
bool  look_for_boat,
bool  use_virt_boat 
)
static

Find nearest and best city placement or (TODO) a city to immigrate to.

Option look_for_boat forces us to find a (real) boat before considering going overseas. Option use_virt_boat allows to use virtual boat but only if punit is in a coastal city right now (should only be used by virtual units). I guess it won't hurt to remove this condition, PF will just give no positions. If (!look_for_boat && !use_virt_boat), will not consider placements overseas.

Returns the better cityresult or nullptr if no result was found.

Definition at line 835 of file aisettler.cpp.

Referenced by contemplate_new_city(), and dai_auto_settler_run().

◆ food_starvation()

static bool food_starvation ( const std::unique_ptr< cityresult > &  result)
static

Check if a city on this location would starve.

Definition at line 517 of file aisettler.cpp.

Referenced by city_desirability(), and print_cityresult().

◆ naval_bonus()

static int naval_bonus ( const std::unique_ptr< cityresult > &  result)
static

Add bonus for coast.

Definition at line 575 of file aisettler.cpp.

Referenced by city_desirability(), and print_cityresult().

◆ print_cityresult()

static void print_cityresult ( struct player pplayer,
const std::unique_ptr< cityresult > &  cr 
)
static

For debugging, print the city result table.

Definition at line 590 of file aisettler.cpp.

Referenced by dai_auto_settler_run().

◆ result_defense_bonus()

static int result_defense_bonus ( struct player pplayer,
const std::unique_ptr< cityresult > &  result 
)
static

Calculate defense bonus, which is a % of total results equal to a given % of the defense bonus %.

Definition at line 544 of file aisettler.cpp.

Referenced by city_desirability(), and print_cityresult().

◆ settler_map_iterate()

static std::unique_ptr< cityresult > settler_map_iterate ( struct ai_type ait,
struct pf_parameter parameter,
struct unit punit,
int  boat_cost 
)
static

Find nearest and best city placement in a PF iteration according to "parameter".

The value in "boat_cost" is both the penalty to pay for using a boat and an indicator (boat_cost != 0) if a boat was used at all. The result is returned in "best".

Return value is a 'struct cityresult' if found something better than what was originally in "best" was found; else nullptr.

TODO: Transparently check if we should add ourselves to an existing city.

Definition at line 740 of file aisettler.cpp.

Referenced by find_best_city_placement().

◆ shield_starvation()

static bool shield_starvation ( const std::unique_ptr< cityresult > &  result)
static

Check if a city on this location would lack shields.

Definition at line 532 of file aisettler.cpp.

Referenced by city_desirability(), and print_cityresult().

◆ tdc_plr_get()

static const struct tile_data_cache * tdc_plr_get ( struct ai_type ait,
struct player plr,
int  tindex 
)
static

Return player's tile data cache.

Definition at line 461 of file aisettler.cpp.

Referenced by cityresult_fill().

◆ tdc_plr_set()

static void tdc_plr_set ( struct ai_type ait,
struct player plr,
int  tindex,
const struct tile_data_cache tdcache 
)
static

Store player's tile data cache.

Definition at line 494 of file aisettler.cpp.

Referenced by cityresult_fill().

◆ tile_data_cache_copy()

struct tile_data_cache * tile_data_cache_copy ( const struct tile_data_cache ptdc)

Make copy of tile data cache.

Definition at line 439 of file aisettler.cpp.

Referenced by cityresult_fill().

◆ tile_data_cache_new()

struct tile_data_cache * tile_data_cache_new ( )

Allocate tile data cache.

Definition at line 425 of file aisettler.cpp.

Referenced by cityresult_fill(), and tile_data_cache_copy().