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

[Minor] Use SetAnimOwnerHouseKind to set owner for anim #1502

Open
wants to merge 4 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions src/Ext/Anim/Body.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,10 +262,9 @@ void AnimExt::SpawnFireAnims(AnimClass* pThis)

auto const loopCount = ScenarioClass::Instance->Random.RandomRanged(1, 2);
auto const pAnim = GameCreate<AnimClass>(pType, newCoords, 0, loopCount, 0x600u, 0, false);
pAnim->Owner = pThis->Owner;
AnimExt::SetAnimOwnerHouseKind(pAnim, pThis->Owner, nullptr, false, true);
auto const pExtNew = AnimExt::ExtMap.Find(pAnim);
pExtNew->Invoker = pExt->Invoker;
pExtNew->InvokerHouse = pExt->InvokerHouse;
pExtNew->SetInvoker(pExt->Invoker, pExt->InvokerHouse);

if (attach && pThis->OwnerObject)
pAnim->SetOwnerObject(pThis->OwnerObject);
Expand Down Expand Up @@ -387,7 +386,7 @@ void AnimExt::InvalidateTechnoPointers(TechnoClass* pTechno)
}

if (pExt->Invoker == pTechno)
pExt->Invoker = nullptr;
pExt->SetInvoker(nullptr);

if ((TechnoClass*)pExt->ParentBuilding == pTechno)
pExt->ParentBuilding = nullptr;
Expand Down
2 changes: 1 addition & 1 deletion src/Ext/Bullet/Hooks.DetonateLogics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ DEFINE_HOOK(0x469E34, BulletClass_Logics_DebrisAnims, 0x5)
auto const pAnim = GameCreate<AnimClass>(debrisAnims[debrisIndex], pThis->GetCoords());

if (pThis->Owner)
pAnim->Owner = pThis->Owner->Owner;
AnimExt::SetAnimOwnerHouseKind(pAnim, pThis->Owner->Owner, nullptr, false, true);

debrisCount--;
}
Expand Down
25 changes: 9 additions & 16 deletions src/Ext/Techno/Body.Update.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,8 @@ void TechnoExt::ExtData::EatPassengers()
{
auto const pAnim = GameCreate<AnimClass>(pAnimType, pThis->Location);
pAnim->SetOwnerObject(pThis);
pAnim->Owner = pThis->Owner;
AnimExt::SetAnimOwnerHouseKind(pAnim, pThis->Owner, nullptr, false, true);
AnimExt::ExtMap.Find(pAnim)->SetInvoker(pThis);
}

// Check if there is money refund
Expand Down Expand Up @@ -570,16 +571,11 @@ void TechnoExt::ExtData::UpdateMindControlAnim()
offset = pThis->GetTechnoType()->MindControlRingOffset;

coords.Z += offset;
auto anim = GameCreate<AnimClass>(this->MindControlRingAnimType, coords, 0, 1);
pThis->MindControlRingAnim = GameCreate<AnimClass>(this->MindControlRingAnimType, coords, 0, 1);
pThis->MindControlRingAnim->SetOwnerObject(pThis);

if (anim)
{
pThis->MindControlRingAnim = anim;
pThis->MindControlRingAnim->SetOwnerObject(pThis);

if (pThis->WhatAmI() == AbstractType::Building)
pThis->MindControlRingAnim->ZAdjust = -1024;
}
if (pThis->WhatAmI() == AbstractType::Building)
pThis->MindControlRingAnim->ZAdjust = -1024;
}
}
else if (this->MindControlRingAnimType)
Expand Down Expand Up @@ -708,12 +704,9 @@ void TechnoExt::KillSelf(TechnoClass* pThis, AutoDeathBehavior deathOption, Anim
{
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);
}
auto const pAnim = GameCreate<AnimClass>(pVanishAnimation, pThis->GetCoords());
AnimExt::SetAnimOwnerHouseKind(pAnim, pThis->Owner, nullptr, false, true);
AnimExt::ExtMap.Find(pAnim)->SetInvoker(pThis);
}

pThis->KillPassengers(pThis);
Expand Down
5 changes: 5 additions & 0 deletions src/Ext/Techno/Hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <ScenarioClass.h>
#include <TunnelLocomotionClass.h>

#include <Ext/Anim/Body.h>
#include <Ext/BuildingType/Body.h>
#include <Ext/House/Body.h>
#include <Ext/WarheadType/Body.h>
Expand Down Expand Up @@ -82,7 +83,11 @@ DEFINE_HOOK(0x6F9FA9, TechnoClass_AI_PromoteAnim, 0x6)
promAnim = GameCreate<AnimClass>(RulesExt::Global()->Promote_EliteAnimation, pThis->GetCenterCoords());

