• 🏆 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 Not Running

Status
Not open for further replies.
So I've been reading a tutorial to make my own AI for a campaign map but I can't get it to run. I pretty much know next to nothing about AI so I have no idea what I'm doing wrong. I was told to check the syntax with JassCraft, but that program is giving me an endless list of errors when I try to run it so no-can-do there. Any help is appreciated.

I call the AI on map init.
  • Initialisaton
    • Events
      • Map initialization
    • Conditions
    • Actions
      • Game - Set the time of day to 12.00
      • Visibility - Disable fog of war
      • Visibility - Disable black mask
      • Player - Set Player 10 (Light Blue) Current gold to 1000
      • Player - Set Player 10 (Light Blue) Current lumber to 1000
      • -------- -------- --------
      • Set TempPlayer = Player 4 (Purple)
      • Player - Set TempPlayer Current gold to 999999
      • Player - Set TempPlayer Current lumber to 999999
      • Visibility - Create an initially Enabled visibility modifier for TempPlayer emitting Visibility across (Playable map area)
      • AI - Start campaign AI script for TempPlayer: war3mapImported\AR_MAP1.ai
      • Set TempPlayer = Player 6 (Orange)
      • Player - Set TempPlayer Current gold to 999999
      • Player - Set TempPlayer Current lumber to 999999
      • Visibility - Create an initially Enabled visibility modifier for TempPlayer emitting Visibility across (Playable map area)
      • AI - Start campaign AI script for TempPlayer: war3mapImported\AR_MAP1.ai
The AI.
JASS:
globals

    //CONFIG
    player     HUMAN_PLAYER    = Player(9) //Player 10

    integer       TOWN_HALL_1     = 'unpl'
    integer       TOWN_HALL_2     = 'unp1'
    integer    TOWN_HALL_3     = 'unp2'

    //Where do I find a list of the AI constants?
    integer       WORKER_1           = 'uaco'    //Eg:     Peasant                 Acolyte                    Wisp                    Peon
    integer       WORKER_2           = 'ugho'    //Eg:     -                        Ghoul                    -                        -
    integer       FOOD_SOURCE     = 'uzig'    //Eg:    Farm                    Ziggurat                Moon Well                Burrow
    integer       ALTAR           = 'uaod'    //Eg:    Altar of Kings            Altar of Darkness        Altar of Elders            Altar of Storms
    integer       SPECIAL_1       = '0000'    //Eg:     Lumber Mill                -                        -                        -
    integer       SPECIAL_2       = 'usap'    //Eg:     -                        Sacrificial Pit            -                        -
    integer       TECH            = 'ugrv'    //Eg:     Blacksmith                 Graveyard                Hunter's Hall            War Mill
    integer       SHOP            = 'utom'    //Eg:     Arcane Vault             Tomb of Relics            Ancient of Wonders        Voodoo Lounge
    integer       DEFENSE_1       = 'uzg1'    //Eg:     Guard Tower             Spirit Tower            Ancient Protector        Watch Tower
    integer       DEFENSE_2       = '0000'    //Eg:     Cannon Tower            -                        -                        -
    integer       DEFENSE_3       = '0000'    //Eg:     Arcane Tower            -                        -                        -
    integer       PRODUCTION_1       = 'usep'    //Eg:     Barracks (Human)        Crypt                     Ancient of War            Barracks (Orc)
    integer       PRODUCTION_2       = 'utod'    //Eg:     Arcane Sanctum             Temple of the Damned    Ancient of Lore            Spirit Lodge
    integer       PRODUCTION_3       = 'uslh'    //Eg:     Workshop                  Slaughterhouse            Ancient of Wind            Beastiary
    integer       PRODUCTION_4       = 'ubon'    //Eg:     Gryphon Aviary             Boneyard                 Chimera Roost            Tauren Totem
    //ENDCONFIG

endglobals


function ConfigureAI takes nothing returns nothing
    call SetUnitsFlee( false )
    call SetHeroesFlee( false )
    call SetGroupsFlee( false )
    call SetSlowChopping( true )
    call SetPeonsRepair( true )
    call DoCampaignFarms( false )
    call GroupTimedLife( true )
endfunction


