Orxonox  0.0.5 Codename: Arcturus
Classes | Public Member Functions | Private Member Functions | Private Attributes | Static Private Attributes | Friends | List of all members
orxonox::ScriptableControllerAPI Class Reference

API for ScriptableController's lua-scripts. More...

#include </home/jenkins/workspace/orxonox_doxygen_trunk/src/orxonox/scriptablecontroller/scriptable_controller_api.h>

Classes

struct  AreaHandler
 Groups everything together that is needed to handle an area enter/leave event. More...
 
struct  NearObjectHandler
 Groups everything together that is needed to handle a near-object event. More...
 
struct  NearPointHandler
 Groups everything together that is needed to handle a near-poinb event. More...
 

Public Member Functions

 ScriptableControllerAPI (lua_State *lua, ScriptableController *controller)
 Constructs the API with the given lua state. More...
 
 ~ScriptableControllerAPI ()
 Destructs the API and closes the lua state. More...
 
void killPawn (std::string id)
 Kill a pawn. More...
 
void moveControllableEntity (std::string id, double x, double y, double z)
 
double myTestFunction (double x, double y)
 Set the angular velocity of an object. More...
 
void orxPrint (std::string msg)
 Print a message. More...
 
void registerAfterTimeout (std::function< void(void)> callback, double timeout)
 Register a function that will be called after a timeout. More...
 
void registerAtAreaEnter (std::function< void(std::string)> callback, std::string id, int x, int y, int z, int dx, int dy, int dz)
 Register a function that will be called when an object enters a cubic area. More...
 
void registerAtAreaLeave (std::function< void(std::string)> callback, std::string id, int x, int y, int z, int dx, int dy, int dz)
 Register a function that will be called when an object leaves a cubic area. More...
 
void registerAtNearObject (std::function< void(std::string, std::string)> callback, std::string id1, std::string id2, double distance)
 Register a function that will be called when two object are close to eachother. More...
 
void registerAtNearPoint (std::function< void(std::string)> callback, std::string id, double x, double y, double z, double distance)
 Register a function that will be called when an object is close to a certain point. More...
 
void registerAtPawnHit (std::function< void(std::string, std::string, double, double)> callback, std::string id)
 Register a function that will be called when a Pawn is hit. More...
 
void registerAtPawnKilled (std::function< void(std::string)> callback, std::string id)
 Register a function that will be called when a Pawn is killed. More...
 
void setAngularVelocity (std::string id, double x, double y, double z)
 Set the angular velocity of an object. More...
 
void setOrientation (std::string id, double x, double y, double z, double angle)
 Set the orientation of an object. More...
 
void setPosition (std::string id, double x, double y, double z)
 Set the position of an object. More...
 
void setVelocity (std::string id, double x, double y, double z)
 Set the velocity of an object. More...
 
void spawn (std::string type, std::string id)
 Spawn an object. More...
 
void spawnTest (std::string id)
 

Private Member Functions

void pawnHit (std::string target_id, std::string source_id, double new_health, double new_shield)
 Called by ScriptableController when a Pawn is hit. More...
 
void pawnKilled (std::string id, Pawn *pawn)
 Called by ScriptableController when a pawn is killed. More...
 
void periodic (void)
 Called every 0.5s. More...
 

Private Attributes

std::list< AreaHandlerareaHandlers_
 
ScriptableControllercontroller_
 
lua_State * lua_
 
std::list< NearObjectHandlernearObjectHandlers_
 
std::list< NearPointHandlernearPointHandlers_
 
std::map< std::string, std::list< std::function< void(std::string)> > > pawnDestroyedHandlers_
 
std::map< std::string, std::list< std::function< void(std::string, std::string, double, double)> > > pawnHitHandlers_
 
Timer periodicTimer
 

Static Private Attributes

static const double periodic_interval = 0.5
 

Friends

class ScriptableController
 

Detailed Description

API for ScriptableController's lua-scripts.

Defines the interface that lua can use in the scripts to communicate with orxonox.

See also
ScriptableController

Constructor & Destructor Documentation

