Pages

Thursday, May 17, 2012

CAs and You!

So what is CA?

CA stands for Cellular Automata. More often, they are called “smells”, although this is somewhat of a misnomer, since light, nutrients, and water are not exactly smells, but since the majority of CAs are smells, the name sticks anyway.

CAs, sadly, are not easily perceived by the player, and as a result, we often forget completely about them while developing or even just setting up a creature habitat. I’m writing this stuff up to help bring awareness to how CAs are used in the game, how creatures perceive them, and how important it is that we design our agents and metarooms with the proper flow of CAs in mind.

CAs are Room Values!

Look at the map of the room below:


Each of those little sections, those little boxes, is called a room. The lines that divide them are known as doors. Even though they don’t really look like rooms or doors as we know them, that is how they are referred to, so just keep that in mind as you read the rest of this article.

CAs are not little invisible agents that waft around the ship like bacteria. They are actually numerical values calculated and stored in each room. One room might have a CA 8 (fat) smell value of 0.65, and the room next to it might have a CA 8 value of 0.55. CA values range from 0 to 1.

If you want to know the value of a certain CA in a certain room, first make sure you can see you room map by entering “dmap 1” in the caos command line. Center the hand in the room you want to check and enter the following: “outv prop grap mopx mopy #” replacing the “#” with a number from 0 to 19, depending on the CA you are testing for. Hitting enter should return a decimal value for the CA.

In the screens below, I’ve created labels to monitor the CA value of protein in each room. I’ve removed all other sources of protein smell in the world, so the only agent producing the smell are the lemons in the top left. As you can see, the CA concentration is the strongest where the lemons are sitting, and gets to be less and less as the rooms get further away. Even down at the bottom of the workshop, the CA exists, meaning a creature can sense it and follow it.


CAOS Note: Lemons don’t smell like lemons just because they’re classified as fruit! To make an agent “smelly” you have to use the EMIT command in the creation script-- the same place in the script you set your ATTR, BHVR, and other agent settings. The EMIT command is structured as such: emit [CA number] [amount]. The amount ranges from 0 to 1, so you might use 0.05 to give your agent a mild scent, or 0.9 for a very strong smell. You can actually set EMIT to a number even higher than 1, but the increase is very minimal.

How Creatures Use CAs

The classic Creatures IQ Test is the most common example of how exactly creatures use CAs to find their way around.

Creature brains already know from the start that protein smell is linked to fruit-- this is defined when the world is created using the CACL command, it’s not something they need to learn. And most creatures are born with an instinct to find fruit when they are hungry for protein. Once a creature decides to go looking for fruit, a combination of brain and action scripts take over.

The brain starts by checking the room the creature is in, and the rooms around it. It then decides which room has the highest CA value. If that room is to the left or right, a creature will simply walk that direction, but if that direction is up or down, the creature will start to feel very “low down” or “high up”, which will trigger its instincts to push or pull lifts to get moving in the direction with the higher CA. Similarly, if the CA is higher in a room that the creature can’t access by walking, it will start feeling “trapped” and feel inclined to push doors.



So in short, for a creature to pass a classic IQ test, it needs to:

- Be hungry.
- Understand that food (or fruit or seeds) will satisfy its hunger.
- Decide that finding food is more important than pushing the training dummy, taking a nap, smashing the lift button repeatedly, running into walls, etc.
- Be able to detect smells
- Understand that pushing lifts will satisfy its “need to go up” drive
- Understand that pushing doors will satisfy its “need to exit/trapped” drive.
- Not have any pose or gait mutations that might prevent it from traveling properly.

