summaryrefslogtreecommitdiffstats
path: root/src/game-server
diff options
context:
space:
mode:
authorErik Schilling <ablu.erikschilling@googlemail.com>2013-02-20 22:46:55 +0100
committerErik Schilling <ablu.erikschilling@googlemail.com>2013-02-21 07:29:13 +0100
commit4559ca444daacfd02ebb05f1657148a2b4cf3d8b (patch)
tree8410fe19f397e70d43a8542c6ba7339d61d9bc0e /src/game-server
parentad1d58b795681cad74642c0f4818b66a3f869794 (diff)
downloadmanaserv-4559ca444daacfd02ebb05f1657148a2b4cf3d8b.tar.gz
manaserv-4559ca444daacfd02ebb05f1657148a2b4cf3d8b.tar.xz
manaserv-4559ca444daacfd02ebb05f1657148a2b4cf3d8b.zip
Introduced Script::Context
This should allow to finally call functions to lua without having to care about working around situations where a lua call causes a c++ call which needs to call to lua again. Tested against the source of tales repository data.
Diffstat (limited to 'src/game-server')
-rw-r--r--src/game-server/being.cpp6
-rw-r--r--src/game-server/character.cpp11
-rw-r--r--src/game-server/item.cpp7
-rw-r--r--src/game-server/mapcomposite.cpp19
-rw-r--r--src/game-server/monster.cpp9
-rw-r--r--src/game-server/npc.cpp6
-rw-r--r--src/game-server/quest.cpp3
-rw-r--r--src/game-server/statuseffect.cpp3
-rw-r--r--src/game-server/trigger.cpp3
9 files changed, 25 insertions, 42 deletions
diff --git a/src/game-server/being.cpp b/src/game-server/being.cpp
index 2c334b3..66545ff 100644
--- a/src/game-server/being.cpp
+++ b/src/game-server/being.cpp
@@ -603,11 +603,10 @@ void Being::recalculateBaseAttribute(unsigned attr)
return;
Script *script = ScriptManager::currentState();
- script->setMap(getMap());
script->prepare(mRecalculateBaseAttributeCallback);
script->push(this);
script->push(attr);
- script->execute();
+ script->execute(getMap());
}
void Being::updateDerivedAttributes(unsigned attr)
@@ -632,11 +631,10 @@ void Being::updateDerivedAttributes(unsigned attr)
return;
Script *script = ScriptManager::currentState();
- script->setMap(getMap());
script->prepare(mRecalculateDerivedAttributesCallback);
script->push(this);
script->push(attr);
- script->execute();
+ script->execute(getMap());
}
void Being::applyStatusEffect(int id, int timer)
diff --git a/src/game-server/character.cpp b/src/game-server/character.cpp
index cf5415d..b139f12 100644
--- a/src/game-server/character.cpp
+++ b/src/game-server/character.cpp
@@ -62,10 +62,9 @@ static bool executeCallback(Script::Ref function, Character *character)
return false;
Script *script = ScriptManager::currentState();
- script->setMap(character->getMap());
script->prepare(function);
script->push(character);
- script->execute();
+ script->execute(character->getMap());
return true;
}
@@ -161,7 +160,7 @@ void Character::update()
script->prepare(s.specialInfo->rechargedCallback);
script->push(this);
script->push(s.specialInfo->id);
- script->execute();
+ script->execute(getMap());
}
}
}
@@ -258,12 +257,11 @@ void Character::useSpecialOnBeing(int id, Being *b)
//tell script engine to cast the spell
Script *script = ScriptManager::currentState();
- script->setMap(getMap());
script->prepare(special.specialInfo->useCallback);
script->push(this);
script->push(b);
script->push(special.specialInfo->id);
- script->execute();
+ script->execute(getMap());
}
void Character::useSpecialOnPoint(int id, int x, int y)
@@ -278,13 +276,12 @@ void Character::useSpecialOnPoint(int id, int x, int y)
//tell script engine to cast the spell
Script *script = ScriptManager::currentState();
- script->setMap(getMap());
script->prepare(special.specialInfo->useCallback);
script->push(this);
script->push(x);
script->push(y);
script->push(special.specialInfo->id);
- script->execute();
+ script->execute(getMap());
}
bool Character::giveSpecial(int id, int currentMana)
diff --git a/src/game-server/item.cpp b/src/game-server/item.cpp
index d568fb2..c6c9d11 100644
--- a/src/game-server/item.cpp
+++ b/src/game-server/item.cpp
@@ -71,11 +71,11 @@ bool ItemEffectScript::apply(Being *itemUser)
if (function.isValid())
{
Script *script = ScriptManager::currentState();
- script->setMap(itemUser->getMap());
script->prepare(function);
script->push(itemUser);
script->push(mItemClass->getDatabaseID());
- script->execute(); // TODO return depending on script execution success.
+ script->execute(itemUser->getMap());
+ // TODO return depending on script execution success.
return true;
}
return false;
@@ -90,11 +90,10 @@ void ItemEffectScript::dispell(Being *itemUser)
if (function.isValid())
{
Script *script = ScriptManager::currentState();
- script->setMap(itemUser->getMap());
script->prepare(function);
script->push(itemUser);
script->push(mItemClass->getDatabaseID());
- script->execute();
+ script->execute(itemUser->getMap());
}
}
diff --git a/src/game-server/mapcomposite.cpp b/src/game-server/mapcomposite.cpp
index 4c7dc66..99d2734 100644
--- a/src/game-server/mapcomposite.cpp
+++ b/src/game-server/mapcomposite.cpp
@@ -512,9 +512,8 @@ bool MapComposite::activate()
else
{
Script *s = ScriptManager::currentState();
- s->setMap(this);
s->prepare(mInitializeCallback);
- s->execute();
+ s->execute(this);
}
return true;
@@ -628,10 +627,9 @@ void MapComposite::update()
if (mUpdateCallback.isValid())
{
Script *s = ScriptManager::currentState();
- s->setMap(this);
s->prepare(mUpdateCallback);
s->push(mID);
- s->execute();
+ s->execute(this);
}
// Move objects around and update zones.
@@ -703,11 +701,10 @@ static void callVariableCallback(Script::Ref &function, const std::string &key,
if (function.isValid())
{
Script *s = ScriptManager::currentState();
- s->setMap(map);
s->prepare(function);
s->push(key);
s->push(value);
- s->execute();
+ s->execute(map);
}
}
@@ -854,11 +851,10 @@ void MapComposite::initializeContent()
if (npcId && !scriptText.empty())
{
Script *script = ScriptManager::currentState();
- script->setMap(this);
script->loadNPC(object->getName(), npcId,
ManaServ::getGender(gender),
object->getX(), object->getY(),
- scriptText.c_str());
+ scriptText.c_str(), this);
}
else
{
@@ -871,16 +867,17 @@ void MapComposite::initializeContent()
std::string scriptText = object->getProperty("TEXT");
Script *script = ScriptManager::currentState();
- script->setMap(this);
+ Script::Context context;
+ context.map = this;
if (!scriptFilename.empty())
{
- script->loadFile(scriptFilename);
+ script->loadFile(scriptFilename, context);
}
else if (!scriptText.empty())
{
std::string name = "'" + object->getName() + "'' in " + mName;
- script->load(scriptText.c_str(), name.c_str());
+ script->load(scriptText.c_str(), name.c_str(), context);
}
else
{
diff --git a/src/game-server/monster.cpp b/src/game-server/monster.cpp
index 4724600..3899c79 100644
--- a/src/game-server/monster.cpp
+++ b/src/game-server/monster.cpp
@@ -142,10 +142,9 @@ void Monster::update()
if (mSpecy->getUpdateCallback().isValid())
{
Script *script = ScriptManager::currentState();
- script->setMap(getMap());
script->prepare(mSpecy->getUpdateCallback());
script->push(this);
- script->execute();
+ script->execute(getMap());
}
refreshTarget();
@@ -276,12 +275,11 @@ void Monster::processAttack(Attack &attack)
if (scriptCallback.isValid() && hit > -1)
{
Script *script = ScriptManager::currentState();
- script->setMap(getMap());
script->prepare(scriptCallback);
script->push(this);
script->push(mTarget);
script->push(hit);
- script->execute();
+ script->execute(getMap());
}
}
@@ -403,13 +401,12 @@ int Monster::damage(Actor *source, const Damage &damage)
if (mSpecy->getDamageCallback().isValid())
{
Script *script = ScriptManager::currentState();
- script->setMap(getMap());
script->prepare(mSpecy->getDamageCallback());
script->push(this);
script->push(source);
script->push(HPLoss);
// TODO: add exact damage parameters as well
- script->execute();
+ script->execute(getMap());
}
return HPLoss;
diff --git a/src/game-server/npc.cpp b/src/game-server/npc.cpp
index ce6ac32..2eb7303 100644
--- a/src/game-server/npc.cpp
+++ b/src/game-server/npc.cpp
@@ -54,11 +54,9 @@ void NPC::update()
return;
Script *script = ScriptManager::currentState();
- script->setMap(getMap());
-
script->prepare(mUpdateCallback);
script->push(this);
- script->execute();
+ script->execute(getMap());
}
void NPC::prompt(Character *ch, bool restart)
@@ -71,7 +69,7 @@ void NPC::prompt(Character *ch, bool restart)
if (restart)
{
Script::Thread *thread = script->newThread();
- thread->mMap = getMap();
+ thread->getContext().map = getMap();
script->prepare(mTalkCallback);
script->push(this);
script->push(ch);
diff --git a/src/game-server/quest.cpp b/src/game-server/quest.cpp
index c28a421..d6d7d92 100644
--- a/src/game-server/quest.cpp
+++ b/src/game-server/quest.cpp
@@ -82,12 +82,11 @@ void QuestRefCallback::triggerCallback(Character *ch,
return;
Script *s = ScriptManager::currentState();
- s->setMap(ch->getMap());
s->prepare(mRef);
s->push(ch);
s->push(mQuestName);
s->push(value);
- s->execute();
+ s->execute(ch->getMap());
}
static void partialRemove(Entity *t)
diff --git a/src/game-server/statuseffect.cpp b/src/game-server/statuseffect.cpp
index c101bc0..b5b988f 100644
--- a/src/game-server/statuseffect.cpp
+++ b/src/game-server/statuseffect.cpp
@@ -37,10 +37,9 @@ void StatusEffect::tick(Being *target, int count)
if (mTickCallback.isValid())
{
Script *s = ScriptManager::currentState();
- s->setMap(target->getMap());
s->prepare(mTickCallback);
s->push(target);
s->push(count);
- s->execute();
+ s->execute(target->getMap());
}
}
diff --git a/src/game-server/trigger.cpp b/src/game-server/trigger.cpp
index 2c00726..10e50ec 100644
--- a/src/game-server/trigger.cpp
+++ b/src/game-server/trigger.cpp
@@ -50,11 +50,10 @@ void ScriptAction::process(Actor *obj)
LOG_DEBUG("Script trigger area activated: "
<< "(" << obj << ", " << mArg << ")");
- mScript->setMap(obj->getMap());
mScript->prepare(mCallback);
mScript->push(obj);
mScript->push(mArg);
- mScript->execute();
+ mScript->execute(obj->getMap());
}
void TriggerArea::update()