-
Notifications
You must be signed in to change notification settings - Fork 1
/
foes.hoon
232 lines (232 loc) · 5.54 KB
/
foes.hoon
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
:: %foes
::
:: Coded by ~hanfel-dovned
:: Designed by ~tiller-tolbus
::
:: A counterpart to %pals for identifying malicious users.
::
:: An enemy is someone you accuse.
:: A suspect is someone your mutual pal accuses.
::
:: You will tell your mutual pals about people you accuse,
:: and they'll flag them as suspects.
::
:: Your mutual pals will tell you about people they accuse,
:: and you'll flag them as suspects.
::
:: Scry Paths:
:: /x/enemies - Returns a (set ship) of all your enemies
:: /x/enemies/@p - Returns a (set tag) of your tags for that enemy
:: /x/suspects - Returns a (map ship (set ship)) of all suspects
:: /x/suspects/@p - Returns a (set ship) of all accused by that accuser
::
:: Subscription Paths:
:: /enemies - Pushes an %accuse or %unaccuse when you accuse or unaccuse someone
:: /suspects - Pushes a %suspected or %unsuspected when one of your pals accuses or unaccuses someone
::
/- *foes, pals
/+ dbug, default-agent
::
|%
::
+$ versioned-state $%(state-0)
::
+$ state-0 [%0 =suspects =enemies targets=(set @p) public=?]
::
+$ card $+(card card:agent:gall)
--
::
%- agent:dbug
=| state-0
=* state -
::
^- agent:gall
::
|_ =bowl:gall
+* this .
def ~(. (default-agent this %|) bowl)
::
++ on-init
^- (quip card _this)
:_ this(public %.n)
:~ :* %pass /targets %agent
[our.bowl %pals] %watch /targets
==
==
::
++ on-save
^- vase
!>(state)
::
++ on-load
|= old-state=vase
^- (quip card _this)
=/ old !<(versioned-state old-state)
?- -.old
%0 `this(state old)
==
::
++ on-poke
|= =cage
^- (quip card _this)
?> =(src.bowl our.bowl)
?> =(-.cage %foes-action)
=/ act !<(action +.cage)
?- -.act
%accuse
:_ this(enemies (~(put by enemies) ship.act ~))
[%give %fact ~[/enemies] %foes-update !>([%accuse ship])]~
::
%unaccuse
:_ this(enemies (~(del by enemies) ship.act))
[%give %fact ~[/enemies] %foes-update !>([%unaccuse ship])]~
::
%add-tag
=- `this(enemies (~(put by enemies) ship.act -))
%. tag.act
%~ put
in
(~(got by enemies) ship.act)
::
%remove-tag
=- `this(enemies (~(put by enemies) ship.act -))
%. tag.act
%~ del
in
(~(got by enemies) ship.act)
::
%switch-public
?: =(public %.y)
`this(public %.n)
`this(public %.y)
==
::
++ on-agent
|= [=wire =sign:agent:gall]
^- (quip card _this)
?+ wire (on-agent:def wire sign)
[%targets ~]
?+ -.sign (on-agent:def wire sign)
%fact
?+ p.cage.sign (on-agent:def wire sign)
%pals-effect
=/ effect
!<(effect:pals q.cage.sign)
?+ -.effect (on-agent:def wire sign)
%meet
:_ this(targets (~(put in targets) ship.effect))
:~ :* %pass /accusations %agent
[ship.effect %foes] %watch /enemies
==
==
::
%part
:_ this(targets (~(del in targets) ship.effect))
=/ leave
:* %pass /accusations %agent
[ship.effect %foes] %leave ~
==
?: =(public %.y)
[leave ~]
[leave [%give %kick ~[/enemies] `ship.effect] ~]
==
==
==
::
[%accusations ~]
?+ -.sign (on-agent:def wire sign)
%kick
:_ this
:~ :* %pass /accusations %agent
[src.bowl %foes] %watch /enemies
==
==
::
%fact
?> =(p.cage.sign %foes-update)
=/ upd !<(update q.cage.sign)
?+ -.upd (on-agent:def wire sign)
%accuse
:- :~ :* %give %fact ~[/suspects]
%foes-update !>([%suspected src.bowl ship.upd])
==
==
=- this(suspects (~(put by suspects) src.bowl -))
%. ship.upd
%~ put
in
(~(got by suspects) src.bowl)
::
%unaccuse
:- :~ :* %give %fact ~[/suspects]
%foes-update !>([%unsuspected src.bowl ship.upd])
==
==
=- this(suspects (~(put by suspects) src.bowl -))
%. ship.upd
%~ del
in
(~(got by suspects) src.bowl)
==
==
==
::
++ on-watch
|= =path
^- (quip card _this)
?+ path !!
[%enemies ~]
?> ?| =(public %.y)
(~(has in targets) src.bowl)
==
:_ this
=/ cards
%+ turn
%~ tap in
~(key by enemies)
|= =ship
^- card
[%give %fact ~[/enemies] %foes-update !>([%accuse ship])]
::
?: (~(has by wex.bowl) [/accusations src.bowl %foes])
cards
[[%pass /accusations %agent [src.bowl %foes] %watch /enemies] cards]
::
[%suspects ~]
?> =(our.bowl src.bowl)
:_ this
%- zing
^- (list (list card))
%+ turn
~(tap by suspects)
|= [accuser=ship accused=(set ship)]
^- (list card)
%+ turn
~(tap in accused)
|= =ship
^- card
[%give %fact ~[/suspects] %foes-update !>([%suspected accuser ship])]
==
::
++ on-peek
|= =path
^- (unit (unit cage))
?> =(src.bowl our.bowl)
?+ path !!
[%x %enemies ~]
``noun+!>(enemies)
::
[%x %enemies @ ~]
``noun+!>((~(get by enemies) (need (slaw %p i.t.t.path))))
::
[%x %suspects ~]
``noun+!>(suspects)
::
[%x %suspects @ ~]
``noun+!>((~(get by suspects) (need (slaw %p i.t.t.path))))
==
::
++ on-arvo on-arvo:def
++ on-fail on-fail:def
++ on-leave on-leave:def
--