]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - hack/hack.engrave.c
1 /* $NetBSD: hack.engrave.c,v 1.8 2009/06/07 20:30:49 dholland Exp $ */
4 * Copyright (c) 1985, Stichting Centrum voor Wiskunde en Informatica,
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions are
12 * - Redistributions of source code must retain the above copyright notice,
13 * this list of conditions and the following disclaimer.
15 * - Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * - Neither the name of the Stichting Centrum voor Wiskunde en
20 * Informatica, nor the names of its contributors may be used to endorse or
21 * promote products derived from this software without specific prior
24 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
25 * IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
26 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
27 * PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
28 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
29 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
30 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
31 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
32 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
33 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
34 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
38 * Copyright (c) 1982 Jay Fenlason <hack@gnu.org>
39 * All rights reserved.
41 * Redistribution and use in source and binary forms, with or without
42 * modification, are permitted provided that the following conditions
44 * 1. Redistributions of source code must retain the above copyright
45 * notice, this list of conditions and the following disclaimer.
46 * 2. Redistributions in binary form must reproduce the above copyright
47 * notice, this list of conditions and the following disclaimer in the
48 * documentation and/or other materials provided with the distribution.
49 * 3. The name of the author may not be used to endorse or promote products
50 * derived from this software without specific prior written permission.
52 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
53 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
54 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
55 * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
56 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
57 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
58 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
59 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
60 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
61 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
64 #include <sys/cdefs.h>
66 __RCSID("$NetBSD: hack.engrave.c,v 1.8 2009/06/07 20:30:49 dholland Exp $");
74 struct engr
*nxt_engr
;
77 unsigned engr_lth
; /* for save & restore; not length of
79 long engr_time
; /* moment engraving was (will be)
88 engr_at(xchar x
, xchar y
)
90 struct engr
*ep
= head_engr
;
92 if (x
== ep
->engr_x
&& y
== ep
->engr_y
)
96 return ((struct engr
*) 0);
100 sengr_at(const char *s
, xchar x
, xchar y
)
102 struct engr
*ep
= engr_at(x
, y
);
105 if (ep
&& ep
->engr_time
<= moves
) {
108 if(!strcmp(s,t)) return(1);
112 if (!strncmp(s
, t
, n
))
123 if (!u
.uswallow
&& !Levitation
)
124 wipe_engr_at(u
.ux
, u
.uy
, cnt
);
128 wipe_engr_at(xchar x
, xchar y
, xchar cnt
)
130 struct engr
*ep
= engr_at(x
, y
);
134 if ((ep
->engr_type
!= DUST
) || Levitation
) {
135 cnt
= rn2(1 + 50 / (cnt
+ 1)) ? 0 : 1;
137 lth
= strlen(ep
->engr_txt
);
138 if (lth
&& cnt
> 0) {
141 if ((ch
= ep
->engr_txt
[pos
]) == ' ')
143 ep
->engr_txt
[pos
] = (ch
!= '?') ? '?' : ' ';
146 while (lth
&& ep
->engr_txt
[lth
- 1] == ' ')
147 ep
->engr_txt
[--lth
] = 0;
148 while (ep
->engr_txt
[0] == ' ')
150 if (!ep
->engr_txt
[0])
156 read_engr_at(int x
, int y
)
158 struct engr
*ep
= engr_at(x
, y
);
159 if (ep
&& ep
->engr_txt
[0]) {
160 switch (ep
->engr_type
) {
162 pline("Something is written here in the dust.");
165 pline("Something is engraved here on the floor.");
168 pline("Some text has been burned here in the floor.");
171 impossible("Something is written in a very strange way.");
173 pline("You read: \"%s\".", ep
->engr_txt
);
178 make_engr_at(int x
, int y
, const char *s
)
182 if ((ep
= engr_at(x
, y
)) != NULL
)
185 alloc((unsigned) (sizeof(struct engr
) + strlen(s
) + 1));
186 ep
->nxt_engr
= head_engr
;
190 ep
->engr_txt
= (char *) (ep
+ 1);
191 (void) strcpy(ep
->engr_txt
, s
);
193 ep
->engr_type
= DUST
;
194 ep
->engr_lth
= strlen(s
) + 1;
202 struct engr
*ep
, *oep
= engr_at(u
.ux
, u
.uy
);
205 int spct
; /* number of leading spaces */
210 pline("You're joking. Hahaha!"); /* riv05!a3 */
213 /* one may write with finger, weapon or wand */
214 otmp
= getobj("#-)/", "write with");
218 if (otmp
== &zeroobj
)
220 if (otmp
&& otmp
->otyp
== WAN_FIRE
&& otmp
->spe
) {
224 /* first wield otmp */
226 if (uwep
&& uwep
->cursed
) {
227 /* Andreas Bormann */
228 pline("Since your weapon is welded to your hand,");
229 pline("you use the %s.", aobjnam(uwep
, (char *) 0));
233 pline("You are now empty-handed.");
234 else if (otmp
->cursed
)
235 pline("The %s %s to your hand!",
236 aobjnam(otmp
, "weld"),
237 (otmp
->quan
== 1) ? "itself" : "themselves");
239 pline("You now wield %s.", doname(otmp
));
245 else if (otmp
->otyp
== DAGGER
|| otmp
->otyp
== TWO_HANDED_SWORD
||
246 otmp
->otyp
== CRYSKNIFE
||
247 otmp
->otyp
== LONG_SWORD
|| otmp
->otyp
== AXE
) {
249 if ((int) otmp
->spe
<= -3) {
251 pline("Your %s too dull for engraving.",
252 aobjnam(otmp
, "are"));
253 if (oep
&& oep
->engr_type
!= DUST
)
259 if (Levitation
&& type
!= BURN
) { /* riv05!a3 */
260 pline("You can't reach the floor!");
263 if (oep
&& oep
->engr_type
== DUST
) {
264 pline("You wipe out the message that was written here.");
268 if (type
== DUST
&& oep
) {
269 pline("You cannot wipe out the message that is %s in the rock.",
270 (oep
->engr_type
== BURN
) ? "burned" : "engraved");
273 pline("What do you want to %s on the floor here? ",
274 (type
== ENGRAVE
) ? "engrave" : (type
== BURN
) ? "burn" : "write");
282 if (!len
|| *buf
== '\033') {
292 nomovemsg
= "You finished writing.";
295 case ENGRAVE
: /* here otmp != 0 */
297 int len2
= (otmp
->spe
+ 3) * 2 + 1;
299 pline("Your %s dull.", aobjnam(otmp
, "get"));
304 nomovemsg
= "You cannot engrave more.";
306 otmp
->spe
-= len
/ 2;
307 nomovemsg
= "You finished engraving.";
314 len
+= strlen(oep
->engr_txt
) + spct
;
315 ep
= (struct engr
*) alloc((unsigned) (sizeof(struct engr
) + len
+ 1));
316 ep
->nxt_engr
= head_engr
;
320 sp
= (char *) (ep
+ 1); /* (char *)ep + sizeof(struct engr) */
323 (void) strcpy(sp
, oep
->engr_txt
);
324 (void) strcat(sp
, buf
);
327 (void) strcpy(sp
, buf
);
328 ep
->engr_lth
= len
+ 1;
329 ep
->engr_type
= type
;
330 ep
->engr_time
= moves
- multi
;
332 /* kludge to protect pline against excessively long texts */
333 if (len
> BUFSZ
- 20)
340 save_engravings(int fd
)
342 struct engr
*ep
= head_engr
;
344 if (!ep
->engr_lth
|| !ep
->engr_txt
[0]) {
348 bwrite(fd
, &(ep
->engr_lth
), sizeof(ep
->engr_lth
));
349 bwrite(fd
, ep
, sizeof(struct engr
) + ep
->engr_lth
);
352 bwrite(fd
, nul
, sizeof(unsigned));
357 rest_engravings(int fd
)
363 mread(fd
, (char *) <h
, sizeof(unsigned));
366 ep
= (struct engr
*) alloc(sizeof(struct engr
) + lth
);
367 mread(fd
, (char *) ep
, sizeof(struct engr
) + lth
);
368 ep
->nxt_engr
= head_engr
;
369 ep
->engr_txt
= (char *) (ep
+ 1); /* Andreas Bormann */
375 del_engr(struct engr
*ep
)
379 head_engr
= ep
->nxt_engr
;
381 for (ept
= head_engr
; ept
; ept
= ept
->nxt_engr
) {
382 if (ept
->nxt_engr
== ep
) {
383 ept
->nxt_engr
= ep
->nxt_engr
;
387 impossible("Error in del_engr?");