コード例 #1
0
 protected virtual void TurretAutoTick()
 {
     if (!vehicle.CompCannons.QueuedToFire(this))
     {
         if (AutoTarget && Find.TickManager.TicksGame % AutoTargetInterval == 0)
         {
             if (CannonDisabled)
             {
                 return;
             }
             if (!cannonTarget.IsValid && CannonTargeter.Instance.Cannon != this && reloadTicks <= 0 && HasAmmo)
             {
                 LocalTargetInfo autoTarget = this.GetCannonTarget();
                 if (autoTarget.IsValid)
                 {
                     AlignToAngleRestricted(TurretLocation.AngleToPointRelative(autoTarget.Thing.DrawPos));
                     SetTarget(autoTarget);
                 }
             }
         }
         if (reloadTicks > 0 && !OnCooldown)
         {
             reloadTicks--;
         }
         if (burstTicks > 0)
         {
             burstTicks--;
         }
     }
 }
コード例 #2
0
        protected virtual void TurretTargeterTick()
        {
            if (cannonTarget.IsValid && currentRotation == rotationTargeted && !TargetLocked)
            {
                TargetLocked = true;
                ResetPrefireTimer();
            }
            if (cannonTarget.Cell.IsValid)
            {
                if (IsTargetable && !CannonTargeter.TargetMeetsRequirements(this, cannonTarget))
                {
                    SetTarget(LocalTargetInfo.Invalid);
                    TargetLocked = false;
                    return;
                }
                if (PrefireTickCount > 0)
                {
                    if (cannonTarget.HasThing)
                    {
                        rotationTargeted = TurretLocation.AngleToPointRelative(cannonTarget.Thing.DrawPos);
                        if (attachedTo != null)
                        {
                            rotationTargeted += attachedTo.TurretRotation;
                        }
                    }
                    else
                    {
                        rotationTargeted = TurretLocation.ToIntVec3().AngleToCell(cannonTarget.Cell, vehicle.Map);
                        if (attachedTo != null)
                        {
                            rotationTargeted += attachedTo.TurretRotation;
                        }
                    }

                    if (turretDef.autoSnapTargeting)
                    {
                        currentRotation = rotationTargeted;
                    }

                    if (TargetLocked && ReadyToFire)
                    {
                        float facing = cannonTarget.Thing != null ? (cannonTarget.Thing.DrawPos - TurretLocation).AngleFlat() : (cannonTarget.Cell - TurretLocation.ToIntVec3()).AngleFlat;
                        GenDraw.DrawAimPieRaw(TurretLocation + new Vector3(turretRenderOffset.x + aimPieOffset.x, 0.5f, turretRenderOffset.y + aimPieOffset.y).RotatedBy(TurretRotation), facing, (int)(PrefireTickCount * 0.5f));
                        PrefireTickCount--;
                    }
                }
                else if (ReadyToFire)
                {
                    if (IsTargetable && RotationIsValid && targetPersists && (cannonTarget.Pawn is null || !SetTargetConditionalOnThing(LocalTargetInfo.Invalid)))
                    {
                        GroupTurrets.ForEach(t => t.PushTurretToQueue());
                    }
                    else if (FullAuto)
                    {
                        GroupTurrets.ForEach(t => t.PushTurretToQueue());
                    }
                }
            }
コード例 #3
0
ファイル: CannonHandler.cs プロジェクト: SaucyPigeon/Boats
        public void DoTick()
        {
            if (cooldownTicks > 0)
            {
                cooldownTicks--;
                if (cooldownTicks <= 0)
                {
                    ReloadCannon();
                }
            }
            if (IsTargetable)
            {
                if (cannonTarget.Cell.IsValid)
                {
                    LockedStatusRotation = false;
                    if (PrefireTickCount > 0)
                    {
                        if (!CannonTargeter.TargetMeetsRequirements(this, cannonTarget) || !pawn.Drafted)
                        {
                            SetTarget(LocalTargetInfo.Invalid);
                            return;
                        }
                        currentRotation = (float)TurretLocation.ToIntVec3().AngleToPoint(cannonTarget.Cell, pawn.Map);

                        float facing = cannonTarget.Thing != null ? (cannonTarget.Thing.DrawPos - TurretLocation).AngleFlat() : (cannonTarget.Cell - TurretLocation.ToIntVec3()).AngleFlat;
                        GenDraw.DrawAimPieRaw(TurretLocation + new Vector3(cannonRenderOffset.x + aimPieOffset.x, 0.5f, cannonRenderOffset.y + aimPieOffset.y).RotatedBy(TurretRotation), facing, (int)(PrefireTickCount * 0.5f));

                        PrefireTickCount--;
                    }
                    else if (cooldownTicks <= 0)
                    {
                        CompCannon.multiFireCannon.Add(new SPTuple <int, CannonHandler, SPTuple2 <int, int> >(cannonDef.numberOfShots, this, new SPTuple2 <int, int>(0, 0)));
                        ActivateTimer();
                    }
                }
            }
        }
コード例 #4
0
        public void DoTick()
        {
            if (pawn.GetComp <CompCannons>().multiFireCannon.NullOrEmpty())
            {
                if (autoTargeting && Find.TickManager.TicksGame % AutoTargetInterval == 0 && pawn.Drafted)
                {
                    if (CannonDisabled)
                    {
                        return;
                    }
                    if (!cannonTarget.IsValid)
                    {
                        LocalTargetInfo autoTarget = this.GetCannonTarget();
                        if (autoTarget.IsValid)
                        {
                            SetTarget(autoTarget);
                            ResetPrefireTimer();
                        }
                    }
                }
                if (cooldownTicks > 0 && RotationIsValid)
                {
                    cooldownTicks--;
                    if (cooldownTicks <= 0)
                    {
                        ReloadCannon();
                    }
                }
            }

            if (rotationTargeted != currentRotation)
            {
                if (pawn.Drafted)
                {
                    float relativeCurrentRotation  = currentRotation + 90;
                    float relativeTargetedRotation = rotationTargeted + 90;
                    if (relativeCurrentRotation < 0)
                    {
                        relativeCurrentRotation += 360;
                    }
                    else if (relativeCurrentRotation > 360)
                    {
                        relativeCurrentRotation -= 360;
                    }
                    if (relativeTargetedRotation < 0)
                    {
                        relativeTargetedRotation += 360;
                    }
                    else if (relativeTargetedRotation > 360)
                    {
                        relativeTargetedRotation -= 360;
                    }
                    if (Math.Abs(relativeCurrentRotation - relativeTargetedRotation) < cannonDef.rotationSpeed)
                    {
                        currentRotation = rotationTargeted;
                    }
                    else
                    {
                        int?sign = AngleDirectionalRestricted(relativeTargetedRotation);

                        if (relativeCurrentRotation < relativeTargetedRotation)
                        {
                            if (Math.Abs(relativeCurrentRotation - relativeTargetedRotation) < 180)
                            {
                                currentRotation += cannonDef.rotationSpeed;
                            }
                            else
                            {
                                currentRotation -= cannonDef.rotationSpeed;
                            }
                        }
                        else
                        {
                            if (Math.Abs(relativeCurrentRotation - relativeTargetedRotation) < 180)
                            {
                                currentRotation -= cannonDef.rotationSpeed;
                            }
                            else
                            {
                                currentRotation += cannonDef.rotationSpeed;
                            }
                        }
                    }
                }
                else
                {
                    rotationTargeted = currentRotation;
                }
            }
            if (IsTargetable)
            {
                if (cannonTarget.Cell.IsValid)
                {
                    if (!CannonTargeter.TargetMeetsRequirements(this, cannonTarget) || !pawn.Drafted)
                    {
                        SetTarget(LocalTargetInfo.Invalid);
                        return;
                    }
                    LockedStatusRotation = false;

                    if (PrefireTickCount > 0)
                    {
                        rotationTargeted = (float)TurretLocation.ToIntVec3().AngleToPoint(cannonTarget.Cell, pawn.Map);
                        if (cannonDef.autoSnapTargeting)
                        {
                            currentRotation = rotationTargeted;
                        }

                        if (RotationIsValid)
                        {
                            float facing = cannonTarget.Thing != null ? (cannonTarget.Thing.DrawPos - TurretLocation).AngleFlat() : (cannonTarget.Cell - TurretLocation.ToIntVec3()).AngleFlat;
                            GenDraw.DrawAimPieRaw(TurretLocation + new Vector3(cannonRenderOffset.x + aimPieOffset.x, 0.5f, cannonRenderOffset.y + aimPieOffset.y).RotatedBy(TurretRotation), facing, (int)(PrefireTickCount * 0.5f));
                            PrefireTickCount--;
                        }
                    }
                    else if (cooldownTicks <= 0 && RotationIsValid && !CannonDisabled)
                    {
                        if (targetPersists && (cannonTarget.Pawn is null || !SetTargetConditionalOnThing(LocalTargetInfo.Invalid)))
                        {
                            CompCannon.multiFireCannon.Add(new Tuple <int, CannonHandler, Tuple <int, int> >(cannonDef.numberOfShots, this, new Tuple <int, int>(0, 0)));
                            ActivateTimer();
                        }

                        if (cannonTarget.IsValid)
                        {
                        }
                    }
                }
            }
        }