private static void SetChunkLightDirty(OCMap map, Vector3i chunkPos) {
			OCChunk chunkData = map.GetChunk(chunkPos);
			if(chunkData == null) return;
			OCChunkRenderer chunk = chunkData.GetChunkRenderer();
			if(chunk == null) return;
			chunk.SetLightDirty();
		}
		public static void RecomputeLightAtPosition(OCMap map, Vector3i pos) {
			OCSunLightMap lightmap = map.GetSunLightmap();
			int oldSunHeight = lightmap.GetSunHeight(pos.x, pos.z);
			ComputeRayAtPosition(map, pos.x, pos.z);
			int newSunHeight = lightmap.GetSunHeight(pos.x, pos.z);
			
			if(newSunHeight < oldSunHeight) { // свет опустился
				// добавляем свет
				list.Clear();
	            for (int ty = newSunHeight; ty <= oldSunHeight; ty++) {
					pos.y = ty;
	                lightmap.SetLight(MIN_LIGHT, pos);
	                list.Add( pos );
	            }
	            Scatter(map, list);
			}
			if(newSunHeight > oldSunHeight) { // свет поднялся
				// удаляем свет
				list.Clear();
	            for (int ty = oldSunHeight; ty <= newSunHeight; ty++) {
					pos.y = ty;
					list.Add( pos );
	            }
	            RemoveLight(map, list);
			}
			
			if(newSunHeight == oldSunHeight) {
				if( map.GetBlock(pos).IsAlpha() ) {
					UpdateLight(map, pos);
				} else {
					RemoveLight(map, pos);
				}
			}
		}
		private static void UpdateLight(OCMap map, Vector3i pos) {
	        list.Clear();
			foreach(Vector3i dir in Vector3i.directions) {
				list.Add( pos + dir );
			}
	        Scatter(map, list);
		}
        public static void Scatter(OCMap map, OCColumnMap columnMap, int cx, int cz)
        {
            int x1 = cx * OCChunk.SIZE_X;
            int z1 = cz * OCChunk.SIZE_Z;

            int x2 = x1 + OCChunk.SIZE_X;
            int z2 = z1 + OCChunk.SIZE_Z;

            OCSunLightMap lightmap = map.GetSunLightmap();

            list.Clear();
            for (int x = x1; x < x2; x++)
            {
                for (int z = z1; z < z2; z++)
                {
                    int maxY = ComputeMaxY(lightmap, x, z) + 1;
                    for (int y = 0; y < maxY; y++)
                    {
                        if (lightmap.GetLight(x, y, z) > MIN_LIGHT)
                        {
                            list.Add(new Vector3i(x, y, z));
                        }
                    }
                }
            }
            Scatter(map, columnMap, list);
        }
