summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog8
-rw-r--r--src/Makefile.am2
-rw-r--r--src/game-server/monster.cpp179
-rw-r--r--src/game-server/monster.hpp132
-rw-r--r--src/game-server/spawnarea.cpp68
-rw-r--r--src/game-server/spawnarea.hpp51
-rw-r--r--src/game-server/state.hpp1
-rw-r--r--src/game-server/testing.cpp26
-rw-r--r--src/game-server/trigger.hpp2
9 files changed, 296 insertions, 173 deletions
diff --git a/ChangeLog b/ChangeLog
index 77ebea81..87da126b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,11 @@
+2007-03-31 Bjørn Lindeijer <bjorn@lindeijer.nl>
+
+ * src/Makefile.am, src/game-server/testing.cpp,
+ src/game-server/spawnarea.cpp, src/game-server/state.hpp,
+ src/game-server/spawnarea.hpp, src/game-server/monster.cpp,
+ src/game-server/monster.hpp, src/game-server/trigger.hpp: Made a start
+ with having monsters spawn using a SpawnArea.
+
2007-03-30 Bjørn Lindeijer <bjorn@lindeijer.nl>
* src/Makefile.am, src/game-server/thing.hpp,
diff --git a/src/Makefile.am b/src/Makefile.am
index 3df85d79..229d7112 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -105,6 +105,8 @@ tmwserv_game_SOURCES = \
game-server/movingobject.hpp \
game-server/movingobject.cpp \
game-server/object.hpp \
+ game-server/spawnarea.hpp \
+ game-server/spawnarea.cpp \
game-server/state.hpp \
game-server/state.cpp \
game-server/testing.cpp \
diff --git a/src/game-server/monster.cpp b/src/game-server/monster.cpp
index 91f7e16e..03cb6384 100644
--- a/src/game-server/monster.cpp
+++ b/src/game-server/monster.cpp
@@ -1,89 +1,90 @@
-/*
- * The Mana World Server
- * 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: controller.cpp 3191 2007-03-15 23:47:13Z crush_tmw $
- */
-
-#include "game-server/monster.hpp"
-
-#include "utils/logger.h"
-
-Monster::Monster():
- Being(OBJECT_MONSTER, 65535),
- mCountDown(0)
-{
- mAttributes.resize(NB_ATTRIBUTES_CONTROLLED, 1); // TODO: fill with the real attributes
-}
-
-void Monster::update()
-{
- /* Temporary "AI" behaviour that is purely artificial and not at all
- * intelligent.
- */
- if (mCountDown == 0)
- {
- if (mAction != DEAD)
- {
- Point randomPos( rand() % 320 + 720,
- rand() % 320 + 840 );
- setDestination(randomPos);
- mCountDown = 10 + rand() % 10;
-
- LOG_DEBUG("Setting new random destination " << randomPos.x << ","
- << randomPos.y << " for being " << getPublicID());
- }
- else
- {
- raiseUpdateFlags(UPDATEFLAG_REMOVE);
- }
- }
- else
- {
- mCountDown--;
- }
-}
-
-void Monster::die()
-{
- mCountDown = 50; //sets remove time to 5 seconds
- Being::die();
-}
-
-WeaponStats Monster::getWeaponStats()
-{
-
- WeaponStats weaponStats;
-
- /*
- * TODO: This should all be set by the monster database
- */
- weaponStats.piercing = 1;
- weaponStats.element = ELEMENT_NEUTRAL;
- weaponStats.skill = MONSTER_SKILL_WEAPON;
-
- return weaponStats;
-}
-
-void Monster::calculateDerivedAttributes()
-{
- Being::calculateDerivedAttributes();
- /*
- * Do any monster specific attribute calculation here
- */
-}
+/*
+ * The Mana World Server
+ * 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 "game-server/monster.hpp"
+
+#include "utils/logger.h"
+
+Monster::Monster():
+ Being(OBJECT_MONSTER, 65535),
+ mCountDown(0)
+{
+ LOG_DEBUG("Monster spawned!");
+ mAttributes.resize(NB_ATTRIBUTES_CONTROLLED, 1); // TODO: fill with the real attributes
+}
+
+void Monster::update()
+{
+ /* Temporary "AI" behaviour that is purely artificial and not at all
+ * intelligent.
+ */
+ if (mCountDown == 0)
+ {
+ if (mAction != DEAD)
+ {
+ Point randomPos( rand() % 320 + 720,
+ rand() % 320 + 840 );
+ setDestination(randomPos);
+ mCountDown = 10 + rand() % 10;
+
+ LOG_DEBUG("Setting new random destination " << randomPos.x << ","
+ << randomPos.y << " for being " << getPublicID());
+ }
+ else
+ {
+ raiseUpdateFlags(UPDATEFLAG_REMOVE);
+ }
+ }
+ else
+ {
+ mCountDown--;
+ }
+}
+
+void Monster::die()
+{
+ mCountDown = 50; //sets remove time to 5 seconds
+ Being::die();
+}
+
+WeaponStats Monster::getWeaponStats()
+{
+
+ WeaponStats weaponStats;
+
+ /*
+ * TODO: This should all be set by the monster database
+ */
+ weaponStats.piercing = 1;
+ weaponStats.element = ELEMENT_NEUTRAL;
+ weaponStats.skill = MONSTER_SKILL_WEAPON;
+
+ return weaponStats;
+}
+
+void Monster::calculateDerivedAttributes()
+{
+ Being::calculateDerivedAttributes();
+ /*
+ * Do any monster specific attribute calculation here
+ */
+}
diff --git a/src/game-server/monster.hpp b/src/game-server/monster.hpp
index 8c32e67f..da5cb71f 100644
--- a/src/game-server/monster.hpp
+++ b/src/game-server/monster.hpp
@@ -1,66 +1,66 @@
-/*
- * The Mana World Server
- * 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: controller.h 3191 2007-03-15 23:47:13Z crush_tmw $
- */
-
-#ifndef _TMWSERV_MONSTER_H_
-#define _TMWSERV_MONSTER_H_
-
-#include "game-server/being.hpp"
-
-/**
- * The class for a fightable monster with its own AI
- */
-class Monster: public Being
-{
- public:
- /**
- * Constructor.
- */
- Monster();
-
- /**
- * Performs one step of controller logic.
- */
- void update();
-
- /**
- * Kills the being
- */
- virtual void die();
-
- protected:
- /**
- * Gets the stats of the currently equipped weapon that are relevant
- * for damage calculation
- */
- virtual WeaponStats getWeaponStats();
-
- /**
- * Calculates all derived attributes
- */
- void calculateDerivedAttributes();
-
- private:
- /** Count down till next random movement (temporary). */
- unsigned int mCountDown;
-};
-
-#endif // _TMWSERV_MONSTER_H_
+/*
+ * The Mana World Server
+ * 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$
+ */
+
+#ifndef _TMWSERV_MONSTER_H_
+#define _TMWSERV_MONSTER_H_
+
+#include "game-server/being.hpp"
+
+/**
+ * The class for a fightable monster with its own AI
+ */
+class Monster: public Being
+{
+ public:
+ /**
+ * Constructor.
+ */
+ Monster();
+
+ /**
+ * Performs one step of controller logic.
+ */
+ void update();
+
+ /**
+ * Kills the being
+ */
+ virtual void die();
+
+ protected:
+ /**
+ * Gets the stats of the currently equipped weapon that are relevant
+ * for damage calculation
+ */
+ virtual WeaponStats getWeaponStats();
+
+ /**
+ * Calculates all derived attributes
+ */
+ void calculateDerivedAttributes();
+
+ private:
+ /** Count down till next random movement (temporary). */
+ unsigned int mCountDown;
+};
+
+#endif // _TMWSERV_MONSTER_H_
diff --git a/src/game-server/spawnarea.cpp b/src/game-server/spawnarea.cpp
new file mode 100644
index 00000000..56430473
--- /dev/null
+++ b/src/game-server/spawnarea.cpp
@@ -0,0 +1,68 @@
+/*
+ * The Mana World Server
+ * Copyright 2006 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 "spawnarea.hpp"
+
+#include "game-server/monster.hpp"
+#include "game-server/state.hpp"
+
+#include "utils/logger.h"
+
+/*
+ * TODO: Take into account spawn rate.
+ * TODO: Be a death listener to spawned monsters, to adjust mNumBeings.
+ * TODO: Allow specifying being type and use it.
+ */
+
+SpawnArea::SpawnArea(int mapId, const Rectangle &zone):
+ Thing(OBJECT_OTHER),
+ mZone(zone),
+ mMaxBeings(10),
+ mBeingType(1),
+ mSpawnRate(10),
+ mNumBeings(0)
+{
+ setMapId(mapId);
+}
+
+void
+SpawnArea::update()
+{
+ while (mNumBeings < mMaxBeings)
+ {
+ Being *being = new Monster();
+
+ // some bogus stats for testing
+ being->setSpeed(150);
+ being->setSize(8);
+ being->setAttribute(BASE_ATTR_VITALITY, 10);
+ being->fillHitpoints();
+
+ being->setMapId(1);
+ being->setPosition(Point(mZone.x + rand() % mZone.w,
+ mZone.y + rand() % mZone.h));
+ gameState->insert(being);
+
+ mNumBeings++;
+ }
+}
diff --git a/src/game-server/spawnarea.hpp b/src/game-server/spawnarea.hpp
new file mode 100644
index 00000000..5d141fa8
--- /dev/null
+++ b/src/game-server/spawnarea.hpp
@@ -0,0 +1,51 @@
+/*
+ * The Mana World Server
+ * Copyright 2006 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$
+ */
+
+#ifndef _TMWSERV_SPAWNAREA
+#define _TMWSERV_SPAWNAREA
+
+#include "point.h"
+#include "game-server/thing.hpp"
+
+/**
+ * A spawn area, where monsters spawn. The area is a rectangular field and will
+ * spawn a certain number of a given monster type.
+ */
+class SpawnArea : public Thing
+{
+ public:
+ SpawnArea(int mapId, const Rectangle &zone);
+
+ virtual ~SpawnArea() {}
+
+ virtual void update();
+
+ protected:
+ Rectangle mZone;
+ int mMaxBeings; /**< Maximum population of this area. */
+ int mBeingType; /**< Type of being that spawns in this area. */
+ int mSpawnRate; /**< Number of beings spawning per minute. */
+ int mNumBeings; /**< Current population of this area. */
+};
+
+#endif
diff --git a/src/game-server/state.hpp b/src/game-server/state.hpp
index 80db0461..adbeb99a 100644
--- a/src/game-server/state.hpp
+++ b/src/game-server/state.hpp
@@ -90,6 +90,7 @@ class State
* Gets a composite map.
*/
MapComposite *getMap(int map);
+
/**
* Inserts an object on the map.
*/
diff --git a/src/game-server/testing.cpp b/src/game-server/testing.cpp
index 5db3557c..cd2f08fb 100644
--- a/src/game-server/testing.cpp
+++ b/src/game-server/testing.cpp
@@ -5,8 +5,8 @@
#include <cassert>
#include "defines.h"
-#include "game-server/monster.hpp"
#include "game-server/itemmanager.hpp"
+#include "game-server/spawnarea.hpp"
#include "game-server/state.hpp"
#include "game-server/trigger.hpp"
@@ -32,29 +32,21 @@ void testingMap(int id)
{
case 1:
{
+ // Create maggot spawn area
+ Rectangle maggotSpawnRect = { 720, 900, 320, 320 };
+ gameState->insert(new SpawnArea(1, maggotSpawnRect));
+
+ // Portal to map 3
gameState->insert(new TriggerArea(1, rectA, &warpA));
- for (int i = 0; i < 10; i++)
- {
- Being *being = new Monster();
- being->setSpeed(150);
- being->setSize(8);
-
- // some bogus stats for testing
- being->setAttribute(BASE_ATTR_VITALITY, 10);
-
- being->fillHitpoints();
-
- being->setMapId(1);
- Point pos(720, 900);
- being->setPosition(pos);
- gameState->insert(being);
- }
+
+ // Drop some items
dropItem(1, 58 * 32 + 16, 20 * 32 + 16, 508);
dropItem(1, 58 * 32 + 16, 21 * 32 + 16, 524);
} break;
case 3:
{
+ // Portal to map 1
gameState->insert(new TriggerArea(3, rectB, &warpB));
} break;
}
diff --git a/src/game-server/trigger.hpp b/src/game-server/trigger.hpp
index c24e73be..d444f75e 100644
--- a/src/game-server/trigger.hpp
+++ b/src/game-server/trigger.hpp
@@ -54,7 +54,7 @@ class TriggerArea : public Thing
/**
* Creates a rectangular trigger for a given map.
*/
- TriggerArea(int, Rectangle const &, TriggerAction *);
+ TriggerArea(int map, Rectangle const &, TriggerAction *);
virtual void update();
private: