Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

actions.c File Reference

Implementations of Xconq actions. More...

#include "conq.h"
#include "kernel.h"
#include "action.def"

Include dependency graph for actions.c:

Include dependency graph

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.

Actionlatest_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

Detailed Description

Implementations of Xconq actions.

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.

Note:
We can't declare all the action functions as static because some of them are in other files, but don't let them be visible to all files.

The DEF_ACTION macro and it's like can't be documented directly with Doxygen, as it doesn't support overlaid macros, or macro substitiution in comments. So where a single definition file is used for several purposes, the documentation has to be manually included each time, which kind of defeats the purpose of having the definions in a single file. One possibility would be to use a pre-processor like m4 to create a set of documentation includes, like action_function.doc to be included. It's probably not worthwile for external function declarations, since they'll be documented where they are defined, but it might be nice for things like enumerations or fixed data structures.

Define Documentation

#define DEF_ACTION NAME,
CODE,
ARGS,
prepfn,
netprepfn,
dofn,
checkfn,
argdecl,
doc   )     { CODE, NAME, ARGS },
 

#define DEF_ACTION name,
code,
args,
prepfn,
netprepfn,
DOFN,
checkfn,
ARGDECL,
doc   )     extern int DOFN ARGDECL;
 


Function Documentation

char* action_desig Action act  ) 
 

int any_construction_possible void   ) 
 

int any_storage_possible void   ) 
 

int can_act Unit actor,
Unit agent
 

Todo:
Eventually assert activeness instead of just returning an error.

int can_auto_repair Unit repairer,
Unit repairee
 

Can given repairer auto-repair given repairee?

Note:
Includes check of hp-recovery mechanism.

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 can_build Unit actor,
Unit builder,
int  u3
 

Can given actor-builder pair build on a given utype?

int can_change_type_to Unit actor,
Unit morpher,
int  u3
 

Can given unit change into given utype?

int can_change_type_to int  u,
int  u2,
Side side
 

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 can_have_enough_acp Unit unit,
int  acp
 

int can_meet_materials_requirement long *  p_mreq,
long *  p_mavail,
long *  p_mavailmax
 

Is materials requirement satisfied by availabilities?

int can_repair Unit actor,
Unit repairer,
Unit repairee
 

Can given repairer explicitly repair given repairee?

int can_repair Unit actor,
Unit repairer,
int  u3
 

Can given actor-repairer pair explicitly repair given utype?

int can_toolup_for Unit actor,
Unit constructor,
int  u3
 

Can given actor-constructor pair toolup for given utype?

int check_add_terrain_action Unit unit,
Unit unit2,
int  x,
int  y,
int  dir,
int  t
 

int check_alter_cell_action Unit unit,
Unit unit2,
int  x,
int  y,
int  t
 

int check_build_action Unit actor,
Unit builder,
Unit buildee
 

Check for Build Unit in Unit Action.

Check to see if a Unit can continue to be built.

See also:
prep_build_action, do_build_action, in_play, uu_acp_to_build, can_have_enough_acp, uu_cp_per_build, uu_tp_to_build, fillsized, dostamce. uu_build_range, completed, uu_occ_can_build, has_enough_acp, um_to_build.
Parameters:
actor is the pointer to the initiating the action.
builder is the pointer to building the new Unit.
buildee is the pointer to being built.

int check_change_side_action Unit unit,
Unit unit2,
Side side
 

int check_change_type_action Unit unit,
Unit unit2,
int  u3
 

Check the 'change-type' action.

Arbiter Function.

int check_create_at_action Unit actor,
Unit creator,
int  u3,
int  x,
int  y,
int  z
 

Check for Create Unit at Location.

Check to see if a may be created at cell(x,y) at altitude z.

See also:
inside_area, type_can_occupy_cell, type_can_occupy_enpty_type, type_can_occupy_cell_without, terrain_at, ut_vanished_on, ut_wrecks_on, type_can_sit_on_conn.
Parameters:
actor is the pointer to the initiating the action.
creator is thepointer to the creating the Unit.
u3 is the type of Unit being created.
x is the location's x co-ordinate.
y is the location's y co-ordinate.
z is the altitude of the new .
Returns:
  • result of can_create_common, if not A_ANY_OK
  • A_ANY_ERROR if
    • the creation location is not in the world,
    • the new Unit can't occupy the desired cell, or the creator can't occupy the new Unit.
    • the Unit vanishes or wrecks in the cell, or can't sit on the connection.
  • A_ANY_OK if it's ok to create the unit.

