Exemple #1
0
    // Use this for initialization
    void Start()
    {
        List <Task> sequenceChildren = new List <Task>();

        sequenceChildren.Add(new Run());
        sequenceChildren.Add(new Leap());
        treeRoot1 = new Sequence(sequenceChildren);

        List <Task> children1 = new List <Task>();

        children1.Add(new Jump());
        children1.Add(new Run());
        treeRoot2 = new Selector(children1);

        List <Rule> rules = new List <Rule>();

        Bar     bar    = new Bar();
        Library lib    = new Library();
        Thirst  thirst = new Thirst();
        Party   party  = new Party();

        List <Condition> conditions0 = new List <Condition>();

        conditions0.Add(bar);
        conditions0.Add(thirst);
        conditions0.Add(party);

        Rule rule0 = new Rule(conditions0, treeRoot1.run);

        rule0.weight = 5;
        rules.Add(rule0);

        List <Condition> conditions1 = new List <Condition>();

        conditions1.Add(bar);
        conditions1.Add(thirst);
        conditions1.Add(party);

        Rule rule1 = new Rule(conditions1, treeRoot2.run);

        rule1.weight = 6;
        rules.Add(rule1);

        //Sort the list in terms of weight
        rules.Sort();

        for (int i = 0; i < rules.Count; i++)
        {
            Debug.Log("Testing rules");
            if (rules[i].isFired())
            {
                Debug.Log("Rule fired");
                rules[i].consequence();
                break;
            }
        }
    }
Exemple #2
0
    void Start()
    {
        float initialDelay = 0.0f;
        float interval     = 1.0f;

        this.genes     = GetComponent <Genes>();
        this.hunger    = GetComponent <Hunger>();
        this.thirst    = GetComponent <Thirst>();
        this.reproduce = GetComponent <Reproduce>();

        InvokeRepeating("metabolize", initialDelay, interval);
    }
    public override bool decide(StateController controller)
    {
        Hunger    hunger    = controller.GetComponent <Hunger>();
        Thirst    thirst    = controller.GetComponent <Thirst>();
        Reproduce reproduce = controller.GetComponent <Reproduce>();

        if (hunger.currentHunger >= thirst.currentThirst && hunger.currentHunger >= reproduce.currentReproduce)
        {
            return(true);
        }
        else
        {
            return(false);
        }
    }
    public override void act(StateController stateController, ActionState actionState)
    {
        if (stateController.getGenes() != null)
        {
            if (actionState.waterToDrink == null)
            {
                Collider[] hitColliders = Physics.OverlapSphere(stateController.transform.position, stateController.getGenes().radiusOfSight);
                for (int i = 0; i < hitColliders.Length; i++)
                {
                    if (hitColliders[i].gameObject.GetComponent <Water>() != null)
                    {
                        actionState.destination  = hitColliders[i].gameObject.transform.position;
                        actionState.waterToDrink = hitColliders[i].gameObject;
                        break;
                    }
                }

                // We failed to find water, so we'll move somewhere random only if we've arrived at that random spot already
                if (actionState.destination == null)
                {
                    actionState.destination = this.randomNavCircle(stateController.transform.position, stateController.getGenes().radiusOfSight);
                }
            }

            float step = stateController.getGenes().movementSpeed *Time.deltaTime;
            stateController.transform.position = Vector3.MoveTowards(stateController.transform.position, (Vector3)actionState.destination, step);

            // found water
            if (stateController.transform.position == actionState.destination && actionState.waterToDrink != null && actionState.waterToDrink.transform.position == actionState.destination)
            {
                Thirst thirst = stateController.GetComponent <Thirst>();
                if (thirst != null)
                {
                    thirst.decreaseThirst(20);
                }
            }

            // arrived at destination
            if (stateController.transform.position == actionState.destination)
            {
                actionState.destination = null;
                Destroy(actionState.waterToDrink);
                actionState.waterToDrink = null;
            }
        }
    }
Exemple #5
0
    void Start()
    {
        this.genes = GetComponent <Genes>();

        this.hunger    = GetComponent <Hunger>();
        this.thirst    = GetComponent <Thirst>();
        this.reproduce = GetComponent <Reproduce>();

        if (this.nameText != null)
        {
            this.nameText.text = this.gameObject.transform.name;
        }

        if (this.currentStateText != null)
        {
            this.currentStateText.text = this.currentState.name;
        }
    }
        public SmartEntity(Vector2 pos, World w, string name) : base(pos, w)
        {
            /*
             * INIT FUZZY MODULES
             */
            _fuzzyThirst = new Thirst();
            _fuzzyHunger = new Hunger();
            _fuzzySleep  = new Sleep();

            NAME = name;
            // random stats
            hunger    = MyWorld.Random.Next(0, 25);
            thirst    = MyWorld.Random.Next(0, 25);
            tiredness = MyWorld.Random.Next(0, 25);

            Velocity = new Vector2(0, 0);
            Think    = new Think(this);
            Think.Activate();
            Behaviours = new List <SteeringBehaviour>
            {
                new WanderBehaviour(this, 90, 100),
                new WallAvoidance(this, 15)
            };
        }
Exemple #7
0
 private void Start()
 {
     janoScripti = GameObject.FindObjectOfType <Thirst>();
 }
 private void Start()
 {
     this.hunger    = GetComponent <Hunger>();
     this.thirst    = GetComponent <Thirst>();
     this.reproduce = GetComponent <Reproduce>();
 }