Placed a rune and some treasure at the bottom level (no buildings yet.)
git-svn-id: https://crawl-ref.svn.sourceforge.net/svnroot/crawl-ref/trunk@1322 c06c8d41-db1a-0410-9941-cceddc491573
AOLWOUIFBQDQTCMSVB7N7GAKFUY5J5LH7CJZAY3HEY3WEUSLADZAC
for (int i = std::max(x-a,margin); i <= std::min(x+a,GXM-margin); ++i)
for (int j = std::max(y-b,margin); j <= std::min(y+b, GYM-margin); ++j)
for (int i = std::max(x-a,margin); i < std::min(x+a,GXM-margin); ++i)
for (int j = std::max(y-b,margin); j < std::min(y+b, GYM-margin); ++j)
// dpeg's algorithm.
// We could have just used spotty_level() and changed rock to
// water, but this is much cooler. Right?
const int margin = 6;
coord_def centres[10];
if ( i < margin || i >= GXM - margin ||
j < margin || j >= GYM - margin ||
taken[i][j] )
return;
// It seems very difficult to get these numbers right, so I'm
// fixing them for now.
// const int estradius = std::max(50 - num_islands*10, 10);
// const int num_islands = std::min(player_branch_depth(), 10);
const int num_islands = 4;
const int estradius = 12;
taken[i][j] = true;
for ( int idelta = -1; idelta <= 1; ++idelta )
for ( int jdelta = -1; jdelta <= 1; ++jdelta )
connected_flood(margin, i + idelta, j + jdelta, taken);
}
// yes, yes, this can probably use travel to avoid duplicating code.
static int count_connected(int margin)
{
bool taken[GXM][GYM];
for (int x = margin; x < GXM-margin; ++x)
for (int y = margin; y < GYM-margin; ++y)
grd[x][y] = DNGN_DEEP_WATER;
for ( int i = margin; i < GXM - margin; ++i )
for ( int j = margin; j < GYM - margin; ++j )
taken[i][j] = (grd[i][j] == DNGN_DEEP_WATER ||
grd[i][j] == DNGN_SHALLOW_WATER);
int count = 0;
for ( int i = margin; i < GXM - margin; ++i )
for ( int j = margin; j < GYM - margin; ++j )
if ( !taken[i][j] )
{
++count;
connected_flood(margin,i,j,taken);
}
return count;
}
static void place_base_islands(int margin, int num_islands, int estradius,
coord_def centres[10])
{
int num_islands = player_branch_depth() + 1;
if ( at_bottom )
num_islands += random2(3);
const int estradius = 50 / num_islands - (num_islands == 2 ? 5 : 0);
int num_tries = 0;
coord_def centres[10];
do {
for (int x = margin; x < GXM-margin; ++x)
for (int y = margin; y < GYM-margin; ++y)
grd[x][y] = DNGN_DEEP_WATER;
place_base_islands(margin, num_islands, estradius, centres);
} while ( ++num_tries < 100 &&
count_connected(margin) != num_islands );
#ifdef DEBUG_DIAGNOSTICS
mprf(MSGCH_DIAGNOSTICS, "Num tries: %d Connected components: %d",
num_tries, count_connected(margin));
#endif
int x, y;
do {
x = random2(GXM);
y = random2(GYM);
} while ( grd[x][y] != DNGN_FLOOR );
grd[x][y] = DNGN_STONE_STAIRS_DOWN_I + i;
// Put all the stairs on one island
grd[centres[0].x][centres[0].y] = DNGN_STONE_STAIRS_UP_I;
grd[centres[0].x+1][centres[0].y] = DNGN_STONE_STAIRS_UP_II;
grd[centres[0].x+2][centres[0].y] = DNGN_STONE_STAIRS_UP_III;
// turn all island centres into floor
for ( int i = 1; i < num_islands; ++i )
grd[centres[i].x][centres[i].y] = DNGN_FLOOR;
do {
x = random2(GXM);
y = random2(GYM);
} while ( grd[x][y] != DNGN_FLOOR );
grd[x][y] = DNGN_STONE_STAIRS_UP_I + i;
// Put a rune in the centre of another island
{
int item_made = items( 1, OBJ_MISCELLANY, MISC_RUNE_OF_ZOT, true,
0, RUNE_ISLANDS );
if (item_made != NON_ITEM && item_made != -1)
{
mitm[item_made].x = centres[1].x;
mitm[item_made].y = centres[1].y;
}
}
// Put good items in the other islands
for ( int i = 2; i < num_islands; ++i )
{
int item_made = items( 1, OBJ_RANDOM, OBJ_RANDOM, true,
MAKE_GOOD_ITEM, MAKE_ITEM_RANDOM_RACE );
if (item_made != NON_ITEM && item_made != -1)
{
mitm[item_made].x = centres[i].x;
mitm[item_made].y = centres[i].y;
}
}
}
else
{
// Place stairs randomly. No elevators.
for ( int i = 0; i < 3; ++i )
{
int x, y;
do {
x = random2(GXM);
y = random2(GYM);
} while ( grd[x][y] != DNGN_FLOOR );
grd[x][y] = DNGN_STONE_STAIRS_DOWN_I + i;
do {
x = random2(GXM);
y = random2(GYM);
} while ( grd[x][y] != DNGN_FLOOR );
grd[x][y] = DNGN_STONE_STAIRS_UP_I + i;
}