Example #1
0
        // ==============================================================================================================


        // ==============================================================================================================
        #region "conversions"
        public string GetShipName(int ShipTypeID)
        {
            if (ShipTypeID >= 0)
            {
                int  Index = -1;
                bool Ok    = ShipTypeIDToIndex.TryGetValue(ShipTypeID, out Index);
                Debug.Assert(Index >= 0 && Index < ShipDescriptions.Count);
                return(ShipDescriptions[Index].m_Name);
            }
            else
            {
                return("unknown");
            }
        }
Example #2
0
        // ==============================================================================================================

        private void DoAddMoreModules(IReadOnlyCollection <int> ModuleTypeIDs)
        {
            Dictionary <int,uint> NewModules = new Dictionary <int,uint>();

            foreach (int ModuleTypeID in ModuleTypeIDs)
            {
                if (NewModules.ContainsKey(ModuleTypeID))
                {
                    NewModules[ModuleTypeID]++;
                }
                else
                {
                    NewModules[ModuleTypeID] = 1;
                }
            }
            foreach (KeyValuePair <int,uint> kvp in NewModules)
            {
                int  ModuleTypeID = kvp.Key;
                uint ModuleCount  = kvp.Value;
                int  Index        = -1;
                bool Ok           = ModuleTypeIDToIndex.TryGetValue(ModuleTypeID,out Index);
                Debug.Assert(Ok && Index >= 0);
                ModuleDescription MD = ModuleDescriptions[Index];
                if (m_Fit[MD.m_Slot].ContainsKey(ModuleTypeID))
                {
                    m_Fit[MD.m_Slot][ModuleTypeID] = Math.Max(m_Fit[MD.m_Slot][ModuleTypeID],ModuleCount);
                }
                else
                {
                    m_Fit[MD.m_Slot][ModuleTypeID] = ModuleCount;
                }
            }

            if (m_ShipTypeID > 0)
            {
                int Index = -1;
                if (ShipTypeIDToIndex.TryGetValue(ShipTypeID,out Index))
                {
                    ShipDescription SD = ShipDescriptions[Index];
                    // recalc slot layout for t3 cruisers
                    RecalcStategicCruiserSlotLayout(SD);
                }
            }
        }
Example #3
0
        private void SetShipTypeID(int ShipTypeID)
        {
            int Index = -1;

            if (ShipTypeIDToIndex.TryGetValue(ShipTypeID,out Index))
            {
                Debug.Assert(Index >= 0);
                m_ShipTypeID = ShipTypeID;
                ShipDescription SD = ShipDescriptions[Index];
                m_Slots[SLOT.HIGH]   = SD.m_HighSlots;
                m_Slots[SLOT.MEDIUM] = SD.m_MedSlots;
                m_Slots[SLOT.LOW]    = SD.m_LowSlots;
                m_Slots[SLOT.RIG]    = SD.m_RigSlots;
                if (SD.m_SubsystemSlots > 0)
                {
                    Debug.Assert(SD.m_SubsystemSlots == 4);
                    m_Slots[SLOT.SUB_CORE]       = 1;
                    m_Slots[SLOT.SUB_DEFENSIVE]  = 1;
                    m_Slots[SLOT.SUB_OFFENSIVE]  = 1;
                    m_Slots[SLOT.SUB_PROPULSION] = 1;
                }
                else
                {
                    m_Slots[SLOT.SUB_CORE]       = 0;
                    m_Slots[SLOT.SUB_DEFENSIVE]  = 0;
                    m_Slots[SLOT.SUB_OFFENSIVE]  = 0;
                    m_Slots[SLOT.SUB_PROPULSION] = 0;
                }
                RecalcStategicCruiserSlotLayout(SD);
            }
            else
            {
                m_ShipTypeID                 = -1;
                m_Slots[SLOT.HIGH]           = 8;
                m_Slots[SLOT.MEDIUM]         = 8;
                m_Slots[SLOT.LOW]            = 8;
                m_Slots[SLOT.RIG]            = 3;
                m_Slots[SLOT.SUB_CORE]       = 1;
                m_Slots[SLOT.SUB_DEFENSIVE]  = 1;
                m_Slots[SLOT.SUB_OFFENSIVE]  = 1;
                m_Slots[SLOT.SUB_PROPULSION] = 1;
            }
        }
        // ==============================================================================================================

        private void RecalculateTank()
        {
            if (!m_ValidFit || m_ShipTypeID < 0)
            {
                TankForInvalidFit();
            }
            else
            {
                int  ShipIndex = -1;
                bool Ok        = ShipTypeIDToIndex.TryGetValue(m_ShipTypeID, out ShipIndex);
                Debug.Assert(Ok && ShipIndex >= 0 && ShipIndex < ShipDescriptions.Count);
                ShipDescription SD = ShipDescriptions[ShipIndex];

                Dictionary <int, uint> AllModuleIDs = new Dictionary <int, uint>();
                foreach (SLOT Slot in Enum.GetValues(typeof(SLOT)))
                {
                    foreach (KeyValuePair <int,uint> ModuleAndCount in m_Fit[Slot])
                    {
                        AllModuleIDs[ModuleAndCount.Key] = ModuleAndCount.Value;
                    }
                }
                bool isPolarized = false;
                List <Tuple <ModuleDescription,uint> > AllModules = new List <Tuple <ModuleDescription,uint> >();
                foreach (KeyValuePair <int,uint> kvp in AllModuleIDs)
                {
                    int Index = -1;
                    Ok = ModuleTypeIDToIndex.TryGetValue(kvp.Key,out Index);
                    Debug.Assert(Ok);
                    isPolarized |= IsPolarized(ModuleDescriptions[Index]);
                    AllModules.Add(new Tuple <ModuleDescription,uint>(ModuleDescriptions[Index],kvp.Value));
                }

                m_Tank[LAYER.SHIELD] = GetLayerTank(SD.m_ShieldHP,SD.m_ShieldHPMultiplier,SD.m_ShieldResistEM,SD.m_ShieldResistThermal,SD.m_ShieldResistKinetic,SD.m_ShieldResistExplosive,isPolarized,LAYER.SHIELD,AllModules,SD.m_OverheatingBonus);
                m_Tank[LAYER.ARMOR]  = GetLayerTank(SD.m_ArmorHP,SD.m_ArmorHPMultiplier,SD.m_ArmorResistEM,SD.m_ArmorResistThermal,SD.m_ArmorResistKinetic,SD.m_ArmorResistExplosive,isPolarized,LAYER.ARMOR,AllModules,SD.m_OverheatingBonus);
                m_Tank[LAYER.HULL]   = GetLayerTank(SD.m_HullHP,SD.m_HullHPMultiplier,SD.m_HullResistEM,SD.m_HullResistThermal,SD.m_HullResistKinetic,SD.m_HullResistExplosive,isPolarized,LAYER.HULL,AllModules,SD.m_OverheatingBonus);
            }

            EventTankChanged();
        }
