Nearby Base Distance

Jul 05, 2004 23:11 Nearby Base Distance
In playing around with a brain lately, I've been using the following if statement to determine if there's a neutral base nearby:
[code:1:a7d99ad98a]
// no friendly base nearby
if (info->base == NULL)
return false;
// friendly but already owned
else if ((info->base != NULL) && (info->base->info != 2))
return false;
// friendly and takeable!
else
return true;
[/code:1:a7d99ad98a]
My problem isn't with the code, it works fine. My problem is that in the brain.h comments it states..
[code:1:a7d99ad98a]ObjectInfo *base; // will be NULL if no friendly base nearby
[/code:1:a7d99ad98a]
So what exactly is classified as "nearby"? Is it what the distance would be for a human to see a friendly/neutral base's resource levels pop up on their screen?
Last edited: Jul 06, 2004 00:24 (edited 1 time)
Jul 05, 2004 23:44
I tested this, and found out that the distance for you to view an allied/neutral base's resource levels is:
-The distance of your Gunsight when it is on as far as it will go; six squares on the map.

-Madd Maxx- (hope this helps!)
Jul 06, 2004 00:26
Yes MM, I already knew that. I'm asking if that's the reason why "nearby" is 6 squares according to the brain interface.
Jul 06, 2004 02:11
Its 1792 world units from the centre of the base to the tank.
Jul 06, 2004 03:54
I used this little function to find the closest base

[code:1:43a3a63af8]
// InProgress Function to return the closest neutral base
ObjectInfo getCloseNeutralbase()
{
int objs;
float opp, adj, hyp;
float oppC, adjC, hypC;

ObjectInfo closestBase;

for (objs = 0; objs <= 15; objs++)
{
if(tBases[objs].info == OBJECT_NEUTRAL)
{
hypC = returnHypotenuse(closestBase);
hyp = returnHypotenuse(tBases[objs]);
if (hyp < hypC)
{
closestBase = tBases[objs];
}
}

}

return closestBase;
}
[/code:1:43a3a63af8]

which is combined with this guy for full functionality. this guy runs every frame, probably should only run once every second until all base locations are known ... but I didn't get that far into optimizing things.

[code:1:43a3a63af8]
// Function to check the objects list and update the bases array
void BaseArrayUpdate()
{
int objs;

for (objs = 0; objs < info->num_objects; objs++)
{
if(info->objects[objs].object == OBJECT_REFBASE)
{
tBases[info->objects[objs].idnum] = info->objects[objs];
}
}

return;
}
[/code:1:43a3a63af8]

oh ya .. I guess it needs this guy too ....

[code:1:43a3a63af8]
float returnHypotenuse(ObjectInfo object)
{
float opp, adj, hyp;
opp = object.x - info->tankx;
adj = object.y - info->tanky;
hyp = sqrt((opp*opp)+(adj*adj));
return hyp;
}
[/code:1:43a3a63af8]
Jul 06, 2004 03:58
btw sticks, if you compile in release mode, it will make your brain much smaller becuase it doesn't have the debug code in there with it.

Min
Jul 06, 2004 19:09
Yeah, I just found that Release option in MSVC++. And 1792 divided by 256 is 7, the number of map squares.

Also Min, I looked through your code that you sent me awhile back. I would have liked to done it my way as it would have eliminated the whole for() loop each call. But yeah, it looks like I will have use a method like you have in your code to find nearby neutral bases.
Jul 06, 2004 19:44
like I said, you don't have to do that every call .... juts too it once a second or something ... optimize!

Min