public override Vector2 CalculateMove(FlockAgent agent, List <Transform> context, Flock flock) { // Not even enough transforms in the area to form an enemy // If agent already stolen, then don't continue if (context.Count < neighborAmount) // || flock.IsAgentStolen(agent)) { return(Vector2.zero); } List <Transform> filteredContext = (filter == null) ? context : filter.Filter(agent, context); if (filteredContext.Count >= neighborAmount) { EnemyBase enemyBase = Instantiate(flockPrefab, agent.transform.position, Quaternion.identity); Flock enemyFlock = enemyBase.Flock; // Try adding enemies in here. Other option is adding in the instantiation of the flock // Capture agents when formed? foreach (Transform neighbor in filteredContext) { FlockAgent neighborAgent = neighbor.GetComponent <FlockAgent>(); if (neighborAgent != null) { enemyFlock.StealAgentFromFlock(neighborAgent, neighborAgent.AgentFlock); } } enemyFlock.StealAgentFromFlock(agent, agent.AgentFlock); } return(Vector2.zero); }
public override Vector2 CalculateMove(FlockAgent agent, List <Transform> context, Flock flock) { // If no neighbors, nothing to steal if (context.Count == 0) { return(Vector2.zero); } // Instead of moving, steal! List <Transform> filteredContext = (filter == null) ? context : filter.Filter(agent, context); foreach (Transform neighbor in filteredContext) { FlockAgent neighborAgent = neighbor.GetComponent <FlockAgent>(); if (neighborAgent != null && Random.Range(0f, 1f) < stealChance) { flock.StealAgentFromFlock(neighborAgent, neighborAgent.AgentFlock); } } return(Vector2.zero); // nothing to move }