diff --git a/src/field_weather.c b/src/field_weather.c index 3c8d82f816..1a337f52e2 100644 --- a/src/field_weather.c +++ b/src/field_weather.c @@ -547,15 +547,11 @@ static void ApplyGammaShift(u8 startPalIndex, u8 numPalettes, s8 gammaIndex) else { if (MapHasNaturalLight(gMapHeader.mapType)) { // Time-blend - // Create the palette mask - u32 palettes = PALETTES_ALL; - numPalettes += startPalIndex; - palettes = (palettes >> startPalIndex) << startPalIndex; - palettes = (palettes << (32-numPalettes)) >> (32-numPalettes); - UpdateAltBgPalettes(palettes & PALETTES_BG); - UpdatePalettesWithTime(palettes); + u32 palettes = ((1 << numPalettes) - 1) << startPalIndex; + UpdateAltBgPalettes(palettes & PALETTES_BG); + UpdatePalettesWithTime(palettes); } else { // copy - CpuFastCopy(gPlttBufferUnfaded + startPalIndex * 16, gPlttBufferFaded + startPalIndex * 16, numPalettes * 16 * sizeof(u16)); + CpuFastCopy(gPlttBufferUnfaded + startPalIndex * 16, gPlttBufferFaded + startPalIndex * 16, numPalettes * 16 * sizeof(u16)); } } } diff --git a/src/overworld.c b/src/overworld.c index 8a3d2c57da..889b2e9f92 100644 --- a/src/overworld.c +++ b/src/overworld.c @@ -819,7 +819,7 @@ void LoadMapFromCameraTransition(u8 mapGroup, u8 mapNum) CopySecondaryTilesetToVramUsingHeap(gMapHeader.mapLayout); LoadSecondaryTilesetPalette(gMapHeader.mapLayout, TRUE); // skip copying to Faded, gamma shift will take care of it - ApplyWeatherGammaShiftToPals(6, 6); // palettes [6,12] + ApplyWeatherGammaShiftToPals(NUM_PALS_IN_PRIMARY, NUM_PALS_TOTAL - NUM_PALS_IN_PRIMARY); // palettes [6,12] InitSecondaryTilesetAnimation(); UpdateLocationHistoryForRoamer(); @@ -1468,46 +1468,47 @@ const struct BlendSettings gTimeOfDayBlend[] = }; u8 UpdateTimeOfDay(void) { - s32 hours, minutes; - RtcCalcLocalTime(); - hours = gLocalTime.hours; - minutes = gLocalTime.minutes; - if (hours < 4) { // night - currentTimeBlend.weight = 256; - currentTimeBlend.altWeight = 0; - return gTimeOfDay = currentTimeBlend.time0 = currentTimeBlend.time1 = TIME_OF_DAY_NIGHT; - } else if (hours < 7) { // night->twilight - currentTimeBlend.time0 = TIME_OF_DAY_NIGHT; - currentTimeBlend.time1 = TIME_OF_DAY_TWILIGHT; - currentTimeBlend.weight = 256 - 256 * ((hours - 4) * 60 + minutes) / ((7-4)*60); - currentTimeBlend.altWeight = (256 - currentTimeBlend.weight) / 2; - return gTimeOfDay = TIME_OF_DAY_DAY; - } else if (hours < 10) { // twilight->day - currentTimeBlend.time0 = TIME_OF_DAY_TWILIGHT; - currentTimeBlend.time1 = TIME_OF_DAY_DAY; - currentTimeBlend.weight = 256 - 256 * ((hours - 7) * 60 + minutes) / ((10-7)*60); - currentTimeBlend.altWeight = (256 - currentTimeBlend.weight) / 2 + 128; - return gTimeOfDay = TIME_OF_DAY_DAY; - } else if (hours < 18) { // day - currentTimeBlend.weight = currentTimeBlend.altWeight = 256; - return gTimeOfDay = currentTimeBlend.time0 = currentTimeBlend.time1 = TIME_OF_DAY_DAY; - } else if (hours < 20) { // day->twilight - currentTimeBlend.time0 = TIME_OF_DAY_DAY; - currentTimeBlend.time1 = TIME_OF_DAY_TWILIGHT; - currentTimeBlend.weight = 256 - 256 * ((hours - 18) * 60 + minutes) / ((20-18)*60); - currentTimeBlend.altWeight = currentTimeBlend.weight / 2 + 128; - return gTimeOfDay = TIME_OF_DAY_TWILIGHT; - } else if (hours < 22) { // twilight->night - currentTimeBlend.time0 = TIME_OF_DAY_TWILIGHT; - currentTimeBlend.time1 = TIME_OF_DAY_NIGHT; - currentTimeBlend.weight = 256 - 256 * ((hours - 20) * 60 + minutes) / ((22-20)*60); - currentTimeBlend.altWeight = currentTimeBlend.weight / 2; - return gTimeOfDay = TIME_OF_DAY_NIGHT; - } else { // 22-24, night - currentTimeBlend.weight = 256; - currentTimeBlend.altWeight = 0; - return gTimeOfDay = currentTimeBlend.time0 = currentTimeBlend.time1 = TIME_OF_DAY_NIGHT; - } + s32 hours, minutes; + RtcCalcLocalTime(); + hours = gLocalTime.hours; + minutes = gLocalTime.minutes; + if (hours < 4) { // night + currentTimeBlend.weight = 256; + currentTimeBlend.altWeight = 0; + gTimeOfDay = currentTimeBlend.time0 = currentTimeBlend.time1 = TIME_OF_DAY_NIGHT; + } else if (hours < 7) { // night->twilight + currentTimeBlend.time0 = TIME_OF_DAY_NIGHT; + currentTimeBlend.time1 = TIME_OF_DAY_TWILIGHT; + currentTimeBlend.weight = 256 - 256 * ((hours - 4) * 60 + minutes) / ((7-4)*60); + currentTimeBlend.altWeight = (256 - currentTimeBlend.weight) / 2; + gTimeOfDay = TIME_OF_DAY_DAY; + } else if (hours < 10) { // twilight->day + currentTimeBlend.time0 = TIME_OF_DAY_TWILIGHT; + currentTimeBlend.time1 = TIME_OF_DAY_DAY; + currentTimeBlend.weight = 256 - 256 * ((hours - 7) * 60 + minutes) / ((10-7)*60); + currentTimeBlend.altWeight = (256 - currentTimeBlend.weight) / 2 + 128; + gTimeOfDay = TIME_OF_DAY_DAY; + } else if (hours < 18) { // day + currentTimeBlend.weight = currentTimeBlend.altWeight = 256; + gTimeOfDay = currentTimeBlend.time0 = currentTimeBlend.time1 = TIME_OF_DAY_DAY; + } else if (hours < 20) { // day->twilight + currentTimeBlend.time0 = TIME_OF_DAY_DAY; + currentTimeBlend.time1 = TIME_OF_DAY_TWILIGHT; + currentTimeBlend.weight = 256 - 256 * ((hours - 18) * 60 + minutes) / ((20-18)*60); + currentTimeBlend.altWeight = currentTimeBlend.weight / 2 + 128; + gTimeOfDay = TIME_OF_DAY_TWILIGHT; + } else if (hours < 22) { // twilight->night + currentTimeBlend.time0 = TIME_OF_DAY_TWILIGHT; + currentTimeBlend.time1 = TIME_OF_DAY_NIGHT; + currentTimeBlend.weight = 256 - 256 * ((hours - 20) * 60 + minutes) / ((22-20)*60); + currentTimeBlend.altWeight = currentTimeBlend.weight / 2; + gTimeOfDay = TIME_OF_DAY_NIGHT; + } else { // 22-24, night + currentTimeBlend.weight = 256; + currentTimeBlend.altWeight = 0; + gTimeOfDay = currentTimeBlend.time0 = currentTimeBlend.time1 = TIME_OF_DAY_NIGHT; + } + return gTimeOfDay; } bool8 MapHasNaturalLight(u8 mapType) { // Whether a map type is naturally lit/outside