public void CreatePheromoneTrail(PheromoneNode home, PheromoneNode away, GV.PhermoneTypes pherType) { PheromoneTrail newPt = Instantiate <GameObject>(phermoneTrailPrefab).GetComponent <PheromoneTrail>(); newPt.GetComponent <DrawLineSprite>().Initialize(new Vector2(), new Vector2()); newPt.Initialize(home, away, pherType); pheromoneTrails.Add(newPt); }
public void PheromoneTrailDied(PheromoneTrail pt) { trails.Remove(pt); if (trails.Count <= 0 && !immortal) { FindObjectOfType <PheromoneManager>().DeleteNode(this); } }
public void AddTrail(PheromoneTrail pt) { if (!trails.Contains(pt)) { trails.Add(pt); } //serouisly if theres a conflict thatd be weird }
public static bool PherTrailIsEqual(PheromoneTrail p1, PheromoneNode pn1, PheromoneNode pn2) { if ((p1.pHome == pn1 || p1.pHome == pn2) && (p1.pAway == pn1 || p1.pAway == pn2)) { return(true); } return(false); }
public void InitializeNode(PheromoneTrail toLink) { if (toLink) { if (!trails.Contains(toLink)) { trails.Add(toLink); } } }
public int GetTotalPhermoneWeights(PheromoneTrail excludeTrail) { int toReturn = 0; foreach (PheromoneTrail pt in trails) { if (pt != excludeTrail && pt != null) { toReturn += pt.strength; } } return(toReturn); }
PheromoneNode DropPheromoneOnExistingTrail(PheromoneTrail pt) { PheromoneNode pn = PheromoneManager.DropPheromone(lastVisitedNode, GetPherType(), transform.position); if (lastVisitedNode) { lastVisitedNode.initialRoot = false; } lastVisitedNode = pn; timeSinceLastEvent = 0; //pt.SplitByNode(pn); return(pn); }
public PheromoneNode CreateNewNode(PheromoneNode parentNode, GV.PhermoneTypes pherType, Vector2 spawnLocation) { if (parentNode == null) { return(RetrieveNewNode(pherType, spawnLocation)); } GameObject newNodeGO = Instantiate(phermoneNodePrefab, spawnLocation, Quaternion.identity) as GameObject; GameObject newTrailGO = Instantiate <GameObject>(phermoneTrailPrefab); PheromoneNode newNode = newNodeGO.GetComponent <PheromoneNode>(); PheromoneTrail newTrail = newTrailGO.GetComponent <PheromoneTrail>(); newTrail.Initialize(parentNode, newNode, pherType); parentNode.AddTrail(newTrail); parentNode.initialRoot = false; newNode.InitializeNode(newTrail); pheromoneNodes.Add(newNode); pheromoneTrails.Add(newTrail); return(newNode); }
public PheromoneTrail SelectNewTrailByWeight(int goalWeightValue, PheromoneTrail ptToIgnore, int backTrackWeight) { int currentWeight = 1; foreach (PheromoneTrail pt in trails) { if (pt == ptToIgnore) { currentWeight += backTrackWeight; } else { currentWeight += pt.strength; } if (goalWeightValue <= currentWeight) { return(pt); } } return(null); //If it goes beyond the size, then it was because SCOUT was chosen }
private void AbsorbTrails(PheromoneNode toAbsorb) { foreach (PheromoneTrail pt in toAbsorb.trails) //for each trail i will absorb { if (pt != null) { pt.SetNewNode(toAbsorb, this); //setup PheromoneTrail trailToAbsorbTrail = PheromoneTrail.PherListContains(trails, pt); if (!trailToAbsorbTrail) { trails.Add(pt); } else { trailToAbsorbTrail.strength += pt.strength; //pt.TrailDie(); pt.SetNewNode(null, null); //since it already exist, and we dont need it, delete it. } } } }
public Intersection(Vector2 _ip, PheromoneTrail _it) { _intersectionPoint = _ip; _intersectionTrail = _it; }
public void DeleteTrail(PheromoneTrail pt) { pheromoneTrails.Remove(pt); Destroy(pt.gameObject); }
void ArriveAtNode(PheromoneNode pn) { if (lastVisitedNode) { lastVisitedNode.initialRoot = false; } int workingBackTrack = backtrackWeight; if (currentTrail) //since might get deleted during { if (holding != null && !holding.isZero()) { currentTrail.strength += GV.BASE_PHER_STRENTH * GV.HOLDING_RES_PHER_MULTIPLIER; } else { currentTrail.strength += GV.BASE_PHER_STRENTH; } } else { workingBackTrack = 0; } int totalWeight = pn.GetTotalPhermoneWeights(currentTrail) + scoutingWeight + workingBackTrack; int randomResult = Random.Range(1, totalWeight + 1); PheromoneTrail isBackTrackTrail = currentTrail; if (hasBackTracked) { PheromoneTrail tempTrail = pn.SelectNewTrailByWeight(randomResult, currentTrail, workingBackTrack); currentTrail = pn.SelectNewTrailByWeight(randomResult, currentTrail, workingBackTrack); if (currentTrail == null || currentTrail.strength > tempTrail.strength) { currentTrail = tempTrail; } hasBackTracked = false; } else { currentTrail = pn.SelectNewTrailByWeight(randomResult, currentTrail, workingBackTrack); } if (currentTrail != null && isBackTrackTrail != null && isBackTrackTrail == currentTrail) { hasBackTracked = !hasBackTracked; } lastVisitedNode = pn; if (currentTrail) { if (currentTrail.GetOtherNode(pn) == null) { currentTrail.TrailDie(); } else { goalSpot = currentTrail.GetOtherNode(pn).transform.position; antMode = AntMode.Forage; } } else { ScoutModeActivate(); } }
//returns the copy of pher found, the one that will become absorbed public static PheromoneTrail PherListContains(System.Collections.Generic.List <PheromoneTrail> pherList, PheromoneTrail toFind) { foreach (PheromoneTrail pt in pherList) { if (PherTrailIsEqual(pt, toFind.pHome, toFind.pAway)) { return(pt); } } return(null); }