//get actor id of closest actor to the specified actor, within a certain distance
        //if no one within distance, return -1
        //does not consider friendly actors
        public int getClosestEnemyActorInRange(int actorId, int distance)
        {
            float minDistance;
            float tempDistance;
            int   closestActor;

            minDistance  = GameUtility.getDistance(actors [actorId].Position, actors [0].Position);
            closestActor = 0;
            for (int i = 1; i < CreatedActorsCount; i++)
            {
                if (actors [actorId].Team != actors [i].Team)                   // also prevents considering distance to self
                {
                    if ((tempDistance = GameUtility.getDistance(actors [actorId].Position, actors [i].Position)) < minDistance)
                    {
                        minDistance  = tempDistance;
                        closestActor = i;
                    }
                }
            }
            if (GameUtility.CoordsWithinDistance(actors [actorId].Position, actors [closestActor].Position, distance))
            {
                return(closestActor);
            }
            return(-1);
        }
        public bool ValidateAreaAbilityUse(int useActorId, AbilityType abilityId, float x, float z)
        {
            AbilityInfo info     = AbilityInfo.InfoArray [(int)abilityId];
            Actor       useActor = actors [useActorId];

            if (!(info.Range == 0) && !GameUtility.CoordsWithinDistance(useActor.Position, new GameUtility.Coordinate(x, z), info.Range + 5))
            {
                return(false);
            }

            return(useActor.UseAbility(abilityId));
        }
        public bool ValidateTargetedAbilityUse(int useActorId, AbilityType abilityId, int targetActorId)
        {
            AbilityInfo info = AbilityInfo.InfoArray [(int)abilityId];

            // Only valid if it's targeted or self
            if (!(info.IsTargeted || info.IsSelf))
            {
                return(false);
            }
            // Not valid if the ability targets self and the use and target actor id are not the same
            if (info.IsSelf && useActorId != targetActorId)
            {
                return(false);
            }

            Actor useActor    = actors [useActorId];
            Actor targetActor = actors [targetActorId];

            if (!(info.Range == 0) && !GameUtility.CoordsWithinDistance(useActor.Position, targetActor.Position, info.Range + 5))
            {
                return(false);
            }

            // If the user and target are on the same and ally target isn't allowed it's invalid
            if (useActor.Team == targetActor.Team && !info.AllyTargetAllowed)
            {
                return(false);
            }
            // If the user and target anr't on the same time and enemy target itn't allowed it's invalid
            if (useActor.Team != targetActor.Team && !info.EnemyTargetAllowed)
            {
                return(false);
            }

            if (abilityId == AbilityType.Banish && targetActor.Stationary)
            {
                return(false);
            }

            return(useActor.UseAbility(abilityId));
        }