Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix issue where some component damage can't be fixed #925

Merged
merged 16 commits into from
Dec 8, 2024
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
5e0c681
Merge branch 'master' of https://github.com/vegastrike/Vega-Strike-En…
royfalk Dec 1, 2023
d5f7361
Merge branch 'master' of https://github.com/vegastrike/Vega-Strike-En…
royfalk Dec 3, 2023
d08bfcf
Merge branch 'master' of https://github.com/vegastrike/Vega-Strike-En…
royfalk Apr 25, 2024
5126833
Merge branch 'master' of https://github.com/vegastrike/Vega-Strike-En…
royfalk May 3, 2024
7fb35f5
Merge branch 'master' of https://github.com/vegastrike/Vega-Strike-En…
royfalk Jul 22, 2024
ad5c297
Merge branch 'master' of https://github.com/vegastrike/Vega-Strike-En…
royfalk Aug 15, 2024
08daa5b
Merge branch 'master' of https://github.com/vegastrike/Vega-Strike-En…
royfalk Sep 2, 2024
4354d63
Merge branch 'master' of https://github.com/vegastrike/Vega-Strike-En…
royfalk Oct 3, 2024
606f5d4
Merge branch 'master' of https://github.com/vegastrike/Vega-Strike-En…
royfalk Oct 14, 2024
d7dc075
Merge branch 'master' of https://github.com/vegastrike/Vega-Strike-En…
royfalk Oct 14, 2024
b7ce610
Merge branch 'master' of https://github.com/vegastrike/Vega-Strike-En…
royfalk Nov 2, 2024
bd42430
Merge branch 'master' of https://github.com/vegastrike/Vega-Strike-En…
royfalk Nov 15, 2024
4f72ce2
Merge branch 'master' of https://github.com/vegastrike/Vega-Strike-En…
royfalk Nov 21, 2024
a86672e
Merge branch 'master' of https://github.com/vegastrike/Vega-Strike-En…
royfalk Nov 25, 2024
cc9d5ad
Fix issue where some component damage can't be fixed
royfalk Dec 4, 2024
7a5ee8c
Add comments
royfalk Dec 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
2 changes: 2 additions & 0 deletions engine/src/components/afterburner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ 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);

operational = (thrust.Percent() + speed.Percent()) / 2 * 100;
}

void Afterburner::SaveToCSV(std::map<std::string, std::string>& unit) const {
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
6 changes: 6 additions & 0 deletions engine/src/components/drive.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,12 @@ 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);

operational = (yaw.Percent() + pitch.Percent() + roll.Percent() +
BenjamenMeyer marked this conversation as resolved.
Show resolved Hide resolved
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
Loading