CvPlayer::addFreeUnitAI(UnitAITypes, int)
- Defined in
- CvPlayer.cpp, line 1654
- Class
- CvPlayer
- Hook name
CivHooks::CvPlayer_addFreeUnitAI
Hooks
static bool BeforeCvPlayer_addFreeUnitAI(CvPlayer* self, UnitAITypes eUnitAI, int iCount);static void AfterCvPlayer_addFreeUnitAI(CvPlayer* self, UnitAITypes eUnitAI, int iCount);static void ReplaceCvPlayer_addFreeUnitAI(void (*original)(CvPlayer*, UnitAITypes, int), CvPlayer* self, UnitAITypes eUnitAI, int iCount);CivRegisterBefore<CivHooks::CvPlayer_addFreeUnitAI>(host, &BeforeCvPlayer_addFreeUnitAI);CivRegisterAfter<CivHooks::CvPlayer_addFreeUnitAI>(host, &AfterCvPlayer_addFreeUnitAI);CivRegisterReplace<CivHooks::CvPlayer_addFreeUnitAI>(host, &ReplaceCvPlayer_addFreeUnitAI);
Code
1654void CvPlayer::addFreeUnitAI(UnitAITypes eUnitAI, int iCount)1655{1656 int iI;16571658 UnitTypes eBestUnit = NO_UNIT;1659 int iBestValue = 0;16601661 CvCivilizationInfo& playerCivilzationInfo = getCivilizationInfo();1662 for(iI = 0; iI < GC.getNumUnitClassInfos(); iI++)1663 {1664 const UnitClassTypes eUnitClass = static_cast<UnitClassTypes>(iI);1665 CvUnitClassInfo* pkUnitClassInfo = GC.getUnitClassInfo(eUnitClass);1666 if(pkUnitClassInfo)1667 {1668 UnitTypes eLoopUnit = (UnitTypes)playerCivilzationInfo.getCivilizationUnits(iI);1669 if(eLoopUnit != NO_UNIT)1670 {1671 CvUnitEntry* pUnitInfo = GC.getUnitInfo(eLoopUnit);1672 if(pUnitInfo != NULL)1673 {1674 if(canTrain(eLoopUnit))1675 {1676 bool bValid = true;1677 for(int iJ = 0; iJ < GC.getNumResourceInfos(); iJ++)1678 {1679 const ResourceTypes eResource = static_cast<ResourceTypes>(iJ);1680 CvResourceInfo* pkResource = GC.getResourceInfo(eResource);1681 if(pkResource)1682 {1683 if(pUnitInfo->GetResourceQuantityRequirement(iJ) > 0)1684 {1685 bValid = false;1686 }1687 }1688 }16891690 if(bValid)1691 {1692 int iValue = 0;16931694 // Default unit AI matches1695 if(pUnitInfo->GetDefaultUnitAIType() == eUnitAI)1696 iValue += (pUnitInfo->GetProductionCost() * 2);1697 // Not default, but still possible1698 else if(pUnitInfo->GetUnitAIType(eUnitAI))1699 iValue += (pUnitInfo->GetProductionCost());17001701 if(iValue > iBestValue)1702 {1703 eBestUnit = eLoopUnit;1704 iBestValue = iValue;1705 }1706 }1707 }1708 }1709 }1710 }17111712 }17131714 if(eBestUnit != NO_UNIT)1715 {1716 for(iI = 0; iI < iCount; iI++)1717 {1718 addFreeUnit(eBestUnit, eUnitAI);1719 }1720 }1721}
Calls
- CvCivilizationInfo::getCivilizationUnits(int) const
- CvGlobals::getNumResourceInfos()
- CvGlobals::getNumUnitClassInfos()
- CvGlobals::getResourceInfo(ResourceTypes)
- CvGlobals::getUnitClassInfo(UnitClassTypes)
- CvGlobals::getUnitInfo(UnitTypes)
- CvPlayer::addFreeUnit(UnitTypes, UnitAITypes)
- CvPlayer::canTrain(UnitTypes, bool, bool, bool, bool, CvString *) const
- CvPlayer::getCivilizationInfo() const
- CvUnitEntry::GetDefaultUnitAIType() const
- CvUnitEntry::GetProductionCost() const
- CvUnitEntry::GetResourceQuantityRequirement(int) const
- CvUnitEntry::GetUnitAIType(int) const