if(promAnim)
{
promAnim->SetOwnerObject(pThis);
AnimExt::SetAnimOwnerHouseKind(promAnim, pThis->Owner, nullptr, false, true);
AnimExt::ExtMap.Find(promAnim)->SetInvoker(pThis);
}
}

return aresProcess();
Expand Down
10 changes: 3 additions & 7 deletions src/Ext/TechnoType/Body.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -183,13 +183,9 @@ TechnoClass* TechnoTypeExt::CreateUnit(TechnoTypeClass* pType, CoordStruct locat

if (pSpawnAnimType)
{
if (auto const pAnim = GameCreate<AnimClass>(pSpawnAnimType, location))
{
AnimExt::SetAnimOwnerHouseKind(pAnim, pInvokerHouse, nullptr, false, true);

if (auto const pAnimExt = AnimExt::ExtMap.Find(pAnim))
pAnimExt->SetInvoker(pInvoker, pInvokerHouse);
}
auto const pAnim = GameCreate<AnimClass>(pSpawnAnimType, location);
AnimExt::SetAnimOwnerHouseKind(pAnim, pInvokerHouse, nullptr, false, true);
AnimExt::ExtMap.Find(pAnim)->SetInvoker(pInvoker, pInvokerHouse);
}

if (!pTechno->InLimbo)
Expand Down
17 changes: 13 additions & 4 deletions src/Ext/TechnoType/Hooks.Teleport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <LocomotionClass.h>
#include <TeleportLocomotionClass.h>

#include <Ext/Anim/Body.h>
#include <Ext/Techno/Body.h>
#include <Ext/WeaponType/Body.h>
#include <TacticalClass.h>
Expand All @@ -19,7 +20,10 @@ DEFINE_HOOK(0x7193F6, TeleportLocomotionClass_ILocomotion_Process_WarpoutAnim, 0
GET_LOCO(ESI);

if (auto pWarpOut = pExt->WarpOut.Get(RulesClass::Instance->WarpOut))
GameCreate<AnimClass>(pWarpOut, pLinked->Location)->Owner = pLinked->Owner;
{
auto const pAnim = GameCreate<AnimClass>(pWarpOut, pLinked->Location);
AnimExt::SetAnimOwnerHouseKind(pAnim, pLinked->Owner, nullptr, false, true);
}

if (pExt->WarpOutWeapon)
WeaponTypeExt::DetonateAt(pExt->WarpOutWeapon, pLinked, pLinked);
Expand Down Expand Up @@ -71,8 +75,10 @@ DEFINE_HOOK(0x719742, TeleportLocomotionClass_ILocomotion_Process_WarpInAnim, 0x
GET_LOCO(ESI);

if (auto pWarpIn = pExt->WarpIn.Get(RulesClass::Instance->WarpIn))
GameCreate<AnimClass>(pWarpIn, pLinked->Location)->Owner
= pLinked->Owner;
{
auto const pAnim = GameCreate<AnimClass>(pWarpIn, pLinked->Location);
AnimExt::SetAnimOwnerHouseKind(pAnim, pLinked->Owner, nullptr, false, true);
}

auto const lastWarpDistance = TechnoExt::ExtMap.Find(pLinked)->LastWarpDistance;
bool isInMinRange = lastWarpDistance < pExt->ChronoRangeMinimum.Get(RulesClass::Instance->ChronoRangeMinimum);
Expand All @@ -91,7 +97,10 @@ DEFINE_HOOK(0x719827, TeleportLocomotionClass_ILocomotion_Process_WarpAway, 0x5)
GET_LOCO(ESI);

if (auto pWarpAway = pExt->WarpAway.Get(RulesClass::Instance->WarpOut))
GameCreate<AnimClass>(pWarpAway, pLinked->Location)->Owner = pLinked->Owner;
{
auto const pAnim = GameCreate<AnimClass>(pWarpAway, pLinked->Location);
AnimExt::SetAnimOwnerHouseKind(pAnim, pLinked->Owner, nullptr, false, true);
}

return 0x719878;
}
Expand Down
3 changes: 3 additions & 0 deletions src/Ext/Unit/Hooks.Unload.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <TechnoClass.h>
#include <TunnelLocomotionClass.h>

#include <Ext/Anim/Body.h>
#include <Ext/Building/Body.h>
#include <Ext/Techno/Body.h>
#include <Utilities/EnumFunctions.h>
Expand Down Expand Up @@ -205,6 +206,8 @@ DEFINE_HOOK(0x739BA8, UnitClass_DeployUndeploy_DeployAnim, 0x5)

pThis->DeployAnim = pAnim;
pAnim->SetOwnerObject(pThis);
AnimExt::SetAnimOwnerHouseKind(pAnim, pThis->Owner, nullptr, false, true);
AnimExt::ExtMap.Find(pAnim)->SetInvoker(pThis);

if (pExt->DeployingAnim_UseUnitDrawer)
return isDeploying ? DeployUseUnitDrawer : UndeployUseUnitDrawer;
Expand Down
8 changes: 5 additions & 3 deletions src/Ext/WarheadType/Detonate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,9 @@ void WarheadTypeExt::ExtData::Detonate(TechnoClass* pOwner, HouseClass* pHouse,
if (this->Crit_ActiveChanceAnims.size() > 0 && this->Crit_CurrentChance > 0.0)
{
int idx = ScenarioClass::Instance->Random.RandomRanged(0, this->Crit_ActiveChanceAnims.size() - 1);
GameCreate<AnimClass>(this->Crit_ActiveChanceAnims[idx], coords);
auto const pAnim = GameCreate<AnimClass>(this->Crit_ActiveChanceAnims[idx], coords);
AnimExt::SetAnimOwnerHouseKind(pAnim, pHouse, nullptr, false, true);
AnimExt::ExtMap.Find(pAnim)->SetInvoker(pOwner, pHouse);
}

bool bulletWasIntercepted = pBulletExt && pBulletExt->InterceptedStatus == InterceptedStatus::Intercepted;
Expand Down Expand Up @@ -336,15 +338,15 @@ void WarheadTypeExt::ExtData::ApplyCrit(HouseClass* pHouse, TechnoClass* pTarget
ScenarioClass::Instance->Random.RandomRanged(0, this->Crit_AnimList.size() - 1) : 0;

auto const pAnim = GameCreate<AnimClass>(this->Crit_AnimList[idx], pTarget->Location);
pAnim->Owner = pHouse;
AnimExt::SetAnimOwnerHouseKind(pAnim, pHouse, nullptr, false, true);
AnimExt::ExtMap.Find(pAnim)->SetInvoker(pOwner, pHouse);
}
else
{
for (auto const& pType : this->Crit_AnimList)
{
auto const pAnim = GameCreate<AnimClass>(pType, pTarget->Location);
pAnim->Owner = pHouse;
AnimExt::SetAnimOwnerHouseKind(pAnim, pHouse, nullptr, false, true);
AnimExt::ExtMap.Find(pAnim)->SetInvoker(pOwner, pHouse);
}
}
Expand Down
11 changes: 5 additions & 6 deletions src/New/Entity/AttachEffectClass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,16 +308,15 @@ void AttachEffectClass::CreateAnim()
auto const pAnim = GameCreate<AnimClass>(pAnimType, this->Techno->Location);

pAnim->SetOwnerObject(this->Techno);
pAnim->Owner = this->Type->Animation_UseInvokerAsOwner ? InvokerHouse : this->Techno->Owner;
auto const pOwner = this->Type->Animation_UseInvokerAsOwner ? InvokerHouse : this->Techno->Owner;
AnimExt::SetAnimOwnerHouseKind(pAnim, pOwner, nullptr, false, true);
pAnim->RemainingIterations = 0xFFu;
this->Animation = pAnim;

if (this->Type->Animation_UseInvokerAsOwner)
{
auto const pAnimExt = AnimExt::ExtMap.Find(pAnim);
pAnimExt->SetInvoker(Invoker);
}

AnimExt::ExtMap.Find(pAnim)->SetInvoker(Invoker);
else
AnimExt::ExtMap.Find(pAnim)->SetInvoker(this->Techno);
}
}

Expand Down
10 changes: 8 additions & 2 deletions src/New/Entity/ShieldClass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,11 @@ void ShieldClass::WeaponNullifyAnim(AnimTypeClass* pHitAnim)
const auto pAnimType = pHitAnim ? pHitAnim : this->Type->HitAnim;

if (pAnimType)
GameCreate<AnimClass>(pAnimType, this->Techno->GetCoords());
{
auto const pAnim = GameCreate<AnimClass>(pAnimType, this->Techno->GetCoords());
AnimExt::SetAnimOwnerHouseKind(pAnim, this->Techno->Owner, nullptr, false, true);
AnimExt::ExtMap.Find(pAnim)->SetInvoker(this->Techno);
}
}

