Beispiel #1
0
        private Tuple <Vector2, Vector2> PlaceAmbushedSquads(IEnumerable <BattleSquad> squads, int xMid, int top,
                                                             Dictionary <BattleSquad, Vector2> squadPositionMap)
        {
            // assume a depth of four yards per squad
            // center them all on the midpoint, one behind the other
            int topLimit    = top;
            int bottomLimit = top;
            int leftLimit   = xMid;
            int rightLimit  = xMid;

            foreach (BattleSquad squad in squads)
            {
                Tuple <int, int> squadSize = squad.GetSquadBoxSize();
                int left  = xMid - squadSize.Item1 / 2;
                int right = xMid + squadSize.Item1 - squadSize.Item1 / 2;
                bottomLimit             = top - squadSize.Item2;
                squadPositionMap[squad] = new Vector2(left, bottomLimit);
                _grid.PlaceBattleSquad(squad, new Tuple <int, int>(left, bottomLimit), true);

                top -= squadSize.Item2 + 1;

                if (left < leftLimit)
                {
                    leftLimit = left;
                }
                if (right > rightLimit)
                {
                    rightLimit = right;
                }
            }

            return(new Tuple <Vector2, Vector2>(new Vector2(leftLimit, topLimit), new Vector2(rightLimit, bottomLimit)));
        }
Beispiel #2
0
        private Vector2 PlaceBottomSquad(BattleSquad squad, ref int left, ref int bottom, ref int right, ref int top)
        {
            Tuple <int, int> squadSize = squad.GetSquadBoxSize();

            // determine if there's more space to the left or right of the current limits
            int spaceRight = _grid.GridWidth - right;
            int placeLeft, placeBottom;

            if (squadSize.Item1 > spaceRight && squadSize.Item1 > left)
            {
                // there's not enough room; move "up"
                bottom = top + 2;
                top   += squadSize.Item2 + 2;
                left   = (_grid.GridWidth / 2) - 2;
                right  = left + squadSize.Item1 + 2;

                placeLeft   = left;
                placeBottom = bottom;
            }
            else if (spaceRight > left)
            {
                // place to the right of the current box
                placeLeft   = right + 2;
                placeBottom = bottom;
                right      += squadSize.Item1 + 2;
                if (top < bottom + squadSize.Item2 + 2)
                {
                    top = bottom + squadSize.Item2 + 2;
                }
            }
            else
            {
                // place to the left of the current box
                left       -= squadSize.Item1 + 2;
                placeLeft   = left;
                placeBottom = bottom;
                if (top < bottom + squadSize.Item2 + 2)
                {
                    top = bottom + squadSize.Item2 + 2;
                }
            }


            _grid.PlaceBattleSquad(squad, new Tuple <int, int>(placeLeft, placeBottom), true);
            return(new Vector2(placeLeft, placeBottom));
        }