Beispiel #5
0
        public static void SetLightDirty(OCMap map, Vector3i pos)
        {
            Vector3i chunkPos = OCChunk.ToChunkPosition(pos);
            Vector3i localPos = OCChunk.ToLocalPosition(pos);

            SetChunkLightDirty(map, chunkPos);

            if (localPos.x == 0)
            {
                SetChunkLightDirty(map, chunkPos - Vector3i.right);
            }
            if (localPos.y == 0)
            {
                SetChunkLightDirty(map, chunkPos - Vector3i.up);
            }
            if (localPos.z == 0)
            {
                SetChunkLightDirty(map, chunkPos - Vector3i.forward);
            }

            if (localPos.x == OCChunk.SIZE_X - 1)
            {
                SetChunkLightDirty(map, chunkPos + Vector3i.right);
            }
            if (localPos.y == OCChunk.SIZE_Y - 1)
            {
                SetChunkLightDirty(map, chunkPos + Vector3i.up);
            }
            if (localPos.z == OCChunk.SIZE_Z - 1)
            {
                SetChunkLightDirty(map, chunkPos + Vector3i.forward);
            }
        }
        private static void Scatter(OCMap map, List <Vector3i> list)          // рассеивание
        {
            OCSunLightMap lightmap = map.GetSunLightmap();

            for (int i = 0; i < list.Count; i++)
            {
                Vector3i pos = list[i];
                if (pos.y < 0)
                {
                    continue;
                }

                OCBlockData block = map.GetBlock(pos);
                int         light = lightmap.GetLight(pos) - OCLightComputerUtils.GetLightStep(block);
                if (light <= MIN_LIGHT)
                {
                    continue;
                }

                foreach (Vector3i dir in Vector3i.directions)
                {
                    Vector3i nextPos = pos + dir;
                    block = map.GetBlock(nextPos);
                    if (block.IsAlpha() && lightmap.SetMaxLight((byte)light, nextPos))
                    {
                        list.Add(nextPos);
                    }
                    if (!block.IsEmpty())
                    {
                        OCLightComputerUtils.SetLightDirty(map, nextPos);
                    }
                }
            }
        }
        //---------------------------------------------------------------------------

        #region Private Member Data

        //---------------------------------------------------------------------------



        //---------------------------------------------------------------------------

        #endregion

        //---------------------------------------------------------------------------

        #region Accessors and Mutators

        //---------------------------------------------------------------------------



        //---------------------------------------------------------------------------

        #endregion

        //---------------------------------------------------------------------------

        #region Public Member Functions

        //---------------------------------------------------------------------------

        public void TransferBlock(Vector3i?origin, Vector3i?destination)
        {
            if (origin.HasValue && destination.HasValue)
            {
                OCMap map = OCMap.Instance;                //(OCMap)GameObject.FindSceneObjectsOfType(typeof(OCMap)).FirstOrDefault();

                OCGoalController[] goalControllers = (OCGoalController[])GameObject.FindObjectsOfType(typeof(OCGoalController));

                foreach (Transform battery in map.BatteriesSceneObject.transform)
                {
                    if (VectorUtil.AreVectorsEqual(battery.position, new Vector3((float)origin.Value.x, (float)origin.Value.y, (float)origin.Value.z)))
                    {
                        battery.position = new Vector3((float)destination.Value.x, (float)destination.Value.y, (float)destination.Value.z);
                    }
                }

                OCBlockData block = map.GetBlock(origin.Value);

                map.SetBlockAndRecompute(block, destination.Value);
                map.SetBlockAndRecompute(OCBlockData.CreateInstance <OCBlockData>().Init(null, origin.Value), origin.Value);

                foreach (OCGoalController goalController in goalControllers)
                {
                    if (goalController.GoalBlockType == block.block)
                    {
                        goalController.FindGoalBlockPositionInChunks(map.GetChunks());
                    }
                }
            }
        }
Beispiel #8
0
        //NOTE: this function pulls the weight of actually destroying blocks for us. It is applied to the OCActions of a character; not to blocks themselves.
        public void DestroyBlock(Vector3i?point)
        {
            if (point.HasValue)
            {
                OCMap map = OCMap.Instance;        //(OCMap)GameObject.FindSceneObjectsOfType(typeof(OCMap)).FirstOrDefault();

                //for updating goal controllers after deletion.
                OCBlock            blockType       = map.GetBlock(point.Value).block;
                OCGoalController[] goalControllers = (OCGoalController[])GameObject.FindObjectsOfType(typeof(OCGoalController));

                //actually sets the block to null and recomputes the chunk.
                Debug.Log(OCLogSymbol.DEBUG + "DeleteSelectedVoxel called from CreateBlockEffect");
                GameManager.world.voxels.DeleteSelectedVoxel(point.Value);

                //re-update goals concerned with this block type
                foreach (OCGoalController goalController in goalControllers)
                {
                    if (goalController.GoalBlockType == blockType)
                    {
                        goalController.FindGoalBlockPositionInChunks(map.GetChunks());
                    }
                }

                blocksDestroyed++;
            }
        }
		private static void Scatter(OCMap map, List<Vector3i> list) { // рассеивание
			OCLightMap lightmap = map.GetLightmap();
			
			foreach( Vector3i pos in list ) {
				byte light = map.GetBlock(pos).GetLight();
				if(light > MIN_LIGHT) lightmap.SetMaxLight(light, pos);
			}
			
	        for(int i=0; i<list.Count; i++) {
	            Vector3i pos = list[i];
				if(pos.y<0) continue;
				
				OCBlockData block = map.GetBlock(pos);
	            int light = lightmap.GetLight(pos) - OCLightComputerUtils.GetLightStep(block);
	            if(light <= MIN_LIGHT) continue;
				
	            foreach(Vector3i dir in Vector3i.directions) {
					Vector3i nextPos = pos + dir;
					block = map.GetBlock(nextPos);
	                if( block.IsAlpha() && lightmap.SetMaxLight((byte)light, nextPos) ) {
	                	list.Add( nextPos );
	                }
					if(!block.IsEmpty()) OCLightComputerUtils.SetLightDirty(map, nextPos);
	            }
	        }
	    }
