예제 #1
0
 public void buildRoad(int v, Direction from, Direction to)
 {
     _road = new Road();
     _road.setLevel(from, v);
     _road.setLevel(to, v);
 }
예제 #2
0
        protected int[] getNearestBranches(PointS p, Direction dir, int length)
        {
            int[] ret = new int[Configure.RoadLevelMax + 1];
            for (int i = 0; i < ret.Length; i++)
            {
                ret[i] = -1;
            }

            if (p.x < 0 || p.x >= world.xWidth)
            {
                return(ret);
            }
            if (p.y < 0 || p.y >= world.yWidth)
            {
                return(ret);
            }

            short vx = 0;
            short vy = 0;

            switch (dir)
            {
            case Direction.EAST:
                vx = +1;
                break;

            case Direction.WEST:
                vx = -1;
                break;

            case Direction.NORTH:
                vy = -1;
                break;

            case Direction.SOUTH:
                vy = +1;
                break;

            default:
                Debug.Assert(false);
                break;
            }
            // find flag: if all level branch found, becomes zero.
            int f = (1 << Configure.RoadLevelMax) - 1;
            // scanning range max.
            int       x    = p.x;
            int       y    = p.y;
            Direction dirL = DirConvertor.rotL(dir);
            Direction dirR = DirConvertor.rotR(dir);

            for (int i = 0; i < length; i++)
            {
                Road r = world[x, y].road;
                if (r != null)
                {
                    int lv = Math.Min(r.getLevel(dirR), r.getLevel(dirL));
                    if (lv <= Configure.RoadLevelMax && ret[lv] == -1)
                    {
                        // store x if dir is E or W otherwise store y.
                        ret[lv] = Math.Abs(x * vx + y * vy);
                        // reset flag
                        f ^= (1 << lv);
                        // all nearest branch found
                        if (f == 0)
                        {
                            break;
                        }
                    }
                }
                x += vx;
                y += vy;
                if (!world.isInWorld(x, y))
                {
                    break;
                }
            }
            return(ret);
        }
예제 #3
0
 public void erase()
 {
     _road      = null;
     _structure = null;
 }