Ejemplo n.º 1
0
        public Missile(MissileInfo info, ProjectileArgs args)
        {
            Info = info;
            Args = args;

            SubPxPosition = Args.src.ToPSubPos();
            Altitude = Args.srcAltitude;
            Facing = Args.facing;

            if (info.Inaccuracy > 0)
                offset = (PVecInt)(info.Inaccuracy * args.firedBy.World.SharedRandom.Gauss2D(2)).ToInt2();

            if (Info.Image != null)
            {
                anim = new Animation(Info.Image, () => Facing);
                anim.PlayRepeating("idle");
            }

            if (Info.ContrailLength > 0)
            {
                Trail = new ContrailHistory(Info.ContrailLength,
                    Info.ContrailUsePlayerColor ? ContrailHistory.ChooseColor(args.firedBy) : Info.ContrailColor,
                    Info.ContrailDelay);
            }
        }
Ejemplo n.º 2
0
        public Missile(MissileInfo info, ProjectileArgs args)
        {
            Info = info;
            Args = args;

            SubPxPosition = Args.src.ToPSubPos();
            Altitude      = Args.srcAltitude;
            Facing        = Args.facing;

            if (info.Inaccuracy > 0)
            {
                offset = (PVecInt)(info.Inaccuracy * args.firedBy.World.SharedRandom.Gauss2D(2)).ToInt2();
            }

            if (Info.Image != null)
            {
                anim = new Animation(Info.Image, () => Facing);
                anim.PlayRepeating("idle");
            }

            if (Info.ContrailLength > 0)
            {
                Trail = new ContrailHistory(Info.ContrailLength,
                                            Info.ContrailUsePlayerColor ? ContrailHistory.ChooseColor(args.firedBy) : Info.ContrailColor,
                                            Info.ContrailDelay);
            }
        }
Ejemplo n.º 3
0
        public Aircraft(ActorInitializer init, AircraftInfo info)
        {
            this.self = init.self;
            if (init.Contains <LocationInit>())
            {
                this.SubPxPosition = Util.CenterOfCell(init.Get <LocationInit, CPos>()).ToPSubPos();
            }

            this.Facing   = init.Contains <FacingInit>() ? init.Get <FacingInit, int>() : info.InitialFacing;
            this.Altitude = init.Contains <AltitudeInit>() ? init.Get <AltitudeInit, int>() : 0;
            Info          = info;
        }
Ejemplo n.º 4
0
        public void Tick(World world)
        {
            t += 40;

            // In pixels
            var dist = Args.target.CenterLocation + offset - PxPosition;

            var targetAltitude = 0;
            if (Args.target.IsValid && Args.target.IsActor && Args.target.Actor.HasTrait<IMove>())
                targetAltitude = Args.target.Actor.Trait<IMove>().Altitude;

            var jammed = Info.Jammable && world.ActorsWithTrait<JamsMissiles>().Any(tp =>
                (tp.Actor.CenterLocation - PxPosition).ToCVec().Length <= tp.Trait.Range

                && (tp.Actor.Owner.Stances[Args.firedBy.Owner] != Stance.Ally
                || (tp.Actor.Owner.Stances[Args.firedBy.Owner] == Stance.Ally && tp.Trait.AlliedMissiles))

                && world.SharedRandom.Next(100 / tp.Trait.Chance) == 0);

            if (!jammed)
            {
                Altitude += Math.Sign(targetAltitude - Altitude);
                if (Args.target.IsValid)
                    Facing = Traits.Util.TickFacing(Facing,
                        Traits.Util.GetFacing(dist, Facing),
                        Info.ROT);
            }
            else
            {
                Altitude += world.SharedRandom.Next(-1, 2);
                Facing = Traits.Util.TickFacing(Facing,
                    Facing + world.SharedRandom.Next(-20, 21),
                    Info.ROT);
            }

            anim.Tick();

            if (dist.LengthSquared < MissileCloseEnough * MissileCloseEnough && Args.target.IsValid)
                Explode(world);

            // TODO: Replace this with a lookup table
            var dir = (-float2.FromAngle((float)(Facing / 128f * Math.PI))).ToPSubVec();

            var move = Info.Speed * dir;
            if (targetAltitude > 0 && Info.TurboBoost)
                move = (move * 3) / 2;
            move = move / 5;

            SubPxPosition += move;

            if (Info.Trail != null)
            {
                var sp = ((SubPxPosition - (move * 3) / 2)).ToPPos() - new PVecInt(0, Altitude);

                if (--ticksToNextSmoke < 0)
                {
                    world.AddFrameEndTask(w => w.Add(new Smoke(w, sp, Info.Trail)));
                    ticksToNextSmoke = Info.TrailInterval;
                }
            }

            if (Info.RangeLimit != 0 && t > Info.RangeLimit * 40)
                Explode(world);

            if (!Info.High)		// check for hitting a wall
            {
                var cell = PxPosition.ToCPos();
                if (world.ActorMap.GetUnitsAt(cell).Any(a => a.HasTrait<IBlocksBullets>()))
                    Explode(world);
            }

            if (Trail != null)
                Trail.Tick(PxPosition.ToWPos(Altitude));
        }
