///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// Environmental Control Plug-In (Roman Calendar Settings) Scripted by Mordaunt aka Drogyn/Mordrogyn
// 
// This is designed for use with my Environmental Script.
// This is NOT a complete "standalone script" rather a "pair" of different settings you can 
// copy/paste into my original script which will enable you to run it using either the
// Roman 10 month calendar, or Roman 12 month calendar.
//
// Documentation used to create this addition can be located @
//	http://webexhibits.org/calendars/calendar-roman.html
//
// Because the moon cycle is set (as near as I can get it) and doesn't vary as the real one does, 
// I have used the "fixed" length months as documented.
//
// The Date will look funky, partly because it's in roman numberals (date & year) and partly because the date of each month
// isn't actually the date, but the days until the next "important" day.
//
// Kalends = 	1st of the month, count down to this displayed day after Ides
// Ides = 	Day of full moon (originally) 15th (or 13th if month has less that 31 days), 
//		count down to this displayed day after Nones
// Nones = 	7th (or 5th if month has less than 31 days) count down to this displayed day after Kalends.
//
// The day before one of the above dates will always display as Pridie, meaning... the day before dur :P
//
// Installation: 	Make sure you have a backup copy of the original script, just incase
//			You're going to need to replace the original defs, with the corresponding ones
//			for the setting you want to use, & replace the f_time_keeper function with the one here.
//			(that's the simple part)
//
// If you do not want the roman style dating & Roman numerals, DO NOT do this next part:
//
//			Then you need to head down to where the date function is situated and locate the:
//			cal_adj_bckwds, cal_adj_fwds & cal_today functions and replace the sysmessage line that appears BEFORE 
//			[FUNCTION f_dl_minus] with the section below marked as "Insert"
//			And that should be it, no when you do .date you should be given the date in latin, according
//			to which ever roman calendar you selected.
//	
// Original Settings:
//
//			You MUST turn off leap years, if activated (10 mnth calendar doesn't have them, 12 mnth runs differently)
//			Technically there is no day called Friday, but it will still run if you have this on.
//			Also Halloween wil not work w/ 10 mnth calendar, as October doesn't have 31 days there.
//			You "can" use Britannian Calendar but the RL lunar cycle would be more accurate.
//
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
// defnames required for BOTH calendar settings:

//Days
//Yes they're letters!
day_1 A 
day_2 B
day_3 C
day_4 D
day_5 E
day_6 F
day_7 G
day_8 H

//Roman Numerals, used for date and year
units_1 I
units_2 II 
units_3 III
units_4 IV
units_5 V
units_6 VI
units_7 VII
units_8 VIII
units_9 IX

tens_1 X
tens_2 XX
tens_3 XXX
tens_4 XL
tens_5 L
tens_6 LX
tens_7 LXX
tens_8 LXX
tens_9 XC

hundreds_1 C
hundreds_2 CC
hundreds_3 CCC
hundreds_4 CD
hundreds_5 D
hundreds_6 DC
hundreds_7 DCC
hundreds_8 DCCC
hundreds_9 CM

thousands_1 M
thousands_2 MM

//Insert 
call roman_year
if  (<eval <var0.date>> >13) && (<eval <strarg <def.month_<eval <var0.month>>>>> <31) || (<eval <var0.date>> >15) && (<eval <strarg <def.month_<eval <var0.month>>>>>==31)   
	call kalends <local.date>
	if (<dlocal.countdown> == 1)
		sysmessage <def.day_<eval <var0.day>>> Kalends <strarg <streat <def.month_<eval <var0.month>>>>> <local.year>
	elif (<dlocal.countdown> < 10)
		sysmessage <def.day_<eval <var0.day>>> <QVAL (<eval <local.countdown>>==2)? Pridie:ante diem <def.units_<eval <local.countdown>>>> Kalends <strarg <streat <def.month_<eval <var0.month>>>>> <local.year>
	else 
		sysmessage <def.day_<eval <var0.day>>> ante diem <def.tens_<strsub 0 1 <eval <local.countdown>>>><def.units_<strsub 1 1 <eval <local.countdown>>>> Kalends <strarg <streat <def.month_<eval <var0.month>>>>> <local.year>
	endif 
	return 1
