Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 2 additions & 10 deletions Source/monster.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#ifdef USE_SDL3
#include <SDL3/SDL_timer.h>
#else
#include <SDL.h>

Check warning on line 30 in Source/monster.cpp

View workflow job for this annotation

GitHub Actions / tidy-check

Source/monster.cpp:30:1 [misc-include-cleaner]

included header SDL.h is not used directly
#endif

#include <expected.hpp>
Expand All @@ -39,7 +39,7 @@
#include "cursor.h"
#include "dead.h"
#include "diablo.h"
#include "dvlnet/leaveinfo.hpp"

Check warning on line 42 in Source/monster.cpp

View workflow job for this annotation

GitHub Actions / tidy-check

Source/monster.cpp:42:1 [misc-include-cleaner]

included header leaveinfo.hpp is not used directly
#include "effects.h"
#include "engine/animationinfo.h"
#include "engine/clx_sprite.hpp"
Expand Down Expand Up @@ -202,8 +202,8 @@
monster.mode = MonsterMode::Stand;
monster.animInfo = {};
monster.changeAnimationData(MonsterGraphic::Stand);
monster.animInfo.tickCounterOfCurrentFrame = GenerateRnd(monster.animInfo.ticksPerFrame - 1);

Check warning on line 205 in Source/monster.cpp

View workflow job for this annotation

GitHub Actions / tidy-check

Source/monster.cpp:205:47 [bugprone-narrowing-conversions]

narrowing conversion from 'int32_t' (aka 'int') to signed type 'int8_t' (aka 'signed char') is implementation-defined
monster.animInfo.currentFrame = GenerateRnd(monster.animInfo.numberOfFrames - 1);

Check warning on line 206 in Source/monster.cpp

View workflow job for this annotation

GitHub Actions / tidy-check

Source/monster.cpp:206:34 [bugprone-narrowing-conversions]

narrowing conversion from 'int32_t' (aka 'int') to signed type 'int8_t' (aka 'signed char') is implementation-defined

const int maxhp = RandomIntBetween(monster.data().hitPointsMinimum, monster.data().hitPointsMaximum);
monster.maxHitPoints = maxhp << 6;
Expand Down Expand Up @@ -299,7 +299,7 @@
InitMonster(monster, rd, typeIndex, position);
}

void PlaceGroup(size_t typeIndex, size_t num, Monster *leader = nullptr, bool leashed = false)

Check warning on line 302 in Source/monster.cpp

View workflow job for this annotation

GitHub Actions / tidy-check

Source/monster.cpp:302:6 [readability-function-cognitive-complexity]

function 'PlaceGroup' has cognitive complexity of 34 (threshold 25)
{
uint8_t placed = 0;

Expand Down Expand Up @@ -353,7 +353,7 @@

if (minion.ai != MonsterAIID::Gargoyle) {
minion.changeAnimationData(MonsterGraphic::Stand);
minion.animInfo.currentFrame = GenerateRnd(minion.animInfo.numberOfFrames - 1);

Check warning on line 356 in Source/monster.cpp

View workflow job for this annotation

GitHub Actions / tidy-check

Source/monster.cpp:356:37 [bugprone-narrowing-conversions]

narrowing conversion from 'int32_t' (aka 'int') to signed type 'int8_t' (aka 'signed char') is implementation-defined
minion.flags &= ~MFLAG_ALLOW_SPECIAL;
minion.mode = MonsterMode::Stand;
}
Expand Down Expand Up @@ -382,7 +382,7 @@
return LevelMonsterTypeCount;
}

Point GetUniqueMonstPosition(UniqueMonsterType uniqindex)

Check warning on line 385 in Source/monster.cpp

View workflow job for this annotation

GitHub Actions / tidy-check

Source/monster.cpp:385:7 [readability-function-cognitive-complexity]

