Skip to content

Commit

Permalink
Decompile Various Weapon Functions
Browse files Browse the repository at this point in the history
* `w_006` - `func_ptr_80170008`
* `w_016` - `func_ptr_80170010`
* `w_022` - `EntityWeaponAttack`
  • Loading branch information
hohle committed Aug 5, 2024
1 parent e44d511 commit af03066
Show file tree
Hide file tree
Showing 3 changed files with 130 additions and 3 deletions.
40 changes: 39 additions & 1 deletion src/weapon/w_006.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,45 @@ s32 func_2E000_8017B6A0(Primitive* prim, s32 x, s32 y) {
return 0;
}

INCLUDE_ASM("weapon/nonmatchings/w_006", func_ptr_80170008);
void func_ptr_80170008(Entity* self) {
Primitive* prim;
s32 posX, posY;
s32 range;

if (self->step == 0) {
self->primIndex = g_api.AllocPrimitives(PRIM_GT4, 1);

if (self->primIndex == -1) {
DestroyEntity(self);
return;
}

self->flags = FLAG_UNK_08000000 | FLAG_UNK_800000;
self->velocityY = FIX(1.0 / 2.0);
range = 24;
posX = (rand() % range) - 0xC;
self->posX.i.hi += posX;
posY = (rand() % range) - 0xC;
self->posY.i.hi += posY;

prim = &g_PrimBuf[self->primIndex];
prim->clut = 0x1B0;
prim->tpage = 0x1A;
prim->b0 = 0;
prim->b1 = 0;
prim->priority = self->zPriority + 4;
prim->drawMode = DRAW_TPAGE2 | DRAW_TPAGE | DRAW_TRANSP;

func_2E000_8017B6A0(prim, self->posX.i.hi, self->posY.i.hi);
self->step++;
} else {
self->posY.val += self->velocityY;
prim = &g_PrimBuf[self->primIndex];
if (func_2E000_8017B6A0(prim, self->posX.i.hi, self->posY.i.hi) != 0) {
DestroyEntity(self);
}
}
}

void func_ptr_8017000C(Entity* self) {}

Expand Down
37 changes: 36 additions & 1 deletion src/weapon/w_016.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,42 @@ void func_ptr_8017000C(Entity* self) {
self->rotZ = ratan2(self->velocityY, abs(self->velocityX));
}

INCLUDE_ASM("weapon/nonmatchings/w_016", func_ptr_80170010);
extern AnimationFrame D_74000_8017A5B0[];
extern s32 D_74000_8017BD74;

void func_ptr_80170010(Entity* self) {
Entity* factory;

if (self->step == 0) {
self->animSet = 2;
self->unk4C = D_74000_8017A5B0;
self->zPriority = PLAYER.zPriority - 4;
self->flags = 0x08100000;
self->velocityY = FIX(-1.0);

if (!(D_74000_8017BD74 & 1)) {
factory = g_api.CreateEntFactoryFromEntity(self, 0xB0004U, 0);
if (factory) {
if (g_HandId == 0) {
factory->entityId = 0xEF;
} else {
factory->entityId = 0xFF;
}
}
}
self->posY.i.hi += -6 + (rand() % 12);
self->posX.i.hi += -3 + (rand() & 7);
D_74000_8017BD74 += 1;
if (!(rand() & 1)) {
self->drawMode |= 0x70;
}
self->step += 1;
}
self->posY.val += self->velocityY;
if (self->animFrameDuration < 0) {
DestroyEntity(self);
}
}

// Tracing function calls in emulator indicates that this function manages
// the physics for the Iron Ball item.
Expand Down
56 changes: 55 additions & 1 deletion src/weapon/w_022.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,61 @@
extern AnimationFrame D_9E000_8017A760[];
extern AnimationFrame D_9E000_8017A800[];

INCLUDE_ASM("weapon/nonmatchings/w_022", EntityWeaponAttack);
extern SpriteParts D_9E000_8017A040[];
extern AnimationFrame D_9E000_8017A77C[];

void EntityWeaponAttack(Entity* self) {
s16 deltaX;

switch (self->step) {
case 0:
SetSpriteBank1(D_9E000_8017A040);
self->animSet = ANIMSET_OVL(16);
self->palette = PAL_DRA(0x110);
self->unk5A = 0x64;

if (g_HandId != 0) {
self->animSet += 2;
self->palette += 0x18;
self->unk5A += 2;
}

self->zPriority = PLAYER.zPriority + 2;
self->facingLeft = PLAYER.facingLeft;
self->flags = FLAG_UNK_100000 | FLAG_UNK_40000;
self->unk4C = D_9E000_8017A77C;

deltaX = (self->facingLeft) ? 32 : -32;
self->posY.i.hi -= 6;
self->posX.i.hi += deltaX;

g_api.PlaySfx(0x669);
DestroyEntityWeapon(1);
g_Player.D_80072F00[10] = 4;
self->step++;
break;

case 1:
if (self->animFrameDuration < 0) {
self->ext.timer.t = 16;
self->drawFlags |= DRAW_MENU;
self->step++;
}
if (self->animFrameIdx == 20 && self->animFrameDuration == 2 &&
g_api.CreateEntFactoryFromEntity(
self, ((g_HandId + 1) << 0xC) | 0x38, 0)) {
g_api.PlaySfx(0x625);
}
break;

case 2:
self->ext.timer.t--;
if (self->ext.timer.t == 0) {
DestroyEntity(self);
}
break;
}
}

s32 func_ptr_80170004(Entity* self) {
switch (self->step) {
Expand Down

0 comments on commit af03066

Please sign in to comment.