elif (<eval <var0.date>> >5) && (<eval <strarg <def.month_<eval <var0.month>>>>> <31) || (<eval <var0.date>> >7) && (<eval <strarg <def.month_<eval <var0.month>>>>>==31)   
	call ides <local.date>
	if (<dlocal.countdown> == 1)
		sysmessage <def.day_<eval <var0.day>>> Ides <strarg <streat <def.month_<eval <var0.month>>>>> <local.year>
	elif (<dlocal.countdown> < 10)
		sysmessage <def.day_<eval <var0.day>>> <<QVAL (<eval <local.countdown>>==2)? Pridie:ante diem <def.units_<eval <local.countdown>>>> Ides <strarg <streat <def.month_<eval <var0.month>>>>> <local.year>
	else 
		sysmessage <def.day_<eval <var0.day>>> ante diem <def.tens_<strsub 0 1 <dlocal.countdown>>><def.units_<strsub 1 1 <dlocal.countdown>>> Ides <strarg <streat <def.month_<eval <var0.month>>>>> <local.year>
	endif
	return 1
else
	call nones <local.date>
	if (<dlocal.countdown> == 1)
		sysmessage <def.day_<eval <var0.day>>> Nones <strarg <streat <def.month_<eval <var0.month>>>>> <local.year>
	elif (<dlocal.countdown> < 10)
		sysmessage <def.day_<eval <var0.day>>> <QVAL (<eval <local.countdown>>==2)? Pridie:ante diem <def.units_<eval <local.countdown>>>> Nones <strarg <streat <def.month_<eval <var0.month>>>>> <local.year>
	else 
		sysmessage <def.day_<eval <var0.day>>> ante diem <def.tens_<strsub 0 1 <dlocal.countdown>>><def.units_<strsub 1 1 <dlocal.countdown>>> Nones <strarg <streat <def.month_<eval <var0.month>>>>> <local.year>
	endif
	return 1
endif
 
[FUNCTION kalends]
local.countdown=<eval (<strarg <def.month_<eval <var0.month>>>>-<eval <eval <var0.date>>-1>)>
return <local.countdown>

[FUNCTION ides]
<QVAL (<eval <strarg <def.month_<eval <var0.month>>>>>==31)? local.countdown=<eval (15-<eval <var0.date>>)>:local.countdown=<eval (13-<eval <var0.date>>)>>
return <local.countdown>


[FUNCTION nones]
<QVAL (<eval <strarg <def.month_<eval <var0.month>>>>>==31)? local.countdown=<eval (7-<eval <var0.date>>)>:local.countdown=<eval (5-<eval <var0.date>>)>>
return <local.countdown>

[function roman_year]
if (<eval <var0.year>> < 10)
	local.year=<def.units_<eval <var0.year>>>
elif (<eval <var0.year>> > 9) && (<eval <var0.year>> < 100)
	local.year=<def.tens_<strsub 0 1 <eval <var0.year>>>><def.units_<strsub 1 1 <eval <var0.year>>>>
elif (<eval <var0.year>> > 99) && (<eval <var0.year>> < 1000)
	local.year=<def.hundreds_<strsub 0 1 <eval <var0.year>>>><def.tens_<strsub 1 1 <eval <var0.year>>>><def.units_<strsub 2 1 <eval <var0.year>>>>
else
	local.year=<def.thousands_<strsub 0 1 <eval <var0.year>>>><def.hundreds_<strsub 1 1 <eval <var0.year>>>><def.tens_<strsub 2 1 <eval <var0.year>>>><def.units_<strsub 3 1 <eval <var0.year>>>>
