more elegant cellwalkers

This commit is contained in:
Zeno Rogue 2018-03-24 12:59:01 +01:00
parent 2c09c5ee56
commit ac37b6df99
20 changed files with 371 additions and 467 deletions

View File

@ -13,17 +13,16 @@ bool checkBarriersFront(cellwalker bb, int q, bool cross) {
if(bb.spin == (nonbitrunc ? 3 : 0)) {q--; if(!q) return true; }
if(!cross) for(int i=0; i<7; i++) {
cellwalker bb2 = bb;
cwspin(bb2, i); cwstep(bb2);
cellwalker bb2 = bb + i + wstep;
if(bb2.c->bardir != NODIR) return false;
if(!nonbitrunc) {
cwspin(bb2, 4); cwstep(bb2);
bb2 = bb2 + 4 + wstep;
if(bb2.c->bardir != NODIR) return false;
}
}
cwstep(bb);
if(!nonbitrunc) { cwspin(bb, 3); cwstep(bb); cwspin(bb, 3); cwstep(bb); }
bb += wstep;
if(!nonbitrunc) { bb = bb + 3 + wstep + 3 + wstep; }
return checkBarriersBack(bb, q);
}
@ -47,19 +46,15 @@ bool checkBarriersBack(cellwalker bb, int q, bool cross) {
// if(bb.spin == 0 && bb.c->mpdist == INFD) return true;
if(!cross) for(int i=0; i<7; i++) {
cellwalker bb2 = bb;
cwspin(bb2, i); cwstep(bb2);
cellwalker bb2 = bb + i + wstep;
if(bb2.c->bardir != NODIR) return false;
if(!nonbitrunc) {
cwspin(bb2, 4); cwstep(bb2);
bb2 = bb2 + 4 + wstep;
if(bb2.c->bardir != NODIR) return false;
}
}
cwspin(bb, 3); cwstep(bb); cwspin(bb, nonbitrunc ? 5 : 4);
// bool create = cwstepcreates(bb);
cwstep(bb); cwspin(bb, 3);
// if(create && bb.spin == 0) return true;
bb = bb + 3 + wstep + (nonbitrunc ? 5 : 4) + wstep + 3;
return checkBarriersFront(bb, q);
}
@ -90,20 +85,13 @@ bool checkBarriersNowall(cellwalker bb, int q, int dir, eLand l1=laNone, eLand l
}
if(nonbitrunc && S3==4) {
cwspin(bb, dir);
cwstep(bb);
cwspin(bb, dir);
bb = bb + dir + wstep + dir;
}
else if(nonbitrunc) {
cwspin(bb, 3*dir);
cwstep(bb);
cwspin(bb, -3*dir);
bb = bb + (3*dir) + wstep - (3*dir);
}
else {
cwstep(bb);
cwspin(bb, 2*dir);
cwstep(bb);
cwspin(bb, dir);
bb = bb + wstep + (2*dir) + wstep + dir;
}
return checkBarriersNowall(bb, q+1, -dir, l2, l1);
}
@ -174,7 +162,7 @@ void extendBarrierFront(cell *c) {
extendcheck(c);
cellwalker bb(c, c->bardir); setbarrier(bb.c);
cwstep(bb);
bb += wstep;
if(!nonbitrunc) {
bb.c->barleft = c->barleft;
@ -183,19 +171,19 @@ void extendBarrierFront(cell *c) {
if(!mirrorwall(bb.c))
bb.c->landparam = (ht-4);
//printf("[A heat %d]\n", ht-4);
cwspin(bb, 2); cwstep(bb); setland(bb.c, c->barleft); cwstep(bb);
cwspin(bb, 2); cwstep(bb); setland(bb.c, c->barright); cwstep(bb);
cwspin(bb, 2);
setland((bb + 2 + wstep).c, c->barleft);
setland((bb + 4 + wstep).c, c->barright);
cwspin(bb, 3); cwstep(bb);
bb = bb + 3 + wstep;
bb.c->barleft = c->barright;
bb.c->barright = c->barleft;
setbarrier(bb.c);
if(!mirrorwall(bb.c))
bb.c->landparam = (ht-4)^2;
//printf("[B heat %d]\n", (ht-4)^2);
cwspin(bb, 3); cwstep(bb);
bb = bb + 3 + wstep;
bb.c->barleft = c->barleft;
bb.c->barright = c->barright;
@ -212,7 +200,7 @@ void extendBarrierFront(cell *c) {
extendBarrier(bb.c);
for(int a=-3; a<=3; a++) if(a) {
bb.c = c; bb.spin = c->bardir; cwspin(bb, nonbitrunc?-a:a); cwstep(bb);
bb.c = c; bb.spin = c->bardir; bb += (nonbitrunc?-a:a); bb += wstep;
setland(bb.c, a > 0 ? c->barright : c->barleft);
}
}
@ -224,9 +212,9 @@ void extendBarrierBack(cell *c) {
extendcheck(c);
cellwalker bb(c, c->bardir); setbarrier(bb.c);
cwspin(bb, 3); cwstep(bb); cwspin(bb, nonbitrunc?5:4);
bb = bb + 3 + wstep + (nonbitrunc?5:4);
setland(bb.c, nonbitrunc ? c->barleft : c->barright);
cwstep(bb); cwspin(bb, 3);
bb = bb + wstep + 3;
bb.c->bardir = bb.spin;
bb.c->barleft = c->barright;
bb.c->barright = c->barleft;
@ -237,12 +225,11 @@ void extendBarrierBack(cell *c) {
// needed for CR2 to work
if(!nonbitrunc) {
cwstep(bb);
bb.c->barleft = c->barright;
bb.c->barright = c->barleft;
if(!mirrorwall(bb.c))
bb.c->landparam = (ht^11)-4;
cwstep(bb);
auto bb2 = bb + wstep;
bb2.c->barleft = c->barright;
bb2.c->barright = c->barleft;
if(!mirrorwall(bb2.c))
bb2.c->landparam = (ht^11)-4;
}
//printf("[E heat %d]\n", (ht^11));
@ -256,68 +243,49 @@ void extendNowall(cell *c) {
cellwalker cw(c, c->bardir);
if(!nonbitrunc) {
cwstep(cw);
cw += wstep;
setland(cw.c, c->barright);
}
if(nonbitrunc && S3 == 4) {
cwstep(cw);
setland(cw.c, c->barright);
cw.c->barleft = NOWALLSEP_USED;
cw.c->barright = c->land;
cw.c->bardir = cw.spin;
cwstep(cw);
auto cw2 = cw + wstep;
setland(cw2.c, c->barright);
cw2.c->barleft = NOWALLSEP_USED;
cw2.c->barright = c->land;
cw2.c->bardir = cw2.spin;
}
for(int i=-1; i<2; i+=2) {
cellwalker cw0;
if(nonbitrunc && S3==4) {
cwspin(cw, i);
cwstep(cw);
cwspin(cw, i);
cw0 = cw + i + wstep + i;
}
else if(nonbitrunc) {
cwspin(cw, 3*i);
cwstep(cw);
cwspin(cw, -3*i);
cw0 = cw + (3*i) + wstep - (3*i);
}
else {
cwspin(cw, 2*i);
cwstep(cw);
cw0 = cw + (2*i) + wstep;
}
if(cw.c->barleft != NOWALLSEP_USED) {
cw.c->barleft = NOWALLSEP;
if(cw0.c->barleft != NOWALLSEP_USED) {
cw0.c->barleft = NOWALLSEP;
if(S3 == 4 && nonbitrunc) {
cw.c->barright = c->barright;
cw.c->bardir = cw.spin;
setland(cw.c, c->land);
cw0.c->barright = c->barright;
cw0.c->bardir = cw0.spin;
setland(cw0.c, c->land);
}
else {
setland(cw.c, c->barright);
cw.c->barright = c->land;
setland(cw0.c, c->barright);
cw0.c->barright = c->land;
if(c->barright == laNone) {
printf("barright\n");
}// NONEDEBUG
setland(cw.c, c->barright);
if(!nonbitrunc) cwspin(cw, i);
cw.c->bardir = cw.spin;
if(!nonbitrunc) cwspin(cw, -i);
setland(cw0.c, c->barright);
if(!nonbitrunc) cw0 += i;
cw0.c->bardir = cw0.spin;
if(!nonbitrunc) cw0 -= i;
}
extendcheck(cw.c);
extendBarrier(cw.c);
}
if(nonbitrunc && S3==4) {
cwspin(cw, -i);
cwstep(cw);
cwspin(cw, -i);
}
else if(nonbitrunc) {
cwspin(cw, 3*i);
cwstep(cw);
cwspin(cw, -3*i);
}
else {
cwstep(cw);
cwspin(cw, -2*i);
extendcheck(cw0.c);
extendBarrier(cw0.c);
}
}
}
@ -332,11 +300,7 @@ void extendCR5(cell *c) {
cellwalker cw(c, c->bardir);
for(int u=0; u<2; u++) {
// if(gotit) break;
cwspin(cw, 2);
cwstep(cw);
cwspin(cw, 2);
cwstep(cw);
cwspin(cw, 5);
cw = cw + 2 + wstep + 2 + wstep + 5;
if(cw.c->bardir == NODIR) {
cw.c->landparam = 40;
cw.c->bardir = cw.spin;
@ -391,7 +355,7 @@ void extendBarrier(cell *c) {
if(firstmirror && c->barleft == laMirror && hrand(100) < 60) {
cellwalker cw(c, c->bardir);
if(!nonbitrunc) cwstep(cw);
if(!nonbitrunc) cw += wstep;
if(cw.c->land != laMirrorWall)
if(buildBarrier6(cw, 1)) return;
}
@ -399,11 +363,10 @@ void extendBarrier(cell *c) {
if(firstmirror && (nonbitrunc?c->barleft == laMirror : c->barright == laMirror) && hrand(100) < 60) {
cellwalker cw(c, c->bardir);
if(nonbitrunc) {
cwspin(cw, -3); cwstep(cw); cwspin(cw, -3);
// cwspin(cw, 3); cwstep(cw); cwspin(cw, -2); cwstep(cw); cwspin(cw, 3);
cw = cw - 3 + wstep - 3;
}
else {
cwstep(cw); cwspin(cw, 3); cwstep(cw); cwspin(cw, -1); // check this
cw = cw + wstep + 3 + wstep - 1; // check this
}
if(buildBarrier6(cw, 2)) return;
}
@ -415,9 +378,9 @@ void extendBarrier(cell *c) {
cellwalker cw(c, c->bardir);
if(nonbitrunc) {
cwstep(cw);
cw += wstep;
if(isbar4(cw.c)) {
cwstep(cw); cwspin(cw, 3); cwstep(cw); cwspin(cw, -1); cwstep(cw);
cw = cw + wstep + 3 + wstep - 1 + wstep;
bool b = buildBarrier4(cw.c, cw.spin, 2, oppositeElement(c->barleft, c->barright), c->barright);
if(b) return;
}
@ -427,10 +390,10 @@ void extendBarrier(cell *c) {
}
}
else {
cwspin(cw, 3); cwstep(cw);
cell *cp = cwpeek(cw, 4);
cw = cw + 3 + wstep;
cell *cp = (cw + 4 + wstep).c;
if(!isbar4(cp)) {
cwspin(cw, 2); cwstep(cw);
cw = cw + 2 + wstep;
bool b = buildBarrier4(cw.c, cw.spin, 2, oppositeElement(c->barleft, c->barright), c->barright);
if(b) return;
}
@ -474,22 +437,23 @@ bool buildBarrier6(cellwalker cw, int type) {
limitgen("build6 %p/%d (%d)\n", cw.c, cw.spin, type);
cellwalker b[4];
for(int i=0; i<4; i++) b[i] = cw;
if(buggyGeneration) return true;
if(!nonbitrunc) {
cwstep(b[0]);
cwspin(b[1], 1); cwstep(b[1]); cwspin(b[1], 3); cwstep(b[1]);
cwspin(b[2], 4); cwstep(b[2]);
cwspin(b[3], 3); cwstep(b[3]); cwspin(b[3], 3); cwstep(b[3]);
b[0] = cw + wstep;
b[1] = cw + 1 + wstep + 3 + wstep;
b[2] = cw + 4 + wstep;
b[3] = cw + 3 + wstep + 3 + wstep;
}
else {
cwspin(b[1], 3); cwstep(b[1]); cwspin(b[1], 3);
cwspin(b[2], -2); cwstep(b[2]); cwspin(b[2], -3);
cwspin(b[3], -3); cwstep(b[3]); cwspin(b[3], 2); cwstep(b[3]); cwspin(b[3],-3);
b[0] = cw;
b[1] = cw + 3 + wstep + 3;
b[2] = cw - 2 + wstep - 3;
b[3] = cw - 3 + wstep + 2 + wstep - 3;
if(type == 1 && b[3].c->land != laMirrorWall) return false;
if(type == 2 && cwpeek(b[1], 0)->land != laMirrorWall) return false;
if(type == 2 && (b[1] + wstep).c->land != laMirrorWall) return false;
// if(type == 2 && b[2].c->land != laMirrorWall) return false;
}
@ -537,49 +501,44 @@ bool buildBarrier6(cellwalker cw, int type) {
for(int z=0; z<4; z++)
b[z].c->item = eItem(1+z+4*type);
for(int a=0; a<4; a++)
extendBarrierBack(cwpeek(b[a],0));
extendBarrierBack((b[a]+wstep).c);
}
if(!nonbitrunc) {
setland(cwpeek(cw, 1), laMirrorWall);
setland(cwpeek(cw, 2), laMirrored);
setland(cwpeek(cw, 3), laMirrorWall2);
setland(cwpeek(cw, 4), laMirrorWall2);
setland(cwpeek(cw, 5), laMirrored);
setland(cwpeek(cw, 0), laMirrorWall);
setland(cwpeek(b[0], 2), laMirrored);
setland(cwpeek(b[3], 6), laMirrored2);
setland(cwpeek(b[3], 5), laMirrored2);
setland(cwpeek(b[1], -1), laMirrored);
setland(cwpeek(b[2], -2), laMirrored);
setland(cwpeek(b[1], -2), laMirrored);
setland(cwpeek(b[0], -2), laMirror);
setland((cw+1+wstep).c, laMirrorWall);
setland((cw+2+wstep).c, laMirrored);
setland((cw+3+wstep).c, laMirrorWall2);
setland((cw+4+wstep).c, laMirrorWall2);
setland((cw+5+wstep).c, laMirrored);
setland((cw+0+wstep).c, laMirrorWall);
setland((b[0]+2+wstep).c, laMirrored);
setland((b[3]+6+wstep).c, laMirrored2);
setland((b[3]+5+wstep).c, laMirrored2);
setland((b[1]-1+wstep).c, laMirrored);
setland((b[2]-2+wstep).c, laMirrored);
setland((b[1]-2+wstep).c, laMirrored);
setland((b[0]-2+wstep).c, laMirror);
cw.c->land = laMirrorWall;
cw.c->wall = waMirrorWall;
cw.c->landparam = 1;
}
else {
setland(cw.c, laMirrorWall2);
setland(cwpeek(cw, 0), laMirrorWall2);
setland(cwpeek(cw, 1), laMirrored);
setland(cwpeek(cw, 2), laMirrored);
setland(cwpeek(cw, 3), laMirrorWall);
setland(cwpeek(cw, 4), laMirrored);
setland(cwpeek(cw, 5), laMirrorWall2);
setland(cwpeek(cw, 6), laMirrored2);
setland((cw+0+wstep).c, laMirrorWall2);
setland((cw+1+wstep).c, laMirrored);
setland((cw+2+wstep).c, laMirrored);
setland((cw+3+wstep).c, laMirrorWall);
setland((cw+4+wstep).c, laMirrored);
setland((cw+5+wstep).c, laMirrorWall2);
setland((cw+6+wstep).c, laMirrored2);
setland(cwpeek(b[1], 0), laMirrorWall);
setland(cwpeek(b[1], 1), laMirror);
setland(cwpeek(b[1], 2), laMirrorWall);
setland(cwpeek(b[1], 6), laMirrored);
setland((b[1]+wstep).c, laMirrorWall);
setland((b[1]+1+wstep).c, laMirror);
setland((b[1]+2+wstep).c, laMirrorWall);
setland((b[1]+6+wstep).c, laMirrored);
cellwalker cf = b[0];
cwstep(cf);
setland(cwpeek(cf, -2), laMirrored);
cf = b[3];
cwstep(cf);
setland(cwpeek(cf, -2), laMirrored);
setland((b[0] + wstep - 2 + wstep).c, laMirrored);
setland((b[3] + wstep - 2 + wstep).c, laMirrored);
}
return true;
@ -591,27 +550,13 @@ bool buildBarrier4(cell *c, int d, int mode, eLand ll, eLand lr) {
limitgen("build4 %p\n", c);
if(buggyGeneration) return true;
d %= 7;
cellwalker b1(c, d);
cellwalker b2(c, d);
if(nonbitrunc) cwstep(b2);
else { cwstep(b2); cwspin(b2, 3); cwstep(b2); cwspin(b2, 3); cwstep(b2); }
cellwalker b3(c, d);
if(nonbitrunc) {
cwspin(b3, -1); cwstep(b3); cwspin(b3, 3);
}
else {
cwstep(b3); cwspin(b3, 4); cwstep(b3); cwspin(b3, 4);
}
cellwalker b4(c, d);
if(nonbitrunc) {
cwspin(b4, 1); cwstep(b4); cwspin(b4, -3);
}
else {
cwstep(b4); cwspin(b4, -4); cwstep(b4); cwspin(b4, -4);
}
cellwalker cd(c, d);
cellwalker b1 = cd;
cellwalker b2 = nonbitrunc ? cd + wstep : cd + wstep + 3 + wstep + 3 + wstep;
cellwalker b3 = nonbitrunc ? cd - 1 + wstep + 3 : cd + wstep + 4 + wstep + 4;
cellwalker b4 = nonbitrunc ? cd + 1 + wstep - 3 : cd + wstep - 4 + wstep - 4;
if(mode == 0) {
if(!((checkBarriersBack(b1) && checkBarriersBack(b2)))) return false;
@ -643,19 +588,19 @@ bool buildBarrier4(cell *c, int d, int mode, eLand ll, eLand lr) {
c->bardir = d, c->barleft = ll, c->barright = xr; extendBarrierFront(c);
if(!nonbitrunc) for(int a=-3; a<=3; a++) if(a) {
setland(cwpeek(b1, a), a > 0 ? lr : ll);
setland(cwpeek(b2, a), a > 0 ? xr : xl);
setland(cwpeek(b3, a), a > 0 ? lr : xl);
setland(cwpeek(b4, a), a > 0 ? xr : ll);
setland((b1+a+wstep).c, a > 0 ? lr : ll);
setland((b2+a+wstep).c, a > 0 ? xr : xl);
setland((b3+a+wstep).c, a > 0 ? lr : xl);
setland((b4+a+wstep).c, a > 0 ? xr : ll);
}
if(nonbitrunc) setbarrier(b1.c), setbarrier(b2.c), setbarrier(b3.c), setbarrier(b4.c);
if(!nonbitrunc) {
cell *cp;
cp = cwpeek(b1, 0);
cp = (b1+wstep).c;
cp->barleft = ll; cp->barright = lr; setbarrier(cp);
cp = cwpeek(b2, 0);
cp = (b2+wstep).c;
cp->barleft = xl; cp->barright = xr; setbarrier(cp);
}

View File

@ -175,8 +175,7 @@ heptagon *createAlternateMap(cell *c, int rad, hstate firststate, int special) {
cell *cx[rad+1];
for(int i=0; i<rad; i++) {
cx[i] = bf.c;
cwrev(bf);
cwstep(bf);
bf += revstep;
}
cx[rad] = bf.c;
heptagon *h = bf.c->master;
@ -331,8 +330,8 @@ cell *buildAnotherEquidistant(cell *c, int radius) {
for(int i=0; i<size(coastpath); i++) coastpath[i]->item = itPirate;
return NULL;
}
cwstep(cw); cwspin(cw, 3);
if(ctof(cw.c) && hrand(2) == 0) cwspin(cw, 1);
cw = cw + wstep + 3;
if(ctof(cw.c) && hrand(2) == 0) cw++;
}
coastpath.push_back(cw.c);
// printf("setdists\n");

View File

@ -172,12 +172,7 @@ struct hrmap_spherical : hrmap {
heptspin hs;
hs.h = dodecahedron[i];
hs.spin = k;
hs = hsstep(hs, 0);
hs = hsspin(hs, S7-1);
hs = hsstep(hs, 0);
hs = hsspin(hs, S7-1);
hs = hsstep(hs, 0);
hs = hsspin(hs, S7-1);
hs = hs + wstep + (S7-1) + wstep + (S7-1) + wstep + (S7-1);
if(hs.h != dodecahedron[i]) printf("error %d,%d\n", i, k);
}
for(int i=0; i<spherecells(); i++) verifycells(dodecahedron[i]);
@ -558,8 +553,8 @@ namespace quotientspace {
code res;
res.c[0] = cod(hs.h);
for(int i=1; i<=S7; i++) {
res.c[i] = cod(hsstep(hs, 0).h);
hs = hsspin(hs, 1);
res.c[i] = cod((hs + wstep).h);
hs += 1;
}
return res;
}
@ -586,7 +581,7 @@ struct hrmap_quotient : hrmap {
if(!reachable.count(g)) {
reachable[g] = bfsq.size();
bfsq.push_back(hs);
add(hsspin(hs, 1));
add(hs + 1);
}
}
@ -605,7 +600,7 @@ struct hrmap_quotient : hrmap {
add(hs);
for(int i=0; i<(int)bfsq.size(); i++) {
hs = hsstep(bfsq[i], 0);
hs = bfsq[i] + wstep;
add(hs);
connections.push_back(reachable[get(hs)]);
}
@ -674,37 +669,59 @@ struct hrmap_quotient : hrmap {
cell *createMov(cell *c, int d);
void cwspin(cellwalker& cw, int d) {
cw.spin = (cw.spin+(MIRR(cw)?-d:d) + MODFIXER) % cw.c->type;
cellwalker& operator += (cellwalker& cw, int spin) {
cw.spin = (cw.spin+(MIRR(cw)?-spin:spin) + MODFIXER) % cw.c->type;
return cw;
}
cellwalker& operator += (cellwalker& cw, wstep_t) {
createMov(cw.c, cw.spin);
int nspin = cw.c->spn(cw.spin);
if(cw.c->mirror(cw.spin)) cw.mirrored = !cw.mirrored;
cw.c = cw.c->mov[cw.spin];
cw.spin = nspin;
return cw;
}
cellwalker& operator -= (cellwalker& cw, int i) { return cw += (-i); }
cellwalker& operator += (cellwalker& cw, wmirror_t) {
cw.mirrored = !cw.mirrored;
return cw;
}
template <class T> cellwalker operator + (cellwalker h, T t) { return h += t; }
template <class T> cellwalker operator - (cellwalker h, T t) { return h += (-t); }
cellwalker& operator ++ (cellwalker& h, int) { return h += 1; }
cellwalker& operator -- (cellwalker& h, int) { return h -= 1; }
bool cwstepcreates(cellwalker& cw) {
return cw.c->mov[cw.spin] == NULL;
}
/*
cell *cwpeek(cellwalker cw, int dir) {
return createMov(cw.c, (cw.spin+MODFIXER+(MIRR(cw)?-dir:dir)) % cw.c->type);
}
return (cw+dir+wstep).c;.
// return createMov(cw.c, (cw.spin+MODFIXER+(MIRR(cw)?-dir:dir)) % cw.c->type);
} */
void cwmirrorat(cellwalker& cw, int d) {
cw.spin = (d+d - cw.spin + MODFIXER) % cw.c->type;
cw.mirrored = !cw.mirrored;
}
void cwstep(cellwalker& cw) {
createMov(cw.c, cw.spin);
int nspin = cw.c->spn(cw.spin);
if(cw.c->mirror(cw.spin)) cw.mirrored = !cw.mirrored;
cw.c = cw.c->mov[cw.spin];
cw.spin = nspin;
static const struct rev_t { } rev;
cellwalker& operator += (cellwalker& cw, rev_t) {
cw += cw.c->type/2 + ((cw.c->type&1)?hrand(2):0);
return cw;
}
void cwrev(cellwalker& cw) {
cwspin(cw, cw.c->type/2 + ((cw.c->type&1)?hrand(2):0));
}
static const struct revstep_t { } revstep;
void cwrevstep(cellwalker& cw) {
cwrev(cw); cwstep(cw);
cellwalker& operator += (cellwalker& cw, revstep_t) {
cw += rev; cw += wstep; return cw;
}
// very similar to createMove in heptagon.cpp
@ -746,7 +763,7 @@ cell *createMov(cell *c, int d) {
*/
for(int u=2; u<S6; u+=2) {
hs = hsstep(hsspin(hs, alt3), -alt4);
hs = hs + alt3 + wstep - alt4;
merge(hs.h->c7, hs.spin, n, u, hs.mirrored);
}
@ -1171,15 +1188,17 @@ cdata *getHeptagonCdata(heptagon *h) {
hstab[7] = hs;
for(int i=8; i<12; i++) {
hstab[i] = hsspin(hstab[i-1], (i&1) ? 4 : 3);
hstab[i] = hsstep(hstab[i], 0);
hstab[i] = hsspin(hstab[i], (i&1) ? 3 : 4);
hstab[i] = hstab[i-1];
hstab[i] += ((i&1) ? 4 : 3);
hstab[i] += wstep;
hstab[i] += ((i&1) ? 3 : 4);
}
for(int i=6; i>=3; i--) {
hstab[i] = hsspin(hstab[i+1], (i&1) ? 3 : 4);
hstab[i] = hsstep(hstab[i], 0);
hstab[i] = hsspin(hstab[i], (i&1) ? 4 : 3);
hstab[i] = hstab[i+1];
hstab[i] += ((i&1) ? 3 : 4);
hstab[i] += wstep;
hstab[i] += ((i&1) ? 4 : 3);
}
if(hstab[3].h->distance < hstab[7].h->distance) {
@ -1205,7 +1224,7 @@ cdata *getHeptagonCdata(heptagon *h) {
break;
}
hs = hsstep(hsspin(hs, 3), 0);
hs = hs + 3 + wstep;
setHeptagonRval(hs.h);
affect(mydata, hs.spin ? hs.h->rval0 : hs.h->rval1, signum);

View File

@ -1101,52 +1101,25 @@ namespace mirror {
cell *c = cw.c;
for(int i=0; i<cw.c->type; i++) {
cwstep(cw);
if(cw.c->type == c->type) {
cwspin(cw, i);
createMirror(cw, cpid);
cwspin(cw, -i);
}
cwstep(cw);
cwspin(cw, 1);
auto cws = cw + wstep;
if(cws.c->type == c->type)
createMirror(cws+i, cpid);
cw += 1;
}
}
void createMirages(cellwalker cw, int cpid) {
if(nonbitrunc) {
for(int i=0; i<cw.c->type; i++) {
cellwalker C2 = cw;
cwstep(C2);
cwspin(C2, 3);
cwstep(C2);
cwspin(C2, 5);
cwstep(C2);
cwspin(C2, 3);
cwspin(C2, -i);
createMirror(C2, cpid);
cwspin(cw, 1);
}
for(int i=0; i<cw.c->type; i++)
createMirror(cw + i + wstep + 3 + wstep + 5 + wstep + 3 - i, cpid);
return;
}
for(int i=0; i<S6; i++) {
cwstep(cw);
if(!ctof(cw.c)) {
cwspin(cw, 2);
cwstep(cw);
cwspin(cw, S6-2-i);
createMirror(cw, cpid);
cwspin(cw, 2+i);
cwstep(cw);
cwspin(cw, S6-4);
cwstep(cw);
cwspin(cw, 2-i);
createMirror(cw, cpid);
cwspin(cw, S6-2+i);
cwstep(cw);
cwspin(cw, 2);
auto cw0 = cw + i + wstep;
if(!ctof(cw0.c)) {
createMirror(cw0 + 2 + wstep - (2+i), cpid);
createMirror(cw0 - 2 + wstep + (2-i), cpid);
}
cwstep(cw);
cwspin(cw, 1);
}
}
@ -1174,7 +1147,7 @@ namespace mirror {
bool isKilledByMirror(cell *c) {
for(auto& m: mirrors) {
cell *c1 = cwpeek(m.second, 0);
cell *c1 = (m.second + wstep).c;
if(inmirror(c1)) c1 = reflect(cellwalker(c1, 0, false)).c;
if(c1 == c && canAttack(m.second.c, moMimic, c, c->monst, 0))
return true;
@ -1193,8 +1166,7 @@ namespace mirror {
if(m.first == multi::cpid) {
cell *c = m.second.c;
if(!m.second.mirrored) nummirage++;
auto cw2 = m.second;
cwstep(cw2);
auto cw2 = m.second + wstep;
if(inmirror(cw2)) cw2 = reflect(cw2);
cell *c2 = cw2.c;
if(c2->monst) {
@ -1241,7 +1213,7 @@ namespace mirror {
if(spinning && d) {
for(auto& m: mirrors)
if(m.first == multi::cpid)
cwspin(m.second, d);
m.second += d;
}
if(flags & ATTACK)
go(flags & GO);
@ -1281,9 +1253,9 @@ namespace mirror {
pair<bool, cellwalker> traceback(vector<int>& v, cellwalker cw) {
bool goout = false;
for(int i=size(v)-1; i>=0; i--) {
if(v[i]) cwspin(cw, -v[i]);
if(v[i]) cw -= v[i];
else {
cwstep(cw);
cw += wstep;
if(cw.c->land == laMirrorWall || cw.c->land == laMirror) goout = true;
}
}
@ -1302,67 +1274,67 @@ namespace mirror {
stepcount++; if(stepcount > 10000) {
return cw;
}
cell *c0 = cwpeek(cw, 0);
cell *c0 = (cw+wstep).c;
int go = 0;
if(!inmirror(c0)) go = 2;
else if(depth(c0) && depth(c0) < depth(cw.c)) go = 1;
if(go) {
v.push_back(0);
cwstep(cw);
cw += wstep;
if(go == 2) break;
}
else {
v.push_back(1);
cwspin(cw, 1);
cw += 1;
}
}
if(cw.c->land == laMirrorWall || cw.c->land == laMirrorWall2) {
if(cw.c->type == 7) {
while(cw.spin != cw.c->bardir) {
cwspin(cw, 1);
cw += 1;
v.push_back(1);
stepcount++; if(stepcount > 10000) { printf("failhep\n"); return cw; }
}
if(nonbitrunc && cwpeek(cw,0) == cwcopy.c)
if(nonbitrunc && (cw+wstep).c == cwcopy.c)
v.pop_back();
if(nonbitrunc && cwpeek(cw,3)->land == laMirrored && cwpeek(cw,2)->land == laMirrorWall) {
cw.mirrored = !cw.mirrored;
if(nonbitrunc && (cw+3+wstep).c->land == laMirrored && (cw+2+wstep).c->land == laMirrorWall) {
cw += wmirror;
auto p = traceback(v, cw);
if(p.first) return p.second;
cwspin(cw, 2);
cw += 2;
v.push_back(2);
cwstep(cw);
cw += wstep;
v.push_back(0);
cwspin(cw, 3);
cw += 3;
v.push_back(3);
}
}
else {
while(cwpeek(cw,0)->type != 7) {
cwspin(cw, 1);
while((cw+wstep).c->type != 7) {
cw ++;
v.push_back(1);
}
int icount = 0;
for(int i=0; i<3; i++) {
if(cwpeek(cw, 0)->bardir == cw.c->spin(cw.spin))
if((cw+wstep).c->bardir == cw.c->spin(cw.spin))
icount++;
cwspin(cw, 2);
cw += 2;
}
if(icount >= 2) {
cellwalker cwcopy = cw;
for(int a=0; a<3; a++) for(int m=0; m<2; m++) {
cellwalker cw = cwcopy;
if(m) cw.mirrored = !cw.mirrored;
cwspin(cw, a*2);
cw += (a*2);
auto p = traceback(v,cw);
if(p.first) return p.second;
}
printf("icount >= 2 but failed\n");
return cw;
}
while(cwpeek(cw, 0)->bardir != cw.c->spin(cw.spin)) {
while((cw+wstep).c->bardir != cw.c->spin(cw.spin)) {
stepcount++; if(stepcount > 10000) { printf("fail2\n"); return cw; }
cwspin(cw, 2);
cw += 2;
v.push_back(1);
v.push_back(1);
}
@ -1405,8 +1377,7 @@ namespace mirror {
while(inmirror(cache[cid].second.c) && tries--)
cache[cid].second = reflect0(cache[cid].second);
}
cellwalker res = cache[cid].second;
cwspin(res, cw.spin);
cellwalker res = cache[cid].second + cw.spin;
if(cw.mirrored) res.mirrored = !res.mirrored;
return res;
}
@ -1733,10 +1704,10 @@ namespace hive {
for(int i=2; i<radius; i++) {
if(bf.c->type == 6)
cwspin(bf, 3);
bf += 3;
else
cwspin(bf, 3 + hrand(2));
cwstep(bf);
bf += 3 + hrand(2);
bf += wstep;
}
cell *citycenter = bf.c;
buginfo.clear();

View File

@ -198,7 +198,7 @@ bool applyCheat(char u, cell *c = NULL) {
if(u == 'Z') {
flipplayer = false;
mirror::act(1, mirror::SPINSINGLE);
cwspin(cwt, 1);
cwt++;
wavephase = (1+wavephase) & 7;
return true;
}

View File

@ -3176,12 +3176,12 @@ array<cell*, 5> traplimits(cell *c) {
res[2] = c;
for(int d=0; d<c->type; d++) {
cellwalker cw(c, d);
cwstep(cw);
cw += wstep;
if(cw.c->wall != waArrowTrap) continue;
res[1+q*2] = cw.c;
cwspin(cw, cw.c->type/2);
if((cw.c->type&1) && cwpeek(cw, 0)->wall != waStone) cwspin(cw, 1);
cwstep(cw);
cw += (cw.c->type/2);
if((cw.c->type&1) && (cw+wstep).c->wall != waStone) cw += 1;
cw += wstep;
res[(q++)*4] = cw.c;
}
while(q<2) { res[q*4] = res[1+q*2] = NULL; q++; }
@ -3790,12 +3790,12 @@ void determinizeBull(cell *c, int *posdir, int& nc) {
int determinizeBullPush(cellwalker bull) {
int nc = 2;
int dirs[2], positive;
cwstep(bull);
bull += wstep;
cell *c2 = bull.c;
if(!(c2->type & 1)) return 1; // irrelevant
int d = c2->type / 2;
cwspin(bull, d); dirs[0] = positive = bull.spin;
cwspin(bull, -2*d); dirs[1] = bull.spin;
bull += d; dirs[0] = positive = bull.spin;
bull -= 2*d; dirs[1] = bull.spin;
determinizeBull(c2, dirs, nc);
if(dirs[0] == positive) return -1;
return 1;
@ -3854,24 +3854,22 @@ cell *determinePush(cellwalker who, cell *c2, int subdir, T valid) {
addMessage("bad push: " + its(subdir));
}
cellwalker push = who;
cwstep(push);
push += wstep;
int pd = push.c->type/2;
cwspin(push, pd * -subdir);
cwstep(push);
push += pd * -subdir;
push += wstep;
if(valid(push.c)) return push.c;
if(c2->type&1) {
cwstep(push);
cwspin(push, 1 * -subdir);
cwstep(push);
push = push + wstep - subdir + wstep;
if(valid(push.c)) return push.c;
}
if(gravityLevel(push.c) < gravityLevel(c2)) {
cwstep(push); cwspin(push, 1); cwstep(push);
push = push + wstep + 1 + wstep;
if(gravityLevel(push.c) < gravityLevel(c2)) {
cwstep(push); cwspin(push, -2); cwstep(push);
push = push + wstep - 2 + wstep;
}
if(gravityLevel(push.c) < gravityLevel(c2)) {
cwstep(push); cwspin(push, 1); cwstep(push);
push = push + wstep + 1 + wstep;
}
if(valid(push.c)) return push.c;
}
@ -4290,21 +4288,21 @@ void ivynext(cell *c) {
cw.c->monst = moIvyWait;
bool findleaf = false;
while(true) {
cwspin(cw, 1);
cw += 1;
if(cw.spin == signed(cw.c->mondir)) {
if(findleaf) {
cw.c->monst = moIvyHead; break;
}
cw.c->monst = moIvyWait;
cwstep(cw);
cw += wstep;
continue;
}
cwstep(cw);
cw += wstep;
if(cw.c->monst == moIvyWait && signed(cw.c->mondir) == cw.spin) {
cw.c->monst = moIvyBranch;
findleaf = true; continue;
}
cwstep(cw);
cw += wstep;
}
}
@ -7259,7 +7257,7 @@ bool movepcto(int d, int subdir, bool checkonly) {
if(!checkonly) { DEBB(DF_TURN, (debugfile,"movepc\n")); }
int origd = d;
if(d >= 0) {
cwspin(cwt, d);
cwt += d;
mirror::act(d, mirror::SPINSINGLE);
d = cwt.spin;
}
@ -7775,7 +7773,7 @@ bool movepcto(int d, int subdir, bool checkonly) {
stabbingAttack(cwt.c, c2, moPlayer);
cell *c1 = cwt.c;
cwstep(cwt);
cwt += wstep;
if(switchplaces)
animateReplacement(c1, cwt.c, LAYER_SMALL);
else

View File

@ -2029,8 +2029,8 @@ bool drawMonster(const transmatrix& Vparam, int ct, cell *c, int col) {
multi::cpid = m.first;
auto cw = m.second;
if(d&1) cwmirrorat(cw, xdir);
if(d>=2) cwspin(cw, 2);
if(d>=4) cwspin(cw, 2);
if(d>=2) cw += 2;
if(d>=4) cw += 2;
transmatrix Vs = Vparam;
bool mirr = cw.mirrored;
Vs = Vs * ddspin(c, cw.spin-cwt.spin, euclid ? 0 : S42);
@ -2538,7 +2538,7 @@ void drawMovementArrows(cell *c, transmatrix V) {
movedir md = vectodir(spin(-d * M_PI/4) * tC0(pushone()));
int u = md.d;
cellwalker xc = cwt; cwspin(xc, u); cwstep(xc);
cellwalker xc = cwt + u + wstep;
if(xc.c == c) {
transmatrix fixrot = rgpushxto0(tC0(V));
// make it more transparent

View File

@ -171,22 +171,23 @@ extern int hrand(int);
// a structure used to walk on the heptagonal tesselation
// (remembers not only the heptagon, but also direction)
heptspin hsstep(const heptspin &hs, int spin) {
heptspin& operator += (heptspin& hs, int spin) {
hs.spin = fixrot(hs.spin + (MIRR(hs)?-spin:spin));
return hs;
}
heptspin operator + (const heptspin& hs, wstep_t) {
createStep(hs.h, hs.spin);
heptspin res;
res.h = hs.h->move[hs.spin];
res.mirrored = hs.mirrored ^ hs.h->mirror(hs.spin);
res.spin = fixrot(hs.h->spin(hs.spin) + (MIRR(res)?-spin:spin));
res.spin = hs.h->spin(hs.spin);
return res;
}
heptspin hsspin(const heptspin &hs, int val) {
heptspin res;
res.h = hs.h;
res.spin = fixrot(hs.spin + (MIRR(hs)?-val:val));
res.mirrored = hs.mirrored;
return res;
}
heptspin operator + (heptspin h, int spin) { return h += spin; }
heptspin operator - (heptspin h, int spin) { return h += -spin; }
heptspin& operator += (heptspin& h, wstep_t) { h = h + wstep; return h; }
heptagon *createStep(heptagon *h, int d) {
d = fixrot(d);
@ -211,9 +212,7 @@ heptagon *createStep(heptagon *h, int d) {
hs.h = h;
hs.spin = 0;
hs.mirrored = false;
hs = hsstep(hs, -1);
hs = hsstep(hs, -1);
hs = hsstep(hs, -1);
hs = hs + wstep - 1 + wstep - 1 + wstep - 1;
connectHeptagons(h, d, hs.h, hs.spin);
}
else if(h->s == hsB && d == S7-1) {
@ -221,9 +220,7 @@ heptagon *createStep(heptagon *h, int d) {
hs.h = h;
hs.spin = 0;
hs.mirrored = false;
hs = hsstep(hs, 1);
hs = hsstep(hs, 1);
hs = hsstep(hs, 1);
hs = hs + wstep + 1 + wstep + 1 + wstep + 1;
connectHeptagons(h, d, hs.h, hs.spin);
}
else

59
hyper.h
View File

@ -56,6 +56,52 @@ inline transmatrix operator * (const transmatrix& T, const transmatrix& U) {
return R;
}
hyperpoint hpxyz(ld x, ld y, ld z);
namespace hyperpoint_vec {
inline hyperpoint& operator *= (hyperpoint& h, ld d) {
h[0] *= d; h[1] *= d; h[2] *= d;
return h;
}
inline hyperpoint& operator /= (hyperpoint& h, ld d) {
h[0] /= d; h[1] /= d; h[2] /= d;
return h;
}
inline hyperpoint operator += (hyperpoint& h, hyperpoint h2) {
for(int i: {0,1,2}) h[i] += h2[i];
return h;
}
inline hyperpoint operator -= (hyperpoint& h, hyperpoint h2) {
for(int i: {0,1,2}) h[i] -= h2[i];
return h;
}
inline hyperpoint operator * (ld d, hyperpoint h) { return h *= d; }
inline hyperpoint operator * (hyperpoint h, ld d) { return h *= d; }
inline hyperpoint operator / (hyperpoint h, ld d) { return h /= d; }
inline hyperpoint operator + (hyperpoint h, hyperpoint h2) { return h += h2; }
inline hyperpoint operator - (hyperpoint h, hyperpoint h2) { return h -= h2; }
// cross product
inline hyperpoint operator ^ (hyperpoint h1, hyperpoint h2) {
return hpxyz(
h1[1] * h2[2] - h1[2] * h2[1],
h1[2] * h2[0] - h1[0] * h2[2],
h1[0] * h2[1] - h1[1] * h2[0]
);
}
// inner product
inline ld operator | (hyperpoint h1, hyperpoint h2) {
return h1[0] * h2[0] + h1[1] * h2[1] + h1[2] * h2[2];
}
}
extern int cellcount, heptacount;
// cell information for the game
@ -2083,11 +2129,7 @@ struct polytodraw {
extern int emeraldtable[100][7];
extern void cwspin(cellwalker& cw, int d);
extern cell *cwpeek(cellwalker cw, int dir);
extern void cwstep(cellwalker& cw);
extern void cwrevstep(cellwalker& cw);
extern void cwrev(cellwalker& cw);
// extern cell *cwpeek(cellwalker cw, int dir);
const eLand NOWALLSEP = laNone;
const eLand NOWALLSEP_USED = laWhirlpool;
@ -2384,7 +2426,12 @@ extern int startseed;
extern transmatrix heptmove[MAX_EDGE], hexmove[MAX_EDGE];
extern transmatrix invheptmove[MAX_EDGE], invhexmove[MAX_EDGE];
heptspin hsstep(const heptspin &hs, int spin);
static const struct wstep_t { } wstep;
static const struct wmirror_t { } wmirror;
// heptspin hsstep(const heptspin &hs, int spin);
template<class T>
extern void fixmatrix(transmatrix&);
void display(const transmatrix& T);

View File

@ -450,49 +450,6 @@ double hdist(const hyperpoint& h1, const hyperpoint& h2) {
}
}
namespace hyperpoint_vec {
hyperpoint& operator *= (hyperpoint& h, ld d) {
h[0] *= d; h[1] *= d; h[2] *= d;
return h;
}
hyperpoint& operator /= (hyperpoint& h, ld d) {
h[0] /= d; h[1] /= d; h[2] /= d;
return h;
}
hyperpoint operator += (hyperpoint& h, hyperpoint h2) {
for(int i: {0,1,2}) h[i] += h2[i];
return h;
}
hyperpoint operator -= (hyperpoint& h, hyperpoint h2) {
for(int i: {0,1,2}) h[i] -= h2[i];
return h;
}
hyperpoint operator * (ld d, hyperpoint h) { return h *= d; }
hyperpoint operator * (hyperpoint h, ld d) { return h *= d; }
hyperpoint operator / (hyperpoint h, ld d) { return h /= d; }
hyperpoint operator + (hyperpoint h, hyperpoint h2) { return h += h2; }
hyperpoint operator - (hyperpoint h, hyperpoint h2) { return h -= h2; }
// cross product
hyperpoint operator ^ (hyperpoint h1, hyperpoint h2) {
return hpxyz(
h1[1] * h2[2] - h1[2] * h2[1],
h1[2] * h2[0] - h1[0] * h2[2],
h1[0] * h2[1] - h1[1] * h2[0]
);
}
// inner product
ld operator | (hyperpoint h1, hyperpoint h2) {
return h1[0] * h2[0] + h1[1] * h2[1] + h1[2] * h2[2];
}
}
hyperpoint mscale(const hyperpoint& t, double fac) {
hyperpoint res;
for(int i=0; i<3; i++)

View File

@ -378,7 +378,7 @@ void drawrec(const heptspin& hs, int lev, hstate s, const transmatrix& V) {
for(int d=0; d<S7; d++) {
hstate s2 = transition(s, d);
if(s2 == hsError) continue;
heptspin hs2 = hsstep(hsspin(hs, d), 0);
heptspin hs2 = hs + d + wstep;
drawrec(hs2, lev-2, s2, V * heptmove[d]);
}
@ -566,8 +566,7 @@ void optimizeview() {
if(turn >= 0) {
View = View * TB;
fixmatrix(View);
viewctr = hsspin(viewctr, turn);
viewctr = hsstep(viewctr, 0);
viewctr = viewctr + turn + wstep;
}
}

View File

@ -300,8 +300,7 @@ struct cellcrawler {
for(int i=0; i<size(data); i++) {
cellwalker cw0 = data[i].orig;
for(int j=0; j<cw0.c->type; j++) {
cellwalker cw = cw0;
cwspin(cw, j); cwstep(cw);
cellwalker cw = cw0 + j + wstep;
if(!getNeuron(cw.c)) continue;
store(cw, i, j);
}
@ -317,9 +316,9 @@ struct cellcrawler {
cellcrawlerdata& s = data[i];
s.target = data[s.from].target;
if(!s.target.c) continue;
cwspin(s.target, s.spin);
s.target += s.spin;
if(cwstepcreates(s.target)) s.target.c = NULL;
else cwstep(s.target);
else s.target += wstep;
}
}
};

View File

@ -274,15 +274,7 @@ void giantLandSwitch(cell *c, int d, cell *from) {
cell *c2 = NULL;
for(int i=0; i<c->type; i++) {
cellwalker cw(c, i);
cwstep(cw);
cwspin(cw, 4);
cwstep(cw);
cwspin(cw, 2);
cwstep(cw);
cwspin(cw, 4);
cwstep(cw);
cwspin(cw, 2 + hrand(3));
cwstep(cw);
cw = cw + wstep + 4 + wstep + 2 + wstep + 4 + wstep + (2 + hrand(3)) + wstep;
if(!c2) c2 = cw.c;
else if(celldist(cw.c) > celldist(c2)) c2 = cw.c;
cw.c->monst = moMouse;
@ -904,8 +896,8 @@ void giantLandSwitch(cell *c, int d, cell *from) {
cell* cc[5];
cc[2] = c;
cellwalker cw2 = cw;
cwstep(cw); cc[3] = cw.c; cwrevstep(cw); cc[4] = cw.c;
cwrevstep(cw2); cc[1] = cw2.c; cwrevstep(cw2); cc[0] = cw2.c;
cw += wstep; cc[3] = cw.c; cw += revstep; cc[4] = cw.c;
cw2 += revstep; cc[1] = cw2.c; cw2 += revstep; cc[0] = cw2.c;
bool ok = true;
for(int i=0; i<5; i++) {
if(cc[i]->land != laNone && cc[i]->land != laTerracotta) ok = false;
@ -1681,10 +1673,9 @@ void giantLandSwitch(cell *c, int d, cell *from) {
vector<pair<cell*, cell*>> next;
int bonus = c->type - 4;
for(int i=0; i<c->type; i++) {
cellwalker cw0(c, i);
cwstep(cw0); cwrevstep(cw0);
cellwalker cw1(c, i+bonus);
cwspin(cw1, 0); cwstep(cw1); cwrevstep(cw1);
cellwalker ci(c, i);
cellwalker cw0 = ci + wstep + revstep;
cellwalker cw1 = ci + bonus + wstep + revstep;
if(cw0.c->mpdist > 7)
if(cw1.c->mpdist > 7)
next.emplace_back(cw0.c, cw1.c);

View File

@ -621,11 +621,11 @@ namespace mapeditor {
auto sd = spill_list[i];
for(int i=0; i<sd.first.c->type; i++) {
auto sd2 = sd;
cwspin(sd2.first, i); cwstep(sd2.first);
sd2.first = sd2.first + i + wstep;
if(eq(sd2.first.c->aitmp, sval)) continue;
sd2.first.c->aitmp = sval;
if(sd2.second.c) {
cwspin(sd2.second, i); cwstep(sd2.second);
sd2.second = sd2.second + i + wstep;
if(sd2.second.c->land == laNone) continue;
}
spill_list.push_back(sd2);
@ -663,7 +663,7 @@ namespace mapeditor {
if(where.c->type != copysource.c->type) return;
if(where.spin<0) where.spin=0;
if(!nonbitrunc && !ctof(mouseover) && ((where.spin&1) != (copysource.spin&1)))
cwspin(where, 1);
where += 1;
}
if(painttype != 4) copysource.c = NULL;
list_spill(where, copysource);

View File

@ -353,7 +353,7 @@ void castLightningBolt(cellwalker lig) {
if(lig.c->mov[lig.spin] == NULL) break;
cwstep(lig);
lig += wstep;
if(inmirror(lig)) lig = mirror::reflect(lig);
cell *c = lig.c;
@ -440,7 +440,7 @@ void castLightningBolt(cellwalker lig) {
drawParticles(c, winf[ow].color, 16);
if(c == cwt.c) {bnc++; if(bnc > 10) break; }
if(spin) cwspin(lig, hrand(lig.c->type));
if(spin) lig += hrand(lig.c->type);
if(brk) break;
@ -449,14 +449,13 @@ void castLightningBolt(cellwalker lig) {
int right = 1;
while(!reflectingBarrierAt(lig, left)) left--;
while(!reflectingBarrierAt(lig, right)) right++;
cwspin(lig, right + left);
lig += right + left;
if(c->wall == waBarrowWall) c->wall = waBarrowDig;
else if(c->wall == waBarrowDig) c->wall = waNone;
bnc++; if(bnc > 10) break;
}
else {
cwrev(lig);
}
else
lig += rev;
if(lig.c->wall == waCloud) {
lig.c->wall = waNone;

View File

@ -131,13 +131,9 @@ void patternFiftyAt(cell *c) {
for(int i=0; i<c->type; i++) {
cellwalker cw(c, i);
cwstep(cw); // cw.c->item = itSilver;
cwspin(cw, 4); // 6
cwstep(cw); // cw.c->item = itSilver;
cwspin(cw, 3); // 6
cwstep(cw); cw.c->wall = waFloorA; cwstep(cw);
cwspin(cw, 1);
cwstep(cw); cw.c->wall = waFloorA; cwstep(cw);
cellwalker cw1 = cw + wstep + 4 + wstep;
(cw1+3+wstep).c->wall = waFloorA;
(cw1+4+wstep).c->wall = waFloorA;
}
}
@ -183,23 +179,13 @@ void patternFiftyAt(cell *c) {
}
for(int i=0; i<c->type; i++) {
cellwalker cw(c, sw);
cwspin(cw, sgn1 * i);
cwstep(cw);
cwspin(cw, sgn*4);
cwstep(cw);
auto cw = cellwalker(c, sw) + (sgn1 * i) + wstep + (sgn * 4) + wstep;
if(cw.spin < 0 || cw.spin >= 7 || cw.c->type != 7) exit(1);
encode(cw.c, s, 1+i, cw.spin);
}
for(int i=0; i<c->type; i++) {
cellwalker cw(c, sw);
cwspin(cw, sgn1 * i);
cwstep(cw);
cwspin(cw, 3);
cwstep(cw);
cwspin(cw, 3);
cwstep(cw);
auto cw = cellwalker(c, sw) + (sgn1 * i) + wstep + 3 + wstep + 3 + wstep;
if(cw.spin < 0 || cw.spin >= 7 || cw.c->type != 7) exit(1);
encode(cw.c, s, 8+i, cw.spin);
}
@ -208,28 +194,28 @@ void patternFiftyAt(cell *c) {
for(int i=0; i<c->type; i++) {
cellwalker cw(c, s.wc2);
cwspin(cw, sgn1 * i);
cwstep(cw);
cw += (sgn1 * i);
cw += wstep;
if(style == 0) cw.c->wall = waCamelot;
// cw.c->item = itSilver;
cwspin(cw, sgn*4); //6
cwstep(cw); if(style == 0) cw.c->wall = waFloorA;
cw += (sgn*4); //6
cw += wstep; if(style == 0) cw.c->wall = waFloorA;
// cw.c->item = itSilver;
cwspin(cw, sgn*4); //7
cwstep(cw); if(style == 0) cw.c->wall = waFloorA;
cw += (sgn*4); //7
cw += wstep; if(style == 0) cw.c->wall = waFloorA;
// cw.c->item = itSilver;
cwspin(cw, 3); //6
cwstep(cw); if(style == 0) cw.c->wall = waFloorA;
cw += (3); //6
cw += wstep; if(style == 0) cw.c->wall = waFloorA;
// cw.c->item = itSilver;
cwspin(cw, 3); //6
cwstep(cw); if(style == 0) cw.c->wall = waFloorA;
cw += (3); //6
cw += wstep; if(style == 0) cw.c->wall = waFloorA;
// cw.c->item = itSilver;
cwspin(cw, sgn*3); //7
cwstep(cw); if(style == 0) cw.c->wall = waCamelot;
cw += (sgn*3); //7
cw += wstep; if(style == 0) cw.c->wall = waCamelot;
// cw.c->item = itSilver;
cwspin(cw, sgn*2); //6
cwstep(cw); // cw.c->item = itGold;
cw += (sgn*2); //6
cw += wstep; // cw.c->item = itGold;
// setdist(cw.c, 8, NULL);
state50 s2 = s; s2.polarity1 = !s.polarity1;
s2.wc2 = (cw.spin + sgn1 * i + sgn + 42) % 7;
@ -243,26 +229,26 @@ void patternFiftyAt(cell *c) {
for(int i=0; i<c->type; i++) {
cellwalker cw(c, s.wc2);
cwspin(cw, sgn1 * i);
cwstep(cw); // cw.c->item = itSilver;
cw += (sgn1 * i);
cw += wstep; // cw.c->item = itSilver;
// cw.c->item = itDiamond;
cwspin(cw, 3); // 6
cwstep(cw); // cw.c->item = itSilver;
cw += (3); // 6
cw += wstep; // cw.c->item = itSilver;
// cw.c->item = itDiamond;
cwspin(cw, sgn*4); // 6
cwstep(cw); // cw.c->item = itSilver;
cw += (sgn*4); // 6
cw += wstep; // cw.c->item = itSilver;
// cw.c->item = itDiamond;
cwspin(cw, sgn*2); // 6
cwstep(cw); // cw.c->item = itSilver;
cw += (sgn*2); // 6
cw += wstep; // cw.c->item = itSilver;
// cw.c->item = itDiamond;
cwspin(cw, 3); // 6
cwstep(cw); // cw.c->item = itSilver;
cw += (3); // 6
cw += wstep; // cw.c->item = itSilver;
// cw.c->item = itDiamond;
cwspin(cw, sgn*3); // 7
cwstep(cw); // cw.c->item = itSilver;
cw += (sgn*3); // 7
cw += wstep; // cw.c->item = itSilver;
// cw.c->item = itDiamond;
cwspin(cw, sgn*4); // 6
cwstep(cw); // cw.c->item = itSilver;
cw += (sgn*4); // 6
cw += wstep; // cw.c->item = itSilver;
// setdist(cw.c, 8, NULL);
state50 s2 = s;
s2.polarity2 = !s.polarity2;
@ -343,28 +329,28 @@ void zebra(cellwalker cwb, int it, int type, string pathcode, int xmods) {
cwb.c->wall = w;
for(int i=0; i<6; i+=2) {
cellwalker cw = cwb;
cwspin(cw, i);
cw += (i);
cw.c->heat = 4 + type + 4 * 9;
cwstep(cw); cwspin(cw, 3); cw.c->wall = w;
cw += wstep; cw += (3); cw.c->wall = w;
int i0 = i; if(type&2 && i0) i0 = 6-i0; i0 /= 2;
cw.c->heat = 4 + type + 4 * (3+i0);
cwstep(cw); cwspin(cw, 3); cw.c->wall = w;
cw += wstep; cw += (3); cw.c->wall = w;
cw.c->heat = 4 + type + 4 * i0;
cwstep(cw); cwspin(cw, 3); cw.c->wall = w;
cw += wstep; cw += (3); cw.c->wall = w;
cw.c->heat = 4 + type + 4 * (6+i0);
cwstep(cw); cwspin(cw, -3);
cwstep(cw); cwspin(cw, -3);
cwstep(cw); cwspin(cw, -3);
cwstep(cw); cwspin(cw, -i);
cwspin(cw, 0);
cw += wstep; cw += (-3);
cw += wstep; cw += (-3);
cw += wstep; cw += (-3);
cw += wstep; cw += (-i);
cw += (0);
setzebra(cw, it-1, type ^ 1, pathcode +'+'+char('A'+i)+char('0'+type), xmods*2);
}
for(int i=0; i<6; i+=2) {
cellwalker cw = cwb;
cwspin(cw, (type&2)?-i:i);
cwstep(cw); cwspin(cw, 3);
cwstep(cw); cwspin(cw, 5);
cw += ((type&2)?-i:i);
cw += wstep; cw += (3);
cw += wstep; cw += (5);
if(xmods < 2) {
if(cw.c->item && cw.c->item != (1+i) && redraw && i==0) {
qconflict++;
@ -375,15 +361,15 @@ void zebra(cellwalker cwb, int it, int type, string pathcode, int xmods) {
// cw.c->item = eItem(1 + i);
// cw.c->heat = 4 + type + 4 * (i/2);
}
cwstep(cw); cwspin(cw, 1);
cw += wstep; cw += (1);
if(type < 2) {
// cwspin(cw, i);
cwspin(cw, i);
// cw += (i);
cw += (i);
}
else {
cwspin(cw, -i);
cw += (-i);
}
// cwspin(cw, ((Q >> (4*type)) & 12));
// cw += (((Q >> (4*type)) & 12));
setzebra(cw, it-1, 2^type, pathcode + '+'+char('a'+i)+char('0'+type), xmods+1);
}
}
@ -395,7 +381,7 @@ void zebraPattern() {
if((Q & (Q>>1)) & 0x5555) continue;
qconflict = false;
cellwalker cw(cwt);
cwstep(cw); cwspin(cw, 1);
cw += wstep; cw += (1);
qconflict = 0;
allconflict = "";
zebra(cw, 3, 0, "");
@ -407,7 +393,7 @@ void zebraPattern() {
Q = 0xFFFB; */
cellwalker cw(cwt);
cwstep(cw); cwspin(cw, 1);
cw += wstep; cw += (1);
setzebra(cw, 7, 0, "", -999);
// cw.c->
// printf("Conflicts: %d\n", qconflict);

View File

@ -537,18 +537,18 @@ namespace sag {
else {
cellwalker cw = cwt;
setsnake(cw, 0);
cwstep(cw);
cw += wstep;
setsnake(cw, 1);
for(int i=2; i<=numsnake; i++) {
if(i == numsnake && sphere) break;
cwstep(cw);
cw += wstep;
snakefirst[i-1] = cw.c->landparam;
while(cw.c->wparam == INSNAKE) {
snakelast[i-1] = cw.c->landparam;
cwstep(cw); cwspin(cw, 1); cwstep(cw);
cw = cw + wstep + 1 + wstep;
}
if(i == numsnake) break;
setsnake(cw, i); cwspin(cw, 1);
setsnake(cw, i); cw += 1;
}
}
int stab = min(numsnake, MAXSNAKETAB);

View File

@ -602,9 +602,7 @@ void buildRug() {
rugpoint *w2 = vptr.at(c3);
if(a4) {
cellwalker cw(c, j);
cwstep(cw); cwspin(cw, -1); cwstep(cw);
cell *c4 = cw.c;
cell *c4 = (cellwalker(c,j) + wstep - 1 + wstep).c;
cell *cm = c; comp(cm, c); comp(cm, c2); comp(cm, c3); comp(cm, c4);
if(cm == c || cm == c4)
addTriangle(v, w, w2);

View File

@ -720,7 +720,8 @@ void handleInput(int delta) {
int dir = multi::whereto[i].d;
if(dir == MD_UNDECIDED) return NULL;
if(dir == MD_USE_ORB) return multi::whereto[i].tgt;
if(dir >= 0) { cwspin(cwti, dir); cwstep(cwti); }
if(dir >= 0)
cwti = cwti + dir + wstep;
return cwti.c;
}
@ -1653,11 +1654,9 @@ void movePlayer(monster *m, int delta) {
}
visibleFor(300);
cellwalker push(c2, dirfromto(c2, m->base));
cwspin(push, 3 * -subdir); cwstep(push);
push = push + 3 * (-subdir) + wstep;
if(!canPushThumperOn(push.c, c2, m->base) && c2->type == 7) {
cwstep(push);
cwspin(push, 1 * -subdir);
cwstep(push);
push = push + wstep - subdir + wstep;
}
if(!canPushThumperOn(push.c, c2, m->base)) {
go = false;
@ -3457,7 +3456,7 @@ void virtualRebase(cell*& base, transmatrix& at, bool tohex) {
heptspin hs;
hs.h = h;
hs.spin = d;
heptspin hs2 = hsstep(hs, 0);
heptspin hs2 = hs + wstep;
transmatrix V2 = spin((nonbitrunc?M_PI:0)-hs2.spin*2*M_PI/S7) * invheptmove[d];
if(nonbitrunc) V2 = V2 * spin(M_PI);
double newz = (V2 * at * C0) [2];

View File

@ -189,17 +189,17 @@ namespace yendor {
in_endorian = false;
nyi.path[i] = lig.c;
cwstep(lig);
lig += wstep;
if(inmirror(lig)) lig = mirror::reflect(lig);
cwspin(lig, 3);
lig += 3;
if(lig.c->type == 7) {
if(in_endorian && endorian_change && i >= YDIST - 20) {
// make the last leg a bit more difficult
cwspin(lig, hrand(2)*3-1);
lig += (hrand(2)*3-1);
endorian_change = false;
}
else
cwspin(lig, hrand(2));
lig += hrand(2);
}
}
nyi.path[YDIST-1] = lig.c;