Skip to content

Commit

Permalink
Non-watering mulch effects
Browse files Browse the repository at this point in the history
  • Loading branch information
Bassoonian committed Nov 30, 2023
1 parent a517e14 commit 4628af3
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 17 deletions.
1 change: 1 addition & 0 deletions include/constants/items.h
Original file line number Diff line number Diff line change
Expand Up @@ -1015,6 +1015,7 @@
#define ITEM_TO_BERRY(itemId)(((itemId) - FIRST_BERRY_INDEX) + 1)
#define ITEM_TO_MAIL(itemId)((itemId) - FIRST_MAIL_INDEX)
#define MAIL_NONE 0xFF
#define ITEM_TO_MULCH(itemId)(((itemId) - ITEM_GROWTH_MULCH) + 1)

#define NUM_TECHNICAL_MACHINES 100
#define NUM_HIDDEN_MACHINES 8
Expand Down
38 changes: 29 additions & 9 deletions src/berry.c
Original file line number Diff line number Diff line change
Expand Up @@ -1566,13 +1566,24 @@ static bool32 BerryTreeGrow(struct BerryTree *tree)
tree->watered4 = 0;
tree->berryYield = 0;
tree->stage = BERRY_STAGE_SPROUTED;
if (++tree->regrowthCount == 10)
if (++tree->regrowthCount == ((tree->mulch == ITEM_TO_MULCH(ITEM_GOOEY_MULCH)) ? 15 : 10))
*tree = gBlankBerryTree;
break;
}
return TRUE;
}

static u16 GetMulchAffectedGrowthRate(u16 berryDuration, u8 mulch, u8 stage)
{
if (stage == BERRY_STAGE_BERRIES)
return berryDuration;
if (mulch == ITEM_TO_MULCH(ITEM_GROWTH_MULCH))
return berryDuration / 4 * 3;
if (mulch == ITEM_TO_MULCH(ITEM_DAMP_MULCH))
return berryDuration / 2 * 3;
return berryDuration;
}

void BerryTreeTimeUpdate(s32 minutes)
{
int i;
Expand Down Expand Up @@ -1600,11 +1611,11 @@ void BerryTreeTimeUpdate(s32 minutes)
break;
}
time -= tree->minutesUntilNextStage;
tree->minutesUntilNextStage = GetStageDurationByBerryType(tree->berry);
tree->minutesUntilNextStage = GetMulchAffectedGrowthRate(GetStageDurationByBerryType(tree->berry), tree->mulch, tree->stage);
if (!BerryTreeGrow(tree))
break;
if (tree->stage == BERRY_STAGE_BERRIES)
tree->minutesUntilNextStage *= 4;
tree->minutesUntilNextStage *= ((tree->mulch == ITEM_TO_MULCH(ITEM_STABLE_MULCH)) ? 6 : 4);
}
}
}
Expand All @@ -1615,14 +1626,13 @@ void PlantBerryTree(u8 id, u8 berry, u8 stage, bool8 allowGrowth)
{
struct BerryTree *tree = GetBerryTreeInfo(id);

*tree = gBlankBerryTree;
tree->berry = berry;
tree->minutesUntilNextStage = GetStageDurationByBerryType(berry);
tree->minutesUntilNextStage = GetMulchAffectedGrowthRate(GetStageDurationByBerryType(berry), tree->mulch, stage);
tree->stage = stage;
if (stage == BERRY_STAGE_BERRIES)
{
tree->berryYield = CalcBerryYield(tree);
tree->minutesUntilNextStage *= 4;
tree->minutesUntilNextStage *= ((tree->mulch == ITEM_TO_MULCH(ITEM_STABLE_MULCH)) ? 6 : 4);
}

// Stop growth, to keep tree at this stage until the player has seen it
Expand All @@ -1648,6 +1658,11 @@ u8 GetStageByBerryTreeId(u8 id)
return gSaveBlock1Ptr->berryTrees[id].stage;
}

u8 GetMulchByBerryTreeId(u8 id)
{
return gSaveBlock1Ptr->berryTrees[id].mulch;
}

u8 ItemIdToBerryType(u16 item)
{
u16 berry = item - FIRST_BERRY_INDEX;
Expand Down Expand Up @@ -1742,8 +1757,11 @@ static u8 CalcBerryYield(struct BerryTree *tree)
const struct Berry *berry = GetBerryInfo(tree->berry);
u8 min = berry->minYield;
u8 max = berry->maxYield;
u8 result = CalcBerryYieldInternal(max, min, BerryTreeGetNumStagesWatered(tree));
if (tree->mulch == ITEM_TO_MULCH(ITEM_RICH_MULCH) || tree->mulch == ITEM_TO_MULCH(ITEM_AMAZE_MULCH))
result += 2;

return CalcBerryYieldInternal(max, min, BerryTreeGetNumStagesWatered(tree));
return result;
}

static u8 GetBerryCountByBerryTreeId(u8 id)
Expand Down Expand Up @@ -1909,7 +1927,7 @@ static u8 GetMutationOutcome(u8 berry1, u8 berry2)

