+ HasCNAT() in Commits.c, prevent endless loop in plant

Felix Wagner 2011-10-05 04:47:07 +01:00
parent b00a192a61
commit e8447f4133
2 changed files with 17 additions and 5 deletions

View File

@ -11,12 +11,15 @@
*/
global func RootSurface()
{
while(GetContact(-1) & CNAT_Center) SetPosition(GetX(),GetY()-1); //Move up if too far underground
var moved_down = false;
if (!(GetContact(-1) & CNAT_Bottom)) moved_down = true;
while(!(GetContact(-1) & CNAT_Bottom)) SetPosition(GetX(),GetY()+1); //Move down if in midair
if (HasCNAT(CNAT_Center)) while(GetContact(-1) & CNAT_Center) SetPosition(GetX(),GetY()-1); //Move up if too far underground
if (HasCNAT(CNAT_Bottom))
{
var moved_down = false;
if (!(GetContact(-1) & CNAT_Bottom)) moved_down = true;
while(!(GetContact(-1) & CNAT_Bottom)) SetPosition(GetX(),GetY()+1); //Move down if in midair
if (moved_down) SetPosition(GetX(),GetY()+1); // make the plant stuck, not just contact with surface (in case it was moved down)
if (moved_down) SetPosition(GetX(),GetY()+1); // make the plant stuck, not just contact with surface (in case it was moved down)
}
}
/* Local */

View File

@ -112,6 +112,15 @@ global func VerticesStuck()
return vertices;
}
// Returns whether the object has a vertex with the given CNAT value
global func HasCNAT(int cnat)
{
for(var i = -1; i < GetVertexNum(); i++)
if (GetVertex(i, VTX_CNAT) == cnat)
return true;
return false;
}
// Creates amount objects of type id inside the indicated rectangle(optional) in the indicated material.
// Returns the number of iterations needed, or -1 when the placement failed.
global func PlaceObjects(id id, int amount, string mat_str, int x, int y, int wdt, int hgt, bool onsf, bool nostuck)