summaryrefslogtreecommitdiffstats
path: root/src/game-server
diff options
context:
space:
mode:
authorThorbjørn Lindeijer <thorbjorn@lindeijer.nl>2013-04-15 21:24:55 +0200
committerThorbjørn Lindeijer <thorbjorn@lindeijer.nl>2013-04-15 21:24:55 +0200
commitef4175cdfae6a6981738e15cb0009d8e47ed7c80 (patch)
tree5237140b62274b63b9a98ef65aec92df804eb1f6 /src/game-server
parent0f1449567d5a2ccab9ff6fdc9975150299482834 (diff)
downloadmanaserv-ef4175cdfae6a6981738e15cb0009d8e47ed7c80.tar.gz
manaserv-ef4175cdfae6a6981738e15cb0009d8e47ed7c80.tar.xz
manaserv-ef4175cdfae6a6981738e15cb0009d8e47ed7c80.zip
Moved functions to entity members where appropriate
Some functions were skipped for now because they may need a new name or change of behavior. Changes: chr_warp entity:warp chr_get_inventory entity:inventory chr_inv_change entity:inv_change chr_inv_count entity:inv_count chr_get_equipment entity:equipment chr_equip_slot entity:equip_slot chr_equip_item entity:equip_item chr_unequip_slot entity:unequip_slot chr_unequip_item entity:unequip_item chr_get_level entity:level chr_get_exp entity:xp chr_give_exp entity:give_xp chr_get_rights entity:rights chr_set_hair_style entity:set_hair_style chr_get_hair_style entity:hair_style chr_set_hair_color entity:set_hair_color chr_get_hair_color entity:hair_color chr_get_kill_count entity:kill_count chr_give_special entity:give_special chr_has_special entity:has_special chr_take_special entity:take_special chr_set_special_recharge_speed entity:set_special_recharge_speed chr_get_special_recharge_speed entity:special_recharge_speed chr_set_special_mana entity:set_special_mana chr_get_special_mana entity:special_mana chr_kick entity:kick exp_for_level xp_for_level monster_get_id entity:monster_id monster_change_anger entity:change_anger monster_drop_anger entity:drop_anger monster_get_angerlist entity:angerlist being_apply_status entity:apply_status being_remove_status entity:remove_status being_has_status entity:has_status being_set_status_time entity:set_status_time being_get_status_time entity:status_time being_get_gender entity:gender being_set_gender entity:set_gender being_type entity:type being_walk entity:walk being_say entity:say being_damage entity:damage being_heal entity:heal being_get_name entity:name being_get_action entity:action being_set_action entity:set_action being_get_direction entity:direction being_set_direction entity:set_direction being_apply_attribute_modifier entity:apply_attribute_modifier being_remove_attribute_modifier entity:remove_attribute_modifier being_set_base_attribute entity:set_base_attribute being_get_modified_attribute entity:modified_attribute being_get_base_attribute entity:base_attribute being_set_walkmask entity:set_walkmask being_get_walkmask entity:walkmask being_get_mapid entity:mapid chat_message entity:message being_register entity:register chr_shake_screen entity:shake_screen chr_create_text_particle entity:show_text_particle - entity:position posX entity:x posY entity:y monster_get_name monsterclass:name item_get_name itemclass:name
Diffstat (limited to 'src/game-server')
-rw-r--r--src/game-server/entity.h18
-rw-r--r--src/game-server/state.cpp8
-rw-r--r--src/game-server/state.h2
3 files changed, 21 insertions, 7 deletions
diff --git a/src/game-server/entity.h b/src/game-server/entity.h
index 2f360df..bb76e44 100644
--- a/src/game-server/entity.h
+++ b/src/game-server/entity.h
@@ -52,6 +52,7 @@ class Entity : public sigc::trackable
template <class T> void addComponent(T *component);
template <class T> T *getComponent() const;
+ template <class T> T *findComponent() const;
template <class T> bool hasComponent() const;
bool isVisible() const;
@@ -106,8 +107,11 @@ inline Component *Entity::getComponent(ComponentType type) const
}
/**
- * Get a component by its class. Avoids the need for doing a static-
- * cast in the calling code.
+ * Get a component by its class. Avoids the need for doing a static-cast in the
+ * calling code.
+ *
+ * Asserts that the component is actually there. Use findComponent instead if
+ * you're not sure whether the requested component is actually present.
*/
template <class T>
inline T *Entity::getComponent() const
@@ -118,6 +122,16 @@ inline T *Entity::getComponent() const
}
/**
+ * Finds a component by its class. Returns 0 when the entity does not have the
+ * requested component.
+ */
+template <class T>
+inline T *Entity::findComponent() const
+{
+ return static_cast<T*>(getComponent(T::type));
+}
+
+/**
* Returns whether this class has a certain component.
*/
template <class T>
diff --git a/src/game-server/state.cpp b/src/game-server/state.cpp
index 1086966..58d848d 100644
--- a/src/game-server/state.cpp
+++ b/src/game-server/state.cpp
@@ -823,18 +823,18 @@ void GameState::enqueueWarp(Entity *ptr,
enqueueEvent(ptr, event);
}
-void GameState::sayAround(Entity *obj, const std::string &text)
+void GameState::sayAround(Entity *entity, const std::string &text)
{
- Point speakerPosition = obj->getComponent<ActorComponent>()->getPosition();
+ Point speakerPosition = entity->getComponent<ActorComponent>()->getPosition();
int visualRange = Configuration::getValue("game_visualRange", 448);
- for (CharacterIterator i(obj->getMap()->getAroundActorIterator(obj, visualRange)); i; ++i)
+ for (CharacterIterator i(entity->getMap()->getAroundActorIterator(entity, visualRange)); i; ++i)
{
const Point &point =
(*i)->getComponent<ActorComponent>()->getPosition();
if (speakerPosition.inRangeOf(point, visualRange))
{
- sayTo(*i, obj, text);
+ sayTo(*i, entity, text);
}
}
}
diff --git a/src/game-server/state.h b/src/game-server/state.h
index 4f690ad..147a57c 100644
--- a/src/game-server/state.h
+++ b/src/game-server/state.h
@@ -99,7 +99,7 @@ namespace GameState
/**
* Says something to everything around an actor.
*/
- void sayAround(Entity *, const std::string &text);
+ void sayAround(Entity *entity, const std::string &text);
/**
* Says something to every player on the server.