Beispiel #1
0
        /// <summary>
        /// TakeComponents from Stockpile takes the specified number of components out of the stockpile, and returns how many were subtracted.
        /// </summary>
        /// <param name="ComponentDef">Component def to be removed.</param>
        /// <param name="decrement">number to remove</param>
        /// <returns>number that were removed.</returns>
        public float TakeComponentsFromStockpile(ComponentDefTN ComponentDef, float decrement)
        {
            float Components = 0.0f;

            if (ComponentStockpileLookup.ContainsKey(ComponentDef.Id) == true)
            {
                Components = ComponentStockpileCount[ComponentStockpileLookup[ComponentDef.Id]];

                if (Components - decrement <= 0.0f)
                {
                    ComponentStockpile.RemoveAt(ComponentStockpileLookup[ComponentDef.Id]);
                    ComponentStockpileCount.RemoveAt(ComponentStockpileLookup[ComponentDef.Id]);
                    ComponentStockpileLookup.Remove(ComponentDef.Id);

                    return(Components);
                }
                else
                {
                    Components = Components - decrement;
                    ComponentStockpileCount[ComponentStockpileLookup[ComponentDef.Id]] = Components;
                }
            }
            else
            {
                /// <summary>
                /// Invalid remove request sent from somewhere. Error reporting? logs?
                /// </summary>
                return(-1.0f);
            }

            return(decrement);
        }
Beispiel #2
0
        /// <summary>
        /// Add a component to the build queue.
        /// </summary>
        /// <param name="ComponentDef">Component to add.</param>
        /// <param name="BuildAmt">number of components to construct.</param>
        /// <param name="RequestedBuildPercentage">Percent of construction factories, conventional industry, engineering teams to devote to construction.</param>
        public void BuildQueueAddComponent(ComponentDefTN ComponentDef, float BuildAmt, float RequestedBuildPercentage)
        {
            ConstructionBuildQueueItem NewCBQItem = new ConstructionBuildQueueItem(ComponentDef);

            NewCBQItem.UpdateBuildQueueInfo(BuildAmt, RequestedBuildPercentage, true, ComponentDef.cost);

            ConstructionBuildQueue.Add(NewCBQItem);
        }
Beispiel #3
0
        /// <summary>
        /// Constructor for ship components.
        /// </summary>
        /// <param name="ComponentToBuild">Ship Component to build</param>
        public ConstructionBuildQueueItem(ComponentDefTN ComponentToBuild)
        {
            Name           = ComponentToBuild.Name;
            numToBuild     = 0.0f;
            buildCapacity  = 0.0f;
            productionRate = 0.0f;
            costPerItem    = ComponentToBuild.cost;

            m_BuildType      = CBType.ShipComponent;
            m_ComponentBuild = ComponentToBuild;
        }
Beispiel #4
0
 /// <summary>
 /// Add Components to stockpile places increment number of componentDefs into the planetary stockpile.
 /// </summary>
 /// <param name="ComponentDef">Component to be added. This is the class all components inherit from, not any particular type of component.</param>
 /// <param name="increment">Number to add to the stockpile.</param>
 public void AddComponentsToStockpile(ComponentDefTN ComponentDef, float increment)
 {
     if (ComponentStockpileLookup.ContainsKey(ComponentDef.Id) == true)
     {
         ComponentStockpileCount[ComponentStockpileLookup[ComponentDef.Id]] = ComponentStockpileCount[ComponentStockpileLookup[ComponentDef.Id]] + increment;
     }
     else
     {
         ComponentStockpile.Add(ComponentDef);
         ComponentStockpileCount.Add(increment);
         ComponentStockpileLookup.Add(ComponentDef.Id, ComponentStockpile.IndexOf(ComponentDef));
     }
 }
