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

Move vetDamage total inside instigator check #6110

Merged
merged 10 commits into from
Jun 14, 2024

Conversation

clyfordv
Copy link
Contributor

@clyfordv clyfordv commented Apr 23, 2024

Previously, all damage taken from any source (including an allied unit or self) would be included in the veterancy dispersal calculations. This moves the addition operation to VetDamageTaken (the denominator in veterancyDispersal) inside an "IsEnemy" check, which prevents (for example) the Paragon from stealing 10,000 damage of veterancy experience for itself as it dies.

Downside is a particular unit may get more credit than it is "rightfully" owed for a unit that was hit by friendly fire--not a big downside, in the scheme of things.

@clyfordv
Copy link
Contributor Author

... also, with the pitiless attitude of working with code I didn't write, is there a reason not to condense VetDamage (<EntityId, Unit>) and VetInstigators (<EntityId, damage>) into <Unit, damage>, and eliminate a whole table declaration on every unit in the game? (see most recent commit, tested it with the Mavor + Paragon and appears to work correctly)

@clyfordv clyfordv force-pushed the VetExperienceUnderpaymentFix branch from efc2493 to 0c3e307 Compare April 23, 2024 16:55
@clyfordv clyfordv marked this pull request as ready for review April 23, 2024 17:05
@Garanas
Copy link
Member

Garanas commented Apr 23, 2024

... also, with the pitiless attitude of working with code I didn't write, is there a reason not to condense VetDamage (<EntityId, Unit>) and VetInstigators (<EntityId, damage>) into <Unit, damage>, and eliminate a whole table declaration on every unit in the game? (see most recent commit, tested it with the Mavor + Paragon and appears to work correctly)

There certainly is!

When you use a table as a key the memory reference is used as the actual 'key' value. This memory reference is not deterministic and is therefore almost guaranteed to be different among players. As a result iterations on this collection are in a different order for each player. And the moment that happens all bets are off and the game can randomly desync, especially when mods or future contributors may suspect it is safe to use for other purposes.

All in all; no - we can't eliminate the table 🤠

@@ -665,6 +667,11 @@ VeterancyComponent = ClassSimple {
return
end

-- Update a mass value killed stat, not used
-- by veterancy but potentially useful to the player
self.MassValueKilled = self.MassValueKilled + experience
Copy link
Member

Choose a reason for hiding this comment

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

The other veterancy values start with Vet, I think this one should too.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

let's do VetMassKillCredit

Copy link
Contributor

Choose a reason for hiding this comment

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

How about VetMassKilled?

@Garanas
Copy link
Member

Garanas commented Apr 24, 2024

We could maybe however use this:

fa/engine/Core.lua

Lines 192 to 195 in ceb09ce

---@param id EntityId
---@return UserUnit | Unit
function GetUnitById(id)
end

I'm not sure how efficient that function is, we'd need to benchmark it. But that way we can entirely rely on the VetInstigators table and get rid of the VetDamage damage.

@lL1l1
Copy link
Contributor

lL1l1 commented May 1, 2024

Would be nice to annotate what stats units usually have.

@lL1l1 lL1l1 added area: sim Area that is affected by the Simulation of the Game area: ui Anything to do with the User Interface of the Game ui: unit-stats related to issues in unit stats/tooltips labels May 1, 2024
@lL1l1 lL1l1 linked an issue May 1, 2024 that may be closed by this pull request
@Garanas
Copy link
Member

Garanas commented May 6, 2024

Would be nice to annotate what stats units usually have.

How would we annotate that?

@Garanas
Copy link
Member

Garanas commented May 11, 2024

The use of GetEntityById and GetUnitById appears to be fast - I can do 900 queries in 0.4ms. That's sufficient for this type of task!

@Garanas
Copy link
Member

Garanas commented May 11, 2024

@clyfordv can you write a changelog snippet? Make sure to also describe the practical change for the players

@clyfordv
Copy link
Contributor Author

Dropping the VetInstigators table introduces the issue where a new unit with a reused ID might get credit for kills by the previous (now dead) unit that had the same entity id. Thoughts?

@Garanas
Copy link
Member

Garanas commented May 14, 2024

Dropping the VetInstigators table introduces the issue where a new unit with a reused ID might get credit for kills by the previous (now dead) unit that had the same entity id. Thoughts?

Is there a way to detect how often this occurs? If it barely, if ever happens then I don't see an issue.

@clyfordv
Copy link
Contributor Author

Unfortunately, I think it might happen... all the time? Basically, any time:

  1. Unit does damage to target
  2. Unit dies
  3. New unit is created with same entity Id
  4. Original target dies

Which feels like it could be an extremely common (inevitable, really) occurrence.

@Garanas
Copy link
Member

Garanas commented May 14, 2024

But is there a way to test and see how often it happens? What if we re-introduce the backup table and see how often they're not the same unit for an AI vs AI game?

@clyfordv
Copy link
Contributor Author

clyfordv commented May 14, 2024

With titans, ravagers as a backstop:
image

So 3-5% is probably a good estimate.

(apropos nothing the dynamics of the waves of bots sloshing back and forth is very interesting)

@clyfordv
Copy link
Contributor Author

Relevant code here/"I know how to github":
image

@Garanas
Copy link
Member

Garanas commented May 15, 2024

Okay; that is super interesting. Let's let this sink in and see if we can come up with a solution.

@Garanas
Copy link
Member

Garanas commented May 22, 2024

I've given it some thought and to me the only correct solution was the old solution where we use a separate table. Did you manage to come up with something?

@clyfordv
Copy link
Contributor Author

I did not, I think it's inescapable, will revert the changes.

@Garanas Garanas changed the base branch from deploy/fafdevelop to develop June 1, 2024 19:31
@MrRowey
Copy link
Member

MrRowey commented Jun 14, 2024

@clyfordv can we get this finalised so we can have as a part of the game patch

@clyfordv
Copy link
Contributor Author

It's done, just needed to update the changelog.

@MrRowey MrRowey merged commit fbb1a87 into FAForever:develop Jun 14, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: sim Area that is affected by the Simulation of the Game area: ui Anything to do with the User Interface of the Game ui: unit-stats related to issues in unit stats/tooltips
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Veterancy values are unintuitive
4 participants