using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Content;

namespace FredriksdalAssault2
{
    /// <summary>
    /// This class represents a tree.
    /// </summary>
    public class Tree : Building, IComparable<Tree>
    {
        #region Class variables

        public static Vector3 cameraPosition;

        #endregion

        #region Constructors

        /// <summary>
        /// Create a new tree.
        /// </summary>
        /// <param name="position"></param>
        /// <param name="rotation"></param>
        /// <param name="scale"></param>
        public Tree(Vector3 position, Vector3 rotation, float scale)
            : base(position, rotation, scale)
        {
            // Create bounding boxes for the house.
            CreateBoundingBoxes();
        }

        #endregion

        #region Methods

        /// <summary>
        /// Create bounding boxes for the house.
        /// </summary>
        public override void CreateBoundingBoxes()
        {
            // Create a new list of bounding boxes.
            this.boundingBoxesList = new List<CustomBoundingBox>(2);

            // Create the world matrix used to place bounding boxes in 2D world space.
            Matrix world = this.world;

            // The tree bounding box
            boundingBoxesList.Add(new CustomBoundingBox("tree", new BoundingBox(Vector3.Transform(new Vector3(-0.5f, 0, -0.5f), world), Vector3.Transform(new Vector3(0.5f, 12, 0.5f), world))));
            boundingBoxesList.Add(new CustomBoundingBox("wall", new BoundingBox(Vector3.Transform(new Vector3(-0.5f, 0, -0.5f), world), Vector3.Transform(new Vector3(0.5f, 12, 0.5f), world))));

        } // End of the CreateBoundingBoxes method

        /// <summary>
        /// Compares to trees on distance to a camera.
        /// </summary>
        /// <param name="otherTree"></param>
        /// <returns></returns>
        public virtual int CompareTo(Tree otherTree)
        {
            // Declare a int as the return value.
            int returnValue = 0;

            // Calculate distances to the camera.
            float treeDistanceToCamera = Vector3.Distance(cameraPosition, this.world.Translation);
            float otherTreeDistanceToCamera = Vector3.Distance(cameraPosition, otherTree.world.Translation);

            if (treeDistanceToCamera > otherTreeDistanceToCamera)
                returnValue = -1;
            if (treeDistanceToCamera < otherTreeDistanceToCamera)
                returnValue = 1;

            // Return -1, 0 or 1
            return returnValue;

        } // End of the CompareTo method.

        #endregion

    } // End of class

} // End of namespace
