예제 #1
0
        private void BindVehicles(IMobileSpaceObject selected = null)
        {
            var vehicles = new HashSet <IVehicle>();

            // find vehicles in sector that are not fleets
            foreach (var v in sector.SpaceObjects.OfType <SpaceVehicle>().OwnedBy(Empire.Current))
            {
                vehicles.Add(v);
            }

            // add vehicles that are being removed from fleets (but not fleets themselves, those go in the fleets tree)
            foreach (var v in newCommands.OfType <LeaveFleetCommand>().Select(c => c.Executor).OfType <SpaceVehicle>())
            {
                vehicles.Add(v);
            }
            foreach (var v in newCommands.OfType <DisbandFleetCommand>().SelectMany(c => c.Executor.Vehicles.OfType <SpaceVehicle>()))
            {
                vehicles.Add(v);
            }

            // remove vehicles that are being added to fleets
            foreach (var v in newCommands.OfType <JoinFleetCommand>().Select(c => c.Executor).OfType <SpaceVehicle>())
            {
                vehicles.Remove(v);
            }

            // make a tree of vehicles
            treeVehicles.Initialize(32);
            foreach (var vtGroup in vehicles.GroupBy(v => v.Design.VehicleType))
            {
                var vtNode = treeVehicles.AddItemWithImage(vtGroup.Key.ToSpacedString(), vtGroup.Key, Pictures.GetVehicleTypeImage(Empire.Current.ShipsetPath, vtGroup.Key));
                foreach (var roleGroup in vtGroup.GroupBy(v => v.Design.Role))
                {
                    var roleNode = vtNode.AddItemWithImage(roleGroup.Key, roleGroup.Key, Pictures.GetVehicleTypeImage(Empire.Current.ShipsetPath, vtGroup.Key));
                    foreach (var designGroup in roleGroup.GroupBy(v => v.Design))
                    {
                        var designNode = roleNode.AddItemWithImage(designGroup.Key.Name, designGroup.Key, designGroup.Key.Icon);
                        foreach (var vehicle in designGroup)
                        {
                            TreeNode vehicleNode;
                            if (vehicle is IMobileSpaceObject sobj)                             // yay pattern matching! :D
                            {
                                vehicleNode = designNode.AddItemWithImage(vehicle.Name + ": " + CalculateStatus(sobj), vehicle, vehicle.Icon);
                            }
                            else
                            {
                                vehicleNode = designNode.AddItemWithImage(vehicle.Name, vehicle, vehicle.Icon);
                            }
                            if (vehicle == selected)
                            {
                                treeVehicles.SelectedNode = vehicleNode;
                            }
                        }
                    }
                }
                if (vtNode.Nodes.Count == 0)
                {
                    vtNode.Remove();
                }
            }

            // expand the treeeee!
            treeVehicles.ExpandAll();
        }
