Added flatspace()
Works like space(), but makes sure there is enough flat space for buildingmaster
parent
59d5545eca
commit
dfd73118a6
|
@ -4322,6 +4322,79 @@ bool CRobotMain::FreeSpace(Math::Vector ¢er, float minRadius, float maxRadiu
|
|||
return false;
|
||||
}
|
||||
|
||||
//! Calculates a flat free space
|
||||
bool CRobotMain::FlatFreeSpace(Math::Vector ¢er, float minFlat, float minRadius, float maxRadius,
|
||||
float space, CObject *exclu)
|
||||
{
|
||||
if (minRadius < maxRadius) // from internal to external?
|
||||
{
|
||||
for (float radius = minRadius; radius <= maxRadius; radius += space)
|
||||
{
|
||||
float ia = space/radius;
|
||||
for (float angle = 0.0f; angle < Math::PI*2.0f; angle += ia)
|
||||
{
|
||||
Math::Point p;
|
||||
p.x = center.x+radius;
|
||||
p.y = center.z;
|
||||
p = Math::RotatePoint(Math::Point(center.x, center.z), angle, p);
|
||||
Math::Vector pos;
|
||||
pos.x = p.x;
|
||||
pos.z = p.y;
|
||||
pos.y = 0.0f;
|
||||
m_terrain->AdjustToFloor(pos, true);
|
||||
float dist = SearchNearestObject(pos, exclu);
|
||||
if (dist >= space)
|
||||
{
|
||||
float flat = m_terrain->GetFlatZoneRadius(pos, dist/2.0f);
|
||||
if (flat >= dist/2.0f)
|
||||
{
|
||||
flat = m_terrain->GetFlatZoneRadius(pos, minFlat);
|
||||
if(flat >= minFlat)
|
||||
{
|
||||
center = pos;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else // from external to internal?
|
||||
{
|
||||
for (float radius=maxRadius; radius >= minRadius; radius -= space)
|
||||
{
|
||||
float ia = space/radius;
|
||||
for (float angle=0.0f ; angle<Math::PI*2.0f ; angle+=ia )
|
||||
{
|
||||
Math::Point p;
|
||||
p.x = center.x+radius;
|
||||
p.y = center.z;
|
||||
p = Math::RotatePoint(Math::Point(center.x, center.z), angle, p);
|
||||
Math::Vector pos;
|
||||
pos.x = p.x;
|
||||
pos.z = p.y;
|
||||
pos.y = 0.0f;
|
||||
m_terrain->AdjustToFloor(pos, true);
|
||||
float dist = SearchNearestObject(pos, exclu);
|
||||
if (dist >= space)
|
||||
{
|
||||
float flat = m_terrain->GetFlatZoneRadius(pos, dist/2.0f);
|
||||
if (flat >= dist/2.0f)
|
||||
{
|
||||
flat = m_terrain->GetFlatZoneRadius(pos, minFlat);
|
||||
if(flat >= minFlat)
|
||||
{
|
||||
center = pos;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
//! Calculates the maximum radius of a free space
|
||||
float CRobotMain::GetFlatZoneRadius(Math::Vector center, float maxRadius,
|
||||
CObject *exclu)
|
||||
|
|
|
@ -269,6 +269,7 @@ public:
|
|||
|
||||
float SearchNearestObject(Math::Vector center, CObject *exclu);
|
||||
bool FreeSpace(Math::Vector ¢er, float minRadius, float maxRadius, float space, CObject *exclu);
|
||||
bool FlatFreeSpace(Math::Vector ¢er, float minFlat, float minRadius, float maxRadius, float space, CObject *exclu);
|
||||
float GetFlatZoneRadius(Math::Vector center, float maxRadius, CObject *exclu);
|
||||
void HideDropZone(CObject* metal);
|
||||
void ShowDropZone(CObject* metal, CObject* transporter);
|
||||
|
|
|
@ -276,6 +276,7 @@ std::string GetHelpFilename(const char *token)
|
|||
if ( strcmp(token, "distance" ) == 0 ) helpfile = "cbot/dist";
|
||||
if ( strcmp(token, "distance2d" ) == 0 ) helpfile = "cbot/dist2d";
|
||||
if ( strcmp(token, "space" ) == 0 ) helpfile = "cbot/space";
|
||||
if ( strcmp(token, "flatspace" ) == 0 ) helpfile = "cbot/flatspace";
|
||||
if ( strcmp(token, "flatground" ) == 0 ) helpfile = "cbot/flatgrnd";
|
||||
if ( strcmp(token, "canbuild" ) == 0 ) helpfile = "cbot/canbuild";
|
||||
if ( strcmp(token, "canresearch" ) == 0 ) helpfile = "cbot/canresearch";
|
||||
|
@ -413,6 +414,7 @@ bool IsFunction(const char *token)
|
|||
if ( strcmp(token, "distance" ) == 0 ) return true;
|
||||
if ( strcmp(token, "distance2d" ) == 0 ) return true;
|
||||
if ( strcmp(token, "space" ) == 0 ) return true;
|
||||
if ( strcmp(token, "flatspace" ) == 0 ) return true;
|
||||
if ( strcmp(token, "flatground" ) == 0 ) return true;
|
||||
if ( strcmp(token, "canbuild" ) == 0 ) return true;
|
||||
if ( strcmp(token, "canresearch" ) == 0 ) return true;
|
||||
|
@ -512,6 +514,7 @@ const char* GetHelpText(const char *token)
|
|||
if ( strcmp(token, "direction" ) == 0 ) return "direction ( position );";
|
||||
if ( strcmp(token, "distance2d") == 0 ) return "distance2d ( p1, p2 );";
|
||||
if ( strcmp(token, "distance" ) == 0 ) return "distance ( p1, p2 );";
|
||||
if ( strcmp(token, "flatspace" ) == 0 ) return "space ( center, flatmin, rmin, rmax, dist );";
|
||||
if ( strcmp(token, "space" ) == 0 ) return "space ( center, rmin, rmax, dist );";
|
||||
if ( strcmp(token, "flatground") == 0 ) return "flatground ( center, rmax );";
|
||||
if ( strcmp(token, "canbuild" ) == 0 ) return "canbuild ( category );";
|
||||
|
|
|
@ -1759,6 +1759,86 @@ bool CScriptFunctions::rSpace(CBotVar* var, CBotVar* result, int& exception, voi
|
|||
return true;
|
||||
}
|
||||
|
||||
CBotTypResult CScriptFunctions::cFlatSpace(CBotVar* &var, void* user)
|
||||
{
|
||||
CBotTypResult ret;
|
||||
|
||||
if ( var == 0 ) return CBotTypResult(CBotErrLowParam);
|
||||
ret = cPoint(var, user);
|
||||
if ( ret.GetType() != 0 ) return ret;
|
||||
|
||||
if ( var == 0 ) return CBotTypResult(CBotErrLowParam);
|
||||
if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum);
|
||||
var = var->GetNext();
|
||||
|
||||
if ( var == 0 ) return CBotTypResult(CBotTypIntrinsic, "point");
|
||||
if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum);
|
||||
var = var->GetNext();
|
||||
|
||||
if ( var == 0 ) return CBotTypResult(CBotTypIntrinsic, "point");
|
||||
if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum);
|
||||
var = var->GetNext();
|
||||
|
||||
if ( var == 0 ) return CBotTypResult(CBotTypIntrinsic, "point");
|
||||
if ( var->GetType() > CBotTypDouble ) return CBotTypResult(CBotErrBadNum);
|
||||
var = var->GetNext();
|
||||
|
||||
if ( var != 0 ) return CBotTypResult(CBotErrOverParam);
|
||||
return CBotTypResult(CBotTypIntrinsic, "point");
|
||||
}
|
||||
|
||||
bool CScriptFunctions::rFlatSpace(CBotVar* var, CBotVar* result, int& exception, void* user)
|
||||
{
|
||||
CScript* script = (static_cast<CObject *>(user))->GetRunScript();
|
||||
CObject* pThis = static_cast<CObject *>(user);
|
||||
CBotVar* pSub;
|
||||
Math::Vector center;
|
||||
float flatMin, rMin, rMax, dist;
|
||||
|
||||
rMin = 10.0f*g_unit;
|
||||
rMax = 50.0f*g_unit;
|
||||
dist = 4.0f*g_unit;
|
||||
|
||||
|
||||
if ( !GetPoint(var, exception, center) ) return true;
|
||||
|
||||
flatMin = var->GetValFloat()*g_unit;
|
||||
var = var->GetNext();
|
||||
|
||||
if ( var != 0 )
|
||||
{
|
||||
rMin = var->GetValFloat()*g_unit;
|
||||
var = var->GetNext();
|
||||
|
||||
if ( var != 0 )
|
||||
{
|
||||
rMax = var->GetValFloat()*g_unit;
|
||||
var = var->GetNext();
|
||||
|
||||
if ( var != 0 )
|
||||
{
|
||||
dist = var->GetValFloat()*g_unit;
|
||||
var = var->GetNext();
|
||||
}
|
||||
}
|
||||
}
|
||||
script->m_main->FlatFreeSpace(center, flatMin, rMin, rMax, dist, pThis);
|
||||
|
||||
if ( result != 0 )
|
||||
{
|
||||
pSub = result->GetItemList();
|
||||
if ( pSub != 0 )
|
||||
{
|
||||
pSub->SetValFloat(center.x/g_unit);
|
||||
pSub = pSub->GetNext(); // "y"
|
||||
pSub->SetValFloat(center.z/g_unit);
|
||||
pSub = pSub->GetNext(); // "z"
|
||||
pSub->SetValFloat(center.y/g_unit);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
// Compilation of the instruction "flatground(center, rMax)".
|
||||
|
||||
|
@ -3709,6 +3789,7 @@ void CScriptFunctions::Init()
|
|||
CBotProgram::AddFunction("distance", rDistance, CScriptFunctions::cDistance);
|
||||
CBotProgram::AddFunction("distance2d",rDistance2d,CScriptFunctions::cDistance);
|
||||
CBotProgram::AddFunction("space", rSpace, CScriptFunctions::cSpace);
|
||||
CBotProgram::AddFunction("flatspace", rFlatSpace, CScriptFunctions::cFlatSpace);
|
||||
CBotProgram::AddFunction("flatground",rFlatGround,CScriptFunctions::cFlatGround);
|
||||
CBotProgram::AddFunction("wait", rWait, CScriptFunctions::cOneFloat);
|
||||
CBotProgram::AddFunction("move", rMove, CScriptFunctions::cOneFloat);
|
||||
|
|
|
@ -63,6 +63,7 @@ private:
|
|||
static CBotTypResult cProduce(CBotVar* &var, void* user);
|
||||
static CBotTypResult cDistance(CBotVar* &var, void* user);
|
||||
static CBotTypResult cSpace(CBotVar* &var, void* user);
|
||||
static CBotTypResult cFlatSpace(CBotVar* &var, void* user);
|
||||
static CBotTypResult cFlatGround(CBotVar* &var, void* user);
|
||||
static CBotTypResult cGoto(CBotVar* &var, void* user);
|
||||
static CBotTypResult cGrabDrop(CBotVar* &var, void* user);
|
||||
|
@ -118,6 +119,7 @@ private:
|
|||
static bool rDistance(CBotVar* var, CBotVar* result, int& exception, void* user);
|
||||
static bool rDistance2d(CBotVar* var, CBotVar* result, int& exception, void* user);
|
||||
static bool rSpace(CBotVar* var, CBotVar* result, int& exception, void* user);
|
||||
static bool rFlatSpace(CBotVar* var, CBotVar* result, int& exception, void* user);
|
||||
static bool rFlatGround(CBotVar* var, CBotVar* result, int& exception, void* user);
|
||||
static bool rWait(CBotVar* var, CBotVar* result, int& exception, void* user);
|
||||
static bool rMove(CBotVar* var, CBotVar* result, int& exception, void* user);
|
||||
|
|
Loading…
Reference in New Issue