SHOVA, you probably found the part missing from your above code already, but for those following along at home...
You need to add a section of code in spawn_main which calls isBetweenMonths similar to the one in spawn_functions.
Here is a complete patch which does the Month change from SHOVA including the minor fixes and documentation. It also adds the ability to have the hours wrap which is something I wanted. They just went in together. The hours change allows you to have a child spawn from say 22 to 02 of the next day, useful late night activities.
(let's see if this formatting works - if not and there is interest I can try something else)
diff --git a/spawn_functions.nss b/spawn_functions.nss
index 4f69ac9..c9f28fc 100644
--- a/spawn_functions.nss
+++ b/spawn_functions.nss
@@ -245,6 +245,8 @@ void InitFlags(object oSpawn, string sSpawnName, string sSpawnTag)
int dfSpawnDayEnd = GetLocalInt(oModule, "df_SpawnDayEnd");
int dfSpawnHourStart = GetLocalInt(oModule, "df_SpawnHourStart");
int dfSpawnHourEnd = GetLocalInt(oModule, "df_SpawnHourEnd");
+ int dfSpawnMonthStart = GetLocalInt(oModule, "df_SpawnMonthStart");
+ int dfSpawnMonthEnd = GetLocalInt(oModule, "df_SpawnMonthEnd");
int dfWanderRange = GetLocalInt(oModule, "df_WanderRange");
int dfReturnHomeRange = GetLocalInt(oModule, "df_ReturnHomeRange");
int dfPCCheckDelay = GetLocalInt(oModule, "df_PCCheckDelay");
@@ -451,22 +453,53 @@ void InitFlags(object oSpawn, string sSpawnName, string sSpawnTag)
// Initialize Day/Hour Spawns
int nSpawnDayStart = GetFlagValue(sSpawnName, "DY", dfSpawnDayStart);
int nSpawnDayEnd = GetSubFlagValue(sSpawnName, "DY", "T", dfSpawnDayEnd);
+ if (nSpawnDayStart < 1 || nSpawnDayStart > 28) {
+ nSpawnDayStart = -1;
+ }
+ // TODO - day could be made to wrap into the next month
+ if (nSpawnDayEnd < 1 || nSpawnDayEnd > 28) {
+ nSpawnDayEnd = -1;
+ }
if (nSpawnDayEnd > nSpawnDayStart)
{
nSpawnDayEnd = -1;
}
+
int nSpawnHourStart = GetFlagValue(sSpawnName, "HR", dfSpawnHourStart);
int nSpawnHourEnd = GetSubFlagValue(sSpawnName, "HR", "T", dfSpawnHourEnd);
- if (nSpawnHourStart > nSpawnHourEnd)
- {
+ if (nSpawnHourStart < 0 || nSpawnHourStart > 23) {
+ nSpawnHourStart = -1;
+ }
+ if (nSpawnHourEnd < 0 || nSpawnHourEnd > 23) {
nSpawnHourEnd = -1;
}
+ // Hours now wrap so you can spwan between 22 and 2 and get 4 valid hours
+ //if (nSpawnHourStart > nSpawnHourEnd)
+ //f (nSpawnHourStart == nSpawnHourEnd)
+ //{
+ // nSpawnHourEnd = -1;
+ //}
+ int nSpawnMonthStart = GetFlagValue(sSpawnName, "MM", dfSpawnMonthStart);
+ int nSpawnMonthEnd = GetSubFlagValue(sSpawnName, "MM", "T", dfSpawnMonthEnd);
+ if (nSpawnMonthStart < 1 || nSpawnMonthStart > 12) {
+ nSpawnMonthStart = -1;
+ }
+ if (nSpawnMonthEnd < 1 || nSpawnMonthEnd > 12) {
+ nSpawnMonthEnd = -1;
+ }
+ // TODO - month > 12 could wrap to next year
+ if (nSpawnMonthStart > nSpawnMonthEnd)
+ {
+ nSpawnMonthEnd = -1;
+ }
// Record Day/Hour Spawns
SetLocalInt(oSpawn, "f_SpawnDayStart", nSpawnDayStart);
SetLocalInt(oSpawn, "f_SpawnDayEnd", nSpawnDayEnd);
SetLocalInt(oSpawn, "f_SpawnHourStart", nSpawnHourStart);
SetLocalInt(oSpawn, "f_SpawnHourEnd", nSpawnHourEnd);
+ SetLocalInt(oSpawn, "f_SpawnMonthStart", nSpawnMonthStart);
+ SetLocalInt(oSpawn, "f_SpawnMonthEnd", nSpawnMonthEnd);
// Initialize RandomWalk
int nRandomWalk = IsFlagPresent(sSpawnName, "RW");
@@ -1160,7 +1193,11 @@ int IsBetweenHours(int nCheckHour, int nHourStart, int nHourEnd)
{
if (nHourEnd > -1)
{
- if (nCheckHour >= nHourStart && nCheckHour <= nHourEnd)
+ if (nHourStart > nHourEnd) {
+ if (nCheckHour >= nHourStart || nCheckHour <= nHourEnd)
+ return TRUE;
+ }
+ else if (nCheckHour >= nHourStart && nCheckHour <= nHourEnd)
{
return TRUE;
}
@@ -1176,6 +1213,26 @@ int IsBetweenHours(int nCheckHour, int nHourStart, int nHourEnd)
return FALSE;
}
//
+// This Function Checks if nCheckMonth is Between Months
+int IsBetweenMonths(int nCheckMonth, int nMonthStart, int nMonthEnd) {
+ if (nMonthEnd > -1)
+ {
+ if (nCheckMonth >= nMonthStart && nCheckMonth <= nMonthEnd)
+ {
+ return TRUE;
+ }
+ }
+ else
+ {
+ if (nCheckMonth == nMonthStart)
+ {
+ return TRUE;
+ }
+ }
+
+ return FALSE;
+}
+
// This Function Pads an IntToString with 0s
string PadIntToString(int nInt, int nDigits)
@@ -3174,6 +3231,8 @@ int IsRestoreBlocked(object oSpawn, location lChildLoc, int iExpireTime,
int nSpawnDayEnd = GetLocalInt(oSpawn, "f_SpawnDayEnd");
int nSpawnHourStart = GetLocalInt(oSpawn, "f_SpawnHourStart");
int nSpawnHourEnd = GetLocalInt(oSpawn, "f_SpawnHourEnd");
+ int nSpawnMonthStart = GetLocalInt(oSpawn, "f_SpawnMonthStart");
+ int nSpawnMonthEnd = GetLocalInt(oSpawn, "f_SpawnMonthEnd");
// Initialize Child Lifespan
int nChildLifespanMax = GetLocalInt(oSpawn, "f_ChildLifespanMax");
@@ -3247,6 +3306,16 @@ int IsRestoreBlocked(object oSpawn, location lChildLoc, int iExpireTime,
}
}
+ // Check Against Specific Month(s) (_MMnn_)
+ if (nSpawnMonthStart > -1)
+ {
+ int nMonth = GetCalendarMonth();
+ if (IsBetweenMonths(nMonth, nSpawnMonthStart, nSpawnMonthEnd) == FALSE)
+ {
+ nSpawnBlock = TRUE;
+ }
+ }
+
// Check Lifespan (_CLnn_)
if (nChildLifespanMax > -1)
{
diff --git a/spawn_defaults.nss b/spawn_defaults.nss
index 2ed14b7..78d98eb 100644
--- a/spawn_defaults.nss
+++ b/spawn_defaults.nss
@@ -49,6 +49,11 @@ int nSpawnDayEnd = -1;
int nSpawnHourStart = -1;
int nSpawnHourEnd = -1;
+// MMn|Tn
+// SpawnMonth
+int nSpawnMonthStart = -1;
+int nSpawnMonthEnd = -1;
+
// RW|Rn
// RandomWalk
int nWanderRange = 0;
@@ -225,6 +230,8 @@ void SetGlobalDefaults()
SetLocalInt(oModule, "df_SpawnDayEnd", nSpawnDayEnd);
SetLocalInt(oModule, "df_SpawnHourStart", nSpawnHourStart);
SetLocalInt(oModule, "df_SpawnHourEnd", nSpawnHourEnd);
+ SetLocalInt(oModule, "df_SpawnMonthStart", nSpawnMonthStart);
+ SetLocalInt(oModule, "df_SpawnMonthEnd", nSpawnMonthEnd);
SetLocalInt(oModule, "df_WanderRange", nWanderRange);
SetLocalInt(oModule, "df_ReturnHomeRange", nReturnHomeRange);
SetLocalInt(oModule, "df_PCCheckDelay", nPCCheckDelay);
diff --git a/spawn__readme.nss b/spawn__readme.nss
index dd92e77..e69d094 100644
--- a/spawn__readme.nss
+++ b/spawn__readme.nss
@@ -191,7 +191,16 @@
// : Children are Despawned during Invalid Hours
// : Optional Flag: T00
// : Spawn from Hour HR00 to Hour T00
+// : Hours may wrap (e.g. HR22T02 will spawn from 10pm to 2 am of the next day)
+// : Interactions with DYXX flags may be interesting
//
+// MMn|Tn
+// : Spawn Month
+// : Spawn Only during Month MM01 to MM12
+// : Children are Despawned during Invalid Months
+// : Optional Flag: T00
+// : Spawn from Month MMXX to Month TXX
+///
// DO|D
// : Day Only
// : Only Spawns at Day