int CArmorClass::GetMaxHP (CItemCtx &ItemCtx) // GetMaxHP // // Returns the max HP for this kind of armor { // Start with hit points defined by the class int iHP = m_iHitPoints; // Fire event to compute HP, if necessary iHP = FireGetMaxHP(ItemCtx, iHP); // Add mods const CItemEnhancement &Mods = ItemCtx.GetMods(); if (Mods.IsNotEmpty()) iHP = iHP * Mods.GetHPAdj() / 100; // Add complete bonus CInstalledArmor *pSect = ItemCtx.GetArmor(); if (pSect && pSect->IsComplete()) iHP += m_iArmorCompleteBonus; // Done return iHP; }
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; }