#include <instance.h>
Public Member Functions | |
Instance (Object *object, const Location &location, const std::string &identifier="") | |
virtual | ~Instance () |
const std::string & | getId () |
void | setId (const std::string &identifier="") |
Object * | getObject () |
void | setLocation (const Location &loc) |
Location | getLocation () const |
Location & | getLocationRef () |
Location | getTargetLocation () const |
void | setFacingLocation (const Location &loc) |
Location | getFacingLocation () |
void | setRotation (int rotation) |
int | getRotation () const |
Location & | getFacingLocationRef () |
void | addActionListener (InstanceActionListener *listener) |
void | removeActionListener (InstanceActionListener *listener) |
void | addChangeListener (InstanceChangeListener *listener) |
void | removeChangeListener (InstanceChangeListener *listener) |
void | addDeleteListener (InstanceDeleteListener *listener) |
void | removeDeleteListener (InstanceDeleteListener *listener) |
Action * | getCurrentAction () const |
double | getMovementSpeed () const |
unsigned int | getActionRuntime () |
void | setActionRuntime (unsigned int time_offset) |
void | move (const std::string &action_name, const Location &target, const double speed) |
void | act (const std::string &action_name, const Location &direction, bool repeating=false) |
void | say (const std::string &text, unsigned int duration=0) |
void | follow (const std::string &action_name, Instance *leader, const double speed) |
const std::string * | getSayText () const |
InstanceChangeInfo | update () |
void | setVisual (AbstractVisual *visual) |
template<typename T > | |
T * | getVisual () const |
void | setTimeMultiplier (float multip) |
float | getTimeMultiplier () |
float | getTotalTimeMultiplier () |
unsigned int | getRuntime () |
void | refresh () |
InstanceChangeInfo | getChangeInfo () |
void | onInstanceDeleted (Instance *instance) |
An Instance is an "instantiation" of an Object at a Location.
Definition at line 83 of file instance.h.
FIFE::Instance::Instance | ( | Object * | object, | |
const Location & | location, | |||
const std::string & | identifier = "" | |||
) |
Constructor Instances are created by calling addInstance from layer, thus this method should really be called only by layer or test code
Definition at line 172 of file instance.cpp.
FIFE::Instance::~Instance | ( | ) | [virtual] |
Destructor
Definition at line 183 of file instance.cpp.
void FIFE::Instance::act | ( | const std::string & | action_name, | |
const Location & | direction, | |||
bool | repeating = false | |||
) |
Performs given named action to the instance. Performs no movement
action_name | name of the action | |
direction | coordinates for cell towards instance is heading to when performing the action | |
repeating | in case true, keeps repeating this action |
Definition at line 304 of file instance.cpp.
References setFacingLocation().
void FIFE::Instance::addActionListener | ( | InstanceActionListener * | listener | ) |
Adds new instance action listener
listener | to add |
Definition at line 224 of file instance.cpp.
void FIFE::Instance::addChangeListener | ( | InstanceChangeListener * | listener | ) |
Adds new instance change listener
listener | to add |
Definition at line 244 of file instance.cpp.
void FIFE::Instance::addDeleteListener | ( | InstanceDeleteListener * | listener | ) |
Adds new instance delete listener
listener | to add |
Definition at line 555 of file instance.cpp.
Referenced by follow().
void FIFE::Instance::follow | ( | const std::string & | action_name, | |
Instance * | leader, | |||
const double | speed | |||
) |
Performs given named action to the instance. While performing the action follows given isntance with given speed
action_name | name of the action | |
leader | followed instance | |
speed | speed used for movement. Units = distance 1 in layer coordinates per second |
Definition at line 293 of file instance.cpp.
References addDeleteListener(), getLocationRef(), and setFacingLocation().
unsigned int FIFE::Instance::getActionRuntime | ( | ) |
Gets the time in milliseconds how long action has been active In case there is no current action, returns -1
Definition at line 475 of file instance.cpp.
References getRuntime().
InstanceChangeInfo FIFE::Instance::getChangeInfo | ( | ) | [inline] |
Returns a bitmask of changes since previous update
Definition at line 371 of file instance.h.
Action * FIFE::Instance::getCurrentAction | ( | ) | const |
Gets the currently active action. This is owned by the instance's object, so don't delete it!
Definition at line 441 of file instance.cpp.
Location FIFE::Instance::getFacingLocation | ( | ) |
Returns the direction where instance is heading
Definition at line 462 of file instance.cpp.
References getFacingLocationRef().
Location & FIFE::Instance::getFacingLocationRef | ( | ) |
Returns reference to the direction where instance is heading Note: if instance didn't previously hadn't defined facing location (e.g. by movement or setFacingLocation), method creates the location thus increasing memory consumption.
Definition at line 466 of file instance.cpp.
Referenced by getFacingLocation().
const std::string& FIFE::Instance::getId | ( | ) | [inline] |
Get the identifier for this instance; possibly null.
Definition at line 98 of file instance.h.
Location FIFE::Instance::getLocation | ( | ) | const [inline] |
Gets current location of instance
Definition at line 117 of file instance.h.
Location& FIFE::Instance::getLocationRef | ( | ) | [inline] |
Gets reference of current location of instance
Definition at line 122 of file instance.h.
Referenced by follow().
double FIFE::Instance::getMovementSpeed | ( | ) | const |
Gets the speed in case instance is moving otherwise returns 0
Definition at line 455 of file instance.cpp.
Object* FIFE::Instance::getObject | ( | ) | [inline] |
Gets object where this instance is instantiated from
Definition at line 106 of file instance.h.
Referenced by FIFE::InstanceVisualCacheItem::getStaticImageIndexByAngle().
int FIFE::Instance::getRotation | ( | ) | const [inline] |
Get the rotation offset of this instance
Definition at line 149 of file instance.h.
unsigned int FIFE::Instance::getRuntime | ( | ) |
Gets the scaled runtime in milliseconds
Definition at line 541 of file instance.cpp.
References FIFE::TimeProvider::getGameTime(), and FIFE::Map::getTimeProvider().
Referenced by getActionRuntime(), and say().
const std::string * FIFE::Instance::getSayText | ( | ) | const |
Returns pointer to currently set saytext. In case no text is set, returns NULL
Definition at line 322 of file instance.cpp.
Location FIFE::Instance::getTargetLocation | ( | ) | const |
Gets movement target in case instance is moving. In case not, returns current location To move target location, call move-method
Definition at line 448 of file instance.cpp.
float FIFE::Instance::getTimeMultiplier | ( | ) |
float FIFE::Instance::getTotalTimeMultiplier | ( | ) |
Gets instance speed, considering also model and map speeds.
Definition at line 528 of file instance.cpp.
References FIFE::Map::getTimeProvider(), and FIFE::TimeProvider::getTotalMultiplier().
T* FIFE::Instance::getVisual | ( | ) | const [inline] |
Gets used visualization
Definition at line 260 of file instance.h.
Referenced by FIFE::InstanceVisual::create().
void FIFE::Instance::move | ( | const std::string & | action_name, | |
const Location & | target, | |||
const double | speed | |||
) |
Performs given named action to the instance. While performing the action moves instance to given target with given speed
action_name | name of the action | |
target | place where to move this instance | |
speed | speed used for movement. Units = distance 1 in layer coordinates per second |
Definition at line 284 of file instance.cpp.
References setFacingLocation().
void FIFE::Instance::onInstanceDeleted | ( | Instance * | instance | ) |
callback so other instances we depend on can notify us if they go away
Definition at line 569 of file instance.cpp.
void FIFE::Instance::refresh | ( | ) |
Refreshes instance e.g. in case location is updated directly (not via setLocation) In this case e.g. instance's master time provider is changed, so it needs to be updated
Definition at line 508 of file instance.cpp.
void FIFE::Instance::removeActionListener | ( | InstanceActionListener * | listener | ) |
Removes associated instance action listener
listener | to remove |
Definition at line 229 of file instance.cpp.
void FIFE::Instance::removeChangeListener | ( | InstanceChangeListener * | listener | ) |
Removes associated instance change listener
listener | to remove |
Definition at line 249 of file instance.cpp.
void FIFE::Instance::removeDeleteListener | ( | InstanceDeleteListener * | listener | ) |
Removes associated instance delete listener
listener | to remove |
Definition at line 558 of file instance.cpp.
void FIFE::Instance::say | ( | const std::string & | text, | |
unsigned int | duration = 0 | |||
) |
Causes instance to "say" given text (shown on screen next to the instance)
text | text to say. If "" given, clear the text | |
duration | duration to show the text (in ms). If 0, shows forever |
Definition at line 311 of file instance.cpp.
References getRuntime().
Referenced by update().
void FIFE::Instance::setActionRuntime | ( | unsigned int | time_offset | ) |
Sets the time in milliseconds how long an action has been active This was requested in Ticket #373. This way the state of the action can be saved and restored at a later time The action time offset that should be applied
Definition at line 484 of file instance.cpp.
void FIFE::Instance::setFacingLocation | ( | const Location & | loc | ) |
Sets the direction where instance is heading. Useful e.g. with static instances which don't "move" or "act"
Definition at line 329 of file instance.cpp.
Referenced by act(), follow(), and move().
void FIFE::Instance::setId | ( | const std::string & | identifier = "" |
) |
Set the identifier for this instance.
Definition at line 220 of file instance.cpp.
void FIFE::Instance::setLocation | ( | const Location & | loc | ) |
Sets location of the instance
loc | new location |
Definition at line 209 of file instance.cpp.
void FIFE::Instance::setRotation | ( | int | rotation | ) |
Set the rotation offset of this instance
Definition at line 215 of file instance.cpp.
void FIFE::Instance::setTimeMultiplier | ( | float | multip | ) |
Sets speed for the map. See Model::setTimeMultiplier.
Definition at line 513 of file instance.cpp.
void FIFE::Instance::setVisual | ( | AbstractVisual * | visual | ) | [inline] |
Sets visualization to be used. Transfers ownership.
Definition at line 256 of file instance.h.
Referenced by FIFE::InstanceVisual::create().
InstanceChangeInfo FIFE::Instance::update | ( | ) |
Updates the instance related to the current action
Definition at line 364 of file instance.cpp.
References say().