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 support for new DSP game version with new config entries #18

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
118 changes: 101 additions & 17 deletions AutoStationConfig/AspConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,20 @@
// ReSharper disable ConvertToConstant.Local
namespace Pasukaru.DSP.AutoStationConfig
{

public static class AspConfig
{
private static readonly string GENERAL_SECTION = "General";
private static readonly string PLS_SECTION = "Planetary Logistics Station";
private static readonly string ILS_SECTION = "Interstellar Logistics Station";
private static readonly string AMM_SECTION = "Advanced Mining Machine";
private static readonly string LD_SECTION = "Logistics Distributor";

public static class General
{
public static ConfigEntry<bool> NotifyWhenDroneOrVesselMissing;
public static ConfigEntry<bool> PlaySoundWhenDroneOrVesselMissing;
public static ConfigEntry<bool> PatchWarperConfigOnSaveLoad;
public static ConfigEntry<bool> EnableAutoReplenish;
}

public static class PLS
Expand All @@ -24,6 +26,8 @@ public static class PLS
public static ConfigEntry<int> DroneTransportRange;
public static ConfigEntry<int> MinDroneLoad;
public static ConfigEntry<double> DroneInsertPercentage;

public static ConfigEntry<int> StackCount;
}

public static class ILS
Expand All @@ -46,6 +50,22 @@ public static class ILS

public static ConfigEntry<bool> UseOrbitalCollectors;
public static ConfigEntry<bool> MustEquipWarp;

public static ConfigEntry<int> StackCount;
}

public static class AMM
{
public static ConfigEntry<int> GatheringSpeedInPercent;

public static ConfigEntry<int> StackCount;
}

public static class LD
{
public static ConfigEntry<int> ChargingPowerInPercent;
public static ConfigEntry<double> BotInsertPercentage;
public static ConfigEntry<bool> AlwaysGuessFilter;
}


Expand All @@ -57,16 +77,20 @@ internal static void Init(ConfigFile config)
General.NotifyWhenDroneOrVesselMissing =
config.Bind(GENERAL_SECTION, "Notify when Drone or Vessel missing", true,
"Sends a notification when there are not enough drones or vessel in your inventory to auto fill");

General.PlaySoundWhenDroneOrVesselMissing =
config.Bind(GENERAL_SECTION, "Play sound when Drone or Vessel missing", true,
"Plays a sound along to the drone/vessel notification. Only works when the notification is turned on.");

General.PatchWarperConfigOnSaveLoad =
config.Bind(GENERAL_SECTION, "Patch ILS Warper config after loading a save", true,
"Patches broken warper configs from previous versions of this mod. See github ticket #12 for details: https://github.com/Pasukaru/DSP-Mods/issues/12\n\n" +
"It only needs to run once. So load up your save game, then save it and close the game. Then disable this setting for a possibly faster loading (on large save games).");


General.EnableAutoReplenish =
config.Bind(GENERAL_SECTION, "Enable AutoReplenishment", false,
"Enable auto-replenishment for PLS/ILS/LD by default, this will override use of Drone/Vessel/Bot Insert Percentage config entries");

////////////////
// PLS Config //
////////////////
Expand All @@ -78,7 +102,8 @@ internal static void Init(ConfigFile config)
PLS.ChargingPowerInPercent = config.Bind(PLS_SECTION, "Charging Power", 100,
new ConfigDescription(
"Maximum power load in percent. For a vanilla PLS, 10% = 6MW, 100% = 60MW",
new AcceptableValueRange<int>(10, 100),
new AcceptableValueList<int>(10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95,
100),
new { }
)
);
Expand All @@ -97,7 +122,7 @@ internal static void Init(ConfigFile config)
PLS.MinDroneLoad = config.Bind(PLS_SECTION, "Min Load of Drones", 100,
new ConfigDescription(
"Min. Load of Drones in percent.",
new AcceptableValueRange<int>(1,100),
new AcceptableValueList<int>(1, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100),
new { }
)
);
Expand All @@ -110,6 +135,14 @@ internal static void Init(ConfigFile config)
)
);

PLS.StackCount = config.Bind(PLS_SECTION, "Output Cargo Stack Count", 0,
new ConfigDescription(
"Default output cargo stack count for PLS. 0 = Use tech limit",
new AcceptableValueRange<int>(0, 4),
new { }
)
);

////////////////
// ILS Config //
////////////////
Expand All @@ -133,7 +166,7 @@ internal static void Init(ConfigFile config)
ILS.MinDroneLoad = config.Bind(ILS_SECTION, "Min Load of Drones", 100,
new ConfigDescription(
"Min. Load of Drones in percent.",
new AcceptableValueRange<int>(1,100),
new AcceptableValueList<int>(1, 10, 20, 30, 40, 50, 60, 70, 80, 90, 100),
new { }
)
);
Expand All @@ -154,15 +187,15 @@ internal static void Init(ConfigFile config)
new { }
)
);

