Example #1
0
        public CannonHandler(Pawn pawn, CannonHandler reference)
        {
            this.pawn = pawn;
            uniqueID  = Find.UniqueIDsManager.GetNextThingID();

            this.label                 = reference.label;
            this.weaponType            = reference.weaponType;
            this.weaponLocation        = reference.weaponLocation;
            this.moteCannon            = reference.moteCannon;
            this.projectile            = reference.projectile;
            this.cannonSound           = reference.cannonSound;
            this.numberCannons         = reference.numberCannons;
            this.cooldownTimer         = reference.cooldownTimer;
            this.baseTicksBetweenShots = reference.baseTicksBetweenShots;
            this.spacing               = reference.spacing;
            this.hitFlags              = reference.hitFlags;
            this.spreadRadius          = reference.spreadRadius;
            this.minRange              = reference.minRange;
            this.maxRange              = reference.maxRange;
            this.offset                = reference.offset;
            this.projectileOffset      = reference.projectileOffset;
            this.splitCannonGroups     = reference.splitCannonGroups;

            if (splitCannonGroups)
            {
                foreach (float f in reference.centerPoints)
                {
                    this.centerPoints.Add(f);
                }
                foreach (int i in reference.cannonsPerPoint)
                {
                    this.cannonsPerPoint.Add(i);
                }

                if (this.cannonsPerPoint.Count != this.centerPoints.Count || (cannonsPerPoint.Count == 0 && centerPoints.Count == 0))
                {
                    Log.Warning("Could Not initialize cannon groups for " + this.pawn.LabelShort);
                    return;
                }
                int group = 0;
                for (int i = 0; i < numberCannons; i++)
                {
                    if ((i + 1) > (this.cannonsPerPoint[group] * (group + 1)))
                    {
                        group++;
                    }
                    cannonGroupDict.Add(i, group);
                    if (ShipHarmony.debug)
                    {
                        Log.Message(string.Concat(new object[]
                        {
                            "Initializing ", pawn.LabelShortCap,
                            " with cannon ", this.label,
                            " with ", cannonsPerPoint[group],
                            " cannons in group: ", group
                        }));
                    }
                }
            }
        }
Example #2
0
        public static bool TargetMeetsRequirements(CannonHandler cannon, LocalTargetInfo obj)
        {
            float distance = (cannon.TurretLocation.ToIntVec3() - obj.Cell).LengthHorizontal;

            return((distance >= cannon.cannonDef.minRange && (distance < cannon.cannonDef.maxRange || cannon.MaxRange <= -1)) &&
                   cannon.AngleBetween(obj.CenterVector3));
        }
Example #3
0
 private void InitializeCannons()
 {
     if (Cannons.Count <= 0 && Props.cannons.Any())
     {
         foreach (CannonHandler cannon in Props.cannons)
         {
             var cannonPermanent = new CannonHandler(this.Pawn, cannon);
             cannonPermanent.SetTarget(LocalTargetInfo.Invalid);
             cannonPermanent.ResetCannonAngle();
             Cannons.Add(cannonPermanent);
         }
     }
 }
Example #4
0
        public CannonHandler(Pawn pawn, CannonHandler reference)
        {
            this.pawn = pawn;
            uniqueID  = Find.UniqueIDsManager.GetNextThingID();
            cannonDef = reference.cannonDef;

            cannonSize           = reference.cannonSize;
            cannonRenderOffset   = reference.cannonRenderOffset;
            cannonRenderLocation = reference.cannonRenderLocation;
            defaultAngleRotated  = reference.defaultAngleRotated;

            aimPieOffset    = reference.aimPieOffset;
            angleRestricted = reference.angleRestricted;

            baseCannonSize           = reference.baseCannonSize;
            baseCannonRenderLocation = reference.baseCannonRenderLocation;
            cannonTurretDrawSize     = reference.cannonTurretDrawSize;

            cannonTurretDrawSize = reference.cannonTurretDrawSize;
            baseCannonDrawSize   = reference.baseCannonDrawSize;
            drawLayer            = reference.drawLayer;

            if (cannonDef.splitCannonGroups)
            {
                if (cannonDef.cannonsPerPoint.Count != cannonDef.centerPoints.Count || (cannonDef.cannonsPerPoint.Count == 0 && cannonDef.centerPoints.Count == 0))
                {
                    Log.Warning("Could Not initialize cannon groups for " + this.pawn.LabelShort);
                    return;
                }
                int group = 0;
                for (int i = 0; i < cannonDef.numberCannons; i++)
                {
                    if ((i + 1) > (cannonDef.cannonsPerPoint[group] * (group + 1)))
                    {
                        group++;
                    }
                    cannonGroupDict.Add(i, group);
                    if (ShipHarmony.debug)
                    {
                        Log.Message(string.Concat(new object[]
                        {
                            "Initializing ", pawn.LabelShortCap,
                            " with cannon ", cannonDef.label,
                            " with ", cannonDef.cannonsPerPoint[group],
                            " cannons in group: ", group
                        }));
                    }
                }
            }
        }
