From 27f8951a9476a0e74e6c3fbc81a837377c702f7c Mon Sep 17 00:00:00 2001 From: Cesar Canassa Date: Mon, 4 Jul 2022 17:47:57 +0200 Subject: [PATCH] :recycle: Refactor MonsterWalk to receive a Monster reference (#4888) --- Source/monster.cpp | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/Source/monster.cpp b/Source/monster.cpp index 5b17fb5a5..51fe052bb 100644 --- a/Source/monster.cpp +++ b/Source/monster.cpp @@ -1198,11 +1198,8 @@ bool MonsterIdle(Monster &monster) /** * @brief Continue movement towards new tile */ -bool MonsterWalk(int monsterId, MonsterMode variant) +bool MonsterWalk(Monster &monster, MonsterMode variant) { - assert(monsterId >= 0 && monsterId < MaxMonsters); - auto &monster = Monsters[monsterId]; - // Check if we reached new tile const bool isAnimationEnd = monster.AnimInfo.currentFrame == monster.AnimInfo.numberOfFrames - 1; if (isAnimationEnd) { @@ -1211,7 +1208,7 @@ bool MonsterWalk(int monsterId, MonsterMode variant) dMonster[monster.position.tile.x][monster.position.tile.y] = 0; monster.position.tile.x += monster._mVar1; monster.position.tile.y += monster._mVar2; - dMonster[monster.position.tile.x][monster.position.tile.y] = monsterId + 1; + dMonster[monster.position.tile.x][monster.position.tile.y] = monster.getId() + 1; break; case MonsterMode::MoveSouthwards: dMonster[monster._mVar1][monster._mVar2] = 0; @@ -1220,7 +1217,7 @@ bool MonsterWalk(int monsterId, MonsterMode variant) dMonster[monster.position.tile.x][monster.position.tile.y] = 0; monster.position.tile = WorldTilePosition { static_cast(monster._mVar1), static_cast(monster._mVar2) }; // dMonster is set here for backwards comparability, without it the monster would be invisible if loaded from a vanilla save. - dMonster[monster.position.tile.x][monster.position.tile.y] = monsterId + 1; + dMonster[monster.position.tile.x][monster.position.tile.y] = monster.getId() + 1; break; default: break; @@ -4244,7 +4241,7 @@ void ProcessMonsters() case MonsterMode::MoveNorthwards: case MonsterMode::MoveSouthwards: case MonsterMode::MoveSideways: - raflag = MonsterWalk(monsterId, monster._mmode); + raflag = MonsterWalk(monster, monster._mmode); break; case MonsterMode::MeleeAttack: raflag = MonsterAttack(monsterId);