From 7aee56f062989c8901322a09b2da40bb028eb222 Mon Sep 17 00:00:00 2001 From: Thorbjørn Lindeijer Date: Sun, 18 Mar 2012 22:24:38 +0100 Subject: Changed Item to a component of Actor Items also have positions, so the ItemComponent only makes sense as part of an Actor. Later on it will probably be part of an entity that also has an ActorComponent. Since it was annoying to update all the places where items were created, I've introduced a function for this. The component types are now prefixed with "CT_" because I wanted to introduce an 'Item' namespace which would otherwise be conflicting. The component types enum isn't used much in the code so it can look a bit ugly. Reviewed-by: Yohann Ferreira --- src/game-server/monster.cpp | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) (limited to 'src/game-server/monster.cpp') diff --git a/src/game-server/monster.cpp b/src/game-server/monster.cpp index 3899c792..edc89ec1 100644 --- a/src/game-server/monster.cpp +++ b/src/game-server/monster.cpp @@ -414,7 +414,8 @@ int Monster::damage(Actor *source, const Damage &damage) void Monster::died() { - if (mAction == DEAD) return; + if (mAction == DEAD) + return; Being::died(); mDecayTimeout.set(DECAY_TIME); @@ -426,11 +427,13 @@ void Monster::died() for (unsigned i = 0; i < size; i++) { const int p = rand() / (RAND_MAX / 10000); - if (p <= mSpecy->mDrops[i].probability) + const MonsterDrop &drop = mSpecy->mDrops[i]; + + if (p <= drop.probability) { - Item *item = new Item(mSpecy->mDrops[i].item, 1); - item->setMap(getMap()); - item->setPosition(getPosition()); + Actor *item = Item::create(getMap(), + getPosition(), + drop.item, 1); GameState::enqueueInsert(item); } } -- cgit v1.2.3-60-g2f50