FIFE
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
instance.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005-2013 by the FIFE team *
3  * http://www.fifengine.net *
4  * This file is part of FIFE. *
5  * *
6  * FIFE is free software; you can redistribute it and/or *
7  * modify it under the terms of the GNU Lesser General Public *
8  * License as published by the Free Software Foundation; either *
9  * version 2.1 of the License, or (at your option) any later version. *
10  * *
11  * This library is distributed in the hope that it will be useful, *
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
14  * Lesser General Public License for more details. *
15  * *
16  * You should have received a copy of the GNU Lesser General Public *
17  * License along with this library; if not, write to the *
18  * Free Software Foundation, Inc., *
19  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA *
20  ***************************************************************************/
21 
22 // Standard C++ library includes
23 #include <iostream>
24 
25 // 3rd party library includes
26 #include <SDL.h>
27 
28 // FIFE includes
29 // These includes are split up in two parts, separated by one empty line
30 // First block: files included from the FIFE root src directory
31 // Second block: files included from the same folder
32 #include "util/log/logger.h"
33 #include "util/base/exception.h"
34 #include "util/math/fife_math.h"
35 #include "util/time/timemanager.h"
38 #include "model/metamodel/action.h"
40 #include "model/structures/layer.h"
41 #include "model/structures/map.h"
43 #include "view/visual.h"
44 #include "pathfinder/route.h"
45 
46 #include "instance.h"
47 
48 namespace FIFE {
49  static Logger _log(LM_INSTANCE);
50 
51  class ActionInfo {
52  public:
53  ActionInfo(IPather* pather, const Location& curloc):
54  m_action(NULL),
55  m_target(NULL),
56  m_speed(0),
57  m_repeating(false),
61  m_pather(pather),
62  m_leader(NULL),
63  m_route(NULL),
64  m_delete_route(true) {}
65 
67  if (m_route && m_delete_route) {
68  int32_t sessionId = m_route->getSessionId();
69  if (sessionId != -1) {
70  m_pather->cancelSession(sessionId);
71  }
72  delete m_route;
73  }
74  delete m_target;
75  }
76 
77  // Current action, owned by object
79  // target location for ongoing movement
81  // current movement speed
82  double m_speed;
83  // should action be repeated? used only for non-moving actions, moving ones repeat until movement is finished
85  // action start time (ticks)
87  // action offset time (ticks) for resuming an action
89  // ticks since last call
91  // pather
93  // leader for follow activity
95  // pointer to route that contain path and additional information
98  };
99 
100  class SayInfo {
101  public:
102  SayInfo(const std::string& txt, uint32_t duration):
103  m_txt(txt),
104  m_duration(duration),
105  m_start_time(0) {}
106 
107  std::string m_txt;
110  };
111 
113  m_location(source.m_location),
114  m_oldLocation(source.m_location),
115  m_rotation(source.m_rotation),
116  m_oldRotation(source.m_rotation),
117  m_action(),
118  m_speed(0),
119  m_timeMultiplier(1.0),
120  m_sayText(""),
121  m_changeListeners(),
122  m_actionListeners(),
123  m_actionInfo(NULL),
124  m_sayInfo(NULL),
125  m_timeProvider(NULL),
126  m_blocking(source.m_blocking),
127  m_additional(ICHANGE_NO_CHANGES) {
128  }
129 
131  delete m_actionInfo;
132  delete m_sayInfo;
133  delete m_timeProvider;
134  }
135 
138  if (m_additional != ICHANGE_NO_CHANGES) {
139  source.m_changeInfo = m_additional;
140  m_additional = ICHANGE_NO_CHANGES;
141  }
142  if (m_location != source.m_location) {
143  source.m_changeInfo |= ICHANGE_LOC;
145  m_oldLocation.setLayer(m_location.getLayer());
146  m_oldLocation.setLayerCoordinates(m_location.getLayerCoordinates());
147  source.m_changeInfo |= ICHANGE_CELL;
148  }
149  m_location = source.m_location;
150  }
151  if (m_rotation != source.m_rotation) {
152  m_oldRotation = m_rotation;
153  source.m_changeInfo |= ICHANGE_ROTATION;
154  m_rotation = source.m_rotation;
155  }
156  if (m_actionInfo && (m_speed != m_actionInfo->m_speed)) {
157  source.m_changeInfo |= ICHANGE_SPEED;
158  m_speed = m_actionInfo->m_speed;
159  }
160  if (m_actionInfo && (m_action != m_actionInfo->m_action)) {
161  source.m_changeInfo |= ICHANGE_ACTION;
162  m_action = m_actionInfo->m_action;
163  }
164  if (m_timeProvider && (m_timeMultiplier != m_timeProvider->getMultiplier())) {
166  m_timeMultiplier = m_timeProvider->getMultiplier();
167  }
168  if (m_sayInfo && (m_sayText != m_sayInfo->m_txt)) {
169  source.m_changeInfo |= ICHANGE_SAYTEXT;
170  m_sayText = m_sayInfo->m_txt;
171  }
172  if (m_blocking != source.m_blocking) {
173  source.m_changeInfo |= ICHANGE_BLOCK;
174  m_blocking = source.m_blocking;
175  }
176 
177  if (source.m_changeInfo != ICHANGE_NO_CHANGES) {
178  std::vector<InstanceChangeListener*>::iterator i = m_changeListeners.begin();
179  while (i != m_changeListeners.end()) {
180  if (NULL != *i)
181  {
182  (*i)->onInstanceChanged(&source, source.m_changeInfo);
183  }
184  ++i;
185  }
186  // Really remove "removed" listeners.
187  m_changeListeners.erase(
188  std::remove(m_changeListeners.begin(),m_changeListeners.end(),
189  (InstanceChangeListener*)NULL),
190  m_changeListeners.end());
191  }
192  }
193 
194  Instance::Instance(Object* object, const Location& location, const std::string& identifier):
195  m_id(identifier),
196  m_rotation(0),
197  m_activity(NULL),
199  m_object(object),
200  m_ownObject(false),
201  m_location(location),
202  m_visual(NULL),
203  m_blocking(object->isBlocking()),
204  m_overrideBlocking(false),
205  m_isVisitor(false),
207  m_visitorRadius(0),
209  m_specialCost(object->isSpecialCost()),
210  m_cost(object->getCost()),
211  m_costId(object->getCostId()),
212  m_mainMultiInstance(NULL) {
213  // create multi object instances
214  if (object->isMultiObject()) {
215  m_mainMultiInstance = this;
216  uint32_t count = 0;
217  Layer* layer = m_location.getLayer();
219  const std::set<Object*>& multis = object->getMultiParts();
220  std::set<Object*>::const_iterator it = multis.begin();
221  for (; it != multis.end(); ++it, ++count) {
222  if (*it == m_object) {
223  continue;
224  }
225  std::vector<ModelCoordinate> partcoords = (*it)->getMultiPartCoordinates(m_rotation);
226  std::vector<ModelCoordinate>::iterator coordit = partcoords.begin();
227  for (; coordit != partcoords.end(); ++coordit) {
228  ExactModelCoordinate tmp_emc(emc.x+(*coordit).x, emc.y+(*coordit).y, emc.z+(*coordit).z);
229  std::ostringstream counter;
230  counter << count;
231  Instance* instance = layer->createInstance(*it, tmp_emc, identifier+counter.str());
232  InstanceVisual::create(instance);
233  m_multiInstances.push_back(instance);
234  instance->addDeleteListener(this);
235  instance->setMainMultiInstance(this);
236  }
237  }
238  }
239  }
240 
242  std::vector<InstanceDeleteListener *>::iterator itor;
243  for(itor = m_deleteListeners.begin(); itor != m_deleteListeners.end(); ++itor) {
244  if (*itor != NULL) {
245  (*itor)->onInstanceDeleted(this);
246  }
247  }
248 
250  // Don't ditribute onActionFinished in case we're already
251  // deleting.
252  m_activity->m_actionListeners.clear();
253  finalizeAction();
254  }
255 
256  if (!m_multiInstances.empty()) {
257  std::vector<Instance*>::iterator it = m_multiInstances.begin();
258  for (; it != m_multiInstances.end(); ++it) {
259  (*it)->removeDeleteListener(this);
260  (*it)->setMainMultiInstance(NULL);
261  }
262  }
263 
264  delete m_activity;
265  delete m_visual;
266  if (m_ownObject) {
267  delete m_object;
268  }
269  }
270 
272  if (!m_activity) {
273  m_activity = new InstanceActivity(*this);
274  }
275  if (m_location.getLayer()) {
277  }
278  }
279 
281  if (isActive()) {
282  refresh();
283  } else {
285  }
286  }
287 
288  bool Instance::isActive() const {
289  return (m_activity != 0);
290  }
291 
293  return m_object;
294  }
295 
296  void Instance::setLocation(const Location& loc) {
297  // ToDo: Handle the case when the layers are different
298  if(m_location != loc) {
300 
303  m_location = loc;
305  } else {
306  m_location = loc;
307  }
308  }
309  }
310 
312  return m_location;
313  }
314 
316  return m_location;
317  }
318 
319  void Instance::setRotation(int32_t rotation) {
320  while (rotation < 0) {
321  rotation += 360;
322  }
323  rotation %= 360;
324  if(m_rotation != rotation) {
326  m_rotation = rotation;
327  }
328  }
329 
330  int32_t Instance::getRotation() const {
331  return m_rotation;
332  }
333 
334  void Instance::setId(const std::string& identifier) {
335  m_id = identifier;
336  }
337 
338  const std::string& Instance::getId() {
339  return m_id;
340  }
341 
342  void Instance::setBlocking(bool blocking) {
343  if (m_overrideBlocking) {
345  m_blocking = blocking;
346  }
347  }
348 
349  bool Instance::isBlocking() const {
350  return m_blocking;
351  }
352 
353  void Instance::setOverrideBlocking(bool overblock) {
354  m_overrideBlocking = overblock;
355  }
356 
358  return m_overrideBlocking;
359  }
360 
363  m_activity->m_actionListeners.push_back(listener);
364  }
365 
367  if (!m_activity) {
368  return;
369  }
370  std::vector<InstanceActionListener*>::iterator i = m_activity->m_actionListeners.begin();
371  while (i != m_activity->m_actionListeners.end()) {
372  if ((*i) == listener) {
373  *i = NULL;
374  return;
375  }
376  ++i;
377  }
378  FL_WARN(_log, "Cannot remove unknown listener");
379  }
380 
383  m_activity->m_changeListeners.push_back(listener);
384  }
385 
386  void Instance::callOnActionFrame(Action* action, int32_t frame) {
387  if (!m_activity) {
388  return;
389  }
390 
391  std::vector<InstanceActionListener*>::iterator i = m_activity->m_actionListeners.begin();
392  while (i != m_activity->m_actionListeners.end()) {
393  if(*i) {
394  (*i)->onInstanceActionFrame(this, action, frame);
395  }
396  ++i;
397  }
398  }
399 
401  if (!m_activity) {
402  return;
403  }
404  std::vector<InstanceChangeListener*>::iterator i = m_activity->m_changeListeners.begin();
405  while (i != m_activity->m_changeListeners.end()) {
406  if ((*i) == listener) {
407  *i = NULL;
408  return;
409  }
410  ++i;
411  }
412  FL_WARN(_log, "Cannot remove unknown listener");
413  }
414 
415  void Instance::initializeAction(const std::string& actionName) {
416  assert(m_object);
417 
419  const Action *old_action = m_activity->m_actionInfo ? m_activity->m_actionInfo->m_action : NULL;
420  if (m_activity->m_actionInfo) {
421  cancelAction();
422  }
426  delete m_activity->m_actionInfo;
427  m_activity->m_actionInfo = NULL;
428  throw NotFound(std::string("action ") + actionName + " not found");
429  }
431  if (m_activity->m_actionInfo->m_action != old_action) {
433  }
434  if (isMultiObject()) {
435  std::vector<Instance*>::iterator multi_it = m_multiInstances.begin();
436  for (; multi_it != m_multiInstances.end(); ++multi_it) {
437  (*multi_it)->initializeAction(actionName);
438  }
439  }
440  }
441 
442  void Instance::move(const std::string& actionName, const Location& target, const double speed, const std::string& costId) {
443  // if new move is identical with the old then return
444  if (m_activity) {
445  if (m_activity->m_actionInfo) {
449  m_activity->m_actionInfo->m_action == m_object->getAction(actionName) &&
450  costId == m_activity->m_actionInfo->m_route->getCostId()) {
451 
452  return;
453  }
454  }
455  }
456  }
457  initializeAction(actionName);
458  m_activity->m_actionInfo->m_target = new Location(target);
459  m_activity->m_actionInfo->m_speed = speed;
460  FL_DBG(_log, LMsg("starting action ") << actionName << " from" << m_location << " to " << target << " with speed " << speed);
461 
463  if (!route) {
465  route->setRotation(getRotation());
466  if (costId != "") {
467  route->setCostId(costId);
468  }
469  if (isMultiCell()) {
470  route->setObject(m_object);
473  } else if (m_object->getZStepRange() != -1 || !m_object->getWalkableAreas().empty()) {
474  route->setObject(m_object);
475  }
476  m_activity->m_actionInfo->m_route = route;
477  if (!m_activity->m_actionInfo->m_pather->solveRoute(route)) {
478  setFacingLocation(target);
479  finalizeAction();
480  }
481  }
482  }
483 
484  void Instance::follow(const std::string& actionName, Instance* leader, const double speed) {
485  initializeAction(actionName);
487  m_activity->m_actionInfo->m_speed = speed;
488  m_activity->m_actionInfo->m_leader = leader;
489  leader->addDeleteListener(this);
490  FL_DBG(_log, LMsg("starting action ") << actionName << " from" << m_location << " to " << *m_activity->m_actionInfo->m_target << " with speed " << speed);
491  }
492 
493  void Instance::follow(const std::string& actionName, Route* route, const double speed) {
494  initializeAction(actionName);
496  m_activity->m_actionInfo->m_speed = speed;
497  m_activity->m_actionInfo->m_route = route;
499  if (isMultiCell()) {
500  route->setObject(m_object);
503  } else if (m_object->getZStepRange() != -1 || !m_object->getWalkableAreas().empty()) {
504  route->setObject(m_object);
505  }
506  FL_DBG(_log, LMsg("starting action ") << actionName << " from" << m_location << " to " << *m_activity->m_actionInfo->m_target << " with speed " << speed);
507  }
508 
510  if (m_activity) {
512  if (info) {
513  Route* route = info->m_route;
514  if (route) {
515  route->cutPath(length);
516  }
517  }
518  }
519  }
520 
522  if (m_activity) {
524  if (info) {
525  return info->m_route;
526  }
527  }
528  return NULL;
529  }
530 
531  void Instance::setVisitor(bool visit) {
532  m_isVisitor = visit;
533  }
534 
536  return m_isVisitor;
537  }
538 
540  m_visitorShape = info;
541  }
542 
544  return m_visitorShape;
545  }
546 
548  m_visitorRadius = radius;
549  }
550 
552  return m_visitorRadius;
553  }
554 
556  m_cellStackPos = stack;
557  }
558 
560  return m_cellStackPos;
561  }
562 
564  return m_specialCost;
565  }
566 
567  const std::vector<Instance*>& Instance::getMultiInstances() {
568  return m_multiInstances;
569  }
570 
572  m_mainMultiInstance = main;
573  }
574 
576  return m_mainMultiInstance;
577  }
578 
579  void Instance::actOnce(const std::string& actionName, const Location& direction) {
580  initializeAction(actionName);
582  setFacingLocation(direction);
583  }
584 
585  void Instance::actOnce(const std::string& actionName, int32_t rotation) {
586  initializeAction(actionName);
588  setRotation(rotation);
589  }
590 
591  void Instance::actOnce(const std::string& actionName) {
592  initializeAction(actionName);
594  }
595 
596  void Instance::actRepeat(const std::string& actionName, const Location& direction) {
597  initializeAction(actionName);
599  setFacingLocation(direction);
600  }
601 
602  void Instance::actRepeat(const std::string& actionName, int32_t rotation) {
603  initializeAction(actionName);
605  setRotation(rotation);
606  }
607 
608  void Instance::actRepeat(const std::string& actionName) {
609  initializeAction(actionName);
611  }
612 
613  void Instance::say(const std::string& text, uint32_t duration) {
615  delete m_activity->m_sayInfo;
616  m_activity->m_sayInfo = NULL;
617 
618  if (text != "") {
619  m_activity->m_sayInfo = new SayInfo(text, duration);
621  }
622  }
623 
624  const std::string* Instance::getSayText() const {
625  if (m_activity && m_activity->m_sayInfo) {
626  return &m_activity->m_sayInfo->m_txt;
627  }
628  return NULL;
629  }
630 
633  Route* route = info->m_route;
634  Location target;
635  if (info->m_leader) {
636  target = info->m_leader->getLocationRef();
637  } else {
638  target = *info->m_target;
639  }
640  if (!route) {
641  route = new Route(m_location, *info->m_target);
642  route->setRotation(getRotation());
643  info->m_route = route;
644  if (isMultiCell()) {
645  route->setObject(m_object);
648  } else if (m_object->getZStepRange() != -1 || !m_object->getWalkableAreas().empty()) {
649  route->setObject(m_object);
650  }
651  if (!info->m_pather->solveRoute(route)) {
652  setFacingLocation(target);
653  return true;
654  }
655  // update target if needed
656  } else if (route->getEndNode().getLayerCoordinates() != target.getLayerCoordinates()) {
657  if (route->isReplanned() || isMultiCell()) {
658  *info->m_target = route->getEndNode();
659  route->setReplanned(false);
660  if (isMultiCell()) {
663  }
664  } else {
665  if (route->getPathLength() == 0) {
666  route->setStartNode(m_location);
667  } else {
668  route->setStartNode(route->getCurrentNode());
669  }
670  route->setEndNode(target);
671  if (!info->m_pather->solveRoute(route)) {
672  setFacingLocation(target);
673  return true;
674  }
675  }
676  }
677 
678  if (route->getRouteStatus() == ROUTE_SOLVED) {
679  // timeslice for this movement
681  // how far we can travel
682  double distance_to_travel = (static_cast<double>(timedelta) / 1000.0) * info->m_speed;
683  // location for this movement
684  Location nextLocation = m_location;
685  bool can_follow = info->m_pather->followRoute(m_location, route, distance_to_travel, nextLocation);
686  if (can_follow) {
687  setRotation(route->getRotation());
688  // move to another layer
689  if (m_location.getLayer() != nextLocation.getLayer()) {
690  m_location.getLayer()->getMap()->addInstanceForTransfer(this, nextLocation);
691  if (!m_multiInstances.empty()) {
692  std::vector<Instance*>::iterator it = m_multiInstances.begin();
693  for (; it != m_multiInstances.end(); ++it) {
694  Location newloc = nextLocation;
695  std::vector<ModelCoordinate> tmpcoords = m_location.getLayer()->getCellGrid()->
696  toMultiCoordinates(nextLocation.getLayerCoordinates(), (*it)->getObject()->getMultiPartCoordinates(m_rotation));
697  newloc.setLayerCoordinates(tmpcoords.front());
699  }
700  }
701  return false;
702  }
703  setLocation(nextLocation);
704  return false;
705  }
706  // move to another layer
707  if (m_location.getLayer() != nextLocation.getLayer()) {
708  m_location.getLayer()->getMap()->addInstanceForTransfer(this, nextLocation);
709  if (!m_multiInstances.empty()) {
710  std::vector<Instance*>::iterator it = m_multiInstances.begin();
711  for (; it != m_multiInstances.end(); ++it) {
712  Location newloc = nextLocation;
713  std::vector<ModelCoordinate> tmpcoords = m_location.getLayer()->getCellGrid()->
714  toMultiCoordinates(nextLocation.getLayerCoordinates(), (*it)->getObject()->getMultiPartCoordinates(m_rotation));
715  newloc.setLayerCoordinates(tmpcoords.front());
717  }
718  }
719  return true;
720  }
721  setLocation(nextLocation);
722  // need new route?
724  if (m_location.getLayerDistanceTo(target) > 1.5) {
725  if (route->getPathLength() == 0) {
726  route->setStartNode(m_location);
727  } else {
728  route->setStartNode(route->getPreviousNode());
729  }
730  route->setEndNode(target);
733  return !info->m_pather->solveRoute(route);
734  }
735  setFacingLocation(target);
736  }
737  return true;
738  } else if (route->getRouteStatus() == ROUTE_FAILED) {
739  return true;
740  }
741  return false;
742  }
743 
745  if (!m_activity) {
746  return ICHANGE_NO_CHANGES;
747  }
748  // remove DeleteListeners
749  m_deleteListeners.erase(std::remove(m_deleteListeners.begin(),m_deleteListeners.end(),
751 
752  if (!m_activity->m_timeProvider) {
754  }
756  if (info) {
757 // FL_DBG(_log, "updating instance");
758 
759  if (info->m_target) {
760 // FL_DBG(_log, "action contains target for movement");
761  bool movement_finished = processMovement();
762  if (movement_finished) {
763 // FL_DBG(_log, "movement finished");
764  finalizeAction();
765  }
766  } else {
767 // FL_DBG(_log, "action does not contain target for movement");
769  if (info->m_repeating) {
771  // prock: offset no longer needed
772  info->m_action_offset_time = 0;
773  } else if (!m_object->isMultiPart()) {
774  finalizeAction();
775  }
776  }
777  }
778 
779  // previous code may invalidate actioninfo.
780  if( m_activity->m_actionInfo ) {
782  }
783  }
784  m_activity->update(*this);
785  if (m_activity->m_sayInfo) {
786  if (m_activity->m_sayInfo->m_duration > 0) {
788  say("");
789  }
790  }
792  // delete superfluous activity
793  delete m_activity;
794  m_activity = 0;
795  return ICHANGE_NO_CHANGES;
796  }
797  return m_changeInfo;
798  }
799 
801  FL_DBG(_log, "finalizing action");
802  assert(m_activity);
803  assert(m_activity->m_actionInfo);
804 
807  }
808 
810  delete m_activity->m_actionInfo;
811  m_activity->m_actionInfo = NULL;
812  // this is needed in case the new action is set on the same pump and
813  // it is the same action as the finalized action
814  m_activity->m_action = NULL;
815 
816  if (isMultiObject()) {
817  std::vector<Instance*>::iterator multi_it = m_multiInstances.begin();
818  for (; multi_it != m_multiInstances.end(); ++multi_it) {
819  (*multi_it)->finalizeAction();
820  }
821  }
822  std::vector<InstanceActionListener*>::iterator i = m_activity->m_actionListeners.begin();
823  while (i != m_activity->m_actionListeners.end()) {
824  if(*i)
825  (*i)->onInstanceActionFinished(this, action);
826  ++i;
827  }
829  std::remove(m_activity->m_actionListeners.begin(),
831  (InstanceActionListener*)NULL),
833  }
834 
836  FL_DBG(_log, "cancel action");
837  assert(m_activity);
838  assert(m_activity->m_actionInfo);
839 
842  }
843 
845  delete m_activity->m_actionInfo;
846  m_activity->m_actionInfo = NULL;
847  // this is needed in case the new action is set on the same pump and
848  // it is the same action as the canceled action
849  m_activity->m_action = NULL;
850 
851  if (isMultiObject()) {
852  std::vector<Instance*>::iterator multi_it = m_multiInstances.begin();
853  for (; multi_it != m_multiInstances.end(); ++multi_it) {
854  (*multi_it)->cancelAction();
855  }
856  }
857  std::vector<InstanceActionListener*>::iterator i = m_activity->m_actionListeners.begin();
858  while (i != m_activity->m_actionListeners.end()) {
859  if(*i)
860  (*i)->onInstanceActionCancelled(this, action);
861  ++i;
862  }
864  std::remove(m_activity->m_actionListeners.begin(),
866  (InstanceActionListener*)NULL),
868  }
869 
873  }
874  return NULL;
875  }
876 
879  return *m_activity->m_actionInfo->m_target;
880  }
881  return m_location;
882  }
883 
884  double Instance::getMovementSpeed() const {
887  }
888  return 0;
889  }
890 
893  }
894 
897  }
898 
900  if (m_activity) {
901  return m_activity->m_oldLocation;
902  }
903  return m_location;
904  }
905 
906  int32_t Instance::getOldRotation() const {
907  if (m_activity) {
908  return m_activity->m_oldRotation;
909  }
910  return m_rotation;
911  }
912 
918  }
919  return getRuntime();
920  }
921 
924  }
925 
927  float multiplier = 1.0;
928  if (m_activity->m_timeProvider) {
929  multiplier = m_activity->m_timeProvider->getMultiplier();
930  }
931  delete m_activity->m_timeProvider;
932  m_activity->m_timeProvider = NULL;
933 
934  if (m_location.getLayer()) {
935  Map* map = m_location.getLayer()->getMap();
936  if (map) {
938  }
939  }
940  if (!m_activity->m_timeProvider) {
942  }
944  }
945 
949  }
950 
952  if (m_activity) {
953  return m_changeInfo;
954  }
955  return ICHANGE_NO_CHANGES;
956  }
957 
961  }
962 
966  }
967 
971  }
972 
973  void Instance::setTimeMultiplier(float multip) {
975  if (!m_activity->m_timeProvider) {
977  }
979  }
980 
984  }
985  return 1.0;
986  }
987 
991  }
992  if (m_location.getLayer()) {
993  Map* map = m_location.getLayer()->getMap();
994  if (map && map->getTimeProvider()) {
995  return map->getTimeProvider()->getTotalMultiplier();
996  }
997  }
998  return 1.0;
999  }
1000 
1002  if (m_activity) {
1004  bindTimeProvider();
1006  }
1007  if (m_location.getLayer()) {
1008  Map* map = m_location.getLayer()->getMap();
1009  if (map && map->getTimeProvider()) {
1010  return map->getTimeProvider()->getGameTime();
1011  }
1012  }
1013  return TimeManager::instance()->getTime();
1014  }
1015 
1016  void Instance::setCost(const std::string& id, double cost) {
1017  m_specialCost = true;
1018  m_costId = id;
1019  m_cost = cost;
1020  }
1021 
1023  m_specialCost = false;
1024  }
1025 
1027  if (m_specialCost) {
1028  return m_cost;
1029  }
1030  return m_object->getCost();
1031  }
1032 
1033  std::string Instance::getCostId() {
1034  if (m_specialCost) {
1035  return m_costId;
1036  }
1037  return m_object->getCostId();
1038  }
1039 
1041  return m_object->getSpeed();
1042  }
1043 
1045  return m_object->isSpecialSpeed();
1046  }
1047 
1049  return m_object->isMultiObject();
1050  }
1051 
1053  return !m_multiInstances.empty();
1054  }
1055 
1057  if (!m_multiInstances.empty()) {
1058  // use map coords for rotation and movement
1059  // instances are changed on InstanceTree but not on CellCache
1060  Location loc = m_location;
1062  const ExactModelCoordinate& offset = m_object->getRotationAnchor();
1063  loc.setExactLayerCoordinates(offset);
1064  const ExactModelCoordinate anchor_offset = loc.getMapCoordinates();
1065  int32_t rot = m_rotation;
1066  if (m_object->isRestrictedRotation()) {
1068  }
1069  double mcos = Mathd::Cos(double(rot) * (Mathd::pi()/180.0));
1070  double msin = Mathd::Sin(double(rot) * (Mathd::pi()/180.0));
1071  std::vector<Instance*>::iterator it = m_multiInstances.begin();
1072  for (; it != m_multiInstances.end(); ++it) {
1073  // use rotation 0 to get the "default" coordinate
1074  std::vector<ModelCoordinate> mcv = (*it)->getObject()->getMultiPartCoordinates(0);
1075  loc.setLayerCoordinates(mcv.front());
1077  ExactModelCoordinate nemc(emc.x-anchor_offset.x, emc.y-anchor_offset.y);
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;
1080  loc.setMapCoordinates(emc);
1081  (*it)->setLocation(loc);
1082  (*it)->setRotation(rot);
1083  }
1084  }
1085  }
1086 
1088  if (!m_ownObject) {
1089  createOwnObject();
1090  }
1092  objVis->addStaticColorOverlay(angle, colors);
1093  prepareForUpdate();
1095  }
1096 
1098  if (!m_ownObject) {
1099  return 0;
1100  }
1102  return objVis->getStaticColorOverlay(angle);
1103  }
1104 
1106  if (m_ownObject) {
1108  objVis->removeStaticColorOverlay(angle);
1109  prepareForUpdate();
1111  }
1112  }
1113 
1115  if (!m_ownObject) {
1116  return false;
1117  }
1119  return objVis->isColorOverlay();
1120  }
1121 
1122  void Instance::addColorOverlay(const std::string& actionName, uint32_t angle, const OverlayColors& colors) {
1123  ActionVisual* visual = getActionVisual(actionName, true);
1124  if (visual) {
1125  visual->addColorOverlay(angle, colors);
1126  prepareForUpdate();
1128  }
1129  }
1130 
1131  OverlayColors* Instance::getColorOverlay(const std::string& actionName, uint32_t angle) {
1132  ActionVisual* visual = getActionVisual(actionName, false);
1133  if (visual) {
1134  return visual->getColorOverlay(angle);
1135  }
1136  return NULL;
1137  }
1138 
1139  void Instance::removeColorOverlay(const std::string& actionName, int32_t angle) {
1140  ActionVisual* visual = getActionVisual(actionName, false);
1141  if (visual) {
1142  visual->removeColorOverlay(angle);
1143  prepareForUpdate();
1145  }
1146  }
1147 
1148  void Instance::addAnimationOverlay(const std::string& actionName, uint32_t angle, int32_t order, const AnimationPtr& animationptr) {
1149  ActionVisual* visual = getActionVisual(actionName, true);
1150  if (visual) {
1151  visual->addAnimationOverlay(angle, order, animationptr);
1152  prepareForUpdate();
1154  }
1155  }
1156 
1157  std::map<int32_t, AnimationPtr> Instance::getAnimationOverlay(const std::string& actionName, int32_t angle) {
1158  ActionVisual* visual = getActionVisual(actionName, false);
1159  if (visual) {
1160  return visual->getAnimationOverlay(angle);
1161  }
1162  return std::map<int32_t, AnimationPtr>();
1163  }
1164 
1165  void Instance::removeAnimationOverlay(const std::string& actionName, uint32_t angle, int32_t order) {
1166  ActionVisual* visual = getActionVisual(actionName, false);
1167  if (visual) {
1168  visual->removeAnimationOverlay(angle, order);
1169  prepareForUpdate();
1171  }
1172  }
1173 
1174  void Instance::addColorOverlay(const std::string& actionName, uint32_t angle, int32_t order, const OverlayColors& colors) {
1175  ActionVisual* visual = getActionVisual(actionName, true);
1176  if (visual) {
1177  visual->addColorOverlay(angle, order, colors);
1178  prepareForUpdate();
1180  }
1181  }
1182 
1183  OverlayColors* Instance::getColorOverlay(const std::string& actionName, uint32_t angle, int32_t order) {
1184  ActionVisual* visual = getActionVisual(actionName, false);
1185  if (visual) {
1186  return visual->getColorOverlay(angle, order);
1187  }
1188  return NULL;
1189  }
1190 
1191  void Instance::removeColorOverlay(const std::string& actionName, int32_t angle, int32_t order) {
1192  ActionVisual* visual = getActionVisual(actionName, false);
1193  if (visual) {
1194  visual->removeColorOverlay(angle, order);
1195  prepareForUpdate();
1197  }
1198  }
1199 
1200  bool Instance::isAnimationOverlay(const std::string& actionName) {
1201  ActionVisual* visual = getActionVisual(actionName, false);
1202  if (visual) {
1203  return visual->isAnimationOverlay();
1204  }
1205  return false;
1206  }
1207 
1208  bool Instance::isColorOverlay(const std::string& actionName) {
1209  ActionVisual* visual = getActionVisual(actionName, false);
1210  if (visual) {
1211  return visual->isColorOverlay();
1212  }
1213  return false;
1214  }
1215 
1216  void Instance::convertToOverlays(const std::string& actionName, bool color) {
1217  ActionVisual* visual = getActionVisual(actionName, true);
1218  visual->convertToOverlays(color);
1219  }
1220 
1222  if (!m_ownObject) {
1223  m_ownObject = true;
1225  ObjectVisual* nov = 0;
1227  if (!ov) {
1229  } else {
1230  nov = new ObjectVisual(*ov);
1231  m_object->adoptVisual(nov);
1232  }
1233  }
1234  }
1235 
1236  ActionVisual* Instance::getActionVisual(const std::string& actionName, bool create) {
1237  ActionVisual* nav = NULL;
1238  if (!m_ownObject) {
1239  createOwnObject();
1240  }
1241  Action* action = m_object->getAction(actionName, false);
1242  if (!action) {
1243  action = m_object->getAction(actionName);
1244  if (!action) {
1245  throw NotFound(std::string("action ") + actionName + " not found");
1246  } else if (create) {
1247  // if we change the current action then we have to replace the pointer
1248  bool replace = getCurrentAction() == action;
1249  // check if its the default action
1250  bool defaultAction = m_object->getDefaultAction() == action;
1251  ActionVisual* av = action->getVisual<ActionVisual>();
1252  action = m_object->createAction(actionName, defaultAction);
1253  nav = new ActionVisual(*av);
1254  action->adoptVisual(nav);
1255  if (replace) {
1256  m_activity->m_actionInfo->m_action = action;
1257  }
1258  }
1259  } else {
1260  nav = action->getVisual<ActionVisual>();
1261  }
1262  return nav;
1263  }
1264 
1266  m_deleteListeners.push_back(listener);
1267  }
1268 
1270  if (!m_deleteListeners.empty()) {
1271  std::vector<InstanceDeleteListener*>::iterator itor;
1272  itor = std::find(m_deleteListeners.begin(), m_deleteListeners.end(), listener);
1273  if(itor != m_deleteListeners.end()) {
1274  if ((*itor) == listener) {
1275  *itor = NULL;
1276  return;
1277  }
1278  } else {
1279  FL_WARN(_log, "Cannot remove unknown listener");
1280  }
1281  }
1282  }
1283 
1286  m_activity->m_actionInfo->m_leader == instance) {
1287  m_activity->m_actionInfo->m_leader = NULL;
1288  }
1289  if (isMultiObject()) {
1290  std::vector<Instance*>::iterator multi_it = m_multiInstances.begin();
1291  for (; multi_it != m_multiInstances.end(); ++multi_it) {
1292  if (*multi_it == instance) {
1293  m_multiInstances.erase(multi_it);
1294  break;
1295  }
1296  }
1297  }
1298  }
1299 }
bool isMultiObject()
Returns true if it is multi object otherwise false.
Definition: instance.cpp:1052
static InstanceVisual * create(Instance *instance)
Constructs and assigns it to the passed item.
Definition: visual.cpp:179
#define FL_WARN(logger, msg)
Definition: logger.h:72
void callOnVisibleChange()
Definition: instance.cpp:963
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...
Definition: instance.cpp:194
void setOccupiedArea(const std::vector< ModelCoordinate > &area)
Sets occupied coordinates for multi cell object.
Definition: route.cpp:254
Timeprovider is an utility providing time management functionality You can have hierarchy of time pro...
Definition: timeprovider.h:42
void prepareForUpdate()
called to prepare the instance for an update
Definition: instance.cpp:280
Map * getMap() const
Get the map this layer is contained in.
Definition: layer.cpp:89
void cutPath(uint32_t length=1)
Cuts path after the given length.
Definition: route.cpp:181
void initializeAction(const std::string &actionName)
Initialize action for use.
Definition: instance.cpp:415
std::string getCostId()
Returns cost id.
Definition: instance.cpp:1033
double getCost() const
Returns the cost.
Definition: object.cpp:309
InstanceActivity * m_activity
Definition: instance.h:598
void updateMultiInstances()
Updates the visual positions of all instances in case this is a multi object.
Definition: instance.cpp:1056
int32_t getAngleBetween(const Location &loc1, const Location &loc2)
Gets angle of vector defined by given locations.
Definition: angles.cpp:97
void setLayerCoordinates(const ModelCoordinate &coordinates)
Sets "cell precise" layer coordinates to this location.
Definition: location.cpp:94
static T Cos(T _val)
Definition: fife_math.h:216
void setObject(Object *obj)
Sets the object, needed for multi cell and z-step range.
Definition: route.cpp:315
void follow(const std::string &actionName, Instance *leader, const double speed)
Performs given named action to the instance.
Definition: instance.cpp:484
void setMultiplier(float multiplier)
With multiplier, you can adjust the time speed.
IPather * m_pather
Definition: instance.cpp:92
InstanceActivity(Instance &source)
Definition: instance.cpp:112
bool m_isVisitor
is instance a visitor (FoW)
Definition: instance.h:617
Action * m_action
action on previous round. : might become invalid, only used for address comparison ...
Definition: instance.h:574
void createOwnObject()
Creates an own object for the instance to allow visual customization.
Definition: instance.cpp:1221
VisitorShapeInfo m_visitorShape
visitor shape type
Definition: instance.h:619
void setExactLayerCoordinates(const ExactModelCoordinate &coordinates)
Sets precise layer coordinates to this location.
Definition: location.cpp:87
const std::string & getNamespace() const
Definition: object.h:69
void addActionListener(InstanceActionListener *listener)
Adds new instance action listener.
Definition: instance.cpp:361
void cancelAction()
Cancel current action.
Definition: instance.cpp:835
bool m_ownObject
indicates if m_object is customized
Definition: instance.h:607
const Location & getPreviousNode()
Returns previous location.
Definition: route.cpp:108
void adoptVisual(IVisual *visual)
Sets visualization to be used.
Definition: object.cpp:209
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 ...
Definition: instance.cpp:271
Helper class to create log strings out from separate parts Usage: LMsg("some text") << variable << "...
Definition: logger.h:82
T * getVisual() const
Gets used visualization.
Definition: action.h:73
void setId(const std::string &identifier="")
Set the identifier for this instance.
Definition: instance.cpp:334
Object class.
Definition: object.h:51
uint32_t m_action_offset_time
Definition: instance.cpp:88
void addDeleteListener(InstanceDeleteListener *listener)
Adds new instance delete listener.
Definition: instance.cpp:1265
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.
Definition: instance.cpp:1148
void callOnActionFrame(Action *action, int32_t frame)
Auxiliary function to inform ActionListeners about the active ActionFrame.
Definition: instance.cpp:386
bool isActive() const
If this returns true, the instance needs to be updated.
Definition: instance.cpp:288
void convertToOverlays(bool color)
Convertes animations and optional color overlay to default animation overlay.
Definition: visual.cpp:369
uint32_t m_action_start_time
Definition: instance.cpp:86
bool isAnimationOverlay(const std::string &actionName)
Indicates if there exists a animation overlay for given action.
Definition: instance.cpp:1200
bool isBlocking() const
Gets if instance blocks movement.
Definition: instance.cpp:349
bool isColorOverlay(const std::string &actionName)
Indicates if there exists a color overlay for given action or animation overlay.
Definition: instance.cpp:1208
const std::string & getId() const
Definition: object.h:68
bool isSpecialSpeed()
Returns true if instance or object have special speed modifier otherwise false.
Definition: instance.cpp:1044
void setMainMultiInstance(Instance *main)
Sets a instance to the main multi instance of this instance.
Definition: instance.cpp:571
void setFacingLocation(const Location &loc)
Sets the direction where instance is heading.
Definition: instance.cpp:891
void setMapCoordinates(const ExactModelCoordinate &coordinates)
Sets map coordinates to this location.
Definition: location.cpp:98
Action visual contains data that is needed to visualize different actions on screen.
Definition: visual.h:212
bool isMultiObject() const
Gets if object uses special cost.
Definition: object.cpp:346
Location getTargetLocation() const
Gets movement target in case instance is moving.
Definition: instance.cpp:877
std::vector< InstanceDeleteListener * > m_deleteListeners
listeners for deletion of the instance
Definition: instance.h:602
IPather * getPather() const
Gets associated pather.
Definition: object.cpp:195
InstanceChangeInfo getChangeInfo()
Returns a bitmask of changes of the last update.
Definition: instance.cpp:951
const Location & getEndNode()
Returns the target location.
Definition: route.cpp:94
bool m_blocking
instance blocking info
Definition: instance.h:613
uint32_t m_start_time
Definition: instance.cpp:109
void removeAnimationOverlay(uint32_t angle, int32_t order)
Removes animation overlay with given angle (degrees) and order.
Definition: visual.cpp:261
void removeAnimationOverlay(const std::string &actionName, uint32_t angle, int32_t order)
Removes animation overlay with given angle (degrees) and order from action.
Definition: instance.cpp:1165
Instance * createInstance(Object *object, const ModelCoordinate &p, const std::string &id="")
Add an instance of an object at a specific position.
Definition: layer.cpp:109
uint32_t getPathLength()
Returns the length of the path.
Definition: route.cpp:215
static Logger _log(LM_AUDIO)
void setVisitorRadius(uint16_t radius)
Sets the range for a visitor.
Definition: instance.cpp:547
void cancelMovement(uint32_t length=1)
Cancel movement after a given length.
Definition: instance.cpp:509
Location m_location
current location
Definition: instance.h:609
uint32_t getActionRuntime()
Gets the time in milliseconds how long action has been active In case there is no current action...
Definition: instance.cpp:913
std::string getCostId() const
Returns the cost id.
Definition: object.cpp:292
bool isMultiPart() const
Gets if object is a part of a multi object.
Definition: object.cpp:393
ActionVisual * getActionVisual(const std::string &actionName, bool create)
Returns pointer to action visual, can also create it.
Definition: instance.cpp:1236
void setActionRuntime(uint32_t time_offset)
Sets the time in milliseconds how long an action has been active This was requested in Ticket #373...
Definition: instance.cpp:922
Action * getCurrentAction() const
Gets the currently active action.
Definition: instance.cpp:870
void removeStaticColorOverlay(int32_t angle)
Removes a static color overlay with given angle (degrees).
Definition: visual.cpp:147
InstanceTree * getInstanceTree(void) const
Get the instance tree.
Definition: layer.cpp:101
Action * m_action
Definition: instance.cpp:78
std::list< std::string > getWalkableAreas() const
Returns a list that contains all walkable area ids.
Definition: object.cpp:606
Layer * getLayer() const
Gets the layer where this location is pointing to.
Definition: location.cpp:83
bool isSpecialCost()
Returns true if instance or object have special cost otherwise false.
Definition: instance.cpp:563
static TimeManager * instance()
Definition: singleton.h:84
Location & getLocationRef()
Gets reference of current location of instance.
Definition: instance.cpp:315
ModelCoordinate getLayerCoordinates() const
Gets cell precision layer coordinates set to this location.
Definition: location.cpp:113
A basic route.
Definition: route.h:64
void callOnTransparencyChange()
Definition: instance.cpp:958
uint32_t m_prev_call_time
Definition: instance.cpp:90
const std::string * getSayText() const
Returns pointer to currently set saytext.
Definition: instance.cpp:624
OverlayColors * getStaticColorOverlay(int32_t angle)
Returns closest matching static color overlay for given angle.
Definition: visual.cpp:139
void update(Instance &source)
updates cached variables, marks changes
Definition: instance.cpp:136
void convertToOverlays(const std::string &actionName, bool color)
If the action have base animation and optional color overlay it gets converted to animation overlay...
Definition: instance.cpp:1216
void removeDeleteListener(InstanceDeleteListener *listener)
Removes associated instance delete listener.
Definition: instance.cpp:1269
OverlayColors * getStaticColorOverlay(int32_t angle)
Returns closest matching static color overlay for given angle.
Definition: instance.cpp:1097
ActionInfo(IPather *pather, const Location &curloc)
Definition: instance.cpp:53
uint16_t m_visitorRadius
visitor radius (FoW)
Definition: instance.h:621
void addChangeListener(InstanceChangeListener *listener)
Adds new instance change listener.
Definition: instance.cpp:381
OverlayColors * getColorOverlay(int32_t angle)
Gets OverlayColors for given angle (degrees).
Definition: visual.cpp:291
unsigned char uint8_t
Definition: core.h:38
IVisual * m_visual
instance visualization
Definition: instance.h:611
void setRotation(int32_t rotation)
Sets the current rotation.
Definition: route.cpp:231
int32_t m_rotation
The rotation offset of this instance.
Definition: instance.h:547
uint32_t getTime() const
Get the time.
void removeColorOverlay(int32_t angle)
Removes color overlay with given angle (degrees).
Definition: visual.cpp:303
void setStartNode(const Location &node)
Sets the start location.
Definition: route.cpp:67
void setOverrideBlocking(bool overblock)
Sets if instance blocking can overriden.
Definition: instance.cpp:353
const std::vector< Instance * > & getMultiInstances()
Returns a vector that contains all instances of a multi object.
Definition: instance.cpp:567
static bool Equal(T _val1, T _val2)
Definition: fife_math.h:286
Instance * m_mainMultiInstance
pointer to the main multi instance
Definition: instance.h:633
std::vector< InstanceActionListener * > m_actionListeners
listeners for action related events
Definition: instance.h:586
void addColorOverlay(uint32_t angle, const OverlayColors &colors)
Adds new color overlay with given angle (degrees) and colors.
Definition: visual.cpp:275
T * getVisual() const
Gets used visualization.
Definition: object.h:122
Object * getObject()
Gets object where this instance is instantiated from.
Definition: instance.cpp:292
std::vector< InstanceChangeListener * > m_changeListeners
listeners for changes
Definition: instance.h:582
float getMultiplier() const
uint32_t InstanceChangeInfo
Definition: instance.h:76
void callOnStackPositionChange()
Definition: instance.cpp:968
static T Sin(T _val)
Definition: fife_math.h:266
int32_t getRotation() const
Get the rotation offset of this instance Returns direction where instance is heading.
Definition: instance.cpp:330
void addAnimationOverlay(uint32_t angle, int32_t order, AnimationPtr animationptr)
Adds new animation overlay with given angle (degrees) and order.
Definition: visual.cpp:250
uint8_t VisitorShapeInfo
Definition: instance.h:95
int32_t getSessionId()
Returns the session identifier.
Definition: route.cpp:227
Location & getOldLocationRef()
Gets reference of old location of instance.
Definition: instance.cpp:899
Location * m_target
Definition: instance.cpp:80
A basic layer on a map.
Definition: layer.h:99
Instance * m_leader
Definition: instance.cpp:94
OverlayColors * getColorOverlay(const std::string &actionName, uint32_t angle)
Returns closest matching color overlay for given angle and action.
Definition: instance.cpp:1131
Location getFacingLocation()
Returns the direction where instance is heading.
Definition: instance.cpp:895
void setCostId(const std::string &cost)
Sets cost identifier which should be used for pathfinding.
Definition: route.cpp:239
void removeStaticColorOverlay(int32_t angle)
Removes a static color overlay with given angle (degrees).
Definition: instance.cpp:1105
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.
Definition: map.cpp:310
void addColorOverlay(const std::string &actionName, uint32_t angle, const OverlayColors &colors)
Adds new color overlay with given angle (degrees) to given action.
Definition: instance.cpp:1122
void setTimeMultiplier(float multip)
Sets speed for the map.
Definition: instance.cpp:973
uint32_t m_duration
Definition: instance.cpp:108
Location getLocation() const
Gets current location of instance.
Definition: instance.cpp:311
void removeChangeListener(InstanceChangeListener *listener)
Removes associated instance change listener.
Definition: instance.cpp:400
RouteStatusInfo getRouteStatus()
Returns route status.
Definition: route.cpp:63
bool isColorOverlay()
Indicates if there exists a color overlay.
Definition: visual.h:141
uint8_t getCellStackPosition()
Gets the cell stack position.
Definition: instance.cpp:559
void addStaticColorOverlay(uint32_t angle, const OverlayColors &colors)
Adds new static color overlay with given angle (degrees).
Definition: visual.cpp:122
Instance * getMainMultiInstance()
Returns a pointer to the main mulit instance or Null if the instance is not part of a multi instance ...
Definition: instance.cpp:575
void onInstanceDeleted(Instance *instance)
callback so other instances we depend on can notify us if they go away
Definition: instance.cpp:1284
void removeInstance(Instance *instance)
Removes an instance from the quad tree.
bool isRestrictedRotation() const
Gets if object uses restricted rotations.
Definition: object.cpp:532
bool isStaticColorOverlay()
Indicates if there exists a static color overlay.
Definition: instance.cpp:1114
InstanceActivity gets allocated in case there is some runtime activity related to the instance...
Definition: instance.h:557
ExactModelCoordinate & getExactLayerCoordinatesRef()
Gets reference to exact layer coordinates.
Definition: location.cpp:105
unsigned short uint16_t
Definition: core.h:39
CellGrid * getCellGrid() const
Get the Cellgrid.
Definition: layer.cpp:93
void setReplanned(bool replanned)
Sets the route to replanned.
Definition: route.cpp:207
void bindTimeProvider()
rebinds time provider based on new location
Definition: instance.cpp:926
void addInstance(Instance *instance)
Adds an instance to the quad tree.
std::string m_id
Definition: instance.h:543
ExactModelCoordinate getRotationAnchor() const
Returns the rotation anchor for this multi object.
Definition: object.cpp:515
virtual bool cancelSession(const int32_t sessionId)=0
Cancels a given session.
void setBlocking(bool blocking)
Sets if instance blocks movement.
Definition: instance.cpp:342
double getMovementSpeed() const
Gets the speed in case instance is moving otherwise returns 0.
Definition: instance.cpp:884
Action * createAction(const std::string &identifier, bool is_default=false)
Adds new action with given id.
Definition: object.cpp:92
InstanceChangeInfo m_additional
additional change info, used for visual class (transparency, visible, stackpos)
Definition: instance.h:596
void finalizeAction()
Finalize current action.
Definition: instance.cpp:800
ActionInfo * m_actionInfo
action information, allocated when actions are bind
Definition: instance.h:588
void setCellStackPosition(uint8_t stack)
Sets the cell stack position.
Definition: instance.cpp:555
double m_cost
holds cost value
Definition: instance.h:627
TimeProvider * m_timeProvider
time scaler for this instance
Definition: instance.h:592
std::vector< ModelCoordinate > getMultiObjectCoordinates(int32_t rotation) const
Returns all multi object coordinates for the given rotation.
Definition: object.cpp:478
SayInfo * m_sayInfo
text to say + duration, allocated when something is said
Definition: instance.h:590
VisitorShapeInfo getVisitorShape()
Gets the shape type for a visitor.
Definition: instance.cpp:543
Object visual contains data that is needed for visualizing objects.
Definition: visual.h:91
virtual bool followRoute(const Location &current, 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.
Definition: instance.cpp:579
InstanceChangeInfo m_changeInfo
bitmask stating current changes
Definition: instance.h:600
static ObjectVisual * create(Object *object)
Constructs and assigns it to the passed item.
Definition: visual.cpp:101
SayInfo(const std::string &txt, uint32_t duration)
Definition: instance.cpp:102
bool m_specialCost
indicates special cost
Definition: instance.h:625
std::string m_txt
Definition: instance.cpp:107
std::string m_costId
holds cost id
Definition: instance.h:629
std::vector< Instance * > m_multiInstances
vector that holds all multi instances
Definition: instance.h:631
double getCost()
Returns cost value.
Definition: instance.cpp:1026
float getTotalTimeMultiplier()
Gets instance speed, considering also model and map speeds.
Definition: instance.cpp:988
void addStaticColorOverlay(uint32_t angle, const OverlayColors &colors)
Adds new static color overlay with given angle (degrees).
Definition: instance.cpp:1087
void removeColorOverlay(const std::string &actionName, int32_t angle)
Removes a color overlay with given angle (degrees) from given action.
Definition: instance.cpp:1139
bool isOverrideBlocking() const
Gets if instance blocking can overriden.
Definition: instance.cpp:357
float getTimeMultiplier()
Gets instance speed.
Definition: instance.cpp:981
void resetCost()
Resets cost.
Definition: instance.cpp:1022
const std::string & getCostId()
Returns cost identifier which is used for pathfinding.
Definition: route.cpp:243
void actRepeat(const std::string &actionName, const Location &direction)
Performs given named action to the instance, repeated.
Definition: instance.cpp:596
static num_type pi()
Definition: fife_math.h:133
InstanceChangeInfo update()
Updates the instance related to the current action.
Definition: instance.cpp:744
int32_t getOldRotation() const
Get the old rotation offset of this instance Returns direction where instance was heading...
Definition: instance.cpp:906
const std::string & getId()
Get the identifier for this instance; possibly null.
Definition: instance.cpp:338
Location m_oldLocation
location on previous cell
Definition: instance.h:568
uint32_t getDuration()
Gets the duration of this action.
Definition: action.h:65
void setRotation(int32_t rotation)
Set the rotation offset of this instance.
Definition: instance.cpp:319
void removeActionListener(InstanceActionListener *listener)
Removes associated instance action listener.
Definition: instance.cpp:366
TimeProvider * getTimeProvider()
Gets timeprovider used in the map.
Definition: map.h:160
const Location & getCurrentNode()
Returns current location.
Definition: route.cpp:98
virtual ~Instance()
Destructor.
Definition: instance.cpp:241
void setEndNode(const Location &node)
Sets the target location.
Definition: route.cpp:82
uint32_t getRuntime()
Gets the scaled runtime in milliseconds.
Definition: instance.cpp:1001
Route * getRoute()
Returns a pointer to the route, in case there is no, it returns NULL.
Definition: instance.cpp:521
int32_t getZStepRange() const
Returns z-step range from object.
Definition: object.cpp:563
void refresh()
Refreshes instance e.g.
Definition: instance.cpp:946
Action * getAction(const std::string &identifier, bool deepsearch=true) const
Gets action with given id.
Definition: object.cpp:121
int32_t getRotation()
Returns the current rotation.
Definition: route.cpp:235
std::map< int32_t, AnimationPtr > getAnimationOverlay(const std::string &actionName, int32_t angle)
Gets map with animations closest to given angle.
Definition: instance.cpp:1157
void setInstanceActivityStatus(Instance *instance, bool active)
Sets the activity status for given instance on this layer.
Definition: layer.cpp:233
double getSpeed() const
Returns the speed modifier.
Definition: object.cpp:336
A container of Layer(s).
Definition: map.h:88
void move(const std::string &actionName, const Location &target, const double speed, const std::string &costId="")
Performs given named action to the instance.
Definition: instance.cpp:442
unsigned int uint32_t
Definition: core.h:40
float getTotalMultiplier() const
Object * m_object
object where instantiated from
Definition: instance.h:605
Action * getDefaultAction() const
Gets default action assigned to this object.
Definition: object.cpp:178
uint16_t getVisitorRadius()
Gets the visitor range.
Definition: instance.cpp:551
bool isVisitor()
If instance is a visitor it returns true otherwise false.
Definition: instance.cpp:535
bool isMultiCell()
Returns true if it is multi cell otherwise false.
Definition: instance.cpp:1048
Location getFacing(const Location &loc, const int32_t angle)
Gets facing location defined by given angle and location.
Definition: angles.cpp:112
int32_t getRestrictedRotation(int32_t rotation)
Returns the most obvious rotation, based on multi coordinates.
Definition: object.cpp:542
bool isSpecialSpeed() const
Gets if object uses special speed modifier.
Definition: object.cpp:319
bool isReplanned()
Gets if the route is replanned.
Definition: route.cpp:211
double getLayerDistanceTo(const Location &location) const
Gets layer distance to another location.
Definition: location.cpp:180
uint8_t m_cellStackPos
position on cell stack
Definition: instance.h:623
void setLocation(const Location &loc)
Sets location of the instance.
Definition: instance.cpp:296
#define FL_DBG(logger, msg)
Definition: logger.h:70
An Instance is an "instantiation" of an Object at a Location.
Definition: instance.h:100
bool processMovement()
Moves instance. Returns true if finished.
Definition: instance.cpp:631
bool m_overrideBlocking
allow to override the blocking property
Definition: instance.h:615
std::map< int32_t, AnimationPtr > getAnimationOverlay(int32_t angle)
Gets map with animations closest to given angle.
Definition: visual.cpp:256
ExactModelCoordinate getMapCoordinates() const
Gets map coordinates set to this location.
Definition: location.cpp:117
bool isAnimationOverlay()
Returns true if it exists a animation overlay, otherwise false.
Definition: visual.h:284
bool isColorOverlay()
Returns true if it exists a color overlay, otherwise false.
Definition: visual.h:288
void setCost(const std::string &id, double cost)
Sets for the given cost id a cost.
Definition: instance.cpp:1016
Route * m_route
Definition: instance.cpp:96
double getSpeed()
Returns speed modifier.
Definition: instance.cpp:1040
int32_t m_oldRotation
rotation on previous round
Definition: instance.h:572
void say(const std::string &text, uint32_t duration=0)
Causes instance to "say" given text (shown on screen next to the instance)
Definition: instance.cpp:613
void setVisitor(bool visit)
Marks this instance as a visitor.
Definition: instance.cpp:531
void setVisitorShape(VisitorShapeInfo info)
Sets the shape type for a visitor.
Definition: instance.cpp:539