Inheritance: MonoBehaviour
Exemplo n.º 1
0
    public static void UpdatePlants()
    {
        float t = GameMaster.LIFEPOWER_TICK;

        if (oaks.Count > 0)
        {
            int   i = 0;
            float theoreticalGrowth;
            while (i < oaks.Count)
            {
                OakTree oak = oaks[i];
                if (oak == null)
                {
                    oaks.RemoveAt(i);
                    continue;
                }
                else
                {
                    oak.timer        -= t;
                    theoreticalGrowth = oak.lifepower / oak.lifepowerToGrow;
                    if (oak.growth < theoreticalGrowth)
                    {
                        oak.growth = Mathf.MoveTowards(oak.growth, theoreticalGrowth, growSpeed * t);
                    }
                    else
                    {
                        oak.lifepower -= decaySpeed * t;
                        if (oak.lifepower <= 0)
                        {
                            oak.Dry();
                        }
                    }
                    if (oak.timer <= 0)
                    {
                        if (oak.growth >= 1 & oak.stage < MAX_STAGE)
                        {
                            byte nextStage = oak.stage;
                            nextStage++;
                            oak.SetStage(nextStage);
                        }
                        oak.timer = oak.stage;
                    }
                    i++;
                }
            }
        }
        else
        {
            if (((existingPlantsMask >> TREE_OAK_ID) & 1) != 0)
            {
                int val = 1;
                val = val << TREE_OAK_ID;
                existingPlantsMask -= val;
            }
        }
    }
Exemplo n.º 2
0
 public static void ResetToDefaults_Static()
 {
     OakTree.ResetToDefaults_Static_OakTree();
     Corn.ResetToDefaults_Static_Corn();
     Hospital.ResetToDefaults_Static_Hospital();
     Dock.ResetToDefaults_Static_Dock();
     RecruitingCenter.ResetToDefaults_Static_RecruitingCenter();
     QuantumTransmitter.ResetToDefaults_Static_QuantumTransmitter();
     Hangar.ResetToDefaults_Static_Hangar();
 }
Exemplo n.º 3
0
    private void OnTriggerEnter(Collider other)
    {
        OakTree tree = other.GetComponentInParent <OakTree>();

        if (carried == null && tree != null && tree.State == OakTree.OakState.Planted)
        {
            carried                      = tree;
            tree.State                   = OakTree.OakState.Carried;
            tree.transform.parent        = carryPos;
            tree.transform.localPosition = Vector3.zero;
            turnipSpawner.enabled        = false;
        }
    }
Exemplo n.º 4
0
 public static void PlantUpdate()       // можно выделить в потоки
 {
     if (existingPlantsMask != 0)
     {
         if ((existingPlantsMask & (1 << CROP_CORN_ID)) != 0)
         {
             Corn.UpdatePlants();
         }
         if ((existingPlantsMask & (1 << TREE_OAK_ID)) != 0)
         {
             OakTree.UpdatePlants();
         }
     }
 }
Exemplo n.º 5
0
 private void FixedUpdate()
 {
     if (Input.GetButton("Fire1") && carried != null)
     {
         //throw tree
         carried.transform.parent     = null;
         carried.State                = OakTree.OakState.Thrown;
         carried.Body.velocity        = treeVelocity + Vector3.Scale(treeRandomness, new Vector3(Random.Range(-1f, 1), Random.Range(-1f, 1), Random.Range(-1f, 1)));
         carried.Body.angularVelocity = new Vector3(Random.Range(-1f, 1), Random.Range(-1f, 1), Random.Range(-1f, 1)).normalized *treeSpin;
         carried.Body.AddTorque(treeTorque, ForceMode.VelocityChange);
         carried = null;
         //delay turnips
         turnipSpawner.enabled = true;
         turnipSpawner.DelayTurnips(treeCooldown);
     }
 }
