Post reply

Message icon:

shortcuts: hit alt+s to submit/post or alt+p to preview

Topic Summary

Posted by: Kronnect
« on: December 05, 2019, 04:45:35 PM »


Use this code:

        /// <summary>
        /// Creates a province with a name and list of points.
        /// </summary>
        /// <returns>The country index.</returns>
        int CreateProvince(string name, int countryIndex, Vector2[] points) {
            // 1) Initialize a new province
            Province province = new Province(name, countryIndex, 0);

            // 2) Define the land region for this country with a list of points with coordinates from -0.5, -0.5 (bottom/left edge of map) to 0.5, 0.5 (top/right edge of map)
            // Note: the list of points should be expressed in clock-wise order
            Region region = new Region(province, 0);


            // 3) Add the region to the province (a province can also have multiple regions, like islands)
            province.regions = new List<Region>();

            // 4) Add the new country to the map
            int provinceIndex = map.ProvinceAdd(province);
            return provinceIndex;

The call to "RefreshProvinceGeometry" was missing in your code. Reason is that Provinces in the asset are not loaded at the begining. They are loaded and initialized as they're needed (when you pass the mouse over a province for example, the asset checks if the province is loaded and proceeds to initialize it for the first time if needed). This is designed this way because there're +4400 provinces in the geodata files.

In next update that call to "RefreshProvinceGeometry" won't be needed as it will be added directly into the ProvinceAdd method.

Posted by: procedurally
« on: December 04, 2019, 07:39:14 AM »

Posted by: procedurally
« on: December 03, 2019, 07:36:47 AM »

thanks for the answer

            Country country = new Country("Country", "Null", 0);
            Province province = new Province("Province",0, 0);
            Region region = new Region(province, 0);
            int countryIndex = map.ProvinceAdd(province);
I have a problem with this code, the province does not appear
Posted by: Kronnect
« on: December 02, 2019, 11:23:54 AM »

Check out demo scene 105 "Create Map Procedurally" under General Examples. It contains sample code for creating a new country using Vector2 coordinates.
Once you understand how to create a country, creating a province is a similar procedure except it involves using the Province class instead of Country and assigning a Province to a Country through the province.countryIndex property.
Posted by: procedurally
« on: December 02, 2019, 10:22:47 AM »

How to procedurally generate provinces by Vector2?