Browse Source

♻️ Clean up direction related code

pull/1660/head
Anders Jenbo 5 years ago
parent
commit
d99522b9a5
  1. 70
      Source/inv.cpp
  2. 18
      Source/missiles.cpp
  3. 89
      Source/objects.cpp
  4. 4
      Source/player.cpp

70
Source/inv.cpp

@ -1868,23 +1868,21 @@ bool CanPut(int x, int y)
bool TryInvPut()
{
int dir;
if (numitems >= MAXITEMS)
return false;
dir = GetDirection(plr[myplr]._px, plr[myplr]._py, cursmx, cursmy);
direction dir = GetDirection(plr[myplr]._px, plr[myplr]._py, cursmx, cursmy);
if (CanPut(plr[myplr]._px + offset_x[dir], plr[myplr]._py + offset_y[dir])) {
return true;
}
dir = (dir - 1) & 7;
if (CanPut(plr[myplr]._px + offset_x[dir], plr[myplr]._py + offset_y[dir])) {
direction dirLeft = left[dir];
if (CanPut(plr[myplr]._px + offset_x[dirLeft], plr[myplr]._py + offset_y[dirLeft])) {
return true;
}
dir = (dir + 2) & 7;
if (CanPut(plr[myplr]._px + offset_x[dir], plr[myplr]._py + offset_y[dir])) {
direction dirRight = right[dir];
if (CanPut(plr[myplr]._px + offset_x[dirRight], plr[myplr]._py + offset_y[dirRight])) {
return true;
}
@ -1907,44 +1905,46 @@ static int PutItem(int pnum, int &x, int &y)
if (numitems >= MAXITEMS)
return false;
int d = GetDirection(plr[pnum]._px, plr[pnum]._py, x, y);
int xx = x - plr[pnum]._px;
int yy = y - plr[pnum]._py;
direction d = GetDirection(plr[pnum]._px, plr[pnum]._py, x, y);
if (abs(xx) > 1 || abs(yy) > 1) {
x = plr[pnum]._px + offset_x[d];
y = plr[pnum]._py + offset_y[d];
}
if (CanPut(x, y))
return true;
if (!CanPut(x, y)) {
d = (d - 1) & 7;
x = plr[pnum]._px + offset_x[d];
y = plr[pnum]._py + offset_y[d];
if (!CanPut(x, y)) {
d = (d + 2) & 7;
x = plr[pnum]._px + offset_x[d];
y = plr[pnum]._py + offset_y[d];
if (!CanPut(x, y)) {
bool done = false;
for (int l = 1; l < 50 && !done; l++) {
for (int j = -l; j <= l && !done; j++) {
int yp = j + plr[pnum]._py;
for (int i = -l; i <= l && !done; i++) {
int xp = i + plr[pnum]._px;
if (CanPut(xp, yp)) {
done = true;
x = xp;
y = yp;
}
}
}
}
if (!done)
return false;
direction dLeft = left[d];
x = plr[pnum]._px + offset_x[dLeft];
y = plr[pnum]._py + offset_y[dLeft];
if (CanPut(x, y))
return true;
direction dRight = right[d];
x = plr[pnum]._px + offset_x[dRight];
y = plr[pnum]._py + offset_y[dRight];
if (CanPut(x, y))
return true;
for (int l = 1; l < 50; l++) {
for (int j = -l; j <= l; j++) {
int yp = j + plr[pnum]._py;
for (int i = -l; i <= l; i++) {
int xp = i + plr[pnum]._px;
if (!CanPut(xp, yp))
continue;
x = xp;
y = yp;
return true;
}
}
}
return true;
return false;
}
int InvPutItem(int pnum, int x, int y)
@ -2003,7 +2003,7 @@ int SyncPutItem(int pnum, int x, int y, int idx, WORD icreateinfo, int iseed, in
if (!PutItem(pnum, x, y))
return -1;
CanPut(x, y);
assert(CanPut(x, y));
int ii = AllocateItem();

18
Source/missiles.cpp

@ -228,19 +228,15 @@ void GetDamageAmt(int i, int *mind, int *maxd)
bool CheckBlock(int fx, int fy, int tx, int ty)
{
int pn;
bool coll;
coll = false;
while (fx != tx || fy != ty) {
pn = GetDirection(fx, fy, tx, ty);
direction pn = GetDirection(fx, fy, tx, ty);
fx += XDirAdd[pn];
fy += YDirAdd[pn];
if (nSolidTable[dPiece[fx][fy]])
coll = true;
return true;
}
return coll;
return false;
}
int FindClosest(int sx, int sy, int rad)
@ -4865,7 +4861,7 @@ void MI_Apoca(Sint32 i)
void MI_Wave(Sint32 i)
{
int sx, sy, sd, nxa, nxb, nya, nyb, dira, dirb;
int sx, sy, nxa, nxb, nya, nyb;
int j, id, pn;
bool f1, f2;
int v1, v2;
@ -4879,9 +4875,9 @@ void MI_Wave(Sint32 i)
sy = missile[i]._miy;
v1 = missile[i]._miVar1;
v2 = missile[i]._miVar2;
sd = GetDirection(sx, sy, v1, v2);
dira = (sd - 2) & 7;
dirb = (sd + 2) & 7;
direction sd = GetDirection(sx, sy, v1, v2);
direction dira = left[left[sd]];
direction dirb = right[right[sd]];
nxa = sx + XDirAdd[sd];
nya = sy + YDirAdd[sd];
pn = dPiece[nxa][nya];

89
Source/objects.cpp

@ -2091,57 +2091,52 @@ void Obj_FlameTrap(int i)
void Obj_Trap(int i)
{
int oti;
bool otrig;
int sx, sy, dx, dy, x, y;
if (object[i]._oVar4 != 0)
return;
otrig = false;
if (object[i]._oVar4 == 0) {
oti = dObject[object[i]._oVar1][object[i]._oVar2] - 1;
switch (object[oti]._otype) {
case OBJ_L1LDOOR:
case OBJ_L1RDOOR:
case OBJ_L2LDOOR:
case OBJ_L2RDOOR:
case OBJ_L3LDOOR:
case OBJ_L3RDOOR:
if (object[oti]._oVar4 != 0)
otrig = true;
break;
case OBJ_LEVER:
case OBJ_CHEST1:
case OBJ_CHEST2:
case OBJ_CHEST3:
case OBJ_SWITCHSKL:
case OBJ_SARC:
if (object[oti]._oSelFlag == 0)
otrig = true;
break;
default:
break;
}
if (otrig) {
object[i]._oVar4 = 1;
sx = object[i]._ox;
sy = object[i]._oy;
dx = object[oti]._ox;
dy = object[oti]._oy;
for (y = dy - 1; y <= object[oti]._oy + 1; y++) {
for (x = object[oti]._ox - 1; x <= object[oti]._ox + 1; x++) {
if (dPlayer[x][y] != 0) {
dx = x;
dy = y;
}
}
}
if (!deltaload) {
direction dir = GetDirection(sx, sy, dx, dy);
AddMissile(sx, sy, dx, dy, dir, object[i]._oVar3, TARGET_PLAYERS, -1, 0, 0);
PlaySfxLoc(IS_TRAP, object[oti]._ox, object[oti]._oy);
int oti = dObject[object[i]._oVar1][object[i]._oVar2] - 1;
switch (object[oti]._otype) {
case OBJ_L1LDOOR:
case OBJ_L1RDOOR:
case OBJ_L2LDOOR:
case OBJ_L2RDOOR:
case OBJ_L3LDOOR:
case OBJ_L3RDOOR:
if (object[oti]._oVar4 == 0)
return;
break;
case OBJ_LEVER:
case OBJ_CHEST1:
case OBJ_CHEST2:
case OBJ_CHEST3:
case OBJ_SWITCHSKL:
case OBJ_SARC:
if (object[oti]._oSelFlag != 0)
return;
break;
default:
return;
}
object[i]._oVar4 = 1;
int sx = object[i]._ox;
int sy = object[i]._oy;
int dx = object[oti]._ox;
int dy = object[oti]._oy;
for (int y = dy - 1; y <= object[oti]._oy + 1; y++) {
for (int x = object[oti]._ox - 1; x <= object[oti]._ox + 1; x++) {
if (dPlayer[x][y] != 0) {
dx = x;
dy = y;
}
object[oti]._oTrapFlag = false;
}
}
if (!deltaload) {
direction dir = GetDirection(sx, sy, dx, dy);
AddMissile(sx, sy, dx, dy, dir, object[i]._oVar3, TARGET_PLAYERS, -1, 0, 0);
PlaySfxLoc(IS_TRAP, object[oti]._ox, object[oti]._oy);
}
object[oti]._oTrapFlag = false;
}
void Obj_BCrossDamage(int i)

4
Source/player.cpp

@ -3867,7 +3867,7 @@ void MakePlrPath(int pnum, int xx, int yy, bool endspace)
void CheckPlrSpell()
{
bool addflag = false;
int sd, sl;
int sl;
if ((DWORD)myplr >= MAX_PLRS) {
app_fatal("CheckPlrSpell: illegal player %d", myplr);
@ -3921,7 +3921,7 @@ void CheckPlrSpell()
if (addflag) {
if (plr[myplr]._pRSpell == SPL_FIREWALL || plr[myplr]._pRSpell == SPL_LIGHTWALL) {
sd = GetDirection(plr[myplr]._px, plr[myplr]._py, cursmx, cursmy);
direction sd = GetDirection(plr[myplr]._px, plr[myplr]._py, cursmx, cursmy);
sl = GetSpellLevel(myplr, plr[myplr]._pRSpell);
NetSendCmdLocParam3(true, CMD_SPELLXYD, cursmx, cursmy, plr[myplr]._pRSpell, sd, sl);
} else if (pcursmonst != -1) {

Loading…
Cancel
Save