; This sucks... I know nothing about halflife. (define-signal bot-x (get-x)) (define-signal bot-y (get-y)) (define-signal yaw-radians (degrees->radians (get-absolute-yaw))) (define-signal bot-sin (sin yaw-radians)) (define-signal bot-negative-sin (- bot-sin)) (define-signal bot-cos (cos yaw-radians)) (define-signal (global->egocentric xy) (let ((x (- (x-of xy) bot-x)) (y (- (y-of xy) bot-y))) (xy-vector (+ (* bot-cos x) (* bot-sin y)) (+ (* bot-cos y) (* bot-negative-sin x))))) (define-signal (follow-xy-vector xy) (let* ((a (angle xy)) (a2 (normalize-radians (+ a (* pi 1/4)))) (unit (unit-vector a))) (cond ((<= a2 (/ pi 2)) (hl-bot-vector (round->integer (* 5000 (y-of unit))) 2 0 0 #f #f #f #f 0 #f #f)) ((< a2 pi) (hl-bot-vector (round->integer (* 5000 (x-of unit))) 0 -2 0 #f #f #f #f 0 #f #f)) ((<= a2 (* pi 3/2)) (hl-bot-vector (round->integer (* -5000 (y-of unit))) -2 0 0 #f #f #f #f 0 #f #f)) (else (hl-bot-vector (round->integer (* -5000 (x-of unit))) 0 2 0 #f #f #f #f 0 #f #f))))) (define-signal (distance x y) (sqrt (+ (square (- x bot-x)) (square (- y bot-y))))) (define-action (goto-xy (x 0) (y 0)) (terminate-when (< (distance x y) 20)) (follow-xy-vector (global->egocentric (xy-vector x y)))) (define-signal jump-and-go-active? #f) (define-action (jump-and-go (x 0) (y 0)) (terminate-when (< (distance x y) 20)) (if (one-shot jump-and-go-active?) (hl-bot-vector 0 2 0 0 #f #f #t #f 0 #f #f) (follow-xy-vector (global->egocentric (xy-vector x y))))) (define-signal jump-and-go-active? (active? jump-and-go)) (define-signal timer (true-time (flip-flop (is-moving) #f))) (define-signal two-minute-kill-behavior (behavior (> timer (* 2 60 1000)) (if (> timer (+ 500 (* 2 60 1000))) (hl-bot-vector 0 0 0 0 #f #f (toggle #t) #f 0 #f #f) limp-hl-motor-vector))) (define-action (match-yaw-pitch (yaw 0) (pitch 0)) (terminate-when (and (< (abs (subtract-angles-degrees yaw (get-absolute-yaw))) 5) (< (abs (subtract-angles-degrees pitch (get-absolute-pitch))) 5))) (hl-bot-vector (round->integer (* 100 (subtract-angles-degrees yaw (get-absolute-yaw)))) 0 0 (round->integer (* 100 (subtract-angles-degrees (get-absolute-pitch) pitch))) #f #f #f #f 0 #f #f)) (define-action (select-weapon (w 0)) (terminate-when (= (get-current-weapon) w)) (hl-bot-vector 0 0 0 0 #f #f #f #f w #f #f)) (define-action (charge-tau-cannon) (hl-bot-vector 0 0 0 0 #f #f #f #t 0 #f #f)) (define-plan (tau-hop (yaw 0) (pitch 0) (ms 0)) (match-yaw-pitch yaw pitch) (select-weapon weapon-gauss) (start (charge-tau-cannon)) (sleep ms) (stop charge-tau-cannon) (sleep 200) (match-yaw-pitch yaw 0)) (define-plan (path) (initially-running? #t) ; get 357 (goto-xy -276 -507) (goto-xy -317 -454) (goto-xy -328 -558) ; get big ammo cache (goto-xy 407 50) (goto-xy 443 529) (goto-xy 452 639) (goto-xy 335 647) (goto-xy 498 723) (goto-xy 561 677) ; (goto-xy 596 705) ; get shotgun (goto-xy 759 455) (goto-xy 883 667) (goto-xy 853 1283) (goto-xy 729 1281) (goto-xy 668 1232) (goto-xy 609 1268) ; go upstairs (goto-xy -54 857) (goto-xy -66 559) (goto-xy -260 578) (goto-xy -280 1264) ; Get crossbow (goto-xy 338 1240) (goto-xy 400 1213) (goto-xy 420 1286) (goto-xy 479 1257) ; Up top, head for tau cannon (goto-xy 1166 1248) (goto-xy 1148 -276) (goto-xy 1297 -274) (goto-xy 1282 -1039) ; Jump off and get snarks (goto-xy 2678 -852) ; Head over to laser mines (goto-xy 2424 -579) (goto-xy 2420 481) (goto-xy 2416 566) (goto-xy 2215 579) ; jump up on the box. Go us! (tau-hop 0 90 700) (goto-xy 2069 589) (goto-xy 2093 667) ; Go over to the ramp, go upstairs (goto-xy 2415 1230) ; grenades (goto-xy 2858 1221) (goto-xy 2941 1194) ; head up, get rockets, egon gun (goto-xy 2917 -296) (goto-xy 2763 -345) (goto-xy 2923 -588) (goto-xy 2863 -971) (goto-xy 2436 -952) (goto-xy 2416 566) (goto-xy 2215 579) (tau-hop 0 90 700) (goto-xy 2069 589) (goto-xy 2093 667) ; Lets head back for some more shotgun and crossbow action (goto-xy 1294 1119) ; shotgun (goto-xy 853 1283) (goto-xy 729 1281) (goto-xy 668 1232) (goto-xy 609 1268) ; to ramp (goto-xy -54 857) (goto-xy -66 559) (goto-xy -260 578) (goto-xy -280 1264) ;crossbow again (goto-xy 338 1240) (goto-xy 420 1286) (goto-xy 479 1257) (goto-xy 400 1213) ; Go for more 357 ammo (goto-xy -54 857) (goto-xy -115 61) (goto-xy 15 -142) (goto-xy -276 -507) (goto-xy -328 -558) ; And now, lets head back to the laser mines (goto-xy -143 -637) (goto-xy 1150 -694) (goto-xy 1278 -704) (goto-xy 1732 290) ; Jump up on a box and get a refill on the tau cannon (tau-hop 245 90 700) (goto-xy 1797 329) (goto-xy 1806 395) (goto-xy 1849 300) (goto-xy 1907 356) ; leap across to the next box! (jump-and-go 2058 494) (goto-xy 2069 589) (goto-xy 2093 667) ; Let's head back for some more shotgun and crossbow action. Again. (goto-xy 1294 1119) ; shotgun (goto-xy 853 1283) (goto-xy 729 1281) (goto-xy 668 1232) (goto-xy 609 1268) ; to ramp (goto-xy -54 857) (goto-xy -66 559) (goto-xy -260 578) (goto-xy -280 1264) ;crossbow again (goto-xy 338 1240) (goto-xy 400 1213) (goto-xy 420 1286) (goto-xy 479 1257)) (define-signal main-signal (drive-hl-bot two-minute-kill-behavior charge-tau-cannon select-weapon match-yaw-pitch jump-and-go goto-xy)) (define (doit) (load fname) (compile-to-c++ "npc" "c:/robots/jorschbot" main-signal path)) (define fname "c:/robots/jorschbot/bot.scm") ; ,load c:\robots\hl-bot-interface.scm ; ,open c-generator