ID:167991
 
How would I determin how many spaces away is point a to point b?
There are two ways. You can use the regular get_dist() proc, though it isn't 'accurate'. You can also make your own distance proc to find the real distance between two objects by using some right angle geometry.

proc/distance(atom/A, atom/B)
return sqrt((B.x-A.x)**2 + (B.y-A.y)**2)


The get_dist proc is pretty much the larger of the absolute value of delta x and delta y.

~~> Unknown Person
In response to Unknown Person
Using the ** operator here is a bad idea, as many times distance is something you want to calculate quickly for a loop. It's far better to simply use (B.x-A.x)*(B.x-A.x)+(B.y-A.y)*(B.y-A.y) instead.

Also important is that if you're merely comparing distances, you do not need to use sqrt(). Your game will be faster without it. Any comparison that's valid for distances will be just as valid for squared distances.

Lummox JR
In response to Lummox JR
Of course, it might not always be comparing distances so much as it is comparing a distance to a value. Just to point out that the sqrt() should be there, if the occasion calls for it. =D

Hiead
In response to Hiead
Of course, it might not always be comparing distances so much as it is comparing a distance to a value.

Still faster to compare a squred distance to value * value :P. The only time you need to do the sqrt is when you need to get the ratio of two distances in which case having them squared gives you largely different results.
In response to Theodis
Theodis wrote:
Of course, it might not always be comparing distances so much as it is comparing a distance to a value.

Still faster to compare a squred distance to value * value :P. The only time you need to do the sqrt is when you need to get the ratio of two distances in which case having them squared gives you largely different results.

Indeed. Or the difference between distances, or sum of several distances, may be something you need to calculate, and that too will give you different results if you don't take the square root.

It should also be noted that wherever possible, at least when this is occurring within a loop, you should inline your distance calculations instead of using a proc. I know that may not sound intuitive, but basically if you're in a tight loop and efficiency becomes a major concern (for instance, several AI procs running at once, each comparing several distances), the overhead of calling a proc starts to matter.

Lummox JR