$treeview $search $mathjax
Stratagus  2.2.6
$projectbrief
$projectbrief
$searchbox
-->
         _________ __                 __
        /   _____//  |_____________ _/  |______     ____  __ __  ______
        \_____  \\   __\_  __ \__  \\   __\__  \   / ___\|  |  \/  ___/
        /        \|  |  |  | \// __ \|  |  / __ \_/ /_/  >  |  /\___ \
       /_______  /|__|  |__|  (____  /__| (____  /\___  /|____//____  >
               \/                  \/          \//_____/            \/
    ______________________                           ______________________
                          T H E   W A R   B E G I N S
           Stratagus - A free fantasy real time strategy game engine

src/include/actions.h File Reference

#include "unit_cache.h"
#include "vec2i.h"

Go to the source code of this file.


actions.h - The actions headerfile.

enum  _diplomacy_ { DiplomacyAllied, DiplomacyNeutral, DiplomacyEnemy, DiplomacyCrazy }
unsigned SyncHash
void CommandQuit (int player)
 Hash calculated to find sync failures.
void CommandStopUnit (CUnit &unit)
 Prepare command stop.
void CommandStandGround (CUnit &unit, int flush)
 Prepare command stand ground.
void CommandFollow (CUnit &unit, CUnit &dest, int flush)
 Prepare command follow.
void CommandMove (CUnit &unit, const Vec2i &pos, int flush)
 Prepare command move.
void CommandRepair (CUnit &unit, const Vec2i &pos, CUnit *dest, int flush)
 Prepare command repair.
void CommandAutoRepair (CUnit &unit, int on)
 Send auto repair command.
void CommandAttack (CUnit &unit, const Vec2i &pos, CUnit *dest, int flush)
 Prepare command attack.
void CommandAttackGround (CUnit &unit, const Vec2i &pos, int flush)
 Prepare command attack ground.
void CommandPatrolUnit (CUnit &unit, const Vec2i &pos, int flush)
 Prepare command patrol.
void CommandBoard (CUnit &unit, CUnit &dest, int flush)
 Prepare command board.
void CommandUnload (CUnit &unit, const Vec2i &pos, CUnit *what, int flush)
 Prepare command unload.
void CommandBuildBuilding (CUnit &unit, const Vec2i &pos, CUnitType &, int flush)
 Prepare command build.
void CommandDismiss (CUnit &unit)
 Prepare command dismiss.
void CommandResourceLoc (CUnit &unit, const Vec2i &pos, int flush)
 Prepare command resource location.
void CommandResource (CUnit &unit, CUnit &dest, int flush)
 Prepare command resource.
void CommandReturnGoods (CUnit &unit, CUnit *goal, int flush)
 Prepare command return.
void CommandTrainUnit (CUnit &unit, CUnitType &what, int flush)
 Prepare command train.
void CommandCancelTraining (CUnit &unit, int slot, const CUnitType *type)
 Prepare command cancel training.
void CommandUpgradeTo (CUnit &unit, CUnitType &what, int flush)
 Prepare command upgrade to.
void CommandTransformIntoType (CUnit &unit, CUnitType &type)
 immediate transforming into type.
void CommandCancelUpgradeTo (CUnit &unit)
 Prepare command cancel upgrade to.
void CommandResearch (CUnit &unit, CUpgrade *what, int flush)
 Prepare command research.
void CommandCancelResearch (CUnit &unit)
 Prepare command cancel research.
void CommandSpellCast (CUnit &unit, const Vec2i &pos, CUnit *dest, SpellType *spell, int flush)
 Prepare command spellcast.
void CommandAutoSpellCast (CUnit &unit, int spellid, int on)
 Prepare command auto spellcast.
void CommandDiplomacy (int player, int state, int opponent)
 Prepare diplomacy command.
void CommandSetResource (int player, int resource, int value)
 Prepare set resources command.
void CommandSharedVision (int player, bool state, int opponent)
 Prepare shared vision command.
void CommandMoveOrder (CUnit &unit, int src, int dst)
 Send any command.
void DropResource (CUnit &unit)
void ResourceGiveUp (CUnit &unit)
int GetNumWaitingWorkers (const CUnit &mine)
void AutoAttack (CUnit &unit, CUnitCache &targets, bool stand_ground)
void UnHideUnit (CUnit &unit)
void ActionStillGeneric (CUnit &unit, bool stand_ground)
 Generic still action.
void HandleActionStill (CUnit &unit)
 Handle command still.
void HandleActionStandGround (CUnit &unit)
 Handle command stand ground.
void HandleActionFollow (CUnit &unit)
 Handle command follow.
int DoActionMove (CUnit &unit)
 Generic move action.
void HandleActionMove (CUnit &unit)
 Handle command move.
void HandleActionRepair (CUnit &unit)
 Handle command repair.
void HandleActionPatrol (CUnit &unit)
 Handle command patrol.
void AnimateActionAttack (CUnit &unit)
 Show attack animation.
void HandleActionAttack (CUnit &unit)
 Handle command attack.
void HandleActionBoard (CUnit &unit)
 Handle command board.
void HandleActionUnload (CUnit &unit)
 Handle command unload.
void HandleActionResource (CUnit &unit)
 Handle command resource.
void HandleActionReturnGoods (CUnit &unit)
 Handle command return.
void HandleActionDie (CUnit &unit)
 Handle command die.
void HandleActionBuild (CUnit &unit)
 Handle command build.
void HandleActionBuilt (CUnit &unit)
 Handle command built.
void HandleActionTrain (CUnit &unit)
 Handle command train.
void HandleActionUpgradeTo (CUnit &unit)
 Handle command upgrade to.
void HandleActionTransformInto (CUnit &unit)
 Handle command transform into.
void HandleActionUpgrade (CUnit &unit)
 Handle command upgrade.
void HandleActionResearch (CUnit &unit)
 Handle command research.
void HandleActionSpellCast (CUnit &unit)
 Handle command spellcast.
int UnitShowAnimationScaled (CUnit &unit, const CAnimation *anim, int scale)
 Handle the animation of a unit.
int UnitShowAnimation (CUnit &unit, const CAnimation *anim)
 Handle the animation of a unit.
void UnitActions ()
 Handle the actions of all units each game cycle.

Enumeration Type Documentation

Enumerator:
DiplomacyAllied 
DiplomacyNeutral  Ally with opponent.
DiplomacyEnemy  Don't attack be neutral.
DiplomacyCrazy  Attack opponent.

Ally and attack opponent


Function Documentation

void ActionStillGeneric ( CUnit unit,
bool  stand_ground 
)

Generic still action.

Unit stands still or stand ground.

Parameters:
unit Unit pointer for action.
stand_ground true if unit is standing ground.

void AnimateActionAttack ( CUnit unit  ) 

Show attack animation.

Animate unit attack!

Parameters:
unit Unit, for that the attack animation is played.
Todo:
manage correctly unit with no animation attack.

void AutoAttack ( CUnit unit,
CUnitCache targets,
bool  stand_ground 
)

void CommandAttack ( CUnit unit,
const Vec2i pos,
CUnit dest,
int  flush 
)

Prepare command attack.

void CommandAttackGround ( CUnit unit,
const Vec2i pos,
int  flush 
)

Prepare command attack ground.

void CommandAutoRepair ( CUnit unit,
int  on 
)

Send auto repair command.

Auto repair.

Parameters:
unit pointer to unit.
on 1 for auto repair on, 0 for off.

void CommandAutoSpellCast ( CUnit unit,
int  spellid,
int  on 
)

Prepare command auto spellcast.

Auto spell cast.

Parameters:
unit pointer to unit.
spellid Spell id.
on 1 for auto cast on, 0 for off.

void CommandBoard ( CUnit unit,
CUnit dest,
int  flush 
)

Prepare command board.

Board a transporter with unit.

Parameters:
unit pointer to unit.
dest unit to be boarded.
flush if true, flush command queue.

void CommandBuildBuilding ( CUnit unit,
const Vec2i pos,
CUnitType ,
int  flush 
)

Prepare command build.

void CommandCancelResearch ( CUnit unit  ) 

Prepare command cancel research.

Cancel Building researching.

Parameters:
unit Pointer to unit.

void CommandCancelTraining ( CUnit unit,
int  slot,
const CUnitType type 
)

Prepare command cancel training.

Cancel the training of an unit.

Parameters:
unit pointer to unit.
slot slot number to cancel.
type Unit-type to cancel.

void CommandCancelUpgradeTo ( CUnit unit  ) 

Prepare command cancel upgrade to.

Cancel building upgrading to.

Parameters:
unit pointer to unit.

void CommandDiplomacy ( int  player,
int  state,
int  opponent 
)

Prepare diplomacy command.

Diplomacy changed.

Parameters:
player Player which changes his state.
state New diplomacy state.
opponent Opponent.

void CommandDismiss ( CUnit unit  ) 

Prepare command dismiss.

Cancel the building construction, or kill a unit.

Parameters:
unit pointer to unit.

void CommandFollow ( CUnit unit,
CUnit dest,
int  flush 
)

Prepare command follow.

Follow unit to new position

Parameters:
unit pointer to unit.
dest unit to be followed
flush if true, flush command queue.

void CommandMove ( CUnit unit,
const Vec2i pos,
int  flush 
)

Prepare command move.

void CommandMoveOrder ( CUnit unit,
int  src,
int  dst 
)

Send any command.

Move an order in command queue

Move an order in the order queue. ( Cannot move the order 0 ! )

Parameters:
unit pointer to unit
src the order to move
dst the new position of the order

void CommandPatrolUnit ( CUnit unit,
const Vec2i pos,
int  flush 
)

Prepare command patrol.

void CommandQuit ( int  player  ) 

Hash calculated to find sync failures.

This function gives a unit a new command. If the command is given by the user the function with Send prefix should be used. Prepare command quit

Player quit.

Parameters:
player Player number that quit.

void CommandRepair ( CUnit unit,
const Vec2i pos,
CUnit dest,
int  flush 
)

Prepare command repair.

void CommandResearch ( CUnit unit,
CUpgrade what,
int  flush 
)

Prepare command research.

Building starts researching.

Parameters:
unit pointer to unit.
what what to research.
flush if true, flush command queue.

void CommandResource ( CUnit unit,
CUnit dest,
int  flush 
)

Prepare command resource.

Send unit to harvest resources

Parameters:
unit pointer to unit.
dest destination unit.
flush if true, flush command queue.

void CommandResourceLoc ( CUnit unit,
const Vec2i pos,
int  flush 
)

Prepare command resource location.

void CommandReturnGoods ( CUnit unit,
CUnit goal,
int  flush 
)

Prepare command return.

Let unit returning goods.

Parameters:
unit pointer to unit.
goal bring goods to this depot.
flush if true, flush command queue.

void CommandSetResource ( int  player,
int  resource,
int  value 
)

Prepare set resources command.

Set new resources count for player.

Parameters:
player Player which changes his state.
resource Resource index
value New value

void CommandSharedVision ( int  player,
bool  state,
int  opponent 
)

Prepare shared vision command.

Shared vision changed.

Parameters:
player Player which changes his state.
state New shared vision state.
opponent Opponent.

void CommandSpellCast ( CUnit unit,
const Vec2i pos,
CUnit dest,
SpellType spell,
int  flush 
)

Prepare command spellcast.

void CommandStandGround ( CUnit unit,
int  flush 
)

Prepare command stand ground.

Stand ground.

Parameters:
unit pointer to unit.
flush if true, flush command queue.

void CommandStopUnit ( CUnit unit  ) 

Prepare command stop.

Stop unit.

Parameters:
unit pointer to unit.

void CommandTrainUnit ( CUnit unit,
CUnitType type,
int   
)

Prepare command train.

Building starts training an unit.

Parameters:
unit pointer to unit.
type unit type to train.
flush if true, flush command queue.

void CommandTransformIntoType ( CUnit unit,
CUnitType type 
)

immediate transforming into type.

Immediate transforming unit into type.

Parameters:
unit pointer to unit.
type upgrade to type

void CommandUnload ( CUnit unit,
const Vec2i pos,
CUnit what,
int  flush 
)

Prepare command unload.

void CommandUpgradeTo ( CUnit unit,
CUnitType type,
int  flush 
)

Prepare command upgrade to.

Building starts upgrading to.

Parameters:
unit pointer to unit.
type upgrade to type
flush if true, flush command queue.

int DoActionMove ( CUnit unit  ) 

Generic move action.

Unit moves! Generic function called from other actions.

Parameters:
unit Pointer to unit.
Returns:
>0 remaining path length, 0 wait for path, -1 reached goal, -2 can't reach the goal.

void DropResource ( CUnit unit  ) 

int GetNumWaitingWorkers ( const CUnit mine  ) 

void HandleActionAttack ( CUnit unit  ) 

Handle command attack.

Unit attacks!

I added a little trick, if SubAction&WEAK_TARGET is true the goal is a weak goal. This means the unit AI (little AI) could choose a new better goal.

Todo:
Lets do some tries to reach the target. If target place is not reachable, choose better goal to reduce the pathfinder load.
Parameters:
unit Unit, for that the attack is handled.

void HandleActionBoard ( CUnit unit  ) 

Handle command board.

The unit boards a transporter.

Todo:
FIXME: While waiting for the transporter the units must defend themselves.
Parameters:
unit Pointer to unit.

void HandleActionBuild ( CUnit unit  ) 

Handle command build.

Unit builds a building.

Parameters:
unit Unit that builds a building

void HandleActionBuilt ( CUnit unit  ) 

Handle command built.

Unit under Construction

Parameters:
unit Unit that is being built

void HandleActionDie ( CUnit unit  ) 

Handle command die.

Unit dies!

Parameters:
unit The unit which dies.

void HandleActionFollow ( CUnit unit  ) 

Handle command follow.

Unit follow action:

Parameters:
unit Pointer to unit.

???????

void HandleActionMove ( CUnit unit  ) 

Handle command move.

Unit move action:

Move to a place or to a unit (can move). Tries 10x to reach the target, note this are the complete tries. If the target entered another unit, move to it's position. If the target unit is destroyed, continue to move to it's last position.

Parameters:
unit Pointer to unit.

void HandleActionPatrol ( CUnit unit  ) 

Handle command patrol.

Unit Patrol: The unit patrols between two points. Any enemy unit in reaction range is attacked.

Todo:
FIXME: Should do some tries to reach the end-points. Should support patrol between more points! Patrol between units.
Parameters:
unit Patroling unit pointer.

void HandleActionRepair ( CUnit unit  ) 

Handle command repair.

Unit repairs

Parameters:
unit Unit, for that the attack is handled.

void HandleActionResearch ( CUnit unit  ) 

Handle command research.

Unit researches!

Parameters:
unit Pointer of researching unit.

void HandleActionResource ( CUnit unit  ) 

Handle command resource.

Control the unit action: getting a resource.

This the generic function for oil, gold, ...

Parameters:
unit Pointer to unit.

void HandleActionReturnGoods ( CUnit unit  ) 

Handle command return.

Return goods to gold/wood deposit.

Parameters:
unit pointer to unit.
Todo:
FIXME: move this into action_resource?

void HandleActionSpellCast ( CUnit unit  ) 

Handle command spellcast.

Unit casts a spell!

Parameters:
unit Unit, for that the spell cast is handled.

void HandleActionStandGround ( CUnit unit  ) 

Handle command stand ground.

Unit stands ground!

Parameters:
unit Action handled for this unit pointer.

void HandleActionStill ( CUnit unit  ) 

Handle command still.

Unit stands still!

Parameters:
unit Unit pointer for still action.

void HandleActionTrain ( CUnit unit  ) 

Handle command train.

Unit trains unit!

Parameters:
unit Unit that trains.

void HandleActionTransformInto ( CUnit unit  ) 

Handle command transform into.

Unit transform into unit.

Parameters:
unit Pointer to unit.

void HandleActionUnload ( CUnit unit  ) 

Handle command unload.

The transporter unloads a unit.

Parameters:
unit Pointer to unit.

void HandleActionUpgrade ( CUnit unit  ) 

Handle command upgrade.

void HandleActionUpgradeTo ( CUnit unit  ) 

Handle command upgrade to.

Unit upgrades unit!

Parameters:
unit Pointer to unit.

void ResourceGiveUp ( CUnit unit  ) 

Give up on gathering.

Parameters:
unit Pointer to unit.

void UnHideUnit ( CUnit unit  ) 

void UnitActions (  ) 

Handle the actions of all units each game cycle.

Update the actions of all units each game cycle.

Todo:
To improve the preformance use slots for waiting.

int UnitShowAnimation ( CUnit unit,
const CAnimation anim 
)

Handle the animation of a unit.

Show unit animation.

Parameters:
unit Unit of the animation.
anim Animation script to handle.
Returns:
The flags of the current script step.

int UnitShowAnimationScaled ( CUnit unit,
const CAnimation anim,
int  scale 
)

Handle the animation of a unit.

Show unit animation.

Parameters:
unit Unit of the animation.
anim Animation script to handle.
scale Scaling factor of the wait times in animation (8 means no scaling).
Returns:
The flags of the current script step.


Variable Documentation

unsigned SyncHash

(C) Copyright 1998-2011 by The Stratagus Project under the GNU General Public License.
All trademarks and copyrights on this page are owned by their respective owners.