Skip to content

Commit

Permalink
Add ribbon API to picoc
Browse files Browse the repository at this point in the history
  • Loading branch information
piepie62 committed Apr 10, 2024
1 parent a8006eb commit e8ff940
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 1 deletion.
38 changes: 38 additions & 0 deletions 3ds/source/picoc/pksm_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2162,6 +2162,44 @@ void pkx_update_party_data(
pkm->updatePartyData();
}

void pkx_ribbon_exists(
struct ParseState* Parser, struct Value* ReturnValue, struct Value** Param, int NumArgs)
{
pksm::Generation gen = pksm::Generation(Param[0]->Val->Integer);
pksm::Ribbon ribbon = pksm::Ribbon(Param[1]->Val->Integer);

checkGen(Parser, gen);

ReturnValue->Val->Integer = PkmUtils::getDefault(gen)->hasRibbon(ribbon) ? 1 : 0;
}

void pkx_get_ribbon(struct ParseState* Parser, struct Value* ReturnValue, struct Value** Param, int NumArgs)
{
u8* data = (u8*)Param[0]->Val->Pointer;
pksm::Generation gen = pksm::Generation(Param[1]->Val->Integer);
pksm::Ribbon ribbon = pksm::Ribbon(Param[2]->Val->Integer);

checkGen(Parser, gen);

auto pkm = getPokemon(data, gen, false);

ReturnValue->Val->Integer = pkm->ribbon(ribbon) ? 1 : 0;
}

void pkx_set_ribbon(struct ParseState* Parser, struct Value* ReturnValue, struct Value** Param, int NumArgs)
{
u8* data = (u8*)Param[0]->Val->Pointer;
pksm::Generation gen = pksm::Generation(Param[1]->Val->Integer);
pksm::Ribbon ribbon = pksm::Ribbon(Param[2]->Val->Integer);
int shouldHave = Param[3]->Val->Integer;

checkGen(Parser, gen);

auto pkm = getPokemon(data, gen, false);

pkm->ribbon(ribbon, shouldHave != 0);
}

