Skip to content
This repository was archived by the owner on Jan 5, 2024. It is now read-only.
Merged
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

- Added `MovableObject` Lua function `EnableOrDisableAllScripts` that allows you to enable or disable all scripts on a `MovableObject` based on the passed in value.

- Added `AEmitter` and `PEmitter` Lua (R/W) properties `NegativeThrottleMultiplier` and `PositiveThrottleMultiplier` that affect the emission rate relative to throttle.

- Added `Attachable` Lua function and INI property `InheritsFrame` which lets `Attachables` inherit their parent's frame. It is set to false by default.

- Added `MovableObject` Lua (R/W) and INI properties `ApplyWoundDamageOnCollision` and `ApplyWoundBurstDamageOnCollision` which allow `MovableObject`s to apply the `EntryWound` damage/burst damage that would occur when they penetrate another object, without actually creating a wound.
Expand Down Expand Up @@ -186,6 +188,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),

<details><summary>Changed</summary>

- `AEmitter` and `PEmitter` throttle logic has changed:
The properties `MinThrottleRange` and `MaxThrottleRange` have been changed to `NegativeThrottleMultiplier` and `PositiveThrottleMultiplier` respectively.
The new logic uses the multipliers to multiply the emission rate relative to the absolute throttle value. `NegativeThrottleMultiplier` is used when throttle is negative, and vice versa.

- Doors in `Team = -1` will now open up for all actors.

