/**** Mutant Races v1.0 for Assassin ONLY 

      Any unlawful distribution, editing or copying of this program
      will result in legal actions!

      1992 Patrick Baker

***************************************************************************/

options results
signal on error;signal on syntax;signal on ioerr

RET = '\n2\c7[Return]-\g1';Tr = Transmit;SS = Sendstring
maxbet = 2000

Getuser 19;cls=d2c(result)

call open file, ('ram:money.tmp'), 'r'
     money = readln(file)
call close file

ddir = 'assassin:assdata/'
tdir = ddir'text/'
gdir = ddir'Gamefiles/'
Mutantfile = gdir'Game.Dat.Gamble2'
Mutantfile2 = tdir'Txt.Gamble2b'
Gamble2txt = tdir'Txt.Gamble2'

call open file, (Mutantfile), 'r'
     Total = readln(file)
     do loop = 1 to total
        Mutant.loop = readln(file)
     end
call close file

sendfile Gamble2Txt
Tr RET
signal MAIN

MAIN:
   Tr CLS'\c3Please chose a mount - \n1'
   do loop = 1 to Total
      var = loop
      call ParseMutant
      v1 = left(Mname,20);v2=MDescrip
      v0 = left(loop,3)
      Tr '\cb'v0'\c7'v1'\c6'v2  
   end
   SS '\n1\c6Selection \c5(\c71 - 'Total'\c6;\c7Q\c6=Quit;Money = $\c7'money'\c5)\c6-\c7'
   Query '';sel=upper(result);call nocarrier;if rv=1 then signal QUIT
   if sel = Q then signal QUIT   
   if sel > 0 & sel <= total then call RACE
signal MAIN


