PyAI

Help - Resources - Discussion
User avatar
poiuy_qwert
Posts: 548
Joined: Sun Jan 13, 2008 2:14 am

PyAI

Postby poiuy_qwert » Fri Jan 18, 2008 1:02 am

This thread is obsolete and may not be up to date. The newest version of PyAI can be downloaded in the GUI thread

Updates:
[spoiler]

Code: Select all

PyAI v0.8 (February 25, 2008):
  - Fixed incorrect "missing label" error
  - Added External Definition files
  - Unused blocks will now be discarded and give a warning
    instead of giving an error
  - Indentation changed
  - Fixed bug when not supplying bwscript.bin file when
      compiling
PyAI v0.7 (February 9, 2008):
  - Fixed and added compression to extra information (this
    means any extra information compiled with the v0.6 will
    not be decompiled, but the ai script will)
  - Fixed, added, changed stuff in the readme
  - Fixed various jumping bugs
  - Added some error reporting
PyAI v0.6 (February 6, 2008):
  - Added a compile feature to save extra information on
    your scripts (optional)
  - Fixed some minor bugs
  - Added some error reporting
PyAI v0.5 (February 3, 2008):
  - Fixed major bugs in strings using TBL formatting
  - Fixed some error reporting
  - Added the -w option to hide warnings when compiling
PyAI v0.4 (January 31, 2008):
  - Fixed upgrade/technology bug for good
  - Added external script jumps
  - More, better error reporting
  - Misc. bug fixes
  - Removed "TRG Name" stuff
PyAI v0.3 (January 24, 2008):
  - Fixed upgrade bug again
  - Fixed various other bugs
  - Some better error reporting
PyAI v0.2 (January 18, 2008):
  - Fixed the upgrades and technology bugs
  - Fixed bug where you could only only use a label name in
    one script
  - May have fixed more bugs, i dont remember
  - Added variables for shortening names (can only store
    values, no manipulations of the values)
[/spoiler]Included readme:
[spoiler]

Code: Select all

PyAI v0.8 by poiuy_qwert
------------------------
Updates:
  PyAI v0.8:
   - Fixed incorrect "missing label" error
   - Added External Definition files
   - Unused blocks will now be discarded and give a warning
      instead of giving an error
   - Indentation changed
   - Fixed bug when not supplying bwscript.bin file when
      compiling
  PyAI v0.7 (February 9, 2008):
   - Fixed and added compression to extra information (this
      means any extra information compiled with the v0.5 will
      not be decompiled, but the ai script will)
   - Fixed, added, changed stuff in the readme
   - Fixed various jumping bugs
   - Added some error reporting
  PyAI v0.6 (February 6, 2008):
   - Added a compile feature to save extra information on
      your scripts (optional)
   - Fixed some minor bugs
   - Added some error reporting
  PyAI v0.5 (February 3, 2008):
   - Fixed major bugs in strings using TBL formatting
   - Fixed some error reporting
   - Added the -w option to hide warnings when compiling
  PyAI v0.4 (January 31, 2008):
   - Fixed upgrade/technology bug for good
   - Added external script jumps
   - More, better error reporting
   - Misc. bug fixes
   - Removed "TRG Name" stuff
  PyAI v0.3 (January 24, 2008):
   - Fixed upgrade bug again
   - Fixed various other bugs
   - Some better error reporting
  PyAI v0.2 (January 18, 2008):
   - Fixed the upgrades and technology bugs
   - Fixed bug where you could only only use a label name in
      one script
   - May have fixed more bugs, i dont remember
   - Added variables for shortening names (can only store
      values, no manipulations of the values)

 PyAI uses basically the same format as all other programs in
PyMS. The only difference is that when decompiling you need 2
input files, and when compiling you need 2 output files. So
for decompiling it is:
   python PyAI.py [options] -d <aiscript.bin> <bwscript.bin> [out]
Like the other programs, if you leave [out] blank it will
make up the filename, so it will take the aiscript.bin's
filename but with the .txt extension. To compile its:
   python PyAI.py [options] -c <inp> [aiscript.bin [bwscript.bin]]
