Esempio n. 1
0
        //The basic constructor for the class.
        public Star(int posX, int posY)
        {
            this.rootTemplate = StellarObjectTemplateDict.GetTemplate("StellarObject_Star");

            this.posX = posX;
            this.posY = posY;
        }
Esempio n. 2
0
        //The basic constructor for the class.
        public EmptySpace(int posX, int posY)
        {
            this.rootTemplate = StellarObjectTemplateDict.GetTemplate("StellarObject_EmptySpace");

            this.posX = posX;
            this.posY = posY;
        }
Esempio n. 3
0
        //The basic constructor for the class.
        public Moon(int posX, int posY)
        {
            this.rootTemplate = StellarObjectTemplateDict.GetTemplate("StellarObject_Moon");

            this.posX = posX;
            this.posY = posY;
        }
Esempio n. 4
0
        //The standard constructor for now.
        public Planet(int posX, int posY)
        {
            this.rootTemplate = StellarObjectTemplateDict.GetTemplate("StellarObject_Planet");

            this.posX = posX;
            this.posY = posY;
        }
Esempio n. 5
0
        //Called upon starting by the Unity engine.
        void Start()
        {
            Settings.LoadSettings();                    //Loads the settings of the game.

            QualitySettings.vSyncCount = 60;            //Sets the frame rate cap used by Unity.

            StellarObjectTemplateDict.Initialize();     //Starts up all the crucial dictionaries we need.
            ShipTemplateDict.Initialize();
            MatDict.Initialize();

            StellarPathfinderList.Initialize();         //Starts up the list of StellarPathfinders.

            TemplateManager.BuildDicts();               //Orders the TemplateManager to build all the template dictionaries.

            DisplayManager.CreateDrawMesh();            //Order the DisplayManager to draw the mesh that is used for rendering.

            Galaxy.RandomGenerate(1, 1);                //Orders the Galaxy to randomly generate a 1 by 1 galaxy.

            //For testing purposes, add a simple ship object to the center of the only star system in the galaxy.
            Galaxy.galaxyArray[0, 0].systemObjects[15, 15].AddShip(new Ship("BasicShip", Galaxy.galaxyArray[0, 0], new IntVec2(15, 15)));
        }
        //Builds the StellarObjectTemplate dictionary from the XML database.
        public static void BuildStellarObjectTemplateDict()
        {
            //First check if the dictionary is already built.
            if (!stellarObjectTemplateDictBuilt)
            {
                //Try to open StellarObjectDefs.xml
                try
                {
                    reader = new XmlTextReader("Assets/Resources/Defs/StellarObjectDefs.xml");
                }
                catch
                {
                    //Catch the file not being found.
                    Debug.Log("Could not find StellarObjectDefs.xml");
                    return;
                }

                //Continue reading the file until the end.
                while (reader.Read())
                {
                    //Check if the read data is a start element.
                    if (reader.IsStartElement())
                    {
                        //If it is, determine what variable it's referring to, and assign it.
                        switch (reader.Name.ToString())
                        {
                        //Start building a new StellarObjectTemplate.
                        case "StellarObjectTemplate":
                            workStellarObjectTemplate = new StellarObjectTemplate();
                            break;

                        //Assign the graphicName.
                        case "graphicName":
                            workStellarObjectTemplate.SetGraphicName(reader.ReadString());
                            break;

                        //Build the template's material.
                        case "graphicPath":
                            workMat                        = new Material(Shader.Find("Sprites/Default"));
                            workMat.mainTexture            = Resources.Load(reader.ReadString()) as Texture2D;
                            workMat.mainTexture.filterMode = FilterMode.Bilinear;
                            MatDict.SetMaterial(workStellarObjectTemplate.graphicName, workMat);
                            break;
                        }
                    }
                    else
                    {
                        //Otherwise, check if the node is an end element.
                        if (reader.NodeType == XmlNodeType.EndElement)
                        {
                            //Check if this is the end of the template.
                            if (reader.Name.Equals("StellarObjectTemplate"))
                            {
                                //If it is, finalize the template and add it to the dictionary.
                                workStellarObjectTemplate.Finalized();
                                StellarObjectTemplateDict.SetTemplate(workStellarObjectTemplate.graphicName, workStellarObjectTemplate);
                            }
                        }
                    }
                }
                //Ensure the file is closed after reading, and mark the StellarObjectTemplate dictionary as built.
                reader.Close();
                stellarObjectTemplateDictBuilt = true;
            }
            else
            {
                //If it's already built, something went wrong.
                Debug.Log("Attempting to build already built StellarObjectTemplateDict.");
            }
        }