[Code][Long] Coins Snippet ARGH!

From: Dana Luther (dtluther@mindspring.com)
Date: 06/15/00


It has come to my attention that some VERY important alterations were left
out of the patch file. I apologize for the oversight and will try to get an
updated file into the ftp site asap. (ps., mailer code = some nasty line
formats)

Also, in response to the questions earlier about
int money[4];  -vs- int money[MAX_COIN_TYPES];
The reason I used the number directly is because it corresponds directly to
the number of object value slots for ITEM_MONEY, and using the macro define
would imply that it could easily be expaned beyond that amount. ;)
I think that version 2.0 is not far in coming, simply because of all the
varied comments I've recieved on this so far. Thanks to those of you who
have sent in input! :)

The code follows for anyone who's been trying it:
In dgscripts.c
**************
---snip---
      else if (!str_cmp(field, "gold")) {
        if (subfield && *subfield) {
          int addition = atoi(subfield);
!          add_money_to_char(c, addition, GOLD_COINS);
        }
        sprintf(str, "%d", GET_MONEY(c, GOLD_COINS));
      }
+     else if (!str_cmp(field, "platinum")) {
+        if (subfield && *subfield) {
+          int addition = atoi(subfield);
+          add_money_to_char(c, addition, PLAT_COINS);
+        }
+        sprintf(str, "%d", GET_MONEY(c, PLAT_COINS));
+      }
+      else if (!str_cmp(field, "silver")) {
+        if (subfield && *subfield) {
+          int addition = atoi(subfield);
+          add_money_to_char(c, addition, SILVER_COINS);
+        }
+        sprintf(str, "%d", GET_MONEY(c, SILVER_COINS));
+      }
+      else if (!str_cmp(field, "copper")) {
+        if (subfield && *subfield) {
+          int addition = atoi(subfield);
+          add_money_to_char(c, addition, COPPER_COINS);
+       }
+        sprintf(str, "%d", GET_MONEY(c, COPPER_COINS));
+      }
      else if (!str_cmp(field, "exp")) {
       if (subfield && *subfield) {
          int addition = MAX(atoi(subfield), 1000);
          GET_EXP(c) += addition;
        }
        sprintf(str, "%d", GET_EXP(c));
      }

in handler.c
*************
!char *money_desc(int amount, int type)
{
  static char buf[128];
  if (amount <= 0) {
    log("SYSERR: Try to create negative or 0 money (%d).", amount);
    return (NULL);
  }
  if (amount == 1)
!    sprintf(buf, "a %s coin", coin_types[type]);
  else if (amount <= 10)
!    sprintf(buf, "a tiny pile of %s coins", coin_types[type]);
  else if (amount <= 20)
!    sprintf(buf, "a handful of %s coins", coin_types[type]);
  else if (amount <= 75)
!    sprintf(buf, "a little pile of %s coins", coin_types[type]);
  else if (amount <= 200)
!    sprintf(buf, "a small pile of %s coins", coin_types[type]);
  else if (amount <= 1000)
!    sprintf(buf, "a pile of %s coins", coin_types[type]);
  else if (amount <= 5000)
!    sprintf(buf, "a big pile of %s coins", coin_types[type]);
  else if (amount <= 10000)
!    sprintf(buf, "a large heap of %s coins", coin_types[type]);
  else if (amount <= 20000)
!    sprintf(buf, "a huge mound of %s coins", coin_types[type]);
  else if (amount <= 75000)
!    sprintf(buf, "an enormous mound of %s coins", coin_types[type]);
  else if (amount <= 150000)
!    sprintf(buf, "a small mountain of %s coins", coin_types[type]);
  else if (amount <= 250000)
!    sprintf(buf, "a mountain of %s coins", coin_types[type]);
  else if (amount <= 500000)
!    sprintf(buf, "a huge mountain of %s coins", coin_types[type]);
  else if (amount <= 1000000)
!    sprintf(buf, "an enormous mountain of %s coins", coin_types[type]);
  else
!    sprintf(buf, "an absolutely colossal mountain of %s coins",
coin_types[type]);

  return (buf);
}

!struct obj_data *create_money(int plat, int gold, int silver, int copper,
int type)
{
  struct obj_data *obj;
  struct extra_descr_data *new_descr;
  char buf[200];
  int amount;

!  amount = plat + gold + silver + copper;
  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) {
!    sprintf(buf, "coin %s", coin_types[type]);
    obj->name = str_dup(buf);
!    sprintf(buf, "a %s coin", coin_types[type]);
    obj->short_description = str_dup(buf);
!    sprintf(buf, "One miserable %s coin is lying here.", coin_types[type]);
    obj->description = str_dup(buf);
!    sprintf(buf, "coin %s", coin_types[type]);
    new_descr->keyword = str_dup(buf);
!    sprintf(buf, "It's just one miserable little %s coin.",
coin_types[type]);
    new_descr->description = str_dup(buf);
  } else {
!    sprintf(buf, "coins %s", coin_types[type]);
    obj->name = str_dup(buf);
!    obj->short_description = str_dup(money_desc(amount, type));
!    sprintf(buf, "%s is lying here.", money_desc(amount, type));
    obj->description = str_dup(CAP(buf));
!    sprintf(buf, "coins %s", coin_types[type]);
    new_descr->keyword = str_dup(buf);
    if (amount < 10) {
!      sprintf(buf, "There are %d %s coins.", amount, coin_types[type]);
      new_descr->description = str_dup(buf);
    } else if (amount < 100) {
!      sprintf(buf, "There are about %d %s coins.", 10 * (amount / 10),
coin_types[type]);
      new_descr->description = str_dup(buf);
    } else if (amount < 1000) {
!      sprintf(buf, "It looks to be about %d %s coins.", 100 * (amount /
100), coin_types[type]);
      new_descr->description = str_dup(buf);
    } else if (amount < 100000) {
!      sprintf(buf, "You guess there are, maybe, %d %s coins.",
!       1000 * ((amount / 1000) + number(0, (amount / 1000))),
coin_types[type]);
      new_descr->description = str_dup(buf);
    } else {
!      sprintf(buf, "There are a LOT of %s coins.", coin_types[type]);
      new_descr->description = str_dup(buf);
    }
  }
  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, PLAT_COINS) = plat;
+  GET_OBJ_VAL(obj, GOLD_COINS) = gold;
+  GET_OBJ_VAL(obj, SILVER_COINS) = silver;
+  GET_OBJ_VAL(obj, COPPER_COINS) = copper;

  GET_OBJ_COST(obj) = ((plat * COPPER_PER_PLAT) + (gold * COPPER_PER_GOLD) +
(silver * COPPER_PER_SILVER) + copper);
  obj->item_number = NOTHING;
  return (obj);
}


     +------------------------------------------------------------+
     | Ensure that you have read the CircleMUD Mailing List FAQ:  |
     |  http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html  |
     +------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 04/10/01 PDT