Use new Entity style

This commit is contained in:
Tal Hayon 2021-12-30 13:38:55 +02:00
parent 87514fcbf7
commit a139e43d93
1 changed files with 169 additions and 156 deletions

View File

@ -1,21 +1,34 @@
#define NENT_DEPRECATED
#include "global.h" #include "global.h"
#include "entity.h" #include "entity.h"
#include "enemy.h" #include "enemy.h"
#include "functions.h" #include "functions.h"
extern void sub_0803C5F0(Entity*); typedef struct {
extern void sub_0803C690(Entity*); Entity base;
extern void sub_0803C4B0(Entity*); u8 filler[0x12];
extern void sub_0803C5C4(Entity*); u8 unk_0x7a;
extern void sub_0803C624(Entity*); u8 unk_0x7b;
extern void sub_0803C6DC(Entity*); u8 filter[0x4];
extern void sub_0803C714(Entity*); u8 unk_0x80;
extern void sub_0803C634(Entity*); u8 unk_0x81;
extern u32 sub_0803C6F8(Entity*); u8 unk_0x82;
extern u32 sub_0803C568(Entity*); u8 unk_0x83;
} BowMoblinEntity;
void sub_0803C5F0(BowMoblinEntity*);
void sub_0803C690(BowMoblinEntity*);
void sub_0803C4B0(BowMoblinEntity*);
void sub_0803C5C4(BowMoblinEntity*);
void sub_0803C624(BowMoblinEntity*);
void sub_0803C6DC(BowMoblinEntity*);
void sub_0803C714(BowMoblinEntity*);
void sub_0803C634(BowMoblinEntity*);
u32 sub_0803C6F8(BowMoblinEntity*);
u32 sub_0803C568(BowMoblinEntity*);
extern Entity* sub_08049DF4(u32); extern Entity* sub_08049DF4(u32);
extern u32 sub_0806FC80(Entity*, Entity*, s32); extern u32 sub_0806FC80(Entity*, Entity*, s32);
extern void sub_0803C664(Entity*); void sub_0803C664(BowMoblinEntity*);
extern void (*const gUnk_080CFF78[])(Entity*); extern void (*const gUnk_080CFF78[])(Entity*);
extern void (*const gUnk_080CFF90[])(Entity*); extern void (*const gUnk_080CFF90[])(Entity*);
@ -30,73 +43,73 @@ void BowMoblin(Entity* this) {
SetChildOffset(this, 0, 1, -0x18); SetChildOffset(this, 0, 1, -0x18);
} }
void sub_0803C180(Entity* this) { void sub_0803C180(BowMoblinEntity* this) {
gUnk_080CFF90[this->action](this); gUnk_080CFF90[super->action](super);
} }
void sub_0803C198(Entity* this) { void sub_0803C198(BowMoblinEntity* this) {
Entity* pEVar1; Entity* pEVar1;
if (this->field_0x43 != 0) { if (super->field_0x43 != 0) {
sub_0804A9FC(this, 0x1c); sub_0804A9FC(super, 0x1c);
} }
sub_0804AA30(this, gUnk_080CFF78); sub_0804AA30(super, gUnk_080CFF78);
if ((this->bitfield & 0x80) != 0) { if ((super->bitfield & 0x80) != 0) {
sub_0803C5F0(this); sub_0803C5F0(this);
pEVar1 = this->child; pEVar1 = super->child;
if (pEVar1 != NULL) { if (pEVar1 != NULL) {
pEVar1->field_0xf++; pEVar1->field_0xf++;
} }
} }
} }
void nullsub_168(Entity* this) { void nullsub_168(BowMoblinEntity* this) {
} }
void sub_0803C1E0(Entity* this) { void sub_0803C1E0(BowMoblinEntity* this) {
sub_0804A720(this); sub_0804A720(super);
this->action = 1; super->action = 1;
this->field_0x7a.HALF.HI = 0; this->unk_0x7b = 0;
this->field_0x80.HALF.LO = 0; this->unk_0x80 = 0;
this->field_0x82.HALF.HI = 0; this->unk_0x83 = 0;
this->field_0x80.HALF.HI = 0; this->unk_0x81 = 0;
this->field_0x7a.HALF.LO = 0; this->unk_0x7a = 0;
this->field_0x82.HALF.LO = 1; this->unk_0x82 = 1;
if (this->actionDelay) { if (super->actionDelay) {
this->animationState = this->type2 << 1; super->animationState = super->type2 << 1;
this->actionDelay = 0x1e; super->actionDelay = 0x1e;
this->speed = 0x80; super->speed = 0x80;
this->direction = this->type2 << 3; super->direction = super->type2 << 3;
sub_0803C690(this); sub_0803C690(this);
} else { } else {
this->animationState = 0x10; super->animationState = 0x10;
sub_0803C4B0(this); sub_0803C4B0(this);
} }
} }
void sub_0803C234(Entity* this) { void sub_0803C234(BowMoblinEntity* this) {
u8 mask; u8 mask;
if (this->field_0x80.HALF.HI) { if (this->unk_0x81) {
this->field_0x80.HALF.HI--; this->unk_0x81--;
} }
mask = 0xff; mask = 0xff;
if (((--this->actionDelay) & mask) == 0) { if (((--super->actionDelay) & mask) == 0) {
u8 tmp = ++this->field_0x80.HALF.LO; u8 tmp = ++this->unk_0x80;
if ((tmp) > 0xf) { if ((tmp) > 0xf) {
sub_0803C5C4(this); sub_0803C5C4(this);
} else if (((this->field_0x80.HALF.LO & 0x3) == 0) && (Random() & 0x10)) { } else if (((this->unk_0x80 & 0x3) == 0) && (Random() & 0x10)) {
sub_0803C624(this); sub_0803C624(this);
} else { } else {
sub_0803C4B0(this); sub_0803C4B0(this);
} }
} else if (sub_0803C6F8(this)) { } else if (sub_0803C6F8(this)) {
sub_0800417E(this, this->collisions); sub_0800417E(super, super->collisions);
this->animationState = ((this->direction + 4) & 0x18) >> 2; super->animationState = ((super->direction + 4) & 0x18) >> 2;
this->field_0x82.HALF.HI++; this->unk_0x83++;
sub_0803C690(this); sub_0803C690(this);
} else if (sub_0803C568(this)) { } else if (sub_0803C568(this)) {
sub_0803C5F0(this); sub_0803C5F0(this);
@ -105,86 +118,86 @@ void sub_0803C234(Entity* this) {
sub_0803C6DC(this); sub_0803C6DC(this);
} }
void sub_0803C2DC(Entity* this) { void sub_0803C2DC(BowMoblinEntity* this) {
u32 res; u32 res;
u32 actionDelay = --this->actionDelay; u32 actionDelay = --super->actionDelay;
if (actionDelay == 0) { if (actionDelay == 0) {
this->action = 3; super->action = 3;
this->field_0x82.HALF.LO = actionDelay; this->unk_0x82 = actionDelay;
this->field_0x80.HALF.LO = actionDelay; this->unk_0x80 = actionDelay;
this->animationState = 0x10; super->animationState = 0x10;
sub_0803C4B0(this); sub_0803C4B0(this);
} else if (res = sub_0803C568(this), res) { } else if (res = sub_0803C568(this), res) {
this->field_0x7a.HALF.HI |= 0x1; this->unk_0x7b |= 0x1;
} }
if (this->field_0xf > 0xb) { if (super->field_0xf > 0xb) {
if (this->field_0x7a.HALF.HI != 0) { if (this->unk_0x7b != 0) {
sub_0803C5F0(this); sub_0803C5F0(this);
} }
} else { } else {
this->field_0xf++; super->field_0xf++;
} }
sub_0803C6DC(this); sub_0803C6DC(this);
} }
void sub_0803C344(Entity* this) { void sub_0803C344(BowMoblinEntity* this) {
if (--this->actionDelay == 0) { if (--super->actionDelay == 0) {
switch (this->field_0x82.HALF.LO) { switch (this->unk_0x82) {
case 3: { case 3: {
this->action = 4; super->action = 4;
this->speed = 0x80; super->speed = 0x80;
this->direction = sub_08049F84(this, 1); super->direction = sub_08049F84(super, 1);
break; break;
} }
case 5: { case 5: {
this->action = 4; super->action = 4;
this->speed = 0x80; super->speed = 0x80;
break; break;
} }
case 2: { case 2: {
u32 tmp; u32 tmp;
this->action = 2; super->action = 2;
this->speed = 0; super->speed = 0;
tmp = Random() & 0x7; tmp = Random() & 0x7;
this->actionDelay = (tmp << 1) + tmp + 0x40; super->actionDelay = (tmp << 1) + tmp + 0x40;
break; break;
} }
case 4: { case 4: {
this->direction = (this->direction + 0x10) & 0x18; super->direction = (super->direction + 0x10) & 0x18;
} }
case 0: case 0:
case 1: case 1:
default: { default: {
u32 tmp; u32 tmp;
this->action = 1; super->action = 1;
this->field_0x82.HALF.LO = 1; this->unk_0x82 = 1;
this->speed = 0x80; super->speed = 0x80;
tmp = (Random() & 0x7); tmp = (Random() & 0x7);
this->actionDelay = (tmp << 1) + tmp + 0x22; super->actionDelay = (tmp << 1) + tmp + 0x22;
break; break;
} }
} }
this->field_0xf = 0; super->field_0xf = 0;
this->animationState = ((this->direction + 4) & 0x18) >> 2; super->animationState = ((super->direction + 4) & 0x18) >> 2;
sub_0803C690(this); sub_0803C690(this);
} }
sub_0803C6DC(this); sub_0803C6DC(this);
} }
void sub_0803C400(Entity* this) { void sub_0803C400(BowMoblinEntity* this) {
if (this->field_0xf) { if (super->field_0xf) {
u8 mask; u8 mask;
this->field_0xf--; super->field_0xf--;
mask = 0xff; mask = 0xff;
if ((this->field_0xf & mask) == 0) { if ((super->field_0xf & mask) == 0) {
if (this->field_0x82.HALF.LO == 3) { if (this->unk_0x82 == 3) {
this->field_0x7a.HALF.LO++; this->unk_0x7a++;
if ((this->field_0x7a.HALF.LO & mask) <= 2) { if ((this->unk_0x7a & mask) <= 2) {
if (Random() & 0xc0) { if (Random() & 0xc0) {
this->actionDelay = 0; super->actionDelay = 0;
sub_0803C690(this); sub_0803C690(this);
sub_0803C6DC(this); sub_0803C6DC(this);
return; return;
@ -195,75 +208,75 @@ void sub_0803C400(Entity* this) {
} }
} else { } else {
Entity* projectile; Entity* projectile;
switch (++this->actionDelay) { switch (++super->actionDelay) {
case 1: case 1:
this->direction = this->animationState << 2; super->direction = super->animationState << 2;
projectile = CreateProjectileWithParent(this, 0xd, this->animationState >> 1); projectile = CreateProjectileWithParent(super, 0xd, super->animationState >> 1);
if (projectile) { if (projectile) {
this->child = projectile; super->child = projectile;
projectile->direction = (this->direction + 4) & 0x18; projectile->direction = (super->direction + 4) & 0x18;
projectile->parent = this; projectile->parent = super;
} }
break; break;
case 24: case 24:
this->actionDelay = 0; super->actionDelay = 0;
this->field_0xf = 0x20; super->field_0xf = 0x20;
break; break;
} }
sub_0803C6DC(this); sub_0803C6DC(this);
if (this->child) { if (super->child) {
sub_0803C714(this); sub_0803C714(this);
} }
} }
} }
void sub_0803C4B0(Entity* this) { void sub_0803C4B0(BowMoblinEntity* this) {
u32 dir; u32 dir;
this->field_0xf = 0; super->field_0xf = 0;
if (this->field_0x82.HALF.LO == 1) { if (this->unk_0x82 == 1) {
this->actionDelay = gUnk_080CFFA4[Random() & 7]; super->actionDelay = gUnk_080CFFA4[Random() & 7];
this->speed = 0x80; super->speed = 0x80;
if (sub_08049FA0(this)) { if (sub_08049FA0(super)) {
dir = Random(); dir = Random();
dir &= 6; dir &= 6;
this->direction = dir << 2; super->direction = dir << 2;
} else { } else {
dir = sub_08049EE4(this); dir = sub_08049EE4(super);
if (this->field_0x82.HALF.HI == 0) { if (this->unk_0x83 == 0) {
dir += gUnk_080CFFAC[Random() & 0xf]; dir += gUnk_080CFFAC[Random() & 0xf];
} else { } else {
dir += gUnk_080CFFAC[Random() & 0x7]; dir += gUnk_080CFFAC[Random() & 0x7];
this->actionDelay += 0x10; super->actionDelay += 0x10;
this->field_0x82.HALF.HI--; this->unk_0x83--;
} }
dir = (this->direction = (dir + 4) & 0x18) >> 2; dir = (super->direction = (dir + 4) & 0x18) >> 2;
} }
} else { } else {
this->actionDelay = 0xc; super->actionDelay = 0xc;
this->speed = this->field_0xf; super->speed = super->field_0xf;
dir = this->direction >> 2; dir = super->direction >> 2;
} }
if (dir != this->animationState) { if (dir != super->animationState) {
this->animationState = dir; super->animationState = dir;
sub_0803C690(this); sub_0803C690(this);
} }
} }
u32 sub_0803C568(Entity* this) { u32 sub_0803C568(BowMoblinEntity* this) {
if (this->field_0x80.HALF.HI == 0) { if (this->unk_0x81 == 0) {
Entity* ent = sub_08049DF4(1); Entity* ent = sub_08049DF4(1);
if (ent) { if (ent) {
if (this->field_0x82.HALF.LO == 2) { if (this->unk_0x82 == 2) {
if (sub_0806FC80(this, ent, 0x30)) { if (sub_0806FC80(super, ent, 0x30)) {
return 1; return 1;
} }
} }
if (sub_0806FC80(this, ent, 0x40)) { if (sub_0806FC80(super, ent, 0x40)) {
u32 direction = (GetFacingDirection(this, ent) + 4) & 0x18; u32 direction = (GetFacingDirection(super, ent) + 4) & 0x18;
direction = direction >> 2; direction = direction >> 2;
if (direction == this->animationState) { if (direction == super->animationState) {
return 1; return 1;
} }
} }
@ -273,52 +286,52 @@ u32 sub_0803C568(Entity* this) {
return 0; return 0;
} }
void sub_0803C5C4(Entity* this) { void sub_0803C5C4(BowMoblinEntity* this) {
u32 state = ((this->direction + 4) & 0x18) >> 2; u32 state = ((super->direction + 4) & 0x18) >> 2;
this->animationState = state; super->animationState = state;
this->direction = state << 2; super->direction = state << 2;
this->field_0x82.HALF.HI >>= 1; this->unk_0x83 >>= 1;
sub_0803C664(this); sub_0803C664(this);
this->field_0x82.HALF.LO = 2; this->unk_0x82 = 2;
} }
void sub_0803C5F0(Entity* this) { void sub_0803C5F0(BowMoblinEntity* this) {
this->direction = sub_08049F84(this, 1); super->direction = sub_08049F84(super, 1);
this->animationState = ((this->direction + 4) & 0x18) >> 2; super->animationState = ((super->direction + 4) & 0x18) >> 2;
this->field_0x82.HALF.HI = 0; this->unk_0x83 = 0;
this->field_0x7a.HALF.LO = 0; this->unk_0x7a = 0;
sub_0803C664(this); sub_0803C664(this);
this->field_0x82.HALF.LO = 3; this->unk_0x82 = 3;
} }
void sub_0803C624(Entity* this) { void sub_0803C624(BowMoblinEntity* this) {
sub_0803C664(this); sub_0803C664(this);
this->field_0x82.HALF.LO = 5; this->unk_0x82 = 5;
} }
void sub_0803C634(Entity* this) { void sub_0803C634(BowMoblinEntity* this) {
this->animationState = ((this->direction + 4) & 0x18) >> 2; super->animationState = ((super->direction + 4) & 0x18) >> 2;
this->direction = this->animationState << 2; super->direction = super->animationState << 2;
this->field_0x82.HALF.HI = 0; this->unk_0x83 = 0;
sub_0803C664(this); sub_0803C664(this);
this->actionDelay <<= 1; super->actionDelay <<= 1;
this->field_0x82.HALF.LO = 4; this->unk_0x82 = 4;
} }
void sub_0803C664(Entity* this) { void sub_0803C664(BowMoblinEntity* this) {
this->action = 3; super->action = 3;
this->actionDelay = 0x20; super->actionDelay = 0x20;
this->field_0xf = 0; super->field_0xf = 0;
this->field_0x80.HALF.LO = 0; this->unk_0x80 = 0;
this->field_0x7a.HALF.HI = 0; this->unk_0x7b = 0;
this->speed = 0; super->speed = 0;
this->field_0x82.HALF.LO = 0; this->unk_0x82 = 0;
sub_0803C690(this); sub_0803C690(this);
} }
void sub_0803C690(Entity* this) { void sub_0803C690(BowMoblinEntity* this) {
u32 tmp = this->animationState >> 1; u32 tmp = super->animationState >> 1;
switch (this->field_0x82.HALF.LO) { switch (this->unk_0x82) {
case 1: case 1:
case 4: { case 4: {
tmp += 0x4; tmp += 0x4;
@ -338,34 +351,34 @@ void sub_0803C690(Entity* this) {
} }
} }
InitializeAnimation(this, tmp); InitializeAnimation(super, tmp);
} }
void sub_0803C6DC(Entity* this) { void sub_0803C6DC(BowMoblinEntity* this) {
u8 tmp = this->field_0x82.HALF.LO; u8 tmp = this->unk_0x82;
if (tmp == 0) { if (tmp == 0) {
this->speed = tmp; super->speed = tmp;
} }
ProcessMovement(this); ProcessMovement(super);
GetNextFrame(this); GetNextFrame(super);
} }
u32 sub_0803C6F8(Entity* this) { u32 sub_0803C6F8(BowMoblinEntity* this) {
u32 tmp = (this->collisions & gUnk_080CFFBC[(this->animationState ^ 1) / 2]); u32 tmp = (super->collisions & gUnk_080CFFBC[(super->animationState ^ 1) / 2]);
u32 tmp2 = -tmp; u32 tmp2 = -tmp;
return (tmp2 | tmp) >> 0x1f; return (tmp2 | tmp) >> 0x1f;
} }
void sub_0803C714(Entity* this) { void sub_0803C714(BowMoblinEntity* this) {
Entity* child = this->child; // Unused Entity* child = super->child; // Unused
const s8* tmp; const s8* tmp;
u32 offsetX; u32 offsetX;
u32 offsetY; u32 offsetY;
tmp = &gUnk_080CFFC4[this->animationState]; tmp = &gUnk_080CFFC4[super->animationState];
// TODO fix array access // TODO fix array access
offsetX = tmp[0] << 0x10; offsetX = tmp[0] << 0x10;
offsetY = tmp[1] << 0x10; offsetY = tmp[1] << 0x10;
PositionRelative(this, child, offsetX, offsetY); PositionRelative(super, child, offsetX, offsetY);
} }