コード例 #1
0
 private void SelectBank(int bankid)
 {
     foreach (DesignSectionInfo designSection in this.WorkingDesign.DesignSections)
     {
         foreach (WeaponBankInfo weaponBank in designSection.WeaponBanks)
         {
             if (weaponBank.ID == bankid)
             {
                 this._selectedWeaponBank = weaponBank;
             }
         }
         this._selectedModule = designSection.Modules.First <DesignModuleInfo>((Func <DesignModuleInfo, bool>)(x => x.MountNodeName == this.ModuleBankdict[bankid]));
     }
 }
コード例 #2
0
ファイル: AllShipData.cs プロジェクト: zerk-js/SOTSII-SOS
 public WeaponBankShipData GetCurrentWeaponBank(
     GameDatabase db,
     WeaponBankInfo bankInfo)
 {
     foreach (SectionShipData currentSection in this.GetCurrentSections())
     {
         foreach (WeaponBankShipData weaponBank in currentSection.WeaponBanks)
         {
             if (bankInfo.BankGUID == weaponBank.Bank.GUID)
             {
                 return(weaponBank);
             }
         }
     }
     return((WeaponBankShipData)null);
 }
コード例 #3
0
        public static void Simulate(GameSession game, int systemId, List <FleetInfo> fleets)
        {
            if (ScriptHost.AllowConsole)
            {
                App.Log.Trace(string.Format("Simulating AI combat at: {0}", (object)systemId), "combat");
            }
            List <PlanetCombatInfo> planets = new List <PlanetCombatInfo>();

            PlanetInfo[] systemPlanetInfos = game.GameDatabase.GetStarSystemPlanetInfos(systemId);
            if (systemPlanetInfos != null)
            {
                foreach (PlanetInfo planetInfo in systemPlanetInfos)
                {
                    planets.Add(new PlanetCombatInfo()
                    {
                        planetInfo = planetInfo,
                        colonyInfo = game.GameDatabase.GetColonyInfoForPlanet(planetInfo.ID)
                    });
                }
            }
            Dictionary <FleetInfo, List <ShipCombatInfo> > shipCombatInfo = new Dictionary <FleetInfo, List <ShipCombatInfo> >();

            foreach (FleetInfo fleet in fleets)
            {
                List <ShipCombatInfo> shipCombatInfoList = new List <ShipCombatInfo>();
                foreach (ShipInfo shipInfo in game.GameDatabase.GetShipInfoByFleetID(fleet.ID, true).ToList <ShipInfo>())
                {
                    if (shipInfo.DesignInfo.Class != ShipClass.BattleRider)
                    {
                        ShipCombatInfo sci = new ShipCombatInfo();
                        sci.shipInfo = shipInfo;
                        float num = 1f;
                        if (shipInfo.DesignInfo.Class == ShipClass.Cruiser || shipInfo.DesignInfo.Class == ShipClass.Dreadnought)
                        {
                            num = 3f;
                        }
                        sci.armorFactor     = (float)shipInfo.DesignInfo.Armour / num;
                        sci.structureFactor = shipInfo.DesignInfo.Structure / num;
                        foreach (DesignSectionInfo designSection in shipInfo.DesignInfo.DesignSections)
                        {
                            ShipSectionAsset shipSectionAsset = game.AssetDatabase.GetShipSectionAsset(designSection.FilePath);
                            foreach (WeaponBankInfo weaponBank in designSection.WeaponBanks)
                            {
                                WeaponBankInfo wbi = weaponBank;
                                if (wbi.WeaponID.HasValue)
                                {
                                    string              weaponName = Path.GetFileNameWithoutExtension(game.GameDatabase.GetWeaponAsset(wbi.WeaponID.Value));
                                    LogicalWeapon       lw         = game.AssetDatabase.Weapons.FirstOrDefault <LogicalWeapon>((Func <LogicalWeapon, bool>)(weapon => string.Equals(weapon.WeaponName, weaponName, StringComparison.InvariantCultureIgnoreCase)));
                                    List <LogicalMount> list       = ((IEnumerable <LogicalMount>)shipSectionAsset.Mounts).Where <LogicalMount>((Func <LogicalMount, bool>)(x => x.Bank.GUID == wbi.BankGUID)).ToList <LogicalMount>();
                                    int totalMounts = list.Count <LogicalMount>() <= 0 ? 1 : list.Count <LogicalMount>();
                                    foreach (LogicalMount logicalMount in list)
                                    {
                                        switch (logicalMount.Bank.TurretClass)
                                        {
                                        case WeaponEnums.TurretClasses.Drone:
                                            ++sci.drones;
                                            continue;

                                        case WeaponEnums.TurretClasses.DestroyerRider:
                                        case WeaponEnums.TurretClasses.CruiserRider:
                                        case WeaponEnums.TurretClasses.DreadnoughtRider:
                                            ++sci.battleRiders;
                                            continue;

                                        default:
                                            CombatSimulator.ApplyWeaponStats(sci, lw, totalMounts);
                                            continue;
                                        }
                                    }
                                }
                            }
                            foreach (DesignModuleInfo module in designSection.Modules)
                            {
                                DesignModuleInfo mod           = module;
                                LogicalModule    logicalModule = game.AssetDatabase.Modules.First <LogicalModule>((Func <LogicalModule, bool>)(x => x.ModulePath == game.GameDatabase.GetModuleAsset(mod.ModuleID)));
                                if (logicalModule != null && mod.WeaponID.HasValue)
                                {
                                    foreach (LogicalBank bank in logicalModule.Banks)
                                    {
                                        LogicalBank         lb          = bank;
                                        string              weaponName2 = Path.GetFileNameWithoutExtension(game.GameDatabase.GetWeaponAsset(mod.WeaponID.Value));
                                        LogicalWeapon       lw          = game.AssetDatabase.Weapons.FirstOrDefault <LogicalWeapon>((Func <LogicalWeapon, bool>)(weapon => string.Equals(weapon.WeaponName, weaponName2, StringComparison.InvariantCultureIgnoreCase)));
                                        List <LogicalMount> list        = ((IEnumerable <LogicalMount>)shipSectionAsset.Mounts).Where <LogicalMount>((Func <LogicalMount, bool>)(x => x.Bank.GUID == lb.GUID)).ToList <LogicalMount>();
                                        int totalMounts = list.Count <LogicalMount>() <= 0 ? 1 : list.Count <LogicalMount>();
                                        foreach (LogicalMount logicalMount in list)
                                        {
                                            CombatSimulator.ApplyWeaponStats(sci, lw, totalMounts);
                                        }
                                    }
                                }
                            }
                        }
                        shipCombatInfoList.Add(sci);
                    }
                }
                shipCombatInfo.Add(fleet, shipCombatInfoList);
            }
            if (fleets.Count <FleetInfo>() > 1)
            {
                CombatSimulator.TrackingPhase(shipCombatInfo, 4f);
                CombatSimulator.DirectPhase(shipCombatInfo, 4f);
                CombatSimulator.TrackingPhase(shipCombatInfo, 1f);
                CombatSimulator.DirectPhase(shipCombatInfo, 2f);
                CombatSimulator.BombardmentPhase(game.GameDatabase, shipCombatInfo, planets, 1f);
            }
            else
            {
                CombatSimulator.BombardmentPhase(game.GameDatabase, shipCombatInfo, planets, 2f);
            }
            CombatSimulator.CompleteSimulation(game, systemId, shipCombatInfo, planets);
        }
