• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

How can I set rally points to nearest region with a trigger?

Status
Not open for further replies.
Level 3
Joined
May 24, 2008
Messages
27
How can I set rally points to the buildings nearest region with a trigger?

Unit - A unit Finishes construction


(Unit - Order (Triggering unit) to Set Rally Point To (Position of (???)))
???
 
Level 6
Joined
Feb 23, 2010
Messages
222
There may be an alternate way to accomplish your goal.

Such as using any kind of destructible or invisible unit or a bunch of things.

What is it this trigger will accomplish?
 
Level 3
Joined
May 24, 2008
Messages
27
it totally will help me and let me explain.
I'm making a defense game. You controll a peasant that goes around and builds things when you tell it to.
Creeps come out because I told the game to automaticly train the units at the structure the peasants make once constructed. Enemy units walk around on a spiraling brick path untill they attack the middle but are smart enough to combat units on their path.

I want each building to set its rally point onto the path (which I have just placed regions for this all over the path). I want the buildings near the paths to automaticly set a rally point onto its nearest region so that the units that are trained will move onto the path, once trained.
 
Level 3
Joined
Jun 3, 2010
Messages
28
  • Rally Point
    • Events
      • Unit - A unit Finishes construction
    • Conditions
    • Actions
      • Unit - Set Rally Point of (Triggering Unit) to (Center of (Region1))
Set region1 as where you want the Rally Point to be.
Actually I'm not really sure what your explanation meant at all. LOL.

Creeps come out because I told the game to automaticly train the units at the structure the peasants make once constructed.

Sentence does not make any sense.
 
Level 6
Joined
Feb 23, 2010
Messages
222
Hm im not sure how to do it exactly- but i have an idea... if you make a trigger that assigns all buildings in a region to a specific group. Than make that specific group assign a rally point to a location that makes sense. It would work.
 
Level 3
Joined
May 24, 2008
Messages
27
  • Rally Point
    • Events
      • Unit - A unit Finishes construction
    • Conditions
    • Actions
      • Unit - Set Rally Point of (Triggering Unit) to (Center of (Region1))
Set region1 as where you want the Rally Point to be.
Actually I'm not really sure what your explanation meant at all. LOL.



Sentence does not make any sense.


no, read
 
Level 3
Joined
May 24, 2008
Messages
27
This is still unresolved, look here
w1.png


w2.png


The green squares in this next pic are the regions. I want the rally points to automaticly become set to its buildings nearest green square region
as soon as the building's built.
w3.png
 

Dr Super Good

Spell Reviewer
Level 63
Joined
Jan 18, 2005
Messages
27,192
Well, as far as I know its impossible cause regions comprise of multiple rects and cells which may or may not be clustered together and so there is no way to get a single closest point. Additionally regions midpoints (if they have any) may not fall inside the bounds of region objects cause the area making of the region need not be next to each other.

However if you are using rects as shown in the screenshot and want to get the nearest mid point of a rect to a point, that is rather simple.

You firstly generate a list of all the midpoints of valid rects from which it is to be able to choose. For effeciency I adivise using a pair of reals representing X and Y vector components. Thats really all the setup thats needed.

To get the closest rect midpoint, you simply loop through all enteries in the list and using simple mathimatics get the distance between that point and the point you are comparing from. To find the closest you simply store the index of which ever has shorter distance to it than the current index (a min search algerthim).

By a list, I mean arrays where the elements are stored consecutivly from index 0 or 1 to how ever many elements there are so that a loop will go over no emptry space.

Not the most efficent but still works and should display no noticable latency to the player due to the brute processing capabilities of computers.

More efficent would be to pre calculate for vast areas of the map the only possible closest points to them meaning that the distance to only 1 or 2 points need be checked instead of all points. This however is a lot more complicated to do and will use more memory but use less processing power for large numbers of points. For this I would look into using hashtables to breakthe game world into largish squares which can be referenced by a range of position cordinits. Each square then points to 1 or more points considered to be close enough that they can appear as a closest point inside the square. This method would need a lot more pre processing and the complexity means it would only be worth it if used multiple times a second on huge numbers of points compared to the previous method.
 
Status
Not open for further replies.
Top