Skip to content

Commit

Permalink
random anims
Browse files Browse the repository at this point in the history
  • Loading branch information
Coronia committed Sep 24, 2024
1 parent 2b28804 commit 42342b7
Show file tree
Hide file tree
Showing 10 changed files with 66 additions and 91 deletions.
2 changes: 1 addition & 1 deletion YRpp
37 changes: 37 additions & 0 deletions src/Ext/Anim/Body.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,43 @@ void AnimExt::HandleDebrisImpact(AnimTypeClass* pExpireAnim, AnimTypeClass* pWak
}
}

AnimClass* AnimExt::CreateRandomAnim(std::vector<AnimTypeClass*> AnimList, CoordStruct coords, TechnoClass* pTechno, HouseClass* pHouse, bool invoker)
{
if (!AnimList.empty())
{
if (auto const pAnimType = AnimList[ScenarioClass::Instance->Random.RandomRanged(0, AnimList.size() - 1)])
{
if (auto const pAnim = GameCreate<AnimClass>(pAnimType, coords))
{
if (pTechno)
{
pAnim->SetOwnerObject(pTechno);
pAnim->Owner = pHouse ? pHouse : pTechno->Owner;

if (invoker)
{
if (auto const pAnimExt = AnimExt::ExtMap.Find(pAnim))
{
if (pHouse)
pAnimExt->SetInvoker(pTechno, pHouse);
else
pAnimExt->SetInvoker(pTechno);
}
}
}
else if (pHouse)
{
pAnim->Owner = pHouse;
}

return pAnim;
}
}
}

return nullptr;
}

// =============================
// load / save

Expand Down
2 changes: 2 additions & 0 deletions src/Ext/Anim/Body.h
Original file line number Diff line number Diff line change
Expand Up @@ -80,4 +80,6 @@ class AnimExt

static void InvalidateTechnoPointers(TechnoClass* pTechno);
static void InvalidateParticleSystemPointers(ParticleSystemClass* pParticleSystem);

static AnimClass* CreateRandomAnim(std::vector<AnimTypeClass*> AnimList, CoordStruct coords, TechnoClass* pTechno = nullptr, HouseClass* pHouse = nullptr, bool invoker = false);
};
15 changes: 2 additions & 13 deletions src/Ext/Anim/Hooks.AnimCreateUnit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,19 +144,8 @@ DEFINE_HOOK(0x424932, AnimClass_AI_CreateUnit_ActualAffects, 0x6)

