summaryrefslogtreecommitdiff
path: root/src/beingmanager.cpp
diff options
context:
space:
mode:
authorBjörn Steinbrink <B.Steinbrink@gmx.de>2006-01-22 13:31:13 +0000
committerBjörn Steinbrink <B.Steinbrink@gmx.de>2006-01-22 13:31:13 +0000
commitbd56bf8afdab16383ed8ad08412a8c807f84af85 (patch)
tree0e963ada63bcbe3c50dd77986aaa15b9ba49816a /src/beingmanager.cpp
parent5359640b6f271af31f6423df9d661433eff89a3e (diff)
downloadmana-bd56bf8afdab16383ed8ad08412a8c807f84af85.tar.gz
mana-bd56bf8afdab16383ed8ad08412a8c807f84af85.tar.bz2
mana-bd56bf8afdab16383ed8ad08412a8c807f84af85.tar.xz
mana-bd56bf8afdab16383ed8ad08412a8c807f84af85.zip
Merged NETWORK branch (includes BEING_OVERHAUL).
Diffstat (limited to 'src/beingmanager.cpp')
-rw-r--r--src/beingmanager.cpp143
1 files changed, 143 insertions, 0 deletions
diff --git a/src/beingmanager.cpp b/src/beingmanager.cpp
new file mode 100644
index 00000000..e6c88041
--- /dev/null
+++ b/src/beingmanager.cpp
@@ -0,0 +1,143 @@
+/*
+ * The Mana World
+ * Copyright 2004 The Mana World Development Team
+ *
+ * This file is part of The Mana World.
+ *
+ * The Mana World is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * any later version.
+ *
+ * The Mana World is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with The Mana World; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * $Id$
+ */
+
+#include "beingmanager.h"
+
+#include "localplayer.h"
+#include "monster.h"
+#include "npc.h"
+#include "player.h"
+
+#include "net/messageout.h"
+#include "net/protocol.h"
+
+class FindBeingFunctor
+{
+ public:
+ bool operator() (Being *being)
+ {
+ Uint16 other_y = y + ((being->getType() == Being::NPC) ? 1 : 0);
+ return (being->x == x && (being->y == y || being->y == other_y) &&
+ being->action != Being::MONSTER_DEAD &&
+ (type == Being::UNKNOWN || being->getType() == type));
+ }
+
+ Uint16 x, y;
+ Being::Type type;
+} beingFinder;
+
+BeingManager::BeingManager(Network *network):
+ mNetwork(network)
+{
+}
+
+void BeingManager::setMap(Map *map)
+{
+ mMap = map;
+ if (player_node)
+ player_node->setMap(map);
+}
+
+void BeingManager::setPlayer(LocalPlayer *player)
+{
+ player_node = player;
+ mBeings.push_back(player);
+}
+
+Being* BeingManager::createBeing(Uint32 id, Uint16 job)
+{
+ Being *being;
+
+ if (job < 10)
+ {
+ being = new Player(id, job, mMap);
+ MessageOut outMsg(mNetwork);
+ outMsg.writeInt16(0x0094);
+ outMsg.writeInt32(id);//readLong(2));
+ }
+ else if (job >= 100 & job < 200)
+ being = new NPC(id, job, mMap, mNetwork);
+ else if (job >= 1000 && job < 1200)
+ being = new Monster(id, job, mMap);
+ else
+ being = new Being(id, job, mMap);
+
+ mBeings.push_back(being);
+
+ return being;
+}
+
+void BeingManager::destroyBeing(Being *being)
+{
+ mBeings.remove(being);
+ delete being;
+}
+
+Being* BeingManager::findBeing(Uint32 id)
+{
+ for (Beings::iterator i = mBeings.begin(); i != mBeings.end(); i++)
+ {
+ Being *being = (*i);
+ if (being->getId() == id) {
+ return being;
+ }
+ }
+ return NULL;
+}
+
+Being* BeingManager::findBeing(Uint16 x, Uint16 y, Being::Type type)
+{
+ beingFinder.x = x;
+ beingFinder.y = y;
+ beingFinder.type = type;
+
+ Beings::iterator i = find_if(mBeings.begin(), mBeings.end(), beingFinder);
+
+ return (i == mBeings.end()) ? NULL : *i;
+}
+
+Beings* BeingManager::getAll()
+{
+ return &mBeings;
+}
+
+void BeingManager::clear()
+{
+ if (player_node)
+ {
+ mBeings.remove(player_node);
+ }
+
+ Beings::iterator i;
+ for (i = mBeings.begin(); i != mBeings.end(); i++)
+ {
+ delete (*i);
+ }
+
+ mBeings.clear();
+
+ if (player_node)
+ {
+ mBeings.push_back(player_node);
+ }
+}