If you dont supply the files for [aiscript.bin] and/or
[bwscript.bin], it will take the filename of <inp> and use
the .bin extension ([bwscript.bin] will get 'bw' added to the
front in this situation).

Option  | Long Option  | Description
--------+--------------+---------------------------------------------------------------------------------
 -d    | --decompile  | Decompile AI's from aiscript.bin and/or bwscript.bin [default]
 -c    | --compile   | Compile AI's to an aiscript.bin and/or bwscript.bin
 -e    | --extrainfo  | Save extra info from your script (variables, label names, and information comments) [default: Off]"
 -u    | --units     | Specify your own units.dat file for unit data lookups [default: Defaultunits.dat]
 -g    | --upgrades   | Specify your own upgrades.dat file for upgrade data lookups [default: Defaultupgrades.dat]
 -t    | --techdata   | Specify your own techdata.dat file for technology data lookups [default: Defaulttechdata.dat]
 -s    | --scripts   | A list of AI Script ID's to decompile, separated by commas [default: All]
 -a    | --aiscript   | Used to signify the base aiscript.bin file to compile on top of
 -b    | --bwscript   | Used to signify the base bwscript.bin file to compile on top of
 -l    | --longlabels | Used to signify that you want decompiled scripts to use desriptive command names [default: Off]
 -x    | --stattxt   | Used to signify the stat_txt.tbl file to use [default: Defaultstat_txt.tbl]
 -r    | --reference  | When decompiling, put a reference for commands and parameters [default: Off]
 -w    | --hidewarns  | Hides any warning produced by compiling your code [default: Off]
 -f    | --deffile   | Specify an External Definition file containing variables to be used when interpreting/decompiling [default: None]

The coding in PyMS is not too much different then SCAIEdit
III's .asc3 format. The differences (:
 - For comments, instead of using semi-colons (';'), PyAI uses
   hash's ('#')
 - Commands use perenthesis ('(' and ')')  to encapsulate the
   parameters, and commas (',') to seperate them
 - Strings (used in the debug command, which works with PyMS,
   BUT NOT SCAIEdit!!!!) use TBL formatting (so use <40> for
   an open parenthesis '(', <41> for a close parenthesis
   ')', and <44> for a comma ',')
 - Block labels are in the format '--Name--' instead of ':Name'
 - Jumping now supports external script jumps. To use them, the
   format is 'AIID:Label', where AIID is the ID of the script,
   and Label is the name of the block in that AI (used like a
   normal label in any jumping command)
 - PyMS has the option to use "Descriptive" command names when
   decompiling. You can also interchange the origional commands
   with the descriptive ones anywhere in your code.
 - Instead of using script_name and script_id, there is one
   header used to start an AI Script
 - Variables can now be defined. They have overflowing types, so
   if you define a 'building' variable, it will also work for a
   'unit' variable because... buildings are units. But if you
   define a 'military' variable, it will not work as a 'building'
   because it isn't a building.
 - Information Comments can be used to save descriptions of things
   in your AI in its compiled form. They are any text within a
   pair of braces ('{' and '}')
 - External Definition files can be supplied either with the -f
   (--deffile) option, or with the 'extdef' keyword

External Definition files are files that list common variables which
can be included in any aiscript. To use them in code all you do is
place an 'extdef' line anywhere in your code like so:
   extdef <file>
You can either supply the name of a file in the same folder as the
aiscript, or a full path to a file.
Information Comments come on the same line, or directly after a
variable declaration, block label, or AI Script header. They are
completely optionally. If its on the same line it must be at the
end (but still before normal comments), and can only my a single
line information comment. Single line information comments are in
the form {<comment>}, and multi-line information comments are in
the form (The braces must be on their own lines):
   {
   <comment>
   }
Note: Variables are saved to aiscript.bin, so if you dont keep
 your aiscript.bin with your bwscript.bin when you try to
 decompile the bwscript.bin, you will not get your variables.
