ID:195097
 
//Title: Time Preprocessor Macros
//Credit to: Jtgibson
//Contributed by: Jtgibson


/*
This is an *extremely* useful set of aliases that allows you to specify time in
your code as actual words rather than arbitrary figures. Internally these words
are converted into ticks for BYOND to interpret.

Rather than typing:
var/one_day = 864000 //eight-hundred-and-sixty-four-thousand whats?
Why not type:
var/one_day = 1 DAY
Or:
var/one_day = 24 HOURS
Or:
var/one_day = 1440 MINUTES
Or even:
var/one_day = 86400 SECONDS
Or, heck, if you really wanted to, even:
var/one_day = 864000 TICKS

This set of definitions allows all of that. Basically, all it does is define
constants that make your life easier by allowing you to specify exact units
rather than expressing everything as a plain number of ticks.
*/




#define DAYS *864000
#define DAY *864000
#define HOURS *36000
#define HOUR *36000
#define MINUTES *600
#define MINUTE *600
#define SECONDS *10
#define SECOND *10
#define TICKS *1
#define TICK *1
#define MILLISECONDS /100
#define MILLISECOND /100


///*
//Testing code/sample implementation

mob/verb/ticks_in_2_secs()
usr << "Number of ticks in two seconds:"
usr << 2 SECONDS
usr << "Number of ticks in a day:"
usr << 1 DAY

mob/verb/brief_delay()
usr << "Waiting 5 seconds..."
sleep(5 SECONDS)
usr << "Hello world!"

mob/verb/random_delay()
usr << "Waiting for random time..."

sleep(rand(1,10) SECONDS)
//This is NOT the same as
// sleep(rand(1, 10 SECONDS))
//but the latter might actually be more useful!

usr << "Hello world!"

mob/verb/countdown()
usr << "Counting down!"
spawn(1 SECOND) usr << "Five!" //You can use either "SECOND" or "SECONDS"
spawn(2 SECONDS) usr << "Four!"
spawn(3 SECONDS) usr << "Three!"
spawn(4 SECONDS) usr << "Two!"
spawn(5 SECONDS) usr << "One!"
spawn(6 SECONDS) usr << "Ignition!"
spawn(7 SECONDS) usr << "Blast-off!"

//*/