Exemplo n.º 1
0
        public bool Match(int x, int y, TileResultCollector <TRenderTile, TContext> onMatchFound)
        {
            var q = queryFn(x, y) >> lowerLimit;

            if (q == 0)
            {
                return(false);
            }

            var result = false;

            for (var i = lowerLimit; i <= limit; i += 1)
            {
                if ((q & 1) == 1)
                {
                    var context = contextFn(x, y, i);
                    if (tileExists[i])
                    {
                        onMatchFound(SpritePosition.Whole, tiles[i], context);
                        result = true;
                    }
                }

                q >>= 1;
            }

            return(result);
        }
Exemplo n.º 2
0
        public override bool Match(int x, int y, TileResultCollector <TRenderTile, TContext> resultCollector)
        {
            if (!Matcher(x, y))
            {
                return(false);
            }

            var context = ContextProvider(x, y);

            neighbourPositions = GridNavigator.NavigateNeighbours(new MapCoordinate(x, y), neighbourPositions);
            bool matchedOne = false;

            for (var i = 1; i < positions.Length; i++)
            {
                var mc = neighbourPositions[i - 1];
                if (Matcher(mc.X, mc.Y) && tileExists[i])
                {
                    resultCollector(SpritePosition.Whole, tiles[i], context);
                    matchedOne = true;
                }
            }

            if (!matchedOne)
            {
                // isolated tile ..
                if (tileExists[0])
                {
                    resultCollector(SpritePosition.Whole, tiles[0], context);
                }
            }

            return(true);
        }
Exemplo n.º 3
0
 public PlotOperation(ITileMatcher <TRenderTile, TContext> matcher,
                      RenderType renderType,
                      IRenderCallback <TRenderTile, TContext> renderer = null)
 {
     this.matcher = matcher;
     adapter      = new RendererAdapter <TRenderTile, TContext>(renderType, renderer);
     onMatchFound = adapter.MatchFound;
 }
Exemplo n.º 4
0
        public override bool Match(int x, int y, TileResultCollector <TRenderTile, TContext> resultCollector)
        {
            coordinates = GridNavigator.NavigateCardinalNeighbours(new MapCoordinate(x, y), coordinates);

            var  n      = Matches(coordinates[(int)Direction.Up]);
            var  e      = Matches(coordinates[(int)Direction.Right]);
            var  s      = Matches(coordinates[(int)Direction.Down]);
            var  w      = Matches(coordinates[(int)Direction.Left]);
            bool result = false;

            if (n)
            {
                if (e)
                {
                    if (tileExists[1])
                    {
                        resultCollector(SpritePosition.Whole, tiles[1], ContextProvider(x, y));
                    }

                    result = true;
                }

                if (w)
                {
                    if (tileExists[0])
                    {
                        resultCollector(SpritePosition.Whole, tiles[0], ContextProvider(x, y));
                    }

                    result = true;
                }
            }

            if (s)
            {
                if (e)
                {
                    if (tileExists[2])
                    {
                        resultCollector(SpritePosition.Whole, tiles[2], ContextProvider(x, y));
                    }

                    result = true;
                }

                if (w)
                {
                    if (tileExists[3])
                    {
                        resultCollector(SpritePosition.Whole, tiles[3], ContextProvider(x, y));
                    }

                    result = true;
                }
            }

            return(result);
        }
Exemplo n.º 5
0
        public bool Match(int x, int y, TileResultCollector <TRenderTile, TContext> onMatchFound)
        {
            if (filterCondition(x, y))
            {
                return(matcher.Match(x, y, onMatchFound));
            }

            return(false);
        }
Exemplo n.º 6
0
        public bool Match(int x, int y, TileResultCollector <TRenderTile, TContextTarget> onMatchFound)
        {
            void Collect(SpritePosition pos, TRenderTile result, TContextSource context)
            {
                onMatchFound(pos, result, Convert(x, y, result, context));
            }

            return(parent.Match(x, y, Collect));
        }
Exemplo n.º 7
0
        public override bool Match(int x, int y, TileResultCollector <TRenderTile, TContext> resultCollector)
        {
            if (tileExists && Matcher(x, y))
            {
                resultCollector(SpritePosition.Whole, tile, ContextProvider(x, y));
                return(true);
            }

            return(false);
        }
Exemplo n.º 8
0
        public bool Match(int x, int y, TileResultCollector <TRenderTile, TContext> resultCollector)
        {
            var result = false;

            for (var i = 0; i < matchers.Count; i++)
            {
                var m = matchers[i];
                result |= m.Match(x, y, resultCollector);
            }

            return(result);
        }
