Ejemplo n.º 1
0
    public override void ChooseNextMove()
    {
        if (windStrength > 0)
        {
            var options = new ChoiceStack <twin>();
            options.AddManyThenLock(twin.right, twin.up, twin.left, twin.down);
            options.RemoveAll(-lastMove);
            options.GetFirstTrue(TryMove); // move!!!
            windStrength--;
        }
        else
        {
            gameObject.name  = "plant";
            box.isTrigger    = false;
            gameObject.layer = LayerMask.NameToLayer("Solid");
            if (CanMoveTo(my_cell_pos))
            {
                BeginPregnancy();
            }
            else
            {
                Object.Destroy(gameObject);
            }
        }

        spriter.sprite = spritelot[IsPregnant() ? 6 : 7];
    }
Ejemplo n.º 2
0
    private void FixedUpdate()
    {
        if (ToCentered().sqrMagnitude < 1)
        {
            transform.position += ToCentered() * 0.5f;
            body.velocity      *= 0.5f;
        }
        else
        {
            body.velocity *= 0.9f;
            body.velocity += 0.1f * ((Vector2)ToCentered()).normalized * 50 * energy;
        }

        if (Mathf.Abs(ToCentered().y) < 2f && Mathf.Abs(ToCentered().x) <= 8f)
        {
            var moves = new ChoiceStack <twin>();
            moves.AddManyThenLock(twin.down);
            moves.AddManyThenLock(twin.left, twin.right);
            moves.RemoveAll(-lastMove);

            lastMove = moves.GetFirstTrue(TryMove);

            if (lastMove == twin.down)
            {
                energy = 1f;
            }
            else if (energy > .1f)
            {
                energy -= .1f;
            }
        }
    }
Ejemplo n.º 3
0
    protected void ChooseNewDir_Forward()
    {
        var dirs = new ChoiceStack <twin>();

        dirs.Add(twin.down); // prefer 'down': gravity
        dirs.AddManyThenLock(twin.compass);
        dirs.RemoveAll(-lastMove);
        lastMove = dirs.GetFirstTrue(this.TryMove);
    }
Ejemplo n.º 4
0
    public void TakeAnyMove()
    {
        var dirs = new ChoiceStack <twin>(twin.compass);

        if (no_turn_around)
        {
            dirs.RemoveAll(-lastMove);
        }
        lastMove = dirs.GetFirstTrue(TryMove);
    }
Ejemplo n.º 5
0
    protected void ChooseMove_no180()
    {
        var dirs = new ChoiceStack<twin>(); dirs.AddManyThenLock(twin.compass);
        dirs.RemoveAll(-lastMove);
        lastMove = dirs.GetFirstTrue(TryMove);

        if (lastMove.x != 0)
        {
            GetComponent<SpriteRenderer>().flipX = lastMove.x < 0;
        }
    }
Ejemplo n.º 6
0
 private void FixedUpdate()
 {
     if (IsWithinDistOfCentered(2f))
     {
         var dirs = new ChoiceStack <twin>(twin.compass);
         dirs.RemoveAll(-lastMove);
         lastMove = dirs.GetFirstTrue(TryMove);
     }
     else
     {
         body.velocity = body.velocity * .5f + .5f * (Vector2)ToCentered() * speed;
     }
 }
Ejemplo n.º 7
0
 // do nothing special.
 private void FixedUpdate()
 {
     if (IsWithinDistOfCentered(2f))
     {
         // dope
         var dirs = new ChoiceStack <twin>(twin.compass);
         dirs.RemoveAll(-lastMove);
         lastMove = dirs.GetFirstTrue(TryMove);
     }
     else
     {
         GetComponent <Rigidbody2D>().velocity = moveSpeed * ToCentered().normalized;
     }
 }
