summaryrefslogtreecommitdiffstats
path: root/src/game-server
diff options
context:
space:
mode:
Diffstat (limited to 'src/game-server')
-rw-r--r--src/game-server/entity.cpp3
-rw-r--r--src/game-server/entity.h162
2 files changed, 97 insertions, 68 deletions
diff --git a/src/game-server/entity.cpp b/src/game-server/entity.cpp
index 3593d90..cbfa96f 100644
--- a/src/game-server/entity.cpp
+++ b/src/game-server/entity.cpp
@@ -35,6 +35,9 @@ Entity::~Entity()
delete mComponents[i];
}
+/**
+ * Updates the internal status. By default, calls update on all its components.
+ */
void Entity::update()
{
for (int i = 0; i < ComponentTypeCount; ++i)
diff --git a/src/game-server/entity.h b/src/game-server/entity.h
index 7aed29e..9d418df 100644
--- a/src/game-server/entity.h
+++ b/src/game-server/entity.h
@@ -48,76 +48,21 @@ class Entity : public sigc::trackable
virtual ~Entity();
- /**
- * Gets type of this entity.
- *
- * @return the type of this entity.
- */
- EntityType getType() const
- { return mType; }
-
- /**
- * Adds a component. Only one component of a given type can be added.
- * Entity takes ownership of \a component.
- */
- template <class T>
- void addComponent(T *component)
- {
- assert(!mComponents[T::type]);
- mComponents[T::type] = component;
- }
-
- /**
- * Returns the component of the given type, or 0 when no such component
- * was set.
- */
- Component *getComponent(ComponentType type) const
- { return mComponents[type]; }
-
- /**
- * Get a component by its class. Avoids the need for doing a static-
- * cast in the calling code.
- */
- template <class T>
- T *getComponent() const
- { return static_cast<T*>(getComponent(T::type)); }
-
- /**
- * Returns whether this entity is visible on the map or not. (Actor)
- */
- bool isVisible() const
- { return mType != OBJECT_OTHER; }
-
- /**
- * Returns whether this entity can move on the map or not. (Actor)
- */
- bool canMove() const
- { return mType == OBJECT_CHARACTER || mType == OBJECT_MONSTER ||
- mType == OBJECT_NPC; }
-
- /**
- * Returns whether this entity can fight or not. (Being)
- */
- bool canFight() const
- { return mType == OBJECT_CHARACTER || mType == OBJECT_MONSTER; }
-
- /**
- * Updates the internal status. By default, calls update on all its
- * components.
- */
- virtual void update();
+ EntityType getType() const;
+
+ template <class T> void addComponent(T *component);
+ template <class T> T *getComponent() const;
+
+ Component *getComponent(ComponentType type) const;
- /**
- * Gets the map this entity is located on.
- */
- MapComposite *getMap() const
- { return mMap; }
+ bool isVisible() const;
+ bool canMove() const;
+ bool canFight() const;
- /**
- * Sets the map this entity is located on.
- */
- virtual void setMap(MapComposite *map)
- { mMap = map; }
+ virtual void update();
+
+ MapComposite *getMap() const;
+ virtual void setMap(MapComposite *map);
sigc::signal<void, Entity *> signal_inserted;
sigc::signal<void, Entity *> signal_removed;
@@ -129,4 +74,85 @@ class Entity : public sigc::trackable
Component *mComponents[ComponentTypeCount];
};
+/**
+ * Gets type of this entity.
+ *
+ * @return the type of this entity.
+ */
+inline EntityType Entity::getType() const
+{
+ return mType;
+}
+
+/**
+ * Adds a component. Only one component of a given type can be added.
+ * Entity takes ownership of \a component.
+ */
+template <class T>
+inline void Entity::addComponent(T *component)
+{
+ assert(!mComponents[T::type]);
+ mComponents[T::type] = component;
+}
+
+/**
+ * Returns the component of the given type, or 0 when no such component
+ * was set.
+ */
+inline Component *Entity::getComponent(ComponentType type) const
+{
+ return mComponents[type];
+}
+
+/**
+ * Get a component by its class. Avoids the need for doing a static-
+ * cast in the calling code.
+ */
+template <class T>
+inline T *Entity::getComponent() const
+{
+ return static_cast<T*>(getComponent(T::type));
+}
+
+/**
+ * Returns whether this entity is visible on the map or not. (Actor)
+ */
+inline bool Entity::isVisible() const
+{
+ return mType != OBJECT_OTHER;
+}
+
+/**
+ * Returns whether this entity can move on the map or not. (Actor)
+ */
+inline bool Entity::canMove() const
+{
+ return mType == OBJECT_CHARACTER || mType == OBJECT_MONSTER ||
+ mType == OBJECT_NPC;
+}
+
+/**
+ * Returns whether this entity can fight or not. (Being)
+ */
+inline bool Entity::canFight() const
+{
+ return mType == OBJECT_CHARACTER || mType == OBJECT_MONSTER;
+}
+
+/**
+ * Gets the map this entity is located on.
+ */
+inline MapComposite *Entity::getMap() const
+{
+ return mMap;
+}
+
+/**
+ * Sets the map this entity is located on.
+ */
+inline void Entity::setMap(MapComposite *map)
+{
+ mMap = map;
+}
+
#endif // ENTITY_H