ILS.MinVesselLoad = config.Bind(ILS_SECTION, "Min Load of Vessels", 100,
new ConfigDescription(
"Min. Load of Vessels in percent.",
new AcceptableValueRange<int>(1,100),
new AcceptableValueRange<int>(1, 100),
new { }
)
);

ILS.VesselInsertPercentage = config.Bind(ILS_SECTION, "Vessel Insert Percentage", 1d,
new ConfigDescription(
"Amount of vessels to insert. 0.01 = 1%. For vanilla ILS, 0.15 => 10/100*15 = 1.5, rounded down to 1.",
Expand All @@ -178,10 +211,9 @@ internal static void Init(ConfigFile config)
new { }
)
);



ILS.WarperInLastItemSlot = config.Bind(ILS_SECTION, "Add Warpers in last Slot", true,
"If true, the last item slot will automatically select Space Warpers"
"If true, the last item slot will automatically select Space Warpers"
);

ILS.WarperDemand = config.Bind(ILS_SECTION, "Warper Demand", 1, new ConfigDescription(
Expand All @@ -190,20 +222,72 @@ internal static void Init(ConfigFile config)
new { }
)
);

ILS.WarperLocalMode = config.Bind(ILS_SECTION, "Warper Local Mode", ELogisticStorage.Demand,
"Local logistics mode of the Warpers when \"Add Warpers in last Slot\" is true"
);

ILS.WarperRemoteMode = config.Bind(ILS_SECTION, "Warper Remote Mode", ELogisticStorage.None,
"Remote logistics mode of the Warpers when \"Add Warpers in last Slot\" is true"
);

ILS.UseOrbitalCollectors = config.Bind(ILS_SECTION, "Pull from Orbital Collectors?", true,
"Toggle to retrieve from Orbital collectors.");

ILS.MustEquipWarp = config.Bind(ILS_SECTION, "Must Equip Warpers", true,
"Toggle for must equip warpers.");

ILS.StackCount = config.Bind(ILS_SECTION, "Output Cargo Stack Count", 0,
new ConfigDescription(
"Default output cargo stack count for ILS. 0 = Use tech limit",
new AcceptableValueRange<int>(0, 4),
new { }
)
);

////////////////
// AMM Config //
////////////////

AMM.GatheringSpeedInPercent = config.Bind(AMM_SECTION, "Gathering Speed", 100,
new ConfigDescription(
"Gathering speed in percent for AMM.",
new AcceptableValueList<int>(100, 110, 120, 130, 140, 150, 160, 170, 180, 190, 200, 210, 220, 230,
240, 250, 260, 270, 280, 290, 300),
new { }
)
);

AMM.StackCount = config.Bind(AMM_SECTION, "Output Cargo Stack Count", 0,
new ConfigDescription(
"Default output cargo stack count for AMM. 0 = Use tech limit",
new AcceptableValueRange<int>(0, 4),
new { }
)
);

///////////////
// LD Config //
///////////////

LD.ChargingPowerInPercent = config.Bind(LD_SECTION, "Charging Power", 100,
new ConfigDescription(
"Maximum power load in percent. For a vanilla LD, 10% = 900kW, 100% = 9MW",
new AcceptableValueRange<int>(10, 100),
new { }
)
);

LD.BotInsertPercentage = config.Bind(LD_SECTION, "Bot Insert Percentage", 1d,
new ConfigDescription(
"Amount of bots to insert. For vanilla LD, 0.25 = 10% = 10/100*15 = 2.5, rounded down to 2.",
new AcceptableValueRange<double>(0, 1),
new { }
)
);

LD.AlwaysGuessFilter = config.Bind(LD_SECTION, "Always Guess Filter", false,
"Always guess item filter even when copying LD. Note: Filter on copied LD will be retained if nothing can be guessed out.");
}
}
}
39 changes: 35 additions & 4 deletions AutoStationConfig/BuildingParametersPatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,41 @@ PlanetFactory factory
){
var entityPool = factory.entityPool;
var stationId = entityPool[entityId].stationId;
if (stationId == 0) return;

var component = factory.transport.stationPool[stationId];
component?.FixDuplicateWarperStores(stationId, factory);
if (stationId != 0)
{
var stationComponent = factory.transport.stationPool[stationId];
if (stationComponent is null)
return;
if (stationComponent.isCollector) return;
/* Parameters[320] is power consumption, which is set to non-zero while copy-building */
if (parameters == null || parameters[320] == 0)
{
stationComponent.SetStackCount();
if (stationComponent.isVeinCollector)
{
stationComponent.SetGatheringSpeed(factory);
}
}
if (!stationComponent.isVeinCollector)
{
stationComponent.FixDuplicateWarperStores(stationId, factory);
}
return;
}

var dispenserId = entityPool[entityId].dispenserId;
if (dispenserId == 0) return;
var dispenserComponent = factory.transport.dispenserPool[dispenserId];
if (dispenserComponent == null) return;
dispenserComponent.ApplyGuessFilter(factory);
var itemProto = LDB.items.Select(entityPool[entityId].protoId);
/* Check if any parameter is not the default value, which indicates a copy-build */
if (parameters == null ||
(parameters[0] == 2 && parameters[1] == 0 && parameters[2] == 30000 && parameters[3] == 0))
{
dispenserComponent.SetChargingPower(factory, itemProto.prefabDesc);
}
dispenserComponent.AddBotsFromInventory(itemProto.prefabDesc);
}
}

