예제 #1
0
        internal virtual void DriveMobile(MobileEntity mobile, DriveCtx dctx)
        {
            var currLane = mobile.Container as Lane;
            var currWay  = currLane.Container as Way;

            if (dctx.IsReachEnd == true)
            {
                currLane.Mobiles.RemoveFirst();
                return;
            }

            //Before updating mobiles status,update that on roadNode
            //the following four funtions are in charge of making decisions,not executing
            this.LaneChanging(dctx);         //换道
            this.Accelerate(dctx);           //符合条件就加速
            this.Decelerate(dctx);           //否则减速
            this.NormalRun(dctx);            //更新位置

            //To execute params setted hereinbefore

            // if a mobile stops ,it must be blocked by traffic light or a mobile ahead
            if (dctx.Params.iMoveY == 0)
            {
                return;
            }
            //还在路段内部
            if (dctx.Params.iMoveY <= dctx.iLaneGap)
            {
                mobile.Move(dctx.Params.iMoveY);
                mobile.iSpeed        = dctx.Params.iSpeed;
                mobile.iAcceleration = dctx.Params.iAcceleration;
            }
            else              //进入了交叉口
            {
                //原有的车道删除该车辆
                currLane.Mobiles.RemoveFirst();

                //进入交叉口
                mobile.Container = currWay.XNodeTo;
                //calculate steps  to move in a xnode
                int iXNodeMoveStep = dctx.Params.iMoveY - dctx.iLaneGap;

                //recalculate moblie shape position
                mobile.Move(iXNodeMoveStep);
                //进入交叉口的等待队列
                currWay.XNodeTo.MobilesInn.Enqueue(mobile);
            }

            mobile.iAcceleration = Math.Max(dctx.Params.iAcceleration, 1);
            mobile.iSpeed        = dctx.Params.iSpeed;
        }
예제 #2
0
        internal virtual void DriveMobile(MobileEntity mobile, DriveCtx dctx)
        {
            var currNode = mobile.Container as XNode;

            //控制权转移出去了
            this.LaneChanging(dctx);         //换道
            this.Accelerate(dctx);           //符合条件就加速

            this.Decelerate(dctx);           //否则减速
            this.NormalRun(dctx);            //更新位置

//			if (mobile.ID ==2) {
//				;
//			}
            //still runing within a xnode
            if (dctx.Params.iMoveY <= dctx.iXNodeGap && dctx.iXNodeGap > 0)
            {
                //modify a mobiles's position
                mobile.Move(dctx.Params.iMoveY);
            }
            else             //enter a lane from its container xnode
            {
                if (dctx.Params.iMoveY > dctx.iFrontHeadWay)
                {
                    ThrowHelper.ThrowArgumentException("前进距离大于车头时距会导致撞车");
                }

                currNode.Mobiles.Remove(mobile);

                int iXNodeStep = dctx.Params.iMoveY - dctx.iXNodeGap;

                var toLane = mobile.Track.ToLane;
                if (toLane != null)
                {
                    toLane.MobilesInn.Enqueue(mobile);

                    //tempraryly modify mobile to get prepareed for moving
                    //mobile.Shape.Start = toLane.Shape.Start;//bug here to modified in the future
                    mobile.Container = toLane;                  //a moible cross a lane and a xnode since it has a ilength

                    mobile.Move(iXNodeStep);
                }
            }

            mobile.iAcceleration = Math.Max(dctx.Params.iAcceleration, 1);
            mobile.iSpeed        = dctx.Params.iSpeed;
        }