void OnTriggerExit(Collider c) { if (tracingPheromone.gameObject.Equals(c.gameObject)) { tracingPheromone = null; } }
void DropPheromone(Pheromone.PheromoneType type, Vector3 target) { Pheromone pheromone = new Pheromone(type, target, this); m_WorldMatrix.DropPheromone(pheromone, gameObject.transform.position); ProcessPheromone(pheromone); }
Vector3 FindMovmementDirection(PheromoneTypes pheromoneType) { Pheromone pheromone = _closestPheromone; Vector3 movementVector = new Vector3(); Vector3 position = transform.position; // check that pheromone still exists if (!pheromone) { return(Vector3.zero); } Vector3 pheromonePosition = pheromone.transform.position; Vector3 pheromoneVector = (pheromonePosition - position).normalized; // find angle of pheromone float pheromoneAngle = Vector3.Dot(transform.forward, pheromoneVector); if (pheromoneAngle > _currentSmellAngle) { // weight added to concentration movementVector += pheromoneVector * pheromone.currentConcentration; } if (pheromoneType == PheromoneTypes.Fear || pheromoneType == PheromoneTypes.Pain) { return(-movementVector); } return(movementVector); }
void OnTriggerEnter(Collider c) { if (c.gameObject.CompareTag("pheromone")) { returningPheromone = c.gameObject.GetComponent <Pheromone>(); // p.Add(QVAL/ distanceSum); } else if (c.gameObject.CompareTag("sugar")) { SetReturning(true); sugarPeace = c.gameObject.GetComponent <Sugar>().GetPeace(); positionHistory.Add(transform.position); SetNextDestination(); } else if (c.gameObject.CompareTag("anthill")) { returningAnthill = c.gameObject.GetComponent <Anthill>(); // if (!isReturning) { // positionHistory.Clear(); // SetReturning(false); // if (sugarPeace != null) { // c.gameObject.GetComponent<Anthill>().AddSugarPeace(sugarPeace); // sugarPeace = null; // } // SetNextDestination(); // } } }
void OnTriggerEnter(Collider c) { if (c.gameObject.CompareTag("pheromone")) { tracingPheromone = c.gameObject.GetComponent <Pheromone>(); // p.Add(QVAL/ distanceSum); } }
// Start is called before the first frame update void Start() { world = GameObject.Find("Controller").GetComponent <Controller>(); direction = new Vector3(Random.Range(-1.0f, 1.0f), 0, Random.Range(-1.0f, 1.0f)).normalized; rigidbody = GetComponent <Rigidbody>(); homePheromone = pheromones[1].GetComponent <Pheromone>(); life = maxLife; }
bool ShouldBePruned(Pheromone pheromone) { if (pheromone) { return(false); } return(true); }
void OnTriggerExit(Collider collider) { Pheromone pheromone = collider.GetComponentInParent <Pheromone> (); if (pheromone) { _pheromoneBehaviour.PheromoneExited(pheromone); } }
void OnTriggerEnter(Collider collider) { Pheromone pheromone = collider.transform.parent.GetComponent <Pheromone> (); if (pheromone) { _nearbyPheromones.Add(pheromone); } }
void OnTriggerExit(Collider collider) { Pheromone pheromone = collider.transform.parent.GetComponent <Pheromone> (); if (pheromone) { _nearbyPheromones.Remove(pheromone); } }
void OnTriggerExit(Collider collider) { Debug.Log("exit pheromone cloud"); Pheromone pheromone = collider.GetComponentInParent <Pheromone>(); if (pheromone) { _pheromoneBehaviour.PheromoneExited(pheromone); } }
private void PlacePheromone(Vector3 position, Vector3 destination) { Pheromone p = returningPheromone; returningPheromone = null; if (p == null) { p = Instantiate(prefabPheromone, position, Quaternion.identity) as Pheromone; } p.Add(destination, defaultPheromoneValue); }
// Use this for initialization void Start() { map = new Pheromone[mapSize, mapSize]; for (int x = 0; x < mapSize; x++) { for (int y = 0; y < mapSize; y++) { map[x, y] = new Pheromone(); } } InvokeRepeating("PheromoneDelete", 0, 1); }
void DropPheromones() { foreach (GameObject pheromoneObj in pheromones) { Pheromone pheromone = pheromoneObj.GetComponent <Pheromone>(); bool drop = false; float strength = 0; switch (pheromone.GetPheromoneType()) { case Pheromone.PheromoneType.Food: if (hasFood) { drop = true; strength = pheromone.GetStartingStrength() - (pheromone.dropRate * foodCount * 2); } break; case Pheromone.PheromoneType.Home: if (!hasFood && !goHome) { drop = true; strength = pheromone.GetStartingStrength() - (pheromone.dropRate * homeCount * 2); } break; } if (strength < 0) { strength = 0; } if (drop) { Debug.Log(strength); GameObject droppedPheromone = Instantiate(pheromoneObj); droppedPheromone.GetComponent <Pheromone>().SetColony(colony); droppedPheromone.GetComponent <Pheromone>().strength = (int)strength; droppedPheromone.transform.position = transform.position; } } }
void ProcessPheromone(Pheromone pheromone) { // Flee for your life if (m_Behaviour == BugBehaviour.Fleeing) { return; } switch (pheromone.Type) { case (Pheromone.PheromoneType.Ennemy): m_Behaviour = BugBehaviour.Fleeing; break; case (Pheromone.PheromoneType.Mating): if (pheromone.Dropper != this) { if (Time.time - TimeTilReadyForMating.value < m_InstanciationTime) { return; } m_Behaviour = BugBehaviour.SeekingMate; m_TargetPosition = pheromone.Target; m_Mate = pheromone.Dropper; } break; case (Pheromone.PheromoneType.Food): m_Behaviour = BugBehaviour.Gathering; m_TargetPosition = pheromone.Target; break; case (Pheromone.PheromoneType.Home): if (m_Behaviour == BugBehaviour.Gathering) { m_TargetPosition = pheromone.Target; } break; } }
public void TourSuivant() { foreach (Pheromone unePheromone in fourmilliere.ObjetAbstraitList.Where(x => x.GetType().Equals(typeof(Pheromone))).ToList()) { if (unePheromone.Dureevie < 1) { fourmilliere.ObjetAbstraitList.Remove(unePheromone); } } foreach (ObjetAbstrait unObjet in fourmilliere.ObjetAbstraitList) { unObjet.TourPasse(); } foreach (PersonnageAbstrait unInsecte in fourmilliere.PersonnageAbstraitList) { if (unInsecte.GetType().Equals(typeof(Ouvriere)) && unInsecte.TransporteNourriture == true) { Coordonnees coordonnees = new Coordonnees(unInsecte.Position.X, unInsecte.Position.Y); Pheromone unPheromone = new Pheromone("pheromone", coordonnees); fourmilliere.ObjetAbstraitList.Add(unPheromone); } unInsecte.Avance1Tour(DimensionX, DimensionY); if (unInsecte.Pointsdevie <= 0) { PersonnagesMortList.Add(unInsecte); PersonnagesList.Remove(unInsecte); } //décommentes si tu veux que tes fourmis souillent la map avec leurs feromones //unInsecte.TransporteNourriture = true; } if (Hazard.Next(1, 11) == 1) { AjouteNourriture(); } tourActuel++; }
void ReDropPheromone(Pheromone pheromone) { DropPheromone(pheromone.Type, pheromone.Target); }
public Vector2 pheromonesAttraction(Vector2 position, TypePheromone type) { Vector2 attraction = Vector2.Zero; Vector2 attractionPhero; PheroSortedList scanPheromones ; if (type == TypePheromone.food) { scanPheromones = game.PheromonesFood; } else if (type == TypePheromone.war) { scanPheromones = game.PheromonesWar; } else { return attraction; } float smellXmin = owner.Position.X - TOLERANCE; float smellXmax = owner.Position.X + TOLERANCE; float smellYmin = owner.Position.Y - TOLERANCE; float smellYmax = owner.Position.Y + TOLERANCE; Pheromone indexPhero = new Pheromone(game,false); indexPhero.Position = new Vector2(smellXmin,0); int index; try { scanPheromones.Add(smellXmin, indexPhero); index = scanPheromones.IndexOfValue(indexPhero); }catch(ArgumentException){ index = scanPheromones.IndexOfKey(smellXmin); } List<Pheromone> selected = new List<Pheromone>(); for (int i = index; i < scanPheromones.Values.Count; i++) { if (scanPheromones.Values[i].Position.X > smellXmax) { break; } if (scanPheromones.Values[i].Position.Y > smellYmin && scanPheromones.Values[i].Position.Y < smellYmax) { selected.Add(scanPheromones.Values[i]); } } scanPheromones.Remove(indexPhero); foreach (Pheromone pheromone in selected) { attractionPhero = (pheromone.Position - position); float distance = attractionPhero.Length(); float scallarProduct = attractionPhero.X * owner.Velocity.X + attractionPhero.Y * owner.Velocity.Y; if (totalAngle || scallarProduct > 0) { attractionPhero.Normalize(); attractionPhero *=(Main.G_PHEROMONES * pheromone.Smell / (distance*distance*distance)); attraction += attractionPhero; } } return attraction; }
public void DropPheromone(Pheromone pheromone, Vector3 position) { }
public void PheromoneEntered(Pheromone pheromone) { _closestPheromone = pheromone; }
public Cell() { this._isColony = false; this.pheromone = new Pheromone(); this.food = null; }
public Vector2 pheromonesAttraction(Vector2 position, TypePheromone type) { Vector2 attraction = Vector2.Zero; Vector2 attractionPhero; PheroSortedList scanPheromones; if (type == TypePheromone.food) { scanPheromones = game.PheromonesFood; } else if (type == TypePheromone.war) { scanPheromones = game.PheromonesWar; } else { return(attraction); } float smellXmin = owner.Position.X - TOLERANCE; float smellXmax = owner.Position.X + TOLERANCE; float smellYmin = owner.Position.Y - TOLERANCE; float smellYmax = owner.Position.Y + TOLERANCE; Pheromone indexPhero = new Pheromone(game, false); indexPhero.Position = new Vector2(smellXmin, 0); int index; try { scanPheromones.Add(smellXmin, indexPhero); index = scanPheromones.IndexOfValue(indexPhero); }catch (ArgumentException) { index = scanPheromones.IndexOfKey(smellXmin); } List <Pheromone> selected = new List <Pheromone>(); for (int i = index; i < scanPheromones.Values.Count; i++) { if (scanPheromones.Values[i].Position.X > smellXmax) { break; } if (scanPheromones.Values[i].Position.Y > smellYmin && scanPheromones.Values[i].Position.Y < smellYmax) { selected.Add(scanPheromones.Values[i]); } } scanPheromones.Remove(indexPhero); foreach (Pheromone pheromone in selected) { attractionPhero = (pheromone.Position - position); float distance = attractionPhero.Length(); float scallarProduct = attractionPhero.X * owner.Velocity.X + attractionPhero.Y * owner.Velocity.Y; if (totalAngle || scallarProduct > 0) { attractionPhero.Normalize(); attractionPhero *= (Main.G_PHEROMONES * pheromone.Smell / (distance * distance * distance)); attraction += attractionPhero; } } return(attraction); }
public override void TourSuivant() { if (!ReineMorte()) { if (reine.sousAttaque == false) { if (Etat != "normal") { Etat = "normal"; Notify(); } } if (reine.sousAttaque == true) { Etat = "attaque"; Notify(); reine.sousAttaque = false; } if (TourActuel % 10 == 0) { meteoChange(); } reine = (Reine)PersonnagesList.Where(x => x.GetType().Equals(typeof(Reine))).FirstOrDefault(); if (reine.OeufPondu != null) { List <ObjetAbstrait> morceaux = ObjetList.Where(x => x.GetType().Equals(typeof(MorceauNourriture)) && x.Position.toString().Equals(reine.Position.toString())).ToList(); if (morceaux.Count > 0) { ObjetList.Remove(morceaux[0]); ObjetList.Add(reine.OeufPondu); } } reine.OeufPondu = null; foreach (Oeuf unOeuf in ObjetList.Where(x => x.GetType().Equals(typeof(Oeuf))).ToList()) { if (unOeuf.Age > Oeuf.DureeAvantEclosion - 1) { PersonnageAbstrait fourmi = unOeuf.fourmiARetourner; fourmi.Nom += PersonnagesList.Count; AjouterFourmi(fourmi); ObjetList.Remove(unOeuf); } } foreach (Pheromone unePheromone in ObjetList.Where(x => x.GetType().Equals(typeof(Pheromone))).ToList()) { if (unePheromone.Dureevie < 1) { ObjetList.Remove(unePheromone); } } foreach (Nourriture nourriture in ObjetList.Where(x => x.GetType().Equals(typeof(Nourriture))).ToList()) { if (nourriture.ListMorceaux.Count < 1 || nourriture.Dureevie < 1) { ObjetList.Remove(nourriture); } } foreach (ObjetAbstrait unObjet in ObjetList) { unObjet.TourPasse(meteo); } Repositioner(); FournirAcces(); foreach (PersonnageAbstrait unInsecte in PersonnagesList.ToList()) { unInsecte.Avance1Tour(DimensionX, DimensionY, TourActuel); if (unInsecte.GetType().Equals(typeof(Ouvriere)) && unInsecte.TransporteNourriture == true) { if (unInsecte.Position.toString().Equals(coordMaison.toString())) { Ouvriere ouvriere = (Ouvriere)unInsecte; MorceauNourriture morceau = ouvriere.DeposeMorceau(); ObjetList.Add(morceau); } Coordonnees coordonnees = new Coordonnees(unInsecte.Position.X, unInsecte.Position.Y); Pheromone unPheromone = new Pheromone("pheromone", coordonnees); ObjetList.Add(unPheromone); } } List <PersonnageAbstrait> persosMorts = PersonnagesList.Where(x => x.PV < 1).ToList(); foreach (PersonnageAbstrait persomort in persosMorts) { Mourrir(persomort); } if (Hazard.Next(1, 7) == 1) { AjouteNourriture(); } if (TourActuel % 50 == 0) { for (int i = 0; i < Config.nbrTermites; i++) { AjouterTermite(); } } TourActuel++; } }
void UpdateDirection() { Vector3 prevDirection = direction; // Momentum direction = direction * momentumRatio; // Target int topStrength = 0; Vector3 topDirection = Vector3.zero; foreach (GameObject pheromoneObj in world.GetPheromones()) { if (Vector3.Distance(transform.position, pheromoneObj.transform.position) < range) { Pheromone pheromone = pheromoneObj.GetComponent <Pheromone>(); switch (pheromone.GetPheromoneType()) { case Pheromone.PheromoneType.Food: if (!hasFood && !goHome && !explorer) { if (pheromone.GetStrength() > topStrength) { topStrength = pheromone.GetStrength(); topDirection = (pheromoneObj.transform.position - transform.position).normalized; } } break; case Pheromone.PheromoneType.Home: if (hasFood || goHome) { if (pheromone.GetStrength() > topStrength) { topStrength = pheromone.GetStrength(); topDirection = (pheromoneObj.transform.position - transform.position).normalized; } } break; } } } direction += topDirection * targetRatio; /* * foreach(GameObject ant in world.GetAnts()) * { * if (Vector3.Distance(transform.position, ant.transform.position) < 2) * { * direction += (transform.position - ant.transform.position).normalized*2; * } * } */ //Randomize slightly direction += new Vector3(Random.Range(-1.0f, 1.0f), 0, Random.Range(-1.0f, 1.0f)) * randomRatio; //Wall avoidance Vector3 myPosition = transform.position; RaycastHit hit; if (Physics.Raycast(myPosition, prevDirection, out hit, range)) { if (hit.collider.gameObject.tag == "Wall") { direction += (transform.position - hit.point).normalized * hitRatio; } } //No climbing if (direction.y > 0) { direction.y = 0; } direction.Normalize(); }
public void DropPheromone(Pheromone pheromone, Vector3 position) { Tile tile = GetTile(position); tile.Pheromones.Add(pheromone); }
/** * Called by the AgentPheromoneSensor when an already percieved pheromone is out of range. */ public void PheromoneExited(Pheromone pheromone) { _nearbyPheromones[pheromone.type].Remove(pheromone); }
// TODO: make pheromone exits fade, (should leave an impression on boids) public void PheromoneExited(Pheromone pheromone) { _closestPheromone = pheromone; }
/** * Called by the AgentPheromoneSensor when a new pheromone is percieved. */ public void PheromoneEntered(Pheromone pheromone) { _nearbyPheromones[pheromone.type].Add(pheromone); }
private void LayPharomone(CellAddress a, Pheromone p) { }
public Pheromone PheromonePooper() { Pheromone pheromone = new Pheromone(antPheromone); return(pheromone); }