public FriendlyBoid(Project2Game game, Flock flock, Model model, Vector3 position) : base(game, flock, model, position, Flock.BoidType.Friendly)
 {
     maxHealth = 200;
     health = maxHealth;
     attack = 10;
     healthyColor = Color.Green;
 }
Esempio n. 2
0
    public MultipleBirdState()
    {
        entries = new List<Entry>();
        flock = new Flock();

        id = count++;
    }
Esempio n. 3
0
    public FlockGame()
    {
        kdBuildTimer = new System.Diagnostics.Stopwatch();
        updateTimer = new System.Diagnostics.Stopwatch();

        anchorFlock = new Flock();
    }
Esempio n. 4
0
 public EnemyBoid(Project2Game game, Flock flock, Model model, Vector3 position)
     : base(game, flock, model, position, Flock.BoidType.Enemy)
 {
     maxHealth = 80;
     health = maxHealth;
     attack = 20;
     healthyColor = Color.Red;
 }
Esempio n. 5
0
 public Observer(Color tint, Vector2 position, Entity2D target, List<Enemy> flockmates, PowerCore core)
     : base("observerEnemy", tint, position, target)
 {
     CurrentHealthPoints = MaxHealthPoints = 100;
     Path = new Flock(this, flockmates, core, target, 400, new Random().Next(75, 150));
     Scale = 1.1f;
     Speed = 290f;
     FireRate = 2.5f;
 }
Esempio n. 6
0
 public Boid(Project2Game game, Flock flock, Model model, Vector3 position, Flock.BoidType boidType)
     : base(game, model, position)
 {
     this.health = maxHealth;
     this.PhysicsDescription.Mass = 0.25f;
     this.boidType = boidType;
     this.flock = flock;
     this.game.physics.World.CollisionSystem.CollisionDetected += HandleCollision;
     effect = game.Content.Load<Effect>("Shaders\\Cel");
 }
Esempio n. 7
0
 void Start()
 {
     objPlayer = GameObject.FindGameObjectWithTag("Player");
     // enable/disable NPCController script if attacking
     npc = gameObject.GetComponent<NPCController>();
     weapon = gameObject.GetComponent<Done_WeaponController>();
     flockControl = gameObject.transform.parent.GetComponent<FlockController>();
     flock = gameObject.transform.parent.GetComponent<Flock>();
     //	Debug.Log(npc.GetPlayerTransform().position + "player place");
 }
Esempio n. 8
0
        public Level(Project2Game game)
        {
            this.game = game;
            Children = new List<INode>();

            player = new Monkey(this.game, game.models["bigmonkey"], getStartPosition());
            AddChild(player);

            flock = new Flock(this.game, this);
            AddChild(flock);
        }
Esempio n. 9
0
        void Simulate(AbstractDuckFactory duckFactory)
        {
            Quackable mallardDuck = duckFactory.CreateMallardDuck();
            Quackable redHeadDuck = duckFactory.CreateRedHeadDuck();
            Quackable duckCall = duckFactory.CreateDuckCall();
            Quackable rubberDuck = duckFactory.CreateRubberDuck();
            Quackable gooseAdapter = duckFactory.CreateGeese();// new GeeseAdapter(new Geese());

            Flock duckFlock = new Flock();
            duckFlock.Add(mallardDuck);
            duckFlock.Add(redHeadDuck);
            duckFlock.Add(duckCall);
            duckFlock.Add(rubberDuck);
            duckFlock.Add(gooseAdapter);

            Flock mallardFlock = new Flock();
            mallardFlock.Add(duckFactory.CreateMallardDuck());
            mallardFlock.Add(duckFactory.CreateMallardDuck());
            mallardFlock.Add(duckFactory.CreateMallardDuck());
            mallardFlock.Add(duckFactory.CreateMallardDuck());

            //again add the mallard to duck flock
            duckFlock.Add(mallardFlock);

            //Quackalogist qmallard = new Quackalogist();
            //MallardDuck malldck = new MallardDuck();
            //malldck.RegisterObservable(qmallard);
            //Simulate(malldck);

            //Quackalogist quackalogist = new Quackalogist();
            //Quackable mallardDuckDec = new QuackCounter(new MallardDuck());
            //mallardDuckDec.RegisterObservable(quackalogist);
            //Simulate(mallardDuckDec);

            Quackalogist quackalogistFlock = new Quackalogist();
            duckFlock.RegisterObservable(quackalogistFlock);

            Console.WriteLine("\nPrinting duckflock+ mallardflock");
            Simulate(duckFlock);

            Console.WriteLine("\nPrinting mallardflock");
            //mallardFlock.RegisterObservable(quackalogistFlock);
            Simulate(mallardFlock);

            Console.WriteLine(QuackCounter.GetQuackCounter());
        }
