Example #1
0
        public Missile(MissileInfo info, ProjectileArgs args)
        {
            Info = info;
            Args = args;

            SubPxPosition = 1024 * Args.src;
            Altitude = Args.srcAltitude;
            Facing = Args.facing;

            if (info.Inaccuracy > 0)
                offset = (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);
            }
        }
Example #2
0
        public Missile(MissileInfo info, ProjectileArgs args)
        {
            this.info = info;
            this.args = args;

            pos = args.Source;
            facing = args.Facing;

            targetPosition = args.PassiveTarget;

            var world = args.SourceActor.World;

            if (world.SharedRandom.Next(100) <= info.LockOnProbability)
                lockOn = true;

            if (info.Inaccuracy.Range > 0)
            {
                var inaccuracy = OpenRA.Traits.Util.ApplyPercentageModifiers(info.Inaccuracy.Range, args.InaccuracyModifiers);
                offset = WVec.FromPDF(world.SharedRandom, 2) * inaccuracy / 1024;
            }

            if (info.Image != null)
            {
                anim = new Animation(world, info.Image, () => facing);
                anim.PlayRepeating("idle");
            }

            if (info.ContrailLength > 0)
            {
                var color = info.ContrailUsePlayerColor ? ContrailRenderable.ChooseColor(args.SourceActor) : info.ContrailColor;
                trail = new ContrailRenderable(world, color, info.ContrailLength, info.ContrailDelay, 0);
            }
        }
Example #3
0
        public AreaBeam(AreaBeamInfo info, ProjectileArgs args, Color color)
        {
            this.info = info;
            this.args = args;
            this.color = color;
            actorAttackBase = args.SourceActor.Trait<AttackBase>();

            var world = args.SourceActor.World;
            if (info.Speed.Length > 1)
                speed = new WDist(world.SharedRandom.Next(info.Speed[0].Length, info.Speed[1].Length));
            else
                speed = info.Speed[0];

            // Both the head and tail start at the source actor, but initially only the head is travelling.
            headPos = args.Source;
            tailPos = headPos;

            target = args.PassiveTarget;
            if (info.Inaccuracy.Length > 0)
            {
                var inaccuracy = Util.ApplyPercentageModifiers(info.Inaccuracy.Length, args.InaccuracyModifiers);
                var maxOffset = inaccuracy * (target - headPos).Length / args.Weapon.Range.Length;
                target += WVec.FromPDF(world.SharedRandom, 2) * maxOffset / 1024;
            }

            towardsTargetFacing = (target - headPos).Yaw.Facing;

            // Update the target position with the range we shoot beyond the target by
            // I.e. we can deliberately overshoot, so aim for that position
            var dir = new WVec(0, -1024, 0).Rotate(WRot.FromFacing(towardsTargetFacing));
            target += dir * info.BeyondTargetRange.Length / 1024;

            length = Math.Max((target - headPos).Length / speed.Length, 1);
        }
Example #4
0
        public Missile(MissileInfo info, ProjectileArgs args)
        {
            this.info = info;
            this.args = args;

            pos = args.Source;
            facing = args.Facing;

            targetPosition = args.PassiveTarget;

            if (info.Inaccuracy.Range > 0)
                offset = WVec.FromPDF(args.SourceActor.World.SharedRandom, 2) * info.Inaccuracy.Range / 1024;

            if (info.Image != null)
            {
                anim = new Animation(args.SourceActor.World, info.Image, () => facing);
                anim.PlayRepeating("idle");
            }

            if (info.ContrailLength > 0)
            {
                var color = info.ContrailUsePlayerColor ? ContrailRenderable.ChooseColor(args.SourceActor) : info.ContrailColor;
                trail = new ContrailRenderable(args.SourceActor.World, color, info.ContrailLength, info.ContrailDelay, 0);
            }
        }
Example #5
0
        public Bullet(BulletInfo info, ProjectileArgs args)
        {
            Info = info;
            Args = args;

            if (info.Inaccuracy > 0)
            {
                var factor = ((Args.dest - Args.src).ToCVec().Length) / args.weapon.Range;
                Args.dest += (PVecInt) (info.Inaccuracy * factor * args.firedBy.World.SharedRandom.Gauss2D(2)).ToInt2();
                Log.Write("debug", "Bullet with Inaccuracy; factor: #{0}; Projectile dest: {1}", factor, Args.dest);
            }

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

            if (Info.ContrailLength > 0)
            {
                Trail = new ContrailHistory(Info.ContrailLength,
                    Info.ContrailUsePlayerColor ? ContrailHistory.ChooseColor(args.firedBy) : Info.ContrailColor,
                    Info.ContrailDelay);
            }
        }
