Crossfire Server, Branches 1.12  R18729
treasure.c File Reference
#include <global.h>
#include <random_map.h>
#include <rproto.h>
+ Include dependency graph for treasure.c:

Go to the source code of this file.

Data Structures

struct  free_spots_struct
 

Macros

#define CONCENTRATED   1 /* all the treasure is at the C's for onions. */
 
#define DOORED   8 /* treasure has doors around it. */
 
#define FILLED   128 /* Fill/tile the entire map with treasure */
 
#define HIDDEN   2 /* doors to treasure are hidden. */
 
#define KEYREQUIRED   4 /* chest has a key, which is placed randomly in the map. */
 
#define LAST_OPTION   64 /* set this to the last real option, for random */
 
#define NO_PASS_DOORS   0
 
#define PASS_DOORS   1
 
#define RICH   64 /* 2x as much treasure as default */
 
#define SPARSE   32 /* 1/2 as much treasure as default */
 
#define TRAPPED   16 /* trap dropped in same location as chest. */
 

Typedefs

typedef struct free_spots_struct free_spots_struct
 

Functions

static objectdoor_in_square (mapstruct *map, int x, int y)
 
objectfind_closest_monster (mapstruct *map, int x, int y, RMParms *RP)
 
object ** find_doors_in_room (mapstruct *map, int x, int y, RMParms *RP)
 
void find_doors_in_room_recursive (char **layout, mapstruct *map, int x, int y, object **doorlist, int *ndoors, RMParms *RP)
 
void find_enclosed_spot (mapstruct *map, int *cx, int *cy, RMParms *RP)
 
objectfind_monster_in_room (mapstruct *map, int x, int y, RMParms *RP)
 
objectfind_monster_in_room_recursive (char **layout, mapstruct *map, int x, int y, RMParms *RP)
 
int find_spot_in_room (mapstruct *map, int x, int y, int *kx, int *ky, RMParms *RP)
 
static void find_spot_in_room_recursive (char **layout, int x, int y, RMParms *RP, free_spots_struct *spots)
 
int keyplace (mapstruct *map, int x, int y, char *keycode, int door_flag, int n_keys, RMParms *RP)
 
void lock_and_hide_doors (object **doorlist, mapstruct *map, int opts, RMParms *RP)
 
objectplace_chest (int treasureoptions, int x, int y, mapstruct *map, mapstruct *style_map, int n_treasures, RMParms *RP)
 
void place_treasure (mapstruct *map, char **layout, char *treasure_style, int treasureoptions, RMParms *RP)
 
static void remove_adjacent_doors (object *door)
 
void remove_monsters (int x, int y, mapstruct *map)
 
static object ** surround_by_doors (mapstruct *map, char **layout, int x, int y, int opts)
 
int wall_blocked (mapstruct *m, int x, int y)
 

Detailed Description

This deals with inserting treasures in random maps.

Definition in file treasure.c.

Macro Definition Documentation

#define NO_PASS_DOORS   0

Definition at line 57 of file treasure.c.

Referenced by keyplace(), and lock_and_hide_doors().

#define PASS_DOORS   1

Definition at line 58 of file treasure.c.

Referenced by keyplace(), and place_chest().

Typedef Documentation

Function Documentation

static object* door_in_square ( mapstruct map,
int  x,
int  y 
)
static

Returns the first door in this square, or NULL if there isn't a door.

Parameters
map
x
ywhere to look.
Returns
door, or NULL if none found.
Todo:
isn't there a function for that in map.c?

Definition at line 801 of file treasure.c.

References obj::above, DOOR, GET_MAP_OB, LOCKED_DOOR, and obj::type.

Referenced by find_doors_in_room_recursive().

+ Here is the caller graph for this function:

object* find_closest_monster ( mapstruct map,
int  x,
int  y,
RMParms RP 
)

finds the closest monster and returns him, regardless of doors or walls

Parameters
map
x
ywhere to look from.
RPparameters for random map.
Returns
monster, or NULL if none found.
Todo:
shouldn't it search further away?

