TOP WC2 Websites


serverwar2ru.jpg

war2me.png

PVPGN

WC2 Editing Tools


PUDDraft

WarDraft

WinMPQ

 


Facebook Site

YouTube Channel

Skype: thinkshareguy

This article is about the computer enemies in WarCraft 2. We're talking about the AI which means "artificial intelligence". So, in WarCraft 2 we can play with a lot of different AI's. But how do they work? Let me tell you some facts about them.

I want that you fully understand how do they work. After that mission is completed you know how to create and play with new own AI's. Its a process.
1. The AI code
#include aidefs.inc

Program:
build nothing          ; build nothing
reset_land             ; reset land attack trigger
reset_water            ; reset naval attack trigger
reset_air              ; reset air attack trigger
strat_on               ; ? strategy on ?
aggr_low               ; ? low aggressiveness ?
build townhall         ; Town Hall
peasants     = 36      ; set # Peasants
build barracks         ; Barracks
footmen      = 4       ; set # Footmen
ptys_land    = 1       ; set number of land attack parties
size_land    = 4       ; set size of land attack party
wait_land              ; wait until land attack parties are complete
size_land    = 1       ; set size of land attack party
attk_land              ; start land attack
sleep 360
build barracks         ; Barracks
build barracks         ; Barracks
footmen      = 6       ; set # Footmen
ptys_land    = 1       ; set number of land attack parties
size_land    = 6       ; set size of land attack party
wait_land              ; wait until land attack parties are complete
size_land    = 2       ; set size of land attack party
attk_land              ; start land attack
build lumbermill       ; Lumber mill
build blacksmith       ; Blacksmith
build tower            ; Scout Tower
build tower            ; Scout Tower
upgrd up_keep          ; upgrade Townhall to Keep
upgrd up_footmen_A1    ; Footman,Knight upgrade A (1/2)
upgrd up_arrow_1       ; Arrow upgrade (1/2)
footmen      = 9       ; set # Footmen
ptys_land    = 1       ; set number of land attack parties
size_land    = 9       ; set size of land attack party
wait_land              ; wait until land attack parties are complete
size_land    = 3       ; set size of land attack party
attk_land              ; start land attack
wait_keep              ; wait until you have a Keep
...
The code is just a list of commands for the computer enemie. You can tell him what he should build and upgrade. You also can include a break with the "sleep" command. In this time the computer wont do anything but collecting gold, wood, oil and repair his buildings. You can set the size and type of attacking groups. The opponent doesn't need commands to build farms. He does this automatically, as required. You can't determine where to place his building. There is an invisible grid for the game. This grid provides at least two fields distance between his buildings. The major exception are farms. That's why he often blocked up the way to a gold mine accidentally. His soldiers and workers stand in the way and then don't move. Then nothing happens and the opponent can't run further commands from the AI. You could attack and destroy / kill some of his stuff to make empty room. His units will move again. This let the AI code continue for the moment. Until everything is blocked again. For some reason the computer places his soldiers right at the main hall. That soldier armys + farms + peons + not enough room for moving = bullshit. The only way to fix that is with map design.
2. AI compatible mapping
I show you what i mean with map design. Its about the start position of the computer enemie. I tried that on many different maps. Its everytime the same.
This is a bad start position design for computers. Maybe you think he has enough room but thats wrong.
Bad design for computer start position
The computer will create something like this. The workers can't deliver. So the AI don't continue with any further commands. You could attack him and kill some of his units but thats not the best solution.
Bad design for computer start position
Now here's the good design for the start positon! You notice there is more dirt arround the start position. You know thats not possible to build on dirt. But you can walk over it. The computer enemy has enough room to place the main hall.
Good design for computer start position
Take a look at this. The computer cant't build the farms arround the main hall. The invisible grid doesn't work because of the dirt. He can place his army there and the workers continue thier delivery. There is enough room for all units. The computer AI can continue with its commands.
Good design for computer start position
Now you see how important the start position design is when you play against computer enemies. Your AI code can be good as hell but without the correct map design it won't work like you want.
3. Modify the AI code
Allright then. You know some basic things about AI now. Where do you can find the AI data exactly? Let me answer this question with some screenshots from WarDraft and WinMPQ.

