/* * Method: SystemOnly * * Derive a SystemPath that points to the whole system. * * > system_path = path:SystemOnly() * * Return: * * system_path - the SystemPath that represents just the system * * Availability: * * alpha 17 * * Status: * * stable */ static int l_sbodypath_system_only(lua_State *l) { SystemPath *path = LuaObject<SystemPath>::CheckFromLua(1); const SystemPath sysOnly(path->SystemOnly()); LuaObject<SystemPath>::PushToLua(sysOnly); return 1; }
void Game::CreatePlayer() { // XXX this should probably be in lua somewhere // XXX no really, it should. per system hacks? oh my. SystemPath startPath = m_space->GetStarSystem()->GetPath(); if (startPath.IsSameSystem(SystemPath(-2,1,90,0))) { // Lave m_player.Reset(new Player("cobra3")); m_player->m_equipment.Set(Equip::SLOT_ENGINE, 0, Equip::DRIVE_CLASS3); m_player->m_equipment.Set(Equip::SLOT_LASER, 0, Equip::PULSECANNON_1MW); m_player->m_equipment.Add(Equip::HYDROGEN, 2); m_player->m_equipment.Add(Equip::MISSILE_GUIDED); m_player->m_equipment.Add(Equip::MISSILE_GUIDED); m_player->m_equipment.Add(Equip::SCANNER); } else { m_player.Reset(new Player("eagle_lrf")); m_player->m_equipment.Set(Equip::SLOT_ENGINE, 0, Equip::DRIVE_CLASS1); m_player->m_equipment.Set(Equip::SLOT_LASER, 0, Equip::PULSECANNON_1MW); m_player->m_equipment.Add(Equip::HYDROGEN, 1); m_player->m_equipment.Add(Equip::ATMOSPHERIC_SHIELDING); m_player->m_equipment.Add(Equip::MISSILE_GUIDED); m_player->m_equipment.Add(Equip::MISSILE_GUIDED); m_player->m_equipment.Add(Equip::AUTOPILOT); m_player->m_equipment.Add(Equip::SCANNER); } m_player->UpdateStats(); m_player->SetMoney(10000); }
void SystemInfoView::UpdateIconSelections() { m_selectedBodyPath = SystemPath(); for (auto& bodyIcon : m_bodyIcons) { bodyIcon.second->SetSelected(false); RefCountedPtr<StarSystem> currentSys = Pi::game->GetSpace()->GetStarSystem(); if (currentSys && currentSys->GetPath() == m_system->GetPath()) { //navtarget can be only set in current system if (Body* navtarget = Pi::player->GetNavTarget()) { const SystemPath& navpath = navtarget->GetSystemBody()->GetPath(); if (bodyIcon.first == navpath.bodyIndex) { bodyIcon.second->SetSelectColor(Color(0, 255, 0, 255)); bodyIcon.second->SetSelected(true); m_selectedBodyPath = navpath; } } } else { SystemPath selected = Pi::sectorView->GetSelected(); if (selected.IsSameSystem(m_system->GetPath()) && !selected.IsSystemPath()) { if (bodyIcon.first == selected.bodyIndex) { bodyIcon.second->SetSelectColor(Color(64, 96, 255, 255)); bodyIcon.second->SetSelected(true); m_selectedBodyPath = selected; } } } } }
/* * Method: SectorOnly * * Derive a SystemPath that points to the whole sector. * * > sector_path = path:SectorOnly() * * Return: * * sector_path - the SystemPath that represents just the sector * * Availability: * * alpha 17 * * Status: * * stable */ static int l_sbodypath_sector_only(lua_State *l) { SystemPath *path = LuaObject<SystemPath>::CheckFromLua(1); if (path->IsSectorPath()) { return 1; } LuaObject<SystemPath>::PushToLua(path->SectorOnly()); return 1; }
/* * Method: IsSameSector * * Determine if two <SystemPath> objects point to objects in the same sector. * * > is_same = path:IsSameSector(otherpath) * * Parameters: * * otherpath - the <SystemPath> to compare with this path * * Return: * * is_same - true if the path's point to the same sector, false otherwise * * Availability: * * alpha 17 * * Status: * * stable */ static int l_sbodypath_is_same_sector(lua_State *l) { SystemPath *a = LuaObject<SystemPath>::CheckFromLua(1); SystemPath *b = LuaObject<SystemPath>::CheckFromLua(2); lua_pushboolean(l, a->IsSameSector(b)); return 1; }
/* * Method: IsSameSystem * * Determine if two <SystemPath> objects point to objects in the same system. * * > is_same = path:IsSameSystem(otherpath) * * Parameters: * * otherpath - the <SystemPath> to compare with this path * * Return: * * is_same - true if the path's point to the same system, false otherwise * * Availability: * * alpha 10 * * Status: * * stable */ static int l_sbodypath_is_same_system(lua_State *l) { SystemPath *a = LuaSystemPath::CheckFromLua(1); SystemPath *b = LuaSystemPath::CheckFromLua(2); lua_pushboolean(l, a->IsSameSystem(b)); return 1; }
/* * Attribute: bodyIndex * * The body index component of the path, or nil if the SystemPath does * not point to a body. * * Availability: * * alpha 10 * * Status: * * stable */ static int l_sbodypath_attr_body_index(lua_State *l) { SystemPath *path = LuaSystemPath::CheckFromLua(1); if (path->IsBodyPath()) lua_pushinteger(l, path->bodyIndex); else lua_pushnil(l); return 1; }
/* * Attribute: systemIndex * * The system index component of the path, or nil if the SystemPath does * not point to a system. * * Availability: * * alpha 10 * * Status: * * stable */ static int l_sbodypath_attr_system_index(lua_State *l) { SystemPath *path = LuaObject<SystemPath>::CheckFromLua(1); if (!path->IsSectorPath()) lua_pushinteger(l, path->systemIndex); else lua_pushnil(l); return 1; }
/* * Attribute: bodyIndex * * The body index component of the path, or nil if the SystemPath does * not point to a body. * * Availability: * * alpha 10 * * Status: * * stable */ static int l_sbodypath_attr_body_index(lua_State *l) { SystemPath *path = LuaObject<SystemPath>::CheckFromLua(1); if (path->HasValidBody()) lua_pushinteger(l, path->bodyIndex); else lua_pushnil(l); return 1; }
/* * Method: SystemOnly * * Derive a SystemPath that points to the whole system. * * > system_path = path:SystemOnly() * * Return: * * system_path - the SystemPath that represents just the system * * Availability: * * alpha 17 * * Status: * * stable */ static int l_sbodypath_system_only(lua_State *l) { SystemPath *path = LuaObject<SystemPath>::CheckFromLua(1); if (!path->HasValidSystem()) return luaL_error(l, "SystemPath:SystemOnly() self argument does not refer to a system"); if (path->IsSystemPath()) { return 1; } const SystemPath sysOnly(path->SystemOnly()); LuaObject<SystemPath>::PushToLua(sysOnly); return 1; }
static int l_get_hyperspace_target(lua_State *l) { LuaObject<Player>::CheckFromLua(1); if (Pi::game->IsNormalSpace()) { SystemPath sys = Pi::sectorView->GetHyperspaceTarget(); assert(sys.IsSystemPath()); LuaSystemPath::PushToLua(&sys); } else lua_pushnil(l); return 1; }
static float distance_to_system(const SystemPath &dest) { SystemPath here = Pi::game->GetSpace()->GetStarSystem()->GetPath(); assert(here.HasValidSystem()); assert(dest.HasValidSystem()); Sector sec1(here.sectorX, here.sectorY, here.sectorZ); Sector sec2(dest.sectorX, dest.sectorY, dest.sectorZ); return Sector::DistanceBetween(&sec1, here.systemIndex, &sec2, dest.systemIndex); }
static int l_set_hyperspace_target(lua_State *l) { LuaObject<Player>::CheckFromLua(1); if (Pi::game->IsNormalSpace()) { const SystemPath sys = *LuaObject<SystemPath>::CheckFromLua(2); if (!sys.IsSystemPath()) return luaL_error(l, "Player:SetHyperspaceTarget() -- second parameter is not a system path"); Pi::sectorView->SetHyperspaceTarget(sys); return 0; } else return luaL_error(l, "Player:SetHyperspaceTarget() cannot be used while in hyperspace"); }
static int l_get_hyperspace_target(lua_State *l) { Player *player = LuaObject<Player>::CheckFromLua(1); SystemPath target; if (Pi::game->IsNormalSpace()) target = Pi::sectorView->GetHyperspaceTarget(); else target = player->GetHyperspaceDest(); assert(target.IsSystemPath()); LuaObject<SystemPath>::PushToLua(target); return 1; }
/* * Method: GetStarSystem * * Get a <StarSystem> object for the system that this path points to * * > system = path:GetStarSystem() * * Return: * * system - the <StarSystem> * * Availability: * * alpha 10 * * Status: * * stable */ static int l_sbodypath_get_star_system(lua_State *l) { SystemPath *path = LuaObject<SystemPath>::CheckFromLua(1); if (path->IsSectorPath()) return luaL_error(l, "SystemPath:GetStarSystem() self argument does not refer to a system"); RefCountedPtr<StarSystem> s = Pi::game->GetGalaxy()->GetStarSystem(path); // LuaObject<StarSystem> shares ownership of the StarSystem, // because LuaAcquirer<LuaObject<StarSystem>> uses IncRefCount and DecRefCount LuaObject<StarSystem>::PushToLua(s.Get()); return 1; }
/* * Method: IsSameSystem * * Determine if two <SystemPath> objects point to objects in the same system. * * > is_same = path:IsSameSystem(otherpath) * * Parameters: * * otherpath - the <SystemPath> to compare with this path * * Return: * * is_same - true if the path's point to the same system, false otherwise * * Availability: * * alpha 10 * * Status: * * stable */ static int l_sbodypath_is_same_system(lua_State *l) { SystemPath *a = LuaObject<SystemPath>::CheckFromLua(1); SystemPath *b = LuaObject<SystemPath>::CheckFromLua(2); if (!a->HasValidSystem()) return luaL_error(l, "SystemPath:IsSameSystem() self argument does not refer to a system"); if (!b->HasValidSystem()) return luaL_error(l, "SystemPath:IsSameSystem() argument #1 does not refer to a system"); lua_pushboolean(l, a->IsSameSystem(b)); return 1; }
/* * Method: ParseString * * Parse a string and try to make a SystemPath from it * * > sector_path = SystemPath.Parse() * * Return: * * sector_path - the SystemPath that represents just the sector * * Availability: * * 2018-06-16 * * Status: * * experimental */ static int l_sbodypath_parse_string(lua_State *l) { std::string path = LuaPull<std::string>(l, 1); try { SystemPath syspath = SystemPath::Parse(path.c_str()); LuaObject<SystemPath>::PushToLua(syspath.SectorOnly()); return 1; } catch (SystemPath::ParseFailure pf) { return 0; } return 0; }
vector3d Space::GetHyperspaceExitPoint(const SystemPath &source) const { assert(m_starSystem); assert(source.IsSystemPath()); const SystemPath &dest = m_starSystem->GetPath(); Sector source_sec(source.sectorX, source.sectorY, source.sectorZ); Sector dest_sec(dest.sectorX, dest.sectorY, dest.sectorZ); Sector::System source_sys = source_sec.m_systems[source.systemIndex]; Sector::System dest_sys = dest_sec.m_systems[dest.systemIndex]; const vector3d sourcePos = vector3d(source_sys.p) + vector3d(source.sectorX, source.sectorY, source.sectorZ); const vector3d destPos = vector3d(dest_sys.p) + vector3d(dest.sectorX, dest.sectorY, dest.sectorZ); // find the first non-gravpoint. should be the primary star Body *primary = 0; for (BodyIterator i = BodiesBegin(); i != BodiesEnd(); ++i) if ((*i)->GetSystemBody()->type != SystemBody::TYPE_GRAVPOINT) { primary = *i; break; } assert(primary); // point along the line between source and dest, a reasonable distance // away based on the radius (don't want to end up inside black holes, and // then mix it up so that ships don't end up on top of each other vector3d pos = (sourcePos - destPos).Normalized() * (primary->GetSystemBody()->GetRadius()/AU+1.0)*11.0*AU*Pi::rng.Double(0.95,1.2) + MathUtil::RandomPointOnSphere(5.0,20.0)*1000.0; assert(pos.Length() > primary->GetSystemBody()->GetRadius()); return pos + primary->GetPositionRelTo(GetRootFrame()); }
static int l_sbodypath_meta_tostring(lua_State *l) { SystemPath *path = LuaObject<SystemPath>::CheckFromLua(1); if (path->IsSectorPath()) { lua_pushfstring(l, "<%d,%d,%d>", path->sectorX, path->sectorY, path->sectorZ); } else if (path->IsSystemPath()) { lua_pushfstring(l, "<%d,%d,%d : %d>", path->sectorX, path->sectorY, path->sectorZ, path->systemIndex); } else { assert(path->IsBodyPath()); lua_pushfstring(l, "<%d,%d,%d : %d, %d>", path->sectorX, path->sectorY, path->sectorZ, path->systemIndex, path->bodyIndex); } return 1; }
vector3d Space::GetHyperspaceExitPoint(const SystemPath &source, const SystemPath &dest) const { assert(m_starSystem); assert(source.IsSystemPath()); assert(dest.IsSameSystem(m_starSystem->GetPath())); RefCountedPtr<const Sector> source_sec = m_sectorCache->GetCached(source); RefCountedPtr<const Sector> dest_sec = m_sectorCache->GetCached(dest); Sector::System source_sys = source_sec->m_systems[source.systemIndex]; Sector::System dest_sys = dest_sec->m_systems[dest.systemIndex]; const vector3d sourcePos = vector3d(source_sys.GetPosition()) + vector3d(source.sectorX, source.sectorY, source.sectorZ); const vector3d destPos = vector3d(dest_sys.GetPosition()) + vector3d(dest.sectorX, dest.sectorY, dest.sectorZ); Body *primary = 0; if (dest.IsBodyPath()) { assert(dest.bodyIndex < m_starSystem->GetNumBodies()); primary = FindBodyForPath(&dest); while (primary && primary->GetSystemBody()->GetSuperType() != SystemBody::SUPERTYPE_STAR) { SystemBody* parent = primary->GetSystemBody()->GetParent(); primary = parent ? FindBodyForPath(&parent->GetPath()) : 0; } } if (!primary) { // find the first non-gravpoint. should be the primary star for (Body* b : GetBodies()) if (b->GetSystemBody()->GetType() != SystemBody::TYPE_GRAVPOINT) { primary = b; break; } } assert(primary); // point along the line between source and dest, a reasonable distance // away based on the radius (don't want to end up inside black holes, and // then mix it up so that ships don't end up on top of each other vector3d pos = (sourcePos - destPos).Normalized() * (primary->GetSystemBody()->GetRadius()/AU+1.0)*11.0*AU*Pi::rng.Double(0.95,1.2) + MathUtil::RandomPointOnSphere(5.0,20.0)*1000.0; assert(pos.Length() > primary->GetSystemBody()->GetRadius()); return pos + primary->GetPositionRelTo(GetRootFrame()); }
Ship::HyperjumpStatus Ship::CheckHyperspaceTo(const SystemPath &dest, int &outFuelRequired, double &outDurationSecs) { assert(dest.HasValidSystem()); outFuelRequired = 0; outDurationSecs = 0.0; if (GetFlightState() != FLYING) return HYPERJUMP_SAFETY_LOCKOUT; return GetHyperspaceDetails(dest, outFuelRequired, outDurationSecs); }
static int l_set_hyperspace_target(lua_State *l) { LuaObject<Player>::CheckFromLua(1); if (Pi::game->IsNormalSpace()) { const SystemPath path = *LuaObject<SystemPath>::CheckFromLua(2); if (!path.IsSystemPath()) { if (!path.IsBodyPath()) { return luaL_error(l, "Player:SetHyperspaceTarget() -- second parameter is not a system path or the path of a star"); } RefCountedPtr<StarSystem> sys = Pi::game->GetGalaxy()->GetStarSystem(path); // Lua should never be able to get an invalid SystemPath // (note: this may change if it becomes possible to remove systems during the game) assert(path.bodyIndex < sys->GetNumBodies()); SystemBody *sbody = sys->GetBodyByPath(path); if (!sbody->GetSuperType() == SystemBody::SUPERTYPE_STAR) return luaL_error(l, "Player:SetHyperspaceTarget() -- second parameter is not a system path or the path of a star"); } Pi::game->GetSectorView()->SetHyperspaceTarget(path); return 0; } else return luaL_error(l, "Player:SetHyperspaceTarget() cannot be used while in hyperspace"); }
Game::Game(const SystemPath &path, double time) : m_galaxy(GalaxyGenerator::Create()), m_time(time), m_state(STATE_NORMAL), m_wantHyperspace(false), m_timeAccel(TIMEACCEL_1X), m_requestedTimeAccel(TIMEACCEL_1X), m_forceTimeAccel(false) { // Now that we have a Galaxy, check the starting location if (!path.IsBodyPath()) throw InvalidGameStartLocation("SystemPath is not a body path"); RefCountedPtr<const Sector> s = m_galaxy->GetSector(path); if (size_t(path.systemIndex) >= s->m_systems.size()) { char buf[128]; std::sprintf(buf, "System %u in sector <%d,%d,%d> does not exist", unsigned(path.systemIndex), int(path.sectorX), int(path.sectorY), int(path.sectorZ)); throw InvalidGameStartLocation(std::string(buf)); } RefCountedPtr<StarSystem> sys = m_galaxy->GetStarSystem(path); if (path.bodyIndex >= sys->GetNumBodies()) { char buf[256]; std::sprintf(buf, "Body %d in system <%d,%d,%d : %d ('%s')> does not exist", unsigned(path.bodyIndex), int(path.sectorX), int(path.sectorY), int(path.sectorZ), unsigned(path.systemIndex), sys->GetName().c_str()); throw InvalidGameStartLocation(std::string(buf)); } m_space.reset(new Space(this, m_galaxy, path)); Body *b = m_space->FindBodyForPath(&path); assert(b); m_player.reset(new Player("kanara")); m_space->AddBody(m_player.get()); m_player->SetFrame(b->GetFrame()); if (b->GetType() == Object::SPACESTATION) { m_player->SetDockedWith(static_cast<SpaceStation*>(b), 0); } else { const SystemBody *sbody = b->GetSystemBody(); m_player->SetPosition(vector3d(0, 1.5*sbody->GetRadius(), 0)); m_player->SetVelocity(vector3d(0,0,0)); } Polit::Init(m_galaxy); CreateViews(); EmitPauseState(IsPaused()); }
/* * Method: GetSystemBody * * Get a <SystemBody> object for the body that this path points to * * > body = path:GetSystemBody() * * Return: * * body - the <SystemBody> * * Availability: * * alpha 10 * * Status: * * stable */ static int l_sbodypath_get_system_body(lua_State *l) { SystemPath *path = LuaObject<SystemPath>::CheckFromLua(1); if (path->IsSectorPath()) { luaL_error(l, "Path <%d,%d,%d> does not name a system or body", path->sectorX, path->sectorY, path->sectorZ); return 0; } RefCountedPtr<StarSystem> sys = Pi::game->GetGalaxy()->GetStarSystem(path); if (path->IsSystemPath()) { luaL_error(l, "Path <%d,%d,%d : %d ('%s')> does not name a body", path->sectorX, path->sectorY, path->sectorZ, path->systemIndex, sys->GetName().c_str()); return 0; } // Lua should never be able to get an invalid SystemPath // (note: this may change if it becomes possible to remove systems during the game) assert(path->bodyIndex < sys->GetNumBodies()); SystemBody *sbody = sys->GetBodyByPath(path); LuaObject<SystemBody>::PushToLua(sbody); return 1; }
Ship::HyperjumpStatus Ship::InitiateHyperjumpTo(const SystemPath &dest, int warmup_time, double duration, LuaRef checks) { if (!dest.HasValidSystem() || GetFlightState() != FLYING || warmup_time < 1) return HYPERJUMP_SAFETY_LOCKOUT; StarSystem *s = Pi::game->GetSpace()->GetStarSystem().Get(); if (s && s->GetPath().IsSameSystem(dest)) return HYPERJUMP_CURRENT_SYSTEM; m_hyperspace.dest = dest; m_hyperspace.countdown = warmup_time; m_hyperspace.now = false; m_hyperspace.duration = duration; m_hyperspace.checks = checks; return Ship::HYPERJUMP_OK; }
vector3d Space::GetHyperspaceExitPoint(const SystemPath &source) const { assert(m_starSystem); assert(source.IsSystemPath()); const SystemPath &dest = m_starSystem->GetPath(); Sector source_sec(source.sectorX, source.sectorY, source.sectorZ); Sector dest_sec(dest.sectorX, dest.sectorY, dest.sectorZ); Sector::System source_sys = source_sec.m_systems[source.systemIndex]; Sector::System dest_sys = dest_sec.m_systems[dest.systemIndex]; const vector3d sourcePos = vector3d(source_sys.p) + vector3d(source.sectorX, source.sectorY, source.sectorZ); const vector3d destPos = vector3d(dest_sys.p) + vector3d(dest.sectorX, dest.sectorY, dest.sectorZ); return (sourcePos - destPos).Normalized() * 11.0*AU + MathUtil::RandomPointOnSphere(5.0,20.0)*1000.0; // "hyperspace zone": 11 AU from primary }
Ship::HyperjumpStatus Ship::GetHyperspaceDetails(const SystemPath &dest, int &outFuelRequired, double &outDurationSecs) { assert(dest.HasValidSystem()); outFuelRequired = 0; outDurationSecs = 0.0; UpdateStats(); if (GetFlightState() == HYPERSPACE) return HYPERJUMP_DRIVE_ACTIVE; Equip::Type t = m_equipment.Get(Equip::SLOT_ENGINE); Equip::Type fuelType = GetHyperdriveFuelType(); int hyperclass = Equip::types[t].pval; int fuel = m_equipment.Count(Equip::SLOT_CARGO, fuelType); if (hyperclass == 0) return HYPERJUMP_NO_DRIVE; StarSystem *s = Pi::game->GetSpace()->GetStarSystem().Get(); if (s && s->GetPath().IsSameSystem(dest)) return HYPERJUMP_CURRENT_SYSTEM; float dist = distance_to_system(dest); outFuelRequired = Pi::CalcHyperspaceFuelOut(hyperclass, dist, m_stats.hyperspace_range_max); double m_totalmass = GetMass()/1000; if (dist > m_stats.hyperspace_range_max) { outFuelRequired = 0; return HYPERJUMP_OUT_OF_RANGE; } else if (fuel < outFuelRequired) { return HYPERJUMP_INSUFFICIENT_FUEL; } else { outDurationSecs = Pi::CalcHyperspaceDuration(hyperclass, m_totalmass, dist); if (outFuelRequired <= fuel) { return HYPERJUMP_OK; } else { return HYPERJUMP_INSUFFICIENT_FUEL; } } }
template <> void LuaObject<SystemPath>::PushToLua(const SystemPath &o) { lua_State *l = Lua::manager->GetLuaState(); // get the system path object cache if (!luaL_getsubtable(l, LUA_REGISTRYINDEX, "SystemPaths")) { lua_createtable(l, 0, 1); lua_pushliteral(l, "v"); lua_setfield(l, -2, "__mode"); lua_setmetatable(l, -2); } // stack: [SystemPaths] // push the system path as a blob to use as a key to look up the actual SystemPath object char key_blob[SystemPath::SizeAsBlob]; o.SerializeToBlob(key_blob); lua_pushlstring(l, key_blob, sizeof(key_blob)); // [SystemPaths key] lua_pushvalue(l, -1); // [SystemPaths key key] lua_rawget(l, -3); // [SystemPaths key value/nil] if (lua_isnil(l, -1)) { // [SystemPaths key nil] lua_pop(l, 1); // push a new Lua SystemPath object Register(new (LuaObjectBase::Allocate(sizeof(LuaCopyObject<SystemPath>))) LuaCopyObject<SystemPath>(o)); // store it in the SystemPaths cache, but keep a copy on the stack lua_pushvalue(l, -1); // [SystemPaths key value value] lua_insert(l, -4); // [value SystemPaths key value] lua_rawset(l, -3); // [value SystemPaths] lua_pop(l, 1); // [value] } else { // [SystemPaths key value] lua_insert(l, -3); // [value SystemPaths key] lua_pop(l, 2); // [value] } }
void SystemInfoView::SystemChanged(const SystemPath &path) { DeleteAllChildren(); m_tabs = 0; m_bodyIcons.clear(); if (!path.HasValidSystem()) return; m_system = StarSystemCache::GetCached(path); m_sbodyInfoTab = new Gui::Fixed(float(Gui::Screen::GetWidth()), float(Gui::Screen::GetHeight()-100)); if (m_system->GetUnexplored()) { Add(m_sbodyInfoTab, 0, 0); std::string _info = Lang::UNEXPLORED_SYSTEM_STAR_INFO_ONLY; Gui::Label *l = (new Gui::Label(_info))->Color(255,255,0); m_sbodyInfoTab->Add(l, 35, 300); m_selectedBodyPath = SystemPath(); ShowAll(); return; } m_econInfoTab = new Gui::Fixed(float(Gui::Screen::GetWidth()), float(Gui::Screen::GetHeight()-100)); Gui::Fixed *demographicsTab = new Gui::Fixed(); m_tabs = new Gui::Tabbed(); m_tabs->AddPage(new Gui::Label(Lang::PLANETARY_INFO), m_sbodyInfoTab); m_tabs->AddPage(new Gui::Label(Lang::ECONOMIC_INFO), m_econInfoTab); m_tabs->AddPage(new Gui::Label(Lang::DEMOGRAPHICS), demographicsTab); Add(m_tabs, 0, 0); m_sbodyInfoTab->onMouseButtonEvent.connect(sigc::mem_fun(this, &SystemInfoView::OnClickBackground)); int majorBodies, starports, onSurface; { float pos[2] = { 0, 0 }; float psize = -1; majorBodies = starports = onSurface = 0; PutBodies(m_system->GetRootBody().Get(), m_econInfoTab, 1, pos, majorBodies, starports, onSurface, psize); majorBodies = starports = onSurface = 0; pos[0] = pos[1] = 0; psize = -1; PutBodies(m_system->GetRootBody().Get(), m_sbodyInfoTab, 1, pos, majorBodies, starports, onSurface, psize); majorBodies = starports = onSurface = 0; pos[0] = pos[1] = 0; psize = -1; PutBodies(m_system->GetRootBody().Get(), demographicsTab, 1, pos, majorBodies, starports, onSurface, psize); } std::string _info = stringf( Lang::STABLE_SYSTEM_WITH_N_MAJOR_BODIES_STARPORTS, formatarg("bodycount", majorBodies), formatarg("body(s)", std::string(majorBodies == 1 ? Lang::BODY : Lang::BODIES)), formatarg("portcount", starports), formatarg("starport(s)", std::string(starports == 1 ? Lang::STARPORT : Lang::COUNT_STARPORTS))); if (starports > 0) _info += stringf(Lang::COUNT_ON_SURFACE, formatarg("surfacecount", onSurface)); _info += ".\n\n"; _info += m_system->GetLongDescription(); { // astronomical body info tab m_infoBox = new Gui::VBox(); Gui::HBox *scrollBox = new Gui::HBox(); scrollBox->SetSpacing(5); m_sbodyInfoTab->Add(scrollBox, 35, 250); Gui::VScrollBar *scroll = new Gui::VScrollBar(); Gui::VScrollPortal *portal = new Gui::VScrollPortal(730); scroll->SetAdjustment(&portal->vscrollAdjust); Gui::Label *l = (new Gui::Label(_info))->Color(255,255,0); m_infoBox->PackStart(l); portal->Add(m_infoBox); scrollBox->PackStart(scroll); scrollBox->PackStart(portal); } { // economy tab Gui::HBox *scrollBox2 = new Gui::HBox(); scrollBox2->SetSpacing(5); m_econInfoTab->Add(scrollBox2, 35, 300); Gui::VScrollBar *scroll2 = new Gui::VScrollBar(); Gui::VScrollPortal *portal2 = new Gui::VScrollPortal(730); scroll2->SetAdjustment(&portal2->vscrollAdjust); scrollBox2->PackStart(scroll2); scrollBox2->PackStart(portal2); m_econInfo = new Gui::Label(""); m_econInfoTab->Add(m_econInfo, 35, 250); Gui::Fixed *f = new Gui::Fixed(); m_econMajImport = new Gui::Label(""); m_econMinImport = new Gui::Label(""); m_econMajExport = new Gui::Label(""); m_econMinExport = new Gui::Label(""); m_econIllegal = new Gui::Label(""); m_econMajImport->Color(255,255,0); m_econMinImport->Color(255,255,0); m_econMajExport->Color(255,255,0); m_econMinExport->Color(255,255,0); m_econIllegal->Color(255,255,0); f->Add(m_econMajImport, 0, 0); f->Add(m_econMinImport, 150, 0); f->Add(m_econMajExport, 300, 0); f->Add(m_econMinExport, 450, 0); f->Add(m_econIllegal, 600, 0); portal2->Add(f); UpdateEconomyTab(); } { Gui::Fixed *col1 = new Gui::Fixed(); demographicsTab->Add(col1, 200, 300); Gui::Fixed *col2 = new Gui::Fixed(); demographicsTab->Add(col2, 400, 300); const float YSEP = Gui::Screen::GetFontHeight() * 1.2f; col1->Add((new Gui::Label(Lang::SYSTEM_TYPE))->Color(255,255,0), 0, 0); col2->Add(new Gui::Label(m_system->GetShortDescription()), 0, 0); col1->Add((new Gui::Label(Lang::GOVERNMENT_TYPE))->Color(255,255,0), 0, 2*YSEP); col2->Add(new Gui::Label(m_system->GetSysPolit().GetGovernmentDesc()), 0, 2*YSEP); col1->Add((new Gui::Label(Lang::ECONOMY_TYPE))->Color(255,255,0), 0, 3*YSEP); col2->Add(new Gui::Label(m_system->GetSysPolit().GetEconomicDesc()), 0, 3*YSEP); col1->Add((new Gui::Label(Lang::ALLEGIANCE))->Color(255,255,0), 0, 4*YSEP); col2->Add(new Gui::Label(m_system->GetFaction()->name.c_str()), 0, 4*YSEP); col1->Add((new Gui::Label(Lang::POPULATION))->Color(255,255,0), 0, 5*YSEP); std::string popmsg; fixed pop = m_system->GetTotalPop(); if (pop >= fixed(1,1)) { popmsg = stringf(Lang::OVER_N_BILLION, formatarg("population", pop.ToInt32())); } else if (pop >= fixed(1,1000)) { popmsg = stringf(Lang::OVER_N_MILLION, formatarg("population", (pop*1000).ToInt32())); } else if (pop != fixed(0)) { popmsg = Lang::A_FEW_THOUSAND; } else { popmsg = Lang::NO_REGISTERED_INHABITANTS; } col2->Add(new Gui::Label(popmsg), 0, 5*YSEP); col1->Add((new Gui::Label(Lang::SECTOR_COORDINATES))->Color(255,255,0), 0, 6*YSEP); col2->Add(new Gui::Label(stringf("%0{d}, %1{d}, %2{d}", path.sectorX, path.sectorY, path.sectorZ)), 0, 6*YSEP); col1->Add((new Gui::Label(Lang::SYSTEM_NUMBER))->Color(255,255,0), 0, 7*YSEP); col2->Add(new Gui::Label(stringf("%0", path.systemIndex)), 0, 7*YSEP); } UpdateIconSelections(); ShowAll(); }
static int l_sbodypath_is_system_path(lua_State *l) { SystemPath *path = LuaObject<SystemPath>::CheckFromLua(1); LuaPush(l, path->IsSystemPath()); return 1; }