Provinces API

advanced scripting

World Map Strategy Kit · Scripting Support (C#)

Class: WMSK (namespace WorldMapStrategyKit)

Provinces API

Methods and properties for working with provinces (states/regions within countries).

Properties

Province[] provinces

Array of all provinces on the map.

Province provinceHighlighted { get; }

The province currently under the pointer (null if none).

int provinceHighlightedIndex { get; }

Index of the highlighted province (-1 if none).

int provinceLastClicked { get; }

Index of the last clicked province.

bool showProvinces { get; set; }

Show or hide province borders.

bool showProvinceNames { get; set; }

Show or hide province name labels.

bool enableProvinceHighlight { get; set; }

Enable or disable province highlighting on hover.

Color provincesFillColor { get; set; }

Default fill color for province surfaces.

enum PROVINCE_LABELS_VISIBILITY

Gets or sets the p r o v i n c e_ l a b e l s_ v i s i b i l i t y.

Region provinceRegionHighlighted

Returns currently highlighted province's region.

int provinceRegionHighlightedIndex

Returns current highlighted province's region index.

int provinceRegionLastClicked

Returns the last clicked province region index.

GameObject provinceRegionHighlightedShape

Gets the province region's highlighted shape.

int provinceLastOver

Returns the last hovered province.

int provinceRegionLastOver

Returns the last hovered province region index.

bool highlightAllProvinceRegions

Gets or sets the highlight all province regions.

bool highlightProvinceKeepTexture

Gets or sets the highlight province keep texture.

bool drawAllProvinces

Forces drawing of all provinces and not only thouse of currently selected country.

bool provincesDashBorders

Use a dash line style when drawing province borders.

float provincesDashAmount

Controls the dash appearance.

Color provincesColor

Gets or sets the provinces color.

string provinceAttributeFile

Gets or sets the province attribute file.

bool provincesCoastlines

Gets or sets the provinces coastlines.

bool showAllCountryProvinceNames

Gets or sets the show all country province names.

PROVINCE_LABELS_VISIBILITY provinceLabelsVisibility

Gets or sets the province labels visibility.

float provinceLabelsAbsoluteMinimumSize

Gets or sets the province labels absolute minimum size.

float provinceLabelsSize

Gets or sets the province labels size.

bool provinceLabelsEnableAutomaticFade

Automatic fading of province labels depending on camera distance and label screen size

float provinceLabelsAutoFadeMaxHeight

Max height of a label relative to screen height (0..1) at which fade out starts

float provinceLabelsAutoFadeMaxHeightFallOff

Fall off for fade labels when height is greater than min height

float provinceLabelsAutoFadeMinHeight

Min height of a label relative to screen height (0..1) at which fade out starts

float provinceLabelsAutoFadeMinHeightFallOff

Fall off for fade labels when height is less than min height

bool showProvinceLabelsShadow

Draws a shadow under province labels. Specify the color using labelsShadowColor.

Color provinceLabelsColor

Color for province labels.

Color provinceLabelsShadowColor

Color for province labels.

Vector2 provinceLabelsShadowOffset

Shadow offset for province labels

Font provinceLabelsFont

Gets or sets the default font for province labels

Query Methods

Province GetProvince(int provinceIndex)

Returns a Province by index.

Province GetProvince(string provinceName, int countryIndex)

Returns a Province by name within a specific country.

Province GetProvince(string provinceName, string countryName)

Returns a Province by name and country name.

int GetProvinceIndex(Vector2 localPosition)

Returns the province at a given map position.

Province[] GetProvinces(int countryIndex)

Returns all provinces belonging to a country.

List<Province> ProvinceNeighbors(int provinceIndex)

Returns neighboring provinces (sharing a border).

List<Province> GetVisibleProvinces()

Returns provinces currently visible in the viewport.

Province GetProvinceRandom(int countryIndex = -1)

Returns a random province, optionally restricted to a specific country.

Manipulation Methods

bool ProvinceRename(int countryIndex, string oldName, string newName)

Renames a province within a country.

bool ProvinceDelete(int provinceIndex, bool redraw = true)

Deletes a province from the map.

bool CountryTransferProvince(int targetCountryIndex, int provinceIndex, bool redraw = true)

Transfers a province to another country.

int ProvinceCreate(string provinceName, int countryIndex)

Creates a new province within a country and returns its index.

Surface & Effects

GameObject ToggleProvinceMainRegionSurface(int provinceIndex, bool visible, Color color)

Toggles the surface of a province's main region. Returns the surface GameObject.

GameObject ToggleProvinceRegionSurface(int provinceIndex, int regionIndex, bool visible, Color color)

Toggles a specific province region surface.

void BlinkProvince(int provinceIndex, Color color1, Color color2, float duration, float blinkingSpeed)

Applies a blinking animation to a province, alternating between two colors.

void HideProvinceSurface(int provinceIndex)

Hides all surfaces for a province.

void HideProvinceSurfaces()

Hides all province surfaces on the entire map.

Additional Methods

bool DrawProvinces(int countryIndex, bool includeNeighbors, bool forceRefresh, bool justComputeBorders)

Draws the borders of the provinces/states a country by its id. Returns true is country is found, false otherwise.

void HideProvinces()

Hides the borders of all provinces/states.

bool ValidProvinceIndex(int provinceIndex)

Returns true if the provinceIndex is valid (ie. within province array range)

bool ValidProvinceRegionIndex(int provinceIndex, int regionIndex)

Returns true if the countryIndex and regionIndex are valid (ie. within province and province regions array range)

int GetProvinceRegionIndex(Vector2 localPosition, out int regionIndex)

Gets the index of the province that contains the provided map coordinates. This will ignore hidden countries. The province index. Map coordinates in the range of (-0.5 .. 0.5) The index of the province region

int GetProvinceRegionIndex(Vector2 localPosition)

Gets the region index of the province that contains the provided map coordinates. The Region index or -1 if no region found. Map coordinates in the range of (-0.5 .. 0.5)

int GetProvinceRegionIndex(int provinceIndex, Region region)

Gets the index of the province region. The province region index. Province index. Region.

bool GetProvinceRegionIndex(Vector2 localPosition, int countryIndex, out int provinceIndex, out int provinceRegionIndex)

Gets the index of the province and region that contains the provided map coordinates. This will ignore hidden countries.

Region GetProvinceRegion(Vector2 localPosition)

Gets the region of the province that contains the provided map coordinates. The province region. Map coordinates in the range of (-0.5 .. 0.5)

List ProvinceNeighborsOfMainRegion(int provinceIndex)

Get neighbors of the main region of a province

List ProvinceNeighborsOfCurrentRegion()

Get neighbors of the currently selected region

List ProvinceNeighborsOfRegion(Region provinceRegion)

Get neighbors of a given province region

int ProvinceAdd(Province province)

Adds a new province which has been properly initialized. Used by the Map Editor. Name must be unique. Index of new province.

int ProvinceToCountry(Province province, string newCountryName, bool redraw)

Creates a new country from an existing province. Existing province will be extracted from previous sovereign. Returns the index of the new country. The new country index or -1 if failed.

int ProvincesToCountry(List provinces, string newCountryName, bool redraw)

Creates a new country from a list of existing provinces. Existing provinces will be extracted from previous sovereign. Returns the index of the new country. The new country index or -1 if failed.

int ProvincesToCountry(List provinces, string newCountryName, string continent, bool redraw)

Creates a new country from a list of existing provinces. Existing provinces will be extracted from previous sovereign. Returns the index of the new country. The new country index or -1 if failed.

bool FlyToProvince(string countryName, string provinceName)

Starts navigation to target province/state. Returns false if not found.

bool FlyToProvince(int provinceIndex)

Starts navigation to target province/state by index in the provinces collection. Returns false if not found.

bool FlyToProvince(string countryName, string provinceName, float duration, float zoomLevel)

Starts navigation to target province/state by name in the provinces collection with duration and zoom level options. Returns false if not found.

bool FlyToProvince(int provinceIndex, float duration, float zoomLevel)

Starts navigation to target province/state by index in the provinces collection with duration and zoom level options. Returns false if not found.

void ToggleProvinceSurface(int provinceIndex, bool visible, Color color))

