-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcombat.arc
72 lines (56 loc) · 1.38 KB
/
combat.arc
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
65
66
67
68
69
70
71
72
(deftem ship
type 'ship
unit-type nil ; type of unit
weapons nil ; temp placeholder (defines attack value)
hull nil ; temp placeholder (defines armor value)
)
(deftem weapon
type 'weapon
weapon-type nil
damage nil
speed 1
)
(= weapons* (table))
(mac defweap (name offense speed)
`(= weapons.name (inst 'weapon 'weapon-type ,name 'damage ,damage 'speed ,speed)))
(= weapons*!laser (inst 'weapon 'weapon-type 'laser 'damage 1 'speed 1))
(deftem (frigate ship)
unit-type 'frigate
weapons (list weapons*!laser)
hull 2
)
(def fire (weapon target)
(-- target!hull weapon!damage))
(def choose (xs)
(let l len.xs
(xs rand.l)))
(def alternate (f a b)
(f a b)
(f b a))
(def barrage (red blue)
(each s red
(each w s!weapons
(repeat w!speed (fire w choose.blue)))))
(def triage (fleet)
(pull [< _!hull 1] fleet))
(= prepare idfn)
(def engage (red blue)
(prepare red)
(barrage red blue)
red)
(mac multizap (op . xs)
`(do
,@(accum acc
(each x xs
(acc `(zap ,op ,x))))))
(def battle (red blue)
(alternate engage red blue)
(map triage (list red blue)))
(def status (army)
(let c (counts army)
(map (fn ((t n)) (list t!unit-type t!hull n)) tablist.c)))
(def list-of (n f)
(accum acc
(repeat n (acc (f)))))
(def fleet units
(mappend (fn ((t n)) (list-of n [inst t])) pair.units))