Esempio n. 10
0
    /// <summary>
    /// Re-calculates the path for each bird
    /// </summary>
    public override void Init()
    {
        if (anchor == null)
            anchor = GameObject.Find("Player").GetComponent<Starling>();

        anchorFlock = new Flock(anchor);
        flock.Add(anchor);

        generalManager.pattern.anchor = anchor;
        //anchor.maxSpeed = 0f;

        //////
        formationManagers.Clear();
        foreach (var entry in entries)
        {
            generalManager.AddCharacter(entry.bird);
            formationManagers.Add(entry.bird, generalManager);
            entry.behavior = getDefaultSteering(entry, generalManager, flock);
        }
    }
Esempio n. 11
0
    public override Vector2 CalculateMove(FlockAgent agent, List <Transform> context, Flock flock)
    {
        if (context.Count == 0)
        {
            return(Vector2.zero);
        }

        Vector2 cohesionMove = Vector2.zero;

        var filteredContext = filter == null ? context : filter.Filter(agent, context);

        foreach (var item in filteredContext)
        {
            cohesionMove += (Vector2)item.position;
        }
        cohesionMove /= context.Count;

        cohesionMove -= (Vector2)agent.transform.position;
        cohesionMove  = Vector2.SmoothDamp(agent.transform.up, cohesionMove, ref currentVelocity, agentSmoothTime);

        return(cohesionMove);
    }
    public override Vector3 CalculateMove(FlockAgent agent, List <Transform> context, Flock flock)
    {
        if (context.Count == 0) // No neighbours, no adjustment
        {
            return(Vector3.zero);
        }

        // Add all points and average out
        Vector3 cohesionMove = Vector3.zero;

        foreach (Transform item in context)
        {
            cohesionMove += item.position;
        }
        cohesionMove /= context.Count;

        // Create offset
        cohesionMove -= agent.transform.position;
        return(cohesionMove);
    }
Esempio n. 13
0
        public SchoolOfFish(ContentManager Content, Texture2D fishTexture, int minX, int maxX, int minZ, int maxZ, float camHeight)
        {
            flock = null;
            //cat = null;

            flockParams = new AIParameters();

            this.content = Content;
            this.fishTexture = fishTexture;
            this.gameMaxX = GameConstants.MainGameMaxRangeX;
            this.gameMaxZ = GameConstants.MainGameMaxRangeZ;
            minValueX = minX;
            minValueZ = minZ;
            maxValueX = maxX;
            maxValueZ = maxZ;
            camHeightScale = (float)GameConstants.StandardCamHeight / (float)camHeight;
            ResetAIParams();
        }
Esempio n. 14
0
 public Mallard(Flock flock, BehaviorFactory behavior)
     : base(flock, behavior)
 {
     Console.WriteLine("A wild Mallard has appeared!" + "\r\n");
 }
Esempio n. 15
0
		public static bool TryCopy (IntPtr source, out Flock destination)
		{
			return ToFlock (source, out destination) == 0;
		}
Esempio n. 16
0
 void Awake()
 {
     _flock = GetComponent<Flock>();
 }
		private static int FromFlock (ref Flock source, IntPtr destination)
		{
			throw new System.NotImplementedException();
		}
Esempio n. 18
0
 public Navfield(NavfieldManager manager, Flock flock, Quaternion orientation, NavFieldPrimitives primitive, float duration)
 {
     Create(manager, flock, orientation, primitive, duration);
 }
Esempio n. 19
0
 public void AssignFlock(Flock flock)
 {
     assignedFlock = flock;
 }
 public void BelongToFlock(Flock flock)
 {
     myFlock = flock;
 }
Esempio n. 21
0
    public override Vector3 CalculateMove(FlockAgent agent, List <Transform> context, Flock flock)
    {
        //if no neighbours, return no adjustment
        if (context.Count == 0)
        {
            return(Vector3.zero);
        }
        //add all points together
        Vector3 cohesionMove = Vector3.zero;

        foreach (Transform item in context)
        {
            cohesionMove += item.position;
        }
        cohesionMove /= context.Count;
        //create offset from agent pos
        cohesionMove -= agent.transform.position;
        return(cohesionMove);
    }
