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

Simple setup for scripting Warcraft 3 maps in C

Level 8
Joined
Aug 1, 2023
Messages
34

Getting the tools​

  • gcc or clang or msvc or some other program that can type check C code
  • cjc
  • pjass
  • mpqeditor
You might already have gcc or clang or msvc on your computer. You can find that out by running the where gcc command in a terminal/console.
After you've downloaded all the tools, you have to make a map in your favorite WorldEditor. Now you can write the script for your map in C (mostly, and some Jass2). Then you can build your map (so that the war3.exe can actually run it) using the following batch script:

PHP:
@echo off

rem we assume that gcc or clang or msvc are in our PATH environment variable
set typecheckGcc=gcc -m32 -Wall -Wextra -Wconversion -fsyntax-only
rem set typecheckClang=clang -m32 -Wall -Wextra -Wconversion -fsyntax-only
rem set typecheckMsvc=cl -nologo -W2 -Zs main.c
set commonj="path\to\common.j"
set blizzardj="path\to\blizzard.j"
set pjass="path\to\pjass.exe"
set cjc="path\to\cjc.exe"
set mpqeditor="path\to\mpqeditor.exe"

rem type check our C code
%typecheckGcc% main.c
if 0 neq %errorlevel% (
  exit /b %errorlevel%
)

rem run the C to Jass2 compiler
%cjc% -o a.j -callcode main.c runtime.j
if 0 neq %errorlevel% (
  exit /b %errorlevel%
)

rem type check our Jass2 code
%pjass% %commonj% %blizzardj% a.j
rem it is okay for pjass to complain about some of the type casting functions in runtime.j
rem if 0 neq %errorlevel% (
rem   exit /b %errorlevel%
rem )

rem make a copy of the map and only modify the copy
copy map.w3x m.w3x

rem add the generated Jass2 code to the map
%mpqeditor% add m.w3x a.j war3map.j

rem try loading m.w3x in the game

The reason that gcc or clang or msvc are needed is because cjc doesn't do type checking. The reason pjass is needed is because the C code needs to call functions written in Jass2.

You could also try loading the map from a batch script by reading this guide (using the -loadfile command line option of war3.exe).

Maybe a bit too simple​

This setup might be a bit too simple. Maps that need to use the WorldEditor for placing units, cameras, regions, etc. would need to parse the data from the map archive and generate C code. You can read about the format of the files found in an .w3x map here. mpqeditor can be used to extract files from an .w3x archive. The command path\to\mpqeditor.exe extract map.w3x war3map.w3r . would extract the file war3map.w3r (regions) to the current directory.
 
Top