Example #1
0
        /// <summary>
        /// Load: initializing constructor to read in a Fleet report from an XmlNode (from a saved file).
        /// </summary>
        /// <param name="xmlnode">An XmlNode representing a Fleet report.</param>
        public FleetIntel(XmlNode xmlnode) :
            base(xmlnode)
        {
            XmlNode node = xmlnode.FirstChild;
            XmlNode subNode;

            while (node != null)
            {
                try
                {
                    switch (node.Name.ToLower())
                    {
                    case "year":
                        Year = int.Parse(node.FirstChild.Value, System.Globalization.CultureInfo.InvariantCulture);
                        break;

                    case "icon":
                        string iconSource = node.FirstChild.Value;
                        Icon = AllShipIcons.Data.GetIconBySource(iconSource);
                        break;

                    case "bearing":
                        Bearing = double.Parse(node.FirstChild.Value, System.Globalization.CultureInfo.InvariantCulture);
                        break;

                    case "speed":
                        Speed = int.Parse(node.FirstChild.Value, System.Globalization.CultureInfo.InvariantCulture);
                        break;

                    case "inorbit":
                        InOrbit = bool.Parse(node.FirstChild.Value);
                        break;

                    case "isstarbase":
                        IsStarbase = bool.Parse(node.FirstChild.Value);
                        break;

                    case "composition":
                        // We can't call Clear() or we'll erase data set by base(xmlnode), so initialize collection here.
                        Composition = new Dictionary <long, ShipToken>();
                        subNode     = node.FirstChild;
                        ShipToken token;
                        while (subNode != null)
                        {
                            token = new ShipToken(subNode);
                            Composition.Add(token.Key, token);
                            subNode = subNode.NextSibling;
                        }
                        break;
                    }
                }
                catch (Exception e)
                {
                    Report.FatalError(e.Message + "\n Details: \n" + e.ToString());
                }

                node = node.NextSibling;
            }
        }
Example #2
0
 /// <summary>
 /// Generates a Stack from a fleet and a specified ShipToken.
 /// </summary>
 /// <param name="fleet">Parent Fleet.</param>
 /// <param name="stackId">Unique Battle Engine ID.</param>
 /// <param name="token">Ship Token for this Stack.</param>
 public Stack(Fleet fleet, uint stackId, ShipToken token)
     : base(fleet)
 {
     Id         = stackId;
     ParentKey  = fleet.Key;
     Name       = "Stack #" + stackId.ToString("X");
     BattlePlan = fleet.BattlePlan;
     InOrbit    = fleet.InOrbit;
     Token      = token; // note this is a reference to the actual token in the fleet
 }
Example #3
0
 /// <summary>
 /// Copy constructor. This is only used by the battle engine so only the fields
 /// used by it in creating stacks need to be copied. Note that we copy the
 /// token as well. Be careful when using the copy; It is a different object.
 /// </summary>
 /// <param name="copy">The fleet to copy.</param>
 /// <remarks>
 /// Why are we copying Stacks?
 /// For the battle viewer, copies are required so the originals are not destroyed in the battle report.
 /// This allows the battle to be replayed multiple times.
 /// In the battle engine, copies are required to create the battle report, so all stacks present at the start of the battle are represented.
 /// </remarks>
 public Stack(Stack copy)
     : base(copy)
 {
     ParentKey     = copy.ParentKey;
     Key           = copy.Key;
     BattlePlan    = copy.BattlePlan;
     Target        = copy.Target;
     InOrbit       = copy.InOrbit;
     Token         = new ShipToken(copy.Token.Design, copy.Token.Quantity, copy.Token.Armor);
     Token.Shields = copy.Token.Shields;
 }
Example #4
0
        /// <summary>
        /// Fleet construction based on a ShipToken and some parameters from a star (this is
        /// the usual case for most fleets when a new ship is manufactured at a star).
        /// </summary>
        /// <param name="ship">The ShipToken being constructed.</param>
        /// <param name="star">The star constructing the ship.</param>
        public Fleet(ShipToken token, Star star, long newKey)
        {
            tokens.Add(token.Key, token);

            FuelAvailable = TotalFuelCapacity;
            Type          = ItemType.Fleet;

            // Have one waypoint to reflect the fleet's current position and the
            // planet it is in orbit around.

            Waypoint w = new Waypoint();

            w.Position    = star.Position;
            w.Destination = star.Name;
            w.WarpFactor  = 0;

            Waypoints.Add(w);

            // Inititialise the fleet elements that come from the star.

            Position = star.Position;
            InOrbit  = star;
            Key      = newKey;
        }
Example #5
0
        /// <summary>
        /// Load: initializing constructor to load a fleet from an XmlNode (save file).
        /// </summary>
        /// <param name="node">An XmlNode representing the fleet.</param>
        public Fleet(XmlNode node)
            : base(node)
        {
            // Read the node
            XmlNode mainNode = node.FirstChild;

            try
            {
                while (mainNode != null)
                {
                    switch (mainNode.Name.ToLower())
                    {
                    case "fleetid":
                        Id = uint.Parse(mainNode.FirstChild.Value, System.Globalization.CultureInfo.InvariantCulture);
                        break;

                    case "cargo":
                        Cargo = new Cargo(mainNode);
                        break;

                    case "inorbit":
                        InOrbit      = new Star();
                        InOrbit.Name = mainNode.FirstChild.Value;
                        break;

                    case "bearing":
                        Bearing = double.Parse(mainNode.FirstChild.Value, System.Globalization.CultureInfo.InvariantCulture);
                        break;

                    case "cloaked":
                        Cloaked = double.Parse(mainNode.FirstChild.Value, System.Globalization.CultureInfo.InvariantCulture);
                        break;

                    case "fuelavailable":
                        FuelAvailable = double.Parse(mainNode.FirstChild.Value, System.Globalization.CultureInfo.InvariantCulture);
                        break;

                    case "targetdistance":
                        TargetDistance = double.Parse(mainNode.FirstChild.Value, System.Globalization.CultureInfo.InvariantCulture);
                        break;

                    case "battleplan":
                        BattlePlan = mainNode.FirstChild.Value;
                        break;

                    case "tokens":
                        XmlNode   subNode = mainNode.FirstChild;
                        ShipToken token;
                        while (subNode != null)
                        {
                            token = new ShipToken(subNode);
                            tokens.Add(token.Key, token);
                            subNode = subNode.NextSibling;
                        }
                        break;

                    case "waypoint":
                        Waypoint waypoint = new Waypoint(mainNode);
                        Waypoints.Add(waypoint);
                        break;

                    default: break;
                    }


                    mainNode = mainNode.NextSibling;
                }
            }
            catch (Exception e)
            {
                Report.Error("Error loading fleet:" + Environment.NewLine + e.Message);
                throw e;
            }
        }