void CShieldClass::CalcMinMaxHP (CItemCtx &Ctx, int iCharges, int iArmorSegs, int iTotalHP, int *retiMin, int *retiMax) const // CalcMinMaxHP // // Returns the min and max HP of this shield // // iCharges = m_iMaxCharges or the current charges on item // iArmorSegs = count of armor segments on ship (or 0) // iTotalHP = current total HP of all armor segments (or 0) { int iMax = m_iHitPoints; int iMin = iMax; if (m_iExtraHPPerCharge) iMax = Max(0, iMax + (m_iExtraHPPerCharge * iCharges)); if (m_iArmorShield) { iMin = m_iArmorShield; if (iArmorSegs > 0) iMax = Min(iMax, ((m_iArmorShield * iTotalHP / iArmorSegs) + 5) / 10); } // If we're installed, fire the custom event to get max HPs if (Ctx.GetSource() && Ctx.GetDevice()) { CItemEnhancementStack *pEnhancements = Ctx.GetDevice()->GetEnhancements(); iMax = FireGetMaxHP(Ctx.GetDevice(), Ctx.GetSource(), iMax); // Apply bonus from device (which includes mods) if (pEnhancements) iMax += (iMax * pEnhancements->GetBonus() / 100); } // Otherwise, we just apply mods else { const CItemEnhancement &Mods = Ctx.GetMods(); if (Mods.IsNotEmpty()) iMax = iMax * Mods.GetHPAdj() / 100; } // Done if (iMin > iMax) iMin = iMax; if (retiMin) *retiMin = iMin; if (retiMax) *retiMax = iMax; }
int CShieldClass::GetMaxHP (CInstalledDevice *pDevice, CSpaceObject *pSource) // GetMaxHP // // Max HP of shields { int iMax = m_iHitPoints; // Adjust based on charges if (m_iExtraHPPerCharge) iMax = Max(0, iMax + m_iExtraHPPerCharge * pDevice->GetCharges(pSource)); // Adjust if shield is based on armor strength CShip *pShip; if (m_iArmorShield && (pShip = pSource->AsShip())) { // Compute the average HP of all the armor int iArmorHP = 0; int iArmorCount = pShip->GetArmorSectionCount(); for (int i = 0; i < iArmorCount; i++) iArmorHP += pShip->GetArmorSection(i)->GetHitPoints(); if (iArmorCount > 0) iArmorHP = ((m_iArmorShield * iArmorHP / iArmorCount) + 5) / 10; // Return HP left iMax = Min(iMax, iArmorHP); } // Fire event iMax = FireGetMaxHP(pDevice, pSource, iMax); // Adjust based on enhancements CItemEnhancementStack *pEnhancements = pDevice->GetEnhancements(); if (pEnhancements) iMax = iMax + ((iMax * pEnhancements->GetBonus()) / 100); // Done return iMax; }
CString CItemEnhancement::GetEnhancedDesc (const CItem &Item, CSpaceObject *pInstalled, CInstalledDevice *pDevice) const // GetEnhancedDesc // // Get short description of enhancement. // // NOTE: This currently include bonuses confered by other ship systems (stored in // the device structure. In the future we need a better mechanism) { CItemEnhancementStack *pAllEnhancements = (pDevice ? pDevice->GetEnhancements() : NULL); switch (GetType()) { case etHPBonus: case etStrengthen: { switch (Item.GetType()->GetCategory()) { case itemcatWeapon: case itemcatLauncher: case itemcatShields: { int iDamageBonus; // See if this device is installed; if so, then the bonus is // calculated and cached in the device; we do this so that we can // include bonuses from all sources. if (pAllEnhancements) iDamageBonus = pAllEnhancements->GetBonus(); else iDamageBonus = GetHPBonus(); // Bonus if (iDamageBonus < 0) return strPatternSubst(CONSTLIT("%d%%"), iDamageBonus); else return strPatternSubst(CONSTLIT("+%d%%"), iDamageBonus); } default: if (IsDisadvantage()) return strPatternSubst(CONSTLIT("-%d%%"), 100 - GetHPAdj()); else return strPatternSubst(CONSTLIT("+%d%%"), GetHPAdj() - 100); } } case etRegenerate: return (IsDisadvantage() ? CONSTLIT("-Decay") : CONSTLIT("+Regen")); case etReflect: return strPatternSubst((IsDisadvantage() ? CONSTLIT("-%s Trans") : CONSTLIT("+%s Reflect")), strCapitalizeWords(::GetDamageShortName(GetDamageType()))); case etRepairOnHit: return strPatternSubst(CONSTLIT("+%s Repair"), strCapitalizeWords(::GetDamageShortName(GetDamageType()))); case etResist: return (IsDisadvantage() ? CONSTLIT("-Vulnerable") : CONSTLIT("+Resistant")); case etResistEnergy: return (IsDisadvantage() ? CONSTLIT("-Energy Vulnerable") : CONSTLIT("+Energy Resistant")); case etResistMatter: return (IsDisadvantage() ? CONSTLIT("-Matter Vulnerable") : CONSTLIT("+Matter Resistant")); case etResistByLevel: { if (IsDisadvantage()) return strPatternSubst(CONSTLIT("-%s -%s"), strCapitalizeWords(::GetDamageShortName(GetDamageType())), strCapitalizeWords(::GetDamageShortName((DamageTypes)(GetDamageType() + 1)))); else return strPatternSubst(CONSTLIT("+%s +%s"), strCapitalizeWords(::GetDamageShortName(GetDamageType())), strCapitalizeWords(::GetDamageShortName((DamageTypes)(GetDamageType() + 1)))); } case etResistByDamage: return strPatternSubst((IsDisadvantage() ? CONSTLIT("-%s") : CONSTLIT("+%s")), strCapitalizeWords(::GetDamageShortName(GetDamageType()))); case etResistByDamage2: { if (IsDisadvantage()) return strPatternSubst(CONSTLIT("-%s -%s"), strCapitalizeWords(::GetDamageShortName(GetDamageType())), strCapitalizeWords(::GetDamageShortName((DamageTypes)(GetDamageType() + 2)))); else { switch (GetDamageType()) { case damageLaser: return CONSTLIT("+Ablative"); case damageKinetic: return CONSTLIT("+Reactive"); default: return strPatternSubst(CONSTLIT("+%s +%s"), strCapitalizeWords(::GetDamageShortName(GetDamageType())), strCapitalizeWords(::GetDamageShortName((DamageTypes)(GetDamageType() + 2)))); } } } case etSpecialDamage: { switch (GetLevel2()) { case specialRadiation: return CONSTLIT("+Rad Immune"); case specialBlinding: return CONSTLIT("+Blind Immune"); case specialEMP: return CONSTLIT("+EMP Immune"); case specialDeviceDamage: return CONSTLIT("+Dev Protect"); case specialDisintegration: return CONSTLIT("+Dis Immune"); default: return CONSTLIT("+Unk Immune"); } } case etImmunityIonEffects: return (IsDisadvantage() ? CONSTLIT("-No Shields") : CONSTLIT("+Ionization Immune")); case etPhotoRegenerate: return CONSTLIT("+SolRegen"); case etPhotoRecharge: return CONSTLIT("+SolPower"); case etPowerEfficiency: return (IsDisadvantage() ? CONSTLIT("-Drain") : CONSTLIT("+Efficient")); case etSpeed: case etSpeedOld: return (IsDisadvantage() ? CONSTLIT("-Slow") : CONSTLIT("+Fast")); default: return CONSTLIT("+Unknown"); } }