1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
|
/*
* Generate a game of life level and make it evolve
*/
/*
* Copyright (c) 2003 DarkGod.
*
* This software may be copied and distributed for educational, research, and
* not for profit purposes provided that this copyright and statement are
* included in all such copies.
*/
#include "angband.h"
/*
* Generate a game of life level :) and make it evolve
*/
void evolve_level(bool_ noise)
{
int i, j;
int cw = 0, cf = 0;
/* Add a bit of noise */
if (noise)
{
for (i = 1; i < cur_wid - 1; i++)
{
for (j = 1; j < cur_hgt - 1; j++)
{
if (f_info[cave[j][i].feat].flags1 & FF1_WALL) cw++;
if (f_info[cave[j][i].feat].flags1 & FF1_FLOOR) cf++;
}
}
for (i = 1; i < cur_wid - 1; i++)
{
for (j = 1; j < cur_hgt - 1; j++)
{
cave_type *c_ptr;
/* Access the grid */
c_ptr = &cave[j][i];
/* Permanent features should stay */
if (f_info[c_ptr->feat].flags1 & FF1_PERMANENT) continue;
/* Avoid evolving grids with object or monster */
if (c_ptr->o_idx || c_ptr->m_idx) continue;
/* Avoid evolving player grid */
if ((j == p_ptr->py) && (i == p_ptr->px)) continue;
if (magik(7))
{
if (cw > cf)
{
place_floor(j, i);
}
else
{
place_filler(j, i);
}
}
}
}
}
for (i = 1; i < cur_wid - 1; i++)
{
for (j = 1; j < cur_hgt - 1; j++)
{
int x, y, c;
cave_type *c_ptr;
/* Access the grid */
c_ptr = &cave[j][i];
/* Permanent features should stay */
if (f_info[c_ptr->feat].flags1 & FF1_PERMANENT) continue;
/* Avoid evolving grids with object or monster */
if (c_ptr->o_idx || c_ptr->m_idx) continue;
/* Avoid evolving player grid */
if ((j == p_ptr->py) && (i == p_ptr->px)) continue;
/* Reset tally */
c = 0;
/* Count number of surrounding walls */
for (x = i - 1; x <= i + 1; x++)
{
for (y = j - 1; y <= j + 1; y++)
{
if ((x == i) && (y == j)) continue;
if (f_info[cave[y][x].feat].flags1 & FF1_WALL) c++;
}
}
/*
* Changed these parameters a bit, so that it doesn't produce
* too open or too narrow levels -- pelpel
*/
/* Starved or suffocated */
if ((c < 4) || (c >= 7))
{
if (f_info[c_ptr->feat].flags1 & FF1_WALL)
{
place_floor(j, i);
}
}
/* Spawned */
else if ((c == 4) || (c == 5))
{
if (!(f_info[c_ptr->feat].flags1 & FF1_WALL))
{
place_filler(j, i);
}
}
}
}
/* Notice changes */
p_ptr->update |= (PU_VIEW | PU_MONSTERS | PU_FLOW | PU_MON_LITE);
}
bool_ level_generate_life()
{
int i, j;
for (i = 1; i < cur_wid - 1; i++)
{
for (j = 1; j < cur_hgt - 1; j++)
{
cave[j][i].info = (CAVE_ROOM | CAVE_GLOW | CAVE_MARK);
if (magik(45)) place_floor(j, i);
else place_filler(j, i);
}
}
evolve_level(FALSE);
evolve_level(FALSE);
evolve_level(FALSE);
/* Determine the character location */
if (!new_player_spot(get_branch()))
return FALSE;
return TRUE;
}
|