Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Radius param for search()
#4
Radius for search can be done in a custom CBOT function pretty easily.

Returning an array of all objects of certain category is even easier.

I bet angular limitations are possible as well. Tho I don't see much of a use for those. You can choose a percise spot to look at anyway.

Example:
Code:
object object::bettersearch(int cat, point pos, float rmin, float rmax)
{
    // Generate objects list
    
    object objects[];
    int i = 0;
    float range = 0;
    int size;
    
    while(true)
    {
        objects[i] = radar(cat, 0, 360, range);
        if(objects[i] == null)
        {
            size = i;
            break;
        }
        
        range = distance(this.position,objects[i].position)+0.1;
        i++;
    }
    
    // Objects list ready
    // One could 'return objects;' here to get searchAll
    
    float distances[];
    int result = nan;
    
    for(i=0;i<size;i++)
    {
        distances[i] = distance(pos,objects[i].position); // Determine distances
        if (distances[i] < rmin) distances[i] = 1000; // Trim objects too close
        
        if (distances[i] < rmax) // Locate closest object
        {
            rmax = distances[i];
            result = i;
        }
    }
    
    // Return the result
    
    if (result == nan)
    {
        message("Object not found",DisplayError);
        return null;
    }
    else return objects[result];
}
 
I didn't post in a while now did I?
My Code Battle League program: MhrodeBattle.txt

Welcome back, Mrocza. You last visited: Sunday, July 7th, 2013, 02:12 pm 
http://imgur.com/L3Y8bQz


Messages In This Thread
Radius param for search() - by melex750 - 03-16-2016, 12:20 PM
RE: Radius param for search() - by krzys_h - 03-16-2016, 08:33 PM
RE: Radius param for search() - by melex750 - 03-17-2016, 12:42 AM
RE: Radius param for search() - by Mrocza - 03-18-2016, 10:51 PM
RE: Radius param for search() - by melex750 - 03-19-2016, 06:12 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)