int check_create_in_action Unit actor,
Unit creator,
int  uc,
Unit transport
 

Check for Create in Unit Action.

Check to see if it's possible to create a in another Unit.

See also:
prep_create_in_action, do_create_in_action, in_play, u_advanced, unit_at, type_can_occupy.
Returns:
  • the return value from can_create_common, if it is not A_ANY_OK;
  • A_ANY_ERROR if
    • destination is not in play, or
    • the new cannot be created in the destination Unit;
  • A_ANY_OK otherwise.

int check_develop_action Unit unit,
Unit developer,
int  new_u
 

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.

Note:
Technical development is different from advances and advanced units.
  • Validate acted on.
    • unit must be in play,
    • developer must be in play, and
    • newunt must be a Unit type.
  • Check to see if the side is an independent side, and independents are allowed to develop.
  • the developer must be able to develop the new unit type
  • unit must be able to have enough acp for the developer to develop the new unit type
  • the side's tech level must not be at the side's maximum value already
  • the unit must have enough acp for the developer to develop the new unit type
  • the developer must have all materials needed to develop the new unit type

See also:
prep_develop_action, do_develop_action, in_play, is_unit_type, g_indepside_can_develop, could_develop, can_have_enough_acp, uu_acp_to_develop, u_tech_max, for_all_material_types.

Parameters:
unit is the pointer to the initiating the action.
developer is the pointer to the which does the development
new_u is the new Unit type to be developed.
Returns:
  • A_ANY_ERROR if
    • unit is not in play,
    • developer is not in play,
    • new_u in not a valid Unit type,
    • the side is independent, and not allowed technical development, or
    • the side has reached it's maximum tech level.
  • A_ANY_CANNOT_DO if
    • the developer cannot develop the new unit type, or
    • the unit can never have enough ACP to develop the new Unit type.
  • A_ANY_NO_ACP if the unit does not currently have enough acp to develop the new unit type.
  • A_ANY_OK if the do_develop_action can be done.

int check_disband_action Unit unit,
Unit disbanded
 

int check_extract_action Unit unit,
Unit extractor,
int  x,
int  y,
int  m,
int  amount
 

Check for Terrain Material Estraction Action.

This checks to see if an extract operation is possible. It verifies:

  • the unit is in play,
  • the extractor is in play,
  • the material type is valid,
  • the unit is capable of extracting material (no negative ACP balance)
  • the unit has enough available ACP,
  • the extractor has any supplies needed for extraction. It then checks to see if material can be produced from the cell, else from any other independent also in the cell.

See also:
prep_extract_action, do_extract_action, in_play, is_material_type, um_acp_to_extract, can_have_enough_acp, has_enough_acp, for_all_material_types, um_to_extract, any_cell_materials_defined, cell_material_defined, material_at, for_all_stack, indep.

Parameters:
unit is the pointer to the initiating the action.
extractor is the pointer to the on which the action is preformed,
x is the x co-ordinate of the cell,
y is the y co-ordinate of the cell,
m is the material to be produced,
amount is the quanity to be produced.
Returns:
  • A_ANY_ERROR if
    • the unit is not in play,
    • the extractor is not in play,
    • the material type is not valid.
  • A_ANY_CANNOT_DO if
    • the ACP is negative,
    • the unit can never have enough ACP.
  • A_ANY_NO_ACP if the unit doesn't have enough ACP.
  • A_ANY_NO_MATERIAL if the cell doesn't have the material.
  • A_ANY_OK if the material is available.
  • A_EXTRACT_NO_SOURCE if no material could be extracted.

int check_none_action Unit unit,
Unit actee
 

Check for No Action.

Check to see if no action is possible.

See also:
prep_none_action, do_none_action.
Parameters:
unit is the pointer to the initiating the action.
actee is the pointer to the which performs the action
Returns:
A_ANY_DONE always.

int check_produce_action Unit unit,
Unit producer,
int  m,
int  amount
 

Check for Material Production Action.

Produce materials from Unit. Validate:

  • unit is in play
  • producer is in play.
  • material type is valid.
  • producer needs at least 1 acp to produce material
  • unit must be able to have enough acp to produce at some point in the future.
  • unit has enough acp to produce the material
  • all needed supplies to produce the material are available.
See also:
prep_produce_action, do_produce_action, in_play, is_material_type, um_acp_to_produce, can_have_enough_acp, um_material_per_production, has_enough_acp, for_all_material_types, um_to_produce.

