From 51dbb6e5d790ac0a02fb0d356d353b528018248d Mon Sep 17 00:00:00 2001 From: Ethan Roseman Date: Thu, 4 Feb 2021 20:28:01 +0900 Subject: [PATCH] improve coconut --- include/common_structs.h | 6 +++ include/functions.h | 4 ++ include/macros.h | 1 + src/battle/item/coconut.c | 71 ++++++++++++++++++++++-------------- src/code_80850_len_3060.c | 2 +- src/code_8560.c | 3 +- src/code_d5a50_len_5fd0.c | 4 +- tools/permuter_settings.toml | 2 + 8 files changed, 60 insertions(+), 33 deletions(-) diff --git a/include/common_structs.h b/include/common_structs.h index 386644c345..05ddbf7136 100644 --- a/include/common_structs.h +++ b/include/common_structs.h @@ -37,6 +37,12 @@ typedef struct Vec3f { /* 0x08 */ f32 z; } Vec3f; // size = 0x0C +typedef struct Vec3i { + /* 0x00 */ s32 x; + /* 0x04 */ s32 y; + /* 0x08 */ s32 z; +} Vec3i; // size = 0x0C + typedef struct Vec2s { /* 0x00 */ s16 x; /* 0x02 */ s16 y; diff --git a/include/functions.h b/include/functions.h index 76068ca32f..487ce9710b 100644 --- a/include/functions.h +++ b/include/functions.h @@ -100,6 +100,7 @@ Trigger* get_trigger_by_id(s32 triggerID); Actor* get_actor(ActorID actorID); ActorPart* get_actor_part(Actor* actor, s32 partIndex); +s32 add_coins(s32 amt); s32 func_800494C0(Npc* npc, s32 arg1, s32 arg2); @@ -121,6 +122,9 @@ s32 func_80055464(s32, s32); void func_800561A4(s32); s32 osGetId(); +s32* create_icon(s32 iconIndex); +void set_icon_render_pos(s32 iconIndex, s32 posX, s32 posY); + void set_curtain_scale_goal(f32 scale); void set_curtain_fade(f32 scale); diff --git a/include/macros.h b/include/macros.h index 02be32f6da..c779514c50 100644 --- a/include/macros.h +++ b/include/macros.h @@ -24,6 +24,7 @@ #define STATIC_ASSERT(condition) enum { static_assert_fail = 1/(!!(condition)) } // Causes division by zero ("not integer constant") if false #define BATTLE_STATUS (&gBattleStatus) +#define PLAYER (gBattleStatus.playerActor) #define GAME_STATUS (*gGameStatusPtr) #define PLAYER_STATUS (&gPlayerStatus) #define UI_STATUS (&gUIStatus) diff --git a/src/battle/item/coconut.c b/src/battle/item/coconut.c index b003aafb6d..8651b9b99a 100644 --- a/src/battle/item/coconut.c +++ b/src/battle/item/coconut.c @@ -4,54 +4,67 @@ MenuIcon* D_802A1E80; void* D_80108A64; // an image -// TODO +#ifdef NON_MATCHING ApiStatus func_802A1000_72F720(ScriptInstance* script, s32 isInitialCall) { - MenuIcon *temp_a0; - f32 playerTop; - s32 sellValue; - s32 temp_s0; - s32 numCoins; - s32 temp_v0; + BattleStatus* battleStatus; Actor* player; + Actor* player2; + s32 sellValue; + s32 numCoins; s32 pickupDelay; f32 facingAngleSign; - s32 phi_s0; - s32 i = 0; - s32 phi_s0_2; + s32 i; + + f32 posX; + f32 posY; + f32 posZ; s32 iconX; s32 iconY; s32 iconZ; - BattleStatus* battleStatus = BATTLE_STATUS; + i = 0; + facingAngleSign = 0.0f; - player = &battleStatus->playerActor; + battleStatus = BATTLE_STATUS; sellValue = gItemTable[battleStatus->selectedItemID].sellValue; - playerTop = player->currentPos.y + (f32) player->size.y; + posY = battleStatus->playerActor->currentPos.y + battleStatus->playerActor->size.y; + + player = PLAYER; // If Refund is equipped, the player gets - if (heroes_is_ability_active(player, Ability_REFUND)) { + if (heroes_is_ability_active(battleStatus->playerActor, Ability_REFUND)) { + //player2 = player; + if (sellValue > 0) { // 75% of the item's sell value, rounded up - numCoins = (sellValue * 75 + 99) / 100; + sellValue = (sellValue * 75 + 99) / 100; - if (numCoins > 0) { - pickupDelay = 1; - facingAngleSign = 0.0f; + pickupDelay = 1; + player2 = player; - for (i = 0; i < numCoins; i++) { - make_item_entity(ItemId_COIN, player->currentPos.x, playerTop, player->currentPos.z, 0x17, pickupDelay, facingAngleSign, 0); - add_coins(1); + while (i < sellValue) { + posX = player2->currentPos.x; + posZ = player2->currentPos.z; - pickupDelay += 3; - facingAngleSign += 30.0f; - } + make_item_entity(ItemId_COIN, posX, posY, posZ, 0x17, pickupDelay, facingAngleSign, 0); + add_coins(1); + + pickupDelay += 3; + facingAngleSign += 30.0f; + i++; } - get_screen_coords(gCurrentCameraID, player->currentPos.x, player->currentPos.y, player->currentPos.z, &iconX, &iconY, &iconZ); + i = (i * 3) + 30; + + //player2 = player; + posX = player2->currentPos.x; + posY = player2->currentPos.y; + posZ = player2->currentPos.z; + + get_screen_coords(gCurrentCameraID, posX, posY, posZ, &iconX, &iconY, &iconZ); D_802A1E80 = create_icon(&D_80108A64); - set_icon_render_pos(D_802A1E80, iconX + 0x24, iconY - 0x3F); - i = (i * 2) + i + 0x1E; + set_icon_render_pos(D_802A1E80, iconX + 36, iconY - 63); } } @@ -59,7 +72,9 @@ ApiStatus func_802A1000_72F720(ScriptInstance* script, s32 isInitialCall) { return ApiStatus_DONE2; } -//INCLUDE_ASM(ApiStatus, "battle/item/coconut", func_802A1000_72F720, ScriptInstance* script, s32 isInitialCall); +#else +INCLUDE_ASM(ApiStatus, "battle/item/coconut", func_802A1000_72F720, ScriptInstance* script, s32 isInitialCall); +#endif ApiStatus func_802A11D4_72F8F4(ScriptInstance* script, s32 isInitialCall) { BattleStatus* battleStatus = BATTLE_STATUS; diff --git a/src/code_80850_len_3060.c b/src/code_80850_len_3060.c index 29329bac57..f4df47f552 100644 --- a/src/code_80850_len_3060.c +++ b/src/code_80850_len_3060.c @@ -1088,7 +1088,7 @@ s32 is_partner_ability_active(void) { return 0; } -s16 add_coins(s32 amt) { +s32 add_coins(s32 amt) { PlayerData* playerData = &gPlayerData; s16 newCoins = playerData->coins + amt; diff --git a/src/code_8560.c b/src/code_8560.c index 86802d68be..c9df80593e 100644 --- a/src/code_8560.c +++ b/src/code_8560.c @@ -21,8 +21,7 @@ void get_cam_viewport(s32 camID, u16* x, u16* y, u16* width, u16* height) { *y = CAM(camID)->viewportStartY; } -INCLUDE_ASM(void, "code_8560", get_screen_coords, Cam camID, f32 x, f32 y, f32 z, f32* outX, f32* outY, - f32* outZ); +INCLUDE_ASM(void, "code_8560", get_screen_coords, Cam camID, f32 x, f32 y, f32 z, f32* outX, f32* outY, f32* outZ); s32 func_8002E754(s32 camID, s32 x, s32 y) { s32 startX = CAM(camID)->viewportStartX; diff --git a/src/code_d5a50_len_5fd0.c b/src/code_d5a50_len_5fd0.c index 873b2bf4e7..bed8f8ce65 100644 --- a/src/code_d5a50_len_5fd0.c +++ b/src/code_d5a50_len_5fd0.c @@ -29,7 +29,7 @@ INCLUDE_ASM(s32, "code_d5a50_len_5fd0", init_menu_icon_list); INCLUDE_ASM(s32, "code_d5a50_len_5fd0", func_801413F8); -INCLUDE_ASM(s32, "code_d5a50_len_5fd0", create_icon); +INCLUDE_ASM(s32*, "code_d5a50_len_5fd0", create_icon, s32 iconIndex); INCLUDE_ASM(s32, "code_d5a50_len_5fd0", update_menu_icons); @@ -69,7 +69,7 @@ INCLUDE_ASM(s32, "code_d5a50_len_5fd0", get_menu_icon); INCLUDE_ASM(s32, "code_d5a50_len_5fd0", free_icon); -INCLUDE_ASM(s32, "code_d5a50_len_5fd0", set_icon_render_pos); +INCLUDE_ASM(void, "code_d5a50_len_5fd0", set_icon_render_pos, s32 iconIndex, s32 posX, s32 posY); INCLUDE_ASM(s32, "code_d5a50_len_5fd0", get_icon_render_pos); diff --git a/tools/permuter_settings.toml b/tools/permuter_settings.toml index c8037eb2e6..5c636342a2 100644 --- a/tools/permuter_settings.toml +++ b/tools/permuter_settings.toml @@ -1 +1,3 @@ build_system = "ninja" +[preserve_macros] +SCRIPT = "void"