Added and implemented TargetList

This commit is contained in:
smallmodel 2024-03-04 23:07:16 +01:00
parent b4bce3431b
commit cebb351505
No known key found for this signature in database
GPG key ID: 9F2D623CEDF08512
2 changed files with 65 additions and 0 deletions

View file

@ -1197,3 +1197,49 @@ bool WithinFarplaneDistance(const Vector& org)
return org.lengthSquared() < (Square(distance) * Square(0.828f));
}
CLASS_DECLARATION(Class, TargetList, NULL) {
{NULL, NULL}
};
TargetList::TargetList() {}
TargetList::TargetList(const str& tname)
: targetname(tname)
{}
void TargetList::AddEntity(Listener *ent)
{
list.AddObject(static_cast<SimpleEntity *>(ent));
}
void TargetList::AddEntityAt(Listener *ent, int i)
{
list.AddObjectAt(i, static_cast<SimpleEntity *>(ent));
}
int TargetList::GetEntityIndex(Listener *ent)
{
return list.IndexOfObject(static_cast<SimpleEntity *>(ent));
}
void TargetList::RemoveEntity(Listener *ent)
{
list.RemoveObject(static_cast<SimpleEntity *>(ent));
}
SimpleEntity *TargetList::GetNextEntity(SimpleEntity *ent)
{
int index;
for (index = list.IndexOfObject(ent); index <= list.NumObjects(); index++) {
Listener *objptr;
objptr = list.ObjectAt(index);
if (objptr->isSubclassOf(SimpleEntity)) {
return static_cast<SimpleEntity *>(objptr);
}
}
return NULL;
}

View file

@ -39,6 +39,25 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
typedef Container<SafePtr<SimpleEntity>> ConSimple;
class TargetList : public Class {
public:
CLASS_PROTOTYPE(TargetList);
public:
ConSimple list;
str targetname;
public:
TargetList();
TargetList(const str& tname);
void AddEntity(Listener* ent);
void AddEntityAt(Listener* ent, int i);
int GetEntityIndex(Listener* ent);
void RemoveEntity(Listener* ent);
SimpleEntity* GetNextEntity(SimpleEntity* ent);
};
class World : public Entity
{
con_set<const_str, ConSimple> m_targetList; // moh could have used con_set instead of TargetList