Skip to content
This repository has been archived by the owner on Oct 4, 2024. It is now read-only.

creature: initialise room number for target enemy #144

Merged
merged 2 commits into from
Aug 23, 2024

Conversation

lahm86
Copy link
Collaborator

@lahm86 lahm86 commented Aug 22, 2024

Resolves #137.

This avoids cases with enemies fighting one another where x and z positions are identical and so LOS_Check does not initialise the target room number, and hence later passes an invalid room number to Room_GetSector.

I got the trace to show it was stemming from the call in Creature_CanTargetEnemy. I realise the room number isn't being set elsewhere for other LOS check targets, but felt perhaps this should be kept in its own commit for now while we continue testing the rest.

I tested the Barkhang scenario for an hour (i.e. loading a save, waiting for monk/merc fights to play out, then reloading) and it was crash-free. @aredfan, perhaps you could also check it out if you have time?
TR2X.zip

@lahm86 lahm86 requested review from rr-, walkawayy and aredfan August 22, 2024 10:39
@aredfan
Copy link

aredfan commented Aug 22, 2024

Thank you for working on this PR @lahm86.

I've not experienced any crashes while testing this build. I did notice an issue with enemies being able to target and shoot Lara/monks through walls.

Saves:
savegame.zip

@lahm86
Copy link
Collaborator Author

lahm86 commented Aug 22, 2024

Thank you for working on this PR @lahm86.

I've not experienced any crashes while testing this build. I did notice an issue with enemies being able to target and shoot Lara/monks through walls.

Saves: savegame.zip

Thank you. Back to the drawing board 😄

@lahm86 lahm86 changed the title creature: initialise room number for target enemy los: set target room number for identical x/z values Aug 22, 2024
@lahm86 lahm86 force-pushed the issue-137-target-enemy-room branch 2 times, most recently from cf8eee8 to 897e7dc Compare August 22, 2024 18:36
@lahm86
Copy link
Collaborator Author

lahm86 commented Aug 22, 2024

The issue with enemies shooting through walls is now resolved (thank you @rr-), this was a problem only in the release build which I had sent. Would you mind checking over it again @aredfan? So this is the same fix as before for the original crashing problem, plus the shooting issue resolved as well.
TR2X.zip

@lahm86 lahm86 changed the title los: set target room number for identical x/z values creature: initialise room number for target enemy Aug 22, 2024
@@ -913,6 +913,7 @@ int32_t __cdecl Creature_CanTargetEnemy(
target.pos.x = enemy->pos.x;
target.pos.y = enemy->pos.y - STEP_L * 3;
target.pos.z = enemy->pos.z;
target.room_num = enemy->room_num;
Copy link
Collaborator

@rr- rr- Aug 22, 2024

Choose a reason for hiding this comment

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

I'm a bit torn here; can we use the previous fix where we always set the target room number, and on top of it, have every caller set the room number as well?

This way we make both the callers and the LOS_Check API behave nicely – the latter will make sure the room number is always set to a valid value, and the former will always provide a nice input to the function. Ideally we could use this same approach in TR1X.

(I'm open to discussion about this.)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Another idea is to alter the LOS internals to use XYZ_32 for target, and have LOS_Check set the target->room_num to Room_FindByPos result.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes, I'm happy to put the check back into LOS_Check, then have each caller explicitly set it. It feels right for sure.
I think we may need to have Gun_FindTargetPoint decompiled as well first though, as @walkawayy mentioned:
#137 (comment)

Copy link
Collaborator

Choose a reason for hiding this comment

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

Done

Copy link
Collaborator

Choose a reason for hiding this comment

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

Thanks! Looks like Gun_FindTargetPoint does set target->room_num = item->room_num;, so that situation should be good.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Pushed a change to have all calls set the room number first, and LOS_Check also does a check for identical x/z. I can squash when the time comes as the title/commits have changed a bit already for this one.

TR2X.zip

The other main references to the function are in camera.c but everything here checks out already as far as I can tell.

@aredfan
Copy link

aredfan commented Aug 22, 2024

The issue with enemies shooting through walls is now resolved (thank you @rr-), this was a problem only in the release build which I had sent. Would you mind checking over it again @aredfan? So this is the same fix as before for the original crashing problem, plus the shooting issue resolved as well. TR2X.zip

Of course, no problem. I did 30 minutes of tests with the newer build and there's been no crashes, or any other odd issues.

I'll be happy to do more tests tomorrow if the code changes. 👍

This avoids cases with enemies fighting one another where x and z
positions are identical and so LOS_Check does not initialise the target
room number and hence later passes an invalid room number to
Room_GetSector.
@lahm86 lahm86 force-pushed the issue-137-target-enemy-room branch from 897e7dc to da6ad4a Compare August 22, 2024 20:02
Copy link
Collaborator

@walkawayy walkawayy left a comment

Choose a reason for hiding this comment

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

LGTM. I didn't see any regressions or crashes. I killed a monk and kept a locked on target on his dead body across the level to make sure shooting through rooms / target lock remained. Did we figure out if this and the issue should be tagged OG bug or TR2X bug?

Copy link

@aredfan aredfan left a comment

Choose a reason for hiding this comment

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

LGTM.

@lahm86 lahm86 merged commit 50f18f5 into LostArtefacts:develop Aug 23, 2024
1 check passed
@lahm86 lahm86 deleted the issue-137-target-enemy-room branch August 23, 2024 08:59
@rr- rr- added the TR2 label Oct 3, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TR2X bug: Rare crash in Barkhang Monastery
4 participants