예제 #1
0
 public void Assign(ref double[] arr, ref int i)
 {
     arr[i++] = Passable.ToInt();
     arr[i++] = InDanger.ToInt();
     arr[i++] = UnderFire.ToInt();
     arr[i++] = GoesToFlag.ToInt();
 }
예제 #2
0
    private bool lineOfSight(Vector3 curPos, Vector3 otherPos)
    {
        //determine if there are no obstacles between curPoint and otherPoint
        curPos   = new Vector3(curPos.x, curPos.y, 0f);
        otherPos = new Vector3(otherPos.x, otherPos.y, 0f);
        Vector3 difference = otherPos - curPos;
        float   distance   = difference.magnitude;
        Vector3 direction  = difference.normalized;

        RaycastHit[] hits;
        hits = Physics.RaycastAll(curPos, direction, distance);
        foreach (RaycastHit hit in hits)
        {
            if (hit.collider != null)
            {
                Waypoint wp = hit.transform.gameObject.GetComponent <Waypoint>();
                if (wp != null)
                {
                    continue;
                }


                Passable passScript = hit.transform.gameObject.GetComponent <Passable> ();
                if (passScript == null)
                {
                    //Debug.Log ("does not have component");
                    return(false);
                }
            }
        }
        //Debug.Log ("raycast passed");
        return(true);
    }
예제 #3
0
 public override int GetHashCode()
 {
     unchecked
     {
         int result = TileNumber;
         result = (result * 397) ^ Passable.GetHashCode();
         result = (result * 397) ^ ObjectNumber;
         return(result);
     }
 }
예제 #4
0
 public int GetGamestateHash()
 {
     unchecked // Overflow is fine, just wrap
     {
         int hash = (int)2166136261;
         // Suitable nullity checks etc, of course :)
         hash = (hash * 16777619) ^ Name.GetHashCode();
         hash = (hash * 16777619) ^ Passable.GetHashCode();
         hash = (hash * 16777619) ^ MoveCost.GetHashCode();
         foreach (var prop in Properties)
         {
             hash = (hash * 16777619) ^ prop.GetHashCode();
         }
         return(hash);
     }
 }
예제 #5
0
        /// <summary>
        /// Gets the hash code
        /// </summary>
        /// <returns>Hash code</returns>
        public override int GetHashCode()
        {
            unchecked             // Overflow is fine, just wrap
            {
                var hashCode = 41;
                // Suitable nullity checks etc, of course :)

                hashCode = hashCode * 59 + Subject.GetHashCode();

                hashCode = hashCode * 59 + EndTime.GetHashCode();

                hashCode = hashCode * 59 + Duration.GetHashCode();

                hashCode = hashCode * 59 + Passable.GetHashCode();
                if (RobotsActive != null)
                {
                    hashCode = hashCode * 59 + RobotsActive.GetHashCode();
                }
                return(hashCode);
            }
        }
예제 #6
0
        /// <summary>
        /// Returns true if TimerStartEvent instances are equal
        /// </summary>
        /// <param name="other">Instance of TimerStartEvent to be compared</param>
        /// <returns>Boolean</returns>
        public bool Equals(TimerStartEvent other)
        {
            if (other is null)
            {
                return(false);
            }
            if (ReferenceEquals(this, other))
            {
                return(true);
            }

            return
                ((
                     Subject == other.Subject ||

                     Subject.Equals(other.Subject)
                     ) &&
                 (
                     EndTime == other.EndTime ||

                     EndTime.Equals(other.EndTime)
                 ) &&
                 (
                     Duration == other.Duration ||

                     Duration.Equals(other.Duration)
                 ) &&
                 (
                     Passable == other.Passable ||

                     Passable.Equals(other.Passable)
                 ) &&
                 (
                     RobotsActive == other.RobotsActive ||
                     RobotsActive != null &&
                     other.RobotsActive != null &&
                     RobotsActive.SequenceEqual(other.RobotsActive)
                 ));
        }
