Ejemplo n.º 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));
    }
Ejemplo n.º 2
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);
    }
Ejemplo n.º 3
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);
                }
            }
        }
    }