Skip to content
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
33 changes: 22 additions & 11 deletions TBot/Includes/CalculationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<int, LFBonusesShip> shipBonus, ServerData serverData, CharacterClass playerClass = CharacterClass.NoClass, int probeCargo = 0) {
public Ships CalcIdealExpeditionShips(Buildables buildable, int hyperspaceTech, LFBonuses LFBonuses, Dictionary<int, LFBonusesShip> 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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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<int, LFBonusesShip> 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<int, LFBonusesShip> 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);
Expand All @@ -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) {
Expand Down Expand Up @@ -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<LFTechno>()) {
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;
Expand Down
6 changes: 3 additions & 3 deletions TBot/Includes/ICalculationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<int, LFBonusesShip> shipsBonus, ServerData serverData, CharacterClass playerClass = CharacterClass.NoClass, int probeCargo = 0);
Ships CalcExpeditionShips(Ships fleet, Buildables primaryShip, int expeditionsNumber, int hyperspaceTech, LFBonuses LFBonuses, Dictionary<int, LFBonusesShip> 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);
Expand All @@ -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<int, LFBonusesShip> shipsBonus, ServerData serverData, CharacterClass playerClass = CharacterClass.NoClass, int probeCargo = 0);
Ships CalcIdealExpeditionShips(Buildables buildable, int hyperspaceTech, LFBonuses LFBonuses, Dictionary<int, LFBonusesShip> 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);
Expand Down Expand Up @@ -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);
Expand Down
6 changes: 3 additions & 3 deletions TBot/Workers/Brain/LifeformsAutoResearchCelestialWorker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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()
Expand Down
2 changes: 1 addition & 1 deletion TBot/Workers/Brain/LifeformsAutoResearchWorker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion TBot/Workers/ExpeditionsWorker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ protected override async Task Execute() {

LFBonuses lfBonuses = origins.First().LFBonuses;
Dictionary<Celestial, int> 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);
}
Expand Down
1 change: 1 addition & 0 deletions TBot/instance_settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,7 @@
"Transports": {
"Active": true
},
"WaitLvl1BeforeIncrease": false,
"MaxResearchLevel": 15,
"MaxTechs11": 15,
"MaxTechs12": 13,
Expand Down