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); } } } }
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); } } }
//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++; } }
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); } } }
//--------------------------------------------------------------------------- #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()); } } } }
public void UpdateGoal() { //List3D<OCChunk> chunks = _map.GetChunks (); // Since this is probably bogging down the gameplay, switch it to block creation only. //FindGoalBlockPositionInChunks(chunks); Vector3 sourcePos = gameObject.transform.position; Vector3 distanceVec = ((Vector3)GoalBlockPos) - sourcePos; float integrityChange = _goalNameToChangeRatePerSecond["Integrity"] / (distanceVec.magnitude * _distanceAttenuation); integrityChange = integrityChange / 10; UnityEngine.GameObject[] agiArray = UnityEngine.GameObject.FindGameObjectsWithTag("OCAGI"); if (integrityChange > 0.04) { for (int iAGI = 0; iAGI < agiArray.Length; iAGI++) { UnityEngine.GameObject agiObject = agiArray[iAGI]; OpenCog.Embodiment.OCPhysiologicalModel agiPhysModel = agiObject.GetComponent <OpenCog.Embodiment.OCPhysiologicalModel>(); OpenCog.Embodiment.OCPhysiologicalEffect nearHomeEffect = OCPhysiologicalEffect.CreateInstance <OCPhysiologicalEffect>(); nearHomeEffect.CostLevelProp = OpenCog.Embodiment.OCPhysiologicalEffect.CostLevel.NONE; nearHomeEffect.FitnessChange = integrityChange; //UnityEngine.Debug.Log ("Increasing Integrity by '" + integrityChange.ToString() + "'"); agiPhysModel.ProcessPhysiologicalEffect(nearHomeEffect); } } if (GoalBlockPos != Vector3i.zero && _map.GetBlock(GoalBlockPos).IsEmpty()) { OpenCog.Utility.Console.Console console = OpenCog.Utility.Console.Console.Instance; console.AddConsoleEntry("I perceive no more " + _goalBlockType.GetName() + " blocks in my world.", "AGI Robot", OpenCog.Utility.Console.Console.ConsoleEntry.Type.SAY); System.Console.WriteLine(OCLogSymbol.RUNNING + "No more " + _goalBlockType.GetName() + " are reported"); GoalBlockPos = Vector3i.zero; OCAction[] actions = gameObject.GetComponentsInChildren <OCAction>(); foreach (OCAction action in actions) { if (action.EndTarget != null) { action.EndTarget.transform.position = Vector3.zero; } if (action.StartTarget != null) { action.StartTarget.transform.position = Vector3.zero; } } } }
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); }
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); } } }
//--------------------------------------------------------------------------- #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()); } } } }
private ActionStatus EndAction() { //OCLogger.Debugging("Ending the " + FullName + " Action."); OCActionArgs args = null; if (_ActionController.Step != null) { args = _ActionController.Step.Arguments; } if (_blockOnFail && _blockOnRunning) { _ActionController.RunningActions.Remove(FullName); } // End animation effects // foreach(OCAnimationEffect afx in _AnimationEffects) // { // afx.Stop(); // } foreach (OCDestroyBlockEffect dbfx in _DestroyBlockEffects) { Vector3i forward = VectorUtil.Vector3ToVector3i(_Source.transform.position + _Source.transform.forward); Vector3i forwardUp = VectorUtil.Vector3ToVector3i(_Source.transform.position + _Source.transform.forward + _Source.transform.up); Vector3i forwardUp2x = VectorUtil.Vector3ToVector3i(_Source.transform.position + _Source.transform.forward + 2 * _Source.transform.up); OCBlockData forwardBlock = _Map.GetBlock(forward); OCBlockData forwardUpBlock = _Map.GetBlock(forwardUp); OCBlockData forwardUp2xBlock = _Map.GetBlock(forwardUp2x); dbfx.DestroyBlock(forward); dbfx.DestroyBlock(forwardUp); dbfx.DestroyBlock(forwardUp2x); args.EndTarget.transform.position = Vector3.zero; args.StartTarget.transform.position = Vector3.zero; // This is just some example code for you Lake, that you can use to give energy to the robot after consuming a battery. if ((forwardBlock.block != null && forwardBlock.block.GetName() == "Battery") || (forwardUpBlock.block != null && forwardUpBlock.block.GetName() == "Battery") || (forwardUp2xBlock.block != null && forwardUp2xBlock.block.GetName() == "Battery")) { UnityEngine.GameObject[] agiArray = UnityEngine.GameObject.FindGameObjectsWithTag("OCAGI"); for (int iAGI = 0; iAGI < agiArray.Length; iAGI++) { UnityEngine.GameObject agiObject = agiArray[iAGI]; //args.EndTarget = agiObject; OCPhysiologicalModel agiPhysModel = agiObject.GetComponent <OCPhysiologicalModel>(); OCPhysiologicalEffect batteryEatEffect = new OCPhysiologicalEffect(OCPhysiologicalEffect.CostLevel.NONE); batteryEatEffect.EnergyIncrease = 0.2f; agiPhysModel.ProcessPhysiologicalEffect(batteryEatEffect); break; } } } //@TODO: Fix this hack... if (Descriptors.Contains("Jump") || Descriptors.Contains("Climb") || Descriptors.Contains("Fall")) { OCCharacterMotor motor = _Source.GetComponent <OCCharacterMotor>(); motor.enabled = true; } if (!Descriptors.Contains("Idle")) { Debug.LogWarning("Ending Action: " + FullName); } // if(args.ActionPlanID != null) // OCConnectorSingleton.Instance.SendActionStatus(args.ActionPlanID, args.SequenceID, args.ActionName, true); return(ActionStatus.SUCCESS); }
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); }
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); } } }
//--------------------------------------------------------------------------- #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; } } }