Freeciv-3.3: /fast/freeciv/nightly/main/server/actiontools.c File Reference

Freeciv-3.3

Loading...
Searching...
No Matches
Macros | Typedefs | Functions
actiontools.c File Reference
`#include "rand.h"`
`#include "actions.h"`
`#include "aiiface.h"`
`#include "nation.h"`
`#include "notify.h"`
`#include "plrhand.h"`
`#include "unithand.h"`
`#include "unittools.h"`
`#include "actiontools.h"`

Go to the source code of this file.

## Macros

#define | action_auto_perf_acquire_targets(_target_extra_)
#define | perform_action_to(act, actor, tgtid, tgt_extra)

## Typedefs

typedef void(* | action_notify) (struct player *, const struct action *, struct player *, struct player *, const struct tile *, const char *)

## Functions

static void | action_success_actor_consume (struct action *paction, int actor_id, struct unit *actor)
static void | action_success_pay_mp (struct action *paction, int actor_id, struct unit *actor)
void | action_success_target_pay_mp (struct action *paction, int target_id, struct unit *target)
void | action_success_actor_price (struct action *paction, int actor_id, struct unit *actor)
static void | action_give_casus_belli (struct player *offender, struct player *victim_player, const bool int_outrage)
static void | action_consequence_common (const struct action *paction, struct player *offender, const struct unit_type *offender_utype, struct player *victim_player, const struct tile *victim_tile, const char *victim_link, const action_notify notify_actor, const action_notify notify_victim, const action_notify notify_global, const enum effect_type eft)
static void | notify_actor_caught (struct player *receiver, const struct action *paction, struct player *offender, struct player *victim_player, const struct tile *victim_tile, const char *victim_link)
static void | notify_victim_caught (struct player *receiver, const struct action *paction, struct player *offender, struct player *victim_player, const struct tile *victim_tile, const char *victim_link)
static void | notify_global_caught (struct player *receiver, const struct action *paction, struct player *offender, struct player *victim_player, const struct tile *victim_tile, const char *victim_link)
void | action_consequence_caught (const struct action *paction, struct player *offender, const struct unit_type *offender_utype, struct player *victim_player, const struct tile *victim_tile, const char *victim_link)
static void | notify_actor_success (struct player *receiver, const struct action *paction, struct player *offender, struct player *victim_player, const struct tile *victim_tile, const char *victim_link)
static void | notify_victim_success (struct player *receiver, const struct action *paction, struct player *offender, struct player *victim_player, const struct tile *victim_tile, const char *victim_link)
static void | notify_global_success (struct player *receiver, const struct action *paction, struct player *offender, struct player *victim_player, const struct tile *victim_tile, const char *victim_link)
void | action_consequence_success (const struct action *paction, struct player *offender, const struct unit_type *offender_utype, struct player *victim_player, const struct tile *victim_tile, const char *victim_link)
void | action_consequence_complete (const struct action *paction, struct player *offender, const struct unit_type *offender_utype, struct player *victim_player, const struct tile *victim_tile, const char *victim_link)
static bool | may_unit_act_vs_city (struct unit *actor, struct city *target, bool accept_all_actions)
struct city * | action_tgt_city (struct unit *actor, struct tile *target_tile, bool accept_all_actions)
static bool | may_unit_act_vs_unit (struct unit *actor, struct unit *target, 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, const struct extra_type *target_extra, bool accept_all_actions)
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)
struct extra_type * | action_tgt_tile_extra (const struct unit *actor, const struct tile *target_tile, bool accept_all_actions)
int | action_sub_target_id_for_action (const struct action *paction, struct unit *actor_unit)
const struct action_auto_perf * | action_auto_perf_unit_sel (const enum action_auto_perf_cause cause, const struct unit *actor, const struct player *other_player, const struct output_type *eval_output, const struct action *eval_action)
const struct action * | action_auto_perf_unit_do (const enum action_auto_perf_cause cause, struct unit *actor, const struct player *other_player, const struct output_type *eval_output, const struct action *eval_action, const struct tile *target_tile, const struct city *target_city, const struct unit *target_unit, const struct extra_type *target_extra)
struct act_prob | action_auto_perf_unit_prob (const enum action_auto_perf_cause cause, struct unit *actor, const struct player *other_player, const struct output_type *eval_output, const struct action *eval_action, const struct tile *target_tile, const struct city *target_city, const struct unit *target_unit, const struct extra_type *target_extra)
bool | action_failed_dice_roll (const struct player *act_player, const struct unit *act_unit, const struct city *tgt_city, const struct player *tgt_player, const struct action *paction)

