public override LispOperator <TBb> CreateOperator( TBb blackboard, LispParser.Node node, LispParser.ICompiler <TBb> compiler) { LispParser.IdentifierNode identifierNode = node as LispParser.IdentifierNode; if (identifierNode == null) { return(null); } Func <bool> func = blackboard.GetBoolFunction(identifierNode.Value); if (func == null) { return(null); } return(new BlackboardBoolFunction <TBb>(identifierNode.Value, func)); }
protected override TreeTask <TBb> CreateTreeTaskFromParseTree(TBb blackboard, LispParser.MethodNode method, LispParser.ICompiler <TBb> compiler) { throw new NotImplementedException("Not implemented, use NamedCoroutine instead?"); }
public override LispOperator <TBb> CreateOperator(TBb blackboard, LispParser.Node node, LispParser.ICompiler <TBb> compiler) { LispParser.MethodNode methodNode = node as LispParser.MethodNode; if (methodNode == null || methodNode.Identifier.Value != Name) { return(null); } LispMethod <TBb> method = CreateMethod(blackboard, methodNode, compiler); if (method != null) { if (method.GetType() != GetType()) { throw new InvalidOperationException( string.Format( "Expected {0} but compiled to {1}!", TypeHelper.GetFriendlyTypeName(GetType()), TypeHelper.GetFriendlyTypeName(method.GetType()))); } foreach (LispParser.Node child in methodNode.Children) { method.Children.Add((LispOperator <TBb>)compiler.Compile(blackboard, child)); } } return(method); }
public abstract LispOperator <TBb> CreateOperator(TBb blackboard, LispParser.Node node, LispParser.ICompiler <TBb> compiler);
protected override TreeTask <TBb> CreateTreeTaskFromParseTree(TBb blackboard, LispParser.MethodNode method, LispParser.ICompiler <TBb> compiler) { ControlFlowNode <TBb> controlFlowNode = CreateControlFlow(blackboard, method, compiler); if (controlFlowNode == null) { return(null); } foreach (LispParser.Node child in method.Children) { bool handled = child.NamedParamX <LispParser.StringNode>("Name", v => controlFlowNode.Name = v.Value) || child.ParamX <LispParser.MethodNode>(null, v => controlFlowNode.Children.Add((TreeTask <TBb>)compiler.Compile(blackboard, child))); if (!handled) { LispParser.NamedParameterNode named = child as LispParser.NamedParameterNode; if (named != null && named.Identifier.Value == "if") { controlFlowNode.Predicate = ((BehaviourTreeCompiler <TBb>)compiler).LispCompiler.Compile(blackboard, named.Value); if (!(controlFlowNode.Predicate is ICanEvaluateToBool)) { throw new InvalidOperationException( string.Format( "The if predicate must evaluate to a bool, {0} doesn't!", named.Value)); } continue; } throw new InvalidOperationException( string.Format( "Unhandled child {0} on {1}!", child, this)); } } return(controlFlowNode); }
public override LispOperator <TBb> CreateOperator(TBb blackboard, LispParser.Node node, LispParser.ICompiler <TBb> compiler) { LispParser.StringNode stringNode = node as LispParser.StringNode; return(stringNode != null ? new StringConstant <TBb>(stringNode.Value) : null); }
protected override TreeTask <TBb> CreateTreeTaskFromParseTree(TBb blackboard, LispParser.MethodNode method, LispParser.ICompiler <TBb> compiler) { return(new KeepRunning <TBb>()); }
LispParser.ICanCreateFromLispParseTree <TBb> LispParser.ICanCreateFromLispParseTree <TBb> .CreateFromParseTree(TBb blackboard, LispParser.Node node, LispParser.ICompiler <TBb> compiler) { LispParser.MethodNode method = node as LispParser.MethodNode; if (method == null) { return(null); } if (method.MethodName == GetClassName()) { TreeTask <TBb> treeTask = CreateTreeTaskFromParseTree(blackboard, method, compiler); foreach (LispParser.Node child in method.Children) { child.NamedParamX <LispParser.StringNode>("Name", v => treeTask.Name = v.Value); } return(treeTask); } else { return(null); } }
protected override TreeTask <TBb> CreateTreeTaskFromParseTree(TBb blackboard, LispParser.MethodNode method, LispParser.ICompiler <TBb> compiler) { UtilityControlFlowNode <TBb> utilityControlFlowNode = CreateUtilityControlFlow(blackboard, method, compiler); if (utilityControlFlowNode == null) { return(null); } foreach (LispParser.Node child in method.Children) { child.NamedParamX <LispParser.StringNode>("Name", v => utilityControlFlowNode.Name = v.Value); child.ParamX <LispParser.MethodNode>(null, v => utilityControlFlowNode.Children.Add((TaskUtility <TBb>)compiler.Compile(blackboard, child))); } return(utilityControlFlowNode); }
public override LispOperator <TBb> CreateOperator(TBb blackboard, LispParser.Node node, LispParser.ICompiler <TBb> compiler) { LispParser.IdentifierNode identifierNode = node as LispParser.IdentifierNode; return(identifierNode != null && identifierNode.Value == "False" ? new FalseConstant <TBb>() : null); }
public override LispOperator <TBb> CreateOperator(TBb blackboard, LispParser.Node node, LispParser.ICompiler <TBb> compiler) { LispParser.IntegerNode integerNode = node as LispParser.IntegerNode; return(integerNode != null ? new IntConstant <TBb>(integerNode.Value) : null); }
protected override TreeTask <TBb> CreateTreeTaskFromParseTree(TBb blackboard, LispParser.MethodNode method, LispParser.ICompiler <TBb> compiler) { throw new NotImplementedException(); }
protected override TreeTask <TBb> CreateTreeTaskFromParseTree(TBb blackboard, LispParser.MethodNode method, LispParser.ICompiler <TBb> compiler) { throw new InvalidOperationException("Not implemented!"); }
protected override LispMethod <TBb> CreateMethod(TBb blackboard, LispParser.MethodNode methodNode, LispParser.ICompiler <TBb> compiler) { return(new LessThanOrEqualTo <TBb>()); }
protected override TreeTask <TBb> CreateTreeTaskFromParseTree(TBb blackboard, LispParser.MethodNode method, LispParser.ICompiler <TBb> compiler) { DebugLog <TBb> debugLog = new DebugLog <TBb>(null); debugLog.StringComputer = ((BehaviourTreeCompiler <TBb>)compiler).LispCompiler.Compile(blackboard, method.Children[0]); if (!(debugLog.StringComputer is ICanEvaluateToString)) { throw new InvalidOperationException("The string computer must evaluate to a string!"); } return(debugLog); }
protected override UtilityControlFlowNode <TBb> CreateUtilityControlFlow(TBb blackboard, LispParser.MethodNode method, LispParser.ICompiler <TBb> compiler) { return(new UtilitySelector <TBb>()); }
public LispParser.ICanCreateFromLispParseTree <TBb> CreateFromParseTree(TBb blackboard, LispParser.Node node, LispParser.ICompiler <TBb> compiler) { LispParser.MethodNode method = node as LispParser.MethodNode; if (method == null) { throw new InvalidOperationException("Expected BehaviourTree but found: null"); } if (method.MethodName != "BehaviourTree") { throw new InvalidOperationException("Expected BehaviourTree but found: " + method); } BehaviourTree <TBb> behaviourTree = new BehaviourTree <TBb>(null, null); foreach (LispParser.Node child in method.Children) { child.NamedParamX <LispParser.NumberNode>("RunningTaskHysterisis", v => behaviourTree.RunningTaskHysterisis = (int)v.FloatValue); child.NamedParamX <LispParser.StringNode>("Name", v => behaviourTree.Name = v.Value); child.ParamX <LispParser.MethodNode>(null, v => behaviourTree.RootTask = (TreeTask <TBb>)compiler.Compile(blackboard, v)); } return(behaviourTree); }
public LispParser.ICanCreateFromLispParseTree <TBb> CreateFromParseTree(TBb blackboard, LispParser.Node node, LispParser.ICompiler <TBb> compiler) { LispParser.MethodNode method = node as LispParser.MethodNode; if (method == null || method.MethodName != "TaskUtility") { return(null); } TaskUtility <TBb> taskUtility = new TaskUtility <TBb>(null, null); taskUtility.UtilityComputer = ((BehaviourTreeCompiler <TBb>)compiler).LispCompiler.Compile(blackboard, method.Children[0]); if (!(taskUtility.UtilityComputer is ICanEvaluateToFloat)) { throw new InvalidOperationException("The utility computer must evaluate to a float!"); } taskUtility.Task = (TreeTask <TBb>)compiler.Compile(blackboard, method.Children[1]); return(taskUtility); }
protected abstract TreeTask <TBb> CreateTreeTaskFromParseTree(TBb blackboard, LispParser.MethodNode method, LispParser.ICompiler <TBb> compiler);
protected override Decorator <TBb> CreateDecoratorFromParseTree(TBb blackboard, LispParser.MethodNode method, LispParser.ICompiler <TBb> compiler) { RunNTimes <TBb> runNTimes = new RunNTimes <TBb>(null); foreach (LispParser.Node child in method.Children) { child.NamedParamX <LispParser.IntegerNode>("MaxRunTimes", x => runNTimes.MaxRunTimes = x.Value); } return(runNTimes); }
protected override LispMethod <TBb> CreateMethod(TBb blackboard, LispParser.MethodNode methodNode, LispParser.ICompiler <TBb> compiler) { return(new Format <TBb>()); }
protected override TreeTask <TBb> CreateTreeTaskFromParseTree(TBb blackboard, LispParser.MethodNode method, LispParser.ICompiler <TBb> compiler) { Decorator <TBb> decorator = CreateDecoratorFromParseTree(blackboard, method, compiler); if (decorator != null) { if (decorator.GetType() != GetType()) { throw new InvalidOperationException( string.Format( "Expected {0} but compiled to {1}!", TypeHelper.GetFriendlyTypeName(GetType()), TypeHelper.GetFriendlyTypeName(decorator.GetType()))); } decorator.DecoratedTask = (TreeTask <TBb>)compiler.Compile(blackboard, method.Children.OfType <LispParser.MethodNode>().Single()); } return(decorator); }
protected override ControlFlowNode <TBb> CreateControlFlow(TBb blackboard, LispParser.MethodNode method, LispParser.ICompiler <TBb> compiler) { return(new Sequence <TBb>()); }
protected abstract Decorator <TBb> CreateDecoratorFromParseTree(TBb blackboard, LispParser.MethodNode method, LispParser.ICompiler <TBb> compiler);
protected abstract ControlFlowNode <TBb> CreateControlFlow(TBb blackboard, LispParser.MethodNode method, LispParser.ICompiler <TBb> compiler);
protected override Decorator <TBb> CreateDecoratorFromParseTree(TBb blackboard, LispParser.MethodNode method, LispParser.ICompiler <TBb> compiler) { return(new Counter <TBb>(null)); }
LispParser.ICanCreateFromLispParseTree <TBb> LispParser.ICanCreateFromLispParseTree <TBb> .CreateFromParseTree(TBb blackboard, LispParser.Node node, LispParser.ICompiler <TBb> compiler) { return(CreateOperator(blackboard, node, compiler)); }
protected override TreeTask <TBb> CreateTreeTaskFromParseTree(TBb blackboard, LispParser.MethodNode method, LispParser.ICompiler <TBb> compiler) { FixedResultState <TBb> fixedResultState = new FixedResultState <TBb>(ResultState); foreach (LispParser.Node child in method.Children) { child.NamedParamX <LispParser.StringNode>("ResultState", v => fixedResultState.ResultState = (TaskState)Enum.Parse(typeof(TaskState), v.Value)); } return(fixedResultState); }
protected abstract LispMethod <TBb> CreateMethod(TBb blackboard, LispParser.MethodNode methodNode, LispParser.ICompiler <TBb> compiler);
protected override TreeTask <TBb> CreateTreeTaskFromParseTree(TBb blackboard, LispParser.MethodNode method, LispParser.ICompiler <TBb> compiler) { NamedCoroutine <TBb> namedCoroutine = new NamedCoroutine <TBb>(null, null); foreach (LispParser.Node child in method.Children) { LispParser.IdentifierNode identifier = child as LispParser.IdentifierNode; if (identifier != null) { Func <IEnumerator <TaskState> > func = blackboard.GetCoRoutineFunc(identifier.Value); if (func == null) { throw new InvalidOperationException("Unrecognized couroutine creator: " + identifier.Value); } namedCoroutine.NamedCoroutineCreator = new NamedCoroutineCreator(identifier.Value, func); } } return(namedCoroutine); }