Exemple #1
0
        public void readLifeNode(XmlNode root)
        {
            try
            {
                DataStore.lifeSpanMultiplier = Convert.ToInt32(root.Attributes["modifier"].InnerText);
            }
            catch (Exception e)
            {
                Debugging.bufferWarning("lifespan multiplier was not an integer: " + e.Message + ". Setting to 3");
                DataStore.lifeSpanMultiplier = 3;
            }

            if (DataStore.lifeSpanMultiplier <= 0)
            {
                Debugging.bufferWarning("Detecting a lifeSpan multiplier less than or equal to 0 . Setting to 3");
                DataStore.lifeSpanMultiplier = 3;
            }

            foreach (XmlNode node in root.ChildNodes)
            {
                if (node.Name.Equals(survivalNodeName))
                {
                    readSurvivalNode(node);
                }
                else if (node.Name.Equals(sicknessNodeName))
                {
                    readSicknessNode(node);
                }
            }
        }
Exemple #2
0
        public void readImmigrateNode(XmlNode root)
        {
            foreach (XmlNode node in root.ChildNodes)
            {
                int[] array = null;

                if (node.Name.Equals("single_adult"))
                {
                    array = DataStore.incomingSingleAge;
                }
                else if (node.Name.Equals("family_adult"))
                {
                    array = DataStore.incomingAdultAge;
                }
                else
                {
                    Debugging.bufferWarning("Unknown immigration node");
                }

                try
                {
                    array[0] = Convert.ToInt32(node.Attributes["min"].InnerText);
                    array[1] = Convert.ToInt32(node.Attributes["max"].InnerText);
                }
                catch (Exception e)
                {
                    Debugging.bufferWarning("readImmigrateNode: " + e.Message);
                }
            }
        }
Exemple #3
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="wealthNode"></param>
        /// <param name="density"></param>
        private void readTravelWealthNode(XmlNode wealthNode, int density)
        {
            foreach (XmlNode node in wealthNode.ChildNodes)
            {
                string    name = node.Name;
                int[][][] array;

                switch (name)
                {
                case "low_wealth":
                    array = DataStore.wealth_low;
                    break;

                case "med_wealth":
                    array = DataStore.wealth_med;
                    break;

                case "high_wealth":
                    array = DataStore.wealth_high;
                    break;

                default:
                    Debugging.bufferWarning("readWealthNode. unknown element name: " + name);
                    return;
                }

                // Read inner attributes
                readTravelAgeNode(node, array[density]);
            } // end foreach
        }
Exemple #4
0
        public void readLifeNode(XmlNode root)
        {
            try
            {
                DataStore.lifeSpanMultiplier = Convert.ToInt32(root.Attributes["modifier"].InnerText);
            }
            catch (Exception e)
            {
                Debugging.bufferWarning("lifespan multiplier was not an integer: " + e.Message + ". Setting to 3");
                DataStore.lifeSpanMultiplier = 3;
            }

/*
 *          try
 *          {
 *              DataStore.workSpeedMultiplier = Convert.ToInt32(root.Attributes["workspeed"].InnerText);
 *          }
 *          catch (Exception e)
 *          {
 *              Debugging.bufferWarning("workspeed multiplier was not an integer: " + e.Message + ". Setting to 3");
 *              DataStore.workSpeedMultiplier = 3;
 *          }
 */

            if (DataStore.lifeSpanMultiplier <= 0)
            {
                Debugging.bufferWarning("Detecting a lifeSpan multiplier less than or equal to 0 . Setting to 3");
                DataStore.lifeSpanMultiplier = 3;
            }

/*
 *          if (DataStore.workSpeedMultiplier <= 0)
 *          {
 *              Debugging.bufferWarning("Detecting a work speed multiplier less than or equal to 0 . Setting to 3");
 *              DataStore.workSpeedMultiplier = 3;
 *          }
 *
 *          DataStore.workNumberCheck = 15 / DataStore.workSpeedMultiplier;
 */
            foreach (XmlNode node in root.ChildNodes)
            {
                if (node.Name.Equals(survivalNodeName))
                {
                    readSurvivalNode(node);
                }
                else if (node.Name.Equals(sicknessNodeName))
                {
                    readSicknessNode(node);
                }
                else if (node.Name.Equals(sickDieNodeName))
                {
                    readHospitalNode(node);
                }
                else if (node.Name.Equals(cheatHearseNodeName))
                {
                    readCheatHearseNode(node);
                }
            }
        }
        /// <summary>
        ///
        /// </summary>
        public static void readFromXML()
        {
            // Switch to default which is the cities skylines in the application data area.
            currentFileLocation = ColossalFramework.IO.DataLocation.localApplicationData + Path.DirectorySeparatorChar + XML_FILE;

            if (File.Exists(currentFileLocation))
            {
                // Load in from XML - Designed to be flat file for ease
                WG_XMLBaseVersion reader = new XML_VersionTwo();
                XmlDocument       doc    = new XmlDocument();
                try
                {
                    doc.Load(currentFileLocation);
                    int version = Convert.ToInt32(doc.DocumentElement.Attributes["version"].InnerText);
                    if (version == 1)
                    {
                        reader = new XML_VersionOne();

                        // Make a back up copy of the old system to be safe
                        File.Copy(currentFileLocation, currentFileLocation + ".ver1", true);
                        string error = "Detected an old version of the XML (v1). " + currentFileLocation + ".ver1 has been created for future reference and will be upgraded to the new version.";
                        Debugging.bufferWarning(error);
                        Debugging.Message(error);
                    }
                    else if (version <= 0) // Uh oh... version 0 was a while back..
                    {
                        string error = "Detected an unsupported version of the XML (v0 or less). Backing up for a new configuration as :" + currentFileLocation + ".ver0";
                        Debugging.bufferWarning(error);
                        Debugging.Message(error);
                        File.Copy(currentFileLocation, currentFileLocation + ".ver0", true);
                        return;
                    }
                    reader.readXML(doc);
                }
                catch (Exception e)
                {
                    // Game will now use defaults
                    Debugging.bufferWarning("The following exception(s) were detected while loading the XML file. Some (or all) values may not be loaded.");
                    Debugging.bufferWarning(e.Message);
                }
            }
            else
            {
                Debugging.Message("configuration file not found. Will output new file to : " + currentFileLocation);
            }
        }