function 'GetUniqueMonstPosition' has cognitive complexity of 28 (threshold 25)
{
if (setlevel) {
switch (uniqindex) {
Expand Down Expand Up @@ -522,7 +522,7 @@
return {};
}

tl::expected<void, std::string> PlaceQuestMonsters()

Check warning on line 525 in Source/monster.cpp

View workflow job for this annotation

GitHub Actions / tidy-check

Source/monster.cpp:525:33 [readability-function-cognitive-complexity]

function 'PlaceQuestMonsters' has cognitive complexity of 139 (threshold 25)
{
if (!setlevel) {
if (Quests[Q_BUTCHER].IsAvailable()) {
Expand Down Expand Up @@ -588,7 +588,7 @@
}
}
}
if (UberDiabloMonsterIndex == -1)

Check warning on line 591 in Source/monster.cpp

View workflow job for this annotation

GitHub Actions / tidy-check

Source/monster.cpp:591:37 [readability-braces-around-statements]

statement should be inside braces
RETURN_IF_ERROR(PlaceUniqueMonst(UniqueMonsterType::NaKrul, 0, 0));
}
} else if (setlvlnum == SL_SKELKING) {
Expand Down Expand Up @@ -670,7 +670,7 @@
return IsAnyOf(monster.ai, MonsterAIID::SkeletonRanged, MonsterAIID::GoatRanged, MonsterAIID::Succubus, MonsterAIID::LazarusSuccubus);
}

void UpdateEnemy(Monster &monster)

Check warning on line 673 in Source/monster.cpp

View workflow job for this annotation

GitHub Actions / tidy-check

Source/monster.cpp:673:6 [readability-function-cognitive-complexity]

function 'UpdateEnemy' has cognitive complexity of 41 (threshold 25)
{
WorldTilePosition target;
int menemy = -1;
Expand Down Expand Up @@ -1205,16 +1205,8 @@
}
return;
}
if (monster.type().type == MT_YZOMBIE && &player == MyPlayer) {
if (player._pMaxHP > 64) {
if (player._pMaxHPBase > 64) {
player._pMaxHP -= 64;
player._pHitPoints = std::min(player._pHitPoints, player._pMaxHP);
player._pMaxHPBase -= 64;
player._pHPBase = std::min(player._pHPBase, player._pMaxHPBase);
}
}
}
if (monster.type().type == MT_YZOMBIE && &player == MyPlayer && player._pMaxHP > (1 << 6))
ModifyPlrLifeCapacity(player, -(1 << 6), false);
// New method fixes a bug which caused the maximum possible damage value to be 63/64ths too low.
int dam = RandomIntBetween(minDam << 6, maxDam << 6);
dam = std::max(dam + (player._pIGetHit << 6), 64);
Expand Down
19 changes: 19 additions & 0 deletions Source/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3372,6 +3372,25 @@ void ModifyPlrVit(Player &player, int l)
}
}

void ModifyPlrLifeCapacity(Player &player, int delta, bool shiftCurrent)
{
constexpr int MinHPBase = 1 << 6;

const int newMaxBase = std::max(MinHPBase, player._pMaxHPBase + delta);
const int applied = newMaxBase - player._pMaxHPBase;

player._pMaxHPBase = newMaxBase;
player._pMaxHP += applied;

if (shiftCurrent) {
player._pHPBase += applied;
player._pHitPoints += applied;
} else {
player._pHPBase = std::min(player._pHPBase, player._pMaxHPBase);
player._pHitPoints = std::min(player._pHitPoints, player._pMaxHP);
}
}

void SetPlayerHitPoints(Player &player, int val)
{
player._pHitPoints = val;
Expand Down
1 change: 1 addition & 0 deletions Source/player.h
Original file line number Diff line number Diff line change
Expand Up @@ -990,6 +990,7 @@ void ModifyPlrStr(Player &player, int l);
void ModifyPlrMag(Player &player, int l);
void ModifyPlrDex(Player &player, int l);
void ModifyPlrVit(Player &player, int l);
void ModifyPlrLifeCapacity(Player &player, int delta, bool shiftCurrent);
void SetPlayerHitPoints(Player &player, int val);
void SetPlrStr(Player &player, int v);
void SetPlrMag(Player &player, int v);
Expand Down
Loading