Beispiel #10
0
        //---------------------------------------------------------------------------

        #region Private Member Data

        //---------------------------------------------------------------------------



        //---------------------------------------------------------------------------

        #endregion

        //---------------------------------------------------------------------------

        #region Accessors and Mutators

        //---------------------------------------------------------------------------



        //---------------------------------------------------------------------------

        #endregion

        //---------------------------------------------------------------------------

        #region Public Member Functions

        //---------------------------------------------------------------------------

        public void DestroyBlock(Vector3i?point)
        {
            if (point.HasValue)
            {
                OCMap map = (OCMap)GameObject.FindSceneObjectsOfType(typeof(OCMap)).FirstOrDefault();
                map.SetBlockAndRecompute(new OpenCog.Map.OCBlockData(), point.Value);
            }
        }
Beispiel #11
0
        private static void RemoveLight(OCMap map, List <Vector3i> list)
        {
            OCLightMap lightmap = map.GetLightmap();

            foreach (Vector3i pos in list)
            {
                lightmap.SetLight(MAX_LIGHT, pos);
            }

            List <Vector3i> lightPoints = new List <Vector3i>();

            for (int i = 0; i < list.Count; i++)
            {
                Vector3i pos = list[i];
                if (pos.y < 0)
                {
                    continue;
                }

                int light = lightmap.GetLight(pos) - STEP_LIGHT;

                lightmap.SetLight(MIN_LIGHT, pos);
                if (light <= MIN_LIGHT)
                {
                    continue;
                }

                foreach (Vector3i dir in Vector3i.directions)
                {
                    Vector3i    nextPos = pos + dir;
                    OCBlockData block   = map.GetBlock(nextPos);

                    if (block.IsAlpha())
                    {
                        if (lightmap.GetLight(nextPos) <= light)
                        {
                            list.Add(nextPos);
                        }
                        else
                        {
                            lightPoints.Add(nextPos);
                        }
                    }
                    if (block.GetLight() > MIN_LIGHT)
                    {
                        lightPoints.Add(nextPos);
                    }

                    if (!block.IsEmpty())
                    {
                        OCLightComputerUtils.SetLightDirty(map, nextPos);
                    }
                }
            }


            Scatter(map, lightPoints);
        }
            //---------------------------------------------------------------------------

            #endregion

            //---------------------------------------------------------------------------

            #region Public Member Functions

            //---------------------------------------------------------------------------

            public void Start()
            {
                _AnimationEffects =
                    gameObject.GetComponentsInChildren <OCAnimationEffect>().ToList();

                _CreateBlockEffects =
                    gameObject.GetComponentsInChildren <OCCreateBlockEffect>().ToList();

                _DestroyBlockEffects =
                    gameObject.GetComponentsInChildren <OCDestroyBlockEffect>().ToList();

                _Map = (OCMap)GameObject.FindSceneObjectsOfType(typeof(OCMap)).LastOrDefault();

                _ActionController = _Source.GetComponent <OCActionController>();

//		foreach(OCDelegate del in _Preconditions)
//		{
//			PreCondition += (OCActionCondition)del.Delegate;
//		}
//
//		foreach(OCDelegate del in _Invariants)
//		{
//			InvariantCondition += (OCActionCondition)del.Delegate;
//		}
//
//		foreach(OCDelegate del in _Postconditions)
//		{
//			PostCondition += (OCActionCondition)del.Delegate;
//		}

                foreach (string condition in _Preconditions)
                {
                    PreCondition += (OCActionCondition)Delegate.CreateDelegate(typeof(OCActionCondition), typeof(OCAction).GetMethod(condition));
                }

                foreach (string condition in _Invariants)
                {
                    InvariantCondition += (OCActionCondition)Delegate.CreateDelegate(typeof(OCActionCondition), typeof(OCAction).GetMethod(condition));
                }

                foreach (string condition in _Postconditions)
                {
                    PostCondition += (OCActionCondition)Delegate.CreateDelegate(typeof(OCActionCondition), typeof(OCAction).GetMethod(condition));
                }

//		PreCondition += IsEndTarget;
//		InvariantCondition += IsSourceAnimating;
//		InvariantCondition += IsSourceNotRunningOtherActionsIgnoreIdle;
//		PostCondition += IsSourceRunningOtherActionsIgnoreIdle;

//		if(_EndTarget == null)
//			_EndTarget = GameObject.Find("EndPointStub");
//		if(_StartTarget == null)
//			_StartTarget = GameObject.Find("StartPointStub");

                DontDestroyOnLoad(this);
            }
 private static void UpdateLight(OCMap map, Vector3i pos)
 {
     list.Clear();
     foreach (Vector3i dir in Vector3i.directions)
     {
         list.Add(pos + dir);
     }
     Scatter(map, list);
 }
        //---------------------------------------------------------------------------

        #endregion

        //---------------------------------------------------------------------------

        #region Public Member Functions

        //---------------------------------------------------------------------------

        public IEnumerator Start()
        {
            _map = (OCMap)GameObject.FindObjectOfType(typeof(OCMap));

            _goalBlockType = _map.GetBlockSet().GetBlock(_blockType);


            while (Application.isPlaying)
            {
                yield return(new WaitForSeconds(1.0f));

                UpdateGoal();
            }
        }