Esempio n. 22
0
    public override Vector2 CalculateMove(FlockAgent agent, List <Transform> context, Flock flock)
    {
        if (!(Services.Scenes.CurrentScene is GameSceneScript))
        {
            return(Vector2.zero);
        }
        // If no neighbors, return no adjustment
        if (context.Count == 0)
        {
            return(Vector2.zero);
        }

        // Average all points
        Vector2 avoidancenMove = Vector2.zero;
        int     nAvoid         = 0;
        bool    contains       = false;

        if (ContextContains(((GameSceneScript)Services.Scenes.CurrentScene).PlayerFlock.Player.transform, context))
        {
            contains = true;
        }
        else
        {
            agent.moreAnxious = false;
            agent.SetAnxietyLevel(Mathf.Lerp(agent.AnxietyLevel, FlockAgent.MIN_ANXIETY_LEVEL, Easing.BackEaseOut(Time.deltaTime)));
        }

        if (agent.ContextContainsPlayer && agent.ContextContainsPlayer != contains && agent.Status == FlockAgent.AgentStatus.ANXIOUS)
        {
            Services.GameEventManager.Fire(new PlayerLeftContextEvent(agent));
        }
        agent.SetContextContainsPlayer(contains);
        List <Transform> filterContext = (filter == null) ? context : filter.Filter(agent, context);

        float avoidanceRadius = flock ? flock.SquareAvoidanceRadius : m_defaultSquareAvoidanceRadius;

        avoidanceRadius *= agent.AnxietyLevel;


        foreach (Transform item in filterContext)
        {
            // If an item is within the avoidanceRadius
            if (Vector2.SqrMagnitude(item.position - agent.transform.position) <
                avoidanceRadius && mask == (mask | (1 << item.gameObject.layer)))
            {
                agent.SetAnxietyLevel(Mathf.Lerp(agent.AnxietyLevel, FlockAgent.MAX_ANXIETY_LEVEL, Easing.BackEaseOut(Time.deltaTime)));
                agent.moreAnxious = true;

                //Add to items to avoid and calculate the direction to move to avoid
                nAvoid++;
                avoidancenMove += (Vector2)(agent.transform.position - item.position);
            }
        }

        if (nAvoid > 0)
        {
            avoidancenMove /= nAvoid;
        }

        return(avoidancenMove);
    }
Esempio n. 23
0
    public override Vector3 CalculateMove(FlockAgent agent, List <Transform> context, Flock flock)
    {
        //if no neighbor maintain current alignment
        if (context.Count == 0)
        {
            return(agent.transform.forward);
        }

        // add all points toogether and average
        Vector3          alignmentMove   = Vector3.zero;
        List <Transform> filteredContext = (filter == null) ? context : filter.Filter(agent, context);

        foreach (Transform item in filteredContext)
        {
            alignmentMove += item.transform.forward;
        }
        alignmentMove /= context.Count;

        return(alignmentMove);
    }
