Ejemplo n.º 1
0
        private void CheckRays()
        {
            if (IsShotAvailable)
            {
                return;
            }

            Dictionary <Collider, bool> originalColliderValues = new Dictionary <Collider, bool>();

            foreach (var collider in Board.Objects)
            {
                if (collider == null)
                {
                    Debug.Log("Collider is null, ignore...");
                    continue;
                }

                originalColliderValues.Add(collider, collider.enabled);
                collider.enabled = (collider.tag == "ShipId:" + Ship2.ShipId) ? true : false;
            }

            bool rayIsFound = false;

            foreach (var limit in Arc.Limits)
            {
                Vector3 vectorFromDegrees = new Vector3((float)Math.Sin(limit.Value * Mathf.Deg2Rad), 0, (float)Math.Cos(limit.Value * Mathf.Deg2Rad));
                vectorFromDegrees = Ship1.TransformVector(vectorFromDegrees);

                RaycastHit hitInfo = new RaycastHit();
                if (Physics.Raycast(Ship1.ShipBase.GetGlobalPoint(limit.Key) + new Vector3(0, 0.003f, 0), vectorFromDegrees + new Vector3(0, 0.003f, 0), out hitInfo, Board.BoardIntoWorld(3 * Board.RANGE_1)))
                {
                    if (hitInfo.collider.tag == "ShipId:" + Ship2.ShipId)
                    {
                        if (!rayIsFound)
                        {
                            MinDistance = new RangeHolder(Ship1.ShipBase.GetGlobalPoint(limit.Key), hitInfo.point, Ship1, Ship2);
                            rayIsFound  = true;
                        }
                        else
                        {
                            RangeHolder secondRayResult = new RangeHolder(Ship1.ShipBase.GetGlobalPoint(limit.Key), hitInfo.point, Ship1, Ship2);
                            if (secondRayResult.DistanceReal < MinDistance.DistanceReal)
                            {
                                MinDistance = new RangeHolder(Ship1.ShipBase.GetGlobalPoint(limit.Key), hitInfo.point, Ship1, Ship2);
                            }
                        }
                    }
                }
            }

            if (rayIsFound)
            {
                Success();
            }

            foreach (var collider in Board.Objects)
            {
                collider.enabled = originalColliderValues[collider];
            }
        }
Ejemplo n.º 2
0
        protected void TryFindPerpendicularDistanceA()
        {
            //Try to get perpendicular
            float angleA = Vector3.Angle(MinDistance.Point2 - MinDistance.Point1, altDistance1.Point2 - altDistance1.Point1);
            float angleB = Vector3.Angle(MinDistance.Point2 - MinDistance.Point1, MinDistance.Point2 - altDistance1.Point2);

            if (angleB >= 90 || angleA + angleB <= 90)
            {
                // No correct perpendicular for this triangle
            }
            else
            {
                // Correct perpendicular exists
                float angleAnewRad = (180 - 90 - angleB) * Mathf.Deg2Rad;
                float distanceB    = MinDistance.DistanceReal * Mathf.Cos(angleAnewRad);
                float distanceA    = distanceB * Mathf.Tan(angleAnewRad);

                Vector3 ship2sideVector = altDistance1.Point2 - MinDistance.Point2;
                float   scale           = distanceA / Vector3.Distance(MinDistance.Point2, altDistance1.Point2);

                Vector3 difference   = ship2sideVector * scale;
                Vector3 nearestPoint = MinDistance.Point2 + difference;

                minDistancePerpA = new RangeHolder(MinDistance.Point1, nearestPoint);
            }
        }
Ejemplo n.º 3
0
        private void CheckRange()
        {
            InArcInfo = new Dictionary <GenericArc, bool>();
            List <ArcTypes> WeaponArcRestrictions = (Weapon is GenericSecondaryWeapon) ? (Weapon as GenericSecondaryWeapon).ArcRestrictions : null;

            if (WeaponArcRestrictions != null && WeaponArcRestrictions.Count == 0)
            {
                WeaponArcRestrictions = null;
            }

            WeaponTypes weaponType = (Weapon is GenericSecondaryWeapon) ? (Weapon as GenericSecondaryWeapon).WeaponType : WeaponTypes.PrimaryWeapon;

            foreach (var arc in Ship1.ArcInfo.Arcs)
            {
                ShotInfoArc shotInfoArc = new ShotInfoArc(Ship1, Ship2, arc);
                InArcInfo.Add(arc, shotInfoArc.InArc);

                if (!arc.ShotPermissions.CanShootByWeaponType(weaponType))
                {
                    continue;
                }

                if (WeaponArcRestrictions != null && !WeaponArcRestrictions.Contains(arc.ArcType))
                {
                    continue;
                }

                if (shotInfoArc.IsShotAvailable)
                {
                    if (IsShotAvailable == false)
                    {
                        MinDistance = shotInfoArc.MinDistance;
                    }
                    else
                    {
                        if (shotInfoArc.MinDistance.DistanceReal < MinDistance.DistanceReal)
                        {
                            MinDistance = shotInfoArc.MinDistance;
                        }
                    }

                    IsShotAvailable = true;

                    if (!(arc is ArcBullseye))
                    {
                        ShotAvailableFromArcs.Add(arc);
                    }
                }

                if (NearestFailedDistance == null)
                {
                    NearestFailedDistance = shotInfoArc.MinDistance;
                }
                else if (shotInfoArc.MinDistance.DistanceReal < NearestFailedDistance.DistanceReal)
                {
                    NearestFailedDistance = shotInfoArc.MinDistance;
                }
            }
        }
