src/gen-chunk.c
bool chunk_copy(struct chunk *dest, struct chunk *source, int y0, int x0,
				int rotate, bool reflect)
{
	int i;
	int y, x;
	int h = source->height, w = source->width;

	/* Check bounds */
	if (rotate % 1) {
		if ((w + y0 > dest->height) || (h + x0 > dest->width))
			return FALSE;
	} else {
		if ((h + y0 > dest->height) || (w + x0 > dest->width))
			return FALSE;
	}

	/* Write the location stuff */
	for (y = 0; y < h; y++) {
		for (x = 0; x < w; x++) {
			/* Work out where we're going */
			int dest_y = y;
			int dest_x = x;
			symmetry_transform(&dest_y, &dest_x, y0, x0, h, w, rotate, reflect);

			/* Terrain */
			dest->squares[dest_y][dest_x].feat = source->squares[y][x].feat;
			sqinfo_copy(dest->squares[dest_y][dest_x].info,
						source->squares[y][x].info);

			/* Dungeon objects */
			if (square_object(source, y, x)) {
				struct object *obj;
				dest->squares[dest_y][dest_x].obj = square_object(source, y, x);

				for (obj = square_object(source, y, x); obj; obj = obj->next) {
					/* Adjust position */
					obj->iy = dest_y;
					obj->ix = dest_x;
				}
			}

			/* Monsters */
			if (source->squares[y][x].mon > 0) {
				struct monster *source_mon = square_monster(source, y, x);
				struct monster *dest_mon = NULL;
				int idx;

				/* Valid monster */
				if (!source_mon->race)
					continue;

				/* Make a monster */
				idx = mon_pop(dest);

				/* Hope this never happens */
				if (!idx)
					break;

				/* Copy over */
				dest_mon = cave_monster(dest, idx);
				dest->squares[dest_y][dest_x].mon = idx;
				memcpy(dest_mon, source_mon, sizeof(*source_mon));

				/* Adjust stuff */
				dest_mon->midx = idx;
				dest_mon->fy = dest_y;
				dest_mon->fx = dest_x;

				/* Held objects */
				if (source_mon->held_obj)
					dest_mon->held_obj = source_mon->held_obj;
			}

			/* Traps */
			if (source->squares[y][x].trap) {
				struct trap *trap = source->squares[y][x].trap;
				dest->squares[y][x].trap = trap;

				/* Traverse the trap list */
				while (trap) {
					/* Adjust location */
					trap->fy = dest_y;
					trap->fx = dest_x;
					trap = trap->next;
				}
			}

			/* Player */
			if (source->squares[y][x].mon == -1) 
				dest->squares[dest_y][dest_x].mon = -1;
		}
	}

	/* Miscellany */
	for (i = 0; i < z_info->f_max + 1; i++)
		dest->feat_count[i] += source->feat_count[i];

	dest->obj_rating += source->obj_rating;
	dest->mon_rating += source->mon_rating;

	if (source->good_item)
		dest->good_item = TRUE;

	return TRUE;
}
/**
 * Write a chunk, transformed, to a given offset in another chunk.  Note that
 * objects are copied from the old chunk and not retained there
 * \param dest the chunk where the copy is going
 * \param source the chunk being copied
 * \param y0
 * \param x0 
 * \param rotate 
 * \param reflect transformation parameters  - see symmetry_transform()
 * \return success - fails if the copy would not fit in the destination chunk
 */
