Ejemplo n.º 1
0
    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);
    }
Ejemplo n.º 2
0
 public void PheromoneTrailDied(PheromoneTrail pt)
 {
     trails.Remove(pt);
     if (trails.Count <= 0 && !immortal)
     {
         FindObjectOfType <PheromoneManager>().DeleteNode(this);
     }
 }
Ejemplo n.º 3
0
 public void AddTrail(PheromoneTrail pt)
 {
     if (!trails.Contains(pt))
     {
         trails.Add(pt);
     }
     //serouisly if theres a conflict thatd be weird
 }
Ejemplo n.º 4
0
 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);
 }
Ejemplo n.º 5
0
 public void InitializeNode(PheromoneTrail toLink)
 {
     if (toLink)
     {
         if (!trails.Contains(toLink))
         {
             trails.Add(toLink);
         }
     }
 }
Ejemplo n.º 6
0
    public int GetTotalPhermoneWeights(PheromoneTrail excludeTrail)
    {
        int toReturn = 0;

        foreach (PheromoneTrail pt in trails)
        {
            if (pt != excludeTrail && pt != null)
            {
                toReturn += pt.strength;
            }
        }
        return(toReturn);
    }
Ejemplo n.º 7
0
    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);
    }
Ejemplo n.º 8
0
    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);
    }
Ejemplo n.º 9
0
    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
    }
Ejemplo n.º 10
0
 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.
             }
         }
     }
 }
Ejemplo n.º 11
0
 public Intersection(Vector2 _ip, PheromoneTrail _it)
 {
     _intersectionPoint = _ip;
     _intersectionTrail = _it;
 }
Ejemplo n.º 12
0
 public void DeleteTrail(PheromoneTrail pt)
 {
     pheromoneTrails.Remove(pt);
     Destroy(pt.gameObject);
 }
Ejemplo n.º 13
0
    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();
        }
    }
Ejemplo n.º 14
0
 //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);
 }