| 10-03-2007, 01:08 PM | #1 |
Alrighty, i'm trying to make a system which randomly generates buildings for little villages. Now what i can do is take a point and start making buildings at random points around my start point, the problem is that sometimes buildings end up inside of each other. If i stick in a check to see if the new point is too close to a previous point, that's fine, but it will only check once, and it's fairly likely that some of the points after this check will end up inside another point. So what i need is some way to loop indefinitely, checking the points until i find a location which does not have any other points near it. Normally i'd just use a loop or while function, but i don't believe WCIII has those? |
| 10-03-2007, 01:21 PM | #2 |
Um... how about storing the points and not deleting them until the end, or using a system of dummy units and then seeing if they are too close together or something? The dummy units would be easier but not quite optimal (as far as I know). |
| 10-03-2007, 01:25 PM | #3 |
Here's my crack at it. I assume you have a wait command in your loop, or are using the periodic timer event to space out building placement. First make 2 array variables with a limit capped at the max # of buildings you want to place. These two variables will be X and Y coordinates. Now when you run the loop, have a tempcount global variable that will tell you the number of times you have placed a building. When a building is placed, set the coordinates to BuildingX[tempcount] and BuildingY[tempcount]. Before you place the building, make a loop within the loop that will check if your randomly generated point is too close to one you've already done. This can be done by making a loop that uses a counting variable for said loop and compares your random X and Y to udg_BuildingX[countingvariable] and udg_BuildingY[countingvariable]. If the points are too close, it will generate a new point. I would write out a JASS example, but I'd be late for class. |
| 10-03-2007, 04:53 PM | #4 |
The way I would do it is create a regular grid of sufficiently spaced points and shuffle out N of them as building locations. If you don't want your buildings to be on a regular grid, then randomly displace each point a bit. Regardless you most certainly can loop, either using the loop ... endloop statements or recursion. Read some JASS tutorials. |
| 10-03-2007, 07:04 PM | #5 |
Give us your triggers/map so we can really give it a good try! |
| 10-03-2007, 10:11 PM | #6 | |
Quote:
??? http://jass.sourceforge.net/doc/statements.shtml |
| 10-03-2007, 10:19 PM | #8 |
Ohh sorry didn't realize you were using GUI. Maybe to get the while-loop effect you could just use the "For each integer variable, do multiple actions" action, and set the variable back to 0 each time, until you want it to exit. Then set it to whatever the end value is. Not sure if you can do that but I think you can. |
| 10-04-2007, 06:56 AM | #12 |
There is the function GetTerrainType(...) which will return an integer id for the type of tile there (Lordaeron Dirt is 'Ldrt'). I would assume that the ids for all the other tiles can be found in some SLK file somewhere (though I'm not sure where it would be), and the only other way to get them would to be to convert the following condition to custom text and see what it's compared to: Trigger: Conditions![]() (Terrain type at (Center of (Playable map area))) Equal to Lordaeron Summer - Dirt |