In the old WarCraft 2 DOS version you have a file named "MAINDAT.WAR". In the WarCraft 2 Battle.net Edition or Combat Edition you have the "War2Dat.mpq". The AI codes are saved in these archives. I show you how to open them and get the AI file for editing / replacing.
3a. WarDraft, MAINDAT.WAR and file #277
That program is a must for AI editing. It doesnt only open the old "MAINDAT.WAR". It also includes the AI editor / compiler. You can download WarDraft by clicking here from my website! But! You dont need the "MAINDAT.WAR" file for working with the AI editor! You will understand later why.
I guess you dont play with the old DOS version of WarCraft 2, right? Okay. But let me show you some things. Its good to know for basic understanding about the AI. I start WarDraft and open the "MAINDAT.WAR". After that i load the knowledge base. Thats good because you get the descriptions with it. So you can see what all those things are. The following screenshots show you where the AI codes are placed. Its the entry number 277.
WarDraft
WarDraft
WarDraft
WarDraft
WarDraft
WarDraft
I extracted that file 277 and start the AI editor from the Tools menu. Then i load the 277 file with it. (Use the load button and use the file 277. Not direct load!)  Now you can edit the AI code. That tool also includes a pretty good helpfile. There are many informations about using the editor.
AI Editor
AI Editor
AI Editor
AI Editor
WarDraft
So. What happens in this editor? First you get the source code from the AI file. You can export and edit that with the compiler. I export the AI code and edit it with N++. A really good text editor. Then i go back and load the new code with the compiler. I compile the code. Then i replace the old land attack AI with my new custom compiled code. I save the AI file. Now i can re-import the AI file (277) into the "MAINDAT.WAR". I start the game and play on a map against the new computer AI. In the map editor you can set which AI the computer shall use. Land attack, Sea attack, Air attack or passive. But these are just names. You can replace them all with your own AI codes. You could write an AI code which attacks with land, air and sea in one! Just replace the old land attack AI and set your map correct. There you go.
3b. WinMPQ, War2dat.mpq and rez\ai.bin
You play with the WarCraft 2 Battle.net Edition or the Combat Edition? Good. Then you find the "War2Dat.mpq" file in your game directory. This file is the new "MAINDAT.WAR". Understand? "War2Dat.mpq = MAINDAT.WAR". Okay. To get and replace the AI code here you need the tool WinMPQ. Download here! Start it, set the knowledge list and open the "War2Dat.mpq". Make a backup of that file first. Scroll down and you see the entry "rez\ai.bin". This is the AI code file here. That means file "rez\ai.bin" = "277". The mpq is kind of zip/rar archive. It contains subdirectories. Like "rez". You can use the AI editor from WarDraft to load the ai.bin and edit it. Its the same file. You can edit it and replace the old "rez\ai.bin". Delete the old ai.bin first and the add the new one. Its very important that you write it with the directory like in the screenshot below - rez\.
WinMPQ
WinMPQ
WinMPQ
WinMPQ
WinMPQ
WinMPQ
AI.bin and 277
So. Now you have a War2Dat.mpq with a new AI code inside. You can play against it like before. Just get a good map for it. I always have 2 different files in my directory. The normal and the AI mod. You can play against the AI with other people online. Using any gateway like war2.ru or warlords-of-warcraft2.com. But! Every player in that match needs exactly the same AI mod in his War2Dat.mpq. Then it works. When i want play with the new AI online i rename my files. The original file then is "War2Dat_Original.mpq" and the other (AI modified) "War2Dat.mpq". After playing i change it back and name the AI modified file "War2Dat_AI.mpq". Understand? Just change the filename when you want play against the new AI you made or got from another place like my website.
War2Dat.mpq
4. Lets play now!
You could try some new AI codes from my website now. I created them for you. Here is all you need:

The first step will be the AI code file for your War2Dat.mpq. Download new AI code here! I replaced the landattack, airattack, seaattack and passive AI codes in it. You can look at these codes by yourself:
Landattack
Seaattack
Airattack
Passive
 
I modified 2 maps from my collection for it. In both maps everyone is starting with 5000 gold/wood/oil.

1. Download: No-Hide-Times_1v1.pud
Here you play against the landattack AI (with ogre mages but no deathknights or dragons). It doesnt use deathknights/dragons but everything else. Play defensive and look how it goes.

2. Download: Ultra-Wartime_4v4.pud
This map is made for a big battle. North vs South. Play it online and dont forgett that every player needs the same AI code in his "War2dat.mpq"! The host has to use map settings. Make your allies at the very beginning of the match. You play against 4 computers. 2x landattack AI (with magic ogres), 1x landattack AI without any magic and 1x airattack AI with landattack (no magic).

You can play offline in a "1 player v 1 computer" match or find 3 other players to make a "4 real players vs 4 computers" battle online. If everyone has the same War2dat.mpq including the correct AI code you can play on war2.ru or warlords-of-warcraft2.com Battle.net gateways.

Now lets have some fun and rock these new computer enemies hard!