Skip to content

Commit

Permalink
Merge from master
Browse files Browse the repository at this point in the history
  • Loading branch information
royfalk committed Nov 22, 2024
2 parents fe81691 + 4f72ce2 commit 54c798f
Show file tree
Hide file tree
Showing 14 changed files with 122 additions and 81 deletions.
3 changes: 1 addition & 2 deletions engine/src/cmd/jump_capable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,8 +271,7 @@ bool JumpCapable::AutoPilotToErrorMessage(const Unit *target,
failuremessage = configuration()->graphics_config.hud.already_near_message;
return false;
}
unit->ftl_energy.Deplete(true, static_cast<double>(totpercent) * unit->ftl_drive.GetAtomConsumption());
// TODO: figure out to do unit->ftl_drive.Consume() instead

if (unsafe == false && totpercent == 0) {
end = endne;
}
Expand Down
101 changes: 64 additions & 37 deletions engine/src/cmd/unit_csv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -722,7 +722,7 @@ void Unit::LoadRow(std::string unit_identifier, string modification, bool saved_
pImage->CockpitCenter.j = UnitCSVFactory::GetVariable(unit_key, "CockpitY", 0.0f) * xml.unitscale;
pImage->CockpitCenter.k = UnitCSVFactory::GetVariable(unit_key, "CockpitZ", 0.0f) * xml.unitscale;
Mass = UnitCSVFactory::GetVariable(unit_key, "Mass", 1.0f);
Momentofinertia = UnitCSVFactory::GetVariable(unit_key, "Moment_Of_Inertia", 1.0f);
Momentofinertia = Mass;


// Hull
Expand All @@ -733,14 +733,28 @@ void Unit::LoadRow(std::string unit_identifier, string modification, bool saved_
specInterdiction = UnitCSVFactory::GetVariable(unit_key, "Spec_Interdiction", 0.0f);

// Init armor
std::string armor_keys[] = {"Armor_Front_Top_Left", "Armor_Front_Top_Right",
// We support 2 options:
// 1. armor = x. Could be 0, 40, etc. This populaes the 8 facets below
// 2. armor = "". Use the old method of reading all 8 facets.
const std::string armor_single_value_string = UnitCSVFactory::GetVariable(unit_key, "armor", std::string());
float armor_values[8];

if(armor_single_value_string != "") {
int armor_single_value = std::stoi(armor_single_value_string, 0);

for (int i = 0; i < 8; i++) {
armor_values[i] = armor_single_value;
}
} else {
std::string armor_keys[] = {"Armor_Front_Top_Left", "Armor_Front_Top_Right",
"Armor_Front_Bottom_Left", "Armor_Front_Bottom_Right",
"Armor_Back_Top_Left", "Armor_Back_Top_Right",
"Armor_Back_Bottom_Left", "Armor_Back_Bottom_Right"};
float armor_values[8];
for (int i = 0; i < 8; i++) {
float tmp_armor_value = UnitCSVFactory::GetVariable(unit_key, armor_keys[i], 0.0f);
armor_values[i] = tmp_armor_value;

for (int i = 0; i < 8; i++) {
float tmp_armor_value = UnitCSVFactory::GetVariable(unit_key, armor_keys[i], 0.0f);
armor_values[i] = tmp_armor_value;
}
}

armor->UpdateFacets(8, armor_values);
Expand All @@ -760,44 +774,58 @@ void Unit::LoadRow(std::string unit_identifier, string modification, bool saved_
//float efficiency = UnitCSVFactory::GetVariable(unit_key, "Shield_Efficiency", 1.0f );

// Get shield count

int shield_count = 0;
float shield_values[4];
std::string shield_string_values[4];
std::vector<string> shield_sections;

const std::string shield_strength_string = UnitCSVFactory::GetVariable(unit_key, "shield_strength", std::string());
const std::string shield_facets_string = UnitCSVFactory::GetVariable(unit_key, "shield_facets", std::string());

if(shield_strength_string != "" && shield_facets_string != "") {
int shield_strength = std::stoi(shield_strength_string);
int shield_facets = std::stoi(shield_facets_string);
shield->number_of_facets = shield_facets;
shield->UpdateFacets(shield_strength);
} else {
int shield_count = 0;
float shield_values[4];


// TODO: this mapping should really go away
// I love macros, NOT.
shield_string_values[0] = UnitCSVFactory::GetVariable(unit_key, "Shield_Front_Top_Right", std::string());
shield_string_values[1] = UnitCSVFactory::GetVariable(unit_key, "Shield_Back_Top_Left", std::string());
shield_string_values[2] = UnitCSVFactory::GetVariable(unit_key, "Shield_Front_Bottom_Right", std::string());
shield_string_values[3] = UnitCSVFactory::GetVariable(unit_key, "Shield_Front_Bottom_Left", std::string());
// TODO: this mapping should really go away
// I love macros, NOT.
shield_string_values[0] = UnitCSVFactory::GetVariable(unit_key, "Shield_Front_Top_Right", std::string());
shield_string_values[1] = UnitCSVFactory::GetVariable(unit_key, "Shield_Back_Top_Left", std::string());
shield_string_values[2] = UnitCSVFactory::GetVariable(unit_key, "Shield_Front_Bottom_Right", std::string());
shield_string_values[3] = UnitCSVFactory::GetVariable(unit_key, "Shield_Front_Bottom_Left", std::string());

for (int i = 0; i < 4; i++) {
shield_values[i] = 0.0f;
for (int i = 0; i < 4; i++) {
shield_values[i] = 0.0f;

if (shield_string_values[i].empty()) {
continue;
if (shield_string_values[i].empty()) {
continue;
}

shield_values[i] = ::stof(shield_string_values[i]);
// Should add up to the shield type - quad or dual
shield_count++;
}

shield_values[i] = ::stof(shield_string_values[i]);
// Should add up to the shield type - quad or dual
shield_count++;
/*
We are making the following assumptions:
1. The CSV is correct
2. Dual shields are 0 front and 1 rear
3. Quad shields are front (0), rear(1), right(2) and left(3)
4. There is no support for 8 facet shields in the game.
This has more to do with the cockpit code than anything else
5. We map the above index to our own
*/

if (shield_count == 4 || shield_count == 2) {
shield->number_of_facets = shield_count;
shield->UpdateFacets(shield_count, shield_values);
}
}

/*
We are making the following assumptions:
1. The CSV is correct
2. Dual shields are 0 front and 1 rear
3. Quad shields are front (0), rear(1), right(2) and left(3)
4. There is no support for 8 facet shields in the game.
This has more to do with the cockpit code than anything else
5. We map the above index to our own
*/

if (shield_count == 4 || shield_count == 2) {
shield->number_of_facets = shield_count;
shield->UpdateFacets(shield_count, shield_values);
}


// End shield section

Expand Down Expand Up @@ -1205,7 +1233,6 @@ const std::map<std::string, std::string> Unit::UnitToMap() {
unit["Cargo"] = carg;
}
unit["Mass"] = tos(Mass);
unit["Moment_Of_Inertia"] = tos(Momentofinertia);
unit["Fuel_Capacity"] = tos(fuel.Level());
unit["Hull"] = tos(GetHullLayer().facets[0].health);
unit["Spec_Interdiction"] = tos(specInterdiction);
Expand Down
13 changes: 10 additions & 3 deletions engine/src/cmd/unit_csv_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@
#include <boost/algorithm/string.hpp>
#include <iostream>

const std::string keys[] = {"Key", "Directory", "Name", "STATUS", "Object_Type",
const std::string keys[] = {"Key", "Directory", "Name", "Object_Type",
"Combat_Role", "Textual_Description", "Hud_image", "Unit_Scale", "Cockpit",
"CockpitX", "CockpitY", "CockpitZ", "Mesh", "Shield_Mesh", "Rapid_Mesh", "BSP_Mesh",
"CockpitX", "CockpitY", "CockpitZ", "Mesh", "Shield_Mesh",
"Rapid_Mesh", // TODO: find out if used in WC
"BSP_Mesh",
"Use_BSP", "Use_Rapid", "NoDamageParticles", "Mass", "Moment_Of_Inertia",
"Fuel_Capacity", "Hull", "Armor_Front_Top_Right", "Armor_Front_Top_Left",
"Armor_Front_Bottom_Right", "Armor_Front_Bottom_Left", "Armor_Back_Top_Right",
Expand Down Expand Up @@ -61,7 +63,12 @@ const std::string keys[] = {"Key", "Directory", "Name", "STATUS", "Object_Type",
"Upgrade_Type", "Facets",
// These values are not in units.csv! There are probably more but I stopped mapping.
// TODO: map all missing values using the commented out code below!
"FaceCamera", "Unit_Role", "Attack_Preference", "Hidden_Hold_Volume", "Equipment_Space"};
"FaceCamera", "Unit_Role", "Attack_Preference", "Hidden_Hold_Volume", "Equipment_Space",

// New stuff
"armor", "shield_strength", "shield_facets"

};


class UnitCSVFactory {
Expand Down
31 changes: 12 additions & 19 deletions engine/src/cmd/unit_optimize_factory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
#include "json.h"

void UnitOptimizeFactory::RecursiveParse(std::map<std::string, std::string> unit_attributes,
const std::string& json_text, bool is_root) {
const std::string& json_text) {
json::jobject json = json::jobject::parse(json_text);

// Parse the data section
Expand All @@ -37,35 +37,28 @@ void UnitOptimizeFactory::RecursiveParse(std::map<std::string, std::string> unit

for (const std::string &key : keys) {
// For some reason, parser adds quotes

if(data_json.has_key(key)) {
const std::string attribute = data_json.get(key);
const std::string stripped_attribute = attribute.substr(1, attribute.size() - 2);
unit_attributes[key] = stripped_attribute;
} else {
// If we do this for non-root, we'll overwrite existing attributes
if(is_root) {
unit_attributes[key] = "";
}
}
}
}

if(unit_attributes.count("Key")) {
std::string unit_key = unit_attributes["Key"];
UnitCSVFactory::units[unit_key] = unit_attributes;
}


// Parse the units array
if(json.has_key("units")) {
std::vector<std::string> units = json::parsing::parse_array(json.get("units").c_str());
// Iterate over root
for (const std::string &unit_text : units) {
RecursiveParse(unit_attributes, unit_text, false);
}
} else {
// Add moment of intertia
if(unit_attributes.count("Mass")) {
unit_attributes["Moment_Of_Inertia"] = unit_attributes["Mass"];
RecursiveParse(unit_attributes, unit_text);
}

std::string unit_key = unit_attributes["Key"];

UnitCSVFactory::units[unit_key] = unit_attributes;
}
}
}


Expand All @@ -79,5 +72,5 @@ void UnitOptimizeFactory::ParseJSON(VSFileSystem::VSFile &file) {
// Add root
unit_attributes["root"] = file.GetRoot();

RecursiveParse(unit_attributes, json_text, true);
RecursiveParse(unit_attributes, json_text);
}
2 changes: 1 addition & 1 deletion engine/src/cmd/unit_optimize_factory.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class UnitOptimizeFactory
public:
static void ParseJSON(VSFileSystem::VSFile &file);
static void RecursiveParse(std::map<std::string, std::string> unit_attributes,
const std::string& json_text, bool is_root);
const std::string& json_text);
};

#endif //VEGA_STRIKE_ENGINE_CMD_UNIT_OPTIMIZE_FACTORY_H
1 change: 1 addition & 0 deletions engine/src/components/component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ void Component::Load(std::string upgrade_key, std::string unit_key) {
mass = UnitCSVFactory::GetVariable(upgrade_key, "Mass", 0.0);

// Get volume and description from MasterPartList.
// We need try/catch for unit tests where MPL isn't loaded.
const Cargo cargo = Manifest::MPL().GetCargoByName(upgrade_key);
if(!cargo.GetName().empty()) {
price = cargo.GetPrice();
Expand Down
19 changes: 18 additions & 1 deletion engine/src/components/energy_container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,12 +126,29 @@ void EnergyContainer::Load(std::string upgrade_key, std::string unit_key) {
break;

default: // This really can't happen
std::cerr << "Illegal container type in EnergyContainer::Load" << std::flush;
abort();
}
}

void EnergyContainer::SaveToCSV(std::map<std::string, std::string>& unit) const {
unit[FUEL_CAPACITY] = std::to_string(MaxLevel());
switch(type) {
case ComponentType::Fuel:
unit[FUEL_CAPACITY] = std::to_string(MaxLevel() / configuration()->fuel.fuel_factor);
break;

case ComponentType::Capacitor:
unit[FUEL_CAPACITY] = std::to_string(MaxLevel() / configuration()->fuel.energy_factor);
break;

case ComponentType::FtlCapacitor:
unit[FUEL_CAPACITY] = std::to_string(MaxLevel() / configuration()->fuel.ftl_energy_factor);
break;

default: // This really can't happen
std::cerr << "Illegal container type in EnergyContainer::SaveToCSV" << std::flush;
abort();
}
}


Expand Down
6 changes: 2 additions & 4 deletions engine/src/components/ftl_drive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,17 +50,15 @@ void FtlDrive::Load(std::string upgrade_key,
std::string unit_key) {
Component::Load(upgrade_key, unit_key);

const double ftl_drive_factor = configuration()->fuel.ftl_drive_factor;

// Consumer
double energy = UnitCSVFactory::GetVariable(unit_key, "Warp_Usage_Cost", 0.0f);
SetConsumption(energy * ftl_drive_factor);
SetConsumption(energy * configuration()->fuel.ftl_drive_factor);

// FTL Drive
}

void FtlDrive::SaveToCSV(std::map<std::string, std::string>& unit) const {
unit["Warp_Usage_Cost"] = std::to_string(consumption);
unit["Warp_Usage_Cost"] = std::to_string(consumption / configuration()->fuel.ftl_drive_factor);
}

// FTL drive is integrated and so cannot be upgraded/downgraded
Expand Down
7 changes: 2 additions & 5 deletions engine/src/components/jump_drive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,10 @@ bool JumpDrive::Enabled() const {
void JumpDrive::Load(std::string upgrade_key, std::string unit_key) {
Component::Load(upgrade_key, unit_key);

const double jump_drive_factor = configuration()->fuel.jump_drive_factor;

// Consumer
double energy = UnitCSVFactory::GetVariable(unit_key, "Outsystem_Jump_Cost", 0.0f);
// Jump drive is unique - consumption and atom_consumption are identical
atom_consumption = consumption = energy * jump_drive_factor;

atom_consumption = consumption = energy * configuration()->fuel.jump_drive_factor;

// Jump Drive
installed = UnitCSVFactory::GetVariable(unit_key, "Jump_Drive_Present", false);
Expand All @@ -94,7 +91,7 @@ void JumpDrive::Load(std::string upgrade_key, std::string unit_key) {
void JumpDrive::SaveToCSV(std::map<std::string, std::string>& unit) const {
unit["Jump_Drive_Present"] = std::to_string(Installed());
unit["Jump_Drive_Delay"] = std::to_string(delay);
unit["Outsystem_Jump_Cost"] = std::to_string(consumption);
unit["Outsystem_Jump_Cost"] = std::to_string(consumption / configuration()->fuel.jump_drive_factor);
}

bool JumpDrive::CanDowngrade() const {
Expand Down
2 changes: 1 addition & 1 deletion engine/src/components/reactor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ void Reactor::Load(std::string upgrade_key, std::string unit_key) {

void Reactor::SaveToCSV(std::map<std::string, std::string>& unit) const {
// TODO: This won't record damage to recharge
unit[REACTOR_RECHARGE] = std::to_string(capacity.MaxValue());
unit[REACTOR_RECHARGE] = std::to_string(capacity.MaxValue() / configuration()->fuel.reactor_factor);
}


Expand Down
9 changes: 2 additions & 7 deletions engine/src/configuration/configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,18 +188,13 @@ struct Fuel {
float ecm_energy_cost{0.05F};

double megajoules_factor{100};

// Reduce the number of tons in a ship to something realistic
// The more we multiply fuel_factor, the more we match here
double fuel_ton_modifier{0.0001};

double fuel_factor{1000.0}; // Multiply fuel by this to get fuel by minutes
double fuel_factor{60.0}; // Multiply fuel by this to get fuel by minutes
double energy_factor{1.0};
double ftl_energy_factor{1.0};

double reactor_factor{1.0};

double ftl_drive_factor{1.0};
double ftl_drive_factor{0.1};
double jump_drive_factor{1.0};

// 0 infinite, 1 fuel, 2 energy, 3 ftl_energy, 4 disabled
Expand Down
6 changes: 6 additions & 0 deletions engine/src/damage/damageable_layer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,12 @@ float DamageableLayer::GetRegeneration() {
return facets[0].regeneration;
}

void DamageableLayer::UpdateFacets(const float new_facet_strength) {
for (unsigned int i = 0; i < number_of_facets; i++) {
facets[i].Update(new_facet_strength);
}
}

void DamageableLayer::UpdateFacets(const unsigned int new_size, const float new_facets[4]) {
assert(new_size == number_of_facets);

Expand Down
1 change: 1 addition & 0 deletions engine/src/damage/damageable_layer.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ struct DamageableLayer {
void Regenerate(float recharge_rate);
void RegenerateOrDischarge(float recharge, bool velocity_discharge, float discharge_rate);
float GetRegeneration();
void UpdateFacets(const float new_facet_strength);
void UpdateFacets(const unsigned int size, const float new_facets[4]);
void UpdateRegeneration(const float &new_regeneration_value);
};
Expand Down
2 changes: 1 addition & 1 deletion engine/src/resource/product.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class Product
// TODO: Can be a fraction for things such as fuel, water, etc. But not for now.
Resource<int> quantity;

// TODO: move to int, x100 and add code to deal with cents.
// TODO: move to int and not deal with cents.
double price; // Price per one of quantity

friend bool operator==(const Product &lhs, const std::string &rhs);
Expand Down

0 comments on commit 54c798f

Please sign in to comment.