[CODE]More about do_time

From: Peter Ajamian (peter@pajamian.dhs.org)
Date: 01/06/01


Taking yet another look at do_time I noticed that there are magic
numbers in the function that would be better represented by the use of
existing macros in utils.h.  The macros I'm referring to, of course, are
the following...

/* mud-life time */
#define SECS_PER_MUD_HOUR       75
#define SECS_PER_MUD_DAY        (24*SECS_PER_MUD_HOUR)
#define SECS_PER_MUD_MONTH      (35*SECS_PER_MUD_DAY)
#define SECS_PER_MUD_YEAR       (17*SECS_PER_MUD_MONTH)

It occurred to me that if these macros (or variations of them) were used
instead of the direct numbers that it would enable an implementor to
change the number of days in a month, months in a year, hours in a day,
etc. in utils.h without having to change the corresponding values in
do_time as well.  I'd like to propose the following modification to the
source...

utils.h:

Change the above referenced section to the following...

/* mud-life time */
#define SECS_PER_MUD_HOUR       75
#define HOURS_PER_MUD_DAY       24
#define DAYS_PER_MUD_WEEK       7
#define DAYS_PER_MUD_MONTH      35
#define MONTHS_PER_MUD_YEAR     17

/* For compatibility with existing functions */
#define SECS_PER_MUD_DAY        (HOURS_PER_MUD_DAY*SECS_PER_MUD_HOUR)
#define SECS_PER_MUD_MONTH      (DAYS_PER_MUD_MONTH*SECS_PER_MUD_DAY)
#define SECS_PER_MUD_YEAR       (MONTHS_PER_MUD_YEAR*SECS_PER_MUD_MONTH)

Then you can make the following changes to do_time:

 ACMD(do_time)
 {
   const char *suf;
   int weekday, day;

   sprintf(buf, "It is %d o'clock %s, on ",
-          ((time_info.hours % 12 == 0) ? 12 : ((time_info.hours) % 12)),
+          ((time_info.hours % (HOURS_PER_MONTH_DAY/2) == 0) ?
+           (HOURS_PER_MONTH_DAY/2) :
+           ((time_info.hours) % (HOURS_PER_MONTH_DAY/2))),
-          ((time_info.hours >= 12) ? "pm" : "am"));
           ((time_info.hours >= (HOURS_PER_MONTH_DAY/2)) ? "pm" : "am"));

   /* 35 days in a month */
-  weekday = ((35 * time_info.month) + time_info.day + 1) % 7;
+  weekday = ((DAYS_PER_MUD_MONTH * time_info.month) +
+             time_info.day + 1) % DAYS_PER_MUD_WEEK;

I haven't gone through the source scrounging for other places where this
type of change should be made, but the following comment in utils.h
would seem to indicate taht there are other places as well...

/*
 * XXX: These constants should be configurable. See act.informative.c
 *      and utils.c for other places to change.
 */

Regards, Peter

--
   +---------------------------------------------------------------+
   | 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/03/01 PST