2013-09-29 00:21:18 +04:00
|
|
|
/* j/6/fire.c
|
|
|
|
**
|
|
|
|
** This file is in the public domain.
|
|
|
|
*/
|
|
|
|
#include "all.h"
|
|
|
|
#include "../pit.h"
|
|
|
|
|
|
|
|
/* logic
|
|
|
|
*/
|
|
|
|
static u2_bean
|
2014-08-28 23:40:40 +04:00
|
|
|
_fire_mull(u2_noun van,
|
2013-09-29 00:21:18 +04:00
|
|
|
u2_noun sut,
|
|
|
|
u2_noun dox,
|
|
|
|
u2_noun gen)
|
|
|
|
{
|
2014-09-03 09:46:55 +04:00
|
|
|
u2_noun rib = u2_cr_at(u2_cqfu_van_rib, van);
|
2014-08-21 01:18:34 +04:00
|
|
|
u2_noun key = u2nt(u2k(sut),
|
|
|
|
u2k(dox),
|
|
|
|
u2k(gen));
|
2013-09-29 00:21:18 +04:00
|
|
|
u2_bean ret;
|
2014-04-22 05:22:11 +04:00
|
|
|
|
2014-09-03 07:36:29 +04:00
|
|
|
if ( u2_yes == u2_cqdi_has(rib, key) ) {
|
2013-09-29 00:21:18 +04:00
|
|
|
ret = u2_yes;
|
|
|
|
}
|
|
|
|
else {
|
2014-09-03 07:36:29 +04:00
|
|
|
u2_noun rob = u2_cqdi_put(rib, key);
|
2014-08-21 01:18:34 +04:00
|
|
|
u2_noun von = u2_ci_molt(u2k(van),
|
2014-09-03 09:46:55 +04:00
|
|
|
u2_cqfu_van_rib, u2k(rob),
|
2013-09-29 00:21:18 +04:00
|
|
|
0);
|
2014-09-03 07:36:29 +04:00
|
|
|
ret = u2_cqfu_mull(von, sut, c3__noun, dox, gen);
|
2013-09-29 00:21:18 +04:00
|
|
|
|
2014-08-21 01:18:34 +04:00
|
|
|
u2z(von);
|
|
|
|
u2z(rob);
|
2013-09-29 00:21:18 +04:00
|
|
|
}
|
2014-08-21 01:18:34 +04:00
|
|
|
u2z(key);
|
2013-09-29 00:21:18 +04:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-04-22 05:22:11 +04:00
|
|
|
static u2_noun
|
2014-08-28 23:40:40 +04:00
|
|
|
_fire_each(u2_noun van,
|
2013-09-29 00:21:18 +04:00
|
|
|
u2_noun vet,
|
|
|
|
u2_noun typ,
|
|
|
|
u2_noun gat)
|
|
|
|
{
|
|
|
|
u2_noun p_typ, q_typ, pq_typ, qq_typ, rq_typ;
|
|
|
|
u2_noun h_gat, t_gat;
|
|
|
|
|
2014-08-21 01:18:34 +04:00
|
|
|
if ( (u2_no == u2du(typ)) || (c3__core != u2h(typ)) ) {
|
|
|
|
return u2_cm_error("fire-core");
|
2014-04-22 05:22:11 +04:00
|
|
|
} else if
|
2014-08-21 01:18:34 +04:00
|
|
|
( (u2_no == u2_cr_cell(u2t(typ), &p_typ, &q_typ)) ||
|
|
|
|
(u2_no == u2_cr_trel(q_typ, &pq_typ, &qq_typ, &rq_typ)) ||
|
|
|
|
(u2_no == u2_cr_cell(gat, &h_gat, &t_gat)) )
|
2013-09-29 00:21:18 +04:00
|
|
|
{
|
2014-08-21 01:18:34 +04:00
|
|
|
return u2_cm_bail(c3__fail);
|
2013-09-29 00:21:18 +04:00
|
|
|
} else {
|
2014-08-21 01:18:34 +04:00
|
|
|
u2_noun dox = u2nt
|
|
|
|
(c3__core, u2k(qq_typ), u2k(q_typ));
|
2013-09-29 00:21:18 +04:00
|
|
|
|
2014-08-21 01:18:34 +04:00
|
|
|
if ( c3__ash == u2h(gat) ) {
|
2013-09-29 00:21:18 +04:00
|
|
|
if ( (u2_yes == vet) &&
|
2014-09-03 07:36:29 +04:00
|
|
|
(u2_no == u2_cqfu_nest
|
2014-08-21 01:18:34 +04:00
|
|
|
(van, qq_typ, u2_yes, p_typ)) )
|
2013-09-29 00:21:18 +04:00
|
|
|
{
|
|
|
|
#if 0
|
2014-09-03 07:36:29 +04:00
|
|
|
u2_noun dun = u2_cqfu_dunq(van, "need", qq_typ);
|
|
|
|
u2_noun niz = u2_cqfu_dunq(van, "have", p_typ);
|
2013-09-29 00:21:18 +04:00
|
|
|
|
2014-08-21 01:18:34 +04:00
|
|
|
u2_ct_push(u2nc(c3__mean, niz));
|
|
|
|
u2_ct_push(u2nc(c3__mean, dun));
|
2013-09-29 00:21:18 +04:00
|
|
|
#endif
|
2014-08-21 01:18:34 +04:00
|
|
|
return u2_cm_error("fire-dry");
|
2013-09-29 00:21:18 +04:00
|
|
|
}
|
|
|
|
else {
|
2014-08-21 01:18:34 +04:00
|
|
|
return u2nc(dox, u2k(t_gat));
|
2013-09-29 00:21:18 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2014-08-21 01:18:34 +04:00
|
|
|
c3_assert(c3__elm == u2h(gat));
|
2013-09-29 00:21:18 +04:00
|
|
|
|
|
|
|
if ( (u2_yes == vet) &&
|
2014-08-21 01:18:34 +04:00
|
|
|
// (u2_no == u2_cr_sing(p_typ, qq_typ)) &&
|
|
|
|
(u2_no == _fire_mull(van, typ, dox, t_gat)) )
|
2013-09-29 00:21:18 +04:00
|
|
|
{
|
|
|
|
#if 0
|
2014-09-03 07:36:29 +04:00
|
|
|
u2_noun dun = u2_cqfu_dunq(van, "wild", typ);
|
|
|
|
u2_noun niz = u2_cqfu_dunq(van, "tame", dox);
|
2013-09-29 00:21:18 +04:00
|
|
|
|
2014-08-21 01:18:34 +04:00
|
|
|
u2_ct_push(u2nc(c3__mean, dun));
|
|
|
|
u2_ct_push(u2nc(c3__mean, niz));
|
2013-09-29 00:21:18 +04:00
|
|
|
#endif
|
2014-08-21 01:18:34 +04:00
|
|
|
return u2_cm_error("fire-wet");
|
2013-09-29 00:21:18 +04:00
|
|
|
}
|
|
|
|
else {
|
2014-08-21 01:18:34 +04:00
|
|
|
u2z(dox);
|
|
|
|
return u2nc(u2k(typ), u2k(t_gat));
|
2013-09-29 00:21:18 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static u2_noun
|
2014-08-21 01:18:34 +04:00
|
|
|
_fire_in(
|
2013-09-29 00:21:18 +04:00
|
|
|
u2_noun van,
|
|
|
|
u2_noun vet,
|
|
|
|
u2_noun hag)
|
|
|
|
{
|
|
|
|
if ( u2_nul == hag ) {
|
|
|
|
return u2_nul;
|
|
|
|
}
|
|
|
|
else {
|
2014-08-21 01:18:34 +04:00
|
|
|
u2_noun i_hag = u2h(hag);
|
|
|
|
u2_noun t_hag = u2t(hag);
|
2013-09-29 00:21:18 +04:00
|
|
|
|
2014-08-21 01:18:34 +04:00
|
|
|
if ( u2_no == u2du(i_hag) ) {
|
|
|
|
return u2_cm_bail(c3__fail);
|
2013-09-29 00:21:18 +04:00
|
|
|
} else {
|
2014-08-21 01:18:34 +04:00
|
|
|
return u2nc
|
|
|
|
(_fire_each(van, vet, u2h(i_hag), u2t(i_hag)),
|
|
|
|
_fire_in(van, vet, t_hag));
|
2013-09-29 00:21:18 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-09-04 01:33:18 +04:00
|
|
|
u2_noun
|
2014-09-03 09:46:55 +04:00
|
|
|
_cqfu_fire(
|
2014-09-04 01:33:18 +04:00
|
|
|
u2_noun van,
|
|
|
|
u2_noun sut,
|
|
|
|
u2_noun hag)
|
2013-09-29 00:21:18 +04:00
|
|
|
{
|
2014-09-03 09:46:55 +04:00
|
|
|
u2_bean vet = u2_cr_at(u2_cqfu_van_vet, van);
|
2013-09-29 00:21:18 +04:00
|
|
|
|
|
|
|
{
|
2014-08-21 01:18:34 +04:00
|
|
|
if ( (u2_yes == u2du(hag)) && (u2_nul == u2t(hag)) ) {
|
|
|
|
u2_noun i_hag = u2h(hag);
|
|
|
|
u2_noun pi_hag = u2h(i_hag);
|
|
|
|
u2_noun qi_hag = u2t(i_hag);
|
2014-04-22 05:22:11 +04:00
|
|
|
|
2014-08-21 01:18:34 +04:00
|
|
|
if ( c3__elm == u2h(qi_hag) ) {
|
|
|
|
u2_noun qqi_hag = u2t(qi_hag);
|
2014-04-22 05:22:11 +04:00
|
|
|
|
2014-08-21 01:18:34 +04:00
|
|
|
if ( u2_yes == u2du(qqi_hag) &&
|
|
|
|
(u2_nul == u2h(qqi_hag)) &&
|
|
|
|
(1 == u2t(qqi_hag)) )
|
2013-09-29 00:21:18 +04:00
|
|
|
{
|
2014-08-21 01:18:34 +04:00
|
|
|
return u2k(pi_hag);
|
2013-09-29 00:21:18 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2014-04-22 05:22:11 +04:00
|
|
|
}
|
2014-08-21 01:18:34 +04:00
|
|
|
return u2nc(c3__hold, _fire_in(van, vet, hag));
|
2013-09-29 00:21:18 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/* boilerplate
|
|
|
|
*/
|
2014-09-04 01:33:18 +04:00
|
|
|
u2_noun
|
2014-09-03 09:46:55 +04:00
|
|
|
u2_cwfu_fire(
|
2014-09-04 01:33:18 +04:00
|
|
|
u2_noun cor)
|
2013-09-29 00:21:18 +04:00
|
|
|
{
|
|
|
|
u2_noun sut, hag, van;
|
|
|
|
|
2014-08-21 01:18:34 +04:00
|
|
|
if ( (u2_no == u2_cr_mean(cor, u2_cv_sam, &hag, u2_cv_con, &van, 0)) ||
|
|
|
|
(u2_none == (sut = u2_cr_at(u2_cv_sam, van))) )
|
2013-09-29 00:21:18 +04:00
|
|
|
{
|
2014-08-21 01:18:34 +04:00
|
|
|
return u2_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-04 01:33:18 +04:00
|
|
|
u2_noun
|
|
|
|
u2_cqfu_fire(u2_noun van,
|
|
|
|
u2_noun sut,
|
|
|
|
u2_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
|
|
|
}
|