Exemplo n.º 1
0
        private void DivideMicroorganism(PetriDishSlot petriDishSlot)
        {
            // TODO: Prototype binary division procedure.

            int[] intRange = Enumerable.Range(0, 6).ToArray();

            intRange = Utils.RandomizeArray(intRange);

            for (int i = 0; i < 6; i++)
            {
                int j = intRange[i];

                Hex hex = Hex.Neighbour(petriDishSlot, j);

                PetriDishSlot neighbour = (PetriDishSlot)hexMap.GetHexAt(hex);

                if (neighbour != null)
                {
                    if (neighbour.Microorganism == null)
                    {
                        PerformDivisionToHex(petriDishSlot, neighbour);

                        return;
                    }
                }
            }

            // TODO: If no target around was found, we can count how many divisions were limited by space.
        }
Exemplo n.º 2
0
 private void Decay(PetriDishSlot petriDishSlot)
 {
     // TODO: Prototype microorganism-pollutant consumption method.
     petriDishSlot.SetMicroorganism(
         petriDishSlot.Microorganism,
         petriDishSlot.MicroorganismAmount - petriDishSlot.Microorganism.PassiveEnergyLoss);
 }
Exemplo n.º 3
0
        public static void CalculateNewTick(Dictionary <Consumption, float> consumptionPerMicroorganism, bool updateGraph)
        {
            List <Hex> hexes = CurrentSimulation.hexMap.AllHexes;
            Tick       tick  = CurrentSimulation.GetNextTick();

            if (!(consumptionPerMicroorganism is null))
            {
                tick.ConsumptionPerMicroorganism = consumptionPerMicroorganism;
            }

            foreach (Hex hex in hexes)
            {
                PetriDishSlot petriDishSlot = (PetriDishSlot)hex;

                if (!(petriDishSlot.Microorganism is null))
                {
                    tick.MicroorganismAmount[petriDishSlot.Microorganism] += petriDishSlot.MicroorganismAmount;
                }

                if (!(petriDishSlot.Pollutant is null))
                {
                    tick.PollutantAmount[petriDishSlot.Pollutant] += petriDishSlot.PollutantAmount;
                }
            }

            if (updateGraph)
            {
                UpdateGraph(tick);
            }

            NextTick = tick.Day + 1;
        }
Exemplo n.º 4
0
        private void PerformDivisionToHex(PetriDishSlot origin, PetriDishSlot target)
        {
            target.AddMicroorganism(origin.Microorganism, origin.MicroorganismAmount / 2);

            origin.SetMicroorganism(
                origin.Microorganism,
                origin.MicroorganismAmount / 2);
        }
Exemplo n.º 5
0
        /// <summary>
        /// Handles every keybind and how they interact with the game.
        ///
        /// Does not account for GUI input
        /// </summary>
        private void HandleControls()
        {
            if (Input.GetMouseButton(0))
            {
                Hex mouseHex = Hex.FindHexAtMousePosition();

                if (mouseHex != null)
                {
                    List <Hex> petriDishSlots;

                    switch (selectedElementType)
                    {
                    case ElementType.MICROORGANISM:
                        petriDishSlots = hexMap.GetHexesWithin(new Hex(mouseHex.Q, mouseHex.R), Config.INSERTION_RADIUS_MICROORGANISM).ToList();

                        Dictionary <string, Microorganism> microorganisms = Repository.GetMicroorganismsDictionary();

                        foreach (Hex hex in petriDishSlots)
                        {
                            PetriDishSlot petriDishSlot = (PetriDishSlot)hex;

                            petriDishSlot.SetMicroorganism(microorganisms[selectedElement], Config.SLOT_MAX_MICROORGANISMS * 0.5f);
                        }

                        break;

                    case ElementType.POLLUTANT:
                        petriDishSlots = hexMap.GetHexesWithin(new Hex(mouseHex.Q, mouseHex.R), Config.INSERTION_RADIUS_POLLUTANT).ToList();

                        Dictionary <string, Pollutant> pollutants = Repository.GetPollutantsDictionary();

                        foreach (Hex hex in petriDishSlots)
                        {
                            PetriDishSlot petriDishSlot = (PetriDishSlot)hex;

                            petriDishSlot.SetPollutant(pollutants[selectedElement], Config.SLOT_MAX_POLLUTANTS);
                        }

                        break;

                    default:
                        break;
                    }
                }
            }
        }
