|
|
|
@ -58,7 +58,7 @@ public class BuildOrderService : IBuildOrderService |
|
|
|
public void Add(EntityModel entity, int atInterval) |
|
|
|
public void Add(EntityModel entity, int atInterval) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (!_buildOrder.StartedOrders.ContainsKey(atInterval)) |
|
|
|
if (!_buildOrder.StartedOrders.ContainsKey(atInterval)) |
|
|
|
_buildOrder.StartedOrders.Add(atInterval, new List<EntityModel>()); |
|
|
|
_buildOrder.StartedOrders.Add(atInterval, []); |
|
|
|
|
|
|
|
|
|
|
|
var production = entity.Production(); |
|
|
|
var production = entity.Production(); |
|
|
|
|
|
|
|
|
|
|
|
@ -66,21 +66,18 @@ public class BuildOrderService : IBuildOrderService |
|
|
|
if (production != null) completedTime += production.BuildTime; |
|
|
|
if (production != null) completedTime += production.BuildTime; |
|
|
|
|
|
|
|
|
|
|
|
if (!_buildOrder.CompletedOrders.ContainsKey(completedTime)) |
|
|
|
if (!_buildOrder.CompletedOrders.ContainsKey(completedTime)) |
|
|
|
_buildOrder.CompletedOrders.Add(completedTime, new List<EntityModel>()); |
|
|
|
_buildOrder.CompletedOrders.Add(completedTime, []); |
|
|
|
|
|
|
|
|
|
|
|
_buildOrder.StartedOrders[atInterval].Add(entity.Clone()); |
|
|
|
_buildOrder.StartedOrders[atInterval].Add(entity.Clone()); |
|
|
|
_buildOrder.CompletedOrders[completedTime].Add(entity.Clone()); |
|
|
|
_buildOrder.CompletedOrders[completedTime].Add(entity.Clone()); |
|
|
|
|
|
|
|
|
|
|
|
if (!_buildOrder.UniqueCompletedTimes.ContainsKey(entity.DataType)) |
|
|
|
_buildOrder.UniqueCompletedTimes.TryAdd(entity.DataType, atInterval); |
|
|
|
_buildOrder.UniqueCompletedTimes.Add(entity.DataType, atInterval); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!_buildOrder.UniqueCompletedCount.ContainsKey(entity.DataType)) |
|
|
|
if (!_buildOrder.UniqueCompletedCount.TryAdd(entity.DataType, 1)) |
|
|
|
_buildOrder.UniqueCompletedCount.Add(entity.DataType, 1); |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
_buildOrder.UniqueCompletedCount[entity.DataType]++; |
|
|
|
_buildOrder.UniqueCompletedCount[entity.DataType]++; |
|
|
|
|
|
|
|
|
|
|
|
if (!_buildOrder.UniqueCompleted.ContainsKey(entity.DataType)) |
|
|
|
if (!_buildOrder.UniqueCompleted.ContainsKey(entity.DataType)) |
|
|
|
_buildOrder.UniqueCompleted.Add(entity.DataType, new List<EntityModel>()); |
|
|
|
_buildOrder.UniqueCompleted.Add(entity.DataType, []); |
|
|
|
|
|
|
|
|
|
|
|
if (entity.Production()?.ProducedBy != null) |
|
|
|
if (entity.Production()?.ProducedBy != null) |
|
|
|
_buildOrder.TrainingCapacityUsed.Add(new TrainingCapacityUsedModel |
|
|
|
_buildOrder.TrainingCapacityUsed.Add(new TrainingCapacityUsedModel |
|
|
|
@ -116,10 +113,10 @@ public class BuildOrderService : IBuildOrderService |
|
|
|
_lastInterval += forInterval; |
|
|
|
_lastInterval += forInterval; |
|
|
|
|
|
|
|
|
|
|
|
if (!_buildOrder.StartedOrders.ContainsKey(_lastInterval)) |
|
|
|
if (!_buildOrder.StartedOrders.ContainsKey(_lastInterval)) |
|
|
|
_buildOrder.StartedOrders.Add(_lastInterval, new List<EntityModel>()); |
|
|
|
_buildOrder.StartedOrders.Add(_lastInterval, []); |
|
|
|
|
|
|
|
|
|
|
|
if (!_buildOrder.CompletedOrders.ContainsKey(_lastInterval)) |
|
|
|
if (!_buildOrder.CompletedOrders.ContainsKey(_lastInterval)) |
|
|
|
_buildOrder.CompletedOrders.Add(_lastInterval, new List<EntityModel>()); |
|
|
|
_buildOrder.CompletedOrders.Add(_lastInterval, []); |
|
|
|
|
|
|
|
|
|
|
|
NotifyDataChanged(); |
|
|
|
NotifyDataChanged(); |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
@ -140,10 +137,10 @@ public class BuildOrderService : IBuildOrderService |
|
|
|
_lastInterval = interval; |
|
|
|
_lastInterval = interval; |
|
|
|
|
|
|
|
|
|
|
|
if (!_buildOrder.StartedOrders.ContainsKey(_lastInterval)) |
|
|
|
if (!_buildOrder.StartedOrders.ContainsKey(_lastInterval)) |
|
|
|
_buildOrder.StartedOrders.Add(_lastInterval, new List<EntityModel>()); |
|
|
|
_buildOrder.StartedOrders.Add(_lastInterval, []); |
|
|
|
|
|
|
|
|
|
|
|
if (!_buildOrder.CompletedOrders.ContainsKey(_lastInterval)) |
|
|
|
if (!_buildOrder.CompletedOrders.ContainsKey(_lastInterval)) |
|
|
|
_buildOrder.CompletedOrders.Add(_lastInterval, new List<EntityModel>()); |
|
|
|
_buildOrder.CompletedOrders.Add(_lastInterval, []); |
|
|
|
|
|
|
|
|
|
|
|
NotifyDataChanged(); |
|
|
|
NotifyDataChanged(); |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
@ -175,9 +172,10 @@ public class BuildOrderService : IBuildOrderService |
|
|
|
|
|
|
|
|
|
|
|
if (supply == null || supply.Takes.Equals(0)) return 0; |
|
|
|
if (supply == null || supply.Takes.Equals(0)) return 0; |
|
|
|
|
|
|
|
|
|
|
|
foreach (var supplyAtTime in _buildOrder.SupplyCountTimes) |
|
|
|
foreach (var supplyAtTime in |
|
|
|
if (supply.Takes + _buildOrder.CurrentSupplyUsed <= supplyAtTime.Key) |
|
|
|
_buildOrder.SupplyCountTimes |
|
|
|
return supplyAtTime.Value; |
|
|
|
.Where(supplyAtTime => supply.Takes + _buildOrder.CurrentSupplyUsed <= supplyAtTime.Key)) |
|
|
|
|
|
|
|
return supplyAtTime.Value; |
|
|
|
|
|
|
|
|
|
|
|
return null; |
|
|
|
return null; |
|
|
|
} |
|
|
|
} |
|
|
|
@ -199,65 +197,64 @@ public class BuildOrderService : IBuildOrderService |
|
|
|
|
|
|
|
|
|
|
|
public void RemoveLast() |
|
|
|
public void RemoveLast() |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (_buildOrder.StartedOrders.Keys.Count > 1) |
|
|
|
if (_buildOrder.StartedOrders.Keys.Count <= 1) return; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (_buildOrder.StartedOrders.Count == 0) |
|
|
|
{ |
|
|
|
{ |
|
|
|
if (_buildOrder.StartedOrders.Count == 0) |
|
|
|
_buildOrder.StartedOrders.Remove(_buildOrder.StartedOrders.Last().Key); |
|
|
|
{ |
|
|
|
_buildOrder.CompletedOrders.Remove(_buildOrder.CompletedOrders.Last().Key); |
|
|
|
_buildOrder.StartedOrders.Remove(_buildOrder.StartedOrders.Last().Key); |
|
|
|
|
|
|
|
_buildOrder.CompletedOrders.Remove(_buildOrder.CompletedOrders.Last().Key); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_lastInterval = _buildOrder.StartedOrders.Last().Key; |
|
|
|
_lastInterval = _buildOrder.StartedOrders.Last().Key; |
|
|
|
return; |
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
var lastStarted = _buildOrder.StartedOrders.Keys.Last(); |
|
|
|
var lastStarted = _buildOrder.StartedOrders.Keys.Last(); |
|
|
|
var lastCompleted = _buildOrder.CompletedOrders.Keys.Last(); |
|
|
|
var lastCompleted = _buildOrder.CompletedOrders.Keys.Last(); |
|
|
|
|
|
|
|
|
|
|
|
EntityModel entityRemoved = default!; |
|
|
|
EntityModel entityRemoved = default!; |
|
|
|
|
|
|
|
|
|
|
|
if (_buildOrder.StartedOrders[lastStarted].Count > 0) |
|
|
|
if (_buildOrder.StartedOrders[lastStarted].Count > 0) |
|
|
|
{ |
|
|
|
{ |
|
|
|
entityRemoved = _buildOrder.StartedOrders[lastStarted].Last(); |
|
|
|
entityRemoved = _buildOrder.StartedOrders[lastStarted].Last(); |
|
|
|
_buildOrder.StartedOrders[lastStarted].Remove(_buildOrder.StartedOrders[lastStarted].Last()); |
|
|
|
_buildOrder.StartedOrders[lastStarted].Remove(_buildOrder.StartedOrders[lastStarted].Last()); |
|
|
|
_buildOrder.CompletedOrders[lastCompleted].Remove(_buildOrder.CompletedOrders[lastCompleted].Last()); |
|
|
|
_buildOrder.CompletedOrders[lastCompleted].Remove(_buildOrder.CompletedOrders[lastCompleted].Last()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (_buildOrder.StartedOrders[lastStarted].Count == 0) _buildOrder.StartedOrders.Remove(lastStarted); |
|
|
|
|
|
|
|
if (_buildOrder.CompletedOrders[lastCompleted].Count == 0) |
|
|
|
|
|
|
|
_buildOrder.CompletedOrders.Remove(lastCompleted); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (_buildOrder.StartedOrders.Keys.Count > 0) |
|
|
|
if (_buildOrder.StartedOrders[lastStarted].Count == 0) _buildOrder.StartedOrders.Remove(lastStarted); |
|
|
|
_lastInterval = _buildOrder.StartedOrders.Keys.Last(); |
|
|
|
if (_buildOrder.CompletedOrders[lastCompleted].Count == 0) |
|
|
|
else |
|
|
|
_buildOrder.CompletedOrders.Remove(lastCompleted); |
|
|
|
_lastInterval = 0; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (entityRemoved.Supply()?.Grants > 0) |
|
|
|
if (_buildOrder.StartedOrders.Keys.Count > 0) |
|
|
|
SupplyCountTimes.Remove(SupplyCountTimes.Last().Key); |
|
|
|
_lastInterval = _buildOrder.StartedOrders.Keys.Last(); |
|
|
|
|
|
|
|
else |
|
|
|
|
|
|
|
_lastInterval = 0; |
|
|
|
|
|
|
|
|
|
|
|
if (entityRemoved.Supply()?.Takes > 0) |
|
|
|
if (entityRemoved.Supply()?.Grants > 0) |
|
|
|
_buildOrder.CurrentSupplyUsed -= entityRemoved.Supply()!.Takes; |
|
|
|
SupplyCountTimes.Remove(SupplyCountTimes.Last().Key); |
|
|
|
|
|
|
|
|
|
|
|
_buildOrder.UniqueCompletedCount[entityRemoved!.DataType]--; |
|
|
|
if (entityRemoved.Supply()?.Takes > 0) |
|
|
|
if (_buildOrder.UniqueCompletedCount[entityRemoved!.DataType] == 0) |
|
|
|
_buildOrder.CurrentSupplyUsed -= entityRemoved.Supply()!.Takes; |
|
|
|
UniqueCompletedTimes.Remove(entityRemoved.DataType); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
_buildOrder.UniqueCompleted[entityRemoved.DataType] |
|
|
|
_buildOrder.UniqueCompletedCount[entityRemoved!.DataType]--; |
|
|
|
.Remove(_buildOrder.UniqueCompleted[entityRemoved.DataType].Last()); |
|
|
|
if (_buildOrder.UniqueCompletedCount[entityRemoved!.DataType] == 0) |
|
|
|
|
|
|
|
UniqueCompletedTimes.Remove(entityRemoved.DataType); |
|
|
|
|
|
|
|
|
|
|
|
if (entityRemoved.Production() != null |
|
|
|
_buildOrder.UniqueCompleted[entityRemoved.DataType] |
|
|
|
&& entityRemoved.Production()!.ProducedBy != null |
|
|
|
.Remove(_buildOrder.UniqueCompleted[entityRemoved.DataType].Last()); |
|
|
|
&& entityRemoved.Supply() != null |
|
|
|
|
|
|
|
&& entityRemoved.Supply()!.Takes > 0) |
|
|
|
|
|
|
|
_buildOrder.TrainingCapacityUsed.Remove(_buildOrder.TrainingCapacityUsed.Last()); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (entityRemoved.Info().Descriptive == DescriptiveType.Worker) |
|
|
|
if (entityRemoved.Production() != null |
|
|
|
{ |
|
|
|
&& entityRemoved.Production()!.ProducedBy != null |
|
|
|
RemoveLast(); |
|
|
|
&& entityRemoved.Supply() != null |
|
|
|
return; |
|
|
|
&& entityRemoved.Supply()!.Takes > 0) |
|
|
|
} |
|
|
|
_buildOrder.TrainingCapacityUsed.Remove(_buildOrder.TrainingCapacityUsed.Last()); |
|
|
|
|
|
|
|
|
|
|
|
NotifyDataChanged(); |
|
|
|
if (entityRemoved.Info().Descriptive == DescriptiveType.Worker) |
|
|
|
|
|
|
|
{ |
|
|
|
|
|
|
|
RemoveLast(); |
|
|
|
|
|
|
|
return; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
NotifyDataChanged(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -352,22 +349,22 @@ public class BuildOrderService : IBuildOrderService |
|
|
|
var uniqueCompleted = _buildOrder.UniqueCompleted[producedBy]; |
|
|
|
var uniqueCompleted = _buildOrder.UniqueCompleted[producedBy]; |
|
|
|
|
|
|
|
|
|
|
|
var shortestIncrement = int.MaxValue; |
|
|
|
var shortestIncrement = int.MaxValue; |
|
|
|
var trainingSlots = 0; |
|
|
|
|
|
|
|
var didDelay = false; |
|
|
|
var didDelay = false; |
|
|
|
|
|
|
|
|
|
|
|
foreach (var productionEntity in uniqueCompleted) trainingSlots += productionEntity.Supply()!.Grants; |
|
|
|
var trainingSlots = uniqueCompleted.Sum(productionEntity => productionEntity.Supply()!.Grants); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
while (true) |
|
|
|
while (true) |
|
|
|
{ |
|
|
|
{ |
|
|
|
var usedSlots = 0; |
|
|
|
var usedSlots = 0; |
|
|
|
foreach (var used in _buildOrder.TrainingCapacityUsed) |
|
|
|
foreach (var used in |
|
|
|
if (checkedInterval >= used.StartingUsageTime && checkedInterval < used.StopUsageTime) |
|
|
|
_buildOrder.TrainingCapacityUsed |
|
|
|
{ |
|
|
|
.Where(used => checkedInterval >= used.StartingUsageTime && checkedInterval < used.StopUsageTime)) |
|
|
|
usedSlots += used.UsedSlots; |
|
|
|
{ |
|
|
|
var duration = used.StopUsageTime - used.StartingUsageTime; |
|
|
|
usedSlots += used.UsedSlots; |
|
|
|
if (duration < shortestIncrement) shortestIncrement = duration; |
|
|
|
var duration = used.StopUsageTime - used.StartingUsageTime; |
|
|
|
} |
|
|
|
if (duration < shortestIncrement) shortestIncrement = duration; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (usedSlots + supply.Takes <= trainingSlots) |
|
|
|
if (usedSlots + supply.Takes <= trainingSlots) |
|
|
|
{ |
|
|
|
{ |
|
|
|
@ -399,16 +396,15 @@ public class BuildOrderService : IBuildOrderService |
|
|
|
for (var interval = atInterval; interval < withEconomy.GetOverTime().Count; interval++) |
|
|
|
for (var interval = atInterval; interval < withEconomy.GetOverTime().Count; interval++) |
|
|
|
{ |
|
|
|
{ |
|
|
|
var economyAtSecond = withEconomy.GetOverTime()[interval]; |
|
|
|
var economyAtSecond = withEconomy.GetOverTime()[interval]; |
|
|
|
if (economyAtSecond.Alloy >= production.Alloy |
|
|
|
if (!(economyAtSecond.Alloy >= production.Alloy) |
|
|
|
&& economyAtSecond.Ether >= production.Ether |
|
|
|
|| !(economyAtSecond.Ether >= production.Ether) |
|
|
|
&& economyAtSecond.Pyre >= production.Pyre) |
|
|
|
|| !(economyAtSecond.Pyre >= production.Pyre)) continue; |
|
|
|
{ |
|
|
|
|
|
|
|
atInterval = interval; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (entity.EntityType != EntityType.Army) atInterval += _timingService.BuildingInputDelay; |
|
|
|
atInterval = interval; |
|
|
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
if (entity.EntityType != EntityType.Army) atInterval += _timingService.BuildingInputDelay; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if (withEconomy.GetOverTime().Last().Ether < production.Ether) |
|
|
|
if (withEconomy.GetOverTime().Last().Ether < production.Ether) |
|
|
|
|