## Macro Definition Documentation

## ◆ action_auto_perf_acquire_targets

#define action_auto_perf_acquire_targets | ( |  | _target_extra_ | ) |

Value:
tgt_city = (target_city ? target_city \
: action_tgt_city(actor, unit_tile(actor), \
TRUE)); \
tgt_tile = (target_tile ? target_tile \
: action_tgt_tile(actor, unit_tile(actor), \
_target_extra_, \
TRUE)); \
tgt_unit = (target_unit ? target_unit \
: action_tgt_unit(actor, unit_tile(actor), \
TRUE));
action_tgt_tile
struct tile * action_tgt_tile(struct unit *actor, struct tile *target, const struct extra_type *target_extra, bool accept_all_actions)
Definition actiontools.c:733
action_tgt_unit
struct unit * action_tgt_unit(struct unit *actor, struct tile *target_tile, bool accept_all_actions)
Definition actiontools.c:707
action_tgt_city
struct city * action_tgt_city(struct unit *actor, struct tile *target_tile, bool accept_all_actions)
Definition actiontools.c:640
incite_cost
char * incite_cost
Definition comments.c:74
target_unit
struct unit struct city struct unit * target_unit
Definition dialogs_g.h:56
actor
struct unit struct city struct unit struct tile struct extra_type const struct act_prob *act_probs int actor_unit_id struct unit * actor
Definition dialogs_g.h:73
target_tile
struct unit struct city struct unit struct tile * target_tile
Definition dialogs_g.h:57
target_city
struct unit struct city * target_city
Definition dialogs_g.h:56
TRUE
#define TRUE
Definition support.h:46
unit_tile
#define unit_tile(_pu)
Definition unit.h:397

Definition at line 977 of file actiontools.c.

## ◆ perform_action_to

#define perform_action_to | ( |  | act,
|  |  | actor,
|  |  | tgtid,
|  |  | tgt_extra
| ) |  |

Value:
if (unit_perform_action(unit_owner(actor), \
actor->id, tgtid, tgt_extra, \
NULL, act, ACT_REQ_RULES)) { \
return action_by_number(act); \
}
action_by_number
static struct action * action_by_number(action_id act_id)
Definition actions.h:390
unit::id
int id
Definition unit.h:147
unit_owner
#define unit_owner(_pu)
Definition unit.h:396
unit_perform_action
bool unit_perform_action(struct player *pplayer, const int actor_id, const int target_id, const int sub_tgt_id_incoming, const char *name, const action_id action_type, const enum action_requester requester)
Definition unithand.c:3337

## Typedef Documentation

## ◆ action_notify

typedef void(* action_notify) (struct player *, const struct action *, struct player *, struct player *, const struct tile *, const char *)

Definition at line 34 of file actiontools.c.

## Function Documentation

## ◆ action_auto_perf_unit_do()

const struct action * action_auto_perf_unit_do | ( | const enum action_auto_perf_cause | cause,
|  | struct unit * | actor,
|  | const struct player * | other_player,
|  | const struct output_type * | eval_output,
|  | const struct action * | eval_action,
|  | const struct tile * | target_tile,
|  | const struct city * | target_city,
|  | const struct unit * | target_unit,
|  | const struct extra_type * | target_extra
| ) |  |

Make the specified actor unit perform an action because of cause.

