Beispiel #1
0
        public List <CropData> GetCropSummary()
        {
            List <CropData> list      = new List <CropData>();
            int             startweek = -1;
            int             endweek   = -1;

            if (hasCrop == 0)
            {
                return(null);
            }
            for (int i = 0; i < plotWeeks.Count; i++)
            {
                if (i == 0)
                {
                    if (!plotWeeks[i].isEmpty)
                    {
                        startweek = i;
                    }
                }
                else
                {
                    if (!plotWeeks[i].isEmpty)
                    {
                        if (plotWeeks[i - 1].isEmpty || plotWeeks[i].getCrop() != plotWeeks[i - 1].getCrop() || i == plotWeeks.Count - 1)
                        {
                            if (startweek == -1)
                            {
                                startweek = i;
                            }
                            else if (!plotWeeks[i - 1].isEmpty)
                            {
                                // The Week holds a crop but is different therefore the week before is the end date and the week is the begin date to another crop
                                if (i == plotWeeks.Count - 1)
                                {
                                    endweek = i;
                                }
                                else
                                {
                                    endweek = i - 1;
                                }
                                CropData data = GetCropDataByDate(endweek);
                                list.Add(data);
                                startweek = i;
                                endweek   = -1;
                            }
                        }
                    }
                    else if (plotWeeks[i].isEmpty && startweek != -1)
                    {   //The week holds no crop therefore the before is the end date
                        endweek = i - 1;
                        CropData data = GetCropDataByDate(endweek);

                        list.Add(data);
                        startweek = -1;
                        endweek   = -1;
                    }
                }
            }
            return(list);
        }
Beispiel #2
0
        public CropData GetCropDataByDate(int weekNumber)
        {
            CropData cropdata;
            int      now = weekNumber;
            Crop     crop;
            int      beginWeek;

            if (isNotEmptyAtSpecificWeek(now, out crop, out beginWeek))
            {
                bool   alive;
                int    health         = plotWeeks[now].getCrop().weeks[now - beginWeek].Health;
                string health_details = "Crop " + crop.GetCropName();
                if (health > 1)
                {
                    alive = true;
                    if (health > 90)
                    {
                        health_details += " is very healthly.";
                    }
                    else if (health < 90 && health > 50)
                    {
                        health_details += " is need more care.";
                    }
                    else if (health < 50 && health > 20)
                    {
                        health_details += " need more care.";
                    }
                    else
                    {
                        health_details += " needs urgent care.";
                    }
                }
                else
                {
                    alive          = false;
                    health_details = reasonOfDeath(crop);
                }

                if (crop.GetMaturityLength() == (now - beginWeek) + 1 && alive == true)
                {
                    cropdata = new CropData(crop.GetCropName(), PlotId, simulation.weekToDate(beginWeek), simulation.weekToDate(beginWeek + crop.GetMaturityLength()), alive, health_details, crop.WaterCosts, crop.FertilizerCosts, crop.WaterCosts + crop.FertilizerCosts + seedCost(crop), getYield(crop), getIdealYield(crop), getCropProfits(crop));
                }
                else
                {
                    cropdata = new CropData(crop.GetCropName(), PlotId, simulation.weekToDate(beginWeek), simulation.weekToDate(beginWeek + crop.GetMaturityLength()), alive, health_details, crop.WaterCosts, crop.FertilizerCosts, crop.WaterCosts + crop.FertilizerCosts + seedCost(crop));
                }

                return(cropdata);
            }
            else
            {
                return(null);
            }
        }
Beispiel #3
0
        public decimal getTotalCostsByDate(int Week)
        {
            decimal         total = 0;
            List <CropData> data  = new List <CropData>();
            List <Plot>     plots = simulation.getListOfPlots();

            foreach (Plot p in plots)
            {
                if (p.getNumberOfCrops() != 0)
                {
                    int  week = Week;
                    Crop crop = null;
                    while (week >= 0)
                    {
                        if (!p.plotWeeks[week].isEmpty)
                        {
                            if (crop != p.plotWeeks[week].getCrop())
                            {
                                crop = p.plotWeeks[week].getCrop();
                                CropData temp = p.GetCropDataByDate(week);
                                data.Add(temp);
                            }
                        }
                        week--;
                    }
                }
            }
            if (data.Count > 0)
            {
                foreach (CropData cd in data)
                {
                    total += cd.GetTotalCost();
                }
            }
            return(total);
        }