FIFE  6e1afdbeda11afe9ac53e6023a4be96ef88f1dc6
instance.h
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 #ifndef FIFE_INSTANCE_H
23 #define FIFE_INSTANCE_H
24 
25 // Standard C++ library includes
26 #include <vector>
27 
28 // 3rd party library includes
29 
30 // FIFE includes
31 // These includes are split up in two parts, separated by one empty line
32 // First block: files included from the FIFE root src directory
33 // Second block: files included from the same folder
34 #include "util/base/fifeclass.h"
35 
36 #include "model/metamodel/object.h"
38 #include "view/visual.h"
39 
40 #include "location.h"
41 
42 
43 namespace FIFE {
44 
45  class Layer;
46  class Action;
47  class Instance;
48  class ActionInfo;
49  class SayInfo;
50  class SoundSource;
51  class TimeProvider;
52  class Route;
53 
55  public:
57  virtual void onInstanceActionFinished(Instance* instance, Action* action) = 0;
58  virtual void onInstanceActionCancelled(Instance* instance, Action* action) = 0;
59  virtual void onInstanceActionFrame(Instance* instance, Action* action, int32_t frame) = 0;
60  };
61 
64  ICHANGE_LOC = 0x0001,
65  ICHANGE_ROTATION = 0x0002,
66  ICHANGE_SPEED = 0x0004,
67  ICHANGE_ACTION = 0x0008,
69  ICHANGE_SAYTEXT = 0x0020,
70  ICHANGE_BLOCK = 0x0040,
71  ICHANGE_CELL = 0x0080,
73  ICHANGE_VISIBLE = 0x0200,
74  ICHANGE_STACKPOS = 0x0400,
75  ICHANGE_VISUAL = 0x0800
76  };
78 
80  public:
82  virtual void onInstanceChanged(Instance* instance, InstanceChangeInfo info) = 0;
83  };
84 
86  public:
88  virtual void onInstanceDeleted(Instance* instance) =0;
89  };
90 
95  };
97 
101  class Instance : public FifeClass, public InstanceDeleteListener {
102  public:
103 
108  Instance(Object* object, const Location& location, const std::string& identifier="");
109 
112  virtual ~Instance();
113 
116  const std::string& getId();
117 
120  void setId(const std::string& identifier="");
121 
124  Object* getObject();
125 
129  void setLocation(const Location& loc);
130 
135  Location getLocation() const;
136 
140  Location& getLocationRef();
141 
148  Location getTargetLocation() const;
149 
153  void setFacingLocation(const Location& loc);
154 
159  Location getFacingLocation();
160 
164  Location& getOldLocationRef();
165 
168  void setRotation(int32_t rotation);
169 
173  int32_t getRotation() const;
174 
178  int32_t getOldRotation() const;
179 
182  void setBlocking(bool blocking);
183 
186  bool isBlocking() const;
187 
190  void setOverrideBlocking(bool overblock);
191 
194  bool isOverrideBlocking() const;
195 
200  void callOnActionFrame(Action* action, int32_t frame);
201 
205  void addActionListener(InstanceActionListener* listener);
206 
210  void removeActionListener(InstanceActionListener* listener);
211 
215  void addChangeListener(InstanceChangeListener* listener);
216 
220  void removeChangeListener(InstanceChangeListener* listener);
221 
225  void addDeleteListener(InstanceDeleteListener* listener);
226 
230  void removeDeleteListener(InstanceDeleteListener* listener);
231 
236  Action* getCurrentAction() const;
237 
242  double getMovementSpeed() const;
243 
248  uint32_t getActionRuntime();
249 
255  void setActionRuntime(uint32_t time_offset);
256 
264  void move(const std::string& actionName, const Location& target, const double speed, const std::string& costId = "");
265 
270  void actOnce(const std::string& actionName, const Location& direction);
271 
276  void actOnce(const std::string& actionName, int32_t rotation);
277 
281  void actOnce(const std::string& actionName);
282 
287  void actRepeat(const std::string& actionName, const Location& direction);
288 
293  void actRepeat(const std::string& actionName, int32_t rotation);
294 
298  void actRepeat(const std::string& actionName);
299 
304  void say(const std::string& text, uint32_t duration=0);
305 
312  void follow(const std::string& actionName, Instance* leader, const double speed);
313 
320  void follow(const std::string& actionName, Route* route, const double speed);
321 
326  void cancelMovement(uint32_t length = 1);
327 
330  const std::string* getSayText() const;
331 
337  InstanceChangeInfo update();
338 
341  bool isActive() const;
342 
345  void setVisual(IVisual* visual) { m_visual = visual; }
346 
349  template<typename T> T* getVisual() const { return reinterpret_cast<T*>(m_visual); }
350 
351  void callOnTransparencyChange();
352  void callOnVisibleChange();
353  void callOnStackPositionChange();
354 
357  void setTimeMultiplier(float multip);
358 
361  float getTimeMultiplier();
362 
365  float getTotalTimeMultiplier();
366 
370  uint32_t getRuntime();
371 
375  void refresh();
376 
379  InstanceChangeInfo getChangeInfo();
380 
383  void onInstanceDeleted(Instance* instance);
384 
387  Route* getRoute();
388 
391  void setVisitor(bool visit);
392 
395  bool isVisitor();
396 
399  void setVisitorShape(VisitorShapeInfo info);
400 
403  VisitorShapeInfo getVisitorShape();
404 
407  void setVisitorRadius(uint16_t radius);
408 
411  uint16_t getVisitorRadius();
412 
415  void setCellStackPosition(uint8_t stack);
416 
419  uint8_t getCellStackPosition();
420 
423  bool isSpecialCost();
424 
429  void setCost(const std::string& id, double cost);
430 
433  void resetCost();
434 
437  double getCost();
438 
441  std::string getCostId();
442 
445  double getSpeed();
446 
449  bool isSpecialSpeed();
450 
453  bool isMultiCell();
454 
457  bool isMultiObject();
458 
461  void updateMultiInstances();
462 
465  const std::vector<Instance*>& getMultiInstances();
466 
469  void setMainMultiInstance(Instance* main);
470 
473  Instance* getMainMultiInstance();
474 
477  void addStaticColorOverlay(uint32_t angle, const OverlayColors& colors);
478 
482  OverlayColors* getStaticColorOverlay(int32_t angle);
483 
486  void removeStaticColorOverlay(int32_t angle);
487 
490  bool isStaticColorOverlay();
491 
494  void addColorOverlay(const std::string& actionName, uint32_t angle, const OverlayColors& colors);
495 
499  OverlayColors* getColorOverlay(const std::string& actionName, uint32_t angle);
500 
503  void removeColorOverlay(const std::string& actionName, int32_t angle);
504 
507  void addAnimationOverlay(const std::string& actionName, uint32_t angle, int32_t order, const AnimationPtr& animationptr);
508 
512  std::map<int32_t, AnimationPtr> getAnimationOverlay(const std::string& actionName, int32_t angle);
513 
516  void removeAnimationOverlay(const std::string& actionName, uint32_t angle, int32_t order);
517 
520  void addColorOverlay(const std::string& actionName, uint32_t angle, int32_t order, const OverlayColors& colors);
521 
525  OverlayColors* getColorOverlay(const std::string& actionName, uint32_t angle, int32_t order);
526 
529  void removeColorOverlay(const std::string& actionName, int32_t angle, int32_t order);
530 
533  void convertToOverlays(const std::string& actionName, bool color);
534 
537  bool isAnimationOverlay(const std::string& actionName);
538 
541  bool isColorOverlay(const std::string& actionName);
542 
543  private:
544  std::string m_id;
545 
548  int32_t m_rotation;
549 
559  public:
560  InstanceActivity(Instance& source);
561  ~InstanceActivity();
562 
563  // ----- Fields related to change tracking -----
565  void update(Instance& source);
571  int32_t m_rotation;
573  int32_t m_oldRotation;
579  double m_speed;
583  std::string m_sayText;
585  std::vector<InstanceChangeListener*> m_changeListeners;
586 
587  // ----- Fields related to generic activity -----
589  std::vector<InstanceActionListener*> m_actionListeners;
599  InstanceChangeInfo m_additional;
600  };
603  InstanceChangeInfo m_changeInfo;
605  std::vector<InstanceDeleteListener*> m_deleteListeners;
606 
622  VisitorShapeInfo m_visitorShape;
630  double m_cost;
632  std::string m_costId;
634  std::vector<Instance*> m_multiInstances;
637 
638  Instance(const Instance&);
639  Instance& operator=(const Instance&);
641  void finalizeAction();
643  void cancelAction();
645  void initializeAction(const std::string& actionName);
647  bool processMovement();
649  void calcMovement();
651  void bindTimeProvider();
653  void initializeChanges();
655  void prepareForUpdate();
656 
658  void createOwnObject();
660  ActionVisual* getActionVisual(const std::string& actionName, bool create);
661  };
662 } // FIFE
663 
664 #endif
Timeprovider is an utility providing time management functionality You can have hierarchy of time pro...
Definition: timeprovider.h:42
InstanceActivity * m_activity
Definition: instance.h:601
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
VisitorShapeInfo m_visitorShape
visitor shape type
Definition: instance.h:622
bool m_ownObject
indicates if m_object is customized
Definition: instance.h:610
Interface class between Instance / ActionAudio and SoundEmitter.
Definition: soundsource.h:45
Object class.
Definition: object.h:51
bool m_blocking
blocking status on previous round
Definition: instance.h:597
SoundSource * m_soundSource
sound source of action audio on previous round
Definition: instance.h:577
Action visual contains data that is needed to visualize different actions on screen.
Definition: visual.h:212
virtual ~InstanceActionListener()
Definition: instance.h:56
std::vector< InstanceDeleteListener * > m_deleteListeners
listeners for deletion of the instance
Definition: instance.h:605
T * getVisual() const
Gets used visualization.
Definition: instance.h:349
bool m_blocking
instance blocking info
Definition: instance.h:616
Base class for all fife classes Used e.g.
Definition: fifeclass.h:42
Location m_location
current location
Definition: instance.h:612
virtual void onInstanceActionCancelled(Instance *instance, Action *action)=0
void setVisual(IVisual *visual)
Sets visualization to be used.
Definition: instance.h:345
VisitorShapeType
Definition: instance.h:91
std::string m_sayText
say text on previous round
Definition: instance.h:583
A basic route.
Definition: route.h:64
virtual void onInstanceActionFinished(Instance *instance, Action *action)=0
uint16_t m_visitorRadius
visitor radius (FoW)
Definition: instance.h:624
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
int32_t m_rotation
The rotation offset of this instance.
Definition: instance.h:548
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
std::vector< InstanceChangeListener * > m_changeListeners
listeners for changes
Definition: instance.h:585
uint32_t InstanceChangeInfo
Definition: instance.h:77
float m_timeMultiplier
time multiplier on previous round
Definition: instance.h:581
uint8_t VisitorShapeInfo
Definition: instance.h:96
virtual ~InstanceDeleteListener()
Definition: instance.h:87
virtual void onInstanceActionFrame(Instance *instance, Action *action, int32_t frame)=0
InstanceActivity gets allocated in case there is some runtime activity related to the instance...
Definition: instance.h:558
unsigned short uint16_t
Definition: core.h:39
Location m_location
location on previous round
Definition: instance.h:567
std::string m_id
Definition: instance.h:544
InstanceChangeInfo m_additional
additional change info, used for visual class (transparency, visible, stackpos)
Definition: instance.h:599
ActionInfo * m_actionInfo
action information, allocated when actions are bind
Definition: instance.h:591
double m_cost
holds cost value
Definition: instance.h:630
TimeProvider * m_timeProvider
time scaler for this instance
Definition: instance.h:595
SayInfo * m_sayInfo
text to say + duration, allocated when something is said
Definition: instance.h:593
InstanceChangeInfo m_changeInfo
bitmask stating current changes
Definition: instance.h:603
bool m_specialCost
indicates special cost
Definition: instance.h:628
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
virtual ~InstanceChangeListener()
Definition: instance.h:81
Location m_oldLocation
location on previous cell
Definition: instance.h:569
InstanceChangeType
Definition: instance.h:62
unsigned int uint32_t
Definition: core.h:40
Object * m_object
object where instantiated from
Definition: instance.h:608
uint8_t m_cellStackPos
position on cell stack
Definition: instance.h:626
int32_t m_rotation
rotation on previous round
Definition: instance.h:571
An Instance is an "instantiation" of an Object at a Location.
Definition: instance.h:101
bool m_overrideBlocking
allow to override the blocking property
Definition: instance.h:618
int32_t m_oldRotation
rotation on previous round
Definition: instance.h:573