Cuberite
A lightweight, fast and extensible game server for Minecraft
Classes | Public Types | Public Member Functions | Protected Types | Protected Member Functions | Protected Attributes | List of all members
cPrefab Class Reference

#include <Prefab.h>

Inheritance diagram for cPrefab:
Inheritance graph
[legend]
Collaboration diagram for cPrefab:
Collaboration graph
[legend]

Classes

struct  sBlockTypeDef
 Packs complete definition of a single block, for per-letter assignment. More...
 
struct  sDef
 

Public Types

enum  eExtendFloorStrategy { efsNone , efsRepeatBottomTillNonAir , efsRepeatBottomTillSolid }
 How to handle the space between the prefab bottom and the terrain top. More...
 
- Public Types inherited from cPiece
typedef std::vector< cConnectorcConnectors
 
typedef std::shared_ptr< cPieceModifiercPieceModifierPtr
 
typedef std::vector< cPieceModifierPtrcPieceModifiers
 
typedef std::shared_ptr< cVerticalLimitcVerticalLimitPtr
 
typedef std::shared_ptr< cVerticalStrategycVerticalStrategyPtr
 

Public Member Functions

void AddConnector (int a_RelX, int a_RelY, int a_RelZ, cPiece::cConnector::eDirection a_Direction, int a_Type)
 Adds the specified connector to the list of connectors this piece supports. More...
 
 cPrefab (const AString &a_BlockDefinitions, const AString &a_BlockData, int a_SizeX, int a_SizeY, int a_SizeZ)
 Creates a prefab based on the specified block data, using the char-to-block map in a_BlockDefinitions. More...
 
 cPrefab (const cBlockArea &a_Image)
 Creates a prefab based on the given BlockArea. More...
 
 cPrefab (const cBlockArea &a_Image, int a_AllowedRotations)
 Creates a prefab based on the given BlockArea and allowed rotations. More...
 
 cPrefab (const sDef &a_Def)
 Creates a prefab from the provided definition. More...
 
void Draw (cChunkDesc &a_Dest, const cPlacedPiece *a_Placement) const
 Draws the prefab into the specified chunk, according to the placement stored in the PlacedPiece. More...
 
void Draw (cChunkDesc &a_Dest, const Vector3i &a_Placement, int a_NumRotations) const
 Draws the prefab into the specified chunks, according to the specified placement and rotations. More...
 
int GetDefaultWeight (void) const
 Returns the unmodified DefaultWeight property for the piece. More...
 
int GetPieceWeight (const cPlacedPiece &a_PlacedPiece, const cPiece::cConnector &a_ExistingConnector) const
 Returns the weight (chance) of this prefab generating as the next piece after the specified placed piece. More...
 
bool HasConnectorType (int a_ConnectorType) const
 Returns true if the prefab has any connector of the specified type. More...
 
void ParseDepthWeight (const char *a_DepthWeightDef)
 Parses the per-depth weight into m_DepthWeight member. More...
 
void SetAddWeightIfSame (int a_AddWeightIfSame)
 Sets the AddWeightIfSame member, that is used to modify the weight when the previous piece is the same prefab. More...
 
void SetAllowedRotations (int a_AllowedRotations)
 Sets the m_AllowedRotations bitmask and fills the m_BlockArea[] with rotated versions of m_BlockArea[0]. More...
 
void SetDefaultWeight (int a_DefaultWeight)
 Sets the (unmodified) DefaultWeight property for this piece. More...
 
void SetExtendFloorStrategy (eExtendFloorStrategy a_Strategy)
 Sets the strategy to use between the bottom of the prefab and the terrain top. More...
 
void SetHitBox (const cCuboid &a_HitBox)
 Sets the internal hitbox to the specified value. More...
 
void SetMergeStrategy (cBlockArea::eMergeStrategy a_MergeStrategy)
 Sets the merge strategy to be used when drawing the piece. More...
 
void SetMoveToGround (bool a_MoveToGround)
 Sets the flag whether the prefab should be moved to ground level before being drawn. More...
 
bool ShouldMoveToGround (void) const
 Returns whether the prefab should be moved Y-wise to ground before drawing, rather than staying at the coords governed by the connectors. More...
 
- Public Member Functions inherited from cPiece
cPieceModifiers GetModifiers (void) const
 
int GetStartingPieceHeight (int a_BlockX, int a_BlockZ)
 Returns the height, based on m_VerticalStrategy, for this piece when used as the starting piece. More...
 
cVerticalLimitPtr GetVerticalLimit (void) const
 
cVerticalStrategyPtr GetVerticalStrategy (void) const
 
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 at a_ToConnectorPos. More...
 
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. More...
 
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. More...
 
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. More...
 
bool SetPieceModifiersFromString (const AString &a_Definition, bool a_LogWarnings)
 Sets the modifiers with their params in the string. More...
 
