Tutorial 2: Upgrades

Now we need to tell the AI to research the upgrades, preferably in parallel with building and training. First let us write the forge upgrade code:


...(a)...
wait_build 2 forge
upgrade 1 p_ground_weapon 70
upgrade 1 p_plasma_shield 70
wait 2700
wait_build 1 cybernetics_core
upgrade 1 p_armor 70
upgrade 2 p_plasma_shield 70
wait 3600
wait_build 1 templar_archives
upgrade 2 p_ground_weapon 70
upgrade 3 p_plasma_shield 70
wait 4500
upgrade 3 p_ground_weapon 70
upgrade 2 p_armor 70
wait 4500
upgrade 3 p_armor 70
...(b)...


Forget about the (a) and (b) for now. Let's concentrate on the new upgrade and wait commands. The upgrade command let's the AI research an upgrade to level 1, 2 or 3 at a priority, 70 in this case. The wait command is necessary to make sure the AI does not start researching a new upgrade until the last has finished. This is very important, because otherwise the game will crash. Also note that each successive upgrade takes longer to research. By building 2 forges we have the luxury of being able to research up to 2 upgrades at a time. We included two additional "wait_build" commands to make sure the researching is continued as the required buildings are constructed.

In order to research these upgrades in parallel we must change the upgrade code into a seperate piece of code:


(a) -> :r_groundupgrades
...
(b) -> stop


By replacing (a) with a unique identifier (we should not forget the : ) and (b) with a stop command we completed our forge upgrades piece of code. Note that the r_ in the identifier name is not necessary, but, personally, I think it looks better ;). The stop command is needed to make sure the script doesn't go beyond the last upgrade. It is very important not to forget the stop command.

The question is now: How do we use the research code in our previous script file? We can include the research (and make it run in parallel) in our script by adding the following 2 lines at the start of our script:


; === START ===
build 1 nexus 150
wait_build 1 nexus
build 4 probe 130
wait_build 4 probe

; --- RESEARCH
multirun r_groundupgrades

build 5 probe 80
wait_buildstart 5 probe


and placing the research code at the bottom of our file (after the "goto repeatrush" line). The multirun command runs the ground upgrades code in parallel with the buildup. By using a lower priority (i.e. 70 vs 80), we make sure the research doesn't slow down our buildup.


Protoss Upgrades 1
An upgraded archon wreaking havoc amongst its enemies ;)





Now that we have learned about the multirun command, let's continue to the next page, where we get to use the goto command to create easier to manage, cleaner code.








Previous Back to Index Next