#include "Block.h" #include "Inventory.h" #include "Globals.h" Block::Block( ItemType *zTool, Framework::Vec3 pos ) : Inventory( pos ) { visible = false; transparent = false; passable = false; hp = 1; maxHP = 1; hardness = 1; this->zTool = zTool; speedModifier = 1; memset( zNeighbours, 0, sizeof( Block * ) * 6 ); } Block::~Block() {} bool Block::updateVisibility() { bool v = 0; for( int d = 0; d < 6; d++ ) { if( IS_BLOCK( zNeighbours[ d ] ) ) v |= zNeighbours[ d ]->isVisible() && ( zNeighbours[ d ]->transparent || zNeighbours[ d ]->passable ); else if( zNeighbours[ d ] ) v = 1; } if( v != visible ) { visible = v; currentGame->setVisibility( this, visible ); return true; } return false; } void Block::setNeighbour( Direction dir, Block *zN ) { zNeighbours[ dir ] = zN; } bool Block::isVisible() const { return visible; } BasicBlockItem::BasicBlockItem( const ItemType *zType, const char *name ) : Item( zType, name ) { placeable = 1; transparent = 0; passable = 0; hp = 0; maxHP = 0; hardness = 0; toolId = 0; speedModifier = 0; } BasicBlockItemType::BasicBlockItemType( int id ) : ItemType( id ) {} void BasicBlockItemType::loadSuperItem( Item *zItem, Framework::StreamReader *zReader ) const { ItemType::loadSuperItem( zItem, zReader ); BasicBlockItem *item = dynamic_cast( zItem ); if( !item ) throw "BasicBlockItemType::loadSuperItem was called with an invalid item"; zReader->lese( (char *)&item->transparent, 1 ); zReader->lese( (char *)&item->passable, 1 ); zReader->lese( (char *)&item->hp, 4 ); zReader->lese( (char *)&item->maxHP, 4 ); zReader->lese( (char *)&item->hardness, 4 ); zReader->lese( (char *)&item->toolId, 4 ); zReader->lese( (char *)&item->speedModifier, 4 ); }