Example #6
0
        public Missile(MissileInfo info, ProjectileArgs args)
        {
            this.info = info;
            this.args = args;

            pos = args.Source;
            facing = args.Facing;

            targetPosition = args.PassiveTarget;

            // Convert ProjectileArg definitions to world coordinates
            // TODO: Change the yaml definitions so we don't need this
            var inaccuracy = (int)(info.Inaccuracy * 1024 / Game.CellSize);
            speed = info.Speed * 1024 / (5 * Game.CellSize);

            if (info.Inaccuracy > 0)
                offset = WVec.FromPDF(args.SourceActor.World.SharedRandom, 2) * inaccuracy / 1024;

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

            if (info.ContrailLength > 0)
            {
                var color = info.ContrailUsePlayerColor ? ContrailRenderable.ChooseColor(args.SourceActor) : info.ContrailColor;
                trail = new ContrailRenderable(args.SourceActor.World, color, info.ContrailLength, info.ContrailDelay, 0);
            }
        }
Example #7
0
        public void Tick(Actor self)
        {
            if (!target.IsInRange(self.CenterPosition, range))
                return;

            var limitedAmmo = self.TraitOrDefault<LimitedAmmo>();
            if (limitedAmmo != null && !limitedAmmo.HasAmmo())
                return;

            if (--dropDelay <= 0)
            {
                var weapon = Rules.Weapons[info.Weapon.ToLowerInvariant()];
                dropDelay = weapon.ROF;

                var pos = self.CenterPosition;
                var args = new ProjectileArgs
                {
                    Weapon = weapon,
                    Facing = self.Trait<IFacing>().Facing,

                    Source = pos,
                    SourceActor = self,
                    PassiveTarget = pos - new WVec(0, 0, pos.Z)
                };

                self.World.Add(args.Weapon.Projectile.Create(args));

                if (args.Weapon.Report != null && args.Weapon.Report.Any())
                    Sound.Play(args.Weapon.Report.Random(self.World.SharedRandom), self.CenterPosition);
            }
        }
Example #8
0
 public WarheadArgs(ProjectileArgs args)
 {
     Weapon          = args.Weapon;
     DamageModifiers = args.DamageModifiers;
     Source          = args.Source;
     SourceActor     = args.SourceActor;
     WeaponTarget    = args.GuidedTarget;
 }
Example #9
0
        int timeUntilRemove = 2; // # of frames

        #endregion Fields

        #region Constructors

        public TeslaZap(TeslaZapInfo info, ProjectileArgs args)
        {
            Args = args;
            var bright = SequenceProvider.GetSequence("litning", "bright");
            var dim = SequenceProvider.GetSequence("litning", "dim");

            for (var n = 0; n < numZaps; n++)
                renderables.AddRange(DrawZapWandering(args.src, args.dest, n == numZaps - 1 ? bright : dim));
        }
Example #10
0
        public LaserZap(ProjectileArgs args, LaserZapInfo info, Color color)
        {
            this.args = args;
            this.info = info;
            this.color = color;

            if (info.Explosion != null)
                this.explosion = new Animation(info.Explosion);
        }
Example #11
0
        public LaserZap(ProjectileArgs args, LaserZapInfo info, Color color)
        {
            this.args = args;
            this.info = info;
            this.color = color;
            this.target = args.PassiveTarget;

            if (info.HitAnim != null)
                this.hitanim = new Animation(info.HitAnim);
        }
Example #12
0
        public LaserZap(ProjectileArgs args, LaserZapInfo info, Color color)
        {
            this.args = args;
            this.info = info;
            this.color = color;
            this.target = args.PassiveTarget;

            if (!string.IsNullOrEmpty(info.HitAnim))
                this.hitanim = new Animation(args.SourceActor.World, info.HitAnim);
        }
        int timeUntilRemove = 2; // # of frames

        #endregion Fields

        #region Constructors

        public TeslaZap(TeslaZapInfo info, ProjectileArgs args)
        {
            Args = args;
            var bright = SequenceProvider.GetSequence(info.Image, "bright");
            var dim = SequenceProvider.GetSequence(info.Image, "dim");

            for( var n = 0; n < info.DimZaps; n++ )
                renderables.AddRange(DrawZapWandering(args.src, args.dest, dim));
            for( var n = 0; n < info.BrightZaps; n++ )
                renderables.AddRange(DrawZapWandering(args.src, args.dest, bright));
        }