Beispiel #15
0
        //---------------------------------------------------------------------------

        #endregion

        //---------------------------------------------------------------------------

        #region Accessors and Mutators

        //---------------------------------------------------------------------------



        //---------------------------------------------------------------------------

        #endregion

        //---------------------------------------------------------------------------

        #region Public Member Functions

        //---------------------------------------------------------------------------

        public void CreateBlock(Vector3i?point)
        {
            if (point.HasValue)
            {
                OCMap map = (OCMap)GameObject.FindSceneObjectsOfType(typeof(OCMap)).FirstOrDefault();

                OCBlock block = map.GetBlockSet().GetBlock(_BlockType);

                //block.SetDirection(GetDirection(-gameObject.transform.forward));

                OCBlockData blockData = new OCBlockData(block, VectorUtil.Vector3ToVector3i(point.Value));
                map.SetBlockAndRecompute(blockData, point.Value);
            }
        }
		public static void SetLightDirty(OCMap map, Vector3i pos) {
			Vector3i chunkPos = OCChunk.ToChunkPosition(pos);
			Vector3i localPos = OCChunk.ToLocalPosition(pos);
			
			SetChunkLightDirty(map, chunkPos);
			
			if(localPos.x == 0) SetChunkLightDirty(map, chunkPos-Vector3i.right);
			if(localPos.y == 0) SetChunkLightDirty(map, chunkPos-Vector3i.up);
			if(localPos.z == 0) SetChunkLightDirty(map, chunkPos-Vector3i.forward);
			
			if(localPos.x == OCChunk.SIZE_X-1) SetChunkLightDirty(map, chunkPos+Vector3i.right);
			if(localPos.y == OCChunk.SIZE_Y-1) SetChunkLightDirty(map, chunkPos+Vector3i.up);
			if(localPos.z == OCChunk.SIZE_Z-1) SetChunkLightDirty(map, chunkPos+Vector3i.forward);
		}
		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);
					}
				}
			}
		}
            public static bool IsPathOpenForSourceForwardBlockSolid(OCAction action, OCActionArgs args)
            {
                OCMap map = (OCMap)GameObject.FindObjectOfType(typeof(OCMap));

                CharacterController charController =
                    args.Source.GetComponent <CharacterController>();

                return
                    (map.IsPathOpen
                         (args.Source.transform
                         , charController.height
                         , OCMap.PathDirection.ForwardBlockSolid
                         )
                    );
            }
