14 #include <fc_config.h>
59 #define TAI_AIT struct ai_type *ait = tai_get_self();
60 #define TAI_TFUNC(_func, ...) _func(ait, ##__VA_ARGS__);
61 #define TAI_DFUNC(_func, ...) _func(ait, ##__VA_ARGS__);
71 ait->private =
nullptr;
101 TAI_DFUNC(dai_player_save,
"tai", pplayer, file, plrno);
111 TAI_DFUNC(dai_player_load,
"tai", pplayer, file, plrno);
194 const struct city *pcity,
const char *citystr)
204 struct city *pcity,
const char *citystr)
243 struct city *wonder_city)
336 struct pf_path *path,
int step)
357 const struct unit *punit,
const char *unitstr)
367 struct unit *punit,
const char *unitstr)
486 enum casus_belli_range scope,
487 const struct action *paction,
499 const struct city *pcity)
509 const struct unit *punit)
565 if (!has_thread_cond_impl()) {
566 qCritical(
_(
"This Freeciv21 compilation has no full threads "
567 "implementation, threaded ai cannot be used."));
571 qstrncpy(ai->
name,
"threaded",
sizeof(ai->
name));
575 ai->private->contemplace_workers =
true;
void dai_gov_value(struct ai_type *ait, struct player *pplayer, struct government *gov, adv_want *val, bool *override)
Set value of the government.
void dai_data_phase_begin(struct ai_type *ait, struct player *pplayer, bool is_new_phase)
Make and cache lots of calculations needed for other functions.
void dai_data_phase_finished(struct ai_type *ait, struct player *pplayer)
Clean up ai data after phase finished.
void dai_ferry_lost(struct ai_type *ait, struct unit *punit)
Close ferry when player loses it.
void dai_ferry_transformed(struct ai_type *ait, struct unit *ferry, const struct unit_type *old)
Update ferry system when unit is transformed.
void dai_ferry_init_ferry(struct ai_type *ait, struct unit *ferry)
Initialize new ferry when player gets it.
void dai_do_last_activities(struct ai_type *ait, struct player *pplayer)
Activities to be done by AI after human turn.
void dai_do_first_activities(struct ai_type *ait, struct player *pplayer)
Activities to be done by AI before human turn.
void dai_unit_log(struct ai_type *ait, char *buffer, int buflength, const struct unit *punit)
Produce logline fragment for srv_log.
void dai_city_log(struct ai_type *ait, char *buffer, int buflength, const struct city *pcity)
Produce logline fragment for srv_log.
void dai_player_copy(struct ai_type *ait, struct player *original, struct player *created)
Copy default ai data from player to player.
void dai_gained_control(struct ai_type *ait, struct player *pplayer)
Ai got control of the player.
void dai_auto_settler_cont(struct ai_type *ait, struct player *pplayer, struct unit *punit, struct settlermap *state)
Auto settler continuing its work.
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.
void dai_auto_settler_reset(struct ai_type *ait, struct player *pplayer)
Reset ai settler engine.
void dai_unit_save(struct ai_type *ait, const char *aitstr, struct section_file *file, const struct unit *punit, const char *unitstr)
Save AI data of a unit.
void dai_units_ruleset_init(struct ai_type *ait)
Initialise the unit data from the ruleset for the AI.
void dai_switch_to_explore(struct ai_type *ait, struct unit *punit, struct tile *target, enum override_bool *allow)
Switch to autoexploring.
void dai_unit_turn_end(struct ai_type *ait, struct unit *punit)
Free unit from use with default AI.
void dai_unit_init(struct ai_type *ait, struct unit *punit)
Initialize unit for use with default AI.
void dai_consider_tile_dangerous(struct ai_type *ait, struct tile *ptile, struct unit *punit, enum override_bool *result)
Are there dangerous enemies at or adjacent to the tile 'ptile'?
void dai_unit_load(struct ai_type *ait, const char *aitstr, const struct section_file *file, struct unit *punit, const char *unitstr)
Load AI data of a unit.
void dai_unit_close(struct ai_type *ait, struct unit *punit)
Free unit from use with default AI.
void dai_units_ruleset_close(struct ai_type *ait)
Close AI unit type data.
void dai_city_save(struct ai_type *ait, const char *aitstr, struct section_file *file, const struct city *pcity, const char *citystr)
Write ai city segments to savefile.
void dai_city_load(struct ai_type *ait, const char *aitstr, const struct section_file *file, struct city *pcity, const char *citystr)
Load ai city segment from savefile.
void dai_city_alloc(struct ai_type *ait, struct city *pcity)
Initialize city for use with default AI.
void dai_consider_wonder_city(struct ai_type *ait, struct city *pcity, bool *result)
Is it ok for advisor code to consider given city as wonder city?
void dai_build_adv_adjust(struct ai_type *ait, struct player *pplayer, struct city *wonder_city)
Calculate how much an AI player should want to build particular improvements, because of the effects ...
void dai_city_free(struct ai_type *ait, struct city *pcity)
Free city from use with default AI.
void dai_build_adv_init(struct ai_type *ait, struct player *pplayer)
Initialize building advisor.
void dai_treaty_accepted(struct ai_type *ait, struct player *pplayer, struct player *aplayer, struct Treaty *ptreaty)
This function is called when a treaty has been concluded, to deal with followup issues like comments ...
void dai_incident(struct ai_type *ait, enum incident_type type, enum casus_belli_range scope, const struct action *paction, struct player *receiver, struct player *violator, struct player *victim)
Handle incident caused by violator.
void dai_diplomacy_actions(struct ai_type *ait, struct player *pplayer)
Do diplomatic actions.
void dai_treaty_evaluate(struct ai_type *ait, struct player *pplayer, struct player *aplayer, struct Treaty *ptreaty)
pplayer is AI player, aplayer is the other player involved, treaty is the treaty being considered.
void dai_diplomacy_first_contact(struct ai_type *ait, struct player *pplayer, struct player *aplayer)
What to do when we first meet.
void dai_wonder_city_distance(struct ai_type *ait, struct player *pplayer, struct adv_data *adv)
Calculate walking distances to wonder city from nearby cities.
void dai_assess_danger_player(struct ai_type *ait, struct player *pplayer, const struct civ_map *dmap)
Call assess_danger() for all cities owned by pplayer.
void(* log_fragment_unit)(char *buffer, int buflength, const struct unit *punit)
void(* city_alloc)(struct city *pcity)
void(* created_by_civil_war)(struct player *original, struct player *created)
void(* consider_tile_dangerous)(struct tile *ptile, struct unit *punit, enum override_bool *result)
void(* unit_lost)(struct unit *punit)
void(* treaty_evaluate)(struct player *pplayer, struct player *aplayer, struct Treaty *ptreaty)
void(* gov_value)(struct player *pplayer, struct government *gov, adv_want *val, bool *override)
void(* treaty_accepted)(struct player *pplayer, struct player *aplayer, struct Treaty *ptreaty)
void(* unit_transformed)(struct unit *punit, const struct unit_type *old_type)
void(* log_fragment_city)(char *buffer, int buflength, const struct city *pcity)
void(* unit_move)(struct unit *punit, struct tile *ptile, const PFPath &path, int step)
void(* settler_run)(struct player *pplayer, struct unit *punit, struct settlermap *state)
void(* unit_load)(const struct section_file *file, struct unit *punit, const char *unitstr)
void(* unit_free)(struct unit *punit)
void(* phase_finished)(struct player *pplayer)
void(* restart_phase)(struct player *pplayer)
void(* settler_reset)(struct player *pplayer)
void(* unit_save)(struct section_file *file, const struct unit *punit, const char *unitstr)
void(* refresh)(struct player *pplayer)
void(* diplomacy_actions)(struct player *pplayer)
void(* player_alloc)(struct player *pplayer)
void(* build_adv_prepare)(struct player *pplayer, struct adv_data *adv)
void(* build_adv_adjust_want)(struct player *pplayer, struct city *wonder_city)
void(* player_load)(struct player *pplayer, const struct section_file *file, int plrno)
void(* build_adv_init)(struct player *pplayer)
void(* unit_task)(struct unit *punit, enum adv_unit_task task, struct tile *ptile)
void(* last_activities)(struct player *pplayer)
void(* incident)(enum incident_type type, enum casus_belli_range scope, const struct action *paction, struct player *receiver, struct player *violator, struct player *victim)
void(* settler_cont)(struct player *pplayer, struct unit *punit, struct settlermap *state)
void(* first_contact)(struct player *pplayer, struct player *aplayer)
void(* city_save)(struct section_file *file, const struct city *pcity, const char *citystr)
void(* consider_wonder_city)(struct city *pcity, bool *result)
void(* city_free)(struct city *pcity)
void(* choose_building)(struct city *pcity, struct adv_choice *choice)
struct ai_type::@12 funcs
void(* city_load)(const struct section_file *file, struct city *pcity, const char *citystr)
void(* phase_begin)(struct player *pplayer, bool new_phase)
void(* player_free)(struct player *pplayer)
void(* split_by_civil_war)(struct player *original, struct player *created)
void(* unit_turn_end)(struct unit *punit)
void(* unit_alloc)(struct unit *punit)
void(* gained_control)(struct player *pplayer)
void(* unit_got)(struct unit *punit)
void(* player_save)(struct player *pplayer, struct section_file *file, int plrno)
void(* first_activities)(struct player *pplayer)
void(* consider_plr_dangerous)(struct player *plr1, struct player *plr2, enum override_bool *result)
void(* units_ruleset_init)()
void(* lost_control)(struct player *pplayer)
void(* units_ruleset_close)()
void(* want_to_explore)(struct unit *punit, struct tile *target, enum override_bool *allow)
void tai_phase_finished(struct ai_type *ait, struct player *pplayer)
Player phase has finished.
void tai_first_activities(struct ai_type *ait, struct player *pplayer)
Time for phase first activities.
void tai_control_gained(struct ai_type *ait, struct player *pplayer)
We actually control the player.
void tai_control_lost(struct ai_type *ait, struct player *pplayer)
We no longer control the player.
void tai_player_alloc(struct ai_type *ait, struct player *pplayer)
Initialize player for use with threaded AI.
void tai_player_free(struct ai_type *ait, struct player *pplayer)
Free player from use with threaded AI.
void tai_init_threading(void)
Initialize ai thread.
void tai_refresh(struct ai_type *ait, struct player *pplayer)
Check for messages sent by player thread.
static void twai_ferry_init_ferry(struct unit *ferry)
Call default ai with threaded ai type as parameter.
static void twai_consider_plr_dangerous(struct player *plr1, struct player *plr2, enum override_bool *result)
Call default ai with threaded ai type as parameter.
static void twai_refresh(struct player *pplayer)
Call default ai with threaded ai type as parameter.
static void twai_city_load(const struct section_file *file, struct city *pcity, const char *citystr)
Call default ai with threaded ai type as parameter.
static void twai_auto_settler_cont(struct player *pplayer, struct unit *punit, struct settlermap *state)
Call default ai with threaded ai type as parameter.
const char * fc_ai_threaded_capstr(void)
Return module capability string.
static void twai_incident(enum incident_type type, enum casus_belli_range scope, const struct action *paction, struct player *receiver, struct player *violator, struct player *victim)
Call default ai with threaded ai type as parameter.
static void twai_city_alloc(struct city *pcity)
Call default ai with threaded ai type as parameter.
static void twai_control_lost(struct player *pplayer)
Call default ai with threaded ai type as parameter.
static void twai_diplomacy_first_contact(struct player *pplayer, struct player *aplayer)
Call default ai with threaded ai type as parameter.
static void twai_city_log(char *buffer, int buflength, const struct city *pcity)
Call default ai with threaded ai type as parameter.
static void twai_control_gained(struct player *pplayer)
Call default ai with threaded ai type as parameter.
static void twai_treaty_evaluate(struct player *pplayer, struct player *aplayer, struct Treaty *ptreaty)
Call default ai with threaded ai type as parameter.
static void twai_first_activities(struct player *pplayer)
Call default ai with threaded ai type as parameter.
bool fc_ai_threaded_setup(struct ai_type *ai)
Setup player ai_funcs function pointers.
static void twai_auto_settler_run(struct player *pplayer, struct unit *punit, struct settlermap *state)
Call default ai with threaded ai type as parameter.
static void tai_module_close(void)
Free resources allocated by the threaded AI module.
static void twai_diplomacy_actions(struct player *pplayer)
Call default ai with threaded ai type as parameter.
static void twai_ferry_lost(struct unit *punit)
Call default ai with threaded ai type as parameter.
static void twai_player_alloc(struct player *pplayer)
Call default ai with threaded ai type as parameter.
static void twai_build_adv_override(struct city *pcity, struct adv_choice *choice)
Call default ai with threaded ai type as parameter.
static void twai_player_save(struct player *pplayer, struct section_file *file, int plrno)
Call default ai with threaded ai type as parameter.
static void twai_build_adv_init(struct player *pplayer)
Call default ai with threaded ai type as parameter.
static void twai_unit_move_or_attack(struct unit *punit, struct tile *ptile, struct pf_path *path, int step)
Call default ai with threaded ai type as parameter.
static void twai_phase_begin(struct player *pplayer, bool is_new_phase)
Call default ai with threaded ai type as parameter.
static void twai_consider_wonder_city(struct city *pcity, bool *result)
Call default ai with threaded ai type as parameter.
static void twai_player_free(struct player *pplayer)
Call default ai with threaded ai type as parameter.
static void twai_unit_save(struct section_file *file, const struct unit *punit, const char *unitstr)
Call default ai with threaded ai type as parameter.
static void twai_restart_phase(struct player *pplayer)
Start working on the thread again.
static void twai_phase_finished(struct player *pplayer)
Call default ai with threaded ai type as parameter.
static void twai_gov_value(struct player *pplayer, struct government *gov, adv_want *val, bool *override)
Call default ai with threaded ai type as parameter.
static void twai_units_ruleset_init(void)
Call default ai with threaded ai type as parameter.
static void twai_switch_to_explore(struct unit *punit, struct tile *target, enum override_bool *allow)
Call default ai with threaded ai type as parameter.
static void twai_unit_new_adv_task(struct unit *punit, enum adv_unit_task task, struct tile *ptile)
Call default ai with threaded ai type as parameter.
static void twai_created_by_civil_war(struct player *original, struct player *created)
Call default ai with threaded ai type as parameter.
#define TAI_TFUNC(_func,...)
static void twai_last_activities(struct player *pplayer)
Call default ai with threaded ai type as parameter.
static void twai_unit_load(const struct section_file *file, struct unit *punit, const char *unitstr)
Call default ai with threaded ai type as parameter.
static void twai_treaty_accepted(struct player *pplayer, struct player *aplayer, struct Treaty *ptreaty)
Call default ai with threaded ai type as parameter.
static void twai_unit_log(char *buffer, int buflength, const struct unit *punit)
Call default ai with threaded ai type as parameter.
static struct ai_type * tai_get_self(void)
Get pointer to ai type of the threaded ai.
#define TAI_DFUNC(_func,...)
static void twai_unit_alloc(struct unit *punit)
Call default ai with threaded ai type as parameter.
static void twai_player_load(struct player *pplayer, const struct section_file *file, int plrno)
Call default ai with threaded ai type as parameter.
static void twai_units_ruleset_close(void)
Call default ai with threaded ai type as parameter.
static void twai_unit_turn_end(struct unit *punit)
Call default ai with threaded ai type as parameter.
static void twai_auto_settler_reset(struct player *pplayer)
Call default ai with threaded ai type as parameter.
static void twai_city_free(struct city *pcity)
Call default ai with threaded ai type as parameter.
static void twai_ferry_transformed(struct unit *ferry, const struct unit_type *old)
Call default ai with threaded ai type as parameter.
static void twai_split_by_civil_war(struct player *original, struct player *created)
Call default ai with threaded ai type as parameter.
static void twai_unit_free(struct unit *punit)
Call default ai with threaded ai type as parameter.
static void tai_init_self(struct ai_type *ai)
Set pointer to ai type of the threaded ai.
static void twai_consider_tile_dangerous(struct tile *ptile, struct unit *punit, enum override_bool *result)
Call default ai with threaded ai type as parameter.
static void twai_wonder_city_distance(struct player *pplayer, struct adv_data *adv)
Call default ai with threaded ai type as parameter.
static void twai_city_save(struct section_file *file, const struct city *pcity, const char *citystr)
Call default ai with threaded ai type as parameter.
static void twai_build_adv_adjust(struct player *pplayer, struct city *wonder_city)
Call default ai with threaded ai type as parameter.