Definition at line 311 of file treasure.c.

References obj::above, FLAG_MONSTER, freearr_x, freearr_y, GET_MAP_FLAGS, GET_MAP_OB, P_IS_ALIVE, QUERY_FLAG, and SIZEOFFREE.

Referenced by keyplace().

+ Here is the caller graph for this function:

object** find_doors_in_room ( mapstruct map,
int  x,
int  y,
RMParms RP 
)

Gets all doors in a room.

Parameters
mapmap to look into.
x
ypoint of a room to find door for.
RPmap parameters.
Returns
door list. Should be free()d be caller. NULL-terminated.
Todo:
couldn't layout be given instead of being computed?

Definition at line 871 of file treasure.c.

References find_doors_in_room_recursive(), wall_blocked(), RMParms::Xsize, and RMParms::Ysize.

Referenced by place_treasure().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void find_doors_in_room_recursive ( char **  layout,
mapstruct map,
int  x,
int  y,
object **  doorlist,
int *  ndoors,
RMParms RP 
)

The workhorse routine, which finds the doors in a room

Parameters
layout
map
x
yrandom map to look into.
doorlistlist of doors.
ndoorsnumber of found doors.
RPmap parameters.

Definition at line 824 of file treasure.c.

References door_in_square(), freearr_x, freearr_y, llevError, and LOG().

Referenced by find_doors_in_room().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void find_enclosed_spot ( mapstruct map,
int *  cx,
int *  cy,
RMParms RP 
)

Searches the map for a spot with walls around it. The more walls the better, but it'll settle for 1 wall, or even 0, but it'll return 0 if no FREE spots are found.

Parameters
mapwhere to look.
cx
cywhere to look, and coordinates of found spot. -1 if no spot found.
RPparameters of the random map.

Definition at line 653 of file treasure.c.

References find_archetype(), find_first_free_spot(), freearr_x, freearr_y, SIZEOFFREE1, and surround_flag3().

Referenced by place_treasure().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

object* find_monster_in_room ( mapstruct map,
int  x,
int  y,
RMParms RP 
)

Find a monster in a room. Real work is done by find_monster_in_room_recursive().

Parameters
mapgenerated map.
x
ywhere to look from.
RPrandom map parameters.
Returns
monster, or NULL if none found.
Todo:
couldn't the layout be given instead of being calculated?

Definition at line 513 of file treasure.c.

References find_monster_in_room_recursive(), wall_blocked(), RMParms::Xsize, and RMParms::Ysize.

Referenced by keyplace().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

object* find_monster_in_room_recursive ( char **  layout,
mapstruct map,
int  x,
int  y,
RMParms RP 
)

A recursive routine which will return a monster, eventually, if there is one. One should really call find_monster_in_room().

Parameters
layoutmap layout.
mapgenerated map.
x
ywhere to look from.
RPrandom map parameters.
Returns
monster, or NULL if none found.

Definition at line 465 of file treasure.c.

References obj::above, FLAG_ALIVE, freearr_x, freearr_y, GET_MAP_FLAGS, GET_MAP_OB, P_IS_ALIVE, and QUERY_FLAG.

Referenced by find_monster_in_room().

+ Here is the caller graph for this function:

int find_spot_in_room ( mapstruct map,
int  x,
int  y,
int *  kx,
int *  ky,
RMParms RP 
)

Find a random non-blocked spot in this room to drop a key. Returns 1 if success, 0 else.

Parameters
mapmap to look into.
x
ywhere to look from.
[out]kx
[out]kyfound spot if 1 is returned.
RPrandom map parameters.
Returns
1 if spot found, 0 else.
Todo:
couldn't layout be given instead of being computed?

Definition at line 600 of file treasure.c.

References find_spot_in_room_recursive(), free_spots_struct::number_of_free_spots_in_room, free_spots_struct::room_free_spots_x, free_spots_struct::room_free_spots_y, wall_blocked(), RMParms::Xsize, and RMParms::Ysize.

Referenced by keyplace().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void find_spot_in_room_recursive ( char **  layout,
int  x,
int  y,
RMParms RP,
free_spots_struct spots 
)
static

