示例#1
0
        /// <summary>
        /// Finds the number of orders directly above this order that have the same template as the item directly above.
        /// </summary>
        /// <param name="o"></param>
        /// <returns></returns>
        public int FindSameItemsCountAbove(IConstructionOrder o)
        {
            var pos = ConstructionQueue.Orders.IndexOf(o);
            int num = 0;
            IConstructionTemplate t = null;

            for (var i = pos - 1; i >= 0; i--)
            {
                if (t == null)
                {
                    t = ConstructionQueue.Orders[i].Template;
                }
                if (ConstructionQueue.Orders[i].Template == t)
                {
                    num++;
                }
                else
                {
                    break;
                }
            }
            return(num);
        }
示例#2
0
        private void RemoveOrder(IConstructionOrder order, bool rebindGui = true)
        {
            var cmds = Empire.Current.Commands.OfType <AddOrderCommand>().Where(o => o.Order == order).ToArray();

            if (cmds.Any())
            {
                // remove add-order command since the order is new this turn
                foreach (var cmd in cmds)
                {
                    removedCommands.Add(cmd);
                }
            }
            else
            {
                cmds = newCommands.OfType <AddOrderCommand>().Where(o => o.Order == order).ToArray();
                if (cmds.Any())
                {
                    // Not only new this turn, but new this instance of this form!
                    foreach (var cmd in cmds)
                    {
                        newCommands.Remove(cmd);
                    }
                }
                else
                {
                    // add remove-order command
                    var cmd = new RemoveOrderCommand(ConstructionQueue, order);
                    newCommands.Add(cmd);
                }
            }

            // remove the order
            ConstructionQueue.Orders.Remove(order);

            if (order.Template is IDesign)
            {
                var design = order.Template as IDesign;

                // is this a new design we've never built before and are not building any more of? then don't tell the server so other players don't know ;)
                if (design.IsNew && !BuildingAnywhere(design))
                {
                    // HACK - why can there be multiple commands to create the same design?
                    foreach (var cmd in Empire.Current.Commands.OfType <ICreateDesignCommand>().Where(c => c.Design == design).ToArray())
                    {
                        Empire.Current.Commands.Remove(cmd);
                    }
                }
            }

            if (rebindGui)
            {
                BindQueueListView();
                if (chkOnlyLatest.Checked)
                {
                    BindUpgradeListView(Empire.Current.UnlockedItems.OfType <FacilityTemplate>().Where(f => f.Cost.Any()).OnlyLatestVersions(f => f.Family));
                }
                else
                {
                    BindUpgradeListView(Empire.Current.UnlockedItems.OfType <FacilityTemplate>().Where(f => f.Cost.Any()));
                }
            }
        }