SetTileSourceLightColor(location, int, int)

From NWN Lexicon
Jump to: navigation, search

Sets the source light color for a tile.

void SetTileSourceLightColor(
    location lTileLocation,
    int nSourceLight1Color,
    int nSourceLight2Color
);

Parameters

lTileLocatio
The location of the tile to change the light color. See Description it is not a typical location but an X, Y grid reference.
nSourceLight1Color
The first source light color, TILE_SOURCE_LIGHT_COLOR_* constant.
nSourceLight2Color
The second source light color, TILE_SOURCE_LIGHT_COLOR_* constant.


Description

Set the source light color on the tile located at lTileLocation. Source lights are the specific lighting on a tile such as torches. They don't always exist. For the general main lighting on a tile use SetTileSourceLightColor.

Note: lTileLocation is not a typical location, instead it is actually a grid reference. See the nwscript code for an example of how to translate an objects location into a grid reference. Only the Area, X and Y parts are used, not the Z or facing. X starts at 0 and ends at GetAreaSize(AREA_WIDTH) - 1, and Y starts at 0 and ends at GetAreaSize(AREA_HEIGHT) - 1.


Remarks

You should call RecomputeStaticLighting() after calling this function in order for the changes to occur visually for the players on older lighting engines.

You can retrieve the current main lights using GetTileMainLight1Color and GetTileMainLight2Color.

Instead of a TILE_SOURCE_LIGHT_COLOR_ you can try and use 255 as the parameter to turn the light off. Even in NWN:EE newest lighting it bugs and fails to turn off, needing an area transition to fix, see Known Bugs.


Known Bugs

It is reported that it is almost impossible for torches (the source lights themselves) to turn off properly, if at all. See note above in remarks - an area transition may help (not very useful however!). [You can retrieve the current main lights using GetTileMainLight1Color and GetTileMainLight2Color. There are bug reports here].

Lighting changes are not recorded in a saved game, so when the save is loaded, the area regresses to its original lighting. A workaround for this is to apply the change again in the area OnEnter script.


Example

// Bioware example of finding a grid reference
void main()
{
    // This assumes these parameters:
    object oPC = GetFirstPC();
    location lLoc = GetLocation(oPC);
 
    int nSourceColor1 = TILE_SOURCE_LIGHT_COLOR_PALE_BLUE;
    int nSourceColor2 = TILE_SOURCE_LIGHT_COLOR_PALE_DARK_YELLOW;
 
    // You must re-generate the location to be an X,Y grid of tiles instead of a X,Y location by meter.
    vector vPos = GetPositionFromLocation(lLoc);
    vPos.x /= 10;
    vPos.y /= 10;
    lLoc = Location(GetArea(OBJECT_SELF), vPos, 0.0);
    SetTileSourceLightColor(lLoc, nSourceColor1, nSourceColor2);
    RecomputeStaticLighting(GetArea(oPC));
}
// This function will compute the location of an object into a grid reference location
location GetObjectTileGridReferenceLocation(object oObject)
{
    vector vPos = GetPositionFromLocation(GetLocation(oObject));
    vPos.x /= 10;
    vPos.y /= 10;
    location lLoc = Location(GetArea(oObject), vPos, 0.0);
    return lLoc;
}
 
// Set the main light to red in the entering objects tile (use this OnEnter of a trigger)
void main()
{
    object oEnterer = GetEnteringObject();
 
    // Get X, Y grid location
    location lTile = GetObjectTileGridReferenceLocation(oEnterer);
 
    // Set main light to red
    SetTileMainLightColor(lTile, TILE_MAIN_LIGHT_COLOR_RED, TILE_MAIN_LIGHT_COLOR_RED);
 
    // Set source light to red
    SetTileSourceLightColor(lTile, TILE_SOURCE_LIGHT_COLOR_PALE_RED, TILE_SOURCE_LIGHT_COLOR_PALE_RED);
 
    // Recompute lighting
    RecomputeStaticLighting(GetArea(oEnterer));
}


// This creates a valid location for use with SetTileMainLightColor/SetTileSourceLightColor
// at grid reference X, Y.
location GetTileGridReferenceLocation(object oArea, int x, int y)
{
    vector vPos = Vector(x/1.0, y/1.0, 0.0);
    location lLoc = Location(oArea, vPos, 0.0);
    return lLoc;
}
 
// Set the entire area - OBJECT_SELF so this could be OnEnter of the area - to red
void main()
{
    object oArea = OBJECT_SELF;
    location lTile;
 
    // Loop area size - this is a little odd due to how "tile grid references" work in NWN.
    // Grid references are 0, 0 being the first tile.
    // For an 8x5 area, it would be 7,4 being the last tile.
    int x, y;
    for(x = 0; x < GetAreaSize(AREA_WIDTH, oArea); x++)
    {
        for(y = 0; y < GetAreaSize(AREA_HEIGHT, oArea); y++)
        {
            lTile = GetTileGridReferenceLocation(oArea, x, y);
 
            // Set main light to red
            SetTileMainLightColor(lTile, TILE_MAIN_LIGHT_COLOR_RED, TILE_MAIN_LIGHT_COLOR_RED);
 
            // Set source light to red
            SetTileSourceLightColor(lTile, TILE_SOURCE_LIGHT_COLOR_PALE_RED, TILE_SOURCE_LIGHT_COLOR_PALE_RED);
        }
    }
 
    // Recompute lighting only once all tiles have their lights set (don't do it for every tile!)
    RecomputeStaticLighting(oArea);
}

Version

1.64

See Also

functions: 

GetTileSourceLight1Color

GetTileSourceLight2Color

SetFogColor

SetTileMainLightColor

RecomputeStaticLighting

constants: 

TILE_SOURCE_LIGHT_* Constants



 author: Tom Cassiotis, editor: Jasperre, additional contributor(s): Charles Feduke, Jasperre, Ruben