Exemplo n.º 6
0
        public override void Decorate(ChunkColumn column, int chunkX, int chunkZ, BiomeBase biome, float[] thresholdMap, int x, int y, int z, bool surface,
                                      bool isBelowMaxHeight)
        {
            try
            {
                var currentTemperature = biome.Temperature;
                if (y > 64)
                {
                    int distanceToSeaLevel = y - 64;
                    currentTemperature = biome.Temperature - (0.00166667f * distanceToSeaLevel);
                }

                int rx = chunkX * 16 + x;
                int rz = chunkZ * 16 + z;

                bool generated = false;
                if (surface && y >= Preset.SeaLevel)
                {
                    var noise = Simplex.Noise(rx, rz, Math.Min(biome.Downfall * 0.32f, 0.03f), 0.5, true);
                    if (x >= 3 && x <= 13 && z >= 3 && z <= 13)
                    {
                        Structure tree = null;
                        //if (biome.Config.)
                        if (biome.Downfall <= 0f && biome.Temperature >= 2f)
                        {
                            if (GetRandom(32) == 16)
                            {
                                var randValue = GetRandom(18);
                                if (randValue >= 0 && randValue <= 2)                                 //3 tall cactus
                                {
                                    tree = new CactusStructure(3);
                                }
                                else if (randValue > 2 && randValue <= 5)                                 // 2 tall cactus
                                {
                                    tree = new CactusStructure(2);
                                }
                                else if (randValue > 5 && randValue <= 11)                                 // 1 tall cactus
                                {
                                    tree = new CactusStructure(1);
                                }
                            }
                        }

                        if (tree == null && biome.Downfall >= 0 && (noise > (0.5f + (y / 512f))))
                        {
                            if (currentTemperature >= 1f && biome.Downfall >= 0.4f)
                            {
                                if (GetRandom(8) == 4)
                                {
                                    tree = new LargeJungleTree();
                                }
                                else
                                {
                                    tree = new SmallJungleTree();
                                }
                            }

                            /*	else if (currentTemperature >= 0.7F && biome.Downfall >= 0.2f)
                             *      {
                             *              tree = new OakTree(true);
                             *      }*/
                            else if (currentTemperature >= 0.7F && biome.Downfall < 0.2f)
                            {
                                tree = new AcaciaTree();
                            }
                            else if (currentTemperature > 0.25f && biome.Downfall > 0f)
                            {
                                if (biome.Name.Contains("Birch") || GetRandom(16) == 8)
                                {
                                    tree = new BirchTree();
                                }
                                else
                                {
                                    tree = new OakTree();
                                }
                            }
                            else if (currentTemperature <= 0.25f && biome.Downfall > 0f)
                            {
                                tree = new PineTree();
                            }
                        }

                        if (tree != null)
                        {
                            if (y + 1 < 254)
                            {
                                tree.Create(column, x, y + 1, z);
                            }
                            generated = true;
                        }
                    }

                    if (!generated)
                    {
                        if (noise > 0.5)                         //Threshold 1
                        {
                            /*if (currentTemperature > 0.3f && currentTemperature < 1.5f && biome.Downfall >= 0.85f)
                             * {
                             *      column.SetBlock(x, y + 1, z, 18); //Leaves
                             *      column.SetMetadata(x, y + 1, z, 3); //Jungle Leaves
                             * }
                             * else*/
                            if (currentTemperature > 0.3f && currentTemperature < 1.5f && biome.Downfall > 0)
                            {
                                var blockBeneath = column.GetBlockId(x, y, z);                                // column.GetBlock(x, y, z);

                                var sugarPosibility = GetRandom(18);
                                if (/*sugarPosibility <= 11*/ noise > 0.75f &&
                                    (blockBeneath == 3 || blockBeneath == 2 || blockBeneath == 12) &&
                                    IsValidSugarCaneLocation(column, x, y, z))
                                {
                                    int height = 1;
                                    if (sugarPosibility <= 2)
                                    {
                                        height = 3;
                                    }
                                    else if (sugarPosibility <= 5)
                                    {
                                        height = 2;
                                    }

                                    //var growth = Rnd.Next(0x1, 0x15);
                                    for (int mY = y + 1; mY < y + 1 + height; mY++)
                                    {
                                        //column.SetBlock(x, mY, z, 83); //SugarCane
                                        //blocks[OverworldGenerator.GetIndex(x, mY, z)] = 83;

                                        if (mY == y + 1 + height)
                                        {
                                            //metadata[OverworldGenerator.GetIndex(x, mY, z)] = (byte) Rnd.Next(0, 15);
                                            //column.SetMetadata(x, mY, z, (byte) Rnd.Next(0, 15));
                                        }
                                        else
                                        {
                                            //metadata[OverworldGenerator.GetIndex(x, mY, z)] = (byte) 0;
                                            //column.SetMetadata(x, mY, z, 0);
                                        }
                                    }
                                }
                                else if (noise > 0.8 && blockBeneath == 3 || blockBeneath == 2)                                 //If above 0.8, we generate flowers :)
                                {
                                    if (Simplex.Noise(rx, rz, 0.5f, 0.5f, true) > 0.5)
                                    {
                                        column.SetBlock(x, y + 1, z, new RedFlower()
                                        {
                                            FlowerType = FlowerTypes[GetRandom(FlowerTypes.Length - 1)]
                                        });
                                        //blocks[OverworldGenerator.GetIndex(x, y + 1, z)] = 38;
                                        //metadata[OverworldGenerator.GetIndex(x, y + 1, z)] = (byte) GetRandom(8);
                                        //column.SetBlock(x, y + 1, z, 38); //Poppy
                                        //column.SetMetadata(x, y + 1, z, (byte) GetRandom(8));
                                    }
                                    else
                                    {
                                        //	blocks[OverworldGenerator.GetIndex(x, y + 1, z)] = 37;
                                        //	column.SetBlock(x, y + 1, z, new Dan());
                                        //	column.SetBlock(x, y + 1, z, 37); //Dandelion
                                    }
                                }
                                else if (blockBeneath == 3 || blockBeneath == 2)
                                {
                                    column.SetBlock(x, y + 1, z, new Tallgrass());
                                    //blocks[OverworldGenerator.GetIndex(x, y + 1, z)] = 31;
                                    //metadata[OverworldGenerator.GetIndex(x, y + 1, z)] = (byte) 1;
                                    //column.SetBlock(x, y + 1, z, 31); //Grass
                                    //column.SetMetadata(x, y + 1, z, 1);
                                }
                            }
                        }
                    }
                }
            }
            catch (Exception e)
            {
            }
        }