bool SetVerticalLimitFromString (const AString &a_LimitDesc, bool a_LogWarnings)
 Sets the vertical limit based on the description string. More...
 
void SetVerticalStrategy (cVerticalStrategyPtr a_VerticalStrategy)
 
bool SetVerticalStrategyFromString (const AString &a_StrategyDesc, bool a_LogWarnings)
 Sets the vertical strategy based on the description in the string. More...
 
virtual ~cPiece ()
 

Protected Types

typedef std::map< int, int > cDepthWeight
 Maps generator tree depth to weight. More...
 
typedef sBlockTypeDef CharMap[256]
 Maps letters in the sDef::m_Image onto a sBlockTypeDef block type definition. More...
 

Protected Member Functions

void AddRotatedBlockAreas (void)
 Based on the m_AllowedRotations, adds rotated cBlockAreas to the m_BlockArea array. More...
 
virtual bool CanRotateCCW (int a_NumRotations) const override
 Returns true if the piece can be rotated CCW the specific number of 90-degree turns. More...
 
virtual cConnectors GetConnectors (void) const override
 Returns all of the available connectors that the piece has. More...
 
virtual cCuboid GetHitBox (void) const override
 Returns the "hitbox" of this piece. More...
 
virtual Vector3i GetSize (void) const override
 Returns the dimensions of this piece. More...
 
void ParseBlockImage (const CharMap &a_CharMap, const char *a_BlockImage)
 Parses the Image in the definition into m_BlockArea[0]'s block types and metas, using the specified CharMap. More...
 
void ParseCharMap (CharMap &a_CharMapOut, const char *a_CharMapDef)
 Parses the CharMap in the definition into a CharMap binary data used for translating the definition into BlockArea. More...
 
void ParseConnectors (const char *a_ConnectorsDef)
 Parses the connectors definition text into m_Connectors member. More...
 

Protected Attributes

int m_AddWeightIfSame
 The weight to add to this piece's base per-depth chance if the previous piece is the same. More...
 
int m_AllowedRotations
 Bitmask, bit N set -> N rotations CCW supported. More...
 
cBlockArea m_BlockArea [4]
 The cBlockArea that contains the block definitions for the prefab. More...
 
cConnectors m_Connectors
 The connectors through which the piece connects to other pieces. More...
 
int m_DefaultWeight
 Chance of this piece being used, if no other modifier is active. More...
 
cDepthWeight m_DepthWeight
 Chances of this piece being used, per depth of the generated piece tree. More...
 
eExtendFloorStrategy m_ExtendFloorStrategy
 How the prefab should handle not being on top of the ground. More...
 
cCuboid m_HitBox
 The hitbox used for collision-checking between prefabs. More...
 
cBlockArea::eMergeStrategy m_MergeStrategy
 The merge strategy to use when drawing the prefab into a block area. More...
 
bool m_MoveToGround
 If true, the piece will be moved Y-wise so that its first connector is sitting on the terrain. More...
 
Vector3i m_Size
 The size of the prefab. More...
 

Additional Inherited Members

- Public Attributes inherited from cPiece
cPieceModifiers m_Modifiers
 The modifiers which are modifying piece's blocks. More...
 
cVerticalLimitPtr m_VerticalLimit
 The checker that verifies each placement's vertical position. More...
 
cVerticalStrategyPtr m_VerticalStrategy
 The strategy used for vertical placement of this piece when it is used as a starting piece. More...
 

Detailed Description

Definition at line 31 of file Prefab.h.

Member Typedef Documentation

◆ cDepthWeight

typedef std::map<int, int> cPrefab::cDepthWeight
protected

Maps generator tree depth to weight.

Definition at line 171 of file Prefab.h.

◆ CharMap

typedef sBlockTypeDef cPrefab::CharMap[256]
protected

Maps letters in the sDef::m_Image onto a sBlockTypeDef block type definition.

Definition at line 168 of file Prefab.h.

Member Enumeration Documentation

◆ eExtendFloorStrategy

How to handle the space between the prefab bottom and the terrain top.

Enumerator
efsNone 

No processing, the prefab is left "floating in the air".

efsRepeatBottomTillNonAir 

Repeat the bottom-most block down until the first non-air block.

efsRepeatBottomTillSolid 

Repeat the bottom-most block down until the first solid block; non-solids are overwritten.

Definition at line 36 of file Prefab.h.

Constructor & Destructor Documentation

◆ cPrefab() [1/4]

cPrefab::cPrefab ( const sDef a_Def)

Creates a prefab from the provided definition.

Definition at line 19 of file Prefab.cpp.

◆ cPrefab() [2/4]

cPrefab::cPrefab ( const cBlockArea a_Image,
int  a_AllowedRotations 
)

Creates a prefab based on the given BlockArea and allowed rotations.

Definition at line 46 of file Prefab.cpp.

◆ cPrefab() [3/4]

cPrefab::cPrefab ( const cBlockArea a_Image)

Creates a prefab based on the given BlockArea.

Allowed rotations can be added later on using SetAllowedRotations().

Definition at line 65 of file Prefab.cpp.

◆ cPrefab() [4/4]

cPrefab::cPrefab ( const AString a_BlockDefinitions,
const AString a_BlockData,
int  a_SizeX,
int  a_SizeY,
int  a_SizeZ 
)

Creates a prefab based on the specified block data, using the char-to-block map in a_BlockDefinitions.

Allowed rotations can be added later on using SetAllowedRotations().

Definition at line 83 of file Prefab.cpp.

Member Function Documentation

◆ AddConnector()

void cPrefab::AddConnector ( int  a_RelX,
int  a_RelY,
int  a_RelZ,
cPiece::cConnector::eDirection  a_Direction,
int  a_Type 
)

Adds the specified connector to the list of connectors this piece supports.

Definition at line 320 of file Prefab.cpp.

◆ AddRotatedBlockAreas()

void cPrefab::AddRotatedBlockAreas ( void  )
protected

Based on the m_AllowedRotations, adds rotated cBlockAreas to the m_BlockArea array.

To be called only from this class's constructor!

Definition at line 104 of file Prefab.cpp.

◆ CanRotateCCW()

bool cPrefab::CanRotateCCW ( int  a_NumRotations) const
overrideprotectedvirtual

Returns true if the piece can be rotated CCW the specific number of 90-degree turns.

Implements cPiece.

Definition at line 521 of file Prefab.cpp.

◆ Draw() [1/2]

void cPrefab::Draw ( cChunkDesc a_Dest,
const cPlacedPiece a_Placement 
) const

Draws the prefab into the specified chunk, according to the placement stored in the PlacedPiece.

Definition at line 133 of file Prefab.cpp.

◆ Draw() [2/2]

void cPrefab::Draw ( cChunkDesc a_Dest,
const Vector3i a_Placement,
int  a_NumRotations 
) const

Draws the prefab into the specified chunks, according to the specified placement and rotations.

Definition at line 142 of file Prefab.cpp.

◆ GetConnectors()

cPiece::cConnectors cPrefab::GetConnectors ( void  ) const
overrideprotectedvirtual

Returns all of the available connectors that the piece has.

Each connector has a (relative) position in the piece, and a type associated with it.

Implements cPiece.

Definition at line 494 of file Prefab.cpp.

◆ GetDefaultWeight()

int cPrefab::GetDefaultWeight ( void  ) const
inline

Returns the unmodified DefaultWeight property for the piece.

Definition at line 129 of file Prefab.h.

◆ GetHitBox()

cCuboid cPrefab::GetHitBox ( void  ) const
overrideprotectedvirtual

Returns the "hitbox" of this piece.

A hitbox is what is compared and must not intersect other pieces' hitboxes when generating.

Implements cPiece.

Definition at line 512 of file Prefab.cpp.

◆ GetPieceWeight()

int cPrefab::GetPieceWeight ( const cPlacedPiece a_PlacedPiece,
const cPiece::cConnector a_ExistingConnector 
) const

Returns the weight (chance) of this prefab generating as the next piece after the specified placed piece.

PiecePool implementations can use this for their GetPieceWeight() implementations.

Definition at line 291 of file Prefab.cpp.

◆ GetSize()

Vector3i cPrefab::GetSize ( void  ) const
overrideprotectedvirtual

Returns the dimensions of this piece.

The dimensions cover the entire piece, there is no block that the piece generates outside of this size.

Implements cPiece.

Definition at line 503 of file Prefab.cpp.

◆ HasConnectorType()

bool cPrefab::HasConnectorType ( int  a_ConnectorType) const

Returns true if the prefab has any connector of the specified type.

Definition at line 275 of file Prefab.cpp.

◆ ParseBlockImage()

void cPrefab::ParseBlockImage ( const CharMap a_CharMap,
const char *  a_BlockImage 
)
protected

Parses the Image in the definition into m_BlockArea[0]'s block types and metas, using the specified CharMap.

Definition at line 378 of file Prefab.cpp.

◆ ParseCharMap()

void cPrefab::ParseCharMap ( CharMap a_CharMapOut,
const char *  a_CharMapDef 
)
protected

Parses the CharMap in the definition into a CharMap binary data used for translating the definition into BlockArea.

Definition at line 339 of file Prefab.cpp.

◆ ParseConnectors()

void cPrefab::ParseConnectors ( const char *  a_ConnectorsDef)
protected

Parses the connectors definition text into m_Connectors member.

Definition at line 400 of file Prefab.cpp.

◆ ParseDepthWeight()

void cPrefab::ParseDepthWeight ( const char *  a_DepthWeightDef)