void sav_get_palpark(
struct ParseState* Parser, struct Value* ReturnValue, struct Value** Param, int NumArgs)
{
Expand Down
3 changes: 3 additions & 0 deletions common/include/picoc/pksm_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,9 @@ void pkx_is_valid(struct ParseState*, struct Value*, struct Value**, int);
void pkx_set_value(struct ParseState*, struct Value*, struct Value**, int);
void pkx_get_value(struct ParseState*, struct Value*, struct Value**, int);
void pkx_update_party_data(struct ParseState*, struct Value*, struct Value**, int);
void pkx_ribbon_exists(struct ParseState*, struct Value*, struct Value**, int);
void pkx_get_ribbon(struct ParseState*, struct Value*, struct Value**, int);
void pkx_set_ribbon(struct ParseState*, struct Value*, struct Value**, int);
// random utilities
void pksm_utf8_to_ucs2(struct ParseState*, struct Value*, struct Value**, int);
void pksm_ucs2_to_utf8(struct ParseState*, struct Value*, struct Value**, int);
Expand Down
28 changes: 27 additions & 1 deletion common/source/picoc/library_pksm.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,9 @@ struct LibraryFunction UnixFunctions[] =
{ pkx_set_value, "void pkx_set_value(char* data, enum Generation gen, enum PKX_Field field, ...);" },
{ pkx_get_value, "unsigned int pkx_get_value(char* data, enum Generation gen, enum PKX_Field field, ...);" },
{ pkx_update_party_data, "void pkx_update_party_data(char* data, enum Generation gen);"},
{ pkx_ribbon_exists, "int pkx_ribbon_exists(enum Generation gen, enum Ribbon ribbon);"},
{ pkx_get_ribbon, "int pkx_get_ribbon(char* data, enum Generation gen, enum Ribbon ribbon);"},
{ pkx_set_ribbon, "void pkx_set_ribbon(char* data, enum Generation gen, enum Ribbon ribbon, int hasRibbon);"},
// io
{ current_directory, "char* current_directory(void);" },
{ read_directory, "struct directory* read_directory(char* dir);" },
Expand Down Expand Up @@ -127,5 +130,28 @@ void PlatformLibraryInit(Picoc *pc)
"SAV_LANGUAGE, SAV_MONEY, SAV_BP, SAV_HOURS, SAV_MINUTES, SAV_SECONDS, SAV_ITEM };"
"enum SAV_MaxField { MAX_SLOTS, MAX_BOXES, MAX_WONDER_CARDS, MAX_FORM, MAX_IN_POUCH };"
"enum SAV_CheckValue { SAV_VALUE_SPECIES, SAV_VALUE_MOVE, SAV_VALUE_ITEM, SAV_VALUE_ABILITY, SAV_VALUE_BALL };"
"enum Pouch { NormalItem, KeyItem, TM, Mail, Medicine, Berry, Ball, Battle, Candy, ZCrystals };");
"enum Pouch { NormalItem, KeyItem, TM, Mail, Medicine, Berry, Ball, Battle, Candy, ZCrystals };"
"enum Ribbon {RIB_ChampionKalos, RIB_ChampionG3Hoenn, RIB_ChampionSinnoh, RIB_BestFriends, RIB_Training, RIB_BattlerSkillful,"
"RIB_BattlerExpert, RIB_Effort, RIB_Alert, RIB_Shock, RIB_Downcast, RIB_Careless, RIB_Relax, RIB_Snooze, RIB_Smile, RIB_Gorgeous,"
"RIB_Royal, RIB_GorgeousRoyal, RIB_Artist, RIB_Footprint, RIB_Record, RIB_Legend, RIB_Country, RIB_National, RIB_Earth, RIB_World,"
"RIB_Classic, RIB_Premier, RIB_Event, RIB_Birthday, RIB_Special, RIB_Souvenir, RIB_Wishing, RIB_ChampionBattle, RIB_ChampionRegional,"
"RIB_ChampionNational, RIB_ChampionWorld, RIB_MemoryContest, RIB_MemoryBattle, RIB_ChampionG6Hoenn, RIB_ContestStar,"
"RIB_MasterCoolness, RIB_MasterBeauty, RIB_MasterCuteness, RIB_MasterCleverness, RIB_MasterToughness, RIB_G3Cool,"
"RIB_G3CoolSuper, RIB_G3CoolHyper, RIB_G3CoolMaster, RIB_G3Beauty, RIB_G3BeautySuper, RIB_G3BeautyHyper, RIB_G3BeautyMaster,"
"RIB_G3Cute, RIB_G3CuteSuper, RIB_G3CuteHyper, RIB_G3CuteMaster, RIB_G3Smart, RIB_G3SmartSuper, RIB_G3SmartHyper, RIB_G3SmartMaster,"
"RIB_G3Tough, RIB_G3ToughSuper, RIB_G3ToughHyper, RIB_G3ToughMaster, RIB_G4Cool, RIB_G4CoolSuper, RIB_G4CoolHyper, RIB_G4CoolMaster,"
"RIB_G4Beauty, RIB_G4BeautySuper, RIB_G4BeautyHyper, RIB_G4BeautyMaster, RIB_G4Cute, RIB_G4CuteSuper, RIB_G4CuteHyper,"
"RIB_G4CuteMaster, RIB_G4Smart, RIB_G4SmartSuper, RIB_G4SmartHyper, RIB_G4SmartMaster, RIB_G4Tough, RIB_G4ToughSuper,"
"RIB_G4ToughHyper, RIB_G4ToughMaster, RIB_Winning, RIB_Victory, RIB_Ability, RIB_AbilityGreat, RIB_AbilityDouble, RIB_AbilityMulti,"
"RIB_AbilityPair, RIB_AbilityWorld, RIB_ChampionAlola, RIB_BattleRoyale, RIB_BattleTreeGreat, RIB_BattleTreeMaster,"
"RIB_ChampionGalar, RIB_TowerMaster, RIB_MasterRank, RIB_MarkLunchtime, RIB_MarkSleepyTime, RIB_MarkDusk, RIB_MarkDawn,"
"RIB_MarkCloudy, RIB_MarkRainy, RIB_MarkStormy, RIB_MarkSnowy, RIB_MarkBlizzard, RIB_MarkDry, RIB_MarkSandstorm, RIB_MarkMisty,"
"RIB_MarkDestiny, RIB_MarkFishing, RIB_MarkCurry, RIB_MarkUncommon, RIB_MarkRare, RIB_MarkRowdy, RIB_MarkAbsentMinded,"
"RIB_MarkJittery, RIB_MarkExcited, RIB_MarkCharismatic, RIB_MarkCalmness, RIB_MarkIntense, RIB_MarkZonedOut, RIB_MarkJoyful,"
"RIB_MarkAngry, RIB_MarkSmiley, RIB_MarkTeary, RIB_MarkUpbeat, RIB_MarkPeeved, RIB_MarkIntellectual, RIB_MarkFerocious,"
"RIB_MarkCrafty, RIB_MarkScowling, RIB_MarkKindly, RIB_MarkFlustered, RIB_MarkPumpedUp, RIB_MarkZeroEnergy, RIB_MarkPrideful,"
"RIB_MarkUnsure, RIB_MarkHumble, RIB_MarkThorny, RIB_MarkVigor, RIB_MarkSlump, RIB_G4CoolGreat = RIB_G4CoolSuper,"
"RIB_G4CoolUltra = RIB_G4CoolHyper, RIB_G4BeautyGreat = RIB_G4BeautySuper, RIB_G4BeautyUltra = RIB_G4BeautyHyper,"
"RIB_G4CuteGreat = RIB_G4CuteSuper, RIB_G4CuteUltra = RIB_G4CuteHyper, RIB_G4SmartGreat = RIB_G4SmartSuper,"
"RIB_G4SmartUltra = RIB_G4SmartHyper, RIB_G4ToughGreat = RIB_G4ToughSuper, RIB_G4ToughUltra = RIB_G4ToughHyper };");
}

0 comments on commit e8ff940

Please sign in to comment.