26#include "map_overlay.h"
30#include "nlua_pilot.h"
32#include "nlua_system.h"
38static int func_system = LUA_NOREF;
39static int func_spob = LUA_NOREF;
40static int func_pilot = LUA_NOREF;
41static int func_board = LUA_NOREF;
42static int func_pos = LUA_NOREF;
43static int func_reset = LUA_NOREF;
44static int func_end = LUA_NOREF;
45static int func_abort = LUA_NOREF;
46static int func_think = LUA_NOREF;
47static int func_update = LUA_NOREF;
48static int func_enter = LUA_NOREF;
55int player_autonavInit (
void)
57 nlua_env env = nlua_newEnv();
62 char *buf =
ndata_read( AUTONAV_PATH, &bufsize );
63 if (nlua_dobufenv(env, buf, bufsize, AUTONAV_PATH) != 0) {
64 WARN( _(
"Error loading file: %s\n"
66 "Most likely Lua file has improper syntax, please check"),
67 AUTONAV_PATH, lua_tostring(naevL,-1));
103 if (pilot_isFlag(
player.
p, PILOT_MANUAL_CONTROL ) ||
115 player_message(
"#r%s#0",_(
"Not enough fuel to jump for autonav."));
119 if (pilot_isFlag(
player.
p, PILOT_NOJUMP)) {
127 lua_rawgeti( naevL, LUA_REGISTRYINDEX, func_system );
129 WARN(
"%s",lua_tostring(naevL,-1));
143 if (pilot_isFlag(
player.
p, PILOT_MANUAL_CONTROL ) ||
149 player_setFlag(PLAYER_AUTONAV);
154static int autonav_ending = 0;
165 player_rmFlag(PLAYER_AUTONAV);
170 lua_rawgeti( naevL, LUA_REGISTRYINDEX, func_end );
172 WARN(
"%s",lua_tostring(naevL,-1));
200 vec2_cset( &pos, x, y );
201 lua_rawgeti( naevL, LUA_REGISTRYINDEX, func_pos );
204 WARN(
"%s",lua_tostring(naevL,-1));
222 lua_rawgeti( naevL, LUA_REGISTRYINDEX, func_spob );
224 lua_pushboolean( naevL, tryland );
226 WARN(
"%s",lua_tostring(naevL,-1));
243 lua_rawgeti( naevL, LUA_REGISTRYINDEX, func_pilot );
246 WARN(
"%s",lua_tostring(naevL,-1));
268 lua_rawgeti( naevL, LUA_REGISTRYINDEX, func_board );
271 WARN(
"%s",lua_tostring(naevL,-1));
289 if (!player_isFlag(PLAYER_AUTONAV))
294 if (pilot_isFlag(
player.
p, PILOT_MANUAL_CONTROL ))
298 lua_rawgeti( naevL, LUA_REGISTRYINDEX, func_abort );
300 lua_pushstring( naevL, reason );
302 lua_pushnil( naevL );
304 WARN(
"%s",lua_tostring(naevL,-1));
309 if (pilot_isFlag(
player.
p, PILOT_HYP_PREP)) {
311 player_message(
"#o%s#0",_(
"Autonav: aborting hyperspace sequence."));
315void player_autonavReset(
double s )
317 lua_rawgeti( naevL, LUA_REGISTRYINDEX, func_reset );
318 lua_pushnumber( naevL, s );
320 WARN(
"%s",lua_tostring(naevL,-1));
337 lua_rawgeti( naevL, LUA_REGISTRYINDEX, func_think );
338 lua_pushnumber( naevL, dt );
340 WARN(
"%s",lua_tostring(naevL,-1));
354 const double dis_dead = 1.0;
355 const double dis_mod = 2.0;
360 pilot_isFlag(
player.
p, PILOT_DEAD) ||
361 player_isFlag( PLAYER_CINEMATICS ))
366 if (pilot_isFlag(
player.
p, PILOT_DISABLED)) {
367 static double tc_mod = 1.0;
381 double dis_ramp = (dis_max-tc_base) / dis_mod;
389 if (time_left < dis_dead + (dis_max-tc_base)*dis_ramp/2. + tc_base*dis_ramp)
390 tc_mod =
MAX( tc_base, tc_mod - dis_mod*dt );
393 tc_mod =
MIN( dis_max, tc_mod + dis_mod*dt );
401 if (!player_isFlag(PLAYER_AUTONAV))
404 lua_rawgeti( naevL, LUA_REGISTRYINDEX, func_update );
405 lua_pushnumber( naevL, dt );
407 WARN(
"%s",lua_tostring(naevL,-1));
412void player_autonavEnter (
void)
415 if (!player_isFlag(PLAYER_AUTONAV))
418 lua_rawgeti( naevL, LUA_REGISTRYINDEX, func_enter );
420 WARN(
"%s",lua_tostring(naevL,-1));
void ai_unsetPilot(AIMemory oldmem)
Finishes setting up a pilot.
void ai_thinkApply(Pilot *p)
Applies the result of thinking.
void ai_thinkSetup(double dt)
Sets up the pilot for thinking.
AIMemory ai_setPilot(Pilot *p)
Sets the pilot for further AI calls.
Provides macros to work with dynamic arrays.
void player_message(const char *fmt,...)
Adds a mesg to the queue to be displayed on screen.
Header file with generic functions and naev-specifics.
void * ndata_read(const char *path, size_t *filesize)
Reads a file from the ndata (will be NUL terminated).
int nlua_loadStandard(nlua_env env)
Loads the standard Naev Lua API.
int nlua_refenvtype(nlua_env env, const char *name, int type)
Gets the reference of a global in a lua environment if it matches a type.
LuaPilot * lua_pushpilot(lua_State *L, LuaPilot pilot)
Pushes a pilot on the stack.
LuaSpob * lua_pushspob(lua_State *L, LuaSpob spob)
Pushes a spob on the stack.
vec2 * lua_pushvector(lua_State *L, vec2 vec)
Pushes a vector on the stack.
void pause_setSpeed(double mod)
Adjusts the game's dt modifier.
void pilot_hyperspaceAbort(Pilot *p)
Stops the pilot from hyperspacing.
Pilot * pilot_get(unsigned int id)
Pulls a pilot out of the pilot_stack based on ID.
int pilot_inRangePilot(const Pilot *p, const Pilot *target, double *dist2)
Check to see if a pilot is in sensor range of another.
void player_resetSpeed(void)
Resets the player speed stuff.
void player_hyperspacePreempt(int preempt)
Enables or disables jump points preempting spobs in autoface and target clearing.
double player_dt_default(void)
Returns the player's total default time delta based on time dilation stuff.
int player_getHypPreempt(void)
Returns whether the jump point target should preempt the spob target.
void player_restoreControl(int reason, const char *str)
Aborts autonav and other states that take control of the ship.
void player_accelOver(void)
Done accelerating.
static int player_autonavSetup(void)
Prepares the player to enter autonav.
void player_autonavEnd(void)
Ends the autonav.
void player_autonavStartWindow(unsigned int wid, const char *str)
Starts autonav and closes the window.
void player_autonavPos(double x, double y)
Starts autonav with a local position destination.
void player_autonavResetSpeed(void)
Resets the game speed.
void player_autonavStart(void)
Starts autonav.
void player_autonavPil(unsigned int p)
Starts autonav with a pilot to follow.
static nlua_env autonav_env
void player_autonavBoard(unsigned int p)
Starts autonav with a pilot to board.
void player_autonavSpob(const char *name, int tryland)
Starts autonav with a spob destination.
void player_autonavAbort(const char *reason)
Aborts autonav.
void player_thinkAutonav(Pilot *pplayer, double dt)
Handles autonav thinking.
void player_updateAutonav(double dt)
Updates the player's autonav.
void sound_setSpeed(double s)
Sets the speed to play the sound at.
Spob * spob_get(const char *spobname)
Gets a spob based on its name.
int spob_index(const Spob *p)
Gets the ID of a spob.
Represents a temporary pilot memory. For use with ai_setPilot and ai_unsetPilot.
The representation of an in-game pilot.
Represents a Space Object (SPOB), including and not limited to planets, stations, wormholes,...