You can set variables anywhere in your file, inside or outside
of your ai's, it doesn't matter. The syntax for a variable is:
   <type> <name> = <value>
Type is a paramater type like 'byte', 'building', etc. You can
view the different types in the reference (Note: Labels can NOT
but set to variables).
Every AI Script in your file must start with the declaration
header, formatted like so:
   <ID>(<String>, <Flags>, <script>):
<ID> is the 4 letter ID for your script, or one of the keywords
Protoss, BWProtoss, Terran, BWTerran, Zerg, and BWZerg, which
represents PMCu, PMCx, TMCu, TMCx, ZMCu, and ZMCx respectivly.
<String> is the id number of the string in your stat_tbl.txt.
<Flags> is 3 ones or zeros (for example 000, 111, 101, 001, etc),
a 0 means a flag is unset, a 1 means a flag is set.
If the first flag is set, the AI script requires a location.
If the second flag is set, the AI script will not show up in
StarEdit. If the third flag is set, its a BW AI Script (DOES
NOT MEAN GOES IN bwscript.bin!). <script> is either the keyword
aiscript, or the keyword bwscript and defines which bin file
it is compiled to. Under that you have your commands and blocks.
Here is an example of Terran 5 - Harvest Town (Te5H):
   # stat_txt.tbl entry 1054: Terran 5 - Terran Harvest Town<0>
   Te5H(1054, 011, aiscript):
      start_campaign()
      start_areatown()
      defaultbuild_off()
      default_min(0)
      wait(1)
      build(1, Terran Command Center, 150)
      build(4, Terran SCV, 130)
         --Te5H 0000--
      wait(1500)
      goto(Te5H 0000)
[/spoiler]Extra help to get you started:
[spoiler]Ok im assuming you are one windows, if not you can skip to step 2:
  1. Download the latest Python and install it to you computer
  2. Download PyMSwithAI.zip, and unzip it to any folder you want (I recommend C:PyMS) if you havn't already done so
  3. Open the folder you extracted PyMS to. Open the file "PyAI readme.txt", it should give an overview of the stuff you need
  4. Open command prompt from either the start menu Accessories, or hitting WinKey+R and opening cmd
  5. Navigate to the PyMS folder, if you installed to C:PyMS, the command would be:
    cd C:PyMS
  6. Then use this command to use the program:
    python PyAI.py [options] <parameters>
  7. For some extra help on option formatting, use the -h option like so:
    python PyAI.py -h
Note: If you get an error saying "'python' is not recognized as an internal or external command, operable program or batch file", then python didn't install the environment variable for itself. Open command prompt and type:

Code: Select all

set PATH=%PATH%;C:Python25
Note: C:Python25 is the default installation directory, if you installed it somewhere else use that path.
For example, to decompile the two ai scripts PMCu and PMCx from the file MYaiscript.bin, to the file myai.txt the command would be:
python PyAI.py -s PMCu,PMCx MYaiscript.bin myai.txt
Then you would edit the myai.txt file to your liking, and recompile it using:
python PyAI.py -c -a MYaiscript.bin myai.txt MYaiscript.bin
To fully understand whats going on, look up what the options do (-s, -c, and -a). If you have any questions just ask.[/spoiler]Optimizing the usage of PyAI:
[spoiler]Here are a few hints to make using PyAI easier:
  1. You don't have to close the terminal you are using everytime you decompile or compile a script. Once you have opened your Terminal and located the folder with PyAI in it using the 'cd' command, leave it open until you are totally finished.
  2. If you press the Up key or Down key, you can cycle through the last command used. This makes it easy if you are constantly compiling and/or decompiling, or even just similar commands. Once you close a terminal you lose your command history (so like hint 1 said, dont close the terminal until you are totally finished).
  3. Use the Tab key to auto-complete filenames. For instance when running PyAI with the python command, you can type:
    python Py
    then hit Tab, and it will complete the line to:
    python PyAI.py
    You can use this on any file/folder that is correct.
  4. To make it so you don't have to type lots to find your file (even with Tab completion), use relative paths. The easiest relative path to type would be to just put your .bin and .txt files in the same folder as PyAI, but a more organized way would be to create a subfolder with a short name in the folder (I use just the letter 'c' as a folder name). Then you dont have to type the fill path, just the relative path. For example instead of having to do:
    C:PyAImyai.txt -or- C:PyAIcmyai.txt
    I could use the relative paths:
    myai.txt -or- cmyai.txt
