Time (script)

From Elanthipedia
Jump to: navigation, search
Time (script)
Category information
Front-end Genie
Author Majebrad

Converts IC to Real time and vice versa

#####################################################
#                                                   #
#                 Time - 7/27/2009                  #
#		         Maje			    #
#						    #
#####################################################
#
#	Converts IC to Real time and vice versa
#	All times are server (CST)
#
#	Note - Does not convert times prior to 1/1/1996
#
#	Things to Fix:
#	
#	Loss of 1 IC day per RL year
#
#	Changes:
#	
#	Fixed end of year wonkiness, now rolls over to new year properly
#	Added IC hour instead of leaving IC days with decimal values when going Real to IC
#	Added real hour time range when going IC to Real
#	
#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#

action setvar ICYear $1; setvar ICTotalDays $2; setvar ICHour 0 when ^It has been (\d+) years, (\d+) days since the Victory of Lanival the Redeemer
action setvar ICMonth $1 when ^It is the (\d+)th month of (.*) in the year of

action setvar RealMonth $1;setvar RealDay $2; setvar RealYear $3; setvar RealHour $4 when (\d+)/(\d+)/(\d+) (\d+)

setvar consICDay 192
setvar consICYear 345
setvar consICTotal 138206

setvar consRealMonth 1
setvar consRealDay 1
setvar consRealYear 1996
setvar consRealHour 0
setvar FudgeFactor 1537

setvar consJanLen 31
setvar consFebLen 28
setvar consMarchLen 31
setvar consAprilLen 30
setvar consMayLen 31
setvar consJuneLen 30
setvar consJulyLen 31
setvar consAugLen 31
setvar consSeptLen 30
setvar consOctLen 31
setvar consNovLen 30
setvar consDecLen 31

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#

Main:
gosub Input
gosub Convert
gosub Report
exit

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#

Input:

Input.Menu:
echo Enter the number for what you'd like to convert:
echo
echo 1. Convert IC time to Real time
echo 2. Convert Real time to IC time
matchre Input.IC 1
matchre Input.Real 2
matchwait

Input.IC:
setvar Input IC
echo Enter the in game time text:
echo
echo Example - It has been 394 years, 384 days since the Victory of Lanival the Redeemer.
matchre Input.Done Lanival the Redeemer
matchwait

Input.Real:
setvar Input Real
echo Enter the real time:
echo
echo Use military time without minutes - July 14th, 2009 6:00 pm...
echo Example - 7/14/2009 18
match Input.Done /
matchwait

Input.Done:
return

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#

Convert:
if "%Input" == "IC" then gosub Convert.ICtoReal
else gosub Convert.RealtoIC
return

Convert.ICtoReal:
gosub Convert.ICtoReal.CalcICDays
gosub Convert.ICtoReal.CalcRealDays
gosub Convert.ICtoReal.FindYear
gosub Convert.ICtoReal.FindMonth
return

Convert.ICtoReal.CalcICDays:
evalmath Days.Current %ICTotalDays + %ICYear * 400
evalmath numDays %Days.Current - %consICTotal
return

Convert.ICtoReal.CalcRealDays:
setvar Days.Real.Part %numDays
math Days.Real.Part modulus 4
evalmath Days.Real %numDays / 4
return

Convert.ICtoReal.FindYear:
setvar tempYear 1996
setvar tempDays %Days.Real
gosub Convert.ICtoReal.FindYear.CalcYear
setvar RealYear %tempYear
setvar RealDay %tempDays
return

Convert.ICtoReal.FindYear.CalcYear:
if %tempDays < 365 then return
setvar tempLeap %tempYear
math tempLeap modulus 4
if %tempLeap == 0 then {
	evalmath tempDays %tempDays - 366
}
else {
	evalmath tempDays %tempDays - 365
}
math tempYear add 1
gosub Convert.ICtoReal.FindYear.CalcYear
return

Convert.ICtoReal.FindMonth:
setvar tempMonth 1
if %tempDays >= %consJanLen then {
	evalmath tempDays %tempDays - %consJanLen
	math tempMonth add 1
}
if %tempDays >= %consFebLen then {
	setvar tempLeap %RealYear
	math tempLeap modulus 4
	if %tempLeap == 0 then {
		evalmath tempDays %tempDays - %consFebLen - 1
	}
	else {
		evalmath tempDays %tempDays - %consFebLen
	}
	math tempMonth add 1
}
if %tempDays >= %consMarchLen then {
	evalmath tempDays %tempDays - %consMarchLen
	math tempMonth add 1
}
if %tempDays >= %consAprilLen then {
	evalmath tempDays %tempDays - %consAprilLen
	math tempMonth add 1
}
if %tempDays >= %consMayLen then {
	evalmath tempDays %tempDays - %consMayLen
	math tempMonth add 1
}
if %tempDays >= %consJuneLen then {
	evalmath tempDays %tempDays - %consJuneLen
	math tempMonth add 1
}
if %tempDays >= %consJulyLen then {
	evalmath tempDays %tempDays - %consJulyLen
	math tempMonth add 1
}
if %tempDays >= %consAugLen then {
	evalmath tempDays %tempDays - %consAugLen
	math tempMonth add 1
}
if %tempDays >= %consSeptLen then {
	evalmath tempDays %tempDays - %consSeptLen
	math tempMonth add 1
}
if %tempDays >= %consOctLen then {
	evalmath tempDays %tempDays - %consOctLen
	math tempMonth add 1
}
if %tempDays >= %consNovLen then {
	evalmath tempDays %tempDays - %consNovLen
	math tempMonth add 1
}
if %tempDays >= %consDecLen then {
	evalmath tempDays %tempDays - %consDecLen
	math tempMonth add 1
}
setvar RealMonth %tempMonth
setvar tempRealDay %tempDays
math tempDays modulus 1
evalmath RealDay %tempRealDay - %tempDays
if %tempDays < .25 then setvar RealHour 12 am to 6 am
if %tempDays >= .25 and %tempDays < .5 then setvar RealHour 6 am to 12 am
if %tempDays >= .5 and %tempDays < .75 then setvar RealHour 12 am to 6 pm
if %tempDays >= .75 then setvar RealHour 6 pm to 12 pm
return

