diff --git a/asm/macros/event.inc b/asm/macros/event.inc index 67b5e9b634..73d0d07526 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 95a91d543f..85db5ba40f 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 982d7a2924..94a98812b1 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 345d3b8bef..974b223f26 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); }