diff --git a/engine/src/cmd/unit_csv.cpp b/engine/src/cmd/unit_csv.cpp index 543734403..467b258c5 100644 --- a/engine/src/cmd/unit_csv.cpp +++ b/engine/src/cmd/unit_csv.cpp @@ -735,7 +735,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 @@ -746,14 +746,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); @@ -773,44 +787,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 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 @@ -1252,7 +1280,6 @@ const std::map 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); diff --git a/engine/src/cmd/unit_csv_factory.h b/engine/src/cmd/unit_csv_factory.h index 6c9876e0c..5dcc613cd 100644 --- a/engine/src/cmd/unit_csv_factory.h +++ b/engine/src/cmd/unit_csv_factory.h @@ -30,9 +30,11 @@ #include #include -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", @@ -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 { diff --git a/engine/src/cmd/unit_optimize_factory.cpp b/engine/src/cmd/unit_optimize_factory.cpp index d39a13bae..17dc8447d 100644 --- a/engine/src/cmd/unit_optimize_factory.cpp +++ b/engine/src/cmd/unit_optimize_factory.cpp @@ -28,7 +28,7 @@ #include "json.h" void UnitOptimizeFactory::RecursiveParse(std::map 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 @@ -37,35 +37,28 @@ void UnitOptimizeFactory::RecursiveParse(std::map 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 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; - } + } } @@ -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); } diff --git a/engine/src/cmd/unit_optimize_factory.h b/engine/src/cmd/unit_optimize_factory.h index 24e9a9004..7ae09c773 100644 --- a/engine/src/cmd/unit_optimize_factory.h +++ b/engine/src/cmd/unit_optimize_factory.h @@ -34,7 +34,7 @@ class UnitOptimizeFactory public: static void ParseJSON(VSFileSystem::VSFile &file); static void RecursiveParse(std::map unit_attributes, - const std::string& json_text, bool is_root); + const std::string& json_text); }; #endif //VEGA_STRIKE_ENGINE_CMD_UNIT_OPTIMIZE_FACTORY_H diff --git a/engine/src/damage/damageable_layer.cpp b/engine/src/damage/damageable_layer.cpp index dc3de05d3..c458e72cc 100644 --- a/engine/src/damage/damageable_layer.cpp +++ b/engine/src/damage/damageable_layer.cpp @@ -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); diff --git a/engine/src/damage/damageable_layer.h b/engine/src/damage/damageable_layer.h index 2a158a217..2acdbf668 100644 --- a/engine/src/damage/damageable_layer.h +++ b/engine/src/damage/damageable_layer.h @@ -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); };