papermario/src/17FEB0.c

307 lines
8.9 KiB
C
Raw Normal View History

2020-10-15 05:49:49 +02:00
#include "common.h"
2020-11-18 06:20:28 +01:00
HitResult calc_item_check_hit(void) {
BattleStatus* battleStatus = &gBattleStatus;
ActorMovement* walk = &battleStatus->playerActor->walk;
2020-11-27 20:38:52 +01:00
ActorID actorID = battleStatus->currentTargetID;
2020-11-18 06:20:28 +01:00
s8 currentTargetPartS8;
u32 currentTargetPart;
Actor* actor;
ActorPart* actorPart;
currentTargetPart = currentTargetPartS8 = battleStatus->currentTargetPart;
battleStatus->currentTargetID2 = battleStatus->currentTargetID;
battleStatus->currentTargetPart2 = currentTargetPartS8;
actor = get_actor(actorID);
if (actor != NULL) {
actorPart = get_actor_part(actor, currentTargetPart);
ASSERT(actorPart != NULL);
if (!(actorPart->eventFlags & 0x20)) {
if (actor->transStatus == 0xE) {
2021-03-29 09:34:39 +02:00
return HIT_RESULT_MISS;
2020-11-18 06:20:28 +01:00
}
if (actor->stoneStatus == 0xC) {
sfx_play_sound_at_position(0x10C, 0, walk->goalPos.x, walk->goalPos.y, walk->goalPos.z);
2021-03-29 09:34:39 +02:00
return HIT_RESULT_IMMUNE;
2020-11-18 06:20:28 +01:00
}
if ((battleStatus->currentAttackElement & 0x80) && (actorPart->eventFlags & 0x10)) {
sfx_play_sound_at_position(0xE9, 0, walk->goalPos.x, walk->goalPos.y, walk->goalPos.z);
2021-03-29 09:34:39 +02:00
return HIT_RESULT_LANDED_ON_SPIKE;
2020-11-18 06:20:28 +01:00
}
} else {
2021-03-29 09:34:39 +02:00
return HIT_RESULT_MISS;
2020-11-18 06:20:28 +01:00
}
}
2021-03-29 09:34:39 +02:00
return HIT_RESULT_HIT;
2020-11-18 06:20:28 +01:00
}
2020-10-15 05:49:49 +02:00
Splat refactor (#257) * all non-world rodata migrated * data disasm * kinda working * updated yaml * bloop * linker header * configure 2.0 * bin * mass rename to remove code_ * pause rename * battle partner stuff * whew * more renames * more renames * more renaming * it builds! * updates * remove main prefix * one more thing * crc, yay0 * .data, .rodata, .bss * img * dead_atan2 * it buildsgit add -A * split battle/partner/6FAD10 * rm &s on sleepy_sheep syms * sha1sum ninja rule description * OK but commented out PaperMarioMapFS and PaperMarioNpcSprites * uncomment * fix mapfs * match func_8003CFB4 * . * clean up and name npc_iter_no_op * npc.c * enable cc warnings * name npc_find_near * use singular options.asset_path * smores * cc_dsl only when needed * kinda fix configure for splat refactor2 * ok! * new msg format * remove old msg format docs * slight bug fixes, splat adjustment * git subrepo pull (merge) --force tools/splat subrepo: subdir: "tools/splat" merged: "cfc140bb76" upstream: origin: "https://github.com/ethteck/splat.git" branch: "master" commit: "cfc140bb76" git-subrepo: version: "0.4.3" origin: "https://github.com/ingydotnet/git-subrepo" commit: "2f68596" * git subrepo pull (merge) --force tools/splat subrepo: subdir: "tools/splat" merged: "85349befcd" upstream: origin: "https://github.com/ethteck/splat.git" branch: "master" commit: "85349befcd" git-subrepo: version: "0.4.3" origin: "https://github.com/ingydotnet/git-subrepo" commit: "2f68596" * Update symbol addrs * git subrepo pull tools/splat subrepo: subdir: "tools/splat" merged: "a44631e194" upstream: origin: "https://github.com/ethteck/splat.git" branch: "master" commit: "a44631e194" git-subrepo: version: "0.4.3" origin: "https://github.com/ingydotnet/git-subrepo" commit: "2f68596" Co-authored-by: Alex Bates <hi@imalex.xyz>
2021-04-13 09:47:52 +02:00
INCLUDE_ASM(s32, "17FEB0", calc_item_damage_enemy);
2020-10-15 05:49:49 +02:00
2020-11-18 06:20:28 +01:00
ApiStatus ItemDamageEnemy(ScriptInstance* script, s32 isInitialCall) {
BattleStatus* battleStatus = &gBattleStatus;
2020-11-18 06:20:28 +01:00
Bytecode* args = script->ptrReadPos;
s32 itemDamageOut = *args++;
s32 a5;
Actor* actor;
s32 itemDamage;
s32 flag = 0x10;
battleStatus->currentAttackElement = *args++;
battleStatus->currentAttackEventSuppression = 0;
battleStatus->currentAttackStatus = *args++;
battleStatus->currentAttackDamage = get_variable(script, *args++);
a5 = *args++;
if ((a5 & 0x30) == 0x30) {
battleStatus->flags1 |= 0x30;
} else if (a5 & flag) {
battleStatus->flags1 = (battleStatus->flags1 | flag) & ~0x20;
} else if (a5 & 0x20) {
battleStatus->flags1 = (battleStatus->flags1 & ~flag) | 0x20;
} else {
battleStatus->flags1 = (battleStatus->flags1 & ~flag) & ~0x20;
}
if (a5 & 0x40) {
gBattleStatus.flags1 |= 0x40;
2020-11-18 06:20:28 +01:00
} else {
gBattleStatus.flags1 &= ~0x40;
2020-11-18 06:20:28 +01:00
}
if (a5 & 0x200) {
gBattleStatus.flags1 |= 0x200;
2020-11-18 06:20:28 +01:00
} else {
gBattleStatus.flags1 &= ~0x200;
2020-11-18 06:20:28 +01:00
}
if (a5 & 0x80) {
gBattleStatus.flags1 |= 0x80;
2020-11-18 06:20:28 +01:00
} else {
gBattleStatus.flags1 &= ~0x80;
2020-11-18 06:20:28 +01:00
}
actor = get_actor(script->owner1.actorID);
battleStatus->currentTargetID = actor->targetActorID;
battleStatus->currentTargetPart = actor->targetPartIndex;
battleStatus->statusChance = battleStatus->currentAttackStatus;
if ((battleStatus->statusChance & 0xFF) == 0xFF) {
battleStatus->statusChance = 0;
}
battleStatus->statusDuration = (battleStatus->currentAttackStatus & 0xF00) >> 8;
itemDamage = calc_item_damage_enemy();
if (itemDamage < 0) {
return ApiStatus_FINISH;
}
set_variable(script, itemDamageOut, itemDamage);
if (!does_script_exist_by_ref(script)) {
return ApiStatus_FINISH;
}
return ApiStatus_DONE2;
}
ApiStatus ItemAfflictEnemy(ScriptInstance* script, s32 isInitialCall) {
BattleStatus* battleStatus = &gBattleStatus;
2020-11-18 06:20:28 +01:00
Bytecode* args = script->ptrReadPos;
s32 itemDamageOut = *args++;
s32 a5;
Actor* actor;
s32 itemDamage;
s32 flag = 0x10;
battleStatus->currentAttackElement = *args++;
battleStatus->currentAttackEventSuppression = 0;
battleStatus->currentAttackStatus = *args++;
battleStatus->currentAttackStatus |= get_variable(script, *args++);
battleStatus->currentAttackDamage = get_variable(script, *args++);
a5 = *args++;
if ((a5 & 0x30) == 0x30) {
battleStatus->flags1 |= 0x30;
} else if (a5 & flag) {
battleStatus->flags1 = (battleStatus->flags1 | flag) & ~0x20;
} else if (a5 & 0x20) {
battleStatus->flags1 = (battleStatus->flags1 & ~flag) | 0x20;
} else {
battleStatus->flags1 = (battleStatus->flags1 & ~flag) & ~0x20;
}
if (a5 & 0x40) {
gBattleStatus.flags1 |= 0x40;
2020-11-18 06:20:28 +01:00
} else {
gBattleStatus.flags1 &= ~0x40;
2020-11-18 06:20:28 +01:00
}
if (a5 & 0x200) {
gBattleStatus.flags1 |= 0x200;
2020-11-18 06:20:28 +01:00
} else {
gBattleStatus.flags1 &= ~0x200;
2020-11-18 06:20:28 +01:00
}
if (a5 & 0x80) {
gBattleStatus.flags1 |= 0x80;
2020-11-18 06:20:28 +01:00
} else {
gBattleStatus.flags1 &= ~0x80;
2020-11-18 06:20:28 +01:00
}
actor = get_actor(script->owner1.actorID);
battleStatus->currentTargetID = actor->targetActorID;
battleStatus->currentTargetPart = actor->targetPartIndex;
battleStatus->statusChance = battleStatus->currentAttackStatus;
if ((battleStatus->statusChance & 0xFF) == 0xFF) {
battleStatus->statusChance = 0;
}
battleStatus->statusDuration = (battleStatus->currentAttackStatus & 0xF00) >> 8;
itemDamage = calc_item_damage_enemy();
if (itemDamage < 0) {
return ApiStatus_FINISH;
}
set_variable(script, itemDamageOut, itemDamage);
if (!does_script_exist_by_ref(script)) {
return ApiStatus_FINISH;
}
return ApiStatus_DONE2;
}
ApiStatus func_80252B3C(ScriptInstance* script, s32 isInitialCall) {
BattleStatus* battleStatus = &gBattleStatus;
2020-11-18 06:20:28 +01:00
Bytecode* args = script->ptrReadPos;
s32 itemDamageOut = *args++;
s32 a5;
Actor* actor;
s32 itemDamage;
s32 flag = 0x10;
battleStatus->currentAttackElement = *args++;
battleStatus->currentAttackEventSuppression = 0;
battleStatus->currentAttackStatus = get_variable(script, *args++);
battleStatus->currentAttackDamage = get_variable(script, *args++);
a5 = *args++;
if ((a5 & 0x30) == 0x30) {
battleStatus->flags1 |= 0x30;
} else if (a5 & flag) {
battleStatus->flags1 = (battleStatus->flags1 | flag) & ~0x20;
} else if (a5 & 0x20) {
battleStatus->flags1 = (battleStatus->flags1 & ~flag) | 0x20;
} else {
battleStatus->flags1 = (battleStatus->flags1 & ~flag) & ~0x20;
}
if (a5 & 0x40) {
gBattleStatus.flags1 |= 0x40;
2020-11-18 06:20:28 +01:00
} else {
gBattleStatus.flags1 &= ~0x40;
2020-11-18 06:20:28 +01:00
}
if (a5 & 0x200) {
gBattleStatus.flags1 |= 0x200;
2020-11-18 06:20:28 +01:00
} else {
gBattleStatus.flags1 &= ~0x200;
2020-11-18 06:20:28 +01:00
}
if (a5 & 0x80) {
gBattleStatus.flags1 |= 0x80;
2020-11-18 06:20:28 +01:00
} else {
gBattleStatus.flags1 &= ~0x80;
2020-11-18 06:20:28 +01:00
}
actor = get_actor(script->owner1.actorID);
battleStatus->currentTargetID = actor->targetActorID;
battleStatus->currentTargetPart = actor->targetPartIndex;
battleStatus->statusChance = battleStatus->currentAttackStatus;
if ((battleStatus->statusChance & 0xFF) == 0xFF) {
battleStatus->statusChance = 0;
}
battleStatus->statusDuration = (battleStatus->currentAttackStatus & 0xF00) >> 8;
itemDamage = calc_item_damage_enemy();
if (itemDamage < 0) {
return ApiStatus_FINISH;
}
set_variable(script, itemDamageOut, itemDamage);
if (!does_script_exist_by_ref(script)) {
return ApiStatus_FINISH;
}
return ApiStatus_DONE2;
}
ApiStatus ItemCheckHit(ScriptInstance* script, s32 isInitialCall) {
BattleStatus* battleStatus = &gBattleStatus;
2020-11-18 06:20:28 +01:00
Bytecode* args = script->ptrReadPos;
s32 itemDamageOut = *args++;
s32 a5;
Actor* actor;
s32 itemDamage;
s32 flag = 0x10;
battleStatus->currentAttackElement = *args++;
battleStatus->currentAttackEventSuppression = 0;
battleStatus->currentAttackStatus = *args++;
battleStatus->currentAttackDamage = get_variable(script, *args++);
a5 = *args++;
if ((a5 & 0x30) == 0x30) {
battleStatus->flags1 |= 0x30;
} else if (a5 & flag) {
battleStatus->flags1 = (battleStatus->flags1 | flag) & ~0x20;
} else if (a5 & 0x20) {
battleStatus->flags1 = (battleStatus->flags1 & ~flag) | 0x20;
} else {
battleStatus->flags1 = (battleStatus->flags1 & ~flag) & ~0x20;
}
if (a5 & 0x40) {
gBattleStatus.flags1 |= 0x40;
2020-11-18 06:20:28 +01:00
} else {
gBattleStatus.flags1 &= ~0x40;
2020-11-18 06:20:28 +01:00
}
if (a5 & 0x200) {
gBattleStatus.flags1 |= 0x200;
2020-11-18 06:20:28 +01:00
} else {
gBattleStatus.flags1 &= ~0x200;
2020-11-18 06:20:28 +01:00
}
if (a5 & 0x80) {
gBattleStatus.flags1 |= 0x80;
2020-11-18 06:20:28 +01:00
} else {
gBattleStatus.flags1 &= ~0x80;
2020-11-18 06:20:28 +01:00
}
actor = get_actor(script->owner1.actorID);
battleStatus->currentTargetID = actor->targetActorID;
battleStatus->currentTargetPart = actor->targetPartIndex;
battleStatus->statusChance = battleStatus->currentAttackStatus;
if ((battleStatus->statusChance & 0xFF) == 0xFF) {
battleStatus->statusChance = 0;
}
battleStatus->statusDuration = (battleStatus->currentAttackStatus & 0xF00) >> 8;
2020-10-15 05:49:49 +02:00
2020-11-18 06:20:28 +01:00
itemDamage = calc_item_check_hit();
if (itemDamage < 0) {
return ApiStatus_FINISH;
}
2020-10-15 05:49:49 +02:00
2020-11-18 06:20:28 +01:00
set_variable(script, itemDamageOut, itemDamage);
2020-10-15 05:49:49 +02:00
2020-11-18 06:20:28 +01:00
return ApiStatus_DONE2;
}