Exemplo n.º 6
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="petriDishSlot">The tile slot to be simulated</param>
        /// <returns>The amount consumed by the microorganism</returns>
        private float Feed(PetriDishSlot petriDishSlot)
        {
            // The return value to be calculated as how much of the pollutant the microorganism has consumed.
            float amountConsumed = 0;

            if (petriDishSlot == null)
            {
                ErrorHandler.LogError("Method Feed() was called with a null argument.", new ArgumentNullException("petriDishSlot"));
            }

            // Performs the basic energy decay step. The microorganism will lose its base energy consumption.
            Decay(petriDishSlot);

            if (petriDishSlot.Microorganism != null && petriDishSlot.Pollutant != null)
            {
                float reaction = Repository.GetReaction(
                    petriDishSlot.Microorganism,
                    petriDishSlot.Pollutant);

                // Generates a random deviation multiplier from the expected reaction,
                // ranging from -1.0f to 1.0f.
                float deviation = (UnityEngine.Random.value - 0.5f) * 2;

                reaction += deviation * Config.MICROORGANISM_CONSUMPTION_RANDOM_VARIATION;

                amountConsumed = Mathf.Min(
                    Config.SLOT_MAX_MICROORGANISMS - petriDishSlot.MicroorganismAmount,
                    Mathf.Min(petriDishSlot.PollutantAmount, reaction));

                petriDishSlot.SetMicroorganism(
                    petriDishSlot.Microorganism,
                    petriDishSlot.MicroorganismAmount + amountConsumed);

                // Takes away a Difference amount of energy from the pollutant, regardless of whether
                // it is positive or negative. It will be negative when the Microorganism reacts to
                // the Pollutant by losing energy. The Pollutant will be not be consumed if it is
                // poisonous to the microorganism.
                petriDishSlot.SetPollutant(
                    petriDishSlot.Pollutant,
                    petriDishSlot.PollutantAmount - amountConsumed);
            }

            return(amountConsumed);
        }
Exemplo n.º 7
0
        /// <summary>
        /// Creates all Hexes in the map and initiates the Hexes property.
        ///
        /// TODO: Make this method abstract and allow other classes that implement HexMap to change this behavior.
        /// </summary>
        public void Generate()
        {
            // If it is not the first time this method is called, this will clear
            // the arrays storing data that is soon to be deleted/destroyed
            hexes = null;
            AllHexes.Clear();

            // Remove any possible previously generated hexes
            for (int i = 0; i < transform.childCount; i++)
            {
                Destroy(transform.GetChild(i).gameObject);
            }

            int diameter = Radius * 2 + 1;

            // Instancing the hexes array in its proper size
            hexes = new Hex[diameter, diameter];

            for (int row = 0; row < diameter; row++)
            {
                // Making the map hexagon-shaped
                int minColumn = Mathf.Clamp(Radius - row, 0, Radius);
                int maxColumn = Mathf.Clamp(diameter, 0, diameter + Radius - row);

                for (int column = minColumn; column < maxColumn; column++)
                {
                    // Instantiate the hexagon object
                    GameObject go = Instantiate(
                        HexPrefab,
                        Vector3.zero,
                        Quaternion.identity,
                        transform);

                    // Creating the abstract representation of a hexagon in cubic coordinates and storing it in the Hex arrays
                    PetriDishSlot hex = new PetriDishSlot(column, row, go);
                    hexes[column, row] = hex;
                    AllHexes.Add(hex);

                    // Makes this object pretty in Unity's inspector
                    go.name = "(" + hex.Q + ", " + hex.R + ", " + hex.S + ")";
                    go.transform.position = hex.WorldPosition;

                    // Instantiate the petri dish model
                    if (petriDish is null && row == column && row == Radius)
                    {
                        petriDish = Instantiate(
                            PetriDishPrefab,
                            hex.WorldPosition,
                            Quaternion.identity);

                        petriDish.transform.localScale = new Vector3(
                            diameter,
                            diameter,
                            diameter);
                    }
                }
            }

            // Updates the total hex count
            CachedHexCount = AllHexes.Count;

            // Centers camera around this petri dish
            SetCameraPosition(petriDish);
        }