2016-04-16 21:49:47 +00:00
|
|
|
#include "CObjectList.hpp"
|
|
|
|
|
|
|
|
namespace urde
|
|
|
|
{
|
|
|
|
|
|
|
|
CObjectList::CObjectList(EGameObjectList listEnum)
|
2017-01-15 03:59:37 +00:00
|
|
|
: x2004_listEnum(listEnum)
|
2016-04-16 21:49:47 +00:00
|
|
|
{}
|
|
|
|
|
|
|
|
void CObjectList::AddObject(CEntity& entity)
|
|
|
|
{
|
2016-10-01 19:00:16 +00:00
|
|
|
if (IsQualified(entity))
|
2016-04-16 21:49:47 +00:00
|
|
|
{
|
2017-01-15 03:59:37 +00:00
|
|
|
if (x2008_firstId != -1)
|
2017-08-10 13:40:07 +00:00
|
|
|
x0_list[x2008_firstId].prev = entity.GetUniqueId().Value();
|
|
|
|
s16 prevFirst = x2008_firstId;
|
|
|
|
x2008_firstId = entity.GetUniqueId().Value();
|
2017-01-15 03:59:37 +00:00
|
|
|
SObjectListEntry& newEnt = x0_list[x2008_firstId];
|
2016-04-16 21:49:47 +00:00
|
|
|
newEnt.entity = &entity;
|
2016-08-14 21:11:44 +00:00
|
|
|
newEnt.next = prevFirst;
|
|
|
|
newEnt.prev = -1;
|
2017-01-15 03:59:37 +00:00
|
|
|
++x200a_count;
|
2016-04-16 21:49:47 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void CObjectList::RemoveObject(TUniqueId uid)
|
|
|
|
{
|
2017-08-10 13:40:07 +00:00
|
|
|
SObjectListEntry& ent = x0_list[uid.Value()];
|
2016-04-16 21:49:47 +00:00
|
|
|
if (!ent.entity || ent.entity->GetUniqueId() != uid)
|
|
|
|
return;
|
2017-08-10 13:40:07 +00:00
|
|
|
if (uid.Value() == x2008_firstId)
|
2016-04-16 21:49:47 +00:00
|
|
|
{
|
2017-01-15 03:59:37 +00:00
|
|
|
x2008_firstId = ent.next;
|
2016-08-14 21:11:44 +00:00
|
|
|
if (ent.next != -1)
|
2017-01-15 03:59:37 +00:00
|
|
|
x0_list[ent.next].prev = -1;
|
2016-04-16 21:49:47 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2016-08-14 21:11:44 +00:00
|
|
|
if (ent.next != -1)
|
2017-01-15 03:59:37 +00:00
|
|
|
x0_list[ent.next].prev = -1;
|
|
|
|
x0_list[ent.prev].next = -1;
|
2016-04-16 21:49:47 +00:00
|
|
|
}
|
|
|
|
ent.entity = nullptr;
|
|
|
|
ent.next = -1;
|
2016-08-14 21:11:44 +00:00
|
|
|
ent.prev = -1;
|
2017-01-15 03:59:37 +00:00
|
|
|
--x200a_count;
|
2016-04-16 21:49:47 +00:00
|
|
|
}
|
|
|
|
|
2017-02-14 04:27:20 +00:00
|
|
|
const CEntity* CObjectList::operator[](size_t i) const
|
|
|
|
{
|
|
|
|
const SObjectListEntry& ent = x0_list[i];
|
2017-11-12 05:14:57 +00:00
|
|
|
if (!ent.entity || ent.entity->x30_26_scriptingBlocked)
|
2017-02-14 04:27:20 +00:00
|
|
|
return nullptr;
|
|
|
|
return ent.entity;
|
|
|
|
}
|
|
|
|
|
|
|
|
CEntity* CObjectList::operator[](size_t i)
|
|
|
|
{
|
|
|
|
SObjectListEntry& ent = x0_list[i];
|
2017-11-12 05:14:57 +00:00
|
|
|
if (!ent.entity || ent.entity->x30_26_scriptingBlocked)
|
2017-02-14 04:27:20 +00:00
|
|
|
return nullptr;
|
|
|
|
return ent.entity;
|
|
|
|
}
|
|
|
|
|
2016-04-16 21:49:47 +00:00
|
|
|
const CEntity* CObjectList::GetObjectById(TUniqueId uid) const
|
|
|
|
{
|
2017-03-20 05:09:53 +00:00
|
|
|
if (uid == kInvalidUniqueId)
|
2016-04-16 21:49:47 +00:00
|
|
|
return nullptr;
|
2017-08-10 13:40:07 +00:00
|
|
|
const SObjectListEntry& ent = x0_list[uid.Value()];
|
2017-11-12 05:14:57 +00:00
|
|
|
if (!ent.entity || ent.entity->x30_26_scriptingBlocked)
|
2016-08-14 21:11:44 +00:00
|
|
|
return nullptr;
|
|
|
|
return ent.entity;
|
2016-04-16 21:49:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
CEntity* CObjectList::GetObjectById(TUniqueId uid)
|
|
|
|
{
|
2017-03-20 05:09:53 +00:00
|
|
|
if (uid == kInvalidUniqueId)
|
2016-04-16 21:49:47 +00:00
|
|
|
return nullptr;
|
2017-08-10 13:40:07 +00:00
|
|
|
SObjectListEntry& ent = x0_list[uid.Value()];
|
2017-11-12 05:14:57 +00:00
|
|
|
if (!ent.entity || ent.entity->x30_26_scriptingBlocked)
|
2016-08-14 21:11:44 +00:00
|
|
|
return nullptr;
|
|
|
|
return ent.entity;
|
2016-04-16 21:49:47 +00:00
|
|
|
}
|
|
|
|
|
2017-03-26 05:53:04 +00:00
|
|
|
const CEntity* CObjectList::GetValidObjectById(TUniqueId uid) const
|
|
|
|
{
|
|
|
|
if (uid == kInvalidUniqueId)
|
|
|
|
return nullptr;
|
2017-08-10 13:40:07 +00:00
|
|
|
const SObjectListEntry& ent = x0_list[uid.Value()];
|
2017-03-26 05:53:04 +00:00
|
|
|
if (!ent.entity)
|
|
|
|
return nullptr;
|
|
|
|
if (ent.entity->GetUniqueId() != uid)
|
|
|
|
return nullptr;
|
|
|
|
return ent.entity;
|
|
|
|
}
|
|
|
|
|
|
|
|
CEntity* CObjectList::GetValidObjectById(TUniqueId uid)
|
|
|
|
{
|
|
|
|
if (uid == kInvalidUniqueId)
|
|
|
|
return nullptr;
|
2017-08-10 13:40:07 +00:00
|
|
|
SObjectListEntry& ent = x0_list[uid.Value()];
|
2017-03-26 05:53:04 +00:00
|
|
|
if (!ent.entity)
|
|
|
|
return nullptr;
|
|
|
|
if (ent.entity->GetUniqueId() != uid)
|
|
|
|
return nullptr;
|
|
|
|
return ent.entity;
|
|
|
|
}
|
|
|
|
|
2016-10-01 19:00:16 +00:00
|
|
|
bool CObjectList::IsQualified(const CEntity&) {return true;}
|
2016-04-16 21:49:47 +00:00
|
|
|
|
|
|
|
}
|