Crossfire Server, Trunk
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, 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

◆ CONCENTRATED

#define CONCENTRATED   1 /* all the treasure is at the C's for onions. */

Definition at line 35 of file treasure.c.

◆ DOORED

#define DOORED   8 /* treasure has doors around it. */

Definition at line 38 of file treasure.c.

◆ FILLED

#define FILLED   128 /* Fill/tile the entire map with treasure */

Definition at line 42 of file treasure.c.

◆ HIDDEN

#define HIDDEN   2 /* doors to treasure are hidden. */

Definition at line 36 of file treasure.c.

◆ KEYREQUIRED

#define KEYREQUIRED   4 /* chest has a key, which is placed randomly in the map. */

Definition at line 37 of file treasure.c.

◆ LAST_OPTION

#define LAST_OPTION   64 /* set this to the last real option, for random */

Definition at line 43 of file treasure.c.

◆ NO_PASS_DOORS

#define NO_PASS_DOORS   0

Definition at line 46 of file treasure.c.

◆ PASS_DOORS

#define PASS_DOORS   1

Definition at line 47 of file treasure.c.

◆ RICH

#define RICH   64 /* 2x as much treasure as default */

Definition at line 41 of file treasure.c.

◆ SPARSE

#define SPARSE   32 /* 1/2 as much treasure as default */

Definition at line 40 of file treasure.c.

◆ TRAPPED

#define TRAPPED   16 /* trap dropped in same location as chest. */

Definition at line 39 of file treasure.c.

Typedef Documentation

◆ free_spots_struct

Function Documentation

◆ door_in_square()

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, LOCKED_DOOR, disinfect::map, Ice::tmp, diamondslots::x, and diamondslots::y.

Referenced by find_doors_in_room_recursive().

+ Here is the caller graph for this function:

◆ find_closest_monster()

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

References FLAG_MONSTER, FOR_MAP_FINISH, FOR_MAP_PREPARE, freearr_x, freearr_y, GET_MAP_FLAGS, disinfect::map, P_IS_ALIVE, QUERY_FLAG, SIZEOFFREE, diamondslots::x, and diamondslots::y.

Referenced by keyplace().

+ Here is the caller graph for this function:

◆ find_doors_in_room()

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(), disinfect::map, wall_blocked(), diamondslots::x, RMParms::Xsize, diamondslots::y, and RMParms::Ysize.

Referenced by place_treasure().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ find_doors_in_room_recursive()

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(), disinfect::map, RANDOM, diamondslots::x, and diamondslots::y.

Referenced by find_doors_in_room().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ find_enclosed_spot()

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

References archininventory::arch, find_archetype(), freearr_x, freearr_y, disinfect::map, object_find_first_free_spot(), SIZEOFFREE1, surround_flag3(), diamondslots::x, and diamondslots::y.

Referenced by place_treasure().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ find_monster_in_room()

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

References find_monster_in_room_recursive(), disinfect::map, wall_blocked(), diamondslots::x, RMParms::Xsize, diamondslots::y, and RMParms::Ysize.

Referenced by keyplace().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ find_monster_in_room_recursive()

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

References FLAG_ALIVE, FOR_MAP_FINISH, FOR_MAP_PREPARE, freearr_x, freearr_y, GET_MAP_FLAGS, HEAD, disinfect::map, P_IS_ALIVE, QUERY_FLAG, RANDOM, diamondslots::x, and diamondslots::y.

Referenced by find_monster_in_room().

+ Here is the caller graph for this function:

◆ find_spot_in_room()

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

References find_spot_in_room_recursive(), disinfect::map, 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(), diamondslots::x, RMParms::Xsize, diamondslots::y, and RMParms::Ysize.

Referenced by keyplace().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ find_spot_in_room_recursive()

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 591 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, free_spots_struct::room_free_spots_y, diamondslots::x, and diamondslots::y.

Referenced by find_spot_in_room().

+ Here is the caller graph for this function:

◆ keyplace()

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 385 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, hall_of_fame::keys, disinfect::map, obj::name, NO_PASS_DOORS, object_find_first_free_spot(), object_insert_in_map_at(), object_insert_in_ob(), PASS_DOORS, RANDOM, obj::slaying, wall_blocked(), diamondslots::x, RMParms::Xsize, diamondslots::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:

◆ lock_and_hide_doors()

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(), disinfect::map, 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, 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:

◆ place_chest()

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

Put a chest into the map, near x and y, with a chest from the styles/cheststyles map.

Parameters
treasureoptionsoptions.
x
yaround which spot to put treasure.
mapmap to put on.
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 220 of file treasure.c.

References add_string(), BC_RANDOM, liv::Cha, RMParms::cheststyle, create_archetype(), RMParms::difficulty, find_style(), find_treasurelist(), freearr_x, freearr_y, liv::hp, keyplace(), KEYREQUIRED, obj::level, disinfect::map, 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, obj::stats, TRAPPED, TREASURE, obj::type, wall_blocked(), diamondslots::x, obj::x, diamondslots::y, and obj::y.

Referenced by place_treasure().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ place_treasure()

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 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 NULL or "none" for no treasures, any other value to put 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(), HIDDEN, LAST_OPTION, lock_and_hide_doors(), disinfect::map, RMParms::map_layout_style, ONION_LAYOUT, place_chest(), RANDOM, RICH, 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:

◆ remove_adjacent_doors()

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(), m, obj::map, object_free_drop_inventory(), object_remove(), P_IS_ALIVE, P_OUT_OF_MAP, Ice::tmp, diamondslots::x, obj::x, diamondslots::y, 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:

◆ remove_monsters()

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, disinfect::map, object_free_drop_inventory(), object_remove(), QUERY_FLAG, Ice::tmp, diamondslots::x, and diamondslots::y.

Referenced by surround_by_doors().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ surround_by_doors()

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, disinfect::map, object_insert_in_map_at(), remove_monsters(), wall_blocked(), diamondslots::x, guild_entry::x1, diamondslots::y, and guild_entry::y1.

Referenced by place_treasure().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ wall_blocked()

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, m, MOVE_BLOCK_DEFAULT, OUT_OF_REAL_MAP, ring_occidental_mages::r, diamondslots::x, and diamondslots::y.

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: