Beispiel #1
0
 public Collision(IGameObject self, IGameObject contact, Vector2f resulVelocity, Vector2f eject)
 {
     Subject = contact;
     Eject = eject;
     Velocity = resulVelocity;
     ContactPoint = self.Body.Incircle.Center + Normal * self.Body.Incircle.Radius;
 }
 public override void UpdateGameObject(IGameObject gameObject)
 {
     if (!this.Equals(gameObject))
     {
         this.chessBoard = gameObject as IChessBoard;
     }
 }
Beispiel #3
0
        ///// <summary>
        ///// Расчитать расход топлива для прыжка
        ///// </summary>
        ///// <returns></returns>
        //public long CalculateFuelForJump(IGameObject obj, IGameObject targetLoc)
        //{
        //    var d = DistanceFor(obj, targetLoc);

        //}

        public double DistanceFor(IGameObject a, IGameObject b)
        {
            LocalPosition alp = LocalPosition.Empty, blp= LocalPosition.Empty;
            var ls = a.Ask(LocalSystem.Query.ResolvePosition)
                .Cast<QueryResponse<LocalPosition>>()
                .FirstOrDefault();
            if (ls != null)
                alp = ls.Value;
            ls = b.Ask(LocalSystem.Query.ResolvePosition)
                .Cast<QueryResponse<LocalPosition>>()
                .FirstOrDefault();
            if (ls != null)
                blp = ls.Value;
            while (!alp.Unknown && !blp.Unknown)
            {
                if (alp.LocalSystem.Level > blp.LocalSystem.Level)
                    alp = alp.LocalSystem.TranslateUp(alp.Coords);
                else if (alp.LocalSystem.Level < blp.LocalSystem.Level)
                    blp = blp.LocalSystem.TranslateUp(blp.Coords);
                if (alp.LocalSystem.Level == blp.LocalSystem.Level)
                    if (alp.LocalSystem != blp.LocalSystem)
                    {
                        alp = alp.LocalSystem.TranslateUp(alp.Coords);
                        blp = blp.LocalSystem.TranslateUp(blp.Coords);
                    }
                    else
                    {
                        
                        return alp.Coords.Distance(blp.Coords) * alp.LocalSystem.Resolution;
                    }
            }
            return double.PositiveInfinity;
        }
Beispiel #4
0
 public Fireball(Image image, GameWorld gameWorld, IGameObject source)
 {
     this.source = source;
     gw = gameWorld;
     Image = image;
     Init();
 }
Beispiel #5
0
 public static bool IGameObjectCollisionCheck(IGameObject object1, IGameObject object2)
 {
     if (object1.Rect.Intersects(object2.Rect))
         return true;
     else
         return false;
 }
Beispiel #6
0
 public EventEntry(IGameObject owner, string name)
 {
     Owner = new WeakReference(owner);
     Name = name;
     _comparison = owner.Id;
     _hashCode = Name.GetHashCode() ^ Owner.GetHashCode();
 }
Beispiel #7
0
 /* Constructors */
 public Level(ISalvagerGame game)
     : base(game)
 {
     mCameras = new List<ICamera>();
     mCameraLock = new ReaderWriterLockSlim();
     mRoot = new SalvagerEngine.Objects.GameObject(this, 0.0f);
 }
Beispiel #8
0
        public static void Raise(string eventName, IGameObject sender, EventArgs args)
        {
            var key = new EventEntry(sender, eventName);
            if(!Entries.ContainsKey(key))
            {
                Log.Warning("A handler for the event '{0}' was not found while attempting to raise the event.", eventName);
                return;
            }

            var list = Entries[key];
            var removes = new List<WeakReference>();
            foreach (var weakRef in list)
            {
                if (!weakRef.IsAlive || weakRef.Target != null)
                {
                    removes.Add(weakRef);
                    continue;
                }
                var action = (Action<IGameObject, EventArgs>) weakRef.Target;
                if (action == null)
                    continue;
                action(sender, args);
            }

            foreach (var weakReference in removes)
            {
                Entries[key].Remove(weakReference);
            }
        }
        public static void DrawObject(this Graphics g, IGameObject obj, Bitmap bitmap, Camera camera)
        {
            var location = obj.Body.Position - camera.Body.Position;
            g.DrawImage(bitmap, location.X, location.Y);

            g.DrawAABB(obj, camera);
        }
 public GrowingImageDrawBehavior(IGameObject gameObject)
 {
     GameObject = gameObject;
     size = new Size(50, 50);
     SpeedX = 1;
     SpeedY = 1;
 }
Beispiel #11
0
 public void registerObject(IGameObject iCollided)
 {
     if (iCollided.left <= _middle.X)
     {
         if (iCollided.top < _middle.Y)
         {
             topLeft.Add(iCollided);
         }
         else
         {
             bottomLeft.Add(iCollided);
         }
     }
     else
     {
         if (iCollided.top < _middle.Y)
         {
             topRight.Add(iCollided);
         }
         else
         {
             bottomRight.Add(iCollided);
         }
     }
 }
Beispiel #12
0
        public void Init()
        {
            m_Random = new Random();
            string[] textures = { "Resources/rocktex.jpg"};
            string[] spriteIDs = m_GameCommand.RequestData<string>(Constant.enumMessage.LOAD_TEXTURES, textures); //Load Textures and Get related IDS

            IGraphicsSettings graphicsSettings = new GraphicsSettings2D();
            graphicsSettings.Initialise(new Vector2(800, 600), false, true, true);
            m_GameCommand.SendData(Constant.enumMessage.UPDATE_GRAPHICS_SETTINGS, new IGraphicsSettings[] { graphicsSettings });
            m_ScreenHeight = graphicsSettings.m_ScreenSize.y;
            m_ScreenWidth = graphicsSettings.m_ScreenSize.x;

            IGameObject[] rocks = new IGameObject[rockCount];
            for (int i = 0; i < rockCount; i++)
            {
                rockKeys[i] = "rock_" + i.ToString();
                rocks[i] = new GameObject(rockKeys[i], -800, 0, 0);
            }

            m_GameCommand.SendData(Constant.enumMessage.CREATE_OBJECTS, rocks);

            for (int i = 0; i < rockCount; i++)
            {
                IComponent[] rockCompArray = { new RigidBody(5, 0, 0, false, true), new Collider(new Vector3(80, 80, 0)), new SpriteComponent(spriteIDs[0]) };
                rockKeys[i] = "rock_" + i.ToString();
                m_GameCommand.SendData(Constant.enumMessage.ADD_COMPONENTS_TO_OBJECT, new Object[] { rockKeys[i], rockCompArray });
            }

            IGameObject[] player = { new GameObject(playerKey, 0, 0, 0) };
            m_GameCommand.SendData(Constant.enumMessage.CREATE_OBJECTS, player);
            m_GameCommand.SendDataForObject<IScript>(Constant.enumMessage.ADD_SCRIPT_TO_OBJECT, playerKey, new TestScript());

            m_GameCommand.SendData(Constant.enumMessage.SWITCH_SPRITES_DRAW_STATUS, rockKeys);
        }
Beispiel #13
0
 public void ChangeState(string stateId)
 {
     System.Diagnostics.Debug.Assert(Exists(stateId));
     _stateStore[stateId].Start();            //切换场景时执行一次start
     _currentState = _stateStore[stateId];
     Input.InitKeys();                        //每切换一次场景,键位复位一次
 }
 public bool Equals(IGameObject other)
 {
     return
         TypeIsSame(other) &&
         FieldNumIsSame(((IChessBoard)other).GetAllFields()) &&
         FieldsAreEqual(((IChessBoard) other).GetAllFields());
 }
Beispiel #15
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="gameObject"></param>
        /// <param name="parentGameObject"></param>
        public void addGameObject(IGameObject gameObject, IGameObject parentGameObject)
        {
            Debug.Assert(gameObject != parentGameObject, "a gameObject cannot be the parent of himself.");

            SceneNode targetSceneNode = SceneNode.getSceneNodeByGameObject(this.sceneNodeTree, parentGameObject);
            Debug.Assert(targetSceneNode != null, "no specified parentGameObject found in SceneNode tree");

            //set position relative to the parent.
            if (parentGameObject != null)
            {
                double xPositionRelativeToParent = parentGameObject.getXPosition() + gameObject.getXPosition();
                double yPositionRelativeToParent = parentGameObject.getYPosition() + gameObject.getYPosition();
                gameObject.setPosition(xPositionRelativeToParent, yPositionRelativeToParent);
            }

            //update the geometry position relative to the gameObject position.
            if (gameObject.getBoundingBoxGeometry() != null)
            {
                gameObject.getBoundingBoxGeometry().Transform = new TranslateTransform(gameObject.getXPosition(), gameObject.getYPosition());
            }

            targetSceneNode.addChild(new SceneNode(gameObject));

            this.registerGameObject(gameObject, this.gameObjectListMapByTag);
        }
Beispiel #16
0
        private void doCannonBehaviour(GameTime gameTime)
        {
            if (currentTarget == null || targetIsOutOfRange(currentTarget))// || minTargetFocusTimer.TimerHasElapsed(gameTime))
            {
                currentTarget = getClosestToSelf(getInRangeTargets(targets));
                minTargetFocusTimer.resetTimer(gameTime.TotalGameTime);
            }

            // XXX: Dirty hack!
            var ship = currentTarget as Ship;

            if (currentTarget != null && ship != null && ship.IsAlive)
            {
                // steer towards the target and potentially fire!
                // get the change to make to point directly at the target.
                var differenceToTarget = AIHelpers.GetRotationToPointInDegrees(currentTarget.Position, Cannon.Position, Cannon.Rotation);

                float angleChangeInDegrees = differenceToTarget;

                // we need to cap the angle to change by the max rotation
                if (Math.Abs(differenceToTarget) > maxCannonRotationDegrees)
                {
                    angleChangeInDegrees = maxCannonRotationDegrees;

                    if (differenceToTarget < 0)
                        angleChangeInDegrees *= -1;
                }

                Cannon.LocalRotation += MathHelper.ToRadians(angleChangeInDegrees);

                if (Math.Abs(differenceToTarget) <= toleranceInDegrees)
                    Cannon.attemptFireCannon(gameTime);
            }
        }
Beispiel #17
0
        public void AddState(string stateId, IGameObject state)
        {
            Console.WriteLine("Add State");

            System.Diagnostics.Debug.Assert(Exists(stateId) == false);
            _stateStore.Add(stateId, state);
        }
Beispiel #18
0
 public override void Touches(IGameObject entity)
 {
     if (entity is IDamageable)
     {
         (entity as IDamageable).Destroy();
     }
 }
 //[MethodImpl(MethodImplOptions.Synchronized)] // single threaded
 public void Check(IGameObject me, FrameUpdateEventArgs e)
 {
     Rect rme = me.Shape;
     bool hitsGround = false;
     foreach (var other in Obstacles)
     {
         if (other != me)
         {
             Rect rother = other.Shape;
             if (rme.IntersectsWith(rother))
             {
                 Rect overlap = Rect.Intersect(rme,rother);
                 if (other is GroundObject)
                     hitsGround = true;
                 if (other.IsObstacle)
                 {
                     ProcessCollision(me, other, overlap, rme, rother, e.ElapsedMilliseconds / 1000);
                 }
                 me.RaiseOnCollision(me, other, true); // bool: me = caller of CheckCollision
                 other.RaiseOnCollision(other, me, false);
             }
         }
     }
     me.IsGrounded = hitsGround;
 }
