Skip to content

Commit 29f26ce

Browse files
committed
random anims
1 parent 2b28804 commit 29f26ce

File tree

10 files changed

+66
-91
lines changed

10 files changed

+66
-91
lines changed

src/Ext/Anim/Body.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,43 @@ void AnimExt::HandleDebrisImpact(AnimTypeClass* pExpireAnim, AnimTypeClass* pWak
189189
}
190190
}
191191

192+
AnimClass* AnimExt::CreateRandomAnim(std::vector<AnimTypeClass*> AnimList, CoordStruct coords, TechnoClass* pTechno, HouseClass* pHouse, bool invoker)
193+
{
194+
if (!AnimList.empty())
195+
{
196+
if (auto const pAnimType = AnimList[ScenarioClass::Instance->Random.RandomRanged(0, AnimList.size() - 1)])
197+
{
198+
if (auto const pAnim = GameCreate<AnimClass>(pAnimType, coords))
199+
{
200+
if (pTechno)
201+
{
202+
pAnim->SetOwnerObject(pTechno);
203+
pAnim->Owner = pHouse ? pHouse : pTechno->Owner;
204+
205+
if (invoker)
206+
{
207+
if (auto const pAnimExt = AnimExt::ExtMap.Find(pAnim))
208+
{
209+
if (pHouse)
210+
pAnimExt->SetInvoker(pTechno, pHouse);
211+
else
212+
pAnimExt->SetInvoker(pTechno);
213+
}
214+
}
215+
}
216+
else if (pHouse)
217+
{
218+
pAnim->Owner = pHouse;
219+
}
220+
221+
return pAnim;
222+
}
223+
}
224+
}
225+
226+
return nullptr;
227+
}
228+
192229
// =============================
193230
// load / save
194231

src/Ext/Anim/Body.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,4 +80,6 @@ class AnimExt
8080

8181
static void InvalidateTechnoPointers(TechnoClass* pTechno);
8282
static void InvalidateParticleSystemPointers(ParticleSystemClass* pParticleSystem);
83+
84+
static AnimClass* CreateRandomAnim(std::vector<AnimTypeClass*> AnimList, CoordStruct coords, TechnoClass* pTechno = nullptr, HouseClass* pHouse = nullptr, bool invoker = false);
8385
};

src/Ext/Anim/Hooks.AnimCreateUnit.cpp

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -144,19 +144,8 @@ DEFINE_HOOK(0x424932, AnimClass_AI_CreateUnit_ActualAffects, 0x6)
144144

