Skip to content

Commit

Permalink
Split master_part_list to multiple files
Browse files Browse the repository at this point in the history
Make ship into a separate superclass of unit
Move additional methods to movable
  • Loading branch information
royfalk committed Jun 7, 2023
1 parent 1fc1e76 commit b75fde9
Show file tree
Hide file tree
Showing 10 changed files with 557 additions and 412 deletions.
1 change: 1 addition & 0 deletions engine/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1104,6 +1104,7 @@ SET(VEGASTRIKE_SOURCES
src/cmd/music.cpp
src/cmd/nebula.cpp
src/cmd/planet.cpp
src/cmd/ship.cpp
src/cmd/script/c_alike/c_alike.tab.cpp
src/cmd/script/c_alike/lex.yy.cpp
src/cmd/script/director.cpp
Expand Down
3 changes: 2 additions & 1 deletion engine/src/cmd/audible.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,11 @@ class Audible {
void playShieldDamageSound(const Vector &pnt);
void playArmorDamageSound(const Vector &pnt);
void playHullDamageSound(const Vector &pnt);
void playEngineSound();
protected:

void playExplosionDamageSound();
void playEngineSound();


// TODO: make into a proper destructor
void killSounds();
Expand Down
53 changes: 32 additions & 21 deletions engine/src/cmd/carrier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "carrier.h"

#include "unit_generic.h"
#include "ship.h"
#include "universe.h"
#include "universe_util.h"

Expand Down Expand Up @@ -228,7 +229,7 @@ void Carrier::EjectCargo(unsigned int index) {
++(fg->nr_ships);
++(fg->nr_ships_left);
}
cargo = new Unit(ans.c_str(), false, unit->faction, "", fg, fgsnumber);
cargo = new Ship(ans.c_str(), false, unit->faction, "", fg, fgsnumber);
cargo->PrimeOrders();
cargo->SetAI(new Orders::AggressiveAI("default.agg.xml"));
cargo->SetTurretAI();
Expand Down Expand Up @@ -551,28 +552,38 @@ Unit *Carrier::makeMasterPartList() {
Unit *ret = new Unit();
ret->name = "master_part_list";

static std::string json_filename = "master_part_list.json"; //vs_config->getVariable("data", "master_part_list", "master_part_list");
std::ifstream ifs(json_filename, std::ifstream::in);
std::stringstream buffer;
buffer << ifs.rdbuf();

const std::string json_text = buffer.str();

std::vector<std::string> parts = json::parsing::parse_array(json_text.c_str());
for (const std::string &part_text : parts) {
json::jobject part = json::jobject::parse(part_text);
Cargo carg;

carg.name = getJSONValue(part, "file", "");
carg.SetCategory(getJSONValue(part, "categoryname", ""));
carg.SetVolume(std::stof(getJSONValue(part, "volume", "")));
carg.SetMass(std::stof(getJSONValue(part, "mass", "")));
carg.quantity = 1;
carg.price = std::stoi(getJSONValue(part, "price", ""));
carg.SetDescription(getJSONValue(part, "description", ""));
ret->cargo.push_back(carg);
//vs_config->getVariable("data", "master_part_list", "master_part_list");
static std::string json_filenames[] = {
"master_part_list.json",
"master_ship_list.json",
"master_component_list.json",
"master_asteroid_list.json",
};

for(const std::string& json_filename : json_filenames) {
std::ifstream ifs(json_filename, std::ifstream::in);
std::stringstream buffer;
buffer << ifs.rdbuf();

const std::string json_text = buffer.str();

std::vector<std::string> parts = json::parsing::parse_array(json_text.c_str());
for (const std::string &part_text : parts) {
json::jobject part = json::jobject::parse(part_text);
Cargo carg;

carg.name = getJSONValue(part, "file", "");
carg.SetCategory(getJSONValue(part, "categoryname", ""));
carg.SetVolume(std::stof(getJSONValue(part, "volume", "")));
carg.SetMass(std::stof(getJSONValue(part, "mass", "")));
carg.quantity = 1;
carg.price = std::stoi(getJSONValue(part, "price", ""));
carg.SetDescription(getJSONValue(part, "description", ""));
ret->cargo.push_back(carg);
}
}


UpdateMasterPartList(ret);
if (!ret->GetCargo("Pilot", i)) { //required items
ret->AddCargo(Cargo("Pilot", "Contraband", 800, 1, .01, 1, 1.0, 1.0), true);
Expand Down
2 changes: 1 addition & 1 deletion engine/src/cmd/energetic.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class Energetic {
float warpenergy; //short fix
float constrained_charge_to_shields;
bool sufficient_energy_to_recharge_shields;
protected:
public:

//fuel of this unit
float fuel;
Expand Down
Loading

0 comments on commit b75fde9

Please sign in to comment.