[Add] Pilot:alive() and Pilot:broadcast() to Lua API.

This commit is contained in:
Allanis 2013-11-19 21:51:04 +00:00
parent 7bbad458e0
commit 47a8efa9ee
2 changed files with 67 additions and 8 deletions

View File

@ -1,4 +1,4 @@
include("../scripts/tpl/generic.lua")
include("../scripts/ai/tpl/generic.lua")
-- Settings
armour_run = 40

View File

@ -21,24 +21,29 @@ static int pilot_addFleet(lua_State* L);
static int pilot_clear(lua_State* L);
static int pilot_toggleSpawn(lua_State* L);
static const luaL_reg pilot_methods[] = {
{ "add", pilot_addFleet },
{ "clear", pilot_clear },
{ "add", pilot_addFleet },
{ "clear", pilot_clear },
{ "toggleSpawn", pilot_toggleSpawn },
{ "clear", pilot_toggleSpawn },
{ 0, 0 }
}; /**< Pilot lua methods. */
/* Pilot metatable methods. */
static int pilotL_eq(lua_State* L);
static int pilotL_name(lua_State* L);
static int pilotL_alive(lua_State* L);
static int pilotL_rename(lua_State* L);
static int pilotL_position(lua_State* L);
static int pilotL_warp(lua_State* L);
static int pilotL_broadcast(lua_State* L);
static const luaL_reg pilotL_methods[] = {
{ "__eq", pilotL_eq },
{ "name", pilotL_name },
{ "rename", pilotL_rename },
{ "pos", pilotL_position },
{ "warp", pilotL_warp },
{ "__eq", pilotL_eq },
{ "name", pilotL_name },
{ "alive", pilotL_alive },
{ "rename", pilotL_rename },
{ "pos", pilotL_position },
{ "warp", pilotL_warp },
{ "broadcast", pilotL_broadcast },
{ 0, 0 }
}; /**< Pilot metatable methods. */
@ -361,6 +366,29 @@ static int pilotL_name(lua_State* L) {
return 1;
}
/**
* @fn static int pilotL_alive(lua_State* L)
* @ingroup META_PILOT
*
* @brief bool alive(nil)
*
* Checks to see if pilot is still alive.
* @return true if pilot is still alive.
*/
static int pilotL_alive(lua_State* L) {
LLUA_MIN_ARGS(1);
LuaPilot* lp;
Pilot* p;
/* Parse parameters. */
lp = lua_topilot(L, 1);
p = pilot_get(lp->pilot);
/* Check if is alive. */
lua_pushboolean(L, p != NULL);
return 1;
}
/**
* @fn static int pilotL_rename(lua_State* L)
*
@ -449,3 +477,34 @@ static int pilotL_warp(lua_State* L) {
return 0;
}
/**
* @fn static int pilotL_broadcast(lua_State* L)
* @ingroup META_PILOT
*
* @brief broadcast(string msg)
*
* Make the pilot broadcast a message.
* @param msg Message to broadcast.
*/
static int pilotL_broadcast(lua_State* L) {
LLUA_MIN_ARGS(2);
Pilot* p;
LuaPilot* lp;
char* msg;
/* Parse arguments. */
lp = lua_topilot(L, 1);
if(lua_isstring(L, 2))
msg = (char*)lua_tostring(L, 2);
else LLUA_INVALID_PARAMETER();
/* Check to see if pilot is valid. */
p = pilot_get(lp->pilot);
if(p == NULL)
return 0;
/* Broadcast message. */
player_message("Broadcast %s> \"%s\"", p->name, msg);
return 0;
}