globals

//  © 2006-2008 Author: Toadcop All rights reserved.         
//################################################################################################
//##     B U R A N X       V A R I A B L E S     by Toadcop                                     ##
//################################################################################################

// Fast Temp vars
    integer                 echolp                = 0
    integer                 ax                    = 0
    string                  sx                    = null
    real                    rx                    = 0
    boolean                 bx                    = false
    unit                    ux                    = null
    timer                   tx                    = null
    item                    ix                    = null
    effect                  ex                    = null
    group                   gx                    = null
    integer                 eax                    = 0
    integer                 eax2                   = 0
    integer                 eax3                   = 0
    string                  esx                    = null
    real                    erx                    = 0
    boolean                 ebx                    = false
    unit                    eux                    = null
    timer                   etx                    = null
    item                    eix                    = null
    effect                  eex                    = null
    group                   egx                    = null
    integer                 eaxx                    = 0
    string                  esxx                    = null
    real                    erxx                    = 0
    boolean                 ebxx                    = false
    unit                    euxx                    = null
    timer                   etxx                    = null
    item                    eixx                    = null
    effect                  eexx                    = null
    group                   egxx                    = null
    
	boolean                 dbg                     =false 

    //hashtable               trs_chars               =null

multiboarditem tmpmbi=null	 
location tmploc=null
real tmplocZ=0
// XDG
integer array Xgroup   
integer XMaxg = 0
integer array XFreegroup
integer XMaxFreeg = 0
integer XMaxs = 0
integer array XFreeslots
integer XMaxFrees = 0
unit array Xgunits
integer array XMaxCount
integer array XLastIndex
integer array XPrevIndex
integer array XNextIndex
gamecache XDG=null

// local global vars

integer      eax00=0
integer      eax01=0
integer      eax02=0
integer      eax03=0
integer      eax04=0
integer      eax05=0
integer      eax06=0
integer      eax07=0
integer      eax08=0
integer      eax09=0
integer      eax10=0
integer      eax11=0
integer      eax12=0
integer      eax13=0
integer      eax14=0
integer      eax15=0
integer      eax16=0
integer      eax17=0
integer      eax18=0
integer      eax19=0
integer      eax20=0
integer      eax21=0
integer      eax22=0
integer      eax23=0
integer      eax24=0
integer      eax25=0
integer      eax26=0
integer      eax27=0
integer      eax28=0
integer      eax29=0
integer      eax30=0
integer      eax31=0
integer      eax32=0
real      erx00=0
real      erx01=0
real      erx02=0
real      erx03=0
real      erx04=0
real      erx05=0
real      erx06=0
real      erx07=0
real      erx08=0
real      erx09=0
real      erx10=0
real      erx11=0
real      erx12=0
real      erx13=0
real      erx14=0
real      erx15=0
real      erx16=0
real      erx17=0
real      erx18=0
real      erx19=0
real      erx20=0
real      erx21=0
real      erx22=0
real      erx23=0
real      erx24=0
real      erx25=0
real      erx26=0
real      erx27=0
real      erx28=0
real      erx29=0
real      erx30=0
real      erx31=0
real      erx32=0
unit      eux00=null
unit      eux01=null
unit      eux02=null
unit      eux03=null
unit      eux04=null
unit      eux05=null
unit      eux06=null
unit      eux07=null
unit      eux08=null
unit      eux09=null
unit      eux10=null
unit      eux11=null
unit      eux12=null
unit      eux13=null
unit      eux14=null
unit      eux15=null
unit      eux16=null
unit      eux17=null
unit      eux18=null
unit      eux19=null
unit      eux20=null
unit      eux21=null
unit      eux22=null
unit      eux23=null
unit      eux24=null
unit      eux25=null
unit      eux26=null
unit      eux27=null
unit      eux28=null
unit      eux29=null
unit      eux30=null
unit      eux31=null
unit      eux32=null
string      esx00=null
string      esx01=null
string      esx02=null
string      esx03=null
string      esx04=null
string      esx05=null
string      esx06=null
string      esx07=null
string      esx08=null
string      esx09=null
string      esx10=null
string      esx11=null
string      esx12=null
string      esx13=null
string      esx14=null
string      esx15=null
string      esx16=null
string      esx17=null
string      esx18=null
string      esx19=null
string      esx20=null
string      esx21=null
string      esx22=null
string      esx23=null
string      esx24=null
string      esx25=null
string      esx26=null
string      esx27=null
string      esx28=null
string      esx29=null
string      esx30=null
string      esx31=null
string      esx32=null
boolean      ebx00=false
boolean      ebx01=false
boolean      ebx02=false
boolean      ebx03=false
boolean      ebx04=false
boolean      ebx05=false
boolean      ebx06=false
boolean      ebx07=false
boolean      ebx08=false
boolean      ebx09=false
boolean      ebx10=false
boolean      ebx11=false
boolean      ebx12=false
boolean      ebx13=false
boolean      ebx14=false
boolean      ebx15=false
boolean      ebx16=false
boolean      ebx17=false
boolean      ebx18=false
boolean      ebx19=false
boolean      ebx20=false
boolean      ebx21=false
boolean      ebx22=false
boolean      ebx23=false
boolean      ebx24=false
boolean      ebx25=false
boolean      ebx26=false
boolean      ebx27=false
boolean      ebx28=false
boolean      ebx29=false
boolean      ebx30=false
boolean      ebx31=false
boolean      ebx32=false
trigger      etrgx00=null
trigger      etrgx01=null
trigger      etrgx02=null
trigger      etrgx03=null
trigger      etrgx04=null
trigger      etrgx05=null
trigger      etrgx06=null
trigger      etrgx07=null
trigger      etrgx08=null
trigger      etrgx09=null
trigger      etrgx10=null
trigger      etrgx11=null
trigger      etrgx12=null
trigger      etrgx13=null
trigger      etrgx14=null
trigger      etrgx15=null
trigger      etrgx16=null
trigger      etrgx17=null
trigger      etrgx18=null
trigger      etrgx19=null
trigger      etrgx20=null
trigger      etrgx21=null
trigger      etrgx22=null
trigger      etrgx23=null
trigger      etrgx24=null
trigger      etrgx25=null
trigger      etrgx26=null
trigger      etrgx27=null
trigger      etrgx28=null
trigger      etrgx29=null
trigger      etrgx30=null
trigger      etrgx31=null
trigger      etrgx32=null
timer      etx00=null
timer      etx01=null
timer      etx02=null
timer      etx03=null
timer      etx04=null
timer      etx05=null
timer      etx06=null
timer      etx07=null
timer      etx08=null
timer      etx09=null
timer      etx10=null
timer      etx11=null
timer      etx12=null
timer      etx13=null
timer      etx14=null
timer      etx15=null
timer      etx16=null
timer      etx17=null
timer      etx18=null
timer      etx19=null
timer      etx20=null
timer      etx21=null
timer      etx22=null
timer      etx23=null
timer      etx24=null
timer      etx25=null
timer      etx26=null
timer      etx27=null
timer      etx28=null
timer      etx29=null
timer      etx30=null
timer      etx31=null
timer      etx32=null
location      elx00=null
location      elx01=null
location      elx02=null
location      elx03=null
location      elx04=null
location      elx05=null
location      elx06=null
location      elx07=null
location      elx08=null
location      elx09=null
location      elx10=null
location      elx11=null
location      elx12=null
location      elx13=null
location      elx14=null
location      elx15=null
location      elx16=null
location      elx17=null
location      elx18=null
location      elx19=null
location      elx20=null
location      elx21=null
location      elx22=null
location      elx23=null
location      elx24=null
location      elx25=null
location      elx26=null
location      elx27=null
location      elx28=null
location      elx29=null
location      elx30=null
location      elx31=null
location      elx32=null
integer      eaX00=0
integer      eaX01=0
integer      eaX02=0
integer      eaX03=0
integer      eaX04=0
integer      eaX05=0
integer      eaX06=0
integer      eaX07=0
integer      eaX08=0
integer      eaX09=0
integer      eaX10=0
integer      eaX11=0
integer      eaX12=0
integer      eaX13=0
integer      eaX14=0
integer      eaX15=0
integer      eaX16=0
integer      eaX17=0
integer      eaX18=0
integer      eaX19=0
integer      eaX20=0
integer      eaX21=0
integer      eaX22=0
integer      eaX23=0
integer      eaX24=0
integer      eaX25=0
integer      eaX26=0
integer      eaX27=0
integer      eaX28=0
integer      eaX29=0
integer      eaX30=0
integer      eaX31=0
integer      eaX32=0
real      erX00=0
real      erX01=0
real      erX02=0
real      erX03=0
real      erX04=0
real      erX05=0
real      erX06=0
real      erX07=0
real      erX08=0
real      erX09=0
real      erX10=0
real      erX11=0
real      erX12=0
real      erX13=0
real      erX14=0
real      erX15=0
real      erX16=0
real      erX17=0
real      erX18=0
real      erX19=0
real      erX20=0
real      erX21=0
real      erX22=0
real      erX23=0
real      erX24=0
real      erX25=0
real      erX26=0
real      erX27=0
real      erX28=0
real      erX29=0
real      erX30=0
real      erX31=0
real      erX32=0
unit      euX00=null
unit      euX01=null
unit      euX02=null
unit      euX03=null
unit      euX04=null
unit      euX05=null
unit      euX06=null
unit      euX07=null
unit      euX08=null
unit      euX09=null
unit      euX10=null
unit      euX11=null
unit      euX12=null
unit      euX13=null
unit      euX14=null
unit      euX15=null
unit      euX16=null
unit      euX17=null
unit      euX18=null
unit      euX19=null
unit      euX20=null
unit      euX21=null
unit      euX22=null
unit      euX23=null
unit      euX24=null
unit      euX25=null
unit      euX26=null
unit      euX27=null
unit      euX28=null
unit      euX29=null
unit      euX30=null
unit      euX31=null
unit      euX32=null
string      esX00=null
string      esX01=null
string      esX02=null
string      esX03=null
string      esX04=null
string      esX05=null
string      esX06=null
string      esX07=null
string      esX08=null
string      esX09=null
string      esX10=null
string      esX11=null
string      esX12=null
string      esX13=null
string      esX14=null
string      esX15=null
string      esX16=null
string      esX17=null
string      esX18=null
string      esX19=null
string      esX20=null
string      esX21=null
string      esX22=null
string      esX23=null
string      esX24=null
string      esX25=null
string      esX26=null
string      esX27=null
string      esX28=null
string      esX29=null
string      esX30=null
string      esX31=null
string      esX32=null
boolean      ebX00=false
boolean      ebX01=false
boolean      ebX02=false
boolean      ebX03=false
boolean      ebX04=false
boolean      ebX05=false
boolean      ebX06=false
boolean      ebX07=false
boolean      ebX08=false
boolean      ebX09=false
boolean      ebX10=false
boolean      ebX11=false
boolean      ebX12=false
boolean      ebX13=false
boolean      ebX14=false
boolean      ebX15=false
boolean      ebX16=false
boolean      ebX17=false
boolean      ebX18=false
boolean      ebX19=false
boolean      ebX20=false
boolean      ebX21=false
boolean      ebX22=false
boolean      ebX23=false
boolean      ebX24=false
boolean      ebX25=false
boolean      ebX26=false
boolean      ebX27=false
boolean      ebX28=false
boolean      ebX29=false
boolean      ebX30=false
boolean      ebX31=false
boolean      ebX32=false
trigger      etrgX00=null
trigger      etrgX01=null
trigger      etrgX02=null
trigger      etrgX03=null
trigger      etrgX04=null
trigger      etrgX05=null
trigger      etrgX06=null
trigger      etrgX07=null
trigger      etrgX08=null
trigger      etrgX09=null
trigger      etrgX10=null
trigger      etrgX11=null
trigger      etrgX12=null
trigger      etrgX13=null
trigger      etrgX14=null
trigger      etrgX15=null
trigger      etrgX16=null
trigger      etrgX17=null
trigger      etrgX18=null
trigger      etrgX19=null
trigger      etrgX20=null
trigger      etrgX21=null
trigger      etrgX22=null
trigger      etrgX23=null
trigger      etrgX24=null
trigger      etrgX25=null
trigger      etrgX26=null
trigger      etrgX27=null
trigger      etrgX28=null
trigger      etrgX29=null
trigger      etrgX30=null
trigger      etrgX31=null
trigger      etrgX32=null
timer      etX00=null
timer      etX01=null
timer      etX02=null
timer      etX03=null
timer      etX04=null
timer      etX05=null
timer      etX06=null
timer      etX07=null
timer      etX08=null
timer      etX09=null
timer      etX10=null
timer      etX11=null
timer      etX12=null
timer      etX13=null
timer      etX14=null
timer      etX15=null
timer      etX16=null
timer      etX17=null
timer      etX18=null
timer      etX19=null
timer      etX20=null
timer      etX21=null
timer      etX22=null
timer      etX23=null
timer      etX24=null
timer      etX25=null
timer      etX26=null
timer      etX27=null
timer      etX28=null
timer      etX29=null
timer      etX30=null
timer      etX31=null
timer      etX32=null
location      elX00=null
location      elX01=null
location      elX02=null
location      elX03=null
location      elX04=null
location      elX05=null
location      elX06=null
location      elX07=null
location      elX08=null
location      elX09=null
location      elX10=null
location      elX11=null
location      elX12=null
location      elX13=null
location      elX14=null
location      elX15=null
location      elX16=null
location      elX17=null
location      elX18=null
location      elX19=null
location      elX20=null
location      elX21=null
location      elX22=null
location      elX23=null
location      elX24=null
location      elX25=null
location      elX26=null
location      elX27=null
location      elX28=null
location      elX29=null
location      elX30=null
location      elX31=null
location      elX32=null
integer      deax00=0
integer      deax01=0
integer      deax02=0
integer      deax03=0
integer      deax04=0
integer      deax05=0
integer      deax06=0
integer      deax07=0
integer      deax08=0
integer      deax09=0
integer      deax10=0
integer      deax11=0
integer      deax12=0
integer      deax13=0
integer      deax14=0
integer      deax15=0
integer      deax16=0
integer      deax17=0
integer      deax18=0
integer      deax19=0
integer      deax20=0
integer      deax21=0
integer      deax22=0
integer      deax23=0
integer      deax24=0
integer      deax25=0
integer      deax26=0
integer      deax27=0
integer      deax28=0
integer      deax29=0
integer      deax30=0
integer      deax31=0
integer      deax32=0
real      derx00=0
real      derx01=0
real      derx02=0
real      derx03=0
real      derx04=0
real      derx05=0
real      derx06=0
real      derx07=0
real      derx08=0
real      derx09=0
real      derx10=0
real      derx11=0
real      derx12=0
real      derx13=0
real      derx14=0
real      derx15=0
real      derx16=0
real      derx17=0
real      derx18=0
real      derx19=0
real      derx20=0
real      derx21=0
real      derx22=0
real      derx23=0
real      derx24=0
real      derx25=0
real      derx26=0
real      derx27=0
real      derx28=0
real      derx29=0
real      derx30=0
real      derx31=0
real      derx32=0
unit      deux00=null
unit      deux01=null
unit      deux02=null
unit      deux03=null
unit      deux04=null
unit      deux05=null
unit      deux06=null
unit      deux07=null
unit      deux08=null
unit      deux09=null
unit      deux10=null
unit      deux11=null
unit      deux12=null
unit      deux13=null
unit      deux14=null
unit      deux15=null
unit      deux16=null
unit      deux17=null
unit      deux18=null
unit      deux19=null
unit      deux20=null
unit      deux21=null
unit      deux22=null
unit      deux23=null
unit      deux24=null
unit      deux25=null
unit      deux26=null
unit      deux27=null
unit      deux28=null
unit      deux29=null
unit      deux30=null
unit      deux31=null
unit      deux32=null
string      desx00=null
string      desx01=null
string      desx02=null
string      desx03=null
string      desx04=null
string      desx05=null
string      desx06=null
string      desx07=null
string      desx08=null
string      desx09=null
string      desx10=null
string      desx11=null
string      desx12=null
string      desx13=null
string      desx14=null
string      desx15=null
string      desx16=null
string      desx17=null
string      desx18=null
string      desx19=null
string      desx20=null
string      desx21=null
string      desx22=null
string      desx23=null
string      desx24=null
string      desx25=null
string      desx26=null
string      desx27=null
string      desx28=null
string      desx29=null
string      desx30=null
string      desx31=null
string      desx32=null
boolean      debx00=false
boolean      debx01=false
boolean      debx02=false
boolean      debx03=false
boolean      debx04=false
boolean      debx05=false
boolean      debx06=false
boolean      debx07=false
boolean      debx08=false
boolean      debx09=false
boolean      debx10=false
boolean      debx11=false
boolean      debx12=false
boolean      debx13=false
boolean      debx14=false
boolean      debx15=false
boolean      debx16=false
boolean      debx17=false
boolean      debx18=false
boolean      debx19=false
boolean      debx20=false
boolean      debx21=false
boolean      debx22=false
boolean      debx23=false
boolean      debx24=false
boolean      debx25=false
boolean      debx26=false
boolean      debx27=false
boolean      debx28=false
boolean      debx29=false
boolean      debx30=false
boolean      debx31=false
boolean      debx32=false
// simple
  integer bax=0
  real brx=0
  string bsx=null
  boolean bbx=false
  code bcx=null
  timer btx=null
  location blx=null
  unit bux=null
  trigger btrgx=null
