HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Possible to spawn units closest to gold mine?

01-18-2008, 07:17 AM#1
vhx
Is it possible to spawn units to the closest mine of the player start location? Similar to how the "Create <Race> starting units at a location" trigger where it makes the building, then kind of spawns the 5 other units close to the gold mine. I mean I know it would be possible to offset the position based on another unit's location, but that will only work for 1 of the locations, the other two locations will make them messed up.

I imagine this wouldn't be hard to do if it was one location. However if you have several player spawns with several gold mines where the spawn place is random, I would think you can't do it. Is this trigger possible?
01-18-2008, 07:28 AM#2
MaD[Lion]
everything is trigger possible almost :P Many ways to do this, but i cant think of a smart way yet
01-18-2008, 11:38 AM#3
Troll-Brain
i think the best way is to ckeck the distance beetween each mine owned by a player and his location, and then take the closest
01-18-2008, 06:59 PM#4
vhx
Quote:
Originally Posted by Troll-Brain
i think the best way is to ckeck the distance beetween each mine owned by a player and his location, and then take the closest
This is something I was thinking as well. Perhaps check all the gold mines distance, then just pick whichever is the closest range and spawn at that mine. Seems quite the complicated trigger, not sure how to go about checking distance nor calculating the other things.

I will look into this later.
01-18-2008, 07:07 PM#5
xombie
Quote:
Originally Posted by vhx
This is something I was thinking as well. Perhaps check all the gold mines distance, then just pick whichever is the closest range and spawn at that mine. Seems quite the complicated trigger, not sure how to go about checking distance nor calculating the other things.

In GUI I'm pretty sure there is already a function for finding the distance, but the distance between two coordinates is:

Root( (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2) )

Picking every goldmine in the map is also simple, as long as you know the unit-type of the goldmine, for instance:

Pick every unit of type goldmine.
Pick every player start location.

Compare the distances between each start location and each goldmine, and choose the one with the smallest distance.
01-18-2008, 07:39 PM#6
Troll-Brain
it's not so complicated.
Read my example in this thread : http://wc3campaigns.net/showthread.php?t=98640

It's not exactly the same thing, but the method is the same.
01-19-2008, 11:22 AM#7
vhx
After I pick every gold mine unit, how exactly do I return the coordinates of each of these? Would I have to create a check for each gold mine or is it possible to just use one function to return all of the values?

It doesn't seem like the coordinate functions won't allow me to select a unit group or even a unit type. Any further help would be appreciative.
01-19-2008, 08:34 PM#9
Troll-Brain
Had you read the link ?
01-23-2008, 12:38 AM#10
vhx
I read the link and still don't get it. I have no regions setup, this doesn't apply here.

I thought maybe it would be easier to set regions in the start locations and then if it's in a certain region spawn it on a certain side... however there seems to be no condition for location checks or region checks. I hope this is wrong... why would there be no location check triggers in a map editor? ;O
01-23-2008, 01:32 AM#11
TaintedReality
Maybe I'm misunderstanding you, but what's so hard about this? Just get all the goldmines nearby and find the closest one.
01-23-2008, 08:39 AM#12
Troll-Brain
of course you don't need regions, use locations instead.
But the method to know which distance is the closest is still the same
01-23-2008, 10:51 PM#13
vhx
Quote:
Originally Posted by TaintedReality
Maybe I'm misunderstanding you, but what's so hard about this? Just get all the goldmines nearby and find the closest one.
I am unfamiliar with a lot of the triggers in the editor which is why it's more complicated for me. I can pick all of the gold mines for sure, but the rest is a little more complicated for me.

What I ended up doing was just put regions on the gold mines. Then once the building is spawned at a specific region, I had the other units spawn closer to a region. This seems a little messy as I can't really adjust it for other maps, and would have to do it manually again.
01-23-2008, 11:37 PM#14
xombie
Trigger:
Untitled Trigger 001
Events
Condition
Collapse Actions
Collapse Unit Group - Pick every unit in (Units of type Gold Mine) and do (Actions)
Collapse Loop - Actions
Set Loc[0] = (Position of (Picked unit))
Collapse For each (Integer A) from 1 to 12, do (Actions)
Collapse Loop - Actions
Set Loc[1] = ((Player((Integer A))) start location)
Set Distance[((Integer A) - 1)] = (Distance between Loc[0] and Loc[1])

That is the code for calculating the distance between gold-mines, you will have to tweak it a little bit to get it to do what you want - does this make it any more clear?
01-24-2008, 05:08 PM#15
vhx
Thanks for the response. I did get this far before, as far as calculating, the main problem was, it spit out over 16 results... there are only 12 mines. Which didn't make much sense so I got rid of that.

Also I don't know how to set the position of the unit with the smallest distance or set the specific mine that has the smallest distance.

I have had the flu so this is the last thing I have been thinking about. Bleh after messing with this for 2 hours (just today) I am done. Although just having the regions setup and stuff is a lot less inefficient, it's definitely less headache than this. Thanks to all the people who tried to help me here.