Пример #1
0
        public override void remove(Location here, Location to)
        {
            if (here == to)
            {
                return;
            }

            Direction d = here.getDirectionTo(to);

            while (true)
            {
                BridgeRail brr = RailRoad.get(here) as BridgeRail;
                if (brr != null && brr.hasRail(d))
                {
                    // destroy it
                    brr.voxel.railRoad = null;
                    // TODO: delete piers

                    BridgePierVoxel.teardownBridgeSupport(here, TrafficVoxel.get(here));
                }

                if (here == to)
                {
                    return;
                }
                here = here.toward(to);
            }
        }
Пример #2
0
        /// <summary>
        /// Builds normal RR between two specified locations
        /// </summary>
        /// <returns>false if the operation was unsuccessful</returns>
        public static bool build(Location here, Location there)
        {
            // ensure that nothing is on our way between "from" and "to"
            World world = World.world;
            int   cost;

            if (comupteRoute(here, there, out cost) == null)
            {
                return(false);
            }

            Direction d = here.getDirectionTo(there);

            while (true)
            {
                TrafficVoxel v = TrafficVoxel.getOrCreate(here);
                if (v == null)
                {
                    Voxel vv = World.world[here];
                    Debug.Assert(vv.entity.isSilentlyReclaimable);
                    vv.entity.remove();
                    v = TrafficVoxel.getOrCreate(here);
                }

                Direction dd;
                if (here != there)
                {
                    dd = here.getDirectionTo(there);
                }
                else
                {
                    dd = d;
                }

                if (v.railRoad != null)
                {
                    v.railRoad.attach(here == there?d.opposite:d);
                    World.world.onVoxelUpdated(here);
                }
                else
                {
                    v.railRoad = new SingleRailRoad(v, RailPattern.get(d.opposite, dd));

                    // if this RR is elevated, elect a bridge support.
//					if((++cycle%2)==0)
                    BridgePierVoxel.electBridgeSupport(here, typeof(BridgePierVoxel.DefaultImpl), v);
                }

                if (here == there)
                {
                    break;
                }

                d    = dd;
                here = here.toward(there);
            }

            accounting.AccountGenre.RAIL_SERVICE.spend(cost);                   // charge the cost
            return(true);
        }
Пример #3
0
        /// <summary>
        /// Creates a new slope. A slope consists of four consective
        /// blocks of railroads. The base parameter specifies the location
        /// of the lowest railroad and the direction parameter
        /// specifies the direction to climb.
        ///
        /// The caller must use the canCreateSlope method to check
        /// if this method can be invoked.
        /// </summary>
        public static void createSlope(Location _base, Direction dir)
        {
            Debug.Assert(canCreateSlope(_base, dir));

            // charge the cost before we alter something
            accounting.AccountGenre.RAIL_SERVICE.spend(calcCostOfNewSlope(_base, dir));

            SlopeEntity entity = new SlopeEntity(_base, dir);

            for (int i = 0; i < 4; i++)
            {
                if (_base.z < World.world.getGroundLevel(_base))
                {
                    new SlopeRailRoad(entity, TrafficVoxel.getOrCreate(
                                          _base.x, _base.y, _base.z + (i / 2)),
                                      RailPattern.getUGSlope(dir, i));
                    if (i < 2)
                    {
                        // space filler
                        new SlopeFillerVoxel(entity, _base.x, _base.y, _base.z + 1, i);
                    }
                    else
                    {
                        new SlopeSupportVoxel(entity, _base.x, _base.y, _base.z, i,
                                              RailPattern.slopeWalls[dir.index + i - 2]);
                    }
                }
                else
                {
                    new SlopeRailRoad(entity, TrafficVoxel.getOrCreate(
                                          _base.x, _base.y, _base.z + (i / 2)),
                                      RailPattern.getSlope(dir, i));
                    if (i < 2)
                    {
                        // space filler
                        new SlopeFillerVoxel(entity, _base.x, _base.y, _base.z + 1, i);
                    }
                    else
                    {
                        new SlopeSupportVoxel(entity, _base.x, _base.y, _base.z, i,
                                              RailPattern.slopeSupports[dir.index + (i - 2)]);
                    }
                }

                Type bridgeStyle;
                if (dir == Direction.NORTH || dir == Direction.EAST)
                {
                    bridgeStyle = typeof(BridgePierVoxel.DefaultImpl);
                }
                else
                {
                    bridgeStyle = typeof(BridgePierVoxel.SlopeNEImpl);
                }
                BridgePierVoxel.electBridgeSupport(_base, bridgeStyle, entity);

                _base += dir;
            }
        }