Esempio n. 24
0
    private void Create(NavfieldManager manager, Flock flock, Quaternion orientation, NavFieldPrimitives primitive, float duration)
    {
        this.manager = manager;
        origin       = flock.getBarycenter();
        rotation     = orientation;
        size         = manager.minSize;
        cellSize     = manager.minCellSize;

        int count = 0;

        for (int i = 0; i < flock.numberOfBoids; i++)
        {
            if (isInside(flock.boids[i].transform.position))
            {
                count++;
            }
        }

        float ratio    = (float)count / (float)flock.numberOfBoids,
              minRatio = (manager.minSize * manager.minCellSize) / flock.boundRadius;

        if (ratio >= minRatio)
        {
            cellSize = (float)manager.minCellSize / ratio;
        }
        else
        {
            cellSize = (float)manager.minCellSize / minRatio;
        }

        forces        = new Vector3[size, size, size];
        this.duration = duration;
        time          = 0f;

        switch (primitive)
        {
        case NavFieldPrimitives.dispersal:
            for (int i = 0; i < size; i++)
            {
                for (int j = 0; j < size; j++)
                {
                    for (int k = 0; k < size; k++)
                    {
                        forces[i, j, k] = manager.force * new Vector3((i - (size * 0.5f)) / (size * 0.5f), (j - (size * 0.5f)) / (size * 0.5f), (k - (size * 0.5f)) / (size * 0.5f));
                    }
                }
            }
            break;

        case NavFieldPrimitives.gathering:
            for (int i = 0; i < size; i++)
            {
                for (int j = 0; j < size; j++)
                {
                    for (int k = 0; k < size; k++)
                    {
                        forces[i, j, k] = manager.force * -new Vector3((i - (size * 0.5f)) / (size * 0.5f), (j - (size * 0.5f)) / (size * 0.5f), (k - (size * 0.5f)) / (size * 0.5f));
                    }
                }
            }
            break;

        case NavFieldPrimitives.horizontal_compressor:
            for (int i = 0; i < size; i++)
            {
                for (int j = 0; j < size; j++)
                {
                    for (int k = 0; k < size; k++)
                    {
                        forces[i, j, k] = manager.force * -new Vector3((i - (size * 0.5f)) / (size * 0.5f), 0, 0);
                    }
                }
            }
            break;

        case NavFieldPrimitives.vertical_compressor:
            for (int i = 0; i < size; i++)
            {
                for (int j = 0; j < size; j++)
                {
                    for (int k = 0; k < size; k++)
                    {
                        forces[i, j, k] = manager.force * -new Vector3(0, (j - (size * 0.5f)) / (size * 0.5f), 0);
                    }
                }
            }
            break;

        case NavFieldPrimitives.ascension:
            for (int i = 0; i < size; i++)
            {
                for (int j = 0; j < size; j++)
                {
                    for (int k = 0; k < size; k++)
                    {
                        forces[i, j, k] = manager.force * new Vector3(0, 1, 0);
                    }
                }
            }
            break;

        case NavFieldPrimitives.descent:
            for (int i = 0; i < size; i++)
            {
                for (int j = 0; j < size; j++)
                {
                    for (int k = 0; k < size; k++)
                    {
                        forces[i, j, k] = manager.force * -new Vector3(0, 1, 0);
                    }
                }
            }
            break;

        case NavFieldPrimitives.tube:
            for (int i = 0; i < size; i++)
            {
                for (int j = 0; j < size; j++)
                {
                    for (int k = 0; k < size; k++)
                    {
                        if (i - (size * 0.5f) < 0)
                        {
                            forces[i, j, k] = manager.force * new Vector3(1, 1, 0);
                        }
                        else
                        {
                            forces[i, j, k] = manager.force * new Vector3(-1, 1, 0);
                        }
                    }
                }
            }
            break;
        }
    }
Esempio n. 25
0
 public void Initialize(Flock flock)
 {
     agentFlock = flock;
 }
Esempio n. 26
0
 public void Initialize(Flock flock)
 {
     mFlock         = flock;
     mColls         = new List <Collider>();
     mIsInitialized = true;
 }
Esempio n. 27
0
	private bool inView(Flock f) {
		float dir = Mathf.Rad2Deg * Mathf.Atan2(velocity.y, velocity.x);
		Vector3 delta = f.transform.position - transform.position;
		float angleTo = Mathf.Rad2Deg * Mathf.Atan2(delta.y, delta.x);
		return withinAngle(dir, angleTo, VIEW_ANGLE);
	}
Esempio n. 28
0
 public GrapeDuck(Flock flock, BehaviorFactory behavior)
     : base(flock, behavior)
 {
 }
Esempio n. 29
0
		public static bool TryCopy (ref Flock source, IntPtr destination)
		{
			return FromFlock (ref source, destination) == 0;
		}
Esempio n. 30
0
        public override Vector2 CalculateMove(FlockAgent agent, List <Transform> context, Flock flock)
        {
            // if have no neighbor, miantain current alingment
            if (context.Count == 0)
            {
                return(agent.transform.up);
            }

            // add all points together and average
            Vector2 alignmentMove = Vector2.zero;

            foreach (Transform item in context)
            {
                alignmentMove += (Vector2)item.transform.up;
            }
            alignmentMove /= context.Count;

            return(alignmentMove);
        }
