Skip to content

BehaviorCheck ​

Inherits: RefCounted

Phase 4 of the Behaviour tab: what the NPC would really do with a schedule. It asks the navigation the terrain baked (the map of the NPC's size and domain, TerrainNavigationRuntime) for the way between the places of the schedule, and answers with a plan: the walks and waits in order (a timeline), the real paths, the places that cannot be reached, how long one round takes, and the problems found. BehaviorGizmoPlugin draws the plan (paths, red places) and the walker (ghost) at a time of the timeline; BehaviorPanel shows the texts. Nothing here needs an editor object, so it is tested headless with a navigation region made by hand.

Description ​

A plan is a Dictionary: entries the timeline, in order: {"kind": "walk" (path, length, ok), "wait" (position) or "jump" (position: a task of a priority schedule starts from where the NPC is placed), "task": index (-1 = the closing walk back to the start), "start": seconds, "seconds": how long} paths the walks, to draw: {"path", "ok", "task"} bad the places that cannot be walked to problems what is wrong: {"task": index (-1 = the schedule), "level": "error" or "note", "text"} seconds the length of one round; open true when some task takes as long as things take (talking, following, wandering), so the real round is longer known is there baked navigation (without it the walks are straight lines and nothing can be called unreachable)

Methods ​

NPCDefinitiondefinition_of( npc: Node ) static
RIDmap_of( npc: Node3D ) static
floatrun_speed_of( definition: NPCDefinition ) static
boolhas_navigation( map: RID ) static
Dictionaryleg( map: RID, from: Vector3, to: Vector3, near: float = NEAR_GROUND ) static
floatpath_length( path: PackedVector3Array ) static
Dictionarypoint_along( path: PackedVector3Array, distance: float ) static
Dictionaryplan( schedule: TaskSchedule, origin: Vector3, map: RID, run_speed: float, find_target: Callable ) static
Dictionaryghost_at( plan_data: Dictionary, seconds: float ) static
Stringseconds_text( seconds: float, open: bool = false ) static
Dictionarybuild_lines( plan_data: Dictionary, to_local: Callable, ghost: Dictionary = {} ) static
Dictionarycheck_script( script: ModularBehaviorScript, origin: Vector3, map: RID, run_speed: float, find_target: Callable ) static
Arrayreaction_problems( reaction: BehaviorReaction, script: ModularBehaviorScript ) static
Array[Dictionary]uncovered_hours( script: ModularBehaviorScript ) static

Constants ​

  • float NEAR_GROUND = 1.5 - How far from the walkable ground a place may be, in metres, to count as on it
  • float NEAR_LINK = 3.0 - The same for the place of a person or an object (it stands beside the furniture, not on the path)
  • float MEET = 0.75 - How near the end of a path must come to the place it was asked for
  • float WALK_FRACTION = 0.33 - The walking speed, as a fraction of the running speed (NavigationController)
  • float WANDER_SECONDS = 6.0 - The seconds a wander with no time is shown to last
  • float HOUR_STEP = 0.25 - The step of the day the checks of the hours go in, in hours

Method descriptions ​

NPCDefinition definition_of( npc: Node ) ​

The definition of a placed NPC (null when it cannot be found)

RID map_of( npc: Node3D ) ​

The navigation map the NPC walks on: the terrain's map for its size and domain, else the world's own

float run_speed_of( definition: NPCDefinition ) ​

The running speed of an NPC (its definition's Movement Speed, else the default of the core stat), in metres a second. The real speed also follows effects and gear, so the times are "about"

bool has_navigation( map: RID ) ​

Is there baked navigation in the map, and has the map taken it in (a query before the map's first synchronization is an error of the server and answers nothing)

Dictionary leg( map: RID, from: Vector3, to: Vector3, near: float = NEAR_GROUND ) ​

The walk from one place to another: {"path", "reachable", "known", "length", "off_ground"}. Without navigation it is the straight line and "known" is false. near is how far from the walkable ground the end may be

float path_length( path: PackedVector3Array ) ​

No description yet.

Dictionary point_along( path: PackedVector3Array, distance: float ) ​

The place a distance along a path, and the direction it goes there: {"position", "direction"}

Dictionary plan( schedule: TaskSchedule, origin: Vector3, map: RID, run_speed: float, find_target: Callable ) ​

The plan of a schedule for an NPC placed at origin. map is the navigation map (RID() = none), run_speed the running speed, find_target answers with the world position of a unique id (a Vector3, or null when the thing is not in the scene)

Dictionary ghost_at( plan_data: Dictionary, seconds: float ) ​

Where the walker is at a time of the plan (it goes round again when the time is past the end): {"position", "direction", "task", "kind"}, or {} when the plan has nothing in it

String seconds_text( seconds: float, open: bool = false ) ​

The length of one round as text ("40 s", "2 min 5 s"), with "and more" when part of it takes as long as things take

Dictionary build_lines( plan_data: Dictionary, to_local: Callable, ghost: Dictionary = {} ) ​

The lines of a plan: "walk" (the real paths), "bad" (the places that cannot be reached, and a straight line to each from where the walk came), "ghost" (the walker at ghost, a result of ghost_at or {}). to_local turns a world point into the space of the drawing

Dictionary check_script( script: ModularBehaviorScript, origin: Vector3, map: RID, run_speed: float, find_target: Callable ) ​

What is found about a whole script: {"navigation": is there baked navigation, "schedules": [{"seconds", "open", "problems": [{"task", "level", "text"}]}] (one for each schedule), "reactions": [{"problems": [...]}] (one for each reaction), "notes": [texts about the script]}

Array reaction_problems( reaction: BehaviorReaction, script: ModularBehaviorScript ) ​

What is wrong with a reaction: [{"task": -1, "level", "text"}]

Array[Dictionary] uncovered_hours( script: ModularBehaviorScript ) ​

The stretches of the day no schedule is for (the NPC then does its fallback): [{"start", "end"}] in hours. Schedules with other conditions count as being there in their hours