// advanced
  integer bax00=0
  integer bax01=0
  integer bax02=0
  integer bax03=0
  integer bax04=0
  integer bax05=0
  integer bax06=0
  integer bax07=0
  integer bax08=0
  integer bax09=0
  integer bax10=0
  integer bax11=0
  integer bax12=0
  integer bax13=0
  integer bax14=0
  integer bax15=0
  integer bax16=0
  integer bax17=0
  integer bax18=0
  integer bax19=0
  integer bax20=0
  integer bax21=0
  integer bax22=0
  integer bax23=0
  integer bax24=0
  integer bax25=0
  integer bax26=0
  integer bax27=0
  integer bax28=0
  integer bax29=0
  integer bax30=0
  integer bax31=0
  integer bax32=0
  real brx00=0
  real brx01=0
  real brx02=0
  real brx03=0
  real brx04=0
  real brx05=0
  real brx06=0
  real brx07=0
  real brx08=0
  real brx09=0
  real brx10=0
  real brx11=0
  real brx12=0
  real brx13=0
  real brx14=0
  real brx15=0
  real brx16=0
  real brx17=0
  real brx18=0
  real brx19=0
  real brx20=0
  real brx21=0
  real brx22=0
  real brx23=0
  real brx24=0
  real brx25=0
  real brx26=0
  real brx27=0
  real brx28=0
  real brx29=0
  real brx30=0
  real brx31=0
  real brx32=0
  string bsx00=null
  string bsx01=null
  string bsx02=null
  string bsx03=null
  string bsx04=null
  string bsx05=null
  string bsx06=null
  string bsx07=null
  string bsx08=null
  string bsx09=null
  string bsx10=null
  string bsx11=null
  string bsx12=null
  string bsx13=null
  string bsx14=null
  string bsx15=null
  string bsx16=null
  string bsx17=null
  string bsx18=null
  string bsx19=null
  string bsx20=null
  string bsx21=null
  string bsx22=null
  string bsx23=null
  string bsx24=null
  string bsx25=null
  string bsx26=null
  string bsx27=null
  string bsx28=null
  string bsx29=null
  string bsx30=null
  string bsx31=null
  string bsx32=null
  boolean bbx00=false
  boolean bbx01=false
  boolean bbx02=false
  boolean bbx03=false
  boolean bbx04=false
  boolean bbx05=false
  boolean bbx06=false
  boolean bbx07=false
  boolean bbx08=false
  boolean bbx09=false
  boolean bbx10=false
  boolean bbx11=false
  boolean bbx12=false
  boolean bbx13=false
  boolean bbx14=false
  boolean bbx15=false
  boolean bbx16=false
  boolean bbx17=false
  boolean bbx18=false
  boolean bbx19=false
  boolean bbx20=false
  boolean bbx21=false
  boolean bbx22=false
  boolean bbx23=false
  boolean bbx24=false
  boolean bbx25=false
  boolean bbx26=false
  boolean bbx27=false
  boolean bbx28=false
  boolean bbx29=false
  boolean bbx30=false
  boolean bbx31=false
  boolean bbx32=false
  code bcx00=null
  code bcx01=null
  code bcx02=null
  code bcx03=null
  code bcx04=null
  code bcx05=null
  code bcx06=null
  code bcx07=null
  code bcx08=null
  code bcx09=null
  code bcx10=null
  code bcx11=null
  code bcx12=null
  code bcx13=null
  code bcx14=null
  code bcx15=null
  code bcx16=null
  code bcx17=null
  code bcx18=null
  code bcx19=null
  code bcx20=null
  code bcx21=null
  code bcx22=null
  code bcx23=null
  code bcx24=null
  code bcx25=null
  code bcx26=null
  code bcx27=null
  code bcx28=null
  code bcx29=null
  code bcx30=null
  code bcx31=null
  code bcx32=null
  timer btx00=null
  timer btx01=null
  timer btx02=null
  timer btx03=null
  timer btx04=null
  timer btx05=null
  timer btx06=null
  timer btx07=null
  timer btx08=null
  timer btx09=null
  timer btx10=null
  timer btx11=null
  timer btx12=null
  timer btx13=null
  timer btx14=null
  timer btx15=null
  timer btx16=null
  timer btx17=null
  timer btx18=null
  timer btx19=null
  timer btx20=null
  timer btx21=null
  timer btx22=null
  timer btx23=null
  timer btx24=null
  timer btx25=null
  timer btx26=null
  timer btx27=null
  timer btx28=null
  timer btx29=null
  timer btx30=null
  timer btx31=null
  timer btx32=null
  location blx00=null
  location blx01=null
  location blx02=null
  location blx03=null
  location blx04=null
  location blx05=null
  location blx06=null
  location blx07=null
  location blx08=null
  location blx09=null
  location blx10=null
  location blx11=null
  location blx12=null
  location blx13=null
  location blx14=null
  location blx15=null
  location blx16=null
  location blx17=null
  location blx18=null
  location blx19=null
  location blx20=null
  location blx21=null
  location blx22=null
  location blx23=null
  location blx24=null
  location blx25=null
  location blx26=null
  location blx27=null
  location blx28=null
  location blx29=null
  location blx30=null
  location blx31=null
  location blx32=null
  unit bux00=null
  unit bux01=null
  unit bux02=null
  unit bux03=null
  unit bux04=null
  unit bux05=null
  unit bux06=null
  unit bux07=null
  unit bux08=null
  unit bux09=null
  unit bux10=null
  unit bux11=null
  unit bux12=null
  unit bux13=null
  unit bux14=null
  unit bux15=null
  unit bux16=null
  unit bux17=null
  unit bux18=null
  unit bux19=null
  unit bux20=null
  unit bux21=null
  unit bux22=null
  unit bux23=null
  unit bux24=null
  unit bux25=null
  unit bux26=null
  unit bux27=null
  unit bux28=null
  unit bux29=null
  unit bux30=null
  unit bux31=null
  unit bux32=null
  trigger btrgx00=null
  trigger btrgx01=null
  trigger btrgx02=null
  trigger btrgx03=null
  trigger btrgx04=null
  trigger btrgx05=null
  trigger btrgx06=null
  trigger btrgx07=null
  trigger btrgx08=null
  trigger btrgx09=null
  trigger btrgx10=null
  trigger btrgx11=null
  trigger btrgx12=null
  trigger btrgx13=null
  trigger btrgx14=null
  trigger btrgx15=null
  trigger btrgx16=null
  trigger btrgx17=null
  trigger btrgx18=null
  trigger btrgx19=null
  trigger btrgx20=null
  trigger btrgx21=null
  trigger btrgx22=null
  trigger btrgx23=null
  trigger btrgx24=null
  trigger btrgx25=null
  trigger btrgx26=null
  trigger btrgx27=null
  trigger btrgx28=null
  trigger btrgx29=null
  trigger btrgx30=null
  trigger btrgx31=null
  trigger btrgx32=null


integer array               Tmrs
terraindeformation array               TmrTDS
lightning array               Blitze
timer array                   BlitzeTmr
unit array                    BlitzeUnt00
unit array                    BlitzeUnt01
unit array                    BlitzeUnt02
unit array                    BlitzeUnt03
unit array                    BlitzeUnt04
unit array                    BlitzeUnt05
unit array                    BlitzeUnt06
unit array                    BlitzeUnt07
real array                    BlitzeReal00
real array                    BlitzeReal01
real array                    BlitzeReal02
real array                    BlitzeReal03
real array                    BlitzeReal04
real array                    BlitzeReal05
real array                    BlitzeReal06
real array                    BlitzeReal07
real array                    BlitzeReal08
real array                    BlitzeReal09
real array                    BlitzeReal10
real array                    BlitzeReal11
real array                    BlitzeReal12
real array                    BlitzeReal13
real array                    BlitzeReal14
real array                    BlitzeReal15
integer array                    BlitzeInt00
integer array                    BlitzeInt01
integer array                    BlitzeInt02
integer array                    BlitzeInt03
integer array                    BlitzeInt04
integer array                    BlitzeInt05
integer array                    BlitzeInt06
integer array                    BlitzeInt07
integer array                    BlitzeInt08
integer array                    BlitzeInt09
integer array                    BlitzeInt10
integer array                    BlitzeInt11
integer array                    BlitzeInt12
integer array                    BlitzeInt13
integer array                    BlitzeInt14
integer array                    BlitzeInt15
trigger array                 AETrg
triggeraction array           AETa
triggercondition array        AETc
boolean                       IsAttacked = false


// Attack Mark 07
unit                          AMCaster = null
unit                          AMDummy = null  
unit array                    AM_Targets
timer array                   AM_Tmrs
real array                    AM_Dmg
real array                    AM_Speed      


  // Stack
    integer                 stackindex              = 0
    integer array           stack
    integer                 stackrindex              = 0
    real array              stackr
    integer                 stacksindex              = 0
    string array            stacks
    integer                 stackuindex              = 0
    unit array              stacku
    unit                    stackU                  = null
	
	image array             stack_images  
	timer array             stack_images_tmr  	
	integer array           stack_images_pos  
	integer array           stack_images_ref   	
    integer                 stack_images_max        = 0	
	
	image tmpimg=null 
// Some others...

    boolean                 dis_msg                 = true

    gamecache               cache                   = null
    gamecache               TRS                     = null
    gamecache               TRSInv                  = null
    gamecache               TRSItems                = null
    gamecache               AECache                 = null
    multiboard array        XMB
    integer                 XMBColumns              = 1
	integer                 mb_max_plr              = 12
    trigger                 Executer                = null
    triggercondition        ExecuterCond            = null
    boolean                 ExecResult              = false 
    unit array              TRSCDunit
    string array            TRSCDId
    string array            DisStr
    integer array           DisStrR
    integer array           DisStrG
    integer array           DisStrB
    integer                 DisStrMax               = 0
    fogmodifier array       TRSVisibility        
    boolean                 TRSInvClearMessages     = true
    trackable array         Trk
    integer                 TrkMax                  = 0
    integer                 InvMax                  = 0
    real array              TrkX
    real array              TrkY
    real array              TrkZ
    integer array           TrkNum
    integer array           TrkIndex
    integer array           TrkInvId
    integer array           TrkExId
    integer array           TrkNatIconId
    real array              TrkNatIconSize
    integer array           InvFirstTrk
    integer array           InvFirstMerchTrk
    string array            TrkSide
    string array            TrkType
    destructable array      TrkIcon
    destructable array      TrkBackIcon
    boolexpr array          TrkReq
    string array            TrkItem
    string array            InvUserId
    string array            InvCurItem
    string array            InvCurMerchItem
	integer array           InvLastTrk
    destructable array      InvCurIcon
    destructable array      InvCurMerchIcon
    unit array              InvUser
    unit array              InvMerchant
	unit array              InvShareInv
    unit array              InvCurSelectedHero
    real array              InvPlayerX
    real array              InvPlayerY
    string                  InvCurSide
    integer array           InvMinChargedSlot
    integer array           InvMaxChargedSlot
    real                    MapBoundMinX
    real                    MapBoundMinY
    real                    MapBoundMaxX
    real                    MapBoundMaxY
    camerasetup array       InvCamSetups
    integer array           InvCamCon
    integer array           InvCamPP
    integer array           InvPageDown
    integer array           InvPageUp
    integer                 InvCamMax                 = 0
    boolean array           InvCamUsed
    timer                   InvCamTimer               = null
    integer                 TRSSubAbilsCount          = 0
    integer                 TRSSubAbilsCurPointer     = 1
    string array            TRSCusFuncs
    integer array           TRSSubAbils
    real array              TRSAbilsRarity
    string array            TRSAbilsMultId
    integer array           TRSSubAbilsPointer
    integer array           TRSSubAbilsId
    integer array           TRSSubAbilsNum
    integer array           TRSSubAbilsParam
    integer array           TRSSubAbilsMin
    integer array           TRSSubAbilsMax
    integer array           TRSSubAbilsMinVal
    integer array           TRSSubAbilsMaxVal
    integer array           TRSSubAbilsSize
    integer array           TRSAbilsToUpdate
    boolean array           TRSAbilsToUpdateUsed
    integer                 TRSAbilsToUpdateMax     = 0
    trigger array           TRSAbilsToDisplayStringCompiler
    string array            TRSAbilsToDisplayReady
    integer array           TRSAbilsToDisplay
    integer array           TRSAbilsToDisplayPar
    integer array           TRSAbilsToDisplayMin
    integer array           TRSAbilsToDisplayMax
    integer array           TRSAbilsToDisplayAbilCount
    integer array           TRSAbilsToDisplayOrdered
    boolean array           TRSAbilsToDisplayUsed
    boolean array           TRSAbilsDisplayNotDisp
    boolean array           TRSAbilsDisplayReqNotDisp
    integer                 TRSAbilsToDisplayCount     = 0
    trigger array           TRSRequires                
    boolean array           TRSRequiresOk
    integer array           TRSRequiresStack
    integer                 TRSRequiresMax             = 0    
    integer                 TRSRequiresVal             = 0   
    unit                    TRSRequiresUnit            = null
    string                  TRSRequiresItem            = null
    boolexpr array          TRSRequiresFuncs
    unit                    TRSUnit                    = null
    string                  TRSItem                    = null
    integer                 TRSMod                     = 0
    boolean                 TRSInsert                  = false
    boolean                 TRSCopying                 = false
    integer array           TRSPar1                     
    integer array           TRSMin1                     
    integer array           TRSMax1   
    integer array           TRSCount1   
    integer array           TRSParS1                     
    integer array           TRSMinS1                     
    integer array           TRSMaxS1  
    integer array           TRSCountS1    
    integer                 TRSPar    =0                  
    integer                 TRSMin    =0                 
    integer                 TRSMax    =0
    integer                 TRSCount  =0    
    integer                 TRSParS   =0                  
    integer                 TRSMinS   =0                 
    integer                 TRSMaxS   =0    
    integer                 TRSCountS =0 
    unit                    TRSDisUnit    =null    
    string                  TRSDisItem    =null 
    string                  TRSDisItemID  =null
    multiboard array        TRSDisMB  
    timer                   TRSRefreshTimer      =null          
    integer array           TRSToExec
    integer array           TRSToExecPos
    boolean array           TRSToExecExist
    integer                 TRSToExecMax                = 0 
    integer array           TrkAttachInt0x00
    integer array           TrkAttachInt0x01
    integer array           TrkAttachInt0x02
    integer array           TrkAttachInt0x03
    integer array           TrkAttachInt0x04
    integer array           TrkAttachInt0x05
    integer array           TrkAttachInt0x06
    integer array           TrkAttachInt0x07
    integer array           TrkAttachInt0x08
    integer array           TrkAttachInt0x09
    integer array           TrkAttachInt0x10
    integer array           TrkAttachInt0x11
    integer array           TrkAttachInt0x12
    integer array           TrkAttachInt0x13
    integer array           TrkAttachInt0x14
    integer array           TrkAttachInt0x15
// Tc's Hyper Walker
    integer array           HWFreeStack
    boolean array           HWFreeUsed
    integer                 HWFreeMax                   = 0
    integer                 HWMax                       = 0 
    gamecache               HW                          = null  
    timer                   HWTimer                     = null 
    integer                 HWXG                        = 0                   
    integer array           Pow2

// OPC

    group array             OPCGroups
    boolean array           OPCGroupsUsed
    timer array             OPCTimers
    boolean array           OPCTimersUsed
	integer array           OPCTimersRefCount
    unit array              OPCUnits
    boolean array           OPCUnitsUsed
	unit array              OPCUnits2
    boolean array           OPCUnitsUsed2
    multiboard array        OPCMbs
    boolean array           OPCMBUsed
    integer                 OPCGroupsCur                     = 0          
    integer                 OPCGroupsToInit                  = 0
    integer                 OPCGroupsMinIndex                = 999999999
    integer                 OPCTimersCur                     = 0
    integer                 OPCTimersToInit                  = 0
    integer                 OPCTimersMinIndex                = 999999999
	integer                 OPCTimersMaxIndex                = 0
    integer                 OPCUnitsCur                      = 0
    integer                 OPCUnitsToInit                   = 0
    integer                 OPCUnitsMinIndex                 = 999999999
	integer                 OPCUnitsCur2                     = 0
    integer                 OPCUnitsToInit2                  = 0
    integer                 OPCUnitsMinIndex2                = 999999999
    integer                 OPCMbsCur                        = 0
    integer                 OPCMbsCurMin                     = 0
    integer                 OPCMbsCurMax                     = 0
    integer                 OPCMbsToInit                     = 0
    integer                 OPCMbsMinIndex                   = 999999999
    boolean                 OPCMbsFront                      = true
	integer                 OPCMaxtimers                     = 0
	integer                 OPCMaxunits                      = 0
	integer                 OPCMaxunits2                     = 0
    image array             Img
	integer array           ImgHndl
	integer                 Img_max                          = 0

// QUC
    unit array              QUCDummyCasters
    integer array           QUCAbilId
    integer                 QUCUnitId                        = 'e005'
	integer                 QUCUnit2Id                       = 'e001'
    integer                 DummyMarker
    real                    QUCDummyX                        = 0
    real                    QUCDummyY                        = 0

// Ultra String Parser
    gamecache               USPData                          = null
    integer array           ANSI2
    integer array           HEX2
    string array            ANSI
    string array            HEX                      
    boolean                 USPInited                        = false
    boolean                 USParray                         = false
    string                  USPStat                          = null
    string                  USPsval                          = null
    integer                 USParrayindex                    = 0
    integer                 USPimin                          = 0
    integer                 USPimax                          = 0
    integer                 USPival                          = 0
    real                    USPrmin                          = 0
    real                    USPrmax                          = 0 
    real                    USPrval                          = 0
    boolean                 USPdyn                           = false
    integer                 USPid                            = 0
    boolean                 USPAdd                           = false
    boolean                 USPMinus                         = false

    string                  USPIsStringPointer               = "$"
    string                  USPDataSetPointer                = "^"
    string                  USPSetPointer                    = "="
    string                  USPHexPointer                    = "0x"   
    string                  USPRealPointer                   = "."
    string                  USPRAWPointer                    = "'"
    string                  USPRandomPointer                 = "~"
    string                  USPDynRandomPointer              = "?"
    string                  USPEndPointer                    = ";"

