Hello all. First off, I must thank Nick and everyone here for all the advice and help. This is my first post, but I have been reading the forum for a while now, and it is great. I have compiled the source, read tons of documents, and made a few changes to the code, adding a snippet or two.
Now I wish to do what seems at first simple: Change the default names of the days and months to what my campaign will use. Unfortunately, for a beginning coder it seems to be confusing the heck out of me.
I looked in act_info and found the names of days and month, in function do_time. I see that there are 7 days a week, and 17 months to a year.
I see where the day is day % 7, which I change to 10, as I have 10 days a week. I change the day names and add more until there are 10. When I compile, it boots up good, but at checking the time, it displays the hour, and uses my new day name but leaves the month name blank. What I would like to do is add a year field to the time, and I can't see how.
Any advice? And forgive the lengthy post.
Gadush
Thanks for the quick response. I will read up on using gdb, first off. And I will take a look in those areas mentioned. It is very likely I simply don't have a good grasp of what the function was doing exactly to begin with, so looking further should help. I suppose I was greedily hoping somebody else had already done something like this. Hee hee. However, figuring it out would be better anyhow. I will post what I find after checking around a bit.
Gadush
In act_info.c I made the following changes:
Note: The comments were added by me for this post, and are not in the code.
char * const day_name [] =
{
"the first day", "the second day", "the third day", "the fourth day", "midweek", "the sixth day", "the seventh day", "the eighth day",
"the ninth day", "the last day"
};
// I changed day names and added a few more to make 10
char * const month_name [] =
{
"Hammer", "Alturiak", "Ches", "Tarsakh",
"Mirtul", "Kythorn", "Flamerule", "Eleasias", "Eleint",
"Marpenoth", "Uktar", "Nightal"
};
// Changed month names
void do_time( CHAR_DATA *ch, char *argument )
{
extern char str_boot_time[];
extern char reboot_time[];
char *suf;
int day;
char *week; // added for name of week
day = time_info.day + 1;
/* added if to get name of week */
if (day >= 1 && day <= 10) week = "Firstride";
else if (day >= 11 && day <= 20) week = "Secondride";
else if (day >= 21 && day <= 30) week = "Thirdride";
/* end of my added if */
if ( day > 4 && day < 20 ) suf = "th";
else if ( day % 10 == 1 ) suf = "st";
else if ( day % 10 == 2 ) suf = "nd";
else if ( day % 10 == 3 ) suf = "rd";
else suf = "th";
set_char_color( AT_YELLOW, ch );
ch_printf( ch,
"It is %d o'clock %s, %s of , week, the Month of %s.\n\r" //I changed this line to try and get
// what I wanted to display. Probably goofed up.
"The mud started up at: %s\r"
"The system time (E.S.T.): %s\r"
"Next Reboot is set for: %s\r",
(time_info.hour % 12 == 0) ? 12 : time_info.hour % 12,
time_info.hour >= 12 ? "pm" : "am",
day_name[day % 10], //Here, I changed the day from 7 to 10
day, suf,
month_name[time_info.month],
str_boot_time,
(char *) ctime( ¤t_time ),
reboot_time
);
return;
}
In db.c I made changes:
/*
* Set time and weather.
*/
{
long lhour, lday, lmonth;
if(time_info.month >= 12) // changed from 17 to 12
{
time_info.month = 0;
time_info.year++;
}
return;
}
It compiled okay, and the mud boots. I can log in, so I did not screw it up entirely. But I did screw up do_time some way. If I try to get the time, the mud crashes. I still am trying to understand gdb, so maybe after I get a handle on that it will help. But I am trying to learn C from this forum and a book I have(the book is actually C++) so it is probably something I will need to understand before I can fix it.
If anybody can see my mistake, I would appreciate any advice. Thanks.
Gadush
Well, a quick test with gdb reveals the problem is indeed where you thought. I only had to type in 3 things to establish that (bt, f 4, list)...
(gdb) bt
#0 0x4207a6db in strlen () from /lib/tls/libc.so.6
#1 0x420477ed in vfprintf () from /lib/tls/libc.so.6
#2 0x420645fc in vsprintf () from /lib/tls/libc.so.6
#3 0x080c0468 in ch_printf(char_data*, char*, ...) (ch=0x857a9f0,
fmt=0x8195520 "It is %d o'clock %s, %s of , week, the Month of %s.\n\rThe mud started up at: %s\rThe system time (E.S.T.): %s\rNext Reboot is set for: %s\r") at comm.c:2962
#4 0x08059d83 in do_time(char_data*, char*) (ch=0x857a9f0, argument=0xbfffe614 "") at act_info.c:1789
#5 0x08100dbb in interpret(char_data*, char*) (ch=0x857a9f0, argument=0xbfffe614 "") at interp.c:738
#6 0x080baebd in game_loop() () at comm.c:738
#7 0x080ba27e in main (argc=1, argv=0xbfffeb14) at comm.c:322
#8 0x420156a4 in __libc_start_main () from /lib/tls/libc.so.6
(gdb) f 4
#4 0x08059d83 in do_time(char_data*, char*) (ch=0x857a9f0, argument=0xbfffe614 "") at act_info.c:1789
1789 ch_printf( ch,
(gdb) list
1784 else if ( day % 10 == 2 ) suf = "nd";
1785 else if ( day % 10 == 3 ) suf = "rd";
1786 else suf = "th";
1787
1788 set_char_color( AT_YELLOW, ch );
1789 ch_printf( ch,
1790 "It is %d o'clock %s, %s of , week, the Month of %s.\n\r"
// I changed this line to try and get
1791 // what I wanted to display. Probably goofed up.
1792 "The mud started up at: %s\r"
1793 "The system time (E.S.T.): %s\r"
1794 "Next Reboot is set for: %s\r",
1795
1796 (time_info.hour % 12 == 0) ? 12 : time_info.hour % 12,
1797 time_info.hour >= 12 ? "pm" : "am",
1798 day_name[day % 10], //Here, I changed the day from 7 to 10
1799 day, suf,
1800 month_name[time_info.month],
1801 str_boot_time,
1802 (char *) ctime( ¤t_time ),
1803 reboot_time
1804 );
1805
1806 return;
1807 }
Your problem is the printf string. To not have a crash the replacement things (%d, %s etc.) need to match up with what you are actually supplying.
Disregarding the other words, you are trying to get expanded:
%d %s %s %s %s %s %s
(ie. 1 number, 6 strings)
However what you are supplying is:
(number) (time_info.hour % 12 == 0) ? 12 : time_info.hour % 12, (string) time_info.hour >= 12 ? "pm" : "am", (string) day_name[day % 10], //Here, I changed the day from 7 to 10 (number) day, (string) suf, (string) month_name[time_info.month], (string) str_boot_time, (string) (char *) ctime( ¤t_time ), (string) reboot_time
Thanks for pointing me in the right direction, Nick. This is really a learning experience for me, and I love it. You see, I had no idea really that the block below my printf was the 'map' for what got used when in the order. After your post I looked at the original act_info and finally grasped what you were saying. Heh. So I commented out the unused 'day' and added my 'week' in the right order. I had to tweak my actual output a few times, but now I've got it working great.
It is 9 o'clock am, the second day of Thirdride,the Month of Nightal.
The mud started up at: Sun Jan 25 19:28:00 2004
The system time (E.S.T.): Sun Jan 25 19:30:04 2004
Next Reboot is set for: Tue Jan 27 06:00:00 2004
Thanks very much. BTW, this really makes it obvious to me that I have to learn to use gdb.
I have an other problem with months and days.
I've changed a few things in act_info.c at the do_time function, for this:
void do_time( CHAR_DATA *ch, char *argument )
{
extern char str_boot_time[];
//extern char reboot_time[];
char *suf;
int day;
day = time_info.day + 1;
suf = ".";
set_char_color( AT_YELLOW, ch );
ch_printf( ch,
"%d o'clock, day of %s, %d%s day from month of %s.\n\r"
"MUD has started: %s\r",
time_info.hour,
day_name[day % 7],
day, suf,
month_name[time_info.month],
str_boot_time);
return;
}
(and I've changed the names of days and months)
And I start the MUD, I type 'date' and it writes out: 5710048 o'clock, day of ‰ì]ÃEnd_timer: bad stime., 10278264šâ day from month of øíœ.
MUD has started: …àëÿ‰$è
What have I done wrong?
(I've removed the am/pm and st/nd/th and some of the data for write)
I'm not sure exactly what it is you were trying to do, but I'm assuming you want it to go by a 24-hour clock instead of 12-hour. Change 'time_info.hour' to 'time_info.hour % 24' and it should work fine.