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.4 2006/08/21 19:45:32 pavalos 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 */
22 static struct engr
*engr_at(xchar
, xchar
);
23 static void del_engr(struct engr
*);
26 engr_at(xchar x
, xchar y
)
28 struct engr
*ep
= head_engr
;
30 if(x
== ep
->engr_x
&& y
== ep
->engr_y
)
34 return((struct engr
*) 0);
38 sengr_at(const char *s
, xchar x
, xchar y
)
40 struct engr
*ep
= engr_at(x
,y
);
43 if(ep
&& ep
->engr_time
<= moves
) {
47 if(!strncmp(s
,t
,n
)) return(1);
57 if(!u
.uswallow
&& !Levitation
)
58 wipe_engr_at(u
.ux
, u
.uy
, cnt
);
62 wipe_engr_at(xchar x
, xchar y
, xchar cnt
)
64 struct engr
*ep
= engr_at(x
,y
);
68 if((ep
->engr_type
!= DUST
) || Levitation
) {
69 cnt
= rn2(1 + 50/(cnt
+1)) ? 0 : 1;
71 lth
= strlen(ep
->engr_txt
);
75 if((ch
= ep
->engr_txt
[pos
]) == ' ')
77 ep
->engr_txt
[pos
] = (ch
!= '?') ? '?' : ' ';
80 while(lth
&& ep
->engr_txt
[lth
-1] == ' ')
81 ep
->engr_txt
[--lth
] = 0;
82 while(ep
->engr_txt
[0] == ' ')
84 if(!ep
->engr_txt
[0]) del_engr(ep
);
89 read_engr_at(int x
, int y
)
91 struct engr
*ep
= engr_at(x
,y
);
92 if(ep
&& ep
->engr_txt
[0]) {
93 switch(ep
->engr_type
) {
95 pline("Something is written here in the dust.");
98 pline("Something is engraved here on the floor.");
101 pline("Some text has been burned here in the floor.");
104 impossible("Something is written in a very strange way.");
106 pline("You read: \"%s\".", ep
->engr_txt
);
111 make_engr_at(int x
, int y
, const char *s
)
115 if((ep
= engr_at(x
,y
)))
118 alloc((unsigned)(sizeof(struct engr
) + strlen(s
) + 1));
119 ep
->nxt_engr
= head_engr
;
123 ep
->engr_txt
= (char *)(ep
+ 1);
124 strcpy(ep
->engr_txt
, s
);
126 ep
->engr_type
= DUST
;
127 ep
->engr_lth
= strlen(s
) + 1;
135 struct engr
*ep
, *oep
= engr_at(u
.ux
,u
.uy
);
138 int spct
; /* number of leading spaces */
143 pline("You're joking. Hahaha!"); /* riv05!a3 */
147 /* one may write with finger, weapon or wand */
148 otmp
= getobj("#-)/", "write with");
153 if(otmp
&& otmp
->otyp
== WAN_FIRE
&& otmp
->spe
) {
157 /* first wield otmp */
159 if(uwep
&& uwep
->cursed
) {
160 /* Andreas Bormann */
161 pline("Since your weapon is welded to your hand,");
162 pline("you use the %s.", aobjnam(uwep
, (char *) 0));
166 pline("You are now empty-handed.");
167 else if(otmp
->cursed
)
168 pline("The %s %s to your hand!",
169 aobjnam(otmp
, "weld"),
170 (otmp
->quan
== 1) ? "itself" : "themselves");
172 pline("You now wield %s.", doname(otmp
));
180 if(otmp
->otyp
== DAGGER
|| otmp
->otyp
== TWO_HANDED_SWORD
||
181 otmp
->otyp
== CRYSKNIFE
||
182 otmp
->otyp
== LONG_SWORD
|| otmp
->otyp
== AXE
) {
184 if((int)otmp
->spe
<= -3) {
186 pline("Your %s too dull for engraving.",
187 aobjnam(otmp
, "are"));
188 if(oep
&& oep
->engr_type
!= DUST
) return(1);
192 if(Levitation
&& type
!= BURN
){ /* riv05!a3 */
193 pline("You can't reach the floor!");
196 if(oep
&& oep
->engr_type
== DUST
){
197 pline("You wipe out the message that was written here.");
201 if(type
== DUST
&& oep
){
202 pline("You cannot wipe out the message that is %s in the rock.",
203 (oep
->engr_type
== BURN
) ? "burned" : "engraved");
207 pline("What do you want to %s on the floor here? ",
208 (type
== ENGRAVE
) ? "engrave" : (type
== BURN
) ? "burn" : "write");
213 while(*sp
== ' ') spct
++, sp
++;
215 if(!len
|| *buf
== '\033') {
216 if(type
== BURN
) otmp
->spe
++;
225 nomovemsg
= "You finished writing.";
228 case ENGRAVE
: /* here otmp != 0 */
229 { int len2
= (otmp
->spe
+ 3) * 2 + 1;
231 pline("Your %s dull.", aobjnam(otmp
, "get"));
236 nomovemsg
= "You cannot engrave more.";
239 nomovemsg
= "You finished engraving.";
245 if(oep
) len
+= strlen(oep
->engr_txt
) + spct
;
246 ep
= (struct engr
*) alloc((unsigned)(sizeof(struct engr
) + len
+ 1));
247 ep
->nxt_engr
= head_engr
;
251 sp
= (char *)(ep
+ 1); /* (char *)ep + sizeof(struct engr) */
254 strcpy(sp
, oep
->engr_txt
);
259 ep
->engr_lth
= len
+1;
260 ep
->engr_type
= type
;
261 ep
->engr_time
= moves
-multi
;
263 /* kludge to protect pline against excessively long texts */
264 if(len
> BUFSZ
-20) sp
[BUFSZ
-20] = 0;
270 save_engravings(int fd
)
272 struct engr
*ep
= head_engr
;
274 if(!ep
->engr_lth
|| !ep
->engr_txt
[0]){
278 bwrite(fd
, (char *) & (ep
->engr_lth
), sizeof(ep
->engr_lth
));
279 bwrite(fd
, (char *) ep
, sizeof(struct engr
) + ep
->engr_lth
);
282 bwrite(fd
, (char *) nul
, sizeof(unsigned));
287 rest_engravings(int fd
)
293 mread(fd
, (char *) <h
, sizeof(unsigned));
295 ep
= (struct engr
*) alloc(sizeof(struct engr
) + lth
);
296 mread(fd
, (char *) ep
, sizeof(struct engr
) + lth
);
297 ep
->nxt_engr
= head_engr
;
298 ep
->engr_txt
= (char *) (ep
+ 1); /* Andreas Bormann */
304 del_engr(struct engr
*ep
)
308 head_engr
= ep
->nxt_engr
;
310 for(ept
= head_engr
; ept
; ept
= ept
->nxt_engr
) {
311 if(ept
->nxt_engr
== ep
) {
312 ept
->nxt_engr
= ep
->nxt_engr
;
316 impossible("Error in del_engr?");