feat(ai): improving agents planning and memory
This commit is contained in:
@@ -44,7 +44,7 @@ internal sealed class StationSimulationService
|
||||
var hullpartsReserve = MathF.Max(constructionHullpartsReserve, HasStationModules(station, "module_gen_build_l_01") ? 120f : 0f);
|
||||
var claytronicsReserve = MathF.Max(constructionClayReserve, HasStationModules(station, "module_gen_build_l_01") ? 120f : 0f);
|
||||
var shipPartsReserve = HasStationModules(station, "module_gen_build_l_01")
|
||||
&& FactionCommanderHasDirective(world, station.FactionId, "produce-military-ships")
|
||||
&& FactionCommanderHasIssuedTask(world, station.FactionId, FactionIssuedTaskKind.ProduceShips, "military")
|
||||
? 90f
|
||||
: 0f;
|
||||
|
||||
@@ -163,14 +163,33 @@ internal sealed class StationSimulationService
|
||||
var priority = (float)recipe.Priority;
|
||||
|
||||
var expansionPressure = GetFactionExpansionPressure(world, station.FactionId);
|
||||
var fleetPressure = FactionCommanderHasDirective(world, station.FactionId, "produce-military-ships") ? 1f : 0f;
|
||||
priority += GetStationRecipePriorityAdjustment(station, recipe, expansionPressure, fleetPressure);
|
||||
var fleetPressure = FactionCommanderHasIssuedTask(world, station.FactionId, FactionIssuedTaskKind.ProduceShips, "military") ? 1f : 0f;
|
||||
priority += GetStationRecipePriorityAdjustment(world, station, recipe, expansionPressure, fleetPressure);
|
||||
|
||||
return priority;
|
||||
}
|
||||
|
||||
private static float GetStationRecipePriorityAdjustment(StationRuntime station, RecipeDefinition recipe, float expansionPressure, float fleetPressure)
|
||||
private static float GetStationRecipePriorityAdjustment(SimulationWorld world, StationRuntime station, RecipeDefinition recipe, float expansionPressure, float fleetPressure)
|
||||
{
|
||||
if (recipe.ShipOutputId is not null && world.ShipDefinitions.TryGetValue(recipe.ShipOutputId, out var shipDefinition))
|
||||
{
|
||||
var shipPressure = GetShipProductionPressure(world, station.FactionId, shipDefinition.Kind);
|
||||
return shipDefinition.Kind switch
|
||||
{
|
||||
"military" => recipe.Id switch
|
||||
{
|
||||
"frigate-construction" => 320f * shipPressure,
|
||||
"destroyer-construction" => 200f * shipPressure,
|
||||
"cruiser-construction" => 120f * shipPressure,
|
||||
_ => 160f * shipPressure,
|
||||
},
|
||||
"construction" => 260f * shipPressure,
|
||||
"mining" => 250f * shipPressure,
|
||||
"transport" => 230f * shipPressure,
|
||||
_ => 0f,
|
||||
};
|
||||
}
|
||||
|
||||
var outputItemIds = recipe.Outputs
|
||||
.Select(output => output.ItemId)
|
||||
.ToHashSet(StringComparer.Ordinal);
|
||||
@@ -201,9 +220,6 @@ internal sealed class StationSimulationService
|
||||
{
|
||||
"command-bridge-module-assembly" or "reactor-core-module-assembly" or "capacitor-bank-module-assembly" or "ion-drive-module-assembly" or "ftl-core-module-assembly" or "gun-turret-module-assembly"
|
||||
=> 220f * MathF.Max(expansionPressure, fleetPressure),
|
||||
"frigate-construction" => 320f * MathF.Max(expansionPressure, fleetPressure),
|
||||
"destroyer-construction" => 200f * MathF.Max(expansionPressure, fleetPressure),
|
||||
"cruiser-construction" => 120f * MathF.Max(expansionPressure, fleetPressure),
|
||||
"ammo-fabrication" => -80f * expansionPressure,
|
||||
"trade-hub-assembly" or "refinery-assembly" or "farm-ring-assembly" or "manufactory-assembly" or "shipyard-assembly" or "defense-grid-assembly" or "stargate-assembly"
|
||||
=> -120f * expansionPressure,
|
||||
@@ -228,8 +244,7 @@ internal sealed class StationSimulationService
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!string.Equals(shipDefinition.Kind, "military", StringComparison.Ordinal)
|
||||
|| !FactionCommanderHasDirective(world, station.FactionId, "produce-military-ships"))
|
||||
if (!FactionCommanderHasIssuedTask(world, station.FactionId, FactionIssuedTaskKind.ProduceShips, shipDefinition.Kind))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -431,16 +446,17 @@ internal sealed class StationSimulationService
|
||||
private static float ScaleReserveByEconomy(FactionEconomySnapshot economy, string itemId, float baseReserve)
|
||||
{
|
||||
var commodity = economy.GetCommodity(itemId);
|
||||
if (float.IsPositiveInfinity(commodity.ShortageHorizonSeconds))
|
||||
if (commodity.Level == CommodityLevelKind.Critical)
|
||||
{
|
||||
return MathF.Max(0f, baseReserve);
|
||||
return baseReserve * 1.6f;
|
||||
}
|
||||
|
||||
return commodity.ShortageHorizonSeconds < 180f
|
||||
? baseReserve * 1.5f
|
||||
: commodity.ShortageHorizonSeconds < 360f
|
||||
? baseReserve * 1.2f
|
||||
: baseReserve;
|
||||
return commodity.Level switch
|
||||
{
|
||||
CommodityLevelKind.Low => baseReserve * 1.25f,
|
||||
CommodityLevelKind.Stable when commodity.ProjectedNetRatePerSecond < -0.01f => baseReserve * 1.1f,
|
||||
_ => MathF.Max(0f, baseReserve),
|
||||
};
|
||||
}
|
||||
|
||||
private static float ScaleSupplyTriggerByEconomy(FactionEconomySnapshot economy, string itemId, float baseTrigger)
|
||||
@@ -452,24 +468,36 @@ internal sealed class StationSimulationService
|
||||
private static float ScaleDemandValuation(FactionEconomySnapshot economy, string itemId, float baseValuation)
|
||||
{
|
||||
var commodity = economy.GetCommodity(itemId);
|
||||
if (float.IsPositiveInfinity(commodity.ShortageHorizonSeconds))
|
||||
return commodity.Level switch
|
||||
{
|
||||
return commodity.ProductionRatePerSecond > 0.01f ? baseValuation : baseValuation * 1.3f;
|
||||
}
|
||||
|
||||
return commodity.ShortageHorizonSeconds < 180f
|
||||
? baseValuation * 1.5f
|
||||
: commodity.ShortageHorizonSeconds < 360f
|
||||
? baseValuation * 1.25f
|
||||
: baseValuation;
|
||||
CommodityLevelKind.Critical => baseValuation * 1.6f,
|
||||
CommodityLevelKind.Low => baseValuation * 1.3f,
|
||||
CommodityLevelKind.Stable when commodity.ProjectedNetRatePerSecond < -0.01f => baseValuation * 1.15f,
|
||||
CommodityLevelKind.Surplus when commodity.ProjectedNetRatePerSecond > 0.01f => baseValuation * 0.9f,
|
||||
_ => commodity.ProductionRatePerSecond > 0.01f ? baseValuation : baseValuation * 1.15f,
|
||||
};
|
||||
}
|
||||
|
||||
private static float ScaleSupplyValuation(FactionEconomySnapshot economy, string itemId, float baseValuation)
|
||||
{
|
||||
var commodity = economy.GetCommodity(itemId);
|
||||
return commodity.NetRatePerSecond > 0.01f && commodity.ShortageHorizonSeconds > 600f
|
||||
return commodity.Level == CommodityLevelKind.Surplus && commodity.NetRatePerSecond > 0.01f
|
||||
? baseValuation * 0.75f
|
||||
: baseValuation;
|
||||
: commodity.Level == CommodityLevelKind.Critical
|
||||
? baseValuation * 1.15f
|
||||
: baseValuation;
|
||||
}
|
||||
|
||||
private static float GetShipProductionPressure(SimulationWorld world, string factionId, string shipKind)
|
||||
{
|
||||
var factionCommander = FindFactionCommander(world, factionId);
|
||||
var task = GetHighestPriorityIssuedTask(factionCommander, FactionIssuedTaskKind.ProduceShips, shipKind);
|
||||
if (task is null)
|
||||
{
|
||||
return 0f;
|
||||
}
|
||||
|
||||
return task.State == FactionIssuedTaskState.Blocked ? 0.4f : 1f;
|
||||
}
|
||||
|
||||
private static bool FactionControlsSystem(SimulationWorld world, string factionId, string systemId)
|
||||
|
||||
Reference in New Issue
Block a user