Пример #4
0
        /// <summary>
        /// Elects a bridge support from the surface level to the given location,
        /// if it can be done.
        /// </summary>
        /// <param name="loc">The location of the elevated RR.</param>
//		public static void electBridgeSupport( Location loc, Type topBridgeType, Type otherBridgeType ) {
//
//			// check if a support is buildable
//			// TODO: start from the surface level
//			for( int z=0; z<loc.z; z++ )
//				if(World.world[loc.x,loc.y,z]!=null)
//					return;
//
//			// if we can, do it
//			for( int z=World.world.getGroundLevel(loc); z<loc.z; z++ ) {
//				Activator.CreateInstance(
//					(z==loc.z-1)?topBridgeType:otherBridgeType,
//					new object[]{ loc.x, loc.y, z });
//			}
//		}

        /// <summary>
        /// Tears down a bridge support if any.
        /// </summary>
        public static void teardownBridgeSupport(Location loc, Entity owner)
        {
            for (int z = 0; z < loc.z; z++)
            {
                BridgePierVoxel v = World.world[loc.x, loc.y, z] as BridgePierVoxel;
                if (v != null)
                {
                    World.world.remove(loc.x, loc.y, z);
                }
            }
        }
Пример #5
0
        public override void build(Location here, Location to)
        {
            Debug.Assert(canBeBuilt(here, to));

            Direction d        = here.getDirectionTo(to);
            bool      building = false;

            bool pier = true;

            while (true)
            {
                if (RailRoad.get(here) == null)
                {
                    TrafficVoxel v = TrafficVoxel.getOrCreate(here);
                    if (!building)
                    {
                        building = true;
                        create(v, d, BridgeRailMode.Begin);
                    }
                    else
                    {
                        create(v, d,
                               (here == to || RailRoad.get(here + d) != null)
                                                        ? BridgeRailMode.End : BridgeRailMode.Middle);
                    }

                    if (pier)
                    {
                        BridgePierVoxel.electBridgeSupport(here,
                                                           d.isParallelToX ? typeof(PierTop1Impl)  : typeof(PierTop2Impl),
                                                           d.isParallelToX ? typeof(PierBody1Impl) : typeof(PierBody2Impl), v);
                    }

                    pier = !pier;
                }
                else
                {
                    building = false;
                }

                if (here == to)
                {
                    return;
                }
                here = here.toward(to);
            }
        }
Пример #6
0
        public override void build(Location here, Location to)
        {
            Debug.Assert(canBeBuilt(here, to));

            Direction d = here.getDirectionTo(to);

            while (true)
            {
                if (RailRoad.get(here) == null)
                {
                    TrafficVoxel tv = TrafficVoxel.getOrCreate(here);
                    new RailImpl(tv, d);
                    BridgePierVoxel.electBridgeSupport(here, tv);
                }

                if (here == to)
                {
                    return;
                }
                here = here.toward(to);
            }
        }
Пример #7
0
        /// <summary>
        /// Removes a slope. The format of the parameters are the same
        /// as the createSlope method. Ut us
        /// </summary>
        public static void removeSlope(Location loc, Direction dir)
        {
            Debug.Assert(canRemoveSlope(loc, dir));

            // charge the cost before we alter something
            accounting.AccountGenre.RAIL_SERVICE.spend(calcCostOfTearDownSlope(loc, dir));

            for (int i = 0; i < 4; i++)
            {
                TrafficVoxel v = TrafficVoxel.get(loc.x, loc.y, loc.z + (i / 2));
                v.railRoad = null;

                Location l = loc;
                l.z += -(i / 2) + 1;
                Debug.Assert(World.world[l] is EmptyVoxel);
                World.world.remove(l);

                BridgePierVoxel.teardownBridgeSupport(loc, v);

                loc += dir;
            }
        }
Пример #8
0
        /// <summary>
        /// Removes normal RR between two specified locations
        /// </summary>
        /// <returns>false if the operation was unsuccessful</returns>
        public static void remove(Location here, Location there)
        {
            World     world = World.world;
            Direction d     = here.getDirectionTo(there);

            // charge the cost first.
            accounting.AccountGenre.RAIL_SERVICE.spend(calcCostOfRemoving(here, there));

            while (true)
            {
                Direction dd;
                if (here != there)
                {
                    dd = here.getDirectionTo(there);
                }
                else
                {
                    dd = d;
                }

                TrafficVoxel v = TrafficVoxel.get(here);
                if (v != null && v.railRoad != null && !v.isOccupied)
                {
                    v.railRoad.detach(d.opposite, dd);
                }

                BridgePierVoxel.teardownBridgeSupport(here, v);

                if (here == there)
                {
                    break;
                }

                d    = dd;
                here = here.toward(there);
            }
        }