Esempio n. 1
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);
        }
Esempio n. 2
0
        public void Spawn(ElementID element, Point position, int size = 1)
        {
            if (!InBounds(position))
            {
                return;
            }

            tempMap = gameMap.GetTemperatureMap();

            if (size == 0)
            {
                if (!InBounds(position))
                {
                    return;
                }

                if (Type(position) == ElementID.AIR)
                {
                    if (!Element.elements.ContainsKey(element))
                    {
                        throw new Exception("Element: " + element + " not introduced in the elements dictionary yet.\nTry adding to ElementsSetup first.\n");
                    }

                    Particle p = new Particle(element, position);
                    particles[GetParticleID(position)] = p;
                    tempMap.Set(position, 0, Element.elements[element].STemp);
                }
            }
            else
            {
                int offset;
                if (size < 20)
                {
                    offset = 4;
                }
                else if (size < 50)
                {
                    offset = 6;
                }
                else
                {
                    offset = 10;
                }

                for (int y = size; y > -size; y--)
                {
                    for (int x = -size; x < size; x++)
                    {
                        if (size + offset >= x * x + y * y)
                        {
                            int   _x        = position.X + x;
                            int   _y        = position.Y + y;
                            Point _position = new Point(_x, _y);

                            if (!InBounds(_position))
                            {
                                continue;
                            }

                            if (Type(_position) == ElementID.AIR)
                            {
                                if (!Element.elements.ContainsKey(element))
                                {
                                    throw new Exception("Element: " + element + " not introduced in the elements dictionary yet.\nTry adding to ElementsSetup first.\n");
                                }

                                Particle p = new Particle(element, _position);
                                particles[GetParticleID(_position)] = p;
                                tempMap.Set(_position, 0, Element.elements[element].STemp);
                            }
                        }
                    }
                }
            }
        }