Esempio n. 1
0
        public StepInfo NextStep()
        {
            stepInfo = new StepInfo();

            //for (int activeMonster = 0; activeMonster < Monsters.Count; activeMonster++)
            Parallel.For(0, Monsters.Count, activeMonster =>
            {
                IMonster monster = Monsters[activeMonster];
                monster.NextStep(this);
                monster.Energy -= MONSTER_MOVE_ENERGY;
                UsedEnergy     -= MONSTER_MOVE_ENERGY;
            });

            for (int i = 0; i < Monsters.Count; i++)
            {
                IMonster monster = Monsters[i];

                // Monster death
                if (monster.Energy < MONSTER_MOVE_ENERGY)// || Common.Random.NextDouble() < 0.000003 * monster.Age)
                {
                    UsedEnergy    -= monster.Energy;
                    monster.Energy = 0.0;
                    Monsters.Remove(monster);
                    Cell cell = GetCellAt(monster.AreaInfo as CellAreaInfo);
                    cell.ContentType = ContentType.Empty;
                    i--;
                }
                // Child monster birth from single parent
                else if (monster.Energy > MONSTER_MASTURBATION_SEX_ENERGY && Common.Random.Next(50) == 48)
                {
                    CreateChildMonster(monster);
                }

                // Add meat to area
                if (UsedEnergy <= TotalEnergy - FOOD_ENERGY - MONSTER_INIT_ENERGY)
                {
                    int  x    = Common.Random.Next(Width);
                    int  y    = Common.Random.Next(Height);
                    Cell cell = cells[x, y];
                    if (cell.ContentType == ContentType.Empty)
                    {
                        cell.ContentType = ContentType.Food;
                        UsedEnergy      += FOOD_ENERGY;
                    }
                }
            }

            // Add random monster to area
            if (UsedEnergy <= TotalEnergy - MONSTER_INIT_ENERGY && Common.Random.Next(100 + 10) == 21)
            {
                GenerateMonster();
            }

            return(stepInfo);
        }