Skip to content

Commit

Permalink
add thermic dock type (passive)
Browse files Browse the repository at this point in the history
  • Loading branch information
amir-arad committed Dec 21, 2018
1 parent f0c9d48 commit a0ab78a
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 24 deletions.
2 changes: 1 addition & 1 deletion scripts/shipTemplates_Corvette.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ template:setTubeDirection(0, -90)
template:setTubeDirection(1, -90)
template:setTubeDirection(2, 90)
template:setTubeDirection(3, 90)
template:setDocks(10, 2)
template:setDocks(8, 2, 2)
template:addDrones("L3 Mouse", 6)
template:addDrones("L3 Cat", 1)

Expand Down
10 changes: 5 additions & 5 deletions src/screens/extra/dockMasterScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ DockMasterScreen::DockMasterScreen(GuiContainer *owner)
// the index in the button list is assumed to equal the index of the dock
for (int n = 0; n < max_docks_count; n++)
{
if (my_spaceship->docks[n].dock_type != Disabled)
if (my_spaceship->docks[n].dock_type != Dock_Disabled)
{
string state = my_spaceship ? " (" + getDockStateName(my_spaceship->docks[n].state) + ")" : "";
docks->addEntry("dock-" + std::to_string(n + 1) + state, "dock-" + std::to_string(n + 1) + " " + getDockTypeName(my_spaceship->docks[n].dock_type));
Expand Down Expand Up @@ -126,9 +126,9 @@ void DockMasterScreen::selectDock(int index)
this->index = index;
docks->setSelectionIndex(index);
auto &dockData = my_spaceship->docks[index];
launch_button->setVisible(dockData.dock_type == Launcher);
energy_bar->setVisible(dockData.dock_type == Energy);
energy_slider->setVisible(dockData.dock_type == Energy);
launch_button->setVisible(dockData.dock_type == Dock_Launcher);
energy_bar->setVisible(dockData.dock_type == Dock_Energy);
energy_slider->setVisible(dockData.dock_type == Dock_Energy);
}

void DockMasterScreen::onDraw(sf::RenderTarget &window)
Expand All @@ -140,7 +140,7 @@ void DockMasterScreen::onDraw(sf::RenderTarget &window)
for (int n = 0; n < max_docks_count; n++)
{
Dock &dockData = my_spaceship->docks[n];
if (dockData.dock_type != Disabled)
if (dockData.dock_type != Dock_Disabled)
{
string state = " (" + getDockStateName(dockData.state) + ")";
string dockName = "d" + std::to_string(n + 1) + "-" + getDockTypeName(dockData.dock_type)[0];
Expand Down
5 changes: 4 additions & 1 deletion src/shipTemplate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,7 @@ ShipTemplate::ShipTemplate()
has_reactor = true;
launcher_dock_count = 0;
energy_dock_count = 0;
thermic_dock_count = 0;
}

void ShipTemplate::setBeamTexture(int index, string texture)
Expand Down Expand Up @@ -408,9 +409,10 @@ void ShipTemplate::addDrones(string template_name, int count)
drones.push_back(DroneTemplate(template_name, count));
}

void ShipTemplate::setDocks(int launchers, int energy){
void ShipTemplate::setDocks(int launchers, int energy, int thermic){
launcher_dock_count = launchers;
energy_dock_count = energy;
thermic_dock_count = thermic;
}

void ShipTemplate::setRadarTrace(string trace)
Expand Down Expand Up @@ -461,6 +463,7 @@ P<ShipTemplate> ShipTemplate::copy(string new_name)
result->drones = drones;
result->launcher_dock_count = launcher_dock_count;
result->energy_dock_count = energy_dock_count;
result->thermic_dock_count = thermic_dock_count;
return result;
}

Expand Down
3 changes: 2 additions & 1 deletion src/shipTemplate.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ class ShipTemplate : public PObject
int weapon_storage[MW_Count];
int launcher_dock_count;
int energy_dock_count;
int thermic_dock_count;
string radar_trace;

std::vector<ShipRoomTemplate> rooms;
Expand Down Expand Up @@ -168,7 +169,7 @@ class ShipTemplate : public PObject
void addRoomSystem(sf::Vector2i position, sf::Vector2i size, ESystem system);
void addDoor(sf::Vector2i position, bool horizontal);
void addDrones(string template_name, int count);
void setDocks(int launchers, int energy);
void setDocks(int launchers, int energy, int thermic);
void setRadarTrace(string trace);

P<ShipTemplate> copy(string new_name);
Expand Down
2 changes: 1 addition & 1 deletion src/spaceObjects/playerSpaceship.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1487,7 +1487,7 @@ void PlayerSpaceship::onReceiveClientCommand(int32_t client_id, sf::Packet& pack
break;
case CMD_SET_DOCK_ENERGY_REQUEST:
packet >> dockIndex;
if (docks[dockIndex].state == EDockState::Docked && docks[dockIndex].dock_type == Energy)
if (docks[dockIndex].state == EDockState::Docked && docks[dockIndex].dock_type == Dock_Energy)
{
float value;
packet >> value;
Expand Down
10 changes: 6 additions & 4 deletions src/spaceObjects/spaceship.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,11 +249,13 @@ void SpaceShip::applyTemplateValues()
for(int n = 0; n < max_docks_count; n++)
{
if (n < ship_template->launcher_dock_count){
docks[n].setDockType(Launcher);
docks[n].setDockType(Dock_Launcher);
} else if (n < ship_template->launcher_dock_count + ship_template->energy_dock_count){
docks[n].setDockType(Energy);
docks[n].setDockType(Dock_Energy);
} else if (n < ship_template->launcher_dock_count + ship_template->energy_dock_count + ship_template->thermic_dock_count){
docks[n].setDockType(Dock_Thermic);
} else {
docks[n].setDockType(Disabled);
docks[n].setDockType(Dock_Disabled);
}
}
int maxActiveDockIndex = ship_template->launcher_dock_count + ship_template->energy_dock_count;
Expand Down Expand Up @@ -1052,7 +1054,7 @@ bool SpaceShip::hasSystem(ESystem system)
return impulse_max_speed > 0.0;
case SYS_Docks:
case SYS_Drones:
return docks[0].dock_type != Disabled;
return docks[0].dock_type != Dock_Disabled;
}
return true;
}
Expand Down
26 changes: 18 additions & 8 deletions src/spaceObjects/spaceshipParts/dock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Dock *Dock::findOpenForDocking(Dock docks[], int size)
return dock;
}

