示例#1
0
        /// <param name="node"></param>
        private void ReadPrintWorkers(XmlNode parent)
        {
            foreach (XmlNode node in parent.ChildNodes)
            {
                if (node.Name.Equals(meshName))
                {
                    try
                    {
                        string name       = node.InnerText;
                        int    PrintValue = 5;
                        PrintValue = Convert.ToInt32(node.Attributes["value"].InnerText);

                        // Needs a value to be valid
                        if (name.Length > 0)
                        {
                            // Don't do anything if this key is already in the dictionary.
                            if (!DataStore.workerPrintOutCache.ContainsKey(name))
                            {
                                DataStore.workerPrintOutCache.Add(name, PrintValue);
                            }
                        }
                    }
                    catch (Exception e)
                    {
                        Debugging.bufferWarning("ReadPrintWorkers exception:\r\n" + e.ToString() + "\r\n...setting to 5");
                    }
                }
            }
        }
示例#2
0
        /// <param name="consumeNode"></param>
        private void ReadConsumptionNode(XmlNode consumeNode)
        {
            foreach (XmlNode node in consumeNode.ChildNodes)
            {
                try
                {
                    // Extract power, water, sewage, garbage and wealth
                    string[] attr    = node.Name.Split(new char[] { '_' });
                    string   name    = attr[0];
                    int      level   = Convert.ToInt32(attr[1]) - 1;
                    int      power   = Convert.ToInt32(node.Attributes["power"].InnerText);
                    int      water   = Convert.ToInt32(node.Attributes["water"].InnerText);
                    int      sewage  = Convert.ToInt32(node.Attributes["sewage"].InnerText);
                    int      garbage = Convert.ToInt32(node.Attributes["garbage"].InnerText);
                    int      wealth  = Convert.ToInt32(node.Attributes["wealth"].InnerText);
                    int[]    array   = GetArray(name, level, "readConsumptionNode");

                    SetConsumptionRates(array, power, water, sewage, garbage, wealth);
                }
                catch (Exception e)
                {
                    Debugging.bufferWarning("readConsumptionNode exception:\r\n" + e.ToString());
                }
            }
        }
        /// <summary>
        /// Loads the configuration XML file and sets the datastore.
        /// </summary>
        internal static void ReadFromXML()
        {
            // Check the exe directory first
            DataStore.currentFileLocation = ColossalFramework.IO.DataLocation.executableDirectory + Path.DirectorySeparatorChar + XML_FILE;
            bool fileAvailable = File.Exists(DataStore.currentFileLocation);

            if (!fileAvailable)
            {
                // Switch to default which is the cities skylines in the application data area.
                DataStore.currentFileLocation = ColossalFramework.IO.DataLocation.localApplicationData + Path.DirectorySeparatorChar + XML_FILE;
                fileAvailable = File.Exists(DataStore.currentFileLocation);
            }

            if (fileAvailable)
            {
                Debugging.Message("loading configuration file " + DataStore.currentFileLocation);

                // Load in from XML - Designed to be flat file for ease
                WG_XMLBaseVersion reader = new XML_VersionSix();
                XmlDocument       doc    = new XmlDocument();
                try
                {
                    doc.Load(DataStore.currentFileLocation);

                    int version = Convert.ToInt32(doc.DocumentElement.Attributes["version"].InnerText);
                    if (version > 3 && version <= 5)
                    {
                        // Use version 5
                        reader = new XML_VersionFive();

                        // Make a back up copy of the old system to be safe
                        File.Copy(DataStore.currentFileLocation, DataStore.currentFileLocation + ".ver5", true);
                        string error = "Detected an old version of the XML (v5). " + DataStore.currentFileLocation + ".ver5 has been created for future reference and will be upgraded to the new version.";
                        Debugging.bufferWarning(error);
                    }
                    else if (version <= 3) // Uh oh... version 4 was a while back..
                    {
                        string error = "Detected an unsupported version of the XML (v4 or less). Backing up for a new configuration as :" + DataStore.currentFileLocation + ".ver4";
                        Debugging.bufferWarning(error);
                        File.Copy(DataStore.currentFileLocation, DataStore.currentFileLocation + ".ver4", 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: " + DataStore.currentFileLocation);
            }
        }
示例#4
0
        /// <param name="node"></param>
        private void ReadOverrideWorkers(XmlNode parent)
        {
            try
            {
                DataStore.printEmploymentNames = Convert.ToBoolean(parent.Attributes["printWorkNames"].InnerText);
            }
            catch (Exception)
            {
                // Do nothing
            }

            try
            {
                DataStore.mergeEmploymentNames = Convert.ToBoolean(parent.Attributes["mergeWorkNames"].InnerText);
            }
            catch (Exception)
            {
                // Do nothing
            }

            foreach (XmlNode node in parent.ChildNodes)
            {
                string name          = node.InnerText;
                int    overrideValue = 5;
                if (node.Name.Equals(meshName) && (name.Length > 0))
                {
                    try
                    {
                        overrideValue = Convert.ToInt32(node.Attributes["value"].InnerText);
                    }
                    catch (Exception e)
                    {
                        Debugging.bufferWarning("readOverrideWorkers exception:\r\n" + e.ToString() + "\r\n...setting to 5");
                        overrideValue = 5;
                    }

                    try
                    {
                        // Don't do anything if this key is already in the dictionary.
                        if (!DataStore.workerCache.ContainsKey(name))
                        {
                            DataStore.workerCache.Add(name, overrideValue);
                        }
                    }
                    catch (Exception e)
                    {
                        Debugging.bufferWarning("ReadOverrideWorkers exception:\r\n" + e.ToString());
                    }
                }
            }
        }
        /// <param name="node"></param>
        private void readBonusWorkers(XmlNode parent)
        {
            try
            {
                DataStore.printEmploymentNames = Convert.ToBoolean(parent.Attributes["printWorkNames"].InnerText);
            }
            catch (Exception)
            {
                // Do nothing
            }

            try
            {
                DataStore.mergeEmploymentNames = Convert.ToBoolean(parent.Attributes["mergeWorkNames"].InnerText);
            }
            catch (Exception)
            {
                // Do nothing
            }

            foreach (XmlNode node in parent.ChildNodes)
            {
                if (node.Name.Equals(meshName))
                {
                    try
                    {
                        string name  = node.InnerText;
                        int    bonus = 5;
                        bonus = Convert.ToInt32(node.Attributes["bonus"].InnerText);

                        if (name.Length > 0)
                        {
                            // Needs a value to be valid
                            DataStore.bonusWorkerCache.Add(name, bonus);
                        }
                    }
                    catch (Exception e)
                    {
                        Debugging.bufferWarning("readBonusWorkers exception:\r\n" + e.ToString() + "\r\n...setting to 5");
                    }
                }
            }
        }
示例#6
0
        /// <param name="produceNode"></param>
        private void ReadVisitNode(XmlNode produceNode)
        {
            foreach (XmlNode node in produceNode.ChildNodes)
            {
                try
                {
                    // Extract power, water, sewage, garbage and wealth
                    string[] attr  = node.Name.Split(new char[] { '_' });
                    string   name  = attr[0];
                    int      level = Convert.ToInt32(attr[1]) - 1;
                    int[]    array = GetArray(name, level, "readVisitNode");

                    array[DataStore.VISIT] = Convert.ToInt32(node.Attributes["visit"].InnerText);
                    if (array[DataStore.VISIT] <= 0)
                    {
                        array[DataStore.VISIT] = 1;
                    }
                }
                catch (Exception e)
                {
                    Debugging.bufferWarning("readVisitNode exception:\r\n" + e.ToString());
                }
            }
        }
示例#7
0
        /// <param name="popNode"></param>
        private void ReadPopulationNode(XmlNode popNode)
        {
            try
            {
                DataStore.strictCapacity = Convert.ToBoolean(popNode.Attributes["strictCapacity"].InnerText);
            }
            catch (Exception)
            {
                // Do nothing
            }

            foreach (XmlNode node in popNode.ChildNodes)
            {
                {
                    string[] attr  = node.Name.Split(new char[] { '_' });
                    string   name  = attr[0];
                    int      level = Convert.ToInt32(attr[1]) - 1;
                    int[]    array = new int[12];

                    try
                    {
                        array = GetArray(name, level, "readPopulationNode");
                        int temp = Convert.ToInt32(node.Attributes["level_height"].InnerText);
                        array[DataStore.LEVEL_HEIGHT] = temp > 0 ? temp : 10;

                        temp = Convert.ToInt32(node.Attributes["space_pp"].InnerText);
                        if (temp <= 0)
                        {
                            temp = 100;  // Bad person trying to give negative or div0 error.
                        }
                        array[DataStore.PEOPLE] = TransformPopulationModifier(name, level, temp, false);
                    }
                    catch (Exception e)
                    {
                        Debugging.bufferWarning("readPopulationNode exception:\r\n" + e.ToString());
                    }

                    try
                    {
                        if (Convert.ToBoolean(node.Attributes["calc"].InnerText.Equals("plot")))
                        {
                            array[DataStore.CALC_METHOD] = 1;
                        }
                        else
                        {
                            array[DataStore.CALC_METHOD] = 0;
                        }
                    }
                    catch
                    {
                    }

                    if (!name.StartsWith("Res"))
                    {
                        try
                        {
                            int dense = Convert.ToInt32(node.Attributes["ground_mult"].InnerText);
                            array[DataStore.DENSIFICATION] = dense >= 0 ? dense : 0;  // Force to be greater than 0

                            int level0 = Convert.ToInt32(node.Attributes["lvl_0"].InnerText);
                            int level1 = Convert.ToInt32(node.Attributes["lvl_1"].InnerText);
                            int level2 = Convert.ToInt32(node.Attributes["lvl_2"].InnerText);
                            int level3 = Convert.ToInt32(node.Attributes["lvl_3"].InnerText);

                            // Ensure all is there first
                            array[DataStore.WORK_LVL0] = level0;
                            array[DataStore.WORK_LVL1] = level1;
                            array[DataStore.WORK_LVL2] = level2;
                            array[DataStore.WORK_LVL3] = level3;
                        }
                        catch (Exception e)
                        {
                            Debugging.bufferWarning("readPopulationNode, part b exception:\r\n" + e.ToString());
                        }
                    }
                } // end if
            }     // end foreach
        }
示例#8
0
        /// <param name="pollutionNode"></param>
        private void ReadPollutionNode(XmlNode pollutionNode)
        {
            string name = "";

            foreach (XmlNode node in pollutionNode.ChildNodes)
            {
                try
                {
                    // Extract power, water, sewage, garbage and wealth
                    string[] attr = node.Name.Split(new char[] { '_' });
                    name = attr[0];
                    int level  = Convert.ToInt32(attr[1]) - 1;
                    int ground = Convert.ToInt32(node.Attributes["ground"].InnerText);
                    int noise  = Convert.ToInt32(node.Attributes["noise"].InnerText);

                    switch (name)
                    {
                    case "ResidentialLow":
                        SetPollutionRates(DataStore.residentialLow[level], ground, noise);
                        break;

                    case "ResidentialHigh":
                        SetPollutionRates(DataStore.residentialHigh[level], ground, noise);
                        break;

                    case "CommercialLow":
                        SetPollutionRates(DataStore.commercialLow[level], ground, noise);
                        break;

                    case "CommercialHigh":
                        SetPollutionRates(DataStore.commercialHigh[level], ground, noise);
                        break;

                    case "CommercialTourist":
                        SetPollutionRates(DataStore.commercialTourist[level], ground, noise);
                        break;

                    case "CommercialLeisure":
                        SetPollutionRates(DataStore.commercialLeisure[level], ground, noise);
                        break;

                    case "Office":
                        SetPollutionRates(DataStore.office[level], ground, noise);
                        break;

                    case "Industry":
                        SetPollutionRates(DataStore.industry[level], ground, noise);
                        break;

                    case "IndustryOre":
                        SetPollutionRates(DataStore.industry_ore[level], ground, noise);
                        break;

                    case "IndustryOil":
                        SetPollutionRates(DataStore.industry_oil[level], ground, noise);
                        break;

                    case "IndustryForest":
                        SetPollutionRates(DataStore.industry_forest[level], ground, noise);
                        break;

                    case "IndustryFarm":
                        SetPollutionRates(DataStore.industry_farm[level], ground, noise);
                        break;
                    }
                }
                catch (Exception e)
                {
                    Debugging.bufferWarning("readPollutionNode exception:\r\n" + e.ToString());
                }
            } // end foreach
        }