Esempio n. 31
0
 protected override Errno OnLockHandle(string file, OpenedPathInfo info, FcntlCommand cmd, ref Flock @lock)
 {
     int r = Syscall.fcntl ((int) info.Handle, cmd, ref @lock);
     if (r == -1)
         return Stdlib.GetLastError ();
     return 0;
 }
    public override Vector3 CalculateMove(FlockAgent agent, List <Transform> context, Flock flock)
    {
        Profiler.BeginSample("Avoidance - CalculateMove()");
        if (context.Count == 0) // No neighbours, no adjustment
        {
            return(Vector3.zero);
        }

        // Add all points and average out
        Vector3          avoidanceMove   = Vector3.zero;
        int              nAvoid          = 0; // How many objects in avoidance radius
        List <Transform> filteredContext = (filter == null) ? context : filter.Filter(agent, context);

        foreach (Transform item in filteredContext)
        {
            if (Vector3.SqrMagnitude(item.position - agent.transform.position) < flock.SquareAvoidanceRadius)
            {
                nAvoid++;
                avoidanceMove += agent.transform.position - item.position;
            }
        }

        if (nAvoid > 0) // If theres objects to avoid
        {
            avoidanceMove /= nAvoid;
        }

        Profiler.EndSample();
        return(avoidanceMove);
    }
Esempio n. 33
0
 public void setFlock(Flock flock)
 {
     _flock = flock;
 }
Esempio n. 34
0
    // move away from neighbours
    public override Vector3 CalculateMove(FlockAgent agent, List <Transform> context, Flock flock)
    {
        // if no neighbours, return no adjustment
        if (context.Count == 0)
        {
            return(Vector3.forward);
        }

        // add all points together and average
        Vector3 avoidanceMove = Vector3.zero;
        int     nAvoid        = 0; // number of avoidances

        List <Transform> filteredContext = (filter == null) ? context : filter.Filter(agent, context);

        foreach (Transform item in filteredContext)
        {
            // check if other agent is in current agent's fov
            float y = item.position.z - agent.transform.position.z;
            float x = item.position.x - agent.transform.position.x;
            float angleBetweenAgents = Mathf.Atan2(y, x) * Mathf.Rad2Deg;
            bool  inView             = (angleBetweenAgents < (90f + agent.fieldOfView / 2)) && (angleBetweenAgents > (90f - agent.fieldOfView / 2));

            if (inView && Vector3.SqrMagnitude(item.position - agent.transform.position) < flock.SquareAvoidanceRadius)
            {
                nAvoid++;
                avoidanceMove += (agent.transform.position - item.position); // move away
            }
        }

        if (nAvoid > 0)
        {
            avoidanceMove /= nAvoid;
        }

        return(avoidanceMove);
    }
Esempio n. 35
0
        public override Vector3 CalculateMove(FlockAgent agent, List <Transform> context, Flock flock)
        {
            Vector3 centerOffset = center - agent.transform.position;
            float   t            = centerOffset.magnitude / radius;

            if (t < 0.9)
            {
                return(Vector3.zero);
            }

            return(centerOffset * t * t);
        }
    public override Vector2 CalculateMove(FlockAgent agent, List <Transform> context, Flock flock)
    {
        // if no neighbor
        if (context.Count == 0)
        {
            return(Vector2.zero);
        }

        Vector2 avoidanceMove = Vector2.zero;
        int     nAvoid        = 0;

        foreach (Transform item in context)
        {
            if (Vector2.SqrMagnitude(item.position - agent.transform.position) < flock.SquareAvoidRadius)
            {
                nAvoid++;
                avoidanceMove = (Vector2)(agent.transform.position - item.position);
            }
        }
        if (nAvoid > 0)
        {
            avoidanceMove /= nAvoid;
        }

        return(avoidanceMove);
    }
Esempio n. 37
0
    public override Vector2 CalculateMove(FlockAgent agent, List <Transform> context, Flock flock)
    {
        // if no neighbor, keep moving
        if (context.Count == 0)
        {
            return((Vector2)agent.transform.up);
        }
        //Debug.Log("agent ke = " + agent.ToString());
        Vector2 alignmentMove = Vector2.zero;
        float   distance;

        foreach (Transform item in context)
        {
            alignmentMove += (Vector2)item.transform.up;
            //Debug.Log(item.ToString());
            distance = Vector2.SqrMagnitude(agent.transform.position - item.transform.position);
            //Debug.Log(distance);
            //AddRecord(agent.ToString(), item.ToString(), distance,"AlingmentNew2.csv");
            //AddRecord(agent.ToString(), item.ToString(), distance,(360 - agent.transform.rotation.eulerAngles.z),"Alingmentrot.csv");
        }
        alignmentMove /= context.Count;

        float alix = alignmentMove.x;
        float aliy = alignmentMove.y;

        //AddRecord(agent.ToString(), alix, aliy, "alignment3.csv");
        return(alignmentMove);
    }
