Project

General

Profile

Feature #2236 ยป 0073-Refactor-adv_unit_move.patch

Marko Lindqvist, 11/15/2026 11:33 AM

View differences:

common/actions.c
Can unit do any action with the given action result to tile?
Returns one of the possible actions, or ACTION_NONE.
****************************************************************************/
enum gen_action select_actres_action_unit_on_tile(struct civ_map *nmap,
enum gen_action select_actres_action_unit_on_tile(const struct civ_map *nmap,
enum action_result actres,
struct unit *punit,
struct tile *ptile)
......
Can unit do any action with the given action result to unit?
Returns one of the possible actions, or ACTION_NONE.
****************************************************************************/
enum gen_action select_actres_action_unit_on_unit(struct civ_map *nmap,
enum gen_action select_actres_action_unit_on_unit(const struct civ_map *nmap,
enum action_result actres,
struct unit *punit,
struct unit *target)
common/actions.h
enum action_result actres,
struct unit *punit,
struct tile *ptile);
enum gen_action select_actres_action_unit_on_tile(struct civ_map *nmap,
enum gen_action select_actres_action_unit_on_tile(const struct civ_map *nmap,
enum action_result actres,
struct unit *punit,
struct tile *ptile);
......
enum action_result actres,
struct unit *punit,
struct city *pcity);
enum gen_action select_actres_action_unit_on_unit(struct civ_map *nmap,
enum gen_action select_actres_action_unit_on_unit(const struct civ_map *nmap,
enum action_result actres,
struct unit *punit,
struct unit *target);
server/advisors/advgoto.c
struct player *pplayer = unit_owner(punit);
struct unit *ptrans = nullptr;
const struct civ_map *nmap = &(wld.map);
enum gen_action act;
/* If enemy, stop and give a chance for the human player to
handle this case */
......
}
/* Select move kind. */
act = ACTION_NONE;
if (!can_unit_survive_at_tile(nmap, punit, ptile)
&& ((ptrans = transporter_for_unit_at(punit, ptile)))
&& is_action_enabled_unit_on_unit(nmap, ACTION_TRANSPORT_EMBARK,
punit, ptrans)) {
/* "Transport Embark". */
paction = action_by_number(ACTION_TRANSPORT_EMBARK);
} else if (!can_unit_survive_at_tile(nmap, punit, ptile)
&& ptrans != nullptr
&& is_action_enabled_unit_on_unit(nmap, ACTION_TRANSPORT_EMBARK2,
punit, ptrans)) {
/* "Transport Embark 2". */
paction = action_by_number(ACTION_TRANSPORT_EMBARK2);
} else if (!can_unit_survive_at_tile(nmap, punit, ptile)
&& ptrans != nullptr
&& is_action_enabled_unit_on_unit(nmap, ACTION_TRANSPORT_EMBARK3,
punit, ptrans)) {
/* "Transport Embark 3". */
paction = action_by_number(ACTION_TRANSPORT_EMBARK3);
} else if (!can_unit_survive_at_tile(nmap, punit, ptile)
&& ptrans != nullptr
&& is_action_enabled_unit_on_unit(nmap, ACTION_TRANSPORT_EMBARK4,
punit, ptrans)) {
/* "Transport Embark 4". */
paction = action_by_number(ACTION_TRANSPORT_EMBARK4);
} else if (is_action_enabled_unit_on_tile(nmap, ACTION_TRANSPORT_DISEMBARK1,
punit, ptile, nullptr)) {
/* "Transport Disembark". */
paction = action_by_number(ACTION_TRANSPORT_DISEMBARK1);
} else if (is_action_enabled_unit_on_tile(nmap, ACTION_TRANSPORT_DISEMBARK2,
punit, ptile, nullptr)) {
/* "Transport Disembark 2". */
paction = action_by_number(ACTION_TRANSPORT_DISEMBARK2);
} else if (is_action_enabled_unit_on_tile(nmap, ACTION_TRANSPORT_DISEMBARK3,
punit, ptile, nullptr)) {
/* "Transport Disembark 3". */
paction = action_by_number(ACTION_TRANSPORT_DISEMBARK3);
} else if (is_action_enabled_unit_on_tile(nmap, ACTION_TRANSPORT_DISEMBARK4,
punit, ptile, nullptr)) {
/* "Transport Disembark 4". */
paction = action_by_number(ACTION_TRANSPORT_DISEMBARK4);
} else if (is_action_enabled_unit_on_tile(nmap, ACTION_HUT_ENTER,
punit, ptile, nullptr)) {
/* "Enter Hut". */
paction = action_by_number(ACTION_HUT_ENTER);
} else if (is_action_enabled_unit_on_tile(nmap, ACTION_HUT_ENTER2,
punit, ptile, nullptr)) {
/* "Enter Hut 2". */
paction = action_by_number(ACTION_HUT_ENTER2);
} else if (is_action_enabled_unit_on_tile(nmap, ACTION_HUT_ENTER3,
punit, ptile, nullptr)) {
/* "Enter Hut 3". */
paction = action_by_number(ACTION_HUT_ENTER3);
} else if (is_action_enabled_unit_on_tile(nmap, ACTION_HUT_ENTER4,
punit, ptile, nullptr)) {
/* "Enter Hut 4". */
paction = action_by_number(ACTION_HUT_ENTER4);
} else if (is_action_enabled_unit_on_tile(nmap, ACTION_HUT_FRIGHTEN,
punit, ptile, nullptr)) {
/* "Frighten Hut". */
paction = action_by_number(ACTION_HUT_FRIGHTEN);
} else if (is_action_enabled_unit_on_tile(nmap, ACTION_HUT_FRIGHTEN2,
punit, ptile, nullptr)) {
/* "Frighten Hut 2". */
paction = action_by_number(ACTION_HUT_FRIGHTEN2);
} else if (is_action_enabled_unit_on_tile(nmap, ACTION_HUT_FRIGHTEN3,
punit, ptile, nullptr)) {
/* "Frighten Hut 3". */
paction = action_by_number(ACTION_HUT_FRIGHTEN3);
} else if (is_action_enabled_unit_on_tile(nmap, ACTION_HUT_FRIGHTEN4,
punit, ptile, nullptr)) {
/* "Frighten Hut 4". */
paction = action_by_number(ACTION_HUT_FRIGHTEN4);
} else if (is_action_enabled_unit_on_tile(nmap, ACTION_UNIT_MOVE,
punit, ptile, nullptr)) {
/* "Unit Move". */
paction = action_by_number(ACTION_UNIT_MOVE);
} else if (is_action_enabled_unit_on_tile(nmap, ACTION_UNIT_MOVE2,
punit, ptile, nullptr)) {
/* "Unit Move 2". */
paction = action_by_number(ACTION_UNIT_MOVE2);
} else {
/* "Unit Move 3". */
paction = action_by_number(ACTION_UNIT_MOVE3);
&& ((ptrans = transporter_for_unit_at(punit, ptile)))) {
act = select_actres_action_unit_on_unit(nmap, ACTRES_TRANSPORT_EMBARK,
punit, ptrans);
}
if (act == ACTION_NONE) {
enum action_result actress[] = {
ACTRES_TRANSPORT_DISEMBARK,
ACTRES_HUT_ENTER,
ACTRES_HUT_FRIGHTEN,
ACTRES_UNIT_MOVE,
ACTRES_LAST
};
int i;
for (i = 0; actress[i] != ACTRES_LAST && act == ACTION_NONE; i++) {
act = select_actres_action_unit_on_tile(nmap, actress[i], punit, ptile);
}
}
if (act == ACTION_NONE) {
UNIT_LOG(LOG_DEBUG, punit, "no movement action possible");
return FALSE;
}
paction = action_by_number(act);
/* Try not to end move next to an enemy if we can avoid it by waiting */
if (action_has_result(paction, ACTRES_UNIT_MOVE)
|| action_has_result(paction, ACTRES_TRANSPORT_DISEMBARK)) {
    (1-1/1)