示例#1
0
        public bool IsValidBuildingPlace(Players playerId, Vector2 position, UnitTypes name, float rotation)
        {
            ABuilding unit;

            switch (name)
            {
            case UnitTypes.Gate:
                unit = new Gate(playerId, position, rotation, mGridSize);
                break;

            case UnitTypes.Wall:
                unit = new Wall(playerId, position, rotation, mGridSize);
                break;

            default:
                return(false);
            }

            var blockedFields  = unit.BlockedFields();
            var passableFields = unit.PassableFields();

            var validBuildPlace = !AreFieldsOccupied(blockedFields, passableFields);

            const int buildingRangeToEnemy = 5 * GameScreen.GridSize;

            foreach (var otherPlayer in UnitsByPlayer.Keys)
            {
                if (otherPlayer == Players.Global || otherPlayer == playerId)
                {
                    continue;
                }
                if (!validBuildPlace)
                {
                    break;
                }

                validBuildPlace &= SpatialUnitsByPlayer.UnitsInRange(otherPlayer, position * GameScreen.GridSize, buildingRangeToEnemy).Count == 0;
            }

            return(validBuildPlace);
        }