Ejemplo n.º 1
0
        void Start()
        {
            // UI Setup - non-important, only for this demo
            labelStyle                        = new GUIStyle();
            labelStyle.alignment              = TextAnchor.MiddleLeft;
            labelStyle.normal.textColor       = Color.white;
            labelStyleShadow                  = new GUIStyle(labelStyle);
            labelStyleShadow.normal.textColor = Color.black;

            // setup GUI resizer - only for the demo
            GUIResizer.Init(800, 500);

            // WMSK setup
            map = WMSK.instance;
            map.OnCountryClick += HandleOnCountryClick;
            map.OnCountryEnter += HandleOnCountryEnter;

            // Extra: sample code to enable travelling between 2 disconnected countries Indonesia <-> Australia
            // Allow to travel from Indonesia -> Australia
            Country    indonesia     = map.GetCountry("Indonesia");
            List <int> newNeighbours = new List <int> (indonesia.neighbours);

            newNeighbours.Add(map.GetCountryIndex("Australia"));
            map.GetCountry("Indonesia").neighbours = newNeighbours.ToArray();
            // Do the same in reverse direction Australia -> Indonesia
            Country australia = map.GetCountry("Australia");

            newNeighbours = new List <int> (australia.neighbours);
            newNeighbours.Add(map.GetCountryIndex("Indonesia"));
            map.GetCountry("Australia").neighbours = newNeighbours.ToArray();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Locates coastal points for a sample country and add custom sprites over that line
        /// </summary>
        void FindFranceCoast()
        {
            int            franceIndex = map.GetCountryIndex("France");
            List <Vector2> points      = map.GetCountryCoastalPoints(franceIndex);

            points.ForEach((point) => AddRandomSpriteAtPosition(point));
            if (points.Count > 0)
            {
                map.FlyToLocation(points [0], 2, 0.2f);
            }
        }
Ejemplo n.º 3
0
        private float Map_OnPathFindingCrossPosition(Vector2 position)
        {
            int countryIndex = map.GetCountryIndex(position);
            int ukraine      = map.GetCountryIndex("Ukraine");
            int slovakia     = map.GetCountryIndex("Slovakia");

            if (countryIndex == ukraine || countryIndex == slovakia)
            {
                return(1); // basic cost
            }
            else
            {
                return(2); // increased cost through other countries
            }
        }
Ejemplo n.º 4
0
        void ChangeCountryOwnerShip(float x, float y) {
            int countryIndex = map.GetCountryIndex(new Vector2(x, y));
            if (countryIndex < 0)
                return;
            Country country = map.countries[countryIndex];
            if (country.attrib["player"] == 1) {
                country.attrib["player"] = 2;
            } else {
                country.attrib["player"] = 1;
            }
            UpdatePathFindingMatrixCost();  // need to update cost matrix

            PaintCountries();
            map.BlinkCountry(countryIndex, player1Color, player2Color, 1f, 0.1f);
        }
Ejemplo n.º 5
0
 void MakeClick(float x, float y)
 {
     if (enableClearFogOnClick)
     {
         // Smoothly clear fog at position
         map.FogOfWarIncrement(x, y, -0.25f, 0.075f);
     }
     else if (enableClearFogCountryOnClick)
     {
         // Get country index at position
         Vector2 position     = new Vector2(x, y);
         int     countryIndex = map.GetCountryIndex(position);
         if (countryIndex >= 0)
         {
             // Get fog alpha at position and toggle its state
             float alpha = map.FogOfWarGet(x, y);
             if (alpha > 0)
             {
                 // Fog is visible, clear it on entire country
                 map.FogOfWarSetCountry(countryIndex, 0);
             }
             else
             {
                 // Fog is clear, show it on entire country
                 map.FogOfWarSetCountry(countryIndex, 1);
             }
         }
     }
 }
Ejemplo n.º 6
0
        void PaintCountries()
        {
            // Color some countries to show different cross cost
            List <int> cellsInCountry = map.GetCellsInCountry(map.GetCountryIndex("France"));

            for (int k = 0; k < cellsInCountry.Count; k++)
            {
                map.ToggleCellSurface(cellsInCountry [k], true, new Color(1, 1, 1, 0.25f));
                map.PathFindingCellSetAllSidesCost(cellsInCountry [k], 3);
            }
            cellsInCountry = map.GetCellsInCountry(map.GetCountryIndex("Germany"));
            for (int k = 0; k < cellsInCountry.Count; k++)
            {
                map.ToggleCellSurface(cellsInCountry [k], true, new Color(0, 1, 0, 0.25f));
                map.PathFindingCellSetAllSidesCost(cellsInCountry [k], 2);
            }
        }
Ejemplo n.º 7
0
        // Utility functions called from OnGUI:

        void FlyToCountryAndBlinkIt(string countryName)
        {
            int   countryIndex = map.GetCountryIndex(countryName);
            float fitZoomLevel = map.GetCountryZoomExtents(countryIndex, true);

            map.FlyToCountry(countryIndex, 2.0f, fitZoomLevel);
            map.BlinkCountry(countryName, Color.green, Color.black, 4.0f, 2.5f);
        }
        void ExpandCountry(Region region)
        {
            if (principalCountryIndex < 0 || region == null)
            {
                return;
            }

            // Store principal country id which is immutable - country index will change because the countries array is modified after one country merges another (one of them disappears).
            int    countryUniqueId = map.countries[principalCountryIndex].uniqueId;
            string countryName     = region.entity.name;

            if (map.CountryTransferCountryRegion(principalCountryIndex, region, true))
            {
                // Restore principal id before countries array changed
                SelectPrincipalCountry(map.GetCountryIndex(countryUniqueId));
                Debug.Log("Country " + countryName + " conquered by " + map.countries[principalCountryIndex].name + "!");
            }
        }
Ejemplo n.º 9
0
        IEnumerator TransferProvinces()
        {
            // Reset map
            map.ReloadData();
            map.Redraw();

            // Transfer some German provinces to Poland
            int countryIndex = map.GetCountryIndex("Poland");

            // Step 1: Focus on area of provinces
            map.showProvinces    = true;
            map.drawAllProvinces = true;
            map.FlyToProvince("Germany", "Brandenburg", 1f, 0.04f);
            yield return(new WaitForSeconds(1f));

            // Step 2: Mark provinces
            string[] provincesToTransfer = new string[] {
                "Brandenburg",
                "Mecklenburg-Vorpommern",
                "Sachsen-Anhalt",
                "Sachsen",
                "Thüringen"
            };
            foreach (string provinceName in provincesToTransfer)
            {
                int provinceIndex = map.GetProvinceIndex("Germany", provinceName);
                map.BlinkProvince(provinceIndex, Color.white, Color.red, 2f, 0.15f);
                LineMarkerAnimator lma = map.AddLine(new Vector2[] {
                    map.provinces [provinceIndex].center,
                    map.countries [countryIndex].center
                }, Color.yellow, 1f, 0.15f);
                lma.dashInterval          = 0.0001f;
                lma.dashAnimationDuration = 0.3f;
                lma.drawingDuration       = 2.5f;
                lma.autoFadeAfter         = 0.5f;
                lma.fadeOutDuration       = 0f;
            }
            yield return(new WaitForSeconds(3f));

            // Step 3: transfer some German provinces to Poland
            foreach (string provinceName in provincesToTransfer)
            {
                Province province = map.GetProvince(provinceName, "Germany");
                if (!map.CountryTransferProvinceRegion(countryIndex, province.mainRegion, false))
                {
                    Debug.LogError("Could not transfer province " + provinceName + " to Poland.");
                }
            }
            map.Redraw();

            // End

            map.FlyToCountry("Poland", 1f, 0.04f);
            map.BlinkCountry("Poland", Color.white, Color.green, 2f, 0.15f);

            Debug.Log("Done.");
        }
Ejemplo n.º 10
0
        /// <summary>
        /// Populate the provinces dropdown with names
        /// </summary>
        void PopulateProvinces(string countryName)
        {
            int           countryIndex = map.GetCountryIndex(countryName);
            List <string> provinces    = new List <string>();

            provinces.AddRange(map.GetProvinceNames(countryIndex, false));

            provincesDropdown.ClearOptions();
            provincesDropdown.AddOptions(provinces);
        }
Ejemplo n.º 11
0
        void Start()
        {
            map = WMSK.instance;

            int    USAIndex = map.GetCountryIndex("United States of America");
            Region region   = map.GetCountry(USAIndex).mainRegion;

            map.RegionGenerateExtrudeGameObject("Extruded USA", region, 1f, Color.gray);

            map.FlyToCountry(USAIndex, 4f, 0.2f);
        }
Ejemplo n.º 12
0
        void Start()
        {
            // Get a reference to the World Map API:
            map = WMSK.instance;

            // Color and add outline to Algeria
            int countryIndex = map.GetCountryIndex("Algeria");

            map.ToggleCountrySurface(countryIndex, true, new Color(1, 1, 1, 0.25f));
            map.ToggleCountryOutline(countryIndex, true, borderTexture, 0.5f, Color.gray);

            // Color and add outline to Niger
            countryIndex = map.GetCountryIndex("Niger");
            map.ToggleCountrySurface(countryIndex, true, new Color(0, 1, 0, 0.25f));
            map.ToggleCountryOutline(countryIndex, true, borderTexture, 0.5f, Color.green);

            // Merge three country regions and add a common border (Spain + France + Germany)
            DrawOutline();

            // Zoom into the zone
            map.FlyToCountry(countryIndex, 0, 0.3f);
        }
Ejemplo n.º 13
0
        void CheckEvents()
        {
            if (map == null)
            {
                return;
            }
            int countryIndex = -1;

            if (OnCountryEnter != null || map.OnVGOCountryEnter != null)
            {
                countryIndex = map.GetCountryIndex(_currentMap2DLocation);
                if (countryIndex != lastCountryIndex)
                {
                    lastCountryIndex = countryIndex;
                    if (countryIndex >= 0)
                    {
                        if (OnCountryEnter != null)
                        {
                            OnCountryEnter(this);
                        }
                        if (map.OnVGOCountryEnter != null)
                        {
                            map.BubbleEvent(map.OnVGOCountryEnter, this);
                        }
                    }
                }
            }
            if (OnProvinceEnter != null)
            {
                int provinceIndex = map.GetProvinceIndex(_currentMap2DLocation, countryIndex);
                if (provinceIndex != lastProvinceIndex)
                {
                    lastProvinceIndex = provinceIndex;
                    if (provinceIndex >= 0)
                    {
                        if (OnProvinceEnter != null)
                        {
                            OnProvinceEnter(this);
                        }
                        if (map.OnVGOProvinceEnter != null)
                        {
                            map.BubbleEvent(map.OnVGOProvinceEnter, this);
                        }
                    }
                }
            }
        }
Ejemplo n.º 14
0
        /// <summary>
        /// This function is hooked at Start() function and will be called when user clicks on a cell
        /// </summary>
        /// <param name="cellIndex">Cell index.</param>
        /// <param name="button">Mouse button index.</param>
        void CellClicked(int cellIndex, int button)
        {
            // if cell already is contained by country then cancel
            Vector2 cellCenter = map.GetCellPosition(cellIndex);
            int     c          = map.GetCountryIndex(cellCenter);

            if (c == countryIndex)
            {
                return;
            }

            // Transfer cell to the country shape
            map.CountryTransferCell(countryIndex, cellIndex, true);             // true = redraw

            // Recolor the country so any new separated region gets the same color
            map.ToggleCountrySurface(countryIndex, true, countryColor);
        }
        void Start()
        {
            // Get a reference to the World Map API:
            map = WMSK.instance;

            // UI Setup - non-important, only for this demo
            labelStyle                         = new GUIStyle();
            labelStyle.alignment               = TextAnchor.MiddleCenter;
            labelStyle.normal.textColor        = Color.white;
            labelStyleShadow                   = new GUIStyle(labelStyle);
            labelStyleShadow.normal.textColor  = Color.black;
            buttonStyle                        = new GUIStyle(labelStyle);
            buttonStyle.alignment              = TextAnchor.MiddleLeft;
            buttonStyle.normal.background      = Texture2D.whiteTexture;
            buttonStyle.normal.textColor       = Color.white;
            sliderStyle                        = new GUIStyle();
            sliderStyle.normal.background      = Texture2D.whiteTexture;
            sliderStyle.fixedHeight            = 4.0f;
            sliderThumbStyle                   = new GUIStyle();
            sliderThumbStyle.normal.background = Resources.Load <Texture2D>("GUI/thumb");
            sliderThumbStyle.overflow          = new RectOffset(0, 0, 8, 0);
            sliderThumbStyle.fixedWidth        = 20.0f;
            sliderThumbStyle.fixedHeight       = 12.0f;

            // setup GUI resizer - only for the demo
            GUIResizer.Init(800, 500);

            // Listen to map events
            map.OnClick += (float x, float y, int buttonIndex) => {
                if (autoExpand)
                {
                    return;
                }
                if (buttonIndex == 0)
                {
                    int countryIndex = map.GetCountryIndex(new Vector2(x, y));
                    SelectPrincipalCountry(countryIndex);
                }
                else
                {
                    Region region = map.GetCountryRegion(new Vector2(x, y));
                    ExpandCountry(region);
                }
            };
        }
Ejemplo n.º 16
0
 public void FlyToAustralia()
 {
     FlyToCountry(map.GetCountryIndex("Australia"));
 }
Ejemplo n.º 17
0
        void OnGUI()
        {
            // Do autoresizing of GUI layer
            GUIResizer.AutoResize();

            switch (state)
            {
            case 0:
                if (GUI.Button(new Rect(10, 10, 160, 30), "Merge North America", buttonStyle))
                {
                    int countryUSA    = map.GetCountryIndex("United States of America");
                    int countryCanada = map.GetCountryIndex("Canada");
                    map.CountryTransferCountry(countryUSA, countryCanada, true);

                    countryUSA = map.GetCountryIndex("United States of America");
                    int countryMexico = map.GetCountryIndex("Mexico");
                    map.CountryTransferCountry(countryUSA, countryMexico, true);
                    state++;
                }
                break;

            case 1:
                if (GUI.Button(new Rect(10, 10, 160, 30), "Save Current Frontiers", buttonStyle))
                {
                    SaveAllData();
                    state++;
                                        #if UNITY_EDITOR
                    EditorUtility.DisplayDialog("Saved Data", "Data stored in temporary variables. You can now click reset frontiers to simulate a game restart and then Load Saved Data to restore the saved data.", "Ok");
                                        #endif
                }
                break;

            case 2:
                if (GUI.Button(new Rect(10, 10, 160, 30), "Reset Frontiers", buttonStyle))
                {
                    map.ReloadData();
                    map.Redraw();
                    state++;
                }
                break;

            case 3:
                if (GUI.Button(new Rect(10, 10, 160, 30), "Load Saved Data", buttonStyle))
                {
                    LoadAllData();
                    state++;
                                        #if UNITY_EDITOR
                    EditorUtility.DisplayDialog("Data Loaded!", "Data has been loaded from the temporary variables.", "Ok");
                                        #endif
                }
                break;

            case 4:
                if (GUI.Button(new Rect(10, 50, 160, 30), "Reset Frontiers", buttonStyle))
                {
                    map.ReloadData();
                    map.Redraw();
                    state = 0;
                }
                break;
            }
        }
Ejemplo n.º 18
0
        void FlyToCountry(string countryName)
        {
            int countryIndex = map.GetCountryIndex(countryName);

            FlyToCountry(countryIndex);
        }
        void UpdateProvinces()
        {
            WMSK map = WMSK.instance;

            if (committingProgress < 0.1f)
            {
                committingStatus   = "Refreshing province borders...";
                committingProgress = 0.25f;
            }
            else if (committingProgress < 0.3f)
            {
                newProvinces = ti.GetProvinces();
                if (additive)
                {
                    for (int k = 0; k < newProvinces.Length; k++)
                    {
                        map.ProvinceAdd(newProvinces [k]);
                    }
                }
                else
                {
                    map.provinces = newProvinces;
                }
                map.editor.provinceChanges = true;
                for (int k = 0; k < map.provinces.Length; k++)
                {
                    map.ProvinceSanitize(k, 5);
                }
                committingProgress = 0.4f;
            }
            else if (committingProgress < 0.5f)
            {
                committingStatus   = "Linking provinces to existing countries...";
                committingProgress = 0.6f;
            }
            else if (committingProgress < 0.7f)
            {
                // Update provinces references
                List <Province> newProvinces = new List <Province> (map.provinces.Length);
                for (int k = 0; k < map.provinces.Length; k++)
                {
                    Province prov = map.provinces [k];
                    if (prov.regions == null || prov.regions.Count == 0)
                    {
                        continue;
                    }
                    prov.regions [0].UpdatePointsAndRect(prov.regions [0].points);                      // compute rect2D and center
                    int countryIndex = map.GetCountryIndex(prov.regions [0].center);
                    if (countryIndex < 0)
                    {
                        // Check first point
                        countryIndex = map.GetCountryIndex(prov.regions [0].points [0]);
                        if (countryIndex < 0)
                        {
                            Debug.Log("Province #" + k + " has no enclosing country. Skipping.");
                            continue;
                        }
                    }
                    prov.countryIndex = countryIndex;
                    newProvinces.Add(prov);
                }
                map.provinces = newProvinces.ToArray();
                // Update country provinces
                newProvinces.Clear();
                for (int k = 0; k < map.countries.Length; k++)
                {
                    newProvinces.Clear();
                    for (int p = 0; p < map.provinces.Length; p++)
                    {
                        if (map.provinces [p].countryIndex == k)
                        {
                            newProvinces.Add(map.provinces [p]);
                        }
                    }
                    map.countries [k].provinces = newProvinces.ToArray();
                }
                committingProgress = 0.8f;
            }
            else if (committingProgress < 0.9f)
            {
                committingStatus   = "Refreshing other dependencies...";
                committingProgress = 0.95f;
            }
            else
            {
                // Update city references
                int citiesCount = map.cities.Length;
                for (int k = 0; k < citiesCount; k++)
                {
                    City city          = map.cities [k];
                    int  provinceIndex = map.GetProvinceIndex(city.unity2DLocation);
                    if (provinceIndex >= 0)
                    {
                        Province prov = map.provinces [provinceIndex];
                        if (!city.province.Equals(prov.name))
                        {
                            city.province          = prov.name;
                            city.countryIndex      = prov.countryIndex;
                            map.editor.cityChanges = true;
                        }
                    }
                    else if (city.province.Length > 0)
                    {
                        city.province          = "";
                        map.editor.cityChanges = true;
                    }
                }

                // Update mount points references
                int mpCount = map.mountPoints.Count;
                for (int k = 0; k < mpCount; k++)
                {
                    MountPoint mp            = map.mountPoints [k];
                    int        provinceIndex = map.GetProvinceIndex(mp.unity2DLocation);
                    if (provinceIndex >= 0)
                    {
                        if (mp.provinceIndex != provinceIndex)
                        {
                            mp.provinceIndex             = provinceIndex;
                            map.editor.mountPointChanges = true;
                        }
                    }
                    else
                    {
                        map.mountPoints.RemoveAt(k);
                        map.editor.mountPointChanges = true;
                        k--;
                        mpCount--;
                    }
                }
                committingProgress = 1f;
            }
        }
        void UpdateCountries()
        {
            WMSK map = WMSK.instance;

            if (committingProgress < 0.1f)
            {
                committingStatus   = "Refreshing country frontiers...";
                committingProgress = 0.25f;
            }
            else if (committingProgress < 0.3f)
            {
                newCountries = ti.GetCountries();
                if (additive)
                {
                    for (int k = 0; k < newCountries.Length; k++)
                    {
                        map.CountryAdd(newCountries [k]);
                    }
                }
                else
                {
                    map.countries = newCountries;
                }
                map.editor.countryChanges = true;
                for (int k = 0; k < map.countries.Length; k++)
                {
                    map.CountrySanitize(k, 5);
                }
                committingProgress = 0.4f;
            }
            else if (committingProgress < 0.5f)
            {
                committingStatus   = "Refreshing provinces...";
                committingProgress = 0.6f;
            }
            else if (committingProgress < 0.7f)
            {
                // Update provinces references
                List <Province> newProvinces = new List <Province> (map.provinces.Length);
                for (int k = 0; k < map.provinces.Length; k++)
                {
                    Province prov = map.provinces [k];
                    if (prov.regions == null)
                    {
                        map.ReadProvincePackedString(prov);
                        if (prov.regions == null)
                        {
                            prov.center = new Vector2(-1000, -1000);
                        }
                    }
                    int countryIndex = map.GetCountryIndex(prov.center);
                    if (countryIndex < 0)
                    {
                        // Province deleted/ignored
                        map.editor.provinceChanges = true;
                    }
                    else if (prov.countryIndex != countryIndex)
                    {
                        prov.countryIndex          = countryIndex;
                        map.editor.provinceChanges = true;
                        newProvinces.Add(prov);
                    }
                }
                map.provinces = newProvinces.ToArray();
                // Update country provinces
                newProvinces.Clear();
                for (int k = 0; k < map.countries.Length; k++)
                {
                    newProvinces.Clear();
                    for (int p = 0; p < map.provinces.Length; p++)
                    {
                        if (map.provinces [p].countryIndex == k)
                        {
                            newProvinces.Add(map.provinces [p]);
                        }
                    }
                    map.countries [k].provinces = newProvinces.ToArray();
                }
                committingProgress = 0.8f;
            }
            else if (committingProgress < 0.9f)
            {
                committingStatus   = "Refreshing other dependencies...";
                committingProgress = 0.95f;
            }
            else
            {
                // Update city references
                int         citiesCount = map.cities.Length;
                List <City> cities      = new List <City>(map.cities);
                for (int k = 0; k < citiesCount; k++)
                {
                    City city         = cities [k];
                    int  countryIndex = map.GetCountryIndex(city.unity2DLocation);
                    if (countryIndex >= 0)
                    {
                        if (city.countryIndex != countryIndex)
                        {
                            city.countryIndex      = countryIndex;
                            map.editor.cityChanges = true;
                        }
                    }
                    else
                    {
                        cities.RemoveAt(k);
                        map.editor.cityChanges = true;
                        k--;
                        citiesCount--;
                    }
                }
                map.cities = cities.ToArray();

                // Update mount points references
                if (map.mountPoints != null)
                {
                    int mpCount = map.mountPoints.Count;
                    for (int k = 0; k < mpCount; k++)
                    {
                        MountPoint mp           = map.mountPoints [k];
                        int        countryIndex = map.GetCountryIndex(mp.unity2DLocation);
                        if (countryIndex >= 0)
                        {
                            if (mp.countryIndex != countryIndex)
                            {
                                mp.countryIndex = countryIndex;
                                map.editor.mountPointChanges = true;
                            }
                        }
                        else
                        {
                            map.mountPoints.RemoveAt(k);
                            map.editor.mountPointChanges = true;
                            k--;
                            mpCount--;
                        }
                    }
                }
                committingProgress = 1f;
            }
        }
Ejemplo n.º 21
0
 public WorldMapStrategyKit.Country GenericToMapCountry(WPM.Country country)
 {
     return(_WMSK.GetCountry(_WMSK.GetCountryIndex(country.name)));
 }
Ejemplo n.º 22
0
        //void ExpandProvince (Region region) {
        //				if (principalProvinceIndex < 0 || region == null)
        //								return;

        //				// Store principal province id which is immutable - province index will change because the provinces array is modified after one province merges another (one of them disappears).
        //				int provinceUniqueId = map.provinces [principalProvinceIndex].uniqueId;
        //				string provinceName = region.entity.name;

        //				if (map.ProvinceTransferProvinceRegion (principalProvinceIndex, region, true)) {
        //								// Restore principal id before provinces array changed
        //								SelectPrincipalProvince (map.GetProvinceIndex (provinceUniqueId));
        //								Debug.Log ("Province " + provinceName + " conquered by " + map.provinces [principalProvinceIndex].name + "!");
        //				}
        //}

        void ExpandProvince(Region region)
        {
            int countryIndex = map.GetCountryIndex("Sweden");

            map.CountryTransferProvinceRegion(countryIndex, region, true);
        }