(**************************************************************************)
(*                             W A R N I N G                              *)
(*                                                                        *)
(*  This Robot has NOT been designed to take advantage of the advanced    *)
(*  features of P-ROBOTS, such as, Shields, Fuel, Teams or Obstructions.  *)
(**************************************************************************)

  PROCEDURE CHASER;

{

Based on a C-Robot by Kazuhiro Yabe

}

  VAR
    save_dmg       : Integer;
    cur_dmg        : Integer;
    speed          : Integer;
    dir            : Integer;
    Range          : Integer;
    degree         : Integer;

    PROCEDURE chkdmg;
    BEGIN
      cur_dmg := damage;
      IF (cur_dmg <> save_dmg) THEN
        BEGIN
          save_dmg := cur_dmg;
          speed := 50; {maximum speed that robot can still turn}
          dir := Random(359);
        END;
    END; {chkdmg}

    PROCEDURE walking;
    BEGIN 
      speed := 50; {maximum speed that robot can still turn}
      IF (loc_x < 200) THEN dir := 0
      ELSE IF (loc_x > 800) THEN dir := 180
      ELSE IF (loc_y < 200) THEN dir := 90
      ELSE IF (loc_y > 800) THEN dir := 270;
      drive(dir, speed);
    END; {walking}

    PROCEDURE shoot;
    VAR return     : Boolean;
    BEGIN 
      return := False;
      REPEAT
        REPEAT
          Range := scan(degree, 10);
          IF (Range > 0) THEN
            IF ObjectScanned = Enemy
              THEN BEGIN
                cannon(degree, Range); {while he's there, shoot at him. }
                drive(degree, 100); {charge foe at top speed!}
                return := True;
              END;
        UNTIL Range = 0;
        IF (degree >= 360)
        THEN degree := 0
        ELSE degree := degree+20;
        walking;
      UNTIL return;
    END; {shoot}

  BEGIN {Chaser Main}
    speed := 50; {maximum speed that robot can still turn}
    dir := 0;
    degree := 0;
    save_dmg := damage;

    REPEAT { Until Dead or Winner }
      shoot;
      chkdmg;
      walking; { move at max speed that can still turn }
    UNTIL Dead OR Winner;

  END; { end of Chaser main }

