1 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
2 /* hack.engrave.c - version 1.0.3 */
3 /* $FreeBSD: src/games/hack/hack.engrave.c,v 1.4 1999/11/16 02:57:04 billf Exp $ */
4 /* $DragonFly: src/games/hack/hack.engrave.c,v 1.3 2005/05/22 03:37:05 y0netan1 Exp $ */
9 extern struct obj zeroobj
;
11 struct engr
*nxt_engr
;
14 unsigned engr_lth
; /* for save & restore; not length of text */
15 long engr_time
; /* moment engraving was (will be) finished */
23 engr_at(x
,y
) xchar x
,y
; {
24 struct engr
*ep
= head_engr
;
26 if(x
== ep
->engr_x
&& y
== ep
->engr_y
)
30 return((struct engr
*) 0);
33 sengr_at(s
,x
,y
) char *s
; xchar x
,y
; {
34 struct engr
*ep
= engr_at(x
,y
);
37 if(ep
&& ep
->engr_time
<= moves
) {
40 if(!strcmp(s,t)) return(1);
44 if(!strncmp(s
,t
,n
)) return(1);
54 if(!u
.uswallow
&& !Levitation
)
55 wipe_engr_at(u
.ux
, u
.uy
, cnt
);
58 wipe_engr_at(x
,y
,cnt
) xchar x
,y
,cnt
; {
59 struct engr
*ep
= engr_at(x
,y
);
63 if((ep
->engr_type
!= DUST
) || Levitation
) {
64 cnt
= rn2(1 + 50/(cnt
+1)) ? 0 : 1;
66 lth
= strlen(ep
->engr_txt
);
70 if((ch
= ep
->engr_txt
[pos
]) == ' ')
72 ep
->engr_txt
[pos
] = (ch
!= '?') ? '?' : ' ';
75 while(lth
&& ep
->engr_txt
[lth
-1] == ' ')
76 ep
->engr_txt
[--lth
] = 0;
77 while(ep
->engr_txt
[0] == ' ')
79 if(!ep
->engr_txt
[0]) del_engr(ep
);
83 read_engr_at(x
,y
) int x
,y
; {
84 struct engr
*ep
= engr_at(x
,y
);
85 if(ep
&& ep
->engr_txt
[0]) {
86 switch(ep
->engr_type
) {
88 pline("Something is written here in the dust.");
91 pline("Something is engraved here on the floor.");
94 pline("Some text has been burned here in the floor.");
97 impossible("Something is written in a very strange way.");
99 pline("You read: \"%s\".", ep
->engr_txt
);
109 if(ep
= engr_at(x
,y
))
112 alloc((unsigned)(sizeof(struct engr
) + strlen(s
) + 1));
113 ep
->nxt_engr
= head_engr
;
117 ep
->engr_txt
= (char *)(ep
+ 1);
118 (void) strcpy(ep
->engr_txt
, s
);
120 ep
->engr_type
= DUST
;
121 ep
->engr_lth
= strlen(s
) + 1;
127 struct engr
*ep
, *oep
= engr_at(u
.ux
,u
.uy
);
130 int spct
; /* number of leading spaces */
135 pline("You're joking. Hahaha!"); /* riv05!a3 */
139 /* one may write with finger, weapon or wand */
140 otmp
= getobj("#-)/", "write with");
145 if(otmp
&& otmp
->otyp
== WAN_FIRE
&& otmp
->spe
) {
149 /* first wield otmp */
151 if(uwep
&& uwep
->cursed
) {
152 /* Andreas Bormann */
153 pline("Since your weapon is welded to your hand,");
154 pline("you use the %s.", aobjnam(uwep
, (char *) 0));
158 pline("You are now empty-handed.");
159 else if(otmp
->cursed
)
160 pline("The %s %s to your hand!",
161 aobjnam(otmp
, "weld"),
162 (otmp
->quan
== 1) ? "itself" : "themselves");
164 pline("You now wield %s.", doname(otmp
));
172 if(otmp
->otyp
== DAGGER
|| otmp
->otyp
== TWO_HANDED_SWORD
||
173 otmp
->otyp
== CRYSKNIFE
||
174 otmp
->otyp
== LONG_SWORD
|| otmp
->otyp
== AXE
) {
176 if((int)otmp
->spe
<= -3) {
178 pline("Your %s too dull for engraving.",
179 aobjnam(otmp
, "are"));
180 if(oep
&& oep
->engr_type
!= DUST
) return(1);
184 if(Levitation
&& type
!= BURN
){ /* riv05!a3 */
185 pline("You can't reach the floor!");
188 if(oep
&& oep
->engr_type
== DUST
){
189 pline("You wipe out the message that was written here.");
193 if(type
== DUST
&& oep
){
194 pline("You cannot wipe out the message that is %s in the rock.",
195 (oep
->engr_type
== BURN
) ? "burned" : "engraved");
199 pline("What do you want to %s on the floor here? ",
200 (type
== ENGRAVE
) ? "engrave" : (type
== BURN
) ? "burn" : "write");
205 while(*sp
== ' ') spct
++, sp
++;
207 if(!len
|| *buf
== '\033') {
208 if(type
== BURN
) otmp
->spe
++;
217 nomovemsg
= "You finished writing.";
220 case ENGRAVE
: /* here otmp != 0 */
221 { int len2
= (otmp
->spe
+ 3) * 2 + 1;
223 pline("Your %s dull.", aobjnam(otmp
, "get"));
228 nomovemsg
= "You cannot engrave more.";
231 nomovemsg
= "You finished engraving.";
237 if(oep
) len
+= strlen(oep
->engr_txt
) + spct
;
238 ep
= (struct engr
*) alloc((unsigned)(sizeof(struct engr
) + len
+ 1));
239 ep
->nxt_engr
= head_engr
;
243 sp
= (char *)(ep
+ 1); /* (char *)ep + sizeof(struct engr) */
246 (void) strcpy(sp
, oep
->engr_txt
);
247 (void) strcat(sp
, buf
);
250 (void) strcpy(sp
, buf
);
251 ep
->engr_lth
= len
+1;
252 ep
->engr_type
= type
;
253 ep
->engr_time
= moves
-multi
;
255 /* kludge to protect pline against excessively long texts */
256 if(len
> BUFSZ
-20) sp
[BUFSZ
-20] = 0;
261 save_engravings(fd
) int fd
; {
262 struct engr
*ep
= head_engr
;
264 if(!ep
->engr_lth
|| !ep
->engr_txt
[0]){
268 bwrite(fd
, (char *) & (ep
->engr_lth
), sizeof(ep
->engr_lth
));
269 bwrite(fd
, (char *) ep
, sizeof(struct engr
) + ep
->engr_lth
);
272 bwrite(fd
, (char *) nul
, sizeof(unsigned));
276 rest_engravings(fd
) int fd
; {
281 mread(fd
, (char *) <h
, sizeof(unsigned));
283 ep
= (struct engr
*) alloc(sizeof(struct engr
) + lth
);
284 mread(fd
, (char *) ep
, sizeof(struct engr
) + lth
);
285 ep
->nxt_engr
= head_engr
;
286 ep
->engr_txt
= (char *) (ep
+ 1); /* Andreas Bormann */
291 del_engr(ep
) struct engr
*ep
; {
294 head_engr
= ep
->nxt_engr
;
296 for(ept
= head_engr
; ept
; ept
= ept
->nxt_engr
) {
297 if(ept
->nxt_engr
== ep
) {
298 ept
->nxt_engr
= ep
->nxt_engr
;
302 impossible("Error in del_engr?");