/** * @brief Gets jump path from current system, or to another. * * Does different things depending on the parameter type: * - nil : Gets path from current system. * - string : Gets path from system matching name. * - system : Gets path from system * * @usage jumps = sys:jumpPath() -- Path to current system. * @usage jumps = sys:jumpPath( "Draygar" ) -- Path from current sys to Draygar. * @usage jumps = system.jumpPath( "Draygar", another_sys ) -- Path from Draygar to another_sys. * * @luatparam System s System to get path from. * @luatparam nil|string|System param See description. * @luatparam[opt=false] boolean hidden Whether or not to consider hidden jumps. * @luatreturn {Jump,...} Table of jumps. * @luafunc jumpPath( s, param, hidden ) */ static int systemL_jumpPath( lua_State *L ) { LuaJump lj; StarSystem *sys, *sysp; StarSystem **s; int i, sid, jumps, pushed, h; const char *start, *goal; h = lua_toboolean(L,3); /* Foo to Bar */ if (lua_gettop(L) > 1) { sys = luaL_validsystem(L,1); start = sys->name; sid = sys->id; if (lua_isstring(L,2)) goal = lua_tostring(L,2); else if (lua_issystem(L,2)) { sysp = luaL_validsystem(L,2); goal = sysp->name; } else NLUA_INVALID_PARAMETER(L); } /* Current to Foo */ else { start = cur_system->name; sid = cur_system->id; sys = luaL_validsystem(L,1); goal = sys->name; } s = map_getJumpPath( &jumps, start, goal, 1, h, NULL ); if (s == NULL) return 0; /* Create the jump table. */ lua_newtable(L); pushed = 0; /* Map path doesn't contain the start system, push it manually. */ lj.srcid = sid; lj.destid = s[0]->id; lua_pushnumber(L, ++pushed); /* key. */ lua_pushjump(L, lj); /* value. */ lua_rawset(L, -3); for (i=0; i<(jumps - 1); i++) { lj.srcid = s[i]->id; lj.destid = s[i+1]->id; lua_pushnumber(L, ++pushed); /* key. */ lua_pushjump(L, lj); /* value. */ lua_rawset(L, -3); } free(s); return 1; }
/** * @brief Gets all the jumps in a system. * * @usage for _,s in ipairs( sys:jumps() ) do -- Iterate over jumps. * * @luaparam s System to get the jumps of. * @luaparam exitonly Whether to exclude exit-only jumps (default false). * @luareturn An ordered table with all the jumps. * @luafunc jumps( s ) */ static int systemL_jumps( lua_State *L ) { int i, exitonly, pushed; LuaJump lj; StarSystem *s; s = luaL_validsystem(L,1); exitonly = lua_toboolean(L,2); pushed = 0; /* Push all jumps. */ lua_newtable(L); for (i=0; i<s->njumps; i++) { /* Skip exit-only jumps if requested. */ if ((exitonly) && (jp_isFlag( jump_getTarget( s->jumps[i].target, s ), JP_EXITONLY))) continue; lj.srcid = s->id; lj.destid = s->jumps[i].targetid; lua_pushnumber(L,++pushed); /* key. */ lua_pushjump(L,lj); /* value. */ lua_rawset(L,-3); } return 1; }
/** * @brief Gets a jump. * * Possible values of params: <br/> * - string : Gets the jump by system name. <br/> * - system : Gets the jump by system. <br/> * * @usage j,r = jump.get( "Ogat", "Goddard" ) -- Returns the Ogat to Goddard and Goddard to Ogat jumps. * @luaparam param See description. * @luareturn Returns the jump and the inverse (where it exits). * @luafunc get( param ) */ static int jumpL_get( lua_State *L ) { LuaJump lj; StarSystem *a, *b; /* Defaults. */ a = NULL; b = NULL; if (lua_gettop(L) > 1) { if (lua_isstring(L, 1)) a = system_get( lua_tostring(L, 1)); else if (lua_issystem(L, 1)) a = system_getIndex( lua_tosystem(L, 1) ); if (lua_isstring(L, 2)) b = system_get( lua_tostring(L, 2)); else if (lua_issystem(L, 2)) b = system_getIndex( lua_tosystem(L, 2) ); if ((a == NULL) || (b == NULL)) { NLUA_ERROR(L, "No matching jump points found."); return 0; } if (jump_getTarget(b, a) != NULL) { lj.srcid = a->id; lj.destid = b->id; lua_pushjump(L, lj); /* The inverse. If it doesn't exist, there are bigger problems. */ lj.srcid = b->id; lj.destid = a->id; lua_pushjump(L, lj); return 2; } } else NLUA_INVALID_PARAMETER(L); return 0; }
/** * @brief Have a pilot order its escorts to jump. * * @param parent Pilot giving the order. */ int escorts_jump( Pilot *parent, JumpPoint *jp ) { int ret; LuaJump lj; lj.destid = jp->targetid; lj.srcid = cur_system->id; lua_pushjump( naevL, lj ); ret = escort_command( parent, "hyperspace", -1 ); lua_pop(naevL, 1); if ((ret == 0) && (parent == player.p)) player_message(_("\agEscorts: \a0Jumping.")); return ret; }