3 the next logical funtions describe attributes of objects.
4 (ajar, hinged, opaque, printd, treasr, vessel, wearng)
15 ajar .TRUE. if item is container and is open or unhinged
20 return ((bitset(g
.obj_state
[item
], OPENBT
))
21 || (vessel(item
) && !hinged(item
)));
25 at .TRUE. To tell if player is on either side of a two sided object.
30 if (item
< 1 || item
> MAXOBJ
)
33 return (g
.place
[item
] == g
.loc
|| g
.fixed
[item
] == g
.loc
);
37 athand .TRUE. if item readily reachable
38 it can be lying here, in hand or in open container.
46 contnr
= -g
.place
[item
];
47 aaa
= enclosed(item
) && ajar(contnr
);
49 return ((g
.place
[item
] == g
.loc
) || holding(item
)
50 || (aaa
&& ((g
.place
[contnr
] == g
.loc
)
51 || (toting(item
) && holding(contnr
)))));
55 bitoff turns off (sets to 0) a bit in obj_state word
63 g
.obj_state
[obj
] &= ~val
;
67 biton turns on (sets to 1) a bit in obj_state word
75 g
.obj_state
[obj
] |= val
;
79 bitset .TRUE. if object_state has bit N set
81 boolean
bitset(state
, bit
)
85 return (((state
>> bit
) & 1) == 1);
89 blind .TRUE. if you can't see at this loc, (darkness of glare)
93 return (dark() || (g
.loc
== 200
94 && athand(LAMP
) && (g
.prop
[LAMP
] == 1)));
98 burden .. returns weight of items being carried
100 if obj=0, burden calculates the total weight of the adventurer's burden
101 including everything in all containers (except the boat) that he is
104 if object is a container, calculate the weight of everything inside
105 the container (including the container itself). Since donkey FORTRAN
106 isn't recursive, we will only calculate weight of contained containers
107 one level down. The only serious contained container would be the sack
108 The only thing we'll miss will be filled VS empty bottle or cage.
110 If object isn't a container, return its weight.
119 for (i
= 1; i
< MAXOBJ
; i
++) {
120 if (toting(i
) && (g
.place
[i
] != -BOAT
))
126 temp
= g
.holder
[obj
];
128 sum
+= g
.weight
[temp
];
129 temp
= g
.hlink
[temp
];
137 Routine to carry an object
138 start toting an object, removing it from the list of things
139 at its former location. If object > MAXOBJ ( moving "FIXED"
140 or second loc), then don't change place.
142 void carry(obj
, where
)
148 if (g
.place
[obj
] == -1)
152 if (g
.atloc
[where
] == obj
)
153 g
.atloc
[where
] = g
.link
[obj
];
155 temp
= g
.atloc
[where
];
156 while (g
.link
[temp
] != obj
) {
161 g
.link
[temp
] = g
.link
[obj
];
167 confuz generates some variant of "Don't understand that" message.
186 dark .TRUE. if there is no light here
190 return (!(g
.loc_attrib
[g
.loc
] & LIGHT
) &&
191 (!g
.prop
[LAMP
] || !athand(LAMP
)));
195 Routine to check for presence
202 for (i
= 1; i
< (DWARFMAX
); ++i
)
203 if (g
.dloc
[i
] == g
.loc
)
209 dead .TRUE. if object is now dead
214 return (bitset(g
.obj_state
[obj
], 10));
218 drop Place an object at a given loc, prefixing it onto the atloc list.
220 void drop(obj
, where
)
224 g
.fixed
[obj
- MAXOBJ
] = where
;
226 g
.place
[obj
] = where
;
228 g
.link
[obj
] = g
.atloc
[where
];
229 g
.atloc
[where
] = obj
;
235 destroy Permanently eliminate "object" by moving it to
236 a non-existent location.
246 edible .TRUE. if obj can be eaten.
251 return (bitset(g
.obj_state
[obj
], 7));
255 enclosed .TRUE. If object is inside a container.
257 boolean
enclosed(item
)
260 if (item
< 1 || item
> MAXOBJ
)
263 return (g
.place
[item
] < -1);
267 extract remove "object" from a container.
268 origionally name "remove" but rename to avoid conflict with stdio.h
275 contnr
= -g
.place
[obj
];
277 if (g
.holder
[contnr
] == obj
)
278 g
.holder
[contnr
] = g
.hlink
[obj
];
280 temp
= g
.holder
[contnr
];
281 while (g
.hlink
[temp
] != obj
) {
282 temp
= g
.hlink
[temp
];
286 g
.hlink
[temp
] = g
.hlink
[obj
];
292 forced To tell if a location will causes a forced move.
293 A forced location is one from which he is immediately bounced
294 to another. Normal use is for death (forced to location zero)
295 and for description of journey from on place to another.
300 return ((g
.loc_attrib
[at_loc
] & 10) == 2);
304 here .TRUE. If an item is at location or is being carried.
309 return (g
.place
[item
] == g
.loc
|| toting(item
));
313 hinged .TRUE. If object can be opened or shut.
315 boolean
hinged(object
)
318 return (bitset(g
.obj_state
[object
], 1));
322 holding .TRUE. If the object is being carried in hand.
324 boolean
holding(item
)
327 if (item
< 1 || item
> MAXOBJ
)
330 return (g
.place
[item
] == -1);
336 void insert(obj
, contnr
)
345 temp
= g
.holder
[contnr
];
346 g
.holder
[contnr
] = obj
;
348 g
.place
[obj
] = -contnr
;
352 inside = .TRUE. If location is well within cave
357 return (!outside(loc
) && !portal(loc
));
361 Juggle an object by picking it up and putting it down again,
362 The purpose being to get the object to the front of the chain
373 move(obj
+ MAXOBJ
, j
);
378 Determine liquid in the vessel
385 if ((item
== BOTTLE
) || (item
== CASK
))
386 liquid
= liq2(((int) g
.prop
[item
] >> 1) & 7);
394 Determine type of liquid in vessel
407 return (0); /* empty */
412 Determine liquid at a location
417 return (liq2((int) ((g
.loc_attrib
[loc
] >> 1) & 7)));
421 living .TRUE. If object is living, bear for example
426 return (bitset(g
.obj_state
[obj
], 9));
430 locked .TRUE. if lockable object is locked
435 return (bitset(g
.obj_state
[item
], 4));
439 locks .TRUE. if you can lock this object
444 return (bitset(g
.obj_state
[item
], 3));
448 LOOKIN list contents if obj is a container and is open or transparent.
456 if (vessel(contnr
) && (ajar(contnr
) || !opaque(contnr
))) {
457 temp
= g
.holder
[contnr
];
464 temp
= g
.hlink
[temp
];
472 Routine to move an object
474 void move(obj
, where
)
480 from
= g
.fixed
[obj
- MAXOBJ
];
486 if ((from
> 0) && (from
< MAXOBJ
* 2))
493 noway, generate's some variant of "can't do that" message.
518 opaque .TRUE. If obj is non-transparent container
523 return (bitset(g
.obj_state
[obj
], 6));
527 outsid .TRUE. If location is outside the cave
532 return (bitset(g
.loc_attrib
[loc
], 6));
536 Routine true x% of the time. (x an integer from 0 to 100)
541 return (ranz(100) < x
);
545 plural .TRUE. if object is multiple objects
550 return (bitset(g
.obj_state
[obj
], 13));
554 portal .TRUE. If location is a cave entrance
559 return (bitset(g
.loc_attrib
[loc
], 5));
563 printed .TRUE. If object can be read.
568 return (bitset(g
.obj_state
[obj
], 8));
572 put is the same as move, except it returns a
573 value used to set the negated prop values
574 for the repository objects.
576 int put(obj
, where
, pval
)
577 int obj
, where
, pval
;
580 return ((-1) - pval
);
589 return (rand() % range
);
593 small .TRUE. If object fits in sack or small container
598 return (bitset(g
.obj_state
[obj
], 5));
602 toting .TRUE. If an item is being caried.
607 boolean aaa
, bbb
, ccc
;
608 int contnr
, outer
, outer2
;
610 contnr
= -g
.place
[item
];
611 outer
= -g
.place
[contnr
];
612 outer2
= -g
.place
[outer
];
614 aaa
= holding(contnr
);
615 bbb
= enclosed(contnr
) && holding(outer
);
616 ccc
= enclosed(outer
) && holding(outer2
);
618 return (holding(item
) || (enclosed(item
) && (aaa
|| bbb
|| ccc
)));
622 treasr .TRUE. If object is valuable for points
627 return (bitset(g
.obj_state
[obj
], 14));
631 vessel .TRUE. if object can hold a liquid
636 return (bitset(g
.obj_state
[obj
], 15));
640 wearng .TRUE. If wearing obj
645 return (bitset(g
.obj_state
[item
], WEARBT
));
649 worn .TRUE. if object is being worn
654 return (bitset(g
.obj_state
[obj
], 11));
657 static char *e_msg
[] = {
658 "message line > 70 characters", /* 00 */
659 "null line in message", /* 01 */
660 "too many words of messages", /* 02 */
661 "too many travel options", /* 03 */
662 "too many vocabulary words", /* 04 */
663 "required vocabulary word not found", /* 05 */
664 "too many rtext or mtext messages", /* 06 */
665 "too many hints", /* 07 */
666 "location has loc_attrib bit being set twice", /* 08 */
667 "invalid section number in database", /* 09 */
668 "out of order locs or rspeak entries.", /* 10 */
669 "illegal motion word in travel table", /* 11 */
670 "** unused **.",/* 12 */
671 "unknown or illegal word in adjective table.", /* 13 */
672 "illegal word in prep/obj table", /* 14 */
673 "too many entries in prep/obj table", /* 15 */
674 "object has condition bit set twice", /* 16 */
675 "object number too large", /* 17 */
676 "too many entries in adjective/noun table.", /* 18 */
677 "** unused **.",/* 19 */
678 "special travel (500>l>300) exceeds goto list", /* 20 */
679 "ran off end of vocabulary table", /* 21 */
680 "verb class (n/1000) not between 1 and 3", /* 22 */
681 "intransitive action verb exceeds goto list", /* 23 */
682 "transitive action verb exceeds goto list", /* 24 */
683 "conditional travel entry with no alternative", /* 25 */
684 "location has no travel entries", /* 26 */
685 "hint number exceeds goto list", /* 27 */
686 "invalid month returned by date function", /* 28 */
687 "action verb 'leave' has no object.", /* 29 */
688 "preposition found in unexpected table", /* 30 */
689 "received an unexpected word terminator from a1toa5", /* 31 */
690 "trying to put a container into itself (tricky!)", /* 32 */
691 "unknown word class in getwds", /* 33 */
692 "** unused **.",/* 34 */
693 "trying to carry a non-existent object"}; /* 35 */
701 if (n
< 36 && *e_msg
[n
] != '*')
702 fprintf(stderr
, "Fatal error, probable cause: %s\n", e_msg
[n
]);
704 fprintf(stderr
, "Fatal error number %d - Unused error number!\n", n
);
705 panic((char *) 0, TRUE
);
709 Prompt for input, strip leading and trailing spaces,
710 return &buf[first non-whitespace].
711 Does not return if end of input.
714 ask(prompt
, buf
, buflen
)
718 fputs(prompt
, stdout
);
720 if (!fgets(buf
, buflen
, stdin
))
721 panic("end of input", FALSE
);
724 char *end
= buf
+ strlen(buf
);
726 /* Skip to end of line */
727 while ((c
= getchar()) != '\n' && c
!= EOF
);
728 while (*buf
&& isspace(*buf
))
730 while (buf
<= --end
&& isspace(*end
))
740 void panic(msg
, save
)
744 fprintf(stderr
, "\nPANIC: %s%s\n",
745 msg
? msg
: "", save
? ". Save..." : msg
? "" : "aborting.");
747 saveadv("advpanic.sav");