function main takes nothing returns nothing
  
    call CampaignAI( FOOD_SOURCE, null )
    call ConfigureAI()

    // **********************************
    // *      Building Strategy         *
    // **********************************
  
    call SetReplacements( 3, 5, 6 )
    set campaign_gold_peons = 5
    set campaign_wood_peons = 4

    //    Tier 1
    call SetBuildUnitEx( 1, 1, 1, TOWN_HALL_1 )
    call SetBuildUnit( 10, WORKER_1 )
    call SetBuildUnit( 4, WORKER_2 )
    call SetBuildUnitEx( 1, 2, 3, FOOD_SOURCE )
    call SetBuildUnit( 1, PRODUCTION_1 )
    call SetBuildUnit( 1, ALTAR )
    call SetBuildUnit( 1, TECH )
    call CampaignDefenderEx( 2, 3, 5, GHOUL)
    call CampaignDefenderEx( 1, 2, 3, CRYPT_FIEND)
    call CampaignDefenderEx( 0, 1, 1, ABOMINATION)
    call CampaignDefenderEx( 1, 1, 2, NECROMANCER)
    call CampaignDefenderEx( 0, 1, 1, OBSIDIAN_STATUE)
    call CampaignDefenderEx( 2, 2, 2, DEFENSE_1)
  
    //    Tier 2
    call SetBuildUnit( 1, TOWN_HALL_2 )
    call SetBuildUnit( 1, PRODUCTION_2 )
    call SetBuildUnit( 1, PRODUCTION_3 )
  
    // Tier 3 buildings
    call SetBuildUnit(1, TOWN_HALL_3)
    call SetBuildUnitEx(0, 1, 1, PRODUCTION_4)
  
    // **********************************
    // *    End Building Strategy       *
    // **********************************

    //*** Wave 1 ***
    call InitAssaultGroup()
    call CampaignAttackerEx( 3, 3, 4, GHOUL )
    call CampaignAttackerEx( 0, 1, 2, CRYPT_FIEND )
    call SuicideOnPlayerEx( M5, M4, M4, HUMAN_PLAYER )

    //*** Wave 2 ***
    call InitAssaultGroup()
    call CampaignAttackerEx( 3, 3, 4, GHOUL )
    call CampaignAttackerEx( 1, 2, 3, CRYPT_FIEND )
    call SuicideOnPlayerEx( M4, M4, M3, HUMAN_PLAYER )

    //*** Wave 3 ***
    call InitAssaultGroup()
    call CampaignAttackerEx( 3, 3, 4, GHOUL )
    call CampaignAttackerEx( 0, 1, 2, CRYPT_FIEND )
    call CampaignAttackerEx( 0, 1, 1, MEAT_WAGON )
    call SuicideOnPlayerEx( M3, M4, M3, HUMAN_PLAYER )

    //*** Wave 4 ***
    call InitAssaultGroup()
    call CampaignAttackerEx( 3, 3, 4, GHOUL )
    call CampaignAttackerEx( 1, 1, 2, CRYPT_FIEND )
    call CampaignAttackerEx( 1, 1, 2, GARGOYLE )
    call CampaignAttackerEx( 0, 1, 1, MEAT_WAGON )
    call SuicideOnPlayerEx( M3, M4, M3, HUMAN_PLAYER )

    loop
  
        //*** Wave 5 ***
        call InitAssaultGroup()
        call CampaignAttackerEx( 2, 2, 3, GHOUL )
        call CampaignAttackerEx( 1, 1, 2, CRYPT_FIEND )
        call CampaignAttackerEx( 1, 1, 2, GARGOYLE )
        call CampaignAttackerEx( 0, 1, 1, ABOMINATION )
        call CampaignAttackerEx( 0, 1, 1, MEAT_WAGON )
        call SuicideOnPlayerEx( M4, M4, M4, HUMAN_PLAYER )

        //*** Wave 6 ***
        call InitAssaultGroup()
        call CampaignAttackerEx( 2, 2, 3, GHOUL )
        call CampaignAttackerEx( 1, 1, 2, NECROMANCER )
        call CampaignAttackerEx( 1, 1, 2, OBSIDIAN_STATUE )
        call CampaignAttackerEx( 0, 1, 1, ABOMINATION )
        call CampaignAttackerEx( 0, 1, 1, MEAT_WAGON )
        call SuicideOnPlayerEx( M4, M4, M4, HUMAN_PLAYER )

        //*** Wave 7 ***
        call InitAssaultGroup()
        call CampaignAttackerEx( 5, 7, 12, GARGOYLE )
        call SuicideOnPlayerEx( M4, M4, M4, HUMAN_PLAYER )

    endloop

endfunction
 

Jampion

Code Reviewer
Level 15
Joined
Mar 25, 2016
Messages
1,327
First go to JassCraft options (f8) and select Jass Enchantments. Then you will see in the left a field "Native Files". You need to check common.j common.ai and blizzard.j.
For you common.ai was probably unchecked, hence all the syntax errors.
After you have done that you should only have one syntax error left:
apparently it's NECRO, not NECROMANCER and then it hopefully works.
 
I think there was a misunderstanding. I can't use JassCraft because the program is giving me a lot of errors on start up. I haven't had the chance to run the ai through it yet. I'll try re-downloading JassCraft and see if I can get it to run again.

I'll change the NECRO thing.

EDIT: Changing NECROMANCER to NECRO finally made the AI work, but I have 4 questions:

