public Drone(int droneId, Vector3 initPos) { this.droneId = droneId; this.isPaused = false; this.safetyStatus = SafetyStatus.NOT_SAFE; this.parkingPos = this.curPos = initPos; this.hoverPos = this.parkingPos + hoverShift; this.status = DroneStatus.PARKED; this.isWarning = false; this.isCollided = false; // create game object // Debug.Log("Created new drone with id: " + droneId); GameObject baseObject = TrafficControl.worldobject.GetComponent <TrafficControl>().droneBaseObject; gameObjectPointer = Object.Instantiate(baseObject, initPos, Quaternion.identity); gameObjectPointer.GetComponent <DroneProperties>().classPointer = this; gameObjectPointer.name = string.Concat("Drone", droneId.ToString()); gameObjectPointer.layer = 2; // gameObjectPointer.gameObject.tag = string.Concat("Drone", droneId.ToString()); gameObjectPointer.transform.parent = TrafficControl.worldobject.transform; GameObject arrow1 = gameObjectPointer.GetComponent <DroneProperties>().Arrows; arrows1 = Object.Instantiate(arrow1, initPos, Quaternion.Euler(0f, -90f, 0f)); arrows1.transform.parent = TrafficControl.worldobject.transform; GameObject arrow2 = gameObjectPointer.GetComponent <DroneProperties>().Arrows; arrows2 = Object.Instantiate(arrow2, initPos, Quaternion.Euler(0f, -270f, 0f)); arrows2.transform.parent = TrafficControl.worldobject.transform; arrows1.SetActive(false); arrows2.SetActive(false); ring_2 = gameObjectPointer.transform.Find("warningSphere").gameObject; }
/// <summary> /// Update the status of drone and Move /// </summary> /// <returns> /// drone paused: 0; /// end of to_shelf trip: 1; /// end of whole trip: 2; /// otherwise: -1 /// </returns> public MoveStatus Move() { MoveStatus flag = MoveStatus.OTHER; if (isPaused) { // if (pauseCounter-- == 0) // { // isPaused = false; // } return(flag); } // curPos = status == 0 ? gameObjectPointer.transform.position : gameObjectPointer.transform.position + direction * SPEED; // direction = Utility.shelves[eventId] - curPos; // direction = GameObject.Find("Event" + eventId.ToString()).transform.position - curPos; curPos = status == DroneStatus.PARKED ? curPos : curPos + direction * SPEED; // Debug.Log("Move drone " + droneId + " with dir: " + direction + " to pos: " + curPos); // New Code if (safetyStatus == SafetyStatus.TO_SAFE_ZONE) { if (curPos.y >= 30.0f) { safetyStatus = SafetyStatus.SAFE; safetyFlightStartTime = Time.time; } else { //Directionally Upward: curPos = curPos + new Vector3(0, SPEED * safetySpeedMultiplier, 0); // Straight Upward: //Vector3 orgPos = curPos - direction * SPEED; //curPos = orgPos + new Vector3(0, SPEED*safetySpeedMultiplier, 0); } } else if (safetyStatus == SafetyStatus.SAFE) { //Debug.Log("Safe zone"); if (Time.time - safetyFlightStartTime > safetyTime) { safetyStatus = SafetyStatus.TO_NONSAFE_ZONE; safetyFlightStartTime = 0; } else { Vector3 orgPos = curPos - direction * SPEED; curPos = orgPos + new Vector3(direction.x * SPEED, 0, direction.z * SPEED); } } else if (safetyStatus == SafetyStatus.TO_NONSAFE_ZONE) { //Debug.Log("Non-safe zone"); if (curPos.y < 30.0f) { safetyStatus = SafetyStatus.NOT_SAFE; } } // End of New code flag = MoveStatus.OTHER; if (status != DroneStatus.PARKED && Utility.IsLessThan(curPos - dstPos, epsilon)) { // Debug.Log(status + " " + curPos + " " + dstPos + " " + hoverPos + " " + parkingPos + " " + eventPos); if (Utility.IsLessThan(dstPos - hoverPos, epsilon)) { if (status == DroneStatus.TAKEOFF) // end of takeoff { Utility.DeleteChild(this.gameObjectPointer, "Line"); status = DroneStatus.TO_SHELF; dstPos = eventPos; // Debug.Log(droneId + "end of takeoff, now to event: " + eventPos + "cur: " + curPos); } } else if (Utility.IsLessThan(dstPos - eventPos, epsilon)) // Drone Reached the event { // cur_s = 2 --> 3 // end of to_shelf trip status = DroneStatus.PARKED; curPos = parkingPos; flag = MoveStatus.END_TO_SHELF; } } gameObjectPointer.transform.position = curPos; // gameObjectPointer.transform.rotation = Quaternion.identity; // gameObjectPointer.transform.rotation = TrafficControl.worldobject.transform.rotation; if (EnableArrows) { DisplayArrow(); } return(flag); }
// new code start public void RaiseDrone() { safetyStatus = SafetyStatus.TO_SAFE_ZONE; //Debug.Log("Raising Drone"); }
public void LowerDrone() { safetyStatus = SafetyStatus.TO_NONSAFE_ZONE; //Debug.Log("Lowering Drone"); }
public static float GetCellStatus(GoBoard lGoBoard, GoCell lCell, GnuGoStatus objGnugoStatus) { float toReturn = 0.5F; SafetyStatus lSafetyStatus = lGoBoard.GetSafetyStatus(lCell.Index); if (!lSafetyStatus.IsUndecided) { if (lSafetyStatus.IsBlack) { toReturn = 1; } else if (lSafetyStatus.IsWhite) { toReturn = 0; } if (lSafetyStatus.IsDead) { toReturn = 1 - toReturn; } } else { if (lCell.Color == Color.Black) { //if (lGoBoard.GetBlockLibertyCount(lCell.Index) > 1) if (objGnugoStatus.CellsByStatus[SafetyFlag.Dead].Contains(lCell.Index)) { toReturn = 0; } else { toReturn = 1; } } else if (lCell.Color == Color.White) { //if (lGoBoard.GetBlockLibertyCount(lCell.Index) > 1) if (objGnugoStatus.CellsByStatus[SafetyFlag.Dead].Contains(lCell.Index)) { toReturn = 1; } else { toReturn = 0; } } else { if (objGnugoStatus.CellsByStatus[GnuGoStatus.BlackTerritory].Contains(lCell.Index)) { toReturn = 1; } else if (objGnugoStatus.CellsByStatus[GnuGoStatus.WhiteTerritory].Contains(lCell.Index)) { toReturn = 0; } else { foreach (int cellIdx in ((GoEmptyBlock)(lCell.Block)).MemberList) { if (objGnugoStatus.CellsByStatus[GnuGoStatus.BlackTerritory].Contains(cellIdx)) { toReturn = 1; break; } else if (objGnugoStatus.CellsByStatus[GnuGoStatus.WhiteTerritory].Contains(cellIdx)) { toReturn = 0; break; } } } } } return(toReturn); }