FIFE
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
object.h
Go to the documentation of this file.
1 /***************************************************************************
2  * Copyright (C) 2006-2012 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_PROTOTYPE_H
23 #define FIFE_PROTOTYPE_H
24 
25 // Standard C++ library includes
26 #include <string>
27 #include <map>
28 #include <list>
29 
30 // 3rd party library includes
31 
32 // FIFE includes
33 // These includes are split up in two parts, separated by one empty line
34 // First block: files included from the FIFE root src directory
35 // Second block: files included from the same folder
36 #include "util/resource/resource.h"
37 #include "util/math/angles.h"
38 
39 namespace FIFE {
40 
41  class Action;
42  class IPather;
43  class IVisual;
44 
51  class Object {
52  public:
62  Object(const std::string& identifier, const std::string& name_space, Object* inherited=NULL);
63 
66  ~Object();
67 
68  const std::string& getId() const { return m_id; }
69  const std::string& getNamespace() const { return m_namespace; }
70 
73  void setId(const std::string& id) { m_id = id; }
74 
85  Action* createAction(const std::string& identifier, bool is_default=false);
86 
89  Action* getAction(const std::string& identifier) const;
90 
93  std::list<std::string> getActionIds() const;
94 
97  void setDefaultAction(const std::string& identifier);
98 
102 
105  void setPather(IPather* pather);
106 
109  IPather* getPather() const { return m_pather; }
110 
114  Object* getInherited() const { return m_inherited; }
115 
118  void adoptVisual(IVisual* visual) { m_visual = visual; }
119 
122  template<typename T> T* getVisual() const { return reinterpret_cast<T*>(m_visual); }
123 
126  void setBlocking(bool blocking) { m_blocking = blocking; }
127 
130  bool isBlocking() const;
131 
134  void setStatic(bool stat) { m_static = stat; }
135 
138  bool isStatic() const;
139 
140  void setFilename(const std::string& file);
141  const std::string& getFilename() const;
142 
147  void setCellStackPosition(uint8_t position);
148 
153 
157  bool isSpecialCost() const;
158 
162  void setCostId(const std::string& cost);
163 
167  const std::string& getCostId() const;
168 
172  void setCost(double cost);
173 
177  double getCost() const;
178 
182  bool isMultiObject() const;
183 
187  void addMultiPartId(const std::string& partId);
188 
192  const std::list<std::string>& getMultiPartIds() const;
193 
197  void removeMultiPartId(const std::string& partId);
198 
201  void removeAllMultiPartIds();
202 
206  bool isMultiPart() const;
207 
211  void setMultiPart(bool part);
212 
216  void addMultiPart(Object* obj);
217 
221  const std::set<Object*>& getMultiParts() const;
222 
226  void removeMultiPart(Object* obj);
227 
230  void removeMultiParts();
231 
236  void addMultiPartCoordinate(int32_t rotation, ModelCoordinate coord);
237 
241  const std::multimap<int32_t, ModelCoordinate>& getMultiPartCoordinates() const;
242 
247  std::vector<ModelCoordinate> getMultiPartCoordinates(int32_t rotation);
248 
253  std::vector<ModelCoordinate> getMultiObjectCoordinates(int32_t rotation);
254 
260  void setRotationAnchor(const ExactModelCoordinate& anchor);
261 
266 
271  void setRestrictedRotation(bool restrict);
272 
276  bool isRestrictedRotation() const;
277 
282  int32_t getRestrictedRotation(int32_t rotation);
283 
288  void setZStepRange(int32_t zRange);
289 
293  int32_t getZStepRange() const;
294 
298  void setArea(const std::string& id);
299 
303  const std::string& getArea() const;
304 
309  void addWalkableArea(const std::string& id);
310 
314  void removeWalkableArea(const std::string& id);
315 
319  const std::list<std::string>& getWalkableAreas() const;
320 
323  bool operator==(const Object& obj) const;
324 
327  bool operator!=(const Object& obj) const;
328 
329  private:
331  std::string m_id;
332 
334  std::string m_namespace;
335 
337  std::string m_filename;
338 
341 
343  std::map<std::string, Action*>* m_actions;
344 
347 
349  bool m_static;
350 
353 
356 
359 
362 
364  std::string m_costId;
365 
367  double m_cost;
368 
371 
374 
376  int32_t m_zRange;
377 
379  std::list<std::string> m_multiPartIds;
380 
383 
385  std::set<Object*> m_multiParts;
386 
389 
392 
394  std::multimap<int32_t, ModelCoordinate> m_multiPartCoordinates;
395 
397  std::multimap<int32_t, ModelCoordinate> m_multiObjectCoordinates;
398 
399  std::string m_area;
400 
401  std::list<std::string> m_walkableAreas;
402  };
403 
404 } //FIFE
405 #endif
406 
double m_cost
cost value, default 1.0
Definition: object.h:367
void setDefaultAction(const std::string &identifier)
Sets default action assigned to this object.
Definition: object.cpp:118
IPather * getPather() const
Gets associated pather.
Definition: object.h:109
double getCost() const
Returns the cost.
Definition: object.cpp:193
void removeMultiPart(Object *obj)
Removes a multi part object.
Definition: object.cpp:239
~Object()
Destructor.
Definition: object.cpp:57
void removeWalkableArea(const std::string &id)
Removes an area id from walkable areas.
Definition: object.cpp:344
void setArea(const std::string &id)
Sets the area id that the instances of this object adds to their cells.
Definition: object.cpp:330
const std::string & getNamespace() const
Definition: object.h:69
void adoptVisual(IVisual *visual)
Sets visualization to be used.
Definition: object.h:118
bool m_restrictedRotation
indicates if object uses only restricted rotations
Definition: object.h:373
Object class.
Definition: object.h:51
void setRotationAnchor(const ExactModelCoordinate &anchor)
Sets the rotation anchor for this multi object.
Definition: object.cpp:296
const std::string & getId() const
Definition: object.h:68
type_angle2id m_partAngleMap
part object angles
Definition: object.h:388
bool isMultiObject() const
Gets if object uses special cost.
Definition: object.cpp:197
bool isStatic() const
Gets if object moves.
Definition: object.cpp:151
void setCellStackPosition(uint8_t position)
Sets the cell stack position.
Definition: object.cpp:169
const std::list< std::string > & getMultiPartIds() const
Returns all multi part identifiers.
Definition: object.cpp:205
Action * getDefaultAction() const
Gets default action assigned to this object.
Definition: object.h:101
void setZStepRange(int32_t zRange)
Sets z-step range for object.
Definition: object.cpp:322
std::list< std::string > m_multiPartIds
list with part identifiers
Definition: object.h:379
const std::set< Object * > & getMultiParts() const
Returns all multi part objects.
Definition: object.cpp:235
std::list< std::string > m_walkableAreas
Definition: object.h:401
Object(const std::string &identifier, const std::string &name_space, Object *inherited=NULL)
Constructor An object may optionally inherit default attributes from another object.
Definition: object.cpp:37
void setFilename(const std::string &file)
Definition: object.cpp:161
bool operator!=(const Object &obj) const
Compares unequality of two objects.
Definition: object.cpp:356
bool isMultiPart() const
Gets if object is a part of a multi object.
Definition: object.cpp:223
std::string m_namespace
namespace
Definition: object.h:334
const std::string & getFilename() const
Definition: object.cpp:165
std::multimap< int32_t, ModelCoordinate > m_multiPartCoordinates
part object coordinates
Definition: object.h:394
void removeAllMultiPartIds()
Removes all multi part identifiers.
Definition: object.cpp:219
Object * getInherited() const
Gets an object where this object was inherited from.
Definition: object.h:114
void removeMultiPartId(const std::string &partId)
Removes a multi part identifier.
Definition: object.cpp:209
unsigned char uint8_t
Definition: core.h:38
std::multimap< int32_t, ModelCoordinate > m_multiObjectCoordinates
multi object coordinates
Definition: object.h:397
void setMultiPart(bool part)
Sets the object as a part of a multi object.
Definition: object.cpp:227
std::string m_id
identifier
Definition: object.h:331
const std::string & getCostId() const
Returns the cost id.
Definition: object.cpp:185
const std::multimap< int32_t, ModelCoordinate > & getMultiPartCoordinates() const
Returns all rotationally dependent coordinates from this object part.
Definition: object.cpp:253
T * getVisual() const
Gets used visualization.
Definition: object.h:122
void setId(const std::string &id)
Sets the identifier for this object.
Definition: object.h:73
void setRestrictedRotation(bool restrict)
Sets the rotation to restricted.
Definition: object.cpp:304
void addMultiPartCoordinate(int32_t rotation, ModelCoordinate coord)
Adds rotationally dependent coordinates for this object part.
Definition: object.cpp:248
ExactModelCoordinate m_rotationAnchor
rotation anchor
Definition: object.h:382
bool isRestrictedRotation() const
Gets if object uses restricted rotations.
Definition: object.cpp:308
Object * m_inherited
pointer to inherited object
Definition: object.h:340
void setCost(double cost)
Sets the cost.
Definition: object.cpp:189
void removeMultiParts()
Removes all multi part objects.
Definition: object.cpp:244
int32_t m_zRange
z range value
Definition: object.h:376
Action * createAction(const std::string &identifier, bool is_default=false)
Adds new action with given id.
Definition: object.cpp:69
bool m_multiPart
indicates if object is part of multi object
Definition: object.h:370
std::string m_area
Definition: object.h:399
const std::list< std::string > & getWalkableAreas() const
Returns a list that contains all walkable area ids.
Definition: object.cpp:348
std::string m_filename
filename
Definition: object.h:337
void addMultiPart(Object *obj)
Adds a object as a part of a multi object.
Definition: object.cpp:231
void addMultiPartId(const std::string &partId)
Adds a multi part identifier.
Definition: object.cpp:201
uint8_t m_cellStack
position on cellstack
Definition: object.h:361
void setStatic(bool stat)
Set to true, if object is such that it doesn&#39;t move.
Definition: object.h:134
IPather * m_pather
pointer to pathfinder
Definition: object.h:352
uint8_t getCellStackPosition() const
Returns cell stack position.
Definition: object.cpp:173
std::vector< ModelCoordinate > getMultiObjectCoordinates(int32_t rotation)
Returns all multi object coordinates for the given rotation.
Definition: object.cpp:270
A 3D Point.
Definition: point.h:202
Action * getAction(const std::string &identifier) const
Gets action with given id.
Definition: object.cpp:92
bool m_blocking
indicates if object blocks
Definition: object.h:346
const std::string & getArea() const
Gets the area id that the instances of this object adds to their cells.
Definition: object.cpp:334
std::set< Object * > m_multiParts
set with part objects
Definition: object.h:385
std::map< uint32_t, int32_t > type_angle2id
Definition: angles.h:37
bool isSpecialCost() const
Gets if object uses special cost.
Definition: object.cpp:177
bool operator==(const Object &obj) const
Compares equality of two objects.
Definition: object.cpp:352
Action * m_defaultAction
pointer to default action
Definition: object.h:358
bool m_static
indicates if object is static
Definition: object.h:349
void addWalkableArea(const std::string &id)
Adds an area id to walkable area.
Definition: object.cpp:338
int32_t getZStepRange() const
Returns z-step range from object.
Definition: object.cpp:326
type_angle2id m_multiAngleMap
multi object angles
Definition: object.h:391
void setPather(IPather *pather)
Sets pather used by instances created out of this object.
Definition: object.cpp:137
void setBlocking(bool blocking)
Sets if object blocks movement.
Definition: object.h:126
std::list< std::string > getActionIds() const
Gets all available action ids of the object and packs them into a list.
Definition: object.cpp:106
const ExactModelCoordinate & getRotationAnchor() const
Returns the rotation anchor for this multi object.
Definition: object.cpp:300
int32_t getRestrictedRotation(int32_t rotation)
Returns the most obvious rotation, based on multi coordinates.
Definition: object.cpp:312
bool isBlocking() const
Gets if object blocks movement.
Definition: object.cpp:141
void setCostId(const std::string &cost)
Sets the cost id.
Definition: object.cpp:181
std::map< std::string, Action * > * m_actions
holds action ids and assigned actions
Definition: object.h:343
IVisual * m_visual
pointer to object visual
Definition: object.h:355
std::string m_costId
cost identifier
Definition: object.h:364