static u8 TryForMutation(u8 berryTreeId, u8 berry)
{
u8 i, j;
u8 i, j, mulch;
s16 x1, x2, y1, y2;

// Get location of current tree
Expand All @@ -1924,14 +1942,16 @@ static u8 TryForMutation(u8 berryTreeId, u8 berry)
x1 = gObjectEvents[i].currentCoords.x;
y1 = gObjectEvents[i].currentCoords.y;

mulch = GetMulchByBerryTreeId(GetObjectEventBerryTreeId(i));

// Try mutation for each adjacent tree
for (j = 0; j < OBJECT_EVENTS_COUNT; j++)
{
if (gObjectEvents[j].active && gObjectEvents[j].movementType == MOVEMENT_TYPE_BERRY_TREE_GROWTH && GetStageByBerryTreeId(GetObjectEventBerryTreeId(j)) != BERRY_STAGE_NO_BERRY && j != i)
{
x2 = gObjectEvents[j].currentCoords.x;
y2 = gObjectEvents[j].currentCoords.y;
if (Random() % 100 < BERRY_MUTATION_CHANCE && (
if (Random() % 100 < (BERRY_MUTATION_CHANCE * (mulch == ITEM_TO_MULCH(ITEM_SURPRISE_MULCH) || mulch == ITEM_TO_MULCH(ITEM_AMAZE_MULCH))) && (
(x1 == x2 && y1 == y2 - 1) ||
(x1 == x2 && y1 == y2 + 1) ||
(x1 == x2 - 1 && y1 == y2) ||
Expand Down
24 changes: 16 additions & 8 deletions src/data/items.h
Original file line number Diff line number Diff line change
Expand Up @@ -2167,7 +2167,8 @@ const struct Item gItems[] =
.description = sGrowthMulchDesc,
.pocket = POCKET_ITEMS,
.type = ITEM_USE_BAG_MENU,
.fieldUseFunc = ItemUseOutOfBattle_CannotUse, // Todo
.fieldUseFunc = ItemUseOutOfBattle_CannotUse,
.secondaryId = ITEM_TO_MULCH(ITEM_GROWTH_MULCH),
.flingPower = 30,
},

Expand All @@ -2178,7 +2179,8 @@ const struct Item gItems[] =
.description = sDampMulchDesc,
.pocket = POCKET_ITEMS,
.type = ITEM_USE_BAG_MENU,
.fieldUseFunc = ItemUseOutOfBattle_CannotUse, // Todo
.fieldUseFunc = ItemUseOutOfBattle_CannotUse,
.secondaryId = ITEM_TO_MULCH(ITEM_DAMP_MULCH),
.flingPower = 30,
},

Expand All @@ -2189,7 +2191,8 @@ const struct Item gItems[] =
.description = sStableMulchDesc,
.pocket = POCKET_ITEMS,
.type = ITEM_USE_BAG_MENU,
.fieldUseFunc = ItemUseOutOfBattle_CannotUse, // Todo
.fieldUseFunc = ItemUseOutOfBattle_CannotUse,
.secondaryId = ITEM_TO_MULCH(ITEM_STABLE_MULCH),
.flingPower = 30,
},

Expand All @@ -2200,7 +2203,8 @@ const struct Item gItems[] =
.description = sGooeyMulchDesc,
.pocket = POCKET_ITEMS,
.type = ITEM_USE_BAG_MENU,
.fieldUseFunc = ItemUseOutOfBattle_CannotUse, // Todo
.fieldUseFunc = ItemUseOutOfBattle_CannotUse,
.secondaryId = ITEM_TO_MULCH(ITEM_GOOEY_MULCH),
.flingPower = 30,
},

Expand All @@ -2211,7 +2215,8 @@ const struct Item gItems[] =
.description = sRichMulchDesc,
.pocket = POCKET_ITEMS,
.type = ITEM_USE_BAG_MENU,
.fieldUseFunc = ItemUseOutOfBattle_CannotUse, // Todo
.fieldUseFunc = ItemUseOutOfBattle_CannotUse,
.secondaryId = ITEM_TO_MULCH(ITEM_RICH_MULCH),
.flingPower = 30,
},

Expand All @@ -2222,7 +2227,8 @@ const struct Item gItems[] =
.description = sSurpriseMulchDesc,
.pocket = POCKET_ITEMS,
.type = ITEM_USE_BAG_MENU,
.fieldUseFunc = ItemUseOutOfBattle_CannotUse, // Todo
.fieldUseFunc = ItemUseOutOfBattle_CannotUse,
.secondaryId = ITEM_TO_MULCH(ITEM_SURPRISE_MULCH),
.flingPower = 30,
},

Expand All @@ -2233,7 +2239,8 @@ const struct Item gItems[] =
.description = sBoostMulchDesc,
.pocket = POCKET_ITEMS,
.type = ITEM_USE_BAG_MENU,
.fieldUseFunc = ItemUseOutOfBattle_CannotUse, // Todo
.fieldUseFunc = ItemUseOutOfBattle_CannotUse,
.secondaryId = ITEM_TO_MULCH(ITEM_BOOST_MULCH),
.flingPower = 30,
},

Expand All @@ -2244,7 +2251,8 @@ const struct Item gItems[] =
.description = sAmazeMulchDesc,
.pocket = POCKET_ITEMS,
.type = ITEM_USE_BAG_MENU,
.fieldUseFunc = ItemUseOutOfBattle_CannotUse, // Todo
.fieldUseFunc = ItemUseOutOfBattle_CannotUse,
.secondaryId = ITEM_TO_MULCH(ITEM_AMAZE_MULCH),
.flingPower = 30,
},

Expand Down

0 comments on commit 4628af3

Please sign in to comment.