if (success)
{
if (!pTypeExt->CreateUnit_SpawnAnim.empty())
{
if (auto const pAnimType = pTypeExt->CreateUnit_SpawnAnim[ScenarioClass::Instance->Random.RandomRanged(0, pTypeExt->CreateUnit_SpawnAnim.size() - 1)])
{
if (auto const pAnim = GameCreate<AnimClass>(pAnimType, location))
{
AnimExt::SetAnimOwnerHouseKind(pAnim, pInvokerHouse, nullptr, false, true);

if (auto const pAnimExt = AnimExt::ExtMap.Find(pAnim))
pAnimExt->SetInvoker(pInvoker, pInvokerHouse);
}
}
}
if (auto const pAnim = AnimExt::CreateRandomAnim(pTypeExt->CreateUnit_SpawnAnim, location, pInvoker, pInvokerHouse, true))
AnimExt::SetAnimOwnerHouseKind(pAnim, pInvokerHouse, nullptr, false, true);

if (pTechno->HasTurret() && pExt->FromDeathUnit && pExt->DeathUnitHasTurret && pTypeExt->CreateUnit_InheritTurretFacings)
{
Expand Down
36 changes: 7 additions & 29 deletions src/Ext/Techno/Body.Update.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,15 +136,11 @@ bool TechnoExt::ExtData::CheckDeathConditions(bool isInLimbo)

// Self-destruction must be enabled
const auto howToDie = pTypeExt->AutoDeath_Behavior.Get();
AnimTypeClass* pVanishAnim = nullptr;

if (!pTypeExt->AutoDeath_VanishAnimation.empty())
pVanishAnim = pTypeExt->AutoDeath_VanishAnimation[ScenarioClass::Instance->Random.RandomRanged(0, pTypeExt->AutoDeath_VanishAnimation.size() - 1)];

// Death if no ammo
if (pType->Ammo > 0 && pThis->Ammo <= 0 && pTypeExt->AutoDeath_OnAmmoDepletion)
{
TechnoExt::KillSelf(pThis, howToDie, pVanishAnim, isInLimbo);
TechnoExt::KillSelf(pThis, howToDie, pTypeExt->AutoDeath_VanishAnimation, isInLimbo);
return true;
}

Expand All @@ -157,7 +153,7 @@ bool TechnoExt::ExtData::CheckDeathConditions(bool isInLimbo)
}
else if (this->AutoDeathTimer.Completed())
{
TechnoExt::KillSelf(pThis, howToDie, pVanishAnim, isInLimbo);
TechnoExt::KillSelf(pThis, howToDie, pTypeExt->AutoDeath_VanishAnimation, isInLimbo);
return true;
}
}
Expand Down Expand Up @@ -186,7 +182,7 @@ bool TechnoExt::ExtData::CheckDeathConditions(bool isInLimbo)
{
if (!existTechnoTypes(pTypeExt->AutoDeath_TechnosDontExist, pTypeExt->AutoDeath_TechnosDontExist_Houses, !pTypeExt->AutoDeath_TechnosDontExist_Any, pTypeExt->AutoDeath_TechnosDontExist_AllowLimboed))
{
TechnoExt::KillSelf(pThis, howToDie, pVanishAnim, isInLimbo);
TechnoExt::KillSelf(pThis, howToDie, pTypeExt->AutoDeath_VanishAnimation, isInLimbo);

return true;
}
Expand All @@ -197,7 +193,7 @@ bool TechnoExt::ExtData::CheckDeathConditions(bool isInLimbo)
{
if (existTechnoTypes(pTypeExt->AutoDeath_TechnosExist, pTypeExt->AutoDeath_TechnosExist_Houses, pTypeExt->AutoDeath_TechnosExist_Any, pTypeExt->AutoDeath_TechnosExist_AllowLimboed))
{
TechnoExt::KillSelf(pThis, howToDie, pVanishAnim, isInLimbo);
TechnoExt::KillSelf(pThis, howToDie, pTypeExt->AutoDeath_VanishAnimation, isInLimbo);

return true;
}
Expand Down Expand Up @@ -286,17 +282,7 @@ void TechnoExt::ExtData::EatPassengers()
if (pDelType->ReportSound >= 0)
VocClass::PlayAt(pDelType->ReportSound.Get(), pThis->GetCoords(), nullptr);

if (!pDelType->Anim.empty())
{
if (auto const pAnimType = pDelType->Anim[ScenarioClass::Instance->Random.RandomRanged(0, pDelType->Anim.size() - 1)])
{
if (auto const pAnim = GameCreate<AnimClass>(pAnimType, pThis->Location))
{
pAnim->SetOwnerObject(pThis);
pAnim->Owner = pThis->Owner;
}
}
}
AnimExt::CreateRandomAnim(pDelType->Anim, pThis->Location, pThis);

// Check if there is money refund
if (pDelType->Soylent &&
Expand Down Expand Up @@ -694,7 +680,7 @@ void TechnoExt::ApplyMindControlRangeLimit(TechnoClass* pThis)
}
}

void TechnoExt::KillSelf(TechnoClass* pThis, AutoDeathBehavior deathOption, AnimTypeClass* pVanishAnimation, bool isInLimbo)
void TechnoExt::KillSelf(TechnoClass* pThis, AutoDeathBehavior deathOption, std::vector<AnimTypeClass*> pVanishAnimation, bool isInLimbo)
{
if (isInLimbo)
{
Expand All @@ -715,15 +701,7 @@ void TechnoExt::KillSelf(TechnoClass* pThis, AutoDeathBehavior deathOption, Anim

case AutoDeathBehavior::Vanish:
{
if (pVanishAnimation)
{
if (auto const pAnim = GameCreate<AnimClass>(pVanishAnimation, pThis->GetCoords()))
{
auto const pAnimExt = AnimExt::ExtMap.Find(pAnim);
pAnim->Owner = pThis->Owner;
pAnimExt->SetInvoker(pThis);
}
}
AnimExt::CreateRandomAnim(pVanishAnimation, pThis->GetCoords(), pThis, nullptr, true);

pThis->KillPassengers(pThis);
pThis->Stun();
Expand Down
2 changes: 1 addition & 1 deletion src/Ext/Techno/Body.h
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ class TechnoExt
static CoordStruct GetSimpleFLH(InfantryClass* pThis, int weaponIndex, bool& FLHFound);

static void ChangeOwnerMissionFix(FootClass* pThis);
static void KillSelf(TechnoClass* pThis, AutoDeathBehavior deathOption, AnimTypeClass* pVanishAnimation, bool isInLimbo = false);
static void KillSelf(TechnoClass* pThis, AutoDeathBehavior deathOption, std::vector<AnimTypeClass*> pVanishAnimation, bool isInLimbo = false);
static void TransferMindControlOnDeploy(TechnoClass* pTechnoFrom, TechnoClass* pTechnoTo);
static void ApplyMindControlRangeLimit(TechnoClass* pThis);
static void ObjectKilledBy(TechnoClass* pThis, TechnoClass* pKiller);
Expand Down
7 changes: 1 addition & 6 deletions src/Ext/TerrainType/Body.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,7 @@ int TerrainTypeExt::ExtData::GetCellsPerAnim()
void TerrainTypeExt::ExtData::PlayDestroyEffects(const CoordStruct& coords)
{
VocClass::PlayIndexAtPos(this->DestroySound, coords);

if (!this->DestroyAnim.empty())
{
if (auto const pAnimType = this->DestroyAnim[ScenarioClass::Instance->Random.RandomRanged(0, this->DestroyAnim.size() - 1)])
GameCreate<AnimClass>(pAnimType, coords);
}
AnimExt::CreateRandomAnim(this->DestroyAnim, coords);
}

void TerrainTypeExt::Remove(TerrainClass* pTerrain)
Expand Down
9 changes: 1 addition & 8 deletions src/Ext/WarheadType/Detonate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -253,14 +253,7 @@ void WarheadTypeExt::ExtData::ApplyShieldModifiers(TechnoClass* pTarget, TechnoE
};

if (this->Shield_Break && pTargetExt->Shield->IsActive() && isShieldTypeEligible(this->Shield_Break_Types.GetElements(this->Shield_AffectTypes)))
{
AnimTypeClass* pAnimType = nullptr;

if (!this->Shield_BreakAnim.empty())
pAnimType = this->Shield_BreakAnim[ScenarioClass::Instance->Random.RandomRanged(0, this->Shield_BreakAnim.size() - 1)];

pTargetExt->Shield->BreakShield(pAnimType, this->Shield_BreakWeapon);
}
pTargetExt->Shield->BreakShield(this->Shield_BreakAnim, this->Shield_BreakWeapon);

if (this->Shield_Respawn_Duration > 0 && isShieldTypeEligible(this->Shield_Respawn_Types.GetElements(this->Shield_AffectTypes)))
{
Expand Down
43 changes: 12 additions & 31 deletions src/New/Entity/ShieldClass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,12 +231,7 @@ int ShieldClass::ReceiveDamage(args_ReceiveDamage* args)
int actualResidueDamage = Math::max(0, int((double)(originalShieldDamage - this->HP) /
GeneralUtils::GetWarheadVersusArmor(args->WH, this->GetArmorType()))); //only absord percentage damage

AnimTypeClass* pAnimType = nullptr;

if (!pWHExt->Shield_BreakAnim.empty())
pAnimType = pWHExt->Shield_BreakAnim[ScenarioClass::Instance->Random.RandomRanged(0, pWHExt->Shield_BreakAnim.size() - 1)];

this->BreakShield(pAnimType, pWHExt->Shield_BreakWeapon.Get(nullptr));
this->BreakShield(pWHExt->Shield_BreakAnim, pWHExt->Shield_BreakWeapon.Get(nullptr));

return this->Type->AbsorbOverDamage ? healthDamage : actualResidueDamage + healthDamage;
}
Expand Down Expand Up @@ -265,14 +260,7 @@ int ShieldClass::ReceiveDamage(args_ReceiveDamage* args)
}

if (!pWHExt->Shield_SkipHitAnim)
{
AnimTypeClass* pAnimType = nullptr;

if (!pWHExt->Shield_HitAnim.empty())
pAnimType = pWHExt->Shield_HitAnim[ScenarioClass::Instance->Random.RandomRanged(0, pWHExt->Shield_HitAnim.size() - 1)];

this->WeaponNullifyAnim(pAnimType);
}
this->WeaponNullifyAnim(pWHExt->Shield_HitAnim);

this->HP = -residueDamage;

Expand Down Expand Up @@ -331,16 +319,15 @@ void ShieldClass::ResponseAttack()
}
}

void ShieldClass::WeaponNullifyAnim(AnimTypeClass* pHitAnim)
void ShieldClass::WeaponNullifyAnim(std::vector<AnimTypeClass*> pHitAnim)
{
if (this->AreAnimsHidden)
return;

if (!pHitAnim && !this->Type->HitAnim.empty())
pHitAnim = this->Type->HitAnim[ScenarioClass::Instance->Random.RandomRanged(0, this->Type->HitAnim.size() - 1)];
if (pHitAnim.empty())
pHitAnim = this->Type->HitAnim;

if (pHitAnim)
GameCreate<AnimClass>(pHitAnim, this->Techno->GetCoords());
AnimExt::CreateRandomAnim(pDelType->Anim, this->Techno->GetCoords(), this->Techno);
}

bool ShieldClass::CanBeTargeted(WeaponTypeClass* pWeapon) const
Expand Down Expand Up @@ -664,7 +651,8 @@ void ShieldClass::SelfHealing()
}
else if (this->HP <= 0)
{
this->BreakShield();
std::vector<AnimTypeClass*> nothing;
this->BreakShield(nothing);
}
}
}
Expand All @@ -681,7 +669,7 @@ int ShieldClass::GetPercentageAmount(double iStatus)
return (int)trunc(iStatus);
}