Parameters:
unit is the pointer to the initiating the action.
producer is the pointer to the that extracts the material.
m is material type?
amount is amount of material produced?
Returns:
  • A_ANY_ERROR if
    • unit is not in play
    • producer is not in play
    • the material type is unknown
  • A_ANY_CANNOT_DO if
    • ACP of unit is less than 1
    • if the unit cannot ever have enough ACP for the extraction
    • if the material production per turn is less than 1
  • A_ANY_NO_ACP if the unit doesn't have enough ACP
  • A_ANY_NO_MATERIAL if any required materials are not available.
  • A_ANY_OK if the unit can produce the material.

int check_remove_terrain_action Unit unit,
Unit unit2,
int  x,
int  y,
int  dir,
int  t
 

int check_repair_action Unit actor,
Unit repairer,
Unit repairee
 

Check for Repair Unit Action.

Check to see if the repair action can be done. Validate:

  • All units are in play.
  • The repairng unit can repair the repaired unit.
  • Sufficient materials are on hand to do the repair.
  • the unit has enought ACP to do the repair this turn.
    See also:
    in_play, uu_acp_to_repair, can_have_enough_acp, uu_hp_to_repair, for_all_material_types, um_to_repair, um_consumption_per_repair, has_enough_acp.

int check_toolup_action Unit actor,
Unit constructor,
int  u3
 

Check Toolup Action.

Check to see if a toolup action may be performed.

See also:
prep_toolup_action, do_toolup_action. in_play, is_unit_type, uu_acp_to_toolup, can_have_enough_acp, uu_tp_max, has_enough_acp.
Parameters:
actor is the pointer to the initiating the action.
constructor is pointer to which will do the tool up for the new unit.
u3 is the type of Unit for which to toolup.
Returns:
  • A_ANY_ERROR if
    • unit is not in play,
    • builder is not in play,
    • new_u is not a Unit type, or
    • tooling points equal or exceed the number needed to toolup for the new Unit type.
  • A_ANY_CANNOT_DO if
    • the builder cannot toolup for the required Unit type (acp less than 1), or
    • the unit can never have enough acp to produce the Unit type.
  • A_ANY_NO_ACP if the unit doesn't have enough acp to toolup this turn.
  • A_ANY_OK if the toolup is possible.

int check_transfer_action Unit unit,
Unit from,
int  m,
int  amount,
Unit to
 

Check for Material Transfer Action.

This routine makes sure that a transfer is possible. It verifies

  • that unit, to, and from are in play.
  • that the material tor transfer is a valid material,
  • that the quantify of material to transfer is non-zero.
  • that the from can unload material (ACP 1 or more),
  • that the to may load material(ACP 1 or more),
  • that the unit can ever have enough ACP to transfer the material,
  • that the suppling the material has the supplies needed to transfer the material,
  • that the receivng the material has the storage for the transferred material. and
  • that the unit has enough ACP to transfer the material.

See also:
prep_transfer_action, do_transfer_action, in_play, is_material_type, um_acp_to_unload, um_acp_to_load, can_have_enough_acp, um_storage_x, has_enough_acp.

Parameters:
unit is the pointer to the initiating the action.
from is the pointer to the supplying the material (if amount is positive).
m is the material being transferred.
amount is the quanity of material being transferred.
to is the pointer to the receiving the transfer (if amount is positive).
Returns:
  • A_ANY_ERROR if
    • the unit is not in play,
    • the to is not in play,
    • the material type is invalid,
    • the quanity of material to produce is zero (negative is ok),
    • the from is not in play,
    • the appropriate (depending on quantity positive or negative) does not have enough supplies of other materials on hand, or
    • the appropriate does not have enough storage capacity.
  • A_ANY_CANNOT_DO if
    • the from cannot unload material (ACP to unload less than 1),
    • the to has a NULL action pointer or cannot load material (ACP to load less than 1), or
    • the unit can never have enought ACP to do the transfer.
  • A_ANY_NO_ACP if the unit doesn't have enought ACP.
  • A_ANY_DONE if at least one unit of material can be transferred.

int construction_possible int  u2  ) 
 

void consume_materials Unit actor,
Unit consumer,
long *  p_mreq
 

Consume materials of a given unit according to given consumption vector.

void consume_materials Unit actor,
Unit consumer,
int(*  getter)(int u, int m),
int  u3 = NONUTYPE,
int  mult = 1
 

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.

