Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds new scripting macros to increase developer quality of life #5177

Merged
merged 35 commits into from
Oct 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
73953b3
Added removeallitem
pkmnsnfrn Aug 10, 2024
811b5d2
Added getobjectposition
pkmnsnfrn Aug 11, 2024
0784f9f
Added checkobjectat
pkmnsnfrn Aug 11, 2024
fba1452
Added Seen/CaughtMon macros
pkmnsnfrn Aug 12, 2024
e746334
Added setmonball
pkmnsnfrn Aug 12, 2024
2625055
checkforspecies
pkmnsnfrn Aug 12, 2024
7f5ecd8
getobjectfacingdirection
pkmnsnfrn Aug 12, 2024
7869cb4
Improved RemoveAllItem
pkmnsnfrn Aug 12, 2024
ebae09f
Improved checkobjectat
pkmnsnfrn Aug 12, 2024
abb17ea
Improved dex flags functions
pkmnsnfrn Aug 12, 2024
f0d5b68
Improved checkspecies functions
pkmnsnfrn Aug 12, 2024
881e54a
Incremental improvement of getobjectfacing
pkmnsnfrn Aug 12, 2024
bdeedaa
Renamed evObjId to localId
pkmnsnfrn Aug 15, 2024
458340e
Moved pokedex special constants to header
pkmnsnfrn Aug 15, 2024
dc06321
Moved pokedex flags to constants files andadded constants to header o…
pkmnsnfrn Aug 15, 2024
67f8a61
Moved current and template positions to headers
pkmnsnfrn Aug 15, 2024
fed7fc4
Fixed bug with checkobjectat
pkmnsnfrn Aug 15, 2024
287f6ba
spaces over tabs please don't eat my ass
pkmnsnfrn Aug 15, 2024
e702308
Merge branch 'upcoming' into scriptCommands
pkmnsnfrn Aug 28, 2024
a0e914b
Merge branch 'upcoming' into scriptCommands
pkmnsnfrn Sep 12, 2024
f87440a
Removed setmonball per https://github.com/rh-hideout/pokeemerald-expa…
pkmnsnfrn Sep 12, 2024
979c999
Set VAR_RESULT to the number of removed items from removeallitem per …
pkmnsnfrn Sep 12, 2024
22b0fdf
Removed checkspecies_auto and made that the default behavior
pkmnsnfrn Sep 13, 2024
10bb349
Changed GetObjectPosition to callnative
pkmnsnfrn Sep 13, 2024
be7938f
Changed CheckObjectAtXY to callnative
pkmnsnfrn Sep 13, 2024
c2db77c
Changed Script_GetSetPokedexFlag to callnative
pkmnsnfrn Sep 13, 2024
ecd435c
Changed CheckChosenMOnMatchDesiredSpecies and CheckPartyHasSpecies to…
pkmnsnfrn Sep 13, 2024
510af1b
Restored original functions and made script versions
pkmnsnfrn Sep 13, 2024
a509f28
Changed Scripot_GetObjectFacingDirection to callnative
pkmnsnfrn Sep 14, 2024
1665423
Renamed scripts to match vanilla
pkmnsnfrn Sep 14, 2024
60fb0b3
Modified getobjectxy to allow for custom destinations
pkmnsnfrn Sep 14, 2024
3b226fc
Removed swp
pkmnsnfrn Sep 14, 2024
d76ccdd
spaces to tabs in inc files
pkmnsnfrn Sep 14, 2024
58aa1e0
Merge branch 'upcoming' into scriptCommands
pkmnsnfrn Sep 30, 2024
0ef3f7d
Merge branch 'upcoming' into scriptCommands
pkmnsnfrn Oct 11, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
Loading