All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.badlogic.gdx.ai.btree.BranchTask Maven / Gradle / Ivy

There is a newer version: 1.8.2
Show newest version
/*******************************************************************************
 * Copyright 2014 See AUTHORS file.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 ******************************************************************************/

package com.badlogic.gdx.ai.btree;

import com.badlogic.gdx.ai.btree.annotation.TaskConstraint;
import com.badlogic.gdx.utils.Array;

/** A branch task defines a behavior tree branch, contains logic of starting or running sub-branches and leaves
 * 
 * @param  type of the blackboard object that tasks use to read or modify game state
 * 
 * @author implicit-invocation
 * @author davebaol */
@TaskConstraint(minChildren = 1)
public abstract class BranchTask extends Task {

	/** The children of this branch tansk. */
	protected Array> children;

	/** Create a branch task with no children */
	public BranchTask () {
		this(new Array>());
	}

	/** Create a branch task with a list of children
	 * 
	 * @param tasks list of this task's children, can be empty */
	public BranchTask (Array> tasks) {
		this.children = tasks;
	}

	@Override
	protected int addChildToTask (Task child) {
		children.add(child);
		return children.size - 1;
	}

	@Override
	public int getChildCount () {
		return children.size;
	}

	@Override
	public Task getChild (int i) {
		return children.get(i);
	}

	@Override
	protected Task copyTo (Task task) {
		BranchTask branch = (BranchTask)task;
		if (children != null) {
			for (int i = 0; i < children.size; i++) {
				branch.children.add(children.get(i).cloneTask());
			}
		}

		return task;
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy