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

Make Cannon respect srcPos on HaveFreeLineOfFire. #1852

Merged

Conversation

saurtron
Copy link
Collaborator

@saurtron saurtron commented Dec 25, 2024

Work done

  • Make Cannon respect srcPos on HaveFreeLineOfFire.

Details

I think all other weapons do this.

Looks safe since the only in-engine user is HaveFreeLineOfFire(GetAimFromPos(preFire), tgtPos, trg) at TryTarget. And GetAimFromPos for cannon is hardcoded to use weaponMuzzlePos anyways. (see Cannon.h).

Could break lua api users (GetUnitWeaponHaveFreeLineOfFire) but I think those seem fine too (actually the fix is for them) since also using GetAimFromPos unless user wants a different srcPos.

Marking as "lua api" since afaics this only affects Spring.GetUnitWeaponHaveFreeLineOfFire.

@sprunk
Copy link
Collaborator

sprunk commented Dec 27, 2024

Looks good, but this reverts a part of ce4c51d from #891 which had a lot of discussion in it that I'm not sure anybody remembers. Maybe @KyleAnthonyShepherd is around to take a look?

@saurtron
Copy link
Collaborator Author

saurtron commented Dec 27, 2024

Looks good, but this reverts a part of ce4c51d from #891 which had a lot of discussion in it that I'm not sure anybody remembers. Maybe @KyleAnthonyShepherd is around to take a look?

For what I could see it looks like changing srcPos will affect only lua code trying to set srcPos (calls through TryTarget will still use the muzzle as pointed at PR description) , and those can still use muzzlepos if they want (I suppose).

Still, for sure it would be great to see any remarks from @KyleAnthonyShepherd, maybe he can point to other issues here.

@KyleAnthonyShepherd
Copy link
Collaborator

Ya, I can take a review this weekend :)

@KyleAnthonyShepherd
Copy link
Collaborator

Alright, this looks safe to me. I think I swapped CCannon::HaveFreeLineOfFire to use weaponMuzzlePos instead of srcPos when testing and implementing the trajectory fixes (to ensure I knew what coordinates were being used), but did not check to see if it was actually necessary.
And yes, it looks like for Cannon weapons, GetAimFromPos(preFire) should always return and feed in the weaponMuzzlePos anyway, no matter the Bool for preFire.
Although I am unable to test the PR myself.

And, to make sure I have the context correct:

  1. BAR is trying to implement automatic high/low trajectory switching.
  2. So lua code is being written to check the high and low trajectory solutions.
  3. And if the low firing solution is blocked, swap to high mode.
  4. But due to animations, the lua code needs to check "what-if" scenarios. Specifically, it needs to check the low solution from the potential, not current, low solution barrel muzzle location, and the same for the high solution.
  5. Otherwise, you end up with edge cases where the elevated high mode firing may pass the low trajectory check, move the barrel down to fire low, fail the low trajectory check, move the barrel up to fire high, and cycle forever without firing.
  6. As (incorrectly) updated by me, when CCannon::HaveFreeLineOfFire is called by lua, it ignores the fed-in "what-if" srcPos in favor of the current muzzle position.

So this PR will fix that, and allow the Lua code to test "what-if" coordinates for cannons.
I'll provide my peanut-gallery opinion on the game side "what-if" code in the relevant PRs or discord threads.

Copy link
Collaborator

@KyleAnthonyShepherd KyleAnthonyShepherd left a comment

Choose a reason for hiding this comment

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

See above comment, looks good to me

@lhog lhog merged commit 3ba62c5 into beyond-all-reason:master Dec 29, 2024
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: Lua API bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants