• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

Board Game Movement 2

Status
Not open for further replies.
Level 3
Joined
Jul 17, 2012
Messages
26
I've made some progress, but I need to figure out how to determine the region for (Target Position for (Triggering Order), so I can make a global variable (integer). If I can do this I can compare My following Global Variables:

Dice1 = Clicked Position - Position of Unit

So, if I can determine the region of the clicked point, then I can do an if/then trigger to set yet another Global Variable as an integer.

I made the position of unit by doing:
If (Any Unit) enters (Region 1), then set Custom Value 1 of (Triggering Unit) = 1
and later (when I needed it)
If Custom Value 1 of (Triggering Unit) = 1, then set "Custom Value of Moving Unit" = 1
"Custom Value of Moving Unit" being a global variable/integer

So, overall I need to turn the click-to-move position into a number based on the region that has been clicked.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,258
If the regions are repeating and regular (all same size and shape), you can use tolerances and rounding to convert points into an integer. This integer could then be fed to a lookup table (an array) to translate it into a different integer (eg, the tile number).

The same approach can be used for irregular regions but requires considerably smaller tolerances (as they define the smallest area).

There is also a final brute force approach that will work for regions of any shape, size and positioning, repeating or not. You put all regions into an array and then perform a linear search to find the first region that contained the point. This is perfectly fine for a small number of regions (<100 would be a sane limit) but the poor scaling of the linear search algorithm means it is not viable for large numbers of regions (>=100 would be a sane limit).

You could combine both approaches for more efficiency. A rough tolerance based lookup to get vaguely which area the press was in and this value can then be used to lookup a list of possible regions in that area which are linearly searched through.

There are also a variety of more complicated space based data structures that you can use to improve lookup efficiency. An example would be quad tree based structures which provide optimum scalability (no linear component). These are not for beginners and should only be considered for performance intensive tasks or if you require huge scalability. For most mapping cases linear search is file.
 
Level 3
Joined
Jul 17, 2012
Messages
26
@ Dr Super Good
My regions are all the same size and they are equally spaced out. I can't figure out how to convert the points into an integer. Is there an action in the trigger editor that will do this?

I also can't figure out how to do the linear search for the brute force approach (I only have about 26 tiles).

You've left me feeling a bit noobish LOL. hopefully you can shed some light on this for me.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,258
SC2 maps run from point 0,0 (bottom left) to X,Y (top right).

Let us say you want to convert an area W wide and H high into N sectors across and M sectors high. The lower left corner of this area is at point AX,AY. The point of interest is at point X,Y.

This means each sector is W/N wide and H/M high. These we will call SW and SH.

1. Encapsulate the entire area into a region. Use this region to filter points that occur outside.
2. Translate the point of interest relative to the area origin. This makes point X-AX,Y-AY. Galaxy supports native point translation using basic mathematical operators if I recall correctly (you subtract the point of interest by the origin of the area).
3. Calculate a X integer for the point of interest. This is done by dividing the X component by SW and taking the floor of that value (round down).
4. Calculate a Y integer for the point of interest. This is done by dividing the Y component by SH and taking the floor of that value (round down).

These 2 integers will have a range of...
X -> 0 to N-1
Y -> 0 to M-1

You may need to catch the special borderline case of if the point of interest is exactly on the top or right borders to prevent an overflow of the range.

You can then use these integers in a 2D array to lookup values such as unit groups, flags etc.
 
Status
Not open for further replies.
Top