]>
git.cameronkatri.com Git - bsdgames-darwin.git/blob - hack/hack.engrave.c
2 * Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985.
6 static char rcsid
[] = "$Id: hack.engrave.c,v 1.2 1993/08/02 17:17:11 mycroft Exp $";
11 extern char *nomovemsg
;
13 extern struct obj zeroobj
;
15 struct engr
*nxt_engr
;
18 unsigned engr_lth
; /* for save & restore; not length of text */
19 long engr_time
; /* moment engraving was (will be) finished */
27 engr_at(x
,y
) register xchar x
,y
; {
28 register struct engr
*ep
= head_engr
;
30 if(x
== ep
->engr_x
&& y
== ep
->engr_y
)
34 return((struct engr
*) 0);
37 sengr_at(s
,x
,y
) register char *s
; register xchar x
,y
; {
38 register struct engr
*ep
= engr_at(x
,y
);
41 if(ep
&& ep
->engr_time
<= moves
) {
44 if(!strcmp(s,t)) return(1);
48 if(!strncmp(s
,t
,n
)) return(1);
58 if(!u
.uswallow
&& !Levitation
)
59 wipe_engr_at(u
.ux
, u
.uy
, cnt
);
62 wipe_engr_at(x
,y
,cnt
) register xchar x
,y
,cnt
; {
63 register struct engr
*ep
= engr_at(x
,y
);
67 if((ep
->engr_type
!= DUST
) || Levitation
) {
68 cnt
= rn2(1 + 50/(cnt
+1)) ? 0 : 1;
70 lth
= strlen(ep
->engr_txt
);
74 if((ch
= ep
->engr_txt
[pos
]) == ' ')
76 ep
->engr_txt
[pos
] = (ch
!= '?') ? '?' : ' ';
79 while(lth
&& ep
->engr_txt
[lth
-1] == ' ')
80 ep
->engr_txt
[--lth
] = 0;
81 while(ep
->engr_txt
[0] == ' ')
83 if(!ep
->engr_txt
[0]) del_engr(ep
);
87 read_engr_at(x
,y
) register int x
,y
; {
88 register struct engr
*ep
= engr_at(x
,y
);
89 if(ep
&& ep
->engr_txt
[0]) {
90 switch(ep
->engr_type
) {
92 pline("Something is written here in the dust.");
95 pline("Something is engraved here on the floor.");
98 pline("Some text has been burned here in the floor.");
101 impossible("Something is written in a very strange way.");
103 pline("You read: \"%s\".", ep
->engr_txt
);
111 register struct engr
*ep
;
113 if(ep
= engr_at(x
,y
))
116 alloc((unsigned)(sizeof(struct engr
) + strlen(s
) + 1));
117 ep
->nxt_engr
= head_engr
;
121 ep
->engr_txt
= (char *)(ep
+ 1);
122 (void) strcpy(ep
->engr_txt
, s
);
124 ep
->engr_type
= DUST
;
125 ep
->engr_lth
= strlen(s
) + 1;
131 register struct engr
*ep
, *oep
= engr_at(u
.ux
,u
.uy
);
134 int spct
; /* number of leading spaces */
135 register struct obj
*otmp
;
139 pline("You're joking. Hahaha!"); /* riv05!a3 */
143 /* one may write with finger, weapon or wand */
144 otmp
= getobj("#-)/", "write with");
149 if(otmp
&& otmp
->otyp
== WAN_FIRE
&& otmp
->spe
) {
153 /* first wield otmp */
155 if(uwep
&& uwep
->cursed
) {
156 /* Andreas Bormann */
157 pline("Since your weapon is welded to your hand,");
158 pline("you use the %s.", aobjnam(uwep
, (char *) 0));
162 pline("You are now empty-handed.");
163 else if(otmp
->cursed
)
164 pline("The %s %s to your hand!",
165 aobjnam(otmp
, "weld"),
166 (otmp
->quan
== 1) ? "itself" : "themselves");
168 pline("You now wield %s.", doname(otmp
));
176 if(otmp
->otyp
== DAGGER
|| otmp
->otyp
== TWO_HANDED_SWORD
||
177 otmp
->otyp
== CRYSKNIFE
||
178 otmp
->otyp
== LONG_SWORD
|| otmp
->otyp
== AXE
) {
180 if((int)otmp
->spe
<= -3) {
182 pline("Your %s too dull for engraving.",
183 aobjnam(otmp
, "are"));
184 if(oep
&& oep
->engr_type
!= DUST
) return(1);
188 if(Levitation
&& type
!= BURN
){ /* riv05!a3 */
189 pline("You can't reach the floor!");
192 if(oep
&& oep
->engr_type
== DUST
){
193 pline("You wipe out the message that was written here.");
197 if(type
== DUST
&& oep
){
198 pline("You cannot wipe out the message that is %s in the rock.",
199 (oep
->engr_type
== BURN
) ? "burned" : "engraved");
203 pline("What do you want to %s on the floor here? ",
204 (type
== ENGRAVE
) ? "engrave" : (type
== BURN
) ? "burn" : "write");
209 while(*sp
== ' ') spct
++, sp
++;
211 if(!len
|| *buf
== '\033') {
212 if(type
== BURN
) otmp
->spe
++;
221 nomovemsg
= "You finished writing.";
224 case ENGRAVE
: /* here otmp != 0 */
225 { int len2
= (otmp
->spe
+ 3) * 2 + 1;
227 pline("Your %s dull.", aobjnam(otmp
, "get"));
232 nomovemsg
= "You cannot engrave more.";
235 nomovemsg
= "You finished engraving.";
241 if(oep
) len
+= strlen(oep
->engr_txt
) + spct
;
242 ep
= (struct engr
*) alloc((unsigned)(sizeof(struct engr
) + len
+ 1));
243 ep
->nxt_engr
= head_engr
;
247 sp
= (char *)(ep
+ 1); /* (char *)ep + sizeof(struct engr) */
250 (void) strcpy(sp
, oep
->engr_txt
);
251 (void) strcat(sp
, buf
);
254 (void) strcpy(sp
, buf
);
255 ep
->engr_lth
= len
+1;
256 ep
->engr_type
= type
;
257 ep
->engr_time
= moves
-multi
;
259 /* kludge to protect pline against excessively long texts */
260 if(len
> BUFSZ
-20) sp
[BUFSZ
-20] = 0;
265 save_engravings(fd
) int fd
; {
266 register struct engr
*ep
= head_engr
;
268 if(!ep
->engr_lth
|| !ep
->engr_txt
[0]){
272 bwrite(fd
, (char *) & (ep
->engr_lth
), sizeof(ep
->engr_lth
));
273 bwrite(fd
, (char *) ep
, sizeof(struct engr
) + ep
->engr_lth
);
276 bwrite(fd
, (char *) nul
, sizeof(unsigned));
280 rest_engravings(fd
) int fd
; {
281 register struct engr
*ep
;
285 mread(fd
, (char *) <h
, sizeof(unsigned));
287 ep
= (struct engr
*) alloc(sizeof(struct engr
) + lth
);
288 mread(fd
, (char *) ep
, sizeof(struct engr
) + lth
);
289 ep
->nxt_engr
= head_engr
;
290 ep
->engr_txt
= (char *) (ep
+ 1); /* Andreas Bormann */
295 del_engr(ep
) register struct engr
*ep
; {
296 register struct engr
*ept
;
298 head_engr
= ep
->nxt_engr
;
300 for(ept
= head_engr
; ept
; ept
= ept
->nxt_engr
) {
301 if(ept
->nxt_engr
== ep
) {
302 ept
->nxt_engr
= ep
->nxt_engr
;
306 impossible("Error in del_engr?");