示例#1
0
    public static BT_Result TickChild(BT_Node child, BT_AgentMemory am)
    {
        if (child.CheckPrecondition(am) == false)
        {
            return(BT_Result.FAILURE);
        }

        am.FinalNodeLastCall = child.ID;

        if (child.Activates == false)
        {
            // Debug.Log(child.ID + " - " + child.GetType().ToString() + " - decider tick");
            BT_Result result = child.Tick(am);
            return(result);
        }
        else
        {
            am.ActivateNode(child.ID);
            // Debug.Log(child.ID + " - " + child.GetType().ToString() + " - action tick");
            BT_Result result = child.Tick(am);
            if (result != BT_Result.RUNNING)
            {
                am.DeactivateNode(child.ID);
            }
            return(result);
        }
    }
示例#2
0
    public override IEnumerator Executar()
    {
        state = BT_State.RUNNING;
        for (int i = 0; i < transform.childCount; i++)
        {
            BT_Node node = transform.GetChild(i).GetComponent <BT_Node> ();

            node.state = BT_State.RUNNING;
            node.StartCoroutine("Executar");

            while (node.state == BT_State.RUNNING)
            {
                yield return(null);
            }

            if (node.state == BT_State.FAILURE)
            {
                this.state = BT_State.FAILURE;
                this.StopCoroutine("Executar");
                break;
            }
        }

        if (this.state != BT_State.FAILURE)
        {
            this.state = BT_State.SUCCESS;
        }
    }
 public void AddChild(BT_Node <T> child)
 {
     if (CanAddChild())
     {
         childs.Add(child);
     }
 }
示例#4
0
 public void AddChild(BT_Node <T> child)
 {
     if (CanAddChild(child))
     {
         child.Blackboard = this.Blackboard;
         children.Add(child);
     }
 }
 public void SetChild(BT_Node <T> child)
 {
     if (CanAddChild(child))
     {
         this.child            = child;
         this.child.Blackboard = this.Blackboard;
     }
 }
示例#6
0
    public BT_Result Tick(BT_AgentMemory am)
    {
        am.ResetActiveNodesList();
        am.ProcessTimers(am.DeltaTime);
        am.CurrentTree = this;

        BT_Result result = BT_Node.TickChild(Root, am);

        // Debug.Log(am.Character.Name + " - " + am.FinalNodeLastCall + " - " + GetNodeByID(am.FinalNodeLastCall).GetType());
        return(result);
    }
示例#7
0
    public void Configurar()
    {
        BT_Node nodo = GetComponent <BT_Node> ();

        if (nodo.GetType() == typeof(BT_Selector))
        {
            texto.text = "?";
        }
        else if (nodo.GetType() == typeof(BT_Sequence))
        {
            texto.text = ">";
        }
    }
示例#8
0
 public Timing(BT_Node node)
 {
     target      = node;
     isActivated = false;
 }
示例#9
0
 public virtual bool CanAddChild(BT_Node <T> child)
 {
     return(true);
 }
示例#10
0
 public FrameCounter(BT_Node node, int _waitCount) : base(node)
 {
     currentFrameCount = 0;
     waitCount         = _waitCount;
 }
示例#11
0
 public BT_Node Add(BT_Node node)
 {
     Children.Add(node);
     return(node);
 }
示例#12
0
    public bool SetNewDestination(Tile tile, bool startMovement, IAccessible tileOwner, BT_Node callingNode)
    {
#if UNITY_EDITOR
        CharacterLogEntry newLog = new CharacterLogEntry(Time.time, tile, tileOwner, callingNode);
#endif
        if (State == CharacterState.PreparingForDeletion ||
            State == CharacterState.UsingService)
        {
            return(false);
        }

        if (tile == null ||
            inaccessibleTilesTimers.ContainsKey(tile) ||
            tile.MovementCost == 0f)
        {
            DestinationTile = CurrentTile;
            return(false);
        }

        if (tile == DestinationTile)
        {
            if (startMovement)
            {
                State = CharacterState.Movement;
            }

#if UNITY_EDITOR
            log.Add(newLog);
#endif
            return(true);
        }

        DestinationTile = tile;

        if (Path != null && Path.Goal != tile)
        {
            NextTile           = null;
            MovementPercentage = 0f;
            Path = null;
        }

        State = startMovement ? CharacterState.Movement : CharacterState.PreparingForCheckingPath;

#if UNITY_EDITOR
        log.Add(newLog);
#endif
        return(true);
    }