1) How to I made preplaced units stay put and not be controlled by the AI?
2) How do I tell the AI I want 4 Ghouls on lumber
3) Is JassCraft 1.13 compatible with the latest wc3 patches?
4) Is there another way/program I can use that will syntax-check my AIs?
 
Last edited:

Jampion

Code Reviewer
Level 15
Joined
Mar 25, 2016
Messages
1,327
Just like Nowow said, I would take a look at the common.ai. It's also in the jasscraft folder.

In one of the main AI triggers campaign_gold_peons and campaign_wood_peons are used.

JASS:
    ...
    if CaptainInCombat(false) then
        set on_wood = 0
    else
        set on_wood = campaign_wood_peons
    endif

    call HarvestGold(0,campaign_gold_peons)
    call HarvestWood(0,on_wood)

    if harvest_town1 then
        call HarvestGold(1,campaign_gold_peons)
        call HarvestWood(1,on_wood)
    endif
    ...

HarvestGold/Wood takes the town index and the number of workers. You can see, that for every town the same number of workers is assigned: campaign_gold_peons / campaign_wood_peons
This is only for campaign AIs though: the function CampaignAI starts this behaviour

In a trigger created by the AI editor, it is handled differently:
The main trigger starts a thread, that periodically runs a function, which assigns the workers correctly for every town by using the function HarvestPriorities. This function is automatically created by the AI editor depending on the harvest priorities you specified.

So to sum it up: read common.ai, look at ai scripts created by blizzard (AI editor or campaigns), HarvestGold/Wood is the final function used to assign workers for a resource. If you used the function CampaignAI this will be periodically set to campaign_gold_peons/ campaign_wood_peons for every town. You can overwrite this again (and have different values for different towns), if you always call a function directly after that.

I am not sure everything I said is correct. This is just what I learned from quickly looking through the related functions in common.ai and a random AI created by the AI editor.

I hope this helps, I am also not familiar with AI and I don't know the answers for the other questions.
 
Level 12
Joined
Jun 15, 2016
Messages
472
1. That depends on where you want those units to stay put. You can just have the AI built the units and issue no order. However, from my experience such units are automatically assigned to the defense group, meaning they will stay in a certain designated location and will only move to defend the town, or if they are assigned to an attack group.

There is another solution I am less versed with: The AI has a functionality called guard posts.
JASS:
native AddGuardPost         takes integer id, real x, real y            returns nothing
You choose a unit type id and XY coordinates and the AI will send a unit there for good, so the unit should stay put and move only when aggro'ed. Moreover, the AI has a unit replacement function: once the unit at the guard post has been killed, the AI will replace it a set number of times (a default of 3 times).

There's even a little something extra with it: you might not have known this, but for the AI script all preplaced and trigger generated units (except for builders maybe) are considered guard posts, and will be rebuilt and replaced once the original unit died. To remove this effect, you can use this action for a single unit
  • Unit - Create 1 Fel Orc Grunt for Player 5 (Yellow) at (Center of Mid Orc 01 <gen>) facing 180.00 degrees
  • AI - Ignore (Last created unit)'s guard position
or a different action for all units matching certain conditions.

2. As Jampion said, the amount of wood harvesting units is handled internally by the function CampaignAI. In order to change the amount, set the global variable campaign_wood_peons to the number you want in the main function. You shouldn't declare this variable, it's already done when the common.ai file is compiled to the map. I will add a little note though: ghouls are a bit tricky because they are fighting units as well as harvesters, so they will stop harvesting and attack when the town is under attack, and should you decide to create an attack group with ghouls, wood harvesting ghouls stop harvesting and go to the attack group, the AI is just stupid that way.

You can have the AI build extra ghouls whenever you want to attack with them so 4 ghouls will stay and harvest at the base, if it's really important to you.

I'm sure there's a better solution but I've yet to find one...

3. Compatible how? If you're worried about changes to the common.ai file over the years, don't. It had barely changed.

4. I'm not aware of any way. You can do a partial check like this:
  • create a new trigger and convert it to custom text.
  • copy-paste your AI script to that trigger.
  • Save the map.
You will receive an error message, and if that message says "redeclared function main" or something, that means JASShelper didn't find an error in your script. That doesn't mean there isn't an error, but it's a good sign. If you get a different error message, then check it out. (If you don't receive an error message then I have no idea what's wrong with your map).

Now that I actually looked at your script, I think the problem is that you order 4 ghouls to harvest, but your AI script creates only 2,3 ghouls on easy/normal. Try calling call SetBuildUnit( 7, 'ugho' ) in the main function and see how many harvesting ghouls you have.
 
Lot of good info to go through here. I'll definitely try the AddGuardPost function and make the AI build more Ghouls.

I'm still at a loss with JassCraft though. When I launch it it tells me Did not find blizzard.j file in MPQ! and then it's an endless repetition of Access violation at address 00560060 in module 'JassCraft.exe'. Read of address 00000004.
 
Status
Not open for further replies.
Top