Beispiel #19
0
        public static void RecomputeLightAtPosition(OCMap map, Vector3i pos)
        {
            OpenCog.Map.Lighting.OCLightMap lightmap = map.GetLightmap();
            int oldLight = lightmap.GetLight(pos);
            int light    = map.GetBlock(pos).GetLight();

            if (oldLight > light)
            {
                RemoveLight(map, pos);
            }
            if (light > MIN_LIGHT)
            {
                Scatter(map, pos);
            }
        }
        public static void ComputeRays(OCMap map, int cx, int cz)
        {
            int x1 = cx * OCChunk.SIZE_X - 1;
            int z1 = cz * OCChunk.SIZE_Z - 1;

            int x2 = x1 + OCChunk.SIZE_X + 2;
            int z2 = z1 + OCChunk.SIZE_Z + 2;

            for (int z = z1; z < z2; z++)
            {
                for (int x = x1; x < x2; x++)
                {
                    OCSunLightComputer.ComputeRayAtPosition(map, x, z);
                }
            }
        }
Beispiel #21
0
        private static void SetChunkLightDirty(OCMap map, Vector3i chunkPos)
        {
            OCChunk chunkData = map.GetChunk(chunkPos);

            if (chunkData == null)
            {
                return;
            }
            OCChunkRenderer chunk = chunkData.GetChunkRenderer();

            if (chunk == null)
            {
                return;
            }
            chunk.SetLightDirty();
        }
		public static void RecomputeLightAtPosition(OCMap map, Vector3i pos) 
		{
			if(map.GetBlock(pos) != null && !map.GetBlock(pos).IsEmpty())
			{
				OpenCog.Map.Lighting.OCLightMap lightmap = map.GetLightmap();
				int oldLight = lightmap.GetLight(pos);
				int light = map.GetBlock(pos).GetLight();
				
				if(oldLight > light) {
					RemoveLight(map, pos);
				}
				if(light > MIN_LIGHT) {
					Scatter(map, pos);
				}
			}
		}
        public static void RecomputeLightAtPosition(OCMap map, Vector3i pos)
        {
            OCSunLightMap lightmap     = map.GetSunLightmap();
            int           oldSunHeight = lightmap.GetSunHeight(pos.x, pos.z);

            ComputeRayAtPosition(map, pos.x, pos.z);
            int newSunHeight = lightmap.GetSunHeight(pos.x, pos.z);

            if (newSunHeight < oldSunHeight)              // свет опустился
            // добавляем свет
            {
                list.Clear();
                for (int ty = newSunHeight; ty <= oldSunHeight; ty++)
                {
                    pos.y = ty;
                    lightmap.SetLight(MIN_LIGHT, pos);
                    list.Add(pos);
                }
                Scatter(map, list);
            }
            if (newSunHeight > oldSunHeight)              // свет поднялся
            // удаляем свет
            {
                list.Clear();
                for (int ty = oldSunHeight; ty <= newSunHeight; ty++)
                {
                    pos.y = ty;
                    list.Add(pos);
                }
                RemoveLight(map, list);
            }

            if (newSunHeight == oldSunHeight)
            {
                if (map.GetBlock(pos).IsAlpha())
                {
                    UpdateLight(map, pos);
                }
                else
                {
                    RemoveLight(map, pos);
                }
            }
        }
Beispiel #24
0
        //---------------------------------------------------------------------------

        #endregion

        //---------------------------------------------------------------------------

        #region Public Member Functions

        //---------------------------------------------------------------------------

        public IEnumerator Start()
        {
            _map = OCMap.Instance;    //(OCMap)GameObject.FindObjectOfType (typeof(OCMap));

            _goalBlockType = _map.GetBlockSet().GetBlock(_blockType);

            List3D <OCChunk> chunks = _map.GetChunks();

            // Since this is probably bogging down the gameplay, switch it to block creation only.
            FindGoalBlockPositionInChunks(chunks);

            while (Application.isPlaying)
            {
                yield return(new WaitForSeconds(1.0f));

                UpdateGoal();
            }
//		yield return 0;
        }
