• 🏆 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] AI Building Expansion Bases

Status
Not open for further replies.
Level 18
Joined
Mar 16, 2008
Messages
721
What is correct way to make AIs expand? This function seems to cause the game to crash intermittently but why? I thought the crash was related to the AI trying to expand to islands but it seems it still crashes even with no islands.

This is from the GUI build expansion town:
JASS:
//===========================================================================
function ExpansionNeeded takes nothing returns boolean
    return take_exp
endfunction

//===========================================================================
function BuildExpansion takes integer hallID, integer mineID returns nothing
    if (HallsCompleted(hallID)) then
        call SetBuildExpa( TownCount(hallID) + 1, mineID )
    endif
endfunction

from the api manual:
JASS:
function SetBuildExpa takes integer qty, integer unitid returns nothing
    call SetBuildAll(BUILD_EXPAND,qty,unitid,-1)
endfunction

When you call this function, within BuildPriorities, it seems to enable like a smart expand setting. It keeps taking gold mines as they are available, which is exactly as desired. However it seems to cause a crash intermittently for unknown reasons.
JASS:
call BuildExpansion (TOWN_HALL, TOWN_HALL)

So I added a limiting condition, which seems to prevent the crashing. I've only tested a few times though, without human-player interference:
JASS:
globals
    boolean                 gCond_Need_Town_Hall       = false
endglobals

JASS:
function UpdateConditions takes nothing returns nothing
    set gCond_Need_Town_Hall = ( (GetUnitCount(TOWN_HALL)) < 2 )
endfunction

JASS:
function BuildPriorities takes nothing returns nothing
    ...
    if gCond_Need_Town_Hall then
        call BuildExpansion (TOWN_HALL, TOWN_HALL)
    endif
    ...
endfunction

So I guess the problem is solved in some sense. However I still have some concerns:
1) What is the proper way to make an AI expand? When you just have the AI build a town hall, without this system above, it builds the town hall in useless spot. The above functions seems to make it build near a gold mine.
2) What if a player takes one of the AI's expansions, then the AI tries to take another expansion, which might crash the game? It's unclear exactly what causes the crash still.

 

Dr Super Good

Spell Reviewer
Level 63
Joined
Jan 18, 2005
Messages
27,191
You might need to provide a demonstration map. Using standard melee data and quickly made terrain would suffice as long as the crash is reproduced reliably. Few Warcraft III modders have gone into the depths of the AI and all its quirks.

If you can recreate this problem with the melee AI then it could be an internal Warcraft III bug. If the melee AI does not have this problem then it could be that there is an explicit fix for it in their code.
 
Level 18
Joined
Mar 16, 2008
Messages
721
can't seem to really re-create the crash in a simple demonstration map. so i'm leaning on the side that it's something to do with my slop, as much as i'd like to blame Reforged. then again i'm not really sure what i'm trying to re-create because I haven't fully identified the crash cause in my spaghetti plate - all i know is that the AI crashes when trying to build a 3rd or sometimes 4th expansion.

i'm just going to put a condition limiting it to two and give up for the time being. i don't want to waste any more time on this at the expense of adding other features to the map. most players don't even choose to add ai players and prefer human players anyway.
 
Status
Not open for further replies.
Top