Okay.
So in this video, we've got the inventory set up and we're going to start using it to get the nurse
and the patients to go to the cubicle that have just been assigned.
So create yourself a new C-sharp file and open that up.
Call it, get treated.
And this class here is actually based on the original get patient's code before we modified it.
And you'll see why I've used this in a moment, because it's actually got a few things that are similar
to the target.
We need to get a cubicle.
We don't want to get the cubicle from remove patient or anywhere else.
We're going to get it out of our inventory.
So in here we're going to put inventory, dot, find object with tag and give it our cubicle.
Like that.
And then if we don't have it, of course we're going to return false or otherwise null.
Now what are going to be the post perform in this situation?
What things do we need to set up?
Well, the first thing is that we could actually add a state to the world.
So world thought, instance, dot, get world and dot modify state.
And we're going to add a new state in there called Treated.
And basically, it's just going to count the number of patients who get treated.
It's not going to be used for anything, but you'll be able to see the count going up.
Maybe if you were turning this into a full blown medical simulation, you would be keeping track of
how many patients were actually treated in this particular state.
And therefore you could trigger some of the event, you know, like you get extra budget or you get
an award or whatever.
So it's just another thing that you can keep track of and you can put all sorts of things into that
world, state with values.
Now, once we've been treated well, we have to remove the cubicle so it will go inventory, dot remove
item and we will remove the target from the agents own inventory.
Okay, great.
So save that.
Now we're going to go back into Unity and get the patient drag and drop that new get treated on to the
patient.
So it's one of the tasks now we will call it get treated.
The target we don't need to set up and the preconditions for this.
So if we don't put any preconditions on this, it's something that can be done pretty much straight
away and it can't really be done until you're in the waiting area.
So there need to be some kind of situation that gets triggered to say that we are actually in the waiting
area.
Unfortunately, we can't be looking at the world state for a precondition to being in the waiting area
because every agent that comes in is going to add to the world state.
So there will be some cases when your agent needs to keep a set of its own states.
And that's where the beliefs that I talked about in previous lectures come into play.
So let's go back into our folder.
We'll go into our agent and we'll add in some beliefs.
So let's have a look here.
We've already added in this beliefs structure, but we haven't actually started to use it.
So in order to use it, we need to put some values in there.
Now the action itself is going to want access to the beliefs.
So let's go back into the action.
And just like we put the inventory in there, we're going to add in a public world states beliefs and
then down in the awake we will put beliefs equals this dot get component for the g agent dot beliefs.
All right.
So you can save that script.
Now, let's go into our go to waiting room.
This is where we want to inject a state into the patient's own belief system.
So in here, we'll put beliefs, dot, modify state, and we'll put at hospital.
In their.
So now we can use at hospital as a precondition for that get treatment.
So back in unity on the patient, we will now put a precondition one in there and under the first element
there will put at hospital.
Do make sure that you are spelling these correctly so that they do match.
Now, what's going to be our after effect?
Well, we need to add one at least.
And the after effect, remember, is going to match whatever our goal is.
So for here we're going to put is treated like that.
So this is pretty much a stand alone action all by itself where it's waiting for our hospital to be
triggered.
And then we have this is treated goal.
And you know what that means?
It means we actually have to go back into the patient code to make sure that is treated is in fact one
of its goals.
So let's go in here while we're in here.
I just want to point out this start method and the way I declared it in the now I know in previous videos
I have it as protected override, void, start and that's what you should have in here as well.
You want to have it for all of the classes that derive from the agent class.
So that's going to be the nurse and anything else that you create.
Okay.
So we're going to create another sub.
I'm just going to copy this one and put it under here and we'll put it as two and we will add to and
our treatment is going to be is treated and we will put this at a five because it's more important than
the is waiting even though we can't obviously get to is treated without that happening first.
Okay.
So save that press play and let's have a look at this.
So I've sped up my agents movement and I've also decreased the amount of duration for their actions
so that there's not so much waiting around.
Okay.
So the nurse comes in, gives the cubicle assignment to the patient and nothing happens.
So what's going wrong?
Well, what is going wrong is the at hospital, which is the trigger for our get treated.
So we've got this ad hospital, but where are we injecting it?
Well, you might say, well, we are we are actually injecting it.
We're doing it in the waiting area.
So go to waiting.
We have a look in here.
There it is.
There it's going into the belief system.
But what isn't using the belief system at the moment?
Well, it's the planner.
The plan is not using the belief system.
The planner is only considering the world states.
Now, if you remember right back when we started working on the agent, if we go to the agent here and
we find where the planner is actually created and fires off, which is somewhere down in where are we
late update.
Let's go.
Down, down, down.
The plana is here.
So planner equals new planner.
And then we go.
Planner.
Plan actions.
Our goals.
Now this is where we're sending through our beliefs.
So make sure you put beliefs in here.
Now, this is all well and good, but the actual planner on the other end doesn't have the capability
just yet to do anything with them.
So just save that.
We're going to go back into the actual planner code here.
And at the very top, what we need to do is create an overloaded constructor for our node that will
take in the beliefs as well as the state of the world which is coming through into here.
So let's just grab a copy of that, put it underneath, and then after our all states, we're going
to put in another dictionary.
Let me just copy that.
Put it in there and let's call this belief states.
So that we have the world and the belief states.
Now, this is putting the world states into there.
What we need to do after that is also add in the belief states.
So for each.
Key value pair, which will be a string.
It.
Be in b leaf states if.
Not this dot state dot contains key.
B key.
Then we're going to go ahead and add it.
So this dot state add B dot key and B dot value.
So now you can be assured that you have both things being fed through.
So that means also just another little change is that when we create our very first node that we send
through the world states and the belief state.
So let's go down into our planner where that very first node gets created.
So here is where the first node is getting created and it's getting sent our world states that we're
grabbing here from our singleton.
We've just made an overloaded method that we can send through the states that come from the agent.
Now, when we initially set up our queue creation or our plan creation up here, we allowed for another
set of states to come through, but we were setting that to null.
So these states here are actually the belief states, so let's call them belief states.
And then down here we want to add them in as a parameter.
So I believe states and.
It's going to be dot.
Get states in order to actually return them in the right format for the node.
Now that takes those parameters where we create the other nodes, which is down.
In build graph where it creates more nodes.
You don't need to change this because the world states that are coming through into here are the concatenation
of both sets of states.
And so any other child leaves that get created for our graph are always going to have the concatenation
of those two initial states, the world state and the set of beliefs inside of them.
Right.
Okay.
So let's save that.
And now that we're actually getting our at hospital from somewhere, let's go back into here, press
play and let's take a look at what happens.
So they're going to spawn as before.
Then here they come up to the reception desk and then after they've registered, they'll start making
their way into the writing room.
And that's going to trigger the nurse who'll go across.
So if he comes to their the nurse, once she and him get in the same space as a goal location, he's
going to shuffle off over to the cubicle whilst avoiding the other guys that are coming in.
All right, so that's working really well.
So what I'm going to do now is actually leave it as a challenge for you to try and create a new action
for the nurse that is going to get the nurse to go over to the same cubicle as the patient.
So it's going to involve creating a new action and basically just setting up the correct preconditions
and after effects and put that onto the nurse.
Now, one little clue that I will give you is that we've just created our get treated for our patient.
And the code that you need for your nurse is very similar for her action.
So go ahead and give that a go.
And when we come back in the next video, I'll show you one way to do that.