12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182 |
- #include "Recipie.h"
- Recipie::Recipie()
- : ReferenceCounter()
- {}
- void Recipie::addIngredient( ItemFilter* filter, int amount )
- {
- filters.add( filter );
- inputAmount.add( amount );
- }
- void Recipie::addOutput( Item* item, int amount )
- {
- outputs.add( item );
- outputAmount.add( amount );
- }
- bool Recipie::testApplicability( CraftingStorage* zStorage )
- {
- for( int i = 0; i < outputs.getEintragAnzahl(); i++ )
- {
- if( !zStorage->hasFreeSpace( outputs.z( i ), outputAmount.get( i ) ) )
- return 0;
- }
- return zStorage->isAllAvailable( filters, inputAmount );
- }
- void Recipie::apply( CraftingStorage* zStorage )
- {
- zStorage->consume( filters, inputAmount );
- for( int i = 0; i < outputs.getEintragAnzahl(); i++ )
- {
- ItemStack* stack = new ItemStack( outputs.z( i )->zItemType()->cloneItem( outputs.z( i ) ), outputAmount.get( i ) );
- zStorage->addCraftingResult( stack );
- stack->release();
- }
- }
- ShapedRecipie::ShapedRecipie( int width, int height )
- :ReferenceCounter(),
- width( width ),
- height( height ),
- output( 0 ),
- outputAmount( 0 )
- {
- for( int i = 0; i < width * height; i++ )
- filters.add( 0 );
- }
- ShapedRecipie::~ShapedRecipie()
- {
- if( output )
- output->release();
- }
- void ShapedRecipie::setIngredient( int x, int y, ItemFilter* filter )
- {
- filters.set( filter, width * x + y );
- }
- void ShapedRecipie::setOutput( Item* item, int amount )
- {
- if( output )
- output->release();
- output = item;
- outputAmount = amount;
- }
- bool ShapedRecipie::testApplicability( ShapedCraftingStorage* zStorage )
- {
- return zStorage->isAllAvailable( filters, width, height ) && zStorage->hasFreeSpace( output, outputAmount );
- }
- void ShapedRecipie::apply( ShapedCraftingStorage* zStorage )
- {
- zStorage->consume( filters, width, height );
- ItemStack* stack = new ItemStack( output->zItemType()->cloneItem( output ), outputAmount );
- zStorage->addCraftingResult( stack );
- stack->release();
- }
|