#pragma once #include "EventListener.h" #include "BlockType.h" #include "ReferenceCounter.h" #include "EventThrower.h" #include "Item.h" #include #include class BlockType; class ItemType; class Chunk; class BasicBlockItemType; enum Direction { NORTH, EAST, SOUTH, WEST, TOP, BOTTOM, DIRECTION_COUNT }; class TickQueue; class Block : public virtual Framework::ReferenceCounter { private: BlockType *type; int ticksLeftCounter; int currentTickTimeout; bool wasTicked; bool onTickCalled; protected: bool transparent; bool passable; float hp; float maxHP; float hardness; BlockType *zType; ItemType *zTool; float speedModifier; Block *neighbours[ DIRECTION_COUNT ]; Framework::Vec3 pos; int minTickTimeout; int maxTickTimeout; bool tickSource; /// /// executes block specific things /// /// a queue to add neighbor blocks that should be ticked after this block /// the number of ticks passed since the last call (only for tickSources) /// can be set to one to tell that this block needs to be tickt again later in the queue of this tick /// true, iff the block needs to be ticked more often virtual bool onTick( TickQueue *zQueue, int numTicks, bool &blocked ) = 0; /// /// gets called after each block was tickt. /// the order of blocks called will be exactly the same as onTick /// virtual void onPostTick() = 0; public: Block( BlockType *zType, ItemType *zTool, Framework::Vec3 pos ); void tick( TickQueue *zQueue ); void postTick(); bool isTickSource() const; BlockType *zBlockType() const; bool isTransparent() const; bool isPassable() const; float getHP() const; float getMaxHP() const; float getHardness() const; ItemType *zEffectiveTool() const; float getSpeedModifier() const; const Framework::Vec3 &getPos() const; friend Chunk; friend BlockType; }; class BasicBlockItem : public Item { protected: bool transparent; bool passable; float hp; float maxHP; float hardness; int toolId; float speedModifier; public: BasicBlockItem( ItemType *zType, const char *name ); virtual bool canBeStackedWith( Item *zItem ) const override; friend BasicBlockItemType; friend BlockType; }; class BasicBlockItemType : public ItemType { protected: BasicBlockItemType( int id, ItemSkillLevelUpRule *levelUpRule, ItemType *zBrokenType ); virtual void loadSuperItem( Item *zItem, Framework::Reader *zReader ) const override; virtual void saveSuperItem( Item *zItem, Framework::Writer *zWriter ) const override; void initializeItem( BasicBlockItem *zItem, bool transparent, bool passable, float hp, float maxHP, float hardness, int toolId, float speedModifier ) const; };