/// <summary> /// Removes a production order from the Queue control. /// </summary> /// <param name="productionOrder">index to remove</param> public void RemoveProductionOrder(int index) { // Can't remove header! if (index == 0) { return; } ICommand command = new ProductionCommand(CommandMode.Delete, null, starKey, index - 1); ProductionCommands.Enqueue(command); Items.RemoveAt(index); UpdateHeader(); }
} // BuildColonizer() /// <summary> /// Add a transport to the production queue, if required and we can afford it. /// </summary> /// <param name="productionIndex">The current insertion point into the planet's production queue.</param> /// <returns>The updated productionIndex.</returns> /// <remarks> /// How many transports do we need? - Let the aiPlan decide. /// </remarks> private int BuildTransport(int productionIndex) { if (this.planet.GetResourceRate() > DefaultAIPlanner.LowProduction && this.aiPlan.TotalTransportKt < this.aiPlan.TransportKtRequired) { if (this.aiPlan.TransportDesign != null) { ProductionOrder transportOrder = new ProductionOrder(1, new ShipProductionUnit(this.aiPlan.TransportDesign), false); ProductionCommand transportCommand = new ProductionCommand(CommandMode.Add, transportOrder, this.planet.Key, productionIndex); if (transportCommand.IsValid(clientState.EmpireState)) { transportCommand.ApplyToState(clientState.EmpireState); clientState.Commands.Push(transportCommand); productionIndex++; } } } return(productionIndex); } // BuildTransport()
} // BuildScouts() /// <summary> /// Add a colonizer to the production queue, if required and we can afford it. /// </summary> /// <param name="productionIndex">The current insertion point into the planet's production queue.</param> /// <returns>The updated productionIndex.</returns> /// <remarks> /// Always make one spare colonizer. /// </remarks> private int BuildColonizer(int productionIndex) { if (this.planet.GetResourceRate() > DefaultAIPlanner.LowProduction && this.aiPlan.ColonizerCount < (this.aiPlan.PlanetsToColonize - this.aiPlan.ColonizerCount + 1)) { if (this.aiPlan.ColonizerDesign != null) { ProductionOrder colonizerOrder = new ProductionOrder(1, new ShipProductionUnit(this.aiPlan.ColonizerDesign), false); ProductionCommand colonizerCommand = new ProductionCommand(CommandMode.Add, colonizerOrder, this.planet.Key, productionIndex); if (colonizerCommand.IsValid(clientState.EmpireState)) { colonizerCommand.ApplyToState(clientState.EmpireState); clientState.Commands.Push(colonizerCommand); productionIndex++; } } } return(productionIndex); } // BuildColonizer()
} // Build ships /// <summary> /// Add a scout to the production queue, if required and we can afford it. /// </summary> /// <param name="productionIndex">The current insertion point into the planet's production queue.</param> /// <returns>The updated productionIndex.</returns> private int BuildScout(int productionIndex) { if (this.planet.GetResourceRate() > DefaultAIPlanner.LowProduction && this.aiPlan.ScoutCount < DefaultAIPlanner.EarlyScouts) { if (this.aiPlan.ScoutDesign != null) { ProductionOrder scoutOrder = new ProductionOrder(1, new ShipProductionUnit(this.aiPlan.ScoutDesign), false); ProductionCommand scoutCommand = new ProductionCommand(CommandMode.Add, scoutOrder, this.planet.Key, productionIndex); if (scoutCommand.IsValid(clientState.EmpireState)) { scoutCommand.ApplyToState(clientState.EmpireState); clientState.Commands.Push(scoutCommand); productionIndex++; } } } return(productionIndex); } // BuildScouts()
/// <summary> /// Inserts a production order to the Queue at a specific index. /// </summary> /// <param name="productionOrder">The ProductionOrder to insert</param> /// <returns>The added ListViewItem</returns> public ListViewItem InsertProductionOrder(ProductionOrder productionOrder, int index) { ICommand command = new ProductionCommand(CommandMode.Add, productionOrder, starKey, index - 1); ProductionCommands.Enqueue(command); ListViewItem item = new ListViewItem(); item.Text = productionOrder.Name; item.Tag = productionOrder; item.SubItems.Add(productionOrder.Quantity.ToString(System.Globalization.CultureInfo.InvariantCulture)); Items.Insert(index, item); Items[index].Selected = true; UpdateHeader(); return(item); }
/// <summary> /// Removes a production order from the Queue control. /// </summary> /// <param name="productionOrder">ListViewItem to remove</param> public void RemoveProductionOrder(ListViewItem item) { if (!Items.Contains(item)) { return; } ICommand command = new ProductionCommand(CommandMode.Edit, null, starKey, Items.IndexOf(item) - 1); ProductionCommands.Enqueue(command); // Can't remove the header! if (Items[0] == item) { return; } Items.Remove(item); UpdateHeader(); }
/// <summary> /// Edits a production order at a certain queue position /// </summary> /// <param name="productionOrder">The new production order</param> /// <param name="index">The queue position</param> /// <returns>The new edited item</returns> public ListViewItem EditProductionOrder(ProductionOrder productionOrder, int index) { // Can't edit header! if (index == 0) { return(null); } ICommand command = new ProductionCommand(CommandMode.Edit, productionOrder, starKey, index - 1); ProductionCommands.Enqueue(command); Items[index].SubItems.Clear(); Items[index].Text = productionOrder.Name; Items[index].Tag = productionOrder; Items[index].SubItems.Add(productionOrder.Quantity.ToString(System.Globalization.CultureInfo.InvariantCulture)); Items[index].Selected = true; return(Items[index]); }
public void HandleProduction() { // keep track of the position in the production queue int productionIndex = 0; // Clear the current manufacturing queue (except for partially built ships/starbases). Queue <ProductionCommand> clearProductionList = new Queue <ProductionCommand>(); foreach (ProductionOrder productionOrderToclear in this.planet.ManufacturingQueue.Queue) { if (productionOrderToclear.Unit.Cost == productionOrderToclear.Unit.RemainingCost) { ProductionCommand clearProductionCommand = new ProductionCommand(CommandMode.Delete, productionOrderToclear, this.planet.Key); if (clearProductionCommand.IsValid(clientState.EmpireState)) { // Put the items to be cleared in a queue, as the actual cleanup can not be done while itterating the list. clearProductionList.Enqueue(clearProductionCommand); clientState.Commands.Push(clearProductionCommand); } } else { productionIndex++; } } foreach (ProductionCommand clearProductionCommand in clearProductionList) { clearProductionCommand.ApplyToState(clientState.EmpireState); } // build factories (limited by Germanium, and don't want to use it all) if (this.planet.ResourcesOnHand.Germanium > 50) { int factoryBuildCostGerm = clientState.EmpireState.Race.HasTrait("CF") ? 3 : 4; int factoriesToBuild = (int)((this.planet.ResourcesOnHand.Germanium - 50) / factoryBuildCostGerm); if (factoriesToBuild > (this.planet.GetOperableFactories() - this.planet.Factories)) { factoriesToBuild = this.planet.GetOperableFactories() - this.planet.Factories; } if (factoriesToBuild > 0) { ProductionOrder factoryOrder = new ProductionOrder(factoriesToBuild, new FactoryProductionUnit(clientState.EmpireState.Race), false); ProductionCommand factoryCommand = new ProductionCommand(CommandMode.Add, factoryOrder, this.planet.Key, FactoryProductionPrecedence); productionIndex++; if (factoryCommand.IsValid(clientState.EmpireState)) { factoryCommand.ApplyToState(clientState.EmpireState); this.clientState.Commands.Push(factoryCommand); } } } // build mines int maxMines = this.planet.GetOperableMines(); if (this.planet.Mines < maxMines) { ProductionOrder mineOrder = new ProductionOrder(maxMines - this.planet.Mines, new MineProductionUnit(clientState.EmpireState.Race), false); ProductionCommand mineCommand = new ProductionCommand(CommandMode.Add, mineOrder, this.planet.Key, Math.Min(MineProductionPrecedence, productionIndex)); productionIndex++; if (mineCommand.IsValid(clientState.EmpireState)) { mineCommand.ApplyToState(clientState.EmpireState); clientState.Commands.Push(mineCommand); } } // Build ships productionIndex = BuildShips(productionIndex); // build defenses int defenseToBuild = Global.MaxDefenses - this.planet.Defenses; if (defenseToBuild > 0) { ProductionOrder defenseOrder = new ProductionOrder(defenseToBuild, new DefenseProductionUnit(), false); ProductionCommand defenseCommand = new ProductionCommand(CommandMode.Add, defenseOrder, this.planet.Key, productionIndex); productionIndex++; if (defenseCommand.IsValid(clientState.EmpireState)) { defenseCommand.ApplyToState(clientState.EmpireState); clientState.Commands.Push(defenseCommand); } } }
// // GET: /ProductionCommand/ public ActionResult Edit(int?id, double?khoGiay, int?buhao) { ProductionCommand command = new ProductionCommand(); command.Detail = db.tbl_OrderTem_BaoGia_Detail.Find(id); command.Product = db.tbl_Products.Find(command.Detail.sanpam_id); command.Command = db.tbl_ProductionCommand.Where(T => T.product_id == command.Product.ID_Products).FirstOrDefault(); if (command.Command == null) { if (khoGiay == null) { khoGiay = 1; } if (buhao == null) { buhao = 0; } command.Command = new tbl_ProductionCommand { KhoGiay = khoGiay.HasValue ? khoGiay.Value :1, NgayLap = DateTime.Now, BuHao = buhao.HasValue?buhao.Value: 0 }; String[] quyCach = command.Product.QuyCachProducts.Trim().Split('x').Where(T => T.Trim().Length > 0).Select(T => T.Trim()).ToArray(); System.Nullable <double> D = (quyCach.Length == 2 ? double.Parse(quyCach[0]) : ((double.Parse(quyCach[0]) + double.Parse(quyCach[1])) * 2 + 5)); System.Nullable <double> R1 = ((double.Parse(quyCach[1]) + 1) * command.Command.KhoGiay) % 5 == 0 ? (((double.Parse(quyCach[1]) + 1) * command.Command.KhoGiay) / 5 * 5) : (((double.Parse(quyCach[1]) + 1) * command.Command.KhoGiay) / 5 * 5 + 5); System.Nullable <double> R = quyCach.Length == 3 ? ((double.Parse(quyCach[0]) + double.Parse(quyCach[1]) + 1) * command.Command.KhoGiay) % 5 == 0 ? (((double.Parse(quyCach[0]) + double.Parse(quyCach[1]) + 1) * command.Command.KhoGiay) / 5 * 5) : (((double.Parse(quyCach[0]) + double.Parse(quyCach[1]) + 1) * command.Command.KhoGiay) / 5 * 5 + 5) : R1; String[] loaiGiay = command.Product.LoaigiayProducts.Trim().Split('-').Where(T => T.Trim().Length > 0).Select(T => T.Trim()).ToArray(); command.Command.Loai7 = loaiGiay[loaiGiay.Length - 1]; command.Command.Loai1 = loaiGiay.Length > 0 && (0 < loaiGiay.Length - 1) ?loaiGiay[0]:""; command.Command.Loai2 = loaiGiay.Length > 1 && (1 < loaiGiay.Length - 1) ? loaiGiay[1]:""; command.Command.Loai3 = loaiGiay.Length > 2 && (2 < loaiGiay.Length - 1) ?loaiGiay[2]:""; command.Command.Loai4 = loaiGiay.Length > 3 && (3 < loaiGiay.Length - 1) ?loaiGiay[3]:""; command.Command.Loai5 = loaiGiay.Length > 4 && (4 < loaiGiay.Length - 1) ?loaiGiay[4]:""; command.Command.Loai6 = loaiGiay.Length > 5 && (5 < loaiGiay.Length - 1) ? loaiGiay[5] : ""; command.Command.Dai = D; command.Command.Rong = R; command.Command.KhoCuon7 = command.Command.Rong; command.Command.KhoCuon1 = loaiGiay.Length > 0 && (0 < loaiGiay.Length - 1) ? command.Command.Rong : null; command.Command.KhoCuon2 = loaiGiay.Length > 1 && (1 < loaiGiay.Length - 1) ? command.Command.Rong : null; command.Command.KhoCuon3 = loaiGiay.Length > 2 && (2 < loaiGiay.Length - 1) ? command.Command.Rong : null; command.Command.KhoCuon4 = loaiGiay.Length > 3 && (3 < loaiGiay.Length - 1) ? command.Command.Rong : null; command.Command.KhoCuon5 = loaiGiay.Length > 4 && (4 < loaiGiay.Length - 1) ? command.Command.Rong : null; command.Command.KhoCuon6 = loaiGiay.Length > 5 && (5 < loaiGiay.Length - 1) ? command.Command.Rong : null; } else { if (khoGiay != null && buhao != null) { command.Command.KhoGiay = khoGiay; command.Command.BuHao = buhao; String[] quyCach = command.Product.QuyCachProducts.Trim().Split('x').Where(T => T.Trim().Length > 0).Select(T => T.Trim()).ToArray(); System.Nullable <double> D = (quyCach.Length == 2 ? double.Parse(quyCach[0]) : ((double.Parse(quyCach[0]) + double.Parse(quyCach[1])) * 2 + 5)); System.Nullable <double> R1 = ((double.Parse(quyCach[1]) + 1) * command.Command.KhoGiay) % 5 == 0 ? (((double.Parse(quyCach[1]) + 1) * command.Command.KhoGiay) / 5 * 5) : (((double.Parse(quyCach[1]) + 1) * command.Command.KhoGiay) / 5 * 5 + 5); System.Nullable <double> R = quyCach.Length == 3 ? ((double.Parse(quyCach[0]) + double.Parse(quyCach[1]) + 1) * command.Command.KhoGiay) % 5 == 0 ? (((double.Parse(quyCach[0]) + double.Parse(quyCach[1]) + 1) * command.Command.KhoGiay) / 5 * 5) : (((double.Parse(quyCach[0]) + double.Parse(quyCach[1]) + 1) * command.Command.KhoGiay) / 5 * 5 + 5) : R1; String[] loaiGiay = command.Product.LoaigiayProducts.Trim().Split('-').Where(T => T.Trim().Length > 0).Select(T => T.Trim()).ToArray(); command.Command.Loai7 = loaiGiay[loaiGiay.Length - 1]; command.Command.Loai1 = loaiGiay.Length > 0 && (0 < loaiGiay.Length - 1) ? loaiGiay[0] : ""; command.Command.Loai2 = loaiGiay.Length > 1 && (1 < loaiGiay.Length - 1) ? loaiGiay[1] : ""; command.Command.Loai3 = loaiGiay.Length > 2 && (2 < loaiGiay.Length - 1) ? loaiGiay[2] : ""; command.Command.Loai4 = loaiGiay.Length > 3 && (3 < loaiGiay.Length - 1) ? loaiGiay[3] : ""; command.Command.Loai5 = loaiGiay.Length > 4 && (4 < loaiGiay.Length - 1) ? loaiGiay[4] : ""; command.Command.Loai6 = loaiGiay.Length > 5 && (5 < loaiGiay.Length - 1) ? loaiGiay[5] : ""; command.Command.Dai = D; command.Command.Rong = R; command.Command.KhoCuon7 = command.Command.Rong; command.Command.KhoCuon1 = loaiGiay.Length > 0 && (0 < loaiGiay.Length - 1) ? command.Command.Rong : null; command.Command.KhoCuon2 = loaiGiay.Length > 1 && (1 < loaiGiay.Length - 1) ? command.Command.Rong : null; command.Command.KhoCuon3 = loaiGiay.Length > 2 && (2 < loaiGiay.Length - 1) ? command.Command.Rong : null; command.Command.KhoCuon4 = loaiGiay.Length > 3 && (3 < loaiGiay.Length - 1) ? command.Command.Rong : null; command.Command.KhoCuon5 = loaiGiay.Length > 4 && (4 < loaiGiay.Length - 1) ? command.Command.Rong : null; command.Command.KhoCuon6 = loaiGiay.Length > 5 && (5 < loaiGiay.Length - 1) ? command.Command.Rong : null; } } return(View(command)); }