Example #5
0
 public void AddCannons(List <CannonHandler> cannonList)
 {
     if (cannonList is null)
     {
         return;
     }
     foreach (CannonHandler cannon in cannonList)
     {
         var cannonPermanent = new CannonHandler(this.Pawn, cannon);
         cannonPermanent.SetTarget(LocalTargetInfo.Invalid);
         cannonPermanent.currentRotation = cannonPermanent.defaultAngleRotated - 90;
         if (Cannons.Any(x => x.baseCannonRenderLocation == cannonPermanent.baseCannonRenderLocation))
         {
             Cannons.RemoveAll(x => x.baseCannonRenderLocation == cannonPermanent.baseCannonRenderLocation);
         }
         Cannons.Add(cannonPermanent);
     }
 }
Example #6
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 || Pawn.Rotation == Rot4.West)
            {
                mirrored = true;
            }
            if (cannon.cannonDef.splitCannonGroups)
            {
                int   group       = cannon.CannonGroup(i);
                float groupOffset = cannon.cannonDef.centerPoints[group];
                initialOffset = ((cannon.cannonDef.spacing * (cannon.cannonDef.cannonsPerPoint[group] - 1)) / 2f) + groupOffset; // s(n-1) / 2
                offset        = (cannon.cannonDef.spacing * i - initialOffset) * (mirrored ? -1 : 1);                            //s*i - x
            }
            else
            {
                initialOffset = ((cannon.cannonDef.spacing * (cannon.cannonDef.numberCannons - 1)) / 2f) + cannon.cannonDef.offset; // s(n-1) / 2
                offset        = (cannon.cannonDef.spacing * i - initialOffset) * (mirrored ? -1 : 1);                               //s*i - x
            }

            float projectileOffset = (this.Pawn.def.size.x / 2f) + cannon.cannonDef.projectileOffset; // (s/2)
            SPTuple2 <float, float> angleOffset = this.AngleRotationProjectileOffset(offset, projectileOffset);
            ThingDef projectile = cannon.cannonDef.projectile;
            IntVec3  targetCell = IntVec3.Invalid;
            Vector3  launchCell = this.Pawn.DrawPos;

            switch (cannon.cannonDef.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.Bow:
                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.Stern:
                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;
            }
            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.cannonDef.spreadRadius * (this.Range / cannon.cannonDef.maxRange)))];
            Projectile projectile2 = (Projectile)GenSpawn.Spawn(projectile, this.Pawn.Position, this.Pawn.Map, WipeMode.Vanish);

            if (cannon.cannonDef.cannonSound is null)
            {
                SoundDefOf_Ships.Explosion_PirateCannon.PlayOneShot(new TargetInfo(this.Pawn.Position, this.Pawn.Map, false));
            }
            else
            {
                cannon.cannonDef.cannonSound.PlayOneShot(new TargetInfo(this.Pawn.Position, this.Pawn.Map, false));
            }
            if (cannon.cannonDef.moteCannon != null)
            {
                MoteMaker.MakeStaticMote(launchCell, this.Pawn.Map, cannon.cannonDef.moteCannon, 1f);
            }
            projectile2.Launch(this.Pawn, launchCell, c, target, cannon.cannonDef.hitFlags);
        }
