Esempio n. 1
0
    public double InsectSim(double insectIntake)
    {
        /*
         * 当该叶片的最低被啃食比例小于细胞纹理的最低被啃食比例时
         * 说明该比例无或者存在一定的问题
         * 因此将该比例设置为细胞纹理的最低被啃食比例
         */
        if (LimitRatio < CelluarTex.LimitRatio)
        {
            LimitRatio = CelluarTex.LimitRatio;

            /*
             * 调整最低被啃食比例
             * 减少重复感
             */
            LimitRatio += (0.8 - LimitRatio) * RandomNumer.Double();
        }

        /*
         * 叶片当前最大可被进食量
         * 用于计算当前实际被进食量
         */
        double maxInsectIntake = (InsectedRatio - LimitRatio) * LeafArea_Uninsected;

        /*
         * 若该叶片已经老去
         * 则不会被并病虫啃食
         * 若还未老去,则根据叶片最大被进食量计算实际被进食量
         * 当最大可被进食量不大于0时,说明无可被进食部分,因此实际被进食量为0
         * 当最大可被进食量大于当前病虫进食量,则说明该叶片满足病虫进食需求,因此实际进食量为病虫进食量
         * 当最大可被进食量大于0并且小于当前病虫进食量,则说明该叶片有被进食,但无法满足病虫进食需求
         * 因此最大可被进食量均被进食,故实际进食量为最大可被进食量
         */
        double actualInsectIntake = Age >= MaizeParams.LEAF_MAX_DEVELOPMENT_AGE ? 0 :
                                    maxInsectIntake <= 0 ? 0 :
                                    maxInsectIntake >= insectIntake ? insectIntake : maxInsectIntake;

        //根据实际进食量计算叶片的面积
        LeafArea -= actualInsectIntake;

        int threshold;

        //设置纹理
        GameObjectOperation.SetTexture(Belong, GetWormholeTex(actualInsectIntake, out threshold));

        //设置阈值
        GameObjectOperation.SetThreshold(Belong, threshold);

        //返回剩余的病虫进食量
        return(insectIntake - actualInsectIntake);
    }