Beispiel #1
0
    override public void Annihilate(bool clearFromSurface, bool returnResources, bool leaveRuins)
    {
        if (destroyed | GameMaster.sceneClearing)
        {
            return;
        }
        else
        {
            destroyed = true;
        }
        PrepareStructureForDestruction(clearFromSurface, returnResources, leaveRuins);
        if (basement != null)
        {
            basement.myChunk.GetNature().RemoveLifesource(this);
            basement.ChangeMaterial(ResourceType.DIRT_ID, true);
            if (GameMaster.realMaster.gameMode != GameMode.Editor)
            {
                switch (ID)
                {
                case TREE_OF_LIFE_ID:
                {
                    HarvestableResource hr = HarvestableResource.ConstructContainer(ContainerModelType.DeadTreeOfLife, ResourceType.Lumber, 5000);
                    hr.SetModelRotation(modelRotation);
                    hr.SetBasement(basement, new PixelPosByte(hr.surfaceRect.x, hr.surfaceRect.z));
                    break;
                }

                case LIFESTONE_ID:
                {
                    HarvestableResource hr = HarvestableResource.ConstructContainer(ContainerModelType.DeadLifestone, ResourceType.Stone, 5000);
                    hr.SetModelRotation(modelRotation);
                    hr.SetBasement(basement, new PixelPosByte(hr.surfaceRect.x, hr.surfaceRect.z));
                    break;
                }
                }
            }
            if (dependentBlocks != null)
            {
                basement.myChunk.ClearBlocksList(this, dependentBlocks, true);
            }
        }
        if (subscribedToRestoreBlockersUpdate)
        {
            GameMaster.realMaster.blockersRestoreEvent -= RestoreBlockers;
            subscribedToRestoreBlockersUpdate           = false;
        }
        Destroy(gameObject);
    }
Beispiel #2
0
 override public void Dry(bool sendMessageToGrassland)
 {
     if (!sendMessageToGrassland)
     {
         basement?.RemoveStructure(this);
     }
     if (stage > TRANSIT_STAGE)
     {
         ContainerModelType cmtype;
         if (stage == 4)
         {
             cmtype = ContainerModelType.DeadOak4;
         }
         else
         {
             if (stage == 5)
             {
                 cmtype = ContainerModelType.DeadOak5;
             }
             else
             {
                 cmtype = ContainerModelType.DeadOak6;
             }
         }
         HarvestableResource hr = HarvestableResource.ConstructContainer(cmtype, ResourceType.Lumber, CountLumber() * GameMaster.realMaster.environmentMaster.environmentalConditions);
         hr.SetModelRotation(modelRotation);
         hr.SetBasement(basement, new PixelPosByte(surfaceRect.x, surfaceRect.z));
         // спрайтовый LOD?
     }
     else
     {
         Structure s = GetStructureByID(DRYED_PLANT_ID);
         s.SetBasement(basement, new PixelPosByte(surfaceRect.x, surfaceRect.z));
         StructureTimer st = s.gameObject.AddComponent <StructureTimer>();
         st.timer = 5;
     }
 }
