1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- #include "Block.h"
- #include "Inventory.h"
- #include "Globals.h"
- Block::Block( ItemType *zTool, Framework::Vec3<int> pos )
- : Inventory( pos )
- {
- visible = false;
- transparent = false;
- passable = false;
- hp = 1;
- maxHP = 1;
- hardness = 1;
- this->zTool = zTool;
- speedModifier = 1;
- }
- 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<BasicBlockItem *>( 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 );
- }
|