void Tree::generate(uint8_t limit) { uint8_t darkness=1; srand((uint32_t)time(NULL)); uint8_t m_trunkHeight = getRandInt(MIN_TRUNK,limit); bool smalltree=false; //in this implementation we generate the trunk and as we do we call branching and canopy if(m_trunkHeight<BRANCHING_HEIGHT) { smalltree=true; darkness=0; } uint8_t th=m_trunkHeight-1; uint8_t i; for(i = 0; i < th; i++) { if(smalltree) { Trunk* v = new Trunk(_x,_y+i,_z,darkness); if(i>=MIN_TRUNK-1){ m_Branch[n_branches]= v; n_branches++; } else { delete v; } } else { Trunk* v = new Trunk(_x,_y+i,_z,darkness); if(i>BRANCHING_HEIGHT-1) { generateBranches(v); } else { delete v; } } } Trunk* v = new Trunk(_x,_y+i,_z,darkness); m_Branch[n_branches]= v; n_branches++; generateBranches(v); generateCanopy(); }
void Tree::generate(uint8_t limit) { const uint8_t m_trunkHeight = uniformUINT8(MIN_TRUNK, limit); bool smalltree = false; uint8_t type = 0; if (m_trunkHeight < BRANCHING_HEIGHT) { smalltree = true; } if (uniform01() > 0.5) // 1/2 chance { ++type; if (uniform01() > 0.5) // 1/4 { ++type; } } for (unsigned int i = 0; i + 1 < m_trunkHeight /* Trunk Height */; ++i) { if (smalltree) { const TrunkPtr v(new Trunk(_x, _y + i, _z, _map, type)); if (i >= MIN_TRUNK - 1) { m_Branch[n_branches++] = v; } } else { const TrunkPtr v(new Trunk(_x, _y + i, _z, _map, type)); if (i > BRANCHING_HEIGHT - 1) { generateBranches(v); m_Branch[n_branches++] = v; } } } const TrunkPtr v(new Trunk(_x, _y + m_trunkHeight - 1, _z, _map, type)); generateBranches(v); generateCanopy(); m_Branch[n_branches++] = v; }