From d29c7c377e2808686d915992ef149a8652009e98 Mon Sep 17 00:00:00 2001 From: Aetias Date: Thu, 29 May 2025 12:24:19 +0200 Subject: `ActorSpawner` 99% --- src/00_Core/Actor/ActorSpawner.cpp | 104 ++++++++++++++++++++++++++++++++++--- 1 file changed, 96 insertions(+), 8 deletions(-) (limited to 'src/00_Core/Actor/ActorSpawner.cpp') diff --git a/src/00_Core/Actor/ActorSpawner.cpp b/src/00_Core/Actor/ActorSpawner.cpp index 76b4ae74..c23babf2 100644 --- a/src/00_Core/Actor/ActorSpawner.cpp +++ b/src/00_Core/Actor/ActorSpawner.cpp @@ -1,10 +1,98 @@ #include "Actor/ActorSpawner.hpp" +#include "Actor/ActorManager.hpp" +#include "Map/MapManager.hpp" -ActorSpawner *ActorSpawner::Create() {} -void ActorSpawner::Destroy() {} -ActorSpawner::ActorSpawner() {} -ActorSpawner::~ActorSpawner() {} -void ActorSpawner::func_ov000_020c4014() {} -void ActorSpawner::func_ov000_020c4018() {} -Actor *ActorSpawner::CreateActor(ActorTypeId type) {} -s32 ActorSpawner::Spawn(ActorTypeId type, Vec3p *pos, void *param3, ActorRef *ref) {} +extern u32 *data_027e0ce0[]; +ARM ActorSpawner *ActorSpawner::Create() { + gActorSpawner = new(data_027e0ce0[1], 4) ActorSpawner(); +} + +ARM void ActorSpawner::Destroy() { + delete gActorSpawner; + gActorSpawner = NULL; +} + +ARM ActorSpawner::ActorSpawner() {} + +ARM ActorSpawner::~ActorSpawner() {} + +ARM void ActorSpawner::func_ov000_020c4014() {} + +ARM void ActorSpawner::func_ov000_020c4018() {} + +ARM Actor *ActorSpawner::CreateActor(ActorTypeId typeId) { + Actor *actor = NULL; + ActorType *type = ActorType::Find(typeId); + if (type != NULL) { + actor = type->create(); + } + return actor; +} + +extern "C" unk32 GetCardinal(s16 angle); +ARM s32 ActorSpawner::Spawn(ActorTypeId type, Vec3p *pos, ActorSpawnOptions *options, ActorRef *ref) { + ActorManager *actorManager = gActorManager; + u16 maxActors = actorManager->mMaxActors; + Actor **actorSlot = actorManager->mActorTable; + ActorRef actorRef; + actorRef.id = -1; + for (actorRef.index = 0; actorRef.index < maxActors; actorRef.index++, actorSlot++) { + if (*actorSlot != NULL) { + continue; + } + + Actor *actor = this->CreateActor(type); + *actorSlot = actor; + if (actor == NULL) { + if (ref != NULL) { + ref->Reset(); + } + return -1; + } + actor->mType = type; + (*actorSlot)->mRef.id = actorManager->mNextActorId; + (*actorSlot)->mRef.index = actorRef.index; + (*actorSlot)->mUnk_014 = *pos; + (*actorSlot)->mUnk_020 = options->mUnk_00; + (*actorSlot)->mAngle = options->mAngle; + (*actorSlot)->mUnk_012 = options->mAngle; + (*actorSlot)->mUnk_074 = GetCardinal(options->mAngle); + if (options->mUnk_18 >= 0xffff) { + (*actorSlot)->mUnk_03c = -1; + } else { + (*actorSlot)->mUnk_03c = options->mUnk_18; + } + (*actorSlot)->mUnk_034 = options->mUnk_1c; + (*actorSlot)->mUnk_140 = options->mUnk_24; + (*actorSlot)->mUnk_144 = options->mUnk_28; + Actor *actor2 = *actorSlot; + actor2->mPos = *pos; + actor2->mPrevPos = *pos; + (*actorSlot)->mUnk_010 = gMapManager->GetCourseData_Unk_1c(); + (*actorSlot)->mUnk_011 = gMapManager->GetCourseData_Unk_1d(); + u16 nextIndex = actorRef.index + 1; + if (actorManager->mMaxActorIndex < nextIndex) { + actorManager->mMaxActorIndex = nextIndex; + } + actorManager->mCacheEmptyActorIndex = actorRef.index; + + actorRef.id = actorManager->mNextActorId; + if (ref != NULL) { + *ref = actorRef; + } + actorManager->mNextActorId += 1; + actorManager->mNumActors += 1; + if (!(*actorSlot)->vfunc_08()) { + (*actorSlot)->mAlive = false; + if (ref != NULL) { + ref->Reset(); + } + return -1; + } + break; + } + if ((actorRef.id == -1) && (ref != NULL)) { + ref->Reset(); + } + return actorRef.id; +} -- cgit v1.2.3