示例#1
0
        /// <summary>
        /// Raise the Split/Merge fleet dialog.
        /// </summary>
        /// <param name="otherFleet">The second fleet to merge with or split into (may be null).</param>
        private void DoSplitMerge(Fleet otherFleet = null)
        {
            using (SplitFleetDialog splitFleet = new SplitFleetDialog())
            {
                splitFleet.SetFleet(selectedFleet, otherFleet);

                if (splitFleet.ShowDialog() == DialogResult.OK)
                {
                    int      index    = wayPoints.SelectedIndices[0];
                    Waypoint waypoint = new Waypoint(selectedFleet.Waypoints[index]);

                    waypoint.Task = new SplitMergeTask(
                        splitFleet.SourceComposition,
                        splitFleet.OtherComposition,
                        (otherFleet == null) ? 0 : otherFleet.Key);

                    WaypointCommand command = new WaypointCommand(CommandMode.Add, selectedFleet.Key, index);
                    command.Waypoint = waypoint;

                    if (command.IsValid(empireState))
                    {
                        commands.Push(command);

                        command.ApplyToState(empireState);
                        // Also perform it here, to update client state for manual split/merge.
                        if (command.Waypoint.Task.IsValid(selectedFleet, otherFleet, empireState, empireState))
                        {
                            command.Waypoint.Task.Perform(selectedFleet, otherFleet, empireState, empireState);

                            // Now clean and remove empty fleets and update remaining ones
                            // This is done to update the Client State visuals only, the server
                            // will handle this "for real".

                            // Check if original fleet was wiped.
                            if (selectedFleet.Composition.Count == 0)
                            {
                                empireState.RemoveFleet(selectedFleet);
                            }
                            else
                            {
                                empireState.AddOrUpdateFleet(selectedFleet);
                            }

                            // If this was a merge, update old fleet.
                            if (otherFleet != null)
                            {
                                if (otherFleet.Composition.Count == 0)
                                {
                                    empireState.RemoveFleet(otherFleet);
                                }
                                else
                                {
                                    empireState.AddOrUpdateFleet(otherFleet);
                                }
                            }

                            // otherFleet won't come out modified in the case
                            // of a split, so check the fleet Limbo.
                            foreach (Fleet newFleet in empireState.TemporaryFleets)
                            {
                                if (newFleet.Composition.Count == 0)
                                {
                                    empireState.RemoveFleet(newFleet);
                                }
                                else
                                {
                                    empireState.AddOrUpdateFleet(newFleet);
                                }
                            }
                        }
                    }

                    selectedFleet = (otherFleet == null) ? selectedFleet : otherFleet;
                }

                // Signal the change.
                OnFleetSelectionChanged(new SelectionArgs(selectedFleet));
            }
        }
示例#2
0
        /// <summary>
        /// Allocate an initial set of resources to a player's "home" star system. for
        /// each player giving it some colonists and initial resources.
        /// </summary>
        /// <param name="star"></param>
        /// <param name="race"></param>
        private void AllocateHomeStarOrbitalInstallations(Star star, EmpireData empire, string player)
        {
            ShipDesign colonyShipDesign = null;

            foreach (ShipDesign design in empire.Designs.Values)
            {
                if (design.Name == "Santa Maria")
                {
                    colonyShipDesign = design;
                }
            }

            if (empire.Race.Traits.Primary.Code != "HE")
            {
                ShipToken cs     = new ShipToken(colonyShipDesign, 1);
                Fleet     fleet1 = new Fleet(cs, star, empire.GetNextFleetKey());
                fleet1.Name = colonyShipDesign.Name + " #1";
                empire.AddOrUpdateFleet(fleet1);
            }
            else
            {
                for (int i = 1; i <= 3; i++)
                {
                    ShipToken cs    = new ShipToken(colonyShipDesign, 1);
                    Fleet     fleet = new Fleet(cs, star, empire.GetNextFleetKey());
                    fleet.Name = string.Format("{0} #{1}", colonyShipDesign.Name, i);
                    empire.AddOrUpdateFleet(fleet);
                }
            }

            ShipDesign scoutDesign = null;

            foreach (ShipDesign design in empire.Designs.Values)
            {
                if (design.Name == "Scout")
                {
                    scoutDesign = design;
                }
            }

            ShipToken scout      = new ShipToken(scoutDesign, 1);
            Fleet     scoutFleet = new Fleet(scout, star, empire.GetNextFleetKey());

            scoutFleet.Name = "Scout #1";
            empire.AddOrUpdateFleet(scoutFleet);

            ShipDesign starbaseDesign = null;

            foreach (ShipDesign design in empire.Designs.Values)
            {
                if (design.Name == "Starbase")
                {
                    starbaseDesign = design;
                }
            }

            ShipToken starbase      = new ShipToken(starbaseDesign, 1);
            Fleet     starbaseFleet = new Fleet(starbase, star, empire.GetNextFleetKey());

            starbaseFleet.Name = star.Name + " Starbase";
            star.Starbase      = starbaseFleet;
            empire.AddOrUpdateFleet(starbaseFleet);
        }