ularn_wintty.c 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311
  1. /* =============================================================================
  2. * PROGRAM: ularn
  3. * FILENAME: ularn_win.c
  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. * This is the curses based TTY display module.
  12. *
  13. * =============================================================================
  14. * EXPORTED VARIABLES
  15. *
  16. * nonap : Set to true if no time delays are to be used.
  17. * nosignal : Set if ctrl-C is to be trapped to prevent exit.
  18. * enable_scroll : Probably superfluous
  19. * yrepcount : Repeat count for input commands.
  20. *
  21. * =============================================================================
  22. * EXPORTED FUNCTIONS
  23. *
  24. * init_app : Initialise the app
  25. * close_app : Close the app and free resources
  26. * get_normal_input : Get the next command input
  27. * get_prompt_input : Get input in response to a question
  28. * get_password_input : Get a password
  29. * get_num_input : Geta number
  30. * get_dir_input : Get a direction
  31. * set_display : Set the display mode
  32. * UpdateStatus : Update the status display
  33. * UpdateEffects : Update the effects display
  34. * UpdateStatusAndEffects : Update both status and effects display
  35. * ClearText : Clear the text output area
  36. * beep : Make a beep
  37. * Cursor : Set the cursor location
  38. * Printc : Print a single character
  39. * Print : Print a string
  40. * Printf : Print a formatted string
  41. * Standout : Print a string is standout format
  42. * SetFormat : Set the output text format
  43. * ClearEOL : Clear to end of line
  44. * ClearEOPage : Clear to end of page
  45. * show1cell : Show 1 cell on the map
  46. * showplayer : Show the player on the map
  47. * showcell : Show the area around the player
  48. * drawscreen : Redraw the screen
  49. * draws : Redraw a section of the screen
  50. * mapeffect : Draw a directional effect
  51. * magic_effect_frames : Get the number of animation frames in a magic fx
  52. * magic_effect : Draw a frame in a magic fx
  53. * nap : Delay for a specified number of milliseconds
  54. * GetUser : Get the username and user id.
  55. *
  56. * =============================================================================
  57. */
  58. #include <curses.h>
  59. #include <stdio.h>
  60. #include <stdarg.h>
  61. #include "config.h"
  62. #include "header.h"
  63. #include "ularn_game.h"
  64. #include "dungeon.h"
  65. #include "player.h"
  66. #include "ularn_win.h"
  67. #include "monster.h"
  68. #include "itm.h"
  69. //
  70. // player id file
  71. //
  72. #ifndef UNIX
  73. static char *PIDName = LIBDIR "\\vlarn.pid";
  74. #endif
  75. #define FIRST_PID 1001
  76. /* =============================================================================
  77. * Exported variables
  78. */
  79. int nonap = 0;
  80. int nosignal = 0;
  81. char enable_scroll = 0;
  82. int yrepcount = 0;
  83. /* =============================================================================
  84. * Local variables
  85. */
  86. int UseColor = 0;
  87. int CaretActive = 0;
  88. #define M_NONE 0
  89. #define M_SHIFT 1
  90. #define M_CTRL 2
  91. #define M_ASCII 255
  92. #define MAX_KEY_BINDINGS 3
  93. struct KeyCodeType
  94. {
  95. int VirtKey;
  96. int ModKey;
  97. };
  98. #define NUM_DIRS 8
  99. static ActionType DirActions[NUM_DIRS] =
  100. {
  101. ACTION_MOVE_WEST,
  102. ACTION_MOVE_EAST,
  103. ACTION_MOVE_SOUTH,
  104. ACTION_MOVE_NORTH,
  105. ACTION_MOVE_NORTHEAST,
  106. ACTION_MOVE_NORTHWEST,
  107. ACTION_MOVE_SOUTHEAST,
  108. ACTION_MOVE_SOUTHWEST
  109. };
  110. /* Default keymap */
  111. /* Allow up to MAX_KEY_BINDINGS per action */
  112. static struct KeyCodeType KeyMap[ACTION_COUNT][MAX_KEY_BINDINGS] =
  113. {
  114. { { 0, 0 }, { 0, 0 }, { 0, 0 } }, // ACTION_NULL
  115. { { '~', M_ASCII }, { 0, 0 }, { 0, 0 } }, // ACTION_DIAG
  116. { { 'h', M_ASCII }, { KEY_LEFT, M_ASCII }, { 0, 0 } }, // ACTION_MOVE_WEST
  117. { { 'H', M_ASCII }, { 0, 0 }, { 0, 0 } }, // ACTION_RUN_WEST
  118. { { 'l', M_ASCII }, { KEY_RIGHT, M_ASCII }, { 0, 0 } }, // ACTION_MOVE_EAST,
  119. { { 'L', M_ASCII }, { 0, 0 }, { 0, 0 } }, // ACTION_RUN_EAST,
  120. { { 'j', M_ASCII }, { KEY_DOWN, M_ASCII }, { 0, 0 } }, // ACTION_MOVE_SOUTH,
  121. { { 'J', M_ASCII }, { 0, 0 }, { 0, 0 } }, // ACTION_RUN_SOUTH,
  122. { { 'k', M_ASCII }, { KEY_UP, M_ASCII }, { 0, 0 } }, // ACTION_MOVE_NORTH,
  123. { { 'K', M_ASCII }, { 0, 0 }, { 0, 0 } }, // ACTION_RUN_NORTH,
  124. { { 'u', M_ASCII }, { KEY_A3, M_ASCII }, { 0, 0 } }, // ACTION_MOVE_NORTHEAST,
  125. { { 'U', M_ASCII }, { 0, 0 }, { 0, 0 } }, // ACTION_RUN_NORTHEAST,
  126. { { 'y', M_ASCII }, { KEY_A1, M_ASCII }, { 0, 0 } }, // ACTION_MOVE_NORTHWEST,
  127. { { 'Y', M_ASCII }, { 0, 0 }, { 0, 0 } }, // ACTION_RUN_NORTHWEST,
  128. { { 'n', M_ASCII }, { KEY_C3, M_ASCII }, { 0, 0 } }, // ACTION_MOVE_SOUTHEAST,
  129. { { 'N', M_ASCII }, { 0, 0 }, { 0, 0 } }, // ACTION_RUN_SOUTHEAST,
  130. { { 'b', M_ASCII }, { KEY_C1, M_ASCII }, { 0, 0 } }, // ACTION_MOVE_SOUTHWEST,
  131. { { 'B', M_ASCII }, { 0, 0 }, { 0, 0 } }, // ACTION_RUN_SOUTHWEST,
  132. { { '.', M_ASCII }, { 0, 0 }, { 0, 0 } }, // ACTION_WAIT,
  133. { { ' ', M_ASCII }, { 0, 0 }, { 0, 0 } }, // ACTION_NONE,
  134. { { 'w', M_ASCII }, { 0, 0 }, { 0, 0 } }, // ACTION_WIELD,
  135. { { 'W', M_ASCII }, { 0, 0 }, { 0, 0 } }, // ACTION_WEAR,
  136. { { 'r', M_ASCII }, { 0, 0 }, { 0, 0 } }, // ACTION_READ,
  137. { { 'q', M_ASCII }, { 0, 0 }, { 0, 0 } }, // ACTION_QUAFF,
  138. { { 'd', M_ASCII }, { 0, 0 }, { 0, 0 } }, // ACTION_DROP,
  139. { { 'c', M_ASCII }, { 0, 0 }, { 0, 0 } }, // ACTION_CAST_SPELL,
  140. { { 'o', M_ASCII }, { 0, 0 }, { 0, 0 } }, // ACTION_OPEN_DOOR
  141. { { 'C', M_ASCII }, { 0, 0 }, { 0, 0 } }, // ACTION_CLOSE_DOOR,
  142. { { 'O', M_ASCII }, { 0, 0 }, { 0, 0 } }, // ACTION_OPEN_CHEST
  143. { { 'i', M_ASCII }, { 0, 0 }, { 0, 0 } }, // ACTION_INVENTORY,
  144. { { 'e', M_ASCII }, { 0, 0 }, { 0, 0 } }, // ACTION_EAT_COOKIE,
  145. { { '\\',M_ASCII }, { 0, 0 }, { 0, 0 } }, // ACTION_LIST_SPELLS,
  146. { { '?', M_ASCII }, { 0, 0 }, { 0, 0 } }, // ACTION_HELP,
  147. { { 'S', M_ASCII }, { 0, 0 }, { 0, 0 } }, // ACTION_SAVE,
  148. { { 'Z', M_ASCII }, { 0, 0 }, { 0, 0 } }, // ACTION_TELEPORT,
  149. { { '^', M_ASCII }, { 0, 0 }, { 0, 0 } }, // ACTION_IDENTIFY_TRAPS,
  150. { { '_', M_ASCII }, { 0, 0 }, { 0, 0 } }, // ACTION_BECOME_CREATOR,
  151. { { '+', M_ASCII }, { 0, 0 }, { 0, 0 } }, // ACTION_CREATE_ITEM,
  152. { { '-', M_ASCII }, { 0, 0 }, { 0, 0 } }, // ACTION_TOGGLE_WIZARD,
  153. { { '`', M_ASCII }, { 0, 0 }, { 0, 0 } }, // ACTION_DEBUG_MODE,
  154. { { 'T', M_ASCII }, { 0, 0 }, { 0, 0 } }, // ACTION_REMOVE_ARMOUR,
  155. { { 'g', M_ASCII }, { 0, 0 }, { 0, 0 } }, // ACTION_PACK_WEIGHT,
  156. { { 'v', M_ASCII }, { 0, 0 }, { 0, 0 } }, // ACTION_VERSION,
  157. { { 'Q', M_ASCII }, { 0, 0 }, { 0, 0 } }, // ACTION_QUIT,
  158. { { 18, M_ASCII }, { 0, 0 }, { 0, 0 } }, // ACTION_REDRAW_SCREEN,
  159. { { 'P', M_ASCII }, { 0, 0 }, { 0, 0 } } // ACTION_SHOW_TAX
  160. };
  161. static struct KeyCodeType RunKeyMap = { KEY_B2, M_ASCII };
  162. typedef enum
  163. {
  164. C_BLACK,
  165. C_RED,
  166. C_GREEN,
  167. C_YELLOW,
  168. C_BLUE,
  169. C_MAGENTA,
  170. C_CYAN,
  171. C_WHITE,
  172. C_COUNT
  173. } Ularn_Color_Type;
  174. static int ColorPairs[C_COUNT][2] =
  175. {
  176. { COLOR_BLACK, COLOR_BLACK },
  177. { COLOR_RED, COLOR_BLACK },
  178. { COLOR_GREEN, COLOR_BLACK },
  179. { COLOR_YELLOW, COLOR_BLACK },
  180. { COLOR_BLUE, COLOR_BLACK },
  181. { COLOR_MAGENTA, COLOR_BLACK },
  182. { COLOR_CYAN, COLOR_BLACK },
  183. { COLOR_WHITE, COLOR_BLACK }
  184. };
  185. static int Runkey;
  186. static ActionType Event;
  187. static int GotChar;
  188. static int EventChar;
  189. //
  190. // Characters for tiles
  191. //
  192. int WallTile[16] =
  193. {
  194. '#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#', '#'
  195. //'#', '-', '|', '+', '-', '-', '+', '-', '|', '+', '|', '|', '+', '-', '|', '#'
  196. };
  197. /* Tiles for directional effects */
  198. static int EffectTile[EFFECT_COUNT][9] =
  199. {
  200. { '*', '|', '-', '|', '-', '/', '\\', '\\', '/' },
  201. { '*', '|', '-', '|', '-', '/', '\\', '\\', '/' },
  202. { '*', '|', '-', '|', '-', '/', '\\', '\\', '/' },
  203. { '*', '|', '-', '|', '-', '/', '\\', '\\', '/' },
  204. { '*', '|', '-', '|', '-', '/', '\\', '\\', '/' },
  205. };
  206. static int EffectColor[EFFECT_COUNT] =
  207. {
  208. C_GREEN,
  209. C_CYAN,
  210. C_RED,
  211. C_YELLOW,
  212. C_WHITE
  213. };
  214. #define MAX_MAGICFX_FRAME 8
  215. struct MagicEffectDataType
  216. {
  217. int Frames; /* Number of frames in the effect */
  218. int Tile[MAX_MAGICFX_FRAME]; /* The primary tile for this frame */
  219. int Color[MAX_MAGICFX_FRAME]; /* Only used for overlay effects */
  220. };
  221. static struct MagicEffectDataType magicfx_tile[MAGIC_COUNT] =
  222. {
  223. /* Sparkle */
  224. {
  225. 8,
  226. { '-', '\\', '|', '/', '-', '\\', '|', '/' },
  227. { C_RED, C_YELLOW, C_GREEN, C_CYAN, C_BLUE, C_MAGENTA, C_RED, C_YELLOW }
  228. },
  229. /* Sleep */
  230. {
  231. 6,
  232. { 'z', 'Z', 'z', 'Z', 'z', 'Z', 0, 0 },
  233. { C_RED, C_RED, C_GREEN, C_GREEN, C_BLUE, C_BLUE, 0, 0 }
  234. },
  235. /* Web */
  236. {
  237. 6,
  238. { '.', 'o', '*', '#', '#', '#', 0, 0 },
  239. { C_WHITE, C_WHITE, C_WHITE, C_WHITE, C_GREEN, C_BLUE, 0, 0 }
  240. },
  241. /* Phantasmal forces */
  242. {
  243. 6,
  244. { '.', ':', '^', 'A', 'A', 'A', 0, 0 },
  245. { C_BLUE, C_BLUE, C_MAGENTA, C_MAGENTA, C_CYAN, C_CYAN, 0, 0 }
  246. },
  247. /* Cloud kill */
  248. {
  249. 6,
  250. { '.', 'o', '*', '#', '#', 'O', 0, 0 },
  251. { C_GREEN, C_GREEN, C_GREEN, C_GREEN, C_YELLOW, C_GREEN, 0 ,0 }
  252. },
  253. /* Vaporize rock */
  254. {
  255. 6,
  256. { '.', 'o', '*', '#', '#', 'O', 0, 0 },
  257. { C_RED, C_RED, C_RED, C_RED, C_YELLOW, C_RED, 0, 0 }
  258. },
  259. /* Dehydrate */
  260. {
  261. 6,
  262. { '.', ':', '|', 'T', '^', '~', 0, 0 },
  263. { C_WHITE, C_WHITE, C_WHITE, C_WHITE, C_WHITE, C_WHITE, 0, 0 }
  264. },
  265. /* Drain life */
  266. {
  267. 6,
  268. { '#', '*', '|', ':', 'o', '.', 0, 0 },
  269. { C_YELLOW, C_YELLOW, C_YELLOW, C_RED, C_RED, C_RED, 0, 0 }
  270. },
  271. /* Flood */
  272. {
  273. 6,
  274. { '.', 'o', 'O', 'o', 'O', 'o', 0, 0 },
  275. { C_BLUE, C_BLUE, C_BLUE, C_CYAN, C_CYAN, C_BLUE, 0, 0 }
  276. },
  277. /* Finger of death */
  278. {
  279. 6,
  280. { '#', '*', '|', ':', 'o', '.', 0, 0 },
  281. { C_RED, C_RED, C_MAGENTA, C_MAGENTA, C_BLUE, C_BLUE, 0, 0 }
  282. },
  283. /* Teleport away */
  284. {
  285. 6,
  286. { ':', '|', 'H', 'H', '|', ':', 0, 0 },
  287. { C_CYAN, C_CYAN, C_CYAN, C_BLUE, C_BLUE, C_BLUE, 0, 0 }
  288. },
  289. /* Magic fire */
  290. {
  291. 6,
  292. { '.', 'o', '*', '#', '#', 'O', 0, 0 },
  293. { C_RED, C_RED, C_RED, C_RED, C_YELLOW, C_RED, 0 ,0 }
  294. },
  295. /* Make wall */
  296. {
  297. 6,
  298. { '.', ':', 'H', '#', '#', '#', 0, 0 },
  299. { C_WHITE, C_WHITE, C_WHITE, C_WHITE, C_RED, C_WHITE, 0, 0 }
  300. },
  301. /* Summon demon */
  302. {
  303. 6,
  304. { '.', ':', '^', '8', '8', '8', 0, 0 },
  305. { C_MAGENTA, C_MAGENTA, C_RED, C_RED, C_YELLOW, C_YELLOW, 0, 0 }
  306. },
  307. /* Annihilate (scroll) */
  308. {
  309. 6,
  310. { '-', '|', '-', '|', '-', '|', 0, 0 },
  311. { C_RED, C_RED, C_YELLOW, C_YELLOW, C_GREEN, C_GREEN, 0 ,0 }
  312. }
  313. };
  314. //
  315. // Display attributes and colours
  316. //
  317. static int ItemAttr[OCOUNT] =
  318. {
  319. 0, 0,
  320. /* Dungeon features */
  321. A_REVERSE, A_REVERSE, A_REVERSE, A_REVERSE, A_REVERSE, A_REVERSE, A_REVERSE, A_REVERSE,
  322. A_REVERSE, A_REVERSE, A_REVERSE, A_REVERSE, A_REVERSE, A_REVERSE, A_REVERSE, A_REVERSE,
  323. 0,
  324. /* gold piles */
  325. 0, 0, 0, 0,
  326. /* eye of larn */
  327. A_STANDOUT,
  328. /* armour */
  329. 0, 0, 0, 0, 0, 0, 0, 0,
  330. 0, 0,
  331. /* weapons */
  332. 0, 0, 0, 0, 0, 0, 0, 0,
  333. 0, 0, 0, 0,
  334. /* rings */
  335. 0, 0, 0, 0, 0, 0, 0, 0,
  336. /* magic items */
  337. 0, 0, 0, A_REVERSE, A_REVERSE, A_BOLD, 0, A_BOLD,
  338. 0, 0, 0, 0, 0, 0, 0, 0,
  339. 0,
  340. /* gems */
  341. 0, 0, 0, 0,
  342. /* buildings/entrances */
  343. A_REVERSE, A_REVERSE, A_REVERSE, A_REVERSE, A_REVERSE, A_REVERSE, A_REVERSE, A_REVERSE,
  344. A_REVERSE, A_REVERSE, A_REVERSE,
  345. /* traps */
  346. 0, 0, 0, 0, 0, 0, 0,
  347. /* misc */
  348. 0, 0, 0,
  349. /* drugs */
  350. 0, 0, 0, 0, 0
  351. };
  352. static int ItemColor[OCOUNT] =
  353. {
  354. C_WHITE, C_WHITE,
  355. /* Dungeon features */
  356. C_WHITE, C_YELLOW, C_YELLOW, C_YELLOW, C_WHITE, C_GREEN, C_WHITE, C_BLUE,
  357. C_WHITE, C_RED, C_WHITE, C_RED, C_WHITE, C_WHITE, C_WHITE, C_WHITE,
  358. C_WHITE,
  359. /* gold piles */
  360. C_YELLOW, C_YELLOW, C_YELLOW, C_YELLOW,
  361. /* eye of larn */
  362. C_WHITE,
  363. /* armour */
  364. C_CYAN, C_CYAN, C_WHITE, C_CYAN, C_WHITE, C_CYAN, C_CYAN, C_CYAN,
  365. C_WHITE, C_GREEN,
  366. /* weapons */
  367. C_CYAN, C_WHITE, C_CYAN, C_CYAN, C_WHITE, C_CYAN, C_CYAN, C_CYAN,
  368. C_WHITE, C_WHITE, C_MAGENTA, C_YELLOW,
  369. /* rings */
  370. C_WHITE, C_GREEN, C_BLUE, C_WHITE, C_CYAN, C_RED, C_MAGENTA, C_WHITE,
  371. /* magic items */
  372. C_WHITE, C_WHITE, C_YELLOW, C_CYAN, C_YELLOW, C_CYAN, C_WHITE, C_RED,
  373. C_WHITE, C_WHITE, C_WHITE, C_WHITE, C_WHITE, C_WHITE, C_WHITE, C_WHITE,
  374. C_WHITE,
  375. /* gems */
  376. C_WHITE, C_RED, C_GREEN, C_BLUE,
  377. /* buildings/entrances */
  378. C_WHITE, C_WHITE, C_WHITE, C_WHITE, C_WHITE, C_WHITE, C_WHITE, C_WHITE,
  379. C_WHITE, C_WHITE, C_WHITE,
  380. /* traps */
  381. C_RED, C_RED, C_RED, C_RED, C_RED, C_RED, C_RED,
  382. /* misc */
  383. C_WHITE, C_WHITE, C_WHITE,
  384. /* drugs */
  385. C_WHITE, C_WHITE, C_WHITE, C_WHITE, C_WHITE
  386. };
  387. static int MonstColor[MONST_COUNT] =
  388. {
  389. C_WHITE,
  390. C_WHITE, C_GREEN, C_GREEN, C_WHITE, C_WHITE, C_RED, C_GREEN, C_GREEN,
  391. C_RED, C_RED, C_RED, C_CYAN, C_GREEN, C_WHITE, C_BLUE, C_RED,
  392. C_WHITE, C_WHITE, C_RED, C_RED, C_CYAN, C_GREEN, C_YELLOW, C_WHITE,
  393. C_WHITE, C_GREEN, C_WHITE, C_CYAN, C_YELLOW, C_RED, C_MAGENTA, C_WHITE,
  394. C_YELLOW, C_YELLOW, C_YELLOW, C_YELLOW, C_RED, C_WHITE, C_WHITE, C_WHITE,
  395. C_CYAN, C_GREEN, C_YELLOW, C_MAGENTA, C_GREEN, C_BLUE, C_BLUE, C_MAGENTA,
  396. C_GREEN, C_MAGENTA, C_RED, C_YELLOW, C_CYAN, C_YELLOW, C_GREEN, C_RED,
  397. C_WHITE, C_YELLOW, C_GREEN, C_CYAN, C_BLUE, C_RED, C_MAGENTA, C_CYAN,
  398. C_MAGENTA
  399. };
  400. //
  401. // Current display mode
  402. //
  403. DisplayModeType CurrentDisplayMode = DISPLAY_TEXT;
  404. WINDOW *MapWindow;
  405. WINDOW *StatusWindow;
  406. WINDOW *EffectsWindow;
  407. WINDOW *MessageWindow;
  408. WINDOW *TextWindow;
  409. // =============================================================================
  410. // Text mode stuff
  411. //
  412. /* XXX trn default is 80 */
  413. #define LINE_LENGTH 80
  414. //
  415. // Messages
  416. //
  417. #define MAX_MSG_LINES 5
  418. static FormatType CurrentMsgFormat;
  419. static int MsgCursorX = 1;
  420. static int MsgCursorY = 1;
  421. //
  422. // Text
  423. //
  424. /* XXX trn default is 24, 80 */
  425. #define MAX_TEXT_LINES 24
  426. #define TEXT_LINE_LENGTH 80
  427. static FormatType CurrentTextFormat;
  428. static int TextCursorX = 1;
  429. static int TextCursorY = 1;
  430. //
  431. // Generalised text buffer
  432. // Top left corner is x=1, y=1
  433. //
  434. static FormatType CurrentFormat;
  435. static int CursorX = 1;
  436. static int CursorY = 1;
  437. static int MaxLine;
  438. //
  439. // The monster to use for showing mimics. Changes every 10 turns.
  440. //
  441. static int mimicmonst = MIMIC;
  442. /* =============================================================================
  443. * Local functions
  444. */
  445. /* =============================================================================
  446. * FUNCTION: SetWallTiles
  447. *
  448. * DESCRIPTION:
  449. * Set the wall tiles to the ACS line drawing values
  450. *
  451. * PARAMETERS:
  452. *
  453. * None
  454. *
  455. * RETURN VALUE:
  456. *
  457. * None.
  458. */
  459. static void SetWallTiles(void)
  460. {
  461. WallTile[0] = ACS_BLOCK;
  462. WallTile[1] = ACS_HLINE;
  463. WallTile[2] = ACS_VLINE;
  464. WallTile[3] = ACS_URCORNER;
  465. WallTile[4] = ACS_HLINE;
  466. WallTile[5] = ACS_HLINE;
  467. WallTile[6] = ACS_ULCORNER;
  468. WallTile[7] = ACS_TTEE;
  469. WallTile[8] = ACS_VLINE;
  470. WallTile[9] = ACS_LRCORNER;
  471. WallTile[10] = ACS_VLINE;
  472. WallTile[11] = ACS_RTEE;
  473. WallTile[12] = ACS_LLCORNER;
  474. WallTile[13] = ACS_BTEE;
  475. WallTile[14] = ACS_LTEE;
  476. WallTile[15] = ACS_PLUS;
  477. }
  478. /* =============================================================================
  479. * FUNCTION: SetCursesAttr
  480. *
  481. * DESCRIPTION:
  482. * Set curses text display attributes for the indicated format.
  483. *
  484. * PARAMETERS:
  485. *
  486. * Format : The text format.
  487. *
  488. * RETURN VALUE:
  489. *
  490. * None.
  491. */
  492. static void SetCursesAttr(FormatType Format)
  493. {
  494. int BaseAttr;
  495. #ifdef W32_TTY
  496. BaseAttr = A_BOLD;
  497. #else
  498. BaseAttr = 0;
  499. #endif
  500. switch (Format)
  501. {
  502. case FORMAT_NORMAL:
  503. if (UseColor)
  504. {
  505. wattrset(TextWindow, BaseAttr | COLOR_PAIR(C_WHITE));
  506. }
  507. else
  508. {
  509. wattrset(TextWindow, A_NORMAL);
  510. }
  511. break;
  512. case FORMAT_STANDOUT:
  513. if (UseColor)
  514. {
  515. wattrset(TextWindow, BaseAttr | COLOR_PAIR(C_RED));
  516. }
  517. else
  518. {
  519. wattrset(TextWindow, A_STANDOUT);
  520. }
  521. break;
  522. case FORMAT_STANDOUT2:
  523. if (UseColor)
  524. {
  525. wattrset(TextWindow, BaseAttr | COLOR_PAIR(C_GREEN));
  526. }
  527. else
  528. {
  529. wattrset(TextWindow, A_BOLD);
  530. }
  531. break;
  532. case FORMAT_STANDOUT3:
  533. if (UseColor)
  534. {
  535. wattrset(TextWindow, BaseAttr | COLOR_PAIR(C_BLUE));
  536. }
  537. else
  538. {
  539. wattrset(TextWindow, A_UNDERLINE);
  540. }
  541. break;
  542. default:
  543. break;
  544. }
  545. }
  546. /* =============================================================================
  547. * FUNCTION: setup_colour_pairs
  548. *
  549. * DESCRIPTION:
  550. * Setup the colour pairs used by curses.
  551. *
  552. * PARAMETERS:
  553. *
  554. * None.
  555. *
  556. * RETURN VALUE:
  557. *
  558. * None.
  559. */
  560. static void setup_colour_pairs(void)
  561. {
  562. short i;
  563. for (i = 0; i < C_COUNT ; i++)
  564. {
  565. init_pair(i, ColorPairs[i][0], ColorPairs[i][1]);
  566. }
  567. #ifdef W32_TTY
  568. //
  569. // PD Curses on windoze doesn't seem to do reverse video correctly!
  570. // Need to set up the reverse colour combinations
  571. //
  572. for (i = 0; i < C_COUNT ; i++)
  573. {
  574. init_pair(C_COUNT + i, ColorPairs[i][1], ColorPairs[i][0]);
  575. }
  576. #endif
  577. }
  578. /*
  579. * Repaint flag to force redraw of everything, not just deltas
  580. */
  581. static int Repaint = 0;
  582. /* =============================================================================
  583. * FUNCTION: PaintStatus
  584. *
  585. * DESCRIPTION:
  586. * Paint the status area.
  587. *
  588. * PARAMETERS:
  589. *
  590. * None.
  591. *
  592. * RETURN VALUE:
  593. *
  594. * None.
  595. */
  596. static void PaintStatus(void)
  597. {
  598. char Line[81];
  599. char Buf[81];
  600. int i;
  601. #ifdef W32_TTY
  602. wattrset(StatusWindow, A_BOLD | COLOR_PAIR(C_WHITE));
  603. #else
  604. wattrset(StatusWindow, COLOR_PAIR(C_WHITE));
  605. #endif
  606. if (Repaint)
  607. {
  608. wclear(StatusWindow);
  609. for (i = 0 ; i < 80 ; i++)
  610. {
  611. mvwaddch(StatusWindow, 0, i, ' ');
  612. mvwaddch(StatusWindow, 1, i, ' ');
  613. }
  614. }
  615. //
  616. // Build the top status line
  617. //
  618. Line[0] = 0;
  619. /* Spells */
  620. if (c[SPELLMAX]>99)
  621. sprintf(Buf, "Spells:%3ld(%3ld)", c[SPELLS],c[SPELLMAX]);
  622. else
  623. sprintf(Buf, "Spells:%3ld(%2ld) ",c[SPELLS],c[SPELLMAX]);
  624. strcat(Line, Buf);
  625. /* AC, WC */
  626. sprintf(Buf, " AC: %-3ld WC: %-3ld Level", c[AC], c[WCLASS]);
  627. strcat(Line, Buf);
  628. /* Level */
  629. if (c[LEVEL]>99)
  630. sprintf(Buf, "%3ld", c[LEVEL]);
  631. else
  632. sprintf(Buf, " %-2ld", c[LEVEL]);
  633. strcat(Line, Buf);
  634. /* Exp, class */
  635. sprintf(Buf, " Exp: %-9ld %s", c[EXPERIENCE], class[c[LEVEL]-1]);
  636. strcat(Line, Buf);
  637. mvwaddstr(StatusWindow, 0, 0, Line);
  638. //
  639. // Format the second line of the status
  640. //
  641. sprintf(Buf, "%ld (%ld)", c[HP], c[HPMAX]);
  642. sprintf(Line, "HP: %11s STR=%-2ld INT=%-2ld WIS=%-2ld CON=%-2ld DEX=%-2ld CHA=%-2ld LV:",
  643. Buf,
  644. c[STRENGTH]+c[STREXTRA],
  645. c[INTELLIGENCE],
  646. c[WISDOM],
  647. c[CONSTITUTION],
  648. c[DEXTERITY],
  649. c[CHARISMA]);
  650. if ((level==0) || (wizard))
  651. c[TELEFLAG]=0;
  652. if (c[TELEFLAG])
  653. strcat(Line, " ?");
  654. else
  655. strcat(Line, levelname[level]);
  656. sprintf(Buf, " Gold: %-8ld", c[GOLD]);
  657. strcat(Line, Buf);
  658. mvwaddstr(StatusWindow, 1, 0, Line);
  659. wrefresh(StatusWindow);
  660. //
  661. // Mark all character values as displayed.
  662. //
  663. c[TMP] = c[STRENGTH]+c[STREXTRA];
  664. for (i=0; i<100; i++)
  665. cbak[i]=c[i];
  666. }
  667. /* Effects strings */
  668. static struct bot_side_def
  669. {
  670. int typ;
  671. char *string;
  672. } bot_data[] =
  673. {
  674. { STEALTH, " Stealth " },
  675. { UNDEADPRO, " Undead Pro " },
  676. { SPIRITPRO, " Spirit Pro " },
  677. { CHARMCOUNT, " Charm " },
  678. { TIMESTOP, " Time Stop " },
  679. { HOLDMONST, " Hold Monst " },
  680. { GIANTSTR, " Giant Str " },
  681. { FIRERESISTANCE, " Fire Resit " },
  682. { DEXCOUNT, " Dexterity " },
  683. { STRCOUNT, " Strength " },
  684. { SCAREMONST, " Scare " },
  685. { HASTESELF, " Haste Self " },
  686. { CANCELLATION, " Cancel " },
  687. { INVISIBILITY, " Invisible " },
  688. { ALTPRO, " Protect 3 " },
  689. { PROTECTIONTIME, " Protect 2 " },
  690. { WTW, " Wall-Walk " }
  691. };
  692. /* =============================================================================
  693. * FUNCTION: PaintEffects
  694. *
  695. * DESCRIPTION:
  696. * Paint the effects display.
  697. *
  698. * PARAMETERS:
  699. *
  700. * None.
  701. *
  702. * RETURN VALUE:
  703. *
  704. * None.
  705. */
  706. static void PaintEffects(void)
  707. {
  708. int i, idx;
  709. int WasSet;
  710. int IsSet;
  711. #ifdef W32_TTY
  712. wattrset(StatusWindow, A_BOLD | COLOR_PAIR(C_WHITE));
  713. #else
  714. wattrset(StatusWindow, COLOR_PAIR(C_WHITE));
  715. #endif
  716. if (Repaint)
  717. {
  718. wclear(EffectsWindow);
  719. }
  720. for (i=0; i < 17; i++)
  721. {
  722. idx = bot_data[i].typ;
  723. WasSet = (cbak[idx] != 0);
  724. IsSet = (c[idx] != 0);
  725. if ((Repaint) || (IsSet != WasSet))
  726. {
  727. if (IsSet)
  728. {
  729. mvwaddstr(EffectsWindow, i, 0, bot_data[i].string);
  730. }
  731. else
  732. {
  733. mvwaddstr(EffectsWindow, i, 0, " ");
  734. }
  735. }
  736. cbak[idx] = c[idx];
  737. }
  738. wrefresh(EffectsWindow);
  739. }
  740. /* =============================================================================
  741. * FUNCTION: GetTile
  742. *
  743. * DESCRIPTION:
  744. * Get the tile to be displayed for a location on the map.
  745. *
  746. * PARAMETERS:
  747. *
  748. * x : The x coordinate for the tile
  749. *
  750. * y : The y coordiante for the tile
  751. *
  752. * TileId : This is set to the tile to be displayed for (x, y).
  753. *
  754. * Attr : The curses attribute for this tile
  755. *
  756. * ColorPair : The colour pair for this tile
  757. *
  758. * RETURN VALUE:
  759. *
  760. * None.
  761. */
  762. static void GetTile(int x, int y, int *TileId, int *Attr, int *ColorPair)
  763. {
  764. MonsterIdType k;
  765. *Attr = 0;
  766. if ((x == playerx) && (y == playery) && (c[BLINDCOUNT] == 0))
  767. {
  768. //
  769. // This is the square containing the player and the players isn't
  770. // blind, so return the player tile.
  771. //
  772. *TileId = '@';
  773. *ColorPair = C_RED;
  774. return;
  775. }
  776. //
  777. // Work out what is here
  778. //
  779. if (know[x][y] == OUNKNOWN)
  780. {
  781. //
  782. // The player doesn't know what is at this position.
  783. //
  784. *TileId = objnamelist[OUNKNOWN];
  785. *Attr = ItemAttr[(int) know[x][y]];
  786. *ColorPair = C_BLACK;
  787. }
  788. else
  789. {
  790. k = mitem[x][y].mon;
  791. if (k != 0)
  792. {
  793. if ((c[BLINDCOUNT] == 0) &&
  794. (((stealth[x][y] & STEALTH_SEEN) != 0) ||
  795. ((stealth[x][y] & STEALTH_AWAKE) != 0)))
  796. {
  797. //
  798. // There is a monster here and the player is not blind and the
  799. // monster is seen or awake.
  800. //
  801. if (k == MIMIC)
  802. {
  803. if ((gtime % 10) == 0)
  804. {
  805. while ((mimicmonst = rnd(MAXMONST))==INVISIBLESTALKER);
  806. }
  807. *TileId = monstnamelist[mimicmonst];
  808. *ColorPair = MonstColor[mimicmonst];
  809. }
  810. else if ((k==INVISIBLESTALKER) && (c[SEEINVISIBLE]==0))
  811. {
  812. *TileId = objnamelist[(int) know[x][y]];
  813. *Attr = ItemAttr[(int) know[x][y]];
  814. *ColorPair = ItemColor[(int) know[x][y]];
  815. }
  816. else if ((k>=DEMONLORD) && (k<=LUCIFER) && (c[EYEOFLARN]==0))
  817. {
  818. /* demons are invisible if not have the eye */
  819. *TileId = objnamelist[(int) know[x][y]];
  820. *Attr = ItemAttr[(int) know[x][y]];
  821. *ColorPair = ItemColor[(int) know[x][y]];
  822. }
  823. else
  824. {
  825. *TileId = monstnamelist[k];
  826. *ColorPair = MonstColor[k];
  827. }
  828. } /* can see monster */
  829. else
  830. {
  831. /*
  832. * The monster at this location is not known to the player, so show
  833. * the tile for the item at this location
  834. */
  835. *TileId = objnamelist[(int) know[x][y]];
  836. *Attr = ItemAttr[(int) know[x][y]];
  837. *ColorPair = ItemColor[(int) know[x][y]];
  838. }
  839. } /* monster here */
  840. else
  841. {
  842. k = know[x][y];
  843. *TileId = objnamelist[k];
  844. *Attr = ItemAttr[(int) know[x][y]];
  845. *ColorPair = ItemColor[(int) know[x][y]];
  846. }
  847. }
  848. /* Handle walls */
  849. if (*TileId == objnamelist[OWALL])
  850. {
  851. *TileId = WallTile[iarg[x][y]];
  852. }
  853. #ifdef W32_TTY
  854. if (*Attr & A_REVERSE)
  855. {
  856. /* If reverse on win32/pdcurses then use the reverse color pair */
  857. *Attr = (*Attr & (~A_REVERSE));
  858. *ColorPair += C_COUNT;
  859. }
  860. else
  861. {
  862. /* PD Curses also needs bold to make bright colours on win32 */
  863. *Attr |= A_BOLD;
  864. }
  865. #endif
  866. }
  867. /* =============================================================================
  868. * FUNCTION: PaintMap
  869. *
  870. * DESCRIPTION:
  871. * Repaint the map.
  872. *
  873. * PARAMETERS:
  874. *
  875. * None.
  876. *
  877. * RETURN VALUE:
  878. *
  879. * None.
  880. */
  881. static void PaintMap(void)
  882. {
  883. int x, y;
  884. int TileId;
  885. int Attr;
  886. int Color;
  887. if (Repaint)
  888. {
  889. wclear(MapWindow);
  890. for (y = 0 ; y < MAXY ; y++)
  891. {
  892. for (x = 0 ; x < MAXX ; x++)
  893. {
  894. GetTile(x, y, &TileId, &Attr, &Color);
  895. if (UseColor)
  896. {
  897. wattrset(MapWindow, Attr | COLOR_PAIR(Color));
  898. }
  899. else
  900. {
  901. wattrset(MapWindow, Attr);
  902. }
  903. mvwaddch(MapWindow, y, x, TileId);
  904. }
  905. }
  906. }
  907. wrefresh(MapWindow);
  908. }
  909. /* =============================================================================
  910. * FUNCTION: PaintTextWindow
  911. *
  912. * DESCRIPTION:
  913. * Repaint the window in text mode.
  914. *
  915. * PARAMETERS:
  916. *
  917. * None.
  918. *
  919. * RETURN VALUE:
  920. *
  921. * None.
  922. */
  923. static void PaintTextWindow(void)
  924. {
  925. touchwin(TextWindow);
  926. wrefresh(TextWindow);
  927. }
  928. /* =============================================================================
  929. * FUNCTION: PaintMapWindow
  930. *
  931. * DESCRIPTION:
  932. * Repaint the window in map mode
  933. *
  934. * PARAMETERS:
  935. *
  936. * None.
  937. *
  938. * RETURN VALUE:
  939. *
  940. * None.
  941. */
  942. static void PaintMapWindow(void)
  943. {
  944. PaintStatus();
  945. PaintEffects();
  946. PaintTextWindow();
  947. PaintMap();
  948. showplayer();
  949. }
  950. /* =============================================================================
  951. * FUNCTION: PaintWindow
  952. *
  953. * DESCRIPTION:
  954. * Repaint the window.
  955. *
  956. * PARAMETERS:
  957. *
  958. * None.
  959. *
  960. * RETURN VALUE:
  961. *
  962. * None.
  963. */
  964. static void PaintWindow(void)
  965. {
  966. Repaint = 1;
  967. if (CurrentDisplayMode == DISPLAY_MAP)
  968. {
  969. PaintMapWindow();
  970. }
  971. else
  972. {
  973. PaintTextWindow();
  974. }
  975. Repaint = 0;
  976. }
  977. /* =============================================================================
  978. * Exported functions
  979. */
  980. /* =============================================================================
  981. * FUNCTION: init_app
  982. */
  983. int init_app(void)
  984. {
  985. int x, y;
  986. /* Initialise curses app */
  987. initscr();
  988. cbreak();
  989. noecho();
  990. nonl();
  991. intrflush(stdscr, FALSE);
  992. // meta(stdscr, TRUE);
  993. start_color();
  994. setup_colour_pairs();
  995. keypad(stdscr, TRUE);
  996. /* Create windows */
  997. MapWindow = newwin(17, 67, 0, 0);
  998. StatusWindow = newwin(2, 80, 17, 0);
  999. EffectsWindow = newwin(17, 13, 0, 67);
  1000. MessageWindow = newwin(5, 80, 19, 0);
  1001. SetWallTiles();
  1002. /* Start colour mode for slowlaris */
  1003. wattrset(stdscr, A_STANDOUT | COLOR_PAIR(C_RED));
  1004. mvwaddch(stdscr, 0, 0, '*');
  1005. touchwin(stdscr);
  1006. wrefresh(stdscr);
  1007. UseColor = has_colors();
  1008. refresh();
  1009. //
  1010. // Clear the text buffers
  1011. //
  1012. TextWindow = MessageWindow;
  1013. SetCursesAttr(FORMAT_NORMAL);
  1014. for (y = 0 ; y < MAX_MSG_LINES ; y++)
  1015. {
  1016. for (x = 0 ; x < LINE_LENGTH ; x++)
  1017. {
  1018. mvwaddch(TextWindow, y, x, ' ');
  1019. }
  1020. }
  1021. wrefresh(TextWindow);
  1022. TextWindow = stdscr;
  1023. SetCursesAttr(FORMAT_NORMAL);
  1024. for (y = 0 ; y < MAX_TEXT_LINES ; y++)
  1025. {
  1026. for (x = 0 ; x < LINE_LENGTH ; x++)
  1027. {
  1028. mvwaddch(TextWindow, y, x, ' ');
  1029. }
  1030. }
  1031. wrefresh(TextWindow);
  1032. return 1;
  1033. }
  1034. /* =============================================================================
  1035. * FUNCTION: close_app
  1036. */
  1037. void close_app(void)
  1038. {
  1039. delwin(MessageWindow);
  1040. delwin(EffectsWindow);
  1041. delwin(StatusWindow);
  1042. delwin(MapWindow);
  1043. nl();
  1044. echo();
  1045. nocbreak();
  1046. endwin();
  1047. }
  1048. /* =============================================================================
  1049. * FUNCTION: get_normal_input
  1050. */
  1051. ActionType get_normal_input(void)
  1052. {
  1053. int idx;
  1054. int got_dir;
  1055. int Found;
  1056. ActionType Action;
  1057. int i;
  1058. Event = ACTION_NULL;
  1059. Runkey = 0;
  1060. while (Event == ACTION_NULL)
  1061. {
  1062. wrefresh(MapWindow);
  1063. EventChar = getch();
  1064. GotChar = 1;
  1065. //
  1066. // Decide the event corresponding to the key pressed
  1067. //
  1068. /* Decode key press as a ULarn Action */
  1069. /*
  1070. * Check ASCII key bindings if no virtual key matches and
  1071. * got a valid ASCII char
  1072. */
  1073. Found = 0;
  1074. if (!Found && GotChar)
  1075. {
  1076. Action = ACTION_NULL;
  1077. while ((Action < ACTION_COUNT) && (!Found))
  1078. {
  1079. for (i = 0 ; i < MAX_KEY_BINDINGS ; i++)
  1080. {
  1081. if (KeyMap[Action][i].ModKey == M_ASCII)
  1082. {
  1083. /* ASCII key binding */
  1084. if (EventChar == KeyMap[Action][i].VirtKey)
  1085. {
  1086. Found = 1;
  1087. }
  1088. }
  1089. }
  1090. if (!Found)
  1091. {
  1092. Action++;
  1093. }
  1094. }
  1095. }
  1096. if (Found)
  1097. {
  1098. Event = Action;
  1099. }
  1100. else
  1101. {
  1102. /* check run key */
  1103. if ((EventChar == RunKeyMap.VirtKey) &&
  1104. (RunKeyMap.ModKey == M_ASCII))
  1105. {
  1106. Runkey = 1;
  1107. }
  1108. }
  1109. //
  1110. // Clear enhanced interface events in enhanced interface is not active
  1111. //
  1112. if (!enhance_interface)
  1113. {
  1114. if ((Event == ACTION_OPEN_DOOR) ||
  1115. (Event == ACTION_OPEN_CHEST))
  1116. {
  1117. Event = ACTION_NULL;
  1118. }
  1119. }
  1120. }
  1121. if (Runkey)
  1122. {
  1123. idx = 0;
  1124. got_dir = 0;
  1125. while ((idx < NUM_DIRS) && (!got_dir))
  1126. {
  1127. if (DirActions[idx] == Event)
  1128. {
  1129. got_dir = 1;
  1130. }
  1131. else
  1132. {
  1133. idx++;
  1134. }
  1135. }
  1136. if (got_dir)
  1137. {
  1138. /* modify into a run event */
  1139. Event = Event + 1;
  1140. }
  1141. }
  1142. return Event;
  1143. }
  1144. /* =============================================================================
  1145. * FUNCTION: get_prompt_input
  1146. */
  1147. char get_prompt_input(char *prompt, char *answers, int ShowCursor)
  1148. {
  1149. char *ch;
  1150. Print(prompt);
  1151. if (ShowCursor)
  1152. {
  1153. CaretActive = 1;
  1154. }
  1155. //
  1156. // Process events until a character in answers has been pressed.
  1157. //
  1158. GotChar = 0;
  1159. while (!GotChar)
  1160. {
  1161. wrefresh(TextWindow);
  1162. EventChar = getch();
  1163. GotChar = 1;
  1164. if (GotChar)
  1165. {
  1166. //
  1167. // Search for the input character in the answers string
  1168. //
  1169. ch = strchr(answers, EventChar);
  1170. if (ch == NULL)
  1171. {
  1172. //
  1173. // Not an answer we want
  1174. //
  1175. GotChar = 0;
  1176. }
  1177. }
  1178. }
  1179. if (ShowCursor)
  1180. {
  1181. CaretActive = 0;
  1182. }
  1183. return EventChar;
  1184. }
  1185. /* =============================================================================
  1186. * FUNCTION: get_password_input
  1187. */
  1188. void get_password_input(char *password, int Len)
  1189. {
  1190. char ch;
  1191. char inputchars[256];
  1192. int Pos;
  1193. int value;
  1194. /* get the printable characters on this system */
  1195. Pos = 0;
  1196. for (value = 0 ; value < 256 ; value++)
  1197. {
  1198. if (isprint(value))
  1199. {
  1200. inputchars[Pos] = (char) value;
  1201. Pos++;
  1202. }
  1203. }
  1204. /* add CR, BS and null terminator */
  1205. inputchars[Pos++] = '\010';
  1206. inputchars[Pos++] = '\015';
  1207. inputchars[Pos] = '\0';
  1208. Pos = 0;
  1209. do
  1210. {
  1211. ch = get_prompt_input("", inputchars, 1);
  1212. if (isprint((int) ch) && (Pos < Len))
  1213. {
  1214. password[Pos] = ch;
  1215. Pos++;
  1216. Printc('*');
  1217. }
  1218. else if (ch == '\010')
  1219. {
  1220. //
  1221. // Backspace
  1222. //
  1223. if (Pos > 0)
  1224. {
  1225. CursorX--;
  1226. Printc(' ');
  1227. CursorX--;
  1228. Pos--;
  1229. wmove(TextWindow, CursorY-1, CursorX-1);
  1230. wrefresh(TextWindow);
  1231. }
  1232. }
  1233. } while (ch != '\015');
  1234. password[Pos] = 0;
  1235. }
  1236. #if 0
  1237. /* =============================================================================
  1238. * FUNCTION: get_string_input
  1239. */
  1240. static void get_string_input(char *string, int Len)
  1241. {
  1242. char ch;
  1243. char inputchars[256];
  1244. int Pos;
  1245. int value;
  1246. /* get the printable characters on this system */
  1247. Pos = 0;
  1248. for (value = 0 ; value < 256 ; value++)
  1249. {
  1250. if (isprint(value))
  1251. {
  1252. inputchars[Pos] = (char) value;
  1253. Pos++;
  1254. }
  1255. }
  1256. /* add CR, BS and null terminator */
  1257. inputchars[Pos++] = '\010';
  1258. inputchars[Pos++] = '\015';
  1259. inputchars[Pos] = '\0';
  1260. Pos = 0;
  1261. do
  1262. {
  1263. ch = get_prompt_input("", inputchars, 1);
  1264. if (isprint((int) ch) && (Pos < Len))
  1265. {
  1266. string[Pos] = ch;
  1267. Pos++;
  1268. Printc(ch);
  1269. }
  1270. else if (ch == '\010')
  1271. {
  1272. //
  1273. // Backspace
  1274. //
  1275. if (Pos > 0)
  1276. {
  1277. CursorX--;
  1278. Printc(' ');
  1279. CursorX--;
  1280. Pos--;
  1281. wmove(TextWindow, CursorY-1, CursorX-1);
  1282. wrefresh(TextWindow);
  1283. }
  1284. }
  1285. } while (ch != '\015');
  1286. string[Pos] = 0;
  1287. }
  1288. #endif
  1289. /* =============================================================================
  1290. * FUNCTION: get_num_input
  1291. */
  1292. int get_num_input(int defval)
  1293. {
  1294. char ch;
  1295. int Pos = 0;
  1296. int value = 0;
  1297. int neg = 0;
  1298. do
  1299. {
  1300. ch = get_prompt_input("", "-*0123456789\010\015", 1);
  1301. if ((ch == '-') && (Pos == 0))
  1302. {
  1303. //
  1304. // Minus
  1305. //
  1306. neg = 1;
  1307. Printc(ch);
  1308. Pos++;
  1309. }
  1310. if (ch == '*')
  1311. {
  1312. return defval;
  1313. }
  1314. else if (ch == '\010')
  1315. {
  1316. //
  1317. // Backspace
  1318. //
  1319. if (Pos > 0)
  1320. {
  1321. if ((Pos == 1) && neg)
  1322. {
  1323. neg = 0;
  1324. }
  1325. else
  1326. {
  1327. value = value / 10;
  1328. }
  1329. CursorX--;
  1330. Printc(' ');
  1331. CursorX--;
  1332. Pos--;
  1333. wmove(TextWindow, CursorY-1, CursorX-1);
  1334. wrefresh(TextWindow);
  1335. }
  1336. }
  1337. else if ((ch >= '0') && (ch <= '9'))
  1338. {
  1339. //
  1340. // digit
  1341. //
  1342. value = value * 10 + (ch - '0');
  1343. Printc(ch);
  1344. Pos++;
  1345. }
  1346. } while (ch != '\015');
  1347. if (Pos == 0)
  1348. {
  1349. return defval;
  1350. }
  1351. else
  1352. {
  1353. if (neg) value = -value;
  1354. return value;
  1355. }
  1356. }
  1357. /* =============================================================================
  1358. * FUNCTION: get_dir_input
  1359. */
  1360. ActionType get_dir_input(char *prompt, int ShowCursor)
  1361. {
  1362. int got_dir;
  1363. int idx;
  1364. //
  1365. // Display the prompt at the current position
  1366. //
  1367. Print(prompt);
  1368. //
  1369. // Show the cursor if required
  1370. //
  1371. if (ShowCursor)
  1372. {
  1373. CaretActive = 1;
  1374. }
  1375. Event = ACTION_NULL;
  1376. got_dir = 0;
  1377. while (!got_dir)
  1378. {
  1379. get_normal_input();
  1380. idx = 0;
  1381. while ((idx < NUM_DIRS) && (!got_dir))
  1382. {
  1383. if (DirActions[idx] == Event)
  1384. {
  1385. got_dir = 1;
  1386. }
  1387. else
  1388. {
  1389. idx++;
  1390. }
  1391. }
  1392. }
  1393. if (ShowCursor)
  1394. {
  1395. CaretActive = 0;
  1396. }
  1397. return Event;
  1398. }
  1399. /* =============================================================================
  1400. * FUNCTION: UpdateStatus
  1401. */
  1402. void UpdateStatus(void)
  1403. {
  1404. if (CurrentDisplayMode == DISPLAY_TEXT)
  1405. {
  1406. /* Don't redisplay if in text mode */
  1407. return;
  1408. }
  1409. PaintStatus();
  1410. }
  1411. /* =============================================================================
  1412. * FUNCTION: UpdateEffects
  1413. */
  1414. void UpdateEffects(void)
  1415. {
  1416. if (CurrentDisplayMode == DISPLAY_TEXT)
  1417. {
  1418. /* Don't redisplay if in text mode */
  1419. return;
  1420. }
  1421. PaintEffects();
  1422. }
  1423. /* =============================================================================
  1424. * FUNCTION: UpdateStatusAndEffects
  1425. */
  1426. void UpdateStatusAndEffects(void)
  1427. {
  1428. if (CurrentDisplayMode == DISPLAY_TEXT)
  1429. {
  1430. /* Don't redisplay if in text mode */
  1431. return;
  1432. }
  1433. //
  1434. // Do effects first as update status will mark all effects as current
  1435. //
  1436. PaintEffects();
  1437. PaintStatus();
  1438. }
  1439. /* =============================================================================
  1440. * FUNCTION: set_display
  1441. */
  1442. void set_display(DisplayModeType Mode)
  1443. {
  1444. //
  1445. // Save the current settings
  1446. //
  1447. if (CurrentDisplayMode == DISPLAY_MAP)
  1448. {
  1449. MsgCursorX = CursorX;
  1450. MsgCursorY = CursorY;
  1451. CurrentMsgFormat = CurrentFormat;
  1452. }
  1453. else if (CurrentDisplayMode == DISPLAY_TEXT)
  1454. {
  1455. TextCursorX = CursorX;
  1456. TextCursorY = CursorY;
  1457. CurrentTextFormat = CurrentFormat;
  1458. }
  1459. CurrentDisplayMode = Mode;
  1460. //
  1461. // Set the text buffer settings for the new display mode
  1462. //
  1463. if (CurrentDisplayMode == DISPLAY_MAP)
  1464. {
  1465. CursorX = MsgCursorX;
  1466. CursorY = MsgCursorY;
  1467. CurrentFormat = CurrentMsgFormat;
  1468. MaxLine = MAX_MSG_LINES;
  1469. TextWindow = MessageWindow;
  1470. }
  1471. else if (CurrentDisplayMode == DISPLAY_TEXT)
  1472. {
  1473. CursorX = TextCursorX;
  1474. CursorY = TextCursorY;
  1475. CurrentFormat = CurrentTextFormat;
  1476. MaxLine = MAX_TEXT_LINES;
  1477. TextWindow = stdscr;
  1478. }
  1479. PaintWindow();
  1480. }
  1481. /* =============================================================================
  1482. * FUNCTION: IncCursorY
  1483. *
  1484. * DESCRIPTION:
  1485. * Increae the cursor y position, scrolling the text window if requried.
  1486. *
  1487. * PARAMETERS:
  1488. *
  1489. * Count : The number of lines to increase the cursor y position
  1490. *
  1491. * RETURN VALUE:
  1492. *
  1493. * None.
  1494. */
  1495. static void IncCursorY(int Count)
  1496. {
  1497. /*int Scroll;*/
  1498. int inc;
  1499. int x;
  1500. inc = Count;
  1501. /*Scroll = 0;*/
  1502. while (inc > 0)
  1503. {
  1504. CursorY = CursorY + 1;
  1505. if (CursorY > MaxLine)
  1506. {
  1507. /*Scroll = 1;*/
  1508. CursorY--;
  1509. scrollok(TextWindow, 1);
  1510. scroll(TextWindow);
  1511. scrollok(TextWindow, 0);
  1512. SetCursesAttr(FORMAT_NORMAL);
  1513. for (x = 0 ; x < LINE_LENGTH ; x++)
  1514. {
  1515. mvwaddch(TextWindow, CursorY-1, x, ' ');
  1516. }
  1517. }
  1518. inc--;
  1519. }
  1520. wrefresh(TextWindow);
  1521. }
  1522. /* =============================================================================
  1523. * FUNCTION: IncCursorX
  1524. *
  1525. * DESCRIPTION:
  1526. * Increase the cursor x position, handling line wrap.
  1527. *
  1528. * PARAMETERS:
  1529. *
  1530. * Count : The amount to increase the cursor x position.
  1531. *
  1532. * RETURN VALUE:
  1533. *
  1534. * None.
  1535. */
  1536. static void IncCursorX(int Count)
  1537. {
  1538. CursorX = CursorX + Count;
  1539. if (CursorX > LINE_LENGTH)
  1540. {
  1541. CursorX = 1;
  1542. IncCursorY(1);
  1543. }
  1544. }
  1545. /* =============================================================================
  1546. * FUNCTION: ClearText
  1547. */
  1548. void ClearText(void)
  1549. {
  1550. int x, y;
  1551. //
  1552. // Clear the text buffer
  1553. //
  1554. SetCursesAttr(FORMAT_NORMAL);
  1555. for (y = 0 ; y < MaxLine ; y++)
  1556. {
  1557. for (x = 0 ; x < LINE_LENGTH ; x++)
  1558. {
  1559. mvwaddch(TextWindow, y, x, ' ');
  1560. }
  1561. }
  1562. wrefresh(TextWindow);
  1563. CursorX = 1;
  1564. CursorY = 1;
  1565. }
  1566. /* =============================================================================
  1567. * FUNCTION: beep
  1568. */
  1569. void UlarnBeep(void)
  1570. {
  1571. //
  1572. // Play a beep
  1573. //
  1574. if (!nobeep)
  1575. {
  1576. #ifdef W32_TTY
  1577. //
  1578. // beep seems to cause problems under windows, so put a bell
  1579. //
  1580. putch(7);
  1581. #else
  1582. beep();
  1583. #endif
  1584. }
  1585. }
  1586. /* =============================================================================
  1587. * FUNCTION: Cursor
  1588. */
  1589. void MoveCursor(int x, int y)
  1590. {
  1591. CursorX = x;
  1592. CursorY = y;
  1593. }
  1594. static int RefreshEachChar = 1;
  1595. /* =============================================================================
  1596. * FUNCTION: Printc
  1597. */
  1598. void Printc(char c)
  1599. {
  1600. int incx;
  1601. switch (c)
  1602. {
  1603. case '\t':
  1604. incx = ((((CursorX - 1) / 8) + 1) * 8 + 1) - CursorX;
  1605. IncCursorX(incx);
  1606. break;
  1607. case '\n':
  1608. CursorX = 1;
  1609. IncCursorY(1);
  1610. break;
  1611. case '\015':
  1612. break;
  1613. default:
  1614. SetCursesAttr(CurrentFormat);
  1615. mvwaddch(TextWindow, CursorY-1, CursorX - 1, c);
  1616. if (RefreshEachChar)
  1617. {
  1618. wrefresh(TextWindow);
  1619. }
  1620. IncCursorX(1);
  1621. break;
  1622. }
  1623. }
  1624. /* =============================================================================
  1625. * FUNCTION: Print
  1626. */
  1627. void Print(char *string)
  1628. {
  1629. int Len;
  1630. int pos;
  1631. if (string == NULL) return;
  1632. Len = strlen(string);
  1633. if (Len == 0) return;
  1634. RefreshEachChar = 0;
  1635. for (pos = 0 ; pos < Len ; pos++)
  1636. {
  1637. Printc(string[pos]);
  1638. }
  1639. RefreshEachChar = 1;
  1640. wrefresh(TextWindow);
  1641. }
  1642. /* =============================================================================
  1643. * FUNCTION: Printf
  1644. */
  1645. void Printf(char *fmt, ...)
  1646. {
  1647. char buf[2048];
  1648. va_list argptr;
  1649. va_start(argptr, fmt);
  1650. vsprintf(buf, fmt, argptr);
  1651. va_end(argptr);
  1652. Print(buf);
  1653. }
  1654. /* =============================================================================
  1655. * FUNCTION: Standout
  1656. */
  1657. void Standout(char *String)
  1658. {
  1659. CurrentFormat = FORMAT_STANDOUT;
  1660. Print(String);
  1661. CurrentFormat = FORMAT_NORMAL;
  1662. }
  1663. /* =============================================================================
  1664. * FUNCTION: SetFormat
  1665. */
  1666. void SetFormat(FormatType format)
  1667. {
  1668. CurrentFormat = format;
  1669. }
  1670. /* =============================================================================
  1671. * FUNCTION: ClearToEOL
  1672. */
  1673. void ClearToEOL(void)
  1674. {
  1675. int x;
  1676. for (x = CursorX ; x <= LINE_LENGTH ; x++)
  1677. {
  1678. SetCursesAttr(FORMAT_NORMAL);
  1679. mvwaddch(TextWindow, CursorY-1, x-1, ' ');
  1680. }
  1681. }
  1682. /* =============================================================================
  1683. * FUNCTION: ClearToEOPage
  1684. */
  1685. void ClearToEOPage(int x, int y)
  1686. {
  1687. int tx, ty;
  1688. SetCursesAttr(FORMAT_NORMAL);
  1689. for (tx = x ; tx <= LINE_LENGTH ; tx++)
  1690. {
  1691. mvwaddch(TextWindow, y-1, tx-1, ' ');
  1692. }
  1693. for (ty = y+1 ; ty <= MaxLine ; ty++)
  1694. {
  1695. for (tx = 1 ; tx <= LINE_LENGTH ; tx++)
  1696. {
  1697. mvwaddch(TextWindow, ty-1, tx-1, ' ');
  1698. }
  1699. }
  1700. }
  1701. /* =============================================================================
  1702. * FUNCTION: show1cell
  1703. */
  1704. void show1cell(int x, int y)
  1705. {
  1706. int TileId;
  1707. int Attr;
  1708. int Color;
  1709. /* see nothing if blind */
  1710. if (c[BLINDCOUNT]) return;
  1711. /* we end up knowing about it */
  1712. know[x][y] = item[x][y];
  1713. if (mitem[x][y].mon != MONST_NONE)
  1714. {
  1715. stealth[x][y] |= STEALTH_SEEN;
  1716. }
  1717. GetTile(x, y, &TileId, &Attr, &Color);
  1718. wattrset(MapWindow, Attr | COLOR_PAIR(Color));
  1719. mvwaddch(MapWindow, y, x, TileId);
  1720. wrefresh(MapWindow);
  1721. }
  1722. /* =============================================================================
  1723. * FUNCTION: showplayer
  1724. */
  1725. void showplayer(void)
  1726. {
  1727. int TileId;
  1728. int Attr;
  1729. int Color;
  1730. //
  1731. // Determine if we need to scroll the map
  1732. //
  1733. if (c[BLINDCOUNT] == 0)
  1734. {
  1735. TileId = '@';
  1736. #ifdef W32_TTY
  1737. Attr = A_BOLD;
  1738. #else
  1739. Attr = 0;
  1740. #endif
  1741. Color = C_RED;
  1742. }
  1743. else
  1744. {
  1745. GetTile(playerx, playery, &TileId, &Attr, &Color);
  1746. }
  1747. wattrset(MapWindow, Attr | COLOR_PAIR(Color));
  1748. mvwaddch(MapWindow, playery, playerx, TileId);
  1749. wmove(MapWindow, playery, playerx);
  1750. wrefresh(MapWindow);
  1751. }
  1752. /* =============================================================================
  1753. * FUNCTION: showcell
  1754. */
  1755. void showcell(int x, int y)
  1756. {
  1757. int minx, maxx;
  1758. int miny, maxy;
  1759. int mx, my;
  1760. int TileId;
  1761. int Attr;
  1762. int Color;
  1763. /*
  1764. * Decide how much the player knows about around him/her.
  1765. */
  1766. if (c[AWARENESS])
  1767. {
  1768. minx = x-3;
  1769. maxx = x+3;
  1770. miny = y-3;
  1771. maxy = y+3;
  1772. }
  1773. else
  1774. {
  1775. minx = x-1;
  1776. maxx = x+1;
  1777. miny = y-1;
  1778. maxy = y+1;
  1779. }
  1780. if (c[BLINDCOUNT])
  1781. {
  1782. minx = x;
  1783. maxx = x;
  1784. miny = y;
  1785. maxy = y;
  1786. }
  1787. /*
  1788. * Limit the area to the map extents
  1789. */
  1790. if (minx < 0) minx = 0;
  1791. if (maxx > MAXX-1) maxx = MAXX-1;
  1792. if (miny < 0) miny=0;
  1793. if (maxy > MAXY-1) maxy = MAXY-1;
  1794. for (my = miny; my <= maxy; my++)
  1795. {
  1796. for (mx = minx; mx <= maxx; mx++)
  1797. {
  1798. if ((mx == playerx) && (my == playery))
  1799. {
  1800. know[mx][my] = item[mx][my];
  1801. }
  1802. else if ((know[mx][my] != item[mx][my]) || /* item changed */
  1803. ((mx == lastpx) && (my == lastpy)) || /* last player pos */
  1804. ((mitem[mx][my].mon != MONST_NONE) && /* unseen monster */
  1805. ((stealth[mx][my] & STEALTH_SEEN) == 0)))
  1806. {
  1807. //
  1808. // Only draw areas not already known (and hence displayed)
  1809. //
  1810. know[mx][my] = item[mx][my];
  1811. if (mitem[mx][my].mon != MONST_NONE)
  1812. {
  1813. stealth[mx][my] |= STEALTH_SEEN;
  1814. }
  1815. GetTile(mx, my, &TileId, &Attr, &Color);
  1816. wattrset(MapWindow, Attr | COLOR_PAIR(Color));
  1817. mvwaddch(MapWindow, my, mx, TileId);
  1818. } // if not known
  1819. }
  1820. }
  1821. showplayer();
  1822. }
  1823. /* =============================================================================
  1824. * FUNCTION: drawscreen
  1825. */
  1826. void drawscreen(void)
  1827. {
  1828. PaintWindow();
  1829. }
  1830. /* =============================================================================
  1831. * FUNCTION: draws
  1832. */
  1833. void draws(int minx, int miny, int maxx, int maxy)
  1834. {
  1835. (void) minx;
  1836. (void) miny;
  1837. (void) maxx;
  1838. (void) maxy;
  1839. PaintWindow();
  1840. }
  1841. /* =============================================================================
  1842. * FUNCTION: mapeffect
  1843. */
  1844. void mapeffect(int x, int y, DirEffectsType effect, int dir)
  1845. {
  1846. wattrset(MapWindow, A_NORMAL | COLOR_PAIR(EffectColor[effect]));
  1847. mvwaddch(MapWindow, y, x, EffectTile[effect][dir]);
  1848. wmove(MapWindow, 0, 0);
  1849. touchwin(MapWindow);
  1850. wrefresh(MapWindow);
  1851. }
  1852. /* =============================================================================
  1853. * FUNCTION: magic_effect_frames
  1854. */
  1855. int magic_effect_frames(MagicEffectsType fx)
  1856. {
  1857. return magicfx_tile[fx].Frames;
  1858. }
  1859. /* =============================================================================
  1860. * FUNCTION: magic_effect
  1861. */
  1862. void magic_effect(int x, int y, MagicEffectsType fx, int frame)
  1863. {
  1864. wattrset(MapWindow, COLOR_PAIR(magicfx_tile[fx].Color[frame]));
  1865. mvwaddch(MapWindow, y, x, magicfx_tile[fx].Tile[frame]);
  1866. wmove(MapWindow, 0, 0);
  1867. touchwin(MapWindow);
  1868. wrefresh(MapWindow);
  1869. }
  1870. /* =============================================================================
  1871. * FUNCTION: nap
  1872. */
  1873. void nap(int delay)
  1874. {
  1875. #ifdef UNIX
  1876. usleep(delay * 1000);
  1877. #else
  1878. napms(delay);
  1879. #endif
  1880. }
  1881. /* =============================================================================
  1882. * FUNCTION: GetUser
  1883. */
  1884. void GetUser(char *username, int *uid)
  1885. {
  1886. #ifdef UNIX
  1887. *uid = getuid();
  1888. strcpy(username, getenv("USER"));
  1889. #else
  1890. FILE *fp;
  1891. char TmpName[80];
  1892. int TmpPid;
  1893. int Found;
  1894. int n;
  1895. if (username[0] == 0)
  1896. {
  1897. //
  1898. // Name is not yet specified, so ask player for the name
  1899. //
  1900. Print("Who are you? ");
  1901. get_string_input(username, USERNAME_LENGTH);
  1902. if (strlen(username) == 0)
  1903. {
  1904. strcpy(username, "Anon");
  1905. }
  1906. }
  1907. /* get the Player Id */
  1908. fp = fopen (PIDName, "rb");
  1909. if (fp == NULL)
  1910. {
  1911. /* Need to create the PID file. */
  1912. fp = fopen(PIDName, "wb");
  1913. if (fp != NULL)
  1914. {
  1915. *uid = FIRST_PID;
  1916. fwrite(username, USERNAME_LENGTH + 1, 1, fp);
  1917. fwrite(uid, sizeof(int), 1, fp);
  1918. fclose(fp);
  1919. }
  1920. }
  1921. else
  1922. {
  1923. /* search the PID file for this player id */
  1924. Found = 0;
  1925. TmpPid = FIRST_PID;
  1926. while (!feof(fp) && !Found)
  1927. {
  1928. n = fread(TmpName, USERNAME_LENGTH + 1, 1, fp);
  1929. if (n == 1)
  1930. {
  1931. n = fread(&TmpPid, sizeof(int), 1, fp);
  1932. }
  1933. if (n == 1)
  1934. {
  1935. if (strcmp(TmpName, username) == 0)
  1936. {
  1937. *uid = TmpPid;
  1938. Found = 1;
  1939. }
  1940. }
  1941. }
  1942. fclose(fp);
  1943. if (!Found)
  1944. {
  1945. *uid = TmpPid + 1;
  1946. fp = fopen(PIDName, "ab");
  1947. if (fp != NULL)
  1948. {
  1949. fwrite(username, USERNAME_LENGTH + 1, 1, fp);
  1950. fwrite(uid, sizeof(int), 1, fp);
  1951. fclose(fp);
  1952. }
  1953. }
  1954. }
  1955. #endif
  1956. }