-
-
Notifications
You must be signed in to change notification settings - Fork 131
Expand file tree
/
Copy pathBody.Internal.cpp
More file actions
308 lines (254 loc) · 8.62 KB
/
Body.Internal.cpp
File metadata and controls
308 lines (254 loc) · 8.62 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
#include "Body.h"
#include <AirstrikeClass.h>
#include <Utilities/EnumFunctions.h>
// Unsorted methods
void TechnoExt::ExtData::InitializeLaserTrails()
{
if (this->LaserTrails.size())
return;
auto const pTypeExt = this->TypeExtData;
this->LaserTrails.reserve(pTypeExt->LaserTrailData.size());
for (auto const& entry : pTypeExt->LaserTrailData)
this->LaserTrails.emplace_back(std::make_unique<LaserTrailClass>(entry.GetType(), this->OwnerObject()->Owner, entry.FLH, entry.IsOnTurret));
}
void TechnoExt::ObjectKilledBy(TechnoClass* pVictim, TechnoClass* pKiller)
{
auto const pKillerType = pKiller->GetTechnoType();
auto const pObjectKiller = ((pKillerType->Spawned || pKillerType->MissileSpawn) && pKiller->SpawnOwner)
? pKiller->SpawnOwner : pKiller;
if (pObjectKiller && pObjectKiller->BelongsToATeam())
{
if (auto const pFootKiller = generic_cast<FootClass*, true>(pObjectKiller))
{
auto const pKillerTechnoData = TechnoExt::ExtMap.Find(pObjectKiller);
pKillerTechnoData->LastKillWasTeamTarget = pFootKiller->Team->Focus == pVictim;
}
}
}
// reversed from 6F3D60
CoordStruct TechnoExt::GetFLHAbsoluteCoords(TechnoClass* pThis, CoordStruct pCoord, bool isOnTurret)
{
auto const pType = pThis->GetTechnoType();
auto const pFoot = abstract_cast<FootClass*, true>(pThis);
Matrix3D mtx;
// Step 1: get body transform matrix
if (pFoot && pFoot->Locomotor)
mtx = pFoot->Locomotor->Draw_Matrix(nullptr);
else // no locomotor means no rotation or transform of any kind (f.ex. buildings) - Kerbiter
mtx.MakeIdentity();
// Steps 2-3: turret offset and rotation
if (isOnTurret && (pType->Turret || !pFoot)) // If building has no turret, it's TurretFacing is TargetDirection
{
TechnoTypeExt::ApplyTurretOffset(pType, &mtx);
const double turretRad = pThis->TurretFacing().GetRadian<32>();
// For BuildingClass turret facing is equal to primary facing
const float angle = pFoot ? (float)(turretRad - pThis->PrimaryFacing.Current().GetRadian<32>()) : (float)(turretRad);
mtx.RotateZ(angle);
}
// Step 4: apply FLH offset
mtx.Translate((float)pCoord.X, (float)pCoord.Y, (float)pCoord.Z);
auto const result = mtx.GetTranslation();
// Step 5: apply as an offset to global object coords
// Resulting coords are mirrored along X axis, so we mirror it back
auto const location = pThis->GetRenderCoords() + CoordStruct { (int)result.X, -(int)result.Y, (int)result.Z };
return location;
}
CoordStruct TechnoExt::GetBurstFLH(TechnoClass* pThis, int weaponIndex, bool& FLHFound)
{
FLHFound = false;
CoordStruct FLH = CoordStruct::Empty;
auto const pExt = TechnoExt::ExtMap.Find(pThis)->TypeExtData;
auto const pInf = abstract_cast<InfantryClass*, true>(pThis);
std::span<std::vector<CoordStruct>> pickedFLHs = pExt->WeaponBurstFLHs;
if (pThis->Veterancy.IsElite())
{
if (pInf)
{
if (pInf->IsDeployed() && pExt->EliteDeployedWeaponBurstFLHs.size() > 0)
pickedFLHs = pExt->EliteDeployedWeaponBurstFLHs;
else if (pInf->Crawling && pExt->EliteCrouchedWeaponBurstFLHs.size() > 0)
pickedFLHs = pExt->EliteCrouchedWeaponBurstFLHs;
else
pickedFLHs = pExt->EliteWeaponBurstFLHs;
}
else
{
pickedFLHs = pExt->EliteWeaponBurstFLHs;
}
}
else if (pInf)
{
if (pInf->IsDeployed() && pExt->DeployedWeaponBurstFLHs.size() > 0)
pickedFLHs = pExt->DeployedWeaponBurstFLHs;
else if (pInf->Crawling && pExt->CrouchedWeaponBurstFLHs.size() > 0)
pickedFLHs = pExt->CrouchedWeaponBurstFLHs;
}
if ((int)pickedFLHs[weaponIndex].size() > pThis->CurrentBurstIndex)
{
FLHFound = true;
FLH = pickedFLHs[weaponIndex][pThis->CurrentBurstIndex];
}
return FLH;
}
CoordStruct TechnoExt::GetSimpleFLH(InfantryClass* pThis, int weaponIndex, bool& FLHFound)
{
FLHFound = false;
CoordStruct FLH = CoordStruct::Empty;
auto const pTypeExt = TechnoTypeExt::ExtMap.Find(pThis->Type);
Nullable<CoordStruct> pickedFLH;
if (pThis->IsDeployed())
{
if (weaponIndex == 0)
pickedFLH = pTypeExt->DeployedPrimaryFireFLH;
else if (weaponIndex == 1)
pickedFLH = pTypeExt->DeployedSecondaryFireFLH;
}
else
{
if (pThis->Crawling)
{
if (weaponIndex == 0)
pickedFLH = pTypeExt->PronePrimaryFireFLH;
else if (weaponIndex == 1)
pickedFLH = pTypeExt->ProneSecondaryFireFLH;
}
}
if (pickedFLH.isset())
{
FLH = pickedFLH.Get();
FLHFound = true;
}
return FLH;
}
CoordStruct TechnoExt::GetCompleteFLH(TechnoClass* pThis, int weaponIndex)
{
bool found = false;
auto FLH = TechnoExt::GetBurstFLH(pThis, weaponIndex, found);
if (!found)
{
if (auto const pInf = abstract_cast<InfantryClass*>(pThis))
FLH = TechnoExt::GetSimpleFLH(pInf, weaponIndex, found);
if (!found)
FLH = pThis->GetWeapon(weaponIndex)->FLH;
if (pThis->CurrentBurstIndex % 2 != 0)
FLH.Y = -FLH.Y;
}
return FLH;
}
void TechnoExt::ExtData::InitializeDisplayInfo()
{
const auto pThis = this->OwnerObject();
const auto pPrimary = pThis->GetWeapon(0)->WeaponType;
if (pPrimary && pThis->GetTechnoType()->LandTargeting != LandTargetingType::Land_Not_OK)
pThis->RearmTimer.TimeLeft = pPrimary->ROF;
else if (const auto pSecondary = pThis->GetWeapon(1)->WeaponType)
pThis->RearmTimer.TimeLeft = pSecondary->ROF;
pThis->RearmTimer.StartTime = Math::min(-2, -pThis->RearmTimer.TimeLeft);
}
void TechnoExt::ExtData::InitializeAttachEffects()
{
auto const pTypeExt = this->TypeExtData;
if (pTypeExt->AttachEffects.AttachTypes.size() < 1)
return;
auto const pThis = this->OwnerObject();
AttachEffectClass::Attach(pThis, pThis->Owner, pThis, pThis, pTypeExt->AttachEffects);
}
// Gets tint colors for invulnerability, airstrike laser target and berserk, depending on parameters.
int TechnoExt::GetTintColor(TechnoClass* pThis, bool invulnerability, bool airstrike, bool berserk)
{
int tintColor = 0;
if (pThis)
{
if (invulnerability && pThis->IsIronCurtained())
{
tintColor |= pThis->ForceShielded ? RulesExt::Global()->TintColorForceShield : RulesExt::Global()->TintColorIronCurtain;
}
if (airstrike)
{
auto const pExt = TechnoExt::ExtMap.Find(pThis);
if (auto const pAirstrike = pExt->AirstrikeTargetingMe)
{
auto const pTypeExt = TechnoTypeExt::ExtMap.Find(pAirstrike->Owner->GetTechnoType());
tintColor |= pTypeExt->TintColorAirstrike;
}
}
if (berserk && pThis->Berzerk)
{
tintColor |= RulesExt::Global()->TintColorBerserk;
}
}
return tintColor;
}
// Gets custom tint color from TechnoTypes & Warheads.
int TechnoExt::GetCustomTintColor(TechnoClass* pThis)
{
int dummy = 0;
int color = 0;
TechnoExt::ApplyCustomTintValues(pThis, color, dummy);
return color;
}
// Gets custom tint intensity from TechnoTypes & Warheads.
int TechnoExt::GetCustomTintIntensity(TechnoClass* pThis)
{
int dummy = 0;
int intensity = 0;
TechnoExt::ApplyCustomTintValues(pThis, dummy, intensity);
return intensity;
}
// Applies custom tint color and intensity from TechnoTypes and any AttachEffects and shields it might have on provided values.
void TechnoExt::ApplyCustomTintValues(TechnoClass* pThis, int& color, int& intensity)
{
auto const pExt = TechnoExt::ExtMap.Find(pThis);
auto const pOwner = pThis->Owner;
if (pOwner == HouseClass::CurrentPlayer)
{
color |= pExt->TintColorOwner;
intensity += pExt->TintIntensityOwner;
}
else if (pOwner->IsAlliedWith(HouseClass::CurrentPlayer))
{
color |= pExt->TintColorAllies;
intensity += pExt->TintIntensityAllies;
}
else
{
color |= pExt->TintColorEnemies;
intensity += pExt->TintIntensityEnemies;
}
}
// This is still not even correct, but let's see how far this can help us
void TechnoExt::ChangeOwnerMissionFix(FootClass* pThis)
{
pThis->ShouldScanForTarget = false;
pThis->ShouldEnterAbsorber = false;
pThis->ShouldEnterOccupiable = false;
pThis->ShouldGarrisonStructure = false;
auto const pType = pThis->GetTechnoType();
if (pThis->HasAnyLink() || pType->ResourceGatherer) // Don't want miners to stop
return;
switch (pThis->GetCurrentMission())
{
case Mission::Harvest:
case Mission::Sleep:
case Mission::Harmless:
case Mission::Repair:
return;
}
pThis->Override_Mission(Mission::Guard, nullptr, nullptr); // I don't even know what this is
pThis->ShouldLoseTargetNow = TRUE;
pThis->QueueMission(pType->DefaultToGuardArea ? Mission::Area_Guard : Mission::Guard, true);
}
// Updates layers of all animations attached to the given techno.
void TechnoExt::UpdateAttachedAnimLayers(TechnoClass* pThis)
{
// Skip if has no attached animations.
if (!pThis->HasParachute)
return;
// Could possibly be faster to track the attached anims in TechnoExt but the profiler doesn't show this as a performance hog so whatever.
for (auto const pAnim : AnimClass::Array)
{
if (pAnim->OwnerObject != pThis)
continue;
DisplayClass::Instance.Submit(pAnim);
}
}