本文整理汇总了C++中CvUnit类的典型用法代码示例。如果您正苦于以下问题:C++ CvUnit类的具体用法?C++ CvUnit怎么用?C++ CvUnit使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CvUnit类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: GET_PLAYER
/// How many units of this type are in army?
int CvArmyAI::GetUnitsOfType(MultiunitPositionTypes ePosition) const
{
int iRtnValue = 0;
for(unsigned int iI = 0; iI < m_FormationEntries.size(); iI++)
{
if(m_FormationEntries[iI].m_iUnitID > ARMYSLOT_NO_UNIT)
{
CvUnit* pUnit = GET_PLAYER(m_eOwner).getUnit(m_FormationEntries[iI].m_iUnitID);
if(pUnit->getMoves() > 0)
{
CvMultiUnitFormationInfo* thisFormation = GC.getMultiUnitFormationInfo(m_iFormationIndex);
if(thisFormation)
{
const CvFormationSlotEntry& thisSlotEntry = thisFormation->getFormationSlotEntry(iI);
if(thisSlotEntry.m_ePositionType == ePosition)
{
iRtnValue++;
}
}
}
}
}
return iRtnValue;
}
示例2: AI_seperateAI
void CvSelectionGroupAI::AI_seperateAI(UnitAITypes eUnitAI)
{
CLLNode<IDInfo>* pEntityNode;
CvUnit* pLoopUnit;
pEntityNode = headUnitNode();
while (pEntityNode != NULL)
{
pLoopUnit = ::getUnit(pEntityNode->m_data);
pEntityNode = nextUnitNode(pEntityNode);
if (pLoopUnit->AI_getUnitAIType() == eUnitAI)
{
pLoopUnit->joinGroup(NULL);
// TAC - AI Assault Sea - koma13, jdog5000(BBAI)
// Was potential crash in use of plot() if group emptied
//if (plot()->getTeam() == getTeam())
if (pLoopUnit->plot()->getTeam() == getTeam())
// TAC - AI Assault Sea - koma13, jdog5000(BBAI)
{
pLoopUnit->getGroup()->pushMission(MISSION_SKIP);
}
}
}
}
示例3: plotXYWithRangeCheck
void HornOfValere::DoTurn()
{
if (!m_bFound)
{
for(int iX = -m_iDiscoveryRange; iX <= m_iDiscoveryRange; iX++)
{
for(int iY = -m_iDiscoveryRange; iY <= m_iDiscoveryRange; iY++)
{
CvPlot* pkPlot = plotXYWithRangeCheck(GetX(), GetY(), iX, iY, m_iDiscoveryRange);
if(pkPlot != NULL)
{
IDInfoVector currentUnits;
if (pkPlot->getUnits(¤tUnits) > 0)
{
for (IDInfoVector::const_iterator itr = currentUnits.begin(); itr != currentUnits.end(); ++itr)
{
CvUnit* pUnit = ::getUnit(*itr);
if(pUnit && pUnit->CanDiscoverHornOfValere())
{
FindHorn(pUnit);
return;
}
}
}
}
}
}
}
IncrementTurnsSinceHornBlown();
}
示例4: GET_PLAYER
//------------------------------------------------------------------------------
void CvDllNetMessageHandler::ResponseSwapUnits(PlayerTypes ePlayer, int iUnitID, MissionTypes eMission, int iData1, int iData2, int iFlags, bool bShift)
{
CvUnit::dispatchingNetMessage(true);
CvPlayerAI& kPlayer = GET_PLAYER(ePlayer);
CvUnit* pkUnit = kPlayer.getUnit(iUnitID);
if(pkUnit != NULL)
{
// Get target plot
CvMap& kMap = GC.getMap();
CvPlot* pkTargetPlot = kMap.plot(iData1, iData2);
if(pkTargetPlot != NULL)
{
CvPlot* pkOriginationPlot = pkUnit->plot();
// Find unit to move out
for(int iI = 0; iI < pkTargetPlot->getNumUnits(); iI++)
{
CvUnit* pkUnit2 = pkTargetPlot->getUnitByIndex(iI);
if(pkUnit2 && pkUnit2->AreUnitsOfSameType(*pkUnit))
{
// Start the swap
pkUnit->PushMission(CvTypes::getMISSION_MOVE_TO(), iData1, iData2, CvUnit::MOVEFLAG_IGNORE_STACKING, bShift, true);
// Move the other unit back out, again splitting if necessary
pkUnit2->PushMission(CvTypes::getMISSION_MOVE_TO(), pkOriginationPlot->getX(), pkOriginationPlot->getY());
}
}
}
}
CvUnit::dispatchingNetMessage(false);
}
示例5: GET_PLAYER
// Find all our enemies (combat units)
void CvTacticalAnalysisMap::BuildEnemyUnitList()
{
m_EnemyUnits.clear();
m_EnemyCities.clear();
TeamTypes ourTeam = GET_PLAYER(m_ePlayer).getTeam();
for(int iPlayer = 0; iPlayer < MAX_PLAYERS; iPlayer++)
{
const PlayerTypes ePlayer = (PlayerTypes)iPlayer;
CvPlayer& kPlayer = GET_PLAYER(ePlayer);
const TeamTypes eTeam = kPlayer.getTeam();
// for each opposing civ
if(kPlayer.isAlive() && GET_TEAM(eTeam).isAtWar(ourTeam))
{
int iLoop;
CvUnit* pLoopUnit = NULL;
CvCity* pLoopCity;
for(pLoopCity = kPlayer.firstCity(&iLoop); pLoopCity != NULL; pLoopCity = kPlayer.nextCity(&iLoop))
if (pLoopCity->plot()->isRevealed(ourTeam))
m_EnemyCities.push_back(pLoopCity->GetIDInfo());
for(pLoopUnit = kPlayer.firstUnit(&iLoop); pLoopUnit != NULL; pLoopUnit = kPlayer.nextUnit(&iLoop))
if(pLoopUnit->IsCanAttack() && pLoopUnit->plot()->isVisible(ourTeam))
m_EnemyUnits.push_back(pLoopUnit->GetIDInfo());
}
}
}
示例6: GET_PLAYER
/// Remove a unit from the army
bool CvArmyAI::RemoveUnit(int iUnitToRemoveID)
{
for(int iI = 0; iI < (int)m_FormationEntries.size(); iI++)
{
CvArmyFormationSlot slot = m_FormationEntries[iI];
if(slot.GetUnitID() == iUnitToRemoveID)
{
CvUnit* pThisUnit = GET_PLAYER(GetOwner()).getUnit(iUnitToRemoveID);
if(pThisUnit)
{
// Clears unit's army ID and erase from formation entries
pThisUnit->setArmyID(-1);
pThisUnit->AI_setUnitAIType(pThisUnit->getUnitInfo().GetDefaultUnitAIType());
// Tell the associate operation that a unit was lost
CvAIOperation* pThisOperation = GET_PLAYER(GetOwner()).getAIOperation(m_iOperationID);
if(pThisOperation)
pThisOperation->UnitWasRemoved(GetID(), iI);
return true;
}
}
}
return false;
}
示例7: GET_PLAYER
// Find all our enemies (combat units)
void CvTacticalAnalysisMap::BuildEnemyUnitList()
{
CvTacticalAnalysisEnemy enemy;
m_EnemyUnits.clear();
for(int iPlayer = 0; iPlayer < MAX_PLAYERS; iPlayer++)
{
const PlayerTypes ePlayer = (PlayerTypes)iPlayer;
CvPlayer& kPlayer = GET_PLAYER(ePlayer);
const TeamTypes eTeam = kPlayer.getTeam();
// for each opposing civ
if(kPlayer.isAlive() && GET_TEAM(eTeam).isAtWar(m_pPlayer->getTeam()))
{
int iLoop;
CvUnit* pLoopUnit = NULL;
for(pLoopUnit = kPlayer.firstUnit(&iLoop); pLoopUnit != NULL; pLoopUnit = kPlayer.nextUnit(&iLoop))
{
// Make sure this unit can attack
if(pLoopUnit->IsCanAttack())
{
m_EnemyUnits.push_back(pLoopUnit);
}
}
}
}
}
示例8: AI_plotTargetMissionAIs
int CvPlayerAI::AI_plotTargetMissionAIs(CvPlot* pPlot, MissionAITypes eMissionAI, int iRange)
{
int iCount = 0;
int iLoop;
for(CvUnit* pLoopUnit = firstUnit(&iLoop); pLoopUnit; pLoopUnit = nextUnit(&iLoop))
{
CvPlot* pMissionPlot = pLoopUnit->GetMissionAIPlot();
if(!pMissionPlot)
{
continue;
}
MissionAITypes eGroupMissionAI = pLoopUnit->GetMissionAIType();
if(eGroupMissionAI != eMissionAI)
{
continue;
}
int iDistance = plotDistance(pPlot->getX(), pPlot->getY(), pMissionPlot->getX(), pMissionPlot->getY());
if(iDistance == iRange)
{
iCount++;
}
}
return iCount;
}
示例9: GetDirectiveGeneral
GreatPeopleDirectiveTypes CvPlayerAI::GetDirectiveGeneral (CvUnit*)
{
GreatPeopleDirectiveTypes eDirective = NO_GREAT_PEOPLE_DIRECTIVE_TYPE;
SpecialUnitTypes eSpecialUnitGreatPerson = (SpecialUnitTypes) GC.getInfoTypeForString("SPECIALUNIT_PEOPLE");
int iGreatGeneralCount = 0;
int iLoop;
for (CvUnit* pLoopUnit = firstUnit(&iLoop); pLoopUnit; pLoopUnit = nextUnit(&iLoop))
{
if (pLoopUnit->getSpecialUnitType() != eSpecialUnitGreatPerson)
{
continue;
}
if (pLoopUnit->AI_getUnitAIType() == UNITAI_GENERAL && pLoopUnit->GetGreatPeopleDirective() != GREAT_PEOPLE_DIRECTIVE_GOLDEN_AGE)
{
iGreatGeneralCount++;
}
}
if (iGreatGeneralCount > 2)
{
eDirective = GREAT_PEOPLE_DIRECTIVE_GOLDEN_AGE;
}
return eDirective;
}
示例10: data
//------------------------------------------------------------------------------
ICvEnumerator* CvDllGameContext::TEMPCalculatePathFinderUpdates(ICvUnit1* pHeadSelectedUnit, int iMouseMapX, int iMouseMapY)
{
CvUnit* pkUnit = GC.UnwrapUnitPointer(pHeadSelectedUnit);
SPathFinderUserData data(pkUnit,CvUnit::MOVEFLAG_DECLARE_WAR);
SPath path = GC.GetPathFinder().GetPath(pkUnit->getX(), pkUnit->getY(), iMouseMapX, iMouseMapY, data);
if (!!path)
{
int size = path.vPlots.size();
std::vector<CvDllPathFinderUpdateListData> pUpdateData;
pUpdateData.reserve(size);
// now fill out the event array
for (int i=0; i<size; i++)
{
CvDllPathFinderUpdateListData update;
update.iX = path.vPlots[i].x;
update.iY = path.vPlots[i].y;
update.iTurnNumber = path.vPlots[i].turns;
pUpdateData.push_back(update);
}
return new CvDllPathFinderUpdateList(pUpdateData);
}
return NULL;
}
示例11: GetDirectiveGeneral
GreatPeopleDirectiveTypes CvPlayerAI::GetDirectiveGeneral(CvUnit* pGreatGeneral)
{
GreatPeopleDirectiveTypes eDirective = NO_GREAT_PEOPLE_DIRECTIVE_TYPE;
SpecialUnitTypes eSpecialUnitGreatPerson = (SpecialUnitTypes) GC.getInfoTypeForString("SPECIALUNIT_PEOPLE");
int iGreatGeneralCount = 0;
int iLoop;
for(CvUnit* pLoopUnit = firstUnit(&iLoop); pLoopUnit; pLoopUnit = nextUnit(&iLoop))
{
if(pLoopUnit->getSpecialUnitType() != eSpecialUnitGreatPerson)
{
continue;
}
if(pLoopUnit->AI_getUnitAIType() == UNITAI_GENERAL && pLoopUnit->GetGreatPeopleDirective() != GREAT_PEOPLE_DIRECTIVE_GOLDEN_AGE)
{
iGreatGeneralCount++;
}
}
if(iGreatGeneralCount > 2 && pGreatGeneral->plot()->getOwner() == pGreatGeneral->getOwner())
{
// we're using a power at this point because constructing the improvement goes through different code
eDirective = GREAT_PEOPLE_DIRECTIVE_USE_POWER;
}
return eDirective;
}
示例12: headUnitNode
void CvSelectionGroupAI::AI_setGroupflag(int newflag)
{
CLLNode<IDInfo>* pUnitNode = headUnitNode();
while (pUnitNode != NULL)
{
CvUnit* pLoopUnit = ::getUnit(pUnitNode->m_data);
pUnitNode = nextUnitNode(pUnitNode);
pLoopUnit->AI_setGroupflag(newflag);
}
}
示例13: AI_sumStrength
int CvSelectionGroupAI::AI_sumStrength(const CvPlot* pAttackedPlot, DomainTypes eDomainType, bool bCheckCanAttack, bool bCheckCanMove) const
{
CLLNode<IDInfo>* pUnitNode;
CvUnit* pLoopUnit;
int strSum = 0;
pUnitNode = headUnitNode();
while (pUnitNode != NULL)
{
pLoopUnit = ::getUnit(pUnitNode->m_data);
pUnitNode = nextUnitNode(pUnitNode);
if (!pLoopUnit->isDead())
{
bool bCanAttack = false;
if (pLoopUnit->getDomainType() == DOMAIN_AIR)
bCanAttack = pLoopUnit->canAirAttack();
else
bCanAttack = pLoopUnit->canAttack();
if (!bCheckCanAttack || bCanAttack)
{
if (!bCheckCanMove || pLoopUnit->canMove())
if (!bCheckCanMove || pAttackedPlot == NULL || pLoopUnit->canMoveInto(pAttackedPlot, /*bAttack*/ true, /*bDeclareWar*/ true))
if (eDomainType == NO_DOMAIN || pLoopUnit->getDomainType() == eDomainType)
strSum += pLoopUnit->currEffectiveStr(pAttackedPlot, pLoopUnit);
}
}
}
return strSum;
}
示例14: GET_PLAYER
// Can this tile be attacked by an enemy unit or city next turn?
bool CvDangerPlotContents::IsUnderImmediateThreat(const CvUnit* pUnit)
{
if (!m_pPlot || !pUnit)
return false;
// Air units operate off of intercepts instead of units/cities that can attack them
if (pUnit->getDomainType() == DOMAIN_AIR)
{
if (pUnit->GetBestInterceptor(*m_pPlot))
{
return true;
}
}
else
{
// Cities in range
for (DangerCityVector::iterator it = m_apCities.begin(); it < m_apCities.end(); ++it)
{
CvCity* pCity = GET_PLAYER(it->first).getCity(it->second);
if (pCity && pCity->getTeam() != pUnit->getTeam())
{
return true;
}
}
// Units in range
for (DangerUnitVector::iterator it = m_apUnits.begin(); it < m_apUnits.end(); ++it)
{
CvUnit* pUnit = GET_PLAYER(it->first).getUnit(it->second);
if (pUnit && !pUnit->isDelayedDeath() && !pUnit->IsDead())
{
return true;
}
}
// Citadel etc in range
if (GetDamageFromFeatures(pUnit->getOwner()) > 0)
{
return true;
}
}
// Terrain damage is greater than heal rate
int iMinimumDamage = m_bFlatPlotDamage ? m_pPlot->getTurnDamage(pUnit->ignoreTerrainDamage(), pUnit->ignoreFeatureDamage(), pUnit->extraTerrainDamage(), pUnit->extraFeatureDamage()) : 0;
if (pUnit->canHeal(m_pPlot))
{
iMinimumDamage -= pUnit->healRate(m_pPlot);
}
return (iMinimumDamage > 0);
}
示例15: CvAssert
void CvPlayerAI::ProcessGreatPeople(void)
{
SpecialUnitTypes eSpecialUnitGreatPerson = (SpecialUnitTypes) GC.getInfoTypeForString("SPECIALUNIT_PEOPLE");
CvAssert(isAlive());
if(!isAlive())
return;
int iLoop;
for(CvUnit* pLoopUnit = firstUnit(&iLoop); pLoopUnit; pLoopUnit = nextUnit(&iLoop))
{
if(pLoopUnit->getSpecialUnitType() != eSpecialUnitGreatPerson)
{
continue;
}
GreatPeopleDirectiveTypes eDirective = NO_GREAT_PEOPLE_DIRECTIVE_TYPE;
switch(pLoopUnit->AI_getUnitAIType())
{
case UNITAI_WRITER:
eDirective = GetDirectiveWriter(pLoopUnit);
break;
case UNITAI_ARTIST:
eDirective = GetDirectiveArtist(pLoopUnit);
break;
case UNITAI_MUSICIAN:
eDirective = GetDirectiveMusician(pLoopUnit);
break;
case UNITAI_ENGINEER:
eDirective = GetDirectiveEngineer(pLoopUnit);
break;
case UNITAI_MERCHANT:
eDirective = GetDirectiveMerchant(pLoopUnit);
break;
case UNITAI_SCIENTIST:
eDirective = GetDirectiveScientist(pLoopUnit);
break;
case UNITAI_GENERAL:
eDirective = GetDirectiveGeneral(pLoopUnit);
break;
case UNITAI_PROPHET:
eDirective = GetDirectiveProphet(pLoopUnit);
break;
case UNITAI_ADMIRAL:
eDirective = GetDirectiveAdmiral(pLoopUnit);
break;
}
pLoopUnit->SetGreatPeopleDirective(eDirective);
}
}