示例#1
0
        /// <summary>
        /// This is used to reset the workers items, for example when there is a genocide,
        /// when going to the next curriculum lesson ...
        /// </summary>
        private void Reset()
        {
            // Curriculum can't be in the reverse order atm (can't increase amount of workers) anyway no point in doing that, yet?

            /*
             * while (workerObjects.Count > WorkerCarniHerbi.AmountOfWorkers)
             * {
             *  var tmp = workerObjects.Last();
             *  ReleaseAgentsInWorker(tmp);
             *  workerObjects.Remove(tmp);
             *  Destroy(tmp.gameObject); // TODO : we are destroying non-agents items, check if not breaking references
             * }*/

            foreach (var workerObject in workerObjects)
            {
                /*
                 * // If the ground scale changed it means new curriculum lesson
                 * if ((int) workerObject.transform.Find("Ground").localScale.x != GroundScale)
                 * {
                 *  // Reposition grounds to adapt to the new ground scale
                 *  workerObject.transform.position = new Vector3(
                 *      (int) ((workerObject.transform.position.x + GroundScale) * 2),
                 *      workerObject.transform.position.y,
                 *      workerObject.transform.position.z);
                 *
                 *  // Then set the new ground scale
                 *  workerObject.transform.Find("Ground").localScale = new Vector3(GroundScale,
                 *      1,
                 *      GroundScale);
                 *
                 *  // Adding herbs
                 *  for (int i = 0;
                 *      i < WorkerCarniHerbi.AmountOfAgentsToAdd -
                 *      workerObject.GetComponentsInChildren(typeof(Herb)).Length;
                 *      i++)
                 *  {
                 *      GameObject herbChild = herbPool.GetObject();
                 *      herbChild.transform.parent = workerObject.transform;
                 *      herbChild.SetActive(true);
                 *      herbChild.GetComponent<Herb>().ResetPosition(workerObject.transform);
                 *  }
                 *
                 *  foreach (Herb h in workerObject.GetComponentsInChildren<Herb>())
                 *      h.ResetPosition(workerObject.transform);
                 * }*/



                // The last condition is only useful in reproduction mode
                if (workerObject.second.GetComponentsInChildren <CarnivorousAgent>().Length == 0 ||
                    workerObject.second.GetComponentsInChildren <HerbivorousAgent>().Length == 0 ||
                    workerObject.second.GetComponentsInChildren <LivingBeingAgent>().Length >
                    WorkerCarniHerbi.AmountOfAgentsToAdd * 10)
                {
                    // The god agent can tweak number of elements to add
                    WorkerCarniHerbi.AmountOfAgentsToAdd = godChild.GetComponent <GodAgent>().ElementsToSpawn;

                    // Life length of the worker
                    workerObject.first.second = evolAcademy.GetStepCount() - workerObject.first.first;

                    // Latest reset in term of steps
                    workerObject.first.first = evolAcademy.GetStepCount();

                    if (workerObject.second.GetComponentsInChildren <CarnivorousAgent>().Length == 0)
                    {
                        carnivorousSpecieLifeExpectancyGauge.Set(workerObject.first.second);
                        godChild.GetComponent <GodAgent>().CarnivorousSpeciesLifeExpectancy = workerObject.first.second;
                    }

                    if (workerObject.second.GetComponentsInChildren <HerbivorousAgent>().Length == 0)
                    {
                        herbivorousSpecieLifeExpectancyGauge.Set(workerObject.first.second);
                        godChild.GetComponent <GodAgent>().HerbivorousSpeciesLifeExpectancy = workerObject.first.second;
                    }


                    resetCounter.Inc(1.1);
                    ReleaseAgentsInWorker(workerObject.second);
                    for (var i = 0; i < WorkerCarniHerbi.AmountOfAgentsToAdd; i++)
                    {
                        var carnivorousChild = carnivorousPool.GetObject();
                        carnivorousChild.transform.parent = workerObject.second.transform;
                        carnivorousChild.SetActive(true);
                        carnivorousChild.GetComponent <LivingBeingAgent>().ResetPosition(workerObject.second.transform);
                        // carnivorousChild.GetComponent<LivingBeingAgent>().LivingBeing.Speed =
                        //    evolAcademy.resetParameters["speed"];

                        var herbivorousChild = herbivorousPool.GetObject();
                        herbivorousChild.transform.parent = workerObject.second.transform;
                        herbivorousChild.SetActive(true);
                        herbivorousChild.GetComponent <LivingBeingAgent>().ResetPosition(workerObject.second.transform);
                    }
                }
            }
        }