Hooks
static bool BeforeCvPlayer_disbandUnit(CvPlayer* self, bool arg0);static void AfterCvPlayer_disbandUnit(CvPlayer* self, bool arg0);static void ReplaceCvPlayer_disbandUnit(void (*original)(CvPlayer*, bool), CvPlayer* self, bool arg0);CivRegisterBefore<CivHooks::CvPlayer_disbandUnit>(host, &BeforeCvPlayer_disbandUnit);CivRegisterAfter<CivHooks::CvPlayer_disbandUnit>(host, &AfterCvPlayer_disbandUnit);CivRegisterReplace<CivHooks::CvPlayer_disbandUnit>(host, &ReplaceCvPlayer_disbandUnit);
Code
3775void CvPlayer::disbandUnit(bool)3776{3777 CvUnit* pLoopUnit;3778 CvUnit* pBestUnit;3779 char szBuffer[1024];3780 const size_t lenBuffer = 1024;3781 int iValue;3782 int iBestValue;3783 int iLoop;37843785 iBestValue = INT_MAX;3786 pBestUnit = NULL;37873788 for(pLoopUnit = firstUnit(&iLoop); pLoopUnit != NULL; pLoopUnit = nextUnit(&iLoop))3789 {3790 if(!(pLoopUnit->hasCargo()))3791 {3792 if(!(pLoopUnit->isGoldenAge()))3793 {3794 if(pLoopUnit->getUnitInfo().GetProductionCost() > 0)3795 {3796 {3797 iValue = (10000 + GC.getGame().getJonRandNum(1000, "Disband Unit"));37983799 iValue += (pLoopUnit->getUnitInfo().GetProductionCost() * 5);38003801#if defined(MOD_UNITS_XP_TIMES_100)3802 iValue += (pLoopUnit->getExperienceTimes100() / 100 * 20);3803#else3804 iValue += (pLoopUnit->getExperience() * 20);3805#endif3806 iValue += (pLoopUnit->getLevel() * 100);38073808 if(pLoopUnit->IsCanDefend() && pLoopUnit->plot()->isCity())3809 {3810 iValue *= 2;3811 }38123813 if(pLoopUnit->plot()->getTeam() == pLoopUnit->getTeam())3814 {3815 iValue *= 3;3816 }38173818 switch(pLoopUnit->AI_getUnitAIType())3819 {3820 case UNITAI_UNKNOWN:3821 break;38223823 case UNITAI_SETTLE:3824 iValue *= 20;3825 break;38263827 case UNITAI_WORKER:3828 iValue *= 10;3829 break;38303831 case UNITAI_ATTACK:3832 case UNITAI_CITY_BOMBARD:3833 case UNITAI_FAST_ATTACK:3834 case UNITAI_DEFENSE:3835 case UNITAI_COUNTER:3836 iValue *= 2;3837 break;38383839 case UNITAI_RANGED:3840 case UNITAI_CITY_SPECIAL:3841 case UNITAI_PARADROP:3842 iValue *= 6;3843 break;38443845 case UNITAI_EXPLORE:3846 iValue *= 15;3847 break;38483849 case UNITAI_ARTIST:3850 case UNITAI_SCIENTIST:3851 case UNITAI_GENERAL:3852 case UNITAI_MERCHANT:3853 case UNITAI_ENGINEER:3854 case UNITAI_SPACESHIP_PART:3855 case UNITAI_TREASURE:3856 case UNITAI_PROPHET:3857 case UNITAI_MISSIONARY:3858 case UNITAI_INQUISITOR:3859 case UNITAI_ADMIRAL:3860 case UNITAI_WRITER:3861 case UNITAI_MUSICIAN:3862 break;38633864 case UNITAI_ICBM:3865 iValue *= 4;3866 break;38673868 case UNITAI_WORKER_SEA:3869 iValue *= 18;3870 break;38713872 case UNITAI_ATTACK_SEA:3873 case UNITAI_RESERVE_SEA:3874 case UNITAI_ESCORT_SEA:3875 break;38763877 case UNITAI_EXPLORE_SEA:3878 iValue *= 25;3879 break;38803881 case UNITAI_ASSAULT_SEA:3882 case UNITAI_SETTLER_SEA:3883 case UNITAI_CARRIER_SEA:3884 case UNITAI_MISSILE_CARRIER_SEA:3885 iValue *= 5;3886 break;38873888 case UNITAI_PIRATE_SEA:3889 case UNITAI_ATTACK_AIR:3890 break;38913892 case UNITAI_DEFENSE_AIR:3893 case UNITAI_CARRIER_AIR:3894 case UNITAI_MISSILE_AIR:3895 iValue *= 3;3896 break;38973898 default:3899 CvAssert(false);3900 break;3901 }39023903 if(pLoopUnit->getUnitInfo().GetExtraMaintenanceCost() > 0)3904 {3905 iValue /= (pLoopUnit->getUnitInfo().GetExtraMaintenanceCost() + 1);3906 }39073908 if(iValue < iBestValue)3909 {3910 iBestValue = iValue;3911 pBestUnit = pLoopUnit;3912 }3913 }3914 }3915 }3916 }3917 }39183919 if(pBestUnit != NULL)3920 {3921 if(GetID() == GC.getGame().getActivePlayer())3922 {3923 sprintf_s(szBuffer, lenBuffer, GetLocalizedText("TXT_KEY_MISC_UNIT_DISBANDED_NO_MONEY", pBestUnit->getNameKey()).GetCString());3924 GC.GetEngineUserInterface()->AddUnitMessage(0, pBestUnit->GetIDInfo(), GetID(), false, GC.getEVENT_MESSAGE_TIME(), szBuffer);//, "AS2D_UNITDISBANDED", MESSAGE_TYPE_MINOR_EVENT, pBestUnit->getUnitInfo().GetButton(), (ColorTypes)GC.getInfoTypeForString("COLOR_RED"), pBestUnit->getX(), pBestUnit->getY(), true, true);3925 }39263927 CvAssert(!(pBestUnit->isGoldenAge()));39283929 pBestUnit->kill(false);3930 }3931}