Feature #1919 ยป 0066-Autoworkers-Seek-shelter-when-there-s-no-work-to-do.patch
| server/advisors/autoworkers.c | ||
|---|---|---|
|
}
|
||
|
TIMING_LOG(AIT_WORKERS, TIMER_STOP);
|
||
|
adv_unit_new_task(punit, AUT_AUTO_WORKER, best_tile);
|
||
|
if (best_tile == nullptr) {
|
||
|
struct pf_parameter parameter;
|
||
|
struct pf_map *shelter_map;
|
||
|
struct tile *shelter_tile = nullptr;
|
||
|
pft_fill_unit_parameter(¶meter, nmap, punit);
|
||
|
shelter_map = pf_map_new(¶meter);
|
||
|
pf_map_tiles_iterate(shelter_map, ptile, TRUE) {
|
||
|
struct city *pcity = tile_city(ptile);
|
||
|
if (pcity != nullptr) {
|
||
|
if (pplayers_allied(pplayer, city_owner(pcity))) {
|
||
|
shelter_tile = ptile;
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
} pf_map_tiles_iterate_end;
|
||
|
if (shelter_tile != nullptr && shelter_tile != unit_tile(punit)) {
|
||
|
struct pf_path *shelter_path;
|
||
|
bool alive;
|
||
|
adv_unit_new_task(punit, AUT_AUTO_WORKER, shelter_tile);
|
||
|
auto_worker_setup_work(nmap, pplayer, punit, state, recursion, &path,
|
||
|
best_tile, best_act, &best_target,
|
||
|
completion_time);
|
||
|
shelter_path = pf_map_path(shelter_map, shelter_tile);
|
||
|
alive = adv_follow_path(punit, shelter_path, shelter_tile);
|
||
|
if (alive && same_pos(unit_tile(punit), shelter_tile)) {
|
||
|
UNIT_LOG(LOG_DEBUG, punit,
|
||
|
"arrives to shelter city at (%d, %d)",
|
||
|
TILE_XY(shelter_tile));
|
||
|
}
|
||
|
pf_path_destroy(shelter_path);
|
||
|
}
|
||
|
pf_map_destroy(shelter_map);
|
||
|
} else {
|
||
|
adv_unit_new_task(punit, AUT_AUTO_WORKER, best_tile);
|
||
|
auto_worker_setup_work(nmap, pplayer, punit, state, recursion, &path,
|
||
|
best_tile, best_act, &best_target,
|
||
|
completion_time);
|
||
|
}
|
||
|
if (NULL != path) {
|
||
|
pf_path_destroy(path);
|
||