[/spoiler]Optional reference printed to decompiled scripts:
[spoiler]

Code: Select all

#----------------------------------------------------
# Parameter Types:
#   label      - The block label name (Can not be used as a variable type!)
#   unit      - A unit ID from 0 to 227, or a full unit name (in the TBL, its the part before the first <0>)
#   word      - A number in the range 0 to 65535
#   byte      - A number in the range 0 to 255
#   building   - Same as Unit type, but only Buildings or Resource Miners
#   upgrade    - An upgrade ID from 0 to 60, or a full upgrade name (label in stat_txt.tbl)
#   technology  - An technology ID from 0 to 43, or a full technology name (label in stat_txt.tbl)
#   military   - Same as Unit type, but only for a unit to train (not a Building or Resource Miner)
#   gg_military - Same as Military type, but only for Ground to Ground defence
#   ag_military - Same as Military type, but only for Air to Ground defence
#   ga_military - Same as Military type, but only for Ground to Air defence
#   aa_military - Same as Military type, but only for Air to Air defence
#   string     - A string of any characters (except for nulls: <0>) in TBL string formatting (use <40> for an open parenthesis '(', <41> for a close parenthesis ')', and <44> for a comma ',')
#
# Commands:
#   goto(label)
#   notowns_jump(unit, label)
#   wait(word)
#   start_town()
#   start_areatown()
#   expand(byte, label)
#   build(byte, building, byte)
#   upgrade(byte, upgrade, byte)
#   tech(technology, byte)
#   wait_build(byte, building)
#   wait_buildstart(byte, unit)
#   attack_clear()
#   attack_add(byte, military)
#   attack_prepare()
#   attack_do()
#   wait_secure()
#   capt_expand()
#   build_bunkers()
#   wait_bunkers()
#   defensebuild_gg(byte, gg_military)
#   defensebuild_ag(byte, ag_military)
#   defensebuild_ga(byte, ga_military)
#   defensebuild_aa(byte, aa_military)
#   defenseuse_gg(byte, gg_military)
#   defenseuse_ag(byte, ag_military)
#   defenseuse_ga(byte, ga_military)
#   defenseuse_aa(byte, aa_military)
#   defenseclear_gg()
#   defenseclear_ag()
#   defenseclear_ga()
#   defenseclear_aa()
#   send_suicide(byte)
#   player_enemy()
#   player_ally()
#   default_min(byte)
#   defaultbuild_off()
#   stop()
#   switch_rescue()
#   move_dt()
#   debug(label, string)
#   fatal_error()
#   enter_bunker()
#   value_area()
#   transports_off()
#   check_transports()
#   nuke_rate(byte)
#   max_force(word)
#   clear_combatdata()
#   random_jump(byte, label)
#   time_jump(byte, label)
#   farms_notiming()
#   farms_timing()
#   build_turrets()
#   wait_turrets()
#   default_build()
#   harass_factor()
#   start_campaign()
#   race_jump(label, label, label)
#   region_size(byte, label)
#   get_oldpeons(byte)
#   groundmap_jump(label)
#   place_guard(unit, byte)
#   wait_force(byte, military)
#   guard_resources(military)
#   call(label)
#   return()
#   eval_harass()
#   creep(byte)
#   panic(label)
#   player_need(byte, building)
#   do_morph()
#   wait_upgrades()
#   multirun(label)
#   rush(byte, label)
#   scout_with(military)
#   define_max(byte, unit)
#   train(byte, military)
#   target_expansion()
#   wait_train(byte, military)
#   set_attacks(byte)
#   set_gencmd()
#   make_patrol()
#   give_money()
#   prep_down()
#   resources_jump(word, word, label)
#   enter_transport()
#   exit_transport()
#   sharedvision_on(byte)
#   sharedvision_off(byte)
#   nuke_location()
#   harass_location()
#   implode()
#   guard_all()
#   enemyowns_jump(unit, label)
#   enemyresources_jump(word, word, label)
#   if_dif()
#   easy_attack()
#   kill_thread()
#   killable()
#   wait_finishattack()
#   quick_attack()
#   junkyard_dog()
#   fake_nuke()
#   disruption_web()
#   recall_location()
#   set_randomseed(word, word)
#   if_owned(unit, label)
#   create_nuke()
#   create_unit(unit, word, word)
#   nuke_pos(word, word)
#   help_iftrouble()
#   allies_watch(byte, label)
#   try_townpoint(byte, label)
#
# Descriptive Commands:
#   Goto(label)
#   DoesntCommandGoto(unit, label)
#   Wait(word)
#   StartTownManagement()
#   StartAreaTownManagement()
#   RunCodeForExpansion(byte, label)
#   Build(byte, building, byte)
#   ResearchUpgrade(byte, upgrade, byte)
#   ResearchTechnology(technology, byte)
#   WaitUntilConstructionFinished(byte, building)
#   WaitUntilConstructionStarted(byte, unit)
#   ClearAttackData()
#   AddToAttackParty(byte, military)
#   PrepareAttackParty()
#   AttackWithAttackParty()
#   WaitForSecureUnknown()
#   CaptureExpandUnknown()
#   BuildBunkersUnknown()
#   WaitForBunkersUnknown()
#   BuildGroundToGroundDefenceUnit(byte, gg_military)
#   BuildAirToGroundDefenceUnit(byte, ag_military)
#   BuildGroundToAirDefenceUnit(byte, ga_military)
#   BuildAirToAirDefenceUnit(byte, aa_military)
#   UseForGroundToGroundDefence(byte, gg_military)
#   UseForAirToGroundDefence(byte, ag_military)
#   UseForGroundToAirDefence(byte, ga_military)
#   UseForAirToAirDefence(byte, aa_military)
#   ClearGroundToGroundDefence()
#   ClearAirToGroundDefence()
#   ClearGroundToAirDefence()
#   ClearAirToAirDefence()
#   AllUnitsSuicideMission(byte)
#   MakeSelectedPlayerEnemy()
#   MakeSelectedPlayerAlly()
#   DefaultMinUnknown(byte)
#   DefaultBuildOffUnknown()
#   StopCodeSection()
#   SwitchComputerToRescuable()
#   MoveDarkTemplarToLocation()
#   Debug(label, string)
#   CauseFatalError()
#   EnterBunker()
#   ValueThisAreaHigher()
#   DontManageOrBuildTransports()
#   UseTransportsUpToMax()
#   BuildNukes(byte)
#   MaxForceUnknown(word)
#   ClearPreviousCombatData()
#   ChanceGoto(byte, label)
#   AfterTimeGoto(byte, label)
#   BuildSupplyOnlyWhenNeeded()
#   BuildSupplyBeforeNeeded()
#   BuildTurretsUnknown()
#   WaitForTurretsUnknown()
#   DefaultBuildUnknown()
#   HarassFactorUnknown()
#   StartCampaignAI()
#   NearestRaceGoto(label, label, label)
#   EnemyInRangeGoto(byte, label)
#   MoveWorkersToExpansion(byte)
#   EnemyReachableByGroundGoto(label)
#   GuardTown(unit, byte)
#   WaitUntilCommandAmount(byte, military)
#   SendUnitsToGuardResources(military)
#   CallSubroutine(label)
#   ReturnFromSubroutine()
#   EvalHarrassUnkown()
#   PlaceTowers(byte)
#   AttackedGoto(label)
#   BuildIfNeeded(byte, building)
#   DoMorphUnknown()
#   WaitForUpgradesUnknown()
#   RunSimultaneously(label)
#   PredifinedConditionalGoto(byte, label)
#   ScoutWithUnknown(military)
#   MaxAmountOfUnit(byte, unit)
#   Train(byte, military)
#   TargetExpansionUnknown()
#   WaitUntilCommands(byte, military)
#   SetAttacksUnknown(byte)
#   SetGeneralCommandTarget()
#   MakeUnitsPatrol()
#   GiveResourcesWhenLow()
#   PrepDownUnknown()
#   ComputerHasResourcesGoto(word, word, label)
#   EnterNearestTransport()
#   ExitTransport()
#   EnableSharedVision(byte)
#   DisableSharedVision(byte)
#   NukeSelectedLocation()
#   HarassSelectedLocation()
#   ImplodeUnknown()
#   GuardAllUnknown()
#   EnemyCommandsGoto(unit, label)
#   EnemyHasResourcesGoto(word, word, label)
#   IfDifUnknown()
#   EasyAttackUnknown()
#   KillCurrentThread()
#   AllowOtherThreadsToKillCurrent()
#   WaitForAttackGroupToAttack()
#   BigAttackPrepare()
#   JunkyardDog()
#   FakeNukeUnknown()
#   DisruptionWebSelectedLocation()
#   RecallSelectedLocation()
#   SetRandomSeed(word, word)
#   IfOwnedUnknown(unit, label)
#   CreateNuke()
#   CreateUnitAtCoordinates(unit, word, word)
#   LaunchNukeAtCoordinates(word, word)
#   AskForHelpWhenInTrouble()
#   WatchAlliesUnknown(byte, label)
#   TryTownpointUnknown(byte, label)
#----------------------------------------------------
[/spoiler]
User avatar
poiuy_qwert
Posts: 548
Joined: Sun Jan 13, 2008 2:14 am

