Feature #340 » 0021-Unhardcode-wld.map-from-is_action_enabled_unit_on_un.patch
ai/default/aidiplomat.c | ||
---|---|---|
struct unit *punit, struct pf_map *pfm)
|
||
{
|
||
int gold_avail, expenses;
|
||
const struct civ_map *nmap = &(wld.map);
|
||
dai_calc_data(pplayer, NULL, &expenses, NULL);
|
||
gold_avail = pplayer->economic.gold - expenses;
|
||
... | ... | |
|| !POTENTIALLY_HOSTILE_PLAYER(ait, pplayer, unit_owner(pvictim))
|
||
|| unit_list_size(ptile->units) > 1
|
||
|| tile_city(ptile)
|
||
|| !is_action_enabled_unit_on_unit(ACTION_SPY_BRIBE_UNIT,
|
||
|| !is_action_enabled_unit_on_unit(nmap, ACTION_SPY_BRIBE_UNIT,
|
||
punit, pvictim)) {
|
||
continue;
|
||
}
|
||
... | ... | |
struct tile *bribee_tile;
|
||
struct pf_path *path;
|
||
bribee_tile = mapstep(&(wld.map), pos.tile, DIR_REVERSE(pos.dir_to_here));
|
||
bribee_tile = mapstep(nmap, pos.tile, DIR_REVERSE(pos.dir_to_here));
|
||
path = pf_map_path(pfm, bribee_tile);
|
||
if (!path || !adv_unit_execute_path(punit, path)
|
||
|| punit->moves_left <= 0) {
|
ai/default/aihunt.c | ||
---|---|---|
}
|
||
} unit_list_iterate_end;
|
||
if (sucker) {
|
||
break; /* found something - kill it! */
|
||
break; /* Found something - kill it! */
|
||
}
|
||
} pf_map_move_costs_iterate_end;
|
||
pf_map_destroy(pfm);
|
||
... | ... | |
if (unit_transported(missile)) {
|
||
struct unit *ptrans = unit_transport_get(missile);
|
||
if (is_action_enabled_unit_on_unit(ACTION_TRANSPORT_ALIGHT,
|
||
if (is_action_enabled_unit_on_unit(nmap, ACTION_TRANSPORT_ALIGHT,
|
||
missile, ptrans)) {
|
||
unit_do_action(unit_owner(punit), punit->id, ptrans->id,
|
||
0, "", ACTION_TRANSPORT_ALIGHT);
|
ai/default/aitools.c | ||
---|---|---|
0, "", ACTION_CONQUER_CITY4);
|
||
} 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,
|
||
&& is_action_enabled_unit_on_unit(nmap, 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(nmap, punit, ptile)
|
||
&& ((ptrans = transporter_for_unit_at(punit, ptile)))
|
||
&& is_action_enabled_unit_on_unit(ACTION_TRANSPORT_EMBARK2,
|
||
&& is_action_enabled_unit_on_unit(nmap, 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(nmap, punit, ptile)
|
||
&& ((ptrans = transporter_for_unit_at(punit, ptile)))
|
||
&& is_action_enabled_unit_on_unit(ACTION_TRANSPORT_EMBARK3,
|
||
&& is_action_enabled_unit_on_unit(nmap, ACTION_TRANSPORT_EMBARK3,
|
||
punit, ptrans)) {
|
||
/* "Transport Embark 3". */
|
||
unit_do_action(unit_owner(punit), punit->id, ptrans->id,
|
||
... | ... | |
/* Select move kind. */
|
||
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,
|
||
&& 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 != NULL
|
||
&& is_action_enabled_unit_on_unit(ACTION_TRANSPORT_EMBARK2,
|
||
&& 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 != NULL
|
||
&& is_action_enabled_unit_on_unit(ACTION_TRANSPORT_EMBARK3,
|
||
&& is_action_enabled_unit_on_unit(nmap, ACTION_TRANSPORT_EMBARK3,
|
||
punit, ptrans)) {
|
||
/* "Transport Embark 3". */
|
||
paction = action_by_number(ACTION_TRANSPORT_EMBARK3);
|
common/actions.c | ||
---|---|---|
/* Can't be enabled. No target. */
|
||
continue;
|
||
}
|
||
if (is_action_enabled_unit_on_unit(blocker->id,
|
||
if (is_action_enabled_unit_on_unit(nmap, blocker->id,
|
||
actor_unit, target_unit)) {
|
||
return blocker;
|
||
}
|
||
... | ... | |
See note in is_action_enabled() for why the action may still be disabled.
|
||
**************************************************************************/
|
||
bool is_action_enabled_unit_on_unit(const action_id wanted_action,
|
||
bool is_action_enabled_unit_on_unit(const struct civ_map *nmap,
|
||
const action_id wanted_action,
|
||
const struct unit *actor_unit,
|
||
const struct unit *target_unit)
|
||
{
|
||
const struct civ_map *nmap = &(wld.map);
|
||
return is_action_enabled_unit_on_unit_full(nmap, wanted_action, actor_unit,
|
||
unit_home(actor_unit),
|
||
unit_tile(actor_unit),
|
common/actions.h | ||
---|---|---|
const struct unit *actor_unit,
|
||
const struct city *target_city);
|
||
bool is_action_enabled_unit_on_unit(const action_id wanted_action,
|
||
bool is_action_enabled_unit_on_unit(const struct civ_map *nmap,
|
||
const action_id wanted_action,
|
||
const struct unit *actor_unit,
|
||
const struct unit *target_unit);
|
||
common/unit.c | ||
---|---|---|
bool can_unit_alight_or_be_unloaded(const struct unit *pcargo,
|
||
const struct unit *ptrans)
|
||
{
|
||
const struct civ_map *nmap = &(wld.map);
|
||
if (!pcargo || !ptrans) {
|
||
return FALSE;
|
||
}
|
||
... | ... | |
fc_assert_ret_val(unit_transport_get(pcargo) == ptrans, FALSE);
|
||
if (is_server()) {
|
||
return (is_action_enabled_unit_on_unit(ACTION_TRANSPORT_ALIGHT,
|
||
return (is_action_enabled_unit_on_unit(nmap, ACTION_TRANSPORT_ALIGHT,
|
||
pcargo, ptrans)
|
||
|| is_action_enabled_unit_on_unit(ACTION_TRANSPORT_UNLOAD,
|
||
|| is_action_enabled_unit_on_unit(nmap, ACTION_TRANSPORT_UNLOAD,
|
||
ptrans, pcargo));
|
||
} else {
|
||
return (action_prob_possible(
|
server/actiontools.c | ||
---|---|---|
break;
|
||
case ATK_UNIT:
|
||
if (tgt_unit
|
||
&& is_action_enabled_unit_on_unit(act, actor, tgt_unit)) {
|
||
&& is_action_enabled_unit_on_unit(nmap, act, actor, tgt_unit)) {
|
||
perform_action_to(act, actor, tgt_unit->id, EXTRA_NONE);
|
||
}
|
||
break;
|
||
... | ... | |
break;
|
||
case ATK_UNIT:
|
||
if (tgt_unit
|
||
&& is_action_enabled_unit_on_unit(act, actor, tgt_unit)) {
|
||
&& is_action_enabled_unit_on_unit(nmap, act, actor, tgt_unit)) {
|
||
current = action_prob_vs_unit(actor, act, tgt_unit);
|
||
}
|
||
break;
|
server/advisors/advgoto.c | ||
---|---|---|
struct action *paction;
|
||
struct player *pplayer = unit_owner(punit);
|
||
struct unit *ptrans = NULL;
|
||
const struct civ_map *nmap = &(wld.map);
|
||
/* if enemy, stop and give a chance for the human player to
|
||
/* If enemy, stop and give a chance for the human player to
|
||
handle this case */
|
||
if (is_enemy_unit_tile(ptile, pplayer)
|
||
|| is_enemy_city_tile(ptile, pplayer)) {
|
||
... | ... | |
}
|
||
/* 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,
|
||
&& 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(&(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,
|
||
&& 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(&(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,
|
||
&& is_action_enabled_unit_on_unit(nmap, ACTION_TRANSPORT_EMBARK3,
|
||
punit, ptrans)) {
|
||
/* "Transport Embark 3". */
|
||
paction = action_by_number(ACTION_TRANSPORT_EMBARK3);
|
||
... | ... | |
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;
|
server/barbarian.c | ||
---|---|---|
int checked_count;
|
||
int dir;
|
||
bool barbarian_stays = FALSE;
|
||
const struct civ_map *nmap = &(wld.map);
|
||
/* FIXME: When there is no L_BARBARIAN unit,
|
||
* but L_BARBARIAN_TECH is already available,
|
||
... | ... | |
/* Get information about surrounding terrains in terrain class level.
|
||
* Only needed if we consider moving units away to random directions. */
|
||
for (dir = 0; dir < 8; dir++) {
|
||
dir_tiles[dir] = mapstep(&(wld.map), ptile, dir);
|
||
dir_tiles[dir] = mapstep(nmap, ptile, dir);
|
||
if (dir_tiles[dir] == NULL) {
|
||
terrainc[dir] = terrain_class_invalid();
|
||
} else if (!is_non_allied_unit_tile(dir_tiles[dir], barbarians)) {
|
||
... | ... | |
checked_count++) {
|
||
int rdir = random_unchecked_direction(land_tiles - checked_count, checked);
|
||
if (unit_can_move_to_tile(&(wld.map), punit2, dir_tiles[rdir],
|
||
if (unit_can_move_to_tile(nmap, punit2, dir_tiles[rdir],
|
||
TRUE, FALSE, FALSE)) {
|
||
/* Move */
|
||
(void) unit_move_pay(punit2, dir_tiles[rdir]);
|
||
... | ... | |
/* We do have a boat. Try to get everybody in */
|
||
unit_list_iterate_safe((ptile)->units, punit2) {
|
||
if (unit_owner(punit2) == barbarians) {
|
||
if (is_action_enabled_unit_on_unit(ACTION_TRANSPORT_EMBARK,
|
||
if (is_action_enabled_unit_on_unit(nmap, ACTION_TRANSPORT_EMBARK,
|
||
punit2, boat)) {
|
||
/* Load */
|
||
unit_do_action(unit_owner(punit2), punit2->id, boat->id,
|
||
0, "", ACTION_TRANSPORT_EMBARK);
|
||
} else if (is_action_enabled_unit_on_unit(ACTION_TRANSPORT_EMBARK2,
|
||
} else if (is_action_enabled_unit_on_unit(nmap, ACTION_TRANSPORT_EMBARK2,
|
||
punit2, boat)) {
|
||
/* Load */
|
||
unit_do_action(unit_owner(punit2), punit2->id, boat->id,
|
||
0, "", ACTION_TRANSPORT_EMBARK2);
|
||
} else if (is_action_enabled_unit_on_unit(ACTION_TRANSPORT_EMBARK3,
|
||
} else if (is_action_enabled_unit_on_unit(nmap, ACTION_TRANSPORT_EMBARK3,
|
||
punit2, boat)) {
|
||
/* Load */
|
||
unit_do_action(unit_owner(punit2), punit2->id, boat->id,
|
||
... | ... | |
rdir = random_unchecked_direction(land_tiles - checked_count, checked);
|
||
if (unit_can_move_to_tile(&(wld.map), punit2, dir_tiles[rdir],
|
||
if (unit_can_move_to_tile(nmap, punit2, dir_tiles[rdir],
|
||
TRUE, FALSE, FALSE)) {
|
||
/* Move */
|
||
(void) unit_move_pay(punit2, dir_tiles[rdir]);
|
||
... | ... | |
bool hut_present = FALSE;
|
||
int city_count;
|
||
int city_max;
|
||
const struct civ_map *nmap = &(wld.map);
|
||
/* We attempt the summons on a particular, random position. If this is
|
||
* an invalid position then the summons simply fails this time. This means
|
||
* that a particular tile's chance of being summoned on is independent of
|
||
* all the other tiles on the map - which is essential for balanced
|
||
* gameplay. */
|
||
ptile = rand_map_pos(&(wld.map));
|
||
ptile = rand_map_pos(nmap);
|
||
if (terrain_has_flag(tile_terrain(ptile), TER_NO_BARBS)) {
|
||
return;
|
||
... | ... | |
if (is_native_tile(boat, utile)
|
||
&& !utype_player_already_has_this_unique(barbarians, boat)
|
||
&& (is_safe_ocean(&(wld.map), utile)
|
||
&& (is_safe_ocean(nmap, utile)
|
||
|| (!utype_has_flag(boat, UTYF_COAST_STRICT)
|
||
&& !utype_has_flag(boat, UTYF_COAST)))) {
|
||
int cap;
|
server/scripting/api_server_edit.c | ||
---|---|---|
bool api_edit_perform_action_unit_vs_unit(lua_State *L, Unit *punit,
|
||
Action *paction, Unit *tgt)
|
||
{
|
||
const struct civ_map *nmap = &(wld.map);
|
||
LUASCRIPT_CHECK_STATE(L, FALSE);
|
||
LUASCRIPT_CHECK_ARG_NIL(L, punit, 2, Unit, FALSE);
|
||
LUASCRIPT_CHECK_ARG_NIL(L, paction, 3, Action, FALSE);
|
||
... | ... | |
fc_assert_ret_val(action_get_actor_kind(paction) == AAK_UNIT, FALSE);
|
||
fc_assert_ret_val(action_get_target_kind(paction) == ATK_UNIT, FALSE);
|
||
fc_assert_ret_val(!action_has_result(paction, ACTRES_FOUND_CITY), FALSE);
|
||
if (is_action_enabled_unit_on_unit(paction->id, punit, tgt)) {
|
||
if (is_action_enabled_unit_on_unit(nmap, paction->id, punit, tgt)) {
|
||
return unit_perform_action(unit_owner(punit), punit->id,
|
||
tgt->id, IDENTITY_NUMBER_ZERO, "",
|
||
paction->id, ACT_REQ_RULES);
|
server/unithand.c | ||
---|---|---|
&& unit_perform_action(pplayer, punit->id, pcity->id, 0, "",
|
||
paction->id, ACT_REQ_SS_AGENT)) {
|
||
number_of_upgraded_units++;
|
||
} else if (UU_NO_MONEY == unit_upgrade_test(&(wld.map), punit, FALSE)) {
|
||
} else if (UU_NO_MONEY == unit_upgrade_test(nmap, punit, FALSE)) {
|
||
break;
|
||
}
|
||
}
|
||
... | ... | |
switch (paction->result) {
|
||
case ACTRES_SPY_BRIBE_UNIT:
|
||
if (punit
|
||
&& is_action_enabled_unit_on_unit(action_type,
|
||
&& is_action_enabled_unit_on_unit(nmap, action_type,
|
||
pactor, punit)) {
|
||
dsend_packet_unit_action_answer(pc,
|
||
actor_id32, actor_id16, target_id,
|
||
... | ... | |
case ATK_UNITS:
|
||
case ATK_TILE:
|
||
case ATK_EXTRAS:
|
||
target_tile = index_to_tile(&(wld.map), target_id);
|
||
target_tile = index_to_tile(nmap, target_id);
|
||
if (target_tile == NULL) {
|
||
log_verbose("unit_perform_action() invalid target tile %d",
|
||
target_id);
|
||
... | ... | |
#define ACTION_PERFORM_UNIT_UNIT(action, actor, target, action_performer) \
|
||
if (punit \
|
||
&& is_action_enabled_unit_on_unit(action_type, actor_unit, punit)) {\
|
||
&& is_action_enabled_unit_on_unit(nmap, action_type, actor_unit, punit)) { \
|
||
bool success; \
|
||
script_server_signal_emit("action_started_unit_unit", \
|
||
action_by_number(action), actor, target); \
|
||
... | ... | |
moves_used = unit_move_rate(punit) - punit->moves_left;
|
||
def_moves_used = unit_move_rate(pdefender) - pdefender->moves_left;
|
||
adj = base_get_direction_for_step(&(wld.map),
|
||
adj = base_get_direction_for_step(nmap,
|
||
punit->tile, pdefender->tile, &facing);
|
||
fc_assert(adj);
|
||
... | ... | |
{
|
||
struct player *pplayer = unit_owner(punit);
|
||
struct unit *ptrans;
|
||
const struct civ_map *nmap = &(wld.map);
|
||
/*** Phase 1: Attempted action interpretation checks ***/
|
||
... | ... | |
* An attempted move to a tile a unit can't move to is always interpreted
|
||
* as trying to perform an action (unless move_do_not_act is TRUE) */
|
||
if (!move_do_not_act) {
|
||
const bool can_not_move = !unit_can_move_to_tile(&(wld.map),
|
||
const bool can_not_move = !unit_can_move_to_tile(nmap,
|
||
punit, pdesttile,
|
||
FALSE, FALSE, FALSE);
|
||
bool one_action_may_be_legal
|
||
... | ... | |
return unit_perform_action(pplayer, punit->id, tile_index(pdesttile),
|
||
NO_TARGET, "", ACTION_UNIT_MOVE3,
|
||
ACT_REQ_PLAYER);
|
||
} else if (!can_unit_survive_at_tile(&(wld.map), punit, pdesttile)
|
||
} else if (!can_unit_survive_at_tile(nmap, punit, pdesttile)
|
||
&& ((ptrans = transporter_for_unit_at(punit, pdesttile)))
|
||
&& is_action_enabled_unit_on_unit(ACTION_TRANSPORT_EMBARK,
|
||
&& is_action_enabled_unit_on_unit(nmap, ACTION_TRANSPORT_EMBARK,
|
||
punit, ptrans)) {
|
||
/* "Transport Embark". */
|
||
return unit_perform_action(pplayer, punit->id, ptrans->id,
|
||
NO_TARGET, "", ACTION_TRANSPORT_EMBARK,
|
||
ACT_REQ_PLAYER);
|
||
} else if (!can_unit_survive_at_tile(&(wld.map), punit, pdesttile)
|
||
} else if (!can_unit_survive_at_tile(nmap, punit, pdesttile)
|
||
&& ((ptrans = transporter_for_unit_at(punit, pdesttile)))
|
||
&& is_action_enabled_unit_on_unit(ACTION_TRANSPORT_EMBARK2,
|
||
&& is_action_enabled_unit_on_unit(nmap, ACTION_TRANSPORT_EMBARK2,
|
||
punit, ptrans)) {
|
||
/* "Transport Embark 2". */
|
||
return unit_perform_action(pplayer, punit->id, ptrans->id,
|
||
NO_TARGET, "", ACTION_TRANSPORT_EMBARK2,
|
||
ACT_REQ_PLAYER);
|
||
} else if (!can_unit_survive_at_tile(&(wld.map), punit, pdesttile)
|
||
} else if (!can_unit_survive_at_tile(nmap, punit, pdesttile)
|
||
&& ((ptrans = transporter_for_unit_at(punit, pdesttile)))
|
||
&& is_action_enabled_unit_on_unit(ACTION_TRANSPORT_EMBARK3,
|
||
&& is_action_enabled_unit_on_unit(nmap, ACTION_TRANSPORT_EMBARK3,
|
||
punit, ptrans)) {
|
||
/* "Transport Embark 3". */
|
||
return unit_perform_action(pplayer, punit->id, ptrans->id,
|
||
... | ... | |
* perform against the target tile. Action decision state can be set by
|
||
* the server it self too. */
|
||
if (index_to_tile(&(wld.map), value) == NULL) {
|
||
if (index_to_tile(nmap, value) == NULL) {
|
||
/* Asked to be reminded to ask what actions the unit can do to a non
|
||
* existing target tile. */
|
||
log_verbose("unit_sscs_set() invalid target tile %d for unit %d",
|
||
... | ... | |
}
|
||
punit->action_decision_want = ACT_DEC_ACTIVE;
|
||
punit->action_decision_tile = index_to_tile(&(wld.map), value);
|
||
punit->action_decision_tile = index_to_tile(nmap, value);
|
||
/* Let the client know that this unit needs the player to decide
|
||
* what to do. */
|
- « Previous
- 1
- 2
- Next »