Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show altitude and vertical speed even when farther away from planet #2446

Merged
merged 4 commits into from Oct 5, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion data/lang/English.txt
Expand Up @@ -1145,7 +1145,9 @@ IN_TRANSIT_TO_N_X_X_X
PROBABILITY_OF_ARRIVAL_X_PERCENT
Probability of arrival: %probability%%
ALT_IN_METRES
Alt: %altitude{f.0}m
Alt: %altitude{f.0}m (%vspeed{f.1}m/s)
ALT_IN_KM
Alt: %altitude{f.0}km (%vspeed{f.1}km/s)
PRESSURE_N_ATMOSPHERES
P: %pressure{f.2} atm
NO_HYPERDRIVE
Expand Down
1 change: 1 addition & 0 deletions src/LangStrings.inc.h
Expand Up @@ -570,6 +570,7 @@ DECLARE_STRING(IN_TRANSIT)
DECLARE_STRING(IN_TRANSIT_TO_N_X_X_X)
DECLARE_STRING(PROBABILITY_OF_ARRIVAL_X_PERCENT)
DECLARE_STRING(ALT_IN_METRES)
DECLARE_STRING(ALT_IN_KM)
DECLARE_STRING(PRESSURE_N_ATMOSPHERES)
DECLARE_STRING(NO_HYPERDRIVE)
DECLARE_STRING(MASS_N_TONNES)
Expand Down
2 changes: 1 addition & 1 deletion src/ShipCpanel.cpp
Expand Up @@ -216,7 +216,7 @@ void ShipCpanel::InitObject()
Add(m_overlay[OVERLAY_TOP_LEFT], 170.0f, 2.0f);
Add(m_overlay[OVERLAY_TOP_RIGHT], 500.0f, 2.0f);
Add(m_overlay[OVERLAY_BOTTOM_LEFT], 150.0f, 62.0f);
Add(m_overlay[OVERLAY_BOTTOM_RIGHT], 580.0f, 62.0f);
Add(m_overlay[OVERLAY_BOTTOM_RIGHT], 520.0f, 62.0f);

m_connOnDockingClearanceExpired =
Pi::onDockingClearanceExpired.connect(sigc::mem_fun(this, &ShipCpanel::OnDockingClearanceExpired));
Expand Down
58 changes: 39 additions & 19 deletions src/WorldView.cpp
Expand Up @@ -618,39 +618,59 @@ void WorldView::RefreshButtonStateAndVisibility()
Pi::cpan->SetOverlayText(ShipCpanel::OVERLAY_TOP_RIGHT, "");

// altitude
if (Pi::player->GetFrame()->GetBody() && Pi::player->GetFrame()->IsRotFrame()) {
Body *astro = Pi::player->GetFrame()->GetBody();
const Frame* frame = Pi::player->GetFrame();
if (frame->GetBody() && frame->GetBody()->IsType(Object::SPACESTATION))
frame = frame->GetParent();
if (frame && frame->GetBody() && frame->GetBody()->IsType(Object::TERRAINBODY) &&
(frame->HasRotFrame() || frame->IsRotFrame())) {
Body *astro = frame->GetBody();
//(GetFrame()->m_sbody->GetSuperType() == SUPERTYPE_ROCKY_PLANET)) {
double radius;
vector3d surface_pos = Pi::player->GetPosition().Normalized();
if (astro->IsType(Object::TERRAINBODY)) {
radius = static_cast<TerrainBody*>(astro)->GetTerrainHeight(surface_pos);
assert(astro->IsType(Object::TERRAINBODY));
TerrainBody* terrain = static_cast<TerrainBody*>(astro);
if (!frame->IsRotFrame())
frame = frame->GetRotFrame();
vector3d pos = (frame == Pi::player->GetFrame() ? Pi::player->GetPosition() : Pi::player->GetPositionRelTo(frame));
double center_dist = pos.Length();
// Avoid calculating terrain if we are too far anyway.
// This should rather be 1.5 * max_radius, but due to quirkses in terrain generation we must be generous.
if (center_dist <= 3.0 * terrain->GetMaxFeatureRadius()) {
vector3d surface_pos = pos.Normalized();
double radius = terrain->GetTerrainHeight(surface_pos);
double altitude = center_dist - radius;
if (altitude < 10000000.0 && altitude < 0.5 * radius) {
vector3d velocity = (frame == Pi::player->GetFrame() ? vel : Pi::player->GetVelocityRelTo(frame));
double vspeed = velocity.Dot(surface_pos);
if (fabs(vspeed) < 0.05) vspeed = 0.0; // Avoid alternating between positive/negative zero
if (altitude < 0) altitude = 0;
if (altitude >= 100000.0)
Pi::cpan->SetOverlayText(ShipCpanel::OVERLAY_BOTTOM_RIGHT, stringf(Lang::ALT_IN_KM, formatarg("altitude", altitude / 1000.0),
formatarg("vspeed", vspeed / 1000.0)));
else
Pi::cpan->SetOverlayText(ShipCpanel::OVERLAY_BOTTOM_RIGHT, stringf(Lang::ALT_IN_METRES, formatarg("altitude", altitude),
formatarg("vspeed", vspeed)));
} else {
Pi::cpan->SetOverlayText(ShipCpanel::OVERLAY_BOTTOM_RIGHT, "");
}
} else {
// XXX this is an improper use of GetBoundingRadius
// since it is not a surface radius
radius = astro->GetPhysRadius();
}
double altitude = Pi::player->GetPosition().Length() - radius;
if (altitude > 9999999.0 || astro->IsType(Object::SPACESTATION))
Pi::cpan->SetOverlayText(ShipCpanel::OVERLAY_BOTTOM_RIGHT, "");
else {
if (altitude < 0) altitude = 0;
Pi::cpan->SetOverlayText(ShipCpanel::OVERLAY_BOTTOM_RIGHT, stringf(Lang::ALT_IN_METRES, formatarg("altitude", altitude)));
}

if (astro->IsType(Object::PLANET)) {
double dist = Pi::player->GetPosition().Length();
double pressure, density;
reinterpret_cast<Planet*>(astro)->GetAtmosphericState(dist, &pressure, &density);

Pi::cpan->SetOverlayText(ShipCpanel::OVERLAY_BOTTOM_LEFT, stringf(Lang::PRESSURE_N_ATMOSPHERES, formatarg("pressure", pressure)));
reinterpret_cast<Planet*>(astro)->GetAtmosphericState(center_dist, &pressure, &density);

if (pressure > 0.001)
Pi::cpan->SetOverlayText(ShipCpanel::OVERLAY_BOTTOM_LEFT, stringf(Lang::PRESSURE_N_ATMOSPHERES, formatarg("pressure", pressure)));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this needs an else clause to clear the overlay text if the pressure is below the threshold.

else
Pi::cpan->SetOverlayText(ShipCpanel::OVERLAY_BOTTOM_LEFT, "");
if (Pi::player->GetHullTemperature() > 0.01) {
m_hudHullTemp->SetValue(float(Pi::player->GetHullTemperature()));
m_hudHullTemp->Show();
} else {
m_hudHullTemp->Hide();
}
} else {
Pi::cpan->SetOverlayText(ShipCpanel::OVERLAY_BOTTOM_LEFT, ""); // No atmosphere, no pressure
}
} else {
Pi::cpan->SetOverlayText(ShipCpanel::OVERLAY_BOTTOM_LEFT, "");
Expand Down