void UpdatePath() { if (nextTile == null || nextTile == currTile[0]) { if (VehiclePath_AStar == null || VehiclePath_AStar.Length() == 0) { //Create a path VehiclePath_AStar = new Path_ASTar(World.Current, currTile[0], destTile, true, false, Direction); if (VehiclePath_AStar.Length() == 0) { Debug.LogError("No route to destination"); VehiclePath_AStar = null; return; } nextTile = VehiclePath_AStar.Dequeue(); secondTile = VehiclePath_AStar.Dequeue(); thirdTile = VehiclePath_AStar.Dequeue(); } nextTile = secondTile; secondTile = thirdTile; thirdTile = VehiclePath_AStar.Dequeue(); CheckDirection(); } }
void Update_DoMovement(float deltaTime) { if (currTile == destTile) { WalkingPath_AStar = null; return; } if (nextTile == null || nextTile == currTile) { if (WalkingPath_AStar == null || WalkingPath_AStar.Length() == 0) { WalkingPath_AStar = new Path_ASTar(World.Current, CurrTile, destTile, false, true, Direction); if (WalkingPath_AStar.Length() == 0) { Debug.LogError("No path to dest"); return; } nextTile = WalkingPath_AStar.Dequeue(); } nextTile = WalkingPath_AStar.Dequeue(); CheckDirection(); } if (nextTile != null && nextTile.IsEnterable(CurrTile) == Enterability.Never) { nextTile = null; WalkingPath_AStar = null; return; } else if (nextTile != null && nextTile.IsEnterable(CurrTile) == Enterability.Soon) { if (!World.Current.ShopOpen) { //Shop is closed, I should see how long until it's open TimeSpan waitingTime = World.Current.Today.OpeningTime - WorldTime.Current.Date; if ((waitingTime.Days > 0 || waitingTime.Hours > 0 || waitingTime.Minutes > 15) && (!World.Current.ShopTiles.Contains(CurrTile) && !World.Current.StockRoomTiles.Contains(CurrTile))) { TimeToWait = 1f; LeaveShop(); nextTile = null; WalkingPath_AStar = null; return; } } return; } //Total dist from A to B if (nextTile == null) { Debug.Log("Wtf"); } float speedWalking = Speed; if (XModifier > 0.5f || XModifier < -0.5f || YModifier > 0.5f || YModifier < -0.5f) { if (!ModifiersCorrect(Numbers.Current.GetRandomTileModerator(), Numbers.Current.GetRandomTileModerator())) { speedWalking = speedWalking / 2; } } if (nextTile != null && currTile != null) { float distToTravel = Mathf.Sqrt(Mathf.Pow(currTile.X - nextTile.X, 2) + Mathf.Pow(currTile.Y - nextTile.Y, 2)); //How much can we travel this update float distThisFrame = (speedWalking / nextTile.PersonMovementCost) * deltaTime; //How much in terms of percentage? float percThisFrame = distThisFrame / distToTravel; //Add to overral percentage travelled MovementPercentage += percThisFrame; if (MovementPercentage >= 1) { CurrTile = nextTile; MovementPercentage = 0f; } if (cbPersonPositionChanged != null) { cbPersonPositionChanged(this); } } }
void Update_DoMovement(float deltaTime) { if (CurrTile == destTile) { WalkingPath_AStar = null; return; } if (nextTile == null || nextTile == currTile) { if (WalkingPath_AStar == null || WalkingPath_AStar.Length() == 0) { WalkingPath_AStar = new Path_ASTar(World.Current, CurrTile, destTile, false, false, Direction); if (WalkingPath_AStar.Length() == 0) { Debug.LogError("No path to dest"); AbandonJob(); return; } nextTile = WalkingPath_AStar.Dequeue(); } nextTile = WalkingPath_AStar.Dequeue(); CheckDirection(); } if (nextTile != null && nextTile.IsEnterable(CurrTile) == Enterability.Never) { nextTile = null; WalkingPath_AStar = null; return; } else if (nextTile != null && nextTile.IsEnterable(CurrTile) == Enterability.Soon) { return; } if (!ModifiersCorrect(0, 0.2f)) { return; } //Total dist from A to B float distToTravel = Mathf.Sqrt(Mathf.Pow(currTile.X - nextTile.X, 2) + Mathf.Pow(currTile.Y - nextTile.Y, 2)); //How much can we travel this update float distThisFrame = (Speed / nextTile.PersonMovementCost) * deltaTime; //How much in terms of percentage? float percThisFrame = distThisFrame / distToTravel; //Add to overral percentage travelled MovementPercentage += percThisFrame; CheckDirection(); if (MovementPercentage >= 1) { CurrTile = nextTile; MovementPercentage = 0f; } if (cbEmployeePositionChanged != null) { cbEmployeePositionChanged(this); } }