public void tryEnqueueShip(ShipCost ship)
    {
        // check resource costs
        ResourceTank[] tanks = GetComponents<ResourceTank>();
        float availableResource = 0;
        foreach (ResourceTank tank in tanks)
        {
            if (tank.Type == ship.Type)
            {
                availableResource += tank.Stored;
            }
        }

        if (availableResource < ship.Cost)
        {
            return;
        }

        // consume resources
        int remainingCost = ship.Cost;
        foreach (ResourceTank tank in tanks)
        {
            if (tank.Type == ship.Type)
            {
                remainingCost -= tank.tryExtract(remainingCost);
            }
        }

        // set up start time based on what's in queue
        float startTime = Time.time;
        if (_constructionQueue.Count > 0)
        {
            startTime = _queueCompletionTime;
        }

        // actually enqueue
        ConstructionOrder toEnqueue = new ConstructionOrder() { Ship = ship, StartTime = startTime };
        _constructionQueue.Enqueue(toEnqueue);
        _queueCompletionTime = toEnqueue.EndTime;
        toEnqueue.OnConstructionCompleted += () => CompleteShip(ship);
        toEnqueue.OnConstructionCompleted += () => { if (orderDequeued != null) orderDequeued(toEnqueue); };

        // notify views
        if (orderEnqueued != null)
        {
            orderEnqueued(toEnqueue);
        }
    }
Beispiel #2
0
        private void lstFacilities_MouseDown(object sender, MouseEventArgs e)
        {
            var item = lstFacilities.GetItemAt(e.X, e.Y);

            if (item != null)
            {
                if (e.Button == MouseButtons.Left)
                {
                    // how many to add?
                    var amount = 1;
                    if (ModifierKeys.HasFlag(Keys.Shift))
                    {
                        amount *= 10;
                    }
                    if (ModifierKeys.HasFlag(Keys.Control))
                    {
                        amount *= 100;
                    }

                    var template = (FacilityTemplate)item.Tag;
                    for (int i = 0; i < amount; i++)
                    {
                        var order = new ConstructionOrder <Facility, FacilityTemplate> {
                            Template = template
                        };
                        ConstructionQueue.Orders.Add(order);
                        var cmd = new AddOrderCommand
                                  (
                            ConstructionQueue,
                            order
                                  );
                        newCommands.Add(cmd);
                    }
                    BindQueueListView();
                }
                else if (e.Button == MouseButtons.Right)
                {
                    var facil  = (FacilityTemplate)item.Tag;
                    var report = new FacilityReport(facil);
                    var form   = report.CreatePopupForm(facil.Name);
                    FindForm().ShowChildForm(form);
                }
            }
        }
