With the require("tile_utils.nut"), it works, but i have an other problem :
1- After the script is done, the IA crashw without error.
2-I want IA print "HQ built at" + town_id, but it don't works.
Here's my new code :
Code: Select all
require("tile_utils.nut");
class soAI extends AIController
{
function Start();
}
function soAI::Start()
{
AILog.Info("Hello, World ! Please wait, i'm creating my company...");
AICompany.SetPresidentName("Nyan Cat");
AILog.Info("President name is Nyan Cat");
if (!AICompany.SetName("TransTime")) {
local i = 2;
while (!AICompany.SetName("TransTime #" + i)) {
i = i + 1;
}
AILog.Info("My company is called TransTime");
}
BuildHQ()
}
function BuildHQ()
{
AILog.Info("Building my HQ, please wait")
local TownsNumber = AITownList();
TownsNumber.Valuate(AITown.GetPopulation);
TownsNumber.Sort(AIList.SORT_BY_VALUE, false);
TownsNumber.KeepTop(10);
TownsNumber.Valuate(function(t) { return AIBase.RandRange(100);});
TownsNumber.Sort(AIList.SORT_BY_VALUE, false);
foreach (town_id, dummy in TownsNumber) {
local list = AITileList();
local location = AITown.GetLocation(town_id);
TileUtils.AddSimmetricRectangleSafe(list, location, 25, 25);
list.Valuate(AITile.IsBuildableRectangle, 2, 2);
list.RemoveValue(0);
list.Valuate(AIMap.DistanceSquare, location);
list.Sort(AIList.SORT_BY_VALUE, true);
foreach (t, dummy in list) {
if (AICompany.BuildCompanyHQ(t)) return town_id;
}
}
AILog.Info("HQ built at" + town_id);
}
I know that town_id is not a name, but i just want the sentence to be print.