Dock::Dock() : parent(nullptr), dock_type(Disabled), move_target_index(-1)
Dock::Dock() : parent(nullptr), dock_type(Dock_Disabled), move_target_index(-1)
{
empty();
}
Expand Down Expand Up @@ -81,7 +81,7 @@ void Dock::empty()

bool Dock::isUnoccupied()
{
return dock_type != Disabled && state == Empty;
return dock_type != Dock_Disabled && state == Empty;
}

bool Dock::isOpenForDocking()
Expand Down Expand Up @@ -127,7 +127,7 @@ void Dock::update(float delta)
}
}
}
else if (game_server && dock_type == Energy && state == Docked)
else if (game_server && dock_type == Dock_Energy && state == Docked)
{
auto cargo = getCargo();
if (cargo)
Expand Down Expand Up @@ -156,9 +156,17 @@ void Dock::update(float delta)
auto cargo = getCargo();
if (cargo && cargo->getHeat() > 0)
{
float heatToAbsorve = std::min(cargo->getHeat(), delta * PlayerSpaceship::heat_transfer_per_second);
parent->addHeat(SYS_Docks, heatToAbsorve);
cargo->setHeat(cargo->getHeat() - heatToAbsorve);
if (dock_type == Dock_Thermic){
float coolDown = std::min(
delta * this->parent->getSystemEffectiveness(SYS_Docks) * PlayerSpaceship::heat_transfer_per_second * 0.2f,
cargo->getHeat());
parent->addHeat(SYS_Docks, coolDown * 0.2f);
cargo->setHeat(cargo->getHeat() - coolDown);
} else {
float heatToAbsorve = std::min(cargo->getHeat(), delta * PlayerSpaceship::heat_transfer_per_second);
parent->addHeat(SYS_Docks, heatToAbsorve);
cargo->setHeat(cargo->getHeat() - heatToAbsorve);
}
}
}
}
Expand All @@ -184,10 +192,12 @@ string getDockTypeName(EDockType dockType)
{
switch (dockType)
{
case Launcher:
case Dock_Launcher:
return "Launcher";
case Energy:
case Dock_Energy:
return "Energy";
case Dock_Thermic:
return "Thermic";
default:
return "Unknown";
}
Expand Down
7 changes: 4 additions & 3 deletions src/spaceObjects/spaceshipParts/dock.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@

enum EDockType
{
Launcher,
Energy,
Disabled
Dock_Launcher,
Dock_Energy,
Dock_Thermic,
Dock_Disabled
};
string getDockTypeName(EDockType dockType);

Expand Down

0 comments on commit a0ab78a

Please sign in to comment.