in procgen/src/games/caveflyer.cpp [145:265]
void game_reset() override {
BasicAbstractGame::game_reset();
out_of_bounds_object = WALL_OBJ;
for (int i = 0; i < grid_size; i++) {
if (rand_gen.rand01() < .5) {
set_obj(i, WALL_OBJ);
} else {
set_obj(i, SPACE);
}
}
for (int iteration = 0; iteration < 4; iteration++) {
room_manager->update();
}
std::set<int> best_room;
room_manager->find_best_room(best_room);
fassert(best_room.size() > 0);
for (int i = 0; i < grid_size; i++) {
set_obj(i, WALL_OBJ);
}
std::vector<int> free_cells;
for (int i : best_room) {
set_obj(i, SPACE);
free_cells.push_back(i);
}
std::vector<int> selected_idxs = rand_gen.simple_choose((int)(free_cells.size()), 2);
int agent_cell = free_cells[selected_idxs[0]];
int goal_cell = free_cells[selected_idxs[1]];
agent->x = (agent_cell % main_width) + .5;
agent->y = (agent_cell / main_width) + .5;
auto ent = spawn_entity_at_idx(goal_cell, .5, GOAL);
ent->collides_with_entities = true;
std::vector<int> goal_path;
room_manager->find_path(agent_cell, goal_cell, goal_path);
bool should_prune = options.distribution_mode != MemoryMode;
if (should_prune) {
std::set<int> wide_path;
wide_path.insert(goal_path.begin(), goal_path.end());
room_manager->expand_room(wide_path, 4);
for (int i = 0; i < grid_size; i++) {
set_obj(i, WALL_OBJ);
}
for (int i : wide_path) {
set_obj(i, SPACE);
}
}
for (int iteration = 0; iteration < 4; iteration++) {
room_manager->update();
for (int i : goal_path) {
set_obj(i, SPACE);
}
}
for (int i : goal_path) {
set_obj(i, MARKER);
}
free_cells.clear();
for (int i = 0; i < grid_size; i++) {
if (get_obj(i) == SPACE) {
free_cells.push_back(i);
} else if (get_obj(i) == WALL_OBJ) {
set_obj(i, CAVEWALL);
}
}
int chunk_size = ((int)(free_cells.size()) / 80);
int num_objs = 3 * chunk_size;
std::vector<int> obstacle_idxs = rand_gen.simple_choose((int)(free_cells.size()), num_objs);
for (int i = 0; i < num_objs; i++) {
int val = free_cells[obstacle_idxs[i]];
if (i < chunk_size) {
auto e = spawn_entity_at_idx(val, .5, OBSTACLE);
e->collides_with_entities = true;
} else if (i < 2 * chunk_size) {
auto e = spawn_entity_at_idx(val, .5, TARGET);
e->health = 5;
e->collides_with_entities = true;
} else {
auto e = spawn_entity_at_idx(val, .5, ENEMY);
float vel = (.1 * rand_gen.rand01() + .1) * (rand_gen.randn(2) * 2 - 1);
if (rand_gen.rand01() < .5) {
e->vx = vel;
} else {
e->vy = vel;
}
e->smart_step = true;
e->collides_with_entities = true;
}
}
for (int i = 0; i < grid_size; i++) {
int val = get_obj(i);
if (val == MARKER)
val = SPACE;
set_obj(i, val);
}
out_of_bounds_object = CAVEWALL;
visibility = options.distribution_mode == EasyMode ? 10 : 16;
}