//Only use this constuctor when you are making a terrain component from another
 public TerrainComponent(HexComponent myHex, Texture2D myTex, bool myImpassable, float myVisBlock)
 {
     this.name = "TerrainComponent";
     hex = myHex;
     impassable = myImpassable;
     texture = myTex;
     visibilityBlock = myVisBlock;
 }
        void createGrid()
        {
            List<int> layerList = new List<int>();
            for (int x = 0; x < gridSize.X; x++)
            {
                for (int y = 0; y < gridSize.Y; y++)
                {
                    Vector2 coordPosition = new Vector2(x, y);
                    if (coordPosition.X % 2 == 0)
                    {
                        coordPosition.Y = coordPosition.X / 2f + y;
                    }
                    else
                    {
                        coordPosition.Y = (coordPosition.X + 1f) / 2f + y;
                    }

                    int layer = 0;

                    if (x % 2 == 0)
                    {
                        layer = y * 2;
                    }
                    else
                    {
                        layer = (y * 2) + 1;
                    }

                    if (!layerList.Contains(layer))
                    {
                        layerList.Add(layer);
                    }

                    Entity hexEntity = new Entity(1 + layer, State.ScreenState.SKIRMISH);
                    hexEntityGrid[x, y] = hexEntity;

                    HexComponent hexComp = new HexComponent(coordPosition);
                    hexEntity.AddComponent(hexComp);
                    hexDictionary.Add(coordPosition, hexComp);
                    HexEntityDictionary.Add(coordPosition, hexEntity);

                    //Creating the sprite for the hex entity
                    Vector2 screenPosition;
                    if (x % 2 == 0)
                    {
                        screenPosition.Y = y * gridTexture.Height + gridTexture.Height / 2f;
                    }
                    else
                    {
                        screenPosition.Y = y * gridTexture.Height + gridTexture.Height / 2f + gridTexture.Height / 2f;
                    }
                    screenPosition.X = x * (gridTexture.Width / 4f * 3f) + gridTexture.Width / 2f;

                    SpriteComponent hexSprite = new SpriteComponent(true, screenPosition, gridTexture);
                    hexEntity.AddComponent(hexSprite);

                    EntityManager.AddEntity(hexEntity);

                    GetHex(coordPosition).SetVisibility(Visibility.Unexplored);
                }
            }

            //Giving all the hex's their adjacents
            foreach (KeyValuePair<Vector2, HexComponent> entry in hexDictionary)
            {
                HexComponent hex = entry.Value;
                Vector2 coords = hex.GetCoordPosition();

                //Setting up everyones adjacent, if it's null, it doesnt exist
                HexComponent n, ne, se, sw, s, nw;
                n = null; ne = null; se = null; s = null; sw = null; nw = null;

                if (GetHex(new Vector2(coords.X, coords.Y - 1)) != null)
                    n = GetHex(new Vector2(coords.X, coords.Y - 1));

                if (GetHex(new Vector2(coords.X + 1, coords.Y)) != null)
                    ne = GetHex(new Vector2(coords.X + 1, coords.Y));

                if (GetHex(new Vector2(coords.X + 1, coords.Y + 1)) != null)
                    se = GetHex(new Vector2(coords.X + 1, coords.Y + 1));

                if (GetHex(new Vector2(coords.X, coords.Y + 1)) != null)
                    s = GetHex(new Vector2(coords.X, coords.Y + 1));

                if (GetHex(new Vector2(coords.X - 1, coords.Y)) != null)
                    sw = GetHex(new Vector2(coords.X - 1, coords.Y));

                if (GetHex(new Vector2(coords.X - 1, coords.Y - 1)) != null)
                    nw = GetHex(new Vector2(coords.X - 1, coords.Y - 1));

                hex.SetAdjacent(n, ne, se, s, sw, nw);
            }
            layerList.Add(0);
        }
        public double GetTargetAngle(HexComponent unit, HexComponent obstruction, HexComponent target)
        {
            double a = (double)Vector2.Distance(GetHexPosition(unit), GetHexPosition(obstruction));
            double b = (double)Vector2.Distance(GetHexPosition(unit), GetHexPosition(target));
            double c = (double)Vector2.Distance(GetHexPosition(obstruction), GetHexPosition(target));

            return (double)Math.Acos(Math.Round((-Math.Pow(c, 2) + Math.Pow(a, 2) + Math.Pow(b, 2)) / (2 * a * b), 5));
        }
        public double GetObstructionAngle(HexComponent unit, HexComponent obstruction)
        {
            SpriteComponent sprite = obstruction._parent.GetDrawable("SpriteComponent") as SpriteComponent;
            double size = (double)sprite.spriteHeight * (double)obstruction.GetLargestTerrainVisibilityBlock() / 100f;
            double distance = (double)Vector2.Distance(GetHexPosition(unit), GetHexPosition(obstruction));

            return (double)Math.Asin(Math.Round(size / distance, 5));
        }
 public Vector2 GetHexPosition(HexComponent hex)
 {
     SpriteComponent sprite = hex._parent.GetDrawable("SpriteComponent") as SpriteComponent;
     return sprite.GetCenterPosition();
 }
        public List<HexComponent> GetAdjacentList(HexComponent hex)
        {
            adjacentList = new List<HexComponent>();
            if (hex.n != null)
            {
                adjacentList.Add(hex.n);
            }
            if (hex.nw != null)
            {
                adjacentList.Add(hex.nw);
            }
            if (hex.ne != null)
            {
                adjacentList.Add(hex.ne);
            }
            if (hex.s != null)
            {
                adjacentList.Add(hex.s);
            }
            if (hex.se != null)
            {
                adjacentList.Add(hex.se);
            }
            if (hex.sw != null)
            {
                adjacentList.Add(hex.sw);
            }

            return adjacentList;
        }
 public void SetHex(HexComponent myHex)
 {
     hex = myHex;
     hex.removePlaceable(this);
     hex.addPlaceable(this);
 }
 public PlaceableComponent(Entity myParent, HexComponent myHex)
     : base(myParent)
 {
     this.name = "PlaceableComponent";
     this.hex = myHex;
 }
        void createGrid()
        {
            for (int x = 0; x < gridSize.X; x++)
            {
                for (int y = 0; y < gridSize.Y; y++)
                {
                    //Each hex will be an entity
                    Entity hexEntity = new Entity(0);
                    hexEntityGrid[x, y] = hexEntity;

                    //Creating the hex comp for the hex entity
                    Vector2 coordPosition = new Vector2(x, y);
                    if (coordPosition.X % 2 == 0)
                    {
                        coordPosition.Y = coordPosition.X / 2f + y;
                    }
                    else
                    {
                        coordPosition.Y = (coordPosition.X + 1f) / 2f + y;
                    }

                    HexComponent hexComp = new HexComponent(hexEntity, coordPosition);
                    hexEntity.AddComponent(hexComp);
                    HexDictionary.Add(coordPosition, hexComp);
                    HexEntityDictionary.Add(coordPosition, hexEntity);

                    //Creating the sprite for the hex entity
                    Vector2 screenPosition;
                    if (x % 2 == 0)
                    {
                        screenPosition.Y = y * gridTexture.Height +gridTexture.Height / 2f;
                    }
                    else
                    {
                        screenPosition.Y = y * gridTexture.Height + gridTexture.Height / 2f +gridTexture.Height / 2f;
                    }
                    screenPosition.X = x * (gridTexture.Width / 4f * 3f) +gridTexture.Width / 2f;

                    SpriteComponent hexSprite = new SpriteComponent(hexEntity, true, screenPosition, gridTexture);
                    hexEntity.AddComponent(hexSprite);
                    hexEntity.AddComponent(new CameraComponent(hexEntity, screenPosition));

                    EntityManager.AddEntity(hexEntity);

                    //Adding text to label the coordinates of the hex entity
                    Vector2 debugTextPosition = new Vector2(hexSprite.getCenterPosition().X, hexSprite.getCenterPosition().Y);
                    hexEntity.AddComponent(new TextSpriteComponent(hexEntity, false, coordPosition.X.ToString() + "," + coordPosition.Y.ToString(), Color.Black, debugTextPosition, gridFont));
                }
            }

            //Giving all the hex's their adjacents
            foreach (KeyValuePair<Vector2, HexComponent> entry in HexDictionary)
            {
                HexComponent hex = entry.Value;
                Vector2 coords = hex.getCoordPosition();

                //Setting up everyones adjacent, if it's null, it doesnt exist
                HexComponent n, ne, se, sw, s, nw;
                n = null; ne = null; se = null; s = null; sw = null; nw = null;

                if (getHex(new Vector2(coords.X, coords.Y - 1)) != null)
                    n = getHex(new Vector2(coords.X, coords.Y - 1));

                if (getHex(new Vector2(coords.X + 1, coords.Y)) != null)
                    ne = getHex(new Vector2(coords.X + 1, coords.Y));

                if (getHex(new Vector2(coords.X + 1, coords.Y+1)) != null)
                    se = getHex(new Vector2(coords.X + 1, coords.Y + 1));

                if (getHex(new Vector2(coords.X, coords.Y+1)) != null)
                    s = getHex(new Vector2(coords.X, coords.Y + 1));

                if (getHex(new Vector2(coords.X - 1, coords.Y)) != null)
                    sw = getHex(new Vector2(coords.X - 1, coords.Y));

                if (getHex(new Vector2(coords.X - 1, coords.Y-1)) != null)
                    nw = getHex(new Vector2(coords.X - 1, coords.Y - 1));

                hex.setAdjacent(n, ne, se, s, sw, nw);
            }
        }
 //, UnitData unitData)
 public UnitComponent(HexComponent myHex, bool mySelectable)
 {
     hex = myHex;
     this.name = "UnitComponent";
     selectable = mySelectable;
 }
 public void SetHex(HexComponent myHex)
 {
     hex.SetUnit(null);
     hex = myHex;
     myHex.SetUnit(this);
 }
 public void SetHex(HexComponent myHex)
 {
     hex = myHex;
     hex.AddTerrain(this);
     SetVisbility(hex.GetVisibility());
 }
        public static void Initialize()
        {
            State.screenState = State.ScreenState.WORLD_MAP;
            State.selectionState = State.SelectionState.NoSelection;
            State.battleState = State.BattleState.Attack;

            State.screenWidth = 0;
            State.screenHeight = 0;

            State.dialoguePosition = 0;//Which textbox you're in
            State.dialogueChoicePosition = 0;
            State.displayedDialogueMessage = "";

            State.dialogueLinePosition = 0;
            State.dialogueWordPosition = 0;
            State.dialogueCharacterPosition = 0;

            State.firstDialogueWord = "";
            State.lastTimeDialogueChecked = 0;
            State.messageBegin = false;
            State.currentDialogueMessage = new List<string>();

            State.originalHexClicked = null;

            State.currentAttacker = null;
            State.currentDefender = null;

            State.battleMessage = "";

            State.attackerBattleStatus = BattleStatus.NoStatus;
            State.defenderBattleStatus = BattleStatus.NoStatus;

            State.enemyMoveIndex = 0;
            State.firstTimeEnemyTurn = true;

            State.elapsedTimeForMove = 0;

            State.font = null;
        }
 public void SetAdjacent(HexComponent N, HexComponent NE, HexComponent SE, HexComponent S, HexComponent SW, HexComponent NW)
 {
     n = N; ne = NE; se = SE; s = S; sw = SW; nw = NW;
 }