Skip to content
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
562 changes: 362 additions & 200 deletions src/screens/crew6/engineeringScreen.cpp

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions src/screens/crew6/engineeringScreen.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ class EngineeringScreen : public GuiOverlay
GuiSlider* power_slider;
GuiLabel* coolant_label;
GuiSlider* coolant_slider;
GuiImage* system_health_icon;
GuiImage* heat_icon;
GuiProgressbar* coolant_remaining_bar;

class SystemRow
Expand Down
51 changes: 38 additions & 13 deletions src/screens/extra/powerManagement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ PowerManagementScreen::PowerManagementScreen(GuiContainer* owner)
coolant_display->setIcon("gui/icons/coolant")->setTextSize(20)->setPosition(315, 20, sp::Alignment::TopLeft)->setSize(280, 40);
GuiElement* layout = new GuiElement(this, "");
layout->setPosition(20, 60, sp::Alignment::TopLeft)->setSize(GuiElement::GuiSizeMax, 400)->setAttribute("layout", "horizontal");
for(int n=0; n<ShipSystem::COUNT; n++)
for (int n = 0; n < ShipSystem::COUNT; n++)
{
if (n == 4)
{
Expand All @@ -40,8 +40,18 @@ PowerManagementScreen::PowerManagementScreen(GuiContainer* owner)

(new GuiLabel(box, "", getLocaleSystemName(ShipSystem::Type(n)), 30))->addBackground()->setAlignment(sp::Alignment::Center)->setPosition(0, 0, sp::Alignment::TopLeft)->setSize(290, 50);
(new GuiLabel(box, "", tr("button", "Power"), 30))->setVertical()->setAlignment(sp::Alignment::CenterLeft)->setPosition(20, 50, sp::Alignment::TopLeft)->setSize(30, 340);
(new GuiLabel(box, "", tr("button", "Coolant"), 30))->setVertical()->setAlignment(sp::Alignment::CenterLeft)->setPosition(100, 50, sp::Alignment::TopLeft)->setSize(30, 340);
(new GuiLabel(box, "", tr("button", "Heat"), 30))->setVertical()->setAlignment(sp::Alignment::CenterLeft)->setPosition(180, 50, sp::Alignment::TopLeft)->setSize(30, 340);
systems[n].coolant_label = new GuiLabel(box, "", tr("button", "Coolant"), 30.0f);
systems[n].coolant_label
->setVertical()
->setAlignment(sp::Alignment::CenterLeft)
->setPosition(100.0f, 50.0f, sp::Alignment::TopLeft)
->setSize(30.0f, 340.0f);
systems[n].heat_label = new GuiLabel(box, "", tr("button", "Heat"), 30.0f);
systems[n].heat_label
->setVertical()
->setAlignment(sp::Alignment::CenterLeft)
->setPosition(180.0f, 50.0f, sp::Alignment::TopLeft)
->setSize(30.0f, 340.0f);

systems[n].power_bar = new GuiProgressbar(box, "", 0.0, 3.0, 1.0);
systems[n].power_bar->setDrawBackground(false)->setPosition(52.5, 60, sp::Alignment::TopLeft)->setSize(50, 320);
Expand Down Expand Up @@ -79,6 +89,8 @@ void PowerManagementScreen::onDraw(sp::RenderTarget& renderer)
{
auto reactor = my_spaceship.getComponent<Reactor>();
auto coolant = my_spaceship.getComponent<Coolant>();
float power_max = (reactor || coolant) ? 3.0f : 1.0f;

if (reactor) {
//Update the energy usage.
if (previous_energy_measurement == 0.0f)
Expand Down Expand Up @@ -107,20 +119,33 @@ void PowerManagementScreen::onDraw(sp::RenderTarget& renderer)
{
auto sys = ShipSystem::get(my_spaceship, ShipSystem::Type(n));
systems[n].box->setVisible(sys);
if (sys) {
systems[n].power_slider->setValue(sys->power_request);
if (sys)
{
// Power
systems[n].power_slider
->setRange(power_max, 0.0f) // Backward order for rotated slider
->setValue(sys->power_request);
systems[n].power_bar
->setRange(0.0f, power_max)
->setValue(sys->power_level)
->setColor(glm::u8vec4(255, 255, 0, 255));

// Heat and coolant
systems[n].coolant_slider->setVisible(coolant);
if (coolant) {
systems[n].coolant_bar->setVisible(coolant);
systems[n].coolant_label->setVisible(coolant);
systems[n].heat_bar->setVisible(coolant);
systems[n].heat_label->setVisible(coolant);
if (coolant)
{
systems[n].coolant_slider->setValue(std::min(sys->coolant_request, coolant->max));
systems[n].coolant_slider->setEnable(!coolant->auto_levels);
}

float heat = sys->heat_level;
float power = sys->power_level;
float coolant = sys->coolant_level;
systems[n].heat_bar->setValue(heat)->setColor(glm::u8vec4(128, 128 * (1.0f - heat), 0, 255));
systems[n].power_bar->setValue(power)->setColor(glm::u8vec4(255, 255, 0, 255));
systems[n].coolant_bar->setValue(coolant)->setColor(glm::u8vec4(0, 128, 255, 255));
float heat = sys->heat_level;
float coolant = sys->coolant_level;
systems[n].heat_bar->setValue(heat)->setColor(glm::u8vec4(128, 128 * (1.0f - heat), 0, 255));
systems[n].coolant_bar->setValue(coolant)->setColor(glm::u8vec4(0, 128, 255, 255));
}
}
}
}
Expand Down
8 changes: 4 additions & 4 deletions src/screens/extra/powerManagement.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#ifndef POWER_MANAGEMENT_H
#define POWER_MANAGEMENT_H
#pragma once

#include "gui/gui2_overlay.h"
#include "components/shipsystem.h"

class GuiLabel;
class GuiPanel;
class GuiSlider;
class GuiProgressbar;
Expand All @@ -27,8 +27,10 @@ class PowerManagementScreen : public GuiOverlay
GuiSlider* power_slider;
GuiSlider* coolant_slider;
GuiProgressbar* heat_bar;
GuiLabel* heat_label;
GuiProgressbar* power_bar;
GuiProgressbar* coolant_bar;
GuiLabel* coolant_label;
};
SystemRow systems[ShipSystem::COUNT];
bool set_power_active[ShipSystem::COUNT] = {false};
Expand All @@ -39,5 +41,3 @@ class PowerManagementScreen : public GuiOverlay
void onDraw(sp::RenderTarget& target) override;
virtual void onUpdate() override;
};

#endif//POWER_MANAGEMENT_H
27 changes: 17 additions & 10 deletions src/systems/shipsystemssystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,35 @@ void ShipSystemsSystem::update(float delta)
{
if (!game_server) return;
for(auto [entity, system] : sp::ecs::Query<Reactor>())
updateSystem(system, delta, entity.hasComponent<Coolant>());
updateSystem(entity, system, delta);
for(auto [entity, system] : sp::ecs::Query<BeamWeaponSys>())
updateSystem(system, delta, entity.hasComponent<Coolant>());
updateSystem(entity, system, delta);
for(auto [entity, system] : sp::ecs::Query<MissileTubes>())
updateSystem(system, delta, entity.hasComponent<Coolant>());
updateSystem(entity, system, delta);
for(auto [entity, system] : sp::ecs::Query<ManeuveringThrusters>())
updateSystem(system, delta, entity.hasComponent<Coolant>());
updateSystem(entity, system, delta);
for(auto [entity, system] : sp::ecs::Query<ImpulseEngine>())
updateSystem(system, delta, entity.hasComponent<Coolant>());
updateSystem(entity, system, delta);
for(auto [entity, system] : sp::ecs::Query<WarpDrive>())
updateSystem(system, delta, entity.hasComponent<Coolant>());
updateSystem(entity, system, delta);
for(auto [entity, system] : sp::ecs::Query<JumpDrive>())
updateSystem(system, delta, entity.hasComponent<Coolant>());
updateSystem(entity, system, delta);
for(auto [entity, system] : sp::ecs::Query<Shields>()) {
updateSystem(system.front_system, delta, entity.hasComponent<Coolant>());
updateSystem(entity, system.front_system, delta);
if (system.entries.size() > 1)
updateSystem(system.rear_system, delta, entity.hasComponent<Coolant>());
updateSystem(entity, system.rear_system, delta);
}
}

void ShipSystemsSystem::updateSystem(ShipSystem& system, float delta, bool has_coolant)
void ShipSystemsSystem::updateSystem(sp::ecs::Entity entity, ShipSystem& system, float delta)
{
const bool has_coolant = entity.hasComponent<Coolant>();
// Cap system power request to 100% if a ship lacks both Coolant (no heat
// generation) and a Reactor (no energy consumption). Otherwise,
// overpowering the system is free of consequences.
if (!has_coolant && !entity.hasComponent<Reactor>())
system.power_request = std::min(system.power_request, 1.0f);

system.health = std::min(1.0f, system.health + delta * system.auto_repair_per_second);

system.hacked_level = std::max(0.0f, system.hacked_level - delta / unhack_time);
Expand Down
3 changes: 2 additions & 1 deletion src/systems/shipsystemssystem.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include "ecs/system.h"
#include "ecs/query.h"
#include "ecs/entity.h"
#include "components/shipsystem.h"


Expand All @@ -12,5 +13,5 @@ class ShipSystemsSystem : public sp::ecs::System

void update(float delta) override;
private:
void updateSystem(ShipSystem& system, float delta, bool has_coolant);
void updateSystem(sp::ecs::Entity entity, ShipSystem& system, float delta);
};
Loading