dialog soccer {
  title "mIRC Soccer 2"
  size -1 -1 449 407
  option pixels
  button "", 1, 11 11 428 246
  list 2, 14 287 133 107, size
  list 3, 309 287 133 107, size
  edit "0", 4, 259 286 38 21, read
  edit "0", 5, 259 310 38 21, read
  edit "Blue Team", 6, 155 286 100 21, read
  edit "Red Team", 7, 155 310 100 21, read
  text "", 8, 156 374 142 16
  edit "10:00", 9, 155 334 143 36, read center
  box "Red Goals", 10, 302 272 146 130
  box "Blue Goals", 11, 9 273 144 130
}
on *:LOAD:{ echo -a Thanks for using mIRC Soccer 2. Have fun, and type /soccer.start to begin. }
on *:UNLOAD:{ unset %ms2.* | echo -a Unloaded successfully, most variables cleaned. }
on *:DIALOG:soccer:init:*:{
  $mdll MarkDialog $dname
  $mdll SetMircVersion $version
  $mdll SetFont $dname 9 28 401 Tahoma
  window -hp +ef @soccer2 -1 -1 434 252 
  soccer.field.draw
  $mdll SetControlMDX 1 Window > $ddll 
  did -a $dname 1 grab $window(@soccer2).hwnd @soccer2
  $mdll SetControlMDX 8 progressbar smooth > $scriptdirctl_gen.mdx
  did -i $dname 8 1 600 0 600
}
alias -l mdll { return dll " $+ $scriptdirmdx.dll $+ " }
alias -l cdll { return $scriptdirctl_gen.mdx }
alias -l ddll { return $scriptdirdialog.mdx }
alias soccer2 { dialog -m soccer soccer }
alias soccer.start {
  soccer2
  set %ms2.bcontrol Red
  set %ms2.bc.one RD1
  set %ms2.bt.score 0
  set %ms2.rt.score 0
  soccer.field.draw
  .timersoccer 1 600 soccer.end
  .timersoccerbar 0 1 soccerbar.fill
}
alias soccerbar.fill {
  if ($dialog(soccer) == $null) { return }
  did -i soccer 8 1 $timer(soccer).secs 0 600
  did -ra soccer 9 $soccer.editlen($calc($timer(soccer).secs * 1000))
}
alias soccer.editlen { 
  var %mplayer.len $int($calc($1 / 1000))
  var %mplayer.min $int($calc(%mplayer.len / 60)) 
  var %mplayer.sec $calc(%mplayer.len - (%mplayer.min * 60))
  if (%mplayer.sec < 10) { set %mplayer.sec 0 $+ %mplayer.sec } 
  set %mplayer.len %mplayer.min $+ : $+ %mplayer.sec 
  return %mplayer.len 
}
alias soccer.end {
  if ($dialog(soccer) == $null) { return }
  set %ms2.rt.score 0
  set %ms2.bt.score 0
  echo -a Game Over, type /soccer.start for a new game..
  did -r soccer 2,3
}
alias soccer.field.draw {
  var %w = @soccer2
  drawrect -fnr %w $rgb(0,255,0) 1 0 0 500 300
  drawrect -nr %w $rgb(157,157,157) 6 0 0 424 242
  drawrect -nrf %w $rgb(255,255,255) 1 209 6 6 230
  drawrect -enr %w $rgb(255,255,255) 2 182 95 60 60  

  drawrect -nfr %w $rgb(255,255,255) 3 6 75 40 6
  drawrect -nrf %w $rgb(255,255,255) 3 6 155 40 6
  drawrect -nrf %w $rgb(255,255,255) 3 46 75 6 86 

  drawrect -nfr %w $rgb(255,255,255) 3 377 75 41 6
  drawrect -nrf %w $rgb(255,255,255) 3 377 155 41 6
  drawrect -nrf %w $rgb(255,255,255) 3 375 75 6 86 

  drawpic -tn %w $rgb(0,255,0) 20 20 " $+ $scriptdirblueteam.bmp $+ "
  drawpic -tn %w $rgb(0,255,0) 15 100 " $+ $scriptdirblueteam.bmp $+ "
  drawpic -tn %w $rgb(0,255,0) 105 70 " $+ $scriptdirblueteam.bmp $+ "
  drawpic -tn %w $rgb(0,255,0) 135 200 " $+ $scriptdirblueteam.bmp $+ "
  set %ms2.bt.d1 20 20 
  set %ms2.bt.f1 135 200 
  set %ms2.bt.f2 105 70 
  set %ms2.bt.g1 15 100 

  drawpic -tn %w $rgb(0,255,0) 250 30 " $+ $scriptdirredteam.bmp $+ "
  drawpic -tn %w $rgb(0,255,0) 395 110 " $+ $scriptdirredteam.bmp $+ "
  drawpic -tn %w $rgb(0,255,0) 210 90 " $+ $scriptdirredteam.bmp $+ "
  drawpic -tn %w $rgb(0,255,0) 225 170 " $+ $scriptdirredteam.bmp $+ "
  set %ms2.rt.d1 250 30 
  set %ms2.rt.f1 210 90 
  set %ms2.rt.f2 225 170 
  set %ms2.rt.g1 395 110 

  drawpic -tn %w $rgb(0,255,0) 242 45 " $+ $scriptdirball.bmp $+ "
  set %ms2.nt.ball 242 45
  drawdot %w
}
alias soccer.r.move {
  tokenize 32 $1-
  var %a = %ms2.player.goto1
  var %b = %ms2.player.goto2
  var %c = $1
  set %ms2.passto $2-
  set %ms2.tmp.todo move
  set %ms2.tmp.tomove $1
  set %ms2.tmp.mover $gettok(% [ $+ [ %ms2.tmp.tomove ] $+ ] ,1,32) 
  set %ms2.tmp.moverr $gettok(% [ $+ [ %ms2.tmp.tomove ] $+ ] ,2,32)
  set %ms2.tmp.move1 $calc(%a - %ms2.tmp.mover)
  set %ms2.tmp.move2 $calc(%b - %ms2.tmp.moverr)
  set %ms2.tmp.move1 $calc(%ms2.tmp.move1 / 50)
  set %ms2.tmp.move2 $calc(%ms2.tmp.move2 / 50)
  set %ms2.z 0
  ai.todo
  .timerms2 -m 50 10 soccer.anim
}
alias soccer.r.pass {
  set %ms2.tmp.a $calc($gettok(% [ $+ [ $1 ] ],1,32) + 5)
  set %ms2.tmp.b $calc($gettok(% [ $+ [ $1 ] ],2,32) + 20)
  set %ms2.topassto $3-
  set %ms2.tmp.todo pass
  set %ms2.tmp.mover $gettok(%ms2.nt.ball,1,32) 
  set %ms2.tmp.moverr $gettok(%ms2.nt.ball,2,32)
  set %ms2.tmp.move1 $calc(%ms2.tmp.a - %ms2.tmp.mover)
  set %ms2.tmp.move2 $calc(%ms2.tmp.b - %ms2.tmp.moverr)
  set %ms2.tmp.move1 $calc(%ms2.tmp.move1 / 50)
  set %ms2.tmp.move2 $calc(%ms2.tmp.move2 / 50)
  set %ms2.z 1
  set %ms2.bc.one $2
  ai.todo
  .timerms2 -m 50 10 soccer.anim
  :end
}
alias soccer.r.shoot { 
  set %ms2.tmp.bcone %ms2.bc.one
  tokenize 32 $1-
  var %a = $1
  var %b = $2
  set %ms2.roaro.samuel %b
  set %ms2.tmp.todo shoot
  set %ms2.tmp.mover $gettok(%ms2.nt.ball,1,32) 
  set %ms2.tmp.moverr $gettok(%ms2.nt.ball,2,32)
  set %ms2.tmp.move1 $calc(%a - %ms2.tmp.mover)
  set %ms2.tmp.move2 $calc(%b - %ms2.tmp.moverr)
  set %ms2.tmp.move1 $calc(%ms2.tmp.move1 / 50)
  set %ms2.tmp.move2 $calc(%ms2.tmp.move2 / 50)
  set %ms2.z 1
  ai.todo
  .timerms2 -m 50 10 soccer.anim
}
on *:DIALOG:soccer:close:*:{ .timersoccer off | .timersoccerbar off }
alias soccer.anim {
  if (%ms2.tmp.todo == move) {
    set % [ $+ [ %ms2.tmp.tomove ] ] $calc(%ms2.tmp.mover + %ms2.tmp.move1) $calc(%ms2.tmp.moverr + %ms2.tmp.move2)
    set %ms2.tmp.mover $calc(%ms2.tmp.mover + %ms2.tmp.move1)
    set %ms2.tmp.moverr $calc(%ms2.tmp.moverr + %ms2.tmp.move2)
  }
  if (%ms2.tmp.todo == pass) {
    set %ms2.nt.ball $calc(%ms2.tmp.mover + %ms2.tmp.move1) $calc(%ms2.tmp.moverr + %ms2.tmp.move2)
    set %ms2.tmp.mover $calc(%ms2.tmp.mover + %ms2.tmp.move1)
    set %ms2.tmp.moverr $calc(%ms2.tmp.moverr + %ms2.tmp.move2)
  }
  if (%ms2.tmp.todo == shoot) {
    set %ms2.nt.ball $calc(%ms2.tmp.mover + %ms2.tmp.move1) $calc(%ms2.tmp.moverr + %ms2.tmp.move2)
    set %ms2.tmp.mover $calc(%ms2.tmp.mover + %ms2.tmp.move1)
    set %ms2.tmp.moverr $calc(%ms2.tmp.moverr + %ms2.tmp.move2)
  }
  if (%ms2.bmp.todo == move) {
    set % [ $+ [ %ms2.bmp.tomove ] ] $calc(%ms2.bmp.mover + %ms2.bmp.move1) $calc(%ms2.bmp.moverr + %ms2.bmp.move2)
    set %ms2.bmp.mover $calc(%ms2.bmp.mover + %ms2.bmp.move1)
    set %ms2.bmp.moverr $calc(%ms2.bmp.moverr + %ms2.bmp.move2)
  }
  if (%ms2.bmp.todo == pass) {
    set %ms2.nt.ball $calc(%ms2.bmp.mover + %ms2.bmp.move1) $calc(%ms2.bmp.moverr + %ms2.bmp.move2)
    set %ms2.bmp.mover $calc(%ms2.bmp.mover + %ms2.bmp.move1)
    set %ms2.bmp.moverr $calc(%ms2.bmp.moverr + %ms2.bmp.move2)
  }
  if (%ms2.bmp.todo == shoot) {
    set %ms2.nt.ball $calc(%ms2.bmp.mover + %ms2.bmp.move1) $calc(%ms2.bmp.moverr + %ms2.bmp.move2)
    set %ms2.bmp.mover $calc(%ms2.bmp.mover + %ms2.bmp.move1)
    set %ms2.bmp.moverr $calc(%ms2.bmp.moverr + %ms2.bmp.move2)
  }
  inc %ms2.z
  var %w = @soccer2
  drawrect -fnr %w $rgb(0,255,0) 1 0 0 500 300
  drawrect -nr %w $rgb(157,157,157) 6 0 0 424 242
  drawrect -nrf %w $rgb(255,255,255) 1 209 6 6 230
  drawrect -enr %w $rgb(255,255,255) 2 182 95 60 60  

  drawrect -nfr %w $rgb(255,255,255) 3 6 75 40 6
  drawrect -nrf %w $rgb(255,255,255) 3 6 155 40 6
  drawrect -nrf %w $rgb(255,255,255) 3 46 75 6 86 

  drawrect -nfr %w $rgb(255,255,255) 3 377 75 41 6
  drawrect -nrf %w $rgb(255,255,255) 3 377 155 41 6
  drawrect -nrf %w $rgb(255,255,255) 3 375 75 6 86 

  drawpic -tn %w $rgb(0,255,0) %ms2.bt.d1 " $+ $scriptdirblueteam.bmp $+ "
  drawpic -tn %w $rgb(0,255,0) %ms2.bt.g1 " $+ $scriptdirblueteam.bmp $+ "
  drawpic -tn %w $rgb(0,255,0) %ms2.bt.f1 " $+ $scriptdirblueteam.bmp $+ "
  drawpic -tn %w $rgb(0,255,0) %ms2.bt.f2 " $+ $scriptdirblueteam.bmp $+ "

  drawpic -tn %w $rgb(0,255,0) %ms2.rt.d1 " $+ $scriptdirredteam.bmp $+ "
  drawpic -tn %w $rgb(0,255,0) %ms2.rt.g1 " $+ $scriptdirredteam.bmp $+ "
  drawpic -tn %w $rgb(0,255,0) %ms2.rt.f1 " $+ $scriptdirredteam.bmp $+ "
  drawpic -tn %w $rgb(0,255,0) %ms2.rt.f2 " $+ $scriptdirredteam.bmp $+ "

  drawpic -tn %w $rgb(0,255,0) %ms2.nt.ball " $+ $scriptdirball.bmp $+ "
  if (%ms2.bcontrol == red) && ($inrect($gettok(%ms2.nt.ball,1,32),$gettok(%ms2.nt.ball,2,32),$gettok(%ms2.bt.d1,1,32),$gettok(%ms2.bt.d1,2,32),17,20)) { set %ms2.bcontrol blue | set %ms2.bc.one BD1 | .timerms2 off | return }
  if (%ms2.bcontrol == red) && ($inrect($gettok(%ms2.nt.ball,1,32),$gettok(%ms2.nt.ball,2,32),$gettok(%ms2.bt.g1,1,32),$gettok(%ms2.bt.g1,2,32),17,20)) { set %ms2.bcontrol blue | set %ms2.bc.one BG1 | .timerms2 off | return }
  if (%ms2.bcontrol == red) && ($inrect($gettok(%ms2.nt.ball,1,32),$gettok(%ms2.nt.ball,2,32),$gettok(%ms2.bt.f1,1,32),$gettok(%ms2.bt.f1,2,32),17,20)) { set %ms2.bcontrol blue | set %ms2.bc.one BF1 | .timerms2 off | return }
  if (%ms2.bcontrol == red) && ($inrect($gettok(%ms2.nt.ball,1,32),$gettok(%ms2.nt.ball,2,32),$gettok(%ms2.bt.f2,1,32),$gettok(%ms2.bt.f2,2,32),17,20)) { set %ms2.bcontrol blue | set %ms2.bc.one BF2 | .timerms2 off | return }
  if (%ms2.bcontrol == blue) && ($inrect($gettok(%ms2.nt.ball,1,32),$gettok(%ms2.nt.ball,2,32),$gettok(%ms2.rt.d1,1,32),$gettok(%ms2.rt.d1,2,32),17,20)) { set %ms2.bcontrol red | set %ms2.bc.one RD1 | .timerms2 off | return }
  if (%ms2.bcontrol == blue) && ($inrect($gettok(%ms2.nt.ball,1,32),$gettok(%ms2.nt.ball,2,32),$gettok(%ms2.rt.g1,1,32),$gettok(%ms2.rt.g1,2,32),17,20)) { set %ms2.bcontrol red | set %ms2.bc.one RG1 | .timerms2 off | return }
  if (%ms2.bcontrol == blue) && ($inrect($gettok(%ms2.nt.ball,1,32),$gettok(%ms2.nt.ball,2,32),$gettok(%ms2.rt.f1,1,32),$gettok(%ms2.rt.f1,2,32),17,20)) { set %ms2.bcontrol red | set %ms2.bc.one RF1 | .timerms2 off | return }
  if (%ms2.bcontrol == blue) && ($inrect($gettok(%ms2.nt.ball,1,32),$gettok(%ms2.nt.ball,2,32),$gettok(%ms2.rt.f2,1,32),$gettok(%ms2.rt.f2,2,32),17,20)) { set %ms2.bcontrol red | set %ms2.bc.one RF2 | .timerms2 off | return }
  if ($inrect($round($gettok(%ms2.nt.ball,1,32),0),$round($gettok(%ms2.nt.ball,2,32),0),4,75,3,80)) { inc %ms2.rt.score | soccer.media.goal | did -ra soccer 5 %ms2.rt.score | did -a soccer 3 $convert.s(%ms2.tmp.bcone) $did(soccer,9).text | set %ms2.bc.one BG1 | set %ms2.bcontrol blue | set %ms2.nt.ball $calc($gettok(%ms2.bt.g1,1,32) + 5) $calc($gettok(%ms2.bt.g1,2,32) + 20) }
  if ($inrect($round($gettok(%ms2.nt.ball,1,32),0),$round($gettok(%ms2.nt.ball,2,32),0),419,75,5,80)) { inc %ms2.bt.score | soccer.media.goal | did -ra soccer 4 %ms2.bt.score | did -a soccer 2 $convert.s(%ms2.bmp.bcone) $did(soccer,9).text | set %ms2.bc.one RG1 | set %ms2.bcontrol red | set %ms2.nt.ball $calc($gettok(%ms2.rt.g1,1,32) + 5) $calc($gettok(%ms2.rt.g1,2,32) + 20) } 
  drawdot %w
}
menu @soccer2 {
  sclick:set %ms2.tmp.bc %ms2.bc.one | set %ms2.player.goto1 $mouse.x | set %ms2.player.goto2 $mouse.y | soccer.pop
  dclick:echo -a $mouse.x $mouse.y
}
alias soccer.media.goal {
  splay -p " $+ $scriptdirgoal!.mp3 $+ "
  .timer 1 12 splay stop
}
alias pop { tokenize 32 $dll(" $+ $scriptdirpopups.dll $+ ",Popup,$1-) | if ($isid) return $1- | $iif($4- != did not select a menu item,$4-) }
alias soccer.pop {
  var %b = $1
  var %a = $2
  dll " $+ $scriptdirpopups.dll $+ " New soccer 16 16
  if ($inrect(%ms2.player.goto1,%ms2.player.goto2,6,75,40,80)) && (%ms2.bcontrol == Red) { dll " $+ $scriptdirpopups.dll $+ " AddItem soccer end + 0 0 Shoot $cr soccer.r.shoot 6 %ms2.player.goto2 %ms2.nt.ball }
  if (%ms2.bcontrol == Red) { dll " $+ $scriptdirpopups.dll $+ " AddItem soccer end +> 0 0 Pass $cr passopt }
  if ($inrect(%ms2.player.goto1,%ms2.player.goto2,0,75,46,80) == $false) { dll " $+ $scriptdirpopups.dll $+ " AddItem soccer end +> 0 0 Move $cr moveopt }
  pop soccer $mouse.dx $mouse.dy 
  dll " $+ $scriptdirpopups.dll $+ " New passopt 16 16
  if (%ms2.tmp.bc != RG1) { dll " $+ $scriptdirpopups.dll $+ " AddItem passopt end + 0 0 Goalie $cr soccer.r.pass ms2.rt.g1 RG1 }
  if (%ms2.tmp.bc != RD1) { dll " $+ $scriptdirpopups.dll $+ " AddItem passopt end + 0 0 Defender $cr soccer.r.pass ms2.rt.d1 RD1 }
  if (%ms2.tmp.bc != RF1) { dll " $+ $scriptdirpopups.dll $+ " AddItem passopt end + 0 0 Forward1 $cr soccer.r.pass ms2.rt.f1 RF1 }
  if (%ms2.tmp.bc != RF2) { dll " $+ $scriptdirpopups.dll $+ " AddItem passopt end + 0 0 Forward2 $cr soccer.r.pass ms2.rt.f2 RF2 }
  dll " $+ $scriptdirpopups.dll $+ " New moveopt 16 16
  if (%ms2.tmp.bc != RG1) && ($inrect(%ms2.player.goto1,%ms2.player.goto2,383,75,100,80) == $true) { dll " $+ $scriptdirpopups.dll $+ " AddItem moveopt end + 0 0 Goalie $cr soccer.r.move ms2.rt.g1 RG1 }
  if (%ms2.tmp.bc != RD1) && ($inrect(%ms2.player.goto1,%ms2.player.goto2,383,75,100,80) == $false) { dll " $+ $scriptdirpopups.dll $+ " AddItem moveopt end + 0 0 Defender $cr soccer.r.move ms2.rt.d1 RD1 }
  if (%ms2.tmp.bc != RF1) && ($inrect(%ms2.player.goto1,%ms2.player.goto2,383,75,100,80) == $false) { dll " $+ $scriptdirpopups.dll $+ " AddItem moveopt end + 0 0 Forward1 $cr soccer.r.move ms2.rt.f1 RF1 }
  if (%ms2.tmp.bc != RF2) && ($inrect(%ms2.player.goto1,%ms2.player.goto2,383,75,100,80) == $false) { dll " $+ $scriptdirpopups.dll $+ " AddItem moveopt end + 0 0 Forward2 $cr soccer.r.move ms2.rt.f2 RF2 }
}
alias convert.s {
  if ($1- == RD1) { return Defender }
  if ($1- == RG1) { return Goalie }
  if ($1- == RF1) { return Forward 1 }
  if ($1- == RF2) { return Forward 2 }
  if ($1- == BD1) { return Defender }
  if ($1- == BG1) { return Goalie }
  if ($1- == BF1) { return Forward 1 }
  if ($1- == BF2) { return Forward 2 }
}

