69 if (sessionId != -1) {
117 m_location(source.m_location),
118 m_oldLocation(source.m_location),
119 m_rotation(source.m_rotation),
120 m_oldRotation(source.m_rotation),
123 m_timeMultiplier(1.0),
129 m_timeProvider(NULL),
130 m_blocking(source.m_blocking),
137 delete m_timeProvider;
160 if (m_actionInfo && (m_speed != m_actionInfo->m_speed)) {
162 m_speed = m_actionInfo->m_speed;
164 if (m_actionInfo && (m_action != m_actionInfo->m_action)) {
166 m_action = m_actionInfo->m_action;
168 if (m_timeProvider && (m_timeMultiplier != m_timeProvider->getMultiplier())) {
170 m_timeMultiplier = m_timeProvider->getMultiplier();
172 if (m_sayInfo && (m_sayText != m_sayInfo->m_txt)) {
174 m_sayText = m_sayInfo->m_txt;
182 std::vector<InstanceChangeListener*>::iterator i = m_changeListeners.begin();
183 while (i != m_changeListeners.end()) {
191 m_changeListeners.erase(
192 std::remove(m_changeListeners.begin(),m_changeListeners.end(),
194 m_changeListeners.end());
220 const std::set<Object*>& multis =
object->getMultiParts();
221 std::set<Object*>::const_iterator it = multis.begin();
222 for (; it != multis.end(); ++it, ++count) {
226 std::vector<ModelCoordinate> partcoords = (*it)->getMultiPartCoordinates(
m_rotation);
227 std::vector<ModelCoordinate>::iterator coordit = partcoords.begin();
228 for (; coordit != partcoords.end(); ++coordit) {
230 std::ostringstream counter;
242 std::vector<InstanceDeleteListener *>::iterator itor;
245 (*itor)->onInstanceDeleted(
this);
259 (*it)->removeDeleteListener(
this);
312 while (rotation < 0) {
373 if ((*i) == listener) {
395 (*i)->onInstanceActionFrame(
this, action, frame);
407 if ((*i) == listener) {
430 throw NotFound(std::string(
"action ") + actionName +
" not found");
439 (*multi_it)->initializeAction(actionName);
444 void Instance::move(
const std::string& actionName,
const Location& target,
const double speed,
const std::string& costId) {
462 FL_DBG(
_log,
LMsg(
"starting action ") << actionName <<
" from" <<
m_location <<
" to " << target <<
" with speed " << speed);
579 void Instance::act(
const std::string& actionName, int32_t rotation,
bool repeating) {
659 double distance_to_travel = (
static_cast<double>(timedelta) / 1000.0) * info->
m_speed;
739 if (movement_finished) {
793 (*i)->onInstanceActionFinished(
this, action);
805 (*multi_it)->finalizeAction();
867 float multiplier = 1.0;
1018 std::vector<ModelCoordinate> mcv = (*it)->getObject()->getMultiPartCoordinates(0);
1022 emc.
x = ((nemc.
x * mcos + nemc.
y * msin) + anchor_offset.
x) + anchor.
x;
1023 emc.
y = ((-nemc.
x * msin + nemc.
y * mcos) + anchor_offset.
y) + anchor.
y;
1025 (*it)->setLocation(loc);
1026 (*it)->setRotation(rot);
1037 std::vector<InstanceDeleteListener*>::iterator itor;
1040 if ((*itor) == listener) {
1058 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...
Map * getMap() const
Get the map this layer is contained in.
void cutPath(uint32_t length=1)
Cuts path after the given length.
IPather * getPather() const
Gets associated pather.
void initializeAction(const std::string &actionName)
Initialize action for use.
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)
VisitorShapeInfo m_visitorShape
visitor shape type
void setExactLayerCoordinates(const ExactModelCoordinate &coordinates)
Sets precise layer coordinates to this location.
void addActionListener(InstanceActionListener *listener)
Adds new instance action listener.
const Location & getPreviousNode()
Returns previous location.
const std::string & getCostId()
Returns cost id.
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 << "...
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 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.
uint32_t m_action_start_time
bool isBlocking() const
Gets if instance blocks movement.
void setFacingLocation(const Location &loc)
Sets the direction where instance is heading.
void setMapCoordinates(const ExactModelCoordinate &coordinates)
Sets map coordinates to this location.
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
InstanceChangeInfo getChangeInfo()
Returns a bitmask of changes of the last update.
const Location & getEndNode()
Returns the target location.
bool m_blocking
instance blocking info
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...
bool isMultiPart() const
Gets if object is a part of a multi object.
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.
InstanceTree * getInstanceTree(void) const
Get the instance tree.
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.
void update(Instance &source)
updates cached variables, marks changes
void removeDeleteListener(InstanceDeleteListener *listener)
Removes associated instance delete listener.
ActionInfo(IPather *pather, const Location &curloc)
uint16_t m_visitorRadius
visitor radius (FoW)
void addChangeListener(InstanceChangeListener *listener)
Adds new instance change listener.
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 setStartNode(const Location &node)
Sets the start location.
void setOverrideBlocking(bool overblock)
Sets if instance blocking can overriden.
const std::string & getCostId() const
Returns the cost id.
const std::vector< Instance * > & getMultiInstances()
Returns a vector that contains all instances of a multi object.
static bool Equal(T _val1, T _val2)
std::vector< InstanceActionListener * > m_actionListeners
listeners for action related events
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.
int32_t getSessionId()
Returns the session identifier.
Location & getOldLocationRef()
Gets reference of old location of instance.
Location getFacingLocation()
Returns the direction where instance is heading.
void setCostId(const std::string &cost)
Sets cost identifier which should be used for pathfinding.
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 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.
uint8_t getCellStackPosition()
Gets the cell stack position.
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.
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.
void act(const std::string &actionName, const Location &direction, bool repeating=false)
Performs given named action to the instance.
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.
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
SayInfo * m_sayInfo
text to say + duration, allocated when something is said
VisitorShapeInfo getVisitorShape()
Gets the shape type for a visitor.
const std::list< std::string > & getWalkableAreas() const
Returns a list that contains all walkable area ids.
virtual bool followRoute(const Location ¤t, Route *route, double speed, Location &nextLocation)=0
Follows the path of the route.
InstanceChangeInfo m_changeInfo
bitmask stating current changes
SayInfo(const std::string &txt, uint32_t duration)
bool m_specialCost
indicates special cost
std::vector< ModelCoordinate > getMultiObjectCoordinates(int32_t rotation)
Returns all multi object coordinates for the given rotation.
Action * getAction(const std::string &identifier) const
Gets action with given id.
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.
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.
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.
int32_t getRotation()
Returns the current rotation.
void setInstanceActivityStatus(Instance *instance, bool active)
Sets the activity status for given instance on this layer.
const ExactModelCoordinate & getRotationAnchor() const
Returns the rotation anchor for this multi object.
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
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 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
ExactModelCoordinate getMapCoordinates() const
Gets map coordinates set to this location.
void setCost(const std::string &id, double cost)
Sets for the given cost id a cost.
void setSessionId(int32_t id)
Sets the session identifier.
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.