]> git.jsancho.org Git - lugaru.git/blobdiff - Source/Environment/Terrain.cpp
This should fix the segfault from #89
[lugaru.git] / Source / Environment / Terrain.cpp
index 4874e337bcd1fa5e532597a414afa67a48fc5283..2530f0a873f5b156fc2c4b8c8a9c1b815a3c2ae1 100644 (file)
@@ -1241,6 +1241,26 @@ void Terrain::AddObject(XYZ where, float radius, int id)
     }
 }
 
+void Terrain::DeleteObject(unsigned int id)
+{
+    for (int i = 0; i < subdivision; i++) {
+        for (int j = 0; j < subdivision; j++) {
+            for (unsigned int k = 0; k < patchobjects[i][j].size();) {
+                if (patchobjects[i][j][k] == id) {
+                    /* Remove all occurences of id (there should never be more than 1 though) */
+                    patchobjects[i][j].erase(patchobjects[i][j].begin() + k);
+                } else {
+                    /* Update id of other objects if needed */
+                    if (patchobjects[i][j][k] > id) {
+                        patchobjects[i][j][k]--;
+                    }
+                    k++;
+                }
+            }
+        }
+    }
+}
+
 void Terrain::DeleteDecal(int which)
 {
     if (decalstoggle) {