#ifndef _UTIL_H_fdc4f28a_ #define _UTIL_H_fdc4f28a_ /* * APIs exported by util.c. Assorted utility routines that didn't seem * to me to fall into other categories. */ #include "structs.h" /* * Always returns false, and has the calling signature of an object ops * `collapsible' function. */ extern int never_collapsible(OBJ *, OBJ *); /* * Always returns true, and has the calling signature of an object ops * `collapsible' function. */ extern int always_collapsible(OBJ *, OBJ *); /* * Always returns false, and has the calling signature of an object ops * `identical' function. */ extern int never_identical(OBJ *, OBJ *); /* * Always returns true, and has the calling signature of an object ops * `identical' function. */ extern int always_identical(OBJ *, OBJ *); /* * Returns the square of the (Euclidean) distance between two cells on * the same level. This knows about LVF_WRAPAROUND. This panics if * handed LOCs that aren't on the same level. */ extern int distance2(LOC *, LOC *); /* * Returns the L-infinity distance between two cells on the same level, * that is, the larger of the difference in X coordinates and the * difference in Y coordinates. This knows about LVF_WRAPAROUND. * This panics if handed LOCs that aren't on the same level. */ extern int distancei(LOC *, LOC *); /* * Return true iff the argument is a vowel. This is specific to ASCII * and English...but so is much of the rest of the game. */ extern int vowel(char); /* * movecell(c,dx,dy,wrap) moves a distance (dx,dy) from c, returning * the cell reached. If wrap is true or if the level has * LVF_WRAPAROUND set, the delta can wrap. Moving off the edge of a * level when not wrapping returns nil. */ extern LOC *movecell(LOC *, int, int, int); /* * dirkey(key,dxp,dyp,dxyp,oflagsp,iflags) takes key as a motion * command (one of hjklyubn, possibly uppercase or control-modified) * and some flags. iflags can include zero or more of DK_NOCTL and * DK_NOCAPS; these suppress recognition of, respectively, * control-modified and uppercase motion commands. If key is a valid * motion command, taking iflags into account, then up to four things * are written through the remaining arguments: the corresponding X * delta through dxp, the Y delta through dyp, both deltas as an XY * through dxyp, and a flags value with 0, DK_CTL, or DK_CAPS through * oflagsp. If any of these last four are nil, that write is skipped. */ extern int dirkey(int, int *, int *, XY *, int *, int); #define DK_CTL 0x00000001 #define DK_CAPS 0x00000002 #define DK_NOCTL 0x00000004 #define DK_NOCAPS 0x00000008 /* * These take an (X,Y) delta and rotate it clockwise 90° (turn_r), * counterclockwise 90° (turn_l), clockwise 45° (turn_r45), or * counterclockwise 45° (turn_l45). The 45° turns, of course, switch * between both-coordinate steps and single-coordinate steps, meaning * their Euclidean length switches betwen 1 and sqrt(2). */ extern XY turn_r(XY); extern XY turn_l(XY); extern XY turn_r45(XY); extern XY turn_l45(XY); /* * This returns its second or third argument depending on whether the * monster is the player avatar (second arg) or not (third arg). */ extern const char *pickverb(MONST *, const char *, const char *); /* * Reset a weapon/armour bonus roll string, given the plusses for it. * Arguments are a pointer to the char * for the roll string and the * plusses (or, if negative, minuses). The string should be * initialized to something that can be free()d, like nil. */ extern void reset_roll_string(char **, int); /* * Indicate whether a space can be occupied (return true) or not * (false). */ extern int occupiable(LOC *); /* * Trace a ray from a location in a direction, calling a function for * each cell passed through, until the function returns nonzero * (indicating it hit something). The first cell hit is not the start * cell, but rather one adjacent to it. Optionally, delay after each * call to the function. * * In ray(lc,dx,dy,cb,ms): * - lc is the start location * - dx and dy are the direction the ray is to proceed in * - cb is the function to call for each cell * - ms is the number of milliseconds to delay after each call to cb * * In (*cb)(lc,n): * - lc is the loc being hit * - n is the number of cells hit so far (0 for first call) */ extern void ray(LOC *, int, int, int (*)(LOC *, int), int); /* * Screen symbol for something moving in a direction given as dx,dy. */ extern char dirsym(int, int); #endif