Source:NetHack 3.6.5/src/quest.c
Jump to navigation
Jump to search
Below is the full text to quest.c from the source code of NetHack 3.6.5. To link to a particular line, write [[Source:NetHack 3.6.5/src/quest.c#line12]], for example.
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. /* NetHack 3.6 quest.c $NHDT-Date: 1505170343 2017/09/11 22:52:23 $ $NHDT-Branch: NetHack-3.6.0 $:$NHDT-Revision: 1.21 $ */ 2. /* Copyright 1991, M. Stephenson */ 3. /* NetHack may be freely redistributed. See license for details. */ 4. 5. #include "hack.h" 6. 7. /* quest dungeon branch routines. */ 8. 9. #include "quest.h" 10. #include "qtext.h" 11. 12. #define Not_firsttime (on_level(&u.uz0, &u.uz)) 13. #define Qstat(x) (quest_status.x) 14. 15. STATIC_DCL void NDECL(on_start); 16. STATIC_DCL void NDECL(on_locate); 17. STATIC_DCL void NDECL(on_goal); 18. STATIC_DCL boolean NDECL(not_capable); 19. STATIC_DCL int FDECL(is_pure, (BOOLEAN_P)); 20. STATIC_DCL void FDECL(expulsion, (BOOLEAN_P)); 21. STATIC_DCL void NDECL(chat_with_leader); 22. STATIC_DCL void NDECL(chat_with_nemesis); 23. STATIC_DCL void NDECL(chat_with_guardian); 24. STATIC_DCL void FDECL(prisoner_speaks, (struct monst *)); 25. 26. STATIC_OVL void 27. on_start() 28. { 29. if (!Qstat(first_start)) { 30. qt_pager(QT_FIRSTTIME); 31. Qstat(first_start) = TRUE; 32. } else if ((u.uz0.dnum != u.uz.dnum) || (u.uz0.dlevel < u.uz.dlevel)) { 33. if (Qstat(not_ready) <= 2) 34. qt_pager(QT_NEXTTIME); 35. else 36. qt_pager(QT_OTHERTIME); 37. } 38. } 39. 40. STATIC_OVL void 41. on_locate() 42. { 43. /* the locate messages are phrased in a manner such that they only 44. make sense when arriving on the level from above */ 45. boolean from_above = (u.uz0.dlevel < u.uz.dlevel); 46. 47. if (Qstat(killed_nemesis)) { 48. return; 49. } else if (!Qstat(first_locate)) { 50. if (from_above) 51. qt_pager(QT_FIRSTLOCATE); 52. /* if we've arrived from below this will be a lie, but there won't 53. be any point in delivering the message upon a return visit from 54. above later since the level has now been seen */ 55. Qstat(first_locate) = TRUE; 56. } else { 57. if (from_above) 58. qt_pager(QT_NEXTLOCATE); 59. } 60. } 61. 62. STATIC_OVL void 63. on_goal() 64. { 65. if (Qstat(killed_nemesis)) { 66. return; 67. } else if (!Qstat(made_goal)) { 68. qt_pager(QT_FIRSTGOAL); 69. Qstat(made_goal) = 1; 70. } else { 71. /* 72. * Some QT_NEXTGOAL messages reference the quest artifact; 73. * find out if it is still present. If not, request an 74. * alternate message (qt_pager() will revert to delivery 75. * of QT_NEXTGOAL if current role doesn't have QT_ALTGOAL). 76. * Note: if hero is already carrying it, it is treated as 77. * being absent from the level for quest message purposes. 78. */ 79. unsigned whichobjchains = ((1 << OBJ_FLOOR) 80. | (1 << OBJ_MINVENT) 81. | (1 << OBJ_BURIED)); 82. struct obj *qarti = find_quest_artifact(whichobjchains); 83. 84. qt_pager(qarti ? QT_NEXTGOAL : QT_ALTGOAL); 85. if (Qstat(made_goal) < 7) 86. Qstat(made_goal)++; 87. } 88. } 89. 90. void 91. onquest() 92. { 93. if (u.uevent.qcompleted || Not_firsttime) 94. return; 95. if (!Is_special(&u.uz)) 96. return; 97. 98. if (Is_qstart(&u.uz)) 99. on_start(); 100. else if (Is_qlocate(&u.uz)) 101. on_locate(); 102. else if (Is_nemesis(&u.uz)) 103. on_goal(); 104. return; 105. } 106. 107. void 108. nemdead() 109. { 110. if (!Qstat(killed_nemesis)) { 111. Qstat(killed_nemesis) = TRUE; 112. qt_pager(QT_KILLEDNEM); 113. } 114. } 115. 116. void 117. artitouch(obj) 118. struct obj *obj; 119. { 120. if (!Qstat(touched_artifact)) { 121. /* in case we haven't seen the item yet (ie, currently blinded), 122. this quest message describes it by name so mark it as seen */ 123. obj->dknown = 1; 124. /* only give this message once */ 125. Qstat(touched_artifact) = TRUE; 126. qt_pager(QT_GOTIT); 127. exercise(A_WIS, TRUE); 128. } 129. } 130. 131. /* external hook for do.c (level change check) */ 132. boolean 133. ok_to_quest() 134. { 135. return (boolean) ((Qstat(got_quest) || Qstat(got_thanks)) 136. && is_pure(FALSE) > 0); 137. } 138. 139. STATIC_OVL boolean 140. not_capable() 141. { 142. return (boolean) (u.ulevel < MIN_QUEST_LEVEL); 143. } 144. 145. STATIC_OVL int 146. is_pure(talk) 147. boolean talk; 148. { 149. int purity; 150. aligntyp original_alignment = u.ualignbase[A_ORIGINAL]; 151. 152. if (wizard && talk) { 153. if (u.ualign.type != original_alignment) { 154. You("are currently %s instead of %s.", align_str(u.ualign.type), 155. align_str(original_alignment)); 156. } else if (u.ualignbase[A_CURRENT] != original_alignment) { 157. You("have converted."); 158. } else if (u.ualign.record < MIN_QUEST_ALIGN) { 159. You("are currently %d and require %d.", u.ualign.record, 160. MIN_QUEST_ALIGN); 161. if (yn_function("adjust?", (char *) 0, 'y') == 'y') 162. u.ualign.record = MIN_QUEST_ALIGN; 163. } 164. } 165. purity = (u.ualign.record >= MIN_QUEST_ALIGN 166. && u.ualign.type == original_alignment 167. && u.ualignbase[A_CURRENT] == original_alignment) 168. ? 1 169. : (u.ualignbase[A_CURRENT] != original_alignment) ? -1 : 0; 170. return purity; 171. } 172. 173. /* 174. * Expel the player to the stairs on the parent of the quest dungeon. 175. * 176. * This assumes that the hero is currently _in_ the quest dungeon and that 177. * there is a single branch to and from it. 178. */ 179. STATIC_OVL void 180. expulsion(seal) 181. boolean seal; 182. { 183. branch *br; 184. d_level *dest; 185. struct trap *t; 186. int portal_flag; 187. 188. br = dungeon_branch("The Quest"); 189. dest = (br->end1.dnum == u.uz.dnum) ? &br->end2 : &br->end1; 190. portal_flag = u.uevent.qexpelled ? 0 /* returned via artifact? */ 191. : !seal ? 1 : -1; 192. schedule_goto(dest, FALSE, FALSE, portal_flag, (char *) 0, (char *) 0); 193. if (seal) { /* remove the portal to the quest - sealing it off */ 194. int reexpelled = u.uevent.qexpelled; 195. 196. u.uevent.qexpelled = 1; 197. remdun_mapseen(quest_dnum); 198. /* Delete the near portal now; the far (main dungeon side) 199. portal will be deleted as part of arrival on that level. 200. If monster movement is in progress, any who haven't moved 201. yet will now miss out on a chance to wander through it... */ 202. for (t = ftrap; t; t = t->ntrap) 203. if (t->ttyp == MAGIC_PORTAL) 204. break; 205. if (t) 206. deltrap(t); /* (display might be briefly out of sync) */ 207. else if (!reexpelled) 208. impossible("quest portal already gone?"); 209. } 210. } 211. 212. /* Either you've returned to quest leader while carrying the quest 213. artifact or you've just thrown it to/at him or her. If quest 214. completion text hasn't been given yet, give it now. Otherwise 215. give another message about the character keeping the artifact 216. and using the magic portal to return to the dungeon. */ 217. void 218. finish_quest(obj) 219. struct obj *obj; /* quest artifact; possibly null if carrying Amulet */ 220. { 221. struct obj *otmp; 222. 223. if (u.uhave.amulet) { /* unlikely but not impossible */ 224. qt_pager(QT_HASAMULET); 225. /* leader IDs the real amulet but ignores any fakes */ 226. if ((otmp = carrying(AMULET_OF_YENDOR)) != 0) 227. fully_identify_obj(otmp); 228. } else { 229. qt_pager(!Qstat(got_thanks) ? QT_OFFEREDIT : QT_OFFEREDIT2); 230. /* should have obtained bell during quest; 231. if not, suggest returning for it now */ 232. if ((otmp = carrying(BELL_OF_OPENING)) == 0) 233. com_pager(5); 234. } 235. Qstat(got_thanks) = TRUE; 236. 237. if (obj) { 238. u.uevent.qcompleted = 1; /* you did it! */ 239. /* behave as if leader imparts sufficient info about the 240. quest artifact */ 241. fully_identify_obj(obj); 242. update_inventory(); 243. } 244. } 245. 246. STATIC_OVL void 247. chat_with_leader() 248. { 249. /* Rule 0: Cheater checks. */ 250. if (u.uhave.questart && !Qstat(met_nemesis)) 251. Qstat(cheater) = TRUE; 252. 253. /* It is possible for you to get the amulet without completing 254. * the quest. If so, try to induce the player to quest. 255. */ 256. if (Qstat(got_thanks)) { 257. /* Rule 1: You've gone back with/without the amulet. */ 258. if (u.uhave.amulet) 259. finish_quest((struct obj *) 0); 260. 261. /* Rule 2: You've gone back before going for the amulet. */ 262. else 263. qt_pager(QT_POSTHANKS); 264. 265. /* Rule 3: You've got the artifact and are back to return it. */ 266. } else if (u.uhave.questart) { 267. struct obj *otmp; 268. 269. for (otmp = invent; otmp; otmp = otmp->nobj) 270. if (is_quest_artifact(otmp)) 271. break; 272. 273. finish_quest(otmp); 274. 275. /* Rule 4: You haven't got the artifact yet. */ 276. } else if (Qstat(got_quest)) { 277. qt_pager(rn1(10, QT_ENCOURAGE)); 278. 279. /* Rule 5: You aren't yet acceptable - or are you? */ 280. } else { 281. if (!Qstat(met_leader)) { 282. qt_pager(QT_FIRSTLEADER); 283. Qstat(met_leader) = TRUE; 284. Qstat(not_ready) = 0; 285. } else 286. qt_pager(QT_NEXTLEADER); 287. 288. /* the quest leader might have passed through the portal into 289. the regular dungeon; none of the remaining make sense there */ 290. if (!on_level(&u.uz, &qstart_level)) 291. return; 292. 293. if (not_capable()) { 294. qt_pager(QT_BADLEVEL); 295. exercise(A_WIS, TRUE); 296. expulsion(FALSE); 297. } else if (is_pure(TRUE) < 0) { 298. com_pager(QT_BANISHED); 299. expulsion(TRUE); 300. } else if (is_pure(TRUE) == 0) { 301. qt_pager(QT_BADALIGN); 302. if (Qstat(not_ready) == MAX_QUEST_TRIES) { 303. qt_pager(QT_LASTLEADER); 304. expulsion(TRUE); 305. } else { 306. Qstat(not_ready)++; 307. exercise(A_WIS, TRUE); 308. expulsion(FALSE); 309. } 310. } else { /* You are worthy! */ 311. qt_pager(QT_ASSIGNQUEST); 312. exercise(A_WIS, TRUE); 313. Qstat(got_quest) = TRUE; 314. } 315. } 316. } 317. 318. void 319. leader_speaks(mtmp) 320. struct monst *mtmp; 321. { 322. /* maybe you attacked leader? */ 323. if (!mtmp->mpeaceful) { 324. Qstat(pissed_off) = TRUE; 325. mtmp->mstrategy &= ~STRAT_WAITMASK; /* end the inaction */ 326. } 327. /* the quest leader might have passed through the portal into the 328. regular dungeon; if so, mustn't perform "backwards expulsion" */ 329. if (!on_level(&u.uz, &qstart_level)) 330. return; 331. 332. if (Qstat(pissed_off)) { 333. qt_pager(QT_LASTLEADER); 334. expulsion(TRUE); 335. } else 336. chat_with_leader(); 337. } 338. 339. STATIC_OVL void 340. chat_with_nemesis() 341. { 342. /* The nemesis will do most of the talking, but... */ 343. qt_pager(rn1(10, QT_DISCOURAGE)); 344. if (!Qstat(met_nemesis)) 345. Qstat(met_nemesis++); 346. } 347. 348. void 349. nemesis_speaks() 350. { 351. if (!Qstat(in_battle)) { 352. if (u.uhave.questart) 353. qt_pager(QT_NEMWANTSIT); 354. else if (Qstat(made_goal) == 1 || !Qstat(met_nemesis)) 355. qt_pager(QT_FIRSTNEMESIS); 356. else if (Qstat(made_goal) < 4) 357. qt_pager(QT_NEXTNEMESIS); 358. else if (Qstat(made_goal) < 7) 359. qt_pager(QT_OTHERNEMESIS); 360. else if (!rn2(5)) 361. qt_pager(rn1(10, QT_DISCOURAGE)); 362. if (Qstat(made_goal) < 7) 363. Qstat(made_goal)++; 364. Qstat(met_nemesis) = TRUE; 365. } else /* he will spit out random maledictions */ 366. if (!rn2(5)) 367. qt_pager(rn1(10, QT_DISCOURAGE)); 368. } 369. 370. STATIC_OVL void 371. chat_with_guardian() 372. { 373. /* These guys/gals really don't have much to say... */ 374. if (u.uhave.questart && Qstat(killed_nemesis)) 375. qt_pager(rn1(5, QT_GUARDTALK2)); 376. else 377. qt_pager(rn1(5, QT_GUARDTALK)); 378. } 379. 380. STATIC_OVL void 381. prisoner_speaks(mtmp) 382. struct monst *mtmp; 383. { 384. if (mtmp->data == &mons[PM_PRISONER] 385. && (mtmp->mstrategy & STRAT_WAITMASK)) { 386. /* Awaken the prisoner */ 387. if (canseemon(mtmp)) 388. pline("%s speaks:", Monnam(mtmp)); 389. verbalize("I'm finally free!"); 390. mtmp->mstrategy &= ~STRAT_WAITMASK; 391. mtmp->mpeaceful = 1; 392. 393. /* Your god is happy... */ 394. adjalign(3); 395. 396. /* ...But the guards are not */ 397. (void) angry_guards(FALSE); 398. } 399. return; 400. } 401. 402. void 403. quest_chat(mtmp) 404. register struct monst *mtmp; 405. { 406. if (mtmp->m_id == Qstat(leader_m_id)) { 407. chat_with_leader(); 408. return; 409. } 410. switch (mtmp->data->msound) { 411. case MS_NEMESIS: 412. chat_with_nemesis(); 413. break; 414. case MS_GUARDIAN: 415. chat_with_guardian(); 416. break; 417. default: 418. impossible("quest_chat: Unknown quest character %s.", mon_nam(mtmp)); 419. } 420. } 421. 422. void 423. quest_talk(mtmp) 424. struct monst *mtmp; 425. { 426. if (mtmp->m_id == Qstat(leader_m_id)) { 427. leader_speaks(mtmp); 428. return; 429. } 430. switch (mtmp->data->msound) { 431. case MS_NEMESIS: 432. nemesis_speaks(); 433. break; 434. case MS_DJINNI: 435. prisoner_speaks(mtmp); 436. break; 437. default: 438. break; 439. } 440. } 441. 442. void 443. quest_stat_check(mtmp) 444. struct monst *mtmp; 445. { 446. if (mtmp->data->msound == MS_NEMESIS) 447. Qstat(in_battle) = (mtmp->mcanmove && !mtmp->msleeping 448. && monnear(mtmp, u.ux, u.uy)); 449. } 450. 451. /*quest.c*/