Beispiel #1
0
        public void remove()
        {
            foreach (Voxel v in cube.voxels)
            {
                if (v.entity == this && !(v is BridgePierVoxel))
                {
                    World.world.remove(v);
                }
                else
                {
                    TrafficVoxel tv = v as TrafficVoxel;
                    if (tv != null)
                    {
                        SlopeRailRoad srr = tv.railRoad as SlopeRailRoad;
                        if (srr != null && srr.entity == this)
                        {
                            tv.remove();
                        }
                    }
                }
//				if(v.location.z==cube.z1)
//					BridgePierVoxel.teardownBridgeSupport(v.location,this);
            }
            if (onEntityRemoved != null)
            {
                onEntityRemoved(this, null);
            }
        }
Beispiel #2
0
        /// <summary>
        /// Compute the cost of destructing a slope rail.
        /// </summary>
        /// <returns>If a destruction is impossible, return 0</returns>
        public static int calcCostOfTearDownSlope(Location loc, Direction dir)
        {
            // make sure the first voxel is not occupied by a car
            if (Car.get(loc) != null)
            {
                return(0);
            }

            // the 2nd block has a distinctive zangle and zdiff. check it.
            loc += dir;
            RailRoad rr = RailRoad.get(loc);

            if (!(rr is SlopeRailRoad))
            {
                return(0);
            }
            SlopeRailRoad srr = (SlopeRailRoad)rr;

            if (!(srr.pattern.zangle == dir && srr.pattern.zdiff == 1))
            {
                return(0);
            }

            // make sure the 2nd rail is not occupied by a car
            if (Car.get(loc) != null)
            {
                return(0);
            }

            // check 3rd and 4th rails.
            loc += dir;
            loc.z++;
            if (Car.get(loc) != null)
            {
                return(0);
            }
            loc += dir;
            if (Car.get(loc) != null)
            {
                return(0);
            }

            return(SLOPE_DESTRUCTION_UNIT_COST * Math.Max(1, loc.z - World.world.waterLevel));
        }
Beispiel #3
0
            public override void draw(DrawContext dc, Point pt)
            {
                Surface display = dc.surface;

                pt.Y -= 9;                      // offset

                CarState.Inside s = state.asInside();
                Debug.Assert(s != null);

                RailRoad rr = s.voxel.railRoad;

                if (rr is SlopeRailRoad)                  // slope rail
                {
                    SlopeRailRoad srr = (SlopeRailRoad)rr;

                    switch (srr.level)                     // apply slope height
                    {
                    case 0: break;

                    case 1: pt.Y -= 4; break;

                    case 2: pt.Y += 8;      break;

                    case 3: pt.Y += 4; break;
                    }

                    if (!parent.isReversed)
                    {
                        type.drawSlope(display, pt, s.direction, s.direction == srr.climbDir);
                    }
                    else
                    {
                        type.drawSlope(display, pt, s.direction.opposite, s.direction != srr.climbDir);
                    }
                }
                else                     // level rail road
                {
                    int d1 = s.direction.index;
                    int d2 = s.voxel.railRoad.guide().index;

                    int angle;
                    if (d1 == d2)
                    {
                        angle = d1 * 2;
                    }
                    else
                    {
                        int diff = (d2 - d1) & 7;
                        if (diff == 7)
                        {
                            diff = -1;
                        }

                        int dd = (d2 * 2 + diff * 3) & 15;                      // operation is on modulo 16.

                        if (2 < dd && dd < 10)
                        {
                            pt.X += 3;
                        }
                        else
                        {
                            pt.X -= 3;
                        }

                        if (6 < dd && dd <= 14)
                        {
                            pt.Y += 2;
                        }
                        else
                        {
                            pt.Y -= 2;
                        }

                        angle = (d1 * 2 + diff) & 15;
                    }

                    if (parent.isReversed)
                    {
                        angle ^= 8;
                    }

                    type.draw(display, pt, angle);
                }
            }