diff --git a/asm/macros/event.inc b/asm/macros/event.inc index 34a6094522b1..ede71eb19b6d 100644 --- a/asm/macros/event.inc +++ b/asm/macros/event.inc @@ -2338,3 +2338,95 @@ .macro hideitemdescription callnative ScriptHideItemDescription .endm + + @ Remove all of specified item from the player's bag and return the number of removed items to VAR_RESULT + .macro removeallitem itemId:req + callnative ScrCmd_removeallitem + .2byte \itemId + .endm + + @ Stores the position of the given object in destX and destY. Mode CURRENT_POSITION will take the object's current position. Mode TEMPLATE_POSITION will take the object's template position. + .macro getobjectxy localId:req, posType:req, destX:req, destY:req + callnative ScrCmd_getobjectxy + .2byte \localId + .2byte \posType + .2byte \destX + .2byte \destY + .endm + + .macro getobjecttemplatexy localId:req, posType = TEMPLATE_POSITION, destX:req, destY:req + callnative ScrCmd_getobjectxy + .2byte \localId + .2byte \posType + .2byte \destX + .2byte \destY + .endm + + .macro getobjectcurrentxy localId:req, posType = CURRENT_POSITION, destX:req, destY:req + callnative ScrCmd_getobjectxy + .2byte \localId + .2byte \posType + .2byte \destX + .2byte \destY + .endm + + @ Return TRUE to dest if there is an object at the position x and y. + .macro checkobjectat x:req, y:req, dest = VAR_RESULT + callnative ScrCmd_checkobjectat + .2byte \x + .2byte \y + .2byte \dest + .endm + + @ Returns the state of the Pokedex Seen Flag to VAR_RESULT for the Pokemon with speciesId + .macro getseenmon species:req + callnative Scrcmd_getsetpokedexflag + .2byte \species + .2byte FLAG_GET_SEEN + .endm + + @ Returns the state of the Pokedex Caught Flag to VAR_RESULT for the Pokemon with speciesId + .macro getcaughtmon species:req + callnative Scrcmd_getsetpokedexflag + .2byte \species + .2byte FLAG_GET_CAUGHT + .endm + + @ Sets the Pokedex Seen Flag for the Pokemon with speciesId + .macro setseenmon species:req + callnative Scrcmd_getsetpokedexflag + .2byte \species + .2byte FLAG_SET_SEEN + .endm + + @ Sets the Pokedex Caught Flag for the Pokemon with speciesId + .macro setcaughtmon species:req + callnative Scrcmd_getsetpokedexflag + .2byte \species + .2byte FLAG_SET_CAUGHT + .endm + + @ Check if the Player has speciesId in their party. OPEN_PARTY_SCREEN will have the player select a mon from their party. NO_PARTY_SCREEN will automatically check every mon in the player's party. + .macro checkspecies speciesId:req, mode=NO_PARTY_SCREEN + .if \mode == OPEN_PARTY_SCREEN + special ChoosePartyMon + waitstate + callnative Scrcmd_checkspecies_choose + .2byte \speciesId + .else + callnative Scrcmd_checkspecies + .2byte \speciesId + .endif + .endm + + .macro checkspecies_choose speciesId:req + checkspecies \speciesId, OPEN_PARTY_SCREEN + .endm + + @ Gets the facing direction of a given event object and stores it in the variable dest. + .macro getobjectfacingdirection localId:req, dest:req + callnative Scrcmd_getobjectfacingdirection + .2byte \localId + .2byte \dest + .endm + diff --git a/data/event_scripts.s b/data/event_scripts.s index 2ef99d34fb51..50f484a17194 100644 --- a/data/event_scripts.s +++ b/data/event_scripts.s @@ -42,6 +42,7 @@ #include "constants/metatile_labels.h" #include "constants/moves.h" #include "constants/party_menu.h" +#include "constants/pokedex.h" #include "constants/pokemon.h" #include "constants/roulette.h" #include "constants/script_menu.h" diff --git a/include/constants/field_specials.h b/include/constants/field_specials.h index 1e08a47f95ee..72966adeb882 100644 --- a/include/constants/field_specials.h +++ b/include/constants/field_specials.h @@ -86,4 +86,14 @@ #define DEOXYS_ROCK_SOLVED 2 #define DEOXYS_ROCK_COMPLETE 3 +enum { + OPEN_PARTY_SCREEN, + NO_PARTY_SCREEN +}; + +enum { + CURRENT_POSITION, + TEMPLATE_POSITION +}; + #endif // GUARD_CONSTANTS_FIELD_SPECIALS_H diff --git a/include/constants/pokedex.h b/include/constants/pokedex.h index 8058f01e5c97..241198e1786b 100644 --- a/include/constants/pokedex.h +++ b/include/constants/pokedex.h @@ -1327,4 +1327,18 @@ enum { #define DEX_HGSS_Y_BOTTOM_PADDING 4 #define DEX_HGSS_MEASUREMENT_X_PADDING 51 +enum +{ + DEX_MODE_HOENN, + DEX_MODE_NATIONAL +}; + +enum +{ + FLAG_GET_SEEN, + FLAG_GET_CAUGHT, + FLAG_SET_SEEN, + FLAG_SET_CAUGHT +}; + #endif // GUARD_CONSTANTS_POKEDEX_H diff --git a/include/event_object_movement.h b/include/event_object_movement.h index 22993cddd90d..1dc604138bd6 100644 --- a/include/event_object_movement.h +++ b/include/event_object_movement.h @@ -127,6 +127,7 @@ bool8 TryGetObjectEventIdByLocalIdAndMap(u8 localId, u8 mapNum, u8 mapGroupId, u u8 GetObjectEventIdByXY(s16 x, s16 y); void SetObjectEventDirection(struct ObjectEvent *objectEvent, u8 direction); u8 GetFirstInactiveObjectEventId(void); +u8 GetObjectEventIdByLocalId(u8); void RemoveObjectEventByLocalIdAndMap(u8 localId, u8 mapNum, u8 mapGroup); void LoadSpecialObjectReflectionPalette(u16 tag, u8 slot); void TryMoveObjectEventToMapCoords(u8 localId, u8 mapNum, u8 mapGroup, s16 x, s16 y); @@ -211,6 +212,7 @@ void ObjectEventForceSetHeldMovement(struct ObjectEvent *objectEvent, u8 movemen bool8 ObjectEventIsMovementOverridden(struct ObjectEvent *objectEvent); u8 ObjectEventCheckHeldMovementStatus(struct ObjectEvent *objectEvent); u8 ObjectEventGetHeldMovementActionId(struct ObjectEvent *objectEvent); +const struct ObjectEventTemplate *FindObjectEventTemplateByLocalId(u8, const struct ObjectEventTemplate *, u8); void TryOverrideTemplateCoordsForObjectEvent(const struct ObjectEvent *objectEvent, u8 movementType); void OverrideTemplateCoordsForObjectEvent(const struct ObjectEvent *objectEvent); void ShiftStillObjectEventCoords(struct ObjectEvent *objEvent); diff --git a/include/field_specials.h b/include/field_specials.h index 95a91d543f06..f391a46ba57f 100644 --- a/include/field_specials.h +++ b/include/field_specials.h @@ -33,5 +33,8 @@ void ResetFanClub(void); bool8 ShouldShowBoxWasFullMessage(void); void SetPCBoxToSendMon(u8 boxId); void PreparePartyForSkyBattle(void); +void GetObjectPosition(u16*, u16*, u32, u32); +bool32 CheckObjectAtXY(u32, u32); +bool32 CheckPartyHasSpecie(u32); #endif // GUARD_FIELD_SPECIALS_H diff --git a/include/pokedex.h b/include/pokedex.h index be861fe682b5..0bd91449c377 100644 --- a/include/pokedex.h +++ b/include/pokedex.h @@ -4,20 +4,6 @@ extern u8 gUnusedPokedexU8; extern void (*gPokedexVBlankCB)(void); -enum -{ - DEX_MODE_HOENN, - DEX_MODE_NATIONAL -}; - -enum -{ - FLAG_GET_SEEN, - FLAG_GET_CAUGHT, - FLAG_SET_SEEN, - FLAG_SET_CAUGHT -}; - void ResetPokedex(void); u16 GetNationalPokedexCount(u8); u16 GetHoennPokedexCount(u8); diff --git a/src/event_object_movement.c b/src/event_object_movement.c index c2c9fdc42f7c..08a5920dbfc7 100644 --- a/src/event_object_movement.c +++ b/src/event_object_movement.c @@ -180,7 +180,6 @@ static void SpriteCB_CameraObject(struct Sprite *); static void CameraObject_Init(struct Sprite *); static void CameraObject_UpdateMove(struct Sprite *); static void CameraObject_UpdateFrozen(struct Sprite *); -static const struct ObjectEventTemplate *FindObjectEventTemplateByLocalId(u8, const struct ObjectEventTemplate *, u8); static void ObjectEventSetSingleMovement(struct ObjectEvent *, struct Sprite *, u8); static void SetSpriteDataForNormalStep(struct Sprite *, u8, u8); static void InitSpriteForFigure8Anim(struct Sprite *); @@ -3421,7 +3420,7 @@ static const struct ObjectEventTemplate *GetObjectEventTemplateByLocalIdAndMap(u return FindObjectEventTemplateByLocalId(localId, templates, count); } -static const struct ObjectEventTemplate *FindObjectEventTemplateByLocalId(u8 localId, const struct ObjectEventTemplate *templates, u8 count) +const struct ObjectEventTemplate *FindObjectEventTemplateByLocalId(u8 localId, const struct ObjectEventTemplate *templates, u8 count) { u8 i; diff --git a/src/field_specials.c b/src/field_specials.c index ed1a80f5324f..b3f5a63332a1 100644 --- a/src/field_specials.c +++ b/src/field_specials.c @@ -30,6 +30,7 @@ #include "overworld.h" #include "party_menu.h" #include "pokeblock.h" +#include "pokedex.h" #include "pokemon.h" #include "pokemon_storage_system.h" #include "random.h" @@ -4277,6 +4278,55 @@ void PreparePartyForSkyBattle(void) CompactPartySlots(); } +void GetObjectPosition(u16* xPointer, u16* yPointer, u32 localId, u32 useTemplate) +{ + u32 objectId; + struct ObjectEvent* objEvent; + + if (useTemplate) + { + const struct ObjectEventTemplate *objTemplate = FindObjectEventTemplateByLocalId(localId, gSaveBlock1Ptr->objectEventTemplates, gMapHeader.events->objectEventCount); + *xPointer = objTemplate->x; + *yPointer = objTemplate->y; + return; + } + + objectId = GetObjectEventIdByLocalId(localId); + objEvent = &gObjectEvents[objectId]; + *xPointer = objEvent->currentCoords.x - 7; + *yPointer = objEvent->currentCoords.y - 7; +} + +bool32 CheckObjectAtXY(u32 x, u32 y) +{ + u32 i; + + for (i = 0; i < OBJECT_EVENTS_COUNT; i++) + { + if (!gObjectEvents[i].active) + continue; + + if (gObjectEvents[i].currentCoords.x != x) + continue; + + if (gObjectEvents[i].currentCoords.y != y) + continue; + return TRUE; + } + return FALSE; +} + +bool32 CheckPartyHasSpecie(u32 givenSpecies) +{ + u32 partyIndex; + + for (partyIndex = 0; partyIndex < CalculatePlayerPartyCount(); partyIndex++) + if (GetMonData(&gPlayerParty[partyIndex], MON_DATA_SPECIES) == givenSpecies) + return TRUE; + + return FALSE; +} + void UseBlankMessageToCancelPokemonPic(void) { u8 t = EOS; diff --git a/src/scrcmd.c b/src/scrcmd.c index ef5084681e55..bef273b0bad7 100644 --- a/src/scrcmd.c +++ b/src/scrcmd.c @@ -32,6 +32,7 @@ #include "mystery_event_script.h" #include "palette.h" #include "party_menu.h" +#include "pokedex.h" #include "pokemon_storage_system.h" #include "random.h" #include "overworld.h" @@ -2478,3 +2479,73 @@ void ScriptSetDoubleBattleFlag(struct ScriptContext *ctx) { sIsScriptedWildDouble = TRUE; } + +bool8 ScrCmd_removeallitem(struct ScriptContext *ctx) +{ + u32 itemId = VarGet(ScriptReadHalfword(ctx)); + u32 count = CountTotalItemQuantityInBag(itemId); + gSpecialVar_Result = count; + RemoveBagItem(itemId, count); + + return FALSE; +} + +bool8 ScrCmd_getobjectxy(struct ScriptContext *ctx) +{ + u32 localId = VarGet(ScriptReadHalfword(ctx)); + u32 useTemplate = VarGet(ScriptReadHalfword(ctx)); + u16 *pX = GetVarPointer(ScriptReadHalfword(ctx)); + u16 *pY = GetVarPointer(ScriptReadHalfword(ctx)); + GetObjectPosition(pX,pY,localId,useTemplate); + + return FALSE; +} + +bool8 ScrCmd_checkobjectat(struct ScriptContext *ctx) +{ + u32 x = VarGet(ScriptReadHalfword(ctx)) + 7; + u32 y = VarGet(ScriptReadHalfword(ctx)) + 7; + u16 *varPointer = GetVarPointer(ScriptReadHalfword(ctx)); + + *varPointer = CheckObjectAtXY(x,y); + + return FALSE; +} + +bool8 Scrcmd_getsetpokedexflag(struct ScriptContext *ctx) +{ + u32 speciesId = SpeciesToNationalPokedexNum(VarGet(ScriptReadHalfword(ctx))); + bool32 desiredFlag = VarGet(ScriptReadHalfword(ctx)); + gSpecialVar_Result = GetSetPokedexFlag(speciesId,desiredFlag); + + if (desiredFlag == FLAG_SET_CAUGHT) + GetSetPokedexFlag(speciesId,FLAG_SET_SEEN); + + return FALSE; +} + +bool8 Scrcmd_checkspecies(struct ScriptContext *ctx) +{ + u32 givenSpecies = VarGet(ScriptReadHalfword(ctx)); + gSpecialVar_Result = CheckPartyHasSpecie(givenSpecies); + + return FALSE; +} + +bool8 Scrcmd_checkspecies_choose(struct ScriptContext *ctx) +{ + u32 givenSpecies = VarGet(ScriptReadHalfword(ctx)); + gSpecialVar_Result = (GetMonData(&gPlayerParty[gSpecialVar_0x8004], MON_DATA_SPECIES) == givenSpecies); + + return FALSE; +} + +bool8 Scrcmd_getobjectfacingdirection(struct ScriptContext *ctx) +{ + u32 objectId = VarGet(ScriptReadHalfword(ctx)); + u16 *varPointer = GetVarPointer(ScriptReadHalfword(ctx)); + + *varPointer = gObjectEvents[GetObjectEventIdByLocalId(objectId)].facingDirection; + + return FALSE; +}