mirror of
https://github.com/pret/pokeheartgold.git
synced 2024-12-12 15:16:55 +00:00
start cleaning up move_relearner.c
This commit is contained in:
parent
f315473a18
commit
1efbb5d7fb
@ -1,22 +0,0 @@
|
||||
#ifndef POKEHEARTGOLD_FIELD_BLACKTHORN_TUTORS_H
|
||||
#define POKEHEARTGOLD_FIELD_BLACKTHORN_TUTORS_H
|
||||
|
||||
#include "player_data.h"
|
||||
#include "pokemon_types_def.h"
|
||||
typedef struct MoveRelearner { //todo: move to unk_0203E348? rename to MoveRelearnerAppData?
|
||||
Pokemon *mon;
|
||||
PlayerProfile *profile;
|
||||
Options *options;
|
||||
u8 filler_0C[4];
|
||||
u16 *eligibleMoves;
|
||||
u8 filler_14[5];
|
||||
u8 unk_19;
|
||||
u8 padding_1A[2];
|
||||
} MoveRelearner;
|
||||
|
||||
struct MoveRelearner *MoveRelearner_New(HeapID heapId);
|
||||
void MoveRelearner_Delete(struct MoveRelearner *moveRelearner);
|
||||
u16 *GetEligibleLevelUpMoves(Pokemon *mon, HeapID heapId);
|
||||
BOOL sub_0209186C(const u16 *ptr);
|
||||
|
||||
#endif //POKEHEARTGOLD_FIELD_BLACKTHORN_TUTORS_H
|
23
include/move_relearner.h
Normal file
23
include/move_relearner.h
Normal file
@ -0,0 +1,23 @@
|
||||
#ifndef POKEHEARTGOLD_MOVE_RELEARNER_H
|
||||
#define POKEHEARTGOLD_MOVE_RELEARNER_H
|
||||
|
||||
#include "player_data.h"
|
||||
#include "pokemon_types_def.h"
|
||||
|
||||
typedef struct MoveRelearner {
|
||||
Pokemon *mon;
|
||||
PlayerProfile *profile;
|
||||
Options *options;
|
||||
u8 filler_0C[4];
|
||||
u16 *eligibleMoves;
|
||||
u8 filler_14[5];
|
||||
u8 unk_19;
|
||||
u8 padding_1A[2];
|
||||
} MoveRelearner;
|
||||
|
||||
MoveRelearner *MoveRelearner_New(HeapID heapId);
|
||||
void MoveRelearner_Delete(MoveRelearner *moveRelearner);
|
||||
u16 *MoveRelearner_GetEligibleLevelUpMoves(Pokemon *mon, HeapID heapId);
|
||||
BOOL sub_0209186C(const u16 *ptr);
|
||||
|
||||
#endif //POKEHEARTGOLD_MOVE_RELEARNER_H
|
@ -8,7 +8,7 @@
|
||||
#include "bag.h"
|
||||
#include "mail.h"
|
||||
#include "fashion_case.h"
|
||||
#include "field_blackthorn_tutors.h"
|
||||
#include "move_relearner.h"
|
||||
#include "credits/credits.h"
|
||||
|
||||
struct UseMailWork;
|
||||
@ -155,7 +155,7 @@ void *sub_0203F984(FieldSystem *fieldSystem);
|
||||
void *sub_0203F844(FieldSystem *fieldSystem, u16 a1);
|
||||
void *sub_0203E460(FieldSystem *fieldSystem, u8 a1);
|
||||
u16 sub_0203E4CC(void *a0);
|
||||
void sub_0203F9C4(FieldSystem *fieldSystem, struct MoveRelearner *moveRelearner);
|
||||
void sub_0203F9C4(FieldSystem *fieldSystem, MoveRelearner *moveRelearner);
|
||||
|
||||
static inline void InitUnkStructScrCmd408(struct UnkStruct_ScrCmd408 *data, u16 a1, u16 a2, ScriptContext *ctx) {
|
||||
MI_CpuClear8(data, sizeof(struct UnkStruct_ScrCmd408));
|
||||
|
2
main.lsf
2
main.lsf
@ -298,7 +298,7 @@ Static main
|
||||
Object asm/unk_02091564.o
|
||||
Object asm/unk_020915B0.o
|
||||
Object asm/unk_02091664.o
|
||||
Object src/field_blackthorn_tutors.o
|
||||
Object src/move_relearner.o
|
||||
Object asm/unk_02091880.o
|
||||
Object asm/unk_02091CDC.o
|
||||
Object asm/unk_020921A4.o
|
||||
|
@ -1,71 +0,0 @@
|
||||
#include "global.h"
|
||||
#include "field_blackthorn_tutors.h"
|
||||
#include "pokemon.h"
|
||||
|
||||
struct MoveRelearner *MoveRelearner_New(HeapID heapId) {
|
||||
struct MoveRelearner *ret;
|
||||
|
||||
ret = AllocFromHeap(heapId, sizeof(struct MoveRelearner));
|
||||
memset(ret, 0, sizeof(struct MoveRelearner));
|
||||
return ret;
|
||||
}
|
||||
|
||||
void MoveRelearner_Delete(struct MoveRelearner *moveRelearner) {
|
||||
FreeToHeap(moveRelearner);
|
||||
}
|
||||
|
||||
u16 *GetEligibleLevelUpMoves(Pokemon *mon, HeapID heapId) {
|
||||
u16 cur_moveset[MAX_MON_MOVES]; // sp+10
|
||||
u16 species; // sp+0C
|
||||
u8 form; // sp+08
|
||||
u8 level; // sp+04
|
||||
u16 *ret;
|
||||
u16 *wotbl;
|
||||
u8 i, j, ct;
|
||||
|
||||
species = GetMonData(mon, MON_DATA_SPECIES, NULL);
|
||||
form = GetMonData(mon, MON_DATA_FORM, NULL);
|
||||
level = GetMonData(mon, MON_DATA_LEVEL, NULL);
|
||||
for (i = 0; i < MAX_MON_MOVES; i++) {
|
||||
cur_moveset[i] = GetMonData(mon, MON_DATA_MOVE1 + i, NULL);
|
||||
}
|
||||
|
||||
wotbl = AllocFromHeap(heapId, WOTBL_MAX * 2);
|
||||
ret = AllocFromHeap(heapId, WOTBL_MAX * 2);
|
||||
|
||||
LoadWotbl_HandleAlternateForm(species, form, wotbl);
|
||||
|
||||
ct = 0;
|
||||
for (i = 0; i < WOTBL_MAX; i++) {
|
||||
if (wotbl[i] == WOTBL_END) {
|
||||
ret[ct] = WOTBL_END;
|
||||
break;
|
||||
} else if (((wotbl[i] & WOTBL_LEVEL_MASK) >> WOTBL_LEVEL_SHIFT) > level) {
|
||||
continue;
|
||||
} else {
|
||||
wotbl[i] &= WOTBL_MOVEID_MASK;
|
||||
for (j = 0; j < MAX_MON_MOVES; j++) {
|
||||
if (wotbl[i] == cur_moveset[j]) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (j == MAX_MON_MOVES) {
|
||||
for (j = 0; j < ct; j++) {
|
||||
if (ret[j] == wotbl[i]) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (j == ct) {
|
||||
ret[ct] = wotbl[i];
|
||||
ct++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
FreeToHeap(wotbl);
|
||||
return ret;
|
||||
}
|
||||
|
||||
BOOL sub_0209186C(const u16 *ptr) {
|
||||
return *ptr != WOTBL_END;
|
||||
}
|
63
src/move_relearner.c
Normal file
63
src/move_relearner.c
Normal file
@ -0,0 +1,63 @@
|
||||
#include "global.h"
|
||||
#include "move_relearner.h"
|
||||
#include "pokemon.h"
|
||||
|
||||
MoveRelearner *MoveRelearner_New(HeapID heapId) {
|
||||
MoveRelearner *ret = AllocFromHeap(heapId, sizeof(MoveRelearner));
|
||||
memset(ret, 0, sizeof(MoveRelearner));
|
||||
return ret;
|
||||
}
|
||||
|
||||
void MoveRelearner_Delete(MoveRelearner *moveRelearner) {
|
||||
FreeToHeap(moveRelearner);
|
||||
}
|
||||
|
||||
//BUILD FAILS - JUST NOT GONNA DO THIS SHIT RN
|
||||
u16 *MoveRelearner_GetEligibleLevelUpMoves(Pokemon *mon, HeapID heapId) {
|
||||
u16 species = (u16)GetMonData(mon, MON_DATA_SPECIES, NULL);
|
||||
u8 form = (u8)GetMonData(mon, MON_DATA_FORM, NULL);
|
||||
u8 level = (u8)GetMonData(mon, MON_DATA_LEVEL, NULL);
|
||||
u16 moves[MAX_MON_MOVES];
|
||||
|
||||
for (u8 i = 0; i < MAX_MON_MOVES; i++) {
|
||||
moves[i] = (u16)GetMonData(mon, MON_DATA_MOVE1 + i, NULL);
|
||||
}
|
||||
|
||||
u16 *tableFromFile = AllocFromHeap(heapId, WOTBL_MAX * 2);
|
||||
u16 *returnTable = AllocFromHeap(heapId, WOTBL_MAX * 2);
|
||||
|
||||
LoadWotbl_HandleAlternateForm(species, form, tableFromFile);
|
||||
|
||||
for (u8 i = 0, j, k = 0; i < WOTBL_MAX; i++) {
|
||||
if (tableFromFile[i] == WOTBL_END) {
|
||||
returnTable[k] = WOTBL_END;
|
||||
break;
|
||||
} else if (WOTBL_LVL(tableFromFile[i]) > level) {
|
||||
continue;
|
||||
} else {
|
||||
tableFromFile[i] = WOTBL_MOVE(tableFromFile[i]);
|
||||
for (j = 0; j < MAX_MON_MOVES; j++) {
|
||||
if (tableFromFile[i] == moves[j]) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (j == MAX_MON_MOVES) {
|
||||
for (j = 0; j < k; j++) {
|
||||
if (returnTable[j] == tableFromFile[i]) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (j == k) {
|
||||
returnTable[k] = tableFromFile[i];
|
||||
k++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
FreeToHeap(tableFromFile);
|
||||
return returnTable;
|
||||
}
|
||||
|
||||
BOOL sub_0209186C(const u16 *ptr) { //MoveRelearner_IsValidMove?
|
||||
return *ptr != WOTBL_END;
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
#include "scrcmd.h"
|
||||
#include "unk_0203E348.h"
|
||||
#include "field_blackthorn_tutors.h"
|
||||
#include "move_relearner.h"
|
||||
|
||||
BOOL ScrNative_WaitApplication(ScriptContext *ctx);
|
||||
|
||||
@ -32,7 +32,7 @@ BOOL ScrCmd_466(ScriptContext *ctx) {
|
||||
u16 slot = ScriptGetVar(ctx);
|
||||
Party *party = SaveArray_Party_Get(ctx->fieldSystem->saveData);
|
||||
Pokemon *mon = Party_GetMonByIndex(party, slot);
|
||||
u16 *eligibleMoves = GetEligibleLevelUpMoves(mon, HEAP_ID_32);
|
||||
u16 *eligibleMoves = MoveRelearner_GetEligibleLevelUpMoves(mon, HEAP_ID_32);
|
||||
*retPtr = sub_0209186C(eligibleMoves);
|
||||
FreeToHeap(eligibleMoves);
|
||||
return FALSE;
|
||||
@ -57,7 +57,7 @@ static void CreateMoveRelearner(ScriptContext *ctx, int a1, Pokemon *mon, u16 *e
|
||||
BOOL ScrCmd_MoveRelearnerInit(ScriptContext *ctx) {
|
||||
u16 slot = ScriptGetVar(ctx);
|
||||
Pokemon *mon = Party_GetMonByIndex(SaveArray_Party_Get(ctx->fieldSystem->saveData), slot);
|
||||
u16 *eligibleMoves = GetEligibleLevelUpMoves(mon, HEAP_ID_32);
|
||||
u16 *eligibleMoves = MoveRelearner_GetEligibleLevelUpMoves(mon, HEAP_ID_32);
|
||||
CreateMoveRelearner(ctx, 1, mon, eligibleMoves);
|
||||
return TRUE;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user