endif
return <local.year>
//End insert
////////////////////////////////////////////////////////////////////////////////////////////
// Roman 10 month Calendar settings: ONLY 304 DAYS PER YEAR
////////////////////////////////////////////////////////////////////////////////////////////
month_1 31 Martius 12.0 
month_2 30 Aprilis 15.0 
month_3 31 Maius 20.0 
month_4 30 Junius 30.0 
month_5 31 Quintilis 35.0 
month_6 30 Sextilis 30.0 
month_7 30 September 30.0 
month_8 31 October 20.0 
month_9 30 November 15.0 
month_10 30 December 12.0 

//TIME KEEPER SETTINGS
mins_per_hour 60
hours_per_day 24
days_per_week 8
months_per_year 10

//Note there is NO leap year setting for this calendar, so if you have it set TURN IT OFF
//This is the most BASIC timekeeper needed to run this calendar, all holidays e.t.c.. are taken out.
//If you want them, re-add them.
[FUNCTION f_time_keeper]
var0.mins +=<ddef.speed>
var0.lunar +=<ddef.speed> // Trammel
if (<eval <var0.lunar>> >= 5310)
	var0.phase +=1
	var0.lunar =1
endif

if (<eval <var0.mins>> == <ddef.mins_per_hour>)
	var0.hours += 1
	var0.mins = 0 
elif (<eval <var0.mins>> > <ddef.mins_per_hour>)
	var0.hours += 1
	var0.mins = 0 
endif

if (<eval <var0.hours>>==<ddef.hours_per_day>) 
	var0.day += 1
	var0.date += 1
	var0.hours = 0 
	serv.newitem i_seasonal
	new.p 10,10
endif

if (<eval <var0.day>> > <ddef.days_per_week>)
	var0.day = 1
endif

if (<eval <var0.date>> > <eval <strarg <def.month_<eval <var0.month>>>>>)
	var0.date = 1
	var0.month += 1
endif

if (<eval <var0.month>> > <ddef.months_per_year>)
	var0.year += 1
	var0.month = 1
endif

///////////////////////////////////////////////////////////////////////////////////////////
//Roman 12 month Calendar settings 355 DAYS PER YEAR (+ LEAP MONTH EVERY OTHER YEAR)
///////////////////////////////////////////////////////////////////////////////////////////
// Works out at 366 days per year (averaged over 2 years) so only slightly out (1/4 day according to docs)

// A wierd one... runs an extra MONTH every other year, 
month_1 29 Januarius 12.0 
month_2 28 Februarius 15.0 
month_3 31 Martius 20.0 
month_4 29 Aprilis 20.0 
month_5 31 Maius 25.0 
month_6 29 Junius 33.0 
month_7 31 Quintilis 35.0 
month_8 29 Sextilis 35.0 
month_9 29 September 30.0 
month_10 31 October 20.0 
month_11 29 November 15.0 
month_12 29 December 12.0 

//Which is why I have continued the month count here! 
month_13 29 Januarius 12.0
month_14 23 Februarius 15.0 //<-- Yes there are only 23 days in this february, trust me!
month_15 27 Mercedonius 17.0  //<-- Here's that funky "leap month"
month_16 31 Martius 20.0
month_17 29 Aprilis 20.0
month_18 31 Maius 25.0
month_19 29 Junius 33.0
month_20 31 Quintilis 35.0
month_21 29 Sextilis 35.0
month_22 29 September 30.0
month_23 31 October 20.0
month_24 29 November 15.0
month_25 29 December 12.0

//TIME KEEPER SETTINGS
mins_per_hour 60
hours_per_day 24
days_per_week 8
months_per_year 25 //I know, logic dictates 12, but trust me, this way is so much easier

//This version of time keeper will take care of the problem with the months...
[FUNCTION f_time_keeper]
var0.mins +=<ddef.speed>
var0.lunar +=<ddef.speed> // Trammel
if (<eval <var0.lunar>> >= 5310)
	var0.phase +=1
	var0.lunar =1