RACE:
 BFlag = Notok
 sendfile Mutantfile2
 SS '\n1\c6Bet how much \c5(\c7'maxbet'\c6=MAX;You have $\c7'money'\c5)\c6-\c7'
 Query '';bet = upper(result);call nocarrier;if rv=1 then signal QUIT
 if bet = '' then BFlag = NOTOK
 if bet > 0 & bet <= maxbet & bet <= money then do
    BFlag = OK
    Tr '\n1\c2"Thanx for the money, now I can take my wench out to dinner!"\c6, the man exclaims.'
 end
 if BFlag = Notok then do
    if Money >= maxbet then bet = 100
    if money < maxbet & money > 100 then bet = 100
    Tr '\n1\c2"Sorry sucker, you are racing in this for $\c7'bet'\c2!"\c6, the man yells and two thugs grab your money.'
 end
 Tr RET

 var = sel;call ParseMutant
 bullets.1 = 3
 Mount.1 = sel
 Speed.1 = Speed
 Armor.1 = Armor
 mhp = (randu()*AHP+1)%1 
 Mhp.1 = mhp
 Xcoord.1 = 4
 Ycoord.1 = 23

 numracers = (randu()*5+2)%1
 do loop = 2 to numracers
    mount = (randu()*total+1)%1
    var = mount;call ParseMutant
    mhp = (randu()*AHP+1)%1

    Armor.loop = armor
    bullets.loop = 3
    Mount.loop = mount
    mhp.loop = mhp
    speed.loop = speed
    YCoord.loop = 23
 end
 Tr CLS'\c3The Mutant Races \c6-\c7 'numracers'\c6 participants!\n1'
 Tr 'Mount Type            Start                      Finish'
 Tr '     |-----------------------------------------------------|'
 xc = 5
 do loop = 1 to numracers
    Xcoord.loop = xc
    xc = xc + 1
 end
 do loop = 1 to numracers
    var = Mount.loop
    call Parsemutant
    v0 = right(Mname,20)
    Tr '\c7'v0
 end    
 do loop = 1 to numracers
    SS '['Xcoord.loop';'Ycoord.loop'H\c'loop||loop    
 end
 SS '[20;1H\c5(\c7F\c5)\c6ire \c4(\c7'bullets.1'\c6 bullets\c4)\c5  \c5(\c7C\c5)\c6hicken Out  \c5(\c7RETURN\c6=Continue\c5)\c6:\c7'

 ne1 = '[12;61H'
 cn1 = '[12;61H  '         
 ne2 = '[13;61H'
 cn2 = '[13;61H  '         

 SS '[12;50H\c2Leader - \c7#'
 SS '[13;50H\c1Last   - \c7#'

 po.1 = '[12;4H'
 po.2 = '[13;4H'
 po.3 = '[14;4H'
 po.4 = '[15;4H'
 po.5 = '[16;4H'
 po.6 = '[17;4H'
 po.7 = '[18;4H'
 SS '[11;1H\c7#  \cbCondition\c7'
 xc = 12
 do loop = 1 to numracers
    SS '['xc';1H\c'loop''loop
    xc = xc + 1
 end
 SS '[1;50H\cbAnd they are OFF!'
 rdone = FALSE

 Rvar.1 = 'W';Rvar.2='P';Rvar.3='S'
 ct=1
 do loop = 1 to numracers
    Rank.loop = loop
 end
 rdone = FALSE;WINNER = FALSE
 do until rdone = TRUE
    do loop = 1 to numracers
       if Ycoord.loop < 60 then do
          if Speed.loop > 0 then move = (randu()*Speed.loop+1)%1
          if Speed.loop <= 0 then do
             SS po.loop'\c4#\c7'loop'\c4 lies dead in its tracks!'
             move = 0
          end
          if Ycoord.loop > 60 then Ycoord.loop = 61
          SS '['Xcoord.loop';'Ycoord.loop'H '
          Ycoord.loop = Ycoord.loop + move
          if Speed.loop > 0 then SS '['Xcoord.loop';'Ycoord.loop'H\c'loop''loop
          if Ycoord.loop >= 60 then do
             WINNER = TRUE
             Rank.loop = Rvar.ct
             ct=ct+1
             if ct >= 2 then rdone = TRUE
          end
          if Speed.loop > 0 then SS '['Xcoord.loop';'Ycoord.loop'H\c'loop||rank.loop
       end                   
    end
    lead = 1;leadpos = Ycoord.1
    do loop = 1 to numracers
       if Ycoord.loop > leadpos then lead = loop
    end
    last = 1;lastpos = Ycoord.1
    do loop = 1 to numracers
       if Ycoord.loop < lastpos then do
          Last = loop
          lastpos = Ycoord.loop
       end
    end
    SS cn1||ne1''lead
    SS cn2||ne2''last
    if Ycoord.1 >= 40 then SS '[1;50H\c1To late to chicken out!\c7  '
    do loop = 1 to numracers
       if Speed.loop > 0 then SS po.loop'\c2Safe.'
    end

    SS '[20;9H'bullets.1'[20;60H'

    Getchar;if result='###PANIC' then signal quit
    ans = upper(result)

    if ans = C & Ycoord.1 < 40 then do
       rdone = TRUE
       money = money - bet%2
    end

    if ans = F & Bullets.1 > 0 then do
       SS '[21;1H\c6Aim at which mutant:\c7 '
       Query '';aim=upper(result);call nocarrier;if rv=1 then signal QUIT
       if aim > 0 & aim <= numracers then do
          Bullets.1 = Bullets.1 - 1
          rhit = (randu()*10+1)%1
          if rhit > Armor.aim then do
             SS po.aim'\c1HIT! '
             Speed.aim = Speed.aim - 1
          end
          if rhit <= Armor.aim then do
             SS po.aim'\c2Safe.'
          end
       end
       SS '[21;1H\c6                      \c7 '
    end
    do loop = 2 to numracers
       ranf = (randu()*2+1)%1
       if ranf = 1 & bullets.loop > 0 then do
          bullets.loop = bullets.loop - 1
          Sflag = FALSE
          sct = 1
          do until Sflag = TRUE
             ranr = (randu()*numracers+1)%1
             if Speed.ranr > 0 then Sflag = TRUE
             sct = sct + 1
             if sct > numracers then Sflag = TRUE
          end
          if ranr = loop then SS po.ranr'\c2Safe.'
          if ranr ~= loop then do
             SS po.ranr
             hit = (randu()*10+1)%1
             if hit > Armor.loop then do
                SS '\c1Hit! '
                Speed.ranr = Speed.ranr - 1
                if Speed.ranr < 0 then Speed.ranr = 0
             end
             if hit <= Armor.loop then SS '\c2Safe.'
          end
       end
    end     
    Alldead = FALSE
    sct = 1
    do until Sflag = TRUE
       ranr = (randu()*numracers+1)%1
       if Speed.ranr > 0 then Sflag = TRUE
       sct = sct + 1
       if sct > numracers then do
          Sflag = TRUE;Alldead = TRUE
          Winner = NONE
       end
    end
 end
 Won = 1
 if WINNER = TRUE then do
    do loop = 1 to numracers
       if Rank.loop = W then Won = LOOP
    end
    Tr CLS'\c6The jockey on mutant #\c7'won'\c6 leads his beast to victory!'
 end
 if WINNER = FALSE then do
    Tr CLS'\c6The speed of the other mutants leave you in the dust as you chicken out of the race.  You lose HALF your bet, better luck nice time coward!'
    Won = 0
 end

 if Won = 1 then do
    Tr '\n1\c6The cashier comes and pays you the pot, \c2"You slime devil!  It is just luck, I warn you.  Here is your $\c7'bet*numracers'\c2"\c6, he throws the money at you and walks away.' 
    money = money + bet*numracers
 end

 if Alldead = True then Tr '\n1\c6All beasts lay motionless in the mud.  Sorry sucker, you lose.'

 if Won ~= 1 then do
    Tr '\n1\c6The cashier comes to collect his money.  You graciously give him $\c7'bet'\c6.'
    money = money - bet
 end

 Tr RET
return

ParseMutant:
 parse var Mutant.var Armor' 'Speed' 'AHP' 'MName'||'MDescrip
return

ERROR:
transmit '\n2\caIllegal Command or Error.. #'sigl
Logentry 'Error in Gamble2.prg...'sigl
return

SYNTAX:
transmit '\n2\caIllegal Command or Error.. #'sigl
Logentry 'Error in Gamble2.prg...'sigl
return

IOERR:
transmit '\n2\caIllegal Command or Error.. #'sigl
Logentry 'Error in Gamble2.prg...'sigl
return

NoCarrier:
GETCARRIER;carrier=result;if carrier=='FALSE' then;rv = 1;else;rv = 0;return

QUIT:
call open file, ('ram:money.tmp'), 'w' 
     call writeln file, money
call close file
call open file, ('ram:done.tmp'), 'w'
     call writeln file, 1
call close file
address command 'delete ram:money.tmp'

bufferflush;exit
