Beispiel #1
0
        public ICellMatcher CreateMatcher(int layerIndex, RenderLayerDefinition rd)
        {
            // In cell matching with multiple targets, the matcher must include a self-match.
            var matchSpecs = new List <string>();

            if (rd.MatchAs != null)
            {
                matchSpecs.Add(rd.MatchAs);
            }

            matchSpecs.AddRange(rd.MatchWith);

            // tagname -> List of matching ITerrains
            var otherGraphicTags = ComputeMatchingTerrains(layerIndex, matchSpecs);
            var factory          = TileTagEntrySelectionFactory.FromTagsAsSingleCharKey(otherGraphicTags.Keys.ToArray());
            var rules            = Context.GameData.Rules;
            var terrainsByKey    = new ITileTagEntrySelection[rules.TerrainTypes.Count];

            foreach (var pair in otherGraphicTags)
            {
                var key = factory.Lookup(pair.Key);
                foreach (var terrain in pair.Value)
                {
                    var b = rules.TerrainTypes.IndexOf(terrain);
                    terrainsByKey[b] = key;
                }
            }

            var map = Context.GameData.Terrain;

            return(new LookupMatcher(map, factory, terrainsByKey));
        }
Beispiel #2
0
 public FogCellMatcher(IFogMap map)
 {
     this.map = map;
     Owner    = TileTagEntrySelectionFactory.FromTagsAsSingleCharKey("unknown", "fog", "known");
     states   = new[]
     {
         Owner[0],
         Owner[1],
         Owner[2],
         Owner[2]
     };
 }
Beispiel #3
0
        public List <TextureTile> Generate(TextureGrid grid)
        {
            var cellMapEntries = grid.CellMappings.Where(e => !string.IsNullOrWhiteSpace(e.Key)).ToList();

            if (cellMapEntries.Count <= 1)
            {
                return(new List <TextureTile>());
            }

            var selectionFactory = TileTagEntrySelectionFactory.FromTagsAsTextKey(cellMapEntries.Select(e => e.Key ?? "").ToArray());
            var selections       = selectionFactory.ToSelectionArray();
            var tileCount        = Math.Pow(selections.Length, 4);
            var width            = (int)Math.Ceiling(Math.Sqrt(tileCount));

            TextureTile Create(ITileTagEntrySelection m1,
                               ITileTagEntrySelection m2,
                               ITileTagEntrySelection m3,
                               ITileTagEntrySelection m4)
            {
                var key      = new CellMapTileSelectorKey(m1, m2, m3, m4);
                var tileName = key.Format(grid.Name, grid.Pattern);
                var x        = key.LinearIndex % width;
                var y        = key.LinearIndex / width;

                return(new TextureTile(true, x, y, tileName)
                {
                    SelectorHint = FormatCellMapSelectorKey(key)
                });
            }

            var x = from m4 in selections
                    from m3 in selections
                    from m2 in selections
                    from m1 in selections
                    select Create(m1, m2, m3, m4);

            return(x.ToList());
        }