Beispiel #3
0
        /// <summary>Creates a specified two-dimensional surface.
        /// </summary>
        /// <typeparam name="THorizontalLabel">The type of the horizontal label.</typeparam>
        /// <typeparam name="TVerticalLabel">The type of the vertical label.</typeparam>
        /// <param name="gridPoints">The grid points in its <see cref="LabelMatrix&lt;THorizontalLabel,TVerticalLabel&gt;"/> representation.</param>
        /// <param name="horizontalInterpolator">The interpolation approach along horizontal direction.</param>
        /// <param name="horizontalLeftExtrapolator">The extrapolation approach in horizontal direction on the left.</param>
        /// <param name="horizontalRightExtrapolator">The extrapolation approach in horizontal direction on the right.</param>
        /// <param name="verticalInterpolator">The interpolation approach along vertical direction.</param>
        /// <param name="verticalAboveExtrapolator">The extrapolation approach in vertical direction above the grid points.</param>
        /// <param name="verticalBelowExtrapolator">The extrapolation approach in vertical direction below the grid points.</param>
        /// <param name="constructionOrder">A value indicating the order of the vertical and horizontal interpolation, extrapolation etc.</param>
        /// <returns>An object that repesents the two-dimensional surface with respect to the specified grid points and interpolation/extrapolation.</returns>
        public static IGridPointSurface2d <THorizontalLabel, TVerticalLabel> Create <THorizontalLabel, TVerticalLabel>(LabelMatrix <THorizontalLabel, TVerticalLabel> gridPoints, GridPointCurve.Interpolator horizontalInterpolator, GridPointCurve.Extrapolator horizontalLeftExtrapolator, GridPointCurve.Extrapolator horizontalRightExtrapolator, GridPointCurve.Interpolator verticalInterpolator, GridPointCurve.Extrapolator verticalAboveExtrapolator, GridPointCurve.Extrapolator verticalBelowExtrapolator, ConstructionOrder constructionOrder = ConstructionOrder.HorizontalVertical)
            where THorizontalLabel : IComparable <THorizontalLabel>, IEquatable <THorizontalLabel>
            where TVerticalLabel : IComparable <TVerticalLabel>, IEquatable <TVerticalLabel>
        {
            if (gridPoints == null)
            {
                throw new ArgumentNullException(nameof(gridPoints));
            }
            if (horizontalInterpolator == null)
            {
                throw new ArgumentNullException(nameof(horizontalInterpolator));
            }
            if (horizontalLeftExtrapolator == null)
            {
                throw new ArgumentNullException(nameof(horizontalLeftExtrapolator));
            }
            if (horizontalRightExtrapolator == null)
            {
                throw new ArgumentNullException(nameof(horizontalRightExtrapolator));
            }
            switch (constructionOrder)
            {
            case ConstructionOrder.HorizontalVertical:
                var horizontalCurveFactory = GridPointCurve.Factory.Create <THorizontalLabel>(horizontalInterpolator, horizontalLeftExtrapolator, horizontalRightExtrapolator);
                return(new HorizontalVerticalWiseSurface2d <THorizontalLabel, TVerticalLabel> .VInterpolation(gridPoints, verticalLabel => horizontalCurveFactory, verticalInterpolator, verticalAboveExtrapolator, verticalBelowExtrapolator));

            case ConstructionOrder.VerticalHorizontal:
                var verticalCurveFactory = GridPointCurve.Factory.Create <TVerticalLabel>(verticalInterpolator, verticalAboveExtrapolator, verticalBelowExtrapolator);
                return(new VerticalHorizontalWiseSurface2d <THorizontalLabel, TVerticalLabel> .HInterpolation(gridPoints, horizontalLabel => verticalCurveFactory, horizontalInterpolator, horizontalLeftExtrapolator, horizontalRightExtrapolator));

            default:
                throw new NotImplementedException();
            }
        }
Beispiel #4
0
        /// <summary>Creates a specified two-dimensional surface.
        /// </summary>
        /// <typeparam name="THorizontalLabel">The type of the horizontal label.</typeparam>
        /// <typeparam name="TVerticalLabel">The type of the vertical label.</typeparam>
        /// <param name="gridPoints">The grid points in its <see cref="LabelMatrix&lt;THorizontalLabel,TVerticalLabel&gt;"/> representation.</param>
        /// <param name="horizontalParametrization">The (curve) parametrization in horizontal direction.</param>
        /// <param name="verticalParametrization">The (curve) parametrization in vertical direction.</param>
        /// <param name="constructionOrder">A value indicating the order of the vertical and horizontal interpolation, extrapolation etc.</param>
        /// <returns>An object that repesents the two-dimensional surface with respect to the specified grid points and interpolation/extrapolation.</returns>
        public static IGridPointSurface2d <THorizontalLabel, TVerticalLabel> Create <THorizontalLabel, TVerticalLabel>(LabelMatrix <THorizontalLabel, TVerticalLabel> gridPoints, GridPointCurve.Parametrization horizontalParametrization, GridPointCurve.Parametrization verticalParametrization, ConstructionOrder constructionOrder = ConstructionOrder.HorizontalVertical)
            where THorizontalLabel : IComparable <THorizontalLabel>, IEquatable <THorizontalLabel>
            where TVerticalLabel : IComparable <TVerticalLabel>, IEquatable <TVerticalLabel>
        {
            if (gridPoints == null)
            {
                throw new ArgumentNullException(nameof(gridPoints));
            }
            switch (constructionOrder)
            {
            case ConstructionOrder.HorizontalVertical:
                var horizontalCurveFactory = GridPointCurve.Factory.Create <THorizontalLabel>(horizontalParametrization);
                return(new HorizontalVerticalWiseSurface2d <THorizontalLabel, TVerticalLabel> .VParametrization(gridPoints, verticalLabel => horizontalCurveFactory, verticalParametrization));

            case ConstructionOrder.VerticalHorizontal:
                var verticalCurveFactory = GridPointCurve.Factory.Create <TVerticalLabel>(verticalParametrization);
                return(new VerticalHorizontalWiseSurface2d <THorizontalLabel, TVerticalLabel> .HParametrization(gridPoints, horizontalLabel => verticalCurveFactory, horizontalParametrization));

            default:
                throw new NotImplementedException();
            }
        }