void cave_map_generator::cave_map_generator_job::place_passage(const passage& p) { const std::string& chance = p.cfg["chance"]; if(chance != "" && int(rng_()%100) < atoi(chance.c_str())) { return; } int windiness = p.cfg["windiness"]; double laziness = std::max<double>(1.0, p.cfg["laziness"].to_double()); passage_path_calculator calc(map_, params.wall_, laziness, windiness, rng_); pathfind::plain_route rt = a_star_search(p.src, p.dst, 10000.0, &calc, params.width_, params.height_); int width = std::max<int>(1, p.cfg["width"].to_int()); int jagged = p.cfg["jagged"]; for(std::vector<map_location>::const_iterator i = rt.steps.begin(); i != rt.steps.end(); ++i) { std::set<map_location> locs; build_chamber(*i,locs,width,jagged); for(std::set<map_location>::const_iterator j = locs.begin(); j != locs.end(); ++j) { set_terrain(*j, params.clear_); } } }
std::vector<map_location> fake_unit_path(const unit& fake_unit, const std::vector<std::string>& xvals, const std::vector<std::string>& yvals) { const gamemap *game_map = & resources::gameboard->map(); std::vector<map_location> path; map_location src; map_location dst; for(size_t i = 0; i != std::min(xvals.size(),yvals.size()); ++i) { if(i==0){ src.x = atoi(xvals[i].c_str())-1; src.y = atoi(yvals[i].c_str())-1; if (!game_map->on_board(src)) { ERR_CF << "invalid move_unit_fake source: " << src << '\n'; break; } path.push_back(src); continue; } pathfind::shortest_path_calculator calc(fake_unit, (*resources::teams)[fake_unit.side()-1], *resources::teams, *game_map); dst.x = atoi(xvals[i].c_str())-1; dst.y = atoi(yvals[i].c_str())-1; if (!game_map->on_board(dst)) { ERR_CF << "invalid move_unit_fake destination: " << dst << '\n'; break; } pathfind::plain_route route = pathfind::a_star_search(src, dst, 10000, &calc, game_map->w(), game_map->h()); if (route.steps.empty()) { WRN_NG << "Could not find move_unit_fake route from " << src << " to " << dst << ": ignoring complexities" << std::endl; pathfind::emergency_path_calculator calc(fake_unit, *game_map); route = pathfind::a_star_search(src, dst, 10000, &calc, game_map->w(), game_map->h()); if(route.steps.empty()) { // This would occur when trying to do a MUF of a unit // over locations which are unreachable to it (infinite movement // costs). This really cannot fail. WRN_NG << "Could not find move_unit_fake route from " << src << " to " << dst << ": ignoring terrain" << std::endl; pathfind::dummy_path_calculator calc(fake_unit, *game_map); route = a_star_search(src, dst, 10000, &calc, game_map->w(), game_map->h()); assert(!route.steps.empty()); } } // we add this section to the end of the complete path // skipping section's head because already included // by the previous iteration path.insert(path.end(), route.steps.begin()+1, route.steps.end()); src = dst; } return path; }
void god_mode() { for (int i = 0; i < d - 3; i++) { #if DEBUG sprintf(str, "Filling %dth top row\n",i); god_mode_debug(str); #endif // Fix top row fix_top_row(i); #if DEBUG sprintf(str, "Fix top corner\n"); god_mode_debug(str); #endif // Fix top corner fix_top_corner(i); // Fix left collumn fix_left_collumn(i); #if DEBUG sprintf(str, "Fix bottom corner\n"); god_mode_debug(str); #endif // Fix bottom corner fix_bottom_corner(i); } #if DEBUG // Solve 3 x 3 puzzle god_mode_debug("Solving 3 x 3 puzzle\n"); #endif search_node head_node; head_node.previous = NULL; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { head_node.board[i][j] = board[i + d - 3][j + d - 3]; } } head_node.g = 0; lifo * solution = NULL; #if DEBUG god_mode_debug("Calling a_star_search\n"); #endif a_star_search(&head_node, &solution); if (solution == NULL) printf("solution is NULL\n"); #if DEBUG god_mode_debug("Solution for 3 x 3 puzzle retrieved, begginning tiles movements\n"); #endif lifo_entry * entry = solution->head; lifo_entry * aux; while (solution->total_entries > 0) { switch(entry->node->move) { case up: move_blank(up); break; case down: move_blank(down); break; case left: move_blank(left); break; case right: move_blank(right); break; } aux = entry->next; free(entry); entry = aux; solution->head = entry; solution->total_entries--; } #if DEBUG god_mode_debug("3 x 3 puzzle solved\n"); #endif return; }