summaryrefslogtreecommitdiff
path: root/src/KingSystem
diff options
context:
space:
mode:
authorLéo Lam <leo@leolam.fr>2020-12-02 18:50:27 +0100
committerLéo Lam <leo@leolam.fr>2020-12-02 19:23:05 +0100
commitfc55c87f12f3c9c81974be3a2cdc460f3fe99fba (patch)
tree587f4d994e82d956bce89e6ab71dbfe3c24cbb21 /src/KingSystem
parent3559c31bc9ab193b7bc601d66762807c6ae460a3 (diff)
ksys/act: Implement ActorUtil "has tag" functions
Diffstat (limited to 'src/KingSystem')
-rw-r--r--src/KingSystem/ActorSystem/actActorConstDataAccess.h2
-rw-r--r--src/KingSystem/ActorSystem/actActorUtil.cpp63
-rw-r--r--src/KingSystem/ActorSystem/actActorUtil.h5
3 files changed, 68 insertions, 2 deletions
diff --git a/src/KingSystem/ActorSystem/actActorConstDataAccess.h b/src/KingSystem/ActorSystem/actActorConstDataAccess.h
index 48de7f10..b5125a03 100644
--- a/src/KingSystem/ActorSystem/actActorConstDataAccess.h
+++ b/src/KingSystem/ActorSystem/actActorConstDataAccess.h
@@ -28,7 +28,7 @@ public:
const sead::SafeString& getProfile() const;
const sead::SafeString& getName() const;
- bool hasTag(const sead::SafeString& tag) const;
+ bool hasTag(const char* tag) const;
bool hasTag(u32 tag) const;
u32 getId() const;
bool acquireConnectedCalcParent(ActorLinkConstDataAccess* accessor) const;
diff --git a/src/KingSystem/ActorSystem/actActorUtil.cpp b/src/KingSystem/ActorSystem/actActorUtil.cpp
index 69f6f51f..98937a2d 100644
--- a/src/KingSystem/ActorSystem/actActorUtil.cpp
+++ b/src/KingSystem/ActorSystem/actActorUtil.cpp
@@ -1,20 +1,83 @@
#include "KingSystem/ActorSystem/actActorUtil.h"
#include "KingSystem/ActorSystem/actActor.h"
+#include "KingSystem/ActorSystem/actActorConstDataAccess.h"
#include "KingSystem/ActorSystem/actActorParam.h"
+#include "KingSystem/ActorSystem/actBaseProcLink.h"
#include "KingSystem/ActorSystem/actInfoData.h"
#include "KingSystem/Resource/resResourceActorLink.h"
namespace ksys::act {
+static ActorConstDataAccess getAccessor(BaseProcLink* link) {
+ ActorConstDataAccess accessor;
+ acquireActor(link, &accessor);
+ return accessor;
+}
+
bool hasTag(Actor* actor, const sead::SafeString& tag) {
if (!actor)
return false;
return actor->getParam()->getRes().mActorLink->hasTag(tag.cstr());
}
+bool hasTag(BaseProcLink* link, const sead::SafeString& tag) {
+ return hasTag(getAccessor(link), tag);
+}
+
+bool hasTag(const ActorConstDataAccess& accessor, const sead::SafeString& tag) {
+ return accessor.hasTag(tag.cstr());
+}
+
bool hasTag(const sead::SafeString& actor, const sead::SafeString& tag) {
auto* data = InfoData::instance();
return data && data->hasTag(actor.cstr(), tag.cstr());
}
+bool hasTag(Actor* actor, u32 tag) {
+ return actor && actor->getParam()->getRes().mActorLink->hasTag(tag);
+}
+
+bool hasTag(BaseProcLink* link, u32 tag) {
+ return hasTag(getAccessor(link), tag);
+}
+
+bool hasTag(const ActorConstDataAccess& accessor, u32 tag) {
+ return accessor.hasTag(tag);
+}
+
+bool hasTag(const sead::SafeString& actor, u32 tag) {
+ auto* data = InfoData::instance();
+ return data && data->hasTag(actor.cstr(), tag);
+}
+
+bool hasOneTagAtLeast(Actor* actor, const sead::SafeString& tags) {
+ sead::FixedSafeString<32> tag;
+ for (auto it = tags.tokenBegin(","); tags.tokenEnd(",") != it; ++it) {
+ it.get(&tag);
+ if (hasTag(actor, tag))
+ return true;
+ }
+ return false;
+}
+
+bool hasOneTagAtLeast(BaseProcLink* link, const sead::SafeString& tags) {
+ sead::FixedSafeString<32> tag;
+ for (auto it = tags.tokenBegin(","); tags.tokenEnd(",") != it; ++it) {
+ it.get(&tag);
+ if (hasTag(link, tag))
+ return true;
+ }
+ return false;
+}
+
+bool act::hasOneTagAtLeast(const ActorConstDataAccess& accessor, const sead::SafeString& tags) {
+ sead::FixedSafeString<32> tag;
+ for (auto it = tags.tokenBegin(","); tags.tokenEnd(",") != it; ++it) {
+ it.get(&tag);
+ if (hasTag(accessor, tag))
+ return true;
+ }
+ return false;
+}
+
} // namespace ksys::act
diff --git a/src/KingSystem/ActorSystem/actActorUtil.h b/src/KingSystem/ActorSystem/actActorUtil.h
index 6a312e45..73f329d5 100644
--- a/src/KingSystem/ActorSystem/actActorUtil.h
+++ b/src/KingSystem/ActorSystem/actActorUtil.h
@@ -45,17 +45,20 @@ enum class ZukanType {
};
bool hasTag(Actor* actor, const sead::SafeString& tag);
+bool hasTag(BaseProcLink* link, const sead::SafeString& tag);
+bool hasTag(const ActorConstDataAccess& accessor, const sead::SafeString& tag);
bool hasTag(const sead::SafeString& actor, const sead::SafeString& tag);
bool hasTag(Actor* actor, u32 tag);
bool hasTag(BaseProcLink* link, u32 tag);
+bool hasTag(const ActorConstDataAccess& accessor, u32 tag);
bool hasTag(const sead::SafeString& actor, u32 tag);
/// Checks whether the actor has at least one of the specified tags.
/// @param tags A comma separated list of tags.
bool hasOneTagAtLeast(Actor* actor, const sead::SafeString& tags);
bool hasOneTagAtLeast(BaseProcLink* link, const sead::SafeString& tags);
-bool hasOneTagAtLeast(ActorConstDataAccess* accessor, const sead::SafeString& tags);
+bool hasOneTagAtLeast(const ActorConstDataAccess& accessor, const sead::SafeString& tags);
bool shouldSkipSpawnForWeatherReasons(map::Object* obj);
bool isAnimalMasterAppearance(map::Object* obj);