int could_auto_repair int  u,
int  u2
 

Could u auto-repair u2?

Note:
Does not check hp-recovery mechanism.

int could_build int  u,
int  u2
 

Could u build u2?

int could_build_any int  u  ) 
 

Could u build any utype?

int could_create int  u,
int  u2
 

Could u create u2?

int could_create_any int  u  ) 
 

Could u create any utype?

int could_give_directly_to_treasury int  u,
Side side,
int  m
 

Could u on a given side give m directly 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_to_treasury int  u,
Side side,
int  m
 

Could u on a given side give m to treasury?

int could_give_to_treasury int  u,
int  m
 

Could u give m to treasury, assuming side has treasury?

int could_repair int  u,
int  u2
 

Could u explicitly repair u2?

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_take_directly_from_treasury int  u,
int  m
 

Could u take m directly 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_from_treasury int  u,
int  m
 

Could u take m from treasury, assuming side has treasury?

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 do_add_terrain_action Unit unit,
Unit unit2,
int  x,
int  y,
int  dir,
int  t
 

int do_alter_cell_action Unit unit,
Unit unit2,
int  x,
int  y,
int  t
 

int do_build_action Unit actor,
Unit builder,
Unit newunit
 

Do Build Unit in Unit Action.

Build a unit.

  • for all materials
    • reduce the supply of the building by the proportional amount based on construction points.
  • increase constrution points for the unit for this build
  • if completed,
    • get rid of building , if neccessary
    • make complete,
    • update Unit display,
    • use up ACP.
  • else

int do_change_side_action Unit unit,
Unit unit2,
Side side
 

int do_change_type_action Unit unit,
Unit unit2,
int  u3
 

int do_create_at_action Unit actor,
Unit creator,
int  u3,
int  x,
int  y,
int  z
 

Do Create Unit at Location.

Create the unit at the given location.

  • Try to allocate a new .
  • If allocated,
    • Set the default properties of the .
    • If the can reuse creation points, adjust the new unit's and creator's creation points.
    • If the new unit can occupy the cell
      • enter the cell with the new .
    • else if there is space in cell and the creating can transport the new unit
      • make the creating leave the cell
      • make the new enter the cell
      • make the creator eter the new unit as an occupant.
    • else there was an error.
    • if the new is completed on creation
      • destroy creating , if neccessary. This is for things like creatinn a city from a colonizer that is "used up" in the process of creating the new Unit.
      • complete the new .
    • else record the creation event.
    • if the creating unit is still alive (not destroyed by creating the new unit)
      • record any score gain from creating unit.
      • use supplies for creation (local and/or treasury).
    • use up creation ACP from the unit.
    • else ran out of memory
    See also:
    create_unit, set_created_unit_props, uu_builder_can_reuse_cp, mn, u_cp, can_occupy_cell, enter_cell, can_occupy_cell_without, can_occupy, leave_cell, enter_transport, run_error, completed, garrison_unit, make_unit_complete, recod_event, add_side_to_set, side_number, alive, count_gain, for_all_material_types, um_consumption_on_creation, side_has_treasury, run_warning, use_up_acp.
    Parameters:
    actor is the pointer to the initiating the action.
    creator is a pointer to the doing the creation.
    u3 is the Unit type to be created.
    x is the creation location's x co-ordiate.
    y is the creation location's y co-ordinate.
    z is the creation location's altitude.
    Returns:
    • A_ANY_ERROR if no memory for creation.
    • A_ANY_OK if unit created.

int do_create_in_action Unit actor,
Unit creator,
int  u3,
Unit transport
 

Do Create In Unit Action.

This action creates a "in" another Unit.

  • If the Unit being created is advanced
    • Figure out if the destination unit is the creator's transport
    • If the destination unit is the creator's transport
      • increment destination unit's size by 1.
      • garrison (destroy) the creator
      • update the Unit display
      • use up ACPs
      • return
  • (If we fell through above code) create the new .
  • If the pointer to the new is not NULL
    • Fill in new properties.
    • if creation points can be passed to the new
      • stuff new with as much as it can hold or is avalible,
      • move balances to the correct places.
    • Put the new in the transport (dest)
    • If created complete
      • garrison in transport
      • make complete
    • Else
      • record the creation event.
    • If creator is alive
      • count the gain in (scorekeeping?)
      • for all materials (supplies)
        • calculate the amount of material consumed in createing new
        • if consumption greater than supply
          • figure out amount lacking
          • reduce supply by amount consumed
          • if lacking supply from unit2
            • remove need amount from treasury.
          • if not in treasury
            • generate run time warning (but still return good status).
    • use ACP needed to create new .
    • return
  • else return error (no memory for new ?)

