Angband
Macros | Functions | Variables
gen-chunk.c File Reference

Handling of chunks of cave. More...

#include "angband.h"
#include "cave.h"
#include "generate.h"
#include "init.h"
#include "mon-make.h"
#include "obj-util.h"
#include "trap.h"

Macros

#define CHUNK_LIST_INCR   10
 

Functions

struct chunkchunk_write (int y0, int x0, int height, int width, bool monsters, bool objects, bool traps)
 Write a chunk to memory and return a pointer to it. More...
 
void chunk_list_add (struct chunk *c)
 Add an entry to the chunk list - any problems with the length of this will be more in the memory used by the chunks themselves rather than the list. More...
 
bool chunk_list_remove (char *name)
 Remove an entry from the chunk list, return whether it was found. More...
 
struct chunkchunk_find_name (char *name)
 Find a chunk by name. More...
 
bool chunk_find (struct chunk *c)
 Find a chunk by pointer. More...
 
void symmetry_transform (int *y, int *x, int y0, int x0, int height, int width, int rotate, bool reflect)
 Transform y, x coordinates by rotation, reflection and translation Stolen from PosChengband. More...
 
bool chunk_copy (struct chunk *dest, struct chunk *source, int y0, int x0, int rotate, bool reflect)
 Write a chunk, transformed, to a given offset in another chunk. More...
 
void chunk_validate_objects (struct chunk *c)
 Validate that the chunk contains no NULL objects. More...
 

Variables

struct chunk ** chunk_list
 list of pointers to saved chunks More...
 
u16b chunk_list_max = 0
 current max actual chunk index More...
 

Detailed Description

Handling of chunks of cave.

Copyright (c) 2014 Nick McConnell

This work is free software; you can redistribute it and/or modify it under the terms of either:

a) the GNU General Public License as published by the Free Software Foundation, version 2, or

b) the "Angband licence": This software may be copied and distributed for educational, research, and not for profit purposes provided that this copyright and statement are included in all such copies. Other copyrights may also apply.

This file maintains a list of saved chunks of world which can be reloaded at any time. The intitial example of this is the town, which is saved immediately after generation and restored when the player returns there.

The copying routines are also useful for generating a level in pieces and then copying those pieces into the actual level chunk.

Macro Definition Documentation

◆ CHUNK_LIST_INCR

#define CHUNK_LIST_INCR   10

Function Documentation

◆ chunk_copy()

bool chunk_copy ( struct chunk dest,
struct chunk source,
int  y0,
int  x0,
int  rotate,
bool  reflect 
)

Write a chunk, transformed, to a given offset in another chunk.

Note that objects are copied from the old chunk and not retained there

Parameters
destthe chunk where the copy is going
sourcethe chunk being copied
y0transformation parameters - see symmetry_transform()
x0transformation parameters - see symmetry_transform()
rotatetransformation parameters - see symmetry_transform()
reflecttransformation parameters - see symmetry_transform()
Returns
success - fails if the copy would not fit in the destination chunk

References cave_monster(), angband_constants::f_max, square::feat, chunk::feat_count, trap::fx, monster::fx, trap::fy, monster::fy, chunk::good_item, h, chunk::height, monster::held_obj, i, square::info, object::ix, object::iy, mem_realloc(), monster::midx, square::mon, mon_pop(), chunk::mon_rating, trap::next, object::next, NULL, square::obj, chunk::obj_max, chunk::obj_rating, chunk::objects, object::oidx, monster::race, sqinfo_copy, square_monster(), square_object(), chunk::squares, symmetry_transform(), square::trap, w, chunk::width, and z_info.

Referenced by gauntlet_gen(), hard_centre_gen(), lair_gen(), and town_gen().

◆ chunk_find()

bool chunk_find ( struct chunk c)

Find a chunk by pointer.

Parameters
cthe actual pointer to the sought chunk
Returns
if it was found

References chunk_list_max, and i.

◆ chunk_find_name()

struct chunk* chunk_find_name ( char *  name)

Find a chunk by name.

Parameters
namethe name of the chunk being sought
Returns
the pointer to the chunk

References chunk_list_max, i, and NULL.

Referenced by cave_generate(), and town_gen().

◆ chunk_list_add()

void chunk_list_add ( struct chunk c)

Add an entry to the chunk list - any problems with the length of this will be more in the memory used by the chunks themselves rather than the list.

Parameters
cthe chunk being added to the list

References CHUNK_LIST_INCR, chunk_list_max, mem_realloc(), and mem_zalloc().

Referenced by cave_generate(), and rd_chunks().

◆ chunk_list_remove()

bool chunk_list_remove ( char *  name)

Remove an entry from the chunk list, return whether it was found.

Parameters
namethe name of the chunk being removed from the list
Returns
whether it was found; success means it was successfully removed

References CHUNK_LIST_INCR, chunk_list_max, i, mem_realloc(), and NULL.

◆ chunk_validate_objects()

void chunk_validate_objects ( struct chunk c)

Validate that the chunk contains no NULL objects.

Only checks for nonzero tval.

Parameters
cis the chunk to validate.

References chunk::height, monster::held_obj, square::mon, object::next, square_monster(), square_object(), chunk::squares, object::tval, and chunk::width.

Referenced by cave_generate().

◆ chunk_write()

struct chunk* chunk_write ( int  y0,
int  x0,
int  height,
int  width,
bool  monsters,
bool  objects,
bool  traps 
)

Write a chunk to memory and return a pointer to it.

Optionally write monsters, objects and/or traps, and in those cases delete those things from the source chunk

Parameters
y0coordinates of the top left corner of the chunk being written
x0coordinates of the top left corner of the chunk being written
heightdimensions of the chunk being written
widthdimensions of the chunk being written
monsterswhether monsters get written
objectswhether objects get written
trapswhether traps get written
Returns
the memory location of the chunk

References cave, cave_monster(), cave_new(), delete_monster(), square::feat, trap::fx, monster::fx, trap::fy, monster::fy, height, monster::held_obj, square::info, object::ix, object::iy, square::mon, new, NULL, monster::race, sqinfo_copy, square_monster(), square_object(), chunk::squares, square::trap, and width.

Referenced by cave_generate().

◆ symmetry_transform()

void symmetry_transform ( int y,
int x,
int  y0,
int  x0,
int  height,
int  width,
int  rotate,
bool  reflect 
)

Transform y, x coordinates by rotation, reflection and translation Stolen from PosChengband.

Parameters
ythe coordinates being transformed
xthe coordinates being transformed
y0how much the coordinates are being translated
x0how much the coordinates are being translated
heightheight of the chunk
widthwidth of the chunk
rotatehow much to rotate, in multiples of 90 degrees clockwise
reflectwhether to reflect horizontally

References i.

Referenced by chunk_copy().

Variable Documentation

◆ chunk_list

struct chunk** chunk_list

list of pointers to saved chunks

◆ chunk_list_max

u16b chunk_list_max = 0

current max actual chunk index

Referenced by chunk_find(), chunk_find_name(), chunk_list_add(), chunk_list_remove(), cleanup_angband(), and wr_chunks().