From aa6d540b7520b1a2c0489a9fb263412f1798d019 Mon Sep 17 00:00:00 2001 From: Eduardo Quezada Date: Fri, 30 Aug 2024 12:17:31 -0400 Subject: [PATCH] Code style adjustments --- asm/macros/event.inc | 4 +- gflib/sprite.c | 8 +- include/global.h | 2 +- src/battle_transition.c | 5 +- src/contest_effect.c | 37 ++++---- src/event_object_movement.c | 78 ++++++++++------ src/field_effect.c | 15 ++- src/field_effect_helpers.c | 15 ++- src/field_weather.c | 50 ++++++---- src/field_weather_effect.c | 14 ++- src/fieldmap.c | 14 ++- src/heal_location.c | 8 +- src/overworld.c | 84 ++++++++++------- src/palette.c | 171 +++++++++++++++++++++++++---------- src/pokemon_summary_screen.c | 6 +- src/scrcmd.c | 3 +- src/tv.c | 3 +- 17 files changed, 339 insertions(+), 178 deletions(-) diff --git a/asm/macros/event.inc b/asm/macros/event.inc index 559573f544..17420538cd 100644 --- a/asm/macros/event.inc +++ b/asm/macros/event.inc @@ -1800,11 +1800,11 @@ @ Equivalent to fadescreen but copies gPlttBufferUnfaded to gDecompressionBuffer on the fade out @ and the reverse on the fade in, in effect saving gPlttBufferUnfaded to restore it. - @ If nowait set, does not wait for the fade to complete + @ If nowait set, does not wait for the fade to complete .macro fadescreenswapbuffers mode:req, nowait=0 .byte 0xdc .byte \mode - .byte \nowait + .byte \nowait .endm @ Buffers the specified trainer's class name to the given string var. diff --git a/gflib/sprite.c b/gflib/sprite.c index 7e0d61a7f0..67192aabab 100644 --- a/gflib/sprite.c +++ b/gflib/sprite.c @@ -1478,7 +1478,8 @@ u16 LoadSpriteSheetByTemplateWithOffset(const struct SpriteTemplate *template, u return LoadSpriteSheetWithOffset(&sheet, offset); } // Like LoadSpriteSheet, but checks if already, and uses template image frames -u16 LoadSpriteSheetByTemplate(const struct SpriteTemplate *template, u8 frame) { +u16 LoadSpriteSheetByTemplate(const struct SpriteTemplate *template, u8 frame) +{ u16 tileStart; struct SpriteSheet tempSheet; // error if template is null or tile tag or images not set @@ -1608,7 +1609,8 @@ void LoadSpritePalettes(const struct SpritePalette *palettes) break; } -u8 LoadSpritePaletteInSlot(const struct SpritePalette *palette, u8 paletteNum) { +u8 LoadSpritePaletteInSlot(const struct SpritePalette *palette, u8 paletteNum) +{ paletteNum = min(15, paletteNum); sSpritePaletteTags[paletteNum] = palette->tag; DoLoadSpritePalette(palette->data, paletteNum * 16); @@ -1617,7 +1619,7 @@ u8 LoadSpritePaletteInSlot(const struct SpritePalette *palette, u8 paletteNum) { void DoLoadSpritePalette(const u16 *src, u16 paletteOffset) { - LoadPaletteFast(src, paletteOffset + OBJ_PLTT_OFFSET, PLTT_SIZE_4BPP); + LoadPaletteFast(src, OBJ_PLTT_OFFSET + paletteOffset, PLTT_SIZE_4BPP); } u8 AllocSpritePalette(u16 tag) diff --git a/include/global.h b/include/global.h index 634ce6e5ec..ada0bbb2f3 100644 --- a/include/global.h +++ b/include/global.h @@ -954,7 +954,7 @@ struct MysteryGiftSave struct WonderCardMetadata cardMetadata; u16 questionnaireWords[NUM_QUESTIONNAIRE_WORDS]; struct WonderNewsMetadata newsMetadata; - u32 trainerIds[2][5]; // Saved ids for 10 trainers, 5 each for battles and trades + u32 trainerIds[2][5]; // Saved ids for 10 trainers, 5 each for battles and trades }; // 0x36C 0x3598 // For external event data storage. The majority of these may have never been used. diff --git a/src/battle_transition.c b/src/battle_transition.c index d2177070f2..6fc7d1ea47 100644 --- a/src/battle_transition.c +++ b/src/battle_transition.c @@ -3952,8 +3952,9 @@ static bool8 TransitionIntro_FadeFromGray(struct Task *task) BlendPalettes(PALETTES_ALL, task->tBlend, RGB(11, 11, 11)); // Restore BLDCNT SetGpuReg(REG_OFFSET_BLDCNT, task->tBldCntSaved); - if (paletteNum < 16) { - u16 index = (paletteNum+16)*16+9; // SHADOW_COLOR_INDEX + if (paletteNum < 16) + { + u16 index = ((paletteNum + 16) * 16) + 9; // SHADOW_COLOR_INDEX gPlttBufferFaded[index] = task->tShadowColor; } } diff --git a/src/contest_effect.c b/src/contest_effect.c index aa22f1d13d..e6735a8698 100644 --- a/src/contest_effect.c +++ b/src/contest_effect.c @@ -132,7 +132,7 @@ static void ContestEffect_UserLessEasilyStartled(void) SetContestantEffectStringID(eContestAppealResults.contestant,CONTEST_STRING_STOPPED_CARING); } -// Slightly startles the POKéMON in front. +// Slightly startles the POKďż˝MON in front. static void ContestEffect_StartleFrontMon(void) { u8 idx = 0; @@ -180,7 +180,7 @@ static void ContestEffect_StartlePrevMons(void) SetContestantEffectStringID(eContestAppealResults.contestant, CONTEST_STRING_ATTEMPT_STARTLE); } -// Startles the POKéMON that appealed before the user. +// Startles the POKďż˝MON that appealed before the user. static void ContestEffect_StartlePrevMon2(void) { u8 rval = Random() % 10; @@ -197,7 +197,7 @@ static void ContestEffect_StartlePrevMon2(void) ContestEffect_StartleFrontMon(); } -// Startles all POKéMON that appealed before the user. +// Startles all POKďż˝MON that appealed before the user. static void ContestEffect_StartlePrevMons2(void) { u8 numStartled = 0; @@ -273,7 +273,7 @@ static void ContestEffect_ShiftJudgeAttention(void) } } -// Startles the POKéMON that has the JUDGE's attention. +// Startles the POKďż˝MON that has the JUDGE's attention. static void ContestEffect_StartleMonWithJudgesAttention(void) { u8 numStartled = 0; @@ -311,7 +311,7 @@ static void ContestEffect_JamsOthersButMissOneTurn(void) SetContestantEffectStringID(eContestAppealResults.contestant, CONTEST_STRING_ATTEMPT_STARTLE); } -// Startles POKéMON that made a same-type appeal. +// Startles POKďż˝MON that made a same-type appeal. static void ContestEffect_StartleMonsSameTypeAppeal(void) { u16 move = eContestantStatus[eContestAppealResults.contestant].currMove; @@ -319,42 +319,42 @@ static void ContestEffect_StartleMonsSameTypeAppeal(void) SetContestantEffectStringID(eContestAppealResults.contestant, CONTEST_STRING_ATTEMPT_STARTLE); } -// Badly startles POKéMON that made COOL appeals. +// Badly startles POKďż˝MON that made COOL appeals. static void ContestEffect_StartleMonsCoolAppeal(void) { JamByMoveCategory(CONTEST_CATEGORY_COOL); SetContestantEffectStringID(eContestAppealResults.contestant, CONTEST_STRING_ATTEMPT_STARTLE); } -// Badly startles POKéMON that made BEAUTY appeals. +// Badly startles POKďż˝MON that made BEAUTY appeals. static void ContestEffect_StartleMonsBeautyAppeal(void) { JamByMoveCategory(CONTEST_CATEGORY_BEAUTY); SetContestantEffectStringID(eContestAppealResults.contestant, CONTEST_STRING_ATTEMPT_STARTLE); } -// Badly startles POKéMON that made CUTE appeals. +// Badly startles POKďż˝MON that made CUTE appeals. static void ContestEffect_StartleMonsCuteAppeal(void) { JamByMoveCategory(CONTEST_CATEGORY_CUTE); SetContestantEffectStringID(eContestAppealResults.contestant, CONTEST_STRING_ATTEMPT_STARTLE); } -// Badly startles POKéMON that made SMART appeals. +// Badly startles POKďż˝MON that made SMART appeals. static void ContestEffect_StartleMonsSmartAppeal(void) { JamByMoveCategory(CONTEST_CATEGORY_SMART); SetContestantEffectStringID(eContestAppealResults.contestant, CONTEST_STRING_ATTEMPT_STARTLE); } -// Badly startles POKéMON that made TOUGH appeals. +// Badly startles POKďż˝MON that made TOUGH appeals. static void ContestEffect_StartleMonsToughAppeal(void) { JamByMoveCategory(CONTEST_CATEGORY_TOUGH); SetContestantEffectStringID(eContestAppealResults.contestant, CONTEST_STRING_ATTEMPT_STARTLE); } -// Makes one POKéMON after the user nervous. +// Makes one POKďż˝MON after the user nervous. static void ContestEffect_MakeFollowingMonNervous(void) { bool32 hitAny = FALSE; @@ -386,7 +386,7 @@ static void ContestEffect_MakeFollowingMonNervous(void) SetContestantEffectStringID2(eContestAppealResults.contestant, CONTEST_STRING_MESSED_UP2); } -// Makes all POKéMON after the user nervous. +// Makes all POKďż˝MON after the user nervous. static void ContestEffect_MakeFollowingMonsNervous(void) { u8 numUnnerved = 0; @@ -493,7 +493,7 @@ static void ContestEffect_WorsenConditionOfPrevMons(void) SetContestantEffectStringID2(eContestAppealResults.contestant, CONTEST_STRING_IGNORED); } -// Badly startles POKéMON in good condition. +// Badly startles POKďż˝MON in good condition. static void ContestEffect_BadlyStartlesMonsInGoodCondition(void) { u8 numHit = 0; @@ -619,15 +619,18 @@ static void ContestEffect_QualityDependsOnTiming(void) { appeal = 10; SetContestantEffectStringID(eContestAppealResults.contestant, CONTEST_STRING_APPEAL_NOT_VERY_WELL); - } else if (rval < 6) + } + else if (rval < 6) { appeal = 20; SetContestantEffectStringID(eContestAppealResults.contestant, CONTEST_STRING_APPEAL_SLIGHTLY_WELL2); - } else if (rval < 8) + } + else if (rval < 8) { appeal = 40; SetContestantEffectStringID(eContestAppealResults.contestant, CONTEST_STRING_APPEAL_PRETTY_WELL2); - } else if (rval < 9) + } + else if (rval < 9) { appeal = 60; SetContestantEffectStringID(eContestAppealResults.contestant, CONTEST_STRING_APPEAL_VERY_WELL); @@ -892,7 +895,7 @@ static void ContestEffect_ExciteAudienceInAnyContest(void) } } -// Badly startles all POKéMON that made good appeals. +// Badly startles all POKďż˝MON that made good appeals. static void ContestEffect_BadlyStartleMonsWithGoodAppeals(void) { int i; diff --git a/src/event_object_movement.c b/src/event_object_movement.c index 075664a31e..42f68473a1 100644 --- a/src/event_object_movement.c +++ b/src/event_object_movement.c @@ -1534,11 +1534,13 @@ u16 LoadSheetGraphicsInfo(const struct ObjectEventGraphicsInfo *info, u16 uuid, // Load, then free, in order to avoid displaying garbage data // before sprite's `sheetTileStart` is repointed tileStart = LoadCompressedSpriteSheetByTemplate(&template, TILE_SIZE_4BPP << sheetSpan); - if (oldTiles) { + if (oldTiles) + { FieldEffectFreeTilesIfUnused(oldTiles); // We weren't able to load the sheet; // retry (after having freed), and set sprite to invisible until done - if (tileStart <= 0) { + if (tileStart <= 0) + { if (sprite) sprite->invisible = TRUE; tileStart = LoadCompressedSpriteSheetByTemplate(&template, TILE_SIZE_4BPP << sheetSpan); @@ -1764,7 +1766,8 @@ static u8 LoadDynamicFollowerPaletteFromGraphicsId(u16 graphicsId, bool8 shiny, } // Like LoadObjectEventPalette, but overwrites the palette tag that is loaded -static u8 LoadObjectEventPaletteWithTag(u16 paletteTag, u16 overTag) { +static u8 LoadObjectEventPaletteWithTag(u16 paletteTag, u16 overTag) +{ u32 i = FindObjectEventPaletteIndexByTag(paletteTag); struct SpritePalette spritePalette; if (i == 0xFF) @@ -1795,17 +1798,17 @@ u8 CreateObjectGraphicsSpriteWithTag(u16 graphicsId, void (*callback)(struct Spr { u32 paletteNum = LoadDynamicFollowerPaletteFromGraphicsId(graphicsId, isShiny, spriteTemplate); spriteTemplate->paletteTag = GetSpritePaletteTagByPaletteNum(paletteNum); - } - else if (spriteTemplate->paletteTag != TAG_NONE) + } + else if (spriteTemplate->paletteTag != TAG_NONE) { if (paletteTag == TAG_NONE) LoadObjectEventPalette(spriteTemplate->paletteTag); - else + else { LoadObjectEventPaletteWithTag(spriteTemplate->paletteTag, paletteTag); spriteTemplate->paletteTag = paletteTag; } - } + } if (OW_GFX_COMPRESS) { @@ -1829,7 +1832,8 @@ u8 CreateObjectGraphicsSpriteWithTag(u16 graphicsId, void (*callback)(struct Spr return spriteId; } -u8 CreateObjectGraphicsSprite(u16 graphicsId, void (*callback)(struct Sprite *), s16 x, s16 y, u8 subpriority) { +u8 CreateObjectGraphicsSprite(u16 graphicsId, void (*callback)(struct Sprite *), s16 x, s16 y, u8 subpriority) +{ return CreateObjectGraphicsSpriteWithTag(graphicsId, callback, x, y, subpriority, TAG_NONE); } @@ -1977,7 +1981,7 @@ static u8 LoadDynamicFollowerPalette(u16 species, u8 form, bool32 shiny) if (gWeatherPtr->currWeather != WEATHER_FOG_HORIZONTAL) // don't want to weather blend in fog UpdateSpritePaletteWithWeather(paletteNum, FALSE); - + return paletteNum; } @@ -2479,7 +2483,8 @@ void GetFollowerAction(struct ScriptContext *ctx) // Essentially a big switch fo } // Sprite callback for light sprites -void UpdateLightSprite(struct Sprite *sprite) { +void UpdateLightSprite(struct Sprite *sprite) +{ s16 left = gSaveBlock1Ptr->pos.x - 2; s16 right = gSaveBlock1Ptr->pos.x + 17; s16 top = gSaveBlock1Ptr->pos.y; @@ -2489,7 +2494,8 @@ void UpdateLightSprite(struct Sprite *sprite) { u16 sheetTileStart; u32 paletteNum; // Ripped from RemoveObjectEventIfOutsideView - if (!(x >= left && x <= right && y >= top && y <= bottom)) { + if (!(x >= left && x <= right && y >= top && y <= bottom)) + { sheetTileStart = sprite->sheetTileStart; paletteNum = sprite->oam.paletteNum; DestroySprite(sprite); @@ -2499,22 +2505,29 @@ void UpdateLightSprite(struct Sprite *sprite) { return; } - if (gTimeOfDay != TIME_OF_DAY_NIGHT) { + if (gTimeOfDay != TIME_OF_DAY_NIGHT) + { sprite->invisible = TRUE; return; } - switch (sprite->data[5]) { // lightType + switch (sprite->data[5]) // lightType + { case 0: - if (gPaletteFade.active) { // if palette fade is active, don't flicker since the timer won't be updated + if (gPaletteFade.active) // if palette fade is active, don't flicker since the timer won't be updated + { Weather_SetBlendCoeffs(7, 12); sprite->invisible = FALSE; - } else if (gPlayerAvatar.tileTransitionState) { + } + else if (gPlayerAvatar.tileTransitionState) + { Weather_SetBlendCoeffs(7, 12); // As long as the second coefficient stays 12, shadows will not change sprite->invisible = FALSE; if (GetSpritePaletteTagByPaletteNum(sprite->oam.paletteNum) == OBJ_EVENT_PAL_TAG_LIGHT_2) LoadSpritePaletteInSlot(&sObjectEventSpritePalettes[FindObjectEventPaletteIndexByTag(OBJ_EVENT_PAL_TAG_LIGHT)], sprite->oam.paletteNum); - } else if ((sprite->invisible = gTimeUpdateCounter & 1)) { + } + else if ((sprite->invisible = gTimeUpdateCounter & 1)) + { Weather_SetBlendCoeffs(12, 12); if (GetSpritePaletteTagByPaletteNum(sprite->oam.paletteNum) == OBJ_EVENT_PAL_TAG_LIGHT) LoadSpritePaletteInSlot(&sObjectEventSpritePalettes[FindObjectEventPaletteIndexByTag(OBJ_EVENT_PAL_TAG_LIGHT_2)], sprite->oam.paletteNum); @@ -2528,11 +2541,13 @@ void UpdateLightSprite(struct Sprite *sprite) { } // Spawn a light at a map coordinate -static void SpawnLightSprite(s16 x, s16 y, s16 camX, s16 camY, u32 lightType) { +static void SpawnLightSprite(s16 x, s16 y, s16 camX, s16 camY, u32 lightType) +{ struct Sprite *sprite; const struct SpriteTemplate *template; u8 i; - for (i = 0; i < MAX_SPRITES; i++) { + for (i = 0; i < MAX_SPRITES; i++) + { sprite = &gSprites[i]; if (sprite->inUse && sprite->callback == UpdateLightSprite && sprite->data[6] == x && sprite->data[7] == y) return; @@ -2552,7 +2567,8 @@ static void SpawnLightSprite(s16 x, s16 y, s16 camX, s16 camY, u32 lightType) { sprite->affineAnims = gDummySpriteAffineAnimTable; sprite->affineAnimBeginning = TRUE; sprite->coordOffsetEnabled = TRUE; - switch (lightType) { + switch (lightType) + { case 0: // Rustboro lanterns sprite->centerToCornerVecX = -(32 >> 1); sprite->centerToCornerVecY = -(32 >> 1); @@ -2571,7 +2587,8 @@ static void SpawnLightSprite(s16 x, s16 y, s16 camX, s16 camY, u32 lightType) { } } -void TrySpawnLightSprites(s16 camX, s16 camY) { +void TrySpawnLightSprites(s16 camX, s16 camY) +{ u8 i; u8 objectCount; s16 left = gSaveBlock1Ptr->pos.x - 2; @@ -2588,7 +2605,8 @@ void TrySpawnLightSprites(s16 camX, s16 camY) { else objectCount = gMapHeader.events->objectEventCount; - for (i = 0; i < objectCount; i++) { + for (i = 0; i < objectCount; i++) + { struct ObjectEventTemplate *template = &gSaveBlock1Ptr->objectEventTemplates[i]; s16 npcX = template->x + MAP_OFFSET; s16 npcY = template->y + MAP_OFFSET; @@ -2623,10 +2641,11 @@ void TrySpawnObjectEvents(s16 cameraX, s16 cameraY) s16 npcX = template->x + MAP_OFFSET; s16 npcY = template->y + MAP_OFFSET; - if (top <= npcY && bottom >= npcY && left <= npcX && right >= npcX && !FlagGet(template->flagId)) { - if (template->graphicsId == OBJ_EVENT_GFX_LIGHT_SPRITE) { // light sprite instead - SpawnLightSprite(npcX, npcY, cameraX, cameraY, template->trainerRange_berryTreeId); - } else + if (top <= npcY && bottom >= npcY && left <= npcX && right >= npcX && !FlagGet(template->flagId)) + { + if (template->graphicsId == OBJ_EVENT_GFX_LIGHT_SPRITE) + SpawnLightSprite(npcX, npcY, cameraX, cameraY, template->trainerRange_berryTreeId); // light sprite instead + else TrySpawnObjectEventTemplate(template, gSaveBlock1Ptr->location.mapNum, gSaveBlock1Ptr->location.mapGroup, cameraX, cameraY); } } @@ -2776,10 +2795,13 @@ static u8 UpdateSpritePalette(const struct SpritePalette *spritePalette, struct sprite->inUse = FALSE; FieldEffectFreePaletteIfUnused(sprite->oam.paletteNum); sprite->inUse = TRUE; - if (IndexOfSpritePaletteTag(spritePalette->tag) == 0xFF) { + if (IndexOfSpritePaletteTag(spritePalette->tag) == 0xFF) + { sprite->oam.paletteNum = LoadSpritePalette(spritePalette); UpdateSpritePaletteWithWeather(sprite->oam.paletteNum, FALSE); - } else { + } + else + { sprite->oam.paletteNum = LoadSpritePalette(spritePalette); } @@ -9795,7 +9817,7 @@ static void (*const sGroundEffectFuncs[])(struct ObjectEvent *objEvent, struct S GroundEffect_Seaweed // GROUND_EFFECT_FLAG_SEAWEED }; -static void GroundEffect_Shadow(struct ObjectEvent *objEvent, struct Sprite *sprite) +static void GroundEffect_Shadow(struct ObjectEvent *objEvent, struct Sprite *sprite) { SetUpShadow(objEvent, sprite); } diff --git a/src/field_effect.c b/src/field_effect.c index ed5286218f..9c85771397 100644 --- a/src/field_effect.c +++ b/src/field_effect.c @@ -1301,7 +1301,8 @@ static void CreateHofMonitorSprite(s16 taskId, s16 x, s16 y, bool8 isSmallMonito { spriteId = CreateSpriteAtEnd(&sSpriteTemplate_HofMonitorBig, x, y, 0); SetSubspriteTables(&gSprites[spriteId], &sSubspriteTable_HofMonitorBig); - } else + } + else { spriteId = CreateSpriteAtEnd(&sSpriteTemplate_HofMonitorSmall, x, y, 0); } @@ -2027,7 +2028,8 @@ static bool8 LavaridgeGymB1FWarpEffect_Rise(struct Task *task, struct ObjectEven { task->data[1] <<= 1; } - } else if (!(task->data[2] & 4) && (task->data[1] > 0)) + } + else if (!(task->data[2] & 4) && (task->data[1] > 0)) { task->data[1] >>= 1; } @@ -2041,7 +2043,8 @@ static bool8 LavaridgeGymB1FWarpEffect_Rise(struct Task *task, struct ObjectEven { task->data[3]++; } - } else + } + else { task->data[4] = 1; } @@ -2196,7 +2199,8 @@ static bool8 LavaridgeGym1FWarpEffect_AshPuff(struct Task *task, struct ObjectEv gFieldEffectArguments[3] = sprite->oam.priority; task->data[1] = FieldEffectStart(FLDEFF_ASH_PUFF); task->data[0]++; - } else + } + else { task->data[1]++; ObjectEventSetHeldMovement(objectEvent, GetWalkInPlaceFasterMovementAction(objectEvent->facingDirection)); @@ -2527,7 +2531,8 @@ static void TeleportWarpInFieldEffect_SpinEnter(struct Task *task) objectEvent->triggerGroundEffectsOnMove = TRUE; sprite->subspriteMode = task->data[14]; } - } else + } + else { sprite->oam.priority = 1; if (sprite->subspriteMode != SUBSPRITES_OFF) diff --git a/src/field_effect_helpers.c b/src/field_effect_helpers.c index df676bb540..cd23ea5bac 100644 --- a/src/field_effect_helpers.c +++ b/src/field_effect_helpers.c @@ -112,12 +112,14 @@ static void LoadObjectReflectionPalette(struct ObjectEvent *objectEvent, struct } // Apply a blue tint effect to a palette -static void ApplyPondFilter(u8 paletteNum, u16 *dest) { +static void ApplyPondFilter(u8 paletteNum, u16 *dest) +{ u32 i; s32 r, g, b; u16 *src = gPlttBufferUnfaded + OBJ_PLTT_ID(paletteNum); *dest++ = *src++; // copy transparency - for (i = 0; i < 16 - 1; i++) { + for (i = 0; i < 16 - 1; i++) + { u32 color = *src++; r = (color << 27) >> 27; g = (color << 22) >> 27; @@ -130,12 +132,14 @@ static void ApplyPondFilter(u8 paletteNum, u16 *dest) { } // Apply a ice tint effect to a palette -static void ApplyIceFilter(u8 paletteNum, u16 *dest) { +static void ApplyIceFilter(u8 paletteNum, u16 *dest) +{ u32 i; s32 r, g, b; u16 *src = gPlttBufferUnfaded + OBJ_PLTT_ID(paletteNum); *dest++ = *src++; // copy transparency - for (i = 0; i < 16 - 1; i++) { + for (i = 0; i < 16 - 1; i++) + { u32 color = *src++; r = (color << 27) >> 27; g = (color << 22) >> 27; @@ -332,7 +336,8 @@ u32 FldEff_Shadow(void) const struct ObjectEventGraphicsInfo *graphicsInfo; u8 spriteId; s32 i; - for (i = MAX_SPRITES - 1; i > -1; i--) { // Search backwards, because of CreateSpriteAtEnd + for (i = MAX_SPRITES - 1; i > -1; i--) // Search backwards, because of CreateSpriteAtEnd + { // Return early if a shadow sprite already exists if (gSprites[i].data[0] == gFieldEffectArguments[0] && gSprites[i].callback == UpdateShadowFieldEffect) return 0; diff --git a/src/field_weather.c b/src/field_weather.c index 73e83bcc98..b7a640642f 100644 --- a/src/field_weather.c +++ b/src/field_weather.c @@ -551,11 +551,16 @@ static void ApplyColorMap(u8 startPalIndex, u8 numPalettes, s8 colorMapIndex) } else { - if (MapHasNaturalLight(gMapHeader.mapType)) { // Time-blend + if (MapHasNaturalLight(gMapHeader.mapType)) + { + // Time-blend u32 palettes = ((1 << numPalettes) - 1) << startPalIndex; UpdateAltBgPalettes(palettes & PALETTES_BG); UpdatePalettesWithTime(palettes); - } else { // copy + } + else + { + // copy CpuFastCopy(&gPlttBufferUnfaded[PLTT_ID(startPalIndex)], &gPlttBufferFaded[PLTT_ID(startPalIndex)], numPalettes * PLTT_SIZE_4BPP); } } @@ -685,7 +690,8 @@ static void ApplyFogBlend(u8 blendCoeff, u32 blendColor) BlendPalettesFine(PALETTES_MAP, gPlttBufferFaded, gPlttBufferFaded, blendCoeff, blendColor); // Do fog blending on marked sprite palettes - for (curPalIndex = 16; curPalIndex < 32; curPalIndex++) { + for (curPalIndex = 16; curPalIndex < 32; curPalIndex++) + { if (LightenSpritePaletteInFog(curPalIndex)) BlendPalettesFine(1, gPlttBufferFaded + PLTT_ID(curPalIndex), gPlttBufferFaded + PLTT_ID(curPalIndex), fogCoeff, RGB(28, 31, 28)); } @@ -798,17 +804,20 @@ void FadeScreen(u8 mode, s8 delay) gWeatherPtr->fadeDestColor = fadeColor; UpdateTimeOfDay(); if (useWeatherPal) - gWeatherPtr->fadeScreenCounter = 0; // Triggers gamma-shift-based fade-in - else { - if (MapHasNaturalLight(gMapHeader.mapType)) { + { + gWeatherPtr->fadeScreenCounter = 0; // Triggers gamma-shift-based fade-in + } + else if (MapHasNaturalLight(gMapHeader.mapType)) + { UpdateAltBgPalettes(PALETTES_BG); BeginTimeOfDayPaletteFade(PALETTES_ALL, delay, 16, 0, - (struct BlendSettings *)&gTimeOfDayBlend[currentTimeBlend.time0], - (struct BlendSettings *)&gTimeOfDayBlend[currentTimeBlend.time1], - currentTimeBlend.weight, fadeColor); - } else { + (struct BlendSettings *)&gTimeOfDayBlend[currentTimeBlend.time0], + (struct BlendSettings *)&gTimeOfDayBlend[currentTimeBlend.time1], + currentTimeBlend.weight, fadeColor); + } + else + { BeginNormalPaletteFade(PALETTES_ALL, delay, 16, 0, fadeColor); - } } gWeatherPtr->palProcessingState = WEATHER_PAL_STATE_SCREEN_FADING_IN; @@ -848,13 +857,18 @@ void UpdateSpritePaletteWithWeather(u8 spritePaletteIndex, bool8 allowFog) // WEATHER_PAL_STATE_CHANGING_WEATHER // WEATHER_PAL_STATE_CHANGING_IDLE default: - if (gWeatherPtr->currWeather != WEATHER_FOG_HORIZONTAL) { + if (gWeatherPtr->currWeather != WEATHER_FOG_HORIZONTAL) + { if (gWeatherPtr->colorMapIndex) ApplyColorMap(paletteIndex, 1, gWeatherPtr->colorMapIndex); else UpdateSpritePaletteWithTime(spritePaletteIndex); - } else { // In horizontal fog, only specific palettes should be fog-blended - if (allowFog) { + } + else + { + // In horizontal fog, only specific palettes should be fog-blended + if (allowFog) + { i = min((gTimeOfDay + 1) * 4, 12); // fog coeff, highest in day and lowest at night paletteIndex = PLTT_ID(paletteIndex); // First blend with time @@ -862,7 +876,10 @@ void UpdateSpritePaletteWithWeather(u8 spritePaletteIndex, bool8 allowFog) UpdateSpritePaletteWithTime(spritePaletteIndex); // Then blend faded->faded with fog coeff BlendPalettesFine(1, gPlttBufferFaded + paletteIndex, gPlttBufferFaded + paletteIndex, i, RGB(28, 31, 28)); - } else { // Otherwise, just time-blend the palette + } + else + { + // Otherwise, just time-blend the palette UpdateSpritePaletteWithTime(spritePaletteIndex); } } @@ -884,7 +901,8 @@ void ApplyWeatherColorMapToPal(u8 paletteIndex) // now unused / obselete ApplyColorMap(paletteIndex, 1, gWeatherPtr->colorMapIndex); } -void ApplyWeatherColorMapToPals(u8 startPalIndex, u8 numPalettes) { +void ApplyWeatherColorMapToPals(u8 startPalIndex, u8 numPalettes) +{ ApplyColorMap(startPalIndex, numPalettes, gWeatherPtr->colorMapIndex); } diff --git a/src/field_weather_effect.c b/src/field_weather_effect.c index 9810cdfcaa..724ad76ae8 100644 --- a/src/field_weather_effect.c +++ b/src/field_weather_effect.c @@ -1357,11 +1357,13 @@ static void DestroyFogHorizontalSprites(void); #define SHADOW_COLOR_INDEX 9 // Updates just the color of shadows to match special weather blending -u8 UpdateShadowColor(u16 color) { +u8 UpdateShadowColor(u16 color) +{ u8 paletteNum = IndexOfSpritePaletteTag(TAG_WEATHER_START); u16 ALIGNED(4) tempBuffer[16]; u16 blendedColor; - if (paletteNum < 16) { + if (paletteNum < 16) + { u16 index = OBJ_PLTT_ID(paletteNum)+SHADOW_COLOR_INDEX; gPlttBufferUnfaded[index] = gPlttBufferFaded[index] = color; // Copy to temporary buffer, blend, and keep just the shadow color index @@ -1409,11 +1411,15 @@ void FogHorizontal_Main(void) { case 0: CreateFogHorizontalSprites(); - if (gWeatherPtr->currWeather == WEATHER_FOG_HORIZONTAL) { + if (gWeatherPtr->currWeather == WEATHER_FOG_HORIZONTAL) + { Weather_SetTargetBlendCoeffs(12, 8, 3); UpdateShadowColor(0x3DEF); // Gray - } else + } + else + { Weather_SetTargetBlendCoeffs(4, 16, 0); + } gWeatherPtr->initStep++; break; case 1: diff --git a/src/fieldmap.c b/src/fieldmap.c index 17e3f2843f..0fa60b964f 100644 --- a/src/fieldmap.c +++ b/src/fieldmap.c @@ -914,16 +914,20 @@ static void LoadTilesetPalette(struct Tileset const *tileset, u16 destOffset, u1 ApplyGlobalTintToPaletteEntries(destOffset, size >> 1); } // convert legacy light palette system to current - if (tileset->lightPalettes) { + if (tileset->lightPalettes) + { u32 i, j, color; - for (i = low; i < high; i++) { - if (tileset->lightPalettes & (1 << (i - low))) { // Mark light colors - for (j = 1, color = gPlttBufferUnfaded[PLTT_ID(i)]; j < 16 && color; j++, color >>= 1) { + for (i = low; i < high; i++) + { + if (tileset->lightPalettes & (1 << (i - low))) // Mark light colors + { + for (j = 1, color = gPlttBufferUnfaded[PLTT_ID(i)]; j < 16 && color; j++, color >>= 1) + { if (color & 1) gPlttBufferFaded[PLTT_ID(i)+j] = gPlttBufferUnfaded[PLTT_ID(i)+j] |= RGB_ALPHA; } if (tileset->customLightColor & (1 << (i - low))) // Copy old custom light color to index 0 - gPlttBufferFaded[PLTT_ID(i)] = gPlttBufferUnfaded[PLTT_ID(i)] = gPlttBufferUnfaded[PLTT_ID(i)+15] | RGB_ALPHA; + gPlttBufferFaded[PLTT_ID(i)] = gPlttBufferUnfaded[PLTT_ID(i)] = gPlttBufferUnfaded[PLTT_ID(i) + 15] | RGB_ALPHA; } } } diff --git a/src/heal_location.c b/src/heal_location.c index 7193ea338e..1743925885 100644 --- a/src/heal_location.c +++ b/src/heal_location.c @@ -34,9 +34,9 @@ u32 GetHealLocationIndexByWarpData(struct WarpData *warp) u32 i; for (i = 0; i < ARRAY_COUNT(sHealLocations); i++) { - if (sHealLocations[i].group == warp->mapGroup - && sHealLocations[i].map == warp->mapNum - && sHealLocations[i].x == warp->x + if (sHealLocations[i].group == warp->mapGroup + && sHealLocations[i].map == warp->mapNum + && sHealLocations[i].x == warp->x && sHealLocations[i].y == warp->y) return i + 1; } @@ -89,7 +89,7 @@ void SetWhiteoutRespawnWarpAndHealerNPC(struct WarpData *warp) u32 healLocationId = GetHealLocationIndexByWarpData(&gSaveBlock1Ptr->lastHealLocation); u32 healNpcLocalId = GetHealNpcLocalId(healLocationId); struct HealLocation pkmCenterHealLocation; - + if (!healNpcLocalId) { *(warp) = gSaveBlock1Ptr->lastHealLocation; diff --git a/src/overworld.c b/src/overworld.c index 10ba8f7368..0a788dcd3f 100644 --- a/src/overworld.c +++ b/src/overworld.c @@ -1533,43 +1533,57 @@ const struct BlendSettings gTimeOfDayBlend[] = [TIME_OF_DAY_DAY] = {.coeff = 0, .blendColor = 0}, }; -u8 UpdateTimeOfDay(void) { +u8 UpdateTimeOfDay(void) +{ s32 hours, minutes; RtcCalcLocalTime(); hours = gLocalTime.hours; minutes = gLocalTime.minutes; - if (hours < 4) { // night + 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 + } + 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 + } + 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 + } + 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 + } + else if (hours < 20) + { 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 + } + 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 + } + else // 22-24, night + { currentTimeBlend.weight = 256; currentTimeBlend.altWeight = 0; gTimeOfDay = currentTimeBlend.time0 = currentTimeBlend.time1 = TIME_OF_DAY_NIGHT; @@ -1577,17 +1591,19 @@ u8 UpdateTimeOfDay(void) { return gTimeOfDay; } -bool8 MapHasNaturalLight(u8 mapType) { // Whether a map type is naturally lit/outside - return ( - mapType == MAP_TYPE_TOWN - || mapType == MAP_TYPE_CITY - || mapType == MAP_TYPE_ROUTE - || mapType == MAP_TYPE_OCEAN_ROUTE +// Whether a map type is naturally lit/outside +bool8 MapHasNaturalLight(u8 mapType) +{ + return (mapType == MAP_TYPE_TOWN + || mapType == MAP_TYPE_CITY + || mapType == MAP_TYPE_ROUTE + || mapType == MAP_TYPE_OCEAN_ROUTE ); } // Update & mix day / night bg palettes (into unfaded) -void UpdateAltBgPalettes(u16 palettes) { +void UpdateAltBgPalettes(u16 palettes) +{ const struct Tileset *primary = gMapHeader.mapLayout->primaryTileset; const struct Tileset *secondary = gMapHeader.mapLayout->secondaryTileset; u32 i = 1; @@ -1599,8 +1615,10 @@ void UpdateAltBgPalettes(u16 palettes) { palettes >>= 1; // start at palette 1 if (!palettes) return; - while (palettes) { - if (palettes & 1) { + while (palettes) + { + if (palettes & 1) + { if (i < NUM_PALS_IN_PRIMARY) AvgPaletteWeighted(&((u16*)primary->palettes)[i*16], &((u16*)primary->palettes)[((i+9)%16)*16], gPlttBufferUnfaded + i * 16, currentTimeBlend.altWeight); else @@ -1611,8 +1629,10 @@ void UpdateAltBgPalettes(u16 palettes) { } } -void UpdatePalettesWithTime(u32 palettes) { - if (MapHasNaturalLight(gMapHeader.mapType)) { +void UpdatePalettesWithTime(u32 palettes) +{ + if (MapHasNaturalLight(gMapHeader.mapType)) + { u32 i; u32 mask = 1 << 16; if (palettes >= (1 << 16)) @@ -1634,18 +1654,19 @@ void UpdatePalettesWithTime(u32 palettes) { } } -u8 UpdateSpritePaletteWithTime(u8 paletteNum) { - if (MapHasNaturalLight(gMapHeader.mapType)) { +u8 UpdateSpritePaletteWithTime(u8 paletteNum) +{ + if (MapHasNaturalLight(gMapHeader.mapType)) + { if (IS_BLEND_IMMUNE_TAG(GetSpritePaletteTagByPaletteNum(paletteNum))) - return paletteNum; - TimeMixPalettes( - 1, - &gPlttBufferUnfaded[OBJ_PLTT_ID(paletteNum)], - &gPlttBufferFaded[OBJ_PLTT_ID(paletteNum)], - (struct BlendSettings *)&gTimeOfDayBlend[currentTimeBlend.time0], - (struct BlendSettings *)&gTimeOfDayBlend[currentTimeBlend.time1], - currentTimeBlend.weight - ); + return paletteNum; + TimeMixPalettes(1, + &gPlttBufferUnfaded[OBJ_PLTT_ID(paletteNum)], + &gPlttBufferFaded[OBJ_PLTT_ID(paletteNum)], + (struct BlendSettings *)&gTimeOfDayBlend[currentTimeBlend.time0], + (struct BlendSettings *)&gTimeOfDayBlend[currentTimeBlend.time1], + currentTimeBlend.weight + ); } return paletteNum; } @@ -1662,7 +1683,8 @@ static void OverworldBasic(void) UpdateTilesetAnimations(); DoScheduledBgTilemapCopiesToVram(); // Every minute if no palette fade is active, update TOD blending as needed - if (!gPaletteFade.active && ++gTimeUpdateCounter >= 3600) { + if (!gPaletteFade.active && ++gTimeUpdateCounter >= 3600) + { struct TimeBlendSettings cachedBlend = { .time0 = currentTimeBlend.time0, .time1 = currentTimeBlend.time1, diff --git a/src/palette.c b/src/palette.c index ee03b5d6a9..f2fdac9fdc 100644 --- a/src/palette.c +++ b/src/palette.c @@ -54,7 +54,7 @@ void LoadPalette(const void *src, u32 offset, u32 size) } // Drop in replacement for LoadPalette, uses CpuFastCopy, size must be 0 % 32 -void LoadPaletteFast(const void *src, u32 offset, u32 size) +void LoadPaletteFast(const void *src, u32 offset, u32 size) { if ((u32)src & 3) // In case palette is not 4 byte aligned return LoadPalette(src, offset, size); @@ -265,23 +265,29 @@ static u8 UpdateTimeOfDayPaletteFade(void) dst = gPlttBufferFaded + paletteOffset; // First pply TOD blend to relevant subset of palettes - if (gPaletteFade.objPaletteToggle) { // Sprite palettes, don't blend those with tags + if (gPaletteFade.objPaletteToggle) // Sprite palettes, don't blend those with tags + { u32 i; u32 j = 1; - for (i = 0; i < 16; i++, j <<= 1) { // Mask out palettes that should not be light blended + for (i = 0; i < 16; i++, j <<= 1) // Mask out palettes that should not be light blended + { if ((selectedPalettes & j) && !IS_BLEND_IMMUNE_TAG(GetSpritePaletteTagByPaletteNum(i))) timePalettes |= j; } - } else { // tile palettes, don't blend [13, 15] + } + else // tile palettes, don't blend [13, 15] + { timePalettes = selectedPalettes & PALETTES_MAP; } TimeMixPalettes(timePalettes, src, dst, gPaletteFade.bld0, gPaletteFade.bld1, gPaletteFade.weight); // palettes that were not blended above must be copied through - if ((copyPalettes = ~timePalettes)) { + if ((copyPalettes = ~timePalettes)) + { u16 * src1 = src; u16 * dst1 = dst; - while (copyPalettes) { + while (copyPalettes) + { if (copyPalettes & 1) CpuFastCopy(src1, dst1, 32); copyPalettes >>= 1; @@ -755,7 +761,8 @@ static bool32 IsSoftwarePaletteFadeFinishing(void) } // optimized based on lucktyphlosion's BlendPalettesFine -void BlendPalettesFine(u32 palettes, u16 *src, u16 *dst, u32 coeff, u32 color) { +void BlendPalettesFine(u32 palettes, u16 *src, u16 *dst, u32 coeff, u32 color) +{ s32 newR, newG, newB; if (!palettes) @@ -766,10 +773,13 @@ void BlendPalettesFine(u32 palettes, u16 *src, u16 *dst, u32 coeff, u32 color) { newG = (color << 22) >> 27; newB = (color << 17) >> 27; - do { - if (palettes & 1) { + do + { + if (palettes & 1) + { u16 *srcEnd = src + 16; - while (src != srcEnd) { // Transparency is blended (for backdrop reasons) + while (src != srcEnd) // Transparency is blended (for backdrop reasons) + { u32 srcColor = *src; s32 r = (srcColor << 27) >> 27; s32 g = (srcColor << 22) >> 27; @@ -780,7 +790,9 @@ void BlendPalettesFine(u32 palettes, u16 *src, u16 *dst, u32 coeff, u32 color) { | ((b + (((newB - (b & 31)) * (s32)coeff) >> 5)) << 10); src++; } - } else { + } + else + { src += 16; dst += 16; } @@ -788,7 +800,8 @@ void BlendPalettesFine(u32 palettes, u16 *src, u16 *dst, u32 coeff, u32 color) { } while (palettes); } -void BlendPalettes(u32 selectedPalettes, u8 coeff, u32 color) { +void BlendPalettes(u32 selectedPalettes, u8 coeff, u32 color) +{ BlendPalettesFine(selectedPalettes, gPlttBufferUnfaded, gPlttBufferFaded, coeff, color); } @@ -796,7 +809,8 @@ void BlendPalettes(u32 selectedPalettes, u8 coeff, u32 color) { // Like BlendPalette, but ignores blendColor if the transparency high bit is set // Optimization help by lucktyphlosion -void TimeBlendPalette(u16 palOffset, u32 coeff, u32 blendColor) { +void TimeBlendPalette(u16 palOffset, u32 coeff, u32 blendColor) +{ s32 newR, newG, newB, defR, defG, defB; u16 * src = gPlttBufferUnfaded + palOffset; u16 * dst = gPlttBufferFaded + palOffset; @@ -809,27 +823,34 @@ void TimeBlendPalette(u16 palOffset, u32 coeff, u32 blendColor) { newG = (blendColor << 22) >> 27; newB = (blendColor << 17) >> 27; - if (altBlendColor >> 15) { // Transparency high bit set; alt blend color + if (altBlendColor >> 15) // Transparency high bit set; alt blend color + { defR = (altBlendColor << 27) >> 27; defG = (altBlendColor << 22) >> 27; defB = (altBlendColor << 17) >> 27; - } else { + } + else + { defR = (defaultBlendColor << 27) >> 27; defG = (defaultBlendColor << 22) >> 27; defB = (defaultBlendColor << 17) >> 27; altBlendColor = 0; } - while (src != srcEnd) { + while (src != srcEnd) + { u32 srcColor = *src; s32 r = (srcColor << 27) >> 27; s32 g = (srcColor << 22) >> 27; s32 b = (srcColor << 16) >> 26; - if (srcColor >> 15) { + if (srcColor >> 15) + { *dst = ((r + (((defR - r) * (s32)coeff) >> 5)) << 0) | ((g + (((defG - g) * (s32)coeff) >> 5)) << 5) | ((b + (((defB - (b & 31)) * (s32)coeff) >> 5)) << 10); - } else { // Use provided blend color + } + else // Use provided blend color + { *dst = ((r + (((newR - r) * (s32)coeff) >> 5)) << 0) | ((g + (((newG - g) * (s32)coeff) >> 5)) << 5) | ((b + (((newB - (b & 31)) * (s32)coeff) >> 5)) << 10); @@ -841,7 +862,8 @@ void TimeBlendPalette(u16 palOffset, u32 coeff, u32 blendColor) { // Blends a weighted average of two blend parameters // Parameters can be either blended (as in BlendPalettes) or tinted (as in TintPaletteRGB_Copy) -void TimeMixPalettes(u32 palettes, u16 *src, u16 *dst, struct BlendSettings *blend0, struct BlendSettings *blend1, u16 weight0) { +void TimeMixPalettes(u32 palettes, u16 *src, u16 *dst, struct BlendSettings *blend0, struct BlendSettings *blend1, u16 weight0) +{ s32 r0, g0, b0, r1, g1, b1, defR, defG, defB, altR, altG, altB; u32 color0, coeff0, color1, coeff1; bool8 tint0, tint1; @@ -857,20 +879,26 @@ void TimeMixPalettes(u32 palettes, u16 *src, u16 *dst, struct BlendSettings *ble tint1 = blend1->isTint; coeff1 = tint1 ? 8*2 : blend1->coeff*2; - if (tint0) { + if (tint0) + { r0 = (color0 << 24) >> 24; g0 = (color0 << 16) >> 24; b0 = (color0 << 8) >> 24; - } else { + } + else + { r0 = (color0 << 27) >> 27; g0 = (color0 << 22) >> 27; b0 = (color0 << 17) >> 27; } - if (tint1) { + if (tint1) + { r1 = (color1 << 24) >> 24; g1 = (color1 << 16) >> 24; b1 = (color1 << 8) >> 24; - } else { + } + else + { r1 = (color1 << 27) >> 27; g1 = (color1 << 22) >> 27; b1 = (color1 << 17) >> 27; @@ -879,33 +907,45 @@ void TimeMixPalettes(u32 palettes, u16 *src, u16 *dst, struct BlendSettings *ble defG = (defaultColor << 22) >> 27; defB = (defaultColor << 17) >> 27; - do { - if (palettes & 1) { + do + { + if (palettes & 1) + { u16 *srcEnd = src + 16; u32 altBlendColor = *dst++ = *src++; // color 0 is copied through - if (altBlendColor >> 15) { // Transparency high bit set; alt blend color + if (altBlendColor >> 15) // Transparency high bit set; alt blend color + { altR = (altBlendColor << 27) >> 27; altG = (altBlendColor << 22) >> 27; altB = (altBlendColor << 17) >> 27; - } else { + } + else + { altBlendColor = 0; } - while (src != srcEnd) { + while (src != srcEnd) + { u32 srcColor = *src; s32 r = (srcColor << 27) >> 27; s32 g = (srcColor << 22) >> 27; s32 b = (srcColor << 17) >> 27; s32 r2, g2, b2; - if (srcColor >> 15) { - if (altBlendColor) { // Use alternate blend color + if (srcColor >> 15) + { + if (altBlendColor) + { + // Use alternate blend color r2 = r + (((altR - r) * (s32)coeff1) >> 5); g2 = g + (((altG - g) * (s32)coeff1) >> 5); b2 = b + (((altB - b) * (s32)coeff1) >> 5); r = r + (((altR - r) * (s32)coeff0) >> 5); g = g + (((altG - g) * (s32)coeff0) >> 5); b = b + (((altB - b) * (s32)coeff0) >> 5); - } else { // Use default blend color + } + else + { + // Use default blend color r2 = r + (((defR - r) * (s32)coeff1) >> 5); g2 = g + (((defG - g) * (s32)coeff1) >> 5); b2 = b + (((defB - b) * (s32)coeff1) >> 5); @@ -913,12 +953,20 @@ void TimeMixPalettes(u32 palettes, u16 *src, u16 *dst, struct BlendSettings *ble g = g + (((defG - g) * (s32)coeff0) >> 5); b = b + (((defB - b) * (s32)coeff0) >> 5); } - } else { // Use provided blend colors - if (!tint1) { // blend-based + } + else + { + // Use provided blend colors + if (!tint1) + { + // blend-based r2 = (r + (((r1 - r) * (s32)coeff1) >> 5)); g2 = (g + (((g1 - g) * (s32)coeff1) >> 5)); b2 = (b + (((b1 - b) * (s32)coeff1) >> 5)); - } else { // tint-based + } + else + { + // tint-based r2 = (u16)((r1 * r)) >> 8; g2 = (u16)((g1 * g)) >> 8; b2 = (u16)((b1 * b)) >> 8; @@ -929,11 +977,16 @@ void TimeMixPalettes(u32 palettes, u16 *src, u16 *dst, struct BlendSettings *ble if (b2 > 31) b2 = 31; } - if (!tint0) { // blend-based + if (!tint0) + { + // blend-based r = (r + (((r0 - r) * (s32)coeff0) >> 5)); g = (g + (((g0 - g) * (s32)coeff0) >> 5)); b = (b + (((b0 - b) * (s32)coeff0) >> 5)); - } else { // tint-based + } + else + { + // tint-based r = (u16)((r0 * r)) >> 8; g = (u16)((g0 * g)) >> 8; b = (u16)((b0 * b)) >> 8; @@ -943,7 +996,7 @@ void TimeMixPalettes(u32 palettes, u16 *src, u16 *dst, struct BlendSettings *ble g = 31; if (b > 31) b = 31; - } + } } r = r2 + (((r - r2) * (s32)weight0) >> 8); g = g2 + (((g - g2) * (s32)weight0) >> 8); @@ -952,7 +1005,9 @@ void TimeMixPalettes(u32 palettes, u16 *src, u16 *dst, struct BlendSettings *ble // *dst++ = RGB2(r, g, b) | (srcColor >> 15) << 15; src++; } - } else { + } + else + { src += 16; dst += 16; } @@ -961,12 +1016,14 @@ void TimeMixPalettes(u32 palettes, u16 *src, u16 *dst, struct BlendSettings *ble } // Apply weighted average to palettes, preserving high bits of dst throughout -void AvgPaletteWeighted(u16 *src0, u16 *src1, u16 *dst, u16 weight0) { +void AvgPaletteWeighted(u16 *src0, u16 *src1, u16 *dst, u16 weight0) +{ u16 *srcEnd = src0 + 16; src0++; src1++; dst++; // leave dst transparency unchanged - while (src0 != srcEnd) { + while (src0 != srcEnd) + { u32 src0Color = *src0++; s32 r0 = (src0Color << 27) >> 27; s32 g0 = (src0Color << 22) >> 27; @@ -1085,7 +1142,8 @@ void TintPalette_CustomTone(u16 *palette, u32 count, u16 rTone, u16 gTone, u16 b } // Tints from Unfaded to Faded, using a 15-bit GBA color -void TintPalette_RGB_Copy(u16 palOffset, u32 blendColor) { +void TintPalette_RGB_Copy(u16 palOffset, u32 blendColor) +{ s32 newR, newG, newB, rTone = 0, gTone = 0, bTone = 0; u16 * src = gPlttBufferUnfaded + palOffset; u16 * dst = gPlttBufferFaded + palOffset; @@ -1093,38 +1151,51 @@ void TintPalette_RGB_Copy(u16 palOffset, u32 blendColor) { u16 *srcEnd = src + 16; u16 altBlendIndices = *dst++ = *src++; // color 0 is copied through unchanged u32 altBlendColor; - + newR = ((blendColor << 27) >> 27) << 3; newG = ((blendColor << 22) >> 27) << 3; newB = ((blendColor << 17) >> 27) << 3; - - if (altBlendIndices >> 15) { // High bit set; bitmask of which colors to alt-blend + + if (altBlendIndices >> 15) // High bit set; bitmask of which colors to alt-blend + { // Note that bit 0 of altBlendIndices specifies color 1 altBlendColor = src[14]; // color 15 - if (altBlendColor >> 15) { // Set alternate blend color + if (altBlendColor >> 15) + { + // Set alternate blend color rTone = ((altBlendColor << 27) >> 27) << 3; gTone = ((altBlendColor << 22) >> 27) << 3; bTone = ((altBlendColor << 17) >> 27) << 3; - } else { // Set default blend color + } + else + { + // Set default blend color rTone = ((defaultBlendColor << 27) >> 27) << 3; gTone = ((defaultBlendColor << 22) >> 27) << 3; bTone = ((defaultBlendColor << 17) >> 27) << 3; } - } else { + } + else + { altBlendIndices = 0; } - while (src != srcEnd) { + while (src != srcEnd) + { u32 srcColor = *src; s32 r = (srcColor << 27) >> 27; s32 g = (srcColor << 22) >> 27; s32 b = (srcColor << 17) >> 27; - if (altBlendIndices & 1) { + if (altBlendIndices & 1) + { r = (u16)((rTone * r)) >> 8; g = (u16)((gTone * g)) >> 8; b = (u16)((bTone * b)) >> 8; - } else { // Use provided blend color + } + else + { + // Use provided blend color r = (u16)((newR * r)) >> 8; g = (u16)((newG * g)) >> 8; b = (u16)((newB * b)) >> 8; diff --git a/src/pokemon_summary_screen.c b/src/pokemon_summary_screen.c index a1ebc2b188..9552055373 100644 --- a/src/pokemon_summary_screen.c +++ b/src/pokemon_summary_screen.c @@ -3969,17 +3969,17 @@ static void SetMoveTypeIcons(void) if (P_SHOW_DYNAMIC_TYPES) { type = CheckDynamicMoveType(mon, summary->moves[i], 0); - SetTypeSpritePosAndPal(type, 85, 32 + (i * 16), i + SPRITE_ARR_ID_TYPE); + SetTypeSpritePosAndPal(type, 85, 32 + (i * 16), i + SPRITE_ARR_ID_TYPE); } else { - SetTypeSpritePosAndPal(gMovesInfo[summary->moves[i]].type, 85, 32 + (i * 16), i + SPRITE_ARR_ID_TYPE); + SetTypeSpritePosAndPal(gMovesInfo[summary->moves[i]].type, 85, 32 + (i * 16), i + SPRITE_ARR_ID_TYPE); } } else { SetSpriteInvisibility(i + SPRITE_ARR_ID_TYPE, TRUE); - } + } } } diff --git a/src/scrcmd.c b/src/scrcmd.c index d8b2643f43..f2660be65b 100644 --- a/src/scrcmd.c +++ b/src/scrcmd.c @@ -632,7 +632,8 @@ static bool8 IsPaletteNotActive(void) } // pauses script until palette fade inactive -bool8 ScrFunc_WaitPaletteNotActive(struct ScriptContext *ctx) { +bool8 ScrFunc_WaitPaletteNotActive(struct ScriptContext *ctx) +{ SetupNativeScript(ctx, IsPaletteNotActive); return TRUE; } diff --git a/src/tv.c b/src/tv.c index c0e207ce8a..8fc8bb684b 100644 --- a/src/tv.c +++ b/src/tv.c @@ -5334,7 +5334,8 @@ static void DoTVShow3CheersForPokeblocks(void) if (show->threeCheers.sheen > 24) { StringCopy(gStringVar2, gText_Excellent); - } else if (show->threeCheers.sheen > 22) + } + else if (show->threeCheers.sheen > 22) { StringCopy(gStringVar2, gText_VeryGood); }