That is a great idea, thanks! This version includes this idea, handles next game mechanics change (loan, negative bank balance and bankruptcy) and fixes situation where money spending was interrupted.
Code: Select all
function _SuperLib_Money::BurnMoney()
{
AICompany.SetLoanAmount(AICompany.GetMaxLoanAmount());
local empty_tile = null;
while(true)
{
for(local i = 0; i < 1000; i++)
{
empty_tile = _SuperLib_Tile.GetRandomTile();
if(AITile.IsBuildable(empty_tile))
{
while(true)
{
if(!AITile.DemolishTile(empty_tile))
{
if(AIError.GetLastError() == AIError.ERR_NOT_ENOUGH_CASH) {
return;
}
break;
}
if(!AITile.PlantTree(empty_tile))
{
if(AIError.GetLastError() == AIError.ERR_NOT_ENOUGH_CASH) {
return;
}
break;
}
}
}
}
AIController.Sleep(500);
}
}
Note:
Code: Select all
/*
* Wastes money (may be used to ensure bankruptcy)
* Note that this function will probably not return until your AI
* has wasted all its money.
may now be
Code: Select all
/*
* Wastes money (may be used to ensure bankruptcy)
as it always will waste all money before returning.
EDIT: It would be a good idea to add documentation of returned value to BuildNextToRoad (it seems to be null on failure, tile index of constructed structure on success).
EDIT2: I just discovered that Squirrell includes enums -
http://www.squirrel-lang.org/doc/squirrel2.html#d0e925 (what seems a proper solution for "what" parameter in BuildNextToRoad)