Release 2;
Serial "000918";

!***********************************************
!*                                             *
!*  This port by Adam Biltcliffe               *
!*                                             *
!*  You may freely distribute this in any way  *
!*  provided its origin is not misrepresented  *
!*                                             *
!***********************************************

Global thirst;
Global canteen;
Global dist;
Global pdist;
Global bflag;
Global camel;
Global pdelay;
Global deadflag;

Array input -> 3;

[ ResetGameState;
   thirst=4;  ! Commands until dying of thirst
   canteen=6; ! Drinks left
   dist=0;    ! Distance travelled
   pdist=0;   ! Distance pygmies travelled
   bflag=0;   ! Berber flag
   camel=0;   ! Camel stress
   pdelay=0;  ! Pygmy delay
   deadflag=0;! End main loop flag
];

[ GetChar;
   input->0=1;
   input->2=0;
   read input 0;
   return input->2;
];

[ Yes;
   switch(GetChar()) {
       'n', 'N': rfalse;
       default: rtrue;
   }
];

[ Main quitflag;
   print "                          CAMEL^                    Creative
          Computing^                  Morristown, New Jersey^^^";
   print "Originally by the Heath Users Group. Ported to the^z-machine
          by Adam Biltcliffe.^^Would you like instructions? ";
   if (Yes()) {
   print   "^^Welcome to CAMEL. The object is to travel^200 miles across
              the great Gobi desert.^A tribe of knock kneed pygmies will be
              chasing you.^You will be asked for commands every so often.
              ^^^C O M M A N D S :
              ^#1 Drink from your canteen
              ^#2 Ahead, moderate speed
              ^#3 Ahead, full speed
              ^#4 Stop for the night
              ^#5 Status check
              ^#6 Hope for help^^^^
              ^You have one quart of water which will last you six drinks.
              ^You may renew your water supply completely at an oasis.
              ^You get half a quart if found by help.
              ^If help does not find you after command six, you lose.^";
   }
   quitflag=0;
   while (quitflag==0) {
       print "Good luck and good camelling !!^You are in the middle of the
              desert at an oasis.^";
       ResetGameState();
       while (~~deadflag) {
           if (dist>199) deadflag=2; else {
               if (UpdateThirst()) {
                   MovePygmies(); ! In the original, the pygmies do not move
                                  ! while you are captive, but the text
                                  ! suggests that they are supposed to
                   if (~~deadflag) {
                       if (bflag) BerberTurn(); else NormalTurn();
                   }
               }
           }
       }
       switch (deadflag) {
           1:  print "You died in the desert.^";
               switch (random(5)) {
                   1: print "The National Camels' Union is not attending
                             your funeral !!!^";
                   2: print "Your body was eaten by vultures and imported
                             cannibals !!!^";
                   3: print "The local sheik now uses your skull for a
                             change purse !!!^";
                   4: print "People with little intelligence should stay
                             out of the desert.^";
                   5: print "Turkeys should fly, not ride camels !!!!!!!^";
               }
           2:  print "You win, a party is being given in your honour .......
                     ^....... the pygmies are planning to attend .......^";
       }
       print "^^Want a new camel and a new game? ";
       if (~~Yes()) { quitflag=1; "-----------------^     CHICKEN
                                  ^-----------------"; }
   }
];

[ UpdateThirst;
   thirst--;
   if (thirst==1)
       print "----------W A R N I N G---------- Get a drink^";
   if (thirst<0) {
       print "You ran out of water ..... sorry, chum !!!^";
       deadflag=1; rfalse;
   }
   rtrue;
];

[ MovePygmies;
   pdelay++;
   if (pdelay>3) {
       pdist=pdist+random(10)+1; ! Not quite the same as the
                                 ! original, but close enough
       if (pdist>=dist) {
           print "The pygmies have captured you. Camel and
                  people soup is^their favourite dish !!!!!^";
           deadflag=3;
       }
   }
];

[ BerberTurn cmd;
   print "#7 Attempt an escape^#8 Wait for payment^";
   cmd=0; while (cmd==0) {
       print "Your sub-command? ";
       cmd=GetChar();
       switch(cmd) {
           '1': TakeDrink(); if (~~deadflag) BerberTurn(); ! The original
                           ! didn't allow this, but I think it's only fair
           '7': Escape();
           '8': Wait();
       }
   }
];

[ Escape;
   if (random(2)==1) {
       bflag=0; "Congratulations, you successfully escaped !!!!";
   }
   deadflag=1; "You were mortally wounded by a pig stabber while escaping.";
];

[ Wait;
   if (random(4)==1) {
       bflag=0; "Your ransom has been paid and you are free to go.";
   }
   "The local sultan is collecting ....... just wait .......";
];

[ NormalTurn;
   if (pdelay>3) print "The pygmies are ", dist-pdist, " miles behind you.^";
   print "You have travelled ", dist, " miles altogether.^";
   DoCommand();
];

[ DoCommand cmd;
   cmd=0; while (cmd==0) {
       print "What is your command? ";
       cmd=GetChar();
       switch(cmd) {
           '1': TakeDrink(); if (~~deadflag) DoCommand();
           '2': AheadModerate();
           '3': AheadFull();
           '4': RestNight();
           '5': StatusCheck(); DoCommand();
           '6': HopeForHelp();
       }
   }
];

[ TakeDrink;
   canteen--;
   if (canteen<0) {
       thirst=0; UpdateThirst();
   } else {
       thirst=4;
       "Better watch for an oasis !";
   }
];

[ AheadModerate;
   camel++;
   if (camel>7) KillCamel(); else {
       DoEvent();
       if (~~bflag) {
           dist=dist+random(10)-1;
           "Your camel likes this pace.";
       }
   }
];

[ AheadFull;
   camel=camel+3;
   if (camel>7) {
       KillCamel();
   } else {
       DoEvent();
       if (~~bflag) {
           dist=dist+(2*(random(10)-1));
           "Your camel is burning across the desert sands.";
       }
   }
];

[ RestNight;
   camel=0;
   "Your camel thanks you !";
];

[ StatusCheck;
   ! Note that this no longer does an implicit drink as the original did
   print "Your camel has ", 7-camel, " good days left.^You have ", canteen,
         " drinks in your canteen.^You can go ", thirst, " commands without
         drinking.^";
];

[ HopeForHelp;
   if (random(10)==1) {
       thirst=4; canteen=3;
       "Help has found you in a state of unconsciousness.";
   } else deadflag=1;
];

[ KillCamel;
   deadflag=1;
   "You dirty rapscallion ! You ran your poor camel to death !!";
];

[ DoEvent;
   switch(random(1000)) {
       1 to 50: Capture();
       51 to 240: Oasis();
       241 to 277: Sandstorm();
       278 to 312: Injury(); ! Yes, this is 0.01% less likely than in
                             ! the original. Sorry.
   }
];

[ Capture;
   print "Wild berbers hidden in the sand have captured you.^Luckily the
          local sheik has agreed to their ransom-^demands ....... but
          ....... watch for the pygmies !!!^You have a new choice of
          sub-commands:^";
   bflag=1;
   BerberTurn();
];

[ Oasis;
   thirst=4; canteen=6;
   "You have arrived at an oasis -------- Your camel is^filling your canteen
    and eating figs.";
];

[ Sandstorm;
   print "You have been caught in a sandstorm ..... good luck !^";
   dist=dist+random(19)-10;
   print "Your new position is ", dist, " miles so far !^";
];

[ Injury;
   pdist++;
   "Your camel hurt his hump.^Luckily the pygmies were footweary !!!";
];