Ejemplo n.º 1
0
    public void ReadXml(XmlReader reader)
    {
        reader.MoveToContent();

        id   = reader.GetAttribute("id");
        name = reader.GetAttribute("name");
        //Debug.Log("New law " + id + " " + name);

        while (reader.Read())
        {
            XmlNodeType nodeType = reader.NodeType;
            switch (nodeType)
            {
            case XmlNodeType.Element:
                if (reader.Name.Equals("Parameter"))
                {
                    string paramType = reader.GetAttribute("type");
                    string dv        = reader.GetAttribute("default");
                    string range     = reader.GetAttribute("range");
                    string name      = reader.ReadElementContentAsString();
                    parameters[name] = new GenericParameter(paramType, dv, range);
                }
                else if (reader.Name.Equals("Action"))
                {
                    string eventType = reader.GetAttribute("type");
                    if (eventType == null)
                    {
                        eventType = "lua";
                    }
                    string eventName  = reader.GetAttribute("event");
                    string actionName = reader.ReadElementContentAsString();
                    actions[eventName] = new GenericAction(eventName, actionName, eventType);
                }
                else if (reader.Name.Equals("Gui"))
                {
                    XmlReader reader2 = reader.ReadSubtree();
                    LawManager.treeDispatcher("Gui", reader2, this);
                    reader2.Close();
                    //guiSubtree = reader.ReadSubtree();
                }
                else if (reader.Name.Equals("Description"))
                {
                    description = reader.ReadElementContentAsString();
                }
                break;

            case XmlNodeType.EndElement:
            default:
                break;
            }
        }
    }
Ejemplo n.º 2
0
    public World(Coord2D size_)
    {
        rnd     = new System.Random();
        size    = size_;
        regions = new Region[size.x, size.y];
        for (int x = 0; x < size.x; ++x)
        {
            for (int y = 0; y < size.y; y++)
            {
                regions[x, y] = new Region(this, new Coord2D(x, y));
            }
        }

        governmentManager = new GovernmentManager();
        lawManager        = new LawManager();
        //

        /// GENERATE
        ///
        int numberOfCountries = 30;

        for (int c = 0; c < numberOfCountries;)
        {
            Region possibleRegion = getRegionAt(
                new Coord2D(
                    rnd.Next(size.x),
                    rnd.Next(size.y)
                    )
                );
            if (possibleRegion == null || possibleRegion.country != null)
            {
                continue;
            }
            Country country = new Country(rnd.Next(1000).ToString());
            if (thisCountry == null)
            {
                thisCountry = country;
            }
            addCountry(country);
            country.addRegion(possibleRegion);
            country.capital = possibleRegion;
            ++c;
        }
        for (int i = 0; i < 1000; i++)
        {
            foreach (Country country in countries)
            {
                int      r     = rnd.Next(country.regions.Count);
                Region[] nhbds = country.regions[r].getNeighbours();
                //foreach (Region nhbd in nhbds)
                //{
                //    if (nhbd.country == null) nhbd.country = country;
                //    break;
                //}
                Region nhbd = nhbds[rnd.Next(8)];
                if (nhbd != null && nhbd.country == null)
                {
                    nhbd.country = country;
                }
            }
        }
        foreach (Country country in countries)
        {
            int size      = country.regions.Count;
            int numCities = rnd.Next(size) / 10 + 3;
            for (int i = 0; i < numCities; i++)
            {
                int max = 100;
                if (i < 3)
                {
                    max = 200;
                }
                int    idx  = rnd.Next(size);
                Region city = country.regions[idx];
                if (i == 0)
                {
                    country.capital = city;
                }
                country.regions[idx].population = rnd.Next(50, max);

                int      metropolitanAreaSize = rnd.Next(1, 6);
                Region[] metropolitanArea     = new Region[metropolitanAreaSize];
                metropolitanArea[0] = country.capital;
                int max_metro = 70;
                for (int j = 1; j < metropolitanAreaSize; j++)
                {
                    Region prev = metropolitanArea[rnd.Next(j)];
                    if (prev == null)
                    {
                        continue;
                    }
                    Region tentative = prev.getNeighbours()[rnd.Next(8)];
                    if (tentative == null || tentative.country == null)
                    {
                        continue;
                    }
                    metropolitanArea[j]            = tentative;
                    metropolitanArea[j].population = rnd.Next(10, max_metro);
                }
            }
        }

        //// TEMPORARILY ASSIGN GOV. (randomly) to country
        int govsize = GovernmentManager.governmentPrototypes.Count;

        foreach (Country ctry in countries)
        {
            int idx = rnd.Next(govsize);
            ctry.government = GovernmentManager.governmentPrototypes[idx].Clone() as Government;
        }
    }