SetTileMainLightColor(location, int, int)

From NWN Lexicon
Jump to: navigation, search

Sets the main light colors for a tile.

void SetTileMainLightColor(
    location lTileLocation,
    int nMainLight1Color,
    int nMainLight2Color
);

Parameters

lTileLocation
This specifies the location of the tile. See Description it is not a typical location but an X, Y grid reference.
nMainLight1Color
The first main light color - TILE_MAIN_LIGHT_COLOR_*
nMainLight2Color
The second main light color - TILE_MAIN_LIGHT_COLOR_*


Description

Sets the main light colors on the tile located at lTileLocation. Main lights are the general lighting of an area - so the bits that are not torches that are sometimes present on tile walls (for these 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 using the older lighting engine. The function is really more "Recompute Tile Lighting" since it doesn't do anything to any other "static" non-moving lights.

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


Known Bugs

These 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.

There are a number of weird bugs with changing area lighting.


Version

1.22

Example

// 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);
}

See Also

functions: 

GetTileMainLight1Color

GetTileMainLight2Color

SetFogColor

SetTileSourceLightColor

RecomputeStaticLighting

constants: 

TILE_MAIN_LIGHT_COLOR_* Constants



 author: Tom Cassiotis