From 3f836d1dfe91c9d56cc8c54b7c578d39a419fc96 Mon Sep 17 00:00:00 2001 From: Zeno Rogue Date: Sun, 10 Mar 2019 18:37:09 +0100 Subject: [PATCH] 3d:: Great Walls in H3 geometries --- barriers.cpp | 86 +++++++++++++++++++++++++++++++++++++++++++++++++++- landgen.cpp | 9 +++--- reg3.cpp | 29 +++++++++++++++++- 3 files changed, 117 insertions(+), 7 deletions(-) diff --git a/barriers.cpp b/barriers.cpp index 879350cc..47375e9f 100644 --- a/barriers.cpp +++ b/barriers.cpp @@ -336,6 +336,8 @@ bool isbar4(cell *c) { c->land == laMercuryRiver; } +void extend3D(cell *c); + void extendBarrier(cell *c) { limitgen("extend barrier %p\n", c); if(buggyGeneration) return; @@ -357,7 +359,8 @@ void extendBarrier(cell *c) { } if(c->barleft == NOWALLSEP) { - extendNowall(c); + if(DIM == 3) extend3D(c); + else extendNowall(c); return; } @@ -731,11 +734,92 @@ void buildCrossroads2(cell *c) { } } +void extend3D(cell *c) { + eLand l1 = c->land; + c->barleft = NOWALLSEP_USED; + + cellwalker cw(c, c->bardir); + + if(S3 == 5) { + cw += wstep; cw += rev; + cw.at->bardir = NOBARRIERS; + setland(cw.at, laBarrier); + } + + auto cw1 = cw + wstep; + setland(cw1.at, c->barright); + if(cw1.at->bardir == NODIR) { + cw1.at->barleft = NOWALLSEP_USED; + cw1.at->barright = l1; + cw1.at->bardir = cw1.spin; + } + + for(int j=0; jbardir == NODIR) { + bb2.at->bardir = bb2.spin; + bb2.at->barleft = NOWALLSEP; + bb2.at->barright = c->barright; + bb2.at->land = l1; + // bb2.at->item = itGold; + extendBarrier(bb2.at); + } + } + } + +bool built = false; + +bool buildBarrier3D(cell *c, eLand l2, int forced_dir) { + if(forced_dir == NODIR) { + for(int t=0; tmove(t) || c->move(t)->mpdist > c->mpdist) && buildBarrier3D(c, l2, t)) return true; + return false; + } + cellwalker cw(c, forced_dir); + if(S3 == 5) { cw += wstep; cw += rev; } + set listed_cells = { cw.at }; + vector to_test { cw }; + for(int i=0; impdist < BARLEV) return false; + if(bb.cpeek()->mpdist < BARLEV) return false; + if(bb.cpeek()->bardir != NODIR) return false; + if(S3 == 5 && (bb+rev).cpeek()->mpdist < BARLEV) return false; + if(S3 == 5 && (bb+rev).cpeek()->bardir != NODIR) return false; + if(bb.at->bardir != NODIR) return false; + for(int j=0; jcmove(j); + if(reg3::dirs_adjacent[bb.spin][j] && bb.at->move(j)) { + cellwalker bb2 = reg3::strafe(bb, j); + if(listed_cells.count(bb2.at)) continue; + listed_cells.insert(bb2.at); + to_test.push_back(bb2); + } + } + } + + for(int i=0; ibardir = NOBARRIERS; setland(bb.at, laBarrier); bb += rev; bb += wstep; } + bb.at->land = c->land; + bb.at->bardir = bb.spin; + bb.at->barleft = NOWALLSEP; + bb.at->barright = l2; + extendBarrier(bb.at); + } + + built = true; + return true; + } + bool buildBarrierNowall(cell *c, eLand l2, int forced_dir) { // 3D binary tilings create walls using their own methods if(DIM == 3 && binarytiling) return false; + if(DIM == 3 && hyperbolic) return buildBarrier3D(c, l2, forced_dir); + if(c->land == laNone) { printf("barrier nowall! [%p]\n", c); raiseBuggyGeneration(c, "barrier nowall!"); diff --git a/landgen.cpp b/landgen.cpp index 27ad89ea..e90963fe 100644 --- a/landgen.cpp +++ b/landgen.cpp @@ -2414,7 +2414,7 @@ void repairLandgen(cell *c) { } if(passable(c, NULL, 0)) { - if(c->land == laBarrier) c->wall = waBarrier; + if(c->land == laBarrier && DIM != 3) c->wall = waBarrier; if(c->land == laOceanWall) c->wall = c->type == 7 ? waBarrier : waSea; } @@ -2467,10 +2467,9 @@ void setdist(cell *c, int d, cell *from) { if(cseek->master->emeraldval) setland(c, eLand(cseek->master->emeraldval)); } - if(!c->land && from && from->land != laElementalWall && from->land != laHauntedWall && from->land != laOceanWall && - from->land != laBarrier && !quotient) { - if(!hasbardir(c)) setland(c, from->land); - } + if(!c->land && from && (DIM == 3 || among(from->land, laBarrier, laElementalWall, laHauntedWall, laOceanWall)) && !quotient) { + if(!hasbardir(c)) setland(c, from->land); + } if(c->land == laTemple && !tactic::on && !chaosmode) setland(c, laRlyeh); if(c->land == laMountain && !tactic::on && !chaosmode) setland(c, laJungle); if(c->land == laClearing && !tactic::on) setland(c, laOvergrown); diff --git a/reg3.cpp b/reg3.cpp index bf822a7a..34a29ed0 100644 --- a/reg3.cpp +++ b/reg3.cpp @@ -34,6 +34,9 @@ namespace reg3 { transmatrix spins[12], adjmoves[12]; + ld adjcheck, strafedist; + bool dirs_adjacent[16][16]; + template ld binsearch(ld dmin, ld dmax, const T& f) { for(int i=0; i<200; i++) { ld d = (dmin + dmax) / 2; @@ -154,7 +157,18 @@ namespace reg3 { println(hlog, "center of ", a, " is ", tC0(adjmoves[a])); println(hlog, "doublemove = ", tC0(adjmoves[0] * adjmoves[0])); - // exit(1); + + adjcheck = hdist(tC0(adjmoves[0]), tC0(adjmoves[1])) * 1.0001; + + int numedges = 0; + for(int a=0; a