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 energy production/consumption on Engineering Screen #1990

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/screens/crew6/engineeringScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ EngineeringScreen::EngineeringScreen(GuiContainer* owner, ECrewPosition crew_pos
my_spaceship->commandSetSystemPowerRequest(ESystem(n), value);
});
info.power_bar->setColor(glm::u8vec4(192, 192, 32, 128))->setSize(column_width, GuiElement::GuiSizeMax);
info.power_label = new GuiLabel(info.power_bar, id + "_POWER_LABEL", "...", 20);
info.power_label->setSize(GuiElement::GuiSizeMax, GuiElement::GuiSizeMax);
info.coolant_bar = new GuiProgressSlider(info.row, id + "_COOLANT", 0.0f, 10.0f, 0.0f, [this,n](float value){
if (my_spaceship)
my_spaceship->commandSetSystemCoolantRequest(ESystem(n), value);
Expand Down Expand Up @@ -252,6 +254,8 @@ void EngineeringScreen::onDraw(sp::RenderTarget& renderer)
info.heat_icon->hide();

info.power_bar->setValue(system.power_level);
info.power_label->setText(toNearbyIntString(my_spaceship->getNetSubsystemEnergyUsage(ESystem(n)) * -60.0f) + "/min");

info.coolant_bar->setValue(system.coolant_level);
if (system.coolant_request > 0.0f) {
float f = system.coolant_request / 10.f;
Expand Down
1 change: 1 addition & 0 deletions src/screens/crew6/engineeringScreen.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class EngineeringScreen : public GuiOverlay
GuiArrow* heat_arrow;
GuiImage* heat_icon;
GuiProgressSlider* power_bar;
GuiLabel* power_label;
GuiProgressSlider* coolant_bar;
GuiImage* coolant_max_indicator;
};
Expand Down
35 changes: 20 additions & 15 deletions src/spaceObjects/playerSpaceship.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1044,6 +1044,25 @@ void PlayerSpaceship::playSoundOnMainScreen(string sound_name)
broadcastServerCommand(packet);
}

float PlayerSpaceship::getNetSubsystemEnergyUsage(ESystem system)
{
if (!hasSystem(system)) return 0.0f;

// Factor the subsystem's health into energy generation.
auto power_user_factor = systems[system].getPowerUserFactor();
if (power_user_factor < 0)
{
float f = getSystemEffectiveness(system);
if (f > 1.0f)
f = (1.0f + f) / 2.0f;
return power_user_factor * f;
}
else
{
return power_user_factor * systems[system].power_level;
}
}

float PlayerSpaceship::getNetSystemEnergyUsage()
{
// Get the net delta of energy draw for subsystems.
Expand All @@ -1052,23 +1071,9 @@ float PlayerSpaceship::getNetSystemEnergyUsage()
// Determine each subsystem's energy draw.
for(int n = 0; n < SYS_COUNT; n++)
{

if (!hasSystem(ESystem(n))) continue;

const auto& system = systems[n];
// Factor the subsystem's health into energy generation.
auto power_user_factor = system.getPowerUserFactor();
if (power_user_factor < 0)
{
float f = getSystemEffectiveness(ESystem(n));
if (f > 1.0f)
f = (1.0f + f) / 2.0f;
net_power -= power_user_factor * f;
}
else
{
net_power -= power_user_factor * system.power_level;
}
net_power -= getNetSubsystemEnergyUsage(ESystem(n));
}

// Return the net subsystem energy draw.
Expand Down
1 change: 1 addition & 0 deletions src/spaceObjects/playerSpaceship.h
Original file line number Diff line number Diff line change
Expand Up @@ -315,6 +315,7 @@ class PlayerSpaceship : public SpaceShip
// Call on the server to play a sound on the main screen.
void playSoundOnMainScreen(string sound_name);

float getNetSubsystemEnergyUsage(ESystem system);
float getNetSystemEnergyUsage();

// Ship's log functions
Expand Down