18
18
//
19
19
// How many times to try creating a single level
20
20
//
21
- static const int MAX_LEVELS = 100 ;
21
+ static const int MAX_LEVELS = 1 ;
22
22
static const int MAX_LEVEL_GEN_TRIES_FOR_SAME_SEED = 1000 ;
23
23
static const int MAX_LEVEL_GEN_ROOM_PLACE_TRIES = 500 ;
24
- static const int MAX_LEVEL_GEN_CORRIDOR_LEN = 20 ;
25
24
static const int MAX_LEVEL_GEN_MIN_BRIDGE_LEN = 6 ;
26
25
static const int MAX_LEVEL_ROOM_COUNT = 25 ;
27
26
static const int MAX_LEVEL_GEN_TRIES_CREATE_ROOM = MAX_LEVEL_ROOM_COUNT * 2 ;
@@ -1135,8 +1134,9 @@ static bool level_gen_trim_dead_tiles(Gamep g, class LevelGen *l, bool debug)
1135
1134
walkable_tile += level_gen_tile_is_walkable (g, l, x, y + 1 ) ? 1 : 0 ;
1136
1135
1137
1136
if (walkable_tile <= 1 ) {
1138
- l->data [ x ][ y ].c = CHARMAP_EMPTY;
1139
- did_something = true ;
1137
+ l->data [ x ][ y ].c = CHARMAP_EMPTY;
1138
+ l->data [ x ][ y ].room = nullptr ;
1139
+ did_something = true ;
1140
1140
}
1141
1141
break ;
1142
1142
}
@@ -1154,8 +1154,9 @@ static bool level_gen_trim_dead_tiles(Gamep g, class LevelGen *l, bool debug)
1154
1154
empty_tile += (l->data [ x ][ y + 1 ].c == CHARMAP_EMPTY) ? 1 : 0 ;
1155
1155
1156
1156
if (empty_tile >= 3 ) {
1157
- l->data [ x ][ y ].c = CHARMAP_EMPTY;
1158
- did_something = true ;
1157
+ l->data [ x ][ y ].c = CHARMAP_EMPTY;
1158
+ l->data [ x ][ y ].room = nullptr ;
1159
+ did_something = true ;
1159
1160
}
1160
1161
break ;
1161
1162
}
@@ -1216,111 +1217,145 @@ static void level_gen_scan_connected_rooms(Gamep g, class LevelGen *l, bool debu
1216
1217
1217
1218
//
1218
1219
// Add corridors between rooms that are not connected
1220
+ // Shortest distance is 2, which is ". ."
1219
1221
//
1220
- static void level_gen_connect_adjacent_rooms (Gamep g, class LevelGen *l, bool debug)
1222
+ static void level_gen_connect_adjacent_rooms_with_distance_and_chance (Gamep g, class LevelGen *l, int dist,
1223
+ int chance, bool debug)
1221
1224
{
1222
1225
TRACE_NO_INDENT ();
1223
1226
1224
1227
const std::initializer_list< point > directions = {point (-1 , 0 ), point (1 , 0 ), point (0 , -1 ), point (0 , 1 )};
1225
1228
1226
- //
1227
- // Shortest distance is 2, which is ". ."
1228
- //
1229
- for (int dist = 2 ; dist < MAX_LEVEL_GEN_CORRIDOR_LEN; dist++) {
1230
- for (int y = dist; y < MAP_HEIGHT - dist - 1 ; y++) {
1231
- for (int x = dist; x < MAP_WIDTH - dist - 1 ; x++) {
1232
- switch (l->data [ x ][ y ].c ) {
1233
- case CHARMAP_FLOOR :
1234
- {
1229
+ for (int y = dist; y < MAP_HEIGHT - dist - 1 ; y++) {
1230
+ for (int x = dist; x < MAP_WIDTH - dist - 1 ; x++) {
1231
+ switch (l->data [ x ][ y ].c ) {
1232
+ case CHARMAP_FLOOR :
1233
+ {
1234
+ //
1235
+ // Decrease the chance of connecting leaf rooms so we don't get too many
1236
+ //
1237
+ if (d100 () > chance - l->rooms_adj_connected * 5 ) {
1238
+ continue ;
1239
+ }
1240
+
1241
+ for (auto direction : directions) {
1235
1242
//
1236
- // Decrease the chance of connecting leaf rooms so we don't get too many
1243
+ // Check there is nothing in the way
1237
1244
//
1238
- if (d100 () > 10 - l->rooms_adj_connected ) {
1245
+ bool has_clear_path = true ;
1246
+ for (auto d = 1 ; d < dist; d++) {
1247
+ point adj (x + direction.x * d, y + direction.y * d);
1248
+ if ((l->data [ adj.x ][ adj.y ].c != CHARMAP_EMPTY)) {
1249
+ has_clear_path = false ;
1250
+ break ;
1251
+ }
1252
+ }
1253
+ if (! has_clear_path) {
1239
1254
continue ;
1240
1255
}
1241
1256
1242
- for (auto direction : directions) {
1243
- //
1244
- // Check there is nothing in the way
1245
- //
1246
- bool has_clear_path = true ;
1247
- for (auto d = 1 ; d < dist; d++) {
1248
- point adj (x + direction.x * d, y + direction.y * d);
1249
- if ((l->data [ adj.x ][ adj.y ].c != CHARMAP_EMPTY)) {
1250
- has_clear_path = false ;
1251
- break ;
1252
- }
1253
- }
1254
- if (! has_clear_path) {
1255
- continue ;
1256
- }
1257
+ //
1258
+ // Check there is a room at the end of the blank space
1259
+ //
1260
+ point dest (x + direction.x * dist, y + direction.y * dist);
1261
+ if (l->data [ dest.x ][ dest.y ].c != CHARMAP_FLOOR) {
1262
+ continue ;
1263
+ }
1257
1264
1258
- //
1259
- // Check there is a room at the end of the blank space
1260
- //
1261
- point dest (x + direction.x * dist, y + direction.y * dist);
1262
- if (l->data [ dest.x ][ dest.y ].c != CHARMAP_FLOOR) {
1263
- continue ;
1264
- }
1265
+ auto room_a = l->data [ x ][ y ].room ;
1266
+ auto room_b = l->data [ dest.x ][ dest.y ].room ;
1265
1267
1266
- auto room_a = l->data [ x ][ y ].room ;
1267
- auto room_b = l->data [ dest.x ][ dest.y ].room ;
1268
+ //
1269
+ // Check the two rooms at either end of the corridor are different.
1270
+ //
1271
+ if (room_a == room_b) {
1272
+ continue ;
1273
+ }
1268
1274
1269
- //
1270
- // Check the two rooms at either end of the corridor are different.
1271
- //
1272
- if (room_a == room_b) {
1273
- continue ;
1274
- }
1275
+ //
1276
+ // Keep connections to the start room minimal
1277
+ //
1278
+ if (room_a->room_type == ROOM_TYPE_START) {
1279
+ continue ;
1280
+ }
1281
+ if (room_b->room_type == ROOM_TYPE_START) {
1282
+ continue ;
1283
+ }
1275
1284
1276
- //
1277
- // Keep connections to the start room minimal
1278
- //
1279
- if (room_a->room_type != room_b->room_type ) {
1280
- continue ;
1285
+ std::pair< class Room *, class Room * > conn;
1286
+ if (room_a && room_b) {
1287
+ if (room_a < room_b) {
1288
+ conn.first = room_a;
1289
+ conn.second = room_b;
1290
+ } else {
1291
+ conn.first = room_b;
1292
+ conn.second = room_a;
1281
1293
}
1294
+ }
1282
1295
1283
- std::pair< class Room *, class Room * > conn;
1284
- if (room_a && room_b) {
1285
- if (room_a < room_b) {
1286
- conn.first = room_a;
1287
- conn.second = room_b;
1296
+ //
1297
+ // If the rooms are not connected, then join them via a corridor
1298
+ //
1299
+ if (l->rooms_connected .find (conn) == l->rooms_connected .end ()) {
1300
+ l->rooms_adj_connected ++;
1301
+ l->rooms_connected [ conn ] = true ;
1302
+ for (auto d = 1 ; d < dist; d++) {
1303
+ point adj (x + direction.x * d, y + direction.y * d);
1304
+
1305
+ if (dist >= MAX_LEVEL_GEN_MIN_BRIDGE_LEN) {
1306
+ l->data [ adj.x ][ adj.y ].c = CHARMAP_BRIDGE;
1288
1307
} else {
1289
- conn.first = room_b;
1290
- conn.second = room_a;
1308
+ l->data [ adj.x ][ adj.y ].c = CHARMAP_CORRIDOR;
1291
1309
}
1292
- }
1293
1310
1294
- //
1295
- // If the rooms are not connected, then join them via a corridor
1296
- //
1297
- if (l->rooms_connected .find (conn) == l->rooms_connected .end ()) {
1298
- l->rooms_adj_connected ++;
1299
- l->rooms_connected [ conn ] = true ;
1300
- for (auto d = 1 ; d < dist; d++) {
1301
- point adj (x + direction.x * d, y + direction.y * d);
1302
-
1303
- if (dist >= MAX_LEVEL_GEN_MIN_BRIDGE_LEN) {
1304
- l->data [ adj.x ][ adj.y ].c = CHARMAP_BRIDGE;
1305
- } else {
1306
- l->data [ adj.x ][ adj.y ].c = CHARMAP_CORRIDOR;
1307
- }
1308
-
1309
- l->data [ adj.x ][ adj.y ].room = room_a;
1310
- }
1311
+ l->data [ adj.x ][ adj.y ].room = room_a;
1311
1312
}
1312
1313
}
1313
-
1314
- break ;
1315
1314
}
1316
- }
1315
+
1316
+ break ;
1317
+ }
1317
1318
}
1318
1319
}
1319
1320
}
1320
1321
}
1321
1322
1322
1323
//
1323
- // Make bridges dramatic...
1324
+ // Add corridors between rooms that are not connected
1325
+ // Shortest distance is 2, which is ". ."
1326
+ //
1327
+ static void level_gen_connect_adjacent_rooms (Gamep g, class LevelGen *l, bool debug)
1328
+ {
1329
+ TRACE_NO_INDENT ();
1330
+
1331
+ const std::initializer_list< std::pair< int , int > > dists = {
1332
+ std::pair (2 /* corridor length */ , 100 /* percentage chance of occuring */ ),
1333
+ std::pair (3 /* corridor length */ , 100 /* percentage chance of occuring */ ),
1334
+ std::pair (4 /* corridor length */ , 100 /* percentage chance of occuring */ ),
1335
+ std::pair (5 /* corridor length */ , 90 /* percentage chance of occuring */ ),
1336
+ std::pair (6 /* corridor length */ , 90 /* percentage chance of occuring */ ),
1337
+ std::pair (7 /* corridor length */ , 90 /* percentage chance of occuring */ ),
1338
+ std::pair (8 /* corridor length */ , 50 /* percentage chance of occuring */ ),
1339
+ std::pair (9 /* corridor length */ , 50 /* percentage chance of occuring */ ),
1340
+ std::pair (10 /* corridor length */ , 50 /* percentage chance of occuring */ ),
1341
+ std::pair (11 /* corridor length */ , 50 /* percentage chance of occuring */ ),
1342
+ std::pair (12 /* corridor length */ , 10 /* percentage chance of occuring */ ),
1343
+ std::pair (13 /* corridor length */ , 10 /* percentage chance of occuring */ ),
1344
+ std::pair (14 /* corridor length */ , 10 /* percentage chance of occuring */ ),
1345
+ std::pair (15 /* corridor length */ , 10 /* percentage chance of occuring */ ),
1346
+ std::pair (16 /* corridor length */ , 5 /* percentage chance of occuring */ ),
1347
+ std::pair (17 /* corridor length */ , 5 /* percentage chance of occuring */ ),
1348
+ std::pair (18 /* corridor length */ , 5 /* percentage chance of occuring */ ),
1349
+ std::pair (19 /* corridor length */ , 5 /* percentage chance of occuring */ ),
1350
+ std::pair (20 /* corridor length */ , 5 /* percentage chance of occuring */ ),
1351
+ };
1352
+ for (auto d : dists) {
1353
+ level_gen_connect_adjacent_rooms_with_distance_and_chance (g, l, d.first , d.second , debug);
1354
+ }
1355
+ }
1356
+
1357
+ //
1358
+ // Make bridges dramatic by adding chasms around them
1324
1359
//
1325
1360
static void level_gen_add_chasms_around_bridges (Gamep g, class LevelGen *l, bool debug)
1326
1361
{
@@ -1364,10 +1399,24 @@ static class LevelGen *level_gen(Gamep g, int which)
1364
1399
return l;
1365
1400
}
1366
1401
1402
+ //
1403
+ // Get rid of tiles that go nowhere
1404
+ //
1367
1405
while (level_gen_trim_dead_tiles (g, l, debug)) {}
1368
1406
1407
+ //
1408
+ // Keep track of which room is connected to another via a door
1409
+ //
1369
1410
level_gen_scan_connected_rooms (g, l, debug);
1411
+
1412
+ //
1413
+ // Add corridors between rooms that are not connected
1414
+ //
1370
1415
level_gen_connect_adjacent_rooms (g, l, debug);
1416
+
1417
+ //
1418
+ // Make bridges dramatic by adding chasms around them
1419
+ //
1371
1420
level_gen_add_chasms_around_bridges (g, l, debug);
1372
1421
1373
1422
return l;
@@ -1395,7 +1444,7 @@ static void level_gen_create_level(Gamep g, int which)
1395
1444
// Per thread seed
1396
1445
//
1397
1446
auto seed = game_get_seed_num (g);
1398
- game_set_seed_for_thread (g, seed * which);
1447
+ game_set_seed_for_thread (g, seed + seed * which);
1399
1448
1400
1449
auto l = level_gen (g, which);
1401
1450
levels[ which ] = l;
0 commit comments