Пример #1
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public bool Add(CarState model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into CarState(");
            strSql.Append("LSH,CASEID,CCCC,CLID,SJ,ZT,TASK_TERMINATION_REASON,ADDTIME)");
            strSql.Append(" values (");
            strSql.Append(":LSH,:CASEID,:CCCC,:CLID,:SJ,:ZT,:TASK_TERMINATION_REASON,:ADDTIME)");
            OracleParameter[] parameters =
            {
                new OracleParameter(":LSH",                     DBOpHelper.GetString(model.LSH)),
                new OracleParameter(":CASEID",                  DBOpHelper.GetString(model.CASEID)),
                new OracleParameter(":CCCC",                    DBOpHelper.GetNumber(model.CCCC)),
                new OracleParameter(":CLID",                    DBOpHelper.GetString(model.CLID)),
                new OracleParameter(":SJ",                      DBOpHelper.GetDateTime(model.SJ)),
                new OracleParameter(":ZT",                      DBOpHelper.GetString(model.ZT)),
                new OracleParameter(":TASK_TERMINATION_REASON", DBOpHelper.GetString(model.TASK_TERMINATION_REASON)),
                new OracleParameter(":ADDTIME",                 DBOpHelper.GetDateTime(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")))
            };
            int rows = DbHelperOra.ExecuteSql(SysParameters.DBConnectString, strSql.ToString(), parameters);

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Пример #2
0
        public Hashtable GetCarStepHashtableByModel(CarState cs)
        {
            /*
             *  lsh;	String	流水号	Varchar2(19) not null	19	必填,主键,120生成
             *  caseId	String	CaseID	Varchar2(20)	20	由APP提供
             *  cccc	Integer	出车车次	Number(2)	2	必填
             *  clid	String	车俩ID	Varchar2(10) not null	10	必填
             *  sj	Date    状态数据时间	Date		必填
             *  zt	String	状态	Varchar2(20)	20	必填,出车默认不需发送,主要有
             *  1.到达现场,2.病人上车,3.送达医院,4.任务完成。
             *  5.任务中止
             *  reason	String	任务中止异常原因描述	Varchar2(100)	100	1.用户来电取消,2车辆故障,3.病人已康复,4.车道人走,5.拒绝治疗,6.病人已死亡
             */
            Hashtable ht = new Hashtable();

            ht.Add("messageName", "CarStep");
            ht.Add("caseId", cs.CASEID);
            ht.Add("cccc", cs.CCCC);
            ht.Add("clid", cs.CLID);
            ht.Add("lsh", cs.LSH);
            ht.Add("sj", string.Format("{0:yyyy-MM-dd HH:mm:ss}", cs.SJ));
            ht.Add("zt", cs.ZT);
            ht.Add("reason", cs.TASK_TERMINATION_REASON);

            return(ht);
        }
Пример #3
0
    // Update is called once per frame
    void Update()
    {
        if (State == CarState.Starting)
        {
            transform.position = Vector3.Lerp(transform.position, StopPoint, Time.deltaTime);
            if (Vector3.Distance(transform.position, StopPoint) < 0.01f)
            {
                transform.position = StopPoint;
                State = CarState.Waiting;
            }
        }

        if (State == CarState.Waiting)
        {
            var cargos = gameObject.GetComponentsInChildren<MoleculeCarCargo>();
            if (cargos != null && cargos.Length > 0 && cargos.All(c=>c.IsLoaded))
            {
                State = CarState.Ending;
            }
        }

        if (State == CarState.Ending)
        {
            transform.position = Vector3.Lerp(transform.position, EndPoint, Time.deltaTime);
        }
    }
Пример #4
0
        private CarState GetCarStateModelByHashtable(Hashtable htMessage)
        {
            CarState sci = new CarState();

            if (htMessage["caseId"] != null)
            {
                sci.CASEID = htMessage["caseId"].ToString();
            }
            if (htMessage["cccc"] != null && htMessage["cccc"].ToString() != "")
            {
                sci.CCCC = int.Parse(htMessage["cccc"].ToString());
            }
            if (htMessage["clid"] != null)
            {
                sci.CLID = htMessage["clid"].ToString();
            }
            if (htMessage["lsh"] != null)
            {
                sci.LSH = htMessage["lsh"].ToString();
            }
            if (htMessage["sj"] != null && htMessage["sj"].ToString() != "")
            {
                sci.SJ = DateTime.Parse(htMessage["sj"].ToString());
            }
            if (htMessage["zt"] != null)
            {
                sci.ZT = htMessage["zt"].ToString();
            }
            if (htMessage["reason"] != null)
            {
                sci.TASK_TERMINATION_REASON = htMessage["reason"].ToString();
            }
            return(sci);
        }
Пример #5
0
 public OnePoint(GISVertex _location, CarState _State, string carID, string gpstime)
 {
     CarLocation = _location;
     State       = _State;
     CarID       = carID;
     GPSTime     = gpstime;
 }
Пример #6
0
        /// <summary>
        /// 增加一条数据
        /// </summary>
        public bool Add(CarState model)
        {
            StringBuilder strSql = new StringBuilder();

            strSql.Append("insert into carstate(");
            strSql.Append("LSH,CASEID,CCCC,CLID,SJ,ZT,TASK_TERMINATION_REASON,ADDTIME)");
            strSql.Append(" values (");
            strSql.Append("@LSH,@CASEID,@CCCC,@CLID,@SJ,@ZT,@TASK_TERMINATION_REASON,@ADDTIME)");
            MySqlParameter[] parameters =
            {
                new MySqlParameter("@LSH",                     DBOpHelper.GetString(model.LSH)),
                new MySqlParameter("@CASEID",                  DBOpHelper.GetString(model.CASEID)),
                new MySqlParameter("@CCCC",                    DBOpHelper.GetNumber(model.CCCC)),
                new MySqlParameter("@CLID",                    DBOpHelper.GetString(model.CLID)),
                new MySqlParameter("@SJ",                      DBOpHelper.GetDateTime(model.SJ)),
                new MySqlParameter("@ZT",                      DBOpHelper.GetString(model.ZT)),
                new MySqlParameter("@TASK_TERMINATION_REASON", DBOpHelper.GetString(model.TASK_TERMINATION_REASON)),
                new MySqlParameter("@ADDTIME",                 DBOpHelper.GetDateTime(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")))
            };

            int rows = DbHelperMySQL.ExecuteSql(strSql.ToString(), parameters);

            if (rows > 0)
            {
                return(true);
            }
            else
            {
                return(false);
            }
        }
Пример #7
0
 protected override void InitializeCustom()
 {
     base.InitializeCustom();
     carState        = CarState.Started;
     total_dist_goal = this.currentGoalV - this.positionV;
     goal_last_frame = 0;
 }
Пример #8
0
    void Start()
    {
        cameraSensor  = GetComponentInChildren <CameraSensor>();
        carState      = GetComponent <CarState>();
        carController = GetComponent <CarController>();

        IPEndPoint localEndPoint = new IPEndPoint(IPAddress.Any, DeterminePort());

        listener = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

        checkpoints = new Checkpoints();
        reward      = new Reward(checkpoints);



        // foreach (GameObject gameObject in checkpoints.checkpointsArray) {
        //  Debug.Log(gameObject.name);
        // }

        try {
            listener.Bind(localEndPoint);
            listener.Listen(1);

            BeginAccept();
        } catch (Exception e) {
            Debug.LogException(e);
        }
    }
Пример #9
0
 private bool IsCarInFront(CarState car, CarState other)
 {
     return((car.lap > other.lap) ||
            (car.lap == other.lap && car.stage > other.stage) ||
            (car.lap == other.lap && car.stage == other.stage &&
             DistanceToCheckpoint(car) < DistanceToCheckpoint(other)));
 }
        IEnumerator SetReady(float waitTime)
        {
            yield return(new WaitForSeconds(waitTime));

            carState = CarState.Ready;
            UIManager.Instance.SetVisibleStartText(true);
        }
Пример #11
0
    private void Update()
    {
        switch (myState)
        {
        case CarState.ARRIVING:
            transform.position = Vector3.Lerp(startPos, parkPos, (Time.time - startedDrive) * speed / distToPark);

            if (transform.position == parkPos)
            {
                // We've made it!
                myState    = CarState.PARKED;
                wc.enabled = true;
            }
            break;

        case CarState.PARKED:
            if (wc.enabled == false)
            {
                // Our wordComponent has disabled itself, drive off.
                myState      = CarState.LEAVING;
                startedDrive = Time.time;
            }
            break;

        case CarState.LEAVING:
            transform.position = Vector3.Lerp(parkPos, endPos, (Time.time - startedDrive) * speed / distToEnd);

            if (transform.position == endPos)
            {
                Destroy(this.gameObject);
            }
            break;
        }
    }
Пример #12
0
    // Called when the camera finds a goal object
    public void FoundGoal(GameObject goalObject)
    {
        if (currentState != CarState.Goal) //If the car is idling but manages to spot a missed goal object, set it as current goal and move towards it (EDGE CASE)
        {
            currentGoal  = goalObject.transform;
            targetPos    = currentGoal.position;
            currentState = CarState.Goal;

            lastTargetSwitch = Time.time;
        }
        else if (currentState == CarState.Goal) //If we already have a goal but we detect another goal object
        {
            if (Time.time - lastTargetSwitch > targetSwitchTimer)
            {
                //If the newfound object is closer than the previously selected obj, set new one as current goal
                float newDistance = Vector3.Distance(transform.position, goalObject.transform.position);
                if (newDistance < distToGoal)
                {
                    currentGoal  = goalObject.transform;
                    targetPos    = currentGoal.position;
                    currentState = CarState.Goal;
                }

                lastTargetSwitch = Time.time;
            }
        }
    }
Пример #13
0
        IReadOnlyList <CarState> GetInitialCarStates()
        {
            var states = new CarState[cars.Length];

            // create all
            for (int i = 0; i < cars.Length; i++)
            {
                states[i] = new CarState(cars[i].InitialLane);
            }

            // make dependencies
            for (int i = 0; i < cars.Length; i++)
            {
                for (int j = i + 1; j < cars.Length; j++)
                {
                    if (AreOverlapping(cars[i].InitialPosition, cars[j].InitialPosition))
                    {
                        var ok = TryMakeDependency(states[i], states[j]);
                        Debug.Assert(ok);
                    }
                }
            }

            // ignore lane when no dependency
            for (int i = 0; i < cars.Length; i++)
            {
                states[i].CleanUp();
            }

            return(states);
        }
    private void Start()
    {
        InvokeRepeating("UpdateCar", 0f, 1 / Constants.targetHz);

        //Get dimensions of car sprite
        float length = GetComponentInChildren <Renderer>().bounds.size.x;
        float width  = GetComponentInChildren <Renderer>().bounds.size.y;

        //Initialize the controllers and system
        carController = new CarController(length);
        steerSys      = new FirstOrderSystem(Constants.carSimSteeringK, Constants.carSimSteeringTau, Constants.targetHz, 0f);
        throttleSys   = new AsymmetricFirstOrderSystem(Constants.carSimVelK, Constants.carSimVelIncreaseTau, Constants.carSimVelDecreaseTau, Constants.targetHz, 0f);

        // Set initial car state
        carState = new CarState(0, transform.position.z, transform.position.x, 0, length / 2, length / 2);
        goalPos  = transform.position;
        SetTargetPosition(goalPos);

        //Draw the lidar visualization
        line = gameObject.GetComponent <LineRenderer>();
        line.SetVertexCount(numLineSegments + 1);
        line.useWorldSpace = false;
        DrawLidar();

        Debug.Log(string.Format("track width {0}", GetTrackWidth()));
        Debug.Log(string.Format("track length {0}", GetTrackLength()));
    }
Пример #15
0
        public void setState(RoleInGame player, ref List <string> notifyMsg, CarState s)
        {
            this._state = s;
            if (player.playerType == RoleInGame.PlayerType.player)
            {
                SendStateAndPurpose((Player)player, this, ref notifyMsg);
            }

            if (s == CarState.waitOnRoad)
            {
                if (player.playerType == RoleInGame.PlayerType.NPC)
                {
                    ((NPC)player).dealWithWaitedNPC(ref notifyMsg);
                }
            }
            if (this._state != CarState.waitOnRoad)
            {
                if (string.IsNullOrEmpty(player.getCar().isControllingKey))
                {
                }
                else
                {
                    player.getCar().clearControllingObj();
                    player.controlPrepareMagicChanged(player, ref notifyMsg);
                }
            }
        }
Пример #16
0
        /// <summary>
        /// 发送车辆状态信息给route server
        /// </summary>
        /// <param name="sci"></param>
        public void SendCarStep(CarState cs)
        {
            Hashtable      ht      = GetCarStepHashtableByModel(cs);
            ScsTextMessage message = new ScsTextMessage(JSON.Encode(ht));

            SendMessage(message);
        }
Пример #17
0
 public float speed;//车速
 public Car(Position carPos, EdgeData car_EdgeData, CarState carState, float speed)
 {
     this.carPos       = carPos;
     this.car_EdgeData = car_EdgeData;
     this.carState     = carState;
     this.speed        = speed;
 }
Пример #18
0
        public void HandleCarStep(CarState cs)
        {
            try
            {
                //Save Database
                IDBCarState db = DataAccess.DataAccess.GetDBCarState();
                db.Add(cs);

                CarStepManagerDelegateClient client = new CarStepManagerDelegateClient();
                client.addCarStepCompleted += new EventHandler <addCarStepCompletedEventArgs>(Service_Completed);
                CredentialSoapHeader header = new CredentialSoapHeader();
                header.Username = SysParameters.AppAPIUsername;
                header.Password = SysParameters.AppAPIPassword;
                string strJson = ConvertModelToJson(cs);

                WebserviceUserState UserState = new WebserviceUserState();
                UserState.TIMES   = 1;
                UserState.MESSAGE = strJson;

                //{"caseId":"a07aa295-e5f0-41bb-858d-277b1e3479ff","lsh":"2016061300000000005","sj":"2016-06-13 17:19:41","zt":"病人上车","reason":"","clid":"101","cccc":2}
                client.addCarStepAsync(header, strJson, UserState);
            }
            catch (Exception ex)
            {
                LogHelper.WriteLog("", ex);
            }
        }
Пример #19
0
    public float DetermineFitness(CarState state)
    {
        //return UnityEngine.Random.value * 1000;

        //state.AngleToGoal         Drehung           0     0.6       0.1
        //state.CurrentVelocity     Geschwindiket     0     0.8       0.3
        //state.DistanceFromGoal    Entfernung        0     0.9       0.2
        //state.NumberOfCollisions  Unfall            0       9         1


        float angle      = state.AngleToGoal();
        float velocity   = state.CurrentVelocity();
        float distance   = state.DistanceFromGoal();
        int   collisions = state.NumberOfCollisions();

        if (angle < 0.1)
        {
            fAngle = 0.1F;
        }
        if (angle >= 0.1)
        {
            fAngle = 0.9F;
        }

        if (velocity < 0.1)
        {
            fVelocity = 0.1F;
        }
        if (velocity > 0.5)
        {
            fVelocity = 0.9F;
        }

        if (distance < 0.5)
        {
            fDistance = 0.1F;
        }
        if (distance >= 0.5)
        {
            fDistance = 0.9F;
        }


        if (collisions == 0)
        {
            fCollision = 0.1F;
        }
        if (collisions > 0 && collisions <= 3)
        {
            fCollision = 0.5F;
        }
        if (collisions > 3)
        {
            fCollision = 0.99F;
        }

        float fitness = 1 - (fAngle * fVelocity * fDistance * fCollision);

        return((distance / 100) - 5);
    }
Пример #20
0
    IEnumerator RunToTargetPositon(float targetPosX)
    {
        arrived = false;
        StartCoroutine(OpenTools());
        Debug.Log("============start==============");
        float   curTime  = 0;
        Vector3 startPos = this.transform.position;

        carState = (targetPosX - this.transform.position.x) > 0?CarState.runForward:CarState.runBack;
        while (Mathf.Abs(targetPosX - this.transform.position.x) > 0.001f)
        {
            yield return(null);

            curTime += Time.deltaTime;
            this.transform.position = new Vector3(Mathf.Lerp(startPos.x, targetPosX, curTime), this.transform.position.y, this.transform.position.z);
        }
        carState  = CarState.stop;
        ropeState = RopeState.Elong;
        yield return(StartCoroutine(OperateTheRope()));

        while (!arrived)
        {
            yield return(null);
        }
    }
        public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
        {
            if (stream.IsWriting)
            {
                if (!photonView.IsMine)
                {
                    return;
                }
                stream.SendNext(Input.Forward);
                stream.SendNext(Input.Steer);
                stream.SendNext(State);

                stream.SendNext(Rigidbody.position);
                stream.SendNext(Rigidbody.rotation);
                stream.SendNext(Rigidbody.velocity);
                stream.SendNext(Rigidbody.angularVelocity);
            }
            else
            {
                Input.Forward = (float)stream.ReceiveNext();
                Input.Steer   = (float)stream.ReceiveNext();
                State         = (CarState)stream.ReceiveNext();

                Network.Position          = (Vector3)stream.ReceiveNext();
                Network.Rotation          = (Quaternion)stream.ReceiveNext();
                Rigidbody.velocity        = (Vector3)stream.ReceiveNext();
                Rigidbody.angularVelocity = (Vector3)stream.ReceiveNext();

                float lag = Mathf.Abs((float)(PhotonNetwork.Time - info.timestamp));
                Network.Position += Rigidbody.velocity * lag;
            }
        }
Пример #22
0
        //Should be beteween 0..1
        public float DetermineFitness(CarState state)
        {
            //Debug.Log(state.DistanceFromGoal() + " -- " + state.AngleToGoal());
            int maxDistance = 40;

            float angle    = state.AngleToGoal(); //transform:  angle = 1 --> Optimal; angle = 0 --> so bad
            float distance = state.DistanceFromGoal();

            float weightDistance  = 0.50f;
            float weightAngle     = 0.30f;
            float weightCollision = 0.1f;
            float weightSpeed     = 0.1f;

            // 0 ... car ... max    --> lerp
            Debug.Log("the angle is: " + angle);
            float partDistance  = weightDistance * (float)Math.Pow((1f - Math.Min(distance, maxDistance) / maxDistance), 2);
            float partCollision = weightCollision * (float)Math.Pow((1f - Math.Min(state.NumberOfCollisions(), 4) / 4), 2);
            float partSpeed     = weightSpeed * (float)Math.Pow((1f - Math.Min(state.CurrentVelocity(), 1)), 2);
            float partAngle     = weightAngle * (float)Math.Pow((1f - (Math.Abs(angle / 4))), 2);                                // why
            //float partAngle = weightAngle           * ((float)Math.Pow(1f - Math.Min(angle, (4 - angle)) / 2f, 2f));
            //float partAngle = weightAngle           * (float)Math.Pow((1 - (Math.Abs ( 2 - angle) / 2)),1f);
            //Debug.Log("Angle: " + angle + "  rel: " + relAngle + " with faktor:" + partAngle);

            float sum = partDistance + partAngle + partCollision + partSpeed;

            return(sum);
            //else return sum;
        }
 // Start is called before the first frame update
 void Start()
 {
     Instance = this;
     carState = CarState.Null;
     rb       = GetComponent <Rigidbody>();
     StartCoroutine(SetReady(0.5f));
 }
Пример #24
0
 public void SetRanksCar()
 {
     CarB[] cars = FindObjectsOfType(typeof(CarB)) as CarB[];//for optimize
     if(cars.Length > 0)
     {
         _cars = new CarState[cars.Length];//for optimize
         int i = 0;
         foreach(CarB car in cars)
         {
             _cars[i] = new CarState(car);
     //				_cars[i].carBody = car.GetComponent<DriftCar>();
     //				_cars[i].carBBody = car;
     //				_cars[i].property = car.GetComponent<CarProperty>();
     //				_cars[i].name = ((Definition.eCarID)car[i].property.carID).ToString();
             i++;
         }
         foreach(UISprite sprite in playerRanks)
         {
             if(sprite)
             {
                 sprite.enabled = true;
             }
         }
     }
 }
Пример #25
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="s"></param>
 /// <returns></returns>
 public CarState this[CarState s]
 {
     get
     {
         return((CarState)s.accept(this));
     }
 }
Пример #26
0
 public bool this[CarState s]
 {
     get
     {
         return((bool)s.accept(this));
     }
 }
Пример #27
0
        public override Controller GetOutput(rlbot.flat.GameTickPacket gameTickPacket)
        {
            gameInfo.Update(gameTickPacket, GetRigidBodyTick());
            ballPrediction.Update(GetBallPrediction());

            if (timeout > 5)
            {
                GameState gamestate = new GameState();
                gamestate.BallState.PhysicsState.Location        = new DesiredVector3(RandomFloat(-3000, 3000), 2000, 100);
                gamestate.BallState.PhysicsState.AngularVelocity = new DesiredVector3(0, 0, 0);
                gamestate.BallState.PhysicsState.Velocity        = new DesiredVector3(RandomFloat(2000, 2000), RandomFloat(1000, 2000), RandomFloat(1500, 1600));

                CarState carstate = new CarState();
                carstate.PhysicsState.AngularVelocity = new DesiredVector3(0, 0, 0);
                carstate.PhysicsState.Velocity        = new DesiredVector3(0, 0, 0);
                carstate.PhysicsState.Location        = new DesiredVector3(0, 0, 17);
                carstate.PhysicsState.Rotation        = new DesiredRotator(0, (float)(Math.PI / 2), 0);

                gamestate.SetCarState(index, carstate);

                SetGameState(gamestate);

                timeout = 0;
                aerial  = null;
            }

            timeout += gameInfo.DeltaTime;

            Controller controller = new Controller();

            Car  car  = gameInfo.Cars[index];
            Ball ball = gameInfo.Ball;

            Slice[] slices = ballPrediction.ToArray();

            if (timeout > 0.3)
            {
                if (aerial == null)
                {
                    aerial = Aerial.FindAerialOpportunity(car, slices, gameInfo.Time, settings);
                }
                else
                {
                    controller = aerial.Step(ball, 0.016667f, gameInfo.Time);
                    Renderer.DrawLine3D(Colors.Red, car.Position, aerial.Target);

                    if (aerial.Finished)
                    {
                        aerial = null;
                    }
                    else
                    {
                        aerial.UpdateAerialTarget(slices, gameInfo.Time);
                    }
                }
            }

            return(controller);
        }
Пример #28
0
        protected override void Seed(CarRentalSystemContext context)
        {
            List <CarState> carStates = context.States.ToList();

            if (carStates.Count == 0)
            {
                string[] states = new string[] { "free", "rented" };

                foreach (string state in states)
                {
                    CarState carState = new CarState()
                    {
                        Value = state
                    };

                    context.States.Add(carState);
                }

                context.SaveChanges();
            }

            CarState     carFreeState = context.States.FirstOrDefault(cs => cs.Value == "free");
            List <Store> stores       = context.Stores.ToList();

            if (stores.Count == 0)
            {
                string[] storeNames = new string[] { "Store1", "Store2", "Store3" };

                foreach (string storeName in storeNames)
                {
                    Store store = new Store()
                    {
                        Name      = storeName,
                        Latitude  = 23.333m,
                        Longitude = 41.111m
                    };

                    context.Stores.Add(store);

                    for (int i = 0; i < 5; i++)
                    {
                        Car car = new Car()
                        {
                            Make   = "CarMake" + i,
                            Model  = "Model" + i,
                            Year   = 1982 + i,
                            Power  = 74 + i * 10,
                            Engine = 2000 + i * 100,
                            Store  = store,
                            State  = carFreeState
                        };

                        context.Cars.Add(car);
                    }
                }
            }

            context.SaveChanges();
        }
Пример #29
0
 private void Stop()
 {
     motorA.StopBack();
     motorA.StopForward();
     motorB.StopForward();
     motorB.StopBack();
     this.CurrentState = CarState.Stopped;
 }
Пример #30
0
 private void StopDrift()
 {
     state = CarState.DRIVE;
     _dampDriftOffsetTarget               = 0;
     _dampDriftStrengthTarget             = 1;
     _dampVisualHorizontalMultiplerTarget = 0;
     input.SetChangeRate(limitedHorizontalChangeRate);
 }
Пример #31
0
 public void setState(RoleInGame player, ref List <string> notifyMsg, CarState s)
 {
     this._state = s;
     if (player.playerType == RoleInGame.PlayerType.player)
     {
         SendStateAndPurpose((Player)player, this, ref notifyMsg);
     }
 }
Пример #32
0
    /// <summary>
    /// Disable the car
    /// </summary>
    protected virtual void DisableCar()
    {
        //Set state
        currentState = CarState.Disabled;

        //Activate the particle system
        smokeParticleSystem.gameObject.SetActive(true);
    }
Пример #33
0
 private void Initialize()
 {
     //initialize the motors.
     motorA = new GpioMotorController(motorAForwardPin, motorABackPin);
     motorB = new GpioMotorController(motorBForwardPin, motorBBackPin);
     //initialize our senses.
     distanceSensor = new HCSR04(triggerPin, echoPin);
     this.Stop();
     this.CurrentState = CarState.Stopped;
 }
Пример #34
0
 // Use this for initialization
 void Start()
 {
     if (this.isTop)
     {
         m_carstate = Main.S.carTop.GetComponent<CarState>();
     }
     else
     {
         m_carstate = Main.S.carBottom.GetComponent<CarState>();
     }
     m_text = gameObject.GetComponent<Text>();
 }
        public void resetCar()
        {
            toNode = 0;
            fromSegment = 0;
            toSegment = 0;
            toLaneID = 0;
            fromLaneID = 0;
            fromLaneFlags = 0;
            stopped = false;

            waitTime = 0;
            carState = CarState.None;
        }
Пример #36
0
 /// <summary>
 /// Initializes the Car Brain
 /// This code runs when a new brain is created.
 /// </summary>
 public CarBrain()
 {
     //sets the first state of the car to unknown.
     CurrentState = CarState.Unknown;
     //initialize our motors.
     this.Initialize();
                 
     while(true) //do stuff forever.
     {
         //drive, this is where main logic happens.
         this.Drive();
     }
 }
Пример #37
0
 void OnEnable()
 {
     if (isBottom)
     {
         m_carstate = Main.S.carBottom.GetComponent<CarState>();
     }
     else
     {
         m_carstate = Main.S.carTop.GetComponent<CarState>();
     }
     setSummary();
     setHighscoreList();
 }
Пример #38
0
        public void ResetCar()
        {
            ToNode = 0;
            FromSegment = 0;
            ToSegment = 0;
            ToLaneId = 0;
            FromLaneId = 0;
            FromLaneFlags = 0;
            Stopped = false;

            WaitTime = 0;
            CarState = CarState.None;
        }
Пример #39
0
 private void DriveForward()
 {
     motorA.DriveForwardFull();
     motorB.DriveForwardFull();
     this.CurrentState = CarState.DrivingForward;            
 }
Пример #40
0
 public void NowOnRoad()
 {
     carState = CarState.onRoad;
 }
Пример #41
0
 private void TurnLeft()
 {
     motorA.StopForward();
     motorB.StopForward();
     motorB.DriveForwardFull();
     this.CurrentState = CarState.TurningLeft;
     System.Threading.SpinWait.SpinUntil(() => { return false; }, 100);
     motorB.StopForward();
     this.CurrentState = CarState.Stopped;
 }
Пример #42
0
 private void Stop()
 {
     motorA.StopBack();
     motorA.StopForward();
     motorB.StopForward();
     motorB.StopBack();
     this.CurrentState = CarState.Stopped;
 }
Пример #43
0
 private bool CalculateRank(CarState car1, CarState car2)
 {
     if(car1.round > car2.round || (car1.round == car2.round && (car1.nowNode > car2.nowNode || (car1.nowNode == car2.nowNode && CalculateDistance(car1, car2, car1.nowNode)))))
     {
         return true;
     }
     else
     {
         return false;
     }
 }
Пример #44
0
 private void Swap(CarState[] cars, int i, int j)
 {
     CarState car = cars[i];
     cars[i] = cars[j];
     cars[j] = car;
 }
Пример #45
0
 public void Sort(CarState[] cars)
 {
     Sort(cars, 0, cars.Length - 1);
 }
Пример #46
0
 bool CalculateDistance(CarState car1, CarState car2, int node)
 {
     float distance1;
     Vector3 nodePosition = PathNodeManager.SP.getNode(node).position;
     //		if(car1.carBody)
     //			distance1 = Vector3.Distance(car1.carBody.transform.position, nodePosition);
     //		else
     distance1 = Vector3.Distance(car1.carBBody.transform.position, nodePosition);
     float distance2;
     //		if(car2.carBody)
     //			distance2 = Vector3.Distance(car2.carBody.transform.position, nodePosition);
     //		else
     distance2 = Vector3.Distance(car2.carBBody.transform.position, nodePosition);
     car1.distance = distance1;
     car2.distance = distance2;
     if(distance1 < distance2)
         return true;
     else
         return false;
 }
Пример #47
0
 // Use this for initialization
 void Start()
 {
     m_arcadeVehicle = gameObject.GetComponentInParent<ArcadeVehicle>();
     m_carstate  = gameObject.GetComponentInParent<CarState>();
     m_transform  = gameObject.GetComponentInParent<Transform>();
     m_topInCollisionZone = false;
     m_bottomInCollisionZone = false;
 }
Пример #48
0
 void Awake()
 {
     m_arcadeVehicle = gameObject.GetComponentInParent<ArcadeVehicle>();
     m_carstate = gameObject.GetComponentInParent<CarState>();
     m_transform = gameObject.GetComponentInParent<Transform>();
 }
Пример #49
0
 public void NowOnPavement()
 {
     carState = CarState.onPavement;
 }
Пример #50
0
 public void setCurrentState(CarState state)
 {
     CurrentState = state;
     Debug.WriteLine("state = " + state);
 }
Пример #51
0
    private void Sort(CarState[] cars, int left, int right)
    {
        if (left < right)
        {
            try
            {
                CarState middleCar = cars[(left + right) / 2];
                int i = left - 1;
                int j = right + 1;

                while (true)
                {
                    while (CalculateRank(cars[++i], middleCar)) ;

                    while (CalculateRank(middleCar, cars[--j])) ;

                    if (i >= j)
                        break;

                    Swap(cars, i, j);
                }

                Sort(cars, left, i - 1);
                Sort(cars, j + 1, right);
            }
            catch
            {
                SetRanksCar();
            }
        }
    }
Пример #52
0
        public void Initialize()
        {
            CurrentState = CarState.NotInWorld;
            PreviousState = CarState.NotInWorld;

            CurrentJackState = JackState.NotJacking;
            PreviousJackState = JackState.NotJacking;

            InTransition = false;
            BetweenCones = false;
            PreviousBetweenCones = false;
            Fueling = false;
            Repairing = false;
            FuelLevel = 0;
            PreviousFuelLevel = 0;
            LiftTimer = DateTime.Now;
            DropTimer = DateTime.Now;
            DropTime = DateTime.Now;
            FuelTimer = DateTime.Now;
            LiftCounter = 0;
        }
Пример #53
0
        // this method will compare the previous and current states and figure out what's going on in transition
        public CarState updateState(TrackSurfaces ts_state, bool between_cones)
        {
            // kick the states along a tick
            PreviousState = CurrentState;
            PreviousBetweenCones = BetweenCones;
            BetweenCones = between_cones;

            InTransition = false;
            switch (ts_state)
            {
                case TrackSurfaces.NotInWorld:
                {
                    // the state we care about is if previous was not, NotInWorld that means we just got kicked out of the world
                    if (PreviousState == CarState.NotInWorld)
                    {
                        // already out, yawn
                    }
                    else if (PreviousState == CarState.ExitingWorld)
                    {
                        // just left the world, now flip to out
                        setCurrentState(CarState.NotInWorld);
                    }
                    else
                    {
                        // in transition, leaving the world
                        InTransition = true;
                        setCurrentState(CarState.ExitingWorld);
                    }
                }
                break;

                case TrackSurfaces.OffTrack:
                {
                    if ((PreviousState != CarState.OnTrack)&&(PreviousState != CarState.NotInWorld))
                        setCurrentState(CarState.OnTrack);
                }
                break;

                case TrackSurfaces.InPitStall:
                {
                    BetweenCones = true;

                    // transitions are dropping in the world and coming into the pits after approaching
                    if (PreviousState == CarState.NotInWorld)
                    {
                        // just dropped in
                        setCurrentState(CarState.EnteringWorld);
                        InTransition = true;
                    }
                    else if (PreviousState == CarState.EnteringWorld)
                    {
                        // just dropped in and now sitting in pits
                        setCurrentState(CarState.InStall);
                    }
                    else if (PreviousState == CarState.EnteringStall)
                    {
                        // now stopping in pit stall
                        setCurrentState(CarState.InStall);
                        InTransition = true;
                    }
                    else if (PreviousState == CarState.EnteringPits)
                    {
                        // driving up to the stall
                        setCurrentState(CarState.EnteringStall);
                        InTransition = true;
                    }
                    else
                    {
                        // best guess default
                        if (PreviousState != CarState.InStall)
                            setCurrentState(CarState.InStall);
                    }

                    // drop through to special handling for changing tires

                }
                break;

                // complication here is we need to watch out for crossing the cone boundaries and capture that
                case TrackSurfaces.AproachingPits:
                {
                    // this state is both entering and exiting the pit lane
                    if (PreviousState == CarState.InStall)
                    {
                        // just exited the stall
                        setCurrentState(CarState.ExitingStall);
                        InTransition = true;
                    }
                    else if (PreviousState == CarState.ExitingStall)
                    {
                        // driving out the stall
                        setCurrentState(CarState.ExitingPits);
                        InTransition = true;
                    }
                    else if (PreviousState == CarState.OnTrack)
                    {
                        // entering the pits
                        setCurrentState(CarState.EnteringPits);
                        InTransition = true;
                    }
                    else if (PreviousState == CarState.EnteringPits)
                    {
                    }
                    else if (PreviousState == CarState.ExitingPits)
                    {
                    }
                    else if (PreviousState == CarState.PassingEntryCones)
                    {
                    }
                    else if (PreviousState == CarState.PassingExitCones)
                    {
                    }
                    else if (PreviousState == CarState.NotInWorld)
                    {
                        // entering the pits
                        setCurrentState(CarState.EnteringWorld);
                        InTransition = true;
                    }
                    else
                    {
                        // best guess default
                        if (PreviousState != CarState.ExitingPits)
                            setCurrentState(CarState.ExitingPits);
                    }

                    // the cones override the standard states this is a bit ugly but meh
                    // hitting the cones on entry
                    if ((PreviousBetweenCones == false) && (between_cones == true) && (PreviousState != CarState.NotInWorld))   // might be qualy dropping right in
                    {
                        setCurrentState(CarState.PassingEntryCones);
                        InTransition = true;
                        BetweenCones = true;
                    }

                    // passing the cones on exit
                    else if ((PreviousBetweenCones == true) && (between_cones == false))
                    {
                        setCurrentState(CarState.PassingExitCones);
                        InTransition = true;
                        BetweenCones = false;
                    }

                }
                break;

                case TrackSurfaces.OnTrack:
                {
                    if (PreviousState == CarState.ExitingPits)
                    {
                        // just exited the pits
                        setCurrentState(CarState.EnteringTrack);
                        InTransition = true;
                    }
                    else if (PreviousState == CarState.EnteringTrack)
                    {
                        // just exited the pits
                        setCurrentState(CarState.OnTrack);
                        InTransition = true;
                    }
                    else if (PreviousState == CarState.PassingExitCones)
                    {
                        // just exited the pits
                        setCurrentState(CarState.OnTrack);
                        InTransition = true;
                    }
                    else if (PreviousState == CarState.NotInWorld)
                    {
                        // entering the pits
                        setCurrentState(CarState.EnteringWorld);
                        InTransition = true;
                    }
                    else
                    {
                        // best guess default
                        if (PreviousState != CarState.OnTrack)
                        setCurrentState(CarState.OnTrack);
                    }

                }
                break;

            }

            return CurrentState;
        }