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

Patch for UndercaveMapComponent (pit gate) #470

Merged
merged 1 commit into from
Jul 14, 2024

Conversation

SokyranTheDragon
Copy link
Member

Info on UndercaveMapComponent:MapComponentTick and why it needs patching:

  • RNG calls after current map/visible camera area checks
  • Majority of the RNG calls are visual/audio effects only
  • TriggerCollapseFX does have an effect on simulation by spawning collapsed mountain roof
    • The collapsing rocks have minimal impact on the game, as they avoid player pawns

Fixing RNG is easy by just pushing/popping the state.

Fixing the collapsed mountain roof is more complex. Possible solutions:

  • Disable rock collapse completely
  • Disable current map checks (suboptimal for performance)
  • Disable the existing calls to TriggerCollapseFX and call it in a deterministic way (used in this PR)

Information about the patch:

  • The transpiler will make the call to Rand.MTBEventOccurs always fail, making so TriggerCollapseFX is never called
    • This could be further improved by removing the RNG call and the current map check altogether to improve performance, but would be more complex
  • The prefix and postfix push/pop RNG state, making sure the ticking code doesn't mess with the RNG state
  • The postfix re-implements the call to TriggerCollapseFX in a deterministic way
    • If the current player is not looking at the current map, it will be called with 0 as both arguments to prevent additional effects from triggering
    • The call to the method is surrounded by RNG push/pop state, as the amount of RNG calls will differ if the player is not looking at the map
      • It's safe as the simulation-affecting RNG calls happen first, followed by RNG calls that don't affect simulation and may be called a different amount of times
      • The call is currently unseeded, but could be easily seeded with Gen.HashCombineInt(Find.TickManager.TicksGame, __instance.map.uniqueID) if we care about having a seed here

Remaining issues with UndercaveMapComponent/Pit Gate:

  • The rock collapse has additional check to not drop rocks on player faction pawns. However, I assume this won't work properly with Multifaction, which could end up crushing pawns of some players.

@SokyranTheDragon SokyranTheDragon added the anomaly Fix or bugs relating to Anomaly (Not 1.5) label May 18, 2024
@SokyranTheDragon
Copy link
Member Author

@Zetrith if you'd prefer me to change something here or use a different approach to patching this let me know.

@Zetrith
Copy link
Member

Zetrith commented May 24, 2024

Looks fine though it conflicts with latest merges

@SokyranTheDragon
Copy link
Member Author

Yup, I'll handle it tomorrow (or the day after, depending if I'll have the time).

Info on `UndercaveMapComponent:MapComponentTick` and why it needs patching:
- RNG calls after current map/visible camera area checks
- Majority of the RNG calls are visual/audio effects only
- `TriggerCollapseFX` does have an effect on simulation by spawning collapsed mountain roof
  - The collapsing rocks have minimal impact on the game, as they avoid player pawns

Fixing RNG is easy by just pushing/popping the state.

Fixing the collapsed mountain roof is more complex. Possible solutions:
- Disable rock collapse completely
- Disable current map checks (suboptimal for performance)
- Disable the existing calls to `TriggerCollapseFX` and call it in a deterministic way (used in this PR)

Information about the patch:
- The transpiler will make the call to `Rand.MTBEventOccurs` always fail, making so `TriggerCollapseFX` is never called
  - This could be further improved by removing the RNG call and the current map check altogether to improve performance, but would be more complex
- The prefix and postfix push/pop RNG state, making sure the ticking code doesn't mess with the RNG state
- The postfix re-implements the call to `TriggerCollapseFX` in a deterministic way
  - If the current player is not looking at the current map, it will be called with `0` as both arguments to prevent additional effects from triggering
  - The call to the method is surrounded by RNG push/pop state, as the amount of RNG calls will differ if the player is not looking at the map
    - It's safe as the simulation-affecting RNG calls happen first
    - The call is currently unseeded, but could be easily seeded with `Gen.HashCombineInt(Find.TickManager.TicksGame, __instance.map.uniqueID)` if we care about having a seed here

Remaining issues with `UndercaveMapComponent`/Pit Gate:
- The rock collapse has additional check to not drop rocks on player faction pawns. However, I assume this won't work properly with Multifaction, which could end up crushing pawns of some players.
@SokyranTheDragon SokyranTheDragon force-pushed the undercave-map-component-patch branch from c5b11a8 to 5796055 Compare May 26, 2024 00:11
@SokyranTheDragon
Copy link
Member Author

I've rebased the branch, so it should now be safe to merge to master.

@Zetrith Zetrith merged commit 50e159c into rwmt:master Jul 14, 2024
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
anomaly Fix or bugs relating to Anomaly (Not 1.5)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants