From befe132861b1995dfe776d4e134a90fc243d1a17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dami=C3=A1n=20Imrich?= Date: Thu, 8 Apr 2021 12:24:59 +0200 Subject: cPieceModifier interface and cPieceModifierRandomizeBlocks class (#5122) --- src/Generating/PiecePool.h | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) (limited to 'src/Generating/PiecePool.h') diff --git a/src/Generating/PiecePool.h b/src/Generating/PiecePool.h index 8beaf0c31..5897f32c7 100644 --- a/src/Generating/PiecePool.h +++ b/src/Generating/PiecePool.h @@ -148,12 +148,41 @@ public: typedef std::shared_ptr cVerticalLimitPtr; + /** Base class (interface) for piece modifiers. */ + class cPieceModifier + { + public: + // Force a virtual destructor in descendants + virtual ~cPieceModifier() {} + + /** Initializes the modifier's parameters from the string + representation. a_Params is the string containing only the parameters + If a_LogWarnings is true, logs any problems to the console. + Returns true if successful, false if the string parsing failed. + Used when loading the modifier from a file. */ + virtual bool InitializeFromString(const AString & a_Params, bool a_LogWarnings) = 0; + + /** Called prior to writing piece to a chunk, so that modifiers can modify blocks in the blockarea */ + virtual void Modify(cBlockArea & a_Image, const Vector3i a_PiecePos, const int a_PieceNumRotations) = 0; + + /** Called when the piece pool is assigned to a generator, + so that the modifiers can access world seed. */ + virtual void AssignSeed(int a_Seed) {} + }; + + + typedef std::shared_ptr cPieceModifierPtr; + + typedef std::vector cPieceModifiers; + /** The strategy used for vertical placement of this piece when it is used as a starting piece. */ cVerticalStrategyPtr m_VerticalStrategy; /** The checker that verifies each placement's vertical position. */ cVerticalLimitPtr m_VerticalLimit; + /** The modifiers which are modifying piece's blocks. */ + cPieceModifiers m_Modifiers; /** 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. */ @@ -196,6 +225,11 @@ public: return m_VerticalLimit; } + cPieceModifiers GetModifiers(void) const + { + return m_Modifiers; + } + /** Sets the vertical strategy based on the description in the string. If a_LogWarnings is true, logs the parsing problems into the server console. Returns true if successful, false if strategy parsing failed (no strategy assigned). */ @@ -206,6 +240,12 @@ public: If a_LogWarnings is true, any problem is reported into the server console. */ bool SetVerticalLimitFromString(const AString & a_LimitDesc, bool a_LogWarnings); + /** Sets the modifiers with their params in the string. + If a_LogWarnings is true, logs the parsing problems into the server console. + Returns true if successful, false if strategy parsing failed (no strategy + assigned). */ + bool SetPieceModifiersFromString(const AString & a_Definition, bool a_LogWarnings); + /** Returns a copy of the a_Pos after rotating the piece the specified number of CCW rotations. */ Vector3i RotatePos(const Vector3i & a_Pos, int a_NumCCWRotations) const; -- cgit v1.2.3