Beispiel #20
0
        public static bool AddHuntableToInventory(DogHuntingSkill ths, IGameObject huntable)
        {
            if (huntable == null)
            {
                return false;
            }

            bool flag = false;

            if (SimTypes.IsSelectable(ths.SkillOwner))
            {
                flag = Inventories.TryToMove(huntable, ths.SkillOwner.CreatedSim);
            }
            else
            {
                // Add the item to head of family
                SimDescription head = SimTypes.HeadOfFamily(ths.SkillOwner.Household);
                if (head != null)
                {
                    flag = Inventories.TryToMove(huntable, head.CreatedSim);
                }
            }

            if (!flag)
            {
                huntable.RemoveFromWorld();
                huntable.Destroy();
            }
            else
            {
                StoryProgression.Main.Skills.Notify("SniffOut", ths.SkillOwner.CreatedSim, Common.Localize("SniffOut:Success", ths.SkillOwner.IsFemale, new object[] { ths.SkillOwner, huntable.GetLocalizedName() }));
            }

            return flag;
        }
Beispiel #21
0
 public Collision(IGameObject gameObject)
 {
     ColliderComponent = gameObject.ColliderComponent;
     GameObject = gameObject;
     RigidBody = GameObject.RigidBody;
     Transform = GameObject.Transform;
 }
    private void ObjectsChanged(Sector sector, IGameObject Object)
    {
        if((Object is IObject) || (Object is Tilemap))
            return;

        UpdateList();
    }
        public BlueBall(Vector2D position, double radius, PlayerPaddle paddle)
        {
            lock (lockCounter)
            {
                ballID = IDCounter++;
            }

            this.playerPaddle = paddle;
            this.Velocity = new Vector2D(0, 0);
            ObjectTextures = new List<GameBitmap>();
            this.Position = position;
            this.Radius = radius;
            ObjectTextures.Add(new GameBitmap("\\Resources\\Images\\ballBlue.png", this.Position - new Vector2D(0, Radius)
                - new Vector2D(Radius, 0),
                this.Position - new Vector2D(0, Radius) + new Vector2D(Radius, 0), this.Position + new Vector2D(0, Radius)
                + new Vector2D(-Radius, 0)));
            ObjectTextures[0].IsBall = true;
            ObjectWidth = ObjectHeight = 2 * radius;
            ObjectTextures[0].IsSquare = true;
            ObjectTextures[0].ColorLowSpec = Color.Aqua;

            //квадратот ќе ги има истите темиња како и сликата
            textureRotator = new GameRectangle(ObjectTextures[0].PositionUL,
                ObjectTextures[0].PositionUR, ObjectTextures[0].PositionDL);

            Health = 1000;
        }
        public void ResolveOverlap(IGameObject overlappingObject, ICollisionSide side) {
            int xCoordinate = (int)overlappingObject.VectorCoordinates.X;
            int yCoordinate = (int)overlappingObject.VectorCoordinates.Y;

            Rectangle hitBoxA = new Rectangle((int)gameObjectA.VectorCoordinates.X, (int)gameObjectA.VectorCoordinates.Y, (int)gameObjectA.Sprite.SpriteDimensions.X, (int)gameObjectA.Sprite.SpriteDimensions.Y);
            Rectangle hitBoxB = new Rectangle((int)gameObjectB.VectorCoordinates.X, (int)gameObjectB.VectorCoordinates.Y, (int)gameObjectB.Sprite.SpriteDimensions.X, (int)gameObjectB.Sprite.SpriteDimensions.Y);

            collisionRectangle = Rectangle.Intersect(hitBoxA, hitBoxB);   
            
            if (side is LeftSideCollision) {
                xCoordinate -= collisionRectangle.Width;
                Vector2 newLocation = new Vector2(xCoordinate, yCoordinate );
                overlappingObject.VectorCoordinates = newLocation;
            }
            else if (side is RightSideCollision) {
                xCoordinate += collisionRectangle.Width;
                Vector2 newLocation = new Vector2(xCoordinate, yCoordinate);
                overlappingObject.VectorCoordinates = newLocation;
            }
            else if (side is TopSideCollision)
            {
                yCoordinate -= collisionRectangle.Height;
                Vector2 newLocation = new Vector2(xCoordinate, yCoordinate);
                overlappingObject.VectorCoordinates = newLocation;
            }
            else if (side is BottomSideCollision)
            {
                yCoordinate += collisionRectangle.Height;
                Vector2 newLocation = new Vector2(xCoordinate, yCoordinate);
                overlappingObject.VectorCoordinates = newLocation;
            }
        }