Exemple #6
0
 public void readCheatHearseNode(XmlNode root)
 {
     try
     {
         DataStore.autoDeadRemovalChance = (int)Convert.ToDouble(root.Attributes["chance"].InnerText);
         if ((DataStore.autoDeadRemovalChance < 0) && (DataStore.autoDeadRemovalChance > 100))
         {
             Debugging.bufferWarning("Cheat hearse is out of range (0-100). Setting to 50");
             DataStore.autoDeadRemovalChance = 50;
         }
     }
     catch (Exception e)
     {
         Debugging.bufferWarning(e.Message);
         DataStore.autoDeadRemovalChance = 50;
     }
 }
Exemple #7
0
 public void readSicknessNode(XmlNode root)
 {
     foreach (XmlNode node in root.ChildNodes)
     {
         if (node.Name.Equals("decile"))
         {
             try
             {
                 int index = Convert.ToInt32(node.Attributes["num"].InnerText) - 1;
                 DataStore.sicknessProbInXML[index] = Convert.ToDouble(node.Attributes["chance"].InnerText) / 100.0;
             }
             catch (Exception e)
             {
                 Debugging.bufferWarning(e.Message);
             }
         }
     }
 }
Exemple #8
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="ageNode"></param>
        /// <param name="arrayRef"></param>
        private void readTravelAgeNode(XmlNode ageNode, int[][] arrayRef)
        {
            foreach (XmlNode node in ageNode.ChildNodes)
            {
                string name  = node.Name;
                int    index = 0;

                if (name.Equals(Citizen.AgeGroup.Child.ToString()))
                {
                    index = 0;
                }
                else if (name.Equals(Citizen.AgeGroup.Teen.ToString()))
                {
                    index = 1;
                }
                else if (name.Equals(Citizen.AgeGroup.Young.ToString()))
                {
                    index = 2;
                }
                else if (name.Equals(Citizen.AgeGroup.Adult.ToString()))
                {
                    index = 3;
                }
                else if (name.Equals(Citizen.AgeGroup.Senior.ToString()))
                {
                    index = 4;
                }

                // Read inner attributes
                try
                {
                    arrayRef[index][DataStore.CAR]  = Convert.ToInt32(node.Attributes["car"].InnerText);
                    arrayRef[index][DataStore.BIKE] = Convert.ToInt32(node.Attributes["bike"].InnerText);
                    arrayRef[index][DataStore.TAXI] = Convert.ToInt32(node.Attributes["taxi"].InnerText);
                }
                catch (Exception e)
                {
                    Debugging.bufferWarning("readAgeNode: " + e.Message);
                }
            } // end foreach
        }
Exemple #9
0
        public void readHospitalNode(XmlNode root)
        {
            foreach (XmlNode node in root.ChildNodes)
            {
                string[] attr  = node.Name.Split(new char[] { '_' });
                string   name  = attr[0];
                int      level = Convert.ToInt32(attr[1]) - 1;

                if (name.Equals("decile"))
                {
                    try
                    {
                        DataStore.sickDeathChance[level] = Convert.ToDouble(node.Attributes["chance"].InnerText) / 100.0;
                    }
                    catch (Exception e)
                    {
                        Debugging.bufferWarning(e.Message);
                    }
                }
            }
        }