dungeon.h 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490
  1. /* =============================================================================
  2. * PROGRAM: ularn
  3. * FILENAME: dungeon.h
  4. *
  5. * DESCRIPTION:
  6. * Dungeon levels module.
  7. * This module provides functions to create, load, save etc dungeon levels.
  8. *
  9. * =============================================================================
  10. * EXPORTED VARIABLES
  11. *
  12. * item : The item at each location on the current level
  13. * know : What the player beleives is at each location
  14. * moved : The monster moved status for each dungeon location
  15. * stealth : The monster stealth status for each dungeon location
  16. * hitp : The monster hit points for each dungeon location
  17. * iarg : The item arg for each dungeon location
  18. * screen : Screen data used in moving monsters
  19. * mitem : The monster and items it has stolen for each dungeon location
  20. * beenhere : Which dungeon levels have been visited
  21. * level : The current dungeon level
  22. * levelname : The name of each dungeon level
  23. *
  24. * =============================================================================
  25. * EXPORTED FUNCTIONS
  26. *
  27. * init_cells : Allocate dungeon storage
  28. * free_cells : Free dungeon storage
  29. * cgood : Check if a cell is empty (monster and/or item)
  30. * dropgold : Drop gold around the player
  31. * fillmonst : Attempt to put a monster into the dungeon
  32. * eat : Eat a maze in a level filled with walls
  33. * savelevel : Save the current dungeon level into storage
  34. * getlevel : Get the current level from storage.
  35. * AnalyseWalls : Calculate wall tiles based on adjacent walls.
  36. * newcavelevel : Function to go to a different cave level, creating if reqd
  37. * verifyxy : Verify x and y coordinates are on the map, adjusting if reqd
  38. * checkxy : Just check if x, y are on the map, making no changes.
  39. * createitem : Create an item
  40. * something : Create a random item
  41. * newobject : Return a randomly selected item
  42. * write_levels : Write dungeon levels to the save file
  43. * read_levels : Read dungeon levels from the save file
  44. *
  45. * =============================================================================
  46. */
  47. #ifndef __DUNGEON_H
  48. #define __DUNGEON_H
  49. #include <stdio.h>
  50. #include "monster.h"
  51. /* =============================================================================
  52. * Exported variables
  53. */
  54. #define MAXLEVEL 16 /* max # levels in the dungeon + 1 */
  55. #define MAXVLEVEL 5 /* max # of levels in the volcano */
  56. #define NLEVELS (MAXLEVEL + MAXVLEVEL)
  57. #define DBOTTOM (MAXLEVEL - 1)
  58. #define VBOTTOM (MAXLEVEL + MAXVLEVEL - 1)
  59. /*
  60. * Dungeon level size. MUST bo odd.
  61. */
  62. #define MAXX 67
  63. #define MAXY 17
  64. /*
  65. * Items stolen by monsters data structure
  66. */
  67. typedef struct _s {
  68. char item;
  69. short itemarg;
  70. } StolenItem;
  71. typedef struct {
  72. char mon;
  73. char n;
  74. StolenItem it[6];
  75. } struct_mitem;
  76. /*
  77. * Stealth flags for monsters.
  78. * STEALTH_SEEN indicates that the player has seen or somehow knowns
  79. * about the monster.
  80. *
  81. * STEALTH_AWAKE indicates that the monster is awake and will move
  82. * about the dungeon.
  83. *
  84. * A monster will be displayed on the map if
  85. * 1. The player's knowledge of the cell containing the monster is not
  86. * OUNKNOWN,
  87. * and either:
  88. * 2a. The monster has been seen (STEALTH_SEEN set) or,
  89. * 2b. The monster is awake (STEALTH_AWAKE set)
  90. * (Awake monsters are assumed to be making noise)
  91. */
  92. #define STEALTH_SEEN 1
  93. #define STEALTH_AWAKE 2
  94. extern char item[MAXX][MAXY]; /* objects in maze if any */
  95. extern char know[MAXX][MAXY]; /* contains what the player thinks is here */
  96. extern char moved[MAXX][MAXY]; /* monster movement flags */
  97. extern char stealth[MAXX][MAXY]; /* 0=sleeping 1=awake monst */
  98. extern short hitp[MAXX][MAXY]; /* monster hp on level */
  99. extern short iarg[MAXX][MAXY]; /* arg for the item array */
  100. extern short screen[MAXX][MAXY]; /* The screen as the player knows it */
  101. extern struct_mitem mitem[MAXX][MAXY]; /* Items stolen by monstes array */
  102. /*
  103. * This serves two purposes:
  104. * 1. Indicates which levels have been visited by the player.
  105. * 0 => not visited
  106. * >0 => visited
  107. * 2. Indicates how many items have been stolen from the player on this level.
  108. * This is used as a sanity check. Don't blame me, it was like this
  109. * when I got here :-)
  110. * Each time an item is stolen this is incremented.
  111. * When the monster that stole the items is killed, this is decremented
  112. * for each item the monster drops.
  113. */
  114. extern char beenhere[NLEVELS];
  115. extern int level; /* cavelevel player is on = c[CAVELEVEL]*/
  116. extern char *levelname[]; /* Dungeon level names */
  117. /*
  118. * MACRO: forget
  119. * Destroy object at present location
  120. * As the player is there, obviously it is known to be destroyed.
  121. */
  122. #define forget() \
  123. { \
  124. item[playerx][playery] = ONOTHING; \
  125. know[playerx][playery] = ONOTHING; \
  126. }
  127. /*
  128. * MACRO: disappear
  129. * Wipe out a monster at a location.
  130. * Redraw the location if it is not unknown.
  131. */
  132. #define disappear(x, y) \
  133. { \
  134. mitem[x][y].mon = 0; \
  135. if (know[x][y] != OUNKNOWN) \
  136. show1cell(x, y); \
  137. }
  138. /* verify coordinates */
  139. #define vxy(x, y) \
  140. { \
  141. if (x < 0) \
  142. x = 0; \
  143. if (y < 0) \
  144. y = 0; \
  145. if (x >= MAXX) \
  146. x = MAXX - 1; \
  147. if (y >= MAXY) \
  148. y = MAXY - 1; \
  149. }
  150. /* =============================================================================
  151. * FUNCTION: init_cells
  152. *
  153. * DESCRIPTION:
  154. * Allocate storage for levels.
  155. *
  156. * PARAMETERS:
  157. *
  158. * None.
  159. *
  160. * RETURN VALUE:
  161. *
  162. * None.
  163. */
  164. void init_cells(void);
  165. /* =============================================================================
  166. * FUNCTION: free_cells
  167. *
  168. * DESCRIPTION:
  169. * Free storage for levels.
  170. *
  171. * PARAMETERS:
  172. *
  173. * None.
  174. *
  175. * RETURN VALUE:
  176. *
  177. * None.
  178. */
  179. void free_cells(void);
  180. /* =============================================================================
  181. * FUNCTION:
  182. *
  183. * DESCRIPTION:
  184. * Function to check location for emptiness and for dungeon exit.
  185. * if itm==TRUE check for no item at this location
  186. * if monst==TRUE check for no monster at this location
  187. *
  188. * PARAMETERS:
  189. *
  190. * x : The x coordinate to check
  191. *
  192. * y : The y coordinate to check
  193. *
  194. * chkitm : True if check for empty of items
  195. *
  196. * chkmonst : True if check for empty of monsters.
  197. *
  198. * RETURN VALUE:
  199. *
  200. * TRUE if a location does not have itm or monst there,
  201. * FALSE (0) otherwise
  202. */
  203. int cgood(int x, int y, int chkitm, int chkmonst);
  204. /* =============================================================================
  205. * FUNCTION: dropgold
  206. *
  207. * DESCRIPTION:
  208. * Function to drop some gold around player.
  209. *
  210. * PARAMETERS:
  211. *
  212. * amount : The amount of gold to drop
  213. *
  214. * RETURN VALUE:
  215. *
  216. * None.
  217. */
  218. void dropgold(int amount);
  219. /* =============================================================================
  220. * FUNCTION: fillmonst
  221. *
  222. * DESCRIPTION:
  223. * Function to put a monster into an empty room without walls or other
  224. * monsters
  225. *
  226. * PARAMETERS:
  227. *
  228. * what : The monster to fill.
  229. *
  230. * RETURN VALUE:
  231. *
  232. * 0 if the monster could be created
  233. * -1 if no location for the monster could be found
  234. */
  235. int fillmonst(int what);
  236. /* =============================================================================
  237. * FUNCTION: eat
  238. *
  239. * DESCRIPTION:
  240. * Function to eat a maze in a level filled with walls.
  241. *
  242. * PARAMETERS:
  243. *
  244. * xx : The starting x coordinate
  245. *
  246. * yy : The starting y coordinate
  247. *
  248. * RETURN VALUE:
  249. *
  250. * None.
  251. */
  252. void eat(int xx, int yy);
  253. /* =============================================================================
  254. * FUNCTION: savelevel
  255. *
  256. * DESCRIPTION:
  257. * Routine to save the present level into storage.
  258. *
  259. * PARAMETERS:
  260. *
  261. * None.
  262. *
  263. * RETURN VALUE:
  264. *
  265. * None.
  266. */
  267. void savelevel(void);
  268. /* =============================================================================
  269. * FUNCTION: getlevel
  270. *
  271. * DESCRIPTION:
  272. * Routine to restore a level from storage.
  273. *
  274. * PARAMETERS:
  275. *
  276. * None.
  277. *
  278. * RETURN VALUE:
  279. *
  280. * None.
  281. */
  282. void getlevel(void);
  283. /* =============================================================================
  284. * FUNCTION: AnalyseWalls
  285. *
  286. * DESCRIPTION:
  287. * Function to analyse the tiles needed for walls based on the layout of
  288. * adjacent walls.
  289. *
  290. * PARAMETERS:
  291. *
  292. * x1 : The leftmost position in the area to analyse
  293. *
  294. * y1 : The topmose position in the area to analyse
  295. *
  296. * x2 : The rightmost position in the area to analyse
  297. *
  298. * y2 : The bottommost position in the area to analyse.
  299. *
  300. * RETURN VALUE:
  301. *
  302. * None.
  303. */
  304. void AnalyseWalls(int x1, int y1, int x2, int y2);
  305. /* =============================================================================
  306. * FUNCTION: newcavelevel
  307. *
  308. * DESCRIPTION:
  309. * Function to enter a new level. This routine must be called anytime the
  310. * player changes levels. If that level is unknown it will be created.
  311. * A new set of monsters will be created for a new level, and existing
  312. * levels will get a few more monsters.
  313. * Note that it is here we remove genocided monsters from the present level
  314. *
  315. * PARAMETERS:
  316. *
  317. * x : The new cave level to visit.
  318. *
  319. * RETURN VALUE:
  320. *
  321. * None.
  322. */
  323. void newcavelevel(int x);
  324. /* =============================================================================
  325. * FUNCTION: verifyxy
  326. *
  327. * DESCRIPTION:
  328. * Function to verify x & y are within the bounds for a level If *x or *y is not
  329. * within the absolute bounds for a level, fix them so that they are on the
  330. * level. Returns TRUE if it was out of bounds, and the *x & *y in the
  331. * calling routine are affected.
  332. *
  333. * PARAMETERS:
  334. *
  335. * x : The x coordinate to verify
  336. *
  337. * y : The y coordiante to verify
  338. *
  339. * RETURN VALUE:
  340. *
  341. * == 0 if no adjustment to x and y required.
  342. * != 0 if x and/or y required adjustment.
  343. */
  344. int verifyxy(int *x, int *y);
  345. /* =============================================================================
  346. * FUNCTION: checkxy
  347. *
  348. * DESCRIPTION:
  349. * Function to check x & y are within the bounds for a level.
  350. *
  351. * PARAMETERS:
  352. *
  353. * x : The x coordinate to check
  354. *
  355. * y : The y coordiante to check
  356. *
  357. * RETURN VALUE:
  358. *
  359. * == 1 if x, y is within the map bounds.
  360. * == 0 if x, y is outside the map bounds.
  361. */
  362. int checkxy(int x, int y);
  363. /* =============================================================================
  364. * FUNCTION: createitem
  365. *
  366. * DESCRIPTION:
  367. * Routine to place an item next to the player.
  368. * When creating gold, arg is the number of gold pieces to drop, not the
  369. * value to be stored in iarg.
  370. *
  371. * PARAMETERS:
  372. *
  373. * x : The x location around which to create the object
  374. *
  375. * y : The y location around which to create the object
  376. *
  377. * it : The item to create
  378. *
  379. * arg : The item arg.
  380. *
  381. * RETURN VALUE:
  382. *
  383. * None.
  384. */
  385. void createitem(int x, int y, int it, int arg);
  386. /* =============================================================================
  387. * FUNCTION: something
  388. *
  389. * DESCRIPTION:
  390. * Function to create a random item around coords x, y
  391. * Items are created from a designed probability for the input level.
  392. *
  393. * PARAMETERS:
  394. *
  395. * x : The x location around which to create the object
  396. *
  397. * y : The y location around which to create the object
  398. *
  399. * lev : The dungeon level of the item
  400. *
  401. * RETURN VALUE:
  402. *
  403. * None.
  404. */
  405. void something(int x, int y, int lev);
  406. /* =============================================================================
  407. * FUNCTION: newobject
  408. *
  409. * DESCRIPTION:
  410. * Function to return a randomly selected object to be created.
  411. *
  412. * PARAMETERS:
  413. *
  414. * lev : The dungeon level for the item.
  415. *
  416. * i : This is set to the item arg.
  417. *
  418. * RETURN VALUE:
  419. *
  420. * The item identifier of the selected item.
  421. */
  422. int newobject(int lev, int *i);
  423. /* =============================================================================
  424. * FUNCTION: write_levels
  425. *
  426. * DESCRIPTION:
  427. * Write the dungeon levels to a save file
  428. *
  429. * PARAMETERS:
  430. *
  431. * fp : A pointer to the save file being written.
  432. *
  433. * RETURN VALUE:
  434. *
  435. * == 0 if successful
  436. * != 0 if error
  437. */
  438. int write_levels(FILE *fp);
  439. /* =============================================================================
  440. * FUNCTION: read_levels
  441. *
  442. * DESCRIPTION:
  443. * Read the dungeon levels from a save file.
  444. *
  445. * PARAMETERS:
  446. *
  447. * fp : A pointer to the save file being read.
  448. *
  449. * RETURN VALUE:
  450. *
  451. * == 0 if successful
  452. * != 0 if error
  453. */
  454. int read_levels(FILE *fp);
  455. #endif