1#include "Library/LiveActor/LiveActorGroup.h"
2
3#include "Library/LiveActor/ActorFlagFunction.h"
4
5namespace al {
6LiveActorGroup::LiveActorGroup(const char* groupName, s32 maxActors)
7 : mGroupName(groupName), mMaxActorCount(maxActors) {
8 mActorCount = 0;
9 mActors = new LiveActor*[maxActors];
10}
11
12s32 LiveActorGroup::registerActor(LiveActor* pActor) {
13 mActors[mActorCount] = pActor;
14 s32 count = mActorCount;
15 mActorCount = count + 1;
16 return count;
17}
18
19void LiveActorGroup::removeActor(const LiveActor* pActor) {
20 for (s32 i = 0; i < mActorCount; i++) {
21 if (mActors[i] == pActor) {
22 mActors[i] = mActors[mActorCount - 1];
23 mActorCount--;
24 break;
25 }
26 }
27}
28
29void LiveActorGroup::removeActorAll() {
30 mActorCount = 0;
31}
32
33bool LiveActorGroup::isExistActor(const LiveActor* pActor) const {
34 if (mActorCount < 1)
35 return false;
36
37 for (s32 i = 0; i < mActorCount; i++)
38 if (mActors[i] == pActor)
39 return true;
40
41 return false;
42}
43
44bool LiveActorGroup::isFull() const {
45 return mActorCount >= mMaxActorCount;
46}
47
48s32 LiveActorGroup::calcAliveActorNum() const {
49 s32 count = 0;
50
51 for (s32 i = 0; i < mActorCount; i++)
52 if (!isDead(actor: mActors[i]))
53 count++;
54
55 return count;
56}
57
58LiveActor* LiveActorGroup::getDeadActor() const {
59 for (s32 i = 0; i < mActorCount; i++)
60 if (isDead(actor: mActors[i]))
61 return mActors[i];
62
63 return nullptr;
64}
65
66LiveActor* LiveActorGroup::tryFindDeadActor() const {
67 for (s32 i = 0; i < mActorCount; i++)
68 if (isDead(actor: mActors[i]))
69 return mActors[i];
70
71 return nullptr;
72}
73
74void LiveActorGroup::appearAll() {
75 for (s32 i = 0; i < mActorCount; i++)
76 if (isDead(actor: mActors[i]))
77 mActors[i]->appear();
78}
79
80void LiveActorGroup::killAll() {
81 for (s32 i = 0; i < mActorCount; i++)
82 if (isAlive(actor: mActors[i]))
83 mActors[i]->kill();
84}
85
86void LiveActorGroup::makeActorAliveAll() {
87 for (s32 i = 0; i < mActorCount; i++)
88 mActors[i]->makeActorAlive();
89}
90
91void LiveActorGroup::makeActorDeadAll() {
92 for (s32 i = 0; i < mActorCount; i++)
93 mActors[i]->makeActorDead();
94}
95} // namespace al
96