Esempio n. 38
0
    public override Vector2 CalculateMove(FlockAgent agent, List <Transform> context, Flock flock)
    {
        //if no neighbors return no adjustment
        if (context.Count == 0)
        {
            return(Vector2.zero);
        }

        // add all points together and avarage
        Vector2          cohensionMove   = Vector2.zero;
        List <Transform> filteredContext = (filter == null) ? context : filter.Filter(agent, context);

        foreach (Transform item in filteredContext)
        {
            cohensionMove += (Vector2)item.position;
        }
        cohensionMove /= context.Count;

        //create offset from agent position
        cohensionMove -= (Vector2)agent.transform.position;
        return(cohensionMove);
    }
    public override Vector2 calculateMove(FlockAgent agent, List <Transform> context, Flock flock)
    {
        //Handle data mismatch
        if (weights.Length != behaviors.Length)
        {
            Debug.LogError("Data mismatch" + name, this);
            return(Vector2.zero);
        }

        //set up move
        Vector2 move = Vector2.zero;

        //iterate through behaviors
        for (int i = 0; i < behaviors.Length; i++)
        {
            Vector2 partialMove = behaviors[i].calculateMove(agent, context, flock) * weights[i];

            if (partialMove.sqrMagnitude > weights[i] * weights[i])
            {
                partialMove.Normalize();
                partialMove *= weights[i];
            }
            move += partialMove;
        }
        return(move);
    }
Esempio n. 40
0
 private void Start()
 {
     m_FlockScript = GetComponent <Flock>();
 }
    // Override CalculateMove method from FlockBehavior class.
    public override Vector2 CalculateMove(FlockAgent currAgent, List <Transform> neighbourAgentsTransforms, Flock flock)
    {
        // If no neighbours, Then keep the flock agent's original direction.
        if (neighbourAgentsTransforms.Count == 0)
        {
            return(Vector2.zero);
        }

        // Get the average value of all neighbour flock agents' positions' sum.

        // Initialize the SteeredCohesion move Vector2.
        var SteeredCohesionMove = Vector2.zero;

        // Add all neighbour flock agents' positions together.
        foreach (var neighbourTransform in neighbourAgentsTransforms)
        {
            SteeredCohesionMove += (Vector2)neighbourTransform.position;
        }

        // Get the average position.
        SteeredCohesionMove /= neighbourAgentsTransforms.Count;

        // Create offset from each agent's position.
        SteeredCohesionMove -= (Vector2)currAgent.transform.position;

        // Gradually changes a vector2 towards a desired goal over time.
        SteeredCohesionMove = Vector2.SmoothDamp(currAgent.transform.up, SteeredCohesionMove,
                                                 ref currVelocity, flockAgentSmoothTime);

        return(SteeredCohesionMove);
    }
Esempio n. 42
0
 //avoidance or cohesion applied here
 public abstract Vector2 Decide(Flock_Agent agent, List <Transform> context, Flock flock);
Esempio n. 43
0
    void Start()
    {
        //input validation for number of herds
        if (numHerds < 1)
            numHerds = 1;
        else if (numHerds > 9) //limiting the maximum number of herds to 9 makes it easier to handle input for the camera
            numHerds = 9;

        //initializing everything
        terrainWidth = (int)terrain.terrainData.size.z;
        terrainLength = (int)terrain.terrainData.size.x;
        BOUNDS_CENTER = new Vector3(terrainLength / 2, 0, terrainWidth / 2);
        BOUNDS_ZRAD = 200.0f;
        BOUNDS_XRAD = 100.0f;
        obstacles = new List<GameObject>();
        deerStart = new List<GameObject>();
        flowField = new Vector3[terrainLength, terrainWidth];
        createFlowField();
        determineStartingLocations();
        wolves = new Flock(Random.Range(minWolves, maxWolves + 1), wolfStart, wolfPrefab, numHerders);
        herds = new List<Flock>();
        int index;
        List<int> usedIndices = new List<int>();
        for (int i = 0; i < numHerds; i++) {
            //make the herds
             do
                index = Random.Range(0, deerStart.Count);
             while(usedIndices.Contains(index));
            Vector3[] seekpoints;
            List<Vector3> seekList = new List<Vector3>();
            foreach(Transform t in deerStart[index].transform)
            {
                seekList.Add(t.position);
            }
            seekpoints=seekList.ToArray();
            herds.Add(new Flock(Random.Range(minDeer,maxDeer+1),deerStart[index].transform.position,deerPrefab,seekpoints));
            usedIndices.Add(index);
        }

        //set camera to follow the game manager
        myCamera.enabled = true;
        myCamera.transform.position = new Vector3(wolfStart.x, 50, wolfStart.z);
    }
