-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.arc
78 lines (64 loc) · 1.76 KB
/
main.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
73
74
75
76
77
78
($ (require web-server/private/timer))
(load "git-db.arc")
(load "objects.arc")
(load "auth.arc")
(load "srv.arc")
(load "web.arc")
; Loads JSON utils
($ (require (file "lib/json.ss")))
($ (xdef read-json read-json))
($ (xdef write-json write-json))
(= git-dir* "./db"
git-ref* "master"
objects* (table))
(def file? (path)
"Return t or nil depending on whether a given file exists"
($ (tnil (file-exists? ,path))))
(def dir? (path)
"Return t or nil depending on whether a given directory exists"
($ (tnil (directory-exists? ,path))))
(git-connect git-dir* git-ref*)
;Load all objects from the repo
(load-objects)
(restore-tables)
(def start-timer-manager ()
"Setup function required before timers can be used"
($ (start-timer-manager)))
(def start-timer (s f)
"Start a timer that waits s seconds before invoking function f"
($ (start-timer s f)))
;money
(deftem (mine building)
name "mine"
type 'money
last-update (seconds)
cost 100
rate 3600
build-time 10)
(def income (prod)
(with (t (seconds)
last-update prod!last-update)
(= prod!last-update t)
(* (/ prod!rate 3600) (- t last-update))))
(def get-balance (u)
(each p (keep [is _!type 'money] u!mines)
(++ u!balance
(income p)))
u!balance)
(def buy (u type)
"Create an instance of an item, deducting its cost from the users balance"
(withs (i (inst type 'owner u!id)
bal (- u!balance i!cost))
(when (> bal 0)
(= u!balance bal)
i)))
(def start-build (u type planet)
(whenlet b (buy u type)
(= b!location planet)
(start-timer b!build-time [finish-build b])))
(def finish-build (b)
(let u (get-user b!owner)
(= b!complete t
b!last-update (seconds)
(buildings* b!id) b)
( b)))