Skip to content

Commit 3d1533b

Browse files
committed
Add some new files, misc changes + combat system
1 parent 1cfa511 commit 3d1533b

File tree

7 files changed

+221
-74
lines changed

7 files changed

+221
-74
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
db/
2+
.floo

actors.arc

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
(def -> (proc . msg)
2+
"Send a message to a process"
3+
(thread-send rep.proc msg))
4+
5+
(mac <- body
6+
"Receive a message using pattern matching"
7+
`(apply (p-m:fn ,@body)
8+
(thread-receive)))
9+
10+
(mac defproc (name args . body)
11+
`(def ,name ,args
12+
(annotate 'proc
13+
(thread ((afn ,args
14+
(<- ,@(apply join
15+
(map [list car._ `(do ,cadr._ (self ,@args))]
16+
pair.body))))
17+
,@args)))))
18+
19+
(defcall proc (p . msg)
20+
(thread-send rep.p msg))

auth.arc

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,4 @@
4242
(def set-session-id (id)
4343
" Assign the user a new session-id, and return it "
4444
(let sid (trunc (* (rand) (expt 10 10)))
45-
(= users*.id!session-id sid)))
45+
(= users*.id!session-id sid)))

combat.arc

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
(deftem ship
2+
type 'ship
3+
unit-type nil ; type of unit
4+
weapons nil ; temp placeholder (defines attack value)
5+
hull nil ; temp placeholder (defines armor value)
6+
)
7+
8+
(deftem weapon
9+
type 'weapon
10+
weapon-type nil
11+
damage nil
12+
speed 1
13+
)
14+
15+
(= weapons* (table))
16+
(mac defweap (name offense speed)
17+
`(= weapons.name (inst 'weapon 'weapon-type ,name 'damage ,damage 'speed ,speed)))
18+
19+
(= weapons*!laser (inst 'weapon 'weapon-type 'laser 'damage 1 'speed 1))
20+
21+
(deftem (frigate ship)
22+
unit-type 'frigate
23+
weapons (list weapons*!laser)
24+
hull 2
25+
)
26+
27+
(def fire (weapon target)
28+
(-- target!hull weapon!damage))
29+
30+
(def choose (xs)
31+
(let l len.xs
32+
(xs rand.l)))
33+
34+
(def alternate (f a b)
35+
(f a b)
36+
(f b a))
37+
38+
(def barrage (red blue)
39+
(each s red
40+
(each w s!weapons
41+
(repeat w!speed (fire w choose.blue)))))
42+
43+
(def triage (fleet)
44+
(pull [< _!hull 1] fleet))
45+
46+
(= prepare idfn)
47+
48+
(def engage (red blue)
49+
(prepare red)
50+
(barrage red blue)
51+
red)
52+
53+
(mac multizap (op . xs)
54+
`(do
55+
,@(accum acc
56+
(each x xs
57+
(acc `(zap ,op ,x))))))
58+
59+
(def battle (red blue)
60+
(alternate engage red blue)
61+
(map triage (list red blue)))
62+
63+
(def status (army)
64+
(let c (counts army)
65+
(map (fn ((t n)) (list t!unit-type t!hull n)) tablist.c)))
66+
67+
(def list-of (n f)
68+
(accum acc
69+
(repeat n (acc (f)))))
70+
71+
(def fleet units
72+
(mappend (fn ((t n)) (list-of n [inst t])) pair.units))

main.arc

+53-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
($ (require web-server/private/timer))
12
(load "git-db.arc")
23
(load "objects.arc")
34
(load "auth.arc")
@@ -14,13 +15,64 @@
1415
objects* (table))
1516

1617
(def file? (path)
18+
"Return t or nil depending on whether a given file exists"
1719
($ (tnil (file-exists? ,path))))
1820

1921
(def dir? (path)
22+
"Return t or nil depending on whether a given directory exists"
2023
($ (tnil (directory-exists? ,path))))
2124

2225
(git-connect git-dir* git-ref*)
2326

2427
;Load all objects from the repo
2528
(load-objects)
26-
(restore-tables)
29+
(restore-tables)
30+
31+
(def start-timer-manager ()
32+
"Setup function required before timers can be used"
33+
($ (start-timer-manager)))
34+
35+
(def start-timer (s f)
36+
"Start a timer that waits s seconds before invoking function f"
37+
($ (start-timer s f)))
38+
39+
;money
40+
(deftem (mine building)
41+
name "mine"
42+
type 'money
43+
last-update (seconds)
44+
cost 100
45+
rate 3600
46+
build-time 10)
47+
48+
(def income (prod)
49+
(with (t (seconds)
50+
last-update prod!last-update)
51+
(= prod!last-update t)
52+
(* (/ prod!rate 3600) (- t last-update))))
53+
54+
(def get-balance (u)
55+
(each p (keep [is _!type 'money] u!mines)
56+
(++ u!balance
57+
(income p)))
58+
u!balance)
59+
60+
(def buy (u type)
61+
"Create an instance of an item, deducting its cost from the users balance"
62+
(withs (i (inst type 'owner u!id)
63+
bal (- u!balance i!cost))
64+
(when (> bal 0)
65+
(= u!balance bal)
66+
i)))
67+
68+
(def start-build (u type planet)
69+
(whenlet b (buy u type)
70+
(= b!location planet)
71+
(start-timer b!build-time [finish-build b])))
72+
73+
(def finish-build (b)
74+
(let u (get-user b!owner)
75+
(= b!complete t
76+
b!last-update (seconds)
77+
(buildings* b!id) b)
78+
( b)))

objects.arc

+3-2
Original file line numberDiff line numberDiff line change
@@ -33,15 +33,16 @@
3333
(deftem (planet object)
3434
type 'planet
3535
system nil ; reference to system
36-
planet_type nil ; type of planet
36+
planet-type nil ; type of planet
3737
size nil ; size of planet
3838
location nil ; 3D coordinates
3939
residents nil ; list of references to players
40+
buildings nil
4041
) ; that live on the planet (may just be one)
4142

4243
(deftem (unit object)
4344
type 'unit
44-
unit_type nil ; type of unit
45+
unit-type nil ; type of unit
4546
location nil ; reference to planet,system,space,etc
4647
health nil ; health of unit
4748
attack nil ; temp placeholder (defines attack value)

0 commit comments

Comments
 (0)