|
@@ -1,6 +1,6 @@
|
|
|
#include "Block.h"
|
|
|
|
|
|
-Block::Block( BlockType *zType, ItemType *zTool )
|
|
|
+Block::Block( BlockType *zType, ItemType *zTool, Framework::Vec3<int> pos )
|
|
|
{
|
|
|
transparent = false;
|
|
|
passable = false;
|
|
@@ -10,73 +10,58 @@ Block::Block( BlockType *zType, ItemType *zTool )
|
|
|
this->zType = zType;
|
|
|
this->zTool = zTool;
|
|
|
speedModifier = 1;
|
|
|
- fluidCapacity = 10;
|
|
|
- fluidAmount = 0;
|
|
|
- fluidTypeId = -1;
|
|
|
- fluidSpeed = 4;
|
|
|
-}
|
|
|
-
|
|
|
-void Block::tick()
|
|
|
-{
|
|
|
- if( fluidTypeId >= 0 )
|
|
|
+ ticksLeftCounter = 0;
|
|
|
+ wasTicked = 0;
|
|
|
+ onTickCalled = 0;
|
|
|
+ minTickTimeout = -1;
|
|
|
+ maxTickTimeout = -1;
|
|
|
+ tickSource = 0;
|
|
|
+ currentTickTimeout = 0;
|
|
|
+ this->pos = pos;
|
|
|
+}
|
|
|
+
|
|
|
+void Block::tick( TickQueue *zQueue )
|
|
|
+{
|
|
|
+ if( wasTicked )
|
|
|
+ return;
|
|
|
+ wasTicked = 1;
|
|
|
+ ticksLeftCounter++;
|
|
|
+ if( minTickTimeout >= 0 )
|
|
|
{
|
|
|
- int fluidLeft = MIN( fluidSpeed, fluidAmount );
|
|
|
- if( fluidLeft > 0 )
|
|
|
+ if( currentTickTimeout < ticksLeftCounter )
|
|
|
{
|
|
|
- if( neighbours[ BOTTOM ] )
|
|
|
- {
|
|
|
- int result = neighbours[ BOTTOM ]->addFluid( fluidTypeId, fluidLeft, TOP );
|
|
|
- fluidLeft -= result;
|
|
|
- fluidAmount -= result;
|
|
|
- }
|
|
|
- int distribution = (int)ceil( (float)fluidLeft / 4.f );
|
|
|
- if( neighbours[ NORTH ] && neighbours[ NORTH ]->getFluidAmount() < fluidAmount - 1 )
|
|
|
- {
|
|
|
- int amount = MIN( distribution, ( fluidAmount - neighbours[ NORTH ]->getFluidAmount() ) / 2 );
|
|
|
- int result = neighbours[ NORTH ]->addFluid( fluidTypeId, amount, SOUTH );
|
|
|
- fluidLeft -= result;
|
|
|
- fluidAmount -= result;
|
|
|
- }
|
|
|
- if( neighbours[ EAST ] && neighbours[ EAST ]->getFluidAmount() < fluidAmount - 1 )
|
|
|
- {
|
|
|
- int amount = MIN( distribution, ( fluidAmount - neighbours[ EAST ]->getFluidAmount() ) / 2 );
|
|
|
- int result = neighbours[ EAST ]->addFluid( fluidTypeId, amount, WEST );
|
|
|
- fluidLeft -= result;
|
|
|
- fluidAmount -= result;
|
|
|
- }
|
|
|
- if( neighbours[ SOUTH ] && neighbours[ SOUTH ]->getFluidAmount() < fluidAmount - 1 )
|
|
|
- {
|
|
|
- int amount = MIN( distribution, ( fluidAmount - neighbours[ SOUTH ]->getFluidAmount() ) / 2 );
|
|
|
- int result = neighbours[ SOUTH ]->addFluid( fluidTypeId, amount, NORTH );
|
|
|
- fluidLeft -= result;
|
|
|
- fluidAmount -= result;
|
|
|
- }
|
|
|
- if( neighbours[ WEST ] && neighbours[ WEST ]->getFluidAmount() < fluidAmount - 1 )
|
|
|
+ onTickCalled = 1;
|
|
|
+ bool blocked = 0;
|
|
|
+ bool result = onTick( zQueue, ticksLeftCounter, blocked );
|
|
|
+ if( blocked )
|
|
|
{
|
|
|
- int amount = MIN( distribution, ( fluidAmount - neighbours[ WEST ]->getFluidAmount() ) / 2 );
|
|
|
- int result = neighbours[ WEST ]->addFluid( fluidTypeId, amount, EAST );
|
|
|
- fluidLeft -= result;
|
|
|
- fluidAmount -= result;
|
|
|
+ wasTicked = 0;
|
|
|
+ ticksLeftCounter--;
|
|
|
+ onTickCalled = 0;
|
|
|
+ return;
|
|
|
}
|
|
|
- if( fluidAmount == 0 )
|
|
|
- fluidTypeId = -1;
|
|
|
+ if( result )
|
|
|
+ currentTickTimeout = MAX( MIN( currentTickTimeout - 1, maxTickTimeout ), MAX( minTickTimeout, 0 ) );
|
|
|
+ else
|
|
|
+ currentTickTimeout = MAX( MIN( currentTickTimeout + 1, maxTickTimeout ), MAX( minTickTimeout, 0 ) );
|
|
|
+ ticksLeftCounter = 0;
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
|
|
|
void Block::postTick()
|
|
|
{
|
|
|
-
|
|
|
+ wasTicked = 0;
|
|
|
+ if( onTickCalled )
|
|
|
+ {
|
|
|
+ onPostTick();
|
|
|
+ onTickCalled = 0;
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
-int Block::addFluid( int fluidTypeId, int amount, DIRECTION dir )
|
|
|
+bool Block::isTickSource() const
|
|
|
{
|
|
|
- if( this->fluidTypeId != -1 && this->fluidTypeId != fluidTypeId )
|
|
|
- return 0;
|
|
|
- this->fluidTypeId = fluidTypeId;
|
|
|
- int result = MIN( amount, fluidCapacity - fluidAmount );
|
|
|
- fluidAmount += result;
|
|
|
- return result;
|
|
|
+ return tickSource;
|
|
|
}
|
|
|
|
|
|
BlockType *Block::zBlockType() const
|
|
@@ -119,22 +104,75 @@ float Block::getSpeedModifier() const
|
|
|
return speedModifier;
|
|
|
}
|
|
|
|
|
|
-int Block::getFluidCapacity() const
|
|
|
+const Framework::Vec3<int> &Block::getPos() const
|
|
|
{
|
|
|
- return fluidCapacity;
|
|
|
+ return pos;
|
|
|
}
|
|
|
|
|
|
-int Block::getFluidAmount() const
|
|
|
-{
|
|
|
- return fluidAmount;
|
|
|
-}
|
|
|
|
|
|
-int Block::getFluidTypeId() const
|
|
|
-{
|
|
|
- return fluidTypeId;
|
|
|
-}
|
|
|
+BasicBlockItem::BasicBlockItem( ItemType *zType, const char *name )
|
|
|
+ : Item( zType, name )
|
|
|
+{}
|
|
|
|
|
|
-int Block::getFluidSpeed() const
|
|
|
+bool BasicBlockItem::canBeStackedWith( Item *zItem ) const
|
|
|
{
|
|
|
- return fluidSpeed;
|
|
|
-}
|
|
|
+ BasicBlockItem *item = dynamic_cast<BasicBlockItem *>( zItem );
|
|
|
+ if( item )
|
|
|
+ {
|
|
|
+ return Item::canBeStackedWith( zItem ) &&
|
|
|
+ transparent == item->transparent &&
|
|
|
+ passable == item->passable &&
|
|
|
+ hp == item->hp &&
|
|
|
+ maxHP == item->maxHP &&
|
|
|
+ hardness == item->hardness &&
|
|
|
+ toolId == item->toolId &&
|
|
|
+ speedModifier == item->speedModifier;
|
|
|
+ }
|
|
|
+ return 0;
|
|
|
+}
|
|
|
+
|
|
|
+
|
|
|
+BasicBlockItemType::BasicBlockItemType( int id, ItemSkillLevelUpRule *levelUpRule, ItemType *zBrokenType )
|
|
|
+ : ItemType( id, levelUpRule, zBrokenType )
|
|
|
+{}
|
|
|
+
|
|
|
+void BasicBlockItemType::loadSuperItem( Item *zItem, Framework::Reader *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 );
|
|
|
+}
|
|
|
+
|
|
|
+void BasicBlockItemType::saveSuperItem( Item *zItem, Framework::Writer *zWriter ) const
|
|
|
+{
|
|
|
+ ItemType::saveSuperItem( zItem, zWriter );
|
|
|
+ BasicBlockItem *item = dynamic_cast<BasicBlockItem *>( zItem );
|
|
|
+ if( !item )
|
|
|
+ throw "BasicBlockItemType::saveSuperItem was called with an invalid item";
|
|
|
+ zWriter->schreibe( (char *)&item->transparent, 1 );
|
|
|
+ zWriter->schreibe( (char *)&item->passable, 1 );
|
|
|
+ zWriter->schreibe( (char *)&item->hp, 4 );
|
|
|
+ zWriter->schreibe( (char *)&item->maxHP, 4 );
|
|
|
+ zWriter->schreibe( (char *)&item->hardness, 4 );
|
|
|
+ zWriter->schreibe( (char *)&item->toolId, 4 );
|
|
|
+ zWriter->schreibe( (char *)&item->speedModifier, 4 );
|
|
|
+}
|
|
|
+
|
|
|
+void BasicBlockItemType::initializeItem( BasicBlockItem *zItem, bool transparent, bool passable, float hp, float maxHP, float hardness, int toolId, float speedModifier ) const
|
|
|
+{
|
|
|
+ zItem->transparent = transparent;
|
|
|
+ zItem->passable = passable;
|
|
|
+ zItem->hp = hp;
|
|
|
+ zItem->maxHP = maxHP;
|
|
|
+ zItem->hardness = hardness;
|
|
|
+ zItem->toolId = toolId;
|
|
|
+ zItem->speedModifier = speedModifier;
|
|
|
+}
|