Beispiel #25
0
        //---------------------------------------------------------------------------

        #region Private Member Data

        //---------------------------------------------------------------------------



        //---------------------------------------------------------------------------

        #endregion

        //---------------------------------------------------------------------------

        #region Accessors and Mutators

        //---------------------------------------------------------------------------



        //---------------------------------------------------------------------------

        #endregion

        //---------------------------------------------------------------------------

        #region Public Member Functions

        //---------------------------------------------------------------------------

        public void DestroyBlock(Vector3i?point)
        {
            if (point.HasValue)
            {
                OCMap map = OCMap.Instance;        //(OCMap)GameObject.FindSceneObjectsOfType(typeof(OCMap)).FirstOrDefault();

                OCGoalController[] goalControllers = (OCGoalController[])GameObject.FindObjectsOfType(typeof(OCGoalController));

                OCBlock blockType = map.GetBlock(point.Value).block;

                map.SetBlockAndRecompute(OCBlockData.CreateInstance <OCBlockData>().Init(null, point.Value), point.Value);

                foreach (OCGoalController goalController in goalControllers)
                {
                    if (goalController.GoalBlockType == blockType)
                    {
                        goalController.FindGoalBlockPositionInChunks(map.GetChunks());
                    }
                }
            }
        }
Beispiel #26
0
        //---------------------------------------------------------------------------

        #endregion

        //---------------------------------------------------------------------------

        #region Public Member Functions

        //---------------------------------------------------------------------------

        public void CreateBlock(Vector3i?point)
        {
            if (point.HasValue)
            {
                OCMap map = OCMap.Instance;        //(OCMap)GameObject.FindSceneObjectsOfType(typeof(OCMap)).FirstOrDefault();

                OCBlock block = map.GetBlockSet().GetBlock(_BlockType);

                OCGoalController[] goalControllers = (OCGoalController[])GameObject.FindObjectsOfType(typeof(OCGoalController));

                foreach (OCGoalController goalController in goalControllers)
                {
                    if (goalController.GoalBlockType == block)
                    {
                        goalController.FindGoalBlockPositionInChunks(map.GetChunks());
                    }
                }

                Debug.Log(OCLogSymbol.DEBUG + "AddSelectedVoxel called from CreateBlockEffect");
                GameManager.world.voxels.AddSelectedVoxel(point.Value, -transform.forward, block);
            }
        }
		private static void RemoveLight(OCMap map, List<Vector3i> list) {
			OCLightMap lightmap = map.GetLightmap();
			foreach(Vector3i pos in list) {
				lightmap.SetLight(MAX_LIGHT, pos);
			}
			
			List<Vector3i> lightPoints = new List<Vector3i>();
			for(int i=0; i<list.Count; i++) {
	            Vector3i pos = list[i];
				if(pos.y<0) continue;
				
				int light = lightmap.GetLight(pos) - STEP_LIGHT;
				
				lightmap.SetLight(MIN_LIGHT, pos);
	            if (light <= MIN_LIGHT) continue;
				
				foreach(Vector3i dir in Vector3i.directions) {
					Vector3i nextPos = pos + dir;
					OCBlockData block = map.GetBlock(nextPos);
					
					if(block.IsAlpha()) {
						if(lightmap.GetLight(nextPos) <= light) {
							list.Add( nextPos );
						} else {
							lightPoints.Add( nextPos );
						}
					}
					if(block.GetLight() > MIN_LIGHT) {
						lightPoints.Add( nextPos );
					}
					
					if(!block.IsEmpty()) OCLightComputerUtils.SetLightDirty(map, nextPos);
				}	
			}
			
			
	        Scatter(map, lightPoints);
	    }