Esempio n. 44
0
    public override Vector2 CalculateMove(FlockAgent agent, List <FlockAgent> context, Flock flock)
    {
        if (weights.Length != behaviors.Length)
        {
            Debug.LogError("Data mismatch in " + name, this);
            return(Vector2.zero);
        }

        Vector2 move = Vector2.zero;

        for (int i = 0; i < behaviors.Length; i++)
        {
            Vector2 partialMove = behaviors[i].CalculateMove(agent, context, flock) * weights[i];

            if (partialMove != Vector2.zero)
            {
                move += partialMove;
            }
        }

        return(move);
    }
		private static int ToFlock (IntPtr source, out Flock destination)
		{
			throw new System.NotImplementedException();
		}
    public float agentSmoothTime = 0.7f; // 0.5 sec kinda, dependent on frame rate


    // find middle point between all neighbours and try to move there
    public override Vector3 CalculateMove(FlockAgent agent, List <Transform> context, Flock flock)
    {
        // if no neighbours, return no adjustment
        if (context.Count == 0)
        {
            return(Vector3.forward);
        }

        currentVelocity = Vector3.zero; // need to set this in order to avoid NaN error in smoothDamp

        // add all points together and average
        Vector3          cohesionMove    = Vector3.zero;
        List <Transform> filteredContext = (filter == null) ? context : filter.Filter(agent, context);

        foreach (Transform item in filteredContext)
        {
            // check if other agent is in current agent's fov
            float y = item.position.z - agent.transform.position.z;
            float x = item.position.x - agent.transform.position.x;
            float angleBetweenAgents = Mathf.Atan2(y, x) * Mathf.Rad2Deg;
            bool  inView             = (angleBetweenAgents < (90f + agent.fieldOfView / 2)) && (angleBetweenAgents > (90f - agent.fieldOfView / 2));

            if (inView)
            {
                cohesionMove += item.position;
            }
        }
        cohesionMove /= filteredContext.Count;

        // create offset from agent position
        cohesionMove -= agent.transform.position;
        cohesionMove  = Vector3.SmoothDamp(agent.transform.forward, cohesionMove, ref currentVelocity, agentSmoothTime);

        if (float.IsNaN(cohesionMove.x) || float.IsNaN(cohesionMove.y) || float.IsNaN(cohesionMove.z))
        {
            cohesionMove -= agent.transform.position;
            return(cohesionMove);
        }

        return(cohesionMove);
    }
Esempio n. 47
0
	private bool canSee(Flock f) {
		return Vector3.Distance(transform.position, f.transform.position) < VIS_DIST && inView(f);
	}
Esempio n. 48
0
    public override Vector2 CalculateMove(FlockAgent agent, List <Transform> context, Flock flock)
    {
        // If no neighbours, return no adjustment
        if (context.Count == 0)
        {
            return(Vector2.zero);
        }

        // Add all points together and find the average point
        Vector2 cohesionMove = Vector2.zero;

        // We go through each items transform in our list of neighbours
        // If using filter, we choose the filtered list of transforms, otherwise ignore this
        List <Transform> filteredContext = (filter == null) ? context : filter.Filter(agent, context);

        foreach (Transform item in filteredContext)
        {
            cohesionMove += (Vector2)item.position;
        }
        // We now average the Vector out again so it is not a huuuge number
        cohesionMove /= context.Count;

        // Change from global position to offset of the agent itself
        // Create offset from agent position:
        cohesionMove -= (Vector2)agent.transform.position;

        cohesionMove = Vector2.SmoothDamp(agent.transform.up, cohesionMove, ref currentVelocity, agentSmoothTime);
        // Then we can return the vector
        return(cohesionMove);
    }
Esempio n. 49
0
		private static extern int FromFlock (ref Flock source, IntPtr destination);
Esempio n. 50
0
    Steering getDefaultSteering(Entry e, FormationManager generalManager, Flock flock)
    {
        var pattSteering = new PatternSteering(e.bird, generalManager);
        var separation = new Separation(e.bird, flock, 5.0f, -1f);
        separation.aknnApproxVal = 1.0;
        var obstacleAvoidance = new ObstacleAvoidance(e.bird, 20f, new string[]{"Ground"});

        var blended = new BlendedSteering[3];

        blended[0] = new BlendedSteering(e.bird, new BehaviorAndWeight(obstacleAvoidance, 1f));
        blended[1] = new BlendedSteering(e.bird, new BehaviorAndWeight(separation, 1f));
        blended[2] = new BlendedSteering(e.bird, new BehaviorAndWeight(pattSteering, 1f));

        return new PrioritySteering(1f, blended);
    }
