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-11-05 04:18:47 +03:00
if ( c3n == u3du(sut) || c3__core != u3h(sut) ) {
2014-11-06 03:20:01 +03:00
return u3m_bail(c3__fail);
2013-09-29 00:21:18 +04:00
}
2014-11-06 03:20:01 +03:00
// else if ( c3n == u3j_hook(u3k(van), "vet") ) {
else if ( c3n == u3r_at(u3_cqfu_van_vet, van) ) {
2014-11-05 04:18:47 +03:00
return c3y;
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-11-06 03:20:01 +03:00
u3x_cell(u3t(sut), &p_sut, &q_sut);
u3x_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-11-05 04:18:47 +03:00
return c3y;
} else return c3n;
2013-12-18 05:47:20 +04:00
}
2013-09-29 00:21:18 +04:00
if ( c3__read == way ) {
switch ( pq_sut ) {
2014-11-06 03:20:01 +03:00
default: return u3m_bail(c3__fail);
2013-09-29 00:21:18 +04:00
2014-11-05 04:18:47 +03:00
case c3__gold: return c3y;
case c3__lead: return c3n;
case c3__iron: return c3n;
case c3__zinc: return
2014-11-06 03:20:01 +03:00
c3a(!(u3r_sing(1, axe)),
u3r_sing(2, u3_cqc_cap(axe)));
2013-09-29 00:21:18 +04:00
}
}
else if ( c3__rite == way ) {
switch ( pq_sut ) {
2014-11-06 03:20:01 +03:00
default: return u3m_bail(c3__fail);
2013-09-29 00:21:18 +04:00
2014-11-05 04:18:47 +03:00
case c3__gold: return c3y;
case c3__lead: return c3n;
case c3__iron: return
2014-11-06 03:20:01 +03:00
c3a(!(u3r_sing(1, axe)),
u3r_sing(2, u3_cqc_cap(axe)));
2014-11-05 04:18:47 +03:00
case c3__zinc: return c3n;
2013-09-29 00:21:18 +04:00
}
}
2014-11-05 04:18:47 +03:00
else if ( c3__free == way ) { return c3y; }
2014-11-06 03:20:01 +03:00
else return u3m_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-11-06 03:20:01 +03:00
if ( (c3n == u3r_mean(cor, u3v_sam_2, &way,
u3v_sam_3, &axe,
u3v_con, &van,
2013-09-29 00:21:18 +04:00
0)) ||
2014-11-05 04:18:47 +03:00
(c3n == u3ud(axe)) ||
2014-11-06 03:20:01 +03:00
(u3_none == (sut = u3r_at(u3v_sam, van))) )
2013-09-29 00:21:18 +04:00
{
2014-11-06 03:20:01 +03:00
return u3m_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
}