ularn_win.h 18 KB

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