Exemple #1
0
    void Start()
    {
        WMSK       map = WMSK.instance;
        Vector3    pos = map.GetCountry("France").center;
        GameObject go  = Instantiate(sprite);

        map.AddMarker2DSprite(go, pos, 0.01f);
    }
Exemple #2
0
    public bool shareLandBorder(Nation first, Nation second)
    {
        int     firstIndex     = first.getIndex();
        Country firstIndexMap  = map.GetCountry(firstIndex);
        int     secondIndex    = second.getIndex();
        Country secondIndexMap = map.GetCountry(secondIndex);

        List <Country> neighbours = map.CountryNeighboursOfMainRegion(firstIndex);

        if (neighbours.Contains(secondIndexMap))
        {
            return(true);
        }
        else
        {
            return(false);
        }
    }
    public void ApplyScenarioDataToMap()
    {
        string nationsPath = Application.dataPath +
                             "/StreamingAssets/Scenarios/" + scenario + "/Nations";
        string provincesPath = Application.dataPath +
                               "/StreamingAssets/Scenarios/" + scenario + "/Provinces";

        string[] provFiles = Directory.GetFiles(provincesPath, "*.json");
        foreach (string file in provFiles)
        {
            string dataAsJson  = File.ReadAllText(file);
            var    newProvince = Newtonsoft.Json.JsonConvert.DeserializeObject <assemblyCsharp.Province>
                                     (dataAsJson);
            //  Debug.Log("Prov quality size" + newProvince.quality[0]);
            provinces.Add(newProvince.getIndex(), newProvince);
            map.GetProvince(newProvince.getIndex()).name        = newProvince.getProvName();
            map.GetProvince(newProvince.getIndex()).customLabel = newProvince.getProvName();
        }

        string[] nationFiles = Directory.GetFiles(nationsPath, "*.json");
        foreach (string file in nationFiles)
        {
            string dataAsJson = File.ReadAllText(file);
            var    newNation  = Newtonsoft.Json.JsonConvert.DeserializeObject <assemblyCsharp.Nation>(dataAsJson);

            nations.Add(newNation.getIndex(), newNation);
            Debug.Log("Nation Name: " + newNation.getNationName());
            Debug.Log("Nation's Capital " + newNation.capital);

            // Debug.Log("Nation Name: " + newNation.getNationName());
            //   Debug.Log("Number of Provinces " + newNation.getAllProvinceIndexes().Count);
            map.GetCountry(newNation.getIndex()).name        = newNation.getNationName();
            map.GetCountry(newNation.getIndex()).customLabel = newNation.getNationName();
            map.CountryRename("Country" + newNation.getIndex(), newNation.getNationName());
            for (int i = 0; i < newNation.getProvinces().Count; i++)
            {
                int provIndex = newNation.getProvinces()[i];
                WorldMapStrategyKit.Province prov = map.GetProvince(provIndex);
                prov.countryIndex = newNation.getIndex();
            }
        }
    }
        void ColorizeFrance()
        {
            Country country = map.GetCountry("France");

            for (int p = 0; p < country.provinces.Length; p++)
            {
                Color color         = new Color(Random.Range(0.0f, 1.0f), Random.Range(0.0f, 1.0f), Random.Range(0.0f, 1.0f));
                int   provinceIndex = map.GetProvinceIndex(country.provinces[p]);
                map.ToggleProvinceSurface(provinceIndex, true, color);
            }
        }
 // Use this for initialization
 void Start()
 {
     map.OnProvinceEnter += (int provinceIndex, int regionIndex) => Debug.Log("Entered province " + map.provinces [provinceIndex].name + " , owned by " + map.GetCountry(map.provinces [provinceIndex].countryIndex).name);
     map.OnProvinceExit  += (int provinceIndex, int regionIndex) => Debug.Log("Exited province " + map.provinces [provinceIndex].name);
     map.OnProvinceClick += (int provinceIndex, int regionIndex, int buttonIndex) =>
     {
         Debug.Log("Clicked province " + map.provinces[provinceIndex].name);
         canvasState.ProvinceSelected = new ProvinceIdentifier()
         {
             Province = map.provinces[provinceIndex].name, Nation = map.GetCountry(map.provinces[provinceIndex].countryIndex).name
         };
     };
 }