Write a chunk, transformed, to a given offset in another chunk.
Write a chunk transformed to a given offset in another chunk .
bool chunk_copy(struct chunk *dest, struct chunk *source, int y0, int x0,
				int rotate, bool reflect)
{
	int i;
	int y, x;
	int h = source->height, w = source->width;
	if (rotate % 1) {
		if ((w + y0 > dest->height) || (h + x0 > dest->width))
			return FALSE;
	} else {
		if ((h + y0 > dest->height) || (w + x0 > dest->width))
			return FALSE;
	}
	for (y = 0; y < h; y++) {
		for (x = 0; x < w; x++) {
			int dest_y = y;
			int dest_x = x;
			symmetry_transform(&dest_y, &dest_x, y0, x0, h, w, rotate, reflect);
			dest->squares[dest_y][dest_x].feat = source->squares[y][x].feat;
			sqinfo_copy(dest->squares[dest_y][dest_x].info,
						source->squares[y][x].info);
			if (square_object(source, y, x)) {
				struct object *obj;
				dest->squares[dest_y][dest_x].obj = square_object(source, y, x);
				for (obj = square_object(source, y, x); obj; obj = obj->next) {
					obj->iy = dest_y;
					obj->ix = dest_x;
				}
			}
			if (source->squares[y][x].mon > 0) {
				struct monster *source_mon = square_monster(source, y, x);
				struct monster *dest_mon = NULL;
				int idx;
				if (!source_mon->race)
					continue;
				idx = mon_pop(dest);
				if (!idx)
					break;
				dest_mon = cave_monster(dest, idx);
				dest->squares[dest_y][dest_x].mon = idx;
				memcpy(dest_mon, source_mon, sizeof(*source_mon));
				dest_mon->midx = idx;
				dest_mon->fy = dest_y;
				dest_mon->fx = dest_x;
				if (source_mon->held_obj)
					dest_mon->held_obj = source_mon->held_obj;
			}
			if (source->squares[y][x].trap) {
				struct trap *trap = source->squares[y][x].trap;
				dest->squares[y][x].trap = trap;
				while (trap) {
					trap->fy = dest_y;
					trap->fx = dest_x;
					trap = trap->next;
				}
			}
			if (source->squares[y][x].mon == -1) 
				dest->squares[dest_y][dest_x].mon = -1;
		}
	}
	for (i = 0; i < z_info->f_max + 1; i++)
		dest->feat_count[i] += source->feat_count[i];
	dest->obj_rating += source->obj_rating;
	dest->mon_rating += source->mon_rating;
	if (source->good_item)
		dest->good_item = TRUE;
	return TRUE;
}
bool chunk_copy ( struct chunk * dest , struct chunk * source , int y0 , int x0 , int rotate , bool reflect ) { int i ; int y , x ; int h = source -> height , w = source -> width ; if ( rotate % 1 ) { if ( ( w + y0 > dest -> height ) || ( h + x0 > dest -> width ) ) return FALSE ; } else { if ( ( h + y0 > dest -> height ) || ( w + x0 > dest -> width ) ) return FALSE ; } for ( y = 0 ; y < h ; y ++ ) { for ( x = 0 ; x < w ; x ++ ) { int dest_y = y ; int dest_x = x ; symmetry_transform ( & dest_y , & dest_x , y0 , x0 , h , w , rotate , reflect ) ; dest -> squares [ dest_y ] [ dest_x ] . feat = source -> squares [ y ] [ x ] . feat ; sqinfo_copy ( dest -> squares [ dest_y ] [ dest_x ] . info , source -> squares [ y ] [ x ] . info ) ; if ( square_object ( source , y , x ) ) { struct object * obj ; dest -> squares [ dest_y ] [ dest_x ] . obj = square_object ( source , y , x ) ; for ( obj = square_object ( source , y , x ) ; obj ; obj = obj -> next ) { obj -> iy = dest_y ; obj -> ix = dest_x ; } } if ( source -> squares [ y ] [ x ] . mon > 0 ) { struct monster * source_mon = square_monster ( source , y , x ) ; struct monster * dest_mon = NULL ; int idx ; if ( ! source_mon -> race ) continue ; idx = mon_pop ( dest ) ; if ( ! idx ) break ; dest_mon = cave_monster ( dest , idx ) ; dest -> squares [ dest_y ] [ dest_x ] . mon = idx ; memcpy ( dest_mon , source_mon , sizeof ( * source_mon ) ) ; dest_mon -> midx = idx ; dest_mon -> fy = dest_y ; dest_mon -> fx = dest_x ; if ( source_mon -> held_obj ) dest_mon -> held_obj = source_mon -> held_obj ; } if ( source -> squares [ y ] [ x ] . trap ) { struct trap * trap = source -> squares [ y ] [ x ] . trap ; dest -> squares [ y ] [ x ] . trap = trap ; while ( trap ) { trap -> fy = dest_y ; trap -> fx = dest_x ; trap = trap -> next ; } } if ( source -> squares [ y ] [ x ] . mon == -1 ) dest -> squares [ dest_y ] [ dest_x ] . mon = -1 ; } } for ( i = 0 ; i < z_info -> f_max + 1 ; i ++ ) dest -> feat_count [ i ] += source -> feat_count [ i ] ; dest -> obj_rating += source -> obj_rating ; dest -> mon_rating += source -> mon_rating ; if ( source -> good_item ) dest -> good_item = TRUE ; return TRUE ; }
Write a chunk, transformed, to a given offset in another chunk.
Write a chunk transformed to a given offset in another chunk .
/* Check bounds */ /* Write the location stuff */ /* Work out where we're going */ /* Terrain */ /* Dungeon objects */ /* Adjust position */ /* Monsters */ /* Valid monster */ /* Make a monster */ /* Hope this never happens */ /* Copy over */ /* Adjust stuff */ /* Held objects */ /* Traps */ /* Traverse the trap list */ /* Adjust location */ /* Player */ /* Miscellany */