Skip to content

Commit

Permalink
Fix some things with regards to the sector map
Browse files Browse the repository at this point in the history
- clear route strings when enging the game, otherwise, when the game
restarts, a segfault occurs

- it turns out that a hyper jump is possible not only to the stars, but
also to the "substellar objects", but they do not return in the method
GetStars. Since a specific body should be shown in the route planner,
implemented an additional method GetJumpable, that gets all the bodies
available for jumping (IsJumpable == true), and this is synchronized
with what you can click in the systeminfo view

- also I had to change the route check, now it’s not the star index that
is checked, but just the path (this check is performed for multisystems,
so that only the specific body that registered in the route is always
selected)

- remove method SectorView::SwapSelectedHyperspaceTarget, because it is
not used anywhere

- clang satisfaction
  • Loading branch information
Gliese852 committed Jul 4, 2020
1 parent 2b0d15b commit 74f0d2a
Show file tree
Hide file tree
Showing 7 changed files with 61 additions and 58 deletions.
7 changes: 7 additions & 0 deletions data/pigui/modules/hyperjump-planner.lua
Original file line number Diff line number Diff line change
Expand Up @@ -361,4 +361,11 @@ function hyperJumpPlanner.onEnterSystem(ship)
updateHyperspaceTarget()
end

function hyperJumpPlanner.onGameEnd(ship)
-- clear the route out so it doesn't show up if the user starts a new game
sectorView:ClearRoute()
-- also clear the route list, saved in this module
buildJumpRouteList()
end

return hyperJumpPlanner
8 changes: 2 additions & 6 deletions data/pigui/modules/map-sector-view.lua
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ function Windows.systemInfo.Show()
ui.separator()
ui.text(jumpData)
ui.separator()
local stars = starsystem:GetStars()
local stars = starsystem:GetJumpable()
for _,star in pairs(stars) do
if ui.selectable(star.name, star.path == systempath, {}) then
clicked = star.path
Expand Down Expand Up @@ -416,11 +416,7 @@ Event.Register("onLeaveSystem", function()
hyperspaceDetailsCache = {}
end)
-- events moved from hyperJumpPlanner
Event.Register("onGameEnd",
function(ship)
-- clear the route out so it doesn't show up if the user starts a new game
sectorView:ClearRoute()
end)
Event.Register("onGameEnd", hyperJumpPlanner.onGameEnd)
Event.Register("onEnterSystem", hyperJumpPlanner.onEnterSystem)
Event.Register("onShipEquipmentChanged", hyperJumpPlanner.onShipEquipmentChanged)

Expand Down
32 changes: 8 additions & 24 deletions src/SectorView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ void SectorView::SetSelected(const SystemPath &path)
m_selected = path;
else if (path.IsSystemPath()) {
RefCountedPtr<StarSystem> system = m_galaxy->GetStarSystem(path);
m_selected = system->GetStars()[CheckIndexInRoute(path)]->GetPath();
m_selected = CheckPathInRoute(system->GetStars()[0]->GetPath());
}
}

Expand All @@ -378,34 +378,18 @@ void SectorView::SwitchToPath(const SystemPath &path)
GotoSystem(path);
}

void SectorView::SwapSelectedHyperspaceTarget()
{
SystemPath tmpTarget = GetHyperspaceTarget();
SetHyperspaceTarget(GetSelected());
if (m_automaticSystemSelection) {
GotoSystem(tmpTarget);
} else {
RefCountedPtr<StarSystem> system = m_galaxy->GetStarSystem(tmpTarget);
SetSelected(system->GetStars()[CheckIndexInRoute(tmpTarget)]->GetPath());
}
}

void SectorView::OnClickSystem(const SystemPath &path)
{
SwitchToPath(path);
}

// check the route, maybe this system is there, then we'll take star number from there
// if single system, bodyindex = 0; if multisystem, bodyindex = (0 or 1),2 ...
int SectorView::CheckIndexInRoute(const SystemPath &path)
// check the route, maybe this system is there, then we'll take the path from the route
const SystemPath &SectorView::CheckPathInRoute(const SystemPath &path)
{
for (auto &p : m_route)
if (p.IsSameSystem(path)) {
if (p.bodyIndex > 0)
return p.bodyIndex - 1;
return 0;
}
return 0;
for (const auto &p : m_route)
if (p.IsSameSystem(path))
return p;
return path;
}

void SectorView::PutSystemLabels(RefCountedPtr<Sector> sec, const vector3f &origin, int drawRadius)
Expand Down Expand Up @@ -1160,7 +1144,7 @@ void SectorView::Update()

