
edit: eh.. those files are only missing in the free Toolkit 2003....

Moderators: hoijui, Moderators
Code: Select all
void CGlobalAI::Update()
{
int frame=cb->GetCurrentFrame();
if (frame==100) {
string name="CORMEX";
const UnitDef *hallo=cb->GetUnitDef(name.c_str());
float3 cpos=cb->GetUnitPos(comID);
float3 pos=cb->ClosestBuildSite(hallo,cpos,30000,0);
Command c;
c.id =-cb->GetUnitDef (name.c_str())->id;
c.params.push_back (pos.x);
c.params.push_back(pos.y);
c.params.push_back (pos.z);
callback->GetAICallback()->GiveOrder (comID, &c);
}
}
Code: Select all
string name="CORMEX";
const UnitDef *hallo=cb->GetUnitDef(name.c_str());
Code: Select all
const UnitDef *hallo=cb->GetUnitDef("CORMEX");
Code: Select all
float3 cpos=cb->GetUnitPos(comID);
float3 pos=cb->ClosestBuildSite(hallo,cpos,30000,0);
Code: Select all
Command c;
c.id =-cb->GetUnitDef (name.c_str())->id;
c.params.push_back (pos.x);
c.params.push_back(pos.y);
c.params.push_back (pos.z);
callback->GetAICallback()->GiveOrder (comID, &c);
Code: Select all
void CGlobalAI::Update()
{
if (cb->GetCurrentFrame()==100) {
const UnitDef* hallo=cb->GetUnitDef("CORMEX");
if(hallo == 0) return;
float3 cpos=cb->GetUnitPos(comID);
if(cpos == ZeroVector) return;
if(cpos == UpVector) return;
float3 pos=cb->ClosestBuildSite(hallo,cpos,3000,1);
Command c;
c.id = -hallo->id;
c.params.push_back(pos.x);
c.params.push_back(pos.y);
c.params.push_back(pos.z);
int i=0;
if(c.params.empty() == false) i = cb->GiveOrder (comID, &c);
if(i == -1)
{
// do stuff here if ti fails
}
}
}
Found a bug with this particular thing last night. The closest build site radius command actually scales down the radius value by SQUARE_SIZE*2, so 30k is really just less than 2k.AF wrote:Also 30k is a bit much to pass in? Are you sure ti isnt slowing SAI down doing so? Brazillian battlefields is only 8kx8k in those units and closestbuildsite will still search the empty sectors past the edges...
IIRC that is because it is specified in world space units, and it needs to be scaled down because the bitmap that marks the occupied areas in spring is half the size of the heightmap. (Well it's dimensions are half of that of the heightmap, so the number of squares is actually one 4th of that of the heightmap....Found a bug with this particular thing last night. The closest build site radius command actually scales down the radius value by SQUARE_SIZE*2, so 30k is really just less than 2k.
<3Zaphod wrote: As krogothe said, I optimized it so it returns directly when the closest spot is found, instead of checking all possible spots and then returning.
So usually, it is much faster than it was when KAI was released, it will only take a lot of time when there actually isn't any building space nearby.