Ejemplo n.º 8
0
    void PickAMove()
    {
        var moves = new ChoiceStack <twin>();

        moves.AddManyThenLock(twin.compass);
        moves.RemoveAll(-bfm.lastMove);
        moves.Add(-bfm.lastMove);
        moves.Lock(shuffle: false);
        twin iMoved = moves.GetFirstTrue(bfm.TryMove);

        if (iMoved == twin.zero)
        {
            bfm.facingDir = twin.compass[Random.Range(0, 4)];
        }

        bfm.UpdateHelper_FaceFacingDir();
    }
Ejemplo n.º 9
0
        private void FixedUpdate()
        {
            switch (agentType)
            {
            case AgentType.Player:
                twin pin = new twin(Util.sign(Input.GetAxisRaw("Horizontal")), Util.sign(Input.GetAxisRaw("Vertical")));
                body.velocity = body.velocity * 0.9f + 0.1f * (Vector2)pin * 50;

                if (pin.taxicabLength == 1)
                {
                    GetComponent <FacingData>().facing = pin;
                }

                transform.rotation = Quaternion.Euler(0, 0, Vector2.SignedAngle(twin.up, GetComponent <FacingData>().facing));
                break;

            case AgentType.Pill:
                AgentScripts.PillFixedUpdate(this);
                break;

            case AgentType.RedBlood:
            case AgentType.WhiteBlood:
            case AgentType.Virus:
            case AgentType.Oxygen:

                if (IsWithinDistOfCentered(2f))
                {
                    // great, keep going
                    var dirs = new ChoiceStack <twin>(twin.compass);
                    dirs.RemoveAll(-lastMove);
                    lastMove = dirs.GetFirstTrue(TryMove);
                }
                else
                {
                    body.velocity = ToCentered().normalized * 20;
                }

                break;

            case AgentType.BodyHeart:
                body.velocity = ToCentered().normalized * 20;
                break;
            }
        }
Ejemplo n.º 10
0
        public static void PillFixedUpdate(InsiderBasicAgent agent)
        {
            var pd = agent.GetComponent <PillData>();

            if (pd.mode_bullet)
            {
                agent.GetComponent <BitsyAni>().speed = .4f;
                agent.SnapMyCellPos();
                if ((agent.body.velocity - pd.bullet_velocity).SqrMagnitude() > 10)
                {
                    pd.mode_medicine = true;
                    pd.mode_bullet   = false;
                    var random_dirs = new ChoiceStack <twin>(twin.compass);
                    random_dirs.GetFirstTrue(agent.TryMove);

                    agent.body.velocity = Quaternion.Euler(0, 0, Random.Range(90, 270)) * pd.bullet_velocity;   // bounce backwards
                    agent.GetComponent <SpriteRenderer>().flipX = !agent.GetComponent <SpriteRenderer>().flipX; // flip sprite
                }
            }
            else if (pd.mode_medicine)
            {
                if (pd.medicine_energize < 1)
                {
                    pd.medicine_energize = Mathf.Clamp01(pd.medicine_energize + .02f);
                    agent.GetComponent <BitsyAni>().speed = Mathf.Lerp(.6f, 0, pd.medicine_energize);
                    agent.body.velocity *= 0.99f;
                }
                else
                {
                    agent.GetComponent <BitsyAni>().speed = .12f;
                    if (agent.IsWithinDistOfCentered(2f))
                    {
                        var dirs = new ChoiceStack <twin>(twin.compass);
                        dirs.RemoveAll(-agent.lastMove);
                        agent.lastMove = dirs.GetFirstTrue(agent.TryMove);
                    }
                    else
                    {
                        agent.body.velocity = agent.body.velocity * .95f + .05f * (Vector2)agent.ToCentered().normalized * 25f;
                    }
                }
            }
        }