예제 #2
0
파일: Cargolist.cs 프로젝트: ekolis/FrEee
        public void Bind()
        {
            tree.Initialize(32);
            var unitTypes = new List <VehicleTypes> {
                VehicleTypes.Drone, VehicleTypes.Fighter, VehicleTypes.Mine, VehicleTypes.Satellite, VehicleTypes.Troop, VehicleTypes.WeaponPlatform
            };

            if (CargoContainer != null)
            {
                var      cargo = CargoContainer.Cargo;
                var      used  = cargo.Size;
                var      total = CargoContainer.CargoStorage;
                var      free  = used - total;
                TreeNode typesNode;
                if (ShowAllUnitsAndPopulationAlways)
                {
                    typesNode = tree.AddItemWithImage("Units - Types", "Types", Pictures.GetVehicleTypeImage(Empire.Current.ShipsetPath));
                    foreach (var vt in unitTypes)
                    {
                        typesNode.AddItemWithImage($"All {vt}s", vt, Pictures.GetVehicleTypeImage(Empire.Current.ShipsetPath, vt));
                    }
                    typesNode.Expand();
                }
                if (CargoContainer.AllUnits.Any())
                {
                    if (!ShowAllUnitsAndPopulationAlways)
                    {
                        typesNode = tree.AddItemWithImage("Units - Types", "Types", Pictures.GetVehicleTypeImage(Empire.Current.ShipsetPath));
                        foreach (var ug in CargoContainer.AllUnits.GroupBy(u => u.Design.VehicleType))
                        {
                            typesNode.AddItemWithImage($"All {ug.Key}s", ug.Key, Pictures.GetVehicleTypeImage(Empire.Current.ShipsetPath, ug.Key));
                        }
                        typesNode.Expand();
                    }
                    foreach (var ug in CargoContainer.AllUnits.GroupBy(u => u.Design.VehicleType))
                    {
                        var typeNode = tree.GetAllNodes().First(x => x.Tag.ToString() == ug.Key.ToString());
                        foreach (var ug2 in ug.GroupBy(u => u.Design))
                        {
                            var designNode = typeNode.AddItemWithImage(ug.Count() + "x \"" + ug2.Key.Name + "\" " + ug2.Key.VehicleTypeName + " (" + ug2.Key.Hull.Size.Kilotons() + " each)", ug.Key, ug.First().Icon);
                            foreach (var u in ug2)
                            {
                                designNode.AddItemWithImage(u.Name, u, u.Icon);
                            }
                        }
                    }
                    var rolesNode = tree.AddItemWithImage("Units - Roles", "Roles", Pictures.GetVehicleTypeImage(Empire.Current.ShipsetPath));
                    foreach (var ug in CargoContainer.AllUnits.GroupBy(u => u.Design.Role))
                    {
                        rolesNode.AddItemWithImage(ug.Count() + "x " + ug.Key, ug.Key, ug.First().Icon);
                    }
                    rolesNode.Expand();
                }
                TreeNode popNode = null;
                if (ShowAllUnitsAndPopulationAlways)
                {
                    popNode = tree.AddItemWithImage(CargoContainer.AllPopulation.Sum(kvp => kvp.Value).ToUnitString(true) + " Total Population (" + ((long)(Mod.Current.Settings.PopulationSize * Mod.Current.Settings.PopulationFactor)).Kilotons() + " per " + Mod.Current.Settings.PopulationFactor.ToUnitString(true) + ")", "Population", Empire.Current.PrimaryRace.Icon);
                }
                if (CargoContainer.AllPopulation.Any())
                {
                    if (popNode == null)
                    {
                        popNode = tree.AddItemWithImage(CargoContainer.AllPopulation.Sum(kvp => kvp.Value).ToUnitString(true) + " Total Population (" + ((long)(Mod.Current.Settings.PopulationSize * Mod.Current.Settings.PopulationFactor)).Kilotons() + " per " + Mod.Current.Settings.PopulationFactor.ToUnitString(true) + ")", "Population", Empire.Current.PrimaryRace.Icon);
                    }
                    foreach (var pop in CargoContainer.AllPopulation)
                    {
                        popNode.AddItemWithImage(pop.Value.ToUnitString(true) + " " + pop.Key + " Population", pop.Key, pop.Key.Icon);
                    }
                    popNode.Expand();
                }

                lblTonnage.Text = "Cargo Storage Free: " + CargoContainer.CargoStorageFree().Kilotons() + "\n" + "Population Storage Free: " + CargoContainer.PopulationStorageFree.ToUnitString(true);
            }
            else if (CargoDelta != null)
            {
                TreeNode typesNode;
                if (ShowAllUnitsAndPopulationAlways)
                {
                    typesNode = tree.AddItemWithImage("Units - Types", "Types", Pictures.GetVehicleTypeImage(Empire.Current.ShipsetPath));
                    foreach (var vt in unitTypes)
                    {
                        typesNode.AddItemWithImage($"All {vt}s", vt, Pictures.GetVehicleTypeImage(Empire.Current.ShipsetPath, vt));
                    }
                    typesNode.Expand();
                }
                else
                {
                    if (CargoDelta.UnitTypeTonnage.Any())
                    {
                        typesNode = tree.AddItemWithImage("Units - Types", "Types", Pictures.GetVehicleTypeImage(Empire.Current.ShipsetPath));
                        foreach (var ug in CargoDelta.UnitTypeTonnage)
                        {
                            typesNode.AddItemWithImage(ug.Value.Kilotons("All") + " " + ug.Key.ToSpacedString() + "s", ug.Key, Pictures.GetVehicleTypeImage(Empire.Current.ShipsetPath, ug.Key));
                        }
                        typesNode.Expand();
                    }
                }

                if (CargoDelta.UnitRoleTonnage.Any())
                {
                    var rolesNode = tree.AddItemWithImage("Units - Roles", "Roles", Pictures.GetVehicleTypeImage(Empire.Current.ShipsetPath));
                    foreach (var ug in CargoDelta.UnitRoleTonnage)
                    {
                        rolesNode.AddItemWithImage(ug.Value.Kilotons("All") + " " + ug.Key + "s", ug.Key, Pictures.GetVehicleTypeImage(Empire.Current.ShipsetPath));
                    }
                    rolesNode.Expand();
                }
                if (CargoDelta.UnitDesignTonnage.Any())
                {
                    var designsNode = tree.AddItemWithImage("Units - Designs", "Designs", Pictures.GetVehicleTypeImage(Empire.Current.ShipsetPath));
                    foreach (var ug in CargoDelta.UnitDesignTonnage)
                    {
                        designsNode.AddItemWithImage(ug.Value.Kilotons("All") + " \"" + ug.Key.Name + "\" " + ug.Key.VehicleType + "s + (" + ug.Key.Hull.Size.Kilotons() + " each)", ug.Key, ug.Key.Icon);
                    }
                    designsNode.Expand();
                }
                if (CargoDelta.Units.Any())
                {
                    var unitsNode = tree.AddItemWithImage("Units - Individual (" + CargoDelta.Units.Count + ")", "Units", Pictures.GetVehicleTypeImage(Empire.Current.ShipsetPath));
                    foreach (var u in CargoDelta.Units)
                    {
                        unitsNode.AddItemWithImage(u.Name, u, u.Icon);
                    }
                    // don't expand the units node, there's probably tons of stuff there!
                }
                TreeNode popNode = null;
                if (ShowAllUnitsAndPopulationAlways || CargoDelta.AllPopulation)
                {
                    popNode = tree.AddItemWithImage("All Population (" + ((long)(Mod.Current.Settings.PopulationSize * Mod.Current.Settings.PopulationFactor)).Kilotons() + " per " + Mod.Current.Settings.PopulationFactor.ToUnitString(true) + ")", "Population", Empire.Current.PrimaryRace.Icon);
                    popNode.Expand();
                }
                if (CargoDelta.RacePopulation.Any() || CargoDelta.AnyPopulation != 0)
                {
                    if (popNode == null)
                    {
                        popNode = tree.AddItemWithImage("All Population (" + ((long)(Mod.Current.Settings.PopulationSize * Mod.Current.Settings.PopulationFactor)).Kilotons() + " per " + Mod.Current.Settings.PopulationFactor.ToUnitString(true) + ")", "Population", Empire.Current.PrimaryRace.Icon);
                    }
                    foreach (var pop in CargoDelta.RacePopulation)
                    {
                        popNode.AddItemWithImage(pop.Value.ToUnitString(true, 4, "All") + " " + pop.Key + " Population (" + ((long)(Mod.Current.Settings.PopulationSize * Mod.Current.Settings.PopulationFactor)).Kilotons() + " per " + Mod.Current.Settings.PopulationFactor.ToUnitString(true) + ")", pop.Key, pop.Key.Icon);
                    }
                    if (CargoDelta.AnyPopulation != 0)
                    {
                        popNode.AddItemWithImage(CargoDelta.AnyPopulation.ToUnitString(true, 4) + " Population of Any Race (" + ((long)(Mod.Current.Settings.PopulationSize * Mod.Current.Settings.PopulationFactor)).Kilotons() + " per " + Mod.Current.Settings.PopulationFactor.ToUnitString(true) + ")", "Total", Pictures.GetGenericImage(typeof(Race)));
                    }
                    popNode.Expand();
                }

                // TODO - estimate tonnage based on available cargo, but we'd need the cargo transfer target for that...
                lblTonnage.Text = "Estimated Tonnage: " + CargoDelta.EstimatedTonnage.Kilotons("Unknown");
            }
        }