Expand Down
72 changes: 69 additions & 3 deletions AutoStationConfig/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ public static void SetChargingPower(
PrefabDesc prefabDesc
)
{
if (component.isCollector) return;

var maxEnergy = prefabDesc.workEnergyPerTick * 5;
var percent = component.isStellar
? AspConfig.ILS.ChargingPowerInPercent.Value
Expand Down Expand Up @@ -62,8 +60,22 @@ this StationComponent component
component.includeOrbitCollector = AspConfig.ILS.UseOrbitalCollectors.Value;
}

public static void SetStackCount(this StationComponent component)
{
if (component.isCollector) return;
if (component.isVeinCollector)
component.pilerCount = AspConfig.AMM.StackCount.Value;
else
component.pilerCount = component.isStellar ? AspConfig.ILS.StackCount.Value : AspConfig.PLS.StackCount.Value;
}

public static void AddDronesFromInventory(this StationComponent component, PrefabDesc prefabDesc)
{
if (AspConfig.General.EnableAutoReplenish.Value)
{
component.droneAutoReplenish = true;
return;
}
var percentage = component.isStellar
? AspConfig.ILS.DroneInsertPercentage.Value
: AspConfig.PLS.DroneInsertPercentage.Value;
Expand All @@ -81,6 +93,11 @@ public static void AddDronesFromInventory(this StationComponent component, Prefa
public static void AddVesselsFromInventory(this StationComponent component, PrefabDesc prefabDesc)
{
if (!component.isStellar) return;
if (AspConfig.General.EnableAutoReplenish.Value)
{
component.shipAutoReplenish = true;
return;
}
var percentage = AspConfig.ILS.VesselInsertPercentage.Value;
var maxToTake = Convert.ToInt32(Math.Floor(prefabDesc.stationMaxShipCount * percentage));
var numAvailable = GameMain.mainPlayer.package.TakeItem(ItemIds.Vessel, maxToTake, out _);
Expand Down Expand Up @@ -142,8 +159,57 @@ public static bool FixDuplicateWarperStores(this StationComponent component, int
);
}

factory.transport.RefreshTraffic();
factory.transport.RefreshStationTraffic();
return true;
}

public static void SetGatheringSpeed(this StationComponent component, PlanetFactory factory)
{
factory.factorySystem.minerPool[component.minerId].speed =
AspConfig.AMM.GatheringSpeedInPercent.Value * 100;
}

public static void SetChargingPower(
this DispenserComponent component,
PlanetFactory factory,
PrefabDesc prefabDesc
)
{
var maxEnergy = prefabDesc.workEnergyPerTick * 5;
var percent = AspConfig.LD.ChargingPowerInPercent.Value;

var workPerTick = maxEnergy * percent / 100;
factory.powerSystem.consumerPool[component.pcId].workEnergyPerTick =
workPerTick / 5000 * 5000; /* align power to multiples of 5kW per tick */
}

public static void AddBotsFromInventory(this DispenserComponent component, PrefabDesc prefabDesc)
{
if (AspConfig.General.EnableAutoReplenish.Value)
{
component.courierAutoReplenish = true;
return;
}
var maxToTake = Convert.ToInt32(Math.Floor(prefabDesc.dispenserMaxCourierCount * AspConfig.LD.BotInsertPercentage.Value));
var numAvailable = GameMain.mainPlayer.package.TakeItem(ItemIds.Bot, maxToTake, out _);
component.idleCourierCount = numAvailable;
if (AspConfig.General.NotifyWhenDroneOrVesselMissing.Value && numAvailable < maxToTake)
{
UIRealtimeTip.PopupAhead("Not enough Logistics Drones in inventory!".Translate(),
AspConfig.General.PlaySoundWhenDroneOrVesselMissing.Value);
}
}

public static void ApplyGuessFilter(this DispenserComponent component, PlanetFactory factory)
{
if (!AspConfig.LD.AlwaysGuessFilter.Value) return;
/* store old filter for later use */
var oldFilter = component.filter;
/* try re-guess */
component.filter = 0;
component.GuessFilter(factory);
/* revert to old filter if nothing is guessed out */
if (component.filter == 0) component.filter = oldFilter;
}
}
}
1 change: 1 addition & 0 deletions AutoStationConfig/ItemIds.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,6 @@ public static class ItemIds
public const int Warper = 1210;
public const int Drone = 5001;
public const int Vessel = 5002;
public const int Bot = 5003;
}
}
Loading