Browse Source

♻️ Change 'SolicLoc' to take a 'Point' instead of 2 separate ints

pull/2057/head
Juliano Leal Goncalves 5 years ago committed by Anders Jenbo
parent
commit
c6fafbf64b
  1. 23
      Source/monster.cpp
  2. 17
      Source/player.cpp
  3. 2
      Source/player.h

23
Source/monster.cpp

@ -624,7 +624,7 @@ bool MonstPlace(int xp, int yp)
return false;
}
return !SolidLoc(xp, yp);
return !SolidLoc({ xp, yp });
}
void monster_some_crypt()
@ -1140,7 +1140,7 @@ void InitMonsters()
na = 0;
for (s = 16; s < 96; s++) {
for (t = 16; t < 96; t++) {
if (!SolidLoc(s, t))
if (!SolidLoc({ s, t }))
na++;
}
}
@ -1244,7 +1244,7 @@ void monster_43C785(int i)
if (monster[i].MType) {
for (d = 0; d < 8; d++) {
position = monster[i].position.tile + monster[i]._mdir;
if (!SolidLoc(position.x, position.y)) {
if (!SolidLoc(position)) {
if (dPlayer[position.x][position.y] == 0 && dMonster[position.x][position.y] == 0) {
if (dObject[position.x][position.y] == 0)
break;
@ -4697,20 +4697,21 @@ bool DirOK(int i, Direction mdir)
int mcount, mi;
commitment((DWORD)i < MAXMONSTERS, i);
Point futurePosition = monster[i].position.tile + mdir;
Point position = monster[i].position.tile;
Point futurePosition = position + mdir;
if (futurePosition.y < 0 || futurePosition.y >= MAXDUNY || futurePosition.x < 0 || futurePosition.x >= MAXDUNX || !PosOkMonst(i, futurePosition.x, futurePosition.y))
return false;
if (mdir == DIR_E) {
if (SolidLoc(futurePosition.x, futurePosition.y + 1) || dFlags[futurePosition.x][futurePosition.y + 1] & BFLAG_MONSTLR)
if (SolidLoc(position + DIR_SE) || dFlags[position.x + 1][position.y] & BFLAG_MONSTLR)
return false;
} else if (mdir == DIR_W) {
if (SolidLoc(futurePosition.x + 1, futurePosition.y) || dFlags[futurePosition.x + 1][futurePosition.y] & BFLAG_MONSTLR)
if (SolidLoc(position + DIR_SW) || dFlags[position.x][position.y + 1] & BFLAG_MONSTLR)
return false;
} else if (mdir == DIR_N) {
if (SolidLoc(futurePosition.x + 1, futurePosition.y) || SolidLoc(futurePosition.x, futurePosition.y + 1))
if (SolidLoc(position + DIR_NE) || SolidLoc(position + DIR_NW))
return false;
} else if (mdir == DIR_S)
if (SolidLoc(futurePosition.x - 1, futurePosition.y) || SolidLoc(futurePosition.x, futurePosition.y - 1))
if (SolidLoc(position + DIR_SW) || SolidLoc(position + DIR_SE))
return false;
if (monster[i].leaderflag == 1) {
if (abs(futurePosition.x - monster[monster[i].leader].position.future.x) >= 4
@ -5143,7 +5144,7 @@ bool PosOkMonst(int i, int x, int y)
int oi;
bool ret;
ret = !SolidLoc(x, y) && dPlayer[x][y] == 0 && dMonster[x][y] == 0;
ret = !SolidLoc({ x, y }) && dPlayer[x][y] == 0 && dMonster[x][y] == 0;
if (ret && dObject[x][y] != 0) {
oi = dObject[x][y] > 0 ? dObject[x][y] - 1 : -(dObject[x][y] + 1);
if (object[oi]._oSolidFlag)
@ -5200,7 +5201,7 @@ bool PosOkMonst2(int i, int x, int y)
int oi;
bool ret;
ret = !SolidLoc(x, y);
ret = !SolidLoc({ x, y });
if (ret && dObject[x][y] != 0) {
oi = dObject[x][y] > 0 ? dObject[x][y] - 1 : -(dObject[x][y] + 1);
if (object[oi]._oSolidFlag)
@ -5231,7 +5232,7 @@ bool PosOkMonst3(int i, int x, int y)
}
}
if (ret) {
ret = (!SolidLoc(x, y) || isdoor) && dPlayer[x][y] == 0 && dMonster[x][y] == 0;
ret = (!SolidLoc({ x, y }) || isdoor) && dPlayer[x][y] == 0 && dMonster[x][y] == 0;
}
if (ret)
ret = monster_posok(i, x, y);

17
Source/player.cpp

@ -1120,13 +1120,13 @@ void InitMultiView()
ViewY = myPlayer.position.tile.y;
}
bool SolidLoc(int x, int y)
bool SolidLoc(Point position)
{
if (x < 0 || y < 0 || x >= MAXDUNX || y >= MAXDUNY) {
if (position.x < 0 || position.y < 0 || position.x >= MAXDUNX || position.y >= MAXDUNY) {
return false;
}
return nSolidTable[dPiece[x][y]];
return nSolidTable[dPiece[position.x][position.y]];
}
bool PlrDirOK(int pnum, Direction dir)
@ -1138,18 +1138,19 @@ bool PlrDirOK(int pnum, Direction dir)
}
auto &player = plr[pnum];
Point position = player.position.tile + dir;
if (position.x < 0 || !dPiece[position.x][position.y] || !PosOkPlayer(pnum, position.x, position.y)) {
Point position = player.position.tile;
Point futurePosition = position + dir;
if (futurePosition.x < 0 || !dPiece[futurePosition.x][futurePosition.y] || !PosOkPlayer(pnum, futurePosition.x, futurePosition.y)) {
return false;
}
isOk = true;
if (dir == DIR_E) {
isOk = !SolidLoc(position.x, position.y + 1) && !(dFlags[position.x][position.y + 1] & BFLAG_PLAYERLR);
isOk = !SolidLoc(position + DIR_SE) && !(dFlags[position.x + 1][position.y] & BFLAG_PLAYERLR);
}
if (isOk && dir == DIR_W) {
isOk = !SolidLoc(position.x + 1, position.y) && !(dFlags[position.x + 1][position.y] & BFLAG_PLAYERLR);
isOk = !SolidLoc(position + DIR_SW) && !(dFlags[position.x][position.y + 1] & BFLAG_PLAYERLR);
}
return isOk;
@ -3510,7 +3511,7 @@ bool PosOkPlayer(int pnum, int x, int y)
return false;
if (dPiece[x][y] == 0)
return false;
if (SolidLoc(x, y))
if (SolidLoc({ x, y }))
return false;
if (dPlayer[x][y] != 0) {
if (dPlayer[x][y] > 0) {

2
Source/player.h

@ -428,7 +428,7 @@ void AddPlrMonstExper(int lvl, int exp, char pmask);
void ApplyPlrDamage(int pnum, int dam, int minHP = 0, int frac = 0, int earflag = 0);
void InitPlayer(int pnum, bool FirstTime);
void InitMultiView();
bool SolidLoc(int x, int y);
bool SolidLoc(Point position);
void PlrClrTrans(Point position);
void PlrDoTrans(Point position);
void SetPlayerOld(PlayerStruct &player);

Loading…
Cancel
Save