diff --git a/data/tilesets/headers.inc b/data/tilesets/headers.inc index 4ebfe80a52..38e74bb66a 100644 --- a/data/tilesets/headers.inc +++ b/data/tilesets/headers.inc @@ -13,7 +13,7 @@ gTileset_General:: @ 83DF704 gTileset_Petalburg:: @ 83DF71C .byte TRUE @ is compressed .byte TRUE @ is secondary tileset - .2byte 0xC0 @ lightPalettes 7,8 + .2byte 3 @ lightPalettes 6,7 .4byte gTilesetTiles_Petalburg .4byte gTilesetPalettes_Petalburg .4byte gMetatiles_Petalburg @@ -24,7 +24,7 @@ gTileset_Petalburg:: @ 83DF71C gTileset_Rustboro:: @ 83DF734 .byte TRUE @ is compressed .byte TRUE @ is secondary tileset - .2byte 1 << 6 @ lightPalettes + .2byte 1 @ lightPalettes 6 .4byte gTilesetTiles_Rustboro .4byte gTilesetPalettes_Rustboro .4byte gMetatiles_Rustboro @@ -46,7 +46,7 @@ gTileset_Dewford:: @ 83DF74C gTileset_Slateport:: @ 83DF764 .byte TRUE @ is compressed .byte TRUE @ is secondary tileset - .2byte 1 << 12 @ lightPalettes + .2byte 0x41 @ lightPalettes 6,12 .4byte gTilesetTiles_Slateport .4byte gTilesetPalettes_Slateport .4byte gMetatiles_Slateport diff --git a/include/global.fieldmap.h b/include/global.fieldmap.h index 248e2a6c00..84a9c14a67 100644 --- a/include/global.fieldmap.h +++ b/include/global.fieldmap.h @@ -29,7 +29,8 @@ struct Tileset { /*0x00*/ bool8 isCompressed; /*0x01*/ bool8 isSecondary; - /*0x02*/ u16 lightPalettes; + /*0x02*/ u8 lightPalettes; // Bitmask determining whether a palette should be time-blended as a light + /*0x03*/ u8 customLightColor; // Bitmask determining which light palettes have custom light colors (color 15) /*0x04*/ void *tiles; /*0x08*/ void *palettes; /*0x0c*/ u16 *metatiles; diff --git a/include/overworld.h b/include/overworld.h index 86d5426b28..918a5dcce9 100644 --- a/include/overworld.h +++ b/include/overworld.h @@ -136,7 +136,7 @@ void CleanupOverworldWindowsAndTilemaps(void); bool32 IsUpdateLinkStateCBActive(void); void CB1_Overworld(void); void CB2_OverworldBasic(void); -void BlendPalettesWithTime(u32); +void UpdatePalettesWithTime(u32); void CB2_Overworld(void); void SetMainCallback1(void (*cb)(void)); void SetUnusedCallback(void *a0); diff --git a/include/palette.h b/include/palette.h index 4a54b1d552..f9bd20560d 100644 --- a/include/palette.h +++ b/include/palette.h @@ -76,8 +76,8 @@ void BeginHardwarePaletteFade(u8, u8, u8, u8, u8); void BlendPalettes(u32 selectedPalettes, u8 coeff, u16 color); void BlendPalettesUnfaded(u32, u8, u16); void BlendPalettesGradually(u32 selectedPalettes, s8 delay, u8 coeff, u8 coeffTarget, u16 color, u8 priority, u8 id); -void TimePalette(u16 palOffset, u16 numEntries, u8 coeff, u16 blendColor); -void TimePalettes(u32 palettes, u8 coeff, u16 color); +void TimeBlendPalette(u16 palOffset, u16 numEntries, u8 coeff, u16 blendColor); +void TimeBlendPalettes(u32 palettes, u8 coeff, u16 color); void TintPalette_GrayScale(u16 *palette, u16 count); void TintPalette_GrayScale2(u16 *palette, u16 count); void TintPalette_SepiaTone(u16 *palette, u16 count); diff --git a/src/field_weather_effect.c b/src/field_weather_effect.c index 9f78940666..db480772c6 100644 --- a/src/field_weather_effect.c +++ b/src/field_weather_effect.c @@ -1142,7 +1142,7 @@ void Thunderstorm_Main(void) { ApplyWeatherGammaShiftIfIdle(3); if (gTimeOfDay != TIME_OF_DAY_DAY) - BlendPalettesWithTime(0xFFFFFFFF); + UpdatePalettesWithTime(0xFFFFFFFF); gWeatherPtr->thunderAllowEnd = TRUE; if (--gWeatherPtr->thunderShortRetries != 0) { @@ -1183,7 +1183,7 @@ void Thunderstorm_Main(void) case TSTORM_STATE_FADE_THUNDER_LONG: if (--gWeatherPtr->thunderDelay == 0) { - gTimeOfDay == TIME_OF_DAY_DAY ? sub_80ABC7C(19, 3, 5) : BlendPalettesWithTime(0xFFFFFFFF); + gTimeOfDay == TIME_OF_DAY_DAY ? sub_80ABC7C(19, 3, 5) : UpdatePalettesWithTime(0xFFFFFFFF); gWeatherPtr->initStep++; } break; diff --git a/src/fieldmap.c b/src/fieldmap.c index d084dcf387..b3b35a7b08 100644 --- a/src/fieldmap.c +++ b/src/fieldmap.c @@ -887,9 +887,11 @@ void LoadTilesetPalette(struct Tileset const *tileset, u16 destOffset, u16 size) u8 i; LoadPalette(((u16*)tileset->palettes) + (NUM_PALS_IN_PRIMARY * 16), destOffset, size); for (i = NUM_PALS_IN_PRIMARY; i < NUM_PALS_TOTAL; i++) { - if (tileset->lightPalettes & (1 << i)) { + if (tileset->lightPalettes & (1 << (i - NUM_PALS_IN_PRIMARY))) { // Mark as light palette u16 index = i * 16; gPlttBufferFaded[index] = gPlttBufferUnfaded[index] |= 0x8000; + if (tileset->customLightColor & (1 << (i - NUM_PALS_IN_PRIMARY))) // Mark as custom light color + gPlttBufferFaded[index+15] = gPlttBufferUnfaded[index+15] |= 0x8000; } } } diff --git a/src/overworld.c b/src/overworld.c index 294bec37bf..5a7ace7b8d 100644 --- a/src/overworld.c +++ b/src/overworld.c @@ -846,7 +846,7 @@ void LoadMapFromCameraTransition(u8 mapGroup, u8 mapNum) RoamerMove(); DoCurrentWeather(); ResetFieldTasksArgs(); - BlendPalettesWithTime(0xFFFFFFFF); + UpdatePalettesWithTime(0xFFFFFFFF); RunOnResumeMapScript(); if (gMapHeader.regionMapSectionId != MAPSEC_BATTLE_FRONTIER @@ -1512,7 +1512,7 @@ static bool8 FadePalettesWithTime(void) { } } -void BlendPalettesWithTime(u32 palettes) { +void UpdatePalettesWithTime(u32 palettes) { // Only blend if not transitioning between times and the map type allows if (gTimeOfDayState == 0 && MapHasNaturalLight(gMapHeader.mapType)) { u8 i; @@ -1524,12 +1524,12 @@ void BlendPalettesWithTime(u32 palettes) { gTimeOfDay = min(TIME_OF_DAY_MAX, gTimeOfDay); if (!palettes) return; - TimePalettes(palettes, sTimeOfDayBlendVars[gTimeOfDay].coeff, sTimeOfDayBlendVars[gTimeOfDay].blendColor); + TimeBlendPalettes(palettes, sTimeOfDayBlendVars[gTimeOfDay].coeff, sTimeOfDayBlendVars[gTimeOfDay].blendColor); } } u8 UpdateSpritePaletteWithTime(u8 paletteNum) { // TODO: Optimize this - BlendPalettesWithTime(1 << (paletteNum + 16)); + UpdatePalettesWithTime(1 << (paletteNum + 16)); return paletteNum; } diff --git a/src/palette.c b/src/palette.c index f433f442b2..1b38003df5 100644 --- a/src/palette.c +++ b/src/palette.c @@ -496,13 +496,13 @@ static u8 UpdateTimeOfDayPaletteFade(void) if (gPaletteFade.yDec) { if (gPaletteFade.objPaletteToggle) { // sprite palettes if (gPaletteFade.y >= gPaletteFade.targetY || GetSpritePaletteTagByPaletteNum(paletteNum) & 0x8000) - TimePalette(paletteOffset, 16, gPaletteFade.y, gPaletteFade.blendColor); + TimeBlendPalette(paletteOffset, 16, gPaletteFade.y, gPaletteFade.blendColor); // tile palettes } else if (gPaletteFade.y >= gPaletteFade.targetY || (paletteNum >= 13 && paletteNum <= 15)) { - TimePalette(paletteOffset, 16, gPaletteFade.y, gPaletteFade.blendColor); + TimeBlendPalette(paletteOffset, 16, gPaletteFade.y, gPaletteFade.blendColor); } } else { - TimePalette(paletteOffset, 16, gPaletteFade.y, gPaletteFade.blendColor); + TimeBlendPalette(paletteOffset, 16, gPaletteFade.y, gPaletteFade.blendColor); } } } @@ -979,8 +979,9 @@ void BlendPalettes(u32 selectedPalettes, u8 coeff, u16 color) } // Like BlendPalette, but ignores blendColor if the transparency high bit is set -void TimePalette(u16 palOffset, u16 numEntries, u8 coeff, u16 blendColor) { +void TimeBlendPalette(u16 palOffset, u16 numEntries, u8 coeff, u16 blendColor) { u16 i; + u16 defaultBlendColor = 0x3f9f; s8 r, g, b; struct PlttData *data2 = (struct PlttData *)&blendColor; struct PlttData *data3; @@ -992,8 +993,10 @@ void TimePalette(u16 palOffset, u16 numEntries, u8 coeff, u16 blendColor) { if (i == 0) { if (data1->unused_15) { // Color 0 is a bitmask for which colors to blend; color 15 is the alt blend color gPlttBufferFaded[index] = gPlttBufferUnfaded[index]; - altBlendIndices = gPlttBufferUnfaded[index] & 0x7FFF; + altBlendIndices = gPlttBufferUnfaded[index] & 0x7FFF; // Note that color 15 will never be light-blended data3 = (struct PlttData *)&gPlttBufferUnfaded[index+15]; + if (!data3->unused_15) // use default blend color instead + data3 = (struct PlttData *)&defaultBlendColor; } continue; } @@ -1008,11 +1011,11 @@ void TimePalette(u16 palOffset, u16 numEntries, u8 coeff, u16 blendColor) { } // Apply time effect to a series of palettes -void TimePalettes(u32 palettes, u8 coeff, u16 color) { +void TimeBlendPalettes(u32 palettes, u8 coeff, u16 color) { u16 paletteOffset; for (paletteOffset = 0; palettes; paletteOffset += 16) { if (palettes & 1) - TimePalette(paletteOffset, 16, coeff, color); + TimeBlendPalette(paletteOffset, 16, coeff, color); palettes >>= 1; } }