56 #define FERRY_AVAILABLE (-1)
57 #define FERRY_ABANDON_BOSS \
65 #define FERRY_WANTED (-1)
71 #define LOGLEVEL_FERRY LOG_DEBUG
73 #define LOGLEVEL_GOBYBOAT LOG_DEBUG
75 #define LOGLEVEL_FINDFERRY LOG_DEBUG
78 #define LOGLEVEL_FERRY_STATS LOG_NORMAL
122 #ifdef LOGLEVEL_FERRY_STATS
123 static void aiferry_print_stats(
struct ai_type *ait,
struct player *pplayer)
128 log_base(LOGLEVEL_FERRY_STATS,
"Boat stats for %s[%d]",
130 log_base(LOGLEVEL_FERRY_STATS,
"Registered: %d free out of total %d",
135 log_base(LOGLEVEL_FERRY_STATS,
"#%d. %s[%d], psngr=%d", n,
194 if (old_f && !new_f) {
205 if (passenger !=
nullptr) {
209 }
else if (!old_f && new_f) {
307 unit_data->
done =
true;
359 #ifdef LOGLEVEL_FERRY_STATS
372 qCritical(
"Player[%d] in turn %d: boats miscounted.",
374 aiferry_print_stats(ait, pplayer);
398 const struct tile *tgt_tile,
498 struct pf_map *search_map;
551 int u_turns = pos.turn;
556 int turns =
MAX(u_turns, f_turns);
558 if (turns < best_turns) {
560 "Found a potential boat %s[%d](%d,%d)(moves left: %d)",
636 struct unit *passenger,
643 int pass_id = passenger->
id;
668 if (alive &&
unit_tile(passenger) != ptile) {
671 struct tile *next_tile;
678 next_tile = path[1].tile;
680 int ferry_id = ferry->
id;
683 "Our boat has arrived "
684 "[%d](moves left: %d)",
727 struct unit *passenger,
struct tile *ptile)
735 if (parameter.land.get_TB !=
no_fights) {
762 struct unit *punit,
struct tile *dest_tile,
768 struct unit *ferryboat =
nullptr;
769 int cap = with_bodyguard ? 2 : 1;
780 "in ai_gothere cannot find any boats.");
788 "found boat[%d](%d,%d), going there", boatid,
836 ACTION_TRANSPORT_BOARD);
849 "got boat[%d](moves left: %d), going (%d,%d)", ferryboat->
id,
879 ACTION_TRANSPORT_BOARD);
896 "Cannot command boat [%d],"
924 if (passengers <= 0) {
949 "Found a potential cargo %s[%d](%d,%d), going there",
966 "AI Passengers counting reported false positive %d", passengers);
999 parameter.omniscience =
false;
1006 if (pos.turn >= turns_horizon) {
1018 bool really_needed =
true;
1027 "%s is NOT suitable: "
1028 "will finish building its own ferry too soon",
1033 if (turns >= turns_horizon) {
1035 "%s is NOT suitable: "
1036 "has just started building",
1046 "%s is NOT suitable: "
1047 "has another ferry",
1049 really_needed =
false;
1055 if (really_needed) {
1057 "will go to %s unless we "
1058 "find something better",
1061 turns_horizon = turns;
1086 int sanity = punit->
id;
1122 "recorded passenger[%d] is not on board, checking for "
1131 struct unit *candidate =
nullptr;
1156 "appointed %s[%d] our passenger-in-charge",
1158 bossid = candidate->
id;
1188 }
else if (unit_data->
passenger == bossid
1227 "Ferryboat is not carrying anyone "
1228 "(moves left: %d).",
1256 unit_data->
done =
true;
1262 unit_data->
done =
true;
1269 "Passing control of ferry to explorer code");
1278 unit_data->
done =
true;
1285 if (safe_city !=
nullptr) {
1288 unit_data->
done =
true;
bool adv_unit_execute_path(struct unit *punit, const PFPath &path)
This is a function to execute paths returned by the path-finding engine, for units controlled by advi...
bool adv_follow_path(struct unit *punit, const PFPath &path, struct tile *ptile)
Move a unit along a path without disturbing its activity, role or assigned destination Return FALSE i...
bool is_ai_data_phase_open(struct ai_type *ait, struct player *pplayer)
Return whether data phase is currently open.
void dai_data_phase_finished(struct ai_type *ait, struct player *pplayer)
Clean up ai data after phase finished.
struct ai_plr * dai_plr_data_get(struct ai_type *ait, struct player *pplayer, bool *caller_closes)
Get current default ai data related to player.
static bool aiferry_findcargo(struct ai_type *ait, struct unit *pferry)
A helper for ai_manage_ferryboat.
static int combined_land_sea_move(const struct tile *src_tile, enum pf_move_scope src_scope, const struct tile *tgt_tile, enum pf_move_scope dst_scope, const struct pf_parameter *param)
Combined cost function for a land unit looking for a ferry.
static void dai_activate_passengers(struct ai_type *ait, struct unit *ferry)
Manage the passengers on a ferry, even if they are asleep.
bool aiferry_gobyboat(struct ai_type *ait, struct player *pplayer, struct unit *punit, struct tile *dest_tile, bool with_bodyguard)
This function is to be called if punit needs to use a boat to get to the destination.
int aiferry_find_boat(struct ai_type *ait, struct unit *punit, int cap, PFPath *path)
Proper and real PF function for finding a boat.
void dai_manage_ferryboat(struct ai_type *ait, struct player *pplayer, struct unit *punit)
It's about 12 feet square and has a capacity of almost 1000 pounds.
bool is_boat_free(struct ai_type *ait, struct unit *boat, struct unit *punit, int cap)
Runs a few checks to determine if "boat" is a free boat that can carry "cap" units of the same type a...
static int sea_move(const struct tile *ptile, enum known_type known, const struct pf_parameter *param)
EC callback to account for the cost of sea moves by a ferry hurrying to pick our unit up.
bool dai_is_ferry_type(const struct unit_type *pferry, struct ai_type *ait)
Print the list of boats of pplayer.
void aiferry_init_stats(struct ai_type *ait, struct player *pplayer)
Call to initialize the ferryboat statistics.
static bool aiferry_find_interested_city(struct ai_type *ait, struct unit *pferry)
A helper for ai_manage_ferryboat.
#define LOGLEVEL_FINDFERRY
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.
bool aiferry_goto_amphibious(struct ai_type *ait, struct unit *ferry, struct unit *passenger, struct tile *ptile)
Move a passenger on a ferry to a specified destination.
bool is_boss_of_boat(struct ai_type *ait, struct unit *punit)
Check if unit is boss in ferry.
static void aiferry_psngr_meet_boat(struct ai_type *ait, struct unit *punit, struct unit *pferry)
Assign the passenger to the boat and vice versa.
static void aiferry_make_available(struct ai_type *ait, struct unit *pferry)
Mark the ferry as available and update the statistics.
static int aiferry_find_boat_nearby(struct ai_type *ait, struct unit *punit, int cap)
Find a boat within one move from us (i.e.
int aiferry_avail_boats(struct ai_type *ait, struct player *pplayer)
Returns the number of available boats.
#define LOGLEVEL_GOBYBOAT
bool dai_amphibious_goto_constrained(struct ai_type *ait, struct unit *ferry, struct unit *passenger, struct tile *ptile, struct pft_amphibious *parameter)
Move a passenger on a ferry to a specified destination.
bool dai_is_ferry(struct unit *pferry, struct ai_type *ait)
Should unit be considered a ferry?
#define FERRY_ABANDON_BOSS
void dai_ferry_init_ferry(struct ai_type *ait, struct unit *ferry)
Initialize new ferry when player gets it.
void aiferry_clear_boat(struct ai_type *ait, struct unit *punit)
Use on a unit which no longer needs a boat.
static void aiferry_request_boat(struct ai_type *ait, struct unit *punit)
Request a boat for the unit.
void aiguard_request_guard(struct ai_type *ait, struct unit *punit)
Request a (new) bodyguard for the unit.
struct unit * aiguard_guard_of(struct ai_type *ait, struct unit *charge)
Which unit, if any, is the body guard of a unit? Returns nullptr if the unit has not been assigned a ...
static struct ai_plr * def_ai_player_data(const struct player *pplayer, struct ai_type *deftype)
static struct ai_city * def_ai_city_data(const struct city *pcity, struct ai_type *deftype)
static struct unit_ai * def_ai_unit_data(const struct unit *punit, struct ai_type *deftype)
void dai_manage_military(struct ai_type *ait, struct player *pplayer, struct unit *punit)
Decide what to do with a military unit.
struct city * find_nearest_safe_city(struct unit *punit)
Find safe city to recover in.
void dai_manage_unit(struct ai_type *ait, struct player *pplayer, struct unit *punit)
manage one unit Careful: punit may have been destroyed upon return from this routine!
#define IS_ATTACKER(ptype)
enum unit_move_result manage_auto_explorer(struct unit *punit)
Handle eXplore mode of a unit (explorers are always in eXplore mode for AI) - explores unknown territ...
struct player * city_owner(const struct city *pcity)
Return the owner of the city.
const char * city_name_get(const struct city *pcity)
Return the name of the city.
int city_production_turns_to_build(const struct city *pcity, bool include_shield_stock)
Calculates the turns which are needed to build the requested production in the city.
bool advance(struct tile *ptile)
Remove the part of a path leading up to a given tile.
struct unit * game_unit_by_number(int id)
Find unit out of all units in game: now uses fast idex method, instead of looking through all units o...
bool has_handicap(const struct player *pplayer, enum handicap_type htype)
AI players may have handicaps - allowing them to cheat or preventing them from using certain algorith...
#define fc_assert_ret(condition)
#define fc_assert(condition)
#define fc_assert_ret_val(condition, val)
#define log_base(level, message,...)
bool is_tiles_adjacent(const struct tile *tile0, const struct tile *tile1)
Are two tiles adjacent to each other.
bool same_pos(const struct tile *tile1, const struct tile *tile2)
Are (x1,y1) and (x2,y2) really the same when adjusted? This function might be necessary ALOT of place...
int real_map_distance(const struct tile *tile0, const struct tile *tile1)
Return real distance between two tiles.
#define square_iterate(nmap, center_tile, radius, tile_itr)
#define square_iterate_end
static int map_move_cost(const struct civ_map *nmap, const struct player *pplayer, const struct unit_type *punittype, const struct tile *src_tile, const struct tile *dst_tile)
bool can_unit_transport(const struct unit *transporter, const struct unit *transported)
Return true iff transporter has ability to transport transported.
struct pf_map * pf_map_new(const struct pf_parameter *parameter)
Factory function to create a new map according to the parameter.
PFPath pf_map_path(struct pf_map *pfm, struct tile *ptile)
CHECK DOCS AFTER FULL CONVERSTION OF pf_path to class PFPath Tries to find the best path in the given...
void pf_map_destroy(struct pf_map *pfm)
After usage the map must be destroyed.
PFPath pf_map_iter_path(struct pf_map *pfm)
Return the path to our current position.This is equivalent to pf_map_path(pfm, pf_map_iter(pfm)).
#define pf_map_positions_iterate_end
#define pf_map_tiles_iterate(ARG_pfm, NAME_tile, COND_from_start)
#define pf_map_positions_iterate(ARG_pfm, NAME_pos, COND_from_start)
#define pf_map_tiles_iterate_end
int player_number(const struct player *pplayer)
Return the player index/number/id.
const char * player_name(const struct player *pplayer)
Return the leader name of the player.
static bool is_barbarian(const struct player *pplayer)
#define UNIT_LOG(_, punit, msg,...)
struct ai_plr::@155 stats
struct universal production
struct packet_game_info info
enum tile_behavior(* get_TB)(const struct tile *ptile, enum known_type known, const struct pf_parameter *param)
int(* get_EC)(const struct tile *ptile, enum known_type known, const struct pf_parameter *param)
const struct player * owner
bool(* get_zoc)(const struct player *pplayer, const struct tile *ptile, const struct civ_map *zmap)
int(* get_MC)(const struct tile *from_tile, enum pf_move_scope src_move_scope, const struct tile *to_tile, enum pf_move_scope dst_move_scope, const struct pf_parameter *param)
const struct unit_type * utype
struct pf_parameter combined
struct pf_parameter land sea
struct unit_class::@80 adv
struct unit_list * transporting
bool is_terrain_class_near_tile(const struct tile *ptile, enum terrain_class tclass)
Is there terrain of the given class near tile? (Does not check ptile itself.)
#define is_ocean_tile(ptile)
struct city * tile_city(const struct tile *ptile)
Return the city on this tile (or nullptr), checking for city center.
const struct unit_type * utype
int get_transporter_occupancy(const struct unit *ptrans)
Return how many units are in the transport.
bool unit_is_alive(int id)
Check if unit with given id is still alive.
bool is_losing_hp(const struct unit *punit)
Does unit lose hitpoints each turn?
bool can_unit_load(const struct unit *pcargo, const struct unit *ptrans)
Return TRUE iff the given unit can be loaded into the transporter.
struct unit * unit_transport_get(const struct unit *pcargo)
Returns the transporter of the unit or nullptr if it is not transported.
bool unit_is_cityfounder(const struct unit *punit)
Is a cityfounder unit?
int get_transporter_capacity(const struct unit *punit)
Return the number of units the transporter can hold (or 0).
bool unit_transported(const struct unit *pcargo)
Returns TRUE iff the unit is transported.
bool unit_has_orders(const struct unit *punit)
Return TRUE iff the unit is following client-side orders.
#define CHECK_UNIT(punit)
void handle_unit_do_action(struct player *pplayer, const int actor_id, const int target_id, const int sub_tgt_id, const char *name, const action_id action_type)
Handle a request to do an action.
bool unit_activity_handling(struct unit *punit, enum unit_activity new_activity)
Handle request for changing activity.
#define unit_list_iterate(unitlist, punit)
#define unit_list_iterate_safe(unitlist, _unit)
#define unit_list_iterate_end
#define unit_list_iterate_safe_end
const char * unit_rule_name(const struct unit *punit)
Return the (untranslated) rule name of the unit.
const struct unit_type * unit_type_get(const struct unit *punit)
Return the unit type for this unit.
bool utype_has_role(const struct unit_type *punittype, int role)
Return whether the given unit type has the role.
struct unit_class * unit_class_get(const struct unit *punit)
Returns unit class pointer for a unit.
bool unit_has_type_role(const struct unit *punit, enum unit_role_id role)
Return whether the unit has the given role.
bool unit_has_type_flag(const struct unit *punit, enum unit_type_flag_id flag)
Return whether the unit has the given flag.
void * utype_ai_data(const struct unit_type *ptype, const struct ai_type *ai)
Return pointer to ai data of given unit type and ai type.
static bool utype_has_flag(const struct unit_type *punittype, int flag)