Beispiel #25
0
        public override void MailedSuccesfully(Mailbox box, IGameObject obj)
        {
            try
            {
                Metal metal = obj as Metal;
                Collecting collecting = Actor.SkillManager.AddElement(SkillNames.Collecting) as Collecting;
                if (metal != null)
                {
                    // Custom
                    if (!collecting.mMetalData.ContainsKey(metal.Guid))
                    {
                        collecting.mMetalData.Add(metal.Guid, new Collecting.MetalStats(0));
                    }
                }

                base.MailedSuccesfully(box, obj);
            }
            catch (ResetException)
            {
                throw;
            }
            catch (Exception e)
            {
                Common.Exception(Actor, Target, e);
            }
        }
 public CircleMotionBehavior(IGameObject gameObject, GameWorld gw, DecimalPoint center)
     : base(gameObject, gw)
 {
     Center = center;
     Range = 200;
     angle = 0;
 }
Beispiel #27
0
 public Window(Game game, Vector2 position, int width, int height)
     : base(game)
 {
     _GameRef = (IGameObject)game;
     ScreenPosition = position;
     WindowSize = new Rectangle(0, 0, width, height);
 }
Beispiel #28
0
 public static bool Contains(this ILayer layer, IGameObject gameObject)
 {
     foreach (IReference<IGameObject> reference in layer.GameObjectReferences)
         if (reference.Target == gameObject)
             return true;
     return false;
 }
 /// <inheritdoc />
 public void Apply(IGameObject go, Model model)
 {
     /*foreach (Transform cell in gameObject.transform)
     {
         cell.gameObject.AddComponent<ModifyableTerrainBehaviour>();
         cell.gameObject.AddComponent<TerrainDrawBehaviour>();
     }*/
 }
Beispiel #30
0
        /// <summary>
        /// 
        /// </summary>
        /// <param name="gameObject"></param>
        /// <param name="clockwiseDegreeAngle"></param>
        /// <param name="xRotationCenter"></param>
        /// <param name="yRotationCenter"></param>
        public void applyRotation(IGameObject gameObject, double clockwiseDegreeAngle, double xRotationCenter, double yRotationCenter, bool affectBoundingBox, bool propagateToChild)
        {
            Debug.Assert(gameObject != null, "expected gameObject != null");
            SceneNode targetSceneNode = SceneNode.getSceneNodeByGameObject(this.sceneNodeTree, gameObject);
            Debug.Assert(targetSceneNode != null, "gameObject not found in the scene node tree");

            this.recursiveApplyRotation(targetSceneNode, clockwiseDegreeAngle, xRotationCenter, yRotationCenter,affectBoundingBox, propagateToChild);
        }
 /// <summary>sets phantom power to be latched at 1.0f or 0.0f</summary>
 public void object_set_phantom_power(IGameObject entity, bool boolean)
 {
 }
Beispiel #32
0
 public override CommonWoohoo.WoohooLocation GetLocation(IGameObject obj)
 {
     return(CommonWoohoo.WoohooLocation.LeafPile);
 }
 /// <summary>Set whether the object can die from damage or not (as opposed to by scripting)</summary>
 public void object_cannot_die(IGameObject entity, bool boolean)
 {
 }
Beispiel #34
0
 internal void Use(Actor user, IGameObject usedAt, uint amount)
 {
     AmountToSteal = amount;
     base.Use(user, usedAt);
 }
 /// <summary>applies damage to a damage section, causing all manner of effects/constraint breakage to occur</summary>
 public void object_damage_damage_section(IGameObject entity, string /*id*/ string_id, float real)
 {
 }
 /// <summary>disabled dynamic simulation for this object (makes it fixed)</summary>
 public void object_dynamic_simulation_disable(IGameObject entity, bool boolean)
 {
 }
 /// <summary>when this object deactivates it will be deleted</summary>
 public void object_set_deleted_when_deactivated(IGameObject entity)
 {
 }
Beispiel #38
0
 public override void SetTarget(IGameObject target)
 {
     this.m_CurrentTarget = target;
 }
 public IGameObject Spawn(IGameObject gameObject, Vector2 pos)
 {
     gameObject.Position = pos;
     GameObjects.Add(gameObject);
     return(gameObject);
 }
 /// <summary>sets the desired region (use "" for all regions) to the model state with the given name, e.g. (object_set_region_state marine head destroyed)</summary>
 public void object_set_region_state(IGameObject entity, string /*id*/ string_id, IDamageState model_state)
 {
 }
 /// <summary>returns true if any of the specified units are looking within the specified number of degrees of the object.</summary>
 public bool objects_can_see_object(IGameObject entity, IGameObject target, float degrees)
 {
     return(ObjectCanSeePoint(entity, target.Position, degrees));
 }
 /// <summary>
 /// Set whether the object can die from damage or not (as opposed to by scripting)
 /// Overload introduced by MCC, used in 03b_newmombasa
 /// </summary>
 public void object_cannot_die(IUnit entity, IGameObject vehicle, string seat)
 {
 }
 /// <summary>makes an object use the cinematic directional and ambient lights instead of sampling the lightmap.</summary>
 public void object_uses_cinematic_lighting(IGameObject entity, bool boolean)
 {
 }
 /// <summary>sets the desired region (use "" for all regions) to the permutation with the given name, e.g. (object_set_permutation flood "right arm" ~damaged)</summary>
 public void object_set_permutation(IGameObject entity, string /*id*/ string_id, string /*id*/ string_id1)
 {
 }
 /// <summary>sets funciton variable for sin-o-matic use</summary>
 public void object_set_function_variable(IGameObject entity, string /*id*/ string_id, float real, float real1)
 {
 }
 /// <summary>clears all funciton variables for sin-o-matic use</summary>
 public void object_clear_all_function_variables(IGameObject entity)
 {
 }
 /// <summary>returns TRUE if the specified model target is destroyed</summary>
 public short object_model_targets_destroyed(IGameObject entity, string /*id*/ target)
 {
     return(default(short));
 }
 /// <summary>clears one funciton variables for sin-o-matic use</summary>
 public void object_clear_function_variable(IGameObject entity, string /*id*/ string_id)
 {
 }
 /// <summary>allows an object to take damage again</summary>
 public void object_can_take_damage(IGameObject entity)
 {
 }
Beispiel #50
0
 public GameObjectOfBodyInfo(string name, IGameObject gameObject)
 {
     Name       = name;
     GameObject = gameObject;
 }
 public IGameObject object_at_marker(IGameObject entity, string stringId)
 {
     return(default(IGameObject));
 }
 public void AddState(string stateId, IGameObject state)
 {
     System.Diagnostics.Debug.Assert(Exists(stateId) == false);
     _stateStore.Add(stateId, state);
 }
 public void ChangeState(string stateId)
 {
     System.Diagnostics.Debug.Assert(Exists(stateId));
     _currentState = _stateStore[stateId];
 }
 /// <summary>make this objects shield be stunned permanently</summary>
 public void object_set_shield_stun_infinite(IGameObject entity)
 {
 }
 /// <summary>prevents an object from taking damage</summary>
 public void object_cannot_take_damage(IGameObject entity) // Unit?
 {
 }
 public void Destroy(IGameObject gameObject)
 {
     GameObjects.Remove(gameObject);
 }
 /// <summary>makes an object use the highest lod for the remainder of the levels' cutscenes.</summary>
 public void object_cinematic_lod(IGameObject entity, bool boolean)
 {
 }
 /// <summary>makes an object bypass visibility and always render during cinematics.</summary>
 public void object_cinematic_visibility(IGameObject entity, bool boolean)
 {
 }
 /// <summary>Sets the (object-relative) forward velocity of the given object</summary>
 public void object_set_velocity(IGameObject entity, float real, float real1, float real12)
 {
 }