- `MovableMan` function `KillAllActors` (commonly found in activities) has been appropriately renamed `KillAllEnemyActors`.
Expand Down
2 changes: 0 additions & 2 deletions Entities/ACrab.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2130,8 +2130,6 @@ void ACrab::Update()
// Jetpack throttle depletes relative to jet time, but only if throttle range values have been defined
float jetTimeRatio = std::max(m_JetTimeLeft / m_JetTimeTotal, 0.0F);
m_pJetpack->SetThrottle(jetTimeRatio * 2.0F - 1.0F);
float minScale = 1.0F - m_pJetpack->GetMinThrottle();
m_pJetpack->SetFlashScale(minScale + (1.0F + m_pJetpack->GetMaxThrottle() - minScale) * jetTimeRatio);
}
// Start Jetpack burn
if (m_Controller.IsState(BODY_JUMPSTART) && m_JetTimeLeft > 0 && m_Status != INACTIVE)
Expand Down
46 changes: 25 additions & 21 deletions Entities/AEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ void AEmitter::Clear()
m_WasEmitting = false;
m_EmitCount = 0;
m_EmitCountLimit = 0;
m_MinThrottleRange = 1.0F;
m_MaxThrottleRange = 1.0F;
m_NegativeThrottleMultiplier = 1.0F;
m_PositiveThrottleMultiplier = 1.0F;
m_Throttle = 0;
m_EmissionsIgnoreThis = false;
m_BurstScale = 1.0F;
Expand Down Expand Up @@ -85,8 +85,8 @@ int AEmitter::Create(const AEmitter &reference) {
m_EmitEnabled = reference.m_EmitEnabled;
m_EmitCount = reference.m_EmitCount;
m_EmitCountLimit = reference.m_EmitCountLimit;
m_MinThrottleRange = reference.m_MinThrottleRange;
m_MaxThrottleRange = reference.m_MaxThrottleRange;
m_NegativeThrottleMultiplier = reference.m_NegativeThrottleMultiplier;
m_PositiveThrottleMultiplier = reference.m_PositiveThrottleMultiplier;
m_Throttle = reference.m_Throttle;
m_EmissionsIgnoreThis = reference.m_EmissionsIgnoreThis;
m_BurstScale = reference.m_BurstScale;
Expand Down Expand Up @@ -138,10 +138,10 @@ int AEmitter::ReadProperty(const std::string_view &propName, Reader &reader) {
reader >> ppm;
// Go through all emissions and set the rate so that it emulates the way it used to work, for mod backwards compatibility.
for (Emission *emission : m_EmissionList) { emission->m_PPM = ppm / static_cast<float>(m_EmissionList.size()); }
} else if (propName == "MinThrottleRange") {
reader >> m_MinThrottleRange;
} else if (propName == "MaxThrottleRange") {
reader >> m_MaxThrottleRange;
} else if (propName == "NegativeThrottleMultiplier") {
reader >> m_NegativeThrottleMultiplier;
} else if (propName == "PositiveThrottleMultiplier") {
reader >> m_PositiveThrottleMultiplier;
} else if (propName == "Throttle") {
reader >> m_Throttle;
} else if (propName == "EmissionsIgnoreThis") {
Expand Down Expand Up @@ -212,10 +212,10 @@ int AEmitter::Save(Writer &writer) const
writer << m_EmitCountLimit;
writer.NewProperty("EmissionsIgnoreThis");
writer << m_EmissionsIgnoreThis;
writer.NewProperty("MinThrottleRange");
writer << m_MinThrottleRange;
writer.NewProperty("MaxThrottleRange");
writer << m_MaxThrottleRange;
writer.NewProperty("NegativeThrottleMultiplier");
writer << m_NegativeThrottleMultiplier;
writer.NewProperty("PositiveThrottleMultiplier");
writer << m_PositiveThrottleMultiplier;
writer.NewProperty("Throttle");
writer << m_Throttle;
writer.NewProperty("BurstScale");
Expand Down Expand Up @@ -344,12 +344,13 @@ float AEmitter::EstimateImpulse(bool burst)

}

// Figure out the throttle factor
// Scale the emission rate up or down according to the appropriate throttle multiplier.
float throttleFactor = 1.0F;
if (m_Throttle < 0) { // Negative throttle, scale down according to the min throttle range
throttleFactor += std::abs(m_MinThrottleRange) * m_Throttle;
} else if (m_Throttle > 0) { // Positive throttle, scale up
throttleFactor += std::abs(m_MaxThrottleRange) * m_Throttle;
float absThrottle = std::abs(m_Throttle);
if (m_Throttle < 0) {
throttleFactor = throttleFactor * (1 - absThrottle) + (m_NegativeThrottleMultiplier * absThrottle);
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm pretty sure you've made this line more complicated than it needs to be. throttleFactor is set to 1.0F right above, but you're using it in your math so you effectively have 1.0F * (1 - std::abs(m_Throttle) + (m_WhateverMultiplier * std::abs(m_Throttle))

Also, can you explain the math changes here a bit, cause I'm pretty sure they're wrong.
Before throttle and throttle multipliers both linearly affected the resulting throttle factor (i.e. emission rate) in a totally straightforward way. Bigger throttle and bigger multiplier meant more emission rate, going from 0 (no emissions at min throttle) to 2 (double emissions at max throttle). Yours doesn't abs the multipliers, meaning that their signs matter (though reasonably they should always be 0 - 1 so that's not a big deal, but probably needs enforcement in the setters), and when I plug the numbers into excel your stuff is super weird (unless I've made a mistake):
image

If you wanna do it yourself, the formulas are:
Old - =1 + (A2*ABS(B2))
New - = 1 * (1-ABS(A2)) + (B2*ABS(A2))

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I gave the formulas to Trez in beforehand to be automatically handled by the converter. I guess it's a thing worth putting into the changelog entry even though it'll probably end up confusing modders, especially when this stuff hasn't ever been very apparent in mods.

I thought we discussed the throttle logic change already so I don't really know what you're frothing about.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lol it's 100% possible that we did, but also possible that I've forgotten since it was a while back, or that I didn't fully understand.

Still, this seems straight up incorrect to me, like why would having throttle 0.1 and positive throttle multiplier 0.1 result in 0.9 strength emissions? Feel free to shoot me a discord message if you'd rather discuss there.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After discussion with 4zK, we're keeping this as-is. There's a followup issue to get rid of these confusing code concepts - #374.

} else if (m_Throttle > 0) {
throttleFactor = throttleFactor * (1 - absThrottle) + (m_PositiveThrottleMultiplier * absThrottle);
}
// Apply the throttle factor to the emission rate per update
if (burst) { return m_AvgBurstImpulse * throttleFactor; }
Expand Down Expand Up @@ -432,12 +433,15 @@ void AEmitter::Update()
// TODO: Potentially get this once outside instead, like in attach/detach")
MovableObject *pRootParent = GetRootParent();

// Scale the emission rate up or down according to the appropriate throttle multiplier.
float throttleFactor = 1.0F;
if (m_Throttle < 0) { // Negative throttle, scale down according to the min throttle range
throttleFactor += std::abs(m_MinThrottleRange) * m_Throttle;
} else if (m_Throttle > 0) { // Positive throttle, scale up
throttleFactor += std::abs(m_MaxThrottleRange) * m_Throttle;
float absThrottle = std::abs(m_Throttle);
if (m_Throttle < 0) {
throttleFactor = throttleFactor * (1 - absThrottle) + (m_NegativeThrottleMultiplier * absThrottle);
} else if (m_Throttle > 0) {
throttleFactor = throttleFactor * (1 - absThrottle) + (m_PositiveThrottleMultiplier * absThrottle);
}
m_FlashScale = throttleFactor;
// Check burst triggering against whether the spacing is fulfilled
if (m_BurstTriggered && (m_BurstSpacing <= 0 || m_BurstTimer.IsPastSimMS(m_BurstSpacing)))
{
Expand Down
29 changes: 21 additions & 8 deletions Entities/AEmitter.h
Original file line number Diff line number Diff line change
Expand Up @@ -263,16 +263,29 @@ ClassInfoGetters;
float GetThrottle() const { return m_Throttle; }

/// <summary>
/// Gets the minimum throttle range of this AEmitter.
/// Gets the negative throttle multiplier of this AEmitter.
/// </summary>
/// <returns>The minimum throttle range of this AEmitter.</returns>
float GetMinThrottle() const { return m_MinThrottleRange; }
/// <returns>The negative throttle multiplier of this AEmitter.</returns>
float GetNegativeThrottleMultiplier() const { return m_NegativeThrottleMultiplier; }

/// <summary>
/// Gets the maximum throttle range of this AEmitter.
/// Gets the positive throttle multiplier of this AEmitter.
/// </summary>
/// <returns>The maximum throttle range of this AEmitter.</returns>
float GetMaxThrottle() const { return m_MaxThrottleRange; }
/// <returns>The positive throttle multiplier of this AEmitter.</returns>
float GetPositiveThrottleMultiplier() const { return m_PositiveThrottleMultiplier; }

/// <summary>
/// Sets the negative throttle multiplier of this AEmitter.
/// </summary>
/// <param name="newValue">The new throttle multiplier of this AEmitter.</param>
void SetNegativeThrottleMultiplier(float newValue) { m_NegativeThrottleMultiplier = newValue; }

/// <summary>
/// Sets the positive throttle multiplier of this AEmitter.
/// </summary>
/// <param name="newValue">The new throttle multiplier of this AEmitter.</param>
void SetPositiveThrottleMultiplier(float newValue) { m_PositiveThrottleMultiplier = newValue; }

/*
//////////////////////////////////////////////////////////////////////////////////////////
// Method: SetEmitRate
Expand Down Expand Up @@ -632,8 +645,8 @@ ClassInfoGetters;
long m_EmitCount;
// The max number of emissions to emit per emit being enabled
long m_EmitCountLimit;
float m_MinThrottleRange; //!< The range negative throttle has on emission rate. 1.0 means the rate can be throttled down to 0%, 0 means negative throttle has no effect
float m_MaxThrottleRange; //!< The range positive throttle has on emission rate. 1.0 means the rate can be throttled up to 200%, 0 means positive throttle has no effect
float m_NegativeThrottleMultiplier; //!< The multiplier applied to the emission rate when throttle is negative. Relative to the absolute throttle value.
float m_PositiveThrottleMultiplier; //!< The multiplier applied to the emission rate when throttle is positive. Relative to the absolute throttle value.
float m_Throttle; //!< The normalized throttle which controls the MSPE between 1.0 * m_MSPERange and -1.0 * m_MSPERange. 0 means emit the regular m_PPM amount.
// Whether or not this' emissions ignore hits with itself, even if they are set to hit other MOs.
bool m_EmissionsIgnoreThis;
Expand Down
2 changes: 0 additions & 2 deletions Entities/AHuman.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3130,8 +3130,6 @@ void AHuman::Update()
// Jetpack throttle depletes relative to jet time, but only if throttle range values have been defined
float jetTimeRatio = std::max(m_JetTimeLeft / m_JetTimeTotal, 0.0F);
m_pJetpack->SetThrottle(jetTimeRatio * 2.0F - 1.0F);
float minScale = 1.0F - m_pJetpack->GetMinThrottle();
m_pJetpack->SetFlashScale(minScale + (1.0F + m_pJetpack->GetMaxThrottle() - minScale) * jetTimeRatio);
}
// Start Jetpack burn
if (m_Controller.IsState(BODY_JUMPSTART) && m_JetTimeLeft > 0 && m_Status != INACTIVE)
Expand Down
60 changes: 30 additions & 30 deletions Entities/PEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ namespace RTE {
m_WasEmitting = false;
m_EmitCount = 0;
m_EmitCountLimit = 0;
m_MinThrottleRange = -1;
m_MaxThrottleRange = 1;
m_NegativeThrottleMultiplier = 1.0F;
m_PositiveThrottleMultiplier = 1.0F;
m_Throttle = 0;
m_EmissionsIgnoreThis = false;
m_BurstScale = 1.0;
Expand Down Expand Up @@ -90,8 +90,8 @@ namespace RTE {
m_EmitEnabled = reference.m_EmitEnabled;
m_EmitCount = reference.m_EmitCount;
m_EmitCountLimit = reference.m_EmitCountLimit;
m_MinThrottleRange = reference.m_MinThrottleRange;
m_MaxThrottleRange = reference.m_MaxThrottleRange;
m_NegativeThrottleMultiplier = reference.m_NegativeThrottleMultiplier;
m_PositiveThrottleMultiplier = reference.m_PositiveThrottleMultiplier;
m_Throttle = reference.m_Throttle;
m_EmissionsIgnoreThis = reference.m_EmissionsIgnoreThis;
m_BurstScale = reference.m_BurstScale;
Expand Down Expand Up @@ -143,10 +143,10 @@ namespace RTE {
for (list<Emission>::iterator eItr = m_EmissionList.begin(); eItr != m_EmissionList.end(); ++eItr)
(*eItr).m_PPM = ppm / m_EmissionList.size();
}
else if (propName == "MinThrottleRange")
reader >> m_MinThrottleRange;
else if (propName == "MaxThrottleRange")
reader >> m_MaxThrottleRange;
else if (propName == "NegativeThrottleMultiplier")
reader >> m_NegativeThrottleMultiplier;
else if (propName == "PositiveThrottleMultiplier")
reader >> m_PositiveThrottleMultiplier;
else if (propName == "Throttle")
reader >> m_Throttle;
else if (propName == "EmissionsIgnoreThis")
Expand Down Expand Up @@ -213,10 +213,10 @@ namespace RTE {
writer << m_EmitCountLimit;
writer.NewProperty("EmissionsIgnoreThis");
writer << m_EmissionsIgnoreThis;
writer.NewProperty("MinThrottleRange");
writer << m_MinThrottleRange;
writer.NewProperty("MaxThrottleRange");
writer << m_MaxThrottleRange;
writer.NewProperty("NegativeThrottleMultiplier");
writer << m_NegativeThrottleMultiplier;
writer.NewProperty("PositiveThrottleMultiplier");
writer << m_PositiveThrottleMultiplier;
writer.NewProperty("Throttle");
writer << m_Throttle;
writer.NewProperty("BurstScale");
Expand Down Expand Up @@ -339,13 +339,14 @@ namespace RTE {

}

// Figure out the throttle factor
float throttleFactor = 1.0f;
if (m_Throttle < 0) // Negative throttle, scale down according to the min throttle range
throttleFactor += fabs(m_MinThrottleRange) * m_Throttle;
else if (m_Throttle > 0) // Positive throttle, scale up
throttleFactor += fabs(m_MaxThrottleRange) * m_Throttle;

// Scale the emission rate up or down according to the appropriate throttle multiplier.
float throttleFactor = 1.0F;
float absThrottle = std::abs(m_Throttle);
if (m_Throttle < 0) {
throttleFactor = throttleFactor * (1 - absThrottle) + (m_NegativeThrottleMultiplier * absThrottle);
} else if (m_Throttle > 0) {
throttleFactor = throttleFactor * (1 - absThrottle) + (m_PositiveThrottleMultiplier * absThrottle);
}
// Apply the throttle factor to the emission rate per update
if (burst)
return m_AvgBurstImpulse * throttleFactor;
Expand Down Expand Up @@ -397,15 +398,15 @@ namespace RTE {
// TODO: Potentially get this once outside instead, like in attach/detach")
MovableObject *pRootParent = GetRootParent();

// Figure out the throttle factor
// Negative throttle, scale down according to the min throttle range
float throttleFactor = 1.0f;
if (m_Throttle < 0)
throttleFactor += fabs(m_MinThrottleRange) * m_Throttle;
// Positive throttle, scale up
else if (m_Throttle > 0)
throttleFactor += fabs(m_MaxThrottleRange) * m_Throttle;

// Scale the emission rate up or down according to the appropriate throttle multiplier.
float throttleFactor = 1.0F;
float absThrottle = std::abs(m_Throttle);
if (m_Throttle < 0) {
throttleFactor = throttleFactor * (1 - absThrottle) + (m_NegativeThrottleMultiplier * absThrottle);
} else if (m_Throttle > 0) {
throttleFactor = throttleFactor * (1 - absThrottle) + (m_PositiveThrottleMultiplier * absThrottle);
}
m_FlashScale = throttleFactor;
// Check burst triggering against whether the spacing is fulfilled
if (m_BurstTriggered && (m_BurstSpacing <= 0 || m_BurstTimer.IsPastSimMS(m_BurstSpacing)))
{
Expand Down Expand Up @@ -477,8 +478,7 @@ namespace RTE {
emitVel = RotateOffset(emitVel);
pParticle->SetVel(parentVel + emitVel);

if (pParticle->GetLifetime() != 0)
pParticle->SetLifetime(pParticle->GetLifetime() * (1.0F + ((*eItr).GetLifeVariation() * RandomNormalNum())));
if (pParticle->GetLifetime() != 0) { pParticle->SetLifetime(std::max(static_cast<int>(pParticle->GetLifetime() * (1.0F + ((*eItr).GetLifeVariation() * RandomNormalNum()))), 1)); }
pParticle->SetTeam(m_Team);
pParticle->SetIgnoresTeamHits(true);

Expand Down
6 changes: 2 additions & 4 deletions Entities/PEmitter.h
Original file line number Diff line number Diff line change
Expand Up @@ -506,10 +506,8 @@ class PEmitter :
long m_EmitCount;
// The max number of emissions to emit per emit being enabled
long m_EmitCountLimit;
// The range negative throttle has on emission rate. 1.0 means the rate can be throttled down to 0%, 0 means negative throttle has no effect
double m_MinThrottleRange;
// The range positive throttle has on emission rate. 1.0 means the rate can be throttled up to 200%, 0 means negative throttle has no effect
double m_MaxThrottleRange;
float m_NegativeThrottleMultiplier; //!< The multiplier applied to the emission rate when throttle is negative. Relative to the absolute throttle value.
float m_PositiveThrottleMultiplier; //!< The multiplier applied to the emission rate when throttle is positive. Relative to the absolute throttle value.
// The normalized throttle which controls the MSPE between 1.0 * m_MSPERange and -1.0 * m_MSPERange. 0 means emit the regular m_PPM amount.
float m_Throttle;
// Whether or not this' emissions ignore hits with itself, even if they are set to hit other MOs.
Expand Down
2 changes: 2 additions & 0 deletions Lua/LuaBindingsEntities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,8 @@ namespace RTE {
.property("EmitAngle", &AEmitter::GetEmitAngle, &AEmitter::SetEmitAngle)
.property("GetThrottle", &AEmitter::GetThrottle, &AEmitter::SetThrottle)
.property("Throttle", &AEmitter::GetThrottle, &AEmitter::SetThrottle)
.property("NegativeThrottleMultiplier", &AEmitter::GetNegativeThrottleMultiplier, &AEmitter::SetNegativeThrottleMultiplier)
.property("PositiveThrottleMultiplier", &AEmitter::GetPositiveThrottleMultiplier, &AEmitter::SetPositiveThrottleMultiplier)
.property("BurstSpacing", &AEmitter::GetBurstSpacing, &AEmitter::SetBurstSpacing)
.property("BurstDamage", &AEmitter::GetBurstDamage, &AEmitter::SetBurstDamage)
.property("EmitterDamageMultiplier", &AEmitter::GetEmitterDamageMultiplier, &AEmitter::SetEmitterDamageMultiplier)
Expand Down