Ejemplo n.º 1
0
        protected override void InternalUpdateSpread(GridSpace otherSpace)
        {
            // Water -> Water spread
            Component water;

            if (!otherSpace.m_components.TryGetValue(ComponentType.Water, out water))
            {
                // Adjacent space has no air so we need to create some
                water = otherSpace.AddType <Water>();
                water.m_amountRemaining = 0.0f;
            }

            float difference = m_amountRemaining - water.m_amountRemaining;

            // If the two spaces are close to a pressure equilibrium then don't bother doing anything.
            if (Mathf.Abs(difference) > 0.01f)
            {
                float average = (m_amountRemaining + water.m_amountRemaining) * 0.5f;

                // Water increases/decreases based on the adjacent space.
                float oldAmount = m_amountRemaining;
                float newAmount = Mathf.Lerp(m_amountRemaining, average, Simulation.DeltaTime * 0.25f);

                float delta = (newAmount - oldAmount);

                m_amountRemaining += delta;

                // The delta moves to/from the adjacent space
                water.m_amountRemaining -= delta;
            }
        }
Ejemplo n.º 2
0
        protected override void InternalUpdateChemistry(GridSpace selfSpace)
        {
            var interactions = selfSpace.m_components;

            // Fire burns some of the plant
            if (interactions.ContainsKey(ComponentType.Fire))
            {
                Debug.Log("Plant amount reduced by fire burning it.");

                // TODO: Could reduce the amount of air based on the amount of fire.

                // TODO: Burn rate of plant could depend on the type of plant

                m_amountRemaining -= Simulation.DeltaTime * 0.1f;
            }

            // Plants create air
            Component air = null;

            if (!interactions.TryGetValue(ComponentType.Air, out air))
            {
                // If no air exists then create some
                air = selfSpace.AddType <Air>();
            }

            // 1000 seconds to fill a grid space with air, if the plant is full size
            air.m_amountRemaining += Simulation.DeltaTime * 0.001f * m_amountRemaining;

            if (interactions.ContainsKey(ComponentType.Water))
            {
                Debug.Log("Plant growing because water is present.");

                // TODO: Could also require light to grow

                m_amountRemaining += Simulation.DeltaTime * 0.001f;
            }
            else
            {
                Debug.Log("Plant wilting because water is not present.");

                m_amountRemaining -= Simulation.DeltaTime * 0.0025f;
            }
        }
Ejemplo n.º 3
0
        private void FireToNewAreaSpread(GridSpace otherSpace)
        {
            // Random chance to spread (based on strength of fire)
            float roll = Random.Range(0.0f, m_amountRemaining);

            // 25% chance per second (if fire is full strength)
            float odds = 1 - 0.25f * Simulation.DeltaTime;

            // If we didn't beat the odds then the fire doesn't spread yet
            if (roll < odds)
            {
                return;
            }

            // Cannot be wet
            if (otherSpace.m_components.ContainsKey(ComponentType.Water))
            {
                return;
            }

            // Must have plant (fuel)
            if (!otherSpace.m_components.ContainsKey(ComponentType.Plant))
            {
                return;
            }

            // Must have enough air to spread
            Component air;

            if (!otherSpace.m_components.TryGetValue(ComponentType.Air, out air) || air.m_amountRemaining < 0.1f)
            {
                return;
            }

            Debug.LogWarning("Fire has spread to " + otherSpace.m_object.name);

            var fire = otherSpace.AddType <Fire>();

            fire.m_amountRemaining = 0.05f;    // Start new fire out small
        }