Files
Anphillia_PRC8/_module/nss/sundial.nss
Jaysyn904 28cdb617b3 Initial commit
Adding all of the current content for Anphillia Unlimited.
2024-01-04 07:49:38 -05:00

95 lines
3.4 KiB
Plaintext

//::///////////////////////////////////////////////
//:: FileName: tr_sundial
//:://////////////////////////////////////////////
/*
This scipt was inspired by Dscaper (craig [at] derby.co.uk)
and his sundial "ds_global_sdial".
Its does mostly the same, meaning it shows the time in
hh:mm[am/pm] style for daytime and hh[am/pm] for dawn and dusk.
It will not show the time at night.
But nevertheless, I rewrote the whole script and added one feature:
It now adapts to the "minutes per hour" setting (=gamespeed) of the module.
The original sundial didn't do that, it only displayed the correct time
with the default value "2 minutes per hour".
Attach to OnUsed event.
*/
//:://////////////////////////////////////////////
//:: Created By: Tobias Riegg
//:: Email: bunduki@spacerun.net
//:: Thanks to Alexander Broschell for his mental support ;-)
//:: Created On: 4th September 2002
//:://////////////////////////////////////////////
// custom function, returns the minutes _gametime_
int GetTimeMinuteGametime();
// custom function, used to convert an integer to a two digit string
string IntToStringFillUp(int number);
void main()
{
string sResult;
// check the daytime
if (GetIsNight())
{
sResult = "It is night, therefore you cannot tell the time.";
} else {
sResult = "It is now ";
// Get the hour gametime
int iHour = GetTimeHour();
string sMinute;
string sComment;
if (GetIsDawn())
{
sResult += "roughly ";
sComment = " You are not able to figure out the minutes, it is dawn.";
} else if (GetIsDusk())
{
sResult += "roughly ";
sComment = " You are not able to figure out the minutes, it is dusk.";
} else // Daytime
{
// Get the minutes gametime
int iMinute = GetTimeMinuteGametime();
// a sundial is not very acurate, only 0, 15, 30, 45 minutes will be displayed:
iMinute /= 15;
iMinute *= 15;
// this does makes sense, because of the datatype integer!!!
// using custom function, this converts integer to string
sMinute = IntToStringFillUp(iMinute);
}
// Generate AM / PM
string sDesignate = "am";
if (iHour >= 13) {
iHour = iHour - 12;
sDesignate = "pm";
}
string sHour = IntToString(iHour);
// assembling everything
sResult += sHour + ":" + sMinute + " " + sDesignate + "." + sComment;
}
// say it
SpeakString(sResult,TALKVOLUME_TALK);
}
int GetTimeMinuteGametime()
{
// Get the seconds per gamehour
// (default is 120, you can change it in edit -> module properties -> advanced)
float fSecondsPerHour = HoursToSeconds(1);
// Get the minutes and seconds passed in the current hour gametime and...
int iMinute = GetTimeMinute();
int iSecond = GetTimeSecond();
// ... calculate the bygone seconds in the current hour gametime
int iBygoneSeconds = iMinute*60 + iSecond;
// Calculate the bygone minutes gametime in the current hour
int iCurrentMinute = FloatToInt((iBygoneSeconds/fSecondsPerHour)*60);
return iCurrentMinute;
}
string IntToStringFillUp(int iNumber)
{
string sNumber = IntToString(iNumber);
// Append 0 if necessary
if (GetStringLength(sNumber) == 1)
{
sNumber = "0" + sNumber;
}
return sNumber;
}