Project

Profile

Help

HostedRedmine.com has moved to the Planio platform. All logins and passwords remained the same. All users will be able to login and use Redmine just as before. *Read more...*

Feature #875938 ยป 0013-Move-target-finders-to-the-actions-module.patch

Sveinung Kvilhaugsvik, 2020-06-02 06:45 AM

View differences:

common/actions.c
return FALSE;
}
/**********************************************************************//**
Returns TRUE iff, from the point of view of the owner of the actor unit,
it looks like the actor unit may be able to do any action to the target
city.
If the owner of the actor unit doesn't have the knowledge needed to know
for sure if the unit can act TRUE will be returned.
If the only action(s) that can be performed against a target has the
rare_pop_up property the target will only be considered valid if the
accept_all_actions argument is TRUE.
**************************************************************************/
static bool may_unit_act_vs_city(struct unit *actor, struct city *target,
bool accept_all_actions)
{
if (actor == NULL || target == NULL) {
/* Can't do any actions if actor or target are missing. */
return FALSE;
}
action_iterate(act) {
if (!(action_id_get_actor_kind(act) == AAK_UNIT
&& action_id_get_target_kind(act) == ATK_CITY)) {
/* Not a relevant action. */
continue;
}
if (action_id_is_rare_pop_up(act) && !accept_all_actions) {
/* Not relevant since not accepted here. */
continue;
}
if (action_prob_possible(action_prob_vs_city(actor, act, target))) {
/* The actor unit may be able to do this action to the target
* city. */
return TRUE;
}
} action_iterate_end;
return FALSE;
}
/**********************************************************************//**
Find a city to target for an action on the specified tile.
Returns NULL if no proper target is found.
If the only action(s) that can be performed against a target has the
rare_pop_up property the target will only be considered valid if the
accept_all_actions argument is TRUE.
**************************************************************************/
struct city *action_tgt_city(struct unit *actor, struct tile *target_tile,
bool accept_all_actions)
{
struct city *target = tile_city(target_tile);
if (target && may_unit_act_vs_city(actor, target, accept_all_actions)) {
/* It may be possible to act against this city. */
return target;
}
return NULL;
}
/**********************************************************************//**
Returns TRUE iff, from the point of view of the owner of the actor unit,
it looks like the actor unit may be able to do any action to the target
unit.
If the owner of the actor unit doesn't have the knowledge needed to know
for sure if the unit can act TRUE will be returned.
If the only action(s) that can be performed against a target has the
rare_pop_up property the target will only be considered valid if the
accept_all_actions argument is TRUE.
**************************************************************************/
static bool may_unit_act_vs_unit(struct unit *actor, struct unit *target,
bool accept_all_actions)
{
if (actor == NULL || target == NULL) {
/* Can't do any actions if actor or target are missing. */
return FALSE;
}
action_iterate(act) {
if (!(action_id_get_actor_kind(act) == AAK_UNIT
&& action_id_get_target_kind(act) == ATK_UNIT)) {
/* Not a relevant action. */
continue;
}
if (action_id_is_rare_pop_up(act) && !accept_all_actions) {
/* Not relevant since not accepted here. */
continue;
}
if (action_prob_possible(action_prob_vs_unit(actor, act, target))) {
/* The actor unit may be able to do this action to the target
* unit. */
return TRUE;
}
} action_iterate_end;
return FALSE;
}
/**********************************************************************//**
Find a unit to target for an action at the specified tile.
Returns the first unit found at the tile that the actor may act against
or NULL if no proper target is found.
If the only action(s) that can be performed against a target has the
rare_pop_up property the target will only be considered valid if the
accept_all_actions argument is TRUE.
**************************************************************************/
struct unit *action_tgt_unit(struct unit *actor, struct tile *target_tile,
bool accept_all_actions)
{
unit_list_iterate(target_tile->units, target) {
if (may_unit_act_vs_unit(actor, target, accept_all_actions)) {
return target;
}
} unit_list_iterate_end;
return NULL;
}
/**********************************************************************//**
Returns the tile iff it, from the point of view of the owner of the
actor unit, looks like a target tile.
Returns NULL if the player knows that the actor unit can't do any
action (that specifies its target as a tile) to the tile.
If the owner of the actor unit doesn't have the knowledge needed to know
for sure if the unit can act the tile will be returned.
If the only action(s) that can be performed against a target has the
rare_pop_up property the target will only be considered valid if the
accept_all_actions argument is TRUE.
**************************************************************************/
struct tile *action_tgt_tile(struct unit *actor,
struct tile *target,
const struct extra_type *target_extra,
bool accept_all_actions)
{
if (actor == NULL || target == NULL) {
/* Can't do any actions if actor or target are missing. */
return NULL;
}
action_iterate(act) {
struct act_prob prob;
if (action_id_get_actor_kind(act) != AAK_UNIT) {
/* Not a relevant action. */
continue;
}
if (action_id_is_rare_pop_up(act) && !accept_all_actions) {
/* Not relevant since not accepted here. */
continue;
}
switch (action_id_get_target_kind(act)) {
case ATK_TILE:
prob = action_prob_vs_tile(actor, act, target, target_extra);
break;
case ATK_UNITS:
prob = action_prob_vs_units(actor, act, target);
break;
case ATK_CITY:
case ATK_UNIT:
case ATK_SELF:
/* Target not specified by tile. */
continue;
case ATK_COUNT:
/* Invalid target kind */
fc_assert(action_id_get_target_kind(act) != ATK_COUNT);
continue;
}
if (action_prob_possible(prob)) {
/* The actor unit may be able to do this action to the target
* tile. */
return target;
}
} action_iterate_end;
return NULL;
}
/**********************************************************************//**
Returns TRUE iff, from the point of view of the owner of the actor unit,
it looks like the actor unit may be able to do any action to the target
extra located at the target tile.
If the owner of the actor unit doesn't have the knowledge needed to know
for sure if the unit can act TRUE will be returned.
If the only action(s) that can be performed against a target has the
rare_pop_up property the target will only be considered valid if the
accept_all_actions argument is TRUE.
**************************************************************************/
static bool may_unit_act_vs_tile_extra(const struct unit *actor,
const struct tile *tgt_tile,
const struct extra_type *tgt_extra,
bool accept_all_actions)
{
if (actor == NULL || tgt_tile == NULL || tgt_extra == NULL) {
/* Can't do any actions if actor or target are missing. */
return FALSE;
}
action_iterate(act) {
if (!(action_id_get_actor_kind(act) == AAK_UNIT
&& action_id_get_target_kind(act) == ATK_TILE
&& action_id_has_complex_target(act))) {
/* Not a relevant action. */
continue;
}
if (action_id_is_rare_pop_up(act) && !accept_all_actions) {
/* Not relevant since not accepted here. */
continue;
}
if (action_prob_possible(action_prob_vs_tile(actor, act,
tgt_tile, tgt_extra))) {
/* The actor unit may be able to do this action to the target
* extra. */
return TRUE;
}
} action_iterate_end;
return FALSE;
}
/**********************************************************************//**
Find an extra to target for an action at the specified tile.
Returns the first extra found that the actor may act against at the tile
or NULL if no proper target is found. (Note that some actions requires
the absence of an extra since they result in its creation while other
requires its presence.)
If the only action(s) that can be performed against a target has the
rare_pop_up property the target will only be considered valid if the
accept_all_actions argument is TRUE.
**************************************************************************/
struct extra_type *action_tgt_tile_extra(const struct unit *actor,
const struct tile *target_tile,
bool accept_all_actions)
{
extra_type_re_active_iterate(target) {
if (may_unit_act_vs_tile_extra(actor, target_tile, target,
accept_all_actions)) {
return target;
}
} extra_type_re_active_iterate_end;
return NULL;
}
/**********************************************************************//**
Return ui_name ruleset variable name for the action.
common/actions.h
action_actor_utype_hard_reqs_ok(enum action_result result,
const struct unit_type *actor_unittype);
/* Action target on tile locators */
struct city *action_tgt_city(struct unit *actor, struct tile *target_tile,
bool accept_all_actions);
struct unit *action_tgt_unit(struct unit *actor, struct tile *target_tile,
bool accept_all_actions);
struct tile *action_tgt_tile(struct unit *actor,
struct tile *target_tile,
const struct extra_type *target_extra,
bool accept_all_actions);
struct extra_type *action_tgt_tile_extra(const struct unit *actor,
const struct tile *target_tile,
bool accept_all_actions);
/* Reasoning about actions */
bool action_immune_government(struct government *gov, action_id act);
server/actiontools.c
EFT_CASUS_BELLI_COMPLETE);
}
/**********************************************************************//**
Returns TRUE iff, from the point of view of the owner of the actor unit,
it looks like the actor unit may be able to do any action to the target
city.
If the owner of the actor unit doesn't have the knowledge needed to know
for sure if the unit can act TRUE will be returned.
If the only action(s) that can be performed against a target has the
rare_pop_up property the target will only be considered valid if the
accept_all_actions argument is TRUE.
**************************************************************************/
static bool may_unit_act_vs_city(struct unit *actor, struct city *target,
bool accept_all_actions)
{
if (actor == NULL || target == NULL) {
/* Can't do any actions if actor or target are missing. */
return FALSE;
}
action_iterate(act) {
if (!(action_id_get_actor_kind(act) == AAK_UNIT
&& action_id_get_target_kind(act) == ATK_CITY)) {
/* Not a relevant action. */
continue;
}
if (action_id_is_rare_pop_up(act) && !accept_all_actions) {
/* Not relevant since not accepted here. */
continue;
}
if (action_prob_possible(action_prob_vs_city(actor, act, target))) {
/* The actor unit may be able to do this action to the target
* city. */
return TRUE;
}
} action_iterate_end;
return FALSE;
}
/**********************************************************************//**
Find a city to target for an action on the specified tile.
Returns NULL if no proper target is found.
If the only action(s) that can be performed against a target has the
rare_pop_up property the target will only be considered valid if the
accept_all_actions argument is TRUE.
**************************************************************************/
struct city *action_tgt_city(struct unit *actor, struct tile *target_tile,
bool accept_all_actions)
{
struct city *target = tile_city(target_tile);
if (target && may_unit_act_vs_city(actor, target, accept_all_actions)) {
/* It may be possible to act against this city. */
return target;
}
return NULL;
}
/**********************************************************************//**
Returns TRUE iff, from the point of view of the owner of the actor unit,
it looks like the actor unit may be able to do any action to the target
unit.
If the owner of the actor unit doesn't have the knowledge needed to know
for sure if the unit can act TRUE will be returned.
If the only action(s) that can be performed against a target has the
rare_pop_up property the target will only be considered valid if the
accept_all_actions argument is TRUE.
**************************************************************************/
static bool may_unit_act_vs_unit(struct unit *actor, struct unit *target,
bool accept_all_actions)
{
if (actor == NULL || target == NULL) {
/* Can't do any actions if actor or target are missing. */
return FALSE;
}
action_iterate(act) {
if (!(action_id_get_actor_kind(act) == AAK_UNIT
&& action_id_get_target_kind(act) == ATK_UNIT)) {
/* Not a relevant action. */
continue;
}
if (action_id_is_rare_pop_up(act) && !accept_all_actions) {
/* Not relevant since not accepted here. */
continue;
}
if (action_prob_possible(action_prob_vs_unit(actor, act, target))) {
/* The actor unit may be able to do this action to the target
* unit. */
return TRUE;
}
} action_iterate_end;
return FALSE;
}
/**********************************************************************//**
Find a unit to target for an action at the specified tile.
Returns the first unit found at the tile that the actor may act against
or NULL if no proper target is found.
If the only action(s) that can be performed against a target has the
rare_pop_up property the target will only be considered valid if the
accept_all_actions argument is TRUE.
**************************************************************************/
struct unit *action_tgt_unit(struct unit *actor, struct tile *target_tile,
bool accept_all_actions)
{
unit_list_iterate(target_tile->units, target) {
if (may_unit_act_vs_unit(actor, target, accept_all_actions)) {
return target;
}
} unit_list_iterate_end;
return NULL;
}
/**********************************************************************//**
Returns the tile iff it, from the point of view of the owner of the
actor unit, looks like a target tile.
Returns NULL if the player knows that the actor unit can't do any
action (that specifies its target as a tile) to the tile.
If the owner of the actor unit doesn't have the knowledge needed to know
for sure if the unit can act the tile will be returned.
If the only action(s) that can be performed against a target has the
rare_pop_up property the target will only be considered valid if the
accept_all_actions argument is TRUE.
**************************************************************************/
struct tile *action_tgt_tile(struct unit *actor,
struct tile *target,
const struct extra_type *target_extra,
bool accept_all_actions)
{
if (actor == NULL || target == NULL) {
/* Can't do any actions if actor or target are missing. */
return NULL;
}
action_iterate(act) {
struct act_prob prob;
if (action_id_get_actor_kind(act) != AAK_UNIT) {
/* Not a relevant action. */
continue;
}
if (action_id_is_rare_pop_up(act) && !accept_all_actions) {
/* Not relevant since not accepted here. */
continue;
}
switch (action_id_get_target_kind(act)) {
case ATK_TILE:
prob = action_prob_vs_tile(actor, act, target, target_extra);
break;
case ATK_UNITS:
prob = action_prob_vs_units(actor, act, target);
break;
case ATK_CITY:
case ATK_UNIT:
case ATK_SELF:
/* Target not specified by tile. */
continue;
case ATK_COUNT:
/* Invalid target kind */
fc_assert(action_id_get_target_kind(act) != ATK_COUNT);
continue;
}
if (action_prob_possible(prob)) {
/* The actor unit may be able to do this action to the target
* tile. */
return target;
}
} action_iterate_end;
return NULL;
}
/**********************************************************************//**
Returns TRUE iff, from the point of view of the owner of the actor unit,
it looks like the actor unit may be able to do any action to the target
extra located at the target tile.
If the owner of the actor unit doesn't have the knowledge needed to know
for sure if the unit can act TRUE will be returned.
If the only action(s) that can be performed against a target has the
rare_pop_up property the target will only be considered valid if the
accept_all_actions argument is TRUE.
**************************************************************************/
static bool may_unit_act_vs_tile_extra(const struct unit *actor,
const struct tile *tgt_tile,
const struct extra_type *tgt_extra,
bool accept_all_actions)
{
if (actor == NULL || tgt_tile == NULL || tgt_extra == NULL) {
/* Can't do any actions if actor or target are missing. */
return FALSE;
}
action_iterate(act) {
if (!(action_id_get_actor_kind(act) == AAK_UNIT
&& action_id_get_target_kind(act) == ATK_TILE
&& action_id_has_complex_target(act))) {
/* Not a relevant action. */
continue;
}
if (action_id_is_rare_pop_up(act) && !accept_all_actions) {
/* Not relevant since not accepted here. */
continue;
}
if (action_prob_possible(action_prob_vs_tile(actor, act,
tgt_tile, tgt_extra))) {
/* The actor unit may be able to do this action to the target
* extra. */
return TRUE;
}
} action_iterate_end;
return FALSE;
}
/**********************************************************************//**
Find an extra to target for an action at the specified tile.
Returns the first extra found that the actor may act against at the tile
or NULL if no proper target is found. (Note that some actions requires
the absence of an extra since they result in its creation while other
requires its presence.)
If the only action(s) that can be performed against a target has the
rare_pop_up property the target will only be considered valid if the
accept_all_actions argument is TRUE.
**************************************************************************/
struct extra_type *action_tgt_tile_extra(const struct unit *actor,
const struct tile *target_tile,
bool accept_all_actions)
{
extra_type_re_active_iterate(target) {
if (may_unit_act_vs_tile_extra(actor, target_tile, target,
accept_all_actions)) {
return target;
}
} extra_type_re_active_iterate_end;
return NULL;
}
/**********************************************************************//**
Returns the action auto performer that the specified cause can force the
specified actor to perform. Returns NULL if no such action auto performer
server/actiontools.h
void action_success_actor_price(struct action *paction,
int actor_id, struct unit *actor);
struct city *action_tgt_city(struct unit *actor, struct tile *target_tile,
bool accept_all_actions);
struct unit *action_tgt_unit(struct unit *actor, struct tile *target_tile,
bool accept_all_actions);
struct tile *action_tgt_tile(struct unit *actor,
struct tile *target_tile,
const struct extra_type *target_extra,
bool accept_all_actions);
struct extra_type *action_tgt_tile_extra(const struct unit *actor,
const struct tile *target_tile,
bool accept_all_actions);
const struct action_auto_perf *
action_auto_perf_unit_sel(const enum action_auto_perf_cause cause,
const struct unit *actor,
    (1-1/1)