/** * @brief Teleports the player to a new system (only if not landed). * * Does not change the position nor velocity of the player.p, which will probably be wrong in the new system. * * @usage player.teleport( system.get("Arcanis") ) -- Teleports the player to arcanis. * @usage player.teleport( "Arcanis" ) -- Teleports the player to arcanis. * * @luaparam sys System or name of a system to teleport the player to. * @luafunc teleport( sys ) */ static int playerL_teleport( lua_State *L ) { LuaSystem *sys; const char *name; /* 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!"); /* Get a system. */ if (lua_issystem(L,1)) { sys = lua_tosystem(L,1); name = system_getIndex(sys->id)->name; } else if (lua_isstring(L,1)) name = lua_tostring(L,1); 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 ); /* Reset targets when teleporting */ player_targetPlanetSet( -1 ); player_targetHyperspaceSet( -1 ); gui_setNav(); 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; }