#side Teledont This is almots a complete rewrite of Teledont. It now uses multiple sensor returns for food and robots. It selects the largest food to eat. It also tries to avoid friendly fire but this doesn't seem to work yet. #author Matt Burkholder #date 22 Nov 2002 #color 55f #type Teledont #color a0a #hardware processor 25 engine 0.2 constructor 1.0 energy 1500 20 solar-cells .2 eater 5 robot-sensor 25 5 food-sensor 12 5 armor 602 repair-rate .1 blaster 14 25 4 #code #vector target #vector dest #vector Home #var Target-Direction 0 #var Target-Result 0 #var Target-Loop 0 #var Food-Good 0 #var robot-sensor-now 0 #var Take-a-Shot 0 #var Home-Factor 1 #var Dist-Factor 2 #vector Center #var Run-Min #var Run-Factor #var Shoot-Factor blaster-range 2 - Run-Min! 100 blaster-range / Shoot-Factor! 140 blaster-range / Run-Factor! do speed while-loop 1 robot-sensor-sees-friends! position 50 < 20 80 ifev swap 50 < 20 80 ifev swap Home! Home dest! food-sensor-range 0.25 * food-sensor-focus-distance! do energy 750 > energy constructor-remaining 1.25 * > or constructor-max-rate 0 ifev constructor-rate! 1 constructor-type! armor max-armor < energy 20 > and max-repair-rate 0 ifev repair-rate! Need-Food^ dup time robot-sensor-now > or if fire-robot-sensor dup Scan-Food& ifc sync Pick-Food& ifc robot-found if 0 Take-a-Shot! 0 Target-Loop! do Target-Loop current-robot-result! Do-I-Shoot-It^ if robot-position Target! current-robot-result Target-Result! Time Take-a-shot! Too-Close^ if -5 robot-Direction polar-to-rect position v+ dest! then do current-robot-result Take-a-Shot and while current-robot-result 1 - current-robot-result! In-the-Way^ if -5 Target-Direction polar-to-rect position v+ dest! 0 Take-a-shot! then loop Target-Result current-robot-result! then Target-Loop 1 + Target-Loop! Target-Loop num-robot-results < Take-a-Shot not and while-loop time 20 + robot-sensor-now! else time 100 + robot-sensor-now! 0 Take-a-Shot! then else drop Move-Home^ then Take-a-Shot Blaster-Cooldown 1 <= and Compute-and-Fire& ifc Motion^ forever Do-I-Shoot-It: robot-side side <> dup if Take-a-shot energy 950 > or robot-distance robot-mass Shoot-Factor / 12 max < or and then return Too-Close: robot-distance robot-mass Run-Factor / Run-Min min < armor 120 < or return In-the-Way: robot-side side = dup if ;target robot-position v- 2dup target project v- rect-to-polar Target-Direction! robot-position position v- 2dup target position v- project v- rect-to-polar Target-Direction! robot-radius 2.5 * < and then return Compute-and-Fire: robot-position position v- 2dup target! robot-velocity velocity v- robot-distance blaster-speed / time Take-a-Shot - + vs* v+ rect-to-polar swap Blaster-Range < if fire-blaster else drop then return Need-Food: eaten engine-power or not friendly-collision or return Scan-Food: Home position v- angle food-sensor-focus-direction! fire-food-sensor return Pick-Food: 0 Food-Good! food-found if do food-energy food-position home dist Home-Factor * - food-distance Dist-Factor * - dup Food-Good > if Food-Good! food-position dest! robot-found if 0 Target-Loop! do Target-Loop current-robot-result! food-position robot-position food-distance 2 / in-range robot-side side = and if 0 Food-Good! then Target-Loop 1 + Target-Loop! Target-Loop num-robot-results < food-good and while-loop then else drop then next-food while-loop then Food-Good nif 10 Home Position 25 in-range random-angle food-sensor-focus-direction ifev polar-to-rect position v+ dest! then return Move-Home: 1 type-population 3 > Position Home 20 in-range and nifr Home 50 50 v- rect-to-polar 1.57 + polar-to-rect 50 50 v+ Home! return Motion: dest 3 max 97 min swap 3 max 97 min swap Seek-location return #end