// CSClodMgr void OnDirtyVoxel(Vector3 pos, byte terrainType) { #if NEW_CLOD_MGR foreach (KeyValuePair <int, CSCreator> kvp in m_Creators) { CSMgCreator mgCreator = kvp.Value as CSMgCreator; if (mgCreator == null) { continue; } if (mgCreator.Assembly != null && mgCreator.Assembly.InLargestRange(pos) && mgCreator.m_Clod != null) { RaycastHit rch; Vector3 realPos = Vector3.zero; if (Physics.Raycast(pos + new Vector3(0, 1, 0), Vector3.down, out rch, 2, 1 << Pathea.Layer.VFVoxelTerrain)) { realPos = rch.point; } else { realPos = pos; } if (!FarmManager.Instance.mPlantHelpMap.ContainsKey(new IntVec3(pos))) { mgCreator.m_Clod.AddClod(realPos, false); } else { mgCreator.m_Clod.AddClod(realPos, true); } } } #else CSMgCreator creator = GetCreator(CSConst.ciDefMgCamp) as CSMgCreator; if (creator.Assembly != null && creator.Assembly.InRange(pos)) { RaycastHit rch; Vector3 realPos = Vector3.zero; if (Physics.Raycast(pos + new Vector3(0, 1, 0), Vector3.down, out rch, 2, 1 << Pathea.Layer.VFVoxelTerrain)) { realPos = rch.point; } else { realPos = pos; } if (!FarmManager.mPlantHelpMap.ContainsKey(new IntVec3(pos))) { CSClodMgr.AddClod(realPos, false); } else { CSClodMgr.AddClod(realPos, true); } } #endif }
// <CSVD> Main Data Managers Imports public static void Import(byte[] buffer) { Clear(); if (buffer == null) { return; } if (buffer.Length < 8) { return; } if (debugSwitch) { Debug.Log("<color=yellow>" + "Start to Import CSDataMgr" + "</color>"); } MemoryStream ms = new MemoryStream(buffer); BinaryReader r = new BinaryReader(ms); int version = r.ReadInt32(); if (debugSwitch) { Debug.Log("<color=yellow>" + "version:" + version + "</color>"); } if (CUR_VERSION != version) { if (debugSwitch) { Debug.LogWarning("The version of ColonyrecordMgr is newer than the record."); } } if (version >= VERSION000) { int count = r.ReadInt32(); for (int i = 0; i < count; i++) { CSDataInst dataInst = new CSDataInst(); if (debugSwitch) { Debug.Log("<color=yellow>" + i + " count: " + count + "</color>"); } dataInst.m_ID = r.ReadInt32(); if (debugSwitch) { Debug.Log("<color=yellow>" + "m_ID: " + dataInst.m_ID + "</color>"); } dataInst.Import(r); m_DataInsts.Add(dataInst.m_ID, dataInst); } CSClodMgr.Init(); CSClodMgr.Instance.Import(r); CSClodsMgr.Init(); CSClodsMgr.Instance.Import(r); //CSSimulatorDataMgr.ImportMgrs(r, version); } }
public static void Init() { if (s_Instance != null) { Debug.Log("The CSCloMgr is areadly."); return; } s_Instance = new CSClodMgr(); }
public static void Clear() { foreach (CSDataInst dataInst in m_DataInsts.Values) { dataInst.ClearData(); } m_DataInsts.Clear(); CSClodMgr.Clear(); CSClodsMgr.Clear(); }
void OnGUI() { if (GUI.Button(new Rect(200, 200, 100, 50), "Plant")) { Vector3 pos = CSClodMgr.FindCleanClod(); if (pos != Vector3.zero) { m_Farm.Plant(pos); } } }
void Awake() { if (s_Instance != null) { Debug.LogError("CSMain must be only one!"); } else { s_Instance = this; } CSEntityLayerIndex = Pathea.Layer.Building; m_Creators = new Dictionary <int, CSCreator>(); if (GameConfig.IsMultiMode) { otherCreators = new Dictionary <int, CSCreator>(); } CSClodMgr.Init(); CSClodsMgr.Init(); CSCreator defMgCreator = CreateCreator(CSConst.ciDefMgCamp, "Default Managed Creator"); if (GameConfig.IsMultiMode) { defMgCreator.teamNum = BaseNetwork.MainPlayer.TeamId; Debug.Log("Main Creator team: " + defMgCreator.teamNum); } CreateCreator(CSConst.ciDefNoMgCamp, "Default Non-Managed Creator", CSConst.CreatorType.NoManaged); DigTerrainManager.onDirtyVoxel += OnDirtyVoxel; FarmManager.Instance.CreatePlantEvent += OnCreatePlant; FarmManager.Instance.RemovePlantEvent += OnRemovePlant; DigTerrainManager.onDigTerrain += OnDigTerrain; // DefmgCreator UI //if ( CSUI_Main.Instance != null) //{ // CSUI_Main.Instance.Creator = defMgCreator; //} if (CSUI_MainWndCtrl.Instance != null) { CSUI_MainWndCtrl.Instance.Creator = defMgCreator; } if (InitOperatItemEvent != null) { InitOperatItemEvent(); InitOperatItemEvent = null; } }
public void ClearFarmWorks() { if (WorkRoom == null) { return; } CSFarm farm = WorkRoom as CSFarm; if (farm == null) { m_FarmWorkMap.Clear(); return; } foreach (KeyValuePair <EFarmWorkType, FarmWorkInfo> kvp in m_FarmWorkMap) { switch (kvp.Key) { case EFarmWorkType.Watering: farm.RestoreWateringPlant(kvp.Value.m_Plant); break; case EFarmWorkType.Cleaning: farm.RestoreCleaningPlant(kvp.Value.m_Plant); break; case EFarmWorkType.Harvesting: farm.RestoreRipePlant(kvp.Value.m_Plant); break; case EFarmWorkType.Planting: #if NEW_CLOD_MGR CSMgCreator mgCreator = m_Creator as CSMgCreator; if (mgCreator == null) { Debug.Log(" CSCreator is error"); break; } mgCreator.m_Clod.DirtyTheChunk(kvp.Value.m_ClodChunk.m_ChunkIndex, false); #else CSClodMgr.DirtyTheChunk(kvp.Value.m_ClodChunk.m_ChunkIndex, false); #endif break; } } m_FarmWorkMap.Clear(); }
void OnRemovePlant(FarmPlantLogic plant) { #if NEW_CLOD_MGR foreach (KeyValuePair <int, CSCreator> kvp in m_Creators) { CSMgCreator mgCreator = kvp.Value as CSMgCreator; if (mgCreator == null) { continue; } mgCreator.m_Clod.DirtyTheClod(plant.mPos, false); } #else CSClodMgr.DirtyTheClod(plant.mPos, false); #endif }
void OnDigTerrain(IntVector3 pos) { #if NEW_CLOD_MGR foreach (KeyValuePair <int, CSCreator> kvp in m_Creators) { CSMgCreator mgCreator = kvp.Value as CSMgCreator; if (mgCreator == null) { continue; } mgCreator.m_Clod.DeleteClod(pos); VFVoxel voxel = VFVoxelTerrain.self.Voxels.SafeRead(pos.x, pos.y - 1, pos.z); if ((voxel.Type == PlantConst.DIRTY_TYPE0 || voxel.Type == PlantConst.DIRTY_TYPE1) && voxel.Volume > 128) { RaycastHit rch; if (Physics.Raycast(pos, Vector3.down, out rch, 2, 1 << Pathea.Layer.VFVoxelTerrain)) { mgCreator.m_Clod.AddClod(rch.point, false); } else { mgCreator.m_Clod.AddClod(new Vector3(pos.x, pos.y - 0.7f, pos.z), false); } } } #else CSClodMgr.DeleteClod(pos); VFVoxel voxel = VFVoxelTerrain.self.Voxels.SafeRead(pos.x, pos.y - 1, pos.z); if (voxel.Type == CSClodMgr.TerrainType) { RaycastHit rch; if (Physics.Raycast(pos, Vector3.down, out rch, 2, 1 << Pathea.Layer.VFVoxelTerrain)) { CSClodMgr.AddClod(rch.point, false); } else { CSClodMgr.AddClod(new Vector3(pos.x, pos.y - 0.7f, pos.z), false); } } #endif }
private void _farmWorkStyle() { CSFarm farm = WorkRoom as CSFarm; if (farm == null) { return; } FarmPlantLogic plant = null; CSMgCreator mgCreator = m_Creator as CSMgCreator; // Only watering and weeding if (m_WorkMode == CSConst.pwtFarmForMag) { if (m_FarmWorkMap.Count != 0) { return; } ItemObject waterItem = farm.GetPlantTool(0); ItemObject weedingItem = farm.GetPlantTool(1); // Watering plant = waterItem == null ? null : farm.AssignOutWateringPlant(); if (plant != null) { FarmWorkInfo fwi = new FarmWorkInfo(plant); m_FarmWorkMap.Add(EFarmWorkType.Watering, fwi); //_sendToWorkOnFarm(fwi.m_Pos); } else { // Weeding plant = weedingItem == null ? null : farm.AssignOutCleaningPlant(); if (plant != null) { FarmWorkInfo fwi = new FarmWorkInfo(plant); m_FarmWorkMap.Add(EFarmWorkType.Cleaning, fwi); //_sendToWorkOnFarm(fwi.m_Pos); } //else // Idle(0.0f, false); } } else if (m_WorkMode == CSConst.pwtFarmForHarvest) { if (m_FarmWorkMap.Count != 0) { return; } CSStorage storage = null; foreach (CSStorage css in farm.Assembly.m_BelongObjectsMap[CSConst.ObjectType.Storage]) { SlotList slotList = css.m_Package.GetSlotList(); if (slotList.GetVacancyCount() >= 2) //if (css.m_Package.GetEmptyGridCount() >= 2) { storage = css; break; } } if (storage != null) { plant = farm.AssignOutRipePlant(); if (plant != null) { FarmWorkInfo fwi = new FarmWorkInfo(plant); m_FarmWorkMap.Add(EFarmWorkType.Harvesting, fwi); //_sendToWorkOnFarm(fwi.m_Pos); } //else // Idle(0.0f, false); } //else // Idle(0.0f, false); } else if (m_WorkMode == CSConst.pwtFarmForPlant) { // Planting if (m_FarmWorkMap.Count == 0) { #if NEW_CLOD_MGR ClodChunk cc = mgCreator.m_Clod.FindCleanChunk(farm.Assembly.Position, farm.Assembly.Radius); #else ClodChunk cc = CSClodMgr.FindCleanChunk(farm.Assembly.Position, farm.Assembly.Radius); #endif if (farm.HasPlantSeed() && cc != null) { Vector3 pos; bool flag = cc.FindCleanClod(out pos); if (flag) { #if NEW_CLOD_MGR mgCreator.m_Clod.DirtyTheChunk(cc.m_ChunkIndex, true); #else CSClodMgr.DirtyTheChunk(cc.m_ChunkIndex, true); #endif FarmWorkInfo fwi = new FarmWorkInfo(cc, pos); m_FarmWorkMap.Add(EFarmWorkType.Planting, fwi); _sendToWorkOnFarm(fwi.m_Pos); } } //else // Idle(0.0f, false); } else if (m_FarmWorkMap.ContainsKey(EFarmWorkType.Planting) && m_FarmWorkMap[EFarmWorkType.Planting].m_Pos == Vector3.zero) { if (farm.HasPlantSeed()) { FarmWorkInfo fwi = m_FarmWorkMap[EFarmWorkType.Planting]; bool flag = fwi.m_ClodChunk.FindCleanClod(out fwi.m_Pos); if (flag) { //_sendToWorkOnFarm(fwi.m_Pos); } else { m_FarmWorkMap.Remove(EFarmWorkType.Planting); } } else { FarmWorkInfo fwi = m_FarmWorkMap[EFarmWorkType.Planting]; #if NEW_CLOD_MGR mgCreator.m_Clod.DirtyTheChunk(fwi.m_ClodChunk.m_ChunkIndex, false); #else CSClodMgr.DirtyTheChunk(fwi.m_ClodChunk.m_ChunkIndex, false); #endif m_FarmWorkMap.Remove(EFarmWorkType.Planting); } } if (!m_FarmWorkMap.ContainsKey(EFarmWorkType.Planting)) { //Idle(0.0f, false); } } }
public IEnumerator SearchVaildClodForAssembly(CSAssembly assem) { if (assem == null) { yield break; } if (assem.isSearchingClod) { yield break; } assem.isSearchingClod = true; CSMgCreator mgCreator = assem.m_Creator as CSMgCreator; mgCreator.m_Clod.Clear(); int width = Mathf.RoundToInt(assem.LargestRadius); // - 10; int length = width; int height = width; Vector3 int_pos = new Vector3(Mathf.FloorToInt(assem.Position.x), Mathf.FloorToInt(assem.Position.y), Mathf.FloorToInt(assem.Position.z)); Vector3 min_pos = int_pos - new Vector3(width, length, height); //Vector3 max_pos = int_pos + new Vector3(width, length, height); Vector3 pos = min_pos; float sqrRadius = assem.LargestRadius * assem.LargestRadius; length *= 2; width *= 2; height *= 2; int raycast_count = 0; int break_count = 0; for (int i = 0; i < width; i++) { for (int j = 0; j < length; j++, break_count++) { Vector3 prv_pos = Vector3.zero; VFVoxel prv_voxel = new VFVoxel(); for (int k = 0; k < height; k++) { pos = min_pos + new Vector3(i, k, j); if ((pos - int_pos).sqrMagnitude > sqrRadius) { continue; } VFVoxel voxel = VFVoxelTerrain.self.Voxels.SafeRead((int)pos.x, (int)pos.y, (int)pos.z); if (voxel.Volume < 128) { if (prv_voxel.Volume > 128 && (prv_voxel.Type == 19 || prv_voxel.Type == 63)) { RaycastHit rch; Vector3 clod_pos = Vector3.zero; if (Physics.Raycast(new Vector3(prv_pos.x, prv_pos.y + 1, prv_pos.z), Vector3.down, out rch, 2, 1 << Pathea.Layer.VFVoxelTerrain)) { raycast_count++; clod_pos = rch.point; } else { clod_pos = new Vector3(prv_pos.x, prv_pos.y + 0.4f, prv_pos.z); } #if NEW_CLOD_MGR if (!FarmManager.Instance.mPlantHelpMap.ContainsKey(new IntVec3(prv_pos))) { mgCreator.m_Clod.AddClod(clod_pos, false); } else { mgCreator.m_Clod.AddClod(clod_pos, true); } #else if (!FarmManager.mPlantHelpMap.ContainsKey(new IntVec3(prv_pos))) { CSClodMgr.AddClod(clod_pos, false); } else { CSClodMgr.AddClod(clod_pos, true); } #endif } } prv_pos = pos; prv_voxel = voxel; } if (break_count >= 30 || raycast_count >= 30) { raycast_count = 0; break_count = 0; yield return(0); if (assem == null) { yield break; } } } } if (assem != null) { assem.isSearchingClod = false; } yield return(0); }