FIFE  6e1afdbeda11afe9ac53e6023a4be96ef88f1dc6
instance.cpp
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2005-2017 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),
208  m_isVisitor(false),
210  m_visitorRadius(0),
212  m_specialCost(object->isSpecialCost()),
213  m_cost(object->getCost()),
214  m_costId(object->getCostId()),
215  m_mainMultiInstance(NULL) {
216  // create multi object instances
217  if (object->isMultiObject()) {
218  m_mainMultiInstance = this;
219  uint32_t count = 0;
220  Layer* layer = m_location.getLayer();
222  const std::set<Object*>& multis = object->getMultiParts();
223  std::set<Object*>::const_iterator it = multis.begin();
224  for (; it != multis.end(); ++it, ++count) {
225  if (*it == m_object) {
226  continue;
227  }
228  std::vector<ModelCoordinate> partcoords = (*it)->getMultiPartCoordinates(m_rotation);
229  std::vector<ModelCoordinate>::iterator coordit = partcoords.begin();
230  for (; coordit != partcoords.end(); ++coordit) {
231  ExactModelCoordinate tmp_emc(emc.x+(*coordit).x, emc.y+(*coordit).y, emc.z+(*coordit).z);
232  std::ostringstream counter;
233  counter << count;
234  Instance* instance = layer->createInstance(*it, tmp_emc, identifier+counter.str());
235  InstanceVisual::create(instance);
236  m_multiInstances.push_back(instance);
237  instance->addDeleteListener(this);
238  instance->setMainMultiInstance(this);
239  }
240  }
241  }
242  }
243 
245  std::vector<InstanceDeleteListener *>::iterator itor;
246  for(itor = m_deleteListeners.begin(); itor != m_deleteListeners.end(); ++itor) {
247  if (*itor != NULL) {
248  (*itor)->onInstanceDeleted(this);
249  }
250  }
251 
253  // Don't ditribute onActionFinished in case we're already
254  // deleting.
255  m_activity->m_actionListeners.clear();
256  finalizeAction();
257  }
258 
259  if (!m_multiInstances.empty()) {
260  std::vector<Instance*>::iterator it = m_multiInstances.begin();
261  for (; it != m_multiInstances.end(); ++it) {
262  (*it)->removeDeleteListener(this);
263  (*it)->setMainMultiInstance(NULL);
264  }
265  }
266 
267  delete m_activity;
268  delete m_visual;
269  if (m_ownObject) {
270  delete m_object;
271  }
272  }
273 
275  if (!m_activity) {
276  m_activity = new InstanceActivity(*this);
277  }
278  if (m_location.getLayer()) {
280  }
281  }
282 
284  if (isActive()) {
285  refresh();
286  } else {
288  }
289  }
290 
291  bool Instance::isActive() const {
292  return (m_activity != 0);
293  }
294 
296  return m_object;
297  }
298 
299  void Instance::setLocation(const Location& loc) {
300  // ToDo: Handle the case when the layers are different
301  if(m_location != loc) {
303 
306  m_location = loc;
308  } else {
309  m_location = loc;
310  }
311  }
312  }
313 
315  return m_location;
316  }
317 
319  return m_location;
320  }
321 
322  void Instance::setRotation(int32_t rotation) {
323  while (rotation < 0) {
324  rotation += 360;
325  }
326  rotation %= 360;
327  if(m_rotation != rotation) {
329  m_rotation = rotation;
330  }
331  }
332 
333  int32_t Instance::getRotation() const {
334  return m_rotation;
335  }
336 
337  void Instance::setId(const std::string& identifier) {
338  m_id = identifier;
339  }
340 
341  const std::string& Instance::getId() {
342  return m_id;
343  }
344 
345  void Instance::setBlocking(bool blocking) {
346  if (m_overrideBlocking) {
348  m_blocking = blocking;
349  }
350  }
351 
352  bool Instance::isBlocking() const {
353  return m_blocking;
354  }
355 
356  void Instance::setOverrideBlocking(bool overblock) {
357  m_overrideBlocking = overblock;
358  }
359 
361  return m_overrideBlocking;
362  }
363 
366  m_activity->m_actionListeners.push_back(listener);
367  }
368 
370  if (!m_activity) {
371  return;
372  }
373  std::vector<InstanceActionListener*>::iterator i = m_activity->m_actionListeners.begin();
374  while (i != m_activity->m_actionListeners.end()) {
375  if ((*i) == listener) {
376  *i = NULL;
377  return;
378  }
379  ++i;
380  }
381  FL_WARN(_log, "Cannot remove unknown listener");
382  }
383 
386  m_activity->m_changeListeners.push_back(listener);
387  }
388 
389  void Instance::callOnActionFrame(Action* action, int32_t frame) {
390  if (!m_activity) {
391  return;
392  }
393 
394  std::vector<InstanceActionListener*>::iterator i = m_activity->m_actionListeners.begin();
395  while (i != m_activity->m_actionListeners.end()) {
396  if(*i) {
397  (*i)->onInstanceActionFrame(this, action, frame);
398  }
399  ++i;
400  }
401  }
402 
404  if (!m_activity) {
405  return;
406  }
407  std::vector<InstanceChangeListener*>::iterator i = m_activity->m_changeListeners.begin();
408  while (i != m_activity->m_changeListeners.end()) {
409  if ((*i) == listener) {
410  *i = NULL;
411  return;
412  }
413  ++i;
414  }
415  FL_WARN(_log, "Cannot remove unknown listener");
416  }
417 
418  void Instance::initializeAction(const std::string& actionName) {
419  assert(m_object);
420 
422  const Action *old_action = m_activity->m_actionInfo ? m_activity->m_actionInfo->m_action : NULL;
423  if (m_activity->m_actionInfo) {
424  cancelAction();
425  }
429  delete m_activity->m_actionInfo;
430  m_activity->m_actionInfo = NULL;
431  throw NotFound(std::string("action ") + actionName + " not found");
432  }
434  if (m_activity->m_actionInfo->m_action != old_action) {
436  }
437  // start sound
439  if (!m_activity->m_soundSource) {
440  m_activity->m_soundSource = new SoundSource(this);
441  }
443  } else if (old_action && old_action->getAudio()) {
445  }
446 
447  if (isMultiObject()) {
448  std::vector<Instance*>::iterator multi_it = m_multiInstances.begin();
449  for (; multi_it != m_multiInstances.end(); ++multi_it) {
450  (*multi_it)->initializeAction(actionName);
451  }
452  }
453  }
454 
455  void Instance::move(const std::string& actionName, const Location& target, const double speed, const std::string& costId) {
456  // if new move is identical with the old then return
457  if (m_activity) {
458  if (m_activity->m_actionInfo) {
462  m_activity->m_actionInfo->m_action == m_object->getAction(actionName) &&
463  costId == m_activity->m_actionInfo->m_route->getCostId()) {
464 
465  return;
466  }
467  }
468  }
469  }
470  initializeAction(actionName);
471  m_activity->m_actionInfo->m_target = new Location(target);
472  m_activity->m_actionInfo->m_speed = speed;
473  FL_DBG(_log, LMsg("starting action ") << actionName << " from" << m_location << " to " << target << " with speed " << speed);
474 
476  if (!route) {
478  route->setRotation(getRotation());
479  if (costId != "") {
480  route->setCostId(costId);
481  }
482  if (isMultiCell()) {
483  route->setObject(m_object);
486  } else if (m_object->getZStepRange() != -1 || !m_object->getWalkableAreas().empty()) {
487  route->setObject(m_object);
488  }
489  m_activity->m_actionInfo->m_route = route;
490  if (!m_activity->m_actionInfo->m_pather->solveRoute(route)) {
491  setFacingLocation(target);
492  finalizeAction();
493  }
494  }
495  }
496 
497  void Instance::follow(const std::string& actionName, Instance* leader, const double speed) {
498  initializeAction(actionName);
500  m_activity->m_actionInfo->m_speed = speed;
501  m_activity->m_actionInfo->m_leader = leader;
502  leader->addDeleteListener(this);
503  FL_DBG(_log, LMsg("starting action ") << actionName << " from" << m_location << " to " << *m_activity->m_actionInfo->m_target << " with speed " << speed);
504  }
505 
506  void Instance::follow(const std::string& actionName, Route* route, const double speed) {
507  initializeAction(actionName);
509  m_activity->m_actionInfo->m_speed = speed;
510  m_activity->m_actionInfo->m_route = route;
512  if (isMultiCell()) {
513  route->setObject(m_object);
516  } else if (m_object->getZStepRange() != -1 || !m_object->getWalkableAreas().empty()) {
517  route->setObject(m_object);
518  }
519  FL_DBG(_log, LMsg("starting action ") << actionName << " from" << m_location << " to " << *m_activity->m_actionInfo->m_target << " with speed " << speed);
520  }
521 
523  if (m_activity) {
525  if (info) {
526  Route* route = info->m_route;
527  if (route) {
528  route->cutPath(length);
529  }
530  }
531  }
532  }
533 
535  if (m_activity) {
537  if (info) {
538  return info->m_route;
539  }
540  }
541  return NULL;
542  }
543 
544  void Instance::setVisitor(bool visit) {
545  m_isVisitor = visit;
546  }
547 
549  return m_isVisitor;
550  }
551 
553  m_visitorShape = info;
554  }
555 
557  return m_visitorShape;
558  }
559 
561  m_visitorRadius = radius;
562  }
563 
565  return m_visitorRadius;
566  }
567 
569  m_cellStackPos = stack;
570  }
571 
573  return m_cellStackPos;
574  }
575 
577  return m_specialCost;
578  }
579 
580  const std::vector<Instance*>& Instance::getMultiInstances() {
581  return m_multiInstances;
582  }
583 
585  m_mainMultiInstance = main;
586  }
587 
589  return m_mainMultiInstance;
590  }
591 
592  void Instance::actOnce(const std::string& actionName, const Location& direction) {
593  initializeAction(actionName);
595  setFacingLocation(direction);
596  }
597 
598  void Instance::actOnce(const std::string& actionName, int32_t rotation) {
599  initializeAction(actionName);
601  setRotation(rotation);
602  }
603 
604  void Instance::actOnce(const std::string& actionName) {
605  initializeAction(actionName);
607  }
608 
609  void Instance::actRepeat(const std::string& actionName, const Location& direction) {
610  initializeAction(actionName);
612  setFacingLocation(direction);
613  }
614 
615  void Instance::actRepeat(const std::string& actionName, int32_t rotation) {
616  initializeAction(actionName);
618  setRotation(rotation);
619  }
620 
621  void Instance::actRepeat(const std::string& actionName) {
622  initializeAction(actionName);
624  }
625 
626  void Instance::say(const std::string& text, uint32_t duration) {
628  delete m_activity->m_sayInfo;
629  m_activity->m_sayInfo = NULL;
630 
631  if (text != "") {
632  m_activity->m_sayInfo = new SayInfo(text, duration);
634  }
635  }
636 
637  const std::string* Instance::getSayText() const {
638  if (m_activity && m_activity->m_sayInfo) {
639  return &m_activity->m_sayInfo->m_txt;
640  }
641  return NULL;
642  }
643 
646  Route* route = info->m_route;
647  Location target;
648  if (info->m_leader) {
649  target = info->m_leader->getLocationRef();
650  } else {
651  target = *info->m_target;
652  }
653  if (!route) {
654  route = new Route(m_location, *info->m_target);
655  route->setRotation(getRotation());
656  info->m_route = route;
657  if (isMultiCell()) {
658  route->setObject(m_object);
661  } else if (m_object->getZStepRange() != -1 || !m_object->getWalkableAreas().empty()) {
662  route->setObject(m_object);
663  }
664  if (!info->m_pather->solveRoute(route)) {
665  setFacingLocation(target);
666  return true;
667  }
668  // update target if needed
669  } else if (route->getEndNode().getLayerCoordinates() != target.getLayerCoordinates()) {
670  if (route->isReplanned() || isMultiCell()) {
671  *info->m_target = route->getEndNode();
672  route->setReplanned(false);
673  if (isMultiCell()) {
676  }
677  } else {
678  if (route->getPathLength() == 0) {
679  route->setStartNode(m_location);
680  } else {
681  route->setStartNode(route->getCurrentNode());
682  }
683  route->setEndNode(target);
684  if (!info->m_pather->solveRoute(route)) {
685  setFacingLocation(target);
686  return true;
687  }
688  }
689  }
690 
691  if (route->getRouteStatus() == ROUTE_SOLVED) {
692  // timeslice for this movement
694  // how far we can travel
695  double distance_to_travel = (static_cast<double>(timedelta) / 1000.0) * info->m_speed;
696  // location for this movement
697  Location nextLocation = m_location;
698  bool can_follow = info->m_pather->followRoute(m_location, route, distance_to_travel, nextLocation);
699  if (can_follow) {
700  setRotation(route->getRotation());
701  // move to another layer
702  if (m_location.getLayer() != nextLocation.getLayer()) {
703  m_location.getLayer()->getMap()->addInstanceForTransfer(this, nextLocation);
704  if (!m_multiInstances.empty()) {
705  std::vector<Instance*>::iterator it = m_multiInstances.begin();
706  for (; it != m_multiInstances.end(); ++it) {
707  Location newloc = nextLocation;
708  std::vector<ModelCoordinate> tmpcoords = m_location.getLayer()->getCellGrid()->
709  toMultiCoordinates(nextLocation.getLayerCoordinates(), (*it)->getObject()->getMultiPartCoordinates(m_rotation));
710  newloc.setLayerCoordinates(tmpcoords.front());
712  }
713  }
714  return false;
715  }
716  setLocation(nextLocation);
717  return false;
718  }
719  // move to another layer
720  if (m_location.getLayer() != nextLocation.getLayer()) {
721  m_location.getLayer()->getMap()->addInstanceForTransfer(this, nextLocation);
722  if (!m_multiInstances.empty()) {
723  std::vector<Instance*>::iterator it = m_multiInstances.begin();
724  for (; it != m_multiInstances.end(); ++it) {
725  Location newloc = nextLocation;
726  std::vector<ModelCoordinate> tmpcoords = m_location.getLayer()->getCellGrid()->
727  toMultiCoordinates(nextLocation.getLayerCoordinates(), (*it)->getObject()->getMultiPartCoordinates(m_rotation));
728  newloc.setLayerCoordinates(tmpcoords.front());
730  }
731  }
732  return true;
733  }
734  setLocation(nextLocation);
735  // need new route?
737  if (m_location.getLayerDistanceTo(target) > 1.5) {
738  if (route->getPathLength() == 0) {
739  route->setStartNode(m_location);
740  } else {
741  route->setStartNode(route->getPreviousNode());
742  }
743  route->setEndNode(target);
746  return !info->m_pather->solveRoute(route);
747  }
748  setFacingLocation(target);
749  }
750  return true;
751  } else if (route->getRouteStatus() == ROUTE_FAILED) {
752  return true;
753  }
754  return false;
755  }
756 
758  if (!m_activity) {
759  return ICHANGE_NO_CHANGES;
760  }
761  // remove DeleteListeners
762  m_deleteListeners.erase(std::remove(m_deleteListeners.begin(),m_deleteListeners.end(),
764 
765  if (!m_activity->m_timeProvider) {
767  }
769  if (info) {
770 // FL_DBG(_log, "updating instance");
771 
772  if (info->m_target) {
773 // FL_DBG(_log, "action contains target for movement");
774  bool movement_finished = processMovement();
775  if (movement_finished) {
776 // FL_DBG(_log, "movement finished");
777  finalizeAction();
778  }
779  } else {
780 // FL_DBG(_log, "action does not contain target for movement");
782  if (info->m_repeating) {
784  // prock: offset no longer needed
785  info->m_action_offset_time = 0;
786  } else if (!m_object->isMultiPart()) {
787  finalizeAction();
788  }
789  }
790  }
791 
792  // previous code may invalidate actioninfo.
793  if( m_activity->m_actionInfo ) {
795  }
796  }
797  m_activity->update(*this);
798  if (m_activity->m_sayInfo) {
799  if (m_activity->m_sayInfo->m_duration > 0) {
801  say("");
802  }
803  }
805  // delete superfluous activity
806  delete m_activity;
807  m_activity = 0;
808  return ICHANGE_NO_CHANGES;
809  }
810  return m_changeInfo;
811  }
812 
814  FL_DBG(_log, "finalizing action");
815  assert(m_activity);
816  assert(m_activity->m_actionInfo);
817 
820  }
821 
823  delete m_activity->m_actionInfo;
824  m_activity->m_actionInfo = NULL;
825  // this is needed in case the new action is set on the same pump and
826  // it is the same action as the finalized action
827  m_activity->m_action = NULL;
828 
829  // stop audio
830  if (action->getAudio() && m_activity->m_soundSource) {
832  }
833 
834  if (isMultiObject()) {
835  std::vector<Instance*>::iterator multi_it = m_multiInstances.begin();
836  for (; multi_it != m_multiInstances.end(); ++multi_it) {
837  (*multi_it)->finalizeAction();
838  }
839  }
840  std::vector<InstanceActionListener*>::iterator i = m_activity->m_actionListeners.begin();
841  while (i != m_activity->m_actionListeners.end()) {
842  if(*i)
843  (*i)->onInstanceActionFinished(this, action);
844  ++i;
845  }
847  std::remove(m_activity->m_actionListeners.begin(),
849  (InstanceActionListener*)NULL),
851  }
852 
854  FL_DBG(_log, "cancel action");
855  assert(m_activity);
856  assert(m_activity->m_actionInfo);
857 
860  }
861 
863  delete m_activity->m_actionInfo;
864  m_activity->m_actionInfo = NULL;
865  // this is needed in case the new action is set on the same pump and
866  // it is the same action as the canceled action
867  m_activity->m_action = NULL;
868 
869  if (isMultiObject()) {
870  std::vector<Instance*>::iterator multi_it = m_multiInstances.begin();
871  for (; multi_it != m_multiInstances.end(); ++multi_it) {
872  (*multi_it)->cancelAction();
873  }
874  }
875  std::vector<InstanceActionListener*>::iterator i = m_activity->m_actionListeners.begin();
876  while (i != m_activity->m_actionListeners.end()) {
877  if(*i)
878  (*i)->onInstanceActionCancelled(this, action);
879  ++i;
880  }
882  std::remove(m_activity->m_actionListeners.begin(),
884  (InstanceActionListener*)NULL),
886  }
887 
891  }
892  return NULL;
893  }
894 
897  return *m_activity->m_actionInfo->m_target;
898  }
899  return m_location;
900  }
901 
902  double Instance::getMovementSpeed() const {
905  }
906  return 0;
907  }
908 
911  }
912 
915  }
916 
918  if (m_activity) {
919  return m_activity->m_oldLocation;
920  }
921  return m_location;
922  }
923 
924  int32_t Instance::getOldRotation() const {
925  if (m_activity) {
926  return m_activity->m_oldRotation;
927  }
928  return m_rotation;
929  }
930 
936  }
937  return getRuntime();
938  }
939 
942  }
943 
945  float multiplier = 1.0;
946  if (m_activity->m_timeProvider) {
947  multiplier = m_activity->m_timeProvider->getMultiplier();
948  }
949  delete m_activity->m_timeProvider;
950  m_activity->m_timeProvider = NULL;
951 
952  if (m_location.getLayer()) {
953  Map* map = m_location.getLayer()->getMap();
954  if (map) {
956  }
957  }
958  if (!m_activity->m_timeProvider) {
960  }
962  }
963 
967  }
968 
970  if (m_activity) {
971  return m_changeInfo;
972  }
973  return ICHANGE_NO_CHANGES;
974  }
975 
979  }
980 
984  }
985 
989  }
990 
991  void Instance::setTimeMultiplier(float multip) {
993  if (!m_activity->m_timeProvider) {
995  }
997  }
998 
1002  }
1003  return 1.0;
1004  }
1005 
1009  }
1010  if (m_location.getLayer()) {
1011  Map* map = m_location.getLayer()->getMap();
1012  if (map && map->getTimeProvider()) {
1013  return map->getTimeProvider()->getTotalMultiplier();
1014  }
1015  }
1016  return 1.0;
1017  }
1018 
1020  if (m_activity) {
1022  bindTimeProvider();
1024  }
1025  if (m_location.getLayer()) {
1026  Map* map = m_location.getLayer()->getMap();
1027  if (map && map->getTimeProvider()) {
1028  return map->getTimeProvider()->getGameTime();
1029  }
1030  }
1031  return TimeManager::instance()->getTime();
1032  }
1033 
1034  void Instance::setCost(const std::string& id, double cost) {
1035  m_specialCost = true;
1036  m_costId = id;
1037  m_cost = cost;
1038  }
1039 
1041  m_specialCost = false;
1042  }
1043 
1045  if (m_specialCost) {
1046  return m_cost;
1047  }
1048  return m_object->getCost();
1049  }
1050 
1051  std::string Instance::getCostId() {
1052  if (m_specialCost) {
1053  return m_costId;
1054  }
1055  return m_object->getCostId();
1056  }
1057 
1059  return m_object->getSpeed();
1060  }
1061 
1063  return m_object->isSpecialSpeed();
1064  }
1065 
1067  return m_object->isMultiObject();
1068  }
1069 
1071  return !m_multiInstances.empty();
1072  }
1073 
1075  if (!m_multiInstances.empty()) {
1076  // use map coords for rotation and movement
1077  // instances are changed on InstanceTree but not on CellCache
1078  Location loc = m_location;
1080  const ExactModelCoordinate& offset = m_object->getRotationAnchor();
1081  loc.setExactLayerCoordinates(offset);
1082  const ExactModelCoordinate anchor_offset = loc.getMapCoordinates();
1083  int32_t rot = m_rotation;
1084  if (m_object->isRestrictedRotation()) {
1086  }
1087  double mcos = Mathd::Cos(double(rot) * (Mathd::pi()/180.0));
1088  double msin = Mathd::Sin(double(rot) * (Mathd::pi()/180.0));
1089  std::vector<Instance*>::iterator it = m_multiInstances.begin();
1090  for (; it != m_multiInstances.end(); ++it) {
1091  // use rotation 0 to get the "default" coordinate
1092  std::vector<ModelCoordinate> mcv = (*it)->getObject()->getMultiPartCoordinates(0);
1093  loc.setLayerCoordinates(mcv.front());
1095  ExactModelCoordinate nemc(emc.x-anchor_offset.x, emc.y-anchor_offset.y);
1096  emc.x = ((nemc.x * mcos + nemc.y * msin) + anchor_offset.x) + anchor.x;
1097  emc.y = ((-nemc.x * msin + nemc.y * mcos) + anchor_offset.y) + anchor.y;
1098  loc.setMapCoordinates(emc);
1099  (*it)->setLocation(loc);
1100  (*it)->setRotation(rot);
1101  }
1102  }
1103  }
1104 
1106  if (!m_ownObject) {
1107  createOwnObject();
1108  }
1110  objVis->addStaticColorOverlay(angle, colors);
1111  prepareForUpdate();
1113  }
1114 
1116  if (!m_ownObject) {
1117  return 0;
1118  }
1120  return objVis->getStaticColorOverlay(angle);
1121  }
1122 
1124  if (m_ownObject) {
1126  objVis->removeStaticColorOverlay(angle);
1127  prepareForUpdate();
1129  }
1130  }
1131 
1133  if (!m_ownObject) {
1134  return false;
1135  }
1137  return objVis->isColorOverlay();
1138  }
1139 
1140  void Instance::addColorOverlay(const std::string& actionName, uint32_t angle, const OverlayColors& colors) {
1141  ActionVisual* visual = getActionVisual(actionName, true);
1142  if (visual) {
1143  visual->addColorOverlay(angle, colors);
1144  prepareForUpdate();
1146  }
1147  }
1148 
1149  OverlayColors* Instance::getColorOverlay(const std::string& actionName, uint32_t angle) {
1150  ActionVisual* visual = getActionVisual(actionName, false);
1151  if (visual) {
1152  return visual->getColorOverlay(angle);
1153  }
1154  return NULL;
1155  }
1156 
1157  void Instance::removeColorOverlay(const std::string& actionName, int32_t angle) {
1158  ActionVisual* visual = getActionVisual(actionName, false);
1159  if (visual) {
1160  visual->removeColorOverlay(angle);
1161  prepareForUpdate();
1163  }
1164  }
1165 
1166  void Instance::addAnimationOverlay(const std::string& actionName, uint32_t angle, int32_t order, const AnimationPtr& animationptr) {
1167  ActionVisual* visual = getActionVisual(actionName, true);
1168  if (visual) {
1169  visual->addAnimationOverlay(angle, order, animationptr);
1170  prepareForUpdate();
1172  }
1173  }
1174 
1175  std::map<int32_t, AnimationPtr> Instance::getAnimationOverlay(const std::string& actionName, int32_t angle) {
1176  ActionVisual* visual = getActionVisual(actionName, false);
1177  if (visual) {
1178  return visual->getAnimationOverlay(angle);
1179  }
1180  return std::map<int32_t, AnimationPtr>();
1181  }
1182 
1183  void Instance::removeAnimationOverlay(const std::string& actionName, uint32_t angle, int32_t order) {
1184  ActionVisual* visual = getActionVisual(actionName, false);
1185  if (visual) {
1186  visual->removeAnimationOverlay(angle, order);
1187  prepareForUpdate();
1189  }
1190  }
1191 
1192  void Instance::addColorOverlay(const std::string& actionName, uint32_t angle, int32_t order, const OverlayColors& colors) {
1193  ActionVisual* visual = getActionVisual(actionName, true);
1194  if (visual) {
1195  visual->addColorOverlay(angle, order, colors);
1196  prepareForUpdate();
1198  }
1199  }
1200 
1201  OverlayColors* Instance::getColorOverlay(const std::string& actionName, uint32_t angle, int32_t order) {
1202  ActionVisual* visual = getActionVisual(actionName, false);
1203  if (visual) {
1204  return visual->getColorOverlay(angle, order);
1205  }
1206  return NULL;
1207  }
1208 
1209  void Instance::removeColorOverlay(const std::string& actionName, int32_t angle, int32_t order) {
1210  ActionVisual* visual = getActionVisual(actionName, false);
1211  if (visual) {
1212  visual->removeColorOverlay(angle, order);
1213  prepareForUpdate();
1215  }
1216  }
1217 
1218  bool Instance::isAnimationOverlay(const std::string& actionName) {
1219  ActionVisual* visual = getActionVisual(actionName, false);
1220  if (visual) {
1221  return visual->isAnimationOverlay();
1222  }
1223  return false;
1224  }
1225 
1226  bool Instance::isColorOverlay(const std::string& actionName) {
1227  ActionVisual* visual = getActionVisual(actionName, false);
1228  if (visual) {
1229  return visual->isColorOverlay();
1230  }
1231  return false;
1232  }
1233 
1234  void Instance::convertToOverlays(const std::string& actionName, bool color) {
1235  ActionVisual* visual = getActionVisual(actionName, true);
1236  visual->convertToOverlays(color);
1237  }
1238 
1240  if (!m_ownObject) {
1241  m_ownObject = true;
1243  ObjectVisual* nov = 0;
1245  if (!ov) {
1247  } else {
1248  nov = new ObjectVisual(*ov);
1249  m_object->adoptVisual(nov);
1250  }
1251  }
1252  }
1253 
1254  ActionVisual* Instance::getActionVisual(const std::string& actionName, bool create) {
1255  ActionVisual* nav = NULL;
1256  if (!m_ownObject) {
1257  createOwnObject();
1258  }
1259  Action* action = m_object->getAction(actionName, false);
1260  if (!action) {
1261  action = m_object->getAction(actionName);
1262  if (!action) {
1263  throw NotFound(std::string("action ") + actionName + " not found");
1264  } else if (create) {
1265  // if we change the current action then we have to replace the pointer
1266  bool replace = getCurrentAction() == action;
1267  // check if its the default action
1268  bool defaultAction = m_object->getDefaultAction() == action;
1269  ActionVisual* av = action->getVisual<ActionVisual>();
1270  action = m_object->createAction(actionName, defaultAction);
1271  nav = new ActionVisual(*av);
1272  action->adoptVisual(nav);
1273  if (replace) {
1274  m_activity->m_actionInfo->m_action = action;
1275  }
1276  }
1277  } else {
1278  nav = action->getVisual<ActionVisual>();
1279  }
1280  return nav;
1281  }
1282 
1284  m_deleteListeners.push_back(listener);
1285  }
1286 
1288  if (!m_deleteListeners.empty()) {
1289  std::vector<InstanceDeleteListener*>::iterator itor;
1290  itor = std::find(m_deleteListeners.begin(), m_deleteListeners.end(), listener);
1291  if(itor != m_deleteListeners.end()) {
1292  if ((*itor) == listener) {
1293  *itor = NULL;
1294  return;
1295  }
1296  } else {
1297  FL_WARN(_log, "Cannot remove unknown listener");
1298  }
1299  }
1300  }
1301 
1304  m_activity->m_actionInfo->m_leader == instance) {
1305  m_activity->m_actionInfo->m_leader = NULL;
1306  }
1307  if (isMultiObject()) {
1308  std::vector<Instance*>::iterator multi_it = m_multiInstances.begin();
1309  for (; multi_it != m_multiInstances.end(); ++multi_it) {
1310  if (*multi_it == instance) {
1311  m_multiInstances.erase(multi_it);
1312  break;
1313  }
1314  }
1315  }
1316  }
1317 }
bool isMultiObject()
Returns true if it is multi object otherwise false.
Definition: instance.cpp:1070
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:981
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
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:283
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:418
std::string getCostId()
Returns cost id.
Definition: instance.cpp:1051
double getCost() const
Returns the cost.
Definition: object.cpp:309
InstanceActivity * m_activity
Definition: instance.h:601
void updateMultiInstances()
Updates the visual positions of all instances in case this is a multi object.
Definition: instance.cpp:1074
int32_t getAngleBetween(const Location &loc1, const Location &loc2)
Gets angle of vector defined by given locations.
Definition: angles.cpp:98
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:497
void setMultiplier(float multiplier)
With multiplier, you can adjust the time speed.
IPather * m_pather
Definition: instance.cpp:93
InstanceActivity(Instance &source)
Definition: instance.cpp:113
ActionAudio * getAudio() const
Gets used audio.
Definition: action.h:82
bool m_isVisitor
is instance a visitor (FoW)
Definition: instance.h:620
Action * m_action
action on previous round. NOTE: might become invalid, only used for address comparison ...
Definition: instance.h:575
void setActionAudio(ActionAudio *audio)
Sets the ActionAudio.
Definition: soundsource.cpp:82
void createOwnObject()
Creates an own object for the instance to allow visual customization.
Definition: instance.cpp:1239
VisitorShapeInfo m_visitorShape
visitor shape type
Definition: instance.h:622
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:364
void cancelAction()
Cancel current action.
Definition: instance.cpp:853
bool m_ownObject
indicates if m_object is customized
Definition: instance.h:610
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:274
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:74
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:337
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:1283
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:1166
void callOnActionFrame(Action *action, int32_t frame)
Auxiliary function to inform ActionListeners about the active ActionFrame.
Definition: instance.cpp:389
bool isActive() const
If this returns true, the instance needs to be updated.
Definition: instance.cpp:291
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:597
bool isAnimationOverlay(const std::string &actionName)
Indicates if there exists a animation overlay for given action.
Definition: instance.cpp:1218
bool isBlocking() const
Gets if instance blocks movement.
Definition: instance.cpp:352
bool isColorOverlay(const std::string &actionName)
Indicates if there exists a color overlay for given action or animation overlay.
Definition: instance.cpp:1226
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:1062
SoundSource * m_soundSource
sound source of action audio on previous round
Definition: instance.h:577
void setMainMultiInstance(Instance *main)
Sets a instance to the main multi instance of this instance.
Definition: instance.cpp:584
void setFacingLocation(const Location &loc)
Sets the direction where instance is heading.
Definition: instance.cpp:909
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:895
std::vector< InstanceDeleteListener * > m_deleteListeners
listeners for deletion of the instance
Definition: instance.h:605
IPather * getPather() const
Gets associated pather.
Definition: object.cpp:195
InstanceChangeInfo getChangeInfo()
Returns a bitmask of changes of the last update.
Definition: instance.cpp:969
const Location & getEndNode()
Returns the target location.
Definition: route.cpp:94
bool m_blocking
instance blocking info
Definition: instance.h:616
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:1183
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:560
void cancelMovement(uint32_t length=1)
Cancel movement after a given length.
Definition: instance.cpp:522
Location m_location
current location
Definition: instance.h:612
uint32_t getActionRuntime()
Gets the time in milliseconds how long action has been active In case there is no current action...
Definition: instance.cpp:931
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:1254
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:940
Action * getCurrentAction() const
Gets the currently active action.
Definition: instance.cpp:888
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:79
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
std::string m_sayText
say text on previous round
Definition: instance.h:583
bool isSpecialCost()
Returns true if instance or object have special cost otherwise false.
Definition: instance.cpp:576
static TimeManager * instance()
Definition: singleton.h:84
Location & getLocationRef()
Gets reference of current location of instance.
Definition: instance.cpp:318
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:976
uint32_t m_prev_call_time
Definition: instance.cpp:91
const std::string * getSayText() const
Returns pointer to currently set saytext.
Definition: instance.cpp:637
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:139
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:1234
void removeDeleteListener(InstanceDeleteListener *listener)
Removes associated instance delete listener.
Definition: instance.cpp:1287
OverlayColors * getStaticColorOverlay(int32_t angle)
Returns closest matching static color overlay for given angle.
Definition: instance.cpp:1115
ActionInfo(IPather *pather, const Location &curloc)
Definition: instance.cpp:54
uint16_t m_visitorRadius
visitor radius (FoW)
Definition: instance.h:624
void addChangeListener(InstanceChangeListener *listener)
Adds new instance change listener.
Definition: instance.cpp:384
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:579
unsigned char uint8_t
Definition: core.h:38
IVisual * m_visual
instance visualization
Definition: instance.h:614
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:548
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:356
const std::vector< Instance * > & getMultiInstances()
Returns a vector that contains all instances of a multi object.
Definition: instance.cpp:580
static bool Equal(T _val1, T _val2)
Definition: fife_math.h:287
Instance * m_mainMultiInstance
pointer to the main multi instance
Definition: instance.h:636
std::vector< InstanceActionListener * > m_actionListeners
listeners for action related events
Definition: instance.h:589
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:295
std::vector< InstanceChangeListener * > m_changeListeners
listeners for changes
Definition: instance.h:585
float getMultiplier() const
uint32_t InstanceChangeInfo
Definition: instance.h:77
float m_timeMultiplier
time multiplier on previous round
Definition: instance.h:581
void callOnStackPositionChange()
Definition: instance.cpp:986
static T Sin(T _val)
Definition: fife_math.h:267
int32_t getRotation() const
Get the rotation offset of this instance Returns direction where instance is heading.
Definition: instance.cpp:333
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:96
int32_t getSessionId()
Returns the session identifier.
Definition: route.cpp:227
Location & getOldLocationRef()
Gets reference of old location of instance.
Definition: instance.cpp:917
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:1149
Location getFacingLocation()
Returns the direction where instance is heading.
Definition: instance.cpp:913
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:1123
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:1140
void setTimeMultiplier(float multip)
Sets speed for the map.
Definition: instance.cpp:991
uint32_t m_duration
Definition: instance.cpp:109
Location getLocation() const
Gets current location of instance.
Definition: instance.cpp:314
void removeChangeListener(InstanceChangeListener *listener)
Removes associated instance change listener.
Definition: instance.cpp:403
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:572
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:588
void onInstanceDeleted(Instance *instance)
callback so other instances we depend on can notify us if they go away
Definition: instance.cpp:1302
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:1132
InstanceActivity gets allocated in case there is some runtime activity related to the instance...
Definition: instance.h:558
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
Location m_location
location on previous round
Definition: instance.h:567
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:944
void addInstance(Instance *instance)
Adds an instance to the quad tree.
std::string m_id
Definition: instance.h:544
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:345
double getMovementSpeed() const
Gets the speed in case instance is moving otherwise returns 0.
Definition: instance.cpp:902
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:599
void finalizeAction()
Finalize current action.
Definition: instance.cpp:813
ActionInfo * m_actionInfo
action information, allocated when actions are bind
Definition: instance.h:591
void setCellStackPosition(uint8_t stack)
Sets the cell stack position.
Definition: instance.cpp:568
double m_cost
holds cost value
Definition: instance.h:630
TimeProvider * m_timeProvider
time scaler for this instance
Definition: instance.h:595
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:593
VisitorShapeInfo getVisitorShape()
Gets the shape type for a visitor.
Definition: instance.cpp:556
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:592
InstanceChangeInfo m_changeInfo
bitmask stating current changes
Definition: instance.h:603
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:628
std::string m_txt
Definition: instance.cpp:108
std::string m_costId
holds cost id
Definition: instance.h:632
std::vector< Instance * > m_multiInstances
vector that holds all multi instances
Definition: instance.h:634
double getCost()
Returns cost value.
Definition: instance.cpp:1044
float getTotalTimeMultiplier()
Gets instance speed, considering also model and map speeds.
Definition: instance.cpp:1006
void addStaticColorOverlay(uint32_t angle, const OverlayColors &colors)
Adds new static color overlay with given angle (degrees).
Definition: instance.cpp:1105
void removeColorOverlay(const std::string &actionName, int32_t angle)
Removes a color overlay with given angle (degrees) from given action.
Definition: instance.cpp:1157
bool isOverrideBlocking() const
Gets if instance blocking can overriden.
Definition: instance.cpp:360
float getTimeMultiplier()
Gets instance speed.
Definition: instance.cpp:999
void resetCost()
Resets cost.
Definition: instance.cpp:1040
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:609
static num_type pi()
Definition: fife_math.h:134
InstanceChangeInfo update()
Updates the instance related to the current action.
Definition: instance.cpp:757
int32_t getOldRotation() const
Get the old rotation offset of this instance Returns direction where instance was heading...
Definition: instance.cpp:924
const std::string & getId()
Get the identifier for this instance; possibly null.
Definition: instance.cpp:341
Location m_oldLocation
location on previous cell
Definition: instance.h:569
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:322
void removeActionListener(InstanceActionListener *listener)
Removes associated instance action listener.
Definition: instance.cpp:369
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:244
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:1019
Route * getRoute()
Returns a pointer to the route, in case there is no, it returns NULL.
Definition: instance.cpp:534
int32_t getZStepRange() const
Returns z-step range from object.
Definition: object.cpp:563
void refresh()
Refreshes instance e.g.
Definition: instance.cpp:964
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:1175
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:455
unsigned int uint32_t
Definition: core.h:40
float getTotalMultiplier() const
Object * m_object
object where instantiated from
Definition: instance.h:608
Action * getDefaultAction() const
Gets default action assigned to this object.
Definition: object.cpp:178
uint16_t getVisitorRadius()
Gets the visitor range.
Definition: instance.cpp:564
bool isVisitor()
If instance is a visitor it returns true otherwise false.
Definition: instance.cpp:548
bool isMultiCell()
Returns true if it is multi cell otherwise false.
Definition: instance.cpp:1066
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 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:626
int32_t m_rotation
rotation on previous round
Definition: instance.h:571
void setLocation(const Location &loc)
Sets location of the instance.
Definition: instance.cpp:299
#define FL_DBG(logger, msg)
Definition: logger.h:70
An Instance is an "instantiation" of an Object at a Location.
Definition: instance.h:101
bool processMovement()
Moves instance. Returns true if finished.
Definition: instance.cpp:644
bool m_overrideBlocking
allow to override the blocking property
Definition: instance.h:618
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:1034
Route * m_route
Definition: instance.cpp:97
double getSpeed()
Returns speed modifier.
Definition: instance.cpp:1058
int32_t m_oldRotation
rotation on previous round
Definition: instance.h:573
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:626
void setVisitor(bool visit)
Marks this instance as a visitor.
Definition: instance.cpp:544
void setVisitorShape(VisitorShapeInfo info)
Sets the shape type for a visitor.
Definition: instance.cpp:552