Todo:
Add crosscheck to make sure that an advanced unit does not exceed it's maximum size.
See also:
prep_create_in_action, check_create_in_action, u_advanced, update_unit_display, garrison_unit, use_up_acp, create_unit, set_created_unit_props, uu_builder_can_reuse_cp, enter_transport, make_unit_complete, completed, record_event, add_sid_to_set, alive, count_gain, for_all_material_types, um_consumption_on_creation side_has_treasury, um_takes_from_treasury, run_warning, use_up_acp, uu_acp_to_create.
Parameters:
unit is the pointer to the initiating the action.
creator is pointer to performing the creation.
new_u is the new Unit type.
dest is the to create the new Unit in.
Returns:
  • A_ANY_ERROR if the new could not be created.
  • A_ANY_DONE otherwise.

int do_develop_action Unit unit,
Unit developer,
int  new_u
 

Do Technical Development Action.

Develop the tech level needed for building , if not already available.

  1. calculate contribution to tech by the developer . Use the value of uu_tech_per_develop divided by 100, plus a random value of zero or one.
  2. Caclulate limit on tech change for the side
  3. If tech change exceeds limit, reset to limit
  4. If tech level changes,
    • notify side of tech change.
    • update vector of buildable Units.
  5. Adjust the tech levels of related Units
  6. Uuse up the ACP of the .

Note:
Technical development is different from advances and advanced units.
See also:
prep_develop_action, prob_fraction, uu_tech_per_develop, u_tech_per_turn_max, update_canbuild_vector, adjust_tech_crossover, use_up_acp, uu_acp_to_develop.

Parameters:
unit is the pointer to the initiating the action.
developer is the pointer to the acted upon.
new_u is the Unit type of the increasing tech Unit.
Returns:
A_ANY_DONE.

int do_disband_action Unit unit,
Unit disbanded
 

Do Unit Disband Action.

Disband the unit by:

  • distributing as much of it's supplies as possble,
  • if it has more hit points than needed to disband, recover as much of it's disbanding materials as possible,
  • kill the unit, and
  • use it's ACP.
    See also:
    for_all_material_types, um_supply_per_disband, distribute_material. hp_per_disband, for_all_material_types, um_recycleable, distribute_material, kill_unit, use_up_acp, u_acp_to_disband.
    Parameters:
    unit is a pointer to the initiating the action.
    disbanded is a pointer to the unit being disbanded.
    Returns:
    A_ANY_OK always.

int do_extract_action Unit unit,
Unit extractor,
int  x,
int  y,
int  m,
int  amount
 

Do Terrain Material Extraction Action.

Extract material from the cell or other in the cell.

  • Calculate material production.
    • if cell produces material and has at least amount units of material
      • reduce materials at cell by amount.
      • if remaining amount is zero and the probability of changing on exhaustion is met, and the terrain on exhaustion has a value, change the terrain.
    • else try to supply from in cell.
  • clip to amount requested.
  • distribute excess to other .
  • reduce ACP of the unit .

See also:
prep_extract_action, check_extract_action, any_cell_materials_defined, cell_material_defined, material_at, set_material_at, terrain_at, probabability, tm_change_on_exhaust, tm_exhaust_type, change_terrain_type, for_all_stack, um_storage_x, distribute_material, use_up_acp, um_acp_to_extract.

Parameters:
unit is the pointer to the initiating the action.
extractor is the pointer to the extracting the material.
x is the cell x location.
y is the cell y location.
m is the material needed.
amount is the quanity to produce.
Returns:
A_ANY_DONE.

int do_none_action Unit unit,
Unit actee
 

Do No Action.

Perform no action action. :-)

See also:
prep_none_action, check_none_action.
Parameters:
unit is the pointer to the initiating the action.
actee is the pointer to the which performs the action.
Returns:
A_ANY_DONE always.

int do_produce_action Unit unit,
Unit producer,
int  m,
int  amount
 

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.

  • Sets the production amount to the quantity asked for, or the maximum that can be produced, whichever is less.
  • Clips the amount stored to the storeage maximum.
  • If there is an excess amount, passes it around, if possible.
  • Uses up ACP for production.

See also:
prep_produce_action, check_produce_action, um_material_per_production, um_storate_x, distribute_material, use_up_acp, um_acp_to_produce.

