urbit/j/6/ut_park.c

94 lines
2.3 KiB
C
Raw Normal View History

2013-09-29 00:21:18 +04:00
/* j/6/ut_park.c
**
** This file is in the public domain.
*/
#include "all.h"
2014-09-04 07:10:43 +04:00
2013-09-29 00:21:18 +04:00
/* logic
*/
2014-09-06 00:13:24 +04:00
u3_bean
2014-09-03 09:46:55 +04:00
_cqfu_park(
2014-09-06 00:13:24 +04:00
u3_noun van,
u3_noun sut,
u3_noun way,
u3_atom axe)
2013-09-29 00:21:18 +04:00
{
2014-09-06 00:13:24 +04:00
if ( u3_no == u3du(sut) || c3__core != u3h(sut) ) {
return u3_cm_bail(c3__fail);
2013-09-29 00:21:18 +04:00
}
2014-09-06 00:13:24 +04:00
// else if ( u3_no == u3_cj_hook(u3k(van), "vet") ) {
else if ( u3_no == u3_cr_at(u3_cqfu_van_vet, van) ) {
return u3_yes;
2013-09-29 00:21:18 +04:00
}
else {
2014-09-06 00:13:24 +04:00
u3_noun p_sut, q_sut, pq_sut;
2013-09-29 00:21:18 +04:00
2014-09-06 00:13:24 +04:00
u3_cx_cell(u3t(sut), &p_sut, &q_sut);
u3_cx_cell(q_sut, &pq_sut, 0);
2013-09-29 00:21:18 +04:00
2013-12-18 05:47:20 +04:00
if ( c3__both == way ) {
2013-12-27 00:58:55 +04:00
if ( c3__gold == pq_sut ) {
2014-09-06 00:13:24 +04:00
return u3_yes;
} else return u3_no;
2013-12-18 05:47:20 +04:00
}
2013-09-29 00:21:18 +04:00
if ( c3__read == way ) {
switch ( pq_sut ) {
2014-09-06 00:13:24 +04:00
default: return u3_cm_bail(c3__fail);
2013-09-29 00:21:18 +04:00
2014-09-06 00:13:24 +04:00
case c3__gold: return u3_yes;
case c3__lead: return u3_no;
case c3__iron: return u3_no;
case c3__zinc: return
2014-09-06 00:13:24 +04:00
u3_and(u3_not(u3_cr_sing(1, axe)),
u3_cr_sing(2, u3_cqc_cap(axe)));
2013-09-29 00:21:18 +04:00
}
}
else if ( c3__rite == way ) {
switch ( pq_sut ) {
2014-09-06 00:13:24 +04:00
default: return u3_cm_bail(c3__fail);
2013-09-29 00:21:18 +04:00
2014-09-06 00:13:24 +04:00
case c3__gold: return u3_yes;
case c3__lead: return u3_no;
case c3__iron: return
2014-09-06 00:13:24 +04:00
u3_and(u3_not(u3_cr_sing(1, axe)),
u3_cr_sing(2, u3_cqc_cap(axe)));
case c3__zinc: return u3_no;
2013-09-29 00:21:18 +04:00
}
}
2014-09-06 00:13:24 +04:00
else if ( c3__free == way ) { return u3_yes; }
else return u3_cm_bail(c3__fail);
2013-09-29 00:21:18 +04:00
}
}
/* boilerplate
*/
2014-09-06 00:13:24 +04:00
u3_noun
u3_cwfu_park(
u3_noun cor)
2013-09-29 00:21:18 +04:00
{
2014-09-06 00:13:24 +04:00
u3_noun sut, way, axe, van;
2013-09-29 00:21:18 +04:00
2014-09-06 00:13:24 +04:00
if ( (u3_no == u3_cr_mean(cor, u3_cv_sam_2, &way,
u3_cv_sam_3, &axe,
u3_cv_con, &van,
2013-09-29 00:21:18 +04:00
0)) ||
2014-09-06 00:13:24 +04:00
(u3_no == u3ud(axe)) ||
(u3_none == (sut = u3_cr_at(u3_cv_sam, van))) )
2013-09-29 00:21:18 +04:00
{
2014-09-06 00:13:24 +04:00
return u3_cm_bail(c3__fail);
2013-09-29 00:21:18 +04:00
} else {
2014-09-03 09:46:55 +04:00
return _cqfu_park(van, sut, way, axe);
2013-09-29 00:21:18 +04:00
}
}
2014-09-06 00:13:24 +04:00
u3_noun
u3_cqfu_park(u3_noun van,
u3_noun sut,
u3_noun way,
u3_noun axe)
2013-09-29 00:21:18 +04:00
{
2014-09-03 09:46:55 +04:00
return _cqfu_park(van, sut, way, axe);
2013-09-29 00:21:18 +04:00
}