if (!m_selected.IsSameSystem(new_selected)) {
RefCountedPtr<StarSystem> system = m_galaxy->GetStarSystem(new_selected);
SetSelected(system->GetStars()[CheckIndexInRoute(new_selected)]->GetPath());
SetSelected(CheckPathInRoute(system->GetStars()[0]->GetPath()));
}
}
}
Expand Down
3 changes: 1 addition & 2 deletions src/SectorView.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@ class SectorView : public UIView, public DeleteEmitter {
void GotoCurrentSystem() { GotoSystem(m_current); }
void GotoSelectedSystem() { GotoSystem(m_selected); }
void GotoHyperspaceTarget() { GotoSystem(m_hyperspaceTarget); }
void SwapSelectedHyperspaceTarget();
bool IsCenteredOn(const SystemPath &path);
void SaveToJson(Json &jsonObj) override;

Expand Down Expand Up @@ -131,7 +130,7 @@ class SectorView : public UIView, public DeleteEmitter {
void AddStarBillboard(const matrix4x4f &modelview, const vector3f &pos, const Color &col, float size);

void OnClickSystem(const SystemPath &path);
int CheckIndexInRoute(const SystemPath &path);
const SystemPath &CheckPathInRoute(const SystemPath &path);

RefCountedPtr<Sector> GetCached(const SystemPath &loc) { return m_sectorCache->GetCached(loc); }
void ShrinkCache();
Expand Down
2 changes: 1 addition & 1 deletion src/SystemInfoView.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ void SystemInfoView::OnBodySelected(SystemBody *b)
Body *body = m_game->GetSpace()->FindBodyForPath(&path);
if (body != 0)
Pi::player->SetNavTarget(body);
} else if (b->GetSuperType() == SystemBody::SUPERTYPE_STAR) { // We allow hyperjump to any star of the system
} else if (b->IsJumpable()) {
m_game->GetSectorView()->SwitchToPath(path);
}
}
Expand Down
52 changes: 27 additions & 25 deletions src/galaxy/SystemBody.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,22 +52,22 @@ class SystemBody : public RefCounted {
TYPE_STAR_A_HYPER_GIANT = 28,
TYPE_STAR_B_HYPER_GIANT = 29,
TYPE_STAR_O_HYPER_GIANT = 30, // these various stars do exist = they are transitional states and are rare
TYPE_STAR_M_WF = 31, //Wolf-Rayet star
TYPE_STAR_B_WF = 32, // while you do not specifically get class M,B or O WF stars,
TYPE_STAR_O_WF = 33, // you do get red = blue and purple from the colour of the gasses = so spectral class is an easy way to define them.
TYPE_STAR_S_BH = 34, //stellar blackhole
TYPE_STAR_IM_BH = 35, //Intermediate-mass blackhole
TYPE_STAR_SM_BH = 36, //Supermassive blackhole
TYPE_STAR_M_WF = 31, //Wolf-Rayet star
TYPE_STAR_B_WF = 32, // while you do not specifically get class M,B or O WF stars,
TYPE_STAR_O_WF = 33, // you do get red = blue and purple from the colour of the gasses = so spectral class is an easy way to define them.
TYPE_STAR_S_BH = 34, //stellar blackhole
TYPE_STAR_IM_BH = 35, //Intermediate-mass blackhole
TYPE_STAR_SM_BH = 36, //Supermassive blackhole
TYPE_PLANET_GAS_GIANT = 37,
TYPE_PLANET_ASTEROID = 38,
TYPE_PLANET_TERRESTRIAL = 39,
TYPE_STARPORT_ORBITAL = 40,
TYPE_STARPORT_SURFACE = 41,
TYPE_MIN = TYPE_BROWN_DWARF, // <enum skip>
TYPE_MIN = TYPE_BROWN_DWARF, // <enum skip>
TYPE_MAX = TYPE_STARPORT_SURFACE, // <enum skip>
TYPE_STAR_MIN = TYPE_BROWN_DWARF, // <enum skip>
TYPE_STAR_MAX = TYPE_STAR_SM_BH, // <enum skip>
// XXX need larger atmosphereless thing
TYPE_STAR_MAX = TYPE_STAR_SM_BH, // <enum skip>
// XXX need larger atmosphereless thing
};