Exemple #6
0
 public bool DoesCountryExist(string country)
 {
     return(_map.GetCountry(country) != null);
 }
        void Start()
        {
            WMSK map = WMSK.instance;

            // ***********************************************************************
            // Adding custom attributes to a country (same for provinces, cities, ...)
            // ***********************************************************************

            Country canada = map.GetCountry("Canada");

            canada.attrib["Language"]         = "French";                                       // Add language as a custom attribute
            canada.attrib["ConstitutionDate"] = new DateTime(1867, 7, 1);                       // Add the date of British North America Act, 1867
            canada.attrib["AreaKm2"]          = 9984670;                                        // Add the land area in km2

            // List example
            List <int> values = new List <int>(10);

            for (int j = 0; j < 10; j++)
            {
                values.Add(j);
            }
            canada.attrib["List"] = JSONObject.FromArray(values);

            // ******************************************************
            // Obtain attributes and print them out over the console.
            // ******************************************************

            Debug.Log("Language = " + canada.attrib["Language"]);
            Debug.Log("Constitution Date = " + canada.attrib["ConstitutionDate"].d);                    // Note the use of .d to force cast the internal number representation to DateTime
            Debug.Log("Area in km2 = " + canada.attrib["AreaKm2"]);
            Debug.Log("List = " + canada.attrib["List"]);

            // *********************************************************
            // Now, look up by attribute example using lambda expression
            // *********************************************************

            List <Country> countries = map.GetCountries(
                (attrib) => "French".Equals(attrib["Language"]) && attrib["AreaKm2"] > 1000000
                );

            Debug.Log("Matches found = " + countries.Count);
            foreach (Country c in countries)
            {
                Debug.Log("Match: " + c.name);
            }

            // *****************************************************************
            // Export/import individual country attributes in JSON format sample
            // *****************************************************************

            string json = canada.attrib.Print();                // Get raw jSON

            Debug.Log(json);

            canada.attrib = new JSONObject(json);               // Import from raw jSON
            int keyCount = canada.attrib.keys.Count;

            Debug.Log("Imported JSON has " + keyCount + " keys.");
            for (int k = 0; k < keyCount; k++)
            {
                Debug.Log("Key " + (k + 1) + ": " + canada.attrib.keys[k] + " = " + canada.attrib[k]);
            }

            // *****************************************************************
            // Finally, export all countries attributes in one single JSON file
            // *****************************************************************

            string jsonCountries = map.GetCountriesXMLAttributes(true);                 // get the complete json for all countries with attributes

            Debug.Log(jsonCountries);

            canada.attrib = null;
            map.SetCountriesXMLAttributes(jsonCountries);                                               // parse the jsonCountries string (expects a jSON compliant string) and loads the attributes
            Debug.Log("Canada's attributes restored: Lang = " + canada.attrib["Language"] + ", Date = " + canada.attrib["ConstitutionDate"].d + ", Area = " + canada.attrib["AreaKm2"]);
        }
Exemple #8
0
    public void SelectProvince(int provinceIndex, int regionIndex, CountryToGlobalCountry.GenericProvince SelectedProvince)
    {
        //  wmslObj.getpr
        // GameProvinceInfoPanel.SetActive(true);


        var cm = new CountryToGlobalCountry();

        gameObject.SetActive(true);
        var controlLevel = 100f;

        if (GameMapManager.SelectedCountryManager != null)
        {
            SelectedProvince = GameMapManager.SelectedCountryManager.CountryGovernment.ControlsProvincesNames.FirstOrDefault(e => e.index == provinceIndex && e.countryIndex == regionIndex);
            //Player controls this province
            //wmslObj.FlyToProvince(provinceIndex, 3f, ZoomChange);
            if (SelectedProvince == null)
            {
                var selectedProvince = wmslObj.provinces[provinceIndex];
                var newProvince      = new CountryToGlobalCountry.GenericProvince(selectedProvince.name);
                newProvince.index        = selectedProvince.uniqueId;
                newProvince.countryIndex = regionIndex;
                newProvince.location.x   = selectedProvince.center.x;
                newProvince.location.y   = selectedProvince.center.y;
                SelectedProvince         = newProvince;
                GameMapManager.SelectedCountryManager.CountryGovernment.ControlsProvincesNames.Add(newProvince);
                ProvinceControllingFlag.texture = SelectedProvince.flagowner;
                // helpers.LoadFlagFromCountryName(selectedProvince.countryIndex);
            }
        }
        else
        {
            var selectedProvince = wmslObj.provinces[provinceIndex];
            //check if the player owns this or if it exists in the list of known provinces
            var gameManager          = FindObjectOfType <GameManager>();
            var playerCountryManager = gameManager.GameWorldManager.CountryPlayerManagerGameObject.GetComponentInChildren <CountryManager>();
            ProvinceMilitary.text = GetTotalMilitaryInProvince(playerCountryManager, selectedProvince.uniqueId);
            if (playerCountryManager.CountryProvinceControlList.Count > 0)
            {
                SelectedProvince = playerCountryManager.CountryProvinceControlList.FirstOrDefault(e => e.index == selectedProvince.uniqueId);
                if (SelectedProvince != null)
                {
                    SelectedProvince.ProvinceCities = playerCountryManager.CountryCityControlList.Where(e => e.provinceName == selectedProvince.name).ToList();
                    controlLevel = playerCountryManager.CountryProvinceControlList.FirstOrDefault(e => e.index == selectedProvince.uniqueId).ProvinceControl;
                }
            }
            else if (gameManager.GameWorldManager.CountryAIManagerGameObject != null && SelectedProvince == null)
            {
                //check if the AI provinces exists
                var AICountryManagers = gameManager.GameWorldManager.CountryAIManagerGameObject.GetComponents <CountryManager>().ToList();
                if (SelectedProvince == null && AICountryManagers != null)
                {
                    SelectedProvince = AICountryManagers.FirstOrDefault(e =>
                                                                        e.CountryGovernment.CountryOfGovernment.index == selectedProvince.countryIndex).CountryProvinceControlList.FirstOrDefault(prov =>
                                                                                                                                                                                                  prov.index == selectedProvince.uniqueId);
                    controlLevel = AICountryManagers.FirstOrDefault(e =>
                                                                    e.CountryGovernment.CountryOfGovernment.index == selectedProvince.countryIndex).CountryProvinceControlList.FirstOrDefault(prov =>
                                                                                                                                                                                              prov.index == selectedProvince.uniqueId).ProvinceControl;
                    SelectedProvince.ProvinceCities = AICountryManagers.FirstOrDefault(e =>
                                                                                       e.CountryGovernment.CountryOfGovernment.index == selectedProvince.countryIndex).CountryCityControlList.Where(prov =>
                                                                                                                                                                                                    prov.index == selectedProvince.uniqueId).ToList();
                    ProvinceMilitary.text = GetTotalMilitaryInProvince(AICountryManagers.FirstOrDefault(e =>
                                                                                                        e.CountryGovernment.CountryOfGovernment.index == selectedProvince.countryIndex), selectedProvince.uniqueId);
                }
            }

            if (SelectedProvince == null)
            {
                //it doesn't exit in the game yet so lets check from the seed data
                SelectedProvince = playerCountryManager.CountryGovernment.ControlsProvincesNames.FirstOrDefault(province => province.index == selectedProvince.uniqueId && province.countryIndex == selectedProvince.countryIndex);
                if (SelectedProvince == null)
                {
                    var listOfCities = wmslObj.cities.Where(e => e.countryIndex == selectedProvince.countryIndex && e.province == selectedProvince.name);
                    //it doesn't exist so add it to the world list temporary
                    var newProvince = cm.RandomProvince(listOfCities, selectedProvince, playerCountryManager.CountryGovernment);
                    newProvince.index        = selectedProvince.uniqueId;
                    newProvince.countryIndex = selectedProvince.countryIndex;
                    newProvince.location.x   = selectedProvince.center.x;
                    newProvince.location.y   = selectedProvince.center.y;
                    newProvince.name         = selectedProvince.name;
                    SelectedProvince         = newProvince;

                    ProvinceNoIntel.gameObject.SetActive(true);
                    ProvinceNoSpyNetwork.gameObject.SetActive(true);
                    ProvinceNoActiveTerrorGroups.gameObject.SetActive(true);
                    ProvinceIncomeText.text    = "Unknown.";
                    ProvinceInfastructure.text = "Unknown.";
                    ProvinceMilitary.text      = "Unknown.";
                }
            }
        }

        if (SelectedProvince != null)
        {
            ProvinceNameText.text          = SelectedProvince.name;
            ProvinceCountryText.text       = wmslObj.GetCountry(SelectedProvince.countryIndex).name;
            ProvinceRuleOfLaw.Value        = provinceRuleOfLaw = (int)SelectedProvince.provinceRuleOfLaw;
            ProvinceHumanSecurity.Value    = provinceHumanSecurity = (int)SelectedProvince.provinceHumanSecurity;
            ProvinceEconomicActivity.Value = provinceEconomicDevelopment = (int)SelectedProvince.provinceEconomicDevelopment;
            ProvinceCulturalValue.Value    = provinceCulturalValue = (int)SelectedProvince.provinceCulturalValue;
            CityTotal.text      = GetTotalCities(SelectedProvince.ProvinceCities);
            PopulationText.text = string.Format("{0} people", SelectedProvince.population);
        }

        gameObject.SetActive(true);
        // provinceUI.PopulationText.text = string.Format("{0:n0}", SelectedProvince.population);
        // SetPanelsByModeOnClick();
    }