Ejemplo n.º 4
0
        private void CheckRange()
        {
            InArcInfo = new Dictionary <ArcTypes, bool>();

            foreach (var arc in Ship1.ArcInfo.Arcs)
            {
                ShotInfoArc shotInfoArc = new ShotInfoArc(Ship1, Ship2, arc);
                InArcInfo.Add(arc.ArcType, shotInfoArc.InArc);

                WeaponTypes weaponType = (Weapon is GenericSecondaryWeapon) ? (Weapon as GenericSecondaryWeapon).WeaponType : WeaponTypes.PrimaryWeapon;

                if (arc.ShotPermissions.CanShootByWeaponType(weaponType))
                {
                    if (shotInfoArc.IsShotAvailable)
                    {
                        if (IsShotAvailable == false)
                        {
                            MinDistance = shotInfoArc.MinDistance;
                        }
                        else
                        {
                            if (shotInfoArc.MinDistance.DistanceReal < MinDistance.DistanceReal)
                            {
                                MinDistance = shotInfoArc.MinDistance;
                            }
                        }

                        IsShotAvailable = true;
                    }

                    if (NearestFailedDistance == null)
                    {
                        NearestFailedDistance = shotInfoArc.MinDistance;
                    }
                    else if (shotInfoArc.MinDistance.DistanceReal < NearestFailedDistance.DistanceReal)
                    {
                        NearestFailedDistance = shotInfoArc.MinDistance;
                    }
                }
            }
        }
Ejemplo n.º 5
0
        protected void FindNearestDistances(List <Vector3> firstShipEdges)
        {
            List <RangeHolder> distances = new List <RangeHolder>();

            // Check distances from all edges to all edges
            foreach (var ship1point in firstShipEdges)
            {
                foreach (var ship2point in Ship2.ShipBase.GetBaseEdges().Values.ToList())
                {
                    distances.Add(new RangeHolder(ship1point, ship2point));
                }
            }

            distances = distances.OrderBy(n => n.DistanceReal).ToList();

            // MinDistance - shortest distance between edges
            MinDistance = distances.First();
            distances.Remove(MinDistance);

            // Save alternative short distances for perpendicular distance calculations
            altDistance1 = distances.First(n => n.Point1 == MinDistance.Point1);
            altDistance2 = distances.First(n => n.Point2 == MinDistance.Point2);
        }
Ejemplo n.º 6
0
        private void CheckRange()
        {
            InArcInfo    = new Dictionary <GenericArc, bool>();
            InSectorInfo = new Dictionary <GenericArc, bool>();

            List <ArcType> WeaponArcRestrictions = new List <ArcType>(Weapon.WeaponInfo.ArcRestrictions);

            if (WeaponArcRestrictions.Contains(ArcType.DoubleTurret))
            {
                WeaponArcRestrictions.RemoveAll(a => a == ArcType.DoubleTurret);
                WeaponArcRestrictions.Add(ArcType.SingleTurret);
            }

            foreach (var arc in Ship1.ArcsInfo.Arcs)
            {
                ShotInfoArc shotInfoArc = new ShotInfoArc(Ship1, Ship2, arc);
                InArcInfo.Add(arc, shotInfoArc.InArc);
            }

            List <GenericArc> sectorsAndTurrets = new List <GenericArc>();

            sectorsAndTurrets.AddRange(Ship1.SectorsInfo.Arcs);
            sectorsAndTurrets.AddRange(Ship1.ArcsInfo.Arcs.Where(a => a.ArcType == ArcType.SingleTurret));
            foreach (var arc in sectorsAndTurrets)
            {
                ShotInfoArc shotInfoArc = new ShotInfoArc(Ship1, Ship2, arc);
                InSectorInfo.Add(arc, shotInfoArc.InArc);

                if (WeaponArcRestrictions.Count > 0 && !WeaponArcRestrictions.Contains(arc.ArcType))
                {
                    continue;
                }

                if (shotInfoArc.IsShotAvailable)
                {
                    if (IsShotAvailable == false)
                    {
                        MinDistance = shotInfoArc.MinDistance;
                    }
                    else
                    {
                        if (shotInfoArc.MinDistance.DistanceReal < MinDistance.DistanceReal)
                        {
                            MinDistance = shotInfoArc.MinDistance;
                        }
                    }

                    IsShotAvailable = true;

                    if (!(arc is ArcBullseye))
                    {
                        ShotAvailableFromArcs.Add(arc);
                    }
                }

                if (NearestFailedDistance == null)
                {
                    NearestFailedDistance = shotInfoArc.MinDistance;
                }
                else if (shotInfoArc.MinDistance.DistanceReal < NearestFailedDistance.DistanceReal)
                {
                    NearestFailedDistance = shotInfoArc.MinDistance;
                }
            }

            // For 360 arcs
            if (Weapon.WeaponInfo.CanShootOutsideArc)
            {
                DistanceInfo distInfo = new DistanceInfo(Ship1, Ship2);

                if (distInfo.Range < 4)
                {
                    MinDistance     = distInfo.MinDistance;
                    IsShotAvailable = true;
                }
                else
                {
                    NearestFailedDistance = distInfo.MinDistance;
                }
            }
        }
