Exemplo n.º 1
0
        internal override void Update(int x, int y)
        {
            BoundedFloat bufferPower = new BoundedFloat(0, 0, powerinU.max + powerinD.max);

            base.powerInUCache = powerinU;
            base.powerInDCache = powerinD;

            bool cond = powerinU > 0 || powerinD > 0;

            BoundedFloat.MoveVals(ref powerinU, ref bufferPower, powerinU);
            BoundedFloat.MoveVals(ref powerinD, ref bufferPower, powerinD);

            EmptyInputs();

            base.EmptyOutputs();

            if (cond)
            {
                BoundedFloat.MoveVals(ref bufferPower, ref poweroutR, bufferPower);
            }

            base.powerOutRCache = poweroutR;

            base.UpdateR(x, y);
        }
Exemplo n.º 2
0
        internal override void Update(int x, int y)
        {
            //power input
            BoundedFloat buffer = new BoundedFloat(0, 0, powerinL.max + powerinR.max + powerinU.max + powerinD.max);

            powerInLCache = powerinL.val;
            powerInRCache = powerinR.val;
            powerInUCache = powerinU.val;
            powerInDCache = powerinD.val;

            BoundedFloat.MoveVals(ref powerinL, ref buffer, powerinL.val);
            BoundedFloat.MoveVals(ref powerinR, ref buffer, powerinR.val);
            BoundedFloat.MoveVals(ref powerinU, ref buffer, powerinU.val);
            BoundedFloat.MoveVals(ref powerinD, ref buffer, powerinD.val);

            EmptyInputs();

            buffer -= dissipate;

            //power output
            base.EmptyOutputs();

            int neighbouring = NeighbouringLogics(x, y);

            if (neighbouring != 0)
            {
                float transval = buffer.val / neighbouring;

                if (base.IsLogicL(x, y))
                {
                    BoundedFloat.MoveVals(ref buffer, ref poweroutL, transval);
                }

                if (base.IsLogicR(x, y))
                {
                    BoundedFloat.MoveVals(ref buffer, ref poweroutR, transval);
                }

                if (base.IsLogicU(x, y))
                {
                    BoundedFloat.MoveVals(ref buffer, ref poweroutU, transval);
                }

                if (base.IsLogicD(x, y))
                {
                    BoundedFloat.MoveVals(ref buffer, ref poweroutD, transval);
                }
            }

            powerOutLCache = poweroutL.val;
            powerOutRCache = poweroutR.val;
            powerOutUCache = poweroutU.val;
            powerOutDCache = poweroutD.val;

            state = poweroutL > 0 || poweroutR > 0 || poweroutU > 0 || poweroutD > 0;

            base.UpdateAll(x, y);

            Terrain.TileAt(x, y).enumId = state ? TileID.WireOn : TileID.WireOff;
        }
Exemplo n.º 3
0
        internal override void Update(int x, int y)
        {
            if (cooldown == null)
            {
                cooldown = new CooldownTimer(30);
            }

            BoundedFloat buffer = new BoundedFloat(0, 0, cost);

            CachePowerLevels();

            if (powerinL + powerinR + powerinD + powerinU >= buffer.max)
            {
                BoundedFloat.MoveVals(ref powerinL, ref buffer, powerinL);
                BoundedFloat.MoveVals(ref powerinR, ref buffer, powerinR);
                BoundedFloat.MoveVals(ref powerinD, ref buffer, powerinD);
                BoundedFloat.MoveVals(ref powerinU, ref buffer, powerinU);
            }

            EmptyInputs();

            if (buffer.IsFull())
            {
                state = true;

                var pos      = new Vector2(x - range, y - range);
                var size     = new Vector2(2 * range, 2 * range);
                var entities = EntityManager.GetEntitiesAt(pos, size, e => !(e is AutoDart || e is Player || e.data.invulnerable));

                if (cooldown.Ready())
                {
                    if (entities.Length > 0)
                    {
                        cooldown.Reset();

                        var e      = entities[MathUtil.RandInt(Program.Rand, 0, entities.Length - 1)];
                        var darvel = e.data.pos - new Vector2(x, y);
                        darvel = darvel.Normalize();
                        var dartpos = new Vector2(x, y);
                        dartpos += 1.5f * darvel;
                        darvel  /= 10;
                        var ad = new AutoDart(dartpos, darvel);
                        if (!ad.IsCollidingWithTerrain())
                        {
                            EntityManager.AddEntity(ad);
                        }
                    }
                    else
                    {
                        cooldown.SetTime(-100);
                    }
                }
            }
            else
            {
                state = false;
            }

            Terrain.TileAt(x, y).enumId = state ? TileID.AutoShooterOn : TileID.AutoShooterOff;
        }
