69#define WORKER_FACTOR 1024
104 ACTRES_TRANSFORM_TERRAIN);
120 ACTRES_CLEAN_POLLUTION);
122 ACTRES_CLEAN_FALLOUT);
136#define MAX_DEP_ROADS 5
139 bool potential_road[12], real_road[12], is_slow[12];
140 int dx[12] = {-1, 0, 1, -1, 1, -1, 0, 1, 0, -2, 2, 0};
141 int dy[12] = {-1, -1, -1, 0, 0, 1, 1, 1, -2, 0, 0, 2};
158 pdep_roads[dep_count] = pdep;
164 for (i = 0; i < 12; i++) {
168 real_road[i] =
FALSE;
169 potential_road[i] =
FALSE;
176 potential_road[i] = real_road[i];
177 for (j = 0 ; !potential_road[i] && j < dep_count ; j++) {
184 is_slow[i] = (build_time == 0 || build_time > 5);
197 if (build_rnbr == rnbr) {
199 potential_road[i] =
TRUE;
201 for (j = 0 ; !potential_road[i] && j < dep_count ; j++) {
202 if (build_rnbr == dep_rnbr[j]) {
203 potential_road[i] =
TRUE;
217 for (i = 0; i < 12; i++) {
244 if (potential_road[0]
245 && !real_road[1] && !real_road[3]
246 && (!real_road[2] || !real_road[8])
247 && (!is_slow[2] || !is_slow[4] || !is_slow[7]
248 || !is_slow[6] || !is_slow[5])) {
251 if (potential_road[2]
252 && !real_road[1] && !real_road[4]
253 && (!real_road[7] || !real_road[10])
254 && (!is_slow[0] || !is_slow[3] || !is_slow[7]
255 || !is_slow[6] || !is_slow[5])) {
258 if (potential_road[5]
259 && !real_road[6] && !real_road[3]
260 && (!real_road[5] || !real_road[11])
261 && (!is_slow[2] || !is_slow[4] || !is_slow[7]
262 || !is_slow[1] || !is_slow[0])) {
265 if (potential_road[7]
266 && !real_road[6] && !real_road[4]
267 && (!real_road[0] || !real_road[9])
268 && (!is_slow[2] || !is_slow[3] || !is_slow[0]
269 || !is_slow[1] || !is_slow[5])) {
282 if (potential_road[1] && !real_road[4] && !real_road[3]
283 && (!is_slow[5] || !is_slow[6] || !is_slow[7])) {
286 if (potential_road[3] && !real_road[1] && !real_road[6]
287 && (!is_slow[2] || !is_slow[4] || !is_slow[7])) {
290 if (potential_road[4] && !real_road[1] && !real_road[6]
291 && (!is_slow[0] || !is_slow[3] || !is_slow[5])) {
294 if (potential_road[6] && !real_road[4] && !real_road[3]
295 && (!is_slow[0] || !is_slow[1] || !is_slow[2])) {
310 enum unit_activity act,
315 bool in_use,
int delay,
319 bool *improve_worked,
321 enum unit_activity *best_act,
323 struct tile **best_tile,
329 int old_improvement_value;
337 if (new_tile_value > old_tile_value) {
339 }
else if (
ADV_WANTS_EQ(new_tile_value, old_tile_value) && extra > 0) {
346 if (improves || extra > 0) {
347 if (!(*improve_worked) && !in_use) {
353 && old_tile_value < *best_old_tile_value))) {
355 *best_old_tile_value = old_tile_value;
358 *best_target = target;
370 base_value = new_tile_value - old_tile_value;
378 total_value =
amortize(total_value, delay);
380 if (*improve_worked) {
389 if (total_value > old_improvement_value
391 && old_tile_value > *best_old_tile_value)) {
394 *improve_worked =
TRUE;
397 *improve_worked =
FALSE;
399 *best_old_tile_value = old_tile_value;
402 *best_target = target;
444 enum unit_activity *best_act,
446 struct tile **best_tile,
459 bool improve_worked =
FALSE;
464 struct unit *enroute = NULL;
477 bool consider =
TRUE;
518 if ((enroute && enroute->
id ==
punit->
id)
522 < inbound_distance))) {
526 "Considering (%d, %d) because we're closer "
527 "(%d, %d) than %d (%d, %d)",
530 enroute->
id, eta, inbound_distance);
538 enum extra_cause cause =
540 enum extra_rmcause rmcause =
567 if (
pos.moves_left == 0) {
574 target, 0.0, base_value,
576 &best_newv, &best_oldv, &best_extra,
578 &best_delay, best_act, best_target,
585 enum unit_activity act = ACTIVITY_LAST;
586 enum unit_activity eval_act = ACTIVITY_LAST;
630 if (eval_act == ACTIVITY_LAST) {
641 if (base_value >= 0) {
647 if (
pos.moves_left == 0) {
655 int mc_multiplier = 1;
668 if (po_road->
move_cost < old_move_cost) {
683 mc_multiplier += old_move_cost;
688 * mc_multiplier / mc_divisor;
705 if (act != ACTIVITY_LAST) {
708 &best_newv, &best_oldv, &best_extra,
710 &best_delay, best_act, best_target,
740 oldv, in_use, dep_turns,
741 &best_newv, &best_oldv, &best_extra,
743 &best_delay, best_act, best_target,
751 enum unit_activity eval_dep_act = ACTIVITY_LAST;
758 eval_dep_action = try_act;
764 if (eval_dep_act != ACTIVITY_LAST) {
782 0.0, dep_value, oldv, in_use,
783 dep_turns, &best_newv, &best_oldv,
784 &best_extra, &improve_worked,
786 best_act, best_target,
800 if (!improve_worked) {
807 best_newv =
MAX(best_newv, 0);
816 *best_act = ACTIVITY_IDLE;
821 *path = *best_tile ?
pf_map_path(pfm, *best_tile) : NULL;
843 struct city *taskcity = NULL;
855 bool consider =
TRUE;
869 ptask->tgt, ptask->ptile)) {
871 struct unit *enroute = NULL;
879 int value = (ptask->want + 1) * 10 / (
pos.turn + 1);
892 && ((enroute && enroute->
id ==
punit->
id)
896 < inbound_distance)))) {
922#define LOG_SETTLER LOG_DEBUG
930 enum unit_activity best_act;
931 struct tile *best_tile = NULL;
934 struct city *taskcity;
937 int completion_time = 0;
944 log_warn(
"Workers displacing each other recursing too much.");
963 if (taskcity != NULL) {
970 best_target = best_task->
tgt;
973 path, best_task->
ptile, best_task->
act,
974 &best_target, completion_time)) {
990 &best_tile, &path, state);
999 best_tile, best_act, &best_target,
1016 struct tile *best_tile,
1017 enum unit_activity best_act,
1019 int completion_time)
1023 struct pf_map *pfm = NULL;
1025 bool working =
FALSE;
1026 struct unit *displaced;
1040 || (state[
tile_index(best_tile)].eta == completion_time
1045 "%d (%d,%d) has displaced %d (%d,%d) for worksite %d,%d",
1076 "%d itself acted due to displacement recursion. "
1077 "Was going from (%d, %d) to (%d, %d). "
1078 "Now heading from (%d, %d) to (%d, %d).",
1087 "is heading to do %s(%s) at (%d, %d)",
1088 unit_activity_name(best_act),
1116 "reached its worksite and started work");
1120 "didn't start work yet; got to (%d, %d) with "
1126 "does not find path (%d, %d) -> (%d, %d)",
1176 if (
is_ai(pplayer)) {
1200 log_debug(
"Warmth = %d, game.globalwarming=%d",
1202 log_debug(
"Frost = %d, game.nuclearwinter=%d",
1215 log_debug(
"%s %s at (%d, %d) is controlled by server side agent %s.",
1219 server_side_agent_name(SSA_AUTOSETTLER));
1227 if (!
is_ai(pplayer)) {
1237 if (!
is_ai(pplayer)) {
1246 if (
is_ai(pplayer)) {
1253 log_verbose(
"%s autosettlers consumed %g milliseconds.",
1287 enum unit_activity activity,
1288 bool omniscient_cheat,
1290 const struct tile *ptile)
1341 log_debug(
"No action found for activity %d", activity);
struct act_prob action_speculate_unit_on_extras(const struct civ_map *nmap, action_id act_id, const struct unit *actor, const struct city *actor_home, const struct tile *actor_tile, bool omniscient_cheat, const struct tile *target_tile, const struct extra_type *target_extra)
enum action_actor_kind action_get_actor_kind(const struct action *paction)
bool action_prob_possible(const struct act_prob probability)
struct act_prob action_speculate_unit_on_self(const struct civ_map *nmap, action_id act_id, const struct unit *actor, const struct city *actor_home, const struct tile *actor_tile, bool omniscient_cheat)
void action_list_end(action_id *act_list, int size)
struct act_prob action_speculate_unit_on_units(const struct civ_map *nmap, action_id act_id, const struct unit *actor, const struct city *actor_home, const struct tile *actor_tile, bool omniscient_cheat, const struct tile *target)
enum unit_activity actres_get_activity(enum action_result result)
void action_list_add_all_by_result(action_id *act_list, int *position, enum action_result result)
struct act_prob action_speculate_unit_on_city(const struct civ_map *nmap, const action_id act_id, const struct unit *actor, const struct city *actor_home, const struct tile *actor_tile, const bool omniscient_cheat, const struct city *target)
struct act_prob action_speculate_unit_on_tile(const struct civ_map *nmap, action_id act_id, const struct unit *actor, const struct city *actor_home, const struct tile *actor_tile, bool omniscient_cheat, const struct tile *target_tile, const struct extra_type *target_extra)
enum action_target_kind action_get_target_kind(const struct action *paction)
#define action_by_activity_iterate(_paction_, _activity_)
static struct action * action_by_number(action_id act_id)
#define action_by_activity_iterate_end
#define action_id_get_activity(act_id)
bool adv_follow_path(struct unit *punit, struct pf_path *path, struct tile *ptile)
#define CALL_PLR_AI_FUNC(_func, _player,...)
static void consider_settler_action(const struct player *pplayer, enum unit_activity act, struct extra_type *target, adv_want extra, adv_want new_tile_value, adv_want old_tile_value, bool in_use, int delay, adv_want *best_value, adv_want *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)
action_id as_actions_rmextra[MAX_NUM_ACTIONS]
void adv_unit_new_task(struct unit *punit, enum adv_unit_task task, struct tile *ptile)
action_id as_actions_transform[MAX_NUM_ACTIONS]
bool auto_settler_setup_work(const struct civ_map *nmap, struct player *pplayer, struct unit *punit, struct settlermap *state, int recursion, struct pf_path *path, struct tile *best_tile, enum unit_activity best_act, struct extra_type **best_target, int completion_time)
void auto_settlers_ruleset_init(void)
static enum tile_behavior autosettler_tile_behavior(const struct tile *ptile, enum known_type known, const struct pf_parameter *param)
struct city * settler_evaluate_city_requests(struct unit *punit, struct worker_task **best_task, struct pf_path **path, struct settlermap *state)
adv_want settler_evaluate_improvements(const struct civ_map *nmap, struct unit *punit, enum unit_activity *best_act, struct extra_type **best_target, struct tile **best_tile, struct pf_path **path, struct settlermap *state)
void auto_settlers_player(struct player *pplayer)
action_id as_actions_extra[MAX_NUM_ACTIONS]
adv_want adv_settlers_road_bonus(const struct civ_map *nmap, struct tile *ptile, struct road_type *proad)
bool adv_settler_safe_tile(const struct civ_map *nmap, const struct player *pplayer, struct unit *punit, struct tile *ptile)
void adv_settlers_free(void)
static struct timer * as_timer
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)
void auto_settler_findwork(const struct civ_map *nmap, struct player *pplayer, struct unit *punit, struct settlermap *state, int recursion)
#define as_transform_action_iterate_end
#define as_rmextra_action_iterate(_act_)
#define as_rmextra_action_iterate_end
#define as_extra_action_iterate_end
#define as_extra_action_iterate(_act_)
#define as_transform_action_iterate(_act_)
int city_map_radius_sq_get(const struct city *pcity)
bool city_can_work_tile(const struct city *pcity, const struct tile *ptile)
#define city_list_iterate(citylist, pcity)
#define city_tile(_pcity_)
#define city_tile_iterate_index(_nmap, _radius_sq, _city_tile, _tile, _index)
#define city_tile_iterate_index_end
#define city_list_iterate_end
void citymap_turn_init(struct player *pplayer)
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit struct unit * punit
bool has_handicap(const struct player *pplayer, enum handicap_type htype)
adv_want adv_city_worker_act_get(const struct city *pcity, int city_tile_index, enum unit_activity act_id)
int adv_city_worker_extra_get(const struct city *pcity, int city_tile_index, const struct extra_type *pextra)
void initialize_infrastructure_cache(struct player *pplayer)
int adv_city_worker_rmextra_get(const struct city *pcity, int city_tile_index, const struct extra_type *pextra)
adv_want city_tile_value(const struct city *pcity, const struct tile *ptile, int foodneed, int prodneed)
#define fc_assert_ret(condition)
#define log_warn(message,...)
#define log_verbose(message,...)
#define fc_assert(condition)
#define fc_assert_ret_val(condition, val)
#define log_debug(message,...)
struct tile * map_pos_to_tile(const struct civ_map *nmap, int map_x, int map_y)
bool same_pos(const struct tile *tile1, const struct tile *tile2)
int real_map_distance(const struct tile *tile0, const struct tile *tile1)
struct terrain_misc terrain_control
#define current_topo_has_flag(flag)
#define whole_map_iterate(_map, _tile)
#define whole_map_iterate_end
#define index_to_map_pos(pmap_x, pmap_y, mindex)
#define fc_calloc(n, esz)
const char * nation_rule_name(const struct nation_type *pnation)
struct nation_type * nation_of_player(const struct player *pplayer)
const struct pf_position * pf_path_last_position(const struct pf_path *path)
void pf_path_destroy(struct pf_path *path)
struct pf_map * pf_map_new(const struct pf_parameter *parameter)
struct pf_path * pf_map_path(struct pf_map *pfm, struct tile *ptile)
bool pf_map_position(struct pf_map *pfm, struct tile *ptile, struct pf_position *pos)
void pf_map_destroy(struct pf_map *pfm)
struct unit * player_unit_by_number(const struct player *pplayer, int unit_id)
bool pplayers_allied(const struct player *pplayer, const struct player *pplayer2)
struct extra_type * road_extra_get(const struct road_type *proad)
Road_type_id road_number(const struct road_type *proad)
bool road_provides_move_bonus(const struct road_type *proad)
#define road_deps_iterate(_reqs, _dep)
#define road_deps_iterate_end
static int recursion[AIT_LAST]
#define UNIT_LOG(loglevel, punit, msg,...)
#define TIMING_LOG(timer, activity)
enum action_result result
struct packet_game_info info
enum tile_behavior(* get_TB)(const struct tile *ptile, enum known_type known, const struct pf_parameter *param)
const struct player * owner
struct city_list * cities
struct player_ai ai_common
enum unit_activity activity
struct extra_type * activity_target
struct unit::@80::@83 server
enum server_side_agent ssa_controller
int terrain_extra_build_time(const struct terrain *pterrain, enum unit_activity activity, const struct extra_type *tgt)
bool tile_has_road(const struct tile *ptile, const struct road_type *proad)
struct city * tile_city(const struct tile *ptile)
#define tile_worked(_tile)
#define tile_terrain(_tile)
#define tile_has_extra(ptile, pextra)
#define tile_owner(_tile)
bool timer_in_use(struct timer *t)
void timer_destroy(struct timer *t)
void timer_start(struct timer *t)
double timer_read_seconds(struct timer *t)
struct timer * timer_renew(struct timer *t, enum timer_timetype type, enum timer_use use)
static int best_value(const void *a, const void *b)
int get_turns_for_activity_at(const struct unit *punit, enum unit_activity activity, const struct tile *ptile, struct extra_type *tgt)
void set_unit_activity(struct unit *punit, enum unit_activity new_activity)
bool is_military_unit(const struct unit *punit)
bool unit_is_cityfounder(const struct unit *punit)
const char * get_activity_text(enum unit_activity activity)
bool is_square_threatened(const struct civ_map *nmap, const struct player *pplayer, const struct tile *ptile, bool omniscient)
bool unit_has_orders(const struct unit *punit)
bool activity_requires_target(enum unit_activity activity)
#define CHECK_UNIT(punit)
bool unit_activity_handling(struct unit *punit, enum unit_activity new_activity)
bool unit_activity_handling_targeted(struct unit *punit, enum unit_activity new_activity, struct extra_type **new_target)
#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 struct unit_type * unit_type_get(const struct unit *punit)
const char * unit_rule_name(const struct unit *punit)
bool unit_has_type_flag(const struct unit *punit, enum unit_type_flag_id flag)
#define worker_task_list_iterate(tasklist, ptask)
#define worker_task_list_iterate_end