#include "conq.h"
#include "kernel.h"
#include "action.def"
Include dependency graph for actions.c:
Defines | |
#define | DEF_ACTION(name, code, args, prepfn, netprepfn, DOFN, checkfn, ARGDECL, doc) extern int DOFN ARGDECL; |
#define | DEF_ACTION(NAME, CODE, ARGS, prepfn, netprepfn, dofn, checkfn, argdecl, doc) { CODE, NAME, ARGS }, |
Functions | |
int | could_take_from_treasury (int u, int m) |
Could u take m from treasury, assuming side has treasury? | |
int | could_take_from_treasury (int u, Side *side, int m) |
Could u on a given side take m from treasury? | |
int | could_take_directly_from_treasury (int u, int m) |
Could u take m directly from treasury, assuming side has treasury? | |
int | could_take_directly_from_treasury (int u, Side *side, int m) |
Could u on a given side take m directly from treasury? | |
int | could_give_to_treasury (int u, int m) |
Could u give m to treasury, assuming side has treasury? | |
int | could_give_to_treasury (int u, Side *side, int m) |
Could u on a given side give m to treasury? | |
int | could_give_directly_to_treasury (int u, int m) |
Could u give m directly to treasury, assuming side has treasury? | |
int | could_give_directly_to_treasury (int u, Side *side, int m) |
Could u on a given side give m directly to treasury? | |
void | get_materials_availability (Unit *actor, Unit *agent, long *p_mavail, long *p_mavailmax, int flags) |
What are current and max materials availabilities for an actor-agent pair? | |
int | can_meet_materials_requirement (long *p_mreq, long *p_mavail, long *p_mavailmax) |
Is materials requirement satisfied by availabilities? | |
void | consume_materials (Unit *actor, Unit *consumer, int(*getter)(int u, int m), int u3, int mult) |
Consume materials of a given unit with a given consumption getter. | |
void | consume_materials (Unit *actor, Unit *consumer, long *p_mreq) |
Consume materials of a given unit according to given consumption vector. | |
int | has_supply_to_act (Unit *unit) |
Does unit has enough of each material needed to act? | |
int | can_act (Unit *actor, Unit *agent) |
int | has_enough_tooling (Unit *constructor, int u2) |
Does the constructor have enough tooling to construct u2? | |
int | could_toolup_for (int u, int u2) |
Could u toolup for u2? | |
int | could_toolup_for_any (int u) |
Could u toolup for any utype? | |
int | can_toolup_for (Unit *actor, Unit *constructor, int u3) |
Can given actor-constructor pair toolup for given utype? | |
int | could_create (int u, int u2) |
Could u create u2? | |
int | could_create_any (int u) |
Could u create any utype? | |
int | can_create_common (Unit *actor, Unit *creator, int u3, int x, int y, int could, int acpcost_spcl, long *p_mreq_spcl) |
Can given actor-creator pair create given utype? | |
int | could_build (int u, int u2) |
Could u build u2? | |
int | could_build_any (int u) |
Could u build any utype? | |
int | can_build (Unit *actor, Unit *builder, int u3) |
Can given actor-builder pair build on a given utype? | |
int | can_build (Unit *actor, Unit *builder, Unit *buildee, int could, int acpcost_spcl, long *p_mreq_spcl) |
Can given actor-builder pair build on a given unit? | |
int | could_auto_repair (int u, int u2) |
Could u auto-repair u2? | |
int | can_auto_repair (Unit *repairer, Unit *repairee) |
Can given repairer auto-repair given repairee? | |
int | could_repair (int u, int u2) |
Could u explicitly repair u2? | |
int | can_repair (Unit *actor, Unit *repairer, int u3) |
Can given actor-repairer pair explicitly repair given utype? | |
int | can_repair (Unit *actor, Unit *repairer, Unit *repairee) |
Can given repairer explicitly repair given repairee? | |
int | can_change_type_to (int u, int u2, Side *side) |
int | can_change_type_to (Unit *actor, Unit *morpher, int u3) |
Can given unit change into given utype? | |
void | init_actions (void) |
Action Initialization. | |
int | prep_none_action (Unit *unit, Unit *actee) |
Prepare for No Action. | |
int | do_none_action (Unit *unit, Unit *actee) |
Do No Action. | |
int | check_none_action (Unit *unit, Unit *actee) |
Check for No Action. | |
int | prep_produce_action (Unit *unit, Unit *producer, int m, int amount) |
Prepare for Material Production Action. | |
int | do_produce_action (Unit *unit, Unit *producer, int m, int amount) |
Do Material Production Action. | |
int | check_produce_action (Unit *unit, Unit *producer, int m, int amount) |
Check for Material Production Action. | |
int | prep_extract_action (Unit *unit, Unit *extractor, int x, int y, int m, int amount) |
Prepare for Terrain Extraction Action. | |
int | do_extract_action (Unit *unit, Unit *extractor, int x, int y, int m, int amount) |
Do Terrain Material Extraction Action. | |
int | check_extract_action (Unit *unit, Unit *extractor, int x, int y, int m, int amount) |
Check for Terrain Material Estraction Action. | |
int | prep_transfer_action (Unit *unit, Unit *from, int m, int amount, Unit *to) |
Prepare for Material Transfer Action. | |
int | do_transfer_action (Unit *unit, Unit *from, int m, int amount, Unit *to) |
Do Material Transfer Action. | |
int | check_transfer_action (Unit *unit, Unit *from, int m, int amount, Unit *to) |
Check for Material Transfer Action. | |
int | transfer_supply (Unit *from, Unit *to, int m, int amount) |
Transfer Supply. | |
int | prep_develop_action (Unit *unit, Unit *developer, int new_u) |
Prepare for technical Development Action. | |
int | do_develop_action (Unit *unit, Unit *developer, int new_u) |
Do Technical Development Action. | |
int | check_develop_action (Unit *unit, Unit *developer, int new_u) |
Check for Technical Development Action. | |
int | prep_toolup_action (Unit *actor, Unit *constructor, int u3) |
Prepare for Toolup Action. | |
int | do_toolup_action (Unit *actor, Unit *constructor, int u3) |
Do Toolup Action. | |
int | check_toolup_action (Unit *actor, Unit *constructor, int u3) |
Check Toolup Action. | |
int | prep_create_in_action (Unit *unit, Unit *creator, int new_u, Unit *dest) |
Prepare for Create In Unit Action. | |
int | do_create_in_action (Unit *actor, Unit *creator, int u3, Unit *transport) |
Do Create In Unit Action. | |
int | check_create_in_action (Unit *actor, Unit *creator, int uc, Unit *transport) |
Check for Create in Unit Action. | |
int | prep_create_at_action (Unit *unit, Unit *creator, int new_u, int x, int y, int z) |
Prepare for Create Unit at Location. | |
int | do_create_at_action (Unit *actor, Unit *creator, int u3, int x, int y, int z) |
Do Create Unit at Location. | |
int | check_create_at_action (Unit *actor, Unit *creator, int u3, int x, int y, int z) |
Check for Create Unit at Location. | |
int | prep_build_action (Unit *unit, Unit *builder, Unit *newunit) |
Prepare to Build Unit in Unit. | |
int | do_build_action (Unit *actor, Unit *builder, Unit *newunit) |
Do Build Unit in Unit Action. | |
void | garrison_unit (Unit *builder, Unit *newunit) |
Garrison Unit. | |
int | check_build_action (Unit *actor, Unit *builder, Unit *buildee) |
Check for Build Unit in Unit Action. | |
void | grant_occs_on_completion (Unit *unit) |
void | make_unit_complete (Unit *unit) |
Complete Unit. | |
int | prep_repair_action (Unit *actor, Unit *repairer, Unit *repairee) |
Prepare for Unit Repair Action. | |
int | do_repair_action (Unit *acpsrc, Unit *repairer, Unit *repairee) |
Do Repair Unit Action. | |
int | check_repair_action (Unit *actor, Unit *repairer, Unit *repairee) |
Check for Repair Unit Action. | |
int | prep_disband_action (Unit *unit, Unit *disbanded) |
Prepare for Unit Disband Action. | |
int | do_disband_action (Unit *unit, Unit *disbanded) |
Do Unit Disband Action. | |
int | check_disband_action (Unit *unit, Unit *disbanded) |
int | prep_change_type_action (Unit *unit, Unit *unit2, int u3) |
int | do_change_type_action (Unit *unit, Unit *unit2, int u3) |
int | check_change_type_action (Unit *unit, Unit *unit2, int u3) |
Check the 'change-type' action. | |
int | prep_change_side_action (Unit *unit, Unit *unit2, Side *side) |
int | do_change_side_action (Unit *unit, Unit *unit2, Side *side) |
int | check_change_side_action (Unit *unit, Unit *unit2, Side *side) |
int | prep_alter_cell_action (Unit *unit, Unit *unit2, int x, int y, int t) |
int | do_alter_cell_action (Unit *unit, Unit *unit2, int x, int y, int t) |
int | check_alter_cell_action (Unit *unit, Unit *unit2, int x, int y, int t) |
int | prep_add_terrain_action (Unit *unit, Unit *unit2, int x, int y, int dir, int t) |
int | do_add_terrain_action (Unit *unit, Unit *unit2, int x, int y, int dir, int t) |
int | check_add_terrain_action (Unit *unit, Unit *unit2, int x, int y, int dir, int t) |
int | prep_remove_terrain_action (Unit *unit, Unit *unit2, int x, int y, int dir, int t) |
int | do_remove_terrain_action (Unit *unit, Unit *unit2, int x, int y, int dir, int t) |
int | check_remove_terrain_action (Unit *unit, Unit *unit2, int x, int y, int dir, int t) |
int | should_play_movies (void) |
Should action movies be played? | |
int | execute_action (Unit *unit, Action *action) |
int | can_have_enough_acp (Unit *unit, int acp) |
int | type_can_have_enough_acp (int u, int acp) |
int | has_enough_acp (Unit *unit, int acp) |
int | type_max_night_acp_from_any_terrains (int u) |
int | type_max_acp_from_any_occs (int u) |
int | type_max_acp (int u) |
void | use_up_acp (Unit *unit, int acp) |
Make the consumed acp disappear, but not go below the minimum possible. | |
int | construction_possible (int u2) |
int | any_construction_possible (void) |
int | storage_possible (int m) |
int | any_storage_possible (void) |
char * | action_desig (Action *act) |
Variables | |
int | at_turn_start |
ActionDefn | actiondefns [] |
Action function table. | |
int | retreating |
Retreat flag. | |
int | retreating_from = NONUTYPE |
Type of Unit from which a Unit is retreating. | |
char * | actiondesigbuf = NULL |
Action description buffer. | |
Action * | latest_action |
int * | cache__type_max_night_acp_from_any_terrains = NULL |
int * | cache__type_max_acp_from_any_occs = NULL |
int * | cache__type_max_acp = NULL |
The general theory of actions is that interface or AI code calls, for an action foo, the routine prep_foo_action, which just records the action for later execution. The action loop in run_game eventually calls do_foo_action, which first calls check_foo_action to confirm that the action will succeed. If check_foo_action does not find any errors, then the action cannot fail. The main body of do_foo_action then implements the effects of the action. Interfaces may call check_foo_action freely, but should never call do_foo_action directly.
action.def is used to declare the actions as extern int, as well as defining the action default function array, actiondefns. A macro, ACTION_DEF is redefined to use different portions of it's arguments to define the different types of information to this module.
Each action has an acting unit, which is the unit that schedules the action and supplies the ACP to perform the action. Each action also has an "actee", a unit that actually performs the action (extractor, builder, creator, etc). The two units are currently always identical, but the theoretical possibility of splitting the work in this way is supported by two separate unit arguments in all action functions. It is the status, position, capabilities and available supplies of the "actee" that determines if, how and to what extent the action can be performed, but the action is also limited by the ACPs that are available to the acting unit. Note that the "actee" is called so for historical reasons - a better name would be "actor" since it in most cases is the active unit. One exception is the materials transfer code, where the "actee" is the donor (not necessarily active) of the transferred materials. Another example is the disband action where the "actee" is the unit being disbanded. Other parameters may be defined.
|
|
|
|
|
|
|
|
|
|
|
|
|
Can given repairer auto-repair given repairee?
|
|
Can given actor-builder pair build on a given unit?
|
|
Can given actor-builder pair build on a given utype?
|
|
Can given unit change into given utype?
|
|
|
|
Can given actor-creator pair create given utype?
|
|
|
|
Is materials requirement satisfied by availabilities?
|
|
Can given repairer explicitly repair given repairee?
|
|
Can given actor-repairer pair explicitly repair given utype?
|
|
Can given actor-constructor pair toolup for given utype?
|
|
|
|
|
|
Check for Build Unit in Unit Action. Check to see if a Unit can continue to be built.
|
|
|
|
Check the 'change-type' action. Arbiter Function. |
|
Check for Create Unit at Location. Check to see if a may be created at cell(x,y) at altitude z.
|
|
Check for Create in Unit Action. Check to see if it's possible to create a in another Unit.
|
|
Check for Technical Development Action. Check to see is tech development action is possible. Tech development is on a unit basis, as opposed to advances, which may depend on each other.
|
|
|
|
Check for Terrain Material Estraction Action. This checks to see if an extract operation is possible. It verifies:
|
|
Check for No Action. Check to see if no action is possible.
|
|
Check for Material Production Action. Produce materials from Unit. Validate:
|
|
|
|
Check for Repair Unit Action. Check to see if the repair action can be done. Validate:
|
|
Check Toolup Action. Check to see if a toolup action may be performed.
|
|
Check for Material Transfer Action. This routine makes sure that a transfer is possible. It verifies
|
|
|
|
Consume materials of a given unit according to given consumption vector.
|
|
Consume materials of a given unit with a given consumption getter. Takes a provided TableUM getter function, and applies consumption for each relevant material to the given unit or, possibly, side. Optionally takes an utype so be used with the getter instead of the agent's utype. Note that requested amounts can be negative, which will cause a gain for the given unit or side treasury, if possible. |
|
Could u auto-repair u2?
|
|
Could u build u2?
|
|
Could u build any utype?
|
|
Could u create u2?
|
|
Could u create any utype?
|
|
Could u on a given side give m directly to treasury?
|
|
Could u give m directly to treasury, assuming side has treasury?
|
|
Could u on a given side give m to treasury?
|
|
Could u give m to treasury, assuming side has treasury?
|
|
Could u explicitly repair u2?
|
|
Could u on a given side take m directly from treasury?
|
|
Could u take m directly from treasury, assuming side has treasury?
|
|
Could u on a given side take m from treasury?
|
|
Could u take m from treasury, assuming side has treasury?
|
|
Could u toolup for u2?
|
|
Could u toolup for any utype?
|
|
|
|
|
|
Do Build Unit in Unit Action. Build a unit.
|
|
|
|
|
|
Do Create Unit at Location. Create the unit at the given location.
|
|
Do Create In Unit Action. This action creates a "in" another Unit.
|
|
Do Technical Development Action. Develop the tech level needed for building , if not already available.
|
|
Do Unit Disband Action. Disband the unit by:
|
|
Do Terrain Material Extraction Action. Extract material from the cell or other in the cell.
|
|
Do No Action. Perform no action action. :-)
|
|
Do Material Production Action. Produce materials from a unit. The producer unit stores as much material internally as possible, then distributes it ot units around it.
|
|
|
|
Do Repair Unit Action. Use a unit to repair another unit.
|
|
Do Toolup Action. Do the tooup action.
|
|
Do Material Transfer Action. This routine transfers material from one to another. Transfer goes from the to Unit to the from Unit if the quanity transferred is negative. The actual quantity transfered is calculated by transfer_supply. The ACP for the transer is used buy the unit Unit, even if no materis is transfered. Transfers always use 1 ACP.
|
|
|
|
Garrison Unit. This name is somewhat confusing. It uses the uu_hp_to_garrison table to determine if the unit should be removed. It is used to remove a building Unit upon creating a new Unit. An example would be a colonizer/settler/engineer disappearing when a villiage/town/city is built. It is also sometimes used when a unit captures a unit, such as an army capturing a city, and being destroyed in the process of capturing the city.
|
|
What are current and max materials availabilities for an actor-agent pair?
|
|
|
|
|
|
Does the constructor have enough tooling to construct u2?
|
|
Does unit has enough of each material needed to act?
|
|
Action Initialization. Do any action-related initialization. Currently it doesn't do anything. |
|
Complete Unit. Do all the little things to make a fully operational unit.
|
|
|
|
|
|
Prepare to Build Unit in Unit. Sets up build operation.
|
|
|
|
|
|
Prepare for Create Unit at Location. Prepare to create a unit in the open at the given location.
|
|
Prepare for Create In Unit Action. This action creates the (incomplete) unit.
|
|
Prepare for technical Development Action. Setup a Develop action. In order to build a specific unit type, a side may first have to develop the tech level needed for that unit. This is achieved by the develop action.
|
|
Prepare for Unit Disband Action. Set up to do a disband action. The disband action destroys a unit in an "orderly" fashion, and can be undertaken voluntarily.
|
|
Prepare for Terrain Extraction Action. Prepare to extract material from a cell. The unit supplies the ACP for the extraction process and stores the parameters for the extaction action. The extractor is the unit which recieves the material.
|
|
Prepare for No Action. Just a placeholder action, so not much to do here.
|
|
Prepare for Material Production Action. Produce materials from unit. The unit supplies the ACP for the action, and stores the action arguments. The producer stores the available material.
|
|
|
|
Prepare for Unit Repair Action.
|
|
Prepare for Toolup Action. Before a can build another, it may need to take some time to prepare by "tooling up". This is to simulate the amount of time it takes to build the first of a Unit.
|
|
Prepare for Material Transfer Action. This routine sets up a material transfer from one to another. The unit supplies the ACP for the action, and stores the parameters for the action. The from Unit supplies the material to the to Unit.
|
|
Should action movies be played?
|
|
|
|
Transfer Supply. Move supply from one to another. Don't move more than is possible; check both from and to amounts and capacities. This routine will also transfer to the side's treasury if necessary can handle overflow. This is a utility routine.
|
|
|
|
|
|
|
|
|
|
Make the consumed acp disappear, but not go below the minimum possible.
|
|
Action function table. The table of all the action functions declared above. It uses CODE_DEF_ACTION and action.def above to generate an "extern int" declaration for every action (prep, do, and * check). Below it generates a table with 3 entries for each function, a code number (CODe), the name of the function (NAME), and the extended declaration list for the function (ARGS). |
|
Action description buffer. This is used to compose a description of what a Unit is doing. |
|
|
|
|
|
|
|
|
|
|
|
Retreat flag. This is used to indicate that a move is a retreat; for normal movement it will always be false. |
|
Type of Unit from which a Unit is retreating. This is a specific type of Unit that the retreater is running away from. |