145145
if (success)
146146
{
147-
if (!pTypeExt->CreateUnit_SpawnAnim.empty())
148-
{
149-
if (auto const pAnimType = pTypeExt->CreateUnit_SpawnAnim[ScenarioClass::Instance->Random.RandomRanged(0, pTypeExt->CreateUnit_SpawnAnim.size() - 1)])
150-
{
151-
if (auto const pAnim = GameCreate<AnimClass>(pAnimType, location))
152-
{
153-
AnimExt::SetAnimOwnerHouseKind(pAnim, pInvokerHouse, nullptr, false, true);
154-
155-
if (auto const pAnimExt = AnimExt::ExtMap.Find(pAnim))
156-
pAnimExt->SetInvoker(pInvoker, pInvokerHouse);
157-
}
158-
}
159-
}
147+
if (auto const pAnim = AnimExt::CreateRandomAnim(pTypeExt->CreateUnit_SpawnAnim, location, pInvoker, pInvokerHouse, true))
148+
AnimExt::SetAnimOwnerHouseKind(pAnim, pInvokerHouse, nullptr, false, true);
160149

161150
if (pTechno->HasTurret() && pExt->FromDeathUnit && pExt->DeathUnitHasTurret && pTypeExt->CreateUnit_InheritTurretFacings)
162151
{

src/Ext/Techno/Body.Update.cpp

Lines changed: 7 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -136,15 +136,11 @@ bool TechnoExt::ExtData::CheckDeathConditions(bool isInLimbo)
136136

137137
// Self-destruction must be enabled
138138
const auto howToDie = pTypeExt->AutoDeath_Behavior.Get();
139-
AnimTypeClass* pVanishAnim = nullptr;
140-
141-
if (!pTypeExt->AutoDeath_VanishAnimation.empty())
142-
pVanishAnim = pTypeExt->AutoDeath_VanishAnimation[ScenarioClass::Instance->Random.RandomRanged(0, pTypeExt->AutoDeath_VanishAnimation.size() - 1)];
143139

144140
// Death if no ammo
145141
if (pType->Ammo > 0 && pThis->Ammo <= 0 && pTypeExt->AutoDeath_OnAmmoDepletion)
146142
{
147-
TechnoExt::KillSelf(pThis, howToDie, pVanishAnim, isInLimbo);
143+
TechnoExt::KillSelf(pThis, howToDie, pTypeExt->AutoDeath_VanishAnimation, isInLimbo);
148144
return true;
149145
}
150146

@@ -157,7 +153,7 @@ bool TechnoExt::ExtData::CheckDeathConditions(bool isInLimbo)
157153
}
158154
else if (this->AutoDeathTimer.Completed())
159155
{
160-
TechnoExt::KillSelf(pThis, howToDie, pVanishAnim, isInLimbo);
156+
TechnoExt::KillSelf(pThis, howToDie, pTypeExt->AutoDeath_VanishAnimation, isInLimbo);
161157
return true;
162158
}
163159
}
@@ -186,7 +182,7 @@ bool TechnoExt::ExtData::CheckDeathConditions(bool isInLimbo)
186182
{
187183
if (!existTechnoTypes(pTypeExt->AutoDeath_TechnosDontExist, pTypeExt->AutoDeath_TechnosDontExist_Houses, !pTypeExt->AutoDeath_TechnosDontExist_Any, pTypeExt->AutoDeath_TechnosDontExist_AllowLimboed))
188184
{
189-
TechnoExt::KillSelf(pThis, howToDie, pVanishAnim, isInLimbo);
185+
TechnoExt::KillSelf(pThis, howToDie, pTypeExt->AutoDeath_VanishAnimation, isInLimbo);
190186

191187
return true;
192188
}
@@ -197,7 +193,7 @@ bool TechnoExt::ExtData::CheckDeathConditions(bool isInLimbo)
197193
{
198194
if (existTechnoTypes(pTypeExt->AutoDeath_TechnosExist, pTypeExt->AutoDeath_TechnosExist_Houses, pTypeExt->AutoDeath_TechnosExist_Any, pTypeExt->AutoDeath_TechnosExist_AllowLimboed))
199195
{
200-
TechnoExt::KillSelf(pThis, howToDie, pVanishAnim, isInLimbo);
196+
TechnoExt::KillSelf(pThis, howToDie, pTypeExt->AutoDeath_VanishAnimation, isInLimbo);
201197

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

289-
if (!pDelType->Anim.empty())
290-
{
291-
if (auto const pAnimType = pDelType->Anim[ScenarioClass::Instance->Random.RandomRanged(0, pDelType->Anim.size() - 1)])
292-
{
293-
if (auto const pAnim = GameCreate<AnimClass>(pAnimType, pThis->Location))
294-
{
295-
pAnim->SetOwnerObject(pThis);
296-
pAnim->Owner = pThis->Owner;
297-
}
298-
}
299-
}
285+
AnimExt::CreateRandomAnim(pDelType->Anim, pThis->Location, pThis);
300286

301287
// Check if there is money refund
302288
if (pDelType->Soylent &&
@@ -694,7 +680,7 @@ void TechnoExt::ApplyMindControlRangeLimit(TechnoClass* pThis)
694680
}
695681
}
696682

697-
void TechnoExt::KillSelf(TechnoClass* pThis, AutoDeathBehavior deathOption, AnimTypeClass* pVanishAnimation, bool isInLimbo)
683+
void TechnoExt::KillSelf(TechnoClass* pThis, AutoDeathBehavior deathOption, std::vector<AnimTypeClass*> pVanishAnimation, bool isInLimbo)
698684
{
699685
if (isInLimbo)
700686
{
@@ -715,15 +701,7 @@ void TechnoExt::KillSelf(TechnoClass* pThis, AutoDeathBehavior deathOption, Anim
715701

716702
case AutoDeathBehavior::Vanish:
717703
{
718-
if (pVanishAnimation)
719-
{
720-
if (auto const pAnim = GameCreate<AnimClass>(pVanishAnimation, pThis->GetCoords()))
721-
{
722-
auto const pAnimExt = AnimExt::ExtMap.Find(pAnim);
723-
pAnim->Owner = pThis->Owner;
724-
pAnimExt->SetInvoker(pThis);
725-
}
726-
}
704+
AnimExt::CreateRandomAnim(pVanishAnimation, pThis->GetCoords(), pThis, nullptr, true);
727705

728706
pThis->KillPassengers(pThis);
729707
pThis->Stun();

src/Ext/Techno/Body.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ class TechnoExt
143143
static CoordStruct GetSimpleFLH(InfantryClass* pThis, int weaponIndex, bool& FLHFound);
144144

145145
static void ChangeOwnerMissionFix(FootClass* pThis);
146-
static void KillSelf(TechnoClass* pThis, AutoDeathBehavior deathOption, AnimTypeClass* pVanishAnimation, bool isInLimbo = false);
146+
static void KillSelf(TechnoClass* pThis, AutoDeathBehavior deathOption, std::vector<AnimTypeClass*> pVanishAnimation, bool isInLimbo = false);
147147
static void TransferMindControlOnDeploy(TechnoClass* pTechnoFrom, TechnoClass* pTechnoTo);
148148
static void ApplyMindControlRangeLimit(TechnoClass* pThis);
149149
static void ObjectKilledBy(TechnoClass* pThis, TechnoClass* pKiller);

src/Ext/TerrainType/Body.cpp

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,7 @@ int TerrainTypeExt::ExtData::GetCellsPerAnim()
2323
void TerrainTypeExt::ExtData::PlayDestroyEffects(const CoordStruct& coords)
2424
{
2525
VocClass::PlayIndexAtPos(this->DestroySound, coords);
26-
27-
if (!this->DestroyAnim.empty())
28-
{
29-
if (auto const pAnimType = this->DestroyAnim[ScenarioClass::Instance->Random.RandomRanged(0, this->DestroyAnim.size() - 1)])
30-
GameCreate<AnimClass>(pAnimType, coords);
31-
}
26+
AnimExt::CreateRandomAnim(this->DestroyAnim, coords);
3227
}
3328

3429
void TerrainTypeExt::Remove(TerrainClass* pTerrain)

src/Ext/WarheadType/Detonate.cpp

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -253,14 +253,7 @@ void WarheadTypeExt::ExtData::ApplyShieldModifiers(TechnoClass* pTarget, TechnoE
253253
};
254254

255255
if (this->Shield_Break && pTargetExt->Shield->IsActive() && isShieldTypeEligible(this->Shield_Break_Types.GetElements(this->Shield_AffectTypes)))
256-
{
257-
AnimTypeClass* pAnimType = nullptr;
258-
259-
if (!this->Shield_BreakAnim.empty())
260-
pAnimType = this->Shield_BreakAnim[ScenarioClass::Instance->Random.RandomRanged(0, this->Shield_BreakAnim.size() - 1)];
261-
262-
pTargetExt->Shield->BreakShield(pAnimType, this->Shield_BreakWeapon);
263-
}
256+
pTargetExt->Shield->BreakShield(this->Shield_BreakAnim, this->Shield_BreakWeapon);
264257

265258
if (this->Shield_Respawn_Duration > 0 && isShieldTypeEligible(this->Shield_Respawn_Types.GetElements(this->Shield_AffectTypes)))
266259
{

src/New/Entity/ShieldClass.cpp

Lines changed: 12 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -231,12 +231,7 @@ int ShieldClass::ReceiveDamage(args_ReceiveDamage* args)
231231
int actualResidueDamage = Math::max(0, int((double)(originalShieldDamage - this->HP) /
232232
GeneralUtils::GetWarheadVersusArmor(args->WH, this->GetArmorType()))); //only absord percentage damage
233233

234-
AnimTypeClass* pAnimType = nullptr;
235-
236-
if (!pWHExt->Shield_BreakAnim.empty())
237-
pAnimType = pWHExt->Shield_BreakAnim[ScenarioClass::Instance->Random.RandomRanged(0, pWHExt->Shield_BreakAnim.size() - 1)];
238-
239-
this->BreakShield(pAnimType, pWHExt->Shield_BreakWeapon.Get(nullptr));
234+
this->BreakShield(pWHExt->Shield_BreakAnim, pWHExt->Shield_BreakWeapon.Get(nullptr));
240235

241236
return this->Type->AbsorbOverDamage ? healthDamage : actualResidueDamage + healthDamage;
242237
}
@@ -265,14 +260,7 @@ int ShieldClass::ReceiveDamage(args_ReceiveDamage* args)
265260
}
266261

267262
if (!pWHExt->Shield_SkipHitAnim)
268-
{
269-
AnimTypeClass* pAnimType = nullptr;
270-
271-
if (!pWHExt->Shield_HitAnim.empty())
272-
pAnimType = pWHExt->Shield_HitAnim[ScenarioClass::Instance->Random.RandomRanged(0, pWHExt->Shield_HitAnim.size() - 1)];
273-
274-
this->WeaponNullifyAnim(pAnimType);
275-
}
263+
this->WeaponNullifyAnim(pWHExt->Shield_HitAnim);
276264

277265
this->HP = -residueDamage;
278266

@@ -331,16 +319,15 @@ void ShieldClass::ResponseAttack()
331319
}
332320
}
333321

334-
void ShieldClass::WeaponNullifyAnim(AnimTypeClass* pHitAnim)
322+
void ShieldClass::WeaponNullifyAnim(std::vector<AnimTypeClass*> pHitAnim)
335323
{
336324
if (this->AreAnimsHidden)
337325
return;
338326

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

342-
if (pHitAnim)
343-
GameCreate<AnimClass>(pHitAnim, this->Techno->GetCoords());
330+
AnimExt::CreateRandomAnim(pHitAnim, this->Techno->GetCoords(), this->Techno);
344331
}
345332

346333
bool ShieldClass::CanBeTargeted(WeaponTypeClass* pWeapon) const
@@ -664,7 +651,8 @@ void ShieldClass::SelfHealing()
664651
}
665652
else if (this->HP <= 0)
666653
{
667-
this->BreakShield();
654+
std::vector<AnimTypeClass*> nothing;
655+
this->BreakShield(nothing);
668656
}
669657
}
670658
}
@@ -681,7 +669,7 @@ int ShieldClass::GetPercentageAmount(double iStatus)
681669
return (int)trunc(iStatus);
682670
}
683671

