Freeciv21
Develop your civilization from humble roots to a global empire
actiontools.cpp File Reference
#include "rand.h"
#include "actions.h"
#include "nation.h"
#include "aiiface.h"
#include "notify.h"
#include "plrhand.h"
#include "unithand.h"
#include "unittools.h"
#include "actiontools.h"
+ Include dependency graph for actiontools.cpp:

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)
 Wipe an actor if the action it successfully performed consumed it. More...
 
static void action_success_pay_mp (struct action *paction, int actor_id, struct unit *actor)
 Pay the movement point cost of success. More...
 
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. More...
 
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. More...
 
static void action_give_casus_belli (struct player *offender, struct player *victim_player, const bool int_outrage)
 Give the victim a casus belli against the offender. More...
 
static void action_consequence_common (const struct action *paction, struct player *offender, 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)
 Take care of any consequences (like casus belli) of the given action when the situation was as specified. More...
 
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)
 Notify the actor that the failed action gave the victim a casus belli against the actor. More...
 
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)
 Notify the victim that the failed action gave the victim a casus belli against the actor. More...
 
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)
 Notify the world that the failed action gave the everyone a casus belli against the actor. More...
 
void action_consequence_caught (const struct action *paction, struct player *offender, 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. More...
 
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)
 Notify the actor that the performed action gave the victim a casus belli against the actor. More...
 
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)
 Notify the victim that the performed action gave the victim a casus belli against the actor. More...
 
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)
 Notify the world that the performed action gave the everyone a casus belli against the actor. More...
 
void action_consequence_success (const struct action *paction, struct player *offender, 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. More...
 
void action_consequence_complete (const struct action *paction, struct player *offender, struct player *victim_player, const struct tile *victim_tile, const char *victim_link)
 Take care of any consequences (like casus belli) of successfully completing the given action. More...
 
int action_sub_target_id_for_action (const struct action *paction, struct unit *actor_unit)
 Find an sub target for the specified action. More...
 
const struct action_auto_perfaction_auto_perf_unit_sel (const enum action_auto_perf_cause cause, const struct unit *actor, const struct player *other_player, const struct output_type *output)
 Returns the action auto performer that the specified cause can force the specified actor to perform. More...
 
const struct actionaction_auto_perf_unit_do (const enum action_auto_perf_cause cause, struct unit *actor, const struct player *other_player, const struct output_type *output, 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. More...
 
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 *output, 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. More...
 
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. More...
 

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));
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.
Definition: actions.cpp:7050
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.
Definition: actions.cpp:6983
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 t...
Definition: actions.cpp:7078
#define unit_tile(_pu)
Definition: unit.h:371

Definition at line 612 of file actiontools.cpp.

◆ 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, \
nullptr, act, ACT_REQ_RULES)) { \
return action_by_number(act); \
}
struct action * action_by_number(action_id act_id)
Return the action with the given id.
Definition: actions.cpp:1149
#define unit_owner(_pu)
Definition: unit.h:370
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)
Execute a request to perform an action and let the caller know if it was performed or not.
Definition: unithand.cpp:2737

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 27 of file actiontools.cpp.

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 output,
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 nullptr if that didn't happen.

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

Definition at line 631 of file actiontools.cpp.

Referenced by 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 output,
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 631 of file actiontools.cpp.

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

Returns the action auto performer that the specified cause can force the specified actor to perform.

Returns nullptr if no such action auto performer exists.

Definition at line 592 of file actiontools.cpp.

Referenced by action_auto_perf_unit_do(), and upkeep_kill_unit().

◆ action_consequence_caught()

void action_consequence_caught ( const struct action paction,
struct player offender,
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 nullptr

Definition at line 337 of file actiontools.cpp.

Referenced by diplomat_get_tech(), diplomat_incite(), diplomat_infiltrate_tile(), diplomat_sabotage(), spy_nuke_city(), 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,
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 nullptr

Definition at line 134 of file actiontools.cpp.

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,
struct player victim_player,
const struct tile victim_tile,
const char *  victim_link 
)

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

victim_player can be nullptr

Definition at line 514 of file actiontools.cpp.

Referenced by unit_activity_complete().

◆ action_consequence_success()

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

◆ 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 797 of file actiontools.cpp.

Referenced by diplomat_get_tech(), diplomat_incite(), diplomat_sabotage(), do_unit_strike_city_building(), do_unit_strike_city_production(), spy_nuke_city(), 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 98 of file actiontools.cpp.

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 529 of file actiontools.cpp.

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 34 of file actiontools.cpp.

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 88 of file actiontools.cpp.

◆ 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 57 of file actiontools.cpp.

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 70 of file actiontools.cpp.

◆ 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 193 of file actiontools.cpp.

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 354 of file actiontools.cpp.

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 296 of file actiontools.cpp.

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 453 of file actiontools.cpp.

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 243 of file actiontools.cpp.

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 400 of file actiontools.cpp.

Referenced by action_consequence_complete(), and action_consequence_success().