From c63c378597dddf1bf967d7a4fddca962dfdb1639 Mon Sep 17 00:00:00 2001 From: Valentin Perrelle Date: Wed, 28 Jun 2023 05:05:04 +0200 Subject: [PATCH] Show energy production/consumption on Engineering Screen --- src/screens/crew6/engineeringScreen.cpp | 4 +++ src/screens/crew6/engineeringScreen.h | 1 + src/spaceObjects/playerSpaceship.cpp | 35 ++++++++++++++----------- src/spaceObjects/playerSpaceship.h | 1 + 4 files changed, 26 insertions(+), 15 deletions(-) diff --git a/src/screens/crew6/engineeringScreen.cpp b/src/screens/crew6/engineeringScreen.cpp index cd5764d8cd..60599419d5 100644 --- a/src/screens/crew6/engineeringScreen.cpp +++ b/src/screens/crew6/engineeringScreen.cpp @@ -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); @@ -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; diff --git a/src/screens/crew6/engineeringScreen.h b/src/screens/crew6/engineeringScreen.h index 28fb108132..2c2ed3f33b 100644 --- a/src/screens/crew6/engineeringScreen.h +++ b/src/screens/crew6/engineeringScreen.h @@ -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; }; diff --git a/src/spaceObjects/playerSpaceship.cpp b/src/spaceObjects/playerSpaceship.cpp index 9e93466e6d..cc9a5e8b11 100644 --- a/src/spaceObjects/playerSpaceship.cpp +++ b/src/spaceObjects/playerSpaceship.cpp @@ -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. @@ -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. diff --git a/src/spaceObjects/playerSpaceship.h b/src/spaceObjects/playerSpaceship.h index f691272a09..6b2c6a1219 100644 --- a/src/spaceObjects/playerSpaceship.h +++ b/src/spaceObjects/playerSpaceship.h @@ -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