Author Topic: Artifact regions after territory transfer  (Read 200 times)

fluqe

  • Newbie
  • *
  • Posts: 10
    • View Profile
Artifact regions after territory transfer
« on: October 05, 2021, 08:55:48 PM »
When some countries transfer a province to another country, they maintain tiny regions around the border of their former province. It appears like a visual artifact of the old border when the country is highlighted. Sanitizing both countries sometimes helps, but only partially.

In the editor, the problem can be solved pretty easily by removing the regions, but when transferring provinces during game with e.g. CountryTransferProvince it can be more of an issue.

Reproduction examples:
  • Demo 103, eastern German provinces. Examine Germany in Map Editor after clicking Transfer Provinces Demo button. Artifact regions are created (regions 11-25 and 27). Some are faintly visible in game mode when highlighting Germany
  • Slovakia - give Prešov (3548) and Žilinský (3543) to Czech Republic. Slovakia retains artifact regions on northern border of lost provinces
  • Vietnam - give southern provinces to Cambodia (forms artifacts on coast) or a new country (forms artifacts on coast and on Cambodian border)


Kronnect

  • Administrator
  • Hero Member
  • *****
  • Posts: 7565
    • View Profile
Re: Artifact regions after territory transfer
« Reply #1 on: October 05, 2021, 09:03:25 PM »
Hi,

I'll check that example, thanks.

You may want to try the CountrySetProvinces method instead. This method directly assigns the desired provinces to a country and updates the regions. This method can be a bit slower than transferring a single province but should be  more robust because there's no polygon substraction operation involved. Instead, the regions of the country are discarded and then replaced by the union of all regions of the given provinces. Additionally CountryRemoveProvinces and CountryAddProvinces do similar things.

Note that when using CountrySetProvinces, you have to pass ALL the provinces you want the country to contain because any existing region will be discarded.


fluqe

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: Artifact regions after territory transfer
« Reply #2 on: October 05, 2021, 10:55:23 PM »
Thanks!

FWIW I love CountryTransferProvince for the ease of use.

I tried using CountrySetProvinces, just tested by creating East Germany out of Germany on a fresh project. Have an issue where both countries now are split by highlighted black border lines. Also, a regular green border between the countries didn't appear.



Code
public void CreateEastGermanyButton()
    {
        map.CountryCreate("East Germany", "Europe");
        int newCountryCode = map.GetCountryIndex("East Germany");

        List<Province> newProvinces = new List<Province>();
        Province testProv = map.GetProvince(800);
        newProvinces.Add(testProv);
        testProv = map.GetProvince(801);
        newProvinces.Add(testProv);
        testProv = map.GetProvince(802);
        newProvinces.Add(testProv);
        testProv = map.GetProvince(803);
        newProvinces.Add(testProv);
        testProv = map.GetProvince(804);
        newProvinces.Add(testProv);
        testProv = map.GetProvince(794);
        newProvinces.Add(testProv);

        map.CountrySetProvinces (newCountryCode, newProvinces, true, true, true);
        map.CountryRemoveProvinces (57, newProvinces, true);

        map.Redraw();
}

Kronnect

  • Administrator
  • Hero Member
  • *****
  • Posts: 7565
    • View Profile
Re: Artifact regions after territory transfer
« Reply #3 on: October 06, 2021, 05:03:10 PM »
I have reproduced the transfer issue and it occurs because the country map has some differences with the provinces map. This is the reason some isolated fragments of land remain when executing the polygon substraction of the province to the country shape. It will be fixed in next update.

fluqe

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: Artifact regions after territory transfer
« Reply #4 on: October 07, 2021, 08:19:08 AM »
Yay, thank you so much!

Kronnect

  • Administrator
  • Hero Member
  • *****
  • Posts: 7565
    • View Profile
Re: Artifact regions after territory transfer
« Reply #5 on: October 07, 2021, 01:42:50 PM »
Ok, some improvements landed into beta 4.

The CountrySetProvinces which uses internally MergeAdjacentRegions is now fixed. Due to a bug in this internal function, not all provinces were correctly merged. Now this method should work as expected.
This method is also used in a new option called "Rebuild Countries Frontiers from Provinces" which is very useful when making changes to the provinces. This ensures the countries frontiers match perfectly the provinces borders. For polygon operations, this is critical.

This option can be found in the Map Editor gear icon:


I have not included the updated map into the beta so you will need to execute this option and save the changes. Reason is that I want to verify the results in terms of accuracy and size before releasing such changes to the countries map.


fluqe

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: Artifact regions after territory transfer
« Reply #6 on: October 07, 2021, 09:11:29 PM »
Thanks for the fast update, this is fantastic!

Fyi CountrySetProvinces still does not create a new country border when forming a country out of separatist provinces. However, using CountryTransferProvince afterwards will make the border appear. Which would be ok as a workaround but unfortunately it wouldn't work for single-province countries.

Kronnect

  • Administrator
  • Hero Member
  • *****
  • Posts: 7565
    • View Profile
Re: Artifact regions after territory transfer
« Reply #7 on: October 07, 2021, 10:31:09 PM »
What do you mean by "separatist provinces"?

Do you first create an empty country and then transfer a province? Or do you create a new country directly from a province using the ProvinceToCountry method?


Kronnect

  • Administrator
  • Hero Member
  • *****
  • Posts: 7565
    • View Profile
Re: Artifact regions after territory transfer
« Reply #8 on: October 08, 2021, 08:11:04 PM »
I tried this code using latest beta and it works fine:

Code
   
                List<Province> provinces = new List<Province>();
                provinces.Add(map.GetProvince("Cádiz", "Spain"));
                provinces.Add(map.GetProvince("Málaga", "Spain"));

               Country country = new Country("New Spain", "Europe", 0);
                int countryIndex = map.CountryAdd(country);
                map.CountrySetProvinces(countryIndex, provinces);
                map.CountryRemoveProvinces(map.GetCountryIndex("Spain"), provinces);
                map.Redraw(true);

The code above adds those two provinces to a new country and also updates the provinces of Spain by setting all provinces except those two (that's what CountryRemoveProvinces does).

fluqe

  • Newbie
  • *
  • Posts: 10
    • View Profile
Re: Artifact regions after territory transfer
« Reply #9 on: October 08, 2021, 11:06:08 PM »
Thanks for confirming that!

Sorry I was trying to post my code but it kept triggering the spam filter.

The problem was that I did map.Redraw(); instead of map.Redraw(true);

It is working now :)
« Last Edit: October 08, 2021, 11:50:10 PM by fluqe »