• 🏆 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!

[AI] Spirit Tower troubles`

Status
Not open for further replies.
Level 2
Joined
Jul 29, 2004
Messages
12
Hello.

I have googled and checked around here. Nothing. My problem is that the AI builds Ziggaurats but seems not to arm them to Spirit Towers. Nerubians are fine but will have plenty of gold and not build spirit towers. When I have played Undead I can build them fine.

What part of the Jass script can I look for to "force" it to build STs or can I do it with Triggers.

Thanks in advance.
 
Level 13
Joined
Nov 22, 2006
Messages
1,260
I don't know AI, but you can do it with triggers:

  • SpiritTowerUpgr
  • Events
    • Unit - A unit begins upgrading a research
  • Conditions
    • Techtree type of research is equal to Nerubian Tower
    • Triggering unit is controlled by AI (this does not exist, I'm just stating what you need to do)
  • Actions
    • Unit - somehow stop the Nerubian Tower research
    • Unit - somehow order the ziggurat to research to Spirit Tower

This will make the Spirit Tower upgrade research every time Nerubian Tower was supposed to. If you want to add a chance, for example 15% that the Spirit Tower will research instead of Nerubian, just add a condition:

  • Random integer between 1 and 100 Less than or equal to 15

Or you can check if the player can afford to build upgrade to Spirit Tower.

EDIT: Or if there is no "cancel" order, you can use custom script: IssueImmediateOrderById(GetTriggerUnit(), 851796)
 
Level 5
Joined
Oct 27, 2007
Messages
158
Hello.

I have googled and checked around here. Nothing. My problem is that the AI builds Ziggaurats but seems not to arm them to Spirit Towers. Nerubians are fine but will have plenty of gold and not build spirit towers. When I have played Undead I can build them fine.

What part of the Jass script can I look for to "force" it to build STs or can I do it with Triggers.

Thanks in advance.

In Jass it's quite simle to order the AI to always make spirit towers. Just be sure to order the AI to make Ziggurats first and then upgrade them to Spirit Towers. The following will build one Ziggurat and then upgrade it to a Spirit Tower.

call SetBuildUnit(1, ZIGGURAT_1)
call SetBuildUnit(1, ZIGGURAT_2)

If you want to have x quantity Spirit Towers then be sure to order the AI to make x quantity Ziggurats first.

FYI

ZIGGURAT_1 = Ziggurat
ZIGGURAT_2 = Spirit Tower

Those globals are from common.ai and can be used in any custom AI script.
 
Level 2
Joined
Jul 29, 2004
Messages
12
Thanks guys.

Now it has been a good while so let me remember on screen here. . .
If I want to use JASS I can create the custom script in the Trigger area or will I actually alter the common.ai file. I would much rather make this a global "rule" if you will so let me know what is the best way to do that.

Thanks again for the responses.
 
Level 5
Joined
Oct 27, 2007
Messages
158
Thanks guys.

Now it has been a good while so let me remember on screen here. . .
If I want to use JASS I can create the custom script in the Trigger area or will I actually alter the common.ai file. I would much rather make this a global "rule" if you will so let me know what is the best way to do that.

Thanks again for the responses.

I assume you want all the Undead AI's to use the same global rule of building Spirit Towers. All those AI's are running individual scripts I assume or multiple instances of the same script? If the latter then all you need to do is include the building strategy I mentioned for Ziggurats and Spirit Towers. If the scripts are different then you need to include that building strategy in every script.

Another solution to the different AI scripts is making a custom script in your map and send commands to the individual AI scripts. You can order all those scripts to build a set amount of Ziggurats and Spirit Towers. For this to have optimal effect, you'd have to put your building strategy in a seperate thread in all the AI scripts. That way you can control through triggers how and when the AI starts to build something.

JASS:
globals
constant real thread_cycle = 1
constant real basics_cycle = 3
constant integer BUILD_SPIRIT_TOWERS = 1

integer need = 0
boolean quantity_set = false
endglobals

function ProcessCommands takes nothing returns nothing
local integer cmd
local integer data

loop
    loop
        exitwhen CommandsWaiting() == 0
        set cmd = GetLastCommand()
        set data = GetLastData()
        call PopLastCommand()
        if cmd == BUILD_SPIRIT_TOWERS then
            set need = 5
            set quantity_set = true
        endif
    endloop
    call Wait(thread_cycle)
endloop
endfunction

function TownBasics takes nothing returns nothing
loop
     call InitBuildArray()
     call SetBuildAll(BUILD_UNIT, 1, ACOLYTE, -1)
     call SetBuildAll(BUILD_UNIT, 1, NECROPOLIS_1, -1)
     call SetBuildAll(BUILD_UNIT, 1, UNDEAD_MINE, -1)
     // Don't rely on the AI to build campaign farms, because it's bugged.
     // It will build excess farms over the max food supply which're useless.
     // Better is to handle this in your own building strategy thread.
     // Set do_campaign_farms to false
     call SetBuildAll(BUILD_UNIT, 1, ZIGGURAT_1, -1)
     call SetBuildAll(BUILD_UNIT, 1, CRYPT, -1)
     call SetBuildAll(BUILD_UNIT, 1, GRAVEYARD, -1)
     call SetBuildAll(BUILD_UNIT, 5, ACOLYTE, -1)
     call SetBuildAll(BUILD_UNIT, 4, GHOUL, -1)
     if quantity_set then
         call SetBuildAll(BUILD_UNIT, need, ZIGGURAT_1, -1)
         call SetBuildAll(BUILD_UNIT, need, ZIGGURAT_2, -1)
     endif
     // Rest of the building strategy comes here
     // Best is to configure basics_cycle to be 1+ seconds.
     call Sleep(basics_cycle)
endloop
endfunction

This is just a quick example of how you could create such a thread. This is just one way of doing it. The idea is to send an AI command through a map trigger and have a command processing function in your AI script. The command processing function will then set quantity_set when it received the command for building need amount Spirit Towers. In the main function you have to start these functions as threads and do other stuff necessary there for your AI.
 
Last edited:
Status
Not open for further replies.
Top