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..160afd4b7 100644 --- a/engine/src/components/afterburner.cpp +++ b/engine/src/components/afterburner.cpp @@ -47,6 +47,9 @@ 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); + + // We calculate percent operational as a simple average + operational = (thrust.Percent() + speed.Percent()) / 2 * 100; } void Afterburner::SaveToCSV(std::map& unit) const { @@ -79,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/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..0c3a1aa20 100644 --- a/engine/src/components/drive.cpp +++ b/engine/src/components/drive.cpp @@ -96,6 +96,13 @@ 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() + + 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; } @@ -164,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() +