Orxonox  0.0.5 Codename: Arcturus
Public Member Functions | Private Member Functions | Private Attributes | List of all members
orxonox::ScriptableController Class Reference

Runs a scripts on a per-level basis and handles the connection to orxonox. More...

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

Public Member Functions

MobileEntitygetMobileEntityByID (std::string id) const
 Convert an ID to a MobileEntity pointer. More...
 
PawngetPawnByID (std::string id) const
 Convert an ID to a Pawt pointer. More...
 
WorldEntitygetWorldEntityByID (std::string id) const
 Convert an ID to a WorldEntity pointer. More...
 
void pawnHit (Pawn *target, Pawn *source, double new_health, double new_shield)
 Called when a Pawn is hit. More...
 
void pawnKilled (Pawn *pawn)
 Called when a Pawn is killed. More...
 
void registerMobileEntity (std::string id, MobileEntity *entity)
 Register a MobileEntity to the ScriptableController. More...
 
void registerPawn (std::string id, Pawn *pawn)
 Register a Pawn to the ScriptableController. More...
 
void registerWorldEntity (std::string id, WorldEntity *entity)
 Register a WorldEntity to the ScriptableController. More...
 
int runScript (const std::string &file_path)
 Run a lua script. More...
 
void setPlayer (PlayerInfo *player)
 Set the player object of the current game. More...
 

Private Member Functions

void printLuaError (lua_State *lua)
 Prints a human readable error message if a lua error occurs. More...
 

Private Attributes

std::list< std::unique_ptr< ScriptableControllerAPI > > apis_
 
std::map< std::string, ControllableEntity * > controllabelEntities_
 
std::map< std::string, MobileEntity * > mobileEntities_
 
std::map< std::string, Pawn * > pawns_
 
std::map< Pawn *, std::string > pawnsReverse_
 
PlayerInfoplayer_
 
std::map< std::string, WorldEntity * > worldEntities_
 

Detailed Description

Runs a scripts on a per-level basis and handles the connection to orxonox.

The script is an attribute of the <Level> element with the name 'script' and should be the path to a lua script. The script will be run as soon as the player spawns. It can then register on various events and react to them. See ScriptableControllerAPI for the complete API.

See also
ScriptableControllerAPI

Member Function Documentation

MobileEntity * orxonox::ScriptableController::getMobileEntityByID ( std::string  id) const

Convert an ID to a MobileEntity pointer.

Parameters
idThe ID of the MobileEntity
Returns
A pointer to the MobileEntity, nullptr if it's not found
Pawn * orxonox::ScriptableController::getPawnByID ( std::string  id) const

Convert an ID to a Pawt pointer.

Parameters
idThe ID of the Pawn
Returns
A pointer to the Pawn, nullptr if it's not found
WorldEntity * orxonox::ScriptableController::getWorldEntityByID ( std::string  id) const

Convert an ID to a WorldEntity pointer.

Parameters
idThe ID of the WorldEntity
Returns
A pointer to the WorldEntity, nullptr if it's not found
void orxonox::ScriptableController::pawnHit ( Pawn target,
Pawn source,
double  new_health,
double  new_shield 
)

Called when a Pawn is hit.

Parameters
targetThe hit Pawn
sourceThe shooting Pawn
new_healthThe new health of the hit Pawn
new_shieldThe new shield health of the hit Pawn

Called by the Pawn itself as soon as it's hit.

void orxonox::ScriptableController::pawnKilled ( Pawn pawn)

Called when a Pawn is killed.

Parameters
pawnThe Pawn

Called by the Pawn itself as soon as it's killed.

void orxonox::ScriptableController::printLuaError ( lua_State *  lua)
private

Prints a human readable error message if a lua error occurs.

Parameters
luaThe lua state where the error occured
void orxonox::ScriptableController::registerMobileEntity ( std::string  id,
MobileEntity entity 
)

Register a MobileEntity to the ScriptableController.

Parameters
idThe ID of the MobileEntity
entityThe MobileEntity

The ScriptableController needs a list of all MobileEntity's so it can convert an ID to a MobileEntity.

void orxonox::ScriptableController::registerPawn ( std::string  id,
Pawn pawn 
)

Register a Pawn to the ScriptableController.

Parameters
idThe ID of the Pawn
pawnThe Pawn

The ScriptableController needs a list of all Pawn's in addition to the WorldEntity's, because they have additional actions available.

void orxonox::ScriptableController::registerWorldEntity ( std::string  id,
WorldEntity entity 
)

Register a WorldEntity to the ScriptableController.

Parameters
idThe ID of the WorldEntity
entityThe WorldEntity

The ScriptableController needs a list of all WorldEntity's so it can convert an ID to a WorldEntity.

int orxonox::ScriptableController::runScript ( const std::string &  file_path)

Run a lua script.

Parameters
file_pathPath to the script
Returns
A lua error code (0 for success)

Constructs an API for the script and runs it.

void orxonox::ScriptableController::setPlayer ( PlayerInfo player)

Set the player object of the current game.

Parameters
playerThe player

The player is a special object and can perfom special actions.

Member Data Documentation

std::list<std::unique_ptr<ScriptableControllerAPI> > orxonox::ScriptableController::apis_
private
std::map<std::string, ControllableEntity*> orxonox::ScriptableController::controllabelEntities_
private
std::map<std::string, MobileEntity*> orxonox::ScriptableController::mobileEntities_
private
std::map<std::string, Pawn*> orxonox::ScriptableController::pawns_
private
std::map<Pawn*, std::string> orxonox::ScriptableController::pawnsReverse_
private
PlayerInfo* orxonox::ScriptableController::player_
private
std::map<std::string, WorldEntity*> orxonox::ScriptableController::worldEntities_
private

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