70 if (sessionId != -1) {
105 m_duration(duration),
114 m_location(source.m_location),
115 m_oldLocation(source.m_location),
116 m_rotation(source.m_rotation),
117 m_oldRotation(source.m_rotation),
121 m_timeMultiplier(1.0),
127 m_timeProvider(NULL),
128 m_blocking(source.m_blocking),
219 const std::set<Object*>& multis =
object->getMultiParts();
220 std::set<Object*>::const_iterator it = multis.begin();
221 for (; it != multis.end(); ++it, ++count) {
225 std::vector<ModelCoordinate> partcoords = (*it)->getMultiPartCoordinates(
m_rotation);
226 std::vector<ModelCoordinate>::iterator coordit = partcoords.begin();
227 for (; coordit != partcoords.end(); ++coordit) {
229 std::ostringstream counter;
242 std::vector<InstanceDeleteListener *>::iterator itor;
245 (*itor)->onInstanceDeleted(
this);
259 (*it)->removeDeleteListener(
this);
260 (*it)->setMainMultiInstance(NULL);
320 while (rotation < 0) {
372 if ((*i) == listener) {
394 (*i)->onInstanceActionFrame(
this, action, frame);
406 if ((*i) == listener) {
428 throw NotFound(std::string(
"action ") + actionName +
" not found");
440 }
else if (old_action && old_action->
getAudio()) {
447 (*multi_it)->initializeAction(actionName);
452 void Instance::move(
const std::string& actionName,
const Location& target,
const double speed,
const std::string& costId) {
470 FL_DBG(
_log,
LMsg(
"starting action ") << actionName <<
" from" <<
m_location <<
" to " << target <<
" with speed " << speed);
668 double distance_to_travel = (
static_cast<double>(timedelta) / 1000.0) * info->
m_speed;
748 if (movement_finished) {
810 (*multi_it)->finalizeAction();
816 (*i)->onInstanceActionFinished(
this, action);
845 (*multi_it)->cancelAction();
851 (*i)->onInstanceActionCancelled(
this, action);
918 float multiplier = 1.0;
1065 std::vector<ModelCoordinate> mcv = (*it)->getObject()->getMultiPartCoordinates(0);
1069 emc.
x = ((nemc.
x * mcos + nemc.
y * msin) + anchor_offset.
x) + anchor.
x;
1070 emc.
y = ((-nemc.
x * msin + nemc.
y * mcos) + anchor_offset.
y) + anchor.
y;
1072 (*it)->setLocation(loc);
1073 (*it)->setRotation(rot);
1153 return std::map<int32_t, AnimationPtr>();
1236 throw NotFound(std::string(
"action ") + actionName +
" not found");
1237 }
else if (create) {
1245 action->adoptVisual(nav);
1262 std::vector<InstanceDeleteListener*>::iterator itor;
1265 if ((*itor) == listener) {
1283 if (*multi_it == instance) {
bool isMultiObject()
Returns true if it is multi object otherwise false.
static InstanceVisual * create(Instance *instance)
Constructs and assigns it to the passed item.
#define FL_WARN(logger, msg)
void callOnVisibleChange()
Instance(Object *object, const Location &location, const std::string &identifier="")
Constructor Instances are created by calling addInstance from layer, thus this method should really b...
void setOccupiedArea(const std::vector< ModelCoordinate > &area)
Sets occupied coordinates for multi cell object.
std::list< std::string > getWalkableAreas() const
Returns a list that contains all walkable area ids.
Timeprovider is an utility providing time management functionality You can have hierarchy of time pro...
void prepareForUpdate()
called to prepare the instance for an update
Action * getAction(const std::string &identifier, bool deepsearch=true) const
Gets action with given id.
void cutPath(uint32_t length=1)
Cuts path after the given length.
std::string getCostId() const
Returns the cost id.
void initializeAction(const std::string &actionName)
Initialize action for use.
std::string getCostId()
Returns cost id.
InstanceActivity * m_activity
void updateMultiInstances()
Updates the visual positions of all instances in case this is a multi object.
int32_t getAngleBetween(const Location &loc1, const Location &loc2)
Gets angle of vector defined by given locations.
IPather * getPather() const
Gets associated pather.
void setLayerCoordinates(const ModelCoordinate &coordinates)
Sets "cell precise" layer coordinates to this location.
void setObject(Object *obj)
Sets the object, needed for multi cell and z-step range.
void follow(const std::string &actionName, Instance *leader, const double speed)
Performs given named action to the instance.
std::vector< ModelCoordinate > getMultiObjectCoordinates(int32_t rotation) const
Returns all multi object coordinates for the given rotation.
void setMultiplier(float multiplier)
With multiplier, you can adjust the time speed.
uint32_t getTime() const
Get the time.
InstanceActivity(Instance &source)
Action * m_action
action on previous round. NOTE: might become invalid, only used for address comparison ...
void setActionAudio(ActionAudio *audio)
Sets the ActionAudio.
double getSpeed() const
Returns the speed modifier.
void createOwnObject()
Creates an own object for the instance to allow visual customization.
void setExactLayerCoordinates(const ExactModelCoordinate &coordinates)
Sets precise layer coordinates to this location.
void addActionListener(InstanceActionListener *listener)
Adds new instance action listener.
void cancelAction()
Cancel current action.
double getMovementSpeed() const
Gets the speed in case instance is moving otherwise returns 0.
bool m_ownObject
indicates if m_object is customized
const Location & getPreviousNode()
Returns previous location.
Layer * getLayer() const
Gets the layer where this location is pointing to.
void adoptVisual(IVisual *visual)
Sets visualization to be used.
virtual bool solveRoute(Route *route, int32_t priority=MEDIUM_PRIORITY, bool immediate=false)=0
Solves the route to create a path.
void initializeChanges()
called when instance has been changed. Causes instance to create InstanceActivity ...
Helper class to create log strings out from separate parts Usage: LMsg("some text") << variable << "...
Interface class between Instance / ActionAudio and SoundEmitter.
void setId(const std::string &identifier="")
Set the identifier for this instance.
uint32_t m_action_offset_time
void addDeleteListener(InstanceDeleteListener *listener)
Adds new instance delete listener.
void addAnimationOverlay(const std::string &actionName, uint32_t angle, int32_t order, const AnimationPtr &animationptr)
Adds new animation overlay with given angle (degrees) and order to given action.
void callOnActionFrame(Action *action, int32_t frame)
Auxiliary function to inform ActionListeners about the active ActionFrame.
ActionAudio * getAudio() const
Gets used audio.
void setLayer(Layer *layer)
Sets layer where this location is pointing to.
void convertToOverlays(bool color)
Convertes animations and optional color overlay to default animation overlay.
uint32_t m_action_start_time
bool m_blocking
blocking status on previous round
bool isAnimationOverlay(const std::string &actionName)
Indicates if there exists a animation overlay for given action.
bool isColorOverlay(const std::string &actionName)
Indicates if there exists a color overlay for given action or animation overlay.
bool isSpecialSpeed()
Returns true if instance or object have special speed modifier otherwise false.
SoundSource * m_soundSource
sound source of action audio on previous round
void setMainMultiInstance(Instance *main)
Sets a instance to the main multi instance of this instance.
void setFacingLocation(const Location &loc)
Sets the direction where instance is heading.
void setMapCoordinates(const ExactModelCoordinate &coordinates)
Sets map coordinates to this location.
Action visual contains data that is needed to visualize different actions on screen.
std::vector< InstanceDeleteListener * > m_deleteListeners
listeners for deletion of the instance
InstanceChangeInfo getChangeInfo()
Returns a bitmask of changes of the last update.
const Location & getEndNode()
Returns the target location.
bool m_blocking
instance blocking info
void removeAnimationOverlay(uint32_t angle, int32_t order)
Removes animation overlay with given angle (degrees) and order.
void removeAnimationOverlay(const std::string &actionName, uint32_t angle, int32_t order)
Removes animation overlay with given angle (degrees) and order from action.
Instance * createInstance(Object *object, const ModelCoordinate &p, const std::string &id="")
Add an instance of an object at a specific position.
uint32_t getPathLength()
Returns the length of the path.
bool isActive() const
If this returns true, the instance needs to be updated.
static Logger _log(LM_AUDIO)
void cancelMovement(uint32_t length=1)
Cancel movement after a given length.
Location m_location
current location
uint32_t getActionRuntime()
Gets the time in milliseconds how long action has been active In case there is no current action...
ActionVisual * getActionVisual(const std::string &actionName, bool create)
Returns pointer to action visual, can also create it.
void setActionRuntime(uint32_t time_offset)
Sets the time in milliseconds how long an action has been active This was requested in Ticket #373...
void removeStaticColorOverlay(int32_t angle)
Removes a static color overlay with given angle (degrees).
std::string m_sayText
say text on previous round
bool isSpecialCost()
Returns true if instance or object have special cost otherwise false.
const std::string & getId() const
static TimeManager * instance()
Location & getLocationRef()
Gets reference of current location of instance.
void callOnTransparencyChange()
uint32_t m_prev_call_time
OverlayColors * getStaticColorOverlay(int32_t angle)
Returns closest matching static color overlay for given angle.
float getTotalMultiplier() const
void update(Instance &source)
updates cached variables, marks changes
double getCost() const
Returns the cost.
void convertToOverlays(const std::string &actionName, bool color)
If the action have base animation and optional color overlay it gets converted to animation overlay...
void removeDeleteListener(InstanceDeleteListener *listener)
Removes associated instance delete listener.
const std::string * getSayText() const
Returns pointer to currently set saytext.
OverlayColors * getStaticColorOverlay(int32_t angle)
Returns closest matching static color overlay for given angle.
ActionInfo(IPather *pather, const Location &curloc)
void addChangeListener(InstanceChangeListener *listener)
Adds new instance change listener.
OverlayColors * getColorOverlay(int32_t angle)
Gets OverlayColors for given angle (degrees).
double m_speed
speed on previous round
IVisual * m_visual
instance visualization
void setRotation(int32_t rotation)
Sets the current rotation.
int32_t m_rotation
The rotation offset of this instance.
void removeColorOverlay(int32_t angle)
Removes color overlay with given angle (degrees).
void setStartNode(const Location &node)
Sets the start location.
void setOverrideBlocking(bool overblock)
Sets if instance blocking can overriden.
uint32_t getGameTime() const
Returns current game ticks, already scaled.
const std::vector< Instance * > & getMultiInstances()
Returns a vector that contains all instances of a multi object.
static bool Equal(T _val1, T _val2)
Location getTargetLocation() const
Gets movement target in case instance is moving.
Instance * m_mainMultiInstance
pointer to the main multi instance
std::vector< InstanceActionListener * > m_actionListeners
listeners for action related events
void addColorOverlay(uint32_t angle, const OverlayColors &colors)
Adds new color overlay with given angle (degrees) and colors.
double getLayerDistanceTo(const Location &location) const
Gets layer distance to another location.
Object * getObject()
Gets object where this instance is instantiated from.
std::vector< InstanceChangeListener * > m_changeListeners
listeners for changes
uint32_t InstanceChangeInfo
float m_timeMultiplier
time multiplier on previous round
void callOnStackPositionChange()
const std::string & getNamespace() const
void addAnimationOverlay(uint32_t angle, int32_t order, AnimationPtr animationptr)
Adds new animation overlay with given angle (degrees) and order.
int32_t getSessionId()
Returns the session identifier.
Location & getOldLocationRef()
Gets reference of old location of instance.
OverlayColors * getColorOverlay(const std::string &actionName, uint32_t angle)
Returns closest matching color overlay for given angle and action.
Location getFacingLocation()
Returns the direction where instance is heading.
void setCostId(const std::string &cost)
Sets cost identifier which should be used for pathfinding.
void removeStaticColorOverlay(int32_t angle)
Removes a static color overlay with given angle (degrees).
void addInstanceForTransfer(Instance *instance, const Location &target)
Adds instance that is to be transferred to another layer.
void addColorOverlay(const std::string &actionName, uint32_t angle, const OverlayColors &colors)
Adds new color overlay with given angle (degrees) to given action.
void setTimeMultiplier(float multip)
Sets speed for the map.
bool isRestrictedRotation() const
Gets if object uses restricted rotations.
void removeChangeListener(InstanceChangeListener *listener)
Removes associated instance change listener.
RouteStatusInfo getRouteStatus()
Returns route status.
bool isColorOverlay()
Indicates if there exists a color overlay.
uint8_t getCellStackPosition()
Gets the cell stack position.
void addStaticColorOverlay(uint32_t angle, const OverlayColors &colors)
Adds new static color overlay with given angle (degrees).
Instance * getMainMultiInstance()
Returns a pointer to the main mulit instance or Null if the instance is not part of a multi instance ...
void onInstanceDeleted(Instance *instance)
callback so other instances we depend on can notify us if they go away
void removeInstance(Instance *instance)
Removes an instance from the quad tree.
bool isStaticColorOverlay()
Indicates if there exists a static color overlay.
InstanceActivity gets allocated in case there is some runtime activity related to the instance...
ExactModelCoordinate & getExactLayerCoordinatesRef()
Gets reference to exact layer coordinates.
Location m_location
location on previous round
void setReplanned(bool replanned)
Sets the route to replanned.
bool isMultiObject() const
Gets if object uses special cost.
void bindTimeProvider()
rebinds time provider based on new location
void addInstance(Instance *instance)
Adds an instance to the quad tree.
ExactModelCoordinate getRotationAnchor() const
Returns the rotation anchor for this multi object.
virtual bool cancelSession(const int32_t sessionId)=0
Cancels a given session.
void setBlocking(bool blocking)
Sets if instance blocks movement.
Action * createAction(const std::string &identifier, bool is_default=false)
Adds new action with given id.
InstanceChangeInfo m_additional
additional change info, used for visual class (transparency, visible, stackpos)
void finalizeAction()
Finalize current action.
Action * getCurrentAction() const
Gets the currently active action.
ActionInfo * m_actionInfo
action information, allocated when actions are bind
void setCellStackPosition(uint8_t stack)
Sets the cell stack position.
double m_cost
holds cost value
TimeProvider * m_timeProvider
time scaler for this instance
SayInfo * m_sayInfo
text to say + duration, allocated when something is said
Object visual contains data that is needed for visualizing objects.
virtual bool followRoute(const Location ¤t, Route *route, double speed, Location &nextLocation)=0
Follows the path of the route.
InstanceTree * getInstanceTree(void) const
Get the instance tree.
CellGrid * getCellGrid() const
Get the Cellgrid.
void actOnce(const std::string &actionName, const Location &direction)
Performs given named action to the instance, once only.
InstanceChangeInfo m_changeInfo
bitmask stating current changes
static ObjectVisual * create(Object *object)
Constructs and assigns it to the passed item.
SayInfo(const std::string &txt, uint32_t duration)
bool m_specialCost
indicates special cost
int32_t getOldRotation() const
Get the old rotation offset of this instance Returns direction where instance was heading...
float getMultiplier() const
std::string m_costId
holds cost id
Action * getDefaultAction() const
Gets default action assigned to this object.
std::vector< Instance * > m_multiInstances
vector that holds all multi instances
double getCost()
Returns cost value.
float getTotalTimeMultiplier()
Gets instance speed, considering also model and map speeds.
int32_t getZStepRange() const
Returns z-step range from object.
void addStaticColorOverlay(uint32_t angle, const OverlayColors &colors)
Adds new static color overlay with given angle (degrees).
void removeColorOverlay(const std::string &actionName, int32_t angle)
Removes a color overlay with given angle (degrees) from given action.
float getTimeMultiplier()
Gets instance speed.
void resetCost()
Resets cost.
const std::string & getCostId()
Returns cost identifier which is used for pathfinding.
void actRepeat(const std::string &actionName, const Location &direction)
Performs given named action to the instance, repeated.
InstanceChangeInfo update()
Updates the instance related to the current action.
const std::string & getId()
Get the identifier for this instance; possibly null.
Location m_oldLocation
location on previous cell
uint32_t getDuration()
Gets the duration of this action.
void setRotation(int32_t rotation)
Set the rotation offset of this instance.
void removeActionListener(InstanceActionListener *listener)
Removes associated instance action listener.
ExactModelCoordinate getMapCoordinates() const
Gets map coordinates set to this location.
ModelCoordinate getLayerCoordinates() const
Gets cell precision layer coordinates set to this location.
TimeProvider * getTimeProvider()
Gets timeprovider used in the map.
const Location & getCurrentNode()
Returns current location.
virtual ~Instance()
Destructor.
void setEndNode(const Location &node)
Sets the target location.
uint32_t getRuntime()
Gets the scaled runtime in milliseconds.
Map * getMap() const
Get the map this layer is contained in.
Route * getRoute()
Returns a pointer to the route, in case there is no, it returns NULL.
bool isBlocking() const
Gets if instance blocks movement.
void refresh()
Refreshes instance e.g.
int32_t getRotation()
Returns the current rotation.
std::map< int32_t, AnimationPtr > getAnimationOverlay(const std::string &actionName, int32_t angle)
Gets map with animations closest to given angle.
void setInstanceActivityStatus(Instance *instance, bool active)
Sets the activity status for given instance on this layer.
T * getVisual() const
Gets used visualization.
bool isSpecialSpeed() const
Gets if object uses special speed modifier.
void move(const std::string &actionName, const Location &target, const double speed, const std::string &costId="")
Performs given named action to the instance.
T * getVisual() const
Gets used visualization.
Object * m_object
object where instantiated from
bool isMultiCell()
Returns true if it is multi cell otherwise false.
Location getFacing(const Location &loc, const int32_t angle)
Gets facing location defined by given angle and location.
int32_t getRestrictedRotation(int32_t rotation)
Returns the most obvious rotation, based on multi coordinates.
bool isReplanned()
Gets if the route is replanned.
uint8_t m_cellStackPos
position on cell stack
int32_t m_rotation
rotation on previous round
void setLocation(const Location &loc)
Sets location of the instance.
#define FL_DBG(logger, msg)
int32_t getRotation() const
Get the rotation offset of this instance Returns direction where instance is heading.
An Instance is an "instantiation" of an Object at a Location.
bool processMovement()
Moves instance. Returns true if finished.
bool m_overrideBlocking
allow to override the blocking property
std::map< int32_t, AnimationPtr > getAnimationOverlay(int32_t angle)
Gets map with animations closest to given angle.
bool isMultiPart() const
Gets if object is a part of a multi object.
bool isAnimationOverlay()
Returns true if it exists a animation overlay, otherwise false.
bool isColorOverlay()
Returns true if it exists a color overlay, otherwise false.
bool isOverrideBlocking() const
Gets if instance blocking can overriden.
void setCost(const std::string &id, double cost)
Sets for the given cost id a cost.
double getSpeed()
Returns speed modifier.
Location getLocation() const
Gets current location of instance.
int32_t m_oldRotation
rotation on previous round
void say(const std::string &text, uint32_t duration=0)
Causes instance to "say" given text (shown on screen next to the instance)