/// <summary> /// Does 1 turn's worth of building. /// </summary> public void Execute(IOrderable q) { var queue = (ConstructionQueue)q; var errors = GetErrors(queue); foreach (var error in errors) { queue.Owner.Log.Add(error); } if (!errors.Any()) { // create item if needed if (Item == null) { Item = Template.Instantiate(); if (!(Item is Facility)) { Item.Owner = queue.Owner; } if (Item is SpaceVehicle) { // space vehicles need their supplies filled up var sv = (SpaceVehicle)(IConstructable)Item; sv.SupplyRemaining = sv.SupplyStorage; } } // apply build rate var costLeft = Item.Cost - Item.ConstructionProgress; var spending = ResourceQuantity.Min(costLeft, queue.UnspentRate); if (!(spending <= queue.Owner.StoredResources)) { spending = ResourceQuantity.Min(spending, queue.Owner.StoredResources); if (spending.IsEmpty) { if (!queue.IsConstructionDelayed) // don't spam messages! { Owner.Log.Add(queue.Container.CreateLogMessage("Construction of " + Template + " at " + queue.Container + " was paused due to lack of resources.")); } } else { Owner.Log.Add(queue.Container.CreateLogMessage("Construction of " + Template + " at " + queue.Container + " was slowed due to lack of resources.")); } queue.IsConstructionDelayed = true; } queue.Owner.StoredResources -= spending; queue.UnspentRate -= spending; Item.ConstructionProgress += spending; } }
/// <summary> /// Does 1 turn's worth of building. /// </summary> public void Execute(IOrderable ord) { if (ord is ConstructionQueue queue) { var errors = GetErrors(queue); foreach (var error in errors) { queue.Owner.Log.Add(error); } if (!errors.Any()) { // create item if needed if (NewFacility == null) { NewFacility = Upgrade.New.Instantiate(); } // apply build rate var costLeft = Cost - NewFacility.ConstructionProgress; var spending = ResourceQuantity.Min(costLeft, queue.UnspentRate); if (spending < queue.Owner.StoredResources) { spending = ResourceQuantity.Min(spending, queue.Owner.StoredResources); queue.Container.CreateLogMessage("Construction of " + Upgrade.New + " at " + queue.Container + " was delayed due to lack of resources."); } queue.Owner.StoredResources -= spending; queue.UnspentRate -= spending; NewFacility.ConstructionProgress += spending; // if we're done, delete the old facility and replace it with this one if (CheckCompletion(queue)) { var planet = (Planet)queue.Container; planet.Colony.Facilities.Where(f => f.Template == Upgrade.Old).First().Dispose(); planet.Colony.Facilities.Add(NewFacility); } } } }