summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog6
-rw-r--r--accountserver.cbp10
-rw-r--r--gameserver.cbp34
-rw-r--r--src/game-server/mapreader.cpp151
-rw-r--r--src/game-server/testing.cpp30
5 files changed, 178 insertions, 53 deletions
diff --git a/ChangeLog b/ChangeLog
index d5db867..e69a02b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2007-08-27 Eugenio Favalli <elvenprogrammer@gmail.com>
+
+ * accountserver.cbp, gameserver.cbp, src/game-server/mapreader.cpp,
+ src/game-server/testing.cpp: Enabled loading of npcs and scripts from
+ map files.
+
2007-08-27 Guillaume Melquiond <guillaume.melquiond@gmail.com>
* src/chat-server/chathandler.hpp, src/chat-server/chatclient.hpp,
diff --git a/accountserver.cbp b/accountserver.cbp
index 776a3e1..e525625 100644
--- a/accountserver.cbp
+++ b/accountserver.cbp
@@ -380,6 +380,16 @@
<Option link="0"/>
<Option target="default"/>
</Unit>
+ <Unit filename="src\utils\tokencollector.cpp">
+ <Option compilerVar="CPP"/>
+ <Option target="default"/>
+ </Unit>
+ <Unit filename="src\utils\tokencollector.hpp">
+ <Option compilerVar=""/>
+ <Option compile="0"/>
+ <Option link="0"/>
+ <Option target="default"/>
+ </Unit>
<Unit filename="src\utils\tokendispenser.cpp">
<Option compilerVar="CPP"/>
<Option target="default"/>
diff --git a/gameserver.cbp b/gameserver.cbp
index 666996c..f90293e 100644
--- a/gameserver.cbp
+++ b/gameserver.cbp
@@ -73,6 +73,16 @@
<Option link="0"/>
<Option target="default"/>
</Unit>
+ <Unit filename="src\game-server\buysell.cpp">
+ <Option compilerVar="CPP"/>
+ <Option target="default"/>
+ </Unit>
+ <Unit filename="src\game-server\buysell.hpp">
+ <Option compilerVar=""/>
+ <Option compile="0"/>
+ <Option link="0"/>
+ <Option target="default"/>
+ </Unit>
<Unit filename="src\game-server\character.cpp">
<Option compilerVar="CPP"/>
<Option target="default"/>
@@ -93,6 +103,10 @@
<Option link="0"/>
<Option target="default"/>
</Unit>
+ <Unit filename="src\game-server\command.cpp">
+ <Option compilerVar="CPP"/>
+ <Option target="default"/>
+ </Unit>
<Unit filename="src\game-server\gamehandler.cpp">
<Option compilerVar="CPP"/>
<Option target="default"/>
@@ -113,6 +127,16 @@
<Option link="0"/>
<Option target="default"/>
</Unit>
+ <Unit filename="src\game-server\item.cpp">
+ <Option compilerVar="CPP"/>
+ <Option target="default"/>
+ </Unit>
+ <Unit filename="src\game-server\item.hpp">
+ <Option compilerVar=""/>
+ <Option compile="0"/>
+ <Option link="0"/>
+ <Option target="default"/>
+ </Unit>
<Unit filename="src\game-server\itemmanager.cpp">
<Option compilerVar="CPP"/>
<Option target="default"/>
@@ -397,6 +421,16 @@
<Option link="0"/>
<Option target="default"/>
</Unit>
+ <Unit filename="src\utils\tokencollector.cpp">
+ <Option compilerVar="CPP"/>
+ <Option target="default"/>
+ </Unit>
+ <Unit filename="src\utils\tokencollector.hpp">
+ <Option compilerVar=""/>
+ <Option compile="0"/>
+ <Option link="0"/>
+ <Option target="default"/>
+ </Unit>
<Unit filename="src\utils\tokendispenser.cpp">
<Option compilerVar="CPP"/>
<Option target="default"/>
diff --git a/src/game-server/mapreader.cpp b/src/game-server/mapreader.cpp
index 88b9eec..5997ae4 100644
--- a/src/game-server/mapreader.cpp
+++ b/src/game-server/mapreader.cpp
@@ -29,6 +29,7 @@
#include "game-server/monstermanager.hpp"
#include "game-server/spawnarea.hpp"
#include "game-server/trigger.hpp"
+#include "scripting/script.hpp"
#include "utils/base64.h"
#include "utils/logger.h"
#include "utils/xml.hpp"
@@ -99,6 +100,13 @@ void MapReader::readMap(const std::string &filename, MapComposite *composite)
{
composite->insert(*i);
}
+
+ if (Script *s = composite->getScript())
+ {
+ s->setMap(composite);
+ s->prepare("initialize");
+ s->execute();
+ }
}
}
@@ -175,6 +183,10 @@ static Map *readMap(xmlNodePtr node, std::string const &path, MapComposite *comp
if (objType == "WARP")
{
+ int destMapId = -1;
+ int destX = -1;
+ int destY = -1;
+
for_each_xml_child_node(propertiesNode, objectNode)
{
if (!xmlStrEqual(propertiesNode->name, BAD_CAST "properties"))
@@ -182,10 +194,6 @@ static Map *readMap(xmlNodePtr node, std::string const &path, MapComposite *comp
continue;
}
- int destMapId = -1;
- int destX = -1;
- int destY = -1;
-
for_each_xml_child_node(propertyNode, propertiesNode)
{
if (xmlStrEqual(propertyNode->name, BAD_CAST "property"))
@@ -205,25 +213,27 @@ static Map *readMap(xmlNodePtr node, std::string const &path, MapComposite *comp
}
}
}
+ }
- if (destMapId != -1 && destX != -1 && destY != -1)
- {
- MapComposite *destMap = MapManager::getMap(destMapId);
- if (destMap)
- {
- things.push_back(new TriggerArea(
- composite, rect,
- new WarpAction(destMap, destX, destY)));
- }
- }
- else
+ if (destMapId != -1 && destX != -1 && destY != -1)
+ {
+ MapComposite *destMap = MapManager::getMap(destMapId);
+ if (destMap)
{
- LOG_WARN("Unrecognized warp format");
+ things.push_back(new TriggerArea(
+ composite, rect,
+ new WarpAction(destMap, destX, destY)));
}
}
+ else
+ {
+ LOG_WARN("Unrecognized warp format");
+ }
}
else if (objType == "SPAWN")
{
+ int monsterId = -1;
+
for_each_xml_child_node(propertiesNode, objectNode)
{
if (!xmlStrEqual(propertiesNode->name, BAD_CAST "properties"))
@@ -231,8 +241,6 @@ static Map *readMap(xmlNodePtr node, std::string const &path, MapComposite *comp
continue;
}
- int monsterId = -1;
-
for_each_xml_child_node(propertyNode, propertiesNode)
{
if (xmlStrEqual(propertyNode->name, BAD_CAST "property"))
@@ -243,16 +251,113 @@ static Map *readMap(xmlNodePtr node, std::string const &path, MapComposite *comp
}
}
}
+ }
- MonsterClass *monster = MonsterManager::getMonster(monsterId);
- if (monster != NULL)
+ MonsterClass *monster = MonsterManager::getMonster(monsterId);
+ if (monster != NULL)
+ {
+ things.push_back(new SpawnArea(composite, monster, rect));
+ }
+ else
+ {
+ LOG_WARN("Unrecognized format for spawn area");
+ }
+ }
+ else if (objType == "NPC")
+ {
+ Script *s = composite->getScript();
+ if (!s)
+ {
+ // Create a Lua context.
+ s = Script::create("lua");
+ composite->setScript(s);
+ }
+
+ int npcId = -1;
+ char const *scriptText = NULL;
+
+ for_each_xml_child_node(propertiesNode, objectNode)
+ {
+ if (!xmlStrEqual(propertiesNode->name, BAD_CAST "properties"))
{
- things.push_back(new SpawnArea(composite, monster, rect));
+ continue;
}
- else
+
+ for_each_xml_child_node(propertyNode, propertiesNode)
{
- LOG_WARN("Unrecognized format for spawn area");
+ if (xmlStrEqual(propertyNode->name, BAD_CAST "property"))
+ {
+ std::string value = XML::getProperty(propertyNode, "name", std::string());
+ if (value == "NPC_ID")
+ {
+ npcId = atoi((const char *)propertyNode->xmlChildrenNode->content);
+ }
+ else if (value == "SCRIPT")
+ {
+ scriptText = (const char *)propertyNode->xmlChildrenNode->content;
+ }
+ }
+ }
+ }
+
+ if (npcId != -1 && scriptText != NULL)
+ {
+ s->loadNPC(npcId, objX, objY, scriptText);
+ }
+ else
+ {
+ LOG_WARN("Unrecognized format for npc");
+ }
+ }
+ else if (objType == "SCRIPT")
+ {
+ printf("SCRIPT");
+ Script *s = composite->getScript();
+ if (!s)
+ {
+ // Create a Lua context.
+ s = Script::create("lua");
+ composite->setScript(s);
+ }
+
+ char const *scriptFilename = NULL;
+ char const *scriptText = NULL;
+
+ for_each_xml_child_node(propertiesNode, objectNode)
+ {
+ if (!xmlStrEqual(propertiesNode->name, BAD_CAST "properties"))
+ {
+ continue;
}
+
+ for_each_xml_child_node(propertyNode, propertiesNode)
+ {
+ if (xmlStrEqual(propertyNode->name, BAD_CAST "property"))
+ {
+ std::string value = XML::getProperty(propertyNode, "name", std::string());
+ if (value == "FILENAME")
+ {
+ scriptFilename = (const char *)propertyNode->xmlChildrenNode->content;
+ }
+ else if (value == "TEXT")
+ {
+ scriptText = (const char *)propertyNode->xmlChildrenNode->content;
+ }
+ }
+ }
+ }
+
+ if (scriptFilename != NULL)
+ {
+ s->loadFile(scriptFilename);
+ }
+ else if (scriptText != NULL)
+ {
+ s->load(scriptText);
+ }
+ else
+ {
+ LOG_WARN("Unrecognized format for script");
}
}
}
diff --git a/src/game-server/testing.cpp b/src/game-server/testing.cpp
index cbff614..cf125ca 100644
--- a/src/game-server/testing.cpp
+++ b/src/game-server/testing.cpp
@@ -22,19 +22,6 @@ static void dropItem(MapComposite *map, int x, int y, int type)
GameState::insert(i);
}
-static char const *npc1 =
- "local nb_times = 1\n"
- "function npc_handler(npc, ch)\n"
- " do_message(npc, ch, \"You know what?\")\n"
- " do_message(npc, ch, string.format(\"I have already asked this question %d times today.\", nb_times))\n"
- " nb_times = nb_times + 1\n"
- "end\n";
-
-static char const *npc2 =
- "function npc_handler(npc, ch)\n"
- " do_message(npc, ch, \"Don't you think the guy behind me is my evil twin?\")\n"
- "end\n";
-
void testingMap(MapComposite *map)
{
switch (map->getID())
@@ -44,23 +31,6 @@ void testingMap(MapComposite *map)
// Drop some items.
dropItem(map, 58 * 32 + 16, 20 * 32 + 16, 508);
dropItem(map, 58 * 32 + 16, 21 * 32 + 16, 524);
-
- // Create a Lua context.
- if (Script *s = Script::create("lua"))
- {
- // Load a script.
- s->loadFile("test.lua");
-
- // Create two NPCs.
- s->loadNPC(107, 53 * 32 + 16, 21 * 32 + 16, npc1);
- s->loadNPC(107, 53 * 32 + 16, 23 * 32 + 16, npc2);
-
- // Associate the script context to the map.
- map->setScript(s);
- s->setMap(map);
- s->prepare("initialize");
- s->execute();
- }
} break;
}
}