// TPC
    integer                 TPCSetup_Pierce                  = 0
    integer                 TPCSetup_EndSplash               = 0
    integer                 TPCSetup_Jump                    = 0
    integer                 TPCSetup_JumpNoCalc              = 0
    integer                 TPCSetup_NoFaceChange            = 0
    integer                 TPCSetup_Suicide                 = 0
    integer                 TPCSetup_UseFacing               = 0
    integer                 TPCSetup_SetFacing               = 0
    integer                 TPCSetup_NoGravity               = 0
    integer                 TPCSetup_IgnoreZ                 = 0
    integer                 TPCSetup_NoZCalc                 = 0
    integer                 TPCSetup_3DInRange               = 0
    integer                 TPCSetup_3DInRangeAOE            = 0
    integer                 TPCSetup_3DDamage                = 0
    integer                 TPCSetup_TargetEffect            = 0
    integer                 TPCSetup_AllowZero               = 0
    integer                 TPCSetup_AdvArc                  = 0
    integer                 TPCSetup_UseArc                  = 0
    integer                 TPCSetup_UsePathing              = 0
    integer                 TPCSetup_SmoothZ                 = 0
    boolexpr                TPCSetup_BoolExpCon              = null
    boolexpr                TPCSetup_BoolExpAOE              = null
    real                    TPCSetup_ProjectilePeriodicalInt = 0
    real                    TPCSetup_ProjectileSpeed         = 0
    integer                 TPCSetup_Projectile              = 0
    real                    TPCSetup_LaunchOffset            = 0
    integer                 TPCSetup_Collision               = 0
    integer                 TPCSetup_CollisionZ              = 0
    integer                 TPCSetup_AOE                     = 0
    real                    TPCSetup_Arc                     = 0
    real                    TPCSetup_ArcStep                 = 0
    real                    TPCSetup_WindRes                 = 0
    real                    TPCSetup_Friction                = 0
    real                    TPCSetup_FallAccelLimit          = 0
    real                    TPCSetup_Mass                    = 0
    real                    TPCSetup_JumpPower               = 0
    integer                 TPCSetup_Damage                  = 0
    integer                 TPCSetup_DamagePierce            = 0
    unit                    TPCSetup_Parent                  = null
    string                  TPCSetup_CustomModel             = null
    string                  TPCSetup_Custom                  = null
    string                  TPCSetup_CustomPierce            = null
    string                  TPCSetup_CustomGround            = null
    string                  TPCSetup_CustomMove              = null
    string                  TPCSetup_CustomEnd               = null
    real                    TPCVecX                          = 0
    real                    TPCVecY                          = 0
    real                    TPCVecZ                          = 0
    real                    MapMinX                          = 0
    real                    MapMinY                          = 0
    real                    MapMaxX                          = 0
    real                    MapMaxY                          = 0
    integer                 TPCProjCount                     = 0
    boolean                 TPCShowCount                     = false

// Data Arrays
    
    gamecache               TPC            = null
    real                    TIPBeginX                        = 0
    real                    TIPBeginY                        = 0
    real                    TIPBeginZ                        = 0
    real                    TIPX                             = 0
    real                    TIPY                             = 0
    real                    TIPZ                             = 0
    unit                    TIPparent                        = null
    unit                    TIPtarget                        = null
    integer                 TPCMax                           = 0
    integer array           TPCFree  
    boolean array           TPCFreeUsed  
    integer                 TPCFreeMax                       = 0
    integer                 TPCMaxProj                       = 1023 
    location                TPCLoc                           = null
    location                TPCLoc0x1                        = null
    location                TPCLoc0x2                        = null
    location                TPCLoc0x3                        = null
    location                TPCLoc0x4                        = null


// TPC
    integer array           TPCInt00
    integer array           TPCInt01
    integer array           TPCInt02
    integer array           TPCInt03
    integer array           TPCInt04
    integer array           TPCInt05
    integer array           TPCInt06
    integer array           TPCInt07
    integer array           TPCInt08
    integer array           TPCInt09
    integer array           TPCInt10
    integer array           TPCInt11
    integer array           TPCInt12
    integer array           TPCInt13
    integer array           TPCInt14
    integer array           TPCInt15
    integer array           TPCInt16
    integer array           TPCInt17
    integer array           TPCInt18
    integer array           TPCInt19
    integer array           TPCInt20
    integer array           TPCInt21
    integer array           TPCInt22
    integer array           TPCInt23
    integer array           TPCInt24
    integer array           TPCInt25
    integer array           TPCInt26
    integer array           TPCInt27
    integer array           TPCInt28
    integer array           TPCInt29
    integer array           TPCInt30
    integer array           TPCInt31
    integer array           TPCInt32
    integer array           TPCInt33
    integer array           TPCInt34
    integer array           TPCInt35
    integer array           TPCInt36
    integer array           TPCInt37
    integer array           TPCInt38
    integer array           TPCInt39
    integer array           TPCInt40
    integer array           TPCInt41
    integer array           TPCInt42
    integer array           TPCInt43
    integer array           TPCInt44
    integer array           TPCInt45
    integer array           TPCInt46
    integer array           TPCInt47
    integer array           TPCInt48
    integer array           TPCInt49
    integer array           TPCInt50
    integer array           TPCInt51
    integer array           TPCInt52
    integer array           TPCInt53
    integer array           TPCInt54
    integer array           TPCInt55
    integer array           TPCInt56
    integer array           TPCInt57
    integer array           TPCInt58
    integer array           TPCInt59
    integer array           TPCInt60
    integer array           TPCInt61
    integer array           TPCInt62
    integer array           TPCInt63
    integer array           TPCInt64
    real array              TPCReal00
    real array              TPCReal01
    real array              TPCReal02
    real array              TPCReal03
    real array              TPCReal04
    real array              TPCReal05
    real array              TPCReal06
    real array              TPCReal07
    real array              TPCReal08
    real array              TPCReal09
    real array              TPCReal10
    real array              TPCReal11
    real array              TPCReal12
    real array              TPCReal13
    real array              TPCReal14
    real array              TPCReal15
    real array              TPCReal16
    real array              TPCReal17
    real array              TPCReal18
    real array              TPCReal19
    real array              TPCReal20
    real array              TPCReal21
    real array              TPCReal22
    real array              TPCReal23
    real array              TPCReal24
    real array              TPCReal25
    real array              TPCReal26
    real array              TPCReal27
    real array              TPCReal28
    real array              TPCReal29
    real array              TPCReal30
    real array              TPCReal31
    real array              TPCReal32
    real array              TPCReal33
    real array              TPCReal34
    real array              TPCReal35
    real array              TPCReal36
    real array              TPCReal37
    real array              TPCReal38
    real array              TPCReal39
    real array              TPCReal40
    real array              TPCReal41
    real array              TPCReal42
    real array              TPCReal43
    real array              TPCReal44
    real array              TPCReal45
    real array              TPCReal46
    real array              TPCReal47
    real array              TPCReal48
    real array              TPCReal49
    real array              TPCReal50
    real array              TPCReal51
    real array              TPCReal52
    real array              TPCReal53
    real array              TPCReal54
    real array              TPCReal55
    real array              TPCReal56
    real array              TPCReal57
    real array              TPCReal58
    real array              TPCReal59
    real array              TPCReal60
    real array              TPCReal61
    real array              TPCReal62
    real array              TPCReal63
    real array              TPCReal64
    string array            TPCStr00
    string array            TPCStr01
    string array            TPCStr02
    string array            TPCStr03
    string array            TPCStr04
    string array            TPCStr05
    string array            TPCStr06
    string array            TPCStr07
    string array            TPCStr08
    string array            TPCStr09
    string array            TPCStr10
    string array            TPCStr11
    string array            TPCStr12
    string array            TPCStr13
    string array            TPCStr14
    string array            TPCStr15
    string array            TPCStr16
    string array            TPCStr17
    string array            TPCStr18
    string array            TPCStr19
    string array            TPCStr20
    string array            TPCStr21
    string array            TPCStr22
    string array            TPCStr23
    string array            TPCStr24
    string array            TPCStr25
    string array            TPCStr26
    string array            TPCStr27
    string array            TPCStr28
    string array            TPCStr29
    string array            TPCStr30
    string array            TPCStr31
    string array            TPCStr32
    string array            TPCStr33
    string array            TPCStr34
    string array            TPCStr35
    string array            TPCStr36
    string array            TPCStr37
    string array            TPCStr38
    string array            TPCStr39
    string array            TPCStr40
    string array            TPCStr41
    string array            TPCStr42
    string array            TPCStr43
    string array            TPCStr44
    string array            TPCStr45
    string array            TPCStr46
    string array            TPCStr47
    string array            TPCStr48
    string array            TPCStr49
    string array            TPCStr50
    string array            TPCStr51
    string array            TPCStr52
    string array            TPCStr53
    string array            TPCStr54
    string array            TPCStr55
    string array            TPCStr56
    string array            TPCStr57
    string array            TPCStr58
    string array            TPCStr59
    string array            TPCStr60
    string array            TPCStr61
    string array            TPCStr62
    string array            TPCStr63
    string array            TPCStr64
    unit array              TPCUnt00
    unit array              TPCUnt01
    unit array              TPCUnt02
    unit array              TPCUnt03
    unit array              TPCUnt04
    unit array              TPCUnt05
    unit array              TPCUnt06
    unit array              TPCUnt07
    unit array              TPCUnt08
    unit array              TPCUnt09
    unit array              TPCUnt10
    unit array              TPCUnt11
    unit array              TPCUnt12
    unit array              TPCUnt13
    unit array              TPCUnt14
    unit array              TPCUnt15
    unit array              TPCUnt16
    unit array              TPCUnt17
    unit array              TPCUnt18
    unit array              TPCUnt19
    unit array              TPCUnt20
    unit array              TPCUnt21
    unit array              TPCUnt22
    unit array              TPCUnt23
    unit array              TPCUnt24
    unit array              TPCUnt25
    unit array              TPCUnt26
    unit array              TPCUnt27
    unit array              TPCUnt28
    unit array              TPCUnt29
    unit array              TPCUnt30
    unit array              TPCUnt31
    unit array              TPCUnt32
    unit array              TPCUnt33
    unit array              TPCUnt34
    unit array              TPCUnt35
    unit array              TPCUnt36
    unit array              TPCUnt37
    unit array              TPCUnt38
    unit array              TPCUnt39
    unit array              TPCUnt40
    unit array              TPCUnt41
    unit array              TPCUnt42
    unit array              TPCUnt43
    unit array              TPCUnt44
    unit array              TPCUnt45
    unit array              TPCUnt46
    unit array              TPCUnt47
    unit array              TPCUnt48
    unit array              TPCUnt49
    unit array              TPCUnt50
    unit array              TPCUnt51
    unit array              TPCUnt52
    unit array              TPCUnt53
    unit array              TPCUnt54
    unit array              TPCUnt55
    unit array              TPCUnt56
    unit array              TPCUnt57
    unit array              TPCUnt58
    unit array              TPCUnt59
    unit array              TPCUnt60
    unit array              TPCUnt61
    unit array              TPCUnt62
    unit array              TPCUnt63
    unit array              TPCUnt64
    trigger array           TPCTrg00
    trigger array           TPCTrg01
    trigger array           TPCTrg02
    trigger array           TPCTrg03
    trigger array           TPCTrg04
    trigger array           TPCTrg05
    trigger array           TPCTrg06
    trigger array           TPCTrg07
    trigger array           TPCTrg08
    trigger array           TPCTrg09
    trigger array           TPCTrg10
    trigger array           TPCTrg11
    trigger array           TPCTrg12
    trigger array           TPCTrg13
    trigger array           TPCTrg14
    trigger array           TPCTrg15
    trigger array           TPCTrg16
    trigger array           TPCTrg17
    trigger array           TPCTrg18
    trigger array           TPCTrg19
    trigger array           TPCTrg20
    trigger array           TPCTrg21
    trigger array           TPCTrg22
    trigger array           TPCTrg23
    trigger array           TPCTrg24
    trigger array           TPCTrg25
    trigger array           TPCTrg26
    trigger array           TPCTrg27
    trigger array           TPCTrg28
    trigger array           TPCTrg29
    trigger array           TPCTrg30
    trigger array           TPCTrg31
    trigger array           TPCTrg32
    trigger array           TPCTrg33
    trigger array           TPCTrg34
    trigger array           TPCTrg35
    trigger array           TPCTrg36
    trigger array           TPCTrg37
    trigger array           TPCTrg38
    trigger array           TPCTrg39
    trigger array           TPCTrg40
    trigger array           TPCTrg41
    trigger array           TPCTrg42
    trigger array           TPCTrg43
    trigger array           TPCTrg44
    trigger array           TPCTrg45
    trigger array           TPCTrg46
    trigger array           TPCTrg47
    trigger array           TPCTrg48
    trigger array           TPCTrg49
    trigger array           TPCTrg50
    trigger array           TPCTrg51
    trigger array           TPCTrg52
    trigger array           TPCTrg53
    trigger array           TPCTrg54
    trigger array           TPCTrg55
    trigger array           TPCTrg56
    trigger array           TPCTrg57
    trigger array           TPCTrg58
    trigger array           TPCTrg59
    trigger array           TPCTrg60
    trigger array           TPCTrg61
    trigger array           TPCTrg62
    trigger array           TPCTrg63
    trigger array           TPCTrg64
    timer array             TPCTmr00
    timer array             TPCTmr01
    timer array             TPCTmr02
    timer array             TPCTmr03
    timer array             TPCTmr04
    timer array             TPCTmr05
    timer array             TPCTmr06
    timer array             TPCTmr07
    timer array             TPCTmr08
    timer array             TPCTmr09
    timer array             TPCTmr10
    timer array             TPCTmr11
    timer array             TPCTmr12
    timer array             TPCTmr13
    timer array             TPCTmr14
    timer array             TPCTmr15
    timer array             TPCTmr16
    timer array             TPCTmr17
    timer array             TPCTmr18
    timer array             TPCTmr19
    timer array             TPCTmr20
    timer array             TPCTmr21
    timer array             TPCTmr22
    timer array             TPCTmr23
    timer array             TPCTmr24
    timer array             TPCTmr25
    timer array             TPCTmr26
    timer array             TPCTmr27
    timer array             TPCTmr28
    timer array             TPCTmr29
    timer array             TPCTmr30
    timer array             TPCTmr31
    timer array             TPCTmr32
    timer array             TPCTmr33
    timer array             TPCTmr34
    timer array             TPCTmr35
    timer array             TPCTmr36
    timer array             TPCTmr37
    timer array             TPCTmr38
    timer array             TPCTmr39
    timer array             TPCTmr40
    timer array             TPCTmr41
    timer array             TPCTmr42
    timer array             TPCTmr43
    timer array             TPCTmr44
    timer array             TPCTmr45
    timer array             TPCTmr46
    timer array             TPCTmr47
    timer array             TPCTmr48
    timer array             TPCTmr49
    timer array             TPCTmr50
    timer array             TPCTmr51
    timer array             TPCTmr52
    timer array             TPCTmr53
    timer array             TPCTmr54
    timer array             TPCTmr55
    timer array             TPCTmr56
    timer array             TPCTmr57
    timer array             TPCTmr58
    timer array             TPCTmr59
    timer array             TPCTmr60
    timer array             TPCTmr61
    timer array             TPCTmr62
    timer array             TPCTmr63
    timer array             TPCTmr64
    triggeraction array     TPCTA00
    triggeraction array     TPCTA01
    triggeraction array     TPCTA02
    triggeraction array     TPCTA03
    triggeraction array     TPCTA04
    triggeraction array     TPCTA05
    triggeraction array     TPCTA06
    triggeraction array     TPCTA07
    triggeraction array     TPCTA08
    triggeraction array     TPCTA09
    triggeraction array     TPCTA10
    triggeraction array     TPCTA11
    triggeraction array     TPCTA12
    triggeraction array     TPCTA13
    triggeraction array     TPCTA14
    triggeraction array     TPCTA15
    triggeraction array     TPCTA16
    triggeraction array     TPCTA17
    triggeraction array     TPCTA18
    triggeraction array     TPCTA19
    triggeraction array     TPCTA20
    triggeraction array     TPCTA21
    triggeraction array     TPCTA22
    triggeraction array     TPCTA23
    triggeraction array     TPCTA24
    triggeraction array     TPCTA25
    triggeraction array     TPCTA26
    triggeraction array     TPCTA27
    triggeraction array     TPCTA28
    triggeraction array     TPCTA29
    triggeraction array     TPCTA30
    triggeraction array     TPCTA31
    triggeraction array     TPCTA32
    triggeraction array     TPCTA33
    triggeraction array     TPCTA34
    triggeraction array     TPCTA35
    triggeraction array     TPCTA36
    triggeraction array     TPCTA37
    triggeraction array     TPCTA38
    triggeraction array     TPCTA39
    triggeraction array     TPCTA40
    triggeraction array     TPCTA41
    triggeraction array     TPCTA42
    triggeraction array     TPCTA43
    triggeraction array     TPCTA44
    triggeraction array     TPCTA45
    triggeraction array     TPCTA46
    triggeraction array     TPCTA47
    triggeraction array     TPCTA48
    triggeraction array     TPCTA49
    triggeraction array     TPCTA50
    triggeraction array     TPCTA51
    triggeraction array     TPCTA52
    triggeraction array     TPCTA53
    triggeraction array     TPCTA54
    triggeraction array     TPCTA55
    triggeraction array     TPCTA56
    triggeraction array     TPCTA57
    triggeraction array     TPCTA58
    triggeraction array     TPCTA59
    triggeraction array     TPCTA60
    triggeraction array     TPCTA61
    triggeraction array     TPCTA62
    triggeraction array     TPCTA63
    triggeraction array     TPCTA64
    triggercondition array  TPCTC00
    triggercondition array  TPCTC01
    triggercondition array  TPCTC02
    triggercondition array  TPCTC03
    triggercondition array  TPCTC04
    triggercondition array  TPCTC05
    triggercondition array  TPCTC06
    triggercondition array  TPCTC07
    triggercondition array  TPCTC08
    triggercondition array  TPCTC09
    triggercondition array  TPCTC10
    triggercondition array  TPCTC11
    triggercondition array  TPCTC12
    triggercondition array  TPCTC13
    triggercondition array  TPCTC14
    triggercondition array  TPCTC15
    triggercondition array  TPCTC16
    triggercondition array  TPCTC17
    triggercondition array  TPCTC18
    triggercondition array  TPCTC19
    triggercondition array  TPCTC20
    triggercondition array  TPCTC21
    triggercondition array  TPCTC22
    triggercondition array  TPCTC23
    triggercondition array  TPCTC24
    triggercondition array  TPCTC25
    triggercondition array  TPCTC26
    triggercondition array  TPCTC27
    triggercondition array  TPCTC28
    triggercondition array  TPCTC29
    triggercondition array  TPCTC30
    triggercondition array  TPCTC31
    triggercondition array  TPCTC32
    triggercondition array  TPCTC33
    triggercondition array  TPCTC34
    triggercondition array  TPCTC35
    triggercondition array  TPCTC36
    triggercondition array  TPCTC37
    triggercondition array  TPCTC38
    triggercondition array  TPCTC39
    triggercondition array  TPCTC40
    triggercondition array  TPCTC41
    triggercondition array  TPCTC42
    triggercondition array  TPCTC43
    triggercondition array  TPCTC44
    triggercondition array  TPCTC45
    triggercondition array  TPCTC46
    triggercondition array  TPCTC47
    triggercondition array  TPCTC48
    triggercondition array  TPCTC49
    triggercondition array  TPCTC50
    triggercondition array  TPCTC51
    triggercondition array  TPCTC52
    triggercondition array  TPCTC53
    triggercondition array  TPCTC54
    triggercondition array  TPCTC55
    triggercondition array  TPCTC56
    triggercondition array  TPCTC57
    triggercondition array  TPCTC58
    triggercondition array  TPCTC59
    triggercondition array  TPCTC60
    triggercondition array  TPCTC61
    triggercondition array  TPCTC62
    triggercondition array  TPCTC63
    triggercondition array  TPCTC64
    boolexpr array          TPCBE00
    boolexpr array          TPCBE01
    boolexpr array          TPCBE02
    boolexpr array          TPCBE03
    boolexpr array          TPCBE04
    boolexpr array          TPCBE05
    boolexpr array          TPCBE06
    boolexpr array          TPCBE07
    boolexpr array          TPCBE08
    boolexpr array          TPCBE09
    boolexpr array          TPCBE10
    boolexpr array          TPCBE11
    boolexpr array          TPCBE12
    boolexpr array          TPCBE13
    boolexpr array          TPCBE14
    boolexpr array          TPCBE15
    boolexpr array          TPCBE16
    boolexpr array          TPCBE17
    boolexpr array          TPCBE18
    boolexpr array          TPCBE19
    boolexpr array          TPCBE20
    boolexpr array          TPCBE21
    boolexpr array          TPCBE22
    boolexpr array          TPCBE23
    boolexpr array          TPCBE24
    boolexpr array          TPCBE25
    boolexpr array          TPCBE26
    boolexpr array          TPCBE27
    boolexpr array          TPCBE28
    boolexpr array          TPCBE29
    boolexpr array          TPCBE30
    boolexpr array          TPCBE31
    boolexpr array          TPCBE32
    boolexpr array          TPCBE33
    boolexpr array          TPCBE34
    boolexpr array          TPCBE35
    boolexpr array          TPCBE36
    boolexpr array          TPCBE37
    boolexpr array          TPCBE38
    boolexpr array          TPCBE39
    boolexpr array          TPCBE40
    boolexpr array          TPCBE41
    boolexpr array          TPCBE42
    boolexpr array          TPCBE43
    boolexpr array          TPCBE44
    boolexpr array          TPCBE45
    boolexpr array          TPCBE46
    boolexpr array          TPCBE47
    boolexpr array          TPCBE48
    boolexpr array          TPCBE49
    boolexpr array          TPCBE50
    boolexpr array          TPCBE51
    boolexpr array          TPCBE52
    boolexpr array          TPCBE53
    boolexpr array          TPCBE54
    boolexpr array          TPCBE55
    boolexpr array          TPCBE56
    boolexpr array          TPCBE57
    boolexpr array          TPCBE58
    boolexpr array          TPCBE59
    boolexpr array          TPCBE60
    boolexpr array          TPCBE61
    boolexpr array          TPCBE62
    boolexpr array          TPCBE63
    boolexpr array          TPCBE64
    unit array              TPCMoveUnt
    unit array              TPCFinishUnt
    boolean array           TPCFinishEnd
    boolean array           TPCFinishFinish
    effect array            TPCEff00
    effect array            TPCEff01
    effect array            TPCEff02
    effect array            TPCEff03
    effect array            TPCEff04
    effect array            TPCEff05
    effect array            TPCEff06
    effect array            TPCEff07
    effect array            TPCEff08
    effect array            TPCEff09
    effect array            TPCEff10
    effect array            TPCEff11
    effect array            TPCEff12
    effect array            TPCEff13
    effect array            TPCEff14
    effect array            TPCEff15
    effect array            TPCEff16
    unit array              TPCus0x00
    unit array              TPCus0x01
    unit array              TPCus0x02
    unit array              TPCus0x03
    unit array              TPCus0x04
    unit array              TPCus0x05
    unit array              TPCus0x06
    unit array              TPCus0x07
    unit array              TPCFinishU0x00
    unit array              TPCFinishU0x01
    unit array              TPCFinishU0x02
    unit array              TPCFinishU0x03
    unit array              TPCFinishU0x04
    unit array              TPCFinishU0x05
    unit array              TPCFinishU0x06
    unit array              TPCFinishU0x07
    boolean array           TPCFinishB10x00
    boolean array           TPCFinishB10x01
    boolean array           TPCFinishB10x02
    boolean array           TPCFinishB10x03
    boolean array           TPCFinishB10x04
    boolean array           TPCFinishB10x05
    boolean array           TPCFinishB10x06
    boolean array           TPCFinishB10x07
    boolean array           TPCFinishB20x00
    boolean array           TPCFinishB20x01
    boolean array           TPCFinishB20x02
    boolean array           TPCFinishB20x03
    boolean array           TPCFinishB20x04
    boolean array           TPCFinishB20x05
    boolean array           TPCFinishB20x06
    boolean array           TPCFinishB20x07
    timer array             TPCFinishTmr
    unit                    TPCProj            = null
    unit                    TPCCaster          = null
    unit                    TPCTarget          = null