Beispiel #3
0
    public void SpreadMinerals(Plane[] planes)
    {
        int            res = PlaneExtension.INNER_RESOLUTION;
        int            maxObjectsCount = res * res / 2, positionsLeft;
        PlaneExtension pe;

        foreach (var p in planes)
        {
            pe = p.FORCED_GetExtension();
            List <PixelPosByte> positions = pe.GetRandomCells(maxObjectsCount);
            if (positions.Count == 0)
            {
                return;
            }
            maxObjectsCount = positions.Count;
            positionsLeft   = maxObjectsCount;
            List <HarvestableResource> allBoulders = new List <HarvestableResource>();


            int containersCount = 0;
            if (Random.value < metalK_abundance * 10)
            {
                containersCount = (int)(maxObjectsCount * GameMaster.geologyModule.metalK_abundance * Random.value);
                if (containersCount != 0)
                {
                    int i = 0;
                    while (i < containersCount && positionsLeft > 0)
                    {
                        HarvestableResource hr = HarvestableResource.ConstructContainer(ContainerModelType.Boulder, ResourceType.metal_K_ore, 1 + Random.value * 100 * metalK_abundance);
                        allBoulders.Add(hr);
                        positionsLeft--; i++;
                    }
                }
            }
            if (Random.value < metalM_abundance * 10 && positionsLeft > 0)
            {
                containersCount = (int)(maxObjectsCount * GameMaster.geologyModule.metalM_abundance * Random.value);
                if (containersCount != 0)
                {
                    int i = 0;
                    while (i < containersCount && positionsLeft > 0)
                    {
                        HarvestableResource hr = HarvestableResource.ConstructContainer(ContainerModelType.Boulder, ResourceType.metal_M_ore, 1 + Random.value * 100 * metalM_abundance);
                        allBoulders.Add(hr); positionsLeft--; i++;
                    }
                }
            }
            if (Random.value < metalE_abundance * 10 && positionsLeft > 0)
            {
                containersCount = (int)(maxObjectsCount * GameMaster.geologyModule.metalE_abundance * Random.value);
                if (containersCount != 0)
                {
                    int i = 0;
                    while (i < containersCount && positionsLeft > 0)
                    {
                        HarvestableResource hr = HarvestableResource.ConstructContainer(ContainerModelType.Boulder, ResourceType.metal_M_ore, 1 + Random.value * 100 * metalE_abundance);
                        allBoulders.Add(hr); positionsLeft--; i++;
                    }
                }
            }
            if (Random.value < metalN_abundance * 10 && positionsLeft > 0)
            {
                containersCount = (int)(maxObjectsCount * GameMaster.geologyModule.metalN_abundance * Random.value);
                if (containersCount != 0)
                {
                    int i = 0;
                    while (i < containersCount && positionsLeft > 0)
                    {
                        HarvestableResource hr = HarvestableResource.ConstructContainer(ContainerModelType.Boulder, ResourceType.metal_N_ore, 1 + Random.value * 100 * metalN_abundance);
                        allBoulders.Add(hr); positionsLeft--; i++;
                    }
                }
            }
            if (Random.value < metalP_abundance * 10 && positionsLeft > 0)
            {
                containersCount = (int)(maxObjectsCount * GameMaster.geologyModule.metalP_abundance * Random.value);
                if (containersCount != 0)
                {
                    int i = 0;
                    while (i < containersCount && positionsLeft > 0)
                    {
                        HarvestableResource hr = HarvestableResource.ConstructContainer(ContainerModelType.Boulder, ResourceType.metal_P_ore, 1 + Random.value * 100 * metalP_abundance);
                        allBoulders.Add(hr); positionsLeft--; i++;
                    }
                }
            }
            if (Random.value < metalS_abundance * 10 && positionsLeft > 0)
            {
                containersCount = (int)(maxObjectsCount * GameMaster.geologyModule.metalS_abundance * Random.value);
                if (containersCount != 0)
                {
                    int i = 0;
                    while (i < containersCount && positionsLeft > 0)
                    {
                        HarvestableResource hr = HarvestableResource.ConstructContainer(ContainerModelType.Boulder, ResourceType.metal_S_ore, 1 + Random.value * 100 * metalS_abundance);
                        allBoulders.Add(hr); positionsLeft--; i++;
                    }
                }
            }
            if (Random.value < mineralF_abundance * 4 && positionsLeft > 0)
            {
                containersCount = (int)(maxObjectsCount * GameMaster.geologyModule.mineralF_abundance * Random.value);
                if (containersCount != 0)
                {
                    int i = 0;
                    while (i < containersCount && positionsLeft > 0)
                    {
                        HarvestableResource hr = HarvestableResource.ConstructContainer(ContainerModelType.Pile, ResourceType.mineral_F, 1 + Random.value * 100 * mineralF_abundance);
                        allBoulders.Add(hr); positionsLeft--; i++;
                    }
                }
            }
            if (Random.value < mineralL_abundance * 4 && positionsLeft > 0)
            {
                containersCount = (int)(maxObjectsCount * GameMaster.geologyModule.mineralL_abundance * Random.value);
                if (containersCount != 0)
                {
                    int i = 0;
                    while (i < containersCount && positionsLeft > 0)
                    {
                        HarvestableResource hr = HarvestableResource.ConstructContainer(ContainerModelType.Pile, ResourceType.mineral_L, 1 + Random.value * 100 * mineralL_abundance);
                        allBoulders.Add(hr); positionsLeft--; i++;
                    }
                }
            }
            if (allBoulders.Count > 0)
            {
                for (int n = 0; n < allBoulders.Count; n++)
                {
                    allBoulders[n].SetBasement(p, positions[n]);
                }
            }
            maxObjectsCount  = res * res - pe.GetStructuresCount();
            maxObjectsCount /= 2;
            maxObjectsCount  = (int)(maxObjectsCount * Random.value);
            if (maxObjectsCount > 0)
            {
                int count = 0;
                if (p.materialID == ResourceType.STONE_ID)
                {
                    count = (int)(maxObjectsCount * (0.05f + Random.value * 0.05f));
                }
                else
                {
                    count = (int)(Random.value * 0.08f);
                }
                List <PixelPosByte> points = pe.GetRandomCells(count);
                if (points.Count > 0)
                {
                    foreach (PixelPosByte pos in points)
                    {
                        HarvestableResource hr = HarvestableResource.ConstructContainer(ContainerModelType.Boulder, ResourceType.Stone, 4 + Random.value * 10);
                        hr.SetBasement(p, pos);
                    }
                }
            }
        }
    }
    override public void Annihilate(StructureAnnihilationOrder order)
    {
        if (destroyed | GameMaster.sceneClearing)
        {
            return;
        }
        else
        {
            destroyed = true;
        }
        PrepareStructureForDestruction(order);
        if (basement != null && order.doSpecialChecks)
        {
            Chunk    chunk = basement.myChunk;
            ChunkPos cpos  = basement.pos;
            Plane    p;
            void CheckAndUnblock(in ChunkPos position)
            {
                Block bx = chunk.GetBlock(position);

                if (bx != null && bx.TryGetPlane(Block.UP_FACE_INDEX, out p))
                {
                    p.UnblockFromStructure(this);
                }
            }

            ChunkPos cpos2 = new ChunkPos(cpos.x - 1, cpos.y, cpos.z + 1); if (cpos2.isOkay)
            {
                CheckAndUnblock(cpos2);
            }
            cpos2 = new ChunkPos(cpos.x, cpos.y, cpos.z + 1); if (cpos2.isOkay)
            {
                CheckAndUnblock(cpos2);
            }
            cpos2 = new ChunkPos(cpos.x + 1, cpos.y, cpos.z + 1); if (cpos2.isOkay)
            {
                CheckAndUnblock(cpos2);
            }
            cpos2 = new ChunkPos(cpos.x - 1, cpos.y, cpos.z); if (cpos2.isOkay)
            {
                CheckAndUnblock(cpos2);
            }
            cpos2 = new ChunkPos(cpos.x + 1, cpos.y, cpos.z); if (cpos2.isOkay)
            {
                CheckAndUnblock(cpos2);
            }
            cpos2 = new ChunkPos(cpos.x - 1, cpos.y, cpos.z - 1); if (cpos2.isOkay)
            {
                CheckAndUnblock(cpos2);
            }
            cpos2 = new ChunkPos(cpos.x, cpos.y, cpos.z - 1); if (cpos2.isOkay)
            {
                CheckAndUnblock(cpos2);
            }
            cpos2 = new ChunkPos(cpos.x + 1, cpos.y, cpos.z - 1); if (cpos2.isOkay)
            {
                CheckAndUnblock(cpos2);
            }

            basement.myChunk.InitializeNature().RemoveLifesource(this);
            basement.ChangeMaterial(ResourceType.DIRT_ID, true);
            if (GameMaster.realMaster.gameMode != GameMode.Editor)
            {
                switch (ID)
                {
                case TREE_OF_LIFE_ID:
                {
                    HarvestableResource hr = HarvestableResource.ConstructContainer(ContainerModelType.DeadTreeOfLife, ResourceType.Lumber, 5000);
                    hr.SetModelRotation(modelRotation);
                    hr.SetBasement(basement, new PixelPosByte(hr.surfaceRect.x, hr.surfaceRect.z));
                    break;
                }

                case LIFESTONE_ID:
                {
                    HarvestableResource hr = HarvestableResource.ConstructContainer(ContainerModelType.DeadLifestone, ResourceType.Stone, 5000);
                    hr.SetModelRotation(modelRotation);
                    hr.SetBasement(basement, new PixelPosByte(hr.surfaceRect.x, hr.surfaceRect.z));
                    break;
                }
                }
            }
            if (dependentBlocks != null)
            {
                basement.myChunk.ClearBlockersList(this, dependentBlocks, true);
            }
        }
        if (subscribedToRestoreBlockersUpdate)
        {
            GameMaster.realMaster.blockersRestoreEvent -= RestoreBlockers;
            subscribedToRestoreBlockersUpdate           = false;
        }
        Destroy(gameObject);
    }