Ejemplo n.º 1
0
        private SPTuples.SPTuple2 <float, float> AngleRotationProjectileOffset(float preOffsetX, float preOffsetY)
        {
            SPTuples.SPTuple2 <float, float> offset = new SPTuples.SPTuple2 <float, float>(preOffsetX, preOffsetY);
            switch (this.Pawn.Rotation.AsInt)
            {
            case 1:
                if (this.CompShip.Angle == -45)
                {
                    SPTuples.SPTuple2 <float, float> newOffset = SPTrig.RotatePointCounterClockwise(preOffsetX, preOffsetY, 45f);
                    offset.First  = newOffset.First;
                    offset.Second = newOffset.Second;
                }
                else if (this.CompShip.Angle == 45)
                {
                    SPTuples.SPTuple2 <float, float> newOffset = SPTrig.RotatePointClockwise(preOffsetX, preOffsetY, 45f);
                    offset.First  = newOffset.First;
                    offset.Second = newOffset.Second;
                }
                break;

            case 3:
                if (this.CompShip.Angle == -45)
                {
                    SPTuples.SPTuple2 <float, float> newOffset = SPTrig.RotatePointClockwise(preOffsetX, preOffsetY, 225f);
                    offset.First  = newOffset.First;
                    offset.Second = newOffset.Second;
                }
                else if (this.CompShip.Angle == 45)
                {
                    SPTuples.SPTuple2 <float, float> newOffset = SPTrig.RotatePointCounterClockwise(preOffsetX, preOffsetY, 225f);
                    offset.First  = newOffset.First;
                    offset.Second = newOffset.Second;
                }
                break;

            default:
                return(offset);
            }
            return(offset);
        }
