[Add] Pilot:alive() and Pilot:broadcast() to Lua API.
This commit is contained in:
parent
7bbad458e0
commit
47a8efa9ee
@ -1,4 +1,4 @@
|
|||||||
include("../scripts/tpl/generic.lua")
|
include("../scripts/ai/tpl/generic.lua")
|
||||||
|
|
||||||
-- Settings
|
-- Settings
|
||||||
armour_run = 40
|
armour_run = 40
|
||||||
|
@ -21,24 +21,29 @@ static int pilot_addFleet(lua_State* L);
|
|||||||
static int pilot_clear(lua_State* L);
|
static int pilot_clear(lua_State* L);
|
||||||
static int pilot_toggleSpawn(lua_State* L);
|
static int pilot_toggleSpawn(lua_State* L);
|
||||||
static const luaL_reg pilot_methods[] = {
|
static const luaL_reg pilot_methods[] = {
|
||||||
{ "add", pilot_addFleet },
|
{ "add", pilot_addFleet },
|
||||||
{ "clear", pilot_clear },
|
{ "clear", pilot_clear },
|
||||||
{ "toggleSpawn", pilot_toggleSpawn },
|
{ "toggleSpawn", pilot_toggleSpawn },
|
||||||
{ "clear", pilot_toggleSpawn },
|
{ "clear", pilot_toggleSpawn },
|
||||||
{ 0, 0 }
|
{ 0, 0 }
|
||||||
}; /**< Pilot lua methods. */
|
}; /**< Pilot lua methods. */
|
||||||
|
|
||||||
|
/* Pilot metatable methods. */
|
||||||
static int pilotL_eq(lua_State* L);
|
static int pilotL_eq(lua_State* L);
|
||||||
static int pilotL_name(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_rename(lua_State* L);
|
||||||
static int pilotL_position(lua_State* L);
|
static int pilotL_position(lua_State* L);
|
||||||
static int pilotL_warp(lua_State* L);
|
static int pilotL_warp(lua_State* L);
|
||||||
|
static int pilotL_broadcast(lua_State* L);
|
||||||
static const luaL_reg pilotL_methods[] = {
|
static const luaL_reg pilotL_methods[] = {
|
||||||
{ "__eq", pilotL_eq },
|
{ "__eq", pilotL_eq },
|
||||||
{ "name", pilotL_name },
|
{ "name", pilotL_name },
|
||||||
{ "rename", pilotL_rename },
|
{ "alive", pilotL_alive },
|
||||||
{ "pos", pilotL_position },
|
{ "rename", pilotL_rename },
|
||||||
{ "warp", pilotL_warp },
|
{ "pos", pilotL_position },
|
||||||
|
{ "warp", pilotL_warp },
|
||||||
|
{ "broadcast", pilotL_broadcast },
|
||||||
{ 0, 0 }
|
{ 0, 0 }
|
||||||
}; /**< Pilot metatable methods. */
|
}; /**< Pilot metatable methods. */
|
||||||
|
|
||||||
@ -361,6 +366,29 @@ static int pilotL_name(lua_State* L) {
|
|||||||
return 1;
|
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)
|
* @fn static int pilotL_rename(lua_State* L)
|
||||||
*
|
*
|
||||||
@ -449,3 +477,34 @@ static int pilotL_warp(lua_State* L) {
|
|||||||
return 0;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user