Beispiel #5
0
        /// <summary>
        /// Do all of the tasks that this shipyard has assigned to it.
        /// </summary>
        /// <param name="CurrentFaction">Faction both the population and the shipyard belong to.</param>
        /// <param name="CurrentPopulation">Population the shipyard is on</param>
        /// <param name="SYInfo">Shipyard the tasks are happening at</param>
        private static void BuildShips(Faction CurrentFaction, Population CurrentPopulation, List <Installation.ShipyardInformation.ShipyardTask> SortedList)
        {
            BindingList <Installation.ShipyardInformation.ShipyardTask> TasksToRemove = new BindingList <Installation.ShipyardInformation.ShipyardTask>();

            foreach (Installation.ShipyardInformation.ShipyardTask Task in SortedList)
            {
                if (Task.IsPaused() == true)
                {
                    continue;
                }

                /// <summary>
                /// the Annual Build Rate(ABR) is the number of BP per year that will be devoted to this activity. this is the number of BP produced only this cycle.
                /// </summary>
                float CycleBuildRate = Task.ABR * Constants.Colony.ConstructionCycleFraction;

                /// <summary>
                /// How much of this task will be completed this construction cycle?
                /// </summary>
                float CurrentProgress = CycleBuildRate / (float)Task.Cost;
                if ((Task.Progress + (decimal)CurrentProgress) > 1.0m)
                {
                    CurrentProgress = (float)(1.0m - Task.Progress);
                }

                /// <summary>
                /// Can this shipyard Task be built this construction cycle?
                /// </summary>
                bool CanBuild = CurrentPopulation.MineralRequirement(Task.minerialsCost, CurrentProgress);

                if (CanBuild == true && Task.CurrentTask != Constants.ShipyardInfo.Task.Scrap)
                {
                    CurrentPopulation.HandleShipyardCost(Task.Cost, Task.minerialsCost, CurrentProgress);
                    Task.Progress = Task.Progress + (decimal)CurrentProgress;
                }
                else if (Task.CurrentTask == Constants.ShipyardInfo.Task.Scrap)
                {
                    /// <summary>
                    /// Return money to the population from the scrap.
                    /// </summary>
                    CurrentPopulation.HandleShipyardCost(Task.Cost, Task.minerialsCost, (CurrentProgress * -1.0f));
                    Task.Progress = Task.Progress + (decimal)CurrentProgress;
                }
                else
                {
                    String       Entry = String.Format("Not enough minerals to finish task {0} at Shipyard {1} on Population {2}", Task.CurrentTask, CurrentPopulation.ShipyardTasks[Task], CurrentPopulation);
                    MessageEntry NMsg  = new MessageEntry(MessageEntry.MessageType.ColonyLacksMinerals, CurrentPopulation.Position.System, CurrentPopulation, GameState.Instance.GameDateTime,
                                                          GameState.Instance.LastTimestep, Entry);
                    GameState.Instance.Factions[0].MessageLog.Add(NMsg);
                }


                /// <summary>
                /// handle standard task completion here.
                /// </summary>
                if (Task.Progress >= 1.0m)
                {
                    TasksToRemove.Add(Task);
                    switch (Task.CurrentTask)
                    {
                    case Constants.ShipyardInfo.Task.Construction:
                        Task.AssignedTaskGroup.AddShip(Task.ConstructRefitTarget, Task.Title);
                        CurrentPopulation.FuelStockpile = Task.AssignedTaskGroup.Ships[Task.AssignedTaskGroup.Ships.Count - 1].Refuel(CurrentPopulation.FuelStockpile);
                        break;

                    case Constants.ShipyardInfo.Task.Repair:
                        /// <summary>
                        /// Set the Armor to fully repaired, set all components as not destroyed, and reduce the maintenance clock by a certain amount.
                        /// </summary>
#warning maintenance clock work should be performed here and in refit as well.
                        Task.CurrentShip.ShipArmor.RepairAllArmor();
                        foreach (ComponentTN CurComp in Task.CurrentShip.ShipComponents)
                        {
                            CurComp.isDestroyed = false;
                        }
                        break;

                    case Constants.ShipyardInfo.Task.Refit:
                        /// <summary>
                        /// need to remove the old ship, put in the new ship, copy over important information, adjust refueling,MSP,etc?
                        /// </summary>

                        /// <summary>
                        /// Credit the population with the fuel and ordnance on the ship. the old ships MSP will be considered where the new ship got its MSP from.
                        /// </summary>
                        CurrentPopulation.FuelStockpile = CurrentPopulation.FuelStockpile + Task.CurrentShip.CurrentFuel;
                        foreach (KeyValuePair <OrdnanceDefTN, int> OrdnancePair in Task.CurrentShip.ShipOrdnance)
                        {
                            CurrentPopulation.LoadMissileToStockpile(OrdnancePair.Key, (float)OrdnancePair.Value);
                        }
                        /// <summary>
                        /// Destroy the ship. just use the existing code to remove the ship from the simulation, no point in reduplicating all of it.
                        /// </summary>
                        Task.CurrentShip.IsDestroyed = true;
                        if (CurrentFaction.RechargeList.ContainsKey(Task.CurrentShip) == true)
                        {
                            if ((CurrentFaction.RechargeList[Task.CurrentShip] & (int)Faction.RechargeStatus.Destroyed) != (int)Faction.RechargeStatus.Destroyed)
                            {
                                CurrentFaction.RechargeList[Task.CurrentShip] = CurrentFaction.RechargeList[Task.CurrentShip] + (int)Faction.RechargeStatus.Destroyed;
                            }
                        }
                        else
                        {
                            CurrentFaction.RechargeList.Add(Task.CurrentShip, (int)Faction.RechargeStatus.Destroyed);
                        }

                        /// <summary>
                        /// Add in the "new" ship.
                        /// </summary>
                        Task.AssignedTaskGroup.AddShip(Task.ConstructRefitTarget, Task.CurrentShip.Name);
                        Task.AssignedTaskGroup.Ships[Task.AssignedTaskGroup.Ships.Count - 1].TFTraining = Task.CurrentShip.TFTraining;
                        Task.AssignedTaskGroup.Ships[Task.AssignedTaskGroup.Ships.Count - 1].ShipGrade  = Task.CurrentShip.ShipGrade;
                        CurrentPopulation.FuelStockpile = Task.AssignedTaskGroup.Ships[Task.AssignedTaskGroup.Ships.Count - 1].Refuel(CurrentPopulation.FuelStockpile);
                        break;

                    case Constants.ShipyardInfo.Task.Scrap:
                        /// <summary>
                        /// All non-destroyed components from the ship need to be put into the population stockpile.
                        /// This further includes fuel, MSP, and ordnance as well as eventually officers and crew.
                        /// </summary>
#warning Handle officers and crew on ship scrapping.
                        BindingList <ComponentDefTN> CompDefList       = Task.CurrentShip.ShipClass.ListOfComponentDefs;
                        BindingList <short>          CompDefCount      = Task.CurrentShip.ShipClass.ListOfComponentDefsCount;
                        BindingList <ComponentTN>    ShipCompList      = Task.CurrentShip.ShipComponents;
                        BindingList <ushort>         ComponentDefIndex = Task.CurrentShip.ComponentDefIndex;
                        int DefCount = Task.CurrentShip.ShipClass.ListOfComponentDefs.Count;
                        for (int CompDefIndex = 0; CompDefIndex < DefCount; CompDefIndex++)
                        {
                            ComponentDefTN CurrentCompDef   = CompDefList[CompDefIndex];
                            short          CurrentCompCount = CompDefCount[CompDefIndex];

                            int destCount = 0;
                            for (int CompIndex = 0; CompIndex < CurrentCompCount; CompIndex++)
                            {
                                if (ShipCompList[ComponentDefIndex[CompDefIndex] + CompIndex].isDestroyed == true)
                                {
                                    destCount++;
                                }
                            }

                            if (destCount != CurrentCompCount)
                            {
                                CurrentPopulation.AddComponentsToStockpile(CurrentCompDef, (float)(CurrentCompCount - destCount));
                            }
                        }

                        CurrentPopulation.FuelStockpile       = CurrentPopulation.FuelStockpile + Task.CurrentShip.CurrentFuel;
                        CurrentPopulation.MaintenanceSupplies = CurrentPopulation.MaintenanceSupplies + Task.CurrentShip.CurrentMSP;
                        foreach (KeyValuePair <OrdnanceDefTN, int> OrdnancePair in Task.CurrentShip.ShipOrdnance)
                        {
                            CurrentPopulation.LoadMissileToStockpile(OrdnancePair.Key, (float)OrdnancePair.Value);
                        }

                        /// <summary>
                        /// Finally destroy the ship. just use the existing code to remove the ship from the simulation, no point in reduplicating all of it.
                        /// </summary>
                        Task.CurrentShip.IsDestroyed = true;
                        if (CurrentFaction.RechargeList.ContainsKey(Task.CurrentShip) == true)
                        {
                            if ((CurrentFaction.RechargeList[Task.CurrentShip] & (int)Faction.RechargeStatus.Destroyed) != (int)Faction.RechargeStatus.Destroyed)
                            {
                                CurrentFaction.RechargeList[Task.CurrentShip] = CurrentFaction.RechargeList[Task.CurrentShip] + (int)Faction.RechargeStatus.Destroyed;
                            }
                        }
                        else
                        {
                            CurrentFaction.RechargeList.Add(Task.CurrentShip, (int)Faction.RechargeStatus.Destroyed);
                        }
                        break;
                    }
                }
                else
                {
                    /// <summary>
                    /// Update the timer since this project won't finish just yet.
                    /// </summary>
                    decimal  CostLeft          = Task.Cost * (1.0m - Task.Progress);
                    float    YearsOfProduction = (float)CostLeft / Task.ABR;
                    DateTime EstTime           = GameState.Instance.GameDateTime;
                    if (YearsOfProduction < Constants.Colony.TimerYearMax)
                    {
                        float    DaysInYear  = (float)Constants.TimeInSeconds.RealYear / (float)Constants.TimeInSeconds.Day;
                        int      TimeToBuild = (int)Math.Floor(YearsOfProduction * DaysInYear);
                        TimeSpan TS          = new TimeSpan(TimeToBuild, 0, 0, 0);
                        EstTime = EstTime.Add(TS);
                    }
                    Task.CompletionDate = EstTime;
                }
            }

            /// <summary>
            /// Remove all the tasks that are now completed.
            /// </summary>
            foreach (Installation.ShipyardInformation.ShipyardTask Task in TasksToRemove)
            {
                /// <summary>
                /// Sanity check here.
                /// </summary>
                if (Task.Progress >= 1.0m)
                {
                    Installation.ShipyardInformation SYI = CurrentPopulation.ShipyardTasks[Task];
                    SYI.BuildingShips.Remove(Task);
                    CurrentPopulation.ShipyardTasks.Remove(Task);
                }
            }
            TasksToRemove.Clear();
        }
Beispiel #6
0
 /// <summary>
 /// Constructor for ship components.
 /// </summary>
 /// <param name="ComponentToBuild">Ship Component to build</param>
 public ConstructionBuildQueueItem(ComponentDefTN ComponentToBuild)
 {
     m_BuildType      = CBType.ShipComponent;
     m_ComponentBuild = ComponentToBuild;
 }