Example #7
0
        public void FireTurretCannon(CannonHandler cannon, ref SPTuple2 <int, int> data)
        {
            if (cannon is null)
            {
                return;
            }
            bool flag = TryFindShootLineFromTo(cannon.TurretLocation.ToIntVec3(), cannon.cannonTarget, out ShootLine shootLine);

            //FIX FOR MULTIPLAYER
            IntVec3 c = cannon.cannonTarget.Cell + GenRadial.RadialPattern[Rand.Range(0, GenRadial.NumCellsInRadius(cannon.cannonDef.spreadRadius * (Range / cannon.cannonDef.maxRange)))];

            if (data.Second >= cannon.cannonDef.projectileShifting.Count)
            {
                data.Second = 0;
            }
            float   horizontalOffset = cannon.cannonDef.projectileShifting.Any() ? cannon.cannonDef.projectileShifting[data.Second] : 0;
            Vector3 launchCell       = cannon.TurretLocation + new Vector3(horizontalOffset, 1f, cannon.cannonDef.projectileOffset).RotatedBy(cannon.TurretRotation);

            ThingDef projectile;

            if (cannon.cannonDef.ammoAllowed?.Any() ?? false)
            {
                projectile = cannon.loadedAmmo;
            }
            else
            {
                projectile = cannon.cannonDef.projectile;
            }
            try
            {
                Projectile projectile2 = (Projectile)GenSpawn.Spawn(projectile, Pawn.Position, Pawn.Map, WipeMode.Vanish);
                if (cannon.cannonDef.ammoAllowed?.Any() ?? false)
                {
                    cannon.ConsumeShellChambered();
                }
                if (cannon.cannonDef.cannonSound is null)
                {
                    SoundDefOf_Ships.Explosion_PirateCannon.PlayOneShot(new TargetInfo(Pawn.Position, Pawn.Map, false));
                }
                else
                {
                    cannon.cannonDef.cannonSound.PlayOneShot(new TargetInfo(Pawn.Position, Pawn.Map, false));
                }

                if (cannon.cannonDef.moteFlash != null)
                {
                    MoteMaker.MakeStaticMote(launchCell, Pawn.Map, cannon.cannonDef.moteFlash, 2);
                }
                if (cannon.cannonDef.moteCannon != null)
                {
                    MoteThrown mote = (MoteThrown)ThingMaker.MakeThing(cannon.cannonDef.moteCannon, null);
                    mote.exactPosition = launchCell;
                    mote.Scale         = 1f;
                    mote.rotationRate  = 15f;
                    mote.SetVelocity(cannon.TurretRotation, cannon.cannonDef.moteSpeedThrown);
                    HelperMethods.ThrowMoteEnhanced(launchCell, Pawn.Map, mote);
                }
                projectile2.Launch(Pawn, launchCell, c, cannon.cannonTarget, cannon.cannonDef.hitFlags);
            }
            catch (Exception ex)
            {
                Log.Error($"Exception when firing Cannon: {cannon.cannonDef.LabelCap} on Pawn: {Pawn.LabelCap}. Exception: {ex.Message}");
            }
        }
Example #8
0
 public void FireCannon(CannonHandler cannon)
 {
 }
