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;
using Primitives3D;

namespace FredriksdalAssault2
{
    /// <summary>
    /// This class represent a house.
    /// </summary>
    public class House : Building
    {

        #region Instance variables

        // No variables here yet.

        #endregion

        #region Constructors

       /// <summary>
       /// Create a new house.
       /// </summary>
       /// <param name="position"></param>
       /// <param name="rotation"></param>
       /// <param name="scale"></param>
        public House(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>(9);
            
            // Create the world matrix used to place bounding boxes in 2D world space.
            Matrix world = this.world;

            // The full house
            boundingBoxesList.Add(new CustomBoundingBox("house", new BoundingBox(Vector3.Transform(new Vector3(-576, -32, -320),
                world), Vector3.Transform(new Vector3(320, 320, 320), world))));

            // Left wall (1) solid in one part
            boundingBoxesList.Add(new CustomBoundingBox("wall", new BoundingBox(Vector3.Transform(new Vector3(-544, -32, -288),
                world), Vector3.Transform(new Vector3(-512, 320, 288), world))));
            
            // Back wall solid (2, 18, 19, 20, 21, 22, 23)
            boundingBoxesList.Add(new CustomBoundingBox("wall", new BoundingBox(Vector3.Transform(new Vector3(-512, -32, -288),
                world), Vector3.Transform(new Vector3(288, 320, -256), world))));
            
            // Front wall (10) solid right "MUST BE THERE"
            boundingBoxesList.Add(new CustomBoundingBox("wall", new BoundingBox(Vector3.Transform(new Vector3(0, -32, 224),
                world), Vector3.Transform(new Vector3(256, 320, 288), world))));
            
            // Front wall (4, 11, 12, 13, 14) solid left
            boundingBoxesList.Add(new CustomBoundingBox("wall", new BoundingBox(Vector3.Transform(new Vector3(-512, -32, 224),
                world), Vector3.Transform(new Vector3(-160, 320, 288), world))));
            
            // Inner wall (24, 25, 26) perfect
            boundingBoxesList.Add(new CustomBoundingBox("wall", new BoundingBox(Vector3.Transform(new Vector3(-256, 0, -95),
                world), Vector3.Transform(new Vector3(-224, 320, 260), world))));
            
            // Right wall left-side
            boundingBoxesList.Add(new CustomBoundingBox("wall", new BoundingBox(Vector3.Transform(new Vector3(256, -32, 224),
                world), Vector3.Transform(new Vector3(288, 320, 288), world))));
            
            // Right wall right-side (15, 16, 17)
            boundingBoxesList.Add(new CustomBoundingBox("wall", new BoundingBox(Vector3.Transform(new Vector3(256, -32, -288),
                world), Vector3.Transform(new Vector3(288, 320, 64), world))));

            // Floor (5)
            boundingBoxesList.Add(new CustomBoundingBox("floor", new BoundingBox(Vector3.Transform(new Vector3(-512, -32, -256),
                world), Vector3.Transform(new Vector3(256, 0, 256), world))));
    
        } // End of the CreateBoundingBoxes method

        /// <summary>
        /// Get a list of cube primitives that represent a house.
        /// </summary>
        /// <param name="graphicsDevice"></param>
        /// <returns>A list with CubePrimitives</returns>
        public static List<CubePrimitive> CreateCubes(GraphicsDevice graphicsDevice)
        {
            //create a list of cube primitives)
            List<CubePrimitive> boxPrimitivesList = new List<CubePrimitive>(9);

            float texCoordScale = 0.2f;

            // Debugging (draw bounding boxes)
            boxPrimitivesList.Add(new CubePrimitive(graphicsDevice, new Vector3(-512, -62, -256), new Vector3(256, 0, 256), 1)); // Floor
            boxPrimitivesList.Add(new CubePrimitive(graphicsDevice, new Vector3(-576, 256, -320), new Vector3(320, 340, 320), 0.5f)); // Roof
            boxPrimitivesList.Add(new CubePrimitive(graphicsDevice, new Vector3(-544, -32, -256), new Vector3(-512, 256, 256), texCoordScale)); // Left wall
            boxPrimitivesList.Add(new CubePrimitive(graphicsDevice, new Vector3(-512, -32, -288), new Vector3(256, 256, -256), texCoordScale)); // Back wall
            boxPrimitivesList.Add(new CubePrimitive(graphicsDevice, new Vector3(0, -32, 224), new Vector3(256, 256, 288), texCoordScale)); // Front wall
            boxPrimitivesList.Add(new CubePrimitive(graphicsDevice, new Vector3(-512, -32, 224), new Vector3(-160, 256, 288), texCoordScale)); // Front wall
            boxPrimitivesList.Add(new CubePrimitive(graphicsDevice, new Vector3(-256, 0, -95), new Vector3(-224, 256, 260), texCoordScale)); // Inner wall
            boxPrimitivesList.Add(new CubePrimitive(graphicsDevice, new Vector3(256, -32, 224), new Vector3(288, 256, 256), texCoordScale)); // Right wall
            boxPrimitivesList.Add(new CubePrimitive(graphicsDevice, new Vector3(256, -32, -256), new Vector3(288, 256, 64), texCoordScale)); // Right wall

            // Return the list with cubes.
            return boxPrimitivesList;

        } // End of the CreateCubes method.

        #endregion

    } // End of class

} // End of namespace