예제 #3
0
        private void PopulateSomeoneHas(Empire emp, TreeView tree, Package package)
        {
            tree.Initialize(32);

            // treaty clauses
            var treatyNode = tree.AddItemWithImage("Treaty Clauses", "Treaty Clauses", emp.Icon);

            if (!package.TreatyClauses.OfType <AllianceClause>().Any())
            {
                var allianceNode = treatyNode.AddItemWithImage("Alliances", "Alliances", emp.Icon);
                foreach (AllianceLevel alliance in Enum.GetValues(typeof(AllianceLevel)))
                {
                    if (alliance != AllianceLevel.None)
                    {
                        var clause = new AllianceClause(package.Owner, package.Recipient, alliance);
                        allianceNode.AddItemWithImage(clause.BriefDescription, clause, null);
                    }
                }
            }
            if (!package.TreatyClauses.OfType <CooperativeResearchClause>().Any())
            {
                var clause = new CooperativeResearchClause(package.Owner, package.Recipient);
                treatyNode.AddItemWithImage(clause.BriefDescription, clause, null);
            }
            var freeTradeNode = treatyNode.AddItemWithImage("Free Trade", "Free Trade", Resource.Minerals.Icon);

            foreach (var res in Resource.All.Where(res => res.IsGlobal && !package.TreatyClauses.OfType <FreeTradeClause>().Any(c => c.Resource == res)))
            {
                var clause = new FreeTradeClause(package.Owner, package.Recipient, res);
                freeTradeNode.AddItemWithImage(res.Name, clause, res.Icon);
            }
            var abilNode = treatyNode.AddItemWithImage("Ability Sharing", "Ability Sharing", null);

            foreach (var abil in Mod.Current.AbilityRules.Where(abil =>
                                                                (abil.CanTarget(AbilityTargets.Sector) || abil.CanTarget(AbilityTargets.StarSystem) || abil.CanTarget(AbilityTargets.Galaxy)) &&
                                                                !package.TreatyClauses.OfType <ShareAbilityClause>().Any(c => c.AbilityRule == abil)))
            {
                var clause = new ShareAbilityClause(package.Owner, package.Recipient, abil, SharingPriority.Medium);
                abilNode.AddItemWithImage(abil.Name, clause, null);
            }
            if (!package.TreatyClauses.OfType <ShareCombatLogsClause>().Any())
            {
                var clause = new ShareCombatLogsClause(package.Owner, package.Recipient);
                treatyNode.AddItemWithImage(clause.BriefDescription, clause, null);
            }
            if (!package.TreatyClauses.OfType <ShareDesignsClause>().Any())
            {
                var clause = new ShareDesignsClause(package.Owner, package.Recipient);
                treatyNode.AddItemWithImage(clause.BriefDescription, clause, null);
            }
            if (!package.TreatyClauses.OfType <ShareVisionClause>().Any())
            {
                var clause = new ShareVisionClause(package.Owner, package.Recipient);
                treatyNode.AddItemWithImage(clause.BriefDescription, clause, null);
            }
            var tributeNode = treatyNode.AddItemWithImage("Tribute", "Tribute", Resource.Minerals.Icon);

            foreach (var res in Resource.All.Where(res => res.IsGlobal && !package.TreatyClauses.OfType <FreeTradeClause>().Any(c => c.Resource == res)))
            {
                var clause = new TributeClause(package.Owner, package.Recipient, res, 10, true);
                tributeNode.AddItemWithImage(res.Name, clause, res.Icon);
            }

            // sort planets alphabetically
            var planetsNode = tree.AddItemWithImage("Planets", "Planets", Pictures.GetGenericImage(typeof(Planet)));

            foreach (var p in emp.ColonizedPlanets.Where(p => !package.Planets.Contains(p)).OrderBy(p => p.Name))
            {
                planetsNode.AddItemWithImage(p.Name, p, p.Icon);
            }

            // sort vehicles descending by size, then alphabetically
            // no trading units that are in cargo
            var vehiclesNode = tree.AddItemWithImage("Vehicles", "Vehicles", Pictures.GetVehicleTypeImage(emp.ShipsetPath, VehicleTypes.Ship));

            foreach (var v in emp.OwnedSpaceObjects.OfType <SpaceVehicle>().Where(v => !package.Vehicles.Contains(v) && !(v is IUnit && ((IUnit)v).Container is ISpaceObject)).OrderByDescending(v => v.Design.Hull.Size).ThenBy(v => v.Name))
            {
                vehiclesNode.AddItemWithImage(v.Name, v, v.Icon);
            }

            // resources
            var resourcesNode = tree.AddItemWithImage("Resources", "Resources", Resource.Minerals.Icon);

            foreach (var r in Resource.All.Where(r => r.IsGlobal))
            {
                resourcesNode.AddItemWithImage(emp.StoredResources[r].ToUnitString(true) + " " + r, r, r.Icon);
            }

            // technology
            var techNode = tree.AddItemWithImage("Technology", "Technology", Resource.Research.Icon);

            foreach (var kvp in emp.ResearchedTechnologies.Where(kvp => kvp.Value > 0))
            {
                techNode.AddItemWithImage(kvp.Key.Name + " level " + kvp.Value, kvp.Key, kvp.Key.Icon);
            }

            // star charts
            var chartsNode = tree.AddItemWithImage("Star Charts", "Star Charts", Pictures.GetGenericImage(typeof(StarSystem)));

            foreach (var sys in emp.ExploredStarSystems.Where(sys => !package.StarCharts.Contains(sys)))
            {
                chartsNode.AddItemWithImage(sys.Name, sys, sys.Icon);
            }

            // comms channels
            var commsNode = tree.AddItemWithImage("Communications Channels", "Communications Channels", Pictures.GetGenericImage(typeof(Empire)));

            foreach (var ee in emp.EncounteredEmpires.Where(ee => !package.CommunicationChannels.Contains(ee)))
            {
                commsNode.AddItemWithImage(ee.Name, ee, ee.Icon);
            }
        }