Пример #1
0
 public void BornAnt(double x, double y, string name)
 {
     Ants.Add(new WorkerAnt(x, y, name, null));
 }
Пример #2
0
 /// <summary>
 /// Adds a ant to the ant cache.
 /// </summary>
 /// <param name="ant">The given ant.</param>
 public void Add(Ant ant) => Ants.Add(ant);
Пример #3
0
    private void SpawnColony(Transform ants)
    {
        var antPrefab = Resources.Load(Naming.Resources.AntPrefab) as GameObject;

        Transform passive = MakeObject("P0", ants).transform;

        NestInfo.Add(new NestInfo(initialNest.NestManager(), 0, true,
                                  MakeObject(Naming.Ants.BehavourState.Assessing + "0", ants),
                                  MakeObject(Naming.Ants.BehavourState.Recruiting + "0", ants),
                                  passive.gameObject,
                                  MakeObject(Naming.Ants.BehavourState.Reversing + "0", ants)
                                  ));

        // Local variables for ant setup
        //find size of square to spawn ants into
        float sqrt             = Mathf.Ceil(Mathf.Sqrt(Settings.ColonySize.Value)); //?
        int   spawnedAnts      = 0;
        int   spawnedAntScouts = 0;

        //just spawns ants in square around wherever this is placed
        while (spawnedAnts < Settings.ColonySize.Value)
        {
            int column = 0;
            while ((column == 0 || spawnedAnts % sqrt != 0) && spawnedAnts < Settings.ColonySize.Value)
            {
                float   row = Mathf.Floor(spawnedAnts / sqrt);
                Vector3 pos = initialNest.transform.position;
                //?
                pos.x -= 1;
                pos.z -= 1;

                GameObject newAnt = Instantiate(antPrefab, pos + (new Vector3(row, 0, column) * Length.v[Length.Spawning]), Quaternion.identity);
                newAnt.transform.position += new Vector3(0, newAnt.GetComponent <CapsuleCollider>().radius * 2, 0);
                newAnt.name = CreateAntId(Settings.ColonySize.Value, spawnedAnts);
                newAnt.AntMovement().simulation = this;

                AntManager newAM = newAnt.AntManager();

                Ants.Add(newAM);

                newAM.AntId  = spawnedAnts;
                newAM.myNest = initialNest.NestManager();
                // why is there 2 of this here? is it meant to be old nest or something
                // newAM.myNest = initialNest;
                newAM.simulation        = this;
                newAM.inNest            = true;
                newAM.quorumThreshold   = Settings.QuorumThreshold.Value;
                newAnt.transform.parent = passive;

                if (spawnedAnts < Settings.ColonySize.Value * Settings.ProportionActive.Value || Settings.ColonySize.Value <= 1 || _spawnOnlyScouts)
                {
                    newAM.state   = BehaviourState.Inactive;
                    newAM.passive = false;
                    newAnt.GetComponentInChildren <Renderer>().material.color = AntColours.States.Inactive;

                    Transform senses = newAnt.transform.Find(Naming.Ants.SensesArea);
                    (senses.GetComponent <SphereCollider>()).enabled = true;
                    (senses.GetComponent <SphereCollider>()).radius  = Length.v[Length.SensesCollider];
                    (senses.GetComponent <AntSenses>()).enabled      = true;

                    if (spawnedAntScouts < InitialScouts || Settings.ColonySize.Value <= 1 || _spawnOnlyScouts)
                    {
                        newAM.nextAssessment = TotalElapsedSimulatedTime("s") + RandomGenerator.Instance.Range(0.5f, 1f) * Times.v[Times.MaxAssessmentWait];
                        spawnedAntScouts++;
                    }
                    else
                    {
                        newAM.nextAssessment = 0;
                    }
                }
                else
                {
                    // Passive ant
                    newAM.passive = true;
                    newAnt.GetComponentInChildren <Renderer>().material.color = AntColours.States.InactivePassive;
                }

                column++;
                spawnedAnts++;
            }
        }
    }