Ejemplo n.º 11
0
    public void TryDWMove()
    {
        twin.StraightenCompass();
        ChoiceStack <twin> directions = new ChoiceStack <twin>();

        if (lastMove.taxicabLength == 2)
        {
            directions.AddManyThenLock(
                new twin(lastMove.x, 0),
                new twin(0, lastMove.y),
                lastMove); // prefer to continue in your weird diagonal direction.
        }
        bool open_space = false;

        for (int i = 0; i < 4; i++)
        {
            var dira = twin.compass[i];
            var dirb = twin.compass[(i + 1) % 4];
            if ((dira == lastMove || dirb == lastMove) &&
                CanMoveTo(my_cell_pos + dira) &&
                CanMoveTo(my_cell_pos + dirb) &&
                CanMoveTo(my_cell_pos + dira + dirb))
            {
                directions.Add(dira + dirb);
                open_space = true; // moving through an open space.
            }
        }
        if (open_space)
        {
            directions.Add(lastMove);             // in an open space, i can continue in the same direction.
        }
        directions.Lock();

        directions.AddManyThenLock(twin.compass);

        directions.RemoveAll(-lastMove);

        lastMove = directions.GetFirstTrue(TryMove);
    }
Ejemplo n.º 12
0
        private void FixedUpdate()
        {
            if (this.mature < 1)
            {
                if (IsWithinDistOfCentered(2f, offset: subtileOffset))
                {
                    this.mature += Random.value * 0.5f;
                    if (this.mature >= 1)
                    {
                        transform.localScale = Vector3.one;
                    }
                    else
                    {
                        var dirs = new ChoiceStack <twin>(twin.compass);
                        dirs.RemoveAll(-lastMove);
                        lastMove = dirs.GetFirstTrue(TryMove);
                    }
                }
                else if (bodyStuckFrames > 20)
                {
                    bodyStuckFrames = 0;
                    SnapMyCellPos();
                    TryMove(-lastMove);
                }
            }

            SetVelocityApproachTarget();

            this.toNextCycle--;
            if (this.toNextCycle <= 0)
            {
                // too many plants in one space will choke + die!

                float[] nutrients_need = { 0, 0, 0 };

                HashSet <twin> myCellAndOrthos = new HashSet <twin>();
                myCellAndOrthos.Add(my_cell_pos);
                foreach (var dir in twin.compass)
                {
                    myCellAndOrthos.Add(my_cell_pos + dir);
                }

                foreach (var agent in board.GetAgentsAt(myCellAndOrthos))
                {
                    if (agent is BaPlant)
                    {
                        var plant = (BaPlant)agent;
                        if (plant.mature >= 1)
                        {
                            nutrients_need[0] += plant.nutrientColour.r;
                            nutrients_need[1] += plant.nutrientColour.g;
                            nutrients_need[2] += plant.nutrientColour.b;
                        }
                    }

                    if (agent is BaFoodSource)
                    {
                        this.thriving += 0.25f; // food sources are great for thriving plants :)
                    }
                }

                // if there's a need of 10, and 5 are available, my nutrient share will be 50%. that's simple.
                // if there's a need of 15, and 5 are avail, i'll get 33%. get the reciprocal, simple.
                // then i need to take all those according to how much i need to see how many nutrients i'll have altogether, right?

                // so if i need .75 green and my neighbour does too... we have a combined need of 1.5
                // my thriving will go down by (.75)*(random)*(1-(66%)) // <-- we'll each be getting 66%
                // therefore the 'shortage' is 1-33%
                // my thriving will go down by (.75)*(random*(.33)), which means i'll be losing thriving:
                // i'll lose 0.12375 on average each frame, too much for my 0.1 to offset.

                if (nutrients_need[0] > 1)
                {
                    this.thriving -= this.nutrientColour.r * Random.value * (1 - (1 / nutrients_need[0]));
                }
                if (nutrients_need[1] > 1)
                {
                    this.thriving -= this.nutrientColour.g * Random.value * (1 - (1 / nutrients_need[1]));
                }
                if (nutrients_need[2] > 1)
                {
                    this.thriving -= this.nutrientColour.b * Random.value * (1 - (1 / nutrients_need[2]));
                }
                this.thriving = Mathf.Clamp01(this.thriving + (mature < 1?0:0.1f));

                this.heart = Mathf.Clamp01(this.heart + 0.2f * (this.thriving - 0.5f));

                if (this.heart >= 1 && this.mature >= 1)
                {
                    Spread();
                }

                transform.localScale = Vector3.one;
                GetComponent <SpriteRenderer>().color = Color.white;

                if (mature < 1)
                {
                    transform.localScale *= 0.5f;
                }
                if (this.heart < .4f)
                {
                    GetComponent <SpriteRenderer>().color = Color.grey;
                }
                if (this.heart < .2f)
                {
                    transform.localScale *= 0.5f;
                }

                if (this.heart <= 0)
                {
                    Object.Destroy(this.gameObject);
                }
                else
                {
                    this.toNextCycle = this.cycleLength;
                }
            }
        }
