-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprobe.rkt
64 lines (53 loc) · 2.2 KB
/
probe.rkt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#lang racket/base
(require racket/class
racket/math
mode-lambda
racket/draw)
(require "defs.rkt"
"utils.rkt"
"ships.rkt"
"draw-utils.rkt")
(provide (all-defined-out))
(define (dmg-ptube tool)
(cond
((null? (tool-dmgs tool))
(if ((random) . < . 0.5)
(list (chadd (dmg (next-id) "offline" DMG_SIZE 0 DMG_FIX?) (ob-id tool)))
(list (chadd (dmg (next-id) "nofire" DMG_SIZE 0 DMG_FIX?) (ob-id tool)))))
(((length (tool-dmgs tool)) . < . 2)
(if (equal? "offline" (dmg-type (car (tool-dmgs tool))))
(list (chadd (dmg (next-id) "nofire" DMG_SIZE 0 DMG_FIX?) (ob-id tool)))
(list (chadd (dmg (next-id) "offline" DMG_SIZE 0 DMG_FIX?) (ob-id tool)))))
(else
#f)))
;; client/server
(define (launch-probe! cmd space stack who)
(define ship (get-ship stack))
(define tool (ship-tool ship 'probe))
(cond
((not (ship-flying? ship))
(printf "~a discarding message (not flying) ~v\n" who cmd)
(values #f '()))
((not tool)
(printf "~a discarding message (no probe tool) ~v\n" who cmd)
(values #f '()))
(else
(define changes '())
(when (server?)
(define a (angle-add (obj-r ship) pi))
(define p (make-ship "probe" "Probe" (ship-faction ship)
#:radar 1000 #:hull 10 #:drag 0.4 #:mass 1
#:tools (append (tools-pilot 100.0 #t 1.0
#:engine-visible? #f #:dock? #f)
(list (tool-endrc (tool-val tool))))))
(define d (+ (ship-radius ship) (* 2.0 (ship-radius p))
(random-between 0 1))) ; random so things don't end up exactly aligned
(set-obj-posvel! p (posvel (space-time space)
(+ (obj-x ship) (* d (cos a)))
(+ (obj-y ship) (* d (sin a)))
a
(obj-dx ship)
(obj-dy ship)
0))
(append! changes (chadd p #f) (chrc (ob-id (car stack)) (ob-id p))))
(values #f changes))))