Example #14
0
        public GravityBomb(GravityBombInfo info, ProjectileArgs args)
        {
            Args = args;
            altitude = args.srcAltitude;

            anim = new Animation(info.Image);
            if (anim.HasSequence("open"))
                anim.PlayThen("open", () => anim.PlayRepeating("idle"));
            else
                anim.PlayRepeating("idle");
        }
Example #15
0
        public GravityBomb(GravityBombInfo info, ProjectileArgs args)
        {
            this.info = info;
            this.args = args;
            pos = args.Source;
            velocity = new WVec(WRange.Zero, WRange.Zero, -info.Velocity);

            anim = new Animation(info.Image);
            if (anim.HasSequence("open"))
                anim.PlayThen("open", () => anim.PlayRepeating("idle"));
            else
                anim.PlayRepeating("idle");
        }
Example #16
0
        public Missile(MissileInfo info, ProjectileArgs args)
        {
            this.info = info;
            this.args = args;

            pos = args.Source;
            hFacing = args.Facing;
            gravity = new WVec(0, 0, -info.Gravity);
            targetPosition = args.PassiveTarget;
            rangeLimit = info.RangeLimit != WDist.Zero ? info.RangeLimit : args.Weapon.Range;
            minLaunchSpeed = info.MinimumLaunchSpeed.Length > -1 ? info.MinimumLaunchSpeed.Length : info.Speed.Length;
            maxLaunchSpeed = info.MaximumLaunchSpeed.Length > -1 ? info.MaximumLaunchSpeed.Length : info.Speed.Length;
            maxSpeed = info.Speed.Length;
            minLaunchAngle = info.MinimumLaunchAngle;
            maxLaunchAngle = info.MaximumLaunchAngle;

            var world = args.SourceActor.World;

            if (info.Inaccuracy.Length > 0)
            {
                var inaccuracy = Util.ApplyPercentageModifiers(info.Inaccuracy.Length, args.InaccuracyModifiers);
                offset = WVec.FromPDF(world.SharedRandom, 2) * inaccuracy / 1024;
            }

            DetermineLaunchSpeedAndAngle(world, out speed, out vFacing);

            velocity = new WVec(0, -speed, 0)
                .Rotate(new WRot(WAngle.FromFacing(vFacing), WAngle.Zero, WAngle.Zero))
                .Rotate(new WRot(WAngle.Zero, WAngle.Zero, WAngle.FromFacing(hFacing)));

            if (world.SharedRandom.Next(100) <= info.LockOnProbability)
                lockOn = true;

            if (!string.IsNullOrEmpty(info.Image))
            {
                anim = new Animation(world, info.Image, () => renderFacing);
                anim.PlayRepeating(info.Sequences.Random(world.SharedRandom));
            }

            if (info.ContrailLength > 0)
            {
                var color = info.ContrailUsePlayerColor ? ContrailRenderable.ChooseColor(args.SourceActor) : info.ContrailColor;
                contrail = new ContrailRenderable(world, color, info.ContrailWidth, info.ContrailLength, info.ContrailDelay, info.ContrailZOffset);
            }

            trailPalette = info.TrailPalette;
            if (info.TrailUsePlayerPalette)
                trailPalette += args.SourceActor.Owner.InternalName;
        }
Example #17
0
        public Bullet(BulletInfo info, ProjectileArgs args)
        {
            this.info = info;
            this.args = args;
            pos = args.Source;

            var world = args.SourceActor.World;

            if (info.LaunchAngle.Length > 1)
                angle = new WAngle(world.SharedRandom.Next(info.LaunchAngle[0].Angle, info.LaunchAngle[1].Angle));
            else
                angle = info.LaunchAngle[0];

            if (info.Speed.Length > 1)
                speed = new WDist(world.SharedRandom.Next(info.Speed[0].Length, info.Speed[1].Length));
            else
                speed = info.Speed[0];

            target = args.PassiveTarget;
            if (info.Inaccuracy.Length > 0)
            {
                var inaccuracy = Util.ApplyPercentageModifiers(info.Inaccuracy.Length, args.InaccuracyModifiers);
                var range = Util.ApplyPercentageModifiers(args.Weapon.Range.Length, args.RangeModifiers);
                var maxOffset = inaccuracy * (target - pos).Length / range;
                target += WVec.FromPDF(world.SharedRandom, 2) * maxOffset / 1024;
            }

            facing = (target - pos).Yaw.Facing;
            length = Math.Max((target - pos).Length / speed.Length, 1);

            if (!string.IsNullOrEmpty(info.Image))
            {
                anim = new Animation(world, info.Image, new Func<int>(GetEffectiveFacing));
                anim.PlayRepeating(info.Sequences.Random(world.SharedRandom));
            }

            if (info.ContrailLength > 0)
            {
                var color = info.ContrailUsePlayerColor ? ContrailRenderable.ChooseColor(args.SourceActor) : info.ContrailColor;
                contrail = new ContrailRenderable(world, color, info.ContrailWidth, info.ContrailLength, info.ContrailDelay, info.ContrailZOffset);
            }

            trailPalette = info.TrailPalette;
            if (info.TrailUsePlayerPalette)
                trailPalette += args.SourceActor.Owner.InternalName;

            smokeTicks = info.TrailDelay;
        }
