diff --git a/bin/Makefile b/bin/Makefile index 31b4465..4404638 100644 --- a/bin/Makefile +++ b/bin/Makefile @@ -29,9 +29,9 @@ ifeq ($(OS),LINUX) CFLAGS += -D_POSIX_SOURCE endif ifdef DEBUG -CFLAGS += -W -Wall -Wextra -Wunused -Wshadow -Wpointer-arith -Wmissing-prototypes -Winline -Wcast-align \ - -Wmissing-declarations -fstack-protector -fstack-protector-all -g3 \ - -DDEBUG -DLUA_USE_APICHECK -std=c99 +CFLAGS += -W -Wall -Wextra -Wunused -Wshadow -Wpointer-arith -Wmissing-prototypes \ + -Winline -Wcast-align -Wmissing-declarations -fstack-protector \ + -fstack-protector-all -g3 -DDEBUG -DLUA_USE_APICHECK -std=c99 else CFLAGS += -O2 -funroll-loops -pipe -std=c99 endif diff --git a/dat/missions/emp_scout00.lua b/dat/missions/emp_scout00.lua index 4712c85..db9f469 100644 --- a/dat/missions/emp_scout00.lua +++ b/dat/missions/emp_scout00.lua @@ -61,7 +61,7 @@ function enter() pilot.add("Empire Sml Defense") pilot.add("Collective Sml Swarm") elseif sys == misn_target then - p = pilot.add("Collective Drone") + p = pilot.add("Collective Drone", "scout") for k,v in pairs(p) do hook.pilotDeath(v, "kill") end diff --git a/src/ai.c b/src/ai.c index 2435ae6..910d3fd 100644 --- a/src/ai.c +++ b/src/ai.c @@ -539,10 +539,24 @@ static int ai_pshield(lua_State* L) { /* Get the distance from the pointer. */ static int ai_getdistance(lua_State* L) { Vec2* vect; + Pilot* pilot; 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)); return 1; } diff --git a/src/misn_lua.c b/src/misn_lua.c index f56936c..a48ded9 100644 --- a/src/misn_lua.c +++ b/src/misn_lua.c @@ -738,15 +738,20 @@ static int hook_pilotDeath(lua_State* L) { static int pilot_addFleet(lua_State* L) { LLUA_MIN_ARGS(1); Fleet* flt; - char* fltname; + char* fltname, *fltai;; int i, j; unsigned int p; double a; 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(); + /* Parse second arguement - Fleet AI override. */ + if(lua_isstring(L, 2)) fltai = (char*) lua_tostring(L, 2); + else fltai = NULL; + /* Pull the fleet. */ flt = fleet_get(fltname); if(flt == NULL) { @@ -772,7 +777,9 @@ static int pilot_addFleet(lua_State* L) { p = pilot_create(flt->pilots[i].ship, flt->pilots[i].name, flt->faction, - flt->ai, + (fltai != NULL) ? /* AI override */ + ai_getProfile(fltai) : + flt->ai, a, &vp, &vv,