Journal Update: SLS2
I ran into an interesting problem with the SLS2 code. This is an issue that cropped up once in the prologue, in the barracks, and I didn't know how to fix it then, or what caused it. My solution at the time was simply to leave torch lights on instead of toggle them off during the day.
The issue is this: In interior areas with windows, I setup torches for night and allow daylight glow to fill a room during the day (so torches go out during the day and only the day glow lights the room). It's a little touch, but I like it, and it doesn't take long to setup.
This, however, becomes problematic when, if you are like me, you like to use lots of torches in an area. Too many light spheres per tile = bad.
My solution, since the beginning, has been to treat interior torch lights just like daylight glows - I use only a couple actual lights in the area, and let a singular controller turn those lights on or off. This is the prescribed method for daylight glow, and it works for torches as well. So instead of each individual light fixture handling the turn on/off for its own light, a single controller handles it for all torch lights in an area (and this is necessity, since every torch doesn't actually have its own light source).
The problem I experienced was, when I ran the module to ensure the lights worked in this area, I found that one of the daylight glows was on the torch light cycle. It would turn on when the torches were turned on, and off when the torches were turned off. It wasn't on the daylight glow cycle, as it should have been.
I checked and rechecked its tags, but it was just a copy of the other daylight glows...
This made me think that maybe this issue was related to the bug fix that kamal had made for SLS2.
I had never taken a close look at kamal's fix, so I wasn't exactly sure how it worked. So now was the time. Turns out, what kamal's fix does is look for the nearest light to a given fixture, and gets the lightTag from the fixture and puts it on the light (because lights lose their tags during a save-game). That's a smart fix - if every fixture has a light source. But my interiors don't operate that way. I usually have one light source for several fixtures, keeping the light spheres-per-tile under the magic 6. This fix was causing the daylight glow to get the torch light "lightTag", since the daylight glow was closer to a torch fixture. Hence why it ended up on the torch cycle instead of the daylight glow cycle.
My solution was to borrow kamal's idea: I put a "lightTag" local variable on the light source itself, and then add a small routine to the SLS2 code so that every light gets its tag reset:
void SetLightTags(object oArea)
{
object oObject = GetFirstObjectInArea(oArea);
while (oObject != OBJECT_INVALID)
{
int nType = GetObjectType(oObject);
// Only do this for Lights
if (nType==OBJECT_TYPE_LIGHT)
{
// Set the light tag using the variable
string sLightTag = GetLocalString(oObject,"lightTag");
// If the light itself has a lightTag variable, then
// use it to set its tag.
if(sLightTag != "")
{
SetTag(oObject, sLightTag);
}
}
oObject = GetNextObjectInArea(oArea);
}
}
The above function gets called from SLS2AreaOnEnter(object oArea) and SLS2AreaHeartbeat(object oArea). It ensures that if a light has a "lightTag" variable, that becomes the value of the light's Tag.
Now I just have to go back and fix my old areas from the prologue, and ensure all the interior lights have proper tags. Pretty happy to finally have this bug under control.