예제 #1
0
        void UpdateReaction(ParticleMap partMap, TemperatureMap tempMap)
        {
            bool pass;

            if (!stable)
            {
                pass = stable;
            }
            else
            {
                // even if stable check for reactions regularly (tanks performance)
                pass = !(stableTime % 10 == 0);
            }
            ElementID result = Element.elements[ID].UpdateReaction(pos, lifeTime, pass, partMap, tempMap);

            if (result != this.ID)
            {
                SetStable(false);
                partMap.UnstableSurroundingParticles(this.pos);
                unstableTimeout = 0;

                if (result == ElementID.VOID) // void == deleted
                {
                    partMap.DeleteLater(this.pos, 0);
                    SetStable(true); //dont update pos after deleting
                }
                else if (result == ElementID.EXPLOSION)
                {
                    partMap.DeleteLater(this.pos, 0);
                    partMap.SpawnLater(ElementID.FIRE, this.pos, Element.elements[ID].ExplosivePwr);
                    SetStable(true); //dont update pos after deleting
                }
                else
                {
                    this.ID       = result;
                    this.lifeTime = 0;
                }
            }
        }
예제 #2
0
        public ElementID UpdateReaction(Point pos, int lifeTime, bool stable, ParticleMap partMap, TemperatureMap tempMap)
        {
            if (!stable)
            {
                foreach (Reaction r in this.reactions) // evaluate all possible reactions
                {
                    if (r.Eval(pos, partMap, out List <ElementID> result, out Point destroy))
                    {
                        //spawn other results around this particle
                        for (int i = 1; i < result.Count; i++)
                        {
                            if (partMap.Type(new Point(pos.X, pos.Y - 1)) == ElementID.AIR)
                            {
                                partMap.SpawnLater(result[i], new Point(pos.X, pos.Y - 1), 1);
                            }

                            else if (partMap.Type(new Point(pos.X, pos.Y + 1)) == ElementID.AIR)
                            {
                                partMap.SpawnLater(result[i], new Point(pos.X, pos.Y + 1), 1);
                            }

                            else if (partMap.Type(new Point(pos.X - 1, pos.Y)) == ElementID.AIR)
                            {
                                partMap.SpawnLater(result[i], new Point(pos.X - 1, pos.Y), 1);
                            }

                            else if (partMap.Type(new Point(pos.X + 1, pos.Y)) == ElementID.AIR)
                            {
                                partMap.SpawnLater(result[i], new Point(pos.X + 1, pos.Y), 1);
                            }
                        }

                        if (partMap.InBounds(destroy))
                        {
                            partMap.DeleteLater(destroy, 0);
                        }

                        return(result[0]);
                    }
                }
            }

            // evaluate preset transitional reactons
            if (lowLevelTempTransition != null && tempMap.Get(pos) <= lowLevelTemp)
            {
                if (lowLevelTempTransition.Eval(pos, partMap, out List <ElementID> result, out Point destroy))
                {
                    tempMap.Set(pos, 0, tempMap.Get(pos) * 1.05f);
                    return(result[0]);
                }
            }
            if (highLevelTempTransition != null && tempMap.Get(pos) >= highLevelTemp)
            {
                if (highLevelTempTransition.Eval(pos, partMap, out List <ElementID> result, out Point destroy))
                {
                    tempMap.Set(pos, 0, tempMap.Get(pos) * 0.95f);
                    return(result[0]);
                }
            }

            if (endOfLifeTransition != null && lifeTime > this.maxLifeTime)
            {
                if (endOfLifeTransition.Eval(pos, partMap, out List <ElementID> result, out Point destroy))
                {
                    return(result[0]);
                }
            }

            return(this.ID);
        }