[Add] Added escort control ai Lua bindings.

This commit is contained in:
Allanis 2013-12-31 06:08:01 +00:00
parent 01a9ae0513
commit dc3bf1292c
4 changed files with 74 additions and 18 deletions

View File

@ -62,6 +62,7 @@
#include "rng.h" #include "rng.h"
#include "space.h" #include "space.h"
#include "faction.h" #include "faction.h"
#include "escort.h"
#include "llua.h" #include "llua.h"
#include "lluadef.h" #include "lluadef.h"
#include "llua_space.h" #include "llua_space.h"
@ -150,6 +151,11 @@ static int ai_getrndplanet(lua_State* L); /* Vec2 getrndplanet() */
static int ai_getlandplanet(lua_State* L); /* Vec2 getlandplanet() */ static int ai_getlandplanet(lua_State* L); /* Vec2 getlandplanet() */
static int ai_hyperspace(lua_State* L); /* [number] hyperspace() */ static int ai_hyperspace(lua_State* L); /* [number] hyperspace() */
static int ai_stop(lua_State* L); /* stop() */ static int ai_stop(lua_State* L); /* stop() */
/* Escorts. */
static int ai_e_attack(lua_State* L); /* bool e_attack() */
static int ai_e_hold(lua_State* L); /* bool e_hold() */
static int ai_e_clear(lua_State* L); /* bool e_clear() */
static int ai_e_return(lua_State* L); /* bool e_return() */
static int ai_dock(lua_State* L); /* dock(number) */ static int ai_dock(lua_State* L); /* dock(number) */
/* Combat. */ /* Combat. */
static int ai_combat(lua_State* L); /* combat(number) */ static int ai_combat(lua_State* L); /* combat(number) */
@ -208,6 +214,11 @@ static const luaL_Reg ai_methods[] = {
{ "brake", ai_brake }, { "brake", ai_brake },
{ "stop", ai_stop }, { "stop", ai_stop },
{ "hyperspace", ai_hyperspace }, { "hyperspace", ai_hyperspace },
/* Escorts. */
{ "e_attack", ai_e_attack },
{ "e_hold", ai_e_hold },
{ "e_clear", ai_e_clear },
{ "e_return", ai_e_return },
{ "dock", ai_dock }, { "dock", ai_dock },
/* Combat. */ /* Combat. */
{ "aim", ai_aim }, { "aim", ai_aim },
@ -1118,6 +1129,38 @@ static int ai_stop(lua_State* L) {
return 0; return 0;
} }
/* Tell the pilots escort to attack its target. */
static int ai_e_attack(lua_State* L) {
int ret;
ret = escorts_attack(cur_pilot);
lua_pushboolean(L, !ret);
return 1;
}
/* Tell the pilots escort to hold position. */
static int ai_e_hold(lua_State* L) {
int ret;
ret = escorts_hold(cur_pilot);
lua_pushboolean(L, !ret);
return 1;
}
/* Tell the pilots escort to clear orders. */
static int ai_e_clear(lua_State* L) {
int ret;
ret = escorts_clear(cur_pilot);
lua_pushboolean(L, !ret);
return 1;
}
/* Tells the pilots escorts to return to dock. */
static int ai_e_return(lua_State* L) {
int ret;
ret = escorts_return(cur_pilot);
lua_pushboolean(L, !ret);
return 1;
}
/* Docks the ship. */ /* Docks the ship. */
static int ai_dock(lua_State* L) { static int ai_dock(lua_State* L) {
Pilot* p; Pilot* p;

View File

@ -135,47 +135,60 @@ static int escort_command(Pilot* parent, int cmd, int param) {
} }
/** /**
* @fn void escorts_attack(Pilot* parent) * @fn int escorts_attack(Pilot* parent)
* *
* @brief HAve a pilot order it's escorts to attack its target. * @brief HAve a pilot order it's escorts to attack its target.
* @param parent Pilot giving the order. * @param parent Pilot giving the order.
*/ */
void escorts_attack(Pilot* parent) { int escorts_attack(Pilot* parent) {
int ret;
ret = 1;
if(parent->target != parent->id) if(parent->target != parent->id)
if(escort_command(parent, ESCORT_ATTACK, parent->target)==0) ret = escort_command(parent, ESCORT_ATTACK, parent->target);
player_message("Escorts: Attacking %s.", pilot_get(parent->target)->name); if((ret == 0) && (parent == player))
player_message("Escorts: Attacking %s.", pilot_get(parent->target)->name);
return ret;
} }
/** /**
* @fn void escorts_hold(Pilot* parent) * @fn int escorts_hold(Pilot* parent)
* *
* @brief Have a pilot order its escorts to hold position. * @brief Have a pilot order its escorts to hold position.
* @param parent Pilot giving the order. * @param parent Pilot giving the order.
*/ */
void escorts_hold(Pilot* parent) { int escorts_hold(Pilot* parent) {
if(escort_command(parent, ESCORT_HOLD, -1)==0) int ret;
ret = escort_command(parent, ESCORT_HOLD, -1);
if((ret == 0) && (parent == player))
player_message("Escorts: Holding position."); player_message("Escorts: Holding position.");
return ret;
} }
/** /**
* @fn void escorts_return(Pilot* parent) * @fn int escorts_return(Pilot* parent)
* *
* @brief Have a pilot order its escorts to dock. * @brief Have a pilot order its escorts to dock.
* @param parent Pilot giving the order. * @param parent Pilot giving the order.
*/ */
void escorts_return(Pilot* parent) { int escorts_return(Pilot* parent) {
if(escort_command(parent, ESCORT_RETURN, -1)==0) int ret;
ret = escort_command(parent, ESCORT_RETURN, -1);
if((ret == 0) && (parent == player))
player_message("Escorts: Returning to ship."); player_message("Escorts: Returning to ship.");
return ret;
} }
/** /**
* @fn void escorts_clear(Pilot* parent) * @fn int escorts_clear(Pilot* parent)
* *
* @brief Have a pilot order its escorts to clear orders. * @brief Have a pilot order its escorts to clear orders.
* @param parent Pilot giving the order. * @param parent Pilot giving the order.
*/ */
void escorts_clear(Pilot* parent) { int escorts_clear(Pilot* parent) {
if(escort_command(parent, ESCORT_CLEAR, -1)==0) int ret;
ret = escort_command(parent, ESCORT_CLEAR, -1);
if((ret == 0) && (parent == player))
player_message("Escorts: Clearing orders."); player_message("Escorts: Clearing orders.");
return ret;
} }

View File

@ -6,8 +6,8 @@ int escort_create(unsigned int parent, char* ship,
Vec2* pos, Vec2* vel, int carried); Vec2* pos, Vec2* vel, int carried);
/* Keybind commands. */ /* Keybind commands. */
void escorts_attack(Pilot* parent); int escorts_attack(Pilot* parent);
void escorts_hold(Pilot* parent); int escorts_hold(Pilot* parent);
void escorts_return(Pilot* parent); int escorts_return(Pilot* parent);
void escorts_clear(Pilot* parent); int escorts_clear(Pilot* parent);

View File

@ -84,7 +84,7 @@ void input_setDefault(void) {
/* Secondary weapon. */ /* Secondary weapon. */
input_setKeybind("secondary", KEYBIND_KEYBOARD, SDLK_LSHIFT, KMOD_ALL, 0); input_setKeybind("secondary", KEYBIND_KEYBOARD, SDLK_LALT, KMOD_ALL, 0);
input_setKeybind("secondary_next", KEYBIND_KEYBOARD, SDLK_e, KMOD_NONE, 0); input_setKeybind("secondary_next", KEYBIND_KEYBOARD, SDLK_e, KMOD_NONE, 0);
/* Space */ /* Space */
input_setKeybind("autonav", KEYBIND_KEYBOARD, SDLK_j, KMOD_LCTRL, 0); input_setKeybind("autonav", KEYBIND_KEYBOARD, SDLK_j, KMOD_LCTRL, 0);