Source:NetHack 3.4.0/quest.c

From NetHackWiki
(Redirected from NetHack 3.4.0/quest.c)
Jump to navigation Jump to search

Below is the full text to quest.c from the source code of NetHack 3.4.0. To link to a particular line, write [[NetHack 3.4.0/quest.c#line123]], for example.

Warning! This is the source code from an old release. For the latest release, 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: @(#)quest.c	3.4	2000/05/05	*/
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 boolean 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.   
27.   STATIC_OVL void
28.   on_start()
29.   {
30.     if(!Qstat(first_start)) {
31.       qt_pager(QT_FIRSTTIME);
32.       Qstat(first_start) = TRUE;
33.     } else if((u.uz0.dnum != u.uz.dnum) || (u.uz0.dlevel < u.uz.dlevel)) {
34.       if(Qstat(not_ready) <= 2) qt_pager(QT_NEXTTIME);
35.       else	qt_pager(QT_OTHERTIME);
36.     }
37.   }
38.   
39.   STATIC_OVL void
40.   on_locate()
41.   {
42.     if(!Qstat(first_locate)) {
43.       qt_pager(QT_FIRSTLOCATE);
44.       Qstat(first_locate) = TRUE;
45.     } else if(u.uz0.dlevel < u.uz.dlevel && !Qstat(killed_nemesis))
46.   	qt_pager(QT_NEXTLOCATE);
47.   }
48.   
49.   STATIC_OVL void
50.   on_goal()
51.   {
52.     if (Qstat(killed_nemesis)) {
53.       return;
54.     } else if (!Qstat(made_goal)) {
55.       qt_pager(QT_FIRSTGOAL);
56.       Qstat(made_goal) = 1;
57.     } else {
58.       qt_pager(QT_NEXTGOAL);
59.       if(Qstat(made_goal) < 7) Qstat(made_goal)++;
60.     }
61.   }
62.   
63.   void
64.   onquest()
65.   {
66.   	if(u.uevent.qcompleted || Not_firsttime) return;
67.   	if(!Is_special(&u.uz)) return;
68.   
69.   	if(Is_qstart(&u.uz)) on_start();
70.   	else if(Is_qlocate(&u.uz) && u.uz.dlevel > u.uz0.dlevel) on_locate();
71.   	else if(Is_nemesis(&u.uz)) on_goal();
72.   	return;
73.   }
74.   
75.   void
76.   nemdead()
77.   {
78.   	if(!Qstat(killed_nemesis)) {
79.   	    Qstat(killed_nemesis) = TRUE;
80.   	    qt_pager(QT_KILLEDNEM);
81.   	}
82.   }
83.   
84.   void
85.   artitouch()
86.   {
87.   	if(!Qstat(touched_artifact)) {
88.   	    Qstat(touched_artifact) = TRUE;
89.   	    qt_pager(QT_GOTIT);
90.   	    exercise(A_WIS, TRUE);
91.   	}
92.   }
93.   
94.   /* external hook for do.c (level change check) */
95.   boolean
96.   ok_to_quest()
97.   {
98.   	return((boolean)((Qstat(got_quest) || Qstat(got_thanks)))
99.   			&& is_pure(FALSE));
100.  }
101.  
102.  STATIC_OVL boolean
103.  not_capable()
104.  {
105.  	return((boolean)(u.ulevel < MIN_QUEST_LEVEL));
106.  }
107.  
108.  STATIC_OVL boolean
109.  is_pure(talk)
110.  boolean talk;
111.  {
112.      aligntyp original_alignment = u.ualignbase[A_ORIGINAL];
113.  
114.  #ifdef WIZARD
115.      if (wizard && talk) {
116.  	if (u.ualign.type != original_alignment) {
117.  	    You("are currently %s instead of %s.",
118.  		align_str(u.ualign.type), align_str(original_alignment));
119.  	} else if (u.ualignbase[A_CURRENT] != original_alignment) {
120.  	    You("have converted.");
121.  	} else if (u.ualign.record < MIN_QUEST_ALIGN) {
122.  	    You("are currently %d and require %d.",
123.  		u.ualign.record, MIN_QUEST_ALIGN);
124.  	    if (yn_function("adjust?", (char *)0, 'y') == 'y')
125.  		u.ualign.record = MIN_QUEST_ALIGN;
126.  	}
127.      }
128.  #endif
129.      return (boolean)(u.ualign.record >= MIN_QUEST_ALIGN &&
130.  		     u.ualign.type == original_alignment &&
131.  		     u.ualignbase[A_CURRENT] == original_alignment);
132.  }
133.  
134.  /*
135.   * Expell the player to the stairs on the parent of the quest dungeon.
136.   *
137.   * This assumes that the hero is currently _in_ the quest dungeon and that
138.   * there is a single branch to and from it.
139.   */
140.  STATIC_OVL void
141.  expulsion(seal)
142.  boolean seal;
143.  {
144.      branch *br;
145.      d_level *dest;
146.      struct trap *t;
147.      int portal_flag;
148.  
149.      br = dungeon_branch("The Quest");
150.      dest = (br->end1.dnum == u.uz.dnum) ? &br->end2 : &br->end1;
151.      portal_flag = u.uevent.qexpelled ? 0 :	/* returned via artifact? */
152.  		  !seal ? 1 : -1;
153.      schedule_goto(dest, FALSE, FALSE, portal_flag, (char *)0, (char *)0);
154.      if (seal) {	/* remove the portal to the quest - sealing it off */
155.  	int reexpelled = u.uevent.qexpelled;
156.  	u.uevent.qexpelled = 1;
157.  	/* Delete the near portal now; the far (main dungeon side)
158.  	   portal will be deleted as part of arrival on that level.
159.  	   If monster movement is in progress, any who haven't moved
160.  	   yet will now miss out on a chance to wander through it... */
161.  	for (t = ftrap; t; t = t->ntrap)
162.  	    if (t->ttyp == MAGIC_PORTAL) break;
163.  	if (t) deltrap(t);	/* (display might be briefly out of sync) */
164.  	else if (!reexpelled) impossible("quest portal already gone?");
165.      }
166.  }
167.  
168.  /* Either you've returned to quest leader while carrying the quest
169.     artifact or you've just thrown it to/at him or her.  If quest
170.     completion text hasn't been given yet, give it now.  Otherwise
171.     give another message about the character keeping the artifact
172.     and using the magic portal to return to the dungeon. */
173.  void
174.  finish_quest(obj)
175.  struct obj *obj;	/* quest artifact; possibly null if carrying Amulet */
176.  {
177.  	struct obj *otmp;
178.  
179.  	if (u.uhave.amulet) {	/* unlikely but not impossible */
180.  	    qt_pager(QT_HASAMULET);
181.  	    /* leader IDs the real amulet but ignores any fakes */
182.  	    if ((otmp = carrying(AMULET_OF_YENDOR)) != 0)
183.  		fully_identify_obj(otmp);
184.  	} else {
185.  	    qt_pager(!Qstat(got_thanks) ? QT_OFFEREDIT : QT_OFFEREDIT2);
186.  	    /* should have obtained bell during quest;
187.  	       if not, suggest returning for it now */
188.  	    if ((otmp = carrying(BELL_OF_OPENING)) == 0)
189.  		com_pager(5);
190.  	}
191.  	Qstat(got_thanks) = TRUE;
192.  
193.  	if (obj) {
194.  	    u.uevent.qcompleted = 1;	/* you did it! */
195.  	    /* behave as if leader imparts sufficient info about the
196.  	       quest artifact */
197.  	    fully_identify_obj(obj);
198.  	    update_inventory();
199.  	}
200.  }
201.  
202.  STATIC_OVL void
203.  chat_with_leader()
204.  {
205.  /*	Rule 0:	Cheater checks.					*/
206.  	if(u.uhave.questart && !Qstat(met_nemesis))
207.  	    Qstat(cheater) = TRUE;
208.  
209.  /*	It is possible for you to get the amulet without completing
210.   *	the quest.  If so, try to induce the player to quest.
211.   */
212.  	if(Qstat(got_thanks)) {
213.  /*	Rule 1:	You've gone back with/without the amulet.	*/
214.  	    if(u.uhave.amulet)	finish_quest((struct obj *)0);
215.  
216.  /*	Rule 2:	You've gone back before going for the amulet.	*/
217.  	    else		qt_pager(QT_POSTHANKS);
218.  	}
219.  
220.  /*	Rule 3: You've got the artifact and are back to return it. */
221.  	  else if(u.uhave.questart) {
222.  	    struct obj *otmp;
223.  
224.  	    for (otmp = invent; otmp; otmp = otmp->nobj)
225.  		if (is_quest_artifact(otmp)) break;
226.  
227.  	    finish_quest(otmp);
228.  
229.  /*	Rule 4: You haven't got the artifact yet.	*/
230.  	} else if(Qstat(got_quest)) {
231.  	    qt_pager(rn1(10, QT_ENCOURAGE));
232.  
233.  /*	Rule 5: You aren't yet acceptable - or are you? */
234.  	} else {
235.  	  if(!Qstat(met_leader)) {
236.  	    qt_pager(QT_FIRSTLEADER);
237.  	    Qstat(met_leader) = TRUE;
238.  	    Qstat(not_ready) = 0;
239.  	  } else qt_pager(QT_NEXTLEADER);
240.  	  /* the quest leader might have passed through the portal into
241.  	     the regular dungeon; none of the remaining make sense there */
242.  	  if (!on_level(&u.uz, &qstart_level)) return;
243.  
244.  	  if(not_capable()) {
245.  	    qt_pager(QT_BADLEVEL);
246.  	    exercise(A_WIS, TRUE);
247.  	    expulsion(FALSE);
248.  	  } else if(!is_pure(TRUE)) {
249.  	    qt_pager(QT_BADALIGN);
250.  	    if(Qstat(not_ready) == MAX_QUEST_TRIES) {
251.  	      qt_pager(QT_LASTLEADER);
252.  	      expulsion(TRUE);
253.  	    } else {
254.  	      Qstat(not_ready)++;
255.  	      exercise(A_WIS, TRUE);
256.  	      expulsion(FALSE);
257.  	    }
258.  	  } else {	/* You are worthy! */
259.  	    qt_pager(QT_ASSIGNQUEST);
260.  	    exercise(A_WIS, TRUE);
261.  	    Qstat(got_quest) = TRUE;
262.  	  }
263.  	}
264.  }
265.  
266.  void
267.  leader_speaks(mtmp)
268.  	register struct monst *mtmp;
269.  {
270.  	/* maybe you attacked leader? */
271.  	if(!mtmp->mpeaceful) {
272.  		Qstat(pissed_off) = TRUE;
273.  		mtmp->mstrategy &= ~STRAT_WAITMASK;	/* end the inaction */
274.  	}
275.  	/* the quest leader might have passed through the portal into the
276.  	   regular dungeon; if so, mustn't perform "backwards expulsion" */
277.  	if (!on_level(&u.uz, &qstart_level)) return;
278.  
279.  	if(Qstat(pissed_off)) {
280.  	  qt_pager(QT_LASTLEADER);
281.  	  expulsion(TRUE);
282.  	} else chat_with_leader();
283.  }
284.  
285.  STATIC_OVL void
286.  chat_with_nemesis()
287.  {
288.  /*	The nemesis will do most of the talking, but... */
289.  	qt_pager(rn1(10, QT_DISCOURAGE));
290.  	if(!Qstat(met_nemesis)) Qstat(met_nemesis++);
291.  }
292.  
293.  void
294.  nemesis_speaks()
295.  {
296.  	if(!Qstat(in_battle)) {
297.  	  if(u.uhave.questart) qt_pager(QT_NEMWANTSIT);
298.  	  else if(Qstat(made_goal) == 1 || !Qstat(met_nemesis))
299.  	      qt_pager(QT_FIRSTNEMESIS);
300.  	  else if(Qstat(made_goal) < 4) qt_pager(QT_NEXTNEMESIS);
301.  	  else if(Qstat(made_goal) < 7) qt_pager(QT_OTHERNEMESIS);
302.  	  else if(!rn2(5))	qt_pager(rn1(10, QT_DISCOURAGE));
303.  	  if(Qstat(made_goal) < 7) Qstat(made_goal)++;
304.  	  Qstat(met_nemesis) = TRUE;
305.  	} else /* he will spit out random maledictions */
306.  	  if(!rn2(5))	qt_pager(rn1(10, QT_DISCOURAGE));
307.  }
308.  
309.  STATIC_OVL void
310.  chat_with_guardian()
311.  {
312.  /*	These guys/gals really don't have much to say... */
313.  	if (u.uhave.questart && Qstat(killed_nemesis))
314.  	    qt_pager(rn1(5, QT_GUARDTALK2));
315.  	else
316.  	    qt_pager(rn1(5, QT_GUARDTALK));
317.  }
318.  
319.  STATIC_OVL void
320.  prisoner_speaks (mtmp)
321.  	register struct monst *mtmp;
322.  {
323.  	if (mtmp->data == &mons[PM_PRISONER] &&
324.  			(mtmp->mstrategy & STRAT_WAITMASK)) {
325.  	    /* Awaken the prisoner */
326.  	    if (canseemon(mtmp))
327.  	    	pline("%s speaks:", Monnam(mtmp));
328.  	    verbalize("I'm finally free!");
329.  	    mtmp->mstrategy &= ~STRAT_WAITMASK;
330.  	    mtmp->mpeaceful = 1;
331.  
332.  	    /* Your god is happy... */
333.  	    adjalign(3);
334.  
335.  		/* ...But the guards are not */
336.  	    (void) angry_guards(FALSE);
337.  	}
338.  	return;
339.  }
340.  
341.  void
342.  quest_chat(mtmp)
343.  	register struct monst *mtmp;
344.  {
345.      if (mtmp->m_id == Qstat(leader_m_id)) {
346.  	chat_with_leader();
347.  	return;
348.      }
349.      switch(mtmp->data->msound) {
350.  	    case MS_NEMESIS:	chat_with_nemesis(); break;
351.  	    case MS_GUARDIAN:	chat_with_guardian(); break;
352.  	    default:	impossible("quest_chat: Unknown quest character %s.",
353.  				   mon_nam(mtmp));
354.  	}
355.  }
356.  
357.  void
358.  quest_talk(mtmp)
359.  	register struct monst *mtmp;
360.  {
361.      if (mtmp->m_id == Qstat(leader_m_id)) {
362.  	leader_speaks(mtmp);
363.  	return;
364.      }
365.      switch(mtmp->data->msound) {
366.  	    case MS_NEMESIS:	nemesis_speaks(); break;
367.  	    case MS_DJINNI:	prisoner_speaks(mtmp); break;
368.  	    default:		break;
369.  	}
370.  }
371.  
372.  void
373.  quest_stat_check(mtmp)
374.  	struct monst *mtmp;
375.  {
376.      if(mtmp->data->msound == MS_NEMESIS)
377.  	Qstat(in_battle) = (mtmp->mcanmove && !mtmp->msleeping &&
378.  			    monnear(mtmp, u.ux, u.uy));
379.  }
380.  
381.  /*quest.c*/