Freeciv-3.2
Loading...
Searching...
No Matches
Data Structures | Macros | Enumerations | Functions
daisettler.c File Reference
#include <stdio.h>
#include <string.h>
#include "mem.h"
#include "log.h"
#include "support.h"
#include "timing.h"
#include "city.h"
#include "game.h"
#include "government.h"
#include "map.h"
#include "movement.h"
#include "packets.h"
#include "player.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 "aiferry.h"
#include "aitools.h"
#include "daicity.h"
#include "daidata.h"
#include "dailog.h"
#include "daiplayer.h"
#include "daisettler.h"
#include "spechash.h"

Go to the source code of this file.

Data Structures

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
 
#define SPECHASH_TAG   tile_data_cache
 
#define SPECHASH_INT_KEY_TYPE
 
#define SPECHASH_IDATA_TYPE   struct tile_data_cache *
 
#define SPECHASH_IDATA_FREE   tile_data_cache_destroy
 

Enumerations

enum  cb_error_level { CBE_OK , CBE_RECOVERABLE , CBE_FATAL }
 

Functions

struct tile_data_cachetile_data_cache_new (void)
 
struct tile_data_cachetile_data_cache_copy (const struct tile_data_cache *ptdc)
 
static void tile_data_cache_destroy (struct tile_data_cache *ptdc)
 
static const struct tile_data_cachetdc_plr_get (struct ai_type *ait, struct player *plr, int tindex)
 
static void tdc_plr_set (struct ai_type *ait, struct player *plr, int tindex, const struct tile_data_cache *tdcache)
 
static struct cityresultcityresult_new (struct tile *ptile)
 
static void cityresult_destroy (struct cityresult *result)
 
static struct cityresultcityresult_fill (struct ai_type *ait, struct player *pplayer, struct tile *center)
 
static bool food_starvation (const struct cityresult *result)
 
static bool shield_starvation (const struct cityresult *result)
 
static adv_want result_defense_bonus (struct player *pplayer, const struct cityresult *result)
 
static adv_want naval_bonus (const struct cityresult *result)
 
static void print_cityresult (struct player *pplayer, const struct cityresult *cr)
 
struct cityresultcity_desirability (struct ai_type *ait, struct player *pplayer, struct unit *punit, struct tile *ptile)
 
static struct cityresultsettler_map_iterate (struct ai_type *ait, struct pf_parameter *parameter, struct unit *punit, int boat_cost)
 
static struct cityresultfind_best_city_placement (struct ai_type *ait, struct unit *punit, bool look_for_boat, bool use_virt_boat)
 
static enum cb_error_level dai_do_build_city (struct ai_type *ait, struct player *pplayer, struct unit *punit)
 
void dai_auto_settler_init (struct ai_plr *ai)
 
void dai_auto_settler_run (struct ai_type *ait, const struct civ_map *nmap, struct player *pplayer, struct unit *punit, struct settlermap *state)
 
void dai_auto_settler_cont (struct ai_type *ait, const struct civ_map *nmap, struct player *pplayer, struct unit *punit, struct settlermap *state)
 
void dai_auto_settler_reset (struct ai_type *ait, struct player *pplayer)
 
void dai_auto_settler_free (struct ai_plr *ai)
 
void contemplate_new_city (struct ai_type *ait, struct city *pcity)
 

Macro Definition Documentation

◆ DEFENSE_EMPHASIS

#define DEFENSE_EMPHASIS   20

Definition at line 116 of file daisettler.c.

◆ FERRY_TECH_WANT

#define FERRY_TECH_WANT   500

Definition at line 96 of file daisettler.c.

◆ GROWTH_POTENTIAL_DEEMPHASIS

#define GROWTH_POTENTIAL_DEEMPHASIS   8

Definition at line 109 of file daisettler.c.

◆ GROWTH_PRIORITY

#define GROWTH_PRIORITY   15

Definition at line 98 of file daisettler.c.

◆ NAVAL_EMPHASIS

#define NAVAL_EMPHASIS   20

Definition at line 112 of file daisettler.c.

◆ PERFECTION

#define PERFECTION   3

Definition at line 104 of file daisettler.c.

◆ RESULT_IS_ENOUGH

#define RESULT_IS_ENOUGH   250

Definition at line 94 of file daisettler.c.

◆ SPECHASH_IDATA_FREE

#define SPECHASH_IDATA_FREE   tile_data_cache_destroy

Definition at line 140 of file daisettler.c.

◆ SPECHASH_IDATA_TYPE

#define SPECHASH_IDATA_TYPE   struct tile_data_cache *

Definition at line 139 of file daisettler.c.

◆ SPECHASH_INT_KEY_TYPE

#define SPECHASH_INT_KEY_TYPE

Definition at line 138 of file daisettler.c.

◆ SPECHASH_TAG

#define SPECHASH_TAG   tile_data_cache

Definition at line 137 of file daisettler.c.

Enumeration Type Documentation

◆ cb_error_level

Enumerator
CBE_OK 
CBE_RECOVERABLE 
CBE_FATAL 

Definition at line 185 of file daisettler.c.

Function Documentation

◆ city_desirability()

struct 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 NULL if no place was found.

Definition at line 713 of file daisettler.c.

Referenced by settler_map_iterate().

◆ cityresult_destroy()

static void cityresult_destroy ( struct cityresult result)
static

◆ cityresult_fill()

static struct 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 275 of file daisettler.c.

Referenced by city_desirability().

◆ cityresult_new()

static struct cityresult * cityresult_new ( struct tile ptile)
static

Allocated a city result.

Definition at line 224 of file daisettler.c.

Referenced by cityresult_fill().

◆ 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 citymap_turn_init() has been run while doing autosettlers.

Definition at line 1327 of file daisettler.c.

Referenced by dai_manage_cities().

◆ dai_auto_settler_cont()

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

Auto settler continuing its work.

Definition at line 1206 of file daisettler.c.

Referenced by cai_auto_settler_cont(), and texwai_auto_settler_cont().

◆ dai_auto_settler_free()

void dai_auto_settler_free ( struct ai_plr ai)

Deinitialize ai settler engine.

Definition at line 1250 of file daisettler.c.

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 1013 of file daisettler.c.

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 1219 of file daisettler.c.

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

◆ dai_auto_settler_run()

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

Auto settler that can also build cities.

Definition at line 1032 of file daisettler.c.

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

◆ dai_do_build_city()

static enum cb_error_level 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 1266 of file daisettler.c.

Referenced by dai_auto_settler_run().

◆ find_best_city_placement()

static struct 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 NULL if no result was found.

Definition at line 896 of file daisettler.c.

Referenced by contemplate_new_city(), and dai_auto_settler_run().

◆ food_starvation()

static bool food_starvation ( const struct cityresult result)
static

Check if a city on this location would starve.

Definition at line 569 of file daisettler.c.

Referenced by city_desirability(), and print_cityresult().

◆ naval_bonus()

static adv_want naval_bonus ( const struct cityresult result)
static

Add bonus for coast.

Definition at line 625 of file daisettler.c.

Referenced by city_desirability(), and print_cityresult().

◆ print_cityresult()

static void print_cityresult ( struct player pplayer,
const struct cityresult cr 
)
static

For debugging, print the city result table.

Definition at line 641 of file daisettler.c.

Referenced by dai_auto_settler_run().

◆ result_defense_bonus()

static adv_want result_defense_bonus ( struct player pplayer,
const struct cityresult result 
)
static

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

Definition at line 596 of file daisettler.c.

Referenced by city_desirability(), and print_cityresult().

◆ settler_map_iterate()

static struct 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 NULL.

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

Definition at line 790 of file daisettler.c.

Referenced by find_best_city_placement().

◆ shield_starvation()

static bool shield_starvation ( const struct cityresult result)
static

Check if a city on this location would lack shields.

Definition at line 584 of file daisettler.c.

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 514 of file daisettler.c.

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 ptdc 
)
static

Store player's tile data cache

Definition at line 549 of file daisettler.c.

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 484 of file daisettler.c.

Referenced by cityresult_fill().

◆ tile_data_cache_destroy()

static void tile_data_cache_destroy ( struct tile_data_cache ptdc)
static

Free resources allocated for tile data cache

Definition at line 504 of file daisettler.c.

◆ tile_data_cache_new()

struct tile_data_cache * tile_data_cache_new ( void  )

Allocate tile data cache

Definition at line 470 of file daisettler.c.

Referenced by cityresult_fill(), and tile_data_cache_copy().