Skip to content

Commit

Permalink
Only Repair allied Tiles if no own destroyed Tiles, Introduce Cost Fa…
Browse files Browse the repository at this point in the history
…ctor
  • Loading branch information
kgd192 committed Jan 17, 2024
1 parent 3ef0ee1 commit 64deaf3
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 16 deletions.
10 changes: 8 additions & 2 deletions framework/options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,6 @@ void dumpOptionsToLog()
dumpOption(optionEnableAgentTemplates);
dumpOption(optionStoreDroppedEquipment);
dumpOption(optionFallingGroundVehicles);
dumpOption(optionMaxTileRepair);

dumpOption(optionEnforceCargoLimits);
dumpOption(optionAllowNearbyVehicleLootPickup);
Expand All @@ -137,6 +136,8 @@ void dumpOptionsToLog()
dumpOption(optionBattlescapeVertScroll);
dumpOption(optionSingleSquadSelect);
dumpOption(optionATVUFOMission);
dumpOption(optionMaxTileRepair);
dumpOption(optionSceneryRepairCostFactor);

dumpOption(optionStunHostileAction);
dumpOption(optionRaidHostileAction);
Expand Down Expand Up @@ -429,8 +430,13 @@ ConfigOptionBool
"Allow ATV vehicles to initiate UFO missions (and recover vehicles)",
false);
ConfigOptionInt
optionMaxTileRepair("OpenApoc.NewFeature", "MaxTileRepair",
optionMaxTileRepair("OpenApoc.Mod", "MaxTileRepair",
"Construction Vehicles will repair a maximum of X Tiles per night", 5);
ConfigOptionFloat
optionSceneryRepairCostFactor("OpenApoc.Mod", "SceneryRepairCostFactor",
"Determines the percentage of the original Price ORGs have to "
"pay for a Scenery Tile to be repaired",
1.0f);

ConfigOptionBool optionStunHostileAction("OpenApoc.Mod", "StunHostileAction",
"Stunning hurts relationships", false);
Expand Down
3 changes: 2 additions & 1 deletion framework/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,6 @@ extern ConfigOptionBool optionAlternateVehicleShieldSound;
extern ConfigOptionBool optionEnableAgentTemplates;
extern ConfigOptionBool optionStoreDroppedEquipment;
extern ConfigOptionBool optionFallingGroundVehicles;
extern ConfigOptionInt optionMaxTileRepair;

extern ConfigOptionBool optionEnforceCargoLimits;
extern ConfigOptionBool optionAllowNearbyVehicleLootPickup;
Expand All @@ -115,6 +114,8 @@ extern ConfigOptionBool optionLeftClickIcon;
extern ConfigOptionBool optionBattlescapeVertScroll;
extern ConfigOptionBool optionSingleSquadSelect;
extern ConfigOptionBool optionATVUFOMission;
extern ConfigOptionInt optionMaxTileRepair;
extern ConfigOptionFloat optionSceneryRepairCostFactor;

extern ConfigOptionBool optionStunHostileAction;
extern ConfigOptionBool optionRaidHostileAction;
Expand Down
39 changes: 26 additions & 13 deletions game/state/city/city.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -426,6 +426,7 @@ void City::repairScenery(GameState &state, bool debugRepair)
}

std::set<sp<OpenApoc::Vehicle>> constructionVehicles = findConstructionVehicles(state);
bool ownBuildingsOnly = true;

while (!constructionVehicles.empty() || debugRepair)
{
Expand Down Expand Up @@ -494,17 +495,19 @@ void City::repairScenery(GameState &state, bool debugRepair)

// search for available construction vehicles
sp<OpenApoc::Vehicle> currentVehicle = NULL;
for (auto &v : constructionVehicles)
if (ownBuildingsOnly)
{
if (v->owner == buildingOwner)
for (auto &v : constructionVehicles)
{
currentVehicle = v;
break;
if (v->owner == buildingOwner)
{
currentVehicle = v;
break;
}
}
}

// if no own vehicles found look for allied vehicles
if (currentVehicle == NULL)
else
{
for (auto &v : constructionVehicles)
{
// if relation is friendly or allied, help them bros out
Expand All @@ -514,7 +517,7 @@ void City::repairScenery(GameState &state, bool debugRepair)
break;
}
}

}
// check if sufficient funds are available, the tile is still dead and a construction
// vehicle is available
if (buildingOwner->balance < initialType->value || s->isAlive() ||
Expand All @@ -526,23 +529,33 @@ void City::repairScenery(GameState &state, bool debugRepair)
else
{
// pay
buildingOwner->balance -= initialType->value;
buildingOwner->balance -=
initialType->value * config().getFloat("OpenApoc.Mod.SceneryRepairCostFactor");
// repair
s->repair(state);
// delete out of list to prevent repairing again
repairQueue.pop();
tilesRepaired++;
if (currentVehicle && currentVehicle->tilesRepaired++ >
config().getInt("OpenApoc.NewFeature.MaxTileRepair"))
if (currentVehicle &&
currentVehicle->tilesRepaired++ > config().getInt("OpenApoc.Mod.MaxTileRepair"))
{
constructionVehicles.erase(currentVehicle);
}
}
}
// No Tiles repaired in last iteration due to no funds or vehicle match
// No Tiles repaired in last iteration due to no funds or vehicle match, look to help
// allies, otherwise break
if (tilesRepaired <= 0 || debugRepair)
{
break;
if (ownBuildingsOnly)
{
ownBuildingsOnly = false;
continue;
}
else
{
break;
}
}
}

Expand Down

0 comments on commit 64deaf3

Please sign in to comment.