Exemplo n.º 4
0
        internal override void Update(int x, int y)
        {
            src.val = (state ? src.max : 0);

            float transval = src.val / 4;

            BoundedFloat.MoveVals(ref src, ref poweroutL, transval);
            BoundedFloat.MoveVals(ref src, ref poweroutR, transval);
            BoundedFloat.MoveVals(ref src, ref poweroutU, transval);
            BoundedFloat.MoveVals(ref src, ref poweroutD, transval);

            PowerTransmitterData l = Terrain.TileAt(x - 1, y).tileattribs as PowerTransmitterData,
                                 r = Terrain.TileAt(x + 1, y).tileattribs as PowerTransmitterData,
                                 u = Terrain.TileAt(x, y + 1).tileattribs as PowerTransmitterData,
                                 d = Terrain.TileAt(x, y - 1).tileattribs as PowerTransmitterData;

            if (l != null)
            {
                BoundedFloat.MoveVals(ref poweroutL, ref l.powerinR, poweroutL.val);
            }
            if (r != null)
            {
                BoundedFloat.MoveVals(ref poweroutR, ref r.powerinL, poweroutR.val);
            }
            if (u != null)
            {
                BoundedFloat.MoveVals(ref poweroutU, ref u.powerinD, poweroutU.val);
            }
            if (d != null)
            {
                BoundedFloat.MoveVals(ref poweroutD, ref d.powerinU, poweroutD.val);
            }

            Terrain.TileAt(x, y).enumId = state ? TileID.SwitchOn : TileID.SwitchOff;
        }
Exemplo n.º 5
0
        protected void UpdateR(int x, int y)
        {
            PowerTransmitterData tr = Terrain.TileAt(x + 1, y).tileattribs as PowerTransmitterData;

            if (tr != null)
            {
                BoundedFloat.MoveVals(ref poweroutR, ref tr.powerinL, poweroutR.val);
            }

            PowerDrainData dr = Terrain.TileAt(x + 1, y).tileattribs as PowerDrainData;

            if (dr != null)
            {
                BoundedFloat.MoveVals(ref poweroutR, ref dr.powerinL, poweroutR.val);
            }
        }
Exemplo n.º 6
0
        protected void UpdateL(int x, int y)
        {
            PowerTransmitterData tl = Terrain.TileAt(x - 1, y).tileattribs as PowerTransmitterData;

            if (tl != null)
            {
                BoundedFloat.MoveVals(ref poweroutL, ref tl.powerinR, poweroutL.val);
            }

            PowerDrainData dl = Terrain.TileAt(x - 1, y).tileattribs as PowerDrainData;

            if (dl != null)
            {
                BoundedFloat.MoveVals(ref poweroutL, ref dl.powerinR, poweroutL.val);
            }
        }
Exemplo n.º 7
0
        protected void UpdateD(int x, int y)
        {
            PowerTransmitterData td = Terrain.TileAt(x, y - 1).tileattribs as PowerTransmitterData;

            if (td != null)
            {
                BoundedFloat.MoveVals(ref poweroutD, ref td.powerinU, poweroutD.val);
            }

            PowerDrainData dd = Terrain.TileAt(x, y - 1).tileattribs as PowerDrainData;

            if (dd != null)
            {
                BoundedFloat.MoveVals(ref poweroutD, ref dd.powerinU, poweroutD.val);
            }
        }
Exemplo n.º 8
0
        protected void UpdateU(int x, int y)
        {
            PowerTransmitterData tu = Terrain.TileAt(x, y + 1).tileattribs as PowerTransmitterData;

            if (tu != null)
            {
                BoundedFloat.MoveVals(ref poweroutU, ref tu.powerinD, poweroutU.val);
            }

            PowerDrainData du = Terrain.TileAt(x, y + 1).tileattribs as PowerDrainData;

            if (du != null)
            {
                BoundedFloat.MoveVals(ref poweroutU, ref du.powerinD, poweroutU.val);
            }
        }
Exemplo n.º 9
0
        internal override void Update(int x, int y)
        {
            if (cooldown == null)
            {
                cooldown = new CooldownTimer(40);
            }

            BoundedFloat buffer = new BoundedFloat(0, 0, cost);

            CachePowerLevels();

            if (powerinL + powerinR + powerinU + powerinD >= buffer.max)
            {
                BoundedFloat.MoveVals(ref powerinL, ref buffer, powerinL);
                BoundedFloat.MoveVals(ref powerinR, ref buffer, powerinR);
                BoundedFloat.MoveVals(ref powerinU, ref buffer, powerinU);
                BoundedFloat.MoveVals(ref powerinD, ref buffer, powerinD);
            }

            EmptyInputs();

            if (buffer.IsFull())
            {
                state = true;
                if (cooldown.Ready())
                {
                    HashSet <Vector2i> done;
                    if (PushTilesHelper(x, y, out done))
                    {
                        var list = done.ToList();
                        list.Sort(new TilePositionComparer());
                        foreach (var v in list)
                        {
                            //here
                            Terrain.MoveTile(v.x, v.y, rotation);
                        }
                        cooldown.Reset();
                    }
                }
            }
            else
            {
                state = false;
            }

            Terrain.TileAt(x, y).enumId = state ? TileID.TilePusherOn : TileID.TilePusherOff;
        }
