@ -77,10 +77,7 @@ public class BuildOrderService : IBuildOrderService
_ buildOrder . UniqueCompletedCount [ entity . DataType ] + + ;
if ( ! _ buildOrder . UniqueCompleted . ContainsKey ( entity . DataType ) )
_ buildOrder . UniqueCompleted . Add ( entity . DataType , new Dictionary < int , List < EntityModel > > ( ) ) ;
if ( ! _ buildOrder . UniqueCompleted [ entity . DataType ] . ContainsKey ( completedTime ) )
_ buildOrder . UniqueCompleted [ entity . DataType ] . Add ( completedTime , new List < EntityModel > ( ) ) ;
_ buildOrder . UniqueCompleted . Add ( entity . DataType , new List < EntityModel > ( ) ) ;
if ( entity . Production ( ) ? . ProducedBy ! = null )
_ buildOrder . TrainingCapacityUsed . Add ( new TrainingCapacityUsedModel
@ -91,7 +88,7 @@ public class BuildOrderService : IBuildOrderService
UsedBuilding = entity . Production ( ) ! . ProducedBy
} ) ;
_ buildOrder . UniqueCompleted [ entity . DataType ] [ completedTime ] . Add ( entity ) ;
_ buildOrder . UniqueCompleted [ entity . DataType ] . Add ( entity ) ;
if ( entity . Supply ( ) ! = null & & entity . Supply ( ) ! . Takes > 0 )
_ buildOrder . CurrentSupplyUsed + = entity . Supply ( ) ! . Takes ;
@ -190,6 +187,7 @@ public class BuildOrderService : IBuildOrderService
if ( ! HandleSupply ( entity , ref atInterval ) ) return false ;
if ( ! HandleRequirements ( entity , ref atInterval ) ) return false ;
if ( ! HandleEconomy ( entity , withEconomy , ref atInterval ) ) return false ;
if ( ! HandleTrainingQueue ( entity , ref atInterval ) ) return false ;
Add ( entity , atInterval ) ;
@ -236,11 +234,21 @@ public class BuildOrderService : IBuildOrderService
if ( entityRemoved . Supply ( ) ? . Takes > 0 )
_ buildOrder . CurrentSupplyUsed - = entityRemoved . Supply ( ) ! . Takes ;
_ buildOrder . UniqueCompletedCount [ entityRemoved ! . DataType ] - - ;
if ( _ buildOrder . UniqueCompletedCount [ entityRemoved ! . DataType ] = = 0 )
UniqueCompletedTimes . Remove ( entityRemoved . DataType ) ;
_ buildOrder . UniqueCompleted [ entityRemoved . DataType ]
. Remove ( _ buildOrder . UniqueCompleted [ entityRemoved . DataType ] . Last ( ) ) ;
if ( entityRemoved . Production ( ) ! = null
& & entityRemoved . Production ( ) ! . ProducedBy ! = null
& & entityRemoved . Supply ( ) ! = null
& & entityRemoved . Supply ( ) ! . Takes > 0 )
{
_ buildOrder . TrainingCapacityUsed . Remove ( _ buildOrder . TrainingCapacityUsed . Last ( ) ) ;
}
if ( entityRemoved . Info ( ) . Descriptive = = DescriptiveType . Worker )
{
RemoveLast ( ) ;
@ -330,35 +338,70 @@ public class BuildOrderService : IBuildOrderService
public int? WillMeetTrainingQueue ( EntityModel entity )
{
Console . WriteLine ( $"WillMeetTrainingQueue {entity.Info().Name}" ) ;
var supply = entity . Supply ( ) ;
var production = entity . Production ( ) ;
if ( supply = = null | | production = = null | | supply . Takes . Equals ( 0 ) ) return 1 ;
var checkedInterval = _l astInterval ;
if ( supply = = null | | production = = null | | supply . Takes . Equals ( 0 ) )
{
Console . WriteLine ( supply = = null ? "Was Null" : supply . Takes ) ;
return 1 ;
}
var producedBy = production . ProducedBy ;
if ( producedBy = = null )
{
Console . WriteLine ( "Produced by Nothing" ) ;
return 1 ;
}
var uniqueCompleted = _ buildOrder . UniqueCompleted [ producedBy ] ;
var shortestIncrement = int . MaxValue ;
var trainingSlots = 0 ;
bool didDelay = false ;
foreach ( var productionEntity in uniqueCompleted ) trainingSlots + = productionEntity . Supply ( ) ! . Grants ;
foreach ( var used in _ buildOrder . TrainingCapacityUsed )
{
//used.UsedBuilding
}
foreach ( var atTime in uniqueCompleted )
while ( true )
{
foreach ( var productionEntity in uniqueCompleted [ atTime . Key ] )
var usedSlots = 0 ;
foreach ( var used in _ buildOrder . TrainingCapacityUsed )
if ( checkedInterval > = used . StartingUsageTime & & checkedInterval < used . StopUsageTime )
{
usedSlots + = used . UsedSlots ;
var duration = used . StopUsageTime - used . StartingUsageTime ;
if ( duration < shortestIncrement ) shortestIncrement = duration ;
Console . WriteLine ( $"Used slots {used.UsedSlots} Duration {duration} Start {used.StartingUsageTime} Stop {used.StopUsageTime} " ) ;
}
if ( usedSlots + supply . Takes < = trainingSlots )
{
if ( didDelay )
{
_ toastService . AddToast ( new ToastModel { Title = "Waited" , SeverityType = SeverityType . Information , Message = $"Had to wait {checkedInterval - _lastInterval}s for Training Queue." } ) ;
}
Console . WriteLine ( $"Time {checkedInterval} did Delay {didDelay}" ) ;
return checkedInterval ;
}
}
foreach ( var supplyAtTime in _ buildOrder . SupplyCountTimes )
if ( supply . Takes + _ buildOrder . CurrentSupplyUsed < supplyAtTime . Key )
return supplyAtTime . Value ;
checkedInterval + = shortestIncrement ;
didDelay = true ;
return null ;
if ( shortestIncrement = = int . MaxValue )
{
Console . WriteLine ( $"MaxValue" ) ;
return null ;
}
}
}
private event Action OnChange = null ! ;
@ -422,19 +465,19 @@ public class BuildOrderService : IBuildOrderService
private bool HandleTrainingQueue ( EntityModel entity , ref int atInterval )
{
var minSupplyInterval = WillMeetSupply ( entity ) ;
if ( minSupply Interval = = null )
var minTrainingQueueInterval = WillMeetTrainingQueue ( entity ) ;
if ( minTrainingQueue Interval = = null )
{
_ toastService . AddToast ( new ToastModel
{
Title = "Supply Cap Reache d" , Message = "Build more supply! " ,
Title = "Invali d" , Message = "Invalid Training Queue error " ,
SeverityType = SeverityType . Error
} ) ;
return false ;
}
if ( minSupply Interval > atInterval ) atInterval = ( int ) minSupply Interval ;
if ( minTrainingQueue Interval > atInterval ) atInterval = ( int ) minTrainingQueue Interval ;
return true ;
}