There’s now a devel
branch for stuff I’m actively working on (should be better about this for repos that I’ve made pubic). It includes a few new agenda types that’ll end up merged into main
, hopefully:
Search
The Search
agenda tells the NPC, basically, to toss any room they wander into. That is, they try to identify stuff that might need to be interacted with in order to locate something they might be looking for. Currently, that just involves trying to open closed containers, but the agenda has an isSearchable(obj)
method for adding additional logic.
The Search
agenda doesn’t directly do anything, it’s basically just meta-logic for managing the Open
and Unlock
agendas, below.
Specifically, if the search agenda is active and the NPC observes an in-scope openable container that isn’t open, they’ll call the Open
agenda on it.
An Actor
(that is unsing targetEngine
) can be told to start searching by calling actorName.search([something])
where [something]
is essentially used as an ID for the task. Just true
will work if you want it all-or-nothing, or a string ID could be used if multiple things might want to turn on searching and you don’t want the completion of one to possibly stop searching when it wants to continue for some other reason.
Open
If the Open
agenda is active, the actor will attempt to open a targetted openable container if it is in scope. Like Obtain
(and most of the other agendas) this will not cause the actor to seek the container, just attempt to interact with it if they encounter it.
If the container is locked, the agenda will:
- remove the container from its target list
- invoke the
Unlock
agenda with the container as its target.
- invoke the
obtainCustom()
agenda with a filter function that matches plausible keys for the container
Unlock
When the Unlock
agenda the actor will attempt to unlock a container on its target list if:
- it is currently in scope
- the actor is holding a key which is plausible for it (checked using
LockableWithKey.keyIsPlausible()
- the actor hasn’t already tried all plausible keys they’re carrying on the container
If the agenda is successful in unlocking the container, it will add the container back to the Open
agenda.
ObtainCustom
The ObtainCustom
agenda is like the vanilla Obtain
agenda, but instead of matching a specific object, it uses a filter function to determine if an object is a target.
For example, the Open
agenda calls:
getActor().obtainCustom(bind(&matchKey, self, t.target));
…where getActor()
will return the Actor
who owns the agenda, matchKey()
is a method on the Open
agenda, self
is the Open
agenda (so the bind
fucntion will call matchKey()
on the agenda instance), and t.target
is the container the agenda just tried and to open and discovered it was locked.
The Open.matchKey()
method looks like:
matchKey(cont, obj) {
if(!obj.ofKind(Key))
return(nil);
if(obj.getCarryingActor() == getActor())
return(nil);
if(cont.keyIsPlausible(obj))
return(true);
return(nil);
}
…so it returns boolean true
for Key
instances that are plausible for the container that the actor isn’t already carrying.
In Action
The searchTest
demo has a searchable box
which is closed and unlocked, a lockable box
wich is closed and locked, a key
that unlocks the lockable box, and an NPC Alice
that has the Search
agenda. The >FOOZLE
command that starts the agenda:
This demo provides a >FOOZLE command that triggers Alice's searchTest agenda.
Alice's Room
This is Alice's starting room.
You see a searchable box, a lockable box, and a key here.
Alice is here in the conversation ready state.
>foozle
Alice is now searching.
>z
Time passes...
Alice opens the searchable box.
>z
Time passes...
Alice attempts to open the lockable box but it seems to be locked.
>z
Time passes...
Alice takes the key.
>z
Time passes...
Alice unlocks the lockable box.
>z
Time passes...
Alice opens the lockable box.
>z
Time passes...
Alice idles.
>
Still in the devel
branch so there’s probably some bugs. And I want to extend this to handle locked doors as well as containers.
But my overall goal for the WIP is to be able to have the player delegate tasks like “go to the library and find their copy of the Necronomicon” and that kind of thing, and this is decdent-sized chunk of it.