So the setup I have is just a plain 96,96 map. I have two regions: A and B. A is 8,96 (x,y) in size and runs vertically. B is 96,8 in size and runs horizontally. They intersect in the middle of the map and the intersection is an area of 8,8 in size.
I'm trying to figure out how to make it so that if a unit enters this intersection, the game knows it. So, to the game it would be a new region, AB. I can sort of do this already, but it would take way too many if,then,else statements. I'm looking for a small, clever solution.
It doesn't matter if it's through script, triggers, etc. I'm actually going to head on over the scripting forums and start looking there.
This is the one thing I want to try. Say I have a global table of all possible integer X values for A (since it runs vertically) and all possible integer Y values for B (since it runs horizontally) in regards to their position on the map.
For example, since the map is 96,96 and A runs vertically and has an X size of 8, the integer range for X would be {44,45,46,47,48,49,50,51,52}, where 48 is the center point.
I'm guessing all I would need to do is when the unit enters a region (it doesn't matter what the event is right now), I check the unit's X value with the table for A's integer X values. I'm just not sure how.
Why X values for A and Y values for B? Because Y range for A is 0-96 and X range for B is 0-96. It is only a problem when there are multiple vertical and/or horizontal regions. And I intend to have several.
Well, as I said before...I'm going to have several of these. So think the entire map. Do I really want to make 144 8,8 regions?
Instead of using 144 8,8 regions, I was thinking of using 12 vertical and 12 horizontal regions and have their intersections make up the 144 regions I need.
So more or less a 8,8 grid for the entire map.
Edit: Unless you guys think that having 144 regions would be a more optimized way to go about it.
Seems like your best bet to me would be to write a custom function to procedurally generate all the regions for you since you know where they need to be. You could have a 2 dimensional region array to store the intersections and write a loop that loops from 0 to 12, (or 0 to 11 depending on how exactly youre defining the intersections, basically however many there are) then another loop inside that one that loops the same. Then in the innermost loop calculate the new region position based on say i and j (the loop counters), then use something like convert rectangle to region based on those variables and a hard coded width/height and set the Regions[i][j] = to that region. Now you have 144 regions with a few lines of code and can use them in your triggers. Also if you didnt mind using circles you could make it slightly simpler and make the array points instead of regions and store a single point for each intersection then use the trigger unit enters within X of point[][].
Not sure exactly how you would set up the triggers in a nice way using the array, since i havent played around with triggers much yet, but im sure there is a solution like above where you could write a minimal amount of code to handle it all, im not sure.
Rollback Post to RevisionRollBack
To post a comment, please login or register a new account.
So the setup I have is just a plain 96,96 map. I have two regions: A and B. A is 8,96 (x,y) in size and runs vertically. B is 96,8 in size and runs horizontally. They intersect in the middle of the map and the intersection is an area of 8,8 in size.
I'm trying to figure out how to make it so that if a unit enters this intersection, the game knows it. So, to the game it would be a new region, AB. I can sort of do this already, but it would take way too many if,then,else statements. I'm looking for a small, clever solution.
It doesn't matter if it's through script, triggers, etc. I'm actually going to head on over the scripting forums and start looking there.
This is the one thing I want to try. Say I have a global table of all possible integer X values for A (since it runs vertically) and all possible integer Y values for B (since it runs horizontally) in regards to their position on the map.
For example, since the map is 96,96 and A runs vertically and has an X size of 8, the integer range for X would be {44,45,46,47,48,49,50,51,52}, where 48 is the center point.
I'm guessing all I would need to do is when the unit enters a region (it doesn't matter what the event is right now), I check the unit's X value with the table for A's integer X values. I'm just not sure how.
Why X values for A and Y values for B? Because Y range for A is 0-96 and X range for B is 0-96. It is only a problem when there are multiple vertical and/or horizontal regions. And I intend to have several.
Make a 3rd region that covers the area of the overlapping two would be way easier..
^ You're thinking way too hard about it, just make an additional region in the center :P
Well, as I said before...I'm going to have several of these. So think the entire map. Do I really want to make 144 8,8 regions?
Instead of using 144 8,8 regions, I was thinking of using 12 vertical and 12 horizontal regions and have their intersections make up the 144 regions I need.
So more or less a 8,8 grid for the entire map.
Edit: Unless you guys think that having 144 regions would be a more optimized way to go about it.
@immor7a1: Go
I don't know if it's most efficient to do it with 144 regions, but It'd sure as heck be easier to read.
@kaji2: Go
Seems like your best bet to me would be to write a custom function to procedurally generate all the regions for you since you know where they need to be. You could have a 2 dimensional region array to store the intersections and write a loop that loops from 0 to 12, (or 0 to 11 depending on how exactly youre defining the intersections, basically however many there are) then another loop inside that one that loops the same. Then in the innermost loop calculate the new region position based on say i and j (the loop counters), then use something like convert rectangle to region based on those variables and a hard coded width/height and set the Regions[i][j] = to that region. Now you have 144 regions with a few lines of code and can use them in your triggers. Also if you didnt mind using circles you could make it slightly simpler and make the array points instead of regions and store a single point for each intersection then use the trigger unit enters within X of point[][].
Not sure exactly how you would set up the triggers in a nice way using the array, since i havent played around with triggers much yet, but im sure there is a solution like above where you could write a minimal amount of code to handle it all, im not sure.