new Think(owner)
Constructs a new Think object.
Parameters:
Name | Type | Default | Description |
---|---|---|---|
owner |
GameEntity | null | The owner of this instance. |
Extends
Members
-
evaluators :Array.<GoalEvaluator>
-
A list of goal evaluators.
-
nullable owner :GameEntity
-
The owner of this goal.
- Overrides:
- Default Value:
- null
-
status :Status
-
The status of this goal.
- Overrides:
- Default Value:
- INACTIVE
-
subgoals :Array.<Goal>
-
A list of subgoals.
- Overrides:
Methods
-
activate()
-
Executed when this goal is activated.
- Overrides:
-
activateIfInactive() → {Goal}
-
Ensures the goal is activated if it is inactive.
- Overrides:
-
active() → {Boolean}
-
Returns true if the status of this goal is ACTIVE.
Returns:
Boolean -Whether the goal is active or not.
- Overrides:
-
addEvaluator(evaluator) → {Think}
-
Adds the given goal evaluator to this instance.
Parameters:
Name Type Description evaluator
GoalEvaluator The goal evaluator to add.
-
addSubgoal(goal) → {Goal}
-
Adds a goal as a subgoal to this instance.
Parameters:
Name Type Description goal
Goal The subgoal to add.
- Overrides:
-
arbitrate() → {Think}
-
This method represents the top level decision process of an agent. It iterates through each goal evaluator and selects the one that has the highest score as the current goal.
-
clearSubgoals() → {Goal}
-
Removes all subgoals and ensures Goal#terminate is called for each subgoal.
- Overrides:
-
completed() → {Boolean}
-
Returns true if the status of this goal is COMPLETED.
Returns:
Boolean -Whether the goal is completed or not.
- Overrides:
-
currentSubgoal() → {Goal}
-
Returns the current subgoal. If no subgoals are defined, null is returned.
- Overrides:
-
execute()
-
Executed in each simulation step.
- Overrides:
-
executeSubgoals() → {Status}
-
Executes the current subgoal of this composite goal.
Returns:
Status -The status of this composite subgoal.
- Overrides:
-
failed() → {Boolean}
-
Returns true if the status of this goal is FAILED.
Returns:
Boolean -Whether the goal is failed or not.
- Overrides:
-
fromJSON(json) → {Think}
-
Restores this instance from the given JSON object.
Parameters:
Name Type Description json
Object The JSON object.
- Overrides:
-
handleMessage() → {Boolean}
-
Returns true if the given message was processed by the current subgoal.
Returns:
Boolean -Whether the message was processed or not.
- Overrides:
-
hasSubgoals() → {Boolean}
-
Returns true if this composite goal has subgoals.
Returns:
Boolean -Whether the composite goal has subgoals or not.
- Overrides:
-
inactive() → {Boolean}
-
Returns true if the status of this goal is INACTIVE.
Returns:
Boolean -Whether the goal is inactive or not.
- Overrides:
-
registerType(type, constructor) → {Think}
-
Registers a custom type for deserialization. When calling Think#fromJSON this instance is able to pick the correct constructor in order to create custom goals or goal evaluators.
Parameters:
Name Type Description type
String The name of the goal or goal evaluator.
constructor
function The constructor function.
-
removeEvaluator(evaluator) → {Think}
-
Removes the given goal evaluator from this instance.
Parameters:
Name Type Description evaluator
GoalEvaluator The goal evaluator to remove.
-
removeSubgoal(goal) → {Goal}
-
Removes a subgoal from this instance.
Parameters:
Name Type Description goal
Goal The subgoal to remove.
- Overrides:
-
replanIfFailed() → {Goal}
-
Ensures the goal is replanned if it has failed.
- Overrides:
-
resolveReferences(entities) → {CompositeGoal}
-
Restores UUIDs with references to GameEntity objects.
Parameters:
Name Type Description entities
Map.<String, GameEntity> Maps game entities to UUIDs.
- Overrides:
-
terminate()
-
Executed when this goal is satisfied.
- Overrides:
-
toJSON() → {Object}
-
Transforms this instance into a JSON object.
Returns:
Object -The JSON object.
- Overrides: