69 if (sessionId != -1) {
113 m_location(source.m_location),
114 m_oldLocation(source.m_location),
115 m_rotation(source.m_rotation),
116 m_oldRotation(source.m_rotation),
119 m_timeMultiplier(1.0),
125 m_timeProvider(NULL),
126 m_blocking(source.m_blocking),
133 delete m_timeProvider;
156 if (m_actionInfo && (m_speed != m_actionInfo->m_speed)) {
158 m_speed = m_actionInfo->m_speed;
160 if (m_actionInfo && (m_action != m_actionInfo->m_action)) {
162 m_action = m_actionInfo->m_action;
164 if (m_timeProvider && (m_timeMultiplier != m_timeProvider->getMultiplier())) {
166 m_timeMultiplier = m_timeProvider->getMultiplier();
168 if (m_sayInfo && (m_sayText != m_sayInfo->m_txt)) {
170 m_sayText = m_sayInfo->m_txt;
178 std::vector<InstanceChangeListener*>::iterator i = m_changeListeners.begin();
179 while (i != m_changeListeners.end()) {
187 m_changeListeners.erase(
188 std::remove(m_changeListeners.begin(),m_changeListeners.end(),
190 m_changeListeners.end());
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");
437 (*multi_it)->initializeAction(actionName);
442 void Instance::move(
const std::string& actionName,
const Location& target,
const double speed,
const std::string& costId) {
460 FL_DBG(
_log,
LMsg(
"starting action ") << actionName <<
" from" <<
m_location <<
" to " << target <<
" with speed " << speed);
682 double distance_to_travel = (
static_cast<double>(timedelta) / 1000.0) * info->
m_speed;
762 if (movement_finished) {
819 (*multi_it)->finalizeAction();
825 (*i)->onInstanceActionFinished(
this, action);
854 (*multi_it)->cancelAction();
860 (*i)->onInstanceActionCancelled(
this, action);
927 float multiplier = 1.0;
1074 std::vector<ModelCoordinate> mcv = (*it)->getObject()->getMultiPartCoordinates(0);
1078 emc.
x = ((nemc.
x * mcos + nemc.
y * msin) + anchor_offset.
x) + anchor.
x;
1079 emc.
y = ((-nemc.
x * msin + nemc.
y * mcos) + anchor_offset.
y) + anchor.
y;
1081 (*it)->setLocation(loc);
1082 (*it)->setRotation(rot);
1162 return std::map<int32_t, AnimationPtr>();
1245 throw NotFound(std::string(
"action ") + actionName +
" not found");
1246 }
else if (create) {
1254 action->adoptVisual(nav);
1271 std::vector<InstanceDeleteListener*>::iterator itor;
1274 if ((*itor) == listener) {
1292 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.
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
Map * getMap() const
Get the map this layer is contained in.
void cutPath(uint32_t length=1)
Cuts path after the given length.
void initializeAction(const std::string &actionName)
Initialize action for use.
std::string getCostId()
Returns cost id.
double getCost() const
Returns the cost.
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.
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.
void setMultiplier(float multiplier)
With multiplier, you can adjust the time speed.
InstanceActivity(Instance &source)
bool m_isVisitor
is instance a visitor (FoW)
Action * m_action
action on previous round. : might become invalid, only used for address comparison ...
void createOwnObject()
Creates an own object for the instance to allow visual customization.
VisitorShapeInfo m_visitorShape
visitor shape type
void setExactLayerCoordinates(const ExactModelCoordinate &coordinates)
Sets precise layer coordinates to this location.
const std::string & getNamespace() const
void addActionListener(InstanceActionListener *listener)
Adds new instance action listener.
void cancelAction()
Cancel current action.
bool m_ownObject
indicates if m_object is customized
const Location & getPreviousNode()
Returns previous location.
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 << "...
T * getVisual() const
Gets used visualization.
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.
bool isActive() const
If this returns true, the instance needs to be updated.
void convertToOverlays(bool color)
Convertes animations and optional color overlay to default animation overlay.
uint32_t m_action_start_time
bool isAnimationOverlay(const std::string &actionName)
Indicates if there exists a animation overlay for given action.
bool isBlocking() const
Gets if instance blocks movement.
bool isColorOverlay(const std::string &actionName)
Indicates if there exists a color overlay for given action or animation overlay.
const std::string & getId() const
bool isSpecialSpeed()
Returns true if instance or object have special speed modifier otherwise false.
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.
bool isMultiObject() const
Gets if object uses special cost.
Location getTargetLocation() const
Gets movement target in case instance is moving.
std::vector< InstanceDeleteListener * > m_deleteListeners
listeners for deletion of the instance
IPather * getPather() const
Gets associated pather.
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.
static Logger _log(LM_AUDIO)
void setVisitorRadius(uint16_t radius)
Sets the range for a visitor.
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...
std::string getCostId() const
Returns the cost id.
bool isMultiPart() const
Gets if object is a part of a multi object.
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...
Action * getCurrentAction() const
Gets the currently active action.
void removeStaticColorOverlay(int32_t angle)
Removes a static color overlay with given angle (degrees).
InstanceTree * getInstanceTree(void) const
Get the instance tree.
std::list< std::string > getWalkableAreas() const
Returns a list that contains all walkable area ids.
Layer * getLayer() const
Gets the layer where this location is pointing to.
bool isSpecialCost()
Returns true if instance or object have special cost otherwise false.
static TimeManager * instance()
Location & getLocationRef()
Gets reference of current location of instance.
ModelCoordinate getLayerCoordinates() const
Gets cell precision layer coordinates set to this location.
void callOnTransparencyChange()
uint32_t m_prev_call_time
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.
void update(Instance &source)
updates cached variables, marks changes
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.
OverlayColors * getStaticColorOverlay(int32_t angle)
Returns closest matching static color overlay for given angle.
ActionInfo(IPather *pather, const Location &curloc)
uint16_t m_visitorRadius
visitor radius (FoW)
void addChangeListener(InstanceChangeListener *listener)
Adds new instance change listener.
OverlayColors * getColorOverlay(int32_t angle)
Gets OverlayColors for given angle (degrees).
IVisual * m_visual
instance visualization
void setRotation(int32_t rotation)
Sets the current rotation.
int32_t m_rotation
The rotation offset of this instance.
uint32_t getTime() const
Get the time.
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.
const std::vector< Instance * > & getMultiInstances()
Returns a vector that contains all instances of a multi object.
static bool Equal(T _val1, T _val2)
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.
T * getVisual() const
Gets used visualization.
Object * getObject()
Gets object where this instance is instantiated from.
std::vector< InstanceChangeListener * > m_changeListeners
listeners for changes
float getMultiplier() const
uint32_t InstanceChangeInfo
void callOnStackPositionChange()
int32_t getRotation() const
Get the rotation offset of this instance Returns direction where instance is heading.
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).
uint32_t getGameTime() const
Returns current game ticks, already scaled.
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.
Location getLocation() const
Gets current location of instance.
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 isRestrictedRotation() const
Gets if object uses restricted rotations.
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.
CellGrid * getCellGrid() const
Get the Cellgrid.
void setReplanned(bool replanned)
Sets the route to replanned.
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.
double getMovementSpeed() const
Gets the speed in case instance is moving otherwise returns 0.
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.
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
std::vector< ModelCoordinate > getMultiObjectCoordinates(int32_t rotation) const
Returns all multi object coordinates for the given rotation.
SayInfo * m_sayInfo
text to say + duration, allocated when something is said
VisitorShapeInfo getVisitorShape()
Gets the shape type for a visitor.
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.
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
std::string m_costId
holds cost id
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.
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.
bool isOverrideBlocking() const
Gets if instance blocking can overriden.
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.
int32_t getOldRotation() const
Get the old rotation offset of this instance Returns direction where instance was heading...
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.
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.
Route * getRoute()
Returns a pointer to the route, in case there is no, it returns NULL.
int32_t getZStepRange() const
Returns z-step range from object.
void refresh()
Refreshes instance e.g.
Action * getAction(const std::string &identifier, bool deepsearch=true) const
Gets action with given id.
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.
double getSpeed() const
Returns the 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.
float getTotalMultiplier() const
Object * m_object
object where instantiated from
Action * getDefaultAction() const
Gets default action assigned to this object.
uint16_t getVisitorRadius()
Gets the visitor range.
bool isVisitor()
If instance is a visitor it returns true otherwise false.
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 isSpecialSpeed() const
Gets if object uses special speed modifier.
bool isReplanned()
Gets if the route is replanned.
double getLayerDistanceTo(const Location &location) const
Gets layer distance to another location.
uint8_t m_cellStackPos
position on cell stack
void setLocation(const Location &loc)
Sets location of the instance.
#define FL_DBG(logger, msg)
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.
ExactModelCoordinate getMapCoordinates() const
Gets map coordinates set to this location.
bool isAnimationOverlay()
Returns true if it exists a animation overlay, otherwise false.
bool isColorOverlay()
Returns true if it exists a color overlay, otherwise false.
void setCost(const std::string &id, double cost)
Sets for the given cost id a cost.
double getSpeed()
Returns speed modifier.
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)
void setVisitor(bool visit)
Marks this instance as a visitor.
void setVisitorShape(VisitorShapeInfo info)
Sets the shape type for a visitor.