Skip to content

Commit

Permalink
Fix issue where some component damage can't be fixed (#925)
Browse files Browse the repository at this point in the history
- Basic Repair to factor damage to these components
- Make Basic Repair also repair this damage
  • Loading branch information
royfalk authored Dec 8, 2024
1 parent 69e3fb2 commit 9b89334
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 6 deletions.
39 changes: 34 additions & 5 deletions engine/src/cmd/unit_generic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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")) {
Expand All @@ -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;
}
Expand Down Expand Up @@ -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;
Expand All @@ -3304,6 +3322,7 @@ int Unit::RepairCost() {
return cost;
}

// This is called when performing a BASIC_REPAIR
int Unit::RepairUpgrade() {
vector<Cargo> savedCargo;
savedCargo.swap(cargo);
Expand Down Expand Up @@ -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 =
Expand Down Expand Up @@ -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)) {
Expand Down
4 changes: 4 additions & 0 deletions engine/src/components/afterburner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ void Afterburner::Load(std::string upgrade_key,
speed = Resource<double>(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<std::string, std::string>& unit) const {
Expand Down Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion engine/src/components/component.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ void Component::Repair() {
}

bool Component::Damaged() const {
return operational.Damaged();
return operational.Value() < operational.MaxValue();
}

bool Component::Destroyed() const {
Expand Down
8 changes: 8 additions & 0 deletions engine/src/components/drive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,13 @@ void Drive::Load(std::string upgrade_key,

speed = Resource<double>(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;
}


Expand Down Expand Up @@ -171,6 +178,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() +
Expand Down

0 comments on commit 9b89334

Please sign in to comment.