From 73953b3e39353687b757fb760765cc3b66fef59e Mon Sep 17 00:00:00 2001 From: pkmnsnfrn Date: Sat, 10 Aug 2024 14:43:50 -0700 Subject: [PATCH 01/31] Added removeallitem --- asm/macros/event.inc | 6 ++++++ src/scrcmd.c | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/asm/macros/event.inc b/asm/macros/event.inc index 891c7fd4edea..f5abad6f295d 100644 --- a/asm/macros/event.inc +++ b/asm/macros/event.inc @@ -2321,3 +2321,9 @@ .macro togglefakertc callnative Script_ToggleFakeRtc .endm + + @ Remove all of specified item from the player's bag + .macro removeallitem itemId:req + callnative RemoveAllItem + .2byte \itemId + .endm diff --git a/src/scrcmd.c b/src/scrcmd.c index 319e66756669..955b5e00ddf2 100644 --- a/src/scrcmd.c +++ b/src/scrcmd.c @@ -2473,3 +2473,9 @@ void ScriptSetDoubleBattleFlag(struct ScriptContext *ctx) { sIsScriptedWildDouble = TRUE; } + +void RemoveAllItem(struct ScriptContext *ctx) +{ + u16 itemId = VarGet(ScriptReadHalfword(ctx)); + RemoveBagItem(itemId, CountTotalItemQuantityInBag(itemId)); +} From 811b5d286e02ec7f433cd3f11692c2a56370b9f4 Mon Sep 17 00:00:00 2001 From: pkmnsnfrn Date: Sat, 10 Aug 2024 21:17:50 -0700 Subject: [PATCH 02/31] Added getobjectposition --- asm/macros/event.inc | 7 +++++++ data/specials.inc | 1 + include/event_object_movement.h | 2 ++ src/event_object_movement.c | 16 +++++++--------- src/field_specials.c | 28 ++++++++++++++++++++++++++++ 5 files changed, 45 insertions(+), 9 deletions(-) diff --git a/asm/macros/event.inc b/asm/macros/event.inc index f5abad6f295d..c6e6e8847adf 100644 --- a/asm/macros/event.inc +++ b/asm/macros/event.inc @@ -2327,3 +2327,10 @@ callnative RemoveAllItem .2byte \itemId .endm + + @ return current (posType = 0) or map (posType = 1) position of object to VAR_0x8007 (x), VAR_0x8008 (y) + .macro getobjectxy localId:req, posType:req + setvar VAR_0x8000, \localId + setvar VAR_0x8001, \posType + special GetObjectPosition + .endm diff --git a/data/specials.inc b/data/specials.inc index f02497d6039e..32f2f633082f 100644 --- a/data/specials.inc +++ b/data/specials.inc @@ -554,3 +554,4 @@ gSpecials:: def_special Script_GetChosenMonDefensiveEVs def_special Script_GetChosenMonOffensiveIVs def_special Script_GetChosenMonDefensiveIVs + def_special GetObjectPosition diff --git a/include/event_object_movement.h b/include/event_object_movement.h index 2906789b3754..92675f01f765 100644 --- a/include/event_object_movement.h +++ b/include/event_object_movement.h @@ -126,6 +126,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); @@ -210,6 +211,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/src/event_object_movement.c b/src/event_object_movement.c index 5a6eb28fc3d1..e4732cac9690 100644 --- a/src/event_object_movement.c +++ b/src/event_object_movement.c @@ -157,7 +157,6 @@ static void ApplyLevitateMovement(u8); static bool8 MovementType_Disguise_Callback(struct ObjectEvent *, struct Sprite *); static bool8 MovementType_Buried_Callback(struct ObjectEvent *, struct Sprite *); static void CreateReflectionEffectSprites(void); -static u8 GetObjectEventIdByLocalId(u8); static u8 GetObjectEventIdByLocalIdAndMapInternal(u8, u8, u8); static bool8 GetAvailableObjectEventId(u16, u8, u8, u8 *); static void SetObjectEventDynamicGraphicsId(struct ObjectEvent *); @@ -179,7 +178,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 *); @@ -1298,7 +1296,7 @@ static u8 GetObjectEventIdByLocalIdAndMapInternal(u8 localId, u8 mapNum, u8 mapG return OBJECT_EVENTS_COUNT; } -static u8 GetObjectEventIdByLocalId(u8 localId) +u8 GetObjectEventIdByLocalId(u8 localId) { u8 i; for (i = 0; i < OBJECT_EVENTS_COUNT; i++) @@ -1493,7 +1491,7 @@ static s16 ReallocSpriteTiles(struct Sprite *sprite, u32 byteSize) { i = -1; } - + sprite->invisible = wasVisible; return i; } @@ -1510,7 +1508,7 @@ u16 LoadSheetGraphicsInfo(const struct ObjectEventGraphicsInfo *info, u16 uuid, bool32 oldInvisible; if (tag == TAG_NONE) tag = COMP_OW_TILE_TAG_BASE + uuid; - + if (sprite) { oldInvisible = sprite->invisible; @@ -1547,7 +1545,7 @@ u16 LoadSheetGraphicsInfo(const struct ObjectEventGraphicsInfo *info, u16 uuid, { FieldEffectFreeTilesIfUnused(oldTiles); } - + if (sprite) { sprite->sheetTileStart = tileStart; @@ -1566,7 +1564,7 @@ u16 LoadSheetGraphicsInfo(const struct ObjectEventGraphicsInfo *info, u16 uuid, { sprite->oam.tileNum = sprite->sheetTileStart; sprite->usingSheet = FALSE; - + } else if (sprite && !sprite->sheetTileStart && sprite->oam.size != info->oam->size) { @@ -1925,7 +1923,7 @@ static u8 LoadDynamicFollowerPalette(u16 species, u8 form, bool32 shiny) spritePalette.data = gSpeciesInfo[species].overworldShinyPalette; else spritePalette.data = gSpeciesInfo[species].overworldPalette; - + // Check if pal data must be decompressed if (IsLZ77Data(spritePalette.data, PLTT_SIZE_4BPP, PLTT_SIZE_4BPP)) { @@ -3306,7 +3304,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 b44c8327aad8..471d88132ca8 100644 --- a/src/field_specials.c +++ b/src/field_specials.c @@ -4266,3 +4266,31 @@ void PreparePartyForSkyBattle(void) VarSet(B_VAR_SKY_BATTLE,participatingPokemonSlot); CompactPartySlots(); } + +// get position (0 for current, 1 for map) of object event, return to VAR_0x8007, VAR_0x8008 +void GetObjectPosition(void) +{ + u16 localId = gSpecialVar_0x8000; + u16 useTemplate = gSpecialVar_0x8001; + + u16 *x = &gSpecialVar_0x8007; + u16 *y = &gSpecialVar_0x8008; + + if (!useTemplate) + { + /* current position */ + const u16 objId = GetObjectEventIdByLocalId(localId); + const struct ObjectEvent *objEvent = &gObjectEvents[objId]; + *x = objEvent->currentCoords.x - 7; // subtract out camera size + *y = objEvent->currentCoords.y - 7; + } + else + { + const struct ObjectEventTemplate *objTemplate = + FindObjectEventTemplateByLocalId(localId, + gSaveBlock1Ptr->objectEventTemplates, + gMapHeader.events->objectEventCount); + *x = objTemplate->x; + *y = objTemplate->y; + } +} From 0784f9fa740f697ecf1ef32c809014304603a8a4 Mon Sep 17 00:00:00 2001 From: pkmnsnfrn Date: Sat, 10 Aug 2024 21:40:57 -0700 Subject: [PATCH 03/31] Added checkobjectat --- asm/macros/event.inc | 7 +++++++ data/specials.inc | 1 + src/field_specials.c | 16 ++++++++++++++++ 3 files changed, 24 insertions(+) diff --git a/asm/macros/event.inc b/asm/macros/event.inc index c6e6e8847adf..0fb6414f61c6 100644 --- a/asm/macros/event.inc +++ b/asm/macros/event.inc @@ -2334,3 +2334,10 @@ setvar VAR_0x8001, \posType special GetObjectPosition .endm + + @ checks if there is any object at a given position + .macro checkobjectat x:req, y:req + setorcopyvar VAR_0x8005, \x + setorcopyvar VAR_0x8006, \y + specialvar VAR_RESULT, CheckObjectAtXY + .endm diff --git a/data/specials.inc b/data/specials.inc index 32f2f633082f..aa994a31f6a7 100644 --- a/data/specials.inc +++ b/data/specials.inc @@ -555,3 +555,4 @@ gSpecials:: def_special Script_GetChosenMonOffensiveIVs def_special Script_GetChosenMonDefensiveIVs def_special GetObjectPosition + def_special CheckObjectAtXY diff --git a/src/field_specials.c b/src/field_specials.c index 471d88132ca8..3014d4840735 100644 --- a/src/field_specials.c +++ b/src/field_specials.c @@ -4294,3 +4294,19 @@ void GetObjectPosition(void) *y = objTemplate->y; } } + +// special to check if there is any object at a given position +u16 CheckObjectAtXY(void) +{ + u16 x = gSpecialVar_0x8005 + 7; + u16 y = gSpecialVar_0x8006 + 7; + u32 i; + + for (i = 0; i < OBJECT_EVENTS_COUNT; i++) + { + if (gObjectEvents[i].active && gObjectEvents[i].currentCoords.x == x && gObjectEvents[i].currentCoords.y == y) + return TRUE; + } + return FALSE; +} + From fba1452c3b7169a4ea54fba3956299392c4a0d76 Mon Sep 17 00:00:00 2001 From: pkmnsnfrn Date: Sun, 11 Aug 2024 18:49:42 -0700 Subject: [PATCH 04/31] Added Seen/CaughtMon macros --- asm/macros/event.inc | 26 ++++++++++++++++++++++++++ data/specials.inc | 4 ++++ src/field_specials.c | 22 ++++++++++++++++++++++ 3 files changed, 52 insertions(+) diff --git a/asm/macros/event.inc b/asm/macros/event.inc index 0fb6414f61c6..e3c47c04ea92 100644 --- a/asm/macros/event.inc +++ b/asm/macros/event.inc @@ -2341,3 +2341,29 @@ setorcopyvar VAR_0x8006, \y specialvar VAR_RESULT, CheckObjectAtXY .endm + + @ Checks the state of the Pokédex Seen flag of the specified Pokemon + @ The result is stored in VAR_RESULT + .macro getseenmon species:req + setvar VAR_TEMP_1, \species + specialvar VAR_RESULT, GetSeenMon + .endm + + @ Checks the state of the Pokédex Caught flag of the specified Pokemon + @ The result is stored in VAR_RESULT + .macro getcaughtmon species:req + setvar VAR_TEMP_1, \species + specialvar VAR_RESULT, GetCaughtMon + .endm + + @ Sets the Pokédex Seen flag of the specified Pokemon + .macro setseenmon species:req + setvar VAR_TEMP_1, \species + special SetSeenMon + .endm + + @ Sets the Pokédex Caught flag of the specified Pokemon + .macro setcaughtmon species:req + setvar VAR_TEMP_1, \species + special SetCaughtMon + .endm diff --git a/data/specials.inc b/data/specials.inc index aa994a31f6a7..8f17fd8e5527 100644 --- a/data/specials.inc +++ b/data/specials.inc @@ -556,3 +556,7 @@ gSpecials:: def_special Script_GetChosenMonDefensiveIVs def_special GetObjectPosition def_special CheckObjectAtXY + def_special GetSeenMon + def_special GetCaughtMon + def_special SetSeenMon + def_special SetCaughtMon diff --git a/src/field_specials.c b/src/field_specials.c index 3014d4840735..64330d2e6dc7 100644 --- a/src/field_specials.c +++ b/src/field_specials.c @@ -68,6 +68,7 @@ #include "constants/metatile_labels.h" #include "palette.h" #include "battle_util.h" +#include "pokedex.h" #define TAG_ITEM_ICON 5500 @@ -4310,3 +4311,24 @@ u16 CheckObjectAtXY(void) return FALSE; } +bool8 GetSeenMon(void) +{ + return GetSetPokedexFlag(SpeciesToNationalPokedexNum(VarGet(VAR_TEMP_1)), FLAG_GET_SEEN); +} + +bool8 GetCaughtMon(void) +{ + return GetSetPokedexFlag(SpeciesToNationalPokedexNum(VarGet(VAR_TEMP_1)), FLAG_GET_CAUGHT); +} + +void SetSeenMon(void) +{ + GetSetPokedexFlag(SpeciesToNationalPokedexNum(VarGet(VAR_TEMP_1)), FLAG_SET_SEEN); +} + +void SetCaughtMon(void) +{ + GetSetPokedexFlag(SpeciesToNationalPokedexNum(VarGet(VAR_TEMP_1)), FLAG_SET_SEEN); + GetSetPokedexFlag(SpeciesToNationalPokedexNum(VarGet(VAR_TEMP_1)), FLAG_SET_CAUGHT); +} + From e746334e1e664f6e5eaa8defa6b3a4d73b5a9283 Mon Sep 17 00:00:00 2001 From: pkmnsnfrn Date: Sun, 11 Aug 2024 18:53:39 -0700 Subject: [PATCH 05/31] Added setmonball --- asm/macros/event.inc | 8 ++++++++ data/specials.inc | 1 + src/field_specials.c | 5 +++++ 3 files changed, 14 insertions(+) diff --git a/asm/macros/event.inc b/asm/macros/event.inc index e3c47c04ea92..7529edc55ad8 100644 --- a/asm/macros/event.inc +++ b/asm/macros/event.inc @@ -2367,3 +2367,11 @@ setvar VAR_TEMP_1, \species special SetCaughtMon .endm + + @ Changes the caught ball of a selected Pokémon + .macro setmonball ballId:req + special ChoosePartyMon + waitstate + setvar VAR_TEMP_1, \ballId + special SetMonBall + .endm diff --git a/data/specials.inc b/data/specials.inc index 8f17fd8e5527..67e82c0e1867 100644 --- a/data/specials.inc +++ b/data/specials.inc @@ -560,3 +560,4 @@ gSpecials:: def_special GetCaughtMon def_special SetSeenMon def_special SetCaughtMon + def_special SetMonBall diff --git a/src/field_specials.c b/src/field_specials.c index 64330d2e6dc7..a574083ae44a 100644 --- a/src/field_specials.c +++ b/src/field_specials.c @@ -4332,3 +4332,8 @@ void SetCaughtMon(void) GetSetPokedexFlag(SpeciesToNationalPokedexNum(VarGet(VAR_TEMP_1)), FLAG_SET_CAUGHT); } +void SetMonBall(void) +{ + u16 ballId = VarGet(VAR_TEMP_1); + SetMonData(&gPlayerParty[gSpecialVar_0x8004], MON_DATA_POKEBALL, &ballId); +} From 262505589a69a71cf7995624ff67a00b0d2a6fb3 Mon Sep 17 00:00:00 2001 From: pkmnsnfrn Date: Sun, 11 Aug 2024 19:19:15 -0700 Subject: [PATCH 06/31] checkforspecies --- asm/macros/event.inc | 17 +++++++++++++++++ data/specials.inc | 1 + src/field_specials.c | 12 ++++++++++++ 3 files changed, 30 insertions(+) diff --git a/asm/macros/event.inc b/asm/macros/event.inc index 7529edc55ad8..da6935ed3c56 100644 --- a/asm/macros/event.inc +++ b/asm/macros/event.inc @@ -2375,3 +2375,20 @@ setvar VAR_TEMP_1, \ballId special SetMonBall .endm + + OPEN_PARTY_SCREEN = FALSE + NO_PARTY_SCREEN = TRUE + + @ Check if the Player has \speciesId in their party. + .macro checkforspecies speciesId:req, silent:req, script:req + .if \silent == OPEN_PARTY_SCREEN + special ChoosePartyMon + waitstate + specialvar VAR_RESULT, ScriptGetPartyMonSpecies + goto_if_eq VAR_RESULT, \speciesId, \script + .else + setvar VAR_TEMP_1, \speciesId + specialvar VAR_RESULT, CheckPartyForMon + goto_if_eq VAR_RESULT, TRUE, \script + .endif + .endm diff --git a/data/specials.inc b/data/specials.inc index 67e82c0e1867..00a8c5402978 100644 --- a/data/specials.inc +++ b/data/specials.inc @@ -561,3 +561,4 @@ gSpecials:: def_special SetSeenMon def_special SetCaughtMon def_special SetMonBall + def_special CheckPartyForMon diff --git a/src/field_specials.c b/src/field_specials.c index a574083ae44a..78ac17678b52 100644 --- a/src/field_specials.c +++ b/src/field_specials.c @@ -4337,3 +4337,15 @@ void SetMonBall(void) u16 ballId = VarGet(VAR_TEMP_1); SetMonData(&gPlayerParty[gSpecialVar_0x8004], MON_DATA_POKEBALL, &ballId); } + +bool8 CheckPartyForMon(void) +{ + int i; + for (i = 0; i < CalculatePlayerPartyCount(); i++) + { + if (GetMonData(&gPlayerParty[i], MON_DATA_SPECIES) == VarGet(VAR_TEMP_1)) + return TRUE; + } + return FALSE; +} + From 7f5ecd8d0f5f95d284241d83b04a33df2b02322d Mon Sep 17 00:00:00 2001 From: pkmnsnfrn Date: Sun, 11 Aug 2024 19:27:18 -0700 Subject: [PATCH 07/31] getobjectfacingdirection --- asm/macros/event.inc | 6 ++++++ data/specials.inc | 1 + src/event_object_movement.c | 7 +++++++ 3 files changed, 14 insertions(+) diff --git a/asm/macros/event.inc b/asm/macros/event.inc index da6935ed3c56..f29a2dfb06e8 100644 --- a/asm/macros/event.inc +++ b/asm/macros/event.inc @@ -2392,3 +2392,9 @@ goto_if_eq VAR_RESULT, TRUE, \script .endif .endm + + @ Gets the facing direction of a given event object and stores it in the variable \dest. + .macro getobjectfacingdirection evObjId:req, dest:req + setvar VAR_TEMP_1, \evObjId + specialvar \dest, Script_GetObjectFacingDirection + .endm diff --git a/data/specials.inc b/data/specials.inc index 00a8c5402978..5b0aa23ddd12 100644 --- a/data/specials.inc +++ b/data/specials.inc @@ -562,3 +562,4 @@ gSpecials:: def_special SetCaughtMon def_special SetMonBall def_special CheckPartyForMon + def_special Script_GetObjectFacingDirection diff --git a/src/event_object_movement.c b/src/event_object_movement.c index e4732cac9690..7facbab5c98e 100644 --- a/src/event_object_movement.c +++ b/src/event_object_movement.c @@ -10632,3 +10632,10 @@ void GetDaycareGraphics(struct ScriptContext *ctx) } gSpecialVar_Result = i; } + +u8 Script_GetObjectFacingDirection(void) +{ + u8 objId = GetObjectEventIdByLocalId(VarGet(VAR_TEMP_1)); + return gObjectEvents[objId].facingDirection; +} + From 7869cb4137fcc48a4725110dd5767265aa812a42 Mon Sep 17 00:00:00 2001 From: pkmnsnfrn Date: Sun, 11 Aug 2024 19:31:52 -0700 Subject: [PATCH 08/31] Improved RemoveAllItem --- src/scrcmd.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/scrcmd.c b/src/scrcmd.c index 955b5e00ddf2..12ec04189556 100644 --- a/src/scrcmd.c +++ b/src/scrcmd.c @@ -2476,6 +2476,6 @@ void ScriptSetDoubleBattleFlag(struct ScriptContext *ctx) void RemoveAllItem(struct ScriptContext *ctx) { - u16 itemId = VarGet(ScriptReadHalfword(ctx)); + u32 itemId = VarGet(ScriptReadHalfword(ctx)); RemoveBagItem(itemId, CountTotalItemQuantityInBag(itemId)); } From ebae09f0a6b9132ad53c925d9717dcb4b07247f3 Mon Sep 17 00:00:00 2001 From: pkmnsnfrn Date: Sun, 11 Aug 2024 20:16:27 -0700 Subject: [PATCH 09/31] Improved checkobjectat --- asm/macros/event.inc | 5 +++- src/field_specials.c | 67 ++++++++++++++++++++++---------------------- 2 files changed, 38 insertions(+), 34 deletions(-) diff --git a/asm/macros/event.inc b/asm/macros/event.inc index f29a2dfb06e8..9375b7be9aa9 100644 --- a/asm/macros/event.inc +++ b/asm/macros/event.inc @@ -2328,7 +2328,10 @@ .2byte \itemId .endm - @ return current (posType = 0) or map (posType = 1) position of object to VAR_0x8007 (x), VAR_0x8008 (y) + CURRENT_POSITION = FALSE + TEMPLATE_POSITION = TRUE + + @ Stores the CURRENT / TEMPLATE position of the given object in VAR_0x8007 (x) and VAR_0x8008 (y) .macro getobjectxy localId:req, posType:req setvar VAR_0x8000, \localId setvar VAR_0x8001, \posType diff --git a/src/field_specials.c b/src/field_specials.c index 78ac17678b52..98a909d72553 100644 --- a/src/field_specials.c +++ b/src/field_specials.c @@ -4268,47 +4268,48 @@ void PreparePartyForSkyBattle(void) CompactPartySlots(); } -// get position (0 for current, 1 for map) of object event, return to VAR_0x8007, VAR_0x8008 void GetObjectPosition(void) { - u16 localId = gSpecialVar_0x8000; - u16 useTemplate = gSpecialVar_0x8001; + u32 localId = gSpecialVar_0x8000; + u32 useTemplate = gSpecialVar_0x8001; + u32 objectId; + struct ObjectEvent* objEvent; - u16 *x = &gSpecialVar_0x8007; - u16 *y = &gSpecialVar_0x8008; + u16 *x = &gSpecialVar_0x8007; + u16 *y = &gSpecialVar_0x8008; - if (!useTemplate) - { - /* current position */ - const u16 objId = GetObjectEventIdByLocalId(localId); - const struct ObjectEvent *objEvent = &gObjectEvents[objId]; - *x = objEvent->currentCoords.x - 7; // subtract out camera size - *y = objEvent->currentCoords.y - 7; - } - else - { - const struct ObjectEventTemplate *objTemplate = - FindObjectEventTemplateByLocalId(localId, - gSaveBlock1Ptr->objectEventTemplates, - gMapHeader.events->objectEventCount); - *x = objTemplate->x; - *y = objTemplate->y; - } + if (useTemplate) + { + const struct ObjectEventTemplate *objTemplate = FindObjectEventTemplateByLocalId(localId, gSaveBlock1Ptr->objectEventTemplates, gMapHeader.events->objectEventCount); + *x = objTemplate->x; + *y = objTemplate->y; + return; + } + + objectId = GetObjectEventIdByLocalId(localId); + objEvent = &gObjectEvents[objectId]; + *x = objEvent->currentCoords.x - 7; + *y = objEvent->currentCoords.y - 7; } -// special to check if there is any object at a given position -u16 CheckObjectAtXY(void) +bool32 CheckObjectAtXY(void) { - u16 x = gSpecialVar_0x8005 + 7; - u16 y = gSpecialVar_0x8006 + 7; - u32 i; + u32 x = gSpecialVar_0x8005 + 7; + u32 y = gSpecialVar_0x8006 + 7; + u32 i; - for (i = 0; i < OBJECT_EVENTS_COUNT; i++) - { - if (gObjectEvents[i].active && gObjectEvents[i].currentCoords.x == x && gObjectEvents[i].currentCoords.y == y) - return TRUE; - } - return FALSE; + for (i = 0; i < OBJECT_EVENTS_COUNT; i++) + { + if (!gObjectEvents[i].active) + return FALSE; + + if (gObjectEvents[i].currentCoords.x != x) + return FALSE; + + if (gObjectEvents[i].currentCoords.y != y) + return FALSE; + } + return TRUE; } bool8 GetSeenMon(void) From abb17ea88b19579b66804408801cc433462bfc39 Mon Sep 17 00:00:00 2001 From: pkmnsnfrn Date: Sun, 11 Aug 2024 21:01:31 -0700 Subject: [PATCH 10/31] Improved dex flags functions --- asm/macros/event.inc | 20 ++++++++++++-------- data/specials.inc | 5 +---- src/field_specials.c | 22 ++++++---------------- 3 files changed, 19 insertions(+), 28 deletions(-) diff --git a/asm/macros/event.inc b/asm/macros/event.inc index 9375b7be9aa9..c4bbda645fd4 100644 --- a/asm/macros/event.inc +++ b/asm/macros/event.inc @@ -2348,27 +2348,31 @@ @ Checks the state of the Pokédex Seen flag of the specified Pokemon @ The result is stored in VAR_RESULT .macro getseenmon species:req - setvar VAR_TEMP_1, \species - specialvar VAR_RESULT, GetSeenMon + setvar VAR_0x8005, \species + setvar VAR_0x8006, 0 + specialvar VAR_RESULT, Script_GetSetPokedexFlag .endm @ Checks the state of the Pokédex Caught flag of the specified Pokemon @ The result is stored in VAR_RESULT .macro getcaughtmon species:req - setvar VAR_TEMP_1, \species - specialvar VAR_RESULT, GetCaughtMon + setvar VAR_0x8005, \species + setvar VAR_0x8006, 1 + specialvar VAR_RESULT, Script_GetSetPokedexFlag .endm @ Sets the Pokédex Seen flag of the specified Pokemon .macro setseenmon species:req - setvar VAR_TEMP_1, \species - special SetSeenMon + setvar VAR_0x8005, \species + setvar VAR_0x8006, 2 + specialvar VAR_RESULT, Script_GetSetPokedexFlag .endm @ Sets the Pokédex Caught flag of the specified Pokemon .macro setcaughtmon species:req - setvar VAR_TEMP_1, \species - special SetCaughtMon + setvar VAR_0x8005, \species + setvar VAR_0x8006, 3 + specialvar VAR_RESULT, Script_GetSetPokedexFlag .endm @ Changes the caught ball of a selected Pokémon diff --git a/data/specials.inc b/data/specials.inc index 5b0aa23ddd12..7b391cc96850 100644 --- a/data/specials.inc +++ b/data/specials.inc @@ -556,10 +556,7 @@ gSpecials:: def_special Script_GetChosenMonDefensiveIVs def_special GetObjectPosition def_special CheckObjectAtXY - def_special GetSeenMon - def_special GetCaughtMon - def_special SetSeenMon - def_special SetCaughtMon + def_special Script_GetSetPokedexFlag def_special SetMonBall def_special CheckPartyForMon def_special Script_GetObjectFacingDirection diff --git a/src/field_specials.c b/src/field_specials.c index 98a909d72553..a161ba3c44e6 100644 --- a/src/field_specials.c +++ b/src/field_specials.c @@ -4312,25 +4312,15 @@ bool32 CheckObjectAtXY(void) return TRUE; } -bool8 GetSeenMon(void) +bool32 Script_GetSetPokedexFlag(void) { - return GetSetPokedexFlag(SpeciesToNationalPokedexNum(VarGet(VAR_TEMP_1)), FLAG_GET_SEEN); -} + u32 speciesId = SpeciesToNationalPokedexNum(gSpecialVar_0x8005); + bool32 desiredFlag = gSpecialVar_0x8006; -bool8 GetCaughtMon(void) -{ - return GetSetPokedexFlag(SpeciesToNationalPokedexNum(VarGet(VAR_TEMP_1)), FLAG_GET_CAUGHT); -} + if (desiredFlag == FLAG_SET_CAUGHT) + GetSetPokedexFlag(speciesId,FLAG_SET_SEEN); -void SetSeenMon(void) -{ - GetSetPokedexFlag(SpeciesToNationalPokedexNum(VarGet(VAR_TEMP_1)), FLAG_SET_SEEN); -} - -void SetCaughtMon(void) -{ - GetSetPokedexFlag(SpeciesToNationalPokedexNum(VarGet(VAR_TEMP_1)), FLAG_SET_SEEN); - GetSetPokedexFlag(SpeciesToNationalPokedexNum(VarGet(VAR_TEMP_1)), FLAG_SET_CAUGHT); + return GetSetPokedexFlag(speciesId,desiredFlag); } void SetMonBall(void) From f0d5b68f70aabdc41af0f56f4fc6e29b25b37596 Mon Sep 17 00:00:00 2001 From: pkmnsnfrn Date: Sun, 11 Aug 2024 22:10:04 -0700 Subject: [PATCH 11/31] Improved checkspecies functions --- asm/macros/event.inc | 22 ++++++++++++++-------- data/specials.inc | 3 ++- src/field_specials.c | 19 ++++++++++++------- 3 files changed, 28 insertions(+), 16 deletions(-) diff --git a/asm/macros/event.inc b/asm/macros/event.inc index c4bbda645fd4..399ad6104fa5 100644 --- a/asm/macros/event.inc +++ b/asm/macros/event.inc @@ -2379,7 +2379,7 @@ .macro setmonball ballId:req special ChoosePartyMon waitstate - setvar VAR_TEMP_1, \ballId + setvar VAR_0x8005, \ballId special SetMonBall .endm @@ -2387,19 +2387,25 @@ NO_PARTY_SCREEN = TRUE @ Check if the Player has \speciesId in their party. - .macro checkforspecies speciesId:req, silent:req, script:req - .if \silent == OPEN_PARTY_SCREEN + .macro checkspecies speciesId:req, mode:req + setvar VAR_0x8005, \speciesId + .if \mode == OPEN_PARTY_SCREEN special ChoosePartyMon waitstate - specialvar VAR_RESULT, ScriptGetPartyMonSpecies - goto_if_eq VAR_RESULT, \speciesId, \script + specialvar VAR_RESULT, CheckChosenMonMatchDesiredSpecie .else - setvar VAR_TEMP_1, \speciesId - specialvar VAR_RESULT, CheckPartyForMon - goto_if_eq VAR_RESULT, TRUE, \script + specialvar VAR_RESULT, CheckPartyHasSpecie .endif .endm + .macro checkspecies_choose speciesId:req + checkspecies \speciesId, OPEN_PARTY_SCREEN + .endm + + .macro checkspecies_auto speciesId:req + checkspecies \speciesId, NO_PARTY_SCREEN + .endm + @ Gets the facing direction of a given event object and stores it in the variable \dest. .macro getobjectfacingdirection evObjId:req, dest:req setvar VAR_TEMP_1, \evObjId diff --git a/data/specials.inc b/data/specials.inc index 7b391cc96850..ed88d42eaeac 100644 --- a/data/specials.inc +++ b/data/specials.inc @@ -558,5 +558,6 @@ gSpecials:: def_special CheckObjectAtXY def_special Script_GetSetPokedexFlag def_special SetMonBall - def_special CheckPartyForMon + def_special CheckPartyHasSpecie + def_special CheckChosenMonMatchDesiredSpecie def_special Script_GetObjectFacingDirection diff --git a/src/field_specials.c b/src/field_specials.c index a161ba3c44e6..e58d861f547f 100644 --- a/src/field_specials.c +++ b/src/field_specials.c @@ -4325,18 +4325,23 @@ bool32 Script_GetSetPokedexFlag(void) void SetMonBall(void) { - u16 ballId = VarGet(VAR_TEMP_1); + u32 ballId = gSpecialVar_0x8005; SetMonData(&gPlayerParty[gSpecialVar_0x8004], MON_DATA_POKEBALL, &ballId); } -bool8 CheckPartyForMon(void) +bool32 CheckPartyHasSpecie(void) { - int i; - for (i = 0; i < CalculatePlayerPartyCount(); i++) - { - if (GetMonData(&gPlayerParty[i], MON_DATA_SPECIES) == VarGet(VAR_TEMP_1)) + u32 partyIndex; + + for (partyIndex = 0; partyIndex < CalculatePlayerPartyCount(); partyIndex++) + if (GetMonData(&gPlayerParty[partyIndex], MON_DATA_SPECIES) == gSpecialVar_0x8005) return TRUE; - } + return FALSE; } +bool32 CheckChosenMonMatchDesiredSpecie(void) +{ + return (GetMonData(&gPlayerParty[gSpecialVar_0x8004], MON_DATA_SPECIES) == gSpecialVar_0x8005); +} + From 881e54a52b965c87359774f80a516358f2001ecc Mon Sep 17 00:00:00 2001 From: pkmnsnfrn Date: Mon, 12 Aug 2024 06:51:09 -0700 Subject: [PATCH 12/31] Incremental improvement of getobjectfacing --- asm/macros/event.inc | 3 ++- src/event_object_movement.c | 5 ++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/asm/macros/event.inc b/asm/macros/event.inc index 399ad6104fa5..9321f5b8c524 100644 --- a/asm/macros/event.inc +++ b/asm/macros/event.inc @@ -2408,6 +2408,7 @@ @ Gets the facing direction of a given event object and stores it in the variable \dest. .macro getobjectfacingdirection evObjId:req, dest:req - setvar VAR_TEMP_1, \evObjId + setvar VAR_0x8005, \evObjId specialvar \dest, Script_GetObjectFacingDirection .endm + diff --git a/src/event_object_movement.c b/src/event_object_movement.c index 7facbab5c98e..4105aa42a55c 100644 --- a/src/event_object_movement.c +++ b/src/event_object_movement.c @@ -10633,9 +10633,8 @@ void GetDaycareGraphics(struct ScriptContext *ctx) gSpecialVar_Result = i; } -u8 Script_GetObjectFacingDirection(void) +u32 Script_GetObjectFacingDirection(void) { - u8 objId = GetObjectEventIdByLocalId(VarGet(VAR_TEMP_1)); - return gObjectEvents[objId].facingDirection; + return gObjectEvents[GetObjectEventIdByLocalId(gSpecialVar_0x8005)].facingDirection; } From bdeedaa9499e8866251242b48d5959ac7ce72c76 Mon Sep 17 00:00:00 2001 From: pkmnsnfrn Date: Wed, 14 Aug 2024 19:05:30 -0700 Subject: [PATCH 13/31] Renamed evObjId to localId --- asm/macros/event.inc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/asm/macros/event.inc b/asm/macros/event.inc index 9321f5b8c524..740777457812 100644 --- a/asm/macros/event.inc +++ b/asm/macros/event.inc @@ -2407,8 +2407,8 @@ .endm @ Gets the facing direction of a given event object and stores it in the variable \dest. - .macro getobjectfacingdirection evObjId:req, dest:req - setvar VAR_0x8005, \evObjId + .macro getobjectfacingdirection localId:req, dest:req + setvar VAR_0x8005, \localId specialvar \dest, Script_GetObjectFacingDirection .endm From 458340e0439104da1310d675255837f68cb75896 Mon Sep 17 00:00:00 2001 From: pkmnsnfrn Date: Wed, 14 Aug 2024 19:09:56 -0700 Subject: [PATCH 14/31] Moved pokedex special constants to header --- asm/macros/event.inc | 5 +---- include/constants/field_specials.h | 5 +++++ 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/asm/macros/event.inc b/asm/macros/event.inc index 740777457812..1c5b004bbbf0 100644 --- a/asm/macros/event.inc +++ b/asm/macros/event.inc @@ -2383,10 +2383,7 @@ special SetMonBall .endm - OPEN_PARTY_SCREEN = FALSE - NO_PARTY_SCREEN = TRUE - - @ Check if the Player has \speciesId in their party. + @ 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:req setvar VAR_0x8005, \speciesId .if \mode == OPEN_PARTY_SCREEN diff --git a/include/constants/field_specials.h b/include/constants/field_specials.h index 1e08a47f95ee..35769ba3b1a1 100644 --- a/include/constants/field_specials.h +++ b/include/constants/field_specials.h @@ -86,4 +86,9 @@ #define DEOXYS_ROCK_SOLVED 2 #define DEOXYS_ROCK_COMPLETE 3 +enum { + OPEN_PARTY_SCREEN, + NO_PARTY_SCREEN +}; + #endif // GUARD_CONSTANTS_FIELD_SPECIALS_H From dc06321054d6f1fca891d26a2cb736241ac9caaf Mon Sep 17 00:00:00 2001 From: pkmnsnfrn Date: Wed, 14 Aug 2024 19:24:55 -0700 Subject: [PATCH 15/31] Moved pokedex flags to constants files andadded constants to header of event_scripts --- asm/macros/event.inc | 8 ++++---- data/event_scripts.s | 1 + include/constants/pokedex.h | 14 ++++++++++++++ include/pokedex.h | 14 -------------- src/field_specials.c | 2 +- 5 files changed, 20 insertions(+), 19 deletions(-) diff --git a/asm/macros/event.inc b/asm/macros/event.inc index 1c5b004bbbf0..ac008119ef8a 100644 --- a/asm/macros/event.inc +++ b/asm/macros/event.inc @@ -2349,7 +2349,7 @@ @ The result is stored in VAR_RESULT .macro getseenmon species:req setvar VAR_0x8005, \species - setvar VAR_0x8006, 0 + setvar VAR_0x8006, FLAG_GET_SEEN specialvar VAR_RESULT, Script_GetSetPokedexFlag .endm @@ -2357,21 +2357,21 @@ @ The result is stored in VAR_RESULT .macro getcaughtmon species:req setvar VAR_0x8005, \species - setvar VAR_0x8006, 1 + setvar VAR_0x8006, FLAG_GET_CAUGHT specialvar VAR_RESULT, Script_GetSetPokedexFlag .endm @ Sets the Pokédex Seen flag of the specified Pokemon .macro setseenmon species:req setvar VAR_0x8005, \species - setvar VAR_0x8006, 2 + setvar VAR_0x8006, FLAG_SET_SEEN specialvar VAR_RESULT, Script_GetSetPokedexFlag .endm @ Sets the Pokédex Caught flag of the specified Pokemon .macro setcaughtmon species:req setvar VAR_0x8005, \species - setvar VAR_0x8006, 3 + setvar VAR_0x8006, FLAG_SET_CAUGHT specialvar VAR_RESULT, Script_GetSetPokedexFlag .endm diff --git a/data/event_scripts.s b/data/event_scripts.s index d4393ac9d473..8ff14199f614 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/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/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/field_specials.c b/src/field_specials.c index e58d861f547f..a99a21f6b722 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" @@ -68,7 +69,6 @@ #include "constants/metatile_labels.h" #include "palette.h" #include "battle_util.h" -#include "pokedex.h" #define TAG_ITEM_ICON 5500 From 67f8a61eef101d197c1f95524f4f8682a7258d0c Mon Sep 17 00:00:00 2001 From: pkmnsnfrn Date: Wed, 14 Aug 2024 19:44:18 -0700 Subject: [PATCH 16/31] Moved current and template positions to headers --- asm/macros/event.inc | 17 +++++++++++++---- include/constants/field_specials.h | 5 +++++ 2 files changed, 18 insertions(+), 4 deletions(-) diff --git a/asm/macros/event.inc b/asm/macros/event.inc index ac008119ef8a..7b4bca117086 100644 --- a/asm/macros/event.inc +++ b/asm/macros/event.inc @@ -2328,16 +2328,25 @@ .2byte \itemId .endm - CURRENT_POSITION = FALSE - TEMPLATE_POSITION = TRUE - - @ Stores the CURRENT / TEMPLATE position of the given object in VAR_0x8007 (x) and VAR_0x8008 (y) + @ Stores the position of the given object in VAR_0x8007 (x) and VAR_0x8008 (y). Mode CURRENT_POSITION will take the object's current position. Mode TEMPLATE_POSITION will takje the object's template position. .macro getobjectxy localId:req, posType:req setvar VAR_0x8000, \localId setvar VAR_0x8001, \posType special GetObjectPosition .endm + .macro getobjecttemplatexy localId:req + setvar VAR_0x8000, \localId + setvar VAR_0x8001, TEMPLATE_POSITION + special GetObjectPosition + .endm + + .macro getobjectcurrentxy localId:req + setvar VAR_0x8000, \localId + setvar VAR_0x8001, CURRENT_POSITION + special GetObjectPosition + .endm + @ checks if there is any object at a given position .macro checkobjectat x:req, y:req setorcopyvar VAR_0x8005, \x diff --git a/include/constants/field_specials.h b/include/constants/field_specials.h index 35769ba3b1a1..64a105a5fd0b 100644 --- a/include/constants/field_specials.h +++ b/include/constants/field_specials.h @@ -91,4 +91,9 @@ enum { NO_PARTY_SCREEN }; +enum { + CURRENT_POSITION, + TEMPLATE_POSITION +}; + #endif // GUARD_CONSTANTS_FIELD_SPECIALS_H From fed7fc4f0a6b871adef04c18411633e44a6ae1b0 Mon Sep 17 00:00:00 2001 From: pkmnsnfrn Date: Wed, 14 Aug 2024 21:35:03 -0700 Subject: [PATCH 17/31] Fixed bug with checkobjectat --- src/field_specials.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/field_specials.c b/src/field_specials.c index a99a21f6b722..38e4fa4fdebe 100644 --- a/src/field_specials.c +++ b/src/field_specials.c @@ -4301,15 +4301,16 @@ bool32 CheckObjectAtXY(void) for (i = 0; i < OBJECT_EVENTS_COUNT; i++) { if (!gObjectEvents[i].active) - return FALSE; + continue; if (gObjectEvents[i].currentCoords.x != x) - return FALSE; + continue; if (gObjectEvents[i].currentCoords.y != y) - return FALSE; + continue; + return TRUE; } - return TRUE; + return FALSE; } bool32 Script_GetSetPokedexFlag(void) From 287f6baaa965ae9ec4ba66bdf162ba8a731d2014 Mon Sep 17 00:00:00 2001 From: pkmnsnfrn Date: Wed, 14 Aug 2024 22:14:48 -0700 Subject: [PATCH 18/31] spaces over tabs please don't eat my ass --- include/constants/field_specials.h | 8 +-- src/event_object_movement.c | 46 +++++++++--------- src/field_specials.c | 78 +++++++++++++++--------------- 3 files changed, 66 insertions(+), 66 deletions(-) diff --git a/include/constants/field_specials.h b/include/constants/field_specials.h index 64a105a5fd0b..72966adeb882 100644 --- a/include/constants/field_specials.h +++ b/include/constants/field_specials.h @@ -87,13 +87,13 @@ #define DEOXYS_ROCK_COMPLETE 3 enum { - OPEN_PARTY_SCREEN, - NO_PARTY_SCREEN + OPEN_PARTY_SCREEN, + NO_PARTY_SCREEN }; enum { - CURRENT_POSITION, - TEMPLATE_POSITION + CURRENT_POSITION, + TEMPLATE_POSITION }; #endif // GUARD_CONSTANTS_FIELD_SPECIALS_H diff --git a/src/event_object_movement.c b/src/event_object_movement.c index 4105aa42a55c..8c069a895b04 100644 --- a/src/event_object_movement.c +++ b/src/event_object_movement.c @@ -9494,30 +9494,30 @@ static void DoTracksGroundEffect_BikeTireTracks(struct ObjectEvent *objEvent, st static void DoTracksGroundEffect_SlitherTracks(struct ObjectEvent *objEvent, struct Sprite *sprite, u8 a) { - // Specifies which bike track shape to show next. - // For example, when the bike turns from up to right, it will show - // a track that curves to the right. - // Each 4-byte row corresponds to the initial direction of the bike, and - // each byte in that row is for the next direction of the bike in the order - // of down, up, left, right. - static const u8 slitherTracks_Transitions[4][4] = { - {1, 2, 7, 8}, - {1, 2, 6, 5}, - {5, 8, 3, 4}, - {6, 7, 3, 4}, - }; - - if (objEvent->currentCoords.x != objEvent->previousCoords.x || objEvent->currentCoords.y != objEvent->previousCoords.y) - { - gFieldEffectArguments[0] = objEvent->previousCoords.x; - gFieldEffectArguments[1] = objEvent->previousCoords.y; - gFieldEffectArguments[2] = 149; - gFieldEffectArguments[3] = 2; - gFieldEffectArguments[4] = - slitherTracks_Transitions[objEvent->previousMovementDirection][objEvent->facingDirection - 5]; + // Specifies which bike track shape to show next. + // For example, when the bike turns from up to right, it will show + // a track that curves to the right. + // Each 4-byte row corresponds to the initial direction of the bike, and + // each byte in that row is for the next direction of the bike in the order + // of down, up, left, right. + static const u8 slitherTracks_Transitions[4][4] = { + {1, 2, 7, 8}, + {1, 2, 6, 5}, + {5, 8, 3, 4}, + {6, 7, 3, 4}, + }; + + if (objEvent->currentCoords.x != objEvent->previousCoords.x || objEvent->currentCoords.y != objEvent->previousCoords.y) + { + gFieldEffectArguments[0] = objEvent->previousCoords.x; + gFieldEffectArguments[1] = objEvent->previousCoords.y; + gFieldEffectArguments[2] = 149; + gFieldEffectArguments[3] = 2; + gFieldEffectArguments[4] = + slitherTracks_Transitions[objEvent->previousMovementDirection][objEvent->facingDirection - 5]; gFieldEffectArguments[5] = objEvent->previousMetatileBehavior; - FieldEffectStart(FLDEFF_TRACKS_SLITHER); - } + FieldEffectStart(FLDEFF_TRACKS_SLITHER); + } } void GroundEffect_Ripple(struct ObjectEvent *objEvent, struct Sprite *sprite) diff --git a/src/field_specials.c b/src/field_specials.c index 38e4fa4fdebe..d0d370c5669e 100644 --- a/src/field_specials.c +++ b/src/field_specials.c @@ -4270,58 +4270,58 @@ void PreparePartyForSkyBattle(void) void GetObjectPosition(void) { - u32 localId = gSpecialVar_0x8000; - u32 useTemplate = gSpecialVar_0x8001; - u32 objectId; - struct ObjectEvent* objEvent; + u32 localId = gSpecialVar_0x8000; + u32 useTemplate = gSpecialVar_0x8001; + u32 objectId; + struct ObjectEvent* objEvent; - u16 *x = &gSpecialVar_0x8007; - u16 *y = &gSpecialVar_0x8008; + u16 *x = &gSpecialVar_0x8007; + u16 *y = &gSpecialVar_0x8008; - if (useTemplate) - { - const struct ObjectEventTemplate *objTemplate = FindObjectEventTemplateByLocalId(localId, gSaveBlock1Ptr->objectEventTemplates, gMapHeader.events->objectEventCount); - *x = objTemplate->x; - *y = objTemplate->y; - return; - } + if (useTemplate) + { + const struct ObjectEventTemplate *objTemplate = FindObjectEventTemplateByLocalId(localId, gSaveBlock1Ptr->objectEventTemplates, gMapHeader.events->objectEventCount); + *x = objTemplate->x; + *y = objTemplate->y; + return; + } - objectId = GetObjectEventIdByLocalId(localId); - objEvent = &gObjectEvents[objectId]; - *x = objEvent->currentCoords.x - 7; - *y = objEvent->currentCoords.y - 7; + objectId = GetObjectEventIdByLocalId(localId); + objEvent = &gObjectEvents[objectId]; + *x = objEvent->currentCoords.x - 7; + *y = objEvent->currentCoords.y - 7; } bool32 CheckObjectAtXY(void) { - u32 x = gSpecialVar_0x8005 + 7; - u32 y = gSpecialVar_0x8006 + 7; - u32 i; + u32 x = gSpecialVar_0x8005 + 7; + u32 y = gSpecialVar_0x8006 + 7; + u32 i; - for (i = 0; i < OBJECT_EVENTS_COUNT; i++) - { - if (!gObjectEvents[i].active) - continue; + for (i = 0; i < OBJECT_EVENTS_COUNT; i++) + { + if (!gObjectEvents[i].active) + continue; - if (gObjectEvents[i].currentCoords.x != x) - continue; + if (gObjectEvents[i].currentCoords.x != x) + continue; - if (gObjectEvents[i].currentCoords.y != y) - continue; - return TRUE; - } - return FALSE; + if (gObjectEvents[i].currentCoords.y != y) + continue; + return TRUE; + } + return FALSE; } bool32 Script_GetSetPokedexFlag(void) { - u32 speciesId = SpeciesToNationalPokedexNum(gSpecialVar_0x8005); - bool32 desiredFlag = gSpecialVar_0x8006; + u32 speciesId = SpeciesToNationalPokedexNum(gSpecialVar_0x8005); + bool32 desiredFlag = gSpecialVar_0x8006; - if (desiredFlag == FLAG_SET_CAUGHT) - GetSetPokedexFlag(speciesId,FLAG_SET_SEEN); + if (desiredFlag == FLAG_SET_CAUGHT) + GetSetPokedexFlag(speciesId,FLAG_SET_SEEN); - return GetSetPokedexFlag(speciesId,desiredFlag); + return GetSetPokedexFlag(speciesId,desiredFlag); } void SetMonBall(void) @@ -4332,9 +4332,9 @@ void SetMonBall(void) bool32 CheckPartyHasSpecie(void) { - u32 partyIndex; + u32 partyIndex; - for (partyIndex = 0; partyIndex < CalculatePlayerPartyCount(); partyIndex++) + for (partyIndex = 0; partyIndex < CalculatePlayerPartyCount(); partyIndex++) if (GetMonData(&gPlayerParty[partyIndex], MON_DATA_SPECIES) == gSpecialVar_0x8005) return TRUE; @@ -4343,6 +4343,6 @@ bool32 CheckPartyHasSpecie(void) bool32 CheckChosenMonMatchDesiredSpecie(void) { - return (GetMonData(&gPlayerParty[gSpecialVar_0x8004], MON_DATA_SPECIES) == gSpecialVar_0x8005); + return (GetMonData(&gPlayerParty[gSpecialVar_0x8004], MON_DATA_SPECIES) == gSpecialVar_0x8005); } From f87440a25a518b1eb54df0b46b7350aa5832416f Mon Sep 17 00:00:00 2001 From: pkmnsnfrn Date: Thu, 12 Sep 2024 05:43:55 -0700 Subject: [PATCH 19/31] Removed setmonball per https://github.com/rh-hideout/pokeemerald-expansion/pull/5177\#issuecomment-2294980531 --- .swo | Bin 0 -> 4096 bytes asm/macros/event.inc | 8 -------- data/specials.inc | 1 - src/field_specials.c | 6 ------ 4 files changed, 15 deletions(-) create mode 100644 .swo diff --git a/.swo b/.swo new file mode 100644 index 0000000000000000000000000000000000000000..dac352690102655cc3a6e5f5a7fee17b83ce8ed2 GIT binary patch literal 4096 zcmYc?2=nw+u+%eP00IFJ0RcOh7#IqQ(_mb@w2N!7cZh$0uBAm-n5(H7UbUl=qaiRF z0s|ESoT0`>hTyEOtfZ(QEEGCW4jHv~Gz3ONU^E0qLtr!nMnhmU1V%$(Gz3ONU;sh@ E055zBfdBvi literal 0 HcmV?d00001 diff --git a/asm/macros/event.inc b/asm/macros/event.inc index 986ed8305fbc..a4057b22dbed 100644 --- a/asm/macros/event.inc +++ b/asm/macros/event.inc @@ -2399,14 +2399,6 @@ setvar VAR_0x8005, \species setvar VAR_0x8006, FLAG_SET_CAUGHT specialvar VAR_RESULT, Script_GetSetPokedexFlag - .endm - - @ Changes the caught ball of a selected Pokémon - .macro setmonball ballId:req - special ChoosePartyMon - waitstate - setvar VAR_0x8005, \ballId - special SetMonBall .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. diff --git a/data/specials.inc b/data/specials.inc index ed88d42eaeac..54a5218c3753 100644 --- a/data/specials.inc +++ b/data/specials.inc @@ -557,7 +557,6 @@ gSpecials:: def_special GetObjectPosition def_special CheckObjectAtXY def_special Script_GetSetPokedexFlag - def_special SetMonBall def_special CheckPartyHasSpecie def_special CheckChosenMonMatchDesiredSpecie def_special Script_GetObjectFacingDirection diff --git a/src/field_specials.c b/src/field_specials.c index 4081e8375717..d26f9219cfd1 100644 --- a/src/field_specials.c +++ b/src/field_specials.c @@ -4334,12 +4334,6 @@ bool32 Script_GetSetPokedexFlag(void) return GetSetPokedexFlag(speciesId,desiredFlag); } -void SetMonBall(void) -{ - u32 ballId = gSpecialVar_0x8005; - SetMonData(&gPlayerParty[gSpecialVar_0x8004], MON_DATA_POKEBALL, &ballId); -} - bool32 CheckPartyHasSpecie(void) { u32 partyIndex; From 979c9994f76c0823b3d221e4c94d67c87a07ee74 Mon Sep 17 00:00:00 2001 From: pkmnsnfrn Date: Thu, 12 Sep 2024 05:47:12 -0700 Subject: [PATCH 20/31] Set VAR_RESULT to the number of removed items from removeallitem per https://github.com/rh-hideout/pokeemerald-expansion/pull/5177\#issuecomment-2294980531 --- .swo | Bin 4096 -> 0 bytes asm/macros/event.inc | 2 +- src/scrcmd.c | 4 +++- 3 files changed, 4 insertions(+), 2 deletions(-) delete mode 100644 .swo diff --git a/.swo b/.swo deleted file mode 100644 index dac352690102655cc3a6e5f5a7fee17b83ce8ed2..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 4096 zcmYc?2=nw+u+%eP00IFJ0RcOh7#IqQ(_mb@w2N!7cZh$0uBAm-n5(H7UbUl=qaiRF z0s|ESoT0`>hTyEOtfZ(QEEGCW4jHv~Gz3ONU^E0qLtr!nMnhmU1V%$(Gz3ONU;sh@ E055zBfdBvi diff --git a/asm/macros/event.inc b/asm/macros/event.inc index a4057b22dbed..dff3faf83a6b 100644 --- a/asm/macros/event.inc +++ b/asm/macros/event.inc @@ -2339,7 +2339,7 @@ callnative ScriptHideItemDescription .endm - @ Remove all of specified item from the player's bag + @ 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 RemoveAllItem .2byte \itemId diff --git a/src/scrcmd.c b/src/scrcmd.c index 12ec04189556..7062721a948c 100644 --- a/src/scrcmd.c +++ b/src/scrcmd.c @@ -2477,5 +2477,7 @@ void ScriptSetDoubleBattleFlag(struct ScriptContext *ctx) void RemoveAllItem(struct ScriptContext *ctx) { u32 itemId = VarGet(ScriptReadHalfword(ctx)); - RemoveBagItem(itemId, CountTotalItemQuantityInBag(itemId)); + u32 count = CountTotalItemQuantityInBag(itemId); + gSpecialVar_Result = count; + RemoveBagItem(itemId, count); } From 22b0fdf5c3cd5cb68f4f23a75b4d917e391e77ac Mon Sep 17 00:00:00 2001 From: pkmnsnfrn Date: Thu, 12 Sep 2024 18:18:41 -0700 Subject: [PATCH 21/31] Removed checkspecies_auto and made that the default behavior --- asm/macros/event.inc | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/asm/macros/event.inc b/asm/macros/event.inc index dff3faf83a6b..f3fa3a40274c 100644 --- a/asm/macros/event.inc +++ b/asm/macros/event.inc @@ -2402,7 +2402,7 @@ .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:req + .macro checkspecies speciesId:req, mode=NO_PARTY_SCREEN setvar VAR_0x8005, \speciesId .if \mode == OPEN_PARTY_SCREEN special ChoosePartyMon @@ -2417,10 +2417,6 @@ checkspecies \speciesId, OPEN_PARTY_SCREEN .endm - .macro checkspecies_auto speciesId:req - checkspecies \speciesId, NO_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 setvar VAR_0x8005, \localId From 10bb349b8cc2b46ffd22cd9e36ce0c18a032d281 Mon Sep 17 00:00:00 2001 From: pkmnsnfrn Date: Thu, 12 Sep 2024 18:41:42 -0700 Subject: [PATCH 22/31] Changed GetObjectPosition to callnative --- asm/macros/event.inc | 22 +++++++++++----------- data/specials.inc | 1 - src/field_specials.c | 24 ------------------------ src/scrcmd.c | 25 +++++++++++++++++++++++++ 4 files changed, 36 insertions(+), 36 deletions(-) diff --git a/asm/macros/event.inc b/asm/macros/event.inc index f3fa3a40274c..b2a2d461599f 100644 --- a/asm/macros/event.inc +++ b/asm/macros/event.inc @@ -2347,21 +2347,21 @@ @ Stores the position of the given object in VAR_0x8007 (x) and VAR_0x8008 (y). Mode CURRENT_POSITION will take the object's current position. Mode TEMPLATE_POSITION will takje the object's template position. .macro getobjectxy localId:req, posType:req - setvar VAR_0x8000, \localId - setvar VAR_0x8001, \posType - special GetObjectPosition + callnative GetObjectPosition + .2byte \localId + .2byte \posType .endm - .macro getobjecttemplatexy localId:req - setvar VAR_0x8000, \localId - setvar VAR_0x8001, TEMPLATE_POSITION - special GetObjectPosition + .macro getobjecttemplatexy localId:req, posType = TEMPLATE_POSITION + callnative GetObjectPosition + .2byte \localId + .2byte \posType .endm - .macro getobjectcurrentxy localId:req - setvar VAR_0x8000, \localId - setvar VAR_0x8001, CURRENT_POSITION - special GetObjectPosition + .macro getobjectcurrentxy localId:req, posType = CURRENT_POSITION + callnative GetObjectPosition + .2byte \localId + .2byte \posType .endm @ checks if there is any object at a given position diff --git a/data/specials.inc b/data/specials.inc index 54a5218c3753..3232dca7af53 100644 --- a/data/specials.inc +++ b/data/specials.inc @@ -554,7 +554,6 @@ gSpecials:: def_special Script_GetChosenMonDefensiveEVs def_special Script_GetChosenMonOffensiveIVs def_special Script_GetChosenMonDefensiveIVs - def_special GetObjectPosition def_special CheckObjectAtXY def_special Script_GetSetPokedexFlag def_special CheckPartyHasSpecie diff --git a/src/field_specials.c b/src/field_specials.c index d26f9219cfd1..3c27ade57026 100644 --- a/src/field_specials.c +++ b/src/field_specials.c @@ -4278,30 +4278,6 @@ void PreparePartyForSkyBattle(void) CompactPartySlots(); } -void GetObjectPosition(void) -{ - u32 localId = gSpecialVar_0x8000; - u32 useTemplate = gSpecialVar_0x8001; - u32 objectId; - struct ObjectEvent* objEvent; - - u16 *x = &gSpecialVar_0x8007; - u16 *y = &gSpecialVar_0x8008; - - if (useTemplate) - { - const struct ObjectEventTemplate *objTemplate = FindObjectEventTemplateByLocalId(localId, gSaveBlock1Ptr->objectEventTemplates, gMapHeader.events->objectEventCount); - *x = objTemplate->x; - *y = objTemplate->y; - return; - } - - objectId = GetObjectEventIdByLocalId(localId); - objEvent = &gObjectEvents[objectId]; - *x = objEvent->currentCoords.x - 7; - *y = objEvent->currentCoords.y - 7; -} - bool32 CheckObjectAtXY(void) { u32 x = gSpecialVar_0x8005 + 7; diff --git a/src/scrcmd.c b/src/scrcmd.c index 7062721a948c..7bcedb89bbb6 100644 --- a/src/scrcmd.c +++ b/src/scrcmd.c @@ -2481,3 +2481,28 @@ void RemoveAllItem(struct ScriptContext *ctx) gSpecialVar_Result = count; RemoveBagItem(itemId, count); } + +void GetObjectPosition(struct ScriptContext *ctx) +{ + u32 localId = VarGet(ScriptReadHalfword(ctx)); + u32 useTemplate = gSpecialVar_0x8001; + u32 objectId; + struct ObjectEvent* objEvent; + + u16 *x = &gSpecialVar_0x8007; + u16 *y = &gSpecialVar_0x8008; + + if (useTemplate) + { + const struct ObjectEventTemplate *objTemplate = FindObjectEventTemplateByLocalId(localId, gSaveBlock1Ptr->objectEventTemplates, gMapHeader.events->objectEventCount); + *x = objTemplate->x; + *y = objTemplate->y; + return; + } + + objectId = GetObjectEventIdByLocalId(localId); + objEvent = &gObjectEvents[objectId]; + *x = objEvent->currentCoords.x - 7; + *y = objEvent->currentCoords.y - 7; +} + From be7938f32221247547b4da30eb396fc999e1a69b Mon Sep 17 00:00:00 2001 From: pkmnsnfrn Date: Thu, 12 Sep 2024 18:55:11 -0700 Subject: [PATCH 23/31] Changed CheckObjectAtXY to callnative --- asm/macros/event.inc | 9 +++++---- data/specials.inc | 1 - src/field_specials.c | 21 --------------------- src/scrcmd.c | 27 ++++++++++++++++++++++++--- 4 files changed, 29 insertions(+), 29 deletions(-) diff --git a/asm/macros/event.inc b/asm/macros/event.inc index b2a2d461599f..a4f22f817a05 100644 --- a/asm/macros/event.inc +++ b/asm/macros/event.inc @@ -2365,10 +2365,11 @@ .endm @ checks if there is any object at a given position - .macro checkobjectat x:req, y:req - setorcopyvar VAR_0x8005, \x - setorcopyvar VAR_0x8006, \y - specialvar VAR_RESULT, CheckObjectAtXY + .macro checkobjectat x:req, y:req, dest = VAR_RESULT + callnative CheckObjectAtXY + .2byte \x + .2byte \y + .2byte \dest .endm @ Checks the state of the Pokédex Seen flag of the specified Pokemon diff --git a/data/specials.inc b/data/specials.inc index 3232dca7af53..91fed72d780d 100644 --- a/data/specials.inc +++ b/data/specials.inc @@ -554,7 +554,6 @@ gSpecials:: def_special Script_GetChosenMonDefensiveEVs def_special Script_GetChosenMonOffensiveIVs def_special Script_GetChosenMonDefensiveIVs - def_special CheckObjectAtXY def_special Script_GetSetPokedexFlag def_special CheckPartyHasSpecie def_special CheckChosenMonMatchDesiredSpecie diff --git a/src/field_specials.c b/src/field_specials.c index 3c27ade57026..0f1854b3b540 100644 --- a/src/field_specials.c +++ b/src/field_specials.c @@ -4278,27 +4278,6 @@ void PreparePartyForSkyBattle(void) CompactPartySlots(); } -bool32 CheckObjectAtXY(void) -{ - u32 x = gSpecialVar_0x8005 + 7; - u32 y = gSpecialVar_0x8006 + 7; - 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 Script_GetSetPokedexFlag(void) { u32 speciesId = SpeciesToNationalPokedexNum(gSpecialVar_0x8005); diff --git a/src/scrcmd.c b/src/scrcmd.c index 7bcedb89bbb6..d68e2dbd8689 100644 --- a/src/scrcmd.c +++ b/src/scrcmd.c @@ -2485,12 +2485,12 @@ void RemoveAllItem(struct ScriptContext *ctx) void GetObjectPosition(struct ScriptContext *ctx) { u32 localId = VarGet(ScriptReadHalfword(ctx)); - u32 useTemplate = gSpecialVar_0x8001; + u32 useTemplate = VarGet(ScriptReadHalfword(ctx)); + u16 *x = &gSpecialVar_0x8007; + u16 *y = &gSpecialVar_0x8008; u32 objectId; struct ObjectEvent* objEvent; - u16 *x = &gSpecialVar_0x8007; - u16 *y = &gSpecialVar_0x8008; if (useTemplate) { @@ -2506,3 +2506,24 @@ void GetObjectPosition(struct ScriptContext *ctx) *y = objEvent->currentCoords.y - 7; } +bool32 CheckObjectAtXY(struct ScriptContext *ctx) +{ + u32 x = VarGet(ScriptReadHalfword(ctx)) + 7; + u32 y = VarGet(ScriptReadHalfword(ctx)) + 7; + 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; +} + From c2db77c4f603f4053c4b08606c32b6a03203dba6 Mon Sep 17 00:00:00 2001 From: pkmnsnfrn Date: Thu, 12 Sep 2024 20:15:55 -0700 Subject: [PATCH 24/31] Changed Script_GetSetPokedexFlag to callnative --- asm/macros/event.inc | 24 ++++++++++++------------ data/specials.inc | 1 - src/field_specials.c | 11 ----------- src/scrcmd.c | 12 ++++++++++++ 4 files changed, 24 insertions(+), 24 deletions(-) diff --git a/asm/macros/event.inc b/asm/macros/event.inc index a4f22f817a05..b826b4c556b1 100644 --- a/asm/macros/event.inc +++ b/asm/macros/event.inc @@ -2375,31 +2375,31 @@ @ Checks the state of the Pokédex Seen flag of the specified Pokemon @ The result is stored in VAR_RESULT .macro getseenmon species:req - setvar VAR_0x8005, \species - setvar VAR_0x8006, FLAG_GET_SEEN - specialvar VAR_RESULT, Script_GetSetPokedexFlag + callnative Script_GetSetPokedexFlag + .2byte \species + .2byte FLAG_GET_SEEN .endm @ Checks the state of the Pokédex Caught flag of the specified Pokemon @ The result is stored in VAR_RESULT .macro getcaughtmon species:req - setvar VAR_0x8005, \species - setvar VAR_0x8006, FLAG_GET_CAUGHT - specialvar VAR_RESULT, Script_GetSetPokedexFlag + callnative Script_GetSetPokedexFlag + .2byte \species + .2byte FLAG_GET_CAUGHT .endm @ Sets the Pokédex Seen flag of the specified Pokemon .macro setseenmon species:req - setvar VAR_0x8005, \species - setvar VAR_0x8006, FLAG_SET_SEEN - specialvar VAR_RESULT, Script_GetSetPokedexFlag + callnative Script_GetSetPokedexFlag + .2byte \species + .2byte FLAG_SET_SEEN .endm @ Sets the Pokédex Caught flag of the specified Pokemon .macro setcaughtmon species:req - setvar VAR_0x8005, \species - setvar VAR_0x8006, FLAG_SET_CAUGHT - specialvar VAR_RESULT, Script_GetSetPokedexFlag + callnative Script_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. diff --git a/data/specials.inc b/data/specials.inc index 91fed72d780d..e6a886009679 100644 --- a/data/specials.inc +++ b/data/specials.inc @@ -554,7 +554,6 @@ gSpecials:: def_special Script_GetChosenMonDefensiveEVs def_special Script_GetChosenMonOffensiveIVs def_special Script_GetChosenMonDefensiveIVs - def_special Script_GetSetPokedexFlag def_special CheckPartyHasSpecie def_special CheckChosenMonMatchDesiredSpecie def_special Script_GetObjectFacingDirection diff --git a/src/field_specials.c b/src/field_specials.c index 0f1854b3b540..57bd0158a6cc 100644 --- a/src/field_specials.c +++ b/src/field_specials.c @@ -4278,17 +4278,6 @@ void PreparePartyForSkyBattle(void) CompactPartySlots(); } -bool32 Script_GetSetPokedexFlag(void) -{ - u32 speciesId = SpeciesToNationalPokedexNum(gSpecialVar_0x8005); - bool32 desiredFlag = gSpecialVar_0x8006; - - if (desiredFlag == FLAG_SET_CAUGHT) - GetSetPokedexFlag(speciesId,FLAG_SET_SEEN); - - return GetSetPokedexFlag(speciesId,desiredFlag); -} - bool32 CheckPartyHasSpecie(void) { u32 partyIndex; diff --git a/src/scrcmd.c b/src/scrcmd.c index d68e2dbd8689..f087d2d290df 100644 --- a/src/scrcmd.c +++ b/src/scrcmd.c @@ -53,6 +53,7 @@ #include "list_menu.h" #include "malloc.h" #include "constants/event_objects.h" +#include "pokedex.h" typedef u16 (*SpecialFunc)(void); typedef void (*NativeFunc)(struct ScriptContext *ctx); @@ -2527,3 +2528,14 @@ bool32 CheckObjectAtXY(struct ScriptContext *ctx) return FALSE; } +void Script_GetSetPokedexFlag(struct ScriptContext *ctx) +{ + u32 speciesId = SpeciesToNationalPokedexNum(VarGet(ScriptReadHalfword(ctx))); + bool32 desiredFlag = VarGet(ScriptReadHalfword(ctx)); + + if (desiredFlag == FLAG_SET_CAUGHT) + GetSetPokedexFlag(speciesId,FLAG_SET_SEEN); + + gSpecialVar_Result = GetSetPokedexFlag(speciesId,desiredFlag); +} + From ecd435cd84be9b986f60d00655b96b2b2c2d93bc Mon Sep 17 00:00:00 2001 From: pkmnsnfrn Date: Thu, 12 Sep 2024 20:45:14 -0700 Subject: [PATCH 25/31] Changed CheckChosenMOnMatchDesiredSpecies and CheckPartyHasSpecies to callnative --- asm/macros/event.inc | 7 ++++--- data/specials.inc | 2 -- src/field_specials.c | 16 ---------------- src/scrcmd.c | 21 +++++++++++++++++++++ 4 files changed, 25 insertions(+), 21 deletions(-) diff --git a/asm/macros/event.inc b/asm/macros/event.inc index b826b4c556b1..67b5e9b634c5 100644 --- a/asm/macros/event.inc +++ b/asm/macros/event.inc @@ -2404,13 +2404,14 @@ @ 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 - setvar VAR_0x8005, \speciesId .if \mode == OPEN_PARTY_SCREEN special ChoosePartyMon waitstate - specialvar VAR_RESULT, CheckChosenMonMatchDesiredSpecie + callnative CheckChosenMonMatchDesiredSpecie + .2byte \speciesId .else - specialvar VAR_RESULT, CheckPartyHasSpecie + callnative CheckPartyHasSpecie + .2byte \speciesId .endif .endm diff --git a/data/specials.inc b/data/specials.inc index e6a886009679..8233deda592f 100644 --- a/data/specials.inc +++ b/data/specials.inc @@ -554,6 +554,4 @@ gSpecials:: def_special Script_GetChosenMonDefensiveEVs def_special Script_GetChosenMonOffensiveIVs def_special Script_GetChosenMonDefensiveIVs - def_special CheckPartyHasSpecie - def_special CheckChosenMonMatchDesiredSpecie def_special Script_GetObjectFacingDirection diff --git a/src/field_specials.c b/src/field_specials.c index 57bd0158a6cc..982d7a29247d 100644 --- a/src/field_specials.c +++ b/src/field_specials.c @@ -4278,19 +4278,3 @@ void PreparePartyForSkyBattle(void) CompactPartySlots(); } -bool32 CheckPartyHasSpecie(void) -{ - u32 partyIndex; - - for (partyIndex = 0; partyIndex < CalculatePlayerPartyCount(); partyIndex++) - if (GetMonData(&gPlayerParty[partyIndex], MON_DATA_SPECIES) == gSpecialVar_0x8005) - return TRUE; - - return FALSE; -} - -bool32 CheckChosenMonMatchDesiredSpecie(void) -{ - return (GetMonData(&gPlayerParty[gSpecialVar_0x8004], MON_DATA_SPECIES) == gSpecialVar_0x8005); -} - diff --git a/src/scrcmd.c b/src/scrcmd.c index f087d2d290df..345d3b8bef38 100644 --- a/src/scrcmd.c +++ b/src/scrcmd.c @@ -2539,3 +2539,24 @@ void Script_GetSetPokedexFlag(struct ScriptContext *ctx) gSpecialVar_Result = GetSetPokedexFlag(speciesId,desiredFlag); } +void CheckPartyHasSpecie(struct ScriptContext *ctx) +{ + u32 partyIndex; + u32 givenSpecies = VarGet(ScriptReadHalfword(ctx)); + u32 hasSpecies = FALSE; + + for (partyIndex = 0; partyIndex < CalculatePlayerPartyCount(); partyIndex++) + if (GetMonData(&gPlayerParty[partyIndex], MON_DATA_SPECIES) == givenSpecies) + hasSpecies = TRUE; + + gSpecialVar_Result = hasSpecies; +} + +void CheckChosenMonMatchDesiredSpecie(struct ScriptContext *ctx) +{ + u32 givenSpecies = VarGet(ScriptReadHalfword(ctx)); + + gSpecialVar_Result = (GetMonData(&gPlayerParty[gSpecialVar_0x8004], MON_DATA_SPECIES) == givenSpecies); +} + + From 510af1bee6746ddf99bafa732b61da7193ec23a2 Mon Sep 17 00:00:00 2001 From: pkmnsnfrn Date: Thu, 12 Sep 2024 20:55:37 -0700 Subject: [PATCH 26/31] Restored original functions and made script versions --- asm/macros/event.inc | 20 +++++++-------- include/field_specials.h | 3 +++ src/field_specials.c | 52 +++++++++++++++++++++++++++++++++++++ src/scrcmd.c | 55 ++++++---------------------------------- 4 files changed, 73 insertions(+), 57 deletions(-) diff --git a/asm/macros/event.inc b/asm/macros/event.inc index 67b5e9b634c5..73d0d0752659 100644 --- a/asm/macros/event.inc +++ b/asm/macros/event.inc @@ -2347,26 +2347,26 @@ @ Stores the position of the given object in VAR_0x8007 (x) and VAR_0x8008 (y). Mode CURRENT_POSITION will take the object's current position. Mode TEMPLATE_POSITION will takje the object's template position. .macro getobjectxy localId:req, posType:req - callnative GetObjectPosition + callnative Script_GetObjectPosition .2byte \localId .2byte \posType .endm .macro getobjecttemplatexy localId:req, posType = TEMPLATE_POSITION - callnative GetObjectPosition + callnative Script_GetObjectPosition .2byte \localId .2byte \posType .endm .macro getobjectcurrentxy localId:req, posType = CURRENT_POSITION - callnative GetObjectPosition + callnative Script_GetObjectPosition .2byte \localId .2byte \posType .endm @ checks if there is any object at a given position .macro checkobjectat x:req, y:req, dest = VAR_RESULT - callnative CheckObjectAtXY + callnative Script_CheckObjectAtXY .2byte \x .2byte \y .2byte \dest @@ -2375,7 +2375,7 @@ @ Checks the state of the Pokédex Seen flag of the specified Pokemon @ The result is stored in VAR_RESULT .macro getseenmon species:req - callnative Script_GetSetPokedexFlag + callnative Script_Script_GetSetPokedexFlag .2byte \species .2byte FLAG_GET_SEEN .endm @@ -2383,21 +2383,21 @@ @ Checks the state of the Pokédex Caught flag of the specified Pokemon @ The result is stored in VAR_RESULT .macro getcaughtmon species:req - callnative Script_GetSetPokedexFlag + callnative Script_Script_GetSetPokedexFlag .2byte \species .2byte FLAG_GET_CAUGHT .endm @ Sets the Pokédex Seen flag of the specified Pokemon .macro setseenmon species:req - callnative Script_GetSetPokedexFlag + callnative Script_Script_GetSetPokedexFlag .2byte \species .2byte FLAG_SET_SEEN .endm @ Sets the Pokédex Caught flag of the specified Pokemon .macro setcaughtmon species:req - callnative Script_GetSetPokedexFlag + callnative Script_Script_GetSetPokedexFlag .2byte \species .2byte FLAG_SET_CAUGHT .endm @@ -2407,10 +2407,10 @@ .if \mode == OPEN_PARTY_SCREEN special ChoosePartyMon waitstate - callnative CheckChosenMonMatchDesiredSpecie + callnative Script_CheckChosenMonMatchDesiredSpecie .2byte \speciesId .else - callnative CheckPartyHasSpecie + callnative Script_CheckPartyHasSpecie .2byte \speciesId .endif .endm diff --git a/include/field_specials.h b/include/field_specials.h index 95a91d543f06..85db5ba40fb6 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(u32, u32); +bool32 CheckObjectAtXY(u32, u32); +bool32 CheckPartyHasSpecie(u32); #endif // GUARD_FIELD_SPECIALS_H diff --git a/src/field_specials.c b/src/field_specials.c index 982d7a29247d..94a98812b15a 100644 --- a/src/field_specials.c +++ b/src/field_specials.c @@ -4278,3 +4278,55 @@ void PreparePartyForSkyBattle(void) CompactPartySlots(); } +void GetObjectPosition(u32 localId, u32 useTemplate) +{ + u32 objectId; + struct ObjectEvent* objEvent; + + u16 *x = &gSpecialVar_0x8007; + u16 *y = &gSpecialVar_0x8008; + + if (useTemplate) + { + const struct ObjectEventTemplate *objTemplate = FindObjectEventTemplateByLocalId(localId, gSaveBlock1Ptr->objectEventTemplates, gMapHeader.events->objectEventCount); + *x = objTemplate->x; + *y = objTemplate->y; + return; + } + + objectId = GetObjectEventIdByLocalId(localId); + objEvent = &gObjectEvents[objectId]; + *x = objEvent->currentCoords.x - 7; + *y = 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; +} + diff --git a/src/scrcmd.c b/src/scrcmd.c index 345d3b8bef38..974b223f2624 100644 --- a/src/scrcmd.c +++ b/src/scrcmd.c @@ -2483,79 +2483,40 @@ void RemoveAllItem(struct ScriptContext *ctx) RemoveBagItem(itemId, count); } -void GetObjectPosition(struct ScriptContext *ctx) +void Script_GetObjectPosition(struct ScriptContext *ctx) { u32 localId = VarGet(ScriptReadHalfword(ctx)); u32 useTemplate = VarGet(ScriptReadHalfword(ctx)); - u16 *x = &gSpecialVar_0x8007; - u16 *y = &gSpecialVar_0x8008; - u32 objectId; - struct ObjectEvent* objEvent; - - if (useTemplate) - { - const struct ObjectEventTemplate *objTemplate = FindObjectEventTemplateByLocalId(localId, gSaveBlock1Ptr->objectEventTemplates, gMapHeader.events->objectEventCount); - *x = objTemplate->x; - *y = objTemplate->y; - return; - } - - objectId = GetObjectEventIdByLocalId(localId); - objEvent = &gObjectEvents[objectId]; - *x = objEvent->currentCoords.x - 7; - *y = objEvent->currentCoords.y - 7; + GetObjectPosition(localId,useTemplate); } -bool32 CheckObjectAtXY(struct ScriptContext *ctx) +void Script_CheckObjectAtXY(struct ScriptContext *ctx) { u32 x = VarGet(ScriptReadHalfword(ctx)) + 7; u32 y = VarGet(ScriptReadHalfword(ctx)) + 7; - 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; + gSpecialVar_Result = CheckObjectAtXY(x,y); } void Script_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); - - gSpecialVar_Result = GetSetPokedexFlag(speciesId,desiredFlag); } -void CheckPartyHasSpecie(struct ScriptContext *ctx) +void Script_CheckPartyHasSpecie(struct ScriptContext *ctx) { - u32 partyIndex; u32 givenSpecies = VarGet(ScriptReadHalfword(ctx)); - u32 hasSpecies = FALSE; - - for (partyIndex = 0; partyIndex < CalculatePlayerPartyCount(); partyIndex++) - if (GetMonData(&gPlayerParty[partyIndex], MON_DATA_SPECIES) == givenSpecies) - hasSpecies = TRUE; - - gSpecialVar_Result = hasSpecies; + gSpecialVar_Result = CheckPartyHasSpecie(givenSpecies); } -void CheckChosenMonMatchDesiredSpecie(struct ScriptContext *ctx) +void Script_CheckChosenMonMatchDesiredSpecie(struct ScriptContext *ctx) { u32 givenSpecies = VarGet(ScriptReadHalfword(ctx)); - gSpecialVar_Result = (GetMonData(&gPlayerParty[gSpecialVar_0x8004], MON_DATA_SPECIES) == givenSpecies); } From a509f28038663b63eaaec88ba665695833db54e9 Mon Sep 17 00:00:00 2001 From: pkmnsnfrn Date: Sat, 14 Sep 2024 06:32:47 -0700 Subject: [PATCH 27/31] Changed Scripot_GetObjectFacingDirection to callnative --- asm/macros/event.inc | 11 +++++++++-- data/specials.inc | 1 - src/event_object_movement.c | 5 ----- src/scrcmd.c | 6 ++++++ 4 files changed, 15 insertions(+), 8 deletions(-) diff --git a/asm/macros/event.inc b/asm/macros/event.inc index 73d0d0752659..9a99ae3756a2 100644 --- a/asm/macros/event.inc +++ b/asm/macros/event.inc @@ -2421,6 +2421,13 @@ @ Gets the facing direction of a given event object and stores it in the variable \dest. .macro getobjectfacingdirection localId:req, dest:req - setvar VAR_0x8005, \localId - specialvar \dest, Script_GetObjectFacingDirection + callnative Script_GetObjectFacingDirection + .2byte \localId + .byte \dest .endm + + @ .macro checkobjectat x:req, y:req, dest = VAR_RESULT + @ callnative Script_CheckObjectAtXY + @ .2byte \x + @ .2byte \y + @ .2byte \dest diff --git a/data/specials.inc b/data/specials.inc index 8233deda592f..f02497d6039e 100644 --- a/data/specials.inc +++ b/data/specials.inc @@ -554,4 +554,3 @@ gSpecials:: def_special Script_GetChosenMonDefensiveEVs def_special Script_GetChosenMonOffensiveIVs def_special Script_GetChosenMonDefensiveIVs - def_special Script_GetObjectFacingDirection diff --git a/src/event_object_movement.c b/src/event_object_movement.c index 646d2323fb43..8fa688fdf6e2 100644 --- a/src/event_object_movement.c +++ b/src/event_object_movement.c @@ -10633,8 +10633,3 @@ void GetDaycareGraphics(struct ScriptContext *ctx) gSpecialVar_Result = i; } -u32 Script_GetObjectFacingDirection(void) -{ - return gObjectEvents[GetObjectEventIdByLocalId(gSpecialVar_0x8005)].facingDirection; -} - diff --git a/src/scrcmd.c b/src/scrcmd.c index 974b223f2624..fc34720683cb 100644 --- a/src/scrcmd.c +++ b/src/scrcmd.c @@ -2520,4 +2520,10 @@ void Script_CheckChosenMonMatchDesiredSpecie(struct ScriptContext *ctx) gSpecialVar_Result = (GetMonData(&gPlayerParty[gSpecialVar_0x8004], MON_DATA_SPECIES) == givenSpecies); } +void Script_GetObjectFacingDirection(struct ScriptContext *ctx) +{ + u32 objectId = VarGet(ScriptReadHalfword(ctx)); + u16 *varPointer = GetVarPointer(ScriptReadHalfword(ctx)); + *varPointer = gObjectEvents[GetObjectEventIdByLocalId(objectId)].facingDirection; +} From 1665423e5214bc834c5f4cf8acc5c82bf3570347 Mon Sep 17 00:00:00 2001 From: pkmnsnfrn Date: Sat, 14 Sep 2024 07:11:04 -0700 Subject: [PATCH 28/31] Renamed scripts to match vanilla Cleaned up descriptions --- asm/macros/event.inc | 49 +++++++++++++++++++------------------------- src/scrcmd.c | 34 ++++++++++++++++++++++-------- 2 files changed, 46 insertions(+), 37 deletions(-) diff --git a/asm/macros/event.inc b/asm/macros/event.inc index 9a99ae3756a2..985ced862faa 100644 --- a/asm/macros/event.inc +++ b/asm/macros/event.inc @@ -2341,76 +2341,74 @@ @ 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 RemoveAllItem + callnative ScrCmd_removeallitem .2byte \itemId .endm - @ Stores the position of the given object in VAR_0x8007 (x) and VAR_0x8008 (y). Mode CURRENT_POSITION will take the object's current position. Mode TEMPLATE_POSITION will takje the object's template position. + @ Stores the position of the given object in VAR_0x8007 (x) and VAR_0x8008 (y). 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 - callnative Script_GetObjectPosition + callnative ScrCmd_getobjectxy .2byte \localId .2byte \posType .endm .macro getobjecttemplatexy localId:req, posType = TEMPLATE_POSITION - callnative Script_GetObjectPosition + callnative ScrCmd_getobjectxy .2byte \localId .2byte \posType .endm .macro getobjectcurrentxy localId:req, posType = CURRENT_POSITION - callnative Script_GetObjectPosition + callnative ScrCmd_getobjectxy .2byte \localId .2byte \posType .endm - @ checks if there is any object at a given position + @ 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 Script_CheckObjectAtXY + callnative ScrCmd_checkobjectat .2byte \x .2byte \y .2byte \dest .endm - @ Checks the state of the Pokédex Seen flag of the specified Pokemon - @ The result is stored in VAR_RESULT + @ Returns the state of the Pokedex Seen Flag to VAR_RESULT for the Pokemon with speciesId .macro getseenmon species:req - callnative Script_Script_GetSetPokedexFlag + callnative Scrcmd_getsetpokedexflag .2byte \species .2byte FLAG_GET_SEEN .endm - @ Checks the state of the Pokédex Caught flag of the specified Pokemon - @ The result is stored in VAR_RESULT + @ Returns the state of the Pokedex Caught Flag to VAR_RESULT for the Pokemon with speciesId .macro getcaughtmon species:req - callnative Script_Script_GetSetPokedexFlag + callnative Scrcmd_getsetpokedexflag .2byte \species .2byte FLAG_GET_CAUGHT .endm - @ Sets the Pokédex Seen flag of the specified Pokemon + @ Sets the Pokedex Seen Flag for the Pokemon with speciesId .macro setseenmon species:req - callnative Script_Script_GetSetPokedexFlag + callnative Scrcmd_getsetpokedexflag .2byte \species .2byte FLAG_SET_SEEN .endm - @ Sets the Pokédex Caught flag of the specified Pokemon + @ Sets the Pokedex Caught Flag for the Pokemon with speciesId .macro setcaughtmon species:req - callnative Script_Script_GetSetPokedexFlag + 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. + @ 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 Script_CheckChosenMonMatchDesiredSpecie + callnative Scrcmd_checkspecies_choose .2byte \speciesId .else - callnative Script_CheckPartyHasSpecie + callnative Scrcmd_checkspecies .2byte \speciesId .endif .endm @@ -2419,15 +2417,10 @@ checkspecies \speciesId, OPEN_PARTY_SCREEN .endm - @ Gets the facing direction of a given event object and stores it in the variable \dest. + @ Gets the facing direction of a given event object and stores it in the variable dest. .macro getobjectfacingdirection localId:req, dest:req - callnative Script_GetObjectFacingDirection + callnative Scrcmd_getobjectfacingdirection .2byte \localId - .byte \dest + .2byte \dest .endm - @ .macro checkobjectat x:req, y:req, dest = VAR_RESULT - @ callnative Script_CheckObjectAtXY - @ .2byte \x - @ .2byte \y - @ .2byte \dest diff --git a/src/scrcmd.c b/src/scrcmd.c index fc34720683cb..be5c3c93462d 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" @@ -53,7 +54,6 @@ #include "list_menu.h" #include "malloc.h" #include "constants/event_objects.h" -#include "pokedex.h" typedef u16 (*SpecialFunc)(void); typedef void (*NativeFunc)(struct ScriptContext *ctx); @@ -2475,30 +2475,38 @@ void ScriptSetDoubleBattleFlag(struct ScriptContext *ctx) sIsScriptedWildDouble = TRUE; } -void RemoveAllItem(struct ScriptContext *ctx) +bool8 ScrCmd_removeallitem(struct ScriptContext *ctx) { u32 itemId = VarGet(ScriptReadHalfword(ctx)); u32 count = CountTotalItemQuantityInBag(itemId); gSpecialVar_Result = count; RemoveBagItem(itemId, count); + + return FALSE; } -void Script_GetObjectPosition(struct ScriptContext *ctx) +bool8 ScrCmd_getobjectxy(struct ScriptContext *ctx) { u32 localId = VarGet(ScriptReadHalfword(ctx)); u32 useTemplate = VarGet(ScriptReadHalfword(ctx)); GetObjectPosition(localId,useTemplate); + + return FALSE; } -void Script_CheckObjectAtXY(struct ScriptContext *ctx) +bool8 ScrCmd_checkobjectat(struct ScriptContext *ctx) { u32 x = VarGet(ScriptReadHalfword(ctx)) + 7; u32 y = VarGet(ScriptReadHalfword(ctx)) + 7; - gSpecialVar_Result = CheckObjectAtXY(x,y); + u16 *varPointer = GetVarPointer(ScriptReadHalfword(ctx)); + + *varPointer = CheckObjectAtXY(x,y); + + return FALSE; } -void Script_GetSetPokedexFlag(struct ScriptContext *ctx) +bool8 Scrcmd_getsetpokedexflag(struct ScriptContext *ctx) { u32 speciesId = SpeciesToNationalPokedexNum(VarGet(ScriptReadHalfword(ctx))); bool32 desiredFlag = VarGet(ScriptReadHalfword(ctx)); @@ -2506,24 +2514,32 @@ void Script_GetSetPokedexFlag(struct ScriptContext *ctx) if (desiredFlag == FLAG_SET_CAUGHT) GetSetPokedexFlag(speciesId,FLAG_SET_SEEN); + + return FALSE; } -void Script_CheckPartyHasSpecie(struct ScriptContext *ctx) +bool8 Scrcmd_checkspecies(struct ScriptContext *ctx) { u32 givenSpecies = VarGet(ScriptReadHalfword(ctx)); gSpecialVar_Result = CheckPartyHasSpecie(givenSpecies); + + return FALSE; } -void Script_CheckChosenMonMatchDesiredSpecie(struct ScriptContext *ctx) +bool8 Scrcmd_checkspecies_choose(struct ScriptContext *ctx) { u32 givenSpecies = VarGet(ScriptReadHalfword(ctx)); gSpecialVar_Result = (GetMonData(&gPlayerParty[gSpecialVar_0x8004], MON_DATA_SPECIES) == givenSpecies); + + return FALSE; } -void Script_GetObjectFacingDirection(struct ScriptContext *ctx) +bool8 Scrcmd_getobjectfacingdirection(struct ScriptContext *ctx) { u32 objectId = VarGet(ScriptReadHalfword(ctx)); u16 *varPointer = GetVarPointer(ScriptReadHalfword(ctx)); *varPointer = gObjectEvents[GetObjectEventIdByLocalId(objectId)].facingDirection; + + return FALSE; } From 60fb0b34fddf3f9bf4d010f29348f7b9c57cafa4 Mon Sep 17 00:00:00 2001 From: pkmnsnfrn Date: Sat, 14 Sep 2024 07:48:24 -0700 Subject: [PATCH 29/31] Modified getobjectxy to allow for custom destinations --- asm/macros/event.inc | 14 ++++++++++---- include/field_specials.h | 2 +- src/field_specials.c | 13 +++++-------- src/scrcmd.c | 5 +++-- 4 files changed, 19 insertions(+), 15 deletions(-) diff --git a/asm/macros/event.inc b/asm/macros/event.inc index 985ced862faa..710514cda164 100644 --- a/asm/macros/event.inc +++ b/asm/macros/event.inc @@ -2345,23 +2345,29 @@ .2byte \itemId .endm - @ Stores the position of the given object in VAR_0x8007 (x) and VAR_0x8008 (y). 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 + @ 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 + .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 + .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. diff --git a/include/field_specials.h b/include/field_specials.h index 85db5ba40fb6..f391a46ba57f 100644 --- a/include/field_specials.h +++ b/include/field_specials.h @@ -33,7 +33,7 @@ void ResetFanClub(void); bool8 ShouldShowBoxWasFullMessage(void); void SetPCBoxToSendMon(u8 boxId); void PreparePartyForSkyBattle(void); -void GetObjectPosition(u32, u32); +void GetObjectPosition(u16*, u16*, u32, u32); bool32 CheckObjectAtXY(u32, u32); bool32 CheckPartyHasSpecie(u32); diff --git a/src/field_specials.c b/src/field_specials.c index 94a98812b15a..8b2ac8de8d5c 100644 --- a/src/field_specials.c +++ b/src/field_specials.c @@ -4278,26 +4278,23 @@ void PreparePartyForSkyBattle(void) CompactPartySlots(); } -void GetObjectPosition(u32 localId, u32 useTemplate) +void GetObjectPosition(u16* xPointer, u16* yPointer, u32 localId, u32 useTemplate) { u32 objectId; struct ObjectEvent* objEvent; - u16 *x = &gSpecialVar_0x8007; - u16 *y = &gSpecialVar_0x8008; - if (useTemplate) { const struct ObjectEventTemplate *objTemplate = FindObjectEventTemplateByLocalId(localId, gSaveBlock1Ptr->objectEventTemplates, gMapHeader.events->objectEventCount); - *x = objTemplate->x; - *y = objTemplate->y; + *xPointer = objTemplate->x; + *yPointer = objTemplate->y; return; } objectId = GetObjectEventIdByLocalId(localId); objEvent = &gObjectEvents[objectId]; - *x = objEvent->currentCoords.x - 7; - *y = objEvent->currentCoords.y - 7; + *xPointer = objEvent->currentCoords.x - 7; + *yPointer = objEvent->currentCoords.y - 7; } bool32 CheckObjectAtXY(u32 x, u32 y) diff --git a/src/scrcmd.c b/src/scrcmd.c index be5c3c93462d..542f3d1dfc10 100644 --- a/src/scrcmd.c +++ b/src/scrcmd.c @@ -2489,8 +2489,9 @@ bool8 ScrCmd_getobjectxy(struct ScriptContext *ctx) { u32 localId = VarGet(ScriptReadHalfword(ctx)); u32 useTemplate = VarGet(ScriptReadHalfword(ctx)); - - GetObjectPosition(localId,useTemplate); + u16 *pX = GetVarPointer(ScriptReadHalfword(ctx)); + u16 *pY = GetVarPointer(ScriptReadHalfword(ctx)); + GetObjectPosition(pX,pY,localId,useTemplate); return FALSE; } From 3b226fc2e240ef6a0967e1238a34ca07a4edea54 Mon Sep 17 00:00:00 2001 From: pkmnsnfrn Date: Sat, 14 Sep 2024 09:01:53 -0700 Subject: [PATCH 30/31] Removed swp --- .swp | Bin 4096 -> 0 bytes 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 .swp diff --git a/.swp b/.swp deleted file mode 100644 index 099c8db49858ca8579ae6d0417da70c45e4b4c51..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 4096 zcmYc?2=nw+u+%eP00IFJ0RfJ6Obi9ZX)rEc+Ql{4JH$Ug*U};^%+=Hkui8<`(GVC7 zfq@DE&QN0`LvU7CR#H?D7786Ghm6`g8UmvsFd71*Aut*OqaiRF0;3@?8UmvsFaRL{ E0G?C|hyVZp From d76ccddad3908789a1a611d057ec8be897900571 Mon Sep 17 00:00:00 2001 From: pkmnsnfrn Date: Sat, 14 Sep 2024 09:03:49 -0700 Subject: [PATCH 31/31] spaces to tabs in inc files --- asm/macros/event.inc | 136 +++++++++++++++++++++---------------------- 1 file changed, 68 insertions(+), 68 deletions(-) diff --git a/asm/macros/event.inc b/asm/macros/event.inc index 710514cda164..a67d5a751cab 100644 --- a/asm/macros/event.inc +++ b/asm/macros/event.inc @@ -2341,92 +2341,92 @@ @ 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 + 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 + .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 + .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 + .2byte \localId + .2byte \posType + .2byte \destX + .2byte \destY .endm - @ Return TRUE to dest if there is an object at the position x and y. + @ 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 + 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 + .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 + .macro getobjectfacingdirection localId:req, dest:req + callnative Scrcmd_getobjectfacingdirection + .2byte \localId + .2byte \dest + .endm