playing_time in do_score

  • Fubar
  • Topic Author
  • Offline
  • Fresh Boarder
  • Fresh Boarder
More
5 years 5 months ago #1447 by Fubar
playing_time in do_score was created by Fubar
ACMD(do_score)
playing_time = *real_time_passed((time(0) - ch->player.time.logon) +
				  ch->player.time.played, 0);
  send_to_char(ch, "You have been playing for %d day%s, %d hour%s, %d minute%s, and %d second%s.\r\n",
     playing_time.day, playing_time.day == 1 ? "" : "s",
     playing_time.hours, playing_time.hours == 1 ? "" : "s",
     playing_time.minutes, playing_time.minutes == 1 ? "" : "s",
     playing_time.seconds, playing_time.seconds == 1 ? "" : "s");

Utils.c
struct time_info_data *real_time_passed(time_t t2, time_t t1)
{
  long secs;
  static struct time_info_data now;

  secs = t2 - t1;

  now.hours = (secs / SECS_PER_REAL_HOUR) % 24;	/* 0..23 hours */
  secs -= SECS_PER_REAL_HOUR * now.hours;

  now.day = (secs / SECS_PER_REAL_DAY);	/* 0..34 days  */
  /* secs -= SECS_PER_REAL_DAY * now.day; - Not used. */

  now.seconds = -1;
  now.minutes = -1;
  now.month = -1;
  now.year = -1;

  return (&now);
}

Now this shows

You have been playing for 0 days, 17 hours, -1 minutes, and -1 seconds.


But if I change the code to something other than above I get:

You have been playing for 0 days, 17 hours, 0 minutes, and 0 seconds.


Now i tried

now.seconds = secs;

But that gives me a huge number, way to huge.

Is there something I am missing.

Please Log in or Create an account to join the conversation.

  • zusuk
  • zusuk's Avatar
  • Offline
  • Gold Boarder
  • Gold Boarder
  • LuminariMUD Developer
More
5 years 5 months ago #1448 by zusuk
Replied by zusuk on topic playing_time in do_score
Hey Fubar:

Just at a quick glance, it seems like 'secs' is the total seconds, i.e. the total play-time.

So if that is the case, the utils.c function is subracting just the hours from the grand-total of playing time seconds.

If that's the case, you have the leftover of all the days, minutes AND seconds still lefter over in the 'secs' value.

I am most definiately not sure though, I am completely unfamiliar with that code :P

Website
www.luminariMUD.com

Main Game Port
luminariMUD.com:4100

Please Log in or Create an account to join the conversation.

  • Vatiken
  • Vatiken's Avatar
  • Offline
  • Administrator
  • Administrator
  • tbaMUD Programmer
More
5 years 5 months ago #1449 by Vatiken
Replied by Vatiken on topic playing_time in do_score
/** Calculate the REAL time passed between two time invervals.
 * @param t2 The later time.
 * @param t1 The earlier time.
 * @retval time_info_data The real hours, days, months and years passed between t2 and t1. */
struct time_info_data *real_time_passed(time_t t2, time_t t1)
{
  long secs;
  static struct time_info_data now;

  secs = t2 - t1;

  now.hours = (secs / SECS_PER_REAL_HOUR) % 24;	/* 0..23 hours */
  secs -= SECS_PER_REAL_HOUR * now.hours;

  now.day = (secs / SECS_PER_REAL_DAY) % 35;	/* 0..34 days  */
  secs -= SECS_PER_REAL_DAY * now.day;

  now.month = (secs / (SECS_PER_REAL_YEAR / 12)) % 12;  /* 0..11 months */
  secs -= (SECS_PER_REAL_YEAR / 12) * now.month;

  now.year = (secs / SECS_PER_REAL_YEAR);
  secs -= SECS_PER_REAL_YEAR * now.year;
  
  return (&now);
}

Tweaked the original real_time_passed() to include months and years, you should be able to take it further to include minutes and seconds if that's what you desire.

tbaMUD developer/programmer

Please Log in or Create an account to join the conversation.

  • Fubar
  • Topic Author
  • Offline
  • Fresh Boarder
  • Fresh Boarder
More
5 years 5 months ago - 5 years 5 months ago #1453 by Fubar
Replied by Fubar on topic playing_time in do_score
now.minutes = (secs / SECS_PER_REAL_HOUR) % 60;	/* 0..59 minutes */
  secs -= SECS_PER_REAL_HOUR * now.minutes;

It shows 53 so ill now in 7 minutes if it switches to days.

but seconds seem to be the hardest is there a way to edit the pfile to show if the months, days and years?
Last edit: 5 years 5 months ago by Fubar.

Please Log in or Create an account to join the conversation.

  • zusuk
  • zusuk's Avatar
  • Offline
  • Gold Boarder
  • Gold Boarder
  • LuminariMUD Developer
More
5 years 5 months ago - 5 years 5 months ago #1454 by zusuk
Replied by zusuk on topic playing_time in do_score
I did not really understand what you wanted, but I will take a guess :P

Just an important note though, I took a gander at the structure and it does not already have the 'minutes' element in it, so you would have to add it. Same with seconds. (in structs.h)
  now.minutes = (secs / SECS_PER_REAL_MIN) % 60;  /*  <------------- this what you want?  */
  secs -= SECS_PER_REAL_MIN * now.minutes;

...

  now.hours = (secs / SECS_PER_REAL_HOUR) % 24;	/* 0..23 hours */
  secs -= SECS_PER_REAL_HOUR * now.hours;

  now.day = (secs / SECS_PER_REAL_DAY) % 35;	/* 0..34 days  */
  secs -= SECS_PER_REAL_DAY * now.day;

  now.month = (secs / (SECS_PER_REAL_YEAR / 12)) % 12;  /* 0..11 months */
  secs -= (SECS_PER_REAL_YEAR / 12) * now.month;

  now.year = (secs / SECS_PER_REAL_YEAR);
  secs -= SECS_PER_REAL_YEAR * now.year;

Website
www.luminariMUD.com

Main Game Port
luminariMUD.com:4100
Last edit: 5 years 5 months ago by zusuk. Reason: didn't format code

Please Log in or Create an account to join the conversation.

Time to create page: 1.099 seconds