23 if (strategy ==
nullptr)
52 auto modifiers = std::make_shared<cPieceModifiers>();
59 for (
size_t i = 0; i < modifiers->size(); i++)
61 Modifiers.push_back(std::move(modifiers->at(i)));
76 switch (a_NumCCWRotations)
91 return Vector3i(Size.
x - a_Pos.
x - 1, a_Pos.
y, Size.
z - a_Pos.
z - 1);
99 ASSERT(!
"Unhandled rotation");
112 switch (a_NumCCWRotations)
155 int a_NumCCWRotations
158 ASSERT(a_NumCCWRotations == (a_NumCCWRotations % 4));
160 ConnPos = a_ToConnectorPos - ConnPos;
170 ASSERT(a_NumCCWRotations == (a_NumCCWRotations % 4));
174 res.
p1.
Move(a_MoveX, a_MoveY, a_MoveZ);
175 res.
p2.
Move(a_MoveX, a_MoveY, a_MoveZ);
187 m_Pos(a_X, a_Y, a_Z),
189 m_Direction(a_Direction)
200 m_Direction(a_Direction)
212 case dirXM:
return Vector3i(a_Pos.
x - 1, a_Pos.
y, a_Pos.
z);
213 case dirXP:
return Vector3i(a_Pos.
x + 1, a_Pos.
y, a_Pos.
z);
214 case dirYM:
return Vector3i(a_Pos.
x, a_Pos.
y - 1, a_Pos.
z);
215 case dirYP:
return Vector3i(a_Pos.
x, a_Pos.
y + 1, a_Pos.
z);
216 case dirZM:
return Vector3i(a_Pos.
x, a_Pos.
y, a_Pos.
z - 1);
217 case dirZP:
return Vector3i(a_Pos.
x, a_Pos.
y, a_Pos.
z + 1);
218 case dirYM_XM_ZM:
return Vector3i(a_Pos.
x, a_Pos.
y - 1, a_Pos.
z);
219 case dirYM_XM_ZP:
return Vector3i(a_Pos.
x, a_Pos.
y - 1, a_Pos.
z);
220 case dirYM_XP_ZM:
return Vector3i(a_Pos.
x, a_Pos.
y - 1, a_Pos.
z);
221 case dirYM_XP_ZP:
return Vector3i(a_Pos.
x, a_Pos.
y - 1, a_Pos.
z);
222 case dirYP_XM_ZM:
return Vector3i(a_Pos.
x, a_Pos.
y + 1, a_Pos.
z);
223 case dirYP_XM_ZP:
return Vector3i(a_Pos.
x, a_Pos.
y + 1, a_Pos.
z);
224 case dirYP_XP_ZM:
return Vector3i(a_Pos.
x, a_Pos.
y + 1, a_Pos.
z);
225 case dirYP_XP_ZP:
return Vector3i(a_Pos.
x, a_Pos.
y + 1, a_Pos.
z);
238 case dirXM:
return "x-";
239 case dirXP:
return "x+";
240 case dirYM:
return "y-";
241 case dirYP:
return "y+";
242 case dirZM:
return "z-";
243 case dirZP:
return "z+";
244 case dirYM_XM_ZM:
return "y-x-z-";
245 case dirYM_XM_ZP:
return "y-x-z+";
246 case dirYM_XP_ZM:
return "y-x+z-";
247 case dirYM_XP_ZP:
return "y-x+z+";
248 case dirYP_XM_ZM:
return "y+x-z-";
249 case dirYP_XM_ZP:
return "y+x-z+";
250 case dirYP_XP_ZM:
return "y+x+z-";
251 case dirYP_XP_ZP:
return "y+x+z+";
294 case dirXM:
return dirXP;
295 case dirXP:
return dirXM;
296 case dirYM:
return dirYM;
297 case dirYP:
return dirYP;
298 case dirZM:
return dirZM;
299 case dirZP:
return dirZP;
300 case dirYM_XM_ZM:
return dirYM_XP_ZP;
301 case dirYM_XM_ZP:
return dirYM_XP_ZM;
302 case dirYM_XP_ZM:
return dirYM_XM_ZP;
303 case dirYM_XP_ZP:
return dirYM_XM_ZM;
304 case dirYP_XM_ZM:
return dirYP_XP_ZP;
305 case dirYP_XM_ZP:
return dirYP_XP_ZM;
306 case dirYP_XP_ZM:
return dirYP_XM_ZP;
307 case dirYP_XP_ZP:
return dirYP_XM_ZM;
321 case dirXM:
return dirZP;
322 case dirXP:
return dirZM;
323 case dirYM:
return dirYM;
324 case dirYP:
return dirYP;
325 case dirZM:
return dirXM;
326 case dirZP:
return dirXP;
327 case dirYM_XM_ZM:
return dirYM_XM_ZP;
328 case dirYM_XM_ZP:
return dirYM_XP_ZP;
329 case dirYM_XP_ZM:
return dirYM_XM_ZM;
330 case dirYM_XP_ZP:
return dirYM_XP_ZM;
331 case dirYP_XM_ZM:
return dirYP_XM_ZP;
332 case dirYP_XM_ZP:
return dirYP_XP_ZP;
333 case dirYP_XP_ZM:
return dirYP_XM_ZM;
334 case dirYP_XP_ZP:
return dirYP_XP_ZM;
348 case dirXM:
return dirZM;
349 case dirXP:
return dirZP;
350 case dirYM:
return dirYM;
351 case dirYP:
return dirYP;
352 case dirZM:
return dirXP;
353 case dirZP:
return dirXM;
354 case dirYM_XM_ZM:
return dirYM_XP_ZM;
355 case dirYM_XM_ZP:
return dirYM_XM_ZM;
356 case dirYM_XP_ZM:
return dirYM_XP_ZP;
357 case dirYM_XP_ZP:
return dirYM_XM_ZP;
358 case dirYP_XM_ZM:
return dirYP_XP_ZM;
359 case dirYP_XM_ZP:
return dirYP_XM_ZM;
360 case dirYP_XP_ZM:
return dirYP_XP_ZP;
361 case dirYP_XP_ZP:
return dirYP_XM_ZP;
375 static const int DirectionRotationTable[14][14] =
378 { 0, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
379 {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1},
380 {-1, -1, 2, 0, 1, 3, -1, -1, -1, -1, -1, -1, -1, -1},
381 {-1, -1, 0, 2, 3, 1, -1, -1, -1, -1, -1, -1, -1, -1},
382 {-1, -1, 3, 1, 2, 0, -1, -1, -1, -1, -1, -1, -1, -1},
383 {-1, -1, 1, 3, 0, 2, -1, -1, -1, -1, -1, -1, -1, -1},
384 {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 0, 3, 1, 2},
385 {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 1, 0, 2, 3},
386 {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 3, 2, 0, 1},
387 {-1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 2, 1, 3, 0},
388 {-1, -1, -1, -1, -1, -1, 0, 3, 1, 2, -1, -1, -1, -1},
389 {-1, -1, -1, -1, -1, -1, 1, 0, 2, 3, -1, -1, -1, -1},
390 {-1, -1, -1, -1, -1, -1, 3, 2, 0, 1, -1, -1, -1, -1},
391 {-1, -1, -1, -1, -1, -1, 2, 1, 3, 0, -1, -1, -1, -1},
394 return DirectionRotationTable[a_FixedDir][a_RotatingDir];
407 if (!IsValidDirection(dirInt))
420 } StringDirections[] =
428 {
"y-x-z-", dirYM_XM_ZM},
429 {
"y-x-z+", dirYM_XM_ZP},
430 {
"y-x+z-", dirYM_XP_ZM},
431 {
"y-x+z+", dirYM_XP_ZP},
432 {
"y+x-z-", dirYP_XM_ZM},
433 {
"y+x-z+", dirYP_XM_ZP},
434 {
"y+x+z-", dirYP_XP_ZM},
435 {
"y+x+z+", dirYP_XP_ZP},
438 {
"y-/x-/z-", dirYM_XM_ZM},
439 {
"y-/x-/z+", dirYM_XM_ZP},
440 {
"y-/x+/z-", dirYM_XP_ZM},
441 {
"y-/x+/z+", dirYM_XP_ZP},
442 {
"y+/x-/z-", dirYP_XM_ZM},
443 {
"y+/x-/z+", dirYP_XM_ZP},
444 {
"y+/x+/z-", dirYP_XP_ZM},
445 {
"y+/x+/z+", dirYP_XP_ZP},
448 for (
size_t i = 0; i <
ARRAYCOUNT(StringDirections); i++)
450 if (strcmp(lcValue.c_str(), StringDirections[i].m_String) == 0)
452 a_Out = StringDirections[i].m_Value;
472 m_NumCCWRotations(a_NumCCWRotations),
473 m_HasBeenMovedToGround(false)
487 ASSERT(Connectors.size() >= a_Index);
bool CreatePieceModifierFromString(const AString &a_Definition, std::shared_ptr< cPiece::cPieceModifiers > &a_Modifiers, bool a_LogWarnings)
cPiece::cVerticalLimitPtr CreateVerticalLimitFromString(const AString &a_LimitDesc, bool a_LogWarnings)
Returns a new cPiece::cVerticalLimit descendant based on the specified description.
cPiece::cVerticalStrategyPtr CreateVerticalStrategyFromString(const AString &a_StrategyDesc, bool a_LogWarnings)
Returns a new cPiece::cVerticalStrategy descendant based on the specified description.
#define ARRAYCOUNT(X)
Evaluates to the number of elements in an array (compile-time!)
AString StrToLower(const AString &s)
Returns a lower-cased copy of the string.
bool StringToInteger(const AString &a_str, T &a_Num)
Parses any integer type.
Represents a single piece.
virtual cCuboid GetHitBox(void) const =0
Returns the "hitbox" of this piece.
virtual cConnectors GetConnectors(void) const =0
Returns all of the available connectors that the piece has.
cCuboid RotateMoveHitBox(int a_NumCCWRotations, int a_MoveX, int a_MoveY, int a_MoveZ) const
Returns the hitbox after the specified number of CCW rotations and moved by the specified amounts.
cVerticalStrategyPtr m_VerticalStrategy
The strategy used for vertical placement of this piece when it is used as a starting piece.
cCuboid RotateHitBoxToConnector(const cConnector &a_MyConnector, const Vector3i &a_ToConnectorPos, int a_NumCCWRotations) const
Returns the hitbox after the specified number of rotations and moved so that a_MyConnector is placed ...
bool SetVerticalStrategyFromString(const AString &a_StrategyDesc, bool a_LogWarnings)
Sets the vertical strategy based on the description in the string.
cPieceModifiers m_Modifiers
The modifiers which are modifying piece's blocks.
virtual Vector3i GetSize(void) const =0
Returns the dimensions of this piece.
cVerticalLimitPtr m_VerticalLimit
The checker that verifies each placement's vertical position.
bool SetVerticalLimitFromString(const AString &a_LimitDesc, bool a_LogWarnings)
Sets the vertical limit based on the description string.
Vector3i RotatePos(const Vector3i &a_Pos, int a_NumCCWRotations) const
Returns a copy of the a_Pos after rotating the piece the specified number of CCW rotations.
bool SetPieceModifiersFromString(const AString &a_Definition, bool a_LogWarnings)
Sets the modifiers with their params in the string.
cConnector RotateMoveConnector(const cConnector &a_Connector, int a_NumCCWRotations, int a_MoveX, int a_MoveY, int a_MoveZ) const
Returns a copy of the connector that is rotated and then moved by the specified amounts.
std::vector< cConnector > cConnectors
std::vector< cPieceModifierPtr > cPieceModifiers
cConnector(int a_X, int a_Y, int a_Z, int a_Type, eDirection a_Direction)
static int GetNumCCWRotationsToFit(eDirection a_FixedDir, eDirection a_RotatingDir)
Returns the number of CCW rotations that a_RotatingDir requires in order to be the counter-direction ...
static eDirection RotateDirectionCCW(eDirection a_Direction)
Returns the direction corresponding to the given direction rotated 90 degrees CCW around the Y axis.
static eDirection RotateDirection(eDirection a_Direction)
Returns the direction corresponding to the given direction rotated 180 degrees around the Y axis.
Vector3i m_Pos
Position relative to the piece.
static bool StringToDirection(const AString &a_Value, eDirection &a_Out)
Converts the string representation of a direction into the eDirection enum value.
eDirection m_Direction
Direction in which the connector is facing.
static const char * DirectionToString(eDirection a_Direction)
Returns the string representation of the direction.
static Vector3i AddDirection(const Vector3i &a_Pos, eDirection a_Direction)
Returns the position of the block that has the specified direction from the specified position.
static bool IsValidDirection(int a_Direction)
Returns true if the specified number corresponds to a valid eDirection.
static eDirection RotateDirectionCW(eDirection a_Direction)
Returns the direction corresponding to the given direction rotated 90 degrees CW around the Y axis.
Represents a single piece that has been placed to specific coords in the world.
void MoveToGroundBy(int a_OffsetY)
Moves the placed piece Y-wise by the specified offset.
cPlacedPiece(const cPlacedPiece *a_Parent, const cPiece &a_Piece, const Vector3i &a_Coords, int a_NumCCWRotations)
cPiece::cConnector GetRotatedConnector(size_t a_Index) const
Returns the connector at the specified index, rotated in the actual placement.
const cPlacedPiece * m_Parent
bool m_HasBeenMovedToGround
Set to true once the piece has been moved Y-wise.
void Move(T a_X, T a_Y, T a_Z)