Parses the per-depth weight into m_DepthWeight member.

Definition at line 446 of file Prefab.cpp.

◆ SetAddWeightIfSame()

void cPrefab::SetAddWeightIfSame ( int  a_AddWeightIfSame)
inline

Sets the AddWeightIfSame member, that is used to modify the weight when the previous piece is the same prefab.

Definition at line 132 of file Prefab.h.

◆ SetAllowedRotations()

void cPrefab::SetAllowedRotations ( int  a_AllowedRotations)

Sets the m_AllowedRotations bitmask and fills the m_BlockArea[] with rotated versions of m_BlockArea[0].

Definition at line 329 of file Prefab.cpp.

◆ SetDefaultWeight()

void cPrefab::SetDefaultWeight ( int  a_DefaultWeight)

Sets the (unmodified) DefaultWeight property for this piece.

Definition at line 311 of file Prefab.cpp.

◆ SetExtendFloorStrategy()

void cPrefab::SetExtendFloorStrategy ( eExtendFloorStrategy  a_Strategy)
inline

Sets the strategy to use between the bottom of the prefab and the terrain top.

Definition at line 154 of file Prefab.h.

◆ SetHitBox()

void cPrefab::SetHitBox ( const cCuboid a_HitBox)
inline

Sets the internal hitbox to the specified value.

Definition at line 157 of file Prefab.h.

◆ SetMergeStrategy()

void cPrefab::SetMergeStrategy ( cBlockArea::eMergeStrategy  a_MergeStrategy)
inline

Sets the merge strategy to be used when drawing the piece.

Definition at line 148 of file Prefab.h.

◆ SetMoveToGround()

void cPrefab::SetMoveToGround ( bool  a_MoveToGround)
inline

Sets the flag whether the prefab should be moved to ground level before being drawn.

Definition at line 151 of file Prefab.h.

◆ ShouldMoveToGround()

bool cPrefab::ShouldMoveToGround ( void  ) const
inline

Returns whether the prefab should be moved Y-wise to ground before drawing, rather than staying at the coords governed by the connectors.

Definition at line 139 of file Prefab.h.

Member Data Documentation

◆ m_AddWeightIfSame

int cPrefab::m_AddWeightIfSame
protected

The weight to add to this piece's base per-depth chance if the previous piece is the same.

Can be positive or negative. This is used e. g. to make nether bridges prefer spanning multiple segments or to penalize turrets next to each other.

Definition at line 210 of file Prefab.h.

◆ m_AllowedRotations

int cPrefab::m_AllowedRotations
protected

Bitmask, bit N set -> N rotations CCW supported.

Definition at line 188 of file Prefab.h.

◆ m_BlockArea

cBlockArea cPrefab::m_BlockArea[4]
protected

The cBlockArea that contains the block definitions for the prefab.

The index identifies the number of CCW rotations applied (0 = no rotation, 1 = 1 CCW rotation, ...).

Definition at line 176 of file Prefab.h.

◆ m_Connectors

cConnectors cPrefab::m_Connectors
protected

The connectors through which the piece connects to other pieces.

Definition at line 185 of file Prefab.h.

◆ m_DefaultWeight

int cPrefab::m_DefaultWeight
protected

Chance of this piece being used, if no other modifier is active.

Definition at line 198 of file Prefab.h.

◆ m_DepthWeight

cDepthWeight cPrefab::m_DepthWeight
protected

Chances of this piece being used, per depth of the generated piece tree.

The starting piece has a depth of 0, the pieces connected to it are depth 1, etc. The specified depth stands for the depth of the new piece (not the existing already-placed piece), so valid depths start at 1. Depths that are not specified will use the m_DefaultWeight value.

Definition at line 205 of file Prefab.h.

◆ m_ExtendFloorStrategy

eExtendFloorStrategy cPrefab::m_ExtendFloorStrategy
protected

How the prefab should handle not being on top of the ground.

This is used for houses to be "on the ground", as well as nether fortresses not to float.

Definition at line 195 of file Prefab.h.

◆ m_HitBox

cCuboid cPrefab::m_HitBox
protected

The hitbox used for collision-checking between prefabs.

Definition at line 182 of file Prefab.h.

◆ m_MergeStrategy

cBlockArea::eMergeStrategy cPrefab::m_MergeStrategy
protected

The merge strategy to use when drawing the prefab into a block area.

Definition at line 191 of file Prefab.h.

◆ m_MoveToGround

bool cPrefab::m_MoveToGround
protected

If true, the piece will be moved Y-wise so that its first connector is sitting on the terrain.

This is used e. g. for village houses.

Definition at line 214 of file Prefab.h.

◆ m_Size

Vector3i cPrefab::m_Size
protected

The size of the prefab.

Definition at line 179 of file Prefab.h.


The documentation for this class was generated from the following files: