create_money()

From: Axiem j'Terre (axiem@swbell.net)
Date: 03/15/01


In handler.c, in the function create_money() (circa line 1123), I noticed
something:

When setting the various values for the "gold" object: (circa line 1148)

    new_descr->keyword = str_dup("coins gold");
    if (amount < 10) {
      sprintf(buf, "There are %d coins.", amount);
      new_descr->description = str_dup(buf);
    } else if (amount < 100) {
      sprintf(buf, "There are about %d coins.", 10 * (amount / 10));
      new_descr->description = str_dup(buf);
    } else if (amount < 1000) {
      sprintf(buf, "It looks to be about %d coins.", 100 * (amount / 100));
      new_descr->description = str_dup(buf);
    } else if (amount < 100000) {
      sprintf(buf, "You guess there are, maybe, %d coins.",
       1000 * ((amount / 1000) + number(0, (amount / 1000))));
      new_descr->description = str_dup(buf);
    } else
      new_descr->description = str_dup("There are a LOT of coins.");


This seems a bit redundant to me. Wouldn't it be easier to set it up like
so?:

(if stuff)
    new_descr->keyword = str_dup("coins gold");
    if (amount < 10) {
      sprintf(buf, "There are %d coins.", amount);
    } else if (amount < 100) {
      sprintf(buf, "There are about %d coins.", 10 * (amount / 10));
    } else if (amount < 1000) {
      sprintf(buf, "It looks to be about %d coins.", 100 * (amount / 100));
    } else if (amount < 100000) {
      sprintf(buf, "You guess there are, maybe, %d coins.",
       1000 * ((amount / 1000) + number(0, (amount / 1000))));
    } else {
      sprintf(buf, "There are a LOT of coins.");
    }
    new_descr->description = str_dup(buf);


Or something to that degree.
This doesn't save a whole lot of room, admittedly, but it makes more sense
to me, instead of repeating "      new_descr->description = str_dup(buf);"
multiple times.
As well, this would make it a bit easier to change these at a coder's whim.
I wonder, however, would there be an easier method of coding this block,
instead of is/then/elseif/else?

If not, then I suggest this slight improvement, unless there's something
here I haven't seen. (If someone's pointed this out before, my mistake,
though I can't recall seeing it in the ChangeLog)

That's all :)

-Axiem

--
   +---------------------------------------------------------------+
   | FAQ: http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html |
   | Archives: http://post.queensu.ca/listserv/wwwarch/circle.html |
   +---------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 12/04/01 PST