diff --git a/include/entity.h b/include/entity.h index b12fbd09..93377940 100644 --- a/include/entity.h +++ b/include/entity.h @@ -2,15 +2,18 @@ #define ENTITY_H #include "global.h" +typedef struct { + u8 type; + u8 subtype; + u8 parameter1; + u8 parameter2; +} EntityType; typedef struct { u32 *field_0x0; u32 * field_0x4; - u8 type; - u8 subtype; - u8 parameter1; - u8 parameter2; + EntityType entityType; u8 action; u8 previousActionFlag; u8 parameter3; @@ -79,4 +82,5 @@ typedef struct u8 filler[12]; u32 * field_0x84; } Entity; + #endif \ No newline at end of file diff --git a/include/entityData.h b/include/entityData.h index 10266725..086c489c 100644 --- a/include/entityData.h +++ b/include/entityData.h @@ -3,7 +3,7 @@ #include "global.h" typedef struct { u8 entityType; - u8 unk; + u8 field_0x1; u8 entitySubtype; u8 entityParameter1; u32 entityParameter2; diff --git a/src/createEnemy.c b/src/createEnemy.c index ee49e8fc..41769a78 100644 --- a/src/createEnemy.c +++ b/src/createEnemy.c @@ -10,9 +10,9 @@ Entity * CreateEnemy(u32 subtype, u32 param1) enemy = sub_0805E678(); if (enemy != NULL) { - enemy->type = 3; - enemy->subtype = subtype; - enemy->parameter1 = param1; + (enemy->entityType).type = 3; + (enemy->entityType).subtype = subtype; + (enemy->entityType).parameter1 = param1; sub_0805EA2C(enemy,4); } return enemy; diff --git a/src/createEntity.c b/src/createEntity.c new file mode 100644 index 00000000..589cae11 --- /dev/null +++ b/src/createEntity.c @@ -0,0 +1,51 @@ +#include "entity.h" +#include "entityData.h" +#include "global.h" + +extern Entity * sub_0805EB9C(u32, u32); +extern Entity * sub_0805E768(); +extern void sub_0804AEB0(Entity *, EntityData *); +extern u32 sub_0804AF0C(Entity *, EntityData *); +extern void sub_08016A30(Entity *); +extern u32 gUnk_03000BF0; + +Entity * CreateEntity(EntityData *param_1) +{ + Entity *preexisting; + Entity *entity; + s32 type; + + type = param_1->entityType & 15; + if (((param_1->field_0x1 & 240) == 80) && + (preexisting = sub_0805EB9C(type,param_1->entitySubtype), preexisting != NULL)) { + entity = NULL; + } + else { + entity = sub_0805E768(); //Get empty entity + if (entity != NULL) { + (entity->entityType).type = type; + (entity->entityType).subtype = param_1->entitySubtype; + (entity->entityType).parameter1 = param_1->entityParameter1; + sub_0804AEB0(entity,param_1); + if ((param_1->field_0x1 & 240) != 16) { + (entity->entityType).parameter2 = *(u8 *)¶m_1->entityParameter2; + /* i suspect this is where the entity's behavior is defined. Not sure. */ + entity->parameter3 = (u8)((u32)param_1->entityParameter2 >> 8); + if ((type != 9) && (sub_0804AF0C(entity,param_1), entity->field_0x4 != NULL)) { + if ((param_1->entityType & 16) == 0) { + if ((param_1->entityType & 32) != 0) { + entity->collisionLayer = 2; + return entity; + } + if ((gUnk_03000BF0 & 2) == 0) { + sub_08016A30(entity); + return entity; + } + } + entity->collisionLayer = 1; + } + } + } + } + return entity; +} \ No newline at end of file