/** * @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 Adds a jump. * * @usage system.createJump( "sys", "target", bothway) -- Creates a regular jump. * * @luaparam name Name of the system in which to create the jump. * @luaparam target Name of the targeted system. * @luaparam bothway If true, create the return jump in the target system. * @luaparam known Whether the player should known the jump * @luafunc createJump( "sys", "target", bothway) */ static int systemL_createJump( lua_State *L ) { StarSystem *sys = luaL_validsystem(L, 1); StarSystem *target = luaL_validsystem(L, 2); int bothway = lua_toboolean(L, 3); int known = lua_toboolean(L, 4); int alreadyExists=0; int i; for (i=0;i<sys->njumps;i++) { if (sys->jumps[i].target==target) alreadyExists=1; } if (!alreadyExists) system_addJumpPoint(sys,target,0,0,-1,-1,1,0,0,1,known); if (bothway==1) { alreadyExists=0; for (i=0;i<target->njumps;i++) { if (target->jumps[i].target==sys) alreadyExists=1; } if (!alreadyExists) system_addJumpPoint(target,sys,0,0,-1,-1,1,0,0,1,known); } systems_reconstructJumps(); return 0; }
/** * @brief Gets jump distance from current system, or to another. * * Does different things depending on the parameter type: * - nil : Gets distance from current system. * - string : Gets distance from system matching name. * - system : Gets distance from system * * @usage d = sys:jumpDist() -- Distance from current system. * @usage d = sys:jumpDist( "Draygar" ) -- Distance from system Draygar. * @usage d = sys:jumpDist( another_sys ) -- Distance from system another_sys. * * @luaparam s System to get distance from. * @luaparam param See description. * @luaparam hidden Whether or not to consider hidden jumps. * @luareturn Number of jumps to system. * @luafunc jumpDist( s, param, hidden ) */ static int systemL_jumpdistance( lua_State *L ) { StarSystem *sys, *sysp; StarSystem **s; int jumps; const char *start, *goal; int h; sys = luaL_validsystem(L,1); start = sys->name; h = lua_toboolean(L,3); if (lua_gettop(L) > 1) { 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); } else goal = cur_system->name; s = map_getJumpPath( &jumps, start, goal, 1, h, NULL ); free(s); lua_pushnumber(L,jumps); 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 Sets a system's known state. * * @usage s:setKnown( false ) -- Makes system unknown. * @luaparam s System to set known. * @luaparam b Whether or not to set as known (defaults to false). * @luaparam r Whether or not to iterate over the system's assets and jump points (defaults to false). * @luafunc setKnown( s, b ) */ static int systemL_setknown( lua_State *L ) { int b, r, i; StarSystem *sys; r = 0; sys = luaL_validsystem(L, 1); b = lua_toboolean(L, 2); if (lua_gettop(L) > 2) r = lua_toboolean(L, 3); if (b) sys_setFlag( sys, SYSTEM_KNOWN ); else sys_rmFlag( sys, SYSTEM_KNOWN ); if (r) { if (b) { for (i=0; i < sys->nplanets; i++) planet_setKnown( sys->planets[i] ); for (i=0; i < sys->njumps; i++) jp_setFlag( &sys->jumps[i], JP_KNOWN ); } else { for (i=0; i < sys->nplanets; i++) planet_rmFlag( sys->planets[i], PLANET_KNOWN ); for (i=0; i < sys->njumps; i++) jp_rmFlag( &sys->jumps[i], JP_KNOWN ); } } return 0; }
/** * @brief Checks to see if a faction has presence in a system. * * This checks to see if the faction has a possibility of having any ships at all * be randomly generated in the system. * * @usage if sys:hasPresence( "Empire" ) then -- Checks to see if Empire has ships in the system * @usage if sys:hasPresence( faction.get("Pirate") ) then -- Checks to see if the Pirate has ships in the system * * @luaparam s System to check to see if has presence of a certain faction. * @luaparam f Faction or name of faction to check to see if has presence in the system. * @luareturn true If faction has presence in the system, false otherwise. * @luafunc hasPresence( s, f ) */ static int systemL_hasPresence( lua_State *L ) { LuaFaction *lf; StarSystem *s; int fct; int i, found; s = luaL_validsystem(L,1); /* Get the second parameter. */ if (lua_isstring(L,2)) { fct = faction_get( lua_tostring(L,2) ); } else if (lua_isfaction(L,2)) { lf = lua_tofaction(L,2); fct = lf->f; } else NLUA_INVALID_PARAMETER(L); /* Try to find a fleet of the faction. */ found = 0; for (i=0; i<s->npresence; i++) { if (s->presence[i].faction == fct) { found = 1; break; } } lua_pushboolean(L, found); return 1; }
/** * @brief Returns the system's name. * * @usage name = sys:name() * * @luaparam s System to get name of. * @luareturn The name of the system. * @luafunc name( s ) */ static int systemL_name( lua_State *L ) { StarSystem *sys; sys = luaL_validsystem(L,1); lua_pushstring(L, sys->name); return 1; }
/** * @brief Sets a system's background star number. * * @usage p:setStars( number ) sets star number * @luaparam p System to set star number for. * @luaparam n star number * @luafunc setStars( s, n ) */ static int systemL_setStars( lua_State *L ) { StarSystem *sys = luaL_validsystem(L, 1); sys->stars=(int)luaL_checknumber(L, 2); return 0; }
/** * @brief Gets all the adjacent systems to a system. * * @usage for _,s in ipairs( sys:adjacentSystems() ) do -- Iterate over adjacent systems. * * @luatparam System s System to get adjacent systems of. * @luatparam[opt=false] boolean hidden Whether or not to show hidden jumps also. * @luatreturn {System,...} An ordered table with all the adjacent systems. * @luafunc adjacentSystems( s, hidden ) */ static int systemL_adjacent( lua_State *L ) { int i, id, h; LuaSystem sysp; StarSystem *s; id = 1; s = luaL_validsystem(L,1); h = lua_toboolean(L,2); /* Push all adjacent systems. */ lua_newtable(L); for (i=0; i<s->njumps; i++) { if (jp_isFlag(&s->jumps[i], JP_EXITONLY )) continue; if (!h && jp_isFlag(&s->jumps[i], JP_HIDDEN)) continue; sysp = system_index( s->jumps[i].target ); lua_pushnumber(L, id); /* key. */ lua_pushsystem(L, sysp); /* value. */ lua_rawset(L,-3); id++; } return 1; }
/** * @brief Sets a system's background script. * * @usage p:setBackground( zone ) sets zone * @luaparam p System to set background for. * @luaparam b background * @luafunc setZone( s, b ) */ static int systemL_setBackground( lua_State *L ) { StarSystem *sys = luaL_validsystem(L, 1); sys->background=strdup(lua_tostring(L, 2)); return 0; }
/** * @brief Sets a system's zone. * * @usage p:setZone( zone ) sets zone * @luaparam p System to set zone for. * @luaparam b zone * @luafunc setZone( s, b ) */ static int systemL_setZone( lua_State *L ) { StarSystem *sys = luaL_validsystem(L, 1); sys->zone=strdup(lua_tostring(L, 2)); return 0; }
/** * @brief Sets a system's lua data. * * @usage p:setLuaData( luaData ) sets lua data * @luaparam p System to set lua data for. * @luaparam b lua data * @luafunc setLuaData( s, b ) */ static int systemL_setLuaData( lua_State *L ) { StarSystem *sys = luaL_validsystem(L, 1); sys->luaData=strdup(lua_tostring(L, 2)); return 0; }
/** * @brief Gets the presence in the system. * * Possible parameters are besides a faction:<br/> * - "all": Gets the sum of all the presences.<br /> * - "friendly": Gets the sum of all the friendly presences.<br /> * - "hostile": Gets the sum of all the hostile presences.<br /> * - "neutral": Gets the sum of all the neutral presences.<br /> * * @usage p = sys:presence( f ) -- Gets the presence of a faction f * @usage p = sys:presence( "all" ) -- Gets the sum of all the presences * @usage if sys:presence("friendly") > sys:presence("hostile") then -- Checks to see if the system is dominantly friendly * * @luatparam System s System to get presence level of. * @luatreturn number The presence level in sys (absolute value). * @luafunc presence( s ) */ static int systemL_presence( lua_State *L ) { StarSystem *sys; int *fct; int nfct; double presence, v; int i, f, used; const char *cmd; /* Get parameters. */ sys = luaL_validsystem(L, 1); /* Allow fall-through. */ used = 0; /* Get the second parameter. */ if (lua_isstring(L, 2)) { /* A string command has been given. */ cmd = lua_tostring(L, 2); nfct = 0; used = 1; /* Check the command string and get the appropriate faction group.*/ if(strcmp(cmd, "all") == 0) fct = faction_getGroup(&nfct, 0); else if(strcmp(cmd, "friendly") == 0) fct = faction_getGroup(&nfct, 1); else if(strcmp(cmd, "hostile") == 0) fct = faction_getGroup(&nfct, 3); else if(strcmp(cmd, "neutral") == 0) fct = faction_getGroup(&nfct, 2); else /* Invalid command string. */ used = 0; } if (!used) { /* A faction id was given. */ f = luaL_validfaction(L, 2); nfct = 1; fct = malloc(sizeof(int)); fct[0] = f; } /* Add up the presence values. */ presence = 0; for(i=0; i<nfct; i++) { /* Only count positive presences. */ v = system_getPresence( sys, fct[i] ); if (v > 0) presence += v; } /* Clean up after ourselves. */ free(fct); /* Push it back to Lua. */ lua_pushnumber(L, presence); return 1; }
/** * @brief Returns the system's coordinates. * * @usage x,y = sys:coords() * * @luaparam s System to get coords of. * @luareturn The coords of the system. * @luafunc name( s ) */ static int systemL_coords( lua_State *L ) { StarSystem *sys; sys = luaL_validsystem(L,1); lua_pushnumber(L,sys->pos.x); lua_pushnumber(L,sys->pos.y); return 2; }
/** * @brief Adds a star graphic to the system. * * @usage system.addStar( "sys", "star") -- Adds a star graphic to the system. * * @luaparam name Name of the system in which to create the star. * @luaparam target Name of the star graphic (the PNG file). * @luafunc addStar( "sys", "star") */ static int systemL_addStar( lua_State *L ) { StarSystem *sys = luaL_validsystem(L, 1); const char* name = luaL_checkstring(L, 2); system_addStar(sys,strdup(name)); return 0; }
/** * @brief Gets the lua data * * @uasge gfx = sys:getLuaData() * @luaparam sys System to get lua data of. * @luareturn The lua data of the system. * @luafunc getLuaData( p ) */ static int systemL_getLuaData( lua_State *L ) { StarSystem *sys = luaL_validsystem(L, 1); if (sys->luaData == NULL) lua_pushstring(L,"{}"); else lua_pushstring(L,sys->luaData); return 1; }
/** * @brief Gets the background seed * * This is the seed for generating the background. * 0 if not specified. * * @usage r = s:backgroundSeed() * * @luatparam System s System to get the background seed of. * @luatreturn number The background seed of the system. * @luafunc radius( s ) */ static int systemL_backgroundSeed( lua_State *L ) { StarSystem *sys; /* Get parameters. */ sys = luaL_validsystem(L, 1); lua_pushnumber( L, sys->backgroundSeed ); return 1; }
/** * @brief Gets the radius of the system. * * This is the radius of the circle which all the default jumps will be on. * * @usage r = s:radius() * * @luaparam s System to get the radius of. * @luareturn The radius of the system. * @luafunc radius( s ) */ static int systemL_radius( lua_State *L ) { StarSystem *sys; /* Get parameters. */ sys = luaL_validsystem(L, 1); lua_pushnumber( L, sys->radius ); return 1; }
/** * @brief Gets the system's nebula parameters. * * @usage density, volatility = sys:nebula() * * @luaparam s System to get nebula parameters from. * @luareturn The density and volatility of the system. * @luafunc nebula( s ) */ static int systemL_nebula( lua_State *L ) { StarSystem *s; s = luaL_validsystem(L,1); /* Push the density and volatility. */ lua_pushnumber(L, s->nebu_density); lua_pushnumber(L, s->nebu_volatility); return 2; }
/** * @brief Gets the presence in the system. * * Possible parameters are besides a faction:<br/> * - "all": Gets the sum of all the presences.<br /> * - "friendly": Gets the sum of all the friendly presences.<br /> * - "hostile": Gets the sum of all the hostile presences.<br /> * - "neutral": Gets the sum of all the neutral presences.<br /> * * @usage p = sys:presence( f ) -- Gets the presence of a faction f * @usage p = sys:presence( "all" ) -- Gets the sum of all the presences * @usage if sys:presence("friendly") > sys:presence("hostile") then -- Checks to see if the system is dominantly friendly * * @luaparam s System to get presence level of. * @luareturn The presence level in sys (absolute value). * @luafunc presence( s ) */ static int systemL_presence( lua_State *L ) { StarSystem *sys; LuaFaction *lf; int *fct; int nfct; double presence; int i; const char *cmd; /* Get parameters. */ sys = luaL_validsystem(L, 1); /* Get the second parameter. */ if (lua_isstring(L, 2)) { /* A string command has been given. */ cmd = lua_tostring(L, 2); nfct = 0; /* Check the command string and get the appropriate faction group.*/ if(strcmp(cmd, "all") == 0) fct = faction_getGroup(&nfct, 0); else if(strcmp(cmd, "friendly") == 0) fct = faction_getGroup(&nfct, 1); else if(strcmp(cmd, "hostile") == 0) fct = faction_getGroup(&nfct, 3); else if(strcmp(cmd, "neutral") == 0) fct = faction_getGroup(&nfct, 2); else /* Invalid command string. */ NLUA_INVALID_PARAMETER(L); } else if (lua_isfaction(L, 2)) { /* A faction id was given. */ lf = lua_tofaction(L, 2); nfct = 1; fct = malloc(sizeof(int) * nfct); fct[0] = lf->f; } else NLUA_INVALID_PARAMETER(L); /* Add up the presence values. */ presence = 0; for(i=0; i<nfct; i++) presence += system_getPresence( sys, fct[i] ); /* Clean up after ourselves. */ free(fct); /* Push it back to Lua. */ lua_pushnumber(L, presence); return 1; }
/** * @brief Gets the position of a jump point from one system to another. * * @usage v = system.cur():jumpPos( neighbour_system ) -- Gets the position of the jump point to neighbour_system * * @luaparam from System jumping from. * @luaparam to System jumping to. * @luareturn A Vector2D containing the jump position or nil if not connected. * @luafunc jumpPos( from, to ) */ static int systemL_jumpPos( lua_State *L ) { LuaVector lv; StarSystem *from, *to; int i; from = luaL_validsystem(L,1); to = luaL_validsystem(L,2); for (i=0; i<from->njumps; i++) { /* Wait until found. */ if (from->jumps[i].target != to) continue; vectcpy( &lv.vec, &from->jumps[i].pos ); lua_pushvector(L,lv); return 1; } lua_pushnil(L); return 1; }
/** * @brief Gets system faction. * * @luatparam System s System to get the faction of. * @luatreturn Faction The dominant faction in the system. * @luafunc faction( s ) */ static int systemL_faction( lua_State *L ) { StarSystem *s; s = luaL_validsystem(L,1); if (s->faction == -1) return 0; lua_pushfaction(L,s->faction); return 1; }
/** * @brief Sets a system's known state. * * @usage s:setKnown( false ) -- Makes system unknown. * @luaparam s System to set known. * @luaparam b Whether or not to set as known (defaults to false). * @luafunc setKnown( s, b ) */ static int systemL_setknown( lua_State *L ) { int b; StarSystem *sys; sys = luaL_validsystem(L, 1); b = lua_toboolean(L, 2); if (b) sys_setFlag( sys, SYSTEM_KNOWN ); else sys_rmFlag( sys, SYSTEM_KNOWN ); return 0; }
/** * @brief Gets system faction. * * @luaparam s System to get the faction of. * @luareturn The dominant faction in the system. * @luafunc faction( s ) */ static int systemL_faction( lua_State *L ) { LuaFaction lf; StarSystem *s; s = luaL_validsystem(L,1); if (s->faction == -1) return 0; else lf.f = s->faction; lua_pushfaction(L,lf); return 1; }
/** * @brief Returns the system's gfx_SunSpaceName. * * @usage name = sys:sunSpaceNames() * * @luaparam s System to get gfx_SunSpaceName of. * @luareturn The name of the system. * @luafunc name( s ) */ static int systemL_sunSpaceNames( lua_State *L ) { StarSystem *s; int i; s = luaL_validsystem(L,1); /* Push all stars. */ lua_newtable(L); for (i=0; i<s->ngfx_SunSpaceNames; i++) { lua_pushnumber(L,i+1); /* key, 1-based as normal in lua */ lua_pushstring(L,s->gfx_SunSpaceNames[i]); /* value */ lua_rawset(L,-3); } return 1; }
/** * @brief Returns the factions that have presence in a system and their respective presence values. * * @usage if sys:presences()["Empire"] then -- Checks to see if Empire has ships in the system * @usage if sys:presences()[faction.get("Pirate")] then -- Checks to see if the Pirates have ships in the system * * @luaparam s System to get the factional presences of. * @luareturn A table with the factions that have presence in the system. * @luafunc presences( s ) */ static int systemL_presences( lua_State *L ) { StarSystem *s; int i; s = luaL_validsystem(L,1); /* Return result in table */ lua_newtable(L); for (i=0; i<s->npresence; i++) { lua_pushstring( L, faction_name(s->presence[i].faction) ); /* t, k */ lua_pushnumber(L,s->presence[i].value); /* t, k, v */ lua_settable(L,-3); /* t */ /* allows syntax foo = system.presences(); if foo["bar"] then ... end */ } return 1; }
/** * @brief Gets all the adjacent systems to a system. * * @usage for _,s in ipairs( sys:adjacentSystems() ) do -- Iterate over adjacent systems. * * @luaparam s System to get adjacent systems of. * @luareturn An ordered table with all the adjacent systems. * @luafunc adjacentSystems( s ) */ static int systemL_adjacent( lua_State *L ) { int i; LuaSystem sysp; StarSystem *s; s = luaL_validsystem(L,1); /* Push all adjacent systems. */ lua_newtable(L); for (i=0; i<s->njumps; i++) { sysp.id = system_index( s->jumps[i].target ); lua_pushnumber(L,i+1); /* key. */ lua_pushsystem(L,sysp); /* value. */ lua_rawset(L,-3); } return 1; }
/** * @brief Gets the planets in a system. * * @usage for key, planet in ipairs( sys:planets() ) do -- Iterate over planets in system * @usage if #sys:planets() > 0 then -- System has planets * * @luatparam System s System to get planets of * @luatreturn {Planet,...} A table with all the planets * @luafunc planets( s ) */ static int systemL_planets( lua_State *L ) { int i, key; StarSystem *s; s = luaL_validsystem(L,1); /* Push all planets. */ lua_newtable(L); key = 0; for (i=0; i<s->nplanets; i++) { if(s->planets[i]->real == ASSET_REAL) { key++; lua_pushnumber(L,key); /* key */ lua_pushplanet(L,planet_index( s->planets[i] )); /* value */ lua_rawset(L,-3); } } return 1; }
/** * @brief Sets a system's known state. * * @usage s:setKnown( false ) -- Makes system unknown. * @luatparam System s System to set known. * @luatparam[opt=false] boolean b Whether or not to set as known. * @luatparam[opt=false] boolean r Whether or not to iterate over the system's assets and jump points. * @luafunc setKnown( s, b, r ) */ static int systemL_setknown( lua_State *L ) { int b, r, i; StarSystem *sys; NLUA_CHECKRW(L); r = 0; sys = luaL_validsystem(L, 1); b = lua_toboolean(L, 2); if (lua_gettop(L) > 2) r = lua_toboolean(L, 3); if (b) sys_setFlag( sys, SYSTEM_KNOWN ); else sys_rmFlag( sys, SYSTEM_KNOWN ); if (r) { if (b) { for (i=0; i < sys->nplanets; i++) planet_setKnown( sys->planets[i] ); for (i=0; i < sys->njumps; i++) jp_setFlag( &sys->jumps[i], JP_KNOWN ); } else { for (i=0; i < sys->nplanets; i++) planet_rmFlag( sys->planets[i], PLANET_KNOWN ); for (i=0; i < sys->njumps; i++) jp_rmFlag( &sys->jumps[i], JP_KNOWN ); } } /* Update outfits image array. */ outfits_updateEquipmentOutfits(); return 0; }
/** * @brief Teleports the player to a new planet or system (only if not landed). * * If the destination is a system, the coordinates of the player will not change. * If the destination is a planet, the player will be placed over that planet. * * @usage player.teleport( system.get("Arcanis") ) -- Teleports the player to Arcanis. * @usage player.teleport( "Arcanis" ) -- Teleports the player to Arcanis. * @usage player.teleport( "Dvaer Prime" ) -- Teleports the player to Dvaer, and relocates him to Dvaer Prime. * * @luaparam dest System or name of a system or planet or name of a planet to teleport the player to. * @luafunc teleport( dest ) */ static int playerL_teleport( lua_State *L ) { Planet *pnt; StarSystem *sys; const char *name, *pntname; /* Must not be landed. */ if (landed) NLUA_ERROR(L,"Can not teleport the player while landed!"); if (comm_isOpen()) NLUA_ERROR(L,"Can not teleport the player while the comm is open!"); if (player_isBoarded()) NLUA_ERROR(L,"Can not teleport the player while he is boarded!"); pnt = NULL; /* Get a system. */ if (lua_issystem(L,1)) { sys = luaL_validsystem(L,1); name = system_getIndex(sys->id)->name; } /* Get a planet. */ else if (lua_isplanet(L,1)) { pnt = luaL_validplanet(L,1); name = planet_getSystem( pnt->name ); if (name == NULL) { NLUA_ERROR( L, "Planet '%s' does not belong to a system..", pnt->name ); return 0; } } /* Get destination from string. */ else if (lua_isstring(L,1)) { name = lua_tostring(L,1); if (!system_exists( name )) { if (!planet_exists( name )) { NLUA_ERROR( L, "'%s' is not a valid teleportation target.", name ); return 0; } /* No system found, assume destination string is the name of a planet. */ pntname = name; name = planet_getSystem( name ); pnt = planet_get( pntname ); if (name == NULL) { NLUA_ERROR( L, "Planet '%s' does not belong to a system..", pntname ); return 0; } } } else NLUA_INVALID_PARAMETER(L); /* Check if system exists. */ if (!system_exists( name )) { NLUA_ERROR( L, "System '%s' does not exist.", name ); return 0; } /* Jump out hook is run first. */ hooks_run( "jumpout" ); /* Just in case remove hyperspace flags. */ pilot_rmFlag( player.p, PILOT_HYPERSPACE ); pilot_rmFlag( player.p, PILOT_HYP_BEGIN ); pilot_rmFlag( player.p, PILOT_HYP_BRAKE ); pilot_rmFlag( player.p, PILOT_HYP_PREP ); /* Free graphics. */ space_gfxUnload( cur_system ); /* Go to the new system. */ space_init( name ); /* Map gets deformed when jumping this way. */ map_clear(); /* Add the escorts. */ player_addEscorts(); /* Run hooks - order is important. */ hooks_run( "jumpin" ); hooks_run( "enter" ); events_trigger( EVENT_TRIGGER_ENTER ); missions_run( MIS_AVAIL_SPACE, -1, NULL, NULL ); /* Reset targets when teleporting */ player_targetPlanetSet( -1 ); player_targetHyperspaceSet( -1 ); gui_setNav(); /* Move to planet. */ if (pnt != NULL) vectcpy( &player.p->solid->pos, &pnt->pos ); return 0; }