Skip to content

Commit

Permalink
Allow pests and weeds interaction
Browse files Browse the repository at this point in the history
  • Loading branch information
Bassoonian committed Dec 5, 2023
1 parent 36befdc commit 3e1c04c
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 3 deletions.
23 changes: 23 additions & 0 deletions data/scripts/berry_tree.inc
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,12 @@ BerryTree_EventScript_ItemUsePlantBerry::
end

BerryTree_EventScript_WantToWater::
.if OW_BERRY_PESTS == TRUE
call BerryTree_EventScript_CheckForPests
.endif
.if OW_BERRY_WEEDS == TRUE
call BerryTree_EventScript_CheckForWeed
.endif
checkitem ITEM_WAILMER_PAIL
goto_if_eq VAR_RESULT, FALSE, BerryTree_EventScript_DontWater
special ObjectEventInteractionGetBerryName
Expand Down Expand Up @@ -373,6 +379,11 @@ BerryTree_Text_ScatteredMulch:
.endif

.if OW_BERRY_WEEDS == TRUE
BerryTree_EventScript_CheckForWeed::
specialvar VAR_RESULT, ObjectEventInteractionBerryHasWeed
call_if_eq VAR_RESULT, TRUE, BerryTree_EventScript_WeedIsGrowing
return

BerryTree_EventScript_WeedIsGrowing::
msgbox BerryTree_Text_WeedIsGrowing, MSGBOX_YESNO
goto_if_eq VAR_RESULT, YES, BerryTree_EventScript_PullOutWeed
Expand All @@ -394,6 +405,18 @@ BerryTree_Text_PulledOutTheWeed:
.endif

.if OW_BERRY_PESTS == TRUE
BerryTree_EventScript_CheckForPests::
specialvar VAR_RESULT, ObjectEventInteractionBerryHasPests
call_if_eq VAR_RESULT, TRUE, BerryTree_EventScript_EncounterPests
return

BerryTree_EventScript_EncounterPests::
message BerryTree_Text_APokemonAppeared
waitmessage
waitbuttonpress
dowildbattle
return

BerryTree_Text_APokemonAppeared:
.string "A Pokémon appeared!$"
.endif
2 changes: 2 additions & 0 deletions data/specials.inc
Original file line number Diff line number Diff line change
Expand Up @@ -545,3 +545,5 @@ gSpecials::
def_special ObjectEventInteractionApplyMulch
def_special ObjectEventInteractionPullBerryWeed
def_special ObjectEventInteractionClearBerryPests
def_special ObjectEventInteractionBerryHasWeed
def_special ObjectEventInteractionBerryHasPests
26 changes: 23 additions & 3 deletions src/berry.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "item_menu.h"
#include "main.h"
#include "random.h"
#include "script_pokemon_util.h"
#include "string_util.h"
#include "text.h"
#include "constants/event_object_movement.h"
Expand All @@ -26,6 +27,7 @@ static u16 GetStageDurationByBerryType(u8);
static u16 GetDrainRateByBerryType(u8);
static void SetTreeMutations(u8 id, u8 berry);
static u8 GetTreeMutationValue(u8 id);
static u16 GetBerryPestSpecies(u8 berryId);
static void TryForWeeds(struct BerryTree *tree);
static void TryForPests(struct BerryTree *tree);

Expand Down Expand Up @@ -1746,7 +1748,7 @@ void BerryTreeTimeUpdate(s32 minutes)
s32 time = minutes;

// Check moisture gradient, pests and weeds
while (time > 0)
while (time > 0 && tree->stage != BERRY_STAGE_BERRIES)
{
tree->moistureClock += 1;
time -= 1;
Expand Down Expand Up @@ -2063,6 +2065,24 @@ bool8 PlayerHasBerries(void)
return IsBagPocketNonEmpty(POCKET_BERRIES);
}

bool8 ObjectEventInteractionBerryHasWeed(void)
{
return gSaveBlock1Ptr->berryTrees[GetObjectEventBerryTreeId(gSelectedObjectEvent)].weeds;
}

bool8 ObjectEventInteractionBerryHasPests(void)
{
u16 species;
if (!OW_BERRY_PESTS || !gSaveBlock1Ptr->berryTrees[GetObjectEventBerryTreeId(gSelectedObjectEvent)].pests)
return FALSE;
species = GetBerryPestSpecies(gSaveBlock1Ptr->berryTrees[GetObjectEventBerryTreeId(gSelectedObjectEvent)].berry);
if (species == SPECIES_NONE)
return FALSE;
CreateScriptedWildMon(species, 14 + Random() % 3, ITEM_NONE);
gSaveBlock1Ptr->berryTrees[GetObjectEventBerryTreeId(gSelectedObjectEvent)].pests = FALSE;
return TRUE;
}

// Berry tree growth is frozen at their initial stage (usually, fully grown) until the player has seen the tree
// For all berry trees on screen, allow normal growth
void SetBerryTreesSeen(void)
Expand Down Expand Up @@ -2224,9 +2244,9 @@ static void SetTreeMutations(u8 id, u8 berry)
#endif
}

#if OW_BERRY_PESTS == TRUE
static u16 GetBerryPestSpecies(u8 berryId)
{
#if OW_BERRY_PESTS == TRUE
const struct Berry *berry = GetBerryInfo(berryId);
switch(berry->color)
{
Expand All @@ -2249,9 +2269,9 @@ static u16 GetBerryPestSpecies(u8 berryId)
return SPECIES_SPEWPA;
break;
}
#endif
return SPECIES_NONE;
}
#endif

#define BERRY_WEEDS_CHANCE 15
#define BERRY_PESTS_CHANCE 15
Expand Down

0 comments on commit 3e1c04c

Please sign in to comment.