123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178 |
- #include "Block.h"
- Block::Block( BlockType *zType, ItemType *zTool, Framework::Vec3<int> pos )
- {
- transparent = false;
- passable = false;
- hp = 1;
- maxHP = 1;
- hardness = 1;
- this->zType = zType;
- this->zTool = zTool;
- speedModifier = 1;
- 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 )
- {
- if( currentTickTimeout < ticksLeftCounter )
- {
- onTickCalled = 1;
- bool blocked = 0;
- bool result = onTick( zQueue, ticksLeftCounter, blocked );
- if( blocked )
- {
- wasTicked = 0;
- ticksLeftCounter--;
- onTickCalled = 0;
- return;
- }
- 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;
- }
- }
- bool Block::isTickSource() const
- {
- return tickSource;
- }
- BlockType *Block::zBlockType() const
- {
- return zType;
- }
- bool Block::isTransparent() const
- {
- return transparent;
- }
- bool Block::isPassable() const
- {
- return passable;
- }
- float Block::getHP() const
- {
- return hp;
- }
- float Block::getMaxHP() const
- {
- return maxHP;
- }
- float Block::getHardness() const
- {
- return hardness;
- }
- ItemType *Block::zEffectiveTool() const
- {
- return zTool;
- }
- float Block::getSpeedModifier() const
- {
- return speedModifier;
- }
- const Framework::Vec3<int> &Block::getPos() const
- {
- return pos;
- }
- BasicBlockItem::BasicBlockItem( ItemType *zType, const char *name )
- : Item( zType, name )
- {}
- bool BasicBlockItem::canBeStackedWith( Item *zItem ) const
- {
- 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;
- }
|