Difference between revisions of "Character Control Script"

From Wolfire Games Wiki
Jump to: navigation, search
m (Controller Script Interface)
m (Functions called from other scripts)
Line 80: Line 80:
 
* [[#WantsToWalkBackwards Function|<code>'''WalkDir WantsToWalkBackwards();'''</code>]]
 
* [[#WantsToWalkBackwards Function|<code>'''WalkDir WantsToWalkBackwards();'''</code>]]
  
Data accessed from other scripts (aschar.as mostly, one call to Execute from the old tutorial level):
+
=== Data accessed from other scripts ===
 +
 
 +
These are accessed by aschar.as mostly. There's only one call to <code>'''movement_object.Execute(...)'''</code> that modifies this data, in the older (no longer used) tutorial level.
  
 
* [[#Situation class|<code>'''Situation situation;'''</code>]]
 
* [[#Situation class|<code>'''Situation situation;'''</code>]]

Revision as of 06:47, 12 January 2018

AI overview

TODO: This page is a work in progress, and I intend to finish it sooner rather than later. I wanted to save my work to make sure it doesn't get lost

AI in Overgrowth is handled with character controllers.

A character controller is a set of responses to events/stimuli that tell the character what physically to do at a given instant in time. It's sort of like a cockpit for an airplane.

Everything a human can do is technically available to an AI implementation, if it's smart enough to figure out how to properly trigger the right action at the right time.

The AI in Overgrowth is implemented using a goal system, and through simulations of sensory input. It makes decisions on what to do at a given moment in time based on its current goal/subgoal, the character's current status, and observations on the environment (sights, sounds).

  • For the player, this control happens in a script Data/Scripts/playercontrol.as
  • For NPCs, this control happens in a script Data/Scripts/enemycontrol.as

There's a layer of logic below the character controller that dictates what the character is physically allowed to do. That logic triggers events and consequences based on what happens to the character, and listens to the inputs from the character controller to direct the character's motion. That layer won't be covered here in detail, though we will talk about the events and control queries that are sent from that layer into the character controller.

  • For both players and NPCs this logic is shared, in a script Data/Scripts/aschar.as

Controller Script Interface

The functions in this control script interface tell the character what to do. If you implement these functions, then you will control the character.

The rest of the details on this page just detail how we chose to drive these functions in the base character controller scripts. You can feel free to drive them in some other way as well.

Functions called from other scripts

These are called both directly (aschar.as) and via execute (the engine, other scripts, peer-to-peer calls)

Data accessed from other scripts

These are accessed by aschar.as mostly. There's only one call to movement_object.Execute(...) that modifies this data, in the older (no longer used) tutorial level.

Goals

The Goal is the current primary motivation for the AI.

Whenever the character is updated, this is consulted first when making decisions on what to do, before the Sub Goal is checked.

List of Goals:

The inital Goal for all AI is Patrolling.

Patrol Goal

This patrol goal is when the character is on the alert, listening for sounds, looking for ally's bodies, and looking for awake enemies to fight.

The inital Goal for all AI is Patrolling, and this is the mode that they will fall back to when they're done in combat.

When Patrol gets set:

  • When the character is first spawned
  • When the character is reset (through the void ResetMind(); function)
  • When the Goal was Attack and the chase target is neutralized, and there are no other targets to pick from
  • When the Goal was Struggle or Hold Still and the character was broken free or was released, while still awake
  • When debug keys are enabled, the C is toggled in the editor, the character was previously not passive, and the character is now being set to to passive, then they will also now be set to patrol
  • When void MindReceiveMessage(string msg); is called for the character, with the message "set_hostile false" (basically when this message is sent to the character with movement_object.RecieveMessage("..."))
  • When the Goal was Investigate
  • When the Goal was Get Help and somehow you no longer have an ally to seek help from (TODO: I don't think this was completely implemented, so it's not clear how this can happen without this goal being switched ahead of this check)
  • When void AIMovementObjectDeleted(int id); is called, and the player had a goal that was focused on the now-deleted character:
    • If the Goal was Get Help and the target ally being sought for help is deleted
    • If the Goal was Investigate and the target being investigated is deleted
    • If the Goal was Escort and the target being escorted is deleted
    • If the Goal was Attack and the chase target is deleted

How Patrol works: TODO: Write this section - or does this get delgated to sub-goals?

How character behaviors are affected by Patrol:

  • int IsUnaware(); returns 1. Other checks are also made, but this always returns 1 if on patrol
  • int IsIdle(); returns 1, otherwise it returns 0
  • string GetIdleOverride(); returns a non-empty value only if the character is on patrol
  • vec3 GetTargetVelocity(); returns waypoint based patrol movement if the character is on patrol, and isn't currently being startled
  • WalkDir WantsToWalkBackwards(); returns WALK_BACKWARDS or STRAFE if the character is on patrol, they don't have a waypoint target, and they get pushed around. If they aren't on patrol, or they have a waypoint target, it returns FORWARDS
  • bool WantsReadyStance(); returns true if the character is not on patrol

Attack Goal

TODO: Write this section

Investigate Goal

TODO: Write this section

Get Help Goal

TODO: Write this section

Escort Goal

TODO: Write this section

Get Weapon Goal

TODO: Write this section

Navigate Goal

TODO: Write this section

Struggle Goal

TODO: Write this section

Hold Still Goal

TODO: Write this section

Flee Goal

TODO: Write this section

Sub Goals

The Sub Goal is the current secondary motivation for the AI. Each goal has an entirely different set of sub-goals, and the sub-goals aren't really shared between goals. It isn't "a second goal", it is like a plan of action to solve the current goal.

Whenever the character is updated, this is consulted second when making decisions on what to do, after the current Goal is checked.

List of Sub Goals:

The inital Sub Goal for all AI is Wait And Attack.

Unknown Sub Goal

TODO: Write this section

Provoke Attack Sub Goal

TODO: Write this section

Avoid Jump Kick Sub Goal

TODO: Write this section

Knock Off Ledge Sub Goal

TODO: Write this section

Wait And Attack Sub Goal

TODO: Write this section

Rush And Attack Sub Goal

TODO: Write this section

Defend Sub Goal

TODO: Write this section

Surround Target Sub Goal

TODO: Write this section

Escape Surround Sub Goal

TODO: Write this section

Investigate Slow Sub Goal

TODO: Write this section

Investigate Urgent Sub Goal

TODO: Write this section

Investigate Body Sub Goal

TODO: Write this section

Investigate Around Sub Goal

TODO: Write this section

Investigate Attack Sub Goal

TODO: Write this section