Skip to content

Commit 76176c9

Browse files
committed
fixed clearing crashing in octagonal mode, and hopefully improved it in general
1 parent f5f21ae commit 76176c9

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

complex.cpp

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -843,6 +843,15 @@ EX namespace clearing {
843843
}
844844
}
845845

846+
bool goes_below(cell *c, int d, int steps) {
847+
if(pseudohept(c)) return false;
848+
if(celldistAlt(c) < d) return true;
849+
if(celldistAlt(c) > d) return false;
850+
if(steps == 0) return false;
851+
forCellIdCM(c2, i, c) if(goes_below(c2, d, steps-1)) return true;
852+
return false;
853+
}
854+
846855
int plantdir(cell *c) {
847856
if(have_alt(c))
848857
gen_alt_around(c);
@@ -888,8 +897,12 @@ EX namespace clearing {
888897
if((d & 7) < 4) i = (i+2) % c->type;
889898
return i;
890899
}
891-
printf("error in plantdir\n");
892-
return 1;
900+
for(int steps=0; steps<60; steps++)
901+
forCellIdCM(c2, i2, c)
902+
if(goes_below(c2, d, steps))
903+
return i2;
904+
println(hlog, "error in plantdir, quseful = ", quseful);
905+
return -1;
893906
}
894907

895908
vector<cell*> onpath;
@@ -957,6 +970,7 @@ EX namespace clearing {
957970
steps++;
958971
onpath.push_back(c); pdir.push_back(d);
959972
// printf("c [%4d] %p -> %p\n", celldistAlt(c), c, c->move(d));
973+
if(d == -1) break;
960974
c = c->move(d);
961975
}
962976
else {

0 commit comments

Comments
 (0)