the workhorse routine, which finds the free spots in a room: a datastructure of free points is set up, and a position chosen from that datastructure.

Parameters
layoutmap layout.
x
ywhere to look from.
RPrandom map parameters.
spotscurrently found free spots.

Definition at line 559 of file treasure.c.

References freearr_x, freearr_y, free_spots_struct::number_of_free_spots_in_room, free_spots_struct::room_free_spots_x, and free_spots_struct::room_free_spots_y.

Referenced by find_spot_in_room().

+ Here is the caller graph for this function:

int keyplace ( mapstruct map,
int  x,
int  y,
char *  keycode,
int  door_flag,
int  n_keys,
RMParms RP 
)

Places keys in the map, preferably in something alive.

The idea is that you call keyplace on x,y where a door is, and it'll make sure a key is placed on both sides of the door.

Parameters
map
x
ywhere to put a key.
keycodekeycode is the key's code.
door_flagif NO_PASS_DOORS won't cross doors or walls to keyplace, PASS_DOORS will. if PASS_DOORS is set, the x & y values that are passed in are basically meaningless - IMO, it is a bit of misnomer, as when it is set, it just randomly chooses spaces on the map, ideally finding a close monster, to put the key in. In fact, if PASS_DOORS is set, there is no guarantee that the keys will be on both sides of the door - it may happen by randomness, but the code doesn't work to make sure it happens.
n_keysnumber of keys to place. If 1, it will place 1 key. Else, it will place 2-4 keys.
RPrandom map parameters.
Returns
1 if key was successfully placed, 0 else.

Definition at line 361 of file treasure.c.

References add_string(), create_archetype(), distance(), RMParms::dungeon_level, RMParms::dungeon_name, find_closest_monster(), find_first_free_spot(), find_monster_in_room(), find_spot_in_room(), free_string(), freearr_x, freearr_y, insert_ob_in_map(), insert_ob_in_ob(), obj::name, NO_PASS_DOORS, PASS_DOORS, obj::slaying, snprintf(), wall_blocked(), obj::x, RMParms::Xsize, obj::y, and RMParms::Ysize.

Referenced by lock_and_hide_doors(), and place_chest().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void lock_and_hide_doors ( object **  doorlist,
mapstruct map,
int  opts,
RMParms RP 
)

Locks and/or hides all the doors in doorlist, or does nothing if opts doesn't say to lock/hide doors. Note that some doors can be not locked if no good spot to put a key was found.

Parameters
doorlistdoors to list. NULL-terminated.
mapmap we're working on.
optsoptions.
RPmap parameters.
Todo:
document opts. Isn't it part of RP?

Definition at line 952 of file treasure.c.

References add_string(), create_archetype(), DOORED, obj::face, FLAG_REMOVED, free_object(), HIDDEN, insert_ob_in_map(), keyplace(), NO_PASS_DOORS, QUERY_FLAG, remove_adjacent_doors(), remove_ob(), retrofit_joined_wall(), obj::slaying, snprintf(), obj::x, and obj::y.

Referenced by place_treasure().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

object* place_chest ( int  treasureoptions,
int  x,
int  y,
mapstruct map,
mapstruct style_map,
int  n_treasures,
RMParms RP 
)

