1 /* NetHack 3.6 quest.c $NHDT-Date: 1446191878 2015/10/30 07:57:58 $ $NHDT-Branch: master $:$NHDT-Revision: 1.20 $ */
2 /* Copyright 1991, M. Stephenson */
3 /* NetHack may be freely redistributed. See license for details. */
7 /* quest dungeon branch routines. */
12 #define Not_firsttime (on_level(&u.uz0, &u.uz))
13 #define Qstat(x) (quest_status.x)
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
*));
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
);
36 qt_pager(QT_OTHERTIME
);
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
);
47 if (Qstat(killed_nemesis
)) {
49 } else if (!Qstat(first_locate
)) {
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
;
58 qt_pager(QT_NEXTLOCATE
);
65 if (Qstat(killed_nemesis
)) {
67 } else if (!Qstat(made_goal
)) {
68 qt_pager(QT_FIRSTGOAL
);
71 qt_pager(QT_NEXTGOAL
);
72 if (Qstat(made_goal
) < 7)
80 if (u
.uevent
.qcompleted
|| Not_firsttime
)
82 if (!Is_special(&u
.uz
))
87 else if (Is_qlocate(&u
.uz
))
89 else if (Is_nemesis(&u
.uz
))
97 if (!Qstat(killed_nemesis
)) {
98 Qstat(killed_nemesis
) = TRUE
;
99 qt_pager(QT_KILLEDNEM
);
107 if (!Qstat(touched_artifact
)) {
108 /* in case we haven't seen the item yet (ie, currently blinded),
109 this quest message describes it by name so mark it as seen */
111 /* only give this message once */
112 Qstat(touched_artifact
) = TRUE
;
114 exercise(A_WIS
, TRUE
);
118 /* external hook for do.c (level change check) */
122 return (boolean
) ((Qstat(got_quest
) || Qstat(got_thanks
))
123 && is_pure(FALSE
) > 0);
129 return (boolean
) (u
.ulevel
< MIN_QUEST_LEVEL
);
137 aligntyp original_alignment
= u
.ualignbase
[A_ORIGINAL
];
139 if (wizard
&& talk
) {
140 if (u
.ualign
.type
!= original_alignment
) {
141 You("are currently %s instead of %s.", align_str(u
.ualign
.type
),
142 align_str(original_alignment
));
143 } else if (u
.ualignbase
[A_CURRENT
] != original_alignment
) {
144 You("have converted.");
145 } else if (u
.ualign
.record
< MIN_QUEST_ALIGN
) {
146 You("are currently %d and require %d.", u
.ualign
.record
,
148 if (yn_function("adjust?", (char *) 0, 'y') == 'y')
149 u
.ualign
.record
= MIN_QUEST_ALIGN
;
152 purity
= (u
.ualign
.record
>= MIN_QUEST_ALIGN
153 && u
.ualign
.type
== original_alignment
154 && u
.ualignbase
[A_CURRENT
] == original_alignment
)
156 : (u
.ualignbase
[A_CURRENT
] != original_alignment
) ? -1 : 0;
161 * Expel the player to the stairs on the parent of the quest dungeon.
163 * This assumes that the hero is currently _in_ the quest dungeon and that
164 * there is a single branch to and from it.
175 br
= dungeon_branch("The Quest");
176 dest
= (br
->end1
.dnum
== u
.uz
.dnum
) ? &br
->end2
: &br
->end1
;
177 portal_flag
= u
.uevent
.qexpelled
? 0 /* returned via artifact? */
179 schedule_goto(dest
, FALSE
, FALSE
, portal_flag
, (char *) 0, (char *) 0);
180 if (seal
) { /* remove the portal to the quest - sealing it off */
181 int reexpelled
= u
.uevent
.qexpelled
;
182 u
.uevent
.qexpelled
= 1;
183 remdun_mapseen(quest_dnum
);
184 /* Delete the near portal now; the far (main dungeon side)
185 portal will be deleted as part of arrival on that level.
186 If monster movement is in progress, any who haven't moved
187 yet will now miss out on a chance to wander through it... */
188 for (t
= ftrap
; t
; t
= t
->ntrap
)
189 if (t
->ttyp
== MAGIC_PORTAL
)
192 deltrap(t
); /* (display might be briefly out of sync) */
193 else if (!reexpelled
)
194 impossible("quest portal already gone?");
198 /* Either you've returned to quest leader while carrying the quest
199 artifact or you've just thrown it to/at him or her. If quest
200 completion text hasn't been given yet, give it now. Otherwise
201 give another message about the character keeping the artifact
202 and using the magic portal to return to the dungeon. */
205 struct obj
*obj
; /* quest artifact; possibly null if carrying Amulet */
209 if (u
.uhave
.amulet
) { /* unlikely but not impossible */
210 qt_pager(QT_HASAMULET
);
211 /* leader IDs the real amulet but ignores any fakes */
212 if ((otmp
= carrying(AMULET_OF_YENDOR
)) != 0)
213 fully_identify_obj(otmp
);
215 qt_pager(!Qstat(got_thanks
) ? QT_OFFEREDIT
: QT_OFFEREDIT2
);
216 /* should have obtained bell during quest;
217 if not, suggest returning for it now */
218 if ((otmp
= carrying(BELL_OF_OPENING
)) == 0)
221 Qstat(got_thanks
) = TRUE
;
224 u
.uevent
.qcompleted
= 1; /* you did it! */
225 /* behave as if leader imparts sufficient info about the
227 fully_identify_obj(obj
);
235 /* Rule 0: Cheater checks. */
236 if (u
.uhave
.questart
&& !Qstat(met_nemesis
))
237 Qstat(cheater
) = TRUE
;
239 /* It is possible for you to get the amulet without completing
240 * the quest. If so, try to induce the player to quest.
242 if (Qstat(got_thanks
)) {
243 /* Rule 1: You've gone back with/without the amulet. */
245 finish_quest((struct obj
*) 0);
247 /* Rule 2: You've gone back before going for the amulet. */
249 qt_pager(QT_POSTHANKS
);
251 /* Rule 3: You've got the artifact and are back to return it. */
252 } else if (u
.uhave
.questart
) {
255 for (otmp
= invent
; otmp
; otmp
= otmp
->nobj
)
256 if (is_quest_artifact(otmp
))
261 /* Rule 4: You haven't got the artifact yet. */
262 } else if (Qstat(got_quest
)) {
263 qt_pager(rn1(10, QT_ENCOURAGE
));
265 /* Rule 5: You aren't yet acceptable - or are you? */
267 if (!Qstat(met_leader
)) {
268 qt_pager(QT_FIRSTLEADER
);
269 Qstat(met_leader
) = TRUE
;
270 Qstat(not_ready
) = 0;
272 qt_pager(QT_NEXTLEADER
);
274 /* the quest leader might have passed through the portal into
275 the regular dungeon; none of the remaining make sense there */
276 if (!on_level(&u
.uz
, &qstart_level
))
280 qt_pager(QT_BADLEVEL
);
281 exercise(A_WIS
, TRUE
);
283 } else if (is_pure(TRUE
) < 0) {
284 com_pager(QT_BANISHED
);
286 } else if (is_pure(TRUE
) == 0) {
287 qt_pager(QT_BADALIGN
);
288 if (Qstat(not_ready
) == MAX_QUEST_TRIES
) {
289 qt_pager(QT_LASTLEADER
);
293 exercise(A_WIS
, TRUE
);
296 } else { /* You are worthy! */
297 qt_pager(QT_ASSIGNQUEST
);
298 exercise(A_WIS
, TRUE
);
299 Qstat(got_quest
) = TRUE
;
308 /* maybe you attacked leader? */
309 if (!mtmp
->mpeaceful
) {
310 Qstat(pissed_off
) = TRUE
;
311 mtmp
->mstrategy
&= ~STRAT_WAITMASK
; /* end the inaction */
313 /* the quest leader might have passed through the portal into the
314 regular dungeon; if so, mustn't perform "backwards expulsion" */
315 if (!on_level(&u
.uz
, &qstart_level
))
318 if (Qstat(pissed_off
)) {
319 qt_pager(QT_LASTLEADER
);
328 /* The nemesis will do most of the talking, but... */
329 qt_pager(rn1(10, QT_DISCOURAGE
));
330 if (!Qstat(met_nemesis
))
331 Qstat(met_nemesis
++);
337 if (!Qstat(in_battle
)) {
338 if (u
.uhave
.questart
)
339 qt_pager(QT_NEMWANTSIT
);
340 else if (Qstat(made_goal
) == 1 || !Qstat(met_nemesis
))
341 qt_pager(QT_FIRSTNEMESIS
);
342 else if (Qstat(made_goal
) < 4)
343 qt_pager(QT_NEXTNEMESIS
);
344 else if (Qstat(made_goal
) < 7)
345 qt_pager(QT_OTHERNEMESIS
);
347 qt_pager(rn1(10, QT_DISCOURAGE
));
348 if (Qstat(made_goal
) < 7)
350 Qstat(met_nemesis
) = TRUE
;
351 } else /* he will spit out random maledictions */
353 qt_pager(rn1(10, QT_DISCOURAGE
));
359 /* These guys/gals really don't have much to say... */
360 if (u
.uhave
.questart
&& Qstat(killed_nemesis
))
361 qt_pager(rn1(5, QT_GUARDTALK2
));
363 qt_pager(rn1(5, QT_GUARDTALK
));
367 prisoner_speaks(mtmp
)
370 if (mtmp
->data
== &mons
[PM_PRISONER
]
371 && (mtmp
->mstrategy
& STRAT_WAITMASK
)) {
372 /* Awaken the prisoner */
374 pline("%s speaks:", Monnam(mtmp
));
375 verbalize("I'm finally free!");
376 mtmp
->mstrategy
&= ~STRAT_WAITMASK
;
379 /* Your god is happy... */
382 /* ...But the guards are not */
383 (void) angry_guards(FALSE
);
390 register struct monst
*mtmp
;
392 if (mtmp
->m_id
== Qstat(leader_m_id
)) {
396 switch (mtmp
->data
->msound
) {
401 chat_with_guardian();
404 impossible("quest_chat: Unknown quest character %s.", mon_nam(mtmp
));
412 if (mtmp
->m_id
== Qstat(leader_m_id
)) {
416 switch (mtmp
->data
->msound
) {
421 prisoner_speaks(mtmp
);
429 quest_stat_check(mtmp
)
432 if (mtmp
->data
->msound
== MS_NEMESIS
)
433 Qstat(in_battle
) = (mtmp
->mcanmove
&& !mtmp
->msleeping
434 && monnear(mtmp
, u
.ux
, u
.uy
));