void use_item( Player *p, Item *it, Level *l ) { DATAFILE *data; data = load_datafile( "dat/sprites.dat" ); if (!data) fatal("Error reading datafile 'dat/sprites.dat'\n"); V_clear( p->item_animation ); switch ( it->type ) { case ITEM_POTION: INC2MAX( p->life, 1, MAX_LIFE ); p->item_in_use = (4 * ANIMATION_RATE); p->item_timer = ANIMATION_RATE; p->cur_item_frame = 0; V_add( p->item_animation, copy_bitmap( (BITMAP *)data[9].dat ) ); V_add( p->item_animation, copy_bitmap( (BITMAP *)data[10].dat ) ); V_add( p->item_animation, copy_bitmap( (BITMAP *)data[11].dat ) ); V_add( p->item_animation, copy_bitmap( (BITMAP *)data[10].dat ) ); break; case ITEM_PIPE: /*tmp = V_length( l->sprite_images ); V_add( l->sprite_images, copy_bitmap( (BITMAP *)data[12].dat ) ); V_add( l->sprite_images, copy_bitmap( (BITMAP *)data[13].dat ) ); V_add( l->sprite_images, copy_bitmap( (BITMAP *)data[14].dat ) ); V_add( l->sprite_images, copy_bitmap( (BITMAP *)data[15].dat ) );*/ /*create_sprite( Level *l, int type, int x, int y, int dir, int speed, int jump_rate, int shot_rate, int life, int num_of_images, ... )*/ create_sprite( l, SPRITE_WALK, p->pos_x, 0, -1, 8, 0, 50, 2, 5, 0, 0, 1, 2, 1 ); break; default: break; } unload_datafile( data ); }
int E_edit_cats(const char *name, struct Categories *cats, int option) { long incr; long atnum; long startcat; long endcat; long first_cat, last_cat; long catnum[NLINES]; char buff[NLINES][80]; char next[20]; char next_line[80]; char title[80]; char msg1[80]; char msg2[80]; int line; CELL max_ind, max_cat, min_ind; DCELL max_val, min_val; if (G_quant_get_limits (&cats->q, &min_val, &max_val, &min_ind, &max_ind) < 0) max_cat = 0; else max_cat = (CELL) max_val; if (max_cat < 0) option = 1; last_cat = (long)max_cat; if (option >= 0) { V_clear(); V_line(1, msg1); V_line(2, msg2); if (option == 0) { strcpy(msg1, "The current value for the highest category"); sprintf(msg2, "in [%s] is shown below", name); V_line(3, "If you need to change it, enter another value"); } else { last_cat = 0; strcpy(msg1, "Please enter the highest category value"); sprintf(msg2, "for [%s]", name); } V_line(10, " Highest Category:"); V_ques(&last_cat, 'l', 10, 28, 5); V_line(16, next_line); *next_line = 0; while (1) { V_intrpt_ok(); if (!V_call()) return -1; if (last_cat >= 0) break; sprintf(next_line, "** Negative values not allowed **"); } } max_cat = last_cat; first_cat = 0; if (cats->ncats > 0 && min_val < 0) first_cat = (CELL) min_val; *title = 0; if (cats->title != NULL) strcpy(title, cats->title); startcat = first_cat; sprintf(msg1, "[%s] ENTER NEW CATEGORY NAMES FOR THESE CATEGORIES", name); while (1) { V_clear(); V_line(0, msg1); V_line(2, "TITLE: "); V_line(3, "CAT NEW CATEGORY NAME"); V_line(4, "NUM"); V_ques(title, 's', 2, 8, 60); endcat = startcat + NLINES <= last_cat + 1 ? startcat + NLINES : last_cat + 1; line = 5; for (incr = startcat; incr < endcat; incr++) { atnum = incr - startcat; strcpy(buff[atnum], G_get_cat((CELL) incr, cats)); catnum[atnum] = incr; V_const(&catnum[atnum], 'l', line, 1, 3); V_ques(buff[atnum], 's', line, 5, 60); line++; } line += 2; *next = 0; if (endcat > last_cat) strcpy(next, "end"); else sprintf(next, "%ld", endcat); sprintf(next_line, "%*s%*s (of %ld)", 41, "Next category ('end' to end): ", 5, "", last_cat); V_line(line, next_line); V_ques(next, 's', line, 41, 5); V_intrpt_ok(); if (!V_call()) return -1; /* store new category name in structure */ for (incr = startcat; incr < endcat; incr++) { atnum = incr - startcat; G_strip(buff[atnum]); if (strcmp(buff[atnum], G_get_cat((CELL) incr, cats)) != 0) G_set_cat((CELL) incr, buff[atnum], cats); } if (*next == 0) break; if (strcmp(next, "end") == 0) break; if (sscanf(next, "%ld", &endcat) != 1) continue; if (endcat < first_cat) endcat = first_cat; if (endcat > last_cat) { endcat = last_cat - NLINES + 1; if (endcat < 0) endcat = 0; } startcat = endcat; } if (cats->title) G_free(cats->title); G_strip(title); cats->title = G_store(title); return (1); }
int E_edit_fp_cats(const char *name, struct Categories *cats) { long incr; long atnum; long startcat; long endcat; char buff[NLINES][60]; char next[20]; char next_line[80]; char title[80]; char msg1[80]; char msg2[80]; int line, ncats; size_t lab_len; DCELL max_val[NLINES], min_val[NLINES]; DCELL dmin, dmax; CELL tmp_cell; struct Categories old_cats; struct FPRange fp_range; if (G_read_fp_range(name, G_mapset(), &fp_range) < 0) G_fatal_error("can't read the floating point range for %s", name); G_get_fp_range_min_max(&fp_range, &dmin, &dmax); /* first save old cats */ G_copy_raster_cats(&old_cats, cats); G_init_raster_cats(old_cats.title, cats); G_free_raster_cats(cats); ncats = old_cats.ncats; V_clear(); if (!ncats) sprintf(msg1, "There are no predefined fp ranges to label"); else sprintf(msg1, "There are %d predefined fp ranges to label", ncats); sprintf(msg2, "Enter the number of fp ranges you want to label"); V_line(1, msg1); V_line(2, msg2); V_ques(&ncats, 'l', 2, 48, 5); V_line(16, next_line); *next_line = 0; V_intrpt_ok(); if (!V_call()) return -1; *title = 0; if (old_cats.title != NULL) strcpy(title, old_cats.title); startcat = 0; sprintf(msg1, "The fp data in map %s ranges from %f to %f", name, dmin, dmax); sprintf(msg2, "[%s] ENTER NEW CATEGORY NAMES FOR THESE CATEGORIES", name); while (1) { V_clear(); V_line(0, msg1); V_line(1, msg2); V_line(3, "TITLE: "); V_line(4, "FP RANGE NEW CATEGORY NAME"); V_ques(title, 's', 2, 8, 60); endcat = startcat + NLINES <= ncats ? startcat + NLINES : ncats; line = 6; for (incr = startcat; incr < endcat; incr++) { atnum = incr - startcat; if (incr < old_cats.ncats) { /* if editing existing range label */ lab_len = strlen(old_cats.labels[incr]); if (lab_len > 58) lab_len = 58; strncpy(buff[atnum], old_cats.labels[incr], lab_len); buff[atnum][lab_len] = 0; G_quant_get_ith_rule(&old_cats.q, incr, &min_val[atnum], &max_val[atnum], &tmp_cell, &tmp_cell); } else { /* adding new range label */ strcpy(buff[atnum], ""); max_val[atnum] = min_val[atnum] = 0; } V_ques(&min_val[atnum], 'd', line, 1, 8); V_const("-", 's', line, 9, 1); V_ques(&max_val[atnum], 'd', line, 10, 8); V_ques(buff[atnum], 's', line, 19, 58); line++; } line += 2; *next = 0; if (endcat >= ncats) strcpy(next, "end"); else sprintf(next, "%ld", endcat); sprintf(next_line, "%*s%*s (of %d)", 41, "Next range number ('end' to end): ", 5, "", ncats); V_line(line, next_line); V_ques(next, 's', line, 41, 5); V_intrpt_ok(); if (!V_call()) return -1; /* store new category name in structure */ for (incr = startcat; incr < endcat; incr++) { atnum = incr - startcat; G_strip(buff[atnum]); /* adding new range label */ if (!(strcmp(buff[atnum], "") == 0 && min_val[atnum] == 0. && max_val[atnum] == 0.)) G_set_d_raster_cat(&min_val[atnum], &max_val[atnum], buff[atnum], cats); } if (*next == 0) break; if (strcmp(next, "end") == 0) break; if (sscanf(next, "%ld", &endcat) != 1) continue; if (endcat < 0) endcat = 0; if (endcat > ncats) { endcat = ncats - NLINES + 1; if (endcat < 0) endcat = 0; } startcat = endcat; } G_strip(title); cats->title = G_store(title); /* since label pointers in old_cats point to the old allocated strings, and cats now has all the newly allocated strings, it never reuses old ones, we need to free them */ return (1); }
int E_edit_cellhd(struct Cell_head *cellhd, int type) { char ll_north[20]; char ll_south[20]; char ll_east[20]; char ll_west[20]; char ll_nsres[20]; char ll_ewres[20]; char ll_def_north[20]; char ll_def_south[20]; char ll_def_east[20]; char ll_def_west[20]; char ll_def_ewres[20]; char ll_def_nsres[20]; char projection[80]; char **screen; struct Cell_head def_wind; double north, south, east, west; double nsres, ewres; char buf[64], buf2[30], *p; short ok; int line; char *prj; char *err; if (type == AS_CELLHD && (cellhd->rows <= 0 || cellhd->cols <= 0)) { G_message("E_edit_cellhd() - programmer error"); G_message(" ** rows and cols must be positive **"); return -1; } if (type != AS_DEF_WINDOW) { if (G_get_default_window(&def_wind) != 1) return -1; if (cellhd->proj < 0) { cellhd->proj = def_wind.proj; cellhd->zone = def_wind.zone; } else if (cellhd->zone < 0) cellhd->zone = def_wind.zone; } prj = G__projection_name(cellhd->proj); if (!prj) prj = "** unknown **"; sprintf(projection, "%d (%s)", cellhd->proj, prj); if (type != AS_DEF_WINDOW) { if (cellhd->west >= cellhd->east || cellhd->south >= cellhd->north) { cellhd->north = def_wind.north; cellhd->south = def_wind.south; cellhd->west = def_wind.west; cellhd->east = def_wind.east; if (type != AS_CELLHD) { cellhd->ew_res = def_wind.ew_res; cellhd->ns_res = def_wind.ns_res; cellhd->rows = def_wind.rows; cellhd->cols = def_wind.cols; } } if (cellhd->proj != def_wind.proj) { if (type == AS_CELLHD) G_message ("header projection %d differs from default projection %d", cellhd->proj, def_wind.proj); else G_message ("region projection %d differs from default projection %d", cellhd->proj, def_wind.proj); if (!G_yes("do you want to make them match? ", 1)) return -1; cellhd->proj = def_wind.proj; cellhd->zone = def_wind.zone; } if (cellhd->zone != def_wind.zone) { if (type == AS_CELLHD) G_message("header zone %d differs from default zone %d", cellhd->zone, def_wind.zone); else G_message("region zone %d differs from default zone %d", cellhd->zone, def_wind.zone); if (!G_yes("do you want to make them match? ", 1)) return -1; cellhd->zone = def_wind.zone; } *ll_def_north = 0; *ll_def_south = 0; *ll_def_east = 0; *ll_def_west = 0; *ll_def_ewres = 0; *ll_def_nsres = 0; format_northing(def_wind.north, ll_def_north, def_wind.proj); format_northing(def_wind.south, ll_def_south, def_wind.proj); format_easting(def_wind.east, ll_def_east, def_wind.proj); format_easting(def_wind.west, ll_def_west, def_wind.proj); format_resolution(def_wind.ew_res, ll_def_ewres, def_wind.proj); format_resolution(def_wind.ns_res, ll_def_nsres, def_wind.proj); } *ll_north = 0; *ll_south = 0; *ll_east = 0; *ll_west = 0; *ll_ewres = 0; *ll_nsres = 0; format_northing(cellhd->north, ll_north, cellhd->proj); format_northing(cellhd->south, ll_south, cellhd->proj); format_easting(cellhd->east, ll_east, cellhd->proj); format_easting(cellhd->west, ll_west, cellhd->proj); format_resolution(cellhd->ew_res, ll_ewres, cellhd->proj); format_resolution(cellhd->ns_res, ll_nsres, cellhd->proj); while (1) { ok = 1; /* List window options on the screen for the user to answer */ switch (type) { case AS_CELLHD: screen = cellhd_screen; break; case AS_DEF_WINDOW: screen = def_window_screen; break; default: screen = window_screen; break; } V_clear(); line = 0; while (*screen) V_line(line++, *screen++); /* V_ques ( variable, type, row, col, length) ; */ V_ques(ll_north, 's', 6, 36, 10); V_ques(ll_south, 's', 10, 36, 10); V_ques(ll_west, 's', 9, 12, 10); V_ques(ll_east, 's', 9, 52, 10); if (type != AS_CELLHD) { V_ques(ll_ewres, 's', 18, 48, 10); V_ques(ll_nsres, 's', 19, 48, 10); } if (type != AS_DEF_WINDOW) { V_const(ll_def_north, 's', 3, 36, 10); V_const(ll_def_south, 's', 13, 36, 10); V_const(ll_def_west, 's', 9, 1, 10); V_const(ll_def_east, 's', 9, 65, 10); if (type != AS_CELLHD) { V_const(ll_def_ewres, 's', 18, 21, 10); V_const(ll_def_nsres, 's', 19, 21, 10); } } V_const(projection, 's', 15, 23, (int)strlen(projection)); V_const(&cellhd->zone, 'i', 15, 60, 3); V_intrpt_ok(); if (!V_call()) return -1; G_squeeze(ll_north); G_squeeze(ll_south); G_squeeze(ll_east); G_squeeze(ll_west); if (type != AS_CELLHD) { G_squeeze(ll_ewres); G_squeeze(ll_nsres); } if (!G_scan_northing(ll_north, &cellhd->north, cellhd->proj)) { G_warning("Illegal value for north: %s", ll_north); ok = 0; } if (!G_scan_northing(ll_south, &cellhd->south, cellhd->proj)) { G_warning("Illegal value for south: %s", ll_south); ok = 0; } if (!G_scan_easting(ll_east, &cellhd->east, cellhd->proj)) { G_warning("Illegal value for east: %s", ll_east); ok = 0; } if (!G_scan_easting(ll_west, &cellhd->west, cellhd->proj)) { G_warning("Illegal value for west: %s", ll_west); ok = 0; } if (type != AS_CELLHD) { if (!G_scan_resolution(ll_ewres, &cellhd->ew_res, cellhd->proj)) { G_warning("Illegal east-west resolution: %s", ll_ewres); ok = 0; } if (!G_scan_resolution(ll_nsres, &cellhd->ns_res, cellhd->proj)) { G_warning("Illegal north-south resolution: %s", ll_nsres); ok = 0; } } if (!ok) { hitreturn(); continue; } /* Adjust and complete the cell header */ north = cellhd->north; south = cellhd->south; east = cellhd->east; west = cellhd->west; nsres = cellhd->ns_res; ewres = cellhd->ew_res; if ((err = G_adjust_Cell_head(cellhd, type == AS_CELLHD, type == AS_CELLHD))) { G_message("%s", err); hitreturn(); continue; } if (type == AS_CELLHD) { nsres = cellhd->ns_res; ewres = cellhd->ew_res; } SHOW: fprintf(stderr, "\n\n"); G_message(" projection: %s", projection); G_message(" zone: %d", cellhd->zone); G_format_northing(cellhd->north, buf, cellhd->proj); G_format_northing(north, buf2, cellhd->proj); fprintf(stderr, " north: %s", buf); if (strcmp(buf, buf2) != 0) { ok = 0; fprintf(stderr, " (Changed to match resolution)"); } fprintf(stderr, "\n"); G_format_northing(cellhd->south, buf, cellhd->proj); G_format_northing(south, buf2, cellhd->proj); fprintf(stderr, " south: %s", buf); if (strcmp(buf, buf2) != 0) { ok = 0; fprintf(stderr, " (Changed to match resolution)"); } fprintf(stderr, "\n"); G_format_easting(cellhd->east, buf, cellhd->proj); G_format_easting(east, buf2, cellhd->proj); fprintf(stderr, " east: %s", buf); if (strcmp(buf, buf2) != 0) { ok = 0; fprintf(stderr, " (Changed to match resolution)"); } fprintf(stderr, "\n"); G_format_easting(cellhd->west, buf, cellhd->proj); G_format_easting(west, buf2, cellhd->proj); fprintf(stderr, " west: %s", buf); if (strcmp(buf, buf2) != 0) { ok = 0; fprintf(stderr, " (Changed to match resolution)"); } fprintf(stderr, "\n\n"); G_format_resolution(cellhd->ew_res, buf, cellhd->proj); G_format_resolution(ewres, buf2, cellhd->proj); fprintf(stderr, " e-w res: %s", buf); if (strcmp(buf, buf2) != 0) { ok = 0; fprintf(stderr, " (Changed to conform to grid)"); } fprintf(stderr, "\n"); G_format_resolution(cellhd->ns_res, buf, cellhd->proj); G_format_resolution(nsres, buf2, cellhd->proj); fprintf(stderr, " n-s res: %s", buf); if (strcmp(buf, buf2) != 0) { ok = 0; fprintf(stderr, " (Changed to conform to grid)"); } fprintf(stderr, "\n\n"); G_message(" total rows: %15d", cellhd->rows); G_message(" total cols: %15d", cellhd->cols); sprintf(buf, "%lf", (double)cellhd->rows * cellhd->cols); *(p = strchr(buf, '.')) = 0; G_insert_commas(buf); G_message(" total cells: %15s", buf); fprintf(stderr, "\n"); if (type != AS_DEF_WINDOW) { if (cellhd->north > def_wind.north) { G_warning("north falls outside the default region"); ok = 0; } if (cellhd->south < def_wind.south) { G_warning("south falls outside the default region"); ok = 0; } if (cellhd->proj != PROJECTION_LL) { if (cellhd->east > def_wind.east) { G_warning("east falls outside the default region"); ok = 0; } if (cellhd->west < def_wind.west) { G_warning("west falls outside the default region"); ok = 0; } } } ASK: fflush(stdin); if (type == AS_CELLHD) fprintf(stderr, "\nDo you accept this header? (y/n) [%s] > ", ok ? "y" : "n"); else fprintf(stderr, "\nDo you accept this region? (y/n) [%s] > ", ok ? "y" : "n"); if (!G_gets(buf)) goto SHOW; G_strip(buf); switch (*buf) { case 0: break; case 'y': case 'Y': ok = 1; break; case 'n': case 'N': ok = 0; break; default: goto ASK; } if (ok) return 0; } }
int mod_cam_info(int have_old, struct Ortho_Camera_File_Ref *cam_info) { long fidnum[NLINES]; char next[20]; char next_line[20]; int i; int atnum; int line; int startfid; int endfid; if (!have_old) strcpy(cam_info->cam_name, "DBA SYSTEMS CAMERA"); V_clear(); V_line(1, " Please provide the following information:"); V_line(2, "+------------------------------------------------------------------------------+"); V_line(4, " Camera Name"); V_line(5, " Camera Identification"); V_line(6, " Calibrated Focal Length mm."); V_line(7, " Point of Symmetry: X-coordinate mm."); V_line(8, " Point of Symmetry: Y-coordinate mm."); V_line(9, " Maximum number of fiducial or reseau marks"); V_line(11, "+-----------------------------------------------------------------------------+"); V_ques(cam_info->cam_name, 's', 4, 55, 20 - 1); V_ques(cam_info->cam_id, 's', 5, 55, 20 - 1); V_ques(&(cam_info->CFL), 'd', 6, 55, 20 - 1); V_ques(&(cam_info->Xp), 'd', 7, 55, 20 - 1); V_ques(&(cam_info->Yp), 'd', 8, 55, 20 - 1); V_ques(&(cam_info->num_fid), 'i', 9, 55, 20 - 1); V_intrpt_ok(); if (!V_call()) exit(0); /* get fiducail or reseau info NUMLINES at a time */ startfid = 0; while (startfid >= 0 && startfid < cam_info->num_fid) { V_clear(); { V_line(1, " Please provide the following information:"); V_line(2, "+--------------------------------------------------------------------------+"); V_line(4, " Fid# Fid Id Xf Yf"); } endfid = startfid + NLINES <= cam_info->num_fid + 1 ? startfid + NLINES : cam_info->num_fid; atnum = 0; line = 6; for (i = startfid; i < endfid; i++) { fidnum[atnum] = i + 1; V_const(&fidnum[atnum], 'i', line, 13, 5); V_ques(cam_info->fiducials[i].fid_id, 's', line, 21, 6); V_ques(&(cam_info->fiducials[i].Xf), 'd', line, 33, 10); V_ques(&(cam_info->fiducials[i].Yf), 'd', line, 49, 10); atnum++; line++; } line += 2; *next = 0; if (endfid >= cam_info->num_fid) strcpy(next, "end"); else sprintf(next, "%d", endfid); sprintf(next_line, next); V_line(line, " Next:"); V_ques(next, 's', line, 34, 5); V_line(line + 2, "+--------------------------------------------------------------------------+"); V_intrpt_ok(); if (!V_call()) exit(0); if (*next == 0) break; if (strcmp(next, "end") == 0) break; if (sscanf(next, "%d", &endfid) != 1) continue; if (endfid < 0) endfid = 0; if (endfid > cam_info->num_fid) { endfid = cam_info->num_fid - NLINES + 1; if (endfid < 0) endfid = 0; } startfid = endfid; } return 0; }