2014-05-07 05:01:30 -04:00
|
|
|
|
|
|
|
// PrefabPiecePool.cpp
|
|
|
|
|
|
|
|
// Implements the cPrefabPiecePool class that represents a cPiecePool descendant that uses cPrefab instances as the pieces
|
|
|
|
|
|
|
|
#include "Globals.h"
|
|
|
|
#include "PrefabPiecePool.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cPrefabPiecePool::cPrefabPiecePool(
|
|
|
|
const cPrefab::sDef * a_PieceDefs, size_t a_NumPieceDefs,
|
|
|
|
const cPrefab::sDef * a_StartingPieceDefs, size_t a_NumStartingPieceDefs
|
|
|
|
)
|
|
|
|
{
|
|
|
|
AddPieceDefs(a_PieceDefs, a_NumPieceDefs);
|
2014-10-20 16:55:07 -04:00
|
|
|
if (a_StartingPieceDefs != nullptr)
|
2014-05-07 05:01:30 -04:00
|
|
|
{
|
|
|
|
AddStartingPieceDefs(a_StartingPieceDefs, a_NumStartingPieceDefs);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-05-28 10:33:10 -04:00
|
|
|
cPrefabPiecePool::~cPrefabPiecePool()
|
|
|
|
{
|
|
|
|
Clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cPrefabPiecePool::Clear(void)
|
|
|
|
{
|
|
|
|
m_PiecesByConnector.clear();
|
|
|
|
for (cPieces::iterator itr = m_AllPieces.begin(), end = m_AllPieces.end(); itr != end; ++itr)
|
|
|
|
{
|
|
|
|
delete *itr;
|
|
|
|
}
|
|
|
|
m_AllPieces.clear();
|
|
|
|
for (cPieces::iterator itr = m_StartingPieces.begin(), end = m_StartingPieces.end(); itr != end; ++itr)
|
|
|
|
{
|
|
|
|
delete *itr;
|
|
|
|
}
|
|
|
|
m_StartingPieces.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-05-07 05:01:30 -04:00
|
|
|
void cPrefabPiecePool::AddPieceDefs(const cPrefab::sDef * a_PieceDefs, size_t a_NumPieceDefs)
|
|
|
|
{
|
2014-10-20 16:55:07 -04:00
|
|
|
ASSERT(a_PieceDefs != nullptr);
|
2014-05-07 05:01:30 -04:00
|
|
|
for (size_t i = 0; i < a_NumPieceDefs; i++)
|
|
|
|
{
|
|
|
|
cPrefab * Prefab = new cPrefab(a_PieceDefs[i]);
|
|
|
|
m_AllPieces.push_back(Prefab);
|
|
|
|
AddToPerConnectorMap(Prefab);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cPrefabPiecePool::AddStartingPieceDefs(const cPrefab::sDef * a_StartingPieceDefs, size_t a_NumStartingPieceDefs)
|
|
|
|
{
|
2014-10-20 16:55:07 -04:00
|
|
|
ASSERT(a_StartingPieceDefs != nullptr);
|
2014-05-07 05:01:30 -04:00
|
|
|
for (size_t i = 0; i < a_NumStartingPieceDefs; i++)
|
|
|
|
{
|
|
|
|
cPrefab * Prefab = new cPrefab(a_StartingPieceDefs[i]);
|
|
|
|
m_StartingPieces.push_back(Prefab);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cPrefabPiecePool::AddToPerConnectorMap(cPrefab * a_Prefab)
|
|
|
|
{
|
|
|
|
cPiece::cConnectors Connectors = ((const cPiece *)a_Prefab)->GetConnectors();
|
|
|
|
for (cPiece::cConnectors::const_iterator itr = Connectors.begin(), end = Connectors.end(); itr != end; ++itr)
|
|
|
|
{
|
|
|
|
m_PiecesByConnector[itr->m_Type].push_back(a_Prefab);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cPieces cPrefabPiecePool::GetPiecesWithConnector(int a_ConnectorType)
|
|
|
|
{
|
|
|
|
return m_PiecesByConnector[a_ConnectorType];
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
cPieces cPrefabPiecePool::GetStartingPieces(void)
|
|
|
|
{
|
|
|
|
if (m_StartingPieces.empty())
|
|
|
|
{
|
|
|
|
return m_AllPieces;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return m_StartingPieces;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int cPrefabPiecePool::GetPieceWeight(const cPlacedPiece & a_PlacedPiece, const cPiece::cConnector & a_ExistingConnector, const cPiece & a_NewPiece)
|
|
|
|
{
|
|
|
|
return ((const cPrefab &)a_NewPiece).GetPieceWeight(a_PlacedPiece, a_ExistingConnector);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-05-27 16:05:50 -04:00
|
|
|
int cPrefabPiecePool::GetStartingPieceWeight(const cPiece & a_NewPiece)
|
|
|
|
{
|
|
|
|
return ((const cPrefab &)a_NewPiece).GetDefaultWeight();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-05-07 05:01:30 -04:00
|
|
|
void cPrefabPiecePool::PiecePlaced(const cPiece & a_Piece)
|
|
|
|
{
|
|
|
|
// Do nothing
|
|
|
|
UNUSED(a_Piece);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void cPrefabPiecePool::Reset(void)
|
|
|
|
{
|
|
|
|
// Do nothing
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|