orxonox::ScriptableControllerAPI::ScriptableControllerAPI ( lua_State *  lua,
ScriptableController controller 
)

Constructs the API with the given lua state.

Parameters
luaThe lua state
controllerThe parent controller

This will not run any scripts, it'll just make the API visible to lua.

orxonox::ScriptableControllerAPI::~ScriptableControllerAPI ( )

Destructs the API and closes the lua state.

Member Function Documentation

void orxonox::ScriptableControllerAPI::killPawn ( std::string  id)

Kill a pawn.

Parameters
idThe pawn to kill

Note: It might up to 0.5s until the pawn is actually killed.

void orxonox::ScriptableControllerAPI::moveControllableEntity ( std::string  id,
double  x,
double  y,
double  z 
)
double orxonox::ScriptableControllerAPI::myTestFunction ( double  x,
double  y 
)

Set the angular velocity of an object.

Parameters
idThe ID of the object
xThe rotation velocity around the x-axis
yThe rotation velocity around the y-axis
zThe rotation velocity around the z-axis
void orxonox::ScriptableControllerAPI::orxPrint ( std::string  msg)

Print a message.

Parameters
msgThe message

Use this function instead of printing from lua directly, because that will mess up the output as it is not synchronized.

void orxonox::ScriptableControllerAPI::pawnHit ( std::string  target_id,
std::string  source_id,
double  new_health,
double  new_shield 
)
private

Called by ScriptableController when a Pawn is hit.

Parameters
target_idThe hit Pawn
source_idThe shooting Pawn
new_healthThe new health of the hit Pawn
new_shieldThe new shield health of the hit Pawn
void orxonox::ScriptableControllerAPI::pawnKilled ( std::string  id,
Pawn pawn 
)
private

Called by ScriptableController when a pawn is killed.

Parameters
idThe dead pawn

Calls the lua callbacks associated with this event.

void orxonox::ScriptableControllerAPI::periodic ( void  )
private

Called every 0.5s.

This handles things that have to be checked periodically (like area events) but doing this in every tick would be an overkill.

void orxonox::ScriptableControllerAPI::registerAfterTimeout ( std::function< void(void)>  callback,
double  timeout 
)

Register a function that will be called after a timeout.

Parameters
callbackThe function to call after the timeout expired
timeoutThe timeout in seconds
void orxonox::ScriptableControllerAPI::registerAtAreaEnter ( std::function< void(std::string)>  callback,
std::string  id,
int  x,
int  y,
int  z,
int  dx,
int  dy,
int  dz 
)

Register a function that will be called when an object enters a cubic area.

Parameters
callbackThe function to call when the object entered the area
idThe object
xX-coordinate of the top-left corner
yY-coordinate of the top-left corner
zZ-coordinate of the top-left corner
dxSize in X-direction of the cube
dySize in Y-direction of the cube
dzSize in Z-direction of the cube

Note: Distances are only checked every 0.5s!

void orxonox::ScriptableControllerAPI::registerAtAreaLeave ( std::function< void(std::string)>  callback,
std::string  id,
int  x,
int  y,
int  z,
int  dx,
int  dy,
int  dz 
)

Register a function that will be called when an object leaves a cubic area.

Parameters
callbackThe function to call when the object left the area
idThe object
xX-coordinate of the top-left corner
yY-coordinate of the top-left corner
zZ-coordinate of the top-left corner
dxSize in X-direction of the cube
dySize in Y-direction of the cube
dzSize in Z-direction of the cube

Note: Distances are only checked every 0.5s!

void orxonox::ScriptableControllerAPI::registerAtNearObject ( std::function< void(std::string, std::string)>  callback,
std::string  id1,
std::string  id2,
double  distance 
)

Register a function that will be called when two object are close to eachother.

Parameters
callbackThe function to call when the objects are close enough
id1The first object
id2The second object
distanceIf the distance between the two objects is smaller than this value, the function is called

Note: Distances are only checked every 0.5s!

