本文整理汇总了C++中CvUnit::AI_update方法的典型用法代码示例。如果您正苦于以下问题:C++ CvUnit::AI_update方法的具体用法?C++ CvUnit::AI_update怎么用?C++ CvUnit::AI_update使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类CvUnit
的用法示例。
在下文中一共展示了CvUnit::AI_update方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: AI_update
// Returns true if the group has become busy...
bool CvSelectionGroupAI::AI_update()
{
CLLNode<IDInfo>* pEntityNode;
CvUnit* pLoopUnit;
bool bDead;
bool bFollow;
PROFILE("CvSelectionGroupAI::AI_update");
FAssert(getOwnerINLINE() != NO_PLAYER);
if (!AI_isControlled())
{
return false;
}
if (getNumUnits() == 0)
{
return false;
}
if (isForceUpdate())
{
clearMissionQueue(); // XXX ???
setActivityType(ACTIVITY_AWAKE);
setForceUpdate(false);
// if we are in the middle of attacking with a stack, cancel it
AI_cancelGroupAttack();
}
FAssert(!(GET_PLAYER(getOwnerINLINE()).isAutoMoves()));
int iTempHack = 0; // XXX
bDead = false;
bool bFailedAlreadyFighting = false;
while ((m_bGroupAttack && !bFailedAlreadyFighting) || readyToMove())
{
iTempHack++;
if (iTempHack > 100)
{
FAssert(false);
CvUnit* pHeadUnit = getHeadUnit();
if (NULL != pHeadUnit)
{
if (GC.getLogging())
{
TCHAR szOut[1024];
CvWString szTempString;
getUnitAIString(szTempString, pHeadUnit->AI_getUnitAIType());
sprintf(szOut, "Unit stuck in loop: %S(%S)[%d, %d] (%S)\n", pHeadUnit->getName().GetCString(), GET_PLAYER(pHeadUnit->getOwnerINLINE()).getName(),
pHeadUnit->getX_INLINE(), pHeadUnit->getY_INLINE(), szTempString.GetCString());
gDLL->messageControlLog(szOut);
}
pHeadUnit->finishMoves();
}
break;
}
// if we want to force the group to attack, force another attack
if (m_bGroupAttack)
{
m_bGroupAttack = false;
groupAttack(m_iGroupAttackX, m_iGroupAttackY, MOVE_DIRECT_ATTACK, bFailedAlreadyFighting);
}
// else pick AI action
else
{
CvUnit* pHeadUnit = getHeadUnit();
if (pHeadUnit == NULL || pHeadUnit->isDelayedDeath())
{
break;
}
resetPath();
if (pHeadUnit->AI_update())
{
// AI_update returns true when we should abort the loop and wait until next slice
break;
}
}
if (doDelayedDeath())
{
bDead = true;
break;
}
// if no longer group attacking, and force separate is true, then bail, decide what to do after group is split up
// (UnitAI of head unit may have changed)
if (!m_bGroupAttack && AI_isForceSeparate())
{
AI_separate(); // pointers could become invalid...
//.........这里部分代码省略.........
示例2: AI_update
// Returns true if the group has become busy...
bool CvSelectionGroupAI::AI_update()
{
CLLNode<IDInfo>* pEntityNode;
CvUnit* pLoopUnit;
bool bDead;
bool bFollow;
PROFILE("CvSelectionGroupAI::AI_update");
FAssert(getOwnerINLINE() != NO_PLAYER);
if (!AI_isControlled())
{
return false;
}
if (getNumUnits() == 0)
{
return false;
}
// K-Mod / BBAI
if (getActivityType() == ACTIVITY_SLEEP && !isHuman() && !getHeadUnit()->isCargo())
{
setForceUpdate(true);
}
// end
if (isForceUpdate())
{
doForceUpdate(); // K-Mod (based on old code)
}
//FAssert(!(GET_PLAYER(getOwnerINLINE()).isAutoMoves())); // (no longer true in K-Mod)
int iTempHack = 0; // XXX
bDead = false;
bool bFailedAlreadyFighting = false;
//while ((m_bGroupAttack && !bFailedAlreadyFighting) || readyToMove())
while ((AI_isGroupAttack() && !isBusy()) || readyToMove()) // K-Mod
{
iTempHack++;
if (iTempHack > 100)
{
FAssertMsg(false, "unit stuck in a loop");
CvUnit* pHeadUnit = getHeadUnit();
if (NULL != pHeadUnit)
{
if (GC.getLogging())
{
TCHAR szOut[1024];
CvWString szTempString;
getUnitAIString(szTempString, pHeadUnit->AI_getUnitAIType());
sprintf(szOut, "Unit stuck in loop: %S(%S)[%d, %d] (%S)\n", pHeadUnit->getName().GetCString(), GET_PLAYER(pHeadUnit->getOwnerINLINE()).getName(),
pHeadUnit->getX_INLINE(), pHeadUnit->getY_INLINE(), szTempString.GetCString());
gDLL->messageControlLog(szOut);
}
pHeadUnit->finishMoves();
}
break;
}
// if we want to force the group to attack, force another attack
if (AI_isGroupAttack())
{
AI_cancelGroupAttack();
groupAttack(m_iGroupAttackX, m_iGroupAttackY, MOVE_DIRECT_ATTACK, bFailedAlreadyFighting);
}
// else pick AI action
else
{
CvUnit* pHeadUnit = getHeadUnit();
//if (pHeadUnit == NULL || pHeadUnit->isDelayedDeath())
if (pHeadUnit == NULL || pHeadUnit->doDelayedDeath()) // K-Mod
{
break;
}
//resetPath();
if (pHeadUnit->AI_update())
{
// AI_update returns true when we should abort the loop and wait until next slice
FAssert(!pHeadUnit->isDelayedDeath());
break;
}
}
if (doDelayedDeath())
{
bDead = true;
break;
}
//.........这里部分代码省略.........