Thursday, April 14, 2011

The Companion Mind

Got a post to the NCCS file entry this morning, asking about whether it was okay to change companion classes; what it would do, et cetera, et al, and yea; other pretentious psuedo-Latin on my part as well!

Now, if you're the author of said comment, relax. This isn't going to be one of my mocking posts.

Reading the comment, the thought occurred to me just how little most players understand how classes and companion behavior in general work in New Vegas (and the other Gamebryo games as well) so I thought I'd take everyone on a little tour.

Hands and feet inside at all times; no flash photography, and any injuries you receive are not the legal nor fiscal responsibility of NosCo, Inc. Don't make me release the NosCo Legal Department (which is primarily made up of demons with automatic weaponry, just for the record).

First of all, probably... eighty to ninety percent of companion NPC behavior is controlled by a combination of their currently running package, and the AI settings. The AI settings are fairly straightforward. Aggression, bravery, energy, warn/attack radius, assistance.

Aggression is exactly that. Normal (unaggressive) NPCs only fight to defend themselves. They will also fight to defend their friends and/or allies, if you've set their assistance value to allow it. NPCs set to help no one will never defend another character. Aggressive NPCs will attack known enemies (as determined by their factions) on detection. Imagine it as the NPC seeing the red tick on their radar, and taking the fight to the enemy as soon as possible. Very Aggressive NPCs attack on sight anything that is not a friend - the filthy Neutrals were probably planing something, anyway. Frenzied NPCs are batshit psycho; and attack everything that isn't themselves. These settings apply at all times, regardless of the package type running. Aggressive NPCs will still attempt to kick the holy living shit out of any enemies who appear, even if they're having lunch at the time. Energy actually does very little. It controls how often a sandboxing NPC gets bored, and goes to do another task. Warn/attack settings are used in the guard package; and specify a radius that the NPC will attack any trespasser they detect inside of.

Packages give the NPC a general idea of what they should be doing at the time. Call it a purpose in life. Purposes include things like following someone, eating, sleeping, traveling between two points, guarding an area, and "sandbox". Sandbox is a general "day to day life" package; that includes wandering, eating, sleeping, and doing general stuff. For a companion, the two most common packages are follow and sandbox. Everything else tends to be special purpose. Following is exactly that; their purpose in life is to stay within the specified distance of you. Sandboxing will have them live an illusion of a normal life. Wandering a cell, sleeping, eating, using idle markers (note here: anytime you see an NPC do something while standing up other than walking or combat, odds are good it's an idle marker - a special marker that tells the NPC to play a specific set of idle animations). While following, sandboxing, whatever; remember that the AI settings still apply. If following you, and a character appears who is part of a faction that is flagged as an enemy of the companion, odds are good they'll attack - independent of whether the character is considered an enemy to you.

As you might have guessed, Factions also play a role in NPC behavior. A few factions are hard-coded in the engine - there's one that has the NPC play "general idle animations" at all times (you can see this one in NCCS, since I add it to all my companions, as well as the templates; it makes them seem more alive, by scratching, picking their noses, fidgeting, and just generally doing small random stuff that most of us do in day to day life; the other hard coded faction is a no-combat faction, and is intended for characters who are not to engage in combat under any circumstances. Needless to say, I don't use that last one. Most factions are simply what one might call "clubs" - like when you were a kid. Clubs have friends, and they have enemies; and joining one forces you to abide by those affiliations. Actually, street-gang might be a more apt analogy... but I think I'll stick with clubs, since it seems a bit more innocent, and less like your companions will later be indicted on drug-smuggling charges. (It wasn't me, honest! I was just a lookout! The others were the ones smuggling Buffout to the boyscout troop!)

Now, thus far we've looked at what you might call autonomic functions. Things like package, AI data, and Factions tell the AI engine how to make a character behave in the absence of specific instructions. Think of it as automatic behavior; things that require no further input on your - or anyone else's - part. There's another type of behavior: the specific.