Convert.RealtoIC:
setvar numDays 0
setvar tempYear %consRealYear
setvar tempMonth %consRealMonth
setvar tempDay %consRealDay
gosub Convert.RealtoIC.CalcRealYears
gosub Convert.RealtoIC.CalcRealMonths
gosub Convert.RealtoIC.CalcRealHours
gosub Convert.RealtoIC.CalcICTime
return

Convert.RealtoIC.CalcRealYears:
if %tempYear < %RealYear then {
	setvar tempLeap %tempYear
	math tempLeap modulus 4
	if %tempLeap == 0 then {
		evalmath numDays %numDays + 366 * 4
	}
	else {
		evalmath numDays %numDays + 365 * 4
	}
	math tempYear add 1
	gosub Convert.RealtoIC.CalcRealYears
}
return

Convert.RealtoIC.CalcRealMonths:
if %tempMonth < %RealMonth then {
	if %tempMonth == 1 then {
		evalmath numDays %numDays + %consJanLen * 4
	}
	if %tempMonth == 2 then {
		setvar tempLeap %RealYear
		math tempLeap modulus 4
		if %tempLeap == 0 then {
			evalmath numDays %numDays + (%consFebLen + 1) * 4
		}
		else {
			evalmath numDays %numDays + %consFebLen * 4
		}
	}
	if %tempMonth == 3 then {
		evalmath numDays %numDays + %consMarchLen * 4
	}
	if %tempMonth == 4  then {
		evalmath numDays %numDays + %consAprilLen * 4
	}
	if %tempMonth == 5 then {
		evalmath numDays %numDays + %consMayLen * 4 
	}
	if %tempMonth == 6 then {
		evalmath numDays %numDays + %consJuneLen * 4
	}
	if %tempMonth == 7 then {
		evalmath numDays %numDays + %consJulyLen * 4
	}
	if %tempMonth == 8 then {
		evalmath numDays %numDays + %consAugLen * 4
	}
	if %tempMonth == 9 then {
		evalmath numDays %numDays + %consSeptLen * 4
	}
	if %tempMonth == 10 then {
		evalmath numDays %numDays + %consOctLen * 4
	}
	if %tempMonth == 11 then {
		evalmath numDays %numDays + %consNovLen * 4
	}
	math tempMonth add 1
	gosub Convert.RealtoIC.CalcRealMonths
}
else {
	evalmath numDays %numDays + %RealDay * 4
}
return

Convert.RealtoIC.CalcRealHours:
evalmath numDays %numDays + (%RealHour / 6) - 2
return

Convert.RealtoIC.CalcICTime:
evalmath numDays %numDays + (400 - %consICDay)
evalmath tempYear %numDays / 400
math numDays modulus 400
evalmath tempYear %tempYear - (%numDays / 400)
evalmath ICYear %tempYear + %consICYear
evalmath ICTotalDays floor(%numDays)
math numDays modulus 1
evalmath ICHour round(24 * %numDays)
return

#~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~#

Report:
gosub Report.GetMonth
gosub Report.Print
return

Report.GetMonth:
evalmath tempMonth floor((%ICTotalDays / 40))
setvar numDays %ICTotalDays
math numDays modulus 40
evalmath ICDay floor(%numDays)
if %tempMonth == 0 then setvar ICMonth Akroeg the Ram
if %tempMonth == 1 then setvar ICMonth Ka'len the Sea Drake
if %tempMonth == 2 then setvar ICMonth Lirisa the Archer
if %tempMonth == 3 then setvar ICMonth Shorka the Cobra
if %tempMonth == 4 then setvar ICMonth Uthmor the Giant
if %tempMonth == 5 then setvar ICMonth Arhat the Fire Lion
if %tempMonth == 6 then setvar ICMonth Moliko the Balance
if %tempMonth == 7 then setvar ICMonth Skullcleaver the Dwarven Axe
if %tempMonth == 8 then setvar ICMonth Dolefaren the Brigantine
if %tempMonth >= 9 then setvar ICMonth Nissa the Maiden
return

Report.Print:
echo IC Time: %ICDay %ICMonth (day %ICTotalDays) %ICYear AV - %ICHour o'clock (military)
echo Real Time: %RealMonth/%RealDay/%RealYear , %RealHour
return




Personal tools
SUPPORT ELANTHIPEDIA