From 6173f9b81d43f7339f26655155ccb37822ca9f26 Mon Sep 17 00:00:00 2001 From: Bassoonian Date: Fri, 8 Dec 2023 01:01:01 +0100 Subject: [PATCH] Add soil moisturing config --- include/config/overworld.h | 3 ++- src/berry.c | 37 +++++++++++++++++++++++++++---------- 2 files changed, 29 insertions(+), 11 deletions(-) diff --git a/include/config/overworld.h b/include/config/overworld.h index 8e8a0a27a8..8df6a4646a 100644 --- a/include/config/overworld.h +++ b/include/config/overworld.h @@ -19,7 +19,8 @@ #define OW_BERRY_MUTATIONS FALSE // If enabled, Berry plants can mutate based on berries planted next to them. #define OW_BERRY_MOISTURE FALSE // If enabled, Berry watering is not a matter of watering it once per stage, but rather of keeping the soil moist. -#define OW_BERRY_VARIABLE_DRAIN_RATE FALSE // If moisture is enabled, this setting uses the Gen4 drain rates for different berries. +#define OW_BERRY_ALWAYS_WATERABLE FALSE // If OW_BERRY_MOISTURE is enabled, this setting allows the player to continuously water soil; dry soil will cause a decrease in Berry Yield (like Gen4). When off, soil can only be watered when dry and watering increases yield (like Gen6). +#define OW_BERRY_VARIABLE_DRAIN_RATE FALSE // If OW_BERRY_MOISTURE is enabled, this setting uses the Gen4 drain rates for different berries. #define OW_BERRY_MULCH_USAGE FALSE // If enabled, Mulch can be used on soil to fertilize it. Otherwise, it is considered unusable. Note that moisture effects only work with OW_BERRY_MOISTURE enabled! #define OW_BERRY_WEEDS FALSE // If enabled, weeds may grow on Berry plants that the player needs to take care of. Without OW_BERRY_MOISTURE, weeding bonuses are rounded down. #define OW_BERRY_PESTS FALSE // If enabled, pests may approach Berry plants that the player needs to take care of. Without OW_BERRY_MOISTURE, pest bonuses are rounded down. diff --git a/src/berry.c b/src/berry.c index 3d709fc88f..68c32db822 100644 --- a/src/berry.c +++ b/src/berry.c @@ -1858,10 +1858,17 @@ struct BerryTree *GetBerryTreeInfo(u8 id) bool32 ObjectEventInteractionWaterBerryTree(void) { struct BerryTree *tree = GetBerryTreeInfo(GetObjectEventBerryTreeId(gSelectedObjectEvent)); -#if OW_BERRY_MOISTURE == TRUE - tree->moistureLevel = 100; - return TRUE; -#else + + if (OW_BERRY_MOISTURE) + { + tree->moistureLevel = 100; + if (OW_BERRY_ALWAYS_WATERABLE) + { + return TRUE; + } + AddTreeBonus(tree, GetWaterBonusByBerryType(tree->berry)); + } + switch (tree->stage) { case BERRY_STAGE_PLANTED: @@ -1882,7 +1889,6 @@ bool32 ObjectEventInteractionWaterBerryTree(void) return FALSE; } return TRUE; -#endif } bool8 IsPlayerFacingEmptyBerryTreePatch(void) @@ -1983,7 +1989,7 @@ void BerryTreeTimeUpdate(s32 minutes) time -= 1; if (tree->moistureClock % 60 == 0) { - if (OW_BERRY_MOISTURE == TRUE) + if (OW_BERRY_MOISTURE) { drainVal = OW_BERRY_VARIABLE_DRAIN_RATE ? GetDrainRateByBerryType(tree->berry) : 4; if (OW_BERRY_MULCH_USAGE) @@ -1995,12 +2001,19 @@ void BerryTreeTimeUpdate(s32 minutes) if (tree->mulch == ITEM_TO_MULCH(ITEM_BOOST_MULCH) || tree->mulch == ITEM_TO_MULCH(ITEM_AMAZE_MULCH)) drainVal = 25; } - if (tree->moistureLevel == 0 || (!OW_BERRY_VARIABLE_DRAIN_RATE && tree->moistureLevel == 4)) // Without variable drain rate (and without mulches), this needs to trigger after 24 hours, hence the extra check - tree->watered++; + if (OW_BERRY_ALWAYS_WATERABLE && tree->moistureLevel == 0) + { + if (tree->berryYield > GetBerryInfo(tree->berry)->minYield + GetBerryInfo(tree->berry)->maxYield / 5) + tree->berryYield -= GetBerryInfo(tree->berry)->maxYield / 5; + else + tree->berryYield = GetBerryInfo(tree->berry)->minYield; + } else if (tree->moistureLevel <= drainVal) tree->moistureLevel = 0; else tree->moistureLevel -= drainVal; + if (!OW_BERRY_VARIABLE_DRAIN_RATE && tree->moistureLevel <= 4) // Without variable drain rate (and without mulches), this needs to trigger after 24 hours, hence the extra check + tree->moistureLevel = 0; } if (tree->moistureClock == 120) { @@ -2041,6 +2054,8 @@ void PlantBerryTree(u8 id, u8 berry, u8 stage, bool8 allowGrowth) tree->minutesUntilNextStage = GetMulchAffectedGrowthRate(GetStageDurationByBerryType(berry), tree->mulch, stage); tree->stage = stage; tree->moistureLevel = 100; + if (OW_BERRY_ALWAYS_WATERABLE) + tree->berryYield = GetBerryInfo(berry)->maxYield; if (stage == BERRY_STAGE_BERRIES) { tree->berryYield = CalcBerryYield(tree); @@ -2147,7 +2162,7 @@ static u8 CalcBerryYieldInternal(u16 max, u16 min, u8 water) u32 rand; u32 extraYield; - if (water == 0) + if (water == 0 || OW_BERRY_MOISTURE) return min; else { @@ -2167,11 +2182,13 @@ static u8 CalcBerryYieldInternal(u16 max, u16 min, u8 water) static u8 CalcBerryYield(struct BerryTree *tree) { const struct Berry *berry = GetBerryInfo(tree->berry); - u8 min = berry->minYield + tree->berryYield; + u8 min = tree->berryYield; u8 max = berry->maxYield; u8 result; if (OW_BERRY_MULCH_USAGE && (tree->mulch == ITEM_TO_MULCH(ITEM_RICH_MULCH) || tree->mulch == ITEM_TO_MULCH(ITEM_AMAZE_MULCH))) min += 2; + if (!(OW_BERRY_MOISTURE && OW_BERRY_ALWAYS_WATERABLE)) + min += berry->minYield; if (min >= max) result = max; else