Ejemplo n.º 13
0
    public override void ChooseNextMove()
    {
        foreach (var mazer in master.GetBodiesAt(my_cell_pos))
        {
            var plant = mazer.GetComponent <MazeBodyPlant>();
            if (plant && plant.IsPregnant())
            {
                fullness += 0.25f;
                plants_eaten++;
                Object.Destroy(plant.gameObject);
                if (plants_eaten > gluttony)
                {
                    this.BeginPregnancy();
                    return;
                }
                else if (fullness > 1)
                {
                    // overeating? reduce gluttony
                    fullness = 1;
                    gluttony--;
                }
            }

            if (mazer.GetComponent <MazeBodyHunter>())
            {
                mazer.GetComponent <MazeBodyHunter>().Fight(this);
            }
        }

        var options = new ChoiceStack <twin>();

        twin.StraightenCompass();
        options.AddManyThenLock(twin.compass);

        var hunter_influence    = new Vector3();
        var hunter_count        = 0;
        var herbivore_influence = new Vector3();
        var herbivore_count     = 0;
        var plant_influence     = new Vector3();
        var plant_count         = 0;

        foreach (var mazer in GetMazeBodiesNear(24f))
        {
            if (mazer.GetComponent <MazeBodyHunter>() && !mazer.GetComponent <MazeBodyHunter>().IsPregnant())
            {
                hunter_influence += (mazer.transform.position - this.transform.position).normalized;
                hunter_count++;
            }
            if (mazer.GetComponent <MazeBodyHerbivore>())
            {
                herbivore_influence += (mazer.transform.position - this.transform.position).normalized;
                herbivore_count++;
            }
            if (mazer.GetComponent <MazeBodyPlant>())
            {
                if (mazer.GetComponent <MazeBodyPlant>().IsPregnant())
                {
                    plant_influence += (mazer.transform.position - this.transform.position).normalized;
                    plant_count++;
                }
            }
        }

        hermitage = Mathf.Max(hermitage, herbivore_count);

        if (hunter_count > 0) // run from hunter
        {
            if (hunter_influence.x > 0)
            {
                options.RemoveAll(twin.right);
            }
            if (hunter_influence.x < 0)
            {
                options.RemoveAll(twin.left);
            }
            if (hunter_influence.y > 0)
            {
                options.RemoveAll(twin.up);
            }
            if (hunter_influence.y < 0)
            {
                options.RemoveAll(twin.down);
            }
        }
        else if (herbivore_count + hermitage > 20) // run from overcrowding
        {
            if (herbivore_influence.x > 0)
            {
                options.RemoveAll(twin.right);
            }
            if (herbivore_influence.x < 0)
            {
                options.RemoveAll(twin.left);
            }
            if (herbivore_influence.y > 0)
            {
                options.RemoveAll(twin.up);
            }
            if (herbivore_influence.y < 0)
            {
                options.RemoveAll(twin.down);
            }
            options.AddManyThenLock(twin.compass);
        }
        else if (plant_count > 0) // chase plant
        {
            gluttony = Mathf.Max(plant_count, gluttony);
            if (-plant_influence.x > 0)
            {
                options.RemoveAll(twin.right);
            }
            if (-plant_influence.x < 0)
            {
                options.RemoveAll(twin.left);
            }
            if (-plant_influence.y > 0)
            {
                options.RemoveAll(twin.up);
            }
            if (-plant_influence.y < 0)
            {
                options.RemoveAll(twin.down);
            }
            options.AddManyThenLock(twin.compass);
        }
        //else if (herbivore_count > 0 && Random.value < .5f) // stick with friends
        //{
        //    if (-herbivore_influence.x > 0) options.RemoveAll(twin.right);
        //    if (-herbivore_influence.x < 0) options.RemoveAll(twin.left);
        //    if (-herbivore_influence.y > 0) options.RemoveAll(twin.up);
        //    if (-herbivore_influence.y < 0) options.RemoveAll(twin.down);
        //    options.AddManyThenLock(twin.compass);
        //}
        else
        {
            options.RemoveAll(-lastMove);
            options.AddManyThenLock(-lastMove);
        }

        lastMove = options.GetFirstTrue(TryMove);
    }
