A few minor bug fixes with area expansion.
This commit is contained in:
@@ -44,82 +44,42 @@ void expand_area() {
|
||||
expanded_area_end = MAP_SIZE + EXPANSION_SIZE - 1;
|
||||
MAP_SIZE += EXPANSION_SIZE;
|
||||
|
||||
// Generate random terrain for the 30 new tiles
|
||||
// Generate a single terrain type for the entire new area
|
||||
string terrain_type;
|
||||
int terrain_roll = random(0, 2);
|
||||
if (terrain_roll == 0) {
|
||||
terrain_type = "stone";
|
||||
} else if (terrain_roll == 1) {
|
||||
terrain_type = "grass";
|
||||
} else {
|
||||
terrain_type = "snow";
|
||||
}
|
||||
|
||||
expanded_terrain_types.resize(EXPANSION_SIZE);
|
||||
for (int i = 0; i < EXPANSION_SIZE; i++) {
|
||||
int terrain_roll = random(0, 2);
|
||||
if (terrain_roll == 0) {
|
||||
expanded_terrain_types[i] = "stone";
|
||||
} else if (terrain_roll == 1) {
|
||||
expanded_terrain_types[i] = "grass";
|
||||
} else {
|
||||
expanded_terrain_types[i] = "snow";
|
||||
}
|
||||
expanded_terrain_types[i] = terrain_type;
|
||||
}
|
||||
|
||||
// Generate streams (30% chance for a stream)
|
||||
int stream_roll = random(1, 100);
|
||||
if (stream_roll <= 30) {
|
||||
// Determine stream width (1-5 tiles)
|
||||
// Place exactly one feature: either a stream or a tree
|
||||
bool place_stream = (terrain_type != "grass") || (random(0, 1) == 0);
|
||||
|
||||
if (place_stream) {
|
||||
int stream_width = random(1, 5);
|
||||
int stream_start = random(0, EXPANSION_SIZE - stream_width);
|
||||
int actual_start = expanded_area_start + stream_start;
|
||||
add_world_stream(actual_start, stream_width);
|
||||
|
||||
// Find a valid starting position for the stream
|
||||
// Stream can only be in grass, stone, or snow areas
|
||||
int attempts = 0;
|
||||
int stream_start = -1;
|
||||
while (attempts < 50) {
|
||||
int candidate_start = random(0, EXPANSION_SIZE - stream_width);
|
||||
bool valid_position = true;
|
||||
string width_desc = "very small";
|
||||
if (stream_width == 2) width_desc = "small";
|
||||
else if (stream_width == 3) width_desc = "medium";
|
||||
else if (stream_width == 4) width_desc = "wide";
|
||||
else if (stream_width == 5) width_desc = "very wide";
|
||||
|
||||
// Check if all tiles in this range are valid for a stream
|
||||
for (int i = 0; i < stream_width; i++) {
|
||||
string terrain = expanded_terrain_types[candidate_start + i];
|
||||
// Streams can be in any terrain type
|
||||
if (terrain != "grass" && terrain != "stone" && terrain != "snow") {
|
||||
valid_position = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (valid_position) {
|
||||
stream_start = candidate_start;
|
||||
break;
|
||||
}
|
||||
attempts++;
|
||||
}
|
||||
|
||||
// Create the stream if we found a valid position
|
||||
if (stream_start != -1) {
|
||||
int actual_start = expanded_area_start + stream_start;
|
||||
add_world_stream(actual_start, stream_width);
|
||||
|
||||
string width_desc = "very small";
|
||||
if (stream_width == 2) width_desc = "small";
|
||||
else if (stream_width == 3) width_desc = "medium";
|
||||
else if (stream_width == 4) width_desc = "wide";
|
||||
else if (stream_width == 5) width_desc = "very wide";
|
||||
|
||||
notify("A " + width_desc + " stream flows through the new area at x " + actual_start + ".");
|
||||
}
|
||||
}
|
||||
|
||||
// Generate trees in grass areas (50% chance for each grass tile)
|
||||
for (int i = 0; i < EXPANSION_SIZE; i++) {
|
||||
if (expanded_terrain_types[i] == "grass") {
|
||||
int tile_pos = expanded_area_start + i;
|
||||
|
||||
// Skip if this position has a stream
|
||||
if (is_position_in_water(tile_pos)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// 50% chance to spawn a tree
|
||||
int tree_roll = random(1, 100);
|
||||
if (tree_roll <= 50) {
|
||||
Tree@ t = Tree(tile_pos);
|
||||
trees.insert_last(t);
|
||||
}
|
||||
}
|
||||
notify("A " + width_desc + " stream flows through the new area at x " + actual_start + ".");
|
||||
} else {
|
||||
int tree_pos = random(expanded_area_start, expanded_area_end);
|
||||
Tree@ t = Tree(tree_pos);
|
||||
trees.insert_last(t);
|
||||
}
|
||||
|
||||
area_expanded_today = true;
|
||||
@@ -235,7 +195,7 @@ string get_time_string() {
|
||||
period = "pm";
|
||||
}
|
||||
|
||||
return display_hour + " oclock " + period;
|
||||
return display_hour + " oclock " + period + " day " + current_day;
|
||||
}
|
||||
|
||||
void check_ambience_transition() {
|
||||
|
||||
Reference in New Issue
Block a user