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

dragon: fix dragon reviving after the dagger is pulled #1759

Merged
merged 3 commits into from
Oct 26, 2024

Conversation

walkawayy
Copy link
Collaborator

@walkawayy walkawayy commented Oct 26, 2024

Resolves #1572.

Checklist

  • I have read the coding conventions
  • I have added a changelog entry about what my pull request accomplishes, or it is an internal change

Description

Fixed the dragon reviving itself after Lara removes the dagger in a 1 frame window.

Explanation:
Dragon_Collision:
item->frame_num - g_Anims[item->anim_num].frame_base <= DRAGON_ALMOST_LIVE // 100

Dragon_Control:

creature->flags++;
if (creature->flags == DRAGON_LIVE_TIME) { // 330
    dragon_front_item->goal_anim_state = DRAGON_ANIM_STOP;
}

if (creature->flags >= DRAGON_LIVE_TIME + DRAGON_ALMOST_LIVE) { // 330 + 100
    dragon_front_item->hit_points =
        g_Objects[O_DRAGON_FRONT].hit_points / 2;
}

So what was happening simultaneously was:

  1. Dragon_Control runs and creature->flags increments to 430 which is >= DRAGON_LIVE_TIME + DRAGON_ALMOST_LIVE (330+100).
  2. Dragon_Collision runs the same frame and item->frame_num - g_Anims[item->anim_num].frame_base is 100 which is <=DRAGON_ALMOST_LIVE (100) so M_PullDagger runs .

So, M_PullDagger runs, but that really only prepares the dragon for death by setting creature->flags = -1;. However, in Dragon_Control already, the hit points were reset to 300/2 because the creature->flags hit 430. So, the else... then if (dragon_front_item->hit_points <= 0) { block is no longer run which checks for if (creature->flags > -20) { when the dragon has no HP and kills the dragon.

So, the fix is to change in Dragon_Control:
if (creature->flags >= DRAGON_LIVE_TIME + DRAGON_ALMOST_LIVE) { // 330 + 100
to
if (creature->flags > DRAGON_LIVE_TIME + DRAGON_ALMOST_LIVE) { // 330 + 100
that way we don't lose 1 frame in the window to pull the dagger and kill the dragon. I cannot screenshot or capture video of the old DirectX SW rendered window for some reason.

@walkawayy walkawayy requested review from a team as code owners October 26, 2024 17:57
@walkawayy walkawayy requested review from rr- and lahm86 and removed request for a team October 26, 2024 17:57
@walkawayy walkawayy added OG bug A bug in original game TR2 labels Oct 26, 2024
Copy link

Copy link
Collaborator

@lahm86 lahm86 left a comment

Choose a reason for hiding this comment

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

LGTM. Recording below catching the dagger on frame 100 and missing it on frame 101.

https://youtu.be/q0Bt4J_n-9Y

DLL with frame display attached too.
TR2X.zip

src/tr2/game/objects/creatures/dragon.c Outdated Show resolved Hide resolved
@walkawayy walkawayy merged commit 8590e7d into LostArtefacts:develop Oct 26, 2024
6 checks passed
@walkawayy walkawayy deleted the dragon-dagger-fix branch November 9, 2024 19:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
OG bug A bug in original game TR2
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

OG Bug: Dragon can live even after pulling the dagger
4 participants