相关代码在AI\core\AIcode.xs;大概你也能看得懂
//============================================================================== // ShouldIResign //============================================================================== rule ShouldIResign minInterval 7 inactive { // Don't resign during treaty since that looks dumb. // Don't resign too soon. // Don't resign if we have over 30 active pop slots. if ((aiTreatyActive() == true) || (kbGetPop() >= 30) || (xsGetTime() < 10 * 60 * 1000)) { return; }
bool humanAlly = false; // Set true if we have a surviving human ally. // Look for human allies. for (i = 1; <= cNumberPlayers) { if ((kbIsPlayerAlly(i) == true) && (kbHasPlayerLost(i) == false) && (kbIsPlayerHuman(i) == true)) { humanAlly = true; // Don't return just yet, let's see if we should chat. } }
// Resign if the known enemy pop is > 10x mine. int enemyPopTotal = 0; int enemyCount = 0; int myPopTotal = 0;
for (i = 1; < cNumberPlayers) { if (kbHasPlayerLost(i) == false) { if (i == cMyID) { myPopTotal += kbUnitCount(i, cUnitTypeUnit, cUnitStateAlive); } if (kbIsPlayerEnemy(i) == true) { enemyPopTotal += kbUnitCount(i, cUnitTypeUnit, cUnitStateAlive); enemyCount++; } } }
if (enemyCount < 1) { enemyCount = 1; // Avoid div by 0. }
float enemyRatio = (enemyPopTotal / enemyCount) / myPopTotal;
// My pop is 1/3 the average known pop of enemies so I'm going to whine to my human ally. if ((enemyRatio > 3) && (humanAlly == true)) { sendStatement(cPlayerRelationAllyExcludingSelf, cAICommPromptToAllyImReadyToQuit); xsEnableRule("resignRetry"); xsDisableSelf(); return; // Never resign if we still have a human ally. } // My pop is 1/4 the average known pop of enemies. // I have no TC. // I have no human ally that I want to stay in the game for so try to resign. if ((enemyRatio > 4) && (kbUnitCount(cMyID, cUnitTypeAgeUpBuilding, cUnitStateAlive) < 1) && (humanAlly == false)) { debugCore("Attempting to resign since I'm heavily outnumbered and have no Town Center left"); aiAttemptResign(cAICommPromptToEnemyMayIResign); xsDisableSelf(); } }
|