684-
void ShieldClass::BreakShield(AnimTypeClass* pBreakAnim, WeaponTypeClass* pBreakWeapon)
672+
void ShieldClass::BreakShield(std::vector<AnimTypeClass*> pBreakAnim, WeaponTypeClass* pBreakWeapon)
685673
{
686674
this->HP = 0;
687675

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

694682
if (!this->AreAnimsHidden)
695683
{
696-
if (!pBreakAnim && !this->Type->BreakAnim.empty())
697-
pBreakAnim = this->Type->BreakAnim[ScenarioClass::Instance->Random.RandomRanged(0, this->Type->BreakAnim.size() - 1)];
684+
if (!pBreakAnim.empty())
685+
pBreakAnim = this->Type->BreakAnim;
698686

699-
if (pBreakAnim)
700-
{
701-
if (auto const pAnim = GameCreate<AnimClass>(pBreakAnim, this->Techno->Location))
702-
{
703-
pAnim->SetOwnerObject(this->Techno);
704-
pAnim->Owner = this->Techno->Owner;
705-
}
706-
}
687+
AnimExt::CreateRandomAnim(pBreakAnim, this->Techno->Location, this->Techno);
707688
}
708689

709690
const auto pWeaponType = pBreakWeapon ? pBreakWeapon : this->Type->BreakWeapon;

src/New/Entity/ShieldClass.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class ShieldClass
2020
int ReceiveDamage(args_ReceiveDamage* args);
2121
bool CanBeTargeted(WeaponTypeClass* pWeapon) const;
2222
bool CanBePenetrated(WarheadTypeClass* pWarhead) const;
23-
void BreakShield(AnimTypeClass* pBreakAnim = nullptr, WeaponTypeClass* pBreakWeapon = nullptr);
23+
void BreakShield(std::vector<AnimTypeClass*> pBreakAnim, WeaponTypeClass* pBreakWeapon = nullptr);
2424

2525
void SetRespawn(int duration, double amount, int rate, bool resetTimer);
2626
void SetSelfHealing(int duration, double amount, int rate, bool restartInCombat, int restartInCombatDelay, bool resetTimer);
@@ -67,7 +67,7 @@ class ShieldClass
6767
void UpdateIdleAnim();
6868
AnimTypeClass* GetIdleAnimType();
6969

70-
void WeaponNullifyAnim(AnimTypeClass* pHitAnim = nullptr);
70+
void WeaponNullifyAnim(std::vector<AnimTypeClass*> pHitAnim);
7171
void ResponseAttack();
7272

7373
void CloakCheck();

0 commit comments

Comments
 (0)