Skip to content

Commit

Permalink
Fix ichthyosaur restarting death sequence on save game load
Browse files Browse the repository at this point in the history
Resolves #152
  • Loading branch information
SamVanheer committed Jul 20, 2022
1 parent b9adea9 commit a47bddd
Showing 1 changed file with 45 additions and 3 deletions.
48 changes: 45 additions & 3 deletions dlls/ichthyosaur.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ class CIchthyosaur : public CFlyingMonster

float ChangeYaw(int speed) override;
Activity GetStoppedActivity() override;
void SetActivity(Activity NewActivity) override;

void Move(float flInterval) override;
void MoveExecute(CBaseEntity* pTargetEnt, const Vector& vecDir, float flInterval) override;
Expand Down Expand Up @@ -289,7 +290,6 @@ Task_t tlTwitchDie[] =
{TASK_STOP_MOVING, 0},
{TASK_SOUND_DIE, (float)0},
{TASK_DIE, (float)0},
{TASK_ICHTHYOSAUR_FLOAT, (float)0},
};

Schedule_t slTwitchDie[] =
Expand All @@ -301,12 +301,26 @@ Schedule_t slTwitchDie[] =
"Die"},
};

Task_t tlFloat[] =
{
{TASK_ICHTHYOSAUR_FLOAT, (float)0},
};

Schedule_t slFloat[] =
{
{tlFloat,
ARRAYSIZE(tlFloat),
0,
0,
"Float"},
};

DEFINE_CUSTOM_SCHEDULES(CIchthyosaur){
slSwimAround,
slSwimAgitated,
slCircleEnemy,
slTwitchDie,
slFloat,
};
IMPLEMENT_CUSTOM_SCHEDULES(CIchthyosaur, CFlyingMonster);

Expand Down Expand Up @@ -564,6 +578,12 @@ Schedule_t* CIchthyosaur::GetScheduleOfType(int Type)
case SCHED_FAIL:
return slSwimAgitated;
case SCHED_DIE:
if (pev->deadflag == DEAD_DEAD)
{
//Already dead, immediately switch to float.
return slFloat;
}

return slTwitchDie;
case SCHED_CHASE_ENEMY:
AttackSound();
Expand Down Expand Up @@ -601,9 +621,17 @@ void CIchthyosaur::StartTask(Task_t* pTask)
break;

case TASK_ICHTHYOSAUR_FLOAT:
pev->skin = EYE_BASE;
SetSequenceByName("bellyup");
{
const int sequenceIndex = LookupSequence("bellyup");

//Don't restart the animation if we're restoring.
if (pev->sequence != sequenceIndex)
{
pev->skin = EYE_BASE;
SetSequenceByName("bellyup");
}
break;
}

default:
CFlyingMonster::StartTask(pTask);
Expand Down Expand Up @@ -853,6 +881,20 @@ Activity CIchthyosaur::GetStoppedActivity()
return ACT_WALK;
}

void CIchthyosaur::SetActivity(Activity NewActivity)
{
const float frame = pev->frame;

CFlyingMonster::SetActivity(NewActivity);

//Restore belly up state.
if (pev->deadflag == DEAD_DEAD)
{
SetSequenceByName("bellyup");
pev->frame = frame;
}
}

void CIchthyosaur::MoveExecute(CBaseEntity* pTargetEnt, const Vector& vecDir, float flInterval)
{
m_SaveVelocity = vecDir * m_flightSpeed;
Expand Down

0 comments on commit a47bddd

Please sign in to comment.