void ShieldClass::BreakShield(AnimTypeClass* pBreakAnim, WeaponTypeClass* pBreakWeapon)
void ShieldClass::BreakShield(std::vector<AnimTypeClass*> pBreakAnim, WeaponTypeClass* pBreakWeapon)
{
this->HP = 0;

Expand All @@ -693,17 +681,10 @@ void ShieldClass::BreakShield(AnimTypeClass* pBreakAnim, WeaponTypeClass* pBreak

if (!this->AreAnimsHidden)
{
if (!pBreakAnim && !this->Type->BreakAnim.empty())
pBreakAnim = this->Type->BreakAnim[ScenarioClass::Instance->Random.RandomRanged(0, this->Type->BreakAnim.size() - 1)];
if (!pBreakAnim.empty())
pBreakAnim = this->Type->BreakAnim;

if (pBreakAnim)
{
if (auto const pAnim = GameCreate<AnimClass>(pBreakAnim, this->Techno->Location))
{
pAnim->SetOwnerObject(this->Techno);
pAnim->Owner = this->Techno->Owner;
}
}
AnimExt::CreateRandomAnim(pBreakAnim, this->Techno->Location, this->Techno);
}

const auto pWeaponType = pBreakWeapon ? pBreakWeapon : this->Type->BreakWeapon;
Expand Down
4 changes: 2 additions & 2 deletions src/New/Entity/ShieldClass.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class ShieldClass
int ReceiveDamage(args_ReceiveDamage* args);
bool CanBeTargeted(WeaponTypeClass* pWeapon) const;
bool CanBePenetrated(WarheadTypeClass* pWarhead) const;
void BreakShield(AnimTypeClass* pBreakAnim = nullptr, WeaponTypeClass* pBreakWeapon = nullptr);
void BreakShield(std::vector<AnimTypeClass*> pBreakAnim, WeaponTypeClass* pBreakWeapon = nullptr);

void SetRespawn(int duration, double amount, int rate, bool resetTimer);
void SetSelfHealing(int duration, double amount, int rate, bool restartInCombat, int restartInCombatDelay, bool resetTimer);
Expand Down Expand Up @@ -67,7 +67,7 @@ class ShieldClass
void UpdateIdleAnim();
AnimTypeClass* GetIdleAnimType();

void WeaponNullifyAnim(AnimTypeClass* pHitAnim = nullptr);
void WeaponNullifyAnim(std::vector<AnimTypeClass*> pHitAnim);
void ResponseAttack();

void CloakCheck();
Expand Down

0 comments on commit 42342b7

Please sign in to comment.