Esempio n. 1
0
        private void FromXml_Version_1_56(XmlDocument xDoc)
        {
            XmlNodeList xNodeList;
            HullRace race;
            Vessel vessel;
            BeamPort bp;
            DronePort dp;
            EnginePort ep;
            ImpulsePoint ip;
            ManeuverPoint mp;

            xNodeList = xDoc.GetElementsByTagName("hullRace");
            foreach (XmlNode node in xNodeList)
            {
                race = new HullRace();

                foreach (XmlAttribute att in node.Attributes)
                {
                    switch (att.Name)
                    {
                        case "ID":
                            race.ID = att.Value;
                            break;
                        case "name":
                            race.name = att.Value;
                            if (!RaceNames.Contains(race.name))
                                RaceNames.Add(race.name);
                            break;
                        case "keys":

                            foreach (string s in att.Value.Split(' '))
                            {
                                race.keys.Add(s);
                                if (!RaceKeys.Contains(s))
                                    RaceKeys.Add(s);
                            }
                            break;
                    }
                }

                if (String.IsNullOrEmpty(race.ID))
                    continue;
                HullRaceList.Add(race.ID, race);
            }

            RaceNamesSortedByLength = RaceNames.ToList();
            RaceNamesSortedByLength.Sort(new Comparison<string>((string a, string b) =>
            {
                int diff = b.Split(' ').Length - a.Split(' ').Length;
                if (diff != 0) return diff;
                return String.Compare(a, b);
            }
            ));

            xNodeList = xDoc.GetElementsByTagName("vessel");
            foreach (XmlNode node in xNodeList)
            {
                vessel = new Vessel();

                foreach (XmlAttribute att in node.Attributes)
                {
                    switch (att.Name)
                    {
                        case "uniqueID":
                            vessel.uniqueID = att.Value;
                            break;
                        case "side":
                            vessel.side = att.Value;
                            break;
                        case "classname":
                            vessel.classname = att.Value;
                            if (!VesselClassNames.Contains(vessel.classname))
                                VesselClassNames.Add(vessel.classname);
                            break;
                        case "broadType":
                            vessel.broadType = att.Value;
                            foreach(string broadType in vessel.broadType.Split(' '))
                                if (!VesselBroadTypes.Contains(broadType))
                                    VesselBroadTypes.Add(broadType);
                            break;
                    }
                }

                if (String.IsNullOrEmpty(vessel.uniqueID))
                    continue;

                foreach (XmlNode subNode in node.ChildNodes)
                {
                    switch (subNode.Name)
                    {
                        case "art":
                            foreach (XmlAttribute att in node.Attributes)
                            {
                                switch (att.Name)
                                {
                                    case "meshfile":
                                        vessel.meshfile = att.Value;
                                        break;
                                    case "diffuseFile":
                                        vessel.diffuseFile = att.Value;
                                        break;
                                    case "glowFile":
                                        vessel.glowFile = att.Value;
                                        break;
                                    case "specularFile":
                                        vessel.specularFile = att.Value;
                                        break;
                                    case "scale":
                                        vessel.scale = Helper.StringToDouble(att.Value);
                                        break;
                                    case "pushRadius":
                                        vessel.pushRadius = Helper.StringToDouble(att.Value);
                                        break;
                                }
                            }
                            break;

                        case "shields":
                            foreach (XmlAttribute att in node.Attributes)
                            {
                                switch (att.Name)
                                {
                                    case "front":
                                        vessel.shields_front = Helper.StringToDouble(att.Value);
                                        break;
                                    case "back":
                                        vessel.shields_back = Helper.StringToDouble(att.Value);
                                        break;
                                }
                            }
                            break;

                        case "carrier":
                            foreach (XmlAttribute att in node.Attributes)
                            {
                                switch (att.Name)
                                {
                                    case "compliment":
                                        vessel.carrier_compliment = Helper.StringToDouble(att.Value);
                                        break;
                                }
                            }
                            break;

                        case "performance":
                            foreach (XmlAttribute att in node.Attributes)
                            {
                                switch (att.Name)
                                {
                                    case "turnrate":
                                        vessel.preformance_turnrate = Helper.StringToDouble(att.Value);
                                        break;
                                    case "topspeed":
                                        vessel.preformance_topspeed = Helper.StringToDouble(att.Value);
                                        break;
                                }
                            }
                            break;

                        case "fleet_ai":
                            foreach (XmlAttribute att in node.Attributes)
                            {
                                switch (att.Name)
                                {
                                    case "commonality":
                                        vessel.fleet_ai_commonality = Helper.StringToDouble(att.Value);
                                        break;
                                }
                            }

                            break;

                        case "beam_port":
                            bp = new BeamPort();
                            foreach (XmlAttribute att in subNode.Attributes)
                            {
                                switch (att.Name)
                                {
                                    case "x":
                                        bp.x = Helper.StringToDouble(att.Value);
                                        break;
                                    case "y":
                                        bp.y = Helper.StringToDouble(att.Value);
                                        break;
                                    case "z":
                                        bp.z = Helper.StringToDouble(att.Value);
                                        break;
                                    case "range":
                                        bp.range = Helper.StringToDouble(att.Value);
                                        break;
                                    case "damage":
                                        bp.damage = Helper.StringToDouble(att.Value);
                                        break;
                                    case "cycletime":
                                        bp.cycletime = Helper.StringToDouble(att.Value);
                                        break;
                                    case "arcwidth":
                                        bp.arcwidth = Helper.StringToDouble(att.Value);
                                        break;
                                }
                            }
                            vessel.beam_ports.Add(bp);
                            break;

                        case "drone_port":
                            dp = new DronePort();
                            foreach (XmlAttribute att in subNode.Attributes)
                            {
                                switch (att.Name)
                                {
                                    case "x":
                                        dp.x = Helper.StringToDouble(att.Value);
                                        break;
                                    case "y":
                                        dp.y = Helper.StringToDouble(att.Value);
                                        break;
                                    case "z":
                                        dp.z = Helper.StringToDouble(att.Value);
                                        break;
                                    case "range":
                                        dp.range = Helper.StringToDouble(att.Value);
                                        break;
                                    case "damage":
                                        dp.damage = Helper.StringToDouble(att.Value);
                                        break;
                                    case "cycletime":
                                        dp.cycletime = Helper.StringToDouble(att.Value);
                                        break;
                                }
                            }
                            vessel.drone_ports.Add(dp);
                            break;

                        case "engine_port":
                            ep = new EnginePort();
                            foreach (XmlAttribute att in subNode.Attributes)
                            {
                                switch (att.Name)
                                {
                                    case "x":
                                        ep.x = Helper.StringToDouble(att.Value);
                                        break;
                                    case "y":
                                        ep.y = Helper.StringToDouble(att.Value);
                                        break;
                                    case "z":
                                        ep.z = Helper.StringToDouble(att.Value);
                                        break;

                                }
                            }
                            vessel.engine_ports.Add(ep);
                            break;

                        case "impulse_point":
                            ip = new ImpulsePoint();
                            foreach (XmlAttribute att in subNode.Attributes)
                            {
                                switch (att.Name)
                                {
                                    case "x":
                                        ip.x = Helper.StringToDouble(att.Value);
                                        break;
                                    case "y":
                                        ip.y = Helper.StringToDouble(att.Value);
                                        break;
                                    case "z":
                                        ip.z = Helper.StringToDouble(att.Value);
                                        break;

                                }
                            }
                            vessel.impulse_points.Add(ip);
                            break;

                        case "maneuver_point":
                            mp = new ManeuverPoint();
                            foreach (XmlAttribute att in subNode.Attributes)
                            {
                                switch (att.Name)
                                {
                                    case "x":
                                        mp.x = Helper.StringToDouble(att.Value);
                                        break;
                                    case "y":
                                        mp.y = Helper.StringToDouble(att.Value);
                                        break;
                                    case "z":
                                        mp.z = Helper.StringToDouble(att.Value);
                                        break;

                                }
                            }
                            vessel.maneuver_points.Add(mp);
                            break;
                    }
                }
                VesselList.Add(vessel.uniqueID, vessel);
            }

            VesselClassNamesSortedByLength = VesselClassNames.ToList();
            VesselClassNamesSortedByLength.Sort(new Comparison<string>((string a, string b) =>
            {
                int diff = b.Split(' ').Length - a.Split(' ').Length;
                if (diff != 0) return diff;
                return String.Compare(a, b);
            }
            ));
        }
        private void FromXml_Version_1_56(XmlDocument xDoc)
        {
            XmlNodeList   xNodeList;
            HullRace      race;
            Vessel        vessel;
            BeamPort      bp;
            DronePort     dp;
            EnginePort    ep;
            ImpulsePoint  ip;
            ManeuverPoint mp;

            xNodeList = xDoc.GetElementsByTagName("hullRace");
            foreach (XmlNode node in xNodeList)
            {
                race = new HullRace();

                foreach (XmlAttribute att in node.Attributes)
                {
                    switch (att.Name)
                    {
                    case "ID":
                        race.ID = att.Value;
                        break;

                    case "name":
                        race.name = att.Value;
                        if (!RaceNames.Contains(race.name))
                        {
                            RaceNames.Add(race.name);
                        }
                        break;

                    case "keys":

                        foreach (string s in att.Value.Split(' '))
                        {
                            race.keys.Add(s);
                            if (!RaceKeys.Contains(s))
                            {
                                RaceKeys.Add(s);
                            }
                        }
                        break;
                    }
                }

                if (String.IsNullOrEmpty(race.ID))
                {
                    continue;
                }
                HullRaceList.Add(race.ID, race);
            }

            RaceNamesSortedByLength = RaceNames.ToList();
            RaceNamesSortedByLength.Sort(new Comparison <string>((string a, string b) =>
            {
                int diff = b.Split(' ').Length - a.Split(' ').Length;
                if (diff != 0)
                {
                    return(diff);
                }
                return(String.Compare(a, b));
            }
                                                                 ));

            xNodeList = xDoc.GetElementsByTagName("vessel");
            foreach (XmlNode node in xNodeList)
            {
                vessel = new Vessel();

                foreach (XmlAttribute att in node.Attributes)
                {
                    switch (att.Name)
                    {
                    case "uniqueID":
                        vessel.uniqueID = att.Value;
                        break;

                    case "side":
                        vessel.side = att.Value;
                        break;

                    case "classname":
                        vessel.classname = att.Value;
                        if (!VesselClassNames.Contains(vessel.classname))
                        {
                            VesselClassNames.Add(vessel.classname);
                        }
                        break;

                    case "broadType":
                        vessel.broadType = att.Value;
                        foreach (string broadType in vessel.broadType.Split(' '))
                        {
                            if (!VesselBroadTypes.Contains(broadType))
                            {
                                VesselBroadTypes.Add(broadType);
                            }
                        }
                        break;
                    }
                }

                if (String.IsNullOrEmpty(vessel.uniqueID))
                {
                    continue;
                }

                foreach (XmlNode subNode in node.ChildNodes)
                {
                    switch (subNode.Name)
                    {
                    case "art":
                        foreach (XmlAttribute att in node.Attributes)
                        {
                            switch (att.Name)
                            {
                            case "meshfile":
                                vessel.meshfile = att.Value;
                                break;

                            case "diffuseFile":
                                vessel.diffuseFile = att.Value;
                                break;

                            case "glowFile":
                                vessel.glowFile = att.Value;
                                break;

                            case "specularFile":
                                vessel.specularFile = att.Value;
                                break;

                            case "scale":
                                vessel.scale = Helper.StringToDouble(att.Value);
                                break;

                            case "pushRadius":
                                vessel.pushRadius = Helper.StringToDouble(att.Value);
                                break;
                            }
                        }
                        break;

                    case "shields":
                        foreach (XmlAttribute att in node.Attributes)
                        {
                            switch (att.Name)
                            {
                            case "front":
                                vessel.shields_front = Helper.StringToDouble(att.Value);
                                break;

                            case "back":
                                vessel.shields_back = Helper.StringToDouble(att.Value);
                                break;
                            }
                        }
                        break;

                    case "carrier":
                        foreach (XmlAttribute att in node.Attributes)
                        {
                            switch (att.Name)
                            {
                            case "compliment":
                                vessel.carrier_compliment = Helper.StringToDouble(att.Value);
                                break;
                            }
                        }
                        break;

                    case "performance":
                        foreach (XmlAttribute att in node.Attributes)
                        {
                            switch (att.Name)
                            {
                            case "turnrate":
                                vessel.preformance_turnrate = Helper.StringToDouble(att.Value);
                                break;

                            case "topspeed":
                                vessel.preformance_topspeed = Helper.StringToDouble(att.Value);
                                break;
                            }
                        }
                        break;

                    case "fleet_ai":
                        foreach (XmlAttribute att in node.Attributes)
                        {
                            switch (att.Name)
                            {
                            case "commonality":
                                vessel.fleet_ai_commonality = Helper.StringToDouble(att.Value);
                                break;
                            }
                        }

                        break;

                    case "beam_port":
                        bp = new BeamPort();
                        foreach (XmlAttribute att in subNode.Attributes)
                        {
                            switch (att.Name)
                            {
                            case "x":
                                bp.x = Helper.StringToDouble(att.Value);
                                break;

                            case "y":
                                bp.y = Helper.StringToDouble(att.Value);
                                break;

                            case "z":
                                bp.z = Helper.StringToDouble(att.Value);
                                break;

                            case "range":
                                bp.range = Helper.StringToDouble(att.Value);
                                break;

                            case "damage":
                                bp.damage = Helper.StringToDouble(att.Value);
                                break;

                            case "cycletime":
                                bp.cycletime = Helper.StringToDouble(att.Value);
                                break;

                            case "arcwidth":
                                bp.arcwidth = Helper.StringToDouble(att.Value);
                                break;
                            }
                        }
                        vessel.beam_ports.Add(bp);
                        break;

                    case "drone_port":
                        dp = new DronePort();
                        foreach (XmlAttribute att in subNode.Attributes)
                        {
                            switch (att.Name)
                            {
                            case "x":
                                dp.x = Helper.StringToDouble(att.Value);
                                break;

                            case "y":
                                dp.y = Helper.StringToDouble(att.Value);
                                break;

                            case "z":
                                dp.z = Helper.StringToDouble(att.Value);
                                break;

                            case "range":
                                dp.range = Helper.StringToDouble(att.Value);
                                break;

                            case "damage":
                                dp.damage = Helper.StringToDouble(att.Value);
                                break;

                            case "cycletime":
                                dp.cycletime = Helper.StringToDouble(att.Value);
                                break;
                            }
                        }
                        vessel.drone_ports.Add(dp);
                        break;

                    case "engine_port":
                        ep = new EnginePort();
                        foreach (XmlAttribute att in subNode.Attributes)
                        {
                            switch (att.Name)
                            {
                            case "x":
                                ep.x = Helper.StringToDouble(att.Value);
                                break;

                            case "y":
                                ep.y = Helper.StringToDouble(att.Value);
                                break;

                            case "z":
                                ep.z = Helper.StringToDouble(att.Value);
                                break;
                            }
                        }
                        vessel.engine_ports.Add(ep);
                        break;

                    case "impulse_point":
                        ip = new ImpulsePoint();
                        foreach (XmlAttribute att in subNode.Attributes)
                        {
                            switch (att.Name)
                            {
                            case "x":
                                ip.x = Helper.StringToDouble(att.Value);
                                break;

                            case "y":
                                ip.y = Helper.StringToDouble(att.Value);
                                break;

                            case "z":
                                ip.z = Helper.StringToDouble(att.Value);
                                break;
                            }
                        }
                        vessel.impulse_points.Add(ip);
                        break;

                    case "maneuver_point":
                        mp = new ManeuverPoint();
                        foreach (XmlAttribute att in subNode.Attributes)
                        {
                            switch (att.Name)
                            {
                            case "x":
                                mp.x = Helper.StringToDouble(att.Value);
                                break;

                            case "y":
                                mp.y = Helper.StringToDouble(att.Value);
                                break;

                            case "z":
                                mp.z = Helper.StringToDouble(att.Value);
                                break;
                            }
                        }
                        vessel.maneuver_points.Add(mp);
                        break;
                    }
                }
                VesselList.Add(vessel.uniqueID, vessel);
            }

            VesselClassNamesSortedByLength = VesselClassNames.ToList();
            VesselClassNamesSortedByLength.Sort(new Comparison <string>((string a, string b) =>
            {
                int diff = b.Split(' ').Length - a.Split(' ').Length;
                if (diff != 0)
                {
                    return(diff);
                }
                return(String.Compare(a, b));
            }
                                                                        ));
        }