Skip to content

Commit

Permalink
Check scripted conditions for a unit's current variation when an upgr…
Browse files Browse the repository at this point in the history
…ade is applied to it
  • Loading branch information
Andrettin committed Dec 31, 2020
1 parent 5b41abb commit f97967b
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 74 deletions.
2 changes: 1 addition & 1 deletion src/unit/unit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,7 @@ void CUnit::SetResourcesHeld(int quantity)

const wyrmgus::unit_type_variation *variation = this->GetVariation();
if (
variation
variation != nullptr
&& (
(variation->ResourceMin && this->ResourcesHeld < variation->ResourceMin)
|| (variation->ResourceMax && this->ResourcesHeld > variation->ResourceMax)
Expand Down
89 changes: 16 additions & 73 deletions src/upgrade/upgrade.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1579,30 +1579,15 @@ static void ApplyUpgradeModifier(CPlayer &player, const wyrmgus::upgrade_modifie

//change variation if current one becomes forbidden
const wyrmgus::unit_type_variation *current_variation = unit.GetVariation();
if (current_variation) {
bool upgrade_forbidden = false;
for (const CUpgrade *forbidden_upgrade : current_variation->UpgradesForbidden) {
if (um->UpgradeId == forbidden_upgrade->ID) {
upgrade_forbidden = true;
break;
}
}
if (upgrade_forbidden == true) {
if (current_variation != nullptr) {
if (!unit.can_have_variation(current_variation)) {
unit.ChooseVariation();
}
}
for (int i = 0; i < MaxImageLayers; ++i) {
const wyrmgus::unit_type_variation *current_layer_variation = unit.GetLayerVariation(i);
if (current_layer_variation) {
bool upgrade_forbidden = false;
for (const CUpgrade *forbidden_upgrade : current_layer_variation->UpgradesForbidden) {
if (um->UpgradeId == forbidden_upgrade->ID) {
upgrade_forbidden = true;
break;
}
}

if (upgrade_forbidden == true) {
if (current_layer_variation != nullptr) {
if (!unit.can_have_variation(current_layer_variation)) {
unit.ChooseVariation(nullptr, false, i);
}
}
Expand Down Expand Up @@ -1873,29 +1858,15 @@ static void RemoveUpgradeModifier(CPlayer &player, const wyrmgus::upgrade_modifi

//change variation if current one becomes forbidden
const wyrmgus::unit_type_variation *current_variation = unit.GetVariation();
if (current_variation) {
bool upgrade_required = false;
for (const CUpgrade *required_upgrade : current_variation->UpgradesRequired) {
if (um->UpgradeId == required_upgrade->ID) {
upgrade_required = true;
break;
}
}
if (upgrade_required == true) {
if (current_variation != nullptr) {
if (!unit.can_have_variation(current_variation)) {
unit.ChooseVariation();
}
}
for (int i = 0; i < MaxImageLayers; ++i) {
const wyrmgus::unit_type_variation *current_layer_variation = unit.GetLayerVariation(i);
if (current_layer_variation) {
bool upgrade_required = false;
for (const CUpgrade *required_upgrade : current_layer_variation->UpgradesRequired) {
if (um->UpgradeId == required_upgrade->ID) {
upgrade_required = true;
break;
}
}
if (upgrade_required == true) {
if (current_layer_variation != nullptr) {
if (!unit.can_have_variation(current_layer_variation)) {
unit.ChooseVariation(nullptr, false, i);
}
}
Expand Down Expand Up @@ -1979,29 +1950,15 @@ void ApplyIndividualUpgradeModifier(CUnit &unit, const wyrmgus::upgrade_modifier
//Wyrmgus start
//change variation if current one becomes forbidden
const wyrmgus::unit_type_variation *current_variation = unit.GetVariation();
if (current_variation) {
bool upgrade_forbidden = false;
for (const CUpgrade *forbidden_upgrade : current_variation->UpgradesForbidden) {
if (um->UpgradeId == forbidden_upgrade->ID) {
upgrade_forbidden = true;
break;
}
}
if (upgrade_forbidden == true) {
if (current_variation != nullptr) {
if (!unit.can_have_variation(current_variation)) {
unit.ChooseVariation();
}
}
for (int i = 0; i < MaxImageLayers; ++i) {
const wyrmgus::unit_type_variation *current_layer_variation = unit.GetLayerVariation(i);
if (current_layer_variation) {
bool upgrade_forbidden = false;
for (const CUpgrade *forbidden_upgrade : current_layer_variation->UpgradesForbidden) {
if (um->UpgradeId == forbidden_upgrade->ID) {
upgrade_forbidden = true;
break;
}
}
if (upgrade_forbidden == true) {
if (current_layer_variation != nullptr) {
if (!unit.can_have_variation(current_layer_variation)) {
unit.ChooseVariation(nullptr, false, i);
}
}
Expand Down Expand Up @@ -2075,29 +2032,15 @@ void RemoveIndividualUpgradeModifier(CUnit &unit, const wyrmgus::upgrade_modifie
//Wyrmgus start
//change variation if current one becomes forbidden
const wyrmgus::unit_type_variation *current_variation = unit.GetVariation();
if (current_variation) {
bool upgrade_required = false;
for (const CUpgrade *required_upgrade : current_variation->UpgradesRequired) {
if (um->UpgradeId == required_upgrade->ID) {
upgrade_required = true;
break;
}
}
if (upgrade_required == true) {
if (current_variation != nullptr) {
if (!unit.can_have_variation(current_variation)) {
unit.ChooseVariation();
}
}
for (int i = 0; i < MaxImageLayers; ++i) {
const wyrmgus::unit_type_variation *current_layer_variation = unit.GetLayerVariation(i);
if (current_layer_variation) {
bool upgrade_required = false;
for (const CUpgrade *required_upgrade : current_layer_variation->UpgradesRequired) {
if (um->UpgradeId == required_upgrade->ID) {
upgrade_required = true;
break;
}
}
if (upgrade_required == true) {
if (current_layer_variation != nullptr) {
if (!unit.can_have_variation(current_layer_variation)) {
unit.ChooseVariation(nullptr, false, i);
}
}
Expand Down

0 comments on commit f97967b

Please sign in to comment.