コード例 #1
0
ファイル: CSClodMgr.cs プロジェクト: shrubba/planetexplorers
    public void Export(BinaryWriter w)
    {
        w.Write(CSDataMgr.VERSION000);

        w.Write(m_IdleChunks.Count);
        Dictionary <IntVec3, ClodChunk> tempChunks = new Dictionary <IntVec3, ClodChunk>();

        foreach (KeyValuePair <IntVec3, ClodChunk> kvp in m_ClodChunks)
        {
            tempChunks.Add(kvp.Key, kvp.Value);
        }

        foreach (IntVec3 vec3 in m_IdleChunks.Keys)
        {
            ClodChunk cc = m_ClodChunks[vec3];
            cc.Export(w);

            tempChunks.Remove(vec3);
        }

        w.Write(tempChunks.Count);
        foreach (KeyValuePair <IntVec3, ClodChunk> kvp in tempChunks)
        {
            kvp.Value.Export(w);
        }
    }
コード例 #2
0
ファイル: CSClodMgr.cs プロジェクト: shrubba/planetexplorers
    public static void AddClod(Vector3 pos, bool dirty = false)
    {
        if (s_Instance == null)
        {
            Debug.Log("Clod manager is not exist.");
            return;
        }

        IntVec3 index_pos  = new IntVec3(pos);
        IntVec3 chunkIndex = GetChunkIndex(index_pos);

        if (!s_Instance.m_ClodChunks.ContainsKey(chunkIndex))
        {
            ClodChunk cc = new ClodChunk();
            cc.m_ChunkIndex = chunkIndex;
            s_Instance.m_ClodChunks.Add(chunkIndex, cc);
            s_Instance.m_ClodChunks[chunkIndex].AddClod(pos, dirty);
        }
        else
        {
            s_Instance.m_ClodChunks[chunkIndex].AddClod(pos, dirty);
        }

        s_Instance.m_IdleChunks[chunkIndex] = 0;
    }
コード例 #3
0
ファイル: CSClodMgr.cs プロジェクト: shrubba/planetexplorers
    /// <summary>
    /// <CSVD> Clod manager main import
    /// </summary>
    public bool Import(BinaryReader r)
    {
        int version = r.ReadInt32();

        if (version >= CSDataMgr.VERSION000)
        {
            int count = r.ReadInt32();
            for (int i = 0; i < count; i++)
            {
                ClodChunk cc = new ClodChunk();
                cc.Import(r, version);
                m_ClodChunks.Add(cc.m_ChunkIndex, cc);
                m_IdleChunks.Add(cc.m_ChunkIndex, 0);
            }

            count = r.ReadInt32();
            for (int i = 0; i < count; i++)
            {
                ClodChunk cc = new ClodChunk();
                cc.Import(r, version);
                m_ClodChunks.Add(cc.m_ChunkIndex, cc);
                if (cc.HasIdleClods())
                {
                    m_IdleChunks[cc.m_ChunkIndex] = 0;
                }
            }
        }
        return(true);
    }
コード例 #4
0
ファイル: CSClodMgr.cs プロジェクト: shrubba/planetexplorers
    public void AddClod(Vector3 pos, bool dirty = false)
    {
        IntVec3 index_pos  = new IntVec3(pos);
        IntVec3 chunkIndex = GetChunkIndex(index_pos);

        if (!m_ClodChunks.ContainsKey(chunkIndex))
        {
            ClodChunk cc = new ClodChunk();
            cc.m_ChunkIndex = chunkIndex;
            m_ClodChunks.Add(chunkIndex, cc);
            m_ClodChunks[chunkIndex].AddClod(pos, dirty);
        }
        else
        {
            m_ClodChunks[chunkIndex].AddClod(pos, dirty);
        }

        m_IdleChunks[chunkIndex] = 0;
    }
コード例 #5
0
 public FarmWorkInfo(ClodChunk clodChunk, Vector3 pos)
 {
     m_ClodChunk = clodChunk;
     m_Pos       = pos;
 }
コード例 #6
0
    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);
            }
        }
    }
コード例 #7
0
ファイル: CSClodMgr.cs プロジェクト: shrubba/planetexplorers
    /// <summary>
    /// <CSVD> Clod manager main import
    /// </summary>
    public void Import(BinaryReader r)
    {
        int version = r.ReadInt32();

        //switch ( version )
        //{
        //case 0x0105:
        //case 0x0106:
        //case 0x0107:
        //{
        //    int count = r.ReadInt32();
        //    for (int i = 0; i < count; i++)
        //    {
        //        Vector3 vec = new Vector3(r.ReadSingle(), r.ReadSingle(), r.ReadSingle());
        //        IntVec3 index_pos = new IntVec3(vec);
        //        m_ClodLocas.Add(index_pos,vec);
        //        m_IdleClods.Add(index_pos, 0);
        //    }

        //    count = r.ReadInt32();
        //    for (int i = 0; i < count; i++)
        //    {
        //        Vector3 vec = new Vector3(r.ReadSingle(), r.ReadSingle(), r.ReadSingle());
        //        IntVec3 index_pos = new IntVec3(vec);
        //        m_ClodLocas.Add(index_pos, vec);
        //    }
        //}
        //return true;
        //case 0x0108:
        //case 0x0109:
        //case 0x0110:
        //case 0x0111:
        //case 0x0112:
        //case 0x0113:
        //case 0x0114:
        //case 0x0115:
        //case 0x0116:
        //{
        if (version >= CSDataMgr.VERSION000)
        {
            int count = r.ReadInt32();
            for (int i = 0; i < count; i++)
            {
                ClodChunk cc = new ClodChunk();
                cc.Import(r, version);
                m_ClodChunks.Add(cc.m_ChunkIndex, cc);
                m_IdleChunks.Add(cc.m_ChunkIndex, 0);
            }

            count = r.ReadInt32();
            for (int i = 0; i < count; i++)
            {
                ClodChunk cc = new ClodChunk();
                cc.Import(r, version);
                m_ClodChunks.Add(cc.m_ChunkIndex, cc);
                if (cc.HasIdleClods())
                {
                    m_IdleChunks[cc.m_ChunkIndex] = 0;
                }
            }
        }

        //}
        //return true;
        //default:
        //    break;
        //}

        //return false;
    }