Merge from vendor branch GCC:
[dragonfly.git] / games / battlestar / com5.c
1 /*
2  * Copyright (c) 1983, 1993
3  *      The Regents of the University of California.  All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  * 1. Redistributions of source code must retain the above copyright
9  *    notice, this list of conditions and the following disclaimer.
10  * 2. Redistributions in binary form must reproduce the above copyright
11  *    notice, this list of conditions and the following disclaimer in the
12  *    documentation and/or other materials provided with the distribution.
13  * 3. All advertising materials mentioning features or use of this software
14  *    must display the following acknowledgement:
15  *      This product includes software developed by the University of
16  *      California, Berkeley and its contributors.
17  * 4. Neither the name of the University nor the names of its contributors
18  *    may be used to endorse or promote products derived from this software
19  *    without specific prior written permission.
20  *
21  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31  * SUCH DAMAGE.
32  *
33  * @(#)com5.c   8.1 (Berkeley) 5/31/93
34  * $FreeBSD: src/games/battlestar/com5.c,v 1.9.2.1 2001/03/05 11:45:35 kris Exp $
35  * $DragonFly: src/games/battlestar/com5.c,v 1.2 2003/06/17 04:25:22 dillon Exp $
36  */
37
38 #include "externs.h"
39
40 void
41 kiss()
42 {
43         while (wordtype[++wordnumber] != NOUNS && wordnumber <= wordcount);
44         if (wordtype[wordnumber] == NOUNS && testbit(location[position].objects,wordvalue[wordnumber])){
45                 pleasure++;
46                 printf("Kissed.\n");
47                 switch (wordvalue[wordnumber]){
48                         case NORMGOD:
49                         switch(godready++){
50                                 case 0:
51                                         puts("She squirms and avoids your advances.");
52                                         break;
53                                 case 1:
54                                         puts("She is coming around; she didn't fight it as much.");
55                                         break;
56                                 case 2:
57                                         puts("She's begining to like it.");
58                                         break;
59                                 default:
60                                         puts("She's gone limp.");
61
62                         }
63                         break;
64                         case NATIVE:
65                                 puts("The lips are warm and her body robust.  She pulls you down to the ground.");
66                                 break;
67                         case TIMER:
68                                 puts("The old man blushes.");
69                                 break;
70                         case MAN:
71                                 puts("The dwarf punches you in the kneecap.");
72                                 break;
73                         default:
74                                 pleasure--;
75                 }
76         }
77         else    puts("I'd prefer not to.");
78 }
79
80 void
81 love()
82 {
83         int n;
84
85         while (wordtype[++wordnumber] != NOUNS && wordnumber <= wordcount);
86         if (wordtype[wordnumber] == NOUNS && testbit(location[position].objects,wordvalue[wordnumber])){
87                 if (wordvalue[wordnumber] == NORMGOD && !loved) {
88                         if (godready >= 2){
89                                 puts("She cuddles up to you, and her mouth starts to work:\n'That was my sister's amulet.  The lovely goddess, Purl, was she.  The Empire\ncaptured her just after the Darkness came.  My other sister, Vert, was killed\nby the Dark Lord himself.  He took her amulet and warped its power.\nYour quest was foretold by my father before he died, but to get the Dark Lord's\namulet you must use cunning and skill.  I will leave you my amulet.");
90                                 puts("which you may use as you wish.  As for me, I am the last goddess of the\nwaters.  My father was the Island King, and the rule is rightfully mine.'\n\nShe pulls the throne out into a large bed.");
91                                 power++;
92                                 pleasure += 15;
93                                 ego++;
94                                 if (card(injuries, NUMOFINJURIES)){
95                                         puts("Her kisses revive you; your wounds are healed.\n");
96                                         for (n=0; n < NUMOFINJURIES; n++)
97                                                 injuries[n] = 0;
98                                         WEIGHT = MAXWEIGHT;
99                                         CUMBER = MAXCUMBER;
100                                 }
101                                 printf("Goddess:\n");
102                                 if (!loved)
103                                         setbit(location[position].objects,MEDALION);
104                                 loved = 1;
105                                 gtime += 10;
106                                 zzz();
107                         }
108                         else {
109                                 puts("You wish!");
110                                 return;
111                         }
112                 }
113                 if (wordvalue[wordnumber] == NATIVE){
114                         puts("The girl is easy prey.  She peels off her sarong and indulges you.");
115                         power++;
116                         pleasure += 5;
117                         printf("Girl:\n");
118                         gtime += 10;
119                         zzz();
120                 }
121                 printf("Loved.\n");
122         }
123         else puts("I't doesn't seem to work.");
124 }
125
126 int
127 zzz()
128 {
129         int oldtime;
130         int n;
131
132         oldtime = gtime;
133         if ((snooze - gtime) < (0.75 * CYCLE)){
134                 gtime += 0.75 * CYCLE - (snooze - gtime);
135                 printf("<zzz>");
136                 for (n = 0; n < gtime - oldtime; n++)
137                         printf(".");
138                 printf("\n");
139                 snooze += 3 * (gtime - oldtime);
140                 if (notes[LAUNCHED]){
141                         fuel -= (gtime - oldtime);
142                         if (location[position].down){
143                                 position = location[position].down;
144                                 crash();
145                         }
146                         else
147                                 notes[LAUNCHED] = 0;
148                 }
149                 if (OUTSIDE && rnd(100) < 50){
150                         puts("You are awakened abruptly by the sound of someone nearby.");
151                         switch(rnd(4)){
152                                 case 0:
153                                         if (ucard(inven)){
154                                                 n = rnd(NUMOFOBJECTS);
155                                                 while(!testbit(inven,n))
156                                                         n = rnd(NUMOFOBJECTS);
157                                                 clearbit(inven,n);
158                                                 if (n != AMULET && n != MEDALION && n != TALISMAN)
159                                                         setbit(location[position].objects,n);
160                                                 carrying -= objwt[n];
161                                                 encumber -= objcumber[n];
162                                         }
163                                         puts("A fiendish little Elf is stealing your treasures!");
164                                         fight(ELF,10);
165                                         break;
166                                 case 1:
167                                         setbit(location[position].objects,DEADWOOD);
168                                         break;
169                                 case 2:
170                                         setbit(location[position].objects,HALBERD);
171                                         break;
172                                 default:
173                                         break;
174                         }
175                 }
176         }
177         else
178                 return(0);
179         return(1);
180 }
181
182 void
183 chime()
184 {
185         if ((gtime / CYCLE + 1) % 2 && OUTSIDE)
186                 switch((gtime % CYCLE)/(CYCLE / 7)){
187                         case 0:
188                                 puts("It is just after sunrise.");
189                                 break;
190                         case 1:
191                                 puts("It is early morning.");
192                                 break;
193                         case 2:
194                                 puts("It is late morning.");
195                                 break;
196                         case 3:
197                                 puts("It is near noon.");
198                                 break;
199                         case 4:
200                                 puts("It is early afternoon.");
201                                 break;
202                         case 5:
203                                 puts("It is late afternoon.");
204                                 break;
205                         case 6:
206                                 puts("It is near sunset.");
207                                 break;
208                 }
209         else if (OUTSIDE)
210                 switch((gtime % CYCLE)/(CYCLE / 7)){
211                         case 0:
212                                 puts("It is just after sunset.");
213                                 break;
214                         case 1:
215                                 puts("It is early evening.");
216                                 break;
217                         case 2:
218                                 puts("The evening is getting old.");
219                                 break;
220                         case 3:
221                                 puts("It is near midnight.");
222                                 break;
223                         case 4:
224                                 puts("These are the wee hours of the morning.");
225                                 break;
226                         case 5:
227                                 puts("The night is waning.");
228                                 break;
229                         case 6:
230                                 puts("It is almost morning.");
231                                 break;
232                 }
233         else
234                 puts("I can't tell the time in here.");
235 }
236
237 int
238 give()
239 {
240         int obj = -1, result = -1, person = 0, firstnumber;
241         int last1 = 0, last2 = 0;
242
243         firstnumber = wordnumber;
244         while (wordtype[++wordnumber] != OBJECT  && wordvalue[wordnumber] != AMULET && wordvalue[wordnumber] != MEDALION && wordvalue[wordnumber] != TALISMAN && wordnumber <= wordcount);
245         if (wordnumber <= wordcount){
246                 obj = wordvalue[wordnumber];
247                 if (obj == EVERYTHING)
248                         wordtype[wordnumber] = -1;
249                 last1 = wordnumber;
250         }
251         wordnumber = firstnumber;
252         while ((wordtype[++wordnumber] != NOUNS || wordvalue[wordnumber] == obj) && wordnumber <= wordcount);
253         if (wordtype[wordnumber] == NOUNS){
254                 person = wordvalue[wordnumber];
255                 last2 = wordnumber;
256         }
257         /* Setting wordnumber to last1 - 1 looks wrong if last1 is 0, e.g.,
258          * plain `give'.  However, detecting this case is liable to detect
259          * `give foo' as well, which would give a confusing error.  We
260          * need to make sure the -1 value can cause no problems if it arises.
261          * If in the below we get to the drop("Given") then drop will look
262          * at word 0 for an object to give, and fail, which is OK; then
263          * result will be -1 and we get to the end, where wordnumber gets
264          * set to something more sensible.  If we get to "I don't think
265          * that is possible" then again wordnumber is set to something
266          * sensible.  The wordnumber we leave with still isn't right if
267          * you include words the game doesn't know in your command, but
268          * that's no worse than what other commands than give do in
269          * the same place.  */
270         wordnumber = last1 - 1;
271         if (person && testbit(location[position].objects,person))
272                 if (person == NORMGOD && godready < 2 && !(obj == RING || obj == BRACELET))
273                         puts("The goddess won't look at you.");
274                 else
275                         result = drop("Given");
276         else {
277                 puts("I don't think that is possible.");
278                 wordnumber = max(last1, last2) + 1;
279                 return(0);
280         }
281         if (result != -1 && (testbit(location[position].objects,obj) || obj == AMULET || obj == MEDALION || obj == TALISMAN)){
282                 clearbit(location[position].objects,obj);
283                 gtime++;
284                 ego++;
285                 switch(person){
286                         case NATIVE:
287                                 puts("She accepts it shyly.");
288                                 ego += 2;
289                                 break;
290                         case NORMGOD:
291                                 if (obj == RING || obj == BRACELET){
292                                         puts("She takes the charm and puts it on.  A little kiss on the cheek is");
293                                         puts("your reward.");
294                                         ego += 5;
295                                         godready += 3;
296                                 }
297                                 if (obj == AMULET || obj == MEDALION || obj == TALISMAN){
298                                         bs_win++;
299                                         ego += 5;
300                                         power -= 5;
301                                         if (bs_win >= 3){
302                                                 puts("The powers of the earth are now legitimate.  You have destroyed the Darkness");
303                                                 puts("and restored the goddess to her thrown.  The entire island celebrates with");
304                                                 puts("dancing and spring feasts.  As a measure of her gratitude, the goddess weds you");
305                                                 puts("in the late summer and crowns you Prince Liverwort, Lord of Fungus.");
306                                                 puts("\nBut, as the year wears on and autumn comes along, you become restless and");
307                                                 puts("yearn for adventure.  The goddess, too, realizes that the marriage can't last.");
308                                                 puts("She becomes bored and takes several more natives as husbands.  One evening,");
309                                                 puts("after having been out drinking with the girls, she kicks the throne particularly");
310                                                 puts("hard and wakes you up.  (If you want to win this game, you're going to have to\nshoot her!)");
311                                                 clearbit(location[position].objects,MEDALION);
312                                                 wintime = gtime;
313                                         }
314                                 }
315                                 break;
316                         case TIMER:
317                                 if (obj == COINS){
318                                         puts("He fingers the coins for a moment and then looks up agape.  `Kind you are and");
319                                         puts("I mean to repay you as best I can.'  Grabbing a pencil and cocktail napkin...\n");
320                                         printf(  "+-----------------------------------------------------------------------------+\n");
321                                         printf(  "|                                xxxxxxxx\\                                 |\n");
322                                         printf(  "|                                    xxxxx\\  CLIFFS                        |\n");
323                                         printf(  "|             FOREST                    xxx\\                               |\n");
324                                         printf(  "|                             \\\\         x\\                OCEAN                 |\n");
325                                         printf(  "|                             ||             x\\                            |\n");
326                                         printf(  "|                             ||  ROAD        x\\                           |\n");
327                                         printf(  "|                             ||              x\\                           |\n");
328                                         printf(  "|             SECRET          ||        .........                           |\n");
329                                         printf(  "|              - + -          ||         ........                           |\n");
330                                         printf(  "|             ENTRANCE        ||              ...      BEACH                |\n");
331                                         printf(  "|                             ||              ...               E           |\n");
332                                         printf(  "|                             ||              ...               |           |\n");
333                                         printf(  "|                             //              ...         N <-- + --- S     |\n");
334                                         printf(  "|             PALM GROVE     //               ...               |           |\n");
335                                         printf(  "|                           //                ...               W           |\n");
336                                         printf(  "+-----------------------------------------------------------------------------+\n");
337                                         puts("\n`This map shows a secret entrance to the catacombs.");
338                                         puts("You will know when you arrive because I left an old pair of shoes there.'");
339                                 }
340                                 break;
341                 }
342         }
343         wordnumber = max(last1,last2) + 1;
344         return(firstnumber);
345 }