Пример #1
0
        /// <summary>
        /// Loads mission from selected file and creates all game objects from the mission file.
        /// Also load materials, mission targets and state (fughts, movements ...).
        /// </summary>
        /// <exception cref="XmlLoadException">Thrown when XML document has a wrong format.</exception>
        public void LoadMission()
        {
            bool hasSun           = false;
            IStaticGameObject sun = null;

            // Load mission (first of given Name)
            missionNode = root.SelectNodes("/mission[1]")[0];

            Game.PropertyManager.LoadPropertyToMission(missionNode.Attributes["propertyFilePath"].InnerText);

            LoadTeams(missionNode.SelectNodes("teams[1]")[0]);

            CompileUsedObjects(missionNode.SelectNodes("usedObjects[1]")[0]);

            // Load every IGameObject
            XmlNode missionSolarSystemNode = missionNode.SelectNodes("solarSystems[1]")[0];

            foreach (XmlNode solarSystem in missionSolarSystemNode)
            {
                List <IStaticGameObject>  isgos = new List <IStaticGameObject>();
                List <IMovableGameObject> imgos = new List <IMovableGameObject>();
                string gameObjectType;
                string solarSystemName = "";
                foreach (XmlNode chldNode in solarSystem.Attributes)
                {
                    switch (chldNode.Name)
                    {
                    case "gate":
                        var gate = runtimeCtor.CreateGate(solarSystemName, teamDict["None"]);
                        isgos.Add(gate);
                        break;

                    case "name":
                        solarSystemName = chldNode.InnerText;
                        break;
                    }
                }

                foreach (XmlNode gameObject in solarSystem.ChildNodes)
                {
                    switch (gameObject.Name)
                    {
                    case "isgo":
                        IsgoType t;
                        gameObjectType = gameObject.Attributes["type"].InnerText;
                        if (gameObjectType == "Sun")
                        {
                            hasSun = true;
                            t      = IsgoType.Sun;
                            sun    = CreateISGO(gameObject, t);
                        }
                        else
                        {
                            t = IsgoType.StaticObject;
                            IStaticGameObject isgo = CreateISGO(gameObject, t);
                            isgo.Team.AddISGO(isgo);
                            isgos.Add(isgo);

                            // Create IGameAction for created object
                            CreateGameActions(gameObject.SelectNodes("gameAction"), isgo);
                            break;
                        }
                        break;

                    case "imgo":
                        gameObjectType = gameObject.Attributes["type"].InnerText;
                        IMovableGameObject imgo = CreateIMGO(gameObject);
                        imgo.Team.AddIMGO(imgo);
                        imgos.Add(imgo);
                        CreateGameActions(gameObject.SelectNodes("gameAction"), imgo);
                        break;

                    default:
                        throw new XmlLoadException("Wrong XML format. In SolarSystem cannot be node " + gameObject.Name);
                    }
                }

                if (hasSun)
                {
                    this.solarSystemList.Add(CreateSolarSystem(solarSystemName,
                                                               ParseStringToVector3(solarSystem.Attributes["position"].Value), isgos, imgos, sun));
                    hasSun = false;
                }
                else
                {
                    this.solarSystemList.Add(CreateSolarSystem(solarSystemName,
                                                               ParseStringToVector3(solarSystem.Attributes["position"].Value), isgos, imgos));
                }
            }

            // Finally load mission targets and materials
            LoadMissionTargets(missionNode.SelectNodes("missionTargets[1]")[0]);
            LoadMaterials(missionNode.SelectNodes("materials[1]")[0]);
            LoadGameState(missionNode.SelectNodes("startState[1]")[0]);
        }