// main game execution int main(int argc, char **argv) { empire_srandom(time(0)); if (argc > 1 && !strcmp(argv[1], "shift")) { if (argc <= 2) { printf("Usage: %s shift <distance>\n", argv[0]); exit(1); } load_and_shift_map(atoi(argv[2])); return 0; } else if (argc > 1) { printf("Unknown mode: %s\n", argv[1]); } create_map(); print_map_graphic(); print_map_to_files(); printf("Done.\n"); output_stats(); return (0); }
void load_and_shift_map(int dist) { char fname[256], line[1024]; FILE *index, *wld; int block, vnum, island, type, junk; // nowork if (dist == 0) { printf("Shift by distance 0: no work to do.\n"); return; } init_grid(); printf("Loaded existing map...\n"); // load in existing map if (!(index = fopen("index", "r"))) { printf("ERROR: Unable to load index file.\n"); exit(1); } while (fscanf(index, "%d.wld\n", &block) == 1) { sprintf(fname, "%d.wld", block); printf("Loading file %s ...\n", fname); if (!(wld = fopen(fname, "r"))) { printf("ERROR: Unable to open world file %s.\n", fname); exit(1); } while (get_line(wld, line)) { if (*line == '$') { break; } else if (*line == '#') { // found entry vnum = atoi(line + 1); if (!get_line(wld, line) || sscanf(line, "%d %d %d", &island, &type, &junk) != 3) { printf("Error reading room #%d\n", vnum); exit(1); } change_grid(vnum, sect_to_terrain(type)); grid[vnum].island_id = island; // trailing 'S' line get_line(wld, line); } else { printf("Unknown line in %s: %s\n", fname, line); exit(1); } } } shift_map_x(dist); print_map_graphic(); print_map_to_files(); printf("Map shifted %d on X-axis.\n", dist); output_stats(); }
int main(int argc, char **argv) { FILE *map_file, *output_file; int lineData[4]; isla *new_isla; list *isla_list; map *active_map; stack *got_stack; bool fuck_up = FALSE; if(argc != 2 || strcmp(get_filename_ext(argv[1]), "map")) file_error("Missing arguments or wrong extension specified on file input"); map_file = fopen(argv[1], "r"); if(map_file == NULL) file_error("Unable to open file specified"); output_file = change_file_ext(argv[1]); while(read_line(map_file, lineData) != 0) { /*Create new map*/ active_map = create_map(lineData[1], lineData[0], lineData[2], lineData[3]); isla_list = create_list(); /*Read isla, create struct isla, add to the map matrix, line by line*/ while(read_line(map_file, lineData) == 1) { new_isla = NULL; setup_isla(new_isla, active_map, lineData, isla_list); } #ifdef DEBUG /*tester: print map, print list*/ print_list(isla_list, print_isla); printf("\n"); print_map(active_map); print_map_graphic(active_map); printf("\n"); /* end of test */ #endif find_adj(active_map); #ifdef DEBUG print_adj(isla_list); #endif fuck_up = initial_fuck_up(isla_list); /* verify if initial f**k up, if yes: rage quit */ if(fuck_up != TRUE) { /*Play the game*/ got_stack = DFS_manager(isla_list, active_map); #ifdef DEBUG print_stack(got_stack, print_bridge); #endif } /*Write in output file*/ print_output_per_map(active_map, output_file, isla_list); /*free stuff, start over*/ if(fuck_up != TRUE) free_stack(got_stack, already_free); free_list(isla_list, free_isla); free_map(active_map); } fclose(map_file); fclose(output_file); exit(EXIT_SUCCESS); }