// Ultra Buffer Arrays
    integer array           UBDx01
    integer array           UBDx02
    integer array           UBDx03
    integer array           UBDx04
    integer array           UBDx05
    integer array           UBDx06
    integer array           UBDx07
    integer array           UBDx08
    integer array           UBDx09
    integer array           UBDx10
    integer array           UBDx11
    integer array           UBDx12
    integer array           UBDx13
    integer array           UBDx14
    integer array           UBDx15
    integer array           UBDx16
    integer array           UBDx17
    integer array           UBDx18
    integer array           UBDx19
    integer array           UBDx20
    integer array           UBDx21
    integer array           UBDx22
    integer array           UBDx23
    integer array           UBDx24
    integer array           UBDx25
    integer array           UBDx26
    integer array           UBDx27
    integer array           UBDx28
    integer array           UBDx29
    integer array           UBDx30
    integer array           UBDx31
    integer array           UBDx32
    integer array           UBStackDx01
    integer array           UBStackDx02
    integer array           UBStackDx03
    integer array           UBStackDx04
    integer array           UBStackDx05
    integer array           UBStackDx06
    integer array           UBStackDx07
    integer array           UBStackDx08
    integer array           UBStackDx09
    integer array           UBStackDx10
    integer array           UBStackDx11
    integer array           UBStackDx12
    integer array           UBStackDx13
    integer array           UBStackDx14
    integer array           UBStackDx15
    integer array           UBStackDx16
    integer array           UBStackDx17
    integer array           UBStackDx18
    integer array           UBStackDx19
    integer array           UBStackDx20
    integer array           UBStackDx21
    integer array           UBStackDx22
    integer array           UBStackDx23
    integer array           UBStackDx24
    integer array           UBStackDx25
    integer array           UBStackDx26
    integer array           UBStackDx27
    integer array           UBStackDx28
    integer array           UBStackDx29
    integer array           UBStackDx30
    integer array           UBStackDx31
    integer array           UBStackDx32

    integer array           UBstack
    integer array           UBstackfree
    integer                 UBstackindex           = 0
    integer                 UBstackfreeindex       = 0

endglobals


//  © 2006-2009 Author: Toadcop All rights reserved.         
//################################################################################################
//##     B U R A N X       F U N C T I O N S                                                    ##
//################################################################################################

function func_h2i takes handle h returns integer
        //return h
        func_return_h2i
        return 0
endfunction

constant function b2i takes boolean b returns integer
if b==true then
       return 1
endif
       return 0
endfunction

constant function i2b takes integer i returns boolean
if i>=1 then
       return true
endif
       return false
endfunction

constant function s2i takes string s returns integer
        return 0
endfunction

function echo takes string s returns nothing
    if dis_msg then
        set echolp=0
        loop
         exitwhen echolp>11
         call DisplayTextToPlayer(Player(echolp),0,0,s)
         set echolp=echolp+1
        endloop
    endif
endfunction


function echo2 takes string s,real sec returns nothing
    if dis_msg then
        set echolp=0
        loop
         exitwhen echolp>11
         call DisplayTimedTextToPlayer(Player(echolp),0,0,sec,s)
         set echolp=echolp+1
        endloop
    endif
endfunction


function echoAdv takes string s returns nothing
    if dis_msg then
        set echolp=0
        loop
         exitwhen echolp>11
         call DisplayTimedTextToPlayer(Player(echolp),0,0,99999999,s)
         set echolp=echolp+1
        endloop
    endif
endfunction

function align takes integer i returns nothing
   loop
    exitwhen i<1
      call Location(0,0)
    set i=i-1
   endloop
endfunction

function PlaySoundBR takes sound s,real x,real y,real z,string file,boolean looping,integer volume,integer cutoff returns sound
  set s=CreateSound(file,looping,true,false,10,10,"")
   call SetSoundVolume(s,volume)
   call SetSoundDistances(s,600,cutoff)
   call SetSoundDistanceCutoff(s,cutoff)
   call SetSoundPosition(s,x,y,z)
  return s
endfunction

function PlaySoundUnitBR takes sound s,unit u,string file,boolean looping,integer volume,integer cutoff returns sound
  set s=CreateSound(file,looping,true,false,10,10,"")
   call SetSoundVolume(s,volume)
   call SetSoundDistances(s,600,cutoff)
   call SetSoundDistanceCutoff(s,cutoff)
   call AttachSoundToUnit(s,u)
  return s
endfunction

function IsTrue takes nothing returns boolean
    return true
endfunction

function IsFalse takes nothing returns boolean
    return false
endfunction

function UnitEvent takes trigger t,playerunitevent e returns nothing
    local integer i=0
    loop
        call TriggerRegisterPlayerUnitEvent(t,Player(i),e,Condition(function IsTrue))
        set i=i+1
        exitwhen i>15
    endloop
endfunction

function CreateTextTagBR takes string s,real x,real y,real z,real fsize,integer r,integer g,integer b,integer a,real VelX,real VelY,real fadepoint,real lifespan returns texttag
         local texttag tt=CreateTextTag()
         call SetTextTagText(tt,s,fsize*0.023/10)
         call SetTextTagPos(tt,x,y,z)
         call SetTextTagColor(tt,r,g,b,a)
         call SetTextTagVelocity(tt,VelX,VelY)
       if lifespan>0.0 then
         call SetTextTagPermanent(tt,false)
         call SetTextTagSuspended(tt,false)
         call SetTextTagLifespan(tt,lifespan)
         call SetTextTagFadepoint(tt,fadepoint)
       endif
         return tt
endfunction

function RAbs takes real a returns real
    if (a >= 0) then
        return a
    else
        return -a
    endif
endfunction

function GetRandomIntBR takes integer i,integer i2 returns integer
     if i>i2 then
        return i
     endif
        return GetRandomInt(i,i2)
endfunction

function GetRandomRealBR takes real r,real r2 returns real
     if r>r2 then
        return r
     endif
        return GetRandomReal(r,r2)
endfunction

function GetChance takes real r returns boolean
   if GetRandomReal(0.001,100)<=r then
     return true
   endif
     return false   
endfunction

function IsTrueBR takes boolean b1,boolean b2 returns boolean
   if b1 then
     return b2
   endif
     return false
endfunction

function AddPercentBonus takes real b,real perc returns real
     return b+(b*(perc*0.01))
endfunction

function LimitToBR takes real r,real limit returns real
   if r>limit then
        return limit
   endif
        return r
endfunction

function NotLessBR takes real r,real limit returns real
   if r<limit then
        return limit
   endif
        return r
endfunction

function AddEffect takes string s,real x,real y returns nothing
    call DestroyEffect(AddSpecialEffect(s,x,y))
endfunction

function AddEffectTarget takes string s,widget w,string a returns nothing
    call DestroyEffect(AddSpecialEffectTarget(s,w,a))
endfunction

function IsUnitDeadBX takes unit u returns boolean
   return GetUnitTypeId(u) == 0 or IsUnitType(u , UNIT_TYPE_DEAD)
endfunction

function CineFilterBR takes player p,real duration,blendmode bmode,texmapflags tmf,string tex,integer red0,integer green0,integer blue0,integer trans0,integer red1,integer green1,integer blue1,integer trans1 returns nothing
if Player(localplayer)==p then
    call DisplayCineFilter(false)
    call SetCineFilterTexture(tex)
    call SetCineFilterBlendMode(bmode)
    call SetCineFilterTexMapFlags(tmf)
    call SetCineFilterStartUV(0,0,1,1)
    call SetCineFilterEndUV(0,0,1,1)
    call SetCineFilterStartColor(red0,green0,blue0,255-trans0)
    call SetCineFilterEndColor(red1,green1,blue1,255-trans1)
    call SetCineFilterDuration(duration)
    call DisplayCineFilter(true)
endif
endfunction

function round takes real r returns integer
	return R2I(r+0.5)
endfunction

function MBSetItemStyleBR takes multiboard mb,integer col,integer row,boolean showValue,boolean showIcon returns nothing
    set tmpmbi=MultiboardGetItem(mb,row-1,col-1)
    call MultiboardSetItemStyle(tmpmbi,showValue,showIcon)
    call MultiboardReleaseItem(tmpmbi)
    set tmpmbi=null
endfunction

function MBSetItemValueBR takes multiboard mb,integer col,integer row,string Val returns nothing
    set tmpmbi=MultiboardGetItem(mb,row-1,col-1)
    call MultiboardSetItemValue(tmpmbi,Val)
    call MultiboardReleaseItem(tmpmbi)
    set tmpmbi=null
endfunction

function MBSetItemColorBR takes multiboard mb,integer col,integer row,integer r,integer g,integer b,integer alpha returns nothing
    set tmpmbi=MultiboardGetItem(mb,row-1,col-1)
    call MultiboardSetItemValueColor(tmpmbi,r,g,b,255-alpha)
    call MultiboardReleaseItem(tmpmbi)
    set tmpmbi=null
endfunction

function MBSetItemWidthBR takes multiboard mb, integer col, integer row, real width returns nothing
    set tmpmbi=MultiboardGetItem(mb,row-1,col-1)
    call MultiboardSetItemWidth(tmpmbi,width/100)
    call MultiboardReleaseItem(tmpmbi)
    set tmpmbi=null
endfunction

function MBSetItemIconBR takes multiboard mb, integer col, integer row,string icon returns nothing
    set tmpmbi=MultiboardGetItem(mb,row-1,col-1)
    call MultiboardSetItemIcon(tmpmbi,icon)
    call MultiboardReleaseItem(tmpmbi)
    set tmpmbi=null
endfunction

function DistanceBetweenCord takes real X,real Y returns real
    return SquareRoot(X*X+Y*Y)
endfunction

function DistanceIn3D takes real X,real Y,real Z returns real
    return SquareRoot(X*X+Y*Y+Z*Z)
endfunction

function AngleBetweenCord takes real X,real Y returns real
    return 57.296*Atan2(Y,X)
endfunction

function MoveX takes real x, real Dist, real Angle returns real
 return x+Dist*Cos(Angle*0.0175)
endfunction

function MoveY takes real x, real Dist, real Angle returns real
 return x+Dist*Sin(Angle*0.0175)
endfunction

function MoveLocBR takes location l,real x,real y returns location
    call MoveLocation(l,x,y)
    return l
endfunction

function GetUnitZ takes unit u returns real
   return GetLocationZ(MoveLocBR(tmploc,GetUnitX(u),GetUnitY(u)))+GetUnitFlyHeight(u)
endfunction

function SetUnitZ takes unit u,real z returns nothing
   set tmplocZ=GetLocationZ(MoveLocBR(tmploc,GetUnitX(u),GetUnitY(u)))
   call SetUnitFlyHeight(u,z-tmplocZ,0)
endfunction

constant function Modulo takes integer h,integer d returns integer
     return  h-(h/d)*d
endfunction

function ModuloR takes real h, real d returns real
    return h-R2I(h/d)*d
endfunction

function UnitAddAbilityBR takes unit u,integer id returns nothing
    call UnitAddAbility(u,id)
    call UnitMakeAbilityPermanent(u,true,id)
endfunction

function log2 takes integer val returns integer
  if val>4194304 then
    return Pow2[val/1000000+2]    
  elseif val>1024 then
    return Pow2[val/1000+1]
  else
    return Pow2[val]
  endif  
    return 0
endfunction

function Initlog2 takes nothing returns nothing
    set Pow2[0]=0
    set Pow2[1]=0
    set Pow2[2]=1
    set Pow2[4]=2
    set Pow2[8]=3
    set Pow2[16]=4
    set Pow2[32]=5
    set Pow2[64]=6
    set Pow2[128]=7
    set Pow2[256]=8
    set Pow2[512]=9
    set Pow2[1024]=10
    set Pow2[3]=11
    set Pow2[5]=12
    set Pow2[9]=13
    set Pow2[17]=14
    set Pow2[33]=15
    set Pow2[66]=16
    set Pow2[132]=17
    set Pow2[263]=18
    set Pow2[525]=19
    set Pow2[1049]=20
    set Pow2[2098]=21
    set Pow2[4195]=22
    set Pow2[10]=23
    set Pow2[18]=24
    set Pow2[35]=25
    set Pow2[69]=26
    set Pow2[136]=27
    set Pow2[270]=28
    set Pow2[538]=29
    set Pow2[1075]=30
    set Pow2[2149]=31
    set Pow2[4296]=32
endfunction

//#########################################################
//##           Toadcop's Object Pre-Cacher               ##
//#########################################################

//##############################################################
//##    Get Funcs
//##############################################################

function GetTimerBR takes nothing returns timer
   local timer t=null
   local integer i=OPCTimersCur
if i>0 then
   set OPCTimersCur=OPCTimersCur-1
   set t=OPCTimers[i]
   set OPCTimersUsed[h2i(t)-OPCTimersMinIndex]=true
   set OPCTimers[i]=null 
   set OPCMaxtimers=OPCMaxtimers+1
   return t
endif
 if dbg then
   call echo("|cffff0000Create A New Timer !|r")
 endif
   return CreateTimer()
endfunction

function GetUnitBR takes nothing returns unit
   local unit u=null
   local integer i=OPCUnitsCur
if i>0 then
   set OPCUnitsCur=OPCUnitsCur-1
   set u=OPCUnits[i]
   call ShowUnit(u,true)
   call SetUnitPathing(u,false)
   call UnitRemoveAbility(u,'Aloc')
   call UnitAddAbility(u,'Aloc')
   set OPCUnitsUsed[h2i(u)-OPCUnitsMinIndex]=true
   set OPCUnits[i]=null 
   set OPCMaxunits=OPCMaxunits+1
   return u
endif
 if dbg then
   call echo("|cffff0000Create A New Unit !|r")
 endif
   return CreateUnit(Player(15),QUCUnitId,0,0,0)
endfunction

function GetUnit2BR takes nothing returns unit
   local unit u=null
   local integer i=OPCUnitsCur2
if i>0 then
   set OPCUnitsCur2=OPCUnitsCur2-1
   set u=OPCUnits2[i]
   call UnitRemoveAbility(u,'Aloc')
   call ShowUnit(u,true)
   call PauseUnit(u,false)
   set OPCUnitsUsed2[h2i(u)-OPCUnitsMinIndex2]=true
   set OPCUnits2[i]=null 
   set OPCMaxunits2=OPCMaxunits2+1
   return u
endif
 if dbg then
   call echo("|cffff0000Create A New Unit X2!|r")
 endif
   return CreateUnit(Player(15),QUCUnit2Id,0,0,0)
endfunction

function GetGroupBR takes nothing returns group
   local group g=null
   local integer i=OPCGroupsCur
if i>0 then
   set OPCGroupsCur=OPCGroupsCur-1
   set g=OPCGroups[i]
   set OPCGroupsUsed[h2i(g)-OPCGroupsMinIndex]=true
   set OPCGroups[i]=null  
   return g
endif
 if dbg then
   call echo("|cffff0000Create A New Group !|r")
 endif
   return CreateGroup()
endfunction

//##############################################################
//##    Recycling Funcs
//##############################################################

function RecycleTimer takes timer t returns nothing
      local integer i=OPCTimersCur+1
if OPCTimersUsed[h2i(t)-OPCTimersMinIndex] then
   if i<0x1fff and t!=null then
      call TimerStart(t,0,false,null)
      set OPCTimersCur=i
      set OPCTimers[i]=t
      set OPCTimersUsed[h2i(t)-OPCTimersMinIndex]=false 
      set OPCMaxtimers=OPCMaxtimers-1	  
   else
     if t!=null then
      call DestroyTimer(t)
     endif
   endif
endif
endfunction

function RecycleUnit takes unit u returns nothing
      local integer i=OPCUnitsCur+1
if OPCUnitsUsed[h2i(u)-OPCUnitsMinIndex] then
   if i<0x1fff and u!=null then
      call ShowUnit(u,false)
      call IssueImmediateOrder(u,"stop")
      call SetUnitScale(u,1,1,1)
      call SetUnitTimeScale(u,1)
      call SetUnitVertexColor(u,255,255,255,255)
      call SetUnitFlyHeight(u,GetUnitDefaultFlyHeight(u),0)
      call SetUnitOwner(u,Player(15),true)
      call SetUnitX(u,QUCDummyX)
      call SetUnitY(u,QUCDummyY)
      set OPCUnitsCur=i
      set OPCUnits[i]=u 
      set OPCUnitsUsed[h2i(u)-OPCUnitsMinIndex]=false 
      set OPCMaxunits=OPCMaxunits-1	  
   else
     if u!=null then
      call RemoveUnit(u)
     endif
   endif
endif
endfunction

function RecycleUnit2 takes unit u returns nothing
      local integer i=OPCUnitsCur2+1
if OPCUnitsUsed2[h2i(u)-OPCUnitsMinIndex2] then
   if i<0x1fff and u!=null then
      call ShowUnit(u,false)
      call IssueImmediateOrder(u,"stop")
      call SetUnitTimeScale(u,1)
      call SetUnitFlyHeight(u,GetUnitDefaultFlyHeight(u),0)
      call SetUnitOwner(u,Player(15),true)
	  call UnitRemoveAbility(u,'Aloc')
	  call PauseUnit(u,true)
      set OPCUnitsCur2=i
      set OPCUnits2[i]=u 
      set OPCUnitsUsed2[h2i(u)-OPCUnitsMinIndex2]=false 
      set OPCMaxunits2=OPCMaxunits2-1	  
   else
     if u!=null then
      call RemoveUnit(u)
     endif
   endif
endif
endfunction

function RecycleGroup takes group g returns nothing
      local integer i=OPCGroupsCur+1
if OPCGroupsUsed[h2i(g)-OPCGroupsMinIndex] then
   if i<0x1fff and g!=null then
      call GroupClear(g)
      set OPCGroupsCur=i
      set OPCGroups[i]=g   
      set OPCGroupsUsed[h2i(g)-OPCGroupsMinIndex]=false  
   else
     if g!=null then
      call DestroyGroup(g)
     endif
   endif
endif
endfunction

//##############################################################
//##    Obj Init Funcs
//##############################################################

function InitTimer takes nothing returns nothing
      local timer t=CreateTimer()
      local integer h=h2i(t)
      local integer i=OPCTimersCur+1
 if h<OPCTimersMinIndex then
      set OPCTimersMinIndex=h
 endif
 if h>OPCTimersMaxIndex then
      set OPCTimersMaxIndex=h
 endif
      set OPCTimersCur=i
      set OPCTimers[i]=t
      set t=null     
endfunction

function InitUnit takes nothing returns nothing
      local unit u=CreateUnit(Player(15),QUCUnitId,QUCDummyX,QUCDummyY,0)
      local integer h=h2i(u)
      local integer i=OPCUnitsCur+1
      call ShowUnit(u,false)
      call SetUnitPathing(u,false)
 if h<OPCUnitsMinIndex then
      set OPCUnitsMinIndex=h
 endif
      set OPCUnitsCur=i
      set OPCUnits[i]=u
      set u=null     
endfunction

function InitUnit2 takes nothing returns nothing
      local unit u=CreateUnit(Player(15),QUCUnit2Id,0,0,0)
      local integer h=h2i(u)
      local integer i=OPCUnitsCur2+1
      call ShowUnit(u,false)
      call SetUnitPathing(u,false)
 if h<OPCUnitsMinIndex2 then
      set OPCUnitsMinIndex2=h
 endif
      set OPCUnitsCur2=i
      set OPCUnits2[i]=u
      set u=null     
endfunction

function InitGroup takes nothing returns nothing
      local group g=CreateGroup()
      local integer h=h2i(g)
      local integer i=OPCGroupsCur+1
 if h<OPCGroupsMinIndex then
      set OPCGroupsMinIndex=h
 endif
      set OPCGroupsCur=i
      set OPCGroups[i]=g   
      set g=null  
endfunction

function TimerInitExec takes nothing returns nothing
  local integer i=1
    loop
      exitwhen i>OPCTimersToInit or i>0x1ffe
       call ExecuteFunc("InitTimer")
       set i=i+1
    endloop
endfunction

function TimerInit takes integer c returns nothing
    set OPCTimersToInit=c
    call ExecuteFunc("TimerInitExec")
endfunction

function UnitInitExec takes nothing returns nothing
  local integer i=1
    loop
      exitwhen i>OPCUnitsToInit or i>0x1ffe
       call ExecuteFunc("InitUnit")
       set i=i+1
    endloop
endfunction

function UnitInit takes integer c returns nothing
    set OPCUnitsToInit=c
    call ExecuteFunc("UnitInitExec")
endfunction

function UnitInit2Exec takes nothing returns nothing
  local integer i=1
    loop
      exitwhen i>OPCUnitsToInit or i>0x1ffe
       call ExecuteFunc("InitUnit2")
       set i=i+1
    endloop
endfunction

function UnitInit2 takes integer c returns nothing
    set OPCUnitsToInit=c
    call ExecuteFunc("UnitInit2Exec")
endfunction

function GroupInitExec takes nothing returns nothing
  local integer i=1
    loop
      exitwhen i>OPCGroupsToInit or i>0x1ffe
       call ExecuteFunc("InitGroup")
       set i=i+1
    endloop
endfunction

function GroupInit takes integer c returns nothing
    set OPCGroupsToInit=c
    call ExecuteFunc("GroupInitExec")
endfunction

//##################################################################
//##                   Toadcop's Quick Unit Cast                  ##
//##################################################################

function QUCRecycle takes nothing returns nothing
   local timer t=GetExpiredTimer()
   local integer tid=h2i(t)-OPCTimersMinIndex
   local unit u=QUCDummyCasters[tid]
   call UnitRemoveAbility(u,QUCAbilId[tid])
   set QUCDummyCasters[tid]=null
   set QUCAbilId[tid]=0
   call RecycleUnit(u)
   call RecycleTimer(t)
endfunction

function RecycleUnitTimed takes unit u,real timeout returns nothing
  if OPCUnitsUsed[h2i(u)-OPCUnitsMinIndex] then
   set etxx=GetTimerBR()
   set eaxx=h2i(etxx)-OPCTimersMinIndex
   set QUCDummyCasters[eaxx]=u
   set QUCAbilId[eaxx]=0
   call TimerStart(etxx,timeout,false,function QUCRecycle)
  endif
endfunction

function QUCRecycle2 takes nothing returns nothing
   local timer t=GetExpiredTimer()
   local integer tid=h2i(t)-OPCTimersMinIndex
   local unit u=QUCDummyCasters[tid]
   set QUCDummyCasters[tid]=null
   call RecycleUnit2(u)
   call RecycleTimer(t)
endfunction

function RecycleUnitTimed2 takes unit u,real timeout returns nothing
  if OPCUnitsUsed2[h2i(u)-OPCUnitsMinIndex2] then
   set etxx=GetTimerBR()
   set eaxx=(h2i(etxx)-OPCTimersMinIndex)
   set QUCDummyCasters[eaxx]=u
   call TimerStart(etxx,timeout,false,function QUCRecycle2)
  endif
endfunction

function CastTargetBR takes player owner,widget target,real x,real y,integer id,string order,integer lvl,real timeout returns boolean
   local unit u=GetUnitBR()
   local timer t=GetTimerBR()
   local integer tid=h2i(t)-OPCTimersMinIndex
   call SetUnitOwner(u,owner,true)
   call SetUnitX(u,x)
   call SetUnitY(u,y)
   call UnitAddAbility(u,id)
   call SetUnitAbilityLevel(u,id,lvl)
   set QUCDummyCasters[tid]=u
   set QUCAbilId[tid]=id
   call TimerStart(t,timeout,false,function QUCRecycle)
if IssueTargetOrder(u,order,target) then
   return true
endif
   return false
endfunction

function CastPointBR takes player owner,real TarX,real TarY,real x,real y,integer id,string order,integer lvl,real timeout returns boolean
   local unit u=GetUnitBR()
   local timer t=GetTimerBR()
   local integer tid=h2i(t)-OPCTimersMinIndex
   call SetUnitOwner(u,owner,true)
   call SetUnitX(u,x)
   call SetUnitY(u,y)
   call UnitAddAbility(u,id)
   call SetUnitAbilityLevel(u,id,lvl)
   set QUCDummyCasters[tid]=u
   set QUCAbilId[tid]=id
   call TimerStart(t,timeout,false,function QUCRecycle)
if IssuePointOrder(u,order,TarX,TarY) then
   return true
endif
   return false
endfunction

function CastInstantBR takes player owner,real x,real y,integer id,string order,integer lvl,real timeout returns boolean
   local unit u=GetUnitBR()
   local timer t=GetTimerBR()
   local integer tid=h2i(t)-OPCTimersMinIndex
   call SetUnitOwner(u,owner,true)
   call SetUnitX(u,x)
   call SetUnitY(u,y)
   call UnitAddAbility(u,id)
   call SetUnitAbilityLevel(u,id,lvl)
   set QUCDummyCasters[tid]=u
   set QUCAbilId[tid]=id
   call TimerStart(t,timeout,false,function QUCRecycle)
if IssueImmediateOrder(u,order) then
   return true
endif
   return false
endfunction

//########################################################
//##   Extra Creation Funcs
//########################################################

function ONLOAD_ClearImagesBX takes nothing returns nothing
    local integer i=1
	//call echo("PREPARE CLEANING "+I2S(stack_images_max))
  loop
    exitwhen i>stack_images_max
	  //call echoAdv("AFTER LOAD "+I2S(h2i(stack_images_tmr[i])-OPCTimersMinIndex))
	  call RecycleTimer(stack_images_tmr[i])
    set i=i+1
  endloop
    set stack_images_max=0
	//call echoAdv(" R E A D Y !")
endfunction

function ONSAVE_ClearImagesBX takes nothing returns nothing
    local integer i=1
  loop
    exitwhen i>stack_images_max
	  call DestroyImage(stack_images[i])
	  call RecycleTimer(stack_images_tmr[i])
	  set stack_images[i]=null
    set i=i+1
  endloop
    set stack_images_max=0
endfunction

function CreateImageBR takes string name,real xsize,real ysize,real zsize,real x,real y,real z,integer Imagetype returns image
    set tmpimg=CreateImage(name,xsize,ysize,zsize,x,y,z,xsize/2,ysize/2,zsize/2,Imagetype)
  if not noubersplats then
    call SetImageRenderAlways(tmpimg,true)
    call ShowImage(tmpimg,true)
  endif
    return tmpimg
endfunction

function RemoveImageTimedBR takes nothing returns nothing
    local timer t=GetExpiredTimer()
    local integer id=h2i(t)-OPCTimersMinIndex
    call DestroyImage(stack_images[stack_images_pos[id]])
    set stack_images[stack_images_pos[id]]=stack_images[stack_images_max]
	set stack_images_tmr[stack_images_pos[id]]=stack_images_tmr[stack_images_max]
    set stack_images_pos[h2i(stack_images_tmr[stack_images_max])-OPCTimersMinIndex]=stack_images_pos[id]
    set stack_images_max=stack_images_max-1
    set Img_max=Img_max-1
    call RecycleTimer(t)
endfunction

function CreateImageTimedBR takes string name,real xsize,real ysize,real zsize,real x,real y,real z,integer Imagetype,real timeout returns nothing
    local timer t=null
    local integer id=0
if x>MapMinX and x<MapMaxX and y>MapMinY and y<MapMaxY then
    set t=GetTimerBR()
    set id=h2i(t)-OPCTimersMinIndex	
    set stack_images_max=stack_images_max+1
    set stack_images[stack_images_max]=CreateImageBR(name,xsize,ysize,zsize,x,y,z,Imagetype)
    set stack_images_pos[id]=stack_images_max
    set stack_images_tmr[stack_images_max]=t
    call TimerStart(t,timeout,false,function RemoveImageTimedBR)
    set Img_max=Img_max+1
endif     
endfunction

//########################################################
//##   Quick Stack
//########################################################

function push takes integer val returns nothing
       set stackindex=stackindex+1
       set stack[stackindex]=val
endfunction

function pop takes nothing returns integer
       local integer popres=stack[stackindex]
       set stack[stackindex]=0
       set stackindex=stackindex-1
      if stackindex<=0 then
       set stackindex=0
      endif
       return popres
endfunction

function pushr takes real val returns nothing
       set stackrindex=stackrindex+1
       set stackr[stackrindex]=val
endfunction

function popr takes nothing returns real
       local real popres=stackr[stackrindex]
       set stackr[stackrindex]=0
       set stackrindex=stackrindex-1
      if stackrindex<=0 then
       set stackrindex=0
      endif
       return popres
endfunction

function pushs takes string val returns nothing
       set stacksindex=stacksindex+1
       set stacks[stacksindex]=val
endfunction

function pops takes nothing returns string
       local string popres=stacks[stacksindex]
       set stacks[stacksindex]=null
       set stacksindex=stacksindex-1
      if stacksindex<=0 then
       set stacksindex=0
      endif
       return popres
endfunction

function pushu takes unit val returns nothing
       set stackuindex=stackuindex+1
       set stacku[stackuindex]=val
endfunction

function popu takes nothing returns unit
       set stackU=stacku[stackuindex]
       set stacku[stackuindex]=null
       set stackuindex=stackuindex-1
      if stackuindex<=0 then
       set stackuindex=0
      endif
       return stackU
endfunction

//##################################################################
//##                     Toadcop's Ultra Buffer                   ##
//##################################################################

constant function UltraModulateBR takes integer i returns integer
   return i-(i/0x03FE0)*0x03FE0
endfunction

function WriteToBufferBR takes integer pos,integer offset,integer i returns nothing
  set eax=pos*0x010+1+offset
if pos>0 then
if pos<0x01ff then
   set UBDx01[eax]=i
elseif pos<0x03fe then
   set UBDx02[eax-0x01FF0]=i
elseif pos<0x05Fd then
   set UBDx03[eax-0x03FE0]=i
elseif pos<0x07FC then
   set UBDx04[eax-0x05Fd0]=i
elseif pos<0x09FB then
   set UBDx05[eax-0x07FC0]=i
elseif pos<0x0BFA then
   set UBDx06[eax-0x09FB0]=i
elseif pos<0x0dF9 then
   set UBDx07[eax-0x0BFA0]=i
elseif pos<0x0FF8 then
   set UBDx08[eax-0x0dF90]=i
elseif pos<0x011F7 then
   set UBDx09[eax-0x0FF80]=i
elseif pos<0x013F6 then
   set UBDx10[eax-0x011F70]=i
