Skip to content

Commit

Permalink
Adds new scripting macros to increase developer quality of life (#5177)
Browse files Browse the repository at this point in the history
  • Loading branch information
ghoulslash authored Oct 12, 2024
2 parents 353915e + 0ef3f7d commit f810d7d
Show file tree
Hide file tree
Showing 10 changed files with 244 additions and 16 deletions.
92 changes: 92 additions & 0 deletions asm/macros/event.inc
Original file line number Diff line number Diff line change
Expand Up @@ -2338,3 +2338,95 @@
.macro hideitemdescription
callnative ScriptHideItemDescription
.endm

@ Remove all of specified item from the player's bag and return the number of removed items to VAR_RESULT
.macro removeallitem itemId:req
callnative ScrCmd_removeallitem
.2byte \itemId
.endm

@ Stores the position of the given object in destX and destY. Mode CURRENT_POSITION will take the object's current position. Mode TEMPLATE_POSITION will take the object's template position.
.macro getobjectxy localId:req, posType:req, destX:req, destY:req
callnative ScrCmd_getobjectxy
.2byte \localId
.2byte \posType
.2byte \destX
.2byte \destY
.endm

.macro getobjecttemplatexy localId:req, posType = TEMPLATE_POSITION, destX:req, destY:req
callnative ScrCmd_getobjectxy
.2byte \localId
.2byte \posType
.2byte \destX
.2byte \destY
.endm

.macro getobjectcurrentxy localId:req, posType = CURRENT_POSITION, destX:req, destY:req
callnative ScrCmd_getobjectxy
.2byte \localId
.2byte \posType
.2byte \destX
.2byte \destY
.endm

@ Return TRUE to dest if there is an object at the position x and y.
.macro checkobjectat x:req, y:req, dest = VAR_RESULT
callnative ScrCmd_checkobjectat
.2byte \x
.2byte \y
.2byte \dest
.endm

@ Returns the state of the Pokedex Seen Flag to VAR_RESULT for the Pokemon with speciesId
.macro getseenmon species:req
callnative Scrcmd_getsetpokedexflag
.2byte \species
.2byte FLAG_GET_SEEN
.endm

@ Returns the state of the Pokedex Caught Flag to VAR_RESULT for the Pokemon with speciesId
.macro getcaughtmon species:req
callnative Scrcmd_getsetpokedexflag
.2byte \species
.2byte FLAG_GET_CAUGHT
.endm

@ Sets the Pokedex Seen Flag for the Pokemon with speciesId
.macro setseenmon species:req
callnative Scrcmd_getsetpokedexflag
.2byte \species
.2byte FLAG_SET_SEEN
.endm

@ Sets the Pokedex Caught Flag for the Pokemon with speciesId
.macro setcaughtmon species:req
callnative Scrcmd_getsetpokedexflag
.2byte \species
.2byte FLAG_SET_CAUGHT
.endm

@ Check if the Player has speciesId in their party. OPEN_PARTY_SCREEN will have the player select a mon from their party. NO_PARTY_SCREEN will automatically check every mon in the player's party.
.macro checkspecies speciesId:req, mode=NO_PARTY_SCREEN
.if \mode == OPEN_PARTY_SCREEN
special ChoosePartyMon
waitstate
callnative Scrcmd_checkspecies_choose
.2byte \speciesId
.else
callnative Scrcmd_checkspecies
.2byte \speciesId
.endif
.endm

.macro checkspecies_choose speciesId:req
checkspecies \speciesId, OPEN_PARTY_SCREEN
.endm

@ Gets the facing direction of a given event object and stores it in the variable dest.
.macro getobjectfacingdirection localId:req, dest:req
callnative Scrcmd_getobjectfacingdirection
.2byte \localId
.2byte \dest
.endm

1 change: 1 addition & 0 deletions data/event_scripts.s
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
10 changes: 10 additions & 0 deletions include/constants/field_specials.h
Original file line number Diff line number Diff line change
Expand Up @@ -86,4 +86,14 @@
#define DEOXYS_ROCK_SOLVED 2
#define DEOXYS_ROCK_COMPLETE 3

enum {
OPEN_PARTY_SCREEN,
NO_PARTY_SCREEN
};

enum {
CURRENT_POSITION,
TEMPLATE_POSITION
};

#endif // GUARD_CONSTANTS_FIELD_SPECIALS_H
14 changes: 14 additions & 0 deletions include/constants/pokedex.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions include/event_object_movement.h
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@ bool8 TryGetObjectEventIdByLocalIdAndMap(u8 localId, u8 mapNum, u8 mapGroupId, u
u8 GetObjectEventIdByXY(s16 x, s16 y);
void SetObjectEventDirection(struct ObjectEvent *objectEvent, u8 direction);
u8 GetFirstInactiveObjectEventId(void);
u8 GetObjectEventIdByLocalId(u8);
void RemoveObjectEventByLocalIdAndMap(u8 localId, u8 mapNum, u8 mapGroup);
void LoadSpecialObjectReflectionPalette(u16 tag, u8 slot);
void TryMoveObjectEventToMapCoords(u8 localId, u8 mapNum, u8 mapGroup, s16 x, s16 y);
Expand Down Expand Up @@ -211,6 +212,7 @@ void ObjectEventForceSetHeldMovement(struct ObjectEvent *objectEvent, u8 movemen
bool8 ObjectEventIsMovementOverridden(struct ObjectEvent *objectEvent);
u8 ObjectEventCheckHeldMovementStatus(struct ObjectEvent *objectEvent);
u8 ObjectEventGetHeldMovementActionId(struct ObjectEvent *objectEvent);
const struct ObjectEventTemplate *FindObjectEventTemplateByLocalId(u8, const struct ObjectEventTemplate *, u8);
void TryOverrideTemplateCoordsForObjectEvent(const struct ObjectEvent *objectEvent, u8 movementType);
void OverrideTemplateCoordsForObjectEvent(const struct ObjectEvent *objectEvent);
void ShiftStillObjectEventCoords(struct ObjectEvent *objEvent);
Expand Down
3 changes: 3 additions & 0 deletions include/field_specials.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,5 +33,8 @@ void ResetFanClub(void);
bool8 ShouldShowBoxWasFullMessage(void);
void SetPCBoxToSendMon(u8 boxId);
void PreparePartyForSkyBattle(void);
void GetObjectPosition(u16*, u16*, u32, u32);
bool32 CheckObjectAtXY(u32, u32);
bool32 CheckPartyHasSpecie(u32);

#endif // GUARD_FIELD_SPECIALS_H
14 changes: 0 additions & 14 deletions include/pokedex.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
3 changes: 1 addition & 2 deletions src/event_object_movement.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,6 @@ static void SpriteCB_CameraObject(struct Sprite *);
static void CameraObject_Init(struct Sprite *);
static void CameraObject_UpdateMove(struct Sprite *);
static void CameraObject_UpdateFrozen(struct Sprite *);
static const struct ObjectEventTemplate *FindObjectEventTemplateByLocalId(u8, const struct ObjectEventTemplate *, u8);
static void ObjectEventSetSingleMovement(struct ObjectEvent *, struct Sprite *, u8);
static void SetSpriteDataForNormalStep(struct Sprite *, u8, u8);
static void InitSpriteForFigure8Anim(struct Sprite *);
Expand Down Expand Up @@ -3421,7 +3420,7 @@ static const struct ObjectEventTemplate *GetObjectEventTemplateByLocalIdAndMap(u
return FindObjectEventTemplateByLocalId(localId, templates, count);
}

static const struct ObjectEventTemplate *FindObjectEventTemplateByLocalId(u8 localId, const struct ObjectEventTemplate *templates, u8 count)
const struct ObjectEventTemplate *FindObjectEventTemplateByLocalId(u8 localId, const struct ObjectEventTemplate *templates, u8 count)
{
u8 i;

Expand Down
50 changes: 50 additions & 0 deletions src/field_specials.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -4277,6 +4278,55 @@ void PreparePartyForSkyBattle(void)
CompactPartySlots();
}

void GetObjectPosition(u16* xPointer, u16* yPointer, u32 localId, u32 useTemplate)
{
u32 objectId;
struct ObjectEvent* objEvent;

if (useTemplate)
{
const struct ObjectEventTemplate *objTemplate = FindObjectEventTemplateByLocalId(localId, gSaveBlock1Ptr->objectEventTemplates, gMapHeader.events->objectEventCount);
*xPointer = objTemplate->x;
*yPointer = objTemplate->y;
return;
}

objectId = GetObjectEventIdByLocalId(localId);
objEvent = &gObjectEvents[objectId];
*xPointer = objEvent->currentCoords.x - 7;
*yPointer = objEvent->currentCoords.y - 7;
}

bool32 CheckObjectAtXY(u32 x, u32 y)
{
u32 i;

for (i = 0; i < OBJECT_EVENTS_COUNT; i++)
{
if (!gObjectEvents[i].active)
continue;

if (gObjectEvents[i].currentCoords.x != x)
continue;

if (gObjectEvents[i].currentCoords.y != y)
continue;
return TRUE;
}
return FALSE;
}

bool32 CheckPartyHasSpecie(u32 givenSpecies)
{
u32 partyIndex;

for (partyIndex = 0; partyIndex < CalculatePlayerPartyCount(); partyIndex++)
if (GetMonData(&gPlayerParty[partyIndex], MON_DATA_SPECIES) == givenSpecies)
return TRUE;

return FALSE;
}

void UseBlankMessageToCancelPokemonPic(void)
{
u8 t = EOS;
Expand Down
71 changes: 71 additions & 0 deletions src/scrcmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -2478,3 +2479,73 @@ void ScriptSetDoubleBattleFlag(struct ScriptContext *ctx)
{
sIsScriptedWildDouble = TRUE;
}

bool8 ScrCmd_removeallitem(struct ScriptContext *ctx)
{
u32 itemId = VarGet(ScriptReadHalfword(ctx));
u32 count = CountTotalItemQuantityInBag(itemId);
gSpecialVar_Result = count;
RemoveBagItem(itemId, count);

return FALSE;
}

bool8 ScrCmd_getobjectxy(struct ScriptContext *ctx)
{
u32 localId = VarGet(ScriptReadHalfword(ctx));
u32 useTemplate = VarGet(ScriptReadHalfword(ctx));
u16 *pX = GetVarPointer(ScriptReadHalfword(ctx));
u16 *pY = GetVarPointer(ScriptReadHalfword(ctx));
GetObjectPosition(pX,pY,localId,useTemplate);

return FALSE;
}

bool8 ScrCmd_checkobjectat(struct ScriptContext *ctx)
{
u32 x = VarGet(ScriptReadHalfword(ctx)) + 7;
u32 y = VarGet(ScriptReadHalfword(ctx)) + 7;
u16 *varPointer = GetVarPointer(ScriptReadHalfword(ctx));

*varPointer = CheckObjectAtXY(x,y);

return FALSE;
}

bool8 Scrcmd_getsetpokedexflag(struct ScriptContext *ctx)
{
u32 speciesId = SpeciesToNationalPokedexNum(VarGet(ScriptReadHalfword(ctx)));
bool32 desiredFlag = VarGet(ScriptReadHalfword(ctx));
gSpecialVar_Result = GetSetPokedexFlag(speciesId,desiredFlag);

if (desiredFlag == FLAG_SET_CAUGHT)
GetSetPokedexFlag(speciesId,FLAG_SET_SEEN);

return FALSE;
}

bool8 Scrcmd_checkspecies(struct ScriptContext *ctx)
{
u32 givenSpecies = VarGet(ScriptReadHalfword(ctx));
gSpecialVar_Result = CheckPartyHasSpecie(givenSpecies);

return FALSE;
}

bool8 Scrcmd_checkspecies_choose(struct ScriptContext *ctx)
{
u32 givenSpecies = VarGet(ScriptReadHalfword(ctx));
gSpecialVar_Result = (GetMonData(&gPlayerParty[gSpecialVar_0x8004], MON_DATA_SPECIES) == givenSpecies);

return FALSE;
}

bool8 Scrcmd_getobjectfacingdirection(struct ScriptContext *ctx)
{
u32 objectId = VarGet(ScriptReadHalfword(ctx));
u16 *varPointer = GetVarPointer(ScriptReadHalfword(ctx));

*varPointer = gObjectEvents[GetObjectEventIdByLocalId(objectId)].facingDirection;

return FALSE;
}

0 comments on commit f810d7d

Please sign in to comment.