• 🏆 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!
  • 🏆 Hive's 6th HD Modeling Contest: Mechanical is now open! Design and model a mechanical creature, mechanized animal, a futuristic robotic being, or anything else your imagination can tinker with! 📅 Submissions close on June 30, 2024. Don't miss this opportunity to let your creativity shine! Enter now and show us your mechanical masterpiece!🔗 Click here to enter!

Pick every units in (Units in angled rectangle)

Status
Not open for further replies.
Level 24
Joined
Aug 1, 2013
Messages
4,657
Hi all.

I am trying to make some nice abilities for my new map but I do have a little problem in here.

For example:
I have an ability that is basically a light beam towards a direction. Every unit hit by the light beam will take damage. The damage is reduced by 5% for every unit hit with a minimum of 40%.

So I need:
1. Pick every units in angled rectangle.
2. Pick the units in the order of closest to starting point.

I know how to get all units in a rectangle.
Every unit in (Max range of caster)
- Picked unit x > left side and unit x < right side.
- Picked unit y > down side and unit y < up side.

But how do I do that for angled rectangles?
And how do I order the units in the group to the order of closest to caster?

(I can also use unit array if that is better.)
 
Level 25
Joined
Jul 10, 2006
Messages
3,315
Convert the angles into lines of the form y = Ax + B and check if it's more/less than that function. If you have trouble with this, I could try explain it better a bit later.

A simpler (but costlier) way is to simply loop a bunch of circle checks.
for a from 1 to 10
set group = units within 150 of (loc offset by a * 100 towards caster facing)
 
Level 24
Joined
Aug 1, 2013
Messages
4,657
Convert the angles into lines of the form y = Ax + B and check if it's more/less than that function. If you have trouble with this, I could try explain it better a bit later.
As far as I understand that...
I pretend that the rectangle is in a regular angle and change the units accordingly.
That would mean about 5 or 6 location variables for every unit?

A simpler (but costlier) way is to simply loop a bunch of circle checks.
for a from 1 to 10
set group = units within 150 of (loc offset by a * 100 towards caster facing)
That is what I wanted to replace :D
 

LeP

LeP

Level 13
Joined
Feb 13, 2008
Messages
539
This snippet can check if a point lies within any polygon. The algorithm is quite easy so you could also simplify it, like not using linkedlists.

But i guess using it as is would be useful too. Maybe you want some star shaped spells in the future))
 
Level 25
Joined
Jul 10, 2006
Messages
3,315
Check here: http://www.hiveworkshop.com/forums/1838224-post336.html

JASS:
library IsPointInRectangle
    //determins if point P is in rectangle ABCD
    function IsPointInRectangle takes real ax, real ay, real bx, real by, real cx, real cy, real dx, real dy, real px, real py returns boolean
        local real cross0 = (py-ay)*(bx-ax)-(px-ax)*(by-ay)
        local real cross1 = (py-cy)*(ax-cx)-(px-cx)*(ay-cy)
        local real cross4 = (py-dy)*(ax-dx)-(px-dx)*(ay-dy)
        
        return ((cross0*cross1 >= 0) and (((py-by)*(cx-bx)-(px-bx)*(cy-by))*cross1 >= 0)) or ((cross0*cross4 >= 0) and (((py-by)*(dx-bx)-(px-bx)*(dy-by))*cross4 >= 0))
    endfunction
endlibrary
 
Level 24
Joined
Aug 1, 2013
Messages
4,657
Ok and is there an easy way to sort the units on closest to caster?
Or do I have to loop through the group and add the units in an array with checking the distance everytime?

I want this not only for once in a whle but also for a missile system :D I am a little afraid of the cpu consumability.
 

Dr Super Good

Spell Reviewer
Level 64
Joined
Jan 18, 2005
Messages
27,202
Ok and is there an easy way to sort the units on closest to caster?
No, sadly Warcraft III lacks that sort of thing. You will need to resort to your own slow sort algorithm.

Or do I have to loop through the group and add the units in an array with checking the distance everytime?
That is probably the best approach. To make the distance check more efficient for Euclidian distance you do not need to square root it. If you need more performance you can use Manhattan distance to trade accuracy for speed.

I want this not only for once in a whle but also for a missile system :D I am a little afraid of the cpu consumability.
I would not recommend sorting units every tick. Sorting every creation or every few ticks should be acceptable.
 
Status
Not open for further replies.
Top