shrub/pkg/arvo/app/aqua.hoon

863 lines
22 KiB
Plaintext
Raw Normal View History

2019-09-25 05:51:01 +03:00
:: An aquarium of virtual ships. Put in some fish and watch them!
::
:: usage:
:: |start %aqua
:: /- aquarium
:: :aqua &pill .^(pill:aquarium %cx %/urbit/pill)
:: OR
:: :aqua &pill +solid
::
:: XX: update these examples
2019-09-25 05:51:01 +03:00
:: Then try stuff:
:: :aqua [%init ~[~bud ~dev]]
:: :aqua [%dojo ~[~bud ~dev] "[our eny (add 3 5)]"]
:: :aqua [%dojo ~[~bud] "|hi ~dev"]
:: :aqua [%wish ~[~bud ~dev] '(add 2 3)']
:: :aqua [%peek ~[~bud] /cx/~bud/base/(scot %da now)/app/curl/hoon]
2019-09-25 05:51:01 +03:00
:: :aqua [%dojo ~[~bud ~dev] '|mount %']
:: :aqua [%file ~[~bud ~dev] %/sys/vane]
:: :aqua [%pause-events ~[~bud ~dev]]
::
:: We get ++unix-event and ++pill from /-aquarium
::
/- aquarium
/+ pill, azimuth, naive, default-agent, aqua-azimuth, dbug, verb
2019-09-25 05:51:01 +03:00
=, pill-lib=pill
=, aquarium
=> $~ |%
+$ versioned-state
$% state-0
==
+$ state-0
2019-09-25 05:51:01 +03:00
$: %0
2021-08-19 03:25:17 +03:00
pil=$>(%pill pill)
assembled=*
tym=@da
fresh-piers=(map [=ship fake=?] [=pier boths=(list unix-both)])
fleet-snaps=(map term fleet)
piers=fleet
==
2020-12-08 03:22:55 +03:00
:: XX temporarily shadowed, fix and remove
::
2021-07-26 08:26:49 +03:00
+$ pill pill:pill-lib
2019-09-25 05:51:01 +03:00
::
+$ fleet [ships=(map ship pier) azi=az-state]
2019-09-25 05:51:01 +03:00
+$ pier
$: snap=*
event-log=(list unix-timed-event)
next-events=(qeu unix-event)
processing-events=?
==
--
2019-09-25 06:21:41 +03:00
::
2020-12-08 03:22:55 +03:00
=| state-0
=* state -
2019-11-07 09:19:32 +03:00
=<
%- agent:dbug
%+ verb |
2019-11-19 07:36:21 +03:00
^- agent:gall
|_ =bowl:gall
2019-11-07 09:19:32 +03:00
+* this .
aqua-core +>
ac ~(. aqua-core bowl)
def ~(. (default-agent this %|) bowl)
2019-11-07 09:19:32 +03:00
++ on-init `this
++ on-save !>(state)
2019-11-07 09:19:32 +03:00
++ on-load
|= old-vase=vase
2019-11-19 07:36:21 +03:00
^- step:agent:gall
2019-09-25 05:51:01 +03:00
~& prep=%aqua
=+ !<(old=versioned-state old-vase)
=| cards=(list card:agent:gall)
|-
?- -.old
:: wipe fleets and piers rather than give them falsely nulled azimuth state
::
%0
[cards this(state old)]
==
2019-09-25 05:51:01 +03:00
::
2019-11-07 09:19:32 +03:00
++ on-poke
2019-09-25 05:51:01 +03:00
|= [=mark =vase]
2019-11-19 07:36:21 +03:00
^- step:agent:gall
=^ cards state
2019-09-25 05:51:01 +03:00
?+ mark ~|([%aqua-bad-mark mark] !!)
%aqua-events (poke-aqua-events:ac !<((list aqua-event) vase))
2021-07-26 08:26:49 +03:00
%pill (poke-pill:ac !<(pill vase))
%noun (poke-noun:ac !<(* vase))
%azimuth-action (poke-azimuth-action:ac !<(azimuth-action vase))
2019-09-25 05:51:01 +03:00
==
2019-11-07 09:19:32 +03:00
[cards this]
2019-09-25 05:51:01 +03:00
::
2019-11-07 09:19:32 +03:00
++ on-watch
2019-09-25 05:51:01 +03:00
|= =path
2019-11-19 07:36:21 +03:00
^- step:agent:gall
2019-09-29 07:44:31 +03:00
?: ?=([?(%effects %effect) ~] path)
2019-09-25 06:21:41 +03:00
`this
?: ?=([%effect @ ~] path)
`this
2019-09-29 07:44:31 +03:00
?. ?=([?(%effects %effect %evens %boths) @ ~] path)
2019-09-25 05:51:01 +03:00
~| [%aqua-bad-subscribe-path path]
!!
?~ (slaw %p i.t.path)
~| [%aqua-bad-subscribe-path-ship path]
!!
`this
::
2019-11-07 09:19:32 +03:00
++ on-leave on-leave:def
++ on-peek peek:ac
2019-09-25 05:51:01 +03:00
::
2019-11-07 09:19:32 +03:00
++ on-agent on-agent:def
::
++ on-arvo
|= [=wire sign=sign-arvo]
^- step:agent:gall
?+ wire (on-arvo:def wire sign)
[%wait @ ~]
?> ?=(%wake +<.sign)
=/ wen=@da (slav %da i.t.wire)
=^ cards state
(handle-wake:ac wen)
[cards this]
==
2019-11-07 09:19:32 +03:00
++ on-fail on-fail:def
2019-09-25 05:51:01 +03:00
--
::
:: unix-{effects,events,boths}: collect jar of effects and events to
:: brodcast all at once to avoid gall backpressure
:: moves: Hoist moves into state for cleaner state management
::
=| unix-effects=(jar ship unix-effect)
=| unix-events=(jar ship unix-timed-event)
=| unix-boths=(jar ship unix-both)
2019-11-19 07:36:21 +03:00
=| cards=(list card:agent:gall)
|_ hid=bowl:gall
2019-09-25 05:51:01 +03:00
::
:: Represents a single ship's state.
::
++ pe
::NOTE if we start needing the fake flag outside of +ahoy and +yaho,
:: probably add it as an argument here.
2019-09-25 05:51:01 +03:00
|= who=ship
=+ (~(gut by ships.piers) who *pier)
2019-09-25 05:51:01 +03:00
=* pier-data -
|%
::
:: Done; install data
::
++ abet-pe
^+ this
=. ships.piers (~(put by ships.piers) who pier-data)
2019-09-25 05:51:01 +03:00
this
::
:: Initialize new ship
::
++ apex
=. pier-data *pier
=. snap assembled
~& pill-size=(met 3 (jam snap))
..abet-pe
::
:: store post-pill ship for later re-use
::
++ ahoy
|= fake=?
=? fresh-piers !(~(has by fresh-piers) [who fake])
%+ ~(put by fresh-piers) [who fake]
[pier-data (~(get ja unix-boths) who)]
..ahoy
::
:: restore post-pill ship for re-use
::
++ yaho
|= fake=?
=/ fresh (~(got by fresh-piers) [who fake])
=. pier-data pier.fresh
=. boths.fresh (flop boths.fresh)
|-
?~ boths.fresh ..yaho
=. ..yaho
?- -.i.boths.fresh
%effect (publish-effect +.i.boths.fresh)
%event (publish-event +.i.boths.fresh)
==
$(boths.fresh t.boths.fresh)
::
2019-09-25 05:51:01 +03:00
:: Enqueue events to child arvo
::
++ push-events
|= ues=(list unix-event)
^+ ..abet-pe
=. next-events (~(gas to next-events) ues)
..abet-pe
::
:: Send cards to host arvo
::
++ emit-cards
2019-11-19 07:36:21 +03:00
|= ms=(list card:agent:gall)
2019-09-25 05:51:01 +03:00
=. this (^emit-cards ms)
..abet-pe
::
:: Process the events in our queue.
::
++ plow
|- ^+ ..abet-pe
?: =(~ next-events)
..abet-pe
?. processing-events
..abet-pe
=^ ue next-events ~(get to next-events)
2021-06-17 09:49:56 +03:00
=/ poke-arm (mox +23.snap)
2019-09-25 05:51:01 +03:00
?> ?=(%0 -.poke-arm)
=/ poke p.poke-arm
=. tym (max +(tym) now.hid)
=/ poke-result (mule |.((slum poke tym ue)))
?: ?=(%| -.poke-result)
%- (slog >%aqua-crash< >guest=who< p.poke-result)
$
=. snap +.p.poke-result
=. ..abet-pe (publish-event tym ue)
2020-05-06 19:33:42 +03:00
=. ..abet-pe
~| ova=-.p.poke-result
(handle-effects ;;((list ovum) -.p.poke-result))
2019-09-25 05:51:01 +03:00
$
::
:: Peek
::
++ peek
|= p=*
2021-06-17 09:49:56 +03:00
=/ res (mox +22.snap)
2019-09-25 05:51:01 +03:00
?> ?=(%0 -.res)
=/ peek p.res
=/ pax (path p)
?> ?=([@ @ @ @ *] pax)
=. i.t.t.t.pax (scot %da tym)
2021-06-18 08:53:07 +03:00
=/ pek (slum peek [[~ ~] & pax])
=+ ;;(res=(unit (cask)) pek)
(bind res tail)
::
2019-09-25 05:51:01 +03:00
:: Wish
::
++ wish
|= txt=@t
2021-06-17 09:49:56 +03:00
=/ res (mox +10.snap)
2019-09-25 05:51:01 +03:00
?> ?=(%0 -.res)
=/ wish p.res
~& [who=who %wished (slum wish txt)]
..abet-pe
::
++ mox |=(* (mock [snap +<] scry))
::
:: Start/stop processing events. When stopped, events are added to
:: our queue but not processed.
::
++ start-processing-events .(processing-events &)
++ stop-processing-events .(processing-events |)
::
:: Handle all the effects produced by a single event.
::
++ handle-effects
|= effects=(list ovum)
^+ ..abet-pe
?~ effects
..abet-pe
=. ..abet-pe
=/ sof ((soft unix-effect) i.effects)
?~ sof
~? aqua-debug=& [who=who %unknown-effect i.effects]
..abet-pe
(publish-effect u.sof)
$(effects t.effects)
::
:: Give effect to our subscribers
::
++ publish-effect
|= uf=unix-effect
^+ ..abet-pe
=. unix-effects (~(add ja unix-effects) who uf)
=. unix-boths (~(add ja unix-boths) who [%effect uf])
..abet-pe
::
:: Give event to our subscribers
::
++ publish-event
|= ute=unix-timed-event
^+ ..abet-pe
=. event-log [ute event-log]
=. unix-events (~(add ja unix-events) who ute)
=. unix-boths (~(add ja unix-boths) who [%event ute])
..abet-pe
--
::
++ this .
::
:: ++apex-aqua and ++abet-aqua must bookend calls from gall
::
++ apex-aqua
^+ this
=: cards ~
unix-effects ~
unix-events ~
unix-boths ~
==
this
::
++ abet-aqua
^- (quip card:agent:gall _state)
::
:: interecept %request effects to handle azimuth subscription
::
=. this
%- emit-cards
%- zing
%+ turn ~(tap by unix-effects)
|= [=ship ufs=(list unix-effect)]
%+ murn ufs
|= uf=unix-effect
(router:aqua-azimuth our.hid ship uf azi.piers)
::
2019-09-29 07:44:31 +03:00
=. this
=/ =path /effect
%- emit-cards
%- zing
%+ turn ~(tap by unix-effects)
|= [=ship ufs=(list unix-effect)]
%- zing
2019-09-29 07:44:31 +03:00
%+ turn ufs
|= uf=unix-effect
:~ [%give %fact ~[/effect] %aqua-effect !>(`aqua-effect`[ship uf])]
[%give %fact ~[/effect/[-.q.uf]] %aqua-effect !>(`aqua-effect`[ship uf])]
==
2019-09-29 07:44:31 +03:00
::
2019-09-25 05:51:01 +03:00
=. this
=/ =path /effects
%- emit-cards
%+ turn ~(tap by unix-effects)
|= [=ship ufs=(list unix-effect)]
[%give %fact ~[path] %aqua-effects !>(`aqua-effects`[ship (flop ufs)])]
2019-09-25 05:51:01 +03:00
::
2019-09-29 07:44:31 +03:00
=. this
%- emit-cards
%- zing
%+ turn ~(tap by unix-effects)
|= [=ship ufs=(list unix-effect)]
=/ =path /effect/(scot %p ship)
%+ turn ufs
|= uf=unix-effect
[%give %fact ~[path] %aqua-effect !>(`aqua-effect`[ship uf])]
2019-09-29 07:44:31 +03:00
::
2019-09-25 05:51:01 +03:00
=. this
%- emit-cards
%+ turn ~(tap by unix-effects)
|= [=ship ufs=(list unix-effect)]
=/ =path /effects/(scot %p ship)
[%give %fact ~[path] %aqua-effects !>(`aqua-effects`[ship (flop ufs)])]
2019-09-25 05:51:01 +03:00
::
=. this
%- emit-cards
%+ turn ~(tap by unix-events)
|= [=ship ve=(list unix-timed-event)]
=/ =path /events/(scot %p ship)
[%give %fact ~[path] %aqua-events !>(`aqua-events`[ship (flop ve)])]
2019-09-25 05:51:01 +03:00
::
=. this
%- emit-cards
%+ turn ~(tap by unix-boths)
|= [=ship bo=(list unix-both)]
=/ =path /boths/(scot %p ship)
[%give %fact ~[path] %aqua-boths !>(`aqua-boths`[ship (flop bo)])]
2019-09-25 05:51:01 +03:00
::
[(flop cards) state]
2019-09-25 05:51:01 +03:00
::
++ emit-cards
2019-11-19 07:36:21 +03:00
|= ms=(list card:agent:gall)
2019-09-25 05:51:01 +03:00
=. cards (weld ms cards)
this
::
:: Run all events on all ships until all queues are empty
::
++ plow-all
|- ^+ this
=/ who
=/ pers ~(tap by ships.piers)
2019-09-25 05:51:01 +03:00
|- ^- (unit ship)
?~ pers
~
?: &(?=(^ next-events.q.i.pers) processing-events.q.i.pers)
`p.i.pers
$(pers t.pers)
~? aqua-debug=| plowing=who
?~ who
this
=. this abet-pe:plow:(pe u.who)
$
::
:: Load a pill and assemble arvo. Doesn't send any of the initial
:: events.
::
++ poke-pill
|= p=pill
^- (quip card:agent:gall _state)
2021-07-26 08:26:49 +03:00
?< ?=(%ivory -.p)
=. userspace-ova.p
:: if there is an azimuth-snapshot in the pill, we stub it out,
:: since it would interfere with aqua's azimuth simulation.
::
^+ userspace-ova.p
%+ turn userspace-ova.p
|= e=unix-event:pill-lib
^+ e
?. ?=(%park -.q.e) e
?. ?=(%& -.yok.q.e) e
=- e(q.p.yok.q -)
^- (map path (each page lobe:clay))
%- ~(urn by q.p.yok.q.e)
|= [=path fil=(each page lobe:clay)]
^+ fil
?. =(/app/azimuth/version-0/azimuth-snapshot path) fil
?: ?=(%| -.fil) fil
&+azimuth-snapshot+[%0 [0x0 0] *^state:naive ~ ~]
2019-09-25 05:51:01 +03:00
=. this apex-aqua =< abet-aqua
=. pil p
~& lent=(met 3 (jam boot-ova.pil))
=/ res=toon :: (each * (list tank))
(mock [boot-ova.pil [2 [0 3] [0 2]]] scry)
=. fleet-snaps ~
?- -.res
%0
~& %suc
=. assembled +7.p.res
=. fresh-piers ~
2019-09-25 05:51:01 +03:00
this
::
%1
~& [%vere-blocked p.res]
this
::
%2
~& %vere-fail
%- (slog p.res)
this
==
::
:: Handle commands from CLI
::
:: Should put some thought into arg structure, maybe make a mark.
::
:: Should convert some of these to just rewrite into ++poke-events.
::
++ poke-noun
|= val=*
^- (quip card:agent:gall _state)
2019-09-25 05:51:01 +03:00
=. this apex-aqua =< abet-aqua
^+ this
:: Could potentially factor out the three lines of turn-ships
:: boilerplate
::
?+ val ~|(%bad-noun-arg !!)
[%swap-vanes vs=*]
?> ?=(^ boot-ova.pil)
?> ?=([%7 * %1 installed=*] i.boot-ova.pil)
=. installed.i.boot-ova.pil
2019-09-25 05:51:01 +03:00
%+ roll (,(list term) vs.val)
|= [v=term =_installed.i.boot-ova.pil]
2019-11-15 23:46:11 +03:00
%^ slum installed now.hid
2019-09-25 05:51:01 +03:00
=/ vane
?+ v ~|([%unknown-vane v] !!)
2019-11-27 11:25:56 +03:00
%a %ames
2019-09-25 05:51:01 +03:00
%b %behn
%c %clay
%d %dill
%e %eyre
%g %gall
%j %jael
2019-11-19 07:36:21 +03:00
%g %gall
2019-09-25 05:51:01 +03:00
==
=/ pax
/(scot %p our.hid)/work/(scot %da now.hid)/sys/vane/[vane]
2019-09-25 05:51:01 +03:00
=/ txt .^(@ %cx (weld pax /hoon))
[/vane/[vane] [%veer v pax txt]]
=> .(this ^+(this this))
=^ ms state (poke-pill pil)
2019-09-25 05:51:01 +03:00
(emit-cards ms)
::
[%swap-files @tas]
=/ =desk +.val
2019-09-25 05:51:01 +03:00
=. userspace-ova.pil
2022-09-29 23:43:31 +03:00
:: take all files from a userspace desk
2019-09-25 05:51:01 +03:00
:_ ~
%- unix-event:pill-lib
%- file-ovum:pill-lib
2023-03-17 21:00:13 +03:00
[desk /(scot %p our.hid)/[desk]/(scot %da now.hid) ~]
=^ ms state (poke-pill pil)
2019-09-25 05:51:01 +03:00
(emit-cards ms)
::
[%wish hers=* p=@t]
%+ turn-ships ((list ship) hers.val)
|= [who=ship thus=_this]
=. this thus
(wish:(pe who) p.val)
::
[%unpause-events hers=*]
=. this start-azimuth-timer
2019-09-25 05:51:01 +03:00
%+ turn-ships ((list ship) hers.val)
|= [who=ship thus=_this]
=. this thus
start-processing-events:(pe who)
::
[%pause-events hers=*]
=. this stop-azimuth-timer
2019-09-25 05:51:01 +03:00
%+ turn-ships ((list ship) hers.val)
|= [who=ship thus=_this]
=. this thus
stop-processing-events:(pe who)
::
[%clear-snap lab=@tas]
=. fleet-snaps ~ :: (~(del by fleet-snaps) lab.val)
this
==
::
:: Make changes to azimuth state for the current fleet
::
++ poke-azimuth-action
|= act=azimuth-action
^- (quip card:agent:gall _state)
=. this apex-aqua =< abet-aqua
^+ this
?- -.act
::
%init-azimuth
=. azi.piers *az-state
start-azimuth-timer
::
%spawn
=. state (spawn who.act)
this
::
%breach
:: should we remove the pier from state here?
=. state (breach who.act)
this
::
==
::
2019-09-25 05:51:01 +03:00
:: Apply a list of events tagged by ship
::
++ poke-aqua-events
|= events=(list aqua-event)
^- (quip card:agent:gall _state)
2019-09-25 05:51:01 +03:00
=. this apex-aqua =< abet-aqua
%+ turn-events events
|= [ae=aqua-event thus=_this]
=. this thus
?- -.ae
::
2019-09-25 05:51:01 +03:00
%init-ship
?: &(fake.ae (~(has by fresh-piers) [who fake]:ae))
~& [%aqua %cached-init +.ae]
=. this abet-pe:(yaho fake):[ae (pe who.ae)]
?: fake.ae (pe who.ae)
:: for real ships, make sure they have their latest keys
::
%. who.ae
=< pe:abet-pe:plow
%- push-events:(pe who.ae)
=/ =life lyfe:(~(got by lives.azi.piers) who.ae)
=/ =ring sec:ex:(get-keys:aqua-azimuth who.ae life)
[/j/aqua/rekey %rekey life ring]~
2019-09-25 05:51:01 +03:00
=. this abet-pe:(publish-effect:(pe who.ae) [/ %sleep ~])
=/ initted
=< plow
%- push-events:apex:(pe who.ae)
^- (list unix-event)
2021-06-18 03:27:17 +03:00
%- zing
:~
:~ [/ %wack 0] :: eny
2021-06-18 08:53:07 +03:00
:: [/ %verb `|] :: possible verb
2021-07-26 08:26:49 +03:00
:^ / %wyrd [~.nonce /aqua] :: dummy runtime version + nonce
2021-06-18 03:27:17 +03:00
^- (list (pair term @))
:~ zuse+zuse
lull+lull
arvo+arvo
hoon+hoon-version
nock+4
==
[/ %whom who.ae] :: who
==
::
kernel-ova.pil :: load compiler
::
:_ ~
:^ /d/term/1 %boot &
2021-06-18 08:53:07 +03:00
?: fake.ae
2021-06-18 03:27:17 +03:00
[%fake who.ae]
2021-06-18 08:53:07 +03:00
[%dawn (dawn who.ae)]
2021-06-18 03:27:17 +03:00
::
userspace-ova.pil :: load os
::
:* [/b/behn/0v1n.2m9vh %born ~]
2021-06-18 03:27:17 +03:00
[/i/http-client/0v1n.2m9vh %born ~]
[/e/http-server/0v1n.2m9vh %born ~]
[/e/http-server/0v1n.2m9vh %live 8.080 `8.445]
[/a/newt/0v1n.2m9vh %born ~]
[/d/term/1 %hail ~]
::
?: fake.ae ~
=+ [%raw-poke %noun %refresh-rate ~s30]
[/g/aqua/reduce-refresh-rate %deal [. .]:who.ae %azimuth -]~
2021-06-18 03:27:17 +03:00
==
2019-09-25 05:51:01 +03:00
==
=. this
abet-pe:(ahoy fake):[ae initted]
2019-09-25 05:51:01 +03:00
(pe who.ae)
::
%pause-events
stop-processing-events:(pe who.ae)
::
%snap-ships
=. this
%+ turn-ships (turn ~(tap by ships.piers) head)
|= [who=ship thus=_this]
=. this thus
(publish-effect:(pe who) [/ %kill ~])
2019-09-25 05:51:01 +03:00
=. fleet-snaps
%+ ~(put by fleet-snaps) lab.ae
:_ azi.piers
2019-09-25 05:51:01 +03:00
%- malt
%+ murn hers.ae
|= her=ship
^- (unit (pair ship pier))
=+ per=(~(get by ships.piers) her)
2019-09-25 05:51:01 +03:00
?~ per
~
`[her u.per]
=. this stop-azimuth-timer
=. piers *fleet
2019-09-25 05:51:01 +03:00
(pe -.hers.ae)
::
%restore-snap
=. this
%+ turn-ships (turn ~(tap by ships.piers) head)
2019-09-25 05:51:01 +03:00
|= [who=ship thus=_this]
=. this thus
(publish-effect:(pe who) [/ %kill ~])
=. piers (~(got by fleet-snaps) lab.ae)
=. this start-azimuth-timer
2019-09-25 05:51:01 +03:00
=. this
%+ turn-ships (turn ~(tap by ships.piers) head)
2019-09-25 05:51:01 +03:00
|= [who=ship thus=_this]
=. this thus
(publish-effect:(pe who) [/ %restore ~])
(pe ~bud) :: XX why ~bud? need an example
::
%event
~? &(aqua-debug=| !?=(?(%belt %hear) -.q.ue.ae))
raw-event=[who.ae -.q.ue.ae]
~? &(debug=| ?=(%receive -.q.ue.ae))
raw-event=[who.ae ue.ae]
(push-events:(pe who.ae) [ue.ae]~)
==
::
:: Run a callback function against a list of ships, aggregating state
:: and plowing all ships at the end.
::
:: I think we should use patterns like this more often. Because we
:: don't, here's some points to be aware.
::
:: `fun` must take `this` as a parameter, since it needs to be
:: downstream of previous state changes. You could use `state` as
:: the state variable, but it muddles the code and it's not clear
:: whether it's better. You could use the `_(pe)` core if you're
:: sure you'll never need to refer to anything outside of your pier,
:: but I don't think we can guarantee that.
::
:: The callback function must start with `=. this thus`, or else
:: you don't get the new state. Would be great if you could hot-swap
:: that context in here, but we don't know where to put it unless we
:: restrict the callbacks to always have `this` at a particular axis,
:: and that doesn't feel right
::
++ turn-plow
|* arg=mold
|= [hers=(list arg) fun=$-([arg _this] _(pe))]
|- ^+ this
?~ hers
plow-all
=. this
abet-pe:plow:(fun i.hers this)
$(hers t.hers, this this)
::
++ turn-ships (turn-plow ship)
++ turn-events (turn-plow aqua-event)
::
:: Check whether we have a snapshot
::
++ peek
|= =path
^- (unit (unit cage))
?+ path ~
[%x %fleet-snap @ ~] ``noun+!>((~(has by fleet-snaps) i.t.t.path))
[%x %fleets ~] ``noun+!>((turn ~(tap by fleet-snaps) head))
[%x %ships ~] ``noun+!>((turn ~(tap by ships.piers) head))
2019-09-25 05:51:01 +03:00
[%x %pill ~] ``pill+!>(pil)
[%x %i @ @ @ @ @ *]
=/ who (slav %p i.t.t.path)
=/ pier (~(get by ships.piers) who)
2019-09-25 05:51:01 +03:00
?~ pier
~
:^ ~ ~ %noun !>
(peek:(pe who) t.t.t.path)
[%x %log-info ~]
``noun+!>([lives.azi.piers (lent logs.azi.piers) tym.azi.piers])
2019-09-25 05:51:01 +03:00
==
::
:: Trivial scry for mock
::
++ scry |=([* *] ~)
::
++ handle-wake
|= wen=@da
^- (quip card:agent:gall _state)
=. this apex-aqua =< abet-aqua
?. =(wen tym.azi.piers)
this
=. state (spam-logs 10)
start-azimuth-timer
::
++ start-azimuth-timer
^+ this
=? this !=(tym.azi.piers *@da)
stop-azimuth-timer
=/ until=@da (add now.hid ~s40)
=. tym.azi.piers until
%- emit-cards
[%pass /wait/(scot %da until) %arvo %b %wait until]~
::
++ stop-azimuth-timer
^+ this
=* tym tym.azi.piers
?: =(tym *@da)
this
%- emit-cards
[%pass /wait/(scot %da tym) %arvo %b %rest tym]~
::
++ spam-logs
|= n=@
^- _state
=* loop $
?: =(n 0)
state
=/ new-state=_state
?. (~(has by lives.azi.piers) ~fes)
(spawn ~fes)
(cycle-keys ~fes)
=. state new-state
loop(n (dec n))
::
++ spawn
|= who=@p
^- _state
?< (~(has by lives.azi.piers) who)
=. lives.azi.piers (~(put by lives.azi.piers) who [1 0])
=. logs.azi.piers
%+ weld logs.azi.piers
:_ ~
%- changed-keys:lo:aqua-azimuth
:* who
(get-public:aqua-azimuth who 1 %crypt)
(get-public:aqua-azimuth who 1 %auth)
1
1
==
(spam-logs 10)
::
++ cycle-keys
|= who=@p
^- _state
=/ prev
~| no-such-ship+who
(~(got by lives.azi.piers) who)
=/ lyfe +(lyfe.prev)
=. lives.azi.piers (~(put by lives.azi.piers) who [lyfe rut.prev])
=. logs.azi.piers
%+ weld logs.azi.piers
:_ ~
%- changed-keys:lo:aqua-azimuth
:* who
(get-public:aqua-azimuth who lyfe %crypt)
(get-public:aqua-azimuth who lyfe %auth)
1
lyfe
==
state
::
++ breach
|= who=@p
^- _state
=. state (cycle-keys who)
=/ prev (~(got by lives.azi.piers) who)
=/ rut +(rut.prev)
=. lives.azi.piers (~(put by lives.azi.piers) who [lyfe.prev rut])
=. logs.azi.piers
%+ weld logs.azi.piers
[(broke-continuity:lo:aqua-azimuth who rut) ~]
(spam-logs 10)
::
++ dawn
|= who=ship
2020-12-08 03:47:06 +03:00
^- dawn-event:jael
=/ clan (clan:title who)
?> ?=(?(%czar %king %duke %earl) clan)
=/ spon=(list [ship point:azimuth])
%- flop
|- ^- (list [ship point:azimuth])
=/ =ship (^sein:title who)
=/ a-point=[^ship point:azimuth]
=/ spon-spon [& (^sein:title ship)]
=/ life-rift ~|([ship lives.azi.piers] (~(got by lives.azi.piers) ship))
=/ =life lyfe.life-rift
=/ =rift rut.life-rift
=/ =pass
%^ pass-from-eth:azimuth
(as-octs:mimes:html (get-public:aqua-azimuth ship life %crypt))
(as-octs:mimes:html (get-public:aqua-azimuth ship life %auth))
1
:^ ship
*[address address address address]:azimuth
`[life=life pass rift spon-spon ~]
~
?: ?=(%czar (clan:title ship))
[a-point]~
[a-point $(who ship)]
2020-12-08 03:47:06 +03:00
=/ =seed:jael
=/ life-rift=[lyfe=life rut=rift]
?: =(%earl clan) [1 0]
(~(got by lives.azi.piers) who)
=/ =life lyfe.life-rift
[who life sec:ex:(get-keys:aqua-azimuth who life) ~]
:* seed
spon
get-czars
~[~['arvo' 'netw' 'ork']]
0
`(need (de-purl:html 'http://fake.aqua.domain/'))
==
::
:: Should only do galaxies
::
++ get-czars
^- (map ship [rift life pass])
%- malt
%+ murn
~(tap by lives.azi.piers)
|= [who=ship lyfe=life rut=rift]
?. =(%czar (clan:title who))
~
%- some
:^ who rut lyfe
%^ pass-from-eth:azimuth
(as-octs:mimes:html (get-public:aqua-azimuth who lyfe %crypt))
(as-octs:mimes:html (get-public:aqua-azimuth who lyfe %auth))
1
2019-09-25 05:51:01 +03:00
--