示例#13
0
 public CharacterLogEntry(float time, Tile goalTile,
                          IAccessible tileOwner, BT_Node callingNode)
 {
     Time      = time; GoalTile = goalTile;
     TileOwner = tileOwner; CallingNode = callingNode;
 }
 public BT_RepeatUntilFail(BT_Node child) : base(child)
 {
 }
示例#15
0
 public void AddChildNode(BT_Node node)
 {
     childNode = node;
 }
 public BT_DecoratorNode(BT_Node child)
 {
     Child = child;
 }
示例#17
0
 public BT_Inverter(BT_Node child) : base(child)
 {
 }
 public override bool CanAddChild(BT_Node <T> child)
 {
     return(child is BT_ConditionNode <T> || child is BT_DecoratorNot <T>);
 }
示例#19
0
 public void AddChildNode(BT_Node node)
 {
     childNodeList.Add(node);
 }
示例#20
0
    public void LoadHumanTree()
    {
        float waitBeforeEntering = 0.2f;

        Root =
            Subtree(new BT_Priority(),
                    new BT_IsUsingService(),
                    new BT_RemoveWorkplaceIfCannotReserve(),
                    new BT_GoToRandomTile(),
                    Subtree(new BT_Sequence(),
                            new BT_HasReservation(),
                            new BT_Inverter(new BT_AreReservedStoragesAccessible()),
                            new BT_RemoveReservation()
                            ),
                    Subtree(new BT_MemSequence(),
                            new BT_HasReservation(),
                            new BT_HasResourceForReservation(),
                            new BT_GoToTargetStorage(),
                            new BT_Wait(waitBeforeEntering),
                            new BT_DepositResource()
                            ),
                    Subtree(new BT_MemSequence(),
                            new BT_HasReservation(),
                            new BT_GoToSourceStorage(),
                            new BT_Wait(waitBeforeEntering),
                            new BT_TakeResource()
                            ),
                    Subtree(new BT_Sequence(),
                            new BT_HasResource(),
                            new BT_Inverter(new BT_HasReservation()),
                            new BT_FindNewStorageForResource()
                            ),
                    Subtree(new BT_MemSequence(),
                            new BT_HasService(),
                            new BT_GoToService(),
                            new BT_Wait(waitBeforeEntering),
                            new BT_StartUsingService()
                            ),
                    Subtree(new BT_Sequence(),
                            new BT_IsNeedHigherThan("Health", StaticData.NeedLevelToDie),
                            new BT_Die()
                            ),
                    Subtree(new BT_Sequence(),
                            new BT_IsNeedHigherThan("Health", StaticData.NeedLevelToSeekService),
                            new BT_FindService("Health")
                            ),
                    Subtree(new BT_Sequence(),
                            new BT_IsNeedHigherThan("Hunger", StaticData.NeedLevelToDie),
                            new BT_Die()
                            ),
                    Subtree(new BT_Sequence(),
                            new BT_IsNeedHigherThan("Hunger", StaticData.NeedLevelToSeekService),
                            new BT_FindService("Hunger")
                            ),
                    Subtree(new BT_MemSequence(),
                            new BT_HasWorkplace(),
                            new BT_GoToWorkplace(),
                            new BT_Wait(waitBeforeEntering),
                            new BT_Work()
                            ),
                    Subtree(new BT_Sequence(),
                            new BT_Inverter(new BT_HasWorkplace()),
                            new BT_FindTransportJob()
                            ),
                    Subtree(new BT_Sequence(),
                            new BT_Inverter(new BT_HasReservation()),
                            new BT_FindWorkplace()
                            ),
                    new BT_SetRandomTile()
                    );

        AssignIDs();
    }