Freeciv21
Develop your civilization from humble roots to a global empire
autosettlers.cpp File Reference
#include "log.h"
#include "support.h"
#include "timing.h"
#include "ai.h"
#include "city.h"
#include "game.h"
#include "government.h"
#include "map.h"
#include "movement.h"
#include "nation.h"
#include "packets.h"
#include "unitlist.h"
#include "workertask.h"
#include "citymap.h"
#include "path_finding.h"
#include "pf_tools.h"
#include "citytools.h"
#include "maphand.h"
#include "srv_log.h"
#include "unithand.h"
#include "unittools.h"
#include "advbuilding.h"
#include "advdata.h"
#include "advgoto.h"
#include "advtools.h"
#include "infracache.h"
#include "handicaps.h"
#include "autosettlers.h"
+ Include dependency graph for autosettlers.cpp:

Go to the source code of this file.

Classes

struct  settlermap
 

Macros

#define WORKER_FACTOR   1024
 
#define MAX_DEP_ROADS   5
 

Functions

void adv_settlers_free ()
 Free resources allocated for autosettlers system. More...
 
void auto_settlers_ruleset_init ()
 Initialize auto settlers based on the ruleset. More...
 
adv_want adv_settlers_road_bonus (struct tile *ptile, struct road_type *proad)
 Calculate the attractiveness of building a road/rail at the given tile. More...
 
static void consider_settler_action (const struct player *pplayer, enum unit_activity act, struct extra_type *target, adv_want extra, int new_tile_value, int old_tile_value, bool in_use, int delay, adv_want *best_value, int *best_old_tile_value, int *best_extra, bool *improve_worked, int *best_delay, enum unit_activity *best_act, struct extra_type **best_target, struct tile **best_tile, struct tile *ptile)
 Compares the best known tile improvement action with improving ptile with activity act. More...
 
static enum tile_behavior autosettler_tile_behavior (const struct tile *ptile, enum known_type known, const struct pf_parameter *param)
 Don't enter in enemy territories. More...
 
adv_want settler_evaluate_improvements (struct unit *punit, enum unit_activity *best_act, struct extra_type **best_target, struct tile **best_tile, PFPath *path, struct settlermap *state)
 Finds tiles to improve, using punit. More...
 
struct citysettler_evaluate_city_requests (struct unit *punit, struct worker_task **best_task, PFPath *path, struct settlermap *state)
 Return best city request to fulfill. More...
 
void auto_settler_findwork (struct player *pplayer, struct unit *punit, struct settlermap *state, int recursion)
 Find some work for our settlers and/or workers. More...
 
bool auto_settler_setup_work (struct player *pplayer, struct unit *punit, struct settlermap *state, int recursion, PFPath *path, struct tile *best_tile, enum unit_activity best_act, struct extra_type **best_target, int completion_time)
 Setup our settler to do the work it has found. More...
 
bool adv_settler_safe_tile (const struct player *pplayer, struct unit *punit, struct tile *ptile)
 Do we consider tile safe for autosettler to work? More...
 
void auto_settlers_player (struct player *pplayer)
 Run through all the players settlers and let those on ai.control work automagically. More...
 
void adv_unit_new_task (struct unit *punit, enum adv_unit_task task, struct tile *ptile)
 Change unit's advisor task. More...
 
bool auto_settlers_speculate_can_act_at (const struct unit *punit, enum unit_activity activity, bool omniscient_cheat, struct extra_type *target, const struct tile *ptile)
 Returns TRUE iff the unit can do the targeted activity at the given location. More...
 

Variables

action_id as_actions_transform [MAX_NUM_ACTIONS]
 
action_id as_actions_extra [MAX_NUM_ACTIONS]
 
action_id as_actions_rmextra [MAX_NUM_ACTIONS]
 
static civtimeras_timer = nullptr
 

Macro Definition Documentation

◆ MAX_DEP_ROADS

#define MAX_DEP_ROADS   5

◆ WORKER_FACTOR

#define WORKER_FACTOR   1024

Definition at line 61 of file autosettlers.cpp.

Function Documentation

◆ adv_settler_safe_tile()

bool adv_settler_safe_tile ( const struct player pplayer,
struct unit punit,
struct tile ptile 
)

Do we consider tile safe for autosettler to work?

Definition at line 1084 of file autosettlers.cpp.

Referenced by auto_settlers_player(), dai_auto_settler_cont(), and settler_evaluate_improvements().

◆ adv_settlers_free()

void adv_settlers_free ( )

Free resources allocated for autosettlers system.

Definition at line 77 of file autosettlers.cpp.

Referenced by server_quit().

◆ adv_settlers_road_bonus()

adv_want adv_settlers_road_bonus ( struct tile ptile,
struct road_type proad 
)

Calculate the attractiveness of building a road/rail at the given tile.

This calculates the overall benefit of connecting the civilization; this is independent from the local tile (trade) bonus granted by the road.

Definition at line 119 of file autosettlers.cpp.

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

◆ adv_unit_new_task()

