Project

General

Profile

Feature #320 » 0038-Unhardcode-wld.map-from-is_action_enabled_unit_on_ci.patch

main, S3_2 - Marko Lindqvist, 03/17/2024 11:06 PM

View differences:

ai/default/daicity.c
const enum action_requester requester)
{
const int punit_id_stored = punit->id;
const struct civ_map *nmap = &(wld.map);
fc_assert_ret(owner == unit_owner(punit));
......
tgt_city = tile_city(unit_tile(punit));
if (tgt_city
&& is_action_enabled_unit_on_city(ACTION_HELP_WONDER,
&& is_action_enabled_unit_on_city(nmap, ACTION_HELP_WONDER,
punit, tgt_city)) {
if (unit_perform_action(owner, punit->id, tgt_city->id,
0, NULL, ACTION_HELP_WONDER, requester)) {
......
tgt_city = tile_city(unit_tile(punit));
if (tgt_city
&& is_action_enabled_unit_on_city(ACTION_DISBAND_UNIT_RECOVER,
&& is_action_enabled_unit_on_city(nmap, ACTION_DISBAND_UNIT_RECOVER,
punit, tgt_city)) {
if (unit_perform_action(owner, punit->id, tgt_city->id,
0, NULL, ACTION_DISBAND_UNIT_RECOVER, requester)) {
ai/default/daitools.c
int sanity = punit->id;
bool alive;
struct city *tcity;
const struct civ_map *nmap = &(wld.map);
CHECK_UNIT(punit);
fc_assert_ret_val(is_ai(unit_owner(punit)), TRUE);
......
0, "", ACTION_NUKE);
} else if (action_id_get_target_kind(ACTION_NUKE) == ATK_CITY
&& (tcity = tile_city(ptile))
&& is_action_enabled_unit_on_city(ACTION_NUKE,
&& is_action_enabled_unit_on_city(nmap, ACTION_NUKE,
punit, tcity)) {
/* Choose "Explode Nuclear". */
unit_do_action(unit_owner(punit), punit->id, tcity->id,
......
0, "", ACTION_NUKE_CITY);
} else if (action_id_get_target_kind(ACTION_NUKE_CITY) == ATK_CITY
&& (tcity = tile_city(ptile))
&& is_action_enabled_unit_on_city(ACTION_NUKE_CITY,
&& is_action_enabled_unit_on_city(nmap, ACTION_NUKE_CITY,
punit, tcity)) {
/* Choose "Nuke City". */
unit_do_action(unit_owner(punit), punit->id, tcity->id,
......
unit_do_action(unit_owner(punit), punit->id, tile_index(ptile),
0, "", ACTION_SUICIDE_ATTACK);
} else if ((tcity = tile_city(ptile))
&& is_action_enabled_unit_on_city(ACTION_CONQUER_CITY,
&& is_action_enabled_unit_on_city(nmap, ACTION_CONQUER_CITY,
punit, tcity)) {
/* Choose "Conquer City". */
unit_do_action(unit_owner(punit), punit->id, tcity->id,
0, "", ACTION_CONQUER_CITY);
} else if ((tcity = tile_city(ptile))
&& is_action_enabled_unit_on_city(ACTION_CONQUER_CITY2,
&& is_action_enabled_unit_on_city(nmap, ACTION_CONQUER_CITY2,
punit, tcity)) {
/* Choose "Conquer City 2". */
unit_do_action(unit_owner(punit), punit->id, tcity->id,
0, "", ACTION_CONQUER_CITY2);
} else if ((tcity = tile_city(ptile))
&& is_action_enabled_unit_on_city(ACTION_CONQUER_CITY3,
&& is_action_enabled_unit_on_city(nmap, ACTION_CONQUER_CITY3,
punit, tcity)) {
/* Choose "Conquer City 3". */
unit_do_action(unit_owner(punit), punit->id, tcity->id,
0, "", ACTION_CONQUER_CITY3);
} else if ((tcity = tile_city(ptile))
&& is_action_enabled_unit_on_city(ACTION_CONQUER_CITY4,
&& is_action_enabled_unit_on_city(nmap, ACTION_CONQUER_CITY4,
punit, tcity)) {
/* Choose "Conquer City 4". */
unit_do_action(unit_owner(punit), punit->id, tcity->id,
0, "", ACTION_CONQUER_CITY4);
} else if (!can_unit_survive_at_tile(&(wld.map), punit, ptile)
} else if (!can_unit_survive_at_tile(nmap, punit, ptile)
&& ((ptrans = transporter_for_unit_at(punit, ptile)))
&& is_action_enabled_unit_on_unit(ACTION_TRANSPORT_EMBARK,
punit, ptrans)) {
/* "Transport Embark". */
unit_do_action(unit_owner(punit), punit->id, ptrans->id,
0, "", ACTION_TRANSPORT_EMBARK);
} else if (!can_unit_survive_at_tile(&(wld.map), punit, ptile)
} else if (!can_unit_survive_at_tile(nmap, punit, ptile)
&& ((ptrans = transporter_for_unit_at(punit, ptile)))
&& is_action_enabled_unit_on_unit(ACTION_TRANSPORT_EMBARK2,
punit, ptrans)) {
/* "Transport Embark 2". */
unit_do_action(unit_owner(punit), punit->id, ptrans->id,
0, "", ACTION_TRANSPORT_EMBARK2);
} else if (!can_unit_survive_at_tile(&(wld.map), punit, ptile)
} else if (!can_unit_survive_at_tile(nmap, punit, ptile)
&& ((ptrans = transporter_for_unit_at(punit, ptile)))
&& is_action_enabled_unit_on_unit(ACTION_TRANSPORT_EMBARK3,
punit, ptrans)) {
/* "Transport Embark 3". */
unit_do_action(unit_owner(punit), punit->id, ptrans->id,
0, "", ACTION_TRANSPORT_EMBARK3);
} else if (!can_unit_survive_at_tile(&(wld.map), punit, ptile)
} else if (!can_unit_survive_at_tile(nmap, punit, ptile)
&& ((ptrans = transporter_for_unit_at(punit, ptile)))
&& is_action_enabled_unit_on_unit(ACTION_TRANSPORT_EMBARK4,
punit, ptrans)) {
......
int sanity = punit->id;
struct player *pplayer = unit_owner(punit);
const bool is_plr_ai = is_ai(pplayer);
const struct civ_map *nmap = &(wld.map);
CHECK_UNIT(punit);
fc_assert_ret_val_msg(is_tiles_adjacent(unit_tile(punit), ptile), FALSE,
......
}
/* Select move kind. */
if (!can_unit_survive_at_tile(&(wld.map), punit, ptile)
if (!can_unit_survive_at_tile(nmap, punit, ptile)
&& ((ptrans = transporter_for_unit_at(punit, ptile)))
&& is_action_enabled_unit_on_unit(ACTION_TRANSPORT_EMBARK,
punit, ptrans)) {
/* "Transport Embark". */
paction = action_by_number(ACTION_TRANSPORT_EMBARK);
} else if (!can_unit_survive_at_tile(&(wld.map), punit, ptile)
} else if (!can_unit_survive_at_tile(nmap, punit, ptile)
&& ptrans != NULL
&& is_action_enabled_unit_on_unit(ACTION_TRANSPORT_EMBARK2,
punit, ptrans)) {
/* "Transport Embark 2". */
paction = action_by_number(ACTION_TRANSPORT_EMBARK2);
} else if (!can_unit_survive_at_tile(&(wld.map), punit, ptile)
} else if (!can_unit_survive_at_tile(nmap, punit, ptile)
&& ptrans != NULL
&& is_action_enabled_unit_on_unit(ACTION_TRANSPORT_EMBARK3,
punit, ptrans)) {
/* "Transport Embark 3". */
paction = action_by_number(ACTION_TRANSPORT_EMBARK3);
} else if (!can_unit_survive_at_tile(&(wld.map), punit, ptile)
} else if (!can_unit_survive_at_tile(nmap, punit, ptile)
&& ptrans != NULL
&& is_action_enabled_unit_on_unit(ACTION_TRANSPORT_EMBARK4,
punit, ptrans)) {
......
if (action_has_result(paction, ACTRES_UNIT_MOVE)
|| action_has_result(paction, ACTRES_TRANSPORT_DISEMBARK)) {
/* The unit will have to move it self rather than being moved. */
int mcost = map_move_cost_unit(&(wld.map), punit, ptile);
int mcost = map_move_cost_unit(nmap, punit, ptile);
if (paction) {
struct tile *from_tile;
ai/default/daiunit.c
{
bool alive = TRUE;
struct unit_ai *unit_data = def_ai_unit_data(punit, ait);
const struct civ_map *nmap = &(wld.map);
fc_assert_ret(NULL != dest_city);
......
if (unit_transported(punit)) {
aiferry_clear_boat(ait, punit);
}
if (help_wonder && is_action_enabled_unit_on_city(ACTION_HELP_WONDER,
if (help_wonder && is_action_enabled_unit_on_city(nmap, ACTION_HELP_WONDER,
punit, dest_city)) {
/*
* We really don't want to just drop all caravans in immediately.
......
city_name_get(dest_city));
unit_do_action(pplayer, punit->id, dest_city->id,
0, "", ACTION_HELP_WONDER);
} else if (is_action_enabled_unit_on_city(ACTION_TRADE_ROUTE,
} else if (is_action_enabled_unit_on_city(nmap, ACTION_TRADE_ROUTE,
punit, dest_city)) {
log_base(LOG_CARAVAN, "%s %s[%d](%d,%d) creates trade route in %s",
nation_rule_name(nation_of_unit(punit)),
......
city_name_get(dest_city));
unit_do_action(pplayer, punit->id, dest_city->id,
0, "", ACTION_TRADE_ROUTE);
} else if (is_action_enabled_unit_on_city(ACTION_MARKETPLACE,
} else if (is_action_enabled_unit_on_city(nmap, ACTION_MARKETPLACE,
punit, dest_city)) {
/* Get the one time bonus. */
log_base(LOG_CARAVAN, "%s %s[%d](%d,%d) enters marketplace of %s",
......
bool required_boat = FALSE;
bool request_boat = FALSE;
bool tired_of_waiting_boat = FALSE;
const struct civ_map *nmap = &(wld.map);
CHECK_UNIT(punit);
......
&& !city_production_gets_caravan_shields(&city_dest->production))
|| (unit_data->task == AIUNIT_TRADE
&& real_map_distance(city_dest->tile, unit_tile(punit)) <= 1
&& !(is_action_enabled_unit_on_city(ACTION_TRADE_ROUTE,
&& !(is_action_enabled_unit_on_city(nmap, ACTION_TRADE_ROUTE,
punit, city_dest)
|| is_action_enabled_unit_on_city(ACTION_MARKETPLACE,
|| is_action_enabled_unit_on_city(nmap, ACTION_MARKETPLACE,
punit, city_dest)))
|| (unit_data->task == AIUNIT_WONDER
&& real_map_distance(city_dest->tile, unit_tile(punit)) <= 1
&& !is_action_enabled_unit_on_city(ACTION_HELP_WONDER,
&& !is_action_enabled_unit_on_city(nmap, ACTION_HELP_WONDER,
punit, city_dest))) {
/* destination invalid! */
dai_unit_new_task(ait, punit, AIUNIT_NONE, NULL);
common/actions.c
const struct city *target_city
= blocked_find_target_city(act, actor_unit, target_tile,
target_city_arg, target_unit);
const struct civ_map *nmap = &(wld.map);
action_iterate(blocker_id) {
struct action *blocker = action_by_number(blocker_id);
......
/* Can't be enabled. No target. */
continue;
}
if (is_action_enabled_unit_on_city(blocker->id,
if (is_action_enabled_unit_on_city(nmap, blocker->id,
actor_unit, target_city)) {
return blocker;
}
......
See note in is_action_enabled() for why the action may still be disabled.
**************************************************************************/
bool is_action_enabled_unit_on_city(const action_id wanted_action,
bool is_action_enabled_unit_on_city(const struct civ_map *nmap,
const action_id wanted_action,
const struct unit *actor_unit,
const struct city *target_city)
{
const struct civ_map *nmap = &(wld.map);
return is_action_enabled_unit_on_city_full(nmap, wanted_action, actor_unit,
unit_home(actor_unit),
unit_tile(actor_unit),
common/actions.h
const struct city *target_city,
const struct unit *target_unit);
bool is_action_enabled_unit_on_city(const action_id wanted_action,
bool is_action_enabled_unit_on_city(const struct civ_map *nmap,
const action_id wanted_action,
const struct unit *actor_unit,
const struct city *target_city);
common/unit.c
bool unit_can_airlift_to(const struct unit *punit,
const struct city *pdest_city)
{
const struct civ_map *nmap = &(wld.map);
fc_assert_ret_val(pdest_city, FALSE);
if (is_server()) {
return is_action_enabled_unit_on_city(ACTION_AIRLIFT,
return is_action_enabled_unit_on_city(nmap, ACTION_AIRLIFT,
punit, pdest_city);
} else {
return action_prob_possible(action_prob_vs_city(punit, ACTION_AIRLIFT,
server/actiontools.c
const struct city *tgt_city;
const struct tile *tgt_tile;
const struct unit *tgt_unit;
const struct civ_map *nmap = &(wld.map);
const struct action_auto_perf *autoperf
= action_auto_perf_unit_sel(cause, actor, other_player,
......
break;
case ATK_CITY:
if (tgt_city
&& is_action_enabled_unit_on_city(act, actor, tgt_city)) {
&& is_action_enabled_unit_on_city(nmap, act, actor, tgt_city)) {
perform_action_to(act, actor, tgt_city->id, EXTRA_NONE)
}
break;
......
const struct city *tgt_city;
const struct tile *tgt_tile;
const struct unit *tgt_unit;
const struct civ_map *nmap = &(wld.map);
const struct action_auto_perf *autoperf
= action_auto_perf_unit_sel(cause, actor, other_player,
......
break;
case ATK_CITY:
if (tgt_city
&& is_action_enabled_unit_on_city(act, actor, tgt_city)) {
&& is_action_enabled_unit_on_city(nmap, act, actor, tgt_city)) {
current = action_prob_vs_city(actor, act, tgt_city);
}
break;
server/scripting/api_server_edit.c
fc_assert_ret_val(action_get_actor_kind(paction) == AAK_UNIT, FALSE);
fc_assert_ret_val(action_get_target_kind(paction) == ATK_CITY, FALSE);
fc_assert_ret_val(!action_has_result(paction, ACTRES_FOUND_CITY), FALSE);
if (is_action_enabled_unit_on_city(paction->id, punit, tgt)) {
if (is_action_enabled_unit_on_city(&(wld.map), paction->id, punit, tgt)) {
return unit_perform_action(unit_owner(punit), punit->id,
tgt->id, IDENTITY_NUMBER_ZERO, "",
paction->id, ACT_REQ_RULES);
......
fc_assert_ret_val(action_get_actor_kind(paction) == AAK_UNIT, FALSE);
fc_assert_ret_val(action_get_target_kind(paction) == ATK_CITY, FALSE);
fc_assert_ret_val(!action_has_result(paction, ACTRES_FOUND_CITY), FALSE);
if (is_action_enabled_unit_on_city(paction->id, punit, tgt)) {
if (is_action_enabled_unit_on_city(&(wld.map), paction->id, punit, tgt)) {
return unit_perform_action(unit_owner(punit), punit->id,
tgt->id, sub_tgt->item_number, "",
paction->id, ACT_REQ_RULES);
......
fc_assert_ret_val(action_get_actor_kind(paction) == AAK_UNIT, FALSE);
fc_assert_ret_val(action_get_target_kind(paction) == ATK_CITY, FALSE);
fc_assert_ret_val(!action_has_result(paction, ACTRES_FOUND_CITY), FALSE);
if (is_action_enabled_unit_on_city(paction->id, punit, tgt)) {
if (is_action_enabled_unit_on_city(&(wld.map), paction->id, punit, tgt)) {
return unit_perform_action(unit_owner(punit), punit->id,
tgt->id, sub_tgt->item_number, "",
paction->id, ACT_REQ_RULES);
server/unithand.c
struct unit_type *from_unittype = utype_by_number(uti);
int number_of_upgraded_units = 0;
struct action *paction = action_by_number(ACTION_UPGRADE_UNIT);
const struct civ_map *nmap = &(wld.map);
if (NULL == from_unittype) {
/* Probably died or bribed. */
......
if (unit_type_get(punit) == from_unittype) {
struct city *pcity = tile_city(unit_tile(punit));
if (is_action_enabled_unit_on_city(paction->id, punit, pcity)
if (is_action_enabled_unit_on_city(nmap, paction->id, punit, pcity)
&& unit_perform_action(pplayer, punit->id, pcity->id, 0, "",
paction->id, ACT_REQ_SS_AGENT)) {
number_of_upgraded_units++;
......
struct action *paction = action_by_number(action_type);
struct unit *punit = game_unit_by_number(target_id);
struct city *pcity = game_city_by_number(target_id);
const struct civ_map *nmap = &(wld.map);
if (NULL == paction) {
/* Non existing action */
......
break;
case ACTRES_SPY_INCITE_CITY:
if (pcity
&& is_action_enabled_unit_on_city(action_type,
&& is_action_enabled_unit_on_city(nmap, action_type,
pactor, pcity)) {
dsend_packet_unit_action_answer(pc,
actor_id, target_id,
......
break;
case ACTRES_UPGRADE_UNIT:
if (pcity
&& is_action_enabled_unit_on_city(action_type,
&& is_action_enabled_unit_on_city(nmap, action_type,
pactor, pcity)) {
const struct unit_type *tgt_utype;
int upgr_cost;
......
case ACTRES_SPY_TARGETED_SABOTAGE_CITY:
case ACTRES_STRIKE_BUILDING:
if (pcity
&& is_action_enabled_unit_on_city(action_type,
&& is_action_enabled_unit_on_city(nmap, action_type,
pactor, pcity)) {
spy_send_sabotage_list(pc, pactor, pcity,
action_by_number(action_type), request_kind);
......
struct impr_type *sub_tgt_impr;
struct unit *punit = NULL;
struct city *pcity = NULL;
const struct civ_map *nmap = &(wld.map);
if (!action_id_exists(action_type)) {
/* Non existing action */
......
#define ACTION_PERFORM_UNIT_CITY(action, actor, target, action_performer) \
if (pcity \
&& is_action_enabled_unit_on_city(action_type, \
actor_unit, pcity)) { \
&& is_action_enabled_unit_on_city(nmap, action_type, \
actor_unit, pcity)) { \
bool success; \
script_server_signal_emit("action_started_unit_city", \
action_by_number(action), actor, target); \
(1-1/2)