Parameters:
unit is the pointer to the initiating the action.
producer is the pointer to the which extracts the material.
m is the material type.
amount is the amount of material to produce.
Returns:
A_ANY_DONE always.

int do_remove_terrain_action Unit unit,
Unit unit2,
int  x,
int  y,
int  dir,
int  t
 

int do_repair_action Unit acpsrc,
Unit repairer,
Unit repairee
 

Do Repair Unit Action.

Use a unit to repair another unit.

  • Calculate amount of hitpoints that can be repaired.
  • Adjust the repaired unit's hitpoints.
  • Use up any materials required.
  • Use up any ACP needed.
    See also:
    uu_repair, add_to_unit_hp, prob_fraction, for_all_material_types, um_comsumption_per_repair, use_up_acp, uu_acp_to_repair.
    Returns:
    A_ANY_DONE always.

int do_toolup_action Unit actor,
Unit constructor,
int  u3
 

Do Toolup Action.

Do the tooup action.

  • If builder tooling pointer is NULL, initialize tooling for it.
  • Get current tooling points (tp), add in the builder tooling points, and clip to the max tooling points for creating the new Unit type.
  • If the number of tooling points changes (can go negative?), notify the side.
  • Adjust the tooling on all other Units, via a crossover array.
  • update Unit display for the side.
  • use up ACP for the unit

See also:
prep_toolup_action, check_tooup_action, init_unit_tooling, uu_tp_per_toolup, uu_tp_max, notify_tp, adjust_tooling_crossover, update_unit_display, use_up_acp, uu_acp_to_toolup.
Parameters:
actor is the pointer to the initiating the action.
constructor is pointer to the which is building the New unit.
u3 is the Unit type for which to tool up.
Returns:
A_ANY_DONE always.

int do_transfer_action Unit unit,
Unit from,
int  m,
int  amount,
Unit to
 

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.

Todo:
Add return code specifying that only a partial amount of material was transferred.
See also:
prep_transfer_action, check_transfer_action, transfer_supply.

Parameters:
unit is the pointer to the initiating the action.
from is the pointer to the supplying the material (for positive transfers).
m is the material being transferred.
amount is the quanity of material being transferred.
to is the pointer to the receiving the transfer (for positive transfers).
Returns:
  • A_ANY_ERROR if no material was transferred.
  • A_ANY_DONE if at least one unit of material was transferred.

int execute_action Unit unit,
Action action
 

void garrison_unit Unit builder,
Unit newunit
 

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.

  • If the hit points to create/capture (hp_to_garrison) is greater than the remaining hit points of the building
    • remove the new from the cell,
    • if the new is being transported by the building/capturing Unit
      • force the new out of the building/capturing Unit.
      • if the there is a transport availble (not currently implemented)
        • put the new in the transport
      • else
        • put the new in the cell.
    • if the new is being transported, but not by the building/capturing Unit
      • set the alternate transport local variable to the transporting .
    • for all occupants of the building/capturing
      • if the occupant of the building can occupy the new Unit
        • remove the occupant from the new .
        • update the Unit display.
        • add the occupant to the new .
      • else if the alternate transport can hold the occupant
        • remove the ocupant from the building/capuring .
        • update the Unit display.
        • add the occupant to the alternate transport.
      • else if the occupant can enter the cell
        • remove the occupant from the building/capturing .
        • update the Unit display.
        • add the occupant to the cell.
      • By default, leave the occupant in the building/capturing to be destroyed with the building/capturing Unit.
    • Set the temporary event data 1 to the id of the new .
    • Kill the building/capturing Unit.
  • else reduce the building/capturing hp and hp2 by the hp to garrison amount.
    Note:
    if this occurs before damage is calculated, hp and hp2 may be different.
    Todo:
    Add code to handle the garrison being put in a transport?

    Add code to handle sub-occupants of doomed occupants?

    Add code to post event for garrisoning damage?

See also:
uu_hp_to_garrison, leave_cell, leave_trasnport, enter_transport, can_occupy, update_unit_display, kill_unit.
Parameters:
builder is a pointer to the building/capturing the unit.
newunit is a pointer to the being built/captured.

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?

void grant_occs_on_completion Unit unit  ) 
 

int has_enough_acp Unit unit,
int  acp
 

int has_enough_tooling Unit constructor,
int  u2
 

Does the constructor have enough tooling to construct u2?

int has_supply_to_act Unit unit  ) 
 