Beispiel #28
0
        //---------------------------------------------------------------------------

        #endregion

        //---------------------------------------------------------------------------

        #region Public Member Functions

        //---------------------------------------------------------------------------

        public void CreateBlock(Vector3i?point)
        {
            if (point.HasValue)
            {
                OCMap map = OCMap.Instance;                //(OCMap)GameObject.FindSceneObjectsOfType(typeof(OCMap)).FirstOrDefault();

                OCBlock block = map.GetBlockSet().GetBlock(_BlockType);

                OCGoalController[] goalControllers = (OCGoalController[])GameObject.FindObjectsOfType(typeof(OCGoalController));

                foreach (OCGoalController goalController in goalControllers)
                {
                    if (goalController.GoalBlockType == block)
                    {
                        goalController.FindGoalBlockPositionInChunks(map.GetChunks());
                    }
                }

                //block.SetDirection(GetDirection(-gameObject.transform.forward));

                OCBlockData blockData = OCBlockData.CreateInstance <OCBlockData>().Init(block, VectorUtil.Vector3ToVector3i(point.Value));
                map.SetBlockAndRecompute(blockData, point.Value);
            }
        }
		public static void ComputeRayAtPosition(OCMap map, int x, int z) {
			int maxY = map.GetMaxY( x, z );
			
			map.GetSunLightmap().SetSunHeight(maxY+1, x, z);
		}
		public static void Scatter(OCMap map, OCColumnMap columnMap, int cx, int cz) {
			int x1 = cx*OCChunk.SIZE_X;
			int z1 = cz*OCChunk.SIZE_Z;
			
			int x2 = x1+OCChunk.SIZE_X;
			int z2 = z1+OCChunk.SIZE_Z;
			
			OCSunLightMap lightmap = map.GetSunLightmap();
			list.Clear();
			for(int x=x1; x<x2; x++) {
				for(int z=z1; z<z2; z++) {
					int maxY = ComputeMaxY(lightmap, x, z)+1;
					for(int y=0; y<maxY; y++) {
						if(lightmap.GetLight(x, y, z) > MIN_LIGHT) {
							list.Add( new Vector3i(x, y, z) );
						}
					}
				}
			}
			Scatter(map, columnMap, list);
		}
        public static void ComputeRayAtPosition(OCMap map, int x, int z)
        {
            int maxY = map.GetMaxY(x, z);

            map.GetSunLightmap().SetSunHeight(maxY + 1, x, z);
        }
 private static void RemoveLight(OCMap map, Vector3i pos)
 {
     list.Clear();
     list.Add(pos);
     RemoveLight(map, list);
 }
		private static void Scatter(OCMap map, OCColumnMap columnMap, List<Vector3i> list) { // рассеивание
			OCSunLightMap lightmap = map.GetSunLightmap();
	        for(int i=0; i<list.Count; i++) {
	            Vector3i pos = list[i];
				if(pos.y<0) continue;
				
				OCBlockData block = map.GetBlock(pos);
				int light = lightmap.GetLight(pos) - OCLightComputerUtils.GetLightStep(block);
	            if(light <= MIN_LIGHT) continue;
				
				Vector3i chunkPos = OCChunk.ToChunkPosition(pos);
				if(columnMap != null && !columnMap.IsBuilt(chunkPos.x, chunkPos.z)) continue;
				
	            foreach(Vector3i dir in Vector3i.directions) {
					Vector3i nextPos = pos + dir;
					block = map.GetBlock(nextPos);
	                if(block != null && block.IsAlpha() && lightmap.SetMaxLight((byte)light, nextPos) ) {
	                	list.Add( nextPos );
	                }
					if(block != null && !block.IsEmpty()) OCLightComputerUtils.SetLightDirty(map, nextPos);
	            }
	        }
	    }
		private static void Scatter(OCMap map, Vector3i pos) {
			list.Clear();
			list.Add( pos );
			Scatter(map, list);
		}
	//---------------------------------------------------------------------------

	#endregion

	//---------------------------------------------------------------------------

	#region Public Member Functions

	//---------------------------------------------------------------------------
		
	public IEnumerator Start()
	{
		_map = OCMap.Instance;//(OCMap)GameObject.FindObjectOfType (typeof(OCMap));
			
		_goalBlockType = 	_map.GetBlockSet().GetBlock(_blockType);
				
		List3D<OCChunk> chunks = _map.GetChunks ();
			
		// Since this is probably bogging down the gameplay, switch it to block creation only.
		FindGoalBlockPositionInChunks(chunks);
			
		while (Application.isPlaying) 
		{
			yield return new WaitForSeconds (1.0f);
			UpdateGoal();
		}
//		yield return 0;
	}
	//---------------------------------------------------------------------------

	#endregion

	//---------------------------------------------------------------------------

	#region Public Member Functions

	//---------------------------------------------------------------------------

	public void Start()
	{
		_AnimationEffects = 
			gameObject.GetComponentsInChildren<OCAnimationEffect>().ToList();

		_CreateBlockEffects =
			gameObject.GetComponentsInChildren<OCCreateBlockEffect>().ToList();

		_DestroyBlockEffects =
			gameObject.GetComponentsInChildren<OCDestroyBlockEffect>().ToList();

		_TransferBlockEffects =
			gameObject.GetComponentsInChildren<OCTransferBlockEffect>().ToList();

		_Map = OCMap.Instance;//(OCMap)GameObject.FindSceneObjectsOfType(typeof(OCMap)).LastOrDefault();

		_ActionController = _Source.GetComponent<OCActionController>();

//		foreach(OCDelegate del in _Preconditions)
//		{
//			PreCondition += (OCActionCondition)del.Delegate;
//		}
//
//		foreach(OCDelegate del in _Invariants)
//		{
//			InvariantCondition += (OCActionCondition)del.Delegate;
//		}
//
//		foreach(OCDelegate del in _Postconditions)
//		{
//			PostCondition += (OCActionCondition)del.Delegate;
//		}

		foreach(string condition in _Preconditions)
		{
			PreCondition += (OCActionCondition)Delegate.CreateDelegate(typeof(OCActionCondition), typeof(OCAction).GetMethod(condition));
		}

		foreach(string condition in _Invariants)
		{
			InvariantCondition += (OCActionCondition)Delegate.CreateDelegate(typeof(OCActionCondition), typeof(OCAction).GetMethod(condition));
		}

		foreach(string condition in _Postconditions)
		{
			PostCondition += (OCActionCondition)Delegate.CreateDelegate(typeof(OCActionCondition), typeof(OCAction).GetMethod(condition));
		}

//		PreCondition += IsEndTarget;
//		InvariantCondition += IsSourceAnimating;
//		InvariantCondition += IsSourceNotRunningOtherActionsIgnoreIdle;
//		PostCondition += IsSourceRunningOtherActionsIgnoreIdle;
				
//		if(_EndTarget == null)
//			_EndTarget = GameObject.Find("EndPointStub");
//		if(_StartTarget == null)
//			_StartTarget = GameObject.Find("StartPointStub");
				
		DontDestroyOnLoad(this);
	}
Beispiel #37
0
 protected OCMap GetMap()
 {
     //get the map instance!
     _map = OCMap.Instance;
     return(_map);
 }
		public static void ComputeRays(OCMap map, int cx, int cz) {
			int x1 = cx*OCChunk.SIZE_X-1;
			int z1 = cz*OCChunk.SIZE_Z-1;
			
			int x2 = x1+OCChunk.SIZE_X+2;
			int z2 = z1+OCChunk.SIZE_Z+2;
			
			for(int z=z1; z<z2; z++) {
				for(int x=x1; x<x2; x++) {
					OCSunLightComputer.ComputeRayAtPosition(map, x, z);
				}
			}
		}
		private static void RemoveLight(OCMap map, Vector3i pos) {
	        list.Clear();
			list.Add(pos);
	        RemoveLight(map, list);
	    }
Beispiel #40
0
 private static void Scatter(OCMap map, Vector3i pos)
 {
     list.Clear();
     list.Add(pos);
     Scatter(map, list);
 }