diff --git a/planet/Objects.ocd/Libraries.ocd/Plant.ocd/Script.c b/planet/Objects.ocd/Libraries.ocd/Plant.ocd/Script.c index f860bc945..e7d9ddc8f 100644 --- a/planet/Objects.ocd/Libraries.ocd/Plant.ocd/Script.c +++ b/planet/Objects.ocd/Libraries.ocd/Plant.ocd/Script.c @@ -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 */ diff --git a/planet/System.ocg/Commits.c b/planet/System.ocg/Commits.c index 86f955c4a..d0d628fdf 100644 --- a/planet/System.ocg/Commits.c +++ b/planet/System.ocg/Commits.c @@ -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)