I have a location which contains two path objects, leading in different directions. Fictionally, they are a single object, and I want them to be treated as a single object for most commands. However, for travel commands such as FOLLOW and TAKE, they need to be treated as a separate objects, since they lead to different destinations. So, for instance, X PATH should simply give the description of either path, without disambiguation, but FOLLOW PATH should ask which path the player means.
I tried giving them an isEquivalent method which returns nil if the current action is a travel-type action, and true otherwise. But even though the method appears to be returning the correct result, the game is now treating them as equivalent for all actions. Can anyone tell me what is wrong with my code, or suggest a better alternative approach?
[code]/* Make the two middle parts of the path equivalent. /
class PathMiddle: Fixture
* treat the middle two paths as equivalent unless trying to travel by
* one of them
if (gActionIn(Enter, Follow, GoThrough, Take, LookThrough, TravelVia))
By default, equivalence checks the name of the items as well as
isEquivalent. For the middle paths, skip that bit.
if (a.ofKind(PathMiddle) && b.ofKind(PathMiddle))
return !(a.isEquivalent && b.isEquivalent);
return inherited(a, b);
‘north n path (to) (the) n/north/path’
‘path to the north’
‘south s path (to) (the) south/s/path’
‘path to the south’
(In my actual code, PathMiddle is a subclass of PathPassage, which handles all the travel-related code, but I’ve made it a fixture here to make the code easier to run on its own.)