summaryrefslogtreecommitdiff
path: root/src/manager/delayedEntityLoadManager.c
diff options
context:
space:
mode:
authorTal Hayon <talhayon1@gmail.com>2022-08-01 21:25:04 +0300
committerTal Hayon <talhayon1@gmail.com>2022-08-01 21:25:04 +0300
commitb20c9cb98c33feef7ec6c82c9231987ed238615e (patch)
treea4164c44014afe852a4f46fadaa9219e25392453 /src/manager/delayedEntityLoadManager.c
parent76634df376948b03825fbdcf770ce8351dbe3bd0 (diff)
Match DelayedEntityLoadManager_Main
Diffstat (limited to 'src/manager/delayedEntityLoadManager.c')
-rw-r--r--src/manager/delayedEntityLoadManager.c74
1 files changed, 72 insertions, 2 deletions
diff --git a/src/manager/delayedEntityLoadManager.c b/src/manager/delayedEntityLoadManager.c
index a878d70e..f113330a 100644
--- a/src/manager/delayedEntityLoadManager.c
+++ b/src/manager/delayedEntityLoadManager.c
@@ -6,9 +6,79 @@
*/
#include "manager/delayedEntityLoadManager.h"
#include "room.h"
+#include "npc.h"
+#include "area.h"
+#include "asm.h"
-ASM_FUNC("asm/non_matching/delayedEntityLoadManager/DelayedEntityLoadManager_Main.inc",
- void DelayedEntityLoadManager_Main())
+typedef struct {
+ Manager base;
+ u8 unk_20;
+ u8 spawnedCount; /**< Count of entities spawned by this manager */
+} DelayedEntityLoadManager;
+
+extern u8 gUnk_020342F8[];
+
+void DelayedEntityLoadManager_Main(DelayedEntityLoadManager* this) {
+ NPCStruct* properties;
+ NPCStruct* npcPtr;
+ NPCStruct* npcPtr2;
+ Entity* entity;
+ u32 index1;
+ u32 index2;
+ u32 tmp;
+ u32 progressMask;
+ u8* bitfield;
+ ScriptExecutionContext* context;
+
+ properties = GetCurrentRoomProperty(super->type);
+ if (properties == NULL) {
+ DeleteThisEntity();
+ }
+ if (super->action == 0) {
+ super->action++;
+ this->unk_20 = gArea.filler[2];
+ SetDefaultPriority((Entity*)this, 6);
+ npcPtr = gNPCData;
+ npcPtr += (super->type2 + this->unk_20);
+ index1 = 0;
+ while (properties->id != 0xff) {
+ *npcPtr = *properties;
+ index1++;
+ properties++;
+ npcPtr++;
+ }
+ npcPtr->id = 0xff;
+ this->spawnedCount = index1;
+ }
+ npcPtr2 = gNPCData;
+ npcPtr2 = &npcPtr2[(super->type2 + this->unk_20)];
+ progressMask = 1 << gSave.global_progress;
+ bitfield = &gUnk_020342F8[(this->unk_20 + 7) / 8];
+ index2 = super->type2;
+ while (npcPtr2->id != 0xff) {
+ if (!CheckRectOnScreen(npcPtr2->x, npcPtr2->y, 0x18, 0x20)) {
+ ClearBit(bitfield, index2);
+ } else if ((npcPtr2->progressBitfield & progressMask) && gEntCount < 0x47 && !WriteBit(bitfield, index2) &&
+ (npcPtr2->script == NULL || (context = CreateScriptExecutionContext(), context != NULL))) {
+ if (super->timer == 0) {
+ entity = CreateNPC(npcPtr2->id, npcPtr2->type, npcPtr2->type2);
+ } else {
+ entity = CreateObject(npcPtr2->id, npcPtr2->type, npcPtr2->type2);
+ }
+ tmp = this->unk_20 + 1;
+ entity->health = index2 + tmp;
+ entity->timer = npcPtr2->timer;
+ entity->x.HALF.HI = npcPtr2->x + gRoomControls.origin_x;
+ entity->y.HALF.HI = npcPtr2->y + gRoomControls.origin_y;
+ entity->collisionLayer = npcPtr2->collisionLayer;
+ if (npcPtr2->script != NULL) {
+ InitScriptForEntity(entity, context, npcPtr2->script);
+ }
+ }
+ npcPtr2++;
+ index2++;
+ }
+}
u32 sub_0805ACC0(Entity* param_1) {
u16* ptr;