Ejemplo n.º 5
0
        public void Tick( World world )
        {
            t += 40;

            // In pixels
            var dist = Args.target.CenterLocation + offset - PxPosition;

            var targetAltitude = 0;
            if (Args.target.IsValid && Args.target.IsActor && Args.target.Actor.HasTrait<IMove>())
                targetAltitude =  Args.target.Actor.Trait<IMove>().Altitude;

            Altitude += Math.Sign(targetAltitude - Altitude);

            if (Args.target.IsValid)
                Facing = Traits.Util.TickFacing(Facing,
                    Traits.Util.GetFacing(dist, Facing),
                    Info.ROT);

            anim.Tick();

            if (dist.LengthSquared < MissileCloseEnough * MissileCloseEnough && Args.target.IsValid )
                Explode(world);

            // TODO: Replace this with a lookup table
            var dir = (-float2.FromAngle((float)(Facing / 128f * Math.PI))).ToPSubVec();

            var move = Info.Speed * dir;
            if (targetAltitude > 0 && Info.TurboBoost)
                move = (move * 3) / 2;
            move = move / 5;

            SubPxPosition += move;

            if (Info.Trail != null)
            {
                var sp = ((SubPxPosition - (move * 3) / 2)).ToPPos() - new PVecInt(0, Altitude);

                if (--ticksToNextSmoke < 0)
                {
                    world.AddFrameEndTask(w => w.Add(new Smoke(w, sp, Info.Trail)));
                    ticksToNextSmoke = Info.TrailInterval;
                }
            }

            if (Info.RangeLimit != 0 && t > Info.RangeLimit * 40)
                Explode(world);

            if (!Info.High)		// check for hitting a wall
            {
                var cell = PxPosition.ToCPos();
                if (world.ActorMap.GetUnitsAt(cell).Any(a => a.HasTrait<IBlocksBullets>()))
                    Explode(world);
            }

            if (Trail != null)
                Trail.Tick(PxPosition - new PVecInt(0, Altitude));
        }
Ejemplo n.º 6
0
        public void Tick(World world)
        {
            t += 40;

            // In pixels
            var dist = Args.target.CenterLocation + offset - PxPosition;

            var targetAltitude = 0;

            if (Args.target.IsValid && Args.target.IsActor && Args.target.Actor.HasTrait <IMove>())
            {
                targetAltitude = Args.target.Actor.Trait <IMove>().Altitude;
            }

            Altitude += Math.Sign(targetAltitude - Altitude);

            if (Args.target.IsValid)
            {
                Facing = Traits.Util.TickFacing(Facing,
                                                Traits.Util.GetFacing(dist, Facing),
                                                Info.ROT);
            }

            anim.Tick();

            if (dist.LengthSquared < MissileCloseEnough * MissileCloseEnough && Args.target.IsValid)
            {
                Explode(world);
            }

            // TODO: Replace this with a lookup table
            var dir = (-float2.FromAngle((float)(Facing / 128f * Math.PI))).ToPSubVec();

            var move = Info.Speed * dir;

            if (targetAltitude > 0 && Info.TurboBoost)
            {
                move = (move * 3) / 2;
            }
            move = move / 5;

            SubPxPosition += move;

            if (Info.Trail != null)
            {
                var sp = ((SubPxPosition - (move * 3) / 2)).ToPPos() - new PVecInt(0, Altitude);

                if (--ticksToNextSmoke < 0)
                {
                    world.AddFrameEndTask(w => w.Add(new Smoke(w, sp, Info.Trail)));
                    ticksToNextSmoke = Info.TrailInterval;
                }
            }

            if (Info.RangeLimit != 0 && t > Info.RangeLimit * 40)
            {
                Explode(world);
            }

            if (!Info.High)                     // check for hitting a wall
            {
                var cell = PxPosition.ToCPos();
                if (world.ActorMap.GetUnitsAt(cell).Any(a => a.HasTrait <IBlocksBullets>()))
                {
                    Explode(world);
                }
            }

            if (Trail != null)
            {
                Trail.Tick(PxPosition - new PVecInt(0, Altitude));
            }
        }