Beispiel #60
0
        public override void FindNewTarget(IEnumerable <IGameObject> objs)
        {
            this.m_CurrentTarget = (IGameObject)null;
            float num1 = 1E+15f;
            List <StellarBody> stellarBodyList = new List <StellarBody>();
            List <Ship>        shipList1       = new List <Ship>();
            List <Ship>        shipList2       = new List <Ship>();
            List <Ship>        source          = new List <Ship>();
            bool flag = this.HasTargetInRange(objs);

            foreach (IGameObject gameObject in objs)
            {
                if (gameObject != this.m_Spector)
                {
                    if (gameObject is Ship)
                    {
                        Ship ship = gameObject as Ship;
                        if (ship.Player.ID == this.m_Spector.Player.ID)
                        {
                            source.Add(ship);
                        }
                        else if (Ship.IsActiveShip(ship) && !Ship.IsBattleRiderSize(ship.RealShipClass) && !(ship.Faction.Name == "loa") && (!flag || ship.IsDetected(this.m_Spector.Player)))
                        {
                            shipList1.Add(ship);
                        }
                    }
                    else if (gameObject is StellarBody)
                    {
                        StellarBody stellarBody = gameObject as StellarBody;
                        if (stellarBody.Population > 0.0 && stellarBody.Parameters.ColonyPlayerID != this.m_Spector.Player.ID)
                        {
                            stellarBodyList.Add(stellarBody);
                        }
                    }
                }
            }
            int num2 = 100;

            foreach (Ship ship in shipList1)
            {
                Ship targ = ship;
                int  spectersForTarget = SpecterCombatAIControl.GetNumSpectersForTarget(targ.ShipClass);
                int  num3 = source.Where <Ship>((Func <Ship, bool>)(x => x.Target == targ)).Count <Ship>();
                if (num3 < spectersForTarget && num3 <= num2)
                {
                    float lengthSquared = (this.m_Spector.Position - targ.Position).LengthSquared;
                    if ((double)lengthSquared < (double)num1 || num3 < num2)
                    {
                        num1 = lengthSquared;
                        this.m_CurrentTarget = (IGameObject)targ;
                        num2 = num3;
                    }
                }
            }
            if (this.m_CurrentTarget == null)
            {
                int num3 = 100;
                foreach (Ship ship in shipList2)
                {
                    Ship targ = ship;
                    int  spectersForTarget = SpecterCombatAIControl.GetNumSpectersForTarget(targ.ShipClass);
                    int  num4 = source.Where <Ship>((Func <Ship, bool>)(x => x.Target == targ)).Count <Ship>();
                    if (num4 < spectersForTarget && num4 <= num3)
                    {
                        float lengthSquared = (this.m_Spector.Position - targ.Position).LengthSquared;
                        if ((double)lengthSquared < (double)num1 || num4 < num3)
                        {
                            num1 = lengthSquared;
                            this.m_CurrentTarget = (IGameObject)targ;
                            num3 = num4;
                        }
                    }
                }
            }
            if (this.m_CurrentTarget != null)
            {
                return;
            }
            foreach (StellarBody stellarBody in stellarBodyList)
            {
                float lengthSquared = (this.m_Spector.Position - stellarBody.Parameters.Position).LengthSquared;
                if ((double)lengthSquared < (double)num1)
                {
                    num1 = lengthSquared;
                    this.m_CurrentTarget = (IGameObject)stellarBody;
                }
            }
        }