HomeUser Control Panel (unavailable in archive)ForumsTutorialsArt GalleryResourcesMaps

Command Parser

04-08-2007, 03:55 AM#1
wyrmlord
A program that will parse a map file for functions with special commands. These commands, such as Spell_Effect, will tell the parser to have that function called whenever a spell effect starts with a specified id. Here's the commands:
Collapse JASS:
//! Spell_Cast 'rwcd'
//! Spell_Effect 'rwcd'
//! Spell_Endcast 'rwcd'
//! Spell_Finish 'rwcd'

//! Order_Object orderid
//! Order_Point orderid
//! Order_Instant orderid

//! OnInit

The first 4 commands are called whenever a spell with rawcode 'rwcd' is cast/effect/endcast/finish. The rawcode can be written with or without the ' marks around the id, but I'd suggest keeping the ' marks.

The second 3 commands are called whenever an order is given with the specified orderid. An orderid, for those who don't know, is a 6-digit integer representing a specific order such as berserk, attack, etc.

All that leaves now is the OnInit command. Any function with this will be called when the map is initialized.

For all of these functions, make sure the function takes nothing and returns nothing that one or more of these commands are placed in.

Here's an example of using a command:
Collapse JASS:
function Cool_Spell takes nothing returns nothing
    //! Spell_Effect 'A000'
    call Some_Other_Function(GetSpellAbilityUnit())
endfunction

The commands can be placed anywhere in the function, you can even have 2+ commands in a function. However, I would suggest placing all the commands on the lines right after the function declaration.

Now, for implementing the system. I would suggest also using grimoire along with JassHelper so it can automatically be called when the map is being saved. If you don't want to do it this way, I've included SFmpq.dll if you want to use it separately. In order to use this with JassHelper and Grimoire, a few things must be done first. First you must add this program to the mapcompiler.conf file. You need to change the file like so. See where the text for the CommandParse tool is located? Copy that line somewhere below the comments after [externaltools].

Code:
[externaltools]
// this is for //! external NAME args the syntax is "NAME","executable path"
// example:
//"OBJMERGE","c:\kool.exe"
"CommandParse","bin\CommandParse.exe"

Now, you'll need to place the CommandParse.exe file inside Grimoire's bin folder (so it has access to SFmpq.dll). Lastly, you'll need to copy the Func.j file into the directory where the mapcompiler.exe file is.

There's just one last thing you need to do before this program will parse your map. Somewhere in the map's script, you must put the text //! external CommandParse This let's JassHelper know to call the CommandParse program by its configurations in the mapcompiler.conf file.

This program has not yet been tested, so I can't say that it works (but I'm not saying it doesn't work). I have, however, tested for any JASS syntax errors. If you have any suggestions, I'll be glad to hear them.
Attached Files
File type: zipCommandParse.zip (76.3 KB)