- UID
- 290177
- 阅读权限
- 30
- 注册时间
- 2017-3-13
- 最后登录
- 2024-10-19
- 在线时间
- 51 小时
- 性别
- 保密
男爵
- 耕战
- 10
- 鹰币
- 60
- 天龙币
- 0
- 回帖
- 47
|
发表于 2017-12-29 13:28:30
|
显示全部楼层
把下面这个复制粘贴到你的游戏安装目录下的AI3文件里,再进游戏就会发现AI基地被摧毁后在资源采集范围内重新建立基地
rule shouldIMigrate
inactive
minInterval 10
group startup
{
int armySize = aiPlanGetNumberUnits(gLandDefendPlan0, cUnitTypeLogicalTypeLandMilitary) + aiPlanGetNumberUnits(gLandReservePlan, cUnitTypeLogicalTypeLandMilitary);
int enemyArmySize = -1;
bool migrate = false;
static int enemyArmyQuery = -1;
if (enemyArmyQuery < 0)
{ // Initialize the queryID
enemyArmyQuery = kbUnitQueryCreate("Enemy army query");
kbUnitQuerySetIgnoreKnockedOutUnits(enemyArmyQuery, true);
kbUnitQuerySetPlayerRelation(enemyArmyQuery, cPlayerRelationEnemyNotGaia);
kbUnitQuerySetUnitType(enemyArmyQuery, cUnitTypeLogicalTypeLandMilitary);
kbUnitQuerySetState(enemyArmyQuery, cUnitStateAlive);
kbUnitQuerySetSeeableOnly(enemyArmyQuery, true); // Ignore units we think are under fog
}
// Check main base first
kbUnitQuerySetPosition(enemyArmyQuery, kbBaseGetLocation(cMyID, kbBaseGetMainID(cMyID)));
kbUnitQuerySetMaximumDistance(enemyArmyQuery, cvDefenseReflexSearchRadius);
kbUnitQuerySetSeeableOnly(enemyArmyQuery, true);
kbUnitQuerySetState(enemyArmyQuery, cUnitStateAlive);
kbUnitQueryResetResults(enemyArmyQuery);
enemyArmySize = kbUnitQueryExecute(enemyArmyQuery);
if (enemyArmySize >= 2)
{
// Enemy army size at least 3x my size and more than 30 units total. Thus, we migrate
if ( ((armySize * 3.0) < enemyArmySize) && (enemyArmySize > 30) )
{ // Too big to handle
xsEnableRule("createNewBase");
}
}
}
//相关参数设定
bool findACompletedTownCenter()
{
bool retVal = false;
static int townCenterQuery = -1;
if (townCenterQuery < 0)
{
townCenterQuery=kbUnitQueryCreate("Completed Town Center Query");
kbUnitQuerySetIgnoreKnockedOutUnits(townCenterQuery, true);
}
//Define the query
if (townCenterQuery != -1)
{
kbUnitQuerySetPlayerRelation(townCenterQuery, -1);
kbUnitQuerySetPlayerID(townCenterQuery, cMyID);
kbUnitQuerySetUnitType(townCenterQuery, cUnitTypeTownCenter);
kbUnitQuerySetState(townCenterQuery, cUnitStateAny);
kbUnitQuerySetAscendingSort(townCenterQuery, true); // Ascending distance from initial location
}
else
return(retVal);
// Run the query
kbUnitQueryResetResults(townCenterQuery);
int count = kbUnitQueryExecute(townCenterQuery);
int tcID = kbUnitQueryGetResult(townCenterQuery, 0);
if (tcID >=0)
retVal = true;
return(retVal);
}
//建造新基地
rule createNewBase
inactive
minInterval 5
{
// First, create a query if needed, then use it to look for a completed town center
static int townCenterQuery = -1;
if (townCenterQuery < 0)
{
townCenterQuery=kbUnitQueryCreate("Completed Town Center Query");
kbUnitQuerySetIgnoreKnockedOutUnits(townCenterQuery, true);
}
//Define the query
if (townCenterQuery != -1)
{
kbUnitQuerySetPlayerRelation(townCenterQuery, -1);
kbUnitQuerySetPlayerID(townCenterQuery, cMyID);
kbUnitQuerySetUnitType(townCenterQuery, cUnitTypeTownCenter);
kbUnitQuerySetState(townCenterQuery, cUnitStateAlive);
}
// Run the query
kbUnitQueryResetResults(townCenterQuery);
int count = kbUnitQueryExecute(townCenterQuery);
if (count < 1)
return;
for (i=0; < count)
{
int tcID = kbUnitQueryGetResult(townCenterQuery, i);
aiEcho("New TC is "+tcID+" at "+kbUnitGetPosition(tcID));
}
if (findACompletedTownCenter() == true)
{
int tcBase = kbUnitGetBaseID(tcID);
gMainBase = kbBaseGetMainID(cMyID);
aiEcho(" TC base is "+tcBase+", main base is "+gMainBase);
// We have a TC. Make sure that the main base exists, and it includes the TC
if ( gMainBase < 0 )
{ // We have no main base, create one
gMainBase = createMainBase(kbUnitGetPosition(tcID));
aiEcho(" We had no main base, so we created one: "+gMainBase);
}
tcBase = kbUnitGetBaseID(tcID); // in case base ID just changed
if ( tcBase != gMainBase )
{
aiEcho(" TC "+tcID+" is not in the main base ("+gMainBase+".");
aiEcho(" Setting base "+gMainBase+" to non-main, setting base "+tcBase+" to main.");
kbBaseSetMain(cMyID, gMainBase, false);
aiRemoveResourceBreakdown(cResourceFood, cAIResourceSubTypeEasy, gMainBase);
aiRemoveResourceBreakdown(cResourceFood, cAIResourceSubTypeHuntAggressive, gMainBase);
aiRemoveResourceBreakdown(cResourceFood, cAIResourceSubTypeFish, gMainBase);
aiRemoveResourceBreakdown(cResourceFood, cAIResourceSubTypeFarm, gMainBase);
aiRemoveResourceBreakdown(cResourceWood, cAIResourceSubTypeEasy, gMainBase);
aiRemoveResourceBreakdown(cResourceGold, cAIResourceSubTypeEasy, gMainBase);
kbBaseSetMain(cMyID, tcBase, true);
gMainBase = tcBase;
}
}
else
return;
}
//建造其它TC
rule createOtherTC
inactive
minInterval 5
{
// British explorer to build 1 additional TC
if ((cMyCiv == cCivBritish) && (cvOkToBuild == true))
{
createSimpleBuildPlan(cUnitTypeTownCenter, 2, 90, true, cEconomyEscrowID, kbBaseGetMainID(cMyID), 1);
aiEcho("Starting build plan for an additional British town center");
}
// French explorer to build 1 additional TC
if ((cMyCiv == cCivFrench) && (cvOkToBuild == true))
{
createSimpleBuildPlan(cUnitTypeTownCenter, 2, 90, true, cEconomyEscrowID, kbBaseGetMainID(cMyID), 1);
aiEcho("Starting build plan for an additional French town center");
}
// Spanish explorer to build 2 additional TCs
if ((cMyCiv == cCivSpanish) && (cvOkToBuild == true))
{
createSimpleBuildPlan(cUnitTypeTownCenter, 2, 90, true, cEconomyEscrowID, kbBaseGetMainID(cMyID), 1);
aiEcho("Starting build plan for an additional Spanish town center");
}
// Russians explorer to build 2 additional TCs
if ((cMyCiv == cCivRussians) && (cvOkToBuild == true))
{
createSimpleBuildPlan(cUnitTypeTownCenter, 2, 90, true, cEconomyEscrowID, kbBaseGetMainID(cMyID), 1);
aiEcho("Starting build plan for an additional Russians town center");
}
// Germans explorer to build 2 additional TCs
if ((cMyCiv == cCivGermans) && (cvOkToBuild == true))
{
createSimpleBuildPlan(cUnitTypeTownCenter, 2, 90, true, cEconomyEscrowID, kbBaseGetMainID(cMyID), 1);
aiEcho("Starting build plan for an additional Germans town center");
}
// Dutch explorer to build 2 additional TC
if ((cMyCiv == cCivDutch) && (cvOkToBuild == true))
{
createSimpleBuildPlan(cUnitTypeTownCenter, 2, 90, true, cEconomyEscrowID, kbBaseGetMainID(cMyID), 1);
aiEcho("Starting build plan for an additional Portuguese town center");
}
// Ottoman explorer to build 1 additional TC
if ((cMyCiv == cCivOttomans) && (cvOkToBuild == true))
{
createSimpleBuildPlan(cUnitTypeTownCenter, 2, 90, true, cEconomyEscrowID, kbBaseGetMainID(cMyID), 1);
aiEcho("Starting build plan for an additional Ottoman town center");
}
// Sioux explorer to build 2 additional TCs
if ((cMyCiv == cCivXPSioux) && (cvOkToBuild == true))
{
createSimpleBuildPlan(cUnitTypeTownCenter, 2, 90, true, cEconomyEscrowID, kbBaseGetMainID(cMyID), 1);
aiEcho("Starting build plan for an additional Sioux town center");
}
// Iroquois explorer to build 1 additional TC
if ((cMyCiv == cCivXPIroquois) && (cvOkToBuild == true))
{
createSimpleBuildPlan(cUnitTypeTownCenter, 2, 90, true, cEconomyEscrowID, kbBaseGetMainID(cMyID), 1);
aiEcho("Starting build plan for an additional Iroquois town center");
}
// Aztec explorer to build 1 additional TC
if ((cMyCiv == cCivXPAztec) && (cvOkToBuild == true))
{
createSimpleBuildPlan(cUnitTypeTownCenter, 2, 90, true, cEconomyEscrowID, kbBaseGetMainID(cMyID), 1);
aiEcho("Starting build plan for an additional Aztec town center");
}
// Chinese explorer to build 2 additional TCs
if ((cMyCiv == cCivChinese) && (cvOkToBuild == true))
{
createSimpleBuildPlan(cUnitTypeTownCenter, 2, 90, true, cEconomyEscrowID, kbBaseGetMainID(cMyID), 1);
aiEcho("Starting build plan for an additional Chinese town center");
}
// Japanese explorer to build 1 additional TC
if ((cMyCiv == cCivJapanese) && (cvOkToBuild == true))
{
createSimpleBuildPlan(cUnitTypeTownCenter, 2, 90, true, cEconomyEscrowID, kbBaseGetMainID(cMyID), 1);
aiEcho("Starting build plan for an additional Japanese town center");
}
// Indians explorer to build 1 additional TC
if ((cMyCiv == cCivIndians) && (cvOkToBuild == true))
{
createSimpleBuildPlan(cUnitTypeTownCenter, 2, 90, true, cEconomyEscrowID, kbBaseGetMainID(cMyID), 1);
aiEcho("Starting build plan for an additional Indians town center");
}
}
//变更主基地
rule ChangeBase
active
minInterval 5
//group startup
{
if(kbGetAge()<cAge4)
return;
static int lastchangebaseTime=0;
if(kbBaseGetMainID(cMyID)<0)
{
xsEnableRule("createNewBase");
return;}
else
{
if((xsGetTime()-lastchangebaseTime)>300000)
{
static int townCenterQuery = -1;
if (townCenterQuery < 0)
{
townCenterQuery=kbUnitQueryCreate("Completed Town Center Query");
kbUnitQuerySetIgnoreKnockedOutUnits(townCenterQuery, true);//去掉重复结果?
}
//Define the query
if (townCenterQuery != -1)
{
kbUnitQuerySetPlayerRelation(townCenterQuery, -1);//查询关系?
kbUnitQuerySetPlayerID(townCenterQuery, cMyID);
kbUnitQuerySetUnitType(townCenterQuery, cUnitTypeTownCenter);
kbUnitQuerySetState(townCenterQuery, cUnitStateAlive);//查询状态?
}
// Run the query
kbUnitQueryResetResults(townCenterQuery);//重置结果。
int count = kbUnitQueryExecute(townCenterQuery);//执行查询,得到数量。
if (count < 1)
return;
for (i=0; < count)
{
int tcID = kbUnitQueryGetResult(townCenterQuery, i);//得到结果。
aiEcho("New TC is "+tcID+" at "+kbUnitGetPosition(tcID));//“kbUnitGetPosition”获取位置?
}
int tcBase = kbUnitGetBaseID(tcID);
gMainBase = kbBaseGetMainID(cMyID);
aiEcho(" TC base is "+tcBase+", main base is "+gMainBase);
// We have a TC. Make sure that the main base exists, and it includes the TC
if ( gMainBase < 0 )
{ // 我们要新建一个基地。
gMainBase = createMainBase(kbUnitGetPosition(tcID));
aiEcho(" We had no main base, so we created one: "+gMainBase);
}
tcBase = kbUnitGetBaseID(tcID); // in case base ID just changed
if ( tcBase != gMainBase )
{
aiEcho(" TC "+tcID+" is not in the main base ("+gMainBase+".");
aiEcho(" Setting base "+gMainBase+" to non-main, setting base "+tcBase+" to main.");
kbBaseSetMain(cMyID, gMainBase, false);
aiRemoveResourceBreakdown(cResourceFood, cAIResourceSubTypeEasy, gMainBase);
aiRemoveResourceBreakdown(cResourceFood, cAIResourceSubTypeHuntAggressive, gMainBase);
aiRemoveResourceBreakdown(cResourceFood, cAIResourceSubTypeFish, gMainBase);
aiRemoveResourceBreakdown(cResourceFood, cAIResourceSubTypeFarm, gMainBase);
aiRemoveResourceBreakdown(cResourceWood, cAIResourceSubTypeEasy, gMainBase);
aiRemoveResourceBreakdown(cResourceGold, cAIResourceSubTypeEasy, gMainBase);
kbBaseSetMain(cMyID, tcBase, true);
gMainBase = tcBase;
}
lastchangebaseTime=xsGetTime();
}
}
} |
|