void World::FindContinentNeighbors()
{
    sint16 center_cont;
    MapPoint center;
    MapPoint test_cont;
    bool is_land = false;

    AllocateNeighborMem();

    for(center.x=0; center.x<m_size.x; center.x++) {
        for(center.y=0; center.y<m_size.y; center.y++) {

            GetContinent(center, center_cont, is_land);

            Assert(0 <= center_cont);
            if (center_cont < 0) continue;

            if(center.GetNeighborPosition(NORTHWEST, test_cont))
				FindAContinentNeighbor(center_cont, test_cont, is_land);

            if(center.GetNeighborPosition(WEST, test_cont))
				FindAContinentNeighbor(center_cont, test_cont, is_land);

            if(center.GetNeighborPosition(SOUTHWEST, test_cont))
				FindAContinentNeighbor(center_cont, test_cont, is_land);

            if(center.GetNeighborPosition(SOUTH, test_cont))
				FindAContinentNeighbor(center_cont, test_cont, is_land);
        }
    }
}
void World::FindContinentSize()
{
    m_water_size->ExtendNFlat(m_water_continent_max);

    sint32 i;
    for (i=0; i<m_water_continent_max; i++) {
        m_water_size->Access(i) = 0;
    }

    sint32 diff =  m_land_continent_max - LAND_CONTINENT_START;

    m_land_size->ExtendNFlat(diff);
    for (i=0; i<diff; i++) {
        m_land_size->Access(i) = 0;
    }

    bool is_land;
    sint16 cont;
    MapPoint pos;
    for (pos.x = 0; pos.x<m_size.x; pos.x++) {
        for (pos.y=0; pos.y<m_size.y; pos.y++) {
            GetContinent(pos, cont, is_land);
            if (is_land) {
                m_land_size->Access(cont)++;
            } else {
                m_water_size->Access(cont)++;
            }
        }
    }
}
void World::FindAContinentNeighbor
(
    sint32     center_cont,
    MapPoint & test_point,
    bool       is_land
)
{
    bool is_neighbor_land = false;
    sint16 test_cont;

    GetContinent(test_point, test_cont, is_neighbor_land);

    if (is_land && !is_neighbor_land) {
        InsertLandNextToWater(center_cont, test_cont);
        InsertWaterNextToLand(test_cont, center_cont);
    } else if (!is_land && is_neighbor_land) {
        InsertWaterNextToLand(center_cont, test_cont);
        InsertLandNextToWater(test_cont, center_cont);
    }
}
Exemple #4
0
CGenerator CContinent::GetContinent()
{
    superficies = 0;
    vector<int> array;
    int end = 0;
    int x,y;
    do
    {
        x = rand()%(area_size-2)+1;
        y = rand()%(area_size-2)+1;
    }
    while(surface[GetUnit(glm::ivec2(x,y))] != 0);
    ///GetObj(glm::ivec3(x,y,0)) = 1;
    surface[GetUnit(glm::ivec2(x,y))] = 3;
    x_max = x_min = x;
    y_max = y_min = y;
    array.push_back(x+1);
    array.push_back(y);
    array.push_back(x);
    array.push_back(y+1);
    array.push_back(x-1);
    array.push_back(y);
    array.push_back(x);
    array.push_back(y-1);
    surface[GetUnit(glm::ivec2(x+1,y))] = 2;
    surface[GetUnit(glm::ivec2(x,y+1))] = 2;
    surface[GetUnit(glm::ivec2(x-1,y))] = 2;
    surface[GetUnit(glm::ivec2(x,y-1))] = 2;
    end += 8;

    int offset;
    while( end > 0 )
    {
        offset = (rand()%end)/2;
        offset *= 2;

        x = array[offset];
        y = array[offset+1];
        if(surface[GetUnit(glm::ivec2(x,y))] == 2)
        {
            surface[GetUnit(glm::ivec2(x,y))] = 3;
            border(x,y);
            ///GetObj(glm::ivec3(x,y,0)) = 1;
        }

        array[offset] = array[end-2];
        array[offset+1] = array[end-1];

        end -= 2;

        if( x+1 >= 0 and x+1 < area_size and y >= 0 and y < area_size and surface[GetUnit(glm::ivec2(x+1,y))] == 0)
        {
            if(end == array.size())
            {
                array.push_back(x+1);
                array.push_back(y);
            }
            else
            {
                array[end] = x+1;
                array[end+1] = y;
            }
            surface[GetUnit(glm::ivec2(x+1,y))] = 2;
            end += 2;
        }
        if( x >= 0 and x < area_size and y+1 >= 0 and y+1 < area_size and surface[GetUnit(glm::ivec2(x,y+1))] == 0)
        {
            if(end == array.size())
            {
                array.push_back(x);
                array.push_back(y+1);
            }
            else
            {
                array[end] = x;
                array[end+1] = y+1;
            }
            surface[GetUnit(glm::ivec2(x,y+1))] = 2;
            end += 2;
        }
        if(x-1 >= 0 and x-1 < area_size and y >= 0 and y < area_size and surface[GetUnit(glm::ivec2(x-1,y))] == 0 )
        {
            if(end == array.size())
            {
                array.push_back(x-1);
                array.push_back(y);
            }
            else
            {
                array[end] = x-1;
                array[end+1] = y;
            }
            surface[GetUnit(glm::ivec2(x-1,y))] = 2;
            end += 2;
        }
        if( x >= 0 and x < area_size and y-1 >= 0 and y-1 < area_size and surface[GetUnit(glm::ivec2(x,y-1))] == 0)
        {
            if(end == array.size())
            {
                array.push_back(x);
                array.push_back(y-1);
            }
            else
            {
                array[end] = x;
                array[end+1] = y-1;
            }
            surface[GetUnit(glm::ivec2(x,y-1))] = 2;
            end += 2;
        }
    }
    ///for(int i = 0 ; i < area_size ; i++)
    ///   for(int j = 0 ; j < area_size ; j++)
    ///       if(surface[GetUnit(glm::ivec2(i,j))])
    ///           GetObj(glm::ivec3(i,j,0)) = 1;
    if( y_max >= area_size-1 or x_max >= area_size-1 or y_min <= 0 or x_min <= 0)
        return GetContinent();
    ///cout << x_max << " " << y_max << " " << x_min << " " << y_min << endl;

    int x_size = x_max - x_min;
    int y_size = y_max - y_min;
    int scale = (x_size > y_size)?(area_size/x_size):(area_size/y_size);
    if(scale > 3)
        scale = 3;
    scale--;
    int shift_x = area_size/2 - (x_size*scale)/2;
    int shift_y = area_size/2 - (y_size*scale)/2;
    for(int i = 0 ; i < x_size ; i++)
        for(int j = 0 ; j < y_size ; j++)
        {
            for(int k = i*scale ; k < (i+1)*scale ; k++)
                for(int l = j*scale ; l < (j+1)*scale ; l++)
                {
                    if(surface[GetUnit(glm::ivec2(i+x_min,j+y_min))] == 3)
                        GetObj(glm::ivec3(k+shift_x,l+shift_y,0)) = 1;
                        superficies++;
                }
        }
    for(int k = 0 ; k < scale ; k++)
        for(int i = 0 ; i < area_size ; i++)
            for(int j = 0 ; j < area_size ; j++)
                if(GetObj(glm::ivec3(i,j,0)) == 1)
                {
                    if(GetObj(glm::ivec3(i+1,j,0)) == 0)
                        if(rand()%3 ==  1)
                        {
                            GetObj(glm::ivec3(i+1,j,0)) = 1;
                            border(i+1,j);
                            superficies++;
                        }
                    if(GetObj(glm::ivec3(i,j+1,0)) == 0)
                        if(rand()%3 ==  1)
                        {
                            GetObj(glm::ivec3(i,j+1,0)) = 1;
                            border(i,j+1);
                            superficies++;
                        }
                    if(GetObj(glm::ivec3(i-1,j,0)) == 0)
                        if(rand()%3 ==  1)
                        {
                            GetObj(glm::ivec3(i-1,j,0)) = 1;
                            border(i-1,j);
                            superficies++;
                        }
                    if(GetObj(glm::ivec3(i,j-1,0)) == 0)
                        if(rand()%3 ==  1)
                        {
                            GetObj(glm::ivec3(i,j-1,0)) = 1;
                            border(i,j-1);
                            superficies++;
                        }
                }
    smooth(0,1);
    smooth(0,1);
    smooth(0,1);
    x_size = x_max - x_min;
    y_size = y_max - y_min;
    CHill hill(x_size,y_size,10); ///! 10
    for(int i = x_min ; i < x_max ; i++)
        for(int j = y_min ; j < y_max ; j++)
        {
            if(GetObj(glm::ivec3(i,j,0)) == 1)
            {
                hill.GetObj(glm::ivec3(i-x_min,j-y_min,0)) = 1;
            }
        }
    hill.generate(superficies*0.8 , 0.8);
    return std::move((CGenerator)hill);
}
bool World::IsOnSameContinent(const MapPoint & pos1, const MapPoint & pos2) const
{
    return GetContinent(pos1) == GetContinent(pos2);
}