Colorize all regions of specified province/state by index in the global provinces collection.

void ToggleProvinceSurface(Province province, bool visible, Color color))

Colorize all regions of specified province/state by index in the global provinces collection.

void ToggleProvinceSurface(Province province, bool visible, Texture2D texture, bool applyTextureToAllRegions)

Colorize all regions of specified province and assigns a texture to main region with options.

void ToggleProvinceSurface(Province province, bool visible, Color color, Texture2D texture, bool applyTextureToAllRegions)

Colorize all regions of specified province and assigns a color and texture to main region with options.

void ToggleProvinceSurface(int provinceIndex, bool visible, Color color, Texture2D texture, bool applyTextureToAllRegions)

Colorize all regions of specified province and assigns a texture to main region with options.

void ToggleProvinceSurface(int provinceIndex, bool visible, Color color, Texture2D texture, Vector2 textureScale, Vector2 textureOffset, float textureRotation, bool applyTextureToAllRegions)

Colorize all regions of specified province and assigns a texture to main region with options.

GameObject ToggleProvinceRegionSurfaceHighlight(int provinceIndex, int regionIndex, Color color)

Highlights the province region specified. Internally used by the Editor component, but you can use it as well to temporarily mark a province region. Pass true only if you're sure you want to force refresh the geometry of the highlight (for instance, if the frontiers data has changed). If you're unsure, pass false.

void HideProvinceRegionHighlights(bool destroyCachedSurfaces)

Disables all province regions highlights. This doesn't destroy custom materials.

