[Change] ai.dist() now accepts pilot id's as parameter.
This commit is contained in:
parent
ef5a8e5a5f
commit
a580cdeed3
@ -29,9 +29,9 @@ ifeq ($(OS),LINUX)
|
|||||||
CFLAGS += -D_POSIX_SOURCE
|
CFLAGS += -D_POSIX_SOURCE
|
||||||
endif
|
endif
|
||||||
ifdef DEBUG
|
ifdef DEBUG
|
||||||
CFLAGS += -W -Wall -Wextra -Wunused -Wshadow -Wpointer-arith -Wmissing-prototypes -Winline -Wcast-align \
|
CFLAGS += -W -Wall -Wextra -Wunused -Wshadow -Wpointer-arith -Wmissing-prototypes \
|
||||||
-Wmissing-declarations -fstack-protector -fstack-protector-all -g3 \
|
-Winline -Wcast-align -Wmissing-declarations -fstack-protector \
|
||||||
-DDEBUG -DLUA_USE_APICHECK -std=c99
|
-fstack-protector-all -g3 -DDEBUG -DLUA_USE_APICHECK -std=c99
|
||||||
else
|
else
|
||||||
CFLAGS += -O2 -funroll-loops -pipe -std=c99
|
CFLAGS += -O2 -funroll-loops -pipe -std=c99
|
||||||
endif
|
endif
|
||||||
|
@ -61,7 +61,7 @@ function enter()
|
|||||||
pilot.add("Empire Sml Defense")
|
pilot.add("Empire Sml Defense")
|
||||||
pilot.add("Collective Sml Swarm")
|
pilot.add("Collective Sml Swarm")
|
||||||
elseif sys == misn_target then
|
elseif sys == misn_target then
|
||||||
p = pilot.add("Collective Drone")
|
p = pilot.add("Collective Drone", "scout")
|
||||||
for k,v in pairs(p) do
|
for k,v in pairs(p) do
|
||||||
hook.pilotDeath(v, "kill")
|
hook.pilotDeath(v, "kill")
|
||||||
end
|
end
|
||||||
|
18
src/ai.c
18
src/ai.c
@ -539,10 +539,24 @@ static int ai_pshield(lua_State* L) {
|
|||||||
/* Get the distance from the pointer. */
|
/* Get the distance from the pointer. */
|
||||||
static int ai_getdistance(lua_State* L) {
|
static int ai_getdistance(lua_State* L) {
|
||||||
Vec2* vect;
|
Vec2* vect;
|
||||||
|
Pilot* pilot;
|
||||||
|
|
||||||
LLUA_MIN_ARGS(1);
|
LLUA_MIN_ARGS(1);
|
||||||
vect = (lua_islightuserdata(L,1)) ?
|
|
||||||
(Vec2*)lua_topointer(L,1) : NULL;
|
/* Vector as a parameter. */
|
||||||
|
if(lua_islightuserdata(L, 1))
|
||||||
|
vect = (Vec2*)lua_topointer(L, 1);
|
||||||
|
|
||||||
|
/* Pilot id as parameter. */
|
||||||
|
else if(lua_isnumber(L, 1)) {
|
||||||
|
pilot = pilot_get((unsigned int) lua_tonumber(L, 1));
|
||||||
|
vect = &pilot->solid->pos;
|
||||||
|
} else {
|
||||||
|
/* Wrong parameter. */
|
||||||
|
LLUA_INVALID_PARAMETER();
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
lua_pushnumber(L, vect_dist(vect, &cur_pilot->solid->pos));
|
lua_pushnumber(L, vect_dist(vect, &cur_pilot->solid->pos));
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -738,15 +738,20 @@ static int hook_pilotDeath(lua_State* L) {
|
|||||||
static int pilot_addFleet(lua_State* L) {
|
static int pilot_addFleet(lua_State* L) {
|
||||||
LLUA_MIN_ARGS(1);
|
LLUA_MIN_ARGS(1);
|
||||||
Fleet* flt;
|
Fleet* flt;
|
||||||
char* fltname;
|
char* fltname, *fltai;;
|
||||||
int i, j;
|
int i, j;
|
||||||
unsigned int p;
|
unsigned int p;
|
||||||
double a;
|
double a;
|
||||||
Vec2 vv, vp, vn;
|
Vec2 vv, vp, vn;
|
||||||
|
|
||||||
if(lua_isstring(L, -1)) fltname = (char*) lua_tostring(L, -1);
|
/* Parse first argument - Fleet name. */
|
||||||
|
if(lua_isstring(L, 1)) fltname = (char*) lua_tostring(L, 1);
|
||||||
else LLUA_INVALID_PARAMETER();
|
else LLUA_INVALID_PARAMETER();
|
||||||
|
|
||||||
|
/* Parse second arguement - Fleet AI override. */
|
||||||
|
if(lua_isstring(L, 2)) fltai = (char*) lua_tostring(L, 2);
|
||||||
|
else fltai = NULL;
|
||||||
|
|
||||||
/* Pull the fleet. */
|
/* Pull the fleet. */
|
||||||
flt = fleet_get(fltname);
|
flt = fleet_get(fltname);
|
||||||
if(flt == NULL) {
|
if(flt == NULL) {
|
||||||
@ -772,6 +777,8 @@ static int pilot_addFleet(lua_State* L) {
|
|||||||
p = pilot_create(flt->pilots[i].ship,
|
p = pilot_create(flt->pilots[i].ship,
|
||||||
flt->pilots[i].name,
|
flt->pilots[i].name,
|
||||||
flt->faction,
|
flt->faction,
|
||||||
|
(fltai != NULL) ? /* AI override */
|
||||||
|
ai_getProfile(fltai) :
|
||||||
flt->ai,
|
flt->ai,
|
||||||
a,
|
a,
|
||||||
&vp,
|
&vp,
|
||||||
|
Loading…
Reference in New Issue
Block a user