- if(data->no_op)
- {
- //dstream<<"makeBlock: no-op"<<std::endl;
- return;
- }
-
- assert(data->vmanip);
- assert(data->nodedef);
- assert(data->blockpos_requested.X >= data->blockpos_min.X &&
- data->blockpos_requested.Y >= data->blockpos_min.Y &&
- data->blockpos_requested.Z >= data->blockpos_min.Z);
- assert(data->blockpos_requested.X <= data->blockpos_max.X &&
- data->blockpos_requested.Y <= data->blockpos_max.Y &&
- data->blockpos_requested.Z <= data->blockpos_max.Z);
-
- INodeDefManager *ndef = data->nodedef;
-
- // Hack: use minimum block coordinates for old code that assumes
- // a single block
- v3s16 blockpos = data->blockpos_requested;
-
- /*dstream<<"makeBlock(): ("<<blockpos.X<<","<<blockpos.Y<<","
- <<blockpos.Z<<")"<<std::endl;*/
-
- v3s16 blockpos_min = data->blockpos_min;
- v3s16 blockpos_max = data->blockpos_max;
- v3s16 blockpos_full_min = blockpos_min - v3s16(1,1,1);
- v3s16 blockpos_full_max = blockpos_max + v3s16(1,1,1);
-
- ManualMapVoxelManipulator &vmanip = *(data->vmanip);
- // Area of central chunk
- v3s16 node_min = blockpos_min*MAP_BLOCKSIZE;
- v3s16 node_max = (blockpos_max+v3s16(1,1,1))*MAP_BLOCKSIZE-v3s16(1,1,1);
- // Full allocated area
- v3s16 full_node_min = (blockpos_min-1)*MAP_BLOCKSIZE;
- v3s16 full_node_max = (blockpos_max+2)*MAP_BLOCKSIZE-v3s16(1,1,1);
-
- v3s16 central_area_size = node_max - node_min + v3s16(1,1,1);
-
- const s16 max_spread_amount = MAP_BLOCKSIZE;
-
- int volume_blocks = (blockpos_max.X - blockpos_min.X + 1)
- * (blockpos_max.Y - blockpos_min.Y + 1)
- * (blockpos_max.Z - blockpos_max.Z + 1);
-
- int volume_nodes = volume_blocks *
- MAP_BLOCKSIZE*MAP_BLOCKSIZE*MAP_BLOCKSIZE;
-
- // Generated surface area
- //double gen_area_nodes = MAP_BLOCKSIZE*MAP_BLOCKSIZE * rel_volume;
-
- // Horribly wrong heuristic, but better than nothing
- bool block_is_underground = (WATER_LEVEL > node_max.Y);
-
- /*
- Create a block-specific seed
- */
- u32 blockseed = get_blockseed(data->seed, full_node_min);
-
- /*
- Cache some ground type values for speed
- */
-
-// Creates variables c_name=id and n_name=node
-#define CONTENT_VARIABLE(ndef, name)\
- content_t c_##name = ndef->getId("mapgen_" #name);\
- MapNode n_##name(c_##name);
-
- CONTENT_VARIABLE(ndef, stone);
- CONTENT_VARIABLE(ndef, air);
- CONTENT_VARIABLE(ndef, water_source);
- CONTENT_VARIABLE(ndef, dirt);
- CONTENT_VARIABLE(ndef, sand);
- CONTENT_VARIABLE(ndef, gravel);
- CONTENT_VARIABLE(ndef, clay);
- CONTENT_VARIABLE(ndef, lava_source);
- CONTENT_VARIABLE(ndef, cobble);
- CONTENT_VARIABLE(ndef, mossycobble);
- CONTENT_VARIABLE(ndef, dirt_with_grass);
- CONTENT_VARIABLE(ndef, junglegrass);
- CONTENT_VARIABLE(ndef, stone_with_coal);
- CONTENT_VARIABLE(ndef, stone_with_iron);
- CONTENT_VARIABLE(ndef, mese);
-
- // Maximum height of the stone surface and obstacles.
- // This is used to guide the cave generation
- s16 stone_surface_max_y = 0;
-
- /*
- Generate general ground level to full area
- */
- {
-#if 1
- TimeTaker timer1("Generating ground level");
-
- for(s16 x=node_min.X; x<=node_max.X; x++)
- for(s16 z=node_min.Z; z<=node_max.Z; z++)
- {
- // Node position
- v2s16 p2d = v2s16(x,z);
-
- /*
- Skip of already generated
- */
- /*{
- v3s16 p(p2d.X, node_min.Y, p2d.Y);
- if(vmanip.m_data[vmanip.m_area.index(p)].d != CONTENT_AIR)
- continue;
- }*/
-
- // Ground height at this point
- float surface_y_f = 0.0;
-
- // Use perlin noise for ground height
- surface_y_f = base_rock_level_2d(data->seed, p2d);
-
- /*// Experimental stuff
- {
- float a = highlands_level_2d(data->seed, p2d);
- if(a > surface_y_f)
- surface_y_f = a;
- }*/
-
- // Convert to integer
- s16 surface_y = (s16)surface_y_f;
-
- // Log it
- if(surface_y > stone_surface_max_y)
- stone_surface_max_y = surface_y;
-
- /*
- Fill ground with stone
- */
- {
- // Use fast index incrementing
- v3s16 em = vmanip.m_area.getExtent();
- u32 i = vmanip.m_area.index(v3s16(p2d.X, node_min.Y, p2d.Y));
- for(s16 y=node_min.Y; y<=node_max.Y; y++)
- {
- if(y <= surface_y){
- if(vmanip.m_data[i].getContent() == CONTENT_IGNORE)
- vmanip.m_data[i] = MapNode(c_stone);
- } else if(y <= WATER_LEVEL){
- vmanip.m_data[i] = MapNode(c_water_source);
- } else {
- vmanip.m_data[i] = MapNode(c_air);
- }
-
- vmanip.m_area.add_y(em, i, 1);
- }
- }
- }
-#endif
-
- }//timer1
-
- // Limit dirt flow area by 1 because mud is flown into neighbors.
- assert(central_area_size.X == central_area_size.Z);
- s16 mudflow_minpos = 0-max_spread_amount+1;
- s16 mudflow_maxpos = central_area_size.X+max_spread_amount-2;
-
- /*
- Loop this part, it will make stuff look older and newer nicely
- */
-
- const u32 age_loops = 2;
- for(u32 i_age=0; i_age<age_loops; i_age++)
- { // Aging loop
- /******************************
- BEGINNING OF AGING LOOP
- ******************************/
-
-#if 1
- {
- // 24ms @cs=8
- //TimeTaker timer1("caves");
-
- /*
- Make caves (this code is relatively horrible)
- */
- double cave_amount = 6.0 + 6.0 * noise2d_perlin(
- 0.5+(double)node_min.X/250, 0.5+(double)node_min.Y/250,
- data->seed+34329, 3, 0.50);
- cave_amount = MYMAX(0.0, cave_amount);
- u32 caves_count = cave_amount * volume_nodes / 20000;
- u32 bruises_count = 1;
- PseudoRandom ps(blockseed+21343);
- if(ps.range(1, 4) == 1)
- bruises_count = ps.range(0, ps.range(0, 2));
- for(u32 jj=0; jj<caves_count+bruises_count; jj++)
- {
- bool large_cave = (jj >= caves_count);
- s16 min_tunnel_diameter = 2;
- s16 max_tunnel_diameter = ps.range(2,5);
- int dswitchint = ps.range(1,14);
- u16 tunnel_routepoints = 0;
- int part_max_length_rs = 0;
- if(large_cave){
- part_max_length_rs = ps.range(2,4);
- tunnel_routepoints = ps.range(5, ps.range(15,30));
- min_tunnel_diameter = 5;
- max_tunnel_diameter = ps.range(7, ps.range(8,24));
- } else {
- part_max_length_rs = ps.range(2,9);
- tunnel_routepoints = ps.range(10, ps.range(15,30));
- }
- bool large_cave_is_flat = (ps.range(0,1) == 0);
-
- v3f main_direction(0,0,0);
-
- // Allowed route area size in nodes
- v3s16 ar = central_area_size;
-
- // Area starting point in nodes
- v3s16 of = node_min;
-
- // Allow a bit more
- //(this should be more than the maximum radius of the tunnel)
- //s16 insure = 5; // Didn't work with max_d = 20
- s16 insure = 10;
- s16 more = max_spread_amount - max_tunnel_diameter/2 - insure;
- ar += v3s16(1,0,1) * more * 2;
- of -= v3s16(1,0,1) * more;
-
- s16 route_y_min = 0;
- // Allow half a diameter + 7 over stone surface
- s16 route_y_max = -of.Y + stone_surface_max_y + max_tunnel_diameter/2 + 7;
-
- /*// If caves, don't go through surface too often
- if(large_cave == false)
- route_y_max -= ps.range(0, max_tunnel_diameter*2);*/
-
- // Limit maximum to area
- route_y_max = rangelim(route_y_max, 0, ar.Y-1);
-
- if(large_cave)
- {
- /*// Minimum is at y=0
- route_y_min = -of.Y - 0;*/
- // Minimum is at y=max_tunnel_diameter/4
- //route_y_min = -of.Y + max_tunnel_diameter/4;
- //s16 min = -of.Y + max_tunnel_diameter/4;
- //s16 min = -of.Y + 0;
- s16 min = 0;
- if(node_min.Y < WATER_LEVEL && node_max.Y > WATER_LEVEL)
- {
- min = WATER_LEVEL - max_tunnel_diameter/3 - of.Y;
- route_y_max = WATER_LEVEL + max_tunnel_diameter/3 - of.Y;
- }
- route_y_min = ps.range(min, min + max_tunnel_diameter);
- route_y_min = rangelim(route_y_min, 0, route_y_max);
- }
-
- /*dstream<<"route_y_min = "<<route_y_min
- <<", route_y_max = "<<route_y_max<<std::endl;*/
-
- s16 route_start_y_min = route_y_min;
- s16 route_start_y_max = route_y_max;
-
- // Start every 4th cave from surface when applicable
- /*bool coming_from_surface = false;
- if(node_min.Y <= 0 && node_max.Y >= 0){
- coming_from_surface = (jj % 4 == 0 && large_cave == false);
- if(coming_from_surface)
- route_start_y_min = -of.Y + stone_surface_max_y + 10;
- }*/
-
- route_start_y_min = rangelim(route_start_y_min, 0, ar.Y-1);
- route_start_y_max = rangelim(route_start_y_max, route_start_y_min, ar.Y-1);
-
- // Randomize starting position
- v3f orp(
- (float)(ps.next()%ar.X)+0.5,
- (float)(ps.range(route_start_y_min, route_start_y_max))+0.5,
- (float)(ps.next()%ar.Z)+0.5
- );
-
- v3s16 startp(orp.X, orp.Y, orp.Z);
- startp += of;
-
- MapNode airnode(CONTENT_AIR);
- MapNode waternode(c_water_source);
- MapNode lavanode(c_lava_source);
-
- /*
- Generate some tunnel starting from orp
- */
-
- for(u16 j=0; j<tunnel_routepoints; j++)
- {
- if(j%dswitchint==0 && large_cave == false)
- {
- main_direction = v3f(
- ((float)(ps.next()%20)-(float)10)/10,
- ((float)(ps.next()%20)-(float)10)/30,
- ((float)(ps.next()%20)-(float)10)/10
- );
- main_direction *= (float)ps.range(0, 10)/10;
- }