Code: Select all
function AroAI::BuildHQ() //from Rondje
{
if(AIMap.IsValidTile(AICompany.GetCompanyHQ(AICompany.COMPANY_SELF))) return;//from simpleai
// Find biggest town for HQ
local towns = AITownList();
towns.Valuate(AITown.GetPopulation);
towns.Sort(AIAbstractList.SORT_BY_VALUE, false);
local town = towns.Begin();
// Find empty 2x2 square as close to town centre as possible
local maxRange = Sqrt(AITown.GetPopulation(town)/100) + 5; //TODO check value correctness
local HQArea = AITileList();
HQArea.AddRectangle(AITown.GetLocation(town) - AIMap.GetTileIndex(maxRange, maxRange),
AITown.GetLocation(town) + AIMap.GetTileIndex(maxRange, maxRange));
HQArea.Valuate(AITile.IsBuildableRectangle, 2, 2);
HQArea.KeepValue(1);
HQArea.Valuate(AIMap.DistanceManhattan, AITown.GetLocation(town))
HQArea.Sort(AIList.SORT_BY_VALUE, true);
for (local tile = HQArea.Begin(); HQArea.IsEnd(); tile = HQArea.Next())
{
if (AICompany.BuildCompanyHQ(tile))
{AISign.BuildSign(tile, "AroAI HQ");
return;
}
}
Code: Select all
for (local tile = HQArea.Begin(); HQArea.IsEnd(); tile = HQArea.Next())
Code: Select all
HQArea.IsEnd()
Code: Select all
HQArea.HasNext()
the trouble is that whenever my ai runs now, it always fails to build an HQ
any comments?
i'm a real beginner at this, but i am learning, so please be patient

hope this makes some sort of sense,
EDITS: topic name change