Esempio n. 51
0
		private static extern int ToFlock (IntPtr source, out Flock destination);
Esempio n. 52
0
    public override Vector2 CalculateMove(FlockAgent agent, List <Transform> context, Flock flock)
    {
        //if no neighbours, return no adjustment
        if (context.Count == 0)
        {
            return(Vector2.zero);
        }

        //add all points together and average
        Vector2          avoidanceMove   = Vector2.zero;
        int              nAvoid          = 0;
        List <Transform> filteredContext = (filter == null) ? context : filter.Filter(agent, context);

        foreach (Transform item in filteredContext)
        {
            if (Vector2.SqrMagnitude(item.position - agent.transform.position) < flock.SquareAvoidanceRadius)
            {
                avoidanceMove += (Vector2)(agent.transform.position - item.position);
                nAvoid++;
            }
        }

        if (nAvoid > 0)
        {
            avoidanceMove /= nAvoid;
        }

        return(avoidanceMove);
    }
Esempio n. 53
0
 public void SetUp()
 {
     flockSize = 5;
     Random rand = new Random();
     rules = new List<Interfaces.BoidRule_Interface>();
     flock = new Flock(flockSize, rand, rules, 500, 500);
 }
Esempio n. 54
0
 public abstract Vector3 CalculateMove(FlockAgent agent, List <Transform> context, Flock flock);
Esempio n. 55
0
 public RubberDuck(Flock flock, BehaviorFactory behavior)
     : base(flock, behavior)
 {
     Console.WriteLine("A Rubber Duck has appeared!" + "\r\n");
 }
Esempio n. 56
0
    /// <summary>
    /// Calcuates the vector that the agent should move along in order to avoid nearby objects
    /// </summary>
    /// <param name="agent"> the current agent </param>
    /// <param name="context"> a list of transforms of gameobjects surrounding the current agent</param>
    /// <param name="flock"> the flock the agent is in</param>
    /// <returns> the vector that the agent should move along </returns>
    public override Vector3 CalculateMove(FlockAgent agent, List <Transform> context, Flock flock)
    {
        ///if there are no neighbours return no adjustment
        if (context.Count == 0)
        {
            return(Vector3.zero);
        }

        ///add all points together and average
        Vector3 avoidanceMove          = Vector3.zero;
        int     numberOfObjectsToAvoid = 0;

        foreach (Transform item in context)
        {
            if (Vector3.SqrMagnitude(item.position - agent.transform.position) < flock.SquareAvoidanceRadius)
            {
                numberOfObjectsToAvoid++;
                if (item.CompareTag("Enemy"))
                {
                    avoidanceMove += (agent.transform.position - item.position);
                }
                else if (item.CompareTag("Obstacle"))
                {
                    avoidanceMove += 3 * (agent.transform.position - item.position);
                }
            }
        }
        avoidanceMove = avoidanceMove.normalized;
        avoidanceMove = Vector3.Lerp(agent.transform.forward, avoidanceMove, agentSmoothFactor);

        return(avoidanceMove);
    }
Esempio n. 57
0
 protected Duck(Flock flock, BehaviorFactory behavior)
 {
     Behavior = behavior.CreateBehavior(this);
     Flock = flock;
 }
 public void Initialize(Flock flock)
 {
     agentFlock = flock; //Set this agent to equal the parameter passed through
 }
Esempio n. 59
0
 public CrazyDuck(Flock flock, BehaviorFactory behavior) : base(flock, behavior)
 {
     Console.WriteLine("A Crazy-Ass Duck has appeared!" + "\r\n");
 }
Esempio n. 60
0
 /// <summary>
 /// Create the fish flock
 /// </summary>
 /// <param name="theNum"></param>
 protected void SpawnFlock(int gameMaxX, int gameMaxZ, int minValueX, int maxValueX, int minValueZ, int maxValueZ)
 {
     if (flock == null)
     {
         flock = new Flock(fishTexture, gameMaxX, gameMaxZ, flockParams, content, minValueX, maxValueX, minValueZ, maxValueZ);
     }
 }