/* * Method: GetGroundPosition * * Get latitude, longitude of a station on the ground or nil if this is an orbital station * * > latitude, longitude = station:GetGroundPosition() * * Returns: * * latitude - the latitude of the station in radians * longitude - the longitude of the station in radians * * Examples: * * > -- Get ground position of L.A. when starting on Earth * > local la = Game.player:GetDockedWith() * > local lat, long = la:GetGroundPosition() * > lat = math.rad2deg(lat) * > long = math.rad2deg(long) * * Availability: * * July 2013 * * Status: * * experimental */ static int l_spacestation_get_ground_position(lua_State *l) { SpaceStation *s = LuaObject<SpaceStation>::CheckFromLua(1); if (!s->IsGroundStation()) return 0; vector3d pos = s->GetPosition(); double latitude = atan2(pos.y, sqrt(pos.x*pos.x + pos.z * pos.z)); double longitude = atan2(pos.x, pos.z); lua_pushnumber(l, latitude); lua_pushnumber(l, longitude); return 2; }
/* * Function: SpawnShipParked * * Create a ship and place it in one of the given <SpaceStation's> parking spots. * * > ship = Space.SpawnShipParked(type, station) * * For orbital stations the parking spots are some distance from the door, out * of the path of ships entering and leaving the station. For group stations * the parking spots are directly above the station, usually some distance * away. * * Parameters: * * type - the name of the ship * * station - the <SpaceStation> to place the near * * Return: * * ship - a <Ship> object for the new ship, or nil if there was no space * inside the station * Availability: * * alpha 10 * * Status: * * experimental */ static int l_space_spawn_ship_parked(lua_State *l) { if (!Pi::game) luaL_error(l, "Game is not started"); LUA_DEBUG_START(l); const char *type = luaL_checkstring(l, 1); if (! ShipType::Get(type)) luaL_error(l, "Unknown ship type '%s'", type); SpaceStation *station = LuaObject<SpaceStation>::CheckFromLua(2); int slot; if (!station->AllocateStaticSlot(slot)) return 0; Ship *ship = new Ship(type); assert(ship); double parkDist = station->GetStationType()->parkingDistance; parkDist -= ship->GetPhysRadius(); // park inside parking radius double parkOffset = 0.5 * station->GetStationType()->parkingGapSize; parkOffset += ship->GetPhysRadius(); // but outside the docking gap double xpos = (slot == 0 || slot == 3) ? -parkOffset : parkOffset; double zpos = (slot == 0 || slot == 1) ? -parkOffset : parkOffset; vector3d parkPos = vector3d(xpos, parkDist, zpos); parkPos = station->GetPosition() + station->GetOrient() * parkPos; // orbital stations have Y as axis of rotation matrix3x3d rot = matrix3x3d::RotateX(M_PI/2) * station->GetOrient(); ship->SetFrame(station->GetFrame()); ship->SetVelocity(vector3d(0.0)); ship->SetPosition(parkPos); ship->SetOrient(rot); Pi::game->GetSpace()->AddBody(ship); ship->AIHoldPosition(); LuaObject<Ship>::PushToLua(ship); LUA_DEBUG_END(l, 1); return 1; }
/* * Function: SpawnShipParked * * Create a ship and place it in one of the given <SpaceStation's> parking spots. * * > ship = Space.SpawnShipParked(type, station) * * For orbital stations the parking spots are some distance from the door, out * of the path of ships entering and leaving the station. For group stations * the parking spots are directly above the station, usually some distance * away. * * Parameters: * * type - the name of the ship * * station - the <SpaceStation> to place the near * * Return: * * ship - a <Ship> object for the new ship, or nil if there was no space * inside the station * Availability: * * alpha 10 * * Status: * * experimental */ static int l_space_spawn_ship_parked(lua_State *l) { if (!Pi::game) luaL_error(l, "Game is not started"); LUA_DEBUG_START(l); const char *type = luaL_checkstring(l, 1); if (! ShipType::Get(type)) luaL_error(l, "Unknown ship type '%s'", type); SpaceStation *station = LuaSpaceStation::CheckFromLua(2); int slot; if (!station->AllocateStaticSlot(slot)) return 0; Ship *ship = new Ship(type); assert(ship); vector3d pos, vel; matrix4x4d rot = matrix4x4d::Identity(); if (station->GetSystemBody()->type == SystemBody::TYPE_STARPORT_SURFACE) { vel = vector3d(0.0); // XXX on tiny planets eg asteroids force this to be larger so the // are out of the docking path pos = station->GetPosition() * 1.1; station->GetRotMatrix(rot); vector3d axis1, axis2; axis1 = pos.Cross(vector3d(0.0,1.0,0.0)); axis2 = pos.Cross(axis1); double ang = atan((140 + ship->GetLmrCollMesh()->GetBoundingRadius()) / pos.Length()); if (slot<2) ang = -ang; vector3d axis = (slot == 0 || slot == 3) ? axis1 : axis2; pos.ArbRotate(axis, ang); } else { double dist = 100 + ship->GetLmrCollMesh()->GetBoundingRadius(); double xpos = (slot == 0 || slot == 3) ? -dist : dist; double zpos = (slot == 0 || slot == 1) ? -dist : dist; pos = vector3d(xpos,5000,zpos); vel = vector3d(0.0); rot.RotateX(M_PI/2); } ship->SetFrame(station->GetFrame()); ship->SetVelocity(vel); ship->SetPosition(pos); ship->SetRotMatrix(rot); Pi::game->GetSpace()->AddBody(ship); ship->AIHoldPosition(); LuaShip::PushToLua(ship); LUA_DEBUG_END(l, 1); return 1; }