Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cpp] Increase cap for exp/cp bonus. #7106

Open
wants to merge 1 commit into
base: base
Choose a base branch
from
Open
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
4 changes: 2 additions & 2 deletions src/map/utils/charutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4731,7 +4731,7 @@ namespace charutils
{
CStatusEffect* commitment = PChar->StatusEffectContainer->GetStatusEffect(EFFECT_COMMITMENT);
int16 percentage = commitment->GetPower();
int16 cap = commitment->GetSubPower();
int32 cap = commitment->GetSubPower();
rawBonus += std::clamp<int32>(((capacityPoints * percentage) / 100), 0, cap);
commitment->SetSubPower(cap -= rawBonus);

Expand Down Expand Up @@ -5963,7 +5963,7 @@ namespace charutils
{
CStatusEffect* dedication = PChar->StatusEffectContainer->GetStatusEffect(EFFECT_DEDICATION);
int16 percentage = dedication->GetPower();
int16 cap = dedication->GetSubPower();
int32 cap = dedication->GetSubPower();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Get/SetSubPower() is defined as:

uint16 CStatusEffect::GetSubPower() const
{
    return m_SubPower;
}

void CStatusEffect::SetSubPower(uint16 subPower)
{
    m_SubPower = subPower;
}

If your goal is to store more in subpower and then have the maths here support that, then subpower also has to change.

The truncation happens here:

dedication->SetSubPower(cap -= bonus);

Where cap is originally int16 (the subpower) and bonus is int32, but SetSubPower takes a uint16. There's a terrible amount of mixing of widths and signedness's here. I'd work on getting all of those in a row, rather than just boosting the width of cap, since it will get immediately truncated on the way into SetSubPower.

When this is eventually sent to the client, it's done through:

CMessageCombatPacket::CMessageCombatPacket(CBaseEntity* PSender, CBaseEntity* PTarget, int32 param0, int32 param1, uint16 messageID)
...
    ref<uint32>(0x10) = param0;

So this ending up as int32 is fine.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So even though the change I made works for raising the subpower for those two effects overall in long run it will cause problems even for those two, unless

uint16 CStatusEffect::GetSubPower() const
{
    return m_SubPower;
}

void CStatusEffect::SetSubPower(uint16 subPower)
{
    m_SubPower = subPower;
}

the uint16 in here matches the other changes made to subpowers around the src? I can't imagine anywhere subpower will ever exceed uint16 let alone int16, other than those two effects so if more needs changing just to apply a quality of life on the exp bonuses, it seems a bit un worth.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The point I was getting at is that m_SubPower and its getters/setters are all handling it as a uint16. It's being captured currently into an int16, and your change is just extending the range of that int16 to int32. GetPower is also uint16.

bonus += std::clamp<int32>((int32)((exp * percentage) / 100), 0, cap);
dedication->SetSubPower(cap -= bonus);

Expand Down