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
  • Loading branch information
Gliese852 committed Jul 4, 2020
1 parent 2b0d15b commit cb3f5a9
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 33 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
2 changes: 2 additions & 0 deletions src/galaxy/SystemBody.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 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 cb3f5a9

Please sign in to comment.