Returns the action the actor unit was forced to perform. Returns NULL if that didn't happen.

Note that the return value doesn't say anything about survival.

Definition at line 998 of file actiontools.c.

Referenced by diplomat_bribe(), kill_unit(), occupy_move(), remove_city(), unit_survive_autoattack(), and upkeep_kill_unit().

## ◆ action_auto_perf_unit_prob()

struct act_prob action_auto_perf_unit_prob | ( | const enum action_auto_perf_cause | cause,
|  | struct unit * | actor,
|  | const struct player * | other_player,
|  | const struct output_type * | eval_output,
|  | const struct action * | eval_action,
|  | const struct tile * | target_tile,
|  | const struct city * | target_city,
|  | const struct unit * | target_unit,
|  | const struct extra_type * | target_extra
| ) |  |

Returns the probability for the specified actor unit to be forced to perform an action by the specified cause.

Definition at line 1100 of file actiontools.c.

Referenced by unit_survive_autoattack().

## ◆ action_auto_perf_unit_sel()

const struct action_auto_perf * action_auto_perf_unit_sel | ( | const enum action_auto_perf_cause | cause,
|  | const struct unit * | actor,
|  | const struct player * | other_player,
|  | const struct output_type * | eval_output,
|  | const struct action * | eval_action
| ) |  |

Returns the action auto performer that the specified cause can force the specified actor to perform. Returns NULL if no such action auto performer exists.

Definition at line 947 of file actiontools.c.

Referenced by action_auto_perf_unit_do(), action_auto_perf_unit_prob(), and upkeep_kill_unit().

## ◆ action_consequence_caught()

void action_consequence_caught | ( | const struct action * | paction,
|  | struct player * | offender,
|  | const struct unit_type * | offender_utype,
|  | struct player * | victim_player,
|  | const struct tile * | victim_tile,
|  | const char * | victim_link
| ) |  |

Take care of any consequences (like casus belli) of getting caught while trying to perform the given action.

victim_player can be NULL

Definition at line 374 of file actiontools.c.

Referenced by diplomat_get_tech(), diplomat_incite(), diplomat_infiltrate_tile(), diplomat_sabotage(), do_paradrop(), spy_nuke_city(), spy_poison(), spy_spread_plague(), spy_steal_gold(), spy_steal_some_maps(), and unit_nuke().

## ◆ action_consequence_common()

static void action_consequence_common | ( | const struct action * | paction,
|  | struct player * | offender,
|  | const struct unit_type * | offender_utype,
|  | struct player * | victim_player,
|  | const struct tile * | victim_tile,
|  | const char * | victim_link,
|  | const action_notify | notify_actor,
|  | const action_notify | notify_victim,
|  | const action_notify | notify_global,
|  | const enum effect_type | eft
| ) |  |

static

Take care of any consequences (like casus belli) of the given action when the situation was as specified.

victim_player can be NULL

Definition at line 150 of file actiontools.c.

Referenced by action_consequence_caught(), action_consequence_complete(), and action_consequence_success().

## ◆ action_consequence_complete()

void action_consequence_complete | ( | const struct action * | paction,
|  | struct player * | offender,
|  | const struct unit_type * | offender_utype,
|  | struct player * | victim_player,
|  | const struct tile * | victim_tile,
|  | const char * | victim_link
| ) |  |

Definition at line 572 of file actiontools.c.

Referenced by update_unit_activity().

## ◆ action_consequence_success()

void action_consequence_success | ( | const struct action * | paction,
|  | struct player * | offender,
|  | const struct unit_type * | offender_utype,
|  | struct player * | victim_player,
|  | const struct tile * | victim_tile,
|  | const char * | victim_link
| ) |  |

Take care of any consequences (like casus belli) of successfully performing the given action.

victim_player can be NULL

Definition at line 551 of file actiontools.c.

