示例#1
0
        /// <summary>
        /// Handles ordnance factory construction.
        /// </summary>
        /// <param name="P">List of factions.</param>
        public static void OrdnanceFactoryBuild(BindingList <Faction> P)
        {
            /// <summary>
            /// Subtract the construction cycle from the construction tick.
            /// </summary>

            foreach (Faction CurrentFaction in P)
            {
                foreach (Population CurrentPopulation in CurrentFaction.Populations)
                {
                    /// <summary>
                    /// How much construction work per day does this colony do? default should be 5 day construction cycle.
                    /// </summary>
                    float CurrentIndustry = CurrentPopulation.CalcTotalOrdnanceIndustry() * Constants.Colony.ConstructionCycleFraction;
                    float BuildPercentage = 0.0f;

                    foreach (MissileBuildQueueItem CurrentConstruction in CurrentPopulation.MissileBuildQueue)
                    {
                        /// <summary>
                        /// Check to see if this item is in the current build queue, or has to wait for capacity to free up.
                        /// </summary>
                        if ((BuildPercentage + CurrentConstruction.buildCapacity) <= 100.0f)
                        {
                            BuildPercentage = BuildPercentage + CurrentConstruction.buildCapacity;
                        }
                        else
                        {
                            break;
                        }

                        /// <summary>
                        /// Calculate Completion Estimate:
                        /// </summary>
                        float BPRequirement     = (float)Math.Floor(CurrentConstruction.numToBuild) * (float)CurrentConstruction.costPerItem;
                        float DaysInYear        = (float)Constants.TimeInSeconds.RealYear / (float)Constants.TimeInSeconds.Day;
                        float YearsOfProduction = (BPRequirement / CurrentConstruction.buildCapacity);

                        if (CurrentConstruction.buildCapacity != 0.0f && YearsOfProduction < Constants.Colony.TimerYearMax)
                        {
                            int      TimeToBuild = (int)Math.Floor(YearsOfProduction * DaysInYear);
                            DateTime EstTime     = GameState.Instance.GameDateTime;
                            TimeSpan TS          = new TimeSpan(TimeToBuild, 0, 0, 0);
                            EstTime = EstTime.Add(TS);
                            CurrentConstruction.completionDate = EstTime;
                        }

                        /// <summary>
                        /// This construction project is paused right now.
                        /// </summary>
                        if (CurrentConstruction.inProduction == false)
                        {
                            continue;
                        }

                        /// <summary>
                        /// how much of total industry does this build project use?
                        /// </summary>
                        float DevotedIndustry = (CurrentConstruction.buildCapacity / 100.0f) * CurrentIndustry;
                        float Completion      = DevotedIndustry / (float)CurrentConstruction.costPerItem;

                        /// <summary>
                        /// Do I have the minerals to build this missile?
                        /// </summary>
                        bool CanBuild = CurrentPopulation.MineralRequirement(CurrentConstruction.ordnanceDef.minerialsCost, Completion);

                        if (CanBuild == false)
                        {
                            String Entry = String.Format("Insufficent Minerals to continue build order on {0} for {1}x {2}", CurrentPopulation, CurrentConstruction.numToBuild,
                                                         CurrentConstruction.Name);
                            MessageEntry Msg = new MessageEntry(MessageEntry.MessageType.ColonyLacksMinerals, CurrentPopulation.Contact.Position.System, CurrentPopulation.Contact,
                                                                GameState.Instance.GameDateTime, GameState.Instance.LastTimestep, Entry);
                            CurrentFaction.MessageLog.Add(Msg);
                            continue;
                        }


                        /// <summary>
                        /// Adjust number to build downward to reflect construction happening.
                        /// </summary>
                        CurrentConstruction.numToBuild = CurrentConstruction.numToBuild - Completion;

                        CurrentPopulation.HandleBuildItemCost(CurrentConstruction.costPerItem, CurrentConstruction.ordnanceDef.minerialsCost, Completion);

                        CurrentPopulation.LoadMissileToStockpile(CurrentConstruction.ordnanceDef, Completion);
                    }

                    /// <summary>
                    /// Cleanup the CBQ here.
                    /// </summary>
                    for (int MBQIterator = 0; MBQIterator < CurrentPopulation.MissileBuildQueue.Count; MBQIterator++)
                    {
                        if (CurrentPopulation.MissileBuildQueue[MBQIterator].numToBuild <= 0.0f)
                        {
                            CurrentPopulation.MissileBuildQueue.RemoveAt(MBQIterator);
                            MBQIterator--;
                        }
                    }
                }
            }
        }
