Source:NetHack 3.1.0/botl.c
Jump to navigation
Jump to search
Below is the full text to botl.c from the source code of NetHack 3.1.0.
Warning! This is the source code from an old release. For newer releases, see Source code
The NetHack General Public License applies to screenshots, source code and other content from NetHack.
This content was modified from the original NetHack source code distribution (by splitting up NetHack content between wiki pages, and possibly further editing). See the page history for a list of who changed it, and on what dates.
1. /* SCCS Id: @(#)botl.c 3.1 93/01/17 */ 2. /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */ 3. /* NetHack may be freely redistributed. See license for details. */ 4. 5. #include "hack.h" 6. 7. #ifdef OVL0 8. extern const char *hu_stat[]; /* defined in eat.c */ 9. 10. const char *enc_stat[] = { 11. "", 12. "Burdened", 13. "Stressed", 14. "Strained", 15. "Overtaxed", 16. "Overloaded" 17. }; 18. 19. static void NDECL(bot1); 20. static void NDECL(bot2); 21. #endif /* OVL0 */ 22. 23. /* 100 suffices for bot(); must be larger than COLNO */ 24. #if COLNO <= 80 25. #define MAXCO 100 26. #else 27. #define MAXCO (COLNO+20) 28. #endif 29. 30. #ifndef OVLB 31. STATIC_DCL int mrank_sz; 32. #else /* OVLB */ 33. STATIC_OVL int NEARDATA mrank_sz = 0; /* loaded by max_rank_sz (from u_init) */ 34. #endif /* OVLB */ 35. 36. struct rank_title { 37. char const * const m; /* male title */ 38. char const * const f; /* female title, or 0 if same as male */ 39. }; 40. struct class_ranks { 41. char plclass, fill_; 42. short mplayer_class; 43. struct rank_title titles[9]; 44. }; 45. 46. STATIC_DCL const struct rank_title *FDECL(rank_array, (CHAR_P)); 47. STATIC_DCL const char *NDECL(rank); 48. 49. #ifdef OVL1 50. 51. /* 9 pairs of ranks for each class */ 52. 53. static const 54. struct class_ranks all_classes[] = { 55. { 'A',0, PM_ARCHEOLOGIST, { 56. {"Digger", 0}, 57. {"Field Worker",0}, 58. {"Investigator",0}, 59. {"Exhumer", 0}, 60. {"Excavator", 0}, 61. {"Spelunker", 0}, 62. {"Speleologist",0}, 63. {"Collector", 0}, 64. {"Curator", 0} 65. } }, 66. { 'B',0, PM_BARBARIAN, { 67. {"Plunderer", "Plunderess"}, 68. {"Pillager", 0}, 69. {"Bandit", 0}, 70. {"Brigand", 0}, 71. {"Raider", 0}, 72. {"Reaver", 0}, 73. {"Slayer", 0}, 74. {"Chieftain", "Chieftainess"}, 75. {"Conqueror", "Conqueress"} 76. } }, 77. { 'C',0, PM_CAVEMAN, { 78. {"Troglodyte", 0}, 79. {"Aborigine", 0}, 80. {"Wanderer", 0}, 81. {"Vagrant", 0}, 82. {"Wayfarer", 0}, 83. {"Roamer", 0}, 84. {"Nomad", 0}, 85. {"Rover", 0}, 86. {"Pioneer", 0} 87. } }, 88. { 'E',0, PM_ELF, { 89. {"Edhel", "Elleth"}, 90. {"Edhel", "Elleth"}, /* elf-maid */ 91. {"Ohtar", "Ohtie"}, /* warrior */ 92. {"Kano", /* commander (Q.) ['a] */ 93. "Kanie"}, /* educated guess, until further research- SAC */ 94. {"Arandur", /* king's servant, minister (Q.) - guess */ 95. "Aranduriel"}, /* educated guess */ 96. {"Hir", "Hiril"}, /* lord, lady (S.) ['ir] */ 97. {"Aredhel", "Arwen"}, /* noble elf, maiden (S.) */ 98. {"Ernil", "Elentariel"}, /* prince (S.), elf-maiden (Q.) */ 99. {"Elentar", "Elentari"} /* Star-king, -queen (Q.) */ 100. } }, 101. { 'H',0, PM_HEALER, { 102. {"Barber", "Midwife"}, 103. {"Leech", 0}, 104. {"Embalmer", 0}, 105. {"Dresser", 0}, 106. {"Bone Setter", 0}, 107. {"Herbalist", 0}, 108. {"Apothecary", 0}, 109. {"Physician", 0}, 110. {"Chirurgeon", 0} 111. } }, 112. { 'K',0, PM_KNIGHT, { 113. {"Gallant", 0}, 114. {"Esquire", 0}, 115. {"Bachelor", 0}, 116. {"Sergeant", 0}, 117. {"Knight", 0}, 118. {"Banneret", 0}, 119. {"Chevalier", 0}, 120. {"Seignieur", 0}, 121. {"Paladin", 0} 122. } }, 123. { 'P',0, PM_PRIEST, { 124. {"Aspirant", 0}, 125. {"Acolyte", 0}, 126. {"Adept", 0}, 127. {"Priest", "Priestess"}, 128. {"Curate", 0}, 129. {"Canon", "Canoness"}, 130. {"Lama", 0}, 131. {"Patriarch", "Matriarch"}, 132. {"High Priest", "High Priestess"} 133. } }, 134. { 'R',0, PM_ROGUE, { 135. {"Footpad", 0}, 136. {"Cutpurse", 0}, 137. {"Rogue", 0}, 138. {"Pilferer", 0}, 139. {"Robber", 0}, 140. {"Burglar", 0}, 141. {"Filcher", 0}, 142. {"Magsman", "Magswoman"}, 143. {"Thief", 0} 144. } }, 145. { 'S',0, PM_SAMURAI, { 146. {"Hatamoto", 0}, /* Banner Knight */ 147. {"Ronin", 0}, /* no allegiance */ 148. {"Ninja", 0}, /* secret society */ 149. {"Joshu", 0}, /* heads a castle */ 150. {"Ryoshu", 0}, /* has a territory */ 151. {"Kokushu", 0}, /* heads a province */ 152. {"Daimyo", 0}, /* a samurai lord */ 153. {"Kuge", 0}, /* Noble of the Court */ 154. {"Shogun", 0} /* supreme commander, warlord */ 155. } }, 156. #ifdef TOURIST 157. { 'T',0, PM_TOURIST, { 158. {"Rambler", 0}, 159. {"Sightseer", 0}, 160. {"Excursionist",0}, 161. {"Peregrinator","Peregrinatrix"}, 162. {"Traveler", 0}, 163. {"Journeyer", 0}, 164. {"Voyager", 0}, 165. {"Explorer", 0}, 166. {"Adventurer", 0} 167. } }, 168. #endif 169. { 'V',0, PM_VALKYRIE, { 170. {"Stripling", 0}, 171. {"Skirmisher", 0}, 172. {"Fighter", 0}, 173. {"Man-at-arms", "Woman-at-arms"}, 174. {"Warrior", 0}, 175. {"Swashbuckler",0}, 176. {"Hero", "Heroine"}, 177. {"Champion", 0}, 178. {"Lord", "Lady"} 179. } }, 180. { 'W',0, PM_WIZARD, { 181. {"Evoker", 0}, 182. {"Conjurer", 0}, 183. {"Thaumaturge", 0}, 184. {"Magician", 0}, 185. {"Enchanter", "Enchantress"}, 186. {"Sorcerer", "Sorceress"}, 187. {"Necromancer", 0}, 188. {"Wizard", 0}, 189. {"Mage", 0} 190. } }, 191. }; 192. 193. STATIC_OVL const struct rank_title * 194. rank_array(pc) 195. char pc; 196. { 197. register int i; 198. 199. for (i = 0; i < SIZE(all_classes); i++) 200. if (all_classes[i].plclass == pc) return all_classes[i].titles; 201. return 0; 202. } 203. 204. /* convert experience level (1..30) to rank index (0..8) */ 205. int xlev_to_rank(xlev) 206. int xlev; 207. { 208. return (xlev <= 2) ? 0 : (xlev <= 30) ? ((xlev + 2) / 4) : 8; 209. } 210. 211. #if 0 /* not currently needed */ 212. /* convert rank index (0..8) to experience level (1..30) */ 213. int rank_to_xlev(rank) 214. int rank; 215. { 216. return (rank <= 0) ? 1 : (rank <= 8) ? ((rank * 4) - 2) : 30; 217. } 218. #endif 219. 220. const char * 221. rank_of(lev, pc, female) 222. register unsigned lev; 223. char pc; 224. boolean female; 225. { 226. register int idx = xlev_to_rank((int)lev); 227. const struct rank_title *ranks = rank_array(pc); 228. 229. if (ranks) 230. return( female && ranks[idx].f ? ranks[idx].f : ranks[idx].m ); 231. return(pl_character); 232. } 233. 234. STATIC_OVL const char * 235. rank() 236. { 237. return(rank_of(u.ulevel, pl_character[0], flags.female)); 238. } 239. 240. int 241. title_to_mon(str, rank_indx, title_length) 242. const char *str; 243. int *rank_indx, *title_length; 244. { 245. register int i, j; 246. register const struct rank_title *ttl; 247. 248. for (i = 0; i < SIZE(all_classes); i++) 249. for (j = 0; j < 9; j++) { 250. ttl = &all_classes[i].titles[j]; 251. if (!strncmpi(ttl->m, str, strlen(ttl->m))) { 252. if (rank_indx) *rank_indx = j; 253. if (title_length) *title_length = strlen(ttl->m); 254. return all_classes[i].mplayer_class; 255. } else if (ttl->f && !strncmpi(ttl->f, str, strlen(ttl->f))) { 256. if (rank_indx) *rank_indx = j; 257. if (title_length) *title_length = strlen(ttl->f); 258. return all_classes[i].plclass == 'C' ? PM_CAVEWOMAN : 259. all_classes[i].plclass == 'P' ? PM_PRIESTESS : 260. all_classes[i].mplayer_class; 261. } 262. } 263. return -1; /* not found */ 264. } 265. 266. #endif /* OVL1 */ 267. #ifdef OVLB 268. 269. void 270. max_rank_sz() 271. { 272. register int i, r, maxr = 0; 273. const struct rank_title *ranks = rank_array(pl_character[0]); 274. 275. if (ranks) { 276. for (i = 0; i < 9; i++) { 277. if ((r = strlen(ranks[i].m)) > maxr) maxr = r; 278. if (ranks[i].f) 279. if ((r = strlen(ranks[i].f)) > maxr) maxr = r; 280. } 281. mrank_sz = maxr; 282. } 283. else mrank_sz = strlen(pl_character); 284. } 285. 286. #endif /* OVLB */ 287. #ifdef OVL0 288. 289. static void 290. bot1() 291. { 292. char newbot1[MAXCO]; 293. register char *nb; 294. register int i,j; 295. 296. Strcpy(newbot1, plname); 297. if('a' <= newbot1[0] && newbot1[0] <= 'z') newbot1[0] += 'A'-'a'; 298. newbot1[10] = 0; 299. Sprintf(nb = eos(newbot1)," the "); 300. #ifdef POLYSELF 301. if (u.mtimedone) { 302. char mbot[BUFSZ]; 303. int k = 0; 304. 305. Strcpy(mbot, mons[u.umonnum].mname); 306. while(mbot[k] != 0) { 307. if ((k == 0 || (k > 0 && mbot[k-1] == ' ')) && 308. 'a' <= mbot[k] && mbot[k] <= 'z') 309. mbot[k] += 'A' - 'a'; 310. k++; 311. } 312. Sprintf(nb = eos(nb), mbot); 313. } else 314. Sprintf(nb = eos(nb), rank()); 315. #else 316. Sprintf(nb = eos(nb), rank()); 317. #endif 318. Sprintf(nb = eos(nb)," "); 319. i = mrank_sz + 15; 320. j = (nb + 2) - newbot1; /* aka strlen(newbot1) but less computation */ 321. if((i - j) > 0) 322. Sprintf(nb = eos(nb),"%*s", i-j, " "); /* pad with spaces */ 323. if (ACURR(A_STR) > 18) { 324. if (ACURR(A_STR) > 118) 325. Sprintf(nb = eos(nb),"St:%2d ",ACURR(A_STR)-100); 326. else if (ACURR(A_STR) < 118) 327. Sprintf(nb = eos(nb), "St:18/%02d ",ACURR(A_STR)-18); 328. else 329. Sprintf(nb = eos(nb),"St:18/** "); 330. } else 331. Sprintf(nb = eos(nb), "St:%-1d ",ACURR(A_STR)); 332. Sprintf(nb = eos(nb), 333. "Dx:%-1d Co:%-1d In:%-1d Wi:%-1d Ch:%-1d", 334. ACURR(A_DEX), ACURR(A_CON), ACURR(A_INT), ACURR(A_WIS), ACURR(A_CHA)); 335. Sprintf(nb = eos(nb), (u.ualign.type == A_CHAOTIC) ? " Chaotic" : 336. (u.ualign.type == A_NEUTRAL) ? " Neutral" : " Lawful"); 337. #ifdef SCORE_ON_BOTL 338. if (flags.showscore) { 339. int deepest = deepest_lev_reached(FALSE); 340. long ugold = u.ugold + hidden_gold(); 341. 342. if ((ugold -= u.ugold0) < 0L) ugold = 0L; 343. Sprintf(nb = eos(nb), " S:%ld", 344. ugold + u.urexp + (long)(50 * (deepest - 1)) 345. + (long)(deepest > 30 ? 10000 : 346. deepest > 20 ? 1000*(deepest - 20) : 0)); 347. } 348. #endif 349. curs(WIN_STATUS, 1, 0); 350. putstr(WIN_STATUS, 0, newbot1); 351. } 352. 353. static void 354. bot2() 355. { 356. char newbot2[MAXCO]; 357. register char *nb; 358. int hp, hpmax; 359. int cap = near_capacity(); 360. 361. #ifdef POLYSELF 362. hp = u.mtimedone ? u.mh : u.uhp; 363. hpmax = u.mtimedone ? u.mhmax : u.uhpmax; 364. #else 365. hp = u.uhp; 366. hpmax = u.uhpmax; 367. #endif 368. if(hp < 0) hp = 0; 369. /* TODO: Add in dungeon name */ 370. #ifdef MULDGN 371. if(Is_knox(&u.uz)) Sprintf(newbot2, "%s ", dungeons[u.uz.dnum].dname); 372. else 373. if(In_quest(&u.uz)) Sprintf(newbot2, "Home %d ", dunlev(&u.uz)); 374. else 375. #endif 376. if(In_endgame(&u.uz)) 377. Sprintf(newbot2, 378. Is_astralevel(&u.uz) ? "Astral Plane " : "End Game "); 379. else 380. Sprintf(newbot2, "Dlvl:%-2d ", depth(&u.uz)); 381. Sprintf(nb = eos(newbot2), 382. "%c:%-2ld HP:%d(%d) Pw:%d(%d) AC:%-2d", oc_syms[GOLD_CLASS], 383. u.ugold, hp, hpmax, u.uen, u.uenmax, u.uac); 384. #ifdef POLYSELF 385. if (u.mtimedone) 386. Sprintf(nb = eos(nb), " HD:%d", mons[u.umonnum].mlevel); 387. else 388. #endif 389. #ifdef EXP_ON_BOTL 390. if(flags.showexp) 391. Sprintf(nb = eos(nb), " Xp:%u/%-1ld", u.ulevel,u.uexp); 392. else 393. #endif 394. Sprintf(nb = eos(nb), " Exp:%u", u.ulevel); 395. if(flags.time) 396. Sprintf(nb = eos(nb), " T:%ld", moves); 397. if(strcmp(hu_stat[u.uhs], " ")) { 398. Sprintf(nb = eos(nb), " "); 399. Strcat(newbot2, hu_stat[u.uhs]); 400. } 401. if(Confusion) Sprintf(nb = eos(nb), " Conf"); 402. if(Sick) Sprintf(nb = eos(nb), " Sick"); 403. if(Blind) Sprintf(nb = eos(nb), " Blind"); 404. if(Stunned) Sprintf(nb = eos(nb), " Stun"); 405. if(Hallucination) Sprintf(nb = eos(nb), " Hallu"); 406. if(cap > UNENCUMBERED) 407. Sprintf(nb = eos(nb), " %s", enc_stat[cap]); 408. curs(WIN_STATUS, 1, 1); 409. putstr(WIN_STATUS, 0, newbot2); 410. } 411. 412. void 413. bot() 414. { 415. bot1(); 416. bot2(); 417. flags.botl = flags.botlx = 0; 418. } 419. 420. #endif /* OVL0 */ 421. 422. /*botl.c*/