Source:NetHack 5.0.0/src/quest.c
Jump to navigation
Jump to search
Below is the full text to quest.c from the source code of NetHack 5.0.0. To link to a particular line, write [[Source:NetHack 5.0.0/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 5.0 quest.c $NHDT-Date: 1774269965 2026/03/23 04:46:05 $ $NHDT-Branch: NetHack-3.7 $:$NHDT-Revision: 1.46 $ */ 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. 11. #define Not_firsttime (on_level(&u.uz0, &u.uz)) 12. #define Qstat(x) (svq.quest_status.x) 13. 14. staticfn void on_start(void); 15. staticfn void on_locate(void); 16. staticfn void on_goal(void); 17. staticfn boolean not_capable(void); 18. staticfn int is_pure(boolean); 19. staticfn void expulsion(boolean); 20. staticfn void chat_with_leader(struct monst *); 21. staticfn void chat_with_nemesis(void); 22. staticfn void chat_with_guardian(void); 23. staticfn void prisoner_speaks(struct monst *); 24. 25. staticfn void 26. on_start(void) 27. { 28. if (!Qstat(first_start)) { 29. qt_pager("firsttime"); 30. Qstat(first_start) = TRUE; 31. } else if ((u.uz0.dnum != u.uz.dnum) || (u.uz0.dlevel < u.uz.dlevel)) { 32. if (Qstat(not_ready) <= 2) 33. qt_pager("nexttime"); 34. else 35. qt_pager("othertime"); 36. } 37. } 38. 39. staticfn void 40. on_locate(void) 41. { 42. /* the locate messages are phrased in a manner such that they only 43. make sense when arriving on the level from above */ 44. boolean from_above = (u.uz0.dlevel < u.uz.dlevel); 45. 46. if (Qstat(killed_nemesis)) { 47. return; 48. } else if (!Qstat(first_locate)) { 49. if (from_above) 50. qt_pager("locate_first"); 51. /* if we've arrived from below this will be a lie, but there won't 52. be any point in delivering the message upon a return visit from 53. above later since the level has now been seen */ 54. Qstat(first_locate) = TRUE; 55. } else { 56. if (from_above) 57. qt_pager("locate_next"); 58. } 59. } 60. 61. staticfn void 62. on_goal(void) 63. { 64. if (Qstat(killed_nemesis)) { 65. return; 66. } else if (!Qstat(made_goal)) { 67. qt_pager("goal_first"); 68. Qstat(made_goal) = 1; 69. } else { 70. /* 71. * Some QT_NEXTGOAL messages reference the quest artifact; 72. * find out if it is still present. If not, request an 73. * alternate message (qt_pager() will revert to delivery 74. * of QT_NEXTGOAL if current role doesn't have QT_ALTGOAL). 75. * Note: if hero is already carrying it, it is treated as 76. * being absent from the level for quest message purposes. 77. */ 78. unsigned whichobjchains = ((1 << OBJ_FLOOR) 79. | (1 << OBJ_MINVENT) 80. | (1 << OBJ_BURIED)); 81. struct obj *qarti = find_quest_artifact(whichobjchains); 82. 83. qt_pager(qarti ? "goal_next" : "goal_alt"); 84. if (Qstat(made_goal) < 7) 85. Qstat(made_goal)++; 86. } 87. } 88. 89. void 90. onquest(void) 91. { 92. if (u.uevent.qcompleted || Not_firsttime) 93. return; 94. if (!Is_special(&u.uz)) 95. return; 96. 97. if (Is_qstart(&u.uz)) 98. on_start(); 99. else if (Is_qlocate(&u.uz)) 100. on_locate(); 101. else if (Is_nemesis(&u.uz)) 102. on_goal(); 103. return; 104. } 105. 106. void 107. nemdead(void) 108. { 109. if (!Qstat(killed_nemesis)) { 110. Qstat(killed_nemesis) = TRUE; 111. qt_pager("killed_nemesis"); 112. } 113. } 114. 115. void 116. leaddead(void) 117. { 118. if (!Qstat(killed_leader)) { 119. Qstat(killed_leader) = TRUE; 120. /* TODO: qt_pager("killed_leader"); ? */ 121. } 122. } 123. 124. void 125. artitouch(struct obj *obj) 126. { 127. if (!Qstat(touched_artifact)) { 128. /* in case we haven't seen the item yet (ie, currently blinded), 129. this quest message describes it by name so mark it as seen */ 130. observe_object(obj); 131. /* only give this message once */ 132. Qstat(touched_artifact) = TRUE; 133. qt_pager("gotit"); 134. exercise(A_WIS, TRUE); 135. } 136. } 137. 138. /* external hook for do.c (level change check) */ 139. boolean 140. ok_to_quest(void) 141. { 142. return (boolean) (((Qstat(got_quest) || Qstat(got_thanks)) 143. && is_pure(FALSE) > 0) || Qstat(killed_leader)); 144. } 145. 146. staticfn boolean 147. not_capable(void) 148. { 149. return (boolean) (u.ulevel < MIN_QUEST_LEVEL); 150. } 151. 152. staticfn int 153. is_pure(boolean talk) 154. { 155. int purity; 156. aligntyp original_alignment = u.ualignbase[A_ORIGINAL]; 157. 158. if (wizard && talk) { 159. if (u.ualign.type != original_alignment) { 160. You("are currently %s instead of %s.", align_str(u.ualign.type), 161. align_str(original_alignment)); 162. } else if (u.ualignbase[A_CURRENT] != original_alignment) { 163. You("have converted."); 164. } else if (u.ualign.record < MIN_QUEST_ALIGN) { 165. You("are currently %d and require %d.", u.ualign.record, 166. MIN_QUEST_ALIGN); 167. if (yn_function("adjust?", (char *) 0, 'y', TRUE) == 'y') 168. u.ualign.record = MIN_QUEST_ALIGN; 169. } 170. } 171. purity = (u.ualign.record >= MIN_QUEST_ALIGN 172. && u.ualign.type == original_alignment 173. && u.ualignbase[A_CURRENT] == original_alignment) 174. ? 1 175. : (u.ualignbase[A_CURRENT] != original_alignment) ? -1 : 0; 176. return purity; 177. } 178. 179. /* 180. * Expel the player to the stairs on the parent of the quest dungeon. 181. * 182. * This assumes that the hero is currently _in_ the quest dungeon and that 183. * there is a single branch to and from it. 184. */ 185. staticfn void 186. expulsion(boolean seal) 187. { 188. branch *br; 189. d_level *dest; 190. struct trap *t; 191. int portal_flag = u.uevent.qexpelled ? UTOTYPE_NONE : UTOTYPE_PORTAL; 192. 193. br = dungeon_branch("The Quest"); 194. dest = (br->end1.dnum == u.uz.dnum) ? &br->end2 : &br->end1; 195. if (seal) 196. portal_flag |= UTOTYPE_RMPORTAL; 197. nomul(0); /* stop running */ 198. schedule_goto(dest, portal_flag, (char *) 0, (char *) 0); 199. if (seal) { /* remove the portal to the quest - sealing it off */ 200. int reexpelled = u.uevent.qexpelled; 201. 202. u.uevent.qexpelled = 1; 203. remdun_mapseen(quest_dnum); 204. /* Delete the near portal now; the far (main dungeon side) 205. portal will be deleted as part of arrival on that level. 206. If monster movement is in progress, any who haven't moved 207. yet will now miss out on a chance to wander through it... */ 208. for (t = gf.ftrap; t; t = t->ntrap) 209. if (t->ttyp == MAGIC_PORTAL) 210. break; 211. if (t) 212. deltrap(t); /* (display might be briefly out of sync) */ 213. else if (!reexpelled) 214. impossible("quest portal already gone?"); 215. } 216. } 217. 218. /* Either you've returned to quest leader while carrying the quest 219. artifact or you've just thrown it to/at him or her. If quest 220. completion text hasn't been given yet, give it now. Otherwise 221. give another message about the character keeping the artifact 222. and using the magic portal to return to the dungeon. Also called 223. if hero throws or kicks an invocation item (probably the Bell) 224. at the leader. */ 225. void 226. finish_quest(struct obj *obj) /* quest artifact or thrown unique item or faux 227. * AoY; possibly null if carrying the Amulet */ 228. { 229. struct obj *otmp; 230. 231. if (obj && !is_quest_artifact(obj)) { 232. /* tossed an invocation item (or [fake] AoY) at the quest leader */ 233. if (Deaf) 234. return; /* optional (unlike quest completion) so skip if deaf */ 235. /* do ID first so that the message identifying the item will refer to 236. it by name (and so justify the ID we already gave...) */ 237. fully_identify_obj(obj); 238. /* update_inventory() is not necessary or helpful here because item 239. was thrown, so isn't currently in inventory anyway */ 240. if (obj->otyp == AMULET_OF_YENDOR) { 241. qt_pager("hasamulet"); 242. } else if (obj->otyp == FAKE_AMULET_OF_YENDOR) { 243. verbalize( 244. "Sorry to say, this is a mere imitation of the true Amulet of Yendor."); 245. } else { 246. verbalize("Ah, I see you've found %s.", the(xname(obj))); 247. } 248. return; 249. } 250. 251. if (u.uhave.amulet) { 252. /* has the amulet in inventory -- most likely the player has already 253. completed the quest and stopped in on her way back up, but it's not 254. impossible to have gotten the amulet before formally presenting the 255. quest artifact to the leader. */ 256. qt_pager("hasamulet"); 257. /* leader IDs the real amulet but ignores any fakes */ 258. if ((otmp = carrying(AMULET_OF_YENDOR)) != (struct obj *) 0) { 259. fully_identify_obj(otmp); 260. update_inventory(); 261. } 262. } else { 263. /* normal quest completion; threw artifact or walked up carrying it */ 264. qt_pager(!Qstat(got_thanks) ? "offeredit" : "offeredit2"); 265. /* should have obtained bell during quest; 266. if not, suggest returning for it now */ 267. if ((otmp = carrying(BELL_OF_OPENING)) == 0) 268. com_pager("quest_complete_no_bell"); 269. } 270. Qstat(got_thanks) = TRUE; 271. 272. if (obj) { 273. u.uevent.qcompleted = 1; /* you did it! */ 274. /* behave as if leader imparts sufficient info about the 275. quest artifact */ 276. fully_identify_obj(obj); 277. update_inventory(); 278. } 279. } 280. 281. staticfn void 282. chat_with_leader(struct monst *mtmp) 283. { 284. if (!mtmp->mpeaceful || Qstat(pissed_off)) 285. return; 286. 287. /* Rule 0: Cheater checks. */ 288. if (u.uhave.questart && !Qstat(met_nemesis)) 289. Qstat(cheater) = TRUE; 290. 291. /* It is possible for you to get the amulet without completing 292. * the quest. If so, try to induce the player to quest. 293. */ 294. if (Qstat(got_thanks)) { 295. /* Rule 1: You've gone back with/without the amulet. */ 296. if (u.uhave.amulet) 297. finish_quest((struct obj *) 0); 298. 299. /* Rule 2: You've gone back before going for the amulet. */ 300. else 301. qt_pager("posthanks"); 302. 303. /* Rule 3: You've got the artifact and are back to return it. */ 304. } else if (u.uhave.questart) { 305. struct obj *otmp; 306. 307. for (otmp = gi.invent; otmp; otmp = otmp->nobj) 308. if (is_quest_artifact(otmp)) 309. break; 310. 311. finish_quest(otmp); 312. 313. /* Rule 4: You haven't got the artifact yet. */ 314. } else if (Qstat(got_quest)) { 315. qt_pager("encourage"); 316. 317. /* Rule 5: You aren't yet acceptable - or are you? */ 318. } else { 319. int purity = 0; 320. 321. if (!Qstat(met_leader)) { 322. qt_pager("leader_first"); 323. Qstat(met_leader) = TRUE; 324. Qstat(not_ready) = 0; 325. } else 326. qt_pager("leader_next"); 327. 328. /* the quest leader might have passed through the portal into 329. the regular dungeon; none of the remaining make sense there */ 330. if (!on_level(&u.uz, &qstart_level)) 331. return; 332. 333. if (not_capable()) { 334. qt_pager("badlevel"); 335. exercise(A_WIS, TRUE); 336. expulsion(FALSE); 337. } else if ((purity = is_pure(TRUE)) < 0) { 338. if (!Qstat(pissed_off)) { 339. com_pager("banished"); 340. Qstat(pissed_off) = TRUE; 341. expulsion(FALSE); 342. 343. /* being expelled is hardly an achievement but none of the 344. other livelog classifications fit */ 345. livelog_printf(LL_ACHIEVE, 346. "%s has expelled you from the quest", 347. noit_mon_nam(mtmp)); 348. } 349. } else if (purity == 0) { 350. qt_pager("badalign"); 351. Qstat(not_ready) = 1; 352. exercise(A_WIS, TRUE); 353. expulsion(FALSE); 354. } else { /* You are worthy! */ 355. qt_pager("assignquest"); 356. exercise(A_WIS, TRUE); 357. Qstat(got_quest) = TRUE; 358. 359. /* phrasing is a bit clumsy but allows #chronicle to provide a 360. clue to players who are reaching the quest for first time; 361. matters most for Home 1 that has stairs down which aren't 362. easily found */ 363. livelog_printf(LL_ACHIEVE, 364. "%s has granted access to proceed deeper into the quest", 365. noit_mon_nam(mtmp)); 366. } 367. } 368. } 369. 370. void 371. leader_speaks(struct monst *mtmp) 372. { 373. /* maybe you attacked leader? */ 374. if (!mtmp->mpeaceful) { 375. if (!Qstat(pissed_off)) { 376. /* again, don't end it permanently if the leader gets angry 377. * since you're going to have to kill him to go questing... :) 378. * ...but do only show this crap once. */ 379. qt_pager("leader_last"); 380. } 381. Qstat(pissed_off) = TRUE; 382. mtmp->mstrategy &= ~STRAT_WAITMASK; /* end the inaction */ 383. } 384. /* the quest leader might have passed through the portal into the 385. regular dungeon; if so, mustn't perform "backwards expulsion" */ 386. if (!on_level(&u.uz, &qstart_level)) 387. return; 388. 389. if (!Qstat(pissed_off)) 390. chat_with_leader(mtmp); 391. } 392. 393. staticfn void 394. chat_with_nemesis(void) 395. { 396. /* The nemesis will do most of the talking, but... */ 397. qt_pager("discourage"); 398. if (!Qstat(met_nemesis)) 399. Qstat(met_nemesis++); 400. } 401. 402. void 403. nemesis_speaks(void) 404. { 405. if (!Qstat(in_battle)) { 406. if (u.uhave.questart) 407. qt_pager("nemesis_wantsit"); 408. else if (Qstat(made_goal) == 1 || !Qstat(met_nemesis)) 409. qt_pager("nemesis_first"); 410. else if (Qstat(made_goal) < 4) 411. qt_pager("nemesis_next"); 412. else if (Qstat(made_goal) < 7) 413. qt_pager("nemesis_other"); 414. else if (!rn2(5)) 415. qt_pager("discourage"); 416. if (Qstat(made_goal) < 7) 417. Qstat(made_goal)++; 418. Qstat(met_nemesis) = TRUE; 419. } else /* he will spit out random maledictions */ 420. if (!rn2(5)) 421. qt_pager("discourage"); 422. } 423. 424. /* create cloud of stinking gas around dying nemesis */ 425. void 426. nemesis_stinks(coordxy mx, coordxy my) 427. { 428. boolean save_mon_moving = svc.context.mon_moving; 429. 430. /* 431. * Some nemeses (determined by caller) release a cloud of noxious 432. * gas when they die. Don't make the hero be responsible for such 433. * a cloud even if hero has just killed nemesis. 434. */ 435. svc.context.mon_moving = TRUE; 436. create_gas_cloud(mx, my, 5, 8); 437. svc.context.mon_moving = save_mon_moving; 438. } 439. 440. staticfn void 441. chat_with_guardian(void) 442. { 443. /* These guys/gals really don't have much to say... */ 444. if (u.uhave.questart && Qstat(killed_nemesis)) 445. qt_pager("guardtalk_after"); 446. else 447. qt_pager("guardtalk_before"); 448. } 449. 450. staticfn void 451. prisoner_speaks(struct monst *mtmp) 452. { 453. if (mtmp->data == &mons[PM_PRISONER] 454. && (mtmp->mstrategy & STRAT_WAITMASK)) { 455. /* Awaken the prisoner */ 456. if (canseemon(mtmp)) 457. pline("%s speaks:", Monnam(mtmp)); 458. SetVoice(mtmp, 0, 80, 0); 459. verbalize("I'm finally free!"); 460. mtmp->mstrategy &= ~STRAT_WAITMASK; 461. mtmp->mpeaceful = 1; 462. 463. /* Your god is happy... */ 464. adjalign(3); 465. 466. /* ...But the guards are not */ 467. (void) angry_guards(FALSE); 468. } 469. return; 470. } 471. 472. void 473. quest_chat(struct monst *mtmp) 474. { 475. if (mtmp->m_id == Qstat(leader_m_id)) { 476. chat_with_leader(mtmp); 477. /* leader might have become pissed during the chat */ 478. if (Qstat(pissed_off)) 479. setmangry(mtmp, FALSE); 480. return; 481. } 482. switch (mtmp->data->msound) { 483. case MS_NEMESIS: 484. chat_with_nemesis(); 485. break; 486. case MS_GUARDIAN: 487. chat_with_guardian(); 488. break; 489. default: 490. impossible("quest_chat: Unknown quest character %s.", mon_nam(mtmp)); 491. } 492. } 493. 494. void 495. quest_talk(struct monst *mtmp) 496. { 497. if (mtmp->m_id == Qstat(leader_m_id)) { 498. leader_speaks(mtmp); 499. return; 500. } 501. switch (mtmp->data->msound) { 502. case MS_NEMESIS: 503. nemesis_speaks(); 504. break; 505. case MS_DJINNI: 506. prisoner_speaks(mtmp); 507. break; 508. default: 509. break; 510. } 511. } 512. 513. void 514. quest_stat_check(struct monst *mtmp) 515. { 516. if (mtmp->data->msound == MS_NEMESIS) 517. Qstat(in_battle) = (!helpless(mtmp) && monnear(mtmp, u.ux, u.uy)); 518. } 519. 520. #undef Not_firsttime 521. #undef Qstat 522. 523. /*quest.c*/