Skip to content

Commit

Permalink
Add city repair depending on Construction Vehicles
Browse files Browse the repository at this point in the history
  • Loading branch information
kgd192 committed Jan 1, 2024
1 parent 77a5768 commit 247ca2f
Show file tree
Hide file tree
Showing 5 changed files with 149 additions and 48 deletions.
25 changes: 5 additions & 20 deletions framework/options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ void dumpOptionsToLog()
dumpOption(actionMusicOption);
dumpOption(autoExecuteOption);
dumpOption(toolTipDelay);
dumpOption(vanillaToggle);

dumpOption(optionPauseOnUfoSpotted);
dumpOption(optionPauseOnVehicleLightDamage);
Expand All @@ -75,7 +74,6 @@ void dumpOptionsToLog()
dumpOption(optionPauseOnVehicleRefuelled);
dumpOption(optionPauseOnNotEnoughFuel);
dumpOption(optionPauseOnUnauthorizedVehicle);
dumpOption(optionPauseOnBaseDestroyed);
dumpOption(optionPauseOnHostileSpotted);
dumpOption(optionPauseOnHostileDied);
dumpOption(optionPauseOnUnknownDied);
Expand All @@ -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);
Expand Down Expand Up @@ -134,8 +130,7 @@ void dumpOptionsToLog()
dumpOption(optionAutoReload);
dumpOption(optionLeftClickIcon);
dumpOption(optionBattlescapeVertScroll);
dumpOption(optionSingleSquadSelect);
dumpOption(optionATVUFOMission);
dumpOption(optionRepairWithConstructionVehicles);

dumpOption(optionStunHostileAction);
dumpOption(optionRaidHostileAction);
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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(
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand Down
7 changes: 1 addition & 6 deletions framework/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down
77 changes: 64 additions & 13 deletions game/state/city/city.cpp
Original file line number Diff line number Diff line change
@@ -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"
Expand Down Expand Up @@ -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<sp<Scenery>> 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<sp<Scenery>> repairedTogether;
Expand Down Expand Up @@ -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<sp<OpenApoc::Vehicle>> 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<OpenApoc::Vehicle> 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);
}
}
}
Expand Down
5 changes: 5 additions & 0 deletions game/state/city/vehicle.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -236,6 +238,9 @@ class Vehicle : public StateObject<Vehicle>,
StateRef<Vehicle> carriedVehicle;
StateRef<Vehicle> carriedByVehicle;

// How Many Tiles have already been repaired this night by this perticular vehicle
int tilesRepaired = 0;

sp<TileObjectVehicle> tileObject;
sp<TileObjectShadow> shadowObject;

Expand Down
83 changes: 74 additions & 9 deletions game/ui/general/ingameoptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <list>

namespace OpenApoc
Expand Down Expand Up @@ -69,9 +68,57 @@ std::list<std::pair<UString, UString>> cityNotificationList = {
{"Notifications.City", "VehicleRefuelled"},
{"Notifications.City", "NotEnoughFuel"},
{"Notifications.City", "UnauthorizedVehicle"},
{"Notifications.City", "BaseDestroyed"},
};

std::list<std::pair<UString, UString>> 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<UString> listNames = {tr("Message Toggles"), tr("OpenApoc Features")};
} // namespace

InGameOptions::InGameOptions(sp<GameState> state)
Expand All @@ -91,14 +138,22 @@ void InGameOptions::saveList()
}
}

void InGameOptions::loadList()
void InGameOptions::loadList(int id)
{
saveList();
menuform->findControlTyped<Label>("LIST_NAME")->setText(tr("Message Toggles"));
curId = id;
menuform->findControlTyped<Label>("LIST_NAME")->setText(listNames[curId]);
std::list<std::pair<UString, UString>> *notificationList = nullptr;

notificationList = state->current_battle ? &battleNotificationList : &cityNotificationList;

switch (curId)
{
case 0:
notificationList =
state->current_battle ? &battleNotificationList : &cityNotificationList;
break;
case 1:
notificationList = &openApocList;
break;
}
auto listControl = menuform->findControlTyped<ListBox>("NOTIFICATIONS_LIST");
listControl->clear();
auto font = ui().getFont("smalfont");
Expand All @@ -119,6 +174,16 @@ void InGameOptions::loadList()
}
}

void InGameOptions::loadNextList()
{
curId++;
if (curId > 1)
{
curId = 0;
}
loadList(curId);
}

void InGameOptions::begin()
{
/* Initialise all initial values */
Expand Down Expand Up @@ -154,7 +219,7 @@ void InGameOptions::begin()

menuform->findControlTyped<Label>("TEXT_FUNDS")->setText(state->getPlayerBalance());

loadList();
loadList(0);
}

void InGameOptions::pause() {}
Expand Down Expand Up @@ -235,7 +300,7 @@ void InGameOptions::eventOccurred(Event *e)
}
if (e->forms().RaisedBy->Name == "BUTTON_NEXT_LIST")
{
fw().stageQueueCommand({StageCmd::Command::PUSH, mksp<MoreOptions>(state)});
loadNextList();
return;
}
if (e->forms().RaisedBy->Name == "BUTTON_CHEATS")
Expand Down

0 comments on commit 247ca2f

Please sign in to comment.