ularn_win.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808
  1. /* =============================================================================
  2. * PROGRAM: ularn
  3. * FILENAME: ularn_win.h
  4. *
  5. * DESCRIPTION:
  6. * This module contains all operating system dependant code for input and
  7. * display update.
  8. * Each version of ularn should provide a different implementation of this
  9. * module.
  10. *
  11. * =============================================================================
  12. * EXPORTED VARIABLES
  13. *
  14. * nonap : Set to true if no time delays are to be used.
  15. * nosignal : Set if ctrl-C is to be trapped to prevent exit.
  16. * enable_scroll : Probably superfluous
  17. * yrepcount : Repeat count for input commands.
  18. *
  19. * =============================================================================
  20. * EXPORTED FUNCTIONS
  21. *
  22. * init_app : Initialise the app
  23. * close_app : Close the app and free resources
  24. * get_normal_input : Get the next command input
  25. * get_prompt_input : Get input in response to a question
  26. * get_password_input : Get a password
  27. * get_num_input : Geta number
  28. * get_dir_input : Get a direction
  29. * set_display : Set the display mode
  30. * UpdateStatus : Update the status display
  31. * UpdateEffects : Update the effects display
  32. * UpdateStatusAndEffects : Update both status and effects display
  33. * ClearText : Clear the text output area
  34. * UlarnBeep : Make a beep
  35. * MoveCursor : Set the cursor location
  36. * Printc : Print a single character
  37. * Print : Print a string
  38. * Printf : Print a formatted string
  39. * Standout : Print a string is standout format
  40. * SetFormat : Set the output text format
  41. * ClearEOL : Clear to end of line
  42. * ClearEOPage : Clear to end of page
  43. * show1cell : Show 1 cell on the map
  44. * showplayer : Show the player on the map
  45. * showcell : Show the area around the player
  46. * drawscreen : Redraw the screen
  47. * draws : Redraw a section of the screen
  48. * mapeffect : Draw a directional effect
  49. * magic_effect_frames : Get the number of animation frames in a magic fx
  50. * magic_effect : Draw a frame in a magic fx
  51. * nap : Delay for a specified number of milliseconds
  52. * GetUser : Get the username and user id.
  53. *
  54. * =============================================================================
  55. */
  56. #ifndef __ULARN_WIN_H
  57. #define __ULARN_WIN_H
  58. #include "config.h"
  59. #ifdef WINDOWS
  60. #include <windows.h>
  61. #endif
  62. /*
  63. * Text formats
  64. */
  65. typedef enum FormatType
  66. {
  67. FORMAT_NORMAL,
  68. FORMAT_STANDOUT,
  69. FORMAT_STANDOUT2,
  70. FORMAT_STANDOUT3,
  71. FORMAT_BOLD,
  72. FORMAT_INVERSE,
  73. } FormatType;
  74. /*
  75. * Flag indicating if time delays are active.
  76. * 0 = Use delays
  77. * 1 = No delays
  78. */
  79. extern int nonap;
  80. /*
  81. * Flag to indicate if signals are to be trapped.
  82. */
  83. extern int nosignal;
  84. /* constant for enabled/disabled scrolling regn */
  85. extern char enable_scroll;
  86. /* Repeat count for the current command */
  87. extern int yrepcount;
  88. /*
  89. * Display modes for the main window
  90. */
  91. typedef enum DisplayModeType
  92. {
  93. DISPLAY_MAP, /* Map display mode for moving around dungeons */
  94. DISPLAY_TEXT /* Text display mode for scores, shops etc. */
  95. } DisplayModeType;
  96. //
  97. // Effects types for map_effect
  98. //
  99. typedef enum DirEffectsType
  100. {
  101. EFFECT_MLE,
  102. EFFECT_SSP,
  103. EFFECT_BAL,
  104. EFFECT_LIT,
  105. EFFECT_CLD,
  106. EFFECT_COUNT
  107. } DirEffectsType;
  108. //
  109. // Effects for show_nagic_effect.
  110. //
  111. typedef enum MagicEffectsType
  112. {
  113. MAGIC_SPARKLE,
  114. MAGIC_SLEEP,
  115. MAGIC_WEB,
  116. MAGIC_PHANTASMAL,
  117. MAGIC_CLOUD,
  118. MAGIC_VAPORIZE,
  119. MAGIC_DEHYDRATE,
  120. MAGIC_DRAIN,
  121. MAGIC_FLOOD,
  122. MAGIC_FINGER,
  123. MAGIC_TELEPORT,
  124. MAGIC_FIRE,
  125. MAGIC_WALL,
  126. MAGIC_DEMON,
  127. MAGIC_ANNIHILATE,
  128. MAGIC_COUNT
  129. } MagicEffectsType;
  130. //
  131. // Actions that can be selected in the game.
  132. //
  133. typedef enum ActionType
  134. {
  135. ACTION_NULL,
  136. ACTION_DIAG,
  137. ACTION_MOVE_WEST,
  138. ACTION_RUN_WEST,
  139. ACTION_MOVE_EAST,
  140. ACTION_RUN_EAST,
  141. ACTION_MOVE_SOUTH,
  142. ACTION_RUN_SOUTH,
  143. ACTION_MOVE_NORTH,
  144. ACTION_RUN_NORTH,
  145. ACTION_MOVE_NORTHEAST,
  146. ACTION_RUN_NORTHEAST,
  147. ACTION_MOVE_NORTHWEST,
  148. ACTION_RUN_NORTHWEST,
  149. ACTION_MOVE_SOUTHEAST,
  150. ACTION_RUN_SOUTHEAST,
  151. ACTION_MOVE_SOUTHWEST,
  152. ACTION_RUN_SOUTHWEST,
  153. ACTION_WAIT,
  154. ACTION_NONE,
  155. ACTION_WIELD,
  156. ACTION_WEAR,
  157. ACTION_READ,
  158. ACTION_QUAFF,
  159. ACTION_DROP,
  160. ACTION_CAST_SPELL,
  161. ACTION_OPEN_DOOR,
  162. ACTION_CLOSE_DOOR,
  163. ACTION_OPEN_CHEST,
  164. ACTION_INVENTORY,
  165. ACTION_EAT_COOKIE,
  166. ACTION_LIST_SPELLS,
  167. ACTION_HELP,
  168. ACTION_SAVE,
  169. ACTION_TELEPORT,
  170. ACTION_IDENTIFY_TRAPS,
  171. ACTION_BECOME_CREATOR,
  172. ACTION_CREATE_ITEM,
  173. ACTION_TOGGLE_WIZARD,
  174. ACTION_DEBUG_MODE,
  175. ACTION_REMOVE_ARMOUR,
  176. ACTION_PACK_WEIGHT,
  177. ACTION_VERSION,
  178. ACTION_QUIT,
  179. ACTION_REDRAW_SCREEN,
  180. ACTION_SHOW_TAX,
  181. ACTION_COUNT
  182. } ActionType;
  183. /* =============================================================================
  184. * FUNCTION: init_app
  185. *
  186. * DESCRIPTION:
  187. * Initialise the application and create the app windows
  188. *
  189. * PARAMETERS:
  190. *
  191. * hinstance : The application instance.
  192. *
  193. * RETURN VALUE:
  194. *
  195. * 0 if init failed, or 1 if success.
  196. */
  197. #ifdef WINDOWS
  198. int init_app(HINSTANCE hinstance);
  199. #else
  200. #ifdef UNIX_X11
  201. int init_app(char *DisplayName);
  202. #else
  203. int init_app(void);
  204. #endif
  205. #endif
  206. /* =============================================================================
  207. * FUNCTION: close_app
  208. *
  209. * DESCRIPTION:
  210. * Close the application, freeing all resources.
  211. *
  212. * PARAMETERS:
  213. *
  214. * None.
  215. *
  216. * RETURN VALUE:
  217. *
  218. * None.
  219. */
  220. void close_app(void);
  221. /* =============================================================================
  222. * FUNCTION: get_normal_input
  223. *
  224. * DESCRIPTION:
  225. * Standard input handling routine.
  226. * Handles all windows events until a keydown or game action is received.
  227. * If a key was pressed then the ASCII code for the key press translated to
  228. * its corresponding actoin and the action is then returned.
  229. * For other action events (menu, toolbar, or whatever else I decide is useful
  230. * for activating game commands) the action corresponding to the event is
  231. * returned.
  232. *
  233. * PARAMETERS:
  234. *
  235. * None.
  236. *
  237. * RETURN VALUE:
  238. *
  239. * The input action.
  240. */
  241. ActionType get_normal_input(void);
  242. /* =============================================================================
  243. * FUNCTION: get_prompt_input
  244. *
  245. * DESCRIPTION:
  246. * Input handling routine for prompting the player for input before the
  247. * game will continue.
  248. * This will display the indicated prompt in the message window, activate
  249. * a cursor and process events until a character in the answers string is
  250. * entered.
  251. *
  252. * PARAMETERS:
  253. *
  254. * prompt : The prompt to display
  255. *
  256. * answers : The acceptable answer characters
  257. *
  258. * ShowCursor : Set to 1 to show a cursor, or 0 for no cursor
  259. *
  260. * RETURN VALUE:
  261. *
  262. * The input character fromt he answers set.
  263. */
  264. char get_prompt_input(char *prompt, char *answers, int ShowCursor);
  265. /* =============================================================================
  266. * FUNCTION: get_password_input
  267. *
  268. * DESCRIPTION:
  269. * Input handling routine to input a password.
  270. * Echos '*' instead of the typed character
  271. *
  272. * PARAMETERS:
  273. *
  274. * password : The buffer to store the input password.
  275. *
  276. * Len : The maximum length of the input password.
  277. * Password should be at least (Len+1) characeters to allow
  278. * for the null terminator.
  279. *
  280. * RETURN VALUE:
  281. *
  282. * None.
  283. */
  284. void get_password_input(char *password, int Len);
  285. /* =============================================================================
  286. * FUNCTION: get_num_input
  287. *
  288. * DESCRIPTION:
  289. * Input handling routine to input a number.
  290. * Allows entry of '*' for returning the default value.
  291. *
  292. * PARAMETERS:
  293. *
  294. * defval : The default value if no entry is input or '*' is entered.
  295. *
  296. * RETURN VALUE:
  297. *
  298. * The input number.
  299. */
  300. int get_num_input(int defval);
  301. /* =============================================================================
  302. * FUNCTION: get_dir_input
  303. *
  304. * DESCRIPTION:
  305. * Input handling routine to input a direction key.
  306. *
  307. * PARAMETERS:
  308. *
  309. * prompt : The prompt to display
  310. *
  311. * ShowCursor : Set to 1 to show a cursor, or 0 for no cursor.
  312. *
  313. * RETURN VALUE:
  314. *
  315. * The move action associated with the input direction key.
  316. */
  317. ActionType get_dir_input(char *prompt, int ShowCursor);
  318. /* =============================================================================
  319. * FUNCTION: set_display
  320. *
  321. * DESCRIPTION:
  322. * Set the display mode for the main display area and redraw the screen
  323. * in the new display mode.
  324. * Display modes available are:
  325. * DISPLAY_MAP, - Displays the dungeon map
  326. * DISPLAY_TEXT, - Displays paged text
  327. *
  328. * PARAMETERS:
  329. *
  330. * Mode : The selected display mode.
  331. *
  332. * RETURN VALUE:
  333. *
  334. * None.
  335. */
  336. void set_display(DisplayModeType Mode);
  337. /* =============================================================================
  338. * Status and effects display update functions
  339. */
  340. /* =============================================================================
  341. * FUNCTION: UpdateStatus
  342. *
  343. * DESCRIPTION:
  344. * Update the status lines showing the current player's attributes, HP, Exp
  345. * etc.
  346. *
  347. * PARAMETERS:
  348. *
  349. * None.
  350. *
  351. * RETURN VALUE:
  352. *
  353. * None.
  354. */
  355. void UpdateStatus(void);
  356. /* =============================================================================
  357. * FUNCTION: UpdateEffects
  358. *
  359. * DESCRIPTION:
  360. * Updates the display of effects curently in play.
  361. *
  362. * PARAMETERS:
  363. *
  364. * None.
  365. *
  366. * RETURN VALUE:
  367. *
  368. * None.
  369. */
  370. void UpdateEffects(void);
  371. /* =============================================================================
  372. * FUNCTION: UpdateStatusAndEffects
  373. *
  374. * DESCRIPTION:
  375. * Update status and effects display.
  376. *
  377. * PARAMETERS:
  378. *
  379. * None.
  380. *
  381. * RETURN VALUE:
  382. *
  383. * None.
  384. */
  385. void UpdateStatusAndEffects(void);
  386. /* =============================================================================
  387. * Text routines (operates on message or text window)
  388. */
  389. /* =============================================================================
  390. * FUNCTION: ClearText
  391. *
  392. * DESCRIPTION:
  393. * Clear the currently active text display.
  394. *
  395. * PARAMETERS:
  396. *
  397. * None.
  398. *
  399. * RETURN VALUE:
  400. *
  401. * None.
  402. */
  403. void ClearText(void);
  404. /* =============================================================================
  405. * FUNCTION: beep
  406. *
  407. * DESCRIPTION:
  408. * Make a beep.
  409. *
  410. * PARAMETERS:
  411. *
  412. * None.
  413. *
  414. * RETURN VALUE:
  415. *
  416. * None.
  417. */
  418. void UlarnBeep(void);
  419. /* =============================================================================
  420. * FUNCTION: MoveCursor
  421. *
  422. * DESCRIPTION:
  423. * Locate the cursor at position x, y where 1, 1 is the top left corner.
  424. *
  425. * PARAMETERS:
  426. *
  427. * x : The new x coordinate for the cursor
  428. *
  429. * y : The new y coordinate for the cursor
  430. *
  431. * RETURN VALUE:
  432. *
  433. * None.
  434. */
  435. void MoveCursor(int x, int y);
  436. /* =============================================================================
  437. * FUNCTION: Printc
  438. *
  439. * DESCRIPTION:
  440. * Print a single character to the current text output.
  441. *
  442. * PARAMETERS:
  443. *
  444. * c : The character to print.
  445. *
  446. * RETURN VALUE:
  447. *
  448. * None.
  449. */
  450. void Printc(char c);
  451. /* =============================================================================
  452. * FUNCTION: Print
  453. *
  454. * DESCRIPTION:
  455. * Print a string to the current text output.
  456. *
  457. * PARAMETERS:
  458. *
  459. * string : The string to print
  460. *
  461. * RETURN VALUE:
  462. *
  463. * None.
  464. */
  465. void Print(char *string);
  466. /* =============================================================================
  467. * FUNCTION: Printf
  468. *
  469. * DESCRIPTION:
  470. * Formatted print to the current text output. Takes the same input as the
  471. * standard printf.
  472. *
  473. * PARAMETERS:
  474. *
  475. * fmt : Theformat string
  476. *
  477. * ... : Values to be printed as specified by the format string
  478. *
  479. * RETURN VALUE:
  480. *
  481. * None.
  482. */
  483. void Printf(char *fmt, ...);
  484. /* =============================================================================
  485. * FUNCTION: Standout
  486. *
  487. * DESCRIPTION:
  488. * Display a string in the standout style.
  489. *
  490. * PARAMETERS:
  491. *
  492. * string : The string to be printed
  493. *
  494. * RETURN VALUE:
  495. *
  496. * None.
  497. */
  498. void Standout(char *String);
  499. /* =============================================================================
  500. * FUNCTION: SetFormat
  501. *
  502. * DESCRIPTION:
  503. * Set the format for future text printing.
  504. *
  505. * PARAMETERS:
  506. *
  507. * format : The new text format.
  508. *
  509. * RETURN VALUE:
  510. *
  511. * None.
  512. */
  513. void SetFormat(FormatType format);
  514. /* =============================================================================
  515. * FUNCTION: ClearToEOL
  516. *
  517. * DESCRIPTION:
  518. * Clear from the current cursor position to the end of the current line.
  519. * The cursor position is unchanged.
  520. *
  521. * PARAMETERS:
  522. *
  523. * None.
  524. *
  525. * RETURN VALUE:
  526. *
  527. * None.
  528. */
  529. void ClearToEOL(void);
  530. /* =============================================================================
  531. * FUNCTION:ClearToEOPage
  532. *
  533. * DESCRIPTION:
  534. * Clear from the specified cursor position to the end of the page.
  535. * The cursor position is unchanged.
  536. *
  537. * PARAMETERS:
  538. *
  539. * x : The x cursor position for the start of the clear
  540. *
  541. * y : The y cursor position for the start of the clear
  542. *
  543. * RETURN VALUE:
  544. *
  545. * None.
  546. */
  547. void ClearToEOPage(int x, int y);
  548. /* =============================================================================
  549. * Map display functions
  550. */
  551. /* =============================================================================
  552. * FUNCTION: show1cell
  553. *
  554. * DESCRIPTION:
  555. * Display a single cell of the map, making that cell known if the player
  556. * isn't blind.
  557. *
  558. * PARAMETERS:
  559. *
  560. * x : The x coordiante of the cell to show.
  561. *
  562. * y : The y coordinate of the cell to show.
  563. *
  564. * RETURN VALUE:
  565. *
  566. * None.
  567. */
  568. void show1cell(int x, int y);
  569. /* =============================================================================
  570. * FUNCTION: showplayer
  571. *
  572. * DESCRIPTION:
  573. * Show the player on the map, scrolling the map if necessary.
  574. *
  575. * PARAMETERS:
  576. *
  577. * None.
  578. *
  579. * RETURN VALUE:
  580. *
  581. * None.
  582. */
  583. void showplayer(void);
  584. /* =============================================================================
  585. * FUNCTION: showcell
  586. *
  587. * DESCRIPTION:
  588. * Display a cell location around the player on the screen.
  589. * The player gets to know about the cells shown (sets the know array).
  590. *
  591. * PARAMETERS:
  592. *
  593. * x : The x position to display
  594. *
  595. * y : The y position to display
  596. *
  597. * RETURN VALUE:
  598. *
  599. * None.
  600. */
  601. void showcell(int x, int y);
  602. /* =============================================================================
  603. * FUNCTION: drawscreen
  604. *
  605. * DESCRIPTION:
  606. * Redraw the entire screen.
  607. *
  608. * PARAMETERS:
  609. *
  610. * None.
  611. *
  612. * RETURN VALUE:
  613. *
  614. * None.
  615. */
  616. void drawscreen(void);
  617. /* =============================================================================
  618. * FUNCTION: draws
  619. *
  620. * DESCRIPTION:
  621. * Redraw a sub-section of the screen.
  622. *
  623. * PARAMETERS:
  624. *
  625. * minx : The min x coordiante of the area to redraw.
  626. *
  627. * miny : The min y coordiante of the area to redraw.
  628. *
  629. * maxx : The max x coordiante of the area to redraw.
  630. *
  631. * maxy : The max y coordiante of the area to redraw.
  632. *
  633. * RETURN VALUE:
  634. *
  635. * None.
  636. */
  637. void draws(int minx, int miny, int maxx, int maxy);
  638. /* =============================================================================
  639. * FUNCTION: mapeffect
  640. *
  641. * DESCRIPTION:
  642. * Draw a directional effect on the map.
  643. * This is used for drawing the range based spell effects.
  644. *
  645. * PARAMETERS:
  646. *
  647. * x : The x location to draw the effect
  648. *
  649. * y : The y location to draw the effect
  650. *
  651. * effect : The effect type to show.
  652. *
  653. * dir : The direction the effect is going.
  654. *
  655. * RETURN VALUE:
  656. *
  657. * None.
  658. */
  659. void mapeffect(int x, int y, DirEffectsType effect, int dir);
  660. /* =============================================================================
  661. * FUNCTION: magic_effect_frames
  662. *
  663. * DESCRIPTION:
  664. * The number of frames in a magic effect animation.
  665. *
  666. * PARAMETERS:
  667. *
  668. * fx : The effect type.
  669. *
  670. * RETURN VALUE:
  671. *
  672. * The number of frames in the effect animation
  673. */
  674. int magic_effect_frames(MagicEffectsType fx);
  675. /* =============================================================================
  676. * FUNCTION: magic_effect
  677. *
  678. * DESCRIPTION:
  679. * Draw 1 frame of the animatin for a magic effect.
  680. *
  681. * PARAMETERS:
  682. *
  683. * x : The x location for the effect
  684. *
  685. * y : The y location for the effect
  686. *
  687. * fx : The effect type.
  688. *
  689. * frame : The frame number to display
  690. *
  691. * RETURN VALUE:
  692. *
  693. * None.
  694. */
  695. void magic_effect(int x, int y, MagicEffectsType fx, int frame);
  696. /* =============================================================================
  697. * Timing functions
  698. */
  699. /* =============================================================================
  700. * FUNCTION: nap
  701. *
  702. * DESCRIPTION:
  703. * Delay for a number of milliseconds.
  704. *
  705. * PARAMETERS:
  706. *
  707. * delay : The number of milliseconds to delay
  708. *
  709. * RETURN VALUE:
  710. *
  711. * None.
  712. */
  713. void nap(int delay);
  714. /* =============================================================================
  715. * User name functions
  716. */
  717. /* =============================================================================
  718. * FUNCTION: GetUser
  719. *
  720. * DESCRIPTION:
  721. * This function gets the username and user id.
  722. * This should use operating system calls if available.
  723. * If not, ask the player for their name (I guess we'll just have to trust
  724. * them).
  725. *
  726. * PARAMETERS:
  727. *
  728. * username : On input this should be set to the name specified in the
  729. * ularn options file. If the OS doesn't provide a username
  730. * then this should be used for the username.
  731. * On exit this is set to the username to use for the game.
  732. *
  733. * uid : This is set to the user id of the user.
  734. * Systems that do not support user ids must provide a mechanism
  735. * for associating a number with each username.
  736. * I suggest using a player id file to store the mappings
  737. * between users and numbers, incrementing the uid for each new
  738. * player.
  739. *
  740. * RETURN VALUE:
  741. *
  742. * None.
  743. */
  744. void GetUser(char *username, int *uid);
  745. #endif