void adv_unit_new_task ( struct unit punit,
enum adv_unit_task  task,
struct tile ptile 
)

◆ auto_settler_findwork()

void auto_settler_findwork ( struct player pplayer,
struct unit punit,
struct settlermap state,
int  recursion 
)

Find some work for our settlers and/or workers.

Definition at line 885 of file autosettlers.cpp.

Referenced by auto_settler_setup_work(), and auto_settlers_player().

◆ auto_settler_setup_work()

bool auto_settler_setup_work ( struct player pplayer,
struct unit punit,
struct settlermap state,
int  recursion,
PFPath path,
struct tile best_tile,
enum unit_activity  best_act,
struct extra_type **  best_target,
int  completion_time 
)

Setup our settler to do the work it has found.

Returns TRUE if started actual work.

Definition at line 957 of file autosettlers.cpp.

Referenced by auto_settler_findwork(), and dai_auto_settler_run().

◆ auto_settlers_player()

void auto_settlers_player ( struct player pplayer)

Run through all the players settlers and let those on ai.control work automagically.

Definition at line 1103 of file autosettlers.cpp.

Referenced by end_phase().

◆ auto_settlers_ruleset_init()

void auto_settlers_ruleset_init ( )

Initialize auto settlers based on the ruleset.

Definition at line 86 of file autosettlers.cpp.

Referenced by adv_units_ruleset_init().

◆ auto_settlers_speculate_can_act_at()

bool auto_settlers_speculate_can_act_at ( const struct unit punit,
enum unit_activity  activity,
bool  omniscient_cheat,
struct extra_type target,
const struct tile ptile 
)

Returns TRUE iff the unit can do the targeted activity at the given location.

Definition at line 1215 of file autosettlers.cpp.

Referenced by settler_evaluate_city_requests().

◆ autosettler_tile_behavior()

static enum tile_behavior autosettler_tile_behavior ( const struct tile ptile,
enum known_type  known,
const struct pf_parameter param 
)
static

Don't enter in enemy territories.

Definition at line 295 of file autosettlers.cpp.

Referenced by auto_settler_setup_work(), settler_evaluate_city_requests(), and settler_evaluate_improvements().

◆ consider_settler_action()

static void consider_settler_action ( const struct player pplayer,
enum unit_activity  act,
struct extra_type target,
adv_want  extra,
int  new_tile_value,
int  old_tile_value,
bool  in_use,
int  delay,
adv_want best_value,
int *  best_old_tile_value,
int *  best_extra,
bool *  improve_worked,
int *  best_delay,
enum unit_activity *  best_act,
struct extra_type **  best_target,
struct tile **  best_tile,
struct tile ptile 
)
static

Compares the best known tile improvement action with improving ptile with activity act.

Calculates the value of improving the tile by discounting the total value by the time it would take to do the work and multiplying by some factor.

Definition at line 295 of file autosettlers.cpp.

Referenced by settler_evaluate_improvements().

◆ settler_evaluate_city_requests()

struct city* settler_evaluate_city_requests ( struct unit punit,
struct worker_task **  best_task,
PFPath path,
struct settlermap state 
)

Return best city request to fulfill.

Definition at line 791 of file autosettlers.cpp.

Referenced by auto_settler_findwork(), and dai_auto_settler_run().

◆ settler_evaluate_improvements()

adv_want settler_evaluate_improvements ( struct unit punit,
enum unit_activity *  best_act,
struct extra_type **  best_target,
struct tile **  best_tile,
PFPath path,
struct settlermap state 
)

Finds tiles to improve, using punit.

The returned value is the goodness of the best tile and action found. If this return value is > 0, then best_tile indicates the tile chosen, bestact indicates the activity it wants to do, and path (if not nullptr) indicates the path to follow for the unit. If 0 is returned then there are no worthwhile activities available.

completion_time is the time that would be taken by punit to travel to and complete work at best_tile

state contains, for each tile, the unit id of the worker en route, and the eta of this worker (if any). This information is used to possibly displace this previously assigned worker. if this array is nullptr, workers are never displaced.

Definition at line 420 of file autosettlers.cpp.

Referenced by auto_settler_findwork(), contemplate_terrain_improvements(), and dai_auto_settler_run().

Variable Documentation

◆ as_actions_extra

action_id as_actions_extra[MAX_NUM_ACTIONS]

Definition at line 69 of file autosettlers.cpp.

Referenced by auto_settlers_ruleset_init().

◆ as_actions_rmextra

action_id as_actions_rmextra[MAX_NUM_ACTIONS]

Definition at line 70 of file autosettlers.cpp.

Referenced by auto_settlers_ruleset_init().

◆ as_actions_transform

action_id as_actions_transform[MAX_NUM_ACTIONS]

Definition at line 68 of file autosettlers.cpp.

Referenced by auto_settlers_ruleset_init().

◆ as_timer

civtimer* as_timer = nullptr
static

Definition at line 72 of file autosettlers.cpp.

Referenced by adv_settlers_free(), and auto_settlers_player().