home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Hack-Phreak Scene Programs
/
cleanhpvac.zip
/
cleanhpvac
/
P_ROBO31.ZIP
/
NINJA.PR
< prev
next >
Wrap
Text File
|
1989-10-23
|
4KB
|
149 lines
(**************************************************************************)
(* 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 Ninja;
{ Author unknown }
{ Based on C-Robot Ninja }
{ Locks on to a target and attacks }
VAR vector : Integer; { current attack vector }
PROCEDURE charge(vec, Range, maxspd : Integer); { charge at an enemy }
{ vec : attack vector to use }
{ range : range to target }
{ maxspd : maximum speed to use }
BEGIN
IF (Range > 40) AND (Range < 800) THEN { good shooting range }
IF ObjectScanned = Enemy
THEN cannon(vec, Range); { fire! }
drive(vec, maxspd); { charge! }
END; { charge }
FUNCTION Pin(vec : Integer) : Integer; { pin down a target }
{ vec : initial vector }
VAR
tv : Integer; { trial vector }
ts : Integer; { trial scan results }
n : Integer; { index }
return : Integer;
BEGIN
tv := vec-10; { coarse screen }
n := 2;
ts := scan(tv, 10);
WHILE (n > 0) AND (ts = 0) DO
BEGIN
tv := tv+20;
n := n-1;
ts := scan(tv, 10);
END;
IF ts = 0
THEN return := 0
ELSE BEGIN
charge(tv, ts, 50);
tv := tv-10; { medium screen }
n := 4;
ts := scan(tv, 5);
WHILE (n > 0) AND (ts = 0) DO
BEGIN
tv := tv+10;
n := n-1;
ts := scan(tv, 5);
END;
IF ts = 0
THEN return := 0
ELSE BEGIN
charge(tv, ts, 50);
tv := tv-4; { fine screen }
n := 3;
ts := scan(tv, 2);
WHILE (n > 0) AND (ts = 0) DO
BEGIN
tv := tv-4;
n := n-1;
ts := scan(tv, 2);
END;
IF ts = 0
THEN return := 0
ELSE BEGIN { found it! }
return := ts; { say how far away it is }
vector := tv;
END;
END; { fine screen }
END; { medium screen }
Pin := return;
END; { Pin }
PROCEDURE attack;
VAR
Range : Integer; { range to locked target }
return : Boolean;
BEGIN
return := False;
REPEAT
Range := scan(vector, 0);
IF (Range > 0)
THEN charge(vector, Range, 100) { got him! }
ELSE IF Pin(vector) = 0 THEN { lost him! }
return := True; { can't find him }
UNTIL return;
END; { Attack }
FUNCTION Find : Integer; { find a new target }
VAR
off : Integer; { offset }
dir : Boolean; { direction }
tv : Integer; { trial vector }
return : Integer;
BEGIN {Find}
off := 180; { half circle sweep }
dir := False; { counter-clockwise first }
tv := (vector+180) MOD 360; { look behind us first }
return := 0; {no target found - default}
WHILE (off >= 0) AND (return = 0) DO { full scan }
BEGIN
IF (scan(tv, 10) > 0) THEN { see anyone? }
return := Pin(tv); { nail him! }
dir := NOT dir;
IF dir { alternate sides }
THEN BEGIN
off := off-20;
tv := vector+off;
END
ELSE tv := vector-off+360;
tv := tv MOD 360;
END;
Find := return;
END; {Find}
BEGIN {Ninja Main}
vector := Random(360);
REPEAT
IF (speed = 0) THEN drive(vector, 30)
ELSE IF (Find > 0)
THEN attack { if we see anyone attack }
ELSE vector := Random(360);
UNTIL Dead OR Winner;
END; {Ninja Main}