/** * Copy the 2nd top item off the stack into pf. * This is called on #else and #elif. * The stack contains [...] [base] [if] at this point. * We want to copy [base]. */ static void pf_copy_2nd_tos(struct parse_frame *pf) { if (cpd.frame_count > 1) { pf_copy(pf, &cpd.frames[cpd.frame_count - 2]); } LOG_FMT(LPF, "%s: count = %d\n", __func__, cpd.frame_count); }
/** * Remove the "bad" spells from a spell list */ static void remove_bad_spells(struct monster *mon, bitflag f[RSF_SIZE]) { bitflag f2[RSF_SIZE], ai_flags[OF_SIZE], ai_pflags[PF_SIZE]; struct element_info el[ELEM_MAX]; bool know_something = false; /* Stupid monsters act randomly */ if (rf_has(mon->race->flags, RF_STUPID)) return; /* Take working copy of spell flags */ rsf_copy(f2, f); /* Don't heal if full */ if (mon->hp >= mon->maxhp) rsf_off(f2, RSF_HEAL); /* Don't haste if hasted with time remaining */ if (mon->m_timed[MON_TMD_FAST] > 10) rsf_off(f2, RSF_HASTE); /* Don't teleport to if the player is already next to us */ if (mon->cdis == 1) rsf_off(f2, RSF_TELE_TO); /* Update acquired knowledge */ of_wipe(ai_flags); pf_wipe(ai_pflags); if (OPT(birth_ai_learn)) { size_t i; /* Occasionally forget player status */ if (one_in_(100)) { of_wipe(mon->known_pstate.flags); pf_wipe(mon->known_pstate.pflags); for (i = 0; i < ELEM_MAX; i++) mon->known_pstate.el_info[i].res_level = 0; } /* Use the memorized info */ of_copy(ai_flags, mon->known_pstate.flags); pf_copy(ai_pflags, mon->known_pstate.pflags); if (!of_is_empty(ai_flags) || !pf_is_empty(ai_pflags)) know_something = true; for (i = 0; i < ELEM_MAX; i++) { el[i].res_level = mon->known_pstate.el_info[i].res_level; if (el[i].res_level != 0) know_something = true; } } /* Cancel out certain flags based on knowledge */ if (know_something) unset_spells(f2, ai_flags, ai_pflags, el, mon->race); /* use working copy of spell flags */ rsf_copy(f, f2); }
/** * Push a copy of the parse frame onto the stack, under the tos. * If this were a linked list, just add before the last item. * This is called on the first #else and #elif. */ void pf_push_under(struct parse_frame *pf) { struct parse_frame *npf1; struct parse_frame *npf2; LOG_FMT(LPF, "%s: before count = %d\n", __func__, cpd.frame_count); if ((cpd.frame_count < (int)ARRAY_SIZE(cpd.frames)) && (cpd.frame_count >= 1)) { npf1 = &cpd.frames[cpd.frame_count - 1]; npf2 = &cpd.frames[cpd.frame_count]; pf_copy(npf2, npf1); pf_copy(npf1, pf); cpd.frame_count++; } LOG_FMT(LPF, "%s: after count = %d\n", __func__, cpd.frame_count); }
/** * Push a copy of the parse frame onto the stack. * This is called on #if and #ifdef. */ void pf_push(struct parse_frame *pf) { static int ref_no = 1; if (cpd.frame_count < (int)ARRAY_SIZE(cpd.frames)) { pf_copy(&cpd.frames[cpd.frame_count], pf); cpd.frame_count++; pf->ref_no = ref_no++; } LOG_FMT(LPF, "%s: count = %d\n", __func__, cpd.frame_count); }