How to make the AI stop producing a unit

Asked by Mikko Merikivi

AiSet is supposed to "opposite to AiNeed, which always inserts a request, AiSet modifies the last request to the new number." However, when I modified the land attack AI script of Aleona's Tales 2.2.7 like this:
  function() return AiSet(AiWorker(), 50) end,
  function() return AiSleep(50) end,
  function() return AiSet(AiWorker(), 1) end,

and put AiDump() in the AiLandAttack() function's while loop, the resulting console information said unit-peon(0/49) even after a couple hundred cycles. The problem is that in my opinion it should be training only one worker at that point. Also, I can't find any other methods to make the AI stop producing units.

How would I go about fixing this? I need such a functionality for Battle for Mandicor to make sure the AI player will produce workers until it has the resources to upgrade its town center to a town hall and at that exact moment halt production of workers and start the upgrade.

Question information

Language:
English Edit question
Status:
Solved
For:
Stratagus Edit question
Assignee:
No assignee Edit question
Solved by:
Mikko Merikivi
Solved:
Last query:
Last reply:
Revision history for this message
Kyran Jackson (erstmap) said :
#1

You'd be better off asking this at the forums.

Revision history for this message
Mikko Merikivi (mikkommm) said :
#2

Maybe I will at some point. Also, I decided I will abandon the old branch and start again with the newest Stratagus version. The number of bugs was just too overwhelming. The question now reflects this new development.

Revision history for this message
Andre Novellino Gouvêa (andre-ng) said :
#3

I find it easier to work with AI in the format which Kyran used for his "Charge" map (i.e., without using "function () return end" and the like).

You could then have something like this:

function AiBfM()
 if (GetPlayerData(GetThisPlayer(), "TotalNumUnits") > 0) then
  AiNeed(AiCityCenter())
  AiUpgradeTo(AiBetterCityCenter())
  if (GetPlayerData(GetThisPlayer(), "UnitTypesCount", "unit-town-hall") >= 1)
   AiSet(AiWorker(), 1)
  else
   AiSet(AiWorker(), 50)
  end
 end
end

DefineAi("ai_bfm", "*", "ai_bfm", AiBfM)

Revision history for this message
Kyran Jackson (erstmap) said :
#4

Something like (I don't think you can determine player resources though):

if (player doesn't have upgraded town hall) then
  if (resources are enough) then
    upgrade town hall
  else
    build peasant
  end
end

There are a few examples in AT of the AI format I developed. The campaign missions have simple examples.

Revision history for this message
Andre Novellino Gouvêa (andre-ng) said :
#5

"GetPlayerData(GetThisPlayer(), "Resources", "gold")" and "GetPlayerData(GetThisPlayer(), "Resources", "wood")" should work for checking player resources (if that's what you meant by determining player resources), unless for some reason they don't work within AI functions.

Revision history for this message
Mikko Merikivi (mikkommm) said :
#6

Thank you, everybody. I will try these ideas when I've finished porting the game to Stratagus 2.2.7.

Revision history for this message
Mikko Merikivi (mikkommm) said :
#7

The solution is working.