Skip to content

Commit 94eddcc

Browse files
committed
- Added InheritsAngularVel to Gibs and Emissions
- Added InheritsVelWhenDetached and InheritsAngularVelWhenDetached to Attachables - Exposed these to Lua
1 parent bcb2426 commit 94eddcc

File tree

8 files changed

+60
-26
lines changed

8 files changed

+60
-26
lines changed

CHANGELOG.md

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
5252

5353
- Allow lua scripts to use LuaJIT's BitOp module (see https://bitop.luajit.org/api.html)
5454

55-
- New `Emission` INI and Lua (R/W) property `ParticleCount` which sets how many particles the Emission spawns per emission.
55+
- New `Emission` INI and Lua (R/W) property `ParticleCount` which sets how many particles the Emission spawns per emission. Defaults to 1.
56+
57+
- New `Gib` and `Emission` INI and Lua (R/W) property `InheritsAngularVel`, which determines how much of the parent MO's angular velocity they inherit. Defaults to 1 for gibs, 0 for emissions.
58+
59+
- New `Attachable` INI and Lua (R/W) properties `InheritsVelWhenDetached` and `InheritsAngularVelWhenDetached`, which determine how much of these velocities an attachable inherits from its parent when detached. Defaults to 1.
5660

5761
</details>
5862

@@ -85,9 +89,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
8589

8690
- Almost all ctrl+* special inputs functionality (i.e restarting activity, world dumps, showing performance stats) are now mapped to right alt, to not interfere with default crouching inputs. The only exception is ctrl+arrow keys for changing console size.
8791

88-
- Gibs and detached Attachables now inherit the parent's angular velocity, as well as velocity derived from the angular velocity of the parent MO and their offset from the parent's centre. On gibs, this is scaled by `InheritsVel`.
92+
- `Gib`s and detached `Attachable`s now inherit the parent's angular velocity by default.
93+
94+
- `InheritsVel` now accounts for the angular velocity of the parent MO, resulting in offset gibs and emissions being flung further away.
8995

90-
- `Emissions` with `InheritsVel` now also inherit velocity and angular velocity derived from the angular velocity of the parent.
96+
- `InheritsVel` and its ilk have been uncapped, allowing users to set them outside of 0-1.
9197

9298
</details>
9399