elseif pos<0x015F5 then
   set UBDx11[eax-0x013F60]=i
elseif pos<0x017F4 then
   set UBDx12[eax-0x015F50]=i
elseif pos<0x019F3 then
   set UBDx13[eax-0x017F40]=i
elseif pos<0x01BF2 then
   set UBDx14[eax-0x019F30]=i
elseif pos<0x01dF1 then
   set UBDx15[eax-0x01BF20]=i
elseif pos<0x01FF0 then
   set UBDx16[eax-0x01dF10]=i
elseif pos<0x021EF then
   set UBDx17[eax-0x01FF00]=i
elseif pos<0x023EE then
   set UBDx18[eax-0x021EF0]=i
elseif pos<0x025Ed then
   set UBDx19[eax-0x023EE0]=i
elseif pos<0x027EC then
   set UBDx20[eax-0x025Ed0]=i
elseif pos<0x029EB then
   set UBDx21[eax-0x027EC0]=i
elseif pos<0x02BEA then
   set UBDx22[eax-0x029EB0]=i
elseif pos<0x02dE9 then
   set UBDx23[eax-0x02BEA0]=i
elseif pos<0x02FE8 then
   set UBDx24[eax-0x02dE90]=i
elseif pos<0x031E7 then
   set UBDx25[eax-0x02FE80]=i
elseif pos<0x033E6 then
   set UBDx26[eax-0x031E70]=i
elseif pos<0x035E5 then
   set UBDx27[eax-0x033E60]=i
elseif pos<0x037E4 then
   set UBDx28[eax-0x035E50]=i
elseif pos<0x039E3 then
   set UBDx29[eax-0x037E40]=i
elseif pos<0x03BE2 then
   set UBDx30[eax-0x039E30]=i
elseif pos<0x03dE1 then
   set UBDx31[eax-0x03BE20]=i
elseif pos<0x03FE0 then
   set UBDx32[eax-0x03dE10]=i
endif
endif
endfunction

function GetFromBufferBR takes integer pos,integer offset returns integer
  set eax=pos*0x010+1+offset
if pos>0 then
if pos<0x01ff then
   return UBDx01[eax]
elseif pos<0x03fe then
   return UBDx02[eax-0x01FF0]
elseif pos<0x05FD then
   return UBDx03[eax-0x03FE0]
elseif pos<0x07FC then
   return UBDx04[eax-0x05FD0]
elseif pos<0x09FB then
   return UBDx05[eax-0x07FC0]
elseif pos<0x0BFA then
   return UBDx06[eax-0x09FB0]
elseif pos<0x0DF9 then
   return UBDx07[eax-0x0BFA0]
elseif pos<0x0FF8 then
   return UBDx08[eax-0x0DF90]
elseif pos<0x011F7 then
   return UBDx09[eax-0x0FF80]
elseif pos<0x013F6 then
   return UBDx10[eax-0x011F70]
elseif pos<0x015F5 then
   return UBDx11[eax-0x013F60]
elseif pos<0x017F4 then
   return UBDx12[eax-0x015F50]
elseif pos<0x019F3 then
   return UBDx13[eax-0x017F40]
elseif pos<0x01BF2 then
   return UBDx14[eax-0x019F30]
elseif pos<0x01DF1 then
   return UBDx15[eax-0x01BF20]
elseif pos<0x01FF0 then
   return UBDx16[eax-0x01DF10]
elseif pos<0x021EF then
   return UBDx17[eax-0x01FF00]
elseif pos<0x023EE then
   return UBDx18[eax-0x021EF0]
elseif pos<0x025ED then
   return UBDx19[eax-0x023EE0]
elseif pos<0x027EC then
   return UBDx20[eax-0x025ED0]
elseif pos<0x029EB then
   return UBDx21[eax-0x027EC0]
elseif pos<0x02BEA then
   return UBDx22[eax-0x029EB0]
elseif pos<0x02DE9 then
   return UBDx23[eax-0x02BEA0]
elseif pos<0x02FE8 then
   return UBDx24[eax-0x02DE90]
elseif pos<0x031E7 then
   return UBDx25[eax-0x02FE80]
elseif pos<0x033E6 then
   return UBDx26[eax-0x031E70]
elseif pos<0x035E5 then
   return UBDx27[eax-0x033E60]
elseif pos<0x037E4 then
   return UBDx28[eax-0x035E50]
elseif pos<0x039E3 then
   return UBDx29[eax-0x037E40]
elseif pos<0x03BE2 then
   return UBDx30[eax-0x039E30]
elseif pos<0x03DE1 then
   return UBDx31[eax-0x03BE20]
elseif pos<0x03FE0 then
   return UBDx32[eax-0x03DE10]
endif
endif
return 0
endfunction

function ClearBufferBR takes integer i returns nothing
  local integer c=0
  local integer limit=0x0f
if i>0 then
   loop
    exitwhen c>limit
     call WriteToBufferBR(i,c,0)
     set c=c+1
   endloop
endif
endfunction

function WriteToUBSBR takes integer pos,integer offset,integer data returns nothing
  set eax=pos*0x010+1+offset
if pos>0 then
if pos<0x01ff then
   set UBStackDx01[eax]=data
elseif pos<0x03fe then
   set UBStackDx02[eax-0x01FF0]=data
elseif pos<0x05FD then
   set UBStackDx03[eax-0x03FE0]=data
elseif pos<0x07FC then
   set UBStackDx04[eax-0x05FD0]=data
elseif pos<0x09FB then
   set UBStackDx05[eax-0x07FC0]=data
elseif pos<0x0BFA then
   set UBStackDx06[eax-0x09FB0]=data
elseif pos<0x0DF9 then
   set UBStackDx07[eax-0x0BFA0]=data
elseif pos<0x0FF8 then
   set UBStackDx08[eax-0x0DF90]=data
elseif pos<0x011F7 then
   set UBStackDx09[eax-0x0FF80]=data
elseif pos<0x013F6 then
   set UBStackDx10[eax-0x011F70]=data
elseif pos<0x015F5 then
   set UBStackDx11[eax-0x013F60]=data
elseif pos<0x017F4 then
   set UBStackDx12[eax-0x015F50]=data
elseif pos<0x019F3 then
   set UBStackDx13[eax-0x017F40]=data
elseif pos<0x01BF2 then
   set UBStackDx14[eax-0x019F30]=data
elseif pos<0x01DF1 then
   set UBStackDx15[eax-0x01BF20]=data
elseif pos<0x01FF0 then
   set UBStackDx16[eax-0x01DF10]=data
elseif pos<0x021EF then
   set UBStackDx17[eax-0x01FF00]=data
elseif pos<0x023EE then
   set UBStackDx18[eax-0x021EF0]=data
elseif pos<0x025ED then
   set UBStackDx19[eax-0x023EE0]=data
elseif pos<0x027EC then
   set UBStackDx20[eax-0x025ED0]=data
elseif pos<0x029EB then
   set UBStackDx21[eax-0x027EC0]=data
elseif pos<0x02BEA then
   set UBStackDx22[eax-0x029EB0]=data
elseif pos<0x02DE9 then
   set UBStackDx23[eax-0x02BEA0]=data
elseif pos<0x02FE8 then
   set UBStackDx24[eax-0x02DE90]=data
elseif pos<0x031E7 then
   set UBStackDx25[eax-0x02FE80]=data
elseif pos<0x033E6 then
   set UBStackDx26[eax-0x031E70]=data
elseif pos<0x035E5 then
   set UBStackDx27[eax-0x033E60]=data
elseif pos<0x037E4 then
   set UBStackDx28[eax-0x035E50]=data
elseif pos<0x039E3 then
   set UBStackDx29[eax-0x037E40]=data
elseif pos<0x03BE2 then
   set UBStackDx30[eax-0x039E30]=data
elseif pos<0x03DE1 then
   set UBStackDx31[eax-0x03BE20]=data
elseif pos<0x03FE0 then
   set UBStackDx32[eax-0x03DE10]=data
endif
endif
endfunction

function GetFromUBSBR takes integer pos,integer offset returns integer
 set eax=pos*0x010+1+offset
if pos>0 then
if pos<0x01ff then
   return UBStackDx01[eax]
elseif pos<0x03fe then
   return UBStackDx02[eax-0x01FF0]
elseif pos<0x05FD then
   return UBStackDx03[eax-0x03FE0]
elseif pos<0x07FC then
   return UBStackDx04[eax-0x05FD0]
elseif pos<0x09FB then
   return UBStackDx05[eax-0x07FC0]
elseif pos<0x0BFA then
   return UBStackDx06[eax-0x09FB0]
elseif pos<0x0DF9 then
   return UBStackDx07[eax-0x0BFA0]
elseif pos<0x0FF8 then
   return UBStackDx08[eax-0x0DF90]
elseif pos<0x011F7 then
   return UBStackDx09[eax-0x0FF80]
elseif pos<0x013F6 then
   return UBStackDx10[eax-0x011F70]
elseif pos<0x015F5 then
   return UBStackDx11[eax-0x013F60]
elseif pos<0x017F4 then
   return UBStackDx12[eax-0x015F50]
elseif pos<0x019F3 then
   return UBStackDx13[eax-0x017F40]
elseif pos<0x01BF2 then
   return UBStackDx14[eax-0x019F30]
elseif pos<0x01DF1 then
   return UBStackDx15[eax-0x01BF20]
elseif pos<0x01FF0 then
   return UBStackDx16[eax-0x01DF10]
elseif pos<0x021EF then
   return UBStackDx17[eax-0x01FF00]
elseif pos<0x023EE then
   return UBStackDx18[eax-0x021EF0]
elseif pos<0x025ED then
   return UBStackDx19[eax-0x023EE0]
elseif pos<0x027EC then
   return UBStackDx20[eax-0x025ED0]
elseif pos<0x029EB then
   return UBStackDx21[eax-0x027EC0]
elseif pos<0x02BEA then
   return UBStackDx22[eax-0x029EB0]
elseif pos<0x02DE9 then
   return UBStackDx23[eax-0x02BEA0]
elseif pos<0x02FE8 then
   return UBStackDx24[eax-0x02DE90]
elseif pos<0x031E7 then
   return UBStackDx25[eax-0x02FE80]
elseif pos<0x033E6 then
   return UBStackDx26[eax-0x031E70]
elseif pos<0x035E5 then
   return UBStackDx27[eax-0x033E60]
elseif pos<0x037E4 then
   return UBStackDx28[eax-0x035E50]
elseif pos<0x039E3 then
   return UBStackDx29[eax-0x037E40]
elseif pos<0x03BE2 then
   return UBStackDx30[eax-0x039E30]
elseif pos<0x03DE1 then
   return UBStackDx31[eax-0x03BE20]
elseif pos<0x03FE0 then
   return UBStackDx32[eax-0x03DE10]
endif
endif
return 0
endfunction

function GetFreeUBSBR takes nothing returns integer
   local integer i=0
if UBstackfreeindex>0 then
   set i=UBstackfree[UBstackfreeindex]
   set UBstackfree[UBstackfreeindex]=0
   set UBstackfreeindex=UBstackfreeindex-1
   return i
else
   set UBstackindex=UBstackindex+1
   return UBstackindex
endif
  return 0
endfunction

function ClearUBSBR takes integer i returns nothing
  local integer c=0
  local integer limit=0x0f
if i>0 then
   loop
    exitwhen c>limit
     call WriteToUBSBR(i,c,0)
     set c=c+1
   endloop
endif
endfunction

function SetFreeUBSBR takes integer i returns nothing
if i>0 then
   call ClearUBSBR(i)
   set UBstackfreeindex=UBstackfreeindex+1
   set UBstackfree[UBstackfreeindex]=i
endif
endfunction

function TrkAttachBR takes integer h,integer i returns nothing
   set h=Modulo(h,0x1FFF0)
 if h<0x1FFF then  
   set TrkAttachInt0x00[h]=i
 elseif h<0x3FFE then
   set TrkAttachInt0x01[h-0x1FFF]=i
 elseif h<0x5FFD then
   set TrkAttachInt0x02[h-0x3FFE]=i
 elseif h<0x7FFC then
   set TrkAttachInt0x03[h-0x5FFD]=i
 elseif h<0x9FFB then
   set TrkAttachInt0x04[h-0x7FFC]=i
 elseif h<0xBFFA then
   set TrkAttachInt0x05[h-0x9FFB]=i
 elseif h<0xDFF9 then
   set TrkAttachInt0x06[h-0xBFFA]=i
 elseif h<0xFFF8 then
   set TrkAttachInt0x07[h-0xDFF9]=i
 elseif h<0x11FF7 then
   set TrkAttachInt0x08[h-0xFFF8]=i
 elseif h<0x13FF6 then
   set TrkAttachInt0x09[h-0x11FF7]=i
 elseif h<0x15FF5 then
   set TrkAttachInt0x10[h-0x13FF6]=i
 elseif h<0x17FF4 then
   set TrkAttachInt0x11[h-0x15FF5]=i
 elseif h<0x19FF3 then
   set TrkAttachInt0x12[h-0x17FF4]=i
 elseif h<0x1BFF2 then
   set TrkAttachInt0x13[h-0x19FF3]=i
 elseif h<0x1DFF1 then
   set TrkAttachInt0x14[h-0x1BFF2]=i
 elseif h<0x1FFF0 then
   set TrkAttachInt0x15[h-0x1DFF1]=i
 endif
endfunction

function TrkGetAttachBR takes integer h returns integer
   set h=Modulo(h,0x1FFF0)
 if h<0x1FFF then  
   return TrkAttachInt0x00[h]
 elseif h<0x3FFE then
   return TrkAttachInt0x01[h-0x1FFF]
 elseif h<0x5FFD then
   return TrkAttachInt0x02[h-0x3FFE]
 elseif h<0x7FFC then
   return TrkAttachInt0x03[h-0x5FFD]
 elseif h<0x9FFB then
   return TrkAttachInt0x04[h-0x7FFC]
 elseif h<0xBFFA then
   return TrkAttachInt0x05[h-0x9FFB]
 elseif h<0xDFF9 then
   return TrkAttachInt0x06[h-0xBFFA]
 elseif h<0xFFF8 then
   return TrkAttachInt0x07[h-0xDFF9]
 elseif h<0x11FF7 then
   return TrkAttachInt0x08[h-0xFFF8]
 elseif h<0x13FF6 then
   return TrkAttachInt0x09[h-0x11FF7]
 elseif h<0x15FF5 then
   return TrkAttachInt0x10[h-0x13FF6]
 elseif h<0x17FF4 then
   return TrkAttachInt0x11[h-0x15FF5]
 elseif h<0x19FF3 then
   return TrkAttachInt0x12[h-0x17FF4]
 elseif h<0x1BFF2 then
   return TrkAttachInt0x13[h-0x19FF3]
 elseif h<0x1DFF1 then
   return TrkAttachInt0x14[h-0x1BFF2]
 elseif h<0x1FFF0 then
   return TrkAttachInt0x15[h-0x1DFF1]
 endif
   return 0
endfunction

//##################################################################
//##               Toadcop's Xtream Dynamic Groups                ##           
//##################################################################

//## Tc's XDG ##

// Pure sys funcs
function XFreeIndexBR takes integer in returns nothing
    set XMaxg=XMaxg+1
    set XFreegroup[XMaxg]=in    
endfunction

function XFreeUnitIndexBR takes integer in returns nothing
    set XMaxs=XMaxs+1
    set XFreeslots[XMaxs]=in    
endfunction

function GetFreeUnitSlotXBR takes nothing returns integer
    local integer i=XMaxFrees
 if i>0 then
    set XMaxFrees=XMaxFrees-1
    return XFreeslots[i]
 else
    set XMaxs=XMaxs+1
    return XMaxs
 endif
    return 0
endfunction

// Create Xgroup - like CreateGroup()
//#####
function CreateGroupXBR takes nothing returns integer
    local integer i=XMaxFreeg
 if i>0 then
    set XMaxFreeg=XMaxFreeg-1
    return XFreegroup[i]
 else
    set XMaxg=XMaxg+1
    return XMaxg
 endif
    return 0
endfunction

// DESTROY Xgroup - like DestroyGroup()
//#####
function DestroyGroupXBR takes integer g returns nothing
local integer i=1
local integer c=Xgroup[g]
if c!=0 then
loop
   exitwhen i>XMaxCount[g]
     set Xgunits[c]=null
     call XFreeUnitIndexBR(c)
     set c=XNextIndex[c]
   set i=i+1
endloop
    set Xgroup[g]=0
    set XLastIndex[g]=0
    call XFreeIndexBR(g)
    call FlushStoredMission(XDG,I2S(g))
endif
endfunction

// Add Unit to Xgroup - like GroupAddUnit()
//#####
function GroupAddXBR takes integer g,unit u returns integer
    local integer b=Xgroup[g]
    local integer s=0
    local string sg=I2S(g)
    local string su=I2S(h2i(u))
if GetStoredInteger(XDG,sg,su)==0 then
if b==0 then
    set b=GetFreeUnitSlotXBR()
    set Xgroup[g]=b
    set XPrevIndex[b]=0
    set XNextIndex[b]=0
    set Xgunits[b]=u
    set XLastIndex[g]=b
    set XMaxCount[g]=XMaxCount[g]+1
    call StoreInteger(XDG,sg,su,b)
    return b
else
    set s=GetFreeUnitSlotXBR()
    set b=XLastIndex[g]
    set XPrevIndex[s]=b
    set XNextIndex[s]=0
    set XNextIndex[b]=s
    set Xgunits[s]=u
    set XLastIndex[g]=s
    call StoreInteger(XDG,sg,su,s)
    set XMaxCount[g]=XMaxCount[g]+1
    return s
endif
endif
    return 0
endfunction

// Remove Unit from Xgroup - like GroupRemoveUnit()
//#####
function GroupRemoveXBR takes integer g,unit u returns nothing
    local integer b=Xgroup[g]
    local integer s=0
    local integer i=0
    local string sg=I2S(g)
    local string su=I2S(h2i(u))
    local integer pos=GetStoredInteger(XDG,sg,su)