Exemplo n.º 7
0
    private void FixedUpdate()
    {
        spinTimer += Time.fixedDeltaTime;
        bool upright = transform.up.y > .5f;

        if (!upright)
        {
            return;
        }
        if (target != null && target.State != OakTree.OakState.Planted)
        {
            target = null;
        }
        if (target == null)
        {
            //wander randomly
            if (spinTimer > spinInterval)
            {
                spinTimer = spinTimer % spinInterval;
                spinState = (SpinState)Mathf.Max(0, Random.Range(0, 3));
            }
            //search for trees
            RaycastHit hit;
            if (Random.value < .1f && Physics.SphereCast(transform.position, castRadius, transform.forward, out hit, castLength, treeMask))
            {
                OakTree oak = hit.transform.GetComponent <OakTree>();
                if (oak != null && oak.State == OakTree.OakState.Planted)
                {
                    target = oak;
                }
            }
        }
        else
        {
            //collision avoidance
            RaycastHit hit;
            if (Physics.Raycast(body.worldCenterOfMass, transform.forward, out hit, avoidDistance, avoidanceMask))
            {
                OakTree hitTree = hit.transform.GetComponent <OakTree>();
                if (hitTree != null && hitTree.State == OakTree.OakState.Planted)
                {
                    hitTree.ChopDown();
                }
                target = null;
            }
            else
            {
                //Turn towards tree
                float yRot = Vector3.SignedAngle(transform.forward, Vector3.Normalize(target.transform.position - transform.position), transform.up);
                if (Mathf.Abs(yRot) > 90)
                {
                    target = null;
                }
                if (Mathf.Abs(yRot) < aimAngleThreshold)
                {
                    spinState = SpinState.Forward;
                }
                else if (yRot < 0)
                {
                    spinState = SpinState.Left;
                }
                else
                {
                    spinState = SpinState.Right;
                }
            }
        }

        //Wander randomly.
        float m = body.velocity.magnitude;

        if (m < moveSpeed)
        {
            body.AddRelativeForce(Vector3.forward * Mathf.Min(accel * Time.fixedDeltaTime, moveSpeed - m), ForceMode.VelocityChange);
        }

        float yAngular = transform.InverseTransformDirection(body.angularVelocity).y;

        switch (spinState)
        {
        case SpinState.Forward:
            body.AddRelativeTorque(Vector3.up * Mathf.Min(turnAccel * Time.fixedDeltaTime, Mathf.Abs(yAngular)) * Mathf.Sign(-yAngular), ForceMode.VelocityChange);
            break;

        case SpinState.Left:
            if (yAngular > -turnSpeed)
            {
                body.AddRelativeTorque(Vector3.up * Mathf.Max(-turnAccel * Time.fixedDeltaTime, -turnSpeed - yAngular), ForceMode.VelocityChange);
            }
            break;

        case SpinState.Right:
            if (yAngular < turnSpeed)
            {
                body.AddRelativeTorque(Vector3.up * Mathf.Min(turnAccel * Time.fixedDeltaTime, turnSpeed - yAngular), ForceMode.VelocityChange);
            }
            break;
        }
    }