Source/Entities/Attachable.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ void Attachable::Clear() {
4747
m_InheritsRotAngle = true;
4848
m_InheritedRotAngleOffset = 0;
4949
m_InheritsFrame = false;
50-
m_InheritsVelWhenDetached = 0.0F;
51-
m_InheritsAngularVelWhenDetached = 0.0F;
50+
m_InheritsVelWhenDetached = 1.0F;
51+
m_InheritsAngularVelWhenDetached = 1.0F;
5252

5353
m_AtomSubgroupID = -1L;
5454
m_CollidesWithTerrainWhileAttached = true;

Source/Entities/Attachable.h

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,11 +271,20 @@ namespace RTE {
271271

272272
/// How much of the root parent's velocity this attachable inherits when detached
273273
/// @return The proportion of the velocity inherited. 0.1 = 10% inheritance.
274-
float InheritsVelocityWhenDetached() { return m_InheritsVelWhenDetached; }
274+
float InheritsVelocityWhenDetached() const { return m_InheritsVelWhenDetached; }
275275

276276
/// How much of the root parent's angular velocity this attachable inherits when detached
277277
/// @return The proportion of the angular velocity inherited. 0.1 = 10% inheritance.
278-
float InheritsAngularVelocityWhenDetached() { return m_InheritsAngularVelWhenDetached; }
278+
float InheritsAngularVelocityWhenDetached() const { return m_InheritsAngularVelWhenDetached; }
279+
280+
/// Sets how much of the root parent's velocity this attachable inherits when detached
281+
/// @param The proportion of the velocity inherited. 0.1 = 10% inheritance.
282+
void SetInheritsVelocityWhenDetached(float newValue) { m_InheritsVelWhenDetached = newValue; }
283+
284+
/// Sets how much of the root parent's angular velocity this attachable inherits when detached
285+
/// @param The proportion of the angular velocity inherited. 0.1 = 10% inheritance.
286+
void SetInheritsAngularVelocityWhenDetached(float newValue) { m_InheritsAngularVelWhenDetached = newValue; }
287+
279288
#pragma endregion
280289

281290
#pragma region Collision Management

Source/Entities/Emission.h

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,21 @@ namespace RTE {
114114
m_StopTimer.Reset();
115115
}
116116

117-
/// How much of the root parent's velocity this emission inherit
117+
/// How much of the root parent's velocity this emission inherits
118118
/// @return The proportion of the velocity inherited. 0.1 = 10% inheritance.
119-
float InheritsVelocity() { return m_InheritsVel; }
119+
float InheritsVelocity() const { return m_InheritsVel; }
120120

121-
/// How much of the root parent's angular velocity this emission inherit
121+
/// How much of the root parent's angular velocity this emission inherits
122122
/// @return The proportion of the angular velocity inherited. 0.1 = 10% inheritance.
123-
float InheritsAngularVelocity() { return m_InheritsAngularVel; }
123+
float InheritsAngularVelocity() const { return m_InheritsAngularVel; }
124+
125+
/// Sets how much of the root parent's velocity this emission inherits
126+
/// @param The proportion of the velocity inherited. 0.1 = 10% inheritance.
127+
void SetInheritsVelocity(float newValue) { m_InheritsVel = newValue; }
128+
129+
/// Sets how much of the root parent's angular velocity this emission inherits
130+
/// @param The proportion of the angular velocity inherited. 0.1 = 10% inheritance.
131+
void SetInheritsAngularVelocity(float newValue) { m_InheritsAngularVel = newValue; }
124132

125133
/// Gets offset of the emission point from Emitter's sprite center, which gets rotated with owner Emitter
126134
/// @return Returns emission offset.

Source/Entities/Gib.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ void Gib::Clear() {
2323
m_MaxVelocity = 0;
2424
m_LifeVariation = 0.1F;
2525
m_InheritsVel = 1.0F;
26+
m_InheritsAngularVel = 1.0F;
2627
m_IgnoresTeamHits = false;
2728
m_SpreadMode = SpreadMode::SpreadRandom;
2829
}
@@ -36,6 +37,7 @@ int Gib::Create(const Gib& reference) {
3637
m_MaxVelocity = reference.m_MaxVelocity;
3738
m_LifeVariation = reference.m_LifeVariation;
3839
m_InheritsVel = reference.m_InheritsVel;
40+
m_InheritsAngularVel = reference.m_InheritsAngularVel;
3941
m_IgnoresTeamHits = reference.m_IgnoresTeamHits;
4042
m_SpreadMode = reference.m_SpreadMode;
4143

@@ -56,6 +58,7 @@ int Gib::ReadProperty(const std::string_view& propName, Reader& reader) {
5658
MatchProperty("MaxVelocity", { reader >> m_MaxVelocity; });
5759
MatchProperty("LifeVariation", { reader >> m_LifeVariation; });
5860
MatchProperty("InheritsVel", { reader >> m_InheritsVel; });
61+
MatchProperty("InheritsAngularVel", { reader >> m_InheritsAngularVel; });
5962
MatchProperty("IgnoresTeamHits", { reader >> m_IgnoresTeamHits; });
6063
MatchProperty("SpreadMode", { m_SpreadMode = static_cast<SpreadMode>(std::stoi(reader.ReadPropValue())); });
6164

@@ -89,6 +92,8 @@ int Gib::Save(Writer& writer) const {
8992
writer << m_LifeVariation;
9093
writer.NewProperty("InheritsVel");
9194
writer << m_InheritsVel;
95+
writer.NewProperty("InheritsAngularVel");
96+
writer << m_InheritsAngularVel;
9297
*/
9398

9499
return 0;

Source/Entities/Gib.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,10 @@ namespace RTE {
8686
/// @return The proportion of inherited velocity as a scalar from 0 to 1.
8787
float InheritsVelocity() const { return m_InheritsVel; }
8888

89+
/// Gets how much of the gibbing parent's angular velocity this Gib's GibParticles should inherit.
90+
/// @return The proportion of inherited velocity as a scalar from 0 to 1.
91+
float InheritsAngularVelocity() const { return m_InheritsAngularVel; }
92+
8993
/// Gets whether this Gib's GibParticles should ignore hits with the team of the gibbing parent.
9094
/// @return Whether this Gib's GibParticles should ignore hits with the team of the gibbing parent.
9195
bool IgnoresTeamHits() const { return m_IgnoresTeamHits; }
@@ -108,6 +112,7 @@ namespace RTE {
108112
float m_MaxVelocity; //!< The maximum velocity a GibParticle object can have when spawned.
109113
float m_LifeVariation; //!< The per-Gib variation in Lifetime, in percentage of the existing Lifetime of the gib.
110114
float m_InheritsVel; //!< How much of the exploding parent's velocity this Gib should inherit.
115+
float m_InheritsAngularVel; //!< How much of the exploding parent's angular velocity this Gib should inherit.
111116
bool m_IgnoresTeamHits; //!< Whether this Gib should ignore hits with the team of the exploding parent or not.
112117
SpreadMode m_SpreadMode; //!< Determines what kind of logic is used when applying velocity to the GibParticle objects.
113118

Source/Entities/MOSRotating.cpp

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -943,12 +943,10 @@ void MOSRotating::CreateGibsWhenGibbing(const Vector& impactImpulse, MovableObje
943943
Vector gibVelocity(radius * scale + minVelocity, 0);
944944
gibVelocity.RadRotate(randAngle + RandomNum(0.0F, spread) + static_cast<float>(i) * goldenAngle);
945945

946-
if (gibSettingsObject.InheritsVelocity() > 0) {
947-
Vector offsetFromRootParent = m_Pos - GetRootParent()->GetPos() + rotatedGibOffset;
948-
Vector rotationalVelocity = (offsetFromRootParent.GetPerpendicular() * GetRootParent()->GetAngularVel() * gibSettingsObject.InheritsVelocity()) / c_PPM;
949-
gibVelocity += rotationalVelocity;
950-
gibParticleClone->SetAngularVel(gibParticleClone->GetAngularVel() + GetRootParent()->GetAngularVel() * gibSettingsObject.InheritsVelocity());
951-
}
946+
Vector offsetFromRootParent = m_Pos - GetRootParent()->GetPos() + rotatedGibOffset;
947+
Vector rotationalVelocity = (offsetFromRootParent.GetPerpendicular() * GetRootParent()->GetAngularVel() * gibSettingsObject.InheritsVelocity()) / c_PPM;
948+
gibVelocity += rotationalVelocity;
949+
gibParticleClone->SetAngularVel(gibParticleClone->GetAngularVel() + GetRootParent()->GetAngularVel() * gibSettingsObject.InheritsAngularVelocity());
952950

953951
if (lifetime != 0) {
954952
gibParticleClone->SetLifetime(std::max(static_cast<int>(static_cast<float>(lifetime) * (1.0F - lifeVariation * ((radius / maxRadius) * 0.75F + RandomNormalNum() * 0.25F))), 1));
@@ -1007,12 +1005,10 @@ void MOSRotating::CreateGibsWhenGibbing(const Vector& impactImpulse, MovableObje
10071005
gibVelocity.RadRotate(gibSpread * RandomNormalNum());
10081006
}
10091007

1010-
if (gibSettingsObject.InheritsVelocity() > 0) {
1011-
Vector offsetFromRootParent = m_Pos - GetRootParent()->GetPos() + rotatedGibOffset;
1012-
Vector rotationalVelocity = (offsetFromRootParent.GetPerpendicular() * GetRootParent()->GetAngularVel() * gibSettingsObject.InheritsVelocity()) / c_PPM;
1013-
gibVelocity += rotationalVelocity;
1014-
gibParticleClone->SetAngularVel(gibParticleClone->GetAngularVel() + GetRootParent()->GetAngularVel() * gibSettingsObject.InheritsVelocity());
1015-
}
1008+
Vector offsetFromRootParent = m_Pos - GetRootParent()->GetPos() + rotatedGibOffset;
1009+
Vector rotationalVelocity = (offsetFromRootParent.GetPerpendicular() * GetRootParent()->GetAngularVel() * gibSettingsObject.InheritsVelocity()) / c_PPM;
1010+
gibVelocity += rotationalVelocity;
1011+
gibParticleClone->SetAngularVel(gibParticleClone->GetAngularVel() + GetRootParent()->GetAngularVel() * gibSettingsObject.InheritsAngularVelocity());
10161012

10171013
gibParticleClone->SetVel(gibVelocity + ((m_PrevVel + m_Vel) / 2) * gibSettingsObject.InheritsVelocity());
10181014

@@ -1478,9 +1474,9 @@ Attachable* MOSRotating::RemoveAttachable(Attachable* attachable, bool addToMova
14781474
}
14791475
RTEAssert(attachable->IsAttachedTo(this), "Tried to remove Attachable " + attachable->GetPresetNameAndUniqueID() + " from presumed parent " + GetPresetNameAndUniqueID() + ", but it had a different parent (" + (attachable->GetParent() ? attachable->GetParent()->GetPresetNameAndUniqueID() : "ERROR") + "). This should never happen!");
14801476

1481-
Vector rotationalVelocity = ((attachable->GetPos() - GetRootParent()->GetPos()).GetPerpendicular() * GetRootParent()->GetAngularVel()) / c_PPM;
1482-
attachable->SetAngularVel(attachable->GetAngularVel() + GetRootParent()->GetAngularVel());
1483-
attachable->SetVel(attachable->GetVel() + rotationalVelocity); // Attachables have already had their velocity updated by ApplyImpulses(), no need to add impactImpulse again
1477+
Vector rotationalVelocity = ((attachable->GetPos() - GetRootParent()->GetPos()).GetPerpendicular() * GetRootParent()->GetAngularVel() * attachable->InheritsVelocityWhenDetached()) / c_PPM;
1478+
attachable->SetAngularVel(attachable->GetAngularVel() + GetRootParent()->GetAngularVel() * attachable->InheritsAngularVelocityWhenDetached());
1479+
attachable->SetVel(attachable->GetVel() * attachable->InheritsVelocityWhenDetached() + rotationalVelocity); // Attachables have already had their velocity updated by ApplyImpulses(), no need to add impactImpulse again
14841480

14851481
if (!m_Attachables.empty()) {
14861482
m_Attachables.remove(attachable);

Source/Lua/LuaBindingsEntities.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -549,6 +549,8 @@ LuaBindingRegisterFunctionDefinitionForType(EntityLuaBindings, Attachable) {
549549
.property("CanCollideWithTerrain", &Attachable::CanCollideWithTerrain)
550550
.property("DrawnAfterParent", &Attachable::IsDrawnAfterParent, &Attachable::SetDrawnAfterParent)
551551
.property("InheritsFrame", &Attachable::InheritsFrame, &Attachable::SetInheritsFrame)
552+
.property("InheritsVelWhenDetached", &Attachable::InheritsVelocityWhenDetached, &Attachable::SetInheritsVelocityWhenDetached)
553+
.property("InheritsAngularVelWhenDetached", &Attachable::InheritsAngularVelocityWhenDetached, &Attachable::SetInheritsAngularVelocityWhenDetached)
552554

553555
.def("IsAttached", &Attachable::IsAttached)
554556
.def("IsAttachedTo", &Attachable::IsAttachedTo)
@@ -581,6 +583,8 @@ LuaBindingRegisterFunctionDefinitionForType(EntityLuaBindings, Emission) {
581583
.property("Spread", &Emission::GetSpread, &Emission::SetSpread)
582584
.property("Offset", &Emission::GetOffset, &Emission::SetOffset)
583585
.property("ParticleCount", &Emission::GetParticleCount, &Emission::SetParticleCount)
586+
.property("InheritsVel", &Emission::InheritsVelocity, &Emission::SetInheritsVelocity)
587+
.property("InheritsAngularVel", &Emission::InheritsAngularVelocity, &Emission::SetInheritsAngularVelocity)
584588

585589
.def("ResetEmissionTimers", &Emission::ResetEmissionTimers);
586590
}
@@ -598,6 +602,7 @@ LuaBindingRegisterFunctionDefinitionForType(EntityLuaBindings, Gib) {
598602
.def_readwrite("Spread", &Gib::m_Spread)
599603
.def_readwrite("LifeVariation", &Gib::m_LifeVariation)
600604
.def_readwrite("InheritsVel", &Gib::m_InheritsVel)
605+
.def_readwrite("InheritsAngularVel", &Gib::m_InheritsAngularVel)
601606
.def_readwrite("IgnoresTeamHits", &Gib::m_IgnoresTeamHits)
602607

603608
.enum_("SpreadMode")[luabind::value("SpreadRandom", Gib::SpreadMode::SpreadRandom),

0 commit comments

Comments
 (0)