HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Structs and distance comparison

02-03-2010, 11:43 AM#1
Anachron
Hey again.

I've a struct with coordinates (x, y), and parabolic movement, so I want to check whether that missle is colliding with another missle of the same type. I did this in 2 loops, while one does the general movement stuff, and the other one is used to compare the distances.
I am using XE and my units have locust.
Is there any other (better) method to get colliding units?
02-03-2010, 11:54 AM#2
akolyt0r
Why do you need a second loop for checking distances ?
02-03-2010, 11:56 AM#3
Anachron
How should I check them else?
I need to check all missles whether they collide with any of the other missles.
02-03-2010, 11:58 AM#4
akolyt0r
or you could enum all units around the missile ..and check wether one of those is a missile too
02-03-2010, 12:02 PM#5
Anachron
Nope, they have
1st: Locust
2nd: Private protection (using xefx).

You can't access to them, only to their coordinates.
02-03-2010, 12:15 PM#6
Saishy
I would like to know that too!
I have two homming missiles, and I want them to collide with each other.

I could just thought of having a pointer to each other struct, but that will only make them able to collide in pairs. (So another pair of casted missiles will not collide with the previously casted ones)
02-03-2010, 12:17 PM#7
Anachron
Yeah, currently I am running loops, but I really would like to avoid such things.
Thats one of the bad xe things.
02-03-2010, 12:17 PM#8
akolyt0r
If the units have locust is not relevant here ... of course it is relevant that you use xefx, you have not mentioned that (you only said you use xe, which could be xebasic only aswell).
Well using xefx, a second loop is the only possibilty to do something like this, without changing xefx's code i think.

xefx would need something like a static method like getStruct4Unit takes unit u, returns xefx, which will return the corresponding xefx instance, if the unit is a xefx dummy or NULL otherwise.

Of course you could make a new struct inherit from xefx and implement something like that...and use that struct instead of xefx
02-03-2010, 12:18 PM#9
Anachron
Yeah, thats how I am doing it currently. Thanks anyway.
02-03-2010, 02:50 PM#10
Anitarf
You could attach another non-locusted unit to the position of your xefx and link it with your struct, then look for that unit when checking collision.
02-03-2010, 02:53 PM#11
Anachron
Wehrm, and hiding it?
Is this really faster then just not creating the handle at all and running all loops?
02-03-2010, 02:59 PM#12
Themerion
You probably want to loop through all structs first, to make sure they have updated positions.

However, when you do the collision check afterwards, I hope you only check the distances once, since

Distance(missile1, missile2) = Distance(missile2, missile1)

In other words, begin with checking missile1 against {missile2, missile3, missile4 ...}

Now we've already checked Distance(missile1, missile2), so next:

check missile2 against {missile3, missile3 ...}
check missile3 against {missile4, ...}
02-03-2010, 03:00 PM#13
Anachron
Yeah, I use the current stack index as minimum index. Thanks.
02-03-2010, 03:01 PM#14
Hans_Maulwurf
I've read, that GroupEnumUnitsInRect gets locusts (just like GroupEnumUnitsOfPlayer). Haven't tried myself, but if it works, moving a rect to check for nearby other missiles wheneever you move one of them, should be much better then creating a extra unit and moving it with the xe one.
02-03-2010, 03:58 PM#15
Anachron
Well, that would work, however, then I enumerate on all units.

And there would be the thing that I can't get the handle ID or even the unit of xefx.