summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThorbjørn Lindeijer <thorbjorn@lindeijer.nl>2013-05-10 15:51:14 +0200
committerThorbjørn Lindeijer <thorbjorn@lindeijer.nl>2013-05-10 15:51:14 +0200
commit598f79c6dd78be5c0ca684c19172f3b9d3420a44 (patch)
treed5727018585de90709da7d4e22bc6d6199a48ce1
parented8fba0a47d2e498267cbfbf1271bacb76c400e9 (diff)
parent000dcd8064d60f9f34077ca0a1731af4b8773b52 (diff)
downloadmanaserv-lpc2012.tar.gz
manaserv-lpc2012.tar.bz2
manaserv-lpc2012.tar.xz
manaserv-lpc2012.zip
Merge branch 'master' into lpc2012lpc2012
-rw-r--r--example/settings.xml5
-rw-r--r--gameserver.cbp2
-rw-r--r--src/game-server/map.h3
-rw-r--r--src/game-server/mapcomposite.cpp133
-rw-r--r--src/game-server/triggerareacomponent.cpp41
-rw-r--r--src/game-server/triggerareacomponent.h33
6 files changed, 186 insertions, 31 deletions
diff --git a/example/settings.xml b/example/settings.xml
index ebe7a717..c2ba755d 100644
--- a/example/settings.xml
+++ b/example/settings.xml
@@ -6,6 +6,9 @@
<include file="equip.xml" />
<include file="items.xml" />
<include file="monsters.xml" />
+ <include file="npcs.xml" />
<include file="emotes.xml" />
<include file="status-effects.xml" />
-</settings> \ No newline at end of file
+ <include file="hair.xml" />
+ <include file="units.xml" />
+</settings>
diff --git a/gameserver.cbp b/gameserver.cbp
index 7cffe21d..ee0bde82 100644
--- a/gameserver.cbp
+++ b/gameserver.cbp
@@ -172,6 +172,8 @@
<Unit filename="src/game-server/postman.h" />
<Unit filename="src/game-server/quest.cpp" />
<Unit filename="src/game-server/quest.h" />
+ <Unit filename="src/game-server/settingsmanager.cpp" />
+ <Unit filename="src/game-server/settingsmanager.h" />
<Unit filename="src/game-server/skillmanager.cpp" />
<Unit filename="src/game-server/skillmanager.h" />
<Unit filename="src/game-server/spawnareacomponent.cpp" />
diff --git a/src/game-server/map.h b/src/game-server/map.h
index 2ade1d75..33663d37 100644
--- a/src/game-server/map.h
+++ b/src/game-server/map.h
@@ -83,6 +83,9 @@ class MapObject
const std::string &getProperty(const std::string &key) const
{ return mProperties.value(key); }
+ bool hasProperty(const std::string &key) const
+ { return mProperties.contains(key); }
+
const std::string &getName() const
{ return mName; }
diff --git a/src/game-server/mapcomposite.cpp b/src/game-server/mapcomposite.cpp
index 4a5d800e..2b12a39b 100644
--- a/src/game-server/mapcomposite.cpp
+++ b/src/game-server/mapcomposite.cpp
@@ -775,51 +775,124 @@ void MapComposite::initializeContent()
if (utils::compareStrI(type, "WARP") == 0)
{
- std::string destMapName = object->getProperty("DEST_MAP");
- std::string destMapObjectName = object->getProperty("DEST_NAME");
-
+ const std::string destMapName = object->getProperty("DEST_MAP");
+ const Rectangle &sourceBounds = object->getBounds();
MapComposite *destMap = MapManager::getMap(destMapName);
- int destX = 0;
- int destY = 0;
- if (destMap && !destMapObjectName.empty())
+ // check destination map
+ if (!destMap)
+ {
+ if (destMapName.empty())
+ {
+ // this must be a one way warp target
+ continue;
+ }
+
+ LOG_ERROR("Warp \"" << object->getName() << "\" targets missing map \""
+ << destMapName << "\" in " << getName());
+ continue;
+ }
+
+
+ TriggerAction* action;
+ if (object->hasProperty("DEST_NAME"))
{
- const MapObject *obj =
- destMap->findMapObject(destMapObjectName, "WARP");
- if (obj)
+ // warp to an object
+ // get destination object name
+ const std::string destMapObjectName = object->getProperty("DEST_NAME");
+ // get target object and validate it
+ const MapObject *destination = destMap->findMapObject(destMapObjectName, "WARP");
+ if (!destination)
{
- const Rectangle &rect = obj->getBounds();
- destX = rect.x + rect.w / 2;
- destY = rect.y + rect.h / 2;
+ LOG_ERROR("Warp \"" << object->getName() << "\" from map " << getName()
+ << " targets missing warp \"" << destMapObjectName << "\" "
+ << " on map " << destMap->getName());
+ continue;
+ }
+
+ const Rectangle &destinationBounds = destination->getBounds();
+
+ const std::string &exit = destination->getProperty("EXIT_DIRECTION");
+
+ if (exit.empty()) {
+ // old style WARP, warp to center of that object
+ int destX = destinationBounds.x + destinationBounds.w / 2;
+ int destY = destinationBounds.y + destinationBounds.h / 2;
+ action = new WarpAction(destMap, Point(destX, destY));
}
else
{
- LOG_ERROR("Warp target \"" << destMapObjectName << "\" "
- << "was not found on the map "
- << destMap->getName());
+ // newer and cooler warp
+
+ AutowarpAction::ExitDirection exitDir;
+
+ // find the exit direction
+ if (utils::compareStrI(exit, "NORTH") == 0)
+ {
+ exitDir = AutowarpAction::ExitNorth;
+ }
+ else if (utils::compareStrI(exit, "EAST") == 0)
+ {
+ exitDir = AutowarpAction::ExitEast;
+ }
+ else if (utils::compareStrI(exit, "SOUTH") == 0)
+ {
+ exitDir = AutowarpAction::ExitSouth;
+ }
+ else if (utils::compareStrI(exit, "WEST") == 0)
+ {
+ exitDir = AutowarpAction::ExitWest;
+ }
+ else
+ {
+ // invalid or missing exit direction
+ if (exit.empty())
+ {
+ LOG_ERROR("Warp target \"" << destMapObjectName << "\" on map "
+ << destMap->getName()
+ << " is missing exit direction!");
+ }
+ else
+ {
+ LOG_ERROR("Warp target \"" << destMapObjectName << "\" on map "
+ << destMap->getName()
+ << " has an invalid exit direction \""
+ << exit
+ << "\"!");
+ }
+ continue;
+ }
+
+ action = new AutowarpAction(destMap, sourceBounds,
+ destinationBounds, exitDir);
}
}
- else
+ else if (object->hasProperty("DEST_X") && object->hasProperty("DEST_Y"))
{
- destX = utils::stringToInt(object->getProperty("DEST_X"));
- destY = utils::stringToInt(object->getProperty("DEST_Y"));
- }
-
+ // warp to absolute position
+ int destX = utils::stringToInt(object->getProperty("DEST_X"));
+ int destY = utils::stringToInt(object->getProperty("DEST_Y"));
- if (destMap && destX && destY)
- {
- Entity *entity = new Entity(OBJECT_OTHER, this);
- const Point warpTarget(destX, destY);
- WarpAction *action = new WarpAction(destMap, warpTarget);
- entity->addComponent(
- new TriggerAreaComponent(object->getBounds(),
- action, false));
- insert(entity);
+ action = new WarpAction(destMap, Point(destX, destY));
}
else
{
- LOG_WARN("Unrecognized warp format on map " << mName);
+ LOG_ERROR("Warp \"" << object->getName() << "\" on map "
+ << getName()
+ << " is invalid!");
+ continue;
}
+
+ // add this trigger to the map
+ Entity *entity = new Entity(OBJECT_OTHER, this);
+ entity->addComponent(
+ new TriggerAreaComponent(
+ sourceBounds,
+ action,
+ false
+ )
+ );
+ insert(entity);
}
else if (utils::compareStrI(type, "SPAWN") == 0)
{
diff --git a/src/game-server/triggerareacomponent.cpp b/src/game-server/triggerareacomponent.cpp
index b599546b..04e77b6a 100644
--- a/src/game-server/triggerareacomponent.cpp
+++ b/src/game-server/triggerareacomponent.cpp
@@ -38,6 +38,47 @@ void WarpAction::process(Entity *obj)
}
}
+void AutowarpAction::process(Entity *obj)
+{
+ Point targetPoint;
+
+ // only characters can warp
+ if (obj->getType() != OBJECT_CHARACTER)
+ return;
+
+ // get the direction
+ ActorComponent *actor = obj->getComponent<ActorComponent>();
+
+ // calculate proportions
+ float horizontal = float(mTargetArea.w) / float(mSourceArea.w);
+ float vertical = float(mTargetArea.h) / float(mSourceArea.h);
+
+ // calculate final target position
+ const Point &actorPosition = actor->getPosition();
+ int actorSize = actor->getSize();
+ switch (mDirection)
+ {
+ case ExitNorth:
+ targetPoint.x = (actorPosition.x - mSourceArea.x) * horizontal + mTargetArea.x;
+ targetPoint.y = mTargetArea.y - actorSize;
+ break;
+ case ExitSouth:
+ targetPoint.x = (actorPosition.x - mSourceArea.x) * horizontal + mTargetArea.x;
+ targetPoint.y = mTargetArea.y + mTargetArea.h + actorSize;
+ break;
+ case ExitEast:
+ targetPoint.x = mTargetArea.x + mTargetArea.w + actorSize;
+ targetPoint.y = (actorPosition.y - mSourceArea.y) * vertical + mTargetArea.y;
+ break;
+ case ExitWest:
+ targetPoint.x = mTargetArea.x - actorSize;
+ targetPoint.y = (actorPosition.y - mSourceArea.y) * vertical + mTargetArea.y;
+ break;
+ }
+
+ GameState::enqueueWarp(obj, mMap, targetPoint);
+}
+
ScriptAction::ScriptAction(Script *script, Script::Ref callback, int arg) :
mScript(script),
mCallback(callback),
diff --git a/src/game-server/triggerareacomponent.h b/src/game-server/triggerareacomponent.h
index 3d2a8412..5857e55a 100644
--- a/src/game-server/triggerareacomponent.h
+++ b/src/game-server/triggerareacomponent.h
@@ -50,6 +50,39 @@ class WarpAction : public TriggerAction
Point mTargetPoint;
};
+class AutowarpAction: public TriggerAction
+{
+ public:
+ enum ExitDirection {
+ ExitNorth,
+ ExitEast,
+ ExitSouth,
+ ExitWest
+ };
+
+ AutowarpAction(MapComposite *m,
+ const Rectangle &sourceArea,
+ const Rectangle &targetArea,
+ ExitDirection direction)
+ : mMap(m),
+ mSourceArea(sourceArea),
+ mTargetArea(targetArea),
+ mDirection(direction)
+ {}
+
+ virtual void process(Entity *obj);
+
+ private:
+ /** Target map */
+ MapComposite *mMap;
+ /** Source area - used to calculate warp offset and warp direction */
+ Rectangle mSourceArea;
+ /** Target area */
+ Rectangle mTargetArea;
+ /** The direction to exit target area */
+ ExitDirection mDirection;
+};
+
class ScriptAction : public TriggerAction
{
public: