Hooks
static bool BeforeCvUnit_setDamage(CvUnit* self, int iNewValue, PlayerTypes ePlayer, int iUnit, float fAdditionalTextDelay, const CvString* pAppendText, int& result);static void AfterCvUnit_setDamage(CvUnit* self, int iNewValue, PlayerTypes ePlayer, int iUnit, float fAdditionalTextDelay, const CvString* pAppendText, int& result);static int ReplaceCvUnit_setDamage(int (*original)(CvUnit*, int, PlayerTypes, int, float, const CvString*), CvUnit* self, int iNewValue, PlayerTypes ePlayer, int iUnit, float fAdditionalTextDelay, const CvString* pAppendText);CivRegisterBefore<CivHooks::CvUnit_setDamage>(host, &BeforeCvUnit_setDamage);CivRegisterAfter<CivHooks::CvUnit_setDamage>(host, &AfterCvUnit_setDamage);CivRegisterReplace<CivHooks::CvUnit_setDamage>(host, &ReplaceCvUnit_setDamage);
Code
16690#if defined(MOD_API_UNIT_STATS)16691int CvUnit::setDamage(int iNewValue, PlayerTypes ePlayer, int iUnit, float fAdditionalTextDelay, const CvString* pAppendText)16692#else16693int CvUnit::setDamage(int iNewValue, PlayerTypes ePlayer, float fAdditionalTextDelay, const CvString* pAppendText)16694#endif16695{16696 VALIDATE_OBJECT16697 int iOldValue;16698 float fDelay = 0.0f + fAdditionalTextDelay;1669916700 iOldValue = getDamage();1670116702 if(GetCurrHitPoints() == GetMaxHitPoints() && iNewValue < GetMaxHitPoints()) 16703 {16704 m_iLastGameTurnAtFullHealth = GC.getGame().getGameTurn();16705 }1670616707 m_iDamage = range(iNewValue, 0, GetMaxHitPoints());16708 int iDiff = m_iDamage - iOldValue;1670916710 CvAssertMsg(GetCurrHitPoints() >= 0, "currHitPoints() is expected to be non-negative (invalid Index)");1671116712 if(iOldValue != getDamage())16713 {16714 if(IsGarrisoned())16715 {16716 if(GetGarrisonedCity() != NULL)16717 {16718 GetGarrisonedCity()->updateStrengthValue();16719 }16720 }1672116722 setInfoBarDirty(true);1672316724 if(IsSelected())16725 {16726 DLLUI->setDirty(UnitInfo_DIRTY_BIT, true);16727 }1672816729 auto_ptr<ICvPlot1> pDllSelectionPlot(DLLUI->getSelectionPlot());16730 const int iSelectionPlotIndex = (pDllSelectionPlot.get() != NULL)? pDllSelectionPlot->GetPlotIndex() : -1;1673116732 if(plot()->GetPlotIndex() == iSelectionPlotIndex)16733 {16734 DLLUI->setDirty(PlotListButtons_DIRTY_BIT, true);16735 }1673616737 auto_ptr<ICvUnit1> pDllUnit(new CvDllUnit(this));16738 gDLL->GameplayUnitSetDamage(pDllUnit.get(), m_iDamage, iOldValue);167391674016741 // send the popup text if the player can see this plot16742 if(plot()->GetActiveFogOfWarMode() == FOGOFWARMODE_OFF)16743 {16744 if(!IsDead())16745 {16746 CvString text;16747#if defined(MOD_UNITS_MAX_HP)16748 iNewValue = MIN(GetMaxHitPoints(),iNewValue);16749#else16750 iNewValue = MIN(GC.getMAX_HIT_POINTS(),iNewValue);16751#endif16752 int iDiff = iOldValue - iNewValue;16753 if(iNewValue < iOldValue)16754 {16755 text.Format("[COLOR_GREEN]+%d", iDiff);16756 fDelay = GC.getPOST_COMBAT_TEXT_DELAY() * 2;16757 }16758 else16759 {16760 text.Format("[COLOR_RED]%d", iDiff);16761 }16762 if(pAppendText != NULL)16763 {16764 text += " ";16765 text += *pAppendText;16766 }16767 text += "[ENDCOLOR]";1676816769 int iX = m_iX;16770 int iY = m_iY;1677116772 // Where do we display this text? - put it where the unit is moving TO if it's this unit's turn16773 if(GET_PLAYER(getOwner()).isTurnActive())16774 {16775 const MissionData* pkMissionData = GetHeadMissionData();16776 if(pkMissionData != NULL)16777 {16778 if(pkMissionData->eMissionType == CvTypes::getMISSION_MOVE_TO())16779 {16780 int iTempX = pkMissionData->iData1;16781 int iTempY = pkMissionData->iData2;1678216783 CvPlot* pPlot = GC.getMap().plot(iTempX, iTempY);1678416785 // No enemies in our destination, and it's not a city OR it's a city we own16786 if(pPlot->getNumVisibleEnemyDefenders(this) == 0 && (!pPlot->isCity() || pPlot->getPlotCity()->getOwner() == getOwner()))16787 {16788 iX = iTempX;16789 iY = iTempY;16790 }16791 }16792 }16793 }1679416795 if (!isSuicide()) // Show the HP lost, expect if it is a suicide unit (missisle, etc.)16796#if defined(SHOW_PLOT_POPUP)16797 SHOW_PLOT_POPUP(GC.getMap().plot(iX, iY), getOwner(), text.c_str(), fDelay);16798#else16799 DLLUI->AddPopupText(iX, iY, text.c_str(), fDelay);16800#endif16801 }16802 }16803 }1680416805 if(IsDead())16806 {16807#if !defined(NO_ACHIEVEMENTS)16808 CvGame& game = GC.getGame();16809 const PlayerTypes eActivePlayer = game.getActivePlayer();16810 CvPlayerAI& activePlayer = GET_PLAYER(eActivePlayer);16811 if(m_iLastGameTurnAtFullHealth != -1 && m_iLastGameTurnAtFullHealth == game.getGameTurn() && getOwner() == eActivePlayer && activePlayer.isHuman())16812 {16813 CvUnitEntry* pUnitInfo = GC.getUnitInfo(getUnitType());16814 if(pUnitInfo != NULL && strcmp(pUnitInfo->GetType(),"UNIT_XCOM_SQUAD") == 0)16815 {16816 gDLL->UnlockAchievement(ACHIEVEMENT_XP2_46);16817 }16818 }16819#endif1682016821 m_iLastGameTurnAtFullHealth = -1;1682216823 kill(true, ePlayer);1682416825 CvString szMsg;16826 CvString szUnitAIString;16827 getUnitAIString(szUnitAIString, AI_getUnitAIType());16828 szMsg.Format("Killed in combat: %s, AI was: ", getName().GetCString());16829 szMsg += szUnitAIString;16830#if defined(MOD_BUGFIX_USE_GETTERS)16831 GET_MY_PLAYER().GetTacticalAI()->LogTacticalMessage(szMsg, true /*bSkipLogDominanceZone*/);16832#else16833 GET_PLAYER(m_eOwner).GetTacticalAI()->LogTacticalMessage(szMsg, true /*bSkipLogDominanceZone*/);16834#endif1683516836 if(ePlayer != NO_PLAYER)16837 {16838#if defined(MOD_BUGFIX_USE_GETTERS)16839 if (getOwner() == BARBARIAN_PLAYER && plot()->getImprovementType() == GC.getBARBARIAN_CAMP_IMPROVEMENT())16840#else16841 if (m_eOwner == BARBARIAN_PLAYER && plot()->getImprovementType() == GC.getBARBARIAN_CAMP_IMPROVEMENT())16842#endif16843 {16844 GET_PLAYER(ePlayer).GetPlayerTraits()->SetDefeatedBarbarianCampGuardType(getUnitType());16845 }1684616847#if defined(MOD_API_EXTENSIONS)16848 GET_PLAYER(ePlayer).DoUnitKilledCombat(NULL, getOwner(), getUnitType());16849#else16850 GET_PLAYER(ePlayer).DoUnitKilledCombat(getOwner(), getUnitType());16851#endif1685216853#if defined(MOD_API_UNIT_STATS)16854 if (iUnit != -1) {16855 CvUnit* killingUnit = GET_PLAYER(ePlayer).getUnit(iUnit);1685616857 if (killingUnit) {16858 killingUnit->changeStatsKilled(1);16859 }16860 }16861#endif16862 }16863 }1686416865 return iDiff;16866}