Author Topic: Territory Color help  (Read 84 times)

Moutik

  • Newbie
  • *
  • Posts: 9
    • View Profile
Territory Color help
« on: October 29, 2020, 12:14:31 AM »
Hello,

I have an issue about territories color.
If you look at the image attached, you will see that there are two territories: one should be blue and the other red.
Right now 2 weird things happen:
  • The blue background has a weird behavior, not coloring the right territory and coloring half of the red one instead
  • The outer border is incomplete as you can see: it stops at the red territory

Despite the color, the cells are working perfectly.

To create the two territories I use this method:
1/ tgs.numTerritories = 2; + Redraw
2/ I reset + remake the territory:
Code
// reset
        for (int i = 0; i < tgs.cells.Count; i++)
        {
            if (tgs.CellGetTerritoryIndex(i) == 1)
            {
                tgs.CellSetTerritory(i, 0);
            }           
        }
       
        // remake the territory
        if (enemyCells.Count > 0)
        {
            for (int i = 0; i < enemyCells.Count; i++)
            {
                tgs.CellSetTerritory(enemyCells[i], 1);
            }
        }
I have also blocked cells that I want to make not visible:
Code
// Remove blocked cell
        foreach (int i in removedCells)
        {
            tgs.CellSetCanCross(i, false);
            tgs.CellSetGroup(i, 26);
            tgs.CellSetVisible(i, false);
            tgs.CellSetTerritory(i, 0);
        }
        tgs.Redraw();

and finally, I add colors:
Code
Color terColor = new Color32(214, 48, 49, 100);
        Color blueColor = new Color32(9, 132, 227, 100);
        tgs.TerritoryToggleRegionSurface(1, true, terColor);
        tgs.territoryFrontiersColor = blueColor;

        tgs.Redraw();

Everything being in the Start() method. This lead to the behavior I described at the beginning.
Is there something I am missing?

Thanks for your help, I appreciate it!

Kronnect

  • Administrator
  • Hero Member
  • *****
  • Posts: 6345
    • View Profile
Re: Territory Color help
« Reply #1 on: October 29, 2020, 11:25:42 AM »
Territories in TGS are currently limited to one connected surface per territory so if you are assigning scattered cells to the same territory, only a few of them will be colorized because only the first group will be included as part of the territory surface. This is a limitation that should be improved in future versions. The alternative is to not use territories but just color cells to reflect the ownership, so instead of assigning cells to territories, you just color them individually and if you need to keep track to which territory they belong to, you can use the cell.tag property to store that info.
« Last Edit: October 29, 2020, 11:31:54 AM by Kronnect »

Moutik

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Territory Color help
« Reply #2 on: October 29, 2020, 11:50:17 AM »
Ok thanks for your quick answer, very clear.
I created a third territority for the cells I want to remove and it's now working!

Just a quick question: is there a way to change a specific disputed frontier border color?
For instance if I want disputed frontier border color between territories 1 & 2 to be blue (as well as between territories 0 & 2), and disputed frontier border color between 0 & 1 to be red, is there a way to achieve this?
« Last Edit: October 29, 2020, 09:36:54 PM by Kronnect »

Kronnect

  • Administrator
  • Hero Member
  • *****
  • Posts: 6345
    • View Profile
Re: Territory Color help
« Reply #3 on: October 29, 2020, 02:11:24 PM »
Not currently, although it's doable.

Moutik

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Territory Color help
« Reply #4 on: October 29, 2020, 03:18:41 PM »
Alright, I guess I will put all frontier borders with the same colors.
Although it might be a good feature in the future? :)
Thanks for your time!

Kronnect

  • Administrator
  • Hero Member
  • *****
  • Posts: 6345
    • View Profile
Re: Territory Color help
« Reply #5 on: October 30, 2020, 06:27:16 PM »
Hi,

A new method called "TerritoryDrawFrontier" has been added to the API into latest beta.
This method accepts the territoryIndex of the territory to draw its frontier and optionally you can provide another territory index (so it draws only the shared frontier), a material or color. If material or color are missing, the asset will use internal material or default colors.

Regards

Moutik

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: Territory Color help
« Reply #6 on: November 09, 2020, 01:11:37 AM »
Wow amazing!
Just tried it and it's working perfectly as intended.
Thanks for your great support!

Kronnect

  • Administrator
  • Hero Member
  • *****
  • Posts: 6345
    • View Profile
Re: Territory Color help
« Reply #7 on: November 09, 2020, 08:08:30 AM »
You're welcome. Glad it works as expected.
That new method is indeed a very useful and opens new gameplay options.