Put a chest into the map. near x and y, with the treasure style determined (may be null, or may be a treasure list from lib/treasures, if the global variable "treasurestyle" is set to that treasure list's name

Parameters
treasureoptionsoptions.
x
yaround which spot to put treasure.
mapmap to put on.
style_mapunused.
n_treasures?
RPparameters the map was generated from.
Returns
inserted chest, NULL for failure.
Todo:
document treasureoptions. Clean parameters. Check meaning of chest hp's field.

Definition at line 232 of file treasure.c.

References add_string(), obj::arch, arch_to_object(), BC_RANDOM, liv::Cha, copy_object(), create_archetype(), RMParms::difficulty, find_first_free_spot(), find_style(), find_treasurelist(), free_object(), freearr_x, freearr_y, liv::hp, insert_ob_in_map(), insert_ob_in_ob(), keyplace(), KEYREQUIRED, obj::level, PASS_DOORS, pick_random_object(), obj::randomitems, obj::slaying, snprintf(), obj::stats, TRAPPED, wall_blocked(), obj::x, and obj::y.

Referenced by place_treasure().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void place_treasure ( mapstruct map,
char **  layout,
char *  treasure_style,
int  treasureoptions,
RMParms RP 
)

Place treasures in the map. map, (required) layout, (required) treasure style (may be empty or NULL, or "none" to cause no treasure.) treasureoptions (may be 0 for random choices or positive)

Parameters
mapwhere to insert to.
layoutlayout the map was generated from.
treasure_styletreasure style. May be empty or NULL for random style, or "none" for no treasures.
treasureoptionstreasure options.
RPrandom map parameters.
Todo:
flags for treasureoptions.

Definition at line 101 of file treasure.c.

References BC_RANDOM, CONCENTRATED, RMParms::difficulty, DOORED, find_doors_in_room(), find_enclosed_spot(), find_style(), HIDDEN, LAST_OPTION, lock_and_hide_doors(), RMParms::map_layout_style, ONION_LAYOUT, place_chest(), RICH, snprintf(), SPARSE, SPIRAL_LAYOUT, SQUARE_SPIRAL_LAYOUT, surround_by_doors(), RMParms::symmetry_used, RMParms::total_map_hp, wall_blocked(), obj::x, RMParms::Xsize, obj::y, and RMParms::Ysize.

Referenced by generate_random_map().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static void remove_adjacent_doors ( object door)
static

This removes any 'normal' doors around the specified door. This is used for lock_and_hide_doors() below - it doesn't make sense to have a locked door right behind a normal door, so lets remove the normal ones. It also fixes key placement issues.

Parameters
doordoor around which to remove unlocked doors.

Definition at line 910 of file treasure.c.

References obj::above, DOOR, flags, free_object(), freearr_x, freearr_y, get_map_flags(), GET_MAP_OB, obj::map, P_IS_ALIVE, P_OUT_OF_MAP, remove_ob(), obj::type, obj::x, and obj::y.

Referenced by lock_and_hide_doors().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void remove_monsters ( int  x,
int  y,
mapstruct map 
)

Remove living things on specified spot.

Parameters
x
y
mapwhere to remove.

Definition at line 722 of file treasure.c.

References obj::above, FLAG_ALIVE, free_object(), GET_MAP_OB, obj::head, QUERY_FLAG, and remove_ob().

Referenced by surround_by_doors().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static object ** surround_by_doors ( mapstruct map,
char **  layout,
int  x,
int  y,
int  opts 
)
static

Surrounds the point x,y by doors, so as to enclose something, like a chest. It only goes as far as the 8 squares surrounding, and it'll remove any monsters it finds.

Parameters
mapmap to work on.
layoutmap's layout.
x
ypoint to surround.
optsflags.
Returns
array of generated doors, NULL-terminated. Should be freed by caller.
Todo:
document opts.

Definition at line 755 of file treasure.c.

References create_archetype(), DOORED, freearr_x, freearr_y, insert_ob_in_map(), remove_monsters(), wall_blocked(), obj::x, and obj::y.

Referenced by place_treasure().

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

int wall_blocked ( mapstruct m,
int  x,
int  y 
)

Returns true if square x,y has P_NO_PASS set, which is true for walls and doors but not monsters. This function is not map tile aware.

Parameters
m
x
ymap and coordinates to check for.
Returns
non zero if blocked, 0 else.

Definition at line 73 of file treasure.c.

References GET_MAP_MOVE_BLOCK, MOVE_BLOCK_DEFAULT, and OUT_OF_REAL_MAP.

Referenced by find_doors_in_room(), find_monster_in_room(), find_spot_in_room(), keyplace(), place_chest(), place_exits(), place_treasure(), surround_by_doors(), and surround_flag4().

+ Here is the caller graph for this function: