struct obj_data *create_money(int amount) { struct obj_data *obj; struct extra_descr_data *new_descr; char buf[200]; int y; if (amount <= 0) { log("SYSERR: Try to create negative or 0 money. (%d)", amount); return (NULL); } obj = create_obj(); CREATE(new_descr, struct extra_descr_data, 1); if (amount == 1) { obj->name = strdup("coin gold"); obj->short_description = strdup("a gold coin"); obj->description = strdup("One miserable gold coin is lying here."); new_descr->keyword = strdup("coin gold"); new_descr->description = strdup("It's just one miserable little gold coin."); } else { obj->name = strdup("coins gold"); obj->short_description = strdup(money_desc(amount)); snprintf(buf, sizeof(buf), "%s is lying here.", money_desc(amount)); obj->description = strdup(CAP(buf)); new_descr->keyword = strdup("coins gold"); if (amount < 10) snprintf(buf, sizeof(buf), "There are %d coins.", amount); else if (amount < 100) snprintf(buf, sizeof(buf), "There are about %d coins.", 10 * (amount / 10)); else if (amount < 1000) snprintf(buf, sizeof(buf), "It looks to be about %d coins.", 100 * (amount / 100)); else if (amount < 100000) snprintf(buf, sizeof(buf), "You guess there are, maybe, %d coins.", 1000 * ((amount / 1000) + rand_number(0, (amount / 1000)))); else strcpy(buf, "There are a LOT of coins."); /* strcpy: OK (is < 200) */ new_descr->description = strdup(buf); } new_descr->next = NULL; obj->ex_description = new_descr; GET_OBJ_TYPE(obj) = ITEM_MONEY; for(y = 0; y < TW_ARRAY_MAX; y++) obj->obj_flags.wear_flags[y] = 0; SET_BIT_AR(GET_OBJ_WEAR(obj), ITEM_WEAR_TAKE); GET_OBJ_VAL(obj, 0) = amount; GET_OBJ_COST(obj) = amount; obj->item_number = NOTHING; return (obj); }
struct obj_data *create_money(struct money_data amount) { struct obj_data *obj; struct extra_descr_data *new_descr; char buf[200]; int coins; if ( money_to_copper(amount) <= 0) { log("SYSERR: Try to create negative or 0 money."); return NULL; } obj = create_obj(); CREATE(new_descr, struct extra_descr_data, 1); coins = amount.platinum + amount.steel + amount.gold + amount.copper; if (coins == 1) { obj->name = str_dup("one coin"); obj->short_description = str_dup("a coin"); obj->description = str_dup("One miserable coin is lying here."); new_descr->keyword = str_dup("coin"); new_descr->description = str_dup("It's just one miserable little coin."); } else { obj->name = str_dup("coins"); obj->short_description = str_dup(money_desc(coins)); sprintf(buf, "%s is lying here.", money_desc(coins)); obj->description = str_dup(CAP(buf)); new_descr->keyword = str_dup("coins"); if (coins < 10) { sprintf(buf, "There are %d coins.", coins); new_descr->description = str_dup(buf); } else if (coins < 100) { sprintf(buf, "There are about %d coins.", 10 * (coins / 10)); new_descr->description = str_dup(buf); } else if (coins < 1000) { sprintf(buf, "It looks to be about %d coins.", 100 * (coins / 100)); new_descr->description = str_dup(buf); } else if (coins < 100000) { sprintf(buf, "You guess there are, maybe, %d coins.", 1000 * ((coins / 1000) + number(0, (coins / 1000)))); new_descr->description = str_dup(buf); } else new_descr->description = str_dup("There are a LOT of coins."); } new_descr->next = NULL; obj->ex_description = new_descr; GET_OBJ_TYPE(obj) = ITEM_MONEY; GET_OBJ_WEAR(obj) = ITEM_WEAR_TAKE; GET_OBJ_VAL(obj, 0) = amount.platinum; GET_OBJ_VAL(obj, 1) = amount.steel; GET_OBJ_VAL(obj, 2) = amount.gold; GET_OBJ_VAL(obj, 3) = amount.copper; GET_OBJ_COST(obj) = money_to_copper(amount); obj->item_number = NOTHING; return obj; }