urbit/pkg/garden/app/treaty.hoon

338 lines
8.9 KiB
Plaintext
Raw Normal View History

2021-08-23 04:48:30 +03:00
/- docket, *treaty
/+ default-agent, agentio, verb, dbug
|%
2021-09-29 15:51:00 +03:00
++ default-ally ~dister-dozzod-dozzod
2021-09-21 07:52:54 +03:00
::
2021-08-23 04:48:30 +03:00
+$ card card:agent:gall
+$ state-0
$: treaties=(map [=ship =desk] treaty)
sovereign=(map desk treaty)
entente=alliance
=allies:ally
direct=(set [=ship =desk])
2021-08-23 04:48:30 +03:00
==
--
^- agent:gall
2021-09-29 07:48:27 +03:00
%+ verb |
2021-08-23 04:48:30 +03:00
%- agent:dbug
=| state-0
=* state -
=<
|_ =bowl:gall
+* this .
def ~(. (default-agent this %|) bowl)
io ~(. agentio bowl)
pass pass:io
cc ~(. +> bowl)
2021-10-06 20:15:17 +03:00
++ on-init
2021-09-21 07:52:54 +03:00
?: =(our.bowl default-ally) `this
(on-poke %ally-update-0 !>([%add default-ally]))
2021-08-23 04:48:30 +03:00
++ on-save !>(state)
++ on-load
|= =vase
=+ !<(old=state-0 vase)
`this(state old)
::
++ on-poke
|= [=mark =vase]
^- (quip card _this)
?> (team:title [our src]:bowl)
2021-10-06 20:15:17 +03:00
|^
2021-08-23 04:48:30 +03:00
?+ mark (on-poke:def mark vase)
2021-08-27 05:24:59 +03:00
%ally-update-0 (ally-update !<(update:ally vase))
2021-10-06 20:15:17 +03:00
%alliance-update-0 (alliance-update !<(update:alliance vase))
2021-08-23 04:48:30 +03:00
::
2021-10-06 20:15:17 +03:00
%noun
2021-08-23 04:48:30 +03:00
=+ ;;([%add =desk] q.vase)
=/ =docket:docket ~(get-docket so:cc desk)
=/ =treaty (treaty-from-docket:cc desk docket)
2021-10-06 20:15:17 +03:00
=. sovereign (~(put by sovereign) desk treaty)
2021-08-23 04:48:30 +03:00
`this
==
::
2021-08-27 05:24:59 +03:00
++ ally-update
|= =update:ally
2021-08-23 04:48:30 +03:00
^- (quip card _this)
2021-08-27 05:24:59 +03:00
=- [[(ally-update:ca:cc update) -.-] +.-]
?< ?=(?(%ini %new) -.update)
=* ship ship.update
2021-08-23 06:32:22 +03:00
?< =(ship our.bowl)
2021-08-27 05:24:59 +03:00
=* al ~(. al:cc ship.update)
?- -.update
%add [~[watch:al] this(allies (~(put by allies) ship *alliance))]
%del [~[leave:al] this(allies (~(del by allies) ship))]
2021-08-23 04:48:30 +03:00
==
::
2021-08-27 05:24:59 +03:00
++ alliance-update
|= =update:alliance
2021-08-23 04:48:30 +03:00
^- (quip card _this)
2021-08-27 05:24:59 +03:00
=- [[(alliance-update:ca:cc update) -.-] +.-]
?+ -.update !!
2021-08-23 06:32:22 +03:00
::
2021-10-06 20:15:17 +03:00
%add
2021-08-27 05:24:59 +03:00
=, update
2021-08-23 06:32:22 +03:00
=. entente (~(put in entente) [ship desk])
?. =(our.bowl ship) `this
2021-08-23 07:10:22 +03:00
=* so ~(. so:cc desk)
=/ =docket:docket get-docket:so
2021-08-23 06:32:22 +03:00
=/ =treaty (treaty-from-docket:cc desk docket)
=. sovereign (~(put by sovereign) desk treaty)
2021-08-23 07:10:22 +03:00
:_ this
2021-10-04 09:01:12 +03:00
[publish warp give]:so
2021-08-23 06:32:22 +03:00
::
%del
2021-08-27 05:24:59 +03:00
=, update
2021-08-23 06:32:22 +03:00
=. entente (~(del in entente) [ship desk])
2021-08-27 05:24:59 +03:00
?. =(our.bowl ship) `this
=. sovereign (~(del by sovereign) desk)
:_(this ~(kick so:cc desk)^~)
2021-08-23 06:32:22 +03:00
==
2021-08-23 04:48:30 +03:00
--
::
++ on-watch
|= =path
^- (quip card _this)
?+ path (on-watch:def path)
2021-10-06 20:15:17 +03:00
:: syncing
[%treaty @ @ ~]
2021-08-23 04:48:30 +03:00
=/ =ship (slav %p i.t.path)
=* desk i.t.t.path
?: =(our.bowl ship)
2021-09-28 03:19:43 +03:00
:_(this (fact-init:io (treaty:cg:cc (~(got by sovereign) desk)))^~)
?^ treat=(~(get by treaties) [ship desk])
:_ this
2021-09-28 03:19:43 +03:00
(fact-init:io (treaty:cg:cc u.treat))^~
?> =(our.bowl src.bowl)
=. direct (~(put in direct) [ship desk])
:_(this (drop ~(safe-watch tr:cc [ship desk])))
2021-10-04 09:01:12 +03:00
::
[%treaties ~]
`this
2021-08-23 04:48:30 +03:00
::
[%alliance ~]
:_ this
(fact-init:io (alliance-update:cg:cc %ini entente))^~
:: local
::
[%allies ~]
:_ this
(fact-init:io (ally-update:cg:cc %ini allies))^~
==
::
::
++ on-peek
|= =path
^- (unit (unit cage))
?+ path (on-peek:def path)
2021-09-21 07:52:54 +03:00
[%x %alliance ~] ``(alliance-update:cg:ca %ini entente)
[%x %default-ally ~] ``ship+!>(default-ally)
[%x %allies ~] ``(ally-update:cg:ca %ini allies)
2021-08-23 04:48:30 +03:00
::
[%x %treaties @ ~]
=/ =ship (slav %p i.t.t.path)
2021-08-27 05:24:59 +03:00
=/ alliance (~(get ju allies) ship)
=/ allied
2021-08-23 04:48:30 +03:00
%- ~(gas by *(map [^ship desk] treaty))
2021-08-27 05:24:59 +03:00
%+ skim ~(tap by treaties)
|= [ref=[^ship desk] =treaty]
(~(has in alliance) ref)
2021-09-28 03:19:43 +03:00
``(treaty-update:cg:ca:cc %ini allied)
2021-08-23 04:48:30 +03:00
::
[%x %treaty @ @ ~]
=/ =ship (slav %p i.t.t.path)
=* desk i.t.t.t.path
2021-09-28 03:19:43 +03:00
``(treaty:cg:cc (~(got by treaties) [ship desk]))
2021-08-23 04:48:30 +03:00
==
::
2021-10-06 20:15:17 +03:00
++ on-agent
2021-08-23 04:48:30 +03:00
|= [=wire =sign:agent:gall]
^- (quip card _this)
=* ship src.bowl
2021-10-06 20:15:17 +03:00
|^
2021-08-23 04:48:30 +03:00
?+ wire (on-agent:def wire sign)
[%ally @ ~] ?>(=(src.bowl (slav %p i.t.wire)) take-ally)
::
2021-10-06 20:15:17 +03:00
[%treaty @ @ ~]
2021-08-23 04:48:30 +03:00
=* desk i.t.t.wire
?> =(ship (slav %p i.t.wire))
(take-treaty desk)
==
::
++ take-ally
?+ -.sign (on-agent:def wire sign)
::
%kick
?. (~(has by allies) ship) `this
:_(this ~[~(watch al:cc ship)])
::
%watch-ack
?~ p.sign (on-agent:def wire sign)
=. allies (~(del by allies) ship)
%- (slog leaf+"Broke alliance with {<ship>}" u.p.sign)
`this
::
%fact
?. =(%alliance-update-0 p.cage.sign) `this
=+ !<(=update:alliance q.cage.sign)
2021-10-06 20:15:17 +03:00
=^ cards allies
?- -.update
2021-08-23 04:48:30 +03:00
::
%ini
:_ (~(put by allies) src.bowl init.update)
%+ murn ~(tap in init.update)
|= [s=^ship =desk]
2021-08-27 10:13:01 +03:00
~(safe-watch tr:cc s desk)
2021-08-23 04:48:30 +03:00
::
2021-10-06 20:15:17 +03:00
%add
2021-08-23 04:48:30 +03:00
:_ (~(put ju allies) src.bowl [ship desk]:update)
(drop ~(safe-watch tr:cc [ship desk]:update))
%del
:_ (~(del ju allies) src.bowl [ship desk]:update)
~[~(leave tr:cc [ship desk]:update)]
==
:_ this
:_ cards
(fact:io (ally-update:cg:cc %new ship (~(get ju allies) src.bowl)) /allies ~)
==
::
++ take-treaty
|= =desk
2021-10-04 09:01:12 +03:00
=* tr ~(. tr:cc ship desk)
2021-08-23 04:48:30 +03:00
?+ -.sign (on-agent:def wire sign)
2021-09-29 17:26:56 +03:00
::
:: rewatch only if we aren't source
:: this would cause a potential kick-rewatch loop otherwise
2021-09-29 06:27:00 +03:00
::
2021-10-06 20:15:17 +03:00
%kick
2021-09-29 06:27:00 +03:00
:_ this
2021-10-04 09:01:12 +03:00
?: =(our.bowl ship) ~
~[watch:tr]
2021-08-23 04:48:30 +03:00
::
%watch-ack
?~ p.sign `this
=: treaties (~(del by treaties) ship desk)
direct (~(del in direct) ship desk)
==
2021-08-23 04:48:30 +03:00
%- (slog leaf+"Withdrew from treaty {<ship>}/{<desk>}" u.p.sign)
2021-10-04 09:01:12 +03:00
[gone:tr this]
2021-08-23 04:48:30 +03:00
::
%fact
?. =(%treaty-0 p.cage.sign) `this
2021-08-23 04:48:30 +03:00
=+ !<(=treaty q.cage.sign)
?> =([ship desk] [ship desk]:treaty)
=. treaties (~(put by treaties) [ship desk]:treaty treaty)
2021-10-04 09:01:12 +03:00
[give:tr this]
2021-08-23 04:48:30 +03:00
==
--
::
++ on-arvo
|= [=wire sign=sign-arvo]
|^
?+ wire (on-arvo:def wire sign)
[%init ~] !! :: setup sponsor ally
::
[%sovereign @ ~]
=* desk i.t.wire
(take-sovereign desk)
==
::
++ take-sovereign
|= =desk
=/ so ~(. so:cc desk)
?> ?=([?(%clay %behn) %writ *] sign)
?. (~(has by sovereign) desk) `this
=* riot p.sign
?~ riot :: docket file is gone
=. sovereign (~(del by sovereign) desk)
[~[kick:so] this]
=* cage r.u.riot
2021-09-28 22:22:06 +03:00
?. =(%docket-0 p.cage) `this
2021-08-23 04:48:30 +03:00
=+ !<(=docket:docket q.cage)
=/ =treaty (treaty-from-docket:cc desk docket)
=. sovereign (~(put by sovereign) desk treaty)
2021-08-24 06:53:01 +03:00
=* so ~(. so:cc desk)
2021-10-04 09:01:12 +03:00
:_(this [warp give]:so)
2021-08-23 04:48:30 +03:00
--
::
++ on-fail on-fail:def
++ on-leave on-leave:def
--
|_ =bowl:gall
++ io ~(. agentio bowl)
++ pass pass:io
::
++ treaty-from-docket
|= [=desk =docket:docket]
=+ .^(=cass:clay %cw (scry:io desk /desk/docket))
=+ .^(hash=@uv %cz (scry:io desk ~))
[our.bowl desk da+da.cass hash docket]
:: +al: Side effects for allies
++ al
|_ =ship
++ pass ~(. ^pass /ally/(scot %p ship))
2021-10-06 20:15:17 +03:00
++ watch (watch:pass [ship dap.bowl] /alliance)
2021-08-23 04:48:30 +03:00
++ leave (leave:pass ship dap.bowl)
--
:: +cg: Cage construction
++ cg
|%
++ ally-update |=(=update:ally ally-update-0+!>(update))
++ alliance-update |=(=update:alliance alliance-update-0+!>(update))
++ treaty |=(t=^treaty treaty-0+!>(t))
2021-08-23 04:48:30 +03:00
++ treaty-update |=(u=update:^treaty treaty-update-0+!>(u))
--
:: +ca: Card construction
++ ca
|%
++ watch-docket (~(watch-our pass /docket) %docket /dockets)
++ ally-update |=(=update:ally (fact:io (ally-update:cg update) /allies ~))
2021-10-06 20:15:17 +03:00
++ alliance-update
2021-08-23 04:48:30 +03:00
|=(=update:alliance (fact:io (alliance-update:cg update) /alliance ~))
--
:: +tr: engine for treaties
++ tr
|_ [=ship =desk]
++ pass ~(. ^pass path)
++ path /treaty/(scot %p ship)/[desk]
++ dock [ship dap.bowl]
++ watch (watch:pass dock path)
++ watching (~(has by wex.bowl) [path dock])
2021-09-29 17:26:56 +03:00
++ safe-watch `(unit card)`?:(|(watching =(our.bowl ship)) ~ `watch)
2021-08-23 04:48:30 +03:00
++ leave (leave:pass dock)
2021-10-06 20:15:17 +03:00
++ gone
2021-10-04 09:01:12 +03:00
^- (list card)
:~ (fact:io (treaty-update:cg %del ship desk) /treaties ~)
(kick-only:io our.bowl path ~)
==
2021-10-06 20:15:17 +03:00
++ give
2021-10-04 09:01:12 +03:00
^- (list card)
2021-08-23 04:48:30 +03:00
=/ t=treaty (~(got by treaties) ship desk)
2021-10-04 09:01:12 +03:00
:~ (fact:io (treaty-update:cg %add t) /treaties ~)
(fact:io (treaty:cg t) path ~)
==
2021-08-23 04:48:30 +03:00
--
:: +so: engine for sovereign treaties
++ so
|_ =desk
2021-08-24 06:53:01 +03:00
++ wire /sovereign/[desk]
++ pass ~(. ^pass wire)
++ path /treaty/(scot %p our.bowl)/[desk]
2021-09-28 03:19:43 +03:00
++ get-docket .^(docket:docket %cx (scry:io desk /desk/docket-0))
2021-08-23 04:48:30 +03:00
++ warp
2021-09-28 03:19:43 +03:00
(warp-our:pass desk `[%next %x da+now.bowl /desk/docket-0])
2021-08-23 04:48:30 +03:00
++ kick
(kick:io path ~)
++ give
2021-10-04 09:01:12 +03:00
^- (list card)
2021-08-23 04:48:30 +03:00
=/ t=treaty (~(got by sovereign) desk)
2021-10-04 09:01:12 +03:00
:~ (fact:io (treaty-update:cg %add t) /treaties ~)
(fact:io (treaty:cg t) path ~)
==
2021-08-23 07:10:22 +03:00
++ publish
(poke-our:pass %hood kiln-permission+!>([desk / &]))
2021-08-23 04:48:30 +03:00
--
--