Exemplo n.º 10
0
        internal override void Update(int x, int y)
        {
            BoundedFloat buffer = new BoundedFloat(0, 0, cost);

            CachePowerLevels();

            BoundedFloat.MoveVals(ref powerinL, ref buffer, powerinL.val);
            BoundedFloat.MoveVals(ref powerinR, ref buffer, powerinR.val);
            BoundedFloat.MoveVals(ref powerinU, ref buffer, powerinU.val);
            BoundedFloat.MoveVals(ref powerinD, ref buffer, powerinD.val);

            EmptyInputs();

            state = buffer.IsFull();

            Terrain.TileAt(x, y).enumId = state ? TileID.LogicLampOn : TileID.LogicLampOff;
        }
Exemplo n.º 11
0
        internal override void Update(int x, int y)
        {
            if (entityCage == null)
            {
                entityCage = new EntityCage(new Vector2(x, y + 1));
                EntityManager.AddEntity(entityCage);
            }

            if (cooldown == null)
            {
                cooldown = new CooldownTimer(100);
            }

            BoundedFloat buffer = new BoundedFloat(0, 0, cost);

            CachePowerLevels();

            if (powerinL + powerinR + powerinD >= buffer.max)
            {
                BoundedFloat.MoveVals(ref powerinL, ref buffer, powerinL);
                BoundedFloat.MoveVals(ref powerinR, ref buffer, powerinR);
                BoundedFloat.MoveVals(ref powerinD, ref buffer, powerinD);
            }

            EmptyInputs();

            if (buffer.IsFull())
            {
                state = true;
                if (cooldown.Ready())
                {
                    Spawn(x, y);
                    cooldown.Reset();
                }
            }
            else
            {
                state = false;
            }

            Terrain.TileAt(x, y).enumId = state ? TileID.EntitySpawnerOn : TileID.EntitySpawnerOff;
        }
Exemplo n.º 12
0
        internal override void Update(int x, int y)
        {
            BoundedFloat bufferHorz = new BoundedFloat(0, 0, powerinL.max + powerinR.max);
            BoundedFloat bufferVert = new BoundedFloat(0, 0, powerinU.max + powerinD.max);

            powerInLCache = powerinL.val;
            powerInRCache = powerinR.val;
            powerInUCache = powerinU.val;
            powerInDCache = powerinD.val;

            BoundedFloat.MoveVals(ref powerinL, ref bufferHorz, powerinL.val);
            BoundedFloat.MoveVals(ref powerinR, ref bufferHorz, powerinR.val);
            BoundedFloat.MoveVals(ref powerinU, ref bufferVert, powerinU.val);
            BoundedFloat.MoveVals(ref powerinD, ref bufferVert, powerinD.val);

            EmptyInputs();

            bufferHorz -= dissipate;
            bufferVert -= dissipate;

            int neighbourHorz = base.NeighbouringLogics(x, y);
            int neighbourVert = base.NeighbouringLogics(x, y);

            if (neighbourHorz != 0)
            {
                float transval = bufferHorz / neighbourHorz;

                if (base.IsLogicL(x, y))
                {
                    BoundedFloat.MoveVals(ref bufferHorz, ref poweroutL, transval);
                }

                if (base.IsLogicR(x, y))
                {
                    BoundedFloat.MoveVals(ref bufferHorz, ref poweroutR, transval);
                }
            }
            if (neighbourVert != 0)
            {
                float transval = bufferVert / neighbourVert;
                if (base.IsLogicU(x, y))
                {
                    BoundedFloat.MoveVals(ref bufferHorz, ref poweroutU, transval);
                }
                if (base.IsLogicD(x, y))
                {
                    BoundedFloat.MoveVals(ref bufferHorz, ref poweroutD, transval);
                }
            }

            powerOutLCache = poweroutL.val;
            powerOutRCache = poweroutR.val;
            powerOutUCache = poweroutU.val;
            powerOutDCache = poweroutD.val;

            stateHorz = poweroutL > 0 || poweroutR > 0;
            stateVert = poweroutU > 0 || poweroutD > 0;

            base.UpdateAll(x, y);

            Terrain.TileAt(x, y).enumId = stateHorz ? (stateVert ? TileID.WireBridgeHorzVertOn : TileID.WireBridgeHorzOn) : (stateVert ? TileID.WireBridgeVertOn : TileID.WireBridgeOff);
        }