Skip to content

Commit

Permalink
Decompile EntityWeaponAttack_w_043 (#1525)
Browse files Browse the repository at this point in the history
  • Loading branch information
joshlory authored Aug 16, 2024
1 parent b3ef37a commit 4d081bc
Showing 1 changed file with 131 additions and 1 deletion.
132 changes: 131 additions & 1 deletion src/weapon/w_043.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,138 @@ extern s32 g_HandId;
#define g_Animset2 w_043_2

extern AnimationFrame D_131000_8017AF40[];
extern SpriteParts D_131000_8017A040[];
extern WeaponAnimation D_131000_8017B014[];

INCLUDE_ASM("weapon/nonmatchings/w_043", EntityWeaponAttack);
void EntityWeaponAttack(Entity* self) {
s8 animIndex = (self->params & 0x7FFF) >> 8;
WeaponAnimation* anim = &D_131000_8017B014[animIndex];
Primitive* prim;
s16 offsetX, offsetY;
bool flag;
s16 baseX, baseY, modifierY;

self->posX.val = PLAYER.posX.val;
self->posY.val = PLAYER.posY.val;
self->facingLeft = PLAYER.facingLeft;

if ((PLAYER.ext.player.anim < anim->frameStart) ||
(PLAYER.ext.player.anim >= anim->frameStart + 7) ||
g_Player.unk46 == 0) {
DestroyEntity(self);
return;
}

flag = 0;
if (self->step == 0) {
self->primIndex = g_api.AllocPrimitives(PRIM_TILE, 16);
if (self->primIndex != -1) {
prim = &g_PrimBuf[self->primIndex];
while (prim != NULL) {
prim->v0 = 2;
prim->u0 = 2;
if (animIndex == 2) {
prim->b0 = 0x20;
prim->g0 = 0x7F;
prim->r0 = 0;
} else {
prim->g0 = 0x20;
prim->b0 = 0xFF;
prim->r0 = 0x20;
}
prim->priority = PLAYER.zPriority + 2;
prim->drawMode = DRAW_UNK_200 | DRAW_TPAGE2 | DRAW_TPAGE |
DRAW_HIDE | DRAW_TRANSP;
prim = prim->next;
}
}
SetSpriteBank1(D_131000_8017A040);
self->animSet = ANIMSET_OVL(0x10);
self->palette = 0x110;
self->unk5A = 0x64;
if (g_HandId) {
self->animSet += 2;
self->palette += 0x18;
self->unk5A += 2;
}
self->palette += anim->palette;
self->flags = FLAG_UNK_40000 | FLAG_UNK_20000;
if (self->primIndex != -1) {
self->flags = FLAG_UNK_800000 | FLAG_UNK_40000 | FLAG_UNK_20000;
}
self->zPriority = PLAYER.zPriority - 2;
self->drawMode = DRAW_TPAGE2 | DRAW_TPAGE;
SetWeaponProperties(self, 0);
self->step++;
}
self->ext.weapon.anim = PLAYER.ext.player.anim - anim->frameStart;
if (PLAYER.animFrameDuration == 1 &&
PLAYER.animFrameIdx == anim->soundFrame) {
g_api.PlaySfx(anim->soundId);
}
if (g_api.UpdateUnarmedAnim(anim->frameProps, anim->frames) < 0) {
DestroyEntity(self);
return;
}
if (PLAYER.animFrameDuration == 1 && PLAYER.animFrameIdx == 3) {
flag = 1;
}
self->drawFlags = PLAYER.drawFlags;
self->rotY = PLAYER.rotY;
self->rotPivotY = PLAYER.rotPivotY;

modifierY = 0;
if (PLAYER.drawFlags & FLAG_DRAW_ROTY) {
modifierY = -3;
if (PLAYER.ext.player.anim >= 0x43 && PLAYER.ext.player.anim < 0x45) {
modifierY = -1;
}
}

if (self->primIndex != -1) {
prim = &g_PrimBuf[self->primIndex];
while (prim != NULL) {
if (prim->r1 == 0) {
if (flag) {
baseX = self->hitboxOffX;
baseY = self->hitboxOffY;
if (self->facingLeft) {
baseX = -baseX;
}
offsetX = self->posX.i.hi + baseX;
offsetY = self->posY.i.hi + baseY + modifierY;

prim->x0 = offsetX + (rand() % 48) - 24;
prim->y0 = offsetY + (rand() & 7);

prim->r1++;
prim->g1 = 9;
prim->b1 = rand() & 3;
}
} else if (prim->b1) {
prim->b1--;
} else if (prim->g1) {
prim->g1--;
if (prim->g1 < 3) {
prim->v0 = 1;
prim->u0 = 1;
}
prim->drawMode &= ~DRAW_HIDE;
if (prim->g1 & 1) {
prim->y0 = prim->y0 - 1;
}
if (self->facingLeft) {
prim->x0 = prim->x0 + 2;
} else {
prim->x0 = prim->x0 - 2;
}
} else {
prim->drawMode |= DRAW_HIDE;
}
prim = prim->next;
}
}
}

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

0 comments on commit 4d081bc

Please sign in to comment.