static enum parser_error parse_r_drop(struct parser *p) { struct monster_race *r = parser_priv(p); struct monster_drop *d; int tval, sval; if (!r) return PARSE_ERROR_MISSING_RECORD_HEADER; tval = tval_find_idx(parser_getsym(p, "tval")); if (tval < 0) return PARSE_ERROR_UNRECOGNISED_TVAL; sval = lookup_sval(tval, parser_getsym(p, "sval")); if (sval < 0) return PARSE_ERROR_UNRECOGNISED_SVAL; if (parser_getuint(p, "min") > 99 || parser_getuint(p, "max") > 99) return PARSE_ERROR_INVALID_ITEM_NUMBER; d = mem_zalloc(sizeof *d); d->kind = objkind_get(tval, sval); d->percent_chance = parser_getuint(p, "chance"); d->min = parser_getuint(p, "min"); d->max = parser_getuint(p, "max"); d->next = r->drops; r->drops = d; return PARSE_ERROR_NONE; }
static enum parser_error parse_r_mimic(struct parser *p) { struct monster_race *r = parser_priv(p); int tval, sval; object_kind *kind; if (!r) return PARSE_ERROR_MISSING_RECORD_HEADER; tval = tval_find_idx(parser_getsym(p, "tval")); if (tval < 0) return PARSE_ERROR_UNRECOGNISED_TVAL; sval = lookup_sval(tval, parser_getsym(p, "sval")); if (sval < 0) return PARSE_ERROR_UNRECOGNISED_SVAL; kind = objkind_get(tval, sval); if (!kind) return PARSE_ERROR_GENERIC; r->mimic_kind = kind; return PARSE_ERROR_NONE; }
/** * Creates a specific monster's drop, including any drops specified * in the monster.txt file. * * Returns TRUE if anything is created, FALSE if nothing is. */ static bool mon_create_drop(struct monster *m_ptr, byte origin) { struct monster_drop *drop; bool great, good, gold_ok, item_ok; bool extra_roll = FALSE; bool any = FALSE; int number = 0, level, j, monlevel; object_type *i_ptr; object_type object_type_body; assert(m_ptr); great = (rf_has(m_ptr->race->flags, RF_DROP_GREAT)); good = great || (rf_has(m_ptr->race->flags, RF_DROP_GOOD)); gold_ok = (!rf_has(m_ptr->race->flags, RF_ONLY_ITEM)); item_ok = (!rf_has(m_ptr->race->flags, RF_ONLY_GOLD)); /* Determine how much we can drop */ if (rf_has(m_ptr->race->flags, RF_DROP_20) && randint0(100) < 20) number++; if (rf_has(m_ptr->race->flags, RF_DROP_40) && randint0(100) < 40) number++; if (rf_has(m_ptr->race->flags, RF_DROP_60) && randint0(100) < 60) number++; if (rf_has(m_ptr->race->flags, RF_DROP_4)) number += rand_range(2, 6); if (rf_has(m_ptr->race->flags, RF_DROP_3)) number += rand_range(2, 4); if (rf_has(m_ptr->race->flags, RF_DROP_2)) number += rand_range(1, 3); if (rf_has(m_ptr->race->flags, RF_DROP_1)) number++; /* Give added bonus for unique monters */ monlevel = m_ptr->race->level; if (rf_has(m_ptr->race->flags, RF_UNIQUE)){ monlevel = MIN(monlevel + 15, monlevel * 2); extra_roll = TRUE; } /* Take the best of (average of monster level and current depth) and (monster level) - to reward fighting OOD monsters */ level = MAX((monlevel + p_ptr->depth) / 2, monlevel); level = MIN(level, 100); /* Specified drops */ for (drop = m_ptr->race->drops; drop; drop = drop->next) { if ((unsigned int)randint0(100) >= drop->percent_chance) continue; i_ptr = &object_type_body; if (drop->artifact) { object_prep(i_ptr, objkind_get(drop->artifact->tval, drop->artifact->sval), level, RANDOMISE); i_ptr->artifact = drop->artifact; copy_artifact_data(i_ptr, i_ptr->artifact); i_ptr->artifact->created = 1; } else { object_prep(i_ptr, drop->kind, level, RANDOMISE); apply_magic(i_ptr, level, TRUE, good, great, extra_roll); } i_ptr->origin = origin; i_ptr->origin_depth = p_ptr->depth; i_ptr->origin_xtra = m_ptr->race->ridx; i_ptr->number = randint0(drop->max - drop->min) + drop->min; if (monster_carry(m_ptr, i_ptr)) any = TRUE; } /* Make some objects */ for (j = 0; j < number; j++) { i_ptr = &object_type_body; object_wipe(i_ptr); if (gold_ok && (!item_ok || (randint0(100) < 50))) { make_gold(i_ptr, level, SV_GOLD_ANY); } else { if (!make_object(cave, i_ptr, level, good, great, extra_roll, NULL, 0)) continue; } i_ptr->origin = origin; i_ptr->origin_depth = p_ptr->depth; i_ptr->origin_xtra = m_ptr->race->ridx; if (monster_carry(m_ptr, i_ptr)) any = TRUE; } return any; }