xref: /original-bsd/games/larn/bill.c (revision 5133e8a4)
1 /*-
2  * Copyright (c) 1991 The Regents of the University of California.
3  * All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  */
7 
8 #ifndef lint
9 static char sccsid[] = "@(#)bill.c	5.2 (Berkeley) 05/28/91";
10 #endif /* not lint */
11 
12 #include <sys/file.h>
13 #include <sys/wait.h>
14 #include <string.h>
15 #include <stdlib.h>
16 #include <stdio.h>
17 #include <unistd.h>
18 #include "header.h"
19 
20 /* bill.c		 Larn is copyrighted 1986 by Noah Morgan. */
21 
22 char *mail[] = {
23 	"From: the LRS (Larn Revenue Service)\n",
24 	"~s undeclared income\n",
25 	"\n   We have heard you survived the caverns of Larn.  Let me be the",
26 	"\nfirst to congratulate you on your success.  It was quite a feat.",
27 	"\nIt was also very profitable for you...",
28 	"\n\n   The Dungeon Master has informed us that you brought",
29 	"1",
30 	"\ncounty of Larn is in dire need of funds, we have spared no time",
31 	"2",
32 	"\nof this notice, and is due within 5 days.  Failure to pay will",
33 	"\nmean penalties.  Once again, congratulations, We look forward",
34 	"\nto your future successful expeditions.\n",
35 	NULL,
36 	"From: His Majesty King Wilfred of Larndom\n",
37 	"~s a noble deed\n",
38 	"\n   I have heard of your magnificent feat, and I, King Wilfred,",
39 	"\nforthwith declare today to be a national holiday.  Furthermore,",
40 	"\nhence three days, ye be invited to the castle to receive the",
41 	"\nhonour of Knight of the realm.  Upon thy name shall it be written...",
42 	"\n\nBravery and courage be yours.",
43 	"\n\nMay you live in happiness forevermore...\n",
44 	NULL,
45 	"From: Count Endelford\n",
46 	"~s You Bastard!\n",
47 	"\n   I have heard (from sources) of your journey.  Congratulations!",
48 	"\nYou Bastard!  With several attempts I have yet to endure the",
49 	" caves,\nand you, a nobody, makes the journey!  From this time",
50 	" onward, bewarned\nupon our meeting you shall pay the price!\n",
51 	NULL,
52 	"From: Mainair, Duke of Larnty\n",
53 	"~s High Praise\n",
54 	"\n   With certainty, a hero I declare to be amongst us!  A nod of",
55 	"\nfavour I send to thee.  Me thinks Count Endelford this day of",
56 	"\nright breath'eth fire as of dragon of whom ye are slayer.  I",
57 	"\nyearn to behold his anger and jealously.  Should ye choose to",
58 	"\nunleash some of thy wealth upon those who be unfortunate, I,",
59 	"\nDuke Mainair, shall equal thy gift also.\n",
60 	NULL,
61 	"From: St. Mary's Children's Home\n",
62 	"~s these poor children\n",
63 	"\n   News of your great conquests has spread to all of Larndom.",
64 	"\nMight I have a moment of a great adventurers's time?  We here at",
65 	"\nSt. Mary's Children's Home are very poor, and many children are",
66 	"\nstarving.  Disease is widespread and very often fatal without",
67 	"\ngood food.  Could you possibly find it in your heart to help us",
68 	"\nin our plight?  Whatever you could give will help much.",
69 	"\n(your gift is tax deductible)\n",
70 	NULL,
71 	"From: The National Cancer Society of Larn\n",
72 	"~s hope\n",
73 	"\nCongratulations on your successful expedition.  We are sure much",
74 	"\ncourage and determination were needed on your quest.  There are",
75 	"\nmany though, that could never hope to undertake such a journey",
76 	"\ndue to an enfeebling disease -- cancer.  We at the National",
77 	"\nCancer Society of Larn wish to appeal to your philanthropy in",
78 	"\norder to save many good people -- possibly even yourself a few",
79 	"\nyears from now.  Much work needs to be done in researching this",
80 	"\ndreaded disease, and you can help today.  Could you please see it",
81 	"\nin your heart to give generously?  Your continued good health",
82 	"\ncan be your everlasting reward.\n",
83 	NULL
84 };
85 
86 /*
87  *	function to mail the letters to the player if a winner
88  */
89 
90 void
91 mailbill()
92 {
93 	register int i;
94 	char fname[32];
95 	char buf[128];
96 	char **cp;
97 	int fd;
98 
99 	wait(0);
100 	if (fork() == 0) {
101 		resetscroll();
102 		cp = mail;
103 		sprintf(fname, "/tmp/#%dlarnmail", getpid());
104 		for (i = 0; i < 6; i++) {
105 			if ((fd = open(fname, O_WRONLY | O_TRUNC | O_CREAT),
106 			    0666) == -1)
107 				exit(0);
108 			while (*cp != NULL) {
109 				if (*cp[0] == '1') {
110 					sprintf(buf, "\n%d gold pieces back with you from your journey.  As the",
111 					    (long)c[GOLD]);
112 					write(fd, buf, strlen(buf));
113 				} else if (*cp[0] == '2') {
114 					sprintf(buf, "\nin preparing your tax bill.  You owe %d gold pieces as", (long)c[GOLD]*TAXRATE);
115 					write(fd, buf, strlen(buf));
116 				} else
117 					write(fd, *cp, strlen(*cp));
118 				cp++;
119 			}
120 			cp++;
121 
122 			close(fd);
123 			sprintf(buf, "mail -I %s < %s > /dev/null",
124 			    loginname, fname);
125 			system(buf);
126 			unlink(fname);
127 		}
128 	}
129 	exit(0);
130 }
131