void orxonox::ScriptableControllerAPI::registerAtNearPoint ( std::function< void(std::string)>  callback,
std::string  id,
double  x,
double  y,
double  z,
double  distance 
)

Register a function that will be called when an object is close to a certain point.

Parameters
callbackThe function to call when the object is close enough
idThe object
xX-coordinate of the point
yY-coordinate of the point
zZ-coordinate of the point
distanceIf the distance between the object and the point is smaller than this value, the function is called.

Note: Distances are only checked every 0.5s!

void orxonox::ScriptableControllerAPI::registerAtPawnHit ( std::function< void(std::string, std::string, double, double)>  callback,
std::string  id 
)

Register a function that will be called when a Pawn is hit.

Parameters
callbackThe function to call as soon as the Pawn is hit
idThe Pawn

Note: Once a Pawn is dead, the all hit-callbacks are removed, even if the pawn got magically revived.

void orxonox::ScriptableControllerAPI::registerAtPawnKilled ( std::function< void(std::string)>  callback,
std::string  id 
)

Register a function that will be called when a Pawn is killed.

Parameters
callbackThe function to call as soon as the Pawn is dead
idThe Pawn

Note: Once a Pawn is dead, the callback is removed, even if the pawn got magically revived.

void orxonox::ScriptableControllerAPI::setAngularVelocity ( std::string  id,
double  x,
double  y,
double  z 
)

Set the angular velocity of an object.

Parameters
idThe ID of the object
xThe rotation velocity around the x-axis
yThe rotation velocity around the y-axis
zThe rotation velocity around the z-axis
void orxonox::ScriptableControllerAPI::setOrientation ( std::string  id,
double  x,
double  y,
double  z,
double  angle 
)

Set the orientation of an object.

Parameters
idThe ID of the object
xThe x component of the axis vector
yThe y component of the axis vector
zThe z component of the axis vector
angleThe angle around the axis

To set the orientation, you have to specify the direction that the object should be facing with the vector (x, y, z) and the rotation of the object around this axis with 'angle', which has to be given in degrees, NOT radian. The vector does not have to be normalized.

void orxonox::ScriptableControllerAPI::setPosition ( std::string  id,
double  x,
double  y,
double  z 
)

Set the position of an object.

Parameters
idThe ID of the object
xThe position on the x-axis
yThe position on the y-axis
zThe position on the z-axis
void orxonox::ScriptableControllerAPI::setVelocity ( std::string  id,
double  x,
double  y,
double  z 
)

Set the velocity of an object.

Parameters
idThe ID of the object
xThe velocity in x-direction
yThe velocity in y-direction
zThe velocity in z-direction

The velocity is in units per second.

void orxonox::ScriptableControllerAPI::spawn ( std::string  type,
std::string  id 
)

Spawn an object.

Parameters
typeName of the class of the object you want to spawn
idThe newly created ID that can be used to access this object

IMPORTANT: Do not use this function yet, it only has minimal functionality and is not really helpful as it is.

void orxonox::ScriptableControllerAPI::spawnTest ( std::string  id)

Friends And Related Function Documentation

friend class ScriptableController
friend

Member Data Documentation

std::list<AreaHandler> orxonox::ScriptableControllerAPI::areaHandlers_
private
ScriptableController* orxonox::ScriptableControllerAPI::controller_
private
lua_State* orxonox::ScriptableControllerAPI::lua_
private
std::list<NearObjectHandler> orxonox::ScriptableControllerAPI::nearObjectHandlers_
private
std::list<NearPointHandler> orxonox::ScriptableControllerAPI::nearPointHandlers_
private
std::map<std::string, std::list<std::function<void (std::string)> > > orxonox::ScriptableControllerAPI::pawnDestroyedHandlers_
private
std::map<std::string, std::list<std::function<void (std::string, std::string, double, double)> > > orxonox::ScriptableControllerAPI::pawnHitHandlers_
private
const double orxonox::ScriptableControllerAPI::periodic_interval = 0.5
staticprivate
Timer orxonox::ScriptableControllerAPI::periodicTimer
private

The documentation for this class was generated from the following files: