Cities API
advanced scriptingWorld Map Strategy Kit · Scripting Support (C#)
WMSK (namespace WorldMapStrategyKit)
Cities API
Methods and properties for working with cities on the map.
Properties
City[] citiesArray of all cities on the map.
City cityHighlighted { get; }The city currently under the pointer (null if none).
int cityHighlightedIndex { get; }Index of the highlighted city (-1 if none).
int cityLastClicked { get; }Index of the last clicked city.
bool showCities { get; set; }Show or hide city icons on the map.
Color citiesColor { get; set; }Default color for city icons.
int minPopulation { get; set; }Minimum population for a city to be displayed.
Color citiesRegionCapitalColorGlobal color for region capitals.
Color citiesCountryCapitalColorGlobal color for country capitals.
float cityIconSizeThe size of the cities icon (dot).
GameObject citySpotAllows you to change default icon for normal cities. This must be a 2D game object (you may duplicate and modify city prefabs in WMSK/Resources/Prefabs folder).
GameObject citySpotCapitalRegionAllows you to change default icon for region capitals. This must be a 2D game object (you may duplicate and modify city prefabs in WMSK/Resources/Prefabs folder).
GameObject citySpotCapitalCountryAllows you to change default icon for country capitals. This must be a 2D game object (you may duplicate and modify city prefabs in WMSK/Resources/Prefabs folder).
int maxCitiesPerCountryGets or sets the max cities per country.
int cityClassAlwaysShowFlags for specifying the class of cities to always show irrespective of other filters like minimum population. Can assign a combination of bit flags defined by CITY_CLASS_FILTER*
string cityAttributeFileGets or sets the city attribute file.
Query Methods
City GetCity(string cityName, string countryName = "")Returns a city by name. Optionally specify the country for disambiguation if multiple cities share the same name.
City GetCity(int cityIndex)Returns a city by index.
int GetCityIndex(string cityName, int countryIndex = -1)Returns the index of a city, optionally filtered by country.
int GetCityIndex(Vector2 localPosition)Returns the index of the nearest city to a map position.
City GetCityRandom()Returns a random city from the map.
City GetCityRandom(Country country)Returns a random city from a specific country.
City GetCityRandom(Province province)Returns a random city from a specific province.
List<City> GetCities(Country country, bool onlyVisible = false)Returns all cities in a country. If onlyVisible is true, only returns cities meeting the minimum population threshold.
List<City> GetCities(Province province)Returns all cities in a province.
List<City> GetVisibleCities()Returns cities currently visible in the viewport.
Manipulation Methods
void CityAdd(City newCity)Adds a new city to the map. The City object must have valid name, countryIndex, and unity2DLocation fields.
bool CityDelete(int cityIndex)Deletes a city from the map. Returns true if successful.
void CityMove(int cityIndex, Vector2 newPosition)Moves a city to a new map position.
Effects
void BlinkCity(int cityIndex, Color color1, Color color2, float duration, float blinkingSpeed)Applies a blinking animation to a city icon, alternating between two colors.
void SetCityIconScale(int cityIndex, float scale)Changes the display scale of a city icon.
Additional Methods
void CitiesDeleteFromContinent(string continentName)Deletes all cities of current selected country's continent
bool FlyToCity(string cityName, string countryName)Starts navigation to target city. Returns false if not found.
bool FlyToCity(string cityName, string countryName, float duration)Starts navigation to target city with duration provided. Returns false if not found.
bool FlyToCity(string cityName, string countryName, float duration, float zoomLevel)Starts navigation to target city. with specified duration and zoom level, ignoring NavigationTime property. Set duration to zero to go instantly. Returns false if city is not found.
void FlyToCity(int cityIndex)Starts navigation to target city by index in the cities collection.
void FlyToCity(int cityIndex, float duration)Starts navigation to target city by index with provided duration
void FlyToCity(int cityIndex, float duration, float zoomLevel)Starts navigation to target city by index with provided duration and zoom level
void FlyToCity(City city, float duration, float zoomLevel)Starts navigation to target city by passing a City object with provided duration and zoom level
int GetCityIndexRandom(Country country)Gets a random city index from a given country The city random. Country object.
int GetCityIndexRandom(Province province)Gets a random city index from a given province The city random. Province object.
string GetCityCountryName(City city)Gets the name of the country of the city.
string GetCityProvinceName(City city)Gets the name of the province of the city.
Vector2 GetCityPosition(int cityIndex)Returns the position of a city
Vector2 GetCityPosition(string cityName, string countryName)Returns the position of a city
void HideCityHighlights()Clears any city highlighted (color changed) and resets them to default city color
int GetCountryCapitalIndex(int countryIndex)Returns the index of the country's capital city in the cities array The country capital index. Country index.
int GetCountryCapitalIndex(string countryName)Returns the index of the country's capital city in the cities array The country capital index. Country name.
City GetCountryCapital(int countryIndex)Returns the country's capital city The country capital index. Country index.
City GetCountryCapital(string countryName)Returns the country's capital city The country capital index. Country name.
void ToggleCityHighlight(int cityIndex, Color color, bool highlighted)Toggles the city highlight. City index. Color. If set to true the color of the city will be changed. If set to false the color of the city will be reseted to default color
string[] GetCityNames()Returns an array with the city names.
string[] GetCityNames(int countryIndex)Returns an array with the city names.
string GetCitiesGeodata()Exports the geographic data in packed string format.
void SetCitiesGeodata(string s)Loads cities information from a string
string GetCitiesAttributes(bool prettyPrint)Gets XML attributes of all cities in jSON format.
string GetCitiesAttributes(List cities, bool prettyPrint)Gets XML attributes of provided cities in jSON format.
void SetCitiesAttributes(string jSON)Sets cities attributes from a jSON formatted string.
string GetCitiesDataJSON(bool prettyPrint)Exports the cities data in jSON format.
void SetCitiesDataJSON(string s)Loads cities information from a jSON string
byte[] GetCitiesGeodataBinary()Exports the geographic data in binary format.
void SetCitiesGeodataBinary(byte[] data)Loads cities information from a binary array
Suggest an improvement
Help us improve this documentation page.