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
;
31 if (x
== ep
->engr_x
&& y
== ep
->engr_y
)
39 sengr_at(const char *s
, xchar x
, xchar y
)
41 struct engr
*ep
= engr_at(x
, y
);
45 if (ep
&& ep
->engr_time
<= moves
) {
49 if (!strncmp(s
, t
, n
))
60 if (!u
.uswallow
&& !Levitation
)
61 wipe_engr_at(u
.ux
, u
.uy
, cnt
);
65 wipe_engr_at(xchar x
, xchar y
, xchar cnt
)
67 struct engr
*ep
= engr_at(x
, y
);
72 if ((ep
->engr_type
!= DUST
) || Levitation
)
73 cnt
= rn2(1 + 50 / (cnt
+ 1)) ? 0 : 1;
74 lth
= strlen(ep
->engr_txt
);
78 if ((ch
= ep
->engr_txt
[pos
]) == ' ')
80 ep
->engr_txt
[pos
] = (ch
!= '?') ? '?' : ' ';
83 while (lth
&& ep
->engr_txt
[lth
- 1] == ' ')
84 ep
->engr_txt
[--lth
] = 0;
85 while (ep
->engr_txt
[0] == ' ')
93 read_engr_at(int x
, int y
)
95 struct engr
*ep
= engr_at(x
, y
);
97 if (ep
&& ep
->engr_txt
[0]) {
98 switch (ep
->engr_type
) {
100 pline("Something is written here in the dust.");
103 pline("Something is engraved here on the floor.");
106 pline("Some text has been burned here in the floor.");
109 impossible("Something is written in a very strange way.");
111 pline("You read: \"%s\".", ep
->engr_txt
);
116 make_engr_at(int x
, int y
, const char *s
)
120 if ((ep
= engr_at(x
, y
)))
122 ep
= alloc((unsigned)(sizeof(struct engr
) + strlen(s
) + 1));
123 ep
->nxt_engr
= head_engr
;
127 ep
->engr_txt
= (char *)(ep
+ 1);
128 strcpy(ep
->engr_txt
, s
);
130 ep
->engr_type
= DUST
;
131 ep
->engr_lth
= strlen(s
) + 1;
139 struct engr
*ep
, *oep
= engr_at(u
.ux
, u
.uy
);
142 int spct
; /* number of leading spaces */
147 pline("You're joking. Hahaha!"); /* riv05!a3 */
151 /* one may write with finger, weapon or wand */
152 otmp
= getobj("#-)/", "write with");
156 if (otmp
== &zeroobj
)
158 if (otmp
&& otmp
->otyp
== WAN_FIRE
&& otmp
->spe
) {
162 /* first wield otmp */
164 if (uwep
&& uwep
->cursed
) {
165 /* Andreas Bormann */
166 pline("Since your weapon is welded to your hand,");
167 pline("you use the %s.", aobjnam(uwep
, NULL
));
171 pline("You are now empty-handed.");
172 else if (otmp
->cursed
)
173 pline("The %s %s to your hand!",
174 aobjnam(otmp
, "weld"),
175 (otmp
->quan
== 1) ? "itself" : "themselves");
177 pline("You now wield %s.", doname(otmp
));
184 else if (otmp
->otyp
== DAGGER
|| otmp
->otyp
== TWO_HANDED_SWORD
||
185 otmp
->otyp
== CRYSKNIFE
||
186 otmp
->otyp
== LONG_SWORD
|| otmp
->otyp
== AXE
) {
188 if ((int)otmp
->spe
<= -3) {
190 pline("Your %s too dull for engraving.",
191 aobjnam(otmp
, "are"));
192 if (oep
&& oep
->engr_type
!= DUST
)
198 if (Levitation
&& type
!= BURN
) { /* riv05!a3 */
199 pline("You can't reach the floor!");
202 if (oep
&& oep
->engr_type
== DUST
) {
203 pline("You wipe out the message that was written here.");
207 if (type
== DUST
&& oep
) {
208 pline("You cannot wipe out the message that is %s in the rock.",
209 (oep
->engr_type
== BURN
) ? "burned" : "engraved");
213 pline("What do you want to %s on the floor here? ",
214 (type
== ENGRAVE
) ? "engrave" : (type
== BURN
) ? "burn" : "write");
224 if (!len
|| *buf
== '\033') {
235 nomovemsg
= "You finished writing.";
238 case ENGRAVE
: /* here otmp != 0 */
240 int len2
= (otmp
->spe
+ 3) * 2 + 1;
242 pline("Your %s dull.", aobjnam(otmp
, "get"));
247 nomovemsg
= "You cannot engrave more.";
249 otmp
->spe
-= len
/ 2;
250 nomovemsg
= "You finished engraving.";
257 len
+= strlen(oep
->engr_txt
) + spct
;
258 ep
= alloc((unsigned)(sizeof(struct engr
) + len
+ 1));
259 ep
->nxt_engr
= head_engr
;
263 sp
= (char *)(ep
+ 1); /* (char *)ep + sizeof(struct engr) */
266 strcpy(sp
, oep
->engr_txt
);
271 ep
->engr_lth
= len
+ 1;
272 ep
->engr_type
= type
;
273 ep
->engr_time
= moves
- multi
;
275 /* kludge to protect pline against excessively long texts */
276 if (len
> BUFSZ
- 20)
283 save_engravings(int fd
)
285 struct engr
*ep
= head_engr
;
288 if (!ep
->engr_lth
|| !ep
->engr_txt
[0]) {
292 bwrite(fd
, (char *)&(ep
->engr_lth
), sizeof(ep
->engr_lth
));
293 bwrite(fd
, (char *)ep
, sizeof(struct engr
) + ep
->engr_lth
);
296 bwrite(fd
, (char *)nul
, sizeof(unsigned));
301 rest_engravings(int fd
)
308 mread(fd
, (char *)<h
, sizeof(unsigned));
311 ep
= alloc(sizeof(struct engr
) + lth
);
312 mread(fd
, (char *)ep
, sizeof(struct engr
) + lth
);
313 ep
->nxt_engr
= head_engr
;
314 ep
->engr_txt
= (char *)(ep
+ 1); /* Andreas Bormann */
320 del_engr(struct engr
*ep
)
325 head_engr
= ep
->nxt_engr
;
327 for (ept
= head_engr
; ept
; ept
= ept
->nxt_engr
) {
328 if (ept
->nxt_engr
== ep
) {
329 ept
->nxt_engr
= ep
->nxt_engr
;
333 impossible("Error in del_engr?");