Browse Source

Take monster reference in M_ClearSquares

pull/4877/head
ephphatha 4 years ago committed by Anders Jenbo
parent
commit
2da2ea7b03
  1. 45
      Source/monster.cpp
  2. 4
      Source/monster.h
  3. 5
      Source/msg.cpp
  4. 4
      Source/sync.cpp

45
Source/monster.cpp

@ -693,7 +693,7 @@ void StartMonsterGotHit(int monsterId)
monster.position.offset = { 0, 0 };
monster.position.tile = monster.position.old;
monster.position.future = monster.position.old;
M_ClearSquares(monsterId);
M_ClearSquares(monster);
dMonster[monster.position.tile.x][monster.position.tile.y] = monsterId + 1;
}
@ -950,7 +950,7 @@ void DiabloDeath(Monster &diablo, bool sendmsg)
monster._mVar1 = 0;
monster.position.tile = monster.position.old;
monster.position.future = monster.position.tile;
M_ClearSquares(k);
M_ClearSquares(monster);
dMonster[monster.position.tile.x][monster.position.tile.y] = k + 1;
}
AddLight(diablo.position.tile, 8);
@ -1034,7 +1034,7 @@ void Teleport(int monsterId)
if (!position)
return;
M_ClearSquares(monsterId);
M_ClearSquares(monster);
dMonster[monster.position.tile.x][monster.position.tile.y] = 0;
dMonster[position->x][position->y] = monsterId + 1;
monster.position.old = *position;
@ -1118,7 +1118,7 @@ void MonsterDeath(int monsterId, int pnum, Direction md, bool sendmsg)
monster.position.offset = { 0, 0 };
monster.position.tile = monster.position.old;
monster.position.future = monster.position.old;
M_ClearSquares(monsterId);
M_ClearSquares(monster);
dMonster[monster.position.tile.x][monster.position.tile.y] = monsterId + 1;
CheckQuestKill(monster, sendmsg);
M_FallenFear(monster.position.tile);
@ -3880,20 +3880,11 @@ void M_StartStand(Monster &monster, Direction md)
UpdateEnemy(monster);
}
void M_ClearSquares(int monsterId)
void M_ClearSquares(const Monster &monster)
{
auto &monster = Monsters[monsterId];
int mx = monster.position.old.x;
int my = monster.position.old.y;
int m1 = -(monsterId + 1);
int m2 = monsterId + 1;
for (int y = my - 1; y <= my + 1; y++) {
for (int x = mx - 1; x <= mx + 1; x++) {
if (InDungeonBounds({ x, y }) && (dMonster[x][y] == m1 || dMonster[x][y] == m2))
dMonster[x][y] = 0;
}
for (Point searchTile : PointsInRectangleRange { Rectangle { monster.position.old, 1 } }) {
if (MonsterAtPosition(searchTile) == &monster)
dMonster[searchTile.x][searchTile.y] = 0;
}
}
@ -3906,7 +3897,7 @@ void M_GetKnockback(int monsterId)
return;
}
M_ClearSquares(monsterId);
M_ClearSquares(monster);
monster.position.old += dir;
StartMonsterGotHit(monsterId);
}
@ -3987,7 +3978,7 @@ void M_SyncStartKill(int monsterId, Point position, int pnum)
}
if (dMonster[position.x][position.y] == 0) {
M_ClearSquares(monsterId);
M_ClearSquares(monster);
monster.position.tile = position;
monster.position.old = position;
}
@ -4704,6 +4695,22 @@ void MissToMonst(Missile &missile, Point position)
}
}
Monster *MonsterAtPosition(Point position)
{
if (!InDungeonBounds(position)) {
return nullptr;
}
auto monsterId = dMonster[position.x][position.y];
if (monsterId != 0) {
return &Monsters[abs(monsterId) - 1];
}
// nothing at this position, return a nullptr
return nullptr;
}
bool IsTileAvailable(const Monster &monster, Point position)
{
if (!IsTileAvailable(position))

4
Source/monster.h

@ -305,7 +305,7 @@ int AddMonster(Point position, Direction dir, int mtype, bool inMap);
void AddDoppelganger(Monster &monster);
bool M_Talker(const Monster &monster);
void M_StartStand(Monster &monster, Direction md);
void M_ClearSquares(int monsterId);
void M_ClearSquares(const Monster &monster);
void M_GetKnockback(int monsterId);
void M_StartHit(int monsterId, int dam);
void M_StartHit(int monsterId, int pnum, int dam);
@ -331,6 +331,8 @@ void PrintUniqueHistory();
void PlayEffect(Monster &monster, int mode);
void MissToMonst(Missile &missile, Point position);
Monster *MonsterAtPosition(Point position);
/**
* @brief Check that the given tile is available to the monster
*/

5
Source/msg.cpp

@ -2401,8 +2401,9 @@ void DeltaLoadLevel()
if (deltaLevel.monster[i].position.x == 0xFF)
continue;
M_ClearSquares(i);
// Should this be Monsters[ActiveMonsters[i]]? this loop uses ActiveMonsterCount, not MAXMONSTERS
auto &monster = Monsters[i];
M_ClearSquares(monster);
{
const WorldTilePosition position = deltaLevel.monster[i].position;
monster.position.tile = position;
@ -2414,7 +2415,7 @@ void DeltaLoadLevel()
monster.mWhoHit = deltaLevel.monster[i].mWhoHit;
}
if (deltaLevel.monster[i]._mhitpoints == 0) {
M_ClearSquares(i);
M_ClearSquares(monster);
if (monster._mAi != AI_DIABLO) {
if (monster._uniqtype == 0) {
AddCorpse(monster.position.tile, monster.type().corpseId, monster._mdir);

4
Source/sync.cpp

@ -180,14 +180,14 @@ void SyncMonster(bool isOwner, const TSyncMonster &monsterSync)
if (!monster.IsWalking()) {
Direction md = GetDirection(monster.position.tile, position);
if (DirOK(monsterId, md)) {
M_ClearSquares(monsterId);
M_ClearSquares(monster);
dMonster[monster.position.tile.x][monster.position.tile.y] = monsterId + 1;
M_WalkDir(monster, md);
monster._msquelch = UINT8_MAX;
}
}
} else if (dMonster[position.x][position.y] == 0) {
M_ClearSquares(monsterId);
M_ClearSquares(monster);
dMonster[position.x][position.y] = monsterId + 1;
monster.position.tile = position;
decode_enemy(monster, enemyId);

Loading…
Cancel
Save