Referenced by city_add_unit(), city_build(), diplomat_bribe(), diplomat_embassy(), diplomat_get_tech(), diplomat_incite(), diplomat_investigate(), diplomat_sabotage(), do_attack(), do_capture_units(), do_conquer_extras(), do_expel_unit(), do_heal_unit(), do_paradrop(), do_unit_conquer_city(), do_unit_establish_trade(), do_unit_strike_city_building(), do_unit_strike_city_production(), do_wipe_units(), spy_attack(), spy_escape(), spy_nuke_city(), spy_poison(), spy_sabotage_unit(), spy_spread_plague(), spy_steal_gold(), spy_steal_some_maps(), unit_activity_targeted_internal(), unit_bombard(), unit_do_destroy_city(), unit_do_help_build(), unit_do_regular_move(), and unit_nuke().

## ◆ action_failed_dice_roll()

bool action_failed_dice_roll | ( | const struct player * | act_player,
|  | const struct unit * | act_unit,
|  | const struct city * | tgt_city,
|  | const struct player * | tgt_player,
|  | const struct action * | paction
| ) |  |

Returns TRUE iff the spy/diplomat was caught outside of a diplomatic battle.

Definition at line 1192 of file actiontools.c.

Referenced by diplomat_get_tech(), diplomat_incite(), diplomat_sabotage(), do_unit_strike_city_building(), do_unit_strike_city_production(), spy_nuke_city(), spy_poison(), spy_spread_plague(), spy_steal_gold(), and spy_steal_some_maps().

## ◆ action_give_casus_belli()

static void action_give_casus_belli | ( | struct player * | offender,
|  | struct player * | victim_player,
|  | const bool | int_outrage
| ) |  |

static

Give the victim a casus belli against the offender.

Definition at line 115 of file actiontools.c.

Referenced by action_consequence_common().

## ◆ action_sub_target_id_for_action()

int action_sub_target_id_for_action | ( | const struct action * | paction,
|  | struct unit * | actor_unit
| ) |  |

Find an sub target for the specified action.

Definition at line 885 of file actiontools.c.

Referenced by execute_orders(), and unit_perform_action().

## ◆ action_success_actor_consume()

static void action_success_actor_consume | ( | struct action * | paction,
|  | int | actor_id,
|  | struct unit * | actor
| ) |  |

static

Wipe an actor if the action it successfully performed consumed it.

Definition at line 44 of file actiontools.c.

Referenced by action_success_actor_price().

## ◆ action_success_actor_price()

void action_success_actor_price | ( | struct action * | paction,
|  | int | actor_id,
|  | struct unit * | actor
| ) |  |

Make the actor that successfully performed the action pay the price.

Definition at line 105 of file actiontools.c.

## ◆ action_success_pay_mp()

static void action_success_pay_mp | ( | struct action * | paction,
|  | int | actor_id,
|  | struct unit * | actor
| ) |  |

static

Pay the movement point cost of success.

Definition at line 67 of file actiontools.c.

Referenced by action_success_actor_price().

## ◆ action_success_target_pay_mp()

void action_success_target_pay_mp | ( | struct action * | paction,
|  | int | target_id,
|  | struct unit * | target
| ) |  |

Pay the movement point price of being the target of an action.

Definition at line 80 of file actiontools.c.

## ◆ action_tgt_city()

struct city * action_tgt_city | ( | struct unit * | actor,
|  | struct tile * | target_tile,
|  | bool | accept_all_actions
| ) |  |

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.

Definition at line 640 of file actiontools.c.

Referenced by handle_unit_get_actions(), unit_move(), and unit_move_handling().

## ◆ action_tgt_tile()

struct tile * action_tgt_tile | ( | struct unit * | actor,
|  | struct tile * | target,
|  | const struct extra_type * | target_extra,
|  | bool | accept_all_actions
| ) |  |

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.

Definition at line 733 of file actiontools.c.

Referenced by unit_move_handling().

## ◆ action_tgt_tile_extra()

struct extra_type * action_tgt_tile_extra | ( | const struct unit * | actor,
|  | const struct tile * | target_tile,
|  | bool | accept_all_actions
| ) |  |

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.

