/// <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; } } } }
/// <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); }