Does unit has enough of each material needed to act?

void init_actions void   ) 
 

Action Initialization.

Do any action-related initialization. Currently it doesn't do anything.

void make_unit_complete Unit unit  ) 
 

Complete Unit.

Do all the little things to make a fully operational unit.

  • if a unit has multiple parts ( fleet or army, for example), it is not created at full size, but at a size of 1, so construction points and hit points are set appropriately.
  • Give the unit a name.
  • set the view coverage area of the unit.
  • if unit creation cuases a change in control of the cell, remove enemy units.
  • handle material supplied, created, and/or shared for created unit.
  • initialize action state.

See also:
max, u_cp, u_hp, make_up_unit_name, cover_area, Kick_out_enemy_users, for_all_material_types, um_completed_supply, um_storage_x, try_sharing, init_unit_actorstate, init_unit_plan, set_unit_acp_for_turn, make_unit_vector, clear_unit_vector, add_unit_to_vector, for_all_sides, trusted_side, add_side_to_set, record_event, side_number, see_all_cell, printf
Parameters:
unit is the unit to be completed.

int prep_add_terrain_action Unit unit,
Unit unit2,
int  x,
int  y,
int  dir,
int  t
 

int prep_alter_cell_action Unit unit,
Unit unit2,
int  x,
int  y,
int  t
 

int prep_build_action Unit unit,
Unit builder,
Unit newunit
 

Prepare to Build Unit in Unit.

Sets up build operation.

Bug:
Shouldn't newunit be checked for NULL as well? If it is NULL, then newunit->id will probably not work as intended.
Parameters:
unit is the initiating the action.
builder is the building the new Unit.
newunit is the new Unit to build.
Returns:
  • FALSE if
    • unit pointer to unit is NULL,
    • pointer to unit action is NULL, or
    • builder pointer to actee is NULL;
  • TRUE otherwise.

int prep_change_side_action Unit unit,
Unit unit2,
Side side
 

int prep_change_type_action Unit unit,
Unit unit2,
int  u3
 

int prep_create_at_action Unit unit,
Unit creator,
int  new_u,
int  x,
int  y,
int  z
 

Prepare for Create Unit at Location.

Prepare to create a unit in the open at the given location.

Parameters:
unit is the pointer to the initiating the action.
creator is a pointer to the creating the new Unit.
new_u is the Unit type of the unit being created.
x is the cell x co-ordinate.
y is the cell y co-ordinate.
z is the altitude of the unit.
Returns:
  • TRUE if action is queued.
  • FALSE if
    • Acting pointer is NULL,
    • Acting action pointer is NULL, or
    • Creating is NULL;

int prep_create_in_action Unit unit,
Unit creator,
int  new_u,
Unit dest
 

Prepare for Create In Unit Action.

This action creates the (incomplete) unit.

See also:
do_create_in_action, check_create_in_action.
Parameters:
unit is the pointer to the initiating the action.
creator is the pointer to the which creates the new Unit.
new_u the the type of to create.
dest is the pointer to the in which to create the new Unit.
Returns:
  • TRUE if action is queued.
  • FALSE if
    • the unit pointer is NULL,
    • the unit action pointer is NULL,
    • the creator pointer is NULL, or
    • the dest pointer is NULL.

int prep_develop_action Unit unit,
Unit developer,
int  new_u
 

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.

Note:
Technical development is different from advances and advanced units.
See also:
do_devop_action, do_check_action.
Parameters:
unit is the pointer to the initiating the action.
developer is the pointer to the doing the development.
new_u is the new Unit type being developed.
Returns:
  • TRUE action is queed.
  • FALSE if
    • unit is null pointer,
    • unit action is a null pointer, or
    • developer is null pointer.

int prep_disband_action Unit unit,
Unit disbanded
 

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.

Parameters:
unit is a pointer to the initiating the action.
disbanded is a pointer to the unit being disbanded.
Returns:
  • true if the action is queued;
  • false if
    • unit pointer is NULL,
    • the unit action pointer is NULL, or
    • the disbanded pointer is NULL.

int prep_extract_action Unit unit,
Unit extractor,
int  x,
int  y,
int  m,
int  amount
 

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.

See also:
do_extract_action, check_extract_action.
Parameters:
unit is the pointer to the initiating the action.
extractor is the pointer to the doing the extraction.
x is the x co-ordinate of the cell.
y is the y co-ordinate of the cell.
m is the material to extract from the cell.
amount is the quantify of material to extract from the cell.
Returns:
  • true action is queed. -false if
    • unit pointer is NULL,
    • unit action pointer is NULL, or
    • extractor pointer is NULL