Postby poiuy_qwert » Fri Jan 18, 2008 2:40 am

Ahhh. i see the problem. you are doing -- null --, the spaces are being counted in the label name. Use --null-- and --cash--, etc.

Edit: This was pointed out later by bajadulce, he put a space between the debug command and its parameters.
User avatar
modmaster50
Posts: 72
Joined: Tue Oct 16, 2007 1:47 am

Postby modmaster50 » Fri Jan 18, 2008 2:41 am

So his block name was " null "? No wonder!
User avatar
poiuy_qwert
Posts: 548
Joined: Sun Jan 13, 2008 2:14 am

Postby poiuy_qwert » Fri Jan 18, 2008 2:51 am

Yes it was. I just updated the attachment so leading and trailing spaces in block labels are no longer kept, so these are the same:
--null--
-- null --
User avatar
poiuy_qwert
Posts: 548
Joined: Sun Jan 13, 2008 2:14 am

Postby poiuy_qwert » Fri Jan 18, 2008 5:57 am

Ugh, found the bug, forgot a to minus 1 from a value :S A fix with new variable support will come out soon.

Note: This bug effects upgrades and techs till i update it
User avatar
modmaster50
Posts: 72
Joined: Tue Oct 16, 2007 1:47 am

Postby modmaster50 » Fri Jan 18, 2008 11:00 pm

[quote name='poiuy_qwert' post='2141' date='Jan 18 2008, 12:57 AM']Ugh, found the bug, forgot a to minus 1 from a value :S A fix with new variable support will come out soon.

Note: This bug effects upgrades and techs till i update it[/quote]

Ohmygod! So upgrades and techs are screwed over in current version? Minus one from something? How would you compile a script correctly on the current version then?
User avatar
poiuy_qwert
Posts: 548
Joined: Sun Jan 13, 2008 2:14 am

Postby poiuy_qwert » Fri Jan 18, 2008 11:02 pm

The first post is updated, forgot to post a reply stating that. Just redownload.

Return to “PyMS (poiuy_qwert's complete modding suite)”

Who is online

Users browsing this forum: No registered users and 1 guest