The important part to focus on is the first line.

This is where I’m passing in that the AIReason is “Sleep”. The colonist would use a toilet if I passed in “Urinate” instead of “Sleep”.

In the second line I’m creating a new state of “UseObjectForReason”. This state is used wherever a colonist needs to use something.

(I say “colonist” because it’s simpler. In reality, any GameObject Agent could use anything)





Multiple Uses of Same Object

Some objects can be used for multiple purposes.

A chair can be used for sleeping, sitting, and eating.

This poses a minor issue, because a colonist needs to do something slightly different when eating in a chair instead of sleeping in a chair.

To solve this we have to tell every object what its valid “use reason” are and what to do when a colonist uses the object for a specific reason.

So when a chair is used for sleeping we play the colonist sleeping animation. When a chair is used for eating we make the colonist eat. In both cases we make the colonist visually sit in the chair.







Claimable Objects

We don’t want multiple colonists to use the same toilet at the same time. We also don’t want 3 colonists waiting to use the same toilet when other toilets are available.

To solve this issue, colonists “claim” objects the moment that they decide to use them. This prevents any other colonist from using that same object.

The objects become unclaimed once the colonist is finished using them (they’re also unclaimed if the colonist fails to use the toilet, for any reason).

Objects can allow multiple claimers. The Food Counter allows this, so that that up to 5 colonists can wait in line at the same counter.

Minor Issue

A claimed toilet basically doesn’t exist at all to a colonist.

This can pose a problem if all toilets are currently being walked towards, because they’ll all be claimed (even though they all appear to be available). Any additional colonists who needs to urinate will think that no toilets exist and might pee on the floor.

We haven’t implemented a solution to this, but we would have to do something where a colonist can distinguish between an object existing and an object being claimed.

Personally, I don’t think this is necessary. It’s much better to simply make a colonist pee on the floor only when they really need to pee. This would provide the colonist with several opportunities to use a toilet before the floor is ever used.





Conditional Claimable Objects

Objects can conditionally be considered valid by individual colonists.

This is frequently used when a colonist is looking for food.

Meatballs

When a colonist is hungry he might be looking for either “bread” or “meatballs”.

There could be 3 objects with food. All of them are “food objects”, but only the objects with “bread” or “meatballs” should be considered valid.

To solve this, we pass in the food (items) that the colonist is looking for. Each food object checks its own internal container to figure out if it has whatever the colonist wants. (We then have to reserve the items so that another colonist doesn’t take them). Any objects without enough bread or meatballs are consider invalid

Personality, Again

The validity check is performed in both the colonist and the target object. So the colonist can also conditionally consider objects valid. (in the previous example, the food object was determining if it should be valid, the colonist wasn’t making the decision)

A colonist could consider any bed with the color red to be invalid. You could prevent a specific colonist from ever using a specific toilet. Or you could have a fancy colonist that only uses high quality furniture.

Other Examples

I mainly talked about urination, but there are all sorts of Reason-Object relationships

Sleeping