Ejemplo n.º 1
0
		/// <summary>
		/// Tries to move a Duplicant to a more sensible location when they are about to fall.
		/// </summary>
		/// <param name="instance">The fall monitor to update if successful.</param>
		/// <param name="navigator">The Duplicant to check.</param>
		/// <param name="layer">The location history of the Duplicant.</param>
		/// <returns>true if the Duplicant was successfully moved away from entombment, or
		/// false otherwise.</returns>
		private static bool TryEscapeFalling(LocationHistoryTransitionLayer layer,
				Navigator navigator, FallMonitor.Instance instance, ref bool flipEmote) {
			bool moved = false;
			for (int i = 0; i < LocationHistoryTransitionLayer.TRACK_CELLS; i++) {
				int last = layer.VisitedCells[i], above = Grid.CellAbove(last);
#if DEBUG
				PUtil.LogDebug("{0} is falling, trying to move to {1:D}".F(navigator.
					gameObject?.name, last));
#endif
				if (Grid.IsValidCell(last) && IsValidNavCell(navigator, last)) {
					ForceMoveTo(instance, last, navigator, ref flipEmote);
					break;
				}
			}
			return moved;
		}
Ejemplo n.º 2
0
        /// <summary>
        /// Tries to move a Duplicant to a more sensible location when entombed or falling.
        /// </summary>
        /// <param name="layer">The location history of the Duplicant.</param>
        /// <param name="navigator">The Duplicant to check.</param>
        /// <param name="instance">The fall monitor to update if successful.</param>
        /// <returns>true if the Duplicant was successfully moved away, or false otherwise.</returns>
        private static bool TryEscape(LocationHistoryTransitionLayer layer,
                                      Navigator navigator, FallMonitor.Instance instance, ref bool flipEmote)
        {
            bool moved = false;

            for (int i = 0; i < LocationHistoryTransitionLayer.TRACK_CELLS; i++)
            {
                int last = layer.VisitedCells[i];
                if (Grid.IsValidCell(last) && IsValidNavCell(navigator, last))
                {
                    PUtil.LogDebug("{0} is in trouble, trying to escape to {1:D}".F(navigator.
                                                                                    gameObject?.name, last));
                    ForceMoveTo(instance, last, navigator, ref flipEmote);
                    // Prevents a loop back and forth between two cells in the history
                    layer.Reset();
                    break;
                }
            }
            return(moved);
        }