Example #18
0
        public static void DoExplosion(Actor attacker, string weapontype, int2 location, int altitude)
        {
            var args = new ProjectileArgs
            {
                src = location,
                dest = location,
                srcAltitude = altitude,
                destAltitude = altitude,
                firedBy = attacker,
                target = null,
                weapon = Rules.Weapons[ weapontype.ToLowerInvariant() ],
                facing = 0
            };

            DoImpacts(args, location);
        }
Example #19
0
        public Bullet(BulletInfo info, ProjectileArgs args)
        {
            Info = info;
            Args = args;

            if (info.Inaccuracy > 0)
            {
                var factor = ((Args.dest - Args.src).Length / Game.CellSize) / args.weapon.Range;
                Args.dest += (info.Inaccuracy * factor * args.firedBy.World.SharedRandom.Gauss2D(2)).ToInt2();
            }

            if (Info.Image != null)
            {
                anim = new Animation(Info.Image, GetEffectiveFacing);
                anim.PlayRepeating("idle");
            }
        }
Example #20
0
        public GravityBomb(GravityBombInfo info, ProjectileArgs args)
        {
            this.info = info;
            this.args = args;
            pos = args.Source;
            velocity = new WVec(WDist.Zero, WDist.Zero, -info.Velocity);
            acceleration = new WVec(WDist.Zero, WDist.Zero, info.Acceleration);

            if (!string.IsNullOrEmpty(info.Image))
            {
                anim = new Animation(args.SourceActor.World, info.Image);

                if (!string.IsNullOrEmpty(info.OpenSequence))
                    anim.PlayThen(info.OpenSequence, () => anim.PlayRepeating(info.Sequence));
                else
                    anim.PlayRepeating(info.Sequence);
            }
        }
Example #21
0
        public Missile(MissileInfo info, ProjectileArgs args)
        {
            Info = info;
            Args = args;

            Pos = Args.src;
            Altitude = Args.srcAltitude;
            Facing = Args.facing;

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

            if (Info.Image != null)
            {
                anim = new Animation(Info.Image, () => Facing);
                anim.PlayRepeating("idle");
            }
        }
Example #22
0
		public void Killed(Actor self, AttackInfo attack)
		{
			foreach (var wep in info.WeaponInfos)
			{
				var pieces = self.World.SharedRandom.Next(info.Pieces[0], info.Pieces[1]);
				var range = self.World.SharedRandom.Next(info.Range[0].Length, info.Range[1].Length);

				for (var i = 0; pieces > i; i++)
				{
					var rotation = WRot.FromFacing(self.World.SharedRandom.Next(1024));
					var args = new ProjectileArgs
					{
						Weapon = wep,
						Facing = self.World.SharedRandom.Next(-1, 255),

						DamageModifiers = self.TraitsImplementing<IFirepowerModifier>()
							.Select(a => a.GetFirepowerModifier()).ToArray(),

						InaccuracyModifiers = self.TraitsImplementing<IInaccuracyModifier>()
							.Select(a => a.GetInaccuracyModifier()).ToArray(),

						RangeModifiers = self.TraitsImplementing<IRangeModifier>()
							.Select(a => a.GetRangeModifier()).ToArray(),

						Source = self.CenterPosition,
						SourceActor = self,
						PassiveTarget = self.CenterPosition + new WVec(range, 0, 0).Rotate(rotation)
					};

					self.World.AddFrameEndTask(x =>
					{
						if (args.Weapon.Projectile != null)
						{
							var projectile = args.Weapon.Projectile.Create(args);
							if (projectile != null)
								self.World.Add(projectile);

							if (args.Weapon.Report != null && args.Weapon.Report.Any())
								Game.Sound.Play(args.Weapon.Report.Random(self.World.SharedRandom), self.CenterPosition);
						}
					});
				}
			}
		}
