Skip to content

Instantly share code, notes, and snippets.

@realnc
Last active February 10, 2021 09:39
Show Gist options
  • Save realnc/a108e72b827d9e405a899d67b2484222 to your computer and use it in GitHub Desktop.
Save realnc/a108e72b827d9e405a899d67b2484222 to your computer and use it in GitHub Desktop.
#charset "CP1252"
#include <adv3.h>
#include <en_us.h>
/*
* Abstract body part class.
*
* This is not intended for direct use. It's only for inheriting sub-classes
* from it.
*/
// RAB: Most of the code in this file was created by Nikos Chantziaras. 11/8/16
// All I did was to add in a few additiional bodyparts as needed. His comments
// about how everything works are at the bottom of the file. The problem we are
// trying to solve is >x character's head/eyes/feet (or whatever) resulting in
// the response, "you don't see character's head here." What this code does is
// give all the characters generic body parts, and then when we want to handle a
// specific character's head or hands or whatever, we do it in their object
// handling.
class BodyPart: Component {
'' ''
"\^<<theName>> <<isPlural ? "look" : "looks">> normal. "
isProperName = true;
hideFromAll(action)
{
return true;
}
initializeThing()
{
inherited();
// The PC's body parts should not be considered for disambiguation.
if (location && location == gPlayerChar) {
vocabLikelihood = -30;
}
}
dobjFor(Feel)
{
check()
{
failCheck('That would be rude. ');
}
}
}
class Body: BodyPart {
'body'
'<<location.theNamePossAdj>> body'
}
class Nose: BodyPart {
'nose'
'<<location.theNamePossAdj>> nose'
dobjFor(LookIn)
{
check()
{
failCheck('That would be rude. ');
}
}
dobjFor(Pick) asDobjFor(LookIn);
}
class Hair: BodyPart {
'hair'
'<<location.theNamePossAdj>> hair'
dobjFor(Pull)
{
verify() { }
check()
{
failCheck('That would be rude. ');
}
}
}
class NoHair: Unthing {
'hair'
'<<location.theNamePossAdj>> hair'
notHereMsg = '\^<<location.theName>> <<location.verbToHave>> no hair. ';
}
class Fur: BodyPart {
'fur'
'<<location.theNamePossAdj>> fur'
dobjFor(Pull)
{
verify() { }
check()
{
failCheck('That would be cruel. ');
}
}
}
class NoFur: Unthing {
'fur'
'<<location.theNamePossAdj>> fur'
notHereMsg = '\^<<location.theName>> <<location.verbToHave>> no fur. ';
}
class Hands: BodyPart {
'hand/hands'
'<<location.theNamePossAdj>> hands'
isPlural = true;
//>Put hands in/on/under/behind something mapped to Feel, but only if they're the player's hands.
dobjFor(PutOn) maybeRemapTo (isIn(me), Feel, IndirectObject)
dobjFor(PutIn) maybeRemapTo (isIn(me), Feel, IndirectObject)
dobjFor(PutUnder) maybeRemapTo (isIn(me), Feel, IndirectObject)
dobjFor(PutBehind) maybeRemapTo (isIn(me), Feel, IndirectObject)
}
class Feet: BodyPart {
'foot/feet/leg/legs'
'<<location.theNamePossAdj>> feet'
isPlural = true;
}
class NoFeet: Unthing { //For snakes
'foot/feet/leg/legs'
'<<location.theNamePossAdj>> feet'
notHereMsg = '\^<<location.theName>> <<location.verbToHave>> no feet. ';
}
class Beard: BodyPart {
'beard'
'<<location.theNamePossAdj>> beard'
}
class NoBeard: Unthing {
'beard'
'<<location.theNamePossAdj>> beard'
notHereMsg = '\^<<location.theName>> <<location.verbToHave>> no beard. ';
}
class Eyes: BodyPart {
'eye/eyes'
'<<location.theNamePossAdj>> eyes'
isPlural = true;
}
class Head: BodyPart {
'head'
'<<location.theNamePossAdj>> head'
}
class Mouth: BodyPart {
'mouth'
'<<location.theNamePossAdj>> mouth'
}
class Clothes: Wearable {
'clothes'
'<<wornBy.theNamePossAdj>> clothes'
"{You/he} see{s} nothing special about {it dobj/him}. "
willNotLetGoMsg = 'That would be rude. ';
isPlural = true;
isProperName = true;
hideFromAll(action)
{
return isWorn();
}
dobjFor(Doff) asDobjFor(TakeFrom)
dobjFor(Search) {
action () {
"That would be an invasion of privacy. ";
}
}
}
modify Person {
hasBodyParts = true;
hasClothes = true;
body = nil;
nose = nil;
hair = nil;
hands = nil;
feet = nil;
beard = nil;
eyes = nil;
head = nil;
mouth = nil;
clothes = nil;
initializeThing()
{
inherited();
if (hasBodyParts) {
if (!body)
body = Body.createInstance();
body.baseMoveInto(self);
if (!nose)
nose = Nose.createInstance();
nose.baseMoveInto(self);
if (!hair)
hair = Hair.createInstance();
hair.baseMoveInto(self);
if (!hands)
hands = Hands.createInstance();
hands.baseMoveInto(self);
if (!feet)
feet = Feet.createInstance();
feet.baseMoveInto(self);
if (!beard)
beard = NoBeard.createInstance();
beard.baseMoveInto(self);
if (!eyes)
eyes = Eyes.createInstance();
eyes.baseMoveInto(self);
if (!head)
head = Head.createInstance();
head.baseMoveInto(self);
if (!mouth)
mouth = Mouth.createInstance();
mouth.baseMoveInto(self);
}
// The generic clothes are not suitable for the PC. Implement those
// manually in the player character object.
if (hasClothes && self != gPlayerChar) {
if (!clothes)
clothes = Clothes.createInstance();
clothes.baseMoveInto(self);
clothes.makeWornBy(self);
}
}
}
modify Animal {
hasBodyParts = true;
hasClothes = nil;
body = nil;
nose = nil;
fur = nil;
feet = nil;
eyes = nil;
head = nil;
mouth = nil;
clothes = nil;
initializeThing()
{
inherited();
if (hasBodyParts) {
if (!body)
body = Body.createInstance();
body.baseMoveInto(self);
if (!nose)
nose = Nose.createInstance();
nose.baseMoveInto(self);
if (!fur)
fur = Fur.createInstance();
fur.baseMoveInto(self);
if (!feet)
feet = Feet.createInstance();
feet.baseMoveInto(self);
if (!eyes)
eyes = Eyes.createInstance();
eyes.baseMoveInto(self);
if (!head)
head = Head.createInstance();
head.baseMoveInto(self);
if (!mouth)
mouth = Mouth.createInstance();
mouth.baseMoveInto(self);
}
// The generic clothes are not suitable for the PC. Implement those
// manually in the player character object.
if (hasClothes && self != gPlayerChar) {
if (!clothes)
clothes = Clothes.createInstance();
clothes.baseMoveInto(self);
clothes.makeWornBy(self);
}
}
}
DefineTAction(Pick);
VerbRule(Pick)
('pick') singleDobj
: PickAction
verbPhrase = 'pick/picking (what)'
;
modify Thing {
dobjFor(Pick)
{
preCond = [touchObj]
verify()
{
illogical('{You/he} can\'t pick {that dobj/him}. ');
}
}
}
/****
Notes from Nick:
This version will add body parts to all NPCs and the player, and clothes to all NPCs. No clothes for the player.
The properties for the body parts are:
body
nose
hair
hands
feet
beard
eyes
There's just one clothes property:
clothes
It is assumed that everyone has hair but no beard. The absence of hair can be indicated by an object of the NoHair class, and absence of a beard by a NoBeard object. By default, everyone has a Hair object and a NoBeard object, meaning they all have hair and no one has a beard:
X BOB'S HAIR
Bob's hair looks normal.
X BOB'S BEARD
Bob has no beard.
X MY BEARD
You have no beard.
(You should obviously rewrite all the default messages in this file to your liking.)
I didn't go too far with the whole thing, so there's no stuff like "left hand" or "right eye". Also, "hand" is the same as "hands", "foot" the same as "feet", etc.
Like before, if you want to prevent an NPC from having body parts or clothes, you can set that NPC's hasBodyParts and hasClothes property to nil. For example:
ch_jack: Person {
hasClothes = nil;
hasBodyParts = nil;
}
By default these properties are set to true.
If you wanted to make an NPC have no hair, you can replace the default hair object with a NoHair object. The NoHair class (and NoBeard class) are derived from the Unthing class, and thus you set the notHereMsg property as the catch-all message for when the player tries to refer to it. For example, to make Jack bald:
ch_jack: Person {
hair: NoHair {
notHereMsg = 'Jack is completely bald. ';
}
}
Whatever the player tries to do with jack's hair, the game will always print that message.
Note that when overriding generic body parts with custom ones, the default vocabulary words are still there. For example, when implementing a custom nose, you don't need to add 'nose' in the vocabulary. Same for clothes. The word "clothes" is always there by default. For example:
ch_jack: Person {
clothes: Clothes {
'fancy black suit/tuxedo/outfit' 'Jack\'s black suit'
"It looks expensive. "
}
}
Even though "clothes" was not specified in the vocabulary, the game still understands this:
X JACK'S CLOTHES
It looks expensive.
The same goes for body parts; "nose", "hair", etc, are always recognized, even if you didn't specify those words in the vocabulary of your custom object.
Play around with it and let me know what you think.
****/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment