2013-09-29 00:21:18 +04:00
|
|
|
/* j/6/fire.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
|
|
|
static u3_bean
|
|
|
|
_fire_mull(u3_noun van,
|
|
|
|
u3_noun sut,
|
|
|
|
u3_noun dox,
|
|
|
|
u3_noun gen)
|
2013-09-29 00:21:18 +04:00
|
|
|
{
|
2014-09-06 00:13:24 +04:00
|
|
|
u3_noun rib = u3_cr_at(u3_cqfu_van_rib, van);
|
|
|
|
u3_noun key = u3nt(u3k(sut),
|
|
|
|
u3k(dox),
|
|
|
|
u3k(gen));
|
|
|
|
u3_bean ret;
|
|
|
|
|
|
|
|
if ( u3_yes == u3_cqdi_has(rib, key) ) {
|
|
|
|
ret = u3_yes;
|
2013-09-29 00:21:18 +04:00
|
|
|
}
|
|
|
|
else {
|
2014-09-06 00:13:24 +04:00
|
|
|
u3_noun rob = u3_cqdi_put(rib, key);
|
|
|
|
u3_noun von = u3_ci_molt(u3k(van),
|
|
|
|
u3_cqfu_van_rib, u3k(rob),
|
2013-09-29 00:21:18 +04:00
|
|
|
0);
|
2014-09-06 00:13:24 +04:00
|
|
|
ret = u3_cqfu_mull(von, sut, c3__noun, dox, gen);
|
2013-09-29 00:21:18 +04:00
|
|
|
|
2014-09-06 00:13:24 +04:00
|
|
|
u3z(von);
|
|
|
|
u3z(rob);
|
2013-09-29 00:21:18 +04:00
|
|
|
}
|
2014-09-06 00:13:24 +04:00
|
|
|
u3z(key);
|
2013-09-29 00:21:18 +04:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-09-06 00:13:24 +04:00
|
|
|
static u3_noun
|
|
|
|
_fire_each(u3_noun van,
|
|
|
|
u3_noun vet,
|
|
|
|
u3_noun typ,
|
|
|
|
u3_noun gat)
|
2013-09-29 00:21:18 +04:00
|
|
|
{
|
2014-09-06 00:13:24 +04:00
|
|
|
u3_noun p_typ, q_typ, pq_typ, qq_typ, rq_typ;
|
|
|
|
u3_noun h_gat, t_gat;
|
2013-09-29 00:21:18 +04:00
|
|
|
|
2014-09-06 00:13:24 +04:00
|
|
|
if ( (u3_no == u3du(typ)) || (c3__core != u3h(typ)) ) {
|
|
|
|
return u3_cm_error("fire-core");
|
2014-04-22 05:22:11 +04:00
|
|
|
} else if
|
2014-09-06 00:13:24 +04:00
|
|
|
( (u3_no == u3_cr_cell(u3t(typ), &p_typ, &q_typ)) ||
|
|
|
|
(u3_no == u3_cr_trel(q_typ, &pq_typ, &qq_typ, &rq_typ)) ||
|
|
|
|
(u3_no == u3_cr_cell(gat, &h_gat, &t_gat)) )
|
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-06 00:13:24 +04:00
|
|
|
u3_noun dox = u3nt
|
|
|
|
(c3__core, u3k(qq_typ), u3k(q_typ));
|
2013-09-29 00:21:18 +04:00
|
|
|
|
2014-09-06 00:13:24 +04:00
|
|
|
if ( c3__ash == u3h(gat) ) {
|
|
|
|
if ( (u3_yes == vet) &&
|
|
|
|
(u3_no == u3_cqfu_nest
|
|
|
|
(van, qq_typ, u3_yes, p_typ)) )
|
2013-09-29 00:21:18 +04:00
|
|
|
{
|
|
|
|
#if 0
|
2014-09-06 00:13:24 +04:00
|
|
|
u3_noun dun = u3_cqfu_dunq(van, "need", qq_typ);
|
|
|
|
u3_noun niz = u3_cqfu_dunq(van, "have", p_typ);
|
2013-09-29 00:21:18 +04:00
|
|
|
|
2014-09-06 00:13:24 +04:00
|
|
|
u3_ct_push(u3nc(c3__mean, niz));
|
|
|
|
u3_ct_push(u3nc(c3__mean, dun));
|
2013-09-29 00:21:18 +04:00
|
|
|
#endif
|
2014-09-06 00:13:24 +04:00
|
|
|
return u3_cm_error("fire-dry");
|
2013-09-29 00:21:18 +04:00
|
|
|
}
|
|
|
|
else {
|
2014-09-06 00:13:24 +04:00
|
|
|
return u3nc(dox, u3k(t_gat));
|
2013-09-29 00:21:18 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2014-09-06 00:13:24 +04:00
|
|
|
c3_assert(c3__elm == u3h(gat));
|
2013-09-29 00:21:18 +04:00
|
|
|
|
2014-09-06 00:13:24 +04:00
|
|
|
if ( (u3_yes == vet) &&
|
|
|
|
// (u3_no == u3_cr_sing(p_typ, qq_typ)) &&
|
|
|
|
(u3_no == _fire_mull(van, typ, dox, t_gat)) )
|
2013-09-29 00:21:18 +04:00
|
|
|
{
|
|
|
|
#if 0
|
2014-09-06 00:13:24 +04:00
|
|
|
u3_noun dun = u3_cqfu_dunq(van, "wild", typ);
|
|
|
|
u3_noun niz = u3_cqfu_dunq(van, "tame", dox);
|
2013-09-29 00:21:18 +04:00
|
|
|
|
2014-09-06 00:13:24 +04:00
|
|
|
u3_ct_push(u3nc(c3__mean, dun));
|
|
|
|
u3_ct_push(u3nc(c3__mean, niz));
|
2013-09-29 00:21:18 +04:00
|
|
|
#endif
|
2014-09-06 00:13:24 +04:00
|
|
|
return u3_cm_error("fire-wet");
|
2013-09-29 00:21:18 +04:00
|
|
|
}
|
|
|
|
else {
|
2014-09-06 00:13:24 +04:00
|
|
|
u3z(dox);
|
|
|
|
return u3nc(u3k(typ), u3k(t_gat));
|
2013-09-29 00:21:18 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-06 00:13:24 +04:00
|
|
|
static u3_noun
|
2014-08-21 01:18:34 +04:00
|
|
|
_fire_in(
|
2014-09-06 00:13:24 +04:00
|
|
|
u3_noun van,
|
|
|
|
u3_noun vet,
|
|
|
|
u3_noun hag)
|
2013-09-29 00:21:18 +04:00
|
|
|
{
|
2014-09-06 00:13:24 +04:00
|
|
|
if ( u3_nul == hag ) {
|
|
|
|
return u3_nul;
|
2013-09-29 00:21:18 +04:00
|
|
|
}
|
|
|
|
else {
|
2014-09-06 00:13:24 +04:00
|
|
|
u3_noun i_hag = u3h(hag);
|
|
|
|
u3_noun t_hag = u3t(hag);
|
2013-09-29 00:21:18 +04:00
|
|
|
|
2014-09-06 00:13:24 +04:00
|
|
|
if ( u3_no == u3du(i_hag) ) {
|
|
|
|
return u3_cm_bail(c3__fail);
|
2013-09-29 00:21:18 +04:00
|
|
|
} else {
|
2014-09-06 00:13:24 +04:00
|
|
|
return u3nc
|
|
|
|
(_fire_each(van, vet, u3h(i_hag), u3t(i_hag)),
|
2014-08-21 01:18:34 +04:00
|
|
|
_fire_in(van, vet, t_hag));
|
2013-09-29 00:21:18 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-09-06 00:13:24 +04:00
|
|
|
u3_noun
|
2014-09-03 09:46:55 +04:00
|
|
|
_cqfu_fire(
|
2014-09-06 00:13:24 +04:00
|
|
|
u3_noun van,
|
|
|
|
u3_noun sut,
|
|
|
|
u3_noun hag)
|
2013-09-29 00:21:18 +04:00
|
|
|
{
|
2014-09-06 00:13:24 +04:00
|
|
|
u3_bean vet = u3_cr_at(u3_cqfu_van_vet, van);
|
2013-09-29 00:21:18 +04:00
|
|
|
|
|
|
|
{
|
2014-09-06 00:13:24 +04:00
|
|
|
if ( (u3_yes == u3du(hag)) && (u3_nul == u3t(hag)) ) {
|
|
|
|
u3_noun i_hag = u3h(hag);
|
|
|
|
u3_noun pi_hag = u3h(i_hag);
|
|
|
|
u3_noun qi_hag = u3t(i_hag);
|
2014-04-22 05:22:11 +04:00
|
|
|
|
2014-09-06 00:13:24 +04:00
|
|
|
if ( c3__elm == u3h(qi_hag) ) {
|
|
|
|
u3_noun qqi_hag = u3t(qi_hag);
|
2014-04-22 05:22:11 +04:00
|
|
|
|
2014-09-06 00:13:24 +04:00
|
|
|
if ( u3_yes == u3du(qqi_hag) &&
|
|
|
|
(u3_nul == u3h(qqi_hag)) &&
|
|
|
|
(1 == u3t(qqi_hag)) )
|
2013-09-29 00:21:18 +04:00
|
|
|
{
|
2014-09-06 00:13:24 +04:00
|
|
|
return u3k(pi_hag);
|
2013-09-29 00:21:18 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-04-22 05:22:11 +04:00
|
|
|
}
|
2014-09-06 00:13:24 +04:00
|
|
|
return u3nc(c3__hold, _fire_in(van, vet, hag));
|
2013-09-29 00:21:18 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* boilerplate
|
|
|
|
*/
|
2014-09-06 00:13:24 +04:00
|
|
|
u3_noun
|
|
|
|
u3_cwfu_fire(
|
|
|
|
u3_noun cor)
|
2013-09-29 00:21:18 +04:00
|
|
|
{
|
2014-09-06 00:13:24 +04:00
|
|
|
u3_noun sut, hag, 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, &hag, u3_cv_con, &van, 0)) ||
|
|
|
|
(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_fire(van, sut, hag);
|
2013-09-29 00:21:18 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2014-09-06 00:13:24 +04:00
|
|
|
u3_noun
|
|
|
|
u3_cqfu_fire(u3_noun van,
|
|
|
|
u3_noun sut,
|
|
|
|
u3_noun hag)
|
2013-09-29 00:21:18 +04:00
|
|
|
{
|
2014-09-03 09:46:55 +04:00
|
|
|
return _cqfu_fire(van, sut, hag);
|
2013-09-29 00:21:18 +04:00
|
|
|
}
|