/** * Make a money object * * \param lev the dungeon level * \param coin_type the name of the type of money object to make * \return a pointer to the newly minted cash (cannot fail) */ struct object *make_gold(int lev, char *coin_type) { /* This average is 20 at dlev0, 100 at dlev40, 220 at dlev100. */ s32b avg = (18 * lev)/10 + 18; s32b spread = lev + 10; s32b value = rand_spread(avg, spread); struct object *new_gold = mem_zalloc(sizeof(*new_gold)); /* Increase the range to infinite, moving the average to 110% */ while (one_in_(100) && value * 10 <= SHRT_MAX) value *= 10; /* Prepare a gold object */ object_prep(new_gold, money_kind(coin_type, value), lev, RANDOMISE); /* If we're playing with no_selling, increase the value */ if (OPT(birth_no_selling) && player->depth) value = value * MIN(5, player->depth); /* Cap gold at max short (or alternatively make pvals s32b) */ if (value > SHRT_MAX) value = SHRT_MAX; new_gold->pval = value; return new_gold; }
/** * Melee effect handler: Take the player's gold. */ static void melee_effect_handler_EAT_GOLD(melee_effect_handler_context_t *context) { struct player *player = context->p; /* Take damage */ take_hit(context->p, context->damage, context->ddesc); /* Obvious */ context->obvious = TRUE; /* Attempt saving throw (unless paralyzed) based on dex and level */ if (!player->timed[TMD_PARALYZED] && (randint0(100) < (adj_dex_safe[player->state.stat_ind[STAT_DEX]] + player->lev))) { /* Saving throw message */ msg("You quickly protect your money pouch!"); /* Occasional blink anyway */ if (randint0(3)) context->blinked = TRUE; } else { s32b gold = (player->au / 10) + randint1(25); if (gold < 2) gold = 2; if (gold > 5000) gold = (player->au / 20) + randint1(3000); if (gold > player->au) gold = player->au; player->au -= gold; if (gold <= 0) { msg("Nothing was stolen."); return; } /* Let the player know they were robbed */ msg("Your purse feels lighter."); if (player->au) msg("%d coins were stolen!", gold); else msg("All of your coins were stolen!"); /* While we have gold, put it in objects */ while (gold > 0) { int amt; /* Create a new temporary object */ object_type *obj = object_new(); object_prep(obj, money_kind("gold", gold), 0, MINIMISE); /* Amount of gold to put in this object */ amt = gold > MAX_PVAL ? MAX_PVAL : gold; obj->pval = amt; gold -= amt; /* Set origin to stolen, so it is not confused with * dropped treasure in monster_death */ obj->origin = ORIGIN_STOLEN; obj->origin_depth = player->depth; /* Give the gold to the monster */ monster_carry(cave, context->m_ptr, obj); } /* Redraw gold */ player->upkeep->redraw |= (PR_GOLD); /* Blink away */ context->blinked = TRUE; } }