void HideProvinceRegionSurface(int provinceIndex, int regionIndex)

Hides all regions of one province.

string[] GetProvinceNames(bool groupByCountry, bool addProvinceIndex)

Returns an array of province names. The returning list can be grouped by country.

string[] GetProvinceNames(int countryIndex, bool addProvinceIndex)

Returns an array of province names for the specified country.

List GetProvincesOverlap(Region region)

Gets a list of provinces that overlap with a given region

List GetProvinceRegionsOverlap(Region region)

Gets a list of provinces regions that overlap with a given region

void ProvincesDeleteOfSameContinent(string continentName)

Delete all provinces from specified continent. This operation does not include dependencies.

List GetVisibleProvincesInWindowRect()

Returns a list of provinces that are visible inside the window rectangle (constraint rect)

Vector2 GetProvinceCenter(int provinceIndex)

Returns the center of the province

Vector2 GetProvinceCentroid(int provinceIndex)

Returns the centroid of the province

Vector2 GetProvinceCentroid(Province province)

Returns the centroid of the province

List GetProvinceCoastalPoints(int provinceIndex, float minDistance)

Returns the list of coastal positions of a given province

List GetProvinceBorderPoints(int provinceIndex1, int provinceIndex2, int extraWidth)

Returns a list of common border points between two provinces. Index of the first province Index of the second province Use extraWidth to widen the points, useful when using the result to block pass in pathfinding

Vector3[] GetProvinceBorderPoints(int provinceIndex, bool worldSpace)

Returns the points for the given province region. Optionally in world space coordinates (normal map, not viewport).

Vector3[] GetProvinceBorderPoints(int provinceIndex, int regionIndex, bool worldSpace)

Returns the points for the given province region. Optionally in world space coordinates (normal map, not viewport).

float GetProvinceRegionZoomExtents(int provinceIndex)

Returns the zoom level required to show the entire province region on screen The province zoom level of -1 if error. Province index.

float GetProvinceRegionZoomExtents(int provinceIndex, int regionIndex)

Returns the zoom level required to show the entire province region on screen The province zoom level of -1 if error. Country index. Region index of the country.

float GetProvinceZoomExtents(int provinceIndex)

Returns the zoom level required to show the entire province (including all regions) on screen The province zoom level of -1 if error. Province index.

bool ProvinceSanitize(int provinceIndex, int minimumPoints, bool refresh)

Checks quality of province's polygon points. Useful before using polygon clipping operations. true, if province was changed, false otherwise.

bool ProvinceTransferProvinceRegion(int provinceIndex, Region sourceProvinceRegion, bool redraw)

Makes provinceIndex absorb another province providing any of its regions. All regions are transfered to target province. This function is quite slow with high definition frontiers. Province index of the conquering province. Source region of the losing province. If set to true, map will be redrawn after operation finishes.

bool ProvinceTransferCell(int provinceIndex, int cellIndex, bool redraw)

Makes provinceIndex absorb an hexagonal portion of the map. If that portion belong to another province, it will be subtracted from that province as well. This function is quite slow with high definition frontiers. Province index of the conquering province. Index of the cell to add to the province.

bool ProvinceRemoveCell(int provinceIndex, int cellIndex, bool redraw)

Removes a cell from a province. Province index. Index of the cell to remove from the province.

GameObject GetProvinceRegionSurfaceGameObject(int provinceIndex, int regionIndex, bool forceCreation)

Returns the colored surface (game object) of a province. If it has not been colored yet, it will generate it.

void DrawProvinceLabels(int countryIndex, Color color))

Draws the labels for the provinces of a given country Country.

void DrawProvinceLabels(Country country, Color color))

Draws the labels for the provinces of a given country Country. Color override for the province labels

void DrawProvinceLabels(string countryName, Color color))

Draws the labels for the provinces of a given country Name of country. Color override for the province labels

void HideProvinceLabels()

Hides all province labels

string GetProvincesGeodata()

Exports the geographic data in packed string format.

void SetProvincesGeodata(string s)

SetProvincesGeodata method.

byte[] GetProvincesGeodataBinary()

Exports the geographic data in binary format.

void SetProvincesGeodataBinary(byte[] data)

SetProvincesGeodataBinary method.

string GetProvincesAttributes(bool prettyPrint)

Gets XML attributes of all provinces in jSON format.

string GetProvincesAttributes(List provinces, bool prettyPrint)

Gets XML attributes of provided provinces in jSON format.

void SetProvincesAttributes(string jSON)

Sets provinces attributes from a jSON formatted string.

int ImportProvincesColorMap(string filename)

Analizes and generate new countries based on a color map The provinces color map. Tex.

string GetProvincesDataJSON(bool prettyPrint)

Returns province data (geodata and any attributes) in jSON format.

void SetProvincesDataJSON(string json)

Sets province data (geodata and attributes) from a jSON string.

Was this page helpful?