#include <ultra64.h>
#include "functions.h"
#include "variables.h"
#include "bk_time.h"
#define _73640_MAX(s,t) ((s < t)? t: s)
#define _73640_MIN(s,t) ((s > t)? t: s)
typedef void *(*ItemPrintNewFn)(s32);
typedef struct item_print_s{
ItemPrintNewFn unk0;
void (*unk4)(s32, struct8s *);
void (*unk8)(enum item_e, struct8s *, Gfx**, Mtx**, Vtx**);
void (*unkC)(s32, struct8s *);
s32 unk10;
struct8s *unk14;
} ItemPrint;
s32 func_802FAD9C(enum item_e item_id);
s16 D_803692E0[6] = {
ASSET_89D_ZOOMBOX_SPRITE,
ASSET_7D9_SPRITE_NOTE,
ASSET_7DD_SPRITE_HEALTH,
ASSET_35F_MODEL_JIGGY,
0x360,
-1
};
s16 D_803692EC[5] = {
ASSET_580_SPRITE_RED_FEATHER,
ASSET_6D1_SPRITE_GOLDFEATHER,
ASSET_41A_SPRITE_MUMBO_TOKEN,
ASSET_36D_SPRITE_BLUE_EGG,
-1
};
#define NF(fn) (ItemPrintNewFn)(fn)
#define UF(fn) (void (*)(s32, struct8s *))(fn)
#define DF(fn) (void (*)(enum item_e, struct8s *, Gfx**, Mtx**, Vtx**))(fn)
ItemPrint D_803692F8[0x2C] = {
{ NF(fxcommon2score_new), UF(fxcommon2score_update), DF(fxcommon2score_draw), UF(fxcommon2score_free), 5, NULL },
{ NF(fxcommon2score_new), UF(fxcommon2score_update), DF(fxcommon2score_draw), UF(fxcommon2score_free), 0, NULL },
{ NF(fxcommon1score_new), UF(fxcommon1score_update), DF(fxcommon1score_draw), UF(fxcommon1score_free), 0, NULL },
{ NF(fxcommon2score_new), UF(fxcommon2score_update), DF(fxcommon2score_draw), UF(fxcommon2score_free), 5, NULL },
{ NF(fxcommon1score_new), UF(fxcommon1score_update), DF(fxcommon1score_draw), UF(fxcommon1score_free), 0, NULL },
{ NF(fxcommon2score_new), UF(fxcommon2score_update), DF(fxcommon2score_draw), UF(fxcommon2score_free), 0, NULL },
{ NF(fxcommon1score_new), UF(fxcommon1score_update), DF(fxcommon1score_draw), UF(fxcommon1score_free), 0, NULL },
{ NF(fxcommon1score_new), UF(fxcommon1score_update), DF(fxcommon1score_draw), UF(fxcommon1score_free), 0, NULL },
{ NF(fxcommon1score_new), UF(fxcommon1score_update), DF(fxcommon1score_draw), UF(fxcommon1score_free), 0, NULL },
{ NF(fxcommon1score_new), UF(fxcommon1score_update), DF(fxcommon1score_draw), UF(fxcommon1score_free), 0, NULL },
{ NF(fxcommon1score_new), UF(fxcommon1score_update), DF(fxcommon1score_draw), UF(fxcommon1score_free), 0, NULL },
{ NF(fxcommon1score_new), UF(fxcommon1score_update), DF(fxcommon1score_draw), UF(fxcommon1score_free), 0, NULL },
{ NF(fxcommon2score_new), UF(fxcommon2score_update), DF(fxcommon2score_draw), UF(fxcommon2score_free), 1, NULL },
{ NF(fxcommon2score_new), UF(fxcommon2score_update), DF(fxcommon2score_draw), UF(fxcommon2score_free), 1, NULL },
{ NF(fxcommon3score_new), UF(fxcommon3score_update), DF(fxcommon3score_draw), UF(fxcommon3score_free), 3, NULL },
{ NF(fxcommon2score_new), UF(fxcommon2score_update), DF(fxcommon2score_draw), UF(fxcommon2score_free), 1, NULL },
{ NF(fxcommon2score_new), UF(fxcommon2score_update), DF(fxcommon2score_draw), UF(fxcommon2score_free), 1, NULL },
{ NF(fxcommon1score_new), UF(fxcommon1score_update), DF(fxcommon1score_draw), UF(fxcommon1score_free), 0, NULL },
{ NF(fxjinjoscore_new), UF(fxjinjoscore_update), DF(fxjinjoscore_draw), UF(fxjinjoscore_free), 3, NULL },
{ NF(fxhoneycarrierscore_new), UF(fxhoneycarrierscore_update), DF(fxhoneycarrierscore_draw), UF(fxhoneycarrierscore_free), 0, NULL },
{ NF(fxhealthscore_new), UF(fxhealthscore_update), DF(fxhealthscore_draw), UF(fxhealthscore_free), 0, NULL },
{ NF(fxcommon1score_new), UF(fxcommon1score_update), DF(fxcommon1score_draw), UF(fxcommon1score_free), 0, NULL },
{ NF(fxlifescore_new), UF(fxlifescore_update), DF(fxlifescore_draw), UF(fxlifescore_free), 6, NULL },
{ NF(fxairscore_new), UF(fxairscore_update), DF(fxairscore_draw), UF(fxairscore_free), 0, NULL },
{ NF(fxcommon3score_new), UF(fxcommon3score_update), DF(fxcommon3score_draw), UF(fxcommon3score_free), 2, NULL },
{ NF(fxcommon3score_new), UF(fxcommon3score_update), DF(fxcommon3score_draw), UF(fxcommon3score_free), 2, NULL },
{ NF(fxcommon2score_new), UF(fxcommon2score_update), DF(fxcommon2score_draw), UF(fxcommon2score_free), 6, NULL },
{ NF(fxcommon2score_new), UF(fxcommon2score_update), DF(fxcommon2score_draw), UF(fxcommon2score_free), 0, NULL },
{ NF(fxcommon2score_new), UF(fxcommon2score_update), DF(fxcommon2score_draw), UF(fxcommon2score_free), 2, NULL },
{ NF(fxcommon3score_new), UF(fxcommon3score_update), DF(fxcommon3score_draw), UF(fxcommon3score_free), 0, NULL },
{ NF(fxcommon3score_new), UF(fxcommon3score_update), DF(fxcommon3score_draw), UF(fxcommon3score_free), 0, NULL },
{ NF(fxcommon3score_new), UF(fxcommon3score_update), DF(fxcommon3score_draw), UF(fxcommon3score_free), 2, NULL },
{ NF(fxcommon3score_new), UF(fxcommon3score_update), DF(fxcommon3score_draw), UF(fxcommon3score_free), 2, NULL },
{ NF(fxcommon3score_new), UF(fxcommon3score_update), DF(fxcommon3score_draw), UF(fxcommon3score_free), 2, NULL },
{ NF(fxcommon3score_new), UF(fxcommon3score_update), DF(fxcommon3score_draw), UF(fxcommon3score_free), 2, NULL },
{ NF(fxcommon3score_new), UF(fxcommon3score_update), DF(fxcommon3score_draw), UF(fxcommon3score_free), 2, NULL },
{ NF(fxcommon3score_new), UF(fxcommon3score_update), DF(fxcommon3score_draw), UF(fxcommon3score_free), 0, NULL },
{ NF(fxcommon2score_new), UF(fxcommon2score_update), DF(fxcommon2score_draw), UF(fxcommon2score_free), 4, NULL },
{ NF(fxcommon3score_new), UF(fxcommon3score_update), DF(fxcommon3score_draw), UF(fxcommon3score_free), 4, NULL },
{ NF(fxcommon2score_new), UF(fxcommon2score_update), DF(fxcommon2score_draw), UF(fxcommon2score_free), 2, NULL },
{ NF(fxcommon2score_new), UF(fxcommon2score_update), DF(fxcommon1score_draw), UF(fxcommon2score_free), 5, NULL },
{ NF(fxcommon2score_new), UF(fxcommon2score_update), DF(fxcommon1score_draw), UF(fxcommon2score_free), 3, NULL },
{ NF(fxcommon2score_new), UF(fxcommon2score_update), DF(fxcommon1score_draw), UF(fxcommon2score_free), 2, NULL },
{ NF(fxcommon3score_new), UF(fxcommon3score_update), DF(fxcommon3score_draw), UF(fxcommon3score_free), 2, NULL }
};
s32 D_803810B0;
f32 itemPrintValues[0x2C];
s32 D_80381168[0x2C];
f32 D_80381218[0x2C];
s32 D_803812C8[0x2C];
s32 D_80381378[0x2C];
void *D_80381428[10];
void *D_80381450[10];
s32 D_80381478[0X2C];
void itemPrint_reset(void){
s32 i;
for(i = 0; i < 0x2C; i++){
itemPrintValues[i] = item_getCount(i);
D_80381378[i] = 0;
D_803812C8[i] = 0;
D_80381168[i] = 0;
D_80381218[i] = 0.7f;
}
}
void func_802FA69C(void){
s32 i;
D_803810B0 = 1;
for(i = 0; i< 0x2C; i++){
D_803692F8[i].unk14 = D_803692F8[i].unk0(i);
func_802FB104(D_803692F8[i].unk10, D_803692F8[i].unk14);
}
itemPrint_reset();
}
void func_802FA718(s32 arg0){
D_803810B0 = arg0;
}
void itemPrint_update(void) {
f32 diff;
s32 i;
f32 sign;
func_802FB1CC();
for(i = 0; i< 0x2C; i++){
if(func_802FAD9C(i)){
if (item_getCount(i) != (s32) (itemPrintValues[i] + 0.01)) {
diff = (f32) item_getCount(i) - itemPrintValues[i];
sign = (diff >= 0.0f) ? 1.0f : -1.0f;
if (D_80381378[i] != 0) {
itemPrintValues[i] += sign *_73640_MIN(time_getDelta() * 6.0f, 1.0);
} else {
itemPrintValues[i] += (sign * _73640_MIN(time_getDelta() * _73640_MAX(diff, 8.0f), 1.0));
}
if ((D_80381168[i] != 0) && ((globalTimer_getTime() & 7) == 0)) {
coMusicPlayer_playMusic(D_80381168[i], 32000);
}
if (D_80381378[i] != 0) {
if ((D_80381478[i] != 0) && ((s32) diff != D_80381478[i])) {
if (itemPrintValues[i] > 9.0f) {
gcsfx_playWithPitch(D_80381378[i], D_80381218[i], 0x7D00);
D_80381218[i] = _73640_MIN(D_80381218[i] + 0.1, 2.0);
}
}
}
D_80381478[i] = diff;
func_802FB020(D_803692F8[i].unk14, 1);
if ((i == ITEM_14_HEALTH) || (i == ITEM_17_AIR)) {
func_802FB020(D_803692F8[0x16].unk14, 1);
}
if (item_getCount(i) == (s32) (itemPrintValues[i] + 0.01)) {
do{
if (D_803812C8[i] != 0) {
coMusicPlayer_playMusic(D_803812C8[i], 0x7D00);
}
D_80381378[i] = 0;
D_803812C8[i] = 0;
D_80381168[i] = 0;
D_80381218[i] = 0.7f;
D_80381478[i] = 0;
}while(0);
}
}
}
}
for(i = 0; i< 0x2C; i++){
func_802FB15C(D_803692F8[i].unk10, D_803692F8[i].unk14);
D_803692F8[i].unk4(i, D_803692F8[i].unk14);
}
}
void itemPrint_draw(Gfx **gfx, Mtx **mtx, Vtx **vtx) {
s32 i;
if(D_803810B0 && level_get() != LEVEL_D_CUTSCENE){
for(i = 0; i < 0x2C; i++){
if(!func_802E4A08() || i < 6){
if(func_802FB0D4(D_803692F8[i].unk14)){
D_803692F8[i].unk8(i, D_803692F8[i].unk14, gfx, mtx, vtx);
}
}
}
}
}
void func_802FAC3C(void){
s32 i;
for(i = 0; i< 0x2C; i++){
func_802FB194(D_803692F8[i].unk10, D_803692F8[i].unk14);
D_803692F8[i].unkC(i, D_803692F8[i].unk14);
}
}
void code_73640_printItemCount(enum item_e item_id){
if(func_802FB0D4(D_803692F8[item_id].unk14) == 2 || item_id < 6 || item_id == ITEM_17_AIR ){
itemPrintValues[item_id] += ((f32)item_getCount(item_id) - itemPrintValues[item_id] )*0.7;
}
func_802FB020(D_803692F8[item_id].unk14, 1);
}
void func_802FAD64(enum item_e item_id){
func_802FB020(D_803692F8[item_id].unk14, 3);
}
s32 func_802FAD9C(enum item_e item_id){
return (func_802FB0D4(D_803692F8[item_id].unk14) == 2);
}
bool func_802FADD4(enum item_e item_id){
s32 v0 = func_802FB0D4(D_803692F8[item_id].unk14);
return (v0 == 2)||(v0 == 1);
}
s32 itemPrint_getValue(s32 item_id){
return itemPrintValues[item_id] + 0.01;
}
void itemPrint_init(void){
s32 i;
BKSpriteDisplayData *sp40;
for(i = 0; D_803692E0[i] != -1; i++){
D_80381428[i] = assetcache_get(D_803692E0[i]);
}
for(i = 0; D_803692EC[i] != -1; i++){
D_80381450[i] = codeB3A80_getSprite(D_803692EC[i], &sp40);
}
}
void itemPrint_free(void){
s32 i;
for(i = 0; D_803692E0[i] != -1; i++){
assetcache_release(D_80381428[i]);
}
for(i = 0; D_803692EC[i] != -1; i++){
assetcache_release(D_80381450[i]);
}
}
void func_802FAFAC(enum item_e item_id, enum comusic_e music_id){
D_80381168[item_id] = music_id;
}
void func_802FAFC0(enum item_e item_id, enum comusic_e music_id){
D_803812C8[item_id] = music_id;
}
void func_802FAFD4(enum item_e item_id, enum sfx_e sfx_id){
D_80381378[item_id] = sfx_id;
}
bool func_802FAFE8(enum item_e item_id){
return func_802FCD98(D_803692F8[item_id].unk14);
}