CompositeGoal(owner)

Class representing a composite goal. Essentially it's a goal which consists of subgoals.

new CompositeGoal(owner)

Constructs a new composite goal.

Parameters:
Name Type Default Description
owner GameEntity null

The owner of this composite goal.

Author:

Extends

Members

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.

Methods

activate()

Executed when this goal is activated.

Overrides:

activateIfInactive() → {Goal}

Ensures the goal is activated if it is inactive.

Returns:
Goal -

A reference to this goal.

Overrides:

active() → {Boolean}

Returns true if the status of this goal is ACTIVE.

Returns:
Boolean -

Whether the goal is active or not.

Overrides:

addSubgoal(goal) → {Goal}

Adds a goal as a subgoal to this instance.

Parameters:
Name Type Description
goal Goal

The subgoal to add.

Returns:
Goal -

A reference to this goal.

clearSubgoals() → {Goal}

Removes all subgoals and ensures Goal#terminate is called for each subgoal.

Returns:
Goal -

A reference to this goal.

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.

Returns:
Goal -

The current subgoal.

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.

failed() → {Boolean}

Returns true if the status of this goal is FAILED.

Returns:
Boolean -

Whether the goal is failed or not.

Overrides:

fromJSON(json) → {Goal}

Restores this instance from the given JSON object.

Parameters:
Name Type Description
json Object

The JSON object.

Returns:
Goal -

A reference to this goal.

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.

inactive() → {Boolean}

Returns true if the status of this goal is INACTIVE.

Returns:
Boolean -

Whether the goal is inactive or not.

Overrides:

removeSubgoal(goal) → {Goal}

Removes a subgoal from this instance.

Parameters:
Name Type Description
goal Goal

The subgoal to remove.

Returns:
Goal -

A reference to this goal.

replanIfFailed() → {Goal}

Ensures the goal is replanned if it has failed.

Returns:
Goal -

A reference to this goal.

Overrides:

resolveReferences(entities) → {CompositeGoal}

Restores UUIDs with references to GameEntity objects.

Parameters:
Name Type Description
entities Map.<String, GameEntity>

Maps game entities to UUIDs.

Returns:
CompositeGoal -

A reference to this composite goal.

Overrides:

terminate()

Executed when this goal is satisfied.

Overrides:

toJSON() → {Object}

Transforms this instance into a JSON object.

Returns:
Object -

The JSON object.

Overrides: