Feature #363 ยป 0051-Rename-action_._units-as-action_._stack.patch
| ai/default/daitools.c | ||
|---|---|---|
|
/* FIXME: try the next action if the unit tried to do an illegal action.
|
||
|
* That would allow the AI to stop using the omniscient
|
||
|
* is_action_enabled_unit_on_*() functions. */
|
||
|
if (is_action_enabled_unit_on_units(nmap, ACTION_CAPTURE_UNITS,
|
||
|
if (is_action_enabled_unit_on_stack(nmap, ACTION_CAPTURE_UNITS,
|
||
|
punit, ptile)) {
|
||
|
/* Choose capture. */
|
||
|
unit_do_action(unit_owner(punit), punit->id, tile_index(ptile),
|
||
|
0, "", ACTION_CAPTURE_UNITS);
|
||
|
} else if (is_action_enabled_unit_on_units(nmap, ACTION_BOMBARD_LETHAL,
|
||
|
} else if (is_action_enabled_unit_on_stack(nmap, ACTION_BOMBARD_LETHAL,
|
||
|
punit, ptile)) {
|
||
|
/* Choose "Bombard Lethal". */
|
||
|
unit_do_action(unit_owner(punit), punit->id, tile_index(ptile),
|
||
|
0, "", ACTION_BOMBARD_LETHAL);
|
||
|
} else if (is_action_enabled_unit_on_units(nmap, ACTION_BOMBARD,
|
||
|
} else if (is_action_enabled_unit_on_stack(nmap, ACTION_BOMBARD,
|
||
|
punit, ptile)) {
|
||
|
/* Choose "Bombard". */
|
||
|
unit_do_action(unit_owner(punit), punit->id, tile_index(ptile),
|
||
|
0, "", ACTION_BOMBARD);
|
||
|
} else if (is_action_enabled_unit_on_units(nmap, ACTION_BOMBARD2,
|
||
|
} else if (is_action_enabled_unit_on_stack(nmap, ACTION_BOMBARD2,
|
||
|
punit, ptile)) {
|
||
|
/* Choose "Bombard 2". */
|
||
|
unit_do_action(unit_owner(punit), punit->id, tile_index(ptile),
|
||
|
0, "", ACTION_BOMBARD2);
|
||
|
} else if (is_action_enabled_unit_on_units(nmap, ACTION_BOMBARD3,
|
||
|
} else if (is_action_enabled_unit_on_stack(nmap, ACTION_BOMBARD3,
|
||
|
punit, ptile)) {
|
||
|
/* Choose "Bombard 3". */
|
||
|
unit_do_action(unit_owner(punit), punit->id, tile_index(ptile),
|
||
|
0, "", ACTION_BOMBARD3);
|
||
|
} else if (is_action_enabled_unit_on_units(nmap, ACTION_NUKE_UNITS,
|
||
|
} else if (is_action_enabled_unit_on_stack(nmap, ACTION_NUKE_UNITS,
|
||
|
punit, ptile)) {
|
||
|
/* Choose "Nuke Units". */
|
||
|
unit_do_action(unit_owner(punit), punit->id, tile_index(ptile),
|
||
| ... | ... | |
|
/* Choose "Nuke City". */
|
||
|
unit_do_action(unit_owner(punit), punit->id, tcity->id,
|
||
|
0, "", ACTION_NUKE_CITY);
|
||
|
} else if (is_action_enabled_unit_on_units(nmap, ACTION_ATTACK,
|
||
|
} else if (is_action_enabled_unit_on_stack(nmap, ACTION_ATTACK,
|
||
|
punit, ptile)) {
|
||
|
/* Choose regular attack. */
|
||
|
unit_do_action(unit_owner(punit), punit->id, tile_index(ptile),
|
||
|
0, "", ACTION_ATTACK);
|
||
|
} else if (is_action_enabled_unit_on_units(nmap, ACTION_SUICIDE_ATTACK,
|
||
|
} else if (is_action_enabled_unit_on_stack(nmap, ACTION_SUICIDE_ATTACK,
|
||
|
punit, ptile)) {
|
||
|
/* Choose suicide attack (explode missile). */
|
||
|
unit_do_action(unit_owner(punit), punit->id, tile_index(ptile),
|
||
| client/control.c | ||
|---|---|---|
|
break;
|
||
|
case ATK_UNITS:
|
||
|
if ((ptile = unit_tile(punit))
|
||
|
&& action_prob_possible(action_prob_vs_units(punit, act, ptile))) {
|
||
|
&& action_prob_possible(action_prob_vs_stack(punit, act, ptile))) {
|
||
|
request_do_action(act, punit->id, ptile->index, 0, "");
|
||
|
}
|
||
|
break;
|
||
| common/actions.c | ||
|---|---|---|
|
/* Can't be enabled. No target. */
|
||
|
continue;
|
||
|
}
|
||
|
if (is_action_enabled_unit_on_units(nmap, blocker->id,
|
||
|
if (is_action_enabled_unit_on_stack(nmap, blocker->id,
|
||
|
actor_unit, target_tile)) {
|
||
|
return blocker;
|
||
|
}
|
||
| ... | ... | |
|
See note in is_action_enabled() for why the action may still be disabled.
|
||
|
**************************************************************************/
|
||
|
static bool
|
||
|
is_action_enabled_unit_on_units_full(const struct civ_map *nmap,
|
||
|
is_action_enabled_unit_on_stack_full(const struct civ_map *nmap,
|
||
|
const action_id wanted_action,
|
||
|
const struct unit *actor_unit,
|
||
|
const struct city *actor_home,
|
||
| ... | ... | |
|
See note in is_action_enabled() for why the action may still be disabled.
|
||
|
**************************************************************************/
|
||
|
bool is_action_enabled_unit_on_units(const struct civ_map *nmap,
|
||
|
bool is_action_enabled_unit_on_stack(const struct civ_map *nmap,
|
||
|
const action_id wanted_action,
|
||
|
const struct unit *actor_unit,
|
||
|
const struct tile *target_tile)
|
||
|
{
|
||
|
return is_action_enabled_unit_on_units_full(nmap, wanted_action, actor_unit,
|
||
|
return is_action_enabled_unit_on_stack_full(nmap, wanted_action, actor_unit,
|
||
|
unit_home(actor_unit),
|
||
|
unit_tile(actor_unit),
|
||
|
target_tile);
|
||
| ... | ... | |
|
action on all units at the target tile.
|
||
|
**************************************************************************/
|
||
|
static struct act_prob
|
||
|
action_prob_vs_units_full(const struct civ_map *nmap,
|
||
|
action_prob_vs_stack_full(const struct civ_map *nmap,
|
||
|
const struct unit *actor_unit,
|
||
|
const struct city *actor_home,
|
||
|
const struct tile *actor_tile,
|
||
| ... | ... | |
|
Get the actor unit's probability of successfully performing the chosen
|
||
|
action on all units at the target tile.
|
||
|
**************************************************************************/
|
||
|
struct act_prob action_prob_vs_units(const struct unit *actor_unit,
|
||
|
struct act_prob action_prob_vs_stack(const struct unit *actor_unit,
|
||
|
const action_id act_id,
|
||
|
const struct tile *target_tile)
|
||
|
{
|
||
|
const struct civ_map *nmap = &(wld.map);
|
||
|
return action_prob_vs_units_full(nmap, actor_unit,
|
||
|
return action_prob_vs_stack_full(nmap, actor_unit,
|
||
|
unit_home(actor_unit),
|
||
|
unit_tile(actor_unit),
|
||
|
act_id,
|
||
| ... | ... | |
|
switch (action_get_target_kind(paction)) {
|
||
|
case ATK_UNITS:
|
||
|
if (tgt_tile) {
|
||
|
prob = action_prob_vs_units(act_unit, paction->id, tgt_tile);
|
||
|
prob = action_prob_vs_stack(act_unit, paction->id, tgt_tile);
|
||
|
}
|
||
|
break;
|
||
|
case ATK_TILE:
|
||
| ... | ... | |
|
game state changes.
|
||
|
**************************************************************************/
|
||
|
struct act_prob
|
||
|
action_speculate_unit_on_units(action_id act_id,
|
||
|
action_speculate_unit_on_stack(action_id act_id,
|
||
|
const struct unit *actor,
|
||
|
const struct city *actor_home,
|
||
|
const struct tile *actor_tile,
|
||
| ... | ... | |
|
const struct civ_map *nmap = &(wld.map);
|
||
|
if (omniscient_cheat) {
|
||
|
if (is_action_enabled_unit_on_units_full(nmap, act_id,
|
||
|
if (is_action_enabled_unit_on_stack_full(nmap, act_id,
|
||
|
actor, actor_home, actor_tile,
|
||
|
target)) {
|
||
|
return ACTPROB_CERTAIN;
|
||
| ... | ... | |
|
return ACTPROB_IMPOSSIBLE;
|
||
|
}
|
||
|
} else {
|
||
|
return action_prob_vs_units_full(nmap, actor, actor_home, actor_tile,
|
||
|
return action_prob_vs_stack_full(nmap, actor, actor_home, actor_tile,
|
||
|
act_id, target);
|
||
|
}
|
||
|
}
|
||
| common/actions.h | ||
|---|---|---|
|
const struct unit *actor_unit,
|
||
|
const struct unit *target_unit);
|
||
|
bool is_action_enabled_unit_on_units(const struct civ_map *nmap,
|
||
|
bool is_action_enabled_unit_on_stack(const struct civ_map *nmap,
|
||
|
const action_id wanted_action,
|
||
|
const struct unit *actor_unit,
|
||
|
const struct tile *target_tile);
|
||
| ... | ... | |
|
const action_id act_id,
|
||
|
const struct unit* victim);
|
||
|
struct act_prob action_prob_vs_units(const struct unit* actor,
|
||
|
struct act_prob action_prob_vs_stack(const struct unit* actor,
|
||
|
const action_id act_id,
|
||
|
const struct tile* victims);
|
||
| ... | ... | |
|
const struct unit *target);
|
||
|
struct act_prob
|
||
|
action_speculate_unit_on_units(action_id act_id,
|
||
|
action_speculate_unit_on_stack(action_id act_id,
|
||
|
const struct unit *actor,
|
||
|
const struct city *actor_home,
|
||
|
const struct tile *actor_tile,
|
||
| server/actiontools.c | ||
|---|---|---|
|
prob = action_prob_vs_extras(actor, act, target, target_extra);
|
||
|
break;
|
||
|
case ATK_UNITS:
|
||
|
prob = action_prob_vs_units(actor, act, target);
|
||
|
prob = action_prob_vs_stack(actor, act, target);
|
||
|
break;
|
||
|
case ATK_CITY:
|
||
|
case ATK_UNIT:
|
||
| ... | ... | |
|
switch (action_id_get_target_kind(act)) {
|
||
|
case ATK_UNITS:
|
||
|
if (tgt_tile
|
||
|
&& is_action_enabled_unit_on_units(nmap, act, actor, tgt_tile)) {
|
||
|
&& is_action_enabled_unit_on_stack(nmap, act, actor, tgt_tile)) {
|
||
|
perform_action_to(act, actor, tgt_tile->index, EXTRA_NONE);
|
||
|
}
|
||
|
break;
|
||
| ... | ... | |
|
switch (action_id_get_target_kind(act)) {
|
||
|
case ATK_UNITS:
|
||
|
if (tgt_tile
|
||
|
&& is_action_enabled_unit_on_units(nmap, act, actor, tgt_tile)) {
|
||
|
current = action_prob_vs_units(actor, act, tgt_tile);
|
||
|
&& is_action_enabled_unit_on_stack(nmap, act, actor, tgt_tile)) {
|
||
|
current = action_prob_vs_stack(actor, act, tgt_tile);
|
||
|
}
|
||
|
break;
|
||
|
case ATK_TILE:
|
||
| server/advisors/autoworkers.c | ||
|---|---|---|
|
FALSE);
|
||
|
break;
|
||
|
case ATK_UNITS:
|
||
|
return action_prob_possible(action_speculate_unit_on_units(
|
||
|
return action_prob_possible(action_speculate_unit_on_stack(
|
||
|
paction->id,
|
||
|
punit, unit_home(punit), ptile,
|
||
|
omniscient_cheat,
|
||
| server/scripting/api_server_edit.c | ||
|---|---|---|
|
fc_assert_ret_val(action_get_actor_kind(paction) == AAK_UNIT, FALSE);
|
||
|
switch (action_get_target_kind(paction)) {
|
||
|
case ATK_UNITS:
|
||
|
enabled = is_action_enabled_unit_on_units(nmap, paction->id, punit, tgt);
|
||
|
enabled = is_action_enabled_unit_on_stack(nmap, paction->id, punit, tgt);
|
||
|
break;
|
||
|
case ATK_TILE:
|
||
|
enabled = is_action_enabled_unit_on_tile(nmap, paction->id, punit,
|
||
| ... | ... | |
|
fc_assert_ret_val(action_get_actor_kind(paction) == AAK_UNIT, FALSE);
|
||
|
switch (action_get_target_kind(paction)) {
|
||
|
case ATK_UNITS:
|
||
|
enabled = is_action_enabled_unit_on_units(nmap, paction->id, punit, tgt);
|
||
|
enabled = is_action_enabled_unit_on_stack(nmap, paction->id, punit, tgt);
|
||
|
break;
|
||
|
case ATK_TILE:
|
||
|
enabled = is_action_enabled_unit_on_tile(nmap, paction->id, punit,
|
||
| server/unithand.c | ||
|---|---|---|
|
case ATK_UNITS:
|
||
|
if (target_tile) {
|
||
|
/* Calculate the probabilities. */
|
||
|
probabilities[act] = action_prob_vs_units(actor_unit, act,
|
||
|
probabilities[act] = action_prob_vs_stack(actor_unit, act,
|
||
|
target_tile);
|
||
|
} else {
|
||
|
/* No target to act against. */
|
||
| ... | ... | |
|
#define ACTION_PERFORM_UNIT_UNITS(action, actor, target, action_performer)\
|
||
|
if (target_tile \
|
||
|
&& is_action_enabled_unit_on_units(nmap, action_type, \
|
||
|
&& is_action_enabled_unit_on_stack(nmap, action_type, \
|
||
|
actor_unit, target_tile)) { \
|
||
|
bool success; \
|
||
|
script_server_signal_emit("action_started_unit_units", \
|
||
| server/unittools.c | ||
|---|---|---|
|
switch (action_id_get_target_kind(order.action)) {
|
||
|
case ATK_UNITS:
|
||
|
prob = action_prob_vs_units(punit, order.action,
|
||
|
prob = action_prob_vs_stack(punit, order.action,
|
||
|
dst_tile);
|
||
|
tgt_id = dst_tile->index;
|
||
|
break;
|
||
| ... | ... | |
|
struct tile *dest = mapstep(&(wld.map), curtile, dirs[choice]);
|
||
|
if (dest != NULL) {
|
||
|
if (action_prob_possible(action_prob_vs_units(punit, ACTION_ATTACK,
|
||
|
if (action_prob_possible(action_prob_vs_stack(punit, ACTION_ATTACK,
|
||
|
dest))) {
|
||
|
if (unit_perform_action(pplayer, id, tile_index(dest), NO_TARGET,
|
||
|
"", ACTION_ATTACK, ACT_REQ_RULES)) {
|
||