12345678910111213141516171819202122232425262728293031323334353637383940 |
- #include "TreeTemplate.h"
- TreeTemplate::TreeTemplate( float propability, const BlockType* zWoodType, const BlockType* zLeaveType, int minHeight, int maxHeight )
- : GenerationTemplate( propability, 0, 1, Framework::Vec3<int>( -2, -2, 0 ), Framework::Vec3<int>( 5, 5, maxHeight ) ),
- zWoodType( zWoodType ),
- zLeaveType( zLeaveType ),
- minHeight( minHeight ),
- maxHeight( maxHeight )
- {}
- GeneratedStructure* TreeTemplate::generateAt( Framework::Vec3<int> location, Noise* zNoise )
- {
- double noise = zNoise->getNoise( (double)location.x + 40, (double)location.y + 70, (double)location.z - 20 );
- int height = (int)(minHeight + (noise * (maxHeight - minHeight)));
- GeneratedStructure* generated = new GeneratedStructure( dynamic_cast<GenerationTemplate*>(getThis()), location, Framework::Vec3<int>( 5, 5, height ), Framework::Vec3<int>( -2, -2, 0 ) + location );
- for( int x = 1; x < 4; x++ )
- {
- for( int y = 1; y < 4; y++ )
- {
- generated->setBlockAt( zLeaveType->getId(), Framework::Vec3<int>( x, y, height - 1 ) );
- generated->setBlockAt( zLeaveType->getId(), Framework::Vec3<int>( x, y, height - 5 ) );
- }
- }
- for( int z = height - 2; z >= height - 4; z-- )
- {
- for( int x = 1; x < 4; x++ )
- {
- generated->setBlockAt( zLeaveType->getId(), Framework::Vec3<int>( x, 0, z ) );
- generated->setBlockAt( zLeaveType->getId(), Framework::Vec3<int>( 0, x, z ) );
- generated->setBlockAt( zLeaveType->getId(), Framework::Vec3<int>( x, 4, z ) );
- generated->setBlockAt( zLeaveType->getId(), Framework::Vec3<int>( 4, x, z ) );
- for( int y = 1; y < 4; y++ )
- generated->setBlockAt( zLeaveType->getId(), Framework::Vec3<int>( x, y, z ) );
- }
- }
- for( int i = 0; i < height - 1; i++ )
- generated->setBlockAt( zWoodType->getId(), Framework::Vec3<int>( 2, 2, i ) );
- return generated;
- }
|