/// <summary> /// Attempts to add a node. Fails if there is a potentially dangerous collision, or if no points were nearby. /// </summary> public bool AddNode(MovementNode node) { // Check for collisions around the node. invalidNodeDetectionCollider_.CenterOn(node); // Track how many points were within the collider here. int numPointsDetected = 0; // I need to make this properly check for collisions around it. Just the same tile isn't enough! if (!GetAnyDangerousPointCollisions(invalidNodeDetectionCollider_, ref numPointsDetected)) { // If no points were detected within the selected area, count it as dangerous. if (numPointsDetected == 0) { return(false); } var container = GetContainingChild(node.Position); container.nodes_.Add(node); return(true); } else { return(false); } }
public MovementNode GetNodeNearest(Vector3 position, LocationTerrainType locationType, bool interior, int occupationFlags) { MovementNode closest = MovementNode.Empty; MovementNode m = MovementNode.Empty; float closestSoFar = Mathf.Infinity; float current = 0f; bool checkFlags = (occupationFlags < Int32.MaxValue); for (int i = 0; i < State.MovementNodes.Count; i++) { m = State.MovementNodes [i]; if (!checkFlags || Flags.Check(occupationFlags, m.OccupationFlags, Flags.CheckType.MatchAny)) { current = Vector3.Distance(position, m.Position); if (current < 2f) { return(closest = m); break; } else if (current < closestSoFar) { closestSoFar = current; closest = m; } } } if (MovementNode.IsEmpty(m)) { Debug.Log("Returning empty in closest from " + name); } return(closest); }
private ClientResolutionAction MakeResolutionAction( MovementNode node, Barrier barrier, GameObject sequenceToPlay, Dictionary <ActorData, ClientActorHitResults> actorToHitResults) { SequenceSource seqSource = new SequenceSource(null, null, ArtemisServerResolutionManager.Get().NextSeqSourceRootID, true); ServerClientUtils.SequenceStartData seqStart = new ServerClientUtils.SequenceStartData( sequenceToPlay, node.pathInfo.square, new ActorData[] { node.actor }, barrier.Caster, seqSource); ClientBarrierResults barrierResults = new ClientBarrierResults( barrier.m_guid, barrier.Caster, actorToHitResults, new Dictionary <Vector3, ClientPositionHitResults>()); ClientMovementResults movementResults = new ClientMovementResults( node.actor, node.pathInfo, new List <ServerClientUtils.SequenceStartData> { seqStart }, null, barrierResults, null, null); return(new ClientResolutionAction(ResolutionActionType.BarrierOnMove, null, null, movementResults)); }
public void SlideActor(ActorSlot actor) { Debug.Log("Slide actor"); CharacterSprite charSprite = CutsceneManager.Instance.rightCharacter.GetComponent <CharacterSprite>(); charSprite.Face.enabled = true; charSprite.Outfit.enabled = true; charSprite.Face.sprite = actor.Actor.BattleFacePath.Get(); charSprite.Outfit.sprite = actor.Actor.BattleOutfitPath.Get(); Transform dest = CutsceneManager.Instance.RightSpot; Image rightImage = CutsceneManager.Instance.rightCharacter; Vector3 _beginPoint = new Vector3(dest.position.x + 100, rightImage.transform.position.y, rightImage.transform.position.z); Vector3 _endPoint = new Vector3(CutsceneManager.Instance.RightSpot.position.x, _beginPoint.y, _beginPoint.z); Image _face = charSprite.Face; Image _outfit = charSprite.Outfit; rightImage.transform.position = _beginPoint; LeanTween.move(rightImage.gameObject, _endPoint, SpriteTime); MovementNode.ColorChange(_outfit.gameObject, new Color(0.7f, 0.7f, 0.7f, 1), new Color(1, 1, 1, 1), SpriteTime); MovementNode.ColorChange(_face.gameObject, new Color(0.7f, 0.7f, 0.7f, 1), new Color(1, 1, 1, 1), SpriteTime); }
public MovementNode ToMovementNode() { MovementNode m = new MovementNode(Index); m.X = transform.localPosition.x; m.Y = transform.localPosition.y; m.Z = transform.localPosition.z; return(m); }
void NodeHandling(MovementNode node) { gameObject.GetComponent <AudioSource>().Play(); switch (node.type) { case NodeType.Split: PrintToLog("you landed on a split path node"); phase = TurnPhase.End; break; case NodeType.Combat: PrintToLog("you landed on a combat node"); phase = TurnPhase.Combat; nodeAtk = node.nodeAttack; nodeDef = node.nodeDefense; combatPanelText.text = monsterNames[Random.Range(0, monsterNames.Length)] + " Attacks!\n" + "Attack: " + nodeAtk + " Defense: " + nodeDef; break; case NodeType.Event: PrintToLog("you landed on an event node"); EventSpace(); //play event break; case NodeType.Teleport: PrintToLog("you landed on a teleport node"); //change path SplitPathChange(); //teleport to new path teleporter Vector3 newPos = players[currentPlayer].path[players[currentPlayer].boardPosition].position; newPos.y = players[currentPlayer].transform.position.y; players[currentPlayer].transform.position = newPos + players[currentPlayer].offset; EndTurn(); break; case NodeType.Empty: PrintToLog("you landed on an empty node"); EndTurn(); break; case NodeType.Boss: PrintToLog("you landed on a boss node"); break; case NodeType.FinalSpace: PrintToLog("you landed on the last space. you win!"); FinalSpace(); break; } }
void CreateChildNode(ref QuadTree tree, double desiredSpeed, double angle) { var newPosition = new Vector2D(Math.Cos(angle) * desiredSpeed_, Math.Sin(angle) * desiredSpeed_) + position_; var newNode = new MovementNode(newPosition, angle, desiredSpeed, goal_, depth_ + 1); if (tree.AddNode(newNode)) { children_.Add(newNode); } }
protected override void Update(uint dt) { Board board = Service.BoardController.Board; for (MovementNode movementNode = this.nodeList.Head; movementNode != null; movementNode = movementNode.Next) { SmartEntity smartEntity = (SmartEntity)movementNode.Entity; if (smartEntity.StateComp.CurState == EntityState.Moving && smartEntity.PathingComp.CurrentPath != null) { smartEntity.PathingComp.TimeOnSegment += dt; if ((ulong)smartEntity.PathingComp.TimeOnSegment > (ulong)((long)smartEntity.PathingComp.TimeToMove)) { BoardCell boardCell = smartEntity.PathingComp.GetNextTile(); if (boardCell == null) { if (smartEntity.DroidComp == null) { Service.ShooterController.StopMoving(smartEntity.StateComp); } Service.EventManager.SendEvent(EventId.TroopReachedPathEnd, smartEntity); smartEntity.PathingComp.CurrentPath = null; } else { smartEntity.TransformComp.X = boardCell.X; smartEntity.TransformComp.Z = boardCell.Z; board.MoveChild(smartEntity.BoardItemComp.BoardItem, smartEntity.TransformComp.CenterGridX(), smartEntity.TransformComp.CenterGridZ(), null, false, false); PathView pathView = smartEntity.PathingComp.PathView; BoardCell nextTurn = pathView.GetNextTurn(); if (nextTurn.X == boardCell.X && nextTurn.Z == boardCell.Z) { pathView.AdvanceNextTurn(); } boardCell = smartEntity.PathingComp.AdvanceNextTile(); if (boardCell != null) { bool flag = smartEntity.TransformComp.X != boardCell.X && smartEntity.TransformComp.Z != boardCell.Z; smartEntity.PathingComp.TimeToMove += ((!flag) ? 1000 : 1414) * smartEntity.PathingComp.TimePerBoardCellMs / 1000; } else { DefenderComponent defenderComp = smartEntity.DefenderComp; if (defenderComp != null) { defenderComp.Patrolling = false; } } } } } } }
public virtual void Update() { if (!contains || !contains.IsPlayerSelected()) { return; } MovementNode newNode = null; // leave spot if (Input.GetKeyUp(KeyCode.Q) && !contains.interacting) { LeaveNodeMap(); return; } // moving up else if (!contains.nodeMoved && Input.GetButtonDown("Vertical") && Mathf.Sign(Input.GetAxis("Vertical")) > 0) { newNode = north; contains.nodeMoved = true; } // moving down else if (!contains.nodeMoved && Input.GetButtonDown("Vertical") && Mathf.Sign(Input.GetAxis("Vertical")) < 0) { newNode = south; contains.nodeMoved = true; } // moving right else if (!contains.nodeMoved && Input.GetButtonDown("Horizontal") && Mathf.Sign(Input.GetAxis("Horizontal")) > 0) { newNode = east; contains.nodeMoved = true; } // moving left else if (!contains.nodeMoved && Input.GetButtonDown("Horizontal") && Mathf.Sign(Input.GetAxis("Horizontal")) < 0) { newNode = west; contains.nodeMoved = true; } contains.interacting = false; if (newNode) { newNode.SetPlayer(contains); contains.SetMovementNode(newNode); this.SetPlayer(null); } StartCoroutine("NodeWait"); }
public void CreateChildren(MovementNode node) { if (node.GeneratedChildren) { foreach (var child in node.Children) { CreateChildren(child); } } else { node.CreateChildNodes(ref points_); } }
void OnDrawGizmos( ) { Gizmos.color = Color.yellow; if (!MovementNode.IsEmpty(LastMovementNode)) { Gizmos.DrawWireSphere(LastMovementNode.Position, 0.5f); Gizmos.DrawLine(transform.position, LastMovementNode.Position); } else { Gizmos.color = Color.red; Gizmos.DrawCube(transform.position, Vector3.one); } }
public void SetMovementNode(MovementNode movementNode) { if (movementNode != null) { mainCam.transform.parent = movementNode.transform; mainCam.transform.localPosition = new Vector3(0,0,-10f); } else { mainCam.transform.parent = this.transform; mainCam.transform.localPosition = new Vector3(0,0,-10f); } this.movementNode = movementNode; }
public static void LinkNodes(List <ActionNodePlaceholder> acps, List <ActionNode> nodes, List <MovementNode> movementNodes) { movementNodes.Clear(); for (int i = 0; i < acps.Count; i++) { ActionNodePlaceholder acp = acps [i]; acp.Index = i; MovementNode mn = new MovementNode(i); mn.X = acp.transform.localPosition.x; mn.Y = acp.transform.localPosition.y; mn.Z = acp.transform.localPosition.z; movementNodes.Add(mn); } for (int i = 0; i < movementNodes.Count; i++) { MovementNode mn = movementNodes [i]; for (int j = 0; j < acps.Count; j++) { if (acps [j].Index == i) { //check all connected nodes foreach (ActionNodePlaceholder otherAcp in acps[j].InConnections) { mn.ConnectingNodes.SafeAdd(otherAcp.Index); } } } movementNodes [i] = mn; } for (int i = 0; i < movementNodes.Count; i++) { for (int j = 0; j < movementNodes.Count; j++) { if (i != j) { MovementNode mn1 = movementNodes [i]; MovementNode mn2 = movementNodes [j]; if (mn1.ConnectingNodes.Contains(mn2.Index)) { mn2.ConnectingNodes.SafeAdd(mn1.Index); movementNodes [j] = mn2; } } } } }
void Start() { path = pathObject.GetComponent<NodeMovementPath>(); //StartCoroutine( "WalkPath" ); //set index if valid, else make valid if (nodeIndex < path.nodes.Count && nodeIndex >= 0) { currNode = path.nodes[nodeIndex]; } else { if (nodeIndex < 0) { nodeIndex = 0; } else { nodeIndex = path.nodes.Count - 1; } } }
public MovementNode( MovementNode parent, bool isWinningMove, bool isLosingMove, string state, MovementType movementType, float rotation, int depth) { this.Parent = parent; this.IsWinningMove = isWinningMove; this.Rotation = rotation; this.IsLosingMove = isLosingMove; this.State = state; this.MovementType = movementType; this.Depth = depth; }
void Update() { if (walkPath) { currNode = path.nodes[nodeIndex]; switch (currNode.type) { case MovementType.Straight: Vector3 currPos = transform.position; Vector3 newPos = Vector3.Lerp(currPos, currNode.end, currNode.travelTime * Time.deltaTime); transform.position = newPos; Vector3 distanceToEnd = transform.position - currPos; print(distanceToEnd.magnitude); if (distanceToEnd.magnitude < 0.01f) { //test magnitude to position nodeComplete = true; } break; case MovementType.Wait: break; case MovementType.LookAndReturn: break; case MovementType.Bezier: break; default: goto case MovementType.Straight; } if (nodeComplete) { if (nodeIndex < path.nodes.Count - 1) { print("node up"); nodeIndex++; } nodeComplete = false; } } }
public void HideSprite() { CharacterSprite charSprite = CutsceneManager.Instance.rightCharacter.GetComponent <CharacterSprite>(); Transform dest = CutsceneManager.Instance.RightSpot; Image rightImage = CutsceneManager.Instance.rightCharacter; Vector3 _endPoint = new Vector3(CutsceneManager.Instance.RightSpot.position.x + 100, charSprite.transform.position.y, charSprite.transform.position.z); Image _face = charSprite.Face; Image _outfit = charSprite.Outfit; LeanTween.move(rightImage.gameObject, _endPoint, SpriteTime); MovementNode.ColorChange(_outfit.gameObject, new Color(1f, 1f, 1f, 1), new Color(0.0f, 0.0f, 0.0f, 0.0f), SpriteTime); MovementNode.ColorChange(_face.gameObject, new Color(1, 1, 1, 1), new Color(0.0f, 0.0f, 0.0f, 0.0f), SpriteTime); StartCoroutine(DisableSprite(charSprite)); }
public static void LinkPlaceholders(List <ActionNodePlaceholder> acps, List <MovementNode> movementNodes) { for (int i = 0; i < movementNodes.Count; i++) { ActionNodePlaceholder currentAcp = null; MovementNode m = movementNodes [i]; foreach (ActionNodePlaceholder a in acps) { if (a.Index == m.Index) { currentAcp = a; break; } } if (currentAcp == null) { Debug.Log("Couldn't find action node index " + m.Index.ToString()); continue; } if (m.ConnectingNodes == null) { Debug.Log("No connecting nodes"); continue; } //get all the other linked nodes currentAcp.InConnections.Clear(); for (int j = 0; j < m.ConnectingNodes.Count; j++) { foreach (ActionNodePlaceholder linkedAcp in acps) { if (linkedAcp.Index == m.ConnectingNodes [j]) { currentAcp.InConnections.Add(linkedAcp); } } } } }
void BossNodeLogic() { if (players[currentPlayer].path[players[currentPlayer].currentNode].GetComponent <MovementNode>().bossHealth > 0) { //boss is alive //cap movement to currrent space players[currentPlayer].boardPosition = players[currentPlayer].currentNode; players[currentPlayer].currentNode--; bossCombat[currentPlayer] = true; MovementNode node = players[currentPlayer].path[players[currentPlayer].currentNode + 1].GetComponent <MovementNode>(); nodeAtk = node.nodeAttack; nodeDef = node.nodeDefense; //combat logic combatPanelText.text = "Boss Encountered! \n" + "Attack: " + nodeAtk + " Defense: " + nodeDef; combatPanel.SetActive(true); } }
void Start() { path = pathObject.GetComponent <NodeMovementPath>(); //StartCoroutine( "WalkPath" ); //set index if valid, else make valid if (nodeIndex < path.nodes.Count && nodeIndex >= 0) { currNode = path.nodes[nodeIndex]; } else { if (nodeIndex < 0) { nodeIndex = 0; } else { nodeIndex = path.nodes.Count - 1; } } }
private void Fire(MovementNode aNode) { if (aNode.TankControl.Tower.HasGun && aNode.TankControl.Tower.HasAmmo) { Transform go = GameObject.Instantiate((GameObject)aNode.TankControl.Tower.bulletPrefab).GetComponent <Transform>(); float ang = AntMath.DegToRad(aNode.TankControl.Tower.Angle); Vector3 p = aNode.entity.Position3D; p.x += aNode.TankControl.Tower.bulletPosition * Mathf.Cos(ang); p.y += aNode.TankControl.Tower.bulletPosition * Mathf.Sin(ang); go.position = p; Vector2 force = new Vector2(); force.x = aNode.TankControl.Tower.bulletSpeed * Mathf.Cos(ang); force.y = aNode.TankControl.Tower.bulletSpeed * Mathf.Sin(ang); go.GetComponent <Rigidbody2D>().AddForce(force, ForceMode2D.Impulse); Quaternion q = Quaternion.AngleAxis(aNode.TankControl.Tower.Angle, Vector3.forward); go.rotation = q; aNode.TankControl.Tower.AmmoCount--; } else if (aNode.TankControl.Tower.HasBomb) { float dist; HealthNode hpNode; for (int i = _healthNodes.Count - 1; i >= 0; i--) { hpNode = _healthNodes[i]; dist = AntMath.Distance(aNode.entity.Position, hpNode.entity.Position); if (dist < 2.5f) { hpNode.Health.HP = 0.0f; } } } }
public MovementNode GetNextNode(MovementNode lastMovementNode, LocationTerrainType locationType, bool interior, int occupationFlags) { //we only have one location type MovementNode mn = MovementNode.Empty; if (State.MovementNodes.Count == 0) { Debug.Log("Movement nodes were zero in " + name); return(mn); } bool checkFlags = (occupationFlags < Int32.MaxValue); if (lastMovementNode.ConnectingNodes != null && lastMovementNode.ConnectingNodes.Count > 0) { int nodeNum = 0; if (lastMovementNode.ConnectingNodes.Count > 1) { nodeNum = UnityEngine.Random.Range(0, lastMovementNode.ConnectingNodes.Count); } int index = lastMovementNode.ConnectingNodes [nodeNum]; mn = State.MovementNodes [lastMovementNode.ConnectingNodes [nodeNum]]; } return(mn); }
public static Graph THINGS() { /* * Sizes * - EC3: 80 * - EC4: 110 * - SNG-3: 70 * - SNG-4: 90 * - SNG-5: 110 * In: * - 0:00:00, EC3(C), EC3(C) * - 0:05:00, SNG-4 * - 0:12:00, EC3, EC4 * - 0:30:00, EC4 * - 1:00:00, SNG-3, SNG-3 * - 1:10:00, SNG-5 * Out: * - 0:20:00, EC3 * - 0:25:00, SNG-4 * - 0:29:00, EC4, EC3 * - 0:45:00, EC3, EC4 * - 1:55:00, SNG-5, SNG-3 * - 2:10:00, SNG-3 * * Cleaning (C): * - EC3: 32 * - EC4: 47 * - SNG-3: 27 * - SNG-4: 35 * - SNG-5: 42 * * Insepction (I): * - EC3: 32 * - EC4: 47 * - SNG-3: 27 * - SNG-4: 35 * - SNG-5: 42 */ var graph = new Graph(); Func <int, int> hours = (int h) => h * 3600; Func <int, int> minutes = (int m) => m * 60; Func <int, int> seconds = (int s) => s; Func <int, int, int> track2secs = (int t, int s) => t * 60 + s * 30; Func <int, int> turnaround2secs = (int c) => c * 30; /* * - 0:00:00, EC3(C), EC3(C) * - 0:05:00, SNG4 * - 0:12:00, EC3, EC4 * - 0:30:00, EC4 * - 1:00:00, SNG3, SNG3 * - 1:10:00, SNG5 */ var ar1 = new ArrivalNode("(1,2)", 0); var ar2 = new ArrivalNode("(3)", minutes(5)); var ar3 = new ArrivalNode("(4, 5)", minutes(12)); var ar4 = new ArrivalNode("(6)", minutes(30)); var ar5 = new ArrivalNode("(7, 8)", hours(1)); var ar6 = new ArrivalNode("(9)", hours(1) + minutes(10)); /* * Out: * - 0:50:00, EC3 * - 0:25:00, SNG-4 * - 0:29:00, EC4, EC3 * - 0:45:00, EC3, EC4 * - 1:55:00, SNG-5, SNG-3 * - 2:10:00, SNG-3 */ var dep1 = new DepartureNode("(1)", minutes(60)); var dep2 = new DepartureNode("(3)", minutes(25)); var dep3 = new DepartureNode("(5,2)", minutes(69)); var dep4 = new DepartureNode("(4, 6)", minutes(45)); var dep5 = new DepartureNode("(9, 7)", hours(1) + minutes(55)); var dep6 = new DepartureNode("(8)", hours(2) + minutes(10)); { Node m12P1 = new MovementNode("(1, 2) to P1", track2secs(2, 1)); Node s12 = new SplitNode("(1, 2) -> (1), (2)", minutes(2) + 30); Node m1p7 = new MovementNode("(1) to P7", track2secs(3, 2)); Node service1p7 = new ServiceNode("(1) insepction", minutes(32)); Node service2p7 = new ServiceNode("(1) insepction", minutes(32)); Node m2p7 = new MovementNode("(2) to P7", track2secs(3, 2)); ar1.AddSuccessor(m12P1); m12P1 += s12; s12 += m1p7; s12 += m2p7; m1p7 += m2p7; m1p7 += service1p7; m2p7 += service2p7; Node m1p4 = new MovementNode("(1) to P4", track2secs(5, 4)); Node m2p4 = new MovementNode("(2) to P4", track2secs(5, 4)); service1p7 += m1p4; service2p7 += m2p4; m1p4.AddSuccessor(dep1); m2p4.AddSuccessor(dep6); } graph.ArrivalNodes.Add(ar1); graph.ArrivalNodes.Add(ar2); graph.ArrivalNodes.Add(ar3); graph.ArrivalNodes.Add(ar4); graph.ArrivalNodes.Add(ar5); graph.ArrivalNodes.Add(ar6); graph.DepartureNodes.Add(dep1); graph.DepartureNodes.Add(dep2); graph.DepartureNodes.Add(dep3); graph.DepartureNodes.Add(dep4); graph.DepartureNodes.Add(dep5); graph.DepartureNodes.Add(dep6); graph.Propagate(); return(graph); }
protected virtual void OnArriveAtNode(MovementNode node) { //No default implementation. }
void MoveForward(PlayerMovement currentPlayer, Transform[] currentPath) { //move player if (canMove) { Vector3 currPos = currentPlayer.transform.position; if (currentPlayer.boardPosition >= currentPath.Length) { currentPlayer.boardPosition = currentPath.Length - 1; } if (currentPlayer.currentNode >= currentPath.Length) { currentPlayer.currentNode = currentPath.Length - 1; } if (currentPlayer.currentNode < currentPlayer.boardPosition) { Vector3 newPos = Vector3.Lerp(currPos, currentPath[currentPlayer.currentNode + 1].position + currentPlayer.offset, 5 * Time.deltaTime); newPos.y = currPos.y; currentPlayer.transform.position = newPos; //transform.Translate(newPos); Vector3 distanceBetweenNodes = currentPlayer.transform.position - currPos; if (distanceBetweenNodes.magnitude < .01) //transform.position == GC.movementNodes[currentNode + 1].position { currentPlayer.currentNode++; //read node type. MovementNode node = currentPath[currentPlayer.currentNode].GetComponent <MovementNode>(); switch (node.type) { case NodeType.Split: splitPanel.SetActive(true); canMove = false; //split path pop up break; case NodeType.Boss: BossNodeLogic(); //boss pop up //set movement to this node, so they cannot move further break; } } } else { //pull in node info MovementNode node = currentPath[currentPlayer.currentNode].GetComponent <MovementNode>(); NodeHandling(node); } } }
public void SetMovementNode(GameObject node) { movementNode = node.GetComponent <MovementNode>(); movementTransform = node.transform; }
public IEnumerator FollowRoutineOverTime() { while (!motile.Initialized || !motile.HasBody) { yield return(null); } //wait for a random interval to reduce the load on the city double waitUntil = WorldClock.AdjustedRealTime + UnityEngine.Random.value; while (WorldClock.AdjustedRealTime < waitUntil) { yield return(null); } if (ParentSite == null) { //Debug.Log ("Parent site was null in " + name + ", removing routine"); Finish(); yield break; } //Debug.Log (worlditem.Group.Props.TerrainType.ToString () + " in " + worlditem.name); //if we don't have a parent site within a second of spawning then we're toast if (!ParentSite.HasMovementNodes(worlditem.Group.Props.TerrainType, worlditem.Group.Props.Interior, OccupationFlags)) { //Debug.Log ("Parent site " + ParentSite.name + " had no movement nodes, quitting routine"); Finish(); yield break; } while (!ParentSite.IsActive(worlditem.Group.Props.TerrainType, worlditem.Group.Props.Interior, OccupationFlags)) { yield return(null); } //get the very first node we'll be using LastMovementNode = ParentSite.GetNodeNearest(worlditem.Position, worlditem.Group.Props.TerrainType, worlditem.Group.Props.Interior, OccupationFlags); //DAILY ROUTINE START while (!(mFinished | mDestroyed)) { //wait a random amount waitUntil = WorldClock.AdjustedRealTime + (UnityEngine.Random.value * 4f); while (WorldClock.AdjustedRealTime < waitUntil) { yield return(null); } //if we're not visible then just hang out while (worlditem.Is(WIActiveState.Invisible)) { waitUntil = WorldClock.AdjustedRealTime + 0.25f; while (WorldClock.AdjustedRealTime < waitUntil) { yield return(null); } } //get the next movement node LastMovementNode = ParentSite.GetNextNode(LastMovementNode, worlditem.Group.Props.TerrainType, worlditem.Group.Props.Interior, OccupationFlags); if (MovementNode.IsEmpty(LastMovementNode)) { //Debug.Log ("Node was empty in routine from " + ParentSite.name + ", ending routine"); mFollowingRoutine = false; Finish(); yield break; } //Debug.Log ("Going to last movement node " + LastMovementNode.Index.ToString () + " at position " + LastMovementNode.Position.ToString ()); motile.GoalObject.position = LastMovementNode.Position; MotileAction goToAction = character.GoToThing(null); goToAction.Range = 1.5f; goToAction.WalkingSpeed = true; //now wait until we get there float maxWaitTime = 30f; double startTime = WorldClock.AdjustedRealTime; var waitUntilFinished = goToAction.WaitForActionToFinish(0.15f); while (waitUntilFinished.MoveNext()) { //Debug.Log ("Waiting for action to finish, state is " + goToAction.State.ToString ()); if (goToAction.State != MotileActionState.Waiting) { motile.GoalObject.position = LastMovementNode.Position; } yield return(waitUntilFinished.Current); if (WorldClock.AdjustedRealTime > startTime + maxWaitTime) { //Debug.Log ("Timed out, finishing now"); goToAction.TryToFinish(); break; } } yield return(null); } mFollowingRoutine = false; yield break; }
public IEnumerator CharacterMovement() { MovementNode moveNode = this; MovementNode.SpotOnScreen scopedSpotOnScreen = moveNode.spotOnScreen; MovementNode.EnterOrLeave movementType = moveNode.enterOrLeave; float _distance = CutsceneManager.Instance.MoveDistance; //manage face/outfit int _whichImage = 1; _whichImage = scopedSpotOnScreen.spotNumber(); //SetSpriteOnScreen(_whichImage, scopedActor, scopedActor.baseClass.FaceID, scopedActor.baseClass.OutfitID); //setting up variables Image _image = CutsceneManager.Instance.rightCharacter; CharacterSprite charSprite = _image.GetComponent <CharacterSprite>(); switch (_whichImage) { case 1: _image = CutsceneManager.Instance.leftCharacter; break; case 2: _image = CutsceneManager.Instance.midLeftCharacter; break; case 3: _image = CutsceneManager.Instance.midRightCharacter; break; case 4: _image = CutsceneManager.Instance.rightCharacter; break; } charSprite = _image.GetComponent <CharacterSprite>(); Vector3 _beginPoint = new Vector3(CutsceneManager.Instance.RightSpot.transform.position.x + _distance, _image.transform.position.y, _image.transform.position.z); Vector3 _endPoint = new Vector3(CutsceneManager.Instance.RightSpot.position.x, _beginPoint.y, _beginPoint.z); float _lerpTime = 1f; float _curLerpTime = 0f; Image _face = charSprite.Face; Image _outfit = charSprite.Outfit; Color _faceColor = _face.color; Color _outfitColor = _outfit.color; float _startOpacity = 0; float _endOpacity = 1; float colorDim = 1f; if (!moveNode.IsSpeaking) { colorDim = 0.7f; } float _startDim = charSprite.Outfit.color.r; float _endDim = colorDim; if (!scopedSpotOnScreen.IsRight()) { Transform LeftSpot = CutsceneManager.Instance.LeftSpot; _beginPoint = new Vector3(LeftSpot.transform.position.x - _distance, _image.transform.position.y, _image.transform.position.z); _endPoint = new Vector3(LeftSpot.position.x, _beginPoint.y, _beginPoint.z); // _endPoint = _beginPoint + Vector3.right * distance; if (scopedSpotOnScreen.IsMiddle()) { } } else if (scopedSpotOnScreen.IsMiddle()) { } bool inScene = false; if (movementType.IsLeaving()) { Vector3 _newStart = new Vector3(_endPoint.x, _endPoint.y, _endPoint.z); Vector3 _newEnd = new Vector3(_beginPoint.x, _endPoint.y, _endPoint.z); _beginPoint = _newStart; _endPoint = _newEnd; _startOpacity = 1f; _endOpacity = 0f; CutsceneManager.Instance.activeImages.Remove(_outfit); CutsceneManager.Instance.activeImages.Remove(_face); } else { CutsceneManager.Instance.activeImages.Add(_outfit); CutsceneManager.Instance.activeImages.Add(_face); inScene = true; } if (!moveNode.enterOrLeave.isMoving()) { do { //here is where we put in return for if player hits skip _curLerpTime += Time.deltaTime; float t = _curLerpTime / _lerpTime; //distance moved _image.transform.position = Vector3.Lerp(_beginPoint, _endPoint, t); //calculate opacity float _currentAlpha = Mathf.Lerp(_startOpacity, _endOpacity, t); float _currentDim = Mathf.Lerp(_startDim, _endDim, t); _faceColor.a = _currentAlpha; _outfitColor.a = _currentAlpha; _outfitColor.r = _currentDim; _outfitColor.g = _currentDim; _outfitColor.b = _currentDim; _face.color = _faceColor; _outfit.color = _outfitColor; yield return(0); } while (_curLerpTime < _lerpTime); charSprite.InScene = inScene; } else {//when just moving to a different spot _image.transform.position = _endPoint; } yield return(0); }
public void CharacterMovement() { MovementNode moveNode = this; MovementNode.SpotOnScreen scopedSpotOnScreen = moveNode.spotOnScreen; MovementNode.EnterOrLeave movementType = moveNode.enterOrLeave; float _distance = CutsceneManager.Instance.MoveDistance; //manage face/outfit int _whichImage = 1; _whichImage = scopedSpotOnScreen.spotNumber(); //SetSpriteOnScreen(_whichImage, scopedActor, scopedActor.baseClass.FaceID, scopedActor.baseClass.OutfitID); //setting up variables Image _image = CutsceneManager.Instance.rightCharacter; switch (_whichImage) { case 1: _image = CutsceneManager.Instance.leftCharacter; break; case 2: _image = CutsceneManager.Instance.midLeftCharacter; break; case 3: _image = CutsceneManager.Instance.midRightCharacter; break; case 4: _image = CutsceneManager.Instance.rightCharacter; break; } CharacterSprite charSprite = _image.GetComponent <CharacterSprite>(); charSprite.IsMoving = true; charSprite = _image.GetComponent <CharacterSprite>(); Vector3 _beginPoint = new Vector3(CutsceneManager.Instance.RightSpot.transform.position.x + _distance, _image.transform.position.y, _image.transform.position.z); Vector3 _endPoint = new Vector3(CutsceneManager.Instance.RightSpot.position.x, _beginPoint.y, _beginPoint.z); float _lerpTime = 0.5f; float _curLerpTime = 0f; charSprite.StartCoroutine(ResetMovingBool(_lerpTime, charSprite)); Image _face = charSprite.Face; Image _outfit = charSprite.Outfit; Color _faceColor = _face.color; Color _outfitColor = _outfit.color; float _startOpacity = 0; float _endOpacity = 1; float colorDim = 1f; if (!moveNode.IsSpeaking) { colorDim = 0.7f; } float _startDim = charSprite.Outfit.color.r; float _endDim = colorDim; if (!scopedSpotOnScreen.IsRight()) { Transform LeftSpot = CutsceneManager.Instance.LeftSpot; _beginPoint = new Vector3(LeftSpot.transform.position.x - _distance, _image.transform.position.y, _image.transform.position.z); _endPoint = new Vector3(LeftSpot.position.x, _beginPoint.y, _beginPoint.z); // _endPoint = _beginPoint + Vector3.right * distance; if (scopedSpotOnScreen.IsMiddle()) { } } else if (scopedSpotOnScreen.IsMiddle()) { } bool inScene = false; if (movementType.IsLeaving()) { Vector3 _newStart = new Vector3(_endPoint.x, _endPoint.y, _endPoint.z); Vector3 _newEnd = new Vector3(_beginPoint.x, _endPoint.y, _endPoint.z); _beginPoint = _newStart; _endPoint = _newEnd; _startOpacity = 1f; _endOpacity = 0f; CutsceneManager.Instance.activeImages.Remove(_outfit); CutsceneManager.Instance.activeImages.Remove(_face); } else { CutsceneManager.Instance.activeImages.Add(_outfit); CutsceneManager.Instance.activeImages.Add(_face); inScene = true; } //move _image.transform.position = _beginPoint; LeanTween.move(_image.gameObject, _endPoint, _lerpTime); // _face.color = new Color(1,1,1,0); // _outfit.color = new Color(1,1,1,0); LeanTween.value(_face.gameObject, new Color(_startDim, _startDim, _startDim, _startOpacity), new Color(_endDim, _endDim, _endDim, _endOpacity), _lerpTime).setOnUpdate( (Color val) => { UnityEngine.UI.Image image = (UnityEngine.UI.Image)_face.gameObject.GetComponent(typeof(UnityEngine.UI.Image)); image.color = val; } ); LeanTween.value(_outfit.gameObject, new Color(_startDim, _startDim, _startDim, _startOpacity), new Color(_endDim, _endDim, _endDim, _endOpacity), _lerpTime).setOnUpdate( (Color val) => { UnityEngine.UI.Image image = (UnityEngine.UI.Image)_outfit.gameObject.GetComponent(typeof(UnityEngine.UI.Image)); image.color = val; } ); }
protected virtual void OnLeaveNode(MovementNode node) { //No default implementation. }
public override void update(float time, Graphics g) { if (runnable) { #region basics movement GunControlNode gunnode = (GunControlNode)lstgun.First(); foreach (Node n in lstmovement.ToList()) // We transform to list to entity from node { MovementNode mn = (MovementNode)n; Velocity v = mn.vitesse; Position p = mn.pos; Vector2D newv = time * v.speedVect + p.point; if (newv.x < size.Width || newv.x > 0) { p.point = newv; } if (newv.y < 0) { factory.removeEntity(mn.entity); gunnode.gun.shoot = true; } else if (newv.y > size.Height) { factory.removeEntity(mn.entity); } } #endregion #region enemies movement GameStateNode gstatenode = null; EnemyBlockNode eblocknode = null; if (lst_game.Count > 0) { gstatenode = (GameStateNode)lst_game.First(); } if (lst_block.Count > 0) { eblocknode = (EnemyBlockNode)lst_block.First(); } // First we move enemies int compteur = 0; foreach (Node enemies in lst_enemies) { EnemyNode en = (EnemyNode)enemies; switch (eblocknode.block.direction) { case EnemyBlock.Direction.Right: en.pos.point.x += en.enemy.vitesse.x * time + (gstatenode.gs.level * time); break; case EnemyBlock.Direction.Left: en.pos.point.x -= en.enemy.vitesse.x * time + (gstatenode.gs.level * time); break; } if (eblocknode.block.collided) { if (time == 0) { time = (float)0.005; // In case the draw update happens at impact } en.pos.point.y += en.enemy.vitesse.y * time; en.enemy.vitesse.y += size.Width / 10 + (gstatenode.gs.level * time); en.enemy.vitesse.x += 3 * gstatenode.gs.level; } } if (eblocknode.block.collided) { eblocknode.block.collided = false; } updateEnemyBlock(eblocknode); #endregion } }
public IEnumerator SpawnCharactersOverTime() { if (Globals.MissionDevelopmentMode) { //we don't care about random characters in mission dev mode HasSpawnedCharacters = true; mSpawningCharacters = false; yield break; } List <ActionNodeState> actionNodeStates = null; while (!GameManager.Is(FGameState.InGame) || (mSpawningCharacters && (location.LocationGroup == null || !location.LocationGroup.Is(WIGroupLoadState.Loaded)))) { yield return(null); } //set owner once it's available location.LocationGroup.Owner = worlditem; bool hasSpawnedMinorStructures = false; while (mSpawningCharacters && !hasSpawnedMinorStructures) { hasSpawnedMinorStructures = true; for (int i = 0; i < State.MinorStructures.Count; i++) { if (State.MinorStructures [i].LoadState != StructureLoadState.ExteriorLoaded) { hasSpawnedMinorStructures = false; break; } } double waitUntil = WorldClock.RealTime + 0.25f + UnityEngine.Random.value; while (WorldClock.RealTime < waitUntil) { yield return(null); } } if (!mSpawningCharacters) { yield break; } yield return(null); if (gTransformHelper == null) { gTransformHelper = new GameObject("City Transform Helper").transform; } gTransformHelper.position = worlditem.tr.position; gTransformHelper.rotation = worlditem.tr.rotation; gTransformHelper.localScale = worlditem.tr.lossyScale; //transform the movement node positions MovementNode mn = MovementNode.Empty; for (int i = 0; i < State.MovementNodes.Count; i++) { mn = State.MovementNodes [i]; mn.Position = MovementNode.GetPosition(gTransformHelper, mn); State.MovementNodes [i] = mn; } yield return(null); //TODO move this functionality into the Spawner script if (worlditem.Group.GetParentChunk().GetNodesForLocation(location.LocationGroup.Props.PathName, out actionNodeStates)) { Character spawnedCharacter = null; for (int i = 0; i < actionNodeStates.Count; i++) { if (!mSpawningCharacters) { //whoops, time to stop yield break; } spawnedCharacter = null; ActionNodeState actionNodeState = actionNodeStates [i]; if (actionNodeState.IsLoaded && actionNodeState.UseAsSpawnPoint && !actionNodeState.HasOccupant) { if (string.IsNullOrEmpty(actionNodeState.OccupantName)) { Characters.SpawnRandomCharacter( actionNodeState.actionNode, State.RandomResidentTemplateNames, State.ResidentFlags, location.LocationGroup, out spawnedCharacter); } else { Characters.SpawnRandomCharacter( actionNodeState.actionNode, actionNodeState.OccupantName, State.ResidentFlags, location.LocationGroup, out spawnedCharacter); } if (spawnedCharacter != null) { //let the character know it can use the city for movement nodes if it wants them DailyRoutine dailyRoutine = null; if (spawnedCharacter.worlditem.Is <DailyRoutine> (out dailyRoutine)) { dailyRoutine.ParentSite = this; } SpawnedCharacters.Add(spawnedCharacter); } } double waitUntil = WorldClock.RealTime + 0.5f + UnityEngine.Random.value; while (WorldClock.RealTime < waitUntil) { yield return(null); } } } HasSpawnedCharacters = true; //do we need to update our characters? if (SpawnedCharacters.Count > 0) { enabled = true; } mSpawningCharacters = false; yield break; }
public static Graph Create() { var graph = new Graph(); Func <int, int> hours = (int h) => h * 3600; Func <int, int> minutes = (int m) => m * 60; Func <int, int> seconds = (int s) => s; Func <int, int, int> track2secs = (int t, int s) => t * 60 + s * 30; Func <int, int> turnaround2secs = (int c) => c * 30; Debug.Assert(track2secs(2, 1) == minutes(2) + seconds(30)); Debug.Assert(turnaround2secs(4) == minutes(2)); var ar1 = new ArrivalNode("(1,2)", 0); var ar2 = new ArrivalNode("(3)", minutes(2) + 30); var arm1 = new MovementNode("(1, 2) to T3", track2secs(2, 1)); var split12 = new SplitNode("(1, 2) to (1), (2)", minutes(2)); var m2 = new MovementNode("(2) to T2", track2secs(2, 1)); var s1 = new ServiceNode("(2) on T2", minutes(34)); var m3 = new MovementNode("(1) to T4", track2secs(2, 1)); var p3a = new ParkingNode("(1) P3"); var p3b = new ParkingNode("(2) P3"); var arm2a = new MovementNode("(3) to T3", track2secs(2, 1)); var arm2b = new TurnAroundNode(turnaround2secs(4)); var arm2c = new MovementNode("(3) to T1", track2secs(2, 1)); var m4 = new MovementNode("(2) to G", track2secs(3, 2)); var m5a = new MovementNode("(1) to T3", track2secs(2, 1)); var m5b = new TurnAroundNode(turnaround2secs(3)); var m5c = new MovementNode("(1) to T2", track2secs(2, 1)); var s2 = new ServiceNode("(1) on T2", minutes(34)); var m6 = new MovementNode("(1) to T1", track2secs(3, 2)); var m7 = new SplitNode("(3) (1) to (3, 1)", minutes(3)); var m8a = new MovementNode("(3, 1) to T4", track2secs(3, 2)); var m8b = new TurnAroundNode(turnaround2secs(7)); var m8c = new MovementNode("(3, 1) to G", track2secs(3, 2)); var dep1 = new DepartureNode("(2)", minutes(90)); var dep2 = new DepartureNode("(3, 1)", hours(2)); ar1.AddSuccessor(arm1); ar2.AddSuccessor(arm2a); split12.AddSuccessor(m2); split12.AddSuccessor(m3); split12.AddSuccessor(p3a); split12.AddSuccessor(p3b); p3a.AddSuccessor(m2); p3b.AddSuccessor(m3); m2.AddSuccessor(s1); m2.AddSuccessor(m3); arm1.AddSuccessor(split12); arm2a.AddSuccessor(arm2b); arm2b.AddSuccessor(arm2c); s1.AddSuccessor(m4); m4.AddSuccessor(dep1); m3.AddSuccessor(m5a); m5a.AddSuccessor(m5b); m5b.AddSuccessor(m5c); m5c.AddSuccessor(s2); s2.AddSuccessor(m6); m6.AddSuccessor(m7); arm2c.AddSuccessor(m7); m7.AddSuccessor(m8a); m8a.AddSuccessor(m8b); m8b.AddSuccessor(m8c); m8c.AddSuccessor(dep2); // Other graph.ArrivalNodes.Add(ar1); graph.ArrivalNodes.Add(ar2); graph.DepartureNodes.Add(dep1); graph.DepartureNodes.Add(dep2); graph.Propagate(); return(graph); }
void Start() { foreach (ColorTweenSprite tween in tweens) { tween.Start(); } if (associatedNode == null) { if (this.transform.parent != null) { associatedNode = this.transform.parent.GetComponent<MovementNode>(); } else { associatedNode = GetComponent<MovementNode>(); } } }
void Start() { originalColor = renderer.materials[materialIndex].color; foreach (ColorTween tween in tweens) { tween.Start(); } if (associatedNode == null) { associatedNode = this.transform.parent.GetComponent<MovementNode>(); } }
public void CenterOn(MovementNode node) { center_ = node.Position; rotation_ = node.Rotation; }
public bool IsConnectedTo(MovementNode node) { return node.connectedNodes.Contains(this); }
protected virtual void OnTargetNodeChanged(MovementNode node) { //No default implementation. }