Open Deenayd opened 2 years ago
I did it in a simplified way for myself.
I have failed trying to implement getting resources from original origin to local moon, if there are not enough on the moon. The problem is function HandleMinerTransport assumes transport's destination is the same as celestial that is about to be upgraded. Changing that looks like a good way to break some code that I don't fully understand so I gave up with that part.
But other that this is looks quite simple:
Getting new setting (yeah, learning how does your settings work):
AutoMinerSettings autoMinerSettings = new() {
OptimizeForStart = (bool) settings.Brain.AutoMine.OptimizeForStart,
PrioritizeRobotsAndNanites = (bool) settings.Brain.AutoMine.PrioritizeRobotsAndNanites,
MaxDaysOfInvestmentReturn = (float) settings.Brain.AutoMine.MaxDaysOfInvestmentReturn,
DepositHours = (int) settings.Brain.AutoMine.DepositHours,
BuildDepositIfFull = (bool) settings.Brain.AutoMine.BuildDepositIfFull,
DeutToLeaveOnMoons = (int) settings.Brain.AutoMine.DeutToLeaveOnMoons,
RouteThroughMoons = (bool) settings.Brain.AutoMine.RouteThroughMoons
};
AutoMine's modified code in AutoMineCelestial:
if ((bool) settings.Brain.AutoMine.Transports.Active) {
fleets = UpdateFleets();
if (!Helpers.IsThereTransportTowardsCelestial(celestial, fleets)) {
Celestial throughMoon = new() { ID = 0 };
if (autoMinerSettings.RouteThroughMoons && (celestial is Planet)) {
throughMoon = celestials
.Unique()
.Where(c => c.Coordinate.Galaxy == celestial.Coordinate.Galaxy)
.Where(c => c.Coordinate.System == celestial.Coordinate.System)
.Where(c => c.Coordinate.Position == celestial.Coordinate.Position)
.Where(c => c.Coordinate.Type == Celestials.Moon)
.SingleOrDefault() ?? new() { ID = 0 };
}
if (throughMoon.ID != 0) {
fleetId = HandleMinerTransport(throughMoon, celestial, xCostBuildable, buildable, maxBuildings, maxFacilities, maxLunarFacilities, autoMinerSettings);
// TODO: handle transport to the moon, if it has too little resources too
} else {
Celestial origin = celestials
.Unique()
.Where(c => c.Coordinate.Galaxy == (int) settings.Brain.AutoMine.Transports.Origin.Galaxy)
.Where(c => c.Coordinate.System == (int) settings.Brain.AutoMine.Transports.Origin.System)
.Where(c => c.Coordinate.Position == (int) settings.Brain.AutoMine.Transports.Origin.Position)
.Where(c => c.Coordinate.Type == Enum.Parse<Celestials>((string) settings.Brain.AutoMine.Transports.Origin.Type))
.SingleOrDefault() ?? new() { ID = 0 };
fleetId = HandleMinerTransport(origin, celestial, xCostBuildable, buildable, maxBuildings, maxFacilities, maxLunarFacilities, autoMinerSettings);
}
if (fleetId == (int) SendFleetCode.AfterSleepTime) {
stop = true;
return;
}
Lifeform Autoresearch's modified code in LifeformAutoResearchCelestial:
if ((bool) settings.Brain.LifeformAutoResearch.Transports.Active) {
fleets = UpdateFleets();
if (!Helpers.IsThereTransportTowardsCelestial(celestial, fleets)) {
Celestial throughMoon = new() { ID = 0 };
if (settings.Brain.AutoMine.RouteThroughMoons && (celestial is Planet)) {
throughMoon = celestials
.Unique()
.Where(c => c.Coordinate.Galaxy == celestial.Coordinate.Galaxy)
.Where(c => c.Coordinate.System == celestial.Coordinate.System)
.Where(c => c.Coordinate.Position == celestial.Coordinate.Position)
.Where(c => c.Coordinate.Type == Celestials.Moon)
.SingleOrDefault() ?? new() { ID = 0 };
}
if (throughMoon.ID != 0) {
fleetId = HandleMinerTransport(throughMoon, celestial, xCostBuildable);
// TODO: handle transport to the moon, if it has too little resources too
} else {
Celestial origin = celestials
.Unique()
.Where(c => c.Coordinate.Galaxy == (int) settings.Brain.AutoMine.Transports.Origin.Galaxy)
.Where(c => c.Coordinate.System == (int) settings.Brain.AutoMine.Transports.Origin.System)
.Where(c => c.Coordinate.Position == (int) settings.Brain.AutoMine.Transports.Origin.Position)
.Where(c => c.Coordinate.Type == Enum.Parse<Celestials>((string) settings.Brain.AutoMine.Transports.Origin.Type))
.SingleOrDefault() ?? new() { ID = 0 };
fleetId = HandleMinerTransport(origin, celestial, xCostBuildable);
}
if (fleetId == (int) SendFleetCode.AfterSleepTime) {
Similar Lifeformautomine's code in LifeformAutoMineCelestial:
if ((bool) settings.Brain.LifeformAutoMine.Transports.Active) {
fleets = UpdateFleets();
if (!Helpers.IsThereTransportTowardsCelestial(celestial, fleets)) {
Celestial throughMoon = new() { ID = 0 };
if (settings.Brain.AutoMine.RouteThroughMoons && (celestial is Planet)) {
throughMoon = celestials
.Unique()
.Where(c => c.Coordinate.Galaxy == celestial.Coordinate.Galaxy)
.Where(c => c.Coordinate.System == celestial.Coordinate.System)
.Where(c => c.Coordinate.Position == celestial.Coordinate.Position)
.Where(c => c.Coordinate.Type == Celestials.Moon)
.SingleOrDefault() ?? new() { ID = 0 };
}
if (throughMoon.ID != 0) {
fleetId = HandleMinerTransport(throughMoon, celestial, xCostBuildable);
// TODO: handle transport to the moon, if it has too little resources too
} else {
Celestial origin = celestials
.Unique()
.Where(c => c.Coordinate.Galaxy == (int) settings.Brain.AutoMine.Transports.Origin.Galaxy)
.Where(c => c.Coordinate.System == (int) settings.Brain.AutoMine.Transports.Origin.System)
.Where(c => c.Coordinate.Position == (int) settings.Brain.AutoMine.Transports.Origin.Position)
.Where(c => c.Coordinate.Type == Enum.Parse<Celestials>((string) settings.Brain.AutoMine.Transports.Origin.Type))
.SingleOrDefault() ?? new() { ID = 0 };
fleetId = HandleMinerTransport(origin, celestial, xCostBuildable);
}
if (fleetId == (int) SendFleetCode.AfterSleepTime) {
And autorepatriate modified code in AutoRepatriate:
if (celestial.Coordinate.IsSame(destinationCoordinate)) {
Helpers.WriteLog(LogType.Info, LogSender.Brain, $"Skipping {celestial.ToString()}: celestial is the target.");
continue;
}
Coordinate localDestination = destinationCoordinate;
if (((bool) settings.Brain.AutoRepatriate.ThroughTheMoons) && (celestial is Planet)) {
Celestial throughMoon = celestials
.Unique()
.Where(c => c.Coordinate.Galaxy == celestial.Coordinate.Galaxy)
.Where(c => c.Coordinate.System == celestial.Coordinate.System)
.Where(c => c.Coordinate.Position == celestial.Coordinate.Position)
.Where(c => c.Coordinate.Type == Celestials.Moon)
.SingleOrDefault() ?? new() { ID = 0 };
if (throughMoon.ID != 0) {
localDestination = throughMoon.Coordinate;
}
}
var tempCelestial = UpdatePlanet(celestial, UpdateTypes.Fast);
.......................
payload = Helpers.CalcMaxTransportableResources(ships, payload, researches.HyperspaceTechnology, userInfo.Class, probeCargo: serverData.ProbeCargo);
if (payload.TotalResources > 0) {
var fleetId = SendFleet(tempCelestial, ships, localDestination, Missions.Transport, Speeds.HundredPercent, payload);
if (fleetId == (int) SendFleetCode.AfterSleepTime) {
stop = true;
return;
}
It's possible to change autoresearch in a similar way, but I skipped it as original origin is always the same as local moon for me. Yeah. Not an universal assumption. Not everybody has to play like me (have laboratory at each planet, no need to transfer resources far away).
i like very much your interest in the project, but posting here a few hundreds lines of code is little to no use sadly if you wish to contribute with code, a pull request is the right way to do it
I'm sorry but we are not using github for anything at work (code repositiory that doesn't have even any paid plan to put code on OUR servers instead of sharing it with third party is useless for anything but open source) so I'm not going to learn it just for tbot.
Will just put ideas here without any code if you don't need my code. No problem.
It would be nice to implement a feature to route resource transports through local moons if possible. To avoid getting scanned or intercepted on long routes.
So for AutoMine, LifeformsAutoMine and LifeformsAutoResearch:
1) if feature enabled and celestial is a planet and it has a moon than: a) try to get resources from the moon b) if there are not enough resources on the moon, than start a transport to the moon
2) if feature is not enabled or if celestial is a moon than do what you do now.
And for AutoRepatriate (it's easier here):
1) if feature enabled and celestial is a planet and it has a moon than: a) send resources to the moon
2) if feature is not enabled or if celestial is a moon than do what you do now.