Exemplo n.º 8
0
        public override void LoadContent()
        {
            #region Debug

            DebugConsole = new DebugConsole(Content.Load <SpriteFont>("fonts/general/ubuntu_mono"));

            #endregion

            #region Items

            ItemContainer.GenerateItemDefinitions(Content);

            var slotPrefab = new InventorySlot(
                Content.Load <Texture2D>("inventory/gui/slot"),
                Content.Load <Texture2D>("inventory/gui/slot_hover"),
                Content.Load <Texture2D>("inventory/gui/slot_pressed")
                );

            Inventory = new Inventory(9, 3);

            #endregion

            #region GUI

            guiComponents = new List <IGuiComponent>();
            guiComponents.Add(new InventoryUI(Inventory, new InventoryUISettings()
            {
                InventorySlotPrefab = slotPrefab,

                ItemHoverInfoNineSlice = Content.Load <Texture2D>("inventory/gui/item_hover_ns"),
                ItemHoverInfoFont      = Content.Load <SpriteFont>("fonts/general/peepo")
            }));

            #endregion

            #region Tilemap

            var atlas = Content.Load <Texture2D>("world/forest/tiles/forest_background_tiles");
            tileMap = new TileMap(atlas, new ForestFloorTile(atlas, 3, 1));
            tileMap.Generate(new Vector2[, ]
            {
                { new Vector2(0, 0), new Vector2(0, 0), new Vector2(0, 0), new Vector2(1, 0), new Vector2(0, 0), new Vector2(0, 0), new Vector2(0, 0) },
                { new Vector2(0, 0), new Vector2(0, 0), new Vector2(1, 0), new Vector2(2, 0), new Vector2(1, 0), new Vector2(0, 0), new Vector2(0, 0) },
                { new Vector2(0, 0), new Vector2(1, 0), new Vector2(2, 0), new Vector2(2, 0), new Vector2(2, 0), new Vector2(1, 0), new Vector2(0, 0) },
                { new Vector2(1, 0), new Vector2(2, 0), new Vector2(2, 0), new Vector2(2, 0), new Vector2(2, 0), new Vector2(2, 0), new Vector2(1, 0) },
                { new Vector2(0, 0), new Vector2(1, 0), new Vector2(2, 0), new Vector2(2, 0), new Vector2(2, 0), new Vector2(1, 0), new Vector2(0, 0) },
                { new Vector2(0, 0), new Vector2(0, 0), new Vector2(1, 0), new Vector2(2, 0), new Vector2(1, 0), new Vector2(0, 0), new Vector2(0, 0) },
                { new Vector2(0, 0), new Vector2(0, 0), new Vector2(0, 0), new Vector2(1, 0), new Vector2(0, 0), new Vector2(0, 0), new Vector2(0, 0) }
            });

            #endregion

            #region Entities

            entities = new List <Entity>();

            var player = new Player(new Dictionary <string, Animation>
            {
                {
                    "Walk",
                    new Animation(Content.Load <Texture2D>("player/player"), 9, 1)
                    {
                        IsLooping  = true,
                        FrameSpeed = 0.1f
                    }
                }
            })
            {
                Position = new Vector2(75, 50)
            };
            var oakTree = new OakTree(Content.Load <Texture2D>("world/forest/environment/decor/oak_tree"))
            {
                Position = new Vector2(200, 100)
            };

            entities.Add(player);
            entities.Add(oakTree);

            #endregion
        }
