Exemple #1
0
    override public PathSpline GetPath()
    {
        GameObject last_obj = Global.Instance.last_inspected_track.gameObject;

        //print("TwoJoin: last_track name: "+last_obj.name);

        AbstractTrack last_track = last_obj.GetComponent <AbstractTrack>();

        if (last_track == null)
        {
            return(rightpath);
        }


        Vector3 twojoin_startpoint = GetStartPoint();


        if (twojoin_startpoint.x - transform.position.x < -1f)
        {
            return(leftpath);
        }
        else if (twojoin_startpoint.x - transform.position.x > 1f)
        {
            return(rightpath);
        }
        else
        {
            if (last_track.usable_junction())
            {
                if (last_track.GetOffset() < 0)
                {
                    return(leftpath);
                }
                else
                {
                    return(rightpath);
                }
            }
        }
        return(rightpath);
    }
Exemple #2
0
    /*
     * public AbstractTrack GetNextTrack(Vector3 pos){
     *  GameObject track = gameObject;
     *  float dist2 = Mathf.Infinity;
     *  foreach (GameObject track_object in track_array)
     *  {
     *      float this_dist = (track_object.transform.position - pos).magnitude;
     *      if(this_dist < dist2){
     *          dist2 = this_dist;
     *          track = track_object;
     *      }
     *  }
     *
     *  int offset =  track.GetComponent<AbstractTrack>().GetOffset();
     *  Vector3 ref_pos = track.transform.position + new Vector3(offset*3,0,4);
     *  GameObject closest = track;
     *  float dist = Mathf.Infinity;
     *  foreach (GameObject track_object in track_array)
     *  {
     *      float this_dist = (track_object.transform.position - ref_pos).magnitude;
     *      if(this_dist < dist){
     *          dist = this_dist;
     *          closest = track_object;
     *      }
     *  }
     *
     *  return closest.GetComponent<AbstractTrack>();
     * }
     *
     * public AbstractTrack GetTrackAt(Vector3 pos){
     *  GameObject track = gameObject;
     *  float dist2 = Mathf.Infinity;
     *  foreach (GameObject track_object in track_array)
     *  {
     *      float z_dist = -(track_object.GetComponent<AbstractTrack>().GetStartPoint().z - pos.z);
     *      float this_dist = (track_object.GetComponent<AbstractTrack>().GetStartPoint() - pos).magnitude;
     *      if(z_dist<0){
     *          continue;
     *      }
     *      if(this_dist < dist2){
     *          dist2 = this_dist;
     *          track = track_object;
     *      }
     *  }
     *  return track.GetComponent<AbstractTrack>();
     * }
     *
     */

    public void RequestPath(GameHandler gamehandler)
    {
        //print("controller requested path");

        AbstractTrack picked_track = Global.Instance.last_inspected_track.GetNextTrack();

        //print("name of last inspected track: "+Global.Instance.last_inspected_track.name);

        //print("name of the picked_track: "+ picked_track.name);


        /*
         * if(Global.Instance.last_inspected_track != null){
         *  if(!picked_track.Equals(Global.Instance.last_inspected_track)){
         *      controller.AddPath(picked_track);
         *  }
         * } */
        if (picked_track == null)
        {
            Debug.LogError("RequestPath: picked_track is null");
        }

        if (picked_track.gameObject.CompareTag("Junction"))
        {
            picked_track.lock_track();
            //                                                  CHECK THIS
            gamehandler.AddPath(picked_track);
            picked_track = picked_track.GetNextTrack();
        }



        //picked_track.lock_track();
        //Global.Instance.last_inspected_track = picked_track;

        int count = 0;

        //picked_track = GetNextTrack(picked_track.gameObject);
        while (true)
        {
            if ((picked_track.gameObject.CompareTag("Junction") && picked_track.usable_junction()))
            {
                Global.Instance.junction_queue.Enqueue(picked_track);
                Global.Instance.ActivateNextJunction();
                //print("queued next junction: "+ picked_track.name);
                break;
            }
            count++;

            //                                                     CHECK THIS
            gamehandler.AddPath(picked_track);
            picked_track.lock_track();

            //Global.Instance.last_inspected_track = picked_track;
            //print("adding track: "+ picked_track.name + "; next track: "+picked_track.GetNextTrack());
            picked_track = picked_track.GetNextTrack();
            if (picked_track.Equals(Global.Instance.last_inspected_track))
            {
                //print("found end");
                break;
            }
            if (picked_track == null)
            {
                Debug.LogWarning("picked track is null");
                break;
            }
            if (count > 100)
            {
                Debug.LogError("COUNT TOO HIGH. INFO: " + picked_track.gameObject.name);
                return;
            }
        }
    }