Ejemplo n.º 2
0
        public void FireCannonBroadside(CannonHandler cannon, int i)
        {
            if (cannon is null)
            {
                return;
            }
            float initialOffset;
            float offset;
            bool  mirrored = false;

            if (this.Pawn.Rotation == Rot4.South || this.Pawn.Rotation == Rot4.West)
            {
                mirrored = true;
            }
            if (cannon.splitCannonGroups)
            {
                int   group       = cannon.CannonGroup(i);
                float groupOffset = cannon.centerPoints[group];
                initialOffset = ((cannon.spacing * (cannon.cannonsPerPoint[group] - 1)) / 2f) + groupOffset; // s(n-1) / 2
                offset        = (cannon.spacing * i - initialOffset) * (mirrored ? -1 : 1);                  //s*i - x
            }
            else
            {
                initialOffset = ((cannon.spacing * (cannon.numberCannons - 1)) / 2f) + cannon.offset; // s(n-1) / 2
                offset        = (cannon.spacing * i - initialOffset) * (mirrored ? -1 : 1);           //s*i - x
            }

            float projectileOffset = (this.Pawn.def.size.x / 2f) + cannon.projectileOffset; // (s/2)

            SPTuples.SPTuple2 <float, float> angleOffset = this.AngleRotationProjectileOffset(offset, projectileOffset);
            ThingDef projectile = cannon.projectile;
            IntVec3  targetCell = IntVec3.Invalid;
            Vector3  launchCell = this.Pawn.DrawPos;

            switch (cannon.weaponLocation)
            {
            case WeaponLocation.Port:
                if (this.CompShip.Angle == 0)
                {
                    if (this.Pawn.Rotation == Rot4.North)
                    {
                        launchCell.x -= projectileOffset;
                        launchCell.z += offset;
                        targetCell    = new IntVec3((int)launchCell.x, this.Pawn.Position.y, (int)launchCell.z);
                        targetCell.x -= (int)this.Range;
                    }
                    else if (this.Pawn.Rotation == Rot4.East)
                    {
                        launchCell.x += offset;
                        launchCell.z += projectileOffset;
                        targetCell    = new IntVec3((int)launchCell.x, this.Pawn.Position.y, (int)launchCell.z);
                        targetCell.z += (int)this.Range;
                    }
                    else if (this.Pawn.Rotation == Rot4.South)
                    {
                        launchCell.x += projectileOffset;
                        launchCell.z += offset;
                        targetCell    = new IntVec3((int)launchCell.x, this.Pawn.Position.y, (int)launchCell.z);
                        targetCell.x += (int)this.Range;
                    }
                    else if (this.Pawn.Rotation == Rot4.West)
                    {
                        launchCell.x += offset;
                        launchCell.z -= projectileOffset;
                        targetCell    = new IntVec3((int)launchCell.x, this.Pawn.Position.y, (int)launchCell.z);
                        targetCell.z -= (int)this.Range;
                    }
                }
                else
                {
                    if (this.Pawn.Rotation == Rot4.East && this.CompShip.Angle == -45)
                    {
                        launchCell.x += angleOffset.First;
                        launchCell.z += angleOffset.Second;
                        targetCell    = new IntVec3((int)launchCell.x, this.Pawn.Position.y, (int)launchCell.z);
                        targetCell.x -= (int)(Math.Cos(this.CompShip.Angle.DegreesToRadians()) * this.Range);
                        targetCell.z -= (int)(Math.Sin(this.CompShip.Angle.DegreesToRadians()) * this.Range);
                    }
                    else if (this.Pawn.Rotation == Rot4.East && this.CompShip.Angle == 45)
                    {
                        launchCell.x += angleOffset.First;
                        launchCell.z += angleOffset.Second;
                        targetCell    = new IntVec3((int)launchCell.x, this.Pawn.Position.y, (int)launchCell.z);
                        targetCell.x += (int)(Math.Cos(this.CompShip.Angle.DegreesToRadians()) * this.Range);
                        targetCell.z += (int)(Math.Sin(this.CompShip.Angle.DegreesToRadians()) * this.Range);
                    }
                    else if (this.Pawn.Rotation == Rot4.West && this.CompShip.Angle == -45)
                    {
                        launchCell.x -= angleOffset.First;
                        launchCell.z += angleOffset.Second;
                        targetCell    = new IntVec3((int)launchCell.x, this.Pawn.Position.y, (int)launchCell.z);
                        targetCell.x += (int)(Math.Cos(this.CompShip.Angle.DegreesToRadians()) * this.Range);
                        targetCell.z += (int)(Math.Sin(this.CompShip.Angle.DegreesToRadians()) * this.Range);
                    }
                    else if (this.Pawn.Rotation == Rot4.West && this.CompShip.Angle == 45)
                    {
                        launchCell.x -= angleOffset.First;
                        launchCell.z += angleOffset.Second;
                        targetCell    = new IntVec3((int)launchCell.x, this.Pawn.Position.y, (int)launchCell.z);
                        targetCell.x -= (int)(Math.Cos(this.CompShip.Angle.DegreesToRadians()) * this.Range);
                        targetCell.z -= (int)(Math.Sin(this.CompShip.Angle.DegreesToRadians()) * this.Range);
                    }
                }
                break;

            case WeaponLocation.Starboard:
                if (this.CompShip.Angle == 0)
                {
                    if (this.Pawn.Rotation == Rot4.North)
                    {
                        launchCell.x += projectileOffset;
                        launchCell.z += offset;
                        targetCell    = new IntVec3((int)launchCell.x, this.Pawn.Position.y, (int)launchCell.z);
                        targetCell.x += (int)this.Range;
                    }
                    else if (this.Pawn.Rotation == Rot4.East)
                    {
                        launchCell.z -= projectileOffset;
                        launchCell.x += offset;
                        targetCell    = new IntVec3((int)launchCell.x, this.Pawn.Position.y, (int)launchCell.z);
                        targetCell.z -= (int)this.Range;
                    }
                    else if (this.Pawn.Rotation == Rot4.South)
                    {
                        launchCell.x -= projectileOffset;
                        launchCell.z += offset;
                        targetCell    = new IntVec3((int)launchCell.x, this.Pawn.Position.y, (int)launchCell.z);
                        targetCell.x -= (int)this.Range;
                    }
                    else if (this.Pawn.Rotation == Rot4.West)
                    {
                        launchCell.z += projectileOffset;
                        launchCell.x += offset;
                        targetCell    = new IntVec3((int)launchCell.x, this.Pawn.Position.y, (int)launchCell.z);
                        targetCell.z += (int)this.Range;
                    }
                }
                else
                {
                    if (this.Pawn.Rotation == Rot4.East && this.CompShip.Angle == -45)
                    {
                        launchCell.x += angleOffset.Second;
                        launchCell.z += angleOffset.First;
                        targetCell    = new IntVec3((int)launchCell.x, this.Pawn.Position.y, (int)launchCell.z);
                        targetCell.x += (int)(Math.Cos(this.CompShip.Angle.DegreesToRadians()) * this.Range);
                        targetCell.z += (int)(Math.Sin(this.CompShip.Angle.DegreesToRadians()) * this.Range);
                    }
                    else if (this.Pawn.Rotation == Rot4.East && this.CompShip.Angle == 45)
                    {
                        launchCell.x -= angleOffset.Second;
                        launchCell.z -= angleOffset.First;
                        targetCell    = new IntVec3((int)launchCell.x, this.Pawn.Position.y, (int)launchCell.z);
                        targetCell.x -= (int)(Math.Cos(this.CompShip.Angle.DegreesToRadians()) * this.Range);
                        targetCell.z -= (int)(Math.Sin(this.CompShip.Angle.DegreesToRadians()) * this.Range);
                    }
                    else if (this.Pawn.Rotation == Rot4.West && this.CompShip.Angle == -45)
                    {
                        launchCell.x += angleOffset.Second;
                        launchCell.z -= angleOffset.First;
                        targetCell    = new IntVec3((int)launchCell.x, this.Pawn.Position.y, (int)launchCell.z);
                        targetCell.x -= (int)(Math.Cos(this.CompShip.Angle.DegreesToRadians()) * this.Range);
                        targetCell.z -= (int)(Math.Sin(this.CompShip.Angle.DegreesToRadians()) * this.Range);
                    }
                    else if (this.Pawn.Rotation == Rot4.West && this.CompShip.Angle == 45)
                    {
                        launchCell.x -= angleOffset.Second;
                        launchCell.z += angleOffset.First;
                        targetCell    = new IntVec3((int)launchCell.x, this.Pawn.Position.y, (int)launchCell.z);
                        targetCell.x += (int)(Math.Cos(this.CompShip.Angle.DegreesToRadians()) * this.Range);
                        targetCell.z += (int)(Math.Sin(this.CompShip.Angle.DegreesToRadians()) * this.Range);
                    }
                }
                break;

            case WeaponLocation.Turret:
                throw new NotImplementedException();
            }
            LocalTargetInfo target = new LocalTargetInfo(targetCell);
            ShootLine       shootLine;
            bool            flag = TryFindShootLineFromTo(this.Pawn.Position, target, out shootLine);

            //FIX FOR MULTIPLAYER
            IntVec3    c           = target.Cell + GenRadial.RadialPattern[Rand.Range(0, GenRadial.NumCellsInRadius(cannon.spreadRadius * (this.Range / cannon.maxRange)))];
            Projectile projectile2 = (Projectile)GenSpawn.Spawn(projectile, this.Pawn.Position, this.Pawn.Map, WipeMode.Vanish);

            if (cannon.cannonSound is null)
            {
                SoundDefOf_Ships.Explosion_PirateCannon.PlayOneShot(new TargetInfo(this.Pawn.Position, this.Pawn.Map, false));
            }
            else
            {
                cannon.cannonSound.PlayOneShot(new TargetInfo(this.Pawn.Position, this.Pawn.Map, false));
            }
            if (cannon.moteCannon != null)
            {
                MoteMaker.MakeStaticMote(launchCell, this.Pawn.Map, cannon.moteCannon, 1f);
            }
            projectile2.Launch(this.Pawn, launchCell, c, target, cannon.hitFlags);
        }