Exemple #1
0
void
mkmap(lev_init *init_lev)
{
    schar	bg_typ = init_lev->bg,
            fg_typ = init_lev->fg;
    boolean smooth = init_lev->smoothed,
            join = init_lev->joined;
    xchar   lit = init_lev->lit,
            walled = init_lev->walled;
    int i;

    if(lit < 0)
        lit = (rnd(1+abs(depth(&u.uz))) < 11 && rn2(77)) ? 1 : 0;

    new_locations = (char *)alloc((WIDTH+1) * HEIGHT);

    if (bg_typ < MAX_TYPE)
        init_map(bg_typ);
    init_fill(bg_typ, fg_typ);

    for(i = 0; i < N_P1_ITER; i++)
        pass_one(bg_typ, fg_typ);

    for(i = 0; i < N_P2_ITER; i++)
        pass_two(bg_typ, fg_typ);

    if(smooth)
        for(i = 0; i < N_P3_ITER; i++)
            pass_three(bg_typ, fg_typ);

    if(join)
        join_map(bg_typ, fg_typ);

    finish_map(fg_typ, bg_typ, (boolean)lit, (boolean)walled);
    /* a walled, joined level is cavernous, not mazelike -dlc
     *
     * also, caverns have a defined "inside" and "outside"; the outside
     * doesn't _have_ to be stone, say, for hell.  so if the player
     * defined a maze filler originally, go ahead and backfill the
     * background in with that filler - DSR */
    if (walled && join && (init_lev->filling > -1)) {
        level.flags.is_maze_lev = FALSE;
        level.flags.is_cavernous_lev = TRUE;
        backfill(bg_typ,init_lev->filling);
    }
    free(new_locations);
}
void
mkmap(struct level *lev, lev_init *init_lev)
{
    schar bg_typ = init_lev->bg, fg_typ = init_lev->fg;
    boolean smooth = init_lev->smoothed, join = init_lev->joined;
    xchar lit = init_lev->lit, walled = init_lev->walled;
    int i;

    if (lit < 0)
        lit = (mklev_rn2(1 + abs(depth(&u.uz)), lev) < 10 &&
               mklev_rn2(77, lev)) ? 1 : 0;

    new_locations = malloc((WIDTH + 1) * HEIGHT);

    init_map(lev, bg_typ);
    init_fill(lev, bg_typ, fg_typ);

    for (i = 0; i < N_P1_ITER; i++)
        pass_one(lev, bg_typ, fg_typ);

    for (i = 0; i < N_P2_ITER; i++)
        pass_two(lev, bg_typ, fg_typ);

    if (smooth)
        for (i = 0; i < N_P3_ITER; i++)
            pass_three(lev, bg_typ, fg_typ);

    if (join)
        join_map(lev, bg_typ, fg_typ);

    finish_map(lev, fg_typ, bg_typ, (boolean) lit, (boolean) walled);
    /* a walled, joined level is cavernous, not mazelike -dlc */
    if (walled && join) {
        lev->flags.is_maze_lev = FALSE;
        lev->flags.is_cavernous_lev = TRUE;
    }
    free(new_locations);
}
Exemple #3
0
main(int argc, char *argv[])
{ 
  char *option;
  char command[MAX_STRING];
    
/*
 *	get command line options
 */
  while (--argc > 0 && (*++argv)[0] == '-')
  { 
    for (option = argv[0]+1; *option != '\0'; option++)
    { 
      switch (*option)
      { 
      case 't':
	argc--; argv++;
	if (argc <= 0 || sscanf(*argv,"%lf", &thin) != 1) error_exit(usage);
	break;
      case 'n':
	argc--; argv++;
	if (argc <= 0 || sscanf(*argv,"%lf", &north) != 1) error_exit(usage);
	break;
      case 's':
	argc--; argv++;
	if (argc <= 0 || sscanf(*argv,"%lf", &south) != 1) error_exit(usage);
	break;
      case 'e':
	argc--; argv++;
	if (argc <= 0 || sscanf(*argv,"%lf", &east) != 1) error_exit(usage);
	break;
      case 'w':
	argc--; argv++;
	if (argc <= 0 || sscanf(*argv,"%lf", &west) != 1) error_exit(usage);
	break;
      case 'v':
	if (very_verbose) very_very_verbose = TRUE;
	if (verbose) very_verbose = TRUE;
	verbose = TRUE;
	break;
      case 'V':
	fprintf(stderr,"%s\n", cdb_edit_c_rcsid);
	break;
      case 'p':
	do_sort = TRUE;
	compare = parallels_min;
	break; 
      case 'q':
	do_sort = TRUE;
	compare = parallels_max;
	break;
      case 'l':
	do_sort = TRUE;
	compare = meridians_min;
	break;
      case 'm':
	do_sort = TRUE;
	compare = meridians_max;
	break;
      case 'h':
	argc--; argv++;
	strncpy(label, *argv, 31);
	break;
      case 'j':
	argc--; argv++;
	if (argc <= 0 || sscanf(*argv,"%lf", &thin) != 1) error_exit(usage);
	join = TRUE;
	break;
      default:
	fprintf(stderr, "invalid option %c\n", *option);
	error_exit(usage);
      }
    }
  }

/*
 *	get new filename
 */
  if (argc < 2) error_exit(usage);
  new_filename = strdup(*argv);
  
  sprintf(temp, "cc_%s", new_filename);
  cc_filename = strdup(temp);
  
  sprintf(temp, "joined_%s", new_filename);
  joined_filename = strdup(temp);
  
  argc--; argv++;
  if (verbose) 
    fprintf(stderr,">creating: %s\n>thin: %lf km\n",
	    new_filename, thin);

/*
 *      initialize .mpp file
 */

  map = init_mapx(MPP_FILENAME);
  if (NULL == map) 
  { fprintf(stderr,"cdb_edit: get a copy of %s, or set the environment\n"\
	    "          variable PATHMPP to the appropriate directory\n",
	    MPP_FILENAME);
    exit(ABORT);
  }
  map->scale = thin/3;
  reinit_mapx(map);
  if(very_verbose) 
    fprintf(stderr, ">>initialized map\n"); 

/*
 *  initialize destination cdb_file
 */

  dest = new_cdb();
  if(NULL == dest) { perror("destination cdb class"); exit(ABORT); }
  dest->header = (cdb_file_header *) calloc(1, sizeof(cdb_file_header));
    
/*
 *	record segment data and create index
 */
  if(join)
  { 
    if (verbose) fprintf(stderr,">clipping source file(s)\n");
    clip_and_concat_files(argc, argv, north, south, east, west);

    free_cdb(source);
    source = NULL;
    source = init_cdb(cc_filename);     
    if(source == NULL) { perror(cc_filename); exit(ABORT); }

    if (verbose) fprintf(stderr,">joining %s...\n", new_filename);
    join_map(); 
    
    free_cdb(source);
    source = NULL;
    source = init_cdb(joined_filename);     
    if(source == NULL) { perror(joined_filename); exit(ABORT); }

    if (verbose) fprintf(stderr,">thinning %s...\n", new_filename);
    thin_map(); 
  }
   
  else
  {
    if (verbose) fprintf(stderr,">clipping source file(s)\n");
    clip_and_concat_files(argc, argv, north, south, east, west);
        
    free_cdb(source);
    source = init_cdb(cc_filename); 
    if(source == NULL) { perror(cc_filename); exit(ABORT); }

    if (verbose) fprintf(stderr,">thining %s...\n", new_filename );
    thin_map();
  }

/*
 *	flush segment data buffer
 */
  if (dest->npoints > 0) write_segment_data(dest->seg_count);

/*
 *	sort index and finish up
 */
  if (do_sort)
  { if (verbose) fprintf(stderr,">sorting %d index entries...\n", dest->seg_count);
    qsort(dest->index, dest->seg_count, sizeof(cdb_index_entry), compare);
  }
 
  finish_new_file();
   
  sprintf(command, "cdb_list %s", new_filename);
  if(verbose) system(command);

  free(new_file);
  free(map);
  free_cdb(dest);
  free_cdb(source);
  free(label);

/*
 *  remove temporary files
 */
/******
  if(join)
    sprintf(command, "rm %s %s", cc_filename, joined_filename);
  
  else
    sprintf(command, "rm %s", cc_filename);
  
  system(command);********/ 

  exit(EXIT_SUCCESS);
}