private List <GridBlock> MoveGridObjectsForTick(List <GridObject> objects) { /* PLAN * - Process a list of GridObjects' data * - Determine one of the following behaviors for the current tick for each object: * ~ Depart the grid * ~ Simply move * ~ FlyBy another object * ~ Nothing */ Vector2Int[] allOriginGridLocations = new Vector2Int[objects.Count]; Vector2Int[] allDestinationGridLocations = new Vector2Int[objects.Count]; List <GridBlock> collisionTestBlocks = new List <GridBlock>(); // Tracker for GridBlock collisions for (int i = 0; i < objects.Count; i++) { allOriginGridLocations[i].Set(99, 99); allDestinationGridLocations[i].Set(99, 99); } // Process movement data for (int i = 0; i < objects.Count; i++) { MovePattern mp = objects[i].GetComponent <MovePattern>(); //IMovable mp.OnTickUpdate(); if (mp.CanMoveThisTurn) { Vector2Int currentLocation = gm.WorldToGrid(objects[i].currentWorldLocation); Vector2Int destinationLocation = currentLocation + mp.DirectionOnGrid; if (gm.CheckIfGridBlockInBounds(destinationLocation)) { // Move or FlyBy allOriginGridLocations[i] = currentLocation; // Maintain index of objects requiring additional processing allDestinationGridLocations[i] = destinationLocation; } else { // Depart objects[i].IsLeavingGrid = true; } } } if (VerboseConsole) { Debug.Log("Fly-By detection starting."); } for (int i = 0; i < allOriginGridLocations.Length; i++) { for (int j = 0; j < allDestinationGridLocations.Length; j++) { if (objects.Count > 1 && i == j) { continue; } else if (allOriginGridLocations[i].x == 99) { continue; } else if (allDestinationGridLocations[j].x == 99) { continue; } else if (allOriginGridLocations[i] == allDestinationGridLocations[j] && allOriginGridLocations[j] == allDestinationGridLocations[i]) { Health hp = objects[i].GetComponent <Health>(); hp.SubtractHealth(objects[j].GetComponent <ContactDamage>().DamageAmount); } } } if (VerboseConsole) { Debug.Log("Moving GridObjects."); } for (int i = 0; i < objects.Count; i++) { if (objects[i].CurrentMode == GridObject.Mode.Spawn) { objects[i].SetGamePlayMode(GridObject.Mode.Play); } MovePattern mp = objects[i].GetComponent <MovePattern>(); //mp.OnTickUpdate(); Vector2Int currentLocation = gm.WorldToGrid(objects[i].currentWorldLocation); Vector2Int destinationLocation = currentLocation + mp.DirectionOnGrid; if (mp.CanMoveThisTurn) { if (objects[i].IsLeavingGrid == false && objects[i].GetComponent <Health>().HasHP) { // Eligible to move gm.RemoveObjectFromGrid(objects[i].gameObject, currentLocation); gm.AddObjectToGrid(objects[i].gameObject, destinationLocation); objects[i].targetWorldLocation = gm.GridToWorld(destinationLocation); if (!IsLocationInCollisionTracker(destinationLocation, collisionTestBlocks)) { collisionTestBlocks.Add(gm.FindGridBlockByLocation(destinationLocation)); } StartCoroutine(GridObjectMovementCoroutine(objects[i], 1.0f)); } else { // Departing objects[i].targetWorldLocation = gm.GridToWorld(destinationLocation); StartCoroutine(GridObjectMovementCoroutine(objects[i], 1.0f)); StartCoroutine(GridObjectDestructionCoroutine(objects[i], 1.1f)); } } } return(collisionTestBlocks); }