Exemplo n.º 9
0
        public override bool Match(int x, int y, TileResultCollector <TRenderTile, TContext> resultCollector)
        {
            // The current tile is not a land tile. If it is an ocean tile, we can test
            // whether one of the cardinal neighbours is a river that flows into the
            // ocean.
            if (!selfMatcher(x, y))
            {
                return(false);
            }

            coordinates = GridNavigator.NavigateCardinalNeighbours(new MapCoordinate(x, y), coordinates);
            if (Matches(coordinates[CardinalIndex.North.AsInt()]))
            {
                if (northTileExists)
                {
                    resultCollector(SpritePosition.Whole, northTile, ContextProvider(x, y));
                }

                return(true);
            }

            if (Matches(coordinates[CardinalIndex.East.AsInt()]))
            {
                if (eastTileExists)
                {
                    resultCollector(SpritePosition.Whole, eastTile, ContextProvider(x, y));
                }

                return(true);
            }

            if (Matches(coordinates[CardinalIndex.South.AsInt()]))
            {
                if (southTileExists)
                {
                    resultCollector(SpritePosition.Whole, southTile, ContextProvider(x, y));
                }

                return(true);
            }

            if (Matches(coordinates[CardinalIndex.West.AsInt()]))
            {
                if (westTileExists)
                {
                    resultCollector(SpritePosition.Whole, westTile, ContextProvider(x, y));
                }

                return(true);
            }

            return(false);
        }
Exemplo n.º 10
0
        public bool Match(int x, int y, TileResultCollector <TRenderTile, TContext> onMatchFound)
        {
            var sourceTile = readMap(x, y);

            if (mapper(sourceTile, out TRenderTile mapResult, out TContext context))
            {
                onMatchFound(SpritePosition.Whole, mapResult, context);
                return(true);
            }

            return(false);
        }
Exemplo n.º 11
0
        public bool Match(int x, int y, TileResultCollector <TRenderTile, TContext> resultCollector)
        {
            // we need to run both matchers regardless of the result. Both selected tiles will be overlaid on to each other.
            var cardinalMatch = cardinalTileSelector.Match(x, y, resultCollector);
            var diagonalMatch = diagonalTileSelector.Match(x, y, resultCollector);

            if (cardinalMatch || diagonalMatch)
            {
                return(true);
            }

            return(isolatedTileMatcher.Match(x, y, resultCollector));
        }
Exemplo n.º 12
0
        public bool Match(int x, int y, TileResultCollector <TTile, TContext> onMatchFound)
        {
            var key = keyFn(x, y);

            if (matchers.TryGetValue(key, out ITileMatcher <TTile, TContext> m))
            {
                if (m.Match(x, y, onMatchFound))
                {
                    return(true);
                }
            }

            return(false);
        }
Exemplo n.º 13
0
        public bool Match(int x, int y, TileResultCollector <TTile, IItem> onMatchFound)
        {
            bool matched = false;

            foreach (var item in gd.QueryItems(x, y))
            {
                var name = item.ItemType.Name;
                if (tiles.TryFind(name, out TTile tile))
                {
                    matched = true;
                    onMatchFound(SpritePosition.Whole, tile, item);
                }
            }

            return(matched);
        }
Exemplo n.º 14
0
        public bool Match(int x, int y, TileResultCollector <TRenderTile, TContext> resultCollector)
        {
            if (matcher(x, y, out TFactor factor))
            {
                var b = choiceKeys.BinarySearch(factor, comparer);
                if (b < 0)
                {
                    b = ~b - 1;
                    if (b < 0)
                    {
                        return(false);
                    }
                }

                var tile = choiceValues[b];
                resultCollector(SpritePosition.Whole, tile, contextProvider(x, y));
                return(true);
            }

            return(false);
        }
Exemplo n.º 15
0
        public override bool Match(int x, int y, TileResultCollector <TRenderTile, TContext> resultCollector)
        {
            if (!selfMatcher(x, y))
            {
                return(false);
            }

            neighbours = GridNavigator.NavigateNeighbours(new MapCoordinate(x, y), neighbours);
            var idx = MatchAsFlag(neighbours[NeighbourIndex.NorthEast.AsInt()]) << 0;

            idx += MatchAsFlag(neighbours[NeighbourIndex.SouthEast.AsInt()]) << 1;
            idx += MatchAsFlag(neighbours[NeighbourIndex.SouthWest.AsInt()]) << 2;
            idx += MatchAsFlag(neighbours[NeighbourIndex.NorthWest.AsInt()]) << 4;

            if (tagExists[idx])
            {
                resultCollector(SpritePosition.Whole, tags[idx], ContextProvider(x, y));
            }

            return(true);
        }
