1 /* Copyright (c) Stichting Mathematisch Centrum, Amsterdam, 1985. */
2 /* hack.engrave.c - version 1.0.3 */
6 extern char *nomovemsg;
8 extern struct obj zeroobj;
10 struct engr *nxt_engr;
13 unsigned engr_lth; /* for save & restore; not length of text */
14 long engr_time; /* moment engraving was (will be) finished */
22 engr_at(x,y) register xchar x,y; {
23 register struct engr *ep = head_engr;
25 if(x == ep->engr_x && y == ep->engr_y)
29 return((struct engr *) 0);
32 sengr_at(s,x,y) register char *s; register xchar x,y; {
33 register struct engr *ep = engr_at(x,y);
36 if(ep && ep->engr_time <= moves) {
39 if(!strcmp(s,t)) return(1);
43 if(!strncmp(s,t,n)) return(1);
53 if(!u.uswallow && !Levitation)
54 wipe_engr_at(u.ux, u.uy, cnt);
57 wipe_engr_at(x,y,cnt) register xchar x,y,cnt; {
58 register struct engr *ep = engr_at(x,y);
62 if((ep->engr_type != DUST) || Levitation) {
63 cnt = rn2(1 + 50/(cnt+1)) ? 0 : 1;
65 lth = strlen(ep->engr_txt);
69 if((ch = ep->engr_txt[pos]) == ' ')
71 ep->engr_txt[pos] = (ch != '?') ? '?' : ' ';
74 while(lth && ep->engr_txt[lth-1] == ' ')
75 ep->engr_txt[--lth] = 0;
76 while(ep->engr_txt[0] == ' ')
78 if(!ep->engr_txt[0]) del_engr(ep);
82 read_engr_at(x,y) register int x,y; {
83 register struct engr *ep = engr_at(x,y);
84 if(ep && ep->engr_txt[0]) {
85 switch(ep->engr_type) {
87 pline("Something is written here in the dust.");
90 pline("Something is engraved here on the floor.");
93 pline("Some text has been burned here in the floor.");
96 impossible("Something is written in a very strange way.");
98 pline("You read: \"%s\".", ep->engr_txt);
106 register struct engr *ep;
108 if(ep = engr_at(x,y))
111 alloc((unsigned)(sizeof(struct engr) + strlen(s) + 1));
112 ep->nxt_engr = head_engr;
116 ep->engr_txt = (char *)(ep + 1);
117 (void) strcpy(ep->engr_txt, s);
119 ep->engr_type = DUST;
120 ep->engr_lth = strlen(s) + 1;
126 register struct engr *ep, *oep = engr_at(u.ux,u.uy);
129 int spct; /* number of leading spaces */
130 register struct obj *otmp;
134 pline("You're joking. Hahaha!"); /* riv05!a3 */
138 /* one may write with finger, weapon or wand */
139 otmp = getobj("#-)/", "write with");
144 if(otmp && otmp->otyp == WAN_FIRE && otmp->spe) {
148 /* first wield otmp */
150 if(uwep && uwep->cursed) {
151 /* Andreas Bormann */
152 pline("Since your weapon is welded to your hand,");
153 pline("you use the %s.", aobjnam(uwep, (char *) 0));
157 pline("You are now empty-handed.");
158 else if(otmp->cursed)
159 pline("The %s %s to your hand!",
160 aobjnam(otmp, "weld"),
161 (otmp->quan == 1) ? "itself" : "themselves");
163 pline("You now wield %s.", doname(otmp));
171 if(otmp->otyp == DAGGER || otmp->otyp == TWO_HANDED_SWORD ||
172 otmp->otyp == CRYSKNIFE ||
173 otmp->otyp == LONG_SWORD || otmp->otyp == AXE) {
175 if((int)otmp->spe <= -3) {
177 pline("Your %s too dull for engraving.",
178 aobjnam(otmp, "are"));
179 if(oep && oep->engr_type != DUST) return(1);
183 if(Levitation && type != BURN){ /* riv05!a3 */
184 pline("You can't reach the floor!");
187 if(oep && oep->engr_type == DUST){
188 pline("You wipe out the message that was written here.");
192 if(type == DUST && oep){
193 pline("You cannot wipe out the message that is %s in the rock.",
194 (oep->engr_type == BURN) ? "burned" : "engraved");
198 pline("What do you want to %s on the floor here? ",
199 (type == ENGRAVE) ? "engrave" : (type == BURN) ? "burn" : "write");
204 while(*sp == ' ') spct++, sp++;
206 if(!len || *buf == '\033') {
207 if(type == BURN) otmp->spe++;
216 nomovemsg = "You finished writing.";
219 case ENGRAVE: /* here otmp != 0 */
220 { int len2 = (otmp->spe + 3) * 2 + 1;
222 pline("Your %s dull.", aobjnam(otmp, "get"));
227 nomovemsg = "You cannot engrave more.";
230 nomovemsg = "You finished engraving.";
236 if(oep) len += strlen(oep->engr_txt) + spct;
237 ep = (struct engr *) alloc((unsigned)(sizeof(struct engr) + len + 1));
238 ep->nxt_engr = head_engr;
242 sp = (char *)(ep + 1); /* (char *)ep + sizeof(struct engr) */
245 (void) strcpy(sp, oep->engr_txt);
246 (void) strcat(sp, buf);
249 (void) strcpy(sp, buf);
250 ep->engr_lth = len+1;
251 ep->engr_type = type;
252 ep->engr_time = moves-multi;
254 /* kludge to protect pline against excessively long texts */
255 if(len > BUFSZ-20) sp[BUFSZ-20] = 0;
260 save_engravings(fd) int fd; {
261 register struct engr *ep = head_engr;
263 if(!ep->engr_lth || !ep->engr_txt[0]){
267 bwrite(fd, (char *) & (ep->engr_lth), sizeof(ep->engr_lth));
268 bwrite(fd, (char *) ep, sizeof(struct engr) + ep->engr_lth);
271 bwrite(fd, (char *) nul, sizeof(unsigned));
275 rest_engravings(fd) int fd; {
276 register struct engr *ep;
280 mread(fd, (char *) <h, sizeof(unsigned));
282 ep = (struct engr *) alloc(sizeof(struct engr) + lth);
283 mread(fd, (char *) ep, sizeof(struct engr) + lth);
284 ep->nxt_engr = head_engr;
285 ep->engr_txt = (char *) (ep + 1); /* Andreas Bormann */
290 del_engr(ep) register struct engr *ep; {
291 register struct engr *ept;
293 head_engr = ep->nxt_engr;
295 for(ept = head_engr; ept; ept = ept->nxt_engr) {
296 if(ept->nxt_engr == ep) {
297 ept->nxt_engr = ep->nxt_engr;
301 impossible("Error in del_engr?");