Example #9
0
        public override IEnumerable <Gizmo> CompGetGizmosExtra()
        {
            if (this.Pawn.Drafted)
            {
                if (this.cannons != null && this.cannons.Count > 0)
                {
                    if (this.cannons.Any(x => x.weaponType == WeaponType.Broadside))
                    {
                        if (this.cannons.Any(x => x.weaponLocation == WeaponLocation.Port))
                        {
                            CannonHandler cannon = this.cannons.Find(x => x.weaponLocation == WeaponLocation.Port);

                            Command_CooldownAction portSideCannons = new Command_CooldownAction();
                            portSideCannons.cannon       = cannon;
                            portSideCannons.comp         = this;
                            portSideCannons.defaultLabel = "CannonLabel".Translate(cannon.label);
                            portSideCannons.icon         = TexCommandShips.BroadsideCannon_Port;
                            portSideCannons.action       = delegate()
                            {
                                SPExtended.SPTuple <Stack <int>, CannonHandler, int> tmpCannonItem = new SPExtended.SPTuple <Stack <int>, CannonHandler, int>(new Stack <int>(), cannon, 0);
                                List <int> cannonOrder = Enumerable.Range(0, cannon.numberCannons).ToList();
                                if (RimShipMod.mod.settings.shuffledCannonFire)
                                {
                                    cannonOrder.SPShuffle();
                                }
                                foreach (int i in cannonOrder)
                                {
                                    tmpCannonItem.First.Push(i);
                                }
                                this.broadsideFire.Add(tmpCannonItem);
                            };
                            portSideCannons.hotKey = KeyBindingDefOf.Misc4;
                            foreach (ShipHandler handler in this.CompShip.handlers)
                            {
                                if (handler.role.handlingType == HandlingTypeFlags.Cannons && handler.handlers.Count < handler.role.slotsToOperate)
                                {
                                    portSideCannons.Disable("NotEnoughCannonCrew".Translate(this.Pawn.LabelShort, handler.role.label));
                                }
                            }
                            yield return(portSideCannons);
                        }
                        if (this.cannons.Any(x => x.weaponLocation == WeaponLocation.Starboard))
                        {
                            CannonHandler cannon = this.cannons.Find(x => x.weaponLocation == WeaponLocation.Starboard);

                            Command_CooldownAction starboardSideCannons = new Command_CooldownAction();
                            starboardSideCannons.cannon       = cannon;
                            starboardSideCannons.comp         = this;
                            starboardSideCannons.defaultLabel = "CannonLabel".Translate(cannon.label);
                            starboardSideCannons.icon         = TexCommandShips.BroadsideCannon_Starboard;
                            starboardSideCannons.action       = delegate()
                            {
                                SPExtended.SPTuple <Stack <int>, CannonHandler, int> tmpCannonItem = new SPExtended.SPTuple <Stack <int>, CannonHandler, int>(new Stack <int>(), cannon, 0);
                                List <int> cannonOrder = Enumerable.Range(0, cannon.numberCannons).ToList();
                                if (RimShipMod.mod.settings.shuffledCannonFire)
                                {
                                    cannonOrder.SPShuffle();
                                }
                                foreach (int i in cannonOrder)
                                {
                                    tmpCannonItem.First.Push(i);
                                }
                                this.broadsideFire.Add(tmpCannonItem);
                            };
                            starboardSideCannons.hotKey = KeyBindingDefOf.Misc5;
                            foreach (ShipHandler handler in this.CompShip.handlers)
                            {
                                if (handler.role.handlingType == HandlingTypeFlags.Cannons && handler.handlers.Count < handler.role.slotsToOperate)
                                {
                                    starboardSideCannons.Disable("NotEnoughCannonCrew".Translate(this.Pawn.LabelShort, handler.role.label));
                                }
                            }
                            yield return(starboardSideCannons);
                        }

                        Command_SetRange range = new Command_SetRange();
                        range.defaultLabel  = "SetRange".Translate();
                        range.icon          = TexCommand.Attack;
                        range.activeCannons = this.cannons.FindAll(x => x.weaponType == WeaponType.Broadside);
                        range.cannonComp    = this;
                        yield return(range);
                    }
                }
            }
        }
Example #10
0
        public void FireCannon(CannonHandler cannon)
        {
            if (cannon is null)
            {
                return;
            }

            float initialOffset    = ((cannon.spacing * (cannon.numberCannons - 1)) / 2f) + cannon.offset; // s(n-1) / 2
            float projectileOffset = (this.Pawn.def.size.x / 2f) + 1;                                      // (s/2) + 1

            for (int i = 0; i < cannon.numberCannons; i++)
            {
                float offset = cannon.spacing * i - initialOffset; //s*i - x
                SPExtended.SPTuple <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.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.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));
                }
                projectile2.Launch(this.Pawn, launchCell, c, target, cannon.hitFlags);
            }
        }
Example #11
0
 public void BeginTargeting(TargetingParameters targetParams, Action <LocalTargetInfo> action, CannonHandler cannon, Action actionWhenFinished = null, Texture2D mouseAttachment = null)
 {
     this.action       = action;
     this.targetParams = targetParams;
     caster            = cannon.pawn;
     this.cannon       = cannon;
     this.cannon.SetTarget(LocalTargetInfo.Invalid);
     this.actionWhenFinished = actionWhenFinished;
     this.mouseAttachment    = mouseAttachment;
     map = cannon.pawn.Map;
 }