Exemplo n.º 16
0
        public bool Match(int x, int y, TileResultCollector <TRenderTile, TContext> onMatchFound)
        {
            var en = keyFn(x, y);

            if (en == null)
            {
                return(false);
            }

            bool found = false;

            foreach (var data in en)
            {
                if (mapper(data, out TRenderTile result, out TContext context))
                {
                    onMatchFound(SpritePosition.Whole, result, context);
                    found = true;
                }
            }

            return(found);
        }
Exemplo n.º 17
0
        public bool Match(int x, int y, TileResultCollector <TRenderTile, TContext> resultCollector)
        {
            NavigateForDownwardRenderDirection(x, y, out MapCoordinate coordA,
                                               out MapCoordinate coordB,
                                               out MapCoordinate coordC,
                                               out MapCoordinate coordD);

            if (matchers.Match(coordA.X, coordA.Y, out ITileTagEntrySelection matchA) &&
                matchers.Match(coordB.X, coordB.Y, out ITileTagEntrySelection matchB) &&
                matchers.Match(coordC.X, coordC.Y, out ITileTagEntrySelection matchC) &&
                matchers.Match(coordD.X, coordD.Y, out ITileTagEntrySelection matchD))
            {
                var linearIndex = CellMapTileSelectorKey.LinearIndexOf(matchA, matchB, matchC, matchD);
                if (tileExists[linearIndex])
                {
                    var tile = tiles[linearIndex];
                    resultCollector(SpritePosition.CellMap, tile, contextProvider(x, y));
                    return(true);
                }
            }

            return(false);
        }
Exemplo n.º 18
0
        public override bool Match(int x, int y, TileResultCollector <TRenderTile, TContext> resultCollector)
        {
            if (!selfMatcher(x, y))
            {
                return(false);
            }

            Coordinates = GridNavigator.NavigateCardinalNeighbours(new MapCoordinate(x, y), Coordinates);
            int idx = 0;

            idx += MatchAsFlag(Coordinates[CardinalIndex.North.AsInt()]);
            idx += MatchAsFlag(Coordinates[CardinalIndex.East.AsInt()]) << 1;
            idx += MatchAsFlag(Coordinates[CardinalIndex.South.AsInt()]) << 2;
            idx += MatchAsFlag(Coordinates[CardinalIndex.West.AsInt()]) << 3;

            if (tagExists[idx])
            {
                resultCollector(SpritePosition.Whole, tags[idx], ContextProvider(x, y));
                return(true);
            }

            return(false);
        }
Exemplo n.º 19
0
        public bool Match(int x, int y, TileResultCollector <TRenderTile, TContext> resultCollector)
        {
            mapCoords = gridNavigator.NavigateCardinalNeighbours(new MapCoordinate(x, y), mapCoords);
            var blendSelf = isBlending(x, y);
            var retval    = false;

            for (var i = 0; i < mapCoords.Length; i++)
            {
                var c = mapCoords[i];
                if (!blendSelf && !isBlending(c.X, c.Y))
                {
                    continue;
                }

                var mq = mapQuery(c.X, c.Y);
                if (mq != null && registry.TryFind(mq, directions[i], out var tile))
                {
                    resultCollector(SpritePosition.Whole, tile, contextProvider(x, y));
                    retval = true;
                }
            }

            return(retval);
        }
Exemplo n.º 20
0
        public bool Match(int x, int y, TileResultCollector <TRenderTile, TContext> tile)
        {
            if (!selfMatcher(x, y))
            {
                return(false);
            }

            neighbours = GridNavigator.NavigateNeighbours(new MapCoordinate(x, y), neighbours);
            for (var index = 0; index < selectors.Length; index++)
            {
                var d   = selectors[index];
                var idx = 0;
                idx += MatchAsFlag(neighbours[d.SelectorCoordinates[0]]) << 0;
                idx += MatchAsFlag(neighbours[d.SelectorCoordinates[1]]) << 1;
                idx += MatchAsFlag(neighbours[d.SelectorCoordinates[2]]) << 2;

                if (d.TryGet(idx, out var tileName))
                {
                    tile(d.Position.MapToPosition(), tileName, contextProvider(x, y));
                }
            }

            return(true);
        }
Exemplo n.º 21
0
 public bool Match(int x, int y, TileResultCollector <TMatchedTile, TMatchedContext> onMatchFound)
 {
     return(false);
 }
Exemplo n.º 22
0
 public abstract bool Match(int x, int y, TileResultCollector <TRenderTile, TContext> resultCollector);