Crossfire Server, Trunk  R20608
treasure.c File Reference
#include "global.h"
#include <stdlib.h>
#include <string.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 46 of file treasure.c.

Referenced by keyplace(), and lock_and_hide_doors().

#define PASS_DOORS   1

Definition at line 47 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 846 of file treasure.c.

References DOOR, FOR_MAP_FINISH, FOR_MAP_PREPARE, and LOCKED_DOOR.

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 338 of file treasure.c.

References FLAG_MONSTER, FOR_MAP_FINISH, FOR_MAP_PREPARE, freearr_x, freearr_y, GET_MAP_FLAGS, 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 920 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 870 of file treasure.c.

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

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 694 of file treasure.c.

References find_archetype(), freearr_x, freearr_y, object_find_first_free_spot(), 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 546 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 495 of file treasure.c.

References FLAG_ALIVE, FOR_MAP_FINISH, FOR_MAP_PREPARE, freearr_x, freearr_y, GET_MAP_FLAGS, HEAD, P_IS_ALIVE, QUERY_FLAG, and RANDOM.

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 638 of file treasure.c.

References find_spot_in_room_recursive(), free_spots_struct::number_of_free_spots_in_room, RANDOM, 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 594 of file treasure.c.

References freearr_x, freearr_y, free_spots_struct::number_of_free_spots_in_room, RANDOM, 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 388 of file treasure.c.

References add_string(), create_archetype(), RMParms::dungeon_level, RMParms::dungeon_name, find_closest_monster(), find_monster_in_room(), find_spot_in_room(), free_string(), freearr_x, freearr_y, obj::name, NO_PASS_DOORS, object_find_first_free_spot(), object_insert_in_map_at(), object_insert_in_ob(), PASS_DOORS, RANDOM, obj::slaying, snprintf, wall_blocked(), RMParms::Xsize, 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 1005 of file treasure.c.

References add_string(), create_archetype(), DOORED, obj::face, FLAG_REMOVED, HIDDEN, keyplace(), NO_PASS_DOORS, object_free_drop_inventory(), object_insert_in_map_at(), object_remove(), QUERY_FLAG, RANDOM, remove_adjacent_doors(), 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 233 of file treasure.c.

References add_string(), BC_RANDOM, liv::Cha, CONTAINER, create_archetype(), RMParms::difficulty, mapdef::difficulty, find_style(), find_treasurelist(), freearr_x, freearr_y, liv::hp, keyplace(), KEYREQUIRED, obj::level, MIMIC, object_copy_with_inv(), object_find_first_free_spot(), object_free_drop_inventory(), object_insert_in_map_at(), object_insert_in_ob(), object_new(), PASS_DOORS, pick_random_object(), RANDOM, obj::randomitems, obj::slaying, snprintf, obj::stats, TRAPPED, obj::type, 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 92 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(), RANDOM, 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 961 of file treasure.c.

References DOOR, flags, FOR_MAP_FINISH, FOR_MAP_PREPARE, freearr_x, freearr_y, get_map_flags(), obj::map, object_free_drop_inventory(), object_remove(), P_IS_ALIVE, P_OUT_OF_MAP, 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 764 of file treasure.c.

References FLAG_ALIVE, FOR_MAP_FINISH, FOR_MAP_PREPARE, GET_MAP_OB, HEAD, object_free_drop_inventory(), object_remove(), and QUERY_FLAG.

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 798 of file treasure.c.

References create_archetype(), DOORED, freearr_x, freearr_y, object_insert_in_map_at(), remove_monsters(), and wall_blocked().

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 62 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: