int comando(int argc, string * argv) { int i, j, size; object ob; string file; string * paths, * files; for(i=0; i<argc; i++) { size = sizeof(files = explore_path(argv[i], 2)); if (size) { for(j=0; j<size; j++) { file = files[j]; if (find_dir(file)) { notify_fail("update: "+file+" es un directorio.\n"); return 0; } if ((ob = find_object(file)) && (ob != find_object(VOID))) { /* pillar los objetos que estan dentro de ob * y llevarlos a void. * Opcion: despues del update, intentar llevarlos de vuelta al origen, * y sino a void. */ } if (!update(file)) { write("update: "+file+" no necesita actualizarse.\n"); } } } else { write("update: No se encuentra el archivo '"+argv[i]+"'.\n"); } } return 1; }
int comando(int argc, string * argv) { object ob; mixed dest; string err; if (argc != 1) { notify_fail("go: Parametros incorrectos: go [jugador | habitacion]\n"); return 0; } argv[0] = lower_case(argv[0]); ob = find_player(argv[0]); if (ob == TP) return 1; if (ob) { dest = environment(ob); if (dest == ETP) return 1; } else { string * paths = explore_path(argv[0], 2); if (sizeof(paths)) dest = paths[0]; else { notify_fail("go: No existe el destino '"+argv[0]+"'.\n"); return 0; } } if (TP->move(dest) != MOVE_OK) { write("go: Error moviendote al destino.\n"); } return 1; }
void find_paths(WeightedPoint ** paths, Point start, int cut_corners, int * weights, int rows, int cols) { WeightedPoint * distances[rows * cols]; int ** visited; int size = 0; visited = calloc(rows, sizeof(int*)); int r; for(r = 0; r < rows; r++) { visited[r] = calloc(cols, sizeof(int)); int c; for(c = 0; c < cols; c++) { distances[size + 1] = &paths[r][c]; distances[size + 1] -> point = (Point){c, r}; if(c > 0 && c < cols - 1 && r > 0 && r < rows - 1) { distances[size + 1] -> index = size + 1; if(r == start.y && c == start.x) { distances[size + 1] -> weight = 0; } else { distances[size + 1] -> weight = UNVISITED_SQUARE; } size++; visited[r][c] = 0; } else { visited[r][c] = 1; } paths[r][c].prev.x = 0; paths[r][c].prev.y = 0; } } init_heap(size, (void**)distances, cmp_weighted_points, weighted_point_callback); while(size) { WeightedPoint * u = deleteMin(size--, (void**)distances, cmp_weighted_points, weighted_point_callback); explore_path(u->point.x - 1, u->point.y, size, cols, u, visited, paths, distances, weights, 0); explore_path(u->point.x + 1, u->point.y, size, cols, u, visited, paths, distances, weights, 0); explore_path(u->point.x, u->point.y - 1, size, cols, u, visited, paths, distances, weights, 0); explore_path(u->point.x, u->point.y + 1, size, cols, u, visited, paths, distances, weights, 0); if(cut_corners) { explore_path(u->point.x - 1, u->point.y + 1, size, cols, u, visited, paths, distances, weights, 1); explore_path(u->point.x + 1, u->point.y - 1, size, cols, u, visited, paths, distances, weights, 1); explore_path(u->point.x - 1, u->point.y - 1, size, cols, u, visited, paths, distances, weights, 1); explore_path(u->point.x + 1, u->point.y + 1, size, cols, u, visited, paths, distances, weights, 1); } visited[u->point.y][u->point.x] = 1; } for(r = 0; r < rows; r++) { free(visited[r]); } free(visited); }
bool get_astar_path(int actor_node, int start_tile, int destination_tile){ /** public function - see header */ int j=0; path_stack_count=0; int lowest_value=0; int next_tile=0; int map_id=clients.client[actor_node].map_id; if(explore_path(actor_node, destination_tile)==false) return false; //if #EXPLORE_TRACE commands have been used then send ascii grid to client if(clients.client[actor_node].debug_status==DEBUG_EXPLORE){ debug_explore(actor_node, destination_tile); clients.client[actor_node].debug_status=DEBUG_OFF; } //start path at destination tile next_tile=destination_tile; path_stack[0].explored=true; //load destination tile to the path clients.client[actor_node].path_count=1; clients.client[actor_node].path[ clients.client[actor_node].path_count-1]=next_tile; //loop through explored tiles finding the best adjacent moves from destination to start do{ lowest_value=9999;//works for paths up to 9999 tiles long which ought to be sufficient bool found=false; for(int i=0; i<path_stack_count; i++){ if(tile_adjacent(next_tile, path_stack[i].tile, map_id)==true){ if(path_stack[i].value<lowest_value && path_stack[i].explored==false){ //ensure path doesn't cross lateral bounds if(tile_in_lateral_bounds(next_tile, path_stack[i].tile, map_id)==true){ lowest_value=path_stack[i].value; j=i; found=true; } } } } //if no adjacent tiles then start is unreachable from destination so abort function if(found==false) { send_text(clients.client[actor_node].socket, CHAT_PERSONAL, "%cthat destination is unreachable", c_red1+127); return false; } next_tile=path_stack[j].tile; path_stack[j].explored=true; clients.client[actor_node].path_count++; if(clients.client[actor_node].path_count>PATH_MAX-1) { log_event(EVENT_ERROR, "client path array exceeded in function %s: module %s: line %i", GET_CALL_INFO); stop_server(); } clients.client[actor_node].path[ clients.client[actor_node].path_count-1]=next_tile; }while(clients.client[actor_node].path[clients.client[actor_node].path_count-1]!=start_tile); //if #TRACE_PATH command has been used then display ascii grid if(clients.client[actor_node].debug_status==DEBUG_PATH){ debug_path(actor_node, destination_tile); clients.client[actor_node].debug_status=DEBUG_OFF; } return true; }