-
-
Notifications
You must be signed in to change notification settings - Fork 45
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of https://github.com/vegastrike/Vega-Strike-En…
- Loading branch information
Showing
15 changed files
with
1,052 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* component.cpp | ||
* | ||
* Copyright (c) 2001-2002 Daniel Horn | ||
* Copyright (c) 2002-2019 pyramid3d and other Vega Strike Contributors | ||
* Copyright (c) 2019-2023 Stephen G. Tuggy, Benjamen R. Meyer, Roy Falk and other Vega Strike Contributors | ||
* | ||
* https://github.com/vegastrike/Vega-Strike-Engine-Source | ||
* | ||
* This file is part of Vega Strike. | ||
* | ||
* Vega Strike is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Vega Strike is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with Vega Strike. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
// -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- | ||
|
||
#include "component.h" | ||
#include "unit_csv_factory.h" | ||
|
||
Component::Component(double mass, double volume, bool integral): | ||
unit_key(""), | ||
upgrade_name(""), | ||
mass(mass), volume(volume), | ||
integral(integral) {} | ||
|
||
|
||
void Component::Load(std::string upgrade_key, std::string unit_key) { | ||
this->unit_key = unit_key; | ||
upgrade_name = UnitCSVFactory::GetVariable(upgrade_key, "Name", std::string()); | ||
this->upgrade_key = upgrade_key; | ||
|
||
mass = UnitCSVFactory::GetVariable(upgrade_key, "Mass", 0.0); | ||
// TODO: volume = UnitCSVFactory::GetVariable(upgrade_key, "Volume", 0.0); | ||
// TODO: bool integral = false; | ||
} | ||
|
||
// TODO: convert to std::pair<bool, double> | ||
bool Component::CanWillUpDowngrade(const std::string upgrade_key, | ||
bool upgrade, bool apply) { | ||
if(upgrade) { | ||
if(apply) { | ||
return Upgrade(upgrade_key); | ||
} else { | ||
return CanUpgrade(upgrade_key); | ||
} | ||
} else { | ||
if(apply) { | ||
return Downgrade(); | ||
} else { | ||
return CanDowngrade(); | ||
} | ||
} | ||
} | ||
|
||
bool Component::Downgrade() { | ||
upgrade_name = std::string(); | ||
upgrade_key = std::string(); | ||
|
||
mass = 0.0; | ||
volume = 0.0; | ||
|
||
return true; | ||
} | ||
|
||
void Component::SetIntegral(bool integral) { | ||
this->integral = integral; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,92 @@ | ||
/* | ||
* component.h | ||
* | ||
* Copyright (c) 2001-2002 Daniel Horn | ||
* Copyright (c) 2002-2019 pyramid3d and other Vega Strike Contributors | ||
* Copyright (c) 2019-2023 Stephen G. Tuggy, Benjamen R. Meyer, Roy Falk and other Vega Strike Contributors | ||
* | ||
* https://github.com/vegastrike/Vega-Strike-Engine-Source | ||
* | ||
* This file is part of Vega Strike. | ||
* | ||
* Vega Strike is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Vega Strike is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with Vega Strike. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
// -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- | ||
|
||
#ifndef COMPONENT_H | ||
#define COMPONENT_H | ||
|
||
#include <string> | ||
#include <map> | ||
|
||
/** | ||
* LibComponent is currently tightly coupled to LibDamage and | ||
* other various libraries in VegaStrike engine. | ||
* Consider decoupling and subclassing every component in it. | ||
*/ | ||
|
||
class Unit; | ||
|
||
// TODO: add complete list | ||
enum class ComponentType { | ||
Hull, | ||
Armor, | ||
Shield, | ||
Drive | ||
}; | ||
|
||
class Component | ||
{ | ||
protected: | ||
std::string unit_key; // Areus.blank | ||
std::string upgrade_name; // Isometal Armor | ||
std::string upgrade_key; // armor03__upgrades | ||
|
||
double mass = 0; | ||
double volume = 0; | ||
|
||
bool integral = false; // Part of the ship. Can't be upgraded/downgraded | ||
public: | ||
Component(double mass, | ||
double volume, bool integral); | ||
|
||
// Load from units dictionary | ||
virtual void Load(std::string upgrade_key, std::string unit_key); | ||
|
||
virtual void SaveToCSV(std::map<std::string, std::string>& unit) const = 0; | ||
|
||
virtual std::string Describe() const = 0; // Describe component in base_computer | ||
|
||
// Handle the four cases of CanUpgrade/Upgrade/CanDowngrade/Downgrade | ||
bool CanWillUpDowngrade(const std::string upgrade_key, | ||
bool upgrade, bool apply); | ||
|
||
virtual bool CanDowngrade() const = 0; | ||
|
||
virtual bool Downgrade(); | ||
|
||
virtual bool CanUpgrade(const std::string upgrade_key) const = 0; | ||
|
||
virtual bool Upgrade(const std::string upgrade_key) = 0; | ||
|
||
virtual void Damage() = 0; | ||
virtual void Repair() = 0; | ||
|
||
virtual bool Damaged() const = 0; | ||
virtual bool Installed() const = 0; | ||
|
||
void SetIntegral(bool integral); | ||
}; | ||
#endif // COMPONENT_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
/* | ||
* energy_consumer.cpp | ||
* | ||
* Copyright (c) 2001-2002 Daniel Horn | ||
* Copyright (c) 2002-2019 pyramid3d and other Vega Strike Contributors | ||
* Copyright (c) 2019-2023 Stephen G. Tuggy, Benjamen R. Meyer, Roy Falk and other Vega Strike Contributors | ||
* | ||
* https://github.com/vegastrike/Vega-Strike-Engine-Source | ||
* | ||
* This file is part of Vega Strike. | ||
* | ||
* Vega Strike is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 2 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* Vega Strike is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with Vega Strike. If not, see <https://www.gnu.org/licenses/>. | ||
*/ | ||
|
||
// -*- mode: c++; c-basic-offset: 4; indent-tabs-mode: nil -*- | ||
|
||
#include "energy_consumer.h" | ||
|
||
double EnergyConsumer::simulation_atom_var = 0.1; | ||
|
||
EnergyConsumer::EnergyConsumer(EnergyContainer *source, | ||
bool partial, | ||
double consumption): | ||
source(source), | ||
partial(partial), | ||
consumption(consumption), | ||
atom_consumption(consumption * simulation_atom_var) {} | ||
|
||
|
||
double EnergyConsumer::Consume() { | ||
if(!source) { | ||
return 0.0; | ||
} | ||
|
||
return source->Deplete(partial, atom_consumption); | ||
} | ||
|
||
double EnergyConsumer::GetConsumption() const { | ||
return consumption; | ||
} | ||
|
||
double EnergyConsumer::GetAtomConsumption() const { | ||
return atom_consumption; | ||
} | ||
|
||
void EnergyConsumer::SetConsumption(double consumption) { | ||
this->consumption = consumption; | ||
atom_consumption = consumption * simulation_atom_var; | ||
} | ||
|
||
void EnergyConsumer::SetSource(EnergyContainer* source) { | ||
this->source = source; | ||
} | ||
|
||
void EnergyConsumer::ZeroSource() { | ||
source->Zero(); | ||
} |
Oops, something went wrong.