enum BodySuperType { // <enum scope='SystemBody' prefix=SUPERTYPE_ public>
Expand All @@ -83,6 +83,8 @@ class SystemBody : public RefCounted {

bool IsPlanet() const;
bool IsMoon() const { return GetSuperType() == SUPERTYPE_ROCKY_PLANET && !IsPlanet(); }
// We allow hyperjump to any star of the system
bool IsJumpable() const { return GetSuperType() == SUPERTYPE_STAR; }

bool HasChildren() const { return !m_children.empty(); }
Uint32 GetNumChildren() const { return static_cast<Uint32>(m_children.size()); }
Expand All @@ -98,7 +100,7 @@ class SystemBody : public RefCounted {
BodySuperType GetSuperType() const;
bool IsCustomBody() const { return m_isCustomBody; }
bool IsCoOrbitalWith(const SystemBody *other) const; //this and other form a binary pair
bool IsCoOrbital() const; //is part of any binary pair
bool IsCoOrbital() const; //is part of any binary pair
fixed GetRadiusAsFixed() const { return m_radius; }

// the aspect ratio adjustment is converting from equatorial to polar radius to account for ellipsoid bodies, used for calculating terrains etc
Expand Down Expand Up @@ -228,38 +230,38 @@ class SystemBody : public RefCounted {

void ClearParentAndChildPointers();

SystemBody *m_parent; // these are only valid if the StarSystem
SystemBody *m_parent; // these are only valid if the StarSystem
std::vector<SystemBody *> m_children; // that create them still exists

SystemPath m_path;
Orbit m_orbit;
Uint32 m_seed; // Planet.cpp can use to generate terrain
std::string m_name;
fixed m_radius; // in earth radii for planets, sol radii for stars. equatorial radius in case of bodies which are flattened at the poles
fixed m_aspectRatio; // ratio between equatorial and polar radius for bodies with eqatorial bulges
fixed m_mass; // earth masses if planet, solar masses if star
fixed m_orbMin, m_orbMax; // periapsism, apoapsis in AUs
fixed m_rotationPeriod; // in days
fixed m_radius; // in earth radii for planets, sol radii for stars. equatorial radius in case of bodies which are flattened at the poles
fixed m_aspectRatio; // ratio between equatorial and polar radius for bodies with eqatorial bulges
fixed m_mass; // earth masses if planet, solar masses if star
fixed m_orbMin, m_orbMax; // periapsism, apoapsis in AUs
fixed m_rotationPeriod; // in days
fixed m_rotationalPhaseAtStart; // 0 to 2 pi
fixed m_humanActivity; // 0 - 1
fixed m_semiMajorAxis; // in AUs
fixed m_humanActivity; // 0 - 1
fixed m_semiMajorAxis; // in AUs
fixed m_eccentricity;
fixed m_orbitalOffset;
fixed m_orbitalPhaseAtStart; // 0 to 2 pi
fixed m_axialTilt; // in radians
fixed m_inclination; // in radians, for surface bodies = latitude
fixed m_axialTilt; // in radians
fixed m_inclination; // in radians, for surface bodies = latitude
int m_averageTemp;
BodyType m_type;
bool m_isCustomBody;

/* composition */
fixed m_metallicity; // (crust) 0.0 = light (Al, SiO2, etc), 1.0 = heavy (Fe, heavy metals)
fixed m_volatileGas; // 1.0 = earth atmosphere density
fixed m_metallicity; // (crust) 0.0 = light (Al, SiO2, etc), 1.0 = heavy (Fe, heavy metals)
fixed m_volatileGas; // 1.0 = earth atmosphere density
fixed m_volatileLiquid; // 1.0 = 100% ocean cover (earth = 70%)
fixed m_volatileIces; // 1.0 = 100% ice cover (earth = 3%)
fixed m_volcanicity; // 0 = none, 1.0 = fucking volcanic
fixed m_volatileIces; // 1.0 = 100% ice cover (earth = 3%)
fixed m_volcanicity; // 0 = none, 1.0 = fucking volcanic
fixed m_atmosOxidizing; // 0.0 = reducing (H2, NH3, etc), 1.0 = oxidising (CO2, O2, etc)
fixed m_life; // 0.0 = dead, 1.0 = teeming
fixed m_life; // 0.0 = dead, 1.0 = teeming

RingStyle m_rings;

Expand Down
15 changes: 15 additions & 0 deletions src/lua/LuaStarSystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,20 @@ static int l_starsystem_get_stars(lua_State *l)
return 1;
}

static int l_starsystem_get_jumpable(lua_State *l)
{
const StarSystem *s = LuaObject<StarSystem>::CheckFromLua(1);
lua_newtable(l);
int i = 1;
for (RefCountedPtr<SystemBody> sb : s->GetBodies())
if (sb->IsJumpable()) {
lua_pushnumber(l, i++);
LuaObject<SystemBody>::PushToLua(sb.Get());
lua_settable(l, -3);
}
return 1;
}

/*
* Method: DistanceTo
*
Expand Down Expand Up @@ -647,6 +661,7 @@ void LuaObject<StarSystem>::RegisterClass()
{ "GetStationPaths", l_starsystem_get_station_paths },
{ "GetBodyPaths", l_starsystem_get_body_paths },
{ "GetStars", l_starsystem_get_stars },
{ "GetJumpable", l_starsystem_get_jumpable },

{ "GetCommodityBasePriceAlterations", l_starsystem_get_commodity_base_price_alterations },
{ "IsCommodityLegal", l_starsystem_is_commodity_legal },
Expand Down

0 comments on commit 74f0d2a

Please sign in to comment.