Specific behavior is controlled by scripts, and trumps all others when the script runs. This, of course, is the script attached to the NPC themselves - what I call the Companion Script. Quest scripting can also apply; but is less efficient for a number of reasons, and is not widely used for behavior.

For modders like me, the Companion Script is where the magic is. It's what separates "just another companion" from "holy fuck this is so cool!" These scripts can be as complex or as simple as the author likes. Some specific behavior that you normally see would be not letting the companion engage in to-the-death combat with the player. A block of specific behavior that I personally like, is the self-healing code - that is, the NPC will heal themselves with stimpaks when they get wounded or crippled. Bethsoft's devs are fond of having their companions fully heal via magic every time combat ends.

One of the specific behaviors I added for Lillian was that whenever she begins her "at home" package, she takes off her stealth suit, and puts on a set of normal clothes. When the sleep package kicks in, the other clothes come off, and a nighty goes on. 'Cause really, who wants to sleep in stealth armor?

The companion script is also where other types of behavior live; like stopping combat, and going to heal the player when they're wounded beyond a certain point. I've recently worked out the code for automatic switching of combat styles on the fly; to make the NPC "decide" how to fight at a certain time, or in a specific situation.

Really, if you can imagine it - and the engine has a function to accomplish it - you can get your companion to do it with their on-board script. If you wanted to (and had the appropriate idle animations from a third party) you could set up a companion to automatically engage you in a celebratory tumble every time combat ended. Note I've never actually tried that; but I know enough about the scripting involved to know it could be done - inconvenient though it would doubtless prove once the novelty wore off.

Lastly, we come to the Class. Why did I save the class for last? Because it has almost nothing to do with behavior. Class influences one thing, and one thing only about NPC behavior: which weapon they'll equip first if they have more than one. This effect is caused by the tag skills: normally, an NPC equips the weapon that they can do the most damage with first - and that is determined by the relevant weapon skill; which is in turn determined by whether it's a tag skill or not. Beyond determining which skills get point-preference, the class determines whether an NPC is willing to offer services - whether they'll buy/sell, repair, and train. Note, I don't think FO3/NV actually use the train function anymore; but it was widely used in Oblivion. Outside of that, Class is really only good for one thing: linking to a combat style; because the engine doesn't have a check for which combat style is running, you can "link" the two, and set up your scripting that if the NPC is using a melee class, they should be switched to a melee style, and so forth.

And that, boys and girls, is how your companion "thinks". Of course, some instances will result in one part being more or less important than I've stated - based on your own creation techniques and scripting style and all - but this is a pretty good outline, at least as I've experienced NPC behavior since starting up modding for CM in late '06/early '07.

7 comments:

  1. Thanks for posting that. As a potential modder, that was rather helpful to know. Mind you, I think you more or less said all this in your RR Companions tutorial, but I'd have to re-read it to know for sure. *shrugs*

    Isn't NosCo's leagle department dominated by red headed demons?

    ReplyDelete
  2. I've touched on most of it; in the explanations for various settings, but not gone into as much detail.

    "Isn't NosCo's leagle department dominated by red headed demons? "

    Dominated is probably the right word. I just leave Maeva in charge of legal complaints.

    Though, for the record: nearly all the NPCs created for my own use are redheads, so yeah...

    ReplyDelete
  3. Aside from the part about the redheads, the NosCo Legal Department sounds a lot like a less censored version of the Legal Firm Wolfram & Hart...

    ReplyDelete
  4. What was that sound?

    Oh, right; it was the sound of a joke zipping over my head.

    Off I go to Google, I suppose...

    ReplyDelete
  5. "Wolfram & Hart, Attorneys at Law is a fictional international, and interdimensional law firm featured in the television series Angel, as well as other extended materials in Joss Whedon's Buffyverse."

    Ah, that would do it.

    Never made it through a single episode of Angel. Didn't watch Buffy beyond that first movie.

    The forced angst crap always got on my nerves.

    ReplyDelete
  6. Thanks for explaining all this stuff, I've recently become interested in modding and the AI stuff is particularly interesting to me. Much appreciated.

    ReplyDelete

Note: Only a member of this blog may post a comment.