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; } } } } }
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); }
/* * 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); lua_pushboolean(l, a->IsSameSystem(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 = 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; }
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()); }
void SectorView::UpdateSystemLabels(SystemLabels &labels, const SystemPath &path) { PROFILE_SCOPED() Sector *sec = GetCached(path.sectorX, path.sectorY, path.sectorZ); Sector *playerSec = GetCached(m_current.sectorX, m_current.sectorY, m_current.sectorZ); char format[256]; if (m_inSystem) { const float dist = Sector::DistanceBetween(sec, path.systemIndex, playerSec, m_current.systemIndex); int fuelRequired; double dur; enum Ship::HyperjumpStatus jumpStatus = Pi::player->GetHyperspaceDetails(&path, fuelRequired, dur); const double DaysNeeded = dur*(1.0 / (24*60*60)); const double HoursNeeded = (DaysNeeded - floor(DaysNeeded))*24; switch (jumpStatus) { case Ship::HYPERJUMP_OK: snprintf(format, sizeof(format), "[ %s | %s | %s, %s ]", Lang::NUMBER_LY, Lang::NUMBER_TONNES, Lang::NUMBER_DAYS, Lang::NUMBER_HOURS); labels.distance->SetText(stringf(format, formatarg("distance", dist), formatarg("mass", fuelRequired), formatarg("days", floor(DaysNeeded)), formatarg("hours", HoursNeeded))); labels.distance->Color(0, 255, 51); m_jumpLine.SetColor(Color(0, 255, 51, 255)); break; case Ship::HYPERJUMP_INSUFFICIENT_FUEL: snprintf(format, sizeof(format), "[ %s | %s ]", Lang::NUMBER_LY, Lang::NUMBER_TONNES); labels.distance->SetText(stringf(format, formatarg("distance", dist), formatarg("mass", fuelRequired))); labels.distance->Color(255, 255, 0); m_jumpLine.SetColor(Color::YELLOW); break; case Ship::HYPERJUMP_OUT_OF_RANGE: snprintf(format, sizeof(format), "[ %s ]", Lang::NUMBER_LY); labels.distance->SetText(stringf(format, formatarg("distance", dist))); labels.distance->Color(255, 0, 0); m_jumpLine.SetColor(Color::RED); break; default: labels.distance->SetText(""); break; } } else if (path.IsSameSystem(Pi::player->GetHyperspaceDest())) { snprintf(format, sizeof(format), "[ %s ]", Lang::IN_TRANSIT); labels.distance->SetText(format); labels.distance->Color(102, 102, 255); } else labels.distance->SetText(""); RefCountedPtr<StarSystem> sys = StarSystem::GetCached(path); std::string desc; if (sys->GetNumStars() == 4) { desc = Lang::QUADRUPLE_SYSTEM; } else if (sys->GetNumStars() == 3) { desc = Lang::TRIPLE_SYSTEM; } else if (sys->GetNumStars() == 2) { desc = Lang::BINARY_SYSTEM; } else { desc = sys->rootBody->GetAstroDescription(); } labels.starType->SetText(desc); labels.systemName->SetText(sys->GetName()); labels.shortDesc->SetText(sys->GetShortDescription()); if (m_detailBoxVisible == DETAILBOX_INFO) m_infoBox->ShowAll(); }