示例#1
0
 /// <summary>
 /// Called when a car approaches neighboring traffic voxels.
 /// </summary>
 public void onCarApproaching(TrafficVoxel v)
 {
     // method needs to be public so that the delegate can be serialized
     // redraw this voxel
     WorldDefinition.World.OnVoxelUpdated(owner);
     registerTimer();
 }
示例#2
0
文件: Car.cs 项目: wcp16/FreeTrainSDL
        /// <summary>
        /// Gets a car that occupies the specified place, if any. Or null otherwise.
        /// </summary>
        public static Car Get(Location loc)
        {
            TrafficVoxel v = TrafficVoxel.get(loc);

            if (v == null)
            {
                return(null);
            }
            else
            {
                return(v.car);
            }
        }
示例#3
0
        private void setupHandler(TrafficVoxel neighbor, Direction d)
        {
            RailRoad rr = neighbor.railRoad;

            if (rr != null && rr.hasRail(d.opposite))
            {
                // connected?
                neighbor.onCarChanged += new TrafficVoxelHandler(onCarApproaching);
            }
            else
            {
                // disconnected?
                neighbor.onCarChanged -= new TrafficVoxelHandler(onCarApproaching);
            }
        }
示例#4
0
        private void onRailRoadChanged(TrafficVoxel v)
        {
            // if relevant voxels are affected,
            TrafficVoxel n1 = neighbor1;
            TrafficVoxel n2 = neighbor2;

            if (v == n1)
            {
                setupHandler(n1, owner.railRoad.Dir1);
            }
            if (v == n2)
            {
                setupHandler(n2, owner.railRoad.Dir2);
            }
        }
示例#5
0
        public RRCrossing(TrafficVoxel _owner)
        {
            this.owner        = _owner;
            this.railDirIndex = owner.railRoad.Dir1.isParallelToY?0:1;
            TrafficVoxel.onRailRoadChanged += new TrafficVoxelHandler(onRailRoadChanged);

            neighbor1Location = owner.Location + owner.railRoad.Dir1;
            neighbor2Location = owner.Location + owner.railRoad.Dir2;

            if (neighbor1 != null)
            {
                onRailRoadChanged(neighbor1);
            }
            if (neighbor2 != null)
            {
                onRailRoadChanged(neighbor2);
            }
        }