In the previous lecture, we got the nurse to go to the waiting area where the patients will be.
We're now going to match up the nurse with a particular patient so that she can then take them to a
cubicle.
So somehow she needs to know about the patient.
And later down the track, the patient and her need to know about these cubicles over here because that's
where the treatment is going to take place.
So now we have to add in a functionality where we can deal with game objects and not just static game
objects like the ones we've got on an IV mesh, but ones that move around and that will be assigned
dynamically.
So we're going to do that in the world script.
So we need to go back into our go folder, find G World and open it up.
And now we're going to extend the world.
So the world is going to have a private static queue.
Of game objects.
And this first cue that we're creating will be our patience.
Q.
As the patients arrive into the waiting place, they'll put themselves in the queue and then the nurse
can get them out of the queue in order to make them her target location.
So we need to methods down here to work with our queue.
First of all, we need a public void add patient.
Where we pass at the game object P and what that does is to and queue that so patient stopped in Q.
4 p.m..
Now, at some point, we'll also have to remove the patients out of the queue, especially when the
nurse has been assigned to them.
We don't want them assigned to any other nurse, so we will go remove patient.
And in here that's going to do is actually return the first game object in the queue.
So let's make that our game object that it's returning.
And in here it'll be if there is a patient in the queue to get hold of.
So if patients dot count equals zero, then we're going to return null.
Otherwise we're going to return patients.
Do you?
Now, of course, before any of this code is actually going to work on your patient queue, you also
need to initialize it.
So let's go up to the top here and go.
Patient's new queue of game objects.
So game object.
Otherwise we won't be able to put anything in the queue or get anything out of it.
Okay, great.
So save that.
Now we're going to go back in to our action that is injecting the waiting state.
And that was in do we remember?
It's the waiting room.
There it is.
I found it.
Okay.
So here at the same time as we're injecting this waiting state into the world states, we can also add
ourselves or this agent can add himself into the queue.
So it's going to be the well queue instance, dot add patient and it'll be this dot game object.
So it's the game object or the agent that this waiting is particularly on that's going to go into that
queue.
Okay.
So we will save that.
Now, what's the nurse going to do?
Well, we go back to the get patients script and in the.
Pre perform.
So the first thing we do before we start running our plan is to get our target and set our target.
So target's going to equal g world.
Dot instance, dot remove patient and we're going to remove just one.
Of course, we can't get any more.
Then we have to remember to test that we've actually got the target because if we don't have a target
then the pre perform should fail which will make the whole plan fail.
So if target equals null, then we're going to return false.
And that will actually allow that get patient to go back into the queue of goals for the nurse so that
it can plan to do that again rather than continuing if there were other goals that needed to go on with.
So if you return true, then the nurse would actually go ahead and go and do that.
Except I guess that in this case the condition is with the nav mesh and the nurse actually has to be
in the right location.
Okay.
Anyway, so we've got all the code, so let's save that and let's go back to Unity and we'll give this
a go.
All right.
So with those changes made, let's have a look at the nurse now.
We're looking for this target here to change.
I'm just going to select this and hit delete to make it none in there.
And let's press play to watch what happens.
So when the agents come in, they're going to eventually register themselves in the patient queue and
the nurse should get one from there and head over.
Now you'll know that that has occurred because the nurse will end up with a target in here and be able
to go and find that particular patient.
So here we go.
Here comes the agents.
Bang!
There's one in the queue.
The nurse has that target and off the nurse goes into the area.
Now it's still going to look exactly the same as what we had before because the nurse and the patient
do not have any further plans after sort of meeting up.
So when we come back in the next lecture, what we're going to do is extend the plans of the nurse and
the patient so that they make their ways over to a cubicle.