private void LoadActionParams(BotActionDesc action, object[] args, MyPerTreeBotMemory botMemory) { for (int i = 0; i < args.Length; i++) { var arg = args[i]; if (arg is Boxed <MyStringId> && action.ParametersDesc.ContainsKey(i)) { var parameterDesc = action.ParametersDesc[i]; Boxed <MyStringId> stringId = arg as Boxed <MyStringId>; MyBBMemoryValue value = null; if (botMemory.TryGetFromBlackboard(stringId, out value)) { if (value == null || value.GetType() == parameterDesc.Item1) { action.ActionParams[i] = value; } else { Debug.Assert(false, "Mismatch of types in the blackboard. Did you use a wrong identifier?"); action.ActionParams[i] = null; } } } else { action.ActionParams[i] = arg; } } }
private void SaveActionParams(BotActionDesc action, object[] args, MyPerTreeBotMemory botMemory) { foreach (var key in action.ParametersDesc.Keys) { MyStringId stringId = args[key] as Boxed <MyStringId>; botMemory.SaveToBlackboard(stringId, action.ActionParams[key] as MyBBMemoryValue); } }
public void PerformPostAction(IMyBot bot, MyStringId actionId) { BotActionDesc desc = this.m_actions[actionId]; if (desc != null) { desc.PostAction(bot); } }
private void SaveActionParams(BotActionDesc action, object[] args, MyPerTreeBotMemory botMemory) { foreach (int num in action.ParametersDesc.Keys) { MyStringId id = (MyStringId)(args[num] as VRage.Boxed <MyStringId>); if (((MyMemoryParameterType)action.ParametersDesc[num].Item2) != MyMemoryParameterType.IN) { botMemory.SaveToBlackboard(id, action.ActionParams[num] as MyBBMemoryValue); } } }
private void LoadActionParams(BotActionDesc action, object[] args, MyPerTreeBotMemory botMemory) { MyBBMemoryValue value2; int index = 0; goto TR_000F; TR_0001: index++; TR_000F: while (true) { if (index >= args.Length) { return; } object obj2 = args[index]; if ((obj2 is VRage.Boxed <MyStringId>) && action.ParametersDesc.ContainsKey(index)) { MyTuple <Type, MyMemoryParameterType> tuple = action.ParametersDesc[index]; VRage.Boxed <MyStringId> boxed = obj2 as VRage.Boxed <MyStringId>; value2 = null; if (!botMemory.TryGetFromBlackboard <MyBBMemoryValue>((MyStringId)boxed, out value2)) { action.ActionParams[index] = null; goto TR_0001; } else if ((value2 != null) && ((value2.GetType() != tuple.Item1) || (((MyMemoryParameterType)tuple.Item2) == MyMemoryParameterType.OUT))) { bool flag1 = value2.GetType() != tuple.Item1; action.ActionParams[index] = null; goto TR_0001; } break; } else { action.ActionParams[index] = obj2; } goto TR_0001; } action.ActionParams[index] = value2; goto TR_0001; }
public void AddAction(MyStringId actionId, MethodInfo methodInfo, bool returnsRunning, Func <IMyBot, object[], MyBehaviorTreeState> action) { if (!this.m_actions.ContainsKey(actionId)) { this.AddBotActionDesc(actionId); } BotActionDesc desc = this.m_actions[actionId]; ParameterInfo[] parameters = methodInfo.GetParameters(); desc._Action = action; desc.ActionParams = new object[parameters.Length]; desc.ParametersDesc = new Dictionary <int, MyTuple <Type, MyMemoryParameterType> >(); desc.ReturnsRunning = returnsRunning; for (int i = 0; i < parameters.Length; i++) { BTMemParamAttribute customAttribute = parameters[i].GetCustomAttribute <BTMemParamAttribute>(true); if (customAttribute != null) { desc.ParametersDesc.Add(i, new MyTuple <Type, MyMemoryParameterType>(parameters[i].ParameterType.GetElementType(), customAttribute.MemoryType)); } } }
public MyBehaviorTreeState PerformAction(IMyBot bot, MyStringId actionId, object[] args) { BotActionDesc action = this.m_actions[actionId]; if (action == null) { return(MyBehaviorTreeState.ERROR); } MyPerTreeBotMemory currentTreeBotMemory = bot.BotMemory.CurrentTreeBotMemory; if (action.ParametersDesc.Count == 0) { return(action._Action(bot, args)); } if (args == null) { return(MyBehaviorTreeState.FAILURE); } this.LoadActionParams(action, args, currentTreeBotMemory); this.SaveActionParams(action, args, currentTreeBotMemory); return(action._Action(bot, action.ActionParams)); }
private void SaveActionParams(BotActionDesc action, object[] args, MyPerTreeBotMemory botMemory) { foreach (var key in action.ParametersDesc.Keys) { MyStringId stringId = args[key] as Boxed<MyStringId>; var parameterDesc = action.ParametersDesc[key]; if(parameterDesc.Item2 != MyMemoryParameterType.IN) botMemory.SaveToBlackboard(stringId, action.ActionParams[key] as MyBBMemoryValue); } }
private void LoadActionParams(BotActionDesc action, object[] args, MyPerTreeBotMemory botMemory) { for (int i = 0; i < args.Length; i++) { var arg = args[i]; if (arg is Boxed<MyStringId> && action.ParametersDesc.ContainsKey(i)) { var parameterDesc = action.ParametersDesc[i]; Boxed<MyStringId> stringId = arg as Boxed<MyStringId>; MyBBMemoryValue value = null; if (botMemory.TryGetFromBlackboard(stringId, out value)) { if (value == null || (value.GetType() == parameterDesc.Item1 && parameterDesc.Item2 != MyMemoryParameterType.OUT)) { action.ActionParams[i] = value; } else { if (value.GetType() != parameterDesc.Item1) Debug.Assert(false, "Mismatch of types in the blackboard. Did you use a wrong identifier?"); action.ActionParams[i] = null; } } else action.ActionParams[i] = null; } else { action.ActionParams[i] = arg; } } }