Exemplo n.º 1
0
    override protected void LabourResult()
    {
        int   i             = 0;
        float totalCost     = 0;
        float actionsPoints = workflow / workflowToProcess;

        workflow = 0;
        List <Structure> structures = basement.surfaceObjects;

        if (basement.cellsStatus == 1)
        {
            while (i < structures.Count & actionsPoints > 0)
            {
                if (structures[i].id == PLANT_ID)
                {
                    Plant p = structures[i] as Plant;
                    if (p.plant_ID == crop_id)
                    {
                        if (p.stage >= harvestableStage & p.growth >= 1)
                        {
                            p.Harvest();
                            actionsPoints -= HARVEST_ACTIVITY_COST;
                        }
                        else
                        {
                            if (p.lifepower < p.lifepowerToGrow)
                            {
                                p.AddLifepower((int)lifepowerBoost);
                                totalCost     += lifepowerBoost;
                                actionsPoints -= BOOST_ACTIVITY_COST;
                            }
                        }
                    }
                }
                i++;
            }
        }
        else
        {
            List <PixelPosByte> pos = basement.GetRandomCells((int)(actionsPoints / PLANT_ACTIVITY_COST));
            int cost = Plant.GetCreateCost(crop_id);
            i = 0;
            while (i < pos.Count)
            {
                Plant p = Plant.GetNewPlant(crop_id);
                p.Prepare();
                p.SetBasement(basement, pos[i]);
                totalCost += cost;
                i++;
            }
        }
        if (totalCost > 0)
        {
            basement.myChunk.TakeLifePowerWithForce((int)totalCost);
        }
    }
Exemplo 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);
    }
Exemplo n.º 3
0
    public static int GrasslandUpdate(float tax)
    {
        if (grasslandList.Count == 0)
        {
            return((int)tax);
        }
        float returnVal = tax;

        if (tax != 0)
        {
            if (tax > 0)
            {
                int pos   = (int)(Random.value * (grasslandList.Count - 1));
                int count = (int)(GameMaster.MAX_LIFEPOWER_TRANSFER * GameMaster.lifeGrowCoefficient);
                grasslandList[pos].AddLifepower(count);
                returnVal -= count;
            }
            else
            {
                tax *= -1;
                int i    = 0;
                int tax2 = Mathf.RoundToInt(tax / grasslandList.Count);
                while (i < grasslandList.Count)
                {
                    returnVal += grasslandList[i].TakeLifepower(tax2);
                    i++;
                }
            }
        }
        List <Plant> plants = new List <Plant>();
        SurfaceBlock myBlock; Chunk c; float lifepower = 0;

        float lifepowerTick = GameMaster.LIFEPOWER_TICK;

        for (var a = 0; a < grasslandList.Count; a++)
        {
            Grassland gl = grasslandList[a];
            myBlock   = gl.myBlock;
            c         = myBlock.myChunk;
            lifepower = gl.lifepower;
            foreach (Structure s in gl.myBlock.surfaceObjects)
            {
                if (s.id == Structure.PLANT_ID)
                {
                    plants.Add(s as Plant);
                }
            }

            byte stage = gl.CheckGrasslandStage();
            if (lifepower > 2 * LIFEPOWER_TO_PREPARE)
            {
                if (stage > 2 & plants.Count < MAX_PLANTS_COUNT)
                {
                    int i = 0;
                    while (lifepower > 2 * LIFEPOWER_TO_PREPARE & i < plants.Count)
                    {
                        Plant p = plants[i];
                        if (p.lifepower < p.lifepowerToGrow)
                        {
                            float donation = p.lifepowerToGrow - p.lifepower;
                            float mt       = p.GetMaxLifeTransfer();
                            if (donation > mt)
                            {
                                donation = mt;
                            }
                            if (donation > (lifepower - 2 * LIFEPOWER_TO_PREPARE))
                            {
                                donation = (lifepower - 2 * LIFEPOWER_TO_PREPARE);
                            }
                            lifepower -= donation;
                            p.AddLifepower((int)donation);
                        }
                        i++;
                    }
                    if (gl.plantCreateCooldown <= 0)
                    {
                        int cost = Plant.GetCreateCost(Plant.TREE_OAK_ID);
                        if (lifepower > (2 * LIFEPOWER_TO_PREPARE + cost) & myBlock.cellsStatus != 1)
                        {
                            PixelPosByte pos = myBlock.GetRandomCell();
                            if (pos != PixelPosByte.Empty)
                            {
                                Plant p = Plant.GetNewPlant(Plant.TREE_OAK_ID);
                                p.SetBasement(myBlock, pos);
                                gl.TakeLifepower(cost);
                                gl.plantCreateCooldown = 10f / lifepowerTick;
                                //MonoBehaviour.print("new plant created");
                            }
                        }
                    }
                    else
                    {
                        gl.plantCreateCooldown -= lifepowerTick;
                    }
                }
            }
            else
            { // lifepower falls down
                if (lifepower < LIFEPOWER_TO_PREPARE & plants.Count > 0)
                {
                    float lifepowerNeeded          = Mathf.Abs(lifepower) + LIFEPOWER_TO_PREPARE + 2;
                    int   lifepowerFromSinglePlant = Mathf.RoundToInt(lifepowerNeeded / (float)plants.Count);
                    while (lifepower <= LIFEPOWER_TO_PREPARE & plants.Count > 0)
                    {
                        int i = (int)(Random.value * (plants.Count - 1));
                        lifepower += plants[i].TakeLifepower(lifepowerFromSinglePlant);
                        plants.RemoveAt(i);
                    }
                }
                gl.CheckGrasslandStage();
            }
            plants.Clear();
        }
        return((int)returnVal);
    }