void Awake() { UnityEngine.Debug.Log("OCWorldGenerator::Awake!"); map = GetComponent <OpenCog.Map.OCMap>(); if (MapName != string.Empty) { //Debug.Log ("In WorldGenerator, MapName defined"); OCFileTerrainGenerator fileTerrainGenerator = new OCFileTerrainGenerator(map, MapName); fileTerrainGenerator.LoadLevel(); } else { terrainGenerator = new OCTerrainGenerator(map); OCBlock[] woodBlocks = map.GetBlockSet().GetBlocks("Wood"); OCBlock[] leavesBlocks = map.GetBlockSet().GetBlocks("Leaves"); treeGenerator = new OCTreeGenerator[Math.Max(woodBlocks.Length, leavesBlocks.Length)]; for (int i = 0; i < treeGenerator.Length; i++) { OCBlock wood = woodBlocks[i % woodBlocks.Length]; OCBlock leaves = leavesBlocks[i % leavesBlocks.Length]; treeGenerator[i] = new OCTreeGenerator(map, wood, leaves); } } }
void Awake() { UnityEngine.Debug.Log("OCWorldGenerator::Awake!"); map = GetComponent <OpenCog.Map.OCMap>(); //map = OCMap.Instance; if (MapName != string.Empty) { //Debug.Log ("In WorldGenerator, MapName defined"); OCFileTerrainGenerator fileTerrainGenerator = new OCFileTerrainGenerator(map, MapName); fileTerrainGenerator.LoadLevel(); } else { terrainGenerator = new OCTerrainGenerator(map); OCBlock[] woodBlocks = map.GetBlockSet().GetBlocks("Wood"); OCBlock[] leavesBlocks = map.GetBlockSet().GetBlocks("Leaves"); treeGenerator = new OCTreeGenerator[Math.Max(woodBlocks.Length, leavesBlocks.Length)]; for (int i = 0; i < treeGenerator.Length; i++) { OCBlock wood = woodBlocks[i % woodBlocks.Length]; OCBlock leaves = leavesBlocks[i % leavesBlocks.Length]; treeGenerator[i] = new OCTreeGenerator(map, wood, leaves); } } TextAsset configFile = (TextAsset)Resources.Load("embodiment"); if (configFile != null) { OCConfig.Instance.LoadFromTextAsset(configFile); } OCConfig.Instance.LoadFromCommandLine(); string testValue = OCConfig.Instance.get("test"); string quitValue = OCConfig.Instance.get("quit"); if (testValue == "internal_XGA") { Screen.SetResolution(1024, 768, false); Console.WriteLine("Level Loaded..."); } if (quitValue == "true") { Application.Quit(); } }
public OCTerrainGenerator(OpenCog.Map.OCMap map) { this.map = map; Debug.Log("OCTerrainGenerator is getting the BlockSet from the Map."); OpenCog.BlockSet.OCBlockSet blockSet = map.GetBlockSet(); Debug.Log("BlockSet retrieved..."); water = blockSet.GetBlock("Water"); grass = blockSet.GetBlock("Grass"); if (grass == null) { Debug.Log("We have no Grass! :("); for (int i = 0; i < blockSet.Blocks.Length; i++) { Debug.Log("But we have " + blockSet.Blocks[i].GetName()); } } dirt = blockSet.GetBlock("Dirt"); sand = blockSet.GetBlock("Sand"); stone = blockSet.GetBlock("Stone"); snow = blockSet.GetBlock("Snow"); ice = blockSet.GetBlock("Ice"); }
public OCTreeGenerator(OpenCog.Map.OCMap map) { this.map = map; OpenCog.BlockSet.OCBlockSet blockSet = map.GetBlockSet(); wood = blockSet.GetBlock("Wood"); leaves = blockSet.GetBlock("Leaves"); }
void Awake() { UnityEngine.Debug.Log ("OCWorldGenerator::Awake!"); map = GetComponent<OpenCog.Map.OCMap>(); //map = OCMap.Instance; if (MapName != string.Empty) { //Debug.Log ("In WorldGenerator, MapName defined"); OCFileTerrainGenerator fileTerrainGenerator = new OCFileTerrainGenerator(map, MapName); fileTerrainGenerator.LoadLevel(); } else { terrainGenerator = new OCTerrainGenerator(map); OCBlock[] woodBlocks = map.GetBlockSet().GetBlocks("Wood"); OCBlock[] leavesBlocks = map.GetBlockSet().GetBlocks("Leaves"); treeGenerator = new OCTreeGenerator[ Math.Max(woodBlocks.Length, leavesBlocks.Length) ]; for(int i=0; i<treeGenerator.Length; i++) { OCBlock wood = woodBlocks[ i%woodBlocks.Length ]; OCBlock leaves = leavesBlocks[ i%leavesBlocks.Length ]; treeGenerator[i] = new OCTreeGenerator(map, wood, leaves); } } TextAsset configFile = (TextAsset)Resources.Load("embodiment"); if(configFile != null) OCConfig.Instance.LoadFromTextAsset(configFile); OCConfig.Instance.LoadFromCommandLine(); string testValue = OCConfig.Instance.get("test"); string quitValue = OCConfig.Instance.get("quit"); if(testValue == "internal_XGA") { Screen.SetResolution(1024, 768, false); Console.WriteLine("Level Loaded..."); } if(quitValue == "true") { Application.Quit(); } }
public void LoadLevel() { int verticalOffset = 85; Debug.Log("About to load level folder: " + _fullMapPath + "."); Substrate.AnvilWorld mcWorld = Substrate.AnvilWorld.Create(_fullMapPath); Substrate.AnvilRegionManager mcAnvilRegionManager = mcWorld.GetRegionManager(); OpenCog.BlockSet.OCBlockSet blockSet = _map.GetBlockSet(); //_map.GetSunLightmap().SetSunHeight(20, 4, 4); int createCount = 0; System.Collections.Generic.Dictionary <int, int> unmappedBlockTypes = new System.Collections.Generic.Dictionary <int, int>(); //Debug.Log("In LoadLevel, there are " + blockSet.BlockCount + " blocks available."); foreach (Substrate.AnvilRegion mcAnvilRegion in mcAnvilRegionManager) { // Loop through x-axis of chunks in this region for (int iMCChunkX = 0; iMCChunkX < mcAnvilRegion.XDim; iMCChunkX++) { // Loop through z-axis of chunks in this region. for (int iMCChunkZ = 0; iMCChunkZ < mcAnvilRegion.ZDim; iMCChunkZ++) { // Retrieve the chunk at the current position in our 2D loop... Substrate.ChunkRef mcChunkRef = mcAnvilRegion.GetChunkRef(iMCChunkX, iMCChunkZ); if (mcChunkRef != null) { if (mcChunkRef.IsTerrainPopulated) { // Ok...now to stick the blocks in... int iMCChunkY = 0; OCChunk chunk = null; //new OCChunk(_map, new Vector3i(iMCChunkX, iMCChunkY, iMCChunkZ)); OCChunk lastChunk = null; Vector3i chunkPos = new Vector3i(mcAnvilRegion.ChunkGlobalX(iMCChunkX), iMCChunkY + verticalOffset, mcAnvilRegion.ChunkGlobalZ(iMCChunkZ)); Vector3i lastChunkPos = Vector3i.zero; chunk = _map.GetChunkInstance(chunkPos); for (int iMCChunkInternalY = 0; iMCChunkInternalY < mcChunkRef.Blocks.YDim; iMCChunkInternalY++) { if (iMCChunkInternalY / OCChunk.SIZE_Y > iMCChunkY) { lastChunk = chunk; lastChunkPos = chunkPos; chunkPos = new Vector3i(mcAnvilRegion.ChunkGlobalX(iMCChunkX), (iMCChunkInternalY + verticalOffset) / OCChunk.SIZE_Y, mcAnvilRegion.ChunkGlobalZ(iMCChunkZ)); chunk = _map.GetChunkInstance(chunkPos); } for (int iMCChunkInternalX = 0; iMCChunkInternalX < mcChunkRef.Blocks.XDim; iMCChunkInternalX++) { for (int iMCChunkInternalZ = 0; iMCChunkInternalZ < mcChunkRef.Blocks.ZDim; iMCChunkInternalZ++) { int iBlockID = mcChunkRef.Blocks.GetID(iMCChunkInternalX, iMCChunkInternalY, iMCChunkInternalZ); if (iBlockID != 0) { Vector3i blockPos = new Vector3i(iMCChunkInternalX, iMCChunkInternalY % OCChunk.SIZE_Y, iMCChunkInternalZ); int ourBlockID = -1; // switch (iBlockID) // { // case 3: // Dirt to first grass // ourBlockID = 1; // break; // case 12: // Grass to grass // ourBlockID = 1; // break; // case 13: // Gravel to stone // ourBlockID = 4; // break; // case 1: // Stone to second stone // ourBlockID = 5; // break; // case 16: // Coal ore to fungus // ourBlockID = 17; // break; // case 15: // Iron ore to pumpkin // ourBlockID = 20; // break; // case 9: // Water to water // ourBlockID = 8; // //Debug.Log ("Creating some water at [" + blockPos.x + ", " + blockPos.y + ", " + blockPos.z + "]"); // break; //// case 2: //// iBlockID = 16; //// break; //// case 4: //// iBlockID = 16; //// break; //// case 18: //// iBlockID = 16; //// break; // default: // { // //Debug.Log ("Unmapped BlockID: " + iBlockID); // // if (!unmappedBlockTypes.ContainsKey (iBlockID)) // { // unmappedBlockTypes.Add (iBlockID, 1); // } // else // { // unmappedBlockTypes[iBlockID] += 1; // } // // break; // } // } if (mcToOCBlockDictionary.ContainsKey(iBlockID)) { ourBlockID = mcToOCBlockDictionary[iBlockID]; } else { if (!unmappedBlockTypes.ContainsKey(iBlockID)) { unmappedBlockTypes.Add(iBlockID, 1); } else { unmappedBlockTypes[iBlockID] += 1; } } if (ourBlockID != -1) { OCBlock newBlock = blockSet.GetBlock(ourBlockID); //OCBlockData block = new OpenCog.Map.OCBlockData(newBlock, blockPos); OCBlockData block = (OCBlockData)OCScriptableObject.CreateInstance <OCBlockData>(); block.Init(newBlock, blockPos); chunk.SetBlock(block, blockPos); OpenCog.Map.Lighting.OCLightComputer.RecomputeLightAtPosition(_map, blockPos); if (block.block.GetName() == "Battery") { GameObject batteryPrefab = OCMap.Instance.BatteryPrefab; if (batteryPrefab == null) { UnityEngine.Debug.Log("OCBuilder::Update, batteryPrefab == null"); } else { GameObject battery = (GameObject)GameObject.Instantiate(batteryPrefab); battery.transform.position = blockPos; battery.name = "Battery"; battery.transform.parent = OCMap.Instance.BatteriesSceneObject.transform; } } if (block.block.GetName() == "Hearth") { GameObject hearthPrefab = OCMap.Instance.HearthPrefab; if (hearthPrefab == null) { UnityEngine.Debug.Log("OCBuilder::Update, hearthPrefab == null"); } else { GameObject hearth = (GameObject)GameObject.Instantiate(hearthPrefab); hearth.transform.position = blockPos; hearth.name = "Hearth"; hearth.transform.parent = OCMap.Instance.HearthsSceneObject.transform; } } createCount += 1; } } } // End for (int iMCChunkInternalZ = 0; iMCChunkInternalZ < mcChunkRef.Blocks.ZDim; iMCChunkInternalZ++) } // End for (int iMCChunkInternalY = 0; iMCChunkInternalY < mcChunkRef.Blocks.YDim; iMCChunkInternalY++) string chunkCoord = chunkPos.x + ", " + chunkPos.z; if (!chunkList.ContainsKey(chunkCoord)) { chunkList.Add(chunkCoord, chunkPos); } if (iMCChunkY < iMCChunkInternalY / OCChunk.SIZE_Y) { _map.Chunks.AddOrReplace(lastChunk, lastChunkPos); _map.UpdateChunkLimits(lastChunkPos); _map.SetDirty(lastChunkPos); iMCChunkY = iMCChunkInternalY / OCChunk.SIZE_Y; } } // End for (int iMCChunkInternalX = 0; iMCChunkInternalX < mcChunkRef.Blocks.XDim; iMCChunkInternalX++) } // End if (mcChunkRef.IsTerrainPopulated) } // End if (mcChunkRef != null) } // End for (int iMCChunkZ = 0; iMCChunkZ < mcAnvilRegion.ZDim; iMCChunkZ++) } // End for (int iMCChunkX = 0; iMCChunkX < mcAnvilRegion.XDim; iMCChunkX++) } // End foreach( Substrate.AnvilRegion mcAnvilRegion in mcAnvilRegionManager ) foreach (Vector3i chunkToLight in chunkList.Values) { OpenCog.Map.Lighting.OCChunkSunLightComputer.ComputeRays(_map, chunkToLight.x, chunkToLight.z); OpenCog.Map.Lighting.OCChunkSunLightComputer.Scatter(_map, null, chunkToLight.x, chunkToLight.z); } foreach (System.Collections.Generic.KeyValuePair <int, int> unmappedBlockData in unmappedBlockTypes) { UnityEngine.Debug.Log("Unmapped BlockID '" + unmappedBlockData.Key + "' found " + unmappedBlockData.Value + " times."); } Debug.Log("Loaded level: " + _fullMapPath + ", created " + createCount + " blocks."); _map.AddColliders(); } // End public void LoadLevel()
public OCTreeGenerator(OpenCog.Map.OCMap map) { this.map = map; OpenCog.BlockSet.OCBlockSet blockSet = map.GetBlockSet(); wood = blockSet.GetBlock("Wood"); leaves = blockSet.GetBlock("Leaves"); }