コード例 #1
0
ファイル: Map.cs プロジェクト: orf53975/worldcraft
    public int GetMaxY(int x, int z)
    {
        Vector3i chunkPos = Chunk.ToChunkPosition(x, 0, z);

        chunkPos.y = chunks.GetMax().y;
        Vector3i localPos = Chunk.ToLocalPosition(x, 0, z);

        for (; chunkPos.y >= 0; chunkPos.y--)
        {
            localPos.y = Chunk.SIZE_Y - 1;
            for (; localPos.y >= 0; localPos.y--)
            {
                Chunk chunk = chunks.SafeGet(chunkPos);
                if (chunk == null)
                {
                    break;
                }
                BlockData block = chunk.GetBlock(localPos);
                if (!block.IsEmpty())
                {
                    return(Chunk.ToWorldPosition(chunkPos, localPos).y);
                }
            }
        }

        return(0);
    }
コード例 #2
0
 public Chunk3D <I> GetChunk(Vector3i pos)
 {
     return(chunks.SafeGet(pos));
 }
コード例 #3
0
        //---------------------------------------------------------------------------

        #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;
                }
            }
        }