Register forum user name Search FAQ

Gammon Forum

Notice: Any messages purporting to come from this site telling you that your password has expired, or that you need to verify your details, confirm your email, resolve issues, making threats, or asking for money, are spam. We do not email users with any such messages. If you have lost your password you can obtain a new one by using the password reset link.

Due to spam on this forum, all posts now need moderator approval.

 Entire forum ➜ SMAUG ➜ SMAUG coding ➜ Changing month and day names

Changing month and day names

It is now over 60 days since the last post. This thread is closed.     Refresh page


Posted by Gadush   (92 posts)  Bio
Date Sun 25 Jan 2004 03:53 AM (UTC)

Amended on Sun 25 Jan 2004 04:25 AM (UTC) by Gadush

Message
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
Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #1 on Sun 25 Jan 2004 05:10 AM (UTC)
Message
Hmm, makes me wonder what time_info.month has in it, as that controls the indexing into the month name array.

Perhaps post your modified function, maybe you have changed something that had an effect you didn't expect.

You could use gdb to put a breakpoint in that function and take a look. I did a length post about using gdb recently.

Also look in time_update in update.c. If you change the size of the months you may need to fiddle with that.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Gadush   (92 posts)  Bio
Date Reply #2 on Sun 25 Jan 2004 12:59 PM (UTC)

Amended on Sun 25 Jan 2004 01:01 PM (UTC) by Gadush

Message
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
Top

Posted by Gadush   (92 posts)  Bio
Date Reply #3 on Sun 25 Jan 2004 02:44 PM (UTC)
Message
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( &current_time ),
reboot_time
);

return;
}


In db.c I made changes:
/*
* Set time and weather.
*/
{
long lhour, lday, lmonth;

log_string("Setting time and weather");

lhour = (current_time - 650336715)
/ (PULSE_TICK / PULSE_PER_SECOND);
time_info.hour = lhour % 24;
lday = lhour / 24;
time_info.day = lday % 30; //changed from 35
lmonth = lday / 30; //changed from 35
time_info.month = lmonth % 12; //changed from 17
time_info.year = lmonth / 12; //changed from 17

if ( time_info.hour < 5 ) time_info.sunlight = SUN_DARK;
else if ( time_info.hour < 6 ) time_info.sunlight = SUN_RISE;
else if ( time_info.hour < 19 ) time_info.sunlight = SUN_LIGHT;
else if ( time_info.hour < 20 ) time_info.sunlight = SUN_SET;
else time_info.sunlight = SUN_DARK;

/*
weather_info.change = 0;
weather_info.mmhg = 960;
if ( time_info.month >= 7 && time_info.month <=12 )
weather_info.mmhg += number_range( 1, 50 );
else
weather_info.mmhg += number_range( 1, 80 );

if ( weather_info.mmhg <= 980 ) weather_info.sky = SKY_LIGHTNING;
else if ( weather_info.mmhg <= 1000 ) weather_info.sky = SKY_RAINING;
else if ( weather_info.mmhg <= 1020 ) weather_info.sky = SKY_CLOUDY;
else weather_info.sky = SKY_CLOUDLESS;
*/
}


in update.c Changed a small thing:

void time_update()
{
AREA_DATA *pArea;
DESCRIPTOR_DATA *d;
WEATHER_DATA *weath;

switch(++time_info.hour)
{
case 5:
case 6:
case 12:
case 19:
case 20:
for(pArea = first_area; pArea;
pArea = (pArea == last_area) ? first_build : pArea->next)
{
get_time_echo(pArea->weather);
}

for(d = first_descriptor; d; d = d->next)
{
if(d->connected == CON_PLAYING &&
IS_OUTSIDE(d->character) &&
IS_AWAKE(d->character))
{
weath = d->character->in_room->area->weather;
if(!weath->echo)
continue;
set_char_color(weath->echo_color,
d->character);
ch_printf(d->character, weath->echo);
}
}
break;
case 24:
time_info.hour = 0;
time_info.day++;
break;
}

if(time_info.day >= 30)
{
time_info.day = 0;
time_info.month++;
}




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
Top

Posted by Nick Gammon   Australia  (23,173 posts)  Bio   Forum Administrator
Date Reply #4 on Sun 25 Jan 2004 08:54 PM (UTC)

Amended on Sun 25 Jan 2004 08:57 PM (UTC) by Nick Gammon

Message
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( &current_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( &current_time ),
(string) reboot_time

(ie. 1 number, 2 strings, 1 number, 6 strings)

Things have to agree, or it will crash.

- Nick Gammon

www.gammon.com.au, www.mushclient.com
Top

Posted by Gadush   (92 posts)  Bio
Date Reply #5 on Sun 25 Jan 2004 11:36 PM (UTC)
Message
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.

Gadush
Top

Posted by Necromancer   Hungary  (3 posts)  Bio
Date Reply #6 on Sat 27 Mar 2004 10:29 AM (UTC)

Amended on Sat 27 Mar 2004 10:31 AM (UTC) by Necromancer

Message
Hi everyone!

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)

Thanks in advance: Viktor T. from Hungary

(and sorry for typing and grammar mistakes)
Top

Posted by Kris   USA  (198 posts)  Bio
Date Reply #7 on Mon 29 Mar 2004 07:42 PM (UTC)
Message
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.
Top

Posted by Necromancer   Hungary  (3 posts)  Bio
Date Reply #8 on Tue 30 Mar 2004 05:34 AM (UTC)
Message
Yes, I've tried it, and it works.

Thank you very much!
Top

The dates and times for posts above are shown in Universal Co-ordinated Time (UTC).

To show them in your local time you can join the forum, and then set the 'time correction' field in your profile to the number of hours difference between your location and UTC time.


30,391 views.

It is now over 60 days since the last post. This thread is closed.     Refresh page

Go to topic:           Search the forum


[Go to top] top

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.