Skip to content

Commit a152f09

Browse files
committed
Added LifeVariation for normal MOs
1 parent 68155a7 commit a152f09

File tree

7 files changed

+21
-6
lines changed

7 files changed

+21
-6
lines changed

Source/Entities/Emission.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ void Emission::Clear() {
1515
m_Spread = 0;
1616
m_MinVelocity = 0;
1717
m_MaxVelocity = 0;
18-
m_LifeVariation = 0.1;
18+
m_LifeVariation = 0.1F;
1919
m_PushesEmitter = true;
2020
m_InheritsVel = 0;
2121
m_StartTimer.SetSimTimeLimitMS(0);

Source/Entities/Emission.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ namespace RTE {
151151
float m_MinVelocity;
152152
// The maximum velocity an emitted MO can have when emitted
153153
float m_MaxVelocity;
154-
// The variation in life time of each emitted aprticle, in percentage of the existing life time of the partilcle
154+
// The variation in life time of each emitted particle, in percentage of the existing life time of the particle
155155
float m_LifeVariation;
156156
// Whether these emissions push the emitter around with recoil or not.
157157
bool m_PushesEmitter;

Source/Entities/MovableObject.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ void MovableObject::Clear() {
5151
m_AgeTimer.Reset();
5252
m_RestTimer.Reset();
5353
m_Lifetime = 0;
54+
m_LifeVariation = 0.0F;
5455
m_Sharpness = 1.0;
5556
// m_MaterialId = 0;
5657
m_CheckTerrIntersection = false;
@@ -286,6 +287,7 @@ int MovableObject::ReadProperty(const std::string_view& propName, Reader& reader
286287
MatchProperty("PinStrength", { reader >> m_PinStrength; });
287288
MatchProperty("RestThreshold", { reader >> m_RestThreshold; });
288289
MatchProperty("LifeTime", { reader >> m_Lifetime; });
290+
MatchProperty("LifeVariation", { reader >> m_LifeVariation; });
289291
MatchProperty("Age", {
290292
double age;
291293
reader >> age;
@@ -415,6 +417,8 @@ int MovableObject::Save(Writer& writer) const {
415417
writer << m_RestThreshold;
416418
writer.NewProperty("LifeTime");
417419
writer << m_Lifetime;
420+
writer.NewProperty("LifeVariation");
421+
writer << m_LifeVariation;
418422
writer.NewProperty("Sharpness");
419423
writer << m_Sharpness;
420424
writer.NewProperty("HitsMOs");

Source/Entities/MovableObject.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,14 @@ namespace RTE {
225225
/// @return A unsigned long describing the current lifetime in ms. 0 means unlimited.
226226
unsigned long GetLifetime() const { return m_Lifetime; }
227227

228+
/// Gets the specified variation in lifetime of the emitted particles.
229+
/// @return The life variation rationally expressed.. 0.1 = up to 10% variation.
230+
float GetLifeVariation() const { return m_LifeVariation; }
231+
232+
/// Sets the specified variation in lifetime of the emitted particles.
233+
/// @param newVariation The life variation rationally expressed.. 0.1 = up to 10% variation.
234+
void SetLifeVariation(float newVariation) { m_LifeVariation = newVariation; }
235+
228236
/// Gets the MOID of this MovableObject for this frame.
229237
/// @return An int specifying the MOID that this MovableObject is
230238
/// assigned for the current frame only.
@@ -1127,6 +1135,8 @@ namespace RTE {
11271135
Timer m_RestTimer;
11281136

11291137
unsigned long m_Lifetime;
1138+
// The variation in life time of this MO, in percentage of the initial lifetime
1139+
float m_LifeVariation;
11301140
// The sharpness factor that gets added to single pixel hit impulses in
11311141
// applicable situations.
11321142
float m_Sharpness;

Source/Entities/Round.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ void Round::Clear() {
2020
m_FireVel = 0;
2121
m_InheritsFirerVelocity = false;
2222
m_Separation = 0;
23-
m_LifeVariation = 0;
23+
m_LifeVariation = 0.0F;
2424
m_Shell = 0;
2525
m_ShellVel = 0;
2626
m_FireSound.Reset();

Source/Lua/LuaBindingsEntities.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -893,6 +893,7 @@ LuaBindingRegisterFunctionDefinitionForType(EntityLuaBindings, MovableObject) {
893893
.property("AirThreshold", &MovableObject::GetAirThreshold, &MovableObject::SetAirThreshold)
894894
.property("Age", &MovableObject::GetAge, &MovableObject::SetAge)
895895
.property("Lifetime", &MovableObject::GetLifetime, &MovableObject::SetLifetime)
896+
.property("LifeVariation", &MovableObject::GetLifeVariation, &MovableObject::SetLifeVariation)
896897
.property("ID", &MovableObject::GetID)
897898
.property("UniqueID", &MovableObject::GetUniqueID)
898899
.property("RootID", &MovableObject::GetRootID)

Source/Managers/MovableMan.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -667,7 +667,7 @@ void MovableMan::AddActor(Actor* actorToAdd) {
667667
}
668668
actorToAdd->NotResting();
669669
actorToAdd->NewFrame();
670-
actorToAdd->SetAge(0);
670+
actorToAdd->SetAge(static_cast<int>(actorToAdd->GetLifetime() * actorToAdd->GetLifeVariation() * RandomNormalNum()));
671671
}
672672

673673
{
@@ -695,7 +695,7 @@ void MovableMan::AddItem(HeldDevice* itemToAdd) {
695695
}
696696
itemToAdd->NotResting();
697697
itemToAdd->NewFrame();
698-
itemToAdd->SetAge(0);
698+
itemToAdd->SetAge(static_cast<int>(itemToAdd->GetLifetime() * itemToAdd->GetLifeVariation() * RandomNormalNum()));
699699
}
700700

701701
std::lock_guard<std::mutex> lock(m_AddedItemsMutex);
@@ -718,7 +718,7 @@ void MovableMan::AddParticle(MovableObject* particleToAdd) {
718718
// TODO consider moving particles out of grass. It's old code that was removed because it's slow to do this for every particle.
719719
particleToAdd->NotResting();
720720
particleToAdd->NewFrame();
721-
particleToAdd->SetAge(0);
721+
particleToAdd->SetAge(static_cast<int>(particleToAdd->GetLifetime() * particleToAdd->GetLifeVariation() * RandomNormalNum()));
722722
}
723723
if (particleToAdd->IsDevice()) {
724724
std::lock_guard<std::mutex> lock(m_AddedItemsMutex);

0 commit comments

Comments
 (0)