From a92ff34b26bd800cc4f3742478804bad8b4e1cda Mon Sep 17 00:00:00 2001 From: INeedAUniqueUsername Date: Sat, 17 Feb 2018 15:01:58 -0800 Subject: [PATCH 1/6] maxFuelBonusPerCharge --- Include/TSEDeviceClassesImpl.h | 2 ++ Include/TSEShipSystems.h | 2 ++ TSE/CReactorClass.cpp | 25 +++++++++++++++++++++++++ 3 files changed, 29 insertions(+) diff --git a/Include/TSEDeviceClassesImpl.h b/Include/TSEDeviceClassesImpl.h index 54c5e3c..9864af1 100644 --- a/Include/TSEDeviceClassesImpl.h +++ b/Include/TSEDeviceClassesImpl.h @@ -298,6 +298,7 @@ class CReactorClass : public CDeviceClass const CReactorDesc *GetReactorDesc (CItemCtx &Ctx, DWORD dwFlags = 0) const; int GetMaxPower (CItemCtx &ItemCtx, const CReactorDesc &Desc) const; + int GetMaxFuel (CItemCtx &ItemCtx, const CReactorDesc &Desc) const; void InitDamagedDesc (void) const; void InitEnhancedDesc (void) const; @@ -310,6 +311,7 @@ class CReactorClass : public CDeviceClass // Other properties int m_iExtraPowerPerCharge; // Adds to max power + int m_iExtraFuelPerCharge; // Adds to max fuel // Damaged/enhanced // We allocate these as needed; the array matches m_pDesc diff --git a/Include/TSEShipSystems.h b/Include/TSEShipSystems.h index dcd49e7..5c63767 100644 --- a/Include/TSEShipSystems.h +++ b/Include/TSEShipSystems.h @@ -601,10 +601,12 @@ class CReactorDesc CString GetFuelCriteriaString (void) const; void GetFuelLevel (int *retiMin, int *retiMax) const; inline int GetMaxPower (void) const { return m_iMaxPower; } + inline Metric GetMaxFuel (void) const { return m_rMaxFuel; } ALERROR InitFromXML (SDesignLoadCtx &Ctx, CXMLElement *pDesc, DWORD dwUNID, bool bShipClass = false); ALERROR InitScaled (SDesignLoadCtx &Ctx, const CReactorDesc &Src, int iBaseLevel, int iScaledLevel); bool IsFuelCompatible (const CItem &FuelItem) const; inline void SetMaxPower (int iPower) { m_iMaxPower = iPower; } + inline void SetMaxFuel (Metric rMaxFuel) { m_rMaxFuel = rMaxFuel; } inline bool UsesFuel (void) const { return (m_fNoFuel ? false : true); } static const SStdStats &GetStdStats (int iLevel); diff --git a/TSE/CReactorClass.cpp b/TSE/CReactorClass.cpp index b26a668..d699bba 100644 --- a/TSE/CReactorClass.cpp +++ b/TSE/CReactorClass.cpp @@ -5,6 +5,7 @@ #include "PreComp.h" #define MAX_POWER_BONUS_PER_CHARGE_ATTRIB CONSTLIT("maxPowerBonusPerCharge") +#define MAX_FUEL_BONUS_PER_CHARGE_ATTRIB CONSTLIT("maxFuelBonusPerCharge") #define PROPERTY_MAX_POWER CONSTLIT("maxPower") #define PROPERTY_POWER CONSTLIT("power") @@ -74,6 +75,7 @@ ALERROR CReactorClass::CreateFromXML (SDesignLoadCtx &Ctx, CXMLElement *pDesc, C // Some properties are not scaled (OK if negative). pDevice->m_iExtraPowerPerCharge = pDesc->GetAttributeInteger(MAX_POWER_BONUS_PER_CHARGE_ATTRIB); + pDevice->m_iExtraFuelPerCharge = pDesc->GetAttributeInteger(MAX_FUEL_BONUS_PER_CHARGE_ATTRIB); // Done @@ -146,6 +148,25 @@ int CReactorClass::GetPowerOutput (CItemCtx &Ctx, DWORD dwFlags) const return GetMaxPower(Ctx, *pDesc); } +int CReactorClass::GetMaxFuel (CItemCtx &ItemCtx, const CReactorDesc &Desc) const + +// GetMaxFuel +// +// Returns max fuel + + { + Metric rMaxFuel = Desc.GetMaxFuel(); + + // Adjust for charges + + if (m_iExtraFuelPerCharge > 0) + rMaxFuel += m_iExtraFuelPerCharge * ItemCtx.GetItemCharges(); + + // Done + + return Max(0.0, rMaxFuel); + } + int CReactorClass::GetMaxPower (CItemCtx &ItemCtx, const CReactorDesc &Desc) const // GetMaxPower @@ -315,6 +336,10 @@ bool CReactorClass::OnAccumulatePerformance (CItemCtx &ItemCtx, SShipPerformance Ctx.ReactorDesc.SetMaxPower(GetMaxPower(ItemCtx, *pDesc)); + // Also increase max fuel based on charges + + Ctx.ReactorDesc.SetMaxFuel(GetMaxFuel(ItemCtx, *pDesc)); + // Done return true; From b80412c2563fbbd9b819dd33bbcc48143e3634be Mon Sep 17 00:00:00 2001 From: INeedAUniqueUsername Date: Sat, 17 Feb 2018 15:39:10 -0800 Subject: [PATCH 2/6] accelerationInc attribute for weapons Accelerates projectiles by a fixed increment rather than by a percentage --- Include/TSEDeviceClassesImpl.h | 2 +- Include/TSEWeaponFireDesc.h | 1 + TSE/CWeaponFireDesc.cpp | 32 +++++++++++++++++++++++++++++--- 3 files changed, 31 insertions(+), 4 deletions(-) diff --git a/Include/TSEDeviceClassesImpl.h b/Include/TSEDeviceClassesImpl.h index 9864af1..52e7fe8 100644 --- a/Include/TSEDeviceClassesImpl.h +++ b/Include/TSEDeviceClassesImpl.h @@ -298,7 +298,7 @@ class CReactorClass : public CDeviceClass const CReactorDesc *GetReactorDesc (CItemCtx &Ctx, DWORD dwFlags = 0) const; int GetMaxPower (CItemCtx &ItemCtx, const CReactorDesc &Desc) const; - int GetMaxFuel (CItemCtx &ItemCtx, const CReactorDesc &Desc) const; + Metric GetMaxFuel (CItemCtx &ItemCtx, const CReactorDesc &Desc) const; void InitDamagedDesc (void) const; void InitEnhancedDesc (void) const; diff --git a/Include/TSEWeaponFireDesc.h b/Include/TSEWeaponFireDesc.h index 7888b60..f2d6d8a 100644 --- a/Include/TSEWeaponFireDesc.h +++ b/Include/TSEWeaponFireDesc.h @@ -541,6 +541,7 @@ class CWeaponFireDesc // Missile stuff (m_iFireType == ftMissile) int m_iAccelerationFactor; // % increase in speed per 10 ticks + int m_iAccelerationInc; // Numerical increase in speed per 10 ticks Metric m_rMaxMissileSpeed; // Max speed. int m_iStealth; // Missile stealth int m_iHitPoints; // HP before dissipating (0 = destroyed by any hit) diff --git a/TSE/CWeaponFireDesc.cpp b/TSE/CWeaponFireDesc.cpp index 67e60a7..3b5c72d 100644 --- a/TSE/CWeaponFireDesc.cpp +++ b/TSE/CWeaponFireDesc.cpp @@ -17,6 +17,7 @@ #define PARTICLE_SYSTEM_TAG CONSTLIT("ParticleSystem") #define ACCELERATION_FACTOR_ATTRIB CONSTLIT("accelerationFactor") +#define ACCELERATION_INC_ATTRIB CONSTLIT("accelerationInc") #define AMMO_ID_ATTRIB CONSTLIT("ammoID") #define AREA_DAMAGE_DENSITY_ATTRIB CONSTLIT("areaDamageDensity") #define AUTO_TARGET_ATTRIB CONSTLIT("autoAcquireTarget") @@ -187,9 +188,31 @@ void CWeaponFireDesc::ApplyAcceleration (CSpaceObject *pMissile) const { if (m_iAccelerationFactor > 0) { - if (m_iAccelerationFactor < 100 - || pMissile->GetVel().Length() < m_rMaxMissileSpeed) - pMissile->SetVel(pMissile->GetVel() * (Metric)(m_iAccelerationFactor / 100.0)); + pMissile->SetVel(pMissile->GetVel() * (Metric)(m_iAccelerationFactor / 100.0)); + + // Truncate to maxMissileSpeed if necessary + if (pMissile->GetVel().Length() > m_rMaxMissileSpeed) + pMissile->SetVel(pMissile->GetVel().Normal() * m_rMaxMissileSpeed); + } + if (m_iAccelerationInc > 0) + { + pMissile->SetVel(pMissile->GetVel() + (pMissile->GetVel().Normal() * m_iAccelerationInc)); + + // Truncate to maxMissileSpeed if necessary + if (pMissile->GetVel().Length() > m_rMaxMissileSpeed) + pMissile->SetVel(pMissile->GetVel().Normal() * m_rMaxMissileSpeed); + } + else if (m_iAccelerationInc < 0) + { + // Truncate to 0 to avoid negative velocity + if (pMissile->GetVel().Length() < Absolute(m_iAccelerationInc)) + { + pMissile->SetVel(pMissile->GetVel() * 0); + } + else + { + pMissile->SetVel(pMissile->GetVel() + (pMissile->GetVel().Normal() * m_iAccelerationInc)); + } } } @@ -1570,6 +1593,7 @@ void CWeaponFireDesc::InitFromDamage (const DamageDesc &Damage) m_iManeuverability = 0; m_iManeuverRate = -1; m_iAccelerationFactor = 0; + m_iAccelerationInc = 0; m_rMaxMissileSpeed = m_rMissileSpeed; // Hit points and interaction @@ -1814,6 +1838,7 @@ ALERROR CWeaponFireDesc::InitFromXML (SDesignLoadCtx &Ctx, CXMLElement *pDesc, c m_pEffect->SetVariants(g_RotationRange); m_iAccelerationFactor = pDesc->GetAttributeInteger(ACCELERATION_FACTOR_ATTRIB); + m_iAccelerationInc = pDesc->GetAttributeInteger(ACCELERATION_INC_ATTRIB); int iMaxSpeed = pDesc->GetAttributeInteger(MAX_MISSILE_SPEED_ATTRIB); if (iMaxSpeed == 0) m_rMaxMissileSpeed = m_rMissileSpeed; @@ -2248,6 +2273,7 @@ ALERROR CWeaponFireDesc::InitScaledStats (SDesignLoadCtx &Ctx, CXMLElement *pDes m_iPassthrough = Src.m_iPassthrough; m_iAccelerationFactor = Src.m_iAccelerationFactor; + m_iAccelerationInc = Src.m_iAccelerationInc; m_rMaxMissileSpeed = Src.m_rMaxMissileSpeed; m_iStealth = Src.m_iStealth; m_iHitPoints = Src.m_iHitPoints; From 51a81b2c60244a18e74acb9a87460a7d1182de36 Mon Sep 17 00:00:00 2001 From: INeedAUniqueUsername Date: Tue, 20 Feb 2018 12:01:42 -0800 Subject: [PATCH 3/6] Rename weapon "Temperature" to "Counter" internally --- Include/TSEDevices.h | 8 ++++---- TSE/CInstalledDevice.cpp | 8 ++++---- TSE/CWeaponClass.cpp | 32 ++++++++++++++++---------------- 3 files changed, 24 insertions(+), 24 deletions(-) diff --git a/Include/TSEDevices.h b/Include/TSEDevices.h index 26ad7ad..089256b 100644 --- a/Include/TSEDevices.h +++ b/Include/TSEDevices.h @@ -454,10 +454,10 @@ class CInstalledDevice inline int GetRotation (void) const { return AngleMiddle(m_iMinFireArc, m_iMaxFireArc); } inline int GetSlotBonus (void) const { return m_iSlotBonus; } inline int GetSlotPosIndex (void) const { return m_iSlotPosIndex; } - inline int GetTemperature (void) const { return m_iTemperature; } + inline int GetCounter (void) const { return m_iCounter; } inline int GetTimeUntilReady (void) const { return m_iTimeUntilReady; } inline bool Has3DPos (void) const { return m_f3DPosition; } - inline void IncTemperature (int iChange) { m_iTemperature += iChange; } + inline void IncCounter (int iChange) { m_iCounter += iChange; } inline bool IsDirectional (void) const { return (m_iMinFireArc != m_iMaxFireArc); } inline bool IsDuplicate (void) const { return (m_fDuplicate ? true : false); } inline bool IsEmpty (void) const { return m_pClass == NULL; } @@ -494,7 +494,7 @@ class CInstalledDevice inline void SetSecondary (bool bSecondary = true) { m_fSecondaryWeapon = bSecondary; } inline void SetSlotBonus (int iBonus) { m_iSlotBonus = iBonus; } inline void SetSlotPosIndex (int iIndex) { m_iSlotPosIndex = iIndex; } - inline void SetTemperature (int iTemperature) { m_iTemperature = iTemperature; } + inline void SetTemperature (int iTemperature) { m_iCounter = iTemperature; } inline void SetTimeUntilReady (int iDelay) { m_iTimeUntilReady = iDelay; } inline void SetTriggered (bool bTriggered) { m_fTriggered = bTriggered; } inline void SetWaiting (bool bWaiting) { m_fWaiting = bWaiting; } @@ -600,7 +600,7 @@ class CInstalledDevice int m_iTimeUntilReady:16; // Timer counting down until ready to activate int m_iFireAngle:16; // Last fire angle - int m_iTemperature:16; // Temperature for weapons + int m_iCounter:16; // Temperature/Capacitor for weapons int m_iActivateDelay:16; // Cached activation delay int m_iSlotBonus:16; // Bonus from device slot itself int m_iSlotPosIndex:16; // Slot placement diff --git a/TSE/CInstalledDevice.cpp b/TSE/CInstalledDevice.cpp index 33713d1..f762c9f 100644 --- a/TSE/CInstalledDevice.cpp +++ b/TSE/CInstalledDevice.cpp @@ -23,7 +23,7 @@ CInstalledDevice::CInstalledDevice (void) : m_iTimeUntilReady(0), m_iFireAngle(0), - m_iTemperature(0), + m_iCounter(0), m_iActivateDelay(0), m_iSlotBonus(0), m_iSlotPosIndex(-1), @@ -312,7 +312,7 @@ void CInstalledDevice::Install (CSpaceObject *pObj, CItemListManipulator &ItemLi m_iSlotPosIndex = -1; m_pOverlay = NULL; m_dwData = 0; - m_iTemperature = 0; + m_iCounter = 0; m_fWaiting = false; m_fEnabled = true; m_fTriggered = false; @@ -583,7 +583,7 @@ void CInstalledDevice::ReadFromStream (CSpaceObject *pSource, SLoadCtx &Ctx) m_iFireAngle = (int)HIWORD(dwLoad); Ctx.pStream->Read((char *)&dwLoad, sizeof(DWORD)); - m_iTemperature = (int)HIWORD(dwLoad); + m_iCounter = (int)HIWORD(dwLoad); if (Ctx.dwVersion < 92) { @@ -970,7 +970,7 @@ void CInstalledDevice::WriteToStream (IWriteStream *pStream) dwSave = MAKELONG(m_iTimeUntilReady, m_iFireAngle); pStream->Write((char *)&dwSave, sizeof(DWORD)); - dwSave = MAKELONG(m_iSlotPosIndex, m_iTemperature); + dwSave = MAKELONG(m_iSlotPosIndex, m_iCounter); pStream->Write((char *)&dwSave, sizeof(DWORD)); dwSave = MAKELONG(m_iSlotBonus, m_iDeviceSlot); diff --git a/TSE/CWeaponClass.cpp b/TSE/CWeaponClass.cpp index dd8a035..cc1cd6c 100644 --- a/TSE/CWeaponClass.cpp +++ b/TSE/CWeaponClass.cpp @@ -1434,12 +1434,12 @@ bool CWeaponClass::ConsumeCapacitor (CItemCtx &ItemCtx, CWeaponFireDesc *pShot) // If we don't have enough capacitor power, then we can't fire - if (pDevice->GetTemperature() < m_iCounterActivate) + if (pDevice->GetCounter() < m_iCounterActivate) return false; // Consume capacitor - pDevice->IncTemperature(m_iCounterActivate); + pDevice->IncCounter(m_iCounterActivate); pSource->OnComponentChanged(comDeviceCounter); return true; @@ -2573,7 +2573,7 @@ int CWeaponClass::GetCounter (CInstalledDevice *pDevice, CSpaceObject *pSource, // If we're a capacitor, then don't show the counter if we are full - if (m_Counter == cntCapacitor && pDevice->GetTemperature() >= MAX_COUNTER) + if (m_Counter == cntCapacitor && pDevice->GetCounter() >= MAX_COUNTER) { if (retiLevel) *retiLevel = MAX_COUNTER; @@ -2584,9 +2584,9 @@ int CWeaponClass::GetCounter (CInstalledDevice *pDevice, CSpaceObject *pSource, // Otherwise, return the current value if (retiLevel) - *retiLevel = pDevice->GetTemperature(); + *retiLevel = pDevice->GetCounter(); - return pDevice->GetTemperature(); + return pDevice->GetCounter(); } int CWeaponClass::GetAlternatingPos (CInstalledDevice *pDevice) const @@ -3238,10 +3238,10 @@ int CWeaponClass::GetWeaponEffectiveness (CSpaceObject *pSource, CInstalledDevic // If we're overheating, we will not be effective case cntTemperature: - if (pDevice->IsWaiting() && pDevice->GetTemperature() > 0) + if (pDevice->IsWaiting() && pDevice->GetCounter() > 0) return -100; - if (pDevice->GetTemperature() + m_iCounterActivate >= MAX_COUNTER) + if (pDevice->GetCounter() + m_iCounterActivate >= MAX_COUNTER) { pDevice->SetWaiting(true); return -100; @@ -3253,10 +3253,10 @@ int CWeaponClass::GetWeaponEffectiveness (CSpaceObject *pSource, CInstalledDevic // If our capacitor is discharged, we will not be effective case cntCapacitor: - if (pDevice->IsWaiting() && pDevice->GetTemperature() < MAX_COUNTER) + if (pDevice->IsWaiting() && pDevice->GetCounter() < MAX_COUNTER) return -100; - if (pDevice->GetTemperature() < m_iCounterActivate) + if (pDevice->GetCounter() < m_iCounterActivate) { pDevice->SetWaiting(true); return -100; @@ -4387,17 +4387,17 @@ void CWeaponClass::Update (CInstalledDevice *pDevice, CSpaceObject *pSource, SDe { if (m_iCounterUpdate > 0) { - if (pDevice->GetTemperature() < MAX_COUNTER) + if (pDevice->GetCounter() < MAX_COUNTER) { - pDevice->IncTemperature(Min(m_iCounterUpdate, MAX_COUNTER - pDevice->GetTemperature())); + pDevice->IncCounter(Min(m_iCounterUpdate, MAX_COUNTER - pDevice->GetCounter())); pSource->OnComponentChanged(comDeviceCounter); } } else { - if (pDevice->GetTemperature() > 0) + if (pDevice->GetCounter() > 0) { - pDevice->IncTemperature(Max(m_iCounterUpdate, -pDevice->GetTemperature())); + pDevice->IncCounter(Max(m_iCounterUpdate, -pDevice->GetCounter())); pSource->OnComponentChanged(comDeviceCounter); } } @@ -4471,12 +4471,12 @@ bool CWeaponClass::UpdateTemperature (CItemCtx &ItemCtx, CWeaponFireDesc *pShot, // If we're overheating, then something happens CFailureDesc::EFailureTypes iFailure = CFailureDesc::failNone; - if (pDevice->GetTemperature() >= OVERHEAT_TEMP) + if (pDevice->GetCounter() >= OVERHEAT_TEMP) { // If we're already past our max temperature, then the weapon does // nothing. - if (pDevice->GetTemperature() >= MAX_TEMP) + if (pDevice->GetCounter() >= MAX_TEMP) { pSource->OnDeviceStatus(pDevice, failWeaponJammed); return false; @@ -4511,7 +4511,7 @@ bool CWeaponClass::UpdateTemperature (CItemCtx &ItemCtx, CWeaponFireDesc *pShot, // Update temperature - pDevice->IncTemperature(m_iCounterActivate); + pDevice->IncCounter(m_iCounterActivate); pSource->OnComponentChanged(comDeviceCounter); // Done From 0e07cd6274c35b2f8fe668d76014bd0296b8691f Mon Sep 17 00:00:00 2001 From: INeedAUniqueUsername Date: Tue, 20 Feb 2018 12:05:27 -0800 Subject: [PATCH 4/6] Fix GetMaxFuel for maxFuelBonusPerCharge --- TSE/CReactorClass.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/TSE/CReactorClass.cpp b/TSE/CReactorClass.cpp index d699bba..4c274cc 100644 --- a/TSE/CReactorClass.cpp +++ b/TSE/CReactorClass.cpp @@ -148,7 +148,7 @@ int CReactorClass::GetPowerOutput (CItemCtx &Ctx, DWORD dwFlags) const return GetMaxPower(Ctx, *pDesc); } -int CReactorClass::GetMaxFuel (CItemCtx &ItemCtx, const CReactorDesc &Desc) const +Metric CReactorClass::GetMaxFuel (CItemCtx &ItemCtx, const CReactorDesc &Desc) const // GetMaxFuel // From 4c8b3550e76a7b6fc9eb58c42021f2beafa446c2 Mon Sep 17 00:00:00 2001 From: INeedAUniqueUsername Date: Sun, 8 Oct 2017 18:59:37 -0700 Subject: [PATCH 5/6] Add counterPowerUse attribute for Weapons --- Include/TSEDeviceClassesImpl.h | 1 + TSE/CWeaponClass.cpp | 9 +++++++++ 2 files changed, 10 insertions(+) diff --git a/Include/TSEDeviceClassesImpl.h b/Include/TSEDeviceClassesImpl.h index 52e7fe8..bd6581a 100644 --- a/Include/TSEDeviceClassesImpl.h +++ b/Include/TSEDeviceClassesImpl.h @@ -818,6 +818,7 @@ class CWeaponClass : public CDeviceClass int m_iCounterUpdateRate; // Ticks to update counter int m_iCounterUpdate; // Inc/dec value per update int m_iCounterActivate; // Inc/dec value per shot + int m_iCounterPowerUse; // Power use when counter is updating bool m_bTargetStationsOnly; // Do not target ships diff --git a/TSE/CWeaponClass.cpp b/TSE/CWeaponClass.cpp index cc1cd6c..28f7ea0 100644 --- a/TSE/CWeaponClass.cpp +++ b/TSE/CWeaponClass.cpp @@ -19,6 +19,7 @@ #define COOLING_RATE_ATTRIB CONSTLIT("coolingRate") #define COUNTER_ATTRIB CONSTLIT("counter") #define COUNTER_ACTIVATE_ATTRIB CONSTLIT("counterActivate") +#define COUNTER_POWER_USE_ATTRIB CONSTLIT("counterPowerUse") #define COUNTER_UPDATE_ATTRIB CONSTLIT("counterUpdate") #define COUNTER_UPDATE_RATE_ATTRIB CONSTLIT("counterUpdateRate") #define FAILURE_CHANCE_ATTRIB CONSTLIT("failureChance") @@ -1183,6 +1184,11 @@ int CWeaponClass::CalcPowerUsed (SUpdateCtx &UpdateCtx, CInstalledDevice *pDevic if (pDevice->IsReady() && (!pDevice->IsTriggered() || !pDevice->IsLastActivateSuccessful())) iPower = m_iIdlePowerUse; + // We consume additional power if our counter needs to update + + if(IsCounterEnabled() && GetCounter(pDevice, pSource)) + iPower += m_iCounterPowerUse; + // Adjust based on power efficiency enhancement const CItemEnhancementStack *pEnhancements = Ctx.GetEnhancementStack(); @@ -1543,6 +1549,7 @@ ALERROR CWeaponClass::CreateFromXML (SDesignLoadCtx &Ctx, CXMLElement *pDesc, CI pWeapon->m_iCounterUpdateRate = pDesc->GetAttributeInteger(COUNTER_UPDATE_RATE_ATTRIB); if (pWeapon->m_iCounterUpdateRate <= 0) pWeapon->m_iCounterUpdateRate = 1; + pWeapon->m_iCounterPowerUse = pDesc->GetAttributeInteger(COUNTER_POWER_USE_ATTRIB); } else if ((pWeapon->m_iCounterActivate = pDesc->GetAttributeInteger(HEATING_ATTRIB)) > 0) { @@ -1553,6 +1560,7 @@ ALERROR CWeaponClass::CreateFromXML (SDesignLoadCtx &Ctx, CXMLElement *pDesc, CI pWeapon->m_iCounterUpdateRate = pDesc->GetAttributeInteger(COOLING_RATE_ATTRIB); if (pWeapon->m_iCounterUpdateRate <= 0) pWeapon->m_iCounterUpdateRate = 1; + pWeapon->m_iCounterPowerUse = 0; } else { @@ -1560,6 +1568,7 @@ ALERROR CWeaponClass::CreateFromXML (SDesignLoadCtx &Ctx, CXMLElement *pDesc, CI pWeapon->m_iCounterActivate = 0; pWeapon->m_iCounterUpdate = 0; pWeapon->m_iCounterUpdateRate = 0; + pWeapon->m_iCounterPowerUse = 0; } // Linked fire options From 36580db5e7eba691654b1508ca174ea65ea6d331 Mon Sep 17 00:00:00 2001 From: INeedAUniqueUsername Date: Tue, 20 Feb 2018 12:29:08 -0800 Subject: [PATCH 6/6] Add OnCounterCooldown event for weapons Fires when counter reaches 0 for temperature Fires when counter reaches MAX_COUNTER for capacitor --- Include/TSEDeviceClassesImpl.h | 4 +++- TSE/CWeaponClass.cpp | 41 ++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/Include/TSEDeviceClassesImpl.h b/Include/TSEDeviceClassesImpl.h index bd6581a..e5e9c81 100644 --- a/Include/TSEDeviceClassesImpl.h +++ b/Include/TSEDeviceClassesImpl.h @@ -531,8 +531,9 @@ class CWeaponClass : public CDeviceClass enum ECachedHandlers { evtOnFireWeapon = 0, + evtOnCounterCooldown = 1, - evtCount = 1, + evtCount = 2, }; struct SBalance @@ -754,6 +755,7 @@ class CWeaponClass : public CDeviceClass bool ConsumeAmmo (CItemCtx &ItemCtx, CWeaponFireDesc *pShot, int iRepeatingCount, bool *retbConsumed); bool ConsumeCapacitor (CItemCtx &ItemCtx, CWeaponFireDesc *pShot); void FailureExplosion (CItemCtx &ItemCtx, CWeaponFireDesc *pShot, bool *retbSourceDestroyed); + void FireOnCounterCooldown (CItemCtx &ItemCtx); EOnFireWeaponResults FireOnFireWeapon (CItemCtx &ItemCtx, CWeaponFireDesc *pShot, const CVector &vSource, diff --git a/TSE/CWeaponClass.cpp b/TSE/CWeaponClass.cpp index 28f7ea0..bab02a2 100644 --- a/TSE/CWeaponClass.cpp +++ b/TSE/CWeaponClass.cpp @@ -51,6 +51,7 @@ #define COUNTER_TYPE_CAPACITOR CONSTLIT("capacitor") #define ON_FIRE_WEAPON_EVENT CONSTLIT("OnFireWeapon") +#define ON_COUNTER_COOLDOWN_EVENT CONSTLIT("OnCounterCooldown") #define FIELD_AMMO_TYPE CONSTLIT("ammoType") #define FIELD_AVERAGE_DAMAGE CONSTLIT("averageDamage") // Average damage (1000x hp) @@ -207,6 +208,7 @@ static CWeaponClass::SStdStats STD_WEAPON_STATS[MAX_ITEM_LEVEL] = static char *CACHED_EVENTS[CWeaponClass::evtCount] = { "OnFireWeapon", + "OnCounterCooldown", }; CFailureDesc CWeaponClass::g_DefaultFailure(CFailureDesc::profileWeaponFailure); @@ -1790,6 +1792,33 @@ bool CWeaponClass::FindDataField (const CString &sField, CString *retsValue) return FindAmmoDataField(Ammo, sRootField, retsValue); } +void CWeaponClass::FireOnCounterCooldown (CItemCtx &ItemCtx) + +// FireOnCounterCooldown +// +// Fires OnCounterCooldown event +// +// Fire this event when the capacitor counter is full or when the temperature counter is 0 + + { + SEventHandlerDesc Event; + if (FindEventHandlerWeaponClass(evtOnCounterCooldown, &Event)) + { + CCodeChainCtx Ctx; + + Ctx.SaveAndDefineSourceVar(ItemCtx.GetSource()); + Ctx.SaveAndDefineItemVar(ItemCtx); + + ICCItem *pResult = Ctx.Run(Event); + if (pResult->IsError()) + ItemCtx.GetSource()->ReportEventError(ON_COUNTER_COOLDOWN_EVENT, pResult); + + Ctx.Discard(pResult); + + // Done + } + } + CWeaponClass::EOnFireWeaponResults CWeaponClass::FireOnFireWeapon (CItemCtx &ItemCtx, CWeaponFireDesc *pShot, const CVector &vSource, @@ -4396,18 +4425,30 @@ void CWeaponClass::Update (CInstalledDevice *pDevice, CSpaceObject *pSource, SDe { if (m_iCounterUpdate > 0) { + // Counter increases + if (pDevice->GetCounter() < MAX_COUNTER) { pDevice->IncCounter(Min(m_iCounterUpdate, MAX_COUNTER - pDevice->GetCounter())); pSource->OnComponentChanged(comDeviceCounter); + + //Fire OnCounterCooldown if we reach max with capacitor + if (m_Counter == cntCapacitor && pDevice->GetCounter() == MAX_COUNTER) + FireOnCounterCooldown(ItemCtx); } } else { + // Counter decreases + if (pDevice->GetCounter() > 0) { pDevice->IncCounter(Max(m_iCounterUpdate, -pDevice->GetCounter())); pSource->OnComponentChanged(comDeviceCounter); + + //Fire OnCounterCooldown if we reach 0 with temperature + if (m_Counter == cntTemperature && pDevice->GetCounter() == 0) + FireOnCounterCooldown(ItemCtx); } } }