Primarily, creatures use CAs to find food. Creatures will also follow them to find their way home. This is most commonly seen in pregnant norns, who will often feel homesick and try to make their way back to the heating pan or incubator, where the hidden “norn home” (CA 15) emitter is located. Ettins will also make use of this, following the CA to “ettin home” (CA 17) when they are carrying a gadget (which they might have sought out by following the CA for “gadget” (18). CAs play a few other roles here and there, for example “norn” (12) CA generally makes grendels angry.

How other agents use CAs

While creatures use CAs for navigation, there are some plants and animals that rely on CAs as well. CA 3 (moisture) and CA 4 (nutrients) are sometimes required for certain plants to grow. The seed might check the room that it lands in, and if the CA levels aren’t high enough, it will just rot away instead of sprouting. Moisture might be added by little raindrops that, upon hitting the ground, add a little CA 3 into the room they land in. CA 4 might be added by decaying food; essentially compost. Similarly, some critters might require certain light or heat levels to reproduce or for eggs to hatch.

But this is all very agent-specific-- many third-party plants and critters especially don’t rely on CAs in part because many third-party metarooms don’t use emitters. These days, having an agent that requires certain CAs to function tends to really cripple where it can be used.

Overall, CA requirements for agents can potentially add a lot of complexity and interest to the game, but it requires a lot of knowledge about exactly what the agents require. In a room of CA-requiring agents, you might want to be careful about planting too many flowers that require lots of nutrients, lest they deplete the soil and your fruit-bearing plants are unable to grow. You might have to worry about watering the soil regularly, or throwing apple cores over it. The more CA requirements an agent has, the more restrictions there are on where it can thrive.

Often, when it comes to customizing, it’s easier to just ignore CA requirements and script in a form of population control, limiting where your plants sprout by room-type instead of CAs, so your species will thrive whether or not a room has proper emitters. But if you want to include this sort of interesting complexity into your agents, it’s important to specify to players what CAs they need, so the player knows to provide them in one way or another, whether by placing them in a room with emitters, creating their own emitters, or using other CA-altering agents.

CAOS Notes: Creating emitters is very easy. The code goes something like this:

new: simp 1 1 [species] "blank" 0 0 0
emit [CA number] [amount]
mvto [x] [y]


That’s it. Let’s say I want to be really mean and make a protein smell emitter to confuse my creatures. I might enter “new: simp 1 1 12345 "blank" 0 0 0 emit 6 0.5 mvto mopx mopy”.

This would create an invisible agent where the hand was that constantly emitted protein/fruit smell. Creatures would come from all over looking for fruit, and find nothing, and get very confused. So I wouldn’t recommend using it for fruit smell, but you might use it to emit light or heat, whatever the agents in the room might require.

But let’s say you don’t want to create an agent that emits a CA forever-- let’s say you just want to give the room a one-time boost of a certain CA, like how fruit might give the soil a little bit of nutrients as it decays. For this, you would use the ALTR command:

ALTR [Room ID] [CA number] [amount]

The room ID will probably be the room that the agent is sitting, in which case you can use “room targ” or “room ownr” in place of the room ID. If you’re running this from the CAOS command line, you can just use “room pntr” to use the room the hand is hovering over.

Amount in this case goes from -1 to 1, depending on if you want to subtract or add some amount of CA from the room.

Now, one thing to note is that ALTR doesn’t work on “smell” CAs that creatures use for navigation; it only works on CAs 0-5. If you need to alter the other CA of a room, you can use PROP, a command with the same function of ALTR, but instead of adding or subtracting the number specified, it sets that CA level in that room to exactly the number specified.

How CAs Travel

Now, we know what causes a CA value to exist at all, but what affects how CAs travel from one room to another?

Just a moment ago, we mentioned that ALTR works on some CAs, but not others. It works on heat, water, light, and other CAs that do not represent smells. Actual smell-based CAs are called “navigable” CAs by the game, presumably meaning that they are CAs creatures can follow to find their way to food sources or other objects of desire.

The interesting thing is that while non-navigable CAs can travel freely in all directions, navigable CAs only travel to the left and right.

For the purposes of demonstration, I have removed CA links from this room. Note how the grendel smell will only travel from left to right, and ignore rooms above and below:


Why do navigable CAs work like this? Doesn't it make more sense that smells would travel through all rooms?  Well, to us, yes, but you have to remember that we're dealing with not-so-bright creatures.
Again, for purposes of demonstration, I have set the pink and white grazer to emit a non-navigable CA that can travel anywhere. But let's say that was a protein smell, and poor Disastrous Plantation wanted to get to it? She would feel a pretty painfully stabbing desire to go up once she reached the open air, and have no way to get there. Maybe she would travel a bit more to the left to take the lift there, but she would just walk off the edge of the cliff trying to get to the grazer, getting increasingly more confused.

So for the sake of the creatures, it is better that smells only naturally travel in the directions that creatures can walk, and the rest be controlled by CA links.

CA links are very critical part of navigation for creatures, but not all third party metarooms include them, meaning you need to set them up manually to ensure your creatures can thrive.

As an example, here we see that there is a bounty of food right above Herria. But since smell CAs do not pass vertically through rooms, without CA links, she'll never be able to smell the food right above her.

CAOS Notes: Setting up a CA link is actually very easy. The syntax is as follows:

LINK [room1] [room2] [perm]

Room1 and Room2  are the room numbers you want to link. Getting these numbers is easy-- using Shift+Ctrl+R will produce the number of the room the hand is currently in right next to the hand:
 As shown, the room numbers we want to link here are 839 and 855. The perm is easy-- for most CA links, it is set to 1, to let all CAs flow freely between the link. Setting it to 0.5 would only let about half the CA amounts through the link, and so on.

So once we enter our command, "LINK 839 855 1" ... Herria can suddenly smell something delicious above her, and does not hesitate even a second to take the lift up to where the fragrant food awaits! As you can see by the tags, the CA smell has spread out into the rooms below.

CA links are also used to connect different metarooms together by creating a link between the rooms that the doors are located in; this way the creatures can smell what's on the other side of the door.

CA links are not just useful for linking up metarooms though-- creating links between rooms where elevines reside will encourage creatures to use them as well. Just remember that you are creating a link between two rooms, not two agents, and if you move the elevine, you'll need to break the old link (by running the command again with the perm set to zero) and create a new one, if you want to avoid some very confused creatures wondering where that smell is coming from!

Room Types and CAs

There's one more important thing to know about CAs, and that's how room types affect them. Room types are not just to determine if plants should grow or if fish should swim-- each type of room treats each CA differently. Consider the chart below:


Gain determines how much of the CA is absorbed from emitters in the room, Loss is how much of the CA dissipates into nothingness, and Diffusion controls how much of the CA flows over into other rooms.

Here you can see that soil-type rooms are really the only ones that can hold onto nutrient CAs, and CA smells travel much more easily through hard surface areas than through soil.

The variations between room types are subtle, but one special type of room to note is "Ettin Home," which is very much like a standard walkway with one huge exception-- it doesn't carry absorb gadget smell from gadgets in the room. This strange mechanism basically ensures that once ettins bring gadgets home to add to their hoard, they don't smell them anymore, meaning they can still pick up the subtle smells of other gadgets further away on the ship and hunt them down.

These relationships between CAs and Room Types can be altered with the RATE command, but you want to be careful what you do, because changes in CA rates will affect your whole world. Perhaps the most common CA rate modification available is Moe's Heat in Water transfer, which changes the rates to allow...well, heat to travel through water.

Wow... well, that about wraps up what I've learned about CAs over the past several weeks! I hope this clears up a lot of questions and misunderstandings about CAs, and hopefully makes the world an easier place for norns to find their way around. If you have any questions or comments or corrections, feel free to leave them below! And stay tuned for the release of a few Magic Words commands that will make managing your world's CA links a lot easier, I hope!

5 comments:

  1. Awesome post, Amai! I'm one of those people who had absolutely no idea what CAs were prior to this article... I couldn't even tell you what CA stood for! Although lengthy, you touched on pretty much everything possible and made CAs seem much easier to understand. The CAOS codes to control them don't seem too crazy, but some Magic Words commands would be amazing! I have a feeling I might have a grand ol' time coding an entire world to make sure CAs were emitted and linked properly. Thanks for putting this together: I think it will be very handy to anyone looking for a reference on CAs!

    ReplyDelete
  2. About time someone wrote an article about this. Hopefully, the amount of metarooms being made without proper CA links should decrease now. Provided this article gets enough attention, that is.

    ReplyDelete
  3. Finally, a comprehensive guide to using CAs. Even better, some CAOS to play with for those who can't code entire rooms!

    Grendelman is right, this stuff needs to be given heaps of attention. The number of amazing rooms or agents I've had to push to one side due to mixed up or non-existant CAs...well it's probably most of them :(

    I'll definitely be linking my blog to this post. The more advertising it gets the better.

    ReplyDelete
  4. Fantastic article! :D

    This could also mention that you can't make an object EMIT more than 1 CA at a time - for rotting detritus such as the apple cores, which emit moisture and nutrients, they use ALTR.

    It could also mention the bootstrap files "z_agent smells.cos" and "z_DS agent smells.cos" control which CA are linked to which objects - so they can be edited if you want to, for example, make flower scent associated with plants and flowers (but in order to get flower smell into your world, you'll need to edit your plant cos files to make it so). They can also be used as a developer's reference for 'what CA is linked to what object in everyone's worlds?'

    It's great to see all of the burgeoning interest and knowledge about CA set out and explained (with pictures! :D) like this. Thanks! :D

    ReplyDelete
  5. One note about CA linking, you can't actually rely on the room numbers themselves as they're variable. This code is more effective:

    // room 1
    setv va00 grap xcoord ycoord
    // room 2
    setv va01 grap xcoord ycoord
    link va00 va01 1

    That will work regardless of what room numbers they are. :)

    ReplyDelete