From d7e2b491acebe4dd8747994b6655c3ec2b7d8c67 Mon Sep 17 00:00:00 2001 From: Zeno Rogue Date: Sat, 29 May 2021 15:44:07 +0200 Subject: [PATCH] determinePush now accepts movei instead of c --- game.cpp | 4 +++- mapeffects.cpp | 11 +++++++---- monstermove.cpp | 4 ++-- pcmove.cpp | 6 +++--- shmup.cpp | 2 +- 5 files changed, 16 insertions(+), 11 deletions(-) diff --git a/game.cpp b/game.cpp index 8b27c005..a035ad41 100644 --- a/game.cpp +++ b/game.cpp @@ -402,7 +402,9 @@ EX void pushThumper(const movei& mi) { cto->wparam = th->wparam; } -EX bool canPushThumperOn(cell *tgt, cell *thumper, cell *player) { +EX bool canPushThumperOn(movei mi, cell *player) { + cell *thumper = mi.s; + cell *tgt = mi.t; if(among(thumper->wall, waRichDie, waHappyDie) && ctof(tgt)) return false; if(tgt->wall == waBoat || tgt->wall == waStrandedBoat) return false; diff --git a/mapeffects.cpp b/mapeffects.cpp index 6c3e992d..05edab2e 100644 --- a/mapeffects.cpp +++ b/mapeffects.cpp @@ -935,17 +935,19 @@ movei determinePush(cellwalker who, int subdir, const T& valid) { auto rd = reverse_directions(push.at, push.spin); for(int i: rd) { push.spin = i; - if(valid(push.cpeek())) return movei(push.at, push.spin); + movei mi = movei(push.at, i); + if(valid(mi)) return mi; } return movei(c2, NO_SPACE); } int pd = push.at->type/2; push += pd * -subdir; + movei mi(push.at, push.spin); push += wstep; - if(valid(push.at)) return movei(c2, (push+wstep).spin); + if(valid(mi)) return mi; if(c2->type&1) { push = push + wstep - subdir + wstep; - if(valid(push.at)) return movei(c2, (push+wstep).spin); + if(valid(mi)) return mi; } if(gravityLevelDiff(push.at, c2) < 0) { push = push + wstep + 1 + wstep; @@ -955,7 +957,8 @@ movei determinePush(cellwalker who, int subdir, const T& valid) { if(gravityLevelDiff(push.at, c2) < 0) { push = push + wstep + 1 + wstep; } - if(valid(push.at)) return movei(c2, (push+wstep).spin); + movei mi = movei(c2, (push+wstep).spin); + if(valid(mi)) return mi; } return movei(c2, NO_SPACE); } diff --git a/monstermove.cpp b/monstermove.cpp index 503bd038..3ede8970 100644 --- a/monstermove.cpp +++ b/monstermove.cpp @@ -655,7 +655,7 @@ EX void beastAttack(cell *c, bool player, bool targetdir) { if(c2->monst && c2->stuntime) { cellwalker bull (c, d); int subdir = determinizeBullPush(bull); - auto mi = determinePush(bull, subdir, [c2] (cell *c) { return passable(c, c2, P_BLOW); }); + auto mi = determinePush(bull, subdir, [c2] (movei mi) { return passable(mi.t, c2, P_BLOW); }); if(mi.proper()) pushMonster(mi); } @@ -672,7 +672,7 @@ EX void beastAttack(cell *c, bool player, bool targetdir) { if(c2->wall == waThumperOn) { cellwalker bull (c, d); int subdir = determinizeBullPush(bull); - auto mi = determinePush(bull, subdir, [c2] (cell *c) { return canPushThumperOn(c, c2, c); }); + auto mi = determinePush(bull, subdir, [c, c2] (movei mi) { return canPushThumperOn(mi, c); }); if(mi.proper()) pushThumper(mi); } diff --git a/pcmove.cpp b/pcmove.cpp index 9528e88b..257d48e7 100644 --- a/pcmove.cpp +++ b/pcmove.cpp @@ -630,7 +630,7 @@ bool pcmove::actual_move() { } if(c2->monst == moAnimatedDie) { - mip = determinePush(cwt, subdir, [c2] (cell *c) { return canPushThumperOn(c, c2, cwt.at); }); + mip = determinePush(cwt, subdir, [c2] (movei mi) { return canPushThumperOn(mi, cwt.at); }); if(mip.proper()) { auto tgt = roll_effect(mip, dice::data[c2]); if(tgt.happy() > 0) { @@ -642,7 +642,7 @@ bool pcmove::actual_move() { } if(isPushable(c2->wall) && !c2->monst && !nonAdjacentPlayer(c2, cwt.at) && fmsMove) { - mip = determinePush(cwt, subdir, [c2] (cell *c) { return canPushThumperOn(c, c2, cwt.at); }); + mip = determinePush(cwt, subdir, [c2] (movei mi) { return canPushThumperOn(mi, cwt.at); }); if(mip.t) changes.ccell(mip.t); if(mip.d == NO_SPACE) { if(vmsg(miWALL)) addMessage(XLAT("No room to push %the1.", c2->wall)); @@ -978,7 +978,7 @@ bool pcmove::attack() { if(items[itCurseWeakness] || (isStunnable(c2->monst) && c2->hitpoints > 1)) { if(monsterPushable(c2)) - mip = determinePush(cwt, subdir, [c2] (cell *c) { return passable(c, c2, P_BLOW); }); + mip = determinePush(cwt, subdir, [c2] (movei mi) { return passable(mi.t, mi.s, P_BLOW); }); else mip.t = c2; if(mip.t) changes.ccell(mip.t); diff --git a/shmup.cpp b/shmup.cpp index 38231859..6b4be864 100644 --- a/shmup.cpp +++ b/shmup.cpp @@ -1123,7 +1123,7 @@ void movePlayer(monster *m, int delta) { if(dbase); }); + auto mip = determinePush(cellwalker(c2, sd1)+wstep, subdir, [m, c2] (movei mi) { return canPushThumperOn(mi, m->base); }); visibleFor(300); if(!mip.proper()) go = false; else pushThumper(mip);