An active ocupier of the world. More...
#include <actor.h>
Public Member Functions | |
Actor (World *w) | |
constructor; creates an invalid actor that needs further initialisation | |
virtual bool | save (QSettings &s) const |
save to a QSettings object | |
virtual bool | load (QSettings &s) |
load from a QSettings object | |
virtual ID | identificator (void) const |
associated ID, if any | |
virtual Factory * | factory (void) const |
associated factory, if any | |
Allow access to components | |
Sensor * | firstSensor (void) const |
first sensor in internal list | |
Actuator * | firstActuator (void) const |
first actuator in internal list | |
Reflex * | firstReflex (void) const |
first reflex in internal list | |
Brain * | firstBrain (void) const |
first brain in internal list | |
find components based on their ID | |
Sensor * | findSensor (ID id) const |
first sensor in internal list | |
Actuator * | findActuator (ID id) const |
first actuator in internal list | |
Reflex * | findReflex (ID id) const |
first reflex in internal list | |
Brain * | findBrain (ID id) const |
first brain in internal list | |
infromation about the actor | |
World * | world (void) const |
the world where we belong | |
ID | kind (void) const |
tell the kind | |
QString | kindName (void) const |
get the name of the kind (shortcut for UniqueId::name() ) | |
const DNA & | dna (void) const |
the DNA of this actor | |
quint64 | birth (void) const |
tell the date of birth | |
quint64 | death (void) const |
tell the date of death | |
quint64 | age (void) const |
tell the age of this actor | |
quint64 | toLive (void) const |
tell the life span of this actor | |
quint64 | energy (void) const |
own energy reserve | |
quint64 | totalEnergy (void) const |
total energy packed in this agent (the agent itself and the compoenets) | |
quint64 | cost (void) const |
energy cost | |
bool | isAlive (void) const |
alive or dead | |
bool | dies (void) const |
tell if this is the moment when the agent dies | |
Public Member Functions inherited from april::Component | |
Component (void) | |
constructor; | |
Amorph & | payload (void) |
associated data |
Static Public Member Functions | |
static Q_REQUIRED_RESULT Actor * | fromStg (World *w, QSettings &s) |
constructor method; creates and loads an actor from QSettings |
Protected Member Functions | |
virtual | ~Actor (void) |
destructor; | |
void | killMe (void) |
kill the actor; both the actor and the world use this method | |
Changing the actor's internals | |
void | setDNA (const DNA &src) |
set the DNA to provided sequence (intended for ActorFactory) | |
bool | decodeDNA (void) |
load the components of the actor from the DNA | |
bool | addActuator (Actuator *act) |
add an Actuator | |
bool | addSensor (Sensor *act) |
add a Sensor | |
bool | addReflex (Reflex *act) |
add a Reflex | |
bool | addBrain (Brain *act) |
add a Brain | |
bool | remActuator (Actuator *act) |
remove an Actuator | |
bool | remSensor (Sensor *act) |
remove a Sensor | |
bool | remReflex (Reflex *act) |
remove a Reflex | |
bool | remBrain (Brain *act) |
remove a Brain | |
void | doSteps (int steps=1) |
perform steps (called by the World) | |
void | makeAlive (void) |
make the actor alive | |
void | setEnergy (quint64 new_val) |
set total energy (used by the world to initialise and terminate actor) | |
Protected Member Functions inherited from april::Component | |
virtual | ~Component (void) |
destructor; | |
virtual void | inserted (void) |
the instance is informed that the parent attached it |
Friends | |
class | Director |
class | Sensor |
class | Actuator |
class | World |
class | Reflex |
class | Brain |
class | ActorFactory |
An active ocupier of the world.
When an actor is first constructed it is not alive. This allows the caller to initialise it, decode, DNA, ... Once the actor is made alive using makeAlive() it will recieve time ticks from the World via doSteps(). Because the world may be runned in a multi-thread environment doSteps() also recieves the number of time units that passed since the actor was last called.
doSteps() substracts the constant cost from the current energy and if the energy is exhausted the actor dies (sends World::actorDies() to parent world). Same happens if the actor reaches its death_ age.
doSteps() iterates components and sends them ActorComp::doSteps(). The order is following:
|
protected |
kill the actor; both the actor and the world use this method
The world is informed using World::actorDies(). Any remaining energy remaining inside is taken by the world.