Exemplo n.º 9
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.º 10
0
        public void Decorate(IWorld world, IChunk chunk, IBiomeRepository biomes)
        {
            Noise                = new Perlin(world.Seed);
            ChanceNoise          = new ClampNoise(Noise);
            ChanceNoise.MaxValue = 2;
            Coordinates2D?lastTree = null;

            for (int x = 0; x < 16; x++)
            {
                for (int z = 0; z < 16; z++)
                {
                    var biome  = biomes.GetBiome(chunk.Biomes[x * Chunk.Width + z]);
                    var blockX = MathHelper.ChunkToBlockX(x, chunk.Coordinates.X);
                    var blockZ = MathHelper.ChunkToBlockZ(z, chunk.Coordinates.Z);
                    var height = chunk.HeightMap[x * Chunk.Width + z];

                    if (lastTree != null && lastTree.Value.DistanceTo(new Coordinates2D(x, z)) < biome.TreeDensity)
                    {
                        continue;
                    }

                    if (Noise.Value2D(blockX, blockZ) > 0.3)
                    {
                        var location = new Coordinates3D(x, height, z);
                        var id       = chunk.GetBlockID(location);
                        var provider = world.BlockRepository.GetBlockProvider(id);
                        if (id == DirtBlock.BlockID || id == GrassBlock.BlockID || id == SnowfallBlock.BlockID ||
                            (id != StationaryWaterBlock.BlockID && id != WaterBlock.BlockID &&
                             id != LavaBlock.BlockID && id != StationaryLavaBlock.BlockID &&
                             provider.BoundingBox == null))
                        {
                            if (provider.BoundingBox == null)
                            {
                                location.Y--;
                            }
                            var oakNoise    = ChanceNoise.Value2D(blockX * 0.6, blockZ * 0.6);
                            var birchNoise  = ChanceNoise.Value2D(blockX * 0.2, blockZ * 0.2);
                            var spruceNoise = ChanceNoise.Value2D(blockX * 0.35, blockZ * 0.35);

                            var baseCoordinates = location + Coordinates3D.Up;
                            if (biome.Trees.Contains(TreeSpecies.Oak) && oakNoise > 1.01 && oakNoise < 1.25)
                            {
                                var oak = new OakTree().GenerateAt(world, chunk, baseCoordinates);
                                if (oak)
                                {
                                    lastTree = new Coordinates2D(x, z);
                                    continue;
                                }
                            }
                            if (biome.Trees.Contains(TreeSpecies.Birch) && birchNoise > 0.3 && birchNoise < 0.95)
                            {
                                var birch = new BirchTree().GenerateAt(world, chunk, baseCoordinates);
                                if (birch)
                                {
                                    lastTree = new Coordinates2D(x, z);
                                    continue;
                                }
                            }
                            if (biome.Trees.Contains(TreeSpecies.Spruce) && spruceNoise < 0.75)
                            {
                                var random    = new Random(world.Seed);
                                var type      = random.Next(1, 2);
                                var generated = false;
                                if (type.Equals(1))
                                {
                                    generated = new PineTree().GenerateAt(world, chunk, baseCoordinates);
                                }
                                else
                                {
                                    generated = new ConiferTree().GenerateAt(world, chunk, baseCoordinates);
                                }

                                if (generated)
                                {
                                    lastTree = new Coordinates2D(x, z);
                                    continue;
                                }
                            }
                        }
                    }
                }
            }
        }