Example #23
0
        public Bullet(BulletInfo info, ProjectileArgs args)
        {
            this.info = info;
            this.args = args;
            this.pos = args.Source;

            var world = args.SourceActor.World;

            if (info.Angle.Length > 1 && info.Speed.Length > 1)
            {
                angle = new WAngle(world.SharedRandom.Next(info.Angle[0].Angle, info.Angle[1].Angle));
                speed = new WRange(world.SharedRandom.Next(info.Speed[0].Range, info.Speed[1].Range));
            }
            else
            {
                angle = info.Angle[0];
                speed = info.Speed[0];
            }

            target = args.PassiveTarget;
            if (info.Inaccuracy.Range > 0)
            {
                var inaccuracy = OpenRA.Traits.Util.ApplyPercentageModifiers(info.Inaccuracy.Range, args.InaccuracyModifiers);
                var maxOffset = inaccuracy * (target - pos).Length / args.Weapon.Range.Range;
                target += WVec.FromPDF(world.SharedRandom, 2) * maxOffset / 1024;
            }

            facing = OpenRA.Traits.Util.GetFacing(target - pos, 0);
            length = Math.Max((target - pos).Length / speed.Range, 1);

            if (info.Image != null)
            {
                anim = new Animation(world, info.Image, GetEffectiveFacing);
                anim.PlayRepeating("idle");
            }

            if (info.ContrailLength > 0)
            {
                var color = info.ContrailUsePlayerColor ? ContrailRenderable.ChooseColor(args.SourceActor) : info.ContrailColor;
                trail = new ContrailRenderable(world, color, info.ContrailLength, info.ContrailDelay, 0);
            }

            smokeTicks = info.TrailDelay;
        }
Example #24
0
        public static void DoExplosion(Actor attacker, string weapontype, PPos pos, int altitude)
        {
            var args = new ProjectileArgs
            {
                src = pos,
                dest = pos,
                srcAltitude = altitude,
                destAltitude = altitude,
                firedBy = attacker,
                target = Target.FromPos(pos),
                weapon = Rules.Weapons[ weapontype.ToLowerInvariant() ],
                facing = 0
            };

            if (args.weapon.Report != null && args.weapon.Report.Any())
                Sound.Play(args.weapon.Report.Random(attacker.World.SharedRandom) + ".aud", pos);

            DoImpacts(args);
        }
Example #25
0
        public Bullet(BulletInfo info, ProjectileArgs args)
        {
            Info = info;
            Args = args;

            if (info.Inaccuracy > 0)
            {
                var factor = (Args.dest - Args.src).LengthSquared / (Game.CellSize * Game.CellSize);
                Args.dest += (info.Inaccuracy * factor * args.firedBy.World.SharedRandom.Gauss2D(2)).ToInt2();
            }

            VisualDest = Args.dest + (10 * args.firedBy.World.CosmeticRandom.Gauss2D(1)).ToInt2();

            if (Info.Image != null)
            {
                anim = new Animation(Info.Image, () => Traits.Util.GetFacing(Args.dest - Args.src, 0));
                anim.PlayRepeating("idle");
            }
        }
Example #26
0
        public static void DoImpact(WarheadInfo warhead, ProjectileArgs args, int2 visualLocation)
        {
            var world = args.firedBy.World;
            var targetTile = ((1f / Game.CellSize) * args.dest.ToFloat2()).ToInt2();
            var isWater = world.GetTerrainType(targetTile) == TerrainType.Water;

            if (warhead.Explosion != 0)
                world.AddFrameEndTask(
                    w => w.Add(new Explosion(w, visualLocation, warhead.Explosion, isWater)));

            Sound.Play(GetImpactSound(warhead, isWater));

            if (!isWater) world.Map.AddSmudge(targetTile, warhead);
            if (warhead.Ore)
                world.WorldActor.traits.Get<ResourceLayer>().Destroy(targetTile);

            var firepowerModifier = args.firedBy.traits
                .WithInterface<IFirepowerModifier>()
                .Select(a => a.GetFirepowerModifier())
                .Product();

            switch (warhead.DamageModel)
            {
                case DamageModel.Normal:
                    {
                        var maxSpread = warhead.Spread * (float)Math.Log(Math.Abs(warhead.Damage), 2);
                        var hitActors = world.FindUnitsInCircle(args.dest, maxSpread);

                        foreach (var victim in hitActors)
                            victim.InflictDamage(args.firedBy,
                                (int)GetDamageToInflict(victim, args, warhead, firepowerModifier), warhead);
                    } break;

                case DamageModel.PerCell:
                    {
                        foreach (var t in world.FindTilesInCircle(targetTile, warhead.Size[0]))
                            foreach (var unit in world.FindUnits(Game.CellSize * t, Game.CellSize * (t + new float2(1,1))))
                                unit.InflictDamage(args.firedBy,
                                    (int)(warhead.Damage * warhead.EffectivenessAgainst(
                                    unit.Info.Traits.Get<OwnedActorInfo>().Armor)), warhead);
                    } break;
            }
        }
