more conversions to weak pointers

This commit is contained in:
Simon Jarrett 2018-06-21 23:32:21 +01:00
parent b08ab94319
commit e91df41c8e
21 changed files with 1201 additions and 747 deletions

View file

@ -73,7 +73,7 @@ void CAmmunitionWeenie::HandleNonTargetCollision()
if (source->AsPlayer())
source->SendText("Your missile attack hit the environment.", LTT_DEFAULT);
else
MarkForDestroy();
g_pWorld->RemoveEntity(GetPointer<CWeenieObject>());
EmitSound(Sound_Collision, 1.0f);
}
@ -83,7 +83,7 @@ void CAmmunitionWeenie::HandleNonTargetCollision()
void CAmmunitionWeenie::HandleTargetCollision()
{
MarkForDestroy();
g_pWorld->RemoveEntity(GetPointer<CWeenieObject>());
}
BOOL CAmmunitionWeenie::DoCollision(const class EnvCollisionProfile &prof)

View file

@ -1041,9 +1041,10 @@ void CClient::GenerateStarterGear(std::shared_ptr<CWeenieObject> weenieObject, A
std::shared_ptr<CContainerWeenie> sack = NULL;
for (auto pack : weenie->m_Packs)
{
if (pack->AsContainer())
std::shared_ptr<CWeenieObject> pPack = pack.lock();
if (pPack && pPack->AsContainer())
{
sack = pack->AsContainer();
sack = pPack->AsContainer();
break;
}
}

File diff suppressed because it is too large Load diff

View file

@ -120,7 +120,7 @@ public:
private:
CClient *m_pClient;
std::shared_ptr<CPlayerWeenie> m_pPlayer;
std::weak_ptr<CPlayerWeenie> m_pPlayer;
WORD m_MoveActionStamp = 0xFFFF;

View file

@ -12,31 +12,31 @@
CContainerWeenie::CContainerWeenie()
{
for (DWORD i = 0; i < MAX_WIELDED_COMBAT; i++)
m_WieldedCombat[i] = NULL;
m_WieldedCombat[i] = std::shared_ptr<CWeenieObject>();
}
CContainerWeenie::~CContainerWeenie()
{
for (DWORD i = 0; i < MAX_WIELDED_COMBAT; i++)
m_WieldedCombat[i] = NULL;
m_WieldedCombat[i] = std::shared_ptr<CWeenieObject>();
for (auto item : m_Wielded)
{
g_pWorld->RemoveEntity(item);
g_pWorld->RemoveEntity(item.lock());
}
m_Wielded.clear();
for (auto item : m_Items)
{
g_pWorld->RemoveEntity(item);
g_pWorld->RemoveEntity(item.lock());
}
m_Items.clear();
for (auto container : m_Packs)
{
g_pWorld->RemoveEntity(container);
g_pWorld->RemoveEntity(container.lock());
}
m_Packs.clear();
@ -84,9 +84,11 @@ std::shared_ptr<CContainerWeenie> CContainerWeenie::FindContainer(DWORD containe
for (auto pack : m_Packs)
{
if (pack->GetID() == container_id)
std::shared_ptr<CWeenieObject> pPack = pack.lock();
if (pPack && pPack->GetID() == container_id)
{
if (std::shared_ptr<CContainerWeenie> packContainer = pack->AsContainer())
if (std::shared_ptr<CContainerWeenie> packContainer = pPack->AsContainer())
{
return packContainer;
}
@ -115,7 +117,7 @@ std::shared_ptr<CWeenieObject> CContainerWeenie::GetWieldedCombat(COMBAT_USE com
if (index < 0 || index >= MAX_WIELDED_COMBAT)
return NULL;
return m_WieldedCombat[index];
return m_WieldedCombat[index].lock();
}
void CContainerWeenie::SetWieldedCombat(std::shared_ptr<CWeenieObject> wielded, COMBAT_USE combatUse)
@ -158,8 +160,10 @@ std::shared_ptr<CWeenieObject> CContainerWeenie::GetWieldedCaster()
{
for (auto item : m_Wielded)
{
if (item->AsCaster())
return item;
std::shared_ptr<CWeenieObject> pItem = item.lock();
if (pItem && pItem->AsCaster())
return pItem;
}
return NULL;
@ -169,8 +173,10 @@ void CContainerWeenie::Container_GetWieldedByMask(std::list<std::shared_ptr<CWee
{
for (auto item : m_Wielded)
{
if (item->InqIntQuality(CURRENT_WIELDED_LOCATION_INT, 0, TRUE) & inv_loc_mask)
wielded.push_back(item);
std::shared_ptr<CWeenieObject> pItem = item.lock();
if (pItem && pItem->InqIntQuality(CURRENT_WIELDED_LOCATION_INT, 0, TRUE) & inv_loc_mask)
wielded.push_back(pItem);
}
}
@ -178,8 +184,10 @@ std::shared_ptr<CWeenieObject> CContainerWeenie::GetWielded(INVENTORY_LOC slot)
{
for (auto item : m_Wielded)
{
if (item->InqIntQuality(CURRENT_WIELDED_LOCATION_INT, 0, TRUE) == slot)
return item;
std::shared_ptr<CWeenieObject> pItem = item.lock();
if (pItem && pItem->InqIntQuality(CURRENT_WIELDED_LOCATION_INT, 0, TRUE) == slot)
return pItem;
}
return NULL;
@ -192,13 +200,13 @@ void CContainerWeenie::ReleaseContainedItemRecursive(std::shared_ptr<CWeenieObje
for (DWORD i = 0; i < MAX_WIELDED_COMBAT; i++)
{
if (item == m_WieldedCombat[i])
m_WieldedCombat[i] = NULL;
if (item == m_WieldedCombat[i].lock())
m_WieldedCombat[i] = std::shared_ptr<CWeenieObject>();
}
for (std::vector<std::shared_ptr<CWeenieObject> >::iterator equipmentIterator = m_Wielded.begin(); equipmentIterator != m_Wielded.end();)
for (std::vector<std::weak_ptr<CWeenieObject> >::iterator equipmentIterator = m_Wielded.begin(); equipmentIterator != m_Wielded.end();)
{
if (*equipmentIterator != item)
if (equipmentIterator->lock() != item)
{
equipmentIterator++;
continue;
@ -207,9 +215,9 @@ void CContainerWeenie::ReleaseContainedItemRecursive(std::shared_ptr<CWeenieObje
equipmentIterator = m_Wielded.erase(equipmentIterator);
}
for (std::vector<std::shared_ptr<CWeenieObject> >::iterator itemIterator = m_Items.begin(); itemIterator != m_Items.end();)
for (std::vector<std::weak_ptr<CWeenieObject> >::iterator itemIterator = m_Items.begin(); itemIterator != m_Items.end();)
{
if (*itemIterator != item)
if (itemIterator->lock() != item)
{
itemIterator++;
continue;
@ -218,9 +226,9 @@ void CContainerWeenie::ReleaseContainedItemRecursive(std::shared_ptr<CWeenieObje
itemIterator = m_Items.erase(itemIterator);
}
for (std::vector<std::shared_ptr<CWeenieObject> >::iterator packIterator = m_Packs.begin(); packIterator != m_Packs.end();)
for (std::vector<std::weak_ptr<CWeenieObject> >::iterator packIterator = m_Packs.begin(); packIterator != m_Packs.end();)
{
std::shared_ptr<CWeenieObject> pack = *packIterator;
std::shared_ptr<CWeenieObject> pack = packIterator->lock();
if (pack != item)
{
@ -255,10 +263,12 @@ BOOL CContainerWeenie::Container_CanEquip(std::shared_ptr<CWeenieObject> item, D
for (auto wielded : m_Wielded)
{
if (wielded == item)
std::shared_ptr<CWeenieObject> pWielded = wielded.lock();
if (pWielded == item)
return TRUE;
if (!wielded->CanEquipWith(item, location))
if (pWielded && !pWielded->CanEquipWith(item, location))
return FALSE;
}
@ -273,7 +283,9 @@ void CContainerWeenie::Container_EquipItem(DWORD dwCell, std::shared_ptr<CWeenie
bool bAlreadyEquipped = false;
for (auto entry : m_Wielded)
{
if (entry == item)
std::shared_ptr<CWeenieObject> pWielded = entry.lock();
if (pWielded == item)
{
bAlreadyEquipped = true;
break;
@ -337,22 +349,33 @@ std::shared_ptr<CWeenieObject> CContainerWeenie::FindContainedItem(DWORD object_
{
for (auto item : m_Wielded)
{
if (item->GetID() == object_id)
return item;
std::shared_ptr<CWeenieObject> pItem = item.lock();
if (pItem && pItem->GetID() == object_id)
return pItem;
}
for (auto item : m_Items)
{
if (item->GetID() == object_id)
return item;
std::shared_ptr<CWeenieObject> pItem = item.lock();
if (pItem && pItem->GetID() == object_id)
return pItem;
}
for (auto item : m_Packs)
{
if (item->GetID() == object_id)
return item;
std::shared_ptr<CWeenieObject> pItem = item.lock();
if (!pItem)
{
continue;
}
if (pItem->GetID() == object_id)
return pItem;
if (auto subitem = item->FindContainedItem(object_id))
if (auto subitem = pItem->FindContainedItem(object_id))
return subitem;
}
@ -417,7 +440,7 @@ BOOL CContainerWeenie::Container_CanStore(std::shared_ptr<CWeenieObject> pItem,
for (auto container : m_Packs)
{
if (container == pItem)
if (container.lock() == pItem)
return TRUE;
}
@ -447,7 +470,7 @@ BOOL CContainerWeenie::Container_CanStore(std::shared_ptr<CWeenieObject> pItem,
for (auto container : m_Items)
{
if (container == pItem)
if (container.lock() == pItem)
return TRUE;
}
@ -589,16 +612,18 @@ bool CContainerWeenie::SpawnInContainer(DWORD wcid, int amount, int ptid, float
//If we're stackable, first let's try stacking to existing items.
for (auto possibleMatch : m_Items)
{
if (item->m_Qualities.id != possibleMatch->m_Qualities.id)
std::shared_ptr<CWeenieObject> pPossibleMatch = possibleMatch.lock();
if (item->m_Qualities.id != pPossibleMatch->m_Qualities.id)
continue;
if (ptid != 0 && possibleMatch->InqIntQuality(PALETTE_TEMPLATE_INT, 0) != ptid)
if (ptid != 0 && pPossibleMatch->InqIntQuality(PALETTE_TEMPLATE_INT, 0) != ptid)
continue;
if (shade >= 0.0 && possibleMatch->InqFloatQuality(SHADE_FLOAT, 0) != shade)
if (shade >= 0.0 && pPossibleMatch->InqFloatQuality(SHADE_FLOAT, 0) != shade)
continue;
int possibleMatchStackSize = possibleMatch->InqIntQuality(STACK_SIZE_INT, 1);
int possibleMatchStackSize = pPossibleMatch->InqIntQuality(STACK_SIZE_INT, 1);
if (possibleMatchStackSize < maxStackSize)
{
//we have room.
@ -606,14 +631,14 @@ bool CContainerWeenie::SpawnInContainer(DWORD wcid, int amount, int ptid, float
if (roomFor >= amount)
{
//room for everything!
possibleMatch->SetStackSize(possibleMatchStackSize + amount);
pPossibleMatch->SetStackSize(possibleMatchStackSize + amount);
return true;
}
else
{
//room for some.
amount -= roomFor;
possibleMatch->SetStackSize(maxStackSize);
pPossibleMatch->SetStackSize(maxStackSize);
}
}
}
@ -795,31 +820,51 @@ void CContainerWeenie::InitPhysicsObj()
for (auto item : m_Wielded)
{
std::shared_ptr<CWeenieObject> pItem = item.lock();
if (!pItem)
{
continue;
}
#ifdef _DEBUG
assert(item->GetWielderID() == GetID());
#endif
int parentLocation = item->InqIntQuality(PARENT_LOCATION_INT, PARENT_ENUM::PARENT_NONE);
int parentLocation = pItem->InqIntQuality(PARENT_LOCATION_INT, PARENT_ENUM::PARENT_NONE);
if (parentLocation != PARENT_ENUM::PARENT_NONE)
{
item->set_parent(GetPointer<CWeenieObject>(), parentLocation);
pItem->set_parent(GetPointer<CWeenieObject>(), parentLocation);
int placement = item->InqIntQuality(PLACEMENT_POSITION_INT, 0);
int placement = pItem->InqIntQuality(PLACEMENT_POSITION_INT, 0);
assert(placement);
item->SetPlacementFrame(placement, FALSE);
pItem->SetPlacementFrame(placement, FALSE);
}
}
#ifdef _DEBUG
for (auto item : m_Items)
{
assert(item->InqIntQuality(PARENT_LOCATION_INT, PARENT_ENUM::PARENT_NONE) == PARENT_ENUM::PARENT_NONE);
std::shared_ptr<CWeenieObject> pItem = item.lock();
if (!pItem)
{
continue;
}
assert(pItem->InqIntQuality(PARENT_LOCATION_INT, PARENT_ENUM::PARENT_NONE) == PARENT_ENUM::PARENT_NONE);
}
for (auto pack : m_Packs)
{
assert(pack->InqIntQuality(PARENT_LOCATION_INT, PARENT_ENUM::PARENT_NONE) == PARENT_ENUM::PARENT_NONE);
std::shared_ptr<CWeenieObject> pPack = pack.lock();
if (!pPack)
{
continue;
}
assert(pPack->InqIntQuality(PARENT_LOCATION_INT, PARENT_ENUM::PARENT_NONE) == PARENT_ENUM::PARENT_NONE);
}
#endif
}
@ -830,20 +875,38 @@ void CContainerWeenie::SaveEx(class CWeenieSave &save)
for (auto item : m_Wielded)
{
save._equipment.push_back(item->GetID());
item->Save();
std::shared_ptr<CWeenieObject> pItem = item.lock();
if (!pItem)
{
continue;
}
save._equipment.push_back(pItem->GetID());
pItem->Save();
}
for (auto item : m_Items)
{
save._inventory.push_back(item->GetID());
item->Save();
std::shared_ptr<CWeenieObject> pItem = item.lock();
if (!pItem)
{
continue;
}
save._inventory.push_back(pItem->GetID());
pItem->Save();
}
for (auto item : m_Packs)
{
save._packs.push_back(item->GetID());
item->Save();
std::shared_ptr<CWeenieObject> pItem = item.lock();
if (!pItem)
{
continue;
}
save._packs.push_back(pItem->GetID());
pItem->Save();
}
}
@ -1004,28 +1067,52 @@ void CContainerWeenie::MakeAwareViewContent(std::shared_ptr<CWeenieObject> other
//start from the bottom of the tree so the packs have their fill bar correctly populated.
for (auto pack : m_Packs)
{
if (pack->AsContainer())
pack->AsContainer()->MakeAwareViewContent(other);
other->MakeAware(pack, true);
std::shared_ptr<CWeenieObject> pPack = pack.lock();
if (!pPack)
{
continue;
}
if (pPack->AsContainer())
pPack->AsContainer()->MakeAwareViewContent(other);
other->MakeAware(pPack, true);
}
for (auto item : m_Items)
{
other->MakeAware(item, true);
std::shared_ptr<CWeenieObject> pItem = item.lock();
if (!pItem)
{
continue;
}
other->MakeAware(pItem, true);
}
PackableList<ContentProfile> inventoryList;
for (auto item : m_Items)
{
std::shared_ptr<CWeenieObject> pItem = item.lock();
if (!pItem)
{
continue;
}
ContentProfile prof;
prof.m_iid = item->GetID();
prof.m_iid = pItem->GetID();
prof.m_uContainerProperties = 0;
inventoryList.push_back(prof);
}
for (auto pack : m_Packs)
{
std::shared_ptr<CWeenieObject> pPack = pack.lock();
if (!pPack)
{
continue;
}
ContentProfile prof;
prof.m_iid = pack->GetID();
prof.m_iid = pPack->GetID();
prof.m_uContainerProperties = 1; //todo: what about foci? Do they need a different value here?
inventoryList.push_back(prof);
}
@ -1118,11 +1205,41 @@ void CContainerWeenie::ResetToInitialState()
SetLocked(m_bInitiallyLocked ? TRUE : FALSE);
while (!m_Wielded.empty())
Container_DeleteItem((*m_Wielded.begin())->GetID());
{
std::shared_ptr<CWeenieObject> pItem = m_Wielded.begin()->lock();
if (!pItem)
{
m_Wielded.erase(m_Wielded.begin());
continue;
}
Container_DeleteItem(pItem->GetID());
}
while (!m_Items.empty())
Container_DeleteItem((*m_Items.begin())->GetID());
{
std::shared_ptr<CWeenieObject> pItem = m_Items.begin()->lock();
if (!pItem)
{
m_Items.erase(m_Items.begin());
continue;
}
Container_DeleteItem(pItem->GetID());
}
while (!m_Packs.empty())
Container_DeleteItem((*m_Packs.begin())->GetID());
{
std::shared_ptr<CWeenieObject> pItem = m_Packs.begin()->lock();
if (!pItem)
{
m_Packs.erase(m_Packs.begin());
continue;
}
Container_DeleteItem(pItem->GetID());
}
if (m_Qualities._generator_table)
@ -1255,31 +1372,66 @@ void CContainerWeenie::InventoryTick()
{
CWeenieObject::InventoryTick();
for (auto wielded : m_Wielded)
auto wielded = m_Wielded.begin();
while (wielded != m_Wielded.end())
{
wielded->WieldedTick();
std::shared_ptr<CWeenieObject> pItem = wielded->lock();
if (!pItem)
{
m_Wielded.erase(wielded);
}
else
{
pItem->WieldedTick();
#ifdef _DEBUG
wielded->DebugValidate();
pItem->DebugValidate();
#endif
}
wielded++;
}
for (auto item : m_Items)
auto item = m_Items.begin();
while (item != m_Items.end())
{
item->InventoryTick();
std::shared_ptr<CWeenieObject> pItem = item->lock();
if (!pItem)
{
m_Items.erase(wielded);
}
else
{
pItem->InventoryTick();
#ifdef _DEBUG
item->DebugValidate();
pItem->DebugValidate();
#endif
}
item++;
}
for (auto pack : m_Packs)
auto pack = m_Packs.begin();
while (pack != m_Packs.end())
{
pack->InventoryTick();
std::shared_ptr<CWeenieObject> pItem = pack->lock();
if (!pItem)
{
m_Packs.erase(wielded);
}
else
{
pItem->InventoryTick();
#ifdef _DEBUG
pack->DebugValidate();
pItem->DebugValidate();
#endif
}
pack++;
}
}
@ -1297,32 +1449,8 @@ void CContainerWeenie::Tick()
return;
}
for(auto wielded : m_Wielded)
{
wielded->WieldedTick();
#ifdef _DEBUG
wielded->DebugValidate();
#endif
}
for (auto item : m_Items)
{
item->InventoryTick();
#ifdef _DEBUG
item->DebugValidate();
#endif
}
for (auto pack : m_Packs)
{
pack->InventoryTick();
#ifdef _DEBUG
pack->DebugValidate();
#endif
}
// TODO mwnciau removed a lot of code here and replaced it with this. If problems occur...
InventoryTick();
_nextInventoryTick = Timer::cur_time + Random::GenFloat(0.4, 0.6);
}
@ -1412,12 +1540,27 @@ DWORD CContainerWeenie::RecalculateCoinAmount()
int coinAmount = 0;
for (auto item : m_Items)
{
if (item->m_Qualities.id == W_COINSTACK_CLASS)
coinAmount += item->InqIntQuality(STACK_SIZE_INT, 1, true);
std::shared_ptr<CWeenieObject> pItem = item.lock();
if (!pItem)
{
continue;
}
if (pItem->m_Qualities.id == W_COINSTACK_CLASS)
coinAmount += pItem->InqIntQuality(STACK_SIZE_INT, 1, true);
}
for (auto pack : m_Packs)
coinAmount += pack->RecalculateCoinAmount();
{
std::shared_ptr<CWeenieObject> pItem = pack.lock();
if (!pItem)
{
continue;
}
coinAmount += pItem->RecalculateCoinAmount();
}
m_Qualities.SetInt(COIN_VALUE_INT, coinAmount);
NotifyIntStatUpdated(COIN_VALUE_INT);
@ -1430,12 +1573,28 @@ DWORD CContainerWeenie::RecalculateAltCoinAmount(int currencyid)
int coinAmount = 0;
for (auto item : m_Items)
{
if (item->m_Qualities.id == currencyid)
coinAmount += item->InqIntQuality(STACK_SIZE_INT, 1, true);
std::shared_ptr<CWeenieObject> pItem = item.lock();
if (!pItem)
{
continue;
}
if (pItem->m_Qualities.id == currencyid)
coinAmount += pItem->InqIntQuality(STACK_SIZE_INT, 1, true);
}
for (auto pack : m_Packs)
coinAmount += pack->RecalculateAltCoinAmount(currencyid);
{
std::shared_ptr<CWeenieObject> pItem = pack.lock();
if (!pItem)
{
continue;
}
coinAmount += pItem->RecalculateAltCoinAmount(currencyid);
}
return coinAmount;
}
@ -1456,18 +1615,25 @@ DWORD CContainerWeenie::ConsumeCoin(int amountToConsume)
DWORD amountConsumed = 0;
for (auto item : m_Items)
{
if (item->m_Qualities.id == W_COINSTACK_CLASS)
std::shared_ptr<CWeenieObject> pItem = item.lock();
if (!pItem)
{
int stackSize = item->InqIntQuality(STACK_SIZE_INT, 1, true);
continue;
}
if (pItem->m_Qualities.id == W_COINSTACK_CLASS)
{
int stackSize = pItem->InqIntQuality(STACK_SIZE_INT, 1, true);
if (stackSize <= amountToConsume)
{
removeList.push_back(item);
removeList.push_back(pItem);
amountToConsume -= stackSize;
amountConsumed += stackSize;
}
else
{
item->SetStackSize(stackSize - amountToConsume);
pItem->SetStackSize(stackSize - amountToConsume);
amountConsumed += amountToConsume;
break;
}
@ -1481,7 +1647,14 @@ DWORD CContainerWeenie::ConsumeCoin(int amountToConsume)
{
for (auto pack : m_Packs)
{
DWORD amountFromPack = pack->ConsumeCoin(amountToConsume);
std::shared_ptr<CWeenieObject> pItem = pack.lock();
if (!pItem)
{
continue;
}
DWORD amountFromPack = pItem->ConsumeCoin(amountToConsume);
amountToConsume -= amountFromPack;
amountConsumed += amountFromPack;
@ -1511,18 +1684,25 @@ DWORD CContainerWeenie::ConsumeAltCoin(int amountToConsume, int currencyid)
DWORD amountConsumed = 0;
for (auto item : m_Items)
{
if (item->m_Qualities.id == currencyid)
std::shared_ptr<CWeenieObject> pItem = item.lock();
if (!pItem)
{
int stackSize = item->InqIntQuality(STACK_SIZE_INT, 1, true);
continue;
}
if (pItem->m_Qualities.id == currencyid)
{
int stackSize = pItem->InqIntQuality(STACK_SIZE_INT, 1, true);
if (stackSize <= amountToConsume)
{
removeList.push_back(item);
removeList.push_back(pItem);
amountToConsume -= stackSize;
amountConsumed += stackSize;
}
else
{
item->SetStackSize(stackSize - amountToConsume);
pItem->SetStackSize(stackSize - amountToConsume);
amountConsumed += amountToConsume;
break;
}
@ -1536,7 +1716,14 @@ DWORD CContainerWeenie::ConsumeAltCoin(int amountToConsume, int currencyid)
{
for (auto pack : m_Packs)
{
DWORD amountFromPack = pack->ConsumeAltCoin(amountToConsume, currencyid);
std::shared_ptr<CWeenieObject> pItem = pack.lock();
if (!pItem)
{
continue;
}
DWORD amountFromPack = pItem->ConsumeAltCoin(amountToConsume, currencyid);
amountToConsume -= amountFromPack;
amountConsumed += amountFromPack;
@ -1557,18 +1744,39 @@ void CContainerWeenie::RecalculateEncumbrance()
int newValue = 0;
for (auto wielded : m_Wielded)
{
newValue += wielded->InqIntQuality(ENCUMB_VAL_INT, 0);
std::shared_ptr<CWeenieObject> pItem = wielded.lock();
if (!pItem)
{
continue;
}
newValue += pItem->InqIntQuality(ENCUMB_VAL_INT, 0);
}
for (auto item : m_Items)
{
newValue += item->InqIntQuality(ENCUMB_VAL_INT, 0);
std::shared_ptr<CWeenieObject> pItem = item.lock();
if (!pItem)
{
continue;
}
newValue += pItem->InqIntQuality(ENCUMB_VAL_INT, 0);
}
for (auto pack : m_Packs)
{
pack->RecalculateEncumbrance();
newValue += pack->InqIntQuality(ENCUMB_VAL_INT, 0);
std::shared_ptr<CWeenieObject> pItem = pack.lock();
if (!pItem)
{
continue;
}
pItem->RecalculateEncumbrance();
newValue += pItem->InqIntQuality(ENCUMB_VAL_INT, 0);
}
if (oldValue != newValue)
@ -1582,19 +1790,40 @@ bool CContainerWeenie::IsAttunedOrContainsAttuned()
{
for (auto wielded : m_Wielded)
{
if (wielded->IsAttunedOrContainsAttuned())
std::shared_ptr<CWeenieObject> pItem = wielded.lock();
if (!pItem)
{
continue;
}
if (pItem->IsAttunedOrContainsAttuned())
return true;
}
for (auto item : m_Items)
{
if (item->IsAttunedOrContainsAttuned())
std::shared_ptr<CWeenieObject> pItem = item.lock();
if (!pItem)
{
continue;
}
if (pItem->IsAttunedOrContainsAttuned())
return true;
}
for (auto pack : m_Packs)
{
if (pack->IsAttunedOrContainsAttuned())
std::shared_ptr<CWeenieObject> pItem = pack.lock();
if (!pItem)
{
continue;
}
if (pItem->IsAttunedOrContainsAttuned())
return true;
}

View file

@ -103,10 +103,10 @@ public:
void AdjustToNewCombatMode();
std::shared_ptr<CWeenieObject> m_WieldedCombat[MAX_WIELDED_COMBAT];
std::vector<std::shared_ptr<CWeenieObject> > m_Wielded;
std::vector<std::shared_ptr<CWeenieObject> > m_Items;
std::vector<std::shared_ptr<CWeenieObject> > m_Packs;
std::weak_ptr<CWeenieObject> m_WieldedCombat[MAX_WIELDED_COMBAT];
std::vector<std::weak_ptr<CWeenieObject> > m_Wielded;
std::vector<std::weak_ptr<CWeenieObject> > m_Items;
std::vector<std::weak_ptr<CWeenieObject> > m_Packs;
// For opening/closing containers
double _nextCheckToClose = 0.0;

View file

@ -140,7 +140,7 @@ void CCorpseWeenie::Tick()
{
if (_mark_for_destroy_at <= Timer::cur_time)
{
MarkForDestroy();
g_pWorld->RemoveEntity(GetPointer<CWeenieObject>());
}
}
}

View file

@ -46,7 +46,7 @@ void CHotSpotWeenie::Tick()
{
if ((_timeToRot + 2.0) <= Timer::cur_time)
{
MarkForDestroy();
g_pWorld->RemoveEntity(GetPointer<CWeenieObject>());
}
}
else

View file

@ -1139,7 +1139,7 @@ int CHookWeenie::DoUseResponse(std::shared_ptr<CWeenieObject> other)
if (m_Items.empty())
return WERROR_OBJECT_GONE;
hookedItem = m_Items[0];
hookedItem = m_Items[0].lock();
if (!hookedItem)
return WERROR_OBJECT_GONE;
@ -1173,7 +1173,7 @@ void CHookWeenie::Identify(std::shared_ptr<CWeenieObject> other, DWORD overrideI
if (m_Items.empty())
return;
hookedItem = m_Items[0];
hookedItem = m_Items[0].lock();
if (!hookedItem)
return;
@ -1206,7 +1206,7 @@ void CHookWeenie::UpdateHookedObject(std::shared_ptr<CWeenieObject> hookedItem,
if (!hookedItem && !m_Items.empty())
{
hookedItem = m_Items[0];
hookedItem = m_Items[0].lock();
}
if (!hookedItem)
@ -1426,7 +1426,7 @@ void CHookWeenie::SetHookVisibility(bool newSetting)
if (!m_Items.empty())
{
std::shared_ptr<CWeenieObject> hookedItem = m_Items[0];
std::shared_ptr<CWeenieObject> hookedItem = m_Items[0].lock();
if (!hookedItem)
return;
@ -1464,7 +1464,7 @@ void CHookWeenie::SetHookVisibility(bool newSetting)
else
SafeDelete(m_Qualities._emote_table);
if (std::shared_ptr<CWeenieObject> hookedItem = m_Items[0])
if (std::shared_ptr<CWeenieObject> hookedItem = m_Items[0].lock())
{
m_Qualities.SetString(NAME_STRING, hookedItem->GetName());
m_Qualities.SetInt(ITEMS_CAPACITY_INT, hookedItem->m_Qualities.GetInt(ITEMS_CAPACITY_INT, 0));

View file

@ -1595,7 +1595,7 @@ void CMonsterWeenie::OnMotionDone(DWORD motion, BOOL success)
NotifyContainedItemRemoved(pItem->id);
pItem->MarkForDestroy();
g_pWorld->RemoveEntity(pItem);
}
}
@ -1682,8 +1682,15 @@ void CMonsterWeenie::GenerateDeathLoot(std::shared_ptr<CCorpseWeenie> pCorpse)
for each(auto item in pCorpse->m_Items)
{
if (item->IsDestroyedOnDeath())
removeList.push_back(item);
std::shared_ptr<CWeenieObject> pItem = item.lock();
if (!pItem)
{
continue;
}
if (pItem->IsDestroyedOnDeath())
removeList.push_back(pItem);
}
for (auto item : removeList)
@ -1699,7 +1706,7 @@ void CMonsterWeenie::OnDeathAnimComplete()
if (!_IsPlayer())
{
MarkForDestroy();
g_pWorld->RemoveEntity(GetPointer<CWeenieObject>());
}
// create corpse
@ -2201,7 +2208,14 @@ double CMonsterWeenie::GetMeleeDefenseModUsingWielded()
Container_GetWieldedByMask(wielded, ARMOR_LOC);
for (auto item : m_Wielded) //check all armor for appropriate imbue effects
{
if (item->GetImbueEffects() & MeleeDefense_ImbuedEffectType)
std::shared_ptr<CWeenieObject> pItem = item.lock();
if (!pItem)
{
continue;
}
if (pItem->GetImbueEffects() & MeleeDefense_ImbuedEffectType)
defenseMod += 0.01;
}
@ -2224,7 +2238,14 @@ double CMonsterWeenie::GetMissileDefenseModUsingWielded()
Container_GetWieldedByMask(wielded, ARMOR_LOC);
for (auto item : m_Wielded) //check all armor for appropriate imbue effects
{
if (item->GetImbueEffects() & MissileDefense_ImbuedEffectType)
std::shared_ptr<CWeenieObject> pItem = item.lock();
if (!pItem)
{
continue;
}
if (pItem->GetImbueEffects() & MissileDefense_ImbuedEffectType)
defenseMod += 0.01;
}

View file

@ -1053,16 +1053,28 @@ BinaryWriter *LoginCharacter(std::shared_ptr<CPlayerWeenie> pPlayer)
PackableList<ContentProfile> inventoryList;
for (auto item : pPlayer->m_Items)
{
std::shared_ptr<CWeenieObject> pItem = item.lock();
if (!pItem)
{
continue;
}
ContentProfile prof;
prof.m_iid = item->GetID();
prof.m_iid = pItem->GetID();
prof.m_uContainerProperties = 0;
inventoryList.push_back(prof);
}
for (auto item : pPlayer->m_Packs)
{
std::shared_ptr<CWeenieObject> pItem = item.lock();
if (!pItem)
{
continue;
}
ContentProfile prof;
prof.m_iid = item->GetID();
prof.m_uContainerProperties = item->AsContainer() ? 1 : 2;
prof.m_iid = pItem->GetID();
prof.m_uContainerProperties = pItem->AsContainer() ? 1 : 2;
inventoryList.push_back(prof);
}
inventoryList.Pack(LC);
@ -1070,10 +1082,16 @@ BinaryWriter *LoginCharacter(std::shared_ptr<CPlayerWeenie> pPlayer)
PackableList<InventoryPlacement> wieldedList;
for (auto wielded : pPlayer->m_Wielded)
{
std::shared_ptr<CWeenieObject> pItem = wielded.lock();
if (!pItem)
{
continue;
}
InventoryPlacement place;
place.iid_ = wielded->GetID();
place.loc_ = wielded->InqIntQuality(CURRENT_WIELDED_LOCATION_INT, 0);
place.priority_ = wielded->InqIntQuality(CLOTHING_PRIORITY_INT, 0);
place.iid_ = pItem->GetID();
place.loc_ = pItem->InqIntQuality(CURRENT_WIELDED_LOCATION_INT, 0);
place.priority_ = pItem->InqIntQuality(CLOTHING_PRIORITY_INT, 0);
wieldedList.push_back(place);
}
wieldedList.Pack(LC);

View file

@ -351,19 +351,21 @@ void CPlayerWeenie::MakeAware(std::shared_ptr<CWeenieObject> pEntity, bool bForc
// make aware of inventory too
for (auto item : m_Wielded)
{
MakeAware(item);
MakeAware(item.lock());
}
for (auto item : m_Items)
{
MakeAware(item);
MakeAware(item.lock());
}
for (auto item : m_Packs)
{
MakeAware(item);
std::shared_ptr<CWeenieObject> pItem = item.lock();
if (std::shared_ptr<CContainerWeenie> container = item->AsContainer())
MakeAware(pItem);
if (std::shared_ptr<CContainerWeenie> container = pItem->AsContainer())
{
container->MakeAwareViewContent(GetPointer<CWeenieObject>());
}
@ -431,7 +433,7 @@ std::string CPlayerWeenie::RemoveLastAssessed()
if (pObject && !pObject->AsPlayer() && !pObject->m_bDontClear) {
std::string name = pObject->GetName();
pObject->MarkForDestroy();
g_pWorld->RemoveEntity(pObject);
m_LastAssessed = 0;
return name;
}
@ -570,18 +572,25 @@ void CPlayerWeenie::OnGivenXP(long long amount, bool allegianceXP)
}
}
void addItemsToDropLists(PhysObjVector items, std::vector<std::shared_ptr<CWeenieObject> > &removeList, std::vector<std::shared_ptr<CWeenieObject> > &alwaysDropList, std::vector<std::shared_ptr<CWeenieObject> > &allValidItems)
void addItemsToDropLists(std::vector<std::weak_ptr<CWeenieObject>> items, std::vector<std::shared_ptr<CWeenieObject> > &removeList, std::vector<std::shared_ptr<CWeenieObject> > &alwaysDropList, std::vector<std::shared_ptr<CWeenieObject> > &allValidItems)
{
for (auto item : items)
{
if (item->m_Qualities.id == W_COINSTACK_CLASS)
std::shared_ptr<CWeenieObject> pItem = item.lock();
if (!pItem)
{
continue;
else if (item->IsDestroyedOnDeath())
removeList.push_back(item);
else if (item->IsDroppedOnDeath())
alwaysDropList.push_back(item);
else if (!item->IsBonded())
allValidItems.push_back(item);
}
if (pItem->m_Qualities.id == W_COINSTACK_CLASS)
continue;
else if (pItem->IsDestroyedOnDeath())
removeList.push_back(pItem);
else if (pItem->IsDroppedOnDeath())
alwaysDropList.push_back(pItem);
else if (!pItem->IsBonded())
allValidItems.push_back(pItem);
}
}
@ -635,7 +644,14 @@ void CPlayerWeenie::CalculateAndDropDeathItems(std::shared_ptr<CCorpseWeenie> pC
for (auto packAsWeenie : m_Packs)
{
std::shared_ptr<CContainerWeenie> pack = packAsWeenie->AsContainer();
std::shared_ptr<CWeenieObject> pItem = packAsWeenie.lock();
if (!pItem)
{
continue;
}
std::shared_ptr<CContainerWeenie> pack = pItem->AsContainer();
if (pack)
{
addItemsToDropLists(pack->m_Items, removeList, alwaysDropList, allValidItems);
@ -1205,11 +1221,18 @@ int CPlayerWeenie::UseEx(bool bConfirmed)
priority_queue<std::shared_ptr<CWeenieObject>, vector<std::shared_ptr<CWeenieObject>>, CompareManaNeeds > itemsNeedingMana, itemsStillNeedingMana; // MIN heaps sorted by mana deficit
for (auto wielded : m_Wielded)
{
int curMana = wielded->InqIntQuality(ITEM_CUR_MANA_INT, 0, TRUE);
int maxMana = wielded->InqIntQuality(ITEM_MAX_MANA_INT, 0, TRUE);
std::shared_ptr<CWeenieObject> pItem = wielded.lock();
if (!pItem)
{
continue;
}
int curMana = pItem->InqIntQuality(ITEM_CUR_MANA_INT, 0, TRUE);
int maxMana = pItem->InqIntQuality(ITEM_MAX_MANA_INT, 0, TRUE);
int deficit = maxMana - curMana;
if (deficit > 0) {
itemsNeedingMana.push(wielded);
itemsNeedingMana.push(pItem);
}
}
if (itemsNeedingMana.empty()) {
@ -3449,11 +3472,18 @@ void CPlayerWeenie::SetLoginPlayerQualities()
for (auto wielded : m_Wielded)
{
if (wielded->InqIntQuality(ITEM_CUR_MANA_INT, 0, true) > 0)
std::shared_ptr<CWeenieObject> pItem = wielded.lock();
if (!pItem)
{
continue;
}
if (pItem->InqIntQuality(ITEM_CUR_MANA_INT, 0, true) > 0)
{
double manaRate = 0.0f;
if (wielded->m_Qualities.InqFloat(MANA_RATE_FLOAT, manaRate, TRUE) && manaRate != 0.0)
wielded->_nextManaUse = Timer::cur_time + (-manaRate * 1000);
if (pItem->m_Qualities.InqFloat(MANA_RATE_FLOAT, manaRate, TRUE) && manaRate != 0.0)
pItem->_nextManaUse = Timer::cur_time + (-manaRate * 1000);
}
}
@ -3461,9 +3491,16 @@ void CPlayerWeenie::SetLoginPlayerQualities()
{
for (auto item : m_Items)
{
if (item->m_Qualities.id == W_TUTORIALBOOK_CLASS)
std::shared_ptr<CWeenieObject> pItem = item.lock();
if (!pItem)
{
item->Use(AsPlayer());
continue;
}
if (pItem->m_Qualities.id == W_TUTORIALBOOK_CLASS)
{
pItem->Use(AsPlayer());
break;
}
}
@ -3908,3 +3945,8 @@ void CPlayerWeenie::ChangeCombatMode(COMBAT_MODE mode, bool playerRequested)
m_pTradeManager->CloseTrade(AsPlayer(), 2); // EnteredCombat
}
}
void CPlayerWeenie::MarkForDestroy()
{
m_dDestroyTime = Timer::cur_time + 2; // give some time to wrap up
}

View file

@ -79,14 +79,6 @@ public:
void HandleItemManaRequest(DWORD itemId);
//base virtuals
virtual void MarkForDestroy()
{
m_pClient = NULL;
CMonsterWeenie::MarkForDestroy();
}
//Movement overrides
//...
@ -207,6 +199,8 @@ public:
void UpdatePKActivity() { m_iPKActivity = Timer::cur_time + 60; }
bool CheckPKActivity() { return m_iPKActivity > Timer::cur_time; }
void MarkForDestroy() override;
protected:
CClient *m_pClient;

View file

@ -3,6 +3,7 @@
#include "WeenieObject.h"
#include "Scroll.h"
#include "Player.h"
#include "World.h"
CScrollWeenie::CScrollWeenie()
{
@ -109,7 +110,7 @@ void CScrollUseEvent::OnUseAnimSuccess(DWORD motion)
pWeenie->ReleaseFromAnyWeenieParent();
pWeenie->NotifyContainedItemRemoved(target->GetID());
target->MarkForDestroy();
g_pWorld->RemoveEntity(target);
}
}

View file

@ -41,11 +41,11 @@ CSpellProjectile::~CSpellProjectile()
void CSpellProjectile::Tick()
{
if (!m_bDestroyMe)
if (!ShouldDestroy())
{
if (!InValidCell() || (m_fDestroyTime <= Timer::cur_time))
{
MarkForDestroy();
g_pWorld->RemoveEntity(GetPointer<CWeenieObject>());
}
// not destroyed yet and distance/time exceeded
else if (m_fDestroyTime > Timer::cur_time + 10 && (m_Position.distance(m_CachedSpellCastData.initial_cast_position) > m_CachedSpellCastData.max_range || (m_fSpawnTime + MAX_SPELL_PROJECTILE_LIFETIME - 1) <= Timer::cur_time))

View file

@ -1703,11 +1703,18 @@ int CSpellcastingManager::LaunchSpellEffect()
{
for (auto wielded : container->m_Wielded)
{
if (wielded->GetItemType() & m_SpellCastData.spell->_non_component_target_type)
std::shared_ptr<CWeenieObject> pItem = wielded.lock();
if (!pItem)
{
if (castTarget == pWeenie || wielded->parent.lock()) // for other targets, only physically wielded allowed
continue;
}
if (pItem->GetItemType() & m_SpellCastData.spell->_non_component_target_type)
{
if (castTarget == pWeenie || pItem->parent.lock()) // for other targets, only physically wielded allowed
{
targets.push_back(wielded);
targets.push_back(pItem);
}
}
}
@ -1904,11 +1911,18 @@ int CSpellcastingManager::LaunchSpellEffect()
{
for (auto wielded : container->m_Wielded)
{
if (wielded->GetItemType() & m_SpellCastData.spell->_non_component_target_type)
std::shared_ptr<CWeenieObject> pItem = wielded.lock();
if (!pItem)
{
if (member == pWeenie || wielded->parent.lock()) // for other targets, only physically wielded allowed
continue;
}
if (pItem->GetItemType() & m_SpellCastData.spell->_non_component_target_type)
{
if (member == pWeenie || pItem->parent.lock()) // for other targets, only physically wielded allowed
{
targets.push_back(wielded);
targets.push_back(pItem);
}
}
}
@ -3191,9 +3205,16 @@ std::map<DWORD, DWORD> CSpellcastingManager::FindComponentInContainer(std::share
int amountLeftToFind = amountNeeded;
for (auto item : container->m_Items)
{
if (item->InqDIDQuality(SPELL_COMPONENT_DID, 0) == componentId)
std::shared_ptr<CWeenieObject> pItem = item.lock();
if (!pItem)
{
int amount = item->InqIntQuality(STACK_SIZE_INT, 1);
continue;
}
if (pItem->InqDIDQuality(SPELL_COMPONENT_DID, 0) == componentId)
{
int amount = pItem->InqIntQuality(STACK_SIZE_INT, 1);
if (amount > amountLeftToFind)
{
amount = amountLeftToFind;
@ -3201,7 +3222,7 @@ std::map<DWORD, DWORD> CSpellcastingManager::FindComponentInContainer(std::share
}
else
amountLeftToFind -= amount;
foundItems.emplace(item->GetID(), amount);
foundItems.emplace(pItem->GetID(), amount);
if (amountLeftToFind == 0)
return foundItems;
@ -3210,14 +3231,28 @@ std::map<DWORD, DWORD> CSpellcastingManager::FindComponentInContainer(std::share
for (auto packSlot : container->m_Packs)
{
std::shared_ptr<CContainerWeenie> pack = packSlot->AsContainer();
if (pack != NULL)
std::shared_ptr<CWeenieObject> pPack = packSlot.lock();
if (!pPack)
{
continue;
}
std::shared_ptr<CContainerWeenie> pack = pPack->AsContainer();
if (pack)
{
for (auto item : pack->m_Items)
{
if (item->InqDIDQuality(SPELL_COMPONENT_DID, 0) == componentId)
std::shared_ptr<CWeenieObject> pItem = item.lock();
if (!pItem)
{
int amount = item->InqIntQuality(STACK_SIZE_INT, 1);
continue;
}
if (pItem->InqDIDQuality(SPELL_COMPONENT_DID, 0) == componentId)
{
int amount = pItem->InqIntQuality(STACK_SIZE_INT, 1);
if (amount > amountLeftToFind)
{
amount = amountLeftToFind;
@ -3225,7 +3260,7 @@ std::map<DWORD, DWORD> CSpellcastingManager::FindComponentInContainer(std::share
}
else
amountLeftToFind -= amount;
foundItems.emplace(item->GetID(), amount);
foundItems.emplace(pItem->GetID(), amount);
if (amountLeftToFind == 0)
return foundItems;
@ -3243,8 +3278,15 @@ std::shared_ptr<CWeenieObject> CSpellcastingManager::FindFociInContainer(std::sh
{
for (auto pack : container->m_Packs)
{
if (pack->m_Qualities.id == fociWcid)
return pack;
std::shared_ptr<CWeenieObject> pItem = pack.lock();
if (!pItem)
{
continue;
}
if (pItem->m_Qualities.id == fociWcid)
return pItem;
}
return NULL;

View file

@ -1094,7 +1094,7 @@ void CWeenieFactory::AddWeenieToDestination(std::shared_ptr<CWeenieObject> weeni
if (!weenie->IsContained() && !weenie->IsStuck() && weenie->m_Position.objcell_id && !weenie->cell)
{
weenie->MarkForDestroy();
g_pWorld->RemoveEntity(weenie);
return;
}

View file

@ -927,7 +927,7 @@ void CWeenieObject::OnGeneratedDeath(std::shared_ptr<CWeenieObject> weenie)
{
//we're the child of a generator and all our children have been destroyed/picked up.
//so we're done and should cease to exist.
MarkForDestroy();
g_pWorld->RemoveEntity(GetPointer<CWeenieObject>());
//make the leftovers rot.
for each (auto entry in rotList)
@ -1014,7 +1014,7 @@ void CWeenieObject::OnGeneratedPickedUp(std::shared_ptr<CWeenieObject> weenie)
{
//we're the child of a generator and all our children have been destroyed/picked up.
//so we're done and should cease to exist.
MarkForDestroy();
g_pWorld->RemoveEntity(GetPointer<CWeenieObject>());
//make the leftovers rot.
for each (auto entry in rotList)
@ -2921,7 +2921,7 @@ void CWeenieObject::Tick()
{
if ((_timeToRot + 2.0) <= Timer::cur_time)
{
MarkForDestroy();
g_pWorld->RemoveEntity(GetPointer<CWeenieObject>());
}
}
else
@ -5722,7 +5722,14 @@ bool CWeenieObject::TryMagicResist(DWORD magicSkill)
{
for (auto item : AsContainer()->m_Wielded)
{
if (item->GetImbueEffects() & MagicDefense_ImbuedEffectType)
std::shared_ptr<CWeenieObject> pItem = item.lock();
if (!pItem)
{
continue;
}
if (pItem->GetImbueEffects() & MagicDefense_ImbuedEffectType)
defenseSkill += 1;
}
}
@ -6047,7 +6054,14 @@ bool CWeenieObject::TryMissileEvade(DWORD attackSkill)
{
for (auto item : AsContainer()->m_Wielded)
{
if (item->GetImbueEffects() & MissileDefense_ImbuedEffectType)
std::shared_ptr<CWeenieObject> pItem = item.lock();
if (!pItem)
{
continue;
}
if (pItem->GetImbueEffects() & MissileDefense_ImbuedEffectType)
defenseMod += 0.01;
}
}
@ -6357,6 +6371,16 @@ bool CWeenieObject::LearnSpell(DWORD spell_id, bool showTextAndEffect)
return false;
}
void CWeenieObject::MarkForDestroy()
{
m_dDestroyTime = Timer::cur_time;
}
bool CWeenieObject::ShouldDestroy()
{
return m_dDestroyTime > 0 && m_dDestroyTime < Timer::cur_time;
}
void CWeenieObject::Remove()
{
if (IsContained())
@ -6384,8 +6408,8 @@ void CWeenieObject::Remove()
SetWieldedLocation(INVENTORY_LOC::NONE_LOC);
m_Qualities.SetInt(PARENT_LOCATION_INT, 0);
unset_parent();
ReleaseFromBlock();
MarkForDestroy();
g_pWorld->RemoveEntity(GetPointer<CWeenieObject>());
}
void CWeenieObject::DebugValidate()
@ -6539,7 +6563,7 @@ void CWeenieObject::HandleEventInactive()
if (std::shared_ptr<CWeenieObject> spawned_weenie = g_pWorld->FindObject(weenie_id))
{
spawned_weenie->MarkForDestroy();
g_pWorld->RemoveEntity(spawned_weenie);
}
// make sure it's gone (it should be already.)

View file

@ -281,8 +281,8 @@ public:
virtual void TryIdentify(std::shared_ptr<CWeenieObject> other);
virtual void Identify(std::shared_ptr<CWeenieObject> other, DWORD overrideId = 0);
virtual void MarkForDestroy() { m_bDestroyMe = true; }
virtual bool ShouldDestroy() { return m_bDestroyMe; }
virtual void MarkForDestroy();
virtual bool ShouldDestroy();
virtual void Remove();
virtual void DebugValidate();
@ -492,8 +492,8 @@ public:
void TryCancelAttack();
float GetArmorModForDamageType(DAMAGE_TYPE dt);
bool m_bDestroyMe = false;
double m_dDestroyTime = -1;
virtual void WieldedTick();
virtual void InventoryTick();

View file

@ -340,7 +340,7 @@ bool CWorld::CreateEntity(std::shared_ptr<CWeenieObject> pEntity, bool bMakeAwar
else
{
// the caller wants to take control so remove all previous owners
if (bForceTakeControl)
if (true || bForceTakeControl)
{
LOG_PRIVATE(World, Warning, csprintf("Trying to spawn second (different) weenie with existing ID 0x%08X! Deleting OLD instead (%d, %d refs).\n", pEntity->id, pExistingWeenie.use_count()));
pExistingWeenie->Destroy();
@ -361,9 +361,18 @@ bool CWorld::CreateEntity(std::shared_ptr<CWeenieObject> pEntity, bool bMakeAwar
// The dupe is in a corpse!
// Let's assume the corpse was already recovered.
while (pContainer->m_Items.size() > 0)
{
pContainer->m_Items[0]->Remove();
auto i = pContainer->m_Items.begin();
std::shared_ptr<CWeenieObject> pItem = i->lock();
if (!pItem)
{
pContainer->m_Items.erase(i);
continue;
}
pItem->Remove();
}
// Corpse is now empty. We can get rid of it.
@ -956,7 +965,10 @@ void CWorld::RemoveEntity(std::shared_ptr<CWeenieObject> pEntity)
void CWorld::EnsureRemoved(std::shared_ptr<CWeenieObject> pEntity)
{
m_mAllPlayers.erase(pEntity->GetID());
if (m_mAllPlayers.erase(pEntity->GetID()))
{
this->GetNumPlayers();
}
m_mAllObjects.erase(pEntity->GetID());
std::string eventString;

View file

@ -947,7 +947,7 @@ BOOL CWorldLandBlock::Think()
}
else
{
Destroy(pEntity);
g_pWorld->RemoveEntity(pEntity);
}
eit++;