int prep_none_action Unit unit,
Unit actee
 

Prepare for No Action.

Just a placeholder action, so not much to do here.

See also:
do_none_action, check_none_action
Parameters:
unit is the pointer to the initiating action.
actee is the pointer to the which performs the action.
Returns:
  • TRUE if action is queed.
  • FALSE if
    • pointer to unit is NULL,
    • action pointer is NULL, or
    • pointer to actee is NULL

int prep_produce_action Unit unit,
Unit producer,
int  m,
int  amount
 

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.

  • Sets the next action type to ACTION_PRODUCE.
  • Sets the type and amount of production.
  • Set producer to the actee. Fails if either of the pointers to is NULL, or tha ction is NULL.

See also:
do_produce_action, check_produce_action.
Parameters:
unit is the pointer to the initiating the action.
producer is the pointer to the extracting the material.
m is material type.
amount is amount of material to produce.
Returns:
  • TRUE if action is queed.
  • FALSE if
    • unit pointer is NULL,
    • unit action pointer is NULL, or
    • producer pointer is NULL.

int prep_remove_terrain_action Unit unit,
Unit unit2,
int  x,
int  y,
int  dir,
int  t
 

int prep_repair_action Unit actor,
Unit repairer,
Unit repairee
 

Prepare for Unit Repair Action.

int prep_toolup_action Unit actor,
Unit constructor,
int  u3
 

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.

See also:
do_toolup_action, check_toolup_action.
Parameters:
unit is the pointer to the initiating the action.
constructor is a pointer to the which builds the new Unit.
u3 is the type of Unit being built.
Returns:
  • TRUE if action is successfully queued.

int prep_transfer_action Unit unit,
Unit from,
int  m,
int  amount,
Unit to
 

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.

See also:
do_transfer_action, check_transfer_action.
Parameters:
unit is the pointer to the initiating the action.
from is the the materisl comes from.
m is the material being transferred.
amount is the quanity of material being transferred.
to is the receiving the transfer.
Returns:
  • TRUE if action is queed.
  • FALSE if
    • unit pointer is NULL,
    • unit action pointer is NULL,
    • from pointer is NULL, or
    • to pointer is NULL.

int should_play_movies void   ) 
 

Should action movies be played?

Note:
Stupid hack.

int storage_possible int  m  ) 
 

int transfer_supply Unit from,
Unit to,
int  m,
int  amount
 

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.

  • Calculate the min amount to transfer based on the available supply and the maximum that can be loaded in the to .
  • if there is a treasury for the material, and the receiving can transfer material to the treasury, then transfer any excess production from the from to the treasure
  • reduce the material supply of the from ,
  • increase the material supply of the to .
  • update to and from supply display for the sides involved.
  • if the treasury was modified, update the treasury supply display.
  • print debug message, if it's enabled.

See also:
do_transfer_material, um_unload_max, um_load_max, UM_storage_x, side_has_treasury, um_gives_to_treasury, update_unit_display, update_side_display.

Parameters:
from is the pointer to the supplying the material.
to is the pointer to the receiving the material.
m is the material type to transfer.
amount is the amount of material to transfer.
Returns:
the amount to transfer.

int type_can_have_enough_acp int  u,
int  acp
 

int type_max_acp int  u  ) 
 

int type_max_acp_from_any_occs int  u  ) 
 

int type_max_night_acp_from_any_terrains int  u  ) 
 

void use_up_acp Unit unit,
int  acp
 

Make the consumed acp disappear, but not go below the minimum possible.

Note:
u_free_acp does not need to be explicitly considered here.


Variable Documentation

ActionDefn actiondefns[]
 

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

char* actiondesigbuf = NULL
 

Action description buffer.

This is used to compose a description of what a Unit is doing.

int at_turn_start
 

int* cache__type_max_acp = NULL
 

int* cache__type_max_acp_from_any_occs = NULL
 

int* cache__type_max_night_acp_from_any_terrains = NULL
 

Action* latest_action
 

int retreating
 

Retreat flag.

This is used to indicate that a move is a retreat; for normal movement it will always be false.

int retreating_from = NONUTYPE
 

Type of Unit from which a Unit is retreating.

This is a specific type of Unit that the retreater is running away from.


Generated on Sat Sep 17 10:28:54 2005 for XconqKernel by doxygen 1.3.6