Beispiel #1
0
        public override void drawVoxel(QuarterViewDrawer view, DrawContextEx canvas, Location loc, Point pt)
        {
            if (base.currentPos != loc)
            {
                return;
            }
            if (!contribution.canBeBuilt(loc))
            {
                return;
            }

            int         x;
            RoadPattern rp = TrafficVoxel.get(loc).road.pattern;

            if (rp.hasRoad(Direction.NORTH))
            {
                x = 0;
            }
            else
            {
                x = 1;
            }

            contribution.sprites[color, x].drawAlpha(canvas.surface, pt);
        }
            /// <summary>
            ///
            /// </summary>
            /// <param name="d"></param>
            /// <returns></returns>
            public override bool Attach(Direction d)
            {
                byte dirs = pattern.dirs;

                dirs      |= (byte)(1 << (d.index / 2));
                Voxel.road = new RoadImpl(contribution, Voxel, RoadPattern.get(dirs));
                return(true);
            }
Beispiel #3
0
    public void CreatAssets()
    {
        RoadPattern pattern = CreateInstance <RoadPattern>();

        for (int i = 0; i < TrainConfirmed.Count; i++)
        {
            pattern.MakeSegment(difficulty, trainTypes[i], TrainConfirmed[i], CoinsConfirmed[i], BonusConfirmed[i]);
        }
        AssetDatabase.CreateAsset(pattern, "Assets/ScriptableObject/Road/Pattern/" + DifficultyName[(int)difficulty] + "/" + FileName + ".asset");
        AssetDatabase.SaveAssets();
    }
Beispiel #4
0
        /// <summary>
        /// Create a new road accessory at the specified location.
        /// </summary>
        /// <param name="loc"></param>
        public void Create(Location loc)
        {
            Debug.Assert(CanBeBuilt(loc));

            int         x;
            RoadPattern rp = TrafficVoxel.get(loc).road.pattern;

            if (rp.hasRoad(Direction.NORTH))
            {
                x = 1;
            }
            else
            {
                x = 0;
            }

            new RoadAccessory(TrafficVoxel.get(loc), this, x);
        }
Beispiel #5
0
        /// <summary>
        /// Create a new car at the specified location.
        /// dir = 0 or 1
        /// </summary>
        /// <param name="loc"></param>
        public void create(Location loc)
        {
            Debug.Assert(canBeBuilt(loc));

            int         x;
            RoadPattern rp = TrafficVoxel.get(loc).road.pattern;

            if (rp.hasRoad(Direction.NORTH))
            {
                x = 0;
            }
            else
            {
                x = 1;
            }

            new DummyCar(TrafficVoxel.get(loc), this, currentColor, x);
        }
        /// <summary>
        ///
        /// </summary>
        /// <param name="from"></param>
        /// <param name="to"></param>
        public override void Build(Location from, Location to)
        {
            Debug.Assert(CanBeBuilt(from, to));

            Direction d = from.getDirectionTo(to);

            Location here = from;

            while (true)
            {
                BaseRoad r = BaseRoad.get(here);
                if (r == null)
                {
                    RoadPattern p = RoadPattern.getStraight(d);
                    if (here == from)
                    {
                        p = RoadPattern.get((byte)(1 << (d.index / 2)));
                    }
                    if (here == to)
                    {
                        p = RoadPattern.get((byte)(1 << (d.opposite.index / 2)));
                    }

                    Create(TrafficVoxel.getOrCreate(here), p);
                }
                else
                {
                    if (here != from)
                    {
                        r.Attach(d.opposite);
                    }
                    if (here != to)
                    {
                        r.Attach(d);
                    }
                }

                if (here == to)
                {
                    return;
                }
                here = here.toward(to);
            }
        }
            /// <summary>
            ///
            /// </summary>
            /// <param name="d1"></param>
            /// <param name="d2"></param>
            public override void Detach(Direction d1, Direction d2)
            {
                byte dirs = pattern.dirs;

                dirs &= (byte)~(1 << (d1.index / 2));
                dirs &= (byte)~(1 << (d2.index / 2));

                if (dirs == 0)
                {
                    // destroy this road
                    Voxel.road = null;
                }
                else
                {
                    Voxel.road = new RoadImpl(contribution, Voxel, RoadPattern.get(dirs));
                }

                WorldDefinition.World.OnVoxelUpdated(Location);
            }
