Beispiel #1
0
        public override bool attach(Direction newDir)
        {
            if (hasRail(newDir))
            {
                return(true);                                           // already added
            }
            Direction d1 = dir1, d2 = dir2;

            if (isWellConnected)
            {
                Debug.Assert(is1or3or4(Direction.angle(d1, newDir)) && is1or3or4(Direction.angle(d2, newDir)));
                // if the line is already well connected, make it a junction
                TrafficVoxel v = voxel;
                v.railRoad = new JunctionRailRoad(v, RailPattern.getJunction(d1, d2, newDir));
                World.world.onVoxelUpdated(voxel);
                return(true);
            }
            else
            {
                // if the line is not well connected, change the
                // direction
                if (Direction.angle(d1, newDir) >= 3)
                {
                    pattern = RailPattern.get(d1, newDir);
                    World.world.onVoxelUpdated(voxel);
                    return(true);
                }
                if (Direction.angle(d2, newDir) >= 3)
                {
                    pattern = RailPattern.get(d2, newDir);
                    World.world.onVoxelUpdated(voxel);
                    return(true);
                }
            }

            return(false);              // unable to attach this.
        }