/* * Initialize plane_index and (if appropriate) wanted and * wanted_varies at the beginning of a group of planes. */ static void begin_planes(gs_image_enum *penum) { cache_planes(penum); penum->plane_index = -1; next_plane(penum); }
/* Process the next piece of an image. */ int gs_image_next(gs_image_enum * penum, const byte * dbytes, uint dsize, uint * pused) { int px = penum->plane_index; int num_planes = penum->num_planes; int i, code; uint used[GS_IMAGE_MAX_COMPONENTS]; gs_const_string plane_data[GS_IMAGE_MAX_COMPONENTS]; if (penum->planes[px].source.size != 0) return_error(gs_error_rangecheck); for (i = 0; i < num_planes; i++) plane_data[i].size = 0; plane_data[px].data = dbytes; plane_data[px].size = dsize; penum->error = false; code = gs_image_next_planes(penum, plane_data, used); *pused = used[px]; if (code >= 0) next_plane(penum); return code; }
int addplane(void) { PLANE p, *pp, *p1; int i, num_starts, close, rnd, rnd2, pnum; memset(&p, 0, sizeof (p)); p.status = S_MARKED; p.plane_type = atcrandom() % 2; num_starts = sp->num_exits + sp->num_airports; rnd = atcrandom() % num_starts; if (rnd < sp->num_exits) { p.dest_type = T_EXIT; p.dest_no = rnd; } else { p.dest_type = T_AIRPORT; p.dest_no = rnd - sp->num_exits; } /* loop until we get a plane not near another */ for (i = 0; i < num_starts; i++) { /* loop till we get a different start point */ while ((rnd2 = atcrandom() % num_starts) == rnd) ; if (rnd2 < sp->num_exits) { p.orig_type = T_EXIT; p.orig_no = rnd2; p.xpos = sp->exit[rnd2].x; p.ypos = sp->exit[rnd2].y; p.new_dir = p.dir = sp->exit[rnd2].dir; p.altitude = p.new_altitude = 7; close = 0; for (p1 = air.head; p1 != NULL; p1 = p1->next) if (too_close(p1, &p, 4)) { close++; break; } if (close) continue; } else { p.orig_type = T_AIRPORT; p.orig_no = rnd2 - sp->num_exits; p.xpos = sp->airport[p.orig_no].x; p.ypos = sp->airport[p.orig_no].y; p.new_dir = p.dir = sp->airport[p.orig_no].dir; p.altitude = p.new_altitude = 0; } p.fuel = sp->width + sp->height; break; } if (i >= num_starts) return (-1); pnum = next_plane(); if (pnum < 0) return (-1); p.plane_no = pnum; pp = newplane(); memcpy(pp, &p, sizeof (p)); if (pp->orig_type == T_AIRPORT) append(&ground, pp); else append(&air, pp); return (pp->dest_type); }