crobs/ogre2.r
001 | /* |
002 |
003 | ===================================================== |
004 | = = |
005 | = O G R E = |
006 | = = |
007 | = ogre (o*ger) n. 1. in fairy tales and = |
008 | = folklore, a man-eating giant. 2. a = |
009 | = hideous, cruel man. 3. a slightly = |
010 | = improved (compared to Hack_Atak) C = |
011 | = robot program, with a greater deal of = |
012 | = complexity and, hopefully, = |
013 | = survivability. = |
014 | = = |
015 | = written by John Nordlie on 3/26/91 = |
016 | = = |
017 | ===================================================== |
018 |
019 | */ |
020 |
021 |
022 | /* Procedures ... */ |
023 |
024 |
025 | /* classical pythagorean distance formula */ |
026 |
027 | distance(x1,y1,x2,y2) |
028 | int x1; |
029 | int y1; |
030 | int x2; |
031 | int y2; |
032 | { |
033 | int x, y; |
034 |
035 | x = x1 - x2; |
036 | y = y1 - y2; |
037 | d = sqrt ((x*x) + (y*y)); |
038 | return (d); |
039 | } |
040 |
041 |
042 | /* tracking subroutine */ |
043 |
044 | track(d,r,l) |
045 | int d,r,l; |
046 | { |
047 | if (r > l) |
048 | { |
049 | if (scan(d-r,r) > 0) |
050 | return (track(d-r,r/2,l)); |
051 | else |
052 | if (scan(d+r,r) > 0) |
053 | return (track(d+r,r/2,l)); |
054 | else |
055 | if (scan(d,r) > 0) |
056 | return (track(d,r/2,l)); |
057 | else |
058 | return (d); |
059 | } |
060 | else |
061 | return (d); |
062 | } |
063 |
064 |
065 |
066 | /* plot course function, return degree heading to */ |
067 | /* reach destination x, y; uses atan() trig function */ |
068 |
069 | plot_course(xx,yy) |
070 | int xx, yy; |
071 | { |
072 | int d; |
073 | int x,y; |
074 | int scale; |
075 | int curx, cury; |
076 |
077 | scale = 100000; /* scale for trig functions */ |
078 | curx = loc_x(); /* get current location */ |
079 | cury = loc_y(); |
080 | x = curx - xx; |
081 | y = cury - yy; |
082 |
083 | /* atan only returns -90 to +90, so figure out how to use */ |
084 | /* the atan() value */ |
085 |
086 | if (x == 0) { /* x is zero, we either move due north or south */ |
087 | if (yy > cury) |
088 | d = 90; /* north */ |
089 | else |
090 | d = 270; /* south */ |
091 | } else { |
092 | if (yy < cury) { |
093 | if (xx > curx) |
094 | d = 360 + atan ((scale * y) / x); /* south-east, quadrant 4 */ |
095 | else |
096 | d = 180 + atan ((scale * y) / x); /* south-west, quadrant 3 */ |
097 | } else { |
098 | if (xx > curx) |
099 | d = atan ((scale * y) / x); /* north-east, quadrant 1 */ |
100 | else |
101 | d = 180 + atan ((scale * y) / x); /* north-west, quadrant 2 */ |
102 | } |
103 | } |
104 | return (d); |
105 | } |
106 |
107 |
108 |
109 | /* Main program (as if you needed to be reminded) */ |
110 |
111 | main() { |
112 | int x, y, x1, y1, range, velocity, resolution, max_cannon, dist, angle; |
113 |
114 | max_cannon = 700; |
115 | angle = 0; |
116 | resolution = 10; |
117 | x1 = rand (900) + 50; |
118 | y1 = rand (900) + 50; |
119 | drive((plot_course(x1, y1)), 100); |
120 | while (1) { |
121 | x = loc_x(); |
122 | y = loc_y(); |
123 | range = scan(angle, resolution); |
124 | while ((range > 40) && (range < max_cannon)) { |
125 | angle = track(angle, resolution, 2); |
126 | range = scan(angle, 10); |
127 | cannon(angle, range); |
128 | x = loc_x(); |
129 | y = loc_y(); |
130 | if (((distance(x,y,x1,y1)) < 100) || ((speed()) == 0)) { |
131 | x1 = rand (900) + 50; |
132 | y1 = rand (900) + 50; |
133 | drive((plot_course(x1,y1)), 100); |
134 | } |
135 | } |
136 | angle = angle + 19; |
137 | if (angle > 360) |
138 | angle = angle - 360; |
139 | if (((speed()) == 0) || ((distance(x,y,x1,y1)) < 100)) { |
140 | x1 = rand (900) + 50; |
141 | y1 = rand (900) + 50; |
142 | drive((plot_course(x1,y1)), 100); |
143 | } |
144 | } |
145 | } |