public OCChunk(OCMap map, Vector3i position) { this.map = map; this.position = position; for (int x = blocks.GetMinX(); x < blocks.GetMaxX(); ++x) { for (int y = blocks.GetMinY(); y < blocks.GetMaxY(); ++y) { for (int z = blocks.GetMinZ(); z < blocks.GetMaxZ(); ++z) { Vector3i pos = new Vector3i(x, y, z); blocks.Set(OCBlockData.CreateInstance <OCBlockData>().Init(null, pos), pos); } } } }
//--------------------------------------------------------------------------- #endregion //--------------------------------------------------------------------------- #region Private Member Functions //--------------------------------------------------------------------------- private void FindGoalBlockPositionInChunks(List3D <OCChunk> chunks) { Vector3 sourcePos = gameObject.transform.position; Vector3 distanceVec = ((Vector3)GoalBlockPos) - sourcePos; // // if(distanceVec.y < -1.0f + 0.5f && distanceVec.y > -1.0f - 0.5f) // if(distanceVec.sqrMagnitude < 2.25f) // { // Debug.Log("We've arrived at our goal TNT block..."); // map.SetBlockAndRecompute(new OCBlockData(), TargetBlockPos); // TargetBlockPos = Vector3i.zero; // // OCAction[] actions = gameObject.GetComponentsInChildren<OCAction>(); // // foreach(OCAction action in actions) // { // action.EndTarget.transform.position = Vector3.zero; // action.StartTarget.transform.position = Vector3.zero; // } // } bool doesGoalExist = false; //distanceVec = new Vector3(1000,1000,1000); for (int cx = chunks.GetMinX(); cx < chunks.GetMaxX(); ++cx) { for (int cy = chunks.GetMinY(); cy < chunks.GetMaxY(); ++cy) { for (int cz = chunks.GetMinZ(); cz < chunks.GetMaxZ(); ++cz) { Vector3i chunkPos = new Vector3i(cx, cy, cz); OCChunk chunk = chunks.SafeGet(chunkPos); if (chunk != null) { for (int z = 0; z < OCChunk.SIZE_Z; z++) { for (int x = 0; x < OCChunk.SIZE_X; x++) { for (int y = 0; y < OCChunk.SIZE_Y; y++) { Vector3i localPos = new Vector3i(x, y, z); OCBlockData blockData = chunk.GetBlock(localPos); Vector3i candidatePos = OCChunk.ToWorldPosition(chunk.GetPosition(), localPos); Vector3 candidateVec = ((Vector3)candidatePos) - sourcePos; if (!blockData.IsEmpty() && blockData.block.GetName() == _goalBlockType.GetName()) { doesGoalExist = true; if (candidateVec.sqrMagnitude < distanceVec.sqrMagnitude) { GoalBlockPos = candidatePos; distanceVec = candidateVec; if (_ShouldMoveTargets) { OCAction[] actions = gameObject.GetComponentsInChildren <OCAction>(); foreach (OCAction action in actions) { action.EndTarget.transform.position = new Vector3(GoalBlockPos.x, GoalBlockPos.y, GoalBlockPos.z); action.StartTarget.transform.position = gameObject.transform.position; } } Debug.Log("We found some " + _goalBlockType.GetName() + " nearby: " + GoalBlockPos + "!"); } } } } } } } } } if (GoalBlockPos != Vector3i.zero && (!doesGoalExist || _map.GetBlock(GoalBlockPos).IsEmpty())) { Debug.Log("No more " + _goalBlockType.GetName() + "... :("); GoalBlockPos = Vector3i.zero; OCAction[] actions = gameObject.GetComponentsInChildren <OCAction>(); foreach (OCAction action in actions) { action.EndTarget.transform.position = Vector3.zero; action.StartTarget.transform.position = Vector3.zero; } } }