Beispiel #8
0
        public ChunkColumn GenerateChunkColumn(ChunkCoordinates chunkCoordinates)
        {
            ChunkColumn chunk = new ChunkColumn();

            chunk.X = chunkCoordinates.X;
            chunk.Z = chunkCoordinates.Z;

            int xOffset = chunk.X << 4;
            int zOffset = chunk.Z << 4;

            for (int x = 0; x < 16; x++)
            {
                for (int z = 0; z < 16; z++)
                {
                    for (int y = 0; y < PlotHeight + 1; y++)
                    {
                        if (y == 0)
                        {
                            chunk.SetBlock(x, y, z, new Bedrock());                                 // Bedrock
                        }
                        else if (y == PlotHeight - 1)
                        {
                            chunk.SetBlock(x, y, z, new Grass());                             // grass
                        }
                        else if (y == PlotHeight)
                        {
                            if (!IsZRoad(z + zOffset, true) && !IsXRoad(x + xOffset, true))
                            {
                                var block = PlotPattern.Next(new BlockCoordinates(x, PlotHeight, z));
                                chunk.SetBlock(x, y, z, block);                                 // pattern
                            }
                        }
                        else if (y > PlotHeight - 4)
                        {
                            chunk.SetBlock(x, y, z, new Dirt());                             // dirt
                        }
                        else
                        {
                            chunk.SetBlock(x, y, z, new Stone());                             // stone
                        }
                    }

                    chunk.SetHeight(x, z, PlotHeight);
                }
            }


            var leaves = new Leaves();

            //if (xOffset < 0) xOffset -= PlotAreaWidth;
            //if (zOffset < 0) zOffset -= PlotAreaDepth;

            for (int x = xOffset; x < xOffset + 16; x++)
            {
                for (int z = zOffset; z < zOffset + 16; z++)
                {
                    for (int i = 1; i < RoadWidth - 1; i++)
                    {
                        var block = RoadPattern.Next(new BlockCoordinates(x, PlotHeight, z));
                        if ((x - i) % PlotAreaWidth == 0)
                        {
                            chunk.SetBlock(x - xOffset, PlotHeight - 1, z - zOffset, block);
                        }

                        if ((z - i) % PlotAreaDepth == 0)
                        {
                            chunk.SetBlock(x - xOffset, PlotHeight - 1, z - zOffset, block);
                        }
                    }

                    if (x % PlotAreaWidth == 0 && !IsZRoad(z))
                    {
                        chunk.SetBlock(x - xOffset, PlotHeight, z - zOffset, leaves);
                    }
                    if ((x - RoadWidth + 1) % PlotAreaWidth == 0 && !IsZRoad(z))
                    {
                        chunk.SetBlock(x - xOffset, PlotHeight, z - zOffset, leaves);
                    }

                    if (z % PlotAreaDepth == 0 && !IsXRoad(x))
                    {
                        chunk.SetBlock(x - xOffset, PlotHeight, z - zOffset, leaves);
                    }
                    if ((z - RoadWidth + 1) % PlotAreaDepth == 0 && !IsXRoad(x))
                    {
                        chunk.SetBlock(x - xOffset, PlotHeight, z - zOffset, leaves);
                    }

                    //if (x%PlotAreaWidth == 0 && z%PlotAreaDepth == 0) chunk.SetBlock(x - xOffset, PlotHeight + 1, z - zOffset, new RedstoneBlock().Id);
                    //if (x%PlotAreaWidth == PlotAreaWidth - 1 && z%PlotAreaDepth == PlotAreaDepth - 1) chunk.SetBlock(x - xOffset, PlotHeight + 1, z - zOffset, new LapisBlock().Id); // stone
                }
            }

            return(chunk);
        }
 /// <summary>
 ///
 /// </summary>
 /// <param name="contrib"></param>
 /// <param name="tv"></param>
 /// <param name="pattern"></param>
 internal protected RoadImpl(AbstractRoadContributionImpl contrib, TrafficVoxel tv, RoadPattern pattern)
     :
     base(tv, pattern, contrib.Style)
 {
     this.contribution = contrib;
 }
 /// <summary>
 /// Creates a new road with a given pattern.
 /// </summary>
 protected virtual BaseRoad Create(TrafficVoxel voxel, RoadPattern pattern)
 {
     return(new RoadImpl(this, voxel, pattern));
 }