bool ShieldClass::CanBeTargeted(WeaponTypeClass* pWeapon) const
Expand Down Expand Up @@ -690,7 +694,8 @@ void ShieldClass::BreakShield(AnimTypeClass* pBreakAnim, WeaponTypeClass* pBreak
auto const pAnim = GameCreate<AnimClass>(pAnimType, this->Techno->Location);

pAnim->SetOwnerObject(this->Techno);
pAnim->Owner = this->Techno->Owner;
AnimExt::SetAnimOwnerHouseKind(pAnim, this->Techno->Owner, nullptr, false, true);
AnimExt::ExtMap.Find(pAnim)->SetInvoker(this->Techno);
}
}

Expand Down Expand Up @@ -780,6 +785,7 @@ void ShieldClass::CreateAnim()

pAnim->SetOwnerObject(this->Techno);
AnimExt::SetAnimOwnerHouseKind(pAnim, this->Techno->Owner, nullptr, false, true);
AnimExt::ExtMap.Find(pAnim)->SetInvoker(this->Techno);
pAnim->RemainingIterations = 0xFFu;
this->IdleAnim = pAnim;
}
Expand Down
27 changes: 21 additions & 6 deletions src/New/Type/Affiliated/DroppodTypeClass.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ DEFINE_HOOK(0x4B5B70, DroppodLocomotionClass_ILoco_Process, 0x5)
if (auto trailerType = podType->Trailer.Get(RulesExt::Global()->DropPodTrailer))
{
auto trailer = GameCreate<AnimClass>(trailerType, oldLoc);
trailer->Owner = pLinked->Owner;
AnimExt::SetAnimOwnerHouseKind(trailer, pLinked->Owner, nullptr, false, true);
if (podType->Trailer_Attached)
trailer->SetOwnerObject(pLinked);
}
Expand All @@ -118,7 +118,10 @@ DEFINE_HOOK(0x4B5B70, DroppodLocomotionClass_ILoco_Process, 0x5)
VocClass::PlayAt(dWpn->Report[Randomizer::Global->Random() % count], coords);
MapClass::DamageArea(locnear, 2 * dWpn->Damage, pLinked, dWpn->Warhead, true, pLinked->Owner);
if (auto dmgAnim = MapClass::SelectDamageAnimation(2 * dWpn->Damage, dWpn->Warhead, LandType::Clear, locnear))
GameCreate<AnimClass>(dmgAnim, locnear, 0, 1, 0x2600, -15, 0)->Owner = pLinked->Owner;
{
auto const pAnim = GameCreate<AnimClass>(dmgAnim, locnear, 0, 1, 0x2600, -15, 0);
AnimExt::SetAnimOwnerHouseKind(pAnim, pLinked->Owner, nullptr, false, true);
}
}
}
}
Expand All @@ -133,10 +136,16 @@ DEFINE_HOOK(0x4B5B70, DroppodLocomotionClass_ILoco_Process, 0x5)
if (pLinked->Unlimbo(pLinked->Location, DirType::North))
{
if (auto puff = podType->Puff.Get(RulesClass::Instance->DropPodPuff))
GameCreate<AnimClass>(puff, pLinked->Location)->Owner = pLinked->Owner;
{
auto const pAnim = GameCreate<AnimClass>(puff, pLinked->Location);
AnimExt::SetAnimOwnerHouseKind(pAnim, pLinked->Owner, nullptr, false, true);
}

if (auto podAnim = podType->GroundAnim[lThis->OutOfMap].Get(RulesClass::Instance->DropPod[lThis->OutOfMap]))
GameCreate<AnimClass>(podAnim, pLinked->Location)->Owner = pLinked->Owner;
{
auto const pAnim = GameCreate<AnimClass>(podAnim, pLinked->Location);
AnimExt::SetAnimOwnerHouseKind(pAnim, pLinked->Owner, nullptr, false, true);
}

if (dWpn && podType->Weapon_HitLandOnly)
WeaponTypeExt::DetonateAt(dWpn, pLinked->Location, pLinked, pLinked->Owner);
Expand All @@ -155,7 +164,10 @@ DEFINE_HOOK(0x4B5B70, DroppodLocomotionClass_ILoco_Process, 0x5)
{
MapClass::DamageArea(coords, 100, pLinked, RulesClass::Instance->C4Warhead, true, pLinked->Owner);
if (auto dmgAnim = MapClass::SelectDamageAnimation(100, RulesClass::Instance->C4Warhead, LandType::Clear, coords))
GameCreate<AnimClass>(dmgAnim, coords, 0, 1, 0x2600, -15, 0)->Owner = pLinked->Owner;
{
auto const pAnim = GameCreate<AnimClass>(dmgAnim, coords, 0, 1, 0x2600, -15, 0);
AnimExt::SetAnimOwnerHouseKind(pAnim, pLinked->Owner, nullptr, false, true);
}
}
lThis->Release();
}
Expand Down Expand Up @@ -194,7 +206,10 @@ DEFINE_HOOK(0x4B607D, DroppodLocomotionClass_ILoco_MoveTo, 0x8)
{
pLinked->PrimaryFacing.SetCurrent(DirStruct { DirType::South });
if (auto entryAnim = podType->AtmosphereEntry.Get(RulesClass::Instance->AtmosphereEntry))
GameCreate<AnimClass>(entryAnim, to)->Owner = pLinked->Owner;
{
auto const pAnim = GameCreate<AnimClass>(entryAnim, to);
AnimExt::SetAnimOwnerHouseKind(pAnim, pLinked->Owner, nullptr, false, true);
}
}

return 0x4B61F0;
Expand Down