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); }
/* * 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; }
/* * 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->HasValidSystem()) lua_pushinteger(l, path->systemIndex); 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; }
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); }
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; }
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; } } }
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(); }
void SystemInfoView::SystemChanged(const SystemPath &path) { DeleteAllChildren(); m_tabs = 0; m_bodyIcons.clear(); if (!path.HasValidSystem()) return; m_system = StarSystem::cache->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; } 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::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; 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); } { 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); 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(); }