Skip to content

Commit

Permalink
Make weeds and pests affect yield
Browse files Browse the repository at this point in the history
  • Loading branch information
Bassoonian committed Dec 7, 2023
1 parent 2b71187 commit 061e56a
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 18 deletions.
20 changes: 10 additions & 10 deletions include/config/overworld.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,16 @@
#define GEN_6_XY GEN_6
#define GEN_6_ORAS (GEN_6 + 0.5)

#define OW_BERRY_MUTATIONS FALSE // If enabled, Berry plants can mutate based on berries planted next to them.
#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.
#define OW_BERRY_PESTS FALSE // If enabled, pests may approach Berry plants that the player needs to take care of.
#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_SIX_STAGES FALSE // In XY, Berries go through six stages instead of four. This toggle does not affect the time it takes for a tree to be ready for harvest. Without OW_BERRY_MOISTURE, the two extra stages count as BERRY_STAGE_TALLER for watering purposes.

#define OW_BERRY_GROWTH_RATE GEN_3 // Presets for how long each Berry plant takes to grow.
#define OW_BERRY_YIELD_RATE GEN_3 // Presets for how many Berries each plant can yield.
#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_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.
#define OW_BERRY_SIX_STAGES FALSE // In XY, Berries go through six stages instead of four. This toggle does not affect the time it takes for a tree to be ready for harvest. Without OW_BERRY_MOISTURE, the two extra stages count as BERRY_STAGE_TALLER for watering purposes.

#define OW_BERRY_GROWTH_RATE GEN_3 // Presets for how long each Berry plant takes to grow.
#define OW_BERRY_YIELD_RATE GEN_3 // Presets for how many Berries each plant can yield.

// Out-of-battle Ability effects
#define OW_SYNCHRONIZE_NATURE GEN_LATEST // In Gen8, if a Pokémon with Synchronize is leading the party, it's 100% guaranteed that wild Pokémon will have the same Nature, as opposed to 50% previously. Stationary Pokémon are excluded in Gen3. In Gen6, all No Eggs Discovered gift Pokémon will have the same Nature, while in Gen7 all gift Pokémon will, regardless of Egg Group - In Gen 8, no gift Pokémon are affected. In Gen9, this ability has no out-of-battle effect.
Expand Down
2 changes: 1 addition & 1 deletion include/global.berry.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ struct BerryTree
u8 pests:1;
u8 mutationB:2;
u8 regrowthCount:4;
u8 watered:4; // Used to keep track of yield lost to drought in case of Gen4 watering
u8 watered:4; // Used to keep track of bonuses in case of gradient watering
u16 moistureLevel:7;
u16 moistureClock:7;
u16 padding:2;
Expand Down
46 changes: 39 additions & 7 deletions src/berry.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ static u8 GetTreeMutationValue(u8 id);
static u16 GetBerryPestSpecies(u8 berryId);
static void TryForWeeds(struct BerryTree *tree);
static void TryForPests(struct BerryTree *tree);
static void AddTreeBonus(struct BerryTree *tree, u8 bonus);

//.rodata
static const u8 sBerryDescriptionPart1_Cheri[] = _("Blooms with delicate pretty flowers.");
Expand Down Expand Up @@ -1919,7 +1920,7 @@ bool32 BerryTreeGrow(struct BerryTree *tree)
case BERRY_STAGE_NO_BERRY:
return FALSE;
case BERRY_STAGE_FLOWERING:
tree->berryYield = tree->berryYield + CalcBerryYield(tree);
tree->berryYield = CalcBerryYield(tree);
case BERRY_STAGE_PLANTED:
case BERRY_STAGE_SPROUTED:
case BERRY_STAGE_TRUNK:
Expand Down Expand Up @@ -2042,7 +2043,7 @@ void PlantBerryTree(u8 id, u8 berry, u8 stage, bool8 allowGrowth)
tree->moistureLevel = 100;
if (stage == BERRY_STAGE_BERRIES)
{
tree->berryYield = tree->berryYield + CalcBerryYield(tree);
tree->berryYield = CalcBerryYield(tree);
tree->minutesUntilNextStage *= ((tree->mulch == ITEM_TO_MULCH(ITEM_STABLE_MULCH)) ? 6 : 4);
}

Expand Down Expand Up @@ -2166,11 +2167,15 @@ 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;
u8 min = berry->minYield + tree->berryYield;
u8 max = berry->maxYield;
u8 result = CalcBerryYieldInternal(max, min, BerryTreeGetNumStagesWatered(tree));
u8 result;
if (OW_BERRY_MULCH_USAGE && (tree->mulch == ITEM_TO_MULCH(ITEM_RICH_MULCH) || tree->mulch == ITEM_TO_MULCH(ITEM_AMAZE_MULCH)))
result += 2;
min += 2;
if (min >= max)
result = max;
else
result = CalcBerryYieldInternal(max, min, BerryTreeGetNumStagesWatered(tree));

return result;
}
Expand Down Expand Up @@ -2306,12 +2311,16 @@ void ObjectEventInteractionRemoveBerryTree(void)

void ObjectEventInteractionPullBerryWeed(void)
{
gSaveBlock1Ptr->berryTrees[GetObjectEventBerryTreeId(gSelectedObjectEvent)].weeds = FALSE;
struct BerryTree *tree = GetBerryTreeInfo(GetObjectEventBerryTreeId(gSelectedObjectEvent));
tree->weeds = FALSE;
AddTreeBonus(tree, GetWeedingBonusByBerryType(tree->berry));
}

void ObjectEventInteractionClearBerryPests(void)
{
gSaveBlock1Ptr->berryTrees[GetObjectEventBerryTreeId(gSelectedObjectEvent)].pests = FALSE;
struct BerryTree *tree = GetBerryTreeInfo(GetObjectEventBerryTreeId(gSelectedObjectEvent));
tree->pests = FALSE;
AddTreeBonus(tree, GetPestsBonusByBerryType(tree->berry));
}

bool8 PlayerHasBerries(void)
Expand Down Expand Up @@ -2549,3 +2558,26 @@ static void TryForPests(struct BerryTree *tree)
if (Random() % 100 < BERRY_PESTS_CHANCE && tree->stage > BERRY_STAGE_PLANTED)
tree->pests = TRUE;
}

static void AddTreeBonus(struct BerryTree *tree, u8 bonus)
{
if (OW_BERRY_MOISTURE) // use watered field to save track of intermediate bonuses
{
tree->watered += bonus;
while (tree->watered > 10)
{
tree->watered -= 10;
bonus = tree->berryYield + 1;
if (bonus > GetBerryInfo(tree->berry)->maxYield)
bonus = GetBerryInfo(tree->berry)->maxYield;
tree->berryYield = bonus;
}
}
else
{
bonus = tree->berryYield + bonus / 10;
if (bonus > GetBerryInfo(tree->berry)->maxYield)
bonus = GetBerryInfo(tree->berry)->maxYield;
tree->berryYield = bonus;
}
}

0 comments on commit 061e56a

Please sign in to comment.