コード例 #4
0
        public static CreateShipDummyParams ObtainShipDummyParams(
            App game,
            ShipInfo shipInfo)
        {
            IEnumerable <string>    modules              = game.AssetDatabase.Modules.Select <LogicalModule, string>((Func <LogicalModule, string>)(x => x.ModuleName));
            IEnumerable <string>    weapons              = game.AssetDatabase.Weapons.Select <LogicalWeapon, string>((Func <LogicalWeapon, string>)(x => x.Name));
            DesignInfo              designInfo           = shipInfo.DesignInfo;
            List <ShipSectionAsset> shipSectionAssetList = new List <ShipSectionAsset>();
            List <ModuleAssignment> moduleAssignmentList = new List <ModuleAssignment>();
            List <WeaponAssignment> weaponAssignmentList = new List <WeaponAssignment>();

            foreach (DesignSectionInfo designSection in designInfo.DesignSections)
            {
                DesignSectionInfo sectionInfo      = designSection;
                ShipSectionAsset  shipSectionAsset = game.AssetDatabase.ShipSections.First <ShipSectionAsset>((Func <ShipSectionAsset, bool>)(x => x.FileName == sectionInfo.FilePath));
                shipSectionAssetList.Add(shipSectionAsset);
                foreach (LogicalBank bank1 in shipSectionAsset.Banks)
                {
                    LogicalBank    bank           = bank1;
                    WeaponBankInfo weaponBankInfo = sectionInfo.WeaponBanks.FirstOrDefault <WeaponBankInfo>((Func <WeaponBankInfo, bool>)(x => x.BankGUID == bank.GUID));
                    bool           flag           = false;
                    if (weaponBankInfo != null && weaponBankInfo.WeaponID.HasValue)
                    {
                        string           weaponName       = Path.GetFileNameWithoutExtension(game.GameDatabase.GetWeaponAsset(weaponBankInfo.WeaponID.Value));
                        WeaponAssignment weaponAssignment = new WeaponAssignment()
                        {
                            ModuleNode          = "",
                            Bank                = bank,
                            Weapon              = game.AssetDatabase.Weapons.First <LogicalWeapon>((Func <LogicalWeapon, bool>)(weapon => string.Equals(weapon.WeaponName, weaponName, StringComparison.InvariantCultureIgnoreCase))),
                            DesignID            = weaponBankInfo == null || !weaponBankInfo.DesignID.HasValue ? 0 : weaponBankInfo.DesignID.Value,
                            InitialTargetFilter = new int?(weaponBankInfo.FilterMode ?? 0),
                            InitialFireMode     = new int?(weaponBankInfo.FiringMode ?? 0)
                        };
                        weaponAssignmentList.Add(weaponAssignment);
                        flag = true;
                    }
                    if (!flag && !string.IsNullOrEmpty(bank.DefaultWeaponName))
                    {
                        WeaponAssignment weaponAssignment = new WeaponAssignment()
                        {
                            ModuleNode = "",
                            Bank       = bank,
                            Weapon     = game.AssetDatabase.Weapons.First <LogicalWeapon>((Func <LogicalWeapon, bool>)(weapon => string.Equals(weapon.WeaponName, bank.DefaultWeaponName, StringComparison.InvariantCultureIgnoreCase))),
                            DesignID   = weaponBankInfo == null || !weaponBankInfo.DesignID.HasValue ? 0 : weaponBankInfo.DesignID.Value
                        };
                        weaponAssignmentList.Add(weaponAssignment);
                    }
                }
                foreach (LogicalModuleMount module in shipSectionAsset.Modules)
                {
                    LogicalModuleMount sectionModule    = module;
                    DesignModuleInfo   designModuleInfo = sectionInfo.Modules.FirstOrDefault <DesignModuleInfo>((Func <DesignModuleInfo, bool>)(x => x.MountNodeName == sectionModule.NodeName));
                    if (designModuleInfo != null)
                    {
                        string        path          = game.GameDatabase.GetModuleAsset(designModuleInfo.ModuleID);
                        LogicalModule logicalModule = game.AssetDatabase.Modules.FirstOrDefault <LogicalModule>((Func <LogicalModule, bool>)(x => x.ModulePath == path));
                        moduleAssignmentList.Add(new ModuleAssignment()
                        {
                            ModuleMount = sectionModule,
                            Module      = logicalModule
                        });
                        if (designModuleInfo.WeaponID.HasValue)
                        {
                            string           weaponPath       = game.GameDatabase.GetWeaponAsset(designModuleInfo.WeaponID.Value);
                            WeaponAssignment weaponAssignment = new WeaponAssignment()
                            {
                                ModuleNode = designModuleInfo.MountNodeName,
                                Bank       = logicalModule.Banks[0],
                                Weapon     = game.AssetDatabase.Weapons.First <LogicalWeapon>((Func <LogicalWeapon, bool>)(x => x.FileName == weaponPath)),
                                DesignID   = 0
                            };
                            weaponAssignmentList.Add(weaponAssignment);
                        }
                    }
                }
            }
            ShipSectionAsset missionSection = shipSectionAssetList.FirstOrDefault <ShipSectionAsset>((Func <ShipSectionAsset, bool>)(x => x.Type == ShipSectionType.Mission));
            Faction          faction        = game.AssetDatabase.Factions.First <Faction>((Func <Faction, bool>)(x => missionSection.Faction == x.Name));
            Player           playerObject   = game.Game.GetPlayerObject(designInfo.PlayerID);
            Subfaction       subfaction     = faction.Subfactions[Math.Min(playerObject.SubfactionIndex, faction.Subfactions.Length - 1)];

            return(new CreateShipDummyParams()
            {
                ShipID = shipInfo.ID,
                PreferredMount = Ship.GetPreferredMount(game, playerObject, faction, shipSectionAssetList),
                ShipFaction = faction,
                Sections = (IEnumerable <ShipSectionAsset>)shipSectionAssetList.ToArray(),
                AssignedModules = (IEnumerable <ModuleAssignment>)moduleAssignmentList.ToArray(),
                PreferredModules = game.AssetDatabase.Modules.Where <LogicalModule>((Func <LogicalModule, bool>)(x => modules.Contains <string>(x.ModuleName))),
                AssignedWeapons = (IEnumerable <WeaponAssignment>)weaponAssignmentList.ToArray(),
                PreferredWeapons = game.AssetDatabase.Weapons.Where <LogicalWeapon>((Func <LogicalWeapon, bool>)(x => weapons.Contains <string>(x.Name)))
            });
        }