Пример #1
0
    override protected void Dry()
    {
        GameObject g = Instantiate(Resources.Load <GameObject>("Lifeforms/DeadTree")) as GameObject;

        g.transform.localScale = transform.localScale;
        HarvestableResource hr = g.GetComponent <HarvestableResource>();

        hr.SetResources(ResourceType.Lumber, CalculateLumberCount());
        hr.SetBasement(basement, new PixelPosByte(innerPosition.x, innerPosition.z));
    }
Пример #2
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);
    }
Пример #3
0
    public static HarvestableResource LoadContainer(System.IO.Stream fs, Plane sblock)
    {
        var data = new byte[STRUCTURE_SERIALIZER_LENGTH + CONTAINER_SERIALIZER_LENGTH];

        fs.Read(data, 0, data.Length);
        int                 containerStartIndex = STRUCTURE_SERIALIZER_LENGTH;
        ushort              modelId             = System.BitConverter.ToUInt16(data, containerStartIndex + 8);
        ResourceType        resType             = ResourceType.GetResourceTypeById(System.BitConverter.ToInt32(data, containerStartIndex));
        float               count = System.BitConverter.ToSingle(data, containerStartIndex + 4);
        HarvestableResource hr    = ConstructContainer((ContainerModelType)modelId, resType, count);

        hr.modelRotation  = data[2];
        hr.indestructible = (data[3] == 1);
        hr.SetBasement(sblock, new PixelPosByte(data[0], data[1]));
        hr.hp    = System.BitConverter.ToSingle(data, 4);
        hr.maxHp = System.BitConverter.ToSingle(data, 8);
        return(hr);
    }
Пример #4
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;
     }
 }
Пример #5
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);
                    }
                }
            }
        }
    }
Пример #6
0
    public void AddLifepowerAndCalculate(int count)
    {
        lifepower += count;
        int existingPlantsCount = 0;

        if (myBlock.cellsStatus != 0)
        {
            foreach (Structure s in myBlock.surfaceObjects)
            {
                if (s is Plant)
                {
                    existingPlantsCount++;
                }
            }
        }
        if (lifepower > 2 * LIFEPOWER_TO_PREPARE)
        {
            float freeEnergy = lifepower - 2 * LIFEPOWER_TO_PREPARE;
            int   treesCount = (int)(Random.value * 10 + 4);
            int   i          = 0;
            List <PixelPosByte> positions = myBlock.GetRandomCells(treesCount);
            if (treesCount > positions.Count)
            {
                treesCount = positions.Count;
            }
            int lifepowerDosis = (int)(freeEnergy / (treesCount + existingPlantsCount));
            if (treesCount != 0)
            {
                while (i < treesCount & freeEnergy > 0 & myBlock.cellsStatus != 1)
                {
                    int plantID = Plant.TREE_OAK_ID;
                    int ld      = (int)(lifepowerDosis * (0.3f + Random.value));
                    if (ld > freeEnergy)
                    {
                        lifepower += freeEnergy; break;
                    }
                    byte  maxStage  = OakTree.MAX_STAGE;
                    float maxEnergy = OakTree.GetLifepowerLevelForStage(maxStage);
                    byte  getStage  = (byte)(ld / maxEnergy * maxStage);
                    if (getStage > maxStage)
                    {
                        getStage = maxStage;
                    }
                    if (getStage == maxStage & Random.value > 0.7f)
                    {
                        getStage--;
                    }

                    if (Random.value > 0.1f)
                    {
                        Plant p = Plant.GetNewPlant(plantID);
                        p.SetBasement(myBlock, positions[i]);
                        p.AddLifepower(ld);
                        p.SetStage(getStage);
                        freeEnergy -= (Plant.GetCreateCost(plantID) + ld);
                    }
                    else
                    {
                        HarvestableResource hr = Structure.GetStructureByID(Structure.CONTAINER_ID) as HarvestableResource;
                        hr.SetResources(ResourceType.Food, 10);
                        hr.SetBasement(myBlock, positions[i]);
                        freeEnergy -= BERRY_BUSH_LIFECOST;
                    }

                    i++;
                }
            }
            if (existingPlantsCount != 0 & freeEnergy >= lifepowerDosis)
            {
                i = 0;
                Plant p = null;
                for (; i < myBlock.surfaceObjects.Count; i++)
                {
                    p = myBlock.surfaceObjects[i] as Plant;
                    if (p != null)
                    {
                        p.AddLifepower(lifepowerDosis);
                        freeEnergy -= lifepowerDosis;
                        if (freeEnergy <= 0)
                        {
                            break;
                        }
                    }
                }
            }
            lifepower += freeEnergy;
        }
        progress = Mathf.Clamp(lifepower / LIFEPOWER_TO_PREPARE, 0, 1);
        byte stage = (byte)(Mathf.RoundToInt(progress / 0.2f));

        prevStage = stage;
        SetGrassTexture(stage);
    }
Пример #7
0
    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);
    }
Пример #8
0
    public void SpreadMinerals(SurfaceBlock surface)
    {
        if (surface == null)
        {
            return;
        }
        int maxObjectsCount = SurfaceBlock.INNER_RESOLUTION * SurfaceBlock.INNER_RESOLUTION / 2, positionsLeft;
        List <PixelPosByte> positions = surface.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 = Structure.GetStructureByID(Structure.CONTAINER_ID) as HarvestableResource;
                    hr.SetResources(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 = Structure.GetStructureByID(Structure.CONTAINER_ID) as HarvestableResource;
                    hr.SetResources(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 = Structure.GetStructureByID(Structure.CONTAINER_ID) as HarvestableResource;
                    hr.SetResources(ResourceType.metal_E_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 = Structure.GetStructureByID(Structure.CONTAINER_ID) as HarvestableResource;
                    hr.SetResources(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 = Structure.GetStructureByID(Structure.CONTAINER_ID) as HarvestableResource;
                    hr.SetResources(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 = Structure.GetStructureByID(Structure.CONTAINER_ID) as HarvestableResource;
                    hr.SetResources(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 = Structure.GetStructureByID(Structure.CONTAINER_ID) as HarvestableResource;
                    hr.SetResources(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 = Structure.GetStructureByID(Structure.CONTAINER_ID) as HarvestableResource;
                    hr.SetResources(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(surface, positions[n]);
            }
        }
        maxObjectsCount  = SurfaceBlock.INNER_RESOLUTION * SurfaceBlock.INNER_RESOLUTION - surface.surfaceObjects.Count;
        maxObjectsCount /= 2;
        maxObjectsCount  = (int)(maxObjectsCount * Random.value);
        if (maxObjectsCount > 0)
        {
            int count = 0;
            if (surface.material_id == ResourceType.STONE_ID)
            {
                count = (int)(maxObjectsCount * (0.05f + Random.value * 0.05f));
            }
            else
            {
                count = (int)(Random.value * 0.08f);
            }
            List <PixelPosByte> points = surface.GetRandomCells(count);
            if (points.Count > 0)
            {
                foreach (PixelPosByte p in points)
                {
                    HarvestableResource hr = Structure.GetStructureByID(Structure.CONTAINER_ID) as HarvestableResource;
                    hr.SetResources(ResourceType.Stone, 4 + Random.value * 10);
                    hr.SetBasement(surface, p);
                }
            }
        }
    }