endif

if (<eval <var0.mins>> == <ddef.mins_per_hour>)
	var0.hours += 1
	var0.mins = 0 
elif (<eval <var0.mins>> > <ddef.mins_per_hour>)
	var0.hours += 1
	var0.mins = 0 
endif

if (<eval <var0.hours>>==<ddef.hours_per_day>) 
	var0.day += 1
	var0.date += 1
	var0.hours = 0 
	serv.newitem i_seasonal
	new.p 10,10
endif

if (<eval <var0.day>> > <ddef.days_per_week>)
	var0.day = 1
endif

if (<eval <var0.date>> > <eval <strarg <def.month_<eval <var0.month>>>>>)
	if (<eval <var0.month>> != 12)
		var0.date = 1
		var0.month += 1
	else  
		if (<eval <var0.date>> > <eval <strarg <def.month_<eval <var0.month>>>>>)
			var0.date = 1
			var0.day = 1 //day resets to A for first day of new year
			var0.month += 1
			var0.year += 1 //add a year at middle January 1st
		endif
	endif
endif

//This section only adds a year every 25 months
if (<eval <var0.month>> > <ddef.months_per_year>)
	var0.year += 1
	var0.month = 1
	var0.day = 1
endif

//This section goes in the f_environ_calc function replacing the very end of the function before the f_light_manager section.
// It replaces the section that it matches so that you seasons can cope with the new calendar.
if (<eval <var0.month>> > 11) && (<eval <var0.month>> < 15) || (<eval <var0.month>> > 24)
	if (<dlocal.weatherchance> < <ddef.weather_winter>)
		if <def.storm_system>
			if (<dlocal.weatherchance> < <eval <ddef.weather_winter>/2>)
				call f_storm <dlocal.temp>
			else
				call f_weather <dlocal.temp>
			endif
		else
			call f_weather <dlocal.temp>
		endif
	else
		call f_dry
	endif
elif (<eval <var0.month>> > 8) && (<eval <var0.month>> < 12) || (<eval <var0.month>> > 21)
	if (<dlocal.weatherchance> < <ddef.weather_fall>)
		if <def.storm_system>
			if (<dlocal.weatherchance> < <eval <ddef.weather_fall>/2>)
				call f_storm <dlocal.temp>
			else
				call f_weather <dlocal.temp>
			endif
		else
			call f_weather <dlocal.temp>
		endif
	else
		call f_dry
	endif
elif (<eval <var0.month>> > 5) && (<eval <var0.month>> < 9) || (<eval <var0.month>> > 18)
	if (<dlocal.weatherchance> < <ddef.weather_summer>)
		if <def.storm_system>
			if (<dlocal.weatherchance> < <eval <ddef.weather_summer>/2>)
				call f_storm <dlocal.temp>
			else
				call f_weather <dlocal.temp>
			endif
		else
			call f_weather <dlocal.temp>
		endif
	else
		call f_dry
	endif
elif (<eval <var0.month>> > > 2) && (<eval <var0.month>> < 6) || (<eval <var0.month>> > 15)
	if (<dlocal.weatherchance> < <ddef.weather_spring>)
		if <def.storm_system>
			if (<dlocal.weatherchance> < <eval <ddef.weather_spring>/2>)
				call f_storm <dlocal.temp>
			else
				call f_weather <dlocal.temp>
			endif
		else
			call f_weather <dlocal.temp>
		endif
	else
		call f_dry
	endif
else
	if (<dlocal.weatherchance> < <ddef.weather_winter>)
		if <def.storm_system>
			if (<dlocal.weatherchance> < <eval <ddef.weather_winter>/2>)
				call f_storm <dlocal.temp>
			else
				call f_weather <dlocal.temp>
			endif
		else
			call f_weather <dlocal.temp>
		endif
	else
		call f_dry
	endif
endif