From 247ca2f8a5ea9f249eb1ea6787fd86c26c2c6843 Mon Sep 17 00:00:00 2001 From: kgd192 <15697480+kgd192@users.noreply.github.com> Date: Sat, 22 Apr 2023 19:22:20 +0200 Subject: [PATCH] Add city repair depending on Construction Vehicles --- framework/options.cpp | 25 ++-------- framework/options.h | 7 +-- game/state/city/city.cpp | 77 +++++++++++++++++++++++----- game/state/city/vehicle.h | 5 ++ game/ui/general/ingameoptions.cpp | 83 +++++++++++++++++++++++++++---- 5 files changed, 149 insertions(+), 48 deletions(-) diff --git a/framework/options.cpp b/framework/options.cpp index 91e84d0c2..b4d11bf0c 100644 --- a/framework/options.cpp +++ b/framework/options.cpp @@ -54,7 +54,6 @@ void dumpOptionsToLog() dumpOption(actionMusicOption); dumpOption(autoExecuteOption); dumpOption(toolTipDelay); - dumpOption(vanillaToggle); dumpOption(optionPauseOnUfoSpotted); dumpOption(optionPauseOnVehicleLightDamage); @@ -75,7 +74,6 @@ void dumpOptionsToLog() dumpOption(optionPauseOnVehicleRefuelled); dumpOption(optionPauseOnNotEnoughFuel); dumpOption(optionPauseOnUnauthorizedVehicle); - dumpOption(optionPauseOnBaseDestroyed); dumpOption(optionPauseOnHostileSpotted); dumpOption(optionPauseOnHostileDied); dumpOption(optionPauseOnUnknownDied); @@ -95,11 +93,9 @@ void dumpOptionsToLog() dumpOption(optionPauseOnAgentPsiControlled); dumpOption(optionPauseOnAgentPsiOver); - dumpOption(optionDebugCommandsVisible); dumpOption(optionUFODamageModel); dumpOption(optionInstantExplosionDamage); dumpOption(optionGravliftSounds); - dumpOption(optionNoScrollSounds); dumpOption(optionNoInstantThrows); dumpOption(optionFerryChecksRelationshipWhenBuying); dumpOption(optionAllowManualCityTeleporters); @@ -134,8 +130,7 @@ void dumpOptionsToLog() dumpOption(optionAutoReload); dumpOption(optionLeftClickIcon); dumpOption(optionBattlescapeVertScroll); - dumpOption(optionSingleSquadSelect); - dumpOption(optionATVUFOMission); + dumpOption(optionRepairWithConstructionVehicles); dumpOption(optionStunHostileAction); dumpOption(optionRaidHostileAction); @@ -259,7 +254,6 @@ ConfigOptionBool autoExecuteOption("Options.Misc", "AutoExecute", ConfigOptionInt toolTipDelay("Options.Misc", "ToolTipDelay", "Delay in milliseconds before showing tooltips (<= 0 to disable)", 500); -ConfigOptionBool vanillaToggle("Options.Misc", "VanillaToggle", "Toggle vanilla mode", false); ConfigOptionBool optionPauseOnUfoSpotted("Notifications.City", "UfoSpotted", "UFO spotted", true); ConfigOptionBool optionPauseOnVehicleLightDamage("Notifications.City", "VehicleLightDamage", @@ -298,8 +292,6 @@ ConfigOptionBool optionPauseOnNotEnoughFuel("Notifications.City", "NotEnoughFuel "Not enough fuel to refuel vehicle", true); ConfigOptionBool optionPauseOnUnauthorizedVehicle("Notifications.City", "UnauthorizedVehicle", "Unauthorized vehicle detected", true); -ConfigOptionBool optionPauseOnBaseDestroyed("Notifications.City", "BaseDestroyed", - "X-COM base destroyed by hostile forces.", true); ConfigOptionBool optionPauseOnHostileSpotted("Notifications.Battle", "HostileSpotted", "Hostile unit spotted", true); ConfigOptionBool optionPauseOnHostileDied("Notifications.Battle", "HostileDied", @@ -338,16 +330,12 @@ ConfigOptionBool optionPauseOnAgentPsiControlled("Notifications.Battle", "AgentP ConfigOptionBool optionPauseOnAgentPsiOver("Notifications.Battle", "AgentPsiOver", "Unit freed from Psionic control", true); -ConfigOptionBool optionDebugCommandsVisible("OpenApoc.NewFeature", "DebugCommandsVisible", - "Show the debug commands on screen", true); ConfigOptionBool optionUFODamageModel("OpenApoc.NewFeature", "UFODamageModel", "X-Com 1 Damage model (0-200%)", false); ConfigOptionBool optionInstantExplosionDamage("OpenApoc.NewFeature", "InstantExplosionDamage", "Explosions damage instantly", false); ConfigOptionBool optionGravliftSounds("OpenApoc.NewFeature", "GravliftSounds", "Gravlift sounds", true); -ConfigOptionBool optionNoScrollSounds("OpenApoc.NewFeature", "NoScrollSounds", - "Disable scrolling sounds", false); ConfigOptionBool optionNoInstantThrows("OpenApoc.NewFeature", "NoInstantThrows", "Throwing requires proper facing and pose", true); ConfigOptionBool optionFerryChecksRelationshipWhenBuying( @@ -422,12 +410,9 @@ ConfigOptionBool optionLeftClickIcon("OpenApoc.NewFeature", "LeftClickIconEquip" ConfigOptionBool optionBattlescapeVertScroll("OpenApoc.NewFeature", "BattlescapeVertScroll", "Mousewheel changes vertical level in battlescape", true); -ConfigOptionBool optionSingleSquadSelect("OpenApoc.NewFeature", "SingleSquadSelect", - "Select squad with single click", false); -ConfigOptionBool - optionATVUFOMission("OpenApoc.NewFeature", "ATVUFOMission", - "Allow ATV vehicles to initiate UFO missions (and recover vehicles)", - false); +ConfigOptionBool optionRepairWithConstructionVehicles( + "OpenApoc.NewFeature", "RepairWithConstructionVehicles", + "Repair Buildings depending on the availability of Construction Vehicles", false); ConfigOptionBool optionStunHostileAction("OpenApoc.Mod", "StunHostileAction", "Stunning hurts relationships", false); @@ -448,7 +433,7 @@ ConfigOptionBool optionCrashingVehicles("OpenApoc.Mod", "CrashingVehicles", ConfigOptionString optionScriptsList("OpenApoc.Mod", "ScriptsList", "Semicolon-separated list of scripts to load", - "scripts/openapoc_base.lua;"); + "data/scripts/openapoc_base.lua;"); ConfigOptionBool optionInfiniteAmmoCheat("OpenApoc.Cheat", "InfiniteAmmo", "Infinite ammo for X-Com agents and vehicles", false); diff --git a/framework/options.h b/framework/options.h index a35615dc7..12788fc28 100644 --- a/framework/options.h +++ b/framework/options.h @@ -32,7 +32,6 @@ extern ConfigOptionBool autoScrollOption; extern ConfigOptionBool actionMusicOption; extern ConfigOptionBool autoExecuteOption; extern ConfigOptionInt toolTipDelay; -extern ConfigOptionBool vanillaToggle; extern ConfigOptionBool optionPauseOnUfoSpotted; extern ConfigOptionBool optionPauseOnVehicleLightDamage; @@ -53,7 +52,6 @@ extern ConfigOptionBool optionPauseOnNotEnoughAmmo; extern ConfigOptionBool optionPauseOnVehicleRefuelled; extern ConfigOptionBool optionPauseOnNotEnoughFuel; extern ConfigOptionBool optionPauseOnUnauthorizedVehicle; -extern ConfigOptionBool optionPauseOnBaseDestroyed; extern ConfigOptionBool optionPauseOnHostileSpotted; extern ConfigOptionBool optionPauseOnHostileDied; extern ConfigOptionBool optionPauseOnUnknownDied; @@ -73,11 +71,9 @@ extern ConfigOptionBool optionPauseOnAgentPsiAttacked; extern ConfigOptionBool optionPauseOnAgentPsiControlled; extern ConfigOptionBool optionPauseOnAgentPsiOver; -extern ConfigOptionBool optionDebugCommandsVisible; extern ConfigOptionBool optionUFODamageModel; extern ConfigOptionBool optionInstantExplosionDamage; extern ConfigOptionBool optionGravliftSounds; -extern ConfigOptionBool optionNoScrollSounds; extern ConfigOptionBool optionNoInstantThrows; extern ConfigOptionBool optionFerryChecksRelationshipWhenBuying; extern ConfigOptionBool optionAllowManualCityTeleporters; @@ -112,8 +108,7 @@ extern ConfigOptionBool optionSeedRng; extern ConfigOptionBool optionAutoReload; extern ConfigOptionBool optionLeftClickIcon; extern ConfigOptionBool optionBattlescapeVertScroll; -extern ConfigOptionBool optionSingleSquadSelect; -extern ConfigOptionBool optionATVUFOMission; +extern ConfigOptionBool optionRepairWithConstructionVehicles; extern ConfigOptionBool optionStunHostileAction; extern ConfigOptionBool optionRaidHostileAction; diff --git a/game/state/city/city.cpp b/game/state/city/city.cpp index 40881dcd8..3f3c25dde 100644 --- a/game/state/city/city.cpp +++ b/game/state/city/city.cpp @@ -1,4 +1,5 @@ #include "game/state/city/city.h" +#include "framework/configfile.h"; #include "framework/framework.h" #include "framework/sound.h" #include "game/state/city/base.h" @@ -432,7 +433,11 @@ void City::repairScenery(GameState &state) sceneryToRepair.insert(s); } } - // Pick one scenery, add all scenery that must be repaired together, try to repair them + + std::queue> repairQueue; + // Find all scenery which should be repaired this night and add them to the repair Queue + // Pick one scenery, add all scenery that must be repaired together, then find the lowest of + // them while (!sceneryToRepair.empty()) { std::set> repairedTogether; @@ -482,25 +487,71 @@ void City::repairScenery(GameState &state) } } - // check if sufficient funds are available - auto initialType = initial_tiles[lowestLevel.get()->initialPosition]; - auto owner = lowestLevel->building && !initialType->commonProperty - ? lowestLevel.get()->building->owner - : state.getGovernment(); - if (owner->balance < initialType->value) + repairQueue.push(lowestLevel); + } + + std::set> constructionVehicles; + // find available construction vehicles + for (auto &v : state.vehicles) + { + if (v.second->name.find("Construction") != std::string::npos && !v.second->crashed) { - break; + constructionVehicles.insert(v.second); + } + } + + // Actually start repairing as long as enought funds and construction vehicles are available + // this night + while (!repairQueue.empty()) + { + auto &s = repairQueue.front(); + auto initialType = initial_tiles[s->initialPosition]; + auto buildingOwner = s->building && !initialType->commonProperty ? s.get()->building->owner + : state.getGovernment(); + + // search for available construction vehicles + sp currentVehicle = NULL; + for (auto &v : constructionVehicles) + { + if (v->owner == buildingOwner) + { + currentVehicle = v; + break; + } + } + + // if no own vehicles found look for allied vehicles + if (currentVehicle == NULL) + for (auto &v : constructionVehicles) + { + // if relation is friendly or allied, help them bros out + if (buildingOwner->getRelationTo(v->owner) > +24.0f) + { + currentVehicle = v; + break; + } + } + + // check if sufficient funds are available, the tile is still dead and a construction + // vehicle is available (when enabled) + if (buildingOwner->balance < initialType->value || s->isAlive() || + (currentVehicle == NULL && + config().getBool("OpenApoc.NewFeature.RepairWithConstructionVehicles"))) + { + repairQueue.pop(); + continue; } else { // pay - owner->balance -= initialType->value; + buildingOwner->balance -= initialType->value; // repair - lowestLevel->repair(state); + s->repair(state); // delete out of list to prevent repairing again - auto pointer = sceneryToRepair.find(lowestLevel); - if (sceneryToRepair.end() != pointer) - sceneryToRepair.erase(pointer); + repairQueue.pop(); + if (config().getBool("OpenApoc.NewFeature.RepairWithConstructionVehicles") && + currentVehicle->tilesRepaired++ > OpenApoc::MAX_TILE_REPAIR) + constructionVehicles.erase(currentVehicle); } } } diff --git a/game/state/city/vehicle.h b/game/state/city/vehicle.h index 59bfe808e..282c46617 100644 --- a/game/state/city/vehicle.h +++ b/game/state/city/vehicle.h @@ -57,6 +57,8 @@ static const int FV_SCRAPPED_COST_PERCENT = 25; static const int FUEL_TICKS_PER_SECOND = 144; // How much ticks is required to spend one unit of fuel static const int FUEL_TICKS_PER_UNIT = 40000; +// How much tiles can one construction vehicle repair at one single night +static const int MAX_TILE_REPAIR = 20; class Image; class TileObjectVehicle; @@ -236,6 +238,9 @@ class Vehicle : public StateObject, StateRef carriedVehicle; StateRef carriedByVehicle; + // How Many Tiles have already been repaired this night by this perticular vehicle + int tilesRepaired = 0; + sp tileObject; sp shadowObject; diff --git a/game/ui/general/ingameoptions.cpp b/game/ui/general/ingameoptions.cpp index f5613b716..bdbb6d52a 100644 --- a/game/ui/general/ingameoptions.cpp +++ b/game/ui/general/ingameoptions.cpp @@ -21,7 +21,6 @@ #include "game/ui/general/savemenu.h" #include "game/ui/skirmish/skirmish.h" #include "game/ui/tileview/cityview.h" -#include "moreoptions.h" #include namespace OpenApoc @@ -69,9 +68,57 @@ std::list> cityNotificationList = { {"Notifications.City", "VehicleRefuelled"}, {"Notifications.City", "NotEnoughFuel"}, {"Notifications.City", "UnauthorizedVehicle"}, - {"Notifications.City", "BaseDestroyed"}, }; +std::list> openApocList = { + {"OpenApoc.NewFeature", "UFODamageModel"}, + {"OpenApoc.NewFeature", "InstantExplosionDamage"}, + {"OpenApoc.NewFeature", "GravliftSounds"}, + {"OpenApoc.NewFeature", "NoInstantThrows"}, + {"OpenApoc.NewFeature", "PayloadExplosion"}, + {"OpenApoc.NewFeature", "DisplayUnitPaths"}, + {"OpenApoc.NewFeature", "AdditionalUnitIcons"}, + {"OpenApoc.NewFeature", "AllowForceFiringParallel"}, + {"OpenApoc.NewFeature", "RequireLOSToMaintainPsi"}, + {"OpenApoc.NewFeature", "AdvancedInventoryControls"}, + {"OpenApoc.NewFeature", "EnableAgentTemplates"}, + {"OpenApoc.NewFeature", "FerryChecksRelationshipWhenBuying"}, + {"OpenApoc.NewFeature", "AllowManualCityTeleporters"}, + {"OpenApoc.NewFeature", "AllowManualCargoFerry"}, + {"OpenApoc.NewFeature", "AllowSoldierTaxiUse"}, + {"OpenApoc.NewFeature", "AllowAttackingOwnedVehicles"}, + {"OpenApoc.NewFeature", "CallExistingFerry"}, + {"OpenApoc.NewFeature", "AlternateVehicleShieldSound"}, + {"OpenApoc.NewFeature", "StoreDroppedEquipment"}, + {"OpenApoc.NewFeature", "EnforceCargoLimits"}, + {"OpenApoc.NewFeature", "AllowNearbyVehicleLootPickup"}, + {"OpenApoc.NewFeature", "AllowBuildingLootDeposit"}, + {"OpenApoc.NewFeature", "ArmoredRoads"}, + {"OpenApoc.NewFeature", "CrashingGroundVehicles"}, + {"OpenApoc.NewFeature", "OpenApocCityControls"}, + {"OpenApoc.NewFeature", "CollapseRaidedBuilding"}, + {"OpenApoc.NewFeature", "ScrambleOnUnintentionalHit"}, + {"OpenApoc.NewFeature", "MarketOnRight"}, + {"OpenApoc.NewFeature", "CrashingDimensionGate"}, + {"OpenApoc.NewFeature", "SkipTurboMovement"}, + {"OpenApoc.NewFeature", "CrashingOutOfFuel"}, + {"OpenApoc.NewFeature", "RunAndKneel"}, + {"OpenApoc.NewFeature", "SeedRng"}, + {"OpenApoc.NewFeature", "AutoReload"}, + {"OpenApoc.NewFeature", "LeftClickIconEquip"}, + {"OpenApoc.NewFeature", "BattlescapeVertScroll"}, + {"OpenApoc.NewFeature", "RepairWithConstructionVehicles"}, + + {"OpenApoc.Mod", "StunHostileAction"}, + {"OpenApoc.Mod", "RaidHostileAction"}, + {"OpenApoc.Mod", "CrashingVehicles"}, + {"OpenApoc.Mod", "InvulnerableRoads"}, + {"OpenApoc.Mod", "ATVTank"}, + {"OpenApoc.Mod", "ATVAPC"}, + {"OpenApoc.Mod", "BSKLauncherSound"}, +}; + +std::vector listNames = {tr("Message Toggles"), tr("OpenApoc Features")}; } // namespace InGameOptions::InGameOptions(sp state) @@ -91,14 +138,22 @@ void InGameOptions::saveList() } } -void InGameOptions::loadList() +void InGameOptions::loadList(int id) { saveList(); - menuform->findControlTyped