WEBVTT

00:06.410 --> 00:11.330
In the previous lecture, we got the nurse to go to the waiting area where the patients will be.

00:11.360 --> 00:17.810
We're now going to match up the nurse with a particular patient so that she can then take them to a

00:17.810 --> 00:18.600
cubicle.

00:18.620 --> 00:23.480
So somehow she needs to know about the patient.

00:23.810 --> 00:31.010
And later down the track, the patient and her need to know about these cubicles over here because that's

00:31.010 --> 00:33.590
where the treatment is going to take place.

00:33.860 --> 00:42.200
So now we have to add in a functionality where we can deal with game objects and not just static game

00:42.200 --> 00:47.150
objects like the ones we've got on an IV mesh, but ones that move around and that will be assigned

00:47.270 --> 00:48.620
dynamically.

00:49.070 --> 00:53.540
So we're going to do that in the world script.

00:53.540 --> 00:59.480
So we need to go back into our go folder, find G World and open it up.

00:59.480 --> 01:02.750
And now we're going to extend the world.

01:02.750 --> 01:11.450
So the world is going to have a private static queue.

01:12.660 --> 01:14.520
Of game objects.

01:14.910 --> 01:19.350
And this first cue that we're creating will be our patience.

01:19.350 --> 01:19.920
Q.

01:21.670 --> 01:27.790
As the patients arrive into the waiting place, they'll put themselves in the queue and then the nurse

01:27.790 --> 01:33.350
can get them out of the queue in order to make them her target location.

01:33.370 --> 01:38.460
So we need to methods down here to work with our queue.

01:38.470 --> 01:43.540
First of all, we need a public void add patient.

01:46.190 --> 02:00.080
Where we pass at the game object P and what that does is to and queue that so patient stopped in Q.

02:01.050 --> 02:02.370
4 p.m..

02:03.780 --> 02:08.100
Now, at some point, we'll also have to remove the patients out of the queue, especially when the

02:08.100 --> 02:10.350
nurse has been assigned to them.

02:10.350 --> 02:16.200
We don't want them assigned to any other nurse, so we will go remove patient.

02:19.400 --> 02:27.120
And in here that's going to do is actually return the first game object in the queue.

02:27.140 --> 02:30.080
So let's make that our game object that it's returning.

02:30.320 --> 02:35.540
And in here it'll be if there is a patient in the queue to get hold of.

02:35.570 --> 02:42.650
So if patients dot count equals zero, then we're going to return null.

02:43.760 --> 02:47.540
Otherwise we're going to return patients.

02:48.230 --> 02:49.250
Do you?

02:53.610 --> 02:58.530
Now, of course, before any of this code is actually going to work on your patient queue, you also

02:58.530 --> 02:59.760
need to initialize it.

02:59.760 --> 03:01.710
So let's go up to the top here and go.

03:01.840 --> 03:07.290
Patient's new queue of game objects.

03:07.290 --> 03:09.030
So game object.

03:11.130 --> 03:15.480
Otherwise we won't be able to put anything in the queue or get anything out of it.

03:16.200 --> 03:16.950
Okay, great.

03:16.950 --> 03:17.900
So save that.

03:17.910 --> 03:26.790
Now we're going to go back in to our action that is injecting the waiting state.

03:26.790 --> 03:29.610
And that was in do we remember?

03:29.610 --> 03:32.070
It's the waiting room.

03:32.070 --> 03:32.490
There it is.

03:32.490 --> 03:33.060
I found it.

03:33.060 --> 03:33.450
Okay.

03:33.450 --> 03:41.340
So here at the same time as we're injecting this waiting state into the world states, we can also add

03:41.340 --> 03:45.180
ourselves or this agent can add himself into the queue.

03:45.420 --> 03:55.560
So it's going to be the well queue instance, dot add patient and it'll be this dot game object.

03:55.560 --> 04:03.180
So it's the game object or the agent that this waiting is particularly on that's going to go into that

04:03.180 --> 04:03.780
queue.

04:03.810 --> 04:04.180
Okay.

04:04.200 --> 04:06.030
So we will save that.

04:06.210 --> 04:08.100
Now, what's the nurse going to do?

04:08.100 --> 04:13.560
Well, we go back to the get patients script and in the.

04:14.880 --> 04:16.230
Pre perform.

04:16.230 --> 04:22.680
So the first thing we do before we start running our plan is to get our target and set our target.

04:22.680 --> 04:25.770
So target's going to equal g world.

04:26.460 --> 04:35.540
Dot instance, dot remove patient and we're going to remove just one.

04:35.550 --> 04:37.020
Of course, we can't get any more.

04:37.050 --> 04:41.970
Then we have to remember to test that we've actually got the target because if we don't have a target

04:41.970 --> 04:46.500
then the pre perform should fail which will make the whole plan fail.

04:46.500 --> 04:55.080
So if target equals null, then we're going to return false.

04:55.440 --> 05:03.360
And that will actually allow that get patient to go back into the queue of goals for the nurse so that

05:03.360 --> 05:10.590
it can plan to do that again rather than continuing if there were other goals that needed to go on with.

05:10.590 --> 05:16.200
So if you return true, then the nurse would actually go ahead and go and do that.

05:16.620 --> 05:23.070
Except I guess that in this case the condition is with the nav mesh and the nurse actually has to be

05:23.070 --> 05:24.630
in the right location.

05:24.660 --> 05:25.020
Okay.

05:25.020 --> 05:30.720
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

05:30.720 --> 05:31.500
a go.

05:31.740 --> 05:32.220
All right.

05:32.220 --> 05:34.920
So with those changes made, let's have a look at the nurse now.

05:34.920 --> 05:38.040
We're looking for this target here to change.

05:38.040 --> 05:41.970
I'm just going to select this and hit delete to make it none in there.

05:42.360 --> 05:46.470
And let's press play to watch what happens.

05:46.470 --> 05:54.870
So when the agents come in, they're going to eventually register themselves in the patient queue and

05:54.870 --> 05:58.050
the nurse should get one from there and head over.

05:58.050 --> 06:04.560
Now you'll know that that has occurred because the nurse will end up with a target in here and be able

06:04.560 --> 06:06.810
to go and find that particular patient.

06:06.810 --> 06:08.160
So here we go.

06:08.160 --> 06:10.140
Here comes the agents.

06:10.140 --> 06:10.650
Bang!

06:10.650 --> 06:11.700
There's one in the queue.

06:11.730 --> 06:17.730
The nurse has that target and off the nurse goes into the area.

06:17.970 --> 06:23.490
Now it's still going to look exactly the same as what we had before because the nurse and the patient

06:23.490 --> 06:27.210
do not have any further plans after sort of meeting up.

06:27.210 --> 06:32.640
So when we come back in the next lecture, what we're going to do is extend the plans of the nurse and

06:32.640 --> 06:37.140
the patient so that they make their ways over to a cubicle.