Definition at line 868 of file actiontools.c.

Referenced by handle_unit_get_actions(), and unit_move_handling().

## ◆ action_tgt_unit()

struct unit * action_tgt_unit | ( | struct unit * | actor,
|  | struct tile * | target_tile,
|  | bool | accept_all_actions
| ) |  |

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.

Definition at line 707 of file actiontools.c.

Referenced by execute_orders(), handle_unit_get_actions(), and unit_move_handling().

## ◆ may_unit_act_vs_city()

static bool may_unit_act_vs_city | ( | struct unit * | actor,
|  | struct city * | target,
|  | bool | accept_all_actions
| ) |  |

static

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.

Definition at line 599 of file actiontools.c.

Referenced by action_tgt_city().

## ◆ may_unit_act_vs_tile_extra()

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
| ) |  |

static

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.

Definition at line 799 of file actiontools.c.

Referenced by action_tgt_tile_extra().

## ◆ may_unit_act_vs_unit()

static bool may_unit_act_vs_unit | ( | struct unit * | actor,
|  | struct unit * | target,
|  | bool | accept_all_actions
| ) |  |

static

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.

Definition at line 665 of file actiontools.c.

Referenced by action_tgt_unit().

## ◆ notify_actor_caught()

static void notify_actor_caught | ( | struct player * | receiver,
|  | const struct action * | paction,
|  | struct player * | offender,
|  | struct player * | victim_player,
|  | const struct tile * | victim_tile,
|  | const char * | victim_link
| ) |  |

static

Notify the actor that the failed action gave the victim a casus belli against the actor.

Definition at line 210 of file actiontools.c.

Referenced by action_consequence_caught().

## ◆ notify_actor_success()

static void notify_actor_success | ( | struct player * | receiver,
|  | const struct action * | paction,
|  | struct player * | offender,
|  | struct player * | victim_player,
|  | const struct tile * | victim_tile,
|  | const char * | victim_link
| ) |  |

static

Notify the actor that the performed action gave the victim a casus belli against the actor.

Definition at line 393 of file actiontools.c.

Referenced by action_consequence_complete(), and action_consequence_success().

## ◆ notify_global_caught()

static void notify_global_caught | ( | struct player * | receiver,
|  | const struct action * | paction,
|  | struct player * | offender,
|  | struct player * | victim_player,
|  | const struct tile * | victim_tile,
|  | const char * | victim_link
| ) |  |

static

Notify the world that the failed action gave the everyone a casus belli against the actor.

Definition at line 326 of file actiontools.c.

Referenced by action_consequence_caught().

## ◆ notify_global_success()

static void notify_global_success | ( | struct player * | receiver,
|  | const struct action * | paction,
|  | struct player * | offender,
|  | struct player * | victim_player,
|  | const struct tile * | victim_tile,
|  | const char * | victim_link
| ) |  |

static

Notify the world that the performed action gave the everyone a casus belli against the actor.

Definition at line 504 of file actiontools.c.

Referenced by action_consequence_complete(), and action_consequence_success().

## ◆ notify_victim_caught()

static void notify_victim_caught | ( | struct player * | receiver,
|  | const struct action * | paction,
|  | struct player * | offender,
|  | struct player * | victim_player,
|  | const struct tile * | victim_tile,
|  | const char * | victim_link
| ) |  |

static

Notify the victim that the failed action gave the victim a casus belli against the actor.

Definition at line 267 of file actiontools.c.

Referenced by action_consequence_caught().

## ◆ notify_victim_success()

static void notify_victim_success | ( | struct player * | receiver,
|  | const struct action * | paction,
|  | struct player * | offender,
|  | struct player * | victim_player,
|  | const struct tile * | victim_tile,
|  | const char * | victim_link
| ) |  |

static

Notify the victim that the performed action gave the victim a casus belli against the actor.

Definition at line 447 of file actiontools.c.

Referenced by action_consequence_complete(), and action_consequence_success().