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

Bugfix: Missiles calculating damage in Process functions instead of Add functions #6327

Open
wants to merge 12 commits into
base: master
Choose a base branch
from

Conversation

kphoenix137
Copy link
Collaborator

@kphoenix137 kphoenix137 commented Jul 9, 2023

Moves damage calculations from the Process functions into the Add functions, so that damage is added to the missile struct rather than calculated every time the Process functions are called, which can also lead to undefined behavior if the source of the missile dies or leaves the game.

Also fixes: #4656

@kphoenix137 kphoenix137 changed the title Bugfix: Arrows and Elemental Arrows damage calculation Bugfix: Missiles calculating damage in Process functions instead of Add functions Jul 9, 2023
@kphoenix137 kphoenix137 marked this pull request as draft July 9, 2023 06:11
@kphoenix137 kphoenix137 marked this pull request as ready for review July 9, 2023 06:41
Source/missiles.cpp Outdated Show resolved Hide resolved
@@ -1396,7 +1396,7 @@ void AddSpectralArrow(Missile &missile, AddMissileParameter &parameter)
int av = 0;

if (missile.sourceType() == MissileSource::Player) {
const Player &player = *missile.sourcePlayer();
Player &player = *missile.sourcePlayer();
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why remove the const? I don't think player is modified her?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Can't iterate through equipment if it's const

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Would it be better to use a traditional for loop to retain player as const?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Ah, right, this will be easy to fix once we have C++17 but for now non-const is fine.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'll add a comment by it so we know to readd const at a later time

@@ -1956,10 +2033,19 @@ void AddMissileExplosion(Missile &missile, AddMissileParameter &parameter)
void AddWeaponExplosion(Missile &missile, AddMissileParameter &parameter)
{
missile.var2 = parameter.dst.x;
if (parameter.dst.x == 1)

const Player &player = *missile.sourcePlayer();
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Need to verify that missile source is player first before defining player

@StephenCWills StephenCWills linked an issue Sep 29, 2023 that may be closed by this pull request
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Issue Report]: Possible collision issues with trap arrows Sparking mail breaks thunderclap's effect
2 participants