From cc9d5ad335f6451074ee99a5caf7381aad3260b9 Mon Sep 17 00:00:00 2001 From: Roy Falk Date: Wed, 4 Dec 2024 17:48:18 +0200 Subject: [PATCH 1/2] Fix issue where some component damage can't be fixed - Basic Repair to factor damage to these components - Make Basic Repair also repair this damage --- engine/src/cmd/unit_generic.cpp | 39 +++++++++++++++++++++++---- engine/src/components/afterburner.cpp | 2 ++ engine/src/components/component.cpp | 2 +- engine/src/components/drive.cpp | 6 +++++ 4 files changed, 43 insertions(+), 6 deletions(-) diff --git a/engine/src/cmd/unit_generic.cpp b/engine/src/cmd/unit_generic.cpp index 7d2687c3a..85e05dc80 100644 --- a/engine/src/cmd/unit_generic.cpp +++ b/engine/src/cmd/unit_generic.cpp @@ -3055,7 +3055,6 @@ bool Unit::UpAndDownGrade(const Unit *up, } } - bool upgradedshield = false; if (!csv_cell_null_check || force_change_on_nothing || cell_has_recursive_data(upgrade_name, up->faction, "Shield_Front_Top_Right")) { @@ -3072,10 +3071,6 @@ bool Unit::UpAndDownGrade(const Unit *up, shield->facets[i].health = shield->facets[i].max_health; } } - - if (touchme && retval == UPGRADEOK) { - upgradedshield = true; - } } else if (up->FShieldData() > 0 || up->RShieldData() > 0 || up->LShieldData() > 0 || up->BShieldData() > 0) { cancompletefully = false; } @@ -3296,6 +3291,29 @@ int Unit::RepairCost() { if (LifeSupportFunctionalityMax < 1) { ++cost; } + + // TODO: figure out better cost + if (afterburner.Damaged()) { + cost += 5; + } + + if (afterburner_upgrade.Damaged()) { + cost += 3; + } + + if (drive.Damaged()) { + cost += 7; + } + + if (drive_upgrade.Damaged()) { + cost += 5; + } + + if (ftl_drive.Damaged()) { + cost += 7; + } + + for (i = 0; i < numCargo(); ++i) { if (GetCargo(i).GetCategory().find(DamagedCategory) == 0) { ++cost; @@ -3304,6 +3322,7 @@ int Unit::RepairCost() { return cost; } +// This is called when performing a BASIC_REPAIR int Unit::RepairUpgrade() { vector savedCargo; savedCargo.swap(cargo); @@ -3369,6 +3388,14 @@ int Unit::RepairUpgrade() { pct = 1; success += 1; } + + // Repair components + afterburner.Repair(); + afterburner_upgrade.Repair(); + drive.Repair(); + drive_upgrade.Repair(); + ftl_drive.Repair(); + damages = Damages::NO_DAMAGE; bool ret = success && pct > 0; static bool ComponentBasedUpgrades = @@ -3826,7 +3853,9 @@ bool isWeapon(std::string name) { } \ while (0) +// This is called every cycle - repair in flight by droids void Unit::Repair() { + // TODO: everything below here needs to go when we're done with lib_components static float repairtime = XMLSupport::parse_float(vs_config->getVariable("physics", "RepairDroidTime", "180")); static float checktime = XMLSupport::parse_float(vs_config->getVariable("physics", "RepairDroidCheckTime", "5")); if ((repairtime <= 0) || (checktime <= 0)) { diff --git a/engine/src/components/afterburner.cpp b/engine/src/components/afterburner.cpp index 8caaa9c8c..57aefb77c 100644 --- a/engine/src/components/afterburner.cpp +++ b/engine/src/components/afterburner.cpp @@ -47,6 +47,8 @@ void Afterburner::Load(std::string upgrade_key, speed = Resource(UnitCSVFactory::GetVariable(unit_key, "Afterburner_Speed_Governor", std::string("0.0")), game_speed); double consumption = UnitCSVFactory::GetVariable(unit_key, "Afterburner_Usage_Cost", 1.0); SetConsumption(consumption); + + operational = (thrust.Percent() + speed.Percent()) / 2 * 100; } void Afterburner::SaveToCSV(std::map& unit) const { diff --git a/engine/src/components/component.cpp b/engine/src/components/component.cpp index 4ac7f8c33..84eefb8bd 100644 --- a/engine/src/components/component.cpp +++ b/engine/src/components/component.cpp @@ -123,7 +123,7 @@ void Component::Repair() { } bool Component::Damaged() const { - return operational.Damaged(); + return operational.Value() < operational.MaxValue(); } bool Component::Destroyed() const { diff --git a/engine/src/components/drive.cpp b/engine/src/components/drive.cpp index 57d838645..64c72cb14 100644 --- a/engine/src/components/drive.cpp +++ b/engine/src/components/drive.cpp @@ -96,6 +96,12 @@ void Drive::Load(std::string upgrade_key, speed = Resource(UnitCSVFactory::GetVariable(unit_key, "Default_Speed_Governor", std::string("0.0")), game_speed, minimal_drive_functionality); + + operational = (yaw.Percent() + pitch.Percent() + roll.Percent() + + lateral.Percent() + vertical.Percent() + forward.Percent() + + retro.Percent() + speed.Percent() + + max_yaw_left.Percent() + max_yaw_right.Percent() + max_pitch_down.Percent() + + max_pitch_up.Percent() + max_roll_left.Percent() + max_roll_right.Percent()) / 14 * 100; } From 7a5ee8c5f7ec2d13b6d86928436c79648b9f5432 Mon Sep 17 00:00:00 2001 From: Roy Falk Date: Sun, 8 Dec 2024 12:14:43 +0200 Subject: [PATCH 2/2] Add comments --- engine/src/components/afterburner.cpp | 2 ++ engine/src/components/drive.cpp | 2 ++ 2 files changed, 4 insertions(+) diff --git a/engine/src/components/afterburner.cpp b/engine/src/components/afterburner.cpp index 57aefb77c..160afd4b7 100644 --- a/engine/src/components/afterburner.cpp +++ b/engine/src/components/afterburner.cpp @@ -48,6 +48,7 @@ void Afterburner::Load(std::string upgrade_key, double consumption = UnitCSVFactory::GetVariable(unit_key, "Afterburner_Usage_Cost", 1.0); SetConsumption(consumption); + // We calculate percent operational as a simple average operational = (thrust.Percent() + speed.Percent()) / 2 * 100; } @@ -81,6 +82,7 @@ void Afterburner::Damage() { thrust.RandomDamage(); speed.RandomDamage(); + // We calculate percent operational as a simple average operational = (thrust.Percent() + speed.Percent()) / 2 * 100; } diff --git a/engine/src/components/drive.cpp b/engine/src/components/drive.cpp index 64c72cb14..0c3a1aa20 100644 --- a/engine/src/components/drive.cpp +++ b/engine/src/components/drive.cpp @@ -97,6 +97,7 @@ void Drive::Load(std::string upgrade_key, speed = Resource(UnitCSVFactory::GetVariable(unit_key, "Default_Speed_Governor", std::string("0.0")), game_speed, minimal_drive_functionality); + // We calculate percent operational as a simple average operational = (yaw.Percent() + pitch.Percent() + roll.Percent() + lateral.Percent() + vertical.Percent() + forward.Percent() + retro.Percent() + speed.Percent() + @@ -170,6 +171,7 @@ void Drive::Damage() { max_roll_left.RandomDamage(); max_roll_right.RandomDamage(); + // We calculate percent operational as a simple average operational = (yaw.Percent() + pitch.Percent() + roll.Percent() + lateral.Percent() + vertical.Percent() + forward.Percent() + retro.Percent() + speed.Percent() +