Beispiel #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
     World.world.onVoxelUpdated(owner);
     registerTimer();
 }
Beispiel #2
0
        /// <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);
            }
        }
Beispiel #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);
            }
        }
Beispiel #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);
            }
        }
Beispiel #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);
            }
        }