Feature #1701 » 1701.patch
| ai/default/daisettler.c | ||
|---|---|---|
|
cityresult_destroy(result);
|
||
|
/*** Go back to and found a city ***/
|
||
|
pf_path_destroy(path);
|
||
|
if (path != NULL) pf_path_destroy(path);
|
||
|
path = NULL;
|
||
|
goto BUILD_CITY;
|
||
|
} else if (best_impr > 0) {
|
||
| ... | ... | |
|
}
|
||
|
if (best_tile != NULL
|
||
|
&& auto_worker_setup_work(nmap, pplayer, punit, state, 0, path,
|
||
|
&& auto_worker_setup_work(nmap, pplayer, punit, state, 0, &path,
|
||
|
best_tile, best_act, &best_target,
|
||
|
completion_time) != ACTIVITY_IDLE) {
|
||
|
if (pcity != NULL) {
|
||
| server/advisors/autoworkers.c | ||
|---|---|---|
|
}
|
||
|
if (path != NULL) {
|
||
|
if (*path != NULL) pf_path_destroy(*path);
|
||
|
*path = best ? pf_map_path(pfm, best->ptile) : NULL;
|
||
|
}
|
||
| ... | ... | |
|
best_target = best_task->tgt;
|
||
|
switch (auto_worker_setup_work(nmap, pplayer, punit, state, recursion,
|
||
|
path, best_task->ptile, best_task->act,
|
||
|
&path, best_task->ptile, best_task->act,
|
||
|
&best_target, completion_time)) {
|
||
|
case ACTIVITY_IDLE:
|
||
|
CITY_LOG(LOG_NORMAL, taskcity, "giving up on %s(%d, %d)", unit_activity_name(best_task->act), TILE_XY(best_task->ptile));
|
||
| ... | ... | |
|
enum unit_activity auto_worker_setup_work(const struct civ_map *nmap,
|
||
|
struct player *pplayer, struct unit *punit,
|
||
|
struct workermap *state, int recursion,
|
||
|
struct pf_path *path,
|
||
|
struct pf_path **path,
|
||
|
struct tile *best_tile,
|
||
|
enum unit_activity best_act,
|
||
|
struct extra_type **best_target,
|
||
| ... | ... | |
|
}
|
||
|
UNIT_LOG(LOG_NORMAL, punit,
|
||
|
"is heading to do %s(%s) at (%d, %d)",
|
||
|
"considering %s(%s) at (%d, %d)",
|
||
|
unit_activity_name(best_act),
|
||
|
best_target && *best_target ? extra_rule_name(*best_target) : "-",
|
||
|
TILE_XY(best_tile));
|
||
|
if (!path) {
|
||
|
if (*path == NULL) {
|
||
|
pft_fill_unit_parameter(¶meter, nmap, punit);
|
||
|
parameter.omniscience = !has_handicap(pplayer, H_MAP);
|
||
|
parameter.get_TB = autoworker_tile_behavior;
|
||
|
pfm = pf_map_new(¶meter);
|
||
|
path = pf_map_path(pfm, best_tile);
|
||
|
*path = pf_map_path(pfm, best_tile);
|
||
|
}
|
||
|
if (path) {
|
||
|
if (*path != NULL) {
|
||
|
bool alive;
|
||
|
/* Hack: make sure the unit has enough moves_left for the move to succeed,
|
||
|
* and adjust moves_left to afterward (if successful). */
|
||
| ... | ... | |
|
punit->goto_tile = best_tile;
|
||
|
unit_activity_handling(punit, ACTIVITY_GOTO, ACTION_NONE);
|
||
|
alive = adv_follow_path(punit, path, best_tile);
|
||
|
alive = adv_follow_path(punit, *path, best_tile);
|
||
|
log_normal("%s", (alive ? "ALIVE" : "\x1b[31munalive\x1b[0m"));
|
||
|
if (alive && same_pos(unit_tile(punit), best_tile) && punit->moves_left > 0) {
|
||
| ... | ... | |
|
ret = best_act;
|
||
|
} else if (alive) {
|
||
|
punit->moves_left = old_moves;
|
||
|
send_unit_info(NULL, punit);
|
||
|
UNIT_LOG(LOG_NORMAL, punit,
|
||
|
"didn't start work yet; got to (%d, %d) with "
|
||
|
"%d move frags left", TILE_XY(unit_tile(punit)),
|
||
|
punit->moves_left);
|
||
|
send_unit_info(NULL, punit);
|
||
|
ret = ACTIVITY_GOTO;
|
||
|
}
|
||
|
pf_path_destroy(*path);
|
||
|
*path = NULL;
|
||
|
} else {
|
||
|
UNIT_LOG(LOG_NORMAL, punit,
|
||
|
"does not find path (%d, %d) -> (%d, %d)",
|
||
| ... | ... | |
|
bool alive;
|
||
|
unit_activity_handling(punit, ACTIVITY_GOTO, ACTION_NONE);
|
||
|
alive = adv_follow_path(punit, path, punit->goto_tile);
|
||
|
if (alive && same_pos(unit_tile(punit), punit->goto_tile)) {
|
||
|
if (alive && punit->goto_tile != nullptr
|
||
|
&& same_pos(unit_tile(punit), punit->goto_tile)) {
|
||
|
unit_activity_handling(punit, ACTIVITY_IDLE, ACTION_NONE);
|
||
|
punit->goto_tile = nullptr;
|
||
|
}
|
||
|
send_unit_info(NULL, punit);
|
||
|
pf_path_destroy(path);
|
||
|
} else {
|
||
|
punit->goto_tile = nullptr;
|
||
|
}
|
||
|
}
|
||
|
if (punit->activity == ACTIVITY_GOTO && punit->goto_tile == nullptr) {
|
||
|
pf_map_destroy(pfm);
|
||
|
} else if (punit->activity == ACTIVITY_GOTO && punit->goto_tile == nullptr) {
|
||
|
unit_activity_handling(punit, ACTIVITY_IDLE, ACTION_NONE);
|
||
|
send_unit_info(NULL, punit);
|
||
|
}
|
||
| ... | ... | |
|
if (!adv_worker_safe_tile(nmap, pplayer, punit,
|
||
|
unit_tile(punit))) {
|
||
|
unit_activity_handling(punit, ACTIVITY_IDLE, ACTION_NONE);
|
||
|
send_unit_info(NULL, punit);
|
||
|
}
|
||
|
} else {
|
||
|
CALL_PLR_AI_FUNC(settler_cont, pplayer, pplayer, punit, state);
|
||
| server/advisors/autoworkers.h | ||
|---|---|---|
|
enum unit_activity auto_worker_setup_work(const struct civ_map *nmap,
|
||
|
struct player *pplayer, struct unit *punit,
|
||
|
struct workermap *state, int recursion,
|
||
|
struct pf_path *path,
|
||
|
struct pf_path **path,
|
||
|
struct tile *best_tile,
|
||
|
enum unit_activity best_act,
|
||
|
struct extra_type **best_target,
|
||