Ejemplo n.º 14
0
    public override void ChooseNextMove()
    {
        foreach (var mazer in master.GetBodiesAt(my_cell_pos))
        {
            if (mazer.GetComponent <MazeBodyHerbivore>() != null)
            {
                Fight(mazer.GetComponent <MazeBodyHerbivore>());
                return;
            }
        }

        var options = new ChoiceStack <twin>();

        twin.StraightenCompass();
        options.AddManyThenLock(twin.compass);

        var hunter_influence    = new Vector3();
        var hunter_count        = 0;
        var herbivore_influence = new Vector3();
        var herbivore_count     = 0;

        foreach (var mazer in GetMazeBodiesNear(24f))
        {
            if (mazer.GetComponent <MazeBodyHunter>())
            {
                hunter_influence += (mazer.transform.position - this.transform.position).normalized;
                hunter_count++;
            }
            if (mazer.GetComponent <MazeBodyHerbivore>())
            {
                herbivore_influence += (mazer.transform.position - this.transform.position).normalized;
                herbivore_count++;
            }
        }

        if (hunter_count > 0) // avoid other hunter
        {
            if (hunter_influence.x > 0)
            {
                options.RemoveAll(twin.right);
            }
            if (hunter_influence.x < 0)
            {
                options.RemoveAll(twin.left);
            }
            if (hunter_influence.y > 0)
            {
                options.RemoveAll(twin.up);
            }
            if (hunter_influence.y < 0)
            {
                options.RemoveAll(twin.down);
            }
            fullness -= 0.02f * hunter_count; // being near other hunters is stressful (we fight)

            if (hunter_count > 5)
            {
                overcrowded = true;
            }

            options.AddManyThenLock(twin.compass);
        }
        else if (herbivore_count > 0) // otherwise, approach herbivores
        {
            if (-herbivore_influence.x > 0)
            {
                options.RemoveAll(twin.right);
            }
            if (-herbivore_influence.x < 0)
            {
                options.RemoveAll(twin.left);
            }
            if (-herbivore_influence.y > 0)
            {
                options.RemoveAll(twin.up);
            }
            if (-herbivore_influence.y < 0)
            {
                options.RemoveAll(twin.down);
            }

            if (herbivore_count > 5)
            {
                killForSport = true;                      // too many? murder murder murder
            }
            options.AddManyThenLock(twin.compass);
        }
        else
        {
            killForSport = false;
            overcrowded  = false;

            // no hunters/herbivores nearby?
            if (TryMove(lastMove)) // then just go straight if possible.
            {
                options = null;
            }
        }

        if (options != null)
        {
            options.RemoveAll(-lastMove); // hunters don't like turning back
            lastMove = options.GetFirstTrue(TryMove);
        }
    }