The Dawn Of Time
The Official Forums for the Dawn Of Time Mud Codebase
 
Log in Register FAQ Memberlist Search The Dawn Of Time Forum Index Goto the Official Dawn Website

An IC time calculator

 
Post new topic   Reply to topic    The Dawn Of Time Forum Index » Snippets
View previous topic :: View next topic  
Author Message
Trell



Joined: 28 Jun 2013
Posts: 49

PostPosted: Wed Jul 19, 2017 7:49 am    Post subject: An IC time calculator Reply with quote

This little function was rehashed together from the do_time() and update_daylight() functions in the code. What it does is it calculates what the IC time will be given a number of ooc hours in the future, so if you put in the command ictimecalculate 240 then it will tell you the IC date 10 ooc days from now.

First, at the top of act_info.cpp you need to add:
Code:

#include "ictime.h"


Then somewhere below, add this new function:
Code:

void do_ictimecalculate(char_data *ch, char *argument)
{
   TIME_INFO_DATA calc;
   const char *suf;
   int hours;
   
   int day;
   int month;
   int year;

   if (IS_NULLSTR(argument) || !is_number(argument)){
      ch->println("Syntax:  ictimecalculate <OOC Hours into the future>");
      return;
   }

   hours = atoi(argument);
   if (hours < 0){
      ch->println("You can't calculate into the past.");
      return;
   }

   hours *= (ICTIME_MINUTES_PER_HOUR/ICTIME_IRLSECS_PER_MINUTE);

   calc.minute = time_info.minute;
   calc.hour = time_info.hour;
   calc.day = time_info.day;
   calc.month = time_info.month;
   calc.year = time_info.year;

   //now advance calc time
   while (hours > 0)
   {
      ++calc.hour;

      if ( calc.hour == HOUR_MIDNIGHT )
      {
         calc.hour = 0;
         calc.day++;
      }

      if ( calc.day >= ICTIME_DAYS_PER_MONTH-1 )
      {
         calc.day = 0;
         calc.month++;
      }

      if ( calc.month >= ICTIME_MONTHS_PER_YEAR-1 )
      {
         calc.month = 0;
         calc.year++;
      }
      hours--;
   }

   day = calc.day+1;
   month = calc.month+1;
   year = calc.year;

   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";

   ch->printlnf("Date predicted: `W%d`S/`W%d`s/`W%d`x",day,month,year);
   ch->printlnf(
      "It will be %d o'clock %s, Day of %s, %d%s the Month of %s in the year %d AK.",
      (calc.hour % (ICTIME_HOURS_PER_DAY/2) == 0) ?
         (ICTIME_HOURS_PER_DAY/2) : calc.hour %(ICTIME_HOURS_PER_DAY/2),
      calc.hour >= (ICTIME_HOURS_PER_DAY/2) ? "pm" : "am",
      day_name[day % ICTIME_DAYS_PER_WEEK],
      day, suf,
      month_name[calc.month],
      calc.year);
   return;
}


And finally, don't forget to add lines to interp.h and interp.cpp for your new function. Then compile, reboot, and set up your new command in comedit.


Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    The Dawn Of Time Forum Index » Snippets All times are GMT + 13 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001-2005 phpBB Group
Theme created by Vjacheslav Trushkin