ksys: Add act::getRandomAreaItem

This commit is contained in:
Léo Lam 2021-11-24 02:12:05 +01:00
parent c0a79e67ee
commit 0f3cb6e1ec
No known key found for this signature in database
GPG Key ID: 0DF30F9081000741
3 changed files with 37 additions and 1 deletions

View File

@ -80406,7 +80406,7 @@ Address,Quality,Size,Name
0x0000007100ee7880,O,000012,_ZN4ksys3act19getDefaultDropActorEv
0x0000007100ee788c,U,000036,Actor::createDrops
0x0000007100ee78b0,U,001192,eco::getEcosystemActorName
0x0000007100ee7d58,U,000344,eco::sub_7100EE7D58
0x0000007100ee7d58,O,000344,_ZN4ksys3act17getRandomAreaItemEPN4sead14SafeStringBaseIcEERKNS_3eco12AreaItemTypeERKNS1_7Vector3IfEE
0x0000007100ee7eb0,O,000056,_ZN4ksys3act22isInSatoriMountainAreaERKN4sead7Vector3IfEE
0x0000007100ee7ee8,U,002112,
0x0000007100ee8728,U,000388,

Can't render this file because it is too large.

View File

@ -1,6 +1,7 @@
#include "KingSystem/ActorSystem/actActorUtil.h"
#include <container/seadSafeArray.h>
#include <math/seadMathCalcCommon.h>
#include <random/seadGlobalRandom.h>
#include "KingSystem/ActorSystem/Profiles/actRopeBase.h"
#include "KingSystem/ActorSystem/actActor.h"
#include "KingSystem/ActorSystem/actActorConstDataAccess.h"
@ -586,6 +587,35 @@ bool getSameGroupActorName(sead::SafeString* name, const sead::SafeString& actor
return true;
}
bool getRandomAreaItem(sead::SafeString* item, const eco::AreaItemType& type,
const sead::Vector3f& pos) {
auto* eco = eco::Ecosystem::instance();
if (!eco)
return false;
const int area = eco->getFieldMapArea(pos.x, pos.z);
eco::AreaItemSet items;
eco->getAreaItems(area, type, &items);
int chosen_idx = -1;
int running_total = 0;
for (int idx = 0; idx < items.count; ++idx) {
const int num = items.items[idx].num;
running_total += num;
if (int(sead::GlobalRandom::instance()->getU32(running_total)) < num)
chosen_idx = idx;
}
if (chosen_idx < 0) {
*item = sead::SafeString::cEmptyString;
return false;
}
*item = items.items[chosen_idx].name;
return true;
}
bool isInSatoriMountainArea(const sead::Vector3f& pos) {
return eco::Ecosystem::instance()->getFieldMapArea(pos.x, pos.z) == 64;
}

View File

@ -7,6 +7,10 @@ namespace al {
class ByamlIter;
}
namespace ksys::eco {
enum class AreaItemType;
}
namespace ksys::map {
class Object;
}
@ -167,6 +171,8 @@ bool getSameGroupActorName(sead::SafeString* name, const sead::SafeString& actor
s32 getSelectedChoiceIdx(s32 max, const char* query_name);
bool getRandomAreaItem(sead::SafeString* item, const eco::AreaItemType& type,
const sead::Vector3f& pos);
bool isInSatoriMountainArea(const sead::Vector3f& pos);
} // namespace ksys::act