示例#2
0
        /// <summary>
        /// Handles ordnance factory construction.
        /// </summary>
        /// <param name="P">List of factions.</param>
        public static void OrdnanceFactoryBuild(BindingList <Faction> P)
        {
            /// <summary>
            /// Subtract the construction cycle from the construction tick.
            /// </summary>

            foreach (Faction CurrentFaction in P)
            {
                foreach (Population CurrentPopulation in CurrentFaction.Populations)
                {
                    /// <summary>
                    /// How much construction work per day does this colony do? default should be 5 day construction cycle.
                    /// </summary>
                    float TimeAdjust      = (float)Constants.Colony.ConstructionCycle / (float)Constants.TimeInSeconds.Year;
                    float CurrentIndustry = CurrentPopulation.CalcTotalOrdnanceIndustry() * TimeAdjust;
                    float BuildPercentage = 0.0f;

                    foreach (MissileBuildQueueItem CurrentConstruction in CurrentPopulation.MissileBuildQueue)
                    {
                        /// <summary>
                        /// Check to see if this item is in the current build queue, or has to wait for capacity to free up.
                        /// </summary>
                        if ((BuildPercentage + CurrentConstruction.buildCapacity) <= 100.0f)
                        {
                            BuildPercentage = BuildPercentage + CurrentConstruction.buildCapacity;
                        }
                        else
                        {
                            break;
                        }

                        /// <summary>
                        /// This construction project is paused right now.
                        /// </summary>
                        if (CurrentConstruction.inProduction == false)
                        {
                            continue;
                        }

                        /// <summary>
                        /// how much of total industry does this build project use?
                        /// </summary>
                        float DevotedIndustry = (CurrentConstruction.buildCapacity / 100.0f) * CurrentIndustry;
                        float Completion      = DevotedIndustry / (float)CurrentConstruction.costPerItem;
                        int   NumberBuilt     = 0;


                        /// <summary>
                        /// Final bit of a construction project to complete.
                        /// </summary>
                        if (Completion >= CurrentConstruction.numToBuild)
                        {
                            NumberBuilt = (int)Math.Floor(CurrentConstruction.numToBuild);
                            Completion  = CurrentConstruction.numToBuild;
                        }
                        /// <summary>
                        /// This is a new build item.
                        /// </summary>
                        else if (Math.Floor(CurrentConstruction.numToBuild) == CurrentConstruction.numToBuild)
                        {
                            /// <summary>
                            /// This colony will build or start to build this many items. charge for all of them.
                            /// </summary>
                            NumberBuilt = (int)Math.Ceiling(Completion);

                            /// <summary>
                            /// the colony can build everything in one go.
                            /// </summary>
                            if (NumberBuilt >= Math.Floor(CurrentConstruction.numToBuild))
                            {
                                NumberBuilt = (int)Math.Floor(CurrentConstruction.numToBuild);
                                Completion  = CurrentConstruction.numToBuild;
                            }
                        }
                        /// <summary>
                        /// This is an inprogress item, new items will be started however.
                        /// </summary>
                        else if ((CurrentConstruction.numToBuild - Completion) < Math.Floor(CurrentConstruction.numToBuild))
                        {
                            /// <summary>
                            /// Adjust out the current build fraction, and then calculate how many new items will be started.
                            float CurBuildReq = (CurrentConstruction.numToBuild - (float)Math.Floor(CurrentConstruction.numToBuild));
                            NumberBuilt = (int)Math.Ceiling(Completion - CurBuildReq);
                            if (NumberBuilt > Math.Floor(CurrentConstruction.numToBuild))
                            {
                                NumberBuilt = (int)Math.Floor(CurrentConstruction.numToBuild);
                            }
                        }

                        /// <summary>
                        /// Do I have the minerals to build this missile?
                        /// </summary>
                        bool CanBuild = CurrentPopulation.MineralRequirement(CurrentConstruction.ordnanceDef.minerialsCost);

                        if (CanBuild == false)
                        {
                            String Entry = String.Format("Insufficent Minerals to continue build order on {0} for {1}x {2}", CurrentPopulation, CurrentConstruction.numToBuild,
                                                         CurrentConstruction.Name);
                            MessageEntry Msg = new MessageEntry(MessageEntry.MessageType.ColonyLacksMinerals, CurrentPopulation.Contact.Position.System, CurrentPopulation.Contact,
                                                                GameState.Instance.GameDateTime, GameState.Instance.LastTimestep, Entry);
                            CurrentFaction.MessageLog.Add(Msg);
                            continue;
                        }


                        /// <summary>
                        /// Adjust number to build downward to reflect construction happening.
                        /// </summary>
                        int CompletedItems = (int)Math.Ceiling(CurrentConstruction.numToBuild);
                        CurrentConstruction.numToBuild = CurrentConstruction.numToBuild - Completion;
                        CompletedItems = CompletedItems - (int)Math.Ceiling(CurrentConstruction.numToBuild);

                        CurrentPopulation.HandleBuildItemCost((CurrentConstruction.costPerItem * NumberBuilt), CurrentConstruction.ordnanceDef.minerialsCost);

                        CurrentPopulation.LoadMissileToStockpile(CurrentConstruction.ordnanceDef, CompletedItems);
                    }

                    /// <summary>
                    /// Cleanup the CBQ here.
                    /// </summary>
                    for (int MBQIterator = 0; MBQIterator < CurrentPopulation.MissileBuildQueue.Count; MBQIterator++)
                    {
                        if (CurrentPopulation.MissileBuildQueue[MBQIterator].numToBuild == 0.0f)
                        {
                            CurrentPopulation.MissileBuildQueue.RemoveAt(MBQIterator);
                            MBQIterator--;
                        }
                    }
                }
            }
        }