Example #27
0
        public static void DoExplosion(Actor attacker, string weapontype, float2 pos, int altitude)
        {
            var args = new ProjectileArgs
            {
                src = pos.ToInt2(),
                dest = pos.ToInt2(),
                srcAltitude = altitude,
                destAltitude = altitude,
                firedBy = attacker,
                target = Target.FromPos(pos),
                weapon = Rules.Weapons[ weapontype.ToLowerInvariant() ],
                facing = 0
            };

            if (args.weapon.Report != null)
                Sound.Play(args.weapon.Report + ".aud", pos);

            DoImpacts(args);
        }
Example #28
0
        public Missile(MissileInfo info, ProjectileArgs args)
        {
            Info = info;
            Args = args;

            Pos = Args.src;
            Altitude = Args.srcAltitude;
            Facing = Args.facing;

            if (info.Inaccuracy > 0)
            {
                var factor = (Args.dest - Args.src).LengthSquared / (Game.CellSize * Game.CellSize);
                offset = (info.Inaccuracy * factor * args.firedBy.World.SharedRandom.Gauss2D(2)).ToInt2();
            }

            if (Info.Image != null)
            {
                anim = new Animation(Info.Image, () => Facing);
                anim.PlayRepeating("idle");
            }
        }
Example #29
0
        public Bullet(BulletInfo info, ProjectileArgs args)
        {
            this.info = info;
            this.args = args;
            this.pos = args.Source;

            // Convert ProjectileArg definitions to world coordinates
            // TODO: Change the yaml definitions so we don't need this
            var range = new WRange((int)(1024 * args.Weapon.Range)); // Range in world units
            var inaccuracy = new WRange((int)(info.Inaccuracy * 1024 / Game.CellSize)); // Offset in world units at max range
            var speed = (int)(info.Speed * 4 * 1024 / (10 * Game.CellSize)); // Speed in world units per tick
            angle = WAngle.ArcTan((int)(info.Angle * 4 * 1024), 1024); // Angle in world angle

            target = args.PassiveTarget;
            if (info.Inaccuracy > 0)
            {
                var maxOffset = inaccuracy.Range * (target - pos).Length / range.Range;
                target += WVec.FromPDF(args.SourceActor.World.SharedRandom, 2) * maxOffset / 1024;
            }

            facing = Traits.Util.GetFacing(target - pos, 0);
            length = Math.Max((target - pos).Length / speed, 1);

            if (info.Image != null)
            {
                anim = new Animation(info.Image, GetEffectiveFacing);
                anim.PlayRepeating("idle");
            }

            if (info.ContrailLength > 0)
            {
                var color = info.ContrailUsePlayerColor ? ContrailRenderable.ChooseColor(args.SourceActor) : info.ContrailColor;
                trail = new ContrailRenderable(args.SourceActor.World, color, info.ContrailLength, info.ContrailDelay, 0);
            }

            smokeTicks = info.TrailDelay;
        }
Example #30
0
        public Bullet(BulletInfo info, ProjectileArgs args)
        {
            Info = info;
            Args = args;

            if (info.Inaccuracy > 0)
            {
                var factor = ((Args.dest - Args.src).Length / Game.CellSize) / args.weapon.Range;
                Args.dest += (info.Inaccuracy * factor * args.firedBy.World.SharedRandom.Gauss2D(2)).ToInt2();
            }

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

            if (Info.ContrailLength > 0)
            {
                Trail = new ContrailHistory(Info.ContrailLength,
                    Info.ContrailUsePlayerColor ? ContrailHistory.ChooseColor(args.firedBy) : Info.ContrailColor,
                    Info.ContrailDelay);
            }
        }
Example #31
0
 public IEffect Create(ProjectileArgs args)
 {
     return new Bullet(this, args);
 }