if pos!=0 then
    set XMaxCount[g]=XMaxCount[g]-1
 if pos==XLastIndex[g] then
    set i=XPrevIndex[pos]
    set XNextIndex[i]=0
    set XLastIndex[g]=i
    set Xgunits[pos]=null
    set XNextIndex[pos]=0
    set XPrevIndex[pos]=0
    call XFreeUnitIndexBR(pos)
    call StoreInteger(XDG,sg,su,0)
 else
    set i=XPrevIndex[XLastIndex[g]]
    set u=Xgunits[XLastIndex[g]]
    set Xgunits[pos]=u
    set XNextIndex[i]=0
    set Xgunits[XLastIndex[g]]=null
    set XNextIndex[XLastIndex[g]]=0
    set XPrevIndex[XLastIndex[g]]=0
    call XFreeUnitIndexBR(XLastIndex[g])
    set XLastIndex[g]=i
    call StoreInteger(XDG,sg,I2S(h2i(u)),pos)
    call StoreInteger(XDG,sg,su,0)
 endif
 if XMaxCount[g]==0 then
    set Xgroup[g]=0
 endif
endif
endfunction

// Clear XGroup DON'T DESTROY IT ! - like GroupClear()
//#####
function GroupClearXBR takes integer g returns nothing
local integer i=1
local integer c=Xgroup[g]
if c!=0 then
loop
   exitwhen i>XMaxCount[g]
     set Xgunits[c]=null
     call XFreeUnitIndexBR(c)
     set c=XNextIndex[c]
   set i=i+1
endloop
    set Xgroup[g]=0
    set XLastIndex[g]=0
    call FlushStoredMission(XDG,I2S(g))
endif
endfunction

// Check if this unit is in this Xgroup - like IsUnitInGroup()
//#####
function IsUnitInGroupXBR takes unit u,integer g returns boolean
  if GetStoredInteger(XDG,I2S(g),I2S(h2i(u)))>0 then
    return true
  endif
    return false
endfunction

// Check how many units are in Xgroup - like lame BJ func CountUnitsInGroup() but X times faster ! (i mean a huge X times from 10 to maybe 1000 !!! if group is large)
//#####
function UnitCountInGroupXBR takes integer g returns integer
    return XMaxCount[g]
endfunction

// Return first unit in Xgroup - like FirstOfGroup()
//#####
function FirstOfGroupXBR takes integer g returns unit
    return Xgunits[Xgroup[g]]
endfunction

// Return last unit in Xgroup - no alternatives...
//#####
function LastOfGroupXBR takes integer g returns unit
    return Xgunits[XLastIndex[g]]
endfunction

//###############################################################
//############### Begin of Toadcop's USP Function ###############
//###############################################################

function InitUSPBR takes nothing returns nothing
    set USPData=InitGameCache("USPDataStore.bx")
/*
  if trs_chars==null then
    set trs_chars=InitHashtable()
  endif
*/
    set ANSI[48]="0"
    set ANSI[49]="1"
    set ANSI[50]="2"
    set ANSI[51]="3"
    set ANSI[52]="4"
    set ANSI[53]="5"
    set ANSI[54]="6"
    set ANSI[55]="7"
    set ANSI[56]="8"
    set ANSI[57]="9"
/*
    call SaveInteger(trs_chars,256,StringHash("0"),48)
    call SaveInteger(trs_chars,256,StringHash("1"),49)
    call SaveInteger(trs_chars,256,StringHash("2"),50)
    call SaveInteger(trs_chars,256,StringHash("3"),51)
    call SaveInteger(trs_chars,256,StringHash("4"),52)
    call SaveInteger(trs_chars,256,StringHash("5"),53)
    call SaveInteger(trs_chars,256,StringHash("6"),54)
    call SaveInteger(trs_chars,256,StringHash("7"),55)
    call SaveInteger(trs_chars,256,StringHash("8"),56)
    call SaveInteger(trs_chars,256,StringHash("9"),57)
*/
    set ANSI[65]="A"
    set ANSI[66]="B"
    set ANSI[67]="C"
    set ANSI[68]="D"
    set ANSI[69]="E"
    set ANSI[70]="F"
    set ANSI[71]="G"
    set ANSI[72]="H"
    set ANSI[73]="I"
    set ANSI[74]="J"
    set ANSI[75]="K"
    set ANSI[76]="L"
    set ANSI[77]="M"
    set ANSI[78]="N"
    set ANSI[79]="O"
    set ANSI[80]="P"
    set ANSI[81]="Q"
    set ANSI[82]="R"
    set ANSI[83]="S"
    set ANSI[84]="T"
    set ANSI[85]="U"
    set ANSI[86]="V"
    set ANSI[87]="W"
    set ANSI[88]="X"
    set ANSI[89]="Y"
    set ANSI[90]="Z"
/*
    call SaveInteger(trs_chars,256,StringHash("A"),65)
    call SaveInteger(trs_chars,256,StringHash("B"),66)
    call SaveInteger(trs_chars,256,StringHash("C"),67)
    call SaveInteger(trs_chars,256,StringHash("D"),68)
    call SaveInteger(trs_chars,256,StringHash("E"),69)
    call SaveInteger(trs_chars,256,StringHash("F"),70)
    call SaveInteger(trs_chars,256,StringHash("G"),71)
    call SaveInteger(trs_chars,256,StringHash("H"),72)
    call SaveInteger(trs_chars,256,StringHash("I"),73)
    call SaveInteger(trs_chars,256,StringHash("J"),74)
    call SaveInteger(trs_chars,256,StringHash("K"),75)
    call SaveInteger(trs_chars,256,StringHash("L"),76)
    call SaveInteger(trs_chars,256,StringHash("M"),77)
    call SaveInteger(trs_chars,256,StringHash("N"),78)
    call SaveInteger(trs_chars,256,StringHash("O"),79)
    call SaveInteger(trs_chars,256,StringHash("P"),80)
    call SaveInteger(trs_chars,256,StringHash("Q"),81)
    call SaveInteger(trs_chars,256,StringHash("R"),82)
    call SaveInteger(trs_chars,256,StringHash("S"),83)
    call SaveInteger(trs_chars,256,StringHash("T"),84)
    call SaveInteger(trs_chars,256,StringHash("U"),85)
    call SaveInteger(trs_chars,256,StringHash("V"),86)
    call SaveInteger(trs_chars,256,StringHash("W"),87)
    call SaveInteger(trs_chars,256,StringHash("X"),88)
    call SaveInteger(trs_chars,256,StringHash("Y"),89)
    call SaveInteger(trs_chars,256,StringHash("Z"),90)
*/
    set ANSI[97]="a"
    set ANSI[98]="b"
    set ANSI[99]="c"
    set ANSI[100]="d"
    set ANSI[101]="e"
    set ANSI[102]="f"
    set ANSI[103]="g"
    set ANSI[104]="h"
    set ANSI[105]="i"
    set ANSI[106]="j"
    set ANSI[107]="k"
    set ANSI[108]="l"
    set ANSI[109]="m"
    set ANSI[110]="n"
    set ANSI[111]="o"
    set ANSI[112]="p"
    set ANSI[113]="q"
    set ANSI[114]="r"
    set ANSI[115]="s"
    set ANSI[116]="t"
    set ANSI[117]="u"
    set ANSI[118]="v"
    set ANSI[119]="w"
    set ANSI[120]="x"
    set ANSI[121]="y"
    set ANSI[122]="z"

/*
    call SaveInteger(trs_chars,256,StringHash("a"),97)
    call SaveInteger(trs_chars,256,StringHash("b"),98)
    call SaveInteger(trs_chars,256,StringHash("c"),99)
    call SaveInteger(trs_chars,256,StringHash("d"),100)
    call SaveInteger(trs_chars,256,StringHash("e"),101)
    call SaveInteger(trs_chars,256,StringHash("f"),102)
    call SaveInteger(trs_chars,256,StringHash("g"),103)
    call SaveInteger(trs_chars,256,StringHash("h"),104)
    call SaveInteger(trs_chars,256,StringHash("i"),105)
    call SaveInteger(trs_chars,256,StringHash("j"),106)
    call SaveInteger(trs_chars,256,StringHash("k"),107)
    call SaveInteger(trs_chars,256,StringHash("l"),108)
    call SaveInteger(trs_chars,256,StringHash("m"),109)
    call SaveInteger(trs_chars,256,StringHash("n"),110)
    call SaveInteger(trs_chars,256,StringHash("o"),111)
    call SaveInteger(trs_chars,256,StringHash("p"),112)
    call SaveInteger(trs_chars,256,StringHash("q"),113)
    call SaveInteger(trs_chars,256,StringHash("r"),114)
    call SaveInteger(trs_chars,256,StringHash("s"),115)
    call SaveInteger(trs_chars,256,StringHash("t"),116)
    call SaveInteger(trs_chars,256,StringHash("u"),117)
    call SaveInteger(trs_chars,256,StringHash("v"),118)
    call SaveInteger(trs_chars,256,StringHash("w"),119)
    call SaveInteger(trs_chars,256,StringHash("x"),120)
    call SaveInteger(trs_chars,256,StringHash("y"),121)
    call SaveInteger(trs_chars,256,StringHash("z"),122)

*/
    set HEX[0]="0"
    set HEX[1]="1"
    set HEX[2]="2"
    set HEX[3]="3"
    set HEX[4]="4"
    set HEX[5]="5"
    set HEX[6]="6"
    set HEX[7]="7"
    set HEX[8]="8"
    set HEX[9]="9"
    set HEX[10]="a"
    set HEX[11]="b"
    set HEX[12]="c"
    set HEX[13]="d"
    set HEX[14]="e"
    set HEX[15]="f"
  /*
    call SaveInteger(trs_chars,16,StringHash("0"),0)
    call SaveInteger(trs_chars,16,StringHash("1"),1)
    call SaveInteger(trs_chars,16,StringHash("2"),2)
    call SaveInteger(trs_chars,16,StringHash("3"),3)
    call SaveInteger(trs_chars,16,StringHash("4"),4)
    call SaveInteger(trs_chars,16,StringHash("5"),5)
    call SaveInteger(trs_chars,16,StringHash("6"),6)
    call SaveInteger(trs_chars,16,StringHash("7"),7)
    call SaveInteger(trs_chars,16,StringHash("8"),8)
    call SaveInteger(trs_chars,16,StringHash("9"),9)
    call SaveInteger(trs_chars,16,StringHash("a"),10)
    call SaveInteger(trs_chars,16,StringHash("A"),10)
    call SaveInteger(trs_chars,16,StringHash("b"),11)
    call SaveInteger(trs_chars,16,StringHash("B"),11)
    call SaveInteger(trs_chars,16,StringHash("c"),12)
    call SaveInteger(trs_chars,16,StringHash("C"),12)
    call SaveInteger(trs_chars,16,StringHash("d"),13)
    call SaveInteger(trs_chars,16,StringHash("D"),13)
    call SaveInteger(trs_chars,16,StringHash("e"),14)
    call SaveInteger(trs_chars,16,StringHash("E"),14)
    call SaveInteger(trs_chars,16,StringHash("f"),15)
    call SaveInteger(trs_chars,16,StringHash("F"),15)
*/
    set USPInited=true
endfunction

function I2ASCExec takes nothing returns nothing
   local integer i=eax
   set esx=ANSI[i/0x1000000]+ANSI[Modulo(i/0x10000,0x100)]+ANSI[Modulo(i/0x100,0x100)]+ANSI[Modulo(i,0x100)]
endfunction

function I2ASC takes integer i returns string
    set eax=i
    call ExecuteFunc("I2ASCExec")
    return esx
endfunction

function ASC2IExec takes nothing returns nothing
    local string s=esx
    set eax=ANSI2[s2i(SubString(s,0,1))]*0x1000000+ANSI2[s2i(SubString(s,1,2))]*0x10000+ANSI2[s2i(SubString(s,2,3))]*0x100+ANSI2[s2i(SubString(s,3,4))]
endfunction

function ASC2I takes string s returns integer
    set esx=s
    call ExecuteFunc("ASC2IExec")
    return eax
endfunction

function S2HEXExec takes nothing returns nothing
    local string s=esx
    local integer sl=StringLength(s)
    local integer i=1
    local integer i2=0
    local integer pow=0
loop
  exitwhen i>sl
    set pow=R2I(Pow(0x10,sl-i))
    set i2=i2+HEX2[s2i(SubString(s,i-1,i))]*pow 
  set i=i+1
endloop
    set eax=i2
endfunction

function S2HEX takes string s returns integer
    set esx=s
    call ExecuteFunc("S2HEXExec")
    return eax
endfunction

function S2HEXExec2 takes nothing returns nothing
    local string s=esx
    local integer sl=eax-eaxx
    local integer i=1
    local integer i2=0
    local integer pow=0
loop
  exitwhen i>sl
    set pow=R2I(Pow(0x10,sl-i))
    set i2=i2+HEX2[s2i(SubString(s,eaxx+i-2,eaxx+i-1))]*pow 
  set i=i+1
endloop
    set eax=i2
endfunction

function S2HEX2 takes string s,integer min,integer max returns integer
    set esx=s
    set eaxx=min
    set eax=max
    call ExecuteFunc("S2HEXExec2")
    return eax
endfunction

function ASC2IExec2 takes nothing returns nothing
    local string s=esx
    set eax=ANSI2[s2i(SubString(s,eaxx-1,eaxx))]*0x1000000+ANSI2[s2i(SubString(s,eaxx,eaxx+1))]*0x10000+ANSI2[s2i(SubString(s,eaxx+1,eaxx+2))]*0x100+ANSI2[s2i(SubString(s,eaxx+2,eaxx+3))]
endfunction

function ASC2I2 takes string s,integer min returns integer
    set esx=s
    set eaxx=min
    call ExecuteFunc("ASC2IExec2")
    return eax
endfunction

function GetIntBitwiseBR takes string STR,integer a,integer b returns integer
    local integer bc=b
    local integer m=1
    local integer t=0
    local string s=null
  loop
   exitwhen bc<=a
   set s=SubString(STR,bc-1,bc)
   set t=t+(S2I(s)*m)
if s=="-" then
   set t=t*(-1)
endif
   set m=m*10
   set bc=bc-1
  endloop
    return t
endfunction

function GetRealBitwiseBR takes string STR,integer a,integer b returns real
    local integer bc=b
    local real m=1.0
    local real t=0.0
    local real t2=0.0
    local string s=null
  loop
   exitwhen bc<=a
   set s=SubString(STR,bc-1,bc)
if s=="-" then
   set t=t*(-1.0)
   set t2=t2*(-1.0)
elseif s=="." then
   set t2=t/(m)
   set bc=bc-1
   set s=SubString(STR,bc-1,bc)
   set m=1.0
   set t=0.0
endif
   set t=t+(S2R(s)*m)
   set m=m*10.0
   set bc=bc-1
  endloop
    set t=t+t2
    return t
endfunction

function DefaultPointersBR takes nothing returns nothing
     set USPIsStringPointer="$"
     set USPDataSetPointer="^"
     set USPSetPointer="="
     set USPHexPointer="0x"
     set USPRealPointer="."
     set USPRAWPointer="'"
     set USPRandomPointer="~"
     set USPDynRandomPointer="?"
     set USPEndPointer=";"
endfunction

function TcUSPBR takes integer h,string Exh,string STR,boolean Add,boolean Minus,string CusInt,string CusReal,string CusStr,boolean bitwise,gamecache gc returns nothing
    local string CurToken=null
    local string x2=null
    local string temp=null
    local string s2=null
    local string Stat=null
    local string sh=I2S(h)+Exh
    local integer dset=0
    local integer dn=0
    local integer itemp=0
    local integer imin=0
    local integer imax=0
    local integer pointer=0
    local integer i=0
    local integer lng=StringLength(STR)
    local boolean min=false
    local boolean hex=false
    local boolean float=false
    local boolean ansi=false
    local boolean dyn=false
    local boolean b=false
    local real rmin=0
    local real rmax=0
    local real rtemp=0
if USPInited==false then
    call ExecuteFunc("InitUSPBR")
endif 
if gc==null then
    set gc=USPData
endif
loop
  exitwhen i>lng
    set USParray=false
    set USPStat=null
    set USPsval=null
    set USParrayindex=0
    set USPimin=0
    set USPimax=0
    set USPival=0
    set USPrmin=0
    set USPrmax=0 
    set USPrval=0
    set USPdyn=false
    set USPid=0
    set USPAdd=false
    set USPMinus=false
    set CurToken=SubString(STR,i,i+1)
    set s2=SubString(STR,pointer,pointer+1)
    set x2=SubString(STR,i,i+2)
    set b=s2!=USPIsStringPointer
if dset==0 then
  if CurToken==USPDataSetPointer then
       set temp=SubString(STR,0,i)
     if temp!="" then
       call StoreString(gc,sh,"LongString",temp)
     endif
       set pointer=i+1
       set dset=1
  endif
elseif dset==1 then
if CurToken==USPDataSetPointer and b then
       set pointer=i+1
       set dset=2
elseif CurToken==USPSetPointer and b then
       set Stat=SubString(STR,pointer,i)
       set pointer=i+1
elseif x2==USPHexPointer and b then
       set pointer=i+2
       set hex=true
elseif CurToken==USPRealPointer and b then
       set float=true
elseif CurToken==USPRAWPointer and b then
    if ansi==false then
       set pointer=i+1
    endif
       set ansi=true
elseif (CurToken==USPRandomPointer or CurToken==USPDynRandomPointer) and b then
     if CurToken==USPDynRandomPointer then
        set dyn=true
     endif
     if hex then
        set imin=S2HEX2(STR,pointer+1,i+1)
        set rmin=imin
        set hex=false
     elseif ansi then
        set imin=ASC2I2(STR,pointer+1)
        set rmin=imin
        set ansi=false
     elseif float then
       if bitwise then
        set rmin=GetRealBitwiseBR(STR,pointer,i)
       else
        set rmin=S2R(SubString(STR,pointer,i))
       endif
     else
       if bitwise then
        set imin=GetIntBitwiseBR(STR,pointer,i)
       else
        set imin=S2I(SubString(STR,pointer,i))
       endif
        set rmin=imin
     endif
        set pointer=i+1
        set min=true
