void GameManagerInterface.PerformHop(PathScript path) { GameObject hopTarget = null; //to=active --> goto from if (path.to.gameObject == activeRouter.gameObject) { hopTarget = path.from.gameObject; } else //from=active --> goto to if (path.from.gameObject == activeRouter.gameObject) { hopTarget = path.to.gameObject; } // Update the active router. activeRouter = hopTarget; currentPath.Add(hopTarget.GetComponent <RouterScript>()); if (isLogEnabled) { Debug.Log("Acitve router is now: " + activeRouter); } }
GameStatus GameManagerInterface.IsValidHop(PathScript path) { //neither is active --> hop is impossible. if (path.from.gameObject != activeRouter.gameObject && path.to.gameObject != activeRouter.gameObject) { gameStatus = GameStatus.ForbiddenHop; return(gameStatus); } GameObject hopTarget = null; //to=active --> goto from if (path.to.gameObject == activeRouter.gameObject) { hopTarget = path.from.gameObject; } else //from=active --> goto to if (path.from.gameObject == activeRouter.gameObject) { hopTarget = path.to.gameObject; } // Check win condition. if (hopTarget.gameObject == currentRun.destination) { gameStatus = GameStatus.RunFinished; return(gameStatus); } gameStatus = GameStatus.ValidHop; return(GameStatus.ValidHop); }
void updateSelectionIsAvailable() { if (this._selectedPosition.isEqualTo(this._homePosition) || this._selectedPosition.isEqualTo(this._doorPosition)) { this.setSelectionIsAvailable(false); } else { DefenseScript d; if (CreateDefensesScript.sharedInstance().anyDefenseAtPosition(this._selectedPosition, out d)) { this.setSelectionIsAvailable(false); } else { ArrayList pathPositions; if (PathScript.sharedInstance().existsPathFromPosToPosIfBlockingPosition(this.getDoorPosition(), this.getHomePosition(), this._selectedPosition, out pathPositions)) { this.setSelectionIsAvailable(true); } else { this.setSelectionIsAvailable(false); } } } }
void GameManagerInterface.PerformWrongHop(PathScript path) { if (isLogEnabled) { Debug.Log("Started error recovery mode."); } // Start the error recovery. errorRecovery = true; // Store the last valid router to that the player needs to return. // Last valid position is the router on which the player is located before the wrong hop. lastValidRouter = activeRouter.GetComponent <RouterScript>(); GameObject hopTarget = null; //to=active --> goto from if (path.to.gameObject == activeRouter.gameObject) { hopTarget = path.from.gameObject; } else //from=active --> goto to if (path.from.gameObject == activeRouter.gameObject) { hopTarget = path.to.gameObject; } activeRouter = hopTarget; }
public override void OnPathClicked(PathScript path) { clickedPath = path; Debug.Log("DijkstraStatus: " + dijkstraManager.GetCurrentMove().Status); switch (dijkstraManager.GetCurrentMove().Status) { case DijkstraStatus.HOP_UNREACHABLE: // Remember last sequence and state. lastSequence = professorController.GetCurrentSequenceId(); lastState = professorController.GetCurrentStateId(); // Show professor with HOP_UNREACHABLE message. professorController.SetSequenceAndState(-1, 0); professorController.ShowAngry(true); break; case DijkstraStatus.WRONG_HOP: prevRouterName = clickedPath.from.GetComponent <RouterScript>().routerName; break; case DijkstraStatus.UNDISCOVERED_PATHS: prevRouterName = clickedPath.from.GetComponent <RouterScript>().routerName; break; } }
void GameManagerInterface.Start(GameTuple startAndEndPoint) { recreateGraphRepresentation(); base.InitializeRun(startAndEndPoint); RouterScript currentRouter = activeRouter.GetComponent <RouterScript>(); currentRouter.SetPriority(0); neighboursOfActiveRouter = ExpandNode(currentRouter); prioQueue = new PriorityQueue <RouterScript>(); for (int i = 0; i < neighboursOfActiveRouter.Count; i++) { PathScript pathToNeighbor = graphRepresentation2[currentRouter.GetRouterIndex(), neighboursOfActiveRouter[i].GetRouterIndex()]; neighboursOfActiveRouter[i].SetPriority(pathToNeighbor.GetPathCosts()); prioQueue.Enqueue(neighboursOfActiveRouter[i]); if (isLogEnabled) { Debug.Log(string.Format("Added router {0} to prio queue with path costs {1}.", neighboursOfActiveRouter[i], pathToNeighbor.GetPathCosts())); } } }
/// <summary> /// Performs a hop within error recovery mode. It is checked whether this hop /// brings the player back to the last valid router. If the player returns to the /// last valid router, the error recovery mode will be disabled. Otherwise, /// the player remains in error recovery mode. /// </summary> /// <param name="path">The path along which the player performs the hop.</param> /// <returns>The current status of the error recovery.</returns> public ErrorRecoveryStatus PerformErrorRecoveryHop(PathScript path) { RouterScript from = path.from.GetComponent <RouterScript>(); RouterScript to = path.to.GetComponent <RouterScript>(); // Check if player returns to the last valid hop. if (lastValidRouter == to || (bidirectional && lastValidRouter == from)) { lastValidRouter = null; // Error recovery finished. errorRecovery = false; if (isLogEnabled) { Debug.Log("Left error recovery mode."); } } // Update the current player position according to the performed hop. UpdateCurrentPlayerPosition(path); // Check if still in error recovery mode. if (errorRecovery) { return(ErrorRecoveryStatus.ERROR_NOT_RECOVERED); } return(ErrorRecoveryStatus.ERROR_RECOVERED); }
bool GameManagerInterface.PerformErrorRecoveryHop(PathScript path) { GameObject hopTarget = null; //to=active --> goto from if (path.to.gameObject == activeRouter.gameObject) { hopTarget = path.from.gameObject; } else //from=active --> goto to if (path.from.gameObject == activeRouter.gameObject) { hopTarget = path.to.gameObject; } if (hopTarget.gameObject == lastValidRouter.gameObject) { errorRecovery = false; activeRouter = hopTarget; return(true); } activeRouter = hopTarget; return(false); }
public static void DrawGizmo(PathScript scr, GizmoType gizmoType) { Vector3[] nodes = scr.GetPath(); if (nodes.Length > 1) iTween.DrawPathGizmos(nodes); for (int i = 0; i < nodes.Length; i++) { if (scr.loops && i == nodes.Length - 1 && nodes.Length > 1) break; if (nodes.Length > 1 && scr.loops) Gizmos.color = Color.Lerp(Color.red, Color.blue, (float)i / (nodes.Length - 2)); else if (nodes.Length > 1) Gizmos.color = Color.Lerp(Color.red, Color.blue, (float)i / (nodes.Length - 1)); else Gizmos.color = Color.red; if ((gizmoType & GizmoType.NonSelected) > 0) Gizmos.DrawWireSphere(nodes[i], 0.25f); else Gizmos.DrawSphere(nodes[i], 0.5f); Vector3 screenPoint = Camera.current.WorldToScreenPoint(nodes[i]); GUI.TextField(new Rect(screenPoint.x, screenPoint.y, 20, 20), i.ToString()); } }
public void blockPathPosition(Position pos) { bool positionIsInPath = false; int i = this._pathPositionIndex; while (!positionIsInPath && i < this._pathPositions.Count) { Position p = (Position)this._pathPositions[i]; positionIsInPath = (pos.isEqualTo(p)); i++; } if (positionIsInPath) { Position startPos = (Position)this._pathPositions[this._pathPositionIndex - 1]; Position endPos = MapScript.sharedInstance().getHomePosition(); ArrayList positions; if (PathScript.sharedInstance().existsPathFromPosToPos(startPos, endPos, out positions)) { PathScript.sharedInstance().addSegmentsFromPositions(positions); PathScript.sharedInstance().removeSegmentsFromPositions(this._pathPositions); this._pathPositions = positions; this._pathPositionIndex = 0; this.getNextPosition(); } } }
public void PerformHop(PathScript path) { GameObject hopTarget = null; //to=active --> goto from if (path.to.gameObject == activeRouter.gameObject) { hopTarget = path.from.gameObject; } else //from=active --> goto to if (path.from.gameObject == activeRouter.gameObject) { hopTarget = path.to.gameObject; } // Update the active router and the neighbours of the active router. activeRouter = hopTarget; neighboursOfActiveRouter = ExpandNode(activeRouter.GetComponent <RouterScript>()); currentPath.Add(hopTarget.GetComponent <RouterScript>()); if (isLogEnabled) { Debug.Log("Acitve router is now: " + activeRouter); } }
void OnDestroy() { if ((this._pathPositions != null) && (PathScript.sharedInstance() != null)) { PathScript.sharedInstance().removeSegmentsFromPositions(this._pathPositions); } }
public override void OnInspectorGUI() { PathScript pathScript = (PathScript)target as PathScript; EditorGUILayout.Separator(); EditorGUILayout.Separator(); EditorGUILayout.Separator(); Rect startButton = EditorGUILayout.BeginHorizontal(); startButton.x = startButton.width / 2 - 100; startButton.width = 200; startButton.height = 18; if (GUI.Button(startButton, "New Path")) { pathScript.NewPath(); GUIUtility.ExitGUI(); } EditorGUILayout.Separator(); EditorGUILayout.Separator(); EditorGUILayout.Separator(); EditorGUILayout.EndHorizontal(); EditorGUILayout.Separator(); EditorGUILayout.Separator(); EditorGUILayout.Separator(); if (GUI.changed) { EditorUtility.SetDirty(pathScript); } }
void Start() { agent = this.GetComponent <NavMeshAgent>(); agent.autoBraking = false; allowFire = true; pathScript = this.GetComponent <PathScript>(); }
/// <summary> /// Performs the path discovery move along the specified path, i.e. the player moves /// towards the destination router and spwans puddles on the way. After the player has reached /// the target position, the player moves back along the path to the origin router. /// </summary> /// <param name="path">The path on which the path discovery should be performed.</param> private void performPathDiscoveryMove(PathScript path) { SpriteRenderer sr = player.GetComponentInChildren <SpriteRenderer>(); Color blue; ColorUtility.TryParseHtmlString("#1DB7FFFF", out blue); sr.color = blue; if (isLogEnabled) { Debug.Log("DijkstraMovementManager: Perform path discovery on path " + path.name); } movementScript.ControlPuddleSpawning(true); performsPathDiscovery = true; if (path.from == dijkstraManager.GetCurrentPlayerPosition()) { originRouter = path.from; movementScript.MovePlayer(path.to); } else { originRouter = path.to; movementScript.MovePlayer(path.from); } }
public override void OnPathClicked(PathScript path) { clickedPath = path; if (debugging) { Debug.Log("LevelController: OnPathClicked - GameStatus: " + movementManager.GetGameStatus().ToString()); } switch (movementManager.GetGameStatus()) { case GameStatus.ForbiddenHop: // Remember last sequence and state. lastSequence = professorController.GetCurrentSequenceId(); lastState = professorController.GetCurrentStateId(); // Show professor with HOP_UNREACHABLE message. professorController.SetSequenceAndState(-1, 0); professorController.ShowAngry(true); break; case GameStatus.InvalidHop: prevRouterName = clickedPath.from.GetComponent <RouterScript>().routerName; break; // Handle other errors in OnStopPlayerWalking() method. } }
public DirectionalPath(PathScript pathScript, Transform start, Transform end, Vector3 shipStart, Vector3 shipEnd) { this.start = start; this.end = end; this.pathScript = pathScript; this.shipStart = shipStart; this.shipEnd = shipEnd; }
void GameManagerInterface.PerformWrongHop(PathScript path) { // Do nothing. if (isLogEnabled) { Debug.Log("In PerformWrongHop method."); } }
GameStatus GameManagerInterface.IsValidHop(PathScript path) { GameObject hopTarget = null; if (isLogEnabled) { Debug.Log("The current player position is: " + activeRouter + ", The path.to is: " + path.to + ", the path.from is: " + path.from); } if (isLogEnabled) { Debug.Log("Active Router: " + activeRouter.GetComponent <RouterScript>().GetRouterName() + " | queue: " + prioQueue.ToString()); } //neither is active --> hop is impossible. if (path.from.gameObject != activeRouter.gameObject && path.to.gameObject != activeRouter.gameObject) { gameStatus = GameStatus.ForbiddenHop; return(gameStatus); } //to=active --> goto from if (path.to.gameObject == activeRouter.gameObject) { hopTarget = path.from.gameObject; } else //from=active --> goto to if (path.from.gameObject == activeRouter.gameObject) { hopTarget = path.to.gameObject; } if (errorRecovery) { gameStatus = GameStatus.ErrorRecoveryHop; return(GameStatus.ErrorRecoveryHop); } //check win condition if (hopTarget.gameObject == currentRun.destination && IsValidUniformCostHop(hopTarget.GetComponent <RouterScript>())) { gameStatus = GameStatus.RunFinished; return(gameStatus); } if (IsValidUniformCostHop(hopTarget.GetComponent <RouterScript>())) { // Valid hop. gameStatus = GameStatus.ValidHop; return(GameStatus.ValidHop); } gameStatus = GameStatus.InvalidHop; return(gameStatus); }
bool GameManagerInterface.PerformErrorRecoveryHop(PathScript path) { // Do nothing. if (isLogEnabled) { Debug.Log("In PerformErrorRecoveryHop method."); } return(true); }
/// <summary> /// Performs the path discovery on the specified path. The path costs of this path /// are determined and it is checked whether the target router can be reached with /// less path costs using this path. If the target router can be reached with less /// path costs via this path, the distance (priority) of the router is adjusted and /// the previous router on this path stored in the predecessorRouter data structure. /// Finally, the path is set to discovered. /// </summary> /// <param name="path">The path for which the path discovery is performed.</param> public void PerformPathDiscovery(PathScript path) { RouterScript from = path.from.GetComponent <RouterScript>(); RouterScript to = path.to.GetComponent <RouterScript>(); RouterScript previousRouter = null; RouterScript discoveredRouter = null; // Check which router will be discovered. if (from == routerScriptCurrentPlayerPosition) { // Player discovers 'to' router. discoveredRouter = to; previousRouter = routerScriptCurrentPlayerPosition; } else if (bidirectional && to == routerScriptCurrentPlayerPosition) { // Player discovers 'from' router. discoveredRouter = from; previousRouter = routerScriptCurrentPlayerPosition; } // Update the current distance if we have found a shorter path to the discovered router. // This only needs to be done when the discovered router has not already been handled by the dijkstra algorithm. if (priorityQueue.IsContained(discoveredRouter)) { // Path costs to the discovered router are the path cost to the previous router + the path costs of this path. int pathCost = previousRouter.GetPriority() + graphRepresentation2[previousRouter.GetRouterIndex(), discoveredRouter.GetRouterIndex()].GetPathCosts(); // Are the new path costs lower than the currently stored lowest path costs. if (pathCost < discoveredRouter.GetPriority()) { // Update the path costs of the router. priorityQueue.DecreasePriority(discoveredRouter, pathCost); // Set the new predecessor for this router. predecessorRouter[discoveredRouter] = previousRouter; } } // Set path to discovered. graphRepresentation2[previousRouter.GetRouterIndex(), discoveredRouter.GetRouterIndex()].SetDiscovered(true); //graphRepresentation2[previousRouter.GetRouterIndex(), discoveredRouter.GetRouterIndex()].DisplayPathCosts(); // If there is a path back with the same costs, discover this path as well. PathScript backPath = graphRepresentation2[discoveredRouter.GetRouterIndex(), previousRouter.GetRouterIndex()]; if (backPath != null && backPath.GetPathCosts() == path.GetPathCosts()) { backPath.SetDiscovered(true); //backPath.DisplayPathCosts(); } // Test: Output the current priority queue. // Debug.Log(priorityQueue.ToString()); }
/// <summary> /// Moves the player along the specified path. /// The player always moves from the router where he is currently located to the other router to which the path is linked. /// </summary> /// <param name="path">The path on which the player object is moved.</param> private void movePlayerAlongPath(PathScript path) { if (path.from == dijkstraManager.GetCurrentPlayerPosition()) { movementScript.MovePlayer(path.to); } else { movementScript.MovePlayer(path.from); } }
// Use this for initialization void Awake() { foreach (Transform child in transform) { PathScript path = child.GetComponent <PathScript>(); if (path != null) { pathList.Add(path); } } pathsInInspector = pathList.ToArray(); }
void OnDrawGizmosSelected() { Gizmos.color = Color.yellow; if (!path) { path = GetComponent <PathScript>(); } if (path) { Gizmos.DrawLine(path.start.position, path.end.position); } }
void Launch(PathScript path) { ShipScript ship = planetScript.ships [Indices.SHIP_PLAYER]; ship.gameObject.SetActive(true); AbstractPlanet targetPlanet = path.GetDirectionStartingFrom(transform).end.gameObject.GetComponent <AbstractPlanet>(); if (targetPlanet != null) { ship.LaunchShipOnPath(path, transform, targetPlanet); } }
void OnDrawGizmos() { Gizmos.color = Color.white; if (!path) { path = GetComponent <PathScript>(); } if (path) { Gizmos.DrawLine(path.start.position, path.end.position); } }
// Use this for initialization #if UNITY_EDITOR void Start() { if (EditorApplication.isPlaying) { return; } pathScript = GetComponent <PathScript>(); if (pathScript != null) { active = true; } DeleteAllRenderers(); }
/// <summary> /// Determines whether this move is a valid hop on the specified path. /// </summary> /// <returns><c>true</c> if this move is valid hop on the specified path; otherwise, <c>false</c>.</returns> /// <param name="path">Path.</param> public GameStatus IsValidHop(PathScript path) { GameObject hopTarget = null; if (isLogEnabled) { Debug.Log("The current player position is: " + activeRouter + ", The path.to is: " + path.to + ", the path.from is: " + path.from); } //neither is active --> hop is impossible. if (path.from.gameObject != activeRouter.gameObject && path.to.gameObject != activeRouter.gameObject) { gameStatus = GameStatus.ForbiddenHop; return(gameStatus); } //to=active --> goto from if (path.to.gameObject == activeRouter.gameObject) { hopTarget = path.from.gameObject; } else //from=active --> goto to if (path.from.gameObject == activeRouter.gameObject) { hopTarget = path.to.gameObject; } if (errorRecovery) { gameStatus = GameStatus.ErrorRecoveryHop; return(GameStatus.ErrorRecoveryHop); } //check win condition if (hopTarget.gameObject == currentRun.destination) { gameStatus = GameStatus.RunFinished; return(gameStatus); } if (IsValidGreedyHop(hopTarget.GetComponent <RouterScript>())) { // Valid hop. gameStatus = GameStatus.ValidHop; return(GameStatus.ValidHop); } // Invalid hop. gameStatus = GameStatus.InvalidHop; return(gameStatus); }
public override void OnInspectorGUI() { PathScript path = (PathScript)target; EditorGUI.BeginChangeCheck(); DrawDefaultInspector(); if (EditorGUI.EndChangeCheck()) { // in case they added something or edited something path.UpdatePoints(); } }
// Update is called once per frame void Update() { if (!this._startPositionGot) { ArrayList checkpoints = PathScript.sharedInstance().getPathCheckpointsPositions(); if (checkpoints != null) { Position firstPosition = (Position)checkpoints[0]; this._startPosition = MapScript.sharedInstance().getPointForMapCoordinates(firstPosition); this._startPositionGot = true; } } else { if (this.isWaiting()) { this._timeToStartRound -= Time.deltaTime; if (!this.isWaiting()) { this._nRounds++; this._secondsPerEnemy = (this.startSecondsPerEnemy / (1 + this._nRounds / 5.0f)); } } else { bool addEnemy = false; if (this._nEnemiesInCurrentRound == 0) { addEnemy = true; } else { this._timeSinceLastEnemy += Time.deltaTime; if (this._timeSinceLastEnemy >= this._secondsPerEnemy) { addEnemy = true; } } if (addEnemy) { this.addEnemy(); if (this._nEnemiesInCurrentRound == this.nEnemiesPerRound) { this._nEnemiesInCurrentRound = 0; this._timeToStartRound = this.timeBetweenRounds; } } } } }
/// <summary> /// Returns the inverse path which corresponds to specified path. The inverse path is the /// path which links the same routers, but from another direction. /// </summary> /// <param name="path">The path for which the inverse path should be extracted.</param> /// <returns>The PathScript of the inverse path.</returns> public PathScript GetInversePath(PathScript path) { PathScript option1 = graphRepresentation2[path.to.GetComponent <RouterScript>().GetRouterIndex(), path.from.GetComponent <RouterScript>().GetRouterIndex()]; PathScript option2 = graphRepresentation2[path.from.GetComponent <RouterScript>().GetRouterIndex(), path.to.GetComponent <RouterScript>().GetRouterIndex()]; if (path == option1) { return(option2); } else { return(option1); } }
void Start () { path=GetComponent<PathScript>(); if(GetComponent<MeshFilter>()==null) gameObject.AddComponent<MeshFilter>(); if(GetComponent<MeshRenderer>()==null) gameObject.AddComponent<MeshRenderer>(); try{ meshPrefab=((GameObject)Resources.Load(prefabName)).transform; }catch{} }
public static Easing easePath( Transform transform, PathScript path, float time, string easingGroup ) { Easing es = new Easing(); es.transform = transform; es.path=path; es.easeTime = time; es.pathStartNode=1; es.pathEndNode=path.path.Count-1; es.easingType = EasingType.SplinePath; es.target = TargetType.path; es.easingGroup = easingGroup; EasingManager.startEasing( es ); es.setDelay( path.delay ); return es; }
void Awake() { singleton = this; this._pathSegments = new Dictionary<Segment, Pair<int, LineRendererObject>> (); }
void OnDestroy() { singleton = null; }