Пример #1
0
 public PathFinishCondition(Vector3Int target, ActionTargetTypeEnum targetType)
 {
     if (targetType == EXACT || targetType == ANY)
     {
         acceptable.Add(target);
     }
     if (targetType == NEAR || targetType == ANY)   // add near tiles
     {
         LocalMap map = GameModel.localMap;
         PositionUtil.allNeighbour
         .Select(delta => target + delta)
         .Where(pos => map.inMap(pos))
         .Where(pos => map.passageMap.passage.get(pos) == PASSABLE.VALUE)
         .Apply(pos => acceptable.Add(pos));
         PositionUtil.allNeighbour
         .Select(delta => target + delta)
         .Select(pos => pos.add(0, 0, -1))
         .Where(pos => map.inMap(pos))
         .Where(pos => map.blockType.get(pos) == RAMP.CODE)
         .Apply(pos => acceptable.Add(pos));
     }
     if (targetType != NEAR && targetType != ANY)
     {
         return;
     }
 }
Пример #2
0
 private bool hasAdjacentWall(int xc, int yc, int z)
 {
     for (int x = xc - 1; x <= xc + 1; x++)
     {
         for (int y = yc - 1; y <= yc + 1; y++)
         {
             if (localMap.inMap(x, y, z) && localMap.blockType.get(x, y, z) == wallCode)
             {
                 return(true);
             }
         }
     }
     return(false);
 }
Пример #3
0
 // Gets tiles that can be stepped in from given tile.
 private List <Vector3Int> getSuccessors(Vector3Int center, HashSet <Vector3Int> closedSet)
 {
     return(PositionUtil.all
            .Select(vector => center + vector)
            .Where(vector => localMap.inMap(vector) && localMap.passageMap.hasPathBetweenNeighbours(center, vector))
            .Where(vector => !closedSet.Contains(vector)).ToList());
 }
Пример #4
0
 //Observes tiles around given one, and updates atlasX for ramps.
 private void updateRampsAround(Vector3Int center)
 {
     PositionUtil.allNeighbour
     .Select(delta => center + delta)     // get absolute position
     .Where(pos => map.inMap(pos))
     .Where(pos => map.blockType.get(pos) == BlockTypeEnum.RAMP.CODE)
     .ToList().ForEach(pos => updateTile(pos, false));
 }
Пример #5
0
        public NeighbourPositionStream(Vector3Int center) : this()
        {
            this.center = center;
            HashSet <Vector3Int> neighbours = new HashSet <Vector3Int>();

            for (int x = center.x - 1; x < center.x + 2; x++)
            {
                for (int y = center.y - 1; y < center.y + 2; y++)
                {
                    for (int z = center.z - 1; z < center.z + 2; z++)
                    {
                        Vector3Int position = new Vector3Int(x, y, z);
                        if (position != center)
                        {
                            neighbours.Add(position);
                        }
                    }
                }
            }
            stream = neighbours.Where(position => localMap.inMap(position));
        }
Пример #6
0
        private void updateText()
        {
            if (cacheTarget == modelPosition)
            {
                return;
            }
            var pos = modelPosition;

            if (!map.inMap(pos))
            {
                return;
            }
            text.text = "[" + pos.x + ",  " + pos.y + ",  " + pos.z + "]" + "\n"
                        + map.blockType.getEnumValue(pos).NAME + " " + MaterialMap.get().material(map.blockType.getMaterial(pos)).name;
            cacheTarget = modelPosition;
        }
Пример #7
0
        public bool positionReachable(Vector3Int?from, Vector3Int?to, bool acceptNearTarget)
        {
            if (from == null || to == null)
            {
                return(false);
            }
            var fromArea = passage.area.get(from.Value);

            if (passage.area.get(to.Value) == fromArea)
            {
                return(true);                                        // target in same area
            }
            return(acceptNearTarget && PositionUtil.allNeighbour
                   .Select(pos => to + pos)
                   .Where(pos => map.inMap(pos.Value))
                   .Select(pos => passage.area.get(pos.Value))
                   .Any(area => area == fromArea));
        }
Пример #8
0
        /**
         * Checks that walking creature can move from one tile to another.
         * Tiles should be adjacent.
         */
        public bool hasPathBetweenNeighbours(int x1, int y1, int z1, int x2, int y2, int z2)
        {
            if (!localMap.inMap(x1, y1, z1) || !localMap.inMap(x2, y2, z2))
            {
                return(false);                                                            // out of map
            }
            if (passage.get(x1, y1, z1) == IMPASSABLE.VALUE || passage.get(x2, y2, z2) == IMPASSABLE.VALUE)
            {
                return(false);
            }
            if (z1 == z2)
            {
                return(true);          // passable tiles on same level
            }
            int lower = z1 < z2?blockTypeMap.get(x1, y1, z1) : blockTypeMap.get(x2, y2, z2);

            if (x1 != x2 || y1 != y2)
            {
                return(lower == RAMP.CODE);                      // handle ramps
            }
            int upper = z1 > z2?blockTypeMap.get(x1, y1, z1) : blockTypeMap.get(x2, y2, z2);

            return((upper == STAIRS.CODE || upper == DOWNSTAIRS.CODE) && lower == STAIRS.CODE); // handle stairs
        }