Example #5
0
        private void CheckFitValid()
        {
            m_ValidFit = true;
            foreach (SLOT Slot in Enum.GetValues(typeof(SLOT)))
            {
                Debug.Assert(m_Fit.ContainsKey(Slot));
                uint ModuleCount = 0;
                foreach (KeyValuePair <int,uint> M in m_Fit[Slot])
                {
                    ModuleCount += M.Value;
                }
                if (ModuleCount > m_Slots[Slot])
                {
                    m_ValidFit = false;
                    break;
                }
            }
            if (m_ValidFit)
            {
                if (m_ShipTypeID > 0)
                {
                    int Index = -1;
                    if (ShipTypeIDToIndex.TryGetValue(ShipTypeID,out Index))
                    {
                        ShipDescription SD = ShipDescriptions[Index];
                        if (SD.m_SubsystemSlots > 0)
                        {
                            foreach (SLOT Slot in new SLOT[] { SLOT.SUB_CORE,SLOT.SUB_DEFENSIVE,SLOT.SUB_OFFENSIVE,SLOT.SUB_PROPULSION })
                            {
                                if (m_Fit[Slot].Count > 1)
                                {
                                    m_ValidFit = false;
                                    break;
                                }
                                #region Check that all 4 subsystems are filled. Not required anymore, coz we can have partial t3c fits.
                                //if (m_Fit[Slot].Count != 1) {
                                //    m_ValidFit = false;
                                //    break;
                                //}
                                #endregion

                                // Check that subsystems belong to current t3 hull.
                                foreach (KeyValuePair <int,uint> kvp in m_Fit[Slot])
                                {
                                    Index = -1;
                                    if (!ModuleTypeIDToIndex.TryGetValue(kvp.Key,out Index) || Index < 0)
                                    {
                                        m_ValidFit = false;
                                        break;
                                    }
                                    ModuleDescription md = ModuleDescriptions[Index];
                                    if (md.m_ShipTypeID < 0 || md.m_ShipTypeID != m_ShipTypeID)
                                    {
                                        m_ValidFit = false;
                                        break;
                                    }

                                    if (kvp.Value != 1)
                                    {
                                        m_ValidFit = false;
                                        break;
                                    }

                                    break;
                                }
                            }
                        }
                    }
                }
            }
            CheckFullFit();
        }