diff --git a/TBot/Includes/CalculationService.cs b/TBot/Includes/CalculationService.cs index f45390c9..75972aa0 100644 --- a/TBot/Includes/CalculationService.cs +++ b/TBot/Includes/CalculationService.cs @@ -588,9 +588,10 @@ public long CalcShipNumberForPayload(Resources payload, Buildables buildable, in return (long) Math.Round(((float) payload.TotalResources / (float) CalcShipCapacity(buildable, hyperspaceTech, serverData, cargoBonus, playerClass, probeCapacity)), MidpointRounding.ToPositiveInfinity); } - public Ships CalcIdealExpeditionShips(Buildables buildable, int hyperspaceTech, float expeditionResourcesBonus, Dictionary shipBonus, ServerData serverData, CharacterClass playerClass = CharacterClass.NoClass, int probeCargo = 0) { + public Ships CalcIdealExpeditionShips(Buildables buildable, int hyperspaceTech, LFBonuses LFBonuses, Dictionary shipBonus, ServerData serverData, CharacterClass playerClass = CharacterClass.NoClass, int probeCargo = 0) { var fleet = new Ships(); - + float expeditionResourcesBonus = LFBonuses.LfResourceBonuses.ResourcesExpedition; + float expeditionClassBonus = LFBonuses.CharacterClassesBonuses.Characterclasses3; int ecoSpeed = serverData.Speed; float topOnePoints = serverData.TopScore; float buildableCargoBonus = 0; @@ -622,8 +623,11 @@ public Ships CalcIdealExpeditionShips(Buildables buildable, int hyperspaceTech, else freightCap *= 2; - if(expeditionResourcesBonus > 0) + if (expeditionResourcesBonus > 0) freightCap += (int) Math.Round((float) freightCap * expeditionResourcesBonus, MidpointRounding.ToPositiveInfinity); + + if (expeditionClassBonus > 0) + freightCap += (int) Math.Round((float) freightCap * expeditionClassBonus, MidpointRounding.ToPositiveInfinity); int oneCargoCapacity = CalcShipCapacity(buildable, hyperspaceTech, serverData, buildableCargoBonus, playerClass, probeCargo); int cargoNumber = (int) Math.Round((float) freightCap / (float) oneCargoCapacity, MidpointRounding.ToPositiveInfinity); @@ -656,8 +660,8 @@ public Buildables CalcMilitaryShipForExpedition(Ships fleet, int expeditionsNumb return Buildables.Null; } - public Ships CalcExpeditionShips(Ships fleet, Buildables primaryShip, int expeditionsNumber, int hyperspaceTech, float expeditionsResourcesBonus, Dictionary shipsBonus, ServerData serverData, CharacterClass playerClass = CharacterClass.NoClass, int probeCargo = 0) { - Ships ideal = CalcIdealExpeditionShips(primaryShip, hyperspaceTech, expeditionsResourcesBonus, shipsBonus, serverData, playerClass, probeCargo); + public Ships CalcExpeditionShips(Ships fleet, Buildables primaryShip, int expeditionsNumber, int hyperspaceTech, LFBonuses LFBonuses, Dictionary shipsBonus, ServerData serverData, CharacterClass playerClass = CharacterClass.NoClass, int probeCargo = 0) { + Ships ideal = CalcIdealExpeditionShips(primaryShip, hyperspaceTech, LFBonuses, shipsBonus, serverData, playerClass, probeCargo); foreach (PropertyInfo prop in fleet.GetType().GetProperties()) { if (prop.Name == primaryShip.ToString()) { long availableVal = (long) prop.GetValue(fleet); @@ -673,7 +677,7 @@ public Ships CalcExpeditionShips(Ships fleet, Buildables primaryShip, int expedi } public Ships CalcExpeditionShips(Ships fleet, Buildables primaryShip, int expeditionsNumber, ServerData serverdata, Researches researches, LFBonuses LFBonuses, CharacterClass playerClass = CharacterClass.NoClass, int probeCargo = 0) { - return CalcExpeditionShips(fleet, primaryShip, expeditionsNumber, researches.HyperspaceTechnology, LFBonuses.LfResourceBonuses.ResourcesExpedition, LFBonuses.LfShipBonusesInt, serverdata, playerClass, probeCargo); + return CalcExpeditionShips(fleet, primaryShip, expeditionsNumber, researches.HyperspaceTechnology, LFBonuses, LFBonuses.LfShipBonusesInt, serverdata, playerClass, probeCargo); } public bool MayAddShipToExpedition(Ships fleet, Buildables buildable, int expeditionsNumber) { @@ -4065,19 +4069,26 @@ public long CalcSatisfied(LFBuildables populationFactory, int populationFactoryL return (long) Math.Floor(((double) foodProduction / (double) foodConsumption) * (double) livingSpace); } - public LFTechno GetNextLFTechToBuild(Celestial celestial, LFTechs MaxReasearchLevel) { + public LFTechno GetNextLFTechToBuild(Celestial celestial, LFTechs MaxReasearchLevel, bool waitFirstLvl = true) { //TODO //As planets can have any lifeform techs, its complicated to find which techs are existing on a planet if the techs are not at least level 1 //Therefore, for the moment, up only techs that are minimum level 1, its a way to also allows player to chose which research to up foreach (LFTechno nextLFTech in Enum.GetValues()) { int? level = celestial.LFTechs.GetLevel(nextLFTech); if (level is null) { - continue; + continue; } - if (level > 0 && GetNextLevel(celestial, nextLFTech) <= MaxReasearchLevel.GetLevel(nextLFTech)) { - //Console.WriteLine($"-----------------------------> {nextLFTech}: {GetNextLevel(celestial, nextLFTech)} / {MaxReasearchLevel.GetLevel(nextLFTech)}"); - return nextLFTech; + if (waitFirstLvl) { + if (level > 0 && GetNextLevel(celestial, nextLFTech) <= MaxReasearchLevel.GetLevel(nextLFTech)) { + //Console.WriteLine($"-----------------------------> {nextLFTech}: {GetNextLevel(celestial, nextLFTech)} / {MaxReasearchLevel.GetLevel(nextLFTech)}"); + return nextLFTech; + } + } else { + if (nextLFTech != LFTechno.None && level >= 0 && GetNextLevel(celestial, nextLFTech) <= MaxReasearchLevel.GetLevel(nextLFTech)) { + //Console.WriteLine($"-----------------------------> {nextLFTech}: {GetNextLevel(celestial, nextLFTech)} / {MaxReasearchLevel.GetLevel(nextLFTech)}"); + return nextLFTech; + } } } return LFTechno.None; diff --git a/TBot/Includes/ICalculationService.cs b/TBot/Includes/ICalculationService.cs index ab84d941..2b6113d1 100644 --- a/TBot/Includes/ICalculationService.cs +++ b/TBot/Includes/ICalculationService.cs @@ -23,7 +23,7 @@ public interface ICalculationService { int CalcDistance(Coordinate origin, Coordinate destination, ServerData serverData); long CalcEnergyProduction(Buildables buildable, int level, int energyTechnology = 0, float ratio = 1, CharacterClass playerClass = CharacterClass.NoClass, bool hasEngineer = false, bool hasStaff = false); long CalcEnergyProduction(Buildables buildable, int level, Researches researches, float ratio = 1, CharacterClass playerClass = CharacterClass.NoClass, bool hasEngineer = false, bool hasStaff = false); - Ships CalcExpeditionShips(Ships fleet, Buildables primaryShip, int expeditionsNumber, int hyperspaceTech, float expeditionResourcesBonus, Dictionary shipsBonus, ServerData serverData, CharacterClass playerClass = CharacterClass.NoClass, int probeCargo = 0); + Ships CalcExpeditionShips(Ships fleet, Buildables primaryShip, int expeditionsNumber, int hyperspaceTech, LFBonuses LFBonuses, Dictionary shipsBonus, ServerData serverData, CharacterClass playerClass = CharacterClass.NoClass, int probeCargo = 0); Ships CalcExpeditionShips(Ships fleet, Buildables primaryShip, int expeditionsNumber, ServerData serverdata, Researches researches, LFBonuses LFBonuses, CharacterClass playerClass = CharacterClass.NoClass, int probeCargo = 0); long CalcFleetCapacity(Ships fleet, ServerData serverData, int hyperspaceTech = 0, LFBonuses lfBonuses = null, CharacterClass playerClass = CharacterClass.NoClass, int probeCargo = 0); long CalcFleetFuelCapacity(Ships fleet, ServerData serverData, int hyperspaceTech = 0, CharacterClass playerClass = CharacterClass.NoClass, int probeCargo = 0); @@ -36,7 +36,7 @@ public interface ICalculationService { long CalcFuelConsumption(Coordinate origin, Coordinate destination, Ships ships, long flightTime, int combustionDrive, int impulseDrive, int hyperspaceDrive, int numberOfGalaxies, int numberOfSystems, bool donutGalaxies, bool donutSystems, int fleetSpeed, float deuteriumSaveFactor, LFBonuses lfBonuses = null, CharacterClass playerClass = CharacterClass.NoClass, AllianceClass allyClass = AllianceClass.NoClass); long CalcFuelConsumption(Coordinate origin, Coordinate destination, Ships ships, Missions mission, long flightTime, Researches researches, ServerData serverData, LFBonuses lfBonuses = null, CharacterClass playerClass = CharacterClass.NoClass, AllianceClass allyClass = AllianceClass.NoClass); Ships CalcFullExpeditionShips(Ships fleet, Buildables primaryShip, int expeditionsNumber, ServerData serverdata, Researches researches, LFBonuses LFBonuses, CharacterClass playerClass = CharacterClass.NoClass, int probeCargo = 0); - Ships CalcIdealExpeditionShips(Buildables buildable, int hyperspaceTech, float expeditionResourcesBonus, Dictionary shipsBonus, ServerData serverData, CharacterClass playerClass = CharacterClass.NoClass, int probeCargo = 0); + Ships CalcIdealExpeditionShips(Buildables buildable, int hyperspaceTech, LFBonuses LFBonuses, Dictionary shipsBonus, ServerData serverData, CharacterClass playerClass = CharacterClass.NoClass, int probeCargo = 0); long CalcMaxBuildableNumber(Buildables buildable, Resources resources); Defences CalcmaxDefencesBuildable(Defences defences, Resources resources); int CalcMaxCrawlers(Planet planet, CharacterClass userClass, bool hasGeologist); @@ -120,7 +120,7 @@ public interface ICalculationService { double CalcFoodConsumptionBonus(Planet planet); long CalcSatisfied(Planet planet); long CalcSatisfied(LFBuildables populationFactory, int populationFactoryLevel, LFBuildables foodFactory, int foodFactoryLevel, double populationBonus = 0, double foodProductionBonus = 0, double foodConsumptionBonus = 0); - LFTechno GetNextLFTechToBuild(Celestial celestial, LFTechs MaxReasearchLevel); + LFTechno GetNextLFTechToBuild(Celestial celestial, LFTechs MaxReasearchLevel, bool allowZero = true); Buildables GetNextLunarFacilityToBuild(Moon moon, Researches researches, int maxLunarBase = 8, int maxRoboticsFactory = 8, int maxSensorPhalanx = 6, int maxJumpGate = 1, int maxShipyard = 0); Buildables GetNextLunarFacilityToBuild(Moon moon, Researches researches, Facilities maxLunarFacilities); Buildables GetNextMineToBuild(Planet planet, int maxMetalMine = 100, int maxCrystalMine = 100, int maxDeuteriumSynthetizer = 100, bool optimizeForStart = true); diff --git a/TBot/Workers/Brain/LifeformsAutoResearchCelestialWorker.cs b/TBot/Workers/Brain/LifeformsAutoResearchCelestialWorker.cs index 54c38f72..0ad35463 100644 --- a/TBot/Workers/Brain/LifeformsAutoResearchCelestialWorker.cs +++ b/TBot/Workers/Brain/LifeformsAutoResearchCelestialWorker.cs @@ -153,7 +153,7 @@ private async Task LifeformAutoResearchCelestial(Celestial celestial) { return; } if (celestial is Planet) { - buildable = _calculationService.GetNextLFTechToBuild(celestial, maxLFTechs);//maxResearchLevel); + buildable = _calculationService.GetNextLFTechToBuild(celestial, maxLFTechs, (bool) _tbotInstance.InstanceSettings.Brain.LifeformAutoResearch.WaitLvl1BeforeIncrease);//maxResearchLevel); if (buildable != LFTechno.None) { level = _calculationService.GetNextLevel(celestial, buildable); @@ -322,7 +322,7 @@ private async Task LifeformAutoResearchCelestial(Celestial celestial) { celestialsToExclude) ); - Celestial destination; + Celestial destination = new() { ID = 0 }; if ((bool) transportsSettings.SendToTheMoonIfPossible && _calculationService.IsThereMoonHere(allCelestials, celestial)) { destination = allCelestials .Unique() @@ -369,7 +369,7 @@ private async Task LifeformAutoResearchCelestial(Celestial celestial) { } } } else { - Celestial destination; + Celestial destination = new() { ID = 0 }; if ((bool) _tbotInstance.InstanceSettings.Brain.Transports.SendToTheMoonIfPossible && _calculationService.IsThereMoonHere(_tbotInstance.UserData.celestials, celestial)) { destination = allCelestials .Unique() diff --git a/TBot/Workers/Brain/LifeformsAutoResearchWorker.cs b/TBot/Workers/Brain/LifeformsAutoResearchWorker.cs index 6a87b8ed..22f26353 100644 --- a/TBot/Workers/Brain/LifeformsAutoResearchWorker.cs +++ b/TBot/Workers/Brain/LifeformsAutoResearchWorker.cs @@ -91,7 +91,7 @@ protected override async Task Execute() { DoLog(LogLevel.Information, $"Skipping {cel.ToString()}: No Lifeform active on this planet."); continue; } - var nextLFTechToBuild = _calculationService.GetNextLFTechToBuild(cel, maxLFTechs);//maxResearchLevel); + var nextLFTechToBuild = _calculationService.GetNextLFTechToBuild(cel, maxLFTechs, (bool) _tbotInstance.InstanceSettings.Brain.LifeformAutoResearch.WaitLvl1BeforeIncrease);//maxResearchLevel); if (nextLFTechToBuild != LFTechno.None) { var level = _calculationService.GetNextLevel(cel, nextLFTechToBuild); Resources nextLFTechCost = _calculationService.CalcPrice(nextLFTechToBuild, level); diff --git a/TBot/Workers/ExpeditionsWorker.cs b/TBot/Workers/ExpeditionsWorker.cs index bcfa777f..ae1b0ca9 100644 --- a/TBot/Workers/ExpeditionsWorker.cs +++ b/TBot/Workers/ExpeditionsWorker.cs @@ -176,7 +176,7 @@ protected override async Task Execute() { LFBonuses lfBonuses = origins.First().LFBonuses; Dictionary originExps = new(); - int quot = (int) Math.Floor((float) expsToSend / (float) origins.Count()); + int quot = (int) Math.Floor((float) expsToSend / (float) origins.Count()); foreach (var origin in origins) { originExps.Add(origin, quot); } diff --git a/TBot/instance_settings.json b/TBot/instance_settings.json index 6f77812b..54c43ba0 100644 --- a/TBot/instance_settings.json +++ b/TBot/instance_settings.json @@ -225,6 +225,7 @@ "Transports": { "Active": true }, + "WaitLvl1BeforeIncrease": false, "MaxResearchLevel": 15, "MaxTechs11": 15, "MaxTechs12": 13,