• 🏆 Texturing Contest #33 is OPEN! Contestants must re-texture a SD unit model found in-game (Warcraft 3 Classic), recreating the unit into a peaceful NPC version. 🔗Click here to enter!
  • It's time for the first HD Modeling Contest of 2024. Join the theme discussion for Hive's HD Modeling Contest #6! Click here to post your idea!

AI Building several Town Halls

Status
Not open for further replies.
Level 16
Joined
Apr 20, 2014
Messages
522
Hello,

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
Joined
Sep 28, 2011
Messages
968
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 28
Joined
Feb 18, 2014
Messages
3,578
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 common.ai file by adding this condition to TownCountEx function :
JASS:
    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 16
Joined
Apr 20, 2014
Messages
522
Thank you for your replies.


For noob, here an extract of my code:
JASS:
    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:
JASS:
    if (( ( GetUnitCount( 'h62X' ) == 0 ) and ( GetUnitCount( 'h62Y' ) == 0 ) )) then
        call SetBuildUnit( 1, 'h62W' )  // TOWN HALL DALARAN
    endif

// 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.
 
Status
Not open for further replies.
Top