Ejemplo n.º 7
0
        public void TickMove(int speed, int facing)
        {
            var rawspeed = speed * 7 / (32 * PSubPos.PerPx);

            SubPxPosition += rawspeed * -Util.SubPxVector[facing];
        }
Ejemplo n.º 8
0
 public void SetPxPosition(Actor self, PPos px)
 {
     SubPxPosition = px.ToPSubPos();
 }
Ejemplo n.º 9
0
        public void Tick(World world)
        {
            t += 40;

            // In pixels
            var dist = Args.target.CenterLocation + offset - PxPosition;

            var targetAltitude = 0;

            if (Args.target.IsValid && Args.target.IsActor && Args.target.Actor.HasTrait <IMove>())
            {
                targetAltitude = Args.target.Actor.Trait <IMove>().Altitude;
            }

            var jammed = Info.Jammable && world.ActorsWithTrait <JamsMissiles>().Any(tp =>
                                                                                     (tp.Actor.CenterLocation - PxPosition).ToCVec().Length <= tp.Trait.Range

                                                                                     && (tp.Actor.Owner.Stances[Args.firedBy.Owner] != Stance.Ally ||
                                                                                         (tp.Actor.Owner.Stances[Args.firedBy.Owner] == Stance.Ally && tp.Trait.AlliedMissiles))

                                                                                     && world.SharedRandom.Next(100 / tp.Trait.Chance) == 0);

            if (!jammed)
            {
                Altitude += Math.Sign(targetAltitude - Altitude);
                if (Args.target.IsValid)
                {
                    Facing = Traits.Util.TickFacing(Facing,
                                                    Traits.Util.GetFacing(dist, Facing),
                                                    Info.ROT);
                }
            }
            else
            {
                Altitude += world.SharedRandom.Next(-1, 2);
                Facing    = Traits.Util.TickFacing(Facing,
                                                   Facing + world.SharedRandom.Next(-20, 21),
                                                   Info.ROT);
            }

            anim.Tick();

            if (dist.LengthSquared < MissileCloseEnough * MissileCloseEnough && Args.target.IsValid)
            {
                Explode(world);
            }

            // TODO: Replace this with a lookup table
            var dir = (-float2.FromAngle((float)(Facing / 128f * Math.PI))).ToPSubVec();

            var move = Info.Speed * dir;

            if (targetAltitude > 0 && Info.TurboBoost)
            {
                move = (move * 3) / 2;
            }
            move = move / 5;

            SubPxPosition += move;

            if (Info.Trail != null)
            {
                var sp = ((SubPxPosition - (move * 3) / 2)).ToPPos() - new PVecInt(0, Altitude);

                if (--ticksToNextSmoke < 0)
                {
                    world.AddFrameEndTask(w => w.Add(new Smoke(w, sp, Info.Trail)));
                    ticksToNextSmoke = Info.TrailInterval;
                }
            }

            if (Info.RangeLimit != 0 && t > Info.RangeLimit * 40)
            {
                Explode(world);
            }

            if (!Info.High)                     // check for hitting a wall
            {
                var cell = PxPosition.ToCPos();
                if (world.ActorMap.GetUnitsAt(cell).Any(a => a.HasTrait <IBlocksBullets>()))
                {
                    Explode(world);
                }
            }

            if (Trail != null)
            {
                Trail.Tick(PxPosition.ToWPos(Altitude));
            }
        }