1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
|
// 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);
if (a_StartingPieceDefs != NULL)
{
AddStartingPieceDefs(a_StartingPieceDefs, a_NumStartingPieceDefs);
}
}
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();
}
void cPrefabPiecePool::AddPieceDefs(const cPrefab::sDef * a_PieceDefs, size_t a_NumPieceDefs)
{
ASSERT(a_PieceDefs != NULL);
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)
{
ASSERT(a_StartingPieceDefs != NULL);
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);
}
void cPrefabPiecePool::PiecePlaced(const cPiece & a_Piece)
{
// Do nothing
UNUSED(a_Piece);
}
void cPrefabPiecePool::Reset(void)
{
// Do nothing
}
|