FIFE  be64c707dea6b3250bd4355bf5c825d25920087d
instance.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005-2019 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 "audio/soundsource.h"
33 #include "util/log/logger.h"
34 #include "util/base/exception.h"
35 #include "util/math/fife_math.h"
36 #include "util/time/timemanager.h"
39 #include "model/metamodel/action.h"
41 #include "model/structures/layer.h"
42 #include "model/structures/map.h"
44 #include "view/visual.h"
45 #include "pathfinder/route.h"
46 
47 #include "instance.h"
48 
49 namespace FIFE {
50  static Logger _log(LM_INSTANCE);
51 
52  class ActionInfo {
53  public:
54  ActionInfo(IPather* pather, const Location& curloc):
55  m_action(NULL),
56  m_target(NULL),
57  m_speed(0),
58  m_repeating(false),
62  m_pather(pather),
63  m_leader(NULL),
64  m_route(NULL),
65  m_delete_route(true) {}
66 
68  if (m_route && m_delete_route) {
69  int32_t sessionId = m_route->getSessionId();
70  if (sessionId != -1) {
71  m_pather->cancelSession(sessionId);
72  }
73  delete m_route;
74  }
75  delete m_target;
76  }
77 
78  // Current action, owned by object
80  // target location for ongoing movement
82  // current movement speed
83  double m_speed;
84  // should action be repeated? used only for non-moving actions, moving ones repeat until movement is finished
86  // action start time (ticks)
88  // action offset time (ticks) for resuming an action
90  // ticks since last call
92  // pather
94  // leader for follow activity
96  // pointer to route that contain path and additional information
99  };
100 
101  class SayInfo {
102  public:
103  SayInfo(const std::string& txt, uint32_t duration):
104  m_txt(txt),
105  m_duration(duration),
106  m_start_time(0) {}
107 
108  std::string m_txt;
111  };
112 
114  m_location(source.m_location),
115  m_oldLocation(source.m_location),
116  m_rotation(source.m_rotation),
117  m_oldRotation(source.m_rotation),
118  m_action(NULL),
119  m_soundSource(NULL),
120  m_speed(0),
121  m_timeMultiplier(1.0),
122  m_sayText(""),
123  m_changeListeners(),
124  m_actionListeners(),
125  m_actionInfo(NULL),
126  m_sayInfo(NULL),
127  m_timeProvider(NULL),
128  m_blocking(source.m_blocking),
129  m_additional(ICHANGE_NO_CHANGES) {
130  }
131 
133  delete m_actionInfo;
134  delete m_sayInfo;
135  delete m_timeProvider;
136  delete m_soundSource;
137  }
138 
142  source.m_changeInfo = m_additional;
144  }
145  if (m_location != source.m_location) {
146  source.m_changeInfo |= ICHANGE_LOC;
150  source.m_changeInfo |= ICHANGE_CELL;
151  }
152  m_location = source.m_location;
153  }
154  if (m_rotation != source.m_rotation) {
156  source.m_changeInfo |= ICHANGE_ROTATION;
157  m_rotation = source.m_rotation;
158  }
159  if (m_actionInfo && (m_speed != m_actionInfo->m_speed)) {
160  source.m_changeInfo |= ICHANGE_SPEED;
162  }
164  source.m_changeInfo |= ICHANGE_ACTION;
166  }
170  }
171  if (m_sayInfo && (m_sayText != m_sayInfo->m_txt)) {
172  source.m_changeInfo |= ICHANGE_SAYTEXT;
174  }
175  if (m_blocking != source.m_blocking) {
176  source.m_changeInfo |= ICHANGE_BLOCK;
177  m_blocking = source.m_blocking;
178  }
179 
180  if (source.m_changeInfo != ICHANGE_NO_CHANGES) {
181  std::vector<InstanceChangeListener*>::iterator i = m_changeListeners.begin();
182  while (i != m_changeListeners.end()) {
183  if (NULL != *i)
184  {
185  (*i)->onInstanceChanged(&source, source.m_changeInfo);
186  }
187  ++i;
188  }
189  // Really remove "removed" listeners.
190  m_changeListeners.erase(
191  std::remove(m_changeListeners.begin(),m_changeListeners.end(),
192  (InstanceChangeListener*)NULL),
193  m_changeListeners.end());
194  }
195  }
196 
197  Instance::Instance(Object* object, const Location& location, const std::string& identifier):
198  m_id(identifier),
199  m_rotation(0),
200  m_activity(NULL),
202  m_object(object),
203  m_ownObject(false),
204  m_location(location),
205  m_visual(NULL),
206  m_blocking(object->isBlocking()),
207  m_overrideBlocking(false),
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  // start sound
436  if (!m_activity->m_soundSource) {
437  m_activity->m_soundSource = new SoundSource(this);
438  }
440  } else if (old_action && old_action->getAudio()) {
442  }
443 
444  if (isMultiObject()) {
445  std::vector<Instance*>::iterator multi_it = m_multiInstances.begin();
446  for (; multi_it != m_multiInstances.end(); ++multi_it) {
447  (*multi_it)->initializeAction(actionName);
448  }
449  }
450  }
451 
452  void Instance::move(const std::string& actionName, const Location& target, const double speed, const std::string& costId) {
453  // if new move is identical with the old then return
454  if (m_activity) {
455  if (m_activity->m_actionInfo) {
459  m_activity->m_actionInfo->m_action == m_object->getAction(actionName) &&
460  costId == m_activity->m_actionInfo->m_route->getCostId()) {
461 
462  return;
463  }
464  }
465  }
466  }
467  initializeAction(actionName);
468  m_activity->m_actionInfo->m_target = new Location(target);
469  m_activity->m_actionInfo->m_speed = speed;
470  FL_DBG(_log, LMsg("starting action ") << actionName << " from" << m_location << " to " << target << " with speed " << speed);
471 
473  if (!route) {
475  route->setRotation(getRotation());
476  if (costId != "") {
477  route->setCostId(costId);
478  }
479  if (isMultiCell()) {
480  route->setObject(m_object);
483  } else if (m_object->getZStepRange() != -1 || !m_object->getWalkableAreas().empty()) {
484  route->setObject(m_object);
485  }
486  m_activity->m_actionInfo->m_route = route;
487  if (!m_activity->m_actionInfo->m_pather->solveRoute(route)) {
488  setFacingLocation(target);
489  finalizeAction();
490  }
491  }
492  }
493 
494  void Instance::follow(const std::string& actionName, Instance* leader, const double speed) {
495  initializeAction(actionName);
497  m_activity->m_actionInfo->m_speed = speed;
498  m_activity->m_actionInfo->m_leader = leader;
499  leader->addDeleteListener(this);
500  FL_DBG(_log, LMsg("starting action ") << actionName << " from" << m_location << " to " << *m_activity->m_actionInfo->m_target << " with speed " << speed);
501  }
502 
503  void Instance::follow(const std::string& actionName, Route* route, const double speed) {
504  initializeAction(actionName);
506  m_activity->m_actionInfo->m_speed = speed;
507  m_activity->m_actionInfo->m_route = route;
509  if (isMultiCell()) {
510  route->setObject(m_object);
513  } else if (m_object->getZStepRange() != -1 || !m_object->getWalkableAreas().empty()) {
514  route->setObject(m_object);
515  }
516  FL_DBG(_log, LMsg("starting action ") << actionName << " from" << m_location << " to " << *m_activity->m_actionInfo->m_target << " with speed " << speed);
517  }
518 
520  if (m_activity) {
522  if (info) {
523  Route* route = info->m_route;
524  if (route) {
525  route->cutPath(length);
526  }
527  }
528  }
529  }
530 
532  if (m_activity) {
534  if (info) {
535  return info->m_route;
536  }
537  }
538  return NULL;
539  }
540 
542  m_cellStackPos = stack;
543  }
544 
546  return m_cellStackPos;
547  }
548 
550  return m_specialCost;
551  }
552 
553  const std::vector<Instance*>& Instance::getMultiInstances() {
554  return m_multiInstances;
555  }
556 
558  m_mainMultiInstance = main;
559  }
560 
562  return m_mainMultiInstance;
563  }
564 
565  void Instance::actOnce(const std::string& actionName, const Location& direction) {
566  initializeAction(actionName);
568  setFacingLocation(direction);
569  }
570 
571  void Instance::actOnce(const std::string& actionName, int32_t rotation) {
572  initializeAction(actionName);
574  setRotation(rotation);
575  }
576 
577  void Instance::actOnce(const std::string& actionName) {
578  initializeAction(actionName);
580  }
581 
582  void Instance::actRepeat(const std::string& actionName, const Location& direction) {
583  initializeAction(actionName);
585  setFacingLocation(direction);
586  }
587 
588  void Instance::actRepeat(const std::string& actionName, int32_t rotation) {
589  initializeAction(actionName);
591  setRotation(rotation);
592  }
593 
594  void Instance::actRepeat(const std::string& actionName) {
595  initializeAction(actionName);
597  }
598 
599  void Instance::say(const std::string& text, uint32_t duration) {
601  delete m_activity->m_sayInfo;
602  m_activity->m_sayInfo = NULL;
603 
604  if (text != "") {
605  m_activity->m_sayInfo = new SayInfo(text, duration);
607  }
608  }
609 
610  const std::string* Instance::getSayText() const {
611  if (m_activity && m_activity->m_sayInfo) {
612  return &m_activity->m_sayInfo->m_txt;
613  }
614  return NULL;
615  }
616 
619  Route* route = info->m_route;
620  Location target;
621  if (info->m_leader) {
622  target = info->m_leader->getLocationRef();
623  } else {
624  target = *info->m_target;
625  }
626  if (!route) {
627  route = new Route(m_location, *info->m_target);
628  route->setRotation(getRotation());
629  info->m_route = route;
630  if (isMultiCell()) {
631  route->setObject(m_object);
634  } else if (m_object->getZStepRange() != -1 || !m_object->getWalkableAreas().empty()) {
635  route->setObject(m_object);
636  }
637  if (!info->m_pather->solveRoute(route)) {
638  setFacingLocation(target);
639  return true;
640  }
641  // update target if needed
642  } else if (route->getEndNode().getLayerCoordinates() != target.getLayerCoordinates()) {
643  if (route->isReplanned() || isMultiCell()) {
644  *info->m_target = route->getEndNode();
645  route->setReplanned(false);
646  if (isMultiCell()) {
649  }
650  } else {
651  if (route->getPathLength() == 0) {
652  route->setStartNode(m_location);
653  } else {
654  route->setStartNode(route->getCurrentNode());
655  }
656  route->setEndNode(target);
657  if (!info->m_pather->solveRoute(route)) {
658  setFacingLocation(target);
659  return true;
660  }
661  }
662  }
663 
664  if (route->getRouteStatus() == ROUTE_SOLVED) {
665  // timeslice for this movement
667  // how far we can travel
668  double distance_to_travel = (static_cast<double>(timedelta) / 1000.0) * info->m_speed;
669  // location for this movement
670  Location nextLocation = m_location;
671  bool can_follow = info->m_pather->followRoute(m_location, route, distance_to_travel, nextLocation);
672  if (can_follow) {
673  setRotation(route->getRotation());
674  // move to another layer
675  if (m_location.getLayer() != nextLocation.getLayer()) {
676  m_location.getLayer()->getMap()->addInstanceForTransfer(this, nextLocation);
677  if (!m_multiInstances.empty()) {
678  std::vector<Instance*>::iterator it = m_multiInstances.begin();
679  for (; it != m_multiInstances.end(); ++it) {
680  Location newloc = nextLocation;
681  std::vector<ModelCoordinate> tmpcoords = m_location.getLayer()->getCellGrid()->
682  toMultiCoordinates(nextLocation.getLayerCoordinates(), (*it)->getObject()->getMultiPartCoordinates(m_rotation));
683  newloc.setLayerCoordinates(tmpcoords.front());
685  }
686  }
687  return false;
688  }
689  setLocation(nextLocation);
690  return false;
691  }
692  // move to another layer
693  if (m_location.getLayer() != nextLocation.getLayer()) {
694  m_location.getLayer()->getMap()->addInstanceForTransfer(this, nextLocation);
695  if (!m_multiInstances.empty()) {
696  std::vector<Instance*>::iterator it = m_multiInstances.begin();
697  for (; it != m_multiInstances.end(); ++it) {
698  Location newloc = nextLocation;
699  std::vector<ModelCoordinate> tmpcoords = m_location.getLayer()->getCellGrid()->
700  toMultiCoordinates(nextLocation.getLayerCoordinates(), (*it)->getObject()->getMultiPartCoordinates(m_rotation));
701  newloc.setLayerCoordinates(tmpcoords.front());
703  }
704  }
705  return true;
706  }
707  setLocation(nextLocation);
708  // need new route?
710  if (m_location.getLayerDistanceTo(target) > 1.5) {
711  if (route->getPathLength() == 0) {
712  route->setStartNode(m_location);
713  } else {
714  route->setStartNode(route->getPreviousNode());
715  }
716  route->setEndNode(target);
719  return !info->m_pather->solveRoute(route);
720  }
721  setFacingLocation(target);
722  }
723  return true;
724  } else if (route->getRouteStatus() == ROUTE_FAILED) {
725  return true;
726  }
727  return false;
728  }
729 
731  if (!m_activity) {
732  return ICHANGE_NO_CHANGES;
733  }
734  // remove DeleteListeners
735  m_deleteListeners.erase(std::remove(m_deleteListeners.begin(),m_deleteListeners.end(),
737 
738  if (!m_activity->m_timeProvider) {
740  }
742  if (info) {
743 // FL_DBG(_log, "updating instance");
744 
745  if (info->m_target) {
746 // FL_DBG(_log, "action contains target for movement");
747  bool movement_finished = processMovement();
748  if (movement_finished) {
749 // FL_DBG(_log, "movement finished");
750  finalizeAction();
751  }
752  } else {
753 // FL_DBG(_log, "action does not contain target for movement");
755  if (info->m_repeating) {
757  // prock: offset no longer needed
758  info->m_action_offset_time = 0;
759  } else if (!m_object->isMultiPart()) {
760  finalizeAction();
761  }
762  }
763  }
764 
765  // previous code may invalidate actioninfo.
766  if( m_activity->m_actionInfo ) {
768  }
769  }
770  m_activity->update(*this);
771  if (m_activity->m_sayInfo) {
772  if (m_activity->m_sayInfo->m_duration > 0) {
774  say("");
775  }
776  }
778  // delete superfluous activity
779  delete m_activity;
780  m_activity = 0;
781  return ICHANGE_NO_CHANGES;
782  }
783  return m_changeInfo;
784  }
785 
787  FL_DBG(_log, "finalizing action");
788  assert(m_activity);
789  assert(m_activity->m_actionInfo);
790 
793  }
794 
796  delete m_activity->m_actionInfo;
797  m_activity->m_actionInfo = NULL;
798  // this is needed in case the new action is set on the same pump and
799  // it is the same action as the finalized action
800  m_activity->m_action = NULL;
801 
802  // stop audio
803  if (action->getAudio() && m_activity->m_soundSource) {
805  }
806 
807  if (isMultiObject()) {
808  std::vector<Instance*>::iterator multi_it = m_multiInstances.begin();
809  for (; multi_it != m_multiInstances.end(); ++multi_it) {
810  (*multi_it)->finalizeAction();
811  }
812  }
813  std::vector<InstanceActionListener*>::iterator i = m_activity->m_actionListeners.begin();
814  while (i != m_activity->m_actionListeners.end()) {
815  if(*i)
816  (*i)->onInstanceActionFinished(this, action);
817  ++i;
818  }
820  std::remove(m_activity->m_actionListeners.begin(),
822  (InstanceActionListener*)NULL),
824  }
825 
827  FL_DBG(_log, "cancel action");
828  assert(m_activity);
829  assert(m_activity->m_actionInfo);
830 
833  }
834 
836  delete m_activity->m_actionInfo;
837  m_activity->m_actionInfo = NULL;
838  // this is needed in case the new action is set on the same pump and
839  // it is the same action as the canceled action
840  m_activity->m_action = NULL;
841 
842  if (isMultiObject()) {
843  std::vector<Instance*>::iterator multi_it = m_multiInstances.begin();
844  for (; multi_it != m_multiInstances.end(); ++multi_it) {
845  (*multi_it)->cancelAction();
846  }
847  }
848  std::vector<InstanceActionListener*>::iterator i = m_activity->m_actionListeners.begin();
849  while (i != m_activity->m_actionListeners.end()) {
850  if(*i)
851  (*i)->onInstanceActionCancelled(this, action);
852  ++i;
853  }
855  std::remove(m_activity->m_actionListeners.begin(),
857  (InstanceActionListener*)NULL),
859  }
860 
864  }
865  return NULL;
866  }
867 
870  return *m_activity->m_actionInfo->m_target;
871  }
872  return m_location;
873  }
874 
875  double Instance::getMovementSpeed() const {
878  }
879  return 0;
880  }
881 
884  }
885 
888  }
889 
891  if (m_activity) {
892  return m_activity->m_oldLocation;
893  }
894  return m_location;
895  }
896 
897  int32_t Instance::getOldRotation() const {
898  if (m_activity) {
899  return m_activity->m_oldRotation;
900  }
901  return m_rotation;
902  }
903 
909  }
910  return getRuntime();
911  }
912 
915  }
916 
918  float multiplier = 1.0;
919  if (m_activity->m_timeProvider) {
920  multiplier = m_activity->m_timeProvider->getMultiplier();
921  }
922  delete m_activity->m_timeProvider;
923  m_activity->m_timeProvider = NULL;
924 
925  if (m_location.getLayer()) {
926  Map* map = m_location.getLayer()->getMap();
927  if (map) {
929  }
930  }
931  if (!m_activity->m_timeProvider) {
933  }
935  }
936 
940  }
941 
943  if (m_activity) {
944  return m_changeInfo;
945  }
946  return ICHANGE_NO_CHANGES;
947  }
948 
952  }
953 
957  }
958 
962  }
963 
964  void Instance::setTimeMultiplier(float multip) {
966  if (!m_activity->m_timeProvider) {
968  }
970  }
971 
975  }
976  return 1.0;
977  }
978 
982  }
983  if (m_location.getLayer()) {
984  Map* map = m_location.getLayer()->getMap();
985  if (map && map->getTimeProvider()) {
986  return map->getTimeProvider()->getTotalMultiplier();
987  }
988  }
989  return 1.0;
990  }
991 
993  if (m_activity) {
997  }
998  if (m_location.getLayer()) {
999  Map* map = m_location.getLayer()->getMap();
1000  if (map && map->getTimeProvider()) {
1001  return map->getTimeProvider()->getGameTime();
1002  }
1003  }
1004  return TimeManager::instance()->getTime();
1005  }
1006 
1007  void Instance::setCost(const std::string& id, double cost) {
1008  m_specialCost = true;
1009  m_costId = id;
1010  m_cost = cost;
1011  }
1012 
1014  m_specialCost = false;
1015  }
1016 
1018  if (m_specialCost) {
1019  return m_cost;
1020  }
1021  return m_object->getCost();
1022  }
1023 
1024  std::string Instance::getCostId() {
1025  if (m_specialCost) {
1026  return m_costId;
1027  }
1028  return m_object->getCostId();
1029  }
1030 
1032  return m_object->getSpeed();
1033  }
1034 
1036  return m_object->isSpecialSpeed();
1037  }
1038 
1040  return m_object->isMultiObject();
1041  }
1042 
1044  return !m_multiInstances.empty();
1045  }
1046 
1048  if (!m_multiInstances.empty()) {
1049  // use map coords for rotation and movement
1050  // instances are changed on InstanceTree but not on CellCache
1051  Location loc = m_location;
1053  const ExactModelCoordinate& offset = m_object->getRotationAnchor();
1054  loc.setExactLayerCoordinates(offset);
1055  const ExactModelCoordinate anchor_offset = loc.getMapCoordinates();
1056  int32_t rot = m_rotation;
1057  if (m_object->isRestrictedRotation()) {
1059  }
1060  double mcos = Mathd::Cos(double(rot) * (Mathd::pi()/180.0));
1061  double msin = Mathd::Sin(double(rot) * (Mathd::pi()/180.0));
1062  std::vector<Instance*>::iterator it = m_multiInstances.begin();
1063  for (; it != m_multiInstances.end(); ++it) {
1064  // use rotation 0 to get the "default" coordinate
1065  std::vector<ModelCoordinate> mcv = (*it)->getObject()->getMultiPartCoordinates(0);
1066  loc.setLayerCoordinates(mcv.front());
1068  ExactModelCoordinate nemc(emc.x-anchor_offset.x, emc.y-anchor_offset.y);
1069  emc.x = ((nemc.x * mcos + nemc.y * msin) + anchor_offset.x) + anchor.x;
1070  emc.y = ((-nemc.x * msin + nemc.y * mcos) + anchor_offset.y) + anchor.y;
1071  loc.setMapCoordinates(emc);
1072  (*it)->setLocation(loc);
1073  (*it)->setRotation(rot);
1074  }
1075  }
1076  }
1077 
1079  if (!m_ownObject) {
1080  createOwnObject();
1081  }
1083  objVis->addStaticColorOverlay(angle, colors);
1084  prepareForUpdate();
1086  }
1087 
1089  if (!m_ownObject) {
1090  return 0;
1091  }
1093  return objVis->getStaticColorOverlay(angle);
1094  }
1095 
1097  if (m_ownObject) {
1099  objVis->removeStaticColorOverlay(angle);
1100  prepareForUpdate();
1102  }
1103  }
1104 
1106  if (!m_ownObject) {
1107  return false;
1108  }
1110  return objVis->isColorOverlay();
1111  }
1112 
1113  void Instance::addColorOverlay(const std::string& actionName, uint32_t angle, const OverlayColors& colors) {
1114  ActionVisual* visual = getActionVisual(actionName, true);
1115  if (visual) {
1116  visual->addColorOverlay(angle, colors);
1117  prepareForUpdate();
1119  }
1120  }
1121 
1122  OverlayColors* Instance::getColorOverlay(const std::string& actionName, uint32_t angle) {
1123  ActionVisual* visual = getActionVisual(actionName, false);
1124  if (visual) {
1125  return visual->getColorOverlay(angle);
1126  }
1127  return NULL;
1128  }
1129 
1130  void Instance::removeColorOverlay(const std::string& actionName, int32_t angle) {
1131  ActionVisual* visual = getActionVisual(actionName, false);
1132  if (visual) {
1133  visual->removeColorOverlay(angle);
1134  prepareForUpdate();
1136  }
1137  }
1138 
1139  void Instance::addAnimationOverlay(const std::string& actionName, uint32_t angle, int32_t order, const AnimationPtr& animationptr) {
1140  ActionVisual* visual = getActionVisual(actionName, true);
1141  if (visual) {
1142  visual->addAnimationOverlay(angle, order, animationptr);
1143  prepareForUpdate();
1145  }
1146  }
1147 
1148  std::map<int32_t, AnimationPtr> Instance::getAnimationOverlay(const std::string& actionName, int32_t angle) {
1149  ActionVisual* visual = getActionVisual(actionName, false);
1150  if (visual) {
1151  return visual->getAnimationOverlay(angle);
1152  }
1153  return std::map<int32_t, AnimationPtr>();
1154  }
1155 
1156  void Instance::removeAnimationOverlay(const std::string& actionName, uint32_t angle, int32_t order) {
1157  ActionVisual* visual = getActionVisual(actionName, false);
1158  if (visual) {
1159  visual->removeAnimationOverlay(angle, order);
1160  prepareForUpdate();
1162  }
1163  }
1164 
1165  void Instance::addColorOverlay(const std::string& actionName, uint32_t angle, int32_t order, const OverlayColors& colors) {
1166  ActionVisual* visual = getActionVisual(actionName, true);
1167  if (visual) {
1168  visual->addColorOverlay(angle, order, colors);
1169  prepareForUpdate();
1171  }
1172  }
1173 
1174  OverlayColors* Instance::getColorOverlay(const std::string& actionName, uint32_t angle, int32_t order) {
1175  ActionVisual* visual = getActionVisual(actionName, false);
1176  if (visual) {
1177  return visual->getColorOverlay(angle, order);
1178  }
1179  return NULL;
1180  }
1181 
1182  void Instance::removeColorOverlay(const std::string& actionName, int32_t angle, int32_t order) {
1183  ActionVisual* visual = getActionVisual(actionName, false);
1184  if (visual) {
1185  visual->removeColorOverlay(angle, order);
1186  prepareForUpdate();
1188  }
1189  }
1190 
1191  bool Instance::isAnimationOverlay(const std::string& actionName) {
1192  ActionVisual* visual = getActionVisual(actionName, false);
1193  if (visual) {
1194  return visual->isAnimationOverlay();
1195  }
1196  return false;
1197  }
1198 
1199  bool Instance::isColorOverlay(const std::string& actionName) {
1200  ActionVisual* visual = getActionVisual(actionName, false);
1201  if (visual) {
1202  return visual->isColorOverlay();
1203  }
1204  return false;
1205  }
1206 
1207  void Instance::convertToOverlays(const std::string& actionName, bool color) {
1208  ActionVisual* visual = getActionVisual(actionName, true);
1209  visual->convertToOverlays(color);
1210  }
1211 
1213  if (!m_ownObject) {
1214  m_ownObject = true;
1216  ObjectVisual* nov = 0;
1218  if (!ov) {
1220  } else {
1221  nov = new ObjectVisual(*ov);
1222  m_object->adoptVisual(nov);
1223  }
1224  }
1225  }
1226 
1227  ActionVisual* Instance::getActionVisual(const std::string& actionName, bool create) {
1228  ActionVisual* nav = NULL;
1229  if (!m_ownObject) {
1230  createOwnObject();
1231  }
1232  Action* action = m_object->getAction(actionName, false);
1233  if (!action) {
1234  action = m_object->getAction(actionName);
1235  if (!action) {
1236  throw NotFound(std::string("action ") + actionName + " not found");
1237  } else if (create) {
1238  // if we change the current action then we have to replace the pointer
1239  bool replace = getCurrentAction() == action;
1240  // check if its the default action
1241  bool defaultAction = m_object->getDefaultAction() == action;
1242  ActionVisual* av = action->getVisual<ActionVisual>();
1243  action = m_object->createAction(actionName, defaultAction);
1244  nav = new ActionVisual(*av);
1245  action->adoptVisual(nav);
1246  if (replace) {
1247  m_activity->m_actionInfo->m_action = action;
1248  }
1249  }
1250  } else {
1251  nav = action->getVisual<ActionVisual>();
1252  }
1253  return nav;
1254  }
1255 
1257  m_deleteListeners.push_back(listener);
1258  }
1259 
1261  if (!m_deleteListeners.empty()) {
1262  std::vector<InstanceDeleteListener*>::iterator itor;
1263  itor = std::find(m_deleteListeners.begin(), m_deleteListeners.end(), listener);
1264  if(itor != m_deleteListeners.end()) {
1265  if ((*itor) == listener) {
1266  *itor = NULL;
1267  return;
1268  }
1269  } else {
1270  FL_WARN(_log, "Cannot remove unknown listener");
1271  }
1272  }
1273  }
1274 
1277  m_activity->m_actionInfo->m_leader == instance) {
1278  m_activity->m_actionInfo->m_leader = NULL;
1279  }
1280  if (isMultiObject()) {
1281  std::vector<Instance*>::iterator multi_it = m_multiInstances.begin();
1282  for (; multi_it != m_multiInstances.end(); ++multi_it) {
1283  if (*multi_it == instance) {
1284  m_multiInstances.erase(multi_it);
1285  break;
1286  }
1287  }
1288  }
1289  }
1290 }
bool isMultiObject()
Returns true if it is multi object otherwise false.
Definition: instance.cpp:1043
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:954
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:197
void setOccupiedArea(const std::vector< ModelCoordinate > &area)
Sets occupied coordinates for multi cell object.
Definition: route.cpp:254
std::list< std::string > getWalkableAreas() const
Returns a list that contains all walkable area ids.
Definition: object.cpp:606
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
Action * getAction(const std::string &identifier, bool deepsearch=true) const
Gets action with given id.
Definition: object.cpp:121
void cutPath(uint32_t length=1)
Cuts path after the given length.
Definition: route.cpp:181
std::string getCostId() const
Returns the cost id.
Definition: object.cpp:292
void initializeAction(const std::string &actionName)
Initialize action for use.
Definition: instance.cpp:415
std::string getCostId()
Returns cost id.
Definition: instance.cpp:1024
InstanceActivity * m_activity
Definition: instance.h:570
void updateMultiInstances()
Updates the visual positions of all instances in case this is a multi object.
Definition: instance.cpp:1047
int32_t getAngleBetween(const Location &loc1, const Location &loc2)
Gets angle of vector defined by given locations.
Definition: angles.cpp:98
IPather * getPather() const
Gets associated pather.
Definition: object.cpp:195
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:217
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:494
std::vector< ModelCoordinate > getMultiObjectCoordinates(int32_t rotation) const
Returns all multi object coordinates for the given rotation.
Definition: object.cpp:478
void setMultiplier(float multiplier)
With multiplier, you can adjust the time speed.
uint32_t getTime() const
Get the time.
IPather * m_pather
Definition: instance.cpp:93
InstanceActivity(Instance &source)
Definition: instance.cpp:113
Action * m_action
action on previous round. NOTE: might become invalid, only used for address comparison ...
Definition: instance.h:544
void setActionAudio(ActionAudio *audio)
Sets the ActionAudio.
Definition: soundsource.cpp:82
double getSpeed() const
Returns the speed modifier.
Definition: object.cpp:336
void createOwnObject()
Creates an own object for the instance to allow visual customization.
Definition: instance.cpp:1212
void setExactLayerCoordinates(const ExactModelCoordinate &coordinates)
Sets precise layer coordinates to this location.
Definition: location.cpp:87
void addActionListener(InstanceActionListener *listener)
Adds new instance action listener.
Definition: instance.cpp:361
void cancelAction()
Cancel current action.
Definition: instance.cpp:826
double getMovementSpeed() const
Gets the speed in case instance is moving otherwise returns 0.
Definition: instance.cpp:875
bool m_ownObject
indicates if m_object is customized
Definition: instance.h:579
const Location & getPreviousNode()
Returns previous location.
Definition: route.cpp:108
Layer * getLayer() const
Gets the layer where this location is pointing to.
Definition: location.cpp:83
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
Interface class between Instance / ActionAudio and SoundEmitter.
Definition: soundsource.h:45
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:89
void addDeleteListener(InstanceDeleteListener *listener)
Adds new instance delete listener.
Definition: instance.cpp:1256
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:1139
void callOnActionFrame(Action *action, int32_t frame)
Auxiliary function to inform ActionListeners about the active ActionFrame.
Definition: instance.cpp:386
ActionAudio * getAudio() const
Gets used audio.
Definition: action.h:82
void setLayer(Layer *layer)
Sets layer where this location is pointing to.
Definition: location.cpp:79
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:87
bool m_blocking
blocking status on previous round
Definition: instance.h:566
bool isAnimationOverlay(const std::string &actionName)
Indicates if there exists a animation overlay for given action.
Definition: instance.cpp:1191
bool isColorOverlay(const std::string &actionName)
Indicates if there exists a color overlay for given action or animation overlay.
Definition: instance.cpp:1199
bool isSpecialSpeed()
Returns true if instance or object have special speed modifier otherwise false.
Definition: instance.cpp:1035
SoundSource * m_soundSource
sound source of action audio on previous round
Definition: instance.h:546
void setMainMultiInstance(Instance *main)
Sets a instance to the main multi instance of this instance.
Definition: instance.cpp:557
void setFacingLocation(const Location &loc)
Sets the direction where instance is heading.
Definition: instance.cpp:882
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
std::vector< InstanceDeleteListener * > m_deleteListeners
listeners for deletion of the instance
Definition: instance.h:574
InstanceChangeInfo getChangeInfo()
Returns a bitmask of changes of the last update.
Definition: instance.cpp:942
const Location & getEndNode()
Returns the target location.
Definition: route.cpp:94
bool m_blocking
instance blocking info
Definition: instance.h:585
uint32_t m_start_time
Definition: instance.cpp:110
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:1156
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
bool isActive() const
If this returns true, the instance needs to be updated.
Definition: instance.cpp:288
static Logger _log(LM_AUDIO)
void cancelMovement(uint32_t length=1)
Cancel movement after a given length.
Definition: instance.cpp:519
Location m_location
current location
Definition: instance.h:581
uint32_t getActionRuntime()
Gets the time in milliseconds how long action has been active In case there is no current action...
Definition: instance.cpp:904
ActionVisual * getActionVisual(const std::string &actionName, bool create)
Returns pointer to action visual, can also create it.
Definition: instance.cpp:1227
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:913
void removeStaticColorOverlay(int32_t angle)
Removes a static color overlay with given angle (degrees).
Definition: visual.cpp:147
Action * m_action
Definition: instance.cpp:79
std::string m_sayText
say text on previous round
Definition: instance.h:552
bool isSpecialCost()
Returns true if instance or object have special cost otherwise false.
Definition: instance.cpp:549
const std::string & getId() const
Definition: object.h:68
static TimeManager * instance()
Definition: singleton.h:84
Location & getLocationRef()
Gets reference of current location of instance.
Definition: instance.cpp:315
A basic route.
Definition: route.h:64
void callOnTransparencyChange()
Definition: instance.cpp:949
uint32_t m_prev_call_time
Definition: instance.cpp:91
OverlayColors * getStaticColorOverlay(int32_t angle)
Returns closest matching static color overlay for given angle.
Definition: visual.cpp:139
float getTotalMultiplier() const
void update(Instance &source)
updates cached variables, marks changes
Definition: instance.cpp:139
double getCost() const
Returns the cost.
Definition: object.cpp:309
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:1207
void removeDeleteListener(InstanceDeleteListener *listener)
Removes associated instance delete listener.
Definition: instance.cpp:1260
const std::string * getSayText() const
Returns pointer to currently set saytext.
Definition: instance.cpp:610
OverlayColors * getStaticColorOverlay(int32_t angle)
Returns closest matching static color overlay for given angle.
Definition: instance.cpp:1088
ActionInfo(IPather *pather, const Location &curloc)
Definition: instance.cpp:54
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
double m_speed
speed on previous round
Definition: instance.h:548
unsigned char uint8_t
Definition: core.h:38
IVisual * m_visual
instance visualization
Definition: instance.h:583
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:517
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
uint32_t getGameTime() const
Returns current game ticks, already scaled.
const std::vector< Instance * > & getMultiInstances()
Returns a vector that contains all instances of a multi object.
Definition: instance.cpp:553
static bool Equal(T _val1, T _val2)
Definition: fife_math.h:287
Location getTargetLocation() const
Gets movement target in case instance is moving.
Definition: instance.cpp:868
Instance * m_mainMultiInstance
pointer to the main multi instance
Definition: instance.h:599
std::vector< InstanceActionListener * > m_actionListeners
listeners for action related events
Definition: instance.h:558
void addColorOverlay(uint32_t angle, const OverlayColors &colors)
Adds new color overlay with given angle (degrees) and colors.
Definition: visual.cpp:275
double getLayerDistanceTo(const Location &location) const
Gets layer distance to another location.
Definition: location.cpp:180
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:554
uint32_t InstanceChangeInfo
Definition: instance.h:77
float m_timeMultiplier
time multiplier on previous round
Definition: instance.h:550
void callOnStackPositionChange()
Definition: instance.cpp:959
static T Sin(T _val)
Definition: fife_math.h:267
const std::string & getNamespace() const
Definition: object.h:69
void addAnimationOverlay(uint32_t angle, int32_t order, AnimationPtr animationptr)
Adds new animation overlay with given angle (degrees) and order.
Definition: visual.cpp:250
int32_t getSessionId()
Returns the session identifier.
Definition: route.cpp:227
Location & getOldLocationRef()
Gets reference of old location of instance.
Definition: instance.cpp:890
Location * m_target
Definition: instance.cpp:81
A basic layer on a map.
Definition: layer.h:99
Instance * m_leader
Definition: instance.cpp:95
OverlayColors * getColorOverlay(const std::string &actionName, uint32_t angle)
Returns closest matching color overlay for given angle and action.
Definition: instance.cpp:1122
Location getFacingLocation()
Returns the direction where instance is heading.
Definition: instance.cpp:886
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:1096
void addInstanceForTransfer(Instance *instance, const Location &target)
Adds instance that is to be transferred to another layer.
Definition: map.cpp:306
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:1113
void setTimeMultiplier(float multip)
Sets speed for the map.
Definition: instance.cpp:964
uint32_t m_duration
Definition: instance.cpp:109
bool isRestrictedRotation() const
Gets if object uses restricted rotations.
Definition: object.cpp:532
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:545
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:561
void onInstanceDeleted(Instance *instance)
callback so other instances we depend on can notify us if they go away
Definition: instance.cpp:1275
void removeInstance(Instance *instance)
Removes an instance from the quad tree.
bool isStaticColorOverlay()
Indicates if there exists a static color overlay.
Definition: instance.cpp:1105
InstanceActivity gets allocated in case there is some runtime activity related to the instance...
Definition: instance.h:527
ExactModelCoordinate & getExactLayerCoordinatesRef()
Gets reference to exact layer coordinates.
Definition: location.cpp:105
Location m_location
location on previous round
Definition: instance.h:536
void setReplanned(bool replanned)
Sets the route to replanned.
Definition: route.cpp:207
bool isMultiObject() const
Gets if object uses special cost.
Definition: object.cpp:346
void bindTimeProvider()
rebinds time provider based on new location
Definition: instance.cpp:917
void addInstance(Instance *instance)
Adds an instance to the quad tree.
std::string m_id
Definition: instance.h:513
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
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:568
void finalizeAction()
Finalize current action.
Definition: instance.cpp:786
Action * getCurrentAction() const
Gets the currently active action.
Definition: instance.cpp:861
ActionInfo * m_actionInfo
action information, allocated when actions are bind
Definition: instance.h:560
void setCellStackPosition(uint8_t stack)
Sets the cell stack position.
Definition: instance.cpp:541
double m_cost
holds cost value
Definition: instance.h:593
TimeProvider * m_timeProvider
time scaler for this instance
Definition: instance.h:564
SayInfo * m_sayInfo
text to say + duration, allocated when something is said
Definition: instance.h:562
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.
InstanceTree * getInstanceTree(void) const
Get the instance tree.
Definition: layer.cpp:101
CellGrid * getCellGrid() const
Get the Cellgrid.
Definition: layer.cpp:93
void actOnce(const std::string &actionName, const Location &direction)
Performs given named action to the instance, once only.
Definition: instance.cpp:565
InstanceChangeInfo m_changeInfo
bitmask stating current changes
Definition: instance.h:572
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:103
bool m_specialCost
indicates special cost
Definition: instance.h:591
int32_t getOldRotation() const
Get the old rotation offset of this instance Returns direction where instance was heading...
Definition: instance.cpp:897
std::string m_txt
Definition: instance.cpp:108
float getMultiplier() const
std::string m_costId
holds cost id
Definition: instance.h:595
Action * getDefaultAction() const
Gets default action assigned to this object.
Definition: object.cpp:178
std::vector< Instance * > m_multiInstances
vector that holds all multi instances
Definition: instance.h:597
double getCost()
Returns cost value.
Definition: instance.cpp:1017
float getTotalTimeMultiplier()
Gets instance speed, considering also model and map speeds.
Definition: instance.cpp:979
int32_t getZStepRange() const
Returns z-step range from object.
Definition: object.cpp:563
void addStaticColorOverlay(uint32_t angle, const OverlayColors &colors)
Adds new static color overlay with given angle (degrees).
Definition: instance.cpp:1078
void removeColorOverlay(const std::string &actionName, int32_t angle)
Removes a color overlay with given angle (degrees) from given action.
Definition: instance.cpp:1130
float getTimeMultiplier()
Gets instance speed.
Definition: instance.cpp:972
void resetCost()
Resets cost.
Definition: instance.cpp:1013
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:582
static num_type pi()
Definition: fife_math.h:134
InstanceChangeInfo update()
Updates the instance related to the current action.
Definition: instance.cpp:730
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:538
uint32_t getDuration()
Gets the duration of this action.
Definition: action.h:66
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
ExactModelCoordinate getMapCoordinates() const
Gets map coordinates set to this location.
Definition: location.cpp:117
ModelCoordinate getLayerCoordinates() const
Gets cell precision layer coordinates set to this location.
Definition: location.cpp:113
TimeProvider * getTimeProvider()
Gets timeprovider used in the map.
Definition: map.h:155
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:992
Map * getMap() const
Get the map this layer is contained in.
Definition: layer.cpp:89
Route * getRoute()
Returns a pointer to the route, in case there is no, it returns NULL.
Definition: instance.cpp:531
bool isBlocking() const
Gets if instance blocks movement.
Definition: instance.cpp:349
void refresh()
Refreshes instance e.g.
Definition: instance.cpp:937
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:1148
void setInstanceActivityStatus(Instance *instance, bool active)
Sets the activity status for given instance on this layer.
Definition: layer.cpp:233
T * getVisual() const
Gets used visualization.
Definition: action.h:74
A container of Layer(s).
Definition: map.h:88
bool isSpecialSpeed() const
Gets if object uses special speed modifier.
Definition: object.cpp:319
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:452
unsigned int uint32_t
Definition: core.h:40
T * getVisual() const
Gets used visualization.
Definition: object.h:122
Object * m_object
object where instantiated from
Definition: instance.h:577
bool isMultiCell()
Returns true if it is multi cell otherwise false.
Definition: instance.cpp:1039
Location getFacing(const Location &loc, const int32_t angle)
Gets facing location defined by given angle and location.
Definition: angles.cpp:113
int32_t getRestrictedRotation(int32_t rotation)
Returns the most obvious rotation, based on multi coordinates.
Definition: object.cpp:542
bool isReplanned()
Gets if the route is replanned.
Definition: route.cpp:211
uint8_t m_cellStackPos
position on cell stack
Definition: instance.h:589
int32_t m_rotation
rotation on previous round
Definition: instance.h:540
void setLocation(const Location &loc)
Sets location of the instance.
Definition: instance.cpp:296
#define FL_DBG(logger, msg)
Definition: logger.h:70
int32_t getRotation() const
Get the rotation offset of this instance Returns direction where instance is heading.
Definition: instance.cpp:330
An Instance is an "instantiation" of an Object at a Location.
Definition: instance.h:94
bool processMovement()
Moves instance. Returns true if finished.
Definition: instance.cpp:617
bool m_overrideBlocking
allow to override the blocking property
Definition: instance.h:587
std::map< int32_t, AnimationPtr > getAnimationOverlay(int32_t angle)
Gets map with animations closest to given angle.
Definition: visual.cpp:256
bool isMultiPart() const
Gets if object is a part of a multi object.
Definition: object.cpp:393
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
bool isOverrideBlocking() const
Gets if instance blocking can overriden.
Definition: instance.cpp:357
void setCost(const std::string &id, double cost)
Sets for the given cost id a cost.
Definition: instance.cpp:1007
Route * m_route
Definition: instance.cpp:97
double getSpeed()
Returns speed modifier.
Definition: instance.cpp:1031
Location getLocation() const
Gets current location of instance.
Definition: instance.cpp:311
int32_t m_oldRotation
rotation on previous round
Definition: instance.h:542
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:599