summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorYohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer>2011-08-04 08:57:50 +0200
committerYohann Ferreira <yohann_dot_ferreira_at_orange_dot_efer>2011-08-04 08:57:50 +0200
commitf5936cd381adcc7f6add59aece084105191aea03 (patch)
treebc4e395912244915b938471efa36d0552c2b49c4
parent4a4acd479ee8de82df0935b3511257ade13258b6 (diff)
parentd11e7d49edb8374767d69859fe9ed542722013fe (diff)
downloadmanaserv-f5936cd381adcc7f6add59aece084105191aea03.tar.gz
manaserv-f5936cd381adcc7f6add59aece084105191aea03.tar.bz2
manaserv-f5936cd381adcc7f6add59aece084105191aea03.tar.xz
manaserv-f5936cd381adcc7f6add59aece084105191aea03.zip
Merge branch 'master' of git://gitorious.org/mana/manaserv
-rw-r--r--example/serverdata/scripts/crafting.lua10
-rw-r--r--example/serverdata/scripts/global_events.lua6
-rw-r--r--example/serverdata/scripts/maps/desert.lua9
-rw-r--r--src/scripting/lua.cpp435
4 files changed, 293 insertions, 167 deletions
diff --git a/example/serverdata/scripts/crafting.lua b/example/serverdata/scripts/crafting.lua
index ea306289..eae26a41 100644
--- a/example/serverdata/scripts/crafting.lua
+++ b/example/serverdata/scripts/crafting.lua
@@ -27,7 +27,7 @@ function on_craft(ch, recipe)
-- uncomment one (but not both!) of the following three lines to enable the
-- example crafting systems
- mana.chatmessage(ch, "There is no crafting in this game world.")
+ mana.chat_message(ch, "There is no crafting in this game world.")
--craft_strict(ch, recipe)
--craft_lax(ch, recipe)
end
@@ -42,10 +42,10 @@ function craft_strict(ch, recipe)
8, -2, --take away the iron
9, -1, --take away the wood
5, 1 ) -- give a sword
- mana.chatmessage(ch, "You've crafted a sword")
+ mana.chat_message(ch, "You've crafted a sword")
return
end
- mana.chatmessage(ch, "This wouldn't create anything useful")
+ mana.chat_message(ch, "This wouldn't create anything useful")
end
-- a primitive example crafting system which doesn't care about item order
@@ -60,10 +60,10 @@ function craft_lax(ch, recipe)
8, -2, --take away the iron
9, -1, --take away the wood
5, 1 ) -- give a sword
- mana.chatmessage(ch, "You've crafted a sword")
+ mana.chat_message(ch, "You've crafted a sword")
return
end
- mana.chatmessage(ch, "This wouldn't create anything useful")
+ mana.chat_message(ch, "This wouldn't create anything useful")
end
-- this turns multiple occurences of the same item into one by adding up
diff --git a/example/serverdata/scripts/global_events.lua b/example/serverdata/scripts/global_events.lua
index 5655dc8c..548351a8 100644
--- a/example/serverdata/scripts/global_events.lua
+++ b/example/serverdata/scripts/global_events.lua
@@ -50,14 +50,14 @@ end
-- to the character and/or initialize a tutorial quest.
function on_chr_birth(ch)
-- this message is shown on first login.
- mana.chatmessage(0, ch, "And so your adventure begins...")
+ mana.chat_message(0, ch, "And so your adventure begins...")
end
-- This function is called when a character logs into the game. This can,
-- for example, be utilized for a message-of-the-day or for various
-- handlings of offline processing mechanics.
function on_chr_login(ch)
- mana.chatmessage(0, ch, "Welcome to Manasource")
+ mana.chat_message(0, ch, "Welcome to Manasource")
end
@@ -72,7 +72,7 @@ function on_chr_logout(ch)
local msg = mana.being_get_name(ch).." left the game."
for b in pairs(around) do
if mana.being_type(b) == TYPE_CHARACTER then
- mana.chatmessage(0, b, msg)
+ mana.chat_message(0, b, msg)
end
end
end
diff --git a/example/serverdata/scripts/maps/desert.lua b/example/serverdata/scripts/maps/desert.lua
index 7449192d..23b95350 100644
--- a/example/serverdata/scripts/maps/desert.lua
+++ b/example/serverdata/scripts/maps/desert.lua
@@ -89,6 +89,15 @@ function Tamer(npc, ch, list)
mana.get_distance(npc, ch)))
mana.being_say(npc, "I will now spawn a monster for your training session.")
+ -- Remove monsters in the area
+ for i, b in ipairs(mana.get_beings_in_rectangle(
+ mana.posX(npc) - 3 * TILESIZE, mana.posY(npc) - 3 * TILESIZE,
+ 6 * TILESIZE, 6 * TILESIZE)) do
+ if mana.being_type(b) == TYPE_MONSTER then
+ mana.monster_remove(b)
+ end
+ end
+
local m1 = mana.monster_create(1, mana.posX(ch), mana.posY(ch))
schedule_in(0.5, function() mana.being_say(m1, "Roaaarrrr!!!") end)
end
diff --git a/src/scripting/lua.cpp b/src/scripting/lua.cpp
index b422fc3e..967620d3 100644
--- a/src/scripting/lua.cpp
+++ b/src/scripting/lua.cpp
@@ -63,8 +63,8 @@ extern "C" {
*/
/**
+ * mana.npc_message(NPC*, Character*, string): void
* Callback for sending a NPC_MESSAGE.
- * mana.npc_message(npc, character, string)
*/
static int npc_message(lua_State *s)
{
@@ -85,8 +85,8 @@ static int npc_message(lua_State *s)
}
/**
+ * mana.npc_choice(NPC*, Character*, string...): void
* Callback for sending a NPC_CHOICE.
- * mana.npc_choice(npc, character, string...)
*/
static int npc_choice(lua_State *s)
{
@@ -115,7 +115,8 @@ static int npc_choice(lua_State *s)
}
else
{
- raiseScriptError(s, "npc_choice called with incorrect parameters.");
+ raiseScriptError(s, "npc_choice called "
+ "with incorrect parameters.");
return 0;
}
lua_pop(s, 1);
@@ -132,8 +133,8 @@ static int npc_choice(lua_State *s)
}
/**
+ * mana.npc_integer(NPC*, Character*, int min, int max, int defaut = min): void
* Callback for sending a NPC_INTEGER.
- * mana.npc_integer(npc, character, min, max, defaut)
*/
static int npc_ask_integer(lua_State *s)
{
@@ -141,7 +142,8 @@ static int npc_ask_integer(lua_State *s)
Character *q = getCharacter(s, 2);
if (!p || !q)
{
- raiseScriptError(s, "npc_integer called with incorrect parameters.");
+ raiseScriptError(s, "npc_ask_integer called "
+ "with incorrect parameters.");
return 0;
}
MessageOut msg(GPMSG_NPC_NUMBER);
@@ -162,8 +164,8 @@ static int npc_ask_integer(lua_State *s)
}
/**
+ * mana.npc_ask_string(NPC*, Character*): void
* Callback for sending a NPC_STRING.
- * mana.npc_ask_string(npc, character)
*/
static int npc_ask_string(lua_State *s)
{
@@ -171,7 +173,7 @@ static int npc_ask_string(lua_State *s)
Character *q = getCharacter(s, 2);
if (!p || !q)
{
- raiseScriptError(s, "npc_string called with incorrect parameters.");
+ raiseScriptError(s, "npc_ask_string called with incorrect parameters.");
return 0;
}
MessageOut msg(GPMSG_NPC_STRING);
@@ -182,8 +184,8 @@ static int npc_ask_string(lua_State *s)
}
/**
+ * mana.npc_create(string name, int id, int x, int y): NPC*
* Callback for creating a NPC on the current map with the current script.
- * mana.npc_create(string name, int id, int x, int y): npc
*/
static int npc_create(lua_State *s)
{
@@ -212,6 +214,10 @@ static int npc_create(lua_State *s)
return 1;
}
+/**
+ * mana.npc_end(NPC*, Character*): void
+ * Callback for ending a NPC conversation with the given character.
+ */
static int npc_end(lua_State *s)
{
NPC *p = getNPC(s, 1);
@@ -229,8 +235,8 @@ static int npc_end(lua_State *s)
}
/**
+ * mana.npc_post(NPC*, Character*): void
* Callback for sending a NPC_POST.
- * mana.npc_post(npc, character)
*/
static int npc_post(lua_State *s)
{
@@ -239,7 +245,7 @@ static int npc_post(lua_State *s)
if (!p || !q)
{
- raiseScriptError(s, "npc_Choice called with incorrect parameters.");
+ raiseScriptError(s, "npc_post called with incorrect parameters.");
return 0;
}
@@ -251,8 +257,8 @@ static int npc_post(lua_State *s)
}
/**
+ * mana.npc_enable(NPC*): void
* Enable a NPC if it has previously disabled
- * mana.npc_enable(npc)
*/
static int npc_enable(lua_State *s)
{
@@ -267,8 +273,8 @@ static int npc_enable(lua_State *s)
}
/**
- * Disable a NPC
- * mana.npc_disable(npc)
+ * mana.npc_disable(NPC*): void
+ * Disable a NPC.
*/
static int npc_disable(lua_State *s)
{
@@ -283,8 +289,8 @@ static int npc_disable(lua_State *s)
}
/**
+ * mana.chr_warp(Character*, nil/int map, int x, int y): void
* Callback for warping a player to another place.
- * mana.chr_warp(character, nil/int map, int x, int y)
*/
static int chr_warp(lua_State *s)
{
@@ -337,6 +343,7 @@ static int chr_warp(lua_State *s)
}
/**
+ * mana.chr_inv_change(Character*, (int id, int nb)...): bool success
* Callback for inserting/removing items in inventory.
* The function can be called several times in a row, but it is better to
* perform all the changes at once, so as to reduce bandwidth. Removals
@@ -348,7 +355,6 @@ static int chr_warp(lua_State *s)
* however currency is now handled through attributes. This breaks backwards
* compatibility with old scripts, and so logs a warning.
* Note: If an insertion fails, extra items are dropped on the floor.
- * mana.chr_inv_change(character, (int id, int nb)...): bool success
*/
static int chr_inv_change(lua_State *s)
{
@@ -364,7 +370,8 @@ static int chr_inv_change(lua_State *s)
{
if (!lua_isnumber(s, i * 2 + 2) || !lua_isnumber(s, i * 2 + 3))
{
- raiseScriptError(s, "chr_inv_change called with incorrect parameters.");
+ raiseScriptError(s, "chr_inv_change called "
+ "with incorrect parameters.");
return 0;
}
@@ -372,7 +379,7 @@ static int chr_inv_change(lua_State *s)
int nb = lua_tointeger(s, i * 2 + 3);
if (id == 0)
{
- LOG_WARN("mana.chr_inv_change() called with id 0! "
+ LOG_WARN("chr_inv_change called with id 0! "
"Currency is now handled through attributes!");
}
else if (nb < 0)
@@ -391,7 +398,8 @@ static int chr_inv_change(lua_State *s)
ItemClass *ic = itemManager->getItem(id);
if (!ic)
{
- raiseScriptError(s, "chr_inv_change called with an unknown item.");
+ raiseScriptError(s, "chr_inv_change called "
+ "with an unknown item.");
continue;
}
nb = inv.insert(id, nb);
@@ -409,8 +417,8 @@ static int chr_inv_change(lua_State *s)
}
/**
+ * mana.chr_inv_count(Character*, int item_id...): int count...
* Callback for counting items in inventory.
- * mana.chr_inv_count(character, int id...): int count...
*/
static int chr_inv_count(lua_State *s)
{
@@ -430,7 +438,7 @@ static int chr_inv_count(lua_State *s)
id = luaL_checkint(s, i);
if (id == 0)
{
- LOG_WARN("mana.chr_inv_count() called with id 0! "
+ LOG_WARN("chr_inv_count called with id 0! "
"Currency is now handled through attributes!");
}
else
@@ -443,8 +451,8 @@ static int chr_inv_count(lua_State *s)
}
/**
+ * mana.npc_trade(NPC*, Character*, bool sell, table items): int
* Callback for trading between a player and an NPC.
- * mana.npc_trade(npc, character, bool sell, table items)
* Let the player buy or sell only a subset of predeterminded items.
* @param table items: a subset of buyable/sellable items.
* When selling, if the 4 parameter is omitted or invalid,
@@ -490,7 +498,8 @@ static int npc_trade(lua_State *s)
}
else
{
- raiseWarning(s, "npc_trade[Buy] called with invalid or empty items table parameter.");
+ raiseWarning(s, "npc_trade[Buy] called with invalid "
+ "or empty items table parameter.");
t->cancel();
lua_pushinteger(s, 2);
return 1;
@@ -504,7 +513,8 @@ static int npc_trade(lua_State *s)
{
if (!lua_istable(s, -1))
{
- raiseWarning(s, "npc_trade called with invalid or empty items table parameter.");
+ raiseWarning(s, "npc_trade called with invalid "
+ "or empty items table parameter.");
t->cancel();
lua_pushinteger(s, 2);
return 1;
@@ -516,7 +526,8 @@ static int npc_trade(lua_State *s)
lua_rawgeti(s, -1, i + 1);
if (!lua_isnumber(s, -1))
{
- raiseWarning(s, "npc_trade called with incorrect parameters in item table.");
+ raiseWarning(s, "npc_trade called with incorrect parameters "
+ "in item table.");
t->cancel();
lua_pushinteger(s, 2);
return 1;
@@ -548,10 +559,9 @@ static int npc_trade(lua_State *s)
}
/**
- * Applies a status effect with id to the being given for a amount of time
- * mana.being_apply_status(Being *being, int id, int time)
+ * mana.being_apply_status(Being*, int id, int time): void
+ * Applies a status effect with id to the being given for a amount of time.
*/
-
static int being_apply_status(lua_State *s)
{
const int id = luaL_checkint(s, 2);
@@ -559,7 +569,8 @@ static int being_apply_status(lua_State *s)
if (!lua_isuserdata(s, 1))
{
- raiseScriptError(s, "being_apply_status called with incorrect parameters.");
+ raiseScriptError(s, "being_apply_status called "
+ "with incorrect parameters.");
return 0;
}
Being *being = getBeing(s, 1);
@@ -568,8 +579,8 @@ static int being_apply_status(lua_State *s)
}
/**
- * Removes the given status effect
- * mana.being_remove_status(Being *being, int id)
+ * mana.being_remove_status(Being*, int id): void
+ * Removes the given status effect.
*/
static int being_remove_status(lua_State *s)
{
@@ -577,7 +588,8 @@ static int being_remove_status(lua_State *s)
if (!lua_isuserdata(s, 1))
{
- raiseScriptError(s, "being_remove_status called with incorrect parameters.");
+ raiseScriptError(s, "being_remove_status called "
+ "with incorrect parameters.");
return 0;
}
Being *being = getBeing(s, 1);
@@ -586,8 +598,8 @@ static int being_remove_status(lua_State *s)
}
/**
- * Returns true if a being has the given status effect
- * mana.being_has_status(Being *being, int id)
+ * mana.being_has_status(Being*, int id): bool
+ * Returns whether a being has the given status effect.
*/
static int being_has_status(lua_State *s)
{
@@ -595,7 +607,8 @@ static int being_has_status(lua_State *s)
if (!lua_isuserdata(s, 1))
{
- raiseScriptError(s, "being_has_status called with incorrect parameters.");
+ raiseScriptError(s, "being_has_status called "
+ "with incorrect parameters.");
return 0;
}
Being *being = getBeing(s, 1);
@@ -604,8 +617,8 @@ static int being_has_status(lua_State *s)
}
/**
- * Returns the time left on the given status effect
- * mana.being_get_status_time(Being *being, int id)
+ * mana.being_get_status_time(Being*, int id): int
+ * Returns the time left on the given status effect.
*/
static int being_get_status_time(lua_State *s)
{
@@ -613,7 +626,8 @@ static int being_get_status_time(lua_State *s)
if (!lua_isuserdata(s, 1))
{
- raiseScriptError(s, "being_time_status called with incorrect parameters.");
+ raiseScriptError(s, "being_get_status_time called "
+ "with incorrect parameters.");
return 0;
}
Being *being = getBeing(s, 1);
@@ -622,8 +636,8 @@ static int being_get_status_time(lua_State *s)
}
/**
- * Sets the time left on the given status effect
- * mana.being_set_status_time(Being *being, int id, int time)
+ * mana.being_set_status_time(Being*, int id, int time): void
+ * Sets the time left on the given status effect.
*/
static int being_set_status_time(lua_State *s)
{
@@ -632,7 +646,8 @@ static int being_set_status_time(lua_State *s)
if (!lua_isuserdata(s, 1))
{
- raiseScriptError(s, "being_time_status called with incorrect parameters.");
+ raiseScriptError(s, "being_set_status_time called "
+ "with incorrect parameters.");
return 0;
}
Being *being = getBeing(s, 1);
@@ -641,8 +656,8 @@ static int being_set_status_time(lua_State *s)
}
/**
- * Returns the Thing type of the given Being
- * mana.being_type(Being *being)
+ * mana.being_type(Being*): ThingType
+ * Returns the Thing type of the given being.
*/
static int being_type(lua_State *s)
{
@@ -661,9 +676,9 @@ static int being_type(lua_State *s)
/**
- * Function for making a being walk to a position
- * being_walk(Being *being, int x, int y[, float speed])
- * The speed is in tile per second
+ * being_walk(Being *, int x, int y[, float speed]): void
+ * Function for making a being walk to a position.
+ * The speed is in tile per second.
*/
static int being_walk(lua_State *s)
{
@@ -684,8 +699,8 @@ static int being_walk(lua_State *s)
}
/**
- * Makes the being say something
- * mana.being_say(source, message)
+ * mana.being_say(Being* source, string message): void
+ * Makes the being say something.
*/
static int being_say(lua_State *s)
{
@@ -714,8 +729,9 @@ static int being_say(lua_State *s)
/**
- * Applies combat damage to a being
- * mana.being_damage(victim, value, delta, cth, type, element)
+ * mana.being_damage(Being* victim, int value, int delta, int cth, int type,
+ * int element): void
+ * Applies combat damage to a being.
*/
static int being_damage(lua_State *s)
{
@@ -724,20 +740,20 @@ static int being_damage(lua_State *s)
if (!being->canFight())
return 0;
- Damage dmg((unsigned short) lua_tointeger(s, 2), /* base */
- (unsigned short) lua_tointeger(s, 3), /* delta */
- (unsigned short) lua_tointeger(s, 4), /* cth */
- (unsigned char) lua_tointeger(s, 6), /* element */
- DAMAGE_PHYSICAL); /* type */
+ Damage dmg((unsigned short) lua_tointeger(s, 2), /* base */
+ (unsigned short) lua_tointeger(s, 3), /* delta */
+ (unsigned short) lua_tointeger(s, 4), /* cth */
+ (unsigned char) lua_tointeger(s, 6), /* element */
+ DAMAGE_PHYSICAL); /* type */
being->damage(NULL, dmg);
return 0;
}
/**
- * Restores hit points of a being
- * mana.being_heal(being[, value])
- * Without a value it heals fully.
+ * mana.being_heal(Being* [, int value]): void
+ * Restores hit points of a being.
+ * Without a value the being is fully healed.
*/
static int being_heal(lua_State *s)
{
@@ -767,8 +783,8 @@ static int being_heal(lua_State *s)
}
/**
- * Gets the base attribute of a being
- * mana.being_get_base_attribute(being, attribute)
+ * mana.being_get_base_attribute(Being*, int attribute): int
+ * Gets the base attribute of a being.
*/
static int being_get_base_attribute(lua_State *s)
{
@@ -790,8 +806,8 @@ static int being_get_base_attribute(lua_State *s)
}
/**
- * Gets the modified attribute of a being
- * mana.being_get_modified_attribute(being, attribute)
+ * mana.being_get_modified_attribute(Being*, int attribute): int
+ * Gets the modified attribute of a being.
*/
static int being_get_modified_attribute(lua_State *s)
{
@@ -813,8 +829,8 @@ static int being_get_modified_attribute(lua_State *s)
}
/**
- * Sets the base attribute of a being
- * mana.being_set_base_attribute(being, attribute, value)
+ * mana.being_set_base_attribute(Being*, int attribute, double value): void
+ * Sets the base attribute of a being.
*/
static int being_set_base_attribute(lua_State *s)
{
@@ -831,9 +847,9 @@ static int being_set_base_attribute(lua_State *s)
}
/**
+ * mana.being_apply_attribute_modifier(Being*, int attribute, double value,
+ * int layer, int [duration, int [effect-id]]): void
* Applies an attribute modifier to a being.
- * mana.being_apply_attribute_modifier(
- * attribute, value, layer, [duration, [effect-id]])
*/
static int being_apply_attribute_modifier(lua_State *s)
{
@@ -858,6 +874,11 @@ static int being_apply_attribute_modifier(lua_State *s)
return 0;
}
+/**
+ * mana.being_remove_attribute_modifier(Being*, int attribute, double value,
+ * int layer, int [effect-id]]): void
+ * Removes an attribute modifier to a being.
+ */
static int being_remove_attribute_modifier(lua_State *s)
{
Being *being = getBeing(s, 1);
@@ -877,8 +898,8 @@ static int being_remove_attribute_modifier(lua_State *s)
}
/**
- * Gets the being's name
- * mana.being_get_name(being)
+ * mana.being_get_name(Being*): string
+ * Gets the being's name.
*/
static int being_get_name(lua_State *s)
{
@@ -893,8 +914,8 @@ static int being_get_name(lua_State *s)
}
/**
- * Gets the being's current action
- * mana.being_get_action(being)
+ * mana.being_get_action(Being*): BeingAction
+ * Gets the being's current action.
*/
static int being_get_action(lua_State *s)
{
@@ -909,8 +930,8 @@ static int being_get_action(lua_State *s)
}
/**
- * Sets the being's current action
- * mana.being_set_action(being, action)
+ * mana.being_set_action(Being*, BeingAction): void
+ * Sets the being's current action.
*/
static int being_set_action(lua_State *s)
{
@@ -927,8 +948,8 @@ static int being_set_action(lua_State *s)
}
/**
- * Gets the being's current direction
- * mana.being_get_direction(being)
+ * mana.being_get_direction(Being*): BeingDirection
+ * Gets the being's current direction.
*/
static int being_get_direction(lua_State *s)
{
@@ -943,8 +964,8 @@ static int being_get_direction(lua_State *s)
}
/**
- * Sets the being's current direction
- * mana.being_set_direction(being, direction)
+ * mana.being_set_direction(Being*, BeingDirection): void
+ * Sets the being's current direction.
*/
static int being_set_direction(lua_State *s)
{
@@ -961,7 +982,8 @@ static int being_set_direction(lua_State *s)
}
/**
- * Function for getting the x-coordinate of the position of a being
+ * mana.posX(Being*): int xcoord
+ * Function for getting the x-coordinate of the position of a being.
*/
static int posX(lua_State *s)
{
@@ -972,7 +994,8 @@ static int posX(lua_State *s)
}
/**
- * Function for getting the y-coordinate of the position of a being
+ * mana.posY(Being*): int ycoord
+ * Function for getting the y-coordinate of the position of a being.
*/
static int posY(lua_State *s)
{
@@ -983,8 +1006,8 @@ static int posY(lua_State *s)
}
/**
+ * mana.monster_create(int type, int x, int y): Monster*
* Callback for creating a monster on the current map.
- * mana.monster_create(int type, int x, int y)
*/
static int monster_create(lua_State *s)
{
@@ -1005,8 +1028,8 @@ static int monster_create(lua_State *s)
MonsterClass *spec = monsterManager->getMonster(monsterId);
if (!spec)
{
- raiseScriptError(s, "monster_create called with invalid monster ID: %d", monsterId);
- //LOG_WARN("LuaMonster_Create invalid monster ID: " << monsterId);
+ raiseScriptError(s, "monster_create called "
+ "with invalid monster Id: %d", monsterId);
return 0;
}
@@ -1020,22 +1043,48 @@ static int monster_create(lua_State *s)
}
/**
- * mana.monster_load_script(mob, scriptfilename)
- * loads a LUA script given for mob
+ * mana.monster_remove(Monster*): bool success
+ * Remove a monster object without kill event.
+ * return whether the monster was enqueued for removal.
+ */
+static int monster_remove(lua_State *s)
+{
+ if (!lua_islightuserdata(s, 1))
+ {
+ lua_pushboolean(s, false);
+ return 1;
+ }
+
+ bool monsterEnqueued = false;
+ Monster *m = dynamic_cast<Monster *>((Thing *)lua_touserdata(s, 1));
+ if (m)
+ {
+ GameState::enqueueRemove(m);
+ monsterEnqueued = true;
+ }
+ lua_pushboolean(s, monsterEnqueued);
+ return 1;
+}
+
+/**
+ * mana.monster_load_script(Monster*, string script_filename): void
+ * loads a LUA script for the given monster.
*/
static int monster_load_script(lua_State *s)
{
Monster *m = static_cast< Monster* >(getBeing(s, 1));
if (!m)
{
- raiseScriptError(s, "monster_load_script called for a nonexistance monster.");
+ raiseScriptError(s, "monster_load_script called "
+ "for a nonexistent monster.");
return 0;
}
const char *scriptName = luaL_checkstring(s, 2);
if (scriptName[0] == 0)
{
- raiseScriptError(s, "monster_load_script called with empty script file name.");
+ raiseScriptError(s, "monster_load_script called "
+ "with empty script file name.");
return 0;
}
@@ -1043,18 +1092,18 @@ static int monster_load_script(lua_State *s)
return 0;
}
-
/**
+ * mana.chr_get_chest(Character*, string): nil or string
* Callback for getting a quest variable. Starts a recovery and returns
* immediatly, if the variable is not known yet.
- * mana.chr_get_chest(character, string): nil or string
*/
static int chr_get_quest(lua_State *s)
{
Character *q = getCharacter(s, 1);
if (!q)
{
- raiseScriptError(s, "chr_get_quest called for nonexistent character.");
+ raiseScriptError(s, "chr_get_quest "
+ "called for nonexistent character.");
}
const char *m = luaL_checkstring(s, 2);
@@ -1078,10 +1127,9 @@ static int chr_get_quest(lua_State *s)
return 0;
}
-
/**
- * gets the value of a persistent map variable.
* mana.getvar_map(string): string
+ * Gets the value of a persistent map variable.
*/
static int getvar_map(lua_State *s)
{
@@ -1102,15 +1150,15 @@ static int getvar_map(lua_State *s)
}
/**
- * sets the value of a persistent map variable.
- * mana.setvar_map(string, string)
+ * mana.setvar_map(string, string): void
+ * Sets the value of a persistent map variable.
*/
static int setvar_map(lua_State *s)
{
const char *m = luaL_checkstring(s, 1);
if (m[0] == 0)
{
- raiseScriptError(s, "getvar_map called for unnamed variable.");
+ raiseScriptError(s, "setvar_map called for unnamed variable.");
return 0;
}
@@ -1125,8 +1173,8 @@ static int setvar_map(lua_State *s)
}
/**
- * gets the value of a persistent global variable.
* mana.getvar_world(string): string
+ * Gets the value of a persistent global variable.
*/
static int getvar_world(lua_State *s)
{
@@ -1144,8 +1192,8 @@ static int getvar_world(lua_State *s)
}
/**
- * sets the value of a persistent global variable.
- * mana.setvar_world(string, string)
+ * mana.setvar_world(string, string): void
+ * Sets the value of a persistent global variable.
*/
static int setvar_world(lua_State *s)
{
@@ -1163,10 +1211,9 @@ static int setvar_world(lua_State *s)
return 0;
}
-
/**
+ * mana.chr_set_chest(Character*, string, string): void
* Callback for setting a quest variable.
- * mana.chr_set_chest(character, string, string)
*/
static int chr_set_quest(lua_State *s)
{
@@ -1188,9 +1235,10 @@ static int chr_set_quest(lua_State *s)
}
/**
+ * mana.trigger_create(int x, int y, int width, int height,
+ * string function, int id)
* Creates a trigger area. Whenever an actor enters this area, a Lua function
* is called.
- * mana.trigger_create (x, y, width, height, function, id)
*/
static int trigger_create(lua_State *s)
{
@@ -1198,6 +1246,7 @@ static int trigger_create(lua_State *s)
const int y = luaL_checkint(s, 2);
const int width = luaL_checkint(s, 3);
const int height = luaL_checkint(s, 4);
+ //TODO: Turn the function string to a lua function pointer
const char *function = luaL_checkstring(s, 5);
const int id = luaL_checkint(s, 6);
@@ -1234,11 +1283,11 @@ static int trigger_create(lua_State *s)
}
/**
- * Creates a chat message in the users chatlog(s)
- * global message: mana.chatmessage (message)
- * private massage: mana.chatmessage (recipent, message)
+ * private message: mana.chat_message(Being* recipent, string message): void
+ * @todo global message: mana.chat_message(string message): void
+ * Creates a chat message in the users chatlog(s).
*/
-static int chatmessage(lua_State *s)
+static int chat_message(lua_State *s)
{
if (lua_gettop(s) == 2 && lua_isuserdata(s, 1) && lua_isstring(s, 2) )
{
@@ -1256,7 +1305,7 @@ static int chatmessage(lua_State *s)
}
else
{
- raiseScriptError(s, "being_say called with incorrect parameters.");
+ raiseScriptError(s, "chat_message called with incorrect parameters.");
return 0;
}
@@ -1264,9 +1313,9 @@ static int chatmessage(lua_State *s)
}
/**
- * Gets a LUA table with the being IDs of all beings
+ * mana.get_beings_in_circle(int x, int y, int radius): table of Being*
+ * Gets a LUA table with the Being* pointers of all beings
* inside of a circular area of the current map.
- * mana.get_beings_in_circle (x, y, radius)
*/
static int get_beings_in_circle(lua_State *s)
{
@@ -1304,9 +1353,10 @@ static int get_beings_in_circle(lua_State *s)
}
/**
- * Gets a LUA table with the being IDs of all beings
- * inside of a recangular area of the current map.
- * mana.get_beings_in_rectangle (x, y, width, height)
+ * mana.get_beings_in_rectangle(int x, int y, int width,
+ * int height): table of Being*
+ * Gets a LUA table with the Being* pointers of all beings
+ * inside of a rectangular area of the current map.
*/
static int get_beings_in_rectangle(lua_State *s)
{
@@ -1342,7 +1392,8 @@ static int get_beings_in_rectangle(lua_State *s)
}
/**
- * Gets the post for the character
+ * mana.chr_get_post(Character*): void
+ * Gets the post for the character.
*/
static int chr_get_post(lua_State *s)
{
@@ -1364,10 +1415,10 @@ static int chr_get_post(lua_State *s)
}
/**
+ * mana.being_register(Being*): void
* Makes the server call the lua functions deathEvent
* and removeEvent when the being dies or is removed
* from the map.
- * mana.being_register (being)
*/
static int being_register(lua_State *s)
{
@@ -1391,11 +1442,10 @@ static int being_register(lua_State *s)
return 0;
}
-
/**
- * Triggers a special effect from the clients effects.xml
- * mana.effect_create (id, x, y)
- * mana.effect_create (id, being)
+ * mana.effect_create (int id, int x, int y): void
+ * mana.effect_create (int id, Being*): void
+ * Triggers a special effect from the clients effects.xml.
*/
static int effect_create(lua_State *s)
{
@@ -1435,17 +1485,18 @@ static int effect_create(lua_State *s)
return 0;
}
-
/**
- *
- * mana.chr_shake_screen(
+ * mana.chr_shake_screen(Character*, int x, int y[, float strength,
+ * int radius]): void
+ * Shake the screen for a given character.
*/
static int chr_shake_screen(lua_State *s)
{
Character *c = getCharacter(s, 1);
if (!c)
{
- raiseScriptError(s, "lua chr_shake_screen called for nonexistent character.");
+ raiseScriptError(s, "chr_shake_screen called "
+ "for nonexistent character.");
return 0;
}
@@ -1468,15 +1519,15 @@ static int chr_shake_screen(lua_State *s)
/**
+ * mana.chr_get_exp(Character*, int skill): int
* Gets the exp total in a skill of a specific character
- * mana.chr_get_exp (being, skill)
*/
static int chr_get_exp(lua_State *s)
{
Character *c = getCharacter(s, 1);
if (!c)
{
- raiseScriptError(s, "luaChr_GetExp called for nonexistent character.");
+ raiseScriptError(s, "chr_get_exp called for nonexistent character.");
return 0;
}
@@ -1487,19 +1538,19 @@ static int chr_get_exp(lua_State *s)
return 1;
}
-
/**
+ * mana.chr_give_exp(Character*, int skill,
+ * int amount[, int optimal_level]): void
* Gives the character a certain amount of experience points
* in a skill. Can also be used to reduce the exp amount when
* desired.
- * mana.chr_give_exp (being, skill, amount)
*/
static int chr_give_exp(lua_State *s)
{
Character *c = getCharacter(s, 1);
if (!c)
{
- raiseScriptError(s, "luaChr_GiveExp called for nonexistent character.");
+ raiseScriptError(s, "chr_give_exp called for nonexistent character.");
return 0;
}
@@ -1513,22 +1564,24 @@ static int chr_give_exp(lua_State *s)
}
/**
- * Sets the given character's hair style to the given style id
- * mana.chr_set_hair_style (character, styleid)
+ * mana.chr_set_hair_style(Character*, int style_id): void
+ * Sets the given character's hair style to the given style id.
*/
static int chr_set_hair_style(lua_State *s)
{
Character *c = getCharacter(s, 1);
if (!c)
{
- raiseScriptError(s, "chr_set_hair_style called for nonexistent character.");
+ raiseScriptError(s, "chr_set_hair_style called "
+ "for nonexistent character.");
return 0;
}
const int style = luaL_checkint(s, 2);
if (style < 0)
{
- raiseScriptError(s, "chr_set_hair_style called for nonexistent style id %d.", style);
+ raiseScriptError(s, "chr_set_hair_style called "
+ "for nonexistent style id %d.", style);
return 0;
}
@@ -1539,15 +1592,16 @@ static int chr_set_hair_style(lua_State *s)
}
/**
- * Gets the hair style of the given character
- * mana.chr_get_hair_style (character)
+ * mana.chr_get_hair_style(Character*): int hair_style
+ * Gets the hair style of the given character.
*/
static int chr_get_hair_style(lua_State *s)
{
Character *c = getCharacter(s, 1);
if (!c)
{
- raiseScriptError(s, "chr_get_hair_style called for nonexistent character.");
+ raiseScriptError(s, "chr_get_hair_style called "
+ "for nonexistent character.");
return 0;
}
@@ -1556,22 +1610,24 @@ static int chr_get_hair_style(lua_State *s)
}
/**
- * Set the hair color of the given character to the given color id
- * mana.chr_set_hair_color (character, colorid)
+ * mana.chr_set_hair_color(Character*, int color_id): void
+ * Set the hair color of the given character to the given color id.
*/
static int chr_set_hair_color(lua_State *s)
{
Character *c = getCharacter(s, 1);
if (!c)
{
- raiseScriptError(s, "chr_set_hair_color called for nonexistent character.");
+ raiseScriptError(s, "chr_set_hair_color called "
+ "for nonexistent character.");
return 0;
}
const int color = luaL_checkint(s, 2);
if (color < 0)
{
- raiseScriptError(s, "chr_set_hair_color called for nonexistent style id %d.", color);
+ raiseScriptError(s, "chr_set_hair_color called "
+ "for nonexistent style id %d.", color);
return 0;
}
@@ -1582,15 +1638,16 @@ static int chr_set_hair_color(lua_State *s)
}
/**
- * Get the hair color of the given character
- * mana.chr_get_hair_color (character)
+ * mana.chr_get_hair_color(Character*): int hair_color
+ * Get the hair color of the given character.
*/
static int chr_get_hair_color(lua_State *s)
{
Character *c = getCharacter(s, 1);
if (!c)
{
- raiseScriptError(s, "chr_get_hair_color called for nonexistent character.");
+ raiseScriptError(s, "chr_get_hair_color called "
+ "for nonexistent character.");
return 0;
}
@@ -1599,15 +1656,16 @@ static int chr_get_hair_color(lua_State *s)
}
/**
- * Get the number of monsters the player killed of a type
- * mana.chr_get_kill_count (character, monsterType)
+ * mana.chr_get_kill_count(Character*, int monster_type): int
+ * Get the number of monsters the player killed of a type.
*/
static int chr_get_kill_count(lua_State *s)
{
Character *c = getCharacter(s, 1);
if (!c)
{
- raiseScriptError(s, "chr_get_kill_count called for nonexistent character.");
+ raiseScriptError(s, "chr_get_kill_count called "
+ "for nonexistent character.");
return 0;
}
@@ -1618,8 +1676,8 @@ static int chr_get_kill_count(lua_State *s)
}
/**
- * Get the gender of the character
- * mana.chr_get_gender (character)
+ * mana.chr_get_gender(Character*): int
+ * Get the gender of the character.
*/
static int chr_get_gender(lua_State *s)
{
@@ -1635,8 +1693,8 @@ static int chr_get_gender(lua_State *s)
}
/**
- * Enables a special for a character
- * mana.chr_give_special (character, special)
+ * mana.chr_give_special(Character*, int special): void
+ * Enables a special for a character.
*/
static int chr_give_special(lua_State *s)
{
@@ -1644,7 +1702,8 @@ static int chr_give_special(lua_State *s)
Character *c = getCharacter(s, 1);
if (!c)
{
- raiseScriptError(s, "chr_give_special called for nonexistent character.");
+ raiseScriptError(s, "chr_give_special called "
+ "for nonexistent character.");
return 0;
}
const int special = luaL_checkint(s, 2);
@@ -1654,8 +1713,8 @@ static int chr_give_special(lua_State *s)
}
/**
- * Checks if a character has a special and returns true or false
- * mana.chr_has_special (character, special)
+ * mana.chr_has_special(Character*, int special): bool
+ * Checks whether a character has a given special.
*/
static int chr_has_special(lua_State *s)
{
@@ -1672,8 +1731,8 @@ static int chr_has_special(lua_State *s)
}
/**
- * Removes a special from a character
- * mana.chr_take_special (character, special)
+ * mana.chr_take_special(Character*, int special): bool success
+ * Removes a special from a character.
*/
static int chr_take_special(lua_State *s)
{
@@ -1690,11 +1749,9 @@ static int chr_take_special(lua_State *s)
return 1;
}
-
-
/**
+ * mana.chr_get_rights(Character*): int
* Returns the rights level of a character.
- * mana.chr_get_rights (being)
*/
static int chr_get_rights(lua_State *s)
{
@@ -1709,8 +1766,8 @@ static int chr_get_rights(lua_State *s)
}
/**
+ * mana.exp_for_level(int level): int
* Returns the exp total necessary to reach a specific skill level.
- * mana.exp_for_level (level)
*/
static int exp_for_level(lua_State *s)
{
@@ -1777,7 +1834,8 @@ static int test_tableget(lua_State *s)
}
/**
- * Returns the ID of the current map
+ * mana.get_map_id(): int
+ * Returns the id of the current map.
*/
static int get_map_id(lua_State *s)
{
@@ -1790,8 +1848,61 @@ static int get_map_id(lua_State *s)
}
/**
- * Creates an item stack on the floor
- * mana.drop_item(x, y, id[, number])
+ * mana.get_map_property(string property): string
+ * Returns the value of a map property.
+ */
+static int get_map_property(lua_State *s)
+{
+ const char *property = luaL_checkstring(s, 1);
+ lua_pushlightuserdata(s, (void *)&registryKey);
+ lua_gettable(s, LUA_REGISTRYINDEX);
+ Script *t = static_cast<Script *>(lua_touserdata(s, -1));
+ MapComposite *m = t->getMap();
+ if (!m)
+ {
+ raiseScriptError(s, "get_map_property called outside a map.");
+ return 0;
+ }
+ Map *map = m->getMap();
+ std::string value = map->getProperty(property);
+ const char *v = &value[0];
+
+ lua_pushstring(s, v);
+ return 1;
+}
+
+/**
+ * mana.is_walkable(int x, int y): bool
+ * Returns whether the pixel on the map is walkable.
+ */
+static int is_walkable(lua_State *s)
+{
+ const int x = luaL_checkint(s, 1);
+ const int y = luaL_checkint(s, 2);
+
+ lua_pushlightuserdata(s, (void *)&registryKey);
+ lua_gettable(s, LUA_REGISTRYINDEX);
+ Script *t = static_cast<Script *>(lua_touserdata(s, -1));
+ MapComposite *m = t->getMap();
+ if (!m)
+ {
+ raiseScriptError(s, "is_walkable called outside a map.");
+ return 0;
+ }
+ Map *map = m->getMap();
+
+ // If the wanted warp place is unwalkable
+ if (map->getWalk(x / map->getTileWidth(), y / map->getTileHeight()))
+ lua_pushboolean(s, 1);
+ else
+ lua_pushboolean(s, 0);
+
+ return 1;
+}
+
+/**
+ * mana.drop_item(int x, int y, int id[, int number]): void
+ * Creates an item stack on the floor.
*/
static int item_drop(lua_State *s)
{
@@ -1821,7 +1932,8 @@ static int item_drop(lua_State *s)
}
/**
- * Logs the given message to the log
+ * mana.log(int log_level, string log_message): void
+ * Logs the given message to the log.
*/
static int log(lua_State *s)
{
@@ -1837,7 +1949,9 @@ static int log(lua_State *s)
}
/**
- * Gets the distance between two beings or two points
+ * mana.get_distance(Being*, Being*): int
+ * mana.get_distance(int x1, int y1, int x2, int y2): int
+ * Gets the distance between two beings or two points.
*/
static int get_distance(lua_State *s)
{
@@ -1929,6 +2043,7 @@ LuaScript::LuaScript():
{ "chr_take_special", &chr_take_special },
{ "exp_for_level", &exp_for_level },
{ "monster_create", &monster_create },
+ { "monster_remove", &monster_remove },
{ "monster_load_script", &monster_load_script },
{ "being_apply_status", &being_apply_status },
{ "being_remove_status", &being_remove_status },
@@ -1953,7 +2068,7 @@ LuaScript::LuaScript():
{ "posX", &posX },
{ "posY", &posY },
{ "trigger_create", &trigger_create },
- { "chatmessage", &chatmessage },
+ { "chat_message", &chat_message },
{ "get_beings_in_circle", &get_beings_in_circle },
{ "get_beings_in_rectangle", &get_beings_in_rectangle },
{ "being_register", &being_register },
@@ -1961,6 +2076,8 @@ LuaScript::LuaScript():
{ "chr_shake_screen", &chr_shake_screen },
{ "test_tableget", &test_tableget },
{ "get_map_id", &get_map_id },
+ { "get_map_property", &get_map_property },
+ { "is_walkable", &is_walkable },
{ "item_drop", &item_drop },
{ "npc_ask_integer", &npc_ask_integer },
{ "npc_end", &npc_end },