Ejemplo n.º 7
0
        private void CheckRange()
        {
            InArcInfo    = new Dictionary <GenericArc, bool>();
            InSectorInfo = new Dictionary <GenericArc, bool>();

            foreach (var arc in Ship1.ArcsInfo.Arcs)
            {
                ShotInfoArc shotInfoArc = new ShotInfoArc(Ship1, Ship2, arc);
                InArcInfo.Add(arc, shotInfoArc.InArc);
            }

            List <GenericArc> sectorsAndTurrets = new List <GenericArc>();

            sectorsAndTurrets.AddRange(Ship1.SectorsInfo.Arcs);
            sectorsAndTurrets.AddRange(Ship1.ArcsInfo.Arcs.Where(a => a.ArcType == ArcType.SingleTurret));
            foreach (var arc in sectorsAndTurrets)
            {
                ShotInfoArc shotInfoArc = new ShotInfoArc(Ship1, Ship2, arc, Weapon);
                InSectorInfo.Add(arc, shotInfoArc.InArc);

                if (Weapon.WeaponInfo.ArcRestrictions.Count > 0 && !Weapon.WeaponInfo.ArcRestrictions.Contains(arc.ArcType))
                {
                    continue;
                }

                bool result = shotInfoArc.IsShotAvailable;
                if (arc.ArcType == ArcType.Bullseye)
                {
                    Ship1.CallOnBullseyeArcCheck(Ship2, ref result);
                }

                if (result)
                {
                    if (IsShotAvailable == false)
                    {
                        MinDistance             = shotInfoArc.MinDistance;
                        ObstructedByShips       = shotInfoArc.ObstructedByShips;
                        ObstructedByObstacles   = shotInfoArc.ObstructedByObstacles;
                        IsObstructedByBombToken = shotInfoArc.IsObstructedByBombToken;
                    }
                    else
                    {
                        if (shotInfoArc.MinDistance.DistanceReal < MinDistance.DistanceReal)
                        {
                            MinDistance             = shotInfoArc.MinDistance;
                            ObstructedByShips       = shotInfoArc.ObstructedByShips;
                            ObstructedByObstacles   = shotInfoArc.ObstructedByObstacles;
                            IsObstructedByBombToken = shotInfoArc.IsObstructedByBombToken;
                        }
                    }

                    IsShotAvailable = true;

                    if (!(arc is ArcBullseye) ||
                        (Weapon.WeaponInfo.ArcRestrictions.Count > 0 && Weapon.WeaponInfo.ArcRestrictions.Contains(ArcType.Bullseye)))
                    {
                        ShotAvailableFromArcs.Add(arc);
                    }
                }

                if (NearestFailedDistance == null)
                {
                    NearestFailedDistance = shotInfoArc.MinDistance;
                }
                else if (shotInfoArc.MinDistance.DistanceReal < NearestFailedDistance.DistanceReal)
                {
                    NearestFailedDistance = shotInfoArc.MinDistance;
                }
            }

            // For 360 arcs
            if (Weapon.WeaponInfo.CanShootOutsideArc)
            {
                DistanceInfo distInfo = new DistanceInfo(Ship1, Ship2);

                if (distInfo.Range < 4)
                {
                    MinDistance = distInfo.MinDistance;
                    //TODO: Obstructed shots for 360 arcs
                    IsShotAvailable = true;
                }
                else
                {
                    NearestFailedDistance = distInfo.MinDistance;
                }
            }

            /*Debug.Log("Check results:");
             * if (IsShotAvailable)
             * {
             *  foreach (var item in ObstructedByShips)
             *  {
             *      Debug.Log("Obstructed by " + item.PilotInfo.PilotName);
             *  }
             *  foreach (var item in ObstructedByObstacles)
             *  {
             *      Debug.Log("Obstructed by " + item.Name);
             *  }
             * }*/
        }