Exemplo n.º 11
0
        public void VegetationTest()
        {
            Vegetation a = new OakTree();

            Assert.IsNotNull(a);
        }
Exemplo n.º 12
0
    public static void CameraUpdate()
    {
        int count = oaks.Count;

        if (count > 0)
        {
            int         i      = 0;
            Vector3     camPos = FollowingCamera.camPos;
            Transform   t;
            Vector3     cpos;
            OakDrawMode newDrawMode = OakDrawMode.NoDraw;
            float       dist, lodDist = LODController.lodCoefficient;

            if (!PoolMaster.shadowCasting)
            {
                while (i < count)
                {
                    OakTree oak = oaks[i];
                    if (oak == null)
                    {
                        oaks.RemoveAt(i);
                        count--;
                        continue;
                    }
                    else
                    {
                        if (!oak.isVisible)
                        {
                            i++; continue;
                        }
                        dist = (oak.transform.position - camPos).magnitude;
                        if (oak.stage <= TRANSIT_STAGE)
                        {
                            if (dist > TREE_SPRITE_MAX_VISIBILITY * oak.stage)
                            {
                                if (oak.drawmode != OakDrawMode.NoDraw)
                                {
                                    oak.spriter.enabled = false;
                                    oak.drawmode        = OakDrawMode.NoDraw;
                                }
                            }
                            else
                            {
                                if (oak.drawmode != OakDrawMode.DrawStartSprite)
                                {
                                    oak.drawmode        = OakDrawMode.DrawStartSprite;
                                    oak.spriter.enabled = true;
                                }
                            }
                        }
                        else
                        {                        // # change model draw mode
                            float x = TREE_SPRITE_MAX_VISIBILITY + 3 * oak.stage;
                            x = dist / x;
                            if (x > lodDist)
                            {
                                if (x > 1)
                                {
                                    newDrawMode = OakDrawMode.NoDraw;
                                }
                                else
                                {
                                    newDrawMode = OakDrawMode.DrawLOD;
                                }
                            }
                            else
                            {
                                newDrawMode = OakDrawMode.DrawModel;
                            }
                            if (newDrawMode != oak.drawmode)
                            {
                                if (newDrawMode == OakDrawMode.NoDraw)
                                {
                                    oak.spriter.enabled = false;
                                    oak.modelHolder.transform.GetChild(MODEL_CHILDNUMBER).gameObject.SetActive(false);
                                }
                                else
                                {
                                    if (newDrawMode == OakDrawMode.DrawModel)
                                    {
                                        oak.spriter.enabled = false;
                                        oak.modelHolder.transform.GetChild(MODEL_CHILDNUMBER).gameObject.SetActive(true);
                                    }
                                    else
                                    {
                                        oak.spriter.enabled = true;
                                        oak.modelHolder.transform.GetChild(MODEL_CHILDNUMBER).gameObject.SetActive(false);
                                    }
                                }
                                oak.drawmode = newDrawMode;
                            }
                            // # setting lod
                            if (oak.drawmode == OakDrawMode.DrawLOD)
                            {
                                byte  spriteNumber = 0;
                                float angle        = Vector3.Angle(Vector3.up, camPos - oak.transform.position);
                                if (angle < 30)
                                {
                                    if (angle < 10)
                                    {
                                        spriteNumber = 3;
                                    }
                                    else
                                    {
                                        spriteNumber = 2;
                                    }
                                }
                                else
                                {
                                    if (angle > 85)
                                    {
                                        spriteNumber = 0;
                                    }
                                    else
                                    {
                                        spriteNumber = 1;
                                    }
                                }
                                if (spriteNumber != oak.lodNumber)
                                {
                                    switch (oak.stage)
                                    {
                                    case 4: oak.spriter.sprite = lodPack_stage4[spriteNumber]; break;

                                    case 5: oak.spriter.sprite = lodPack_stage5[spriteNumber]; break;

                                    case 6: oak.spriter.sprite = lodPack_stage6[spriteNumber]; break;
                                    }
                                    oak.lodNumber = spriteNumber;
                                }
                            }
                            // eo setting lod
                        }
                        i++;
                    }
                }
            }
            else
            { // то же самое, только с разворотом на камеру
                while (i < count)
                {
                    OakTree oak = oaks[i];
                    if (oak == null)
                    {
                        oaks.RemoveAt(i); continue;
                    }
                    else
                    {
                        if (!oak.isVisible)
                        {
                            i++; continue;
                        }
                        dist = (oak.transform.position - camPos).magnitude;
                        if (oak.stage <= TRANSIT_STAGE)
                        {
                            if (dist > TREE_SPRITE_MAX_VISIBILITY * oak.stage)
                            {
                                if (oak.drawmode != OakDrawMode.NoDraw)
                                {
                                    oak.spriter.enabled = false;
                                    oak.drawmode        = OakDrawMode.NoDraw;
                                }
                            }
                            else
                            {
                                if (oak.drawmode != OakDrawMode.DrawStartSprite)
                                {
                                    oak.drawmode        = OakDrawMode.DrawStartSprite;
                                    oak.spriter.enabled = true;
                                }
                                t         = oak.spriter.transform;
                                cpos      = Vector3.ProjectOnPlane(camPos - t.position, t.up);
                                t.forward = cpos.normalized;
                            }
                        }
                        else
                        {                        // # change model draw mode
                            float x = TREE_SPRITE_MAX_VISIBILITY + 3 * oak.stage;
                            x = dist / x;
                            if (x > lodDist)
                            {
                                if (x > 1)
                                {
                                    newDrawMode = OakDrawMode.NoDraw;
                                }
                                else
                                {
                                    newDrawMode = OakDrawMode.DrawLOD;
                                }
                            }
                            else
                            {
                                newDrawMode = OakDrawMode.DrawModel;
                            }
                            if (newDrawMode != oak.drawmode)
                            {
                                if (newDrawMode == OakDrawMode.NoDraw)
                                {
                                    oak.spriter.enabled = false;
                                    oak.modelHolder.transform.GetChild(MODEL_CHILDNUMBER).gameObject.SetActive(false);
                                }
                                else
                                {
                                    if (newDrawMode == OakDrawMode.DrawModel)
                                    {
                                        oak.spriter.enabled = false;
                                        oak.modelHolder.transform.GetChild(MODEL_CHILDNUMBER).gameObject.SetActive(true);
                                    }
                                    else
                                    {
                                        oak.spriter.enabled = true;
                                        oak.modelHolder.transform.GetChild(MODEL_CHILDNUMBER).gameObject.SetActive(false);
                                    }
                                }
                                oak.drawmode = newDrawMode;
                            }
                            // # setting lod
                            if (oak.drawmode == OakDrawMode.DrawLOD)
                            {
                                byte  spriteNumber = 0;
                                float angle        = Vector3.Angle(Vector3.up, camPos - oak.transform.position);
                                if (angle < 30)
                                {
                                    if (angle < 10)
                                    {
                                        spriteNumber = 3;
                                    }
                                    else
                                    {
                                        spriteNumber = 2;
                                    }
                                }
                                else
                                {
                                    if (angle > 85)
                                    {
                                        spriteNumber = 0;
                                    }
                                    else
                                    {
                                        spriteNumber = 1;
                                    }
                                }
                                if (spriteNumber != oak.lodNumber)
                                {
                                    switch (oak.stage)
                                    {
                                    case 4: oak.spriter.sprite = lodPack_stage4[spriteNumber]; break;

                                    case 5: oak.spriter.sprite = lodPack_stage5[spriteNumber]; break;

                                    case 6: oak.spriter.sprite = lodPack_stage6[spriteNumber]; break;
                                    }
                                    oak.lodNumber = spriteNumber;
                                }
                                oak.spriter.transform.forward = oak.transform.position - camPos;
                            }
                            // eo setting lod
                        }
                        i++;
                    }
                }
            }
        }
    }