elseif CurToken==USPEndPointer then
  if b then
      if hex then
        set imax=S2HEX2(STR,pointer+1,i+1)
        set rmax=imax
        set hex=false
      elseif ansi then
        set imax=ASC2I2(STR,pointer+1)
        set rmax=imax
        set ansi=false
      elseif float then
       if bitwise then
        set rmax=GetRealBitwiseBR(STR,pointer,i)
       else
        set rmax=S2R(SubString(STR,pointer,i))
       endif
      else
       if bitwise then
        set imax=GetIntBitwiseBR(STR,pointer,i)
       else
        set imax=S2I(SubString(STR,pointer,i))
       endif
      endif
    if min then
     if dyn then
      if float then
 if CusReal==null then
        if Add then
          if Minus then
              call StoreReal(gc,sh,Stat+"min",GetStoredReal(gc,sh,Stat+"min")-rmin)
              call StoreReal(gc,sh,Stat+"max",GetStoredReal(gc,sh,Stat+"max")-rmax)
          else
              call StoreReal(gc,sh,Stat+"min",GetStoredReal(gc,sh,Stat+"min")+rmin)
              call StoreReal(gc,sh,Stat+"max",GetStoredReal(gc,sh,Stat+"max")+rmax)            
          endif
        else
          if Minus then
              call StoreReal(gc,sh,Stat+"min",-rmin)
              call StoreReal(gc,sh,Stat+"max",-rmax)
          else
              call StoreReal(gc,sh,Stat+"min",rmin)
              call StoreReal(gc,sh,Stat+"max",rmax)             
          endif
        endif
 else
      set USPStat=Stat
      set USPsval=null
      set USPival=0
      set USPrmin=rmin
      set USPrmax=rmax
      set USPdyn=dyn
      set USPid=h
      set USPAdd=Add
      set USPMinus=Minus
      set USParray=false
      call ExecuteFunc(CusReal)
 endif
      else
 if CusInt==null then
        if Add then
          if Minus then
              call StoreInteger(gc,sh,Stat+"min",GetStoredInteger(gc,sh,Stat+"min")-imin)
              call StoreInteger(gc,sh,Stat+"max",GetStoredInteger(gc,sh,Stat+"max")-imax)
          else
              call StoreInteger(gc,sh,Stat+"min",GetStoredInteger(gc,sh,Stat+"min")+imin)
              call StoreInteger(gc,sh,Stat+"max",GetStoredInteger(gc,sh,Stat+"max")+imax)             
          endif
        else
          if Minus then
              call StoreInteger(gc,sh,Stat+"min",-imin)
              call StoreInteger(gc,sh,Stat+"max",-imax)
          else
              call StoreInteger(gc,sh,Stat+"min",imin)
              call StoreInteger(gc,sh,Stat+"max",imax)             
          endif
        endif
 else
      set USPStat=Stat
      set USPsval=null
      set USPimin=imin
      set USPimax=imax
      set USPdyn=dyn
      set USPid=h
      set USPAdd=Add
      set USPMinus=Minus
      set USParray=false
      call ExecuteFunc(CusInt)
 endif
      endif
     else
      if float then
        set rtemp=GetRandomReal(rmin,rmax)
      else
        set itemp=GetRandomInt(imin,imax)
      endif
     endif
    else
     if float then
       set rtemp=rmax
     else
       set itemp=imax
     endif
    endif
   if float then
 if CusReal==null then
     if Add then
       if Minus then
                call StoreReal(gc,sh,Stat,GetStoredReal(gc,sh,Stat)-rtemp)
       else
                call StoreReal(gc,sh,Stat,GetStoredReal(gc,sh,Stat)+rtemp)
       endif
     else
       if Minus then
                call StoreReal(gc,sh,Stat,-rtemp)
       else
                call StoreReal(gc,sh,Stat,rtemp)
       endif      
     endif
 else
      set USPStat=Stat
      set USPsval=null
      set USPival=0
      set USPrval=rtemp
      set USPdyn=dyn
      set USPid=h
      set USPAdd=Add
      set USPMinus=Minus
      set USParray=false
      call ExecuteFunc(CusReal)
 endif
   else
 if CusInt==null then
     if Add then
       if Minus then
                call StoreInteger(gc,sh,Stat,GetStoredInteger(gc,sh,Stat)-itemp)
       else
                call StoreInteger(gc,sh,Stat,GetStoredInteger(gc,sh,Stat)+itemp)
       endif
     else
       if Minus then
                call StoreInteger(gc,sh,Stat,-itemp)
       else
                call StoreInteger(gc,sh,Stat,itemp)
       endif      
     endif
 else
      set USPStat=Stat
      set USPsval=null
      set USPrval=0
      set USPival=itemp
      set USPdyn=dyn
      set USPid=h
      set USPAdd=Add
      set USPMinus=Minus
      set USParray=false
      call ExecuteFunc(CusInt)
 endif
   endif
  else
    if not b then
       set temp=SubString(STR,pointer+1,i)
    else
       set temp=SubString(STR,pointer,i)
    endif
 if CusStr==null then
       call StoreString(gc,sh,Stat,temp)
 else
      set USPStat=Stat
      set USPival=0
      set USPrval=0
      set USPsval=temp
      set USPid=h
      set USParray=false
      call ExecuteFunc(CusStr)
 endif
  endif
 if dyn then
       call StoreBoolean(gc,sh,Stat,true)
 else
       call StoreBoolean(gc,sh,Stat,false)
 endif
       set imin=0
       set imax=0
       set float=false
       set min=false
       set dyn=false
       set pointer=i+1
endif
elseif dset==2 then
if CurToken==USPSetPointer and b then
       set Stat=SubString(STR,pointer,i)
       set dn=1
       set pointer=i+1
elseif x2==USPHexPointer and b then
       set pointer=i+2
       set hex=true
elseif CurToken==USPRealPointer and b then
       set float=true
elseif CurToken==USPRAWPointer and b then
    if ansi==false then
       set pointer=i+1
    endif
       set ansi=true
elseif (CurToken==USPRandomPointer or CurToken==USPDynRandomPointer) and b then
     if CurToken==USPDynRandomPointer then
        set dyn=true
     endif
     if hex then
        set imin=S2HEX2(STR,pointer+1,i+1)
        set rmin=imin
        set hex=false
     elseif ansi then
        set imin=ASC2I2(STR,pointer+1)
        set rmin=imin
        set ansi=false
     elseif float then
       if bitwise then
        set rmin=GetRealBitwiseBR(STR,pointer,i)
       else
        set rmin=S2R(SubString(STR,pointer,i))
       endif
     else
       if bitwise then
        set imin=GetIntBitwiseBR(STR,pointer,i)
       else
        set imin=S2I(SubString(STR,pointer,i))
       endif
        set rmin=imin
     endif
        set pointer=i+1
        set min=true
elseif CurToken==USPEndPointer then
  if b then
      if hex then
        set imax=S2HEX2(STR,pointer+1,i+1)
        set rmax=imax
        set hex=false
      elseif ansi then
        set imax=ASC2I2(STR,pointer+1)
        set rmax=imax
        set ansi=false
      elseif float then
       if bitwise then
        set rmax=GetRealBitwiseBR(STR,pointer,i)
       else
        set rmax=S2R(SubString(STR,pointer,i))
       endif
      else
       if bitwise then
        set imax=GetIntBitwiseBR(STR,pointer,i)
       else
        set imax=S2I(SubString(STR,pointer,i))
       endif
      endif
    if min then
     if dyn then
      if float then
 if CusReal==null then
        if Add then
          if Minus then
              call StoreReal(gc,sh,Stat+I2S(dn)+"min",GetStoredReal(gc,sh,Stat+I2S(dn)+"min")-rmin)
              call StoreReal(gc,sh,Stat+I2S(dn)+"max",GetStoredReal(gc,sh,Stat+I2S(dn)+"max")-rmax)
          else
              call StoreReal(gc,sh,Stat+I2S(dn)+"min",GetStoredReal(gc,sh,Stat+I2S(dn)+"min")+rmin)
              call StoreReal(gc,sh,Stat+I2S(dn)+"max",GetStoredReal(gc,sh,Stat+I2S(dn)+"max")+rmax)            
          endif
        else
          if Minus then
              call StoreReal(gc,sh,Stat+I2S(dn)+"min",-rmin)
              call StoreReal(gc,sh,Stat+I2S(dn)+"max",-rmax)
          else
              call StoreReal(gc,sh,Stat+I2S(dn)+"min",rmin)
              call StoreReal(gc,sh,Stat+I2S(dn)+"max",rmax)          
          endif
        endif
 else
      set USPStat=Stat
      set USPsval=null
      set USPrmin=rmin
      set USPrmax=rmax
      set USPdyn=dyn
      set USPid=h
      set USPAdd=Add
      set USPMinus=Minus
      set USParray=true
      set USParrayindex=dn
      call ExecuteFunc(CusReal)
 endif
      else
 if CusInt==null then
        if Add then
          if Minus then
              call StoreInteger(gc,sh,Stat+I2S(dn)+"min",GetStoredInteger(gc,sh,Stat+I2S(dn)+"min")-imin)
              call StoreInteger(gc,sh,Stat+I2S(dn)+"max",GetStoredInteger(gc,sh,Stat+I2S(dn)+"max")-imax)
          else
              call StoreInteger(gc,sh,Stat+I2S(dn)+"min",GetStoredInteger(gc,sh,Stat+I2S(dn)+"min")+imin)
              call StoreInteger(gc,sh,Stat+I2S(dn)+"max",GetStoredInteger(gc,sh,Stat+I2S(dn)+"max")+imax)             
          endif
        else
          if Minus then
              call StoreInteger(gc,sh,Stat+I2S(dn)+"min",-imin)
              call StoreInteger(gc,sh,Stat+I2S(dn)+"max",-imax)
          else
              call StoreInteger(gc,sh,Stat+I2S(dn)+"min",imin)
              call StoreInteger(gc,sh,Stat+I2S(dn)+"max",imax)             
          endif
        endif
 else
      set USPStat=Stat
      set USPsval=null
      set USPimin=imin
      set USPimax=imax
      set USPdyn=dyn
      set USPid=h
      set USPAdd=Add
      set USPMinus=Minus
      set USParray=true
      set USParrayindex=dn
      call ExecuteFunc(CusInt)
 endif
      endif
     else
      if float then
        set rtemp=GetRandomReal(rmin,rmax)
      else
        set itemp=GetRandomInt(imin,imax)
      endif
     endif
    else
     if float then
       set rtemp=rmax
     else
       set itemp=imax
     endif
    endif
   if float then
 if CusReal==null then
     if Add then
       if Minus then
                call StoreReal(gc,sh,Stat+I2S(dn),GetStoredReal(gc,sh,Stat+I2S(dn))-rtemp)
       else
                call StoreReal(gc,sh,Stat+I2S(dn),GetStoredReal(gc,sh,Stat+I2S(dn))+rtemp)
       endif
     else
       if Minus then
                call StoreReal(gc,sh,Stat+I2S(dn),-rtemp)
       else
                call StoreReal(gc,sh,Stat+I2S(dn),rtemp)
       endif      
     endif
 else
      set USPStat=Stat
      set USPsval=null
      set USPrval=rtemp
      set USPdyn=dyn
      set USPid=h
      set USPAdd=Add
      set USPMinus=Minus
      set USParray=true
      set USParrayindex=dn
      call ExecuteFunc(CusInt)
 endif
   else
 if CusInt==null then
     if Add then
       if Minus then
                call StoreInteger(gc,sh,Stat+I2S(dn),GetStoredInteger(gc,sh,Stat+I2S(dn))-itemp)
       else
                call StoreInteger(gc,sh,Stat+I2S(dn),GetStoredInteger(gc,sh,Stat+I2S(dn))+itemp)
       endif
     else
       if Minus then
                call StoreInteger(gc,sh,Stat+I2S(dn),-itemp)
       else
                call StoreInteger(gc,sh,Stat+I2S(dn),itemp)
       endif      
     endif
 else
      set USPStat=Stat
      set USPsval=null
      set USPival=itemp
      set USPdyn=dyn
      set USPid=h
      set USPAdd=Add
      set USPMinus=Minus
      set USParray=true
      set USParrayindex=dn
      call ExecuteFunc(CusInt)
 endif
   endif
  else
    if not b then
       set temp=SubString(STR,pointer+1,i)
    else
       set temp=SubString(STR,pointer,i)
    endif
 if CusStr==null then
       call StoreString(gc,sh,Stat+I2S(dn),temp)
 else
      set USPStat=Stat
      set USPsval=temp
      set USPid=h
      set USParray=true
      set USParrayindex=dn
      call ExecuteFunc(CusStr)
 endif
  endif
 if dyn then
       call StoreBoolean(gc,sh,Stat+I2S(dn),true)
 else
       call StoreBoolean(gc,sh,Stat+I2S(dn),false)
 endif
       set imin=0
       set imax=0
       set float=false
       set min=false
       set dyn=false
       set pointer=i+1
       set dn=dn+1
endif
endif 
  set i=i+1
endloop
endfunction

function SetupBRExec takes nothing returns nothing
     call TcUSPBR(ax,null,sx,false,false,null,null,null,false,null)
endfunction

function SetupBR takes integer i,string s returns nothing
     set sx=s
     set ax=i
     call ExecuteFunc("SetupBRExec")
endfunction

function GetIntBR takes integer i,string stat returns integer
 local string s=I2S(i)
 if GetStoredBoolean(USPData,s,stat) then
    return GetRandomInt(GetStoredInteger(USPData,s,stat+"min"),GetStoredInteger(USPData,s,stat+"max"))
 else
    return GetStoredInteger(USPData,s,stat)
 endif
    return 0
endfunction

function GetSubIntBR takes integer i,string stat,integer i2 returns integer
 local string s=I2S(i)
 if GetStoredBoolean(USPData,s,stat+I2S(i2)) then
    return GetRandomInt(GetStoredInteger(USPData,s,stat+I2S(i2)+"min"),GetStoredInteger(USPData,s,stat+I2S(i2)+"max"))
 else
    return GetStoredInteger(USPData,s,stat+I2S(i2))
 endif
    return 0
endfunction

function GetRealBR takes integer i,string stat returns real
 local string s=I2S(i)
 if GetStoredBoolean(USPData,s,stat) then
    return GetRandomReal(GetStoredReal(USPData,s,stat+"min"),GetStoredReal(USPData,s,stat+"max"))
 else
    return GetStoredReal(USPData,s,stat)
 endif
    return 0.0
endfunction

function GetSubRealBR takes integer i,string stat,integer i2 returns real
 local string s=I2S(i)
 local string s2=stat+I2S(i2)
 if GetStoredBoolean(USPData,s,s2) then
    return GetRandomReal(GetStoredReal(USPData,s,s2+"min"),GetStoredReal(USPData,s,s2+"max"))
 else
    return GetStoredReal(USPData,s,s2)
 endif
    return 0.0
endfunction

function GetStrBR takes integer i,string stat returns string
    return GetStoredString(USPData,I2S(i),stat)
endfunction

function GetExtraStrBR takes integer i returns string
    return GetStoredString(USPData,I2S(i),"LongString")
endfunction

function GetSubStrBR takes integer i,string stat,integer i2 returns string
    return GetStoredString(USPData,I2S(i),stat+I2S(i2))
endfunction

//###############################################################
//################ End of Toadcop's USP Function ################
//###############################################################

function CustomMBsInitsBR takes nothing returns nothing
       local integer i=1
       local integer i2=1
	   local integer max=40*mb_max_plr
    loop
       exitwhen i>max
        set XMB[i]=CreateMultiboard()
        call MultiboardSetRowCount(XMB[i],i2)
        call MultiboardSetColumnCount(XMB[i],XMBColumns)
        call MultiboardMinimize(XMB[i],true)
       set i=i+1
       set i2=i2+1
     if i2>40 then
       set i2=1
     endif
    endloop
      call DestroyTimer(GetExpiredTimer())
endfunction

function CustomInitializationBR takes nothing returns nothing
       set XDG=InitGameCache("XDG.bx")
       set cache=InitGameCache("DefaultGameCache.bx")
       set TRS=InitGameCache("TRS.bx")
       set TRSInv=InitGameCache("TRSInv.bx")
       set TRSItems=InitGameCache("TRSItems.bx")
       set TPC=InitGameCache("TPC.bx")
       set MapBoundMinX=GetCameraBoundMinX()
       set MapBoundMinY=GetCameraBoundMinY()
       set MapBoundMaxX=GetCameraBoundMaxX()
       set MapBoundMaxY=GetCameraBoundMaxY()
       set tmploc=Location(0,0)
       call TimerStart(CreateTimer(),0,false,function CustomMBsInitsBR)
endfunction



function setconfigoperation takes nothing returns nothing
   local gamecache g=InitGameCache("DefaultGameCache.bx")
   local string s=GetStoredString(g,"TcXConfig","XXToadcopXX")
   local integer i=0
   local integer i2=0
   local integer lng=StringLength(s)
   local string token=SubString(s,0,1)
   local integer max=0
 loop
   set token=SubString(s,i,i+1)
   exitwhen i>=lng or token==" "
   set i=i+1
 endloop
   set i2=i
   set token=SubString(s,0,i)
 if StringLength(token)>0 then
  if token!=null and token!="" then
   set i=GetStoredInteger(g,"XConfig",token)
  if i>0 then
   set max=GetStoredInteger(g,"XConfig_stack","max")+1
   call StoreInteger(g,"XConfig_stack","max",max)
   call StoreInteger(g,"XConfig_stack",I2S(max),i)
   call StoreString(g,"XConfig_stack",I2S(max),SubString(s,i2+1,lng))
  endif
  endif
 endif
endfunction

function setconfig takes string s returns nothing
    local gamecache g=InitGameCache("DefaultGameCache.bx")
	call StoreString(g,"TcXConfig","XXToadcopXX",s)
	call StoreInteger(g,"TcXConfig","XXX",GetStoredInteger(g,"TcXConfig","XXX")+1)
if GetStoredInteger(g,"TcXConfig","XXX")<=GetStoredInteger(g,"XConfig_max_config","max") then
    call ExecuteFunc("setconfigoperation")
else
    loop
	  exitwhen false
    endloop	
endif	
endfunction