;AI

alias ai.todo {
  if (%ms2.bcontrol == Blue) {
    if ($gettok(%ms2.nt.ball,1,32) > 211) && ($gettok(%ms2.bt.f1,1,32) > 211) && ($gettok(%ms2.bt.f2,1,32) > 211) { 
      var %a = $rand(1,2)
      if (%a == 1) { $soccer.b.shoot(420 $rand(75,155) %ms2.nt.ball) }
      if (%a == 2) { 
        var %c = $rand(1,2)
        if (%ms2.bc.one == BF1) { $soccer.b.pass(ms2.bt.f2 BF2) }
        if (%ms2.bc.one == BF2) { $soccer.b.pass(ms2.bt.f1 BF1) }
        else { 
          if (%c == 1) { $soccer.b.pass(ms2.bt.f1 BF1) }  
          if (%c == 2) { $soccer.b.pass(ms2.bt.f2 BF2) }
        }
      }
    }
    elseif ($gettok(%ms2.bt.f1,1,32) < 211) && ($gettok(%ms2.bt.f2,1,32) < 211) {
      var %n = $rand(1,2)
      if (%n == 1) { soccer.b.move ms2.bt.f1 BF1 }
      if (%n == 2) { soccer.b.move ms2.bt.f2 BF2 }
    }
    elseif ($gettok(%ms2.bt.f1,1,32) < 211) && ($gettok(%ms2.bt.f2,1,32) < 211) && ($gettok(%ms2.bt.d1,1,32) < 211) { $soccer.b.move(ms2.bt.d1 BD1) }
    else {
      var %n = $rand(1,6)
      if (%n == 1) || (%n == 2) { $soccer.b.shoot(420 $rand(75,155) %ms2.nt.ball) }
      if (%n == 3) || (%n == 4) { 
        if (%ms2.bc.one == BD1) {
          var %z = $rand(1,3)
          if (%z == 1) { $soccer.b.pass(ms2.bt.f1 BF1) }
          if (%z == 2) { $soccer.b.pass(ms2.bt.f2 BF2) } 
          if (%z == 3) { $soccer.b.pass(ms2.bt.g1 BG1) }
        }
        if (%ms2.bc.one == BG1) {
          var %z = $rand(1,3)
          if (%z == 1) { $soccer.b.pass(ms2.bt.f1 BF1) }
          if (%z == 2) { $soccer.b.pass(ms2.bt.f2 BF2) } 
          if (%z == 3) { $soccer.b.pass(ms2.bt.d1 BD1) }
        }
        if (%ms2.bc.one == BF1) {
          var %z = $rand(1,3)
          if (%z == 1) { $soccer.b.pass(ms2.bt.d1 BD1) }
          if (%z == 2) { $soccer.b.pass(ms2.bt.f2 BF2) } 
          if (%z == 3) { $soccer.b.pass(ms2.bt.g1 BG1) }
        }
        if (%ms2.bc.one == BF2) {
          var %z = $rand(1,3)
          if (%z == 1) { $soccer.b.pass(ms2.bt.f1 BF1) }
          if (%z == 2) { $soccer.b.pass(ms2.bt.d1 BD1) } 
          if (%z == 3) { $soccer.b.pass(ms2.bt.g1 BG1) }
        }
      }
      if (%n == 5) || (%n == 6) {
        if (%ms2.bc.one == BD1) {
          var %z = $rand(1,2)
          if (%z == 1) { $soccer.b.move(ms2.bt.f1 BF1) }
          if (%z == 2) { $soccer.b.move(ms2.bt.f2 BF2) } 
        }
        if (%ms2.bc.one == BG1) {
          var %z = $rand(1,3)
          if (%z == 1) { $soccer.b.move(ms2.bt.f1 BF1) }
          if (%z == 2) { $soccer.b.move(ms2.bt.f2 BF2) } 
          if (%z == 3) { $soccer.b.move(ms2.bt.d1 BD1) }
        }
        if (%ms2.bc.one == BF1) {
          var %z = $rand(1,2)
          if (%z == 1) { $soccer.b.move(ms2.bt.d1 BD1) }
          if (%z == 2) { $soccer.b.move(ms2.bt.f2 BF2) } 
        }
        if (%ms2.bc.one == BF2) {
          var %z = $rand(1,2)
          if (%z == 1) { $soccer.b.move(ms2.bt.f1 BF1) }
          if (%z == 2) { $soccer.b.move(ms2.bt.d1 BD1) } 
        }
      }
    }
  }
  if (%ms2.bcontrol == Red) {
    if (%ms2.tmp.todo == shoot) {
      var %a = $rand(1,4)
      if (%a == 4) { $soccer.b.gmove(410 $rand(75,155)) }
      else { $soccer.b.gmove(410 %ms2.roaro.samuel) }
    }
    if (%ms2.tmp.todo == pass) { 
      var %a == $rand(1,7)
      if (%a == 1) || (%a == 2) { $soccer.b.dmove }
      else { 
        var %b = $rand(1,3)
        if (%b == 1) { $soccer.b.move(ms2.bt.f1 BF1) }
        if (%b == 2) { $soccer.b.move(ms2.bt.d1 BD1) }
        if (%b == 3) { $soccer.b.move(ms2.bt.f2 BF2) }
      }
    }
    if (%ms2.tmp.todo == move) {
      var %b = $rand(1,3)
      if (%b == 1) { $soccer.b.move(ms2.bt.f1 BF1) }
      if (%b == 2) { $soccer.b.move(ms2.bt.d1 BD1) }
      if (%b == 3) { $soccer.b.move(ms2.bt.f2 BF2) }
    }
  }
}
alias soccer.b.gmove {
  tokenize 32 $1-
  var %a = 5
  var %b = $calc($2 - 10)
  set %ms2.bmp.todo move
  set %ms2.bmp.tomove ms2.bt.g1
  set %ms2.bmp.mover $gettok(%ms2.bt.g1,1,32) 
  set %ms2.bmp.moverr $gettok(%ms2.bt.g1,2,32)
  set %ms2.bmp.move1 $calc(%a - %ms2.bmp.mover)
  set %ms2.bmp.move2 $calc(%b - %ms2.bmp.moverr)
  set %ms2.bmp.move1 $calc(%ms2.bmp.move1 / 55)
  set %ms2.bmp.move2 $calc(%ms2.bmp.move2 / 55)
}
alias soccer.b.dmove {
  var %a = %ms2.tmp.a
  var %b = %ms2.tmp.b
  set %ms2.bmp.todo move
  set %ms2.bmp.tomove ms2.bt.d1
  set %ms2.bmp.mover $gettok(%ms2.bt.d1,1,32) 
  set %ms2.bmp.moverr $gettok(%ms2.bt.d1,2,32)
  set %ms2.bmp.move1 $calc(%a - %ms2.bmp.mover)
  set %ms2.bmp.move2 $calc(%b - %ms2.bmp.moverr)
  set %ms2.bmp.move1 $calc(%ms2.bmp.move1 / 50)
  set %ms2.bmp.move2 $calc(%ms2.bmp.move2 / 50)
}
alias soccer.b.shoot { 
  set %ms2.bmp.bcone %ms2.bc.one
  tokenize 32 $1-
  var %a = $1
  var %b = $2
  set %ms2.bmp.todo shoot
  set %ms2.bmp.mover $gettok(%ms2.nt.ball,1,32) 
  set %ms2.bmp.moverr $gettok(%ms2.nt.ball,2,32)
  set %ms2.bmp.move1 $calc(%a - %ms2.bmp.mover)
  set %ms2.bmp.move2 $calc(%b - %ms2.bmp.moverr)
  set %ms2.bmp.move1 $calc(%ms2.bmp.move1 / 50)
  set %ms2.bmp.move2 $calc(%ms2.bmp.move2 / 50)
}
alias soccer.b.pass {
  tokenize 32 $1-
  set %ms2.bmp.a $calc($gettok(% [ $+ [ $1 ] ],1,32) + 5)
  set %ms2.bmp.b $calc($gettok(% [ $+ [ $1 ] ],2,32) + 20)
  set %ms2.bmp.todo pass
  set %ms2.bmp.mover $gettok(%ms2.nt.ball,1,32) 
  set %ms2.bmp.moverr $gettok(%ms2.nt.ball,2,32)
  set %ms2.bmp.move1 $calc(%ms2.bmp.a - %ms2.bmp.mover)
  set %ms2.bmp.move2 $calc(%ms2.bmp.b - %ms2.bmp.moverr)
  set %ms2.bmp.move1 $calc(%ms2.bmp.move1 / 50)
  set %ms2.bmp.move2 $calc(%ms2.bmp.move2 / 50)
  set %ms2.bc.one $2
}
alias soccer.b.move {
  tokenize 32 $1-
  :start
  if ($2 == BF1) || ($2 == BF2) { var %a = $rand(211,400) | var %b = $rand(20,220) }
  if ($2 == BD1) { var %a = $rand(20,200) | var %b = $rand(20,220) }
  if ($inrect(%a,%b,6,75,40,85) == $true) || ($inrect(%a,%b,372,75,40,85) == $true) { goto start }  
  set %ms2.bmp.todo move
  set %ms2.bmp.tomove $1
  set %ms2.bmp.mover $gettok(% [ $+ [ %ms2.bmp.tomove ] $+ ] ,1,32) 
  set %ms2.bmp.moverr $gettok(% [ $+ [ %ms2.bmp.tomove ] $+ ] ,2,32)
  set %ms2.bmp.move1 $calc(%a - %ms2.bmp.mover)
  set %ms2.bmp.move2 $calc(%b - %ms2.bmp.moverr)
  set %ms2.bmp.move1 $calc(%ms2.bmp.move1 / 50)
  set %ms2.bmp.move2 $calc(%ms2.bmp.move2 / 50)
}