예제 #7
0
    private IEnumerator WaypointCoroutine()
    {
        float t = 0.0f;

        foreach (AStarSearch.AStarTile tile in AStarSearch.ms_instance.m_worldRepresentation)
        {
            t += .1f;
            if (t > 100.0f)
            {
                t = 0.0f;
                yield return(new WaitForEndOfFrame());
            }

            if (tile == null)
            {
                Debug.Log("Tile is weird");
                continue;
            }

            Passable pass = tile.GetTiles() as Passable;
            if (pass == null)
            {
                continue;
            }

            Waypoint curPoint = (GameObject.Instantiate(waypoint, new Vector3(tile.GetTiles().transform.position.x, tile.GetTiles().transform.position.y, mapOffset), transform.rotation, this.transform) as GameObject).GetComponent <Waypoint>();
            waypoints.Add(curPoint);
            curPoint.GetComponent <Waypoint>().Initialize();
        }

        yield return(new WaitForEndOfFrame());

        //t = 0.0f;
        int i = 5;

        while (i > 0)
        {
            foreach (Waypoint wp in waypoints)
            {
                /*t += .1f;
                 * if(t > 100.0f)
                 * {
                 *      t = 0.0f;
                 *      yield return new WaitForEndOfFrame();
                 * }*/

                if (removedWP.Contains(wp))
                {
                    continue;
                }
                //1. expand box to collide with neighbors
                Debug.Log("Grow Waypoint: " + wp.transform.position);
                yield return(new WaitForEndOfFrame());

                //1. raycast in four directions
                RaycastHit leftHit;
                Debug.DrawRay(wp.transform.position, new Vector3(-1 * wp.getWidth() * tileSize, 0, 0), Color.black, 1.0f);
                if (Physics.Raycast(wp.transform.position, new Vector3(-1, 0, 0), out leftHit, wp.getWidth() * tileSize))
                {
                    Debug.Log("hit left");
                    if (leftHit.transform.position.y == transform.position.y)
                    {
                        Waypoint otherWP = leftHit.transform.gameObject.GetComponent <Waypoint> ();
                        if (!removedWP.Contains(otherWP) && otherWP.getHeight() == wp.getHeight())
                        {
                            Debug.Log("left match");
                            Merge(wp, otherWP, true);
                        }
                    }
                }
                RaycastHit rightHit;
                Debug.DrawRay(wp.transform.position, new Vector3(1 * wp.getWidth() * tileSize, 0, 0), Color.black, 1.0f);
                if (Physics.Raycast(wp.transform.position, new Vector3(1, 0, 0), out rightHit, wp.getWidth() * tileSize))
                {
                    Debug.Log("hit right");
                    if (rightHit.transform.position.y == transform.position.y)
                    {
                        Debug.Log("horizontal match");
                        Waypoint otherWP = rightHit.transform.gameObject.GetComponent <Waypoint> ();
                        if (!removedWP.Contains(otherWP) && otherWP.getHeight() == wp.getHeight())
                        {
                            Debug.Log("right match");
                            Merge(wp, otherWP, true);
                        }
                    }
                }
                RaycastHit topHit;
                Debug.DrawRay(wp.transform.position, new Vector3(0, 1 * wp.getWidth() * tileSize, 0), Color.black, 1.0f);
                if (Physics.Raycast(wp.transform.position, new Vector3(0, 1, 0), out topHit, wp.getHeight() * tileSize))
                {
                    Debug.Log("hit top");
                    if (topHit.transform.position.x == transform.position.x)
                    {
                        Waypoint otherWP = topHit.transform.gameObject.GetComponent <Waypoint> ();
                        if (!removedWP.Contains(otherWP) && otherWP.getWidth() == wp.getWidth())
                        {
                            Debug.Log("top match");
                            Merge(wp, otherWP, false);
                        }
                    }
                }
                RaycastHit bottomHit;
                Debug.DrawRay(wp.transform.position, new Vector3(0, -1 * wp.getWidth() * tileSize, 0), Color.black, 1.0f);
                if (Physics.Raycast(wp.transform.position, new Vector3(0, -1, 0), out bottomHit, wp.getHeight() * tileSize))
                {
                    Debug.Log("hit bottom");
                    if (bottomHit.transform.position.x == transform.position.x)
                    {
                        Waypoint otherWP = bottomHit.transform.gameObject.GetComponent <Waypoint> ();
                        if (!removedWP.Contains(otherWP) && otherWP.getWidth() == wp.getWidth())
                        {
                            Debug.Log("bottom match");
                            Merge(wp, otherWP, false);
                        }
                    }
                }
            }
            for (int j = 0; i < removedWP.Count; i++)
            {
                Waypoint wp = removedWP [j];
                waypoints.Remove(wp);
                removedWP.Remove(wp);
                Destroy(wp);
            }
            i--;
        }

        /*t = 0.0f;
         * for (int i = 0; i < waypoints.Count; i++)
         * {
         *  for (int j = i + 1; j < waypoints.Count; j++)
         *  {
         *
         *      t += .1f;
         *      if (t > 100.0f)
         *      {
         *          t = 0.0f;
         *          yield return new WaitForEndOfFrame();
         *      }
         *
         *      Waypoint curPoint = waypoints[i];
         *      Waypoint otherPoint = waypoints[j];
         *      Vector3 curPos = curPoint.getPos();
         *      Vector3 otherPos = otherPoint.getPos();
         *      if (lineOfSight(curPos, otherPos))
         *      {
         *          yield return new WaitForEndOfFrame();
         *          curPoint.addNeighbor(otherPoint);
         *          otherPoint.addNeighbor(curPoint);
         *
         *          if (curPoint.HasSameNeighbors(otherPoint))
         *          {
         *              Destroy(otherPoint);
         *              continue;
         *          }
         *          curPoint.addLine(otherPos);
         *      }
         *  }
         * }*/
        uic.activateButtons();
    }