Skip to content

Commit

Permalink
Fix nullptr check
Browse files Browse the repository at this point in the history
  • Loading branch information
ramon-bernardo committed Oct 24, 2024
1 parent 88f1b7a commit 29d7f70
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 11 deletions.
6 changes: 4 additions & 2 deletions src/combat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1368,8 +1368,10 @@ void MagicField::onStepInField(Creature* creature)
bool harmfulField = true;

if (g_game.getWorldType() == WORLD_TYPE_NO_PVP || getTile()->hasFlag(TILESTATE_NOPVPZONE)) {
if (Creature* owner = g_game.getCreatureByID(ownerId); owner->hasPlayerOwned()) {
harmfulField = false;
if (Creature* owner = g_game.getCreatureByID(ownerId)) {
if (owner->hasPlayerOwned()) {
harmfulField = false;
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions src/creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1463,8 +1463,8 @@ int64_t Creature::getStepDuration() const
double duration = std::floor(1000 * groundSpeed / calculatedStepSpeed);
int64_t stepDuration = std::ceil(duration / 50) * 50;

if (const Monster* monster = getMonster(); monster->isTargetNearby()) {
if (!monster->isFleeing()) {
if (const Monster* monster = getMonster()) {
if (monster->isTargetNearby() && !monster->isFleeing()) {
stepDuration *= 2;
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/monster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -446,8 +446,10 @@ bool Monster::isOpponent(const Creature* creature) const
return true;
}

if (const Player* player = creature->getPlayer(); !player->hasFlag(PlayerFlag_IgnoredByMonsters)) {
return true;
if (const Player* player = creature->getPlayer()) {
if (!player->hasFlag(PlayerFlag_IgnoredByMonsters)) {
return true;
}
}

if (creature->isPlayerSummon()) {
Expand Down
8 changes: 5 additions & 3 deletions src/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3690,9 +3690,11 @@ void Player::onAttackedCreatureDrainHealth(Creature* target, int32_t points)

if (party && target) {
if (!target->hasPlayerOwned()) {
if (const Monster* monster = target->getMonster(); monster->isHostile()) {
// We have fulfilled a requirement for shared experience
party->updatePlayerTicks(this, points);
if (const Monster* monster = target->getMonster()) {
if (monster->isHostile()) {
// We have fulfilled a requirement for shared experience
party->updatePlayerTicks(this, points);
}
}
}
}
Expand Down
6 changes: 4 additions & 2 deletions src/tile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -505,8 +505,10 @@ ReturnValue Tile::queryAdd(int32_t, const Thing& thing, uint32_t, uint32_t flags
if (!creatures->empty()) {
if (monster->canPushCreatures() && !monster->isSummon()) {
for (Creature* tileCreature : *creatures) {
if (const Player* tilePlayer = tileCreature->getPlayer(); tilePlayer->isInGhostMode()) {
continue;
if (const Player* tilePlayer = tileCreature->getPlayer()) {
if (tilePlayer->isInGhostMode()) {
continue;
}
}

if (!tileCreature->isPushable()) {
Expand Down

0 comments on commit 29d7f70

Please sign in to comment.