void CvUnit::doDamage(int iDmg, int iDmgLimit, CvUnit* pAttacker, int iDmgType)
{
CvWString szMessage;
int iResist;
iResist = baseCombatStr() *2;
iResist += getLevel() * 2;
if (iDmgType != -1)
{
iResist += getDamageTypeResist((DamageTypes)iDmgType);
}
if (pAttacker != NULL)
{
iDmg += pAttacker->getSpellDamageModify();
}
if (iResist < 100)
{
iResist *= -1;
iDmg = GC.getGameINLINE().getSorenRandNum(iDmg, "Damage") + GC.getGameINLINE().getSorenRandNum(iDmg, "Damage");
iDmg = iDmg * (iResist + 100) / 100;
if (iDmg + getDamage() > iDmgLimit)
{
iDmg = iDmgLimit - getDamage();
}
if (iDmg > 0)
{
if (iDmg + getDamage() >= 100)
{
szMessage = gDLL->getText("TXT_KEY_MESSAGE_KILLED_BY", GC.getUnitInfo(getUnitType()).getDescription(), GC.getDamageTypeInfo((DamageTypes)iDmgType).getDescription());
}
else
{
szMessage = gDLL->getText("TXT_KEY_MESSAGE_DAMAGED_BY", GC.getUnitInfo(getUnitType()).getDescription(), iDmg, GC.getDamageTypeInfo((DamageTypes)iDmgType).getDescription());
}
gDLL->getInterfaceIFace()->addMessage(((PlayerTypes)getOwner()), true, GC.getDefineINT("EVENT_MESSAGE_TIME"), szMessage, "", MESSAGE_TYPE_MAJOR_EVENT, "Art/Interface/Buttons/Fire.dds", (ColorTypes)GC.getInfoTypeForString("COLOR_RED"), getX_INLINE(), getY_INLINE(), true, true);
if (pAttacker != NULL)
{
gDLL->getInterfaceIFace()->addMessage(((PlayerTypes)pAttacker->getOwner()), true, GC.getDefineINT("EVENT_MESSAGE_TIME"), szMessage, "", MESSAGE_TYPE_MAJOR_EVENT, GC.getDamageTypeInfo((DamageTypes)iDmgType).getButton(), (ColorTypes)GC.getInfoTypeForString("COLOR_GREEN"), getX_INLINE(), getY_INLINE(), true, true);
changeDamage(iDmg, pAttacker->getOwner());
if (getDamage() >= 100)
{
kill(true,pAttacker->getOwner());
}
if (!(pAttacker->isHiddenNationality()) && !(isHiddenNationality()))
{
if (getTeam() != pAttacker->getTeam())
{
GET_TEAM(pAttacker->getTeam()).declareWar(getTeam(), false, NO_WARPLAN);
}
}
}
else
{
changeDamage(iDmg, NO_PLAYER);
if (getDamage() >= 100)
{
kill(true,NO_PLAYER);
}
}
}
}
}