AI Building several Town Halls

Level 12
Apr 20, 2014

For my campaign project, I created new buildings for an ally. I am using JASS to create AI and it's very simple orders.

However, each time my ally upgrades its Town Hall to a Keep, it builds an additionnal Town Hall. Same with Castle. So at the end, it has a Town Hall, a Keep & a Castle in the same base.
I think its a Known Issue, but is there a way to solve with directly in JASS?

Thanks in advance,
Level 14
Sep 28, 2011
It seems that according to this description it is trying to fill building requirements and that the keep does not counts as a town hall for its imagined building requirements.
Which ai system do you use?
Melee ais does not have this problem.
Some files(ex: the ai scripts) would probably help to understand.
Level 27
Feb 18, 2014
I don't know how to do it in JASS AI but in the AI Editor you just need to add this condition to the first tier building (Town Hall)

((Total number of Town Hall units) Equal to 0 and (((Total number of Keep units) Equal to (Total number of Town Hall units)) and ((Total number of Castle units) Equal to (Total number of Keep units))))

Alternatively, or if you don't want to repeat this condition every time you create an AI. You can edit the file by adding this condition to TownCountEx function :
    elseif unitid == TOWN_HALL then
        set have_qty = have_qty + GetUnitCountEx(KEEP,false,townid) + GetUnitCountEx(CASTLE,false,townid)
    elseif unitid == KEEP then
        set have_qty = have_qty  + GetUnitCountEx(CASTLE,false,townid)
Simply, replace Town Hall, Keep and Castle with your custom buildings.
Level 12
Apr 20, 2014
Thank you for your replies.

For noob, here an extract of my code:
    call SetBuildUnit( 1, 'h62W' ) // TOWN HALL DALARAN
    call SetBuildUnit( 5, 'h62V' )  // PEASANT DALARAN
    call SetBuildUnit( 2, HOUSE )
    call SetBuildUnit( 1, 'halt' )
    call SetBuildUnit( 1, 'Hamg' )
    call SetBuildUnit( 2, 'h62T' )// BARRACKS DALARAN
    call SetBuildUnit( 4, HOUSE )
    call SetBuildUnit( 10, 'h62V' )
    call SetBuildUnit( 5, HOUSE )
    call SetBuildUnit( 1, LUMBER_MILL )
    call SetBuildUnit( 1, BLACKSMITH )
    call SetBuildUnit( 8, HOUSE )
    call SetBuildUnit( 1, 'hvlt')
    // Tier 2 buildings
    call SetBuildUnit( 1, 'h62X' )    // KEEP DALARAN
    call SetBuildUnit( 2, 'h62U' ) // SANCTUM DALARAN
    call SetBuildUnit( 17, HOUSE )
    call SetBuildUnit( 5, 'hwtw' )
    call SetBuildUnit( 2, 'hgtw' )
    call SetBuildUnit( 3, 'hatw' )
    // Tier 3 buildings
    call SetBuildUnit( 1, 'h62Y' ) // Castle
    call SetBuildUnit( 1, 'h62Z' ) // MAGIC SPIRE

So with classic buildings, it builds everything correctly, since the Town Hall becomes a Keep, etc.
But with custom buildings, it rebuild a new Town Hall because Keep is not the same model.

With your advice, I added a condition directly in the AI file:
    if (( ( GetUnitCount( 'h62X' ) == 0 ) and ( GetUnitCount( 'h62Y' ) == 0 ) )) then
        call SetBuildUnit( 1, 'h62W' )  // TOWN HALL DALARAN

// With h62X = Keep and h62Y = Castle.
// Basically, it don't rebuild a Town Hall if there is a Keep or a Castle.
// It can't work with expansion, but it's a Campaign AI so it's not needed.

It works properly now. Thank you.